Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
dist/
node_modules/
target/
.wrangler/
bench/.trace/
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Use this deployment to test an implementation.
| :------------------------------------------------- | :------------------------------------------- |
| [Browser extension](./examples/browser-extension/) | Adds a `Signature` on every outgoing request |
| [Rust](./examples/rust/) | Signs a hardcoded test request |
| [Cloudflare Workers](./examples/signing-worker/) | Forwards requests to a target, signed |

### Verifying

Expand Down
11 changes: 11 additions & 0 deletions examples/signing-worker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "signing-worker",
"private": true,
"scripts": {
"deploy": "npx wrangler deploy",
"dev": "npx wrangler dev"
},
"dependencies": {
"web-bot-auth": "*"
}
}
39 changes: 39 additions & 0 deletions examples/signing-worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { sign, SIGNATURE_AGENT_HEADER } from "web-bot-auth";
import { signerFromJWK } from "web-bot-auth/crypto";

interface Env {
TARGET: string;
SIGNATURE_AGENT: string;
// Set with `wrangler secret put JWK`. Defaults to the published RFC 9421 test key.
JWK?: string;
}

// Published RFC 9421 test key. Never use it in production.
const RFC_9421_ED25519_TEST_KEY = {
kty: "OKP",
crv: "Ed25519",
d: "n4Ni-HpISpVObnQMW0wOhCKROaIKqKtW_2ZYb2p9KcU",
x: "JrQLj5P_89iXES9-vFgrIy29clF9CC_oPPsw3c5D0bs",
};

export default {
async fetch(request: Request, env: Env): Promise<Response> {
const signer = await signerFromJWK(
env.JWK ? JSON.parse(env.JWK) : RFC_9421_ED25519_TEST_KEY
);
const outgoing = new Request(env.TARGET, request);
outgoing.headers.set(
SIGNATURE_AGENT_HEADER,
`sig1="${env.SIGNATURE_AGENT}";type=directory`
);
const now = new Date();
const fields = await sign(outgoing, {
signer,
created: now,
expires: new Date(now.getTime() + 300_000),
});
outgoing.headers.set("Signature", fields.signature);
outgoing.headers.set("Signature-Input", fields.signatureInput);
return fetch(outgoing);
},
};
9 changes: 9 additions & 0 deletions examples/signing-worker/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "signing-worker",
"main": "src/index.ts",
"compatibility_date": "2026-09-03",
"vars": {
"TARGET": "https://http-message-signatures-example.research.cloudflare.com/debug",
"SIGNATURE_AGENT": "https://http-message-signatures-example.research.cloudflare.com",
},
}
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading