View Source Radixir.Key (radixir v0.0.2)

Handles all things to do with public/private keys and radix addresses.

Link to this section Summary

Functions

Converts address to its public key.

Converts private_key to its keypair and addresses.

Generates a new keypair and addresses.

Converts private_key to its secret integer.

Converts public_key to its addresses.

Signs data with private_key.

Link to this section Types

Specs

address() :: String.t()

Specs

addresses() :: map()

Specs

data() :: String.t()

Specs

error_message() :: String.t()
Link to this type

keypair_and_addresses()

View Source

Specs

keypair_and_addresses() :: map()

Specs

private_key() :: String.t()

Specs

public_key() :: String.t()

Specs

signed_data() :: Stiring.t()

Link to this section Functions

Link to this function

address_to_public_key(address)

View Source

Specs

address_to_public_key(address()) :: {:ok, public_key()} | {:error, atom()}

Converts address to its public key.

Parameters

  • address: Radix address.

Examples

iex> Radixir.Key.address_to_public_key("tdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmccyzjy7")
{:ok,
  "032f9accc4f9906dffa212d5cef8f13c7faf600242ee44111d4dee4fcaf978646f"
}
Link to this function

from_private_key(private_key)

View Source

Specs

from_private_key(private_key()) ::
  {:ok, keypair_and_addresses()} | {:error, error_message()}

Converts private_key to its keypair and addresses.

Parameters

  • private_key: Hex encoded private key.

Examples

iex> Radixir.Key.from_private_key("ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17")
{:ok,
%{
  mainnet_address: "rdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmceghq5a",
  private_key: "ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17",
  public_key: "032f9accc4f9906dffa212d5cef8f13c7faf600242ee44111d4dee4fcaf978646f",
  testnet_address: "tdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmccyzjy7",
  validator_mainnet_address: "rv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7rtpsuj",
  validator_testnet_address: "tv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx79jxkn9"
  }
}

Specs

generate() :: keypair_and_addresses()

Generates a new keypair and addresses.

Link to this function

private_key_to_secret_integer(private_key)

View Source

Specs

private_key_to_secret_integer(private_key()) ::
  {:ok, non_neg_integer()} | {:error, error_message()}

Converts private_key to its secret integer.

Parameters

  • private_key: Hex encoded private key.

Examples

iex> Radixir.Key.private_key_to_secret_integer("ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17")
{:ok,
  107340927595134471984420820489673630767605194678966104711498635548873815202327
}
Link to this function

public_key_to_addresses(public_key)

View Source

Specs

public_key_to_addresses(public_key()) :: addresses() | {:error, error_message()}

Converts public_key to its addresses.

Parameters

  • public_key: Hex encoded public key.

Examples

iex> Radixir.Key.public_key_to_addresses("032f9accc4f9906dffa212d5cef8f13c7faf600242ee44111d4dee4fcaf978646f")
%{
  mainnet_address: "rdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmceghq5a",
  testnet_address: "tdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmccyzjy7",
  validator_mainnet_address: "rv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7rtpsuj",
  validator_testnet_address: "tv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx79jxkn9"
}
Link to this function

sign_data(data, private_key)

View Source

Specs

sign_data(data(), private_key()) ::
  {:ok, signed_data()} | {:error, error_message()}

Signs data with private_key.

Parameters

  • data: Hex encoded data to be signed.
  • private_key: Hex encoded private key.

Examples

iex> Radixir.Key.sign_data("68656C6C6F207261646978","ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17")
{:ok,
  "304402206f2c0f3a70c23879a44a2910f9b060e59d5b96e350605fdbee2a7a265ca503c302201043a8a957353744608c86824c286034e6166be475c7c096527a225cbdf90d0a"
}