Skip to content

Commit 95c634a

Browse files
committed
fix: remove doPublicKeysMatchUsername
1 parent 93683a3 commit 95c634a

File tree

3 files changed

+0
-74
lines changed

3 files changed

+0
-74
lines changed

packages/auth/src/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ export {
66
verifyAuthResponse,
77
isExpirationDateValid,
88
isIssuanceDateValid,
9-
doPublicKeysMatchUsername,
109
doPublicKeysMatchIssuer,
1110
doSignaturesMatchPublicKeys,
1211
isManifestUriValid,

packages/auth/src/verification.ts

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

packages/auth/tests/auth.test.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import {
88
isIssuanceDateValid,
99
doSignaturesMatchPublicKeys,
1010
doPublicKeysMatchIssuer,
11-
doPublicKeysMatchUsername,
1211
isManifestUriValid,
1312
isRedirectUriValid,
1413
verifyAuthRequestAndLoadManifest,
@@ -191,10 +190,6 @@ test('makeAuthResponse && verifyAuthResponse', async () => {
191190
expect(isIssuanceDateValid(authResponse)).toBe(true);
192191
expect(doSignaturesMatchPublicKeys(authResponse)).toBe(true);
193192
expect(doPublicKeysMatchIssuer(authResponse)).toBe(true);
194-
195-
await doPublicKeysMatchUsername(authResponse, nameLookupURL).then(verifiedResult => {
196-
expect(verifiedResult).toBe(true);
197-
});
198193
});
199194

200195
test('auth response with invalid or empty appPrivateKeyFromWalletSalt', async () => {
@@ -253,10 +248,6 @@ test('auth response with username', async () => {
253248

254249
const authResponse = await makeAuthResponse(privateKey, sampleProfiles.ryan, 'ryan.id', null);
255250

256-
await doPublicKeysMatchUsername(authResponse, nameLookupURL).then(verified => {
257-
expect(verified).toBe(true);
258-
});
259-
260251
await verifyAuthResponse(authResponse).then(verifiedResult => {
261252
expect(verifiedResult).toBe(true);
262253
});

0 commit comments

Comments
 (0)