Skip to content

Speak the @bsv/sdk 4.1.1 wallet wire and JSON - #20

Merged
rohenaz merged 10 commits into
mainfrom
wallet-ts4-interop
Nov 16, 2026
Merged

rohenaz merged 10 commits into
mainfrom
wallet-ts4-interop

Conversation

@rohenaz

@rohenaz rohenaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Before: the BRC-100 wallet wire and JSON followed Go v1.3.3 rulings, so TS 4.1.1 apps and wallets got errors or wrong values from a Swift wallet (txid byte order, totals, certificate field order, HMAC tags, error frames) and the reverse.

After: the Swift wallet processor and transceiver interoperate with @bsv/sdk 4.1.1 in both directions. A TS oracle with 104 live 4.1.1 cases and the Go oracle both pass.

How: wire and JSON codecs, ProtoWallet and the key deriver follow the TS source; rulings COMP-045/046/048/050 are rewritten (TS wallets and apps are the 1Sat wallet's peers) and COMP-065 covers the HMAC key. A Bun-based TS oracle lives in Tools/Conformance/TSOracle.

Behaviour and API changes

  • WalletListOutputsResult.totalOutputs is UInt64 (also in JSON); balance baskets follow BRC-112.
  • WalletCreateActionResult / WalletSignActionResult may have no txid or transaction.
  • Txids in action results, knownTxids and sendWith are in display order on the wire.
  • WalletWireProcessor.transmit returns an error frame instead of throwing for malformed requests and unknown calls; call 29 gets the exact frame TS uses to fall back to plain calls; false verify results are code-1 frames; error texts match TS.
  • Page limits are enforced as TS does (encode refuses more records than the request's limit; decode stops at it).
  • noSendChange no longer requires noSend, as in TS.
  • Certificate(binary:) reads fields in any order (TS writes localeCompare order) and still rejects duplicates; fieldsNotInCanonicalOrder is no longer thrown.
  • HMACs are created with the minimal-length key like TS; verification accepts the minimal or 32-byte key, so old tags still verify. New tags differ from old Swift tags for about 1 key in 256.
  • listCertificates verifier goes on the wire as 33 raw bytes; JSON tags optional; JSON keyring: {} and an empty keyring read as no keyring.
  • False privileged / forSelf written as absent; discovery seekPermission defaults to true; revealSpecificKeyLinkage accepts self and anyone; remote message limit 4096 bytes; redacting mapper default text "Wallet operation failed".
  • New: WalletWireListOutputsEncoding, listOutputsEncoding: / request: parameters (defaulted), WalletWireDecodedActionRequest.listOutputsEncoding, WalletWireResultRejection, walletIsBalanceBasket(_:), WalletKeyDeriver.resolvedCounterparty(_:).
  • Processor failures are logged with full detail through WalletLog (os Logger, dev.opl.swift-sdk / BSVWallet); the peer gets fixed short text.

Still open, as a follow-up: signing wallet certificates in localeCompare order (Swift still writes byte order; TS reads either).

Testing

swift test in swift:6.1 (Linux) after merging main: 925 tests passed, XCTest 155 passed, 0 failures; only opt-in tests skipped. TS 4.1.1 and Go v1.3.3 oracles: 43 tests passed.

…terparties

createHMAC keys HMAC-SHA256 with the minimal-length X coordinate, as
@bsv/sdk 4.1.1 and earlier TypeScript SDKs do. verifyHMAC also accepts
tags made with the 32-byte padded key, so earlier Swift and Go tags stay
valid. AES-GCM keeps the 32-byte key (COMP-064).

The counterparty linkage proof writes z as 32 bytes, and
revealSpecificKeyLinkage accepts self and anyone and returns the resolved
key.
TypeScript wallets and apps are the 1Sat wallet's peers, so the binary
wallet wire now follows @bsv/sdk 4.1.1 where pinned Go v1.3.3 differs:

- createAction and signAction results use the TypeScript layout with
  display-order txids; the txid and signable transaction may be absent
- list totals count every match and records run to the end of the frame
- listOutputs totalOutputs is UInt64 for BRC-112 balance baskets
- the optional spendable listOutputs extension
- abortAction refusal is error code 8
- false verifications, unknown calls (including the call-29 probe) and
  malformed requests are answered in-band with the TypeScript messages
- maps arrive in any order, omitted booleans and counterparties use the
  TypeScript sentinels, empty list entries have length 0
- discovery seekPermission defaults to true; JSON errors carry code 1
- JSON keyring {} reads as no keyring

Go-oracle tests now record the Go differences instead of pinning them.
Tools/Conformance/TSOracle/generate.sh runs the real @bsv/sdk transceiver
against its own processor with Bun and records every frame. The opt-in
WalletWireTypeScriptOracleTests replays those frames against the Swift
processor and transceiver.
COMP-045, 046, 048 and 050 now say why the wire follows @bsv/sdk 4.1.1 and
what still differs from pinned Go. COMP-064 replaces the HMAC part of
COMP-002.
WalletWireResultRejection gets an errorDescription a wallet can show. The
message keeps the exact @bsv/sdk wire text and description keeps both for
logs.
COMP-064 is taken by the interpreter Chronicle rules ruling.
@bsv/sdk 4.1.1 writes certificate fields sorted with localeCompare
(auth/certificates/Certificate.ts:290), so cardholder comes before
cardNumber. The decoder rejected that as out of order, which lost whole
acquireCertificate, listCertificates and discovery results from TS
wallets. It now reads any order and still rejects a repeated name.
Swift keeps writing byte order.
- Accept createAction noSendChange without noSend, as TS does.
- Keep ABI and certificate errors as they are, so the error frame says
  which value was wrong instead of "unsupported wallet action value".
- Log processor decode and encode failures with full detail
  (dev.opl.swift-sdk, BSVWallet) and send the peer a fixed short text
  for errors the codecs do not describe.
- Refuse list and discovery results longer than the request's limit
  with the TS text, and read certificate pages only up to that limit.
- Store an empty certificate keyring as absent and write flag 0.
- Use the TS wording for false relinquishCertificate and
  waitForAuthentication, page totals, non-UTF-8 originators, a bad
  identityKey flag and a call-29 probe with trailing data.
- Keep the underlying error in resolvedCounterparty.
- Add the review cases to the TS oracle and fixed vectors from it.
# Conflicts:
#	Documentation/Compatibility/Rulings.md
@rohenaz
rohenaz merged commit 0553bac into main Nov 16, 2026
2 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant