@metamask/passkey-controller 3.0.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.
Files changed (209) hide show
  1. package/CHANGELOG.md +27 -1
  2. package/dist/{PasskeyController-method-action-types.d.mts → PasskeyController-method-action-types.d.ts} +2 -2
  3. package/dist/PasskeyController-method-action-types.d.ts.map +1 -0
  4. package/dist/{PasskeyController-method-action-types.mjs → PasskeyController-method-action-types.js} +1 -1
  5. package/dist/PasskeyController-method-action-types.js.map +1 -0
  6. package/dist/{PasskeyController.d.mts → PasskeyController.d.ts} +6 -6
  7. package/dist/PasskeyController.d.ts.map +1 -0
  8. package/dist/PasskeyController.js +680 -0
  9. package/dist/PasskeyController.js.map +1 -0
  10. package/dist/{ceremony-manager.d.cts → ceremony-manager.d.ts} +2 -2
  11. package/dist/ceremony-manager.d.ts.map +1 -0
  12. package/dist/ceremony-manager.js +135 -0
  13. package/dist/ceremony-manager.js.map +1 -0
  14. package/dist/{constants.d.mts → constants.d.ts} +12 -12
  15. package/dist/constants.d.ts.map +1 -0
  16. package/dist/{constants.mjs → constants.js} +1 -1
  17. package/dist/constants.js.map +1 -0
  18. package/dist/{errors.d.mts → errors.d.ts} +2 -2
  19. package/dist/errors.d.ts.map +1 -0
  20. package/dist/{errors.mjs → errors.js} +4 -1
  21. package/dist/errors.js.map +1 -0
  22. package/dist/{index.d.cts → index.d.ts} +8 -7
  23. package/dist/index.d.ts.map +1 -0
  24. package/dist/index.js +5 -0
  25. package/dist/index.js.map +1 -0
  26. package/dist/{key-derivation.d.cts → key-derivation.d.ts} +3 -3
  27. package/dist/key-derivation.d.ts.map +1 -0
  28. package/dist/{key-derivation.mjs → key-derivation.js} +5 -5
  29. package/dist/key-derivation.js.map +1 -0
  30. package/dist/logger.d.ts +4 -0
  31. package/dist/logger.d.ts.map +1 -0
  32. package/dist/logger.js +6 -0
  33. package/dist/logger.js.map +1 -0
  34. package/dist/{types.d.mts → types.d.ts} +6 -6
  35. package/dist/types.d.ts.map +1 -0
  36. package/dist/types.js +2 -0
  37. package/dist/types.js.map +1 -0
  38. package/dist/utils/{crypto.d.mts → crypto.d.ts} +1 -1
  39. package/dist/utils/crypto.d.ts.map +1 -0
  40. package/dist/utils/{crypto.mjs → crypto.js} +7 -7
  41. package/dist/utils/crypto.js.map +1 -0
  42. package/dist/utils/{encoding.d.cts → encoding.d.ts} +1 -1
  43. package/dist/utils/encoding.d.ts.map +1 -0
  44. package/dist/utils/{encoding.mjs → encoding.js} +2 -2
  45. package/dist/utils/encoding.js.map +1 -0
  46. package/dist/webauthn/{constants.d.mts → constants.d.ts} +1 -1
  47. package/dist/webauthn/constants.d.ts.map +1 -0
  48. package/dist/webauthn/{constants.mjs → constants.js} +1 -1
  49. package/dist/webauthn/constants.js.map +1 -0
  50. package/dist/webauthn/{decode-attestation-object.d.mts → decode-attestation-object.d.ts} +2 -2
  51. package/dist/webauthn/decode-attestation-object.d.ts.map +1 -0
  52. package/dist/webauthn/{decode-attestation-object.mjs → decode-attestation-object.js} +2 -2
  53. package/dist/webauthn/decode-attestation-object.js.map +1 -0
  54. package/dist/webauthn/{decode-client-data-json.d.cts → decode-client-data-json.d.ts} +2 -2
  55. package/dist/webauthn/decode-client-data-json.d.ts.map +1 -0
  56. package/dist/webauthn/{decode-client-data-json.mjs → decode-client-data-json.js} +2 -2
  57. package/dist/webauthn/decode-client-data-json.js.map +1 -0
  58. package/dist/webauthn/{match-expected-rp-id.d.cts → match-expected-rp-id.d.ts} +1 -1
  59. package/dist/webauthn/match-expected-rp-id.d.ts.map +1 -0
  60. package/dist/webauthn/{match-expected-rp-id.mjs → match-expected-rp-id.js} +4 -4
  61. package/dist/webauthn/match-expected-rp-id.js.map +1 -0
  62. package/dist/webauthn/{parse-authenticator-data.d.cts → parse-authenticator-data.d.ts} +2 -2
  63. package/dist/webauthn/parse-authenticator-data.d.ts.map +1 -0
  64. package/dist/webauthn/{parse-authenticator-data.mjs → parse-authenticator-data.js} +2 -2
  65. package/dist/webauthn/parse-authenticator-data.js.map +1 -0
  66. package/dist/webauthn/{types.d.mts → types.d.ts} +2 -2
  67. package/dist/webauthn/types.d.ts.map +1 -0
  68. package/dist/webauthn/types.js +2 -0
  69. package/dist/webauthn/types.js.map +1 -0
  70. package/dist/webauthn/{verify-authentication-response.d.cts → verify-authentication-response.d.ts} +3 -3
  71. package/dist/webauthn/verify-authentication-response.d.ts.map +1 -0
  72. package/dist/webauthn/{verify-authentication-response.mjs → verify-authentication-response.js} +9 -9
  73. package/dist/webauthn/verify-authentication-response.js.map +1 -0
  74. package/dist/webauthn/{verify-registration-response.d.mts → verify-registration-response.d.ts} +24 -3
  75. package/dist/webauthn/verify-registration-response.d.ts.map +1 -0
  76. package/dist/webauthn/{verify-registration-response.mjs → verify-registration-response.js} +54 -20
  77. package/dist/webauthn/verify-registration-response.js.map +1 -0
  78. package/dist/webauthn/{verify-signature.d.cts → verify-signature.d.ts} +1 -1
  79. package/dist/webauthn/verify-signature.d.ts.map +1 -0
  80. package/dist/webauthn/{verify-signature.mjs → verify-signature.js} +7 -7
  81. package/dist/webauthn/verify-signature.js.map +1 -0
  82. package/package.json +21 -26
  83. package/dist/PasskeyController-method-action-types.cjs +0 -7
  84. package/dist/PasskeyController-method-action-types.cjs.map +0 -1
  85. package/dist/PasskeyController-method-action-types.d.cts +0 -204
  86. package/dist/PasskeyController-method-action-types.d.cts.map +0 -1
  87. package/dist/PasskeyController-method-action-types.d.mts.map +0 -1
  88. package/dist/PasskeyController-method-action-types.mjs.map +0 -1
  89. package/dist/PasskeyController.cjs +0 -685
  90. package/dist/PasskeyController.cjs.map +0 -1
  91. package/dist/PasskeyController.d.cts +0 -208
  92. package/dist/PasskeyController.d.cts.map +0 -1
  93. package/dist/PasskeyController.d.mts.map +0 -1
  94. package/dist/PasskeyController.mjs +0 -680
  95. package/dist/PasskeyController.mjs.map +0 -1
  96. package/dist/ceremony-manager.cjs +0 -135
  97. package/dist/ceremony-manager.cjs.map +0 -1
  98. package/dist/ceremony-manager.d.cts.map +0 -1
  99. package/dist/ceremony-manager.d.mts +0 -72
  100. package/dist/ceremony-manager.d.mts.map +0 -1
  101. package/dist/ceremony-manager.mjs +0 -131
  102. package/dist/ceremony-manager.mjs.map +0 -1
  103. package/dist/constants.cjs +0 -39
  104. package/dist/constants.cjs.map +0 -1
  105. package/dist/constants.d.cts +0 -36
  106. package/dist/constants.d.cts.map +0 -1
  107. package/dist/constants.d.mts.map +0 -1
  108. package/dist/constants.mjs.map +0 -1
  109. package/dist/errors.cjs +0 -57
  110. package/dist/errors.cjs.map +0 -1
  111. package/dist/errors.d.cts +0 -34
  112. package/dist/errors.d.cts.map +0 -1
  113. package/dist/errors.d.mts.map +0 -1
  114. package/dist/errors.mjs.map +0 -1
  115. package/dist/index.cjs +0 -13
  116. package/dist/index.cjs.map +0 -1
  117. package/dist/index.d.cts.map +0 -1
  118. package/dist/index.d.mts +0 -7
  119. package/dist/index.d.mts.map +0 -1
  120. package/dist/index.mjs +0 -4
  121. package/dist/index.mjs.map +0 -1
  122. package/dist/key-derivation.cjs +0 -44
  123. package/dist/key-derivation.cjs.map +0 -1
  124. package/dist/key-derivation.d.cts.map +0 -1
  125. package/dist/key-derivation.d.mts +0 -20
  126. package/dist/key-derivation.d.mts.map +0 -1
  127. package/dist/key-derivation.mjs.map +0 -1
  128. package/dist/logger.cjs +0 -9
  129. package/dist/logger.cjs.map +0 -1
  130. package/dist/logger.d.cts +0 -5
  131. package/dist/logger.d.cts.map +0 -1
  132. package/dist/logger.d.mts +0 -5
  133. package/dist/logger.d.mts.map +0 -1
  134. package/dist/logger.mjs +0 -6
  135. package/dist/logger.mjs.map +0 -1
  136. package/dist/types.cjs +0 -4
  137. package/dist/types.cjs.map +0 -1
  138. package/dist/types.d.cts +0 -132
  139. package/dist/types.d.cts.map +0 -1
  140. package/dist/types.d.mts.map +0 -1
  141. package/dist/types.mjs +0 -2
  142. package/dist/types.mjs.map +0 -1
  143. package/dist/utils/crypto.cjs +0 -66
  144. package/dist/utils/crypto.cjs.map +0 -1
  145. package/dist/utils/crypto.d.cts +0 -37
  146. package/dist/utils/crypto.d.cts.map +0 -1
  147. package/dist/utils/crypto.d.mts.map +0 -1
  148. package/dist/utils/crypto.mjs.map +0 -1
  149. package/dist/utils/encoding.cjs +0 -42
  150. package/dist/utils/encoding.cjs.map +0 -1
  151. package/dist/utils/encoding.d.cts.map +0 -1
  152. package/dist/utils/encoding.d.mts +0 -22
  153. package/dist/utils/encoding.d.mts.map +0 -1
  154. package/dist/utils/encoding.mjs.map +0 -1
  155. package/dist/webauthn/constants.cjs +0 -74
  156. package/dist/webauthn/constants.cjs.map +0 -1
  157. package/dist/webauthn/constants.d.cts +0 -68
  158. package/dist/webauthn/constants.d.cts.map +0 -1
  159. package/dist/webauthn/constants.d.mts.map +0 -1
  160. package/dist/webauthn/constants.mjs.map +0 -1
  161. package/dist/webauthn/decode-attestation-object.cjs +0 -18
  162. package/dist/webauthn/decode-attestation-object.cjs.map +0 -1
  163. package/dist/webauthn/decode-attestation-object.d.cts +0 -10
  164. package/dist/webauthn/decode-attestation-object.d.cts.map +0 -1
  165. package/dist/webauthn/decode-attestation-object.d.mts.map +0 -1
  166. package/dist/webauthn/decode-attestation-object.mjs.map +0 -1
  167. package/dist/webauthn/decode-client-data-json.cjs +0 -17
  168. package/dist/webauthn/decode-client-data-json.cjs.map +0 -1
  169. package/dist/webauthn/decode-client-data-json.d.cts.map +0 -1
  170. package/dist/webauthn/decode-client-data-json.d.mts +0 -9
  171. package/dist/webauthn/decode-client-data-json.d.mts.map +0 -1
  172. package/dist/webauthn/decode-client-data-json.mjs.map +0 -1
  173. package/dist/webauthn/match-expected-rp-id.cjs +0 -26
  174. package/dist/webauthn/match-expected-rp-id.cjs.map +0 -1
  175. package/dist/webauthn/match-expected-rp-id.d.cts.map +0 -1
  176. package/dist/webauthn/match-expected-rp-id.d.mts +0 -11
  177. package/dist/webauthn/match-expected-rp-id.d.mts.map +0 -1
  178. package/dist/webauthn/match-expected-rp-id.mjs.map +0 -1
  179. package/dist/webauthn/parse-authenticator-data.cjs +0 -69
  180. package/dist/webauthn/parse-authenticator-data.cjs.map +0 -1
  181. package/dist/webauthn/parse-authenticator-data.d.cts.map +0 -1
  182. package/dist/webauthn/parse-authenticator-data.d.mts +0 -10
  183. package/dist/webauthn/parse-authenticator-data.d.mts.map +0 -1
  184. package/dist/webauthn/parse-authenticator-data.mjs.map +0 -1
  185. package/dist/webauthn/types.cjs +0 -3
  186. package/dist/webauthn/types.cjs.map +0 -1
  187. package/dist/webauthn/types.d.cts +0 -113
  188. package/dist/webauthn/types.d.cts.map +0 -1
  189. package/dist/webauthn/types.d.mts.map +0 -1
  190. package/dist/webauthn/types.mjs +0 -2
  191. package/dist/webauthn/types.mjs.map +0 -1
  192. package/dist/webauthn/verify-authentication-response.cjs +0 -133
  193. package/dist/webauthn/verify-authentication-response.cjs.map +0 -1
  194. package/dist/webauthn/verify-authentication-response.d.cts.map +0 -1
  195. package/dist/webauthn/verify-authentication-response.d.mts +0 -64
  196. package/dist/webauthn/verify-authentication-response.d.mts.map +0 -1
  197. package/dist/webauthn/verify-authentication-response.mjs.map +0 -1
  198. package/dist/webauthn/verify-registration-response.cjs +0 -207
  199. package/dist/webauthn/verify-registration-response.cjs.map +0 -1
  200. package/dist/webauthn/verify-registration-response.d.cts +0 -60
  201. package/dist/webauthn/verify-registration-response.d.cts.map +0 -1
  202. package/dist/webauthn/verify-registration-response.d.mts.map +0 -1
  203. package/dist/webauthn/verify-registration-response.mjs.map +0 -1
  204. package/dist/webauthn/verify-signature.cjs +0 -176
  205. package/dist/webauthn/verify-signature.cjs.map +0 -1
  206. package/dist/webauthn/verify-signature.d.cts.map +0 -1
  207. package/dist/webauthn/verify-signature.d.mts +0 -21
  208. package/dist/webauthn/verify-signature.d.mts.map +0 -1
  209. package/dist/webauthn/verify-signature.mjs.map +0 -1
@@ -1,113 +0,0 @@
1
- import type { AuthenticatorTransportFuture, Base64URLString as Base64URL } from "../types.cjs";
2
- export type PublicKeyCredentialDescriptorJSON = {
3
- id: Base64URL;
4
- type: 'public-key';
5
- transports?: AuthenticatorTransportFuture[];
6
- };
7
- export type PublicKeyCredentialHint = 'hybrid' | 'security-key' | 'client-device';
8
- export type PasskeyRegistrationOptions = {
9
- rp: {
10
- name: string;
11
- id?: string;
12
- };
13
- user: {
14
- id: Base64URL;
15
- name: string;
16
- displayName: string;
17
- };
18
- challenge: Base64URL;
19
- pubKeyCredParams: {
20
- alg: number;
21
- type: 'public-key';
22
- }[];
23
- timeout?: number;
24
- excludeCredentials?: PublicKeyCredentialDescriptorJSON[];
25
- authenticatorSelection?: {
26
- authenticatorAttachment?: 'cross-platform' | 'platform';
27
- residentKey?: 'discouraged' | 'preferred' | 'required';
28
- requireResidentKey?: boolean;
29
- userVerification?: 'discouraged' | 'preferred' | 'required';
30
- };
31
- hints?: PublicKeyCredentialHint[];
32
- attestation?: 'direct' | 'enterprise' | 'indirect' | 'none';
33
- extensions?: Record<string, unknown>;
34
- };
35
- export type PasskeyRegistrationResponse = {
36
- id: Base64URL;
37
- rawId: Base64URL;
38
- type: 'public-key';
39
- response: {
40
- clientDataJSON: Base64URL;
41
- attestationObject: Base64URL;
42
- transports?: string[];
43
- publicKeyAlgorithm?: number;
44
- publicKey?: Base64URL;
45
- authenticatorData?: Base64URL;
46
- };
47
- authenticatorAttachment?: 'cross-platform' | 'platform';
48
- clientExtensionResults: Record<string, unknown>;
49
- };
50
- export type PasskeyAuthenticationOptions = {
51
- challenge: Base64URL;
52
- timeout?: number;
53
- rpId?: string;
54
- allowCredentials?: PublicKeyCredentialDescriptorJSON[];
55
- userVerification?: 'discouraged' | 'preferred' | 'required';
56
- hints?: PublicKeyCredentialHint[];
57
- extensions?: Record<string, unknown>;
58
- };
59
- export type PasskeyAuthenticationResponse = {
60
- id: Base64URL;
61
- rawId: Base64URL;
62
- type: 'public-key';
63
- response: {
64
- clientDataJSON: Base64URL;
65
- authenticatorData: Base64URL;
66
- signature: Base64URL;
67
- userHandle?: Base64URL;
68
- };
69
- authenticatorAttachment?: 'cross-platform' | 'platform';
70
- clientExtensionResults: Record<string, unknown>;
71
- };
72
- export type ClientDataJSON = {
73
- type: string;
74
- challenge: string;
75
- origin: string;
76
- crossOrigin?: boolean;
77
- tokenBinding?: {
78
- id?: string;
79
- status: 'present' | 'supported' | 'not-supported';
80
- };
81
- };
82
- export type AttestationFormat = 'fido-u2f' | 'packed' | 'android-safetynet' | 'android-key' | 'tpm' | 'apple' | 'none';
83
- export type AttestationObject = {
84
- get(key: 'fmt'): AttestationFormat;
85
- get(key: 'attStmt'): AttestationStatement;
86
- get(key: 'authData'): Uint8Array;
87
- };
88
- export type AttestationStatement = {
89
- get(key: 'sig'): Uint8Array | undefined;
90
- get(key: 'x5c'): Uint8Array[] | undefined;
91
- get(key: 'alg'): number | undefined;
92
- readonly size: number;
93
- };
94
- export type AuthenticatorDataFlags = {
95
- up: boolean;
96
- uv: boolean;
97
- be: boolean;
98
- bs: boolean;
99
- at: boolean;
100
- ed: boolean;
101
- flagsByte: number;
102
- };
103
- export type ParsedAuthenticatorData = {
104
- rpIdHash: Uint8Array;
105
- flags: AuthenticatorDataFlags;
106
- counter: number;
107
- aaguid?: Uint8Array;
108
- credentialID?: Uint8Array;
109
- credentialPublicKey?: Uint8Array;
110
- extensionsData?: Map<string, unknown>;
111
- extensionsDataBuffer?: Uint8Array;
112
- };
113
- //# sourceMappingURL=types.d.cts.map
@@ -1 +0,0 @@
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,MA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E,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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.mjs.map
@@ -1 +0,0 @@
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"]}
@@ -1,133 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyAuthenticationResponse = void 0;
4
- const tiny_cbor_1 = require("@levischuck/tiny-cbor");
5
- const utils_1 = require("@metamask/utils");
6
- const sha2_1 = require("@noble/hashes/sha2");
7
- const encoding_1 = require("../utils/encoding.cjs");
8
- const decode_client_data_json_1 = require("./decode-client-data-json.cjs");
9
- const match_expected_rp_id_1 = require("./match-expected-rp-id.cjs");
10
- const parse_authenticator_data_1 = require("./parse-authenticator-data.cjs");
11
- const verify_signature_1 = require("./verify-signature.cjs");
12
- /**
13
- * Verifies a WebAuthn authentication (assertion) response per
14
- * W3C WebAuthn Level 3 §7.2.
15
- *
16
- * Performs the following checks in order:
17
- * 1. Credential ID presence, base64url consistency, and type.
18
- * 2. `clientDataJSON` -- type is `"webauthn.get"`, challenge and origin
19
- * match.
20
- * 3. `authenticatorData` -- RP ID hash matches, user-presence flag is
21
- * set, and optional user-verification flag is checked.
22
- * 4. Signature verification -- `signature` is verified over
23
- * `authData || SHA-256(clientDataJSON)` using the stored credential
24
- * public key (COSE-encoded).
25
- * 5. Counter monotonicity -- if either the stored or returned counter
26
- * is non-zero, the new counter must exceed the stored value.
27
- *
28
- * @param opts - Verification options.
29
- * @param opts.response - The `PublicKeyCredential` result from
30
- * `navigator.credentials.get()`, serialized as JSON.
31
- * @param opts.expectedChallenge - The base64url challenge that was issued
32
- * for this ceremony.
33
- * @param opts.expectedOrigin - One or more acceptable origins.
34
- * @param opts.expectedRPIDs - Relying Party ID strings to match against `rpIdHash`.
35
- * @param opts.credential - The stored credential record to verify against.
36
- * @param opts.credential.id - The credential ID (base64url).
37
- * @param opts.credential.publicKey - The COSE-encoded public key bytes
38
- * persisted during registration.
39
- * @param opts.credential.counter - The last known signature counter value.
40
- * @param opts.credential.transports - Optional authenticator transports.
41
- * @param opts.requireUserVerification - When `true`, verification fails
42
- * if the UV flag is not set. Defaults to `false`.
43
- * @returns Verification result containing `verified` status and parsed
44
- * authentication info (new counter, origin, RP ID).
45
- */
46
- async function verifyAuthenticationResponse(opts) {
47
- const { response, expectedChallenge, expectedOrigin, expectedRPIDs, credential, requireUserVerification = false, } = opts;
48
- const { id, rawId, type: credentialType, response: assertionResponse, } = response;
49
- // Ensure credential specified an ID
50
- if (!id) {
51
- throw new Error('Missing credential ID');
52
- }
53
- // Ensure ID is base64url-encoded
54
- if (id !== rawId) {
55
- throw new Error('Credential ID was not base64url-encoded');
56
- }
57
- // Make sure credential type is public-key
58
- if (credentialType !== 'public-key') {
59
- throw new Error(`Unexpected credential type ${String(credentialType)}, expected "public-key"`);
60
- }
61
- if (typeof assertionResponse?.clientDataJSON !== 'string') {
62
- throw new Error('Credential response clientDataJSON was not a string');
63
- }
64
- const clientDataJSON = (0, decode_client_data_json_1.decodeClientDataJSON)(assertionResponse.clientDataJSON);
65
- const { type, challenge, origin, tokenBinding } = clientDataJSON;
66
- // Make sure we're handling an authentication
67
- if (type !== 'webauthn.get') {
68
- throw new Error(`Unexpected authentication response type: ${type}`);
69
- }
70
- // Ensure the device provided the challenge we gave it
71
- if (challenge !== expectedChallenge) {
72
- throw new Error(`Unexpected authentication response challenge "${challenge}", expected "${expectedChallenge}"`);
73
- }
74
- // Check that the origin is our site
75
- const expectedOrigins = Array.isArray(expectedOrigin)
76
- ? expectedOrigin
77
- : [expectedOrigin];
78
- if (!expectedOrigins.includes(origin)) {
79
- throw new Error(`Unexpected authentication response origin "${origin}", expected one of: ${expectedOrigins.join(', ')}`);
80
- }
81
- if (assertionResponse.userHandle &&
82
- typeof assertionResponse.userHandle !== 'string') {
83
- throw new Error('Credential response userHandle was not a string');
84
- }
85
- if (tokenBinding) {
86
- if (typeof tokenBinding !== 'object') {
87
- throw new Error('ClientDataJSON tokenBinding was not an object');
88
- }
89
- if (!['present', 'supported', 'not-supported'].includes(tokenBinding.status)) {
90
- throw new Error(`Unexpected tokenBinding status ${tokenBinding.status}`);
91
- }
92
- }
93
- const authDataBuffer = (0, encoding_1.base64URLToBytes)(assertionResponse.authenticatorData);
94
- const parsedAuthData = (0, parse_authenticator_data_1.parseAuthenticatorData)(authDataBuffer);
95
- const { rpIdHash, flags, counter } = parsedAuthData;
96
- const matchedRPID = expectedRPIDs.length > 0 ? (0, match_expected_rp_id_1.matchExpectedRPID)(rpIdHash, expectedRPIDs) : '';
97
- // WebAuthn only requires the user presence flag be true
98
- if (!flags.up) {
99
- throw new Error('User not present during authentication');
100
- }
101
- // Enforce user verification if required
102
- if (requireUserVerification && !flags.uv) {
103
- throw new Error('User verification required, but user could not be verified');
104
- }
105
- const clientDataHash = (0, sha2_1.sha256)((0, encoding_1.base64URLToBytes)(assertionResponse.clientDataJSON));
106
- const signatureBase = (0, utils_1.concatBytes)([authDataBuffer, clientDataHash]);
107
- const signature = (0, encoding_1.base64URLToBytes)(assertionResponse.signature);
108
- const cosePublicKey = (0, tiny_cbor_1.decodePartialCBOR)(new Uint8Array(credential.publicKey), 0)[0];
109
- const verified = await (0, verify_signature_1.verifySignature)({
110
- cosePublicKey,
111
- signature,
112
- data: signatureBase,
113
- });
114
- if (!verified) {
115
- return { verified: false };
116
- }
117
- if ((counter > 0 || credential.counter > 0) &&
118
- counter <= credential.counter) {
119
- throw new Error(`Response counter value ${counter} must be greater than stored counter ${credential.counter}`);
120
- }
121
- return {
122
- verified: true,
123
- authenticationInfo: {
124
- credentialId: credential.id,
125
- newCounter: counter,
126
- userVerified: flags.uv,
127
- origin: clientDataJSON.origin,
128
- rpID: matchedRPID,
129
- },
130
- };
131
- }
132
- exports.verifyAuthenticationResponse = verifyAuthenticationResponse;
133
- //# sourceMappingURL=verify-authentication-response.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"verify-authentication-response.cjs","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings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,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"]}
@@ -1 +0,0 @@
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"}
@@ -1,64 +0,0 @@
1
- import type { AuthenticatorTransportFuture } from "../types.mjs";
2
- import type { PasskeyAuthenticationResponse } from "./types.mjs";
3
- export type VerifiedAuthenticationResponse = {
4
- verified: false;
5
- authenticationInfo?: never;
6
- } | {
7
- verified: true;
8
- authenticationInfo: {
9
- credentialId: string;
10
- newCounter: number;
11
- userVerified: boolean;
12
- origin: string;
13
- /** Matched RP ID, or `""` when `expectedRPIDs` is empty (RP ID hash check skipped). */
14
- rpID: string;
15
- };
16
- };
17
- /**
18
- * Verifies a WebAuthn authentication (assertion) response per
19
- * W3C WebAuthn Level 3 §7.2.
20
- *
21
- * Performs the following checks in order:
22
- * 1. Credential ID presence, base64url consistency, and type.
23
- * 2. `clientDataJSON` -- type is `"webauthn.get"`, challenge and origin
24
- * match.
25
- * 3. `authenticatorData` -- RP ID hash matches, user-presence flag is
26
- * set, and optional user-verification flag is checked.
27
- * 4. Signature verification -- `signature` is verified over
28
- * `authData || SHA-256(clientDataJSON)` using the stored credential
29
- * public key (COSE-encoded).
30
- * 5. Counter monotonicity -- if either the stored or returned counter
31
- * is non-zero, the new counter must exceed the stored value.
32
- *
33
- * @param opts - Verification options.
34
- * @param opts.response - The `PublicKeyCredential` result from
35
- * `navigator.credentials.get()`, serialized as JSON.
36
- * @param opts.expectedChallenge - The base64url challenge that was issued
37
- * for this ceremony.
38
- * @param opts.expectedOrigin - One or more acceptable origins.
39
- * @param opts.expectedRPIDs - Relying Party ID strings to match against `rpIdHash`.
40
- * @param opts.credential - The stored credential record to verify against.
41
- * @param opts.credential.id - The credential ID (base64url).
42
- * @param opts.credential.publicKey - The COSE-encoded public key bytes
43
- * persisted during registration.
44
- * @param opts.credential.counter - The last known signature counter value.
45
- * @param opts.credential.transports - Optional authenticator transports.
46
- * @param opts.requireUserVerification - When `true`, verification fails
47
- * if the UV flag is not set. Defaults to `false`.
48
- * @returns Verification result containing `verified` status and parsed
49
- * authentication info (new counter, origin, RP ID).
50
- */
51
- export declare function verifyAuthenticationResponse(opts: {
52
- response: PasskeyAuthenticationResponse;
53
- expectedChallenge: string;
54
- expectedOrigin: string | string[];
55
- expectedRPIDs: string[];
56
- credential: {
57
- id: string;
58
- publicKey: Uint8Array;
59
- counter: number;
60
- transports?: AuthenticatorTransportFuture[];
61
- };
62
- requireUserVerification?: boolean;
63
- }): Promise<VerifiedAuthenticationResponse>;
64
- //# sourceMappingURL=verify-authentication-response.d.mts.map
@@ -1 +0,0 @@
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"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"verify-authentication-response.mjs","sourceRoot":"","sources":["../../src/webauthn/verify-authentication-response.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,8BAA8B;AAC1D,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAC9C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAG5C,OAAO,EAAE,gBAAgB,EAAE,8BAA0B;AACrD,OAAO,EAAE,oBAAoB,EAAE,sCAAkC;AACjE,OAAO,EAAE,iBAAiB,EAAE,mCAA+B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,uCAAmC;AAGpE,OAAO,EAAE,eAAe,EAAE,+BAA2B;AAgBrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,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,q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AC7B,CAAC;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","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"]}
@@ -1,207 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.verifyRegistrationResponse = void 0;
4
- const tiny_cbor_1 = require("@levischuck/tiny-cbor");
5
- const utils_1 = require("@metamask/utils");
6
- const sha2_1 = require("@noble/hashes/sha2");
7
- const encoding_1 = require("../utils/encoding.cjs");
8
- const constants_1 = require("./constants.cjs");
9
- const decode_attestation_object_1 = require("./decode-attestation-object.cjs");
10
- const decode_client_data_json_1 = require("./decode-client-data-json.cjs");
11
- const match_expected_rp_id_1 = require("./match-expected-rp-id.cjs");
12
- const parse_authenticator_data_1 = require("./parse-authenticator-data.cjs");
13
- const verify_signature_1 = require("./verify-signature.cjs");
14
- /**
15
- * Verifies a WebAuthn registration (attestation) response per
16
- * W3C WebAuthn Level 3 §7.1.
17
- *
18
- * Performs the following checks in order:
19
- * 1. Credential ID presence and base64url consistency (`id === rawId`), and
20
- * that `id` matches the credential id inside parsed authenticator data.
21
- * 2. Credential type is `"public-key"`.
22
- * 3. `clientDataJSON` -- type is `"webauthn.create"`, challenge and origin
23
- * match the expected values.
24
- * 4. Attestation object -- CBOR-decodes and parses `authData` to verify
25
- * the RP ID hash, user-presence flag, optional user-verification flag,
26
- * and the attested credential public key algorithm.
27
- * 5. Attestation statement -- supports `"none"` (no signature) and
28
- * `"packed"` self-attestation (signature verified against the
29
- * credential's own public key).
30
- *
31
- * @param opts - Verification options.
32
- * @param opts.response - The `PublicKeyCredential` result from
33
- * `navigator.credentials.create()`, serialized as JSON.
34
- * @param opts.expectedChallenge - The base64url challenge that was passed
35
- * to the authenticator (must match `clientDataJSON.challenge`).
36
- * @param opts.expectedOrigin - One or more acceptable values for
37
- * `clientDataJSON.origin` (WebAuthn). Extension and HTTPS contexts differ by scheme.
38
- * @param opts.expectedRPIDs - Relying Party ID strings. The authenticator's
39
- * `rpIdHash` must equal `SHA-256(rpID)` for at least one entry.
40
- * @param opts.requireUserVerification - When `true`, verification fails
41
- * if the UV flag is not set. Defaults to `false`.
42
- * @param opts.supportedAlgorithmIDs - COSE algorithm identifiers accepted
43
- * for the credential public key. Defaults to EdDSA, ES256, and RS256.
44
- * @returns On success, `{ verified: true, registrationInfo }` with the
45
- * parsed credential ID, public key, counter, AAGUID, and transport
46
- * hints. On failure, `{ verified: false }`.
47
- */
48
- async function verifyRegistrationResponse(opts) {
49
- const { response, expectedChallenge, expectedOrigin, expectedRPIDs, requireUserVerification = false, supportedAlgorithmIDs = [constants_1.COSEALG.EdDSA, constants_1.COSEALG.ES256, constants_1.COSEALG.RS256], } = opts;
50
- const { id, rawId, type: credentialType, response: attestationResponse, } = response;
51
- // Ensure credential specified an ID
52
- if (!id) {
53
- throw new Error('Missing credential ID');
54
- }
55
- // Ensure ID is base64url-encoded
56
- if (id !== rawId) {
57
- throw new Error('Credential ID was not base64url-encoded');
58
- }
59
- // Make sure credential type is public-key
60
- if (credentialType !== 'public-key') {
61
- throw new Error(`Unexpected credential type ${String(credentialType)}, expected "public-key"`);
62
- }
63
- const clientDataJSON = (0, decode_client_data_json_1.decodeClientDataJSON)(attestationResponse.clientDataJSON);
64
- const { type, challenge, origin, tokenBinding } = clientDataJSON;
65
- // Make sure we're handling an registration
66
- if (type !== 'webauthn.create') {
67
- throw new Error(`Unexpected registration response type: ${type}`);
68
- }
69
- // Ensure the device provided the challenge we gave it
70
- if (challenge !== expectedChallenge) {
71
- throw new Error(`Unexpected registration response challenge "${challenge}", expected "${expectedChallenge}"`);
72
- }
73
- // Check that the origin is our site
74
- const expectedOrigins = Array.isArray(expectedOrigin)
75
- ? expectedOrigin
76
- : [expectedOrigin];
77
- if (!expectedOrigins.includes(origin)) {
78
- throw new Error(`Unexpected registration response origin "${origin}", expected one of: ${expectedOrigins.join(', ')}`);
79
- }
80
- if (tokenBinding) {
81
- if (typeof tokenBinding !== 'object') {
82
- throw new Error('ClientDataJSON tokenBinding was not an object');
83
- }
84
- if (!['present', 'supported', 'not-supported'].includes(tokenBinding.status)) {
85
- throw new Error(`Unexpected tokenBinding.status value of "${tokenBinding.status}"`);
86
- }
87
- }
88
- const attestationObjectBytes = (0, encoding_1.base64URLToBytes)(attestationResponse.attestationObject);
89
- const decodedAttObj = (0, decode_attestation_object_1.decodeAttestationObject)(attestationObjectBytes);
90
- const fmt = decodedAttObj.get('fmt');
91
- const authData = decodedAttObj.get('authData');
92
- const attStmt = decodedAttObj.get('attStmt');
93
- const parsedAuthData = (0, parse_authenticator_data_1.parseAuthenticatorData)(authData);
94
- const { rpIdHash, flags, counter, credentialID, credentialPublicKey, aaguid, } = parsedAuthData;
95
- if (expectedRPIDs.length > 0) {
96
- (0, match_expected_rp_id_1.matchExpectedRPID)(rpIdHash, expectedRPIDs);
97
- }
98
- // Make sure someone was physically present
99
- if (!flags.up) {
100
- throw new Error('User presence was required, but user was not present');
101
- }
102
- // Enforce user verification if specified
103
- if (requireUserVerification && !flags.uv) {
104
- throw new Error('User verification was required, but user could not be verified');
105
- }
106
- if (!credentialID) {
107
- throw new Error('No credential ID was provided by authenticator');
108
- }
109
- const attestedCredentialId = (0, encoding_1.bytesToBase64URL)(credentialID);
110
- if (id !== attestedCredentialId) {
111
- throw new Error('Credential id does not match the credential id in authenticator data');
112
- }
113
- if (!credentialPublicKey) {
114
- throw new Error('No public key was provided by authenticator');
115
- }
116
- if (!aaguid) {
117
- throw new Error('No AAGUID was present during registration');
118
- }
119
- const decodedPublicKey = (0, tiny_cbor_1.decodePartialCBOR)(new Uint8Array(credentialPublicKey), 0)[0];
120
- const alg = decodedPublicKey.get(constants_1.COSEKEYS.Alg);
121
- if (typeof alg !== 'number') {
122
- throw new Error('Credential public key was missing numeric alg');
123
- }
124
- // Make sure the key algorithm is one we specified within the registration options
125
- if (!supportedAlgorithmIDs.includes(alg)) {
126
- throw new Error(`Unexpected public key alg "${alg}", expected one of "${supportedAlgorithmIDs.join(', ')}"`);
127
- }
128
- let verified = false;
129
- if (fmt === 'none') {
130
- if (attStmt.size > 0) {
131
- throw new Error('None attestation had unexpected attestation statement');
132
- }
133
- verified = true;
134
- }
135
- else if (fmt === 'packed') {
136
- verified = await verifyPackedAttestation(attStmt, authData, attestationResponse.clientDataJSON, decodedPublicKey);
137
- }
138
- else {
139
- throw new Error(`Unsupported attestation format: ${fmt}`);
140
- }
141
- if (!verified) {
142
- return { verified: false };
143
- }
144
- const aaguidHex = (0, encoding_1.bytesToHex)(aaguid);
145
- const aaguidStr = [
146
- aaguidHex.slice(0, 8),
147
- aaguidHex.slice(8, 12),
148
- aaguidHex.slice(12, 16),
149
- aaguidHex.slice(16, 20),
150
- aaguidHex.slice(20),
151
- ].join('-');
152
- return {
153
- verified: true,
154
- registrationInfo: {
155
- credentialId: attestedCredentialId,
156
- publicKey: credentialPublicKey,
157
- counter,
158
- transports: attestationResponse.transports,
159
- aaguid: aaguidStr,
160
- attestationFormat: fmt,
161
- userVerified: flags.uv,
162
- },
163
- };
164
- }
165
- exports.verifyRegistrationResponse = verifyRegistrationResponse;
166
- /**
167
- * Verify packed self-attestation per WebAuthn §8.2: no x5c certificate
168
- * chain, signature over `authData || SHA-256(clientDataJSON)` verified
169
- * with the credential's own public key, and `alg` in the attestation
170
- * statement must match the credential key's algorithm.
171
- *
172
- * @param attStmt - The attestation statement map from the attestation
173
- * object.
174
- * @param attStmt.get - Accessor to retrieve statement fields by key.
175
- * @param attStmt.size - Number of entries in the statement.
176
- * @param authData - Raw authenticator data bytes.
177
- * @param clientDataJSONB64url - Base64url-encoded clientDataJSON.
178
- * @param cosePublicKey - Decoded COSE public key map from authenticator
179
- * data.
180
- * @returns Whether the packed attestation signature is valid.
181
- */
182
- async function verifyPackedAttestation(attStmt, authData, clientDataJSONB64url, cosePublicKey) {
183
- const attStmtAlg = attStmt.get('alg');
184
- const signature = attStmt.get('sig');
185
- const x5c = attStmt.get('x5c');
186
- if (typeof attStmtAlg !== 'number') {
187
- throw new Error('Packed attestation statement missing alg');
188
- }
189
- if (!signature) {
190
- throw new Error('Packed attestation missing signature');
191
- }
192
- if (x5c && x5c.length > 0) {
193
- throw new Error('Packed attestation with certificate chain (x5c) is not supported; only self-attestation is accepted');
194
- }
195
- const credAlg = cosePublicKey.get(constants_1.COSEKEYS.Alg);
196
- if (attStmtAlg !== credAlg) {
197
- throw new Error(`Packed attestation alg ${attStmtAlg} does not match credential alg ${credAlg}`);
198
- }
199
- const clientDataHash = (0, sha2_1.sha256)((0, encoding_1.base64URLToBytes)(clientDataJSONB64url));
200
- const signatureBase = (0, utils_1.concatBytes)([authData, clientDataHash]);
201
- return (0, verify_signature_1.verifySignature)({
202
- cosePublicKey,
203
- signature,
204
- data: signatureBase,
205
- });
206
- }
207
- //# sourceMappingURL=verify-registration-response.cjs.map