From dfb32f4891f6c955c25b2f305fa702cdaf8c5a5e Mon Sep 17 00:00:00 2001 From: Matthew Miller Date: Fri, 18 Aug 2023 11:11:56 -0700 Subject: Format browser --- .../src/helpers/identifyRegistrationError.ts | 72 ++++++++++++---------- 1 file changed, 39 insertions(+), 33 deletions(-) (limited to 'packages/browser/src/helpers/identifyRegistrationError.ts') diff --git a/packages/browser/src/helpers/identifyRegistrationError.ts b/packages/browser/src/helpers/identifyRegistrationError.ts index 02c9dac..d0def65 100644 --- a/packages/browser/src/helpers/identifyRegistrationError.ts +++ b/packages/browser/src/helpers/identifyRegistrationError.ts @@ -1,5 +1,5 @@ -import { isValidDomain } from './isValidDomain'; -import { WebAuthnError } from './webAuthnError'; +import { isValidDomain } from "./isValidDomain"; +import { WebAuthnError } from "./webAuthnError"; /** * Attempt to intuit _why_ an error was raised after calling `navigator.credentials.create()` @@ -14,104 +14,110 @@ export function identifyRegistrationError({ const { publicKey } = options; if (!publicKey) { - throw Error('options was missing required publicKey property'); + throw Error("options was missing required publicKey property"); } - if (error.name === 'AbortError') { + if (error.name === "AbortError") { if (options.signal instanceof AbortSignal) { // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 16) return new WebAuthnError({ - message: 'Registration ceremony was sent an abort signal', - code: 'ERROR_CEREMONY_ABORTED', + message: "Registration ceremony was sent an abort signal", + code: "ERROR_CEREMONY_ABORTED", cause: error, }); } - } else if (error.name === 'ConstraintError') { + } else if (error.name === "ConstraintError") { if (publicKey.authenticatorSelection?.requireResidentKey === true) { // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 4) return new WebAuthnError({ - message: 'Discoverable credentials were required but no available authenticator supported it', - code: 'ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT', + message: + "Discoverable credentials were required but no available authenticator supported it", + code: "ERROR_AUTHENTICATOR_MISSING_DISCOVERABLE_CREDENTIAL_SUPPORT", cause: error, }); - } else if (publicKey.authenticatorSelection?.userVerification === 'required') { + } else if ( + publicKey.authenticatorSelection?.userVerification === "required" + ) { // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 5) return new WebAuthnError({ - message: 'User verification was required but no available authenticator supported it', - code: 'ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT', + message: + "User verification was required but no available authenticator supported it", + code: "ERROR_AUTHENTICATOR_MISSING_USER_VERIFICATION_SUPPORT", cause: error, }); } - } else if (error.name === 'InvalidStateError') { + } else if (error.name === "InvalidStateError") { // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 20) // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 3) return new WebAuthnError({ - message: 'The authenticator was previously registered', - code: 'ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED', - cause: error + message: "The authenticator was previously registered", + code: "ERROR_AUTHENTICATOR_PREVIOUSLY_REGISTERED", + cause: error, }); - } else if (error.name === 'NotAllowedError') { + } else if (error.name === "NotAllowedError") { /** * Pass the error directly through. Platforms are overloading this error beyond what the spec * defines and we don't want to overwrite potentially useful error messages. */ return new WebAuthnError({ message: error.message, - code: 'ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY', + code: "ERROR_PASSTHROUGH_SEE_CAUSE_PROPERTY", cause: error, }); - } else if (error.name === 'NotSupportedError') { + } 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({ message: 'No entry in pubKeyCredParams was of type "public-key"', - code: 'ERROR_MALFORMED_PUBKEYCREDPARAMS', + code: "ERROR_MALFORMED_PUBKEYCREDPARAMS", cause: error, }); } // https://www.w3.org/TR/webauthn-2/#sctn-op-make-cred (Step 2) return new WebAuthnError({ - message: 'No available authenticator supported any of the specified pubKeyCredParams algorithms', - code: 'ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG', + message: + "No available authenticator supported any of the specified pubKeyCredParams algorithms", + code: "ERROR_AUTHENTICATOR_NO_SUPPORTED_PUBKEYCREDPARAMS_ALG", cause: error, }); - } else if (error.name === 'SecurityError') { + } else if (error.name === "SecurityError") { const effectiveDomain = window.location.hostname; if (!isValidDomain(effectiveDomain)) { // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 7) return new WebAuthnError({ message: `${window.location.hostname} is an invalid domain`, - code: 'ERROR_INVALID_DOMAIN', - cause: error + code: "ERROR_INVALID_DOMAIN", + cause: error, }); } else if (publicKey.rp.id !== effectiveDomain) { // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 8) return new WebAuthnError({ message: `The RP ID "${publicKey.rp.id}" is invalid for this domain`, - code: 'ERROR_INVALID_RP_ID', + code: "ERROR_INVALID_RP_ID", cause: error, }); } - } else if (error.name === 'TypeError') { + } else if (error.name === "TypeError") { if (publicKey.user.id.byteLength < 1 || publicKey.user.id.byteLength > 64) { // https://www.w3.org/TR/webauthn-2/#sctn-createCredential (Step 5) return new WebAuthnError({ - message: 'User ID was not between 1 and 64 characters', - code: 'ERROR_INVALID_USER_ID_LENGTH', + message: "User ID was not between 1 and 64 characters", + code: "ERROR_INVALID_USER_ID_LENGTH", cause: error, }); } - } else if (error.name === 'UnknownError') { + } else if (error.name === "UnknownError") { // 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({ - message: 'The authenticator was unable to process the specified options, or could not create a new credential', - code: 'ERROR_AUTHENTICATOR_GENERAL_ERROR', + message: + "The authenticator was unable to process the specified options, or could not create a new credential", + code: "ERROR_AUTHENTICATOR_GENERAL_ERROR", cause: error, }); } -- cgit v1.2.3