WebAuthnProvider
public protocol WebAuthnProvider : Sendable
Platform-specific WebAuthn provider interface.
Implementations trigger platform biometric / security-key prompts, handle WebAuthn credential creation and assertion, and return properly formatted byte-array results.
Sendable is required because the protocol crosses actor / task boundaries when invoked
from the smart-account transaction pipeline.
Errors thrown from register or authenticate are subclasses of WebAuthnException
(defined in the smart-account error module): RegistrationFailed, AuthenticationFailed,
NotSupported, or Cancelled.
Example:
let provider: WebAuthnProvider = MyApplePasskeyProvider()
let registration = try await provider.register(
challenge: challenge,
userId: userIdBytes,
userName: "user@example.com"
)
-
register(challenge:AsynchronoususerId: userName: ) Registers a new WebAuthn credential (passkey creation).
Triggers the platform’s credential-creation flow, prompts the user to create a new passkey using biometric authentication or a security key, generates a secp256r1 keypair and credential ID, and returns the public key plus attestation data.
The challenge MUST be used as-is in the registration request — it is a cryptographic hash that binds the credential to the smart-account deployment.
Declaration
Swift
func register( challenge: Data, userId: Data, userName: String ) async throws -> WebAuthnRegistrationResultParameters
challengeChallenge bytes to sign (typically 32 bytes).
userIdUser identifier bytes (typically random; used for discoverable credentials).
userNameUser-friendly name for the credential.
Return Value
A
WebAuthnRegistrationResultcontaining credential ID, public key, and attestation data. -
authenticate(challenge:AsynchronousallowCredentials: ) Authenticates with an existing WebAuthn credential (passkey assertion).
Triggers the platform’s credential-assertion flow, prompts the user to authenticate, signs the challenge with the private key, and returns the signature plus authenticator data.
The challenge MUST be used as-is in the authentication request — it is the authorization-payload hash that authorizes the transaction.
Declaration
Swift
func authenticate( challenge: Data, allowCredentials: [WebAuthnAllowCredential]? ) async throws -> WebAuthnAuthenticationResultParameters
challengeChallenge bytes to sign (typically the 32-byte authorization-payload hash).
allowCredentialsOptional list of credential descriptors with transport hints. Constrains which passkey the authenticator uses and indicates how the client can reach the authenticator. When
nil, discoverable-credential selection is used — the user picks which passkey to use. Including transport hints (e.g.,hybrid) enables cross-device authentication flows such as QR-code scanning.Return Value
A
WebAuthnAuthenticationResultcontaining signature and assertion data.
View on GitHub
Install in Dash