Repository navigation
feat(gateway): answer every origin on a public gateway, and run the TypeScript SDK contract against it - #2628
Conversation
Gas snapshotNo gas changes vs base. |
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 3 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
🟡 Changes recommended
Valid filenames can resolve to the wrong entry or cause metadata lookup to throw a TypeError.
2 open issues
1 file not reviewed
sdk/typescript/pnpm-lock.yaml: Generated file
What changed in this PR
Adds @decdn/client, a TypeScript SDK that accesses deCDN through the existing HTTP gateway, with public-gateway CORS support for browser clients.
Changes:
- Adds streamed BLAKE3 verification, typed errors, capability helpers, and namespace pointer signing.
- Adds public CORS responses and shared SDK tests against fake and real gateways.
- Adds SDK build, CI, publishing, and usage documentation.
| File | Description |
|---|---|
| sdk/typescript/vitest.config.ts | Defines unit, contract, and browser test projects. |
| sdk/typescript/tsconfig.json | Configures strict TypeScript checks. |
| sdk/typescript/tsconfig.build.json | Configures declaration generation. |
| sdk/typescript/test/unit/uri.test.ts | Tests URI parsing and formatting. |
| sdk/typescript/test/unit/pointer.test.ts | Tests pointer signing and publication. |
| sdk/typescript/test/unit/node.test.ts | Tests gateway token loading. |
| sdk/typescript/test/unit/manifest.test.ts | Tests manifest parsing and verification. |
| sdk/typescript/test/unit/loopback.test.ts | Tests loopback capability APIs. |
| sdk/typescript/test/unit/hash.test.ts | Tests hashing and site-label encoding. |
| sdk/typescript/test/unit/client.test.ts | Tests client contexts, verification, and errors. |
| sdk/typescript/test/unit/capability.test.ts | Tests capability token decoding. |
| sdk/typescript/test/support/host-fetch.ts | Routes test requests through one listener. |
| sdk/typescript/test/fixtures/pointer.json | Pins Rust-compatible pointer vectors. |
| sdk/typescript/test/fixtures/capability.json | Pins Rust-compatible capability vectors. |
| sdk/typescript/test/contract/public.test.ts | Tests the public gateway contract. |
| sdk/typescript/test/contract/loopback.test.ts | Tests the loopback gateway contract. |
| sdk/typescript/test/contract/fixture.ts | Selects fake or real gateway fixtures. |
| sdk/typescript/test/browser/smoke.test.ts | Tests browser CORS and verification. |
| sdk/typescript/test/browser/setup.ts | Starts the browser test gateway. |
| sdk/typescript/src/verify.ts | Guards streamed bodies and collects bytes. |
| sdk/typescript/src/uri.ts | Parses and formats deCDN URIs. |
| sdk/typescript/src/pointer.ts | Signs and submits namespace pointers. |
| sdk/typescript/src/node.ts | Loads local gateway tokens. |
| sdk/typescript/src/mime.ts | Classifies entry content types and rewriting. |
| sdk/typescript/src/manifest.ts | Parses and verifies bundle manifests. |
| sdk/typescript/src/loopback.ts | Implements delegate and capability APIs. |
| sdk/typescript/src/index.ts | Exports the SDK API. |
| sdk/typescript/src/http.ts | Wraps fetch and maps gateway errors. |
| sdk/typescript/src/hex.ts | Adds hexadecimal conversion helpers. |
| sdk/typescript/src/hash.ts | Provides BLAKE3 hashing helpers. |
| sdk/typescript/src/errors.ts | Defines typed SDK errors. |
| sdk/typescript/src/capability.ts | Decodes capability tokens. |
| sdk/typescript/src/base32.ts | Converts hashes to site labels. |
| sdk/typescript/scripts/build.mjs | Builds ESM, CommonJS, and declarations. |
| sdk/typescript/README.md | Documents SDK usage and compatibility. |
| sdk/typescript/package.json | Defines package exports, dependencies, and scripts. |
| sdk/typescript/LICENSE-MIT | Includes the MIT license. |
| sdk/typescript/LICENSE-APACHE | Includes the Apache license. |
| sdk/typescript/eslint.config.mjs | Configures SDK linting. |
| sdk/typescript/.prettierrc.json | Enables default formatting rules. |
| sdk/typescript/.prettierignore | Excludes generated files from formatting. |
| sdk/typescript/.gitignore | Excludes local build and test artifacts. |
| scripts/tests/test_publish_npm_gates.py | Tests publishing input validation. |
| scripts/publish-npm.sh | Publishes SDK releases from signed tags. |
| RELEASING.md | Documents independent SDK releases. |
| docker/README.decdn.md | Documents proxy requirements for CORS. |
| crates/incentive/src/capability_grant/tests.rs | Pins the capability encoding vector. |
| crates/e2e/tests/gateway_sdk.rs | Runs SDK contract tests against real gateways. |
| crates/e2e/Cargo.toml | Gates the SDK integration test target. |
| crates/cli/src/commands/gateway/tests.rs | Tests public CORS and loopback isolation. |
| crates/cli/src/commands/gateway/pointer/tests.rs | Pins pointer signing vectors. |
| crates/cli/src/commands/gateway.rs | Adds public CORS headers and preflight handling. |
| CONTRIBUTING.md | Documents SDK development and testing. |
| CLAUDE.md | Documents SDK ownership and fake-gateway synchronization. |
| CHANGELOG.md | Records the SDK and public CORS changes. |
| adr/appendix-gateway.md | Specifies cross-origin gateway behavior. |
| .github/workflows/ci.yml | Adds SDK and real-gateway CI gates. |
Review effort: Balanced
`decdn gateway --public-url` adds `Access-Control-Allow-Origin: *` and exposes the headers a reader needs (length, range, type, ETag, Retry-After, Link) on every answer, and answers `OPTIONS` on a known host with a 204 preflight: `GET, HEAD` with `range` on content, `PUT` with `content-type` on `/_pointer`. `/_delegate` and `/_capability` stay 404, and a loopback gateway sends no CORS header outside its API, so its token never becomes sendable cross-origin. A web page, and the TypeScript SDK in a browser, read content and the 402/503 fallback URI straight from a public gateway. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`a_fixed_grant_encodes_to_a_pinned_token` pins the `dcap1:` token of a fixed grant, and `a_fixed_pointer_signs_to_a_pinned_signature` the signing hash and signature of a fixed namespace pointer. The TypeScript SDK (decdn/sdk-typescript) decodes and signs the same vectors, so a codec or EIP-712 change on either side fails one of them. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`crates/e2e/tests/gateway_sdk.rs` (features `anvil-e2e` + `sdk-e2e`) stands up a chain, a node and a real `decdn gateway`: public, with a namespace the fixture key owns, and loopback, with a capability the owner issued to a minted delegate. It writes what the suite needs to a fixture file and runs the contract suite of decdn/sdk-typescript, the checkout `DECDN_SDK_DIR` names, against it. The SDK runs the same suite against its fake gateway, so the fake and the binary cannot drift apart unnoticed. A missing checkout, `node` or `node_modules` fails the test. CI: `anvil-e2e-sdk` checks out decdn/sdk-typescript at `main` and runs the target on Rust or Solidity changes; it gates `CI success`. Co-Authored-By: Claude Opus 5.5 <[email protected]>
CONTRIBUTING gains the `DECDN_SDK_DIR` contract run against a decdn/sdk-typescript checkout, and CLAUDE.md the rule that a gateway change the SDK can observe needs a matching SDK PR. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…scripts or saved caches The job runs decdn/sdk-typescript's main. Neither checkout persists its token, pnpm runs no install scripts, and the job saves no rust, pnpm or solc cache, so code from the other repository cannot reach what decdn's main-branch jobs restore. Co-Authored-By: Claude Opus 5.5 <[email protected]>
0791ce7 to
d1d870b
Compare
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
…CORS docs A site or namespace host answers `PUT /_pointer` with 404, so its preflight now does too instead of admitting a PUT it then refuses. The CORS header values are constants, so a bad value is a compile error rather than a panic on every public answer. The module, `handle` and test docs say what the code does: loopback answers cross-origin only on its API; every public answer is readable anywhere. The appendix section is in plain STE, names the preflight's host and metric, and the CHANGELOG entry carries the PR number and the old 404/405 answers. The Docker overview tells the proxy to add no CORS headers of its own. Tests now cover a blob HEAD, a redirect, namespace-host answers and the closed `/_capability` preflight. Co-Authored-By: Claude Opus 5.5 <[email protected]>
`run_suite` reads vitest's JSON report and requires every collected test to pass, so a suite that skips (a fixture-mode mismatch, a todo) fails. The harness sets DECDN_CONTRACT_REQUIRED=1, so the suite cannot fall back to its fake, and afterwards checks state only the suite's own requests create: the namespace pointer on the public run, the registered capability on loopback. vitest is killed with the test, the start-up loops stop on a gateway that exited, every harness request has a 10s timeout, the token must be whole before it is used, and a gateway that crashed under the suite fails the run. nextest gives this target no retries and a cap above its own timeout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The job checks out the SDK at the commit `.github/sdk-typescript.sha` names, not its `main`: new SDK code runs in decdn CI only once a decdn PR moves the pin, and an SDK commit can no longer turn decdn's `main` red on its own. A gateway change the SDK can observe lands its SDK PR first, then moves the pin with the gateway change. The job restores the journeys' Rust cache read-only instead of a key nothing saves, and runs nextest with `--no-tests=fail`. CONTRIBUTING and CLAUDE.md describe the pin and the order. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The SDK pin moves only in a PR, so a push or dispatch run tests nothing new, and it would run decdn/sdk-typescript's code in the default branch's cache scope (CodeQL: cache poisoning through a privileged checkout). Co-Authored-By: Claude Opus 5.5 <[email protected]>
anvil-e2e-sdk runs decdn/sdk-typescript's code. Inside ci.yml, which also runs on push and dispatch, CodeQL flags it as cache poisoning through a privileged checkout, whatever the job's own if. In .github/workflows/sdk-contract.yml, triggered by pull_request alone (paths: Rust, contracts, the pin, nextest config), it never runs in the default branch's context. It leaves CI success; the branch ruleset can require its check. Co-Authored-By: Claude Opus 5.5 <[email protected]>

What
The gateway side of the TypeScript SDK. The SDK itself,
@decdn/client, lives in decdn/sdk-typescript.decdn-cli): a public gateway (--public-url) answers every origin. Every answer carriesAccess-Control-Allow-Origin: *and exposes the headers a reader needs (length, range, type, ETag, Retry-After, Link).OPTIONSon a known host is a 204 preflight:GET, HEADwithrangeon content, andPUTwithcontent-typeon/_pointer. A loopback gateway is unchanged: it sends no CORS outside its API, so its token never becomes sendable cross-origin. Spec: appendix-gateway § Cross-origin reads.a_fixed_grant_encodes_to_a_pinned_tokenpins adcap1:token anda_fixed_pointer_signs_to_a_pinned_signaturea pointer signature. The SDK decodes and signs the same bytes.crates/e2e/tests/gateway_sdk.rs(featuresanvil-e2e+sdk-e2e) stands up a chain, a node and a real gateway in public and loopback mode. It runs the SDK's contract suite, from the checkoutDECDN_SDK_DIRnames, against the gateway. The SDK runs the same suite against its fake gateway, so the two cannot drift apart unnoticed. The new CI jobanvil-e2e-sdkchecks outdecdn/sdk-typescriptatmainand gatesCI success. It runs that checkout with no persisted credentials and no install scripts, and saves no caches.Breaking
Behaviour change of the public gateway:
OPTIONSanswered 404 and is now a 204 preflight, and every public answer carries CORS headers. A proxy in front of a public gateway must passOPTIONSand these headers through (docker/README.decdn.md). Loopback gateways are unchanged.Reviewer notes
crates/cli/src/commands/gateway.rs(handle,answer,public_preflight,readable_anywhere) and its new tests.decdn/sdk-typescriptPR that updates its fake gateway.anvil-e2e-sdkfails until that PR lands (CONTRIBUTING § TypeScript SDK contract run).anvil-e2e-sdkruns the SDK'smain, not a pinned commit, so it always checks the latest contract. Code from that repository runs in this job, so branch protection ondecdn/sdk-typescriptmainmatters.Verification
pre-commit run --all-files→ passCARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features→ passcargo nextest run --workspace→ 5800/5800DECDN_SDK_DIR=<sdk-typescript checkout> cargo nextest run -p decdn-e2e --features anvil-e2e,sdk-e2e --test gateway_sdk→ 2/2: the contract suite passes 11/11 on loopback and 12/12 on public, including against a fresh clone installed with--ignore-scripts. WithoutDECDN_SDK_DIRthe test fails with the setup message.make -C adr check-refs→ pass; actionlint reports nothing new onci.yml.Always:
pre-commit run --all-filesCARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-featurescargo nextest runOnly if touched:
adr/:make -C adr check-refsCHANGELOG.mdentry added by hand🤖 Generated with Claude Code