Module BSV::Primitives::Digest ¶
Cryptographic hash functions and HMAC operations.
Thin wrappers around OpenSSL::Digest and OpenSSL::HMAC providing the hash algorithms used throughout the BSV protocol: SHA-1, SHA-256, double-SHA-256, SHA-512, RIPEMD-160, Hash160, HMAC, and PBKDF2.
Public Class Methods¶
hash160(data) ¶
Compute Hash160: RIPEMD-160(SHA-256(data)).
Standard Bitcoin hash used for addresses and P2PKH script matching. - @param data [String] binary data to hash - @return [String] 20-byte digest
hmac_sha256(key, data) ¶
Compute HMAC-SHA-256. - @param key [String] HMAC key - @param data [String] data to authenticate - @return [String] 32-byte MAC
hmac_sha512(key, data) ¶
Compute HMAC-SHA-512. - @param key [String] HMAC key - @param data [String] data to authenticate - @return [String] 64-byte MAC
pbkdf2_hmac_sha512(password, salt, iterations: = 2048, key_length: = 64) ¶
Derive a key using PBKDF2-HMAC-SHA-512.
Used by BIP-39 to convert mnemonic phrases into seeds. - @param password [String] the password (mnemonic phrase) - @param salt [String] the salt (+"mnemonic"+ + passphrase) - @param iterations [Integer] iteration count (default: 2048 per BIP-39) - @param key_length [Integer] desired output length in bytes (default: 64) - @return [String] derived key bytes
ripemd160(data) ¶
Compute RIPEMD-160 digest. - @param data [String] binary data to hash - @return [String] 20-byte digest
sha1(data) ¶
Compute SHA-1 digest. - @param data [String] binary data to hash - @return [String] 20-byte digest
sha256(data) ¶
Compute SHA-256 digest. - @param data [String] binary data to hash - @return [String] 32-byte digest
sha256d(data) ¶
Compute double-SHA-256 (SHA-256d) digest.
Used extensively in Bitcoin for transaction and block hashing. - @param data [String] binary data to hash - @return [String] 32-byte digest
sha512(data) ¶
Compute SHA-512 digest. - @param data [String] binary data to hash - @return [String] 64-byte digest