From 3170379c67a9cf33374d9f9ab89dafed16ba7edf Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 27 Dec 2022 19:21:46 -0800 Subject: Update startRegistration to use new values --- .../browser/src/helpers/toAuthenticatorAttachment.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 packages/browser/src/helpers/toAuthenticatorAttachment.ts (limited to 'packages/browser/src/helpers/toAuthenticatorAttachment.ts') diff --git a/packages/browser/src/helpers/toAuthenticatorAttachment.ts b/packages/browser/src/helpers/toAuthenticatorAttachment.ts new file mode 100644 index 0000000..7a2aca0 --- /dev/null +++ b/packages/browser/src/helpers/toAuthenticatorAttachment.ts @@ -0,0 +1,18 @@ +import { AuthenticatorAttachment } from '@simplewebauthn/typescript-types'; + +const attachments: AuthenticatorAttachment[] = ['cross-platform', 'platform']; + +/** + * If possible coerce a `string` value into a known `AuthenticatorAttachment` + */ +export function toAuthenticatorAttachment(attachment: string | null): AuthenticatorAttachment | undefined { + if (!attachment) { + return; + } + + if (attachments.indexOf(attachment as AuthenticatorAttachment) < 0) { + return; + } + + return attachment as AuthenticatorAttachment; +} -- cgit v1.2.3 From ad5e7119317ab5915c7063b575e2bdd4fe263f9e Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Tue, 27 Dec 2022 21:38:27 -0800 Subject: Lint everything --- packages/browser/src/helpers/toAuthenticatorAttachment.ts | 4 +++- packages/browser/src/methods/startAuthentication.test.ts | 2 +- packages/browser/src/methods/startRegistration.test.ts | 2 +- packages/browser/src/methods/startRegistration.ts | 4 +++- .../src/authentication/verifyAuthenticationResponse.test.ts | 5 +---- .../server/src/registration/verifyRegistrationResponse.test.ts | 2 +- packages/typescript-types/src/index.ts | 8 ++++++-- 7 files changed, 16 insertions(+), 11 deletions(-) (limited to 'packages/browser/src/helpers/toAuthenticatorAttachment.ts') diff --git a/packages/browser/src/helpers/toAuthenticatorAttachment.ts b/packages/browser/src/helpers/toAuthenticatorAttachment.ts index 7a2aca0..366cf8f 100644 --- a/packages/browser/src/helpers/toAuthenticatorAttachment.ts +++ b/packages/browser/src/helpers/toAuthenticatorAttachment.ts @@ -5,7 +5,9 @@ const attachments: AuthenticatorAttachment[] = ['cross-platform', 'platform']; /** * If possible coerce a `string` value into a known `AuthenticatorAttachment` */ -export function toAuthenticatorAttachment(attachment: string | null): AuthenticatorAttachment | undefined { +export function toAuthenticatorAttachment( + attachment: string | null, +): AuthenticatorAttachment | undefined { if (!attachment) { return; } diff --git a/packages/browser/src/methods/startAuthentication.test.ts b/packages/browser/src/methods/startAuthentication.test.ts index 49f8898..31dbde3 100644 --- a/packages/browser/src/methods/startAuthentication.test.ts +++ b/packages/browser/src/methods/startAuthentication.test.ts @@ -299,7 +299,7 @@ test('should return authenticatorAttachment if present', async () => { return new Promise(resolve => { resolve({ response: {}, - getClientExtensionResults: () => { }, + getClientExtensionResults: () => {}, authenticatorAttachment: 'cross-platform', }); }); diff --git a/packages/browser/src/methods/startRegistration.test.ts b/packages/browser/src/methods/startRegistration.test.ts index 19e9185..8ba6f5a 100644 --- a/packages/browser/src/methods/startRegistration.test.ts +++ b/packages/browser/src/methods/startRegistration.test.ts @@ -239,7 +239,7 @@ test('should return authenticatorAttachment if present', async () => { return new Promise(resolve => { resolve({ response: {}, - getClientExtensionResults: () => { }, + getClientExtensionResults: () => {}, authenticatorAttachment: 'cross-platform', }); }); diff --git a/packages/browser/src/methods/startRegistration.ts b/packages/browser/src/methods/startRegistration.ts index 3ce3083..546347b 100644 --- a/packages/browser/src/methods/startRegistration.ts +++ b/packages/browser/src/methods/startRegistration.ts @@ -34,7 +34,9 @@ export async function startRegistration( ...creationOptionsJSON.user, id: utf8StringToBuffer(creationOptionsJSON.user.id), }, - excludeCredentials: creationOptionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor), + excludeCredentials: creationOptionsJSON.excludeCredentials?.map( + toPublicKeyCredentialDescriptor, + ), }; // Finalize options diff --git a/packages/server/src/authentication/verifyAuthenticationResponse.test.ts b/packages/server/src/authentication/verifyAuthenticationResponse.test.ts index fcd1b4f..30eb9d1 100644 --- a/packages/server/src/authentication/verifyAuthenticationResponse.test.ts +++ b/packages/server/src/authentication/verifyAuthenticationResponse.test.ts @@ -3,10 +3,7 @@ import { verifyAuthenticationResponse } from './verifyAuthenticationResponse'; import * as esmDecodeClientDataJSON from '../helpers/decodeClientDataJSON'; import * as esmParseAuthenticatorData from '../helpers/parseAuthenticatorData'; import { toHash } from '../helpers/toHash'; -import { - AuthenticatorDevice, - AuthenticationResponseJSON, -} from '@simplewebauthn/typescript-types'; +import { AuthenticatorDevice, AuthenticationResponseJSON } from '@simplewebauthn/typescript-types'; import { isoUint8Array, isoBase64URL } from '../helpers/iso'; let mockDecodeClientData: jest.SpyInstance; diff --git a/packages/server/src/registration/verifyRegistrationResponse.test.ts b/packages/server/src/registration/verifyRegistrationResponse.test.ts index 850e51e..9fd8a96 100644 --- a/packages/server/src/registration/verifyRegistrationResponse.test.ts +++ b/packages/server/src/registration/verifyRegistrationResponse.test.ts @@ -90,7 +90,7 @@ test('should verify Packed (EC2) attestation', async () => { expect(verification.registrationInfo?.credentialID).toEqual( isoBase64URL.toBuffer( 'AYThY1csINY4JrbHyGmqTl1nL_F1zjAF3hSAIngz8kAcjugmAMNVvxZRwqpEH-bNHHAIv291OX5ko9eDf_5mu3U' + - 'B2BvsScr2K-ppM4owOpGsqwg5tZglqqmxIm1Q', + 'B2BvsScr2K-ppM4owOpGsqwg5tZglqqmxIm1Q', ), ); }); diff --git a/packages/typescript-types/src/index.ts b/packages/typescript-types/src/index.ts index 85f3ef5..b8b1394 100644 --- a/packages/typescript-types/src/index.ts +++ b/packages/typescript-types/src/index.ts @@ -205,9 +205,13 @@ export interface PublicKeyCredentialFuture extends PublicKeyCredential { // See https://github.com/w3c/webauthn/issues/1745 isConditionalMediationAvailable?(): Promise; // See https://w3c.github.io/webauthn/#sctn-parseCreationOptionsFromJSON - parseCreationOptionsFromJSON?(options: PublicKeyCredentialCreationOptionsJSON): PublicKeyCredentialCreationOptions; + parseCreationOptionsFromJSON?( + options: PublicKeyCredentialCreationOptionsJSON, + ): PublicKeyCredentialCreationOptions; // See https://w3c.github.io/webauthn/#sctn-parseRequestOptionsFromJSON - parseRequestOptionsFromJSON?(options: PublicKeyCredentialRequestOptionsJSON): PublicKeyCredentialRequestOptions; + parseRequestOptionsFromJSON?( + options: PublicKeyCredentialRequestOptionsJSON, + ): PublicKeyCredentialRequestOptions; // See https://w3c.github.io/webauthn/#dom-publickeycredential-tojson toJSON?(): PublicKeyCredentialJSON; } -- cgit v1.2.3