# E-signatures and clickwrap with Turso

> E-signatures and clickwrap with Turso: the esigncomply package in a Node.js server, and a Turso table for receipts through @libsql/client and two secrets.

Source: https://esigncomply.com/turso

Platform · Turso

To add e-signatures and clickwrap with Turso, run the `esigncomply` package in a Node.js server and keep the pinned versions and the receipt in a Turso database through `@libsql/client`. The database URL and its auth token are two secrets of your host, beside the API key. 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/turso)

`npm install esigncomply @libsql/client`

[Turso quickstart](https://esigncomply.com/docs/quickstart/turso)

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

Last updated November 26, 2026

Run locally for Turso before publishing

**Session route**

server.js (excerpt)

```js
// Step 4: create the session with the secret key. The browser gets the client token only.
if (req.method === "POST" && url.pathname === "/api/ceremony") {
  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: `${req.headers.origin ?? url.origin}/signup`, locale: "en-US", purpose: "account_signup" },
    },
    { idempotencyKey: `signup-${signer.external_id}-${randomUUID()}` },
  );
  if (error) return json(res, 502, { error: error.code });
  // In the Turso database, not in memory: the confirmation can reach another instance of this server.
  await savePinned(signer.external_id, session.documents.map((d) => d.version_id).sort());
  return json(res, 200, { clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents });
}
```

**Turso store**

store.js (excerpt)

```js
// Two secrets on your host: the URL of the Turso database and its auth token. `turso dev` asks for no token.
// The URL names the remote database, never a file: every instance of the server then reads the same rows.
const db = createClient({ url: process.env.TURSO_DATABASE_URL, authToken: process.env.TURSO_AUTH_TOKEN });

// One row per signer: the versions the session pinned, then the record and its receipt.
// SQLite has no JSON type and no timestamp type: both columns are text.
export async function migrate() {
  // A batch is one implicit transaction in a single request: both statements apply, or neither does.
  await db.batch(
    [
      `CREATE TABLE IF NOT EXISTS esc_acceptances (
        signer_id    TEXT PRIMARY KEY,
        version_ids  TEXT NOT NULL,
        record_id    TEXT,
        receipt      TEXT,
        confirmed_at TEXT
      )`,
      "CREATE UNIQUE INDEX IF NOT EXISTS esc_acceptances_record ON esc_acceptances (record_id)",
    ],
    "write",
  );
}

export async function savePinned(signerId, versionIds) {
  // JSON.stringify here: the client takes an array as an argument without an error and stores "a,b".
  await db.execute({
    sql: `INSERT INTO esc_acceptances (signer_id, version_ids) VALUES (?, ?)
          ON CONFLICT (signer_id) DO UPDATE SET version_ids = excluded.version_ids`,
    args: [signerId, JSON.stringify(versionIds)],
  });
}

export async function getPinned(signerId) {
  const { rows } = await db.execute({ sql: "SELECT version_ids FROM esc_acceptances WHERE signer_id = ?", args: [signerId] });
  // The column comes back as a string, so parse it.
  return rows.length ? JSON.parse(rows[0].version_ids) : [];
}
```

**Confirm**

server.js (excerpt)

```js
// Step 6: confirm the record with the secret key before the account exists.
if (req.method === "POST" && url.pathname === "/api/signup/confirm") {
  const { recordId } = await body(req);
  const { data: record, error } = await esc.records.get(String(recordId));
  const expected = await getPinned(signer.external_id);
  const confirmed =
    !error &&
    SEALED.includes(record.status) &&
    record.livemode === LIVE &&
    record.signer.external_id === signer.external_id &&
    expected.length > 0 &&
    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 json(res, 409, { confirmed: false });
  // Only now create the account. The record ID and the receipt go in the same row.
  await saveReceipt(signer.external_id, record.id, record.receipt);
  return json(res, 200, { confirmed: true, recordId: record.id });
}
```

**Table**

`migrate.js`

```js
// migrate.js: creates the table. Run it once for each database, and in the release step of your host.
import { close, migrate } from "./store.js";

// IF NOT EXISTS in both statements: running it again changes nothing.
await migrate();
console.log("table esc_acceptances ready");
close();
```

Integrate with Turso

## How do you integrate Esign Comply with Turso?

With Turso the server half runs on your own host and reaches the database over HTTP with `@libsql/client`. Two variables name the database, `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN`. SQLite has no JSON type, so the pinned version IDs are stored as text, and every instance of the server reads the remote database, not a local copy.

Turso Cloud is a fully managed database platform, designed to scale from prototype to production. It hosts two database engines, both fully compatible with SQLite.

Source: [Turso documentation, Turso Cloud](https://docs.turso.tech/turso-cloud), read on November 26, 2026.

[Turso quickstart](https://esigncomply.com/docs/quickstart/turso) · [All platforms](https://esigncomply.com/platforms)

Where each part lives on Turso

- **Session route** · `server.js`
- **Turso store** · `store.js`
- **Confirm** · `server.js`
- **Table** · `migrate.js`

Run on 2026-11-26 with Node.js 24.22.1, esigncomply 1.0.4, @libsql/client 0.18.0, the browser SDK script build and the conformance check from esigncomply 1.0.4, as two instances of the server on one database served by turso dev (Turso CLI 1.0.34 starting libsql-server 0.24.32, SQLite 3.45.1), with no Turso account and no login, against the API in test mode. A second turso dev started with --auth-jwt-key-file checked the auth token, and embedded replicas, batches and interactive transactions were tried against the same local server. The Turso Cloud settings are from Turso's documentation as of that date, and the turso db commands in step 8 were not run. No Turso Cloud database has been used yet.

Three steps

## How does Esign Comply fit with Turso?

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

1. **Three secrets on your host**

   `ESIGNCOMPLY_API_KEY` is read by the SDK. `TURSO_DATABASE_URL` and `TURSO_AUTH_TOKEN` go to `createClient`. Turso's documentation says SDKs require an auth token unless you work locally, and the local server of `turso dev` asked for none in the test. Source: [Turso documentation, Authentication](https://docs.turso.tech/sdk/authentication), read on November 26, 2026.

2. **Your server creates the session**

   `POST /api/ceremony` calls `esc.sessions.create` and returns the client token. The same server serves the signup page, and the browser SDK records the ceremony from the signer's device. Turso is not in that path: it holds what the server has to remember.

3. **A Turso table keeps the receipt**

   The session route stores the pinned versions as JSON text in a table of the database. The confirm route reads the record with the secret key, compares it with the row, and writes the record ID, the receipt and the time into it. `@libsql/client` is Turso's package for a remote libSQL database. Source: [Turso documentation, TypeScript reference](https://docs.turso.tech/sdk/ts/reference), read on November 26, 2026.

Turso setup

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

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

### The URL and the token

`turso db show NAME --url` prints the URL and `turso db tokens create NAME` creates a token. Turso's documentation says that token grants full access and never expires unless you pass `--expiration`. On the local server started with `--auth-jwt-key-file`, a missing or expired token failed with HTTP status `401` and a read-only token with `403` on the first write.

Source: [Turso documentation, db tokens create](https://docs.turso.tech/cli/db/tokens/create), read on November 26, 2026.

### Local development

`turso dev` starts a local libSQL server and prints its URL, `http://127.0.0.1:8080`. In the test, Turso CLI 1.0.34 ran it with no login. It starts `sqld`, which the CLI does not include: without it on the `PATH` the command printed `Could not start libsql-server`. Pass `--db-file`, or the data is lost when the server stops.

Source: [Turso documentation, Local Development](https://docs.turso.tech/local-development), read on November 26, 2026.

### Preview databases and test mode

Turso's documentation describes branching: `turso db create NAME --from-db PRODUCTION` creates a separate database, and it suggests one for each pull request. A branch needs a token of its own or a group token, and you delete it yourself. Give each preview its branch and the test key, and list the preview's exact host under Domains in the Esign Comply dashboard as a test origin.

Source: [Turso documentation, Branching](https://docs.turso.tech/features/branching), read on November 26, 2026.

### The registered domain and the webhook

Turso serves the database, not your pages: register the domain your host serves the signup page on, and verify it with one DNS record. For the `record.completed` webhook, add a route to the server and register its production URL under Webhooks in the Esign Comply dashboard.

Read on November 26, 2026: [Turso documentation, Turso Cloud](https://docs.turso.tech/turso-cloud), [Turso documentation, Turso SDKs](https://docs.turso.tech/sdk/introduction), [Turso documentation, TypeScript reference](https://docs.turso.tech/sdk/ts/reference), [Turso documentation, Authentication](https://docs.turso.tech/sdk/authentication), [Turso documentation, Authorization](https://docs.turso.tech/sdk/authorization), [Turso documentation, Local Development](https://docs.turso.tech/local-development), [Turso documentation, Embedded Replicas](https://docs.turso.tech/features/embedded-replicas/introduction), [Turso documentation, Branching](https://docs.turso.tech/features/branching), [Turso documentation, SQL over HTTP reference](https://docs.turso.tech/sdk/http/reference), [Turso documentation, db create](https://docs.turso.tech/cli/db/create), [Turso documentation, db show](https://docs.turso.tech/cli/db/show), [Turso documentation, db tokens create](https://docs.turso.tech/cli/db/tokens/create), [libSQL repository, Build and run sqld](https://github.com/tursodatabase/libsql/blob/main/docs/BUILD-RUN.md).

Copy-paste prompt

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

```
Add Esign Comply clickwrap to my app with a Turso database: 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/turso.md (the steps and the tested code for Turso)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Turso 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 database client is Turso's @libsql/client, for a libSQL database on Turso Cloud.
- Three secrets on the host: ESIGNCOMPLY_API_KEY, TURSO_DATABASE_URL and TURSO_AUTH_TOKEN. Never commit them, never print them. The local server of turso dev asks for no token.
- createClient({ url, authToken }) with the remote URL. No file: URL and no embedded replica for this table when more than one instance of the server runs: another instance reads its own copy.
- SQLite has no JSON type and no timestamp type. JSON.stringify the version IDs and JSON.parse them on read. Store the time as an ISO string. Never pass an array or a Date as an argument: the client stores "a,b" and a number of milliseconds, with no error.
- Write with one statement or with client.batch(). Never hold client.transaction() open across the call to Esign Comply: an interactive transaction times out after 5 seconds and blocks other writers until then.
- Give each preview a database of its own (turso db create NAME --from-db PRODUCTION) with a token of its own, and the test key.
- 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 creates the session with esc.sessions.create and an Idempotency-Key, saves the signer ID and the pinned version IDs in the Turso database, and returns only clientToken, apiUrl and documents.
4. Server: GET /legal/terms and /legal/privacy 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. Server: 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 row in the database. 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: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.md
```

3 things to watch

## What goes wrong when you add e-signatures on Turso?

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

- **An array argument is stored as a,b and a Date as milliseconds**

  In the test with `@libsql/client` 0.18.0, an array passed as an argument was stored as the text `dv_1,dv_2`, an object as `[object Object]` and a `Date` as `1795665600000.0`, all with no error. SQLite has no JSON type and no timestamp type. The quickstart stores `JSON.stringify` of the version IDs and an ISO string, and parses the text when it reads the row.

- **An embedded replica on another instance does not see the session**

  Turso's documentation says an embedded replica serves reads from a local file, and that other replicas see new data when they call `sync()` or at the next sync period. In the test with two replicas of one database, the first wrote a row and the second read none until it synced. The confirm route can run on another instance, so the quickstart reads the remote database.

  Source: [Turso documentation, Embedded Replicas](https://docs.turso.tech/features/embedded-replicas/introduction), read on November 26, 2026.

- **A transaction left open times out after 5 seconds**

  Turso's documentation says an interactive transaction locks the database for writing, with a 5-second timeout. In the test, a write transaction held for 7 seconds failed at commit with `TRANSACTION_TIMEOUT`, its insert was gone, and a write from a second client waited 5.1 seconds. Never keep one open across the call to Esign Comply. The quickstart writes with one statement, and creates the table with `batch()`.

  Source: [Turso documentation, TypeScript reference](https://docs.turso.tech/sdk/ts/reference), read on November 26, 2026.

## Where are the Turso quickstart and the API reference?

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

- Quickstart

  **[Turso quickstart](https://esigncomply.com/docs/quickstart/turso)**

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

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

### How does test mode work on preview URLs with Turso?

Give each preview a database of its own and the test key. Turso's documentation describes branching, `turso db create` with `--from-db`, for one database per pull request, each with its own token. The preview runs on your host's URL, which a test key refuses until you list that exact host under Domains as a test origin.

### Where should the receipt be stored with Turso?

In a table of the Turso database, beside the signer ID and the record ID. The confirm route writes the receipt and the time once the record is confirmed. Esign Comply keeps the sealed record itself, and the receipt is the signed token that names it.

### Which Turso package does a Node.js server use for this?

`@libsql/client`, Turso's client for a remote libSQL database, which is what `turso db create` makes by default. Turso's documentation names `@tursodatabase/serverless` for a remote database of the newer Turso engine, which it marks as an early preview on Turso Cloud. The quickstart was run with `@libsql/client` 0.18.0.

### Can the server use an embedded replica or a local file?

Not for this table when more than one instance runs. In the test, a second embedded replica read no row until it called `sync()`, and two `file:` URLs shared nothing. The confirm route has to see the versions the session route pinned, wherever each request lands.

### Was this code run against Turso Cloud?

Not yet. It ran against the local libSQL server that `turso dev` starts, with and without an auth token, as two instances of the server on one database. Creating a database, its URL and tokens, branches and the hosted database's behaviour are proven only on Turso Cloud.

### Other platforms

- [Supabase](https://esigncomply.com/supabase)
- [PocketBase](https://esigncomply.com/pocketbase)
- [Railway](https://esigncomply.com/railway)

### Stacks used with Turso

- [Node.js](https://esigncomply.com/nodejs)
- [Express](https://esigncomply.com/express)
- [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)

## Keep the receipt in your Turso database. Leave the record to us.

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

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

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