# Add e-signatures and clickwrap to SvelteKit

> Add e-signatures and clickwrap to SvelteKit with esigncomply in +server routes, the key in $app/env/private and @esigncomply/browser in onMount. Tested code.

Source: https://esigncomply.com/sveltekit

Stack · SvelteKit

To add e-signatures and clickwrap to SvelteKit, install `esigncomply` and `@esigncomply/browser`. A `+server` route creates the session with the secret key, which only server code can import from `$app/env/private`. The page attaches the browser SDK in `onMount`, and a second route 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.

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

`npm install esigncomply @esigncomply/browser`

[SvelteKit quickstart](https://esigncomply.com/docs/quickstart/sveltekit)

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

Last updated November 26, 2026

Run in SvelteKit before publishing

**+server route**

`src/routes/api/ceremony/+server.ts`

```ts
// src/routes/api/ceremony/+server.ts
import { json } from '@sveltejs/kit';
import { ESIGNCOMPLY_PROFILE_ID } from '$app/env/private';
import { DOCUMENTS, esc, pinned, signer } from '#lib/server/esigncomply.js';
import type { RequestHandler } from './$types';

// Step 4: create the session with the secret key. The browser gets the client token only.
export const POST: RequestHandler = async ({ request, url }) => {
	// The page that runs the ceremony: the origin the browser reports, plus its path.
	const origin = request.headers.get('origin') ?? url.origin;

	const { data: session, error } = await esc.sessions.create(
		{
			profile: ESIGNCOMPLY_PROFILE_ID,
			signer,
			documents: [
				{ document: DOCUMENTS.terms!, version: 'current' },
				{ document: DOCUMENTS.privacy!, version: 'current' }
			],
			context: { url: `${origin}/signup`, locale: 'en-US', purpose: 'account_signup' }
		},
		{ idempotencyKey: `signup-${signer.external_id}-${crypto.randomUUID()}` }
	);
	if (error) return json({ error: error.code }, { status: 502 });

	pinned.set(
		signer.external_id,
		session.documents.map((d) => d.version_id)
	);
	return json({ clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents });
};
```

**Page**

src/routes/signup/+page.svelte (excerpt)

```svelte
// One session per page load.
onMount(() => {
	start();
	return () => ceremony?.destroy();
});

async function start() {
	try {
		// Your +server route creates the session and returns { clientToken, apiUrl, documents }. Never the secret key.
		const response = await fetch('/api/ceremony', { method: 'POST' });
		if (!response.ok) throw new Error('We could not start the signup. Reload the page to try again.');
		const session = await response.json();

		ceremony = await EsignComply.attach({ clientToken: session.clientToken, apiUrl: session.apiUrl });
		ceremony.on('change', ({ remainingSteps }) => {
			canComplete = !remainingSteps.some((step) => step !== 'signature.applied');
		});

		// Point each link at the exact version this session pinned, wait for Svelte to update the DOM, then report it.
		versions = session.documents.map((document: { version_id: string }) => document.version_id);
		await tick();
		await ceremony.presentDocument({ versionId: versions[0], mode: 'hyperlink', link: termsLink });
		await ceremony.presentDocument({ versionId: versions[1], mode: 'hyperlink', link: privacyLink });
		await ceremony.observeAssent({ region: assent, checkbox, submit }); // region: notice, links, checkbox, button
		ready = true; // the SDK watches the box from here on
```

**Private key**

`src/env.ts`

```ts
// src/env.ts
import { defineEnvVars } from '@sveltejs/kit/env';

// Every variable is private unless it is marked public: only server code can import it,
// from $app/env/private. A variable with no schema must be set, or the app does not start.
export const variables = defineEnvVars({
	ESIGNCOMPLY_API_KEY: { description: 'The secret API key. Never public.' },
	ESIGNCOMPLY_PROFILE_ID: {},
	ESIGNCOMPLY_TERMS_ID: {},
	ESIGNCOMPLY_PRIVACY_ID: {},
	// Optional: the SDK picks the API host from the key when this is not set.
	ESIGNCOMPLY_API_URL: { schema: (value) => value },
	// "true" in production only.
	ESIGNCOMPLY_LIVE: { schema: (value) => value === 'true' }
});
```

**Confirm route**

`src/routes/api/signup/confirm/+server.ts`

```ts
// src/routes/api/signup/confirm/+server.ts
import { json } from '@sveltejs/kit';
import { LIVE, SEALED, esc, pinned, signer } from '#lib/server/esigncomply.js';
import type { RequestHandler } from './$types';

// Step 6: confirm the record with the secret key before the account exists.
export const POST: RequestHandler = async ({ request }) => {
	const body = await request.json().catch(() => ({})); // an empty or malformed body is refused below
	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 === 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 json({ confirmed: false }, { status: 409 });
	// Only now create the account, and store record.id and record.receipt with it.
	return json({ confirmed: true, recordId: record.id });
};
```

Integrate with SvelteKit

## How do you integrate Esign Comply with SvelteKit?

In SvelteKit the file name decides where code runs. `+server.ts` and `+page.server.ts` run on the server only, and the key reaches them through `$app/env/private`, which browser code cannot import. The script of `+page.svelte` runs on the server and in the browser, so the page attaches the SDK in `onMount`.

SvelteKit is a framework for rapidly developing robust, performant web applications using Svelte.

Source: [SvelteKit documentation, Introduction](https://svelte.dev/docs/kit/introduction), read on November 25, 2026.

[SvelteKit quickstart](https://esigncomply.com/docs/quickstart/sveltekit) · [All stacks](https://esigncomply.com/stacks)

Where each part lives in SvelteKit

- **+server route** · `src/routes/api/ceremony/+server.ts`
- **Page** · `src/routes/signup/+page.svelte`
- **Private key** · `src/env.ts`
- **Confirm route** · `src/routes/api/signup/confirm/+server.ts`

Run on 2026-11-26 with SvelteKit 3.4.0, Svelte 5.59.1, Vite 8.3.8 and @sveltejs/adapter-node 6.0.5, esigncomply 1.0.4 and @esigncomply/browser 1.0.4 on Node.js 24.22.1, under vite dev (the conformance check from esigncomply 1.0.4) and as the built Node.js server (one ceremony), against the API in test mode.

Copy-paste prompt

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

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

SvelteKit facts
- Packages (the only ones that exist): esigncomply (server code, Node.js 20.19 or later) and @esigncomply/browser (the page). There is no Svelte package. This is SvelteKit 3 with Svelte 5 runes: configuration is in vite.config.ts, and the lib alias is #lib.
- Declare ESIGNCOMPLY_API_KEY in src/env.ts with defineEnvVars and never mark it public. Import it only in server code, from $app/env/private, and pass it to new EsignComply(key): under vite dev the values of .env are not in process.env.
- Create the client in src/lib/server/. A file in a server directory cannot be imported by code that runs in the browser: the build stops with server_only_import.
- Server SDK calls return { data, error } and do not throw. Check error every time.
- The script of +page.svelte also runs on the server. Call fetch and EsignComply.attach inside onMount only. After you set the state that feeds the two link addresses, await tick() before presentDocument.
- In production set ORIGIN to the address visitors use (adapter-node), or SvelteKit answers the page's own POST with 403.
- The form is in the server HTML before the page hydrates: 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. src/routes/api/ceremony/+server.ts (POST): create the session with esc.sessions.create and an Idempotency-Key, save the signer ID and the pinned version IDs in server-owned state, and return only clientToken, apiUrl and documents.
4. src/routes/legal/[slug]/+page.server.ts and +page.svelte: load the registered version from esc.documents.versions.getContent and render it inside <article data-esc-document> with {@html}, unmodified.
5. src/routes/signup/+page.svelte: in onMount, EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }) with bind:this elements, then ceremony.complete() in the submit handler. The checkbox has no checked attribute and no bind:checked that starts true.
6. src/routes/api/signup/confirm/+server.ts (POST): 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 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:5173/signup --callback http://localhost:5173/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 in SvelteKit?

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

- **Under vite dev, the key is not in process.env**

  The `esigncomply` client reads `ESIGNCOMPLY_API_KEY` from `process.env` when it gets no argument. In a test on SvelteKit 3.4.0 under `vite dev`, the key from `.env` was in `$app/env/private` and not in `process.env`, and a client created with no argument answered `missing_api_key`. Pass the key from `$app/env/private`.

- **The built server answers 403 to the session request until ORIGIN is set**

  After the build, SvelteKit compares the `Origin` header of a `POST` that has a form content type, or none, with its own origin. In the test, the adapter-node build run on `http://localhost` without `ORIGIN` answered the page's own `POST /api/ceremony` with `403`. With `ORIGIN` set it answered `200`. `vite dev` makes no such check.

  Source: [SvelteKit documentation, Node servers](https://svelte.dev/docs/kit/adapter-node), read on November 25, 2026.

- **A page that imports the private module fails the build, not the first render**

  `vite build` stopped with `server_only_import` when a page imported `$app/env/private` or a file under `src/lib/server`. Under `vite dev` the same page was rendered on the server once, with the value in its HTML, before the browser's request for the module was refused. Keep secrets out of `+page.svelte` from the start.

  Source: [SvelteKit documentation, Server-only modules](https://svelte.dev/docs/kit/server-only-modules), read on November 25, 2026.

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

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

- Quickstart

  **[SvelteKit quickstart](https://esigncomply.com/docs/quickstart/sveltekit)**

  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 in SvelteKit?

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

### Is there an Esign Comply SDK for SvelteKit?

Yes, the two JavaScript packages, and no Svelte bindings. `+server` routes use `esigncomply`, and the page calls `@esigncomply/browser` directly in `onMount`. The browser SDK is headless, so it attaches to the markup you wrote.

### Where do I create the session in SvelteKit?

In a `+server.ts` route, for example `src/routes/api/ceremony/+server.ts`, with `esc.sessions.create`. The client lives in `src/lib/server`, which only server code can import, and the route returns only the client token, the API URL and the pinned documents.

### Does the SvelteKit cookies helper sign or encrypt what it sets?

No. In a test, `cookies.set` with the value `plain-value` sent the header `probe=plain-value; Path=/; HttpOnly; SameSite=Lax` under `vite dev`, and the same with `Secure` from the built server. The quickstart keeps the pinned versions on the server instead: a Map for a first run, a table in your database after that.

### Why does a fetch at the top of the page script answer 500?

Because that script also runs on the server while the page is rendered. In a test on SvelteKit 3.4.0, a `fetch` to `/api/ceremony` at the top level stopped the render with `ssr_fetch_relative_url`. The quickstart makes the request in `onMount`, which does not run on the server.

### What happens when a declared variable is missing?

The app does not run. In the test, the built server started with no variables stopped with `env_invalid` and named `ESIGNCOMPLY_API_KEY`, and under `vite dev` the page and the route answered `500` with the same message. `src/env.ts` declares the key with no schema, which makes it required.

### Other stacks

- [Nuxt](https://esigncomply.com/nuxt)
- [Next.js](https://esigncomply.com/nextjs)
- [Vue](https://esigncomply.com/vue)

### Platforms used with SvelteKit

- [Vercel](https://esigncomply.com/vercel)
- [Netlify](https://esigncomply.com/netlify)
- [Cloudflare Pages](https://esigncomply.com/cloudflare-pages)

[All stacks](https://esigncomply.com/stacks) · [All platforms](https://esigncomply.com/platforms) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Build the signup in your own SvelteKit app. Leave the record to us.

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

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

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