btcruby 1.5 → 1.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b28e8aae378a1e3a925ccb7acdb05b68e2e1987c
4
- data.tar.gz: a134759a151e238011207ea52d7ff0a2bbbbf92e
3
+ metadata.gz: 9bbec90a3ce39cd29196eafbbbfc18e884e8c514
4
+ data.tar.gz: 05eb71dfff15d7b3f4949945623be1dfdebd8855
5
5
  SHA512:
6
- metadata.gz: 3a0b2f8cbfc3cb5fba98cc1844beae30410db5da37fcc2decbe91190c41c571ef9be5c16c86d1e496d6ffa46afbb5d5c92c1c9d4fdb494714bc3c531505dd4c3
7
- data.tar.gz: 5e2edf87ad3704f45acd614a67763325e73aaf85ab61fdc52c3ac6827e09bc7273a5c48a66764fd1b38836b88888f21e3680d8330750ec8c76c7a653a8b3dbfa
6
+ metadata.gz: 9d658653097c2a101c5e42f03b287f2769070a379c6a6e2f1ec244f1782421f9cfcc10bad946e3d9e4a6721bb13f8ef4148a21dd6cc2baac6635115cc96b001d
7
+ data.tar.gz: fc9c6d2bb51365065b558590f0f5a45b8bac0d1ac6df795fd3ce195ee5e4f8af241772d4e34a8634f66826747e08389cb34d497f4a8ccc7ed80194205f2e593f
data/RELEASE_NOTES.md CHANGED
@@ -2,11 +2,18 @@
2
2
  BTCRuby Release Notes
3
3
  =====================
4
4
 
5
+ 1.5.1 (December 30, 2015)
6
+ -----------------------
7
+
8
+ * `BTC::TransactionSignatureChecker` accepts `version` and `amount` to support different hashing schemes (e.g. segwit) and passes them to `BTC::Transaction#signature_hash` function.
9
+
10
+
5
11
  1.5 (November 29, 2015)
6
12
  -----------------------
7
13
 
8
14
  * `BTC::SecretSharing` changes API to support 96-, 104- and 128-bit secrets.
9
15
 
16
+
10
17
  1.4 (November 26, 2015)
11
18
  -----------------------
12
19
 
@@ -33,6 +33,13 @@ module BTC
33
33
  @index == INVALID_INDEX && @transaction_hash == ZERO_HASH256
34
34
  end
35
35
 
36
+ def data
37
+ data = "".b
38
+ data << BTC::Data.ensure_binary_encoding(transaction_hash)
39
+ data << BTC::WireFormat.encode_uint32le(index)
40
+ data
41
+ end
42
+
36
43
  def ==(other)
37
44
  index == other.index &&
38
45
  transaction_hash == other.transaction_hash
@@ -25,7 +25,7 @@ module BTC
25
25
  ecdsa_sig = script_signature[0..-2]
26
26
 
27
27
  key = BTC::Key.new(public_key: public_key)
28
- result = key.verify_ecdsa_signature(ecdsa_sig, hash)
28
+ result = key.verify_ecdsa_signature(ecdsa_sig, signature_hash)
29
29
  return result
30
30
  end
31
31
 
@@ -2,11 +2,16 @@ module BTC
2
2
  class TransactionSignatureChecker
3
3
  include SignatureChecker
4
4
 
5
+ attr_accessor :version
5
6
  attr_accessor :transaction
6
7
  attr_accessor :input_index
7
- def initialize(transaction: nil, input_index: nil)
8
+ attr_accessor :amount
9
+
10
+ def initialize(version: 0, transaction: nil, input_index: nil, amount: 0)
11
+ @version = version
8
12
  @transaction = transaction
9
13
  @input_index = input_index
14
+ @amount = amount
10
15
  end
11
16
 
12
17
  def check_signature(script_signature:nil, public_key:nil, script:nil)
@@ -19,7 +24,13 @@ module BTC
19
24
  ecdsa_sig = script_signature[0..-2]
20
25
 
21
26
  key = BTC::Key.new(public_key: public_key)
22
- hash = @transaction.signature_hash(input_index: @input_index, output_script: script, hash_type: hashtype)
27
+ hash = @transaction.signature_hash(
28
+ input_index: @input_index,
29
+ output_script: script,
30
+ hash_type: hashtype,
31
+ version: version,
32
+ amount: amount
33
+ )
23
34
  result = key.verify_ecdsa_signature(ecdsa_sig, hash)
24
35
  return result
25
36
  rescue BTC::FormatError => e # public key is invalid
data/lib/btcruby/ssss.rb CHANGED
@@ -313,7 +313,8 @@ if $0 == __FILE__
313
313
 
314
314
  begin
315
315
  require_relative 'base58'
316
- payload_length = 13
316
+ payload_length = 14 # 13 + checksum
317
+ #payload_length = 15 # 14 + checksum
317
318
  lengths = {}
318
319
  (0..255).each do |ver|
319
320
  prefixes = []
@@ -332,7 +332,7 @@ module BTC
332
332
  # Hash for signing a transaction.
333
333
  # You should specify an input index, output script of the previous transaction for that input,
334
334
  # and an optional hash type (default is SIGHASH_ALL).
335
- def signature_hash(input_index: nil, output_script: nil, hash_type: BTC::SIGHASH_ALL)
335
+ def signature_hash(input_index: nil, output_script: nil, hash_type: BTC::SIGHASH_ALL, version: 0, amount: 0)
336
336
 
337
337
  raise ArgumentError, "Should specify input_index in Transaction#signature_hash." if !input_index
338
338
  raise ArgumentError, "Should specify output_script in Transaction#signature_hash." if !output_script
@@ -1,3 +1,3 @@
1
1
  module BTC
2
- VERSION = "1.5".freeze
2
+ VERSION = "1.5.1".freeze
3
3
  end
data/spec/ssss_spec.rb CHANGED
@@ -127,9 +127,12 @@ describe BTC::SecretSharing do
127
127
  shares = ssss.split(secret, m, n)
128
128
  hexshares = shares.map{|s| BTC.to_hex(s)}
129
129
  hexshares.must_equal defined_shares
130
- subshares = shares[0...m] # TODO: iterate over various combinations
131
- restored_secret = ssss.restore(subshares)
132
- BTC.to_hex(restored_secret).must_equal hexsecret
130
+ [shares, shares.reverse].each do |list|
131
+ [list[0...m], list[0...m].reverse].each do |subshares|
132
+ restored_secret = ssss.restore(subshares)
133
+ BTC.to_hex(restored_secret).must_equal hexsecret
134
+ end
135
+ end
133
136
  end
134
137
  end
135
138
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: btcruby
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.5'
4
+ version: 1.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleg Andreev
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-11-29 00:00:00.000000000 Z
12
+ date: 2015-12-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ffi