Socket
Book a DemoInstallSign in
Socket

@towns-protocol/olm

Package Overview
Dependencies
Maintainers
4
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@towns-protocol/olm

An implementation of the Double Ratchet cryptographic ratchet

3.2.28
latest
Source
npmnpm
Version published
Maintainers
4
Created
Source

@towns-protocol/olm

Note: before using any of the olm functions, you must call initAsync(), and wait for the promise to resolve, otherwise you will get errors like: Uncaught TypeError: Olm.Account is not a constructor

Example:

import Olm from "@towns-protocol/olm";
await Olm.initAsync();

const alice = new Olm.Account();
alice.create();

const bob = new Olm.Account();
bob.create();
bob.generate_one_time_keys(1);

const bobs_id_keys = JSON.parse(bob.identity_keys());
const bobs_id_key = bobs_id_keys.curve25519;

let bobs_ot_key;
for (const key in bobs_ot_keys.curve25519) {
  bobs_ot_key = bobs_ot_keys.curve25519[key];
}

const alice_session = new Olm.Session();
alice_session.create_outbound(alice, bobs_id_key, bobs_ot_key);
const alice_message = alice_session.encrypt("Hello");

const bob_session = new Olm.Session();
bob_session.create_inbound(bob, alice_message);
const plaintext = bob_session.decrypt(alice_message.type, alice_message);
bob.remove_one_time_keys(bob_session);

Group chat:

import Olm from "@towns-protocol/olm";
await Olm.initAsync();

const outbound_session = new Olm.OutboundGroupSession();
outbound_session.create();

// exchange these over a secure channel
const session_id = group_session.session_id();
const session_key = group_session.session_key();
const message_index = group_session.message_index();

const inbound_session = new Olm.InboundGroupSession();
inbound_session.create(message_index, session_key);

const ciphertext = outbound_session.encrypt("Hello");
const plaintext = inbound_session.decrypt(ciphertext);

Keywords

matrix-org

FAQs

Package last updated on 29 May 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.