X402.Signer.SolanaKey (X402 v0.6.0)

Copy Markdown View Source

X402.Signer backed by a raw Ed25519 private key held in memory.

Signs Solana transaction message bytes through OTP's :crypto (EdDSA on the ed25519 curve) — no extra dependencies. new/1 accepts:

  • a raw 32-byte Ed25519 seed
  • a 64-byte Solana keypair (seed <> public_key, the solana-keygen format) — the embedded public key is checked against the derived one
  • the Base64 or Base58 encoding of either

The struct redacts the private key when inspected, but the key still lives in process memory — prefer an external signer implementation (KMS, hardware wallet) for production payers holding significant funds.

Examples

{:ok, signer} = X402.Signer.SolanaKey.new(:crypto.strong_rand_bytes(32))
{:ok, address} = X402.Signer.SolanaKey.address(signer)

Summary

Types

t()

A local Ed25519 signing key with its derived Solana address.

Functions

Returns the Base58 Solana address derived from the private key.

Builds a signer from an Ed25519 seed or Solana keypair.

Signs message with the local Ed25519 key.

Types

t()

@type t() :: %X402.Signer.SolanaKey{address: String.t(), seed: binary()}

A local Ed25519 signing key with its derived Solana address.

Functions

address(solana_key)

(since 0.6.0)
@spec address(t()) :: {:ok, String.t()}

Returns the Base58 Solana address derived from the private key.

new(private_key)

(since 0.6.0)
@spec new(binary()) :: {:ok, t()} | {:error, :invalid_private_key}

Builds a signer from an Ed25519 seed or Solana keypair.

Returns {:error, :invalid_private_key} for malformed keys and for 64-byte keypairs whose public half does not match the seed.

Examples

iex> {:ok, signer} = X402.Signer.SolanaKey.new(:binary.copy(<<1>>, 32))
iex> signer.address
"AKnL4NNf3DGWZJS6cPknBuEGnVsV4A4m5tgebLHaRSZ9"

iex> X402.Signer.SolanaKey.new("not a key")
{:error, :invalid_private_key}

sign_ed25519(solana_key, message)

(since 0.6.0)
@spec sign_ed25519(t(), binary()) :: {:ok, X402.Signer.ed25519_signature()}

Signs message with the local Ed25519 key.

Ed25519 signing is deterministic (RFC 8032), so the same key and message always produce the same 64-byte signature.