@simplewebauthn/browser 10.0.0 → 11.0.0-alpha3
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/bundle/index.es5.umd.min.js +2 -0
- package/esm/helpers/base64URLStringToBuffer.d.ts +9 -0
- package/esm/helpers/base64URLStringToBuffer.d.ts.map +1 -0
- package/esm/helpers/base64URLStringToBuffer.js +29 -0
- package/esm/helpers/browserSupportsWebAuthn.d.ts +8 -0
- package/esm/helpers/browserSupportsWebAuthn.d.ts.map +1 -0
- package/esm/helpers/browserSupportsWebAuthn.js +11 -0
- package/esm/helpers/browserSupportsWebAuthnAutofill.d.ts +9 -0
- package/esm/helpers/browserSupportsWebAuthnAutofill.d.ts.map +1 -0
- package/esm/helpers/browserSupportsWebAuthnAutofill.js +26 -0
- package/esm/helpers/bufferToBase64URLString.d.ts +8 -0
- package/esm/helpers/bufferToBase64URLString.d.ts.map +1 -0
- package/esm/helpers/bufferToBase64URLString.js +15 -0
- package/esm/helpers/identifyAuthenticationError.d.ts +9 -0
- package/esm/helpers/identifyAuthenticationError.d.ts.map +1 -0
- package/esm/helpers/identifyAuthenticationError.js +61 -0
- package/esm/helpers/identifyRegistrationError.d.ts +9 -0
- package/esm/helpers/identifyRegistrationError.d.ts.map +1 -0
- package/esm/helpers/identifyRegistrationError.js +126 -0
- package/esm/helpers/isValidDomain.d.ts +10 -0
- package/esm/helpers/isValidDomain.d.ts.map +1 -0
- package/esm/helpers/isValidDomain.js +14 -0
- package/esm/helpers/platformAuthenticatorIsAvailable.d.ts +8 -0
- package/esm/helpers/platformAuthenticatorIsAvailable.d.ts.map +1 -0
- package/esm/helpers/platformAuthenticatorIsAvailable.js +13 -0
- package/{dist/types → esm}/helpers/toAuthenticatorAttachment.d.ts +4 -0
- package/esm/helpers/toAuthenticatorAttachment.d.ts.map +1 -0
- package/esm/helpers/toAuthenticatorAttachment.js +13 -0
- package/esm/helpers/toPublicKeyCredentialDescriptor.d.ts +3 -0
- package/esm/helpers/toPublicKeyCredentialDescriptor.d.ts.map +1 -0
- package/esm/helpers/toPublicKeyCredentialDescriptor.js +14 -0
- package/esm/helpers/webAuthnAbortService.d.ts +14 -0
- package/esm/helpers/webAuthnAbortService.d.ts.map +1 -0
- package/esm/helpers/webAuthnAbortService.js +45 -0
- package/{dist/types → esm}/helpers/webAuthnError.d.ts +19 -1
- package/esm/helpers/webAuthnError.d.ts.map +1 -0
- package/esm/helpers/webAuthnError.js +31 -0
- package/esm/index.d.ts +16 -0
- package/esm/index.d.ts.map +1 -0
- package/{dist/types/index.d.ts → esm/index.js} +13 -10
- package/esm/methods/startAuthentication.d.ts +15 -0
- package/esm/methods/startAuthentication.d.ts.map +1 -0
- package/esm/methods/startAuthentication.js +89 -0
- package/esm/methods/startRegistration.d.ts +13 -0
- package/esm/methods/startRegistration.d.ts.map +1 -0
- package/esm/methods/startRegistration.js +115 -0
- package/esm/package.json +3 -0
- package/package.json +24 -29
- package/script/helpers/base64URLStringToBuffer.d.ts +9 -0
- package/script/helpers/base64URLStringToBuffer.d.ts.map +1 -0
- package/script/helpers/base64URLStringToBuffer.js +32 -0
- package/script/helpers/browserSupportsWebAuthn.d.ts +8 -0
- package/script/helpers/browserSupportsWebAuthn.d.ts.map +1 -0
- package/script/helpers/browserSupportsWebAuthn.js +15 -0
- package/script/helpers/browserSupportsWebAuthnAutofill.d.ts +9 -0
- package/script/helpers/browserSupportsWebAuthnAutofill.d.ts.map +1 -0
- package/script/helpers/browserSupportsWebAuthnAutofill.js +30 -0
- package/script/helpers/bufferToBase64URLString.d.ts +8 -0
- package/script/helpers/bufferToBase64URLString.d.ts.map +1 -0
- package/script/helpers/bufferToBase64URLString.js +18 -0
- package/script/helpers/identifyAuthenticationError.d.ts +9 -0
- package/script/helpers/identifyAuthenticationError.d.ts.map +1 -0
- package/script/helpers/identifyAuthenticationError.js +64 -0
- package/script/helpers/identifyRegistrationError.d.ts +9 -0
- package/script/helpers/identifyRegistrationError.d.ts.map +1 -0
- package/script/helpers/identifyRegistrationError.js +129 -0
- package/script/helpers/isValidDomain.d.ts +10 -0
- package/script/helpers/isValidDomain.d.ts.map +1 -0
- package/script/helpers/isValidDomain.js +17 -0
- package/script/helpers/platformAuthenticatorIsAvailable.d.ts +8 -0
- package/script/helpers/platformAuthenticatorIsAvailable.d.ts.map +1 -0
- package/script/helpers/platformAuthenticatorIsAvailable.js +16 -0
- package/script/helpers/toAuthenticatorAttachment.d.ts +6 -0
- package/script/helpers/toAuthenticatorAttachment.d.ts.map +1 -0
- package/script/helpers/toAuthenticatorAttachment.js +16 -0
- package/script/helpers/toPublicKeyCredentialDescriptor.d.ts +3 -0
- package/script/helpers/toPublicKeyCredentialDescriptor.d.ts.map +1 -0
- package/script/helpers/toPublicKeyCredentialDescriptor.js +17 -0
- package/script/helpers/webAuthnAbortService.d.ts +14 -0
- package/script/helpers/webAuthnAbortService.d.ts.map +1 -0
- package/script/helpers/webAuthnAbortService.js +48 -0
- package/script/helpers/webAuthnError.d.ts +28 -0
- package/script/helpers/webAuthnError.d.ts.map +1 -0
- package/script/helpers/webAuthnError.js +35 -0
- package/script/index.d.ts +16 -0
- package/script/index.d.ts.map +1 -0
- package/script/index.js +25 -0
- package/script/methods/startAuthentication.d.ts +15 -0
- package/script/methods/startAuthentication.d.ts.map +1 -0
- package/script/methods/startAuthentication.js +92 -0
- package/script/methods/startRegistration.d.ts +13 -0
- package/script/methods/startRegistration.d.ts.map +1 -0
- package/script/methods/startRegistration.js +118 -0
- package/script/package.json +3 -0
- package/dist/bundle/index.es5.umd.min.js +0 -2
- package/dist/bundle/index.js +0 -384
- package/dist/bundle/index.umd.min.js +0 -2
- package/dist/types/helpers/base64URLStringToBuffer.d.ts +0 -1
- package/dist/types/helpers/browserSupportsWebAuthn.d.ts +0 -1
- package/dist/types/helpers/browserSupportsWebAuthnAutofill.d.ts +0 -1
- package/dist/types/helpers/bufferToBase64URLString.d.ts +0 -1
- package/dist/types/helpers/identifyAuthenticationError.d.ts +0 -5
- package/dist/types/helpers/identifyRegistrationError.d.ts +0 -5
- package/dist/types/helpers/isValidDomain.d.ts +0 -1
- package/dist/types/helpers/platformAuthenticatorIsAvailable.d.ts +0 -1
- package/dist/types/helpers/toPublicKeyCredentialDescriptor.d.ts +0 -2
- package/dist/types/helpers/webAuthnAbortService.d.ts +0 -7
- package/dist/types/methods/startAuthentication.d.ts +0 -2
- package/dist/types/methods/startRegistration.d.ts +0 -2
- package/jest-environment.js +0 -29
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A custom Error used to return a more nuanced error detailing _why_ one of the eight documented
|
|
3
|
+
* errors in the spec was raised after calling `navigator.credentials.create()` or
|
|
4
|
+
* `navigator.credentials.get()`:
|
|
5
|
+
*
|
|
6
|
+
* - `AbortError`
|
|
7
|
+
* - `ConstraintError`
|
|
8
|
+
* - `InvalidStateError`
|
|
9
|
+
* - `NotAllowedError`
|
|
10
|
+
* - `NotSupportedError`
|
|
11
|
+
* - `SecurityError`
|
|
12
|
+
* - `TypeError`
|
|
13
|
+
* - `UnknownError`
|
|
14
|
+
*
|
|
15
|
+
* Error messages were determined through investigation of the spec to determine under which
|
|
16
|
+
* scenarios a given error would be raised.
|
|
17
|
+
*/
|
|
18
|
+
export class WebAuthnError extends Error {
|
|
19
|
+
constructor({ message, code, cause, name, }) {
|
|
20
|
+
// @ts-ignore: help Rollup understand that `cause` is okay to set
|
|
21
|
+
super(message, { cause });
|
|
22
|
+
Object.defineProperty(this, "code", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
this.name = name ?? cause.name;
|
|
29
|
+
this.code = code;
|
|
30
|
+
}
|
|
31
|
+
}
|
package/esm/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module @simplewebauthn/browser
|
|
4
|
+
*/
|
|
5
|
+
import { startRegistration } from './methods/startRegistration.js';
|
|
6
|
+
import { startAuthentication } from './methods/startAuthentication.js';
|
|
7
|
+
import { browserSupportsWebAuthn } from './helpers/browserSupportsWebAuthn.js';
|
|
8
|
+
import { platformAuthenticatorIsAvailable } from './helpers/platformAuthenticatorIsAvailable.js';
|
|
9
|
+
import { browserSupportsWebAuthnAutofill } from './helpers/browserSupportsWebAuthnAutofill.js';
|
|
10
|
+
import { base64URLStringToBuffer } from './helpers/base64URLStringToBuffer.js';
|
|
11
|
+
import { bufferToBase64URLString } from './helpers/bufferToBase64URLString.js';
|
|
12
|
+
import { WebAuthnAbortService } from './helpers/webAuthnAbortService.js';
|
|
13
|
+
import { WebAuthnError } from './helpers/webAuthnError.js';
|
|
14
|
+
export { base64URLStringToBuffer, browserSupportsWebAuthn, browserSupportsWebAuthnAutofill, bufferToBase64URLString, platformAuthenticatorIsAvailable, startAuthentication, startRegistration, WebAuthnAbortService, WebAuthnError, };
|
|
15
|
+
export type { WebAuthnErrorCode } from './helpers/webAuthnError.js';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACjG,OAAO,EAAE,+BAA+B,EAAE,MAAM,8CAA8C,CAAC;AAC/F,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAC;AACzE,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAE3D,OAAO,EACL,uBAAuB,EACvB,uBAAuB,EACvB,+BAA+B,EAC/B,uBAAuB,EACvB,gCAAgC,EAChC,mBAAmB,EACnB,iBAAiB,EACjB,oBAAoB,EACpB,aAAa,GACd,CAAC;AAEF,YAAY,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
1
|
+
/**
|
|
2
|
+
* @packageDocumentation
|
|
3
|
+
* @module @simplewebauthn/browser
|
|
4
|
+
*/
|
|
5
|
+
import { startRegistration } from './methods/startRegistration.js';
|
|
6
|
+
import { startAuthentication } from './methods/startAuthentication.js';
|
|
7
|
+
import { browserSupportsWebAuthn } from './helpers/browserSupportsWebAuthn.js';
|
|
8
|
+
import { platformAuthenticatorIsAvailable } from './helpers/platformAuthenticatorIsAvailable.js';
|
|
9
|
+
import { browserSupportsWebAuthnAutofill } from './helpers/browserSupportsWebAuthnAutofill.js';
|
|
10
|
+
import { base64URLStringToBuffer } from './helpers/base64URLStringToBuffer.js';
|
|
11
|
+
import { bufferToBase64URLString } from './helpers/bufferToBase64URLString.js';
|
|
12
|
+
import { WebAuthnAbortService } from './helpers/webAuthnAbortService.js';
|
|
13
|
+
import { WebAuthnError } from './helpers/webAuthnError.js';
|
|
10
14
|
export { base64URLStringToBuffer, browserSupportsWebAuthn, browserSupportsWebAuthnAutofill, bufferToBase64URLString, platformAuthenticatorIsAvailable, startAuthentication, startRegistration, WebAuthnAbortService, WebAuthnError, };
|
|
11
|
-
export type { WebAuthnErrorCode } from './helpers/webAuthnError';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { AuthenticationResponseJSON, PublicKeyCredentialRequestOptionsJSON } from '@simplewebauthn/types';
|
|
2
|
+
export type StartAuthenticationOpts = {
|
|
3
|
+
optionsJSON: PublicKeyCredentialRequestOptionsJSON;
|
|
4
|
+
useBrowserAutofill?: boolean;
|
|
5
|
+
verifyBrowserAutofillInput?: boolean;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Begin authenticator "login" via WebAuthn assertion
|
|
9
|
+
*
|
|
10
|
+
* @param optionsJSON Output from **@simplewebauthn/server**'s `generateAuthenticationOptions()`
|
|
11
|
+
* @param useBrowserAutofill (Optional) Initialize conditional UI to enable logging in via browser autofill prompts. Defaults to `false`.
|
|
12
|
+
* @param verifyBrowserAutofillInput (Optional) Ensure a suitable `<input>` element is present when `useBrowserAutofill` is `true`. Defaults to `true`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function startAuthentication(options: StartAuthenticationOpts): Promise<AuthenticationResponseJSON>;
|
|
15
|
+
//# sourceMappingURL=startAuthentication.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startAuthentication.d.ts","sourceRoot":"","sources":["../../src/methods/startAuthentication.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAC1B,qCAAqC,EACtC,MAAM,uBAAuB,CAAC;AAW/B,MAAM,MAAM,uBAAuB,GAAG;IACpC,WAAW,EAAE,qCAAqC,CAAC;IACnD,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B,0BAA0B,CAAC,EAAE,OAAO,CAAC;CACtC,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,mBAAmB,CACvC,OAAO,EAAE,uBAAuB,GAC/B,OAAO,CAAC,0BAA0B,CAAC,CAkGrC"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { bufferToBase64URLString } from '../helpers/bufferToBase64URLString.js';
|
|
2
|
+
import { base64URLStringToBuffer } from '../helpers/base64URLStringToBuffer.js';
|
|
3
|
+
import { browserSupportsWebAuthn } from '../helpers/browserSupportsWebAuthn.js';
|
|
4
|
+
import { browserSupportsWebAuthnAutofill } from '../helpers/browserSupportsWebAuthnAutofill.js';
|
|
5
|
+
import { toPublicKeyCredentialDescriptor } from '../helpers/toPublicKeyCredentialDescriptor.js';
|
|
6
|
+
import { identifyAuthenticationError } from '../helpers/identifyAuthenticationError.js';
|
|
7
|
+
import { WebAuthnAbortService } from '../helpers/webAuthnAbortService.js';
|
|
8
|
+
import { toAuthenticatorAttachment } from '../helpers/toAuthenticatorAttachment.js';
|
|
9
|
+
/**
|
|
10
|
+
* Begin authenticator "login" via WebAuthn assertion
|
|
11
|
+
*
|
|
12
|
+
* @param optionsJSON Output from **@simplewebauthn/server**'s `generateAuthenticationOptions()`
|
|
13
|
+
* @param useBrowserAutofill (Optional) Initialize conditional UI to enable logging in via browser autofill prompts. Defaults to `false`.
|
|
14
|
+
* @param verifyBrowserAutofillInput (Optional) Ensure a suitable `<input>` element is present when `useBrowserAutofill` is `true`. Defaults to `true`.
|
|
15
|
+
*/
|
|
16
|
+
export async function startAuthentication(options) {
|
|
17
|
+
const { optionsJSON, useBrowserAutofill = false, verifyBrowserAutofillInput = true, } = options;
|
|
18
|
+
if (!browserSupportsWebAuthn()) {
|
|
19
|
+
throw new Error('WebAuthn is not supported in this browser');
|
|
20
|
+
}
|
|
21
|
+
// We need to avoid passing empty array to avoid blocking retrieval
|
|
22
|
+
// of public key
|
|
23
|
+
let allowCredentials;
|
|
24
|
+
if (optionsJSON.allowCredentials?.length !== 0) {
|
|
25
|
+
allowCredentials = optionsJSON.allowCredentials?.map(toPublicKeyCredentialDescriptor);
|
|
26
|
+
}
|
|
27
|
+
// We need to convert some values to Uint8Arrays before passing the credentials to the navigator
|
|
28
|
+
const publicKey = {
|
|
29
|
+
...optionsJSON,
|
|
30
|
+
challenge: base64URLStringToBuffer(optionsJSON.challenge),
|
|
31
|
+
allowCredentials,
|
|
32
|
+
};
|
|
33
|
+
// Prepare options for `.get()`
|
|
34
|
+
const getOptions = {};
|
|
35
|
+
/**
|
|
36
|
+
* Set up the page to prompt the user to select a credential for authentication via the browser's
|
|
37
|
+
* input autofill mechanism.
|
|
38
|
+
*/
|
|
39
|
+
if (useBrowserAutofill) {
|
|
40
|
+
if (!(await browserSupportsWebAuthnAutofill())) {
|
|
41
|
+
throw Error('Browser does not support WebAuthn autofill');
|
|
42
|
+
}
|
|
43
|
+
// Check for an <input> with "webauthn" in its `autocomplete` attribute
|
|
44
|
+
const eligibleInputs = document.querySelectorAll("input[autocomplete$='webauthn']");
|
|
45
|
+
// WebAuthn autofill requires at least one valid input
|
|
46
|
+
if (eligibleInputs.length < 1 && verifyBrowserAutofillInput) {
|
|
47
|
+
throw Error('No <input> with "webauthn" as the only or last value in its `autocomplete` attribute was detected');
|
|
48
|
+
}
|
|
49
|
+
// `CredentialMediationRequirement` doesn't know about "conditional" yet as of
|
|
50
|
+
// typescript@4.6.3
|
|
51
|
+
getOptions.mediation = 'conditional';
|
|
52
|
+
// Conditional UI requires an empty allow list
|
|
53
|
+
publicKey.allowCredentials = [];
|
|
54
|
+
}
|
|
55
|
+
// Finalize options
|
|
56
|
+
getOptions.publicKey = publicKey;
|
|
57
|
+
// Set up the ability to cancel this request if the user attempts another
|
|
58
|
+
getOptions.signal = WebAuthnAbortService.createNewAbortSignal();
|
|
59
|
+
// Wait for the user to complete assertion
|
|
60
|
+
let credential;
|
|
61
|
+
try {
|
|
62
|
+
credential = (await navigator.credentials.get(getOptions));
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
throw identifyAuthenticationError({ error: err, options: getOptions });
|
|
66
|
+
}
|
|
67
|
+
if (!credential) {
|
|
68
|
+
throw new Error('Authentication was not completed');
|
|
69
|
+
}
|
|
70
|
+
const { id, rawId, response, type } = credential;
|
|
71
|
+
let userHandle = undefined;
|
|
72
|
+
if (response.userHandle) {
|
|
73
|
+
userHandle = bufferToBase64URLString(response.userHandle);
|
|
74
|
+
}
|
|
75
|
+
// Convert values to base64 to make it easier to send back to the server
|
|
76
|
+
return {
|
|
77
|
+
id,
|
|
78
|
+
rawId: bufferToBase64URLString(rawId),
|
|
79
|
+
response: {
|
|
80
|
+
authenticatorData: bufferToBase64URLString(response.authenticatorData),
|
|
81
|
+
clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
|
|
82
|
+
signature: bufferToBase64URLString(response.signature),
|
|
83
|
+
userHandle,
|
|
84
|
+
},
|
|
85
|
+
type,
|
|
86
|
+
clientExtensionResults: credential.getClientExtensionResults(),
|
|
87
|
+
authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { PublicKeyCredentialCreationOptionsJSON, RegistrationResponseJSON } from '@simplewebauthn/types';
|
|
2
|
+
export type StartRegistrationOpts = {
|
|
3
|
+
optionsJSON: PublicKeyCredentialCreationOptionsJSON;
|
|
4
|
+
useAutoRegister?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Begin authenticator "registration" via WebAuthn attestation
|
|
8
|
+
*
|
|
9
|
+
* @param optionsJSON Output from **@simplewebauthn/server**'s `generateRegistrationOptions()`
|
|
10
|
+
* @param useAutoRegister (Optional) Try to silently create a passkey with the password manager that the user just signed in with. Defaults to `false`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function startRegistration(options: StartRegistrationOpts): Promise<RegistrationResponseJSON>;
|
|
13
|
+
//# sourceMappingURL=startRegistration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"startRegistration.d.ts","sourceRoot":"","sources":["../../src/methods/startRegistration.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sCAAsC,EAEtC,wBAAwB,EACzB,MAAM,uBAAuB,CAAC;AAU/B,MAAM,MAAM,qBAAqB,GAAG;IAClC,WAAW,EAAE,sCAAsC,CAAC;IACpD,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CA6GnC"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { bufferToBase64URLString } from '../helpers/bufferToBase64URLString.js';
|
|
2
|
+
import { base64URLStringToBuffer } from '../helpers/base64URLStringToBuffer.js';
|
|
3
|
+
import { browserSupportsWebAuthn } from '../helpers/browserSupportsWebAuthn.js';
|
|
4
|
+
import { toPublicKeyCredentialDescriptor } from '../helpers/toPublicKeyCredentialDescriptor.js';
|
|
5
|
+
import { identifyRegistrationError } from '../helpers/identifyRegistrationError.js';
|
|
6
|
+
import { WebAuthnAbortService } from '../helpers/webAuthnAbortService.js';
|
|
7
|
+
import { toAuthenticatorAttachment } from '../helpers/toAuthenticatorAttachment.js';
|
|
8
|
+
/**
|
|
9
|
+
* Begin authenticator "registration" via WebAuthn attestation
|
|
10
|
+
*
|
|
11
|
+
* @param optionsJSON Output from **@simplewebauthn/server**'s `generateRegistrationOptions()`
|
|
12
|
+
* @param useAutoRegister (Optional) Try to silently create a passkey with the password manager that the user just signed in with. Defaults to `false`.
|
|
13
|
+
*/
|
|
14
|
+
export async function startRegistration(options) {
|
|
15
|
+
const { optionsJSON, useAutoRegister = false } = options;
|
|
16
|
+
if (!browserSupportsWebAuthn()) {
|
|
17
|
+
throw new Error('WebAuthn is not supported in this browser');
|
|
18
|
+
}
|
|
19
|
+
// We need to convert some values to Uint8Arrays before passing the credentials to the navigator
|
|
20
|
+
const publicKey = {
|
|
21
|
+
...optionsJSON,
|
|
22
|
+
challenge: base64URLStringToBuffer(optionsJSON.challenge),
|
|
23
|
+
user: {
|
|
24
|
+
...optionsJSON.user,
|
|
25
|
+
id: base64URLStringToBuffer(optionsJSON.user.id),
|
|
26
|
+
},
|
|
27
|
+
excludeCredentials: optionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
|
|
28
|
+
};
|
|
29
|
+
// Prepare options for `.create()`
|
|
30
|
+
const createOptions = {};
|
|
31
|
+
/**
|
|
32
|
+
* Try to use conditional create to register a passkey for the user with the password manager
|
|
33
|
+
* the user just used to authenticate with. The user won't be shown any prominent UI by the
|
|
34
|
+
* browser.
|
|
35
|
+
*/
|
|
36
|
+
if (useAutoRegister) {
|
|
37
|
+
// @ts-ignore: `mediation` doesn't yet exist on CredentialCreationOptions but it's possible as of Sept 2024
|
|
38
|
+
createOptions.mediation = 'conditional';
|
|
39
|
+
}
|
|
40
|
+
// Finalize options
|
|
41
|
+
createOptions.publicKey = publicKey;
|
|
42
|
+
// Set up the ability to cancel this request if the user attempts another
|
|
43
|
+
createOptions.signal = WebAuthnAbortService.createNewAbortSignal();
|
|
44
|
+
// Wait for the user to complete attestation
|
|
45
|
+
let credential;
|
|
46
|
+
try {
|
|
47
|
+
credential = (await navigator.credentials.create(createOptions));
|
|
48
|
+
}
|
|
49
|
+
catch (err) {
|
|
50
|
+
throw identifyRegistrationError({ error: err, options: createOptions });
|
|
51
|
+
}
|
|
52
|
+
if (!credential) {
|
|
53
|
+
throw new Error('Registration was not completed');
|
|
54
|
+
}
|
|
55
|
+
const { id, rawId, response, type } = credential;
|
|
56
|
+
// Continue to play it safe with `getTransports()` for now, even when L3 types say it's required
|
|
57
|
+
let transports = undefined;
|
|
58
|
+
if (typeof response.getTransports === 'function') {
|
|
59
|
+
transports = response.getTransports();
|
|
60
|
+
}
|
|
61
|
+
// L3 says this is required, but browser and webview support are still not guaranteed.
|
|
62
|
+
let responsePublicKeyAlgorithm = undefined;
|
|
63
|
+
if (typeof response.getPublicKeyAlgorithm === 'function') {
|
|
64
|
+
try {
|
|
65
|
+
responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
warnOnBrokenImplementation('getPublicKeyAlgorithm()', error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
let responsePublicKey = undefined;
|
|
72
|
+
if (typeof response.getPublicKey === 'function') {
|
|
73
|
+
try {
|
|
74
|
+
const _publicKey = response.getPublicKey();
|
|
75
|
+
if (_publicKey !== null) {
|
|
76
|
+
responsePublicKey = bufferToBase64URLString(_publicKey);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
warnOnBrokenImplementation('getPublicKey()', error);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// L3 says this is required, but browser and webview support are still not guaranteed.
|
|
84
|
+
let responseAuthenticatorData;
|
|
85
|
+
if (typeof response.getAuthenticatorData === 'function') {
|
|
86
|
+
try {
|
|
87
|
+
responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
warnOnBrokenImplementation('getAuthenticatorData()', error);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
id,
|
|
95
|
+
rawId: bufferToBase64URLString(rawId),
|
|
96
|
+
response: {
|
|
97
|
+
attestationObject: bufferToBase64URLString(response.attestationObject),
|
|
98
|
+
clientDataJSON: bufferToBase64URLString(response.clientDataJSON),
|
|
99
|
+
transports,
|
|
100
|
+
publicKeyAlgorithm: responsePublicKeyAlgorithm,
|
|
101
|
+
publicKey: responsePublicKey,
|
|
102
|
+
authenticatorData: responseAuthenticatorData,
|
|
103
|
+
},
|
|
104
|
+
type,
|
|
105
|
+
clientExtensionResults: credential.getClientExtensionResults(),
|
|
106
|
+
authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Visibly warn when we detect an issue related to a passkey provider intercepting WebAuthn API
|
|
111
|
+
* calls
|
|
112
|
+
*/
|
|
113
|
+
function warnOnBrokenImplementation(methodName, cause) {
|
|
114
|
+
console.warn(`The browser extension that intercepted this WebAuthn API call incorrectly implemented ${methodName}. You should report this error to them.\n`, cause);
|
|
115
|
+
}
|
package/esm/package.json
ADDED
package/package.json
CHANGED
|
@@ -1,46 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplewebauthn/browser",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "11.0.0-alpha3",
|
|
4
4
|
"description": "SimpleWebAuthn for Browsers",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
"keywords": [
|
|
6
|
+
"typescript",
|
|
7
|
+
"webauthn",
|
|
8
|
+
"passkeys",
|
|
9
|
+
"fido",
|
|
10
|
+
"umd"
|
|
11
|
+
],
|
|
8
12
|
"author": "Matthew Miller <matthew@millerti.me>",
|
|
9
|
-
"
|
|
13
|
+
"homepage": "https://github.com/MasterKale/SimpleWebAuthn/tree/master/packages/browser#readme",
|
|
10
14
|
"repository": {
|
|
11
15
|
"type": "git",
|
|
12
16
|
"url": "git+https://github.com/MasterKale/SimpleWebAuthn.git",
|
|
13
17
|
"directory": "packages/browser"
|
|
14
18
|
},
|
|
15
|
-
"
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/MasterKale/SimpleWebAuthn/issues"
|
|
22
|
+
},
|
|
23
|
+
"main": "./script/index.js",
|
|
24
|
+
"module": "./esm/index.js",
|
|
25
|
+
"exports": {
|
|
26
|
+
".": {
|
|
27
|
+
"import": "./esm/index.js",
|
|
28
|
+
"require": "./script/index.js"
|
|
29
|
+
}
|
|
30
|
+
},
|
|
16
31
|
"publishConfig": {
|
|
17
32
|
"access": "public"
|
|
18
33
|
},
|
|
19
|
-
"keywords": [
|
|
20
|
-
"typescript",
|
|
21
|
-
"webauthn",
|
|
22
|
-
"passkeys",
|
|
23
|
-
"fido",
|
|
24
|
-
"umd"
|
|
25
|
-
],
|
|
26
34
|
"dependencies": {
|
|
27
|
-
"@simplewebauthn/types": "^
|
|
35
|
+
"@simplewebauthn/types": "^11.0.0-alpha3"
|
|
28
36
|
},
|
|
29
37
|
"devDependencies": {
|
|
30
|
-
"@
|
|
31
|
-
"@rollup/plugin-terser": "^0.4.3",
|
|
32
|
-
"@rollup/plugin-typescript": "^8.2.1",
|
|
33
|
-
"rollup": "^2.52.1",
|
|
34
|
-
"rollup-plugin-version-injector": "^1.3.3",
|
|
35
|
-
"tslib": "^2.6.2"
|
|
38
|
+
"@types/node": "^20.9.0"
|
|
36
39
|
},
|
|
37
|
-
"
|
|
38
|
-
"gitHead": "ba039fdd5fdff87f78d3bd246e9bea5f7aa39ccb",
|
|
39
|
-
"scripts": {
|
|
40
|
-
"build": "rimraf dist && rollup -c",
|
|
41
|
-
"test": "jest",
|
|
42
|
-
"test:watch": "jest --watch",
|
|
43
|
-
"test:coverage": "npm test -- --coverage",
|
|
44
|
-
"prepublish": "npm run build"
|
|
45
|
-
}
|
|
40
|
+
"_generatedBy": "dnt@dev"
|
|
46
41
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert from a Base64URL-encoded string to an Array Buffer. Best used when converting a
|
|
3
|
+
* credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
|
|
4
|
+
* excludeCredentials
|
|
5
|
+
*
|
|
6
|
+
* Helper method to compliment `bufferToBase64URLString`
|
|
7
|
+
*/
|
|
8
|
+
export declare function base64URLStringToBuffer(base64URLString: string): ArrayBuffer;
|
|
9
|
+
//# sourceMappingURL=base64URLStringToBuffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base64URLStringToBuffer.d.ts","sourceRoot":"","sources":["../../src/helpers/base64URLStringToBuffer.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,wBAAgB,uBAAuB,CAAC,eAAe,EAAE,MAAM,GAAG,WAAW,CAyB5E"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.base64URLStringToBuffer = base64URLStringToBuffer;
|
|
4
|
+
/**
|
|
5
|
+
* Convert from a Base64URL-encoded string to an Array Buffer. Best used when converting a
|
|
6
|
+
* credential ID from a JSON string to an ArrayBuffer, like in allowCredentials or
|
|
7
|
+
* excludeCredentials
|
|
8
|
+
*
|
|
9
|
+
* Helper method to compliment `bufferToBase64URLString`
|
|
10
|
+
*/
|
|
11
|
+
function base64URLStringToBuffer(base64URLString) {
|
|
12
|
+
// Convert from Base64URL to Base64
|
|
13
|
+
const base64 = base64URLString.replace(/-/g, '+').replace(/_/g, '/');
|
|
14
|
+
/**
|
|
15
|
+
* Pad with '=' until it's a multiple of four
|
|
16
|
+
* (4 - (85 % 4 = 1) = 3) % 4 = 3 padding
|
|
17
|
+
* (4 - (86 % 4 = 2) = 2) % 4 = 2 padding
|
|
18
|
+
* (4 - (87 % 4 = 3) = 1) % 4 = 1 padding
|
|
19
|
+
* (4 - (88 % 4 = 0) = 4) % 4 = 0 padding
|
|
20
|
+
*/
|
|
21
|
+
const padLength = (4 - (base64.length % 4)) % 4;
|
|
22
|
+
const padded = base64.padEnd(base64.length + padLength, '=');
|
|
23
|
+
// Convert to a binary string
|
|
24
|
+
const binary = atob(padded);
|
|
25
|
+
// Convert binary string to buffer
|
|
26
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
27
|
+
const bytes = new Uint8Array(buffer);
|
|
28
|
+
for (let i = 0; i < binary.length; i++) {
|
|
29
|
+
bytes[i] = binary.charCodeAt(i);
|
|
30
|
+
}
|
|
31
|
+
return buffer;
|
|
32
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determine if the browser is capable of Webauthn
|
|
3
|
+
*/
|
|
4
|
+
export declare function browserSupportsWebAuthn(): boolean;
|
|
5
|
+
export declare const _browserSupportsWebAuthnInternals: {
|
|
6
|
+
stubThis: (value: boolean) => boolean;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=browserSupportsWebAuthn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserSupportsWebAuthn.d.ts","sourceRoot":"","sources":["../../src/helpers/browserSupportsWebAuthn.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,wBAAgB,uBAAuB,IAAI,OAAO,CAKjD;AAGD,eAAO,MAAM,iCAAiC;sBAC1B,OAAO;CAC1B,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._browserSupportsWebAuthnInternals = void 0;
|
|
4
|
+
exports.browserSupportsWebAuthn = browserSupportsWebAuthn;
|
|
5
|
+
/**
|
|
6
|
+
* Determine if the browser is capable of Webauthn
|
|
7
|
+
*/
|
|
8
|
+
function browserSupportsWebAuthn() {
|
|
9
|
+
return exports._browserSupportsWebAuthnInternals.stubThis(globalThis?.PublicKeyCredential !== undefined &&
|
|
10
|
+
typeof globalThis.PublicKeyCredential === 'function');
|
|
11
|
+
}
|
|
12
|
+
// Make it possible to stub the return value during testing
|
|
13
|
+
exports._browserSupportsWebAuthnInternals = {
|
|
14
|
+
stubThis: (value) => value,
|
|
15
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Determine if the browser supports conditional UI, so that WebAuthn credentials can
|
|
3
|
+
* be shown to the user in the browser's typical password autofill popup.
|
|
4
|
+
*/
|
|
5
|
+
export declare function browserSupportsWebAuthnAutofill(): Promise<boolean>;
|
|
6
|
+
export declare const _browserSupportsWebAuthnAutofillInternals: {
|
|
7
|
+
stubThis: (value: Promise<boolean>) => Promise<boolean>;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=browserSupportsWebAuthnAutofill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browserSupportsWebAuthnAutofill.d.ts","sourceRoot":"","sources":["../../src/helpers/browserSupportsWebAuthnAutofill.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,wBAAgB,+BAA+B,IAAI,OAAO,CAAC,OAAO,CAAC,CAyBlE;AAGD,eAAO,MAAM,yCAAyC;sBAClC,OAAO,CAAC,OAAO,CAAC;CACnC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports._browserSupportsWebAuthnAutofillInternals = void 0;
|
|
4
|
+
exports.browserSupportsWebAuthnAutofill = browserSupportsWebAuthnAutofill;
|
|
5
|
+
const browserSupportsWebAuthn_js_1 = require("./browserSupportsWebAuthn.js");
|
|
6
|
+
/**
|
|
7
|
+
* Determine if the browser supports conditional UI, so that WebAuthn credentials can
|
|
8
|
+
* be shown to the user in the browser's typical password autofill popup.
|
|
9
|
+
*/
|
|
10
|
+
function browserSupportsWebAuthnAutofill() {
|
|
11
|
+
if (!(0, browserSupportsWebAuthn_js_1.browserSupportsWebAuthn)()) {
|
|
12
|
+
return exports._browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* I don't like the `as unknown` here but there's a `declare var PublicKeyCredential` in
|
|
16
|
+
* TS' DOM lib that's making it difficult for me to just go `as PublicKeyCredentialFuture` as I
|
|
17
|
+
* want. I think I'm fine with this for now since it's _supposed_ to be temporary, until TS types
|
|
18
|
+
* have a chance to catch up.
|
|
19
|
+
*/
|
|
20
|
+
const globalPublicKeyCredential = globalThis
|
|
21
|
+
.PublicKeyCredential;
|
|
22
|
+
if (globalPublicKeyCredential?.isConditionalMediationAvailable === undefined) {
|
|
23
|
+
return exports._browserSupportsWebAuthnAutofillInternals.stubThis(new Promise((resolve) => resolve(false)));
|
|
24
|
+
}
|
|
25
|
+
return exports._browserSupportsWebAuthnAutofillInternals.stubThis(globalPublicKeyCredential.isConditionalMediationAvailable());
|
|
26
|
+
}
|
|
27
|
+
// Make it possible to stub the return value during testing
|
|
28
|
+
exports._browserSupportsWebAuthnAutofillInternals = {
|
|
29
|
+
stubThis: (value) => value,
|
|
30
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert the given array buffer into a Base64URL-encoded string. Ideal for converting various
|
|
3
|
+
* credential response ArrayBuffers to string for sending back to the server as JSON.
|
|
4
|
+
*
|
|
5
|
+
* Helper method to compliment `base64URLStringToBuffer`
|
|
6
|
+
*/
|
|
7
|
+
export declare function bufferToBase64URLString(buffer: ArrayBuffer): string;
|
|
8
|
+
//# sourceMappingURL=bufferToBase64URLString.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bufferToBase64URLString.d.ts","sourceRoot":"","sources":["../../src/helpers/bufferToBase64URLString.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,WAAW,GAAG,MAAM,CAWnE"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.bufferToBase64URLString = bufferToBase64URLString;
|
|
4
|
+
/**
|
|
5
|
+
* Convert the given array buffer into a Base64URL-encoded string. Ideal for converting various
|
|
6
|
+
* credential response ArrayBuffers to string for sending back to the server as JSON.
|
|
7
|
+
*
|
|
8
|
+
* Helper method to compliment `base64URLStringToBuffer`
|
|
9
|
+
*/
|
|
10
|
+
function bufferToBase64URLString(buffer) {
|
|
11
|
+
const bytes = new Uint8Array(buffer);
|
|
12
|
+
let str = '';
|
|
13
|
+
for (const charCode of bytes) {
|
|
14
|
+
str += String.fromCharCode(charCode);
|
|
15
|
+
}
|
|
16
|
+
const base64String = btoa(str);
|
|
17
|
+
return base64String.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
18
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WebAuthnError } from './webAuthnError.js';
|
|
2
|
+
/**
|
|
3
|
+
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
|
|
4
|
+
*/
|
|
5
|
+
export declare function identifyAuthenticationError({ error, options, }: {
|
|
6
|
+
error: Error;
|
|
7
|
+
options: CredentialRequestOptions;
|
|
8
|
+
}): WebAuthnError | Error;
|
|
9
|
+
//# sourceMappingURL=identifyAuthenticationError.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifyAuthenticationError.d.ts","sourceRoot":"","sources":["../../src/helpers/identifyAuthenticationError.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,EAC1C,KAAK,EACL,OAAO,GACR,EAAE;IACD,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,wBAAwB,CAAC;CACnC,GAAG,aAAa,GAAG,KAAK,CAuDxB"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.identifyAuthenticationError = identifyAuthenticationError;
|
|
4
|
+
const isValidDomain_js_1 = require("./isValidDomain.js");
|
|
5
|
+
const webAuthnError_js_1 = require("./webAuthnError.js");
|
|
6
|
+
/**
|
|
7
|
+
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
|
|
8
|
+
*/
|
|
9
|
+
function identifyAuthenticationError({ error, options, }) {
|
|
10
|
+
const { publicKey } = options;
|
|
11
|
+
if (!publicKey) {
|
|
12
|
+
throw Error('options was missing required publicKey property');
|
|
13
|
+
}
|
|
14
|
+
if (error.name === 'AbortError') {
|
|
15
|
+
if (options.signal instanceof AbortSignal) {
|
|
16
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
|
|
17
|
+
return new webAuthnError_js_1.WebAuthnError({
|
|
18
|
+
message: 'Authentication ceremony was sent an abort signal',
|
|
19
|
+
code: 'ERROR_CEREMONY_ABORTED',
|
|
20
|
+
cause: error,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
else if (error.name === 'NotAllowedError') {
|
|
25
|
+
/**
|
|
26
|
+
* Pass the error directly through. Platforms are overloading this error beyond what the spec
|
|
27
|
+
* defines and we don't want to overwrite potentially useful error messages.
|
|
28
|
+
*/
|
|
29
|
+
return new webAuthnError_js_1.WebAuthnError({
|
|
30
|
+
message: error.message,
|
|
31
|
+
code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY',
|
|
32
|
+
cause: error,
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
else if (error.name === 'SecurityError') {
|
|
36
|
+
const effectiveDomain = globalThis.location.hostname;
|
|
37
|
+
if (!(0, isValidDomain_js_1.isValidDomain)(effectiveDomain)) {
|
|
38
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 5)
|
|
39
|
+
return new webAuthnError_js_1.WebAuthnError({
|
|
40
|
+
message: `${globalThis.location.hostname} is an invalid domain`,
|
|
41
|
+
code: 'ERROR_INVALID_DOMAIN',
|
|
42
|
+
cause: error,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
else if (publicKey.rpId !== effectiveDomain) {
|
|
46
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
|
|
47
|
+
return new webAuthnError_js_1.WebAuthnError({
|
|
48
|
+
message: `The RP ID "${publicKey.rpId}" is invalid for this domain`,
|
|
49
|
+
code: 'ERROR_INVALID_RP_ID',
|
|
50
|
+
cause: error,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (error.name === 'UnknownError') {
|
|
55
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
|
|
56
|
+
// https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
|
|
57
|
+
return new webAuthnError_js_1.WebAuthnError({
|
|
58
|
+
message: 'The authenticator was unable to process the specified options, or could not create a new assertion signature',
|
|
59
|
+
code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR',
|
|
60
|
+
cause: error,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
return error;
|
|
64
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WebAuthnError } from './webAuthnError.js';
|
|
2
|
+
/**
|
|
3
|
+
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`
|
|
4
|
+
*/
|
|
5
|
+
export declare function identifyRegistrationError({ error, options, }: {
|
|
6
|
+
error: Error;
|
|
7
|
+
options: CredentialCreationOptions;
|
|
8
|
+
}): WebAuthnError | Error;
|
|
9
|
+
//# sourceMappingURL=identifyRegistrationError.d.ts.map
|