View Source Nostr.Keys.PrivateKey (Nostr v0.1.2)

Private keys management functions

Link to this section Summary

Functions

Creates a new private key

Extracts a binary private key from the nsec format

Extracts a binary private key from the nsec format

Encodes a private key into the nsec format

Link to this section Functions

@spec create() :: K256.Schnorr.signing_key()

Creates a new private key

examples

Examples

iex> Nostr.Keys.PrivateKey.create()
Link to this function

from_nsec(bech32_private_key)

View Source
@spec from_nsec(binary()) :: {:ok, binary()} | {:error, binary()}

Extracts a binary private key from the nsec format

examples

Examples

iex> nsec = "nsec1d4ed5x49d7p24xn63flj4985dc4gpfngdhtqcxpth0ywhm6czxcs5l2exj"
...> Nostr.Keys.PrivateKey.from_nsec(nsec)
{:ok, <<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>}
Link to this function

from_nsec!(bech32_private_key)

View Source
@spec from_nsec!(binary()) :: <<_::256>>

Extracts a binary private key from the nsec format

examples

Examples

iex> nsec = "nsec1d4ed5x49d7p24xn63flj4985dc4gpfngdhtqcxpth0ywhm6czxcs5l2exj"
...> Nostr.Keys.PrivateKey.from_nsec!(nsec)
<<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>
@spec to_nsec(<<_::256>>) :: binary()

Encodes a private key into the nsec format

examples

Examples

iex> private_key = <<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>
...> Nostr.Keys.PrivateKey.to_nsec(private_key)
"nsec1d4ed5x49d7p24xn63flj4985dc4gpfngdhtqcxpth0ywhm6czxcs5l2exj"