NostrElixir.Keys (nostr_elixir v0.1.0)

View Source

Key management functions for NostrElixir.

Examples

iex> alias NostrElixir.Keys
iex> keys = Keys.generate_keypair()
iex> Keys.public_key_to_bech32(keys.public_key)
"npub..."

Summary

Types

bech32_key()

@type bech32_key() :: String.t()

hex_key()

@type hex_key() :: String.t()

keys_map()

@type keys_map() :: %{
  public_key: String.t(),
  secret_key: String.t(),
  npub: String.t(),
  nsec: String.t()
}

Functions

generate_keypair()

@spec generate_keypair() :: keys_map()

Generate a new keypair and return it in a convenient map format.

generate_keys()

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

Generate a new keypair (JSON string).

get_public_key(keys_json)

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

Extract public key from keys JSON.

get_secret_key(keys_json)

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

Extract secret key from keys JSON.

keys_generate_nif()

See NostrElixir.keys_generate_nif/0.

keys_parse_nif(secret_key)

See NostrElixir.keys_parse_nif/1.

keys_public_key_bech32_nif(public_key)

See NostrElixir.keys_public_key_bech32_nif/1.

keys_public_key_nif(keys_json)

See NostrElixir.keys_public_key_nif/1.

keys_secret_key_bech32_nif(secret_key)

See NostrElixir.keys_secret_key_bech32_nif/1.

keys_secret_key_hex_nif(secret_key)

See NostrElixir.keys_secret_key_hex_nif/1.

keys_secret_key_nif(keys_json)

See NostrElixir.keys_secret_key_nif/1.

parse_keypair(secret_key)

@spec parse_keypair(hex_key() | bech32_key()) :: keys_map()

Parse a secret key and return it in a convenient map format.

parse_keys(secret_key)

@spec parse_keys(hex_key() | bech32_key()) :: String.t()

Parse a secret key (hex or bech32) to JSON string.

public_key_to_bech32(public_key)

@spec public_key_to_bech32(hex_key()) :: bech32_key()

Convert hex public key to bech32 npub.

secret_key_to_bech32(secret_key)

@spec secret_key_to_bech32(hex_key()) :: bech32_key()

Convert hex secret key to bech32 nsec.

secret_key_to_hex(secret_key)

@spec secret_key_to_hex(bech32_key()) :: hex_key()

Convert bech32 secret key to hex.