From 7f5bb4f7cfe24c2aeb25c930586235b60367fa16 Mon Sep 17 00:00:00 2001 From: Afr Schoe <58883403+q9f@users.noreply.github.com> Date: Wed, 29 Sep 2021 12:21:08 +0200 Subject: [PATCH] docs: regenerate crystal documentation (#46) --- docs/Secp256k1.html | 89 +++++------ docs/Secp256k1/Bitcoin.html | 161 +++++++++---------- docs/Secp256k1/Bitcoin/Account.html | 121 ++++++-------- docs/Secp256k1/Core.html | 79 +++++----- docs/Secp256k1/ECDSASignature.html | 79 +++++----- docs/Secp256k1/ECPoint.html | 79 +++++----- docs/Secp256k1/Ethereum.html | 83 +++++----- docs/Secp256k1/Ethereum/Account.html | 93 +++++------ docs/Secp256k1/Ethereum/Enode.html | 107 ++++++------- docs/Secp256k1/Hash.html | 155 ++++++++---------- docs/Secp256k1/Keypair.html | 93 +++++------ docs/Secp256k1/Signature.html | 79 +++++----- docs/Secp256k1/Util.html | 103 ++++++------ docs/css/style.css | 62 +++++++- docs/index.html | 89 ++++++----- docs/index.json | 2 +- docs/js/doc.js | 225 +++++++++++++++++---------- docs/search-index.js | 2 +- 18 files changed, 867 insertions(+), 834 deletions(-) diff --git a/docs/Secp256k1.html b/docs/Secp256k1.html index 362be05..2fccf68 100644 --- a/docs/Secp256k1.html +++ b/docs/Secp256k1.html @@ -3,54 +3,65 @@
- + + + + + - - - -Implements 256-bit Secp256k1
Koblitz elliptic curve.
-Ref: secg.org/sec2-v2.pdf
Secp256k1
has the characteristic prime p
, it is defined over the prime field ℤ_p.
-Ref: en.bitcoin.it/wiki/Secp256k1
"0.3.0"
+ VERSION = "0.3.6"
Generates a Bitcoin
address from a private key.
Generates a Bitcoin
address for any public key, compressed or uncompressed.
Gets a Base-58 Wallet-Import Format (WIF) from a private key.
Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.
Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.
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)
+Secp256k1::Bitcoin.address_from_private BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
# => "1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN"
pub
(String
): the public key, compressed or uncompressed.version
(String
): the version byte, default: "00"
(Bitcoin).Secp256k1::Bitcoin.address_from_public_key "03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b"
+Secp256k1::Bitcoin.address_from_public_key "03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b"
# => "1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN"
Note, compressed public keys generate compressed addresses, whereas
@@ -372,17 +379,15 @@
- [View source]
-
p
(ECPoint
): the public key as point with x
and y
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 ECPoint
for usage instructions.
See .address_from_public_key
and ECPoint
for usage instructions.
wif
(String
): the Base-58 Wallet-Import Format (WIF).Secp256k1::Bitcoin.address_from_wif "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
+Secp256k1::Bitcoin.address_from_wif "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
# => "1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC"
Raises if Wallet-Import Format (WIF) is invalid.
@@ -429,8 +432,6 @@
- [View source]
-
wif
(String
): the Base-58 Wallet-Import Format (WIF).Secp256k1::Bitcoin.is_wif_compressed? "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
+Secp256k1::Bitcoin.is_wif_compressed? "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
# => false
Returns true if the key is compressed.
@@ -461,8 +462,6 @@
- [View source]
-
m
(String
): the mini-private key.Secp256k1::Bitcoin.mini_is_valid? "S7qq5k98DAvee6mtQgpg4xAJatT9mR"
+Secp256k1::Bitcoin.mini_is_valid? "S7qq5k98DAvee6mtQgpg4xAJatT9mR"
# => true
Returns true if the key contains a valid checksum and is formatted correctly.
@@ -491,8 +490,6 @@
- [View source]
-
Generates a new mini-private key (30 characters length, Base-56 encoded).
-Secp256k1::Bitcoin.new_mini_private_key
+Secp256k1::Bitcoin.new_mini_private_key
# => S7qq5k98DAvee6mtQgpg4xAJatT9mR
m
(String
): the mini-private key.Secp256k1::Bitcoin.private_key_from_mini "S7qq5k98DAvee6mtQgpg4xAJatT9mR"
+Secp256k1::Bitcoin.private_key_from_mini "S7qq5k98DAvee6mtQgpg4xAJatT9mR"
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
Raises if the key is invalid.
@@ -545,8 +540,6 @@
- [View source]
-
wif
(String
): the Base-58 Wallet-Import Format (WIF).Secp256k1::Bitcoin.private_key_from_wif "Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu"
+Secp256k1::Bitcoin.private_key_from_wif "Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu"
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
Raises if Wallet-Import Format (WIF) is invalid.
@@ -575,8 +568,6 @@
- [View source]
-
wif
(String
): the Base-58 Wallet-Import Format (WIF).Secp256k1::Bitcoin.version_byte_from_wif "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
+Secp256k1::Bitcoin.version_byte_from_wif "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
# => "80"
Raises if Wallet-Import Format (WIF) is invalid.
@@ -605,17 +596,15 @@
- [View source]
-
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)
+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
.
+"01"
for compressed keys. See also .wif_from_private_compressed
and .wif_from_private_uncompressed
.
k
(BigInt
): the private keyversion
(String
): the version byte, default: "80"
(Bitcoin)Secp256k1::Bitcoin.wif_from_private_compressed BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+Secp256k1::Bitcoin.wif_from_private_compressed BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
# => "Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu"
k
(BigInt
): the private keyversion
(String
): the version byte, default: "80"
(Bitcoin)Secp256k1::Bitcoin.wif_from_private_uncompressed BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+Secp256k1::Bitcoin.wif_from_private_uncompressed BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
# => "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
wif
(String
): the Base-58 Wallet-Import Format (WIF).Secp256k1::Bitcoin.wif_is_valid? "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
+Secp256k1::Bitcoin.wif_is_valid? "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
# => true
Returns true if the key contains a valid checksum and is formatted correctly.
@@ -722,8 +705,6 @@
- [View source]
-
#key_pair
(Keypair
): the Keypair
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 public Bitcoin
address.#wif
(String
): the private Wallet-Import Format (WIF).btc = Secp256k1::Bitcoin::Account.new
+btc = Secp256k1::Bitcoin::Account.new
btc.wif
# => "5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1"
btc.address
@@ -184,9 +195,7 @@
-
- bitcoin.cr
-
+ bitcoin.cr
@@ -404,7 +413,7 @@
#key_pair
(Keypair
): the Keypair
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)
+key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
btc = Secp256k1::Bitcoin::Account.new key, "00", true
# => #<Secp256k1::Bitcoin::Account:0x7f81ef21ab80>
@@ -414,8 +423,6 @@
- [View source]
-
#key_pair
(Keypair
): the Keypair
containing the secret key.#version
(String
): the version byte determining the used network encoding.key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
btc = Secp256k1::Bitcoin::Account.new key, "1e"
# => #<Secp256k1::Bitcoin::Account:0x7f81ef21ab80>
@@ -448,8 +455,6 @@
- [View source]
-
key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
btc = Secp256k1::Bitcoin::Account.new key
# => #<Secp256k1::Bitcoin::Account:0x7f81ef21ab80>
@@ -479,8 +484,6 @@
- [View source]
-
Generates a new Bitcoin::Account
from a fresh random Keypair
.
btc = Secp256k1::Bitcoin::Account.new
+btc = Secp256k1::Bitcoin::Account.new
# => #<Secp256k1::Bitcoin::Account:0x7f81ef21ab80>
Note, this always generates an uncompressed mainnet Bitcoin account.
@@ -505,8 +508,6 @@
- [View source]
-
Gets the private key as hexadecimal formatted string literal.
-btc.get_secret
+btc.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
Tells if the Bitcoin::Account
is compressed.
btc.is_compressed?
+btc.is_compressed?
# => false
Returns true if the compressed format is used.
@@ -653,8 +644,6 @@
- [View source]
-
@@ -674,8 +663,6 @@
- [View source]
-
@@ -695,8 +682,6 @@
- [View source]
-
@@ -712,15 +697,13 @@
Gets the account formatted as Bitcoin
address.
-btc.to_s
+btc.to_s
# => "1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC"
- [View source]
-
@@ -740,8 +723,6 @@
- [View source]
-
@@ -761,8 +742,6 @@
- [View source]
-
@@ -779,15 +758,13 @@
Computes the version byte for the private Wallet-Import Format which is
offset by + 0x80
from the public address #version
byte.
-btc.version_wif
+btc.version_wif
# => "80"
- [View source]
-
@@ -807,8 +784,6 @@
- [View source]
-
@@ -828,8 +803,6 @@
- [View source]
-
diff --git a/docs/Secp256k1/Core.html b/docs/Secp256k1/Core.html
index 921c716..116202c 100644
--- a/docs/Secp256k1/Core.html
+++ b/docs/Secp256k1/Core.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::Core - github.com/q9f/secp256k1.cr
+
+ Secp256k1::Core - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -147,10 +158,10 @@
Implements 256-bit Secp256k1
Koblitz elliptic curve.
-Ref: secg.org/sec2-v2.pdf
+Ref: secg.org/sec2-v2.pdf
Secp256k1
has the characteristic prime p
, it is defined over the prime field ℤ_p.
-Ref: en.bitcoin.it/wiki/Secp256k1
+Ref: en.bitcoin.it/wiki/Secp256k1
@@ -175,9 +186,7 @@
-
- core.cr
-
+ core.cr
@@ -275,8 +284,6 @@
- [View source]
-
@@ -306,8 +313,6 @@
- [View source]
-
@@ -333,8 +338,6 @@
- [View source]
-
@@ -363,8 +366,6 @@
- [View source]
-
diff --git a/docs/Secp256k1/ECDSASignature.html b/docs/Secp256k1/ECDSASignature.html
index 60033be..9a108fd 100644
--- a/docs/Secp256k1/ECDSASignature.html
+++ b/docs/Secp256k1/ECDSASignature.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::ECDSASignature - github.com/q9f/secp256k1.cr
+
+ Secp256k1::ECDSASignature - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -157,7 +168,7 @@
-sig = ECDSASignature.new r.x, proof
+sig = ECDSASignature.new r.x, proof
@@ -182,9 +193,7 @@
-
- structs.cr
-
+ structs.cr
@@ -324,8 +333,6 @@
- [View source]
-
@@ -359,8 +366,6 @@
- [View source]
-
@@ -380,8 +385,6 @@
- [View source]
-
@@ -401,8 +404,6 @@
- [View source]
-
@@ -422,8 +423,6 @@
- [View source]
-
diff --git a/docs/Secp256k1/ECPoint.html b/docs/Secp256k1/ECPoint.html
index 3bb1400..6c8abf3 100644
--- a/docs/Secp256k1/ECPoint.html
+++ b/docs/Secp256k1/ECPoint.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::ECPoint - github.com/q9f/secp256k1.cr
+
+ Secp256k1::ECPoint - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -154,7 +165,7 @@
-p = ECPoint.new BigInt.new(0), BigInt.new(0)
+p = ECPoint.new BigInt.new(0), BigInt.new(0)
p.x
# => 0
p.y
@@ -183,9 +194,7 @@
-
- structs.cr
-
+ structs.cr
@@ -325,8 +334,6 @@
- [View source]
-
@@ -360,8 +367,6 @@
- [View source]
-
@@ -381,8 +386,6 @@
- [View source]
-
@@ -402,8 +405,6 @@
- [View source]
-
@@ -423,8 +424,6 @@
- [View source]
-
diff --git a/docs/Secp256k1/Ethereum.html b/docs/Secp256k1/Ethereum.html
index f219c20..b8cd2dd 100644
--- a/docs/Secp256k1/Ethereum.html
+++ b/docs/Secp256k1/Ethereum.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::Ethereum - github.com/q9f/secp256k1.cr
+
+ Secp256k1::Ethereum - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -171,9 +182,7 @@
-
- ethereum.cr
-
+ ethereum.cr
@@ -258,13 +267,13 @@
Returns a checksummed Ethereum
address as per EIP-55.
-Reference: eips.ethereum.org/EIPS/eip-55
+Reference: eips.ethereum.org/EIPS/eip-55
Parameters:
adr
(String
): an unchecked Ethereum
address.
-
Secp256k1::Ethereum.address_checksum "0x7598c0fbaeb021161ce2e598f45ddee90fe5c6f7"
+Secp256k1::Ethereum.address_checksum "0x7598c0fbaeb021161ce2e598f45ddee90fe5c6f7"
# => "0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7"
Raises if address is malformed.
@@ -273,8 +282,6 @@
- [View source]
-
@@ -294,7 +301,7 @@
priv
(BigInt
): a private key as number.
-Secp256k1::Ethereum.address_from_private BigInt.new("b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268", 16)
+Secp256k1::Ethereum.address_from_private BigInt.new("b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268", 16)
# => "0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7"
Note, that the returned Ethereum
address is already checksummed.
@@ -303,8 +310,6 @@
- [View source]
-
@@ -324,7 +329,7 @@
pub
(String
): an uncompressed public key string.
-Secp256k1::Ethereum.address_from_public_key "d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5"
+Secp256k1::Ethereum.address_from_public_key "d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5"
# => "0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7"
Note, that the returned Ethereum
address is already checksummed.
@@ -335,8 +340,6 @@
- [View source]
-
@@ -362,8 +365,6 @@
- [View source]
-
diff --git a/docs/Secp256k1/Ethereum/Account.html b/docs/Secp256k1/Ethereum/Account.html
index 6371960..fb398ca 100644
--- a/docs/Secp256k1/Ethereum/Account.html
+++ b/docs/Secp256k1/Ethereum/Account.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::Ethereum::Account - github.com/q9f/secp256k1.cr
+
+ Secp256k1::Ethereum::Account - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -154,7 +165,7 @@
#key_pair
(Keypair
): the Keypair
containing the secret key.#address
(String
): the public checksummed Ethereum
address.
-eth = Secp256k1::Ethereum::Account.new
+eth = Secp256k1::Ethereum::Account.new
eth.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
eth.address
@@ -183,9 +194,7 @@
-
- ethereum.cr
-
+ ethereum.cr
@@ -328,7 +337,7 @@
Generates an Ethereum::Account
from a provided Keypair
.
-key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
eth = Secp256k1::Ethereum::Account.new key
# => #<Secp256k1::Ethereum::Account:0x7f81ef21ab80>
@@ -336,8 +345,6 @@
- [View source]
-
@@ -353,15 +360,13 @@
Generates a new Ethereum::Account
from a fresh random Keypair
.
-eth = Secp256k1::Ethereum::Account.new
+eth = Secp256k1::Ethereum::Account.new
# => #<Secp256k1::Ethereum::Account:0x7f81ef21ab80>
- [View source]
-
@@ -395,8 +400,6 @@
- [View source]
-
@@ -416,8 +419,6 @@
- [View source]
-
@@ -433,15 +434,13 @@
Gets the private key as hexadecimal formatted string literal.
-eth.get_secret
+eth.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
- [View source]
-
@@ -461,8 +460,6 @@
- [View source]
-
@@ -482,8 +479,6 @@
- [View source]
-
@@ -499,15 +494,13 @@
Gets the account formatted as Ethereum
address.
-eth.to_s
+eth.to_s
# => "0x224008a0F3d3cB989c807F568c7f99Bf451328A6"
- [View source]
-
diff --git a/docs/Secp256k1/Ethereum/Enode.html b/docs/Secp256k1/Ethereum/Enode.html
index 2dbc522..26d04a1 100644
--- a/docs/Secp256k1/Ethereum/Enode.html
+++ b/docs/Secp256k1/Ethereum/Enode.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::Ethereum::Enode - github.com/q9f/secp256k1.cr
+
+ Secp256k1::Ethereum::Enode - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -154,7 +165,7 @@
#key_pair
(Keypair
): the Keypair
containing the secret key.#address
(Socket::IPAddress
): the public (or local) IP address with port.
-p2p = Secp256k1::Ethereum::Enode.new
+p2p = Secp256k1::Ethereum::Enode.new
p2p.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
p2p.to_s
@@ -183,9 +194,7 @@
-
- ethereum.cr
-
+ ethereum.cr
@@ -349,7 +358,7 @@
Generates an Ethereum::Enode
from a provided Keypair
and a custom IP address with port.
-key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
p2p = Secp256k1::Ethereum::Enode.new key, "192.168.13.37", 31337
# => #<Secp256k1::Ethereum::Enode:0x7f81ef21ab80>
@@ -357,8 +366,6 @@
- [View source]
-
@@ -374,7 +381,7 @@
Generates an Ethereum::Enode
from a provided Keypair
and a custom port.
-key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
p2p = Secp256k1::Ethereum::Enode.new key, 50000
# => #<Secp256k1::Ethereum::Enode:0x7f81ef21ab80>
@@ -384,8 +391,6 @@
- [View source]
-
@@ -401,7 +406,7 @@
Generates an Ethereum::Enode
from a provided Keypair
.
-key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
p2p = Secp256k1::Ethereum::Enode.new key
# => #<Secp256k1::Ethereum::Enode:0x7f81ef21ab80>
@@ -411,8 +416,6 @@
- [View source]
-
@@ -428,7 +431,7 @@
Generates a new Ethereum::Enode
from a fresh random Keypair
.
-p2p = Secp256k1::Ethereum::Enode.new
+p2p = Secp256k1::Ethereum::Enode.new
# => #<Secp256k1::Ethereum::Enode:0x7f81ef21ab80>
Note, this tries to find out the public IP address and silently falls back to "127.0.0.1" if it fails.
@@ -437,8 +440,6 @@
- [View source]
-
@@ -472,8 +473,6 @@
- [View source]
-
@@ -493,8 +492,6 @@
- [View source]
-
@@ -510,18 +507,16 @@
Tries to find out the public IP address for the node.
-It queries ident.me for a potential public IP and silently
+
It queries ident.me for a potential public IP and silently
falls back to "127.0.0.1" if it fails without raising. Should be used with caution.
-p2p.get_my_ip
+p2p.get_my_ip
# => "84.160.86.205"
- [View source]
-
@@ -537,15 +532,13 @@
Gets the private key as hexadecimal formatted string literal.
-p2p.get_secret
+p2p.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
- [View source]
-
@@ -565,8 +558,6 @@
- [View source]
-
@@ -586,8 +577,6 @@
- [View source]
-
@@ -603,15 +592,13 @@
Gets the Enode
formatted as devp2p enode address.
-p2p.to_s
+p2p.to_s
# => "enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303"
- [View source]
-
diff --git a/docs/Secp256k1/Hash.html b/docs/Secp256k1/Hash.html
index 9902c64..c9d7ff0 100644
--- a/docs/Secp256k1/Hash.html
+++ b/docs/Secp256k1/Hash.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::Hash - github.com/q9f/secp256k1.cr
+
+ Secp256k1::Hash - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
-
- .keccak256_string(h : String)
+ .keccak256(h : String)
Operating a Keccak-256 hash on an actual string literal.
@@ -293,7 +302,7 @@
-
- .ripemd160_string(h : String)
+ .ripemd160(h : String)
Operating a RIPEMD-160 hash on an actual string literal.
@@ -307,7 +316,7 @@
-
- .sha256_string(h : String)
+ .sha256(h : String)
Operating a SHA2-256 hash on an actual string literal.
@@ -321,7 +330,7 @@
-
- .sha3_string(h : String)
+ .sha3(h : String)
Operating a SHA3-256 hash on an actual string literal.
@@ -367,15 +376,13 @@
i
(Int32
): the position in the Base-56 alphabet.
-Secp256k1::Hash.base56_char 13
+Secp256k1::Hash.base56_char 13
# => 'F'
- [View source]
-
@@ -395,15 +402,13 @@
i
(Int32
): the position in the Base-58 alphabet.
-Secp256k1::Hash.base58_char 13
+Secp256k1::Hash.base58_char 13
# => 'E'
- [View source]
-
@@ -423,15 +428,13 @@
s
(String
): The Base-58 encoded string to be decoded.
-Secp256k1::Hash.base58_decode "1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt"
+Secp256k1::Hash.base58_decode "1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt"
# => "007d7935bde6c9341de87a4d64588783033e23472d7322c46b"
- [View source]
-
@@ -451,15 +454,13 @@
h
(String
): The hexadecimal string to be encoded.
-Secp256k1::Hash.base58_encode "007d7935bde6c9341de87a4d64588783033e23472d7322c46b"
+Secp256k1::Hash.base58_encode "007d7935bde6c9341de87a4d64588783033e23472d7322c46b"
# => "1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt"
- [View source]
-
@@ -479,15 +480,13 @@
b
(Bytes
): the byte array to be converted.
-Secp256k1::Hash.bin_to_hex Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
+Secp256k1::Hash.bin_to_hex Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
=> "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
- [View source]
-
@@ -507,15 +506,13 @@
h
(String
): the hexadecimal string to be converted.
-Secp256k1::Hash.hex_to_bin "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
+Secp256k1::Hash.hex_to_bin "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
=> Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
- [View source]
-
@@ -535,24 +532,22 @@
b
(Bytes
): the byte array to be hashed.
-Secp256k1::Hash.keccak256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
+Secp256k1::Hash.keccak256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
# => "fcb41efa0456ba9f27e573422d6b5898c61da6f2137d07e4dae618eddd72e003"
- [View source]
-
-
+
@@ -563,15 +558,13 @@
h
(String
): the string literal to be hashed.
-Secp256k1::Hash.keccak256_string "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
+Secp256k1::Hash.keccak256 "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
# => "99cfa79866ec88f87f8e25a98a4b9873f3f8ee82482a317a5494572b00f51cec"
- [View source]
-
@@ -591,24 +584,22 @@
b
(Bytes
): the byte array to be hashed.
-Secp256k1::Hash.ripemd160 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
+Secp256k1::Hash.ripemd160 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
# => "5f3455f9ac58e25be08c99a7090108751b4796b9"
- [View source]
-
-
+
@@ -619,15 +610,13 @@
h
(String
): the string literal to be hashed.
-Secp256k1::Hash.ripemd160_string "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
+Secp256k1::Hash.ripemd160 "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
# => "46dff6cd5666c8e67db26ac0dfaf685bf71fc5f6"
- [View source]
-
@@ -647,24 +636,22 @@
b
(Bytes
): the byte array to be hashed.
-Secp256k1::Hash.sha256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
+Secp256k1::Hash.sha256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
# => "2739cc5f45c0e05236527e4e687dc54f0d5e88be64b9a90e5264a6721c0c71f2"
- [View source]
-
-
+
@@ -675,15 +662,13 @@
h
(String
): the string literal to be hashed.
-Secp256k1::Hash.sha256_string "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
+Secp256k1::Hash.sha256 "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
# => "452a41c28c9981faebb402095a5d553de28dc212338057aed27081110dfb907a"
- [View source]
-
@@ -703,24 +688,22 @@
b
(Bytes
): the byte array to be hashed.
-Secp256k1::Hash.sha3 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
+Secp256k1::Hash.sha3 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]
# => "66bb65180108362a3e25ba8282f7b96bfe840ce34a2e5dbc421aa8a590cc5f2e"
- [View source]
-
-
+
@@ -731,15 +714,13 @@
h
(String
): the string literal to be hashed.
-Secp256k1::Hash.sha3_string "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
+Secp256k1::Hash.sha3 "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
# => "aedc012933679615eb93fb0063f53010e6f0034e92aaccf97dacc46e338037e9"
- [View source]
-
diff --git a/docs/Secp256k1/Keypair.html b/docs/Secp256k1/Keypair.html
index 1a57e40..8f0c797 100644
--- a/docs/Secp256k1/Keypair.html
+++ b/docs/Secp256k1/Keypair.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::Keypair - github.com/q9f/secp256k1.cr
+
+ Secp256k1::Keypair - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -154,7 +165,7 @@
#private_key
(BigInt
): the secret as known as the private key.#public_key
(ECPoint
): the point on the elliptic curve as known as the public key.
-key = Secp256k1::Keypair.new
+key = Secp256k1::Keypair.new
key.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
key.to_s
@@ -183,9 +194,7 @@
-
- structs.cr
-
+ structs.cr
@@ -332,15 +341,13 @@
#private_key
(BigInt
): the secret as known as the private key.
-key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
+key = Secp256k1::Keypair.new BigInt.new("53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97", 16)
# => #<Secp256k1::Keypair:0x7f8be5611d80>
- [View source]
-
@@ -356,15 +363,13 @@
Generates a new keypair using a fresh random private key.
-key = Secp256k1::Keypair.new
+key = Secp256k1::Keypair.new
# => #<Secp256k1::Keypair:0x7f8be5611d80>
- [View source]
-
@@ -394,15 +399,13 @@
Gets the private key as hexadecimal formatted string literal.
-key.get_secret
+key.get_secret
# => "53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97"
- [View source]
-
@@ -422,8 +425,6 @@
- [View source]
-
@@ -443,8 +444,6 @@
- [View source]
-
@@ -464,8 +463,6 @@
- [View source]
-
@@ -485,8 +482,6 @@
- [View source]
-
@@ -502,15 +497,13 @@
Gets the key formatted as uncompressed public key string.
-key.to_s
+key.to_s
# => "e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f"
- [View source]
-
diff --git a/docs/Secp256k1/Signature.html b/docs/Secp256k1/Signature.html
index 873df54..26e551d 100644
--- a/docs/Secp256k1/Signature.html
+++ b/docs/Secp256k1/Signature.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::Signature - github.com/q9f/secp256k1.cr
+
+ Secp256k1::Signature - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -148,7 +159,7 @@
Implements ECDSASignature
generation and verification for Secp256k1
elliptic curves.
-Ref: cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages
+Ref: cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages
@@ -173,9 +184,7 @@
-
- signature.cr
-
+ signature.cr
@@ -262,7 +271,7 @@
msg
(String
): A message string to sign.priv
(BigInt
): A private key to sign with.
-sig = Secp256k1::Signature.sign "Hello, World!", BigInt.new("b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268", 16)
+sig = Secp256k1::Signature.sign "Hello, World!", BigInt.new("b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268", 16)
sig.r
# => "63945398370917837063250848409972066837033757647691696776146735867163610886143"
sig.s
@@ -272,8 +281,6 @@
- [View source]
-
@@ -297,7 +304,7 @@
msg
(String
): A message string to verify.sig
(ECDSASignature
): A signature to verify the message.pub
(ECPoint
): A public key to verify the signature against.
-pub = Secp256k1::Util.restore_public_key "03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a"
+pub = Secp256k1::Util.restore_public_key "03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a"
msg = "Hello, World!"
sig = Secp256k1::ECDSASignature.new BigInt.new("63945398370917837063250848409972066837033757647691696776146735867163610886143"), BigInt.new("20291418537568297129028959685291490143232574306335372594306006819765182564103")
@@ -308,8 +315,6 @@
- [View source]
-
@@ -337,8 +342,6 @@
- [View source]
-
diff --git a/docs/Secp256k1/Util.html b/docs/Secp256k1/Util.html
index dc65821..803e5ed 100644
--- a/docs/Secp256k1/Util.html
+++ b/docs/Secp256k1/Util.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- Secp256k1::Util - github.com/q9f/secp256k1.cr
+
+ Secp256k1::Util - secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -172,9 +183,7 @@
-
- util.cr
-
+ util.cr
@@ -300,7 +309,7 @@
pub
(String
): the public key in prefixed compressed format.prime
(BigInt
): the prime number that shapes the field, default: EC_PRIME_P
.
-Secp256k1::Util.decode_compressed_public_key "03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a"
+Secp256k1::Util.decode_compressed_public_key "03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a"
Returns an ECPoint
containing the public key.
@@ -310,8 +319,6 @@
- [View source]
-
@@ -328,15 +335,13 @@
A helper function to generate 32 pseudo-random bytes within the elliptic
curve field size of EC_ORDER_N
.
-Secp256k1::Util.new_private_key
+Secp256k1::Util.new_private_key
# => "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
- [View source]
-
@@ -361,15 +366,13 @@
p
(ECPoint
): the public key point which shall be compressed.
-Secp256k1::Util.public_key_compressed_prefix my_public_key
+Secp256k1::Util.public_key_compressed_prefix my_public_key
# => "03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a"
- [View source]
-
@@ -392,7 +395,7 @@
priv
(BigInt
): the private key to be used.
-Secp256k1::Util.public_key_from_private BigInt.new("b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268", 16)
+Secp256k1::Util.public_key_from_private BigInt.new("b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268", 16)
Returns an ECPoint
containing the public key.
@@ -400,8 +403,6 @@
- [View source]
-
@@ -424,15 +425,13 @@
p
(ECPoint
): the public key point which shall be uncompressed.
-Secp256k1::Util.public_key_uncompressed my_public_key
+Secp256k1::Util.public_key_uncompressed my_public_key
# => "d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5"
- [View source]
-
@@ -455,15 +454,13 @@
p
(ECPoint
): the public key point which shall be uncompressed.
-Secp256k1::Util.public_key_uncompressed_prefix my_public_key
+Secp256k1::Util.public_key_uncompressed_prefix my_public_key
# => "04d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5"
- [View source]
-
@@ -483,7 +480,7 @@
pub
(String
): the public key in any format.prime
(BigInt
): the prime number that shapes the field, default: EC_PRIME_P
.
-Secp256k1::Util.restore_public_key "d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5"
+Secp256k1::Util.restore_public_key "d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5"
Returns an ECPoint
containing the public key.
@@ -493,8 +490,6 @@
- [View source]
-
@@ -514,15 +509,13 @@
i
(Int32
): the integer to be formatted as padded hex byte.
-Secp256k1::Util.to_padded_hex_01 7
+Secp256k1::Util.to_padded_hex_01 7
# => "07"
- [View source]
-
@@ -543,15 +536,13 @@
i
(BigInt
): the integer to be formatted as padded hex byte string.
-Secp256k1::Util.to_padded_hex_32 BigInt.new 7
+Secp256k1::Util.to_padded_hex_32 BigInt.new 7
# => "0000000000000000000000000000000000000000000000000000000000000007"
- [View source]
-
diff --git a/docs/css/style.css b/docs/css/style.css
index a63baf5..20bb084 100644
--- a/docs/css/style.css
+++ b/docs/css/style.css
@@ -56,10 +56,11 @@ body {
padding: 0 0 30px;
box-shadow: inset -3px 0 4px rgba(0,0,0,.35);
line-height: 1.2;
+ z-index: 0;
}
.sidebar .search-box {
- padding: 8px 9px;
+ padding: 13px 9px;
}
.sidebar input {
@@ -106,6 +107,55 @@ body {
text-indent: 2px;
}
+.project-summary {
+ padding: 9px 15px 30px 30px;
+}
+
+.project-name {
+ font-size: 1.4rem;
+ margin: 0;
+ color: #f4f4f4;
+ font-weight: 600;
+}
+
+.project-version {
+ margin-top: 5px;
+ display: inline-block;
+ position: relative;
+}
+
+.project-version > form::after {
+ position: absolute;
+ right: 0;
+ top: 0;
+ content: "\25BC";
+ font-size: .6em;
+ line-height: 1.2rem;
+ z-index: -1;
+}
+
+.project-versions-nav {
+ cursor: pointer;
+ margin: 0;
+ padding: 0 .9em 0 0;
+ border: none;
+ -moz-appearance: none;
+ -webkit-appearance: none;
+ appearance: none;
+ background-color: transparent;
+ color: inherit;
+ font-family: inherit;
+ font-size: inherit;
+ line-height: inherit;
+}
+.project-versions-nav:focus {
+ outline: none;
+}
+
+.project-versions-nav > option {
+ color: initial;
+}
+
.sidebar ul {
margin: 0;
padding: 0;
@@ -148,10 +198,6 @@ body {
color: #866BA6;
}
-.repository-links {
- padding: 5px 15px 5px 30px;
-}
-
.types-list li ul {
overflow: hidden;
height: 0;
@@ -414,6 +460,12 @@ span.flag.purple {
border-color: #1F0B37;
}
+span.flag.lime {
+ background-color: #a3ff00;
+ color: #222222;
+ border-color: #00ff1e;
+}
+
.tooltip>span {
position: absolute;
opacity: 0;
diff --git a/docs/index.html b/docs/index.html
index 7cdeb50..84206f5 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -3,54 +3,65 @@
-
+
+
+
+
+
-
-
-
- README - github.com/q9f/secp256k1.cr
+
+ secp256k1 0.3.5-dev
+
-
- README
+
+
+
+ secp256k1
+
+
+
+
+ 0.3.5-dev
+
-
+
- -
+
-
Secp256k1
- -
+
-
Bitcoin
- -
+
-
Account
@@ -60,32 +71,32 @@
- -
+
-
Core
- -
+
-
ECDSASignature
- -
+
-
ECPoint
- -
+
-
Ethereum
- -
+
-
Hash
- -
+
-
Keypair
- -
+
-
Signature
- -
+
-
Util
@@ -133,11 +144,11 @@
secp256k1.cr
-
+
a native library implementing secp256k1
purely for the crystal language. secp256k1
is the elliptic curve used in the public-private-key cryptography required by bitcoin and ethereum.
@@ -172,7 +183,7 @@
usage
-tl;dr, check out crystal run ./try.cr
!
+tl;dr, check out crystal run ./try.cr
!
# import secp256k1
require "secp256k1"
@@ -247,11 +258,11 @@
documentation
-the full library documentation can be found here: q9f.github.io/secp256k1.cr
+the full library documentation can be found here: q9f.github.io/secp256k1.cr
generate a local copy with:
-crystal docs
+crystal docs
diff --git a/docs/index.json b/docs/index.json
index 6d69b8c..b276015 100644
--- a/docs/index.json
+++ b/docs/index.json
@@ -1 +1 @@
-{"repository_name":"github.com/q9f/secp256k1.cr","body":"# secp256k1.cr\n\n[![Build Status](https://img.shields.io/github/workflow/status/q9f/secp256k1.cr/Nightly)](https://github.com/q9f/secp256k1.cr/actions)\n[![Documentation](https://img.shields.io/badge/docs-html-black)](https://q9f.github.io/secp256k1.cr/)\n[![Release](https://img.shields.io/github/v/release/q9f/secp256k1.cr?include_prereleases&color=black)](https://github.com/q9f/secp256k1.cr/releases/latest)\n[![Language](https://img.shields.io/github/languages/top/q9f/secp256k1.cr?color=black)](https://github.com/q9f/secp256k1.cr/search?l=crystal)\n[![License](https://img.shields.io/github/license/q9f/secp256k1.cr.svg?color=black)](LICENSE)\n\na native library implementing `secp256k1` purely for the crystal language. `secp256k1` is the elliptic curve used in the public-private-key cryptography required by bitcoin and ethereum.\n\nthis library allows for key generation of:\n* private keys (from secure random within the elliptic curve field size)\n* mini private keys (short 30-char base-56 keys)\n* wallet import format (checksummed base-58 private keys)\n* public keys, prefixed, compressed (from private)\n* public keys, unprefixed and prefixed, uncompressed (from private)\n* conversion between the different public key formats\n\nthis library allows for address generation of:\n* bitcoin address, compressed and uncompressed (from private or public key)\n* any other bitcoin-based address by passing a `version` byte\n* ethereum address, checksummed and unchecksummed (from private or public key)\n* any other ethereum-based address\n\nfurthermore, this library allows for:\n* signing `(r, s)` and verification of arbitrary messages and message-hashes (with key pairs)\n* managing `enode` addresses as per `devp2p` specification for ethereum nodes\n\n# installation\n\nadd the `secp256k1` library to your `shard.yml`\n\n```yaml\ndependencies:\n secp256k1:\n github: q9f/secp256k1.cr\n version: \"~> 0.3\"\n```\n\n# usage\n\n_tl;dr,_ check out [`crystal run ./try.cr`](./try.cr)!\n\n\n```crystal\n# import secp256k1\nrequire \"secp256k1\"\n```\n\nthis library exposes the following modules (in logical order):\n\n* `Secp256k1`: necessary constants and data structures, including:\n - `Secp256k1::Keypair`: for managing private-public key-pairs\n - `Secp256k1::ECPoint`: for handling of secp256k1 elliptic curve points (public keys)\n - `Secp256k1::ECDSASignature`: for secp256k1 ecdsa signatures\n* `Secp256k1::Core`: the entire core mathematics behind the elliptic curve cryptography\n* `Secp256k1::Util`: all tools for the handling of private-public key-pairs\n* `Secp256k1::Hash`: implementation of various hashing algorithms for convenience\n* `Secp256k1::Signature`: allows for signing messages and verifying signatures\n* `Secp256k1::Bitcoin`: for the generation of bitcoin addresses, including:\n - `Secp256k1::Bitcoin::Account`: for bitcoin account management\n* `Secp256k1::Ethereum`: for the generation of ethereum addresses, including\n - `Secp256k1::Ethereum::Account`: for ethereum account management\n - `Secp256k1::Ethereum::Enode`: for devp2p enode address management\n\nbasic usage:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# gets the private key\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n\n# gets the compressed public key with prefix\ncompressed = Secp256k1::Util.public_key_compressed_prefix key.public_key\n# => \"03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b\"\n```\n\ngenerate a compressed bitcoin mainnet address:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# generates a compressed bitcoin account from the keypair\nbtc = Secp256k1::Bitcoin::Account.new key, \"00\", true\n# => #\n\n# gets the wallet-import format (checksummed private key)\nbtc.wif\n# => \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n\n# gets the compressed bitcoin addresss\nbtc.address\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```\n\ngenerate a checksummed ethereum address:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# generates an ethereum account from the keypair\neth = Secp256k1::Ethereum::Account.new key\n# => #\n\n# gets the private key\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n\n# gets the ethereum addresss\neth.address\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```\n\n# documentation\n\nthe full library documentation can be found here: [q9f.github.io/secp256k1.cr](https://q9f.github.io/secp256k1.cr/)\n\ngenerate a local copy with:\n\n```\ncrystal docs\n```\n\n# testing\n\nthe library is entirely specified through tests in `./spec`; run:\n\n```bash\ncrystal spec --verbose\n```\n\n# understand\n\nprivate keys are just scalars and public keys are points with `x` and `y` coordinates.\n\nbitcoin public keys can be uncompressed `#{p}#{x}#{y}` or compressed `#{p}#{x}`. both come with a prefix `p` which is useless for uncompressed keys but necessary for compressed keys to recover the `y` coordinate on the `secp256k1` elliptic curve.\n\nethereum public keys are uncompressed `#{x}#{y}` without any prefix. the last 20 bytes slice of the `y` coordinate is actually used as address without any checksum. a checksum was later added in eip-55 using a `keccak256` hash and indicating character capitalization.\n\nneither bitcoin nor ethereum allow for recovering public keys from an address unless there exists a transaction with a valid signature on the blockchain.\n\n# known issues\n\n_note: this library should not be used in production without proper auditing._\n\n* this library is not constant time and might be subject to side-channel attacks. ([#4](https://github.com/q9f/secp256k1.cr/issues/4))\n* this library does unnecessary big-integer math and should someday rather correctly implement the secp256k1 prime field ([#5](https://github.com/q9f/secp256k1.cr/issues/5))\n\nfound another issue? report it: [github.com/q9f/secp256k1.cr/issues](https://github.com/q9f/secp256k1.cr/issues)\n\n# contribute\n\ncreate a pull request, and make sure tests and linter passes.\n\nthis pure crystal implementation is based on the python implementation [wobine/blackboard101](https://github.com/wobine/blackboard101) which is also used as reference to write tests against. it's a complete rewrite of the abandoned [packetzero/bitcoinutils](https://github.com/packetzero/bitcoinutils) for educational purposes.\n\nhonerable mention for the [bitcoin wiki](https://en.bitcoin.it/wiki/Main_Page) and the [ethereum stackexchange](https://ethereum.stackexchange.com/) for providing so many in-depth resources that supported this project in reimplementing everything.\n\nlicense: apache license v2.0\n\ncontributors: [**@q9f**](https://github.com/q9f/)\n","program":{"html_id":"github.com/q9f/secp256k1.cr/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"github.com/q9f/secp256k1.cr","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","path":"Secp256k1.html","kind":"module","full_name":"Secp256k1","name":"Secp256k1","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"bitcoin.cr","line_number":16,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr"},{"filename":"constants.cr","line_number":22,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/constants.cr"},{"filename":"structs.cr","line_number":20,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr"},{"filename":"version.cr","line_number":20,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/version.cr"},{"filename":"secp256k1.cr","line_number":30,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/secp256k1.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"EC_BASE_G","name":"EC_BASE_G","value":"ECPoint.new(EC_BASE_G_X, EC_BASE_G_Y)","doc":"The commonly used base point `G` coordinates `x`, `y`;\nany other point that satisfies `y^2 = x^3 + 7` would also do.","summary":"The commonly used base point G
coordinates x
, y
; any other point that satisfies y^2 = x^3 + 7
would also do.
"},{"id":"EC_BASE_G_COMPRESSED","name":"EC_BASE_G_COMPRESSED","value":"BigInt.new((Secp256k1::Util.public_key_compressed_prefix(EC_BASE_G)), 16)","doc":"The base point `G` in compressed form.","summary":"The base point G
in compressed form.
"},{"id":"EC_BASE_G_UNCOMPRESSED","name":"EC_BASE_G_UNCOMPRESSED","value":"BigInt.new((Secp256k1::Util.public_key_uncompressed_prefix(EC_BASE_G)), 16)","doc":"The base point `G` in uncompressed form.","summary":"The base point G
in uncompressed form.
"},{"id":"EC_BASE_G_X","name":"EC_BASE_G_X","value":"BigInt.new(\"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\", 16)","doc":"The `x`-coordinate of the base point `G`.","summary":"The x
-coordinate of the base point G
.
"},{"id":"EC_BASE_G_Y","name":"EC_BASE_G_Y","value":"BigInt.new(\"483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8\", 16)","doc":"The `y`-coordinate of the base point `G`.","summary":"The y
-coordinate of the base point G
.
"},{"id":"EC_COFACTOR_H","name":"EC_COFACTOR_H","value":"BigInt.new(\"01\", 16)","doc":"The elliptic curve cofactor `h`.","summary":"The elliptic curve cofactor h
.
"},{"id":"EC_FACTOR_A","name":"EC_FACTOR_A","value":"BigInt.new(\"00\", 16)","doc":"The curve `E`: `y^2 = x^3 + ax + b` over `F_p` is defined by `a = 0`.\nAs the `a` constant is zero, the `ax` term in the curve equation is always zero,\nhence the curve equation becomes `y^2 = x^3 + b`.","summary":"The curve E
: y^2 = x^3 + ax + b
over F_p
is defined by a = 0
.
"},{"id":"EC_FACTOR_B","name":"EC_FACTOR_B","value":"BigInt.new(\"07\", 16)","doc":"The curve `E`: `y^2 = x^3 + b` over `F_p` is defined by `b = 7`,\nhence the curve equation becomes `y^2 = x^3 + 7`.","summary":"The curve E
: y^2 = x^3 + b
over F_p
is defined by b = 7
, hence the curve equation becomes y^2 = x^3 + 7
.
"},{"id":"EC_ORDER_N","name":"EC_ORDER_N","value":"BigInt.new(\"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141\", 16)","doc":"The order `n` of `G` defines the finite size of the Secp256k1 field `E`.","summary":"The order n
of G
defines the finite size of the Secp256k1 field E
.
"},{"id":"EC_PRIME_P","name":"EC_PRIME_P","value":"BigInt.new(\"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f\", 16)","doc":"The elliptic curve domain parameters over `F_p` associated with a Koblitz curve\nSecp256k1 are specified by the sextuple `T = (p, a, b, G, n, h)` where the finite\nfield `F_p` is defined by the prime `p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1`.","summary":"The elliptic curve domain parameters over F_p
associated with a Koblitz curve Secp256k1 are specified by the sextuple T = (p, a, b, G, n, h)
where the finite field F_p
is defined by the prime p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
.
"},{"id":"VERSION","name":"VERSION","value":"\"0.3.0\"","doc":"The `VERSION` of the `Secp256k1` module.","summary":"The VERSION
of the Secp256k1
module.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Implements 256-bit `Secp256k1` Koblitz elliptic curve.\nRef: [secg.org/sec2-v2.pdf](https://www.secg.org/sec2-v2.pdf)\n\n`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p.\nRef: [en.bitcoin.it/wiki/Secp256k1](https://en.bitcoin.it/wiki/Secp256k1)","summary":"Implements 256-bit Secp256k1
Koblitz elliptic curve.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Bitcoin","path":"Secp256k1/Bitcoin.html","kind":"module","full_name":"Secp256k1::Bitcoin","name":"Bitcoin","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"bitcoin.cr","line_number":16,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements the `Bitcoin` address space for the `Secp256k1` library.","summary":"Implements the Bitcoin
address space for the Secp256k1
library.
","class_methods":[{"id":"address_from_private(priv:BigInt,version="00",compressed=true)-class-method","html_id":"address_from_private(priv:BigInt,version="00",compressed=true)-class-method","name":"address_from_private","doc":"Generates a `Bitcoin` address from a private key.\n\nParameters:\n* `priv` (`BigInt`): the private key as number.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n* `compressed` (`Bool`): indicator if address should be compressed or not, default: `true` (compressed).\n\n```\nSecp256k1::Bitcoin.address_from_private BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```","summary":"Generates a Bitcoin
address from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"args_string":"(priv : BigInt, version = "00", compressed = true)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L563","def":{"name":"address_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"p = Secp256k1::Util.public_key_from_private(priv)\naddress_from_public_point(p, version, compressed)\n"}},{"id":"address_from_public_key(pub:String,version="00")-class-method","html_id":"address_from_public_key(pub:String,version="00")-class-method","name":"address_from_public_key","doc":"Generates a `Bitcoin` address for any public key, compressed or uncompressed.\n\nParameters:\n* `pub` (`String`): the public key, compressed or uncompressed.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n\n```\nSecp256k1::Bitcoin.address_from_public_key \"03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b\"\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```\n\nNote, compressed public keys generate compressed addresses, whereas\nuncompressed keys generate uncompressed addresses.\n\nRaises if the public key is malformed.","summary":"Generates a Bitcoin
address for any public key, compressed or uncompressed.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""}],"args_string":"(pub : String, version = "00")","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L467","def":{"name":"address_from_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (pub.size === 130) || (pub.size === 66)\n sha2 = Hash.sha256(Hash.hex_to_bin(pub))\n ripe = Hash.ripemd160(Hash.hex_to_bin(sha2))\n ripe_versioned = \"#{version}#{ripe}\"\n hashed = Hash.sha256(Hash.hex_to_bin(ripe_versioned))\n hashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\n binary = \"#{ripe_versioned}#{hashed_twice[0, 8]}\"\n Hash.base58_encode(binary)\nelse\n raise(\"malformed public key (invalid key size: #{pub.size})\")\nend"}},{"id":"address_from_public_point(p:Secp256k1::ECPoint,version="00",compressed=true)-class-method","html_id":"address_from_public_point(p:Secp256k1::ECPoint,version="00",compressed=true)-class-method","name":"address_from_public_point","doc":"Generates a `Bitcoin` address from an public key as `ECPoint`.\n\nParameters:\n* `p` (`ECPoint`): the public key as point with `x` and `y` coordinates.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n* `compressed` (`Bool`): indicator if address should be compressed or not, default: `true` (compressed).\n\nSee `address_from_public_key` and `ECPoint` for usage instructions.","summary":"Generates a Bitcoin
address from an public key as ECPoint
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"args_string":"(p : Secp256k1::ECPoint, version = "00", compressed = true)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L506","def":{"name":"address_from_public_point","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = Secp256k1::Util.public_key_uncompressed_prefix(p)\nif compressed\n pub = Secp256k1::Util.public_key_compressed_prefix(p)\nend\naddress_from_public_key(pub, version)\n"}},{"id":"address_from_wif(wif:String)-class-method","html_id":"address_from_wif(wif:String)-class-method","name":"address_from_wif","doc":"Gets a `Bitcoin` address from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.address_from_wif \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets a Bitcoin
address from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L526","def":{"name":"address_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if wif_is_valid?(wif)\n vers = version_byte_from_wif(wif)\n vers = vers.to_i(16)\n vers = vers - 128\n vers = Secp256k1::Util.to_padded_hex_01(vers)\n priv = private_key_from_wif(wif)\n priv = BigInt.new(priv, 16)\n comp = is_wif_compressed?(wif)\n address_from_private(priv, vers, comp)\nelse\n raise(\"invalid wallet import format (invalid wif: #{wif})\")\nend"}},{"id":"is_wif_compressed?(wif:String)-class-method","html_id":"is_wif_compressed?(wif:String)-class-method","name":"is_wif_compressed?","doc":"Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.is_wif_compressed? \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => false\n```\n\nReturns _true_ if the key is compressed.\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L392","def":{"name":"is_wif_compressed?","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"versioned = Hash.base58_decode(wif)\nif (versioned.size === 74) || (versioned.size === 76)\n versioned.size === 76\nelse\n raise(\"invalid wallet import format (invalid wif size: #{versioned.size})\")\nend\n"}},{"id":"mini_is_valid?(m:String)-class-method","html_id":"mini_is_valid?(m:String)-class-method","name":"mini_is_valid?","doc":"Validates wether a mini-private key has a correct checksum and formatting.\n\nParameters:\n* `m` (`String`): the mini-private key.\n\n```\nSecp256k1::Bitcoin.mini_is_valid? \"S7qq5k98DAvee6mtQgpg4xAJatT9mR\"\n# => true\n```\n\nReturns _true_ if the key contains a valid checksum and is formatted correctly.","summary":"Validates wether a mini-private key has a correct checksum and formatting.
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"args_string":"(m : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L253","def":{"name":"mini_is_valid?","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"valid = m.size === 30\nvalid = valid && (m[0, 1] === \"S\")\nchecksum = Hash.sha256_string(\"#{m}?\")\nvalid && (checksum[0, 2] === \"00\")\n"}},{"id":"new_mini_private_key-class-method","html_id":"new_mini_private_key-class-method","name":"new_mini_private_key","doc":"Generates a new mini-private key (30 characters length, Base-56 encoded).\n\n```\nSecp256k1::Bitcoin.new_mini_private_key\n# => S7qq5k98DAvee6mtQgpg4xAJatT9mR\n```","summary":"Generates a new mini-private key (30 characters length, Base-56 encoded).
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L193","def":{"name":"new_mini_private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"valid = false\nkey = String.new\nwhile !valid\n i = 1\n key = \"S\"\n while i < 30\n i = i + 1\n r = Random.rand(56)\n key = key + (Hash.base56_char(r))\n end\n valid = mini_is_valid?(key)\n if valid\n priv = private_key_from_mini(key)\n valid = valid && priv > 0\n valid = valid && (priv === (priv % Secp256k1::EC_ORDER_N))\n end\nend\nkey\n"}},{"id":"private_key_from_mini(m:String)-class-method","html_id":"private_key_from_mini(m:String)-class-method","name":"private_key_from_mini","doc":"Gets a private key from a mini-private key if the key is valid.\n\nParameters:\n* `m` (`String`): the mini-private key.\n\n```\nSecp256k1::Bitcoin.private_key_from_mini \"S7qq5k98DAvee6mtQgpg4xAJatT9mR\"\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```\n\nRaises if the key is invalid.","summary":"Gets a private key from a mini-private key if the key is valid.
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"args_string":"(m : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L232","def":{"name":"private_key_from_mini","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if mini_is_valid?(m)\n private_key = Hash.sha256_string(m)\n BigInt.new(private_key, 16)\nelse\n raise(\"mini private key is not valid (invalid checksum for: #{m})\")\nend"}},{"id":"private_key_from_wif(wif:String)-class-method","html_id":"private_key_from_wif(wif:String)-class-method","name":"private_key_from_wif","doc":"Gets a private key from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.private_key_from_wif \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets a private key from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L341","def":{"name":"private_key_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"checksum_key = Hash.base58_decode(wif)\nif (checksum_key.size == 74) || (checksum_key.size == 76)\n private_key = BigInt.new(checksum_key[2, 64], 16)\n Secp256k1::Util.to_padded_hex_32(private_key)\nelse\n raise(\"invalid wallet import format (invalid wif size: #{checksum_key.size})\")\nend\n"}},{"id":"version_byte_from_wif(wif:String)-class-method","html_id":"version_byte_from_wif(wif:String)-class-method","name":"version_byte_from_wif","doc":"Gets the version byte from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.version_byte_from_wif \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => \"80\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets the version byte from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L366","def":{"name":"version_byte_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"versioned = Hash.base58_decode(wif)\nif (versioned.size === 74) || (versioned.size === 76)\n versioned[0, 2]\nelse\n raise(\"invalid wallet import format (invalid wif size: #{versioned.size})\")\nend\n"}},{"id":"wif_from_private(k:BigInt,version="80",compr="")-class-method","html_id":"wif_from_private(k:BigInt,version="80",compr="")-class-method","name":"wif_from_private","doc":"Gets a Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key.\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin).\n* `compr` (`String`): the compression byte, default: `\"\"` (uncompressed).\n\n```\nSecp256k1::Bitcoin.wif_from_private BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n```\n\nNote, the compression byte `compr` is either empty `\"\"` for uncompressed keys or\n`\"01\"` for compressed keys. See also `wif_from_private_compressed` and `wif_from_private_uncompressed`.","summary":"Gets a Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""},{"name":"compr","doc":null,"default_value":"\"\"","external_name":"compr","restriction":""}],"args_string":"(k : BigInt, version = "80", compr = "")","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L277","def":{"name":"wif_from_private","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""},{"name":"compr","doc":null,"default_value":"\"\"","external_name":"compr","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"priv = Secp256k1::Util.to_padded_hex_32(k)\nversioned = \"#{version}#{priv}#{compr}\"\nhashed = Hash.sha256(Hash.hex_to_bin(versioned))\nhashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\nbinary = \"#{versioned}#{hashed_twice[0, 8]}\"\nHash.base58_encode(binary)\n"}},{"id":"wif_from_private_compressed(k:BigInt,version="80")-class-method","html_id":"wif_from_private_compressed(k:BigInt,version="80")-class-method","name":"wif_from_private_compressed","doc":"Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin)\n\n```\nSecp256k1::Bitcoin.wif_from_private_compressed BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n```","summary":"Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"args_string":"(k : BigInt, version = "80")","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L310","def":{"name":"wif_from_private_compressed","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"wif_from_private(k, version, \"01\")"}},{"id":"wif_from_private_uncompressed(k:BigInt,version="80")-class-method","html_id":"wif_from_private_uncompressed(k:BigInt,version="80")-class-method","name":"wif_from_private_uncompressed","doc":"Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin)\n\n```\nSecp256k1::Bitcoin.wif_from_private_uncompressed BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n```","summary":"Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"args_string":"(k : BigInt, version = "80")","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L325","def":{"name":"wif_from_private_uncompressed","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"wif_from_private(k, version, \"\")"}},{"id":"wif_is_valid?(wif:String)-class-method","html_id":"wif_is_valid?(wif:String)-class-method","name":"wif_is_valid?","doc":"Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.wif_is_valid? \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => true\n```\n\nReturns _true_ if the key contains a valid checksum and is formatted correctly.","summary":"Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L416","def":{"name":"wif_is_valid?","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"checksum_key = Hash.base58_decode(wif)\nvalid = (checksum_key.size === 74) || (checksum_key.size === 76)\nif valid\n private_key = private_key_from_wif(wif)\n valid = (valid && (private_key != \"-999\")) && (private_key.size === 64)\n versioned = checksum_key[0, 66]\n wif_checksum = checksum_key[66, 8]\n if checksum_key.size === 76\n versioned = checksum_key[0, 68]\n wif_checksum = checksum_key[68, 8]\n end\n hashed = Hash.sha256(Hash.hex_to_bin(versioned))\n hashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\n pk_checksum = hashed_twice[0, 8]\n valid = valid && (wif_checksum === pk_checksum)\nend\nvalid\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Bitcoin/Account","path":"Secp256k1/Bitcoin/Account.html","kind":"class","full_name":"Secp256k1::Bitcoin::Account","name":"Account","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"bitcoin.cr","line_number":34,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Bitcoin","kind":"module","full_name":"Secp256k1::Bitcoin","name":"Bitcoin"},"doc":"Implements a `Bitcoin` account containing a `Keypair`, a Wallet-Import Format,\nand an address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n* `compressed` (`Bool`): an indicator whether a compressed format should be used.\n* `address` (`String`): the public `Bitcoin` address.\n* `wif` (`String`): the private Wallet-Import Format (WIF).\n\n```\nbtc = Secp256k1::Bitcoin::Account.new\nbtc.wif\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\nbtc.address\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```","summary":"Implements a Bitcoin
account containing a Keypair
, a Wallet-Import Format, and an address.
","class_methods":[],"constructors":[{"id":"new(key_pair,version,compressed)-class-method","html_id":"new(key_pair,version,compressed)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair` allowing for a custom\nnetwork version byte and compression.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n* `compressed` (`Bool`): an indicator whether a compressed format should be used.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key, \"00\", true\n# => #\n```\n\nRaises if the version byte is out of range.","summary":"Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom network version byte and compression.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":""}],"args_string":"(key_pair, version, compressed)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L125","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, version, compressed)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new(key_pair,version)-class-method","html_id":"new(key_pair,version)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair` allowing for a custom\nnetwork version byte.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key, \"1e\"\n# => #\n```\n\nNote, this always generates an uncompressed account for the specified network.\n\nRaises if the version byte is out of range.","summary":"Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom network version byte.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""}],"args_string":"(key_pair, version)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L97","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, version)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new(key_pair)-class-method","html_id":"new(key_pair)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair`.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key\n# => #\n```\n\nNote, this always generates an uncompressed mainnet Bitcoin account.","summary":"Generates a Bitcoin::Account
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L74","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Generates a new `Bitcoin::Account` from a fresh random `Keypair`.\n\n```\nbtc = Secp256k1::Bitcoin::Account.new\n# => #\n```\n\nNote, this always generates an uncompressed mainnet Bitcoin account.","summary":"Generates a new Bitcoin::Account
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L54","def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"address:String-instance-method","html_id":"address:String-instance-method","name":"address","doc":"The public `Bitcoin` address.","summary":"The public Bitcoin
address.
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L42","def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@address"}},{"id":"address=(address:String)-instance-method","html_id":"address=(address:String)-instance-method","name":"address=","doc":"The public `Bitcoin` address.","summary":"The public Bitcoin
address.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"args_string":"(address : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L42","def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"id":"compressed:Bool-instance-method","html_id":"compressed:Bool-instance-method","name":"compressed","doc":"An indicator whether a compressed format should be used.","summary":"An indicator whether a compressed format should be used.
","abstract":false,"args":[],"args_string":" : Bool","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L40","def":{"name":"compressed","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@compressed"}},{"id":"compressed=(compressed:Bool)-instance-method","html_id":"compressed=(compressed:Bool)-instance-method","name":"compressed=","doc":"An indicator whether a compressed format should be used.","summary":"An indicator whether a compressed format should be used.
","abstract":false,"args":[{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":"Bool"}],"args_string":"(compressed : Bool)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L40","def":{"name":"compressed=","args":[{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@compressed = compressed"}},{"id":"get_secret-instance-method","html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\nbtc.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L172","def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"id":"is_compressed?:Bool-instance-method","html_id":"is_compressed?:Bool-instance-method","name":"is_compressed?","doc":"Tells if the `Bitcoin::Account` is compressed.\n\n```\nbtc.is_compressed?\n# => false\n```\n\nReturns _true_ if the compressed format is used.","summary":"Tells if the Bitcoin::Account
is compressed.
","abstract":false,"args":[],"args_string":" : Bool","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L151","def":{"name":"is_compressed?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@compressed"}},{"id":"key_pair:Keypair-instance-method","html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L36","def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"id":"key_pair=(key_pair:Keypair)-instance-method","html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L36","def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"id":"to_s:String-instance-method","html_id":"to_s:String-instance-method","name":"to_s","doc":"Gets the account formatted as `Bitcoin` address.\n\n```\nbtc.to_s\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```","summary":"Gets the account formatted as Bitcoin
address.
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L182","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address"}},{"id":"version:String-instance-method","html_id":"version:String-instance-method","name":"version","doc":"The version byte determining the used network encoding.","summary":"The version byte determining the used network encoding.
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L38","def":{"name":"version","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@version"}},{"id":"version=(version:String)-instance-method","html_id":"version=(version:String)-instance-method","name":"version=","doc":"The version byte determining the used network encoding.","summary":"The version byte determining the used network encoding.
","abstract":false,"args":[{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":"String"}],"args_string":"(version : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L38","def":{"name":"version=","args":[{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@version = version"}},{"id":"version_wif-instance-method","html_id":"version_wif-instance-method","name":"version_wif","doc":"Computes the version byte for the private Wallet-Import Format which is\noffset by `+ 0x80` from the public address `version` byte.\n\n```\nbtc.version_wif\n# => \"80\"\n```","summary":"Computes the version byte for the private Wallet-Import Format which is offset by + 0x80
from the public address #version
byte.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L162","def":{"name":"version_wif","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_01((@version.to_i(16)) + 128)"}},{"id":"wif:String-instance-method","html_id":"wif:String-instance-method","name":"wif","doc":"The private Wallet-Import Format (WIF).","summary":"The private Wallet-Import Format (WIF).
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L44","def":{"name":"wif","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@wif"}},{"id":"wif=(wif:String)-instance-method","html_id":"wif=(wif:String)-instance-method","name":"wif=","doc":"The private Wallet-Import Format (WIF).","summary":"The private Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L44","def":{"name":"wif=","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@wif = wif"}}],"macros":[],"types":[]}]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Core","path":"Secp256k1/Core.html","kind":"module","full_name":"Secp256k1::Core","name":"Core","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"core.cr","line_number":20,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements 256-bit `Secp256k1` Koblitz elliptic curve.\nRef: [secg.org/sec2-v2.pdf](https://www.secg.org/sec2-v2.pdf)\n\n`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p.\nRef: [en.bitcoin.it/wiki/Secp256k1](https://en.bitcoin.it/wiki/Secp256k1)","summary":"Implements 256-bit Secp256k1
Koblitz elliptic curve.
","class_methods":[{"id":"ec_add(p:ECPoint,q:ECPoint,prime=EC_PRIME_P)-class-method","html_id":"ec_add(p:ECPoint,q:ECPoint,prime=EC_PRIME_P)-class-method","name":"ec_add","doc":"The elliptic curve jive addition of point `p(x, y)` and `q(x, y)`.\n\nWe basically _draw_ a line between `p` and `q` which will intersect the\ncurve in the point `r` which will be mirrored over the `x`-axis.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the jive addition.\n* `q` (`ECPoint`): the point `q(x, y)` to be used in the jive addition.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns another `ECPoint` as result.","summary":"The elliptic curve jive addition of point p(x, y)
and q(x, y)
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"q","doc":null,"default_value":"","external_name":"q","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(p : ECPoint, q : ECPoint, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr#L60","def":{"name":"ec_add","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"q","doc":null,"default_value":"","external_name":"q","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x_delta = q.x - p.x\nx_inv = ec_mod_inv(x_delta)\ny_delta = q.y - p.y\nm = (y_delta * x_inv) % prime\nx = (((m * m) - p.x) - q.x) % prime\ny = ((m * (p.x - x)) - p.y) % prime\nx = BigInt.new(x)\ny = BigInt.new(y)\nECPoint.new(x, y)\n"}},{"id":"ec_double(p:ECPoint,prime=EC_PRIME_P)-class-method","html_id":"ec_double(p:ECPoint,prime=EC_PRIME_P)-class-method","name":"ec_double","doc":"The elliptic curve juke point doubling of `p(x, y)`.\n\nThis is a special case of addition where both points are the same.\nWe _draw_ a tangent line at `p` which will intersect the curve\nat point `r` which will be mirrored over the `x`-axis.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the juke doubling.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns another `ECPoint` as result.","summary":"The elliptic curve juke point doubling of p(x, y)
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(p : ECPoint, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr#L83","def":{"name":"ec_double","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"lam_numer = ((3 * p.x) * p.x) + EC_FACTOR_A\nlam_denom = 2 * p.y\nlam_inv = ec_mod_inv(lam_denom)\nlam = (lam_numer * lam_inv) % prime\nx = ((lam * lam) - (2 * p.x)) % prime\ny = ((lam * (p.x - x)) - p.y) % prime\nx = BigInt.new(x)\ny = BigInt.new(y)\nECPoint.new(x, y)\n"}},{"id":"ec_mod_inv(a:BigInt,prime=EC_PRIME_P)-class-method","html_id":"ec_mod_inv(a:BigInt,prime=EC_PRIME_P)-class-method","name":"ec_mod_inv","doc":"Computes the elliptic curve modular multiplicative inverse of `a`.\n\nParemeters:\n* `a` (`BigInt`): the integer that we want the modular inverse of.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns a `BigInt` value as result.","summary":"Computes the elliptic curve modular multiplicative inverse of a
.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"BigInt"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(a : BigInt, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr#L28","def":{"name":"ec_mod_inv","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"BigInt"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m_low = 1\nm_high = 0\nv_low = a % prime\nv_high = prime\nwhile v_low > 1\n v_ratio = v_high // v_low\n m_low_r = m_low * v_ratio\n v_low_r = v_low * v_ratio\n m = m_high - m_low_r\n v = v_high - v_low_r\n m_high = m_low\n v_high = v_low\n m_low = m\n v_low = v\nend\nm_low % prime\n"}},{"id":"ec_mul(p:ECPoint,s:BigInt)-class-method","html_id":"ec_mul(p:ECPoint,s:BigInt)-class-method","name":"ec_mul","doc":"The elliptic curve sequence multiplication of point `p(x, y)` and\na skalar `s`.\n\nWith `s` being a private key within the elliptic curve field size of `EC_ORDER_N`.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the sequencing.\n* `s` (`BigInt`): a skalar, in most cases a private key.\n\nReturns another `ECPoint` as result, in most cases a public key.","summary":"The elliptic curve sequence multiplication of point p(x, y)
and a skalar s
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(p : ECPoint, s : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr#L105","def":{"name":"ec_mul","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (s === 0) || s >= EC_ORDER_N\n raise(\"invalid private key: outside of ec field size.\")\nend\ns_bin = s.to_s(2)\nq = p\ns_bin.each_char_with_index do |char, index|\n if index === 0\n next\n end\n q = ec_double(q)\n if char === '1'\n q = ec_add(q, p)\n end\nend\nq\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/ECDSASignature","path":"Secp256k1/ECDSASignature.html","kind":"struct","full_name":"Secp256k1::ECDSASignature","name":"ECDSASignature","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"github.com/q9f/secp256k1.cr/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"structs.cr","line_number":127,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A basic ECDSA Signature containing a random point `r` and the\nsignature proof `s`.\n\nSee: `Signature` for signature generation.\n\nProperties:\n* `r` (`BigInt`): the `x` coordinate of a random point `R`.\n* `s` (`BigInt`): the signature proof of a message.\n\n```\nsig = ECDSASignature.new r.x, proof\n```","summary":"A basic ECDSA Signature containing a random point #r
and the signature proof #s
.
","class_methods":[],"constructors":[{"id":"new(r:BigInt,s:BigInt)-class-method","html_id":"new(r:BigInt,s:BigInt)-class-method","name":"new","doc":"A signature always requires the random point `r` and the signature proof `s`.\n\nParameters:\n* `r` (`BigInt`): the `x` coordinate of a random point `R`.\n* `s` (`BigInt`): the signature proof of a message.","summary":"A signature always requires the random point #r
and the signature proof #s
.
","abstract":false,"args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(r : BigInt, s : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L139","def":{"name":"new","args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(r, s)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"r:BigInt-instance-method","html_id":"r:BigInt-instance-method","name":"r","doc":"The `x` coordinate of a random point `R`.","summary":"The x
coordinate of a random point R
.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L129","def":{"name":"r","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@r"}},{"id":"r=(r:BigInt)-instance-method","html_id":"r=(r:BigInt)-instance-method","name":"r=","doc":"The `x` coordinate of a random point `R`.","summary":"The x
coordinate of a random point R
.
","abstract":false,"args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"}],"args_string":"(r : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L129","def":{"name":"r=","args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@r = r"}},{"id":"s:BigInt-instance-method","html_id":"s:BigInt-instance-method","name":"s","doc":"The signature proof of a message.","summary":"The signature proof of a message.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L132","def":{"name":"s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@s"}},{"id":"s=(s:BigInt)-instance-method","html_id":"s=(s:BigInt)-instance-method","name":"s=","doc":"The signature proof of a message.","summary":"The signature proof of a message.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(s : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L132","def":{"name":"s=","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@s = s"}}],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/ECPoint","path":"Secp256k1/ECPoint.html","kind":"struct","full_name":"Secp256k1::ECPoint","name":"ECPoint","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"github.com/q9f/secp256k1.cr/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"structs.cr","line_number":99,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A point in the two-dimensional space of an elliptic curve.\n\nProperties:\n* `x` (`BigInt`): the position on the x-axis.\n* `y` (`BigInt`): the position on the y-axis.\n\n```\np = ECPoint.new BigInt.new(0), BigInt.new(0)\np.x\n# => 0\np.y\n# => 0\n```","summary":"A point in the two-dimensional space of an elliptic curve.
","class_methods":[],"constructors":[{"id":"new(x:BigInt,y:BigInt)-class-method","html_id":"new(x:BigInt,y:BigInt)-class-method","name":"new","doc":"An ECPoint always requires two coordinates `x`, `y`.\n\nParameters:\n* `x` (`BigInt`): the position on the x-axis.\n* `y` (`BigInt`): the position on the y-axis.","summary":"An ECPoint always requires two coordinates #x
, #y
.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"args_string":"(x : BigInt, y : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L111","def":{"name":"new","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(x, y)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"x:BigInt-instance-method","html_id":"x:BigInt-instance-method","name":"x","doc":"The position on the x-axis.","summary":"The position on the x-axis.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L101","def":{"name":"x","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@x"}},{"id":"x=(x:BigInt)-instance-method","html_id":"x=(x:BigInt)-instance-method","name":"x=","doc":"The position on the x-axis.","summary":"The position on the x-axis.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"}],"args_string":"(x : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L101","def":{"name":"x=","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@x = x"}},{"id":"y:BigInt-instance-method","html_id":"y:BigInt-instance-method","name":"y","doc":"The position on the y-axis.","summary":"The position on the y-axis.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L104","def":{"name":"y","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@y"}},{"id":"y=(y:BigInt)-instance-method","html_id":"y=(y:BigInt)-instance-method","name":"y=","doc":"The position on the y-axis.","summary":"The position on the y-axis.
","abstract":false,"args":[{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"args_string":"(y : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L104","def":{"name":"y=","args":[{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@y = y"}}],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum","path":"Secp256k1/Ethereum.html","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"ethereum.cr","line_number":19,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements the `Ethereum` address space for the `Secp256k1` library.","summary":"Implements the Ethereum
address space for the Secp256k1
library.
","class_methods":[{"id":"address_checksum(adr:String)-class-method","html_id":"address_checksum(adr:String)-class-method","name":"address_checksum","doc":"Returns a checksummed `Ethereum` address as per EIP-55.\n\nReference: [eips.ethereum.org/EIPS/eip-55](https://eips.ethereum.org/EIPS/eip-55)\n\nParameters:\n* `adr` (`String`): an unchecked `Ethereum` address.\n\n```\nSecp256k1::Ethereum.address_checksum \"0x7598c0fbaeb021161ce2e598f45ddee90fe5c6f7\"\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nRaises if address is malformed.","summary":"Returns a checksummed Ethereum
address as per EIP-55.
","abstract":false,"args":[{"name":"adr","doc":null,"default_value":"","external_name":"adr","restriction":"String"}],"args_string":"(adr : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L210","def":{"name":"address_checksum","args":[{"name":"adr","doc":null,"default_value":"","external_name":"adr","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"adr = adr.downcase\nif adr.size === 42\n adr = adr[2, 40]\nend\nif adr.size === 40\n keccak = Hash.keccak256_string(adr)\n address = \"0x\"\n i = 0\n while i < adr.size\n k = keccak[i].to_i(16)\n if k >= 8\n address = address + \"#{adr[i]}\".upcase\n else\n address = address + \"#{adr[i]}\".downcase\n end\n i = i + 1\n end\n address\nelse\n raise(\"malformed ethereum address (invalid size: #{adr.size})\")\nend\n"}},{"id":"address_from_private(priv:BigInt)-class-method","html_id":"address_from_private(priv:BigInt)-class-method","name":"address_from_private","doc":"Generates a checksummed `Ethereum` address from a private key.\n\nParameters:\n* `priv` (`BigInt`): a private key as number.\n\n```\nSecp256k1::Ethereum.address_from_private BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nNote, that the returned `Ethereum` address is already checksummed.","summary":"Generates a checksummed Ethereum
address from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(priv : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L297","def":{"name":"address_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"p = Secp256k1::Util.public_key_from_private(priv)\naddress_from_public_point(p)\n"}},{"id":"address_from_public_key(pub:String)-class-method","html_id":"address_from_public_key(pub:String)-class-method","name":"address_from_public_key","doc":"Generates a checksummed `Ethereum` address for an uncompressed public key.\n\nParameters:\n* `pub` (`String`): an uncompressed public key string.\n\n```\nSecp256k1::Ethereum.address_from_public_key \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nNote, that the returned `Ethereum` address is already checksummed.\n\nRaises if the public key is malformed.","summary":"Generates a checksummed Ethereum
address for an uncompressed public key.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"}],"args_string":"(pub : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L256","def":{"name":"address_from_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if pub.size === 130\n pub = pub[2, 128]\nend\nif pub.size === 128\n keccak = Hash.keccak256(Hash.hex_to_bin(pub))\n address_checksum(keccak[24, 40])\nelse\n raise(\"malformed public key (invalid key size: #{pub.size})\")\nend\n"}},{"id":"address_from_public_point(p:Secp256k1::ECPoint)-class-method","html_id":"address_from_public_point(p:Secp256k1::ECPoint)-class-method","name":"address_from_public_point","doc":"Generates a checksummed `Ethereum` address from an public key as `ECPoint`.\n\nParameters:\n* `p` (`ECPoint`): a public key point with `x` and `y` coordinates.\n\nSee `address_from_public_key` and `ECPoint` for usage instructions.","summary":"Generates a checksummed Ethereum
address from an public key as ECPoint
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"}],"args_string":"(p : Secp256k1::ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L280","def":{"name":"address_from_public_point","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = Secp256k1::Util.public_key_uncompressed(p)\naddress_from_public_key(pub)\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum/Account","path":"Secp256k1/Ethereum/Account.html","kind":"class","full_name":"Secp256k1::Ethereum::Account","name":"Account","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"ethereum.cr","line_number":33,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum"},"doc":"Implements an `Ethereum` account containing a `Keypair` and an address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `address` (`String`): the public checksummed `Ethereum` address.\n\n```\neth = Secp256k1::Ethereum::Account.new\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\neth.address\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```","summary":"Implements an Ethereum
account containing a Keypair
and an address.
","class_methods":[],"constructors":[{"id":"new(key_pair)-class-method","html_id":"new(key_pair)-class-method","name":"new","doc":"Generates an `Ethereum::Account` from a provided `Keypair`.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\neth = Secp256k1::Ethereum::Account.new key\n# => #\n```","summary":"Generates an Ethereum::Account
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L57","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Generates a new `Ethereum::Account` from a fresh random `Keypair`.\n\n```\neth = Secp256k1::Ethereum::Account.new\n# => #\n```","summary":"Generates a new Ethereum::Account
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L45","def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"address:String-instance-method","html_id":"address:String-instance-method","name":"address","doc":"The public checksummed `Ethereum` address.","summary":"The public checksummed Ethereum
address.
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L37","def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@address"}},{"id":"address=(address:String)-instance-method","html_id":"address=(address:String)-instance-method","name":"address=","doc":"The public checksummed `Ethereum` address.","summary":"The public checksummed Ethereum
address.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"args_string":"(address : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L37","def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"id":"get_secret-instance-method","html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L67","def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"id":"key_pair:Keypair-instance-method","html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L35","def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"id":"key_pair=(key_pair:Keypair)-instance-method","html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L35","def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":"Gets the account formatted as `Ethereum` address.\n\n```\neth.to_s\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```","summary":"Gets the account formatted as Ethereum
address.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L77","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Ethereum.address_checksum(@address)"}}],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum/Enode","path":"Secp256k1/Ethereum/Enode.html","kind":"class","full_name":"Secp256k1::Ethereum::Enode","name":"Enode","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"ethereum.cr","line_number":95,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum"},"doc":"Implements an `Ethereum` devp2p enode containing a `Keypair` and an IP address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `address` (`Socket::IPAddress`): the public (or local) IP address with port.\n\n```\np2p = Secp256k1::Ethereum::Enode.new\np2p.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\np2p.to_s\n# => \"enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303\"\n```","summary":"Implements an Ethereum
devp2p enode containing a Keypair
and an IP address.
","class_methods":[],"constructors":[{"id":"new(key_pair,host,port)-class-method","html_id":"new(key_pair,host,port)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair` and a custom IP address with port.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key, \"192.168.13.37\", 31337\n# => #\n```","summary":"Generates an Ethereum::Enode
from a provided Keypair
and a custom IP address with port.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"host","doc":null,"default_value":"","external_name":"host","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"args_string":"(key_pair, host, port)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L147","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"host","doc":null,"default_value":"","external_name":"host","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, host, port)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new(key_pair,port)-class-method","html_id":"new(key_pair,port)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair` and a custom port.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key, 50000\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates an Ethereum::Enode
from a provided Keypair
and a custom port.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"args_string":"(key_pair, port)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L136","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, port)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new(key_pair)-class-method","html_id":"new(key_pair)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair`.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates an Ethereum::Enode
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L123","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Generates a new `Ethereum::Enode` from a fresh random `Keypair`.\n\n```\np2p = Secp256k1::Ethereum::Enode.new\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates a new Ethereum::Enode
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L109","def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"address:Socket::IPAddress-instance-method","html_id":"address:Socket::IPAddress-instance-method","name":"address","doc":"The public (or local) IP address with port.","summary":"The public (or local) IP address with port.
","abstract":false,"args":[],"args_string":" : Socket::IPAddress","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L99","def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Socket::IPAddress","visibility":"Public","body":"@address"}},{"id":"address=(address:Socket::IPAddress)-instance-method","html_id":"address=(address:Socket::IPAddress)-instance-method","name":"address=","doc":"The public (or local) IP address with port.","summary":"The public (or local) IP address with port.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"Socket::IPAddress"}],"args_string":"(address : Socket::IPAddress)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L99","def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"Socket::IPAddress"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"id":"get_my_ip-instance-method","html_id":"get_my_ip-instance-method","name":"get_my_ip","doc":"Tries to find out the public IP address for the node.\n\nIt queries [ident.me](http://ident.me/) for a potential public IP and silently\nfalls back to \"127.0.0.1\" if it fails without raising. _Should be used with caution._\n\n```\np2p.get_my_ip\n# => \"84.160.86.205\"\n```","summary":"Tries to find out the public IP address for the node.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L160","def":{"name":"get_my_ip","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ip = nil\nbegin\n ip = (HTTP::Client.get(\"http://ident.me/\")).body.to_s\nrescue\n ip = \"127.0.0.1\"\nensure\n if ip.nil? || ip.size < 2\n ip = \"127.0.0.1\"\n end\nend\nip\n"}},{"id":"get_secret-instance-method","html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\np2p.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L182","def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"id":"key_pair:Keypair-instance-method","html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L97","def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"id":"key_pair=(key_pair:Keypair)-instance-method","html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L97","def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":"Gets the `Enode` formatted as devp2p enode address.\n\n```\np2p.to_s\n# => \"enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303\"\n```","summary":"Gets the Enode
formatted as devp2p enode address.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L192","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"enode://#{@key_pair.to_s}@#{@address.to_s}\""}}],"macros":[],"types":[]}]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Hash","path":"Secp256k1/Hash.html","kind":"module","full_name":"Secp256k1::Hash","name":"Hash","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"hash.cr","line_number":20,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"BASE_56","name":"BASE_56","value":"\"23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz\"","doc":"The Base-56 alphabet for `Bitcoin` mini-private keys is a Base-58 alphabet\nwithout `1` and `o` to additionally omit more similar-looking letters.","summary":"The Base-56 alphabet for Bitcoin
mini-private keys is a Base-58 alphabet without 1
and o
to additionally omit more similar-looking letters.
"},{"id":"BASE_58","name":"BASE_58","value":"\"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\"","doc":"The Base-58 alphabet for `Bitcoin` addresses is a Base-64 alphabet without\n`0`, `O`, `I`, and `l` to omit similar-looking letters.","summary":"The Base-58 alphabet for Bitcoin
addresses is a Base-64 alphabet without 0
, O
, I
, and l
to omit similar-looking letters.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"The `Secp256k1::Hash` module wraps various hashing functions for convenience\nand exposes them for general use.","summary":"The Secp256k1::Hash
module wraps various hashing functions for convenience and exposes them for general use.
","class_methods":[{"id":"base56_char(i:Int32)-class-method","html_id":"base56_char(i:Int32)-class-method","name":"base56_char","doc":"Gets a character from the Base-56 alphabet at position `i`.\n\nParameters:\n* `i` (`Int32`): the position in the Base-56 alphabet.\n\n```\nSecp256k1::Hash.base56_char 13\n# => 'F'\n```","summary":"Gets a character from the Base-56 alphabet at position i
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L211","def":{"name":"base56_char","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"i = i % 56\nBASE_56[i]\n"}},{"id":"base58_char(i:Int32)-class-method","html_id":"base58_char(i:Int32)-class-method","name":"base58_char","doc":"Gets a character from the Base-58 alphabet at position `i`.\n\nParameters:\n* `i` (`Int32`): the position in the Base-58 alphabet.\n\n```\nSecp256k1::Hash.base58_char 13\n# => 'E'\n```","summary":"Gets a character from the Base-58 alphabet at position i
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L225","def":{"name":"base58_char","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"i = i % 58\nBASE_58[i]\n"}},{"id":"base58_decode(s:String)-class-method","html_id":"base58_decode(s:String)-class-method","name":"base58_decode","doc":"Decodes a hexadecimal string from a Base-58 encoded string.\n\nParameters:\n* `s` (`String`): The Base-58 encoded string to be decoded.\n\n```\nSecp256k1::Hash.base58_decode \"1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt\"\n# => \"007d7935bde6c9341de87a4d64588783033e23472d7322c46b\"\n```","summary":"Decodes a hexadecimal string from a Base-58 encoded string.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L146","def":{"name":"base58_decode","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"index = 0\ndecimal = BigInt.new(0)\nwhile index < s.size\n b58_char = s[index]\n position = BASE_58.index(b58_char)\n if !position.nil?\n decimal = (decimal * 58) + position\n index = index + 1\n else\n raise(\"cannot decode, invalid base58 character: '#{s[index]}'\")\n end\nend\nhex = decimal.to_s(16)\nleading = 0\nwhile s[leading] === '1'\n leading = leading + 1\n hex = \"00#{hex}\"\nend\nhex\n"}},{"id":"base58_encode(h:String)-class-method","html_id":"base58_encode(h:String)-class-method","name":"base58_encode","doc":"Encodes a Base-58 string from a hexadecimal string.\n\nParameters:\n* `h` (`String`): The hexadecimal string to be encoded.\n\n```\nSecp256k1::Hash.base58_encode \"007d7935bde6c9341de87a4d64588783033e23472d7322c46b\"\n# => \"1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt\"\n```","summary":"Encodes a Base-58 string from a hexadecimal string.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L180","def":{"name":"base58_encode","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = BigInt.new(h, 16)\nadr = String.new\nwhile pub > 0\n pub, rem = pub.divmod(58)\n adr = adr + (base58_char(rem.to_i))\nend\ni, s = 0, 2\ncurrent_byte = h[i, s]\nwhile (current_byte.to_i(16)) === 0\n adr = \"#{adr}1\"\n i = i + s\n current_byte = h[i, s]\nend\nadr.reverse\n"}},{"id":"bin_to_hex(b:Bytes)-class-method","html_id":"bin_to_hex(b:Bytes)-class-method","name":"bin_to_hex","doc":"Helper function to convert byte arrays to hexadecimal strings.\n\nParameters:\n* `b` (`Bytes`): the byte array to be converted.\n\n```\nSecp256k1::Hash.bin_to_hex Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n=> \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n```","summary":"Helper function to convert byte arrays to hexadecimal strings.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L239","def":{"name":"bin_to_hex","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"b.hexstring"}},{"id":"hex_to_bin(h:String)-class-method","html_id":"hex_to_bin(h:String)-class-method","name":"hex_to_bin","doc":"Helper function to convert hexadecimal strings to byte arrays.\n\nParameters:\n* `h` (`String`): the hexadecimal string to be converted.\n\n```\nSecp256k1::Hash.hex_to_bin \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n=> Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n```","summary":"Helper function to convert hexadecimal strings to byte arrays.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L252","def":{"name":"hex_to_bin","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h.hexbytes"}},{"id":"keccak256(b:Bytes)-class-method","html_id":"keccak256(b:Bytes)-class-method","name":"keccak256","doc":"Operating a Keccak-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.keccak256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"fcb41efa0456ba9f27e573422d6b5898c61da6f2137d07e4dae618eddd72e003\"\n```","summary":"Operating a Keccak-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L66","def":{"name":"keccak256","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"keccak = Digest::Keccak3.new(256)\n(keccak.update(b)).hexdigest\n"}},{"id":"keccak256_string(h:String)-class-method","html_id":"keccak256_string(h:String)-class-method","name":"keccak256_string","doc":"Operating a Keccak-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.keccak256_string \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"99cfa79866ec88f87f8e25a98a4b9873f3f8ee82482a317a5494572b00f51cec\"\n```","summary":"Operating a Keccak-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L80","def":{"name":"keccak256_string","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"keccak = Digest::Keccak3.new(256)\n(keccak.update(h)).hexdigest\n"}},{"id":"ripemd160(b:Bytes)-class-method","html_id":"ripemd160(b:Bytes)-class-method","name":"ripemd160","doc":"Operating a RIPEMD-160 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.ripemd160 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"5f3455f9ac58e25be08c99a7090108751b4796b9\"\n```","summary":"Operating a RIPEMD-160 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L120","def":{"name":"ripemd160","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"RIPEMD160\")).update(b)).hexdigest"}},{"id":"ripemd160_string(h:String)-class-method","html_id":"ripemd160_string(h:String)-class-method","name":"ripemd160_string","doc":"Operating a RIPEMD-160 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.ripemd160_string \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"46dff6cd5666c8e67db26ac0dfaf685bf71fc5f6\"\n```","summary":"Operating a RIPEMD-160 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L133","def":{"name":"ripemd160_string","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"RIPEMD160\")).update(h)).hexdigest"}},{"id":"sha256(b:Bytes)-class-method","html_id":"sha256(b:Bytes)-class-method","name":"sha256","doc":"Operating a SHA2-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.sha256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"2739cc5f45c0e05236527e4e687dc54f0d5e88be64b9a90e5264a6721c0c71f2\"\n```","summary":"Operating a SHA2-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L94","def":{"name":"sha256","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"SHA256\")).update(b)).hexdigest"}},{"id":"sha256_string(h:String)-class-method","html_id":"sha256_string(h:String)-class-method","name":"sha256_string","doc":"Operating a SHA2-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.sha256_string \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"452a41c28c9981faebb402095a5d553de28dc212338057aed27081110dfb907a\"\n```","summary":"Operating a SHA2-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L107","def":{"name":"sha256_string","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"SHA256\")).update(h)).hexdigest"}},{"id":"sha3(b:Bytes)-class-method","html_id":"sha3(b:Bytes)-class-method","name":"sha3","doc":"Operating a SHA3-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.sha3 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"66bb65180108362a3e25ba8282f7b96bfe840ce34a2e5dbc421aa8a590cc5f2e\"\n```","summary":"Operating a SHA3-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L38","def":{"name":"sha3","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sha3 = Digest::SHA3.new(256)\n(sha3.update(b)).hexdigest\n"}},{"id":"sha3_string(h:String)-class-method","html_id":"sha3_string(h:String)-class-method","name":"sha3_string","doc":"Operating a SHA3-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.sha3_string \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"aedc012933679615eb93fb0063f53010e6f0034e92aaccf97dacc46e338037e9\"\n```","summary":"Operating a SHA3-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L52","def":{"name":"sha3_string","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sha3 = Digest::SHA3.new(256)\n(sha3.update(h)).hexdigest\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Keypair","path":"Secp256k1/Keypair.html","kind":"class","full_name":"Secp256k1::Keypair","name":"Keypair","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"structs.cr","line_number":34,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements a `Secp256k1` key pair containing a private and a public key.\n\nProperties:\n* `private_key` (`BigInt`): the secret as known as the private key.\n* `public_key` (`ECPoint`): the point on the elliptic curve as known as the public key.\n\n```\nkey = Secp256k1::Keypair.new\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\nkey.to_s\n# => \"e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f\"\n```","summary":"Implements a Secp256k1
key pair containing a private and a public key.
","class_methods":[],"constructors":[{"id":"new(private_key)-class-method","html_id":"new(private_key)-class-method","name":"new","doc":"Generates a new keypair using a provided private key.\n\nParameters:\n* `private_key` (`BigInt`): the secret as known as the private key.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => #\n```","summary":"Generates a new keypair using a provided private key.
","abstract":false,"args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":""}],"args_string":"(private_key)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L61","def":{"name":"new","args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(private_key)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Generates a new keypair using a fresh random private key.\n\n```\nkey = Secp256k1::Keypair.new\n# => #\n```","summary":"Generates a new keypair using a fresh random private key.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L47","def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"get_secret-instance-method","html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L71","def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@private_key)"}},{"id":"private_key:BigInt-instance-method","html_id":"private_key:BigInt-instance-method","name":"private_key","doc":"The secret as known as the private key.","summary":"The secret as known as the private key.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L36","def":{"name":"private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@private_key"}},{"id":"private_key=(private_key:BigInt)-instance-method","html_id":"private_key=(private_key:BigInt)-instance-method","name":"private_key=","doc":"The secret as known as the private key.","summary":"The secret as known as the private key.
","abstract":false,"args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":"BigInt"}],"args_string":"(private_key : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L36","def":{"name":"private_key=","args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@private_key = private_key"}},{"id":"public_key:ECPoint-instance-method","html_id":"public_key:ECPoint-instance-method","name":"public_key","doc":"The point on the elliptic curve as known as the public key.","summary":"The point on the elliptic curve as known as the public key.
","abstract":false,"args":[],"args_string":" : ECPoint","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L39","def":{"name":"public_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ECPoint","visibility":"Public","body":"@public_key"}},{"id":"public_key=(public_key:ECPoint)-instance-method","html_id":"public_key=(public_key:ECPoint)-instance-method","name":"public_key=","doc":"The point on the elliptic curve as known as the public key.","summary":"The point on the elliptic curve as known as the public key.
","abstract":false,"args":[{"name":"public_key","doc":null,"default_value":"","external_name":"public_key","restriction":"ECPoint"}],"args_string":"(public_key : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L39","def":{"name":"public_key=","args":[{"name":"public_key","doc":null,"default_value":"","external_name":"public_key","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@public_key = public_key"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":"Gets the key formatted as uncompressed public key string.\n\n```\nkey.to_s\n# => \"e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f\"\n```","summary":"Gets the key formatted as uncompressed public key string.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L81","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.public_key_uncompressed(@public_key)"}}],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Signature","path":"Secp256k1/Signature.html","kind":"module","full_name":"Secp256k1::Signature","name":"Signature","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"signature.cr","line_number":18,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/signature.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements `ECDSASignature` generation and verification for `Secp256k1`\nelliptic curves.\nRef: [cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages](https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages)","summary":"Implements ECDSASignature
generation and verification for Secp256k1
elliptic curves.
","class_methods":[{"id":"sign(msg:String,priv:BigInt)-class-method","html_id":"sign(msg:String,priv:BigInt)-class-method","name":"sign","doc":"Signs a message and creates a signature proof using a private key.\n\nThe ECDSA signing algorithm (RFC-6979) takes as input a message `msg`\nand a private key `priv`. It produces as output a signature, which\nconsists of pair of integers `(r, s)`, where `r` is the `x`-coordinate\nof a random point on our curve and `s` is the signature proof.\n\nParameters:\n* `msg` (`String`): A message string to sign.\n* `priv` (`BigInt`): A private key to sign with.\n\n```\nsig = Secp256k1::Signature.sign \"Hello, World!\", BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\nsig.r\n# => \"63945398370917837063250848409972066837033757647691696776146735867163610886143\"\nsig.s\n# => \"20291418537568297129028959685291490143232574306335372594306006819765182564103\"\n```","summary":"Signs a message and creates a signature proof using a private key.
","abstract":false,"args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(msg : String, priv : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/signature.cr#L37","def":{"name":"sign","args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hash = BigInt.new(Hash.sha256_string(msg), 16)\nk = Util.new_private_key\nr = (Core.ec_mul(EC_BASE_G, k)).x % EC_ORDER_N\nk_inv = Core.ec_mod_inv(k, EC_ORDER_N)\ns = ((hash + (r * priv)) * k_inv) % EC_ORDER_N\nECDSASignature.new(r, s)\n"}},{"id":"verify(msg:String,sig:ECDSASignature,pub:ECPoint)-class-method","html_id":"verify(msg:String,sig:ECDSASignature,pub:ECPoint)-class-method","name":"verify","doc":"Verifies a signature of a message against a public key.\n\nThe algorithm to verify an ECDSA signature takes as input the signed message `msg`\nand the signature `(r, s)` produced from `sign` and the public key `pub`,\ncorresponding to the signer's private key. The result is boolean.\n\nParameters:\n* `msg` (`String`): A message string to verify.\n* `sig` (`ECDSASignature`): A signature to verify the message.\n* `pub` (`ECPoint`): A public key to verify the signature against.\n\n```\npub = Secp256k1::Util.restore_public_key \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\nmsg = \"Hello, World!\"\nsig = Secp256k1::ECDSASignature.new BigInt.new(\"63945398370917837063250848409972066837033757647691696776146735867163610886143\"), BigInt.new(\"20291418537568297129028959685291490143232574306335372594306006819765182564103\")\n\nSecp256k1::Signature.verify msg, sig, pub\n# => true\n```","summary":"Verifies a signature of a message against a public key.
","abstract":false,"args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"args_string":"(msg : String, sig : ECDSASignature, pub : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/signature.cr#L75","def":{"name":"verify","args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hash = BigInt.new(Hash.sha256_string(msg), 16)\nverify_hash(hash, sig, pub)\n"}},{"id":"verify_hash(hash:BigInt,sig:ECDSASignature,pub:ECPoint)-class-method","html_id":"verify_hash(hash:BigInt,sig:ECDSASignature,pub:ECPoint)-class-method","name":"verify_hash","doc":"Verifies a signature of a message hash against a public key.\n\nSame as `verify`, just using the hashed message directly.\n\nParameters:\n* `hash` (`BigInt`): A SHA-256 hash of the message to verify.\n* `sig` (`ECDSASignature`): A signature to verify the message.\n* `pub` (`ECPoint`): A public key to verify the signature against.\n\nReturns _true_ if signature is valid. See `verify` for usage example.","summary":"Verifies a signature of a message hash against a public key.
","abstract":false,"args":[{"name":"hash","doc":null,"default_value":"","external_name":"hash","restriction":"BigInt"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"args_string":"(hash : BigInt, sig : ECDSASignature, pub : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/signature.cr#L91","def":{"name":"verify_hash","args":[{"name":"hash","doc":null,"default_value":"","external_name":"hash","restriction":"BigInt"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"s_inv = Core.ec_mod_inv(sig.s, EC_ORDER_N)\np0 = Core.ec_mul(EC_BASE_G, (hash * s_inv) % EC_ORDER_N)\np1 = Core.ec_mul(pub, (sig.r * s_inv) % EC_ORDER_N)\np = Core.ec_add(p0, p1)\nsig.r === p.x\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Util","path":"Secp256k1/Util.html","kind":"module","full_name":"Secp256k1::Util","name":"Util","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"util.cr","line_number":23,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A collection of utilities for `Secp256k1` key management, e.g., private key\ngeneration, public key conversions, key formatting, or hex padding.","summary":"A collection of utilities for Secp256k1
key management, e.g., private key generation, public key conversions, key formatting, or hex padding.
","class_methods":[{"id":"decode_compressed_public_key(pub:String,prime=EC_PRIME_P)-class-method","html_id":"decode_compressed_public_key(pub:String,prime=EC_PRIME_P)-class-method","name":"decode_compressed_public_key","doc":"Decodes a public key as `ECPoint` from a compressed public key string.\n\nIf unsure, `restore_public_key` should be used.\n\nParameters:\n* `pub` (`String`): the public key in prefixed compressed format.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\n```\nSecp256k1::Util.decode_compressed_public_key \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\n```\n\nReturns an `ECPoint` containing the public key.\n\nRaises if compressed public key is malformed or comes with invalid prefix.","summary":"Decodes a public key as ECPoint
from a compressed public key string.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(pub : String, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L163","def":{"name":"decode_compressed_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if pub.size === 66\n prefix = pub[0, 2]\n if (prefix === \"02\") || (prefix === \"03\")\n x = BigInt.new(pub[2, 64], 16)\n a = (x ** 3) % prime\n a = (a + 7) % prime\n e = ((prime + 1) // 4) % prime\n y = BigInt.new\n LibGMP.mpz_powm_sec(y, a, e, prime)\n parity = prefix.to_i - 2\n if (y % 2) != parity\n y = (-y) % prime\n end\n ECPoint.new(x, y)\n else\n raise(\"invalid prefix for compressed public key: #{prefix}\")\n end\nelse\n raise(\"malformed compressed public key (invalid key size: #{pub.size})\")\nend"}},{"id":"new_private_key-class-method","html_id":"new_private_key-class-method","name":"new_private_key","doc":"A helper function to generate 32 pseudo-random bytes within the elliptic\ncurve field size of `EC_ORDER_N`.\n\n```\nSecp256k1::Util.new_private_key\n# => \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n```","summary":"A helper function to generate 32 pseudo-random bytes within the elliptic curve field size of EC_ORDER_N
.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L66","def":{"name":"new_private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"key = -999\nwhile !key > 0\n key = Random::Secure.hex(32)\n key = BigInt.new(key, 16)\nend\nkey % EC_ORDER_N\n"}},{"id":"public_key_compressed_prefix(p:ECPoint)-class-method","html_id":"public_key_compressed_prefix(p:ECPoint)-class-method","name":"public_key_compressed_prefix","doc":"Exports the compressed public key from an `ECPoint` with either the\nprefix `\"02\"` or `\"03\"`.\n\nThe prefix can be later used to recover the `y` coordinate of the public key,\nsee `decode_compressed_public_key`. `Bitcoin` uses this format\nto generate shorter addresses as compared to using uncompressed keys.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be compressed.\n\n```\nSecp256k1::Util.public_key_compressed_prefix my_public_key\n# => \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\n```","summary":"Exports the compressed public key from an ECPoint
with either the prefix \"02\"
or \"03\"
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L109","def":{"name":"public_key_compressed_prefix","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"prefix = (p.y % 2) === 1 ? \"03\" : \"02\"\n\"#{prefix}#{public_key_compressed(p)}\"\n"}},{"id":"public_key_from_private(priv:BigInt)-class-method","html_id":"public_key_from_private(priv:BigInt)-class-method","name":"public_key_from_private","doc":"Gets a public key from a private key.\n\nThis is basically a wrapper function to perform an elliptic curve\nmultiplication with the generator point `g` and a provided private key `priv`.\n\nParameters:\n* `priv` (`BigInt`): the private key to be used.\n\n```\nSecp256k1::Util.public_key_from_private BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\n```\n\nReturns an `ECPoint` containing the public key.","summary":"Gets a public key from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(priv : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L258","def":{"name":"public_key_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Core.ec_mul(EC_BASE_G, priv)"}},{"id":"public_key_uncompressed(p:ECPoint)-class-method","html_id":"public_key_uncompressed(p:ECPoint)-class-method","name":"public_key_uncompressed","doc":"Exports the uncompressed public key from an `ECPoint` without prefix.\n\n`Ethereum` uses this format to generate addresses. For prefixed\nuncompressed public keys, see `public_key_uncompressed_prefix`.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be uncompressed.\n\n```\nSecp256k1::Util.public_key_uncompressed my_public_key\n# => \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```","summary":"Exports the uncompressed public key from an ECPoint
without prefix.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L126","def":{"name":"public_key_uncompressed","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x = to_padded_hex_32(p.x)\ny = to_padded_hex_32(p.y)\n\"#{x}#{y}\"\n"}},{"id":"public_key_uncompressed_prefix(p:ECPoint)-class-method","html_id":"public_key_uncompressed_prefix(p:ECPoint)-class-method","name":"public_key_uncompressed_prefix","doc":"Exports the uncompressed public key from an `ECPoint` with prefix `\"04\"`.\n\n`Bitcoin` uses this format to generate uncompressed addresses.\nFor unprefixed public keys, see `public_key_uncompressed`.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be uncompressed.\n\n```\nSecp256k1::Util.public_key_uncompressed_prefix my_public_key\n# => \"04d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```","summary":"Exports the uncompressed public key from an ECPoint
with prefix \"04\"
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L144","def":{"name":"public_key_uncompressed_prefix","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"04#{public_key_uncompressed(p)}\""}},{"id":"restore_public_key(pub:String,prime=EC_PRIME_P)-class-method","html_id":"restore_public_key(pub:String,prime=EC_PRIME_P)-class-method","name":"restore_public_key","doc":"Detects public key type and tries to restore the `ECPoint` from it.\n\nParameters:\n* `pub` (`String`): the public key in any format.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\n```\nSecp256k1::Util.restore_public_key \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```\n\nReturns an `ECPoint` containing the public key.\n\nRaises if public key format is unknown.","summary":"Detects public key type and tries to restore the ECPoint
from it.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(pub : String, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L234","def":{"name":"restore_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case pub.size\nwhen 130, 128\n decode_uncompressed_public_key(pub)\nwhen 66\n decode_compressed_public_key(pub, prime)\nelse\n raise(\"unknown public key format (invalid key size: #{pub.size})\")\nend"}},{"id":"to_padded_hex_01(i:Int32)-class-method","html_id":"to_padded_hex_01(i:Int32)-class-method","name":"to_padded_hex_01","doc":"A generic utility to encode single hex bytes as strings, e.g., \"07\"\n\nParameters:\n* `i` (`Int32`): the integer to be formatted as padded hex byte.\n\n```\nSecp256k1::Util.to_padded_hex_01 7\n# => \"07\"\n```","summary":"A generic utility to encode single hex bytes as strings, e.g., \"07\"
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L33","def":{"name":"to_padded_hex_01","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hex = i.to_s(16)\nwhile hex.size < 2\n hex = '0' + hex\nend\nhex\n"}},{"id":"to_padded_hex_32(i:BigInt)-class-method","html_id":"to_padded_hex_32(i:BigInt)-class-method","name":"to_padded_hex_32","doc":"An utility tool to ensure hex keys are always 32 bytes;\nit pads the number with leading zeros if it's shorter.\n\nParameters:\n* `i` (`BigInt`): the integer to be formatted as padded hex byte string.\n\n```\nSecp256k1::Util.to_padded_hex_32 BigInt.new 7\n# => \"0000000000000000000000000000000000000000000000000000000000000007\"\n```","summary":"An utility tool to ensure hex keys are always 32 bytes; it pads the number with leading zeros if it's shorter.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"BigInt"}],"args_string":"(i : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L51","def":{"name":"to_padded_hex_32","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hex = i.to_s(16)\nwhile hex.size < 64\n hex = '0' + hex\nend\nhex\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}}
\ No newline at end of file
+{"repository_name":"secp256k1","body":"# secp256k1.cr\n\n[![Build Status](https://img.shields.io/github/workflow/status/q9f/secp256k1.cr/Nightly)](https://github.com/q9f/secp256k1.cr/actions)\n[![Documentation](https://img.shields.io/badge/docs-html-black)](https://q9f.github.io/secp256k1.cr/)\n[![Release](https://img.shields.io/github/v/release/q9f/secp256k1.cr?include_prereleases&color=black)](https://github.com/q9f/secp256k1.cr/releases/latest)\n[![Language](https://img.shields.io/github/languages/top/q9f/secp256k1.cr?color=black)](https://github.com/q9f/secp256k1.cr/search?l=crystal)\n[![License](https://img.shields.io/github/license/q9f/secp256k1.cr.svg?color=black)](LICENSE)\n\na native library implementing `secp256k1` purely for the crystal language. `secp256k1` is the elliptic curve used in the public-private-key cryptography required by bitcoin and ethereum.\n\nthis library allows for key generation of:\n* private keys (from secure random within the elliptic curve field size)\n* mini private keys (short 30-char base-56 keys)\n* wallet import format (checksummed base-58 private keys)\n* public keys, prefixed, compressed (from private)\n* public keys, unprefixed and prefixed, uncompressed (from private)\n* conversion between the different public key formats\n\nthis library allows for address generation of:\n* bitcoin address, compressed and uncompressed (from private or public key)\n* any other bitcoin-based address by passing a `version` byte\n* ethereum address, checksummed and unchecksummed (from private or public key)\n* any other ethereum-based address\n\nfurthermore, this library allows for:\n* signing `(r, s)` and verification of arbitrary messages and message-hashes (with key pairs)\n* managing `enode` addresses as per `devp2p` specification for ethereum nodes\n\n# installation\n\nadd the `secp256k1` library to your `shard.yml`\n\n```yaml\ndependencies:\n secp256k1:\n github: q9f/secp256k1.cr\n version: \"~> 0.3\"\n```\n\n# usage\n\n_tl;dr,_ check out [`crystal run ./try.cr`](./try.cr)!\n\n\n```crystal\n# import secp256k1\nrequire \"secp256k1\"\n```\n\nthis library exposes the following modules (in logical order):\n\n* `Secp256k1`: necessary constants and data structures, including:\n - `Secp256k1::Keypair`: for managing private-public key-pairs\n - `Secp256k1::ECPoint`: for handling of secp256k1 elliptic curve points (public keys)\n - `Secp256k1::ECDSASignature`: for secp256k1 ecdsa signatures\n* `Secp256k1::Core`: the entire core mathematics behind the elliptic curve cryptography\n* `Secp256k1::Util`: all tools for the handling of private-public key-pairs\n* `Secp256k1::Hash`: implementation of various hashing algorithms for convenience\n* `Secp256k1::Signature`: allows for signing messages and verifying signatures\n* `Secp256k1::Bitcoin`: for the generation of bitcoin addresses, including:\n - `Secp256k1::Bitcoin::Account`: for bitcoin account management\n* `Secp256k1::Ethereum`: for the generation of ethereum addresses, including\n - `Secp256k1::Ethereum::Account`: for ethereum account management\n - `Secp256k1::Ethereum::Enode`: for devp2p enode address management\n\nbasic usage:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# gets the private key\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n\n# gets the compressed public key with prefix\ncompressed = Secp256k1::Util.public_key_compressed_prefix key.public_key\n# => \"03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b\"\n```\n\ngenerate a compressed bitcoin mainnet address:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# generates a compressed bitcoin account from the keypair\nbtc = Secp256k1::Bitcoin::Account.new key, \"00\", true\n# => #\n\n# gets the wallet-import format (checksummed private key)\nbtc.wif\n# => \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n\n# gets the compressed bitcoin addresss\nbtc.address\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```\n\ngenerate a checksummed ethereum address:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# generates an ethereum account from the keypair\neth = Secp256k1::Ethereum::Account.new key\n# => #\n\n# gets the private key\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n\n# gets the ethereum addresss\neth.address\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```\n\n# documentation\n\nthe full library documentation can be found here: [q9f.github.io/secp256k1.cr](https://q9f.github.io/secp256k1.cr/)\n\ngenerate a local copy with:\n\n```\ncrystal docs\n```\n\n# testing\n\nthe library is entirely specified through tests in `./spec`; run:\n\n```bash\ncrystal spec --verbose\n```\n\n# understand\n\nprivate keys are just scalars and public keys are points with `x` and `y` coordinates.\n\nbitcoin public keys can be uncompressed `#{p}#{x}#{y}` or compressed `#{p}#{x}`. both come with a prefix `p` which is useless for uncompressed keys but necessary for compressed keys to recover the `y` coordinate on the `secp256k1` elliptic curve.\n\nethereum public keys are uncompressed `#{x}#{y}` without any prefix. the last 20 bytes slice of the `y` coordinate is actually used as address without any checksum. a checksum was later added in eip-55 using a `keccak256` hash and indicating character capitalization.\n\nneither bitcoin nor ethereum allow for recovering public keys from an address unless there exists a transaction with a valid signature on the blockchain.\n\n# known issues\n\n_note: this library should not be used in production without proper auditing._\n\n* this library is not constant time and might be subject to side-channel attacks. ([#4](https://github.com/q9f/secp256k1.cr/issues/4))\n* this library does unnecessary big-integer math and should someday rather correctly implement the secp256k1 prime field ([#5](https://github.com/q9f/secp256k1.cr/issues/5))\n\nfound another issue? report it: [github.com/q9f/secp256k1.cr/issues](https://github.com/q9f/secp256k1.cr/issues)\n\n# contribute\n\ncreate a pull request, and make sure tests and linter passes.\n\nthis pure crystal implementation is based on the python implementation [wobine/blackboard101](https://github.com/wobine/blackboard101) which is also used as reference to write tests against. it's a complete rewrite of the abandoned [packetzero/bitcoinutils](https://github.com/packetzero/bitcoinutils) for educational purposes.\n\nhonerable mention for the [bitcoin wiki](https://en.bitcoin.it/wiki/Main_Page) and the [ethereum stackexchange](https://ethereum.stackexchange.com/) for providing so many in-depth resources that supported this project in reimplementing everything.\n\nlicense: apache license v2.0\n\ncontributors: [**@q9f**](https://github.com/q9f/), [@cserb](https://github.com/cserb), [MrSorcus](https://github.com/MrSorcus)\n","program":{"html_id":"secp256k1/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"secp256k1","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"secp256k1/Secp256k1","path":"Secp256k1.html","kind":"module","full_name":"Secp256k1","name":"Secp256k1","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/bitcoin.cr","line_number":16,"url":null},{"filename":"src/constants.cr","line_number":22,"url":null},{"filename":"src/secp256k1.cr","line_number":30,"url":null},{"filename":"src/structs.cr","line_number":20,"url":null},{"filename":"src/version.cr","line_number":20,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"EC_BASE_G","name":"EC_BASE_G","value":"ECPoint.new(EC_BASE_G_X, EC_BASE_G_Y)","doc":"The commonly used base point `G` coordinates `x`, `y`;\nany other point that satisfies `y^2 = x^3 + 7` would also do.","summary":"The commonly used base point G
coordinates x
, y
; any other point that satisfies y^2 = x^3 + 7
would also do.
"},{"id":"EC_BASE_G_COMPRESSED","name":"EC_BASE_G_COMPRESSED","value":"BigInt.new((Secp256k1::Util.public_key_compressed_prefix(EC_BASE_G)), 16)","doc":"The base point `G` in compressed form.","summary":"The base point G
in compressed form.
"},{"id":"EC_BASE_G_UNCOMPRESSED","name":"EC_BASE_G_UNCOMPRESSED","value":"BigInt.new((Secp256k1::Util.public_key_uncompressed_prefix(EC_BASE_G)), 16)","doc":"The base point `G` in uncompressed form.","summary":"The base point G
in uncompressed form.
"},{"id":"EC_BASE_G_X","name":"EC_BASE_G_X","value":"BigInt.new(\"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\", 16)","doc":"The `x`-coordinate of the base point `G`.","summary":"The x
-coordinate of the base point G
.
"},{"id":"EC_BASE_G_Y","name":"EC_BASE_G_Y","value":"BigInt.new(\"483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8\", 16)","doc":"The `y`-coordinate of the base point `G`.","summary":"The y
-coordinate of the base point G
.
"},{"id":"EC_COFACTOR_H","name":"EC_COFACTOR_H","value":"BigInt.new(\"01\", 16)","doc":"The elliptic curve cofactor `h`.","summary":"The elliptic curve cofactor h
.
"},{"id":"EC_FACTOR_A","name":"EC_FACTOR_A","value":"BigInt.new(\"00\", 16)","doc":"The curve `E`: `y^2 = x^3 + ax + b` over `F_p` is defined by `a = 0`.\nAs the `a` constant is zero, the `ax` term in the curve equation is always zero,\nhence the curve equation becomes `y^2 = x^3 + b`.","summary":"The curve E
: y^2 = x^3 + ax + b
over F_p
is defined by a = 0
.
"},{"id":"EC_FACTOR_B","name":"EC_FACTOR_B","value":"BigInt.new(\"07\", 16)","doc":"The curve `E`: `y^2 = x^3 + b` over `F_p` is defined by `b = 7`,\nhence the curve equation becomes `y^2 = x^3 + 7`.","summary":"The curve E
: y^2 = x^3 + b
over F_p
is defined by b = 7
, hence the curve equation becomes y^2 = x^3 + 7
.
"},{"id":"EC_ORDER_N","name":"EC_ORDER_N","value":"BigInt.new(\"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141\", 16)","doc":"The order `n` of `G` defines the finite size of the Secp256k1 field `E`.","summary":"The order n
of G
defines the finite size of the Secp256k1 field E
.
"},{"id":"EC_PRIME_P","name":"EC_PRIME_P","value":"BigInt.new(\"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f\", 16)","doc":"The elliptic curve domain parameters over `F_p` associated with a Koblitz curve\nSecp256k1 are specified by the sextuple `T = (p, a, b, G, n, h)` where the finite\nfield `F_p` is defined by the prime `p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1`.","summary":"The elliptic curve domain parameters over F_p
associated with a Koblitz curve Secp256k1 are specified by the sextuple T = (p, a, b, G, n, h)
where the finite field F_p
is defined by the prime p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
.
"},{"id":"VERSION","name":"VERSION","value":"\"0.3.6\"","doc":"The `VERSION` of the `Secp256k1` module.","summary":"The VERSION
of the Secp256k1
module.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Implements 256-bit `Secp256k1` Koblitz elliptic curve.\nRef: [secg.org/sec2-v2.pdf](https://www.secg.org/sec2-v2.pdf)\n\n`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p.\nRef: [en.bitcoin.it/wiki/Secp256k1](https://en.bitcoin.it/wiki/Secp256k1)","summary":"Implements 256-bit Secp256k1
Koblitz elliptic curve.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"secp256k1/Secp256k1/Bitcoin","path":"Secp256k1/Bitcoin.html","kind":"module","full_name":"Secp256k1::Bitcoin","name":"Bitcoin","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/bitcoin.cr","line_number":16,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements the `Bitcoin` address space for the `Secp256k1` library.","summary":"Implements the Bitcoin
address space for the Secp256k1
library.
","class_methods":[{"html_id":"address_from_private(priv:BigInt,version=\"00\",compressed=true)-class-method","name":"address_from_private","doc":"Generates a `Bitcoin` address from a private key.\n\nParameters:\n* `priv` (`BigInt`): the private key as number.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n* `compressed` (`Bool`): indicator if address should be compressed or not, default: `true` (compressed).\n\n```\nSecp256k1::Bitcoin.address_from_private BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```","summary":"Generates a Bitcoin
address from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"args_string":"(priv : BigInt, version = \"00\", compressed = true)","args_html":"(priv : BigInt, version = "00", compressed = true)","location":{"filename":"src/bitcoin.cr","line_number":563,"url":null},"def":{"name":"address_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"p = Secp256k1::Util.public_key_from_private(priv)\naddress_from_public_point(p, version, compressed)\n"}},{"html_id":"address_from_public_key(pub:String,version=\"00\")-class-method","name":"address_from_public_key","doc":"Generates a `Bitcoin` address for any public key, compressed or uncompressed.\n\nParameters:\n* `pub` (`String`): the public key, compressed or uncompressed.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n\n```\nSecp256k1::Bitcoin.address_from_public_key \"03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b\"\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```\n\nNote, compressed public keys generate compressed addresses, whereas\nuncompressed keys generate uncompressed addresses.\n\nRaises if the public key is malformed.","summary":"Generates a Bitcoin
address for any public key, compressed or uncompressed.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""}],"args_string":"(pub : String, version = \"00\")","args_html":"(pub : String, version = "00")","location":{"filename":"src/bitcoin.cr","line_number":467,"url":null},"def":{"name":"address_from_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (pub.size === 130) || (pub.size === 66)\n sha2 = Hash.sha256(Hash.hex_to_bin(pub))\n ripe = Hash.ripemd160(Hash.hex_to_bin(sha2))\n ripe_versioned = \"#{version}#{ripe}\"\n hashed = Hash.sha256(Hash.hex_to_bin(ripe_versioned))\n hashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\n binary = \"#{ripe_versioned}#{hashed_twice[0, 8]}\"\n Hash.base58_encode(binary)\nelse\n raise(\"malformed public key (invalid key size: #{pub.size})\")\nend"}},{"html_id":"address_from_public_point(p:Secp256k1::ECPoint,version=\"00\",compressed=true)-class-method","name":"address_from_public_point","doc":"Generates a `Bitcoin` address from an public key as `ECPoint`.\n\nParameters:\n* `p` (`ECPoint`): the public key as point with `x` and `y` coordinates.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n* `compressed` (`Bool`): indicator if address should be compressed or not, default: `true` (compressed).\n\nSee `address_from_public_key` and `ECPoint` for usage instructions.","summary":"Generates a Bitcoin
address from an public key as ECPoint
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"args_string":"(p : Secp256k1::ECPoint, version = \"00\", compressed = true)","args_html":"(p : Secp256k1::ECPoint, version = "00", compressed = true)","location":{"filename":"src/bitcoin.cr","line_number":506,"url":null},"def":{"name":"address_from_public_point","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = Secp256k1::Util.public_key_uncompressed_prefix(p)\nif compressed\n pub = Secp256k1::Util.public_key_compressed_prefix(p)\nend\naddress_from_public_key(pub, version)\n"}},{"html_id":"address_from_wif(wif:String)-class-method","name":"address_from_wif","doc":"Gets a `Bitcoin` address from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.address_from_wif \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets a Bitcoin
address from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":526,"url":null},"def":{"name":"address_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if wif_is_valid?(wif)\n vers = version_byte_from_wif(wif)\n vers = vers.to_i(16)\n vers = vers - 128\n vers = Secp256k1::Util.to_padded_hex_01(vers)\n priv = private_key_from_wif(wif)\n priv = BigInt.new(priv, 16)\n comp = is_wif_compressed?(wif)\n address_from_private(priv, vers, comp)\nelse\n raise(\"invalid wallet import format (invalid wif: #{wif})\")\nend"}},{"html_id":"is_wif_compressed?(wif:String)-class-method","name":"is_wif_compressed?","doc":"Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.is_wif_compressed? \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => false\n```\n\nReturns _true_ if the key is compressed.\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":392,"url":null},"def":{"name":"is_wif_compressed?","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"versioned = Hash.base58_decode(wif)\nif (versioned.size === 74) || (versioned.size === 76)\n versioned.size === 76\nelse\n raise(\"invalid wallet import format (invalid wif size: #{versioned.size})\")\nend\n"}},{"html_id":"mini_is_valid?(m:String)-class-method","name":"mini_is_valid?","doc":"Validates wether a mini-private key has a correct checksum and formatting.\n\nParameters:\n* `m` (`String`): the mini-private key.\n\n```\nSecp256k1::Bitcoin.mini_is_valid? \"S7qq5k98DAvee6mtQgpg4xAJatT9mR\"\n# => true\n```\n\nReturns _true_ if the key contains a valid checksum and is formatted correctly.","summary":"Validates wether a mini-private key has a correct checksum and formatting.
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"args_string":"(m : String)","args_html":"(m : String)","location":{"filename":"src/bitcoin.cr","line_number":253,"url":null},"def":{"name":"mini_is_valid?","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"valid = m.size === 30\nvalid = valid && (m[0, 1] === \"S\")\nchecksum = Hash.sha256(\"#{m}?\")\nvalid && (checksum[0, 2] === \"00\")\n"}},{"html_id":"new_mini_private_key-class-method","name":"new_mini_private_key","doc":"Generates a new mini-private key (30 characters length, Base-56 encoded).\n\n```\nSecp256k1::Bitcoin.new_mini_private_key\n# => S7qq5k98DAvee6mtQgpg4xAJatT9mR\n```","summary":"Generates a new mini-private key (30 characters length, Base-56 encoded).
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/bitcoin.cr","line_number":193,"url":null},"def":{"name":"new_mini_private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"valid = false\nkey = String.new\nwhile !valid\n i = 1\n key = \"S\"\n while i < 30\n i = i + 1\n r = Random.rand(56)\n key = key + (Hash.base56_char(r))\n end\n valid = mini_is_valid?(key)\n if valid\n priv = private_key_from_mini(key)\n valid = valid && priv > 0\n valid = valid && (priv === (priv % Secp256k1::EC_ORDER_N))\n end\nend\nkey\n"}},{"html_id":"private_key_from_mini(m:String)-class-method","name":"private_key_from_mini","doc":"Gets a private key from a mini-private key if the key is valid.\n\nParameters:\n* `m` (`String`): the mini-private key.\n\n```\nSecp256k1::Bitcoin.private_key_from_mini \"S7qq5k98DAvee6mtQgpg4xAJatT9mR\"\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```\n\nRaises if the key is invalid.","summary":"Gets a private key from a mini-private key if the key is valid.
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"args_string":"(m : String)","args_html":"(m : String)","location":{"filename":"src/bitcoin.cr","line_number":232,"url":null},"def":{"name":"private_key_from_mini","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if mini_is_valid?(m)\n private_key = Hash.sha256(m)\n BigInt.new(private_key, 16)\nelse\n raise(\"mini private key is not valid (invalid checksum for: #{m})\")\nend"}},{"html_id":"private_key_from_wif(wif:String)-class-method","name":"private_key_from_wif","doc":"Gets a private key from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.private_key_from_wif \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets a private key from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":341,"url":null},"def":{"name":"private_key_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"checksum_key = Hash.base58_decode(wif)\nif (checksum_key.size == 74) || (checksum_key.size == 76)\n private_key = BigInt.new(checksum_key[2, 64], 16)\n Secp256k1::Util.to_padded_hex_32(private_key)\nelse\n raise(\"invalid wallet import format (invalid wif size: #{checksum_key.size})\")\nend\n"}},{"html_id":"version_byte_from_wif(wif:String)-class-method","name":"version_byte_from_wif","doc":"Gets the version byte from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.version_byte_from_wif \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => \"80\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets the version byte from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":366,"url":null},"def":{"name":"version_byte_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"versioned = Hash.base58_decode(wif)\nif (versioned.size === 74) || (versioned.size === 76)\n versioned[0, 2]\nelse\n raise(\"invalid wallet import format (invalid wif size: #{versioned.size})\")\nend\n"}},{"html_id":"wif_from_private(k:BigInt,version=\"80\",compr=\"\")-class-method","name":"wif_from_private","doc":"Gets a Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key.\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin).\n* `compr` (`String`): the compression byte, default: `\"\"` (uncompressed).\n\n```\nSecp256k1::Bitcoin.wif_from_private BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n```\n\nNote, the compression byte `compr` is either empty `\"\"` for uncompressed keys or\n`\"01\"` for compressed keys. See also `wif_from_private_compressed` and `wif_from_private_uncompressed`.","summary":"Gets a Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""},{"name":"compr","doc":null,"default_value":"\"\"","external_name":"compr","restriction":""}],"args_string":"(k : BigInt, version = \"80\", compr = \"\")","args_html":"(k : BigInt, version = "80", compr = "")","location":{"filename":"src/bitcoin.cr","line_number":277,"url":null},"def":{"name":"wif_from_private","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""},{"name":"compr","doc":null,"default_value":"\"\"","external_name":"compr","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"priv = Secp256k1::Util.to_padded_hex_32(k)\nversioned = \"#{version}#{priv}#{compr}\"\nhashed = Hash.sha256(Hash.hex_to_bin(versioned))\nhashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\nbinary = \"#{versioned}#{hashed_twice[0, 8]}\"\nHash.base58_encode(binary)\n"}},{"html_id":"wif_from_private_compressed(k:BigInt,version=\"80\")-class-method","name":"wif_from_private_compressed","doc":"Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin)\n\n```\nSecp256k1::Bitcoin.wif_from_private_compressed BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n```","summary":"Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"args_string":"(k : BigInt, version = \"80\")","args_html":"(k : BigInt, version = "80")","location":{"filename":"src/bitcoin.cr","line_number":310,"url":null},"def":{"name":"wif_from_private_compressed","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"wif_from_private(k, version, \"01\")"}},{"html_id":"wif_from_private_uncompressed(k:BigInt,version=\"80\")-class-method","name":"wif_from_private_uncompressed","doc":"Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin)\n\n```\nSecp256k1::Bitcoin.wif_from_private_uncompressed BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n```","summary":"Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"args_string":"(k : BigInt, version = \"80\")","args_html":"(k : BigInt, version = "80")","location":{"filename":"src/bitcoin.cr","line_number":325,"url":null},"def":{"name":"wif_from_private_uncompressed","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"wif_from_private(k, version, \"\")"}},{"html_id":"wif_is_valid?(wif:String)-class-method","name":"wif_is_valid?","doc":"Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.wif_is_valid? \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => true\n```\n\nReturns _true_ if the key contains a valid checksum and is formatted correctly.","summary":"Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":416,"url":null},"def":{"name":"wif_is_valid?","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"checksum_key = Hash.base58_decode(wif)\nvalid = (checksum_key.size === 74) || (checksum_key.size === 76)\nif valid\n private_key = private_key_from_wif(wif)\n valid = (valid && (private_key != \"-999\")) && (private_key.size === 64)\n versioned = checksum_key[0, 66]\n wif_checksum = checksum_key[66, 8]\n if checksum_key.size === 76\n versioned = checksum_key[0, 68]\n wif_checksum = checksum_key[68, 8]\n end\n hashed = Hash.sha256(Hash.hex_to_bin(versioned))\n hashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\n pk_checksum = hashed_twice[0, 8]\n valid = valid && (wif_checksum === pk_checksum)\nend\nvalid\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"secp256k1/Secp256k1/Bitcoin/Account","path":"Secp256k1/Bitcoin/Account.html","kind":"class","full_name":"Secp256k1::Bitcoin::Account","name":"Account","abstract":false,"superclass":{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/bitcoin.cr","line_number":34,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1/Bitcoin","kind":"module","full_name":"Secp256k1::Bitcoin","name":"Bitcoin"},"doc":"Implements a `Bitcoin` account containing a `Keypair`, a Wallet-Import Format,\nand an address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n* `compressed` (`Bool`): an indicator whether a compressed format should be used.\n* `address` (`String`): the public `Bitcoin` address.\n* `wif` (`String`): the private Wallet-Import Format (WIF).\n\n```\nbtc = Secp256k1::Bitcoin::Account.new\nbtc.wif\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\nbtc.address\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```","summary":"Implements a Bitcoin
account containing a Keypair
, a Wallet-Import Format, and an address.
","class_methods":[],"constructors":[{"html_id":"new(key_pair,version,compressed)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair` allowing for a custom\nnetwork version byte and compression.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n* `compressed` (`Bool`): an indicator whether a compressed format should be used.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key, \"00\", true\n# => #\n```\n\nRaises if the version byte is out of range.","summary":"Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom network version byte and compression.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":""}],"args_string":"(key_pair, version, compressed)","args_html":"(key_pair, version, compressed)","location":{"filename":"src/bitcoin.cr","line_number":125,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, version, compressed)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(key_pair,version)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair` allowing for a custom\nnetwork version byte.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key, \"1e\"\n# => #\n```\n\nNote, this always generates an uncompressed account for the specified network.\n\nRaises if the version byte is out of range.","summary":"Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom network version byte.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""}],"args_string":"(key_pair, version)","args_html":"(key_pair, version)","location":{"filename":"src/bitcoin.cr","line_number":97,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, version)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(key_pair)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair`.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key\n# => #\n```\n\nNote, this always generates an uncompressed mainnet Bitcoin account.","summary":"Generates a Bitcoin::Account
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","args_html":"(key_pair)","location":{"filename":"src/bitcoin.cr","line_number":74,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new-class-method","name":"new","doc":"Generates a new `Bitcoin::Account` from a fresh random `Keypair`.\n\n```\nbtc = Secp256k1::Bitcoin::Account.new\n# => #\n```\n\nNote, this always generates an uncompressed mainnet Bitcoin account.","summary":"Generates a new Bitcoin::Account
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/bitcoin.cr","line_number":54,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"address:String-instance-method","name":"address","doc":"The public `Bitcoin` address.","summary":"The public Bitcoin
address.
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/bitcoin.cr","line_number":42,"url":null},"def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@address"}},{"html_id":"address=(address:String)-instance-method","name":"address=","doc":"The public `Bitcoin` address.","summary":"The public Bitcoin
address.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"args_string":"(address : String)","args_html":"(address : String)","location":{"filename":"src/bitcoin.cr","line_number":42,"url":null},"def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"html_id":"compressed:Bool-instance-method","name":"compressed","doc":"An indicator whether a compressed format should be used.","summary":"An indicator whether a compressed format should be used.
","abstract":false,"args":[],"args_string":" : Bool","args_html":" : Bool","location":{"filename":"src/bitcoin.cr","line_number":40,"url":null},"def":{"name":"compressed","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@compressed"}},{"html_id":"compressed=(compressed:Bool)-instance-method","name":"compressed=","doc":"An indicator whether a compressed format should be used.","summary":"An indicator whether a compressed format should be used.
","abstract":false,"args":[{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":"Bool"}],"args_string":"(compressed : Bool)","args_html":"(compressed : Bool)","location":{"filename":"src/bitcoin.cr","line_number":40,"url":null},"def":{"name":"compressed=","args":[{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@compressed = compressed"}},{"html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\nbtc.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/bitcoin.cr","line_number":172,"url":null},"def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"html_id":"is_compressed?:Bool-instance-method","name":"is_compressed?","doc":"Tells if the `Bitcoin::Account` is compressed.\n\n```\nbtc.is_compressed?\n# => false\n```\n\nReturns _true_ if the compressed format is used.","summary":"Tells if the Bitcoin::Account
is compressed.
","abstract":false,"args":[],"args_string":" : Bool","args_html":" : Bool","location":{"filename":"src/bitcoin.cr","line_number":151,"url":null},"def":{"name":"is_compressed?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@compressed"}},{"html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","args_html":" : Keypair","location":{"filename":"src/bitcoin.cr","line_number":36,"url":null},"def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","args_html":"(key_pair : Keypair)","location":{"filename":"src/bitcoin.cr","line_number":36,"url":null},"def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"html_id":"to_s:String-instance-method","name":"to_s","doc":"Gets the account formatted as `Bitcoin` address.\n\n```\nbtc.to_s\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```","summary":"Gets the account formatted as Bitcoin
address.
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/bitcoin.cr","line_number":182,"url":null},"def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address"}},{"html_id":"version:String-instance-method","name":"version","doc":"The version byte determining the used network encoding.","summary":"The version byte determining the used network encoding.
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/bitcoin.cr","line_number":38,"url":null},"def":{"name":"version","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@version"}},{"html_id":"version=(version:String)-instance-method","name":"version=","doc":"The version byte determining the used network encoding.","summary":"The version byte determining the used network encoding.
","abstract":false,"args":[{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":"String"}],"args_string":"(version : String)","args_html":"(version : String)","location":{"filename":"src/bitcoin.cr","line_number":38,"url":null},"def":{"name":"version=","args":[{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@version = version"}},{"html_id":"version_wif-instance-method","name":"version_wif","doc":"Computes the version byte for the private Wallet-Import Format which is\noffset by `+ 0x80` from the public address `version` byte.\n\n```\nbtc.version_wif\n# => \"80\"\n```","summary":"Computes the version byte for the private Wallet-Import Format which is offset by + 0x80
from the public address #version
byte.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/bitcoin.cr","line_number":162,"url":null},"def":{"name":"version_wif","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_01((@version.to_i(16)) + 128)"}},{"html_id":"wif:String-instance-method","name":"wif","doc":"The private Wallet-Import Format (WIF).","summary":"The private Wallet-Import Format (WIF).
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/bitcoin.cr","line_number":44,"url":null},"def":{"name":"wif","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@wif"}},{"html_id":"wif=(wif:String)-instance-method","name":"wif=","doc":"The private Wallet-Import Format (WIF).","summary":"The private Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":44,"url":null},"def":{"name":"wif=","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@wif = wif"}}],"macros":[],"types":[]}]},{"html_id":"secp256k1/Secp256k1/Core","path":"Secp256k1/Core.html","kind":"module","full_name":"Secp256k1::Core","name":"Core","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/core.cr","line_number":20,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements 256-bit `Secp256k1` Koblitz elliptic curve.\nRef: [secg.org/sec2-v2.pdf](https://www.secg.org/sec2-v2.pdf)\n\n`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p.\nRef: [en.bitcoin.it/wiki/Secp256k1](https://en.bitcoin.it/wiki/Secp256k1)","summary":"Implements 256-bit Secp256k1
Koblitz elliptic curve.
","class_methods":[{"html_id":"ec_add(p:ECPoint,q:ECPoint,prime=EC_PRIME_P)-class-method","name":"ec_add","doc":"The elliptic curve jive addition of point `p(x, y)` and `q(x, y)`.\n\nWe basically _draw_ a line between `p` and `q` which will intersect the\ncurve in the point `r` which will be mirrored over the `x`-axis.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the jive addition.\n* `q` (`ECPoint`): the point `q(x, y)` to be used in the jive addition.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns another `ECPoint` as result.","summary":"The elliptic curve jive addition of point p(x, y)
and q(x, y)
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"q","doc":null,"default_value":"","external_name":"q","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(p : ECPoint, q : ECPoint, prime = EC_PRIME_P)","args_html":"(p : ECPoint, q : ECPoint, prime = EC_PRIME_P)","location":{"filename":"src/core.cr","line_number":60,"url":null},"def":{"name":"ec_add","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"q","doc":null,"default_value":"","external_name":"q","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x_delta = q.x - p.x\nx_inv = ec_mod_inv(x_delta)\ny_delta = q.y - p.y\nm = (y_delta * x_inv) % prime\nx = (((m * m) - p.x) - q.x) % prime\ny = ((m * (p.x - x)) - p.y) % prime\nx = BigInt.new(x)\ny = BigInt.new(y)\nECPoint.new(x, y)\n"}},{"html_id":"ec_double(p:ECPoint,prime=EC_PRIME_P)-class-method","name":"ec_double","doc":"The elliptic curve juke point doubling of `p(x, y)`.\n\nThis is a special case of addition where both points are the same.\nWe _draw_ a tangent line at `p` which will intersect the curve\nat point `r` which will be mirrored over the `x`-axis.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the juke doubling.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns another `ECPoint` as result.","summary":"The elliptic curve juke point doubling of p(x, y)
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(p : ECPoint, prime = EC_PRIME_P)","args_html":"(p : ECPoint, prime = EC_PRIME_P)","location":{"filename":"src/core.cr","line_number":83,"url":null},"def":{"name":"ec_double","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"lam_numer = ((3 * p.x) * p.x) + EC_FACTOR_A\nlam_denom = 2 * p.y\nlam_inv = ec_mod_inv(lam_denom)\nlam = (lam_numer * lam_inv) % prime\nx = ((lam * lam) - (2 * p.x)) % prime\ny = ((lam * (p.x - x)) - p.y) % prime\nx = BigInt.new(x)\ny = BigInt.new(y)\nECPoint.new(x, y)\n"}},{"html_id":"ec_mod_inv(a:BigInt,prime=EC_PRIME_P)-class-method","name":"ec_mod_inv","doc":"Computes the elliptic curve modular multiplicative inverse of `a`.\n\nParemeters:\n* `a` (`BigInt`): the integer that we want the modular inverse of.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns a `BigInt` value as result.","summary":"Computes the elliptic curve modular multiplicative inverse of a
.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"BigInt"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(a : BigInt, prime = EC_PRIME_P)","args_html":"(a : BigInt, prime = EC_PRIME_P)","location":{"filename":"src/core.cr","line_number":28,"url":null},"def":{"name":"ec_mod_inv","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"BigInt"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m_low = 1\nm_high = 0\nv_low = a % prime\nv_high = prime\nwhile v_low > 1\n v_ratio = v_high // v_low\n m_low_r = m_low * v_ratio\n v_low_r = v_low * v_ratio\n m = m_high - m_low_r\n v = v_high - v_low_r\n m_high = m_low\n v_high = v_low\n m_low = m\n v_low = v\nend\nm_low % prime\n"}},{"html_id":"ec_mul(p:ECPoint,s:BigInt)-class-method","name":"ec_mul","doc":"The elliptic curve sequence multiplication of point `p(x, y)` and\na skalar `s`.\n\nWith `s` being a private key within the elliptic curve field size of `EC_ORDER_N`.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the sequencing.\n* `s` (`BigInt`): a skalar, in most cases a private key.\n\nReturns another `ECPoint` as result, in most cases a public key.","summary":"The elliptic curve sequence multiplication of point p(x, y)
and a skalar s
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(p : ECPoint, s : BigInt)","args_html":"(p : ECPoint, s : BigInt)","location":{"filename":"src/core.cr","line_number":105,"url":null},"def":{"name":"ec_mul","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (s === 0) || s >= EC_ORDER_N\n raise(\"invalid private key: outside of ec field size.\")\nend\ns_bin = s.to_s(2)\nq = p\ns_bin.each_char_with_index do |char, index|\n if index === 0\n next\n end\n q = ec_double(q)\n if char === '1'\n q = ec_add(q, p)\n end\nend\nq\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/ECDSASignature","path":"Secp256k1/ECDSASignature.html","kind":"struct","full_name":"Secp256k1::ECDSASignature","name":"ECDSASignature","abstract":false,"superclass":{"html_id":"secp256k1/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"secp256k1/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"secp256k1/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/structs.cr","line_number":127,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A basic ECDSA Signature containing a random point `r` and the\nsignature proof `s`.\n\nSee: `Signature` for signature generation.\n\nProperties:\n* `r` (`BigInt`): the `x` coordinate of a random point `R`.\n* `s` (`BigInt`): the signature proof of a message.\n\n```\nsig = ECDSASignature.new r.x, proof\n```","summary":"A basic ECDSA Signature containing a random point #r
and the signature proof #s
.
","class_methods":[],"constructors":[{"html_id":"new(r:BigInt,s:BigInt)-class-method","name":"new","doc":"A signature always requires the random point `r` and the signature proof `s`.\n\nParameters:\n* `r` (`BigInt`): the `x` coordinate of a random point `R`.\n* `s` (`BigInt`): the signature proof of a message.","summary":"A signature always requires the random point #r
and the signature proof #s
.
","abstract":false,"args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(r : BigInt, s : BigInt)","args_html":"(r : BigInt, s : BigInt)","location":{"filename":"src/structs.cr","line_number":139,"url":null},"def":{"name":"new","args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(r, s)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"r:BigInt-instance-method","name":"r","doc":"The `x` coordinate of a random point `R`.","summary":"The x
coordinate of a random point R
.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":129,"url":null},"def":{"name":"r","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@r"}},{"html_id":"r=(r:BigInt)-instance-method","name":"r=","doc":"The `x` coordinate of a random point `R`.","summary":"The x
coordinate of a random point R
.
","abstract":false,"args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"}],"args_string":"(r : BigInt)","args_html":"(r : BigInt)","location":{"filename":"src/structs.cr","line_number":129,"url":null},"def":{"name":"r=","args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@r = r"}},{"html_id":"s:BigInt-instance-method","name":"s","doc":"The signature proof of a message.","summary":"The signature proof of a message.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":132,"url":null},"def":{"name":"s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@s"}},{"html_id":"s=(s:BigInt)-instance-method","name":"s=","doc":"The signature proof of a message.","summary":"The signature proof of a message.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(s : BigInt)","args_html":"(s : BigInt)","location":{"filename":"src/structs.cr","line_number":132,"url":null},"def":{"name":"s=","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@s = s"}}],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/ECPoint","path":"Secp256k1/ECPoint.html","kind":"struct","full_name":"Secp256k1::ECPoint","name":"ECPoint","abstract":false,"superclass":{"html_id":"secp256k1/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"secp256k1/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"secp256k1/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/structs.cr","line_number":99,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A point in the two-dimensional space of an elliptic curve.\n\nProperties:\n* `x` (`BigInt`): the position on the x-axis.\n* `y` (`BigInt`): the position on the y-axis.\n\n```\np = ECPoint.new BigInt.new(0), BigInt.new(0)\np.x\n# => 0\np.y\n# => 0\n```","summary":"A point in the two-dimensional space of an elliptic curve.
","class_methods":[],"constructors":[{"html_id":"new(x:BigInt,y:BigInt)-class-method","name":"new","doc":"An ECPoint always requires two coordinates `x`, `y`.\n\nParameters:\n* `x` (`BigInt`): the position on the x-axis.\n* `y` (`BigInt`): the position on the y-axis.","summary":"An ECPoint always requires two coordinates #x
, #y
.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"args_string":"(x : BigInt, y : BigInt)","args_html":"(x : BigInt, y : BigInt)","location":{"filename":"src/structs.cr","line_number":111,"url":null},"def":{"name":"new","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(x, y)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"x:BigInt-instance-method","name":"x","doc":"The position on the x-axis.","summary":"The position on the x-axis.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":101,"url":null},"def":{"name":"x","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@x"}},{"html_id":"x=(x:BigInt)-instance-method","name":"x=","doc":"The position on the x-axis.","summary":"The position on the x-axis.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"}],"args_string":"(x : BigInt)","args_html":"(x : BigInt)","location":{"filename":"src/structs.cr","line_number":101,"url":null},"def":{"name":"x=","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@x = x"}},{"html_id":"y:BigInt-instance-method","name":"y","doc":"The position on the y-axis.","summary":"The position on the y-axis.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":104,"url":null},"def":{"name":"y","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@y"}},{"html_id":"y=(y:BigInt)-instance-method","name":"y=","doc":"The position on the y-axis.","summary":"The position on the y-axis.
","abstract":false,"args":[{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"args_string":"(y : BigInt)","args_html":"(y : BigInt)","location":{"filename":"src/structs.cr","line_number":104,"url":null},"def":{"name":"y=","args":[{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@y = y"}}],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Ethereum","path":"Secp256k1/Ethereum.html","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/ethereum.cr","line_number":19,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements the `Ethereum` address space for the `Secp256k1` library.","summary":"Implements the Ethereum
address space for the Secp256k1
library.
","class_methods":[{"html_id":"address_checksum(adr:String)-class-method","name":"address_checksum","doc":"Returns a checksummed `Ethereum` address as per EIP-55.\n\nReference: [eips.ethereum.org/EIPS/eip-55](https://eips.ethereum.org/EIPS/eip-55)\n\nParameters:\n* `adr` (`String`): an unchecked `Ethereum` address.\n\n```\nSecp256k1::Ethereum.address_checksum \"0x7598c0fbaeb021161ce2e598f45ddee90fe5c6f7\"\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nRaises if address is malformed.","summary":"Returns a checksummed Ethereum
address as per EIP-55.
","abstract":false,"args":[{"name":"adr","doc":null,"default_value":"","external_name":"adr","restriction":"String"}],"args_string":"(adr : String)","args_html":"(adr : String)","location":{"filename":"src/ethereum.cr","line_number":210,"url":null},"def":{"name":"address_checksum","args":[{"name":"adr","doc":null,"default_value":"","external_name":"adr","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"adr = adr.downcase\nif adr.size === 42\n adr = adr[2, 40]\nend\nif adr.size === 40\n keccak = Hash.keccak256(adr)\n address = \"0x\"\n i = 0\n while i < adr.size\n k = keccak[i].to_i(16)\n if k >= 8\n address = address + \"#{adr[i]}\".upcase\n else\n address = address + \"#{adr[i]}\".downcase\n end\n i = i + 1\n end\n address\nelse\n raise(\"malformed ethereum address (invalid size: #{adr.size})\")\nend\n"}},{"html_id":"address_from_private(priv:BigInt)-class-method","name":"address_from_private","doc":"Generates a checksummed `Ethereum` address from a private key.\n\nParameters:\n* `priv` (`BigInt`): a private key as number.\n\n```\nSecp256k1::Ethereum.address_from_private BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nNote, that the returned `Ethereum` address is already checksummed.","summary":"Generates a checksummed Ethereum
address from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(priv : BigInt)","args_html":"(priv : BigInt)","location":{"filename":"src/ethereum.cr","line_number":297,"url":null},"def":{"name":"address_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"p = Secp256k1::Util.public_key_from_private(priv)\naddress_from_public_point(p)\n"}},{"html_id":"address_from_public_key(pub:String)-class-method","name":"address_from_public_key","doc":"Generates a checksummed `Ethereum` address for an uncompressed public key.\n\nParameters:\n* `pub` (`String`): an uncompressed public key string.\n\n```\nSecp256k1::Ethereum.address_from_public_key \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nNote, that the returned `Ethereum` address is already checksummed.\n\nRaises if the public key is malformed.","summary":"Generates a checksummed Ethereum
address for an uncompressed public key.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"}],"args_string":"(pub : String)","args_html":"(pub : String)","location":{"filename":"src/ethereum.cr","line_number":256,"url":null},"def":{"name":"address_from_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if pub.size === 130\n pub = pub[2, 128]\nend\nif pub.size === 128\n keccak = Hash.keccak256(Hash.hex_to_bin(pub))\n address_checksum(keccak[24, 40])\nelse\n raise(\"malformed public key (invalid key size: #{pub.size})\")\nend\n"}},{"html_id":"address_from_public_point(p:Secp256k1::ECPoint)-class-method","name":"address_from_public_point","doc":"Generates a checksummed `Ethereum` address from an public key as `ECPoint`.\n\nParameters:\n* `p` (`ECPoint`): a public key point with `x` and `y` coordinates.\n\nSee `address_from_public_key` and `ECPoint` for usage instructions.","summary":"Generates a checksummed Ethereum
address from an public key as ECPoint
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"}],"args_string":"(p : Secp256k1::ECPoint)","args_html":"(p : Secp256k1::ECPoint)","location":{"filename":"src/ethereum.cr","line_number":280,"url":null},"def":{"name":"address_from_public_point","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = Secp256k1::Util.public_key_uncompressed(p)\naddress_from_public_key(pub)\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"secp256k1/Secp256k1/Ethereum/Account","path":"Secp256k1/Ethereum/Account.html","kind":"class","full_name":"Secp256k1::Ethereum::Account","name":"Account","abstract":false,"superclass":{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/ethereum.cr","line_number":33,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1/Ethereum","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum"},"doc":"Implements an `Ethereum` account containing a `Keypair` and an address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `address` (`String`): the public checksummed `Ethereum` address.\n\n```\neth = Secp256k1::Ethereum::Account.new\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\neth.address\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```","summary":"Implements an Ethereum
account containing a Keypair
and an address.
","class_methods":[],"constructors":[{"html_id":"new(key_pair)-class-method","name":"new","doc":"Generates an `Ethereum::Account` from a provided `Keypair`.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\neth = Secp256k1::Ethereum::Account.new key\n# => #\n```","summary":"Generates an Ethereum::Account
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","args_html":"(key_pair)","location":{"filename":"src/ethereum.cr","line_number":57,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new-class-method","name":"new","doc":"Generates a new `Ethereum::Account` from a fresh random `Keypair`.\n\n```\neth = Secp256k1::Ethereum::Account.new\n# => #\n```","summary":"Generates a new Ethereum::Account
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":45,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"address:String-instance-method","name":"address","doc":"The public checksummed `Ethereum` address.","summary":"The public checksummed Ethereum
address.
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/ethereum.cr","line_number":37,"url":null},"def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@address"}},{"html_id":"address=(address:String)-instance-method","name":"address=","doc":"The public checksummed `Ethereum` address.","summary":"The public checksummed Ethereum
address.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"args_string":"(address : String)","args_html":"(address : String)","location":{"filename":"src/ethereum.cr","line_number":37,"url":null},"def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":67,"url":null},"def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","args_html":" : Keypair","location":{"filename":"src/ethereum.cr","line_number":35,"url":null},"def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","args_html":"(key_pair : Keypair)","location":{"filename":"src/ethereum.cr","line_number":35,"url":null},"def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"html_id":"to_s-instance-method","name":"to_s","doc":"Gets the account formatted as `Ethereum` address.\n\n```\neth.to_s\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```","summary":"Gets the account formatted as Ethereum
address.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":77,"url":null},"def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Ethereum.address_checksum(@address)"}}],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Ethereum/Enode","path":"Secp256k1/Ethereum/Enode.html","kind":"class","full_name":"Secp256k1::Ethereum::Enode","name":"Enode","abstract":false,"superclass":{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/ethereum.cr","line_number":95,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1/Ethereum","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum"},"doc":"Implements an `Ethereum` devp2p enode containing a `Keypair` and an IP address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `address` (`Socket::IPAddress`): the public (or local) IP address with port.\n\n```\np2p = Secp256k1::Ethereum::Enode.new\np2p.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\np2p.to_s\n# => \"enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303\"\n```","summary":"Implements an Ethereum
devp2p enode containing a Keypair
and an IP address.
","class_methods":[],"constructors":[{"html_id":"new(key_pair,host,port)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair` and a custom IP address with port.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key, \"192.168.13.37\", 31337\n# => #\n```","summary":"Generates an Ethereum::Enode
from a provided Keypair
and a custom IP address with port.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"host","doc":null,"default_value":"","external_name":"host","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"args_string":"(key_pair, host, port)","args_html":"(key_pair, host, port)","location":{"filename":"src/ethereum.cr","line_number":147,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"host","doc":null,"default_value":"","external_name":"host","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, host, port)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(key_pair,port)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair` and a custom port.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key, 50000\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates an Ethereum::Enode
from a provided Keypair
and a custom port.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"args_string":"(key_pair, port)","args_html":"(key_pair, port)","location":{"filename":"src/ethereum.cr","line_number":136,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, port)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(key_pair)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair`.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates an Ethereum::Enode
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","args_html":"(key_pair)","location":{"filename":"src/ethereum.cr","line_number":123,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new-class-method","name":"new","doc":"Generates a new `Ethereum::Enode` from a fresh random `Keypair`.\n\n```\np2p = Secp256k1::Ethereum::Enode.new\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates a new Ethereum::Enode
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":109,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"address:Socket::IPAddress-instance-method","name":"address","doc":"The public (or local) IP address with port.","summary":"The public (or local) IP address with port.
","abstract":false,"args":[],"args_string":" : Socket::IPAddress","args_html":" : Socket::IPAddress","location":{"filename":"src/ethereum.cr","line_number":99,"url":null},"def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Socket::IPAddress","visibility":"Public","body":"@address"}},{"html_id":"address=(address:Socket::IPAddress)-instance-method","name":"address=","doc":"The public (or local) IP address with port.","summary":"The public (or local) IP address with port.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"Socket::IPAddress"}],"args_string":"(address : Socket::IPAddress)","args_html":"(address : Socket::IPAddress)","location":{"filename":"src/ethereum.cr","line_number":99,"url":null},"def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"Socket::IPAddress"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"html_id":"get_my_ip-instance-method","name":"get_my_ip","doc":"Tries to find out the public IP address for the node.\n\nIt queries [ident.me](http://ident.me/) for a potential public IP and silently\nfalls back to \"127.0.0.1\" if it fails without raising. _Should be used with caution._\n\n```\np2p.get_my_ip\n# => \"84.160.86.205\"\n```","summary":"Tries to find out the public IP address for the node.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":160,"url":null},"def":{"name":"get_my_ip","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ip = nil\nbegin\n ip = (HTTP::Client.get(\"http://ident.me/\")).body.to_s\nrescue\n ip = \"127.0.0.1\"\nensure\n if ip.nil? || ip.size < 2\n ip = \"127.0.0.1\"\n end\nend\nip\n"}},{"html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\np2p.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":182,"url":null},"def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","args_html":" : Keypair","location":{"filename":"src/ethereum.cr","line_number":97,"url":null},"def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","args_html":"(key_pair : Keypair)","location":{"filename":"src/ethereum.cr","line_number":97,"url":null},"def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"html_id":"to_s-instance-method","name":"to_s","doc":"Gets the `Enode` formatted as devp2p enode address.\n\n```\np2p.to_s\n# => \"enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303\"\n```","summary":"Gets the Enode
formatted as devp2p enode address.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":192,"url":null},"def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"enode://#{@key_pair.to_s}@#{@address.to_s}\""}}],"macros":[],"types":[]}]},{"html_id":"secp256k1/Secp256k1/Hash","path":"Secp256k1/Hash.html","kind":"module","full_name":"Secp256k1::Hash","name":"Hash","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/hash.cr","line_number":20,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"BASE_56","name":"BASE_56","value":"\"23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz\"","doc":"The Base-56 alphabet for `Bitcoin` mini-private keys is a Base-58 alphabet\nwithout `1` and `o` to additionally omit more similar-looking letters.","summary":"The Base-56 alphabet for Bitcoin
mini-private keys is a Base-58 alphabet without 1
and o
to additionally omit more similar-looking letters.
"},{"id":"BASE_58","name":"BASE_58","value":"\"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\"","doc":"The Base-58 alphabet for `Bitcoin` addresses is a Base-64 alphabet without\n`0`, `O`, `I`, and `l` to omit similar-looking letters.","summary":"The Base-58 alphabet for Bitcoin
addresses is a Base-64 alphabet without 0
, O
, I
, and l
to omit similar-looking letters.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"The `Secp256k1::Hash` module wraps various hashing functions for convenience\nand exposes them for general use.","summary":"The Secp256k1::Hash
module wraps various hashing functions for convenience and exposes them for general use.
","class_methods":[{"html_id":"base56_char(i:Int32)-class-method","name":"base56_char","doc":"Gets a character from the Base-56 alphabet at position `i`.\n\nParameters:\n* `i` (`Int32`): the position in the Base-56 alphabet.\n\n```\nSecp256k1::Hash.base56_char 13\n# => 'F'\n```","summary":"Gets a character from the Base-56 alphabet at position i
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","args_html":"(i : Int32)","location":{"filename":"src/hash.cr","line_number":211,"url":null},"def":{"name":"base56_char","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"i = i % 56\nBASE_56[i]\n"}},{"html_id":"base58_char(i:Int32)-class-method","name":"base58_char","doc":"Gets a character from the Base-58 alphabet at position `i`.\n\nParameters:\n* `i` (`Int32`): the position in the Base-58 alphabet.\n\n```\nSecp256k1::Hash.base58_char 13\n# => 'E'\n```","summary":"Gets a character from the Base-58 alphabet at position i
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","args_html":"(i : Int32)","location":{"filename":"src/hash.cr","line_number":225,"url":null},"def":{"name":"base58_char","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"i = i % 58\nBASE_58[i]\n"}},{"html_id":"base58_decode(s:String)-class-method","name":"base58_decode","doc":"Decodes a hexadecimal string from a Base-58 encoded string.\n\nParameters:\n* `s` (`String`): The Base-58 encoded string to be decoded.\n\n```\nSecp256k1::Hash.base58_decode \"1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt\"\n# => \"007d7935bde6c9341de87a4d64588783033e23472d7322c46b\"\n```","summary":"Decodes a hexadecimal string from a Base-58 encoded string.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","args_html":"(s : String)","location":{"filename":"src/hash.cr","line_number":146,"url":null},"def":{"name":"base58_decode","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"index = 0\ndecimal = BigInt.new(0)\nwhile index < s.size\n b58_char = s[index]\n position = BASE_58.index(b58_char)\n if !position.nil?\n decimal = (decimal * 58) + position\n index = index + 1\n else\n raise(\"cannot decode, invalid base58 character: '#{s[index]}'\")\n end\nend\nhex = decimal.to_s(16)\nleading = 0\nwhile s[leading] === '1'\n leading = leading + 1\n hex = \"00#{hex}\"\nend\nhex\n"}},{"html_id":"base58_encode(h:String)-class-method","name":"base58_encode","doc":"Encodes a Base-58 string from a hexadecimal string.\n\nParameters:\n* `h` (`String`): The hexadecimal string to be encoded.\n\n```\nSecp256k1::Hash.base58_encode \"007d7935bde6c9341de87a4d64588783033e23472d7322c46b\"\n# => \"1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt\"\n```","summary":"Encodes a Base-58 string from a hexadecimal string.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":180,"url":null},"def":{"name":"base58_encode","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = BigInt.new(h, 16)\nadr = String.new\nwhile pub > 0\n pub, rem = pub.divmod(58)\n adr = adr + (base58_char(rem.to_i))\nend\ni, s = 0, 2\ncurrent_byte = h[i, s]\nwhile (current_byte.to_i(16)) === 0\n adr = \"#{adr}1\"\n i = i + s\n current_byte = h[i, s]\nend\nadr.reverse\n"}},{"html_id":"bin_to_hex(b:Bytes)-class-method","name":"bin_to_hex","doc":"Helper function to convert byte arrays to hexadecimal strings.\n\nParameters:\n* `b` (`Bytes`): the byte array to be converted.\n\n```\nSecp256k1::Hash.bin_to_hex Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n=> \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n```","summary":"Helper function to convert byte arrays to hexadecimal strings.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":239,"url":null},"def":{"name":"bin_to_hex","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"b.hexstring"}},{"html_id":"hex_to_bin(h:String)-class-method","name":"hex_to_bin","doc":"Helper function to convert hexadecimal strings to byte arrays.\n\nParameters:\n* `h` (`String`): the hexadecimal string to be converted.\n\n```\nSecp256k1::Hash.hex_to_bin \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n=> Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n```","summary":"Helper function to convert hexadecimal strings to byte arrays.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":252,"url":null},"def":{"name":"hex_to_bin","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h.hexbytes"}},{"html_id":"keccak256(b:Bytes)-class-method","name":"keccak256","doc":"Operating a Keccak-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.keccak256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"fcb41efa0456ba9f27e573422d6b5898c61da6f2137d07e4dae618eddd72e003\"\n```","summary":"Operating a Keccak-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":66,"url":null},"def":{"name":"keccak256","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"keccak = Digest::Keccak3.new(256)\n(keccak.update(b)).hexdigest\n"}},{"html_id":"keccak256(h:String)-class-method","name":"keccak256","doc":"Operating a Keccak-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.keccak256 \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"99cfa79866ec88f87f8e25a98a4b9873f3f8ee82482a317a5494572b00f51cec\"\n```","summary":"Operating a Keccak-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":80,"url":null},"def":{"name":"keccak256","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"keccak = Digest::Keccak3.new(256)\n(keccak.update(h)).hexdigest\n"}},{"html_id":"ripemd160(b:Bytes)-class-method","name":"ripemd160","doc":"Operating a RIPEMD-160 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.ripemd160 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"5f3455f9ac58e25be08c99a7090108751b4796b9\"\n```","summary":"Operating a RIPEMD-160 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":120,"url":null},"def":{"name":"ripemd160","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"RIPEMD160\")).update(b)).final.hexstring"}},{"html_id":"ripemd160(h:String)-class-method","name":"ripemd160","doc":"Operating a RIPEMD-160 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.ripemd160 \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"46dff6cd5666c8e67db26ac0dfaf685bf71fc5f6\"\n```","summary":"Operating a RIPEMD-160 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":133,"url":null},"def":{"name":"ripemd160","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"RIPEMD160\")).update(h)).final.hexstring"}},{"html_id":"sha256(b:Bytes)-class-method","name":"sha256","doc":"Operating a SHA2-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.sha256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"2739cc5f45c0e05236527e4e687dc54f0d5e88be64b9a90e5264a6721c0c71f2\"\n```","summary":"Operating a SHA2-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":94,"url":null},"def":{"name":"sha256","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"SHA256\")).update(b)).final.hexstring"}},{"html_id":"sha256(h:String)-class-method","name":"sha256","doc":"Operating a SHA2-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.sha256 \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"452a41c28c9981faebb402095a5d553de28dc212338057aed27081110dfb907a\"\n```","summary":"Operating a SHA2-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":107,"url":null},"def":{"name":"sha256","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"SHA256\")).update(h)).final.hexstring"}},{"html_id":"sha3(b:Bytes)-class-method","name":"sha3","doc":"Operating a SHA3-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.sha3 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"66bb65180108362a3e25ba8282f7b96bfe840ce34a2e5dbc421aa8a590cc5f2e\"\n```","summary":"Operating a SHA3-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":38,"url":null},"def":{"name":"sha3","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sha3 = Digest::SHA3.new(256)\n(sha3.update(b)).hexdigest\n"}},{"html_id":"sha3(h:String)-class-method","name":"sha3","doc":"Operating a SHA3-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.sha3 \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"aedc012933679615eb93fb0063f53010e6f0034e92aaccf97dacc46e338037e9\"\n```","summary":"Operating a SHA3-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":52,"url":null},"def":{"name":"sha3","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sha3 = Digest::SHA3.new(256)\n(sha3.update(h)).hexdigest\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Keypair","path":"Secp256k1/Keypair.html","kind":"class","full_name":"Secp256k1::Keypair","name":"Keypair","abstract":false,"superclass":{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/structs.cr","line_number":34,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements a `Secp256k1` key pair containing a private and a public key.\n\nProperties:\n* `private_key` (`BigInt`): the secret as known as the private key.\n* `public_key` (`ECPoint`): the point on the elliptic curve as known as the public key.\n\n```\nkey = Secp256k1::Keypair.new\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\nkey.to_s\n# => \"e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f\"\n```","summary":"Implements a Secp256k1
key pair containing a private and a public key.
","class_methods":[],"constructors":[{"html_id":"new(private_key)-class-method","name":"new","doc":"Generates a new keypair using a provided private key.\n\nParameters:\n* `private_key` (`BigInt`): the secret as known as the private key.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => #\n```","summary":"Generates a new keypair using a provided private key.
","abstract":false,"args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":""}],"args_string":"(private_key)","args_html":"(private_key)","location":{"filename":"src/structs.cr","line_number":61,"url":null},"def":{"name":"new","args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(private_key)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new-class-method","name":"new","doc":"Generates a new keypair using a fresh random private key.\n\n```\nkey = Secp256k1::Keypair.new\n# => #\n```","summary":"Generates a new keypair using a fresh random private key.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/structs.cr","line_number":47,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/structs.cr","line_number":71,"url":null},"def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@private_key)"}},{"html_id":"private_key:BigInt-instance-method","name":"private_key","doc":"The secret as known as the private key.","summary":"The secret as known as the private key.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":36,"url":null},"def":{"name":"private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@private_key"}},{"html_id":"private_key=(private_key:BigInt)-instance-method","name":"private_key=","doc":"The secret as known as the private key.","summary":"The secret as known as the private key.
","abstract":false,"args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":"BigInt"}],"args_string":"(private_key : BigInt)","args_html":"(private_key : BigInt)","location":{"filename":"src/structs.cr","line_number":36,"url":null},"def":{"name":"private_key=","args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@private_key = private_key"}},{"html_id":"public_key:ECPoint-instance-method","name":"public_key","doc":"The point on the elliptic curve as known as the public key.","summary":"The point on the elliptic curve as known as the public key.
","abstract":false,"args":[],"args_string":" : ECPoint","args_html":" : ECPoint","location":{"filename":"src/structs.cr","line_number":39,"url":null},"def":{"name":"public_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ECPoint","visibility":"Public","body":"@public_key"}},{"html_id":"public_key=(public_key:ECPoint)-instance-method","name":"public_key=","doc":"The point on the elliptic curve as known as the public key.","summary":"The point on the elliptic curve as known as the public key.
","abstract":false,"args":[{"name":"public_key","doc":null,"default_value":"","external_name":"public_key","restriction":"ECPoint"}],"args_string":"(public_key : ECPoint)","args_html":"(public_key : ECPoint)","location":{"filename":"src/structs.cr","line_number":39,"url":null},"def":{"name":"public_key=","args":[{"name":"public_key","doc":null,"default_value":"","external_name":"public_key","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@public_key = public_key"}},{"html_id":"to_s-instance-method","name":"to_s","doc":"Gets the key formatted as uncompressed public key string.\n\n```\nkey.to_s\n# => \"e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f\"\n```","summary":"Gets the key formatted as uncompressed public key string.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/structs.cr","line_number":81,"url":null},"def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.public_key_uncompressed(@public_key)"}}],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Signature","path":"Secp256k1/Signature.html","kind":"module","full_name":"Secp256k1::Signature","name":"Signature","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/signature.cr","line_number":18,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements `ECDSASignature` generation and verification for `Secp256k1`\nelliptic curves.\nRef: [cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages](https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages)","summary":"Implements ECDSASignature
generation and verification for Secp256k1
elliptic curves.
","class_methods":[{"html_id":"sign(msg:String,priv:BigInt)-class-method","name":"sign","doc":"Signs a message and creates a signature proof using a private key.\n\nThe ECDSA signing algorithm (RFC-6979) takes as input a message `msg`\nand a private key `priv`. It produces as output a signature, which\nconsists of pair of integers `(r, s)`, where `r` is the `x`-coordinate\nof a random point on our curve and `s` is the signature proof.\n\nParameters:\n* `msg` (`String`): A message string to sign.\n* `priv` (`BigInt`): A private key to sign with.\n\n```\nsig = Secp256k1::Signature.sign \"Hello, World!\", BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\nsig.r\n# => \"63945398370917837063250848409972066837033757647691696776146735867163610886143\"\nsig.s\n# => \"20291418537568297129028959685291490143232574306335372594306006819765182564103\"\n```","summary":"Signs a message and creates a signature proof using a private key.
","abstract":false,"args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(msg : String, priv : BigInt)","args_html":"(msg : String, priv : BigInt)","location":{"filename":"src/signature.cr","line_number":37,"url":null},"def":{"name":"sign","args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hash = BigInt.new(Hash.sha256(msg), 16)\nk = Util.new_private_key\nr = (Core.ec_mul(EC_BASE_G, k)).x % EC_ORDER_N\nk_inv = Core.ec_mod_inv(k, EC_ORDER_N)\ns = ((hash + (r * priv)) * k_inv) % EC_ORDER_N\nECDSASignature.new(r, s)\n"}},{"html_id":"verify(msg:String,sig:ECDSASignature,pub:ECPoint)-class-method","name":"verify","doc":"Verifies a signature of a message against a public key.\n\nThe algorithm to verify an ECDSA signature takes as input the signed message `msg`\nand the signature `(r, s)` produced from `sign` and the public key `pub`,\ncorresponding to the signer's private key. The result is boolean.\n\nParameters:\n* `msg` (`String`): A message string to verify.\n* `sig` (`ECDSASignature`): A signature to verify the message.\n* `pub` (`ECPoint`): A public key to verify the signature against.\n\n```\npub = Secp256k1::Util.restore_public_key \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\nmsg = \"Hello, World!\"\nsig = Secp256k1::ECDSASignature.new BigInt.new(\"63945398370917837063250848409972066837033757647691696776146735867163610886143\"), BigInt.new(\"20291418537568297129028959685291490143232574306335372594306006819765182564103\")\n\nSecp256k1::Signature.verify msg, sig, pub\n# => true\n```","summary":"Verifies a signature of a message against a public key.
","abstract":false,"args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"args_string":"(msg : String, sig : ECDSASignature, pub : ECPoint)","args_html":"(msg : String, sig : ECDSASignature, pub : ECPoint)","location":{"filename":"src/signature.cr","line_number":75,"url":null},"def":{"name":"verify","args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hash = BigInt.new(Hash.sha256(msg), 16)\nverify_hash(hash, sig, pub)\n"}},{"html_id":"verify_hash(hash:BigInt,sig:ECDSASignature,pub:ECPoint)-class-method","name":"verify_hash","doc":"Verifies a signature of a message hash against a public key.\n\nSame as `verify`, just using the hashed message directly.\n\nParameters:\n* `hash` (`BigInt`): A SHA-256 hash of the message to verify.\n* `sig` (`ECDSASignature`): A signature to verify the message.\n* `pub` (`ECPoint`): A public key to verify the signature against.\n\nReturns _true_ if signature is valid. See `verify` for usage example.","summary":"Verifies a signature of a message hash against a public key.
","abstract":false,"args":[{"name":"hash","doc":null,"default_value":"","external_name":"hash","restriction":"BigInt"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"args_string":"(hash : BigInt, sig : ECDSASignature, pub : ECPoint)","args_html":"(hash : BigInt, sig : ECDSASignature, pub : ECPoint)","location":{"filename":"src/signature.cr","line_number":91,"url":null},"def":{"name":"verify_hash","args":[{"name":"hash","doc":null,"default_value":"","external_name":"hash","restriction":"BigInt"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"s_inv = Core.ec_mod_inv(sig.s, EC_ORDER_N)\np0 = Core.ec_mul(EC_BASE_G, (hash * s_inv) % EC_ORDER_N)\np1 = Core.ec_mul(pub, (sig.r * s_inv) % EC_ORDER_N)\np = Core.ec_add(p0, p1)\nsig.r === p.x\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Util","path":"Secp256k1/Util.html","kind":"module","full_name":"Secp256k1::Util","name":"Util","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/util.cr","line_number":23,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A collection of utilities for `Secp256k1` key management, e.g., private key\ngeneration, public key conversions, key formatting, or hex padding.","summary":"A collection of utilities for Secp256k1
key management, e.g., private key generation, public key conversions, key formatting, or hex padding.
","class_methods":[{"html_id":"decode_compressed_public_key(pub:String,prime=EC_PRIME_P)-class-method","name":"decode_compressed_public_key","doc":"Decodes a public key as `ECPoint` from a compressed public key string.\n\nIf unsure, `restore_public_key` should be used.\n\nParameters:\n* `pub` (`String`): the public key in prefixed compressed format.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\n```\nSecp256k1::Util.decode_compressed_public_key \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\n```\n\nReturns an `ECPoint` containing the public key.\n\nRaises if compressed public key is malformed or comes with invalid prefix.","summary":"Decodes a public key as ECPoint
from a compressed public key string.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(pub : String, prime = EC_PRIME_P)","args_html":"(pub : String, prime = EC_PRIME_P)","location":{"filename":"src/util.cr","line_number":163,"url":null},"def":{"name":"decode_compressed_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if pub.size === 66\n prefix = pub[0, 2]\n if (prefix === \"02\") || (prefix === \"03\")\n x = BigInt.new(pub[2, 64], 16)\n a = (x ** 3) % prime\n a = (a + 7) % prime\n e = ((prime + 1) // 4) % prime\n y = BigInt.new\n LibGMP.mpz_powm_sec(y, a, e, prime)\n parity = prefix.to_i - 2\n if (y % 2) != parity\n y = (-y) % prime\n end\n ECPoint.new(x, y)\n else\n raise(\"invalid prefix for compressed public key: #{prefix}\")\n end\nelse\n raise(\"malformed compressed public key (invalid key size: #{pub.size})\")\nend"}},{"html_id":"new_private_key-class-method","name":"new_private_key","doc":"A helper function to generate 32 pseudo-random bytes within the elliptic\ncurve field size of `EC_ORDER_N`.\n\n```\nSecp256k1::Util.new_private_key\n# => \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n```","summary":"A helper function to generate 32 pseudo-random bytes within the elliptic curve field size of EC_ORDER_N
.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/util.cr","line_number":66,"url":null},"def":{"name":"new_private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"key = -999\nwhile !key > 0\n key = Random::Secure.hex(32)\n key = BigInt.new(key, 16)\nend\nkey % EC_ORDER_N\n"}},{"html_id":"public_key_compressed_prefix(p:ECPoint)-class-method","name":"public_key_compressed_prefix","doc":"Exports the compressed public key from an `ECPoint` with either the\nprefix `\"02\"` or `\"03\"`.\n\nThe prefix can be later used to recover the `y` coordinate of the public key,\nsee `decode_compressed_public_key`. `Bitcoin` uses this format\nto generate shorter addresses as compared to using uncompressed keys.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be compressed.\n\n```\nSecp256k1::Util.public_key_compressed_prefix my_public_key\n# => \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\n```","summary":"Exports the compressed public key from an ECPoint
with either the prefix \"02\"
or \"03\"
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","args_html":"(p : ECPoint)","location":{"filename":"src/util.cr","line_number":109,"url":null},"def":{"name":"public_key_compressed_prefix","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"prefix = (p.y % 2) === 1 ? \"03\" : \"02\"\n\"#{prefix}#{public_key_compressed(p)}\"\n"}},{"html_id":"public_key_from_private(priv:BigInt)-class-method","name":"public_key_from_private","doc":"Gets a public key from a private key.\n\nThis is basically a wrapper function to perform an elliptic curve\nmultiplication with the generator point `g` and a provided private key `priv`.\n\nParameters:\n* `priv` (`BigInt`): the private key to be used.\n\n```\nSecp256k1::Util.public_key_from_private BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\n```\n\nReturns an `ECPoint` containing the public key.","summary":"Gets a public key from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(priv : BigInt)","args_html":"(priv : BigInt)","location":{"filename":"src/util.cr","line_number":258,"url":null},"def":{"name":"public_key_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Core.ec_mul(EC_BASE_G, priv)"}},{"html_id":"public_key_uncompressed(p:ECPoint)-class-method","name":"public_key_uncompressed","doc":"Exports the uncompressed public key from an `ECPoint` without prefix.\n\n`Ethereum` uses this format to generate addresses. For prefixed\nuncompressed public keys, see `public_key_uncompressed_prefix`.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be uncompressed.\n\n```\nSecp256k1::Util.public_key_uncompressed my_public_key\n# => \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```","summary":"Exports the uncompressed public key from an ECPoint
without prefix.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","args_html":"(p : ECPoint)","location":{"filename":"src/util.cr","line_number":126,"url":null},"def":{"name":"public_key_uncompressed","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x = to_padded_hex_32(p.x)\ny = to_padded_hex_32(p.y)\n\"#{x}#{y}\"\n"}},{"html_id":"public_key_uncompressed_prefix(p:ECPoint)-class-method","name":"public_key_uncompressed_prefix","doc":"Exports the uncompressed public key from an `ECPoint` with prefix `\"04\"`.\n\n`Bitcoin` uses this format to generate uncompressed addresses.\nFor unprefixed public keys, see `public_key_uncompressed`.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be uncompressed.\n\n```\nSecp256k1::Util.public_key_uncompressed_prefix my_public_key\n# => \"04d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```","summary":"Exports the uncompressed public key from an ECPoint
with prefix \"04\"
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","args_html":"(p : ECPoint)","location":{"filename":"src/util.cr","line_number":144,"url":null},"def":{"name":"public_key_uncompressed_prefix","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"04#{public_key_uncompressed(p)}\""}},{"html_id":"restore_public_key(pub:String,prime=EC_PRIME_P)-class-method","name":"restore_public_key","doc":"Detects public key type and tries to restore the `ECPoint` from it.\n\nParameters:\n* `pub` (`String`): the public key in any format.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\n```\nSecp256k1::Util.restore_public_key \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```\n\nReturns an `ECPoint` containing the public key.\n\nRaises if public key format is unknown.","summary":"Detects public key type and tries to restore the ECPoint
from it.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(pub : String, prime = EC_PRIME_P)","args_html":"(pub : String, prime = EC_PRIME_P)","location":{"filename":"src/util.cr","line_number":234,"url":null},"def":{"name":"restore_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case pub.size\nwhen 130, 128\n decode_uncompressed_public_key(pub)\nwhen 66\n decode_compressed_public_key(pub, prime)\nelse\n raise(\"unknown public key format (invalid key size: #{pub.size})\")\nend"}},{"html_id":"to_padded_hex_01(i:Int32)-class-method","name":"to_padded_hex_01","doc":"A generic utility to encode single hex bytes as strings, e.g., \"07\"\n\nParameters:\n* `i` (`Int32`): the integer to be formatted as padded hex byte.\n\n```\nSecp256k1::Util.to_padded_hex_01 7\n# => \"07\"\n```","summary":"A generic utility to encode single hex bytes as strings, e.g., \"07\"
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","args_html":"(i : Int32)","location":{"filename":"src/util.cr","line_number":33,"url":null},"def":{"name":"to_padded_hex_01","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hex = i.to_s(16)\nwhile hex.size < 2\n hex = '0' + hex\nend\nhex\n"}},{"html_id":"to_padded_hex_32(i:BigInt)-class-method","name":"to_padded_hex_32","doc":"An utility tool to ensure hex keys are always 32 bytes;\nit pads the number with leading zeros if it's shorter.\n\nParameters:\n* `i` (`BigInt`): the integer to be formatted as padded hex byte string.\n\n```\nSecp256k1::Util.to_padded_hex_32 BigInt.new 7\n# => \"0000000000000000000000000000000000000000000000000000000000000007\"\n```","summary":"An utility tool to ensure hex keys are always 32 bytes; it pads the number with leading zeros if it's shorter.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"BigInt"}],"args_string":"(i : BigInt)","args_html":"(i : BigInt)","location":{"filename":"src/util.cr","line_number":51,"url":null},"def":{"name":"to_padded_hex_32","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hex = i.to_s(16)\nwhile hex.size < 64\n hex = '0' + hex\nend\nhex\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}}
\ No newline at end of file
diff --git a/docs/js/doc.js b/docs/js/doc.js
index 8796e74..c0ebb1e 100644
--- a/docs/js/doc.js
+++ b/docs/js/doc.js
@@ -1,11 +1,11 @@
-window.CrystalDoc = (window.CrystalDoc || {});
+window.CrystalDocs = (window.CrystalDocs || {});
-CrystalDoc.base_path = (CrystalDoc.base_path || "");
+CrystalDocs.base_path = (CrystalDocs.base_path || "");
-CrystalDoc.searchIndex = (CrystalDoc.searchIndex || false);
-CrystalDoc.MAX_RESULTS_DISPLAY = 140;
+CrystalDocs.searchIndex = (CrystalDocs.searchIndex || false);
+CrystalDocs.MAX_RESULTS_DISPLAY = 140;
-CrystalDoc.runQuery = function(query) {
+CrystalDocs.runQuery = function(query) {
function searchType(type, query, results) {
var matches = [];
var matchedFields = [];
@@ -33,7 +33,7 @@ CrystalDoc.runQuery = function(query) {
}
if (matches.length > 0) {
results.push({
- id: type.id,
+ id: type.html_id,
result_type: "type",
kind: type.kind,
name: name,
@@ -96,14 +96,14 @@ CrystalDoc.runQuery = function(query) {
matches = matches.concat(typeMatches);
}
results.push({
- id: method.id,
+ id: method.html_id,
type: type.full_name,
result_type: kind,
name: method.name,
full_name: type.full_name + "#" + method.name,
args_string: method.args_string,
summary: method.summary,
- href: type.path + "#" + method.id,
+ href: type.path + "#" + method.html_id,
matched_fields: matchedFields,
matched_terms: matches
});
@@ -130,14 +130,14 @@ CrystalDoc.runQuery = function(query) {
matches = matches.concat(typeMatches);
}
results.push({
- id: constant.id,
+ id: constant.html_id,
type: type.full_name,
result_type: "constant",
name: constant.name,
full_name: type.full_name + "#" + constant.name,
value: constant.value,
summary: constant.summary,
- href: type.path + "#" + constant.id,
+ href: type.path + "#" + constant.html_id,
matched_fields: matchedFields,
matched_terms: matches
});
@@ -145,11 +145,11 @@ CrystalDoc.runQuery = function(query) {
}
var results = [];
- searchType(CrystalDoc.searchIndex.program, query, results);
+ searchType(CrystalDocs.searchIndex.program, query, results);
return results;
};
-CrystalDoc.rankResults = function(results, query) {
+CrystalDocs.rankResults = function(results, query) {
function uniqueArray(ar) {
var j = {};
@@ -171,42 +171,42 @@ CrystalDoc.rankResults = function(results, query) {
var bOnlyDocs = bHasDocs && b.matched_fields.length == 1;
if (a.result_type == "type" && b.result_type != "type" && !aOnlyDocs) {
- if(CrystalDoc.DEBUG) { console.log("a is type b not"); }
+ if(CrystalDocs.DEBUG) { console.log("a is type b not"); }
return -1;
} else if (b.result_type == "type" && a.result_type != "type" && !bOnlyDocs) {
- if(CrystalDoc.DEBUG) { console.log("b is type, a not"); }
+ if(CrystalDocs.DEBUG) { console.log("b is type, a not"); }
return 1;
}
if (a.matched_fields.includes("name")) {
if (b.matched_fields.includes("name")) {
- var a_name = (CrystalDoc.prefixForType(a.result_type) || "") + ((a.result_type == "type") ? a.full_name : a.name);
- var b_name = (CrystalDoc.prefixForType(b.result_type) || "") + ((b.result_type == "type") ? b.full_name : b.name);
+ var a_name = (CrystalDocs.prefixForType(a.result_type) || "") + ((a.result_type == "type") ? a.full_name : a.name);
+ var b_name = (CrystalDocs.prefixForType(b.result_type) || "") + ((b.result_type == "type") ? b.full_name : b.name);
a_name = a_name.toLowerCase();
b_name = b_name.toLowerCase();
for(var i = 0; i < query.normalizedTerms.length; i++) {
var term = query.terms[i].replace(/^::?|::?$/, "");
var a_orig_index = a_name.indexOf(term);
var b_orig_index = b_name.indexOf(term);
- if(CrystalDoc.DEBUG) { console.log("term: " + term + " a: " + a_name + " b: " + b_name); }
- if(CrystalDoc.DEBUG) { console.log(a_orig_index, b_orig_index, a_orig_index - b_orig_index); }
+ if(CrystalDocs.DEBUG) { console.log("term: " + term + " a: " + a_name + " b: " + b_name); }
+ if(CrystalDocs.DEBUG) { console.log(a_orig_index, b_orig_index, a_orig_index - b_orig_index); }
if (a_orig_index >= 0) {
if (b_orig_index >= 0) {
- if(CrystalDoc.DEBUG) { console.log("both have exact match", a_orig_index > b_orig_index ? -1 : 1); }
+ if(CrystalDocs.DEBUG) { console.log("both have exact match", a_orig_index > b_orig_index ? -1 : 1); }
if(a_orig_index != b_orig_index) {
- if(CrystalDoc.DEBUG) { console.log("both have exact match at different positions", a_orig_index > b_orig_index ? 1 : -1); }
+ if(CrystalDocs.DEBUG) { console.log("both have exact match at different positions", a_orig_index > b_orig_index ? 1 : -1); }
return a_orig_index > b_orig_index ? 1 : -1;
}
} else {
- if(CrystalDoc.DEBUG) { console.log("a has exact match, b not"); }
+ if(CrystalDocs.DEBUG) { console.log("a has exact match, b not"); }
return -1;
}
} else if (b_orig_index >= 0) {
- if(CrystalDoc.DEBUG) { console.log("b has exact match, a not"); }
+ if(CrystalDocs.DEBUG) { console.log("b has exact match, a not"); }
return 1;
}
}
} else {
- if(CrystalDoc.DEBUG) { console.log("a has match in name, b not"); }
+ if(CrystalDocs.DEBUG) { console.log("a has match in name, b not"); }
return -1;
}
} else if (
@@ -217,19 +217,19 @@ CrystalDoc.rankResults = function(results, query) {
}
if (matchedTermsDiff != 0 || (aHasDocs != bHasDocs)) {
- if(CrystalDoc.DEBUG) { console.log("matchedTermsDiff: " + matchedTermsDiff, aHasDocs, bHasDocs); }
+ if(CrystalDocs.DEBUG) { console.log("matchedTermsDiff: " + matchedTermsDiff, aHasDocs, bHasDocs); }
return matchedTermsDiff;
}
var matchedFieldsDiff = b.matched_fields.length - a.matched_fields.length;
if (matchedFieldsDiff != 0) {
- if(CrystalDoc.DEBUG) { console.log("matched to different number of fields: " + matchedFieldsDiff); }
+ if(CrystalDocs.DEBUG) { console.log("matched to different number of fields: " + matchedFieldsDiff); }
return matchedFieldsDiff > 0 ? 1 : -1;
}
var nameCompare = a.name.localeCompare(b.name);
if(nameCompare != 0){
- if(CrystalDoc.DEBUG) { console.log("nameCompare resulted in: " + a.name + "<=>" + b.name + ": " + nameCompare); }
+ if(CrystalDocs.DEBUG) { console.log("nameCompare resulted in: " + a.name + "<=>" + b.name + ": " + nameCompare); }
return nameCompare > 0 ? 1 : -1;
}
@@ -238,7 +238,7 @@ CrystalDoc.rankResults = function(results, query) {
var term = query.terms[i];
var aIndex = a.args_string.indexOf(term);
var bIndex = b.args_string.indexOf(term);
- if(CrystalDoc.DEBUG) { console.log("index of " + term + " in args_string: " + aIndex + " - " + bIndex); }
+ if(CrystalDocs.DEBUG) { console.log("index of " + term + " in args_string: " + aIndex + " - " + bIndex); }
if(aIndex >= 0){
if(bIndex >= 0){
if(aIndex != bIndex){
@@ -267,7 +267,7 @@ CrystalDoc.rankResults = function(results, query) {
return results;
};
-CrystalDoc.prefixForType = function(type) {
+CrystalDocs.prefixForType = function(type) {
switch (type) {
case "instance_method":
return "#";
@@ -282,14 +282,14 @@ CrystalDoc.prefixForType = function(type) {
}
};
-CrystalDoc.displaySearchResults = function(results, query) {
+CrystalDocs.displaySearchResults = function(results, query) {
function sanitize(html){
return html.replace(/<(?!\/?code)[^>]+>/g, "");
}
// limit results
- if (results.length > CrystalDoc.MAX_RESULTS_DISPLAY) {
- results = results.slice(0, CrystalDoc.MAX_RESULTS_DISPLAY);
+ if (results.length > CrystalDocs.MAX_RESULTS_DISPLAY) {
+ results = results.slice(0, CrystalDocs.MAX_RESULTS_DISPLAY);
}
var $frag = document.createDocumentFragment();
@@ -297,12 +297,12 @@ CrystalDoc.displaySearchResults = function(results, query) {
$resultsElem.innerHTML = "";
results.forEach(function(result, i) {
- var url = CrystalDoc.base_path + result.href;
+ var url = CrystalDocs.base_path + result.href;
var type = false;
var title = query.highlight(result.result_type == "type" ? result.full_name : result.name);
- var prefix = CrystalDoc.prefixForType(result.result_type);
+ var prefix = CrystalDocs.prefixForType(result.result_type);
if (prefix) {
title = "" + prefix + "" + title;
}
@@ -351,10 +351,10 @@ CrystalDoc.displaySearchResults = function(results, query) {
$resultsElem.appendChild($frag);
- CrystalDoc.toggleResultsList(true);
+ CrystalDocs.toggleResultsList(true);
};
-CrystalDoc.toggleResultsList = function(visible) {
+CrystalDocs.toggleResultsList = function(visible) {
if (visible) {
document.querySelector(".types-list").classList.add("hidden");
document.querySelector(".search-results").classList.remove("hidden");
@@ -364,20 +364,20 @@ CrystalDoc.toggleResultsList = function(visible) {
}
};
-CrystalDoc.Query = function(string) {
+CrystalDocs.Query = function(string) {
this.original = string;
this.terms = string.split(/\s+/).filter(function(word) {
- return CrystalDoc.Query.stripModifiers(word).length > 0;
+ return CrystalDocs.Query.stripModifiers(word).length > 0;
});
- var normalized = this.terms.map(CrystalDoc.Query.normalizeTerm);
+ var normalized = this.terms.map(CrystalDocs.Query.normalizeTerm);
this.normalizedTerms = normalized;
function runMatcher(field, matcher) {
if (!field) {
return false;
}
- var normalizedValue = CrystalDoc.Query.normalizeTerm(field);
+ var normalizedValue = CrystalDocs.Query.normalizeTerm(field);
var matches = [];
normalized.forEach(function(term) {
@@ -435,7 +435,7 @@ CrystalDoc.Query = function(string) {
methodName = term.substring(i+1);
if(termType != "") {
- if(CrystalDoc.Query.normalizeTerm(type.full_name).indexOf(termType) < 0){
+ if(CrystalDocs.Query.normalizeTerm(type.full_name).indexOf(termType) < 0){
return false;
}
}
@@ -461,10 +461,10 @@ CrystalDoc.Query = function(string) {
);
};
};
-CrystalDoc.Query.normalizeTerm = function(term) {
+CrystalDocs.Query.normalizeTerm = function(term) {
return term.toLowerCase();
};
-CrystalDoc.Query.stripModifiers = function(term) {
+CrystalDocs.Query.stripModifiers = function(term) {
switch (term[0]) {
case "#":
case ".":
@@ -476,34 +476,34 @@ CrystalDoc.Query.stripModifiers = function(term) {
}
}
-CrystalDoc.search = function(string) {
- if(!CrystalDoc.searchIndex) {
- console.log("CrystalDoc search index not initialized, delaying search");
+CrystalDocs.search = function(string) {
+ if(!CrystalDocs.searchIndex) {
+ console.log("CrystalDocs search index not initialized, delaying search");
- document.addEventListener("CrystalDoc:loaded", function listener(){
- document.removeEventListener("CrystalDoc:loaded", listener);
- CrystalDoc.search(string);
+ document.addEventListener("CrystalDocs:loaded", function listener(){
+ document.removeEventListener("CrystalDocs:loaded", listener);
+ CrystalDocs.search(string);
});
return;
}
- document.dispatchEvent(new Event("CrystalDoc:searchStarted"));
+ document.dispatchEvent(new Event("CrystalDocs:searchStarted"));
- var query = new CrystalDoc.Query(string);
- var results = CrystalDoc.runQuery(query);
- results = CrystalDoc.rankResults(results, query);
- CrystalDoc.displaySearchResults(results, query);
+ var query = new CrystalDocs.Query(string);
+ var results = CrystalDocs.runQuery(query);
+ results = CrystalDocs.rankResults(results, query);
+ CrystalDocs.displaySearchResults(results, query);
- document.dispatchEvent(new Event("CrystalDoc:searchPerformed"));
+ document.dispatchEvent(new Event("CrystalDocs:searchPerformed"));
};
-CrystalDoc.initializeIndex = function(data) {
- CrystalDoc.searchIndex = data;
+CrystalDocs.initializeIndex = function(data) {
+ CrystalDocs.searchIndex = data;
- document.dispatchEvent(new Event("CrystalDoc:loaded"));
+ document.dispatchEvent(new Event("CrystalDocs:loaded"));
};
-CrystalDoc.loadIndex = function() {
+CrystalDocs.loadIndex = function() {
function loadJSON(file, callback) {
var xobj = new XMLHttpRequest();
xobj.overrideMimeType("application/json");
@@ -523,7 +523,7 @@ CrystalDoc.loadIndex = function() {
}
function parseJSON(json) {
- CrystalDoc.initializeIndex(JSON.parse(json));
+ CrystalDocs.initializeIndex(JSON.parse(json));
}
for(var i = 0; i < document.scripts.length; i++){
@@ -546,7 +546,7 @@ CrystalDoc.loadIndex = function() {
// Callback for jsonp
function crystal_doc_search_index_callback(data) {
- CrystalDoc.initializeIndex(data);
+ CrystalDocs.initializeIndex(data);
}
Navigator = function(sidebar, searchInput, list, leaveSearchScope){
@@ -555,23 +555,23 @@ Navigator = function(sidebar, searchInput, list, leaveSearchScope){
var performingSearch = false;
- document.addEventListener('CrystalDoc:searchStarted', function(){
+ document.addEventListener('CrystalDocs:searchStarted', function(){
performingSearch = true;
});
- document.addEventListener('CrystalDoc:searchDebounceStarted', function(){
+ document.addEventListener('CrystalDocs:searchDebounceStarted', function(){
performingSearch = true;
});
- document.addEventListener('CrystalDoc:searchPerformed', function(){
+ document.addEventListener('CrystalDocs:searchPerformed', function(){
performingSearch = false;
});
- document.addEventListener('CrystalDoc:searchDebounceStopped', function(event){
+ document.addEventListener('CrystalDocs:searchDebounceStopped', function(event){
performingSearch = false;
});
function delayWhileSearching(callback) {
if(performingSearch){
- document.addEventListener('CrystalDoc:searchPerformed', function listener(){
- document.removeEventListener('CrystalDoc:searchPerformed', listener);
+ document.addEventListener('CrystalDocs:searchPerformed', function listener(){
+ document.removeEventListener('CrystalDocs:searchPerformed', listener);
// add some delay to let search results display kick in
setTimeout(callback, 100);
@@ -783,6 +783,74 @@ Navigator = function(sidebar, searchInput, list, leaveSearchScope){
this.move();
};
+CrystalDocs.initializeVersions = function () {
+ function loadJSON(file, callback) {
+ var xobj = new XMLHttpRequest();
+ xobj.overrideMimeType("application/json");
+ xobj.open("GET", file, true);
+ xobj.onreadystatechange = function() {
+ if (xobj.readyState == 4 && xobj.status == "200") {
+ callback(xobj.responseText);
+ }
+ };
+ xobj.send(null);
+ }
+
+ function parseJSON(json) {
+ CrystalDocs.loadConfig(JSON.parse(json));
+ }
+
+ $elem = document.querySelector("html > head > meta[name=\"crystal_docs.json_config_url\"]")
+ if ($elem == undefined) {
+ return
+ }
+ jsonURL = $elem.getAttribute("content")
+ if (jsonURL && jsonURL != "") {
+ loadJSON(jsonURL, parseJSON);
+ }
+}
+
+CrystalDocs.loadConfig = function (config) {
+ var projectVersions = config["versions"]
+ var currentVersion = document.querySelector("html > head > meta[name=\"crystal_docs.project_version\"]").getAttribute("content")
+
+ var currentVersionInList = projectVersions.find(function (element) {
+ return element.name == currentVersion
+ })
+
+ if (!currentVersionInList) {
+ projectVersions.unshift({ name: currentVersion, url: '#' })
+ }
+
+ $version = document.querySelector(".project-summary > .project-version")
+ $version.innerHTML = ""
+
+ $select = document.createElement("select")
+ $select.classList.add("project-versions-nav")
+ $select.addEventListener("change", function () {
+ window.location.href = this.value
+ })
+ projectVersions.forEach(function (version) {
+ $item = document.createElement("option")
+ $item.setAttribute("value", version.url)
+ $item.append(document.createTextNode(version.name))
+
+ if (version.name == currentVersion) {
+ $item.setAttribute("selected", true)
+ $item.setAttribute("disabled", true)
+ }
+ $select.append($item)
+ });
+ $form = document.createElement("form")
+ $form.setAttribute("autocomplete", "off")
+ $form.append($select)
+ $version.append($form)
+}
+
+document.addEventListener("DOMContentLoaded", function () {
+ CrystalDocs.initializeVersions()
+})
+
var UsageModal = function(title, content) {
var $body = document.body;
var self = this;
@@ -840,7 +908,7 @@ document.addEventListener('DOMContentLoaded', function() {
};
}
- var repositoryName = document.querySelector('#repository-name').getAttribute('content');
+ var repositoryName = document.querySelector('[name=repository-name]').getAttribute('content');
var typesList = document.querySelector('.types-list');
var searchInput = document.querySelector('.search-input');
var parents = document.querySelectorAll('.types-list li.parent');
@@ -883,28 +951,28 @@ document.addEventListener('DOMContentLoaded', function() {
}
var leaveSearchScope = function(){
- CrystalDoc.toggleResultsList(false);
+ CrystalDocs.toggleResultsList(false);
window.focus();
}
var navigator = new Navigator(document.querySelector('.types-list'), searchInput, document.querySelector(".search-results"), leaveSearchScope);
- CrystalDoc.loadIndex();
+ CrystalDocs.loadIndex();
var searchTimeout;
var lastSearchText = false;
var performSearch = function() {
- document.dispatchEvent(new Event("CrystalDoc:searchDebounceStarted"));
+ document.dispatchEvent(new Event("CrystalDocs:searchDebounceStarted"));
clearTimeout(searchTimeout);
searchTimeout = setTimeout(function() {
var text = searchInput.value;
if(text == "") {
- CrystalDoc.toggleResultsList(false);
+ CrystalDocs.toggleResultsList(false);
}else if(text == lastSearchText){
- document.dispatchEvent(new Event("CrystalDoc:searchDebounceStopped"));
+ document.dispatchEvent(new Event("CrystalDocs:searchDebounceStopped"));
}else{
- CrystalDoc.search(text);
+ CrystalDocs.search(text);
navigator.highlightFirst();
searchInput.focus();
}
@@ -920,7 +988,7 @@ document.addEventListener('DOMContentLoaded', function() {
var searchQuery = location.hash.substring(3);
history.pushState({searchQuery: searchQuery}, "Search for " + searchQuery, location.href.replace(/#q=.*/, ""));
searchInput.value = searchQuery;
- document.addEventListener('CrystalDoc:loaded', performSearch);
+ document.addEventListener('CrystalDocs:loaded', performSearch);
}
if (searchInput.value.length == 0) {
@@ -1006,11 +1074,10 @@ document.addEventListener('DOMContentLoaded', function() {
var scrollToEntryFromLocationHash = function() {
var hash = window.location.hash;
if (hash) {
- var targetAnchor = unescape(hash.substr(1));
- var targetEl = document.querySelectorAll('.entry-detail[id="' + targetAnchor + '"]');
-
- if (targetEl && targetEl.length > 0) {
- targetEl[0].offsetParent.scrollTop = targetEl[0].offsetTop;
+ var targetAnchor = decodeURI(hash.substr(1));
+ var targetEl = document.getElementById(targetAnchor)
+ if (targetEl) {
+ targetEl.offsetParent.scrollTop = targetEl.offsetTop;
}
}
};
diff --git a/docs/search-index.js b/docs/search-index.js
index 0794a7e..3654feb 100644
--- a/docs/search-index.js
+++ b/docs/search-index.js
@@ -1 +1 @@
-crystal_doc_search_index_callback({"repository_name":"github.com/q9f/secp256k1.cr","body":"# secp256k1.cr\n\n[![Build Status](https://img.shields.io/github/workflow/status/q9f/secp256k1.cr/Nightly)](https://github.com/q9f/secp256k1.cr/actions)\n[![Documentation](https://img.shields.io/badge/docs-html-black)](https://q9f.github.io/secp256k1.cr/)\n[![Release](https://img.shields.io/github/v/release/q9f/secp256k1.cr?include_prereleases&color=black)](https://github.com/q9f/secp256k1.cr/releases/latest)\n[![Language](https://img.shields.io/github/languages/top/q9f/secp256k1.cr?color=black)](https://github.com/q9f/secp256k1.cr/search?l=crystal)\n[![License](https://img.shields.io/github/license/q9f/secp256k1.cr.svg?color=black)](LICENSE)\n\na native library implementing `secp256k1` purely for the crystal language. `secp256k1` is the elliptic curve used in the public-private-key cryptography required by bitcoin and ethereum.\n\nthis library allows for key generation of:\n* private keys (from secure random within the elliptic curve field size)\n* mini private keys (short 30-char base-56 keys)\n* wallet import format (checksummed base-58 private keys)\n* public keys, prefixed, compressed (from private)\n* public keys, unprefixed and prefixed, uncompressed (from private)\n* conversion between the different public key formats\n\nthis library allows for address generation of:\n* bitcoin address, compressed and uncompressed (from private or public key)\n* any other bitcoin-based address by passing a `version` byte\n* ethereum address, checksummed and unchecksummed (from private or public key)\n* any other ethereum-based address\n\nfurthermore, this library allows for:\n* signing `(r, s)` and verification of arbitrary messages and message-hashes (with key pairs)\n* managing `enode` addresses as per `devp2p` specification for ethereum nodes\n\n# installation\n\nadd the `secp256k1` library to your `shard.yml`\n\n```yaml\ndependencies:\n secp256k1:\n github: q9f/secp256k1.cr\n version: \"~> 0.3\"\n```\n\n# usage\n\n_tl;dr,_ check out [`crystal run ./try.cr`](./try.cr)!\n\n\n```crystal\n# import secp256k1\nrequire \"secp256k1\"\n```\n\nthis library exposes the following modules (in logical order):\n\n* `Secp256k1`: necessary constants and data structures, including:\n - `Secp256k1::Keypair`: for managing private-public key-pairs\n - `Secp256k1::ECPoint`: for handling of secp256k1 elliptic curve points (public keys)\n - `Secp256k1::ECDSASignature`: for secp256k1 ecdsa signatures\n* `Secp256k1::Core`: the entire core mathematics behind the elliptic curve cryptography\n* `Secp256k1::Util`: all tools for the handling of private-public key-pairs\n* `Secp256k1::Hash`: implementation of various hashing algorithms for convenience\n* `Secp256k1::Signature`: allows for signing messages and verifying signatures\n* `Secp256k1::Bitcoin`: for the generation of bitcoin addresses, including:\n - `Secp256k1::Bitcoin::Account`: for bitcoin account management\n* `Secp256k1::Ethereum`: for the generation of ethereum addresses, including\n - `Secp256k1::Ethereum::Account`: for ethereum account management\n - `Secp256k1::Ethereum::Enode`: for devp2p enode address management\n\nbasic usage:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# gets the private key\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n\n# gets the compressed public key with prefix\ncompressed = Secp256k1::Util.public_key_compressed_prefix key.public_key\n# => \"03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b\"\n```\n\ngenerate a compressed bitcoin mainnet address:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# generates a compressed bitcoin account from the keypair\nbtc = Secp256k1::Bitcoin::Account.new key, \"00\", true\n# => #\n\n# gets the wallet-import format (checksummed private key)\nbtc.wif\n# => \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n\n# gets the compressed bitcoin addresss\nbtc.address\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```\n\ngenerate a checksummed ethereum address:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# generates an ethereum account from the keypair\neth = Secp256k1::Ethereum::Account.new key\n# => #\n\n# gets the private key\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n\n# gets the ethereum addresss\neth.address\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```\n\n# documentation\n\nthe full library documentation can be found here: [q9f.github.io/secp256k1.cr](https://q9f.github.io/secp256k1.cr/)\n\ngenerate a local copy with:\n\n```\ncrystal docs\n```\n\n# testing\n\nthe library is entirely specified through tests in `./spec`; run:\n\n```bash\ncrystal spec --verbose\n```\n\n# understand\n\nprivate keys are just scalars and public keys are points with `x` and `y` coordinates.\n\nbitcoin public keys can be uncompressed `#{p}#{x}#{y}` or compressed `#{p}#{x}`. both come with a prefix `p` which is useless for uncompressed keys but necessary for compressed keys to recover the `y` coordinate on the `secp256k1` elliptic curve.\n\nethereum public keys are uncompressed `#{x}#{y}` without any prefix. the last 20 bytes slice of the `y` coordinate is actually used as address without any checksum. a checksum was later added in eip-55 using a `keccak256` hash and indicating character capitalization.\n\nneither bitcoin nor ethereum allow for recovering public keys from an address unless there exists a transaction with a valid signature on the blockchain.\n\n# known issues\n\n_note: this library should not be used in production without proper auditing._\n\n* this library is not constant time and might be subject to side-channel attacks. ([#4](https://github.com/q9f/secp256k1.cr/issues/4))\n* this library does unnecessary big-integer math and should someday rather correctly implement the secp256k1 prime field ([#5](https://github.com/q9f/secp256k1.cr/issues/5))\n\nfound another issue? report it: [github.com/q9f/secp256k1.cr/issues](https://github.com/q9f/secp256k1.cr/issues)\n\n# contribute\n\ncreate a pull request, and make sure tests and linter passes.\n\nthis pure crystal implementation is based on the python implementation [wobine/blackboard101](https://github.com/wobine/blackboard101) which is also used as reference to write tests against. it's a complete rewrite of the abandoned [packetzero/bitcoinutils](https://github.com/packetzero/bitcoinutils) for educational purposes.\n\nhonerable mention for the [bitcoin wiki](https://en.bitcoin.it/wiki/Main_Page) and the [ethereum stackexchange](https://ethereum.stackexchange.com/) for providing so many in-depth resources that supported this project in reimplementing everything.\n\nlicense: apache license v2.0\n\ncontributors: [**@q9f**](https://github.com/q9f/)\n","program":{"html_id":"github.com/q9f/secp256k1.cr/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"github.com/q9f/secp256k1.cr","program":true,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","path":"Secp256k1.html","kind":"module","full_name":"Secp256k1","name":"Secp256k1","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"bitcoin.cr","line_number":16,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr"},{"filename":"constants.cr","line_number":22,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/constants.cr"},{"filename":"structs.cr","line_number":20,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr"},{"filename":"version.cr","line_number":20,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/version.cr"},{"filename":"secp256k1.cr","line_number":30,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/secp256k1.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"EC_BASE_G","name":"EC_BASE_G","value":"ECPoint.new(EC_BASE_G_X, EC_BASE_G_Y)","doc":"The commonly used base point `G` coordinates `x`, `y`;\nany other point that satisfies `y^2 = x^3 + 7` would also do.","summary":"The commonly used base point G
coordinates x
, y
; any other point that satisfies y^2 = x^3 + 7
would also do.
"},{"id":"EC_BASE_G_COMPRESSED","name":"EC_BASE_G_COMPRESSED","value":"BigInt.new((Secp256k1::Util.public_key_compressed_prefix(EC_BASE_G)), 16)","doc":"The base point `G` in compressed form.","summary":"The base point G
in compressed form.
"},{"id":"EC_BASE_G_UNCOMPRESSED","name":"EC_BASE_G_UNCOMPRESSED","value":"BigInt.new((Secp256k1::Util.public_key_uncompressed_prefix(EC_BASE_G)), 16)","doc":"The base point `G` in uncompressed form.","summary":"The base point G
in uncompressed form.
"},{"id":"EC_BASE_G_X","name":"EC_BASE_G_X","value":"BigInt.new(\"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\", 16)","doc":"The `x`-coordinate of the base point `G`.","summary":"The x
-coordinate of the base point G
.
"},{"id":"EC_BASE_G_Y","name":"EC_BASE_G_Y","value":"BigInt.new(\"483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8\", 16)","doc":"The `y`-coordinate of the base point `G`.","summary":"The y
-coordinate of the base point G
.
"},{"id":"EC_COFACTOR_H","name":"EC_COFACTOR_H","value":"BigInt.new(\"01\", 16)","doc":"The elliptic curve cofactor `h`.","summary":"The elliptic curve cofactor h
.
"},{"id":"EC_FACTOR_A","name":"EC_FACTOR_A","value":"BigInt.new(\"00\", 16)","doc":"The curve `E`: `y^2 = x^3 + ax + b` over `F_p` is defined by `a = 0`.\nAs the `a` constant is zero, the `ax` term in the curve equation is always zero,\nhence the curve equation becomes `y^2 = x^3 + b`.","summary":"The curve E
: y^2 = x^3 + ax + b
over F_p
is defined by a = 0
.
"},{"id":"EC_FACTOR_B","name":"EC_FACTOR_B","value":"BigInt.new(\"07\", 16)","doc":"The curve `E`: `y^2 = x^3 + b` over `F_p` is defined by `b = 7`,\nhence the curve equation becomes `y^2 = x^3 + 7`.","summary":"The curve E
: y^2 = x^3 + b
over F_p
is defined by b = 7
, hence the curve equation becomes y^2 = x^3 + 7
.
"},{"id":"EC_ORDER_N","name":"EC_ORDER_N","value":"BigInt.new(\"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141\", 16)","doc":"The order `n` of `G` defines the finite size of the Secp256k1 field `E`.","summary":"The order n
of G
defines the finite size of the Secp256k1 field E
.
"},{"id":"EC_PRIME_P","name":"EC_PRIME_P","value":"BigInt.new(\"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f\", 16)","doc":"The elliptic curve domain parameters over `F_p` associated with a Koblitz curve\nSecp256k1 are specified by the sextuple `T = (p, a, b, G, n, h)` where the finite\nfield `F_p` is defined by the prime `p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1`.","summary":"The elliptic curve domain parameters over F_p
associated with a Koblitz curve Secp256k1 are specified by the sextuple T = (p, a, b, G, n, h)
where the finite field F_p
is defined by the prime p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
.
"},{"id":"VERSION","name":"VERSION","value":"\"0.3.0\"","doc":"The `VERSION` of the `Secp256k1` module.","summary":"The VERSION
of the Secp256k1
module.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Implements 256-bit `Secp256k1` Koblitz elliptic curve.\nRef: [secg.org/sec2-v2.pdf](https://www.secg.org/sec2-v2.pdf)\n\n`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p.\nRef: [en.bitcoin.it/wiki/Secp256k1](https://en.bitcoin.it/wiki/Secp256k1)","summary":"Implements 256-bit Secp256k1
Koblitz elliptic curve.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Bitcoin","path":"Secp256k1/Bitcoin.html","kind":"module","full_name":"Secp256k1::Bitcoin","name":"Bitcoin","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"bitcoin.cr","line_number":16,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements the `Bitcoin` address space for the `Secp256k1` library.","summary":"Implements the Bitcoin
address space for the Secp256k1
library.
","class_methods":[{"id":"address_from_private(priv:BigInt,version="00",compressed=true)-class-method","html_id":"address_from_private(priv:BigInt,version="00",compressed=true)-class-method","name":"address_from_private","doc":"Generates a `Bitcoin` address from a private key.\n\nParameters:\n* `priv` (`BigInt`): the private key as number.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n* `compressed` (`Bool`): indicator if address should be compressed or not, default: `true` (compressed).\n\n```\nSecp256k1::Bitcoin.address_from_private BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```","summary":"Generates a Bitcoin
address from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"args_string":"(priv : BigInt, version = "00", compressed = true)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L563","def":{"name":"address_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"p = Secp256k1::Util.public_key_from_private(priv)\naddress_from_public_point(p, version, compressed)\n"}},{"id":"address_from_public_key(pub:String,version="00")-class-method","html_id":"address_from_public_key(pub:String,version="00")-class-method","name":"address_from_public_key","doc":"Generates a `Bitcoin` address for any public key, compressed or uncompressed.\n\nParameters:\n* `pub` (`String`): the public key, compressed or uncompressed.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n\n```\nSecp256k1::Bitcoin.address_from_public_key \"03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b\"\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```\n\nNote, compressed public keys generate compressed addresses, whereas\nuncompressed keys generate uncompressed addresses.\n\nRaises if the public key is malformed.","summary":"Generates a Bitcoin
address for any public key, compressed or uncompressed.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""}],"args_string":"(pub : String, version = "00")","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L467","def":{"name":"address_from_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (pub.size === 130) || (pub.size === 66)\n sha2 = Hash.sha256(Hash.hex_to_bin(pub))\n ripe = Hash.ripemd160(Hash.hex_to_bin(sha2))\n ripe_versioned = \"#{version}#{ripe}\"\n hashed = Hash.sha256(Hash.hex_to_bin(ripe_versioned))\n hashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\n binary = \"#{ripe_versioned}#{hashed_twice[0, 8]}\"\n Hash.base58_encode(binary)\nelse\n raise(\"malformed public key (invalid key size: #{pub.size})\")\nend"}},{"id":"address_from_public_point(p:Secp256k1::ECPoint,version="00",compressed=true)-class-method","html_id":"address_from_public_point(p:Secp256k1::ECPoint,version="00",compressed=true)-class-method","name":"address_from_public_point","doc":"Generates a `Bitcoin` address from an public key as `ECPoint`.\n\nParameters:\n* `p` (`ECPoint`): the public key as point with `x` and `y` coordinates.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n* `compressed` (`Bool`): indicator if address should be compressed or not, default: `true` (compressed).\n\nSee `address_from_public_key` and `ECPoint` for usage instructions.","summary":"Generates a Bitcoin
address from an public key as ECPoint
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"args_string":"(p : Secp256k1::ECPoint, version = "00", compressed = true)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L506","def":{"name":"address_from_public_point","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = Secp256k1::Util.public_key_uncompressed_prefix(p)\nif compressed\n pub = Secp256k1::Util.public_key_compressed_prefix(p)\nend\naddress_from_public_key(pub, version)\n"}},{"id":"address_from_wif(wif:String)-class-method","html_id":"address_from_wif(wif:String)-class-method","name":"address_from_wif","doc":"Gets a `Bitcoin` address from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.address_from_wif \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets a Bitcoin
address from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L526","def":{"name":"address_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if wif_is_valid?(wif)\n vers = version_byte_from_wif(wif)\n vers = vers.to_i(16)\n vers = vers - 128\n vers = Secp256k1::Util.to_padded_hex_01(vers)\n priv = private_key_from_wif(wif)\n priv = BigInt.new(priv, 16)\n comp = is_wif_compressed?(wif)\n address_from_private(priv, vers, comp)\nelse\n raise(\"invalid wallet import format (invalid wif: #{wif})\")\nend"}},{"id":"is_wif_compressed?(wif:String)-class-method","html_id":"is_wif_compressed?(wif:String)-class-method","name":"is_wif_compressed?","doc":"Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.is_wif_compressed? \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => false\n```\n\nReturns _true_ if the key is compressed.\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L392","def":{"name":"is_wif_compressed?","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"versioned = Hash.base58_decode(wif)\nif (versioned.size === 74) || (versioned.size === 76)\n versioned.size === 76\nelse\n raise(\"invalid wallet import format (invalid wif size: #{versioned.size})\")\nend\n"}},{"id":"mini_is_valid?(m:String)-class-method","html_id":"mini_is_valid?(m:String)-class-method","name":"mini_is_valid?","doc":"Validates wether a mini-private key has a correct checksum and formatting.\n\nParameters:\n* `m` (`String`): the mini-private key.\n\n```\nSecp256k1::Bitcoin.mini_is_valid? \"S7qq5k98DAvee6mtQgpg4xAJatT9mR\"\n# => true\n```\n\nReturns _true_ if the key contains a valid checksum and is formatted correctly.","summary":"Validates wether a mini-private key has a correct checksum and formatting.
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"args_string":"(m : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L253","def":{"name":"mini_is_valid?","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"valid = m.size === 30\nvalid = valid && (m[0, 1] === \"S\")\nchecksum = Hash.sha256_string(\"#{m}?\")\nvalid && (checksum[0, 2] === \"00\")\n"}},{"id":"new_mini_private_key-class-method","html_id":"new_mini_private_key-class-method","name":"new_mini_private_key","doc":"Generates a new mini-private key (30 characters length, Base-56 encoded).\n\n```\nSecp256k1::Bitcoin.new_mini_private_key\n# => S7qq5k98DAvee6mtQgpg4xAJatT9mR\n```","summary":"Generates a new mini-private key (30 characters length, Base-56 encoded).
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L193","def":{"name":"new_mini_private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"valid = false\nkey = String.new\nwhile !valid\n i = 1\n key = \"S\"\n while i < 30\n i = i + 1\n r = Random.rand(56)\n key = key + (Hash.base56_char(r))\n end\n valid = mini_is_valid?(key)\n if valid\n priv = private_key_from_mini(key)\n valid = valid && priv > 0\n valid = valid && (priv === (priv % Secp256k1::EC_ORDER_N))\n end\nend\nkey\n"}},{"id":"private_key_from_mini(m:String)-class-method","html_id":"private_key_from_mini(m:String)-class-method","name":"private_key_from_mini","doc":"Gets a private key from a mini-private key if the key is valid.\n\nParameters:\n* `m` (`String`): the mini-private key.\n\n```\nSecp256k1::Bitcoin.private_key_from_mini \"S7qq5k98DAvee6mtQgpg4xAJatT9mR\"\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```\n\nRaises if the key is invalid.","summary":"Gets a private key from a mini-private key if the key is valid.
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"args_string":"(m : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L232","def":{"name":"private_key_from_mini","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if mini_is_valid?(m)\n private_key = Hash.sha256_string(m)\n BigInt.new(private_key, 16)\nelse\n raise(\"mini private key is not valid (invalid checksum for: #{m})\")\nend"}},{"id":"private_key_from_wif(wif:String)-class-method","html_id":"private_key_from_wif(wif:String)-class-method","name":"private_key_from_wif","doc":"Gets a private key from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.private_key_from_wif \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets a private key from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L341","def":{"name":"private_key_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"checksum_key = Hash.base58_decode(wif)\nif (checksum_key.size == 74) || (checksum_key.size == 76)\n private_key = BigInt.new(checksum_key[2, 64], 16)\n Secp256k1::Util.to_padded_hex_32(private_key)\nelse\n raise(\"invalid wallet import format (invalid wif size: #{checksum_key.size})\")\nend\n"}},{"id":"version_byte_from_wif(wif:String)-class-method","html_id":"version_byte_from_wif(wif:String)-class-method","name":"version_byte_from_wif","doc":"Gets the version byte from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.version_byte_from_wif \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => \"80\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets the version byte from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L366","def":{"name":"version_byte_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"versioned = Hash.base58_decode(wif)\nif (versioned.size === 74) || (versioned.size === 76)\n versioned[0, 2]\nelse\n raise(\"invalid wallet import format (invalid wif size: #{versioned.size})\")\nend\n"}},{"id":"wif_from_private(k:BigInt,version="80",compr="")-class-method","html_id":"wif_from_private(k:BigInt,version="80",compr="")-class-method","name":"wif_from_private","doc":"Gets a Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key.\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin).\n* `compr` (`String`): the compression byte, default: `\"\"` (uncompressed).\n\n```\nSecp256k1::Bitcoin.wif_from_private BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n```\n\nNote, the compression byte `compr` is either empty `\"\"` for uncompressed keys or\n`\"01\"` for compressed keys. See also `wif_from_private_compressed` and `wif_from_private_uncompressed`.","summary":"Gets a Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""},{"name":"compr","doc":null,"default_value":"\"\"","external_name":"compr","restriction":""}],"args_string":"(k : BigInt, version = "80", compr = "")","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L277","def":{"name":"wif_from_private","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""},{"name":"compr","doc":null,"default_value":"\"\"","external_name":"compr","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"priv = Secp256k1::Util.to_padded_hex_32(k)\nversioned = \"#{version}#{priv}#{compr}\"\nhashed = Hash.sha256(Hash.hex_to_bin(versioned))\nhashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\nbinary = \"#{versioned}#{hashed_twice[0, 8]}\"\nHash.base58_encode(binary)\n"}},{"id":"wif_from_private_compressed(k:BigInt,version="80")-class-method","html_id":"wif_from_private_compressed(k:BigInt,version="80")-class-method","name":"wif_from_private_compressed","doc":"Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin)\n\n```\nSecp256k1::Bitcoin.wif_from_private_compressed BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n```","summary":"Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"args_string":"(k : BigInt, version = "80")","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L310","def":{"name":"wif_from_private_compressed","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"wif_from_private(k, version, \"01\")"}},{"id":"wif_from_private_uncompressed(k:BigInt,version="80")-class-method","html_id":"wif_from_private_uncompressed(k:BigInt,version="80")-class-method","name":"wif_from_private_uncompressed","doc":"Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin)\n\n```\nSecp256k1::Bitcoin.wif_from_private_uncompressed BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n```","summary":"Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"args_string":"(k : BigInt, version = "80")","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L325","def":{"name":"wif_from_private_uncompressed","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"wif_from_private(k, version, \"\")"}},{"id":"wif_is_valid?(wif:String)-class-method","html_id":"wif_is_valid?(wif:String)-class-method","name":"wif_is_valid?","doc":"Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.wif_is_valid? \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => true\n```\n\nReturns _true_ if the key contains a valid checksum and is formatted correctly.","summary":"Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L416","def":{"name":"wif_is_valid?","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"checksum_key = Hash.base58_decode(wif)\nvalid = (checksum_key.size === 74) || (checksum_key.size === 76)\nif valid\n private_key = private_key_from_wif(wif)\n valid = (valid && (private_key != \"-999\")) && (private_key.size === 64)\n versioned = checksum_key[0, 66]\n wif_checksum = checksum_key[66, 8]\n if checksum_key.size === 76\n versioned = checksum_key[0, 68]\n wif_checksum = checksum_key[68, 8]\n end\n hashed = Hash.sha256(Hash.hex_to_bin(versioned))\n hashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\n pk_checksum = hashed_twice[0, 8]\n valid = valid && (wif_checksum === pk_checksum)\nend\nvalid\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Bitcoin/Account","path":"Secp256k1/Bitcoin/Account.html","kind":"class","full_name":"Secp256k1::Bitcoin::Account","name":"Account","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"bitcoin.cr","line_number":34,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Bitcoin","kind":"module","full_name":"Secp256k1::Bitcoin","name":"Bitcoin"},"doc":"Implements a `Bitcoin` account containing a `Keypair`, a Wallet-Import Format,\nand an address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n* `compressed` (`Bool`): an indicator whether a compressed format should be used.\n* `address` (`String`): the public `Bitcoin` address.\n* `wif` (`String`): the private Wallet-Import Format (WIF).\n\n```\nbtc = Secp256k1::Bitcoin::Account.new\nbtc.wif\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\nbtc.address\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```","summary":"Implements a Bitcoin
account containing a Keypair
, a Wallet-Import Format, and an address.
","class_methods":[],"constructors":[{"id":"new(key_pair,version,compressed)-class-method","html_id":"new(key_pair,version,compressed)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair` allowing for a custom\nnetwork version byte and compression.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n* `compressed` (`Bool`): an indicator whether a compressed format should be used.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key, \"00\", true\n# => #\n```\n\nRaises if the version byte is out of range.","summary":"Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom network version byte and compression.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":""}],"args_string":"(key_pair, version, compressed)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L125","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, version, compressed)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new(key_pair,version)-class-method","html_id":"new(key_pair,version)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair` allowing for a custom\nnetwork version byte.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key, \"1e\"\n# => #\n```\n\nNote, this always generates an uncompressed account for the specified network.\n\nRaises if the version byte is out of range.","summary":"Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom network version byte.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""}],"args_string":"(key_pair, version)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L97","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, version)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new(key_pair)-class-method","html_id":"new(key_pair)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair`.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key\n# => #\n```\n\nNote, this always generates an uncompressed mainnet Bitcoin account.","summary":"Generates a Bitcoin::Account
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L74","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Generates a new `Bitcoin::Account` from a fresh random `Keypair`.\n\n```\nbtc = Secp256k1::Bitcoin::Account.new\n# => #\n```\n\nNote, this always generates an uncompressed mainnet Bitcoin account.","summary":"Generates a new Bitcoin::Account
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L54","def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"address:String-instance-method","html_id":"address:String-instance-method","name":"address","doc":"The public `Bitcoin` address.","summary":"The public Bitcoin
address.
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L42","def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@address"}},{"id":"address=(address:String)-instance-method","html_id":"address=(address:String)-instance-method","name":"address=","doc":"The public `Bitcoin` address.","summary":"The public Bitcoin
address.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"args_string":"(address : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L42","def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"id":"compressed:Bool-instance-method","html_id":"compressed:Bool-instance-method","name":"compressed","doc":"An indicator whether a compressed format should be used.","summary":"An indicator whether a compressed format should be used.
","abstract":false,"args":[],"args_string":" : Bool","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L40","def":{"name":"compressed","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@compressed"}},{"id":"compressed=(compressed:Bool)-instance-method","html_id":"compressed=(compressed:Bool)-instance-method","name":"compressed=","doc":"An indicator whether a compressed format should be used.","summary":"An indicator whether a compressed format should be used.
","abstract":false,"args":[{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":"Bool"}],"args_string":"(compressed : Bool)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L40","def":{"name":"compressed=","args":[{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@compressed = compressed"}},{"id":"get_secret-instance-method","html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\nbtc.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L172","def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"id":"is_compressed?:Bool-instance-method","html_id":"is_compressed?:Bool-instance-method","name":"is_compressed?","doc":"Tells if the `Bitcoin::Account` is compressed.\n\n```\nbtc.is_compressed?\n# => false\n```\n\nReturns _true_ if the compressed format is used.","summary":"Tells if the Bitcoin::Account
is compressed.
","abstract":false,"args":[],"args_string":" : Bool","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L151","def":{"name":"is_compressed?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@compressed"}},{"id":"key_pair:Keypair-instance-method","html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L36","def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"id":"key_pair=(key_pair:Keypair)-instance-method","html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L36","def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"id":"to_s:String-instance-method","html_id":"to_s:String-instance-method","name":"to_s","doc":"Gets the account formatted as `Bitcoin` address.\n\n```\nbtc.to_s\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```","summary":"Gets the account formatted as Bitcoin
address.
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L182","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address"}},{"id":"version:String-instance-method","html_id":"version:String-instance-method","name":"version","doc":"The version byte determining the used network encoding.","summary":"The version byte determining the used network encoding.
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L38","def":{"name":"version","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@version"}},{"id":"version=(version:String)-instance-method","html_id":"version=(version:String)-instance-method","name":"version=","doc":"The version byte determining the used network encoding.","summary":"The version byte determining the used network encoding.
","abstract":false,"args":[{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":"String"}],"args_string":"(version : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L38","def":{"name":"version=","args":[{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@version = version"}},{"id":"version_wif-instance-method","html_id":"version_wif-instance-method","name":"version_wif","doc":"Computes the version byte for the private Wallet-Import Format which is\noffset by `+ 0x80` from the public address `version` byte.\n\n```\nbtc.version_wif\n# => \"80\"\n```","summary":"Computes the version byte for the private Wallet-Import Format which is offset by + 0x80
from the public address #version
byte.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L162","def":{"name":"version_wif","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_01((@version.to_i(16)) + 128)"}},{"id":"wif:String-instance-method","html_id":"wif:String-instance-method","name":"wif","doc":"The private Wallet-Import Format (WIF).","summary":"The private Wallet-Import Format (WIF).
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L44","def":{"name":"wif","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@wif"}},{"id":"wif=(wif:String)-instance-method","html_id":"wif=(wif:String)-instance-method","name":"wif=","doc":"The private Wallet-Import Format (WIF).","summary":"The private Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/bitcoin.cr#L44","def":{"name":"wif=","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@wif = wif"}}],"macros":[],"types":[]}]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Core","path":"Secp256k1/Core.html","kind":"module","full_name":"Secp256k1::Core","name":"Core","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"core.cr","line_number":20,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements 256-bit `Secp256k1` Koblitz elliptic curve.\nRef: [secg.org/sec2-v2.pdf](https://www.secg.org/sec2-v2.pdf)\n\n`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p.\nRef: [en.bitcoin.it/wiki/Secp256k1](https://en.bitcoin.it/wiki/Secp256k1)","summary":"Implements 256-bit Secp256k1
Koblitz elliptic curve.
","class_methods":[{"id":"ec_add(p:ECPoint,q:ECPoint,prime=EC_PRIME_P)-class-method","html_id":"ec_add(p:ECPoint,q:ECPoint,prime=EC_PRIME_P)-class-method","name":"ec_add","doc":"The elliptic curve jive addition of point `p(x, y)` and `q(x, y)`.\n\nWe basically _draw_ a line between `p` and `q` which will intersect the\ncurve in the point `r` which will be mirrored over the `x`-axis.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the jive addition.\n* `q` (`ECPoint`): the point `q(x, y)` to be used in the jive addition.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns another `ECPoint` as result.","summary":"The elliptic curve jive addition of point p(x, y)
and q(x, y)
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"q","doc":null,"default_value":"","external_name":"q","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(p : ECPoint, q : ECPoint, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr#L60","def":{"name":"ec_add","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"q","doc":null,"default_value":"","external_name":"q","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x_delta = q.x - p.x\nx_inv = ec_mod_inv(x_delta)\ny_delta = q.y - p.y\nm = (y_delta * x_inv) % prime\nx = (((m * m) - p.x) - q.x) % prime\ny = ((m * (p.x - x)) - p.y) % prime\nx = BigInt.new(x)\ny = BigInt.new(y)\nECPoint.new(x, y)\n"}},{"id":"ec_double(p:ECPoint,prime=EC_PRIME_P)-class-method","html_id":"ec_double(p:ECPoint,prime=EC_PRIME_P)-class-method","name":"ec_double","doc":"The elliptic curve juke point doubling of `p(x, y)`.\n\nThis is a special case of addition where both points are the same.\nWe _draw_ a tangent line at `p` which will intersect the curve\nat point `r` which will be mirrored over the `x`-axis.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the juke doubling.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns another `ECPoint` as result.","summary":"The elliptic curve juke point doubling of p(x, y)
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(p : ECPoint, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr#L83","def":{"name":"ec_double","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"lam_numer = ((3 * p.x) * p.x) + EC_FACTOR_A\nlam_denom = 2 * p.y\nlam_inv = ec_mod_inv(lam_denom)\nlam = (lam_numer * lam_inv) % prime\nx = ((lam * lam) - (2 * p.x)) % prime\ny = ((lam * (p.x - x)) - p.y) % prime\nx = BigInt.new(x)\ny = BigInt.new(y)\nECPoint.new(x, y)\n"}},{"id":"ec_mod_inv(a:BigInt,prime=EC_PRIME_P)-class-method","html_id":"ec_mod_inv(a:BigInt,prime=EC_PRIME_P)-class-method","name":"ec_mod_inv","doc":"Computes the elliptic curve modular multiplicative inverse of `a`.\n\nParemeters:\n* `a` (`BigInt`): the integer that we want the modular inverse of.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns a `BigInt` value as result.","summary":"Computes the elliptic curve modular multiplicative inverse of a
.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"BigInt"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(a : BigInt, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr#L28","def":{"name":"ec_mod_inv","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"BigInt"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m_low = 1\nm_high = 0\nv_low = a % prime\nv_high = prime\nwhile v_low > 1\n v_ratio = v_high // v_low\n m_low_r = m_low * v_ratio\n v_low_r = v_low * v_ratio\n m = m_high - m_low_r\n v = v_high - v_low_r\n m_high = m_low\n v_high = v_low\n m_low = m\n v_low = v\nend\nm_low % prime\n"}},{"id":"ec_mul(p:ECPoint,s:BigInt)-class-method","html_id":"ec_mul(p:ECPoint,s:BigInt)-class-method","name":"ec_mul","doc":"The elliptic curve sequence multiplication of point `p(x, y)` and\na skalar `s`.\n\nWith `s` being a private key within the elliptic curve field size of `EC_ORDER_N`.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the sequencing.\n* `s` (`BigInt`): a skalar, in most cases a private key.\n\nReturns another `ECPoint` as result, in most cases a public key.","summary":"The elliptic curve sequence multiplication of point p(x, y)
and a skalar s
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(p : ECPoint, s : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/core.cr#L105","def":{"name":"ec_mul","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (s === 0) || s >= EC_ORDER_N\n raise(\"invalid private key: outside of ec field size.\")\nend\ns_bin = s.to_s(2)\nq = p\ns_bin.each_char_with_index do |char, index|\n if index === 0\n next\n end\n q = ec_double(q)\n if char === '1'\n q = ec_add(q, p)\n end\nend\nq\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/ECDSASignature","path":"Secp256k1/ECDSASignature.html","kind":"struct","full_name":"Secp256k1::ECDSASignature","name":"ECDSASignature","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"github.com/q9f/secp256k1.cr/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"structs.cr","line_number":127,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A basic ECDSA Signature containing a random point `r` and the\nsignature proof `s`.\n\nSee: `Signature` for signature generation.\n\nProperties:\n* `r` (`BigInt`): the `x` coordinate of a random point `R`.\n* `s` (`BigInt`): the signature proof of a message.\n\n```\nsig = ECDSASignature.new r.x, proof\n```","summary":"A basic ECDSA Signature containing a random point #r
and the signature proof #s
.
","class_methods":[],"constructors":[{"id":"new(r:BigInt,s:BigInt)-class-method","html_id":"new(r:BigInt,s:BigInt)-class-method","name":"new","doc":"A signature always requires the random point `r` and the signature proof `s`.\n\nParameters:\n* `r` (`BigInt`): the `x` coordinate of a random point `R`.\n* `s` (`BigInt`): the signature proof of a message.","summary":"A signature always requires the random point #r
and the signature proof #s
.
","abstract":false,"args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(r : BigInt, s : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L139","def":{"name":"new","args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(r, s)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"r:BigInt-instance-method","html_id":"r:BigInt-instance-method","name":"r","doc":"The `x` coordinate of a random point `R`.","summary":"The x
coordinate of a random point R
.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L129","def":{"name":"r","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@r"}},{"id":"r=(r:BigInt)-instance-method","html_id":"r=(r:BigInt)-instance-method","name":"r=","doc":"The `x` coordinate of a random point `R`.","summary":"The x
coordinate of a random point R
.
","abstract":false,"args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"}],"args_string":"(r : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L129","def":{"name":"r=","args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@r = r"}},{"id":"s:BigInt-instance-method","html_id":"s:BigInt-instance-method","name":"s","doc":"The signature proof of a message.","summary":"The signature proof of a message.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L132","def":{"name":"s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@s"}},{"id":"s=(s:BigInt)-instance-method","html_id":"s=(s:BigInt)-instance-method","name":"s=","doc":"The signature proof of a message.","summary":"The signature proof of a message.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(s : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L132","def":{"name":"s=","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@s = s"}}],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/ECPoint","path":"Secp256k1/ECPoint.html","kind":"struct","full_name":"Secp256k1::ECPoint","name":"ECPoint","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"github.com/q9f/secp256k1.cr/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"structs.cr","line_number":99,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A point in the two-dimensional space of an elliptic curve.\n\nProperties:\n* `x` (`BigInt`): the position on the x-axis.\n* `y` (`BigInt`): the position on the y-axis.\n\n```\np = ECPoint.new BigInt.new(0), BigInt.new(0)\np.x\n# => 0\np.y\n# => 0\n```","summary":"A point in the two-dimensional space of an elliptic curve.
","class_methods":[],"constructors":[{"id":"new(x:BigInt,y:BigInt)-class-method","html_id":"new(x:BigInt,y:BigInt)-class-method","name":"new","doc":"An ECPoint always requires two coordinates `x`, `y`.\n\nParameters:\n* `x` (`BigInt`): the position on the x-axis.\n* `y` (`BigInt`): the position on the y-axis.","summary":"An ECPoint always requires two coordinates #x
, #y
.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"args_string":"(x : BigInt, y : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L111","def":{"name":"new","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(x, y)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"x:BigInt-instance-method","html_id":"x:BigInt-instance-method","name":"x","doc":"The position on the x-axis.","summary":"The position on the x-axis.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L101","def":{"name":"x","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@x"}},{"id":"x=(x:BigInt)-instance-method","html_id":"x=(x:BigInt)-instance-method","name":"x=","doc":"The position on the x-axis.","summary":"The position on the x-axis.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"}],"args_string":"(x : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L101","def":{"name":"x=","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@x = x"}},{"id":"y:BigInt-instance-method","html_id":"y:BigInt-instance-method","name":"y","doc":"The position on the y-axis.","summary":"The position on the y-axis.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L104","def":{"name":"y","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@y"}},{"id":"y=(y:BigInt)-instance-method","html_id":"y=(y:BigInt)-instance-method","name":"y=","doc":"The position on the y-axis.","summary":"The position on the y-axis.
","abstract":false,"args":[{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"args_string":"(y : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L104","def":{"name":"y=","args":[{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@y = y"}}],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum","path":"Secp256k1/Ethereum.html","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"ethereum.cr","line_number":19,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements the `Ethereum` address space for the `Secp256k1` library.","summary":"Implements the Ethereum
address space for the Secp256k1
library.
","class_methods":[{"id":"address_checksum(adr:String)-class-method","html_id":"address_checksum(adr:String)-class-method","name":"address_checksum","doc":"Returns a checksummed `Ethereum` address as per EIP-55.\n\nReference: [eips.ethereum.org/EIPS/eip-55](https://eips.ethereum.org/EIPS/eip-55)\n\nParameters:\n* `adr` (`String`): an unchecked `Ethereum` address.\n\n```\nSecp256k1::Ethereum.address_checksum \"0x7598c0fbaeb021161ce2e598f45ddee90fe5c6f7\"\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nRaises if address is malformed.","summary":"Returns a checksummed Ethereum
address as per EIP-55.
","abstract":false,"args":[{"name":"adr","doc":null,"default_value":"","external_name":"adr","restriction":"String"}],"args_string":"(adr : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L210","def":{"name":"address_checksum","args":[{"name":"adr","doc":null,"default_value":"","external_name":"adr","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"adr = adr.downcase\nif adr.size === 42\n adr = adr[2, 40]\nend\nif adr.size === 40\n keccak = Hash.keccak256_string(adr)\n address = \"0x\"\n i = 0\n while i < adr.size\n k = keccak[i].to_i(16)\n if k >= 8\n address = address + \"#{adr[i]}\".upcase\n else\n address = address + \"#{adr[i]}\".downcase\n end\n i = i + 1\n end\n address\nelse\n raise(\"malformed ethereum address (invalid size: #{adr.size})\")\nend\n"}},{"id":"address_from_private(priv:BigInt)-class-method","html_id":"address_from_private(priv:BigInt)-class-method","name":"address_from_private","doc":"Generates a checksummed `Ethereum` address from a private key.\n\nParameters:\n* `priv` (`BigInt`): a private key as number.\n\n```\nSecp256k1::Ethereum.address_from_private BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nNote, that the returned `Ethereum` address is already checksummed.","summary":"Generates a checksummed Ethereum
address from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(priv : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L297","def":{"name":"address_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"p = Secp256k1::Util.public_key_from_private(priv)\naddress_from_public_point(p)\n"}},{"id":"address_from_public_key(pub:String)-class-method","html_id":"address_from_public_key(pub:String)-class-method","name":"address_from_public_key","doc":"Generates a checksummed `Ethereum` address for an uncompressed public key.\n\nParameters:\n* `pub` (`String`): an uncompressed public key string.\n\n```\nSecp256k1::Ethereum.address_from_public_key \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nNote, that the returned `Ethereum` address is already checksummed.\n\nRaises if the public key is malformed.","summary":"Generates a checksummed Ethereum
address for an uncompressed public key.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"}],"args_string":"(pub : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L256","def":{"name":"address_from_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if pub.size === 130\n pub = pub[2, 128]\nend\nif pub.size === 128\n keccak = Hash.keccak256(Hash.hex_to_bin(pub))\n address_checksum(keccak[24, 40])\nelse\n raise(\"malformed public key (invalid key size: #{pub.size})\")\nend\n"}},{"id":"address_from_public_point(p:Secp256k1::ECPoint)-class-method","html_id":"address_from_public_point(p:Secp256k1::ECPoint)-class-method","name":"address_from_public_point","doc":"Generates a checksummed `Ethereum` address from an public key as `ECPoint`.\n\nParameters:\n* `p` (`ECPoint`): a public key point with `x` and `y` coordinates.\n\nSee `address_from_public_key` and `ECPoint` for usage instructions.","summary":"Generates a checksummed Ethereum
address from an public key as ECPoint
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"}],"args_string":"(p : Secp256k1::ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L280","def":{"name":"address_from_public_point","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = Secp256k1::Util.public_key_uncompressed(p)\naddress_from_public_key(pub)\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum/Account","path":"Secp256k1/Ethereum/Account.html","kind":"class","full_name":"Secp256k1::Ethereum::Account","name":"Account","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"ethereum.cr","line_number":33,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum"},"doc":"Implements an `Ethereum` account containing a `Keypair` and an address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `address` (`String`): the public checksummed `Ethereum` address.\n\n```\neth = Secp256k1::Ethereum::Account.new\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\neth.address\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```","summary":"Implements an Ethereum
account containing a Keypair
and an address.
","class_methods":[],"constructors":[{"id":"new(key_pair)-class-method","html_id":"new(key_pair)-class-method","name":"new","doc":"Generates an `Ethereum::Account` from a provided `Keypair`.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\neth = Secp256k1::Ethereum::Account.new key\n# => #\n```","summary":"Generates an Ethereum::Account
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L57","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Generates a new `Ethereum::Account` from a fresh random `Keypair`.\n\n```\neth = Secp256k1::Ethereum::Account.new\n# => #\n```","summary":"Generates a new Ethereum::Account
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L45","def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"address:String-instance-method","html_id":"address:String-instance-method","name":"address","doc":"The public checksummed `Ethereum` address.","summary":"The public checksummed Ethereum
address.
","abstract":false,"args":[],"args_string":" : String","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L37","def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@address"}},{"id":"address=(address:String)-instance-method","html_id":"address=(address:String)-instance-method","name":"address=","doc":"The public checksummed `Ethereum` address.","summary":"The public checksummed Ethereum
address.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"args_string":"(address : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L37","def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"id":"get_secret-instance-method","html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L67","def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"id":"key_pair:Keypair-instance-method","html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L35","def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"id":"key_pair=(key_pair:Keypair)-instance-method","html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L35","def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":"Gets the account formatted as `Ethereum` address.\n\n```\neth.to_s\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```","summary":"Gets the account formatted as Ethereum
address.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L77","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Ethereum.address_checksum(@address)"}}],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum/Enode","path":"Secp256k1/Ethereum/Enode.html","kind":"class","full_name":"Secp256k1::Ethereum::Enode","name":"Enode","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"ethereum.cr","line_number":95,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Ethereum","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum"},"doc":"Implements an `Ethereum` devp2p enode containing a `Keypair` and an IP address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `address` (`Socket::IPAddress`): the public (or local) IP address with port.\n\n```\np2p = Secp256k1::Ethereum::Enode.new\np2p.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\np2p.to_s\n# => \"enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303\"\n```","summary":"Implements an Ethereum
devp2p enode containing a Keypair
and an IP address.
","class_methods":[],"constructors":[{"id":"new(key_pair,host,port)-class-method","html_id":"new(key_pair,host,port)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair` and a custom IP address with port.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key, \"192.168.13.37\", 31337\n# => #\n```","summary":"Generates an Ethereum::Enode
from a provided Keypair
and a custom IP address with port.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"host","doc":null,"default_value":"","external_name":"host","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"args_string":"(key_pair, host, port)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L147","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"host","doc":null,"default_value":"","external_name":"host","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, host, port)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new(key_pair,port)-class-method","html_id":"new(key_pair,port)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair` and a custom port.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key, 50000\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates an Ethereum::Enode
from a provided Keypair
and a custom port.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"args_string":"(key_pair, port)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L136","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, port)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new(key_pair)-class-method","html_id":"new(key_pair)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair`.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates an Ethereum::Enode
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L123","def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Generates a new `Ethereum::Enode` from a fresh random `Keypair`.\n\n```\np2p = Secp256k1::Ethereum::Enode.new\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates a new Ethereum::Enode
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L109","def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"address:Socket::IPAddress-instance-method","html_id":"address:Socket::IPAddress-instance-method","name":"address","doc":"The public (or local) IP address with port.","summary":"The public (or local) IP address with port.
","abstract":false,"args":[],"args_string":" : Socket::IPAddress","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L99","def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Socket::IPAddress","visibility":"Public","body":"@address"}},{"id":"address=(address:Socket::IPAddress)-instance-method","html_id":"address=(address:Socket::IPAddress)-instance-method","name":"address=","doc":"The public (or local) IP address with port.","summary":"The public (or local) IP address with port.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"Socket::IPAddress"}],"args_string":"(address : Socket::IPAddress)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L99","def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"Socket::IPAddress"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"id":"get_my_ip-instance-method","html_id":"get_my_ip-instance-method","name":"get_my_ip","doc":"Tries to find out the public IP address for the node.\n\nIt queries [ident.me](http://ident.me/) for a potential public IP and silently\nfalls back to \"127.0.0.1\" if it fails without raising. _Should be used with caution._\n\n```\np2p.get_my_ip\n# => \"84.160.86.205\"\n```","summary":"Tries to find out the public IP address for the node.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L160","def":{"name":"get_my_ip","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ip = nil\nbegin\n ip = (HTTP::Client.get(\"http://ident.me/\")).body.to_s\nrescue\n ip = \"127.0.0.1\"\nensure\n if ip.nil? || ip.size < 2\n ip = \"127.0.0.1\"\n end\nend\nip\n"}},{"id":"get_secret-instance-method","html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\np2p.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L182","def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"id":"key_pair:Keypair-instance-method","html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L97","def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"id":"key_pair=(key_pair:Keypair)-instance-method","html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L97","def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":"Gets the `Enode` formatted as devp2p enode address.\n\n```\np2p.to_s\n# => \"enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303\"\n```","summary":"Gets the Enode
formatted as devp2p enode address.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/ethereum.cr#L192","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"enode://#{@key_pair.to_s}@#{@address.to_s}\""}}],"macros":[],"types":[]}]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Hash","path":"Secp256k1/Hash.html","kind":"module","full_name":"Secp256k1::Hash","name":"Hash","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"hash.cr","line_number":20,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[{"id":"BASE_56","name":"BASE_56","value":"\"23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz\"","doc":"The Base-56 alphabet for `Bitcoin` mini-private keys is a Base-58 alphabet\nwithout `1` and `o` to additionally omit more similar-looking letters.","summary":"The Base-56 alphabet for Bitcoin
mini-private keys is a Base-58 alphabet without 1
and o
to additionally omit more similar-looking letters.
"},{"id":"BASE_58","name":"BASE_58","value":"\"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\"","doc":"The Base-58 alphabet for `Bitcoin` addresses is a Base-64 alphabet without\n`0`, `O`, `I`, and `l` to omit similar-looking letters.","summary":"The Base-58 alphabet for Bitcoin
addresses is a Base-64 alphabet without 0
, O
, I
, and l
to omit similar-looking letters.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"The `Secp256k1::Hash` module wraps various hashing functions for convenience\nand exposes them for general use.","summary":"The Secp256k1::Hash
module wraps various hashing functions for convenience and exposes them for general use.
","class_methods":[{"id":"base56_char(i:Int32)-class-method","html_id":"base56_char(i:Int32)-class-method","name":"base56_char","doc":"Gets a character from the Base-56 alphabet at position `i`.\n\nParameters:\n* `i` (`Int32`): the position in the Base-56 alphabet.\n\n```\nSecp256k1::Hash.base56_char 13\n# => 'F'\n```","summary":"Gets a character from the Base-56 alphabet at position i
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L211","def":{"name":"base56_char","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"i = i % 56\nBASE_56[i]\n"}},{"id":"base58_char(i:Int32)-class-method","html_id":"base58_char(i:Int32)-class-method","name":"base58_char","doc":"Gets a character from the Base-58 alphabet at position `i`.\n\nParameters:\n* `i` (`Int32`): the position in the Base-58 alphabet.\n\n```\nSecp256k1::Hash.base58_char 13\n# => 'E'\n```","summary":"Gets a character from the Base-58 alphabet at position i
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L225","def":{"name":"base58_char","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"i = i % 58\nBASE_58[i]\n"}},{"id":"base58_decode(s:String)-class-method","html_id":"base58_decode(s:String)-class-method","name":"base58_decode","doc":"Decodes a hexadecimal string from a Base-58 encoded string.\n\nParameters:\n* `s` (`String`): The Base-58 encoded string to be decoded.\n\n```\nSecp256k1::Hash.base58_decode \"1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt\"\n# => \"007d7935bde6c9341de87a4d64588783033e23472d7322c46b\"\n```","summary":"Decodes a hexadecimal string from a Base-58 encoded string.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L146","def":{"name":"base58_decode","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"index = 0\ndecimal = BigInt.new(0)\nwhile index < s.size\n b58_char = s[index]\n position = BASE_58.index(b58_char)\n if !position.nil?\n decimal = (decimal * 58) + position\n index = index + 1\n else\n raise(\"cannot decode, invalid base58 character: '#{s[index]}'\")\n end\nend\nhex = decimal.to_s(16)\nleading = 0\nwhile s[leading] === '1'\n leading = leading + 1\n hex = \"00#{hex}\"\nend\nhex\n"}},{"id":"base58_encode(h:String)-class-method","html_id":"base58_encode(h:String)-class-method","name":"base58_encode","doc":"Encodes a Base-58 string from a hexadecimal string.\n\nParameters:\n* `h` (`String`): The hexadecimal string to be encoded.\n\n```\nSecp256k1::Hash.base58_encode \"007d7935bde6c9341de87a4d64588783033e23472d7322c46b\"\n# => \"1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt\"\n```","summary":"Encodes a Base-58 string from a hexadecimal string.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L180","def":{"name":"base58_encode","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = BigInt.new(h, 16)\nadr = String.new\nwhile pub > 0\n pub, rem = pub.divmod(58)\n adr = adr + (base58_char(rem.to_i))\nend\ni, s = 0, 2\ncurrent_byte = h[i, s]\nwhile (current_byte.to_i(16)) === 0\n adr = \"#{adr}1\"\n i = i + s\n current_byte = h[i, s]\nend\nadr.reverse\n"}},{"id":"bin_to_hex(b:Bytes)-class-method","html_id":"bin_to_hex(b:Bytes)-class-method","name":"bin_to_hex","doc":"Helper function to convert byte arrays to hexadecimal strings.\n\nParameters:\n* `b` (`Bytes`): the byte array to be converted.\n\n```\nSecp256k1::Hash.bin_to_hex Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n=> \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n```","summary":"Helper function to convert byte arrays to hexadecimal strings.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L239","def":{"name":"bin_to_hex","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"b.hexstring"}},{"id":"hex_to_bin(h:String)-class-method","html_id":"hex_to_bin(h:String)-class-method","name":"hex_to_bin","doc":"Helper function to convert hexadecimal strings to byte arrays.\n\nParameters:\n* `h` (`String`): the hexadecimal string to be converted.\n\n```\nSecp256k1::Hash.hex_to_bin \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n=> Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n```","summary":"Helper function to convert hexadecimal strings to byte arrays.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L252","def":{"name":"hex_to_bin","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h.hexbytes"}},{"id":"keccak256(b:Bytes)-class-method","html_id":"keccak256(b:Bytes)-class-method","name":"keccak256","doc":"Operating a Keccak-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.keccak256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"fcb41efa0456ba9f27e573422d6b5898c61da6f2137d07e4dae618eddd72e003\"\n```","summary":"Operating a Keccak-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L66","def":{"name":"keccak256","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"keccak = Digest::Keccak3.new(256)\n(keccak.update(b)).hexdigest\n"}},{"id":"keccak256_string(h:String)-class-method","html_id":"keccak256_string(h:String)-class-method","name":"keccak256_string","doc":"Operating a Keccak-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.keccak256_string \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"99cfa79866ec88f87f8e25a98a4b9873f3f8ee82482a317a5494572b00f51cec\"\n```","summary":"Operating a Keccak-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L80","def":{"name":"keccak256_string","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"keccak = Digest::Keccak3.new(256)\n(keccak.update(h)).hexdigest\n"}},{"id":"ripemd160(b:Bytes)-class-method","html_id":"ripemd160(b:Bytes)-class-method","name":"ripemd160","doc":"Operating a RIPEMD-160 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.ripemd160 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"5f3455f9ac58e25be08c99a7090108751b4796b9\"\n```","summary":"Operating a RIPEMD-160 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L120","def":{"name":"ripemd160","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"RIPEMD160\")).update(b)).hexdigest"}},{"id":"ripemd160_string(h:String)-class-method","html_id":"ripemd160_string(h:String)-class-method","name":"ripemd160_string","doc":"Operating a RIPEMD-160 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.ripemd160_string \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"46dff6cd5666c8e67db26ac0dfaf685bf71fc5f6\"\n```","summary":"Operating a RIPEMD-160 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L133","def":{"name":"ripemd160_string","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"RIPEMD160\")).update(h)).hexdigest"}},{"id":"sha256(b:Bytes)-class-method","html_id":"sha256(b:Bytes)-class-method","name":"sha256","doc":"Operating a SHA2-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.sha256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"2739cc5f45c0e05236527e4e687dc54f0d5e88be64b9a90e5264a6721c0c71f2\"\n```","summary":"Operating a SHA2-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L94","def":{"name":"sha256","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"SHA256\")).update(b)).hexdigest"}},{"id":"sha256_string(h:String)-class-method","html_id":"sha256_string(h:String)-class-method","name":"sha256_string","doc":"Operating a SHA2-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.sha256_string \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"452a41c28c9981faebb402095a5d553de28dc212338057aed27081110dfb907a\"\n```","summary":"Operating a SHA2-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L107","def":{"name":"sha256_string","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"SHA256\")).update(h)).hexdigest"}},{"id":"sha3(b:Bytes)-class-method","html_id":"sha3(b:Bytes)-class-method","name":"sha3","doc":"Operating a SHA3-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.sha3 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"66bb65180108362a3e25ba8282f7b96bfe840ce34a2e5dbc421aa8a590cc5f2e\"\n```","summary":"Operating a SHA3-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L38","def":{"name":"sha3","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sha3 = Digest::SHA3.new(256)\n(sha3.update(b)).hexdigest\n"}},{"id":"sha3_string(h:String)-class-method","html_id":"sha3_string(h:String)-class-method","name":"sha3_string","doc":"Operating a SHA3-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.sha3_string \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"aedc012933679615eb93fb0063f53010e6f0034e92aaccf97dacc46e338037e9\"\n```","summary":"Operating a SHA3-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/hash.cr#L52","def":{"name":"sha3_string","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sha3 = Digest::SHA3.new(256)\n(sha3.update(h)).hexdigest\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Keypair","path":"Secp256k1/Keypair.html","kind":"class","full_name":"Secp256k1::Keypair","name":"Keypair","abstract":false,"superclass":{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"github.com/q9f/secp256k1.cr/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"github.com/q9f/secp256k1.cr/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"structs.cr","line_number":34,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements a `Secp256k1` key pair containing a private and a public key.\n\nProperties:\n* `private_key` (`BigInt`): the secret as known as the private key.\n* `public_key` (`ECPoint`): the point on the elliptic curve as known as the public key.\n\n```\nkey = Secp256k1::Keypair.new\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\nkey.to_s\n# => \"e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f\"\n```","summary":"Implements a Secp256k1
key pair containing a private and a public key.
","class_methods":[],"constructors":[{"id":"new(private_key)-class-method","html_id":"new(private_key)-class-method","name":"new","doc":"Generates a new keypair using a provided private key.\n\nParameters:\n* `private_key` (`BigInt`): the secret as known as the private key.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => #\n```","summary":"Generates a new keypair using a provided private key.
","abstract":false,"args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":""}],"args_string":"(private_key)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L61","def":{"name":"new","args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(private_key)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"id":"new-class-method","html_id":"new-class-method","name":"new","doc":"Generates a new keypair using a fresh random private key.\n\n```\nkey = Secp256k1::Keypair.new\n# => #\n```","summary":"Generates a new keypair using a fresh random private key.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L47","def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"id":"get_secret-instance-method","html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L71","def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@private_key)"}},{"id":"private_key:BigInt-instance-method","html_id":"private_key:BigInt-instance-method","name":"private_key","doc":"The secret as known as the private key.","summary":"The secret as known as the private key.
","abstract":false,"args":[],"args_string":" : BigInt","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L36","def":{"name":"private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@private_key"}},{"id":"private_key=(private_key:BigInt)-instance-method","html_id":"private_key=(private_key:BigInt)-instance-method","name":"private_key=","doc":"The secret as known as the private key.","summary":"The secret as known as the private key.
","abstract":false,"args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":"BigInt"}],"args_string":"(private_key : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L36","def":{"name":"private_key=","args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@private_key = private_key"}},{"id":"public_key:ECPoint-instance-method","html_id":"public_key:ECPoint-instance-method","name":"public_key","doc":"The point on the elliptic curve as known as the public key.","summary":"The point on the elliptic curve as known as the public key.
","abstract":false,"args":[],"args_string":" : ECPoint","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L39","def":{"name":"public_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ECPoint","visibility":"Public","body":"@public_key"}},{"id":"public_key=(public_key:ECPoint)-instance-method","html_id":"public_key=(public_key:ECPoint)-instance-method","name":"public_key=","doc":"The point on the elliptic curve as known as the public key.","summary":"The point on the elliptic curve as known as the public key.
","abstract":false,"args":[{"name":"public_key","doc":null,"default_value":"","external_name":"public_key","restriction":"ECPoint"}],"args_string":"(public_key : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L39","def":{"name":"public_key=","args":[{"name":"public_key","doc":null,"default_value":"","external_name":"public_key","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@public_key = public_key"}},{"id":"to_s-instance-method","html_id":"to_s-instance-method","name":"to_s","doc":"Gets the key formatted as uncompressed public key string.\n\n```\nkey.to_s\n# => \"e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f\"\n```","summary":"Gets the key formatted as uncompressed public key string.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/structs.cr#L81","def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.public_key_uncompressed(@public_key)"}}],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Signature","path":"Secp256k1/Signature.html","kind":"module","full_name":"Secp256k1::Signature","name":"Signature","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"signature.cr","line_number":18,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/signature.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements `ECDSASignature` generation and verification for `Secp256k1`\nelliptic curves.\nRef: [cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages](https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages)","summary":"Implements ECDSASignature
generation and verification for Secp256k1
elliptic curves.
","class_methods":[{"id":"sign(msg:String,priv:BigInt)-class-method","html_id":"sign(msg:String,priv:BigInt)-class-method","name":"sign","doc":"Signs a message and creates a signature proof using a private key.\n\nThe ECDSA signing algorithm (RFC-6979) takes as input a message `msg`\nand a private key `priv`. It produces as output a signature, which\nconsists of pair of integers `(r, s)`, where `r` is the `x`-coordinate\nof a random point on our curve and `s` is the signature proof.\n\nParameters:\n* `msg` (`String`): A message string to sign.\n* `priv` (`BigInt`): A private key to sign with.\n\n```\nsig = Secp256k1::Signature.sign \"Hello, World!\", BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\nsig.r\n# => \"63945398370917837063250848409972066837033757647691696776146735867163610886143\"\nsig.s\n# => \"20291418537568297129028959685291490143232574306335372594306006819765182564103\"\n```","summary":"Signs a message and creates a signature proof using a private key.
","abstract":false,"args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(msg : String, priv : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/signature.cr#L37","def":{"name":"sign","args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hash = BigInt.new(Hash.sha256_string(msg), 16)\nk = Util.new_private_key\nr = (Core.ec_mul(EC_BASE_G, k)).x % EC_ORDER_N\nk_inv = Core.ec_mod_inv(k, EC_ORDER_N)\ns = ((hash + (r * priv)) * k_inv) % EC_ORDER_N\nECDSASignature.new(r, s)\n"}},{"id":"verify(msg:String,sig:ECDSASignature,pub:ECPoint)-class-method","html_id":"verify(msg:String,sig:ECDSASignature,pub:ECPoint)-class-method","name":"verify","doc":"Verifies a signature of a message against a public key.\n\nThe algorithm to verify an ECDSA signature takes as input the signed message `msg`\nand the signature `(r, s)` produced from `sign` and the public key `pub`,\ncorresponding to the signer's private key. The result is boolean.\n\nParameters:\n* `msg` (`String`): A message string to verify.\n* `sig` (`ECDSASignature`): A signature to verify the message.\n* `pub` (`ECPoint`): A public key to verify the signature against.\n\n```\npub = Secp256k1::Util.restore_public_key \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\nmsg = \"Hello, World!\"\nsig = Secp256k1::ECDSASignature.new BigInt.new(\"63945398370917837063250848409972066837033757647691696776146735867163610886143\"), BigInt.new(\"20291418537568297129028959685291490143232574306335372594306006819765182564103\")\n\nSecp256k1::Signature.verify msg, sig, pub\n# => true\n```","summary":"Verifies a signature of a message against a public key.
","abstract":false,"args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"args_string":"(msg : String, sig : ECDSASignature, pub : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/signature.cr#L75","def":{"name":"verify","args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hash = BigInt.new(Hash.sha256_string(msg), 16)\nverify_hash(hash, sig, pub)\n"}},{"id":"verify_hash(hash:BigInt,sig:ECDSASignature,pub:ECPoint)-class-method","html_id":"verify_hash(hash:BigInt,sig:ECDSASignature,pub:ECPoint)-class-method","name":"verify_hash","doc":"Verifies a signature of a message hash against a public key.\n\nSame as `verify`, just using the hashed message directly.\n\nParameters:\n* `hash` (`BigInt`): A SHA-256 hash of the message to verify.\n* `sig` (`ECDSASignature`): A signature to verify the message.\n* `pub` (`ECPoint`): A public key to verify the signature against.\n\nReturns _true_ if signature is valid. See `verify` for usage example.","summary":"Verifies a signature of a message hash against a public key.
","abstract":false,"args":[{"name":"hash","doc":null,"default_value":"","external_name":"hash","restriction":"BigInt"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"args_string":"(hash : BigInt, sig : ECDSASignature, pub : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/signature.cr#L91","def":{"name":"verify_hash","args":[{"name":"hash","doc":null,"default_value":"","external_name":"hash","restriction":"BigInt"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"s_inv = Core.ec_mod_inv(sig.s, EC_ORDER_N)\np0 = Core.ec_mul(EC_BASE_G, (hash * s_inv) % EC_ORDER_N)\np1 = Core.ec_mul(pub, (sig.r * s_inv) % EC_ORDER_N)\np = Core.ec_add(p0, p1)\nsig.r === p.x\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1/Util","path":"Secp256k1/Util.html","kind":"module","full_name":"Secp256k1::Util","name":"Util","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"util.cr","line_number":23,"url":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr"}],"repository_name":"github.com/q9f/secp256k1.cr","program":false,"enum":false,"alias":false,"aliased":"","const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"github.com/q9f/secp256k1.cr/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A collection of utilities for `Secp256k1` key management, e.g., private key\ngeneration, public key conversions, key formatting, or hex padding.","summary":"A collection of utilities for Secp256k1
key management, e.g., private key generation, public key conversions, key formatting, or hex padding.
","class_methods":[{"id":"decode_compressed_public_key(pub:String,prime=EC_PRIME_P)-class-method","html_id":"decode_compressed_public_key(pub:String,prime=EC_PRIME_P)-class-method","name":"decode_compressed_public_key","doc":"Decodes a public key as `ECPoint` from a compressed public key string.\n\nIf unsure, `restore_public_key` should be used.\n\nParameters:\n* `pub` (`String`): the public key in prefixed compressed format.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\n```\nSecp256k1::Util.decode_compressed_public_key \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\n```\n\nReturns an `ECPoint` containing the public key.\n\nRaises if compressed public key is malformed or comes with invalid prefix.","summary":"Decodes a public key as ECPoint
from a compressed public key string.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(pub : String, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L163","def":{"name":"decode_compressed_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if pub.size === 66\n prefix = pub[0, 2]\n if (prefix === \"02\") || (prefix === \"03\")\n x = BigInt.new(pub[2, 64], 16)\n a = (x ** 3) % prime\n a = (a + 7) % prime\n e = ((prime + 1) // 4) % prime\n y = BigInt.new\n LibGMP.mpz_powm_sec(y, a, e, prime)\n parity = prefix.to_i - 2\n if (y % 2) != parity\n y = (-y) % prime\n end\n ECPoint.new(x, y)\n else\n raise(\"invalid prefix for compressed public key: #{prefix}\")\n end\nelse\n raise(\"malformed compressed public key (invalid key size: #{pub.size})\")\nend"}},{"id":"new_private_key-class-method","html_id":"new_private_key-class-method","name":"new_private_key","doc":"A helper function to generate 32 pseudo-random bytes within the elliptic\ncurve field size of `EC_ORDER_N`.\n\n```\nSecp256k1::Util.new_private_key\n# => \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n```","summary":"A helper function to generate 32 pseudo-random bytes within the elliptic curve field size of EC_ORDER_N
.
","abstract":false,"args":[],"args_string":"","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L66","def":{"name":"new_private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"key = -999\nwhile !key > 0\n key = Random::Secure.hex(32)\n key = BigInt.new(key, 16)\nend\nkey % EC_ORDER_N\n"}},{"id":"public_key_compressed_prefix(p:ECPoint)-class-method","html_id":"public_key_compressed_prefix(p:ECPoint)-class-method","name":"public_key_compressed_prefix","doc":"Exports the compressed public key from an `ECPoint` with either the\nprefix `\"02\"` or `\"03\"`.\n\nThe prefix can be later used to recover the `y` coordinate of the public key,\nsee `decode_compressed_public_key`. `Bitcoin` uses this format\nto generate shorter addresses as compared to using uncompressed keys.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be compressed.\n\n```\nSecp256k1::Util.public_key_compressed_prefix my_public_key\n# => \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\n```","summary":"Exports the compressed public key from an ECPoint
with either the prefix \"02\"
or \"03\"
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L109","def":{"name":"public_key_compressed_prefix","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"prefix = (p.y % 2) === 1 ? \"03\" : \"02\"\n\"#{prefix}#{public_key_compressed(p)}\"\n"}},{"id":"public_key_from_private(priv:BigInt)-class-method","html_id":"public_key_from_private(priv:BigInt)-class-method","name":"public_key_from_private","doc":"Gets a public key from a private key.\n\nThis is basically a wrapper function to perform an elliptic curve\nmultiplication with the generator point `g` and a provided private key `priv`.\n\nParameters:\n* `priv` (`BigInt`): the private key to be used.\n\n```\nSecp256k1::Util.public_key_from_private BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\n```\n\nReturns an `ECPoint` containing the public key.","summary":"Gets a public key from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(priv : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L258","def":{"name":"public_key_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Core.ec_mul(EC_BASE_G, priv)"}},{"id":"public_key_uncompressed(p:ECPoint)-class-method","html_id":"public_key_uncompressed(p:ECPoint)-class-method","name":"public_key_uncompressed","doc":"Exports the uncompressed public key from an `ECPoint` without prefix.\n\n`Ethereum` uses this format to generate addresses. For prefixed\nuncompressed public keys, see `public_key_uncompressed_prefix`.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be uncompressed.\n\n```\nSecp256k1::Util.public_key_uncompressed my_public_key\n# => \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```","summary":"Exports the uncompressed public key from an ECPoint
without prefix.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L126","def":{"name":"public_key_uncompressed","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x = to_padded_hex_32(p.x)\ny = to_padded_hex_32(p.y)\n\"#{x}#{y}\"\n"}},{"id":"public_key_uncompressed_prefix(p:ECPoint)-class-method","html_id":"public_key_uncompressed_prefix(p:ECPoint)-class-method","name":"public_key_uncompressed_prefix","doc":"Exports the uncompressed public key from an `ECPoint` with prefix `\"04\"`.\n\n`Bitcoin` uses this format to generate uncompressed addresses.\nFor unprefixed public keys, see `public_key_uncompressed`.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be uncompressed.\n\n```\nSecp256k1::Util.public_key_uncompressed_prefix my_public_key\n# => \"04d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```","summary":"Exports the uncompressed public key from an ECPoint
with prefix \"04\"
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L144","def":{"name":"public_key_uncompressed_prefix","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"04#{public_key_uncompressed(p)}\""}},{"id":"restore_public_key(pub:String,prime=EC_PRIME_P)-class-method","html_id":"restore_public_key(pub:String,prime=EC_PRIME_P)-class-method","name":"restore_public_key","doc":"Detects public key type and tries to restore the `ECPoint` from it.\n\nParameters:\n* `pub` (`String`): the public key in any format.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\n```\nSecp256k1::Util.restore_public_key \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```\n\nReturns an `ECPoint` containing the public key.\n\nRaises if public key format is unknown.","summary":"Detects public key type and tries to restore the ECPoint
from it.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(pub : String, prime = EC_PRIME_P)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L234","def":{"name":"restore_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case pub.size\nwhen 130, 128\n decode_uncompressed_public_key(pub)\nwhen 66\n decode_compressed_public_key(pub, prime)\nelse\n raise(\"unknown public key format (invalid key size: #{pub.size})\")\nend"}},{"id":"to_padded_hex_01(i:Int32)-class-method","html_id":"to_padded_hex_01(i:Int32)-class-method","name":"to_padded_hex_01","doc":"A generic utility to encode single hex bytes as strings, e.g., \"07\"\n\nParameters:\n* `i` (`Int32`): the integer to be formatted as padded hex byte.\n\n```\nSecp256k1::Util.to_padded_hex_01 7\n# => \"07\"\n```","summary":"A generic utility to encode single hex bytes as strings, e.g., \"07\"
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L33","def":{"name":"to_padded_hex_01","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hex = i.to_s(16)\nwhile hex.size < 2\n hex = '0' + hex\nend\nhex\n"}},{"id":"to_padded_hex_32(i:BigInt)-class-method","html_id":"to_padded_hex_32(i:BigInt)-class-method","name":"to_padded_hex_32","doc":"An utility tool to ensure hex keys are always 32 bytes;\nit pads the number with leading zeros if it's shorter.\n\nParameters:\n* `i` (`BigInt`): the integer to be formatted as padded hex byte string.\n\n```\nSecp256k1::Util.to_padded_hex_32 BigInt.new 7\n# => \"0000000000000000000000000000000000000000000000000000000000000007\"\n```","summary":"An utility tool to ensure hex keys are always 32 bytes; it pads the number with leading zeros if it's shorter.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"BigInt"}],"args_string":"(i : BigInt)","source_link":"https://github.com/q9f/secp256k1.cr/blob/f6ea8e70d50b6270fa3f31c07fb97831baff6d5b/src/util.cr#L51","def":{"name":"to_padded_hex_32","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hex = i.to_s(16)\nwhile hex.size < 64\n hex = '0' + hex\nend\nhex\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}})
\ No newline at end of file
+crystal_doc_search_index_callback({"repository_name":"secp256k1","body":"# secp256k1.cr\n\n[![Build Status](https://img.shields.io/github/workflow/status/q9f/secp256k1.cr/Nightly)](https://github.com/q9f/secp256k1.cr/actions)\n[![Documentation](https://img.shields.io/badge/docs-html-black)](https://q9f.github.io/secp256k1.cr/)\n[![Release](https://img.shields.io/github/v/release/q9f/secp256k1.cr?include_prereleases&color=black)](https://github.com/q9f/secp256k1.cr/releases/latest)\n[![Language](https://img.shields.io/github/languages/top/q9f/secp256k1.cr?color=black)](https://github.com/q9f/secp256k1.cr/search?l=crystal)\n[![License](https://img.shields.io/github/license/q9f/secp256k1.cr.svg?color=black)](LICENSE)\n\na native library implementing `secp256k1` purely for the crystal language. `secp256k1` is the elliptic curve used in the public-private-key cryptography required by bitcoin and ethereum.\n\nthis library allows for key generation of:\n* private keys (from secure random within the elliptic curve field size)\n* mini private keys (short 30-char base-56 keys)\n* wallet import format (checksummed base-58 private keys)\n* public keys, prefixed, compressed (from private)\n* public keys, unprefixed and prefixed, uncompressed (from private)\n* conversion between the different public key formats\n\nthis library allows for address generation of:\n* bitcoin address, compressed and uncompressed (from private or public key)\n* any other bitcoin-based address by passing a `version` byte\n* ethereum address, checksummed and unchecksummed (from private or public key)\n* any other ethereum-based address\n\nfurthermore, this library allows for:\n* signing `(r, s)` and verification of arbitrary messages and message-hashes (with key pairs)\n* managing `enode` addresses as per `devp2p` specification for ethereum nodes\n\n# installation\n\nadd the `secp256k1` library to your `shard.yml`\n\n```yaml\ndependencies:\n secp256k1:\n github: q9f/secp256k1.cr\n version: \"~> 0.3\"\n```\n\n# usage\n\n_tl;dr,_ check out [`crystal run ./try.cr`](./try.cr)!\n\n\n```crystal\n# import secp256k1\nrequire \"secp256k1\"\n```\n\nthis library exposes the following modules (in logical order):\n\n* `Secp256k1`: necessary constants and data structures, including:\n - `Secp256k1::Keypair`: for managing private-public key-pairs\n - `Secp256k1::ECPoint`: for handling of secp256k1 elliptic curve points (public keys)\n - `Secp256k1::ECDSASignature`: for secp256k1 ecdsa signatures\n* `Secp256k1::Core`: the entire core mathematics behind the elliptic curve cryptography\n* `Secp256k1::Util`: all tools for the handling of private-public key-pairs\n* `Secp256k1::Hash`: implementation of various hashing algorithms for convenience\n* `Secp256k1::Signature`: allows for signing messages and verifying signatures\n* `Secp256k1::Bitcoin`: for the generation of bitcoin addresses, including:\n - `Secp256k1::Bitcoin::Account`: for bitcoin account management\n* `Secp256k1::Ethereum`: for the generation of ethereum addresses, including\n - `Secp256k1::Ethereum::Account`: for ethereum account management\n - `Secp256k1::Ethereum::Enode`: for devp2p enode address management\n\nbasic usage:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# gets the private key\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n\n# gets the compressed public key with prefix\ncompressed = Secp256k1::Util.public_key_compressed_prefix key.public_key\n# => \"03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b\"\n```\n\ngenerate a compressed bitcoin mainnet address:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# generates a compressed bitcoin account from the keypair\nbtc = Secp256k1::Bitcoin::Account.new key, \"00\", true\n# => #\n\n# gets the wallet-import format (checksummed private key)\nbtc.wif\n# => \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n\n# gets the compressed bitcoin addresss\nbtc.address\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```\n\ngenerate a checksummed ethereum address:\n\n```crystal\n# generates a new keypair\nkey = Secp256k1::Keypair.new\n# => #\n\n# generates an ethereum account from the keypair\neth = Secp256k1::Ethereum::Account.new key\n# => #\n\n# gets the private key\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n\n# gets the ethereum addresss\neth.address\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```\n\n# documentation\n\nthe full library documentation can be found here: [q9f.github.io/secp256k1.cr](https://q9f.github.io/secp256k1.cr/)\n\ngenerate a local copy with:\n\n```\ncrystal docs\n```\n\n# testing\n\nthe library is entirely specified through tests in `./spec`; run:\n\n```bash\ncrystal spec --verbose\n```\n\n# understand\n\nprivate keys are just scalars and public keys are points with `x` and `y` coordinates.\n\nbitcoin public keys can be uncompressed `#{p}#{x}#{y}` or compressed `#{p}#{x}`. both come with a prefix `p` which is useless for uncompressed keys but necessary for compressed keys to recover the `y` coordinate on the `secp256k1` elliptic curve.\n\nethereum public keys are uncompressed `#{x}#{y}` without any prefix. the last 20 bytes slice of the `y` coordinate is actually used as address without any checksum. a checksum was later added in eip-55 using a `keccak256` hash and indicating character capitalization.\n\nneither bitcoin nor ethereum allow for recovering public keys from an address unless there exists a transaction with a valid signature on the blockchain.\n\n# known issues\n\n_note: this library should not be used in production without proper auditing._\n\n* this library is not constant time and might be subject to side-channel attacks. ([#4](https://github.com/q9f/secp256k1.cr/issues/4))\n* this library does unnecessary big-integer math and should someday rather correctly implement the secp256k1 prime field ([#5](https://github.com/q9f/secp256k1.cr/issues/5))\n\nfound another issue? report it: [github.com/q9f/secp256k1.cr/issues](https://github.com/q9f/secp256k1.cr/issues)\n\n# contribute\n\ncreate a pull request, and make sure tests and linter passes.\n\nthis pure crystal implementation is based on the python implementation [wobine/blackboard101](https://github.com/wobine/blackboard101) which is also used as reference to write tests against. it's a complete rewrite of the abandoned [packetzero/bitcoinutils](https://github.com/packetzero/bitcoinutils) for educational purposes.\n\nhonerable mention for the [bitcoin wiki](https://en.bitcoin.it/wiki/Main_Page) and the [ethereum stackexchange](https://ethereum.stackexchange.com/) for providing so many in-depth resources that supported this project in reimplementing everything.\n\nlicense: apache license v2.0\n\ncontributors: [**@q9f**](https://github.com/q9f/), [@cserb](https://github.com/cserb), [MrSorcus](https://github.com/MrSorcus)\n","program":{"html_id":"secp256k1/toplevel","path":"toplevel.html","kind":"module","full_name":"Top Level Namespace","name":"Top Level Namespace","abstract":false,"superclass":null,"ancestors":[],"locations":[],"repository_name":"secp256k1","program":true,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":null,"summary":null,"class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"secp256k1/Secp256k1","path":"Secp256k1.html","kind":"module","full_name":"Secp256k1","name":"Secp256k1","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/bitcoin.cr","line_number":16,"url":null},{"filename":"src/constants.cr","line_number":22,"url":null},{"filename":"src/secp256k1.cr","line_number":30,"url":null},{"filename":"src/structs.cr","line_number":20,"url":null},{"filename":"src/version.cr","line_number":20,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"EC_BASE_G","name":"EC_BASE_G","value":"ECPoint.new(EC_BASE_G_X, EC_BASE_G_Y)","doc":"The commonly used base point `G` coordinates `x`, `y`;\nany other point that satisfies `y^2 = x^3 + 7` would also do.","summary":"The commonly used base point G
coordinates x
, y
; any other point that satisfies y^2 = x^3 + 7
would also do.
"},{"id":"EC_BASE_G_COMPRESSED","name":"EC_BASE_G_COMPRESSED","value":"BigInt.new((Secp256k1::Util.public_key_compressed_prefix(EC_BASE_G)), 16)","doc":"The base point `G` in compressed form.","summary":"The base point G
in compressed form.
"},{"id":"EC_BASE_G_UNCOMPRESSED","name":"EC_BASE_G_UNCOMPRESSED","value":"BigInt.new((Secp256k1::Util.public_key_uncompressed_prefix(EC_BASE_G)), 16)","doc":"The base point `G` in uncompressed form.","summary":"The base point G
in uncompressed form.
"},{"id":"EC_BASE_G_X","name":"EC_BASE_G_X","value":"BigInt.new(\"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798\", 16)","doc":"The `x`-coordinate of the base point `G`.","summary":"The x
-coordinate of the base point G
.
"},{"id":"EC_BASE_G_Y","name":"EC_BASE_G_Y","value":"BigInt.new(\"483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8\", 16)","doc":"The `y`-coordinate of the base point `G`.","summary":"The y
-coordinate of the base point G
.
"},{"id":"EC_COFACTOR_H","name":"EC_COFACTOR_H","value":"BigInt.new(\"01\", 16)","doc":"The elliptic curve cofactor `h`.","summary":"The elliptic curve cofactor h
.
"},{"id":"EC_FACTOR_A","name":"EC_FACTOR_A","value":"BigInt.new(\"00\", 16)","doc":"The curve `E`: `y^2 = x^3 + ax + b` over `F_p` is defined by `a = 0`.\nAs the `a` constant is zero, the `ax` term in the curve equation is always zero,\nhence the curve equation becomes `y^2 = x^3 + b`.","summary":"The curve E
: y^2 = x^3 + ax + b
over F_p
is defined by a = 0
.
"},{"id":"EC_FACTOR_B","name":"EC_FACTOR_B","value":"BigInt.new(\"07\", 16)","doc":"The curve `E`: `y^2 = x^3 + b` over `F_p` is defined by `b = 7`,\nhence the curve equation becomes `y^2 = x^3 + 7`.","summary":"The curve E
: y^2 = x^3 + b
over F_p
is defined by b = 7
, hence the curve equation becomes y^2 = x^3 + 7
.
"},{"id":"EC_ORDER_N","name":"EC_ORDER_N","value":"BigInt.new(\"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141\", 16)","doc":"The order `n` of `G` defines the finite size of the Secp256k1 field `E`.","summary":"The order n
of G
defines the finite size of the Secp256k1 field E
.
"},{"id":"EC_PRIME_P","name":"EC_PRIME_P","value":"BigInt.new(\"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f\", 16)","doc":"The elliptic curve domain parameters over `F_p` associated with a Koblitz curve\nSecp256k1 are specified by the sextuple `T = (p, a, b, G, n, h)` where the finite\nfield `F_p` is defined by the prime `p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1`.","summary":"The elliptic curve domain parameters over F_p
associated with a Koblitz curve Secp256k1 are specified by the sextuple T = (p, a, b, G, n, h)
where the finite field F_p
is defined by the prime p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
.
"},{"id":"VERSION","name":"VERSION","value":"\"0.3.6\"","doc":"The `VERSION` of the `Secp256k1` module.","summary":"The VERSION
of the Secp256k1
module.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":null,"doc":"Implements 256-bit `Secp256k1` Koblitz elliptic curve.\nRef: [secg.org/sec2-v2.pdf](https://www.secg.org/sec2-v2.pdf)\n\n`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p.\nRef: [en.bitcoin.it/wiki/Secp256k1](https://en.bitcoin.it/wiki/Secp256k1)","summary":"Implements 256-bit Secp256k1
Koblitz elliptic curve.
","class_methods":[],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"secp256k1/Secp256k1/Bitcoin","path":"Secp256k1/Bitcoin.html","kind":"module","full_name":"Secp256k1::Bitcoin","name":"Bitcoin","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/bitcoin.cr","line_number":16,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements the `Bitcoin` address space for the `Secp256k1` library.","summary":"Implements the Bitcoin
address space for the Secp256k1
library.
","class_methods":[{"html_id":"address_from_private(priv:BigInt,version=\"00\",compressed=true)-class-method","name":"address_from_private","doc":"Generates a `Bitcoin` address from a private key.\n\nParameters:\n* `priv` (`BigInt`): the private key as number.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n* `compressed` (`Bool`): indicator if address should be compressed or not, default: `true` (compressed).\n\n```\nSecp256k1::Bitcoin.address_from_private BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```","summary":"Generates a Bitcoin
address from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"args_string":"(priv : BigInt, version = \"00\", compressed = true)","args_html":"(priv : BigInt, version = "00", compressed = true)","location":{"filename":"src/bitcoin.cr","line_number":563,"url":null},"def":{"name":"address_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"p = Secp256k1::Util.public_key_from_private(priv)\naddress_from_public_point(p, version, compressed)\n"}},{"html_id":"address_from_public_key(pub:String,version=\"00\")-class-method","name":"address_from_public_key","doc":"Generates a `Bitcoin` address for any public key, compressed or uncompressed.\n\nParameters:\n* `pub` (`String`): the public key, compressed or uncompressed.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n\n```\nSecp256k1::Bitcoin.address_from_public_key \"03e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b\"\n# => \"1Q1zbmPZtS2chwxpviqz6qHgoM8UUuviGN\"\n```\n\nNote, compressed public keys generate compressed addresses, whereas\nuncompressed keys generate uncompressed addresses.\n\nRaises if the public key is malformed.","summary":"Generates a Bitcoin
address for any public key, compressed or uncompressed.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""}],"args_string":"(pub : String, version = \"00\")","args_html":"(pub : String, version = "00")","location":{"filename":"src/bitcoin.cr","line_number":467,"url":null},"def":{"name":"address_from_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (pub.size === 130) || (pub.size === 66)\n sha2 = Hash.sha256(Hash.hex_to_bin(pub))\n ripe = Hash.ripemd160(Hash.hex_to_bin(sha2))\n ripe_versioned = \"#{version}#{ripe}\"\n hashed = Hash.sha256(Hash.hex_to_bin(ripe_versioned))\n hashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\n binary = \"#{ripe_versioned}#{hashed_twice[0, 8]}\"\n Hash.base58_encode(binary)\nelse\n raise(\"malformed public key (invalid key size: #{pub.size})\")\nend"}},{"html_id":"address_from_public_point(p:Secp256k1::ECPoint,version=\"00\",compressed=true)-class-method","name":"address_from_public_point","doc":"Generates a `Bitcoin` address from an public key as `ECPoint`.\n\nParameters:\n* `p` (`ECPoint`): the public key as point with `x` and `y` coordinates.\n* `version` (`String`): the version byte, default: `\"00\"` (Bitcoin).\n* `compressed` (`Bool`): indicator if address should be compressed or not, default: `true` (compressed).\n\nSee `address_from_public_key` and `ECPoint` for usage instructions.","summary":"Generates a Bitcoin
address from an public key as ECPoint
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"args_string":"(p : Secp256k1::ECPoint, version = \"00\", compressed = true)","args_html":"(p : Secp256k1::ECPoint, version = "00", compressed = true)","location":{"filename":"src/bitcoin.cr","line_number":506,"url":null},"def":{"name":"address_from_public_point","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"},{"name":"version","doc":null,"default_value":"\"00\"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"true","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = Secp256k1::Util.public_key_uncompressed_prefix(p)\nif compressed\n pub = Secp256k1::Util.public_key_compressed_prefix(p)\nend\naddress_from_public_key(pub, version)\n"}},{"html_id":"address_from_wif(wif:String)-class-method","name":"address_from_wif","doc":"Gets a `Bitcoin` address from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.address_from_wif \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets a Bitcoin
address from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":526,"url":null},"def":{"name":"address_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if wif_is_valid?(wif)\n vers = version_byte_from_wif(wif)\n vers = vers.to_i(16)\n vers = vers - 128\n vers = Secp256k1::Util.to_padded_hex_01(vers)\n priv = private_key_from_wif(wif)\n priv = BigInt.new(priv, 16)\n comp = is_wif_compressed?(wif)\n address_from_private(priv, vers, comp)\nelse\n raise(\"invalid wallet import format (invalid wif: #{wif})\")\nend"}},{"html_id":"is_wif_compressed?(wif:String)-class-method","name":"is_wif_compressed?","doc":"Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.is_wif_compressed? \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => false\n```\n\nReturns _true_ if the key is compressed.\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Checks if it's a compressed or an uncompressed Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":392,"url":null},"def":{"name":"is_wif_compressed?","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"versioned = Hash.base58_decode(wif)\nif (versioned.size === 74) || (versioned.size === 76)\n versioned.size === 76\nelse\n raise(\"invalid wallet import format (invalid wif size: #{versioned.size})\")\nend\n"}},{"html_id":"mini_is_valid?(m:String)-class-method","name":"mini_is_valid?","doc":"Validates wether a mini-private key has a correct checksum and formatting.\n\nParameters:\n* `m` (`String`): the mini-private key.\n\n```\nSecp256k1::Bitcoin.mini_is_valid? \"S7qq5k98DAvee6mtQgpg4xAJatT9mR\"\n# => true\n```\n\nReturns _true_ if the key contains a valid checksum and is formatted correctly.","summary":"Validates wether a mini-private key has a correct checksum and formatting.
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"args_string":"(m : String)","args_html":"(m : String)","location":{"filename":"src/bitcoin.cr","line_number":253,"url":null},"def":{"name":"mini_is_valid?","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"valid = m.size === 30\nvalid = valid && (m[0, 1] === \"S\")\nchecksum = Hash.sha256(\"#{m}?\")\nvalid && (checksum[0, 2] === \"00\")\n"}},{"html_id":"new_mini_private_key-class-method","name":"new_mini_private_key","doc":"Generates a new mini-private key (30 characters length, Base-56 encoded).\n\n```\nSecp256k1::Bitcoin.new_mini_private_key\n# => S7qq5k98DAvee6mtQgpg4xAJatT9mR\n```","summary":"Generates a new mini-private key (30 characters length, Base-56 encoded).
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/bitcoin.cr","line_number":193,"url":null},"def":{"name":"new_mini_private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"valid = false\nkey = String.new\nwhile !valid\n i = 1\n key = \"S\"\n while i < 30\n i = i + 1\n r = Random.rand(56)\n key = key + (Hash.base56_char(r))\n end\n valid = mini_is_valid?(key)\n if valid\n priv = private_key_from_mini(key)\n valid = valid && priv > 0\n valid = valid && (priv === (priv % Secp256k1::EC_ORDER_N))\n end\nend\nkey\n"}},{"html_id":"private_key_from_mini(m:String)-class-method","name":"private_key_from_mini","doc":"Gets a private key from a mini-private key if the key is valid.\n\nParameters:\n* `m` (`String`): the mini-private key.\n\n```\nSecp256k1::Bitcoin.private_key_from_mini \"S7qq5k98DAvee6mtQgpg4xAJatT9mR\"\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```\n\nRaises if the key is invalid.","summary":"Gets a private key from a mini-private key if the key is valid.
","abstract":false,"args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"args_string":"(m : String)","args_html":"(m : String)","location":{"filename":"src/bitcoin.cr","line_number":232,"url":null},"def":{"name":"private_key_from_mini","args":[{"name":"m","doc":null,"default_value":"","external_name":"m","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if mini_is_valid?(m)\n private_key = Hash.sha256(m)\n BigInt.new(private_key, 16)\nelse\n raise(\"mini private key is not valid (invalid checksum for: #{m})\")\nend"}},{"html_id":"private_key_from_wif(wif:String)-class-method","name":"private_key_from_wif","doc":"Gets a private key from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.private_key_from_wif \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets a private key from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":341,"url":null},"def":{"name":"private_key_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"checksum_key = Hash.base58_decode(wif)\nif (checksum_key.size == 74) || (checksum_key.size == 76)\n private_key = BigInt.new(checksum_key[2, 64], 16)\n Secp256k1::Util.to_padded_hex_32(private_key)\nelse\n raise(\"invalid wallet import format (invalid wif size: #{checksum_key.size})\")\nend\n"}},{"html_id":"version_byte_from_wif(wif:String)-class-method","name":"version_byte_from_wif","doc":"Gets the version byte from a Base-58 Wallet-Import Format (WIF).\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.version_byte_from_wif \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => \"80\"\n```\n\nRaises if Wallet-Import Format (WIF) is invalid.","summary":"Gets the version byte from a Base-58 Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":366,"url":null},"def":{"name":"version_byte_from_wif","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"versioned = Hash.base58_decode(wif)\nif (versioned.size === 74) || (versioned.size === 76)\n versioned[0, 2]\nelse\n raise(\"invalid wallet import format (invalid wif size: #{versioned.size})\")\nend\n"}},{"html_id":"wif_from_private(k:BigInt,version=\"80\",compr=\"\")-class-method","name":"wif_from_private","doc":"Gets a Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key.\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin).\n* `compr` (`String`): the compression byte, default: `\"\"` (uncompressed).\n\n```\nSecp256k1::Bitcoin.wif_from_private BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n```\n\nNote, the compression byte `compr` is either empty `\"\"` for uncompressed keys or\n`\"01\"` for compressed keys. See also `wif_from_private_compressed` and `wif_from_private_uncompressed`.","summary":"Gets a Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""},{"name":"compr","doc":null,"default_value":"\"\"","external_name":"compr","restriction":""}],"args_string":"(k : BigInt, version = \"80\", compr = \"\")","args_html":"(k : BigInt, version = "80", compr = "")","location":{"filename":"src/bitcoin.cr","line_number":277,"url":null},"def":{"name":"wif_from_private","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""},{"name":"compr","doc":null,"default_value":"\"\"","external_name":"compr","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"priv = Secp256k1::Util.to_padded_hex_32(k)\nversioned = \"#{version}#{priv}#{compr}\"\nhashed = Hash.sha256(Hash.hex_to_bin(versioned))\nhashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\nbinary = \"#{versioned}#{hashed_twice[0, 8]}\"\nHash.base58_encode(binary)\n"}},{"html_id":"wif_from_private_compressed(k:BigInt,version=\"80\")-class-method","name":"wif_from_private_compressed","doc":"Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin)\n\n```\nSecp256k1::Bitcoin.wif_from_private_compressed BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"Kz2grUzxEAxNopiREbNpVbjoitAGQVXnUZY4n8pNdmWdVqub99qu\"\n```","summary":"Gets a compressed Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"args_string":"(k : BigInt, version = \"80\")","args_html":"(k : BigInt, version = "80")","location":{"filename":"src/bitcoin.cr","line_number":310,"url":null},"def":{"name":"wif_from_private_compressed","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"wif_from_private(k, version, \"01\")"}},{"html_id":"wif_from_private_uncompressed(k:BigInt,version=\"80\")-class-method","name":"wif_from_private_uncompressed","doc":"Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.\n\nParameters:\n* `k` (`BigInt`): the private key\n* `version` (`String`): the version byte, default: `\"80\"` (Bitcoin)\n\n```\nSecp256k1::Bitcoin.wif_from_private_uncompressed BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n```","summary":"Gets an uncompressed Base-58 Wallet-Import Format (WIF) from a private key.
","abstract":false,"args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"args_string":"(k : BigInt, version = \"80\")","args_html":"(k : BigInt, version = "80")","location":{"filename":"src/bitcoin.cr","line_number":325,"url":null},"def":{"name":"wif_from_private_uncompressed","args":[{"name":"k","doc":null,"default_value":"","external_name":"k","restriction":"BigInt"},{"name":"version","doc":null,"default_value":"\"80\"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"wif_from_private(k, version, \"\")"}},{"html_id":"wif_is_valid?(wif:String)-class-method","name":"wif_is_valid?","doc":"Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.\n\nParameters:\n* `wif` (`String`): the Base-58 Wallet-Import Format (WIF).\n\n```\nSecp256k1::Bitcoin.wif_is_valid? \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\n# => true\n```\n\nReturns _true_ if the key contains a valid checksum and is formatted correctly.","summary":"Validates wether a Wallet-Import Format (WIF) has a correct checksum and formatting.
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":416,"url":null},"def":{"name":"wif_is_valid?","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"checksum_key = Hash.base58_decode(wif)\nvalid = (checksum_key.size === 74) || (checksum_key.size === 76)\nif valid\n private_key = private_key_from_wif(wif)\n valid = (valid && (private_key != \"-999\")) && (private_key.size === 64)\n versioned = checksum_key[0, 66]\n wif_checksum = checksum_key[66, 8]\n if checksum_key.size === 76\n versioned = checksum_key[0, 68]\n wif_checksum = checksum_key[68, 8]\n end\n hashed = Hash.sha256(Hash.hex_to_bin(versioned))\n hashed_twice = Hash.sha256(Hash.hex_to_bin(hashed))\n pk_checksum = hashed_twice[0, 8]\n valid = valid && (wif_checksum === pk_checksum)\nend\nvalid\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"secp256k1/Secp256k1/Bitcoin/Account","path":"Secp256k1/Bitcoin/Account.html","kind":"class","full_name":"Secp256k1::Bitcoin::Account","name":"Account","abstract":false,"superclass":{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/bitcoin.cr","line_number":34,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1/Bitcoin","kind":"module","full_name":"Secp256k1::Bitcoin","name":"Bitcoin"},"doc":"Implements a `Bitcoin` account containing a `Keypair`, a Wallet-Import Format,\nand an address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n* `compressed` (`Bool`): an indicator whether a compressed format should be used.\n* `address` (`String`): the public `Bitcoin` address.\n* `wif` (`String`): the private Wallet-Import Format (WIF).\n\n```\nbtc = Secp256k1::Bitcoin::Account.new\nbtc.wif\n# => \"5JTDCfWtwBsA26NcrJJdb7xvBPvJY9jKTdppXckp3SVTrBe6pg1\"\nbtc.address\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```","summary":"Implements a Bitcoin
account containing a Keypair
, a Wallet-Import Format, and an address.
","class_methods":[],"constructors":[{"html_id":"new(key_pair,version,compressed)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair` allowing for a custom\nnetwork version byte and compression.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n* `compressed` (`Bool`): an indicator whether a compressed format should be used.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key, \"00\", true\n# => #\n```\n\nRaises if the version byte is out of range.","summary":"Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom network version byte and compression.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":""}],"args_string":"(key_pair, version, compressed)","args_html":"(key_pair, version, compressed)","location":{"filename":"src/bitcoin.cr","line_number":125,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""},{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, version, compressed)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(key_pair,version)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair` allowing for a custom\nnetwork version byte.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `version` (`String`): the version byte determining the used network encoding.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key, \"1e\"\n# => #\n```\n\nNote, this always generates an uncompressed account for the specified network.\n\nRaises if the version byte is out of range.","summary":"Generates a Bitcoin::Account
from a provided Keypair
allowing for a custom network version byte.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""}],"args_string":"(key_pair, version)","args_html":"(key_pair, version)","location":{"filename":"src/bitcoin.cr","line_number":97,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, version)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(key_pair)-class-method","name":"new","doc":"Generates a `Bitcoin::Account` from a provided `Keypair`.\n\nParameters:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\nbtc = Secp256k1::Bitcoin::Account.new key\n# => #\n```\n\nNote, this always generates an uncompressed mainnet Bitcoin account.","summary":"Generates a Bitcoin::Account
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","args_html":"(key_pair)","location":{"filename":"src/bitcoin.cr","line_number":74,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new-class-method","name":"new","doc":"Generates a new `Bitcoin::Account` from a fresh random `Keypair`.\n\n```\nbtc = Secp256k1::Bitcoin::Account.new\n# => #\n```\n\nNote, this always generates an uncompressed mainnet Bitcoin account.","summary":"Generates a new Bitcoin::Account
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/bitcoin.cr","line_number":54,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"address:String-instance-method","name":"address","doc":"The public `Bitcoin` address.","summary":"The public Bitcoin
address.
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/bitcoin.cr","line_number":42,"url":null},"def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@address"}},{"html_id":"address=(address:String)-instance-method","name":"address=","doc":"The public `Bitcoin` address.","summary":"The public Bitcoin
address.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"args_string":"(address : String)","args_html":"(address : String)","location":{"filename":"src/bitcoin.cr","line_number":42,"url":null},"def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"html_id":"compressed:Bool-instance-method","name":"compressed","doc":"An indicator whether a compressed format should be used.","summary":"An indicator whether a compressed format should be used.
","abstract":false,"args":[],"args_string":" : Bool","args_html":" : Bool","location":{"filename":"src/bitcoin.cr","line_number":40,"url":null},"def":{"name":"compressed","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Bool","visibility":"Public","body":"@compressed"}},{"html_id":"compressed=(compressed:Bool)-instance-method","name":"compressed=","doc":"An indicator whether a compressed format should be used.","summary":"An indicator whether a compressed format should be used.
","abstract":false,"args":[{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":"Bool"}],"args_string":"(compressed : Bool)","args_html":"(compressed : Bool)","location":{"filename":"src/bitcoin.cr","line_number":40,"url":null},"def":{"name":"compressed=","args":[{"name":"compressed","doc":null,"default_value":"","external_name":"compressed","restriction":"Bool"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@compressed = compressed"}},{"html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\nbtc.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/bitcoin.cr","line_number":172,"url":null},"def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"html_id":"is_compressed?:Bool-instance-method","name":"is_compressed?","doc":"Tells if the `Bitcoin::Account` is compressed.\n\n```\nbtc.is_compressed?\n# => false\n```\n\nReturns _true_ if the compressed format is used.","summary":"Tells if the Bitcoin::Account
is compressed.
","abstract":false,"args":[],"args_string":" : Bool","args_html":" : Bool","location":{"filename":"src/bitcoin.cr","line_number":151,"url":null},"def":{"name":"is_compressed?","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@compressed"}},{"html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","args_html":" : Keypair","location":{"filename":"src/bitcoin.cr","line_number":36,"url":null},"def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","args_html":"(key_pair : Keypair)","location":{"filename":"src/bitcoin.cr","line_number":36,"url":null},"def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"html_id":"to_s:String-instance-method","name":"to_s","doc":"Gets the account formatted as `Bitcoin` address.\n\n```\nbtc.to_s\n# => \"1Gbxhju13BpwpzzFRgNr2TDYCRTg94kgFC\"\n```","summary":"Gets the account formatted as Bitcoin
address.
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/bitcoin.cr","line_number":182,"url":null},"def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address"}},{"html_id":"version:String-instance-method","name":"version","doc":"The version byte determining the used network encoding.","summary":"The version byte determining the used network encoding.
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/bitcoin.cr","line_number":38,"url":null},"def":{"name":"version","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@version"}},{"html_id":"version=(version:String)-instance-method","name":"version=","doc":"The version byte determining the used network encoding.","summary":"The version byte determining the used network encoding.
","abstract":false,"args":[{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":"String"}],"args_string":"(version : String)","args_html":"(version : String)","location":{"filename":"src/bitcoin.cr","line_number":38,"url":null},"def":{"name":"version=","args":[{"name":"version","doc":null,"default_value":"","external_name":"version","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@version = version"}},{"html_id":"version_wif-instance-method","name":"version_wif","doc":"Computes the version byte for the private Wallet-Import Format which is\noffset by `+ 0x80` from the public address `version` byte.\n\n```\nbtc.version_wif\n# => \"80\"\n```","summary":"Computes the version byte for the private Wallet-Import Format which is offset by + 0x80
from the public address #version
byte.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/bitcoin.cr","line_number":162,"url":null},"def":{"name":"version_wif","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_01((@version.to_i(16)) + 128)"}},{"html_id":"wif:String-instance-method","name":"wif","doc":"The private Wallet-Import Format (WIF).","summary":"The private Wallet-Import Format (WIF).
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/bitcoin.cr","line_number":44,"url":null},"def":{"name":"wif","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@wif"}},{"html_id":"wif=(wif:String)-instance-method","name":"wif=","doc":"The private Wallet-Import Format (WIF).","summary":"The private Wallet-Import Format (WIF).
","abstract":false,"args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"args_string":"(wif : String)","args_html":"(wif : String)","location":{"filename":"src/bitcoin.cr","line_number":44,"url":null},"def":{"name":"wif=","args":[{"name":"wif","doc":null,"default_value":"","external_name":"wif","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@wif = wif"}}],"macros":[],"types":[]}]},{"html_id":"secp256k1/Secp256k1/Core","path":"Secp256k1/Core.html","kind":"module","full_name":"Secp256k1::Core","name":"Core","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/core.cr","line_number":20,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements 256-bit `Secp256k1` Koblitz elliptic curve.\nRef: [secg.org/sec2-v2.pdf](https://www.secg.org/sec2-v2.pdf)\n\n`Secp256k1` has the characteristic prime `p`, it is defined over the prime field ℤ_p.\nRef: [en.bitcoin.it/wiki/Secp256k1](https://en.bitcoin.it/wiki/Secp256k1)","summary":"Implements 256-bit Secp256k1
Koblitz elliptic curve.
","class_methods":[{"html_id":"ec_add(p:ECPoint,q:ECPoint,prime=EC_PRIME_P)-class-method","name":"ec_add","doc":"The elliptic curve jive addition of point `p(x, y)` and `q(x, y)`.\n\nWe basically _draw_ a line between `p` and `q` which will intersect the\ncurve in the point `r` which will be mirrored over the `x`-axis.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the jive addition.\n* `q` (`ECPoint`): the point `q(x, y)` to be used in the jive addition.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns another `ECPoint` as result.","summary":"The elliptic curve jive addition of point p(x, y)
and q(x, y)
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"q","doc":null,"default_value":"","external_name":"q","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(p : ECPoint, q : ECPoint, prime = EC_PRIME_P)","args_html":"(p : ECPoint, q : ECPoint, prime = EC_PRIME_P)","location":{"filename":"src/core.cr","line_number":60,"url":null},"def":{"name":"ec_add","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"q","doc":null,"default_value":"","external_name":"q","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x_delta = q.x - p.x\nx_inv = ec_mod_inv(x_delta)\ny_delta = q.y - p.y\nm = (y_delta * x_inv) % prime\nx = (((m * m) - p.x) - q.x) % prime\ny = ((m * (p.x - x)) - p.y) % prime\nx = BigInt.new(x)\ny = BigInt.new(y)\nECPoint.new(x, y)\n"}},{"html_id":"ec_double(p:ECPoint,prime=EC_PRIME_P)-class-method","name":"ec_double","doc":"The elliptic curve juke point doubling of `p(x, y)`.\n\nThis is a special case of addition where both points are the same.\nWe _draw_ a tangent line at `p` which will intersect the curve\nat point `r` which will be mirrored over the `x`-axis.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the juke doubling.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns another `ECPoint` as result.","summary":"The elliptic curve juke point doubling of p(x, y)
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(p : ECPoint, prime = EC_PRIME_P)","args_html":"(p : ECPoint, prime = EC_PRIME_P)","location":{"filename":"src/core.cr","line_number":83,"url":null},"def":{"name":"ec_double","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"lam_numer = ((3 * p.x) * p.x) + EC_FACTOR_A\nlam_denom = 2 * p.y\nlam_inv = ec_mod_inv(lam_denom)\nlam = (lam_numer * lam_inv) % prime\nx = ((lam * lam) - (2 * p.x)) % prime\ny = ((lam * (p.x - x)) - p.y) % prime\nx = BigInt.new(x)\ny = BigInt.new(y)\nECPoint.new(x, y)\n"}},{"html_id":"ec_mod_inv(a:BigInt,prime=EC_PRIME_P)-class-method","name":"ec_mod_inv","doc":"Computes the elliptic curve modular multiplicative inverse of `a`.\n\nParemeters:\n* `a` (`BigInt`): the integer that we want the modular inverse of.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\nReturns a `BigInt` value as result.","summary":"Computes the elliptic curve modular multiplicative inverse of a
.
","abstract":false,"args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"BigInt"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(a : BigInt, prime = EC_PRIME_P)","args_html":"(a : BigInt, prime = EC_PRIME_P)","location":{"filename":"src/core.cr","line_number":28,"url":null},"def":{"name":"ec_mod_inv","args":[{"name":"a","doc":null,"default_value":"","external_name":"a","restriction":"BigInt"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"m_low = 1\nm_high = 0\nv_low = a % prime\nv_high = prime\nwhile v_low > 1\n v_ratio = v_high // v_low\n m_low_r = m_low * v_ratio\n v_low_r = v_low * v_ratio\n m = m_high - m_low_r\n v = v_high - v_low_r\n m_high = m_low\n v_high = v_low\n m_low = m\n v_low = v\nend\nm_low % prime\n"}},{"html_id":"ec_mul(p:ECPoint,s:BigInt)-class-method","name":"ec_mul","doc":"The elliptic curve sequence multiplication of point `p(x, y)` and\na skalar `s`.\n\nWith `s` being a private key within the elliptic curve field size of `EC_ORDER_N`.\n\nParamters:\n* `p` (`ECPoint`): the point `p(x, y)` to be used in the sequencing.\n* `s` (`BigInt`): a skalar, in most cases a private key.\n\nReturns another `ECPoint` as result, in most cases a public key.","summary":"The elliptic curve sequence multiplication of point p(x, y)
and a skalar s
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(p : ECPoint, s : BigInt)","args_html":"(p : ECPoint, s : BigInt)","location":{"filename":"src/core.cr","line_number":105,"url":null},"def":{"name":"ec_mul","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if (s === 0) || s >= EC_ORDER_N\n raise(\"invalid private key: outside of ec field size.\")\nend\ns_bin = s.to_s(2)\nq = p\ns_bin.each_char_with_index do |char, index|\n if index === 0\n next\n end\n q = ec_double(q)\n if char === '1'\n q = ec_add(q, p)\n end\nend\nq\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/ECDSASignature","path":"Secp256k1/ECDSASignature.html","kind":"struct","full_name":"Secp256k1::ECDSASignature","name":"ECDSASignature","abstract":false,"superclass":{"html_id":"secp256k1/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"secp256k1/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"secp256k1/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/structs.cr","line_number":127,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A basic ECDSA Signature containing a random point `r` and the\nsignature proof `s`.\n\nSee: `Signature` for signature generation.\n\nProperties:\n* `r` (`BigInt`): the `x` coordinate of a random point `R`.\n* `s` (`BigInt`): the signature proof of a message.\n\n```\nsig = ECDSASignature.new r.x, proof\n```","summary":"A basic ECDSA Signature containing a random point #r
and the signature proof #s
.
","class_methods":[],"constructors":[{"html_id":"new(r:BigInt,s:BigInt)-class-method","name":"new","doc":"A signature always requires the random point `r` and the signature proof `s`.\n\nParameters:\n* `r` (`BigInt`): the `x` coordinate of a random point `R`.\n* `s` (`BigInt`): the signature proof of a message.","summary":"A signature always requires the random point #r
and the signature proof #s
.
","abstract":false,"args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(r : BigInt, s : BigInt)","args_html":"(r : BigInt, s : BigInt)","location":{"filename":"src/structs.cr","line_number":139,"url":null},"def":{"name":"new","args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"},{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(r, s)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"r:BigInt-instance-method","name":"r","doc":"The `x` coordinate of a random point `R`.","summary":"The x
coordinate of a random point R
.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":129,"url":null},"def":{"name":"r","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@r"}},{"html_id":"r=(r:BigInt)-instance-method","name":"r=","doc":"The `x` coordinate of a random point `R`.","summary":"The x
coordinate of a random point R
.
","abstract":false,"args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"}],"args_string":"(r : BigInt)","args_html":"(r : BigInt)","location":{"filename":"src/structs.cr","line_number":129,"url":null},"def":{"name":"r=","args":[{"name":"r","doc":null,"default_value":"","external_name":"r","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@r = r"}},{"html_id":"s:BigInt-instance-method","name":"s","doc":"The signature proof of a message.","summary":"The signature proof of a message.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":132,"url":null},"def":{"name":"s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@s"}},{"html_id":"s=(s:BigInt)-instance-method","name":"s=","doc":"The signature proof of a message.","summary":"The signature proof of a message.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"args_string":"(s : BigInt)","args_html":"(s : BigInt)","location":{"filename":"src/structs.cr","line_number":132,"url":null},"def":{"name":"s=","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@s = s"}}],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/ECPoint","path":"Secp256k1/ECPoint.html","kind":"struct","full_name":"Secp256k1::ECPoint","name":"ECPoint","abstract":false,"superclass":{"html_id":"secp256k1/Struct","kind":"struct","full_name":"Struct","name":"Struct"},"ancestors":[{"html_id":"secp256k1/Struct","kind":"struct","full_name":"Struct","name":"Struct"},{"html_id":"secp256k1/Value","kind":"struct","full_name":"Value","name":"Value"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/structs.cr","line_number":99,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A point in the two-dimensional space of an elliptic curve.\n\nProperties:\n* `x` (`BigInt`): the position on the x-axis.\n* `y` (`BigInt`): the position on the y-axis.\n\n```\np = ECPoint.new BigInt.new(0), BigInt.new(0)\np.x\n# => 0\np.y\n# => 0\n```","summary":"A point in the two-dimensional space of an elliptic curve.
","class_methods":[],"constructors":[{"html_id":"new(x:BigInt,y:BigInt)-class-method","name":"new","doc":"An ECPoint always requires two coordinates `x`, `y`.\n\nParameters:\n* `x` (`BigInt`): the position on the x-axis.\n* `y` (`BigInt`): the position on the y-axis.","summary":"An ECPoint always requires two coordinates #x
, #y
.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"args_string":"(x : BigInt, y : BigInt)","args_html":"(x : BigInt, y : BigInt)","location":{"filename":"src/structs.cr","line_number":111,"url":null},"def":{"name":"new","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"},{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(x, y)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"x:BigInt-instance-method","name":"x","doc":"The position on the x-axis.","summary":"The position on the x-axis.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":101,"url":null},"def":{"name":"x","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@x"}},{"html_id":"x=(x:BigInt)-instance-method","name":"x=","doc":"The position on the x-axis.","summary":"The position on the x-axis.
","abstract":false,"args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"}],"args_string":"(x : BigInt)","args_html":"(x : BigInt)","location":{"filename":"src/structs.cr","line_number":101,"url":null},"def":{"name":"x=","args":[{"name":"x","doc":null,"default_value":"","external_name":"x","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@x = x"}},{"html_id":"y:BigInt-instance-method","name":"y","doc":"The position on the y-axis.","summary":"The position on the y-axis.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":104,"url":null},"def":{"name":"y","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@y"}},{"html_id":"y=(y:BigInt)-instance-method","name":"y=","doc":"The position on the y-axis.","summary":"The position on the y-axis.
","abstract":false,"args":[{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"args_string":"(y : BigInt)","args_html":"(y : BigInt)","location":{"filename":"src/structs.cr","line_number":104,"url":null},"def":{"name":"y=","args":[{"name":"y","doc":null,"default_value":"","external_name":"y","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@y = y"}}],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Ethereum","path":"Secp256k1/Ethereum.html","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/ethereum.cr","line_number":19,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements the `Ethereum` address space for the `Secp256k1` library.","summary":"Implements the Ethereum
address space for the Secp256k1
library.
","class_methods":[{"html_id":"address_checksum(adr:String)-class-method","name":"address_checksum","doc":"Returns a checksummed `Ethereum` address as per EIP-55.\n\nReference: [eips.ethereum.org/EIPS/eip-55](https://eips.ethereum.org/EIPS/eip-55)\n\nParameters:\n* `adr` (`String`): an unchecked `Ethereum` address.\n\n```\nSecp256k1::Ethereum.address_checksum \"0x7598c0fbaeb021161ce2e598f45ddee90fe5c6f7\"\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nRaises if address is malformed.","summary":"Returns a checksummed Ethereum
address as per EIP-55.
","abstract":false,"args":[{"name":"adr","doc":null,"default_value":"","external_name":"adr","restriction":"String"}],"args_string":"(adr : String)","args_html":"(adr : String)","location":{"filename":"src/ethereum.cr","line_number":210,"url":null},"def":{"name":"address_checksum","args":[{"name":"adr","doc":null,"default_value":"","external_name":"adr","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"adr = adr.downcase\nif adr.size === 42\n adr = adr[2, 40]\nend\nif adr.size === 40\n keccak = Hash.keccak256(adr)\n address = \"0x\"\n i = 0\n while i < adr.size\n k = keccak[i].to_i(16)\n if k >= 8\n address = address + \"#{adr[i]}\".upcase\n else\n address = address + \"#{adr[i]}\".downcase\n end\n i = i + 1\n end\n address\nelse\n raise(\"malformed ethereum address (invalid size: #{adr.size})\")\nend\n"}},{"html_id":"address_from_private(priv:BigInt)-class-method","name":"address_from_private","doc":"Generates a checksummed `Ethereum` address from a private key.\n\nParameters:\n* `priv` (`BigInt`): a private key as number.\n\n```\nSecp256k1::Ethereum.address_from_private BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nNote, that the returned `Ethereum` address is already checksummed.","summary":"Generates a checksummed Ethereum
address from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(priv : BigInt)","args_html":"(priv : BigInt)","location":{"filename":"src/ethereum.cr","line_number":297,"url":null},"def":{"name":"address_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"p = Secp256k1::Util.public_key_from_private(priv)\naddress_from_public_point(p)\n"}},{"html_id":"address_from_public_key(pub:String)-class-method","name":"address_from_public_key","doc":"Generates a checksummed `Ethereum` address for an uncompressed public key.\n\nParameters:\n* `pub` (`String`): an uncompressed public key string.\n\n```\nSecp256k1::Ethereum.address_from_public_key \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n# => \"0x7598c0FBAEB021161ce2E598F45dDEe90FE5C6f7\"\n```\n\nNote, that the returned `Ethereum` address is already checksummed.\n\nRaises if the public key is malformed.","summary":"Generates a checksummed Ethereum
address for an uncompressed public key.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"}],"args_string":"(pub : String)","args_html":"(pub : String)","location":{"filename":"src/ethereum.cr","line_number":256,"url":null},"def":{"name":"address_from_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if pub.size === 130\n pub = pub[2, 128]\nend\nif pub.size === 128\n keccak = Hash.keccak256(Hash.hex_to_bin(pub))\n address_checksum(keccak[24, 40])\nelse\n raise(\"malformed public key (invalid key size: #{pub.size})\")\nend\n"}},{"html_id":"address_from_public_point(p:Secp256k1::ECPoint)-class-method","name":"address_from_public_point","doc":"Generates a checksummed `Ethereum` address from an public key as `ECPoint`.\n\nParameters:\n* `p` (`ECPoint`): a public key point with `x` and `y` coordinates.\n\nSee `address_from_public_key` and `ECPoint` for usage instructions.","summary":"Generates a checksummed Ethereum
address from an public key as ECPoint
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"}],"args_string":"(p : Secp256k1::ECPoint)","args_html":"(p : Secp256k1::ECPoint)","location":{"filename":"src/ethereum.cr","line_number":280,"url":null},"def":{"name":"address_from_public_point","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"Secp256k1::ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = Secp256k1::Util.public_key_uncompressed(p)\naddress_from_public_key(pub)\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[{"html_id":"secp256k1/Secp256k1/Ethereum/Account","path":"Secp256k1/Ethereum/Account.html","kind":"class","full_name":"Secp256k1::Ethereum::Account","name":"Account","abstract":false,"superclass":{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/ethereum.cr","line_number":33,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1/Ethereum","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum"},"doc":"Implements an `Ethereum` account containing a `Keypair` and an address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `address` (`String`): the public checksummed `Ethereum` address.\n\n```\neth = Secp256k1::Ethereum::Account.new\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\neth.address\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```","summary":"Implements an Ethereum
account containing a Keypair
and an address.
","class_methods":[],"constructors":[{"html_id":"new(key_pair)-class-method","name":"new","doc":"Generates an `Ethereum::Account` from a provided `Keypair`.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\neth = Secp256k1::Ethereum::Account.new key\n# => #\n```","summary":"Generates an Ethereum::Account
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","args_html":"(key_pair)","location":{"filename":"src/ethereum.cr","line_number":57,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new-class-method","name":"new","doc":"Generates a new `Ethereum::Account` from a fresh random `Keypair`.\n\n```\neth = Secp256k1::Ethereum::Account.new\n# => #\n```","summary":"Generates a new Ethereum::Account
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":45,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"address:String-instance-method","name":"address","doc":"The public checksummed `Ethereum` address.","summary":"The public checksummed Ethereum
address.
","abstract":false,"args":[],"args_string":" : String","args_html":" : String","location":{"filename":"src/ethereum.cr","line_number":37,"url":null},"def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"String","visibility":"Public","body":"@address"}},{"html_id":"address=(address:String)-instance-method","name":"address=","doc":"The public checksummed `Ethereum` address.","summary":"The public checksummed Ethereum
address.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"args_string":"(address : String)","args_html":"(address : String)","location":{"filename":"src/ethereum.cr","line_number":37,"url":null},"def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\neth.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":67,"url":null},"def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","args_html":" : Keypair","location":{"filename":"src/ethereum.cr","line_number":35,"url":null},"def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","args_html":"(key_pair : Keypair)","location":{"filename":"src/ethereum.cr","line_number":35,"url":null},"def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"html_id":"to_s-instance-method","name":"to_s","doc":"Gets the account formatted as `Ethereum` address.\n\n```\neth.to_s\n# => \"0x224008a0F3d3cB989c807F568c7f99Bf451328A6\"\n```","summary":"Gets the account formatted as Ethereum
address.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":77,"url":null},"def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Ethereum.address_checksum(@address)"}}],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Ethereum/Enode","path":"Secp256k1/Ethereum/Enode.html","kind":"class","full_name":"Secp256k1::Ethereum::Enode","name":"Enode","abstract":false,"superclass":{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/ethereum.cr","line_number":95,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1/Ethereum","kind":"module","full_name":"Secp256k1::Ethereum","name":"Ethereum"},"doc":"Implements an `Ethereum` devp2p enode containing a `Keypair` and an IP address.\n\nProperties:\n* `key_pair` (`Keypair`): the `Keypair` containing the secret key.\n* `address` (`Socket::IPAddress`): the public (or local) IP address with port.\n\n```\np2p = Secp256k1::Ethereum::Enode.new\np2p.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\np2p.to_s\n# => \"enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303\"\n```","summary":"Implements an Ethereum
devp2p enode containing a Keypair
and an IP address.
","class_methods":[],"constructors":[{"html_id":"new(key_pair,host,port)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair` and a custom IP address with port.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key, \"192.168.13.37\", 31337\n# => #\n```","summary":"Generates an Ethereum::Enode
from a provided Keypair
and a custom IP address with port.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"host","doc":null,"default_value":"","external_name":"host","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"args_string":"(key_pair, host, port)","args_html":"(key_pair, host, port)","location":{"filename":"src/ethereum.cr","line_number":147,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"host","doc":null,"default_value":"","external_name":"host","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, host, port)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(key_pair,port)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair` and a custom port.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key, 50000\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates an Ethereum::Enode
from a provided Keypair
and a custom port.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"args_string":"(key_pair, port)","args_html":"(key_pair, port)","location":{"filename":"src/ethereum.cr","line_number":136,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""},{"name":"port","doc":null,"default_value":"","external_name":"port","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair, port)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new(key_pair)-class-method","name":"new","doc":"Generates an `Ethereum::Enode` from a provided `Keypair`.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\np2p = Secp256k1::Ethereum::Enode.new key\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates an Ethereum::Enode
from a provided Keypair
.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"args_string":"(key_pair)","args_html":"(key_pair)","location":{"filename":"src/ethereum.cr","line_number":123,"url":null},"def":{"name":"new","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(key_pair)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new-class-method","name":"new","doc":"Generates a new `Ethereum::Enode` from a fresh random `Keypair`.\n\n```\np2p = Secp256k1::Ethereum::Enode.new\n# => #\n```\n\nNote, this tries to find out the public IP address and silently falls back to \"127.0.0.1\" if it fails.","summary":"Generates a new Ethereum::Enode
from a fresh random Keypair
.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":109,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"address:Socket::IPAddress-instance-method","name":"address","doc":"The public (or local) IP address with port.","summary":"The public (or local) IP address with port.
","abstract":false,"args":[],"args_string":" : Socket::IPAddress","args_html":" : Socket::IPAddress","location":{"filename":"src/ethereum.cr","line_number":99,"url":null},"def":{"name":"address","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Socket::IPAddress","visibility":"Public","body":"@address"}},{"html_id":"address=(address:Socket::IPAddress)-instance-method","name":"address=","doc":"The public (or local) IP address with port.","summary":"The public (or local) IP address with port.
","abstract":false,"args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"Socket::IPAddress"}],"args_string":"(address : Socket::IPAddress)","args_html":"(address : Socket::IPAddress)","location":{"filename":"src/ethereum.cr","line_number":99,"url":null},"def":{"name":"address=","args":[{"name":"address","doc":null,"default_value":"","external_name":"address","restriction":"Socket::IPAddress"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@address = address"}},{"html_id":"get_my_ip-instance-method","name":"get_my_ip","doc":"Tries to find out the public IP address for the node.\n\nIt queries [ident.me](http://ident.me/) for a potential public IP and silently\nfalls back to \"127.0.0.1\" if it fails without raising. _Should be used with caution._\n\n```\np2p.get_my_ip\n# => \"84.160.86.205\"\n```","summary":"Tries to find out the public IP address for the node.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":160,"url":null},"def":{"name":"get_my_ip","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"ip = nil\nbegin\n ip = (HTTP::Client.get(\"http://ident.me/\")).body.to_s\nrescue\n ip = \"127.0.0.1\"\nensure\n if ip.nil? || ip.size < 2\n ip = \"127.0.0.1\"\n end\nend\nip\n"}},{"html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\np2p.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":182,"url":null},"def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@key_pair.private_key)"}},{"html_id":"key_pair:Keypair-instance-method","name":"key_pair","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[],"args_string":" : Keypair","args_html":" : Keypair","location":{"filename":"src/ethereum.cr","line_number":97,"url":null},"def":{"name":"key_pair","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"Keypair","visibility":"Public","body":"@key_pair"}},{"html_id":"key_pair=(key_pair:Keypair)-instance-method","name":"key_pair=","doc":"The `Keypair` containing the secret key.","summary":"The Keypair
containing the secret key.
","abstract":false,"args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"args_string":"(key_pair : Keypair)","args_html":"(key_pair : Keypair)","location":{"filename":"src/ethereum.cr","line_number":97,"url":null},"def":{"name":"key_pair=","args":[{"name":"key_pair","doc":null,"default_value":"","external_name":"key_pair","restriction":"Keypair"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@key_pair = key_pair"}},{"html_id":"to_s-instance-method","name":"to_s","doc":"Gets the `Enode` formatted as devp2p enode address.\n\n```\np2p.to_s\n# => \"enode://e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f@84.160.86.205:30303\"\n```","summary":"Gets the Enode
formatted as devp2p enode address.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/ethereum.cr","line_number":192,"url":null},"def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"enode://#{@key_pair.to_s}@#{@address.to_s}\""}}],"macros":[],"types":[]}]},{"html_id":"secp256k1/Secp256k1/Hash","path":"Secp256k1/Hash.html","kind":"module","full_name":"Secp256k1::Hash","name":"Hash","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/hash.cr","line_number":20,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[{"id":"BASE_56","name":"BASE_56","value":"\"23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz\"","doc":"The Base-56 alphabet for `Bitcoin` mini-private keys is a Base-58 alphabet\nwithout `1` and `o` to additionally omit more similar-looking letters.","summary":"The Base-56 alphabet for Bitcoin
mini-private keys is a Base-58 alphabet without 1
and o
to additionally omit more similar-looking letters.
"},{"id":"BASE_58","name":"BASE_58","value":"\"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz\"","doc":"The Base-58 alphabet for `Bitcoin` addresses is a Base-64 alphabet without\n`0`, `O`, `I`, and `l` to omit similar-looking letters.","summary":"The Base-58 alphabet for Bitcoin
addresses is a Base-64 alphabet without 0
, O
, I
, and l
to omit similar-looking letters.
"}],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"The `Secp256k1::Hash` module wraps various hashing functions for convenience\nand exposes them for general use.","summary":"The Secp256k1::Hash
module wraps various hashing functions for convenience and exposes them for general use.
","class_methods":[{"html_id":"base56_char(i:Int32)-class-method","name":"base56_char","doc":"Gets a character from the Base-56 alphabet at position `i`.\n\nParameters:\n* `i` (`Int32`): the position in the Base-56 alphabet.\n\n```\nSecp256k1::Hash.base56_char 13\n# => 'F'\n```","summary":"Gets a character from the Base-56 alphabet at position i
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","args_html":"(i : Int32)","location":{"filename":"src/hash.cr","line_number":211,"url":null},"def":{"name":"base56_char","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"i = i % 56\nBASE_56[i]\n"}},{"html_id":"base58_char(i:Int32)-class-method","name":"base58_char","doc":"Gets a character from the Base-58 alphabet at position `i`.\n\nParameters:\n* `i` (`Int32`): the position in the Base-58 alphabet.\n\n```\nSecp256k1::Hash.base58_char 13\n# => 'E'\n```","summary":"Gets a character from the Base-58 alphabet at position i
.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","args_html":"(i : Int32)","location":{"filename":"src/hash.cr","line_number":225,"url":null},"def":{"name":"base58_char","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"i = i % 58\nBASE_58[i]\n"}},{"html_id":"base58_decode(s:String)-class-method","name":"base58_decode","doc":"Decodes a hexadecimal string from a Base-58 encoded string.\n\nParameters:\n* `s` (`String`): The Base-58 encoded string to be decoded.\n\n```\nSecp256k1::Hash.base58_decode \"1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt\"\n# => \"007d7935bde6c9341de87a4d64588783033e23472d7322c46b\"\n```","summary":"Decodes a hexadecimal string from a Base-58 encoded string.
","abstract":false,"args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"args_string":"(s : String)","args_html":"(s : String)","location":{"filename":"src/hash.cr","line_number":146,"url":null},"def":{"name":"base58_decode","args":[{"name":"s","doc":null,"default_value":"","external_name":"s","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"index = 0\ndecimal = BigInt.new(0)\nwhile index < s.size\n b58_char = s[index]\n position = BASE_58.index(b58_char)\n if !position.nil?\n decimal = (decimal * 58) + position\n index = index + 1\n else\n raise(\"cannot decode, invalid base58 character: '#{s[index]}'\")\n end\nend\nhex = decimal.to_s(16)\nleading = 0\nwhile s[leading] === '1'\n leading = leading + 1\n hex = \"00#{hex}\"\nend\nhex\n"}},{"html_id":"base58_encode(h:String)-class-method","name":"base58_encode","doc":"Encodes a Base-58 string from a hexadecimal string.\n\nParameters:\n* `h` (`String`): The hexadecimal string to be encoded.\n\n```\nSecp256k1::Hash.base58_encode \"007d7935bde6c9341de87a4d64588783033e23472d7322c46b\"\n# => \"1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt\"\n```","summary":"Encodes a Base-58 string from a hexadecimal string.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":180,"url":null},"def":{"name":"base58_encode","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"pub = BigInt.new(h, 16)\nadr = String.new\nwhile pub > 0\n pub, rem = pub.divmod(58)\n adr = adr + (base58_char(rem.to_i))\nend\ni, s = 0, 2\ncurrent_byte = h[i, s]\nwhile (current_byte.to_i(16)) === 0\n adr = \"#{adr}1\"\n i = i + s\n current_byte = h[i, s]\nend\nadr.reverse\n"}},{"html_id":"bin_to_hex(b:Bytes)-class-method","name":"bin_to_hex","doc":"Helper function to convert byte arrays to hexadecimal strings.\n\nParameters:\n* `b` (`Bytes`): the byte array to be converted.\n\n```\nSecp256k1::Hash.bin_to_hex Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n=> \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n```","summary":"Helper function to convert byte arrays to hexadecimal strings.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":239,"url":null},"def":{"name":"bin_to_hex","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"b.hexstring"}},{"html_id":"hex_to_bin(h:String)-class-method","name":"hex_to_bin","doc":"Helper function to convert hexadecimal strings to byte arrays.\n\nParameters:\n* `h` (`String`): the hexadecimal string to be converted.\n\n```\nSecp256k1::Hash.hex_to_bin \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n=> Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n```","summary":"Helper function to convert hexadecimal strings to byte arrays.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":252,"url":null},"def":{"name":"hex_to_bin","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"h.hexbytes"}},{"html_id":"keccak256(b:Bytes)-class-method","name":"keccak256","doc":"Operating a Keccak-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.keccak256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"fcb41efa0456ba9f27e573422d6b5898c61da6f2137d07e4dae618eddd72e003\"\n```","summary":"Operating a Keccak-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":66,"url":null},"def":{"name":"keccak256","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"keccak = Digest::Keccak3.new(256)\n(keccak.update(b)).hexdigest\n"}},{"html_id":"keccak256(h:String)-class-method","name":"keccak256","doc":"Operating a Keccak-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.keccak256 \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"99cfa79866ec88f87f8e25a98a4b9873f3f8ee82482a317a5494572b00f51cec\"\n```","summary":"Operating a Keccak-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":80,"url":null},"def":{"name":"keccak256","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"keccak = Digest::Keccak3.new(256)\n(keccak.update(h)).hexdigest\n"}},{"html_id":"ripemd160(b:Bytes)-class-method","name":"ripemd160","doc":"Operating a RIPEMD-160 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.ripemd160 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"5f3455f9ac58e25be08c99a7090108751b4796b9\"\n```","summary":"Operating a RIPEMD-160 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":120,"url":null},"def":{"name":"ripemd160","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"RIPEMD160\")).update(b)).final.hexstring"}},{"html_id":"ripemd160(h:String)-class-method","name":"ripemd160","doc":"Operating a RIPEMD-160 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.ripemd160 \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"46dff6cd5666c8e67db26ac0dfaf685bf71fc5f6\"\n```","summary":"Operating a RIPEMD-160 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":133,"url":null},"def":{"name":"ripemd160","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"RIPEMD160\")).update(h)).final.hexstring"}},{"html_id":"sha256(b:Bytes)-class-method","name":"sha256","doc":"Operating a SHA2-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.sha256 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"2739cc5f45c0e05236527e4e687dc54f0d5e88be64b9a90e5264a6721c0c71f2\"\n```","summary":"Operating a SHA2-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":94,"url":null},"def":{"name":"sha256","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"SHA256\")).update(b)).final.hexstring"}},{"html_id":"sha256(h:String)-class-method","name":"sha256","doc":"Operating a SHA2-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.sha256 \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"452a41c28c9981faebb402095a5d553de28dc212338057aed27081110dfb907a\"\n```","summary":"Operating a SHA2-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":107,"url":null},"def":{"name":"sha256","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"((OpenSSL::Digest.new(\"SHA256\")).update(h)).final.hexstring"}},{"html_id":"sha3(b:Bytes)-class-method","name":"sha3","doc":"Operating a SHA3-256 hash on a byte array.\n\nParameters:\n* `b` (`Bytes`): the byte array to be hashed.\n\n```\nSecp256k1::Hash.sha3 Bytes[183, 149, 205, 44, 92, 224, 204, 99, 44, 161, 246, 94, 146, 27, 156, 117, 27, 54, 62, 151, 252, 174, 236, 129, 192, 42, 133, 183, 99, 68, 130, 104]\n# => \"66bb65180108362a3e25ba8282f7b96bfe840ce34a2e5dbc421aa8a590cc5f2e\"\n```","summary":"Operating a SHA3-256 hash on a byte array.
","abstract":false,"args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"args_string":"(b : Bytes)","args_html":"(b : Bytes)","location":{"filename":"src/hash.cr","line_number":38,"url":null},"def":{"name":"sha3","args":[{"name":"b","doc":null,"default_value":"","external_name":"b","restriction":"Bytes"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sha3 = Digest::SHA3.new(256)\n(sha3.update(b)).hexdigest\n"}},{"html_id":"sha3(h:String)-class-method","name":"sha3","doc":"Operating a SHA3-256 hash on an actual string literal.\n\nParameters:\n* `h` (`String`): the string literal to be hashed.\n\n```\nSecp256k1::Hash.sha3 \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n# => \"aedc012933679615eb93fb0063f53010e6f0034e92aaccf97dacc46e338037e9\"\n```","summary":"Operating a SHA3-256 hash on an actual string literal.
","abstract":false,"args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"args_string":"(h : String)","args_html":"(h : String)","location":{"filename":"src/hash.cr","line_number":52,"url":null},"def":{"name":"sha3","args":[{"name":"h","doc":null,"default_value":"","external_name":"h","restriction":"String"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"sha3 = Digest::SHA3.new(256)\n(sha3.update(h)).hexdigest\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Keypair","path":"Secp256k1/Keypair.html","kind":"class","full_name":"Secp256k1::Keypair","name":"Keypair","abstract":false,"superclass":{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},"ancestors":[{"html_id":"secp256k1/Reference","kind":"class","full_name":"Reference","name":"Reference"},{"html_id":"secp256k1/Object","kind":"class","full_name":"Object","name":"Object"}],"locations":[{"filename":"src/structs.cr","line_number":34,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements a `Secp256k1` key pair containing a private and a public key.\n\nProperties:\n* `private_key` (`BigInt`): the secret as known as the private key.\n* `public_key` (`ECPoint`): the point on the elliptic curve as known as the public key.\n\n```\nkey = Secp256k1::Keypair.new\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\nkey.to_s\n# => \"e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f\"\n```","summary":"Implements a Secp256k1
key pair containing a private and a public key.
","class_methods":[],"constructors":[{"html_id":"new(private_key)-class-method","name":"new","doc":"Generates a new keypair using a provided private key.\n\nParameters:\n* `private_key` (`BigInt`): the secret as known as the private key.\n\n```\nkey = Secp256k1::Keypair.new BigInt.new(\"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\", 16)\n# => #\n```","summary":"Generates a new keypair using a provided private key.
","abstract":false,"args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":""}],"args_string":"(private_key)","args_html":"(private_key)","location":{"filename":"src/structs.cr","line_number":61,"url":null},"def":{"name":"new","args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize(private_key)\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}},{"html_id":"new-class-method","name":"new","doc":"Generates a new keypair using a fresh random private key.\n\n```\nkey = Secp256k1::Keypair.new\n# => #\n```","summary":"Generates a new keypair using a fresh random private key.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/structs.cr","line_number":47,"url":null},"def":{"name":"new","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"_ = allocate\n_.initialize\nif _.responds_to?(:finalize)\n ::GC.add_finalizer(_)\nend\n_\n"}}],"instance_methods":[{"html_id":"get_secret-instance-method","name":"get_secret","doc":"Gets the private key as hexadecimal formatted string literal.\n\n```\nkey.get_secret\n# => \"53d77137b39427a35d8c4b187f532d3912e1e7135985e730633e1e3c1b87ce97\"\n```","summary":"Gets the private key as hexadecimal formatted string literal.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/structs.cr","line_number":71,"url":null},"def":{"name":"get_secret","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.to_padded_hex_32(@private_key)"}},{"html_id":"private_key:BigInt-instance-method","name":"private_key","doc":"The secret as known as the private key.","summary":"The secret as known as the private key.
","abstract":false,"args":[],"args_string":" : BigInt","args_html":" : BigInt","location":{"filename":"src/structs.cr","line_number":36,"url":null},"def":{"name":"private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"BigInt","visibility":"Public","body":"@private_key"}},{"html_id":"private_key=(private_key:BigInt)-instance-method","name":"private_key=","doc":"The secret as known as the private key.","summary":"The secret as known as the private key.
","abstract":false,"args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":"BigInt"}],"args_string":"(private_key : BigInt)","args_html":"(private_key : BigInt)","location":{"filename":"src/structs.cr","line_number":36,"url":null},"def":{"name":"private_key=","args":[{"name":"private_key","doc":null,"default_value":"","external_name":"private_key","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@private_key = private_key"}},{"html_id":"public_key:ECPoint-instance-method","name":"public_key","doc":"The point on the elliptic curve as known as the public key.","summary":"The point on the elliptic curve as known as the public key.
","abstract":false,"args":[],"args_string":" : ECPoint","args_html":" : ECPoint","location":{"filename":"src/structs.cr","line_number":39,"url":null},"def":{"name":"public_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"ECPoint","visibility":"Public","body":"@public_key"}},{"html_id":"public_key=(public_key:ECPoint)-instance-method","name":"public_key=","doc":"The point on the elliptic curve as known as the public key.","summary":"The point on the elliptic curve as known as the public key.
","abstract":false,"args":[{"name":"public_key","doc":null,"default_value":"","external_name":"public_key","restriction":"ECPoint"}],"args_string":"(public_key : ECPoint)","args_html":"(public_key : ECPoint)","location":{"filename":"src/structs.cr","line_number":39,"url":null},"def":{"name":"public_key=","args":[{"name":"public_key","doc":null,"default_value":"","external_name":"public_key","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"@public_key = public_key"}},{"html_id":"to_s-instance-method","name":"to_s","doc":"Gets the key formatted as uncompressed public key string.\n\n```\nkey.to_s\n# => \"e097fc69f0b92f711620511c07fefdd648e469df46b1e4385a00a1786f6bc55b7d9011bb589e883d8a7947cfb37dc6b3c8beae9c614cab4a83009bd9d8732a9f\"\n```","summary":"Gets the key formatted as uncompressed public key string.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/structs.cr","line_number":81,"url":null},"def":{"name":"to_s","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Util.public_key_uncompressed(@public_key)"}}],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Signature","path":"Secp256k1/Signature.html","kind":"module","full_name":"Secp256k1::Signature","name":"Signature","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/signature.cr","line_number":18,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"Implements `ECDSASignature` generation and verification for `Secp256k1`\nelliptic curves.\nRef: [cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages](https://cryptobook.nakov.com/digital-signatures/ecdsa-sign-verify-messages)","summary":"Implements ECDSASignature
generation and verification for Secp256k1
elliptic curves.
","class_methods":[{"html_id":"sign(msg:String,priv:BigInt)-class-method","name":"sign","doc":"Signs a message and creates a signature proof using a private key.\n\nThe ECDSA signing algorithm (RFC-6979) takes as input a message `msg`\nand a private key `priv`. It produces as output a signature, which\nconsists of pair of integers `(r, s)`, where `r` is the `x`-coordinate\nof a random point on our curve and `s` is the signature proof.\n\nParameters:\n* `msg` (`String`): A message string to sign.\n* `priv` (`BigInt`): A private key to sign with.\n\n```\nsig = Secp256k1::Signature.sign \"Hello, World!\", BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\nsig.r\n# => \"63945398370917837063250848409972066837033757647691696776146735867163610886143\"\nsig.s\n# => \"20291418537568297129028959685291490143232574306335372594306006819765182564103\"\n```","summary":"Signs a message and creates a signature proof using a private key.
","abstract":false,"args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(msg : String, priv : BigInt)","args_html":"(msg : String, priv : BigInt)","location":{"filename":"src/signature.cr","line_number":37,"url":null},"def":{"name":"sign","args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hash = BigInt.new(Hash.sha256(msg), 16)\nk = Util.new_private_key\nr = (Core.ec_mul(EC_BASE_G, k)).x % EC_ORDER_N\nk_inv = Core.ec_mod_inv(k, EC_ORDER_N)\ns = ((hash + (r * priv)) * k_inv) % EC_ORDER_N\nECDSASignature.new(r, s)\n"}},{"html_id":"verify(msg:String,sig:ECDSASignature,pub:ECPoint)-class-method","name":"verify","doc":"Verifies a signature of a message against a public key.\n\nThe algorithm to verify an ECDSA signature takes as input the signed message `msg`\nand the signature `(r, s)` produced from `sign` and the public key `pub`,\ncorresponding to the signer's private key. The result is boolean.\n\nParameters:\n* `msg` (`String`): A message string to verify.\n* `sig` (`ECDSASignature`): A signature to verify the message.\n* `pub` (`ECPoint`): A public key to verify the signature against.\n\n```\npub = Secp256k1::Util.restore_public_key \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\nmsg = \"Hello, World!\"\nsig = Secp256k1::ECDSASignature.new BigInt.new(\"63945398370917837063250848409972066837033757647691696776146735867163610886143\"), BigInt.new(\"20291418537568297129028959685291490143232574306335372594306006819765182564103\")\n\nSecp256k1::Signature.verify msg, sig, pub\n# => true\n```","summary":"Verifies a signature of a message against a public key.
","abstract":false,"args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"args_string":"(msg : String, sig : ECDSASignature, pub : ECPoint)","args_html":"(msg : String, sig : ECDSASignature, pub : ECPoint)","location":{"filename":"src/signature.cr","line_number":75,"url":null},"def":{"name":"verify","args":[{"name":"msg","doc":null,"default_value":"","external_name":"msg","restriction":"String"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hash = BigInt.new(Hash.sha256(msg), 16)\nverify_hash(hash, sig, pub)\n"}},{"html_id":"verify_hash(hash:BigInt,sig:ECDSASignature,pub:ECPoint)-class-method","name":"verify_hash","doc":"Verifies a signature of a message hash against a public key.\n\nSame as `verify`, just using the hashed message directly.\n\nParameters:\n* `hash` (`BigInt`): A SHA-256 hash of the message to verify.\n* `sig` (`ECDSASignature`): A signature to verify the message.\n* `pub` (`ECPoint`): A public key to verify the signature against.\n\nReturns _true_ if signature is valid. See `verify` for usage example.","summary":"Verifies a signature of a message hash against a public key.
","abstract":false,"args":[{"name":"hash","doc":null,"default_value":"","external_name":"hash","restriction":"BigInt"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"args_string":"(hash : BigInt, sig : ECDSASignature, pub : ECPoint)","args_html":"(hash : BigInt, sig : ECDSASignature, pub : ECPoint)","location":{"filename":"src/signature.cr","line_number":91,"url":null},"def":{"name":"verify_hash","args":[{"name":"hash","doc":null,"default_value":"","external_name":"hash","restriction":"BigInt"},{"name":"sig","doc":null,"default_value":"","external_name":"sig","restriction":"ECDSASignature"},{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"s_inv = Core.ec_mod_inv(sig.s, EC_ORDER_N)\np0 = Core.ec_mul(EC_BASE_G, (hash * s_inv) % EC_ORDER_N)\np1 = Core.ec_mul(pub, (sig.r * s_inv) % EC_ORDER_N)\np = Core.ec_add(p0, p1)\nsig.r === p.x\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]},{"html_id":"secp256k1/Secp256k1/Util","path":"Secp256k1/Util.html","kind":"module","full_name":"Secp256k1::Util","name":"Util","abstract":false,"superclass":null,"ancestors":[],"locations":[{"filename":"src/util.cr","line_number":23,"url":null}],"repository_name":"secp256k1","program":false,"enum":false,"alias":false,"aliased":null,"aliased_html":null,"const":false,"constants":[],"included_modules":[],"extended_modules":[],"subclasses":[],"including_types":[],"namespace":{"html_id":"secp256k1/Secp256k1","kind":"module","full_name":"Secp256k1","name":"Secp256k1"},"doc":"A collection of utilities for `Secp256k1` key management, e.g., private key\ngeneration, public key conversions, key formatting, or hex padding.","summary":"A collection of utilities for Secp256k1
key management, e.g., private key generation, public key conversions, key formatting, or hex padding.
","class_methods":[{"html_id":"decode_compressed_public_key(pub:String,prime=EC_PRIME_P)-class-method","name":"decode_compressed_public_key","doc":"Decodes a public key as `ECPoint` from a compressed public key string.\n\nIf unsure, `restore_public_key` should be used.\n\nParameters:\n* `pub` (`String`): the public key in prefixed compressed format.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\n```\nSecp256k1::Util.decode_compressed_public_key \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\n```\n\nReturns an `ECPoint` containing the public key.\n\nRaises if compressed public key is malformed or comes with invalid prefix.","summary":"Decodes a public key as ECPoint
from a compressed public key string.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(pub : String, prime = EC_PRIME_P)","args_html":"(pub : String, prime = EC_PRIME_P)","location":{"filename":"src/util.cr","line_number":163,"url":null},"def":{"name":"decode_compressed_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"if pub.size === 66\n prefix = pub[0, 2]\n if (prefix === \"02\") || (prefix === \"03\")\n x = BigInt.new(pub[2, 64], 16)\n a = (x ** 3) % prime\n a = (a + 7) % prime\n e = ((prime + 1) // 4) % prime\n y = BigInt.new\n LibGMP.mpz_powm_sec(y, a, e, prime)\n parity = prefix.to_i - 2\n if (y % 2) != parity\n y = (-y) % prime\n end\n ECPoint.new(x, y)\n else\n raise(\"invalid prefix for compressed public key: #{prefix}\")\n end\nelse\n raise(\"malformed compressed public key (invalid key size: #{pub.size})\")\nend"}},{"html_id":"new_private_key-class-method","name":"new_private_key","doc":"A helper function to generate 32 pseudo-random bytes within the elliptic\ncurve field size of `EC_ORDER_N`.\n\n```\nSecp256k1::Util.new_private_key\n# => \"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\"\n```","summary":"A helper function to generate 32 pseudo-random bytes within the elliptic curve field size of EC_ORDER_N
.
","abstract":false,"args":[],"args_string":"","args_html":"","location":{"filename":"src/util.cr","line_number":66,"url":null},"def":{"name":"new_private_key","args":[],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"key = -999\nwhile !key > 0\n key = Random::Secure.hex(32)\n key = BigInt.new(key, 16)\nend\nkey % EC_ORDER_N\n"}},{"html_id":"public_key_compressed_prefix(p:ECPoint)-class-method","name":"public_key_compressed_prefix","doc":"Exports the compressed public key from an `ECPoint` with either the\nprefix `\"02\"` or `\"03\"`.\n\nThe prefix can be later used to recover the `y` coordinate of the public key,\nsee `decode_compressed_public_key`. `Bitcoin` uses this format\nto generate shorter addresses as compared to using uncompressed keys.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be compressed.\n\n```\nSecp256k1::Util.public_key_compressed_prefix my_public_key\n# => \"03d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a\"\n```","summary":"Exports the compressed public key from an ECPoint
with either the prefix \"02\"
or \"03\"
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","args_html":"(p : ECPoint)","location":{"filename":"src/util.cr","line_number":109,"url":null},"def":{"name":"public_key_compressed_prefix","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"prefix = (p.y % 2) === 1 ? \"03\" : \"02\"\n\"#{prefix}#{public_key_compressed(p)}\"\n"}},{"html_id":"public_key_from_private(priv:BigInt)-class-method","name":"public_key_from_private","doc":"Gets a public key from a private key.\n\nThis is basically a wrapper function to perform an elliptic curve\nmultiplication with the generator point `g` and a provided private key `priv`.\n\nParameters:\n* `priv` (`BigInt`): the private key to be used.\n\n```\nSecp256k1::Util.public_key_from_private BigInt.new(\"b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268\", 16)\n```\n\nReturns an `ECPoint` containing the public key.","summary":"Gets a public key from a private key.
","abstract":false,"args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"args_string":"(priv : BigInt)","args_html":"(priv : BigInt)","location":{"filename":"src/util.cr","line_number":258,"url":null},"def":{"name":"public_key_from_private","args":[{"name":"priv","doc":null,"default_value":"","external_name":"priv","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"Core.ec_mul(EC_BASE_G, priv)"}},{"html_id":"public_key_uncompressed(p:ECPoint)-class-method","name":"public_key_uncompressed","doc":"Exports the uncompressed public key from an `ECPoint` without prefix.\n\n`Ethereum` uses this format to generate addresses. For prefixed\nuncompressed public keys, see `public_key_uncompressed_prefix`.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be uncompressed.\n\n```\nSecp256k1::Util.public_key_uncompressed my_public_key\n# => \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```","summary":"Exports the uncompressed public key from an ECPoint
without prefix.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","args_html":"(p : ECPoint)","location":{"filename":"src/util.cr","line_number":126,"url":null},"def":{"name":"public_key_uncompressed","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"x = to_padded_hex_32(p.x)\ny = to_padded_hex_32(p.y)\n\"#{x}#{y}\"\n"}},{"html_id":"public_key_uncompressed_prefix(p:ECPoint)-class-method","name":"public_key_uncompressed_prefix","doc":"Exports the uncompressed public key from an `ECPoint` with prefix `\"04\"`.\n\n`Bitcoin` uses this format to generate uncompressed addresses.\nFor unprefixed public keys, see `public_key_uncompressed`.\n\nParameters:\n* `p` (`ECPoint`): the public key point which shall be uncompressed.\n\n```\nSecp256k1::Util.public_key_uncompressed_prefix my_public_key\n# => \"04d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```","summary":"Exports the uncompressed public key from an ECPoint
with prefix \"04\"
.
","abstract":false,"args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"args_string":"(p : ECPoint)","args_html":"(p : ECPoint)","location":{"filename":"src/util.cr","line_number":144,"url":null},"def":{"name":"public_key_uncompressed_prefix","args":[{"name":"p","doc":null,"default_value":"","external_name":"p","restriction":"ECPoint"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"\"04#{public_key_uncompressed(p)}\""}},{"html_id":"restore_public_key(pub:String,prime=EC_PRIME_P)-class-method","name":"restore_public_key","doc":"Detects public key type and tries to restore the `ECPoint` from it.\n\nParameters:\n* `pub` (`String`): the public key in any format.\n* `prime` (`BigInt`): the prime number that shapes the field, default: `EC_PRIME_P`.\n\n```\nSecp256k1::Util.restore_public_key \"d885aed4bcaf3a8c95a57e3be08caa1bd6a060a68b9795c03129073597fcb19a67299d1cf25955e9b6425583cbc33f4ab831f5a31ef88c7167e9eb714cc758a5\"\n```\n\nReturns an `ECPoint` containing the public key.\n\nRaises if public key format is unknown.","summary":"Detects public key type and tries to restore the ECPoint
from it.
","abstract":false,"args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"args_string":"(pub : String, prime = EC_PRIME_P)","args_html":"(pub : String, prime = EC_PRIME_P)","location":{"filename":"src/util.cr","line_number":234,"url":null},"def":{"name":"restore_public_key","args":[{"name":"pub","doc":null,"default_value":"","external_name":"pub","restriction":"String"},{"name":"prime","doc":null,"default_value":"EC_PRIME_P","external_name":"prime","restriction":""}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"case pub.size\nwhen 130, 128\n decode_uncompressed_public_key(pub)\nwhen 66\n decode_compressed_public_key(pub, prime)\nelse\n raise(\"unknown public key format (invalid key size: #{pub.size})\")\nend"}},{"html_id":"to_padded_hex_01(i:Int32)-class-method","name":"to_padded_hex_01","doc":"A generic utility to encode single hex bytes as strings, e.g., \"07\"\n\nParameters:\n* `i` (`Int32`): the integer to be formatted as padded hex byte.\n\n```\nSecp256k1::Util.to_padded_hex_01 7\n# => \"07\"\n```","summary":"A generic utility to encode single hex bytes as strings, e.g., \"07\"
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"args_string":"(i : Int32)","args_html":"(i : Int32)","location":{"filename":"src/util.cr","line_number":33,"url":null},"def":{"name":"to_padded_hex_01","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"Int32"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hex = i.to_s(16)\nwhile hex.size < 2\n hex = '0' + hex\nend\nhex\n"}},{"html_id":"to_padded_hex_32(i:BigInt)-class-method","name":"to_padded_hex_32","doc":"An utility tool to ensure hex keys are always 32 bytes;\nit pads the number with leading zeros if it's shorter.\n\nParameters:\n* `i` (`BigInt`): the integer to be formatted as padded hex byte string.\n\n```\nSecp256k1::Util.to_padded_hex_32 BigInt.new 7\n# => \"0000000000000000000000000000000000000000000000000000000000000007\"\n```","summary":"An utility tool to ensure hex keys are always 32 bytes; it pads the number with leading zeros if it's shorter.
","abstract":false,"args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"BigInt"}],"args_string":"(i : BigInt)","args_html":"(i : BigInt)","location":{"filename":"src/util.cr","line_number":51,"url":null},"def":{"name":"to_padded_hex_32","args":[{"name":"i","doc":null,"default_value":"","external_name":"i","restriction":"BigInt"}],"double_splat":null,"splat_index":null,"yields":null,"block_arg":null,"return_type":"","visibility":"Public","body":"hex = i.to_s(16)\nwhile hex.size < 64\n hex = '0' + hex\nend\nhex\n"}}],"constructors":[],"instance_methods":[],"macros":[],"types":[]}]}]}})
\ No newline at end of file