coin-op 0.1.0 → 0.2.0
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/lib/coin-op/bit/input.rb +2 -2
- data/lib/coin-op/bit/multi_wallet.rb +31 -20
- data/lib/coin-op/bit/transaction.rb +0 -3
- data/lib/coin-op/crypto.rb +4 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2901af471862b2ef2ccdc2ca7fc7192a71400d93
|
4
|
+
data.tar.gz: 538d7b513fc85ef0da0bdb8175886708766e2bd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b19ee9fc1272c34d5380ad87eaa4b32e121d17059b80ba97ff568b4e09debdd881b9e0ec78cd63ca35c118bfee9c3541b3cd4dbfc4e6d7815c8f7a65cf26c686
|
7
|
+
data.tar.gz: 57f64f37f1e18e3e1d8b50f7fa8eda1ee89bb6b3e05af583ff39c45e50d04bae46231bd0857051c68df96b68278e8d21c173ab357e1a0ae25cdd19e974250b59
|
data/lib/coin-op/bit/input.rb
CHANGED
@@ -46,7 +46,7 @@ module CoinOp::Bit
|
|
46
46
|
|
47
47
|
def binary_sig_hash=(blob)
|
48
48
|
@binary_sig_hash = blob
|
49
|
-
@sig_hash =
|
49
|
+
@sig_hash = hex(blob)
|
50
50
|
end
|
51
51
|
|
52
52
|
def script_sig=(blob)
|
@@ -59,7 +59,7 @@ module CoinOp::Bit
|
|
59
59
|
def to_json(*a)
|
60
60
|
{
|
61
61
|
:output => self.output,
|
62
|
-
:signatures => self.signatures.map {|b|
|
62
|
+
:signatures => self.signatures.map {|b| hex(b) },
|
63
63
|
:sig_hash => self.sig_hash || "",
|
64
64
|
:script_sig => self.script_sig || ""
|
65
65
|
}.to_json(*a)
|
@@ -24,6 +24,7 @@ module CoinOp::Bit
|
|
24
24
|
@trees = {}
|
25
25
|
private_trees = options[:private]
|
26
26
|
|
27
|
+
# FIXME: we should allow this.
|
27
28
|
if !private_trees
|
28
29
|
raise "Must supply :private"
|
29
30
|
end
|
@@ -41,6 +42,17 @@ module CoinOp::Bit
|
|
41
42
|
end
|
42
43
|
end
|
43
44
|
|
45
|
+
def get_node(arg)
|
46
|
+
case arg
|
47
|
+
when MoneyTree::Node
|
48
|
+
arg
|
49
|
+
when String
|
50
|
+
MoneyTree::Node.from_serialized_address(arg)
|
51
|
+
else
|
52
|
+
raise "Unusable type: #{node.class}"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
44
56
|
def drop(*names)
|
45
57
|
names = names.map(&:to_sym)
|
46
58
|
options = {:private => {}, :public => {}}
|
@@ -93,9 +105,8 @@ module CoinOp::Bit
|
|
93
105
|
end
|
94
106
|
end
|
95
107
|
|
96
|
-
alias_method :public_address, :public_seed
|
97
108
|
|
98
|
-
def
|
109
|
+
def private_seeds
|
99
110
|
out = {}
|
100
111
|
@private_trees.each do |name, tree|
|
101
112
|
out[name] = self.private_address(name)
|
@@ -103,7 +114,7 @@ module CoinOp::Bit
|
|
103
114
|
out
|
104
115
|
end
|
105
116
|
|
106
|
-
def
|
117
|
+
def public_seeds
|
107
118
|
out = {}
|
108
119
|
@private_trees.each do |name, node|
|
109
120
|
out[name] = node.to_serialized_address
|
@@ -111,16 +122,9 @@ module CoinOp::Bit
|
|
111
122
|
out
|
112
123
|
end
|
113
124
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
arg
|
118
|
-
when String
|
119
|
-
MoneyTree::Node.from_serialized_address(arg)
|
120
|
-
else
|
121
|
-
raise "Unusable type: #{node.class}"
|
122
|
-
end
|
123
|
-
end
|
125
|
+
alias_method :public_address, :public_seed
|
126
|
+
alias_method :private_addresses, :private_seeds
|
127
|
+
alias_method :public_addresses, :public_seeds
|
124
128
|
|
125
129
|
def path(path)
|
126
130
|
options = {
|
@@ -159,6 +163,13 @@ module CoinOp::Bit
|
|
159
163
|
end
|
160
164
|
end
|
161
165
|
|
166
|
+
def set_sig_hashes(transaction)
|
167
|
+
transaction.inputs.each do |input|
|
168
|
+
path = input.output.metadata[:wallet_path]
|
169
|
+
node = self.path(path)
|
170
|
+
input.binary_sig_hash = transaction.sig_hash(input, node.script)
|
171
|
+
end
|
172
|
+
end
|
162
173
|
|
163
174
|
# Takes a Transaction and any number of Arrays of signature dictionaries.
|
164
175
|
# Each sig_dict in an Array corresponds to the Input with the same index.
|
@@ -200,11 +211,8 @@ module CoinOp::Bit
|
|
200
211
|
class MultiNode
|
201
212
|
include CoinOp::Encodings
|
202
213
|
|
203
|
-
attr_reader :path, :keys, :public_keys
|
214
|
+
attr_reader :path, :private, :public, :keys, :public_keys
|
204
215
|
def initialize(options)
|
205
|
-
# m of n
|
206
|
-
# TODO: take @m from the options
|
207
|
-
@m = 2
|
208
216
|
@path = options[:path]
|
209
217
|
|
210
218
|
@keys = {}
|
@@ -222,15 +230,18 @@ module CoinOp::Bit
|
|
222
230
|
end
|
223
231
|
end
|
224
232
|
|
225
|
-
def script
|
233
|
+
def script(m=2)
|
234
|
+
# m of n
|
226
235
|
keys = @public_keys.sort_by {|name, key| name }.map {|name, key| key.pub }
|
227
|
-
Script.new(:public_keys => keys, :needed =>
|
236
|
+
Script.new(:public_keys => keys, :needed => m)
|
228
237
|
end
|
229
238
|
|
230
|
-
def
|
239
|
+
def address
|
231
240
|
self.script.p2sh_address
|
232
241
|
end
|
233
242
|
|
243
|
+
alias_method :p2sh_address, :address
|
244
|
+
|
234
245
|
def p2sh_script
|
235
246
|
Script.new(:address => self.script.p2sh_address)
|
236
247
|
end
|
data/lib/coin-op/crypto.rb
CHANGED
@@ -24,7 +24,7 @@ module CoinOp
|
|
24
24
|
#
|
25
25
|
def self.decrypt(passphrase, hash)
|
26
26
|
salt, nonce, ciphertext =
|
27
|
-
hash.values_at(:salt, :nonce, :ciphertext).map {|s|
|
27
|
+
hash.values_at(:salt, :nonce, :ciphertext).map {|s| decode_hex(s) }
|
28
28
|
box = self.new(passphrase, salt, hash[:iterations])
|
29
29
|
box.decrypt(nonce, ciphertext)
|
30
30
|
end
|
@@ -53,10 +53,10 @@ module CoinOp
|
|
53
53
|
nonce = RbNaCl::Random.random_bytes(RbNaCl::SecretBox.nonce_bytes)
|
54
54
|
ciphertext = @box.encrypt(nonce, plaintext)
|
55
55
|
{
|
56
|
-
:salt =>
|
56
|
+
:salt => hex(@salt),
|
57
57
|
:iterations => @iterations,
|
58
|
-
:nonce =>
|
59
|
-
:ciphertext =>
|
58
|
+
:nonce => hex(nonce),
|
59
|
+
:ciphertext => hex(ciphertext)
|
60
60
|
}
|
61
61
|
end
|
62
62
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coin-op
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew King
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bitcoin-ruby
|