@metamask/passkey-controller 3.1.0 → 4.0.0
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.
- package/CHANGELOG.md +16 -1
- package/dist/{PasskeyController-method-action-types.d.mts → PasskeyController-method-action-types.d.ts} +2 -2
- package/dist/PasskeyController-method-action-types.d.ts.map +1 -0
- package/dist/{PasskeyController-method-action-types.mjs → PasskeyController-method-action-types.js} +1 -1
- package/dist/PasskeyController-method-action-types.js.map +1 -0
- package/dist/{PasskeyController.d.cts → PasskeyController.d.ts} +6 -6
- package/dist/PasskeyController.d.ts.map +1 -0
- package/dist/PasskeyController.js +680 -0
- package/dist/PasskeyController.js.map +1 -0
- package/dist/{ceremony-manager.d.cts → ceremony-manager.d.ts} +2 -2
- package/dist/ceremony-manager.d.ts.map +1 -0
- package/dist/ceremony-manager.js +135 -0
- package/dist/ceremony-manager.js.map +1 -0
- package/dist/{constants.d.mts → constants.d.ts} +12 -12
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +1 -1
- package/dist/constants.js.map +1 -0
- package/dist/{errors.d.mts → errors.d.ts} +2 -2
- package/dist/errors.d.ts.map +1 -0
- package/dist/{errors.mjs → errors.js} +4 -1
- package/dist/errors.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +8 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/{key-derivation.d.cts → key-derivation.d.ts} +3 -3
- package/dist/key-derivation.d.ts.map +1 -0
- package/dist/{key-derivation.mjs → key-derivation.js} +5 -5
- package/dist/key-derivation.js.map +1 -0
- package/dist/logger.d.ts +4 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +6 -0
- package/dist/logger.js.map +1 -0
- package/dist/{types.d.mts → types.d.ts} +6 -6
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/{crypto.d.mts → crypto.d.ts} +1 -1
- package/dist/utils/crypto.d.ts.map +1 -0
- package/dist/utils/{crypto.mjs → crypto.js} +7 -7
- package/dist/utils/crypto.js.map +1 -0
- package/dist/utils/{encoding.d.cts → encoding.d.ts} +1 -1
- package/dist/utils/encoding.d.ts.map +1 -0
- package/dist/utils/{encoding.mjs → encoding.js} +2 -2
- package/dist/utils/encoding.js.map +1 -0
- package/dist/webauthn/{constants.d.mts → constants.d.ts} +1 -1
- package/dist/webauthn/constants.d.ts.map +1 -0
- package/dist/webauthn/{constants.mjs → constants.js} +1 -1
- package/dist/webauthn/constants.js.map +1 -0
- package/dist/webauthn/{decode-attestation-object.d.mts → decode-attestation-object.d.ts} +2 -2
- package/dist/webauthn/decode-attestation-object.d.ts.map +1 -0
- package/dist/webauthn/{decode-attestation-object.mjs → decode-attestation-object.js} +2 -2
- package/dist/webauthn/decode-attestation-object.js.map +1 -0
- package/dist/webauthn/{decode-client-data-json.d.cts → decode-client-data-json.d.ts} +2 -2
- package/dist/webauthn/decode-client-data-json.d.ts.map +1 -0
- package/dist/webauthn/{decode-client-data-json.mjs → decode-client-data-json.js} +2 -2
- package/dist/webauthn/decode-client-data-json.js.map +1 -0
- package/dist/webauthn/{match-expected-rp-id.d.cts → match-expected-rp-id.d.ts} +1 -1
- package/dist/webauthn/match-expected-rp-id.d.ts.map +1 -0
- package/dist/webauthn/{match-expected-rp-id.mjs → match-expected-rp-id.js} +4 -4
- package/dist/webauthn/match-expected-rp-id.js.map +1 -0
- package/dist/webauthn/{parse-authenticator-data.d.cts → parse-authenticator-data.d.ts} +2 -2
- package/dist/webauthn/parse-authenticator-data.d.ts.map +1 -0
- package/dist/webauthn/{parse-authenticator-data.mjs → parse-authenticator-data.js} +2 -2
- package/dist/webauthn/parse-authenticator-data.js.map +1 -0
- package/dist/webauthn/{types.d.mts → types.d.ts} +2 -2
- package/dist/webauthn/types.d.ts.map +1 -0
- package/dist/webauthn/types.js +2 -0
- package/dist/webauthn/types.js.map +1 -0
- package/dist/webauthn/{verify-authentication-response.d.cts → verify-authentication-response.d.ts} +3 -3
- package/dist/webauthn/verify-authentication-response.d.ts.map +1 -0
- package/dist/webauthn/{verify-authentication-response.mjs → verify-authentication-response.js} +9 -9
- package/dist/webauthn/verify-authentication-response.js.map +1 -0
- package/dist/webauthn/{verify-registration-response.d.mts → verify-registration-response.d.ts} +3 -3
- package/dist/webauthn/verify-registration-response.d.ts.map +1 -0
- package/dist/webauthn/{verify-registration-response.mjs → verify-registration-response.js} +11 -11
- package/dist/webauthn/verify-registration-response.js.map +1 -0
- package/dist/webauthn/{verify-signature.d.cts → verify-signature.d.ts} +1 -1
- package/dist/webauthn/verify-signature.d.ts.map +1 -0
- package/dist/webauthn/{verify-signature.mjs → verify-signature.js} +7 -7
- package/dist/webauthn/verify-signature.js.map +1 -0
- package/package.json +16 -21
- package/dist/PasskeyController-method-action-types.cjs +0 -7
- package/dist/PasskeyController-method-action-types.cjs.map +0 -1
- package/dist/PasskeyController-method-action-types.d.cts +0 -204
- package/dist/PasskeyController-method-action-types.d.cts.map +0 -1
- package/dist/PasskeyController-method-action-types.d.mts.map +0 -1
- package/dist/PasskeyController-method-action-types.mjs.map +0 -1
- package/dist/PasskeyController.cjs +0 -685
- package/dist/PasskeyController.cjs.map +0 -1
- package/dist/PasskeyController.d.cts.map +0 -1
- package/dist/PasskeyController.d.mts +0 -208
- package/dist/PasskeyController.d.mts.map +0 -1
- package/dist/PasskeyController.mjs +0 -680
- package/dist/PasskeyController.mjs.map +0 -1
- package/dist/ceremony-manager.cjs +0 -135
- package/dist/ceremony-manager.cjs.map +0 -1
- package/dist/ceremony-manager.d.cts.map +0 -1
- package/dist/ceremony-manager.d.mts +0 -72
- package/dist/ceremony-manager.d.mts.map +0 -1
- package/dist/ceremony-manager.mjs +0 -131
- package/dist/ceremony-manager.mjs.map +0 -1
- package/dist/constants.cjs +0 -39
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts +0 -36
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/errors.cjs +0 -57
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts +0 -34
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.mts.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/index.cjs +0 -15
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -8
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -5
- package/dist/index.mjs.map +0 -1
- package/dist/key-derivation.cjs +0 -44
- package/dist/key-derivation.cjs.map +0 -1
- package/dist/key-derivation.d.cts.map +0 -1
- package/dist/key-derivation.d.mts +0 -20
- package/dist/key-derivation.d.mts.map +0 -1
- package/dist/key-derivation.mjs.map +0 -1
- package/dist/logger.cjs +0 -9
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts +0 -5
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -5
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs +0 -6
- package/dist/logger.mjs.map +0 -1
- package/dist/types.cjs +0 -4
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts +0 -132
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs +0 -2
- package/dist/types.mjs.map +0 -1
- package/dist/utils/crypto.cjs +0 -66
- package/dist/utils/crypto.cjs.map +0 -1
- package/dist/utils/crypto.d.cts +0 -37
- package/dist/utils/crypto.d.cts.map +0 -1
- package/dist/utils/crypto.d.mts.map +0 -1
- package/dist/utils/crypto.mjs.map +0 -1
- package/dist/utils/encoding.cjs +0 -42
- package/dist/utils/encoding.cjs.map +0 -1
- package/dist/utils/encoding.d.cts.map +0 -1
- package/dist/utils/encoding.d.mts +0 -22
- package/dist/utils/encoding.d.mts.map +0 -1
- package/dist/utils/encoding.mjs.map +0 -1
- package/dist/webauthn/constants.cjs +0 -74
- package/dist/webauthn/constants.cjs.map +0 -1
- package/dist/webauthn/constants.d.cts +0 -68
- package/dist/webauthn/constants.d.cts.map +0 -1
- package/dist/webauthn/constants.d.mts.map +0 -1
- package/dist/webauthn/constants.mjs.map +0 -1
- package/dist/webauthn/decode-attestation-object.cjs +0 -18
- package/dist/webauthn/decode-attestation-object.cjs.map +0 -1
- package/dist/webauthn/decode-attestation-object.d.cts +0 -10
- package/dist/webauthn/decode-attestation-object.d.cts.map +0 -1
- package/dist/webauthn/decode-attestation-object.d.mts.map +0 -1
- package/dist/webauthn/decode-attestation-object.mjs.map +0 -1
- package/dist/webauthn/decode-client-data-json.cjs +0 -17
- package/dist/webauthn/decode-client-data-json.cjs.map +0 -1
- package/dist/webauthn/decode-client-data-json.d.cts.map +0 -1
- package/dist/webauthn/decode-client-data-json.d.mts +0 -9
- package/dist/webauthn/decode-client-data-json.d.mts.map +0 -1
- package/dist/webauthn/decode-client-data-json.mjs.map +0 -1
- package/dist/webauthn/match-expected-rp-id.cjs +0 -26
- package/dist/webauthn/match-expected-rp-id.cjs.map +0 -1
- package/dist/webauthn/match-expected-rp-id.d.cts.map +0 -1
- package/dist/webauthn/match-expected-rp-id.d.mts +0 -11
- package/dist/webauthn/match-expected-rp-id.d.mts.map +0 -1
- package/dist/webauthn/match-expected-rp-id.mjs.map +0 -1
- package/dist/webauthn/parse-authenticator-data.cjs +0 -69
- package/dist/webauthn/parse-authenticator-data.cjs.map +0 -1
- package/dist/webauthn/parse-authenticator-data.d.cts.map +0 -1
- package/dist/webauthn/parse-authenticator-data.d.mts +0 -10
- package/dist/webauthn/parse-authenticator-data.d.mts.map +0 -1
- package/dist/webauthn/parse-authenticator-data.mjs.map +0 -1
- package/dist/webauthn/types.cjs +0 -3
- package/dist/webauthn/types.cjs.map +0 -1
- package/dist/webauthn/types.d.cts +0 -113
- package/dist/webauthn/types.d.cts.map +0 -1
- package/dist/webauthn/types.d.mts.map +0 -1
- package/dist/webauthn/types.mjs +0 -2
- package/dist/webauthn/types.mjs.map +0 -1
- package/dist/webauthn/verify-authentication-response.cjs +0 -133
- package/dist/webauthn/verify-authentication-response.cjs.map +0 -1
- package/dist/webauthn/verify-authentication-response.d.cts.map +0 -1
- package/dist/webauthn/verify-authentication-response.d.mts +0 -64
- package/dist/webauthn/verify-authentication-response.d.mts.map +0 -1
- package/dist/webauthn/verify-authentication-response.mjs.map +0 -1
- package/dist/webauthn/verify-registration-response.cjs +0 -242
- package/dist/webauthn/verify-registration-response.cjs.map +0 -1
- package/dist/webauthn/verify-registration-response.d.cts +0 -81
- package/dist/webauthn/verify-registration-response.d.cts.map +0 -1
- package/dist/webauthn/verify-registration-response.d.mts.map +0 -1
- package/dist/webauthn/verify-registration-response.mjs.map +0 -1
- package/dist/webauthn/verify-signature.cjs +0 -176
- package/dist/webauthn/verify-signature.cjs.map +0 -1
- package/dist/webauthn/verify-signature.d.cts.map +0 -1
- package/dist/webauthn/verify-signature.d.mts +0 -21
- package/dist/webauthn/verify-signature.d.mts.map +0 -1
- package/dist/webauthn/verify-signature.mjs.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { bytesToBase64, base64ToBytes } from
|
|
2
|
-
import { gcm } from
|
|
3
|
-
import { randomBytes } from
|
|
4
|
-
import { hkdf } from
|
|
5
|
-
import { sha256 } from
|
|
6
|
-
import { bytesToBase64URL } from
|
|
1
|
+
import { bytesToBase64, base64ToBytes } from '@metamask/utils';
|
|
2
|
+
import { gcm } from '@noble/ciphers/aes';
|
|
3
|
+
import { randomBytes } from '@noble/ciphers/webcrypto';
|
|
4
|
+
import { hkdf } from '@noble/hashes/hkdf';
|
|
5
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
6
|
+
import { bytesToBase64URL } from './encoding.js';
|
|
7
7
|
const PASSKEY_HKDF_INFO = 'metamask:passkey:encryption-key:v1';
|
|
8
8
|
const AES_GCM_IV_LENGTH = 12;
|
|
9
9
|
/**
|
|
@@ -56,4 +56,4 @@ export function decryptWithKey(ciphertext, iv, key) {
|
|
|
56
56
|
const plaintext = gcm(key, ivBytes).decrypt(ciphertextBytes);
|
|
57
57
|
return new TextDecoder().decode(plaintext);
|
|
58
58
|
}
|
|
59
|
-
//# sourceMappingURL=crypto.
|
|
59
|
+
//# sourceMappingURL=crypto.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,iBAAiB,GAAG,oCAAoC,CAAC;AAE/D,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;;;GAKG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAkB;IACvD,OAAO,gBAAgB,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CACjC,GAAe,EACf,IAAgB;IAEhB,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,cAAc,CAC5B,SAAiB,EACjB,GAAe;IAEf,MAAM,EAAE,GAAG,WAAW,CAAC,iBAAiB,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,GAAG,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtD,OAAO;QACL,UAAU,EAAE,aAAa,CAAC,eAAe,CAAC;QAC1C,EAAE,EAAE,aAAa,CAAC,EAAE,CAAC;KACtB,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,cAAc,CAC5B,UAAkB,EAClB,EAAU,EACV,GAAe;IAEf,MAAM,eAAe,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAE7D,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import { bytesToBase64, base64ToBytes } from '@metamask/utils';\nimport { gcm } from '@noble/ciphers/aes';\nimport { randomBytes } from '@noble/ciphers/webcrypto';\nimport { hkdf } from '@noble/hashes/hkdf';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport { bytesToBase64URL } from './encoding.js';\n\nconst PASSKEY_HKDF_INFO = 'metamask:passkey:encryption-key:v1';\n\nconst AES_GCM_IV_LENGTH = 12;\n\n/**\n * Generates random bytes and returns them as a base64url string (no padding).\n *\n * @param byteLength - Number of bytes to generate (e.g. WebAuthn challenge length).\n * @returns Base64url-encoded random bytes.\n */\nexport function randomBytesToBase64URL(byteLength: number): string {\n return bytesToBase64URL(randomBytes(byteLength));\n}\n\n/**\n * Derives an AES-256 encryption key from input key material and a credential ID\n * using HKDF-SHA256.\n *\n * @param ikm - Input key material (e.g. PRF output or userHandle).\n * @param salt - HKDF salt.\n * @returns 32-byte derived encryption key.\n */\nexport function deriveEncryptionKey(\n ikm: Uint8Array,\n salt: Uint8Array,\n): Uint8Array {\n return hkdf(sha256, ikm, salt, PASSKEY_HKDF_INFO, 32);\n}\n\n/**\n * Encrypts plaintext with an AES-256-GCM key.\n *\n * @param plaintext - UTF-8 string to encrypt.\n * @param key - 32-byte AES-256 key from {@link deriveEncryptionKey}.\n * @returns Base64-encoded ciphertext and IV.\n */\nexport function encryptWithKey(\n plaintext: string,\n key: Uint8Array,\n): { ciphertext: string; iv: string } {\n const iv = randomBytes(AES_GCM_IV_LENGTH);\n const encoded = new TextEncoder().encode(plaintext);\n const ciphertextBytes = gcm(key, iv).encrypt(encoded);\n\n return {\n ciphertext: bytesToBase64(ciphertextBytes),\n iv: bytesToBase64(iv),\n };\n}\n\n/**\n * Decrypts AES-256-GCM ciphertext with the given key.\n *\n * @param ciphertext - Base64-encoded ciphertext.\n * @param iv - Base64-encoded initialization vector.\n * @param key - 32-byte AES-256 key from {@link deriveEncryptionKey}.\n * @returns Decrypted UTF-8 string.\n */\nexport function decryptWithKey(\n ciphertext: string,\n iv: string,\n key: Uint8Array,\n): string {\n const ciphertextBytes = base64ToBytes(ciphertext);\n const ivBytes = base64ToBytes(iv);\n const plaintext = gcm(key, ivBytes).decrypt(ciphertextBytes);\n\n return new TextDecoder().decode(plaintext);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../src/utils/encoding.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAK1D;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,CAI1D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAIpD"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bytesToBase64, base64ToBytes } from
|
|
1
|
+
import { bytesToBase64, base64ToBytes } from '@metamask/utils';
|
|
2
2
|
/**
|
|
3
3
|
* Encode a byte array as a base64url string (RFC 4648 §5).
|
|
4
4
|
*
|
|
@@ -33,4 +33,4 @@ export function bytesToHex(bytes) {
|
|
|
33
33
|
.map((byte) => byte.toString(16).padStart(2, '0'))
|
|
34
34
|
.join('');
|
|
35
35
|
}
|
|
36
|
-
//# sourceMappingURL=encoding.
|
|
36
|
+
//# sourceMappingURL=encoding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encoding.js","sourceRoot":"","sources":["../../src/utils/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAE/D;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAiB;IAChD,OAAO,aAAa,CAAC,KAAK,CAAC;SACxB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,OAAO,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAC3B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa;IAC5C,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAC/D,MAAM,SAAS,GAAG,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAClD,OAAO,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;AAC1E,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,KAAiB;IAC1C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;SACrB,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;SACjD,IAAI,CAAC,EAAE,CAAC,CAAC;AACd,CAAC","sourcesContent":["import { bytesToBase64, base64ToBytes } from '@metamask/utils';\n\n/**\n * Encode a byte array as a base64url string (RFC 4648 §5).\n *\n * @param bytes - The bytes to encode.\n * @returns Base64url-encoded string without padding.\n */\nexport function bytesToBase64URL(bytes: Uint8Array): string {\n return bytesToBase64(bytes)\n .replace(/\\+/gu, '-')\n .replace(/\\//gu, '_')\n .replace(/[=]+$/u, '');\n}\n\n/**\n * Decode a base64url string (RFC 4648 §5) into bytes.\n *\n * @param value - Base64url-encoded string.\n * @returns Decoded bytes.\n */\nexport function base64URLToBytes(value: string): Uint8Array {\n const standard = value.replace(/-/gu, '+').replace(/_/gu, '/');\n const padLength = (4 - (standard.length % 4)) % 4;\n return Uint8Array.from(base64ToBytes(standard + '='.repeat(padLength)));\n}\n\n/**\n * Encode a byte array as a hexadecimal string.\n *\n * @param bytes - The bytes to encode.\n * @returns Hex-encoded string.\n */\nexport function bytesToHex(bytes: Uint8Array): string {\n return Array.from(bytes)\n .map((byte) => byte.toString(16).padStart(2, '0'))\n .join('');\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/webauthn/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,oBAAY,OAAO;IACjB,KAAK,KAAK;IACV,KAAK,KAAK;IACV,KAAK,MAAM;IACX,KAAK,MAAM;IACX,KAAK,MAAM;IACX,KAAK,MAAM;IACX,KAAK,MAAM;IACX,MAAM,MAAM;IACZ,KAAK,OAAO;IACZ,KAAK,OAAO;IACZ,KAAK,OAAO;IACZ,GAAG,SAAS;CACb;AAED;;;;GAIG;AACH,oBAAY,OAAO;IACjB,GAAG,IAAI;IACP,GAAG,IAAI;IACP,GAAG,IAAI;CACR;AAED;;;;GAIG;AACH,oBAAY,OAAO;IACjB,IAAI,IAAI;IACR,IAAI,IAAI;IACR,IAAI,IAAI;IACR,OAAO,IAAI;IACX,SAAS,IAAI;CACd;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,QAAQ;IACnB,wBAAwB;aACxB,GAAG,EAAE,CAAC;IACN,yBAAyB;aACzB,GAAG,EAAE,CAAC;IAEN,kCAAkC;aAClC,GAAG,EAAE,CAAC,CAAC;IACP,0CAA0C;aAC1C,CAAC,EAAE,CAAC,CAAC;IACL,wBAAwB;aACxB,CAAC,EAAE,CAAC,CAAC;IAEL,qDAAqD;aACrD,CAAC,EAAE,CAAC,CAAC;IACL,oDAAoD;aACpD,CAAC,EAAE,CAAC,CAAC;CACG,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/webauthn/constants.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAN,IAAY,OAaX;AAbD,WAAY,OAAO;IACjB,wCAAU,CAAA;IACV,wCAAU,CAAA;IACV,yCAAW,CAAA;IACX,yCAAW,CAAA;IACX,yCAAW,CAAA;IACX,yCAAW,CAAA;IACX,yCAAW,CAAA;IACX,2CAAY,CAAA;IACZ,0CAAY,CAAA;IACZ,0CAAY,CAAA;IACZ,0CAAY,CAAA;IACZ,wCAAY,CAAA;AACd,CAAC,EAbW,OAAO,KAAP,OAAO,QAalB;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,OAIX;AAJD,WAAY,OAAO;IACjB,mCAAO,CAAA;IACP,mCAAO,CAAA;IACP,mCAAO,CAAA;AACT,CAAC,EAJW,OAAO,KAAP,OAAO,QAIlB;AAED;;;;GAIG;AACH,MAAM,CAAN,IAAY,OAMX;AAND,WAAY,OAAO;IACjB,qCAAQ,CAAA;IACR,qCAAQ,CAAA;IACR,qCAAQ,CAAA;IACR,2CAAW,CAAA;IACX,+CAAa,CAAA;AACf,CAAC,EANW,OAAO,KAAP,OAAO,QAMlB;AAED;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,wBAAwB;IACxB,GAAG,EAAE,CAAC;IACN,yBAAyB;IACzB,GAAG,EAAE,CAAC;IAEN,kCAAkC;IAClC,GAAG,EAAE,CAAC,CAAC;IACP,0CAA0C;IAC1C,CAAC,EAAE,CAAC,CAAC;IACL,wBAAwB;IACxB,CAAC,EAAE,CAAC,CAAC;IAEL,qDAAqD;IACrD,CAAC,EAAE,CAAC,CAAC;IACL,oDAAoD;IACpD,CAAC,EAAE,CAAC,CAAC;CACG,CAAC","sourcesContent":["/**\n * COSE Algorithms\n *\n * @see https://www.iana.org/assignments/cose/cose.xhtml#algorithms\n */\nexport enum COSEALG {\n ES256 = -7,\n EdDSA = -8,\n ES384 = -35,\n ES512 = -36,\n PS256 = -37,\n PS384 = -38,\n PS512 = -39,\n ES256K = -47,\n RS256 = -257,\n RS384 = -258,\n RS512 = -259,\n RS1 = -65535,\n}\n\n/**\n * COSE Key Types\n *\n * @see https://www.iana.org/assignments/cose/cose.xhtml#key-type\n */\nexport enum COSEKTY {\n OKP = 1,\n EC2 = 2,\n RSA = 3,\n}\n\n/**\n * COSE Curves\n *\n * @see https://www.iana.org/assignments/cose/cose.xhtml#elliptic-curves\n */\nexport enum COSECRV {\n P256 = 1,\n P384 = 2,\n P521 = 3,\n ED25519 = 6,\n SECP256K1 = 8,\n}\n\n/**\n * COSE Key common and type-specific parameter labels.\n *\n * EC2 and RSA re-use the same numeric labels (-1, -2, -3) with different\n * semantics, so this is a plain object instead of an enum to avoid\n * duplicate-value violations.\n *\n * @see https://www.iana.org/assignments/cose/cose.xhtml#key-common-parameters\n * @see https://www.iana.org/assignments/cose/cose.xhtml#key-type-parameters\n */\nexport const COSEKEYS = {\n /** Key Type (common) */\n Kty: 1,\n /** Algorithm (common) */\n Alg: 3,\n\n /** EC2 / OKP: curve identifier */\n Crv: -1,\n /** EC2: x-coordinate / OKP: public key */\n X: -2,\n /** EC2: y-coordinate */\n Y: -3,\n\n /** RSA: modulus n (shares numeric label with Crv) */\n N: -1,\n /** RSA: exponent e (shares numeric label with X) */\n E: -2,\n} as const;\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AttestationObject } from
|
|
1
|
+
import type { AttestationObject } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* CBOR-decode an attestationObject buffer into a Map with `fmt`, `attStmt`,
|
|
4
4
|
* and `authData` entries.
|
|
@@ -7,4 +7,4 @@ import type { AttestationObject } from "./types.mjs";
|
|
|
7
7
|
* @returns Decoded AttestationObject map.
|
|
8
8
|
*/
|
|
9
9
|
export declare function decodeAttestationObject(attestationObject: Uint8Array): AttestationObject;
|
|
10
|
-
//# sourceMappingURL=decode-attestation-object.d.
|
|
10
|
+
//# sourceMappingURL=decode-attestation-object.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-attestation-object.d.ts","sourceRoot":"","sources":["../../src/webauthn/decode-attestation-object.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEpD;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CACrC,iBAAiB,EAAE,UAAU,GAC5B,iBAAiB,CAInB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decodePartialCBOR } from
|
|
1
|
+
import { decodePartialCBOR } from '@levischuck/tiny-cbor';
|
|
2
2
|
/**
|
|
3
3
|
* CBOR-decode an attestationObject buffer into a Map with `fmt`, `attStmt`,
|
|
4
4
|
* and `authData` entries.
|
|
@@ -11,4 +11,4 @@ export function decodeAttestationObject(attestationObject) {
|
|
|
11
11
|
const [decoded] = decodePartialCBOR(copy, 0);
|
|
12
12
|
return decoded;
|
|
13
13
|
}
|
|
14
|
-
//# sourceMappingURL=decode-attestation-object.
|
|
14
|
+
//# sourceMappingURL=decode-attestation-object.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-attestation-object.js","sourceRoot":"","sources":["../../src/webauthn/decode-attestation-object.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAI1D;;;;;;GAMG;AACH,MAAM,UAAU,uBAAuB,CACrC,iBAA6B;IAE7B,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAAC;IAC/C,MAAM,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC,IAAI,EAAE,CAAC,CAAgC,CAAC;IAC5E,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\n\nimport type { AttestationObject } from './types.js';\n\n/**\n * CBOR-decode an attestationObject buffer into a Map with `fmt`, `attStmt`,\n * and `authData` entries.\n *\n * @param attestationObject - Raw attestation object bytes.\n * @returns Decoded AttestationObject map.\n */\nexport function decodeAttestationObject(\n attestationObject: Uint8Array,\n): AttestationObject {\n const copy = new Uint8Array(attestationObject);\n const [decoded] = decodePartialCBOR(copy, 0) as [AttestationObject, number];\n return decoded;\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ClientDataJSON } from
|
|
1
|
+
import type { ClientDataJSON } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Decode an authenticator's base64url-encoded clientDataJSON to JSON.
|
|
4
4
|
*
|
|
@@ -6,4 +6,4 @@ import type { ClientDataJSON } from "./types.cjs";
|
|
|
6
6
|
* @returns Parsed ClientDataJSON object.
|
|
7
7
|
*/
|
|
8
8
|
export declare function decodeClientDataJSON(data: string): ClientDataJSON;
|
|
9
|
-
//# sourceMappingURL=decode-client-data-json.d.
|
|
9
|
+
//# sourceMappingURL=decode-client-data-json.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-client-data-json.d.ts","sourceRoot":"","sources":["../../src/webauthn/decode-client-data-json.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,CAIjE"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { base64URLToBytes } from
|
|
1
|
+
import { base64URLToBytes } from '../utils/encoding.js';
|
|
2
2
|
/**
|
|
3
3
|
* Decode an authenticator's base64url-encoded clientDataJSON to JSON.
|
|
4
4
|
*
|
|
@@ -10,4 +10,4 @@ export function decodeClientDataJSON(data) {
|
|
|
10
10
|
const text = new TextDecoder().decode(bytes);
|
|
11
11
|
return JSON.parse(text);
|
|
12
12
|
}
|
|
13
|
-
//# sourceMappingURL=decode-client-data-json.
|
|
13
|
+
//# sourceMappingURL=decode-client-data-json.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-client-data-json.js","sourceRoot":"","sources":["../../src/webauthn/decode-client-data-json.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAGxD;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,IAAY;IAC/C,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACrC,MAAM,IAAI,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC7C,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAmB,CAAC;AAC5C,CAAC","sourcesContent":["import { base64URLToBytes } from '../utils/encoding.js';\nimport type { ClientDataJSON } from './types.js';\n\n/**\n * Decode an authenticator's base64url-encoded clientDataJSON to JSON.\n *\n * @param data - Base64url-encoded clientDataJSON string.\n * @returns Parsed ClientDataJSON object.\n */\nexport function decodeClientDataJSON(data: string): ClientDataJSON {\n const bytes = base64URLToBytes(data);\n const text = new TextDecoder().decode(bytes);\n return JSON.parse(text) as ClientDataJSON;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-expected-rp-id.d.ts","sourceRoot":"","sources":["../../src/webauthn/match-expected-rp-id.ts"],"names":[],"mappings":"AAKA;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,UAAU,EACpB,aAAa,EAAE,MAAM,EAAE,GACtB,MAAM,CAQR"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { areUint8ArraysEqual } from
|
|
2
|
-
import { sha256 } from
|
|
3
|
-
import { bytesToHex } from
|
|
1
|
+
import { areUint8ArraysEqual } from '@metamask/utils';
|
|
2
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
3
|
+
import { bytesToHex } from '../utils/encoding.js';
|
|
4
4
|
/**
|
|
5
5
|
* Verify that an authenticator data rpIdHash matches one of the expected
|
|
6
6
|
* RP IDs by SHA-256 hashing each candidate and comparing.
|
|
@@ -19,4 +19,4 @@ export function matchExpectedRPID(rpIdHash, expectedRPIDs) {
|
|
|
19
19
|
}
|
|
20
20
|
throw new Error(`Unexpected RP ID hash: received ${bytesToHex(rpIdHash)}`);
|
|
21
21
|
}
|
|
22
|
-
//# sourceMappingURL=match-expected-rp-id.
|
|
22
|
+
//# sourceMappingURL=match-expected-rp-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-expected-rp-id.js","sourceRoot":"","sources":["../../src/webauthn/match-expected-rp-id.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD;;;;;;;;GAQG;AACH,MAAM,UAAU,iBAAiB,CAC/B,QAAoB,EACpB,aAAuB;IAEvB,KAAK,MAAM,IAAI,IAAI,aAAa,EAAE,CAAC;QACjC,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAC5D,IAAI,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,EAAE,CAAC;YAChD,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,mCAAmC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC7E,CAAC","sourcesContent":["import { areUint8ArraysEqual } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport { bytesToHex } from '../utils/encoding.js';\n\n/**\n * Verify that an authenticator data rpIdHash matches one of the expected\n * RP IDs by SHA-256 hashing each candidate and comparing.\n *\n * @param rpIdHash - The rpIdHash from authenticatorData (32 bytes).\n * @param expectedRPIDs - One or more RP ID strings to check against.\n * @returns The matching RP ID string.\n * @throws If no expected RP ID matches.\n */\nexport function matchExpectedRPID(\n rpIdHash: Uint8Array,\n expectedRPIDs: string[],\n): string {\n for (const rpID of expectedRPIDs) {\n const expectedHash = sha256(new TextEncoder().encode(rpID));\n if (areUint8ArraysEqual(rpIdHash, expectedHash)) {\n return rpID;\n }\n }\n throw new Error(`Unexpected RP ID hash: received ${bytesToHex(rpIdHash)}`);\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ParsedAuthenticatorData } from
|
|
1
|
+
import type { ParsedAuthenticatorData } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Parse an authenticator data buffer per §6.1 of the WebAuthn spec.
|
|
4
4
|
*
|
|
@@ -7,4 +7,4 @@ import type { ParsedAuthenticatorData } from "./types.cjs";
|
|
|
7
7
|
* optional attested credential data.
|
|
8
8
|
*/
|
|
9
9
|
export declare function parseAuthenticatorData(authData: Uint8Array): ParsedAuthenticatorData;
|
|
10
|
-
//# sourceMappingURL=parse-authenticator-data.d.
|
|
10
|
+
//# sourceMappingURL=parse-authenticator-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-authenticator-data.d.ts","sourceRoot":"","sources":["../../src/webauthn/parse-authenticator-data.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,YAAY,CAAC;AAIpB;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,UAAU,GACnB,uBAAuB,CAkFzB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { decodePartialCBOR } from
|
|
1
|
+
import { decodePartialCBOR } from '@levischuck/tiny-cbor';
|
|
2
2
|
/* eslint-disable no-bitwise */
|
|
3
3
|
/**
|
|
4
4
|
* Parse an authenticator data buffer per §6.1 of the WebAuthn spec.
|
|
@@ -62,4 +62,4 @@ export function parseAuthenticatorData(authData) {
|
|
|
62
62
|
return result;
|
|
63
63
|
}
|
|
64
64
|
/* eslint-enable no-bitwise */
|
|
65
|
-
//# sourceMappingURL=parse-authenticator-data.
|
|
65
|
+
//# sourceMappingURL=parse-authenticator-data.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-authenticator-data.js","sourceRoot":"","sources":["../../src/webauthn/parse-authenticator-data.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO1D,+BAA+B;AAE/B;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CACpC,QAAoB;IAEpB,IAAI,QAAQ,CAAC,UAAU,GAAG,EAAE,EAAE,CAAC;QAC7B,MAAM,IAAI,KAAK,CACb,wBAAwB,QAAQ,CAAC,UAAU,8BAA8B,CAC1E,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,GAAG,CAAC,CAAC;IAEhB,MAAM,QAAQ,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,EAAE,CAAC,CAAC;IACvD,OAAO,IAAI,EAAE,CAAC;IAEd,MAAM,SAAS,GAAG,QAAQ,CAAC,OAAO,CAAC,CAAC;IACpC,MAAM,KAAK,GAA2B;QACpC,EAAE,EAAE,OAAO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AK,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC,CAAC;QAClE,OAAO,IAAI,SAAS,CAAC;QAErB,MAAM,WAAW,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC5C,MAAM,CAAC,EAAE,UAAU,CAAC,GAAG,iBAAiB,CACtC,IAAI,UAAU,CAAC,WAAW,CAAC,EAC3B,CAAC,CACmB,CAAC;QACvB,MAAM,mBAAmB,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAAC,CAAC;QAC1E,OAAO,IAAI,UAAU,CAAC;QAEtB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;QACvB,MAAM,CAAC,YAAY,GAAG,YAAY,CAAC;QACnC,MAAM,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACnD,CAAC;IAED,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC;QACb,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAC1C,MAAM,CAAC,OAAO,EAAE,QAAQ,CAAC,GAAG,iBAAiB,CAC3C,IAAI,UAAU,CAAC,SAAS,CAAC,EACzB,CAAC,CACgC,CAAC;QACpC,MAAM,CAAC,cAAc,GAAG,OAAO,CAAC;QAChC,MAAM,CAAC,oBAAoB,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;QAC3D,OAAO,IAAI,QAAQ,CAAC;IACtB,CAAC;IAED,IAAI,QAAQ,CAAC,UAAU,GAAG,OAAO,EAAE,CAAC;QAClC,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,8BAA8B","sourcesContent":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\n\nimport type {\n ParsedAuthenticatorData,\n AuthenticatorDataFlags,\n} from './types.js';\n\n/* eslint-disable no-bitwise */\n\n/**\n * Parse an authenticator data buffer per §6.1 of the WebAuthn spec.\n *\n * @param authData - Raw authenticator data bytes.\n * @returns Parsed authenticator data with flags, rpIdHash, counter, and\n * optional attested credential data.\n */\nexport function parseAuthenticatorData(\n authData: Uint8Array,\n): ParsedAuthenticatorData {\n if (authData.byteLength < 37) {\n throw new Error(\n `authenticatorData is ${authData.byteLength} bytes, expected at least 37`,\n );\n }\n\n let pointer = 0;\n\n const rpIdHash = authData.slice(pointer, pointer + 32);\n pointer += 32;\n\n const flagsByte = authData[pointer];\n const flags: AuthenticatorDataFlags = {\n up: Boolean(flagsByte & (1 << 0)),\n uv: Boolean(flagsByte & (1 << 2)),\n be: Boolean(flagsByte & (1 << 3)),\n bs: Boolean(flagsByte & (1 << 4)),\n at: Boolean(flagsByte & (1 << 6)),\n ed: Boolean(flagsByte & (1 << 7)),\n flagsByte,\n };\n pointer += 1;\n\n const counterView = new DataView(\n authData.buffer,\n authData.byteOffset + pointer,\n 4,\n );\n const counter = counterView.getUint32(0, false);\n pointer += 4;\n\n const result: ParsedAuthenticatorData = {\n rpIdHash,\n flags,\n counter,\n };\n\n if (flags.at) {\n const aaguid = authData.slice(pointer, pointer + 16);\n pointer += 16;\n\n const credIDLenView = new DataView(\n authData.buffer,\n authData.byteOffset + pointer,\n 2,\n );\n const credIDLen = credIDLenView.getUint16(0, false);\n pointer += 2;\n\n const credentialID = authData.slice(pointer, pointer + credIDLen);\n pointer += credIDLen;\n\n const pubKeyBytes = authData.slice(pointer);\n const [, nextOffset] = decodePartialCBOR(\n new Uint8Array(pubKeyBytes),\n 0,\n ) as [unknown, number];\n const credentialPublicKey = authData.slice(pointer, pointer + nextOffset);\n pointer += nextOffset;\n\n result.aaguid = aaguid;\n result.credentialID = credentialID;\n result.credentialPublicKey = credentialPublicKey;\n }\n\n if (flags.ed) {\n const remaining = authData.slice(pointer);\n const [decoded, consumed] = decodePartialCBOR(\n new Uint8Array(remaining),\n 0,\n ) as [Map<string, unknown>, number];\n result.extensionsData = decoded;\n result.extensionsDataBuffer = remaining.slice(0, consumed);\n pointer += consumed;\n }\n\n if (authData.byteLength > pointer) {\n throw new Error('Leftover bytes detected while parsing authenticator data');\n }\n\n return result;\n}\n\n/* eslint-enable no-bitwise */\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AuthenticatorTransportFuture, Base64URLString as Base64URL } from
|
|
1
|
+
import type { AuthenticatorTransportFuture, Base64URLString as Base64URL } from '../types.js';
|
|
2
2
|
export type PublicKeyCredentialDescriptorJSON = {
|
|
3
3
|
id: Base64URL;
|
|
4
4
|
type: 'public-key';
|
|
@@ -110,4 +110,4 @@ export type ParsedAuthenticatorData = {
|
|
|
110
110
|
extensionsData?: Map<string, unknown>;
|
|
111
111
|
extensionsDataBuffer?: Uint8Array;
|
|
112
112
|
};
|
|
113
|
-
//# sourceMappingURL=types.d.
|
|
113
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,IAAI,SAAS,EAC7B,MAAM,aAAa,CAAC;AAErB,MAAM,MAAM,iCAAiC,GAAG;IAC9C,EAAE,EAAE,SAAS,CAAC;IACd,IAAI,EAAE,YAAY,CAAC;IACnB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAC/B,QAAQ,GACR,cAAc,GACd,eAAe,CAAC;AAEpB,MAAM,MAAM,0BAA0B,GAAG;IACvC,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,EAAE,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAClC,IAAI,EAAE;QACJ,EAAE,EAAE,SAAS,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,SAAS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AG,oBAAoB,CAAC;IAC1C,GAAG,CAAC,GAAG,EAAE,UAAU,GAAG,UAAU,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,UAAU,GAAG,SAAS,CAAC;IACxC,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,UAAU,EAAE,GAAG,SAAS,CAAC;IAC1C,GAAG,CAAC,GAAG,EAAE,KAAK,GAAG,MAAM,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,EAAE,EAAE,OAAO,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,EAAE,UAAU,CAAC;IACrB,KAAK,EAAE,sBAAsB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,UAAU,CAAC;IACpB,YAAY,CAAC,EAAE,UAAU,CAAC;IAC1B,mBAAmB,CAAC,EAAE,UAAU,CAAC;IACjC,cAAc,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,oBAAoB,CAAC,EAAE,UAAU,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuthenticatorTransportFuture,\n Base64URLString as Base64URL,\n} from '../types.js';\n\nexport type PublicKeyCredentialDescriptorJSON = {\n id: Base64URL;\n type: 'public-key';\n transports?: AuthenticatorTransportFuture[];\n};\n\nexport type PublicKeyCredentialHint =\n | 'hybrid'\n | 'security-key'\n | 'client-device';\n\nexport type PasskeyRegistrationOptions = {\n rp: { name: string; id?: string };\n user: {\n id: Base64URL;\n name: string;\n displayName: string;\n };\n challenge: Base64URL;\n pubKeyCredParams: { alg: number; type: 'public-key' }[];\n timeout?: number;\n excludeCredentials?: PublicKeyCredentialDescriptorJSON[];\n authenticatorSelection?: {\n authenticatorAttachment?: 'cross-platform' | 'platform';\n residentKey?: 'discouraged' | 'preferred' | 'required';\n requireResidentKey?: boolean;\n userVerification?: 'discouraged' | 'preferred' | 'required';\n };\n hints?: PublicKeyCredentialHint[];\n attestation?: 'direct' | 'enterprise' | 'indirect' | 'none';\n extensions?: Record<string, unknown>;\n};\n\nexport type PasskeyRegistrationResponse = {\n id: Base64URL;\n rawId: Base64URL;\n type: 'public-key';\n response: {\n clientDataJSON: Base64URL;\n attestationObject: Base64URL;\n transports?: string[];\n publicKeyAlgorithm?: number;\n publicKey?: Base64URL;\n authenticatorData?: Base64URL;\n };\n authenticatorAttachment?: 'cross-platform' | 'platform';\n clientExtensionResults: Record<string, unknown>;\n};\n\nexport type PasskeyAuthenticationOptions = {\n challenge: Base64URL;\n timeout?: number;\n rpId?: string;\n allowCredentials?: PublicKeyCredentialDescriptorJSON[];\n userVerification?: 'discouraged' | 'preferred' | 'required';\n hints?: PublicKeyCredentialHint[];\n extensions?: Record<string, unknown>;\n};\n\nexport type PasskeyAuthenticationResponse = {\n id: Base64URL;\n rawId: Base64URL;\n type: 'public-key';\n response: {\n clientDataJSON: Base64URL;\n authenticatorData: Base64URL;\n signature: Base64URL;\n userHandle?: Base64URL;\n };\n authenticatorAttachment?: 'cross-platform' | 'platform';\n clientExtensionResults: Record<string, unknown>;\n};\n\nexport type ClientDataJSON = {\n type: string;\n challenge: string;\n origin: string;\n crossOrigin?: boolean;\n tokenBinding?: {\n id?: string;\n status: 'present' | 'supported' | 'not-supported';\n };\n};\n\nexport type AttestationFormat =\n | 'fido-u2f'\n | 'packed'\n | 'android-safetynet'\n | 'android-key'\n | 'tpm'\n | 'apple'\n | 'none';\n\nexport type AttestationObject = {\n get(key: 'fmt'): AttestationFormat;\n get(key: 'attStmt'): AttestationStatement;\n get(key: 'authData'): Uint8Array;\n};\n\nexport type AttestationStatement = {\n get(key: 'sig'): Uint8Array | undefined;\n get(key: 'x5c'): Uint8Array[] | undefined;\n get(key: 'alg'): number | undefined;\n readonly size: number;\n};\n\nexport type AuthenticatorDataFlags = {\n up: boolean;\n uv: boolean;\n be: boolean;\n bs: boolean;\n at: boolean;\n ed: boolean;\n flagsByte: number;\n};\n\nexport type ParsedAuthenticatorData = {\n rpIdHash: Uint8Array;\n flags: AuthenticatorDataFlags;\n counter: number;\n aaguid?: Uint8Array;\n credentialID?: Uint8Array;\n credentialPublicKey?: Uint8Array;\n extensionsData?: Map<string, unknown>;\n extensionsDataBuffer?: Uint8Array;\n};\n"]}
|
package/dist/webauthn/{verify-authentication-response.d.cts → verify-authentication-response.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AuthenticatorTransportFuture } from
|
|
2
|
-
import type { PasskeyAuthenticationResponse } from
|
|
1
|
+
import type { AuthenticatorTransportFuture } from '../types.js';
|
|
2
|
+
import type { PasskeyAuthenticationResponse } from './types.js';
|
|
3
3
|
export type VerifiedAuthenticationResponse = {
|
|
4
4
|
verified: false;
|
|
5
5
|
authenticationInfo?: never;
|
|
@@ -61,4 +61,4 @@ export declare function verifyAuthenticationResponse(opts: {
|
|
|
61
61
|
};
|
|
62
62
|
requireUserVerification?: boolean;
|
|
63
63
|
}): Promise<VerifiedAuthenticationResponse>;
|
|
64
|
-
//# sourceMappingURL=verify-authentication-response.d.
|
|
64
|
+
//# sourceMappingURL=verify-authentication-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-authentication-response.d.ts","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAMhE,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAGhE,MAAM,MAAM,8BAA8B,GACtC;IAAE,QAAQ,EAAE,KAAK,CAAC;IAAC,kBAAkB,CAAC,EAAE,KAAK,CAAA;CAAE,GAC/C;IACE,QAAQ,EAAE,IAAI,CAAC;IACf,kBAAkB,EAAE;QAClB,YAAY,EAAE,MAAM,CAAC;QACrB,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,OAAO,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,uFAAuF;QACvF,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH,CAAC;AAEN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAsB,4BAA4B,CAAC,IAAI,EAAE;IACvD,QAAQ,EAAE,6BAA6B,CAAC;IACxC,iBAAiB,EAAE,MAAM,CAAC;IAC1B,cAAc,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAClC,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE;QACV,EAAE,EAAE,MAAM,CAAC;QACX,SAAS,EAAE,UAAU,CAAC;QACtB,OAAO,EAAE,MAAM,CAAC;QAChB,UAAU,CAAC,EAAE,4BAA4B,EAAE,CAAC;KAC7C,CAAC;IACF,uBAAuB,CAAC,EAAE,OAAO,CAAC;CACnC,GAAG,OAAO,CAAC,8BAA8B,CAAC,CA+I1C"}
|
package/dist/webauthn/{verify-authentication-response.mjs → verify-authentication-response.js}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { decodePartialCBOR } from
|
|
2
|
-
import { concatBytes } from
|
|
3
|
-
import { sha256 } from
|
|
4
|
-
import { base64URLToBytes } from
|
|
5
|
-
import { decodeClientDataJSON } from
|
|
6
|
-
import { matchExpectedRPID } from
|
|
7
|
-
import { parseAuthenticatorData } from
|
|
8
|
-
import { verifySignature } from
|
|
1
|
+
import { decodePartialCBOR } from '@levischuck/tiny-cbor';
|
|
2
|
+
import { concatBytes } from '@metamask/utils';
|
|
3
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
4
|
+
import { base64URLToBytes } from '../utils/encoding.js';
|
|
5
|
+
import { decodeClientDataJSON } from './decode-client-data-json.js';
|
|
6
|
+
import { matchExpectedRPID } from './match-expected-rp-id.js';
|
|
7
|
+
import { parseAuthenticatorData } from './parse-authenticator-data.js';
|
|
8
|
+
import { verifySignature } from './verify-signature.js';
|
|
9
9
|
/**
|
|
10
10
|
* Verifies a WebAuthn authentication (assertion) response per
|
|
11
11
|
* W3C WebAuthn Level 3 §7.2.
|
|
@@ -126,4 +126,4 @@ export async function verifyAuthenticationResponse(opts) {
|
|
|
126
126
|
},
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
-
//# sourceMappingURL=verify-authentication-response.
|
|
129
|
+
//# sourceMappingURL=verify-authentication-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-authentication-response.js","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAGvE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAgBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAA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":["import { decodePartialCBOR } from '@levischuck/tiny-cbor';\nimport { concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha2';\n\nimport type { AuthenticatorTransportFuture } from '../types.js';\nimport { base64URLToBytes } from '../utils/encoding.js';\nimport { decodeClientDataJSON } from './decode-client-data-json.js';\nimport { matchExpectedRPID } from './match-expected-rp-id.js';\nimport { parseAuthenticatorData } from './parse-authenticator-data.js';\nimport type { ParsedAuthenticatorData } from './types.js';\nimport type { PasskeyAuthenticationResponse } from './types.js';\nimport { verifySignature } from './verify-signature.js';\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"]}
|
package/dist/webauthn/{verify-registration-response.d.mts → verify-registration-response.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AuthenticatorTransportFuture } from
|
|
2
|
-
import type { PasskeyRegistrationResponse } from
|
|
1
|
+
import type { AuthenticatorTransportFuture } from '../types.js';
|
|
2
|
+
import type { PasskeyRegistrationResponse } from './types.js';
|
|
3
3
|
export type VerifiedRegistrationResponse = {
|
|
4
4
|
verified: false;
|
|
5
5
|
registrationInfo?: never;
|
|
@@ -78,4 +78,4 @@ export declare function verifyRegistrationResponse(opts: {
|
|
|
78
78
|
* @throws If the attestation object or its authenticator data is malformed.
|
|
79
79
|
*/
|
|
80
80
|
export declare function getAAGUIDFromRegistrationResponse(registrationResponse: PasskeyRegistrationResponse): string | undefined;
|
|
81
|
-
//# sourceMappingURL=verify-registration-response.d.
|
|
81
|
+
//# sourceMappingURL=verify-registration-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-registration-response.d.ts","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAC;AAWhE,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAG9D,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,CAkLxC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iCAAiC,CAC/C,oBAAoB,EAAE,2BAA2B,GAChD,MAAM,GAAG,SAAS,CAMpB"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { decodePartialCBOR } from
|
|
2
|
-
import { concatBytes } from
|
|
3
|
-
import { sha256 } from
|
|
4
|
-
import { base64URLToBytes, bytesToBase64URL, bytesToHex } from
|
|
5
|
-
import { COSEALG, COSEKEYS } from
|
|
6
|
-
import { decodeAttestationObject } from
|
|
7
|
-
import { decodeClientDataJSON } from
|
|
8
|
-
import { matchExpectedRPID } from
|
|
9
|
-
import { parseAuthenticatorData } from
|
|
10
|
-
import { verifySignature } from
|
|
1
|
+
import { decodePartialCBOR } from '@levischuck/tiny-cbor';
|
|
2
|
+
import { concatBytes } from '@metamask/utils';
|
|
3
|
+
import { sha256 } from '@noble/hashes/sha2';
|
|
4
|
+
import { base64URLToBytes, bytesToBase64URL, bytesToHex, } from '../utils/encoding.js';
|
|
5
|
+
import { COSEALG, COSEKEYS } from './constants.js';
|
|
6
|
+
import { decodeAttestationObject } from './decode-attestation-object.js';
|
|
7
|
+
import { decodeClientDataJSON } from './decode-client-data-json.js';
|
|
8
|
+
import { matchExpectedRPID } from './match-expected-rp-id.js';
|
|
9
|
+
import { parseAuthenticatorData } from './parse-authenticator-data.js';
|
|
10
|
+
import { verifySignature } from './verify-signature.js';
|
|
11
11
|
/**
|
|
12
12
|
* Verifies a WebAuthn registration (attestation) response per
|
|
13
13
|
* W3C WebAuthn Level 3 §7.1.
|
|
@@ -234,4 +234,4 @@ async function verifyPackedAttestation(attStmt, authData, clientDataJSONB64url,
|
|
|
234
234
|
data: signatureBase,
|
|
235
235
|
});
|
|
236
236
|
}
|
|
237
|
-
//# sourceMappingURL=verify-registration-response.
|
|
237
|
+
//# sourceMappingURL=verify-registration-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-registration-response.js","sourceRoot":"","sources":["../../src/webauthn/verify-registration-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,UAAU,GACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAEvE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAiBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAAC,IAOhD;IACC,MAAM,EACJ,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,uBAAuB,GAAG,KAAK,EAC/B,qBAAqB,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,GACtE,GAAG,IAAI,CAAC;IAET,MAAM,EACJ,EAAE,EACF,KAAK,EACL,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,mBAAmB,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,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.js';\nimport {\n base64URLToBytes,\n bytesToBase64URL,\n bytesToHex,\n} from '../utils/encoding.js';\nimport { COSEALG, COSEKEYS } from './constants.js';\nimport { decodeAttestationObject } from './decode-attestation-object.js';\nimport { decodeClientDataJSON } from './decode-client-data-json.js';\nimport { matchExpectedRPID } from './match-expected-rp-id.js';\nimport { parseAuthenticatorData } from './parse-authenticator-data.js';\nimport type { PasskeyRegistrationResponse } from './types.js';\nimport { verifySignature } from './verify-signature.js';\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 return {\n verified: true,\n registrationInfo: {\n credentialId: attestedCredentialId,\n publicKey: credentialPublicKey,\n counter,\n transports:\n attestationResponse.transports as AuthenticatorTransportFuture[],\n aaguid: formatAAGUID(aaguid),\n attestationFormat: fmt,\n userVerified: flags.uv,\n },\n };\n}\n\n/**\n * Reads the authenticator AAGUID out of a registration response by decoding its\n * attestation object and parsing the attested credential data within\n * `authData`.\n *\n * The AAGUID identifies the authenticator model (e.g. iCloud Keychain, Google\n * Password Manager, a hardware key), so it is useful for telemetry or for\n * showing the user where their passkey lives.\n *\n * Unlike {@link verifyRegistrationResponse}, this reads the response as-is\n * without verifying it, so treat the value as untrusted until enrollment\n * completes; the verified AAGUID is persisted on\n * `passkeyRecord.credential.aaguid`. Note also that many authenticators\n * deliberately report an all-zero AAGUID.\n *\n * @param registrationResponse - Result of `navigator.credentials.create()`.\n * @returns The AAGUID as a dashed UUID string, or `undefined` if the\n * authenticator data carries no attested credential data.\n * @throws If the attestation object or its authenticator data is malformed.\n */\nexport function getAAGUIDFromRegistrationResponse(\n registrationResponse: PasskeyRegistrationResponse,\n): string | undefined {\n const attestationObject = decodeAttestationObject(\n base64URLToBytes(registrationResponse.response.attestationObject),\n );\n const { aaguid } = parseAuthenticatorData(attestationObject.get('authData'));\n return aaguid ? formatAAGUID(aaguid) : undefined;\n}\n\n/**\n * Format the raw 16-byte AAGUID from attested credential data as a dashed\n * UUID string (8-4-4-4-12).\n *\n * @param aaguid - Raw AAGUID bytes.\n * @returns The AAGUID in canonical UUID form.\n */\nfunction formatAAGUID(aaguid: Uint8Array): string {\n const aaguidHex = bytesToHex(aaguid);\n return [\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\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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-signature.d.ts","sourceRoot":"","sources":["../../src/webauthn/verify-signature.ts"],"names":[],"mappings":"AAQA,KAAK,aAAa,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,UAAU,CAAC,CAAC;AAsLtD;;;;;;;;;;;;GAYG;AACH,wBAAsB,eAAe,CAAC,IAAI,EAAE;IAC1C,aAAa,EAAE,aAAa,CAAC;IAC7B,SAAS,EAAE,UAAU,CAAC;IACtB,IAAI,EAAE,UAAU,CAAC;CAClB,GAAG,OAAO,CAAC,OAAO,CAAC,CAcnB"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { concatBytes } from
|
|
2
|
-
import { ed25519 } from
|
|
3
|
-
import { p256, p384, p521 } from
|
|
4
|
-
import { sha256, sha384, sha512 } from
|
|
5
|
-
import { bytesToBase64URL } from
|
|
6
|
-
import { COSEALG, COSECRV, COSEKEYS, COSEKTY } from
|
|
1
|
+
import { concatBytes } from '@metamask/utils';
|
|
2
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
3
|
+
import { p256, p384, p521 } from '@noble/curves/nist';
|
|
4
|
+
import { sha256, sha384, sha512 } from '@noble/hashes/sha2';
|
|
5
|
+
import { bytesToBase64URL } from '../utils/encoding.js';
|
|
6
|
+
import { COSEALG, COSECRV, COSEKEYS, COSEKTY } from './constants.js';
|
|
7
7
|
/**
|
|
8
8
|
* Get the key type from a COSE public key map.
|
|
9
9
|
*
|
|
@@ -169,4 +169,4 @@ export async function verifySignature(opts) {
|
|
|
169
169
|
throw new Error(`Unsupported COSE key type: ${kty}`);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
|
-
//# sourceMappingURL=verify-signature.
|
|
172
|
+
//# sourceMappingURL=verify-signature.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-signature.js","sourceRoot":"","sources":["../../src/webauthn/verify-signature.ts"],"names":[],"mappings":"AAAA,OAA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UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CACpC,eAAe,EACf,GAAG,EACH,cAAc,EACd,SAAS,CACV,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CAAC,IAIrC;IACC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC;IAChD,MAAM,GAAG,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAEtC,QAAQ,GAAG,EAAE,CAAC;QACZ,KAAK,OAAO,CAAC,GAAG;YACd,OAAO,SAAS,CAAC,aAAa,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QACnD,KAAK,OAAO,CAAC,GAAG;YACd,OAAO,SAAS,CAAC,aAAa,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QACnD,KAAK,OAAO,CAAC,GAAG;YACd,OAAO,SAAS,CAAC,aAAa,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;QACnD;YACE,MAAM,IAAI,KAAK,CAAC,8BAA8B,GAAG,EAAE,CAAC,CAAC;IACzD,CAAC;AACH,CAAC","sourcesContent":["import { concatBytes } from '@metamask/utils';\nimport { ed25519 } from '@noble/curves/ed25519';\nimport { p256, p384, p521 } from '@noble/curves/nist';\nimport { sha256, sha384, sha512 } from '@noble/hashes/sha2';\n\nimport { bytesToBase64URL } from '../utils/encoding.js';\nimport { COSEALG, COSECRV, COSEKEYS, COSEKTY } from './constants.js';\n\ntype COSEPublicKey = Map<number, number | Uint8Array>;\n\n/**\n * Get the key type from a COSE public key map.\n *\n * @param cosePublicKey - COSE public key map.\n * @returns The COSEKTY value.\n */\nfunction getKeyType(cosePublicKey: COSEPublicKey): number {\n const kty = cosePublicKey.get(COSEKEYS.Kty);\n if (typeof kty !== 'number') {\n throw new Error('COSE public key missing kty');\n }\n return kty;\n}\n\n/**\n * Verify an EC2 (P-256, P-384, P-521) signature using @noble/curves.\n *\n * ECDSA requires the data to be hashed with the curve-appropriate\n * algorithm before verification: SHA-256 for P-256 and SHA-384 for P-384.\n *\n * @param cosePublicKey - COSE-encoded EC2 public key.\n * @param signature - DER-encoded ECDSA signature.\n * @param data - Data that was signed.\n * @returns Whether the signature is valid.\n */\nfunction verifyEC2(\n cosePublicKey: COSEPublicKey,\n signature: Uint8Array,\n data: Uint8Array,\n): boolean {\n const alg = cosePublicKey.get(COSEKEYS.Alg);\n const crv = cosePublicKey.get(COSEKEYS.Crv) as number;\n const xCoord = cosePublicKey.get(COSEKEYS.X) as Uint8Array;\n const yCoord = cosePublicKey.get(COSEKEYS.Y) as Uint8Array;\n\n if (typeof alg !== 'number') {\n throw new Error('EC2 public key missing alg');\n }\n\n if (!xCoord || !yCoord) {\n throw new Error('EC2 public key missing x or y coordinate');\n }\n\n const uncompressed = concatBytes([new Uint8Array([0x04]), xCoord, yCoord]);\n\n switch (crv) {\n case COSECRV.P256:\n return p256.verify(signature, sha256(data), uncompressed);\n case COSECRV.P384:\n return p384.verify(signature, sha384(data), uncompressed);\n case COSECRV.P521:\n return p521.verify(signature, sha512(data), uncompressed);\n default:\n throw new Error(`Unsupported EC2 curve: ${crv}`);\n }\n}\n\n/**\n * Verify an OKP (Ed25519) signature using @noble/curves.\n *\n * @param cosePublicKey - COSE-encoded OKP public key.\n * @param signature - Raw Ed25519 signature (64 bytes).\n * @param data - Data that was signed.\n * @returns Whether the signature is valid.\n */\nfunction verifyOKP(\n cosePublicKey: COSEPublicKey,\n signature: Uint8Array,\n data: Uint8Array,\n): boolean {\n const alg = cosePublicKey.get(COSEKEYS.Alg);\n const crv = cosePublicKey.get(COSEKEYS.Crv);\n const xCoord = cosePublicKey.get(COSEKEYS.X) as Uint8Array;\n\n if (alg !== COSEALG.EdDSA) {\n throw new Error(`Unexpected OKP algorithm: ${String(alg)}`);\n }\n\n if (crv !== COSECRV.ED25519) {\n throw new Error(`Unsupported OKP curve: ${String(crv)}`);\n }\n\n if (!xCoord) {\n throw new Error('OKP public key missing x coordinate');\n }\n\n return ed25519.verify(signature, data, xCoord);\n}\n\n/**\n * Verify an RSA signature using Web Crypto API.\n *\n * @param cosePublicKey - COSE-encoded RSA public key.\n * @param signature - RSA PKCS#1 v1.5 signature.\n * @param data - Data that was signed.\n * @returns Whether the signature is valid.\n */\nasync function verifyRSA(\n cosePublicKey: COSEPublicKey,\n signature: Uint8Array,\n data: Uint8Array,\n): Promise<boolean> {\n const alg = cosePublicKey.get(COSEKEYS.Alg);\n const modulus = cosePublicKey.get(COSEKEYS.N) as Uint8Array;\n const exponent = cosePublicKey.get(COSEKEYS.E) as Uint8Array;\n\n if (typeof alg !== 'number') {\n throw new Error('RSA public key missing alg');\n }\n\n if (!modulus || !exponent) {\n throw new Error('RSA public key missing n or e');\n }\n\n let keyAlgorithmName: 'RSASSA-PKCS1-v1_5' | 'RSA-PSS';\n let hashAlg: string;\n let saltLength: number | undefined;\n switch (alg) {\n case COSEALG.RS1:\n keyAlgorithmName = 'RSASSA-PKCS1-v1_5';\n hashAlg = 'SHA-1';\n break;\n case COSEALG.RS256:\n keyAlgorithmName = 'RSASSA-PKCS1-v1_5';\n hashAlg = 'SHA-256';\n break;\n case COSEALG.RS384:\n keyAlgorithmName = 'RSASSA-PKCS1-v1_5';\n hashAlg = 'SHA-384';\n break;\n case COSEALG.RS512:\n keyAlgorithmName = 'RSASSA-PKCS1-v1_5';\n hashAlg = 'SHA-512';\n break;\n case COSEALG.PS256:\n keyAlgorithmName = 'RSA-PSS';\n hashAlg = 'SHA-256';\n saltLength = 32;\n break;\n case COSEALG.PS384:\n keyAlgorithmName = 'RSA-PSS';\n hashAlg = 'SHA-384';\n saltLength = 48;\n break;\n case COSEALG.PS512:\n keyAlgorithmName = 'RSA-PSS';\n hashAlg = 'SHA-512';\n saltLength = 64;\n break;\n default:\n throw new Error(`Unsupported RSA algorithm: ${alg}`);\n }\n\n const key = await globalThis.crypto.subtle.importKey(\n 'jwk',\n {\n kty: 'RSA',\n n: bytesToBase64URL(modulus),\n e: bytesToBase64URL(exponent),\n },\n { name: keyAlgorithmName, hash: { name: hashAlg } },\n false,\n ['verify'],\n );\n\n const verifyAlgorithm =\n keyAlgorithmName === 'RSA-PSS'\n ? { name: 'RSA-PSS', saltLength: saltLength as number }\n : 'RSASSA-PKCS1-v1_5';\n\n const signatureBytes = Uint8Array.from(signature);\n const dataBytes = Uint8Array.from(data);\n return globalThis.crypto.subtle.verify(\n verifyAlgorithm,\n key,\n signatureBytes,\n dataBytes,\n );\n}\n\n/**\n * Verify a WebAuthn signature using the appropriate algorithm based on\n * the COSE key type.\n *\n * Uses @noble/curves for EC2 and OKP (synchronous, audited, handles DER\n * natively). Falls back to Web Crypto API for RSA.\n *\n * @param opts - Options object.\n * @param opts.cosePublicKey - COSE-encoded public key as a Map.\n * @param opts.signature - The signature bytes.\n * @param opts.data - The data that was signed.\n * @returns Whether the signature is valid.\n */\nexport async function verifySignature(opts: {\n cosePublicKey: COSEPublicKey;\n signature: Uint8Array;\n data: Uint8Array;\n}): Promise<boolean> {\n const { cosePublicKey, signature, data } = opts;\n const kty = getKeyType(cosePublicKey);\n\n switch (kty) {\n case COSEKTY.EC2:\n return verifyEC2(cosePublicKey, signature, data);\n case COSEKTY.OKP:\n return verifyOKP(cosePublicKey, signature, data);\n case COSEKTY.RSA:\n return verifyRSA(cosePublicKey, signature, data);\n default:\n throw new Error(`Unsupported COSE key type: ${kty}`);\n }\n}\n"]}
|