Skip to main content

The L2PS Module

The L2PS module provides client-side encryption for private transactions on the Demos Network.

Installation

import { L2PSEncryption } from "@kynesyslabs/demosdk/l2ps"

Initialization

To use L2PS, you need the shared encryption keys for your L2PS network:
// Keys must match the L2PS network configuration
const aesKey = "your_64_character_hex_aes_256_key..."
const iv = "your_32_character_hex_iv..."
const l2psUid = "testnet_l2ps_001"

// Create L2PS encryption instance
const l2ps = new L2PSEncryption(aesKey, iv)
Critical: The AES key and IV must exactly match the keys configured on the L2PS network nodes. If there’s any mismatch, transactions will fail to decrypt on the node side.

Configuration Options

ParameterTypeDescription
aesKeystring64-character hex string (256-bit AES key)
ivstring32-character hex string (128-bit initialization vector)

Key Generation

If you’re setting up a new L2PS network, generate keys using OpenSSL:
# Generate AES-256 key (32 bytes = 64 hex characters)
openssl rand -hex 32 > private_key.txt

# Generate IV (16 bytes = 32 hex characters)
openssl rand -hex 16 > iv.txt

Encryption Details

The L2PS module uses AES-256-CBC encryption:

AES-256

Industry-standard symmetric encryption with 256-bit key security.

CBC Mode

Cipher Block Chaining provides semantic security for variable-length messages.

What Gets Encrypted

// This inner transaction is encrypted
const innerTx = {
  type: "native",
  from: "0xSender...",
  to: "0xRecipient...",
  amount: 10,
  nonce: 5,
  timestamp: Date.now()
}

// The encrypted blob is wrapped in outer L2PS transaction
const l2psTx = {
  type: "l2ps",
  to: l2psUid,      // L2PS network identifier
  data: encryptedBlob  // Encrypted inner transaction
}

Key Matching Requirement

For POC App Users: Copy keys directly from your node’s L2PS configuration:
# From your Demos node directory, view key contents
cat data/l2ps/testnet_l2ps_001/private_key.txt
cat data/l2ps/testnet_l2ps_001/iv.txt
Then paste these values into your POC app’s .env file as VITE_L2PS_AES_KEY and VITE_L2PS_IV.

Next Steps

Interacting with L2PS

Learn how to send encrypted transactions and query history