register

open suspend override fun register(challenge: ByteArray, userId: ByteArray, userName: String): WebAuthnRegistrationResult

Registers a new WebAuthn credential (passkey creation).

Calls navigator.credentials.create() with PublicKeyCredentialCreationOptions configured for ES256 (algorithm -7, secp256r1). The resulting credential's public key is extracted using three fallback strategies and returned as an uncompressed 65-byte secp256r1 key with 0x04 prefix.

The authenticator flags in the attestation data are parsed to determine the device type ("singleDevice" or "multiDevice") and backup status.

Return

WebAuthnRegistrationResult containing credential ID, public key, attestation data, transport hints, device type, and backup status

Parameters

challenge

The challenge bytes to bind into the credential (typically 32 bytes)

userId

User identifier bytes for discoverable credentials

userName

User-friendly display name for the credential

Throws

if WebAuthn is not available (e.g. Node.js)

if the user dismissed the registration prompt

for any other registration error