View Source Nostr.Keys.PrivateKey (Nostr v0.1.3)
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
Does its best to convert any private key format to binary, issues an error if it can't
Does its best to convert any private key format to binary, raises an error if it can't
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()
Extracts a binary private key from the nsec format
examples
Examples
iex> nsec = "nsec1d4ed5x49d7p24xn63flj4985dc4gpfngdhtqcxpth0ywhm6czxcs5l2exj"
...> Nostr.Keys.PrivateKey.from_nsec(nsec)
{:ok, <<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>}
@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>>
Does its best to convert any private key format to binary, issues an error if it can't
examples
Examples
iex> "nsec1fc3d5s6p3hvngdeuhvu2t2cnqkgerg4n55w9uzm8avfngetfgwuqc25heg"
...> |> Nostr.Keys.PrivateKey.to_binary()
{ :ok, <<0x4e22da43418dd934373cbb38a5ab13059191a2b3a51c5e0b67eb1334656943b8::256>> }
@spec to_binary!(<<_::256>> | String.t()) :: <<_::256>>
Does its best to convert any private key format to binary, raises an error if it can't
examples
Examples
iex> "nsec1fc3d5s6p3hvngdeuhvu2t2cnqkgerg4n55w9uzm8avfngetfgwuqc25heg"
...> |> Nostr.Keys.PrivateKey.to_binary!()
<<0x4e22da43418dd934373cbb38a5ab13059191a2b3a51c5e0b67eb1334656943b8::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"