3 ms·
Webauthn L4 standardises on JSON serialisation luckily. Yes the spec is horribly complex unfortunately. In my own project I send the assertion and attestation
by arianvanp 4y ago
Webauthn L4 standardises on JSON serialisation luckily.
Yes the spec is horribly complex unfortunately.
In my own project I send the assertion and attestation as multipart/form-data. Which means I can just directly send the ArrayBuffers over the wire.
PublicKeyCredential.prototype.toFormData = function (this: PublicKeyCredential) {
const formData = new FormData()
formData.append('type', this.type)
formData.append('id', this.id)
formData.append('rawId', new Blob([this.rawId]))
switch (this.type) {
case 'webauthn.get':
if (!(this.response instanceof AuthenticatorAssertionResponse)) {
throw new Error('Unknown type')
}
formData.append('response.authenticatorData', new Blob([this.response.authenticatorData]))
formData.append('response.signature', new Blob([this.response.signature]))
formData.append('response.clientDataJSON', new Blob([this.response.clientDataJSON]))
if (this.response.userHandle) {
formData.append('response.userHandle', new Blob([this.response.userHandle]))
}
case 'webauthn.create':
if (!(this.response instanceof AuthenticatorAttestationResponse)) {
throw new Error('Unknown type')
}
formData.append('response.attestationObject', new Blob([this.response.attestationObject]))
formData.append('response.clientDataJSON', new Blob([this.response.clientDataJSON]))
break
default:
throw new Error('Unknown type')
}
return formData
}
async solveChallenge(challenge: Challenge, credential: PublicKeyCredential) {
const formData = credential.toFormData()
await fetch(challenge.location, { method: 'POST', headers: {'content-type':'multipart/form-data'}, body: formData })
}