ExSwan.Registration (exswan v0.1.0)
View SourceHandles WebAuthn registration ceremony operations.
This module provides functions for generating credential creation options, processing attestation responses, and verifying registration ceremonies according to the WebAuthn specification.
Registration Flow
- Generate creation options with
generate_creation_options/3 - Send options to client for credential creation
- Receive attestation response from client
- Verify the response with
verify_creation/3 - Store the resulting credential
Examples
# Generate creation options
rp = %ExSwan.Credential.RelyingParty{id: "example.com", name: "Example"}
user = %ExSwan.Credential.User{id: user_id, name: "user@example.com", display_name: "User"}
{:ok, options} = ExSwan.Registration.generate_creation_options(rp, user)
# After receiving attestation response from client
{:ok, credential} = ExSwan.Registration.verify_creation(response, options, origin)
Summary
Functions
Generates creation options for registering a new credential.
Converts creation options to JSON-serializable format for client.
Verifies a registration response and returns a validated credential.
Functions
@spec generate_creation_options( ExSwan.Credential.RelyingParty.t(), ExSwan.Credential.User.t(), keyword() ) :: {:ok, ExSwan.Attestation.CreationOptions.t()} | {:error, atom()}
Generates creation options for registering a new credential.
Creates properly formatted options for the navigator.credentials.create() call
including challenge, user information, relying party details, and algorithm preferences.
Parameters
rp- Relying party informationuser- User entity informationopts- Optional configuration (timeout, exclude_credentials, etc.)
Examples
rp = %ExSwan.Credential.RelyingParty{id: "example.com", name: "Example Corp"}
user = %ExSwan.Credential.User{
id: :crypto.strong_rand_bytes(32),
name: "john@example.com",
display_name: "John Doe"
}
{:ok, options} = ExSwan.Registration.generate_creation_options(rp, user)
@spec options_to_json(ExSwan.Attestation.CreationOptions.t()) :: map()
Converts creation options to JSON-serializable format for client.
Encodes binary data as base64url strings and formats the options according to WebAuthn specification requirements.
@spec verify_creation( map(), ExSwan.Attestation.CreationOptions.t(), String.t() | [String.t()] ) :: {:ok, ExSwan.Credential.t()} | {:error, atom()}
Verifies a registration response and returns a validated credential.
Processes the attestation response from the client, validates the attestation statement, parses authenticator data, and extracts the credential information.
Parameters
response- Raw attestation response from clientoptions- Creation options used for the registrationorigin- Expected origin(s) for the ceremony
Returns
{:ok, credential}- Successfully validated credential{:error, reason}- Validation failure with reason
Examples
{:ok, credential} = ExSwan.Registration.verify_creation(
attestation_response,
creation_options,
"https://example.com"
)