Skip to content

Commit

Permalink
Update README (#4)
Browse files Browse the repository at this point in the history
Put some stuff about usage in the "Usage" section
  • Loading branch information
richvdh authored Jul 13, 2023
1 parent 70c3132 commit 5c4de19
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 5c4de19

Please sign in to comment.