bsv-wallet 0.2.0 → 0.2.2

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: 42266cef3c2585982df666f123097ea4fb4edd9f6619aacf37ed50628148ae1f
4
- data.tar.gz: cec92d7893bba6a8b25439f5fd9c4d203ae7fce0cc2f63370adfc1a01d6bed61
3
+ metadata.gz: c1c9a3b59c2d83b14456fcdc7e4eb9f26ad8a5cd4094bc1dd192b26e69903d2b
4
+ data.tar.gz: 3fa4584de7d5f3ce782468aa9243ffc80ddc7106b1da6ed11b7d0a97250c2a29
5
5
  SHA512:
6
- metadata.gz: b45b5c376c8c2b20ec7afffd1f57a15e89d19509ad6afecce8da8f3cdd69b9f7d8af20b5157ca380b8d0a65d9db5dc9a6aed2b8ac1518542775207534e576825
7
- data.tar.gz: aae7eaec036fd2bd620551645e5a111bccfa39ac948ccb6541f24dc5e187acd1c9458a2576b4bca3adc5e31c0ec73d83af270cee8861d940af9952da429fe36c
6
+ metadata.gz: 500bec40cbe5fbf13f325e975522ec467a87d8ddef268a88cc6f4f35f429d75d27b1fd7adbd0f085668d21c79ddef1a19270b5502296e4dcc35fa74031f27b0f
7
+ data.tar.gz: b0dd2838de3f000c5dadd73cb9ce3b6e5575e7c224a4397dbdb0ce2cfd73afdd2cb0366e6805faa035a3375560d3fe2b5ede49a82ae77e494957eb9549cd7727
@@ -91,6 +91,7 @@ module BSV
91
91
 
92
92
  def filter_outputs(query)
93
93
  results = @outputs
94
+ results = results.select { |o| o[:outpoint] == query[:outpoint] } if query[:outpoint]
94
95
  results = results.select { |o| o[:basket] == query[:basket] } if query[:basket]
95
96
  if query[:tags]
96
97
  mode = query[:tag_query_mode] || 'any'
@@ -45,7 +45,7 @@ module BSV
45
45
  # @option args [Boolean] :for_self derive from own identity
46
46
  # @param originator [String, nil] FQDN of the originating application
47
47
  # @return [Hash] { public_key: String } hex-encoded compressed public key
48
- def get_public_key(args, _originator: nil)
48
+ def get_public_key(args, originator: nil)
49
49
  if args[:identity_key]
50
50
  { public_key: @key_deriver.identity_key }
51
51
  else
@@ -69,7 +69,7 @@ module BSV
69
69
  # @option args [String] :counterparty public key hex, 'self', or 'anyone'
70
70
  # @param originator [String, nil] FQDN of the originating application
71
71
  # @return [Hash] { ciphertext: Array<Integer> }
72
- def encrypt(args, _originator: nil)
72
+ def encrypt(args, originator: nil)
73
73
  sym_key = derive_sym_key(args)
74
74
  ciphertext = sym_key.encrypt(bytes_to_string(args[:plaintext]))
75
75
  { ciphertext: string_to_bytes(ciphertext) }
@@ -84,7 +84,7 @@ module BSV
84
84
  # @option args [String] :counterparty public key hex, 'self', or 'anyone'
85
85
  # @param originator [String, nil] FQDN of the originating application
86
86
  # @return [Hash] { plaintext: Array<Integer> }
87
- def decrypt(args, _originator: nil)
87
+ def decrypt(args, originator: nil)
88
88
  sym_key = derive_sym_key(args)
89
89
  plaintext = sym_key.decrypt(bytes_to_string(args[:ciphertext]))
90
90
  { plaintext: string_to_bytes(plaintext) }
@@ -99,7 +99,7 @@ module BSV
99
99
  # @option args [String] :counterparty public key hex, 'self', or 'anyone'
100
100
  # @param originator [String, nil] FQDN of the originating application
101
101
  # @return [Hash] { hmac: Array<Integer> }
102
- def create_hmac(args, _originator: nil)
102
+ def create_hmac(args, originator: nil)
103
103
  sym_key = derive_sym_key(args)
104
104
  hmac = BSV::Primitives::Digest.hmac_sha256(sym_key.to_bytes, bytes_to_string(args[:data]))
105
105
  { hmac: string_to_bytes(hmac) }
@@ -116,7 +116,7 @@ module BSV
116
116
  # @param originator [String, nil] FQDN of the originating application
117
117
  # @return [Hash] { valid: true }
118
118
  # @raise [InvalidHmacError] if the HMAC does not match
119
- def verify_hmac(args, _originator: nil)
119
+ def verify_hmac(args, originator: nil)
120
120
  sym_key = derive_sym_key(args)
121
121
  expected = BSV::Primitives::Digest.hmac_sha256(sym_key.to_bytes, bytes_to_string(args[:data]))
122
122
  provided = bytes_to_string(args[:hmac])
@@ -140,7 +140,7 @@ module BSV
140
140
  # @option args [String] :counterparty public key hex, 'self', or 'anyone'
141
141
  # @param originator [String, nil] FQDN of the originating application
142
142
  # @return [Hash] { signature: Array<Integer> } DER-encoded signature as byte array
143
- def create_signature(args, _originator: nil)
143
+ def create_signature(args, originator: nil)
144
144
  counterparty = args[:counterparty] || 'self'
145
145
  priv_key = @key_deriver.derive_private_key(args[:protocol_id], args[:key_id], counterparty)
146
146
 
@@ -170,7 +170,7 @@ module BSV
170
170
  # @param originator [String, nil] FQDN of the originating application
171
171
  # @return [Hash] { valid: true }
172
172
  # @raise [InvalidSignatureError] if the signature does not verify
173
- def verify_signature(args, _originator: nil)
173
+ def verify_signature(args, originator: nil)
174
174
  counterparty = args[:counterparty] || 'self'
175
175
  for_self = args[:for_self] || false
176
176
 
@@ -208,7 +208,7 @@ module BSV
208
208
  # @param originator [String, nil] FQDN of the originating application
209
209
  # @return [Hash] with :prover, :verifier, :counterparty, :revelation_time,
210
210
  # :encrypted_linkage, :encrypted_linkage_proof
211
- def reveal_counterparty_key_linkage(args, _originator: nil)
211
+ def reveal_counterparty_key_linkage(args, originator: nil)
212
212
  counterparty = args[:counterparty]
213
213
  verifier = args[:verifier]
214
214
 
@@ -270,7 +270,7 @@ module BSV
270
270
  # @param originator [String, nil] FQDN of the originating application
271
271
  # @return [Hash] with :prover, :verifier, :counterparty, :protocol_id, :key_id,
272
272
  # :encrypted_linkage, :encrypted_linkage_proof, :proof_type
273
- def reveal_specific_key_linkage(args, _originator: nil)
273
+ def reveal_specific_key_linkage(args, originator: nil)
274
274
  counterparty = args[:counterparty]
275
275
  verifier = args[:verifier]
276
276
  protocol_id = args[:protocol_id]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module BSV
4
4
  module WalletInterface
5
- VERSION = '0.2.0'
5
+ VERSION = '0.2.2'
6
6
  end
7
7
  end
@@ -483,8 +483,17 @@ module BSV
483
483
  )
484
484
 
485
485
  wire_source(input, txid_hex, output_index, beef) if beef
486
-
487
- input.unlocking_script = BSV::Script::Script.from_hex(spec[:unlocking_script]) if spec[:unlocking_script]
486
+ wire_source_from_storage(input, spec[:outpoint]) if input.source_satoshis.nil? || input.source_locking_script.nil?
487
+
488
+ case spec[:unlocking_script]
489
+ when BSV::Transaction::UnlockingScriptTemplate
490
+ input.unlocking_script_template = spec[:unlocking_script]
491
+ when String
492
+ input.unlocking_script = BSV::Script::Script.from_hex(spec[:unlocking_script])
493
+ when nil then nil
494
+ else
495
+ raise InvalidParameterError.new('unlocking_script', 'a hex String or UnlockingScriptTemplate')
496
+ end
488
497
 
489
498
  tx.add_input(input)
490
499
  end
@@ -504,6 +513,19 @@ module BSV
504
513
  input.source_locking_script = source_tx.outputs[output_index].locking_script
505
514
  end
506
515
 
516
+ def wire_source_from_storage(input, outpoint)
517
+ results = @storage.find_outputs({ outpoint: outpoint, limit: 1 })
518
+ stored = results.first
519
+ return unless stored
520
+
521
+ input.source_satoshis = stored[:satoshis]
522
+ input.source_locking_script = BSV::Script::Script.from_hex(stored[:locking_script])
523
+
524
+ return unless stored[:source_tx_hex]
525
+
526
+ input.source_transaction = BSV::Transaction::Transaction.from_hex(stored[:source_tx_hex])
527
+ end
528
+
507
529
  def build_outputs(tx, outputs)
508
530
  outputs.each do |spec|
509
531
  output = BSV::Transaction::TransactionOutput.new(
@@ -540,6 +562,7 @@ module BSV
540
562
  end
541
563
 
542
564
  def finalize_action(tx, args)
565
+ tx.sign_all if tx.inputs.any?(&:unlocking_script_template)
543
566
  txid = tx.txid_hex
544
567
  status = args.dig(:options, :no_send) ? 'nosend' : 'completed'
545
568
 
@@ -582,6 +605,8 @@ module BSV
582
605
  def store_tracked_outputs(txid, tx, output_specs)
583
606
  return unless output_specs
584
607
 
608
+ tx_hex = tx.to_hex
609
+
585
610
  output_specs.each do |spec|
586
611
  next unless spec[:basket]
587
612
 
@@ -598,7 +623,8 @@ module BSV
598
623
  basket: spec[:basket],
599
624
  tags: spec[:tags] || [],
600
625
  custom_instructions: spec[:custom_instructions],
601
- spendable: true
626
+ spendable: true,
627
+ source_tx_hex: tx_hex
602
628
  })
603
629
  end
604
630
  end
@@ -641,6 +667,7 @@ module BSV
641
667
 
642
668
  def process_internalize_outputs(tx, output_specs)
643
669
  txid = tx.txid_hex
670
+ tx_hex = tx.to_hex
644
671
 
645
672
  output_specs.each do |spec|
646
673
  output_index = spec[:output_index]
@@ -649,16 +676,16 @@ module BSV
649
676
 
650
677
  case spec[:protocol]
651
678
  when 'wallet payment'
652
- internalize_payment(txid, output_index, tx_output, spec[:payment_remittance])
679
+ internalize_payment(txid, output_index, tx_output, spec[:payment_remittance], tx_hex)
653
680
  when 'basket insertion'
654
- internalize_basket(txid, output_index, tx_output, spec[:insertion_remittance])
681
+ internalize_basket(txid, output_index, tx_output, spec[:insertion_remittance], tx_hex)
655
682
  else
656
683
  raise InvalidParameterError.new('protocol', '"wallet payment" or "basket insertion"')
657
684
  end
658
685
  end
659
686
  end
660
687
 
661
- def internalize_payment(txid, output_index, tx_output, remittance)
688
+ def internalize_payment(txid, output_index, tx_output, remittance, tx_hex = nil)
662
689
  unless remittance
663
690
  raise InvalidParameterError.new('payment_remittance',
664
691
  'present for wallet payment protocol')
@@ -686,11 +713,12 @@ module BSV
686
713
  spendable: true,
687
714
  sender_identity_key: sender_key,
688
715
  derivation_prefix: prefix,
689
- derivation_suffix: suffix
716
+ derivation_suffix: suffix,
717
+ source_tx_hex: tx_hex
690
718
  })
691
719
  end
692
720
 
693
- def internalize_basket(txid, output_index, tx_output, remittance)
721
+ def internalize_basket(txid, output_index, tx_output, remittance, tx_hex = nil)
694
722
  unless remittance
695
723
  raise InvalidParameterError.new('insertion_remittance',
696
724
  'present for basket insertion protocol')
@@ -705,7 +733,8 @@ module BSV
705
733
  basket: remittance[:basket],
706
734
  tags: remittance[:tags] || [],
707
735
  custom_instructions: remittance[:custom_instructions],
708
- spendable: true
736
+ spendable: true,
737
+ source_tx_hex: tx_hex
709
738
  })
710
739
  end
711
740
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsv-wallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Bettison
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2026-04-01 00:00:00.000000000 Z
10
+ date: 2026-04-06 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: base64