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,238 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BSV
4
- module Wallet
5
- module Wire
6
- # Consumes a binary byte string using BRC-100 wire protocol decoding conventions.
7
- #
8
- # All multi-byte integers use little-endian order unless stated otherwise.
9
- # VarInts follow Bitcoin encoding; the 9-byte MaxUint64 sentinel decodes as -1.
10
- class Reader
11
- # The 64-bit sentinel value that encodes -1 in a signed VarInt.
12
- MAX_UINT64 = 0xFFFF_FFFF_FFFF_FFFF
13
-
14
- def initialize(data)
15
- @data = data.b
16
- @offset = 0
17
- end
18
-
19
- # Current read position (bytes consumed so far).
20
- attr_reader :offset
21
-
22
- # Reads a single unsigned byte (0–255).
23
- #
24
- # @return [Integer]
25
- def read_byte
26
- require_bytes(1)
27
- byte = @data.getbyte(@offset)
28
- @offset += 1
29
- byte
30
- end
31
-
32
- # Reads a signed 8-bit integer (-128–127).
33
- #
34
- # @return [Integer]
35
- def read_int8
36
- require_bytes(1)
37
- val = @data.byteslice(@offset, 1).unpack1('c')
38
- @offset += 1
39
- val
40
- end
41
-
42
- # Reads an unsigned Bitcoin VarInt.
43
- #
44
- # @return [Integer]
45
- def read_varint
46
- require_bytes(1)
47
- first = @data.getbyte(@offset)
48
-
49
- case first
50
- when 0..0xFC
51
- @offset += 1
52
- first
53
- when 0xFD
54
- require_bytes(3)
55
- val = @data.byteslice(@offset + 1, 2).unpack1('v')
56
- @offset += 3
57
- val
58
- when 0xFE
59
- require_bytes(5)
60
- val = @data.byteslice(@offset + 1, 4).unpack1('V')
61
- @offset += 5
62
- val
63
- else # 0xFF
64
- require_bytes(9)
65
- val = @data.byteslice(@offset + 1, 8).unpack1('Q<')
66
- @offset += 9
67
- val
68
- end
69
- end
70
-
71
- # Reads a signed VarInt, returning -1 for the MaxUint64 sentinel.
72
- #
73
- # @return [Integer] non-negative value or -1
74
- def read_signed_varint
75
- val = read_varint
76
- val == MAX_UINT64 ? -1 : val
77
- end
78
-
79
- # Reads exactly n raw bytes.
80
- #
81
- # @param n [Integer]
82
- # @return [String] binary string
83
- def read_bytes(n)
84
- require_bytes(n)
85
- slice = @data.byteslice(@offset, n)
86
- @offset += n
87
- slice
88
- end
89
-
90
- # Reads all remaining bytes from the current offset.
91
- #
92
- # @return [String] binary string
93
- def read_remaining
94
- slice = @data.byteslice(@offset, @data.bytesize - @offset) || ''.b
95
- @offset = @data.bytesize
96
- slice
97
- end
98
-
99
- # Reads a VarInt-prefixed byte array.
100
- #
101
- # @return [String] binary string
102
- def read_byte_array
103
- len = read_varint
104
- read_bytes(len)
105
- end
106
-
107
- # Reads an optional VarInt-prefixed byte array; returns nil for the -1 sentinel.
108
- #
109
- # @return [String, nil]
110
- def read_optional_byte_array
111
- len = read_signed_varint
112
- return nil if len == -1
113
-
114
- read_bytes(len)
115
- end
116
-
117
- # Reads a VarInt-prefixed UTF-8 string.
118
- #
119
- # @return [String]
120
- def read_utf8_string
121
- len = read_varint
122
- read_bytes(len).force_encoding('UTF-8')
123
- end
124
-
125
- # Reads an optional VarInt-prefixed UTF-8 string; returns nil for the -1 sentinel.
126
- #
127
- # @return [String, nil]
128
- def read_optional_utf8_string
129
- len = read_signed_varint
130
- return nil if len == -1
131
-
132
- read_bytes(len).force_encoding('UTF-8')
133
- end
134
-
135
- # Reads a signed Int8 optional boolean: 1=true, 0=false, -1=nil.
136
- #
137
- # @return [Boolean, nil]
138
- def read_optional_bool
139
- val = read_int8
140
- return nil if val == -1
141
-
142
- val == 1
143
- end
144
-
145
- # Reads an outpoint: 32 bytes (txid hex in display order) + VarInt index.
146
- #
147
- # @return [Array(String, Integer)] [txid_hex, index]
148
- def read_outpoint
149
- txid_bytes = read_bytes(32)
150
- txid_hex = txid_bytes.unpack1('H*')
151
- index = read_varint
152
- [txid_hex, index]
153
- end
154
-
155
- # Reads a counterparty value using the first-byte dispatch scheme.
156
- #
157
- # @return [String, nil] 'self', 'anyone', nil, or 66-char hex pubkey
158
- def read_counterparty
159
- flag = read_byte
160
- case flag
161
- when 11
162
- 'self'
163
- when 12
164
- 'anyone'
165
- when 0
166
- nil
167
- else
168
- # First byte is part of the 33-byte compressed pubkey; read 32 more
169
- remaining = read_bytes(32)
170
- ([flag].pack('C') + remaining).unpack1('H*')
171
- end
172
- end
173
-
174
- # Reads a protocol ID: UInt8 security level + VarInt-prefixed UTF-8 name.
175
- #
176
- # @return [Array(Integer, String)] [level, name]
177
- def read_protocol_id
178
- level = read_byte
179
- name = read_utf8_string
180
- [level, name]
181
- end
182
-
183
- # Reads an optional string array: VarInt count + strings, or nil for the -1 sentinel.
184
- #
185
- # @return [Array<String>, nil]
186
- def read_string_array
187
- count = read_signed_varint
188
- return nil if count == -1
189
-
190
- count.times.map { read_utf8_string }
191
- end
192
-
193
- # Reads an optional string→string map: VarInt count + key/value pairs, or nil.
194
- #
195
- # @return [Hash, nil]
196
- def read_map
197
- count = read_signed_varint
198
- return nil if count == -1
199
-
200
- count.times.each_with_object({}) do |_, hash|
201
- key = read_utf8_string
202
- val = read_utf8_string
203
- hash[key] = val
204
- end
205
- end
206
-
207
- # Reads privileged parameters: optional bool + Int8-length reason string.
208
- #
209
- # @return [Array(Boolean|nil, String|nil)] [privileged, privileged_reason]
210
- def read_privileged
211
- privileged = read_optional_bool
212
- reason_len = read_int8
213
- privileged_reason = if reason_len == -1
214
- nil
215
- elsif reason_len.negative?
216
- raise ArgumentError, "invalid privileged_reason length: #{reason_len}"
217
- else
218
- read_bytes(reason_len).force_encoding('UTF-8')
219
- end
220
- [privileged, privileged_reason]
221
- end
222
-
223
- private
224
-
225
- def require_bytes(n)
226
- raise ArgumentError, "negative byte count: #{n}" if n.negative?
227
-
228
- remaining = @data.bytesize - @offset
229
- return if remaining >= n
230
-
231
- raise ArgumentError,
232
- "truncated wire data: need #{n} bytes at offset #{@offset}, " \
233
- "got #{remaining}"
234
- end
235
- end
236
- end
237
- end
238
- end