add link directly into contact page to add a new contact via "contactJwt" query parameter

This commit is contained in:
2024-09-27 18:41:11 -06:00
parent 2942a02a4e
commit a271d9c206
13 changed files with 204 additions and 78 deletions

View File

@@ -130,9 +130,7 @@ export default class ContactImportView extends Vue {
const importedContacts =
((this.$route as Router).query["contacts"] as string) || "[]";
this.contactsImporting = JSON.parse(importedContacts);
this.contactsSelected = new Array(this.contactsImporting.length).fill(
false,
);
this.contactsSelected = new Array(this.contactsImporting.length).fill(true);
await db.open();
const baseContacts = await db.contacts.toArray();
@@ -158,9 +156,9 @@ export default class ContactImportView extends Vue {
if (R.isEmpty(differences)) {
this.sameCount++;
}
} else {
// automatically import new data
this.contactsSelected[i] = true;
// don't automatically import previous data
this.contactsSelected[i] = false;
}
}
}

View File

@@ -90,8 +90,6 @@
<script lang="ts">
import { AxiosError } from "axios";
import { Buffer } from "buffer/";
import { sha256 } from "ethereum-cryptography/sha256.js";
import QRCodeVue3 from "qr-code-generator-vue3";
import * as R from "ramda";
import { Component, Vue } from "vue-facing-decorator";
@@ -104,15 +102,8 @@ import { NotificationIface } from "@/constants/app";
import { accountsDB, db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { getContactPayloadFromJwtUrl } from "@/libs/crypto";
import {
deriveAddress,
getContactPayloadFromJwtUrl,
nextDerivationPath,
} from "@/libs/crypto";
import {
CONTACT_URL_PREFIX,
createEndorserJwtForDid,
ENDORSER_JWT_URL_LOCATION,
generateEndorserJwtForAccount,
isDid,
register,
@@ -153,37 +144,6 @@ export default class ContactQRScanShow extends Vue {
const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.activeDid, accounts);
if (account) {
const publicKeyHex = account.publicKeyHex;
const publicEncKey = Buffer.from(publicKeyHex, "hex").toString("base64");
const contactInfo = {
iat: Date.now(),
iss: this.activeDid,
own: {
name:
(settings.firstName || "") +
(settings.lastName ? ` ${settings.lastName}` : ""), // lastName is deprecated, pre v 0.1.3
publicEncKey,
profileImageUrl: settings.profileImageUrl,
registered: settings.isRegistered,
},
};
if (account?.mnemonic && account?.derivationPath) {
const newDerivPath = nextDerivationPath(account.derivationPath);
const nextPublicHex = deriveAddress(account.mnemonic, newDerivPath)[2];
const nextPublicEncKey = Buffer.from(nextPublicHex, "hex");
const nextPublicEncKeyHash = sha256(nextPublicEncKey);
const nextPublicEncKeyHashBase64 =
Buffer.from(nextPublicEncKeyHash).toString("base64");
contactInfo.own.nextPublicEncKeyHash = nextPublicEncKeyHashBase64;
}
const vcJwt = await createEndorserJwtForDid(this.activeDid, contactInfo);
const viewPrefix = CONTACT_URL_PREFIX + ENDORSER_JWT_URL_LOCATION;
viewPrefix + vcJwt;
const name =
(settings.firstName || "") +
(settings.lastName ? ` ${settings.lastName}` : ""); // lastName is deprecated, pre v 0.1.3
@@ -193,6 +153,7 @@ export default class ContactQRScanShow extends Vue {
!!settings.isRegistered,
name,
settings.profileImageUrl,
false,
);
}
}

View File

@@ -299,6 +299,7 @@ import {
} from "@/db/index";
import { Contact } from "@/db/tables/contacts";
import { getContactPayloadFromJwtUrl } from "@/libs/crypto";
import { decodeEndorserJwt } from "@/libs/crypto/vc";
import {
CONTACT_CSV_HEADER,
CONTACT_URL_PREFIX,
@@ -307,6 +308,7 @@ import {
isDid,
register,
setVisibilityUtil,
UserInfo,
} from "@/libs/endorserServer";
import * as libsUtil from "@/libs/util";
import QuickNav from "@/components/QuickNav.vue";
@@ -374,6 +376,24 @@ export default class ContactsView extends Vue {
this.contacts = baseContacts.sort((a, b) =>
(a.name || "").localeCompare(b.name || ""),
);
const importedContactJwt = (this.$route as Router).query[
"contactJwt"
] as string;
if (importedContactJwt) {
// really should fully verify
const { payload } = decodeEndorserJwt(importedContactJwt);
const userInfo = payload["own"] as UserInfo;
const newContact = {
did: payload["iss"],
name: userInfo.name,
nextPubKeyHashB64: userInfo.nextPublicEncKeyHash,
profileImageUrl: userInfo.profileImageUrl,
publicKeyBase64: userInfo.publicEncKey,
registered: userInfo.registered,
} as Contact;
this.addContact(newContact);
}
}
private danger(message: string, title: string = "Error", timeout = 5000) {
@@ -891,7 +911,10 @@ export default class ContactsView extends Vue {
}
return true;
} else {
console.error("Got strange result from setting visibility:", result);
console.error(
"Got strange result from setting visibility. It can happen when setting visibility on oneself.",
result,
);
const message =
(result.error as string) || "Could not set visibility on the server.";
this.$notify(

View File

@@ -146,7 +146,7 @@
</div>
<div
v-if="showGeneralAdvanced && includeLocation && false"
v-if="showGeneralAdvanced && includeLocation"
class="items-center mb-4"
>
<div class="flex">

View File

@@ -77,6 +77,7 @@ export default class ShareMyContactInfoView extends Vue {
isRegistered,
givenName,
profileImageUrl,
true,
);
useClipboard()
.copy(message)