You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-23 17:02:25 +03:00
* Apply more strict typescript around the codebase * Fix tests * Revert strict mode commit * Iterate strict * Iterate * Iterate strict * Iterate * Fix tests * Iterate * Iterate strict * Add tests * Iterate * Iterate * Fix tests * Fix tests * Strict types be strict * Fix types * detectOpenHandles * Strict * Fix client not stopping * Add sync peeking tests * Make test happier * More strict * Iterate * Stabilise * Moar strictness * Improve coverage * Fix types * Fix types * Improve types further * Fix types * Improve typing of NamespacedValue * Fix types
46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
import { IRecoveryKey } from '../../../src/crypto/api';
|
|
import { CrossSigningLevel } from '../../../src/crypto/CrossSigning';
|
|
import { IndexedDBCryptoStore } from '../../../src/crypto/store/indexeddb-crypto-store';
|
|
|
|
// needs to be phased out and replaced with bootstrapSecretStorage,
|
|
// but that is doing too much extra stuff for it to be an easy transition.
|
|
export async function resetCrossSigningKeys(
|
|
client,
|
|
{ level }: { level?: CrossSigningLevel} = {},
|
|
): Promise<void> {
|
|
const crypto = client.crypto;
|
|
|
|
const oldKeys = Object.assign({}, crypto.crossSigningInfo.keys);
|
|
try {
|
|
await crypto.crossSigningInfo.resetKeys(level);
|
|
await crypto.signObject(crypto.crossSigningInfo.keys.master);
|
|
// write a copy locally so we know these are trusted keys
|
|
await crypto.cryptoStore.doTxn(
|
|
'readwrite', [IndexedDBCryptoStore.STORE_ACCOUNT],
|
|
(txn) => {
|
|
crypto.cryptoStore.storeCrossSigningKeys(
|
|
txn, crypto.crossSigningInfo.keys);
|
|
},
|
|
);
|
|
} catch (e) {
|
|
// If anything failed here, revert the keys so we know to try again from the start
|
|
// next time.
|
|
crypto.crossSigningInfo.keys = oldKeys;
|
|
throw e;
|
|
}
|
|
crypto.emit("crossSigning.keysChanged", {});
|
|
await crypto.afterCrossSigningLocalKeyChange();
|
|
}
|
|
|
|
export async function createSecretStorageKey(): Promise<IRecoveryKey> {
|
|
const decryption = new global.Olm.PkDecryption();
|
|
const storagePublicKey = decryption.generate_key();
|
|
const storagePrivateKey = decryption.get_private_key();
|
|
decryption.free();
|
|
return {
|
|
// `pubkey` not used anymore with symmetric 4S
|
|
keyInfo: { pubkey: storagePublicKey, key: undefined! },
|
|
privateKey: storagePrivateKey,
|
|
};
|
|
}
|