Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NPM example in documentation does not work #91

Open
raxod502 opened this issue Jul 23, 2024 · 1 comment
Open

NPM example in documentation does not work #91

raxod502 opened this issue Jul 23, 2024 · 1 comment

Comments

@raxod502
Copy link

The following example code is given at https://www.npmjs.com/package/@matrix-org/olm:

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);

This refers to a nonexistent group_session variable, but I assume that is a typo and outbound_session is meant instead. However, executing those commands produces an error:

> Olm = require('@matrix-org/olm'); await Olm.init()
undefined
> var outbound_session = new Olm.OutboundGroupSession();
undefined
> outbound_session.create();
undefined
> var session_id = outbound_session.session_id();
undefined
> var session_key = outbound_session.session_key();
undefined
> var message_index = outbound_session.message_index();
undefined
> var inbound_session = new Olm.InboundGroupSession();
undefined
> inbound_session.create(message_index, session_key);
/home/raxod502/files/temp/matrix/node_modules/@matrix-org/olm/olm.js:19
if(ia)m=l?require("path").dirname(m)+"/":__dirname+"/",na=()=>{ma||(fs=require("fs"),ma=require("path"))},ja=function(b,c){na();b=ma.normalize(b);return fs.readFileSync(b,c?void 0:"utf8")},la=b=>{b=ja(b,!0);b.buffer||(b=new Uint8Array(b));return b},ka=(b,c,d)=>{na();b=ma.normalize(b);fs.readFile(b,function(e,f){e?d(e):c(f.buffer)})},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),process.on("uncaughtException",function(b){throw b;}),process.on("unhandledRejection",
                                                                                                                                                                                                                                                                                                                                                                                                                                                                          ^

Error: OLM.BAD_SESSION_KEY
    at /home/raxod502/files/temp/matrix/node_modules/@matrix-org/olm/olm.js:78:251
    at O.<anonymous> (/home/raxod502/files/temp/matrix/node_modules/@matrix-org/olm/olm.js:80:92)
    at O.create (/home/raxod502/files/temp/matrix/node_modules/@matrix-org/olm/olm.js:96:290)

Node.js v20.15.1

What am I missing? This is matrix-olm installed from npm as linked above, release version 3.2.15.

@raxod502
Copy link
Author

Apparently the message_index argument doesn't exist...? Code here: https://gitlab.matrix.org/matrix-org/olm/-/blob/66294cf7f66ae380683dbb7f43a16a8922249fc8/javascript/olm_inbound_group_session.js#L66

If I omit that argument then it works... can the documentation be updated to be correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant