summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/src/methods/startRegistration.ts
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2023-08-18 11:11:56 -0700
committerMatthew Miller <matthew@millerti.me>2023-08-18 11:11:56 -0700
commitdfb32f4891f6c955c25b2f305fa702cdaf8c5a5e (patch)
tree07c3c57caa54c77a08a209fd3cc509a359ed03e4 /packages/browser/src/methods/startRegistration.ts
parentde5e22f5fec4eb980c77f00c586a1179565359d7 (diff)
Format browser
Diffstat (limited to 'packages/browser/src/methods/startRegistration.ts')
-rw-r--r--packages/browser/src/methods/startRegistration.ts43
1 files changed, 24 insertions, 19 deletions
diff --git a/packages/browser/src/methods/startRegistration.ts b/packages/browser/src/methods/startRegistration.ts
index 5b97a5e..c56f0ed 100644
--- a/packages/browser/src/methods/startRegistration.ts
+++ b/packages/browser/src/methods/startRegistration.ts
@@ -1,18 +1,18 @@
import {
+ AuthenticatorTransportFuture,
PublicKeyCredentialCreationOptionsJSON,
RegistrationCredential,
RegistrationResponseJSON,
- AuthenticatorTransportFuture,
-} from '@simplewebauthn/typescript-types';
+} from "@simplewebauthn/typescript-types";
-import { utf8StringToBuffer } from '../helpers/utf8StringToBuffer';
-import { bufferToBase64URLString } from '../helpers/bufferToBase64URLString';
-import { base64URLStringToBuffer } from '../helpers/base64URLStringToBuffer';
-import { browserSupportsWebAuthn } from '../helpers/browserSupportsWebAuthn';
-import { toPublicKeyCredentialDescriptor } from '../helpers/toPublicKeyCredentialDescriptor';
-import { identifyRegistrationError } from '../helpers/identifyRegistrationError';
-import { webauthnAbortService } from '../helpers/webAuthnAbortService';
-import { toAuthenticatorAttachment } from '../helpers/toAuthenticatorAttachment';
+import { utf8StringToBuffer } from "../helpers/utf8StringToBuffer";
+import { bufferToBase64URLString } from "../helpers/bufferToBase64URLString";
+import { base64URLStringToBuffer } from "../helpers/base64URLStringToBuffer";
+import { browserSupportsWebAuthn } from "../helpers/browserSupportsWebAuthn";
+import { toPublicKeyCredentialDescriptor } from "../helpers/toPublicKeyCredentialDescriptor";
+import { identifyRegistrationError } from "../helpers/identifyRegistrationError";
+import { webauthnAbortService } from "../helpers/webAuthnAbortService";
+import { toAuthenticatorAttachment } from "../helpers/toAuthenticatorAttachment";
/**
* Begin authenticator "registration" via WebAuthn attestation
@@ -23,7 +23,7 @@ export async function startRegistration(
creationOptionsJSON: PublicKeyCredentialCreationOptionsJSON,
): Promise<RegistrationResponseJSON> {
if (!browserSupportsWebAuthn()) {
- throw new Error('WebAuthn is not supported in this browser');
+ throw new Error("WebAuthn is not supported in this browser");
}
// We need to convert some values to Uint8Arrays before passing the credentials to the navigator
@@ -47,31 +47,32 @@ export async function startRegistration(
// Wait for the user to complete attestation
let credential;
try {
- credential = (await navigator.credentials.create(options)) as RegistrationCredential;
+ credential =
+ (await navigator.credentials.create(options)) as RegistrationCredential;
} catch (err) {
throw identifyRegistrationError({ error: err as Error, options });
}
if (!credential) {
- throw new Error('Registration was not completed');
+ throw new Error("Registration was not completed");
}
const { id, rawId, response, type } = credential;
// Continue to play it safe with `getTransports()` for now, even when L3 types say it's required
let transports: AuthenticatorTransportFuture[] | undefined = undefined;
- if (typeof response.getTransports === 'function') {
+ if (typeof response.getTransports === "function") {
transports = response.getTransports();
}
// L3 says this is required, but browser and webview support are still not guaranteed.
let responsePublicKeyAlgorithm: number | undefined = undefined;
- if (typeof response.getPublicKeyAlgorithm === 'function') {
+ if (typeof response.getPublicKeyAlgorithm === "function") {
responsePublicKeyAlgorithm = response.getPublicKeyAlgorithm();
}
let responsePublicKey: string | undefined = undefined;
- if (typeof response.getPublicKey === 'function') {
+ if (typeof response.getPublicKey === "function") {
const _publicKey = response.getPublicKey();
if (_publicKey !== null) {
responsePublicKey = bufferToBase64URLString(_publicKey);
@@ -80,8 +81,10 @@ export async function startRegistration(
// L3 says this is required, but browser and webview support are still not guaranteed.
let responseAuthenticatorData: string | undefined;
- if (typeof response.getAuthenticatorData === 'function') {
- responseAuthenticatorData = bufferToBase64URLString(response.getAuthenticatorData());
+ if (typeof response.getAuthenticatorData === "function") {
+ responseAuthenticatorData = bufferToBase64URLString(
+ response.getAuthenticatorData(),
+ );
}
return {
@@ -97,6 +100,8 @@ export async function startRegistration(
},
type,
clientExtensionResults: credential.getClientExtensionResults(),
- authenticatorAttachment: toAuthenticatorAttachment(credential.authenticatorAttachment),
+ authenticatorAttachment: toAuthenticatorAttachment(
+ credential.authenticatorAttachment,
+ ),
};
}