bsv_rpc v1.0.0-alpha3 BsvRpc.PrivateKey View Source
Function for Bitcoin private key manipulation.
A private key struct can be created using BsvRpc.PrivateKey.create/2
:
iex> BsvRpc.PrivateKey.create(<<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56, 93, 12, 228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>, :mainnet) {:ok,
%BsvRpc.PrivateKey{
key: <<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56,
93, 12, 228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>,
network: :mainnet,
}
}
or from a HD extended key using BsvRpc.PrivateKey.create/1
:
iex> words = "battle reunion keep inflict pair speed parade piece chimney leisure fiber miracle survey parade drift grocery lumber pumpkin pretty utility help party board turkey" iex> seed = Mnemonic.to_seed(words, "", :english) iex> master = ExtendedKey.master(seed) iex> BsvRpc.PrivateKey.create(master) {:ok,
%BsvRpc.PrivateKey{
key: <<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56, 93, 12,
228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>,
network: :mainnet,
}
}
Link to this section Summary
Functions
Creates a private key from a HD extended key.
Creates a private key.
Creates a private key from a HD extended key.
Creates a private key.
Link to this section Types
t()
View Sourcet() :: %BsvRpc.PrivateKey{key: binary(), network: :mainnet | :testnet}
A private key.
Link to this section Functions
create(key)
View Sourcecreate(ExtendedKey.key()) :: {:ok, BsvRpc.PrivateKey.t()}
Creates a private key from a HD extended key.
Examples
iex> words = "battle reunion keep inflict pair speed parade piece chimney leisure fiber miracle survey parade drift grocery lumber pumpkin pretty utility help party board turkey" iex> seed = Mnemonic.to_seed(words, "", :english) iex> master = ExtendedKey.master(seed) iex> BsvRpc.PrivateKey.create(master) {:ok,
%BsvRpc.PrivateKey{
key: <<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56, 93, 12,
228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>,
network: :mainnet,
}
}
create(key, network)
View Sourcecreate(binary(), :mainnet | :testnet) :: {:ok, BsvRpc.PrivateKey.t()} | {:error, String.t()}
Creates a private key.
Examples
iex> BsvRpc.PrivateKey.create(<<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56, 93, 12, 228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>, :mainnet) {:ok,
%BsvRpc.PrivateKey{
key: <<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56,
93, 12, 228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>,
network: :mainnet,
}
}
iex> BsvRpc.PrivateKey.create("C827815BB4A66A604B91E54F6B2674F0385D0CE43FFE80D3369CB5CD15BD0198", :mainnet) {:ok,
%BsvRpc.PrivateKey{
key: <<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56,
93, 12, 228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>,
network: :mainnet,
}
}
Creates a private key from a HD extended key.
Works similar to create/1
with the exception being thrown in case of an error.
Examples
iex> words = "battle reunion keep inflict pair speed parade piece chimney leisure fiber miracle survey parade drift grocery lumber pumpkin pretty utility help party board turkey" iex> seed = Mnemonic.to_seed(words, "", :english) iex> master = ExtendedKey.master(seed) iex> BsvRpc.PrivateKey.create!(master) %BsvRpc.PrivateKey{
key: <<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56, 93, 12,
228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>,
network: :mainnet,
}
create!(key, network)
View Sourcecreate!(binary(), :mainnet | :testnet) :: BsvRpc.PrivateKey.t()
Creates a private key.
Works similar to create/2
with the exception being thrown in case of an error.
Examples
iex> BsvRpc.PrivateKey.create!(<<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56, 93, 12, 228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>, :mainnet) %BsvRpc.PrivateKey{
key: <<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56,
93, 12, 228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>,
network: :mainnet,
}
iex> BsvRpc.PrivateKey.create!("C827815BB4A66A604B91E54F6B2674F0385D0CE43FFE80D3369CB5CD15BD0198", :mainnet) %BsvRpc.PrivateKey{
key: <<200, 39, 129, 91, 180, 166, 106, 96, 75, 145, 229, 79, 107, 38, 116, 240, 56,
93, 12, 228, 63, 254, 128, 211, 54, 156, 181, 205, 21, 189, 1, 152>>,
network: :mainnet,
}