From 571fd241aad5921983318f2908d30e599b546a4c Mon Sep 17 00:00:00 2001 From: Matthew Aaron Raymer Date: Mon, 12 Dec 2022 18:35:20 +0800 Subject: [PATCH] Added Dixie class and cryptography. Need to figure out generating password, storing, and boot sequence. --- package-lock.json | 48 ++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + src/libs/db/index.ts | 27 +++++++++++++++++++++++++ 3 files changed, 76 insertions(+) create mode 100644 src/libs/db/index.ts diff --git a/package-lock.json b/package-lock.json index aa14655f..d4c010e3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,6 +12,7 @@ "@fortawesome/fontawesome-svg-core": "^6.2.1", "@fortawesome/free-solid-svg-icons": "^6.2.1", "@fortawesome/vue-fontawesome": "^3.0.2", + "@pvermeer/dexie-encrypted-addon": "^2.0.2", "@veramo/core": "^4.1.1", "@veramo/credential-w3c": "^4.1.1", "@veramo/data-store": "^4.1.1", @@ -5641,6 +5642,38 @@ "integrity": "sha512-a5Sab1C4/icpTZVzZc5Ghpz88yQtGOyNqYXcZgOssB2uuAr+wF/MvN6bgtW32q7HHrvBki+BsZ0OuNv6EV3K9g==", "dev": true }, + "node_modules/@pvermeer/dexie-encrypted-addon": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/@pvermeer/dexie-encrypted-addon/-/dexie-encrypted-addon-2.0.2.tgz", + "integrity": "sha512-yy9BPE5NUcovHAIoDMP/m1OFl84VU5TYtnxqb6IRw4G3HliDPu5Qba4T+Z43FlUVnHtYOu3GBEw3gskm90TKzQ==", + "dependencies": { + "@pvermeer/dexie-immutable-addon": "^1.1.1", + "@stablelib/base64": "^1.0.1", + "@stablelib/utf8": "^1.0.1", + "tslib": "^2.3.1", + "tweetnacl": "^1.0.3" + }, + "peerDependencies": { + "dexie": "^3.0.3" + } + }, + "node_modules/@pvermeer/dexie-encrypted-addon/node_modules/@stablelib/utf8": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stablelib/utf8/-/utf8-1.0.1.tgz", + "integrity": "sha512-FrYD1xadah/TtAP6VJ04lDD5h9rdDj/d8wH/jMYTtHqZBv9z2btdvEU8vTxdjdkFmo1b/BH+t3R1wi/mYhCCNg==" + }, + "node_modules/@pvermeer/dexie-immutable-addon": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@pvermeer/dexie-immutable-addon/-/dexie-immutable-addon-1.1.1.tgz", + "integrity": "sha512-lwNsR/43ol2HdLiehX2sWYxZTea0LAbqZdURFv653osQ2e/7hC7kuyTYU86CboSyJYgLuk1yOpoerTWr2spWcA==", + "dependencies": { + "lodash.clonedeep": "^4.5.0", + "tslib": "^2.3.1" + }, + "peerDependencies": { + "dexie": "^3.0.3" + } + }, "node_modules/@react-native-community/cli": { "version": "9.3.2", "resolved": "https://registry.npmjs.org/@react-native-community/cli/-/cli-9.3.2.tgz", @@ -7050,6 +7083,11 @@ "@stablelib/wipe": "^1.0.1" } }, + "node_modules/@stablelib/base64": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/@stablelib/base64/-/base64-1.0.1.tgz", + "integrity": "sha512-1bnPQqSxSuc3Ii6MhBysoWCg58j97aUjuCSZrGSmDxNqtytIi0k8utUenAwTZN4V5mXXYGsVUI9zeBqy+jBOSQ==" + }, "node_modules/@stablelib/binary": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@stablelib/binary/-/binary-1.0.1.tgz", @@ -17492,6 +17530,11 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "devOptional": true }, + "node_modules/lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha512-H5ZhCF25riFd9uB5UCkVKo61m3S/xZk1x4wA6yp/L3RFP6Z/eHH1ymQcGLo7J3GMPfm0V/7m1tryHuGVxpqEBQ==" + }, "node_modules/lodash.debounce": { "version": "4.0.8", "resolved": "https://registry.npmmirror.com/lodash.debounce/-/lodash.debounce-4.0.8.tgz", @@ -24498,6 +24541,11 @@ "integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg==", "dev": true }, + "node_modules/tweetnacl": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", + "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==" + }, "node_modules/type-check": { "version": "0.4.0", "resolved": "https://registry.npmmirror.com/type-check/-/type-check-0.4.0.tgz", diff --git a/package.json b/package.json index 778a054c..9f8267be 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@fortawesome/fontawesome-svg-core": "^6.2.1", "@fortawesome/free-solid-svg-icons": "^6.2.1", "@fortawesome/vue-fontawesome": "^3.0.2", + "@pvermeer/dexie-encrypted-addon": "^2.0.2", "@veramo/core": "^4.1.1", "@veramo/credential-w3c": "^4.1.1", "@veramo/data-store": "^4.1.1", diff --git a/src/libs/db/index.ts b/src/libs/db/index.ts new file mode 100644 index 00000000..8638ac67 --- /dev/null +++ b/src/libs/db/index.ts @@ -0,0 +1,27 @@ +import Dexie, { Table } from "dexie"; +import { encrypted } from "@pvermeer/dexie-encrypted-addon"; + +export interface Account { + id?: number; + did: string; + kid: string; + kms: string; + meta: string; + privateKeyHex: string; + publicKeyHex: string; + type: string; +} + +export class AccountsDb extends Dexie { + accounts!: Table; + + constructor(secret?: string) { + super("KickStartDb"); + encrypted(this, { secretKey: secret }); + this.version(1).stores({ + accounts: "++id, privateKeyHex, publicKeyHex", // Primary key and indexed props + }); + } +} + +export const db = new AccountsDb();