You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-06 12:02:40 +03:00
Clean up typescript types related to rust crypto (#4706)
* Simplify bootstrapSecretStorage logic might as well just export the keys immediately, rather than having multiple tests. * Clean up typescript types related to rust crypto A forthcoming release of matrix-rust-sdk-crypto-wasm tightens up a number of typescript types. In preparation, we need to get our house in order too.
This commit is contained in:
committed by
GitHub
parent
33648a711c
commit
554804cd10
@@ -104,10 +104,10 @@ export class CrossSigningIdentity {
|
||||
}
|
||||
|
||||
// Get the current device
|
||||
const device: RustSdkCryptoJs.Device = await this.olmMachine.getDevice(
|
||||
const device: RustSdkCryptoJs.Device = (await this.olmMachine.getDevice(
|
||||
this.olmMachine.userId,
|
||||
this.olmMachine.deviceId,
|
||||
);
|
||||
))!;
|
||||
try {
|
||||
// Sign the device with our cross-signing key and upload the signature
|
||||
const request: RustSdkCryptoJs.SignatureUploadRequest = await device.verify();
|
||||
@@ -172,7 +172,8 @@ export class CrossSigningIdentity {
|
||||
* (If secret storage is *not* configured, we assume that the export will happen when it is set up)
|
||||
*/
|
||||
private async exportCrossSigningKeysToStorage(): Promise<void> {
|
||||
const exported: RustSdkCryptoJs.CrossSigningKeyExport | null = await this.olmMachine.exportCrossSigningKeys();
|
||||
const exported: RustSdkCryptoJs.CrossSigningKeyExport | undefined =
|
||||
await this.olmMachine.exportCrossSigningKeys();
|
||||
/* istanbul ignore else (this function is only called when we know the olm machine has keys) */
|
||||
if (exported?.masterKey) {
|
||||
await this.secretStorage.store("m.cross_signing.master", exported.masterKey);
|
||||
|
@@ -386,7 +386,7 @@ export class RustBackupManager extends TypedEventEmitter<RustBackupCryptoEvents,
|
||||
|
||||
while (!this.stopped) {
|
||||
// Get a batch of room keys to upload
|
||||
let request: RustSdkCryptoJs.KeysBackupRequest | null = null;
|
||||
let request: RustSdkCryptoJs.KeysBackupRequest | undefined = undefined;
|
||||
try {
|
||||
request = await logDuration(
|
||||
logger,
|
||||
|
@@ -783,9 +783,13 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
|
||||
await this.addSecretStorageKeyToSecretStorage(recoveryKey);
|
||||
}
|
||||
|
||||
const crossSigningStatus: RustSdkCryptoJs.CrossSigningStatus = await this.olmMachine.crossSigningStatus();
|
||||
const crossSigningPrivateKeys: RustSdkCryptoJs.CrossSigningKeyExport | undefined =
|
||||
await this.olmMachine.exportCrossSigningKeys();
|
||||
const hasPrivateKeys =
|
||||
crossSigningStatus.hasMaster && crossSigningStatus.hasSelfSigning && crossSigningStatus.hasUserSigning;
|
||||
crossSigningPrivateKeys &&
|
||||
crossSigningPrivateKeys.masterKey !== undefined &&
|
||||
crossSigningPrivateKeys.self_signing_key !== undefined &&
|
||||
crossSigningPrivateKeys.userSigningKey !== undefined;
|
||||
|
||||
// If we have cross-signing private keys cached, store them in secret
|
||||
// storage if they are not there already.
|
||||
@@ -795,21 +799,6 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
|
||||
) {
|
||||
this.logger.info("bootstrapSecretStorage: cross-signing keys not yet exported; doing so now.");
|
||||
|
||||
const crossSigningPrivateKeys: RustSdkCryptoJs.CrossSigningKeyExport =
|
||||
await this.olmMachine.exportCrossSigningKeys();
|
||||
|
||||
if (!crossSigningPrivateKeys.masterKey) {
|
||||
throw new Error("missing master key in cross signing private keys");
|
||||
}
|
||||
|
||||
if (!crossSigningPrivateKeys.userSigningKey) {
|
||||
throw new Error("missing user signing key in cross signing private keys");
|
||||
}
|
||||
|
||||
if (!crossSigningPrivateKeys.self_signing_key) {
|
||||
throw new Error("missing self signing key in cross signing private keys");
|
||||
}
|
||||
|
||||
await this.secretStorage.store("m.cross_signing.master", crossSigningPrivateKeys.masterKey);
|
||||
await this.secretStorage.store("m.cross_signing.user_signing", crossSigningPrivateKeys.userSigningKey);
|
||||
await this.secretStorage.store("m.cross_signing.self_signing", crossSigningPrivateKeys.self_signing_key);
|
||||
@@ -1819,7 +1808,7 @@ export class RustCrypto extends TypedEventEmitter<RustCryptoEvents, CryptoEventH
|
||||
* @param name - The name of the secret received.
|
||||
*/
|
||||
public async checkSecrets(name: string): Promise<void> {
|
||||
const pendingValues: string[] = await this.olmMachine.getSecretsFromInbox(name);
|
||||
const pendingValues: Set<string> = await this.olmMachine.getSecretsFromInbox(name);
|
||||
for (const value of pendingValues) {
|
||||
if (await this.handleSecretReceived(name, value)) {
|
||||
// If we have a valid secret for that name there is no point of processing the other secrets values.
|
||||
|
Reference in New Issue
Block a user