BSV v0.1.0-dev.1 BSV.KeyPair View Source
Module for generating and using Bitcoin key pairs.
Link to this section Summary
Functions
Converts ECDSA keys to a BSV key pair.
Generates a new BSV key pair.
Returns the Bitcoin address from the given key pair or public key.
Decodes the given Wallet Import Format (WIF) binary into a BSV key pair.
Encodes the given BSV key pair into a Wallet Import Format (WIF) binary.
Link to this section Types
BSV Key Pair
Link to this section Functions
Link to this function
from_ecdsa_key(key, options \\ [])
View Sourcefrom_ecdsa_key( BSV.Crypto.ECDSA.PrivateKey.t() | {binary(), binary()}, keyword() ) :: BSV.KeyPair.t()
Converts ECDSA keys to a BSV key pair.
Options
The accepted options are:
:compressed
- Specify whether to compress the given public key. Defaults totrue
.
Examples
iex> keypair =BSV.KeyPair.from_ecdsa_key(BSV.Test.bsv_keys)
...> (%BSV.KeyPair{} = keypair) == keypair
true
Generates a new BSV key pair.
Options
The accepted options are:
:compressed
- Specify whether to compress the generated public key. Defaults totrue
.
Examples
iex> keypair = BSV.KeyPair.generate
...> (%BSV.KeyPair{} = keypair) == keypair
true
Link to this function
get_address(key)
View Sourceget_address(BSV.KeyPair.t() | {binary(), binary()} | binary()) :: binary()
Returns the Bitcoin address from the given key pair or public key.
Examples
iex> BSV.Crypto.ECDSA.PrivateKey.from_sequence(BSV.Test.ecdsa_key)
...> |> BSV.KeyPair.from_ecdsa_key
...> |> BSV.KeyPair.get_address
"18cqNbEBxkAttxcZLuH9LWhZJPd1BNu1A5"
iex> BSV.Crypto.ECDSA.PrivateKey.from_sequence(BSV.Test.ecdsa_key)
...> |> BSV.KeyPair.from_ecdsa_key(compressed: false)
...> |> BSV.KeyPair.get_address
"1N5Cu7YUPQhcwZaQLDT5KnDpRVKzFDJxsf"
Decodes the given Wallet Import Format (WIF) binary into a BSV key pair.
Examples
iex> BSV.KeyPair.wif_decode("KyGHAK8MNohVPdeGPYXveiAbTfLARVrQuJVtd3qMqN41UEnTWDkF")
...> |> BSV.KeyPair.get_address
"18cqNbEBxkAttxcZLuH9LWhZJPd1BNu1A5"
iex> BSV.KeyPair.wif_decode("5JH9eTJyj6bYopGhBztsDd4XvAbFNQkpZEw8AXYoQePtK1r86nu")
...> |> BSV.KeyPair.get_address
"1N5Cu7YUPQhcwZaQLDT5KnDpRVKzFDJxsf"
Encodes the given BSV key pair into a Wallet Import Format (WIF) binary.
Examples
iex> BSV.Crypto.ECDSA.PrivateKey.from_sequence(BSV.Test.ecdsa_key)
...> |> BSV.KeyPair.from_ecdsa_key
...> |> BSV.KeyPair.wif_encode
"KyGHAK8MNohVPdeGPYXveiAbTfLARVrQuJVtd3qMqN41UEnTWDkF"
iex> BSV.Crypto.ECDSA.PrivateKey.from_sequence(BSV.Test.ecdsa_key)
...> |> BSV.KeyPair.from_ecdsa_key(compressed: false)
...> |> BSV.KeyPair.wif_encode
"5JH9eTJyj6bYopGhBztsDd4XvAbFNQkpZEw8AXYoQePtK1r86nu"