From 5c4de193c5e777f0a2697ce563cb033b3bb8ecf0 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff <1389908+richvdh@users.noreply.github.com> Date: Thu, 13 Jul 2023 13:41:23 +0100 Subject: [PATCH] Update README (#4) Put some stuff about usage in the "Usage" section --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2defbb1..f04dfa8 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,47 @@ Encryption](https://en.wikipedia.org/wiki/End-to-end_encryption)) for ## Usage +1. Install in your project: + + ``` + npm install --save @matrix-org/matrix-sdk-crypto-wasm + ``` + + or: + + ``` + yarn add @matrix-org/matrix-sdk-crypto-wasm + ``` + +2. Import the library into your project and initialise it. + + It is recommended that you use a dynamic import, particularly in a Web + environment, because the WASM artifiact is large: + + ```javascript + async function loadCrypto(userId, deviceId) { + const matrixSdkCrypto = await import("@matrix-org/matrix-sdk-crypto-wasm"); + await matrixSdkCrypto.initAsync(); + + // Optional: enable tracing in the rust-sdk + new matrixSdkCrypto.Tracing(matrixSdkCrypto.LoggerLevel.Trace).turnOn(); + + // Create a new OlmMachine + // + // The following will use an in-memory store. It is recommended to use + // indexedDB where that is available. + // See https://matrix-org.github.io/matrix-rust-sdk-crypto-wasm/classes/OlmMachine.html#initialize + const olmMachine = await RustSdkCryptoJs.OlmMachine.initialize( + new RustSdkCryptoJs.UserId(userId), + new RustSdkCryptoJs.DeviceId(deviceId), + ); + + return olmMachine; + } + ``` + +## Building + These WebAssembly bindings are written in [Rust]. To build them, you need to install the Rust compiler, see [the Install Rust Page](https://www.rust-lang.org/tools/install). Then, the workflow is @@ -25,15 +66,11 @@ following commands: ```sh $ yarn install -$ yarn build +$ yarn build # or 'yarn build:dev' to make an unoptimised build $ yarn test ``` -A `matrix_sdk_crypto.js`, `matrix_sdk_crypto.d.ts` and a -`matrix_sdk_crypto_bg.wasm` files should be generated in the `pkg/` -directory. - -TBD +The compiled output should be generated in the `pkg/` directory. ## Documentation