View Source Nostr.Keys.PublicKey (Nostr v0.1.1)

Public keys management functions

Link to this section Summary

Functions

Converts a public key in the npub format into a binary public key that can be used with this lib

Converts a public key in the npub format into a binary public key that can be used with this lib

Issues the public key corresponding to a given private key

Issues the public key corresponding to a given private key

Encodes a public key into the npub format

Link to this section Functions

Link to this function

from_npub(bech32_pubkey)

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

Converts a public key in the npub format into a binary public key that can be used with this lib

examples

Examples

iex> npub = "npub1d4ed5x49d7p24xn63flj4985dc4gpfngdhtqcxpth0ywhm6czxcscfpcq8"
...> Nostr.Keys.PublicKey.from_npub(npub)
{:ok, <<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>}
Link to this function

from_npub!(bech32_pubkey)

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

Converts a public key in the npub format into a binary public key that can be used with this lib

examples

Examples

iex> npub = "npub1d4ed5x49d7p24xn63flj4985dc4gpfngdhtqcxpth0ywhm6czxcscfpcq8"
...> Nostr.Keys.PublicKey.from_npub!(npub)
<<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>
Link to this function

from_private_key(private_key)

View Source
@spec from_private_key(K256.Schnorr.signing_key()) ::
  {:ok, K256.Schnorr.verifying_key()} | {:error, :signing_key_decoding_failed}

Issues the public key corresponding to a given private key

examples

Examples

iex> private_key = <<0xb6907368a945db7769b5eaecd73c3c175b77c64e1df3e9900acd66aeea7b53ab::256>>
...> Nostr.Keys.PublicKey.from_private_key(private_key)
{:ok, <<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>}
Link to this function

from_private_key!(private_key)

View Source
@spec from_private_key!(K256.Schnorr.signing_key()) :: K256.Schnorr.verifying_key()

Issues the public key corresponding to a given private key

examples

Examples

iex> private_key = <<0xb6907368a945db7769b5eaecd73c3c175b77c64e1df3e9900acd66aeea7b53ab::256>>
...> Nostr.Keys.PublicKey.from_private_key!(private_key)
<<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>
@spec to_npub(<<_::256>>) :: binary()

Encodes a public key into the npub format

examples

Examples

iex> public_key = <<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>
...> Nostr.Keys.PublicKey.to_npub(public_key)
"npub1d4ed5x49d7p24xn63flj4985dc4gpfngdhtqcxpth0ywhm6czxcscfpcq8"