Skip to content

Commit 2d4a1d1

Browse files
committed
Review changes
1 parent 9c5504a commit 2d4a1d1

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/secret-storage.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ export interface ServerSideSecretStorage {
318318

319319
/**
320320
* Set the default key ID for encrypting secrets.
321+
*
321322
* If keyId is `null`, the default key id value in the account data will be set to an empty object.
322323
* This is considered as "disabling" the default key.
323324
*
@@ -367,19 +368,26 @@ export class ServerSideSecretStorageImpl implements ServerSideSecretStorage {
367368
public setDefaultKeyId(keyId: string | null): Promise<void> {
368369
return new Promise<void>((resolve, reject) => {
369370
const listener = (ev: MatrixEvent): void => {
371+
if (ev.getType() !== "m.secret_storage.default_key") {
372+
// Different account data item
373+
return;
374+
}
375+
370376
const content = ev.getContent();
377+
// If keyId === null, the content should be an empty object.
378+
// Otherwise, keyId should be returned in the content object.
371379
const isSameKey = keyId === null ? !Object.keys(content).length : content.key === keyId;
372-
if (ev.getType() === "m.secret_storage.default_key" && isSameKey) {
380+
if (isSameKey) {
373381
this.accountDataAdapter.removeListener(ClientEvent.AccountData, listener);
374382
resolve();
375383
}
376384
};
377385
this.accountDataAdapter.on(ClientEvent.AccountData, listener);
378386

379-
// The spec says that the key should be an object with a `key` property
380-
// https://spec.matrix.org/v1.13/client-server-api/#key-storage
381-
// To delete the default key, we send an empty object like the rust sdk does
382-
// (see https://docs.rs/matrix-sdk/latest/matrix_sdk/encryption/recovery/struct.Recovery.html#method.reset_identity)
387+
// The spec [1] says that the value of the account data entry should be an object with a `key` property.
388+
// It doesn't specify how to delete the default key; we do it by setting the account data to an empty object.
389+
//
390+
// [1]: https://spec.matrix.org/v1.13/client-server-api/#key-storage
383391
const newValue: Record<string, never> | { key: string } = keyId === null ? {} : { key: keyId };
384392
this.accountDataAdapter.setAccountData("m.secret_storage.default_key", newValue).catch((e) => {
385393
this.accountDataAdapter.removeListener(ClientEvent.AccountData, listener);

0 commit comments

Comments
 (0)