Skip to main content

L2PS SDK

Layer 2 Privacy Subnets (L2PS) are encrypted execution lanes that ride on top of the main Demos Network. Transactions submitted to a subnet are encrypted with AES-GCM before they reach the mempool, batched, proven, and confirmed without revealing their contents to non-members. The architecture and lifecycle live in L2PS Privacy Subnets. This page documents the SDK surface used by clients to encrypt transactions for a subnet they belong to. The L2PS module is exported from @kynesyslabs/demosdk/l2ps.

Creating an L2PS instance

L2PS.create(privateKey?, iv?) is the factory method. Each instance is a participant in one subnet, identified by the SHA-256 of its private key. Random keys are generated if you don’t provide your own.
Members of the same subnet must share both the private key and the IV. Distribute these out-of-band — the SDK never transmits them.

Encrypting a transaction

encryptTx(tx, senderIdentity?) takes an ordinary signed Transaction and wraps it in a new transaction of type "l2psEncryptedTx". The original payload is serialized, encrypted with AES-GCM, base64-encoded, and stored alongside the auth tag and a hash of the original transaction for integrity verification.
The wrapped transaction carries an L2PSEncryptedPayload:
The optional senderIdentity parameter overrides the from field on the encrypted wrapper — useful when subnet members want to obscure the originating address from non-members.

Decrypting a transaction

Subnet members verify and decrypt incoming traffic with decryptTx:
Decryption uses the same private key + IV as encryption. AES-GCM’s authentication tag detects tampering — a modified payload throws rather than silently producing garbage.

Instance registry

L2PS instances are registered in a static map keyed by their ID (SHA-256 of the private key). Useful when a process participates in multiple subnets:

Configuration object

You can attach an L2PSConfig to an instance to associate it with a subnet UID and known RPC endpoints:
When a config is set, encryptTx uses config.uid as the l2ps_uid on the encrypted payload. Otherwise the instance ID (SHA-256) is used.