mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2025-01-09 19:56:44 +01:00
WIP
This commit is contained in:
parent
a925ec622a
commit
25aac4b7c0
@ -89,6 +89,7 @@ export class Session {
|
|||||||
this._megolmDecryption = null;
|
this._megolmDecryption = null;
|
||||||
this._getSyncToken = () => this.syncToken;
|
this._getSyncToken = () => this.syncToken;
|
||||||
this._olmWorker = olmWorker;
|
this._olmWorker = olmWorker;
|
||||||
|
this._secretStorage = undefined;
|
||||||
this._keyBackup = new ObservableValue(undefined);
|
this._keyBackup = new ObservableValue(undefined);
|
||||||
this._crossSigning = new ObservableValue(undefined);
|
this._crossSigning = new ObservableValue(undefined);
|
||||||
this._observedRoomStatus = new Map();
|
this._observedRoomStatus = new Map();
|
||||||
@ -332,13 +333,14 @@ export class Session {
|
|||||||
const isValid = await secretStorage.hasValidKeyForAnyAccountData();
|
const isValid = await secretStorage.hasValidKeyForAnyAccountData();
|
||||||
log.set("isValid", isValid);
|
log.set("isValid", isValid);
|
||||||
if (isValid) {
|
if (isValid) {
|
||||||
await this._loadSecretStorageServices(secretStorage, log);
|
this._secretStorage = secretStorage;
|
||||||
|
await this._loadSecretStorageService(log);
|
||||||
}
|
}
|
||||||
return isValid;
|
return isValid;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async _loadSecretStorageServices(secretStorage, log) {
|
async _loadSecretStorageServices(log) {
|
||||||
try {
|
try {
|
||||||
await log.wrap("enable key backup", async log => {
|
await log.wrap("enable key backup", async log => {
|
||||||
const keyBackup = new KeyBackup(
|
const keyBackup = new KeyBackup(
|
||||||
@ -348,7 +350,7 @@ export class Session {
|
|||||||
this._storage,
|
this._storage,
|
||||||
this._platform,
|
this._platform,
|
||||||
);
|
);
|
||||||
if (await keyBackup.load(secretStorage, log)) {
|
if (await keyBackup.load(this._secretStorage, log)) {
|
||||||
for (const room of this._rooms.values()) {
|
for (const room of this._rooms.values()) {
|
||||||
if (room.isEncrypted) {
|
if (room.isEncrypted) {
|
||||||
room.enableKeyBackup(keyBackup);
|
room.enableKeyBackup(keyBackup);
|
||||||
@ -364,7 +366,7 @@ export class Session {
|
|||||||
await log.wrap("enable cross-signing", async log => {
|
await log.wrap("enable cross-signing", async log => {
|
||||||
const crossSigning = new CrossSigning({
|
const crossSigning = new CrossSigning({
|
||||||
storage: this._storage,
|
storage: this._storage,
|
||||||
secretStorage,
|
secretStorage: this._secretStorage,
|
||||||
platform: this._platform,
|
platform: this._platform,
|
||||||
olm: this._olm,
|
olm: this._olm,
|
||||||
olmUtil: this._olmUtil,
|
olmUtil: this._olmUtil,
|
||||||
@ -775,12 +777,13 @@ export class Session {
|
|||||||
txn.accountData.set(event);
|
txn.accountData.set(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
changes.accountData = accountData.events;
|
||||||
}
|
}
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
afterSync({syncInfo, e2eeAccountChanges}) {
|
afterSync({syncInfo, e2eeAccountChanges, accountData}) {
|
||||||
if (syncInfo) {
|
if (syncInfo) {
|
||||||
// sync transaction succeeded, modify object state now
|
// sync transaction succeeded, modify object state now
|
||||||
this._syncInfo = syncInfo;
|
this._syncInfo = syncInfo;
|
||||||
@ -788,6 +791,9 @@ export class Session {
|
|||||||
if (this._e2eeAccount) {
|
if (this._e2eeAccount) {
|
||||||
this._e2eeAccount.afterSync(e2eeAccountChanges);
|
this._e2eeAccount.afterSync(e2eeAccountChanges);
|
||||||
}
|
}
|
||||||
|
if (accountData && this._secretStorage) {
|
||||||
|
this._secretStorage.afterSync(accountData);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
|
@ -41,6 +41,7 @@ export class SecretStorage {
|
|||||||
private readonly _key: Key;
|
private readonly _key: Key;
|
||||||
private readonly _platform: Platform;
|
private readonly _platform: Platform;
|
||||||
private readonly _storage: Storage;
|
private readonly _storage: Storage;
|
||||||
|
private observedSecrets
|
||||||
|
|
||||||
constructor({key, platform, storage}: {key: Key, platform: Platform, storage: Storage}) {
|
constructor({key, platform, storage}: {key: Key, platform: Platform, storage: Storage}) {
|
||||||
this._key = key;
|
this._key = key;
|
||||||
@ -48,6 +49,12 @@ export class SecretStorage {
|
|||||||
this._storage = storage;
|
this._storage = storage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
afterSync(accountData: ReadonlyArray<{type: string, content: Record<string, any>}>): void {
|
||||||
|
for(const event of accountData) {
|
||||||
|
if (type === )
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** this method will auto-commit any indexeddb transaction because of its use of the webcrypto api */
|
/** this method will auto-commit any indexeddb transaction because of its use of the webcrypto api */
|
||||||
async hasValidKeyForAnyAccountData() {
|
async hasValidKeyForAnyAccountData() {
|
||||||
const txn = await this._storage.readTxn([
|
const txn = await this._storage.readTxn([
|
||||||
@ -69,6 +76,10 @@ export class SecretStorage {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
observeSecret(name: string): BaseObservableValue<string | undefined> {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/** this method will auto-commit any indexeddb transaction because of its use of the webcrypto api */
|
/** this method will auto-commit any indexeddb transaction because of its use of the webcrypto api */
|
||||||
async readSecret(name: string): Promise<string | undefined> {
|
async readSecret(name: string): Promise<string | undefined> {
|
||||||
const txn = await this._storage.readTxn([
|
const txn = await this._storage.readTxn([
|
||||||
|
Loading…
x
Reference in New Issue
Block a user