feat: add contacts DB & page

This commit is contained in:
2023-03-12 18:30:18 -06:00
parent 701f71e942
commit 4fdfe2f824
9 changed files with 156 additions and 13 deletions

View File

@@ -1,6 +1,12 @@
import BaseDexie from "dexie";
import BaseDexie, { Table } from "dexie";
import { encrypted, Encryption } from "@pvermeer/dexie-encrypted-addon";
import { accountsSchema, AccountsTable } from "./tables/accounts";
import { accountsSchema, Account } from "./tables/accounts";
import { contactsSchema, Contact } from "./tables/contacts";
type AllTables = {
accounts: Table<Account>;
contacts: Table<Contact>;
};
/**
* In order to make the next line be acceptable, the program needs to have its linter suppress a rule:
@@ -10,10 +16,9 @@ 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 = AllTables;
export type Dexie<T extends unknown = DexieTables> = BaseDexie & T;
export const db = new BaseDexie("kickStarter") as Dexie;
const schema = Object.assign({}, accountsSchema);
/**
* Needed to enable a special webpack setting to allow *await* below:
@@ -27,6 +32,7 @@ const secret =
if (localStorage.getItem("secret") == null) {
localStorage.setItem("secret", secret);
}
console.log(secret);
console.log("DB encryption secretKey:", secret);
encrypted(db, { secretKey: secret });
db.version(1).stores(schema);
db.version(1).stores(accountsSchema);
db.version(2).stores(contactsSchema);

View File

@@ -1,5 +1,3 @@
import { Table } from "dexie";
export type Account = {
id?: number;
publicKey: string;
@@ -8,10 +6,6 @@ export type Account = {
dateCreated: number;
};
export type AccountsTable = {
accounts: Table<Account>;
};
// mark encrypted field by starting with a $ character
export const accountsSchema = {
accounts: "++id, publicKey, $mnemonic, $identity, dateCreated",

12
src/db/tables/contacts.ts Normal file
View File

@@ -0,0 +1,12 @@
export interface Contact {
did: string;
name?: string;
publicKeyBase64?: string;
seesMe?: boolean;
registered?: boolean;
}
// mark encrypted field by starting with a $ character
export const contactsSchema = {
contacts: "++did, name, publicKeyBase64, seesMe, registered",
};