summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/browser/src/helpers/identifyAuthenticationError.ts19
-rw-r--r--packages/browser/src/helpers/identifyRegistrationError.ts28
-rw-r--r--packages/browser/src/helpers/isValidDomain.ts3
-rw-r--r--packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts3
-rw-r--r--packages/browser/src/methods/startRegistration.test.ts6
-rw-r--r--packages/browser/src/methods/startRegistration.ts2
6 files changed, 36 insertions, 25 deletions
diff --git a/packages/browser/src/helpers/identifyAuthenticationError.ts b/packages/browser/src/helpers/identifyAuthenticationError.ts
index bf88628..7f9bd82 100644
--- a/packages/browser/src/helpers/identifyAuthenticationError.ts
+++ b/packages/browser/src/helpers/identifyAuthenticationError.ts
@@ -1,7 +1,6 @@
import { isValidDomain } from './isValidDomain';
import { WebAuthnError } from './structs';
-
/**
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.get()`
*/
@@ -9,8 +8,8 @@ export function identifyAuthenticationError({
error,
options,
}: {
- error: Error,
- options: CredentialRequestOptions,
+ error: Error;
+ options: CredentialRequestOptions;
}): WebAuthnError | Error {
const { publicKey } = options;
@@ -19,7 +18,7 @@ export function identifyAuthenticationError({
}
if (error.name === 'AbortError') {
- if (options.signal === (new AbortController()).signal) {
+ if (options.signal === new AbortController().signal) {
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
return new WebAuthnError('Authentication ceremony was sent an abort signal (AbortError)');
}
@@ -28,13 +27,15 @@ export function identifyAuthenticationError({
// https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 17)
// https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 6)
return new WebAuthnError(
- 'No available authenticator recognized any of the allowed credentials (NotAllowedError)'
+ 'No available authenticator recognized any of the allowed credentials (NotAllowedError)',
);
}
// https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 18)
// https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 7)
- return new WebAuthnError('User clicked cancel, or the authentication ceremony timed out (NotAllowedError)');
+ return new WebAuthnError(
+ 'User clicked cancel, or the authentication ceremony timed out (NotAllowedError)',
+ );
} else if (error.name === 'SecurityError') {
const effectiveDomain = window.location.hostname;
if (!isValidDomain(effectiveDomain)) {
@@ -42,13 +43,15 @@ export function identifyAuthenticationError({
return new WebAuthnError(`${window.location.hostname} is an invalid domain (SecurityError)`);
} else if (publicKey.rpId !== effectiveDomain) {
// https://www.w3.org/TR/webauthn-2/#sctn-discover-from-external-source (Step 6)
- return new WebAuthnError(`The RP ID "${publicKey.rpId}" is invalid for this domain (SecurityError)`);
+ return new WebAuthnError(
+ `The RP ID "${publicKey.rpId}" is invalid for this domain (SecurityError)`,
+ );
}
} else if (error.name === 'UnknownError') {
// https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 1)
// https://www.w3.org/TR/webauthn-2/#sctn-op-get-assertion (Step 12)
return new WebAuthnError(
- 'The authenticator was unable to process the specified options, or could not create a new assertion signature (UnknownError)'
+ 'The authenticator was unable to process the specified options, or could not create a new assertion signature (UnknownError)',
);
}
diff --git a/packages/browser/src/helpers/identifyRegistrationError.ts b/packages/browser/src/helpers/identifyRegistrationError.ts
index 75d6740..544953b 100644
--- a/packages/browser/src/helpers/identifyRegistrationError.ts
+++ b/packages/browser/src/helpers/identifyRegistrationError.ts
@@ -1,13 +1,15 @@
import { isValidDomain } from './isValidDomain';
import { WebAuthnError } from './structs';
-
/**
* Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()`
*/
-export function identifyRegistrationError({ error, options }: {
- error: Error,
- options: CredentialCreationOptions,
+export function identifyRegistrationError({
+ error,
+ options,
+}: {
+ error: Error;
+ options: CredentialCreationOptions;
}): WebAuthnError | Error {
const { publicKey } = options;
@@ -16,7 +18,7 @@ export function identifyRegistrationError({ error, options }: {
}
if (error.name === 'AbortError') {
- if (options.signal === (new AbortController()).signal) {
+ if (options.signal === new AbortController().signal) {
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16)
return new WebAuthnError('Registration ceremony was sent an abort signal');
}
@@ -39,15 +41,19 @@ export function identifyRegistrationError({ error, options }: {
} else if (error.name === 'NotAllowedError') {
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20)
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 21)
- return new WebAuthnError('User clicked cancel, or the registration ceremony timed out (NotAllowedError)');
+ return new WebAuthnError(
+ 'User clicked cancel, or the registration ceremony timed out (NotAllowedError)',
+ );
} else if (error.name === 'NotSupportedError') {
const validPubKeyCredParams = publicKey.pubKeyCredParams.filter(
- (param) => param.type === 'public-key',
+ param => param.type === 'public-key',
);
if (validPubKeyCredParams.length === 0) {
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 10)
- return new WebAuthnError('No entry in pubKeyCredParams was of type "public-key" (NotSupportedError)');
+ return new WebAuthnError(
+ 'No entry in pubKeyCredParams was of type "public-key" (NotSupportedError)',
+ );
}
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2)
@@ -61,7 +67,9 @@ export function identifyRegistrationError({ error, options }: {
return new WebAuthnError(`${window.location.hostname} is an invalid domain (SecurityError)`);
} else if (publicKey.rp.id !== effectiveDomain) {
// https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8)
- return new WebAuthnError(`The RP ID "${publicKey.rp.id}" is invalid for this domain (SecurityError)`);
+ return new WebAuthnError(
+ `The RP ID "${publicKey.rp.id}" is invalid for this domain (SecurityError)`,
+ );
}
} else if (error.name === 'TypeError') {
if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) {
@@ -72,7 +80,7 @@ export function identifyRegistrationError({ error, options }: {
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 1)
// https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 8)
return new WebAuthnError(
- 'The authenticator was unable to process the specified options, or could not create a new credential (UnknownError)'
+ 'The authenticator was unable to process the specified options, or could not create a new credential (UnknownError)',
);
}
diff --git a/packages/browser/src/helpers/isValidDomain.ts b/packages/browser/src/helpers/isValidDomain.ts
index 2eb146f..4d2eedd 100644
--- a/packages/browser/src/helpers/isValidDomain.ts
+++ b/packages/browser/src/helpers/isValidDomain.ts
@@ -9,7 +9,6 @@
export function isValidDomain(hostname: string): boolean {
return (
// Consider localhost valid as well since it's okay wrt Secure Contexts
- hostname === 'localhost'
- || /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname)
+ hostname === 'localhost' || /^([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,}$/i.test(hostname)
);
}
diff --git a/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts b/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts
index e8e53c7..3e0b65b 100644
--- a/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts
+++ b/packages/browser/src/helpers/platformAuthenticatorIsAvailable.test.ts
@@ -7,7 +7,8 @@ beforeEach(() => {
// @ts-ignore 2741
window.PublicKeyCredential = jest.fn().mockReturnValue(() => {});
- window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable = mockIsUVPAA.mockResolvedValue(true);
+ window.PublicKeyCredential.isUserVerifyingPlatformAuthenticatorAvailable =
+ mockIsUVPAA.mockResolvedValue(true);
});
test('should return true when platform authenticator is available', async () => {
diff --git a/packages/browser/src/methods/startRegistration.test.ts b/packages/browser/src/methods/startRegistration.test.ts
index 683bae8..78b0157 100644
--- a/packages/browser/src/methods/startRegistration.test.ts
+++ b/packages/browser/src/methods/startRegistration.test.ts
@@ -203,7 +203,7 @@ describe('WebAuthnError', () => {
authenticatorSelection: {
residentKey: 'required',
requireResidentKey: true,
- }
+ },
};
const rejected = await expect(startRegistration(opts)).rejects;
@@ -220,7 +220,7 @@ describe('WebAuthnError', () => {
...goodOpts1,
authenticatorSelection: {
userVerification: 'required',
- }
+ },
};
const rejected = await expect(startRegistration(opts)).rejects;
@@ -332,7 +332,7 @@ describe('WebAuthnError', () => {
user: {
...goodOpts1.user,
id: Array(65).fill('a').join(''),
- }
+ },
};
const rejected = await expect(startRegistration(opts)).rejects;
diff --git a/packages/browser/src/methods/startRegistration.ts b/packages/browser/src/methods/startRegistration.ts
index 4cc92cc..4037092 100644
--- a/packages/browser/src/methods/startRegistration.ts
+++ b/packages/browser/src/methods/startRegistration.ts
@@ -40,7 +40,7 @@ export default async function startRegistration(
let credential;
try {
credential = (await navigator.credentials.create(options)) as RegistrationCredential;
- } catch(err) {
+ } catch (err) {
throw identifyRegistrationError({ error: err as Error, options });
}