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.
L2PSEncryptedPayload:
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 withdecryptTx:
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 anL2PSConfig to an instance to associate it with a subnet UID and known RPC endpoints:
encryptTx uses config.uid as the l2ps_uid on the encrypted payload. Otherwise the instance ID (SHA-256) is used.
Related documentation
- L2PS Privacy Subnets (Backend) — architecture, batch lifecycle, ZK-proof aggregation.
- How L2PS Transactions Are Handled — node-side processing of
l2psEncryptedTx. - L2PS Quickstart — running an L2PS subnet end-to-end.