API Reference
Both classes are exported from@kynesyslabs/demosdk under the instantMessaging namespace:
@kynesyslabs/demosdk/instant_messaging subpath — the package root is the only canonical entry point.
L2PSMessagingPeer
The production client. Connects to the L2PS messaging server (default port3006) and provides registered, E2E-encrypted, persisted messaging with pagination, offline delivery, and L2PS pipeline tracking.
Constructor
signFn is invoked by the SDK whenever a frame requires an ed25519 proof — currently for register (register:{publicKey}:{timestamp}) and history (history:{peerKey}:{timestamp}). It must return a hex-encoded ed25519 signature of the input string.
Example:
Lifecycle
connect()
register with a fresh ed25519 proof, and resolves once the server replies with the registered frame. Times out after 10 seconds. The returned payload includes the list of currently online peers in the same L2PS network.
disconnect()
Disconnected, clears the local peer set, and notifies connection-state handlers with "disconnected".
Messaging
send(to, encrypted, messageHash)
{ messageHash, l2psStatus: "submitted" | "failed" }— server framemessage_sent{ messageHash, status: "queued" }— server framemessage_queued(recipient was offline)
Not registered. Call connect() first. if invoked before connect() completes.
history(peerKey, options)
peerKey. before is a millisecond timestamp for backward pagination; limit caps the page size. The SDK signs history:{peerKey}:{timestamp} with signFn and includes the proof in the request.
discover()
peer.peers).
requestPublicKey(targetId)
null if the server cannot resolve targetId.
Getters
Event handlers
Allon* handlers can be registered multiple times; registration order is preserved.
Removal counterparts:
Reconnection
On unexpected socket close,L2PSMessagingPeer retries with exponential backoff:
- Base delay 1000 ms, doubled per attempt.
- Capped at 30 000 ms.
- Up to 10 attempts.
- After the socket re-opens,
registeris replayed automatically; pendingsend/history/discoverrequests are not replayed.
MessagingPeer (legacy)
The legacy signaling-server client (default port3005). Provides peer registration, discovery, and per-message relay with the same ml-kem-aes encryption applied client-side. No persistence, no history API, no offline queue, no server-side delivery acknowledgement.
Constructor
Methods
Event handlers
Removal counterparts:
removeMessageHandler, removeErrorHandler, removePeerDisconnectedHandler, removeConnectionStateHandler.
Message interface
Reconnection
Same shape asL2PSMessagingPeer: exponential backoff starting at 1000 ms, capped at 30 000 ms, up to 10 attempts. Queued outbound messages are flushed once the connection reopens.