cleanup
This commit is contained in:
@@ -12,10 +12,10 @@ const base64ToBase64url = (value = '') =>
|
||||
value.replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
|
||||
|
||||
const decodeBase64 = (value) => {
|
||||
if (typeof window !== 'undefined' && typeof window.atob === 'function') {
|
||||
if (window.atob) {
|
||||
return window.atob(value);
|
||||
}
|
||||
const bufferCtor = typeof globalThis !== 'undefined' ? globalThis.Buffer : undefined;
|
||||
const bufferCtor = globalThis?.Buffer;
|
||||
if (bufferCtor) {
|
||||
return bufferCtor.from(value, 'base64').toString('binary');
|
||||
}
|
||||
@@ -23,10 +23,10 @@ const decodeBase64 = (value) => {
|
||||
};
|
||||
|
||||
const encodeBase64 = (binary) => {
|
||||
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
||||
if (window.btoa) {
|
||||
return window.btoa(binary);
|
||||
}
|
||||
const bufferCtor = typeof globalThis !== 'undefined' ? globalThis.Buffer : undefined;
|
||||
const bufferCtor = globalThis?.Buffer;
|
||||
if (bufferCtor) {
|
||||
return bufferCtor.from(binary, 'binary').toString('base64');
|
||||
}
|
||||
@@ -54,11 +54,7 @@ export const arrayBufferToBase64url = (buffer) => {
|
||||
};
|
||||
|
||||
export const isWebAuthnAvailable = () =>
|
||||
typeof window !== 'undefined'
|
||||
&& typeof navigator !== 'undefined'
|
||||
&& navigator.credentials
|
||||
&& typeof navigator.credentials.create === 'function'
|
||||
&& typeof navigator.credentials.get === 'function';
|
||||
Boolean(navigator?.credentials?.create && navigator.credentials.get);
|
||||
|
||||
export const preparePublicKeyCreationOptions = (challengeResponse) => {
|
||||
if (!challengeResponse || !challengeResponse.publicKey) {
|
||||
@@ -118,10 +114,7 @@ export const serializeRegistrationCredential = (credential) => {
|
||||
return null;
|
||||
}
|
||||
|
||||
const transports =
|
||||
typeof credential?.response?.getTransports === 'function'
|
||||
? credential.response.getTransports()
|
||||
: undefined;
|
||||
const transports = credential?.response?.getTransports?.();
|
||||
|
||||
return {
|
||||
id: credential.id,
|
||||
@@ -132,10 +125,7 @@ export const serializeRegistrationCredential = (credential) => {
|
||||
attestationObject: arrayBufferToBase64url(credential.response.attestationObject),
|
||||
transports: transports && transports.length ? Array.from(transports) : undefined,
|
||||
},
|
||||
clientExtensionResults:
|
||||
typeof credential.getClientExtensionResults === 'function'
|
||||
? credential.getClientExtensionResults()
|
||||
: {},
|
||||
clientExtensionResults: credential.getClientExtensionResults?.() || {},
|
||||
};
|
||||
};
|
||||
|
||||
@@ -156,9 +146,6 @@ export const serializeAuthenticationCredential = (credential) => {
|
||||
? arrayBufferToBase64url(credential.response.userHandle)
|
||||
: undefined,
|
||||
},
|
||||
clientExtensionResults:
|
||||
typeof credential.getClientExtensionResults === 'function'
|
||||
? credential.getClientExtensionResults()
|
||||
: {},
|
||||
clientExtensionResults: credential.getClientExtensionResults?.() || {},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user