Module: Secp256k1::Util
- Defined in:
- lib/rbsecp256k1/util.rb
Overview
Contains utility methods that complement the functionality of the library.
Constant Summary collapse
- HEX_REGEXP =
Regexp to validate a hexadecimal string
/^[A-Fa-f\d]+$/.freeze
Class Method Summary collapse
-
.bin_to_hex(binary_string) ⇒ String
Converts a binary string to a hex string.
-
.hex_to_bin(hex_string) ⇒ String
Converts a hex string to a binary string.
Class Method Details
.bin_to_hex(binary_string) ⇒ String
Converts a binary string to a hex string.
13 14 15 |
# File 'lib/rbsecp256k1/util.rb', line 13 def self.bin_to_hex(binary_string) binary_string.unpack('H*').first end |
.hex_to_bin(hex_string) ⇒ String
Converts a hex string to a binary string.
22 23 24 25 26 |
# File 'lib/rbsecp256k1/util.rb', line 22 def self.hex_to_bin(hex_string) raise ArgumentError, "Invalid hexadecimal string" unless hex_string =~ HEX_REGEXP [hex_string].pack('H*') end |