bsv-sdk 0.18.0 → 0.18.1

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: 6bb4b97822f38d793a308e9beddc94bd90e64457bda8f1782875ddcd8a1ff1f3
4
- data.tar.gz: 85009a67a04ee1264acd883224ea418ed46558629a18db3d1757486cc544852d
3
+ metadata.gz: 7e425cc46fca3c3db1d2dc79702491600ec302625132ba10c95ee8dee7242ed9
4
+ data.tar.gz: 1839e24be2d7ebea84478b54526f7793839681cd385fb9de962f118826220338
5
5
  SHA512:
6
- metadata.gz: 85e2958f6bb6af774b2ca06e5187bbc1c756546e322430375108617b4675e6e5d5373aa8d93fd4504327d3c48e29507a2caea566d0b9af5e16c3fdd089bc2fbc
7
- data.tar.gz: 56797e445e8996c2a41e85484e49f53b3568eaebeaf01de39a1e919c6949f40b172236ad5bd89fbc77eb9405a532653c9ab1972e696e699d6410e503318360d7
6
+ metadata.gz: 285dd4fc51b19fef84f31071cec373b43c70347de9cd5bf904c17fff65ff1c964b62d49969de79b98caa241198b6e689c7e50551a66aac2c1c593b1b9f491dc9
7
+ data.tar.gz: 3e5536f21302a75992e221967fa5de233cb4200a9efc34cd71b6d892f714955fd2dda73625a998a9943110274d63925e044690a99fe8870ef5a09323d6c1d901
data/CHANGELOG.md CHANGED
@@ -5,6 +5,15 @@ All notable changes to the `bsv-sdk` gem are documented here.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
6
6
  and this gem adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 0.18.1 — 2026-05-09
9
+
10
+ ### Added
11
+ - ARC broadcast accepts hex and binary strings directly, in addition to transaction objects
12
+
13
+ ### Fixed
14
+ - Hex string detection uses content inspection rather than string encoding
15
+ - Stale "Phase B" text removed from Protocols namespace module doc
16
+
8
17
  ## 0.18.0 — 2026-05-09
9
18
 
10
19
  ### Breaking Changes
@@ -68,7 +68,8 @@ module BSV
68
68
  # Broadcast escape hatch: EF format preference, custom headers, rejection
69
69
  # detection, and malformed 2xx detection.
70
70
  #
71
- # @param tx [Transaction] the transaction to broadcast
71
+ # @param tx [#to_ef_hex, #to_hex, String] transaction object, hex string,
72
+ # or binary string
72
73
  # @param wait_for [String, nil] ARC wait condition
73
74
  # @param skip_fee_validation [Boolean, nil]
74
75
  # @param skip_script_validation [Boolean, nil]
@@ -80,7 +81,7 @@ module BSV
80
81
  def call_broadcast(tx, wait_for: nil, skip_fee_validation: nil,
81
82
  skip_script_validation: nil, skip_tx_validation: nil,
82
83
  callback_url: nil, callback_token: nil, callback_batch: nil, **)
83
- hex = ef_hex_with_fallback(tx)
84
+ hex = resolve_tx_hex(tx)
84
85
  body = JSON.generate(rawTx: hex)
85
86
 
86
87
  extra_headers = build_broadcast_headers(
@@ -99,7 +100,7 @@ module BSV
99
100
 
100
101
  # Broadcast-many escape hatch: batch broadcast with per-item rejection detection.
101
102
  #
102
- # @param txs [Array<Transaction>]
103
+ # @param txs [Array<#to_ef_hex, #to_hex, String>]
103
104
  # @param wait_for [String, nil]
104
105
  # @param skip_fee_validation [Boolean, nil]
105
106
  # @param skip_script_validation [Boolean, nil]
@@ -113,7 +114,7 @@ module BSV
113
114
  callback_url: nil, callback_token: nil, callback_batch: nil, **)
114
115
  return Result::Success.new(data: []) if txs.empty?
115
116
 
116
- body = JSON.generate(txs.map { |tx| { rawTx: ef_hex_with_fallback(tx) } })
117
+ body = JSON.generate(txs.map { |tx| { rawTx: resolve_tx_hex(tx) } })
117
118
 
118
119
  extra_headers = build_broadcast_headers(
119
120
  wait_for: wait_for,
@@ -136,10 +137,26 @@ module BSV
136
137
  request
137
138
  end
138
139
 
139
- # Prefer Extended Format hex (BRC-30) so ARC can validate sighashes without
140
- # fetching parent transactions. Falls back to plain raw-tx hex when any input
141
- # lacks source_satoshis / source_locking_script.
142
- def ef_hex_with_fallback(tx)
140
+ # Coerce a transaction input to hex for the ARC JSON body.
141
+ #
142
+ # Accepts (in order of preference):
143
+ # 1. Hex string — pass-through, zero conversion
144
+ # 2. Binary string — convert to hex
145
+ # 3. Transaction object — prefer EF hex (BRC-30), fall back to raw hex
146
+ #
147
+ # Detection uses content, not encoding: a string is hex if it has even
148
+ # length and contains only hex characters. This handles hex strings
149
+ # tagged as ASCII-8BIT (e.g. read from IO in binary mode).
150
+ #
151
+ # @param tx [String, #to_ef_hex, #to_hex] transaction in any supported form
152
+ # @return [String] hex-encoded transaction
153
+ def resolve_tx_hex(tx)
154
+ if tx.is_a?(String)
155
+ return tx if tx.match?(/\A[0-9a-fA-F]*\z/) && tx.length.even?
156
+
157
+ return tx.unpack1('H*')
158
+ end
159
+
143
160
  tx.to_ef_hex
144
161
  rescue ArgumentError => e
145
162
  BSV.logger&.debug { "[ARC] EF serialisation failed: #{e.message} — falling back to raw hex" }
@@ -3,9 +3,8 @@
3
3
  module BSV
4
4
  module Network
5
5
  # Protocols is a namespace module for concrete Protocol subclasses.
6
- #
7
- # Protocol implementations (e.g. ARC, WhatsOnChain adapters built on
8
- # the Protocol base class) will be autoloaded here in Phase B.
6
+ # Each class maps a service's commands to HTTP endpoints: ARC, Chaintracks,
7
+ # JungleBus, Ordinals, TAALBinary, and WoCREST.
9
8
  module Protocols
10
9
  autoload :ARC, 'bsv/network/protocols/arc'
11
10
  autoload :Chaintracks, 'bsv/network/protocols/chaintracks'
data/lib/bsv/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BSV
4
- VERSION = '0.18.0'
4
+ VERSION = '0.18.1'
5
5
  end
@@ -8,15 +8,51 @@ module BSV
8
8
  module Wallet
9
9
  # Minimal cryptographic wallet implementing the BRC-100 interface.
10
10
  #
11
- # ProtoWallet provides signing, encryption, HMAC, and key derivation
12
- # without transactions, storage, or blockchain interaction. It is the
13
- # direct implementation of the BRC-100 crypto methods, not a delegating
14
- # client. This makes it suitable for use in the SDK's Auth module without
15
- # depending on the bsv-wallet gem.
11
+ # ProtoWallet is a direct, in-process implementation of the BRC-100 crypto
12
+ # operations. It requires no external gem, no storage, and no blockchain
13
+ # access making it suitable for use inside the SDK itself (e.g. the Auth
14
+ # module) as well as lightweight applications that need cryptographic
15
+ # operations without full wallet infrastructure.
16
16
  #
17
- # Includes +BSV::Wallet::Interface::BRC100+ methods it supports are
18
- # overridden; unsupported methods (transactions, blockchain, authentication)
19
- # fall through to +NotImplementedError+.
17
+ # == Supported BRC-100 areas
18
+ #
19
+ # - *Public key management* — {#get_public_key}, {#reveal_counterparty_key_linkage},
20
+ # {#reveal_specific_key_linkage}
21
+ # - *Cryptography* — {#encrypt}, {#decrypt}, {#create_hmac}, {#verify_hmac},
22
+ # {#create_signature}, {#verify_signature}
23
+ # - *Certificates (read-only stub)* — {#list_certificates} returns an empty list;
24
+ # {#prove_certificate} raises {UnsupportedActionError}
25
+ #
26
+ # == NOT supported
27
+ #
28
+ # The following BRC-100 areas are not implemented and will raise
29
+ # +NotImplementedError+:
30
+ #
31
+ # - Transactions (+create_action+, +sign_action+, +list_actions+, etc.)
32
+ # - Output management (+list_outputs+, +relinquish_output+, etc.)
33
+ # - Authentication (+authenticated?+, +wait_for_authentication+)
34
+ # - Blockchain / network data (+get_height+, +get_header_for_height+, etc.)
35
+ # - Certificate acquisition / discovery (+acquire_certificate+,
36
+ # +discover_by_identity_key+, etc.)
37
+ #
38
+ # For full wallet functionality, use the +bsv-wallet+ gem. See
39
+ # +docs/sdk/wallet.md+ for usage guidance.
40
+ #
41
+ # == Construction
42
+ #
43
+ # Pass a {BSV::Primitives::PrivateKey} or the special string <tt>'anyone'</tt>.
44
+ # The <tt>'anyone'</tt> variant uses a well-known key (private key = 1) and is
45
+ # suitable for verifying or encrypting data that should be readable by
46
+ # any party — it must not be used where secrecy is required.
47
+ #
48
+ # @example Normal usage
49
+ # wallet = BSV::Wallet::ProtoWallet.new(BSV::Primitives::PrivateKey.generate)
50
+ # sig = wallet.create_signature(protocol_id: [1, 'my-app'], key_id: 'msg-1',
51
+ # data: 'hello'.bytes)
52
+ #
53
+ # @example Anyone wallet
54
+ # wallet = BSV::Wallet::ProtoWallet.new('anyone')
55
+ # pub = wallet.get_public_key(identity_key: true)
20
56
  #
21
57
  class ProtoWallet
22
58
  include Interface::BRC100
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bsv-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.18.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Bettison