Clean up some references to internal js-sdk classes (#12363)

* Fix references to `crypto-api/verification`

This is supposed to be an internal module; use the front door instead.

* `IRecoveryKey` -> `GeneratedSecretStorageKey`

`IRecoveryKey` is just a backwards-compatibility alias for
`GeneratedSecretStorageKey`

* `ISecretStorageKeyInfo` -> `SecretStorage.SecretStorageKeyDescription`

Again, same thing

* `IPassphraseInfo` -> `SecretStorage.PassphraseInfo`

* Remove unused import restriction exceptions
This commit is contained in:
Richard van der Hoff
2024-03-22 12:28:13 +00:00
committed by GitHub
parent 79f9a130fa
commit d36c1b39fd
15 changed files with 42 additions and 41 deletions

View File

@@ -14,8 +14,13 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
import { DeviceVerificationStatus, ICryptoCallbacks, MatrixClient, encodeBase64 } from "matrix-js-sdk/src/matrix";
import { ISecretStorageKeyInfo } from "matrix-js-sdk/src/crypto/api";
import {
DeviceVerificationStatus,
ICryptoCallbacks,
MatrixClient,
encodeBase64,
SecretStorage,
} from "matrix-js-sdk/src/matrix";
import { deriveKey } from "matrix-js-sdk/src/crypto/key_passphrase";
import { decodeRecoveryKey } from "matrix-js-sdk/src/crypto/recoverykey";
import { logger } from "matrix-js-sdk/src/logger";
@@ -38,14 +43,14 @@ import InteractiveAuthDialog from "./components/views/dialogs/InteractiveAuthDia
// single secret storage operation, as it will clear the cached keys once the
// operation ends.
let secretStorageKeys: Record<string, Uint8Array> = {};
let secretStorageKeyInfo: Record<string, ISecretStorageKeyInfo> = {};
let secretStorageKeyInfo: Record<string, SecretStorage.SecretStorageKeyDescription> = {};
let secretStorageBeingAccessed = false;
let nonInteractive = false;
let dehydrationCache: {
key?: Uint8Array;
keyInfo?: ISecretStorageKeyInfo;
keyInfo?: SecretStorage.SecretStorageKeyDescription;
} = {};
function isCachingAllowed(): boolean {
@@ -80,7 +85,9 @@ async function confirmToDismiss(): Promise<boolean> {
return !sure;
}
function makeInputToKey(keyInfo: ISecretStorageKeyInfo): (keyParams: KeyParams) => Promise<Uint8Array> {
function makeInputToKey(
keyInfo: SecretStorage.SecretStorageKeyDescription,
): (keyParams: KeyParams) => Promise<Uint8Array> {
return async ({ passphrase, recoveryKey }): Promise<Uint8Array> => {
if (passphrase) {
return deriveKey(passphrase, keyInfo.passphrase.salt, keyInfo.passphrase.iterations);
@@ -94,11 +101,11 @@ function makeInputToKey(keyInfo: ISecretStorageKeyInfo): (keyParams: KeyParams)
async function getSecretStorageKey({
keys: keyInfos,
}: {
keys: Record<string, ISecretStorageKeyInfo>;
keys: Record<string, SecretStorage.SecretStorageKeyDescription>;
}): Promise<[string, Uint8Array]> {
const cli = MatrixClientPeg.safeGet();
let keyId = await cli.getDefaultSecretStorageKeyId();
let keyInfo!: ISecretStorageKeyInfo;
let keyInfo!: SecretStorage.SecretStorageKeyDescription;
if (keyId) {
// use the default SSSS key if set
keyInfo = keyInfos[keyId];
@@ -177,7 +184,7 @@ async function getSecretStorageKey({
}
export async function getDehydrationKey(
keyInfo: ISecretStorageKeyInfo,
keyInfo: SecretStorage.SecretStorageKeyDescription,
checkFunc: (data: Uint8Array) => void,
): Promise<Uint8Array> {
const keyFromCustomisations = SecurityCustomisations.getSecretStorageKey?.();
@@ -226,7 +233,11 @@ export async function getDehydrationKey(
return key;
}
function cacheSecretStorageKey(keyId: string, keyInfo: ISecretStorageKeyInfo, key: Uint8Array): void {
function cacheSecretStorageKey(
keyId: string,
keyInfo: SecretStorage.SecretStorageKeyDescription,
key: Uint8Array,
): void {
if (isCachingAllowed()) {
secretStorageKeys[keyId] = key;
secretStorageKeyInfo[keyId] = keyInfo;