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. 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/browserFree plan: 10 live signatures a month and a full test mode. No card required.
Last updated
// 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 }); };
// 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
// 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' } });
// 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 }); };
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, 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 .- +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.
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 toolAdd 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.mdWhat 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
esigncomplyclient readsESIGNCOMPLY_API_KEYfromprocess.envwhen it gets no argument. In a test on SvelteKit 3.4.0 undervite dev, the key from.envwas in$app/envand not in/private process.env, and a client created with no argument answeredmissing_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
Source: SvelteKit documentation, Node servers, read on .Originheader of aPOSTthat has a form content type, or none, with its own origin. In the test, the adapter-node build run onhttp:/without/localhost ORIGINanswered the page's ownPOST /apiwith/ceremony 403. WithORIGINset it answered200.vite devmakes no such check. - 03
A page that imports the private module fails the build, not the first render
Source: SvelteKit documentation, Server-only modules, read on .vite buildstopped withserver_only_importwhen a page imported$app/envor a file under/private src/lib. Under/server vite devthe 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.sveltefrom the start.
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.
- QuickstartSvelteKit 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 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, 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 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, with esc.sessions.create. The client lives in src/lib, 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 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.