add correct encodings for public keys, plus some instructions for entering a contact

This commit is contained in:
2023-03-20 18:58:55 -06:00
parent d293d0c3e2
commit 5c75ad80af
6 changed files with 45 additions and 16 deletions

View File

@@ -144,6 +144,9 @@ import { accountsDB, db } from "@/db";
import { Contact } from "@/db/tables/contacts";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
// eslint-disable-next-line @typescript-eslint/no-var-requires
const Buffer = require("buffer/").Buffer;
export interface GiveVerifiableCredential {
"@context": string;
"@type": string;
@@ -196,6 +199,11 @@ export default class ContactsView extends Vue {
publicKeyBase64 = this.contactInput.substring(commaPos2 + 1).trim();
}
}
// help with potential mistakes while this sharing requires copy-and-paste
if (publicKeyBase64 && /^[0-9A-Fa-f]{66}$/i.test(publicKeyBase64)) {
// it must be all hex (compressed public key), so convert
publicKeyBase64 = Buffer.from(publicKeyBase64, "hex").toString("base64");
}
const newContact = { did, name, publicKeyBase64 };
await db.contacts.add(newContact);
this.contacts = this.contacts.concat([newContact]);