diff --git a/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts b/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts index e19bbd9d..1eca3321 100644 --- a/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts +++ b/packages/browser/src/helpers/toPublicKeyCredentialDescriptor.ts @@ -2,6 +2,7 @@ import type { AuthenticatorTransport, PublicKeyCredentialDescriptor, PublicKeyCredentialDescriptorJSON, + PublicKeyCredentialType, } from '../types/index.ts'; import { base64URLStringToBuffer } from './base64URLStringToBuffer.ts'; @@ -13,11 +14,7 @@ export function toPublicKeyCredentialDescriptor( return { ...descriptor, id: base64URLStringToBuffer(id), - /** - * `descriptor.transports` is an array of our `AuthenticatorTransportFuture` that includes newer - * transports that TypeScript's DOM lib is ignorant of. Convince TS that our list of transports - * are fine to pass to WebAuthn since browsers will recognize the new value. - */ transports: descriptor.transports as AuthenticatorTransport[], + type: descriptor.type as PublicKeyCredentialType, }; } diff --git a/packages/browser/src/methods/startAuthentication.ts b/packages/browser/src/methods/startAuthentication.ts index 2a95e56f..5260e38a 100644 --- a/packages/browser/src/methods/startAuthentication.ts +++ b/packages/browser/src/methods/startAuthentication.ts @@ -105,7 +105,10 @@ export async function startAuthentication( // Wait for the user to complete assertion let credential; try { - credential = (await navigator.credentials.get(getOptions as globalThis.CredentialRequestOptions)) as AuthenticationCredential; + credential = (await navigator.credentials.get( + // TODO: Newer versions of Deno require this casting, revisit once we're using Deno 2.6+ + getOptions as globalThis.CredentialRequestOptions, + )) as AuthenticationCredential; } catch (err) { throw identifyAuthenticationError({ error: err as Error, options: getOptions }); } diff --git a/packages/browser/src/methods/startRegistration.ts b/packages/browser/src/methods/startRegistration.ts index a601526a..918be719 100644 --- a/packages/browser/src/methods/startRegistration.ts +++ b/packages/browser/src/methods/startRegistration.ts @@ -1,5 +1,4 @@ import type { - AuthenticatorTransportFuture, CredentialCreationOptions, PublicKeyCredentialCreationOptions, PublicKeyCredentialCreationOptionsJSON, @@ -78,7 +77,10 @@ export async function startRegistration( // Wait for the user to complete attestation let credential; try { - credential = (await navigator.credentials.create(createOptions as globalThis.CredentialCreationOptions)) as RegistrationCredential; + credential = (await navigator.credentials.create( + // TODO: Newer versions of Deno require this casting, revisit once we're using Deno 2.6+ + createOptions as globalThis.CredentialCreationOptions, + )) as RegistrationCredential; } catch (err) { throw identifyRegistrationError({ error: err as Error, options: createOptions }); } @@ -90,7 +92,7 @@ export async function startRegistration( const { id, rawId, response, type } = credential; // Continue to play it safe with `getTransports()` for now, even when L3 types say it's required - let transports: AuthenticatorTransportFuture[] | undefined = undefined; + let transports: string[] | undefined = undefined; if (typeof response.getTransports === 'function') { transports = response.getTransports(); } diff --git a/packages/browser/src/types/dom.ts b/packages/browser/src/types/dom.ts index 38eb272e..d3ad8e0e 100644 --- a/packages/browser/src/types/dom.ts +++ b/packages/browser/src/types/dom.ts @@ -136,6 +136,12 @@ export interface PublicKeyCredentialDescriptor { type: PublicKeyCredentialType; } +export interface PublicKeyCredentialDescriptorJSON { + id: Base64URLString; + transports?: string[]; + type: string; +} + export interface PublicKeyCredentialParameters { alg: COSEAlgorithmIdentifier; type: PublicKeyCredentialType; @@ -592,6 +598,7 @@ export interface RsaKeyGenParams extends Algorithm { export type AttestationConveyancePreference = "direct" | "enterprise" | "indirect" | "none"; export type AuthenticatorTransport = "ble" | "hybrid" | "internal" | "nfc" | "usb"; +export type Base64URLString = string; export type COSEAlgorithmIdentifier = number; export type ResidentKeyRequirement = "discouraged" | "preferred" | "required"; export type UserVerificationRequirement = "discouraged" | "preferred" | "required"; diff --git a/packages/browser/src/types/index.ts b/packages/browser/src/types/index.ts index 915f8bd7..e565d1c3 100644 --- a/packages/browser/src/types/index.ts +++ b/packages/browser/src/types/index.ts @@ -16,10 +16,11 @@ import type { AuthenticatorAttachment, AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria, + Base64URLString, COSEAlgorithmIdentifier, PublicKeyCredential, PublicKeyCredentialCreationOptions, - PublicKeyCredentialDescriptor, + PublicKeyCredentialDescriptorJSON, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, @@ -36,6 +37,7 @@ export type { AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria, AuthenticatorTransport, + Base64URLString, COSEAlgorithmIdentifier, CredentialCreationOptions, CredentialRequestOptions, @@ -43,6 +45,7 @@ export type { PublicKeyCredential, PublicKeyCredentialCreationOptions, PublicKeyCredentialDescriptor, + PublicKeyCredentialDescriptorJSON, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, @@ -89,15 +92,6 @@ export interface PublicKeyCredentialRequestOptionsJSON { extensions?: AuthenticationExtensionsClientInputs; } -/** - * https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptorjson - */ -export interface PublicKeyCredentialDescriptorJSON { - id: Base64URLString; - type: PublicKeyCredentialType; - transports?: AuthenticatorTransportFuture[]; -} - /** * https://w3c.github.io/webauthn/#dictdef-publickeycredentialuserentityjson */ @@ -111,7 +105,7 @@ export interface PublicKeyCredentialUserEntityJSON { * The value returned from navigator.credentials.create() */ export interface RegistrationCredential extends PublicKeyCredentialFuture { - response: AuthenticatorAttestationResponseFuture; + response: AuthenticatorAttestationResponse; } /** @@ -163,7 +157,7 @@ export interface AuthenticatorAttestationResponseJSON { // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation authenticatorData?: Base64URLString; // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation - transports?: AuthenticatorTransportFuture[]; + transports?: string[]; // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation publicKeyAlgorithm?: COSEAlgorithmIdentifier; publicKey?: Base64URLString; @@ -190,52 +184,10 @@ export type WebAuthnCredential = { publicKey: Uint8Array_; // Number of times this authenticator is expected to have been used counter: number; - // From browser's `startRegistration()` -> RegistrationCredentialJSON.transports (API L2 and up) - transports?: AuthenticatorTransportFuture[]; + // From browser's `startRegistration()` -> RegistrationCredential.response.transports (API L2 and up) + transports?: string[]; }; -/** - * An attempt to communicate that this isn't just any string, but a Base64URL-encoded string - */ -export type Base64URLString = string; - -/** - * AuthenticatorAttestationResponse in TypeScript's DOM lib is outdated (up through v3.9.7). - * Maintain an augmented version here so we can implement additional properties as the WebAuthn - * spec evolves. - * - * See https://www.w3.org/TR/webauthn-2/#iface-authenticatorattestationresponse - * - * Properties marked optional are not supported in all browsers. - */ -export interface AuthenticatorAttestationResponseFuture extends AuthenticatorAttestationResponse { - getTransports(): AuthenticatorTransportFuture[]; -} - -/** - * 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 AuthenticatorTransportFuture = - | 'ble' - | 'cable' - | 'hybrid' - | 'internal' - | 'nfc' - | 'smart-card' - | 'usb'; - -/** - * 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 { - transports?: AuthenticatorTransportFuture[]; -} - /** */ export type PublicKeyCredentialJSON = | RegistrationResponseJSON diff --git a/packages/server/src/authentication/generateAuthenticationOptions.ts b/packages/server/src/authentication/generateAuthenticationOptions.ts index 21db84d4..f0d9f8d0 100644 --- a/packages/server/src/authentication/generateAuthenticationOptions.ts +++ b/packages/server/src/authentication/generateAuthenticationOptions.ts @@ -1,6 +1,5 @@ import type { AuthenticationExtensionsClientInputs, - AuthenticatorTransportFuture, Base64URLString, PublicKeyCredentialRequestOptionsJSON, Uint8Array_, @@ -27,7 +26,7 @@ export async function generateAuthenticationOptions( rpID: string; allowCredentials?: { id: Base64URLString; - transports?: AuthenticatorTransportFuture[]; + transports?: string[]; }[]; challenge?: string | Uint8Array_; timeout?: number; diff --git a/packages/server/src/registration/generateRegistrationOptions.ts b/packages/server/src/registration/generateRegistrationOptions.ts index 1065c009..12fc23c2 100644 --- a/packages/server/src/registration/generateRegistrationOptions.ts +++ b/packages/server/src/registration/generateRegistrationOptions.ts @@ -1,7 +1,6 @@ import type { AuthenticationExtensionsClientInputs, AuthenticatorSelectionCriteria, - AuthenticatorTransportFuture, Base64URLString, COSEAlgorithmIdentifier, PublicKeyCredentialCreationOptionsJSON, @@ -94,7 +93,7 @@ export async function generateRegistrationOptions( attestationType?: 'direct' | 'enterprise' | 'none'; excludeCredentials?: { id: Base64URLString; - transports?: AuthenticatorTransportFuture[]; + transports?: string[]; }[]; authenticatorSelection?: AuthenticatorSelectionCriteria; extensions?: AuthenticationExtensionsClientInputs; diff --git a/packages/server/src/types/dom.ts b/packages/server/src/types/dom.ts index 38eb272e..d3ad8e0e 100644 --- a/packages/server/src/types/dom.ts +++ b/packages/server/src/types/dom.ts @@ -136,6 +136,12 @@ export interface PublicKeyCredentialDescriptor { type: PublicKeyCredentialType; } +export interface PublicKeyCredentialDescriptorJSON { + id: Base64URLString; + transports?: string[]; + type: string; +} + export interface PublicKeyCredentialParameters { alg: COSEAlgorithmIdentifier; type: PublicKeyCredentialType; @@ -592,6 +598,7 @@ export interface RsaKeyGenParams extends Algorithm { export type AttestationConveyancePreference = "direct" | "enterprise" | "indirect" | "none"; export type AuthenticatorTransport = "ble" | "hybrid" | "internal" | "nfc" | "usb"; +export type Base64URLString = string; export type COSEAlgorithmIdentifier = number; export type ResidentKeyRequirement = "discouraged" | "preferred" | "required"; export type UserVerificationRequirement = "discouraged" | "preferred" | "required"; diff --git a/packages/server/src/types/index.ts b/packages/server/src/types/index.ts index 915f8bd7..e565d1c3 100644 --- a/packages/server/src/types/index.ts +++ b/packages/server/src/types/index.ts @@ -16,10 +16,11 @@ import type { AuthenticatorAttachment, AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria, + Base64URLString, COSEAlgorithmIdentifier, PublicKeyCredential, PublicKeyCredentialCreationOptions, - PublicKeyCredentialDescriptor, + PublicKeyCredentialDescriptorJSON, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, @@ -36,6 +37,7 @@ export type { AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria, AuthenticatorTransport, + Base64URLString, COSEAlgorithmIdentifier, CredentialCreationOptions, CredentialRequestOptions, @@ -43,6 +45,7 @@ export type { PublicKeyCredential, PublicKeyCredentialCreationOptions, PublicKeyCredentialDescriptor, + PublicKeyCredentialDescriptorJSON, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, @@ -89,15 +92,6 @@ export interface PublicKeyCredentialRequestOptionsJSON { extensions?: AuthenticationExtensionsClientInputs; } -/** - * https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptorjson - */ -export interface PublicKeyCredentialDescriptorJSON { - id: Base64URLString; - type: PublicKeyCredentialType; - transports?: AuthenticatorTransportFuture[]; -} - /** * https://w3c.github.io/webauthn/#dictdef-publickeycredentialuserentityjson */ @@ -111,7 +105,7 @@ export interface PublicKeyCredentialUserEntityJSON { * The value returned from navigator.credentials.create() */ export interface RegistrationCredential extends PublicKeyCredentialFuture { - response: AuthenticatorAttestationResponseFuture; + response: AuthenticatorAttestationResponse; } /** @@ -163,7 +157,7 @@ export interface AuthenticatorAttestationResponseJSON { // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation authenticatorData?: Base64URLString; // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation - transports?: AuthenticatorTransportFuture[]; + transports?: string[]; // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation publicKeyAlgorithm?: COSEAlgorithmIdentifier; publicKey?: Base64URLString; @@ -190,52 +184,10 @@ export type WebAuthnCredential = { publicKey: Uint8Array_; // Number of times this authenticator is expected to have been used counter: number; - // From browser's `startRegistration()` -> RegistrationCredentialJSON.transports (API L2 and up) - transports?: AuthenticatorTransportFuture[]; + // From browser's `startRegistration()` -> RegistrationCredential.response.transports (API L2 and up) + transports?: string[]; }; -/** - * An attempt to communicate that this isn't just any string, but a Base64URL-encoded string - */ -export type Base64URLString = string; - -/** - * AuthenticatorAttestationResponse in TypeScript's DOM lib is outdated (up through v3.9.7). - * Maintain an augmented version here so we can implement additional properties as the WebAuthn - * spec evolves. - * - * See https://www.w3.org/TR/webauthn-2/#iface-authenticatorattestationresponse - * - * Properties marked optional are not supported in all browsers. - */ -export interface AuthenticatorAttestationResponseFuture extends AuthenticatorAttestationResponse { - getTransports(): AuthenticatorTransportFuture[]; -} - -/** - * 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 AuthenticatorTransportFuture = - | 'ble' - | 'cable' - | 'hybrid' - | 'internal' - | 'nfc' - | 'smart-card' - | 'usb'; - -/** - * 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 { - transports?: AuthenticatorTransportFuture[]; -} - /** */ export type PublicKeyCredentialJSON = | RegistrationResponseJSON diff --git a/packages/types/extract-dom-types.ts b/packages/types/extract-dom-types.ts index 2e9c301e..0c0b0610 100644 --- a/packages/types/extract-dom-types.ts +++ b/packages/types/extract-dom-types.ts @@ -45,6 +45,7 @@ const types = [ 'AuthenticationExtensionsClientInputs', 'AuthenticationExtensionsClientOutputs', 'AuthenticatorSelectionCriteria', + 'Base64URLString', 'COSEAlgorithmIdentifier', 'CredentialCreationOptions', 'CredentialRequestOptions', @@ -52,6 +53,7 @@ const types = [ 'PublicKeyCredential', 'PublicKeyCredentialCreationOptions', 'PublicKeyCredentialDescriptor', + 'PublicKeyCredentialDescriptorJSON', 'PublicKeyCredentialParameters', 'PublicKeyCredentialRequestOptions', 'PublicKeyCredentialUserEntity', diff --git a/packages/types/src/dom.ts b/packages/types/src/dom.ts index 82941cba..59e762ef 100644 --- a/packages/types/src/dom.ts +++ b/packages/types/src/dom.ts @@ -128,6 +128,12 @@ export interface PublicKeyCredentialDescriptor { type: PublicKeyCredentialType; } +export interface PublicKeyCredentialDescriptorJSON { + id: Base64URLString; + transports?: string[]; + type: string; +} + export interface PublicKeyCredentialParameters { alg: COSEAlgorithmIdentifier; type: PublicKeyCredentialType; @@ -584,6 +590,7 @@ export interface RsaKeyGenParams extends Algorithm { export type AttestationConveyancePreference = "direct" | "enterprise" | "indirect" | "none"; export type AuthenticatorTransport = "ble" | "hybrid" | "internal" | "nfc" | "usb"; +export type Base64URLString = string; export type COSEAlgorithmIdentifier = number; export type ResidentKeyRequirement = "discouraged" | "preferred" | "required"; export type UserVerificationRequirement = "discouraged" | "preferred" | "required"; diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index ae69b9c0..12a5857d 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -6,10 +6,11 @@ import type { AuthenticatorAttachment, AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria, + Base64URLString, COSEAlgorithmIdentifier, PublicKeyCredential, PublicKeyCredentialCreationOptions, - PublicKeyCredentialDescriptor, + PublicKeyCredentialDescriptorJSON, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, @@ -26,6 +27,7 @@ export type { AuthenticatorAttestationResponse, AuthenticatorSelectionCriteria, AuthenticatorTransport, + Base64URLString, COSEAlgorithmIdentifier, CredentialCreationOptions, CredentialRequestOptions, @@ -33,6 +35,7 @@ export type { PublicKeyCredential, PublicKeyCredentialCreationOptions, PublicKeyCredentialDescriptor, + PublicKeyCredentialDescriptorJSON, PublicKeyCredentialParameters, PublicKeyCredentialRequestOptions, PublicKeyCredentialRpEntity, @@ -79,15 +82,6 @@ export interface PublicKeyCredentialRequestOptionsJSON { extensions?: AuthenticationExtensionsClientInputs; } -/** - * https://w3c.github.io/webauthn/#dictdef-publickeycredentialdescriptorjson - */ -export interface PublicKeyCredentialDescriptorJSON { - id: Base64URLString; - type: PublicKeyCredentialType; - transports?: AuthenticatorTransportFuture[]; -} - /** * https://w3c.github.io/webauthn/#dictdef-publickeycredentialuserentityjson */ @@ -101,7 +95,7 @@ export interface PublicKeyCredentialUserEntityJSON { * The value returned from navigator.credentials.create() */ export interface RegistrationCredential extends PublicKeyCredentialFuture { - response: AuthenticatorAttestationResponseFuture; + response: AuthenticatorAttestationResponse; } /** @@ -153,7 +147,7 @@ export interface AuthenticatorAttestationResponseJSON { // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation authenticatorData?: Base64URLString; // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation - transports?: AuthenticatorTransportFuture[]; + transports?: string[]; // Optional in L2, but becomes required in L3. Play it safe until L3 becomes Recommendation publicKeyAlgorithm?: COSEAlgorithmIdentifier; publicKey?: Base64URLString; @@ -180,52 +174,10 @@ export type WebAuthnCredential = { publicKey: Uint8Array_; // Number of times this authenticator is expected to have been used counter: number; - // From browser's `startRegistration()` -> RegistrationCredentialJSON.transports (API L2 and up) - transports?: AuthenticatorTransportFuture[]; + // From browser's `startRegistration()` -> RegistrationCredential.response.transports (API L2 and up) + transports?: string[]; }; -/** - * An attempt to communicate that this isn't just any string, but a Base64URL-encoded string - */ -export type Base64URLString = string; - -/** - * AuthenticatorAttestationResponse in TypeScript's DOM lib is outdated (up through v3.9.7). - * Maintain an augmented version here so we can implement additional properties as the WebAuthn - * spec evolves. - * - * See https://www.w3.org/TR/webauthn-2/#iface-authenticatorattestationresponse - * - * Properties marked optional are not supported in all browsers. - */ -export interface AuthenticatorAttestationResponseFuture extends AuthenticatorAttestationResponse { - getTransports(): AuthenticatorTransportFuture[]; -} - -/** - * 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 AuthenticatorTransportFuture = - | 'ble' - | 'cable' - | 'hybrid' - | 'internal' - | 'nfc' - | 'smart-card' - | 'usb'; - -/** - * 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 { - transports?: AuthenticatorTransportFuture[]; -} - /** */ export type PublicKeyCredentialJSON = | RegistrationResponseJSON