mirror of
https://github.com/vector-im/hydrogen-web.git
synced 2024-12-23 03:25:12 +01:00
Implement store for shared secret
This commit is contained in:
parent
c0928c75f8
commit
e6a9e39c7d
@ -34,7 +34,8 @@ export enum StoreNames {
|
|||||||
operations = "operations",
|
operations = "operations",
|
||||||
accountData = "accountData",
|
accountData = "accountData",
|
||||||
calls = "calls",
|
calls = "calls",
|
||||||
crossSigningKeys = "crossSigningKeys"
|
crossSigningKeys = "crossSigningKeys",
|
||||||
|
sharedSecrets = "sharedSecrets",
|
||||||
}
|
}
|
||||||
|
|
||||||
export const STORE_NAMES: Readonly<StoreNames[]> = Object.values(StoreNames);
|
export const STORE_NAMES: Readonly<StoreNames[]> = Object.values(StoreNames);
|
||||||
|
@ -38,6 +38,7 @@ import {GroupSessionDecryptionStore} from "./stores/GroupSessionDecryptionStore"
|
|||||||
import {OperationStore} from "./stores/OperationStore";
|
import {OperationStore} from "./stores/OperationStore";
|
||||||
import {AccountDataStore} from "./stores/AccountDataStore";
|
import {AccountDataStore} from "./stores/AccountDataStore";
|
||||||
import {CallStore} from "./stores/CallStore";
|
import {CallStore} from "./stores/CallStore";
|
||||||
|
import {SharedSecretStore} from "./stores/SharedSecretStore";
|
||||||
import type {ILogger, ILogItem} from "../../../logging/types";
|
import type {ILogger, ILogItem} from "../../../logging/types";
|
||||||
|
|
||||||
export type IDBKey = IDBValidKey | IDBKeyRange;
|
export type IDBKey = IDBValidKey | IDBKeyRange;
|
||||||
@ -178,6 +179,10 @@ export class Transaction {
|
|||||||
return this._store(StoreNames.calls, idbStore => new CallStore(idbStore));
|
return this._store(StoreNames.calls, idbStore => new CallStore(idbStore));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sharedSecrets(): SharedSecretStore {
|
||||||
|
return this._store(StoreNames.sharedSecrets, idbStore => new SharedSecretStore(idbStore));
|
||||||
|
}
|
||||||
|
|
||||||
async complete(log?: ILogItem): Promise<void> {
|
async complete(log?: ILogItem): Promise<void> {
|
||||||
try {
|
try {
|
||||||
await txnAsPromise(this._txn);
|
await txnAsPromise(this._txn);
|
||||||
|
@ -37,7 +37,8 @@ export const schema: MigrationFunc[] = [
|
|||||||
addInboundSessionBackupIndex,
|
addInboundSessionBackupIndex,
|
||||||
migrateBackupStatus,
|
migrateBackupStatus,
|
||||||
createCallStore,
|
createCallStore,
|
||||||
applyCrossSigningChanges
|
applyCrossSigningChanges,
|
||||||
|
createSharedSecretStore,
|
||||||
];
|
];
|
||||||
// TODO: how to deal with git merge conflicts of this array?
|
// TODO: how to deal with git merge conflicts of this array?
|
||||||
|
|
||||||
@ -299,3 +300,8 @@ async function applyCrossSigningChanges(db: IDBDatabase, txn: IDBTransaction, lo
|
|||||||
});
|
});
|
||||||
log.set("marked_outdated", counter);
|
log.set("marked_outdated", counter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//v19 create shared secrets store
|
||||||
|
function createSharedSecretStore(db: IDBDatabase) : void {
|
||||||
|
db.createObjectStore("sharedSecrets", {keyPath: "key"});
|
||||||
|
}
|
||||||
|
39
src/matrix/storage/idb/stores/SharedSecretStore.ts
Normal file
39
src/matrix/storage/idb/stores/SharedSecretStore.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
import {Store} from "../Store";
|
||||||
|
|
||||||
|
type SharedSecret = any;
|
||||||
|
|
||||||
|
export class SharedSecretStore {
|
||||||
|
private _store: Store<SharedSecret>;
|
||||||
|
|
||||||
|
constructor(store: Store<SharedSecret>) {
|
||||||
|
this._store = store;
|
||||||
|
}
|
||||||
|
|
||||||
|
get(name: string): Promise<SharedSecret | undefined> {
|
||||||
|
return this._store.get(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
set(name: string, secret: SharedSecret): void {
|
||||||
|
secret.key = name;
|
||||||
|
this._store.put(secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
remove(name: string): void {
|
||||||
|
this._store.delete(name);
|
||||||
|
}
|
||||||
|
}
|
@ -98,8 +98,12 @@ export class ToDeviceChannel extends Disposables implements IChannel {
|
|||||||
this.track(
|
this.track(
|
||||||
this.deviceMessageHandler.disposableOn(
|
this.deviceMessageHandler.disposableOn(
|
||||||
"message",
|
"message",
|
||||||
async ({ unencrypted }) =>
|
async ({ unencrypted }) => {
|
||||||
await this.handleDeviceMessage(unencrypted)
|
if (!unencrypted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await this.handleDeviceMessage(unencrypted);
|
||||||
|
}
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
this.track(() => {
|
this.track(() => {
|
||||||
|
Loading…
Reference in New Issue
Block a user