bitcoinrb 1.5.0 → 1.7.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.
Files changed (37) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/README.md +7 -5
  4. data/lib/bitcoin/block.rb +27 -0
  5. data/lib/bitcoin/descriptor/addr.rb +31 -0
  6. data/lib/bitcoin/descriptor/checksum.rb +74 -0
  7. data/lib/bitcoin/descriptor/combo.rb +30 -0
  8. data/lib/bitcoin/descriptor/expression.rb +122 -0
  9. data/lib/bitcoin/descriptor/key_expression.rb +30 -0
  10. data/lib/bitcoin/descriptor/multi.rb +49 -0
  11. data/lib/bitcoin/descriptor/multi_a.rb +43 -0
  12. data/lib/bitcoin/descriptor/pk.rb +27 -0
  13. data/lib/bitcoin/descriptor/pkh.rb +15 -0
  14. data/lib/bitcoin/descriptor/raw.rb +32 -0
  15. data/lib/bitcoin/descriptor/raw_tr.rb +20 -0
  16. data/lib/bitcoin/descriptor/script_expression.rb +24 -0
  17. data/lib/bitcoin/descriptor/sh.rb +31 -0
  18. data/lib/bitcoin/descriptor/sorted_multi.rb +15 -0
  19. data/lib/bitcoin/descriptor/sorted_multi_a.rb +15 -0
  20. data/lib/bitcoin/descriptor/tr.rb +91 -0
  21. data/lib/bitcoin/descriptor/wpkh.rb +19 -0
  22. data/lib/bitcoin/descriptor/wsh.rb +30 -0
  23. data/lib/bitcoin/descriptor.rb +186 -100
  24. data/lib/bitcoin/key.rb +1 -1
  25. data/lib/bitcoin/message_sign.rb +2 -1
  26. data/lib/bitcoin/script/script.rb +8 -3
  27. data/lib/bitcoin/script_witness.rb +1 -0
  28. data/lib/bitcoin/secp256k1/native.rb +1 -1
  29. data/lib/bitcoin/silent_payment.rb +5 -0
  30. data/lib/bitcoin/sp/addr.rb +55 -0
  31. data/lib/bitcoin/taproot/custom_depth_builder.rb +64 -0
  32. data/lib/bitcoin/taproot/simple_builder.rb +1 -6
  33. data/lib/bitcoin/taproot.rb +1 -0
  34. data/lib/bitcoin/tx.rb +14 -1
  35. data/lib/bitcoin/version.rb +1 -1
  36. data/lib/bitcoin.rb +1 -0
  37. metadata +23 -2
@@ -0,0 +1,64 @@
1
+ module Bitcoin
2
+ module Taproot
3
+ # A class that takes the script tree configuration as a nested array and constructs the Taproot output.
4
+ # TODO WIP
5
+ class CustomDepthBuilder < SimpleBuilder
6
+
7
+ attr_reader :tree
8
+
9
+ # Constructor
10
+ # @param [String] internal_key Internal public key with hex format.
11
+ # @param [Array] tree Script tree configuration as a nested array.
12
+ # @return [Bitcoin::Taproot::CustomDepthBuilder]
13
+ def initialize(internal_key, tree)
14
+ super(internal_key, [])
15
+ raise ArgumentError, "tree must be an array." unless tree.is_a?(Array)
16
+ raise ArgumentError, "tree must be binary tree." unless tree.length == 2
17
+ tree.each do |item|
18
+ unless item.is_a?(Array) || item.is_a?(Bitcoin::Taproot::LeafNode)
19
+ raise ArgumentError, "tree must consist of either an array or LeafNode."
20
+ end
21
+ raise ArgumentError, "tree must be binary tree." if item.is_a?(Array) && item.length != 2
22
+ end
23
+ @tree = tree
24
+ end
25
+
26
+ def add_leaf(leaf)
27
+ raise NotImplementedError
28
+ end
29
+
30
+ def add_branch(leaf1, leaf2 = nil)
31
+ raise NotImplementedError
32
+ end
33
+
34
+ def control_block(leaf)
35
+ raise NotImplementedError # TODO
36
+ end
37
+
38
+ def inclusion_proof(leaf)
39
+ raise NotImplementedError # TODO
40
+ end
41
+
42
+ private
43
+
44
+ def merkle_root
45
+ build_tree(tree).bth
46
+ end
47
+
48
+ def build_tree(tree)
49
+ left, right = tree
50
+ left_hash = if left.is_a?(Array)
51
+ build_tree(left)
52
+ else
53
+ left
54
+ end
55
+ right_hash = if right.is_a?(Array)
56
+ build_tree(right)
57
+ else
58
+ right
59
+ end
60
+ combine_hash([left_hash, right_hash])
61
+ end
62
+ end
63
+ end
64
+ end
@@ -16,6 +16,7 @@ module Bitcoin
16
16
  # @raise [Bitcoin::Taproot::Builder] +internal_pubkey+ dose not xonly public key or leaf in +leaves+ does not instance of Bitcoin::Taproot::LeafNode.
17
17
  # @return [Bitcoin::Taproot::SimpleBuilder]
18
18
  def initialize(internal_key, leaves = [])
19
+ raise ArgumentError, "Internal public key must be string." unless internal_key.is_a?(String)
19
20
  raise Error, "Internal public key must be #{X_ONLY_PUBKEY_SIZE} bytes" unless internal_key.htb.bytesize == X_ONLY_PUBKEY_SIZE
20
21
  raise Error, 'leaf must be Bitcoin::Taproot::LeafNode object' if leaves.find{ |leaf| !leaf.is_a?(Bitcoin::Taproot::LeafNode)}
21
22
 
@@ -113,12 +114,6 @@ module Bitcoin
113
114
 
114
115
  private
115
116
 
116
- # Compute tweak from script tree.
117
- # @return [String] tweak with binary format.
118
- def tweak
119
- Taproot.tweak(Bitcoin::Key.from_xonly_pubkey(internal_key), merkle_root)
120
- end
121
-
122
117
  # Calculate merkle root from branches.
123
118
  # @return [String] merkle root with hex format.
124
119
  def merkle_root
@@ -6,6 +6,7 @@ module Bitcoin
6
6
  autoload :LeafNode, 'bitcoin/taproot/leaf_node'
7
7
  autoload :ControlBlock, 'bitcoin/taproot/control_block'
8
8
  autoload :SimpleBuilder, 'bitcoin/taproot/simple_builder'
9
+ autoload :CustomDepthBuilder, 'bitcoin/taproot/custom_depth_builder'
9
10
 
10
11
  module_function
11
12
 
data/lib/bitcoin/tx.rb CHANGED
@@ -33,6 +33,19 @@ module Bitcoin
33
33
  alias_method :in, :inputs
34
34
  alias_method :out, :outputs
35
35
 
36
+ # Create coinbase transaction.
37
+ # @param [String] msg Message embedded in coinbase transaction.
38
+ # @param [Bitcoin::Script] script Coinbase transaction scriptPubkey.
39
+ # @param [Integer] rewards Coinbase Transaction Rewards
40
+ # @return [Bitcoin::Tx] Coinbase transaction.
41
+ def self.create_coinbase(msg, script, rewards = 50 * 100000000)
42
+ coinbase = Tx.new
43
+ script_sig = Bitcoin::Script.new << 486604799 << "04" << msg.bth
44
+ coinbase.in << TxIn.new(out_point: OutPoint.create_coinbase_outpoint, script_sig: script_sig)
45
+ coinbase.out << TxOut.new(value: rewards, script_pubkey: script)
46
+ coinbase
47
+ end
48
+
36
49
  def self.parse_from_payload(payload, non_witness: false, strict: false)
37
50
  buf = payload.is_a?(String) ? StringIO.new(payload) : payload
38
51
  tx = new
@@ -111,7 +124,7 @@ module Bitcoin
111
124
  end
112
125
 
113
126
  def witness?
114
- !inputs.find { |i| !i.script_witness.empty? }.nil?
127
+ inputs.any?(&:has_witness?)
115
128
  end
116
129
 
117
130
  def ==(other)
@@ -1,3 +1,3 @@
1
1
  module Bitcoin
2
- VERSION = "1.5.0"
2
+ VERSION = "1.7.0"
3
3
  end
data/lib/bitcoin.rb CHANGED
@@ -61,6 +61,7 @@ module Bitcoin
61
61
  autoload :SigHashGenerator, 'bitcoin/sighash_generator'
62
62
  autoload :MessageSign, 'bitcoin/message_sign'
63
63
  autoload :Taproot, 'bitcoin/taproot'
64
+ autoload :SilentPayment, 'bitcoin/silent_payment'
64
65
  autoload :BIP324, 'bitcoin/bip324'
65
66
 
66
67
  require_relative 'bitcoin/constants'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitcoinrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-14 00:00:00.000000000 Z
11
+ date: 2024-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecdsa_ext
@@ -350,6 +350,24 @@ files:
350
350
  - lib/bitcoin/chainparams/testnet.yml
351
351
  - lib/bitcoin/constants.rb
352
352
  - lib/bitcoin/descriptor.rb
353
+ - lib/bitcoin/descriptor/addr.rb
354
+ - lib/bitcoin/descriptor/checksum.rb
355
+ - lib/bitcoin/descriptor/combo.rb
356
+ - lib/bitcoin/descriptor/expression.rb
357
+ - lib/bitcoin/descriptor/key_expression.rb
358
+ - lib/bitcoin/descriptor/multi.rb
359
+ - lib/bitcoin/descriptor/multi_a.rb
360
+ - lib/bitcoin/descriptor/pk.rb
361
+ - lib/bitcoin/descriptor/pkh.rb
362
+ - lib/bitcoin/descriptor/raw.rb
363
+ - lib/bitcoin/descriptor/raw_tr.rb
364
+ - lib/bitcoin/descriptor/script_expression.rb
365
+ - lib/bitcoin/descriptor/sh.rb
366
+ - lib/bitcoin/descriptor/sorted_multi.rb
367
+ - lib/bitcoin/descriptor/sorted_multi_a.rb
368
+ - lib/bitcoin/descriptor/tr.rb
369
+ - lib/bitcoin/descriptor/wpkh.rb
370
+ - lib/bitcoin/descriptor/wsh.rb
353
371
  - lib/bitcoin/errors.rb
354
372
  - lib/bitcoin/ext.rb
355
373
  - lib/bitcoin/ext/array_ext.rb
@@ -452,10 +470,12 @@ files:
452
470
  - lib/bitcoin/secp256k1/rfc6979.rb
453
471
  - lib/bitcoin/secp256k1/ruby.rb
454
472
  - lib/bitcoin/sighash_generator.rb
473
+ - lib/bitcoin/silent_payment.rb
455
474
  - lib/bitcoin/slip39.rb
456
475
  - lib/bitcoin/slip39/share.rb
457
476
  - lib/bitcoin/slip39/sss.rb
458
477
  - lib/bitcoin/slip39/wordlist/english.txt
478
+ - lib/bitcoin/sp/addr.rb
459
479
  - lib/bitcoin/store.rb
460
480
  - lib/bitcoin/store/chain_entry.rb
461
481
  - lib/bitcoin/store/db.rb
@@ -464,6 +484,7 @@ files:
464
484
  - lib/bitcoin/store/utxo_db.rb
465
485
  - lib/bitcoin/taproot.rb
466
486
  - lib/bitcoin/taproot/control_block.rb
487
+ - lib/bitcoin/taproot/custom_depth_builder.rb
467
488
  - lib/bitcoin/taproot/leaf_node.rb
468
489
  - lib/bitcoin/taproot/simple_builder.rb
469
490
  - lib/bitcoin/tx.rb