class Secp256k1::Bitcoin::Account
- Secp256k1::Bitcoin::Account
- Reference
- Object
Overview
Implements a Bitcoin
account containing a Keypair
, a Wallet-Import Format,
and an address.
Properties:
#key_pair
(Keypair
): theKeypair
containing the secret key.#version
(String
): the version byte determining the used network encoding.#compressed
(Bool
): an indicator whether a compressed format should be used.#address
(String
): the publicBitcoin
address.#wif
(String
): the private Wallet-Import Format (WIF).
btc = Secp256k1::Bitcoin::Account.new
btc.wif
# => "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
btc.address
# => "1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC"
Defined in:
bitcoin.crConstructors
-
.new(key_pair : Secp256k1::Keypair, version : String, compressed : Bool)
Generates a
Bitcoin::Account
from a providedKeypair
allowing for a custom network version byte and compression. -
.new(key_pair : Secp256k1::Keypair, version : String)
Generates a
Bitcoin::Account
from a providedKeypair
allowing for a custom network version byte. -
.new(key_pair : Secp256k1::Keypair)
Generates a
Bitcoin::Account
from a providedKeypair
. -
.new
Generates a new
Bitcoin::Account
from a fresh randomKeypair
.
Instance Method Summary
-
#address : String
The public
Bitcoin
address. -
#address=(address : String)
The public
Bitcoin
address. -
#compressed : Bool
An indicator whether a compressed format should be used.
-
#compressed=(compressed : Bool)
An indicator whether a compressed format should be used.
-
#get_secret
Gets the private key as hexadecimal formatted string literal.
-
#is_compressed? : Bool
Tells if the
Bitcoin::Account
is compressed. -
#key_pair : Keypair
The
Keypair
containing the secret key. -
#key_pair=(key_pair : Keypair)
The
Keypair
containing the secret key. -
#to_s : String
Gets the account formatted as
Bitcoin
address. -
#version : String
The version byte determining the used network encoding.
-
#version=(version : String)
The version byte determining the used network encoding.
-
#version_wif
Computes the version byte for the private Wallet-Import Format which is offset by
+ 0x80
from the public address#version
byte. -
#wif : String
The private Wallet-Import Format (WIF).
-
#wif=(wif : String)
The private Wallet-Import Format (WIF).
Constructor Detail
Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom
network version byte and compression.
Parameters:
#key_pair
(Keypair
): theKeypair
containing the secret key.#version
(String
): the version byte determining the used network encoding.#compressed
(Bool
): an indicator whether a compressed format should be used.
key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
btc = Secp256k1::Bitcoin::Account.new key, "00", true
# => #<Secp256k1::Bitcoin::Account:0x7f81ef21ab80>
Raises if the version byte is out of range.
Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom
network version byte.
Parameters:
#key_pair
(Keypair
): theKeypair
containing the secret key.#version
(String
): the version byte determining the used network encoding.
key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
btc = Secp256k1::Bitcoin::Account.new key, "1e"
# => #<Secp256k1::Bitcoin::Account:0x7f81ef21ab80>
Note, this always generates an uncompressed account for the specified network.
Raises if the version byte is out of range.
Generates a Bitcoin::Account
from a provided Keypair
.
Parameters:
key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
btc = Secp256k1::Bitcoin::Account.new key
# => #<Secp256k1::Bitcoin::Account:0x7f81ef21ab80>
Note, this always generates an uncompressed mainnet Bitcoin account.
Generates a new Bitcoin::Account
from a fresh random Keypair
.
btc = Secp256k1::Bitcoin::Account.new
# => #<Secp256k1::Bitcoin::Account:0x7f81ef21ab80>
Note, this always generates an uncompressed mainnet Bitcoin account.
Instance Method Detail
Gets the private key as hexadecimal formatted string literal.
btc.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
Tells if the Bitcoin::Account
is compressed.
btc.is_compressed?
# => false
Returns true if the compressed format is used.
Gets the account formatted as Bitcoin
address.
btc.to_s
# => "1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC"