Skip to content

BSVAuth and wallet crypto accept 16 MiB payloads, as the TS AuthFetch does - #19

Merged
rohenaz merged 2 commits into
mainfrom
auth-payload-16mib
Nov 16, 2026
Merged

rohenaz merged 2 commits into
mainfrom
auth-payload-16mib

Conversation

@rohenaz

@rohenaz rohenaz commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Before

After a large image inscribe (180 KB), the next action failed with BSVAuth.BRC104HTTPFramingError.resourceLimit. The live harness (swift-1sat-sdk PR #55) logged createAction and beginActionBatch replies of 1,328,943 and 1,330,479 bytes.

AuthLimits.maximumPayloadBytes and BRC104Limits.maximumPayloadBytes both defaulted to 1 << 20, so BRC104HTTPResponseFrame refused any body over 1 MiB before reading it.

With the framing raised alone, a payload over 1 MiB still failed. BRC-103 signs and verifies each general message's whole payload through the wallet, and WalletCryptoLimits.standard capped signature data at 1 MiB. The test below then hit payloadTooLarge(actual: 1048679, maximum: 1048576).

After

The defaults now follow the TS SDK (@bsv/sdk 4.1.0):

Limit Before After TS reference
AuthLimits.maximumPayloadBytes 1 MiB 16 MiB MAX_AUTH_MESSAGE_BYTES, MAX_AUTH_HTTP_REQUEST_FRAME_BYTES
BRC104Limits.maximumPayloadBytes (and so BRC104HTTPFramingLimits.standard) 1 MiB 16 MiB as above; response bodies DEFAULT_SIMPLIFIED_FETCH_MAX_RESPONSE_BYTES
WalletCryptoLimits.maximumPayloadByteCount (ciphertext = payload + 48) 1 MiB 16 MiB ProtoWallet.createSignature / verifySignature set no bound

The toolbox fix (swift-wallet-toolbox PR #56) keeps these replies small in the first place by asking for base64 bytes on every call. This change makes a reply TS accepts acceptable here too.

Other framing differences from TS (found, not changed here)

  • Signed headers (BRC104Limits). Swift allows 64 headers, 256-byte names, 8 KiB values and 64 KiB in total. AuthFetch and SimplifiedFetchTransport allow 512, 1,024 bytes, 32 KiB and 256 KiB. Swift is stricter.
  • Raw HTTP headers (BRC104HTTPFramingLimits). Swift also bounds every HTTP header, signed or not: 128 headers, 256-byte names. TS bounds only the signed ones.
  • Query. Swift allows 64 KiB; TS allows 8,192 bytes. Swift is looser.
  • Response payload. TS allows a payload of up to maxResponseBytes + 512 KiB of framing (MAX_AUTH_RESPONSE_FRAME_OVERHEAD_BYTES). Swift uses one 16 MiB cap for the whole payload, so a response body within a few hundred bytes of 16 MiB is refused here.
  • JSON message limit. AuthLimits.maximumJSONBytes is 8 MiB. TS caps the handshake response at 1 MiB (DEFAULT_SIMPLIFIED_FETCH_MAX_HANDSHAKE_RESPONSE_BYTES).
  • Error for an oversized payload. PeerAuthenticator.makeGeneralMessage throws notAuthenticated, not resourceLimit.

None of these affects wallet storage traffic today.

How

  • The new defaults are in AuthModels.swift, BRC104Payload.swift and WalletCryptoLimits.swift. Each has a doc comment naming the TS constant it follows.
  • New tests in BRC104HTTPFramingTests:
    • payloadsOverOneMebibyte: a 1 MiB + 1 request body and a 1,330,479-byte response body are signed, framed, decoded and verified through PeerAuthenticator and ProtoWallet with default limits.
    • sixteenMebibyteBoundary: a response payload of exactly 16 MiB encodes and decodes. One byte more is refused by the codec and by BRC104HTTPResponseFrame.
  • Updated tests:
    • testCryptoLimitsValidation checks the new standard.
    • The certificate test that signs a preimage beyond the wallet payload limit now builds its ProtoWallet with an explicit 1 MiB limit, so it still exercises that path.
  • macOS build fix: UHRPAdvertisementTests declared a private let hash: [UInt8]. On Darwin, XCTestCase is an NSObject, so this clashed with NSObject.hash: Int, and the test target did not compile (property 'hash' with type '[UInt8]' cannot override a property with type 'Int'). main 614a838 fails Swift 6.1 / macos-15 the same way. The property is now contentHash. Linux was never affected.
  • swift test in swift:6.1-noble (docker): 878 Swift Testing tests passed (3 skipped: live network and scale tests), and 154 XCTest tests with 0 failures.

… does

AuthLimits.maximumPayloadBytes and BRC104Limits.maximumPayloadBytes defaulted to 1 MiB, so a
wallet storage reply over 1 MiB was refused with BRC104HTTPFramingError.resourceLimit before it
was read. After a 180 KB image inscription the harness saw createAction and beginActionBatch
replies of 1,328,943 and 1,330,479 bytes. TS AuthFetch sends request frames up to 16 MiB
(MAX_AUTH_HTTP_REQUEST_FRAME_BYTES), reads response bodies up to 16 MiB
(DEFAULT_SIMPLIFIED_FETCH_MAX_RESPONSE_BYTES), and MAX_AUTH_MESSAGE_BYTES is 16 MiB. Both
defaults are now 16 MiB.

BRC-103 signs and verifies each general message's whole payload through the wallet, and
WalletCryptoLimits capped signature data at 1 MiB, so a larger payload still failed with
payloadTooLarge. The TS ProtoWallet sets no bound there; the default is now 16 MiB as well.
On Darwin an XCTestCase is an NSObject, whose hash is an Int, so a [UInt8]
property named hash cannot override it. Linux builds it because there
XCTestCase is not an NSObject.
@rohenaz
rohenaz merged commit 17b381b into main Nov 16, 2026
6 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