ExSwan (exswan v0.1.0)
View SourceExSwan is an Elixir library implementing the WebAuthn (FIDO2) specification for passwordless authentication.
The compatibility baseline is WebAuthn Level 2 with SimpleWebAuthn browser JSON. Supported algorithms and attestation formats are deliberately limited to the combinations covered by end-to-end cryptographic tests.
Key Features
- Registration and authentication ceremony support
- ES256 credentials and
noneattestation - Strict validation and security checks
Basic Usage
The four ceremony entry points are generate_registration_options/1,
verify_registration_response/1, generate_authentication_options/1, and
verify_authentication_response/1.
Summary
Functions
Generates browser-ready authentication options.
Generates browser-ready registration options.
Verifies a complete authentication response from @simplewebauthn/browser.
Verifies a complete registration response from @simplewebauthn/browser.
Returns the library version.
Functions
@spec generate_authentication_options(keyword()) :: {:ok, %{options: map(), ceremony: ExSwan.AuthenticationCeremony.t()}} | {:error, term()}
Generates browser-ready authentication options.
The returned :options map can be passed directly to
startAuthentication({optionsJSON}). Keep :ceremony on the server for later
verification.
Examples
iex> {:ok, result} = ExSwan.generate_authentication_options(
...> rp_id: "example.com",
...> challenge: :binary.copy(<<1>>, 32)
...> )
iex> result.options["rpId"]
"example.com"
iex> result.ceremony.rp_id
"example.com"
@spec generate_registration_options(keyword()) :: {:ok, %{options: map(), ceremony: ExSwan.RegistrationCeremony.t()}} | {:error, term()}
Generates browser-ready registration options.
The returned :options map can be passed directly to
startRegistration({optionsJSON}). Keep :ceremony on the server for later
verification.
Examples
iex> user_id = <<1, 2, 3, 4>>
iex> {:ok, result} = ExSwan.generate_registration_options(
...> rp_name: "Example",
...> rp_id: "example.com",
...> user_name: "person@example.com",
...> user_id: user_id,
...> challenge: :binary.copy(<<1>>, 32)
...> )
iex> result.options["rp"]["id"]
"example.com"
iex> result.ceremony.user_id
<<1, 2, 3, 4>>
@spec verify_authentication_response(keyword()) :: {:ok, ExSwan.AuthenticationResult.t()} | {:error, term()}
Verifies a complete authentication response from @simplewebauthn/browser.
The result includes the new signature counter and backup state that the caller must persist after successful verification.
Examples
ExSwan.verify_authentication_response(
response: browser_json,
expected_challenge: challenge,
expected_origin: "https://example.com",
expected_rp_id: "example.com",
credential: stored_credential
)
@spec verify_registration_response(keyword()) :: {:ok, ExSwan.RegistrationResult.t()} | {:error, term()}
Verifies a complete registration response from @simplewebauthn/browser.
Pass the browser response without extracting its nested response object.
Examples
ExSwan.verify_registration_response(
response: browser_json,
expected_challenge: challenge,
expected_origin: "https://example.com",
expected_rp_id: "example.com"
)
@spec version() :: String.t()
Returns the library version.