Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow setting default secret storage key id to null #4615

Merged

Conversation

florianduros
Copy link
Contributor

@florianduros florianduros commented Jan 14, 2025

Checklist

  • Tests written for new code (and old code if feasible).
  • New or updated public/exported symbols have accurate TSDoc documentation.
  • Linter and other CI checks pass.
  • Sign-off given on the changes (see CONTRIBUTING.md).

Task element-hq/element-web#28977
The goal is to be able to remove the current recovery key.

The spec expects a string for the key however the rust sdk replaces the content of m.secret_storage.default_key with an empty object({}). We went with the same strategy to keep it consistent.

Also, the MatrixClient already authorises to set the account data with an empty object.

matrix-js-sdk/src/client.ts

Lines 4233 to 4244 in 07f97d7

/**
* Set account data event for the current user.
* It will retry the request up to 5 times.
* @param eventType - The event type
* @param content - the contents object for the event
* @returns Promise which resolves: an empty object
* @returns Rejects: with an error response.
*/
public setAccountData<K extends keyof AccountDataEvents>(
eventType: K,
content: AccountDataEvents[K] | Record<string, never>,
): Promise<{}> {

@florianduros florianduros force-pushed the florianduros/secret-storage-delete-default-key branch from a20b352 to 1091e68 Compare January 14, 2025 15:04
@florianduros florianduros changed the title defaultKeyId of the secret storage can be set at null Allow default key id of secret storage to be remove Jan 14, 2025
src/@types/event.ts Outdated Show resolved Hide resolved
@florianduros florianduros force-pushed the florianduros/secret-storage-delete-default-key branch 2 times, most recently from 6e70dd0 to 3f51d8e Compare January 14, 2025 15:22
@florianduros florianduros force-pushed the florianduros/secret-storage-delete-default-key branch from 3f51d8e to 9c5504a Compare January 14, 2025 15:26
@florianduros florianduros marked this pull request as ready for review January 14, 2025 15:30
@florianduros florianduros requested review from a team as code owners January 14, 2025 15:30
@florianduros florianduros changed the title Allow default key id of secret storage to be remove Allow default key id of secret storage to be null Jan 14, 2025
@richvdh richvdh changed the title Allow default key id of secret storage to be null Allow setting default secret storage key id to null Jan 14, 2025
src/secret-storage.ts Show resolved Hide resolved
src/secret-storage.ts Outdated Show resolved Hide resolved
src/secret-storage.ts Outdated Show resolved Hide resolved
// https://spec.matrix.org/v1.13/client-server-api/#key-storage
// To delete the default key, we send an empty object like the rust sdk does
// (see https://docs.rs/matrix-sdk/latest/matrix_sdk/encryption/recovery/struct.Recovery.html#method.reset_identity)
const newValue: Record<string, never> | { key: string } = keyId === null ? {} : { key: keyId };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a bit surprised the explicit type is needed here.

Copy link
Contributor Author

@florianduros florianduros Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inferred type doesn't work really well here:

const newValue: { key?: undefined } | { key: string }

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd likely work fine as const or inline in the setAccountData call

src/secret-storage.ts Outdated Show resolved Hide resolved
Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm otherwise

src/secret-storage.ts Outdated Show resolved Hide resolved
…be set at `null` in order to delete an exising recovery key
@florianduros florianduros added this pull request to the merge queue Jan 15, 2025
Merged via the queue into develop with commit 5babcaf Jan 15, 2025
30 checks passed
@florianduros florianduros deleted the florianduros/secret-storage-delete-default-key branch January 15, 2025 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants