Add e-signatures and clickwrap to NestJS
To add e-signatures and clickwrap to NestJS, install the esigncomply package and wrap it in one injectable provider that reads the secret key through ConfigService. A controller method creates the session, the browser SDK attaches to your own form, and a second method confirms the record. 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 esigncomply @nestjs/configFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
// src/esigncomply.service.ts import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { EsignComply } from 'esigncomply'; // One provider holds the client and the secret key. Controllers inject it, and nothing here reaches the browser. @Injectable() export class EsignComplyService { readonly esc: EsignComply; // Signer ID -> the version IDs this server pinned. Use a table in your database in production. readonly pinned = new Map<string, string[]>(); // The signer. In your app this is the signed-in user, or the account you are about to create. readonly signer = { external_id: 'user_7c1d', email: 'dana@example.org', name: 'Dana Whitfield', class: 'consumer', country: 'US', region: 'US-CA', } as const; constructor(private readonly config: ConfigService) { // Read the key here, not at the top of the file: .env is loaded after the imports have run. this.esc = new EsignComply(config.get<string>('ESIGNCOMPLY_API_KEY'), { baseUrl: config.get<string>('ESIGNCOMPLY_API_URL') }); } /** The registered document behind /legal/terms and /legal/privacy. */ documentId(slug: string): string | undefined { return { terms: this.config.get<string>('ESIGNCOMPLY_TERMS_ID'), privacy: this.config.get<string>('ESIGNCOMPLY_PRIVACY_ID') }[slug]; } /** Test records in development, live records where ESIGNCOMPLY_LIVE is "true": production only. */ get live(): boolean { return this.config.get<string>('ESIGNCOMPLY_LIVE') === 'true'; } }
// Step 4: create the session with the secret key. The browser gets the client token only. @Post('api/ceremony') @HttpCode(200) async ceremony(@Headers('origin') origin?: string, @Headers('host') host?: string) { const { esc, signer, pinned } = this.esign; const { data: session, error } = await esc.sessions.create( { profile: this.config.getOrThrow<string>('ESIGNCOMPLY_PROFILE_ID'), signer, documents: [ { document: this.esign.documentId('terms')!, version: 'current' }, { document: this.esign.documentId('privacy')!, version: 'current' }, ], // The page that runs the ceremony: the origin the browser reports, plus its path. context: { url: `${origin ?? `http://${host}`}/signup`, locale: 'en-US', purpose: 'account_signup' }, }, { idempotencyKey: `signup-${signer.external_id}-${randomUUID()}` }, ); if (error) throw new BadGatewayException({ 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. @Post('api/signup/confirm') @HttpCode(200) async confirm(@Body() body: { recordId?: string }) { const { esc, signer, pinned } = this.esign; const { data: record, error } = await esc.records.get(String(body?.recordId)); const expected = [...(pinned.get(signer.external_id) ?? [])].sort(); const confirmed = !error && SEALED.includes(record.status) && record.livemode === this.esign.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) throw new ConflictException({ confirmed: false }); // Only now create the account, and store record.id and record.receipt with it. return { confirmed: true, recordId: record.id };
// src/app.module.ts import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { EsignComplyService } from './esigncomply.service.js'; import { SignupController } from './signup.controller.js'; @Module({ // ConfigModule reads .env when the application starts. Nest does not read it on its own. imports: [ConfigModule.forRoot()], controllers: [SignupController], providers: [EsignComplyService], }) export class AppModule {}
How do you integrate Esign Comply with NestJS?
In Nest the client lives in one @Injectable() provider, and controllers receive it through their constructor. ConfigModule.forRoot() loads .env, and the provider reads the key through ConfigService when Nest builds it. A project generated by Nest CLI 12 is an ES module, like the package, so the import works as written.
Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications.
Source: NestJS documentation, read on .- Providersrc/esigncomply.service.ts
- Session routesrc/signup.controller.ts
- Confirm routesrc/signup.controller.ts
- Modulesrc/app.module.ts
Run on 2026-11-26 with NestJS 12.6.0 (a project generated by Nest CLI 12, an ES module with TypeScript 6.0.3), @nestjs/config 12.1.1, esigncomply 1.0.4, the browser SDK script build and the conformance check from esigncomply 1.0.4 on Node.js 24.22.1, against the API in test mode.
What prompt adds Esign Comply clickwrap to a NestJS 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 NestJS, 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 NestJS 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/nestjs.md (the steps and the tested code for NestJS)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)
NestJS facts
- Packages (the only ones that exist): esigncomply (server, Node.js 20.19 or later, an ES module) and @esigncomply/browser. There is no Nest module package: wrap new EsignComply(...) in one @Injectable() provider. Without a bundler, load the browser SDK from https://esigncomply.com/sdk/v1/esigncomply.js.
- The secret key is ESIGNCOMPLY_API_KEY in .env, loaded by ConfigModule.forRoot(). Read it with ConfigService inside the provider's constructor, never at the top of a file: .env is loaded after the imports have run. Never print the key.
- Server SDK calls return { data, error } and do not throw. Check error every time.
- A Nest CLI 12 project is an ES module with nodenext module resolution: write every relative import with its .js extension. Use esigncomply 1.0.3 or later, whose results are fully typed there: never cast them to any.
- Nest answers 201 to a @Post route by default. Set @HttpCode(200) where the client expects 200.
- 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. Controller: @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. Controller: @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. Controller: @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 NestJS?
These are specific to NestJS. Each one was seen while the quickstart's code was run, or is in NestJS's own documentation.
- 01
.env is not loaded yet when your files are imported
ConfigModule.forRoot()loads.envwhen the application starts, after every import has run. In a test on NestJS 12.6.0,process.envread at the top of a file was undefined, and the same variable read inside a handler, or throughConfigService, held its value. Create the client in the provider's constructor. - 02
Nest answers 201 to a POST unless you set the status
A
@Post()handler with no status decorator answered201in the test. The quickstart puts@HttpCode(200)on the session route and the confirm route, so they answer as on every other stack, and refuses withConflictException, which is409. - 03
Your own imports need the .js extension
A project generated by Nest CLI 12 is an ES module with
moduleResolution: nodenext, so a relative import names the compiled file:./esigncomply.service.js. In a test, the same import without the extension stopped the build withTS2307, and everything read from the provider lost its type. Theesigncomplyimport needs nothing: from 1.0.3 its results are typed under this resolution.
Where are the NestJS quickstart and the API reference?
Start with the quickstart: it carries every file this page excerpts, in the order you write them.
- QuickstartNestJS 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 NestJS?
The same record on every stack and platform. Your NestJS 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 NestJS
Is there an Esign Comply SDK for NestJS?
Yes. Nest runs on Node.js, so it uses the esigncomply server package directly. There is no Nest module to install for it: one @Injectable() provider creates the client, and controllers inject that provider.
Where do I create the session in NestJS?
In a controller method, for example one decorated with @Post("api/ceremony"), that calls sessions.create on the client the provider holds. The method returns only the client token, the API URL and the pinned documents.
Does the esigncomply import work in a CommonJS Nest project?
A project generated by Nest CLI 12 is an ES module, and the import works there as written. In a CommonJS file on Node.js 24.22.1, require("esigncomply") returned the class in a test. On the Lambda Node.js 22 runtime image the same call failed with ERR_REQUIRE_ESM, so there load it with await import("esigncomply").
Why does the provider take ConfigService instead of process.env?
Because it works whenever the provider is built, and process.env at the top of a file does not: .env is loaded after the imports have run. In the test, the top-level read was undefined and ConfigService returned the key.
Do I need @nestjs/serve-static for the signup page?
No. The quickstart serves public/signup.html from a controller method that reads the file and sets the content type with @Header. A second method of the same controller renders the document pages, so the page and its documents share one origin. In the test run all three answered from Nest with no static module.
Put the client in one provider. Leave the record to us.
Free plan: 10 live signatures a month and a full test mode. No card required.
NestJS is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about NestJS is from NestJS's documentation or from a test run, as marked, on . /nestjs.md is this page as Markdown.