Skip to content

feat(gateway): answer every origin on a public gateway, and run the TypeScript SDK contract against it - #2628

Merged
thiras merged 10 commits into
mainfrom
feat/typescript-sdk
Oct 26, 2026
Merged

thiras merged 10 commits into
mainfrom
feat/typescript-sdk

Conversation

@thiras

@thiras thiras commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What

The gateway side of the TypeScript SDK. The SDK itself, @decdn/client, lives in decdn/sdk-typescript.

  • Gateway (decdn-cli): a public gateway (--public-url) answers every origin. Every answer carries Access-Control-Allow-Origin: * and exposes the headers a reader needs (length, range, type, ETag, Retry-After, Link). OPTIONS on a known host is a 204 preflight: GET, HEAD with range on content, and PUT with content-type on /_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.
  • Pinned vectors: a_fixed_grant_encodes_to_a_pinned_token pins a dcap1: token and a_fixed_pointer_signs_to_a_pinned_signature a pointer signature. The SDK decodes and signs the same bytes.
  • Contract run: crates/e2e/tests/gateway_sdk.rs (features anvil-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 checkout DECDN_SDK_DIR names, against the gateway. The SDK runs the same suite against its fake gateway, so the two cannot drift apart unnoticed. The new CI job anvil-e2e-sdk checks out decdn/sdk-typescript at main and gates CI success. It runs that checkout with no persisted credentials and no install scripts, and saves no caches.

Breaking

Behaviour change of the public gateway: OPTIONS answered 404 and is now a 204 preflight, and every public answer carries CORS headers. A proxy in front of a public gateway must pass OPTIONS and these headers through (docker/README.decdn.md). Loopback gateways are unchanged.

Reviewer notes

  • Read first: crates/cli/src/commands/gateway.rs (handle, answer, public_preflight, readable_anywhere) and its new tests.
  • A gateway change the SDK can observe now needs a matching decdn/sdk-typescript PR that updates its fake gateway. anvil-e2e-sdk fails until that PR lands (CONTRIBUTING § TypeScript SDK contract run).
  • anvil-e2e-sdk runs the SDK's main, not a pinned commit, so it always checks the latest contract. Code from that repository runs in this job, so branch protection on decdn/sdk-typescript main matters.
  • The SDK names the release that carries this change (expected v0.3.0) as its floor for browser and public use. Deploying CORS on decdn.link is an ops task.

Verification

  • pre-commit run --all-files → pass
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features → pass
  • cargo nextest run --workspace → 5800/5800
  • DECDN_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. Without DECDN_SDK_DIR the test fails with the setup message.
  • make -C adr check-refs → pass; actionlint reports nothing new on ci.yml.

Always:

  • pre-commit run --all-files
  • CARGO_BUILD_WARNINGS=deny cargo clippy --workspace --all-targets --all-features
  • cargo nextest run
  • PR title uses an allowed type and a lowercase subject

Only if touched:

  • adr/: make -C adr check-refs
  • User-visible change: CHANGELOG.md entry added by hand

🤖 Generated with Claude Code

Copilot AI balanced review requested due to automatic review settings October 26, 2026 14:37
@github-actions

Copy link
Copy Markdown

Gas snapshot

No gas changes vs base.

@github-code-quality

github-code-quality Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Code coverage overview

Languages: Rust

Rust / code-coverage/cargo-llvm-cov

main 3b079e7 feat/typescript-sdk 01c62ea +/-
77% 77% 0%
View coverage of the 3 most impacted files.
File main 3b079e7 feat/typescript-sdk 01c62ea +/-
crates/client/src/lib.rs 89% 89% 0%
crates/node/src...gin/pull_leg.rs 84% 84% 0%
crates/cli/src/...ands/gateway.rs 76% 77% +1%

ℹ️ Calculations represent line coverage. Results may change as calculations are updated.


Updated October 26, 2026 16:32 UTC

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread sdk/typescript/src/mime.ts Resolved
Comment thread sdk/typescript/src/uri.ts Resolved
thiras and others added 5 commits October 26, 2026 17:47
`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]>
@thiras
thiras force-pushed the feat/typescript-sdk branch from 0791ce7 to d1d870b Compare October 26, 2026 14:56
@thiras thiras changed the title feat(sdk): @decdn/client TypeScript SDK over the gateway, and CORS on public gateways feat(gateway): answer every origin on a public gateway, and run the TypeScript SDK contract against it Oct 26, 2026
@thiras
thiras requested a balanced review from Copilot October 26, 2026 15:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

thiras and others added 3 commits October 26, 2026 19:05
…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]>
Comment thread .github/workflows/ci.yml Fixed
thiras and others added 2 commits October 26, 2026 19:18
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]>
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.

3 participants