hashtastic 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/Gemfile.lock +1 -1
- data/lib/hashtastic.rb +1 -0
- data/lib/hashtastic/dictionary_hasher.rb +1 -1
- data/lib/hashtastic/list_hasher.rb +1 -1
- data/lib/hashtastic/merkle_tree/invalid_hex_format_error.rb +7 -0
- data/lib/hashtastic/merkle_tree/merkle_tree.rb +22 -11
- data/lib/hashtastic/utils.rb +7 -0
- data/lib/hashtastic/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a898d7fa1b1f5188d55a073cc4db58dc2b462fabad86d9798abd2e29620f9600
|
4
|
+
data.tar.gz: bb55e244d752b738d09e72205c680efb9799aacf52123c899acba5d51ab022ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e949ae465b4ae7e0cb59d2b1d6aa077dcc386707f115efeb66ef62220bd7fbf255007722b7173f6e6890f0c4f179a3252d27a262bd674d4c8107a2a044159a6a
|
7
|
+
data.tar.gz: ef1fd8c18bfb65ce033bf7da0c97ba98a1cc3691ee02136d3d3194acf6d8848d47f7165202054ede2095278760ee9c8176759b6dc47cf68c181aa2af4e9ac0de
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,15 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
5
5
|
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
6
6
|
|
7
|
+
## [0.3.1] - 2019-08-05
|
8
|
+
### Added:
|
9
|
+
- Validate hex input
|
10
|
+
|
11
|
+
### Fixed:
|
12
|
+
- Prefix '0x' with hexdigest
|
13
|
+
|
14
|
+
### Changed:
|
15
|
+
- Move verify to class method of MerkleTree
|
7
16
|
|
8
17
|
## [0.3.0] - 2019-08-05
|
9
18
|
### Added:
|
data/Gemfile.lock
CHANGED
data/lib/hashtastic.rb
CHANGED
@@ -5,6 +5,7 @@ require 'active_support/all'
|
|
5
5
|
require 'hashtastic/utils'
|
6
6
|
require 'hashtastic/list_hasher'
|
7
7
|
require 'hashtastic/dictionary_values_hasher'
|
8
|
+
require 'hashtastic/merkle_tree/invalid_hex_format_error'
|
8
9
|
require 'hashtastic/ethereum_sha3'
|
9
10
|
require 'hashtastic/dictionary_hasher'
|
10
11
|
require 'hashtastic/digester'
|
@@ -2,9 +2,29 @@
|
|
2
2
|
|
3
3
|
module Hashtastic
|
4
4
|
class MerkleTree
|
5
|
+
class << self
|
6
|
+
def verify(proof:, root:, leaf:, hashfunc: EthereumSHA3)
|
7
|
+
proof.each { |hex| validate_hex(hex) }
|
8
|
+
|
9
|
+
computed_hash =
|
10
|
+
proof.reduce(leaf) do |acc, element|
|
11
|
+
combined = [acc, element].map { |h| Utils.hex_to_ascii(h) }.sort.join
|
12
|
+
|
13
|
+
hashfunc.call(combined)
|
14
|
+
end
|
15
|
+
|
16
|
+
computed_hash == root
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_hex(hex)
|
20
|
+
raise ArgumentError, hex unless Utils.hex?(hex)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
5
24
|
attr_reader :layers, :leafs
|
6
25
|
|
7
26
|
def initialize(leafs, hashfunc = EthereumSHA3)
|
27
|
+
leafs.each { |leaf| self.class.validate_hex(leaf) }
|
8
28
|
@hashfunc = hashfunc
|
9
29
|
@leafs = leafs.sort.uniq
|
10
30
|
@layers = LayersCreator.call(@leafs, hashfunc)
|
@@ -27,21 +47,12 @@ module Hashtastic
|
|
27
47
|
end
|
28
48
|
end
|
29
49
|
|
50
|
+
private
|
51
|
+
|
30
52
|
def pair_element(index, layer)
|
31
53
|
pair_index = index.even? ? index + 1 : index - 1
|
32
54
|
|
33
55
|
return layer[pair_index] if pair_index < layer.length
|
34
56
|
end
|
35
|
-
|
36
|
-
def verify(proof:, root:, leaf:)
|
37
|
-
computed_hash =
|
38
|
-
proof.reduce(leaf) do |acc, element|
|
39
|
-
combined = [acc, element].map { |h| Utils.hex_to_ascii(h) }.sort.join
|
40
|
-
|
41
|
-
@hashfunc.call(combined)
|
42
|
-
end
|
43
|
-
|
44
|
-
computed_hash == root
|
45
|
-
end
|
46
57
|
end
|
47
58
|
end
|
data/lib/hashtastic/utils.rb
CHANGED
data/lib/hashtastic/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hashtastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lucidity
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-08-
|
11
|
+
date: 2019-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- lib/hashtastic/digester.rb
|
134
134
|
- lib/hashtastic/ethereum_sha3.rb
|
135
135
|
- lib/hashtastic/list_hasher.rb
|
136
|
+
- lib/hashtastic/merkle_tree/invalid_hex_format_error.rb
|
136
137
|
- lib/hashtastic/merkle_tree/layers_creator.rb
|
137
138
|
- lib/hashtastic/merkle_tree/leaf_not_found_error.rb
|
138
139
|
- lib/hashtastic/merkle_tree/merkle_tree.rb
|