bitcoinrb 1.3.0 → 1.4.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 23f677d00426b94e0bdcee887901bb1e89a98c65ae61b0a025c7d95467dcb484
4
- data.tar.gz: 7426638ec33999d466026a09a91517fe698adc0a55f32db6d416dc3f4ad6a386
3
+ metadata.gz: 544382f715d87eb79e185e310c827b2349c0af75c1bd89887a653510e226cd1f
4
+ data.tar.gz: c807d0965da7c06f71b248d5a543ccfff2375d702a6ab4db70698c4be245720d
5
5
  SHA512:
6
- metadata.gz: 960aada8b3db4c610a2b206254f878af9c149f81ce42a53a2ebe8441e0a5179964a9a505807ae2b7519349c4a48125397acb20b412cfb84ea59d58957acd84e4
7
- data.tar.gz: 493c6e06d7fb686dda65fd4bc4075e3716004427beab0cce9e040060711ad4a7197d0fdece2838d130ed6b1b64cdc94a37957a8354d7629bf9bd68fc02d326e4
6
+ metadata.gz: 22ea36535fb045c35d28809f87c60f4451e2d37801e7a231772068c268d6e58cdeb086456ffc649091a5a28a82815af77f6d35ef286a7a101e53fa3f97e55a9a
7
+ data.tar.gz: 7ca7b637b77bdde57d2af3faf056184397b1d87fd98dd5c46933dfb40e716d5bf8ef56890691771b97d8e66dde1c9684cb1d03e9f74f99d4f8b5bbaeb6a37e2c
data/bitcoinrb.gemspec CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  spec.add_runtime_dependency 'ecdsa_ext', '~> 0.5.0'
24
24
  spec.add_runtime_dependency 'eventmachine'
25
- spec.add_runtime_dependency 'murmurhash3'
25
+ spec.add_runtime_dependency 'murmurhash3', '~> 0.1.7'
26
26
  spec.add_runtime_dependency 'bech32', '>= 1.3.0'
27
27
  spec.add_runtime_dependency 'daemon-spawn'
28
28
  spec.add_runtime_dependency 'thor'
@@ -31,7 +31,6 @@ Gem::Specification.new do |spec|
31
31
  spec.add_runtime_dependency 'eventmachine_httpserver'
32
32
  spec.add_runtime_dependency 'iniparse'
33
33
  spec.add_runtime_dependency 'siphash'
34
- spec.add_runtime_dependency 'protobuf', '3.8.5'
35
34
  spec.add_runtime_dependency 'json_pure', '>= 2.3.1'
36
35
  spec.add_runtime_dependency 'bip-schnorr', '>= 0.5.0'
37
36
  spec.add_runtime_dependency 'base32', '>= 0.3.4'
data/lib/bitcoin/key.rb CHANGED
@@ -52,7 +52,7 @@ module Bitcoin
52
52
 
53
53
  # generate key pair
54
54
  def self.generate(key_type = TYPES[:compressed])
55
- priv_key, pubkey = Bitcoin.secp_impl.generate_key_pair
55
+ priv_key, pubkey = Bitcoin.secp_impl.generate_key_pair(compressed: key_type != TYPES[:uncompressed])
56
56
  new(priv_key: priv_key, pubkey: pubkey, key_type: key_type)
57
57
  end
58
58
 
@@ -261,6 +261,12 @@ module Bitcoin
261
261
  pubkey[2..65]
262
262
  end
263
263
 
264
+ # Convert this key to decompress key.
265
+ # @return [String] decompress public key with hex format.
266
+ def decompress_pubkey
267
+ pubkey.htb.bytesize == PUBLIC_KEY_SIZE ? pubkey : to_point.to_hex(false)
268
+ end
269
+
264
270
  # check +pubkey+ (hex) is compress or uncompress pubkey.
265
271
  def self.compress_or_uncompress_pubkey?(pubkey)
266
272
  p = pubkey.htb
@@ -233,11 +233,28 @@ module Bitcoin
233
233
  OP_HASH160 == chunks[0].ord && OP_EQUAL == chunks[2].ord && chunks[1].bytesize == 21
234
234
  end
235
235
 
236
+ # Check whether this script is a P2PK format script.
237
+ # @return [Boolean] if P2PK return true, otherwise false
238
+ def p2pk?
239
+ return false unless chunks.size == 2
240
+ return false unless chunks[0].pushdata?
241
+ key_type = chunks[0].pushed_data[0].ord
242
+ case key_type
243
+ when 0x02, 0x03
244
+ return false unless chunks[0].pushed_data.bytesize == 33
245
+ when 0x04
246
+ return false unless chunks[0].pushed_data.bytesize == 65
247
+ else
248
+ return false
249
+ end
250
+ chunks[1].ord == OP_CHECKSIG
251
+ end
252
+
236
253
  def multisig?
237
254
  return false if chunks.size < 4 || chunks.last.ord != OP_CHECKMULTISIG
238
255
  pubkey_count = Opcodes.opcode_to_small_int(chunks[-2].opcode)
239
256
  sig_count = Opcodes.opcode_to_small_int(chunks[0].opcode)
240
- return false unless pubkey_count || sig_count
257
+ return false if pubkey_count.nil? || sig_count.nil?
241
258
  sig_count <= pubkey_count
242
259
  end
243
260
 
@@ -1,3 +1,3 @@
1
1
  module Bitcoin
2
- VERSION = "1.3.0"
2
+ VERSION = "1.4.0"
3
3
  end
data/lib/bitcoin.rb CHANGED
@@ -46,7 +46,6 @@ module Bitcoin
46
46
  autoload :RPC, 'bitcoin/rpc'
47
47
  autoload :Wallet, 'bitcoin/wallet'
48
48
  autoload :BloomFilter, 'bitcoin/bloom_filter'
49
- autoload :Payments, 'bitcoin/payments'
50
49
  autoload :PSBT, 'bitcoin/psbt'
51
50
  autoload :GCSFilter, 'bitcoin/gcs_filter'
52
51
  autoload :BlockFilter, 'bitcoin/block_filter'
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.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - azuchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-07 00:00:00.000000000 Z
11
+ date: 2023-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ecdsa_ext
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: murmurhash3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.1.7
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.1.7
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bech32
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -164,20 +164,6 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: protobuf
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - '='
172
- - !ruby/object:Gem::Version
173
- version: 3.8.5
174
- type: :runtime
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - '='
179
- - !ruby/object:Gem::Version
180
- version: 3.8.5
181
167
  - !ruby/object:Gem::Dependency
182
168
  name: json_pure
183
169
  requirement: !ruby/object:Gem::Requirement
@@ -439,13 +425,6 @@ files:
439
425
  - lib/bitcoin/opcodes.rb
440
426
  - lib/bitcoin/out_point.rb
441
427
  - lib/bitcoin/payment_code.rb
442
- - lib/bitcoin/payments.rb
443
- - lib/bitcoin/payments/output.pb.rb
444
- - lib/bitcoin/payments/payment.pb.rb
445
- - lib/bitcoin/payments/payment_ack.pb.rb
446
- - lib/bitcoin/payments/payment_details.pb.rb
447
- - lib/bitcoin/payments/payment_request.pb.rb
448
- - lib/bitcoin/payments/x509_certificates.pb.rb
449
428
  - lib/bitcoin/psbt.rb
450
429
  - lib/bitcoin/psbt/hd_key_path.rb
451
430
  - lib/bitcoin/psbt/input.rb
@@ -1,20 +0,0 @@
1
- module Bitcoin
2
- module Payments
3
-
4
- # https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki#Output
5
- class Output < Protobuf::Message
6
-
7
- optional :uint64, :amount, 1, {default: 0}
8
-
9
- required :bytes, :script, 2
10
-
11
- # convert to TxOut object.
12
- # @return [Bitcoin::TxOut]
13
- def to_tx_out
14
- Bitcoin::TxOut.new(value: amount, script_pubkey: Bitcoin::Script.parse_from_payload(script))
15
- end
16
-
17
- end
18
-
19
- end
20
- end
@@ -1,26 +0,0 @@
1
- module Bitcoin
2
- module Payments
3
-
4
- # https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki#Payment
5
- class Payment < Protobuf::Message
6
-
7
- optional :bytes, :merchant_data, 1
8
-
9
- repeated :bytes, :transactions, 2
10
-
11
- repeated Bitcoin::Payments::Output, :refund_to, 3
12
-
13
- optional :string, :memo, 4
14
-
15
- def self.parse_from_payload(payload)
16
- decode(payload)
17
- end
18
-
19
- def transactions
20
- @values[:transactions].map{|raw_tx|Bitcoin::Tx.parse_from_payload(raw_tx, strict: true)}
21
- end
22
-
23
- end
24
-
25
- end
26
- end
@@ -1,17 +0,0 @@
1
- module Bitcoin
2
- module Payments
3
-
4
- # https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki#PaymentACK
5
- class PaymentACK < Protobuf::Message
6
-
7
- required Bitcoin::Payments::Payment, :payment, 1
8
-
9
- optional :string, :memo, 2
10
-
11
- def self.parse_from_payload(payload)
12
- decode(payload)
13
- end
14
- end
15
-
16
- end
17
- end
@@ -1,24 +0,0 @@
1
- module Bitcoin
2
- module Payments
3
-
4
- # https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki#PaymentDetailsPaymentRequest
5
- class PaymentDetails < Protobuf::Message
6
-
7
- optional :string, :network, 1, {default: 'main'}
8
-
9
- repeated Bitcoin::Payments::Output, :outputs, 2
10
-
11
- required :uint64, :time, 3
12
-
13
- optional :uint64, :expires, 4
14
-
15
- optional :string, :memo, 5
16
-
17
- optional :string, :payment_url, 6
18
-
19
- optional :bytes, :merchant_data, 7
20
-
21
- end
22
-
23
- end
24
- end
@@ -1,79 +0,0 @@
1
- module Bitcoin
2
- module Payments
3
-
4
- # https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki#PaymentDetailsPaymentRequest
5
- class PaymentRequest < Protobuf::Message
6
-
7
- optional :uint32, :payment_details_version, 1, {default: 1}
8
-
9
- optional :string, :pki_type, 2, {default: 'none'}
10
-
11
- optional :bytes, :pki_data, 3
12
-
13
- required :bytes, :serialized_payment_details, 4
14
-
15
- optional :bytes, :signature, 5
16
-
17
- def self.parse_from_payload(payload)
18
- self.decode(payload)
19
- end
20
-
21
- # verify +pki_data+.
22
- # @return [Struct] pki information.
23
- def verify_pki_data
24
- d = Struct.new(:display_name, :merchant_sign_key, :root_auth, :root_auth_name)
25
- d
26
- end
27
-
28
- # get payment details
29
- # @return [Bitcoin::Payments:PaymentDetails]
30
- def details
31
- PaymentDetails.decode(serialized_payment_details)
32
- end
33
-
34
- # get certificates
35
- # @return [Array[OpenSSL::X509::Certificate]]
36
- def certs
37
- return [] unless has_pki?
38
- X509Certificates.decode(pki_data).certs
39
- end
40
-
41
- # whether exist +pki_data+.
42
- def has_pki?
43
- pki_type != 'none'
44
- end
45
-
46
- # verify signature.
47
- def valid_sig?
48
- return false unless has_pki?
49
- digest = case pki_type
50
- when 'x509+sha256'
51
- OpenSSL::Digest::SHA256.new
52
- when 'x509+sha1'
53
- OpenSSL::Digest::SHA1.new
54
- else
55
- raise "pki_type: #{pki_type} is invalid type."
56
- end
57
- certs.first.public_key.verify(digest, signature, sig_message)
58
- end
59
-
60
- # verify expire time for payment request.
61
- def valid_time?
62
- expires = details.expires
63
- return true if expires == 0
64
- Time.now.to_i <= expires
65
- end
66
-
67
- private
68
-
69
- # Generate data to be signed
70
- def sig_message
71
- PaymentRequest.new(payment_details_version: payment_details_version,
72
- pki_type: pki_type, pki_data: pki_data, signature: '',
73
- serialized_payment_details: serialized_payment_details).encode
74
- end
75
-
76
- end
77
-
78
- end
79
- end
@@ -1,18 +0,0 @@
1
- module Bitcoin
2
- module Payments
3
-
4
- # https://github.com/bitcoin/bips/blob/master/bip-0070.mediawiki#Certificates
5
- class X509Certificates < Protobuf::Message
6
-
7
- repeated :bytes, :certificate, 1
8
-
9
- # get certificates
10
- # @return [Array[OpenSSL::X509::Certificate]]
11
- def certs
12
- certificate.map{|v|OpenSSL::X509::Certificate.new(v)}
13
- end
14
-
15
- end
16
-
17
- end
18
- end
@@ -1,14 +0,0 @@
1
- require 'protobuf'
2
-
3
- module Bitcoin
4
- module Payments
5
-
6
- autoload :Output, 'bitcoin/payments/output.pb'
7
- autoload :Payment, 'bitcoin/payments/payment.pb'
8
- autoload :PaymentACK, 'bitcoin/payments/payment_ack.pb'
9
- autoload :PaymentDetails, 'bitcoin/payments/payment_details.pb'
10
- autoload :PaymentRequest, 'bitcoin/payments/payment_request.pb'
11
- autoload :X509Certificates, 'bitcoin/payments/x509_certificates.pb'
12
-
13
- end
14
- end