# Add e-signatures and clickwrap to a Cloudflare Workers app

> Add e-signatures and clickwrap to a Cloudflare Workers app: the key as a Worker secret, the esigncomply package in the fetch handler, and a D1 table.

Source: https://esigncomply.com/cloudflare-workers

Platform · Cloudflare Workers

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.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/cloudflare-workers)

`npm install esigncomply && npm install --save-dev wrangler`

[Cloudflare Workers quickstart](https://esigncomply.com/docs/quickstart/cloudflare-workers)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run locally for Cloudflare Workers before publishing

**Worker**

src/index.js (excerpt)

```js
// 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**

`wrangler.jsonc`

```
// 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" }
}
```

**D1 table**

`schema.sql`

```sql
-- 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
);
```

**Confirm**

src/index.js (excerpt)

```js
// 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 });
```

Integrate with Cloudflare Workers

## 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](https://developers.cloudflare.com/workers/), read on November 23, 2026.

[Cloudflare Workers quickstart](https://esigncomply.com/docs/quickstart/cloudflare-workers) · [All platforms](https://esigncomply.com/platforms)

Where each part lives on Cloudflare Workers

- **Worker** · `src/index.js`
- **wrangler.jsonc** · `wrangler.jsonc`
- **D1 table** · `schema.sql`
- **Confirm** · `src/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.

Three steps

## 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.

1. **A Worker secret holds the key**

   Add it with `npx wrangler secret put ESIGNCOMPLY_API_KEY` for the deployed Worker, and keep a `.dev.vars` file for `wrangler dev`. The Worker reads it as `env.ESIGNCOMPLY_API_KEY`. Source: [Cloudflare documentation, Secrets](https://developers.cloudflare.com/workers/configuration/secrets/), read on November 23, 2026.

2. **The fetch handler creates the session**

   `POST /api/ceremony` calls `esc.sessions.create` inside 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](https://developers.cloudflare.com/workers/static-assets/), read on November 23, 2026.

3. **A D1 row keeps the receipt**

   The 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.

Cloudflare Workers setup

## 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](https://developers.cloudflare.com/workers/configuration/secrets/), read on November 23, 2026.

### 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](https://developers.cloudflare.com/d1/best-practices/local-development/), read on November 23, 2026.

### 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/esigncomply.txt` 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 November 23, 2026: [Cloudflare documentation, Workers](https://developers.cloudflare.com/workers/), [Cloudflare documentation, Secrets](https://developers.cloudflare.com/workers/configuration/secrets/), [Cloudflare documentation, Static Assets](https://developers.cloudflare.com/workers/static-assets/), [Cloudflare documentation, D1 local development](https://developers.cloudflare.com/d1/best-practices/local-development/).

Copy-paste prompt

## 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](https://esigncomply.com/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](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap on Cloudflare Workers

```
Add 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.md
```

3 things to watch

## What 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.

- **The key is a secret, never a var**

  `vars` in the Wrangler configuration file is plain text in a file you commit. The key goes in with `npx wrangler secret put`, and into `.dev.vars` for local runs. Without either, `env.ESIGNCOMPLY_API_KEY` is empty and every call resolves with `missing_api_key`.

- **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 `/signup` came from `public/signup.html`, and `/api/ceremony` and `/legal/terms` reached the Worker. Keep everything that needs the key out of the assets folder.

  Source: [Cloudflare documentation, Static Assets](https://developers.cloudflare.com/workers/static-assets/), read on November 23, 2026.

- **Local D1 and remote D1 are two databases**

  The table you created with `--local` does 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.

- Quickstart

  **[Cloudflare Workers quickstart](https://esigncomply.com/docs/quickstart/cloudflare-workers)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## 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](https://esigncomply.com/product/evidence).

- **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, and `GET /v1/records/{id}/receipt` returns it again.

- **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.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## 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.

### Other platforms

- [Vercel](https://esigncomply.com/vercel)
- [Netlify](https://esigncomply.com/netlify)
- [Supabase](https://esigncomply.com/supabase)

### Stacks used with Cloudflare Workers

- [Node.js](https://esigncomply.com/nodejs)
- [React](https://esigncomply.com/react)
- [Express](https://esigncomply.com/express)

[All platforms](https://esigncomply.com/platforms) · [All stacks](https://esigncomply.com/stacks) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Run the signing flow in your Worker. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/cloudflare-workers)

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 November 23, 2026. `/cloudflare-workers.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
