BSV-ex v0.2.2 BSV.KeyPair View Source

Module for generating and using Bitcoin key pairs.

Bitcoin keys are ECDSA keys. Virtually any 256-bit number is a valid private key, and the corresponding point on the `secp256k1` curve is the public key.

Link to this section Summary

Types

t()

BSV Key Pair

Functions

Converts ECDSA keys to a BSV key pair.

Generates a new BSV key pair.

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

Link to this type

t()

View Source
t() :: %BSV.KeyPair{
  network: term(),
  private_key: binary(),
  public_key: binary()
}

BSV Key Pair

Link to this section Functions

Link to this function

from_ecdsa_key(key, options \\ [])

View Source
from_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 to `true`.

Examples

iex> keypair = BSV.KeyPair.from_ecdsa_key(BSV.Test.bsv_keys)
...> keypair.__struct__ == BSV.KeyPair
true
Link to this function

generate(options \\ [])

View Source
generate(keyword()) :: BSV.KeyPair.t()

Generates a new BSV key pair.

Options

The accepted options are:

  • `:compressed` - Specify whether to compress the generated public key. Defaults to `true`.

Examples

iex> keypair = BSV.KeyPair.generate
...> keypair.__struct__ == BSV.KeyPair
true

Decodes the given Wallet Import Format (WIF) binary into a BSV key pair.

Examples

iex> BSV.KeyPair.wif_decode("KyGHAK8MNohVPdeGPYXveiAbTfLARVrQuJVtd3qMqN41UEnTWDkF")
...> |> BSV.Address.from_public_key
...> |> BSV.Address.to_string
"18cqNbEBxkAttxcZLuH9LWhZJPd1BNu1A5"

iex> BSV.KeyPair.wif_decode("5JH9eTJyj6bYopGhBztsDd4XvAbFNQkpZEw8AXYoQePtK1r86nu")
...> |> BSV.Address.from_public_key
...> |> BSV.Address.to_string
"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"