A ratcheting forward secrecy protocol that works in synchronous and asynchronous messaging environments.
WARNING: This code has NOT been reviewed by an experienced cryptographer. IT IS FOR RESEARCH ONLY!!!!!
You can read more about the signal protocol (formerly /axolotl/ for its self-healing abilities) here.
npm install signal-protocol
There are two ways to use this package.
You can require with your front-end bundler of choice (e.g. browserify, webpack):
var signal =
IMPT NOTE!!! If you intend to call this from the browser, have your bundler exclude
src/node_polyfills.js. You won't need that file for your browser bundles, and it could crash your bundler. (Even at best, it will add tons of useless junk to your bundled js file).
Or, you can include the prebundled
dist/libsignal.js in your HTML file.
The following steps will walk you through the lifecycle of the signal protocol
This protocol uses a concept called 'PreKeys'. A PreKey is an ECPublicKey and an associated unique ID which are stored together by a server. PreKeys can also be signed.
At install time, clients generate a single signed PreKey, as well as a large list of unsigned PreKeys, and transmit all of them to the server.
var signal =var KeyHelper = signalKeyHelper;var registrationId = KeyHelper;// Store registrationId somewhere durable and safe.KeyHelper;KeyHelper;KeyHelper;// Register preKeys and signedPreKey with the server
Signal Protocol is session-oriented. Clients establish a "session," which is then used for all subsequent encrypt/decrypt operations. There is no need to ever tear down a session once one has been established.
Sessions are established in one of two ways:
An established session encapsulates a lot of state between two clients. That state is maintained in durable records which need to be kept for the life of the session.
State is kept in the following places:
A signal client needs to implement a storage interface that will manage
loading and storing of identity, prekeys, signed prekeys, and session state.
test/InMemorySignalProtocolStore.js for an example.
Once your storage interface is implemented, building a session is fairly straightforward:
var store = ;var address = recipientId deviceId;// Instantiate a SessionBuilder for a remote recipientId + deviceId tuple.var sessionBuilder = store address;// Process a prekey fetched from the server. Returns a promise that resolves// once a session is created and saved in the store, or rejects if the// identityKey differs from a previously seen identity for this address.var promise = sessionBuilder;promise;promise;
Once you have a session established with an address, you can encrypt messages using SessionCipher.
var plaintext = "Hello world";var sessionCipher = store address;sessionCipher;
Ciphertexts come in two flavors: WhisperMessage and PreKeyWhisperMessage.
var address = recipientId deviceId;var sessionCipher = store address;// Decrypt a PreKeyWhisperMessage by first establishing a new session.// Returns a promise that resolves when the message is decrypted or// rejects if the identityKey differs from a previously seen identity for this// address.sessionCipher;// Decrypt a normal message using an existing sessionvar sessionCipher = store address;sessionCipher;
I (elsehow) release copyright to Copyright 2015-2016 Open Whisper Systems under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html