Skip to content

Implementation of the Double Ratchet protocol in TypeScript based on libsodium.

License

Notifications You must be signed in to change notification settings

TICESoftware/double-ratchet.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

double-ratchet.js

Implementation of the Double Ratchet protocol in TypeScript. The cryptographic operations are provided by libsodium entirely.

Installation

$ yarn add double-ratchet-ts
or
$ npm i --save double-ratchet-ts

Usage

Alice and Bob calculate a shared secret using a secure channel. After that one party can start the conversation as soon as she gets to know the public key of the other one.

import {DoubleRatchet} from "double-ratchet-ts";

const sharedSecret = new Uint8Array(32).fill(1);
const info = "DoubleRatchetExample";

const bob = await DoubleRatchet.init(info, 20, 20, sharedSecret, undefined, undefined);

// Bob sends his public key to Alice using another channel
// sendToAlice(bob.publicKey())

const alice = await DoubleRatchet.init(info, 20, 20, sharedSecret, bob.publicKey(), undefined);

// Now the conversation begins
const message = Uint8Array.from(Array.from("Hello, Bob!").map(letter => letter.charCodeAt(0)));

const encryptedMessage = await alice.encrypt(message);
const decryptedMessage = await bob.decrypt(encryptedMessage);

console.log(String.fromCharCode(...decryptedMessage)); // Hello, Bob!

License

This library is licensed under MIT license.

About

Implementation of the Double Ratchet protocol in TypeScript based on libsodium.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published