Add e-signatures and clickwrap to a Cloudflare Pages app
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.
$npm install esigncomply && npm install --save-dev wranglerFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
// 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 }); }
// 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" } }
// 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 }); }
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 is POST /api. 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, read on .- Session Functionfunctions/api/ceremony.js
- Shared modulelib/esigncomply.js
- wrangler.jsoncwrangler.jsonc
- Confirm Functionfunctions/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.
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.
- 01A Pages secret holds the keyAdd
ESIGNCOMPLY_API_KEYin the project's settings under Variables and Secrets, for production and for preview separately, and keep a.dev.varsfile forwrangler pages dev. Functions read it ascontext.env.ESIGNCOMPLY_API_KEY. Source: Cloudflare documentation, Pages Functions bindings, read on . - 02A Pages Function creates the session
functions/apiexports/ceremony.js onRequestPost, callsesc.sessions.createand 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, read on . - 03A D1 row keeps the receiptThe 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.
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, read on .
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, read on .
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, read on .
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 instead. For the record.completed webhook, add a Function and register its production URL under Webhooks in the Esign Comply dashboard.
Read on : Cloudflare documentation, Pages Functions, Cloudflare documentation, Pages Functions routing, Cloudflare documentation, Pages Functions bindings, Cloudflare documentation, Pages Wrangler configuration, Cloudflare documentation, Preview deployments, Cloudflare documentation, Wrangler commands for Pages.
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. 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 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.mdWhat 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.
- 01
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:/was refused with/373f31e2.my-app.pages.dev domain_mismatch, and accepted oncemy-app.pages.devwas a test origin, as was one for a branch alias. A host of another project stayed refused. - 02
Production does not inherit vars or bindings
Cloudflare's documentation lists
Source: Cloudflare documentation, Pages Wrangler configuration, read on .varsand the binding keys as non-inheritable: override one inenv.productionand you must repeat the others there. Locally,wrangler pages devused the top-level values and printedUsing secrets defined in .dev.vars. - 03
The functions folder is a route table
The path of a file under
Source: Cloudflare documentation, Pages Functions routing, read on .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 underfunctions/answered404at its path.
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.
- QuickstartCloudflare Pages 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 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.
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 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.
Put the key in a Pages Function. Leave the record to us.
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 . /cloudflare-pages.md is this page as Markdown.