Class: Hashtastic::EthereumSHA3
- Inherits:
-
Object
- Object
- Hashtastic::EthereumSHA3
- Defined in:
- lib/hashtastic/ethereum_sha3.rb
Class Method Summary collapse
- .call(*values) ⇒ Object (also: digest)
- .packed_values(values) ⇒ Object
Class Method Details
.call(*values) ⇒ Object Also known as: digest
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/hashtastic/ethereum_sha3.rb', line 6 def call(*values) values = values.flatten.map do |value| if value.is_a?(String) if value[0..1] == '0x' value[2..-1] else value.unpack('H*') end elsif value.is_a?(Numeric) value.to_s(16).rjust(64, '0') else '' end end "0x#{Digest::SHA3.hexdigest(packed_values(values), 256)}" end |
.packed_values(values) ⇒ Object
24 25 26 |
# File 'lib/hashtastic/ethereum_sha3.rb', line 24 def packed_values(values) [values.join].pack('H*') end |