Functional Identity Management
This commit is contained in:
@@ -25,12 +25,15 @@
|
|||||||
<ul class="mb-4">
|
<ul class="mb-4">
|
||||||
<li
|
<li
|
||||||
class="block bg-slate-100 rounded-md flex items-center px-4 py-3 mb-2"
|
class="block bg-slate-100 rounded-md flex items-center px-4 py-3 mb-2"
|
||||||
|
v-for="ident in otherIdentities"
|
||||||
|
:key="ident.did"
|
||||||
|
@click="switchAccount(ident.did)"
|
||||||
>
|
>
|
||||||
<fa icon="circle" class="fa-fw text-slate-400 text-xl mr-3"></fa>
|
<fa icon="circle" class="fa-fw text-slate-400 text-xl mr-3"></fa>
|
||||||
<span class="overflow-hidden">
|
<span class="overflow-hidden">
|
||||||
<h2 class="text-xl font-semibold mb-0">Givenname Surname</h2>
|
<h2 class="text-xl font-semibold mb-0"></h2>
|
||||||
<div class="text-sm text-slate-500 truncate">
|
<div class="text-sm text-slate-500 truncate">
|
||||||
<b>ID:</b> <code>did:peer:lk451kl3kl45kj41</code>
|
<b>ID:</b> <code>{{ ident.did }}</code>
|
||||||
</div>
|
</div>
|
||||||
</span>
|
</span>
|
||||||
</li>
|
</li>
|
||||||
@@ -44,8 +47,9 @@
|
|||||||
Add Another Identity…
|
Add Another Identity…
|
||||||
</router-link>
|
</router-link>
|
||||||
<a
|
<a
|
||||||
href="start.html"
|
href="#"
|
||||||
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-8"
|
class="block w-full text-center text-md uppercase bg-slate-500 text-white px-1.5 py-2 rounded-md mb-8"
|
||||||
|
@click="switchAccount('0')"
|
||||||
>
|
>
|
||||||
No Identity
|
No Identity
|
||||||
</a>
|
</a>
|
||||||
@@ -68,10 +72,23 @@ import QuickNav from "@/components/QuickNav";
|
|||||||
@Component({ components: { AlertMessage, QuickNav } })
|
@Component({ components: { AlertMessage, QuickNav } })
|
||||||
export default class IdentitySwitcherView extends Vue {
|
export default class IdentitySwitcherView extends Vue {
|
||||||
Constants = AppString;
|
Constants = AppString;
|
||||||
private accounts: AccountsSchema;
|
public accounts: AccountsSchema;
|
||||||
public activeDid;
|
public activeDid;
|
||||||
public firstName;
|
public firstName;
|
||||||
public lastName;
|
public lastName;
|
||||||
|
public alertTitle;
|
||||||
|
public alertMessage;
|
||||||
|
public otherIdentities = [];
|
||||||
|
|
||||||
|
public async getIdentity(activeDid) {
|
||||||
|
await accountsDB.open();
|
||||||
|
const account = await accountsDB.accounts
|
||||||
|
.where("did")
|
||||||
|
.equals(activeDid)
|
||||||
|
.first();
|
||||||
|
const identity = JSON.parse(account?.identity || "null");
|
||||||
|
return identity;
|
||||||
|
}
|
||||||
|
|
||||||
async created() {
|
async created() {
|
||||||
try {
|
try {
|
||||||
@@ -86,14 +103,19 @@ export default class IdentitySwitcherView extends Vue {
|
|||||||
|
|
||||||
const identity = await this.getIdentity(this.activeDid);
|
const identity = await this.getIdentity(this.activeDid);
|
||||||
|
|
||||||
this.publicHex = identity.keys[0].publicKeyHex;
|
if (identity) {
|
||||||
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
|
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||||
this.derivationPath = identity.keys[0].meta.derivationPath;
|
activeDid: identity.did,
|
||||||
|
});
|
||||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
}
|
||||||
activeDid: identity.did,
|
await accountsDB.open();
|
||||||
});
|
const accounts = await accountsDB.accounts.toArray();
|
||||||
this.checkLimits();
|
for (let n = 0; n < accounts.length; n++) {
|
||||||
|
const did = JSON.parse(accounts[n].identity)["did"];
|
||||||
|
if (did && this.activeDid !== did) {
|
||||||
|
this.otherIdentities.push({ did: did });
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (
|
if (
|
||||||
err.message ===
|
err.message ===
|
||||||
@@ -113,31 +135,24 @@ export default class IdentitySwitcherView extends Vue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async switchAccount(accountNum: number) {
|
async switchAccount(did: string) {
|
||||||
// 0 means none
|
// 0 means none
|
||||||
if (accountNum === 0) {
|
if (did === "0") {
|
||||||
await db.open();
|
did = undefined;
|
||||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
}
|
||||||
activeDid: undefined,
|
await db.open();
|
||||||
});
|
db.settings.update(MASTER_SETTINGS_KEY, {
|
||||||
this.activeDid = "";
|
activeDid: did,
|
||||||
this.derivationPath = "";
|
});
|
||||||
this.publicHex = "";
|
this.activeDid = did;
|
||||||
this.publicBase64 = "";
|
this.otherIdentities = [];
|
||||||
} else {
|
await accountsDB.open();
|
||||||
await accountsDB.open();
|
const accounts = await accountsDB.accounts.toArray();
|
||||||
const accounts = await accountsDB.accounts.toArray();
|
for (let n = 0; n < accounts.length; n++) {
|
||||||
const account = accounts[accountNum - 1];
|
const did = JSON.parse(accounts[n].identity)["did"];
|
||||||
|
if (did && this.activeDid !== did) {
|
||||||
await db.open();
|
this.otherIdentities.push({ did: did });
|
||||||
db.settings.update(MASTER_SETTINGS_KEY, {
|
}
|
||||||
activeDid: account.did,
|
|
||||||
});
|
|
||||||
|
|
||||||
this.activeDid = account.did;
|
|
||||||
this.derivationPath = account.derivationPath;
|
|
||||||
this.publicHex = account.publicKeyHex;
|
|
||||||
this.publicBase64 = Buffer.from(this.publicHex, "hex").toString("base64");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user