ox 0.12.4 → 0.13.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 (105) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/_cjs/core/P256.js +1 -1
  3. package/_cjs/core/P256.js.map +1 -1
  4. package/_cjs/core/WebAuthnP256.js +15 -256
  5. package/_cjs/core/WebAuthnP256.js.map +1 -1
  6. package/_cjs/core/WebCryptoP256.js +3 -1
  7. package/_cjs/core/WebCryptoP256.js.map +1 -1
  8. package/_cjs/core/internal/webauthn.js +5 -13
  9. package/_cjs/core/internal/webauthn.js.map +1 -1
  10. package/_cjs/index.docs.js +1 -0
  11. package/_cjs/index.docs.js.map +1 -1
  12. package/_cjs/version.js +1 -1
  13. package/_cjs/webauthn/Authentication.js +246 -0
  14. package/_cjs/webauthn/Authentication.js.map +1 -0
  15. package/_cjs/webauthn/Authenticator.js +55 -0
  16. package/_cjs/webauthn/Authenticator.js.map +1 -0
  17. package/_cjs/webauthn/Credential.js +53 -0
  18. package/_cjs/webauthn/Credential.js.map +1 -0
  19. package/_cjs/webauthn/Registration.js +349 -0
  20. package/_cjs/webauthn/Registration.js.map +1 -0
  21. package/_cjs/webauthn/Types.js +3 -0
  22. package/_cjs/webauthn/Types.js.map +1 -0
  23. package/_cjs/webauthn/index.js +9 -0
  24. package/_cjs/webauthn/index.js.map +1 -0
  25. package/_cjs/webauthn/internal/utils.js +53 -0
  26. package/_cjs/webauthn/internal/utils.js.map +1 -0
  27. package/_esm/core/P256.js +1 -1
  28. package/_esm/core/P256.js.map +1 -1
  29. package/_esm/core/WebAuthnP256.js +13 -261
  30. package/_esm/core/WebAuthnP256.js.map +1 -1
  31. package/_esm/core/WebCryptoP256.js +4 -1
  32. package/_esm/core/WebCryptoP256.js.map +1 -1
  33. package/_esm/core/internal/webauthn.js +5 -13
  34. package/_esm/core/internal/webauthn.js.map +1 -1
  35. package/_esm/erc8021/index.js +2 -2
  36. package/_esm/index.docs.js +1 -0
  37. package/_esm/index.docs.js.map +1 -1
  38. package/_esm/tempo/TransactionReceipt.js +1 -1
  39. package/_esm/tempo/TransactionRequest.js +1 -1
  40. package/_esm/version.js +1 -1
  41. package/_esm/webauthn/Authentication.js +453 -0
  42. package/_esm/webauthn/Authentication.js.map +1 -0
  43. package/_esm/webauthn/Authenticator.js +176 -0
  44. package/_esm/webauthn/Authenticator.js.map +1 -0
  45. package/_esm/webauthn/Credential.js +95 -0
  46. package/_esm/webauthn/Credential.js.map +1 -0
  47. package/_esm/webauthn/Registration.js +512 -0
  48. package/_esm/webauthn/Registration.js.map +1 -0
  49. package/_esm/webauthn/Types.js +2 -0
  50. package/_esm/webauthn/Types.js.map +1 -0
  51. package/_esm/webauthn/index.js +31 -0
  52. package/_esm/webauthn/index.js.map +1 -0
  53. package/_esm/webauthn/internal/utils.js +52 -0
  54. package/_esm/webauthn/internal/utils.js.map +1 -0
  55. package/_types/core/WebAuthnP256.d.ts +33 -208
  56. package/_types/core/WebAuthnP256.d.ts.map +1 -1
  57. package/_types/core/WebCryptoP256.d.ts +2 -0
  58. package/_types/core/WebCryptoP256.d.ts.map +1 -1
  59. package/_types/core/internal/webauthn.d.ts +2 -110
  60. package/_types/core/internal/webauthn.d.ts.map +1 -1
  61. package/_types/erc8021/index.d.ts +2 -2
  62. package/_types/index.docs.d.ts +1 -0
  63. package/_types/index.docs.d.ts.map +1 -1
  64. package/_types/tempo/Transaction.d.ts +2 -2
  65. package/_types/tempo/TransactionReceipt.d.ts +2 -2
  66. package/_types/tempo/TransactionRequest.d.ts +2 -2
  67. package/_types/version.d.ts +1 -1
  68. package/_types/webauthn/Authentication.d.ts +324 -0
  69. package/_types/webauthn/Authentication.d.ts.map +1 -0
  70. package/_types/webauthn/Authenticator.d.ts +182 -0
  71. package/_types/webauthn/Authenticator.d.ts.map +1 -0
  72. package/_types/webauthn/Credential.d.ts +77 -0
  73. package/_types/webauthn/Credential.d.ts.map +1 -0
  74. package/_types/webauthn/Registration.d.ts +308 -0
  75. package/_types/webauthn/Registration.d.ts.map +1 -0
  76. package/_types/webauthn/Types.d.ts +106 -0
  77. package/_types/webauthn/Types.d.ts.map +1 -0
  78. package/_types/webauthn/index.d.ts +33 -0
  79. package/_types/webauthn/index.d.ts.map +1 -0
  80. package/_types/webauthn/internal/utils.d.ts +17 -0
  81. package/_types/webauthn/internal/utils.d.ts.map +1 -0
  82. package/core/P256.ts +1 -1
  83. package/core/WebAuthnP256.ts +37 -582
  84. package/core/WebCryptoP256.ts +6 -1
  85. package/core/internal/webauthn.ts +6 -165
  86. package/erc8021/index.ts +2 -2
  87. package/index.docs.ts +1 -0
  88. package/package.json +31 -1
  89. package/tempo/Transaction.ts +2 -2
  90. package/tempo/TransactionReceipt.ts +2 -2
  91. package/tempo/TransactionRequest.ts +2 -2
  92. package/version.ts +1 -1
  93. package/webauthn/Authentication/package.json +6 -0
  94. package/webauthn/Authentication.ts +673 -0
  95. package/webauthn/Authenticator/package.json +6 -0
  96. package/webauthn/Authenticator.ts +259 -0
  97. package/webauthn/Credential/package.json +6 -0
  98. package/webauthn/Credential.ts +146 -0
  99. package/webauthn/Registration/package.json +6 -0
  100. package/webauthn/Registration.ts +805 -0
  101. package/webauthn/Types/package.json +6 -0
  102. package/webauthn/Types.ts +158 -0
  103. package/webauthn/index.ts +38 -0
  104. package/webauthn/internal/utils.ts +63 -0
  105. package/webauthn/package.json +6 -0
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SignFailedError = void 0;
4
+ exports.deserializeOptions = deserializeOptions;
5
+ exports.deserializeResponse = deserializeResponse;
6
+ exports.getOptions = getOptions;
7
+ exports.getSignPayload = getSignPayload;
8
+ exports.serializeOptions = serializeOptions;
9
+ exports.serializeResponse = serializeResponse;
10
+ exports.sign = sign;
11
+ exports.verify = verify;
12
+ const Base64 = require("../core/Base64.js");
13
+ const Bytes = require("../core/Bytes.js");
14
+ const Errors = require("../core/Errors.js");
15
+ const Hash = require("../core/Hash.js");
16
+ const Hex = require("../core/Hex.js");
17
+ const internal = require("../core/internal/webauthn.js");
18
+ const P256 = require("../core/P256.js");
19
+ const Signature = require("../core/Signature.js");
20
+ const Authenticator_js_1 = require("./Authenticator.js");
21
+ const utils_js_1 = require("./internal/utils.js");
22
+ function deserializeOptions(options) {
23
+ const { publicKey, ...rest } = options;
24
+ if (!publicKey)
25
+ return { ...rest };
26
+ const { allowCredentials, challenge, extensions, ...publicKeyRest } = publicKey;
27
+ return {
28
+ ...rest,
29
+ publicKey: {
30
+ ...publicKeyRest,
31
+ challenge: Bytes.fromHex(challenge),
32
+ ...(allowCredentials && {
33
+ allowCredentials: allowCredentials.map(({ id, ...rest }) => ({
34
+ ...rest,
35
+ id: Base64.toBytes(id),
36
+ })),
37
+ }),
38
+ ...(extensions && {
39
+ extensions: (0, utils_js_1.deserializeExtensions)(extensions),
40
+ }),
41
+ },
42
+ };
43
+ }
44
+ function deserializeResponse(response) {
45
+ const { id, metadata, raw, signature } = response;
46
+ const rawResponse = {};
47
+ for (const [key, value] of Object.entries(raw.response))
48
+ rawResponse[key] = (0, utils_js_1.bytesToArrayBuffer)(Base64.toBytes(value));
49
+ return {
50
+ id,
51
+ metadata,
52
+ raw: {
53
+ id: raw.id,
54
+ type: raw.type,
55
+ authenticatorAttachment: raw.authenticatorAttachment,
56
+ rawId: (0, utils_js_1.bytesToArrayBuffer)(Base64.toBytes(raw.rawId)),
57
+ response: rawResponse,
58
+ getClientExtensionResults: () => ({}),
59
+ },
60
+ signature: Signature.from(signature),
61
+ };
62
+ }
63
+ function getOptions(options) {
64
+ const { credentialId, challenge, extensions, rpId = window.location.hostname, userVerification = 'required', } = options;
65
+ return {
66
+ publicKey: {
67
+ ...(credentialId
68
+ ? {
69
+ allowCredentials: Array.isArray(credentialId)
70
+ ? credentialId.map((id) => ({
71
+ id: Base64.toBytes(id),
72
+ type: 'public-key',
73
+ }))
74
+ : [
75
+ {
76
+ id: Base64.toBytes(credentialId),
77
+ type: 'public-key',
78
+ },
79
+ ],
80
+ }
81
+ : {}),
82
+ challenge: Bytes.fromHex(challenge),
83
+ ...(extensions && { extensions }),
84
+ rpId,
85
+ userVerification,
86
+ },
87
+ };
88
+ }
89
+ function getSignPayload(options) {
90
+ const { challenge, crossOrigin, extraClientData, flag, origin, rpId, signCount, userVerification = 'required', } = options;
91
+ const authenticatorData = (0, Authenticator_js_1.getAuthenticatorData)({
92
+ flag,
93
+ rpId,
94
+ signCount,
95
+ });
96
+ const clientDataJSON = (0, Authenticator_js_1.getClientDataJSON)({
97
+ challenge,
98
+ crossOrigin,
99
+ extraClientData,
100
+ origin,
101
+ });
102
+ const clientDataJSONHash = Hash.sha256(Hex.fromString(clientDataJSON));
103
+ const challengeIndex = clientDataJSON.indexOf('"challenge"');
104
+ const typeIndex = clientDataJSON.indexOf('"type"');
105
+ const metadata = {
106
+ authenticatorData,
107
+ clientDataJSON,
108
+ challengeIndex,
109
+ typeIndex,
110
+ userVerificationRequired: userVerification === 'required',
111
+ };
112
+ const payload = Hex.concat(authenticatorData, clientDataJSONHash);
113
+ return { metadata, payload };
114
+ }
115
+ function serializeOptions(options) {
116
+ const { publicKey, signal: _, ...rest } = options;
117
+ if (!publicKey)
118
+ return { ...rest };
119
+ const { allowCredentials, challenge, extensions, ...publicKeyRest } = publicKey;
120
+ return {
121
+ ...rest,
122
+ publicKey: {
123
+ ...publicKeyRest,
124
+ challenge: Hex.fromBytes((0, utils_js_1.bufferSourceToBytes)(challenge)),
125
+ ...(allowCredentials && {
126
+ allowCredentials: allowCredentials.map(({ id, ...rest }) => ({
127
+ ...rest,
128
+ id: Base64.fromBytes((0, utils_js_1.bufferSourceToBytes)(id), utils_js_1.base64UrlOptions),
129
+ })),
130
+ }),
131
+ ...(extensions && {
132
+ extensions: (0, utils_js_1.serializeExtensions)(extensions),
133
+ }),
134
+ },
135
+ };
136
+ }
137
+ function serializeResponse(response) {
138
+ const { id, metadata, raw, signature } = response;
139
+ const rawResponse = {};
140
+ for (const key of utils_js_1.responseKeys) {
141
+ const value = raw.response[key];
142
+ if (value instanceof ArrayBuffer)
143
+ rawResponse[key] = Base64.fromBytes(new Uint8Array(value), utils_js_1.base64UrlOptions);
144
+ }
145
+ return {
146
+ id,
147
+ metadata,
148
+ raw: {
149
+ id: raw.id,
150
+ type: raw.type,
151
+ authenticatorAttachment: raw.authenticatorAttachment,
152
+ rawId: Base64.fromBytes((0, utils_js_1.bufferSourceToBytes)(raw.rawId), utils_js_1.base64UrlOptions),
153
+ response: rawResponse,
154
+ },
155
+ signature: Signature.toHex(signature),
156
+ };
157
+ }
158
+ async function sign(options) {
159
+ const { getFn = window.navigator.credentials.get.bind(window.navigator.credentials), ...rest } = options;
160
+ const requestOptions = 'publicKey' in rest
161
+ ? rest
162
+ : getOptions(rest);
163
+ try {
164
+ const credential = (await getFn(requestOptions));
165
+ if (!credential)
166
+ throw new SignFailedError();
167
+ const response = credential.response;
168
+ const clientDataJSON = String.fromCharCode(...new Uint8Array(response.clientDataJSON));
169
+ const challengeIndex = clientDataJSON.indexOf('"challenge"');
170
+ const typeIndex = clientDataJSON.indexOf('"type"');
171
+ const signature = internal.parseAsn1Signature(new Uint8Array(response.signature));
172
+ return {
173
+ id: credential.id,
174
+ metadata: {
175
+ authenticatorData: Hex.fromBytes(new Uint8Array(response.authenticatorData)),
176
+ clientDataJSON,
177
+ challengeIndex,
178
+ typeIndex,
179
+ userVerificationRequired: requestOptions.publicKey.userVerification === 'required',
180
+ },
181
+ signature,
182
+ raw: credential,
183
+ };
184
+ }
185
+ catch (error) {
186
+ throw new SignFailedError({
187
+ cause: error,
188
+ });
189
+ }
190
+ }
191
+ class SignFailedError extends Errors.BaseError {
192
+ constructor({ cause } = {}) {
193
+ super('Failed to request credential.', {
194
+ cause,
195
+ });
196
+ Object.defineProperty(this, "name", {
197
+ enumerable: true,
198
+ configurable: true,
199
+ writable: true,
200
+ value: 'Authentication.SignFailedError'
201
+ });
202
+ }
203
+ }
204
+ exports.SignFailedError = SignFailedError;
205
+ function verify(options) {
206
+ const { challenge, metadata, origin, publicKey, rpId, signature } = options;
207
+ const { authenticatorData, clientDataJSON, userVerificationRequired } = metadata;
208
+ const authenticatorDataBytes = Bytes.fromHex(authenticatorData);
209
+ if (authenticatorDataBytes.length < 37)
210
+ return false;
211
+ if (rpId !== undefined) {
212
+ const rpIdHash = authenticatorDataBytes.slice(0, 32);
213
+ const expectedRpIdHash = Hash.sha256(Hex.fromString(rpId), { as: 'Bytes' });
214
+ if (!Bytes.isEqual(rpIdHash, expectedRpIdHash))
215
+ return false;
216
+ }
217
+ const flag = authenticatorDataBytes[32];
218
+ if ((flag & 0x01) !== 0x01)
219
+ return false;
220
+ if (userVerificationRequired && (flag & 0x04) !== 0x04)
221
+ return false;
222
+ if ((flag & 0x08) !== 0x08 && (flag & 0x10) === 0x10)
223
+ return false;
224
+ const clientData = JSON.parse(clientDataJSON);
225
+ if (clientData.type !== 'webauthn.get')
226
+ return false;
227
+ if (!clientData.challenge ||
228
+ Hex.fromBytes(Base64.toBytes(clientData.challenge)) !== challenge)
229
+ return false;
230
+ if (origin !== undefined) {
231
+ const origins = Array.isArray(origin) ? origin : [origin];
232
+ if (!origins.includes(clientData.origin))
233
+ return false;
234
+ }
235
+ const clientDataJSONHash = Hash.sha256(Bytes.fromString(clientDataJSON), {
236
+ as: 'Bytes',
237
+ });
238
+ const payload = Bytes.concat(authenticatorDataBytes, clientDataJSONHash);
239
+ return P256.verify({
240
+ hash: true,
241
+ payload,
242
+ publicKey,
243
+ signature,
244
+ });
245
+ }
246
+ //# sourceMappingURL=Authentication.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Authentication.js","sourceRoot":"","sources":["../../webauthn/Authentication.ts"],"names":[],"mappings":";;;AAoDA,gDAyBC;AAoCD,kDAoBC;AA0BD,gCAiCC;AA4DD,wCAyCC;AA2DD,4CAyBC;AA4BD,8CAyBC;AAyCD,oBA8CC;AAmED,wBA6DC;AAroBD,4C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esModule", { value: true });
3
+ exports.getAuthenticatorData = getAuthenticatorData;
4
+ exports.getSignCount = getSignCount;
5
+ exports.getClientDataJSON = getClientDataJSON;
6
+ exports.getAttestationObject = getAttestationObject;
7
+ const Base64 = require("../core/Base64.js");
8
+ const Bytes = require("../core/Bytes.js");
9
+ const Cbor = require("../core/Cbor.js");
10
+ const CoseKey = require("../core/CoseKey.js");
11
+ const Hash = require("../core/Hash.js");
12
+ const Hex = require("../core/Hex.js");
13
+ function getAuthenticatorData(options = {}) {
14
+ const { credential, flag = 5, rpId = window.location.hostname, signCount = 0, } = options;
15
+ const rpIdHash = Hash.sha256(Hex.fromString(rpId));
16
+ const flag_bytes = Hex.fromNumber(flag, { size: 1 });
17
+ const signCount_bytes = Hex.fromNumber(signCount, { size: 4 });
18
+ const base = Hex.concat(rpIdHash, flag_bytes, signCount_bytes);
19
+ if (!credential)
20
+ return base;
21
+ const aaguid = Hex.fromBytes(new Uint8Array(16));
22
+ const credentialId = Hex.fromBytes(credential.id);
23
+ const credIdLen = Hex.fromNumber(credential.id.length, { size: 2 });
24
+ const coseKey = CoseKey.fromPublicKey(credential.publicKey);
25
+ return Hex.concat(base, aaguid, credIdLen, credentialId, coseKey);
26
+ }
27
+ function getSignCount(authenticatorData) {
28
+ const bytes = Bytes.fromHex(authenticatorData);
29
+ if (bytes.length < 37)
30
+ return 0;
31
+ return (((bytes[33] << 24) |
32
+ (bytes[34] << 16) |
33
+ (bytes[35] << 8) |
34
+ bytes[36]) >>>
35
+ 0);
36
+ }
37
+ function getClientDataJSON(options) {
38
+ const { challenge, crossOrigin = false, extraClientData, origin = window.location.origin, type = 'webauthn.get', } = options;
39
+ return JSON.stringify({
40
+ type,
41
+ challenge: Base64.fromHex(challenge, { url: true, pad: false }),
42
+ origin,
43
+ crossOrigin,
44
+ ...extraClientData,
45
+ });
46
+ }
47
+ function getAttestationObject(options) {
48
+ const { attStmt = {}, authData, fmt = 'none' } = options;
49
+ return Cbor.encode({
50
+ fmt,
51
+ attStmt,
52
+ authData: Hex.toBytes(authData),
53
+ });
54
+ }
55
+ //# sourceMappingURL=Authenticator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Authenticator.js","sourceRoot":"","sources":["../../webauthn/Authenticator.ts"],"names":[],"mappings":";;AA0DA,oDA2BC;AA4CD,oCAUC;AAgCD,8CAgBC;AAiDD,oDASC;AArPD,4CAA2C;AAC3C,0CAAyC;AACzC,wCAAuC;AACvC,8CAA6C;AAE7C,wCAAuC;AACvC,sCAAqC;AAoDrC,SAAgB,oBAAoB,CAClC,UAAwC,EAAE;IAE1C,MAAM,EACJ,UAAU,EACV,IAAI,GAAG,CAAC,EACR,IAAI,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,EAC/B,SAAS,GAAG,CAAC,GACd,GAAG,OAAO,CAAA;IACX,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAA;IAClD,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;IACpD,MAAM,eAAe,GAAG,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;IAC9D,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,QAAQ,EAAE,UAAU,EAAE,eAAe,CAAC,CAAA;IAE9D,IAAI,CAAC,UAAU;QAAE,OAAO,IAAI,CAAA;IAG5B,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,CAAC,IAAI,UAAU,CAAC,EAAE,CAAC,CAAC,CAAA;IAGhD,MAAM,YAAY,GAAG,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,CAAC,CAAA;IACjD,MAAM,SAAS,GAAG,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,EA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GAAG;QACH,OAAO;QACP,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;KAChC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serialize = serialize;
4
+ exports.deserialize = deserialize;
5
+ const Base64 = require("../core/Base64.js");
6
+ const PublicKey = require("../core/PublicKey.js");
7
+ const utils_js_1 = require("./internal/utils.js");
8
+ function serialize(credential) {
9
+ const { attestationObject, clientDataJSON, id, publicKey, raw } = credential;
10
+ const response = {};
11
+ for (const key of utils_js_1.responseKeys) {
12
+ const value = raw.response[key];
13
+ if (value instanceof ArrayBuffer)
14
+ response[key] = Base64.fromBytes(new Uint8Array(value), utils_js_1.base64UrlOptions);
15
+ }
16
+ return {
17
+ attestationObject: Base64.fromBytes(new Uint8Array(attestationObject), utils_js_1.base64UrlOptions),
18
+ clientDataJSON: Base64.fromBytes(new Uint8Array(clientDataJSON), utils_js_1.base64UrlOptions),
19
+ id,
20
+ publicKey: PublicKey.toHex(publicKey),
21
+ raw: {
22
+ id: raw.id,
23
+ type: raw.type,
24
+ authenticatorAttachment: raw.authenticatorAttachment,
25
+ rawId: Base64.fromBytes((0, utils_js_1.bufferSourceToBytes)(raw.rawId), utils_js_1.base64UrlOptions),
26
+ response: response,
27
+ },
28
+ };
29
+ }
30
+ function deserialize(credential) {
31
+ const { attestationObject, clientDataJSON, id, publicKey, raw } = credential;
32
+ const response = Object.create(null);
33
+ for (const key of utils_js_1.responseKeys) {
34
+ const value = raw.response[key];
35
+ if (value)
36
+ response[key] = (0, utils_js_1.bytesToArrayBuffer)(Base64.toBytes(value));
37
+ }
38
+ return {
39
+ attestationObject: (0, utils_js_1.bytesToArrayBuffer)(Base64.toBytes(attestationObject)),
40
+ clientDataJSON: (0, utils_js_1.bytesToArrayBuffer)(Base64.toBytes(clientDataJSON)),
41
+ id,
42
+ publicKey: PublicKey.from(publicKey),
43
+ raw: {
44
+ id: raw.id,
45
+ type: raw.type,
46
+ authenticatorAttachment: raw.authenticatorAttachment,
47
+ rawId: (0, utils_js_1.bytesToArrayBuffer)(Base64.toBytes(raw.rawId)),
48
+ response: response,
49
+ getClientExtensionResults: () => ({}),
50
+ },
51
+ };
52
+ }
53
+ //# sourceMappingURL=Credential.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Credential.js","sourceRoot":"","sources":["../../webauthn/Credential.ts"],"names":[],"mappings":";;AAkDA,8BA6BC;AAoCD,kCAuBC;AA1ID,4CAA2C;AAI3C,kDAAiD;AACjD,kDAK4B;AAwC5B,SAAgB,SAAS,CAAC,UAAsB;IAC9C,MAAM,EAAE,iBAAiB,EAAE,cAAc,EAAE,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,UAAU,CAAA;IAE5E,MAAM,QAAQ,GAAG,EAA4B,CAAA;IAC7C,KAAK,MAAM,GAAG,IAAI,uBAAY,EAAE,CAAC;QAC/B,MAAM,KAAK,GAAI,GAAG,CAAC,QAA+C,CAAC,GAAG,CAAC,CAAA;QACvE,IAAI,KAAK,YAAY,WAAW;YAC9B,QAAQ,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,2BAAgB,CAAC,CAAA;IAC7E,CAAC;IAED,OAAO;QACL,iBAAiB,EAAE,MAAM,CAAC,SAAS,CACjC,IAAI,UAAU,CAAC,iBAAiB,CAAC,EACjC,2BAAgB,CACjB;QACD,cAAc,EAAE,MAAM,CAAC,SAAS,CAC9B,IAAI,UAAU,CAAC,cAAc,CAAC,EAC9B,2BAAgB,CACjB;QACD,EAAE;QACF,SAAS,EAAE,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC;QACrC,GAAG,EAAE;YACH,EAAE,EAAE,GAAG,CAAC,EAAE;YACV,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,uBAAuB,EAAE,GAAG,CAAC,uBAAuB;YACpD,K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