INNER CODE UNIT · JavaScript
auth
mylofi/webauthn-local-client · src/walc.js:303
async function auth(authOptions = authDefaults()) {
try {
if (supportsWebAuthn) {
// ensure credential IDs are binary (not base64 string)
authOptions[authOptions[credentialTypeKey]].allowCredentials = (
normalizeCredentialsList(
authOptions[authOptions[credentialTypeKey]].allowCredentials
)
);
let authResult = await navigator.credentials.get(authOptions);
let authClientDataRaw = new Uint8Array(authResult.response.clientDataJSON);
let authClientData = JSON.parse(toUTF8String(authClientDataRaw));
if (authClientData.type != "webauthn.get") {
throw new Error("Invalid auth response");
}
let expectedChallenge = sodium.to_base64(
authOptions[authOptions[credentialTypeKey]].challenge,