Module: Crypto
- Defined in:
- lib/substrate_common.rb
Class Method Summary collapse
- .blake2_128(bytes) ⇒ Object
- .blake2_128_concat(bytes) ⇒ Object
- .blake2_256(bytes) ⇒ Object
- .identity(bytes) ⇒ Object
- .twox128(data) ⇒ Object
- .twox64(data) ⇒ Object
- .twox64_concat(bytes) ⇒ Object
Class Method Details
.blake2_128(bytes) ⇒ Object
72 73 74 75 |
# File 'lib/substrate_common.rb', line 72 def self.blake2_128(bytes) data = bytes.bytes_to_utf8 Blake2b.hex data, Blake2b::Key.none, 16 end |
.blake2_128_concat(bytes) ⇒ Object
82 83 84 |
# File 'lib/substrate_common.rb', line 82 def self.blake2_128_concat(bytes) blake2_128(bytes) + bytes.bytes_to_hex[2..] end |
.blake2_256(bytes) ⇒ Object
77 78 79 80 |
# File 'lib/substrate_common.rb', line 77 def self.blake2_256(bytes) data = bytes.bytes_to_utf8 Blake2b.hex data, Blake2b::Key.none, 32 end |
.identity(bytes) ⇒ Object
48 49 50 |
# File 'lib/substrate_common.rb', line 48 def self.identity(bytes) bytes.bytes_to_hex[2..] end |
.twox128(data) ⇒ Object
58 59 60 61 62 63 64 65 |
# File 'lib/substrate_common.rb', line 58 def self.twox128(data) bytes = [] 2.times do |i| result = XXhash.xxh64 data, i bytes = bytes + result.to_s(16).rjust(16, '0').hex_to_bytes.reverse end bytes.bytes_to_hex[2..] end |
.twox64(data) ⇒ Object
52 53 54 55 56 |
# File 'lib/substrate_common.rb', line 52 def self.twox64(data) result = XXhash.xxh64 data, 0 bytes = result.to_s(16).rjust(16, '0').hex_to_bytes.reverse bytes.bytes_to_hex[2..] end |
.twox64_concat(bytes) ⇒ Object
67 68 69 70 |
# File 'lib/substrate_common.rb', line 67 def self.twox64_concat(bytes) data = bytes.bytes_to_utf8 twox64(data) + bytes.bytes_to_hex[2..] end |