summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--packages/browser/src/methods/startAuthentication.ts24
-rw-r--r--packages/browser/src/methods/startRegistration.ts32
2 files changed, 14 insertions, 42 deletions
diff --git a/packages/browser/src/methods/startAuthentication.ts b/packages/browser/src/methods/startAuthentication.ts
index 8c9564f..fbb840d 100644
--- a/packages/browser/src/methods/startAuthentication.ts
+++ b/packages/browser/src/methods/startAuthentication.ts
@@ -2,7 +2,6 @@ import {
PublicKeyCredentialRequestOptionsJSON,
AuthenticationCredential,
AuthenticationResponseJSON,
- PublicKeyCredentialFuture,
} from '@simplewebauthn/typescript-types';
import { bufferToBase64URLString } from '../helpers/bufferToBase64URLString';
@@ -30,9 +29,6 @@ export async function startAuthentication(
throw new Error('WebAuthn is not supported in this browser');
}
- const globalPublicKeyCredential =
- window.PublicKeyCredential as unknown as PublicKeyCredentialFuture;
-
// We need to avoid passing empty array to avoid blocking retrieval
// of public key
let allowCredentials;
@@ -41,16 +37,11 @@ export async function startAuthentication(
}
// We need to convert some values to Uint8Arrays before passing the credentials to the navigator
- let publicKey: PublicKeyCredentialRequestOptions;
- if (typeof globalPublicKeyCredential.parseRequestOptionsFromJSON === 'function') {
- publicKey = globalPublicKeyCredential.parseRequestOptionsFromJSON(requestOptionsJSON);
- } else {
- publicKey = {
- ...requestOptionsJSON,
- challenge: base64URLStringToBuffer(requestOptionsJSON.challenge),
- allowCredentials,
- };
- }
+ const publicKey: PublicKeyCredentialRequestOptions = {
+ ...requestOptionsJSON,
+ challenge: base64URLStringToBuffer(requestOptionsJSON.challenge),
+ allowCredentials,
+ };
// Prepare options for `.get()`
const options: CredentialRequestOptions = {};
@@ -96,11 +87,6 @@ export async function startAuthentication(
throw new Error('Authentication was not completed');
}
- // Use toJSON() if it's available in the browser
- if (typeof credential.toJSON === 'function') {
- return credential.toJSON() as AuthenticationResponseJSON;
- }
-
// Manually construct an instance of AuthenticationResponseJSON
const { id, rawId, response, type } = credential;
diff --git a/packages/browser/src/methods/startRegistration.ts b/packages/browser/src/methods/startRegistration.ts
index 14419ca..2218725 100644
--- a/packages/browser/src/methods/startRegistration.ts
+++ b/packages/browser/src/methods/startRegistration.ts
@@ -2,7 +2,6 @@ import {
PublicKeyCredentialCreationOptionsJSON,
RegistrationCredential,
RegistrationResponseJSON,
- PublicKeyCredentialFuture,
} from '@simplewebauthn/typescript-types';
import { utf8StringToBuffer } from '../helpers/utf8StringToBuffer';
@@ -26,24 +25,16 @@ export async function startRegistration(
throw new Error('WebAuthn is not supported in this browser');
}
- const globalPublicKeyCredential =
- window.PublicKeyCredential as unknown as PublicKeyCredentialFuture;
-
- let publicKey: PublicKeyCredentialCreationOptions;
// We need to convert some values to Uint8Arrays before passing the credentials to the navigator
- if (typeof globalPublicKeyCredential.parseCreationOptionsFromJSON === 'function') {
- publicKey = globalPublicKeyCredential.parseCreationOptionsFromJSON(creationOptionsJSON);
- } else {
- publicKey = {
- ...creationOptionsJSON,
- challenge: base64URLStringToBuffer(creationOptionsJSON.challenge),
- user: {
- ...creationOptionsJSON.user,
- id: utf8StringToBuffer(creationOptionsJSON.user.id),
- },
- excludeCredentials: creationOptionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
- };
- }
+ const publicKey: PublicKeyCredentialCreationOptions = {
+ ...creationOptionsJSON,
+ challenge: base64URLStringToBuffer(creationOptionsJSON.challenge),
+ user: {
+ ...creationOptionsJSON.user,
+ id: utf8StringToBuffer(creationOptionsJSON.user.id),
+ },
+ excludeCredentials: creationOptionsJSON.excludeCredentials?.map(toPublicKeyCredentialDescriptor),
+ };
// Finalize options
const options: CredentialCreationOptions = { publicKey };
@@ -62,11 +53,6 @@ export async function startRegistration(
throw new Error('Registration was not completed');
}
- // Use toJSON() if it's available in the browser
- if (typeof credential.toJSON === 'function') {
- return credential.toJSON() as RegistrationResponseJSON;
- }
-
// Manually construct an instance of RegistrationResponseJSON
const { id, rawId, response, type } = credential;