Skip to main content

Build a TLSNotary Webapp

This tutorial walks you through building a complete browser-based TLSNotary attestation application from scratch. By the end, you’ll have a working webapp that can:
  • Connect to the Demos Network
  • Request attestation tokens
  • Perform TLS attestations on HTTPS endpoints
  • Store cryptographic proofs on-chain

Prerequisites

  • Node.js 18+ or Bun
  • Basic knowledge of React and TypeScript
  • A Demos wallet with some DEM tokens for fees

Project Setup

Step 1: Initialize Project

Step 2: Install Dependencies

The Demos SDK (@kynesyslabs/demosdk) includes all TLSNotary WASM files and webpack helpers. You don’t need to install tlsn-js separately!

Step 3: Create Project Structure

Configuration Files

tsconfig.json

webpack.config.cjs

The cross-origin isolation headers are required for TLSNotary WASM to work. Without them, SharedArrayBuffer won’t be available and the attestation will fail.
The SDK provides webpack helpers that automatically configure WASM file copying and required polyfills:
The getTlsnWebpackConfig() helper automatically:
  • Configures CopyWebpackPlugin to copy WASM files from the SDK
  • Sets up Node.js polyfills required by TLSNotary
  • Enables async WebAssembly experiments
The getCrossOriginHeaders() helper returns the required COOP/COEP headers for SharedArrayBuffer.

package.json scripts

Add these scripts to your package.json:

Source Files

src/index.html

src/worker.ts

The Web Worker loads and exposes the TLSNotary WASM module. All imports come from the SDK:

src/TLSNotaryClient.ts

This wrapper handles the WASM initialization and provides a clean API. All types come from the SDK:

src/app.tsx

The main React application with full TLSNotary integration:

Running the Application

Open http://localhost:3000 in your browser.

Usage Flow

1

Initialize WASM

The app automatically initializes the TLSNotary WASM module on load.
2

Connect Wallet

Enter your mnemonic and click “Connect Wallet” to connect to the Demos Network.
3

Configure Target

Enter the HTTPS URL you want to attest. Only HTTPS URLs are supported.
4

Perform Attestation

Click “Full Attestation” to request a token and perform the attestation in one step. This burns 1 DEM for the token request.
5

Store Proof (Optional)

After attestation, click “Store On-Chain” or “Store on IPFS” to persist the proof. This burns 1 DEM base + 1 DEM per KB of proof data.

Production Considerations

Wallet Extension Integration

For production applications, use the Demos Wallet Extension instead of direct mnemonic input. The wallet extension handles the 3-step transaction flow:
  1. Generate Transaction - SDK creates the transaction
  2. Sign & Confirm - User approves in wallet extension
  3. Broadcast - Wallet sends signed transaction to network
The Wallet Extension provides better security as the mnemonic never leaves the extension.

Cross-Origin Isolation in Production

For production deployments, configure your web server to send the required headers:

Commit Ranges

The commit field in the notarization config specifies which parts of the request/response to include in the proof:
Larger ranges result in larger proofs, which increase storage costs. Only include the data you need to prove.

Error Handling

Always implement proper error handling for production:

Fee Summary

Example: Attesting and storing a 5KB proof costs:
  • Token request: 1 DEM
  • Storage: 1 (base) + 5 (size) = 6 DEM
  • Total: 7 DEM + gas fees

Next Steps