olm/javascript
Hubert Chathi 7e0c827703 release 3.2.16 2023-11-23 12:38:51 -05:00
..
demo Fix group demo to work with > 2 users 2020-07-04 16:59:26 -04:00
test switch to jasmine (instead of jasmine-node) for JavaScript tests 2021-12-22 13:51:47 -05:00
.gitignore also ignore the non-wasm JS file 2018-10-16 16:11:22 -04:00
.gitlab-ci.yml ci: add initial build pipeline 2021-05-10 20:40:42 +00:00
README.md add note about telling olm how to find wasm file 2021-11-11 14:05:07 -05:00
externs.js Another day, another interface 2018-09-25 17:13:29 +01:00
index.d.ts Correct `message_index` type in return signature of `InboundGroupSession::decrypt` 2023-03-29 08:33:55 +00:00
olm_inbound_group_session.js fix compatibility with newer versions of emscripten 2022-10-06 13:14:38 -04:00
olm_outbound_group_session.js fix compatibility with newer versions of emscripten 2022-10-06 13:14:38 -04:00
olm_pk.js fix compatibility with newer versions of emscripten 2022-10-06 13:14:38 -04:00
olm_post.js fix compatibility with newer versions of emscripten 2022-10-06 13:14:38 -04:00
olm_pre.js remove workaround for closure compiler that is now causing problems 2023-03-17 17:50:10 -04:00
olm_prefix.js.in Add LibreJS license tag 2021-03-31 16:11:41 -04:00
olm_sas.js fix compatibility with newer versions of emscripten 2022-10-06 13:14:38 -04:00
olm_suffix.js Add LibreJS license tag 2021-03-31 16:11:41 -04:00
package-lock.json use npmlock2nix to provide node_modules 2022-05-11 13:59:33 -04:00
package.json release 3.2.16 2023-11-23 12:38:51 -05:00

README.md

Olm

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

If you get errors about failure to compile the wasm file, it is likely that Olm is not locating the wasm file properly. You can tell Olm where the wasm file is by passing a locateFile parameter to Olm.init(), for example: Olm.init({locateFile: () => pathToWasmFile}).

Example:

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

var bobs_id_keys = JSON.parse(bob.identity_keys());
var bobs_id_key = bobs_id_keys.curve25519;
var bobs_ot_keys = JSON.parse(bob.one_time_keys());
for (key in bobs_ot_keys.curve25519) {
    var bobs_ot_key = bobs_ot_keys.curve25519[key];
}

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

bob_session.create_inbound(bob, bob_message);
var plaintext = bob_session.decrypt(message_1.type, bob_message);
bob.remove_one_time_keys(bob_session);

Group chat:

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

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

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

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