View Source Radixir.Key (radixir v0.0.3)

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.

Generates mainnet and testnet token rri from public_key and symbol.

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()

Specs

symbol() :: String.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: %{
    account_address: "rdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmceghq5a",
    node_address: "rn1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7mctqsv",
    validator_address: "rv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7rtpsuj"
  },
  testnet: %{
    account_address: "tdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmccyzjy7",
    node_address: "tn1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7apvxlm",
    validator_address: "tv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx79jxkn9"
  },
  private_key: "ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17",
  public_key: "032f9accc4f9906dffa212d5cef8f13c7faf600242ee44111d4dee4fcaf978646f"
}}

Specs

generate() :: keypair_and_addresses()

Generates a new keypair and addresses.

Link to this function

generate_token_rri(public_key, symbol)

View Source

Specs

generate_token_rri(public_key(), symbol()) ::
  {:ok, map()} | {:error, error_message()}

Generates mainnet and testnet token rri from public_key and symbol.

Parameters

  • public_key: Hex encoded public key.
  • synbol: Token symbol.

Examples

iex> Radixir.Key.generate_token_rri("02690937690ffb9d7ae8b67af05efc03a5a9f7e53933de80f92ce763a5554a1fa3","gok")
%{
  mainnet: "gok_rr1qdjusppk2dqe2r08xlnlauuaedn9rtuttz2c6g76jq3qee68dq",
  testnet: "gok_tr1qdjusppk2dqe2r08xlnlauuaedn9rtuttz2c6g76jq3qezz2ds"
}
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()) ::
  {:ok, 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")
{:ok,
%{
  mainnet: %{
    account_address: "rdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmceghq5a",
    node_address: "rn1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7mctqsv",
    validator_address: "rv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7rtpsuj"
  },
  testnet: %{
    account_address: "tdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmccyzjy7",
    node_address: "tn1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7apvxlm",
    validator_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"
}