Skip to content
Stack · SvelteKit

Add e-signatures and clickwrap to 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.

$npm install esigncomply @esigncomply/browser
SvelteKit quickstart

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

Last updated

Run in SvelteKit before publishing
src/routes/api/ceremony/+server.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 });
};
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, read on .
Where each part lives in SvelteKit
  • +server routesrc/routes/api/ceremony/+server.ts
  • Pagesrc/routes/signup/+page.svelte
  • Private keysrc/env.ts
  • Confirm routesrc/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. 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 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.

  • 01

    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.

  • 02

    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, read on .
  • 03

    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, read on .
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.

  • 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 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.

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

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 . /sveltekit.md is this page as Markdown.

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