Skip to content

Commit ca598bc

Browse files
committed
Update SecretStorage doc
1 parent 03cdaba commit ca598bc

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,8 @@ To obtain a reference, call [`MatrixClient.getCrypto`](https://matrix-org.github
331331

332332
### Secret storage
333333

334-
If your [secret storage](https://spec.matrix.org/v1.12/client-server-api/#secret-storage) is not set up, you need to bootstrap it before using the `CryptoApi`:
334+
You should set up the [secret storage](https://spec.matrix.org/v1.12/client-server-api/#secret-storage) before using the end-to-end encryption. To do this, you need to call [`CryptoApi.bootstrapSecretStorage`](https://matrix-org.github.io/matrix-js-sdk/interfaces/crypto_api.CryptoApi.html#bootstrapSecretStorage).
335+
`CryptoApi.bootstrapSecretStorage` can be called unconditionally, but it will only set up the secret storage if it is not already set up (unless you use the `setupNewSecretStorage` parameter).
335336

336337
```javascript
337338
const matrixClient = sdk.createClient({
@@ -350,26 +351,31 @@ matrixClient.getCrypto().bootstrapSecretStorage({
350351
// If `setupNewSecretStorage` is `true`, you need to fill `createSecretStorageKey`
351352
setupNewSecretStorage: true,
352353
// This function will be called if a new secret storage key (aka recovery key) is needed.
353-
// You should remember the key you return here, because you will need it to unlock the secret storage.
354+
// You should prompt the user to save the keu somewhere, because you will need it to unlock the secret storage.
354355
createSecretStorageKey: async () => {
355356
return mySecretStorageKey;
356357
},
357358
});
358359
```
359360

360361
In the example above, we are setting up a new secret storage. The secret storage data will be encrypted using the secret storage key returned in `createSecretStorageKey`.
361-
You should remember this key because when access to the secret storage is needed, the crypto moduel is expecting the `getSecretStorageKey` to return this key.
362-
363-
- [CryptoCallbacks#getSecretStorageKey](https://matrix-org.github.io/matrix-js-sdk/interfaces/crypto_api.CryptoCallbacks.html#getSecretStorageKey)
364-
- [CryptoApi#bootstrapSecretStorage](https://matrix-org.github.io/matrix-js-sdk/interfaces/crypto_api.CryptoApi.html#bootstrapSecretStorage)
362+
We recommend that you prompt the user to re-enter this key when [`CryptoCallbacks.getSecretStorageKey`](https://matrix-org.github.io/matrix-js-sdk/interfaces/crypto_api.CryptoCallbacks.html#getSecretStorageKey) is called (when the secret storage access is needed).
365363

366364
Also, if you don't have a [key backup](https://spec.matrix.org/v1.12/client-server-api/#server-side-key-backups) you should create one:
367365

368366
```javascript
367+
// Check if we have a key backup.
368+
// checkKeyBackupAndEnable returns null, there is no key backup.
369+
const hasKeyBackup = await matrixClient.getCrypto().checkKeyBackupAndEnable() !== null
370+
371+
// First option when setting up the secret storage
369372
matrixClient.getCrypto().bootstrapSecretStorage({
370373
...,
371-
setupNewKeyBackup: true,
374+
setupNewKeyBackup: !hasKeyBackup,
372375
});
376+
377+
// Second option
378+
matrixClient.getCrypto().resetKeyBackup();
373379
```
374380

375381
Once the key backup and the secret storage are set up, you don't need to set them up again for all your devices.
@@ -389,7 +395,6 @@ matrixClient.getCrypto().bootstrapCrossSigning({
389395
The [`authUploadDeviceSigningKeys`](https://matrix-org.github.io/matrix-js-sdk/interfaces/crypto_api.BootstrapCrossSigningOpts.html#authUploadDeviceSigningKeys) callback
390396
is required in order to upload newly-generated public cross-signing keys to the server.
391397

392-
393398
### Verify a new device
394399

395400
Once the cross-signing is set up on one of your devices, you can verify another device with two methods:

0 commit comments

Comments
 (0)