Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Documentation/Compatibility/FixtureSources.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,24 @@ is not committed as golden data. See the repository
[fixture license policy](../Planning/FixtureLicensePolicy.md) and
[vector inventory](VectorInventory.md) for the source boundary and approved
families.

## Recorded TypeScript auth vectors

The BRC-103 and BRC-104 vectors in
`Tests/BSVAuthTests/BRC103/TypeScriptAuthVectors.swift` and the collation
digests in `Tests/BSVAuthTests/Certificates/LocaleCompareOrderTests.swift` are
outputs recorded from running permissively licensed source. They are not copied
upstream fixtures and are not under the conformance fixture root, so they have no
manifest fragment. Their provenance:

| Item | Value |
| --- | --- |
| 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 |
| 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 |

Regenerate them only from the pinned revision, and record a new revision here
when they change.
13 changes: 9 additions & 4 deletions Documentation/Compatibility/GoSDK-v1.3.3-Defects.md
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,11 @@ Suggested correction: store one bounded pending request on the session,
compare the exact response with that request, and clear the request only after
successful signature and certificate validation.

Swift handling: `PeerAuthenticator` stores one pending request per session,
rejects unsolicited or mismatched responses, and clears the request only after
successful response-signature verification.
Swift handling: `PeerAuthenticator` keeps up to 16 open requests per session
and direction, as `@bsv/sdk` 4.1.1 does (`Peer.ts:474-478`). After the
response signature verifies, it binds the response to the oldest open request
it fits, in the order of `Peer.ts:1236-1241`, rejects unsolicited or
mismatched responses, and clears that request.

### GO-063: The requested-certificate HTTP header is not signed

Expand All @@ -1096,7 +1098,10 @@ Suggested correction: include a canonical hash of the requested-certificate
set in the signed payload, or send a signed BRC-103 certificate-request
message.

Swift handling: the HTTP frame codec rejects this header. Callers use the
Swift handling: `@bsv/sdk` 4.1.1 sends and reads the same unsigned header, so
the HTTP frame codec reads and writes it for interoperability (COMP-059).
`PeerAuthenticator` does not act on a requested set in a general message, as
`Peer.processGeneralMessage` does not. Callers that need a request use the
signed BRC-103 certificate-request message.

### GO-064: Storage resolution does not bind advertisements to the requested UHRP identifier
Expand Down
8 changes: 4 additions & 4 deletions Documentation/Compatibility/Rulings.md

Large diffs are not rendered by default.

72 changes: 63 additions & 9 deletions Documentation/Compatibility/Rulings/COMP-052-BRC-103-104-Core.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,46 @@ COMP-060 covers signed certificate exchange.
## Decision

Swift emits BRC-103 version `0.1`. It rejects unknown versions. The strict JSON
codec rejects duplicate and unknown object members before Foundation decodes
the document. It requires canonical compressed public keys, canonical Base64
nonces, complete low-S DER signatures, and explicit JSON and payload limits.
codec rejects duplicate and unknown object members, invalid UTF-8, lone
surrogates and excessive nesting before Foundation decodes the document. It
requires canonical compressed public keys, canonical Base64 nonces, complete
low-S DER signatures, and explicit JSON and payload limits. Swift writes the
message JSON itself, so certificate data on the wire is byte-identical to the
text it signs (COMP-060).

The peer authenticator uses an injected wallet, secure random source, and
clock-based session timeout. It binds an expected peer identity, rejects nonce
reuse and message replay, limits sessions and accepted messages, and checks
cancellation around each wallet call. A responder remains unauthenticated
until it verifies the first signed general message.
until it verifies the first signed general, certificate-request or
certificate-response message from the initiator.

Swift accepts 32-byte protocol nonces and the exact 48-byte Go nonce form. It
generates 32-byte nonces and propagates random-source failures. It does not
accept the other variable nonce lengths that the pinned Go verifier accepts.
Every session nonce Swift creates, as initiator or responder, is 48 random
bytes in canonical padded Base64 (64 characters). Message nonces are 32 bytes.
Swift accepts 32-byte and 48-byte session nonces from peers and propagates
random-source failures. It does not accept the other variable nonce lengths
that the pinned Go verifier accepts.

The BRC-104 codec is transport-neutral. It binds a 32-byte request identifier
to the method, path, optional query, selected headers, body, or response status.
It uses canonical CompactSize values and explicit payload and header limits.
It excludes all `x-bsv-auth-*` headers from the signed payload, rejects
duplicate headers, and sorts selected header names by lowercase UTF-8 bytes.
It excludes every header whose name starts with `x-bsv-auth` from the signed
payload, as `AuthFetch.ts:727` does, rejects duplicate headers, and sorts the
lowercase selected header names in `localeCompare` order (`AuthFetch.ts:740`).
That order differs from the Go SDK's UTF-8 byte order only where names differ
at a `_`: `localeCompare` puts `x-bsv-a_b` before `x-bsv-a-b`, `x-bsv-a1` and
`x-bsv-ab`, and byte order puts it after them. A signed header value must be
printable ASCII without leading or trailing spaces, because `fetch` trims
values and reads them as Latin-1 before a TypeScript client rebuilds the
payload; Swift refuses other values rather than sign bytes the peer will not
see.

An absent or empty body is written as -1, never 0, in requests and responses.
When a client encodes a POST, PUT, PATCH or DELETE request with an absent body
and a `content-type` containing `application/json`, it signs and sends `{}`.
An empty body stays empty. A server rebuilding a received request never adds
`{}`. A `multipart/form-data` content type is signed whole, with its boundary;
any other content type is cut at the first `;` and trimmed.

## Go SDK defects

Expand All @@ -47,3 +68,36 @@ The separate Go SDK defect report records the related pinned defects:
Swift does not reproduce these defects. Shared messages other than requested
certificate sets remain interoperable through the pinned Go oracle. COMP-060
records the requested-certificate wire incompatibility.

## Changes for `@bsv/sdk` 4.1.1

TypeScript `@bsv/sdk` 4.1.1 is the reference peer. Where this ruling and that
SDK disagreed on the wire, Swift now follows the SDK:

- A responder created 32-byte session nonces. TypeScript requires exactly 48
bytes for `initialNonce` and `yourNonce` (`AuthMessageValidation.ts:391-428`)
and rejected every Swift initialResponse.
- A responder became authenticated only on a general message. TypeScript marks
the peer authenticated on any verified certificate request, certificate
response or general message (`Peer.ts:1092`, `Peer.ts:1227`, `Peer.ts:1317`).
- An empty body was written as 0. TypeScript writes and expects -1 in both
directions (`clients/AuthFetch.ts:762-770`,
`transports/SimplifiedFetchTransport.ts:314-321`,
`auth-express-middleware/src/index.ts:2112-2117`). The client `{}` default
applies only to an absent body, as in `clients/AuthFetch.ts:755-760`.
- `content-type` was cut at `;` without trimming, also for multipart.
TypeScript uses `authenticatedContentType` (`utils/paymentTransport.ts:84-90`).
- Default limits were below what TypeScript sends. They now match: 16 MiB
messages (`AuthMessageValidation.ts:8`), payloads of 16 MiB plus 512 KiB
(`clients/AuthFetch.ts:147`), 100 certificates, certifiers and types
(`AuthMessageValidation.ts:12-14`), and 512 headers, 1 KiB names, 32 KiB
values and 256 KiB in total, with 256 KiB for `x-bsv-payment`
(`transports/SimplifiedFetchTransport.ts:25-28`, `:655-661`). BRC-103 signs
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.

`Tests/BSVAuthTests/BRC103/TypeScriptInteropTests.swift` replays TypeScript
messages from `TypeScriptAuthVectors.md` and checks Swift messages against a
live TypeScript peer.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,19 @@ transport and payment policies that a framing codec cannot select safely.
general messages. The codec uses the seven BRC-104 authentication headers. It
requires canonical header values, one value for each authentication header,
complete request-ID correlation, valid HTTP component text, and explicit
resource limits. It rejects the requested-certificate header because that
resource limits.

`x-bsv-auth-message-type` is optional on requests. `AuthFetch` sends only the
other six headers (`transports/SimplifiedFetchTransport.ts:189-194`) and the
TypeScript middleware assumes `general`
(`auth-express-middleware/src/index.ts:361-366`). When the header is present it
must be `general`. Swift still sends it; TypeScript ignores it. A received
request is rebuilt without the client JSON body default, and an empty body is
signed as -1 (COMP-052).

The default framing limits allow 1024 headers, 1 KiB names, 256 KiB values and
1 MiB of headers in total, so a frame that carries the largest TypeScript
signed headers (COMP-052) and the authentication headers fits. It rejects the requested-certificate header because that
header is not part of the signed payload. Callers use the signed BRC-103
certificate-request message from COMP-060.

Expand Down
Loading
Loading