Skip to content

Commit ad596ac

Browse files
committed
read truvera api configs from data-store
1 parent cab1595 commit ad596ac

5 files changed

Lines changed: 50 additions & 20 deletions

File tree

integration-tests/delegatable-revocation.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,10 @@ describe('Delegatable Revocation', () => {
6868
ctx = {
6969
wallet: walletClient.wallet,
7070
issuerDID: walletClient.did,
71-
truveraApiSponsorKey: SPONSOR_KEY as string,
72-
apiUrl: API_URL as string,
71+
truveraApiConfigs: {
72+
authKey: SPONSOR_KEY as string,
73+
apiUrl: API_URL as string,
74+
},
7375
};
7476
});
7577

packages/core/src/delegation/delegation-issuance.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export async function issueCredential(
4242

4343
assert(recipientRole, `Role ${delegationRoleId} not found in ruleset`);
4444

45-
const credentialStatus = revocationContext
45+
const credentialStatus = revocationContext?.truveraApiConfigs
4646
? (await allocateStatusEntry(revocationContext)).credentialStatus
4747
: credentialData.credentialStatus;
4848

@@ -72,12 +72,14 @@ export async function delegateCredential({
7272
delegationPolicy,
7373
delegationRoleId,
7474
delegatorDID,
75+
revocationContext,
7576
}: {
7677
credential: any;
7778
wallet: any;
7879
delegationPolicy: DelegationPolicy;
7980
delegationRoleId: string;
8081
delegatorDID: string;
82+
revocationContext?: RevocationContext;
8183
}) {
8284
assert(isDelegatableCredential(credential), 'Credential is not delegatable');
8385
assert(!!delegatorDID, 'delegatorDID is required');
@@ -112,5 +114,6 @@ export async function delegateCredential({
112114
delegationPolicy,
113115
delegationRoleId,
114116
credential.rootCredentialId || credential.id,
117+
revocationContext,
115118
);
116119
}

packages/core/src/delegation/delegation-offer.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,20 @@ export async function createDelegationOffer({
8787
isDelegatableCredential(parentCredential),
8888
`Credential ${credentialId} is not delegatable`,
8989
);
90-
const parentDetails = await getDelegationDetails(parentCredential, wallet);
90+
const parentDetails = await getDelegationDetails(
91+
parentCredential,
92+
wallet,
93+
);
9194
if (parentDetails.delegationPolicy) {
92-
assertPolicyConformsToParent(delegationPolicy, parentDetails.delegationPolicy, {
93-
delegationRole,
94-
remainingDepth: parentDetails.remainingDelegationDepth,
95-
parentRoleId: parentDetails.role?.roleId,
96-
});
95+
assertPolicyConformsToParent(
96+
delegationPolicy,
97+
parentDetails.delegationPolicy,
98+
{
99+
delegationRole,
100+
remainingDepth: parentDetails.remainingDelegationDepth,
101+
parentRoleId: parentDetails.role?.roleId,
102+
},
103+
);
97104
}
98105
}
99106
}
@@ -149,8 +156,10 @@ export function createOOBInvitation(
149156
issuerDID: issuerDID,
150157
issuerName: finalIssuerName,
151158
role: delegationOffer.delegationRole,
152-
roleLabel: getRole(delegationOffer.delegationRole, delegationOffer.delegationPolicy)
153-
?.label,
159+
roleLabel: getRole(
160+
delegationOffer.delegationRole,
161+
delegationOffer.delegationPolicy,
162+
)?.label,
154163
createdAt: delegationOffer.sentAt,
155164
expiresAt: delegationOffer.expiresAt,
156165
};
@@ -325,7 +334,10 @@ export const DELEGATION_REQUEST_HANDLER = {
325334
try {
326335
validateDelegationPolicy(delegationOffer.delegationPolicy);
327336
if (parentCredential && isDelegatableCredential(parentCredential)) {
328-
const parentDetails = await getDelegationDetails(parentCredential, wallet);
337+
const parentDetails = await getDelegationDetails(
338+
parentCredential,
339+
wallet,
340+
);
329341
if (parentDetails.delegationPolicy) {
330342
assertPolicyConformsToParent(
331343
delegationOffer.delegationPolicy,
@@ -361,6 +373,11 @@ export const DELEGATION_REQUEST_HANDLER = {
361373
delegationPolicy: delegationOffer.delegationPolicy,
362374
delegationRoleId: delegationOffer.delegationRole,
363375
delegatorDID: delegationOffer.issuerDID || issuerDID,
376+
revocationContext: {
377+
wallet,
378+
truveraApiConfigs: wallet.dataStore.configs.truveraApi,
379+
issuerDID: delegationOffer.issuerDID || issuerDID,
380+
},
364381
});
365382

366383
const delegationChain = await getDelegationChain(parentCredential, wallet);
@@ -498,8 +515,8 @@ export const messageHandlers = [
498515
export async function handleMessage(
499516
message,
500517
context: {
501-
wallet;
502-
messageProvider;
518+
wallet: any;
519+
messageProvider: any;
503520
},
504521
) {
505522
const decoded = decodeMessage(message);

packages/core/src/delegation/delegation-revocation.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ export interface StatusList2021Entry {
4646
statusListCredential: string;
4747
}
4848

49+
export interface TruveraApiConfigs {
50+
authKey: string;
51+
apiUrl: string;
52+
}
53+
4954
/**
5055
* Common context for every signed revocation API call.
5156
*
@@ -55,8 +60,7 @@ export interface StatusList2021Entry {
5560
export interface RevocationContext {
5661
wallet: IWallet;
5762
issuerDID: string; // the did:key that owns the registry / signs the JWT
58-
truveraApiSponsorKey: string;
59-
apiUrl: string;
63+
truveraApiConfigs: TruveraApiConfigs;
6064
}
6165

6266
/**
@@ -97,16 +101,16 @@ async function postRevocation(
97101
registryId: string,
98102
body: Record<string, any>,
99103
): Promise<any> {
100-
assert(!!ctx.truveraApiSponsorKey, 'truveraApiSponsorKey is required');
104+
assert(!!ctx.truveraApiConfigs, 'truveraApiSponsorKey is required');
101105
const jwt = await signRevocationJWT(ctx, {registryId, ...body});
102106

103107
try {
104108
const response = await axios.post(
105-
`${ctx.apiUrl}/delegatable-revocations/${registryId}`,
109+
`${ctx.truveraApiConfigs.apiUrl}/delegatable-revocations/${registryId}`,
106110
body,
107111
{
108112
headers: {
109-
'X-MOBILE-SPONSOR-KEY': ctx.truveraApiSponsorKey,
113+
'X-MOBILE-SPONSOR-KEY': ctx.truveraApiConfigs.authKey,
110114
Authorization: `Bearer ${jwt}`,
111115
'Content-Type': 'application/json',
112116
},

packages/data-store/src/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,11 @@ export type DataStoreConfigs = {
8585
cloudWallet?: {
8686
edvUrl: string;
8787
authKey: string;
88-
}
88+
};
89+
truveraApi?: {
90+
apiUrl: string;
91+
authKey: string;
92+
};
8993
};
9094

9195
export type AnyJSON = any;

0 commit comments

Comments
 (0)