WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 5761781

Browse files
authored
Merge pull request #715 from MasterKale/fix/714-better-registration-verification-typing
Make `VerifiedRegistrationResponse` into a stricter type
2 parents a1a3d4d + 0c32dcc commit 5761781

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

packages/server/src/registration/verifyRegistrationResponse.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,16 +276,15 @@ export async function verifyRegistrationResponse(
276276
throw new Error(`Unsupported Attestation Format: ${fmt}`);
277277
}
278278

279-
const toReturn: VerifiedRegistrationResponse = {
280-
verified,
281-
};
279+
if (!verified) {
280+
return { verified: false };
281+
}
282282

283-
if (toReturn.verified) {
284-
const { credentialDeviceType, credentialBackedUp } = parseBackupFlags(
285-
flags,
286-
);
283+
const { credentialDeviceType, credentialBackedUp } = parseBackupFlags(flags);
287284

288-
toReturn.registrationInfo = {
285+
return {
286+
verified: true,
287+
registrationInfo: {
289288
fmt,
290289
aaguid: convertAAGUIDToString(aaguid),
291290
credentialType,
@@ -302,10 +301,8 @@ export async function verifyRegistrationResponse(
302301
origin: clientDataJSON.origin,
303302
rpID: matchedRPID,
304303
authenticatorExtensionResults: extensionsData,
305-
};
306-
}
307-
308-
return toReturn;
304+
},
305+
};
309306
}
310307

311308
/**
@@ -335,8 +332,11 @@ export async function verifyRegistrationResponse(
335332
* by the browser
336333
*/
337334
export type VerifiedRegistrationResponse = {
338-
verified: boolean;
339-
registrationInfo?: {
335+
verified: false;
336+
registrationInfo?: never;
337+
} | {
338+
verified: true;
339+
registrationInfo: {
340340
fmt: AttestationFormat;
341341
aaguid: string;
342342
credential: WebAuthnCredential;

0 commit comments

Comments
 (0)