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

Loading…
Cancel
Save