feat(x402): namespace the deferred scheme and add the v2 Discovery API - #145
Merged
JulioMCruz merged 1 commit intoAug 4, 2026
Conversation
Implements the actionable findings from STACK-PROTOCOL-RESEARCH-2026-07-29.md. Scheme namespace (research R1) x402 v2 standardizes exactly one scheme, `exact`. `deferred`, `upto` and batch-settlement are proposed, and the namespace is now governed by the x402 Foundation TSC under the Linux Foundation. Stack was advertising a PerkOS-designed voucher scheme as `deferred`, so a future spec release could redefine a string existing clients already negotiate. Stack now advertises `perkos-deferred`. The bare `deferred` name is still accepted on verify/settle and answers with an `X-x402-Deprecation` header, so no client breaks. Scheme handling is centralized in lib/utils/x402-schemes.ts and fails closed on unknown identifiers instead of falling through to a default handler. Transaction filters match the whole scheme family, so rows written before the rename stay visible. Discovery API (research R2) Adds `GET /api/discovery/resources`, the spec-defined listing with limit/offset pagination and type filtering. This is how facilitators index each other; Stack previously had only /.well-known/x402-discovery.json, which is PerkOS metadata about the facilitator rather than a resource listing. Endpoints are read in one batched query per page rather than per vendor. Docs (research R4, R6, R7) - CLAUDE.md documented the v1 request shape the code stopped emitting a major version ago: bare network names instead of CAIP-2, no `accepted` echo. Now v2. - Adds a protocol status table stating plainly that none of x402, ERC-8004, x401 or ERC-8183 is a finalized standard, with the wording to avoid. - Docs/PROTOCOL-PIN-REVIEW.md: monthly re-pin checklist for all four. Unrelated pre-existing fixes, needed to verify any of the above - lib/utils/chains.ts imported `megaeth` from viem/chains, which does not export it (only `megaethTestnet`). package-lock.json is untracked, so any fresh install resolves ^2.44.1 and main does not build. Removed the mainnet entry rather than invent a chain ID; MegaETH mainnet launched 2026-02-09 but its ID is not confirmed in a primary source and its payment token here was the zero-address placeholder. Re-add once viem ships it. - `npm test` ran without --experimental-strip-types, so on Node 23.3 every suite failed with ERR_UNKNOWN_FILE_EXTENSION on the .ts imports. Verified: typecheck clean (first time), npm test 22/22 including 5 new scheme tests, npm run build compiles with /api/discovery/resources registered.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
JulioMCruz
merged commit Aug 4, 2026
a064823
into
chore/drop-local-erc8004-registries
2 checks passed
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.
Implements the actionable findings from the protocol research (
STACK-PROTOCOL-RESEARCH-2026-07-29.md).R1 — Namespace the
deferredschemex402 v2 standardizes exactly one scheme:
exact.deferred,uptoand batch-settlement are proposed, and since 2026-07-14 the namespace is governed by the x402 Foundation TSC under the Linux Foundation.Stack was advertising a PerkOS-designed voucher scheme under the bare name
deferred. If the TSC standardizes that string with different semantics, every client that negotiated it is speaking a different protocol than a compliant counterparty.Backward-compatible migration, as agreed:
perkos-deferreddeferredX-x402-Deprecationon the responseScheme handling is centralized in
lib/utils/x402-schemes.tsand fails closed —canonicalizeSchemereturnsnullfor anything unrecognized rather than letting it fall through to a default handler.One subtlety worth calling out: transactions written before the rename are stored as
deferred. A filter matching only the new spelling would silently hide history, soschemeFilterValues()matches the whole family and the transactions query uses.in()instead of.eq().R2 — x402 v2 Discovery API
Adds
GET /api/discovery/resources— the spec-defined listing withlimit/offsetpagination andtypefiltering.Stack already had
/.well-known/x402-discovery.json, but that is PerkOS metadata about the facilitator (its own header comment says it "is not a core endpoint"), not a resource listing. The Discovery extension is how facilitators index each other, so without this Stack does not appear in that channel.Vendor endpoints are read in one batched query per page rather than one per vendor.
R4, R6, R7 — Docs
CLAUDE.mddocumented the v1 request shape — bare network names ("avalanche"),x402Version: 1, noacceptedecho. The code has been fully v2 for a while; anyone onboarding from that doc wrote wrong clients. Now shows v2 with CAIP-2 and the echo rule.Docs/X401-STATUS-2026-07-22.md.Docs/PROTOCOL-PIN-REVIEW.md— monthly re-pin checklist for all four, with the specific things that would break us (a standardizeddeferred, an x401 0.3.0 wire redesign, the ERC-8004 Validation Registry shipping, a slimmedERC8183WithAuthorization).Two unrelated pre-existing fixes
Both were blocking verification of everything above.
maindid not build.lib/utils/chains.tsimportsmegaethfromviem/chains, which does not export it — onlymegaethTestnet.package-lock.jsonis untracked, so any fresh install resolves^2.44.1and hits this.I removed the mainnet entry rather than invent a chain ID. MegaETH mainnet launched 2026-02-09, but I could not confirm its chain ID in a primary source, and its payment token here was the zero-address placeholder — so it was never a working payment network. Re-add properly once viem ships it. The testnet (6342) is untouched.
npm testdid not run. The script omitted--experimental-strip-types, so on Node 23.3 every suite failed withERR_UNKNOWN_FILE_EXTENSIONon its.tsimports. The whole suite was red, not just mine.Verification
Not included
R5, the ERC-8183 → ERC-8004 reputation loop, is deliberately out of scope — it needs its own design (who signs the feedback, what value/decimals, idempotency) and is the strategically interesting piece rather than plumbing.
R3,
@perkos/contracts-erc8004@1.0.1, cannot be fixed here: the package source is not in this repo or the workspace, and npm reports norepository.url. It is still published describing pre-v2 contracts, so external installers get stale definitions with no warning.