class Secp256k1::Bitcoin::Account

Overview

Implements a Bitcoin account containing a Keypair, a Wallet-Import Format, and an address.

Properties:

btc = Secp256k1::Bitcoin::Account.new
btc.wif
# => "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
btc.address
# => "1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC"

Defined in:

bitcoin.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(key_pair, version, compressed) #

Generates a Bitcoin::Account from a provided Keypair allowing for a custom network version byte and compression.

Parameters:

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.


[View source]
def self.new(key_pair, version) #

Generates a Bitcoin::Account from a provided Keypair allowing for a custom network version byte.

Parameters:

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.


[View source]
def self.new(key_pair) #

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.


[View source]
def self.new #

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.


[View source]

Instance Method Detail

def address : String #

The public Bitcoin address.


[View source]
def address=(address : String) #

The public Bitcoin address.


[View source]
def compressed : Bool #

An indicator whether a compressed format should be used.


[View source]
def compressed=(compressed : Bool) #

An indicator whether a compressed format should be used.


[View source]
def get_secret #

Gets the private key as hexadecimal formatted string literal.

btc.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"

[View source]
def is_compressed? : Bool #

Tells if the Bitcoin::Account is compressed.

btc.is_compressed?
# => false

Returns true if the compressed format is used.


[View source]
def key_pair : Keypair #

The Keypair containing the secret key.


[View source]
def key_pair=(key_pair : Keypair) #

The Keypair containing the secret key.


[View source]
def to_s : String #

Gets the account formatted as Bitcoin address.

btc.to_s
# => "1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC"

[View source]
def version : String #

The version byte determining the used network encoding.


[View source]
def version=(version : String) #

The version byte determining the used network encoding.


[View source]
def version_wif #

Computes the version byte for the private Wallet-Import Format which is offset by + 0x80 from the public address #version byte.

btc.version_wif
# => "80"

[View source]
def wif : String #

The private Wallet-Import Format (WIF).


[View source]
def wif=(wif : String) #

The private Wallet-Import Format (WIF).


[View source]