Repository navigation
Sign certificates in TS field order and send SDK logs to a handler on every platform - #23
Merged
Merged
Conversation
@bsv/sdk 4.1.1 writes, signs and verifies certificate fields sorted with localeCompare (auth/certificates/Certificate.ts:290, :437-458, :473). LocaleCompareOrder moves from BSVAuth to BSVCore so BSVWallet and BSVIdentity use it, and now collates the 488 precomposed accented Latin letters exactly as ICU does, besides printable ASCII. Certificate.binary writes that order, Certificate.signed signs it and refuses names whose order is not reproduced, and verifySignature accepts either localeCompare or UTF-8 byte order, so IdentityClient and the BRC-103 exchange verify TypeScript certificates. CertificateFieldNameError moves to BSVWallet with the case unsupportedCharacter. Vectors come from the live TypeScript source under Bun, cross-checked with Node.
NetworkLog, WalletLog, OverlayLog and AuthLog wrote only through os.Logger, so nothing was logged on Linux. They now write through BSVLog in BSVCore, which keeps the os.Logger path on Apple platforms and also calls the handler a caller installs with BSVLog.setHandler, on every platform. A detail the system log marks private reaches the handler as <private> unless the caller installs it with revealingPrivateDetails.
WalletWireLimits frames and call payloads and the WalletABILimits aggregate were capped at 16 MiB (payloads at 8 MiB), so a wallet reached over the wire could not sign, verify or encrypt the payloads between that and WalletCryptoLimits.defaultPayloadByteCount, which BSVAuth shares. The defaults are now that payload plus 64 KiB of framing (WalletWireLimits.defaultFrameByteCount), and a test signs, verifies, encrypts and decrypts a maximum-size payload over the wire.
walletIsBalanceBasket tested the raw basket, so " Balance Tickets" was a balance query to the wallet toolbox, which trims and lowercases baskets with @bsv/sdk validateIdentifier (wallet/validationHelpers.ts:376-418), but an output count to this SDK. The basket is now matched after the same trim and lowercasing.
…ngle field TypeScript sorts certificate fields with localeCompare in the host's default locale. Swift reproduces the en-US order for printable ASCII and accented Latin letters; say so, with the Danish and Czech tailorings that reorder even ASCII names. A certificate read from binary keeps the order its fields arrived in, and verifySignature also checks the signature over that order, so a TypeScript certificate with names such as ß, Cyrillic or CJK, or one signed on a Danish host, verifies. The preimage is length-prefixed, so every order commits to the same fields. A match by byte or received order, and a failure with a name outside the reproduced characters, are logged without names or values. Certificate equality ignores the received order. A certificate with no field or one has a single order, so signed and CertificateEngine.issue accept any name there, as TypeScript does.
NetworkLog and OverlayLog wrote the description of any underlying error in clear, including one thrown by a caller's HTTP transport or overlay facilitator. Treat those as AuthLog does: the description of an error type the SDK defines stays public, any other is private and reaches a BSVLog handler as <private> unless it reveals private details. The SDK module check moves to BSVLog and covers every SDK module. Document that a handler may log or replace itself, that a logging handler recurses, and that a line in flight can reach a handler just replaced; test re-entry and lines written from many tasks while the handler is swapped. The lock now builds on Android and Windows too.
The one-byte-over check accepted any error. Assert the transceiver's byteLimitExceeded for signature and HMAC data, decode a frame of exactly the frame limit, and check that one byte more is refused as a request frame and answered in band. HMAC a maximum-size payload over the wire. Note in COMP-045 that the JSON form keeps its 8 MiB bounds.
walletIsBalanceBasket compared Characters, so a space followed by a combining mark was not a space. Match the moduleBalanceQuery.ts pattern on UTF-8 bytes, as the JavaScript expression matches code units.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Before: Swift wrote and signed BRC-52 certificate fields in UTF-8 byte order. @bsv/sdk 4.1.1 uses localeCompare order, so certificates with mixed-case names that Swift signed failed to verify in TS, and the reverse was also true. SDK log lines went only to os.Logger, so Linux and Android hosts saw nothing. The wallet wire capped crypto payloads below the shared 16.5 MiB limit.
After: certificates are written and signed in TS localeCompare order (ICU root, the order an en-US host uses). A certificate read from binary keeps the order its fields arrived in. verifySignature tries localeCompare order, then byte order, then the received order. Certificates with zero or one field may use any name. Every platform can install a log handler with
BSVLog.setHandler, and caller error text stays private in network and overlay lines. The wallet wire carries the full 16.5 MiB payload, and BRC-112 balance baskets match the way TS does.How: there is a new
LocaleCompareOrderand aBSVLogsink with Android and Windows lock branches. The new TS vectors (ß, Cyrillic, CJK and da_DK collation) come from @bsv/sdk 4.1.1 under Bun. Tested with swift test on Linux (swift:6.1): 1033 Swift Testing and 155 XCTest pass, and check-public-api.sh is clean. Signatures fromCertificate.signedchange for names whose locale and byte orders differ.CertificateFieldNameErrormoved to BSVWallet.