Skip to content
Open
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 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/) | Signs arbitrary outgoing requests |

### Verifying

Expand Down
12 changes: 12 additions & 0 deletions examples/signing-worker/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# http://editorconfig.org
root = true

[*]
indent_style = tab
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.yml]
indent_style = space
167 changes: 167 additions & 0 deletions examples/signing-worker/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Logs

logs
_.log
npm-debug.log_
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)

report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json

# Runtime data

pids
_.pid
_.seed
\*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover

lib-cov

# Coverage directory used by tools like istanbul

coverage
\*.lcov

# nyc test coverage

.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)

.grunt

# Bower dependency directory (https://bower.io/)

bower_components

# node-waf configuration

.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)

build/Release

# Dependency directories

node_modules/
jspm_packages/

# Snowpack dependency directory (https://snowpack.dev/)

web_modules/

# TypeScript cache

\*.tsbuildinfo

# Optional npm cache directory

.npm

# Optional eslint cache

.eslintcache

# Optional stylelint cache

.stylelintcache

# Microbundle cache

.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history

.node_repl_history

# Output of 'npm pack'

\*.tgz

# Yarn Integrity file

.yarn-integrity

# parcel-bundler cache (https://parceljs.org/)

.cache
.parcel-cache

# Next.js build output

.next
out

# Nuxt.js build / generate output

.nuxt
dist

# Gatsby files

.cache/

# Comment in the public line in if your project uses Gatsby and not Next.js

# https://nextjs.org/blog/next-9-1#public-directory-support

# public

# vuepress build output

.vuepress/dist

# vuepress v2.x temp and cache directory

.temp
.cache

# Docusaurus cache and generated files

.docusaurus

# Serverless directories

.serverless/

# FuseBox cache

.fusebox/

# DynamoDB Local files

.dynamodb/

# TernJS port file

.tern-port

# Stores VSCode versions used for testing VSCode extensions

.vscode-test

# yarn v2

.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.\*

# wrangler project

.dev.vars*
!.dev.vars.example
.env*
!.env.example
.wrangler/
6 changes: 6 additions & 0 deletions examples/signing-worker/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 140,
"singleQuote": true,
"semi": true,
"useTabs": true
}
5 changes: 5 additions & 0 deletions examples/signing-worker/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"wrangler.json": "jsonc"
}
}
23 changes: 23 additions & 0 deletions examples/signing-worker/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "signing-worker",
"version": "0.0.0",
"private": true,
"scripts": {
"build": "npm --prefix ../.. run build",
"deploy": "wrangler deploy",
"dev": "wrangler dev",
"start": "wrangler dev",
"test": "vitest",
"cf-typegen": "wrangler types"
},
"devDependencies": {
"@cloudflare/vitest-plugin": "^1.0.0",
"@types/node": "^26.4.1",
"typescript": "^5.5.2",
"vitest": "~4.1.0",
"wrangler": "^4.129.0"
},
"dependencies": {
"web-bot-auth": "^0.2.0"
}
}
33 changes: 33 additions & 0 deletions examples/signing-worker/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { sign, SIGNATURE_AGENT_HEADER } from 'web-bot-auth';
import { signerFromJWK } from 'web-bot-auth/crypto';

export default {
async fetch(request, _env, _ctx): Promise<Response> {
// hardcoded key - bring your own!
const wba_jwk = {
kty: 'OKP',
crv: 'Ed25519',
x: '2TXotAGP3Aev7jxkiYZq_6oqpDg_r4OQS-ocFkdq8B4',
d: 'ToJ_oAIupe-7gDv64XYhdUsG-GZmhKh2VQGqKiLqoe8',
};
const signer = await signerFromJWK(wba_jwk);
const now = new Date();

const modifiedRequest = new Request(request);
modifiedRequest.headers.set(
SIGNATURE_AGENT_HEADER,
'sig1="https://www.example.com/.well-known/http-message-signatures-directory";type=directory',
);

const fields = await sign(modifiedRequest, {
signer,
created: now,
expires: new Date(now.getTime() + 300_000),
});

modifiedRequest.headers.set('Signature', fields.signature);
modifiedRequest.headers.set('Signature-Input', fields.signatureInput);

return fetch(modifiedRequest);
},
} satisfies ExportedHandler<Env>;
43 changes: 43 additions & 0 deletions examples/signing-worker/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"compilerOptions": {
/* Visit https://aka.ms/tsconfig.json to read more about this file */

/* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
"target": "es2024",
/* Specify a set of bundled library declaration files that describe the target runtime environment. */
"lib": ["es2024"],
/* Specify what JSX code is generated. */
"jsx": "react-jsx",

/* Specify what module code is generated. */
"module": "es2022",
/* Specify how TypeScript looks up a file from a given module specifier. */
"moduleResolution": "Bundler",
/* Enable importing .json files */
"resolveJsonModule": true,

/* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
"allowJs": true,
/* Enable error reporting in type-checked JavaScript files. */
"checkJs": false,

/* Disable emitting files from a compilation. */
"noEmit": true,

/* Ensure that each file can be safely transpiled without relying on other imports. */
"isolatedModules": true,
/* Allow 'import x from y' when a module doesn't have a default export. */
"allowSyntheticDefaultImports": true,
/* Ensure that casing is correct in imports. */
"forceConsistentCasingInFileNames": true,

/* Enable all strict type-checking options. */
"strict": true,

/* Skip type checking all .d.ts files. */
"skipLibCheck": true,
"types": ["./worker-configuration.d.ts", "node"]
},
"exclude": ["test"],
"include": ["worker-configuration.d.ts", "src/**/*.ts"]
}
10 changes: 10 additions & 0 deletions examples/signing-worker/vitest.config.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { cloudflareTest } from '@cloudflare/vitest-plugin';
import { defineConfig } from 'vitest/config';

export default defineConfig({
plugins: [
cloudflareTest({
wrangler: { configPath: './wrangler.jsonc' },
}),
],
});
Loading