diff options
author | Matthew Miller <matthew@millerti.me> | 2023-07-27 08:42:05 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-27 08:42:05 -0700 |
commit | f30a195ab1c5b7476fb8056e6ac25a13a7546452 (patch) | |
tree | c2779d080e51bea1463effd581752cd245b9940a /packages/server/src/helpers | |
parent | 5731c7d0427323bbd78df195295c28eb39f822ba (diff) | |
parent | 22ca0cd6dab119a28794dbaa33d650f97ab107a1 (diff) |
Merge pull request #415 from Mikescops/feature/add-origin-authentication-registration-info
Add origin and rpID in authentication and registration info
Diffstat (limited to 'packages/server/src/helpers')
-rw-r--r-- | packages/server/src/helpers/matchExpectedRPID.ts | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/packages/server/src/helpers/matchExpectedRPID.ts b/packages/server/src/helpers/matchExpectedRPID.ts index be49fc2..c08c223 100644 --- a/packages/server/src/helpers/matchExpectedRPID.ts +++ b/packages/server/src/helpers/matchExpectedRPID.ts @@ -2,19 +2,22 @@ import { toHash } from './toHash'; import { isoUint8Array } from './iso'; /** - * Go through each expected RP ID and try to find one that matches. Raises an Error if no + * Go through each expected RP ID and try to find one that matches. Returns the unhashed RP ID + * that matched the hash in the response. + * + * Raises an `UnexpectedRPIDHash` error if no match is found */ export async function matchExpectedRPID( rpIDHash: Uint8Array, expectedRPIDs: string[], -): Promise<void> { +): Promise<string> { try { - await Promise.any( + const matchedRPID = await Promise.any<string>( expectedRPIDs.map(expected => { return new Promise((resolve, reject) => { toHash(isoUint8Array.fromASCIIString(expected)).then(expectedRPIDHash => { if (isoUint8Array.areEqual(rpIDHash, expectedRPIDHash)) { - resolve(true); + resolve(expected); } else { reject(); } @@ -22,6 +25,8 @@ export async function matchExpectedRPID( }); }), ); + + return matchedRPID; } catch (err) { const _err = err as Error; |