Cartouche.Solana.Signer (Cartouche v0.2.1)

Copy Markdown View Source

GenServer that wraps Ed25519 signing backends for Solana.

Follows the same MFA (module, function, args) backend pattern as the Ethereum Cartouche.Signer, but much simpler: no recovery bit brute-force, no chain ID encoding.

Delegates to a backend module (e.g., Cartouche.Solana.Signer.Ed25519 for local keys, or Cartouche.Solana.Signer.CloudKMS for GCP KMS). Caches the public key on first use.

Examples

# Start via supervisor or manually:
{:ok, pid} = Cartouche.Solana.Signer.start_link(
  mfa: {Cartouche.Solana.Signer.Ed25519, :sign, [seed]},
  name: MySolSigner
)

# Sign a message:
{:ok, signature} = Cartouche.Solana.Signer.sign(message, MySolSigner)

# Get the signer's public key:
pub_key = Cartouche.Solana.Signer.address(MySolSigner)

API Functions

FunctionArityDescriptionParam Kinds
verify3Verify an Ed25519 signature against raw Solana message bytes and a public key.message: value, signature: value, pub_key: value
address1Get the Solana public key controlled by a signer process.name: value
sign2Sign raw Solana message bytes with a running signer process.message: value, name: value
start_link1Start a Solana signer process backed by the provided Ed25519 signing MFA.opts: value
child_spec1Build the supervisor child specification for a Solana signer process.init_arg: value

Summary

Functions

Get the 32-byte public key (Solana address) for this signer.

Returns a specification to start this module under a supervisor.

Sign raw message bytes. Returns a 64-byte Ed25519 signature.

Starts a new Solana signer process.

Verify an Ed25519 signature. Standalone function, no GenServer needed.

Functions

address(name \\ Default)

@spec address(GenServer.name()) :: <<_::256>>

Get the 32-byte public key (Solana address) for this signer.

Examples

iex> signer = Cartouche.Solana.Test.Signer.start_signer()
iex> address = Cartouche.Solana.Signer.address(signer)
iex> byte_size(address)
32

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

sign(message, name \\ Default)

@spec sign(binary(), GenServer.name()) :: {:ok, <<_::512>>} | {:error, term()}

Sign raw message bytes. Returns a 64-byte Ed25519 signature.

Examples

iex> signer = Cartouche.Solana.Test.Signer.start_signer()
iex> {:ok, sig} = Cartouche.Solana.Signer.sign("test", signer)
iex> byte_size(sig)
64

start_link(opts)

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

Starts a new Solana signer process.

verify(message, arg1, arg2)

@spec verify(binary(), <<_::512>>, <<_::256>>) :: boolean()

Verify an Ed25519 signature. Standalone function, no GenServer needed.

Examples

iex> seed = Base.decode16!("9D61B19DEFFD5A60BA844AF492EC2CC44449C5697B326919703BAC031CAE7F60")
iex> pub = Base.decode16!("D75A980182B10AB7D54BFED3C964073A0EE172F3DAA62325AF021A68F707511A")
iex> {:ok, sig} = Cartouche.Solana.Signer.Ed25519.sign("test", seed)
iex> Cartouche.Solana.Signer.verify("test", sig, pub)
true