View Source Radixir.Key (radixir v0.0.5)
Handles all things to do with mnemonics, keys and addresses.
Link to this section Summary
Functions
Generates addresses from master public key.
Converts address
to its public key.
Derives account extended private key and account extended public key from mnemonic.
Derives mainnet and testnet token rri from public_key
and symbol
.
Derives a keypair and addresses from account extended private key.
Derives a keypair and addresses from mnemonic.
Derives keypair and addresses from private key.
Generates a new keypair and addresses.
Generates a new mnemonic.
Converts private_key
to its secret integer.
Converts public_key
to its addresses.
Signs data
with private_key
.
Link to this section Types
@type account_extended_private_key() :: String.t()
@type account_extended_public_key() :: String.t()
@type address() :: String.t()
@type address_index() :: integer()
@type addresses() :: map()
@type data() :: String.t()
@type error_message() :: String.t()
@type options() :: keyword()
@type private_key() :: String.t()
@type public_key() :: String.t()
@type signed_data() :: Stiring.t()
@type symbol() :: String.t()
Link to this section Functions
account_extended_public_key_to_addresses(account_extended_public_key, address_index \\ 0)
View Source@spec account_extended_public_key_to_addresses( account_extended_public_key(), address_index() ) :: {:ok, map()} | {:error, error_message()}
Generates addresses from master public key.
parameters
Parameters
account_extended_public_key
: Master public key.address_index
: Address index.
examples
Examples
iex> Radixir.Key.account_extended_public_key_to_addresses("xpub6BucvERR84wuK71ffTMSZ6j7NJeQZdcEJWKtqF1gq7VrwBmhxgzpUKNK1P6jR2iWRMUagy94y9XK3wG3hUtAoVLVyQ3nSwA9pzepBCb2rRK", 1)
{:ok,
%{
mainnet: %{
account_address: "rdx1qspr0yphjarred20cr9vyy6h8ky60wun5t8z7g3lm3z25klf4yulmwgmwg5c8",
node_address: "rn1qgmeqduhgc7t2n7qetppx4ea3xnmhyazechjy07ugj49h6df887mjqymm42",
validator_address: "rv1qgmeqduhgc7t2n7qetppx4ea3xnmhyazechjy07ugj49h6df887mjch3te5"
},
testnet: %{
account_address: "tdx1qspr0yphjarred20cr9vyy6h8ky60wun5t8z7g3lm3z25klf4yulmwg6zaxgy",
node_address: "tn1qgmeqduhgc7t2n7qetppx4ea3xnmhyazechjy07ugj49h6df887mjxaua6a",
validator_address: "tv1qgmeqduhgc7t2n7qetppx4ea3xnmhyazechjy07ugj49h6df887mj7wkdkr"
}
}}
@spec address_to_public_key(address()) :: {:ok, public_key()} | {:error, atom()}
Converts address
to its public key.
parameters
Parameters
address
: Radix address.
examples
Examples
iex> Radixir.Key.address_to_public_key("tdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmccyzjy7")
{:ok,
"032f9accc4f9906dffa212d5cef8f13c7faf600242ee44111d4dee4fcaf978646f"
}
@spec derive_account_extended_keys_from_mnemonic(options()) :: {:ok, map()} | {:error, error_message()}
Derives account extended private key and account extended public key from mnemonic.
parameters
Parameters
options
: Keyword list that containsmnemonic
(optional, string): Ifmnemonic
is not inoptions
then the mnemonic set in the configs will be used.account_index
(optional, integer): Ifaccount_index
is not inoptions
then anaccount_index
of 0 will be used.
examples
Examples
iex> Radixir.Key.derive_account_extended_keys_from_mnemonic(mnemonic: "nurse grid sister metal flock choice system control about mountain sister rapid hundred render shed chicken print cover tape sister zero bronze tattoo stairs", account_index: 1)
%{
account_extended_private_key: "xprv9xvGWitXHhPc6cwCZRpSBxnNpGovAAtNwHQJ2rc5Gmxt4PSZR9gZvX3qA614mU9EyZaFxcHnFWmdZAKFu1WiritR9UMGXL5drySpT1pRSFz",
account_extended_public_key: "xpub6BucvERR84wuK71ffTMSZ6j7NJeQZdcEJWKtqF1gq7VrwBmhxgzpUKNK1P6jR2iWRMUagy94y9XK3wG3hUtAoVLVyQ3nSwA9pzepBCb2rRK"
}
@spec derive_token_rri(public_key(), symbol()) :: {:ok, map()} | {:error, error_message()}
Derives mainnet and testnet token rri from public_key
and symbol
.
parameters
Parameters
public_key
: Hex encoded public key.synbol
: Token symbol.
examples
Examples
iex> Radixir.Key.derive_token_rri("02690937690ffb9d7ae8b67af05efc03a5a9f7e53933de80f92ce763a5554a1fa3","gok")
{:ok,
%{
mainnet: "gok_rr1qdjusppk2dqe2r08xlnlauuaedn9rtuttz2c6g76jq3qee68dq",
testnet: "gok_tr1qdjusppk2dqe2r08xlnlauuaedn9rtuttz2c6g76jq3qezz2ds"
}}
from_account_extended_private_key(account_extended_private_key, address_index \\ 0)
View Source@spec from_account_extended_private_key( account_extended_private_key(), address_index() ) :: {:ok, map()} | {:error, error_message()}
Derives a keypair and addresses from account extended private key.
parameters
Parameters
account_extended_private_key
: Account extended private key.address_index
: Address index.
examples
Examples
iex> Radixir.Key.from_account_extended_private_key("xprv9xvGWitXHhPc4R9opoQJrA5xfvUsXzdS9gEsEE8AVk1rbdHxcjngXHJ971JC7ensJS6u5XT7wNo23smXy1KfSmmffZWMyCDsfQQaQ2QPr5z", 1)
{:ok,
%{
mainnet: %{
account_address: "rdx1qspgw45trvgp9nd7ca9vznrmq0cqy44du60utqmj3f0xp404gx04mwq28puxy",
node_address: "rn1q2r4dzcmzqfvm0k8ftq5c7cr7qp9dt0xnlzcxu52tesdta2pnawmsv4kwd6",
validator_address: "rv1q2r4dzcmzqfvm0k8ftq5c7cr7qp9dt0xnlzcxu52tesdta2pnawms5xu7py"
},
private_key: "f7b9e64ce04a7c6ad62520e14d787b3109e9b3317483da0bc970d4d6e59e866a",
public_key: "0287568b1b1012cdbec74ac14c7b03f00256ade69fc583728a5e60d5f5419f5db8",
testnet: %{
account_address: "tdx1qspgw45trvgp9nd7ca9vznrmq0cqy44du60utqmj3f0xp404gx04mwqtt5wk8",
node_address: "tn1q2r4dzcmzqfvm0k8ftq5c7cr7qp9dt0xnlzcxu52tesdta2pnawms2v3gzd",
validator_address: "tv1q2r4dzcmzqfvm0k8ftq5c7cr7qp9dt0xnlzcxu52tesdta2pnawmsjlmcwn"
}
}}
@spec from_mnemonic(options()) :: {:ok, map()} | {:error, error_message()}
Derives a keypair and addresses from mnemonic.
parameters
Parameters
options
: Keyword list that containsmnemonic
(optional, string): Ifmnemonic
is not inoptions
then the mnemonic set in the configs will be used.account_index
(optional, integer): Ifaccount_index
is not inoptions
then anaccount_index
of 0 will be used.address_index
(optional, integer): Ifaddress_index
is not inoptions
then anaddress_index
of 0 will be used.
examples
Examples
iex> Radixir.Key.from_mnemonic(mnemonic: "nurse grid sister metal flock choice system control about mountain sister rapid hundred render shed chicken print cover tape sister zero bronze tattoo stairs", account_index: 0, address_index: 0)
{:ok,
%{
mainnet: %{
account_address: "rdx1qspdkgfmwl656m4nvejgskjrzhp27auwefswhvaztzfamgse2mk8t6gt2apaj",
node_address: "rn1qtdjzwmh74xkavmxvjy95sc4c2hh0rk2vr4m8gjcj0w6yx2ka367jtmsh45",
validator_address: "rv1qtdjzwmh74xkavmxvjy95sc4c2hh0rk2vr4m8gjcj0w6yx2ka367jng68e2"
},
private_key: "9dd06ce00e682e5b6e5e16ced5d90316ddc19a12d0cdeefc223cfd6920aee54b",
public_key: "02db213b77f54d6eb36664885a4315c2af778eca60ebb3a25893dda21956ec75e9",
testnet: %{
account_address: "tdx1qspdkgfmwl656m4nvejgskjrzhp27auwefswhvaztzfamgse2mk8t6g2xgnd3",
node_address: "tn1qtdjzwmh74xkavmxvjy95sc4c2hh0rk2vr4m8gjcj0w6yx2ka367jdzh36r",
validator_address: "tv1qtdjzwmh74xkavmxvjy95sc4c2hh0rk2vr4m8gjcj0w6yx2ka367j43apka"
}
}}
@spec from_private_key(private_key()) :: {:ok, map()} | {:error, error_message()}
Derives keypair and addresses from private key.
parameters
Parameters
private_key
: Private key.
examples
Examples
iex> Radixir.Key.from_private_key("ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17")
{:ok,
%{
mainnet: %{
account_address: "rdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmceghq5a",
node_address: "rn1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7mctqsv",
validator_address: "rv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7rtpsuj"
},
private_key: "ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17",
public_key: "032f9accc4f9906dffa212d5cef8f13c7faf600242ee44111d4dee4fcaf978646f",
testnet: %{
account_address: "tdx1qspjlxkvcnueqm0l5gfdtnhc7y78ltmqqfpwu3q3r4x7un72l9uxgmccyzjy7",
node_address: "tn1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx7apvxlm",
validator_address: "tv1qvhe4nxylxgxmlazzt2ua78383l67cqzgthygygafhhyljhe0pjx79jxkn9"
}
}}
@spec generate() :: map()
Generates a new keypair and addresses.
examples
Examples
Radixir.Key.generate()
%{
mainnet: %{
account_address: "rdx1qsp6sg72yg8hpznc60hsy4jmjqyknst2sfswu5h9xv5knyntemgvnesrl9mr9",
node_address: "rn1qw5z8j3zpacg57xnaup9vkusp95uz65zvrh99efn995ey67w6ry7vqje79j",
validator_address: "rv1qw5z8j3zpacg57xnaup9vkusp95uz65zvrh99efn995ey67w6ry7vcpnwfv"
},
private_key: "519b6c5c1db1fab3e8513ad18b419082c81844ef66b24f850f9ab7366f7efc34",
public_key: "03a823ca220f708a78d3ef02565b900969c16a8260ee52e5332969926bced0c9e6",
testnet: %{
account_address: "tdx1qsp6sg72yg8hpznc60hsy4jmjqyknst2sfswu5h9xv5knyntemgvnesznsfnx",
node_address: "tn1qw5z8j3zpacg57xnaup9vkusp95uz65zvrh99efn995ey67w6ry7vxt7c29",
validator_address: "tv1qw5z8j3zpacg57xnaup9vkusp95uz65zvrh99efn995ey67w6ry7v7c5gxm"
}
}
@spec generate_mnemonic() :: String.t()
Generates a new mnemonic.
examples
Examples
Radixir.Key.generate_mnemonic()
"rival glimpse kick start glide fix school cook adult pulse property chef garden hobby attract market market broom position truly shell diagram throw invite"
@spec private_key_to_secret_integer(private_key()) :: {:ok, non_neg_integer()} | {:error, error_message()}
Converts private_key
to its secret integer.
parameters
Parameters
private_key
: Hex encoded private key.
examples
Examples
iex> Radixir.Key.private_key_to_secret_integer("ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17")
{:ok,
107340927595134471984420820489673630767605194678966104711498635548873815202327
}
@spec public_key_to_addresses(public_key()) :: {:ok, addresses()} | {:error, error_message()}
Converts public_key
to its addresses.
parameters
Parameters
public_key
: Hex encoded public key.
examples
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"
}
}}
@spec sign_data(data(), private_key()) :: {:ok, signed_data()} | {:error, error_message()}
Signs data
with private_key
.
parameters
Parameters
data
: Hex encoded data to be signed.private_key
: Hex encoded private key.
examples
Examples
iex> Radixir.Key.sign_data("68656C6C6F207261646978","ed50cfe0904bfbf7668502a3f7d562c3139997255c3268c779eeff04a40f9a17")
{:ok,
"304402206f2c0f3a70c23879a44a2910f9b060e59d5b96e350605fdbee2a7a265ca503c302201043a8a957353744608c86824c286034e6166be475c7c096527a225cbdf90d0a"
}