1. Mint Read-Only Token & Read Calendar
Mints a token scoped strictly to calendar:read with a $1.00 spend cap and 60s TTL, then calls POST /api/protected/read-calendar.
Cryptographic Capability Attenuation · Browser ↔ Edge Worker
Delegate narrow, short-lived tool authority from the browser without exposing static API keys or ambient cookies. Every capability proof carries signed scopes, an origin binding, a hard USD spend ceiling, a replay nonce, and a short TTL enforced by an edge WebCrypto verifier and SQLite Durable Object ledger (DelegationLedger).
Non-extractable WebCrypto ECDSA P-256 keys combined with WebAuthn Level 3 prf confirmation and Durable Object spend ledgers enforce verifiable per-action scope, TTL, replay nonce, and cumulative dollar caps without exposing long-lived account secrets.
Confirm: dollar-cap overflow, nonce replay, payload tampering, and out-of-scope calls reject in DelegationLedger while valid attenuated tokens succeed. Falsify: key derivation or passkey prompt latency (measured below) creates UX friction pushing developers back to ambient OAuth.
Run Try 1 (Expect 200) to mint a calendar:read proof and call /read-calendar, then Try 2 (Expect 403) for scope escalation and spend overflow, and Try 3 (Expect 401) for 1-byte tamper and expired TTL.
The W3C WebAuthn PRF extension requests a deterministic pseudo-random evaluation from a platform or roaming authenticator during user verification. Hardware Passkey mode executes a live navigator.credentials.create() or get() call with extensions: { prf: { eval: { first } } } and binds the returned credential ID and salt metadata into the signed ECDSA P-256 capability claims.
Mints a token scoped strictly to calendar:read with a $1.00 spend cap and 60s TTL, then calls POST /api/protected/read-calendar.
Calls /send-email without email:send (403 insufficient_scope), then mints a $5.00 cap token and requests $25.00 on /transfer-funds (403 spend_cap_exceeded).
Mutates 1 byte inside the signed base64url payload (401 invalid_signature) and sends an already-expired TTL token (401 token_expired).
Authorization Header (Wire Proof)
Authorization: Cap <mint a token to inspect compact base64url proof>
Decoded Capability Claims (Payload)
{}
Last HTTP Request & Edge Verification Response
{}
Ordered Verification Checks
Public JWK Stored in Edge Durable Object (Private parameter d never leaves browser)
{}
GET /api/ledger/:sessionId)
0 events
| Time | Endpoint | Scope | Spend | Decision | Reason | Remaining |
|---|---|---|---|---|---|---|
| No edge ledger entries recorded for this session yet. | ||||||
Raw Ledger Snapshot JSON
{}
Ambient OAuth cookies and static bearer keys carry full account authority on every request. When an automated tool pipeline calls an API, the server cannot distinguish whether the user authorized a $0 calendar read or an unbounded funds transfer.
Attenuate authority per task before execution: bind exact tool scopes, a maximum dollar spend cap, the target origin, and an expiration timestamp into a compact cryptographic proof verified independently of ambient browser state.
Generate a non-extractable ECDSA P-256 keypair inside crypto.subtle (optionally confirmed by a WebAuthn Level 3 PRF passkey prompt), register the public JWK at the edge, and sign Cap <payload>.<sig> tokens checked against signature, TTL, origin, scope, nonce, and cumulative spend.
Mint short-lived ECDSA P-256 capability tokens in the browser via non-extractable crypto.subtle keys and WebAuthn Level 3 PRF confirmation, then enforce scope, origin, nonce uniqueness, and cumulative spend ceilings in the DelegationLedger SQLite Durable Object.
// Long-lived Bearer secret or ambient cookie grants unbounded scope and spend
const headers = {
Authorization: `Bearer ${process.env.SERVICE_API_KEY}`,
"Content-Type": "application/json",
};
// Downstream endpoint accepts the static secret with no per-call budget ceiling
await fetch("/api/protected/transfer-funds", {
method: "POST",
credentials: "include", // Ambient cookies attach automatically on requests
headers,
body: JSON.stringify({ amount: 250, destination: "acct_vendor" }),
});
// public/lib/webcrypto-cap.js + public/app.js — hardware confirmation + scoped P-256 proof
const prf = await runWebAuthnPrfConfirmation({ rpId: location.hostname, sessionId });
const { privateKey, publicKey } = await generateSessionKeyPair(); // extractable = false
await fetch("/api/delegate/register", {
method: "POST",
headers: { "Content-Type": "application/json", "X-Session-Id": sessionId },
body: JSON.stringify({ sessionId, keyId, publicKeyJwk: await exportPublicJwk(publicKey), delegationMode: "webauthn-prf-bound", prfCredentialId: prf.credentialId }),
});
const token = await signCapabilityToken({
tokenId, keyId, issuer: `session:${sessionId}`, origin: location.origin,
scopes: ["payments:transfer"], maxSpendUsd: 25, spentBefore: 0, iat, exp: iat + 60, nonce,
delegationMode: "webauthn-prf-bound", prfCredentialId: prf.credentialId,
}, privateKey);
await fetch("/api/protected/transfer-funds", {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: `Cap ${token}`, "X-Request-Nonce": reqNonce, "X-Session-Id": sessionId },
body: JSON.stringify({ amount: 12.5 }),
});
End-to-end wiring from the policy form in public/index.html, the CapabilityClaims schema in src/capability.ts, WebCrypto/PRF minting in public/app.js (using public/lib/webcrypto-cap.js), and SQLite DelegationLedger verification in src/worker.ts.
<!-- 1. Page HTML Setup (public/index.html) -->
<input type="radio" name="delegation-mode" value="webauthn-prf-bound">
<button type="button" id="btn-passkey-gate">Confirm Passkey + PRF Now</button>
<form id="mint-form">
<input type="checkbox" id="scope-calendar" name="scope" value="calendar:read" checked>
<input type="checkbox" id="scope-email" name="scope" value="email:send">
<input type="checkbox" id="scope-payments" name="scope" value="payments:transfer">
<input type="number" id="input-max-spend" step="0.50" value="5.00" required>
<input type="number" id="input-ttl" step="1" value="60" required>
<button type="submit" id="btn-mint">Register Key & Mint Cap Token</button>
</form>
<script type="module" src="/app.js"></script>
// 2. Concrete Capability Claims Schema (src/capability.ts)
const claims = {
tokenId: `cap_${crypto.randomUUID().slice(0, 12)}`,
keyId: state.keyId,
issuer: `session:${state.sessionId}`,
origin: window.location.origin,
scopes: ["calendar:read", "email:send", "payments:transfer"],
maxSpendUsd: 5.00,
spentBefore: 0,
iat: nowSec,
exp: nowSec + 60,
nonce: `n_${nonceHex}`,
delegationMode: "webauthn-prf-bound",
prfCredentialId: prfResult.credentialId,
prfSaltHex: prfResult.prfSaltHex,
};
// 3. Page Bootstrap & DelegationLedger SQLite Enforcement (public/app.js + src/worker.ts)
import { generateSessionKeyPair, exportPublicJwk, runWebAuthnPrfConfirmation, signCapabilityToken } from "/lib/webcrypto-cap.js";
const prfResult = await runWebAuthnPrfConfirmation({ rpId: window.location.hostname, sessionId: state.sessionId });
state.keyPair = await generateSessionKeyPair(); // ECDSA P-256, extractable: false
state.publicKeyJwk = await exportPublicJwk(state.keyPair.publicKey);
await fetch("/api/delegate/register", {
method: "POST",
headers: { "Content-Type": "application/json", "X-Session-Id": state.sessionId },
body: JSON.stringify({ sessionId: state.sessionId, keyId: state.keyId, publicKeyJwk: state.publicKeyJwk, delegationMode: state.delegationMode, prfCredentialId: prfResult.credentialId }),
});
const tokenString = await signCapabilityToken(claims, state.keyPair.privateKey);
await fetch("/api/protected/transfer-funds", {
method: "POST",
headers: { "Content-Type": "application/json", Authorization: `Cap ${tokenString}`, "X-Request-Nonce": requestNonce, "X-Session-Id": state.sessionId },
body: JSON.stringify({ amount: 2.00 }),
});
// src/capability.ts + src/worker.ts — verify P-256 signature before trusting claims, then debit DO SQLite
const result = await verifyCapabilityToken({
tokenString, publicKeyJwk, requiredScope, requestedSpendUsd, expectedOrigin, cumulativeSpentUsd: priorSpendSnapshot,
});
// Inside DelegationLedger.verifyAndRecord() — atomic SQLite write inside Durable Object
this.ctx.storage.sql.exec("INSERT INTO used_request_nonces (nonce, token_id, created_at) VALUES (?, ?, ?)", requestNonce, tokenId, now);
this.ctx.storage.sql.exec(
"INSERT INTO token_spend (token_id, spent_usd, max_spend_usd, revoked, updated_at) VALUES (?, ?, ?, 0, ?) " +
"ON CONFLICT(token_id) DO UPDATE SET spent_usd = excluded.spent_usd, updated_at = excluded.updated_at",
tokenId, nextSpent, claims.maxSpendUsd, now,
);
Static bearer API keys shared across automated pipelines and ambient session cookies that authorize unconstrained mutations on an origin.
Per-token origin binding, scope lists (calendar:read, email:send, payments:transfer), strict exp TTLs, single-use X-Request-Nonce checks, and atomic SQLite spend ceilings (token_spend).
WebAuthn Level 3 prf extension availability varies across authenticators and OS keychains, and non-extractable browser keys still require registering the public JWK in the edge ledger before enforcement.