Page MenuHomePhabricator

D6996.id23514.diff
No OneTemporary

D6996.id23514.diff

diff --git a/web/database/utils/constants.js b/web/database/utils/constants.js
--- a/web/database/utils/constants.js
+++ b/web/database/utils/constants.js
@@ -1,3 +1,4 @@
// @flow
export const SQLITE_CONTENT = 'sqliteFileContent';
+export const SQLITE_ENCRYPTION_KEY = 'encryptionKey';
diff --git a/web/database/worker/web-db-worker.js b/web/database/worker/web-db-worker.js
--- a/web/database/worker/web-db-worker.js
+++ b/web/database/worker/web-db-worker.js
@@ -13,7 +13,8 @@
workerResponseMessageTypes,
type WorkerRequestProxyMessage,
} from '../../types/worker-types.js';
-import { SQLITE_CONTENT } from '../utils/constants.js';
+import { SQLITE_CONTENT, SQLITE_ENCRYPTION_KEY } from '../utils/constants.js';
+import { generateCryptoKey } from '../utils/worker-crypto-utils.js';
const localforageConfig: PartialConfig = {
driver: localforage.INDEXEDDB,
@@ -59,6 +60,10 @@
} else if (message.type === workerRequestMessageTypes.INIT) {
await initDatabase();
return;
+ } else if (message.type === workerRequestMessageTypes.GENERATE_CRYPTO_KEY) {
+ const cryptoKey = await generateCryptoKey();
+ await localforage.setItem(SQLITE_ENCRYPTION_KEY, cryptoKey);
+ return;
}
throw new Error('Request type not supported');
diff --git a/web/types/worker-types.js b/web/types/worker-types.js
--- a/web/types/worker-types.js
+++ b/web/types/worker-types.js
@@ -4,6 +4,7 @@
export const workerRequestMessageTypes = Object.freeze({
PING: 0,
INIT: 1,
+ GENERATE_CRYPTO_KEY: 2,
});
export type PingWorkerRequestMessage = {
@@ -15,9 +16,14 @@
+type: 1,
};
+export type GenerateCryptoKeyRequestMessage = {
+ +type: 2,
+};
+
export type WorkerRequestMessage =
| PingWorkerRequestMessage
- | InitWorkerRequestMessage;
+ | InitWorkerRequestMessage
+ | GenerateCryptoKeyRequestMessage;
export type WorkerRequestProxyMessage = {
+id: number,

File Metadata

Mime Type
text/plain
Expires
Tue, Dec 3, 8:01 AM (21 h, 7 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2610942
Default Alt Text
D6996.id23514.diff (1 KB)

Event Timeline