module Secp256k1::Bitcoin
Overview
Implements the Bitcoin
address space for the Secp256k1
library.
Defined in:
bitcoin.crClass Method Summary
-
.address_from_private(priv : BigInt, version = "00", compressed = true)
Generates a
Bitcoin
address from a private key. -
.address_from_public_key(pub : String, version = "00")
Generates a
Bitcoin
address for any public key, compressed or uncompressed. - .address_from_public_point(p : Secp256k1::EC_Point, version = "00", compressed = true)
-
.address_from_wif(wif : String)
Gets a
Bitcoin
address from a Base-58 Wallet-Import Format (WIF). -
.is_wif_compressed?(wif : String)
Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).
-
.mini_is_valid?(m : String)
Validates wether a mini-private key has a correct checksum and formatting.
-
.new_mini_private_key
Generates a new mini-private key (30 characters length, Base-56 encoded).
-
.private_key_from_mini(m : String)
Gets a private key from a mini-private key if the key is valid.
-
.private_key_from_wif(wif : String)
Gets a private key from a Base-58 Wallet-Import Format (WIF).
-
.version_byte_from_wif(wif : String)
Gets the version byte from a Base-58 Wallet-Import Format (WIF).
-
.wif_from_private(k : BigInt, version = "80", compr = "")
Gets a Base-58 Wallet-Import Format (WIF) from a private key.
-
.wif_from_private_compressed(k : BigInt, version = "80")
Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.
-
.wif_from_private_uncompressed(k : BigInt, version = "80")
Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.
-
.wif_is_valid?(wif : String)
Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.
Class Method Detail
Generates a Bitcoin
address from a private key.
Parameters:
priv
(BigInt
): the private key as number.version
(String
): the version byte, default:"00"
(Bitcoin).compressed
(Bool
): indicator if address should be compressed or not, default:true
(compressed).
Secp256k1::Bitcoin.address_from_private BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
# => "1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN"
Generates a Bitcoin
address for any public key, compressed or uncompressed.
Parameters:
pub
(String
): the public key, compressed or uncompressed.version
(String
): the version byte, default:"00"
(Bitcoin).
Secp256k1::Bitcoin.address_from_public_key "03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b"
# => "1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN"
Note, compressed public keys generate compressed addresses, whereas uncompressed keys generate uncompressed addresses.
Raises if the public key is malformed.
Generates a Bitcoin
address from an public key as EC_Point
.
Parameters:
p
(EC_Point
): the public key as point withx
andy
coordinates.version
(String
): the version byte, default:"00"
(Bitcoin).compressed
(Bool
): indicator if address should be compressed or not, default:true
(compressed).
See .address_from_public_key
and EC_Point
for usage instructions.
Gets a Bitcoin
address from a Base-58 Wallet-Import Format (WIF).
Parameters:
wif
(String
): the Base-58 Wallet-Import Format (WIF).
Secp256k1::Bitcoin.address_from_wif "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
# => "1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC"
Raises if Wallet-Import Format (WIF) is invalid.
Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).
Parameters:
wif
(String
): the Base-58 Wallet-Import Format (WIF).
Secp256k1::Bitcoin.is_wif_compressed? "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
# => false
Returns true if the key is compressed.
Raises if Wallet-Import Format (WIF) is invalid.
Validates wether a mini-private key has a correct checksum and formatting.
Parameters:
m
(String
): the mini-private key.
Secp256k1::Bitcoin.mini_is_valid? "S7qq5k98DAvee6mtQgpg4xAJatT9mR"
# => true
Returns true if the key contains a valid checksum and is formatted correctly.
Generates a new mini-private key (30 characters length, Base-56 encoded).
Secp256k1::Bitcoin.new_mini_private_key
# => S7qq5k98DAvee6mtQgpg4xAJatT9mR
Gets a private key from a mini-private key if the key is valid.
Parameters:
m
(String
): the mini-private key.
Secp256k1::Bitcoin.private_key_from_mini "S7qq5k98DAvee6mtQgpg4xAJatT9mR"
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
Raises if the key is invalid.
Gets a private key from a Base-58 Wallet-Import Format (WIF).
Parameters:
wif
(String
): the Base-58 Wallet-Import Format (WIF).
Secp256k1::Bitcoin.private_key_from_wif "Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu"
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
Raises if Wallet-Import Format (WIF) is invalid.
Gets the version byte from a Base-58 Wallet-Import Format (WIF).
Parameters:
wif
(String
): the Base-58 Wallet-Import Format (WIF).
Secp256k1::Bitcoin.version_byte_from_wif "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
# => "80"
Raises if Wallet-Import Format (WIF) is invalid.
Gets a Base-58 Wallet-Import Format (WIF) from a private key.
Parameters:
k
(BigInt
): the private key.version
(String
): the version byte, default:"80"
(Bitcoin).compr
(String
): the compression byte, default:""
(uncompressed).
Secp256k1::Bitcoin.wif_from_private BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
# => "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
Note, the compression byte compr
is either empty ""
for uncompressed keys or
"01"
for compressed keys. See also .wif_from_private_compressed
and .wif_from_private_uncompressed
.
Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.
Parameters:
k
(BigInt
): the private keyversion
(String
): the version byte, default:"80"
(Bitcoin)
Secp256k1::Bitcoin.wif_from_private_compressed BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
# => "Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu"
Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.
Parameters:
k
(BigInt
): the private keyversion
(String
): the version byte, default:"80"
(Bitcoin)
Secp256k1::Bitcoin.wif_from_private_uncompressed BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
# => "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.
Parameters:
wif
(String
): the Base-58 Wallet-Import Format (WIF).
Secp256k1::Bitcoin.wif_is_valid? "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
# => true
Returns true if the key contains a valid checksum and is formatted correctly.