change accessToken to take a DID

This commit is contained in:
2024-07-09 19:20:05 -06:00
parent 45f0a14661
commit bce003e508
15 changed files with 47 additions and 192 deletions

View File

@@ -1,8 +1,4 @@
import {
Axios,
AxiosRequestConfig,
AxiosResponse,
} from "axios";
import { Axios, AxiosRequestConfig, AxiosResponse } from "axios";
import * as didJwt from "did-jwt";
import { LRUCache } from "lru-cache";
import * as R from "ramda";
@@ -458,7 +454,7 @@ export async function getHeaders(did?: string) {
"Content-Type": "application/json",
};
if (did) {
const token = await accessToken(undefined, did);
const token = await accessToken(did);
headers["Authorization"] = "Bearer " + token;
} else {
// it's often OK to request without auth; we assume necessary checks are done earlier
@@ -716,7 +712,7 @@ export async function createAndSubmitClaim(
// Make the xhr request payload
const payload = JSON.stringify({ jwtEncoded: vcJwt });
const url = `${apiServer}/api/v2/claim`;
const token = await accessToken(identity);
const token = await accessToken(identity.did);
const response = await axios.post(url, payload, {
headers: {
@@ -948,7 +944,7 @@ export const bvcMeetingJoinClaim = (did: string, startTime: string) => {
export async function createEndorserJwt(did: string, payload: object) {
const account = await getAccount(did);
if (account.identity) {
if (account?.identity) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const identity = JSON.parse(account.identity!);
const privateKeyHex = identity.keys[0].privateKeyHex;
@@ -957,7 +953,7 @@ export async function createEndorserJwt(did: string, payload: object) {
issuer: did,
signer: signer,
});
} else if (account.passkeyCredIdHex) {
} else if (account?.passkeyCredIdHex) {
return createDidPeerJwt(did, account.passkeyCredIdHex, payload);
} else {
throw new Error("No identity data found to sign for DID " + did);