Skip to content
Merged
2 changes: 1 addition & 1 deletion Documentation/Compatibility/FixtureSources.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ manifest fragment. Their provenance:
| Source | `ts-stack` repository, `packages/sdk`, `@bsv/sdk` 4.1.1 |
| Revision | `3b1abc5691c0848eb00eaf5e8f018e8a7a26d5f1` |
| License | Apache-2.0, from relicensing commit `4760b26d0` (2026-11-11), an ancestor of the revision; NOTICE "Copyright 2020-2026 BSV Association" |
| Generator | `gen.ts`, `det.ts`, `toswift.py` and `collate-vec.ts` in [TypeScriptAuthVectors.md](TypeScriptAuthVectors.md), run with Bun 1.4.4; the collation output was also checked with Node 22.23.4 |
| Generator | `gen.ts`, `det.ts`, `toswift.py`, `collate-vec.ts`, `certorder-vec.ts` and `certwire-vec.ts` in [TypeScriptAuthVectors.md](TypeScriptAuthVectors.md), run with Bun 1.4.4; the collation output was also checked with Node 22.23.4 |
| Inputs | Chosen in this repository: private keys 3, 7 and 11, a SHA-256 counter random stream, certificate fields and request targets |
| Transformation | Program output written verbatim into Swift string literals by `toswift.py`; no TypeScript source text is copied |

Expand Down
4 changes: 2 additions & 2 deletions Documentation/Compatibility/GoSDK-v1.3.3.md
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ maps that Swift writes UTF-8-byte-sorted and reads in any order (as
`@bsv/sdk` 4.1.1 writes them), and exact keyring presence. `nil` keyring emits `00`;
a nonempty keyring emits `01` and its map. An empty keyring is stored as `nil`
and emits `00`, as `@bsv/sdk` 4.1.1 writes it. Certificate binary fields are
read in any order (TypeScript writes `localeCompare` order) and written in
byte order.
read in any order and written in `localeCompare` order, as `@bsv/sdk` 4.1.1
writes and signs them; the pinned Go SDK writes byte order (COMP-041).
The Swift codec supports bounded multi-certificate discovery through the
intended nested grammar. Live-Go parity uses zero or one item, and the safe Go
adapter rejects multiple items before the pinned identity-certificate reader
Expand Down
2 changes: 1 addition & 1 deletion Documentation/Compatibility/Rulings.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ behind the general rule.
| COMP-038 | Go wallet request structs encode zero-value artifacts: an omitted or JSON `null` counterparty means an operation-specific default, and an identity-key request may carry `protocolID: [0, ""]`. Treating every `null` as absence would also hide malformed known fields. | Swift accepts missing or `null` counterparty only at the flattened request field and maps it to that operation's `.self` or `.anyone` default. It accepts the exact zero protocol tuple only with `identityKey: true` and no contradictory fields. Canonical output emits the explicit counterparty or only `identityKey: true`; `null` for other known fields is rejected. | This imports Go-generated requests without making the typed JSON model broadly nullable or preserving meaningless zero fields. Tests cover each operation's default, canonical re-encoding, the exact identity artifact, contradictions, and rejected known-field nulls. |
| COMP-039 | Go auto-detects Extended Format from the bytes following a transaction version, which makes a valid raw zero-input transaction whose locktime begins with the marker byte sequence ambiguous. BRC-128 prose also shows one extra zero while its table and Go use the six-byte `00 00 00 00 00 EF` marker. | Swift requires callers to select `.raw` or `.extended`, emits and accepts the six-byte marker, and never auto-detects. Extended source amounts remain the eight-byte values selected by COMP-003. | Explicit selection preserves every raw transaction byte string and transaction ID while retaining canonical Go-compatible Extended Format. Tests cover the raw collision, literal marker mismatch/truncation, eight-byte amounts, canonical and permissive CompactSize policies, and bidirectional pinned-Go encoding. |
| COMP-040 | An ARC POST can reach the provider before the client receives or validates its response. Official ARC submission success requires `status`, `title`, `timestamp`, `txid`, and `txStatus`. Status lookup success requires `timestamp`, `txid`, and `txStatus`, but it does not require `status` or `title`. A redirect, oversized response, malformed semantic field, or wrong transaction ID does not prove rejection. | Swift never retries an ARC POST. It validates operation-specific fields without removing control or format characters from semantic values. It returns explicit rejection only for a valid matching ARC rejection or a documented ARC validation status. Every other response failure after POST begins returns `uncertainDelivery` with the local transaction ID and a typed cause. | This prevents unsafe automatic resubmission and prevents malformed text from becoming a valid status or proof field. Tests cover preflight failure with zero POSTs, cancellation, timeout, transport loss, redirects, response limits, malformed responses, wrong transaction IDs, official response shapes, semantic-field injection, and explicit rejection. |
| COMP-041 | BRC-52 and Go use display-order revocation transaction IDs. Go also accepts or produces some values that do not satisfy one strict bounded certificate policy. JSON object keys use Unicode string equality. The Go SDK orders binary certificate fields by raw UTF-8 bytes; `@bsv/sdk` 4.1.1 signs and verifies them in JavaScript `localeCompare` order (`Certificate.ts:290`), so a certificate with field names such as `Zip` and `age` signed by one fails to verify in the other. | Swift uses display-order revocation transaction IDs, canonical Base64, canonical CompactSize, strict complete DER, low-S verification, and explicit size limits. `CertificateEngine.issue` signs the fields in `localeCompare` order, using the ICU root collation that Node and Bun use, which `LocaleCompareOrder` reproduces exactly for printable ASCII. `CertificateEngine.issue` refuses field names outside printable ASCII with `CertificateFieldNameError.nonASCII`, because ICU orders accented letters among ASCII ones and ignores control characters, so the order TypeScript verifies could not be predicted. BRC-103 exchange and `CertificateEngine` accept a signature over either the `localeCompare` order or the UTF-8 byte order. The `BSVWallet` binary codec writes raw UTF-8 field-name order and reads fields in any order with no repeated name (COMP-048); `Certificate.verifySignature` still uses byte order. It rejects byte-distinct field names that are canonically equivalent in Unicode so JSON output cannot silently replace a signed field. Certificate verification is cryptographic only. The caller must check the revocation output before it trusts a certificate. | Canonical values stay interoperable with both SDKs; certificates Swift issues verify in TypeScript, and Go and earlier Swift certificates still verify. Strict parsing prevents ambiguous fields, trailing data, hidden signature bytes, and lossy JSON conversion. Tests cover binary and JSON boundaries, Unicode-equivalent names, the order against Bun for all printable ASCII pairs, a TypeScript-signed mixed-case certificate, both signature orders, signature binding, field encryption, verifier projection, all-or-nothing failure, secret redaction, and refusal of non-ASCII names. Certificates with non-ASCII names signed elsewhere are still verified in both orders, and TypeScript hosts with a non-English default locale may order names differently. |
| COMP-041 | BRC-52 and Go use display-order revocation transaction IDs. Go also accepts or produces some values that do not satisfy one strict bounded certificate policy. JSON object keys use Unicode string equality. The Go SDK orders binary certificate fields by raw UTF-8 bytes; `@bsv/sdk` 4.1.1 writes, signs and verifies them in JavaScript `localeCompare` order (`auth/certificates/Certificate.ts:290`, `:437-458`, `:473`), so a certificate with field names such as `Zip` and `age`, `a_1` and `a1`, or `émile` and `zip` signed by one fails to verify in the other. | Swift uses display-order revocation transaction IDs, canonical Base64, canonical CompactSize, strict complete DER, low-S verification, and explicit size limits. `Certificate.binary` writes the fields in `localeCompare` order on an `en-US` host, the untailored ICU root collation, and `Certificate.signed` and `CertificateEngine.issue` sign that binary. TypeScript takes the order from the host's default locale (`Certificate.ts:287-290` calls it host-locale order): Bun always resolves `en-US`, but Node reads `LC_ALL` or `LANG`, so under `LC_ALL=da_DK.UTF-8` Node 22 sorts `email Email id ID aa z` as `Email email ID id z aa`, and under `cs_CZ` `ch` sorts after `h`. Danish, Norwegian, Czech, Slovak, Lithuanian, Estonian, Welsh and Azerbaijani hosts reorder plain ASCII names; Swedish, Polish, Spanish, Turkish, Hungarian and Canadian French hosts also reorder accented ones. Swift targets `en-US`. `LocaleCompareOrder` (BSVCore) reproduces the collation exactly for printable ASCII and for the 488 precomposed Latin letters in U+00C0-U+024F and U+1E00-U+1EFF that decompose to an ASCII letter and combining diacritics, such as `é`, `Å` and `ǖ`. When a certificate has two fields or more, `Certificate.signed` and `CertificateEngine.issue` refuse any other field name with `CertificateFieldNameError.unsupportedCharacter`, because ICU orders other scripts, letters such as `ø` and `ß`, and decomposed accents in ways this SDK does not reproduce, and ignores control characters, so the order TypeScript verifies could not be predicted. A certificate with no field or one has only one order and is signed whatever the name, as TypeScript signs it. `Certificate.verifySignature`, BRC-103 exchange, `CertificateEngine` and `IdentityClient.publiclyRevealAttributes` accept a signature over the `localeCompare` order, over the UTF-8 byte order, or, for a certificate read with `Certificate(binary:)`, over the order its fields arrived in, which is the order its signer signed. The preimage is length-prefixed, so every order commits to the same names and values. A match by byte or received order, and a failure where a name is outside the reproduced characters, are written to the `BSVWallet` log without names or values. `Certificate(binary:)` reads fields in any order with no repeated name (COMP-048). It rejects byte-distinct field names that are canonically equivalent in Unicode so JSON output cannot silently replace a signed field. Certificate verification is cryptographic only. The caller must check the revocation output before it trusts a certificate. | Canonical values stay interoperable with both SDKs; certificates Swift issues verify in TypeScript, TypeScript certificate binary re-encodes byte for byte, and Go and earlier Swift certificates still verify. Go verifies Swift certificates only when `localeCompare` and byte order agree on their names. Strict parsing prevents ambiguous fields, trailing data, hidden signature bytes, and lossy JSON conversion. Tests cover binary and JSON boundaries, Unicode-equivalent names, the order against Bun and Node for all printable ASCII pairs and for the accented Latin letters, TypeScript-signed certificates with mixed-case, accented, underscored and numbered names, both signature orders, signature binding, field encryption, verifier projection, all-or-nothing failure, secret redaction, and refusal of unsupported names. TypeScript certificates with `ß`, Cyrillic and CJK names, and ASCII names signed under a Danish host collation, verify when read from binary. Read from JSON, a certificate whose names are outside the reproduced characters, or that was signed on a host with a tailored collation, has no received order and can fail to verify; such a certificate can also fail in TypeScript on an `en-US` host. |
| COMP-042 | Go BIP-276 accepts a broader prefix domain and re-encodes parsed values before checksum comparison. Its BRC-307 enriched-inscription path omits the enriched suffix, and its specific-ordinal helper has unsafe range artifacts. | Swift emits and requires canonical lowercase BIP-276 text with a restricted lowercase prefix. Swift emits the BRC-307 enriched `OP_RETURN` suffix and rejects invalid input indexes, satoshi ranges, missing source data, and arithmetic overflow before transaction mutation. | The Swift rules preserve canonical protocol output and prevent ambiguous text or partial transaction changes. Tests cover every size boundary, checksum, prefix deviation, push boundary, ordinal boundary, atomic failure, and pinned-Go canonical BIP-276 behavior. |
| COMP-043 | Go and TypeScript place Bitcoin Signed Message, ECIES, BIP-32, and BIP-39 in explicit compatibility packages, while they differ on raw Base58 placement. | Swift exposes the four common families only through the opt-in `BSVCompat` product, outside the modern `BSV` umbrella. Raw Base58 remains a bounded primitive in `BSVCore`; Address, WIF, Base58Check, BRC-42, BRC-94, and BRC-140 remain in `BSVKeys`. | This preserves the common package boundary without declaring a primitive utility obsolete where the reference SDKs disagree. Structure and compile tests verify module ownership and prevent accidental umbrella re-export. |
| COMP-044 | Go places wallet-independent PushDrop construction, decoding, and transaction signing in one package. The Swift target graph cannot place transaction signing in `BSVScript` without a dependency cycle. | Swift keeps wallet-independent PushDrop construction and decoding in `BSVScript`. It keeps transaction signing in `BSVTransaction`. | The split prevents dependency cycles and preserves Go and BRC behavior. Unit and pinned-Go tests cover construction, decoding, and transaction signing across the module boundary. |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,23 @@ Encoding follows the TypeScript writers in
- A processor never sends an error's type or value to the peer. An error the
codecs do not describe gets a fixed text (`Invalid Wallet Wire <call>
request`, `Invalid <call> result`). The full error goes to the local log:
subsystem `dev.opl.swift-sdk`, category `BSVWallet` (`WalletLog`).
`BSVLog` category `BSVWallet` (`WalletLog`), which is `os.Logger` subsystem
`dev.opl.swift-sdk` on Apple platforms and the caller's `BSVLog` handler on
every platform.

Swift keeps these bounds: canonical CompactSize, explicit frame, payload,
text, originator and error limits, checked UInt32 values, low-S DER
signatures, exact SEC1 keys and full payload consumption.
signatures, exact SEC1 keys and full payload consumption. The default frame
bound, `WalletWireLimits.defaultFrameByteCount`, is
`WalletCryptoLimits.defaultPayloadByteCount` (16 MiB plus 512 KiB) plus 64 KiB
of framing (`frameOverheadByteCount`); the call parameters or result payload
of a frame default to the same bound, and `WalletABILimits` bounds an ABI
value's payloads in total by the same amount, so a wallet reached over the
wire signs, verifies, HMACs, encrypts and decrypts every payload BSVAuth and
the wallet's own cryptography accept. TypeScript sets no frame bound. The
JSON form keeps its 8 MiB bounds (`WalletABILimits.maximumBytePayloadCount`
and `WalletCryptoLimits.maximumJSONByteCount`), so a payload over 8 MiB
crosses the binary wire but not a JSON substrate.

## Divergence from pinned Go v1.3.3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ balances must cross the wire between Swift and TypeScript in both directions.
(`wallet/validationHelpers.ts:680`, `WalletWireProcessor.ts:539-556`).
- **BRC-112 balance.** For a basket matching `^(?:balance |p [^ ]+ balance )`,
`totalOutputs` is a UInt64 balance with no outputs and no BEEF
(`walletIsBalanceBasket`). Other totals stay within UInt32.
(`walletIsBalanceBasket`). Other totals stay within UInt32. The basket is
matched after `validateIdentifier`'s trim and lowercasing
(`wallet/validationHelpers.ts:376-418`), as the wallet toolbox decides a
balance query, so `" Balance Tickets"` is one. The TypeScript wire codecs
match the raw basket (`WalletWireProcessor.ts:1296`,
`WalletWireTransceiver.ts:726`) and read such an answer as an output
count.
- **Spendable listOutputs extension.** A request may end with one `01` byte.
The answer then starts with a `-1` marker and each record carries a
spendable byte after its locking script. Without the extension a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ certificate frames must be read and answered without rejection.
which differs from byte order when names differ in case, digits or
punctuation (`cardholder` comes before `cardNumber`). Swift reads certificate
fields in any order and rejects only a repeated name, so acquireCertificate,
listCertificates and discovery read TypeScript answers. Swift still writes
byte order; signing and writing in `localeCompare` order follows once that
comparator is available below BSVAuth.
listCertificates and discovery read TypeScript answers. Swift writes and
signs certificate binary in `localeCompare` order too (COMP-041), so a
certificate TypeScript sent re-encodes byte for byte.
- **List and discovery totals.** `totalCertificates` counts every match. The
records follow with no count and end at the end of the frame. A page may be
shorter than its total but never longer. A processor refuses a page longer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ SDK disagreed on the wire, Swift now follows the SDK:
each general payload through the wallet, so `WalletCryptoLimits` defaults to
the same 16 MiB plus 512 KiB (`WalletCryptoLimits.defaultPayloadByteCount`,
which `AuthLimits.defaultPayloadBytes` is); the TypeScript `ProtoWallet` has
no bound.
no bound. Wallet-wire frames default to that payload plus 64 KiB of framing
(COMP-045), so a wallet reached over the wire signs the same payloads.

`Tests/BSVAuthTests/BRC103/TypeScriptInteropTests.swift` replays TypeScript
messages from `TypeScriptAuthVectors.md` and checks Swift messages against a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ append and writes large Base64 values directly under the limit.
Swift requires a wallet. It does not create a random fallback wallet. Swift
proves the disclosure keyring to the fixed "anyone" verifier and checks that
the wallet returns exactly the requested proved-keyring fields. It verifies the certificate
signature before any disclosure wallet call.
signature before any disclosure wallet call, over the fields in `localeCompare`
order as TypeScript `IdentityClient.publiclyRevealAttributes` does
(`identity/IdentityClient.ts:461`), or over the UTF-8 byte order Go signs
(COMP-041).

Swift uses canonical lowercase compressed-key hex for display identity keys.
It treats every unrecognized certificate type as unknown. It accepts only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ requested certificate type.
Errors stay short and name no side, so the same text fits Swift as client or
server. The detailed cause of a refused message or certificate, such as the
underlying `BRC104Error`, JSON or certificate decoding error, or which
certificate failed which check, is written to the system log on Apple
platforms through `os.Logger` with subsystem `dev.opl.swift-sdk` and category
`BSVAuth`. The reasons `BSVAuth` writes hold no certificate field value,
certificate failed which check, is written to `BSVLog` with category
`BSVAuth`: the system log on Apple platforms through `os.Logger` with
subsystem `dev.opl.swift-sdk`, and the caller's `BSVLog` handler on every
platform. The reasons `BSVAuth` writes hold no certificate field value,
keyring, nonce or signature. An underlying error defined by this SDK is logged
in full; any other, such as one from a caller's wallet, is public by type only
and its description is marked private.
and its description is marked private. The handler receives that description
as `<private>` unless it was installed with `revealingPrivateDetails`.

## Compatibility

Expand Down
Loading
Loading