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

> Add e-signatures and clickwrap to a Cloudflare Pages app: Pages Functions with the esigncomply package, the key as a secret, previews and a D1 table.

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

Platform · Cloudflare Pages

To add e-signatures and clickwrap to a Cloudflare Pages app, put the server calls in Pages Functions and store the secret key as a secret of the project. One Function creates the session with the `esigncomply` package, another confirms the record, 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-pages)

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

[Cloudflare Pages quickstart](https://esigncomply.com/docs/quickstart/cloudflare-pages)

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

Last updated November 26, 2026

Run locally for Cloudflare Pages before publishing

**Session Function**

`functions/api/ceremony.js`

```js
// functions/api/ceremony.js
import { client, documents, signer } from "../../lib/esigncomply.js";

// Step 4: create the session with the secret key. The browser gets the client token only.
export async function onRequestPost({ request, env }) {
  const docs = documents(env);
  const { data: session, error } = await client(env).sessions.create(
    {
      profile: env.ESIGNCOMPLY_PROFILE_ID,
      signer,
      documents: [
        { document: docs.terms, version: "current" },
        { document: docs.privacy, version: "current" },
      ],
      // The deployment that served the page: localhost, a preview on pages.dev or your own domain.
      context: { url: `${new URL(request.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 Function 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 });
}
```

**Shared module**

`lib/esigncomply.js`

```js
// lib/esigncomply.js
import { EsignComply } from "esigncomply";

export const SEALED = ["recorded", "timestamped", "anchored"];

// The signer. In your app this is the signed-in user, or the account you are about to create.
export const signer = {
  external_id: "user_7c1d",
  email: "dana@example.org",
  name: "Dana Whitfield",
  class: "consumer",
  country: "US",
  region: "US-CA",
};

// Secrets and variables arrive on context.env with each request, so the client is made per request.
export function client(env) {
  return new EsignComply(env.ESIGNCOMPLY_API_KEY, { baseUrl: env.ESIGNCOMPLY_API_URL });
}

export function documents(env) {
  return { terms: env.ESIGNCOMPLY_TERMS_ID, privacy: env.ESIGNCOMPLY_PRIVACY_ID };
}
```

**wrangler.jsonc**

`wrangler.jsonc`

```
// wrangler.jsonc
{
  "name": "esigncomply-quickstart",
  // This key makes the file a Pages configuration: the folder of static files to publish.
  "pages_build_output_dir": "./public",
  "compatibility_date": "2026-11-01",
  // D1 keeps what the session 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. Preview deployments keep "false".
  "vars": { "ESIGNCOMPLY_LIVE": "false" }
}
```

**Confirm Function**

`functions/api/signup/confirm.js`

```js
// functions/api/signup/confirm.js
import { client, SEALED, signer } from "../../../lib/esigncomply.js";

// Step 6: confirm the record with the secret key before the account exists.
export async function onRequestPost({ request, env }) {
  const { recordId } = await request.json();
  const { data: record, error } = await client(env).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 Pages

## How do you integrate Esign Comply with Cloudflare Pages?

On Pages the server half is a folder. Each file under `functions/` answers the path it sits at: `functions/api/ceremony.js` is `POST /api/ceremony`. Secrets arrive on `context.env`, so the client is made per request, and the code the routes share lives outside the folder. Preview deployments get hosts under the project's own `pages.dev` host.

Functions files in the /functions directory of a Pages project generate a Worker that runs at the routes the files name.

Source: [Cloudflare documentation, Pages Functions](https://developers.cloudflare.com/pages/functions/get-started/), read on November 24, 2026.

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

Where each part lives on Cloudflare Pages

- **Session Function** · `functions/api/ceremony.js`
- **Shared module** · `lib/esigncomply.js`
- **wrangler.jsonc** · `wrangler.jsonc`
- **Confirm Function** · `functions/api/signup/confirm.js`

Run on 2026-11-26 with Wrangler 4.168.0 (wrangler pages dev, local Pages Functions 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-24. The code has not yet been deployed to Cloudflare Pages.

Three steps

## How does Esign Comply fit with Cloudflare Pages?

Each step uses a feature Cloudflare Pages already has. The secret key stays on the server side of Cloudflare Pages in all three.

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

   Add `ESIGNCOMPLY_API_KEY` in the project's settings under Variables and Secrets, for production and for preview separately, and keep a `.dev.vars` file for `wrangler pages dev`. Functions read it as `context.env.ESIGNCOMPLY_API_KEY`. Source: [Cloudflare documentation, Pages Functions bindings](https://developers.cloudflare.com/pages/functions/bindings/), read on November 24, 2026.

2. **A Pages Function creates the session**

   `functions/api/ceremony.js` exports `onRequestPost`, calls `esc.sessions.create` and returns the client token. The signup page is a static file of the project, and the browser SDK records the ceremony from the signer's device. Source: [Cloudflare documentation, Pages Functions routing](https://developers.cloudflare.com/pages/functions/routing/), read on November 24, 2026.

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

   The session Function stores the pinned versions in a D1 table bound as `DB`. The confirm Function reads the record with the secret key, compares it with the row, and writes the record ID and the receipt into it.

Cloudflare Pages setup

## Where do the key, the preview hosts and the webhook go on Cloudflare Pages?

Four settings carry an Esign Comply integration on Cloudflare Pages. What is said here about Cloudflare Pages was read from its own documentation, and the quickstart has each command.

### Secrets and the Wrangler file

Secrets are set in the dashboard or with `npx wrangler pages secret put`, before the deployment that uses them. The key `pages_build_output_dir` makes a Wrangler file a Pages configuration, and that file is then the source of truth for the fields it holds.

Source: [Cloudflare documentation, Pages Wrangler configuration](https://developers.cloudflare.com/pages/functions/wrangler-configuration/), read on November 24, 2026.

### Production values

`vars` and bindings are not inherited by an environment override. An `env.production` block that sets `ESIGNCOMPLY_LIVE` to `true` has to repeat `d1_databases` as well, or the file fails to validate when you deploy.

Source: [Cloudflare documentation, Pages Wrangler configuration](https://developers.cloudflare.com/pages/functions/wrangler-configuration/), read on November 24, 2026.

### Preview deployments and test mode

Every branch gets `<hash>.<project>.pages.dev` and an alias, `<branch>.<project>.pages.dev`. List `<project>.pages.dev` once under Domains in the Esign Comply dashboard as a test origin: an entry covers its subdomains, so it covers every preview. Never list the shared suffix `pages.dev`.

Source: [Cloudflare documentation, Preview deployments](https://developers.cloudflare.com/pages/configuration/preview-deployments/), read on November 24, 2026.

### The registered domain and the webhook

Register your custom domain and verify it with one DNS record. A project that goes live on its `pages.dev` host verifies with a file at `/.well-known/esigncomply.txt` instead. For the `record.completed` webhook, add a Function and register its production URL under Webhooks in the Esign Comply dashboard.

Read on November 24, 2026: [Cloudflare documentation, Pages Functions](https://developers.cloudflare.com/pages/functions/get-started/), [Cloudflare documentation, Pages Functions routing](https://developers.cloudflare.com/pages/functions/routing/), [Cloudflare documentation, Pages Functions bindings](https://developers.cloudflare.com/pages/functions/bindings/), [Cloudflare documentation, Pages Wrangler configuration](https://developers.cloudflare.com/pages/functions/wrangler-configuration/), [Cloudflare documentation, Preview deployments](https://developers.cloudflare.com/pages/configuration/preview-deployments/), [Cloudflare documentation, Wrangler commands for Pages](https://developers.cloudflare.com/workers/wrangler/commands/pages/).

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Cloudflare Pages 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 Pages, 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 Pages

```
Add Esign Comply clickwrap to my Cloudflare Pages project: 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-pages.md (the steps and the tested code for Cloudflare Pages)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Cloudflare Pages facts
- Packages (the only ones that exist): esigncomply (server) and @esigncomply/browser. The esigncomply package runs in Pages Functions: create the client per request with new EsignComply(context.env.ESIGNCOMPLY_API_KEY).
- Server code lives in the functions folder at the project root, one file per route: functions/api/ceremony.js answers /api/ceremony. Shared code sits outside that folder.
- The secret key is a Pages secret: npx wrangler pages secret put ESIGNCOMPLY_API_KEY for the project, a .dev.vars file for wrangler pages dev. Never put it under vars in the Wrangler configuration file. Never print it.
- Two requests can run in two isolates. Keep the pinned version IDs in D1, never in a module-level variable.
- Preview deployments run on <hash>.<project>.pages.dev and <branch>.<project>.pages.dev. One test origin, <project>.pages.dev, covers them all.
- 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. Function functions/api/ceremony.js (onRequestPost): create the session with esc.sessions.create and an Idempotency-Key, save the signer ID and the pinned version IDs in D1, and return only clientToken, apiUrl and documents.
4. Function functions/legal/[slug].js (onRequestGet): 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. Function functions/api/signup/confirm.js (onRequestPost): read the record with esc.records.get and require: 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:8788/signup --callback http://localhost:8788/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 Pages?

These are specific to Cloudflare Pages. Each one was seen while the quickstart's code was run, or is in Cloudflare Pages's own documentation.

- **One test origin covers every Pages preview**

  Preview hosts are subdomains of the project's host. In a test against the API, a session for `https://373f31e2.my-app.pages.dev` was refused with `domain_mismatch`, and accepted once `my-app.pages.dev` was a test origin, as was one for a branch alias. A host of another project stayed refused.

- **Production does not inherit vars or bindings**

  Cloudflare's documentation lists `vars` and the binding keys as non-inheritable: override one in `env.production` and you must repeat the others there. Locally, `wrangler pages dev` used the top-level values and printed `Using secrets defined in .dev.vars`.

  Source: [Cloudflare documentation, Pages Wrangler configuration](https://developers.cloudflare.com/pages/functions/wrangler-configuration/), read on November 24, 2026.

- **The functions folder is a route table**

  The path of a file under `functions/` is its route, and the folder sits at the project root, not inside the published folder. Shared code goes elsewhere: in the test, a file with no handler under `functions/` answered `404` at its path.

  Source: [Cloudflare documentation, Pages Functions routing](https://developers.cloudflare.com/pages/functions/routing/), read on November 24, 2026.

## Where are the Cloudflare Pages quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

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

  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 Pages?

The same record on every stack and platform. Your Cloudflare Pages 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 Pages

### How does test mode work on Cloudflare Pages preview URLs?

A test key works on every preview of a project once `<project>.pages.dev` is listed as a test origin of your domain. Preview hosts are subdomains of that host, and an entry covers its subdomains. In a test, a hash address and a branch alias were both accepted after one entry.

### Where should the receipt be stored on Cloudflare Pages?

In a D1 table, beside the signer ID and the record ID. The confirm Function writes both once the record is confirmed. The quickstart binds the database as `DB` and uses one table for the pinned versions and the receipt.

### How is Cloudflare Pages different from Workers for this integration?

The routing and the previews. On Pages each file under `functions/` is a route and reads secrets from `context.env`, and every branch gets a preview host under the project's `pages.dev` host. On Workers one `fetch` handler routes every path. The package and the D1 table are the same.

### Where do Pages Functions read the secret key?

From `context.env`, the object each handler receives with the request. Locally the value comes from `.dev.vars`, and on Cloudflare from a secret of the project, set for production and for preview separately. The quickstart creates the client inside each handler for that reason.

### Was this code deployed to Cloudflare Pages?

Not yet. It was run with `wrangler pages dev` on Wrangler 4.168.0, and the Cloudflare settings come from Cloudflare's documentation as of November 24, 2026. The deployed Functions, the secrets per environment, the remote D1 database and file verification on a `pages.dev` host are proven only by a deployment.

### Other platforms

- [Cloudflare Workers](https://esigncomply.com/cloudflare-workers)
- [Vercel](https://esigncomply.com/vercel)
- [Netlify](https://esigncomply.com/netlify)

### Stacks used with Cloudflare Pages

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

[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)

## Put the key in a Pages Function. Leave the record to us.

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

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

Cloudflare Pages is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Cloudflare Pages is from Cloudflare Pages's documentation or from a test run, as marked, on November 24, 2026. `/cloudflare-pages.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.
