Repository navigation
feat!: pending-key capabilities, scoped registration, capabilities-only public gateways, no loopback token - #28
Conversation
The loopback gateway holds one pending delegate key and pays with the first
usable capability in registration order. registerCapability takes the
capability alone and returns {signer, pool, expiry}; capabilities() entries
carry cap, expiry, pool, signer and spent. The host option and the
x-decdn-host header are gone, and the delegate and capability API is called
without the token.
The loopback contract suite skips against decdn v0.3.1 and earlier, and
scripts/decdn-contract.sh leaves those releases' loopback journey out.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
A public gateway pays only with capabilities registered on its bare host and
answers 503 when none can pay; it has no daily allowance and never answers
402. PAYMENT_REQUIRED is a loopback gateway's 402 alone. The fake gateway's
public mode drops the allowance, serves /_delegate, /_capability and /_status
on the bare host to any origin, and serves a cached blob with nothing that
pays. New public contract tests are gated on shippedAfter("0.3.1").
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The loopback gateway has no token and gates every request on browser
headers instead. The token option, the x-decdn-token header,
readLoopbackToken and the UNAUTHORIZED error code are removed. The fake
gateway applies the gate to every loopback route, redirects only a browser
navigation to a bundle or entry to its site, and the loopback contract suite
checks the gate's refusals behind the existing shippedAfter("0.3.1") gate.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
registerCapability takes a required scope: "any", or a namespace scope
{ namespaces, signature } whose pool-owner signature the SDK passes
through. The registration result and capability listing entries carry
optional namespaces, read as bigints. The fake gateway requires the
scope, checks its shape, echoes namespaces, and pays with a namespace
scope only for requests that name one of its namespaces.
A 503 maps to PAYMENT_REQUIRED, like a 402; POOL_UNFUNDED is gone. The
./node subpath export and defaultDataDir are removed.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…oken (#2910) * feat(gateway)!: one pending delegate key, capabilities on both gateway modes The gateway holds at most one pending delegate key: GET /_delegate returns it until a capability claims it. PUT /_capability takes {"capability"} only, for a key the gateway holds, one capability per pool per key. The gateway pays every pull with the first registered capability that no funding stop retired and that sits outside the node expiry margin, and serves a cache hit with nothing that can pay. /_delegate, /_capability and /_status need no token and no Origin; a loopback gateway answers nothing cross-origin. A public gateway answers the same API on its bare host and pays with capabilities first, then from its own pool when it names a keystore. Removes the per-page scope, x-decdn-host selection, per-site delegate bounds, the pending-key TTL and the psl dependency. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(gateway)!: pay only with capabilities, no keystore and no allowance A gateway, loopback or public, pays only with the capabilities pool owners register to its in-memory delegate keys: --keystore and --capability are refused, it opens no pool and keeps no buyer store past its run. The daily allowance (--allowance-bytes-per-day, --allowance) is gone; the caps of the capabilities bound what a gateway spends. A public gateway with nothing that can pay answers 503 with the canonical decdn: URI. The counter requests_allowance_exhausted is renamed requests_payment_required, /_status loses its allowance field, and an active pull's payer is {signer, pool}. The e2e journeys fund their gateways through decdn_e2e::pool_owner. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(gateway)!: a loopback gateway takes no token; browser headers gate it A loopback gateway writes no token file and reads no x-decdn-token. Every request passes a browser-header check after the Host check: a cross-site page, an Origin that is none of the gateway's own (the bare host and its site origins), and a browser that sends no Sec-Fetch-Site (an Origin, or a Mozilla/ User-Agent) get 403. A client outside a browser passes. On the bare host, a browser's navigation to a bundle or entry redirects to its site; any other request is served there. Site pages may connect to their own origin only. decdn dashboard reads the gateway's /_status with no token. Moves the SDK pins to decdn/sdk-typescript#28 and decdn/sdk-python#15, whose contract suites pass against this gateway. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(gateway): a pool owner scopes a capability to its namespaces A capability registered with a scope that its pool's owner signed (EIP-712 CapabilityScope, domain decdn-capability-scope) pays only for requests that one of the scope's namespace pointers serves: the pointed bundle on <ns>.<host>. Scoped matches pay before unscoped capabilities. The listing, /_status and the dashboard show each capability's namespaces. `decdn pool assign --namespace` signs the scope and prints the whole PUT /_capability body. Co-Authored-By: Claude Opus 5.5 <[email protected]> * feat(gateway)!: every capability registration states its scope `PUT /_capability` requires `scope`: "any" for a capability that pays for any content, or a pool owner's signed namespace scope. A body with no scope is refused, so no capability pays for everything by accident. `decdn pool assign --any-namespace` prints the "any" registration. A loopback gateway selects a scoped capability by the namespace the request's decdn: URI names (`?ns=`, or the site label). A top-level GET navigation passes its browser check from any site, so a link on any page opens loopback content. The gateway_pointer journey funds its gateway with a namespace-scoped capability. Moves the SDK pins to decdn/sdk-typescript@1dab70e and decdn/sdk-python@3b502a9, which send the scope and map 503 to PAYMENT_REQUIRED. Co-Authored-By: Claude Opus 5.5 <[email protected]> * docs(adr): point ADR 003 and the overview at the gateway's capability scope Co-Authored-By: Claude Opus 5.5 <[email protected]> --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
PR review: #28 (pending-key capabilities, no loopback token)ContextReview of PR #28 (local branch Critical — fake gateway diverges from the real gateway
Important
Suggestions
Strengths
Next stepFix 1–3 (fake parity, with contract cases), then 4–6; run |
Port the /_decdn/ redirect tests from #30 to capabilities-only public gateways: no allowance, and no pull means nothing paid. Co-Authored-By: Claude Opus 5.5 <[email protected]>
… gate The fake gateway pays with a capability scoped to the request's namespace before an earlier "any" one; on a public gateway, only a namespace pointer selects a scope, for its own bundle. A top-level GET navigation passes the loopback browser gate from any page, a site spends only for a navigation to a document, and the scope signature's length is checked after the key. The SDK refuses a malformed scope (no namespace, an id outside u64 >= 1, a signature that is not 65 bytes) with CONFIG before any request, maps a non-JSON answer to HTTP, keeps PAYMENT_REQUIRED for a 503 that names a fallback URI, and opens the site on a site page whatever gatewayUrl names. README documents the payment order, the public scope rule and the gate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Addressed in 6536cd8, checked against decdn Fixed
Not changed
Verification
🤖 Generated with Claude Code |
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…contract - open() takes localhost, any 127.0.0.0/8 address and [::1] (in any IPv6 spelling) as a loopback gateway; an IPv4-mapped address stays public. - delegate(), registerCapability(), capabilities() and pointer.set read the gateway's JSON field by field: an answer that is not JSON, or lacks a field its contract names, or has one of another type, is HTTP with the body. A string the gateway writes in an integer field stays a type error. - The loopback API's CONFIG message says the SDK offers it on a loopback client, since a public gateway's bare host serves it too. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Namespace validation still coerces unsupported input types or leaks native exceptions instead of CONFIG errors, risking unintended namespace selection and violating the validation-before-sending contract.
1 open issue
What changed in this PR
Updates the TypeScript SDK to match the gateway’s pending-key capability model, replacing loopback tokens and public daily allowances with capability-based payment.
Changes:
- Adds scoped capability registration, pending-key handling, and stricter response validation.
- Removes token helpers and updates client selection and payment-error handling.
- Aligns the fake gateway, contract tests, packaging, and documentation with the new protocol while retaining older public-gateway coverage.
| File | Description |
|---|---|
test/unit/pointer.test.ts |
Tests malformed pointer responses and funds fixtures. |
test/unit/node.test.ts |
Removes token-helper tests. |
test/unit/loopback.test.ts |
Covers pending keys, scopes, validation, and payment order. |
test/unit/client.test.ts |
Updates context, browser-gate, and payment tests. |
test/support/dcap.ts |
Adds synthetic capability-token generation. |
test/scripts/decdn-contract.test.ts |
Checks release-version filtering consistency. |
test/fake-gateway.ts |
Models capability payment, registration, and browser gates. |
test/contract/public.test.ts |
Covers the public capability API and preflights. |
test/contract/loopback.test.ts |
Exercises the tokenless pending-key protocol. |
test/contract/fixture.ts |
Adopts pending-key fixtures and public capability funding. |
test/browser/setup.ts |
Funds the browser-test gateway. |
src/pointer.ts |
Shares namespace validation and validates pointer responses. |
src/node.ts |
Removes Node token helpers. |
src/loopback.ts |
Implements scoped registration and validated API responses. |
src/index.ts |
Exports scope and registration types. |
src/http.ts |
Adds response validation and revises payment-error mapping. |
src/errors.ts |
Updates error codes for the new protocol. |
src/client.ts |
Removes token handling and revises context selection. |
scripts/decdn-contract.sh |
Excludes incompatible older loopback journeys. |
scripts/check-package.sh |
Checks the remaining package entry point. |
scripts/build.mjs |
Stops building the Node helper entry point. |
README.md |
Documents capability payment, migration, and compatibility. |
package.json |
Removes the ./node export. |
CONTRIBUTING.md |
Explains older-release loopback exclusions. |
.github/workflows/ci.yml |
Updates import checks for the remaining entry point. |
Review effort: Balanced
integer() passed anything to BigInt, so a JavaScript caller's `true` or `"7"` became an id and `null` or `"x"` threw a native error. It now gives CONFIG for any type but bigint and number, before a request is sent. Co-Authored-By: Claude Opus 5.5 <[email protected]>

The
decdn gatewaychanges how it pays and who may use it. This PR updates the SDK, the fake gateway and the contract suite to match."any"or an owner-signed namespace scope."any"one pays.?ns=or the site's label)./_decdn/for the site's own hash.?ns=and<ns>.<hash32>select no scope.The gateway change is on decdn
main, which pins this branch in.github/sdk-typescript.sha. sdk-python makes the same change in decdn/sdk-python#15, and the two SDKs behave the same.Public API changes (breaking)
OpenOptions.tokenandOpenOptions.hostare removed.localhostor a loopback address (127.0.0.0/8,[::1]in any spelling) opens a loopback client. Any other URL opens a public one, including an IPv4-mapped address,0.0.0.0anddecdn.localhost.open()opens that site, whatevergatewayUrlnames.x-decdn-token, nox-decdn-hostand noOrigin. From Node,fetchsendsUser-Agent: node, which the gate passes.@decdn/client/nodesubpath, withreadLoopbackTokenanddefaultDataDir.UNAUTHORIZEDerror code: a 401 maps toHTTP.POOL_UNFUNDED.client.loopback.delegate()returns the gateway's pending key. It is the same address on every call until a capability claims it. The gateway keeps keys in memory, so a restart loses them.client.loopback.registerCapability({ capability, scope }):scopeis"any"or{ namespaces, signature }, exported asCapabilityScope.Registration, newly exported:{ signer, pool, expiry, namespaces? }.CONFIGan emptynamespaces, an id that is not a u64 of at least 1, or a signature that is not0xplus 65 bytes. Otherwise it sends the signature as given, and the gateway checks it.client.loopback.capabilities()lists the held capabilities in registration order, asRegisteredCapabilityentries{ cap, expiry, namespaces?, pool, signer, spent }.namespacesis present only on a namespace-scoped capability.client.loopbackon a non-loopback client throwsCONFIG: "the SDK offers the delegate and capability API on a loopback client alone: open one on a localhost or loopback-address URL".PAYMENT_REQUIREDis a loopback gateway's plain-text 402, and a public gateway's 503 that names a fallback URI. It carriesretryAfterSecsandfallbackUri. Any other 503 isHTTP.HTTP: "the gateway's answer to<path>is not the JSON its contract names: …". The error carries the body. It no longer surfaces as a rawSyntaxErroror a silentundefined.Fake gateway
Loopback gate. A top-level
GET(Sec-Fetch-Mode: navigateandSec-Fetch-Dest: document) passes first. Otherwise, in this order:Sec-Fetch-Site: cross-sitegives 403.Originthat is neither the bare host nor a site originhttp://[<ns>.]<hash32>.localhost:<port>gives 403.Sec-Fetch-Site, on a request with anOriginor aMozilla/user agent, gives 403.Loopback routing.
same-origin,none, or noSec-Fetch-Site), and for a navigation to a document.API, both modes:
/_delegatekeeps a single pending key.PUT /_capability, in the real gateway's check order:"any"or a non-empty list of u64s (0 included) with an even-length hex signature.namespacesfor a namespace scope.OPTIONS. On a public gateway,/_delegate,/_capabilityand/_statusanswer on the bare host to any origin, with a 204 preflight, and answer 404 on site hosts.Paying.
drainedretires its capability, and the next one pays.the gateway holds no capability that can pay: register one with PUT /_capability.{"error": "the gateway cannot pay right now", "retry_after_secs": 60, "uri": ...}, withRetry-After: 60and theLinkfallback.fake.fund()gives a test a capability that pays.Contract suite and released gateways
describe.skipIf(!shippedAfter("0.3.1"))):token. Itscapabilitiesfield is one{ capability }per flavour, each from its own pool, all issued to the pending key. Real-gateway registrations passscope: "any".headreads;if (shippedAfter("0.3.1"))):/_delegate,/_capabilityand/_status(with noallowance) on the bare host to any origin, and the API preflight on the bare host only. The fixture registers a capability before the suite, as decdn's harness does.scripts/decdn-contract.sh --tagleaves out the loopback journey for any release at or before v0.3.1.released_afteragainstshippedAfter.HTTP. The README says so.Docs
The README covers:
NETWORK;0.1, 0.2row in the compatibility table.The docs link the ADR sections
#capabilities,#scopeand#cross-origin-reads.Gates
Local, on b9ae4e2:
pnpm lint(eslint, prettier, tsc) passes.pnpm test:coverage: 285 passed, 43 skipped, 94.3% statement coverage. One test fails:publish.test.ts"stops on a version npm has from another tarball", which fails on macOS because itstarhas no--mtime. CI runs it on Linux.pnpm test:browserdid not run locally, because Playwright's Chromium is not installed here. CI's browser job runs it.Real gateway (
scripts/decdn-contract.sh --ref main):main, and decdnmain's harness does not write itsdocs/index.htmlfixture yet (gateway: a directory under a site's /_decdn/ redirects to a URI the gateway refuses decdn#2818).On b9ae4e2, all 17 CI checks pass, including Node 20.19/22/24/26, browser (Chromium), coverage, package and the v0.3.0/v0.3.1 release contracts.
🤖 Generated with Claude Code