Add e-signatures and clickwrap to a Cloudflare Workers app
To add e-signatures and clickwrap to a Cloudflare Workers app, store the secret key as a Worker secret. The Worker's fetch handler creates the session with the esigncomply package and confirms the record, the signup page is a static asset, and a D1 table keeps the receipt. Esign Comply seals each acceptance as an independent record.
Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.
$npm install esigncomply && npm install --save-dev wranglerFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
// Step 4: create the session with the secret key. The browser gets the client token only. if (request.method === "POST" && url.pathname === "/api/ceremony") { const { data: session, error } = await esc.sessions.create( { profile: env.ESIGNCOMPLY_PROFILE_ID, signer, documents: [ { document: documents.terms, version: "current" }, { document: documents.privacy, version: "current" }, ], context: { url: `${url.origin}/signup`, locale: "en-US", purpose: "account_signup" }, }, { idempotencyKey: `signup-${signer.external_id}-${crypto.randomUUID()}` }, ); if (error) return Response.json({ error: error.code }, { status: 502 }); // Two requests can run in two isolates, so what this Worker pinned goes to D1, not to memory. const versionIds = JSON.stringify(session.documents.map((d) => d.version_id).sort()); await env.DB.prepare( "INSERT INTO acceptances (signer_id, version_ids) VALUES (?1, ?2) ON CONFLICT (signer_id) DO UPDATE SET version_ids = ?2, record_id = NULL, receipt = NULL, accepted_at = NULL", ) .bind(signer.external_id, versionIds) .run(); return Response.json({ clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents });
// wrangler.jsonc { "name": "esigncomply-quickstart", "main": "src/index.js", "compatibility_date": "2026-11-01", "compatibility_flags": ["nodejs_compat"], // public/signup.html is served at /signup. Every other path runs the Worker. "assets": { "directory": "./public" }, // D1 keeps what the Worker pinned, then the record ID and the receipt. // Local development accepts any database_id. Before you deploy, run // `npx wrangler d1 create esigncomply-quickstart` and paste the ID it prints. "d1_databases": [ { "binding": "DB", "database_name": "esigncomply-quickstart", "database_id": "00000000-0000-0000-0000-000000000000" } ], // Plain text, so never a key. Set it to "true" on the production Worker only. "vars": { "ESIGNCOMPLY_LIVE": "false" } }
-- schema.sql CREATE TABLE IF NOT EXISTS acceptances ( signer_id TEXT PRIMARY KEY, -- signer.external_id sent to Esign Comply version_ids TEXT NOT NULL, -- JSON array: the versions the session pinned record_id TEXT, -- rec_..., set once the record is confirmed receipt TEXT, -- the signed receipt (JWS, ES256) accepted_at TEXT );
// Step 6: confirm the record with the secret key before the account exists. if (request.method === "POST" && url.pathname === "/api/signup/confirm") { const { recordId } = await request.json(); const { data: record, error } = await esc.records.get(String(recordId)); const row = await env.DB.prepare("SELECT version_ids FROM acceptances WHERE signer_id = ?1").bind(signer.external_id).first(); const confirmed = !error && row !== null && SEALED.includes(record.status) && record.livemode === (env.ESIGNCOMPLY_LIVE === "true") && record.signer.external_id === signer.external_id && JSON.stringify(record.documents.map((d) => d.version_id).sort()) === row.version_ids; console.log(confirmed ? `confirmed ${record.id} (${record.status})` : "refused"); if (!confirmed) return Response.json({ confirmed: false }, { status: 409 }); // Only now create the account. The record ID and the receipt stay in your own table. await env.DB.prepare("UPDATE acceptances SET record_id = ?2, receipt = ?3, accepted_at = ?4 WHERE signer_id = ?1") .bind(signer.external_id, record.id, record.receipt, record.signed_at) .run(); return Response.json({ confirmed: true, recordId: record.id });
How do you integrate Esign Comply with Cloudflare Workers?
On Workers the whole server half is one fetch handler. Secrets arrive on env with each request, so the client is created inside the handler. The esigncomply package runs in the Workers runtime: every call on the quickstart was made from a Worker under wrangler dev. A D1 table keeps the pinned versions, then the record ID and the receipt.
Cloudflare describes Workers as a serverless platform for building, deploying, and scaling apps across Cloudflare's global network.
Source: Cloudflare documentation, Workers, read on .- Workersrc/index.js
- wrangler.jsoncwrangler.jsonc
- D1 tableschema.sql
- Confirmsrc/index.js
Run on 2026-11-26 with Wrangler 4.166.0 (wrangler dev, local workerd and local D1, compatibility date 2026-11-01), esigncomply 1.0.4, the browser SDK script build and the conformance check from esigncomply 1.0.4, against the API in test mode. The Cloudflare settings are from Cloudflare's documentation as of 2026-11-23. The code has not yet been deployed to Cloudflare.
How does Esign Comply fit with Cloudflare Workers?
Each step uses a feature Cloudflare Workers already has. The secret key stays on the server side of Cloudflare Workers in all three.
- 01A Worker secret holds the keyAdd it with
npx wrangler secret put ESIGNCOMPLY_API_KEYfor the deployed Worker, and keep a.dev.varsfile forwrangler dev. The Worker reads it asenv.ESIGNCOMPLY_API_KEY. Source: Cloudflare documentation, Secrets, read on . - 02The fetch handler creates the session
POST /apicalls/ceremony esc.sessions.createinside the Worker and returns the client token. The signup page is a static asset, served without running the Worker, and the browser SDK records the ceremony from the signer's device. Source: Cloudflare documentation, Static Assets, read on . - 03A D1 row keeps the receiptThe session route stores the pinned versions in a D1 table. The confirm route reads the record with the secret key, compares it with the row, and writes the record ID and the receipt into it.
Where do the key, the preview hosts and the webhook go on Cloudflare Workers?
Four settings carry an Esign Comply integration on Cloudflare Workers. What is said here about Cloudflare Workers was read from its own documentation, and the quickstart has each command.
Secrets and variables
Secrets go in with npx wrangler secret put, and local values in .dev.vars beside the Wrangler configuration file. Do not store the key under vars: Cloudflare's documentation says not to use vars for sensitive information. vars is the place for ESIGNCOMPLY_LIVE.
Source: Cloudflare documentation, Secrets, read on .
The database, local and remote
wrangler dev keeps local and remote data apart. Apply schema.sql to both: npx wrangler d1 execute <name> --local --file=schema.sql for development and the same command with --remote for the deployed database.
Source: Cloudflare documentation, D1 local development, read on .
The registered domain and other hosts
Register your custom domain and verify it with one DNS record. A Worker on a workers.dev host verifies with a file at /.well-known instead. A staging Worker on another host keeps the test key, and its exact host goes under Domains as a test origin.
The webhook endpoint
Add a route to the Worker for the record.completed webhook and register its URL under Webhooks in the Esign Comply dashboard. It backs the confirmation up when the browser closes before the Worker hears about the record.
Read on : Cloudflare documentation, Workers, Cloudflare documentation, Secrets, Cloudflare documentation, Static Assets, Cloudflare documentation, D1 local development.
What prompt adds Esign Comply clickwrap to a Cloudflare Workers app?
Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes on Cloudflare Workers, what to build and what never to do, and it ends with the rules block for your project.
The rules block lives at /rules.md. Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The prompt generator writes the long version, with your own document and profile IDs.
Pages for each AI toolAdd Esign Comply clickwrap to my Cloudflare Workers app: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.
Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/cloudflare-workers.md (the steps and the tested code for Cloudflare Workers)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)
Cloudflare Workers facts
- Packages (the only ones that exist): esigncomply (server) and @esigncomply/browser. The esigncomply package runs in the Workers runtime: create the client in the fetch handler with new EsignComply(env.ESIGNCOMPLY_API_KEY).
- The secret key is a Worker secret: npx wrangler secret put ESIGNCOMPLY_API_KEY for the deployed Worker, a .dev.vars file for wrangler dev. Never put it under vars in the Wrangler configuration file. Never print it.
- Static assets are served without running the Worker. The signup page is a file in the assets directory, and the API routes and document pages are the Worker.
- Two requests can run in two isolates. Keep the pinned version IDs in D1, never in a module-level variable.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.
Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Worker: POST /api/ceremony creates the session with esc.sessions.create and an Idempotency-Key, saves the signer ID and the pinned version IDs in D1, and returns only clientToken, apiUrl and documents.
4. Worker: GET /legal/terms and /legal/privacy render the registered version from esc.documents.versions.getContent inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Worker: POST /api/signup/confirm reads the record with esc.records.get and requires: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the row in D1. Only then create the account, and store the record ID and the receipt in the same row.
Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.
Check before you report success
- Run: npx esigncomply check --url http://localhost:8787/signup --callback http://localhost:8787/api/signup/confirm
Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.
Then add the rules block to this project's instruction file: https://esigncomply.com/rules.mdWhat goes wrong when you add e-signatures on Cloudflare Workers?
These are specific to Cloudflare Workers. Each one was seen while the quickstart's code was run, or is in Cloudflare Workers's own documentation.
- 01
The key is a secret, never a var
varsin the Wrangler configuration file is plain text in a file you commit. The key goes in withnpx wrangler secret put, and into.dev.varsfor local runs. Without either,env.ESIGNCOMPLY_API_KEYis empty and every call resolves withmissing_api_key. - 02
Static assets do not run the Worker
A request that matches a file in the assets directory is served without invoking Worker code. In the test run
Source: Cloudflare documentation, Static Assets, read on ./signupcame frompublic/signup.html, and/apiand/ceremony /legalreached the Worker. Keep everything that needs the key out of the assets folder./terms - 03
Local D1 and remote D1 are two databases
The table you created with
--localdoes not exist in the deployed database. Run the schema against both. In the test run the local row held the record ID, the receipt and the acceptance time after the confirm route ran.
Where are the Cloudflare Workers quickstart and the API reference?
Start with the quickstart: it carries every file this page excerpts, in the order you write them.
- QuickstartCloudflare Workers quickstartStep by step, from install to your first sealed test record, with every file and the output of each step.Open
- ReferenceAPI referenceEvery endpoint, field and error code. Sessions, records and documents are the three this page uses.Open
- GuideServer confirmationThe one place access is granted: what to compare, and the webhook that backs the check up.Open
What does Esign Comply record for a signature on Cloudflare Workers?
The same record on every stack and platform. Your Cloudflare Workers code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on Evidence and verification.
Observed and asserted fields
Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.
A signed receipt
complete()returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, andGET /v1returns it again./records /{id} /receipt An external timestamp
An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.
An offline verifier
Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source
esigncomply-verify, without an account.
Questions about e-signatures on Cloudflare Workers
How does test mode work on Cloudflare preview URLs?
A test key works on localhost with no setup, which covers wrangler dev. A Worker on a workers.dev host, or any other preview host, keeps the test key and needs its exact host listed under Domains as a test origin. Without the entry the session is refused with domain_mismatch.
Where should the receipt be stored on Cloudflare Workers?
In a D1 table, beside the signer ID and the record ID. The confirm route writes both once the record is confirmed. The quickstart uses one table for the pinned versions and the receipt.
Does the esigncomply package run on Cloudflare Workers?
Yes. Every server call of the quickstart was made with the package inside a Worker, under Wrangler 4.166.0 with compatibility date 2026-11-01. It was tested with the nodejs_compat flag and without it, and worked both ways.
Do I need a Cloudflare account to try it?
No. wrangler dev runs the Worker and D1 on your machine, and it accepted a placeholder database_id in the test. You need an account to create the remote database, add the secrets and deploy.
Was this code deployed to Cloudflare?
Not yet. It was run with wrangler dev on Wrangler 4.166.0, and the Cloudflare settings come from Cloudflare's documentation as of November 23, 2026. The deployed Worker, its secrets, the remote D1 database and file verification on a workers.dev host are proven only by a deployment.
Run the signing flow in your Worker. Leave the record to us.
Free plan: 10 live signatures a month and a full test mode. No card required.
Cloudflare Workers is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Cloudflare Workers is from Cloudflare Workers's documentation or from a test run, as marked, on . /cloudflare-workers.md is this page as Markdown.