Peer SDK
@vaultys/peer-sdk connects VaultysID identities directly to each other. Every peer is a did:vaultys. Two peers prove who they are to each other before anything is exchanged, and everything after that is end-to-end encrypted.
const peer = await createPeer({ identity, transport: peerjsTransport() });
await peer.send(bobDid, { text: "Hello, Bob" });
peer.on("message", ({ from, body }) => console.log(from, body));
Version 2
This documentation covers v2, a rewrite that isn't compatible with v1. If you're upgrading, see Migrating from v1. v2 is a pre-release (2.0.0-alpha) and isn't published to npm yet.
What you get
| Verified peers | A mutual VaultysID handshake runs before any data flows. A message's from is the DID the sender proved, not one it claimed. |
| End-to-end encryption | Each session uses a key only the two identities can derive. The relay that introduces peers can't read or alter traffic. |
| Durable messaging | send() stores the message, delivers it when the recipient is reachable, retries, and reports delivery. |
| Your own protocols | Typed channels for anything else (cursors, presence, signaling), multiplexed over the same sessions. |
| Collaboration | A Yjs provider for shared documents, canvases and presence. |
| Small and pluggable | The transport, storage and collaboration layers are separate entry points. The core has one dependency (msgpack). |
How it fits together
your app ── createPeer() ─ contacts · durable messages · protocols · events
│
Session ──── one authenticated, encrypted link per DID
│
handshake ─── mutual VaultysID proof + key agreement
│
Transport ── moves raw frames: PeerJS/WebRTC, in-memory, your own
Each layer only depends on the one below it. You'll usually only touch createPeer() and choose a transport.
Packages and entry points
| Import | Contains | Needs |
|---|---|---|
@vaultys/peer-sdk | createPeer, stores, memoryNetwork, errors | @vaultys/id |
@vaultys/peer-sdk/peerjs | peerjsTransport (WebRTC through a PeerJS relay) | peerjs |
@vaultys/peer-sdk/yjs | YjsProvider, ownedBy | yjs, y-protocols, lib0 |
@vaultys/peer-sdk/node | fileStore, installWebRTC | Node.js |
Next steps
- Quickstart: two peers chatting in a few minutes.
- Identity and trust: what a peer is, and who may talk to you.
- Playground: try it in two browser tabs, no code needed.