module Secp256k1::Hash
Overview
The Secp256k1::Hash
module wraps various hashing functions for convenience
and exposes them for general use.
Defined in:
hash.crConstant Summary
-
BASE_56 =
"23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnpqrstuvwxyz"
-
The Base-56 alphabet for
Bitcoin
mini-private keys is a Base-58 alphabet without1
ando
to additionally omit more similar-looking letters. -
BASE_58 =
"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
-
The Base-58 alphabet for
Bitcoin
addresses is a Base-64 alphabet without0
,O
,I
, andl
to omit similar-looking letters.
Class Method Summary
-
.base56_char(i : Int32)
Gets a character from the Base-56 alphabet at position
i
. -
.base58_char(i : Int32)
Gets a character from the Base-58 alphabet at position
i
. -
.base58_decode(s : String)
Decodes a hexadecimal string from a Base-58 encoded string.
-
.base58_encode(h : String)
Encodes a Base-58 string from a hexadecimal string.
-
.bin_to_hex(b : Bytes)
Helper function to convert byte arrays to hexadecimal strings.
-
.hex_to_bin(h : String)
Helper function to convert hexadecimal strings to byte arrays.
-
.keccak256(b : Bytes)
Operating a Keccak-256 hash on a byte array.
-
.keccak256_string(h : String)
Operating a Keccak-256 hash on an actual string literal.
-
.ripemd160(b : Bytes)
Operating a RIPEMD-160 hash on a byte array.
-
.ripemd160_string(h : String)
Operating a RIPEMD-160 hash on an actual string literal.
-
.sha256(b : Bytes)
Operating a SHA2-256 hash on a byte array.
-
.sha256_string(h : String)
Operating a SHA2-256 hash on an actual string literal.
-
.sha3(b : Bytes)
Operating a SHA3-256 hash on a byte array.
-
.sha3_string(h : String)
Operating a SHA3-256 hash on an actual string literal.
Class Method Detail
Gets a character from the Base-56 alphabet at position i
.
Parameters:
i
(Int32
): the position in the Base-56 alphabet.
Secp256k1::Hash.base56_char 13
# => 'F'
Gets a character from the Base-58 alphabet at position i
.
Parameters:
i
(Int32
): the position in the Base-58 alphabet.
Secp256k1::Hash.base58_char 13
# => 'E'
Decodes a hexadecimal string from a Base-58 encoded string.
Parameters:
s
(String
): The Base-58 encoded string to be decoded.
Secp256k1::Hash.base58_decode "1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt"
# => "007d7935bde6c9341de87a4d64588783033e23472d7322c46b"
Encodes a Base-58 string from a hexadecimal string.
Parameters:
h
(String
): The hexadecimal string to be encoded.
Secp256k1::Hash.base58_encode "007d7935bde6c9341de87a4d64588783033e23472d7322c46b"
# => "1CSSfnxKnQK1GDWSaWqNpYXSdfPTtSooHt"
Helper function to convert byte arrays to hexadecimal strings.
Parameters:
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]
=> "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
Helper function to convert hexadecimal strings to byte arrays.
Parameters:
h
(String
): the hexadecimal string to be converted.
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]
Operating a Keccak-256 hash on a byte array.
Parameters:
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]
# => "fcb41efa0456ba9f27e573422d6b5898c61da6f2137d07e4dae618eddd72e003"
Operating a Keccak-256 hash on an actual string literal.
Parameters:
h
(String
): the string literal to be hashed.
Secp256k1::Hash.keccak256_string "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
# => "99cfa79866ec88f87f8e25a98a4b9873f3f8ee82482a317a5494572b00f51cec"
Operating a RIPEMD-160 hash on a byte array.
Parameters:
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]
# => "5f3455f9ac58e25be08c99a7090108751b4796b9"
Operating a RIPEMD-160 hash on an actual string literal.
Parameters:
h
(String
): the string literal to be hashed.
Secp256k1::Hash.ripemd160_string "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
# => "46dff6cd5666c8e67db26ac0dfaf685bf71fc5f6"
Operating a SHA2-256 hash on a byte array.
Parameters:
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]
# => "2739cc5f45c0e05236527e4e687dc54f0d5e88be64b9a90e5264a6721c0c71f2"
Operating a SHA2-256 hash on an actual string literal.
Parameters:
h
(String
): the string literal to be hashed.
Secp256k1::Hash.sha256_string "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
# => "452a41c28c9981faebb402095a5d553de28dc212338057aed27081110dfb907a"
Operating a SHA3-256 hash on a byte array.
Parameters:
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]
# => "66bb65180108362a3e25ba8282f7b96bfe840ce34a2e5dbc421aa8a590cc5f2e"
Operating a SHA3-256 hash on an actual string literal.
Parameters:
h
(String
): the string literal to be hashed.
Secp256k1::Hash.sha3_string "b795cd2c5ce0cc632ca1f65e921b9c751b363e97fcaeec81c02a85b763448268"
# => "aedc012933679615eb93fb0063f53010e6f0034e92aaccf97dacc46e338037e9"