@clasp-to/crypto
v4.3.0
Published
E2E encryption add-on for CLASP protocol clients - AES-256-GCM, ECDH P-256, ECDSA signing, TOFU verification
Maintainers
Readme
@clasp-to/crypto
E2E encryption add-on for CLASP protocol clients. Provides client-side AES-256-GCM encryption that is transparent to the router.
Install
npm install @clasp-to/cryptoPeer dependency: @clasp-to/core ^4.0.0
Quick Start
import { Clasp } from '@clasp-to/core'
import { CryptoClient, MemoryKeyStore } from '@clasp-to/crypto'
const clasp = new Clasp('ws://localhost:7330')
const crypto = new CryptoClient(clasp, {
identityId: 'device-1',
store: new MemoryKeyStore(),
})
// Create an encrypted session
const session = crypto.session('/myapp/signals', {
rotationInterval: 3_600_000, // 1 hour
})
await session.start()
await session.enableEncryption()
// Encrypted set/emit -- CryptoClient handles encryption automatically
await crypto.set('/myapp/signals/fader', 0.75)
await crypto.emit('/myapp/signals/trigger', { note: 60 })
// Encrypted subscribe -- auto-decrypts E2E envelopes
crypto.subscribe('/myapp/signals/**', (data, address) => {
console.log(address, data) // decrypted automatically
})API
CryptoClient
Wraps a Clasp instance for transparent encrypt/decrypt.
session(basePath, options?)-- get or create anE2ESessionset(address, value)-- encrypts if a session matches, otherwise passes throughemit(address, payload?)-- same behavior asset()subscribe(pattern, callback)-- auto-decrypts E2E envelopes before callbackclose()-- destroys all sessions
E2ESession
Manages key exchange and encryption for one group/room/channel.
start()-- subscribe to key exchange paths, load persisted keyenableEncryption()-- generate a new group keyrequestGroupKey()-- request the group key from peersencrypt(value)-- encrypt a string into anE2EEnvelopedecrypt(envelope)-- decrypt anE2EEnvelopeback to a stringrotateKey()-- generate a new key and distribute to peersdestroy()-- clean up subscriptions and zero key material
Storage Backends
MemoryKeyStore-- in-memory, for testing or ephemeral sessionsIndexedDBKeyStore-- browser-based persistent storage
Documentation
See the E2E Encryption Guide for the full protocol description, key exchange flow, and security properties.
License
MIT
