forked from trent_larson/crowd-funder-for-time-pwa
New structure
This commit is contained in:
9
package-lock.json
generated
9
package-lock.json
generated
@@ -28,6 +28,7 @@
|
|||||||
"ethereum-cryptography": "^1.1.2",
|
"ethereum-cryptography": "^1.1.2",
|
||||||
"ethereumjs-util": "^7.1.5",
|
"ethereumjs-util": "^7.1.5",
|
||||||
"ethr-did-resolver": "^8.0.0",
|
"ethr-did-resolver": "^8.0.0",
|
||||||
|
"js-generate-password": "^0.1.7",
|
||||||
"localstorage-slim": "^2.3.0",
|
"localstorage-slim": "^2.3.0",
|
||||||
"luxon": "^3.1.1",
|
"luxon": "^3.1.1",
|
||||||
"merkletreejs": "^0.3.9",
|
"merkletreejs": "^0.3.9",
|
||||||
@@ -16845,6 +16846,14 @@
|
|||||||
"url": "https://github.com/sponsors/panva"
|
"url": "https://github.com/sponsors/panva"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/js-generate-password": {
|
||||||
|
"version": "0.1.7",
|
||||||
|
"resolved": "https://registry.npmjs.org/js-generate-password/-/js-generate-password-0.1.7.tgz",
|
||||||
|
"integrity": "sha512-O2fTDgD2DSf4mnuTKO0rZ2DMgv/CkWvdboKzV5XDDLsUrmFQppbMtMkbLIEHiiXSsIdMcFdr/OAN+CXqc7TdTQ==",
|
||||||
|
"bin": {
|
||||||
|
"js-generate-password": "dist/index.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/js-message": {
|
"node_modules/js-message": {
|
||||||
"version": "1.0.7",
|
"version": "1.0.7",
|
||||||
"resolved": "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz",
|
"resolved": "https://registry.npmmirror.com/js-message/-/js-message-1.0.7.tgz",
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
"ethereum-cryptography": "^1.1.2",
|
"ethereum-cryptography": "^1.1.2",
|
||||||
"ethereumjs-util": "^7.1.5",
|
"ethereumjs-util": "^7.1.5",
|
||||||
"ethr-did-resolver": "^8.0.0",
|
"ethr-did-resolver": "^8.0.0",
|
||||||
|
"js-generate-password": "^0.1.7",
|
||||||
"localstorage-slim": "^2.3.0",
|
"localstorage-slim": "^2.3.0",
|
||||||
"luxon": "^3.1.1",
|
"luxon": "^3.1.1",
|
||||||
"merkletreejs": "^0.3.9",
|
"merkletreejs": "^0.3.9",
|
||||||
|
|||||||
7
src/constants/app.ts
Normal file
7
src/constants/app.ts
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
/**
|
||||||
|
* Generic strings that could be used throughout the app.
|
||||||
|
*/
|
||||||
|
export enum AppString {
|
||||||
|
APP_NAME = "Kickstart for time",
|
||||||
|
VERSION = "0.1",
|
||||||
|
}
|
||||||
27
src/constants/model.ts
Normal file
27
src/constants/model.ts
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/**
|
||||||
|
* Field names used by the tables for the DB objects.
|
||||||
|
*/
|
||||||
|
export enum Field {
|
||||||
|
// Setting
|
||||||
|
KEY = "key",
|
||||||
|
VALUE = "value",
|
||||||
|
// Log
|
||||||
|
SEVERITY = "severity",
|
||||||
|
LABEL = "label",
|
||||||
|
ERROR = "error",
|
||||||
|
// Accounts
|
||||||
|
NAME = "name",
|
||||||
|
DESCRIPTION = "description",
|
||||||
|
ID = "id",
|
||||||
|
IDENTITY = "indentity",
|
||||||
|
CREATED_TIMESTAMP = "createdTimestamp",
|
||||||
|
STATUS = "status",
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum Severity {
|
||||||
|
DEBUG = "Debug",
|
||||||
|
INFO = "Info",
|
||||||
|
WARN = "Warning",
|
||||||
|
ERROR = "Error",
|
||||||
|
CRITICAL = "Critical",
|
||||||
|
}
|
||||||
6
src/constants/table.ts
Normal file
6
src/constants/table.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
/**
|
||||||
|
* Dexie table names used by the DexieWrapper service.
|
||||||
|
*/
|
||||||
|
export enum AppTable {
|
||||||
|
ACCOUNTS = "Accounts-Table",
|
||||||
|
}
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
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<Account>;
|
|
||||||
|
|
||||||
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();
|
|
||||||
@@ -45,7 +45,6 @@ library.add(
|
|||||||
);
|
);
|
||||||
|
|
||||||
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";
|
||||||
import { db } from "./libs/db";
|
|
||||||
|
|
||||||
createApp(App)
|
createApp(App)
|
||||||
.component("fa", FontAwesomeIcon)
|
.component("fa", FontAwesomeIcon)
|
||||||
|
|||||||
9
src/models/Account.ts
Normal file
9
src/models/Account.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import type { Field } from "@/constants/model";
|
||||||
|
|
||||||
|
export interface IDBAccount {
|
||||||
|
[Field.ID]?: string;
|
||||||
|
[Field.IDENTITY]: string;
|
||||||
|
[Field.NAME]: string;
|
||||||
|
[Field.DESCRIPTION]: string;
|
||||||
|
[Field.CREATED_TIMESTAMP]: number;
|
||||||
|
}
|
||||||
@@ -115,7 +115,7 @@ router.beforeEach(async (to) => {
|
|||||||
const isPublic = publicPages.includes(to.path);
|
const isPublic = publicPages.includes(to.path);
|
||||||
const appStore = useAppStore();
|
const appStore = useAppStore();
|
||||||
let return_path = "/start";
|
let return_path = "/start";
|
||||||
|
console.log(isPublic);
|
||||||
if (isPublic) {
|
if (isPublic) {
|
||||||
switch (appStore.condition) {
|
switch (appStore.condition) {
|
||||||
case "uninitialized":
|
case "uninitialized":
|
||||||
|
|||||||
35
src/services/DexieWrapper.ts
Normal file
35
src/services/DexieWrapper.ts
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
import Dexie, { type Table } from "dexie";
|
||||||
|
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
|
||||||
|
|
||||||
|
import { AppString } from "@/constants/app";
|
||||||
|
import { AppTable } from "../constants/table";
|
||||||
|
import { Field } from "@/constants/model";
|
||||||
|
import { IDBAccount } from "@/models/Account";
|
||||||
|
|
||||||
|
export class DexieWrapper extends Dexie {
|
||||||
|
[AppTable.ACCOUNTS]!: Table<IDBAccount>;
|
||||||
|
|
||||||
|
constructor(name: string, secret: string) {
|
||||||
|
super(name, { autoOpen: true });
|
||||||
|
encrypted(this, { secretKey: secret });
|
||||||
|
this.version(1).stores({
|
||||||
|
[AppTable.ACCOUNTS]: `#&${Field.ID}, $${Field.IDENTITY}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const secret =
|
||||||
|
localStorage.getItem("secret") || Encryption.createRandomEncryptionKey();
|
||||||
|
|
||||||
|
if (localStorage.getItem("secret") == null) {
|
||||||
|
localStorage.setItem("secret", secret);
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log("secret", secret);
|
||||||
|
/**
|
||||||
|
* Preconfigured DexieWrapper
|
||||||
|
*/
|
||||||
|
export const dexieWrapper = new DexieWrapper(
|
||||||
|
`${AppString.APP_NAME} v${AppString.VERSION}`,
|
||||||
|
secret
|
||||||
|
);
|
||||||
41
src/use/useDBAccounts.ts
Normal file
41
src/use/useDBAccounts.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
import type { IndexableType } from "dexie";
|
||||||
|
import { AppTable } from "@/constants/table";
|
||||||
|
import { Field } from "@/constants/model";
|
||||||
|
import { dexieWrapper } from "@/services/DexieWrapper";
|
||||||
|
import type { IDBAccount } from "@/models/Account";
|
||||||
|
|
||||||
|
export default function useDBAccounts() {
|
||||||
|
/**
|
||||||
|
* Gets all data from the Logs table.
|
||||||
|
* @returns IDBAccount[]
|
||||||
|
*/
|
||||||
|
async function getAccountsTable(): Promise<IDBAccount[]> {
|
||||||
|
return await dexieWrapper.table(AppTable.ACCOUNTS).toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an Account to the database.
|
||||||
|
* @param name
|
||||||
|
* @param description
|
||||||
|
* @param identity
|
||||||
|
* @returns Id of new Account
|
||||||
|
*/
|
||||||
|
async function addAccount(
|
||||||
|
name: string,
|
||||||
|
description: string,
|
||||||
|
identity: string
|
||||||
|
): Promise<IndexableType> {
|
||||||
|
const account: IDBAccount = {
|
||||||
|
[Field.CREATED_TIMESTAMP]: new Date().getTime(),
|
||||||
|
[Field.NAME]: name,
|
||||||
|
[Field.DESCRIPTION]: description,
|
||||||
|
[Field.IDENTITY]: identity,
|
||||||
|
};
|
||||||
|
return await dexieWrapper.table(AppTable.ACCOUNTS).add(account);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
getAccountsTable,
|
||||||
|
addAccount,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -172,7 +172,9 @@ import { useAccountStore } from "../store/account";
|
|||||||
import { createIdentifier, deriveAddress, newIdentifier } from "../libs/crypto";
|
import { createIdentifier, deriveAddress, newIdentifier } from "../libs/crypto";
|
||||||
import { IIdentifier } from "@veramo/core";
|
import { IIdentifier } from "@veramo/core";
|
||||||
import * as R from "ramda";
|
import * as R from "ramda";
|
||||||
import { db } from "../libs/db";
|
import useDBAccounts from "@/use/useDBAccounts";
|
||||||
|
|
||||||
|
const { addAccount } = useDBAccounts();
|
||||||
|
|
||||||
@Options({
|
@Options({
|
||||||
components: {},
|
components: {},
|
||||||
@@ -221,15 +223,7 @@ export default class AccountViewView extends Vue {
|
|||||||
UPORT_ROOT_DERIVATION_PATH
|
UPORT_ROOT_DERIVATION_PATH
|
||||||
);
|
);
|
||||||
console.log(newId);
|
console.log(newId);
|
||||||
db.accounts.add({
|
addAccount("me", "you", "identity");
|
||||||
did: address,
|
|
||||||
kid: newId.keys[0].kid,
|
|
||||||
kms: newId.keys[0].kms,
|
|
||||||
meta: "",
|
|
||||||
privateKeyHex: privateHex,
|
|
||||||
publicKeyHex: publicHex,
|
|
||||||
type: "Secp256k1",
|
|
||||||
});
|
|
||||||
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... created new ID..."}))
|
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... created new ID..."}))
|
||||||
accountStore.account = JSON.stringify(newId);
|
accountStore.account = JSON.stringify(newId);
|
||||||
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... stored new ID..."}))
|
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... stored new ID..."}))
|
||||||
|
|||||||
Reference in New Issue
Block a user