Tradehub.Wallet (Tradehub v0.1.7) View Source
This module aims to signing, generating, and interacting with a Tradehub account.
Link to this section Summary
Functions
Look for the wallet address based on the given mnemonic phrase within a network.
Look for the wallet address based on the given public key within a network.
Look for the wallet address of based on the given public key within a network.
Generate a new Tradehub wallet
Encode a map to JSON with all of the keys in alphabetical order (nested included).
Open a wallet based on its mnemonic.
Open a wallet based on its private key.
Look for the private key based on the given mnemonic phrase.
Look for the public key based on the given mnemonic phrase.
Look for the public key based on the given private key phrase.
Sign the given message by using a wallet private key, and verify the signed messaged by using the wallet public key.
Link to this section Types
Specs
Link to this section Functions
Specs
Look for the wallet address based on the given mnemonic phrase within a network.
Examples
iex> Tradehub.Wallet.address_from_mnemonic("wrist coyote fuel wet evil tag shoot yellow morning history visit mosquito")
{:ok, "tswth174cz08dmgluavwcz2suztvydlptp4a8f8t5h4t"}
iex> Tradehub.Wallet.address_from_mnemonic("wrist coyote fuel wet evil tag shoot yellow morning history visit mosquito", :mainnet)
{:ok, "swth174cz08dmgluavwcz2suztvydlptp4a8fru98vw"}
iex> Tradehub.Wallet.address_from_mnemonic("wrost coyote fuel wet evil tag shoot yellow morning history visit mosquito")
{:error, "Invalid mnemonic"}
Specs
address_from_private_key(String.t() | bitstring(), atom()) :: {:ok, String.t()} | {:error, String.t()}
Look for the wallet address based on the given public key within a network.
Examples
iex> Tradehub.Wallet.address_from_private_key("151f85d41358f56d14bec4846c5370a3ae4f34decba71d48feac75ecbf6c8ca1")
{:ok, "tswth174cz08dmgluavwcz2suztvydlptp4a8f8t5h4t"}
iex> Tradehub.Wallet.address_from_private_key(<<21, 31, 133, 212, 19, 88, 245, 109, 20, 190, 196, 132, 108, 83, 112, 163, 174, 79, 52, 222, 203, 167, 29, 72, 254, 172, 117, 236, 191, 108, 140, 161>>)
{:ok, "tswth174cz08dmgluavwcz2suztvydlptp4a8f8t5h4t"}
iex> Tradehub.Wallet.address_from_private_key("151f85d41358f56d14bec4846c5370a3ae4f34decba71d48feac75ecbf6c8ca1", :mainnet)
{:ok, "swth174cz08dmgluavwcz2suztvydlptp4a8fru98vw"}
Specs
Look for the wallet address of based on the given public key within a network.
Examples
iex> Tradehub.Wallet.address_from_public_key("02e6193b57b672df29997fe495d78b4fd3eaae9daae0a5e2803129e2c21b504e23")
{:ok, "tswth174cz08dmgluavwcz2suztvydlptp4a8f8t5h4t"}
iex> Tradehub.Wallet.address_from_public_key(<<2, 230, 25, 59, 87, 182, 114, 223, 41, 153, 127, 228, 149, 215, 139, 79, 211, 234, 174, 157, 170, 224, 165, 226, 128, 49, 41, 226, 194, 27, 80, 78, 35>>)
{:ok, "tswth174cz08dmgluavwcz2suztvydlptp4a8f8t5h4t"}
iex> Tradehub.Wallet.address_from_public_key("02e6193b57b672df29997fe495d78b4fd3eaae9daae0a5e2803129e2c21b504e23", :mainnet)
{:ok, "swth174cz08dmgluavwcz2suztvydlptp4a8fru98vw"}
Specs
Generate a new Tradehub wallet
Examples
iex> Tradehub.Wallet.create_wallet
iex> Tradehub.Wallet.create_wallet(:testnet)
Encode a map to JSON with all of the keys in alphabetical order (nested included).
Examples
iex> Tradehub.Wallet.encode_object_in_alphanumeric_key_order(%{b: 1, c: 2, a: 3, d: 4})
"{\"a\":3,\"b\":1,\"c\":2,\"d\":4}"
iex> Tradehub.Wallet.encode_object_in_alphanumeric_key_order(%{b: %{e: 1, f: 2}, c: 2, a: 3, d: 4})
"{\"a\":3,\"b\":{\"e\":1,\"f\":2},\"c\":2,\"d\":4}"
iex> Tradehub.Wallet.encode_object_in_alphanumeric_key_order("")
"\"\""
Specs
Open a wallet based on its mnemonic.
Examples
iex> {:ok, wallet} = Tradehub.Wallet.from_mnemonic("wrist coyote fuel wet evil tag shoot yellow morning history visit mosquito")
iex> wallet.address
"tswth174cz08dmgluavwcz2suztvydlptp4a8f8t5h4t"
iex> {:ok, wallet} = Tradehub.Wallet.from_mnemonic("wrist coyote fuel wet evil tag shoot yellow morning history visit mosquito", :mainnet)
iex> wallet.address
"swth174cz08dmgluavwcz2suztvydlptp4a8fru98vw"
Specs
Open a wallet based on its private key.
Examples
iex> Tradehub.Wallet.from_private_key("151f85d41358f56d14bec4846c5370a3ae4f34decba71d48feac75ecbf6c8ca1")
Specs
Look for the private key based on the given mnemonic phrase.
Examples
iex> Tradehub.Wallet.private_key_from_mnemonic("wrist coyote fuel wet evil tag shoot yellow morning history visit mosquito")
{:ok, <<21, 31, 133, 212, 19, 88, 245, 109, 20, 190, 196, 132, 108, 83, 112, 163, 174, 79, 52, 222, 203, 167, 29, 72, 254, 172, 117, 236, 191, 108, 140, 161>>}
iex> Tradehub.Wallet.private_key_from_mnemonic("clumb twenty either puppy thank liquid vital rigid tide tragic flash elevator")
{:error, "Invalid mnemonic"}
Specs
Look for the public key based on the given mnemonic phrase.
Examples
iex> Tradehub.Wallet.public_key_from_mnemonic("wrist coyote fuel wet evil tag shoot yellow morning history visit mosquito")
{:ok, <<2, 230, 25, 59, 87, 182, 114, 223, 41, 153, 127, 228, 149, 215, 139, 79, 211, 234, 174, 157, 170, 224, 165, 226, 128, 49, 41, 226, 194, 27, 80, 78, 35>>}
Specs
Look for the public key based on the given private key phrase.
Examples
iex> Tradehub.Wallet.public_key_from_private_key("151f85d41358f56d14bec4846c5370a3ae4f34decba71d48feac75ecbf6c8ca1")
{:ok, <<2, 230, 25, 59, 87, 182, 114, 223, 41, 153, 127, 228, 149, 215, 139, 79, 211, 234, 174, 157, 170, 224, 165, 226, 128, 49, 41, 226, 194, 27, 80, 78, 35>>}
Specs
sign(map(), %Tradehub.Wallet{ address: term(), mnemonic: term(), network: term(), private_key: term(), public_key: term() }) :: {:ok, String.t()} | {:error, String.t()}
Sign the given message by using a wallet private key, and verify the signed messaged by using the wallet public key.
Due to the nature of blockchain, the message will sign by the curve digital signature algorithm (ECDSA), with curve
is secp256k1
and the hash algorithm is sha256
.
Examples
iex> wallet = Tradehub.Wallet.create_wallet()
iex> Tradehub.Wallet.sign(%{message: "hello world"}, wallet)