SigilGuard.Signer.Ed25519 (SigilGuard v0.2.0)

View Source

Default Ed25519 signer using OTP :crypto.

For production use, consider implementing SigilGuard.Signer with an HSM or KMS backend instead.

Usage

Process-free, passing the signer struct explicitly:

{_pub, priv} = SigilGuard.Signer.generate_keypair()
signer = SigilGuard.Signer.Ed25519.new(priv)
signature = SigilGuard.Signer.Ed25519.sign_with(signer, message)

Or as a module-based signer (the form SigilGuard.Envelope.sign/3 expects in its :signer option) via start_link/1:

{:ok, _pid} = SigilGuard.Signer.Ed25519.start_link(private_key: priv)
signature = SigilGuard.Signer.Ed25519.sign(message)

Process Model

start_link/1 registers a singleton Agent under SigilGuard.Signer.Ed25519 holding the keypair — one keypair per node. Supervise it in your application's tree; sign/1 and public_key/0 exit if it is not running. For multiple keypairs in one node, use new/1 + sign_with/2 or implement SigilGuard.Signer in your own module.

Summary

Functions

Returns a specification to start this module under a supervisor.

Create a signer struct from a private key (seed).

Sign a message using a signer struct (without requiring the Agent).

Start a named agent holding the keypair for module-based callback usage.

Verify a signature using a raw public key.

Types

t()

@type t() :: %SigilGuard.Signer.Ed25519{private_key: binary(), public_key: binary()}

Functions

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

new(private_key)

@spec new(binary()) :: t()

Create a signer struct from a private key (seed).

Accepts the raw 32-byte Ed25519 seed as returned by :crypto.generate_key/2. Derives the public key from the seed.

sign_with(ed25519, message)

@spec sign_with(t(), binary()) :: binary()

Sign a message using a signer struct (without requiring the Agent).

start_link(opts)

@spec start_link(keyword()) :: Agent.on_start()

Start a named agent holding the keypair for module-based callback usage.

verify(message, signature, public_key)

@spec verify(binary(), binary(), binary()) :: boolean()

Verify a signature using a raw public key.