News for hackers. Stuff that matters.
Re:Bitwarden Acquires Passwordless.dev by arianvanp on Wednesday January 18, 2023 @11:40AM (#34429035)
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
    }

There are no comments on this comment yet.