|
1 | 1 | import { decodeToken, TokenVerifier } from 'jsontokens'; |
2 | 2 | import { getAddressFromDID } from './dids'; |
3 | 3 | import { publicKeyToAddress } from '@stacks/encryption'; |
4 | | -import { fetchPrivate, isSameOriginAbsoluteUrl } from '@stacks/common'; |
5 | 4 | import { fetchAppManifest } from './provider'; |
6 | | -import { c32ToB58 } from 'c32check'; |
7 | 5 |
|
8 | 6 | /** |
9 | 7 | * Checks if the ES256k signature on passed `token` match the claimed public key |
@@ -65,70 +63,6 @@ export function doPublicKeysMatchIssuer(token: string): boolean { |
65 | 63 | return false; |
66 | 64 | } |
67 | 65 |
|
68 | | -/** |
69 | | - * Looks up the identity address that owns the claimed username |
70 | | - * in `token` using the lookup endpoint provided in `nameLookupURL` |
71 | | - * to determine if the username is owned by the identity address |
72 | | - * that matches the claimed public key |
73 | | - * |
74 | | - * @param {String} token encoded and signed authentication token |
75 | | - * @param {String} nameLookupURL a URL to the name lookup endpoint of the Blockstack Core API |
76 | | - * @return {Promise<Boolean>} returns a `Promise` that resolves to |
77 | | - * `true` if the username is owned by the public key, otherwise the |
78 | | - * `Promise` resolves to `false` |
79 | | - * @private |
80 | | - * @ignore |
81 | | - */ |
82 | | -export async function doPublicKeysMatchUsername( |
83 | | - token: string, |
84 | | - nameLookupURL: string |
85 | | -): Promise<boolean> { |
86 | | - try { |
87 | | - const payload = decodeToken(token).payload; |
88 | | - if (typeof payload === 'string') { |
89 | | - throw new Error('Unexpected token payload type of string'); |
90 | | - } |
91 | | - if (!payload.username) { |
92 | | - return true; |
93 | | - } |
94 | | - |
95 | | - if (payload.username === null) { |
96 | | - return true; |
97 | | - } |
98 | | - |
99 | | - if (nameLookupURL === null) { |
100 | | - return false; |
101 | | - } |
102 | | - |
103 | | - const username = payload.username; |
104 | | - const url = `${nameLookupURL.replace(/\/$/, '')}/${username}`; |
105 | | - const response = await fetchPrivate(url); |
106 | | - const responseText = await response.text(); |
107 | | - const responseJSON = JSON.parse(responseText); |
108 | | - if (responseJSON.hasOwnProperty('address')) { |
109 | | - const nameOwningAddress = responseJSON.address; |
110 | | - let nameOwningAddressBtc = nameOwningAddress; |
111 | | - try { |
112 | | - // try converting STX to BTC |
113 | | - // if this throws, it's already a BTC address |
114 | | - nameOwningAddressBtc = c32ToB58(nameOwningAddress, 0); |
115 | | - } catch {} |
116 | | - const addressFromIssuer = getAddressFromDID(payload.iss); |
117 | | - if (nameOwningAddressBtc === addressFromIssuer) { |
118 | | - return true; |
119 | | - } else { |
120 | | - return false; |
121 | | - } |
122 | | - } else { |
123 | | - return false; |
124 | | - } |
125 | | - } catch (error) { |
126 | | - console.log(error); |
127 | | - console.log('Error checking `doPublicKeysMatchUsername`'); |
128 | | - return false; |
129 | | - } |
130 | | -} |
131 | | - |
132 | 66 | /** |
133 | 67 | * Checks if the if the token issuance time and date is after the |
134 | 68 | * current time and date. |
|
0 commit comments