diff options
author | Matthew Miller <matthew@millerti.me> | 2022-05-18 16:29:30 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-18 16:29:30 -0700 |
commit | c245be34b40c79c798661ce5869b49ec5a964ac3 (patch) | |
tree | 0e45394439b42b0339d4b5a48ac204458e570a69 | |
parent | c93517488b6efec5c72ff212b834f4c6138ad494 (diff) | |
parent | 97790e8c6f5f00a9875414aee3d4d7ed20f0f437 (diff) |
Merge pull request #203 from MasterKale/fix/authenticator-transports-override
fix/authenticator-transports-override
6 files changed, 25 insertions, 14 deletions
diff --git a/packages/server/src/authentication/generateAuthenticationOptions.ts b/packages/server/src/authentication/generateAuthenticationOptions.ts index f176835..54a81a3 100644 --- a/packages/server/src/authentication/generateAuthenticationOptions.ts +++ b/packages/server/src/authentication/generateAuthenticationOptions.ts @@ -1,7 +1,7 @@ import type { AuthenticationExtensionsClientInputs, PublicKeyCredentialRequestOptionsJSON, - PublicKeyCredentialDescriptor, + PublicKeyCredentialDescriptorFuture, UserVerificationRequirement, } from '@simplewebauthn/typescript-types'; import base64url from 'base64url'; @@ -9,7 +9,7 @@ import base64url from 'base64url'; import generateChallenge from '../helpers/generateChallenge'; export type GenerateAuthenticationOptionsOpts = { - allowCredentials?: PublicKeyCredentialDescriptor[]; + allowCredentials?: PublicKeyCredentialDescriptorFuture[]; challenge?: string | Buffer; timeout?: number; userVerification?: UserVerificationRequirement; diff --git a/packages/server/src/helpers/convertCertBufferToPEM.test.ts b/packages/server/src/helpers/convertCertBufferToPEM.test.ts index 91c5d6b..9f99128 100644 --- a/packages/server/src/helpers/convertCertBufferToPEM.test.ts +++ b/packages/server/src/helpers/convertCertBufferToPEM.test.ts @@ -20,7 +20,7 @@ dHJpbmcgY2VydEJ1ZmZlclN0cmluZw== }); test('should return pem when input is buffer', () => { - const input = new Buffer(128); + const input = Buffer.alloc(128); const actual = convertCertBufferToPEM(input); const actualPemArr = actual.split("\n"); expect(actual).toEqual(`-----BEGIN CERTIFICATE----- diff --git a/packages/server/src/helpers/toHash.test.ts b/packages/server/src/helpers/toHash.test.ts index de37390..4f012e5 100644 --- a/packages/server/src/helpers/toHash.test.ts +++ b/packages/server/src/helpers/toHash.test.ts @@ -6,6 +6,6 @@ test('should return a buffer of at 32 bytes for input string', () => { }); test('should return a buffer of at 32 bytes for input Buffer', () => { - const hash = toHash(new Buffer(10)); + const hash = toHash(Buffer.alloc(10)); expect(hash.byteLength).toEqual(32); }); diff --git a/packages/server/src/registration/generateRegistrationOptions.ts b/packages/server/src/registration/generateRegistrationOptions.ts index c55b308..f3cf5c2 100644 --- a/packages/server/src/registration/generateRegistrationOptions.ts +++ b/packages/server/src/registration/generateRegistrationOptions.ts @@ -4,7 +4,7 @@ import type { AuthenticatorSelectionCriteria, COSEAlgorithmIdentifier, PublicKeyCredentialCreationOptionsJSON, - PublicKeyCredentialDescriptor, + PublicKeyCredentialDescriptorFuture, PublicKeyCredentialParameters, } from '@simplewebauthn/typescript-types'; import base64url from 'base64url'; @@ -20,7 +20,7 @@ export type GenerateRegistrationOptionsOpts = { userDisplayName?: string; timeout?: number; attestationType?: AttestationConveyancePreference; - excludeCredentials?: PublicKeyCredentialDescriptor[]; + excludeCredentials?: PublicKeyCredentialDescriptorFuture[]; authenticatorSelection?: AuthenticatorSelectionCriteria; extensions?: AuthenticationExtensionsClientInputs; supportedAlgorithmIDs?: COSEAlgorithmIdentifier[]; diff --git a/packages/typescript-types/extract-dom-types.ts b/packages/typescript-types/extract-dom-types.ts index 75d16cc..856cb63 100644 --- a/packages/typescript-types/extract-dom-types.ts +++ b/packages/typescript-types/extract-dom-types.ts @@ -20,6 +20,7 @@ const types = [ 'AuthenticatorAssertionResponse', 'AttestationConveyancePreference', 'AuthenticatorAttestationResponse', + 'AuthenticatorTransport', 'AuthenticationExtensionsClientInputs', 'AuthenticationExtensionsClientOutputs', 'AuthenticatorSelectionCriteria', diff --git a/packages/typescript-types/src/index.ts b/packages/typescript-types/src/index.ts index 6381b80..b4bafc0 100644 --- a/packages/typescript-types/src/index.ts +++ b/packages/typescript-types/src/index.ts @@ -42,9 +42,9 @@ export interface PublicKeyCredentialRequestOptionsJSON } export interface PublicKeyCredentialDescriptorJSON - extends Omit<PublicKeyCredentialDescriptor, 'id' | 'transports'> { + extends Omit<PublicKeyCredentialDescriptorFuture, 'id' | 'transports'> { id: Base64URLString; - transports?: AuthenticatorTransport[]; + transports?: AuthenticatorTransportFuture[]; } export interface PublicKeyCredentialUserEntityJSON @@ -68,7 +68,7 @@ export interface RegistrationCredentialJSON rawId: Base64URLString; response: AuthenticatorAttestationResponseJSON; clientExtensionResults: AuthenticationExtensionsClientOutputs; - transports?: AuthenticatorTransport[]; + transports?: AuthenticatorTransportFuture[]; } /** @@ -123,7 +123,7 @@ export type AuthenticatorDevice = { // Number of times this authenticator is expected to have been used counter: number; // From browser's `startRegistration()` -> RegistrationCredentialJSON.transports (API L2 and up) - transports?: AuthenticatorTransport[]; + transports?: AuthenticatorTransportFuture[]; }; /** @@ -141,17 +141,27 @@ export type Base64URLString = string; * Properties marked optional are not supported in all browsers. */ export interface AuthenticatorAttestationResponseFuture extends AuthenticatorAttestationResponse { - getTransports?: () => AuthenticatorTransport[]; + getTransports?: () => AuthenticatorTransportFuture[]; getAuthenticatorData?: () => ArrayBuffer; getPublicKey?: () => ArrayBuffer; getPublicKeyAlgorithm?: () => COSEAlgorithmIdentifier[]; } /** - * Communication methods by which an authenticator can talk with the browser to perform WebAuthn - * registration and authentication. + * A super class of TypeScript's `AuthenticatorTransport` that includes support for the latest + * transports. Should eventually be replaced by TypeScript's when TypeScript gets updated to + * know about it (sometime after 4.6.3) */ -export type AuthenticatorTransport = "ble" | "internal" | "nfc" | "usb" | "cable"; +export type AuthenticatorTransportFuture = "ble" | "internal" | "nfc" | "usb" | "cable"; + +/** + * A super class of TypeScript's `PublicKeyCredentialDescriptor` that knows about the latest + * transports. Should eventually be replaced by TypeScript's when TypeScript gets updated to + * know about it (sometime after 4.6.3) + */ +export interface PublicKeyCredentialDescriptorFuture extends Omit<PublicKeyCredentialDescriptor, 'transports'> { + transports?: AuthenticatorTransportFuture[]; +} /** * The two types of credentials as defined by bit 3 ("Backup Eligibility") in authenticator data: |