@metamask/passkey-controller 1.0.0 → 2.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 +23 -2
- package/README.md +30 -13
- package/dist/PasskeyController.cjs +178 -120
- package/dist/PasskeyController.cjs.map +1 -1
- package/dist/PasskeyController.d.cts +61 -60
- package/dist/PasskeyController.d.cts.map +1 -1
- package/dist/PasskeyController.d.mts +61 -60
- package/dist/PasskeyController.d.mts.map +1 -1
- package/dist/PasskeyController.mjs +180 -122
- package/dist/PasskeyController.mjs.map +1 -1
- package/dist/ceremony-manager.cjs +3 -2
- package/dist/ceremony-manager.cjs.map +1 -1
- package/dist/ceremony-manager.d.cts +3 -2
- package/dist/ceremony-manager.d.cts.map +1 -1
- package/dist/ceremony-manager.d.mts +3 -2
- package/dist/ceremony-manager.d.mts.map +1 -1
- package/dist/ceremony-manager.mjs +3 -2
- package/dist/ceremony-manager.mjs.map +1 -1
- package/dist/constants.cjs +2 -0
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +2 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +2 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +2 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/key-derivation.cjs +3 -35
- package/dist/key-derivation.cjs.map +1 -1
- package/dist/key-derivation.d.cts +5 -28
- package/dist/key-derivation.d.cts.map +1 -1
- package/dist/key-derivation.d.mts +5 -28
- package/dist/key-derivation.d.mts.map +1 -1
- package/dist/key-derivation.mjs +2 -33
- package/dist/key-derivation.mjs.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +1 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +1 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs.map +1 -1
- package/dist/utils/crypto.cjs +12 -1
- package/dist/utils/crypto.cjs.map +1 -1
- package/dist/utils/crypto.d.cts +7 -0
- package/dist/utils/crypto.d.cts.map +1 -1
- package/dist/utils/crypto.d.mts +7 -0
- package/dist/utils/crypto.d.mts.map +1 -1
- package/dist/utils/crypto.mjs +10 -0
- package/dist/utils/crypto.mjs.map +1 -1
- package/dist/webauthn/types.cjs.map +1 -1
- package/dist/webauthn/types.d.cts +1 -1
- package/dist/webauthn/types.d.cts.map +1 -1
- package/dist/webauthn/types.d.mts +1 -1
- package/dist/webauthn/types.d.mts.map +1 -1
- package/dist/webauthn/types.mjs.map +1 -1
- package/dist/webauthn/verify-authentication-response.cjs +3 -4
- package/dist/webauthn/verify-authentication-response.cjs.map +1 -1
- package/dist/webauthn/verify-authentication-response.d.cts +3 -2
- package/dist/webauthn/verify-authentication-response.d.cts.map +1 -1
- package/dist/webauthn/verify-authentication-response.d.mts +3 -2
- package/dist/webauthn/verify-authentication-response.d.mts.map +1 -1
- package/dist/webauthn/verify-authentication-response.mjs +3 -4
- package/dist/webauthn/verify-authentication-response.mjs.map +1 -1
- package/dist/webauthn/verify-registration-response.cjs +8 -6
- package/dist/webauthn/verify-registration-response.cjs.map +1 -1
- package/dist/webauthn/verify-registration-response.d.cts +5 -5
- package/dist/webauthn/verify-registration-response.d.cts.map +1 -1
- package/dist/webauthn/verify-registration-response.d.mts +5 -5
- package/dist/webauthn/verify-registration-response.d.mts.map +1 -1
- package/dist/webauthn/verify-registration-response.mjs +8 -6
- package/dist/webauthn/verify-registration-response.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1,28 +1,5 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { PasskeyAuthenticationResponse
|
|
3
|
-
/**
|
|
4
|
-
* Derives an AES-256 wrapping key from a WebAuthn registration ceremony
|
|
5
|
-
* response.
|
|
6
|
-
*
|
|
7
|
-
* Uses the PRF output as HKDF input key material when
|
|
8
|
-
* `clientExtensionResults.prf.results.first` is a non-empty string;
|
|
9
|
-
* otherwise falls back to the random `userHandle` created during option
|
|
10
|
-
* generation (including when PRF is enabled but no output is present).
|
|
11
|
-
*
|
|
12
|
-
* @param registrationResponse - The registration credential result from
|
|
13
|
-
* `navigator.credentials.create()`.
|
|
14
|
-
* @param registrationCeremony - In-flight registration ceremony state from
|
|
15
|
-
* when `generateRegistrationOptions()` was called.
|
|
16
|
-
* @param verifiedCredentialId - Base64url credential id from verified
|
|
17
|
-
* authenticator data (same value as persisted `credential.id` after
|
|
18
|
-
* `verifyRegistrationResponse`), not the client wrapper field alone.
|
|
19
|
-
* @returns The derived 32-byte AES wrapping key and the
|
|
20
|
-
* {@link PasskeyKeyDerivation} parameters needed to reproduce it.
|
|
21
|
-
*/
|
|
22
|
-
export declare function deriveKeyFromRegistrationResponse(registrationResponse: PasskeyRegistrationResponse, registrationCeremony: PasskeyRegistrationCeremony, verifiedCredentialId: string): {
|
|
23
|
-
encKey: Uint8Array;
|
|
24
|
-
keyDerivation: PasskeyKeyDerivation;
|
|
25
|
-
};
|
|
1
|
+
import type { PasskeyRecord } from "./types.mjs";
|
|
2
|
+
import type { PasskeyAuthenticationResponse } from "./webauthn/types.mjs";
|
|
26
3
|
/**
|
|
27
4
|
* Derives an AES-256 wrapping key from a WebAuthn authentication ceremony
|
|
28
5
|
* response.
|
|
@@ -33,11 +10,11 @@ export declare function deriveKeyFromRegistrationResponse(registrationResponse:
|
|
|
33
10
|
*
|
|
34
11
|
* @param authenticationResponse - The authentication credential result
|
|
35
12
|
* from `navigator.credentials.get()`.
|
|
36
|
-
* @param record -
|
|
37
|
-
*
|
|
13
|
+
* @param record - Credential id and key derivation parameters (ciphertext is
|
|
14
|
+
* not read).
|
|
38
15
|
* @returns The derived 32-byte AES wrapping key.
|
|
39
16
|
* @throws {@link PasskeyControllerError} with code `missing_key_material` if the
|
|
40
17
|
* required key material (PRF result or userHandle) is missing from the response.
|
|
41
18
|
*/
|
|
42
|
-
export declare function deriveKeyFromAuthenticationResponse(authenticationResponse: PasskeyAuthenticationResponse, record: PasskeyRecord): Uint8Array;
|
|
19
|
+
export declare function deriveKeyFromAuthenticationResponse(authenticationResponse: PasskeyAuthenticationResponse, record: Pick<PasskeyRecord, 'credential' | 'keyDerivation'>): Uint8Array;
|
|
43
20
|
//# sourceMappingURL=key-derivation.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-derivation.d.mts","sourceRoot":"","sources":["../src/key-derivation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"key-derivation.d.mts","sourceRoot":"","sources":["../src/key-derivation.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,aAAa,EAA6B,oBAAgB;AAGxE,OAAO,KAAK,EAAE,6BAA6B,EAAE,6BAAyB;AAEtE;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mCAAmC,CACjD,sBAAsB,EAAE,6BAA6B,EACrD,MAAM,EAAE,IAAI,CAAC,aAAa,EAAE,YAAY,GAAG,eAAe,CAAC,GAC1D,UAAU,CA0BZ"}
|
package/dist/key-derivation.mjs
CHANGED
|
@@ -2,37 +2,6 @@ import { PasskeyControllerErrorCode, PasskeyControllerErrorMessage } from "./con
|
|
|
2
2
|
import { PasskeyControllerError } from "./errors.mjs";
|
|
3
3
|
import { deriveEncryptionKey } from "./utils/crypto.mjs";
|
|
4
4
|
import { base64URLToBytes } from "./utils/encoding.mjs";
|
|
5
|
-
/**
|
|
6
|
-
* Derives an AES-256 wrapping key from a WebAuthn registration ceremony
|
|
7
|
-
* response.
|
|
8
|
-
*
|
|
9
|
-
* Uses the PRF output as HKDF input key material when
|
|
10
|
-
* `clientExtensionResults.prf.results.first` is a non-empty string;
|
|
11
|
-
* otherwise falls back to the random `userHandle` created during option
|
|
12
|
-
* generation (including when PRF is enabled but no output is present).
|
|
13
|
-
*
|
|
14
|
-
* @param registrationResponse - The registration credential result from
|
|
15
|
-
* `navigator.credentials.create()`.
|
|
16
|
-
* @param registrationCeremony - In-flight registration ceremony state from
|
|
17
|
-
* when `generateRegistrationOptions()` was called.
|
|
18
|
-
* @param verifiedCredentialId - Base64url credential id from verified
|
|
19
|
-
* authenticator data (same value as persisted `credential.id` after
|
|
20
|
-
* `verifyRegistrationResponse`), not the client wrapper field alone.
|
|
21
|
-
* @returns The derived 32-byte AES wrapping key and the
|
|
22
|
-
* {@link PasskeyKeyDerivation} parameters needed to reproduce it.
|
|
23
|
-
*/
|
|
24
|
-
export function deriveKeyFromRegistrationResponse(registrationResponse, registrationCeremony, verifiedCredentialId) {
|
|
25
|
-
const prfFirst = registrationResponse.clientExtensionResults?.prf?.results?.first;
|
|
26
|
-
const hasPrfOutput = typeof prfFirst === 'string' && prfFirst.length > 0;
|
|
27
|
-
const keyDerivation = hasPrfOutput
|
|
28
|
-
? { method: 'prf', prfSalt: registrationCeremony.prfSalt }
|
|
29
|
-
: { method: 'userHandle' };
|
|
30
|
-
const ikm = keyDerivation.method === 'prf'
|
|
31
|
-
? base64URLToBytes(prfFirst)
|
|
32
|
-
: base64URLToBytes(registrationCeremony.userHandle);
|
|
33
|
-
const encKey = deriveEncryptionKey(ikm, base64URLToBytes(verifiedCredentialId));
|
|
34
|
-
return { encKey, keyDerivation };
|
|
35
|
-
}
|
|
36
5
|
/**
|
|
37
6
|
* Derives an AES-256 wrapping key from a WebAuthn authentication ceremony
|
|
38
7
|
* response.
|
|
@@ -43,8 +12,8 @@ export function deriveKeyFromRegistrationResponse(registrationResponse, registra
|
|
|
43
12
|
*
|
|
44
13
|
* @param authenticationResponse - The authentication credential result
|
|
45
14
|
* from `navigator.credentials.get()`.
|
|
46
|
-
* @param record -
|
|
47
|
-
*
|
|
15
|
+
* @param record - Credential id and key derivation parameters (ciphertext is
|
|
16
|
+
* not read).
|
|
48
17
|
* @returns The derived 32-byte AES wrapping key.
|
|
49
18
|
* @throws {@link PasskeyControllerError} with code `missing_key_material` if the
|
|
50
19
|
* required key material (PRF result or userHandle) is missing from the response.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key-derivation.mjs","sourceRoot":"","sources":["../src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,CAAC,kBAAkB,EAAE,CACxD,CAAC;IACJ,CAAC;IAED,OAAO,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC,CAAC;AAC1E,CAAC","sourcesContent":["import {\n PasskeyControllerErrorCode,\n PasskeyControllerErrorMessage,\n} from './constants';\nimport { PasskeyControllerError } from './errors';\nimport type { PasskeyRecord, PrfClientExtensionResults } from './types';\nimport { deriveEncryptionKey } from './utils/crypto';\nimport { base64URLToBytes } from './utils/encoding';\nimport type { PasskeyAuthenticationResponse } from './webauthn/types';\n\n/**\n * Derives an AES-256 wrapping key from a WebAuthn authentication ceremony\n * response.\n *\n * The derivation method is determined by `record.keyDerivation`:\n * - `prf` -- uses the PRF evaluation result from `clientExtensionResults`.\n * - `userHandle` -- uses the `userHandle` returned in the assertion.\n *\n * @param authenticationResponse - The authentication credential result\n * from `navigator.credentials.get()`.\n * @param record - Credential id and key derivation parameters (ciphertext is\n * not read).\n * @returns The derived 32-byte AES wrapping key.\n * @throws {@link PasskeyControllerError} with code `missing_key_material` if the\n * required key material (PRF result or userHandle) is missing from the response.\n */\nexport function deriveKeyFromAuthenticationResponse(\n authenticationResponse: PasskeyAuthenticationResponse,\n record: Pick<PasskeyRecord, 'credential' | 'keyDerivation'>,\n): Uint8Array {\n const { userHandle } = authenticationResponse.response;\n const prfFirst = (\n authenticationResponse.clientExtensionResults as PrfClientExtensionResults\n )?.prf?.results?.first;\n const hasPrfOutput = typeof prfFirst === 'string' && prfFirst.length > 0;\n\n let ikm: Uint8Array;\n if (record.keyDerivation.method === 'prf') {\n if (!hasPrfOutput) {\n throw new PasskeyControllerError(\n PasskeyControllerErrorMessage.MissingKeyMaterial,\n { code: PasskeyControllerErrorCode.MissingKeyMaterial },\n );\n }\n ikm = base64URLToBytes(prfFirst);\n } else if (userHandle) {\n ikm = base64URLToBytes(userHandle);\n } else {\n throw new PasskeyControllerError(\n PasskeyControllerErrorMessage.MissingKeyMaterial,\n { code: PasskeyControllerErrorCode.MissingKeyMaterial },\n );\n }\n\n return deriveEncryptionKey(ikm, base64URLToBytes(record.credential.id));\n}\n"]}
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type Base64String = string;\n\nexport type Base64URLString = string;\n\nexport type AuthenticatorTransportFuture =\n | 'ble'\n | 'cable'\n | 'hybrid'\n | 'internal'\n | 'nfc'\n | 'smart-card'\n | 'usb';\n\n/**\n * WebAuthn credential metadata used to identify the passkey and verify\n * subsequent assertions.\n */\nexport type PasskeyCredentialInfo = {\n /** WebAuthn credential ID (base64url). */\n id: Base64URLString;\n /** COSE-encoded credential public key (base64url) used to verify assertions. */\n publicKey: Base64URLString;\n /** Authenticator signature counter for replay/clone detection. */\n counter: number;\n /** Authenticator transports hint for `allowCredentials`. */\n transports?: AuthenticatorTransportFuture[];\n /** Authenticator AAGUID captured from attested credential data at registration. */\n aaguid: string;\n};\n\n/**\n * Vault key wrapped under the passkey-derived AES-256-GCM key.\n */\nexport type EncryptedVaultKey = {\n /** Base64-encoded AES-256-GCM ciphertext of the vault key. */\n ciphertext: Base64String;\n /** Base64-encoded AES-GCM IV used during encryption. */\n iv: Base64String;\n};\n\n/**\n * Parameters needed to reproduce the AES-256 wrapping key at unlock time.\n *\n * Encoded as a discriminated union so PRF-only fields (e.g. `prfSalt`) can\n * only exist on the PRF branch, removing the \"optional but actually\n * required\" footgun.\n */\nexport type PasskeyKeyDerivation =\n | {\n method: 'prf';\n /**\n * PRF salt sent in `get()` extension options to reproduce the same PRF\n * output that was generated at registration.\n */\n prfSalt: Base64URLString;\n }\n | { method: 'userHandle' };\n\n/** Discriminator value for {@link PasskeyKeyDerivation}. */\nexport type PasskeyDerivationMethod = PasskeyKeyDerivation['method'];\n\nexport type PasskeyRecord = {\n /** WebAuthn credential metadata used for assertion verification & re-discovery. */\n credential: PasskeyCredentialInfo;\n /** Vault key wrapped under the passkey-derived key. */\n encryptedVaultKey: EncryptedVaultKey;\n /** How the wrapping key is reconstructed at unlock time. */\n keyDerivation: PasskeyKeyDerivation;\n};\n\n/**\n * In-memory state for one **in-flight** WebAuthn **registration** ceremony\n * (from `create()` options until `protectVaultKeyWithPasskey` completes). This is\n * not a user login session; it is keyed by challenge and distinct from the full\n * spec ceremony (which includes the authenticator round-trip).\n */\nexport type PasskeyRegistrationCeremony = {\n userHandle: Base64URLString;\n prfSalt
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type Base64String = string;\n\nexport type Base64URLString = string;\n\nexport type AuthenticatorTransportFuture =\n | 'ble'\n | 'cable'\n | 'hybrid'\n | 'internal'\n | 'nfc'\n | 'smart-card'\n | 'usb';\n\n/**\n * WebAuthn credential metadata used to identify the passkey and verify\n * subsequent assertions.\n */\nexport type PasskeyCredentialInfo = {\n /** WebAuthn credential ID (base64url). */\n id: Base64URLString;\n /** COSE-encoded credential public key (base64url) used to verify assertions. */\n publicKey: Base64URLString;\n /** Authenticator signature counter for replay/clone detection. */\n counter: number;\n /** Authenticator transports hint for `allowCredentials`. */\n transports?: AuthenticatorTransportFuture[];\n /** Authenticator AAGUID captured from attested credential data at registration. */\n aaguid: string;\n};\n\n/**\n * Vault key wrapped under the passkey-derived AES-256-GCM key.\n */\nexport type EncryptedVaultKey = {\n /** Base64-encoded AES-256-GCM ciphertext of the vault key. */\n ciphertext: Base64String;\n /** Base64-encoded AES-GCM IV used during encryption. */\n iv: Base64String;\n};\n\n/**\n * Parameters needed to reproduce the AES-256 wrapping key at unlock time.\n *\n * Encoded as a discriminated union so PRF-only fields (e.g. `prfSalt`) can\n * only exist on the PRF branch, removing the \"optional but actually\n * required\" footgun.\n */\nexport type PasskeyKeyDerivation =\n | {\n method: 'prf';\n /**\n * PRF salt sent in `get()` extension options to reproduce the same PRF\n * output that was generated at registration.\n */\n prfSalt: Base64URLString;\n }\n | { method: 'userHandle' };\n\n/** Discriminator value for {@link PasskeyKeyDerivation}. */\nexport type PasskeyDerivationMethod = PasskeyKeyDerivation['method'];\n\nexport type PasskeyRecord = {\n /** WebAuthn credential metadata used for assertion verification & re-discovery. */\n credential: PasskeyCredentialInfo;\n /** Vault key wrapped under the passkey-derived key. */\n encryptedVaultKey: EncryptedVaultKey;\n /** How the wrapping key is reconstructed at unlock time. */\n keyDerivation: PasskeyKeyDerivation;\n};\n\n/**\n * In-memory state for one **in-flight** WebAuthn **registration** ceremony\n * (from `create()` options until `protectVaultKeyWithPasskey` completes). This is\n * not a user login session; it is keyed by challenge and distinct from the full\n * spec ceremony (which includes the authenticator round-trip).\n */\nexport type PasskeyRegistrationCeremony = {\n userHandle: Base64URLString;\n prfSalt?: Base64URLString;\n challenge: Base64URLString;\n /** When this ceremony was started (ms since epoch); used for TTL pruning. */\n createdAt: number;\n};\n\n/**\n * In-memory state for one **in-flight** WebAuthn **authentication** ceremony\n * (`get()` options until the assertion is verified). Not a user login session.\n */\nexport type PasskeyAuthenticationCeremony = {\n challenge: Base64URLString;\n /** When this ceremony was started (ms since epoch); used for TTL pruning. */\n createdAt: number;\n};\n\n/**\n * PRF extension types not covered by DOM typings.\n */\nexport type PrfEvalExtension = {\n eval: {\n first: Base64URLString;\n };\n};\n\nexport type PrfClientExtensionResults = {\n prf?: {\n enabled?: boolean;\n results?: { first?: Base64URLString };\n };\n};\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -61,7 +61,7 @@ export type PasskeyRecord = {
|
|
|
61
61
|
*/
|
|
62
62
|
export type PasskeyRegistrationCeremony = {
|
|
63
63
|
userHandle: Base64URLString;
|
|
64
|
-
prfSalt
|
|
64
|
+
prfSalt?: Base64URLString;
|
|
65
65
|
challenge: Base64URLString;
|
|
66
66
|
/** When this ceremony was started (ms since epoch); used for TTL pruning. */
|
|
67
67
|
createdAt: number;
|
package/dist/types.d.cts.map
CHANGED
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;GAKG;AACH,MAAM,MAAM,2BAA2B,GAAG;IACxC,UAAU,EAAE,eAAe,CAAC;IAC5B,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,SAAS,EAAE,eAAe,CAAC;IAC3B,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,6BAA6B,GAAG;IAC1C,SAAS,EAAE,eAAe,CAAC;IAC3B,6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE;QACJ,KAAK,EAAE,eAAe,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,CAAC,EAAE;QACJ,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,OAAO,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,eAAe,CAAA;SAAE,CAAC;KACvC,CAAC;CACH,CAAC"}
|
package/dist/types.d.mts
CHANGED
|
@@ -61,7 +61,7 @@ export type PasskeyRecord = {
|
|
|
61
61
|
*/
|
|
62
62
|
export type PasskeyRegistrationCeremony = {
|
|
63
63
|
userHandle: Base64URLString;
|
|
64
|
-
prfSalt
|
|
64
|
+
prfSalt?: Base64URLString;
|
|
65
65
|
challenge: Base64URLString;
|
|
66
66
|
/** When this ceremony was started (ms since epoch); used for TTL pruning. */
|
|
67
67
|
createdAt: number;
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC;AAElC,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,4BAA4B,GACpC,KAAK,GACL,OAAO,GACP,QAAQ,GACR,UAAU,GACV,KAAK,GACL,YAAY,GACZ,KAAK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6EAA6E;IAC7E,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE;QACJ,KAAK,EAAE,eAAe,CAAC;KACxB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,GAAG,CAAC,EAAE;QACJ,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,OAAO,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,eAAe,CAAA;SAAE,CAAC;KACvC,CAAC;CACH,CAAC"}
|
package/dist/types.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type Base64String = string;\n\nexport type Base64URLString = string;\n\nexport type AuthenticatorTransportFuture =\n | 'ble'\n | 'cable'\n | 'hybrid'\n | 'internal'\n | 'nfc'\n | 'smart-card'\n | 'usb';\n\n/**\n * WebAuthn credential metadata used to identify the passkey and verify\n * subsequent assertions.\n */\nexport type PasskeyCredentialInfo = {\n /** WebAuthn credential ID (base64url). */\n id: Base64URLString;\n /** COSE-encoded credential public key (base64url) used to verify assertions. */\n publicKey: Base64URLString;\n /** Authenticator signature counter for replay/clone detection. */\n counter: number;\n /** Authenticator transports hint for `allowCredentials`. */\n transports?: AuthenticatorTransportFuture[];\n /** Authenticator AAGUID captured from attested credential data at registration. */\n aaguid: string;\n};\n\n/**\n * Vault key wrapped under the passkey-derived AES-256-GCM key.\n */\nexport type EncryptedVaultKey = {\n /** Base64-encoded AES-256-GCM ciphertext of the vault key. */\n ciphertext: Base64String;\n /** Base64-encoded AES-GCM IV used during encryption. */\n iv: Base64String;\n};\n\n/**\n * Parameters needed to reproduce the AES-256 wrapping key at unlock time.\n *\n * Encoded as a discriminated union so PRF-only fields (e.g. `prfSalt`) can\n * only exist on the PRF branch, removing the \"optional but actually\n * required\" footgun.\n */\nexport type PasskeyKeyDerivation =\n | {\n method: 'prf';\n /**\n * PRF salt sent in `get()` extension options to reproduce the same PRF\n * output that was generated at registration.\n */\n prfSalt: Base64URLString;\n }\n | { method: 'userHandle' };\n\n/** Discriminator value for {@link PasskeyKeyDerivation}. */\nexport type PasskeyDerivationMethod = PasskeyKeyDerivation['method'];\n\nexport type PasskeyRecord = {\n /** WebAuthn credential metadata used for assertion verification & re-discovery. */\n credential: PasskeyCredentialInfo;\n /** Vault key wrapped under the passkey-derived key. */\n encryptedVaultKey: EncryptedVaultKey;\n /** How the wrapping key is reconstructed at unlock time. */\n keyDerivation: PasskeyKeyDerivation;\n};\n\n/**\n * In-memory state for one **in-flight** WebAuthn **registration** ceremony\n * (from `create()` options until `protectVaultKeyWithPasskey` completes). This is\n * not a user login session; it is keyed by challenge and distinct from the full\n * spec ceremony (which includes the authenticator round-trip).\n */\nexport type PasskeyRegistrationCeremony = {\n userHandle: Base64URLString;\n prfSalt
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["export type Base64String = string;\n\nexport type Base64URLString = string;\n\nexport type AuthenticatorTransportFuture =\n | 'ble'\n | 'cable'\n | 'hybrid'\n | 'internal'\n | 'nfc'\n | 'smart-card'\n | 'usb';\n\n/**\n * WebAuthn credential metadata used to identify the passkey and verify\n * subsequent assertions.\n */\nexport type PasskeyCredentialInfo = {\n /** WebAuthn credential ID (base64url). */\n id: Base64URLString;\n /** COSE-encoded credential public key (base64url) used to verify assertions. */\n publicKey: Base64URLString;\n /** Authenticator signature counter for replay/clone detection. */\n counter: number;\n /** Authenticator transports hint for `allowCredentials`. */\n transports?: AuthenticatorTransportFuture[];\n /** Authenticator AAGUID captured from attested credential data at registration. */\n aaguid: string;\n};\n\n/**\n * Vault key wrapped under the passkey-derived AES-256-GCM key.\n */\nexport type EncryptedVaultKey = {\n /** Base64-encoded AES-256-GCM ciphertext of the vault key. */\n ciphertext: Base64String;\n /** Base64-encoded AES-GCM IV used during encryption. */\n iv: Base64String;\n};\n\n/**\n * Parameters needed to reproduce the AES-256 wrapping key at unlock time.\n *\n * Encoded as a discriminated union so PRF-only fields (e.g. `prfSalt`) can\n * only exist on the PRF branch, removing the \"optional but actually\n * required\" footgun.\n */\nexport type PasskeyKeyDerivation =\n | {\n method: 'prf';\n /**\n * PRF salt sent in `get()` extension options to reproduce the same PRF\n * output that was generated at registration.\n */\n prfSalt: Base64URLString;\n }\n | { method: 'userHandle' };\n\n/** Discriminator value for {@link PasskeyKeyDerivation}. */\nexport type PasskeyDerivationMethod = PasskeyKeyDerivation['method'];\n\nexport type PasskeyRecord = {\n /** WebAuthn credential metadata used for assertion verification & re-discovery. */\n credential: PasskeyCredentialInfo;\n /** Vault key wrapped under the passkey-derived key. */\n encryptedVaultKey: EncryptedVaultKey;\n /** How the wrapping key is reconstructed at unlock time. */\n keyDerivation: PasskeyKeyDerivation;\n};\n\n/**\n * In-memory state for one **in-flight** WebAuthn **registration** ceremony\n * (from `create()` options until `protectVaultKeyWithPasskey` completes). This is\n * not a user login session; it is keyed by challenge and distinct from the full\n * spec ceremony (which includes the authenticator round-trip).\n */\nexport type PasskeyRegistrationCeremony = {\n userHandle: Base64URLString;\n prfSalt?: Base64URLString;\n challenge: Base64URLString;\n /** When this ceremony was started (ms since epoch); used for TTL pruning. */\n createdAt: number;\n};\n\n/**\n * In-memory state for one **in-flight** WebAuthn **authentication** ceremony\n * (`get()` options until the assertion is verified). Not a user login session.\n */\nexport type PasskeyAuthenticationCeremony = {\n challenge: Base64URLString;\n /** When this ceremony was started (ms since epoch); used for TTL pruning. */\n createdAt: number;\n};\n\n/**\n * PRF extension types not covered by DOM typings.\n */\nexport type PrfEvalExtension = {\n eval: {\n first: Base64URLString;\n };\n};\n\nexport type PrfClientExtensionResults = {\n prf?: {\n enabled?: boolean;\n results?: { first?: Base64URLString };\n };\n};\n"]}
|
package/dist/utils/crypto.cjs
CHANGED
|
@@ -1,13 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.decryptWithKey = exports.encryptWithKey = exports.deriveEncryptionKey = void 0;
|
|
3
|
+
exports.decryptWithKey = exports.encryptWithKey = exports.deriveEncryptionKey = exports.randomBytesToBase64URL = void 0;
|
|
4
4
|
const utils_1 = require("@metamask/utils");
|
|
5
5
|
const aes_1 = require("@noble/ciphers/aes");
|
|
6
6
|
const webcrypto_1 = require("@noble/ciphers/webcrypto");
|
|
7
7
|
const hkdf_1 = require("@noble/hashes/hkdf");
|
|
8
8
|
const sha2_1 = require("@noble/hashes/sha2");
|
|
9
|
+
const encoding_1 = require("./encoding.cjs");
|
|
9
10
|
const PASSKEY_HKDF_INFO = 'metamask:passkey:encryption-key:v1';
|
|
10
11
|
const AES_GCM_IV_LENGTH = 12;
|
|
12
|
+
/**
|
|
13
|
+
* Generates random bytes and returns them as a base64url string (no padding).
|
|
14
|
+
*
|
|
15
|
+
* @param byteLength - Number of bytes to generate (e.g. WebAuthn challenge length).
|
|
16
|
+
* @returns Base64url-encoded random bytes.
|
|
17
|
+
*/
|
|
18
|
+
function randomBytesToBase64URL(byteLength) {
|
|
19
|
+
return (0, encoding_1.bytesToBase64URL)((0, webcrypto_1.randomBytes)(byteLength));
|
|
20
|
+
}
|
|
21
|
+
exports.randomBytesToBase64URL = randomBytesToBase64URL;
|
|
11
22
|
/**
|
|
12
23
|
* Derives an AES-256 encryption key from input key material and a credential ID
|
|
13
24
|
* using HKDF-SHA256.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.cjs","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":";;;AAAA,2CAA+D;AAC/D,4CAAyC;AACzC,wDAAuD;AACvD,6CAA0C;AAC1C,6CAA4C;AAE5C,MAAM,iBAAiB,GAAG,oCAAoC,CAAC;AAE/D,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;;;;;GAOG;AACH,SAAgB,mBAAmB,CACjC,GAAe,EACf,IAAgB;IAEhB,OAAO,IAAA,WAAI,EAAC,aAAM,EAAE,GAAG,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,CAAC,CAAC;AACxD,CAAC;AALD,kDAKC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,SAAiB,EACjB,GAAe;IAEf,MAAM,EAAE,GAAG,IAAA,uBAAW,EAAC,iBAAiB,CAAC,CAAC;IAC1C,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IACpD,MAAM,eAAe,GAAG,IAAA,SAAG,EAAC,GAAG,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAEtD,OAAO;QACL,UAAU,EAAE,IAAA,qBAAa,EAAC,eAAe,CAAC;QAC1C,EAAE,EAAE,IAAA,qBAAa,EAAC,EAAE,CAAC;KACtB,CAAC;AACJ,CAAC;AAZD,wCAYC;AAED;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,UAAkB,EAClB,EAAU,EACV,GAAe;IAEf,MAAM,eAAe,GAAG,IAAA,qBAAa,EAAC,UAAU,CAAC,CAAC;IAClD,MAAM,OAAO,GAAG,IAAA,qBAAa,EAAC,EAAE,CAAC,CAAC;IAClC,MAAM,SAAS,GAAG,IAAA,SAAG,EAAC,GAAG,EAAE,OAAO,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAE7D,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;AAC7C,CAAC;AAVD,wCAUC","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\nconst PASSKEY_HKDF_INFO = 'metamask:passkey:encryption-key:v1';\n\nconst AES_GCM_IV_LENGTH = 12;\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"]}
|
|
1
|
+
{"version":3,"file":"crypto.cjs","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":";;;AAAA,2CAA+D;AAC/D,4CAAyC;AACzC,wDAAuD;AACvD,6CAA0C;AAC1C,6CAA4C;AAE5C,6CAA8C;AAE9C,MAAM,iBAAiB,GAAG,oCAAoC,CAAC;AAE/D,MAAM,iBAAiB,GAAG,EAAE,CA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ils';\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';\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"]}
|
package/dist/utils/crypto.d.cts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates random bytes and returns them as a base64url string (no padding).
|
|
3
|
+
*
|
|
4
|
+
* @param byteLength - Number of bytes to generate (e.g. WebAuthn challenge length).
|
|
5
|
+
* @returns Base64url-encoded random bytes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function randomBytesToBase64URL(byteLength: number): string;
|
|
1
8
|
/**
|
|
2
9
|
* Derives an AES-256 encryption key from input key material and a credential ID
|
|
3
10
|
* using HKDF-SHA256.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.cts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto.d.cts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,UAAU,GACf,UAAU,CAEZ;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,UAAU,GACd;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CASpC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,UAAU,GACd,MAAM,CAMR"}
|
package/dist/utils/crypto.d.mts
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generates random bytes and returns them as a base64url string (no padding).
|
|
3
|
+
*
|
|
4
|
+
* @param byteLength - Number of bytes to generate (e.g. WebAuthn challenge length).
|
|
5
|
+
* @returns Base64url-encoded random bytes.
|
|
6
|
+
*/
|
|
7
|
+
export declare function randomBytesToBase64URL(byteLength: number): string;
|
|
1
8
|
/**
|
|
2
9
|
* Derives an AES-256 encryption key from input key material and a credential ID
|
|
3
10
|
* using HKDF-SHA256.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.d.mts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crypto.d.mts","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAEjE;AAED;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,UAAU,EACf,IAAI,EAAE,UAAU,GACf,UAAU,CAEZ;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,GAAG,EAAE,UAAU,GACd;IAAE,UAAU,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAA;CAAE,CASpC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EACV,GAAG,EAAE,UAAU,GACd,MAAM,CAMR"}
|
package/dist/utils/crypto.mjs
CHANGED
|
@@ -3,8 +3,18 @@ import { gcm } from "@noble/ciphers/aes";
|
|
|
3
3
|
import { randomBytes } from "@noble/ciphers/webcrypto";
|
|
4
4
|
import { hkdf } from "@noble/hashes/hkdf";
|
|
5
5
|
import { sha256 } from "@noble/hashes/sha2";
|
|
6
|
+
import { bytesToBase64URL } from "./encoding.mjs";
|
|
6
7
|
const PASSKEY_HKDF_INFO = 'metamask:passkey:encryption-key:v1';
|
|
7
8
|
const AES_GCM_IV_LENGTH = 12;
|
|
9
|
+
/**
|
|
10
|
+
* Generates random bytes and returns them as a base64url string (no padding).
|
|
11
|
+
*
|
|
12
|
+
* @param byteLength - Number of bytes to generate (e.g. WebAuthn challenge length).
|
|
13
|
+
* @returns Base64url-encoded random bytes.
|
|
14
|
+
*/
|
|
15
|
+
export function randomBytesToBase64URL(byteLength) {
|
|
16
|
+
return bytesToBase64URL(randomBytes(byteLength));
|
|
17
|
+
}
|
|
8
18
|
/**
|
|
9
19
|
* Derives an AES-256 encryption key from input key material and a credential ID
|
|
10
20
|
* using HKDF-SHA256.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.mjs","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,wBAAwB;AAC/D,OAAO,EAAE,GAAG,EAAE,2BAA2B;AACzC,OAAO,EAAE,WAAW,EAAE,iCAAiC;AACvD,OAAO,EAAE,IAAI,EAAE,2BAA2B;AAC1C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAE5C,MAAM,iBAAiB,GAAG,oCAAoC,CAAC;AAE/D,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;;;;;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\nconst PASSKEY_HKDF_INFO = 'metamask:passkey:encryption-key:v1';\n\nconst AES_GCM_IV_LENGTH = 12;\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"]}
|
|
1
|
+
{"version":3,"file":"crypto.mjs","sourceRoot":"","sources":["../../src/utils/crypto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,wBAAwB;AAC/D,OAAO,EAAE,GAAG,EAAE,2BAA2B;AACzC,OAAO,EAAE,WAAW,EAAE,iCAAiC;AACvD,OAAO,EAAE,IAAI,EAAE,2BAA2B;AAC1C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAE5C,OAAO,EAAE,gBAAgB,EAAE,uBAAmB;AAE9C,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';\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuthenticatorTransportFuture,\n Base64URLString as Base64URL,\n} from '../types';\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
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuthenticatorTransportFuture,\n Base64URLString as Base64URL,\n} from '../types';\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,IAAI,SAAS,EAC7B,qBAAiB;AAElB,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,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AO,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,IAAI,SAAS,EAC7B,qBAAiB;AAElB,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,EAAE,MAAM,CAAA;KAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,4BAA4B,EAC5B,eAAe,IAAI,SAAS,EAC7B,qBAAiB;AAElB,MAAM,MAAM,iCAAiC,GAAG;IAC9C,EAAE,EAAE,SAAS,CAAC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AE,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuthenticatorTransportFuture,\n Base64URLString as Base64URL,\n} from '../types';\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
|
|
1
|
+
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/webauthn/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuthenticatorTransportFuture,\n Base64URLString as Base64URL,\n} from '../types';\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"]}
|
|
@@ -31,7 +31,7 @@ const verify_signature_1 = require("./verify-signature.cjs");
|
|
|
31
31
|
* @param opts.expectedChallenge - The base64url challenge that was issued
|
|
32
32
|
* for this ceremony.
|
|
33
33
|
* @param opts.expectedOrigin - One or more acceptable origins.
|
|
34
|
-
* @param opts.
|
|
34
|
+
* @param opts.expectedRPIDs - Relying Party ID strings to match against `rpIdHash`.
|
|
35
35
|
* @param opts.credential - The stored credential record to verify against.
|
|
36
36
|
* @param opts.credential.id - The credential ID (base64url).
|
|
37
37
|
* @param opts.credential.publicKey - The COSE-encoded public key bytes
|
|
@@ -44,7 +44,7 @@ const verify_signature_1 = require("./verify-signature.cjs");
|
|
|
44
44
|
* authentication info (new counter, origin, RP ID).
|
|
45
45
|
*/
|
|
46
46
|
async function verifyAuthenticationResponse(opts) {
|
|
47
|
-
const { response, expectedChallenge, expectedOrigin,
|
|
47
|
+
const { response, expectedChallenge, expectedOrigin, expectedRPIDs, credential, requireUserVerification = false, } = opts;
|
|
48
48
|
const { id, rawId, type: credentialType, response: assertionResponse, } = response;
|
|
49
49
|
// Ensure credential specified an ID
|
|
50
50
|
if (!id) {
|
|
@@ -93,8 +93,7 @@ async function verifyAuthenticationResponse(opts) {
|
|
|
93
93
|
const authDataBuffer = (0, encoding_1.base64URLToBytes)(assertionResponse.authenticatorData);
|
|
94
94
|
const parsedAuthData = (0, parse_authenticator_data_1.parseAuthenticatorData)(authDataBuffer);
|
|
95
95
|
const { rpIdHash, flags, counter } = parsedAuthData;
|
|
96
|
-
|
|
97
|
-
const matchedRPID = (0, match_expected_rp_id_1.matchExpectedRPID)(rpIdHash, [expectedRPID]);
|
|
96
|
+
const matchedRPID = expectedRPIDs.length > 0 ? (0, match_expected_rp_id_1.matchExpectedRPID)(rpIdHash, expectedRPIDs) : '';
|
|
98
97
|
// WebAuthn only requires the user presence flag be true
|
|
99
98
|
if (!flags.up) {
|
|
100
99
|
throw new Error('User not present during authentication');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-authentication-response.cjs","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":";;;AAAA,qDAA0D;AAC1D,2CAA8C;AAC9C,6CAA4C;AAG5C,oDAAqD;AACrD,2EAAiE;AACjE,qEAA2D;AAC3D,6EAAoE;AAGpE,6DAAqD;AAerD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,KAAK,UAAU,4BAA4B,CAAC,IAYlD;IACC,MAAM,EACJ,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,YAAY,EACZ,UAAU,EACV,uBAAuB,GAAG,KAAK,GAChC,GAAG,IAAI,CAAC;IAET,MAAM,EACJ,EAAE,EACF,KAAK,EACL,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,iBAAiB,GAC5B,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;QACjB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,0CAA0C;IAC1C,IAAI,cAAc,KAAK,YAAY,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,8BAA8B,MAAM,CAAC,cAAc,CAAC,yBAAyB,CAC9E,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,iBAAiB,EAAE,cAAc,KAAK,QAAQ,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,cAAc,GAAG,IAAA,8CAAoB,EAAC,iBAAiB,CAAC,cAAc,CAAC,CAAC;IAC9E,MAAM,EAAE,IAAI,EAAE,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AO,EAC7B,CAAC;QACD,MAAM,IAAI,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;AA3JD,oEA2JC","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.cjs","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":";;;AAAA,qDAA0D;AAC1D,2CAA8C;AAC9C,6CAA4C;AAG5C,oDAAqD;AACrD,2EAAiE;AACjE,qEAA2D;AAC3D,6EAAoE;AAGpE,6DAAqD;AAgBrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACI,KAAK,UAAU,4BAA4B,CAAC,IAYlD;IACC,MAAM,EACJ,QAAQ,EACR,iBAAiB,EACjB,cAAc,EACd,aAAa,EACb,UAAU,EACV,uBAAuB,GAAG,KAAK,GAChC,GAAG,IAAI,CAAC;IAET,MAAM,EACJ,EAAE,EACF,KAAK,EACL,IAAI,EAAE,cAAc,EACpB,QAAQ,EAAE,iBAAiB,GAC5B,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;QACjB,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;IAC7D,CAAC;IAED,0CAA0C;IAC1C,IAAI,cAAc,KAAK,YAAY,EAAE,CAAC;QACpC,MAAM,IAAI,KAAK,CACb,8BAA8B,MAAM,CAAC,cAAc,CAAC,yBAAyB,CAC9E,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,iBAAiB,EAAE,cAAc,KAAK,QAAQ,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IAED,MAAM,cAAc,GAAG,IAAA,8CAAoB,EA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AC;IAED,IACE,CAAC,OAAO,GAAG,CAAC,IAAI,UAAU,CAAC,OAAO,GAAG,CAAC,CAAC;QACvC,OAAO,IAAI,UAAU,CAAC,OAAO,EAC7B,CAAC;QACD,MAAM,IAAI,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;AA3JD,oEA2JC","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"]}
|
|
@@ -10,6 +10,7 @@ export type VerifiedAuthenticationResponse = {
|
|
|
10
10
|
newCounter: number;
|
|
11
11
|
userVerified: boolean;
|
|
12
12
|
origin: string;
|
|
13
|
+
/** Matched RP ID, or `""` when `expectedRPIDs` is empty (RP ID hash check skipped). */
|
|
13
14
|
rpID: string;
|
|
14
15
|
};
|
|
15
16
|
};
|
|
@@ -35,7 +36,7 @@ export type VerifiedAuthenticationResponse = {
|
|
|
35
36
|
* @param opts.expectedChallenge - The base64url challenge that was issued
|
|
36
37
|
* for this ceremony.
|
|
37
38
|
* @param opts.expectedOrigin - One or more acceptable origins.
|
|
38
|
-
* @param opts.
|
|
39
|
+
* @param opts.expectedRPIDs - Relying Party ID strings to match against `rpIdHash`.
|
|
39
40
|
* @param opts.credential - The stored credential record to verify against.
|
|
40
41
|
* @param opts.credential.id - The credential ID (base64url).
|
|
41
42
|
* @param opts.credential.publicKey - The COSE-encoded public key bytes
|
|
@@ -51,7 +52,7 @@ export declare function verifyAuthenticationResponse(opts: {
|
|
|
51
52
|
response: PasskeyAuthenticationResponse;
|
|
52
53
|
expectedChallenge: string;
|
|
53
54
|
expectedOrigin: string | string[];
|
|
54
|
-
|
|
55
|
+
expectedRPIDs: string[];
|
|
55
56
|
credential: {
|
|
56
57
|
id: string;
|
|
57
58
|
publicKey: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-authentication-response.d.cts","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAiB;AAM7D,OAAO,KAAK,EAAE,6BAA6B,EAAE,oBAAgB;AAG7D,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,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,
|
|
1
|
+
{"version":3,"file":"verify-authentication-response.d.cts","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAiB;AAM7D,OAAO,KAAK,EAAE,6BAA6B,EAAE,oBAAgB;AAG7D,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"}
|
|
@@ -10,6 +10,7 @@ export type VerifiedAuthenticationResponse = {
|
|
|
10
10
|
newCounter: number;
|
|
11
11
|
userVerified: boolean;
|
|
12
12
|
origin: string;
|
|
13
|
+
/** Matched RP ID, or `""` when `expectedRPIDs` is empty (RP ID hash check skipped). */
|
|
13
14
|
rpID: string;
|
|
14
15
|
};
|
|
15
16
|
};
|
|
@@ -35,7 +36,7 @@ export type VerifiedAuthenticationResponse = {
|
|
|
35
36
|
* @param opts.expectedChallenge - The base64url challenge that was issued
|
|
36
37
|
* for this ceremony.
|
|
37
38
|
* @param opts.expectedOrigin - One or more acceptable origins.
|
|
38
|
-
* @param opts.
|
|
39
|
+
* @param opts.expectedRPIDs - Relying Party ID strings to match against `rpIdHash`.
|
|
39
40
|
* @param opts.credential - The stored credential record to verify against.
|
|
40
41
|
* @param opts.credential.id - The credential ID (base64url).
|
|
41
42
|
* @param opts.credential.publicKey - The COSE-encoded public key bytes
|
|
@@ -51,7 +52,7 @@ export declare function verifyAuthenticationResponse(opts: {
|
|
|
51
52
|
response: PasskeyAuthenticationResponse;
|
|
52
53
|
expectedChallenge: string;
|
|
53
54
|
expectedOrigin: string | string[];
|
|
54
|
-
|
|
55
|
+
expectedRPIDs: string[];
|
|
55
56
|
credential: {
|
|
56
57
|
id: string;
|
|
57
58
|
publicKey: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-authentication-response.d.mts","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAiB;AAM7D,OAAO,KAAK,EAAE,6BAA6B,EAAE,oBAAgB;AAG7D,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,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,
|
|
1
|
+
{"version":3,"file":"verify-authentication-response.d.mts","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,qBAAiB;AAM7D,OAAO,KAAK,EAAE,6BAA6B,EAAE,oBAAgB;AAG7D,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"}
|