Browse Source

Refactored again. Fields update on Account page

kb/add-usage-guide
Matthew Aaron Raymer 2 years ago
parent
commit
c6d0473fab
  1. 2
      src/db/index.ts
  2. 84
      src/views/AccountViewView.vue

2
src/db/index.ts

@ -29,7 +29,7 @@ if (exists == false) {
if (localStorage.getItem("secret") == null) { if (localStorage.getItem("secret") == null) {
localStorage.setItem("secret", secret); localStorage.setItem("secret", secret);
} }
console.log(secret);
encrypted(db, { secretKey: secret }); encrypted(db, { secretKey: secret });
db.version(1).stores(schema); db.version(1).stores(schema);
} }

84
src/views/AccountViewView.vue

@ -79,7 +79,7 @@
class="text-sm text-slate-500 flex justify-between items-center mb-1" class="text-sm text-slate-500 flex justify-between items-center mb-1"
> >
<span <span
><code>did:peer:kl45kj41lk451kl3</code> ><code>{{ address }}</code>
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa> <fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
</span> </span>
<span> <span>
@ -99,7 +99,7 @@
<div class="text-slate-500 text-sm font-bold">Public Key</div> <div class="text-slate-500 text-sm font-bold">Public Key</div>
<div class="text-sm text-slate-500 mb-1"> <div class="text-sm text-slate-500 mb-1">
<span <span
><code>dyIgKepL19trfrFu5jzkoNhI</code> ><code>{{ publicHex }}</code>
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa> <fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
</span> </span>
</div> </div>
@ -107,7 +107,7 @@
<div class="text-slate-500 text-sm font-bold">Derivation Path</div> <div class="text-slate-500 text-sm font-bold">Derivation Path</div>
<div class="text-sm text-slate-500 mb-1"> <div class="text-sm text-slate-500 mb-1">
<span <span
><code>m/44'/0'/0'/0/0</code> ><code>{{ UPORT_ROOT_DERIVATION_PATH }}</code>
<fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa> <fa icon="copy" class="text-slate-400 fa-fw ml-1"></fa>
</span> </span>
</div> </div>
@ -167,8 +167,6 @@
<script lang="ts"> <script lang="ts">
import { Options, Vue } from "vue-class-component"; import { Options, Vue } from "vue-class-component";
import { useAppStore } from "../store/app";
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";
@ -178,76 +176,76 @@ import { db } from "../db";
components: {}, components: {},
}) })
export default class AccountViewView extends Vue { export default class AccountViewView extends Vue {
created() { mnemonic = "";
address = "";
privateHex = "";
publicHex = "";
UPORT_ROOT_DERIVATION_PATH = "";
async created() {
const previousIdentifiers: Array<IIdentifier> = []; const previousIdentifiers: Array<IIdentifier> = [];
const toLowercase = true; const toLowercase = true;
const appStore = useAppStore();
const accountStore = useAccountStore();
if (appStore._condition == "uninitialized") { this.mnemonic = createIdentifier();
const mnemonic = createIdentifier(); [
this.address,
const [address, privateHex, publicHex, UPORT_ROOT_DERIVATION_PATH] = this.privateHex,
deriveAddress(mnemonic); this.publicHex,
this.UPORT_ROOT_DERIVATION_PATH,
] = deriveAddress(this.mnemonic);
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... derived keys and address..."})) //appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... derived keys and address..."}))
const prevIds = previousIdentifiers || []; const prevIds = previousIdentifiers || [];
let addr = address;
if (toLowercase) { if (toLowercase) {
const foundEqual = R.find( const foundEqual = R.find(
(id: IIdentifier) => id.did.split(":")[2] === address, (id: IIdentifier) => id.did.split(":")[2] === this.address,
prevIds prevIds
); );
if (foundEqual) { if (foundEqual) {
// appStore.dispatch(appSlice.actions.addLog({log: true, msg: "Will create a normal-case version of the DID since a regular version exists."})) // appStore.dispatch(appSlice.actions.addLog({log: true, msg: "Will create a normal-case version of the DID since a regular version exists."}))
} else { } else {
addr = address.toLowerCase(); this.address = this.address.toLowerCase();
} }
} else { } else {
// They're not trying to convert to lowercase. // They're not trying to convert to lowercase.
const foundLower = R.find( const foundLower = R.find(
(id: IIdentifier) => id.did.split(":")[2] === address.toLowerCase(), (id: IIdentifier) =>
id.did.split(":")[2] === this.address.toLowerCase(),
prevIds prevIds
); );
if (foundLower) { if (foundLower) {
// appStore.dispatch(appSlice.actions.addLog({log: true, msg: "Will create a lowercase version of the DID since a lowercase version exists."})) // appStore.dispatch(appSlice.actions.addLog({log: true, msg: "Will create a lowercase version of the DID since a lowercase version exists."}))
addr = address.toLowerCase(); this.address = this.address.toLowerCase();
} }
} }
const newId = newIdentifier( const newId = newIdentifier(
addr, this.address,
publicHex, this.publicHex,
privateHex, this.privateHex,
UPORT_ROOT_DERIVATION_PATH this.UPORT_ROOT_DERIVATION_PATH
); );
db.open() try {
.then(function (odexie) { await db.open();
odexie._allTables.accounts.count(function (result) { const num_accounts = await db._allTables.accounts.count();
if (result === 0) { if (num_accounts === 0) {
console.log("No accounts"); console.log("...");
odexie._allTables.accounts await db._allTables.accounts.add({
.add({
publicKey: newId.keys[0].publicKeyHex, publicKey: newId.keys[0].publicKeyHex,
mnemonic: mnemonic, mnemonic: this.mnemonic,
identity: JSON.stringify(newId), identity: JSON.stringify(newId),
dateCreated: new Date().getTime(), dateCreated: new Date().getTime(),
})
.then(function () {
odexie._allTables.accounts.each(function (account) {
console.log("Found close friend: " + account.publicKey);
});
}); });
} else {
console.log("Skipping initial create on empty db.");
} }
}); const accounts = await db._allTables.accounts.toArray();
}) console.log(accounts[0]);
.catch(function (err) { const identity = JSON.parse(accounts[0].identity);
console.error("Failed to open db: " + (err.stack || err));
}); this.address = identity.did;
this.publicHex = identity.keys[0].publicKeyHex;
//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);
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... stored new ID..."})) //appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... stored new ID..."}))
} catch {
console.log("Error!");
} }
} }
} }

Loading…
Cancel
Save