prompt for name when showing info, and provide a "copy" page when remote
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
import { Axios, AxiosRequestConfig, AxiosResponse } from "axios";
|
||||
import { Buffer } from "buffer";
|
||||
import { sha256 } from "ethereum-cryptography/sha256";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import * as R from "ramda";
|
||||
|
||||
import { DEFAULT_IMAGE_API_SERVER } from "@/constants/app";
|
||||
import { Contact } from "@/db/tables/contacts";
|
||||
import { accessToken } from "@/libs/crypto";
|
||||
import { accessToken, deriveAddress, nextDerivationPath } from "@/libs/crypto";
|
||||
import { NonsensitiveDexie } from "@/db/index";
|
||||
import { getAccount, getPasskeyExpirationSeconds } from "@/libs/util";
|
||||
import { createEndorserJwtForKey, KeyMeta } from "@/libs/crypto/vc";
|
||||
import { Account } from "@/db/tables/accounts";
|
||||
|
||||
export const SCHEMA_ORG_CONTEXT = "https://schema.org";
|
||||
// the object in RegisterAction claims
|
||||
@@ -925,6 +928,53 @@ export async function createAndSubmitClaim(
|
||||
}
|
||||
}
|
||||
|
||||
export async function generateEndorserJwtForAccount(
|
||||
account: Account,
|
||||
isRegistered?: boolean,
|
||||
name?: string,
|
||||
profileImageUrl?: string,
|
||||
) {
|
||||
const publicKeyHex = account.publicKeyHex;
|
||||
const publicEncKey = Buffer.from(publicKeyHex, "hex").toString("base64");
|
||||
|
||||
interface UserInfo {
|
||||
name: string;
|
||||
publicEncKey: string;
|
||||
registered: boolean;
|
||||
profileImageUrl?: string;
|
||||
nextPublicEncKeyHash?: string;
|
||||
}
|
||||
const contactInfo = {
|
||||
iat: Date.now(),
|
||||
iss: account.did,
|
||||
own: {
|
||||
name: name ?? "",
|
||||
publicEncKey,
|
||||
registered: !!isRegistered,
|
||||
} as UserInfo,
|
||||
};
|
||||
if (profileImageUrl) {
|
||||
contactInfo.own.profileImageUrl = profileImageUrl;
|
||||
}
|
||||
|
||||
if (account?.mnemonic && account?.derivationPath) {
|
||||
const newDerivPath = nextDerivationPath(account.derivationPath as string);
|
||||
const nextPublicHex = deriveAddress(
|
||||
account.mnemonic as string,
|
||||
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(account.did, contactInfo);
|
||||
|
||||
const viewPrefix = CONTACT_URL_PREFIX + ENDORSER_JWT_URL_LOCATION;
|
||||
return viewPrefix + vcJwt;
|
||||
}
|
||||
|
||||
export async function createEndorserJwtForDid(
|
||||
issuerDid: string,
|
||||
payload: object,
|
||||
|
||||
Reference in New Issue
Block a user