diff --git a/integration-tests/delegatable-revocation.test.ts b/integration-tests/delegatable-revocation.test.ts index f46a225f..ed2c5d5d 100644 --- a/integration-tests/delegatable-revocation.test.ts +++ b/integration-tests/delegatable-revocation.test.ts @@ -68,8 +68,10 @@ describe('Delegatable Revocation', () => { ctx = { wallet: walletClient.wallet, issuerDID: walletClient.did, - truveraApiSponsorKey: SPONSOR_KEY as string, - apiUrl: API_URL as string, + truveraApiConfigs: { + authKey: SPONSOR_KEY as string, + apiUrl: API_URL as string, + }, }; }); diff --git a/packages/core/src/delegation/delegation-issuance.ts b/packages/core/src/delegation/delegation-issuance.ts index 0528a412..7d3a447c 100644 --- a/packages/core/src/delegation/delegation-issuance.ts +++ b/packages/core/src/delegation/delegation-issuance.ts @@ -42,7 +42,7 @@ export async function issueCredential( assert(recipientRole, `Role ${delegationRoleId} not found in ruleset`); - const credentialStatus = revocationContext + const credentialStatus = revocationContext?.truveraApiConfigs ? (await allocateStatusEntry(revocationContext)).credentialStatus : credentialData.credentialStatus; @@ -72,12 +72,14 @@ export async function delegateCredential({ delegationPolicy, delegationRoleId, delegatorDID, + revocationContext, }: { credential: any; wallet: any; delegationPolicy: DelegationPolicy; delegationRoleId: string; delegatorDID: string; + revocationContext?: RevocationContext; }) { assert(isDelegatableCredential(credential), 'Credential is not delegatable'); assert(!!delegatorDID, 'delegatorDID is required'); @@ -112,5 +114,6 @@ export async function delegateCredential({ delegationPolicy, delegationRoleId, credential.rootCredentialId || credential.id, + revocationContext, ); } diff --git a/packages/core/src/delegation/delegation-offer.ts b/packages/core/src/delegation/delegation-offer.ts index 056b8180..03d8c306 100644 --- a/packages/core/src/delegation/delegation-offer.ts +++ b/packages/core/src/delegation/delegation-offer.ts @@ -87,13 +87,20 @@ export async function createDelegationOffer({ isDelegatableCredential(parentCredential), `Credential ${credentialId} is not delegatable`, ); - const parentDetails = await getDelegationDetails(parentCredential, wallet); + const parentDetails = await getDelegationDetails( + parentCredential, + wallet, + ); if (parentDetails.delegationPolicy) { - assertPolicyConformsToParent(delegationPolicy, parentDetails.delegationPolicy, { - delegationRole, - remainingDepth: parentDetails.remainingDelegationDepth, - parentRoleId: parentDetails.role?.roleId, - }); + assertPolicyConformsToParent( + delegationPolicy, + parentDetails.delegationPolicy, + { + delegationRole, + remainingDepth: parentDetails.remainingDelegationDepth, + parentRoleId: parentDetails.role?.roleId, + }, + ); } } } @@ -149,8 +156,10 @@ export function createOOBInvitation( issuerDID: issuerDID, issuerName: finalIssuerName, role: delegationOffer.delegationRole, - roleLabel: getRole(delegationOffer.delegationRole, delegationOffer.delegationPolicy) - ?.label, + roleLabel: getRole( + delegationOffer.delegationRole, + delegationOffer.delegationPolicy, + )?.label, createdAt: delegationOffer.sentAt, expiresAt: delegationOffer.expiresAt, }; @@ -325,7 +334,10 @@ export const DELEGATION_REQUEST_HANDLER = { try { validateDelegationPolicy(delegationOffer.delegationPolicy); if (parentCredential && isDelegatableCredential(parentCredential)) { - const parentDetails = await getDelegationDetails(parentCredential, wallet); + const parentDetails = await getDelegationDetails( + parentCredential, + wallet, + ); if (parentDetails.delegationPolicy) { assertPolicyConformsToParent( delegationOffer.delegationPolicy, @@ -361,6 +373,11 @@ export const DELEGATION_REQUEST_HANDLER = { delegationPolicy: delegationOffer.delegationPolicy, delegationRoleId: delegationOffer.delegationRole, delegatorDID: delegationOffer.issuerDID || issuerDID, + revocationContext: { + wallet, + truveraApiConfigs: wallet.dataStore.configs?.truveraApi, + issuerDID: delegationOffer.issuerDID || issuerDID, + }, }); const delegationChain = await getDelegationChain(parentCredential, wallet); @@ -498,8 +515,8 @@ export const messageHandlers = [ export async function handleMessage( message, context: { - wallet; - messageProvider; + wallet: any; + messageProvider: any; }, ) { const decoded = decodeMessage(message); diff --git a/packages/core/src/delegation/delegation-revocation.ts b/packages/core/src/delegation/delegation-revocation.ts index 0d26e8f0..de989753 100644 --- a/packages/core/src/delegation/delegation-revocation.ts +++ b/packages/core/src/delegation/delegation-revocation.ts @@ -46,6 +46,11 @@ export interface StatusList2021Entry { statusListCredential: string; } +export interface TruveraApiConfigs { + authKey: string; + apiUrl: string; +} + /** * Common context for every signed revocation API call. * @@ -55,8 +60,7 @@ export interface StatusList2021Entry { export interface RevocationContext { wallet: IWallet; issuerDID: string; // the did:key that owns the registry / signs the JWT - truveraApiSponsorKey: string; - apiUrl: string; + truveraApiConfigs?: TruveraApiConfigs; } /** @@ -74,7 +78,7 @@ async function signRevocationJWT( const now = Math.floor(Date.now() / 1000); const payload = { - aud: ctx.apiUrl, + aud: ctx.truveraApiConfigs.apiUrl, iss: ctx.issuerDID, iat: now, exp: now + 120, @@ -97,16 +101,21 @@ async function postRevocation( registryId: string, body: Record, ): Promise { - assert(!!ctx.truveraApiSponsorKey, 'truveraApiSponsorKey is required'); + assert(!!ctx.truveraApiConfigs, 'truveraApiConfigs is required'); + assert(!!ctx.truveraApiConfigs.apiUrl, 'truveraApiConfigs.apiUrl is required'); + assert( + !!ctx.truveraApiConfigs.authKey, + 'truveraApiConfigs.authKey is required', + ); const jwt = await signRevocationJWT(ctx, {registryId, ...body}); try { const response = await axios.post( - `${ctx.apiUrl}/delegatable-revocations/${registryId}`, + `${ctx.truveraApiConfigs.apiUrl}/delegatable-revocations/${registryId}`, body, { headers: { - 'X-MOBILE-SPONSOR-KEY': ctx.truveraApiSponsorKey, + 'X-MOBILE-SPONSOR-KEY': ctx.truveraApiConfigs.authKey, Authorization: `Bearer ${jwt}`, 'Content-Type': 'application/json', }, diff --git a/packages/data-store/src/types.ts b/packages/data-store/src/types.ts index d2c3af38..6efb522f 100644 --- a/packages/data-store/src/types.ts +++ b/packages/data-store/src/types.ts @@ -85,7 +85,11 @@ export type DataStoreConfigs = { cloudWallet?: { edvUrl: string; authKey: string; - } + }; + truveraApi?: { + apiUrl: string; + authKey: string; + }; }; export type AnyJSON = any;