Skip to content

fix x402: Lightning millisat amounts, drop unserviced BCH rail, correct fee docs - #384

Merged
ralyodio merged 1 commit into
profullstack:masterfrom
ceedot-rock:courtesy/fix-x402-amount-and-rails
Oct 1, 2026
Merged

ralyodio merged 1 commit into
profullstack:masterfrom
ceedot-rock:courtesy/fix-x402-amount-and-rails

Conversation

@ceedot-rock

Copy link
Copy Markdown
Contributor

Courtesy fixes for three x402 issues I found while studying the multi-rail flow. Minimal, no behavior changes beyond what each fix needs.

1. Lightning quoted in millisats, not sats
PAYMENT_METHODS.lightning used decimals: 0, so convertUsdToAssetAmount rounded sub-sat USD values to "0" — a $5 offer emitted "maxAmountRequired": "0" while /api/x402/verify checks expected.amount in millisats (ln_payments.amount_msat). The amount check was vacuous. Now decimals: 11 (10^11 millisats per BTC), matching the verifier's unit: $5 → "5000000", $1 → "1000000" (at BTC=$100k). Added a regression test asserting nonzero for a $1 offer, in the rail's native smallest unit.

2. BCH removed from x402 accepts
The SDK advertised bitcoin-cash in accepts, but /api/x402/settle refuses it ("no verified lookup wired up") — an offered rail no payment could complete on. Removed bch from PAYMENT_METHODS, the legacy network map, the docs table/examples, and the x402 marketing page, each with a note to re-add it once a verified lookup exists and is tested. Nothing else in the platform's (working) BCH support was touched.

3. Fee docs now match the code
The docs and pricing page said a 1.0%/0.5% commission is "deducted before forwarding to the merchant" on x402. The settle route's own header documents the reality: on x402 the buyer pays the merchant wallet directly, no platform wallet is in the path, and the fee is not collected (the computed splitTieredPayment values are record-keeping only). Reworded both fee sections to say the 1.0%/0.5% is the standard rate collected on custodial rails, and 0% on x402. No fee-collection code was added — out of scope.

Test evidence (all against this branch):

  • packages/sdk/test/x402.test.js: 49/49 pass (incl. new millisats regression test)
  • packages/sdk/test/x402-v2.test.js + x402-v2-offer.test.js: 49/49 pass
  • packages/extension/src/core/__tests__/x402.test.ts: 27/27 pass
  • src/app/api/x402/verify/route.test.ts, settle/route.test.ts, settle/route-v2.test.ts: 68/68 pass
  • tsc --noEmit on the edited src/app/x402/page.tsx: clean

Slid Phi Labs accepts donations to keep the lab independent: https://www.patreon.com/SlidPhiLabs

- Lightning quotes in millisats (decimals 11), matching the verifier's
  expected.amount unit; sub-sat USD values no longer round to 0.
- Remove BCH from x402 accepts: the settle route refuses bitcoin-cash
  (no verified lookup), so it must not be advertised. Re-add with a
  tested verify path.
- Fee docs: the 1.0%/0.5% commission is collected on custodial rails,
  not on x402 where the buyer pays the merchant wallet directly.
@ralyodio
ralyodio merged commit e6525bf into profullstack:master Oct 1, 2026
3 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.

2 participants