Skip to content

Commit bbbf990

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

File tree

5 files changed

+0
-80
lines changed

5 files changed

+0
-80
lines changed

package-lock.json

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/auth/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
"@stacks/encryption": "^3.3.0",
4545
"@stacks/network": "^3.3.0",
4646
"@stacks/profile": "^3.3.0",
47-
"c32check": "^1.1.3",
4847
"cross-fetch": "^3.1.4",
4948
"jsontokens": "^3.0.0",
5049
"query-string": "^6.13.1"

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 & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { decodeToken, TokenVerifier } from 'jsontokens';
22
import { getAddressFromDID } from './dids';
33
import { publicKeyToAddress } from '@stacks/encryption';
4-
import { fetchPrivate, isSameOriginAbsoluteUrl } from '@stacks/common';
54
import { fetchAppManifest } from './provider';
6-
import { c32ToB58 } from 'c32check';
75

86
/**
97
* Checks if the ES256k signature on passed `token` match the claimed public key
@@ -65,70 +63,6 @@ export function doPublicKeysMatchIssuer(token: string): boolean {
6563
return false;
6664
}
6765

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-
13266
/**
13367
* Checks if the if the token issuance time and date is after the
13468
* current time and date.

packages/auth/tests/auth.test.ts

Lines changed: 0 additions & 10 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,
@@ -30,7 +29,6 @@ beforeEach(() => {
3029

3130
const privateKey = 'a5c61c6ca7b3e7e55edee68566aeab22e4da26baa285c7bd10e8d2218aa3b229';
3231
const publicKey = '027d28f9951ce46538951e3697c62588a87f1f1f295de4a14fdd4c780fc52cfe69';
33-
const nameLookupURL = 'https://stacks-node-api.mainnet.stacks.co/v1/names/';
3432

3533
test('makeAuthRequest && verifyAuthRequest', async () => {
3634
const appConfig = new AppConfig(['store_write'], 'http://localhost:3000');
@@ -191,10 +189,6 @@ test('makeAuthResponse && verifyAuthResponse', async () => {
191189
expect(isIssuanceDateValid(authResponse)).toBe(true);
192190
expect(doSignaturesMatchPublicKeys(authResponse)).toBe(true);
193191
expect(doPublicKeysMatchIssuer(authResponse)).toBe(true);
194-
195-
await doPublicKeysMatchUsername(authResponse, nameLookupURL).then(verifiedResult => {
196-
expect(verifiedResult).toBe(true);
197-
});
198192
});
199193

200194
test('auth response with invalid or empty appPrivateKeyFromWalletSalt', async () => {
@@ -253,10 +247,6 @@ test('auth response with username', async () => {
253247

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

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

0 commit comments

Comments
 (0)