I try to use webauthn by using cross platform.
but, I got a error. ( use platform has normal )
Error message is Error - Error: 1 remaining bytes after end of encoding
const credentialOption = {
...JSON.parse(noNested),
rp: JSON.parse(rp),
user: JSON.parse(user),
pubKeyCredParams: JSON.parse(pubKeyCredParams),
authenticatorSelection: JSON.parse(authenticatorSelection),
};
const originChallenge = credentialOption.challenge;
credentialOption.challenge = b64ToByteArray(credentialOption.challenge);
credentialOption.rp.id = location.hostname;
credentialOption.user.id = b64ToByteArray(credentialOption.user.id);
const credential = await navigator.credentials
.create({ publicKey: credentialOption })
.then((result) => result)
.catch(() => 'cancel');
if (credential === undefined || credential === 'cancel') {
return 'cancel';
}
const credentialResult = {
id: credential.id,
type: credential.type,
response: {
clientDataJSON: JSON.parse(Uint8toString(credential.response.clientDataJSON)),
attestationObject: CBOR.decode(credential.response.attestationObject),
},
};
credentialResult.response.attestationObject.authData = parseAuthData(
credentialResult.response.attestationObject.authData
);
if (credentialResult.response.attestationObject.attStmt.sig) {
credentialResult.response.attestationObject.attStmt.sig = Array.from(
credentialResult.response.attestationObject.attStmt.sig
).join(',');
}
credentialResult.response.credentialId = credentialResult.response.attestationObject.authData.id;
credentialResult.response.originChallenge = originChallenge;
credentialResult.response.transports = credential.response.getTransports().join(',');
const userAgent = UAParser(navigator.userAgent);
const os = userAgent.os;
const browser = userAgent.browser;
credentialResult.response.device = `${os.name} ${os.version}|${browser.name} ${browser.version}`;
delete credentialResult.response.attestationObject.authData.id;
return JSON.stringify(credentialResult);
This code is based on https://webauthn.guide/ demo site success
I don't know why not operate this code.