matrix-js-sdk icon indicating copy to clipboard operation
matrix-js-sdk copied to clipboard

Feat: Add NodeJS E2EE TS example.

Open saul-jb opened this issue 1 year ago • 5 comments

This PR adds a NodeJS TypeScript example with E2EE enabled to the examples, this should help people figure out how to use the E2EE in a NodeJS environment.

E2EE is one of the primary reasons to use Matrix and the docs/examples are really scarce on how to handle it properly, this example is up to date and should really help with that.

Related issues:

  • #2205
  • #1726
  • #437

This PR currently has none of the required changelog labels.

A reviewer can add one of: T-Deprecation, T-Enhancement, T-Defect, T-Task to indicate what type of change this is, or add Type: [enhancement/defect/task] to the description and I'll add them for you.

saul-jb avatar May 09 '23 04:05 saul-jb

Hmm, at first glance this feels extremely complex for an example.

I don't feel this example is too complicated, a little complex maybe but this allows me to segregate parts of the code that people want to look at without having to sift through the rest that they are not interested in like in node example.

Here we have matrix-importer.ts which handles the setup for importing the Matrix SDK correctly and matrix.ts which holds the methods for doing various actions through Matrix. The rest is mostly logic to turn it into a working example.

I could also use some help understanding how this works.

I have updated the README to hopefully increase the clarity on how it is setup and what it is doing.

saul-jb avatar May 10 '23 00:05 saul-jb

Thanks a lot @saul-jb, this was exactly what I was looking for ❤️ All the other (few) examples concerning e2ee on node are outdated, difficult to find, and not working.

Imho this example/little app should be merged in master ASAP.

FYI Tested, working, with:

ironoa avatar Jun 13 '23 17:06 ironoa

@saul-jb could you provide more details here ?

Adding this section

import sqlite3 from "sqlite3";
import indexeddbjs from "indexeddb-js";

const engine = new sqlite3.Database("./sqlite");
const { indexedDB } = indexeddbjs.makeScope("sqlite3", engine);

to the createClient of the startWithToken function doesn't work smoothly, it gives back and error such as

if (e.name === "VersionError") {
            ^
TypeError: Cannot read properties of null (reading 'name')

Also: if we want to have the crypto Store persisted, do we still need to login via username and password (getTokenLogin) ?

ironoa avatar Jun 13 '23 23:06 ironoa

All the other (few) examples concerning e2ee on node are outdated, difficult to find, and not working.

Yeah, Matrix is pretty cool overall but it is a nightmare to figure out how to use this library due to lack of working examples and documentation. I think a few up to date examples would go a long way to increasing adoption.

Adding this section to the createClient of the startWithToken function doesn't work smoothly, it gives back and error such as

Yeah, that seems to have problems and the only way I have found to persist storage is using node-localstorage. I have updated the example to use this by default now.

Also: if we want to have the crypto Store persisted, do we still need to login via username and password (getTokenLogin) ?

No, since we can persist an access token and device we can skip straight to the token login - the example has be updated to do this too.

saul-jb avatar Jun 14 '23 00:06 saul-jb

Well done, it works perfectly with node-localstorage, just tested. Many thanks again.
When and if you have time, the last thing that is missing to have an optimal solution is the verification, so we can get rid of that warning image

Yeah, Matrix is pretty cool overall but it is a nightmare to figure out how to use this library due to lack of working examples and documentation. I think a few up to date examples would go a long way to increasing adoption.

Yeah, I agree, it was a nightmare, until I managed to find this issue.

ironoa avatar Jun 14 '23 07:06 ironoa