Skip to content

Commit

Permalink
πŸ› webauthn: parse attestation object correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzdanilo committed Jan 9, 2024
1 parent 2274486 commit 2617535
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions webauthn/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,35 @@ if (ExpoWebauthn) {
global.window.PublicKeyCredential ??= {} as PublicKeyCredential; // eslint-disable-line @typescript-eslint/no-unnecessary-condition
}

function stringify(value: unknown) {
return JSON.stringify(value, (_, v) => {
if (v instanceof ArrayBuffer) {
return encode(v).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
function stringify(object: unknown) {
return JSON.stringify(object, (_, value) => {
if (value instanceof ArrayBuffer) {
return encode(value).replaceAll("+", "-").replaceAll("/", "_").replaceAll("=", "");
}
return v as unknown;
return value as unknown;
});
}

function parse(text: string) {
let clientExtensionResults: AuthenticationExtensionsClientOutputs = {};
const credential = JSON.parse(text, (key, v) => {
const credential = JSON.parse(text, (key, value) => {
if (
typeof v === "string" &&
typeof value === "string" &&
(key === "rawId" ||
key === "publicKey" ||
key === "signature" ||
key === "userHandle" ||
key === "clientDataJSON" ||
key === "attestationObject" ||
key === "authenticatorData")
) {
return decode(v.replaceAll("-", "+").replaceAll("_", "/"));
return decode(value.replaceAll("-", "+").replaceAll("_", "/"));
}
if (key === "clientExtensionResults") {
clientExtensionResults = v as AuthenticationExtensionsClientOutputs;
clientExtensionResults = value as AuthenticationExtensionsClientOutputs;
return;
}
return v as unknown;
return value as unknown;
}) as PublicKeyCredential;
credential.getClientExtensionResults = () => clientExtensionResults;
return credential;
Expand Down

0 comments on commit 2617535

Please sign in to comment.