SignedNote.Verifier (signed_note v1.0.0)

Copy Markdown View Source

A verifier key: the public half of a note-signing key, parsed from the C2SP vkey encoding.

<key name>+<hex key ID>+<base64(signature type || public key)>

For Ed25519 keys (signature type 0x01, the only type this library implements), the key ID embedded in the vkey must equal the first four bytes of SHA-256(key name || 0x0A || 0x01 || public key), so a mistyped or tampered vkey fails at parse time rather than producing a verifier that can never match a signature.

Summary

Types

t()

An Ed25519 verifier: key name, 4-byte key ID, 32-byte public key.

Functions

Builds a verifier from a key name and a raw 32-byte Ed25519 public key, computing the key ID.

Parses a vkey string.

Renders the vkey encoding of this verifier.

Types

t()

@type t() :: %SignedNote.Verifier{
  key_id: <<_::4*8>>,
  name: String.t(),
  public_key: <<_::32*8>>
}

An Ed25519 verifier: key name, 4-byte key ID, 32-byte public key.

Functions

from_ed25519(name, public_key)

@spec from_ed25519(String.t(), <<_::32*8>>) ::
  {:ok, t()} | {:error, SignedNote.Error.t()}

Builds a verifier from a key name and a raw 32-byte Ed25519 public key, computing the key ID.

from_string(vkey)

@spec from_string(String.t()) :: {:ok, t()} | {:error, SignedNote.Error.t()}

Parses a vkey string.

iex> {:ok, verifier} =
...>   SignedNote.Verifier.from_string(
...>     "example.com/foo+530d903a+AekyeRrm56hApGFkyQR4ZCbV54Id2LKaANYcrnKv3U2k"
...>   )
iex> verifier.name
"example.com/foo"
iex> Base.encode16(verifier.key_id, case: :lower)
"530d903a"

to_string(verifier)

@spec to_string(t()) :: String.t()

Renders the vkey encoding of this verifier.

iex> {:ok, verifier} =
...>   SignedNote.Verifier.from_string(
...>     "example.com/foo+530d903a+AekyeRrm56hApGFkyQR4ZCbV54Id2LKaANYcrnKv3U2k"
...>   )
iex> SignedNote.Verifier.to_string(verifier)
"example.com/foo+530d903a+AekyeRrm56hApGFkyQR4ZCbV54Id2LKaANYcrnKv3U2k"