forked from trent_larson/crowd-funder-for-time-pwa
Refactored again. Fields update on Account page
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,
|
||||||
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... derived keys and address..."}))
|
this.UPORT_ROOT_DERIVATION_PATH,
|
||||||
const prevIds = previousIdentifiers || [];
|
] = deriveAddress(this.mnemonic);
|
||||||
let addr = address;
|
//appStore.dispatch(appSlice.actions.addLog({log: false, msg: "... derived keys and address..."}))
|
||||||
if (toLowercase) {
|
const prevIds = previousIdentifiers || [];
|
||||||
const foundEqual = R.find(
|
if (toLowercase) {
|
||||||
(id: IIdentifier) => id.did.split(":")[2] === address,
|
const foundEqual = R.find(
|
||||||
prevIds
|
(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();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// They're not trying to convert to lowercase.
|
|
||||||
const foundLower = R.find(
|
|
||||||
(id: IIdentifier) => id.did.split(":")[2] === 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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const newId = newIdentifier(
|
|
||||||
addr,
|
|
||||||
publicHex,
|
|
||||||
privateHex,
|
|
||||||
UPORT_ROOT_DERIVATION_PATH
|
|
||||||
);
|
);
|
||||||
db.open()
|
if (foundEqual) {
|
||||||
.then(function (odexie) {
|
// appStore.dispatch(appSlice.actions.addLog({log: true, msg: "Will create a normal-case version of the DID since a regular version exists."}))
|
||||||
odexie._allTables.accounts.count(function (result) {
|
} else {
|
||||||
if (result === 0) {
|
this.address = this.address.toLowerCase();
|
||||||
console.log("No accounts");
|
}
|
||||||
odexie._allTables.accounts
|
} else {
|
||||||
.add({
|
// They're not trying to convert to lowercase.
|
||||||
publicKey: newId.keys[0].publicKeyHex,
|
const foundLower = R.find(
|
||||||
mnemonic: mnemonic,
|
(id: IIdentifier) =>
|
||||||
identity: JSON.stringify(newId),
|
id.did.split(":")[2] === this.address.toLowerCase(),
|
||||||
dateCreated: new Date().getTime(),
|
prevIds
|
||||||
})
|
);
|
||||||
.then(function () {
|
if (foundLower) {
|
||||||
odexie._allTables.accounts.each(function (account) {
|
// appStore.dispatch(appSlice.actions.addLog({log: true, msg: "Will create a lowercase version of the DID since a lowercase version exists."}))
|
||||||
console.log("Found close friend: " + account.publicKey);
|
this.address = this.address.toLowerCase();
|
||||||
});
|
}
|
||||||
});
|
}
|
||||||
} else {
|
|
||||||
console.log("Skipping initial create on empty db.");
|
const newId = newIdentifier(
|
||||||
}
|
this.address,
|
||||||
});
|
this.publicHex,
|
||||||
})
|
this.privateHex,
|
||||||
.catch(function (err) {
|
this.UPORT_ROOT_DERIVATION_PATH
|
||||||
console.error("Failed to open db: " + (err.stack || err));
|
);
|
||||||
|
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: this.mnemonic,
|
||||||
|
identity: JSON.stringify(newId),
|
||||||
|
dateCreated: new Date().getTime(),
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
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..."}))
|
//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!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user