@capgo/capacitor-passkey 8.2.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/CapgoCapacitorPasskey.podspec +17 -0
- package/LICENSE +373 -0
- package/Package.swift +28 -0
- package/README.md +692 -0
- package/android/build.gradle +61 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/app/capgo/passkey/CapacitorPasskey.java +21 -0
- package/android/src/main/java/app/capgo/passkey/CapacitorPasskeyPlugin.java +299 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +1034 -0
- package/dist/esm/definitions.d.ts +531 -0
- package/dist/esm/definitions.js +2 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +87 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/internal.d.ts +14 -0
- package/dist/esm/internal.js +2 -0
- package/dist/esm/internal.js.map +1 -0
- package/dist/esm/shim.d.ts +8 -0
- package/dist/esm/shim.js +108 -0
- package/dist/esm/shim.js.map +1 -0
- package/dist/esm/web.d.ts +12 -0
- package/dist/esm/web.js +69 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/esm/webauthn.d.ts +23 -0
- package/dist/esm/webauthn.js +440 -0
- package/dist/esm/webauthn.js.map +1 -0
- package/dist/plugin.cjs.js +707 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +710 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Sources/CapacitorPasskeyPlugin/CapacitorPasskey.swift +39 -0
- package/ios/Sources/CapacitorPasskeyPlugin/CapacitorPasskeyPlugin.swift +388 -0
- package/ios/Tests/CapacitorPasskeyPluginTests/CapacitorPasskeyPluginTests.swift +17 -0
- package/package.json +105 -0
- package/scripts/configure-native.js +263 -0
|
@@ -0,0 +1,440 @@
|
|
|
1
|
+
const PASSKEY_TYPE = 'public-key';
|
|
2
|
+
export function createNativeRequest(options) {
|
|
3
|
+
if ('mediation' in options) {
|
|
4
|
+
const getOptions = options;
|
|
5
|
+
return {
|
|
6
|
+
origin: resolveOrigin(getOptions.origin, getOptions.publicKey.rpId),
|
|
7
|
+
requestJson: JSON.stringify(normalizeRequestOptionsJSON(getOptions.publicKey, getOptions.origin)),
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const createOptions = options;
|
|
11
|
+
return {
|
|
12
|
+
origin: resolveOrigin(createOptions.origin, createOptions.publicKey.rp.id),
|
|
13
|
+
requestJson: JSON.stringify(normalizeCreationOptionsJSON(createOptions.publicKey, createOptions.origin)),
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export function webAuthnCreationOptionsToJSON(options, origin) {
|
|
17
|
+
var _a;
|
|
18
|
+
return normalizeCreationOptionsJSON({
|
|
19
|
+
attestation: options.attestation,
|
|
20
|
+
authenticatorSelection: options.authenticatorSelection
|
|
21
|
+
? {
|
|
22
|
+
authenticatorAttachment: options.authenticatorSelection.authenticatorAttachment,
|
|
23
|
+
requireResidentKey: options.authenticatorSelection.requireResidentKey,
|
|
24
|
+
residentKey: options.authenticatorSelection.residentKey,
|
|
25
|
+
userVerification: options.authenticatorSelection.userVerification,
|
|
26
|
+
}
|
|
27
|
+
: undefined,
|
|
28
|
+
challenge: encodeBase64Url(options.challenge),
|
|
29
|
+
excludeCredentials: (_a = options.excludeCredentials) === null || _a === void 0 ? void 0 : _a.map(descriptorToJSON),
|
|
30
|
+
extensions: cloneExtensions(options.extensions),
|
|
31
|
+
pubKeyCredParams: options.pubKeyCredParams.map((entry) => ({
|
|
32
|
+
alg: entry.alg,
|
|
33
|
+
type: entry.type,
|
|
34
|
+
})),
|
|
35
|
+
rp: {
|
|
36
|
+
id: options.rp.id,
|
|
37
|
+
name: options.rp.name,
|
|
38
|
+
},
|
|
39
|
+
timeout: options.timeout,
|
|
40
|
+
user: {
|
|
41
|
+
displayName: options.user.displayName,
|
|
42
|
+
id: encodeBase64Url(options.user.id),
|
|
43
|
+
name: options.user.name,
|
|
44
|
+
},
|
|
45
|
+
}, origin);
|
|
46
|
+
}
|
|
47
|
+
export function webAuthnRequestOptionsToJSON(options, origin) {
|
|
48
|
+
var _a;
|
|
49
|
+
return normalizeRequestOptionsJSON({
|
|
50
|
+
allowCredentials: (_a = options.allowCredentials) === null || _a === void 0 ? void 0 : _a.map(descriptorToJSON),
|
|
51
|
+
challenge: encodeBase64Url(options.challenge),
|
|
52
|
+
extensions: cloneExtensions(options.extensions),
|
|
53
|
+
rpId: options.rpId,
|
|
54
|
+
timeout: options.timeout,
|
|
55
|
+
userVerification: options.userVerification,
|
|
56
|
+
}, origin);
|
|
57
|
+
}
|
|
58
|
+
export function normalizeCreationOptionsJSON(options, origin) {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
const rpId = (_a = options.rp.id) !== null && _a !== void 0 ? _a : deriveRpId(resolveOrigin(origin, options.rp.id));
|
|
61
|
+
if (!rpId) {
|
|
62
|
+
throw createPasskeyDomException('DataError', 'A relying party id or HTTPS origin is required.');
|
|
63
|
+
}
|
|
64
|
+
return Object.assign(Object.assign({}, options), { excludeCredentials: (_b = options.excludeCredentials) === null || _b === void 0 ? void 0 : _b.map(descriptorToJSON), pubKeyCredParams: options.pubKeyCredParams.map((entry) => {
|
|
65
|
+
var _a;
|
|
66
|
+
return ({
|
|
67
|
+
alg: entry.alg,
|
|
68
|
+
type: (_a = entry.type) !== null && _a !== void 0 ? _a : PASSKEY_TYPE,
|
|
69
|
+
});
|
|
70
|
+
}), rp: Object.assign(Object.assign({}, options.rp), { id: rpId }) });
|
|
71
|
+
}
|
|
72
|
+
export function normalizeRequestOptionsJSON(options, origin) {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
const rpId = (_a = options.rpId) !== null && _a !== void 0 ? _a : deriveRpId(resolveOrigin(origin, options.rpId));
|
|
75
|
+
return Object.assign(Object.assign({}, options), { allowCredentials: (_b = options.allowCredentials) === null || _b === void 0 ? void 0 : _b.map(descriptorToJSON), rpId });
|
|
76
|
+
}
|
|
77
|
+
export function browserCreationOptionsFromJSON(options) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
return {
|
|
80
|
+
attestation: options.attestation,
|
|
81
|
+
authenticatorSelection: options.authenticatorSelection
|
|
82
|
+
? {
|
|
83
|
+
authenticatorAttachment: options.authenticatorSelection.authenticatorAttachment,
|
|
84
|
+
requireResidentKey: options.authenticatorSelection.requireResidentKey,
|
|
85
|
+
residentKey: options.authenticatorSelection.residentKey,
|
|
86
|
+
userVerification: options.authenticatorSelection.userVerification,
|
|
87
|
+
}
|
|
88
|
+
: undefined,
|
|
89
|
+
challenge: decodeBase64Url(options.challenge),
|
|
90
|
+
excludeCredentials: (_a = options.excludeCredentials) === null || _a === void 0 ? void 0 : _a.map(jsonDescriptorToBrowser),
|
|
91
|
+
extensions: cloneExtensions(options.extensions),
|
|
92
|
+
pubKeyCredParams: options.pubKeyCredParams.map((entry) => {
|
|
93
|
+
var _a;
|
|
94
|
+
return ({
|
|
95
|
+
alg: entry.alg,
|
|
96
|
+
type: (_a = entry.type) !== null && _a !== void 0 ? _a : PASSKEY_TYPE,
|
|
97
|
+
});
|
|
98
|
+
}),
|
|
99
|
+
rp: {
|
|
100
|
+
id: options.rp.id,
|
|
101
|
+
name: options.rp.name,
|
|
102
|
+
},
|
|
103
|
+
timeout: options.timeout,
|
|
104
|
+
user: {
|
|
105
|
+
displayName: (_b = options.user.displayName) !== null && _b !== void 0 ? _b : options.user.name,
|
|
106
|
+
id: decodeBase64Url(options.user.id),
|
|
107
|
+
name: options.user.name,
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export function browserRequestOptionsFromJSON(options) {
|
|
112
|
+
var _a;
|
|
113
|
+
return {
|
|
114
|
+
allowCredentials: (_a = options.allowCredentials) === null || _a === void 0 ? void 0 : _a.map(jsonDescriptorToBrowser),
|
|
115
|
+
challenge: decodeBase64Url(options.challenge),
|
|
116
|
+
extensions: cloneExtensions(options.extensions),
|
|
117
|
+
rpId: options.rpId,
|
|
118
|
+
timeout: options.timeout,
|
|
119
|
+
userVerification: options.userVerification,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
export async function browserRegistrationToJSON(credential) {
|
|
123
|
+
var _a;
|
|
124
|
+
const publicKeyCredential = expectPublicKeyCredential(credential, 'registration');
|
|
125
|
+
const response = publicKeyCredential.response;
|
|
126
|
+
const nativeJson = credentialWithToJSON(publicKeyCredential);
|
|
127
|
+
if (nativeJson && 'attestationObject' in nativeJson.response) {
|
|
128
|
+
return normalizeRegistrationCredential(nativeJson);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
authenticatorAttachment: normalizeAttachment(publicKeyCredential.authenticatorAttachment),
|
|
132
|
+
clientExtensionResults: clientExtensionResultsToRecord((_a = publicKeyCredential.getClientExtensionResults) === null || _a === void 0 ? void 0 : _a.call(publicKeyCredential)),
|
|
133
|
+
id: publicKeyCredential.id,
|
|
134
|
+
rawId: encodeBase64Url(publicKeyCredential.rawId),
|
|
135
|
+
response: {
|
|
136
|
+
attestationObject: encodeBase64Url(response.attestationObject),
|
|
137
|
+
clientDataJSON: encodeBase64Url(response.clientDataJSON),
|
|
138
|
+
publicKey: response.getPublicKey ? nullableBufferToOptionalBase64Url(response.getPublicKey()) : undefined,
|
|
139
|
+
publicKeyAlgorithm: response.getPublicKeyAlgorithm ? response.getPublicKeyAlgorithm() : undefined,
|
|
140
|
+
transports: response.getTransports ? response.getTransports() : undefined,
|
|
141
|
+
},
|
|
142
|
+
type: PASSKEY_TYPE,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
export async function browserAuthenticationToJSON(credential) {
|
|
146
|
+
var _a;
|
|
147
|
+
const publicKeyCredential = expectPublicKeyCredential(credential, 'authentication');
|
|
148
|
+
const response = publicKeyCredential.response;
|
|
149
|
+
const nativeJson = credentialWithToJSON(publicKeyCredential);
|
|
150
|
+
if (nativeJson && 'authenticatorData' in nativeJson.response) {
|
|
151
|
+
return normalizeAuthenticationCredential(nativeJson);
|
|
152
|
+
}
|
|
153
|
+
return {
|
|
154
|
+
authenticatorAttachment: normalizeAttachment(publicKeyCredential.authenticatorAttachment),
|
|
155
|
+
clientExtensionResults: clientExtensionResultsToRecord((_a = publicKeyCredential.getClientExtensionResults) === null || _a === void 0 ? void 0 : _a.call(publicKeyCredential)),
|
|
156
|
+
id: publicKeyCredential.id,
|
|
157
|
+
rawId: encodeBase64Url(publicKeyCredential.rawId),
|
|
158
|
+
response: {
|
|
159
|
+
authenticatorData: encodeBase64Url(response.authenticatorData),
|
|
160
|
+
clientDataJSON: encodeBase64Url(response.clientDataJSON),
|
|
161
|
+
signature: encodeBase64Url(response.signature),
|
|
162
|
+
userHandle: nullableBufferToBase64Url(response.userHandle),
|
|
163
|
+
},
|
|
164
|
+
type: PASSKEY_TYPE,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
export function credentialFromJSON(credential) {
|
|
168
|
+
const shimCredential = new PasskeyPublicKeyCredential(credential);
|
|
169
|
+
if (typeof globalThis.PublicKeyCredential === 'function') {
|
|
170
|
+
Object.setPrototypeOf(shimCredential, globalThis.PublicKeyCredential.prototype);
|
|
171
|
+
}
|
|
172
|
+
return shimCredential;
|
|
173
|
+
}
|
|
174
|
+
export function parseCreationOptionsFromJSON(options) {
|
|
175
|
+
return browserCreationOptionsFromJSON(normalizeCreationOptionsJSON(options));
|
|
176
|
+
}
|
|
177
|
+
export function parseRequestOptionsFromJSON(options) {
|
|
178
|
+
return browserRequestOptionsFromJSON(normalizeRequestOptionsJSON(options));
|
|
179
|
+
}
|
|
180
|
+
export function decodeBase64Url(value) {
|
|
181
|
+
const bytes = base64UrlToBytes(value);
|
|
182
|
+
return bytes.slice().buffer;
|
|
183
|
+
}
|
|
184
|
+
export function encodeBase64Url(value) {
|
|
185
|
+
if (typeof value === 'undefined' || value === null) {
|
|
186
|
+
return '';
|
|
187
|
+
}
|
|
188
|
+
const bytes = toUint8Array(value);
|
|
189
|
+
let binary = '';
|
|
190
|
+
bytes.forEach((byte) => {
|
|
191
|
+
binary += String.fromCharCode(byte);
|
|
192
|
+
});
|
|
193
|
+
return btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/u, '');
|
|
194
|
+
}
|
|
195
|
+
export function resolveOrigin(explicitOrigin, rpId) {
|
|
196
|
+
if (explicitOrigin) {
|
|
197
|
+
return explicitOrigin;
|
|
198
|
+
}
|
|
199
|
+
if (typeof globalThis.location !== 'undefined' && /^https?:$/u.test(globalThis.location.protocol)) {
|
|
200
|
+
return globalThis.location.origin;
|
|
201
|
+
}
|
|
202
|
+
if (rpId) {
|
|
203
|
+
return `https://${rpId}`;
|
|
204
|
+
}
|
|
205
|
+
return undefined;
|
|
206
|
+
}
|
|
207
|
+
export function createPasskeyDomException(name, message) {
|
|
208
|
+
if (typeof DOMException !== 'undefined') {
|
|
209
|
+
return new DOMException(message, name);
|
|
210
|
+
}
|
|
211
|
+
const error = new Error(message);
|
|
212
|
+
error.name = name;
|
|
213
|
+
return error;
|
|
214
|
+
}
|
|
215
|
+
export function abortIfNeeded(signal) {
|
|
216
|
+
if (signal === null || signal === void 0 ? void 0 : signal.aborted) {
|
|
217
|
+
throw createPasskeyDomException('AbortError', 'The passkey request was aborted.');
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
export function normalizePluginError(error) {
|
|
221
|
+
if (error instanceof Error) {
|
|
222
|
+
return error;
|
|
223
|
+
}
|
|
224
|
+
const message = typeof error === 'object' && error && 'message' in error ? String(error.message) : String(error);
|
|
225
|
+
const name = resolveErrorName(error);
|
|
226
|
+
return createPasskeyDomException(name, message);
|
|
227
|
+
}
|
|
228
|
+
function credentialWithToJSON(credential) {
|
|
229
|
+
const toJSON = credential.toJSON;
|
|
230
|
+
if (typeof toJSON !== 'function') {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
const json = toJSON();
|
|
234
|
+
if (!json || typeof json !== 'object') {
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
const response = json.response;
|
|
238
|
+
if (!response) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
if ('attestationObject' in response) {
|
|
242
|
+
return normalizeRegistrationCredential(json);
|
|
243
|
+
}
|
|
244
|
+
if ('authenticatorData' in response) {
|
|
245
|
+
return normalizeAuthenticationCredential(json);
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
function normalizeRegistrationCredential(credential) {
|
|
250
|
+
var _a, _b, _c, _d, _e;
|
|
251
|
+
return {
|
|
252
|
+
authenticatorAttachment: normalizeAttachment(credential.authenticatorAttachment),
|
|
253
|
+
clientExtensionResults: (_a = credential.clientExtensionResults) !== null && _a !== void 0 ? _a : {},
|
|
254
|
+
id: String((_b = credential.id) !== null && _b !== void 0 ? _b : ''),
|
|
255
|
+
rawId: String((_d = (_c = credential.rawId) !== null && _c !== void 0 ? _c : credential.id) !== null && _d !== void 0 ? _d : ''),
|
|
256
|
+
response: normalizeAttestationResponse((_e = credential.response) !== null && _e !== void 0 ? _e : {}),
|
|
257
|
+
type: PASSKEY_TYPE,
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
function normalizeAuthenticationCredential(credential) {
|
|
261
|
+
var _a, _b, _c, _d, _e;
|
|
262
|
+
return {
|
|
263
|
+
authenticatorAttachment: normalizeAttachment(credential.authenticatorAttachment),
|
|
264
|
+
clientExtensionResults: (_a = credential.clientExtensionResults) !== null && _a !== void 0 ? _a : {},
|
|
265
|
+
id: String((_b = credential.id) !== null && _b !== void 0 ? _b : ''),
|
|
266
|
+
rawId: String((_d = (_c = credential.rawId) !== null && _c !== void 0 ? _c : credential.id) !== null && _d !== void 0 ? _d : ''),
|
|
267
|
+
response: normalizeAssertionResponse((_e = credential.response) !== null && _e !== void 0 ? _e : {}),
|
|
268
|
+
type: PASSKEY_TYPE,
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
function normalizeAttestationResponse(response) {
|
|
272
|
+
var _a, _b;
|
|
273
|
+
return {
|
|
274
|
+
attestationObject: String((_a = response.attestationObject) !== null && _a !== void 0 ? _a : ''),
|
|
275
|
+
clientDataJSON: String((_b = response.clientDataJSON) !== null && _b !== void 0 ? _b : ''),
|
|
276
|
+
publicKey: response.publicKey,
|
|
277
|
+
publicKeyAlgorithm: response.publicKeyAlgorithm,
|
|
278
|
+
transports: response.transports,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
function normalizeAssertionResponse(response) {
|
|
282
|
+
var _a, _b, _c;
|
|
283
|
+
return {
|
|
284
|
+
authenticatorData: String((_a = response.authenticatorData) !== null && _a !== void 0 ? _a : ''),
|
|
285
|
+
clientDataJSON: String((_b = response.clientDataJSON) !== null && _b !== void 0 ? _b : ''),
|
|
286
|
+
signature: String((_c = response.signature) !== null && _c !== void 0 ? _c : ''),
|
|
287
|
+
userHandle: typeof response.userHandle === 'undefined' ? null : response.userHandle,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
function expectPublicKeyCredential(credential, flow) {
|
|
291
|
+
if (!credential || !(credential instanceof PublicKeyCredential)) {
|
|
292
|
+
throw createPasskeyDomException('InvalidStateError', `The browser did not return a ${flow} credential.`);
|
|
293
|
+
}
|
|
294
|
+
return credential;
|
|
295
|
+
}
|
|
296
|
+
function descriptorToJSON(descriptor) {
|
|
297
|
+
var _a;
|
|
298
|
+
return {
|
|
299
|
+
id: typeof descriptor.id === 'string' ? descriptor.id : encodeBase64Url(descriptor.id),
|
|
300
|
+
transports: descriptor.transports ? [...descriptor.transports] : undefined,
|
|
301
|
+
type: (_a = descriptor.type) !== null && _a !== void 0 ? _a : PASSKEY_TYPE,
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function jsonDescriptorToBrowser(descriptor) {
|
|
305
|
+
var _a;
|
|
306
|
+
return {
|
|
307
|
+
id: decodeBase64Url(descriptor.id),
|
|
308
|
+
transports: descriptor.transports,
|
|
309
|
+
type: (_a = descriptor.type) !== null && _a !== void 0 ? _a : PASSKEY_TYPE,
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function cloneExtensions(extensions) {
|
|
313
|
+
if (!extensions) {
|
|
314
|
+
return undefined;
|
|
315
|
+
}
|
|
316
|
+
return JSON.parse(JSON.stringify(extensions));
|
|
317
|
+
}
|
|
318
|
+
function nullableBufferToBase64Url(value) {
|
|
319
|
+
if (typeof value === 'undefined') {
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
if (value === null) {
|
|
323
|
+
return null;
|
|
324
|
+
}
|
|
325
|
+
return encodeBase64Url(value);
|
|
326
|
+
}
|
|
327
|
+
function nullableBufferToOptionalBase64Url(value) {
|
|
328
|
+
const encoded = nullableBufferToBase64Url(value);
|
|
329
|
+
return encoded !== null && encoded !== void 0 ? encoded : undefined;
|
|
330
|
+
}
|
|
331
|
+
function deriveRpId(origin) {
|
|
332
|
+
if (!origin) {
|
|
333
|
+
return undefined;
|
|
334
|
+
}
|
|
335
|
+
try {
|
|
336
|
+
return new URL(origin).hostname;
|
|
337
|
+
}
|
|
338
|
+
catch (_a) {
|
|
339
|
+
return undefined;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
function base64UrlToBytes(value) {
|
|
343
|
+
const normalized = value.replace(/-/g, '+').replace(/_/g, '/');
|
|
344
|
+
const padding = normalized.length % 4 === 0 ? '' : '='.repeat(4 - (normalized.length % 4));
|
|
345
|
+
const binary = atob(`${normalized}${padding}`);
|
|
346
|
+
const bytes = new Uint8Array(binary.length);
|
|
347
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
348
|
+
bytes[index] = binary.charCodeAt(index);
|
|
349
|
+
}
|
|
350
|
+
return bytes;
|
|
351
|
+
}
|
|
352
|
+
function toUint8Array(value) {
|
|
353
|
+
if (Array.isArray(value)) {
|
|
354
|
+
return Uint8Array.from(value);
|
|
355
|
+
}
|
|
356
|
+
if (ArrayBuffer.isView(value)) {
|
|
357
|
+
return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);
|
|
358
|
+
}
|
|
359
|
+
return new Uint8Array(value);
|
|
360
|
+
}
|
|
361
|
+
function normalizeAttachment(value) {
|
|
362
|
+
if (value === 'platform' || value === 'cross-platform') {
|
|
363
|
+
return value;
|
|
364
|
+
}
|
|
365
|
+
return undefined;
|
|
366
|
+
}
|
|
367
|
+
function clientExtensionResultsToRecord(value) {
|
|
368
|
+
if (!value) {
|
|
369
|
+
return {};
|
|
370
|
+
}
|
|
371
|
+
return JSON.parse(JSON.stringify(value));
|
|
372
|
+
}
|
|
373
|
+
class PasskeyAuthenticatorAttestationResponse {
|
|
374
|
+
constructor(json) {
|
|
375
|
+
this.json = json;
|
|
376
|
+
this.clientDataJSON = decodeBase64Url(json.clientDataJSON);
|
|
377
|
+
this.attestationObject = decodeBase64Url(json.attestationObject);
|
|
378
|
+
}
|
|
379
|
+
getPublicKey() {
|
|
380
|
+
return this.json.publicKey ? decodeBase64Url(this.json.publicKey) : null;
|
|
381
|
+
}
|
|
382
|
+
getPublicKeyAlgorithm() {
|
|
383
|
+
var _a;
|
|
384
|
+
return (_a = this.json.publicKeyAlgorithm) !== null && _a !== void 0 ? _a : -7;
|
|
385
|
+
}
|
|
386
|
+
getTransports() {
|
|
387
|
+
return this.json.transports ? [...this.json.transports] : [];
|
|
388
|
+
}
|
|
389
|
+
toJSON() {
|
|
390
|
+
return Object.assign({}, this.json);
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
class PasskeyAuthenticatorAssertionResponse {
|
|
394
|
+
constructor(json) {
|
|
395
|
+
this.json = json;
|
|
396
|
+
this.clientDataJSON = decodeBase64Url(json.clientDataJSON);
|
|
397
|
+
this.authenticatorData = decodeBase64Url(json.authenticatorData);
|
|
398
|
+
this.signature = decodeBase64Url(json.signature);
|
|
399
|
+
this.userHandle = json.userHandle ? decodeBase64Url(json.userHandle) : null;
|
|
400
|
+
}
|
|
401
|
+
toJSON() {
|
|
402
|
+
return Object.assign({}, this.json);
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
class PasskeyPublicKeyCredential {
|
|
406
|
+
constructor(json) {
|
|
407
|
+
var _a;
|
|
408
|
+
this.json = json;
|
|
409
|
+
this.type = PASSKEY_TYPE;
|
|
410
|
+
this.id = json.id;
|
|
411
|
+
this.rawId = decodeBase64Url(json.rawId);
|
|
412
|
+
this.authenticatorAttachment = (_a = json.authenticatorAttachment) !== null && _a !== void 0 ? _a : null;
|
|
413
|
+
this.response =
|
|
414
|
+
'attestationObject' in json.response
|
|
415
|
+
? new PasskeyAuthenticatorAttestationResponse(json.response)
|
|
416
|
+
: new PasskeyAuthenticatorAssertionResponse(json.response);
|
|
417
|
+
}
|
|
418
|
+
getClientExtensionResults() {
|
|
419
|
+
var _a;
|
|
420
|
+
return ((_a = this.json.clientExtensionResults) !== null && _a !== void 0 ? _a : {});
|
|
421
|
+
}
|
|
422
|
+
toJSON() {
|
|
423
|
+
return JSON.parse(JSON.stringify(this.json));
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
function resolveErrorName(error) {
|
|
427
|
+
if (typeof error === 'object' && error) {
|
|
428
|
+
if ('code' in error && typeof error.code === 'string') {
|
|
429
|
+
return error.code;
|
|
430
|
+
}
|
|
431
|
+
if ('data' in error && error.data && typeof error.data === 'object' && 'name' in error.data) {
|
|
432
|
+
const candidate = error.data.name;
|
|
433
|
+
if (typeof candidate === 'string') {
|
|
434
|
+
return candidate;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
return 'UnknownError';
|
|
439
|
+
}
|
|
440
|
+
//# sourceMappingURL=webauthn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webauthn.js","sourceRoot":"","sources":["../../src/webauthn.ts"],"names":[],"mappings":"AAiBA,MAAM,YAAY,GAAG,YAAY,CAAC;AAElC,MAAM,UAAU,mBAAmB,CAAC,OAAuD;IACzF,IAAI,WAAW,IAAI,OAAO,EAAE,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CAAC;QACpB,CAAC;QAED,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;YAC5F,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;YAClC,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;gBAClC,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,cAAc,CAAC;AACxB,CAAC","sourcesContent":["import type {\n CreateCredentialOptions,\n GetCredentialOptions,\n PasskeyAuthenticationCredential,\n PasskeyAuthenticatorAssertionResponseJSON,\n PasskeyAuthenticatorAttestationResponseJSON,\n PasskeyCredentialDescriptor,\n PasskeyPublicKeyCredentialCreationOptionsJSON,\n PasskeyPublicKeyCredentialRequestOptionsJSON,\n PasskeyRegistrationCredential,\n} from './definitions';\nimport type { NativePasskeyRequest } from './internal';\n\ntype BufferLike = BufferSource | ArrayLike<number>;\ntype JsonRecord = Record<string, unknown>;\ntype CredentialJson = PasskeyRegistrationCredential | PasskeyAuthenticationCredential;\n\nconst PASSKEY_TYPE = 'public-key';\n\nexport function createNativeRequest(options: CreateCredentialOptions | GetCredentialOptions): NativePasskeyRequest {\n if ('mediation' in options) {\n const getOptions = options as GetCredentialOptions;\n return {\n origin: resolveOrigin(getOptions.origin, getOptions.publicKey.rpId),\n requestJson: JSON.stringify(normalizeRequestOptionsJSON(getOptions.publicKey, getOptions.origin)),\n };\n }\n\n const createOptions = options as CreateCredentialOptions;\n return {\n origin: resolveOrigin(createOptions.origin, createOptions.publicKey.rp.id),\n requestJson: JSON.stringify(normalizeCreationOptionsJSON(createOptions.publicKey, createOptions.origin)),\n };\n}\n\nexport function webAuthnCreationOptionsToJSON(\n options: PublicKeyCredentialCreationOptions,\n origin?: string,\n): PasskeyPublicKeyCredentialCreationOptionsJSON {\n return normalizeCreationOptionsJSON(\n {\n attestation: options.attestation,\n authenticatorSelection: options.authenticatorSelection\n ? {\n authenticatorAttachment: options.authenticatorSelection.authenticatorAttachment,\n requireResidentKey: options.authenticatorSelection.requireResidentKey,\n residentKey: options.authenticatorSelection.residentKey,\n userVerification: options.authenticatorSelection.userVerification,\n }\n : undefined,\n challenge: encodeBase64Url(options.challenge),\n excludeCredentials: options.excludeCredentials?.map(descriptorToJSON),\n extensions: cloneExtensions(options.extensions),\n pubKeyCredParams: options.pubKeyCredParams.map((entry) => ({\n alg: entry.alg,\n type: entry.type,\n })),\n rp: {\n id: options.rp.id,\n name: options.rp.name,\n },\n timeout: options.timeout,\n user: {\n displayName: options.user.displayName,\n id: encodeBase64Url(options.user.id),\n name: options.user.name,\n },\n },\n origin,\n );\n}\n\nexport function webAuthnRequestOptionsToJSON(\n options: PublicKeyCredentialRequestOptions,\n origin?: string,\n): PasskeyPublicKeyCredentialRequestOptionsJSON {\n return normalizeRequestOptionsJSON(\n {\n allowCredentials: options.allowCredentials?.map(descriptorToJSON),\n challenge: encodeBase64Url(options.challenge),\n extensions: cloneExtensions(options.extensions),\n rpId: options.rpId,\n timeout: options.timeout,\n userVerification: options.userVerification,\n },\n origin,\n );\n}\n\nexport function normalizeCreationOptionsJSON(\n options: PasskeyPublicKeyCredentialCreationOptionsJSON,\n origin?: string,\n): PasskeyPublicKeyCredentialCreationOptionsJSON {\n const rpId = options.rp.id ?? deriveRpId(resolveOrigin(origin, options.rp.id));\n\n if (!rpId) {\n throw createPasskeyDomException('DataError', 'A relying party id or HTTPS origin is required.');\n }\n\n return {\n ...options,\n excludeCredentials: options.excludeCredentials?.map(descriptorToJSON),\n pubKeyCredParams: options.pubKeyCredParams.map((entry) => ({\n alg: entry.alg,\n type: entry.type ?? PASSKEY_TYPE,\n })),\n rp: {\n ...options.rp,\n id: rpId,\n },\n };\n}\n\nexport function normalizeRequestOptionsJSON(\n options: PasskeyPublicKeyCredentialRequestOptionsJSON,\n origin?: string,\n): PasskeyPublicKeyCredentialRequestOptionsJSON {\n const rpId = options.rpId ?? deriveRpId(resolveOrigin(origin, options.rpId));\n\n return {\n ...options,\n allowCredentials: options.allowCredentials?.map(descriptorToJSON),\n rpId,\n };\n}\n\nexport function browserCreationOptionsFromJSON(\n options: PasskeyPublicKeyCredentialCreationOptionsJSON,\n): PublicKeyCredentialCreationOptions {\n return {\n attestation: options.attestation,\n authenticatorSelection: options.authenticatorSelection\n ? {\n authenticatorAttachment: options.authenticatorSelection.authenticatorAttachment,\n requireResidentKey: options.authenticatorSelection.requireResidentKey,\n residentKey: options.authenticatorSelection.residentKey,\n userVerification: options.authenticatorSelection.userVerification,\n }\n : undefined,\n challenge: decodeBase64Url(options.challenge),\n excludeCredentials: options.excludeCredentials?.map(jsonDescriptorToBrowser),\n extensions: cloneExtensions(options.extensions),\n pubKeyCredParams: options.pubKeyCredParams.map((entry) => ({\n alg: entry.alg,\n type: entry.type ?? PASSKEY_TYPE,\n })),\n rp: {\n id: options.rp.id,\n name: options.rp.name,\n },\n timeout: options.timeout,\n user: {\n displayName: options.user.displayName ?? options.user.name,\n id: decodeBase64Url(options.user.id),\n name: options.user.name,\n },\n };\n}\n\nexport function browserRequestOptionsFromJSON(\n options: PasskeyPublicKeyCredentialRequestOptionsJSON,\n): PublicKeyCredentialRequestOptions {\n return {\n allowCredentials: options.allowCredentials?.map(jsonDescriptorToBrowser),\n challenge: decodeBase64Url(options.challenge),\n extensions: cloneExtensions(options.extensions),\n rpId: options.rpId,\n timeout: options.timeout,\n userVerification: options.userVerification,\n };\n}\n\nexport async function browserRegistrationToJSON(credential: Credential | null): Promise<PasskeyRegistrationCredential> {\n const publicKeyCredential = expectPublicKeyCredential(credential, 'registration');\n const response = publicKeyCredential.response as AuthenticatorAttestationResponse;\n const nativeJson = credentialWithToJSON(publicKeyCredential);\n\n if (nativeJson && 'attestationObject' in nativeJson.response) {\n return normalizeRegistrationCredential(nativeJson as PasskeyRegistrationCredential);\n }\n\n return {\n authenticatorAttachment: normalizeAttachment(publicKeyCredential.authenticatorAttachment),\n clientExtensionResults: clientExtensionResultsToRecord(publicKeyCredential.getClientExtensionResults?.()),\n id: publicKeyCredential.id,\n rawId: encodeBase64Url(publicKeyCredential.rawId),\n response: {\n attestationObject: encodeBase64Url(response.attestationObject),\n clientDataJSON: encodeBase64Url(response.clientDataJSON),\n publicKey: response.getPublicKey ? nullableBufferToOptionalBase64Url(response.getPublicKey()) : undefined,\n publicKeyAlgorithm: response.getPublicKeyAlgorithm ? response.getPublicKeyAlgorithm() : undefined,\n transports: response.getTransports ? response.getTransports() : undefined,\n },\n type: PASSKEY_TYPE,\n };\n}\n\nexport async function browserAuthenticationToJSON(\n credential: Credential | null,\n): Promise<PasskeyAuthenticationCredential> {\n const publicKeyCredential = expectPublicKeyCredential(credential, 'authentication');\n const response = publicKeyCredential.response as AuthenticatorAssertionResponse;\n const nativeJson = credentialWithToJSON(publicKeyCredential);\n\n if (nativeJson && 'authenticatorData' in nativeJson.response) {\n return normalizeAuthenticationCredential(nativeJson as PasskeyAuthenticationCredential);\n }\n\n return {\n authenticatorAttachment: normalizeAttachment(publicKeyCredential.authenticatorAttachment),\n clientExtensionResults: clientExtensionResultsToRecord(publicKeyCredential.getClientExtensionResults?.()),\n id: publicKeyCredential.id,\n rawId: encodeBase64Url(publicKeyCredential.rawId),\n response: {\n authenticatorData: encodeBase64Url(response.authenticatorData),\n clientDataJSON: encodeBase64Url(response.clientDataJSON),\n signature: encodeBase64Url(response.signature),\n userHandle: nullableBufferToBase64Url(response.userHandle),\n },\n type: PASSKEY_TYPE,\n };\n}\n\nexport function credentialFromJSON(credential: CredentialJson): PublicKeyCredential {\n const shimCredential = new PasskeyPublicKeyCredential(credential) as unknown as PublicKeyCredential;\n\n if (typeof globalThis.PublicKeyCredential === 'function') {\n Object.setPrototypeOf(shimCredential, globalThis.PublicKeyCredential.prototype);\n }\n\n return shimCredential;\n}\n\nexport function parseCreationOptionsFromJSON(\n options: PasskeyPublicKeyCredentialCreationOptionsJSON,\n): PublicKeyCredentialCreationOptions {\n return browserCreationOptionsFromJSON(normalizeCreationOptionsJSON(options));\n}\n\nexport function parseRequestOptionsFromJSON(\n options: PasskeyPublicKeyCredentialRequestOptionsJSON,\n): PublicKeyCredentialRequestOptions {\n return browserRequestOptionsFromJSON(normalizeRequestOptionsJSON(options));\n}\n\nexport function decodeBase64Url(value: string): ArrayBuffer {\n const bytes = base64UrlToBytes(value);\n return bytes.slice().buffer;\n}\n\nexport function encodeBase64Url(value: BufferLike | null | undefined): string {\n if (typeof value === 'undefined' || value === null) {\n return '';\n }\n\n const bytes = toUint8Array(value);\n let binary = '';\n\n bytes.forEach((byte) => {\n binary += String.fromCharCode(byte);\n });\n\n return btoa(binary).replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=+$/u, '');\n}\n\nexport function resolveOrigin(explicitOrigin?: string, rpId?: string): string | undefined {\n if (explicitOrigin) {\n return explicitOrigin;\n }\n\n if (typeof globalThis.location !== 'undefined' && /^https?:$/u.test(globalThis.location.protocol)) {\n return globalThis.location.origin;\n }\n\n if (rpId) {\n return `https://${rpId}`;\n }\n\n return undefined;\n}\n\nexport function createPasskeyDomException(name: string, message: string): Error {\n if (typeof DOMException !== 'undefined') {\n return new DOMException(message, name);\n }\n\n const error = new Error(message);\n error.name = name;\n return error;\n}\n\nexport function abortIfNeeded(signal?: AbortSignal | null): void {\n if (signal?.aborted) {\n throw createPasskeyDomException('AbortError', 'The passkey request was aborted.');\n }\n}\n\nexport function normalizePluginError(error: unknown): Error {\n if (error instanceof Error) {\n return error;\n }\n\n const message = typeof error === 'object' && error && 'message' in error ? String(error.message) : String(error);\n const name = resolveErrorName(error);\n\n return createPasskeyDomException(name, message);\n}\n\nfunction credentialWithToJSON(credential: PublicKeyCredential): CredentialJson | null {\n const toJSON = (credential as PublicKeyCredential & { toJSON?: () => unknown }).toJSON;\n\n if (typeof toJSON !== 'function') {\n return null;\n }\n\n const json = toJSON();\n\n if (!json || typeof json !== 'object') {\n return null;\n }\n\n const response = (json as { response?: JsonRecord }).response;\n if (!response) {\n return null;\n }\n\n if ('attestationObject' in response) {\n return normalizeRegistrationCredential(json as Partial<PasskeyRegistrationCredential>);\n }\n\n if ('authenticatorData' in response) {\n return normalizeAuthenticationCredential(json as Partial<PasskeyAuthenticationCredential>);\n }\n\n return null;\n}\n\nfunction normalizeRegistrationCredential(\n credential: Partial<PasskeyRegistrationCredential>,\n): PasskeyRegistrationCredential {\n return {\n authenticatorAttachment: normalizeAttachment(credential.authenticatorAttachment),\n clientExtensionResults: credential.clientExtensionResults ?? {},\n id: String(credential.id ?? ''),\n rawId: String(credential.rawId ?? credential.id ?? ''),\n response: normalizeAttestationResponse(credential.response ?? {}),\n type: PASSKEY_TYPE,\n };\n}\n\nfunction normalizeAuthenticationCredential(\n credential: Partial<PasskeyAuthenticationCredential>,\n): PasskeyAuthenticationCredential {\n return {\n authenticatorAttachment: normalizeAttachment(credential.authenticatorAttachment),\n clientExtensionResults: credential.clientExtensionResults ?? {},\n id: String(credential.id ?? ''),\n rawId: String(credential.rawId ?? credential.id ?? ''),\n response: normalizeAssertionResponse(credential.response ?? {}),\n type: PASSKEY_TYPE,\n };\n}\n\nfunction normalizeAttestationResponse(\n response: Partial<PasskeyAuthenticatorAttestationResponseJSON>,\n): PasskeyAuthenticatorAttestationResponseJSON {\n return {\n attestationObject: String(response.attestationObject ?? ''),\n clientDataJSON: String(response.clientDataJSON ?? ''),\n publicKey: response.publicKey,\n publicKeyAlgorithm: response.publicKeyAlgorithm,\n transports: response.transports,\n };\n}\n\nfunction normalizeAssertionResponse(\n response: Partial<PasskeyAuthenticatorAssertionResponseJSON>,\n): PasskeyAuthenticatorAssertionResponseJSON {\n return {\n authenticatorData: String(response.authenticatorData ?? ''),\n clientDataJSON: String(response.clientDataJSON ?? ''),\n signature: String(response.signature ?? ''),\n userHandle: typeof response.userHandle === 'undefined' ? null : response.userHandle,\n };\n}\n\nfunction expectPublicKeyCredential(credential: Credential | null, flow: string): PublicKeyCredential {\n if (!credential || !(credential instanceof PublicKeyCredential)) {\n throw createPasskeyDomException('InvalidStateError', `The browser did not return a ${flow} credential.`);\n }\n\n return credential;\n}\n\nfunction descriptorToJSON(\n descriptor: PublicKeyCredentialDescriptor | PasskeyCredentialDescriptor,\n): PasskeyCredentialDescriptor {\n return {\n id: typeof descriptor.id === 'string' ? descriptor.id : encodeBase64Url(descriptor.id),\n transports: descriptor.transports ? [...descriptor.transports] : undefined,\n type: descriptor.type ?? PASSKEY_TYPE,\n };\n}\n\nfunction jsonDescriptorToBrowser(descriptor: PasskeyCredentialDescriptor): PublicKeyCredentialDescriptor {\n return {\n id: decodeBase64Url(descriptor.id),\n transports: descriptor.transports as AuthenticatorTransport[] | undefined,\n type: descriptor.type ?? PASSKEY_TYPE,\n };\n}\n\nfunction cloneExtensions(\n extensions: AuthenticationExtensionsClientInputs | JsonRecord | undefined,\n): JsonRecord | undefined {\n if (!extensions) {\n return undefined;\n }\n\n return JSON.parse(JSON.stringify(extensions)) as JsonRecord;\n}\n\nfunction nullableBufferToBase64Url(value: ArrayBuffer | null): string | null;\nfunction nullableBufferToBase64Url(value: ArrayBuffer | BufferSource | null | undefined): string | null | undefined;\nfunction nullableBufferToBase64Url(value: ArrayBuffer | BufferSource | null | undefined): string | null | undefined {\n if (typeof value === 'undefined') {\n return undefined;\n }\n\n if (value === null) {\n return null;\n }\n\n return encodeBase64Url(value);\n}\n\nfunction nullableBufferToOptionalBase64Url(value: ArrayBuffer | BufferSource | null | undefined): string | undefined {\n const encoded = nullableBufferToBase64Url(value);\n return encoded ?? undefined;\n}\n\nfunction deriveRpId(origin?: string): string | undefined {\n if (!origin) {\n return undefined;\n }\n\n try {\n return new URL(origin).hostname;\n } catch {\n return undefined;\n }\n}\n\nfunction base64UrlToBytes(value: string): Uint8Array {\n const normalized = value.replace(/-/g, '+').replace(/_/g, '/');\n const padding = normalized.length % 4 === 0 ? '' : '='.repeat(4 - (normalized.length % 4));\n const binary = atob(`${normalized}${padding}`);\n const bytes = new Uint8Array(binary.length);\n\n for (let index = 0; index < binary.length; index += 1) {\n bytes[index] = binary.charCodeAt(index);\n }\n\n return bytes;\n}\n\nfunction toUint8Array(value: BufferLike): Uint8Array {\n if (Array.isArray(value)) {\n return Uint8Array.from(value);\n }\n\n if (ArrayBuffer.isView(value)) {\n return new Uint8Array(value.buffer, value.byteOffset, value.byteLength);\n }\n\n return new Uint8Array(value);\n}\n\nfunction normalizeAttachment(value: string | null | undefined) {\n if (value === 'platform' || value === 'cross-platform') {\n return value;\n }\n\n return undefined;\n}\n\nfunction clientExtensionResultsToRecord(\n value: AuthenticationExtensionsClientOutputs | undefined,\n): Record<string, unknown> {\n if (!value) {\n return {};\n }\n\n return JSON.parse(JSON.stringify(value)) as Record<string, unknown>;\n}\n\nclass PasskeyAuthenticatorAttestationResponse {\n public readonly clientDataJSON: ArrayBuffer;\n public readonly attestationObject: ArrayBuffer;\n\n constructor(private readonly json: PasskeyAuthenticatorAttestationResponseJSON) {\n this.clientDataJSON = decodeBase64Url(json.clientDataJSON);\n this.attestationObject = decodeBase64Url(json.attestationObject);\n }\n\n getPublicKey(): ArrayBuffer | null {\n return this.json.publicKey ? decodeBase64Url(this.json.publicKey) : null;\n }\n\n getPublicKeyAlgorithm(): number {\n return this.json.publicKeyAlgorithm ?? -7;\n }\n\n getTransports(): string[] {\n return this.json.transports ? [...this.json.transports] : [];\n }\n\n toJSON(): PasskeyAuthenticatorAttestationResponseJSON {\n return { ...this.json };\n }\n}\n\nclass PasskeyAuthenticatorAssertionResponse {\n public readonly clientDataJSON: ArrayBuffer;\n public readonly authenticatorData: ArrayBuffer;\n public readonly signature: ArrayBuffer;\n public readonly userHandle: ArrayBuffer | null;\n\n constructor(private readonly json: PasskeyAuthenticatorAssertionResponseJSON) {\n this.clientDataJSON = decodeBase64Url(json.clientDataJSON);\n this.authenticatorData = decodeBase64Url(json.authenticatorData);\n this.signature = decodeBase64Url(json.signature);\n this.userHandle = json.userHandle ? decodeBase64Url(json.userHandle) : null;\n }\n\n toJSON(): PasskeyAuthenticatorAssertionResponseJSON {\n return { ...this.json };\n }\n}\n\nclass PasskeyPublicKeyCredential {\n public readonly id: string;\n public readonly rawId: ArrayBuffer;\n public readonly type: PublicKeyCredentialType = PASSKEY_TYPE;\n public readonly authenticatorAttachment: string | null;\n public readonly response: PasskeyAuthenticatorAttestationResponse | PasskeyAuthenticatorAssertionResponse;\n\n constructor(private readonly json: CredentialJson) {\n this.id = json.id;\n this.rawId = decodeBase64Url(json.rawId);\n this.authenticatorAttachment = json.authenticatorAttachment ?? null;\n this.response =\n 'attestationObject' in json.response\n ? new PasskeyAuthenticatorAttestationResponse(json.response)\n : new PasskeyAuthenticatorAssertionResponse(json.response);\n }\n\n getClientExtensionResults(): AuthenticationExtensionsClientOutputs {\n return (this.json.clientExtensionResults ?? {}) as AuthenticationExtensionsClientOutputs;\n }\n\n toJSON(): CredentialJson {\n return JSON.parse(JSON.stringify(this.json)) as CredentialJson;\n }\n}\n\nfunction resolveErrorName(error: unknown): string {\n if (typeof error === 'object' && error) {\n if ('code' in error && typeof error.code === 'string') {\n return error.code;\n }\n\n if ('data' in error && error.data && typeof error.data === 'object' && 'name' in error.data) {\n const candidate = error.data.name;\n if (typeof candidate === 'string') {\n return candidate;\n }\n }\n }\n\n return 'UnknownError';\n}\n"]}
|