View Source Nostr.Keys.PublicKey (Nostr v0.1.3)
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
Does its best to convert any public key format to binary, issues an error if it can't
Converts a public key into a string containing hex characters
Encodes a public key into the npub format
Link to this section Functions
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>>}
@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>>
@spec from_private_key(K256.Schnorr.signing_key()) :: {:ok, K256.Schnorr.verifying_key()} | {:error, String.t() | :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>>}
@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>>
Does its best to convert any public key format to binary, issues an error if it can't
examples
Examples
iex> "npub1mxrssnzg8y9zjr6a9g6xqwhxfa23xlvmftluakxqatsrp6ez9gjssu0htc"
...> |> Nostr.Keys.PublicKey.to_binary()
{ :ok, <<0xd987084c48390a290f5d2a34603ae64f55137d9b4affced8c0eae030eb222a25::256>> }
@spec to_hex(<<_::256>>) :: String.t()
Converts a public key into a string containing hex characters
examples
Examples
iex> public_key = <<0x6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1::256>>
...> Nostr.Keys.PublicKey.to_hex(public_key)
"6d72da1aa56f82aa9a7a8a7f2a94f46e2a80a6686dd60c182bbbc8ebef5811b1"
@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"