merkletree 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 9bdd4412b5bb49cfa7d3f5d5d93d5f0254248952
4
- data.tar.gz: 3759dac07a1eb87444a7264089a83a113ec62a18
2
+ SHA256:
3
+ metadata.gz: df5c0ce0d6a4a0c85bf7ab16750728fe99756d1c0d011f7b4f7df55b5120bc8e
4
+ data.tar.gz: 8bb9d363824fc3fb6e6480280544b950e25ce1a63d3528c54ae70b76bbdd8866
5
5
  SHA512:
6
- metadata.gz: a99eb56b3472efcca00ea11d2b9a7dedc69903dc43d33cd5d9677dd737b32288a216fd6d5f1be9bf4b6b893c311034c9c30cc7ffd0f890e65827dd730f36881f
7
- data.tar.gz: a0c2465fcb59581478779ef74bd05bf74642fb5b818072d53847fa949cdb66e8f127852edc5d99ef4ab4652d3a454ab850fbcc640a75bf6e73a91b5fc3f23594
6
+ metadata.gz: 68de4014fc2681b5d5aab8787e7a451a337931546cbd80e9d3b97cecd083cccc8047c6e70a2e7b471a847594991cfd2ff1537893f35429fdf60079d46ebbbf2e
7
+ data.tar.gz: e429a1483f01343e12f9a2f69b1f9b6584a9b419e6bc4c15a2a80342855fcc34b4e609ae00859e079b1bf1f8b04fa99b8d7882f6e292ad52e5bd82e917aff701
@@ -1,3 +1,3 @@
1
- ### 0.0.1 / 2017-12-18
2
-
3
- * Everything is new. First release
1
+ ### 0.0.1 / 2017-12-18
2
+
3
+ * Everything is new. First release
@@ -1,5 +1,4 @@
1
- HISTORY.md
2
- LICENSE.md
1
+ CHANGELOG.md
3
2
  Manifest.txt
4
3
  README.md
5
4
  Rakefile
data/README.md CHANGED
@@ -1,162 +1,162 @@
1
- # Merkle Tree (Ruby Edition)
2
-
3
- merkletree library / gem - build your own crypto hash trees; named after Ralph Merkle who patented hash trees in 1979; grow your own money on trees
4
-
5
-
6
- * home :: [github.com/openblockchains/merkletree.rb](https://github.com/openblockchains/merkletree.rb)
7
- * bugs :: [github.com/openblockchains/merkletree.rb/issues](https://github.com/openblockchains/merkletree.rb/issues)
8
- * gem :: [rubygems.org/gems/merkletree](https://rubygems.org/gems/merkletree)
9
- * rdoc :: [rubydoc.info/gems/merkletree](http://rubydoc.info/gems/merkletree)
10
-
11
-
12
- ## What's a Merkle Tree?
13
-
14
- > A Merkle tree or hash tree is a tree in which every leaf node is labelled with
15
- > the hash of a data block and every non-leaf node is labelled with the
16
- > cryptographic hash of the labels of its child nodes.
17
- > Hash trees allow efficient and secure verification of the
18
- > contents of large data structures. [...]
19
- >
20
- > The concept of hash trees is named after Ralph Merkle
21
- > who patented it in 1979.
22
- >
23
- > -- [Wikipedia](https://en.wikipedia.org/wiki/Merkle_tree)
24
-
25
-
26
- ## Usage
27
-
28
-
29
- Pass along all (leaf / data block) hashes as strings or packaged in an array.
30
- Example:
31
-
32
- ``` ruby
33
- merkle = MerkleTree.new(
34
- 'eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743',
35
- 'edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b',
36
- '5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d' )
37
-
38
- # -or-
39
-
40
- merkle = MerkleTree.new( [
41
- 'eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743',
42
- 'edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b',
43
- '5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d' ])
44
-
45
-
46
- puts 'merkle tree root hash:'
47
- puts merkle.root.value
48
- # => '25fd59b79d70bbdf043d66a7b0fc01409d11b990e943bb46b840fbbddd5ab895'
49
-
50
- pp merkle ## pp (pretty print)
51
- ```
52
-
53
- resulting in:
54
-
55
- ```
56
- @root = #<MerkleTree::Node:0x46b55e0
57
- @left = #<MerkleTree::Node:0x46b6060
58
- @left = #<MerkleTree::Node:0x46b6870
59
- @left = nil,
60
- @right = nil,
61
- @value = "eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743">,
62
- @right = #<MerkleTree::Node:0x46b6810
63
- @left = nil,
64
- @right = nil,
65
- @value = "edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b">,
66
- @value = "c9de03ced4db3c63835807016b1efedb647c694d2db8b9a8579cbf0c5dcb5ab0">,
67
- @right= #<MerkleTree::Node:0x46b5ca0
68
- @left= #<MerkleTree::Node:0x46b6798
69
- @left = nil,
70
- @right = nil,
71
- @value = "5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d">,
72
- @right = #<MerkleTree::Node:0x46b6798
73
- @left = nil,
74
- @right = nil,
75
- @value = "5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d">,
76
- @value = "50963aa3b2047e0d58bb850fc12e5a324cf01061af55889389be72d3849e1d03">,
77
- @value="25fd59b79d70bbdf043d66a7b0fc01409d11b990e943bb46b840fbbddd5ab895">>
78
- ```
79
-
80
-
81
- Use `MerkleTree.compute_root` for computing the root (crypto) hash without building a
82
- tree. Example:
83
-
84
- ``` ruby
85
- merkle_root_value = MerkleTree.compute_root(
86
- 'eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743',
87
- 'edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b',
88
- '5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d' )
89
-
90
- # -or-
91
-
92
- merkle_root_value = MerkleTree.compute_root( [
93
- 'eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743',
94
- 'edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b',
95
- '5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d' ])
96
-
97
-
98
- puts 'merkle tree root hash:'
99
- puts merkle_root_value
100
- # => '25fd59b79d70bbdf043d66a7b0fc01409d11b990e943bb46b840fbbddd5ab895'
101
- ```
102
-
103
-
104
- ### Transactions
105
-
106
- Use `MerkleTree.for` or `MerkleTree.compute_root_for` for passing along transactions.
107
- Will use `to_s` on every transaction and use the resulting "serialized" string
108
- to (auto-) calculate the (crypto) hash.
109
-
110
- Let's put the transactions from the (hyper) ledger book from [Tulips on the Blockchain!](https://github.com/openblockchains/tulips)
111
- on the ~~blockchain~~ merkle tree:
112
-
113
-
114
- | From | To | What | Qty |
115
- |---------------------|--------------|---------------------------|----:|
116
- | Bloom & Blossom (†) | Daisy | Tulip Admiral of Admirals | 8 |
117
- | Vincent | Max | Tulip Bloemendaal Sunset | 2 |
118
- | Anne | Martijn | Tulip Semper Augustus | 2 |
119
- | Ruben | Julia | Tulip Admiral van Eijck | 2 |
120
-
121
- (†): Grower Transaction - New Tulips on the Market!
122
-
123
- ``` ruby
124
- merkle = MerkleTree.for(
125
- { from: "Bloom & Blossom", to: "Daisy", what: "Tulip Admiral of Admirals", qty: 8 },
126
- { from: "Vincent", to: "Max", what: "Tulip Bloemendaal Sunset", qty: 2 },
127
- { from: "Anne", to: "Martijn", what: "Tulip Semper Augustus", qty: 2 },
128
- { from: "Ruben", to: "Julia", what: "Tulip Admiral van Eijck", qty: 2 } )
129
-
130
- puts 'merkle tree root hash:'
131
- puts merkle.root.value
132
- # => '703f44630117ef9b4ac20cb149ed8a0f06e4c3ed2a791e11e16a2fe7a7d0de3d'
133
-
134
- # -or-
135
-
136
- merkle_root_value = MerkleTree.compute_root_for(
137
- { from: "Bloom & Blossom", to: "Daisy", what: "Tulip Admiral of Admirals", qty: 8 },
138
- { from: "Vincent", to: "Max", what: "Tulip Bloemendaal Sunset", qty: 2 },
139
- { from: "Anne", to: "Martijn", what: "Tulip Semper Augustus", qty: 2 },
140
- { from: "Ruben", to: "Julia", what: "Tulip Admiral van Eijck", qty: 2 } )
141
-
142
- puts 'merkle tree root hash:'
143
- puts merkle_root_value
144
- # => '703f44630117ef9b4ac20cb149ed8a0f06e4c3ed2a791e11e16a2fe7a7d0de3d'
145
- ```
146
-
147
-
148
- ## Install
149
-
150
- Just install the gem:
151
-
152
- ```
153
- $ gem install merkletree
154
- ```
155
-
156
-
157
- ## License
158
-
159
- ![](https://publicdomainworks.github.io/buttons/zero88x31.png)
160
-
161
- The `merkletree` scripts are dedicated to the public domain.
162
- Use it as you please with no restrictions whatsoever.
1
+ # Merkle Tree
2
+
3
+ merkletree library / gem - build your own crypto hash trees; named after Ralph Merkle who patented hash trees in 1979 (the patent expired in 2002); grow your own money on trees
4
+
5
+
6
+ * home :: [github.com/rubycoco/blockchain](https://github.com/rubycoco/blockchain)
7
+ * bugs :: [github.com/rubycoco/blockchain/issues](https://github.com/rubycoco/blockchain/issues)
8
+ * gem :: [rubygems.org/gems/merkletree](https://rubygems.org/gems/merkletree)
9
+ * rdoc :: [rubydoc.info/gems/merkletree](http://rubydoc.info/gems/merkletree)
10
+
11
+
12
+ ## What's a Merkle Tree?
13
+
14
+ > A Merkle tree or hash tree is a tree in which every leaf node is labelled with
15
+ > the hash of a data block and every non-leaf node is labelled with the
16
+ > cryptographic hash of the labels of its child nodes.
17
+ > Hash trees allow efficient and secure verification of the
18
+ > contents of large data structures. [...]
19
+ >
20
+ > The concept of hash trees is named after Ralph Merkle
21
+ > who patented it in 1979.
22
+ >
23
+ > -- [Wikipedia](https://en.wikipedia.org/wiki/Merkle_tree)
24
+
25
+
26
+ ## Usage
27
+
28
+
29
+ Pass along all (leaf / data block) hashes as strings or packaged in an array.
30
+ Example:
31
+
32
+ ``` ruby
33
+ merkle = MerkleTree.new(
34
+ 'eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743',
35
+ 'edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b',
36
+ '5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d' )
37
+
38
+ # -or-
39
+
40
+ merkle = MerkleTree.new( [
41
+ 'eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743',
42
+ 'edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b',
43
+ '5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d' ])
44
+
45
+
46
+ puts merkle.root.value
47
+ # => '25fd59b79d70bbdf043d66a7b0fc01409d11b990e943bb46b840fbbddd5ab895'
48
+
49
+ pp merkle ## pp (pretty print)
50
+ ```
51
+
52
+ resulting in:
53
+
54
+ ```
55
+ @root = #<MerkleTree::Node:0x46b55e0
56
+ @left = #<MerkleTree::Node:0x46b6060
57
+ @left = #<MerkleTree::Node:0x46b6870
58
+ @left = nil,
59
+ @right = nil,
60
+ @value = "eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743">,
61
+ @right = #<MerkleTree::Node:0x46b6810
62
+ @left = nil,
63
+ @right = nil,
64
+ @value = "edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b">,
65
+ @value = "c9de03ced4db3c63835807016b1efedb647c694d2db8b9a8579cbf0c5dcb5ab0">,
66
+ @right= #<MerkleTree::Node:0x46b5ca0
67
+ @left= #<MerkleTree::Node:0x46b6798
68
+ @left = nil,
69
+ @right = nil,
70
+ @value = "5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d">,
71
+ @right = #<MerkleTree::Node:0x46b6798
72
+ @left = nil,
73
+ @right = nil,
74
+ @value = "5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d">,
75
+ @value = "50963aa3b2047e0d58bb850fc12e5a324cf01061af55889389be72d3849e1d03">,
76
+ @value="25fd59b79d70bbdf043d66a7b0fc01409d11b990e943bb46b840fbbddd5ab895">>
77
+ ```
78
+
79
+
80
+ Use `MerkleTree.compute_root` for computing the root (crypto) hash without building a
81
+ tree. Example:
82
+
83
+ ``` ruby
84
+ merkle_root_value = MerkleTree.compute_root(
85
+ 'eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743',
86
+ 'edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b',
87
+ '5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d' )
88
+
89
+ # -or-
90
+
91
+ merkle_root_value = MerkleTree.compute_root( [
92
+ 'eb8ecbf6d5870763ae246e37539d82e37052cb32f88bb8c59971f9978e437743',
93
+ 'edbd4e11e69bc399a9ccd8faaea44fb27410fe8e3023bb9462450a0a9c4caa1b',
94
+ '5ee2981606328abfe0c3b1171440f0df746c1e1f8b3b56c351727f7da7ae5d8d' ])
95
+
96
+
97
+ puts merkle_root_value
98
+ # => '25fd59b79d70bbdf043d66a7b0fc01409d11b990e943bb46b840fbbddd5ab895'
99
+ ```
100
+
101
+
102
+ ### Transactions
103
+
104
+ Use `MerkleTree.for` or `MerkleTree.compute_root_for` for passing along transactions.
105
+ Will use `to_s` on every transaction and use the resulting "serialized" string
106
+ to (auto-) calculate the (crypto) hash.
107
+
108
+ Let's put the transactions from the (hyper) ledger book from [Tulips on the Blockchain!](https://github.com/openblockchains/tulips)
109
+ on the ~~blockchain~~ merkle tree:
110
+
111
+
112
+ | From | To | What | Qty |
113
+ |---------------------|--------------|---------------------------|----:|
114
+ | Bloom & Blossom (†) | Daisy | Tulip Admiral of Admirals | 8 |
115
+ | Vincent | Max | Tulip Bloemendaal Sunset | 2 |
116
+ | Anne | Martijn | Tulip Semper Augustus | 2 |
117
+ | Ruben | Julia | Tulip Admiral van Eijck | 2 |
118
+
119
+ (†): Grower Transaction - New Tulips on the Market!
120
+
121
+ ``` ruby
122
+ merkle = MerkleTree.for(
123
+ { from: "Bloom & Blossom", to: "Daisy", what: "Tulip Admiral of Admirals", qty: 8 },
124
+ { from: "Vincent", to: "Max", what: "Tulip Bloemendaal Sunset", qty: 2 },
125
+ { from: "Anne", to: "Martijn", what: "Tulip Semper Augustus", qty: 2 },
126
+ { from: "Ruben", to: "Julia", what: "Tulip Admiral van Eijck", qty: 2 } )
127
+
128
+ puts merkle.root.value
129
+ # => '703f44630117ef9b4ac20cb149ed8a0f06e4c3ed2a791e11e16a2fe7a7d0de3d'
130
+
131
+ # -or-
132
+
133
+ merkle_root_value = MerkleTree.compute_root_for(
134
+ { from: "Bloom & Blossom", to: "Daisy", what: "Tulip Admiral of Admirals", qty: 8 },
135
+ { from: "Vincent", to: "Max", what: "Tulip Bloemendaal Sunset", qty: 2 },
136
+ { from: "Anne", to: "Martijn", what: "Tulip Semper Augustus", qty: 2 },
137
+ { from: "Ruben", to: "Julia", what: "Tulip Admiral van Eijck", qty: 2 } )
138
+
139
+ puts merkle_root_value
140
+ # => '703f44630117ef9b4ac20cb149ed8a0f06e4c3ed2a791e11e16a2fe7a7d0de3d'
141
+ ```
142
+
143
+
144
+
145
+ ## Merkle Tree in the Real World
146
+
147
+ - [**blockchain-lite**](https://github.com/rubycoco/blockchain) - build your own blockchain with crypto hashes - revolutionize the world with blockchains, blockchains, blockchains one block at a time
148
+ - You? Add your library / service
149
+
150
+
151
+ ## References
152
+
153
+ [**Programming Cryptocurrencies and Blockchains (in Ruby)**](http://yukimotopress.github.io/blockchains) by Gerald Bauer et al, 2018, Yuki & Moto Press
154
+
155
+
156
+
157
+ ## License
158
+
159
+ ![](https://publicdomainworks.github.io/buttons/zero88x31.png)
160
+
161
+ The `merkletree` scripts are dedicated to the public domain.
162
+ Use it as you please with no restrictions whatsoever.
data/Rakefile CHANGED
@@ -1,29 +1,29 @@
1
- require 'hoe'
2
- require './lib/merkletree/version.rb'
3
-
4
- Hoe.spec 'merkletree' do
5
-
6
- self.version = MerkleTree::VERSION
7
-
8
- self.summary = "merkletree - build your own crypto hash trees; named after Ralph Merkle who patented hash trees in 1979; grow your own money on trees"
9
- self.description = summary
10
-
11
- self.urls = ['https://github.com/openblockchains/merkletree.rb']
12
-
13
- self.author = 'Gerald Bauer'
14
- self.email = 'wwwmake@googlegroups.com'
15
-
16
- # switch extension to .markdown for gihub formatting
17
- self.readme_file = 'README.md'
18
- self.history_file = 'HISTORY.md'
19
-
20
- ## self.extra_deps = [
21
- ## ]
22
-
23
- self.licenses = ['Public Domain']
24
-
25
- self.spec_extras = {
26
- required_ruby_version: '>= 2.3'
27
- }
28
-
29
- end
1
+ require 'hoe'
2
+ require './lib/merkletree/version.rb'
3
+
4
+ Hoe.spec 'merkletree' do
5
+
6
+ self.version = MerkleTree::VERSION
7
+
8
+ self.summary = "merkletree - build your own crypto hash trees; named after Ralph Merkle who patented hash trees in 1979; grow your own money on trees"
9
+ self.description = summary
10
+
11
+ self.urls = { home: 'https://github.com/rubycoco/blockchain' }
12
+
13
+ self.author = 'Gerald Bauer'
14
+ self.email = 'wwwmake@googlegroups.com'
15
+
16
+ # switch extension to .markdown for gihub formatting
17
+ self.readme_file = 'README.md'
18
+ self.history_file = 'CHANGELOG.md'
19
+
20
+ ## self.extra_deps = [
21
+ ## ]
22
+
23
+ self.licenses = ['Public Domain']
24
+
25
+ self.spec_extras = {
26
+ required_ruby_version: '>= 2.3'
27
+ }
28
+
29
+ end
@@ -26,6 +26,26 @@ class MerkleTree
26
26
  @left = left
27
27
  @right = right
28
28
  end
29
+
30
+
31
+ ####
32
+ ## for debugging / testing add pretty printing (dump tree)
33
+ def dump() do_dump( 0 ); end
34
+
35
+ def do_dump( depth ) ## dump (recursive_worker)
36
+ depth.times { print ' ' }
37
+ print "#{depth}:[#{value}] "
38
+ if @left
39
+ print '{'
40
+ puts
41
+ @left.do_dump( depth+1 )
42
+ @right.do_dump( depth+1) if @right # note: make right node optional (might be nil/empty)
43
+ depth.times { print ' ' }
44
+ print '}'
45
+ end
46
+ puts
47
+ end # do_dump
48
+
29
49
  end # class Node
30
50
 
31
51
 
@@ -103,6 +123,7 @@ class MerkleTree
103
123
 
104
124
 
105
125
 
126
+
106
127
  ### shortcut/convenience - compute root hash w/o building tree nodes
107
128
  def self.compute_root( *args )
108
129
  if args.size == 1 && args[0].is_a?( Array )
@@ -150,4 +171,4 @@ end # class MerkleTree
150
171
 
151
172
 
152
173
  # say hello
153
- puts MerkleTree.banner if defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG
174
+ puts MerkleTree.banner ## if defined?($RUBYLIBS_DEBUG) && $RUBYLIBS_DEBUG
@@ -1,24 +1,22 @@
1
- # encoding: utf-8
2
-
3
-
4
- class MerkleTree ## note: use class (!) for now and NOT module
5
-
6
-
7
- MAJOR = 0
8
- MINOR = 1
9
- PATCH = 0
10
- VERSION = [MAJOR,MINOR,PATCH].join('.')
11
-
12
- def self.version
13
- VERSION
14
- end
15
-
16
- def self.banner
17
- "merkletree/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
18
- end
19
-
20
- def self.root
21
- "#{File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )}"
22
- end
23
-
24
- end # module MerkleTree
1
+ # encoding: utf-8
2
+
3
+
4
+ class MerkleTree ## note: use class (!) for now and NOT module
5
+ MAJOR = 0
6
+ MINOR = 1
7
+ PATCH = 1
8
+ VERSION = [MAJOR,MINOR,PATCH].join('.')
9
+
10
+ def self.version
11
+ VERSION
12
+ end
13
+
14
+ def self.banner
15
+ "merkletree/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
16
+ end
17
+
18
+ def self.root
19
+ File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
20
+ end
21
+
22
+ end # module MerkleTree
@@ -1,10 +1,10 @@
1
- ## $:.unshift(File.dirname(__FILE__))
2
-
3
- ## minitest setup
4
-
5
- require 'minitest/autorun'
6
-
7
-
8
- ## our own code
9
-
10
- require 'merkletree'
1
+ ## $:.unshift(File.dirname(__FILE__))
2
+
3
+ ## minitest setup
4
+
5
+ require 'minitest/autorun'
6
+
7
+
8
+ ## our own code
9
+
10
+ require 'merkletree'
@@ -1,158 +1,164 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_build.rb
6
-
7
-
8
- require 'helper'
9
-
10
-
11
- class TestBuild < MiniTest::Test
12
-
13
-
14
- def test_example_4
15
-
16
- hashes = [
17
- '00',
18
- '11',
19
- '22',
20
- '33',
21
- ]
22
-
23
- hash00 = '00'
24
- hash11 = '11'
25
- hash0011 = MerkleTree.calc_hash( hash00 + hash11 )
26
-
27
- hash22 = '22'
28
- hash33 = '33'
29
- hash2233 = MerkleTree.calc_hash( hash22 + hash33 )
30
-
31
- hash00112233 = MerkleTree.calc_hash( hash0011 + hash2233 )
32
-
33
-
34
- merkle = MerkleTree.new( hashes )
35
-
36
- puts "merkletree root hash:"
37
- puts merkle.root.value
38
-
39
- puts "merkletree:"
40
- pp merkle.root
41
-
42
- assert_equal hash00, merkle.root.left.left.value
43
- assert_equal hash11, merkle.root.left.right.value
44
- assert_equal hash22, merkle.root.right.left.value
45
- assert_equal hash33, merkle.root.right.right.value
46
-
47
- assert_equal hash0011, merkle.root.left.value
48
- assert_equal hash2233, merkle.root.right.value
49
-
50
- assert_equal hash00112233, merkle.root.value
51
-
52
-
53
-
54
- merkle_root_value = MerkleTree.compute_root( hashes )
55
- puts "merkletree root hash:"
56
- puts merkle_root_value
57
-
58
- assert_equal merkle.root.value, merkle_root_value
59
- end # method test_example_4
60
-
61
-
62
- def test_example_3 ## test odd (not even hashes)
63
-
64
- hashes = [
65
- '00',
66
- '11',
67
- '22',
68
- ]
69
-
70
- hash00 = '00'
71
- hash11 = '11'
72
- hash0011 = MerkleTree.calc_hash( hash00 + hash11 )
73
-
74
- hash22 = '22'
75
- hash2222 = MerkleTree.calc_hash( hash22 + hash22 )
76
-
77
- hash00112222 = MerkleTree.calc_hash( hash0011 + hash2222 )
78
-
79
-
80
- merkle = MerkleTree.new( hashes )
81
-
82
- puts "merkletree root hash:"
83
- puts merkle.root.value
84
-
85
- puts "merkletree:"
86
- pp merkle.root
87
-
88
- assert_equal hash00, merkle.root.left.left.value
89
- assert_equal hash11, merkle.root.left.right.value
90
- assert_equal hash22, merkle.root.right.left.value
91
- assert_equal hash22, merkle.root.right.right.value
92
-
93
- assert_equal hash0011, merkle.root.left.value
94
- assert_equal hash2222, merkle.root.right.value
95
-
96
- assert_equal hash00112222, merkle.root.value
97
-
98
-
99
-
100
- merkle_root_value = MerkleTree.compute_root( hashes )
101
- puts "merkletree root hash:"
102
- puts merkle_root_value
103
-
104
- assert_equal merkle.root.value, merkle_root_value
105
- end # method test_example_3
106
-
107
-
108
- def test_example_5 ## test odd (not even hashes)
109
-
110
- hashes = [
111
- '0000',
112
- '0011',
113
- '0022',
114
- '0033',
115
- '0044',
116
- ]
117
-
118
- merkle = MerkleTree.new( hashes )
119
-
120
- puts "merkletree root hash:"
121
- puts merkle.root.value
122
-
123
- puts "merkletree:"
124
- pp merkle.root
125
-
126
-
127
- merkle_root_value = MerkleTree.compute_root( hashes )
128
- puts "merkletree root hash:"
129
- puts merkle_root_value
130
-
131
- assert_equal merkle.root.value, merkle_root_value
132
- end # method test_example_5
133
-
134
-
135
- def test_tulips
136
-
137
- merkle = MerkleTree.for(
138
- { from: "Dutchgrown", to: "Vincent", what: "Tulip Bloemendaal Sunset", qty: 10 },
139
- { from: "Keukenhof", to: "Anne", what: "Tulip Semper Augustus", qty: 7 } )
140
-
141
- puts "merkletree root hash:"
142
- puts merkle.root.value
143
-
144
- puts "merkletree:"
145
- pp merkle.root
146
-
147
- merkle_root_value = MerkleTree.compute_root_for(
148
- { from: "Dutchgrown", to: "Vincent", what: "Tulip Bloemendaal Sunset", qty: 10 },
149
- { from: "Keukenhof", to: "Anne", what: "Tulip Semper Augustus", qty: 7 } )
150
-
151
- puts "merkletree root hash:"
152
- puts merkle_root_value
153
-
154
- assert_equal merkle.root.value, merkle_root_value
155
- end # method test_tulips
156
-
157
-
158
- end # class TestBuild
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_build.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestBuild < MiniTest::Test
12
+
13
+
14
+ def test_example_4
15
+
16
+ hashes = [
17
+ '00',
18
+ '11',
19
+ '22',
20
+ '33',
21
+ ]
22
+
23
+ hash00 = '00'
24
+ hash11 = '11'
25
+ hash0011 = MerkleTree.calc_hash( hash00 + hash11 )
26
+
27
+ hash22 = '22'
28
+ hash33 = '33'
29
+ hash2233 = MerkleTree.calc_hash( hash22 + hash33 )
30
+
31
+ hash00112233 = MerkleTree.calc_hash( hash0011 + hash2233 )
32
+
33
+
34
+ merkle = MerkleTree.new( hashes )
35
+
36
+ puts "merkletree root hash:"
37
+ puts merkle.root.value
38
+
39
+ puts "merkletree:"
40
+ pp merkle.root
41
+
42
+ assert_equal hash00, merkle.root.left.left.value
43
+ assert_equal hash11, merkle.root.left.right.value
44
+ assert_equal hash22, merkle.root.right.left.value
45
+ assert_equal hash33, merkle.root.right.right.value
46
+
47
+ assert_equal hash0011, merkle.root.left.value
48
+ assert_equal hash2233, merkle.root.right.value
49
+
50
+ assert_equal hash00112233, merkle.root.value
51
+
52
+
53
+
54
+ merkle_root_value = MerkleTree.compute_root( hashes )
55
+ puts "merkletree root hash:"
56
+ puts merkle_root_value
57
+
58
+ assert_equal merkle.root.value, merkle_root_value
59
+ end # method test_example_4
60
+
61
+
62
+ def test_example_3 ## test odd (not even hashes)
63
+
64
+ hashes = [
65
+ '00',
66
+ '11',
67
+ '22',
68
+ ]
69
+
70
+ hash00 = '00'
71
+ hash11 = '11'
72
+ hash0011 = MerkleTree.calc_hash( hash00 + hash11 )
73
+
74
+ hash22 = '22'
75
+ hash2222 = MerkleTree.calc_hash( hash22 + hash22 )
76
+
77
+ hash00112222 = MerkleTree.calc_hash( hash0011 + hash2222 )
78
+
79
+
80
+ merkle = MerkleTree.new( hashes )
81
+
82
+ puts "merkletree root hash:"
83
+ puts merkle.root.value
84
+
85
+ ## try handcoded pretty printer (dump)
86
+ merkle.root.dump
87
+
88
+ puts "merkletree:"
89
+ pp merkle.root
90
+
91
+ assert_equal hash00, merkle.root.left.left.value
92
+ assert_equal hash11, merkle.root.left.right.value
93
+ assert_equal hash22, merkle.root.right.left.value
94
+ assert_equal hash22, merkle.root.right.right.value
95
+
96
+ assert_equal hash0011, merkle.root.left.value
97
+ assert_equal hash2222, merkle.root.right.value
98
+
99
+ assert_equal hash00112222, merkle.root.value
100
+
101
+
102
+
103
+ merkle_root_value = MerkleTree.compute_root( hashes )
104
+ puts "merkletree root hash:"
105
+ puts merkle_root_value
106
+
107
+ assert_equal merkle.root.value, merkle_root_value
108
+ end # method test_example_3
109
+
110
+
111
+ def test_example_5 ## test odd (not even hashes)
112
+
113
+ hashes = [
114
+ '0000',
115
+ '0011',
116
+ '0022',
117
+ '0033',
118
+ '0044',
119
+ ]
120
+
121
+ merkle = MerkleTree.new( hashes )
122
+
123
+ puts "merkletree root hash:"
124
+ puts merkle.root.value
125
+
126
+ puts "merkletree:"
127
+ pp merkle.root
128
+
129
+ ## try handcoded pretty printer (dump)
130
+ merkle.root.dump
131
+
132
+
133
+ merkle_root_value = MerkleTree.compute_root( hashes )
134
+ puts "merkletree root hash:"
135
+ puts merkle_root_value
136
+
137
+ assert_equal merkle.root.value, merkle_root_value
138
+ end # method test_example_5
139
+
140
+
141
+ def test_tulips
142
+
143
+ merkle = MerkleTree.for(
144
+ { from: "Dutchgrown", to: "Vincent", what: "Tulip Bloemendaal Sunset", qty: 10 },
145
+ { from: "Keukenhof", to: "Anne", what: "Tulip Semper Augustus", qty: 7 } )
146
+
147
+ puts "merkletree root hash:"
148
+ puts merkle.root.value
149
+
150
+ puts "merkletree:"
151
+ pp merkle.root
152
+
153
+ merkle_root_value = MerkleTree.compute_root_for(
154
+ { from: "Dutchgrown", to: "Vincent", what: "Tulip Bloemendaal Sunset", qty: 10 },
155
+ { from: "Keukenhof", to: "Anne", what: "Tulip Semper Augustus", qty: 7 } )
156
+
157
+ puts "merkletree root hash:"
158
+ puts merkle_root_value
159
+
160
+ assert_equal merkle.root.value, merkle_root_value
161
+ end # method test_tulips
162
+
163
+
164
+ end # class TestBuild
metadata CHANGED
@@ -1,56 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: merkletree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-12-19 00:00:00.000000000 Z
11
+ date: 2021-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '4.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '7'
20
23
  type: :development
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '4.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '7'
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: hoe
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '3.16'
39
+ version: '3.22'
34
40
  type: :development
35
41
  prerelease: false
36
42
  version_requirements: !ruby/object:Gem::Requirement
37
43
  requirements:
38
44
  - - "~>"
39
45
  - !ruby/object:Gem::Version
40
- version: '3.16'
46
+ version: '3.22'
41
47
  description: merkletree - build your own crypto hash trees; named after Ralph Merkle
42
48
  who patented hash trees in 1979; grow your own money on trees
43
49
  email: wwwmake@googlegroups.com
44
50
  executables: []
45
51
  extensions: []
46
52
  extra_rdoc_files:
47
- - HISTORY.md
48
- - LICENSE.md
53
+ - CHANGELOG.md
49
54
  - Manifest.txt
50
55
  - README.md
51
56
  files:
52
- - HISTORY.md
53
- - LICENSE.md
57
+ - CHANGELOG.md
54
58
  - Manifest.txt
55
59
  - README.md
56
60
  - Rakefile
@@ -60,11 +64,11 @@ files:
60
64
  - test/test_build.rb
61
65
  - test/test_readme.rb
62
66
  - test/test_version.rb
63
- homepage: https://github.com/openblockchains/merkletree.rb
67
+ homepage: https://github.com/rubycoco/blockchain
64
68
  licenses:
65
69
  - Public Domain
66
70
  metadata: {}
67
- post_install_message:
71
+ post_install_message:
68
72
  rdoc_options:
69
73
  - "--main"
70
74
  - README.md
@@ -81,9 +85,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
85
  - !ruby/object:Gem::Version
82
86
  version: '0'
83
87
  requirements: []
84
- rubyforge_project:
85
- rubygems_version: 2.5.2
86
- signing_key:
88
+ rubygems_version: 3.1.4
89
+ signing_key:
87
90
  specification_version: 4
88
91
  summary: merkletree - build your own crypto hash trees; named after Ralph Merkle who
89
92
  patented hash trees in 1979; grow your own money on trees
data/LICENSE.md DELETED
@@ -1,116 +0,0 @@
1
- CC0 1.0 Universal
2
-
3
- Statement of Purpose
4
-
5
- The laws of most jurisdictions throughout the world automatically confer
6
- exclusive Copyright and Related Rights (defined below) upon the creator and
7
- subsequent owner(s) (each and all, an "owner") of an original work of
8
- authorship and/or a database (each, a "Work").
9
-
10
- Certain owners wish to permanently relinquish those rights to a Work for the
11
- purpose of contributing to a commons of creative, cultural and scientific
12
- works ("Commons") that the public can reliably and without fear of later
13
- claims of infringement build upon, modify, incorporate in other works, reuse
14
- and redistribute as freely as possible in any form whatsoever and for any
15
- purposes, including without limitation commercial purposes. These owners may
16
- contribute to the Commons to promote the ideal of a free culture and the
17
- further production of creative, cultural and scientific works, or to gain
18
- reputation or greater distribution for their Work in part through the use and
19
- efforts of others.
20
-
21
- For these and/or other purposes and motivations, and without any expectation
22
- of additional consideration or compensation, the person associating CC0 with a
23
- Work (the "Affirmer"), to the extent that he or she is an owner of Copyright
24
- and Related Rights in the Work, voluntarily elects to apply CC0 to the Work
25
- and publicly distribute the Work under its terms, with knowledge of his or her
26
- Copyright and Related Rights in the Work and the meaning and intended legal
27
- effect of CC0 on those rights.
28
-
29
- 1. Copyright and Related Rights. A Work made available under CC0 may be
30
- protected by copyright and related or neighboring rights ("Copyright and
31
- Related Rights"). Copyright and Related Rights include, but are not limited
32
- to, the following:
33
-
34
- i. the right to reproduce, adapt, distribute, perform, display, communicate,
35
- and translate a Work;
36
-
37
- ii. moral rights retained by the original author(s) and/or performer(s);
38
-
39
- iii. publicity and privacy rights pertaining to a person's image or likeness
40
- depicted in a Work;
41
-
42
- iv. rights protecting against unfair competition in regards to a Work,
43
- subject to the limitations in paragraph 4(a), below;
44
-
45
- v. rights protecting the extraction, dissemination, use and reuse of data in
46
- a Work;
47
-
48
- vi. database rights (such as those arising under Directive 96/9/EC of the
49
- European Parliament and of the Council of 11 March 1996 on the legal
50
- protection of databases, and under any national implementation thereof,
51
- including any amended or successor version of such directive); and
52
-
53
- vii. other similar, equivalent or corresponding rights throughout the world
54
- based on applicable law or treaty, and any national implementations thereof.
55
-
56
- 2. Waiver. To the greatest extent permitted by, but not in contravention of,
57
- applicable law, Affirmer hereby overtly, fully, permanently, irrevocably and
58
- unconditionally waives, abandons, and surrenders all of Affirmer's Copyright
59
- and Related Rights and associated claims and causes of action, whether now
60
- known or unknown (including existing as well as future claims and causes of
61
- action), in the Work (i) in all territories worldwide, (ii) for the maximum
62
- duration provided by applicable law or treaty (including future time
63
- extensions), (iii) in any current or future medium and for any number of
64
- copies, and (iv) for any purpose whatsoever, including without limitation
65
- commercial, advertising or promotional purposes (the "Waiver"). Affirmer makes
66
- the Waiver for the benefit of each member of the public at large and to the
67
- detriment of Affirmer's heirs and successors, fully intending that such Waiver
68
- shall not be subject to revocation, rescission, cancellation, termination, or
69
- any other legal or equitable action to disrupt the quiet enjoyment of the Work
70
- by the public as contemplated by Affirmer's express Statement of Purpose.
71
-
72
- 3. Public License Fallback. Should any part of the Waiver for any reason be
73
- judged legally invalid or ineffective under applicable law, then the Waiver
74
- shall be preserved to the maximum extent permitted taking into account
75
- Affirmer's express Statement of Purpose. In addition, to the extent the Waiver
76
- is so judged Affirmer hereby grants to each affected person a royalty-free,
77
- non transferable, non sublicensable, non exclusive, irrevocable and
78
- unconditional license to exercise Affirmer's Copyright and Related Rights in
79
- the Work (i) in all territories worldwide, (ii) for the maximum duration
80
- provided by applicable law or treaty (including future time extensions), (iii)
81
- in any current or future medium and for any number of copies, and (iv) for any
82
- purpose whatsoever, including without limitation commercial, advertising or
83
- promotional purposes (the "License"). The License shall be deemed effective as
84
- of the date CC0 was applied by Affirmer to the Work. Should any part of the
85
- License for any reason be judged legally invalid or ineffective under
86
- applicable law, such partial invalidity or ineffectiveness shall not
87
- invalidate the remainder of the License, and in such case Affirmer hereby
88
- affirms that he or she will not (i) exercise any of his or her remaining
89
- Copyright and Related Rights in the Work or (ii) assert any associated claims
90
- and causes of action with respect to the Work, in either case contrary to
91
- Affirmer's express Statement of Purpose.
92
-
93
- 4. Limitations and Disclaimers.
94
-
95
- a. No trademark or patent rights held by Affirmer are waived, abandoned,
96
- surrendered, licensed or otherwise affected by this document.
97
-
98
- b. Affirmer offers the Work as-is and makes no representations or warranties
99
- of any kind concerning the Work, express, implied, statutory or otherwise,
100
- including without limitation warranties of title, merchantability, fitness
101
- for a particular purpose, non infringement, or the absence of latent or
102
- other defects, accuracy, or the present or absence of errors, whether or not
103
- discoverable, all to the greatest extent permissible under applicable law.
104
-
105
- c. Affirmer disclaims responsibility for clearing rights of other persons
106
- that may apply to the Work or any use thereof, including without limitation
107
- any person's Copyright and Related Rights in the Work. Further, Affirmer
108
- disclaims responsibility for obtaining any necessary consents, permissions
109
- or other rights required for any use of the Work.
110
-
111
- d. Affirmer understands and acknowledges that Creative Commons is not a
112
- party to this document and has no duty or obligation with respect to this
113
- CC0 or use of the Work.
114
-
115
- For more information, please see
116
- <http://creativecommons.org/publicdomain/zero/1.0/>