Add e-signatures and clickwrap to Fastify
To add e-signatures and clickwrap to Fastify, install fastify and the esigncomply package. One route creates the session with the secret key, the browser SDK attaches to your own checkbox and button, and a second route with a JSON schema confirms the record before your app grants anything. Esign Comply seals each acceptance as an independent record anyone can verify.
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 fastify @fastify/static esigncomplyFree 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. app.post("/api/ceremony", async (request, reply) => { const { data: session, error } = await esc.sessions.create( { profile: process.env.ESIGNCOMPLY_PROFILE_ID, signer, documents: [ { document: DOCUMENTS.terms, version: "current" }, { document: DOCUMENTS.privacy, version: "current" }, ], // The page that runs the ceremony: the origin the browser reports, plus its path. context: { url: `${request.headers.origin ?? `${request.protocol}://${request.host}`}/signup`, locale: "en-US", purpose: "account_signup" }, }, { idempotencyKey: `signup-${signer.external_id}-${randomUUID()}` }, ); if (error) return reply.code(502).send({ error: error.code }); pinned.set(signer.external_id, session.documents.map((d) => d.version_id)); return { clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents };
// Step 6: confirm the record with the secret key before the account exists. // Fastify parses the JSON body itself, and the schema refuses a body without a record ID. const confirmBody = { type: "object", required: ["recordId"], properties: { recordId: { type: "string" } } }; app.post("/api/signup/confirm", { schema: { body: confirmBody } }, async (request, reply) => { const { data: record, error } = await esc.records.get(request.body.recordId); const expected = [...(pinned.get(signer.external_id) ?? [])].sort(); const confirmed = !error && SEALED.includes(record.status) && record.livemode === LIVE && record.signer.external_id === signer.external_id && JSON.stringify(record.documents.map((d) => d.version_id).sort()) === JSON.stringify(expected); console.log(confirmed ? `confirmed ${record.id} (${record.status})` : "refused"); if (!confirmed) return reply.code(409).send({ confirmed: false }); // Only now create the account, and store record.id and record.receipt with it. return { confirmed: true, recordId: record.id };
// The signup page. app.register(fastifyStatic, { root: join(import.meta.dirname, "public") }); app.get("/signup", (request, reply) => reply.sendFile("signup.html"));
How do you integrate Esign Comply with Fastify?
Fastify does two parts of the integration for you. It parses the JSON body, so the confirm route reads request.body.recordId with no plugin, and a JSON schema on that route refuses a malformed body before the handler runs. An async handler returns the payload, and reply.code(409).send(...) refuses.
Fastify natively supports the application/json and text/plain content types.
Source: Fastify documentation, Content-Type Parser, read on .- Session routeserver.js
- Schema and confirm routeserver.js
- Signup pageserver.js
Run on 2026-11-26 with Fastify 5.12.8 and @fastify/static 10.1.12 on Node.js 24.22.1, esigncomply 1.0.4, the browser SDK script build and the conformance check from esigncomply 1.0.4 (--timeout 60), against the API in test mode.
What prompt adds Esign Comply clickwrap to a Fastify 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 in Fastify, 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 Fastify 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/fastify.md (the steps and the tested code for Fastify)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)
Fastify facts
- Packages (the only ones that exist): esigncomply (server, Node.js 20.19 or later, an ES module) and @esigncomply/browser. Without a bundler, load the browser SDK from https://esigncomply.com/sdk/v1/esigncomply.js.
- The secret key is in ESIGNCOMPLY_API_KEY, in a .env file loaded with: node --env-file=.env server.js. Never print it.
- Server SDK calls return { data, error } and do not throw. Check error every time.
- Fastify parses JSON bodies itself. Put a JSON schema on the confirm route so a body without recordId is refused before the handler runs. A request with Content-Type application/json and an empty body is answered 400 by Fastify: the page must send no content type when it sends no body.
- Fastify listens on 127.0.0.1 unless listen() gets a host.
- 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. Server: app.post("/api/ceremony") creates the session with esc.sessions.create and an Idempotency-Key, saves the signer ID and the pinned version IDs in server-owned state, and returns only clientToken, apiUrl and documents.
4. Server: app.get("/legal/:slug") renders 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. Server: app.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 server-owned state. Only then create the account.
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:3000/signup --callback http://localhost:3000/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 in Fastify?
These are specific to Fastify. Each one was seen while the quickstart's code was run, or is in Fastify's own documentation.
- 01
A JSON content type with an empty body is refused with 400
In a test on Fastify 5.12.8, a
POSTto/apiwith/ceremony Content-Type: application/jsonand no body was answered400withFST_ERR_CTP_EMPTY_JSON_BODYbefore the handler ran. The samePOSTwith no content type, which is what the signup page sends, was answered200. - 02
Fastify listens on 127.0.0.1 unless you pass a host
app.listen({ port })bound to127.0.0.1in the test, and a request through the machine's own network address was refused. Withhost: "0.0.0.0"the same request succeeded. Pass the host in a container, or nothing outside it reaches the server. - 03
The schema answers before the record check
A body without
recordIdnever reaches the handler: the schema answered400withFST_ERR_VALIDATIONin the test. A body with a made-up record ID passed the schema, reached the API, and was refused with409. Both are refusals, with two different status codes.
Where are the Fastify quickstart and the API reference?
Start with the quickstart: it carries every file this page excerpts, in the order you write them.
- QuickstartFastify 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 in Fastify?
The same record on every stack and platform. Your Fastify 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 in Fastify
Is there an Esign Comply SDK for Fastify?
Yes. Fastify runs on Node.js, so it uses the esigncomply server package directly, with the browser SDK for the page. There is no Fastify plugin to register for it: the integration is three routes of your own and @fastify/static for the page.
Where do I create the session in Fastify?
In a route handler, for example app.post("/api, with esc.sessions.create and the secret key. The async handler returns only the client token, the API URL and the pinned documents, and Fastify sends them as JSON.
Does Fastify need a body parser for the confirm route?
No. Fastify parses application/json bodies itself, so request.body is an object with no plugin added. The quickstart was run on Fastify 5.12.8, and its confirm route read the record ID straight from request.body.
What does the JSON schema on the confirm route add?
It refuses a malformed request before the handler and before any API call. In the test run, a body without recordId was answered 400 by the schema, and a made-up record ID reached the handler and was refused with 409.
Why can nothing outside my machine reach the Fastify server?
Because Fastify listens on 127.0.0.1 unless listen gets a host. In a test, a request through the machine's network address was refused, and it succeeded once the server listened with host: "0.0.0.0".
Add three routes to your Fastify app. Leave the record to us.
Free plan: 10 live signatures a month and a full test mode. No card required.
Fastify is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Fastify is from Fastify's documentation or from a test run, as marked, on . /fastify.md is this page as Markdown.