Skip to content
Platform · PocketBase

E-signatures and clickwrap with PocketBase

To add e-signatures and clickwrap with PocketBase, extend the one binary with JavaScript in pb_hooks. Two routes call the REST API with PocketBase's own $http.send, and the secret key stays in the environment of the process. A collection with locked API rules keeps the pinned versions and 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.

No package to install: the hooks call the REST API with $http.send

PocketBase quickstart

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

Last updated

Run locally for PocketBase before publishing
pb_hooks/main.pb.js (excerpt)
// Step 4: create the session with the secret key. The browser gets the client token only.
routerAdd("POST", "/api/ceremony", (e) => {
  const esc = require(`${__hooks}/esc.js`);
  // The page that runs the ceremony: the origin the browser reports, plus its path.
  const origin = e.request.header.get("Origin") || "http://" + e.request.host;
  const res = esc.call(
    "POST",
    "/sessions",
    {
      profile: $os.getenv("ESIGNCOMPLY_PROFILE_ID"),
      signer: esc.signer,
      documents: [
        { document: esc.documents.terms, version: "current" },
        { document: esc.documents.privacy, version: "current" },
      ],
      context: { url: origin + "/signup", locale: "en-US", purpose: "account_signup" },
    },
    "signup-" + esc.signer.external_id + "-" + $security.randomString(24),
  );
  if (res.status !== 201) return e.json(502, { error: res.data.error.code });

  // One row per signer, in a collection whose API rules are locked: only the hooks and a superuser read it.
  const collection = e.app.findCollectionByNameOrId("esc_acceptances");
  let row;
  try {
    row = e.app.findFirstRecordByData("esc_acceptances", "signer_id", esc.signer.external_id);
  } catch (_) {
    row = new Record(collection);
    row.set("signer_id", esc.signer.external_id);
  }
  row.set("version_ids", res.data.documents.map((d) => d.version_id).sort());
  e.app.save(row);
  return e.json(200, { clientToken: res.data.client_token, apiUrl: res.data.api_url, documents: res.data.documents });
});
Integrate with PocketBase

How do you integrate Esign Comply with PocketBase?

With PocketBase the server half is JavaScript in pb_hooks, run by the binary's embedded engine and not by Node.js. Each handler runs in a scope of its own, so the routes load what they share with require(). They call the REST API with $http.send, read the key with $os.getenv, and keep the pinned versions in a collection that a migration creates with every API rule locked.

PocketBase is an open source backend consisting of embedded database (SQLite) with realtime subscriptions, builtin auth management, convenient dashboard UI and simple REST-ish API.

Source: PocketBase documentation, Introduction, read on .
Where each part lives on PocketBase
  • Session routepb_hooks/main.pb.js
  • REST helperpb_hooks/esc.js
  • Confirmpb_hooks/main.pb.js
  • Collectionpb_migrations/1795000000_create_esc_acceptances.js

Run on 2026-11-26 with the prebuilt PocketBase 0.42.3 executable for Linux x64, started with --dir, --hooksDir, --migrationsDir and --publicDir pointing at the folders of this project, with no Node.js and no package in the project, and with the browser SDK script build and the conformance check from esigncomply 1.0.4, against the API in test mode. A second instance with a data folder of its own was tried, the collection was read as a superuser, as a signed-in user and as a guest, and the JavaScript engine of the hooks was probed in the same version. Everything ran on one machine over plain HTTP on localhost. TLS, a domain, a reverse proxy, backups and updates of PocketBase are from its documentation as of that date and were not run.

Three steps

How does Esign Comply fit with PocketBase?

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

  1. 01
    The environment of the binary holds the keyThe hooks read ESIGNCOMPLY_API_KEY with $os.getenv. PocketBase loads no .env file: in the test an instance started beside one, without loading it, answered missing_api_key. Load the file into the shell that starts PocketBase, or set the variable in its service.
  2. 02
    A hook route creates the sessionrouterAdd("POST", "/api/ceremony", ...) sends POST /v1/sessions with $http.send and returns the client token. PocketBase serves the signup page from pb_public, and the browser SDK records the ceremony from the signer's device. Source: PocketBase documentation, Routing, read on .
  3. 03
    A locked collection keeps the receiptA migration creates esc_acceptances with all five API rules null. PocketBase's documentation calls that locked: only a superuser can perform the action through the Web API. 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. Source: PocketBase documentation, API rules and filters, read on .
PocketBase setup

Where do the key, the preview hosts and the webhook go on PocketBase?

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

The key and the other variables

Set ESIGNCOMPLY_API_KEY, the three IDs and, in production only, ESIGNCOMPLY_LIVE=true in the environment of the PocketBase process. The production guide runs PocketBase as a systemd service: the variables belong to that service. Never put the key in pb_public, which is served to everyone, or in pb_migrations, which is committed.

Source: PocketBase documentation, Going to production, read on .

Routes and static files

The hooks own /signup, /legal/{slug}, /api/ceremony and /api/signup/confirm, and all of them answered in the test. PocketBase serves pb_public/signup.html at /signup.html, so one route serves the same file at /signup. PocketBase's documentation suggests a prefix such as /api/myapp/ for your own routes, to avoid collisions with system routes.

Source: PocketBase documentation, Routing, read on .

Preview instances and test mode

PocketBase's FAQ says it is self-hosted only, so a preview is another PocketBase process on another host, with a pb_data folder of its own and the test key. List that exact host under Domains in the Esign Comply dashboard as a test origin. On localhost a test key works with no setup.

Source: PocketBase, FAQ, read on .

The registered domain and the webhook

The production guide starts PocketBase with ./pocketbase serve yourdomain.com, which issues a Let's Encrypt certificate for the domain. Register the same domain with Esign Comply and verify it with one DNS record. For the record.completed webhook, add one more routerAdd route and register its production URL under Webhooks in the Esign Comply dashboard.

Source: PocketBase documentation, Going to production, read on .

Read on : PocketBase documentation, Introduction, PocketBase documentation, Extend with JavaScript, PocketBase documentation, Routing, PocketBase documentation, Sending HTTP requests, PocketBase documentation, Migrations, PocketBase documentation, Collection operations, PocketBase documentation, Record operations, PocketBase documentation, API rules and filters, PocketBase documentation, Going to production, PocketBase, FAQ.

Copy-paste prompt

What prompt adds Esign Comply clickwrap to a PocketBase 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 PocketBase, 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 PocketBase
Add Esign Comply clickwrap to my PocketBase 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/pocketbase.md (the steps and the tested code for PocketBase)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

PocketBase facts
- There is no Esign Comply package for PocketBase. The hooks in pb_hooks run in PocketBase's embedded JavaScript engine, not in Node.js: no fetch, no setTimeout, no npm package that needs Node.js. Call the REST API with $http.send. In the browser, load the SDK from https://esigncomply.com/sdk/v1/esigncomply.js.
- The secret key is the environment variable ESIGNCOMPLY_API_KEY of the PocketBase process, read with $os.getenv. PocketBase loads no .env file. Never put the key in pb_public, in a collection or in a migration. Never print it.
- Every handler runs in a scope of its own and cannot see variables of its file. Put shared code in pb_hooks/esc.js and load it with require(`${__hooks}/esc.js`) inside each handler.
- Routes with routerAdd: GET /signup, GET /legal/{slug}, POST /api/ceremony, POST /api/signup/confirm. Never register a path PocketBase already serves under /api/: the server stops when it loads the hook.
- Keep the pinned version IDs and the receipt in a collection created by a migration in pb_migrations, with all five API rules null. Read its json field with getString() and JSON.parse, never with get().
- One PocketBase instance, one pb_data folder. A second instance with its own data cannot confirm a session of the first.
- Expect live records only where ESIGNCOMPLY_LIVE is "true": production.
- 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: POST /api/ceremony sends POST /v1/sessions with an Idempotency-Key, saves the signer ID and the pinned version IDs in the collection, and returns only clientToken, apiUrl and documents.
4. Server: GET /legal/terms and /legal/privacy render the html of GET /v1/documents/{id}/versions/{version}/content 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: POST /api/signup/confirm reads GET /v1/records/{id} and requires: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the row in the collection. 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:8090/signup --callback http://localhost:8090/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 PocketBase?

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

  • 01

    get() on a json field returns bytes, not your array

    PocketBase's documentation says json field values are exported as a raw bytes array. In the test with version 0.42.3, get() on the field that held two IDs returned an array of 15 numbers. Compared with the versions of a record, that never matches. The quickstart reads the field with getString() and JSON.parse, and the confirm route then found the pinned versions.

    Source: PocketBase documentation, Record operations, read on .
  • 02

    A handler cannot see the variables of its own file

    PocketBase's documentation says each handler is serialized and executed in an isolated context. In the test, a constant declared at the top of a hooks file was undefined inside a route, and the route that used it answered 400. The quickstart keeps the signer, the IDs and the API call in pb_hooks/esc.js and loads it with require() inside every handler.

    Source: PocketBase documentation, Extend with JavaScript, read on .
  • 03

    A hook route on a system path stops the server

    PocketBase's documentation suggests a prefix such as /api/myapp/ to avoid collisions with system routes. In the test, a hook that registered GET /api/health, a path PocketBase has, stopped the server when the hooks were reloaded, with a message that the two patterns conflict. /api/ceremony and /api/signup/confirm collided with nothing in version 0.42.3.

    Source: PocketBase documentation, Routing, read on .
Verifiable

What does Esign Comply record for a signature on PocketBase?

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

How does test mode work on preview URLs with PocketBase?

A preview is another PocketBase process with the test key and a pb_data folder of its own, on a host that a test key refuses until you list that exact host under Domains as a test origin. PocketBase has no preview deployments of its own: its FAQ says it is self-hosted only. On localhost a test key works with no setup.

Where should the receipt be stored with PocketBase?

In a collection whose five API rules are null, beside the signer ID and the record ID. In the test a guest and a signed-in user got 403 from the Web API, and the hooks read and wrote the row. The data is the pb_data folder of one server: back it up, and run one instance.

Is there an Esign Comply package for PocketBase hooks?

No. The hooks run in PocketBase's embedded JavaScript engine, which its documentation says is not a Node.js environment. In the test with version 0.42.3, fetch and setTimeout were undefined and require("esigncomply") failed. The routes call the REST API with $http.send, and the browser loads the SDK from a script tag.

Who can read the receipts in the PocketBase dashboard?

Every superuser. PocketBase's documentation says API rules are ignored for superusers, and in the test a superuser read the row, receipt included, while everyone else got 403. The production guide recommends restricting superusers to specific IP addresses and lists MFA for them as an option.

Was this code run on a production PocketBase server?

Not yet. It ran with the prebuilt PocketBase 0.42.3 executable on one machine, over plain HTTP on localhost, until the conformance check passed. The certificate that serve issues for a domain, the systemd service, backups and updates are from PocketBase's documentation and are proven only on a real server.

Keep the key in your PocketBase hooks and the receipt in a locked collection. Leave the record to us.

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

PocketBase is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about PocketBase is from PocketBase's documentation or from a test run, as marked, on . /pocketbase.md is this page as Markdown.

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