fix(utils): make base64 and CBOR payload decoding consistent across platforms - #986
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #986 +/- ##
==========================================
+ Coverage 95.89% 95.92% +0.03%
==========================================
Files 55 56 +1
Lines 5938 5961 +23
Branches 1507 1516 +9
==========================================
+ Hits 5694 5718 +24
Misses 103 103
+ Partials 141 140 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
Author
|
@KvngMikey - related to your work in #967, would value your thoughts. |
52 tasks
robwoodgate
force-pushed
the
fix/strict-payload-decoding
branch
from
August 19, 2026 17:19
8897b9c to
4a634bb
Compare
robwoodgate
force-pushed
the
fix/strict-payload-decoding
branch
from
August 19, 2026 17:27
4a634bb to
2761b76
Compare
17 tasks
robwoodgate
added a commit
that referenced
this pull request
Aug 28, 2026
[5.0.0-rc.8](v5.0.0-rc.7...v5.0.0-rc.8) (2026-08-27) ### Features * **model:** expose NUT-06 urls, time and tos_url on MintInfo ([#1003](#1003)) ([832a71c](832a71c)) * **utils:** findCashuPayload to locate tokens and payment requests in text ([#967](#967)) ([d094499](d094499)) * **wallet:** add LockBuilder and asLocked as forward-compatible names ([#995](#995)) ([4d69fe7](4d69fe7)) * **wallet:** add swap preview serialize helpers and persistence docs ([#972](#972)) ([02f0bfe](02f0bfe)) ### Bug Fixes * **transport:** split request option precedence by option class ([#968](#968)) ([603553d](603553d)) * **utils:** make base64 and CBOR payload decoding consistent across platforms ([#986](#986)) ([59d36b1](59d36b1)) * **wallet:** keep large proofs in the close-match selection pool ([#1001](#1001)) ([a9ade37](a9ade37))
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.
TLDR
Base64 and CBOR payload decoding now gives the same verdict on Node and in browsers: well-formed input decodes, malformed input throws
CTSError.Why
The two platform decoders (
Buffer,atob) disagree on some edge cases, so the same string could decode on one platform and fail on the other. #967 validates scanned text candidates by decoding them, so verdicts must be uniform across platforms; this PR is sequenced ahead of it.Changes
Bytes.fromBase64normalizes (trim, whitespace strip, base64url mapping, padding) and validates in one place, then decodes the validated string, so both backends see identical input.decodeCBORrequires a payload to consume the whole buffer.encodeBase64ToJsondelegates toBytes.fromBase64directly; the redundant private pre-mapping helper is removed and the base64url output mapping has a single implementation.Impact
getDecodedToken,getDecodedTokenBinaryandPaymentRequest.fromEncodedRequestthrowCTSErrorfor malformed payloads on every platform. Line-wrapped, unpadded, and edge-whitespace input still decodes. Full suite and prtasks pass. v5 only, as it may now throw on platforms that once passed.