Skip to content
Platform · Cloudflare Workers

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 wrangler
Cloudflare Workers quickstart

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

Last updated

Run locally for Cloudflare Workers before publishing
src/index.js (excerpt)
// 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 });
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, read on .
Where each part lives on Cloudflare Workers
  • 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.

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. 01
    A Worker secret holds the keyAdd 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, read on .
  2. 02
    The fetch handler creates the sessionPOST /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, read on .
  3. 03
    A 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.
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, 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/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 : Cloudflare documentation, Workers, Cloudflare documentation, Secrets, Cloudflare documentation, Static Assets, Cloudflare documentation, D1 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. 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 tool
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.

  • 01

    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.

  • 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 /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, read on .
  • 03

    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.

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.

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

Recordrec_Z4m8
simple · L1
RecordedWritten durably, receipt signed with ES256
TimestampedExternal RFC 3161 token over the record hash
AnchoredPublic anchor pending
Checkbox changed by a trusted user eventobserved
Terms of Service, version dv_3kT9observed
Server time 2026-11-21T15:03:20.291Zobserved
Signer email dana@example.orgasserted
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.

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.

Working with an AI tool? This page is also available as Markdown: /cloudflare-workers.md