bsv-sdk 0.7.0 → 0.8.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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +406 -146
  3. data/lib/bsv/identity/client.rb +11 -5
  4. data/lib/bsv/overlay/topic_broadcaster.rb +1 -3
  5. data/lib/bsv/primitives/openssl_ec_shim.rb +8 -4
  6. data/lib/bsv/primitives/secp256k1.rb +11 -1
  7. data/lib/bsv/transaction/beef.rb +45 -38
  8. data/lib/bsv/transaction/merkle_path.rb +64 -0
  9. data/lib/bsv/transaction/transaction.rb +3 -2
  10. data/lib/bsv/version.rb +1 -1
  11. metadata +2 -32
  12. data/lib/bsv/attest/configuration.rb +0 -9
  13. data/lib/bsv/attest/response.rb +0 -19
  14. data/lib/bsv/attest/verification_error.rb +0 -7
  15. data/lib/bsv/attest/version.rb +0 -7
  16. data/lib/bsv/attest.rb +0 -71
  17. data/lib/bsv/wallet_interface/chain_provider.rb +0 -37
  18. data/lib/bsv/wallet_interface/errors/invalid_hmac_error.rb +0 -11
  19. data/lib/bsv/wallet_interface/errors/invalid_parameter_error.rb +0 -14
  20. data/lib/bsv/wallet_interface/errors/invalid_signature_error.rb +0 -11
  21. data/lib/bsv/wallet_interface/errors/unsupported_action_error.rb +0 -11
  22. data/lib/bsv/wallet_interface/errors/wallet_error.rb +0 -14
  23. data/lib/bsv/wallet_interface/file_store.rb +0 -222
  24. data/lib/bsv/wallet_interface/interface.rb +0 -384
  25. data/lib/bsv/wallet_interface/key_deriver.rb +0 -144
  26. data/lib/bsv/wallet_interface/local_proof_store.rb +0 -42
  27. data/lib/bsv/wallet_interface/memory_store.rb +0 -149
  28. data/lib/bsv/wallet_interface/null_chain_provider.rb +0 -22
  29. data/lib/bsv/wallet_interface/proof_store.rb +0 -32
  30. data/lib/bsv/wallet_interface/proto_wallet.rb +0 -361
  31. data/lib/bsv/wallet_interface/storage_adapter.rb +0 -71
  32. data/lib/bsv/wallet_interface/validators.rb +0 -126
  33. data/lib/bsv/wallet_interface/version.rb +0 -7
  34. data/lib/bsv/wallet_interface/wallet_client.rb +0 -874
  35. data/lib/bsv/wallet_interface/wire/reader.rb +0 -238
  36. data/lib/bsv/wallet_interface/wire/serializer.rb +0 -1993
  37. data/lib/bsv/wallet_interface/wire/writer.rb +0 -214
  38. data/lib/bsv/wallet_interface/wire.rb +0 -19
  39. data/lib/bsv/wallet_interface.rb +0 -31
  40. data/lib/bsv-attest.rb +0 -4
  41. data/lib/bsv-wallet.rb +0 -4
@@ -1,214 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BSV
4
- module Wallet
5
- module Wire
6
- # Builds a binary byte string using BRC-100 wire protocol encoding conventions.
7
- #
8
- # All multi-byte integers use little-endian order unless stated otherwise.
9
- # VarInts follow Bitcoin encoding; -1 is encoded as the 9-byte MaxUint64 sentinel.
10
- class Writer
11
- # Maximum byte length for a PrivilegedReason string (Int8 length field).
12
- MAX_PRIVILEGED_REASON = 127
13
-
14
- def initialize
15
- @buf = ''.b
16
- end
17
-
18
- # Returns the accumulated binary data.
19
- #
20
- # @return [String] binary string (encoding: ASCII-8BIT)
21
- def to_binary
22
- @buf
23
- end
24
-
25
- # Appends a single unsigned byte (0–255).
26
- #
27
- # @param val [Integer]
28
- def write_byte(val)
29
- @buf << [val & 0xFF].pack('C')
30
- end
31
-
32
- # Appends a signed 8-bit integer (-128–127).
33
- # Negative values are encoded as their two's-complement byte.
34
- #
35
- # @param val [Integer]
36
- def write_int8(val)
37
- @buf << [val].pack('c')
38
- end
39
-
40
- # Appends an unsigned Bitcoin VarInt.
41
- #
42
- # @param val [Integer] non-negative integer
43
- def write_varint(val)
44
- @buf << if val < 0xFD
45
- [val].pack('C')
46
- elsif val <= 0xFFFF
47
- [0xFD, val].pack('Cv')
48
- elsif val <= 0xFFFF_FFFF
49
- [0xFE, val].pack('CV')
50
- else
51
- [0xFF, val].pack('CQ<')
52
- end
53
- end
54
-
55
- # Appends a signed VarInt where -1 is encoded as MaxUint64 (9 bytes: FF * 9).
56
- #
57
- # @param val [Integer] non-negative integer, or -1 to signal absence
58
- def write_signed_varint(val)
59
- if val == -1
60
- @buf << "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF".b
61
- else
62
- write_varint(val)
63
- end
64
- end
65
-
66
- # Appends raw bytes with no length prefix.
67
- #
68
- # @param data [String] binary string
69
- def write_bytes(data)
70
- @buf << data.b
71
- end
72
-
73
- # Appends a VarInt-prefixed byte array.
74
- #
75
- # @param data [String] binary string
76
- def write_byte_array(data)
77
- write_varint(data.bytesize)
78
- write_bytes(data)
79
- end
80
-
81
- # Appends a VarInt-prefixed byte array, or the -1 sentinel if nil.
82
- #
83
- # @param data_or_nil [String, nil]
84
- def write_optional_byte_array(data_or_nil)
85
- if data_or_nil.nil?
86
- write_signed_varint(-1)
87
- else
88
- write_byte_array(data_or_nil)
89
- end
90
- end
91
-
92
- # Appends a VarInt-prefixed UTF-8 string.
93
- #
94
- # @param str [String]
95
- def write_utf8_string(str)
96
- bytes = str.encode('UTF-8').b
97
- write_varint(bytes.bytesize)
98
- write_bytes(bytes)
99
- end
100
-
101
- # Appends a VarInt-prefixed UTF-8 string, or the -1 sentinel if nil.
102
- #
103
- # @param str_or_nil [String, nil]
104
- def write_optional_utf8_string(str_or_nil)
105
- if str_or_nil.nil?
106
- write_signed_varint(-1)
107
- else
108
- write_utf8_string(str_or_nil)
109
- end
110
- end
111
-
112
- # Appends an optional boolean as a signed Int8: 1=true, 0=false, -1=nil.
113
- #
114
- # @param val_or_nil [Boolean, nil]
115
- def write_optional_bool(val_or_nil)
116
- if val_or_nil.nil?
117
- write_int8(-1)
118
- elsif val_or_nil
119
- write_int8(1)
120
- else
121
- write_int8(0)
122
- end
123
- end
124
-
125
- # Appends an outpoint: 32 bytes (txid in display order) + VarInt index.
126
- #
127
- # @param txid_hex [String] 64-character hex txid
128
- # @param index [Integer] output index
129
- def write_outpoint(txid_hex, index)
130
- write_bytes([txid_hex].pack('H*'))
131
- write_varint(index)
132
- end
133
-
134
- # Appends a counterparty value using the first-byte dispatch scheme.
135
- #
136
- # Encoding:
137
- # 'self' → 0x0B (11)
138
- # 'anyone' → 0x0C (12)
139
- # nil → 0x00 (0)
140
- # hex pubkey (33 bytes compressed) → 33 raw bytes
141
- #
142
- # @param val [String, nil] 'self', 'anyone', nil, or 66-char hex pubkey
143
- def write_counterparty(val)
144
- case val
145
- when 'self'
146
- write_byte(11)
147
- when 'anyone'
148
- write_byte(12)
149
- when nil
150
- write_byte(0)
151
- else
152
- write_bytes([val].pack('H*'))
153
- end
154
- end
155
-
156
- # Appends a protocol ID: UInt8 security level + VarInt-prefixed UTF-8 name.
157
- #
158
- # @param protocol_id [Array] [Integer level, String name]
159
- def write_protocol_id(protocol_id)
160
- level, name = protocol_id
161
- write_byte(level)
162
- write_utf8_string(name)
163
- end
164
-
165
- # Appends an optional string array: VarInt count + strings, or -1 if nil.
166
- #
167
- # @param arr_or_nil [Array<String>, nil]
168
- def write_string_array(arr_or_nil)
169
- if arr_or_nil.nil?
170
- write_signed_varint(-1)
171
- else
172
- write_varint(arr_or_nil.length)
173
- arr_or_nil.each { |s| write_utf8_string(s) }
174
- end
175
- end
176
-
177
- # Appends an optional string→string map: VarInt count + key/value pairs, or -1 if nil.
178
- #
179
- # @param hash_or_nil [Hash, nil]
180
- def write_map(hash_or_nil)
181
- if hash_or_nil.nil?
182
- write_signed_varint(-1)
183
- else
184
- write_varint(hash_or_nil.length)
185
- hash_or_nil.each do |key, value|
186
- write_utf8_string(key.to_s)
187
- write_utf8_string(value.to_s)
188
- end
189
- end
190
- end
191
-
192
- # Appends privileged parameters: optional bool + Int8-length reason string.
193
- #
194
- # PrivilegedReason uses Int8 for its length field (max 127 bytes), not VarInt.
195
- # -1 (0xFF) means absent.
196
- #
197
- # @param privileged [Boolean, nil]
198
- # @param privileged_reason [String, nil]
199
- def write_privileged(privileged, privileged_reason)
200
- write_optional_bool(privileged)
201
- if privileged_reason.nil?
202
- write_int8(-1)
203
- else
204
- reason_bytes = privileged_reason.encode('UTF-8').b
205
- raise ArgumentError, 'privileged_reason exceeds 127 bytes' if reason_bytes.bytesize > MAX_PRIVILEGED_REASON
206
-
207
- write_int8(reason_bytes.bytesize)
208
- write_bytes(reason_bytes)
209
- end
210
- end
211
- end
212
- end
213
- end
214
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BSV
4
- module Wallet
5
- # BRC-100 binary wire protocol.
6
- #
7
- # Provides low-level serialisation primitives ({Writer}, {Reader}) and a
8
- # higher-level {Serializer} that encodes/decodes all 28 BRC-100 method calls.
9
- #
10
- # Usage:
11
- # frame = BSV::Wallet::Wire::Serializer.serialize_request(:get_height, {})
12
- # method_name, args, originator = BSV::Wallet::Wire::Serializer.deserialize_request(frame)
13
- module Wire
14
- autoload :Writer, 'bsv/wallet_interface/wire/writer'
15
- autoload :Reader, 'bsv/wallet_interface/wire/reader'
16
- autoload :Serializer, 'bsv/wallet_interface/wire/serializer'
17
- end
18
- end
19
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BSV
4
- module WalletInterface
5
- autoload :VERSION, 'bsv/wallet_interface/version'
6
- end
7
-
8
- module Wallet
9
- # BRC-100 Interface
10
- autoload :Interface, 'bsv/wallet_interface/interface'
11
- autoload :KeyDeriver, 'bsv/wallet_interface/key_deriver'
12
- autoload :ProtoWallet, 'bsv/wallet_interface/proto_wallet'
13
- autoload :Validators, 'bsv/wallet_interface/validators'
14
- autoload :StorageAdapter, 'bsv/wallet_interface/storage_adapter'
15
- autoload :MemoryStore, 'bsv/wallet_interface/memory_store'
16
- autoload :FileStore, 'bsv/wallet_interface/file_store'
17
- autoload :ProofStore, 'bsv/wallet_interface/proof_store'
18
- autoload :LocalProofStore, 'bsv/wallet_interface/local_proof_store'
19
- autoload :ChainProvider, 'bsv/wallet_interface/chain_provider'
20
- autoload :NullChainProvider, 'bsv/wallet_interface/null_chain_provider'
21
- autoload :WalletClient, 'bsv/wallet_interface/wallet_client'
22
- autoload :Wire, 'bsv/wallet_interface/wire'
23
-
24
- # Error classes
25
- autoload :WalletError, 'bsv/wallet_interface/errors/wallet_error'
26
- autoload :InvalidParameterError, 'bsv/wallet_interface/errors/invalid_parameter_error'
27
- autoload :InvalidHmacError, 'bsv/wallet_interface/errors/invalid_hmac_error'
28
- autoload :InvalidSignatureError, 'bsv/wallet_interface/errors/invalid_signature_error'
29
- autoload :UnsupportedActionError, 'bsv/wallet_interface/errors/unsupported_action_error'
30
- end
31
- end
data/lib/bsv-attest.rb DELETED
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bsv-sdk'
4
- require_relative 'bsv/attest'
data/lib/bsv-wallet.rb DELETED
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'bsv-sdk'
4
- require_relative 'bsv/wallet_interface'