Repository navigation
fix(core): keep the X-PAYMENT header ASCII so 402 challenges with non-ASCII extensions are payable - #110
Merged
vapi-development merged 1 commit intoDec 1, 2026
Conversation
ege-arhan
force-pushed
the
fix/x-payment-ascii-header
branch
from
December 1, 2026 07:40
31160e4 to
b63331e
Compare
…-ASCII extensions are payable A 402 challenge echoes its own metadata back into the payment payload. When a server's `extensions` carried typographic text such as `…` (U+2026), the legacy `X-PAYMENT` header was a raw JSON string with that code point in it, so `Headers.set` threw `Cannot convert argument to a ByteString because the character at index ... has a value of 8230` before the request left the machine. Every paid call to such a server failed, and `vapi pay` printed no receipt. Non-ASCII code points are now escaped when the compatibility header is built. The JSON parses back to the same value that `PAYMENT-SIGNATURE` carries, so facilitators see the extensions unchanged. Fixes vAPI-Network#109 Signed-off-by: ege-arhan <[email protected]>
ztsrdev
force-pushed
the
fix/x-payment-ascii-header
branch
from
December 1, 2026 10:45
b63331e to
769d8f2
Compare
vapi-development
approved these changes
Dec 1, 2026
vapi-development
left a comment
Contributor
There was a problem hiding this comment.
Thanks — this is the right fix. X-PAYMENT was the only header carrying raw JSON (PAYMENT-SIGNATURE and SIGN-IN-WITH-X are base64 of UTF-8), so escaping there covers every case. I rebased onto main and moved the changelog line under the current Unreleased section.
Merged
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.
What & why
vapi payaborted every call to a server whose 402 challenge carried non-ASCII text inextensions, withCannot convert argument to a ByteString because the character at index ... has a value of 8230and no receipt. Fixes #109.The challenge metadata is echoed into the payment payload.
PAYMENT-SIGNATUREis base64 and carries UTF-8 fine, but the legacyX-PAYMENTheader is a raw JSON string, andHeaders.setrejects any code point above 0xff. The text came from the server's own bazaar description (ECB reference rates are…), so the failure depends on the resource, not on the wallet or the amount. Reproduced againsthttps://api.stablecoingateways.com/v1/fx/rates?base=EUR&symbols=USD,GBP, which returns a 402 with three U+2026 characters inextensions.bazaar.Changes
packages/core/src/x402.ts: newencodeLegacyPaymentHeader, which serializes the compatibility payload and escapes every code point from U+007F up as\uXXXX.buildCompatibleX402Paymentuses it forX-PAYMENT.packages/mcp/src/x402.ts: the same builder there uses the shared helper instead of a secondJSON.stringify.packages/core/src/x402.test.ts: a challenge whosebazaarinfo contains…now produces a header thatHeaders.setaccepts, and parsing it returns the extensions unchanged.CHANGELOG.md: entry underUnreleased.Escaping rather than dropping keeps the payload byte-identical after
JSON.parse, so a facilitator reads the sameextensionsthatPAYMENT-SIGNATUREcarries and the compatibility header stays a faithful copy. Only the header encoding changes; no protocol field is added, renamed or removed.Checked with
pnpm format:check,pnpm lint,pnpm typecheck,pnpm test,pnpm buildandpnpm pack:check.packages/coreran 2492 tests andpackages/mcp40 inx402.test.ts; nothing else was touched. The first fullpnpm testrun hit two timeouts invault-key.test.ts, which passed when the file ran alone and in the next full run.Checklist
pnpm lint && pnpm typecheck && pnpm test && pnpm build && pnpm pack:checkpass locallygit commit -s, Developer Certificate of Origin)Breaking changes
None. The header is still a JSON object with the same keys and values after parsing; only characters above U+007E are written as escapes.