@metamask/passkey-controller 1.0.0 → 2.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/CHANGELOG.md +34 -2
  2. package/README.md +30 -13
  3. package/dist/PasskeyController.cjs +182 -125
  4. package/dist/PasskeyController.cjs.map +1 -1
  5. package/dist/PasskeyController.d.cts +61 -60
  6. package/dist/PasskeyController.d.cts.map +1 -1
  7. package/dist/PasskeyController.d.mts +61 -60
  8. package/dist/PasskeyController.d.mts.map +1 -1
  9. package/dist/PasskeyController.mjs +184 -127
  10. package/dist/PasskeyController.mjs.map +1 -1
  11. package/dist/ceremony-manager.cjs +3 -2
  12. package/dist/ceremony-manager.cjs.map +1 -1
  13. package/dist/ceremony-manager.d.cts +3 -2
  14. package/dist/ceremony-manager.d.cts.map +1 -1
  15. package/dist/ceremony-manager.d.mts +3 -2
  16. package/dist/ceremony-manager.d.mts.map +1 -1
  17. package/dist/ceremony-manager.mjs +3 -2
  18. package/dist/ceremony-manager.mjs.map +1 -1
  19. package/dist/constants.cjs +2 -0
  20. package/dist/constants.cjs.map +1 -1
  21. package/dist/constants.d.cts +2 -0
  22. package/dist/constants.d.cts.map +1 -1
  23. package/dist/constants.d.mts +2 -0
  24. package/dist/constants.d.mts.map +1 -1
  25. package/dist/constants.mjs +2 -0
  26. package/dist/constants.mjs.map +1 -1
  27. package/dist/key-derivation.cjs +3 -35
  28. package/dist/key-derivation.cjs.map +1 -1
  29. package/dist/key-derivation.d.cts +5 -28
  30. package/dist/key-derivation.d.cts.map +1 -1
  31. package/dist/key-derivation.d.mts +5 -28
  32. package/dist/key-derivation.d.mts.map +1 -1
  33. package/dist/key-derivation.mjs +2 -33
  34. package/dist/key-derivation.mjs.map +1 -1
  35. package/dist/types.cjs.map +1 -1
  36. package/dist/types.d.cts +1 -1
  37. package/dist/types.d.cts.map +1 -1
  38. package/dist/types.d.mts +1 -1
  39. package/dist/types.d.mts.map +1 -1
  40. package/dist/types.mjs.map +1 -1
  41. package/dist/utils/crypto.cjs +12 -1
  42. package/dist/utils/crypto.cjs.map +1 -1
  43. package/dist/utils/crypto.d.cts +7 -0
  44. package/dist/utils/crypto.d.cts.map +1 -1
  45. package/dist/utils/crypto.d.mts +7 -0
  46. package/dist/utils/crypto.d.mts.map +1 -1
  47. package/dist/utils/crypto.mjs +10 -0
  48. package/dist/utils/crypto.mjs.map +1 -1
  49. package/dist/webauthn/types.cjs.map +1 -1
  50. package/dist/webauthn/types.d.cts +1 -1
  51. package/dist/webauthn/types.d.cts.map +1 -1
  52. package/dist/webauthn/types.d.mts +1 -1
  53. package/dist/webauthn/types.d.mts.map +1 -1
  54. package/dist/webauthn/types.mjs.map +1 -1
  55. package/dist/webauthn/verify-authentication-response.cjs +3 -4
  56. package/dist/webauthn/verify-authentication-response.cjs.map +1 -1
  57. package/dist/webauthn/verify-authentication-response.d.cts +3 -2
  58. package/dist/webauthn/verify-authentication-response.d.cts.map +1 -1
  59. package/dist/webauthn/verify-authentication-response.d.mts +3 -2
  60. package/dist/webauthn/verify-authentication-response.d.mts.map +1 -1
  61. package/dist/webauthn/verify-authentication-response.mjs +3 -4
  62. package/dist/webauthn/verify-authentication-response.mjs.map +1 -1
  63. package/dist/webauthn/verify-registration-response.cjs +8 -6
  64. package/dist/webauthn/verify-registration-response.cjs.map +1 -1
  65. package/dist/webauthn/verify-registration-response.d.cts +5 -5
  66. package/dist/webauthn/verify-registration-response.d.cts.map +1 -1
  67. package/dist/webauthn/verify-registration-response.d.mts +5 -5
  68. package/dist/webauthn/verify-registration-response.d.mts.map +1 -1
  69. package/dist/webauthn/verify-registration-response.mjs +8 -6
  70. package/dist/webauthn/verify-registration-response.mjs.map +1 -1
  71. package/package.json +2 -2
@@ -28,7 +28,7 @@ import { verifySignature } from "./verify-signature.mjs";
28
28
  * @param opts.expectedChallenge - The base64url challenge that was issued
29
29
  * for this ceremony.
30
30
  * @param opts.expectedOrigin - One or more acceptable origins.
31
- * @param opts.expectedRPID - The Relying Party ID domain.
31
+ * @param opts.expectedRPIDs - Relying Party ID strings to match against `rpIdHash`.
32
32
  * @param opts.credential - The stored credential record to verify against.
33
33
  * @param opts.credential.id - The credential ID (base64url).
34
34
  * @param opts.credential.publicKey - The COSE-encoded public key bytes
@@ -41,7 +41,7 @@ import { verifySignature } from "./verify-signature.mjs";
41
41
  * authentication info (new counter, origin, RP ID).
42
42
  */
43
43
  export async function verifyAuthenticationResponse(opts) {
44
- const { response, expectedChallenge, expectedOrigin, expectedRPID, credential, requireUserVerification = false, } = opts;
44
+ const { response, expectedChallenge, expectedOrigin, expectedRPIDs, credential, requireUserVerification = false, } = opts;
45
45
  const { id, rawId, type: credentialType, response: assertionResponse, } = response;
46
46
  // Ensure credential specified an ID
47
47
  if (!id) {
@@ -90,8 +90,7 @@ export async function verifyAuthenticationResponse(opts) {
90
90
  const authDataBuffer = base64URLToBytes(assertionResponse.authenticatorData);
91
91
  const parsedAuthData = parseAuthenticatorData(authDataBuffer);
92
92
  const { rpIdHash, flags, counter } = parsedAuthData;
93
- // Make sure the response's RP ID is ours
94
- const matchedRPID = matchExpectedRPID(rpIdHash, [expectedRPID]);
93
+ const matchedRPID = expectedRPIDs.length > 0 ? matchExpectedRPID(rpIdHash, expectedRPIDs) : '';
95
94
  // WebAuthn only requires the user presence flag be true
96
95
  if (!flags.up) {
97
96
  throw new Error('User not present during authentication');
@@ -1 +1 @@
1
- {"version":3,"file":"verify-authentication-response.mjs","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAC1D,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAC9C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAG5C,OAAO,EAAE,gBAAgB,EAAE,8BAA0B;AACrD,OAAO,EAAE,oBAAoB,EAAE,sCAAkC;AACjE,OAAO,EAAE,iBAAiB,EAAE,mCAA+B;AAC3D,OA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tB,MAAM,EAAE,cAAc,CAAC,MAAM;YAC7B,IAAI,EAAE,WAAW;SAClB;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types';\nimport { base64URLToBytes } from '../utils/encoding';\nimport { decodeClientDataJSON } from './decode-client-data-json';\nimport { matchExpectedRPID } from './match-expected-rp-id';\nimport { parseAuthenticatorData } from './parse-authenticator-data';\nimport type { ParsedAuthenticatorData } from './types';\nimport type { PasskeyAuthenticationResponse } from './types';\nimport { verifySignature } from './verify-signature';\n\nexport type VerifiedAuthenticationResponse =\n | { verified: false; authenticationInfo?: never }\n | {\n verified: true;\n authenticationInfo: {\n credentialId: string;\n newCounter: number;\n userVerified: boolean;\n origin: string;\n rpID: string;\n };\n };\n\n/**\n * Verifies a WebAuthn authentication (assertion) response per\n * W3C WebAuthn Level 3 §7.2.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence, base64url consistency, and type.\n * 2. `clientDataJSON` -- type is `\"webauthn.get\"`, challenge and origin\n * match.\n * 3. `authenticatorData` -- RP ID hash matches, user-presence flag is\n * set, and optional user-verification flag is checked.\n * 4. Signature verification -- `signature` is verified over\n * `authData || SHA-256(clientDataJSON)` using the stored credential\n * public key (COSE-encoded).\n * 5. Counter monotonicity -- if either the stored or returned counter\n * is non-zero, the new counter must exceed the stored value.\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.get()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was issued\n * for this ceremony.\n * @param opts.expectedOrigin - One or more acceptable origins.\n * @param opts.expectedRPID - The Relying Party ID domain.\n * @param opts.credential - The stored credential record to verify against.\n * @param opts.credential.id - The credential ID (base64url).\n * @param opts.credential.publicKey - The COSE-encoded public key bytes\n * persisted during registration.\n * @param opts.credential.counter - The last known signature counter value.\n * @param opts.credential.transports - Optional authenticator transports.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @returns Verification result containing `verified` status and parsed\n * authentication info (new counter, origin, RP ID).\n */\nexport async function verifyAuthenticationResponse(opts: {\n response: PasskeyAuthenticationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPID: string;\n credential: {\n id: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n };\n requireUserVerification?: boolean;\n}): Promise<VerifiedAuthenticationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPID,\n credential,\n requireUserVerification = false,\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: assertionResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n if (typeof assertionResponse?.clientDataJSON !== 'string') {\n throw new Error('Credential response clientDataJSON was not a string');\n }\n\n const clientDataJSON = decodeClientDataJSON(assertionResponse.clientDataJSON);\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an authentication\n if (type !== 'webauthn.get') {\n throw new Error(`Unexpected authentication response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected authentication response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected authentication response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (\n assertionResponse.userHandle &&\n typeof assertionResponse.userHandle !== 'string'\n ) {\n throw new Error('Credential response userHandle was not a string');\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(`Unexpected tokenBinding status ${tokenBinding.status}`);\n }\n }\n\n const authDataBuffer = base64URLToBytes(assertionResponse.authenticatorData);\n const parsedAuthData: ParsedAuthenticatorData =\n parseAuthenticatorData(authDataBuffer);\n const { rpIdHash, flags, counter } = parsedAuthData;\n\n // Make sure the response's RP ID is ours\n const matchedRPID = matchExpectedRPID(rpIdHash, [expectedRPID]);\n\n // WebAuthn only requires the user presence flag be true\n if (!flags.up) {\n throw new Error('User not present during authentication');\n }\n\n // Enforce user verification if required\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification required, but user could not be verified',\n );\n }\n\n const clientDataHash = sha256(\n base64URLToBytes(assertionResponse.clientDataJSON),\n );\n const signatureBase = concatBytes([authDataBuffer, clientDataHash]);\n\n const signature = base64URLToBytes(assertionResponse.signature);\n\n const cosePublicKey = decodePartialCBOR(\n new Uint8Array(credential.publicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n\n const verified = await verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n\n if (!verified) {\n return { verified: false };\n }\n\n if (\n (counter > 0 || credential.counter > 0) &&\n counter <= credential.counter\n ) {\n throw new Error(\n `Response counter value ${counter} must be greater than stored counter ${credential.counter}`,\n );\n }\n\n return {\n verified: true,\n authenticationInfo: {\n credentialId: credential.id,\n newCounter: counter,\n userVerified: flags.uv,\n origin: clientDataJSON.origin,\n rpID: matchedRPID,\n },\n };\n}\n"]}
1
+ {"version":3,"file":"verify-authentication-response.mjs","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAC1D,OAAO,EAAE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AI,KAAK,CACb,0BAA0B,OAAO,wCAAwC,UAAU,CAAC,OAAO,EAAE,CAC9F,CAAC;IACJ,CAAC;IAED,OAAO;QACL,QAAQ,EAAE,IAAI;QACd,kBAAkB,EAAE;YAClB,YAAY,EAAE,UAAU,CAAC,EAAE;YAC3B,UAAU,EAAE,OAAO;YACnB,YAAY,EAAE,KAAK,CAAC,EAAE;YACtB,MAAM,EAAE,cAAc,CAAC,MAAM;YAC7B,IAAI,EAAE,WAAW;SAClB;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types';\nimport { base64URLToBytes } from '../utils/encoding';\nimport { decodeClientDataJSON } from './decode-client-data-json';\nimport { matchExpectedRPID } from './match-expected-rp-id';\nimport { parseAuthenticatorData } from './parse-authenticator-data';\nimport type { ParsedAuthenticatorData } from './types';\nimport type { PasskeyAuthenticationResponse } from './types';\nimport { verifySignature } from './verify-signature';\n\nexport type VerifiedAuthenticationResponse =\n | { verified: false; authenticationInfo?: never }\n | {\n verified: true;\n authenticationInfo: {\n credentialId: string;\n newCounter: number;\n userVerified: boolean;\n origin: string;\n /** Matched RP ID, or `\"\"` when `expectedRPIDs` is empty (RP ID hash check skipped). */\n rpID: string;\n };\n };\n\n/**\n * Verifies a WebAuthn authentication (assertion) response per\n * W3C WebAuthn Level 3 §7.2.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence, base64url consistency, and type.\n * 2. `clientDataJSON` -- type is `\"webauthn.get\"`, challenge and origin\n * match.\n * 3. `authenticatorData` -- RP ID hash matches, user-presence flag is\n * set, and optional user-verification flag is checked.\n * 4. Signature verification -- `signature` is verified over\n * `authData || SHA-256(clientDataJSON)` using the stored credential\n * public key (COSE-encoded).\n * 5. Counter monotonicity -- if either the stored or returned counter\n * is non-zero, the new counter must exceed the stored value.\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.get()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was issued\n * for this ceremony.\n * @param opts.expectedOrigin - One or more acceptable origins.\n * @param opts.expectedRPIDs - Relying Party ID strings to match against `rpIdHash`.\n * @param opts.credential - The stored credential record to verify against.\n * @param opts.credential.id - The credential ID (base64url).\n * @param opts.credential.publicKey - The COSE-encoded public key bytes\n * persisted during registration.\n * @param opts.credential.counter - The last known signature counter value.\n * @param opts.credential.transports - Optional authenticator transports.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @returns Verification result containing `verified` status and parsed\n * authentication info (new counter, origin, RP ID).\n */\nexport async function verifyAuthenticationResponse(opts: {\n response: PasskeyAuthenticationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPIDs: string[];\n credential: {\n id: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n };\n requireUserVerification?: boolean;\n}): Promise<VerifiedAuthenticationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPIDs,\n credential,\n requireUserVerification = false,\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: assertionResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n if (typeof assertionResponse?.clientDataJSON !== 'string') {\n throw new Error('Credential response clientDataJSON was not a string');\n }\n\n const clientDataJSON = decodeClientDataJSON(assertionResponse.clientDataJSON);\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an authentication\n if (type !== 'webauthn.get') {\n throw new Error(`Unexpected authentication response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected authentication response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected authentication response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (\n assertionResponse.userHandle &&\n typeof assertionResponse.userHandle !== 'string'\n ) {\n throw new Error('Credential response userHandle was not a string');\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(`Unexpected tokenBinding status ${tokenBinding.status}`);\n }\n }\n\n const authDataBuffer = base64URLToBytes(assertionResponse.authenticatorData);\n const parsedAuthData: ParsedAuthenticatorData =\n parseAuthenticatorData(authDataBuffer);\n const { rpIdHash, flags, counter } = parsedAuthData;\n\n const matchedRPID =\n expectedRPIDs.length > 0 ? matchExpectedRPID(rpIdHash, expectedRPIDs) : '';\n\n // WebAuthn only requires the user presence flag be true\n if (!flags.up) {\n throw new Error('User not present during authentication');\n }\n\n // Enforce user verification if required\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification required, but user could not be verified',\n );\n }\n\n const clientDataHash = sha256(\n base64URLToBytes(assertionResponse.clientDataJSON),\n );\n const signatureBase = concatBytes([authDataBuffer, clientDataHash]);\n\n const signature = base64URLToBytes(assertionResponse.signature);\n\n const cosePublicKey = decodePartialCBOR(\n new Uint8Array(credential.publicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n\n const verified = await verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n\n if (!verified) {\n return { verified: false };\n }\n\n if (\n (counter > 0 || credential.counter > 0) &&\n counter <= credential.counter\n ) {\n throw new Error(\n `Response counter value ${counter} must be greater than stored counter ${credential.counter}`,\n );\n }\n\n return {\n verified: true,\n authenticationInfo: {\n credentialId: credential.id,\n newCounter: counter,\n userVerified: flags.uv,\n origin: clientDataJSON.origin,\n rpID: matchedRPID,\n },\n };\n}\n"]}
@@ -33,10 +33,10 @@ const verify_signature_1 = require("./verify-signature.cjs");
33
33
  * `navigator.credentials.create()`, serialized as JSON.
34
34
  * @param opts.expectedChallenge - The base64url challenge that was passed
35
35
  * to the authenticator (must match `clientDataJSON.challenge`).
36
- * @param opts.expectedOrigin - One or more acceptable origins (e.g.
37
- * `"chrome-extension://..."` or `"https://metamask.io"`).
38
- * @param opts.expectedRPID - The Relying Party ID domain. The
39
- * authenticator's `rpIdHash` is compared against `SHA-256(expectedRPID)`.
36
+ * @param opts.expectedOrigin - One or more acceptable values for
37
+ * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.
38
+ * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's
39
+ * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.
40
40
  * @param opts.requireUserVerification - When `true`, verification fails
41
41
  * if the UV flag is not set. Defaults to `false`.
42
42
  * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted
@@ -46,7 +46,7 @@ const verify_signature_1 = require("./verify-signature.cjs");
46
46
  * hints. On failure, `{ verified: false }`.
47
47
  */
48
48
  async function verifyRegistrationResponse(opts) {
49
- const { response, expectedChallenge, expectedOrigin, expectedRPID, requireUserVerification = false, supportedAlgorithmIDs = [constants_1.COSEALG.EdDSA, constants_1.COSEALG.ES256, constants_1.COSEALG.RS256], } = opts;
49
+ const { response, expectedChallenge, expectedOrigin, expectedRPIDs, requireUserVerification = false, supportedAlgorithmIDs = [constants_1.COSEALG.EdDSA, constants_1.COSEALG.ES256, constants_1.COSEALG.RS256], } = opts;
50
50
  const { id, rawId, type: credentialType, response: attestationResponse, } = response;
51
51
  // Ensure credential specified an ID
52
52
  if (!id) {
@@ -92,7 +92,9 @@ async function verifyRegistrationResponse(opts) {
92
92
  const attStmt = decodedAttObj.get('attStmt');
93
93
  const parsedAuthData = (0, parse_authenticator_data_1.parseAuthenticatorData)(authData);
94
94
  const { rpIdHash, flags, counter, credentialID, credentialPublicKey, aaguid, } = parsedAuthData;
95
- (0, match_expected_rp_id_1.matchExpectedRPID)(rpIdHash, [expectedRPID]);
95
+ if (expectedRPIDs.length > 0) {
96
+ (0, match_expected_rp_id_1.matchExpectedRPID)(rpIdHash, expectedRPIDs);
97
+ }
96
98
  // Make sure someone was physically present
97
99
  if (!flags.up) {
98
100
  throw new Error('User presence was required, but user was not present');
@@ -1 +1 @@
1
- {"version":3,"file":"verify-registration-response.cjs","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":";;;AAAA,qDAA0D;AAC1D,2CAA8C;AAC9C,6CAA4C;AAG5C,oDAI2B;AAC3B,+CAAgD;AAChD,+EAAsE;AACtE,2EAAiE;AACjE,qEAA2D;AAC3D,6EAAoE;AAEpE,6DAAqD;AAiBrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,KAAK,UAAU,0BAA0B,CAAC,IAOhD;IACC,MAAM,EACJ,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,uBAAuB,GAAG,KAAK,EAC/B,qBAAqB,GAAG,CAAC,mBAAO,CAAC,KAAK,EAAE,mBAAO,CAAC,KAAK,EAAE,mBAAO,CAAC,KAAK,CAAC,GACtE,GAAG,IAAI,CAAC;IAET,MAAM,EACJ,EAAE,EACF,KAAK,EACL,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,mBAAmB,GAC9B,GAAG,QAAQ,CAAC;IAEb,oCAAoC;IACpC,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,KAAK,CAAC,uBAAuB,CAAC,CAAC;IAC3C,CAAC;IAED,iCAAiC;IACjC,IAAI,EAAE,KAAK,KAAK,EAAE,CAAC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,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IAED,IAAI,GAAG,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CACb,qGAAqG,CACtG,CAAC;IACJ,CAAC;IAED,MAAM,OAAO,GAAG,aAAa,CAAC,GAAG,CAAC,oBAAQ,CAAC,GAAG,CAAW,CAAC;IAC1D,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,0BAA0B,UAAU,kCAAkC,OAAO,EAAE,CAChF,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GAAG,IAAA,aAAM,EAAC,IAAA,2BAAgB,EAAC,oBAAoB,CAAC,CAAC,CAAC;IACtE,MAAM,aAAa,GAAG,IAAA,mBAAW,EAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAE9D,OAAO,IAAA,kCAAe,EAAC;QACrB,aAAa;QACb,SAAS;QACT,IAAI,EAAE,aAAa;KACpB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding';\nimport { COSEALG, COSEKEYS } from './constants';\nimport { decodeAttestationObject } from './decode-attestation-object';\nimport { decodeClientDataJSON } from './decode-client-data-json';\nimport { matchExpectedRPID } from './match-expected-rp-id';\nimport { parseAuthenticatorData } from './parse-authenticator-data';\nimport type { PasskeyRegistrationResponse } from './types';\nimport { verifySignature } from './verify-signature';\n\nexport type VerifiedRegistrationResponse =\n | { verified: false; registrationInfo?: never }\n | {\n verified: true;\n registrationInfo: {\n credentialId: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n aaguid: string;\n attestationFormat: string;\n userVerified: boolean;\n };\n };\n\n/**\n * Verifies a WebAuthn registration (attestation) response per\n * W3C WebAuthn Level 3 §7.1.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence and base64url consistency (`id === rawId`), and\n * that `id` matches the credential id inside parsed authenticator data.\n * 2. Credential type is `\"public-key\"`.\n * 3. `clientDataJSON` -- type is `\"webauthn.create\"`, challenge and origin\n * match the expected values.\n * 4. Attestation object -- CBOR-decodes and parses `authData` to verify\n * the RP ID hash, user-presence flag, optional user-verification flag,\n * and the attested credential public key algorithm.\n * 5. Attestation statement -- supports `\"none\"` (no signature) and\n * `\"packed\"` self-attestation (signature verified against the\n * credential's own public key).\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.create()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was passed\n * to the authenticator (must match `clientDataJSON.challenge`).\n * @param opts.expectedOrigin - One or more acceptable origins (e.g.\n * `\"chrome-extension://...\"` or `\"https://metamask.io\"`).\n * @param opts.expectedRPID - The Relying Party ID domain. The\n * authenticator's `rpIdHash` is compared against `SHA-256(expectedRPID)`.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted\n * for the credential public key. Defaults to EdDSA, ES256, and RS256.\n * @returns On success, `{ verified: true, registrationInfo }` with the\n * parsed credential ID, public key, counter, AAGUID, and transport\n * hints. On failure, `{ verified: false }`.\n */\nexport async function verifyRegistrationResponse(opts: {\n response: PasskeyRegistrationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPID: string;\n requireUserVerification?: boolean;\n supportedAlgorithmIDs?: number[];\n}): Promise<VerifiedRegistrationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPID,\n requireUserVerification = false,\n supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256],\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: attestationResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n const clientDataJSON = decodeClientDataJSON(\n attestationResponse.clientDataJSON,\n );\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an registration\n if (type !== 'webauthn.create') {\n throw new Error(`Unexpected registration response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected registration response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected registration response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(\n `Unexpected tokenBinding.status value of \"${tokenBinding.status}\"`,\n );\n }\n }\n\n const attestationObjectBytes = base64URLToBytes(\n attestationResponse.attestationObject,\n );\n const decodedAttObj = decodeAttestationObject(attestationObjectBytes);\n const fmt = decodedAttObj.get('fmt');\n const authData = decodedAttObj.get('authData');\n const attStmt = decodedAttObj.get('attStmt');\n\n const parsedAuthData = parseAuthenticatorData(authData);\n const {\n rpIdHash,\n flags,\n counter,\n credentialID,\n credentialPublicKey,\n aaguid,\n } = parsedAuthData;\n\n matchExpectedRPID(rpIdHash, [expectedRPID]);\n\n // Make sure someone was physically present\n if (!flags.up) {\n throw new Error('User presence was required, but user was not present');\n }\n\n // Enforce user verification if specified\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification was required, but user could not be verified',\n );\n }\n\n if (!credentialID) {\n throw new Error('No credential ID was provided by authenticator');\n }\n\n const attestedCredentialId = bytesToBase64URL(credentialID);\n if (id !== attestedCredentialId) {\n throw new Error(\n 'Credential id does not match the credential id in authenticator data',\n );\n }\n\n if (!credentialPublicKey) {\n throw new Error('No public key was provided by authenticator');\n }\n if (!aaguid) {\n throw new Error('No AAGUID was present during registration');\n }\n\n const decodedPublicKey = decodePartialCBOR(\n new Uint8Array(credentialPublicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n const alg = decodedPublicKey.get(COSEKEYS.Alg);\n\n if (typeof alg !== 'number') {\n throw new Error('Credential public key was missing numeric alg');\n }\n\n // Make sure the key algorithm is one we specified within the registration options\n if (!supportedAlgorithmIDs.includes(alg)) {\n throw new Error(\n `Unexpected public key alg \"${alg}\", expected one of \"${supportedAlgorithmIDs.join(', ')}\"`,\n );\n }\n\n let verified = false;\n if (fmt === 'none') {\n if (attStmt.size > 0) {\n throw new Error('None attestation had unexpected attestation statement');\n }\n verified = true;\n } else if (fmt === 'packed') {\n verified = await verifyPackedAttestation(\n attStmt,\n authData,\n attestationResponse.clientDataJSON,\n decodedPublicKey,\n );\n } else {\n throw new Error(`Unsupported attestation format: ${fmt}`);\n }\n\n if (!verified) {\n return { verified: false };\n }\n\n const aaguidHex = bytesToHex(aaguid);\n const aaguidStr = [\n aaguidHex.slice(0, 8),\n aaguidHex.slice(8, 12),\n aaguidHex.slice(12, 16),\n aaguidHex.slice(16, 20),\n aaguidHex.slice(20),\n ].join('-');\n\n return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: aaguidStr,\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate\n * chain, signature over `authData || SHA-256(clientDataJSON)` verified\n * with the credential's own public key, and `alg` in the attestation\n * statement must match the credential key's algorithm.\n *\n * @param attStmt - The attestation statement map from the attestation\n * object.\n * @param attStmt.get - Accessor to retrieve statement fields by key.\n * @param attStmt.size - Number of entries in the statement.\n * @param authData - Raw authenticator data bytes.\n * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.\n * @param cosePublicKey - Decoded COSE public key map from authenticator\n * data.\n * @returns Whether the packed attestation signature is valid.\n */\nasync function verifyPackedAttestation(\n attStmt: { get(key: string): unknown; size: number },\n authData: Uint8Array,\n clientDataJSONB64url: string,\n cosePublicKey: Map<number, number | Uint8Array>,\n): Promise<boolean> {\n const attStmtAlg = attStmt.get('alg') as number | undefined;\n const signature = attStmt.get('sig') as Uint8Array | undefined;\n const x5c = attStmt.get('x5c') as Uint8Array[] | undefined;\n\n if (typeof attStmtAlg !== 'number') {\n throw new Error('Packed attestation statement missing alg');\n }\n\n if (!signature) {\n throw new Error('Packed attestation missing signature');\n }\n\n if (x5c && x5c.length > 0) {\n throw new Error(\n 'Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted',\n );\n }\n\n const credAlg = cosePublicKey.get(COSEKEYS.Alg) as number;\n if (attStmtAlg !== credAlg) {\n throw new Error(\n `Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`,\n );\n }\n\n const clientDataHash = sha256(base64URLToBytes(clientDataJSONB64url));\n const signatureBase = concatBytes([authData, clientDataHash]);\n\n return verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n}\n"]}
1
+ {"version":3,"file":"verify-registration-response.cjs","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":";;;AAAA,qDAA0D;AAC1D,2CAA8C;AAC9C,6CAA4C;AAG5C,oDAI2B;AAC3B,+CAAgD;AAChD,+EAAsE;AACtE,2EAAiE;AACjE,qEAA2D;AAC3D,6EAAoE;AAEpE,6DAAqD;AAiB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QACb,SAAS;QACT,IAAI,EAAE,aAAa;KACpB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding';\nimport { COSEALG, COSEKEYS } from './constants';\nimport { decodeAttestationObject } from './decode-attestation-object';\nimport { decodeClientDataJSON } from './decode-client-data-json';\nimport { matchExpectedRPID } from './match-expected-rp-id';\nimport { parseAuthenticatorData } from './parse-authenticator-data';\nimport type { PasskeyRegistrationResponse } from './types';\nimport { verifySignature } from './verify-signature';\n\nexport type VerifiedRegistrationResponse =\n | { verified: false; registrationInfo?: never }\n | {\n verified: true;\n registrationInfo: {\n credentialId: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n aaguid: string;\n attestationFormat: string;\n userVerified: boolean;\n };\n };\n\n/**\n * Verifies a WebAuthn registration (attestation) response per\n * W3C WebAuthn Level 3 §7.1.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence and base64url consistency (`id === rawId`), and\n * that `id` matches the credential id inside parsed authenticator data.\n * 2. Credential type is `\"public-key\"`.\n * 3. `clientDataJSON` -- type is `\"webauthn.create\"`, challenge and origin\n * match the expected values.\n * 4. Attestation object -- CBOR-decodes and parses `authData` to verify\n * the RP ID hash, user-presence flag, optional user-verification flag,\n * and the attested credential public key algorithm.\n * 5. Attestation statement -- supports `\"none\"` (no signature) and\n * `\"packed\"` self-attestation (signature verified against the\n * credential's own public key).\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.create()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was passed\n * to the authenticator (must match `clientDataJSON.challenge`).\n * @param opts.expectedOrigin - One or more acceptable values for\n * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.\n * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's\n * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted\n * for the credential public key. Defaults to EdDSA, ES256, and RS256.\n * @returns On success, `{ verified: true, registrationInfo }` with the\n * parsed credential ID, public key, counter, AAGUID, and transport\n * hints. On failure, `{ verified: false }`.\n */\nexport async function verifyRegistrationResponse(opts: {\n response: PasskeyRegistrationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPIDs: string[];\n requireUserVerification?: boolean;\n supportedAlgorithmIDs?: number[];\n}): Promise<VerifiedRegistrationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPIDs,\n requireUserVerification = false,\n supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256],\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: attestationResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n const clientDataJSON = decodeClientDataJSON(\n attestationResponse.clientDataJSON,\n );\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an registration\n if (type !== 'webauthn.create') {\n throw new Error(`Unexpected registration response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected registration response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected registration response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(\n `Unexpected tokenBinding.status value of \"${tokenBinding.status}\"`,\n );\n }\n }\n\n const attestationObjectBytes = base64URLToBytes(\n attestationResponse.attestationObject,\n );\n const decodedAttObj = decodeAttestationObject(attestationObjectBytes);\n const fmt = decodedAttObj.get('fmt');\n const authData = decodedAttObj.get('authData');\n const attStmt = decodedAttObj.get('attStmt');\n\n const parsedAuthData = parseAuthenticatorData(authData);\n const {\n rpIdHash,\n flags,\n counter,\n credentialID,\n credentialPublicKey,\n aaguid,\n } = parsedAuthData;\n\n if (expectedRPIDs.length > 0) {\n matchExpectedRPID(rpIdHash, expectedRPIDs);\n }\n\n // Make sure someone was physically present\n if (!flags.up) {\n throw new Error('User presence was required, but user was not present');\n }\n\n // Enforce user verification if specified\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification was required, but user could not be verified',\n );\n }\n\n if (!credentialID) {\n throw new Error('No credential ID was provided by authenticator');\n }\n\n const attestedCredentialId = bytesToBase64URL(credentialID);\n if (id !== attestedCredentialId) {\n throw new Error(\n 'Credential id does not match the credential id in authenticator data',\n );\n }\n\n if (!credentialPublicKey) {\n throw new Error('No public key was provided by authenticator');\n }\n if (!aaguid) {\n throw new Error('No AAGUID was present during registration');\n }\n\n const decodedPublicKey = decodePartialCBOR(\n new Uint8Array(credentialPublicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n const alg = decodedPublicKey.get(COSEKEYS.Alg);\n\n if (typeof alg !== 'number') {\n throw new Error('Credential public key was missing numeric alg');\n }\n\n // Make sure the key algorithm is one we specified within the registration options\n if (!supportedAlgorithmIDs.includes(alg)) {\n throw new Error(\n `Unexpected public key alg \"${alg}\", expected one of \"${supportedAlgorithmIDs.join(', ')}\"`,\n );\n }\n\n let verified = false;\n if (fmt === 'none') {\n if (attStmt.size > 0) {\n throw new Error('None attestation had unexpected attestation statement');\n }\n verified = true;\n } else if (fmt === 'packed') {\n verified = await verifyPackedAttestation(\n attStmt,\n authData,\n attestationResponse.clientDataJSON,\n decodedPublicKey,\n );\n } else {\n throw new Error(`Unsupported attestation format: ${fmt}`);\n }\n\n if (!verified) {\n return { verified: false };\n }\n\n const aaguidHex = bytesToHex(aaguid);\n const aaguidStr = [\n aaguidHex.slice(0, 8),\n aaguidHex.slice(8, 12),\n aaguidHex.slice(12, 16),\n aaguidHex.slice(16, 20),\n aaguidHex.slice(20),\n ].join('-');\n\n return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: aaguidStr,\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate\n * chain, signature over `authData || SHA-256(clientDataJSON)` verified\n * with the credential's own public key, and `alg` in the attestation\n * statement must match the credential key's algorithm.\n *\n * @param attStmt - The attestation statement map from the attestation\n * object.\n * @param attStmt.get - Accessor to retrieve statement fields by key.\n * @param attStmt.size - Number of entries in the statement.\n * @param authData - Raw authenticator data bytes.\n * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.\n * @param cosePublicKey - Decoded COSE public key map from authenticator\n * data.\n * @returns Whether the packed attestation signature is valid.\n */\nasync function verifyPackedAttestation(\n attStmt: { get(key: string): unknown; size: number },\n authData: Uint8Array,\n clientDataJSONB64url: string,\n cosePublicKey: Map<number, number | Uint8Array>,\n): Promise<boolean> {\n const attStmtAlg = attStmt.get('alg') as number | undefined;\n const signature = attStmt.get('sig') as Uint8Array | undefined;\n const x5c = attStmt.get('x5c') as Uint8Array[] | undefined;\n\n if (typeof attStmtAlg !== 'number') {\n throw new Error('Packed attestation statement missing alg');\n }\n\n if (!signature) {\n throw new Error('Packed attestation missing signature');\n }\n\n if (x5c && x5c.length > 0) {\n throw new Error(\n 'Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted',\n );\n }\n\n const credAlg = cosePublicKey.get(COSEKEYS.Alg) as number;\n if (attStmtAlg !== credAlg) {\n throw new Error(\n `Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`,\n );\n }\n\n const clientDataHash = sha256(base64URLToBytes(clientDataJSONB64url));\n const signatureBase = concatBytes([authData, clientDataHash]);\n\n return verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n}\n"]}
@@ -37,10 +37,10 @@ export type VerifiedRegistrationResponse = {
37
37
  * `navigator.credentials.create()`, serialized as JSON.
38
38
  * @param opts.expectedChallenge - The base64url challenge that was passed
39
39
  * to the authenticator (must match `clientDataJSON.challenge`).
40
- * @param opts.expectedOrigin - One or more acceptable origins (e.g.
41
- * `"chrome-extension://..."` or `"https://metamask.io"`).
42
- * @param opts.expectedRPID - The Relying Party ID domain. The
43
- * authenticator's `rpIdHash` is compared against `SHA-256(expectedRPID)`.
40
+ * @param opts.expectedOrigin - One or more acceptable values for
41
+ * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.
42
+ * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's
43
+ * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.
44
44
  * @param opts.requireUserVerification - When `true`, verification fails
45
45
  * if the UV flag is not set. Defaults to `false`.
46
46
  * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted
@@ -53,7 +53,7 @@ export declare function verifyRegistrationResponse(opts: {
53
53
  response: PasskeyRegistrationResponse;
54
54
  expectedChallenge: string;
55
55
  expectedOrigin: string | string[];
56
- expectedRPID: string;
56
+ expectedRPIDs: string[];
57
57
  requireUserVerification?: boolean;
58
58
  supportedAlgorithmIDs?: number[];
59
59
  }): Promise<VerifiedRegistrationResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"verify-registration-response.d.cts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAiB;AAW7D,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAgB;AAG3D,MAAM,MAAM,4BAA4B,GACpC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAyLxC"}
1
+ {"version":3,"file":"verify-registration-response.d.cts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAiB;AAW7D,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAgB;AAG3D,MAAM,MAAM,4BAA4B,GACpC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CA2LxC"}
@@ -37,10 +37,10 @@ export type VerifiedRegistrationResponse = {
37
37
  * `navigator.credentials.create()`, serialized as JSON.
38
38
  * @param opts.expectedChallenge - The base64url challenge that was passed
39
39
  * to the authenticator (must match `clientDataJSON.challenge`).
40
- * @param opts.expectedOrigin - One or more acceptable origins (e.g.
41
- * `"chrome-extension://..."` or `"https://metamask.io"`).
42
- * @param opts.expectedRPID - The Relying Party ID domain. The
43
- * authenticator's `rpIdHash` is compared against `SHA-256(expectedRPID)`.
40
+ * @param opts.expectedOrigin - One or more acceptable values for
41
+ * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.
42
+ * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's
43
+ * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.
44
44
  * @param opts.requireUserVerification - When `true`, verification fails
45
45
  * if the UV flag is not set. Defaults to `false`.
46
46
  * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted
@@ -53,7 +53,7 @@ export declare function verifyRegistrationResponse(opts: {
53
53
  response: PasskeyRegistrationResponse;
54
54
  expectedChallenge: string;
55
55
  expectedOrigin: string | string[];
56
- expectedRPID: string;
56
+ expectedRPIDs: string[];
57
57
  requireUserVerification?: boolean;
58
58
  supportedAlgorithmIDs?: number[];
59
59
  }): Promise<VerifiedRegistrationResponse>;
@@ -1 +1 @@
1
- {"version":3,"file":"verify-registration-response.d.mts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAiB;AAW7D,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAgB;AAG3D,MAAM,MAAM,4BAA4B,GACpC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,YAAY,EAAE,MAAM,CAAC;IACrB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAyLxC"}
1
+ {"version":3,"file":"verify-registration-response.d.mts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAiB;AAW7D,OAAO,KAAK,EAAE,2BAA2B,EAAE,oBAAgB;AAG3D,MAAM,MAAM,4BAA4B,GACpC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,gBAAgB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC7C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,gBAAgB,EAAE;QAChB,YAAY,EAAE,MAAM,CAAC;QACrB,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;QAC5C,MAAM,EAAE,MAAM,CAAC;QACf,iBAAiB,EAAE,MAAM,CAAC;QAC1B,YAAY,EAAE,OAAO,CAAC;KACvB,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,0BAA0B,CAAC,IAAI,EAAE;IACrD,QAAQ,EAAE,2BAA2B,CAAC;IACtC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,uBAAuB,CAAC,EAAE,OAAO,CAAC;IAClC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;CAClC,GAAG,OAAO,CAAC,4BAA4B,CAAC,CA2LxC"}
@@ -30,10 +30,10 @@ import { verifySignature } from "./verify-signature.mjs";
30
30
  * `navigator.credentials.create()`, serialized as JSON.
31
31
  * @param opts.expectedChallenge - The base64url challenge that was passed
32
32
  * to the authenticator (must match `clientDataJSON.challenge`).
33
- * @param opts.expectedOrigin - One or more acceptable origins (e.g.
34
- * `"chrome-extension://..."` or `"https://metamask.io"`).
35
- * @param opts.expectedRPID - The Relying Party ID domain. The
36
- * authenticator's `rpIdHash` is compared against `SHA-256(expectedRPID)`.
33
+ * @param opts.expectedOrigin - One or more acceptable values for
34
+ * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.
35
+ * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's
36
+ * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.
37
37
  * @param opts.requireUserVerification - When `true`, verification fails
38
38
  * if the UV flag is not set. Defaults to `false`.
39
39
  * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted
@@ -43,7 +43,7 @@ import { verifySignature } from "./verify-signature.mjs";
43
43
  * hints. On failure, `{ verified: false }`.
44
44
  */
45
45
  export async function verifyRegistrationResponse(opts) {
46
- const { response, expectedChallenge, expectedOrigin, expectedRPID, requireUserVerification = false, supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256], } = opts;
46
+ const { response, expectedChallenge, expectedOrigin, expectedRPIDs, requireUserVerification = false, supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256], } = opts;
47
47
  const { id, rawId, type: credentialType, response: attestationResponse, } = response;
48
48
  // Ensure credential specified an ID
49
49
  if (!id) {
@@ -89,7 +89,9 @@ export async function verifyRegistrationResponse(opts) {
89
89
  const attStmt = decodedAttObj.get('attStmt');
90
90
  const parsedAuthData = parseAuthenticatorData(authData);
91
91
  const { rpIdHash, flags, counter, credentialID, credentialPublicKey, aaguid, } = parsedAuthData;
92
- matchExpectedRPID(rpIdHash, [expectedRPID]);
92
+ if (expectedRPIDs.length > 0) {
93
+ matchExpectedRPID(rpIdHash, expectedRPIDs);
94
+ }
93
95
  // Make sure someone was physically present
94
96
  if (!flags.up) {
95
97
  throw new Error('User presence was required, but user was not present');
@@ -1 +1 @@
1
- {"version":3,"file":"verify-registration-response.mjs","sour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CAAC,QAAQ,CAAC,GAAG,CAAW,CAAC;IAC1D,IAAI,UAAU,KAAK,OAAO,EAAE,CAAC;QAC3B,MAAM,IAAI,KAAK,CACb,0BAA0B,UAAU,kCAAkC,OAAO,EAAE,CAChF,CAAC;IACJ,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,CAAC,gBAAgB,CAAC,oBAAoB,CAAC,CAAC,CAAC;IACtE,MAAM,aAAa,GAAG,WAAW,CAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;IAE9D,OAAO,eAAe,CAAC;QACrB,aAAa;QACb,SAAS;QACT,IAAI,EAAE,aAAa;KACpB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding';\nimport { COSEALG, COSEKEYS } from './constants';\nimport { decodeAttestationObject } from './decode-attestation-object';\nimport { decodeClientDataJSON } from './decode-client-data-json';\nimport { matchExpectedRPID } from './match-expected-rp-id';\nimport { parseAuthenticatorData } from './parse-authenticator-data';\nimport type { PasskeyRegistrationResponse } from './types';\nimport { verifySignature } from './verify-signature';\n\nexport type VerifiedRegistrationResponse =\n | { verified: false; registrationInfo?: never }\n | {\n verified: true;\n registrationInfo: {\n credentialId: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n aaguid: string;\n attestationFormat: string;\n userVerified: boolean;\n };\n };\n\n/**\n * Verifies a WebAuthn registration (attestation) response per\n * W3C WebAuthn Level 3 §7.1.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence and base64url consistency (`id === rawId`), and\n * that `id` matches the credential id inside parsed authenticator data.\n * 2. Credential type is `\"public-key\"`.\n * 3. `clientDataJSON` -- type is `\"webauthn.create\"`, challenge and origin\n * match the expected values.\n * 4. Attestation object -- CBOR-decodes and parses `authData` to verify\n * the RP ID hash, user-presence flag, optional user-verification flag,\n * and the attested credential public key algorithm.\n * 5. Attestation statement -- supports `\"none\"` (no signature) and\n * `\"packed\"` self-attestation (signature verified against the\n * credential's own public key).\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.create()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was passed\n * to the authenticator (must match `clientDataJSON.challenge`).\n * @param opts.expectedOrigin - One or more acceptable origins (e.g.\n * `\"chrome-extension://...\"` or `\"https://metamask.io\"`).\n * @param opts.expectedRPID - The Relying Party ID domain. The\n * authenticator's `rpIdHash` is compared against `SHA-256(expectedRPID)`.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted\n * for the credential public key. Defaults to EdDSA, ES256, and RS256.\n * @returns On success, `{ verified: true, registrationInfo }` with the\n * parsed credential ID, public key, counter, AAGUID, and transport\n * hints. On failure, `{ verified: false }`.\n */\nexport async function verifyRegistrationResponse(opts: {\n response: PasskeyRegistrationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPID: string;\n requireUserVerification?: boolean;\n supportedAlgorithmIDs?: number[];\n}): Promise<VerifiedRegistrationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPID,\n requireUserVerification = false,\n supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256],\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: attestationResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n const clientDataJSON = decodeClientDataJSON(\n attestationResponse.clientDataJSON,\n );\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an registration\n if (type !== 'webauthn.create') {\n throw new Error(`Unexpected registration response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected registration response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected registration response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(\n `Unexpected tokenBinding.status value of \"${tokenBinding.status}\"`,\n );\n }\n }\n\n const attestationObjectBytes = base64URLToBytes(\n attestationResponse.attestationObject,\n );\n const decodedAttObj = decodeAttestationObject(attestationObjectBytes);\n const fmt = decodedAttObj.get('fmt');\n const authData = decodedAttObj.get('authData');\n const attStmt = decodedAttObj.get('attStmt');\n\n const parsedAuthData = parseAuthenticatorData(authData);\n const {\n rpIdHash,\n flags,\n counter,\n credentialID,\n credentialPublicKey,\n aaguid,\n } = parsedAuthData;\n\n matchExpectedRPID(rpIdHash, [expectedRPID]);\n\n // Make sure someone was physically present\n if (!flags.up) {\n throw new Error('User presence was required, but user was not present');\n }\n\n // Enforce user verification if specified\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification was required, but user could not be verified',\n );\n }\n\n if (!credentialID) {\n throw new Error('No credential ID was provided by authenticator');\n }\n\n const attestedCredentialId = bytesToBase64URL(credentialID);\n if (id !== attestedCredentialId) {\n throw new Error(\n 'Credential id does not match the credential id in authenticator data',\n );\n }\n\n if (!credentialPublicKey) {\n throw new Error('No public key was provided by authenticator');\n }\n if (!aaguid) {\n throw new Error('No AAGUID was present during registration');\n }\n\n const decodedPublicKey = decodePartialCBOR(\n new Uint8Array(credentialPublicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n const alg = decodedPublicKey.get(COSEKEYS.Alg);\n\n if (typeof alg !== 'number') {\n throw new Error('Credential public key was missing numeric alg');\n }\n\n // Make sure the key algorithm is one we specified within the registration options\n if (!supportedAlgorithmIDs.includes(alg)) {\n throw new Error(\n `Unexpected public key alg \"${alg}\", expected one of \"${supportedAlgorithmIDs.join(', ')}\"`,\n );\n }\n\n let verified = false;\n if (fmt === 'none') {\n if (attStmt.size > 0) {\n throw new Error('None attestation had unexpected attestation statement');\n }\n verified = true;\n } else if (fmt === 'packed') {\n verified = await verifyPackedAttestation(\n attStmt,\n authData,\n attestationResponse.clientDataJSON,\n decodedPublicKey,\n );\n } else {\n throw new Error(`Unsupported attestation format: ${fmt}`);\n }\n\n if (!verified) {\n return { verified: false };\n }\n\n const aaguidHex = bytesToHex(aaguid);\n const aaguidStr = [\n aaguidHex.slice(0, 8),\n aaguidHex.slice(8, 12),\n aaguidHex.slice(12, 16),\n aaguidHex.slice(16, 20),\n aaguidHex.slice(20),\n ].join('-');\n\n return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: aaguidStr,\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate\n * chain, signature over `authData || SHA-256(clientDataJSON)` verified\n * with the credential's own public key, and `alg` in the attestation\n * statement must match the credential key's algorithm.\n *\n * @param attStmt - The attestation statement map from the attestation\n * object.\n * @param attStmt.get - Accessor to retrieve statement fields by key.\n * @param attStmt.size - Number of entries in the statement.\n * @param authData - Raw authenticator data bytes.\n * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.\n * @param cosePublicKey - Decoded COSE public key map from authenticator\n * data.\n * @returns Whether the packed attestation signature is valid.\n */\nasync function verifyPackedAttestation(\n attStmt: { get(key: string): unknown; size: number },\n authData: Uint8Array,\n clientDataJSONB64url: string,\n cosePublicKey: Map<number, number | Uint8Array>,\n): Promise<boolean> {\n const attStmtAlg = attStmt.get('alg') as number | undefined;\n const signature = attStmt.get('sig') as Uint8Array | undefined;\n const x5c = attStmt.get('x5c') as Uint8Array[] | undefined;\n\n if (typeof attStmtAlg !== 'number') {\n throw new Error('Packed attestation statement missing alg');\n }\n\n if (!signature) {\n throw new Error('Packed attestation missing signature');\n }\n\n if (x5c && x5c.length > 0) {\n throw new Error(\n 'Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted',\n );\n }\n\n const credAlg = cosePublicKey.get(COSEKEYS.Alg) as number;\n if (attStmtAlg !== credAlg) {\n throw new Error(\n `Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`,\n );\n }\n\n const clientDataHash = sha256(base64URLToBytes(clientDataJSONB64url));\n const signatureBase = concatBytes([authData, clientDataHash]);\n\n return verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n}\n"]}
1
+ {"version":3,"file":"verify-registration-response.mjs","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAC1D,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAC9C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAG5C,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,EACX,8BAA0B;AAC3B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,wBAAoB;AAChD,OAAO,EAAE,uBAAuB,EAAE,wCAAoC;AACtE,OAAO,EAAE,oBAAoB,EAAE,sCAAkC;AACjE,OAAO,EAAE,iBAAiB,EAAE,mCAA+B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,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;KACpB,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding';\nimport { COSEALG, COSEKEYS } from './constants';\nimport { decodeAttestationObject } from './decode-attestation-object';\nimport { decodeClientDataJSON } from './decode-client-data-json';\nimport { matchExpectedRPID } from './match-expected-rp-id';\nimport { parseAuthenticatorData } from './parse-authenticator-data';\nimport type { PasskeyRegistrationResponse } from './types';\nimport { verifySignature } from './verify-signature';\n\nexport type VerifiedRegistrationResponse =\n | { verified: false; registrationInfo?: never }\n | {\n verified: true;\n registrationInfo: {\n credentialId: string;\n publicKey: Uint8Array;\n counter: number;\n transports?: AuthenticatorTransportFuture[];\n aaguid: string;\n attestationFormat: string;\n userVerified: boolean;\n };\n };\n\n/**\n * Verifies a WebAuthn registration (attestation) response per\n * W3C WebAuthn Level 3 §7.1.\n *\n * Performs the following checks in order:\n * 1. Credential ID presence and base64url consistency (`id === rawId`), and\n * that `id` matches the credential id inside parsed authenticator data.\n * 2. Credential type is `\"public-key\"`.\n * 3. `clientDataJSON` -- type is `\"webauthn.create\"`, challenge and origin\n * match the expected values.\n * 4. Attestation object -- CBOR-decodes and parses `authData` to verify\n * the RP ID hash, user-presence flag, optional user-verification flag,\n * and the attested credential public key algorithm.\n * 5. Attestation statement -- supports `\"none\"` (no signature) and\n * `\"packed\"` self-attestation (signature verified against the\n * credential's own public key).\n *\n * @param opts - Verification options.\n * @param opts.response - The `PublicKeyCredential` result from\n * `navigator.credentials.create()`, serialized as JSON.\n * @param opts.expectedChallenge - The base64url challenge that was passed\n * to the authenticator (must match `clientDataJSON.challenge`).\n * @param opts.expectedOrigin - One or more acceptable values for\n * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.\n * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's\n * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.\n * @param opts.requireUserVerification - When `true`, verification fails\n * if the UV flag is not set. Defaults to `false`.\n * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted\n * for the credential public key. Defaults to EdDSA, ES256, and RS256.\n * @returns On success, `{ verified: true, registrationInfo }` with the\n * parsed credential ID, public key, counter, AAGUID, and transport\n * hints. On failure, `{ verified: false }`.\n */\nexport async function verifyRegistrationResponse(opts: {\n response: PasskeyRegistrationResponse;\n expectedChallenge: string;\n expectedOrigin: string | string[];\n expectedRPIDs: string[];\n requireUserVerification?: boolean;\n supportedAlgorithmIDs?: number[];\n}): Promise<VerifiedRegistrationResponse> {\n const {\n response,\n expectedChallenge,\n expectedOrigin,\n expectedRPIDs,\n requireUserVerification = false,\n supportedAlgorithmIDs = [COSEALG.EdDSA, COSEALG.ES256, COSEALG.RS256],\n } = opts;\n\n const {\n id,\n rawId,\n type: credentialType,\n response: attestationResponse,\n } = response;\n\n // Ensure credential specified an ID\n if (!id) {\n throw new Error('Missing credential ID');\n }\n\n // Ensure ID is base64url-encoded\n if (id !== rawId) {\n throw new Error('Credential ID was not base64url-encoded');\n }\n\n // Make sure credential type is public-key\n if (credentialType !== 'public-key') {\n throw new Error(\n `Unexpected credential type ${String(credentialType)}, expected \"public-key\"`,\n );\n }\n\n const clientDataJSON = decodeClientDataJSON(\n attestationResponse.clientDataJSON,\n );\n const { type, challenge, origin, tokenBinding } = clientDataJSON;\n\n // Make sure we're handling an registration\n if (type !== 'webauthn.create') {\n throw new Error(`Unexpected registration response type: ${type}`);\n }\n\n // Ensure the device provided the challenge we gave it\n if (challenge !== expectedChallenge) {\n throw new Error(\n `Unexpected registration response challenge \"${challenge}\", expected \"${expectedChallenge}\"`,\n );\n }\n\n // Check that the origin is our site\n const expectedOrigins = Array.isArray(expectedOrigin)\n ? expectedOrigin\n : [expectedOrigin];\n if (!expectedOrigins.includes(origin)) {\n throw new Error(\n `Unexpected registration response origin \"${origin}\", expected one of: ${expectedOrigins.join(', ')}`,\n );\n }\n\n if (tokenBinding) {\n if (typeof tokenBinding !== 'object') {\n throw new Error('ClientDataJSON tokenBinding was not an object');\n }\n\n if (\n !['present', 'supported', 'not-supported'].includes(tokenBinding.status)\n ) {\n throw new Error(\n `Unexpected tokenBinding.status value of \"${tokenBinding.status}\"`,\n );\n }\n }\n\n const attestationObjectBytes = base64URLToBytes(\n attestationResponse.attestationObject,\n );\n const decodedAttObj = decodeAttestationObject(attestationObjectBytes);\n const fmt = decodedAttObj.get('fmt');\n const authData = decodedAttObj.get('authData');\n const attStmt = decodedAttObj.get('attStmt');\n\n const parsedAuthData = parseAuthenticatorData(authData);\n const {\n rpIdHash,\n flags,\n counter,\n credentialID,\n credentialPublicKey,\n aaguid,\n } = parsedAuthData;\n\n if (expectedRPIDs.length > 0) {\n matchExpectedRPID(rpIdHash, expectedRPIDs);\n }\n\n // Make sure someone was physically present\n if (!flags.up) {\n throw new Error('User presence was required, but user was not present');\n }\n\n // Enforce user verification if specified\n if (requireUserVerification && !flags.uv) {\n throw new Error(\n 'User verification was required, but user could not be verified',\n );\n }\n\n if (!credentialID) {\n throw new Error('No credential ID was provided by authenticator');\n }\n\n const attestedCredentialId = bytesToBase64URL(credentialID);\n if (id !== attestedCredentialId) {\n throw new Error(\n 'Credential id does not match the credential id in authenticator data',\n );\n }\n\n if (!credentialPublicKey) {\n throw new Error('No public key was provided by authenticator');\n }\n if (!aaguid) {\n throw new Error('No AAGUID was present during registration');\n }\n\n const decodedPublicKey = decodePartialCBOR(\n new Uint8Array(credentialPublicKey),\n 0,\n )[0] as Map<number, number | Uint8Array>;\n const alg = decodedPublicKey.get(COSEKEYS.Alg);\n\n if (typeof alg !== 'number') {\n throw new Error('Credential public key was missing numeric alg');\n }\n\n // Make sure the key algorithm is one we specified within the registration options\n if (!supportedAlgorithmIDs.includes(alg)) {\n throw new Error(\n `Unexpected public key alg \"${alg}\", expected one of \"${supportedAlgorithmIDs.join(', ')}\"`,\n );\n }\n\n let verified = false;\n if (fmt === 'none') {\n if (attStmt.size > 0) {\n throw new Error('None attestation had unexpected attestation statement');\n }\n verified = true;\n } else if (fmt === 'packed') {\n verified = await verifyPackedAttestation(\n attStmt,\n authData,\n attestationResponse.clientDataJSON,\n decodedPublicKey,\n );\n } else {\n throw new Error(`Unsupported attestation format: ${fmt}`);\n }\n\n if (!verified) {\n return { verified: false };\n }\n\n const aaguidHex = bytesToHex(aaguid);\n const aaguidStr = [\n aaguidHex.slice(0, 8),\n aaguidHex.slice(8, 12),\n aaguidHex.slice(12, 16),\n aaguidHex.slice(16, 20),\n aaguidHex.slice(20),\n ].join('-');\n\n return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: aaguidStr,\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate\n * chain, signature over `authData || SHA-256(clientDataJSON)` verified\n * with the credential's own public key, and `alg` in the attestation\n * statement must match the credential key's algorithm.\n *\n * @param attStmt - The attestation statement map from the attestation\n * object.\n * @param attStmt.get - Accessor to retrieve statement fields by key.\n * @param attStmt.size - Number of entries in the statement.\n * @param authData - Raw authenticator data bytes.\n * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.\n * @param cosePublicKey - Decoded COSE public key map from authenticator\n * data.\n * @returns Whether the packed attestation signature is valid.\n */\nasync function verifyPackedAttestation(\n attStmt: { get(key: string): unknown; size: number },\n authData: Uint8Array,\n clientDataJSONB64url: string,\n cosePublicKey: Map<number, number | Uint8Array>,\n): Promise<boolean> {\n const attStmtAlg = attStmt.get('alg') as number | undefined;\n const signature = attStmt.get('sig') as Uint8Array | undefined;\n const x5c = attStmt.get('x5c') as Uint8Array[] | undefined;\n\n if (typeof attStmtAlg !== 'number') {\n throw new Error('Packed attestation statement missing alg');\n }\n\n if (!signature) {\n throw new Error('Packed attestation missing signature');\n }\n\n if (x5c && x5c.length > 0) {\n throw new Error(\n 'Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted',\n );\n }\n\n const credAlg = cosePublicKey.get(COSEKEYS.Alg) as number;\n if (attStmtAlg !== credAlg) {\n throw new Error(\n `Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`,\n );\n }\n\n const clientDataHash = sha256(base64URLToBytes(clientDataJSONB64url));\n const signatureBase = concatBytes([authData, clientDataHash]);\n\n return verifySignature({\n cosePublicKey,\n signature,\n data: signatureBase,\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/passkey-controller",
3
- "version": "1.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Controller and utilities for passkey-based wallet unlock",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -54,7 +54,7 @@
54
54
  "dependencies": {
55
55
  "@levischuck/tiny-cbor": "^0.3.3",
56
56
  "@metamask/base-controller": "^9.1.0",
57
- "@metamask/messenger": "^1.1.1",
57
+ "@metamask/messenger": "^1.2.0",
58
58
  "@metamask/utils": "^11.9.0",
59
59
  "@noble/ciphers": "^1.3.0",
60
60
  "@noble/curves": "^1.9.2",