Skip to content

fix(utils): make base64 and CBOR payload decoding consistent across platforms - #986

Merged
robwoodgate merged 1 commit into
mainfrom
fix/strict-payload-decoding
Aug 19, 2026
Merged

fix(utils): make base64 and CBOR payload decoding consistent across platforms#986
robwoodgate merged 1 commit into
mainfrom
fix/strict-payload-decoding

Conversation

@robwoodgate

@robwoodgate robwoodgate commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

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.fromBase64 normalizes (trim, whitespace strip, base64url mapping, padding) and validates in one place, then decodes the validated string, so both backends see identical input.
  • decodeCBOR requires a payload to consume the whole buffer.
  • encodeBase64ToJson delegates to Bytes.fromBase64 directly; the redundant private pre-mapping helper is removed and the base64url output mapping has a single implementation.
  • Tests run a shared accept/reject corpus under both decoder backends.

Impact

getDecodedToken, getDecodedTokenBinary and PaymentRequest.fromEncodedRequest throw CTSError for 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.

@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.92%. Comparing base (46195de) to head (2761b76).
⚠️ Report is 2 commits behind head on main.
✅ All tests successful. No failed tests found.

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     
Flag Coverage Δ
integration 37.40% <50.00%> (-0.05%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@robwoodgate

Copy link
Copy Markdown
Collaborator Author

@KvngMikey - related to your work in #967, would value your thoughts.

@robwoodgate
robwoodgate force-pushed the fix/strict-payload-decoding branch from 8897b9c to 4a634bb Compare August 19, 2026 17:19
@robwoodgate
robwoodgate force-pushed the fix/strict-payload-decoding branch from 4a634bb to 2761b76 Compare August 19, 2026 17:27
@robwoodgate robwoodgate changed the title fix(utils): validate base64 and CBOR input strictly before decoding fix(utils): make base64 and CBOR payload decoding consistent across platforms Aug 19, 2026
@robwoodgate
robwoodgate merged commit 59d36b1 into main Aug 19, 2026
19 checks passed
@robwoodgate
robwoodgate deleted the fix/strict-payload-decoding branch August 19, 2026 19:07
@github-project-automation github-project-automation Bot moved this from Backlog to Done in cashu-ts Aug 19, 2026
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))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant