Skip to main content

Quickstart

This quickstart targets the production messaging client, L2PSMessagingPeer (default port 3006). For the legacy signaling-server flow (MessagingPeer, port 3005), see the section at the bottom.

1. Install and import

The only canonical import path for both classes is the package root: import { instantMessaging } from "@kynesyslabs/demosdk". There is no @kynesyslabs/demosdk/instant_messaging subpath.

2. Build a signFn

L2PSMessagingPeer registers and authenticates by signing short proof strings (register:{publicKey}:{timestamp}, history:{peerKey}:{timestamp}) with an ed25519 key. The constructor takes a signFn that you control — bring your own ed25519 signer.

3. Connect

connect() opens the WebSocket, sends the register frame with a fresh ed25519 proof, and resolves once the server replies with registered.

4. Receive messages

5. Send a message

L2PSMessagingPeer.send takes an already-encrypted payload (a SerializedEncryptedMessage) plus a messageHash for server-side dedup. You produce the encrypted payload with your ML-KEM-AES encryption layer and serialize it to the wire shape:

6. Read history

Each StoredMessage includes id, from, to, messageHash, encrypted, l2psUid, l2psTxHash, timestamp, and a status from the L2PS pipeline (delivered, queued, sent, failed, l2ps_pending, l2ps_batched, l2ps_confirmed).

7. Discover peers and disconnect

You can also read state synchronously: peer.isConnected, peer.isRegistered, peer.peers.

Connection lifecycle

  1. Initialization — construct an L2PSMessagingPeer with serverUrl, publicKey, l2psUid, and signFn.
  2. Connectionconnect() opens the WebSocket and registers the peer; the server replies with registered.
  3. Communicationsend(), history(), discover(), requestPublicKey(). Inbound messages arrive through onMessage.
  4. Reconnection — on socket close, the client retries with exponential backoff (base 1000 ms, max 10 attempts, capped at 30 s) and re-registers automatically.
  5. Disconnectiondisconnect() stops reconnection, closes the socket, rejects all pending request-response promises, and clears the peer set.

Legacy: MessagingPeer (port 3005)

The legacy signaling-server client is still exported for backwards compatibility:
MessagingPeer does not provide history, offline delivery, or server-side delivery acknowledgement — for those, use L2PSMessagingPeer.