From cfeabf05a4ce8c2ff74c5b6af5d0009e76721a5a Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 18 Mar 2023 17:04:14 -0600 Subject: [PATCH 1/6] refactor DB organization (prepping for more tables) --- README.md | 12 ++++++++++-- src/db/index.ts | 10 ++++++---- src/db/tables/accounts.ts | 19 ++++++++----------- src/libs/crypto/index.ts | 6 +++--- src/views/AccountViewView.vue | 31 +++++++++++++------------------ src/views/ImportAccountView.vue | 20 ++++++++------------ 6 files changed, 48 insertions(+), 50 deletions(-) diff --git a/README.md b/README.md index 31291bc..9b43e43 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ New users require registration. This can be done with a claim payload like this const vcClaim = { "@context": "https://schema.org", "@type": "RegisterAction", - agent: { did: identity0.did }, + agent: { identifier: identity0.did }, object: SERVICE_ID, - participant: { did: newIdentity.did }, + participant: { identifier: newIdentity.did }, }; ``` @@ -62,6 +62,14 @@ See [this page](openssl_signing_console.rst) See [Configuration Reference](https://cli.vuejs.org/config/). +## Dependencies + +See https://tea.xyz + +| Project | Version | +| ---------- | --------- | +| nodejs.org | ^16.0.0 | +| npmjs.com | ^8.0.0 | ## Other diff --git a/src/db/index.ts b/src/db/index.ts index be9d9f4..26dcee0 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,6 +1,6 @@ -import BaseDexie from "dexie"; +import BaseDexie, { Table } from "dexie"; import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon"; -import { accountsSchema, AccountsTable } from "./tables/accounts"; +import { Account, accountsSchema } from "./tables/accounts"; /** * In order to make the next line be acceptable, the program needs to have its linter suppress a rule: @@ -10,9 +10,11 @@ import { accountsSchema, AccountsTable } from "./tables/accounts"; * * https://9to5answer.com/how-to-bypass-warning-unexpected-any-specify-a-different-type-typescript-eslint-no-explicit-any */ -type DexieTables = AccountsTable; +type DexieTables = { + accounts: Table; +}; export type Dexie = BaseDexie & T; -export const db = new BaseDexie("kickStarter") as Dexie; +export const db = new BaseDexie("KickStart") as Dexie; const schema = Object.assign({}, accountsSchema); /** diff --git a/src/db/tables/accounts.ts b/src/db/tables/accounts.ts index 8ed1bd2..d4a4e61 100644 --- a/src/db/tables/accounts.ts +++ b/src/db/tables/accounts.ts @@ -1,18 +1,15 @@ -import { Table } from "dexie"; - export type Account = { - id?: number; - publicKey: string; - mnemonic: string; + id?: number; // auto-generated by Dexie + dateCreated: Date; + derivationPath: string; identity: string; - dateCreated: number; -}; - -export type AccountsTable = { - accounts: Table; + publicKeyHex: string; + mnemonic: string; }; // mark encrypted field by starting with a $ character +// see https://github.com/PVermeer/dexie-addon-suite-monorepo/tree/master/packages/dexie-encrypted-addon export const accountsSchema = { - accounts: "++id, publicKey, $mnemonic, $identity, dateCreated", + accounts: + "++id, dateCreated, derivationPath, $identity, $mnemonic, publicKeyHex", }; diff --git a/src/libs/crypto/index.ts b/src/libs/crypto/index.ts index a760295..bec075e 100644 --- a/src/libs/crypto/index.ts +++ b/src/libs/crypto/index.ts @@ -65,7 +65,7 @@ export const deriveAddress = ( * * @return {*} {string} */ -export const createIdentifier = (): string => { +export const generateSeed = (): string => { const entropy: Uint8Array = getRandomBytesSync(32); const mnemonic = entropyToMnemonic(entropy, wordlist); @@ -87,9 +87,9 @@ export const accessToken = async (identifier: IIdentifier) => { const nowEpoch = Math.floor(Date.now() / 1000); const endEpoch = nowEpoch + 60; // add one minute - const uportTokenPayload = { exp: endEpoch, iat: nowEpoch, iss: did }; + const tokenPayload = { exp: endEpoch, iat: nowEpoch, iss: did }; const alg = undefined; // defaults to 'ES256K', more standardized but harder to verify vs ES256K-R - const jwt: string = await didJwt.createJWT(uportTokenPayload, { + const jwt: string = await didJwt.createJWT(tokenPayload, { alg, issuer: did, signer, diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index 0bc56fa..098f35b 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -111,8 +111,8 @@
Derivation Path
{{ UPORT_ROOT_DERIVATION_PATH }} - @@ -174,10 +174,9 @@ diff --git a/src/views/ImportAccountView.vue b/src/views/ImportAccountView.vue index b2dfb5c..8738566 100644 --- a/src/views/ImportAccountView.vue +++ b/src/views/ImportAccountView.vue @@ -46,7 +46,6 @@ import { Options, Vue } from "vue-class-component"; import { deriveAddress, newIdentifier } from "../libs/crypto"; import { db } from "@/db"; -import { useAppStore } from "@/store/app"; @Options({ components: {}, @@ -87,7 +86,6 @@ export default class ImportAccountView extends Vue { publicKeyHex: newId.keys[0].publicKeyHex, }); } - useAppStore().setCondition("registered"); this.$router.push({ name: "account" }); } catch (err) { console.log("Error!"); -- 2.30.2 From 315cdc0cf10af14ef17e93b8d0af6f57449ecc38 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 18 Mar 2023 18:06:58 -0600 Subject: [PATCH 3/6] remove unused lastView and localStorage account names --- src/store/account.ts | 22 ---------------------- src/store/app.ts | 4 ---- 2 files changed, 26 deletions(-) delete mode 100644 src/store/account.ts diff --git a/src/store/account.ts b/src/store/account.ts deleted file mode 100644 index 79c8340..0000000 --- a/src/store/account.ts +++ /dev/null @@ -1,22 +0,0 @@ -// @ts-check -import { defineStore } from "pinia"; - -export const useAccountStore = defineStore({ - id: "account", - state: () => ({ - account: JSON.parse( - typeof localStorage["account"] == "undefined" - ? null - : localStorage["account"] - ), - }), - getters: { - firstName: (state) => state.account.firstName, - lastName: (state) => state.account.lastName, - }, - actions: { - reset() { - localStorage.removeItem("account"); - }, - }, -}); diff --git a/src/store/app.ts b/src/store/app.ts index f5e82cb..0ed6c46 100644 --- a/src/store/app.ts +++ b/src/store/app.ts @@ -4,10 +4,6 @@ import { defineStore } from "pinia"; export const useAppStore = defineStore({ id: "app", state: () => ({ - _lastView: - typeof localStorage["lastView"] == "undefined" - ? "/start" - : localStorage["lastView"], _projectId: typeof localStorage.getItem("projectId") === "undefined" ? "" -- 2.30.2 From afc175e3e7642b7b8b0abb777b3e5490acee59c0 Mon Sep 17 00:00:00 2001 From: Trent Larson Date: Sat, 18 Mar 2023 19:56:57 -0600 Subject: [PATCH 4/6] add settings table to store names (and other things soon) --- src/db/index.ts | 23 +++++++++-- src/db/tables/{accounts.ts => index.ts} | 15 ++++++- src/views/AccountViewView.vue | 53 +++++++++++++------------ src/views/NewEditAccountView.vue | 21 ++++++++-- 4 files changed, 77 insertions(+), 35 deletions(-) rename src/db/tables/{accounts.ts => index.ts} (66%) diff --git a/src/db/index.ts b/src/db/index.ts index 26dcee0..e6d469e 100644 --- a/src/db/index.ts +++ b/src/db/index.ts @@ -1,6 +1,12 @@ import BaseDexie, { Table } from "dexie"; import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon"; -import { Account, accountsSchema } from "./tables/accounts"; +import { + Account, + AccountsSchema, + MASTER_SETTINGS, + Settings, + SettingsSchema, +} from "./tables"; /** * In order to make the next line be acceptable, the program needs to have its linter suppress a rule: @@ -12,10 +18,13 @@ import { Account, accountsSchema } from "./tables/accounts"; */ type DexieTables = { accounts: Table; + settings: Table; }; + export type Dexie = BaseDexie & T; export const db = new BaseDexie("KickStart") as Dexie; -const schema = Object.assign({}, accountsSchema); + +const AllSchemas = Object.assign({}, AccountsSchema, SettingsSchema); /** * Needed to enable a special webpack setting to allow *await* below: @@ -29,6 +38,12 @@ const secret = if (localStorage.getItem("secret") == null) { localStorage.setItem("secret", secret); } -console.log(secret); +console.log("Secret:", secret); encrypted(db, { secretKey: secret }); -db.version(1).stores(schema); +db.version(1).stores(AllSchemas); + +// initialize, a la https://dexie.org/docs/Tutorial/Design#the-populate-event +db.on("populate", function () { + // ensure there's an initial entry for settings + db.settings.add({ id: MASTER_SETTINGS }); +}); diff --git a/src/db/tables/accounts.ts b/src/db/tables/index.ts similarity index 66% rename from src/db/tables/accounts.ts rename to src/db/tables/index.ts index d4a4e61..1c48594 100644 --- a/src/db/tables/accounts.ts +++ b/src/db/tables/index.ts @@ -9,7 +9,20 @@ export type Account = { // mark encrypted field by starting with a $ character // see https://github.com/PVermeer/dexie-addon-suite-monorepo/tree/master/packages/dexie-encrypted-addon -export const accountsSchema = { +export const AccountsSchema = { accounts: "++id, dateCreated, derivationPath, $identity, $mnemonic, publicKeyHex", }; + +// a singleton +export type Settings = { + id: number; + firstName?: string; + lastName?: string; +}; + +export const SettingsSchema = { + settings: "id", +}; + +export const MASTER_SETTINGS = 1; diff --git a/src/views/AccountViewView.vue b/src/views/AccountViewView.vue index a202dfa..e97cabe 100644 --- a/src/views/AccountViewView.vue +++ b/src/views/AccountViewView.vue @@ -185,46 +185,47 @@