@@ -65,70 +65,6 @@ export function doPublicKeysMatchIssuer(token: string): boolean {
6565 return false ;
6666}
6767
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-
13268/**
13369 * Checks if the if the token issuance time and date is after the
13470 * current time and date.
0 commit comments