Quickstart
Install the SDK and run a real encrypted round trip through a Sandbox environment of the Signal Protocol Relay.
- Status
- stable
- Applies to
- 15.0.0
- Platforms
- Node · Browser · Expo
- Prereqs
- Node 22.18+ and a package manager
- Reading time
- 6 min
This page has one goal. One identity encrypts a message, the ciphertext stays unreadable in transit, and another identity decrypts it. You do not deploy a relay. A Sandbox environment of the OpenE2EE Signal Protocol Relay carries the envelopes. Once that runs, you know the protocol works in your runtime. Every other page explains how to replace the development pieces.
Try it before installation
Open the playground to run a message and reply with real console output.
For native execution, follow Expo setup. Use a native development or release build. Expo Go does not include SQLCipher.
Install locally
npm install @open-e2ee/signal-protocol-sdk@latestConnect a Sandbox environment
The round trip needs two things:
-
A Relay project. The
oecommand creates a Relay project and its Sandbox environment. The Sandbox environment needs no payment card. -
An identity assertion. The Relay registers a device only with a signed identity assertion. A
getIdentityAssertion(request)callback supplies it.In a Sandbox environment configured for device-owned identity,
hostedSignalProtocolRelaySandboxIdentity(storage)creates the callback. It signs a device-owned assertion with a key in the device-local store. The device keeps the same Sandbox account when it registers again. The helper works only in Sandbox.hostedSignalProtocolRelayDeviceOwnedIdentity(storage)signs with the same key, and it also works in a device-owned Production environment.Every environment, Production included, starts device-owned. For application-bound Production accounts, select the custom-token profile before the first device registers. The callback then returns a short-lived assertion for the signed-in user. Identity and authentication describes both modes.
The SDK needs Node.js 22.12 or later. The oe command needs Node.js 22.18 or later, so this page needs Node.js 22.18 or later. In the directory where you installed the SDK, run these commands:
npm install --global @open-e2ee/oe
oe auth login
oe new
npm installA person approves the login in a browser. When the Organization has not accepted the OpenE2EE terms, read them, then run oe auth login --accept-terms. At a terminal, a person who belongs to more than one Organization chooses one at login. oe org switch changes it later. To run oe without an installation, use npx @open-e2ee/oe@latest in place of oe, for example npx @open-e2ee/oe@latest new. Do not run npx oe, because the npm package oe is not an OpenE2EE package.
If you already created a project in the Console, run oe link PROJECT_SLUG instead of oe new. Copy the slug from the project Settings page or use the exact command in its Sandbox setup guide. The link command uses that project and creates no second project.
Check its saved Sandbox identity first. This program does not work with Clerk, Firebase, or custom-token identity. Those verifiers require the configured application identity through getIdentityAssertion. See identity and authentication for the current setup restrictions.
oe new creates the Relay project and writes the Sandbox connection URL to .env.local. The URL is public configuration. It is not a credential. The variable name comes from the dependencies and devDependencies of package.json. The first row of this table that matches sets the name:
| Dependency | Variable in .env.local |
|---|---|
next | NEXT_PUBLIC_OPEN_E2EE_SIGNAL_RELAY_URL |
expo | EXPO_PUBLIC_OPEN_E2EE_SIGNAL_RELAY_URL |
vite | VITE_OPEN_E2EE_SIGNAL_RELAY_URL |
None of these, or no package.json | OPEN_E2EE_SIGNAL_RELAY_URL |
To set a different name, run oe new --env-var NAME. The CLI reference lists every oe command.
oe new also adds @open-e2ee/oe to the devDependencies of package.json, because open-e2ee.config.ts imports its types. npm install installs it. With pnpm, Yarn, or Bun, run the install command that oe new prints.
The whole round trip
Two identities in one process, each with its own device-local store. The Sandbox environment is between them.
import {
createHostedSignalProtocolClient,
hostedSignalProtocolRelaySandboxIdentity,
} from '@open-e2ee/signal-protocol-sdk';
import { inMemoryStore } from '@open-e2ee/signal-protocol-sdk/local/store/memory';
// Match the framework variable that oe link or oe new writes.
// A .env.local file that oe 4 wrote holds the names without SIGNAL_ until you run oe link again or rename them.
const variables = [
'NEXT_PUBLIC_OPEN_E2EE_SIGNAL_RELAY_URL',
'EXPO_PUBLIC_OPEN_E2EE_SIGNAL_RELAY_URL',
'VITE_OPEN_E2EE_SIGNAL_RELAY_URL',
'OPEN_E2EE_SIGNAL_RELAY_URL',
];
const variable = variables.find((name) => process.env[name]);
if (!variable) {
throw new Error('Run oe link in this directory. Expected ' + variables.join(' or ') + ' in .env.local.');
}
const relayUrl = process.env[variable]!;
const aliceStorage = inMemoryStore();
const alice = await createHostedSignalProtocolClient({
adapters: { storage: aliceStorage },
hosted: { relayUrl, getIdentityAssertion: hostedSignalProtocolRelaySandboxIdentity(aliceStorage) },
});
const bobStorage = inMemoryStore();
const bob = await createHostedSignalProtocolClient({
adapters: { storage: bobStorage },
hosted: { relayUrl, getIdentityAssertion: hostedSignalProtocolRelaySandboxIdentity(bobStorage) },
});
const delivered = new Promise<void>((resolve) => {
bob.registerHook('onMessageDecrypted', async (message) => {
console.log(`${message.senderId}: ${message.content}`);
resolve();
});
});
let timer: ReturnType<typeof setTimeout> | undefined;
try {
await alice.send(bob.userId, 'the ratchet turned');
bob.startRelaySubscription();
await Promise.race([
delivered,
new Promise<never>((_, reject) => {
timer = setTimeout(() => reject(new Error('No message arrived within 30 seconds. Run oe doctor --env sandbox.')), 30_000);
}),
]);
} finally {
clearTimeout(timer);
await Promise.all([bob.stop(), alice.stop()]);
}Save the program as quickstart.mts in the same directory. Then run it:
node --env-file=.env.local quickstart.mtsNode.js 22.18 and later run TypeScript files without a build step. The .mts extension makes Node.js load the file as an ES module, which permits the top-level await. --env-file=.env.local loads the connection URL.
The program checks the names in the table in the same order as the CLI. It therefore runs from an existing Next.js, Expo, or Vite directory without changing the variable in the example. If the value is missing, the error names the expected variables and .env.local. Always load the Sandbox file, including after Production activation.
That prints one line: Alice's account ID, a colon, and the ratchet turned. Then run oe doctor --env sandbox to read the recorded acknowledgment. You can repeat that check. To observe a new acknowledgment, start oe doctor --env sandbox --wait in another terminal before you run the program.
The protocol and cryptography are real, and so is the relay. send() ran the required PQXDH handshake against Bob's published prekey bundle. It then created the configured ratchets and produced real ciphertext. The Sandbox environment registered both devices, distributed their public keys, and carried the envelope.
What each line actually did
| Call | What happened |
|---|---|
inMemoryStore() | Created the device-local protocol state. adapters.storage is the only required adapter. |
hostedSignalProtocolRelaySandboxIdentity(storage) | Created the Sandbox identity callback. On its first call, it created the account key and kept it in storage. |
createHostedSignalProtocolClient | Created or loaded the device's identity and prekeys, then authenticated and registered the device with the Relay and published its public prekeys. |
getIdentityAssertion | Returned the device-owned assertion for the registration, signed with the account key. The Relay authorizes each request from verified credentials, never from an identifier that the client sends. |
userId | Returned the account ID that the Relay assigned. |
registerHook('onMessageDecrypted', …) | Registered the callback that receives a DecryptedEnvelope after successful decryption. |
send() | Fetched Bob's prekey bundle, established a session on first contact, encrypted, and handed the envelope to the Relay. |
startRelaySubscription() | Started relay delivery and device-local decryption. The promise keeps the example alive until the hook receives the plaintext. |
Run it again
hostedSignalProtocolRelaySandboxIdentity keeps the account key in the store that you pass to it. An identity keeps its Sandbox account only while its store keeps that key. Pass the same store as adapters.storage.
An in-memory store makes a new Sandbox test account on each run
inMemoryStore() loses the account key when the process stops. So each run of the program creates two new Sandbox test accounts, one for Alice and one for Bob. The Sandbox boundary gives the number of test accounts that the environment includes.
For repeated runs, keep the state in files. Install the peer of the Node store:
npm install @open-e2ee/signal-protocol-sdk@latest better-sqlite3-multiple-ciphersThen replace the two inMemoryStore() calls:
import type { SignalProtocolLocalSecretVault } from '@open-e2ee/signal-protocol-sdk';
import { nodeStore } from '@open-e2ee/signal-protocol-sdk/local/store/node';
// A database without encryption at rest does not use the vault.
const refuse = async (): Promise<never> => {
throw new Error('This Sandbox test store has no vault.');
};
const noVault: SignalProtocolLocalSecretVault = {
getSecret: refuse,
setSecret: refuse,
deleteSecret: refuse,
};
const aliceStorage = await nodeStore({
directory: '.open-e2ee',
name: 'alice.db',
vault: noVault,
encryptionAtRest: false,
});
const bobStorage = await nodeStore({
directory: '.open-e2ee',
name: 'bob.db',
vault: noVault,
encryptionAtRest: false,
});Each run then uses the same two Sandbox accounts. The files hold private keys without encryption, and the store logs a warning at each open. Use them only for Sandbox tests, and add .open-e2ee/ to .gitignore. To start again with new accounts, delete the directory.
What the relay receives
Look at what send() returns:
const result = await alice.send(bob.userId, 'the ratchet turned');
console.log(result);send() returns a SendResult with message identifiers, timestamps, and the number of recipient devices. It holds no message plaintext. The relay receives each message as an Envelope, the type that /remote/signal-relay/types exports. An Envelope holds the ciphertext plus routing metadata: sender and recipient identifiers, device IDs, a message type, a delivery class, and timestamps. The relay needs those to deliver. It does not need, and does not get, the plaintext.
That distinction is the whole product, and it has a hard edge worth understanding early: the metadata is real and it is not encrypted. Who talks to whom, how often, from how many devices, and at what size is visible to whoever runs the relay. See what the relay can still see before you make promises to your users.
Replace the in-memory store
The in-memory store was the shortcut. Replacing it is the actual integration work, and it differs by runtime more than anything else in the SDK. Pick yours: the rest of the documentation will keep showing it.
npm install @open-e2ee/signal-protocol-sdk@latest react-native-get-random-values expo-secure-store expo-sqliteimport 'react-native-get-random-values';
import { expoStore } from '@open-e2ee/signal-protocol-sdk/local/store/expo';
const signal = await createHostedSignalProtocolClient({
adapters: { storage: await expoStore() },
hosted: { relayUrl, getIdentityAssertion },
});await expoStore() opens the SDK-owned SQLCipher database with a key from expo-secure-store. react-native-get-random-values gives the SDK its global random source, so load it before the first SDK call. The store needs a development build, so understand it before you start.
npm install @open-e2ee/signal-protocol-sdk@latest idbimport { webSqliteStore } from '@open-e2ee/signal-protocol-sdk/local/store/web-sqlite';
const storage = await webSqliteStore();await webSqliteStore() opens an SDK-owned, encrypted SQLite database in the origin private file system, with its key in IndexedDB through the idb peer. It needs a CSP that allows 'wasm-unsafe-eval'. Where the origin private file system is not available, the open fails with OPFS_UNAVAILABLE, and you use await indexedDbStore() from /local/store/web there. Both stores support the full store contract. A deployment still requires the browser threat-model review.
npm install @open-e2ee/signal-protocol-sdk@latest better-sqlite3-multiple-ciphersimport { nodeStore } from '@open-e2ee/signal-protocol-sdk/local/store/node';
const storage = await nodeStore({
directory: '/var/lib/my-app/signal-protocol',
vault,
});nodeStore opens an SDK-owned SQLCipher database in directory, with its key in the vault that you pass. Both options are required. Use a private directory on a local file system.
The relay is the other half. It is a backend choice, not a runtime choice: the Signal Protocol Relay or an application-owned SignalProtocolRelayServer. Choosing adapters describes all four slots and their maturity.
The seven production decisions behind this example
The short program works because the in-memory store, the Sandbox identity helper, and the Sandbox environment hide decisions that a production application must make. Decide these before you ship.
-
Package.
@open-e2ee/signal-protocol-sdkis OpenE2EE's maintained TypeScript package for this protocol profile. It is independent and does not interoperate with Signal Messenger or libsignal. Compare the maintained alternatives and their limits. -
Key custody. Identity private keys, prekey private halves, sessions, and ratchet state stay in the device-local protocol store. The relay receives public key material. The in-memory store has no wrapping key. The Expo store holds a SQLCipher key through secure storage. The browser store keeps its record key in the same origin. The Node store holds a SQLCipher key in the vault that the application passes.
-
Key lifetime. Identity keys change only through explicit trust, while signed and Kyber prekeys refresh after two days. Their hard age ceiling is 14 days. One-time prekeys live until a peer consumes them. Retained Double Ratchet message keys expire after seven days. Deleting local storage removes only this device's copy. It cannot erase copies, plaintext, or backups held elsewhere.
-
Relay visibility. Per message, the relay receives ciphertext and delivery metadata. This includes user and device identifiers, message type, timestamp, and size. It does not need message plaintext or device private keys. Encryption is not anonymity. Read limits and metadata before you write user-facing claims.
-
Prekey maintenance.
syncToServer()uploads and replenishes batches of EC and Kyber one-time public prekeys. Mobile apps can run it on foreground, while services can use a schedule. Exhaustion can use a last-resort key with weaker initial forward secrecy. The sender receives no error for that fallback. Monitor the remaining count and the low-watermark hook. Key rotation gives the exact controls. -
Additional devices. In the two-device link, the new device calls
joinHostedSignalProtocolRelayAccount()with an empty store, and device 1 approves it. The one-process link,linkHostedSignalProtocolRelayDevice(), needs the account identity in the new store, from transfer or your own channel. The new device gets its own registration, prekeys, and sessions. It gets no existing sessions or message history. It cannot decrypt messages sent before it existed. Multi-device covers the link, and device lifecycle covers revocation. -
Recovery. The SDK does not choose a recovery policy. A
business-archiveprofile keeps an encrypted recovery artifact for continuity. This creates a durable attack surface. Ahigh-risk-messagingprofile makes lost-device history unrecoverable. Acollaboration-defaultprofile preserves limited working context but is not a system of record. Recovery, backup, and migration defines the tradeoffs and operations.
Authentication, authorization, first-contact trust, safety-number verification, groups, and attachments are also application work. Use the production checklist before release.
Next
- Choosing adapters: decide what replaces the in-memory store.
- End-to-end encryption architecture: the model underneath the six lines.
- Keys, identity, and sessions: what the client published and why.
- API reference: the full client surface.