Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions integration-tests/delegatable-revocation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
};
});

Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/delegation/delegation-issuance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -112,5 +114,6 @@ export async function delegateCredential({
delegationPolicy,
delegationRoleId,
credential.rootCredentialId || credential.id,
revocationContext,
);
}
39 changes: 28 additions & 11 deletions packages/core/src/delegation/delegation-offer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
);
}
}
}
Expand Down Expand Up @@ -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,
};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
},
Comment thread
maycon-mello marked this conversation as resolved.
});

const delegationChain = await getDelegationChain(parentCredential, wallet);
Expand Down Expand Up @@ -498,8 +515,8 @@ export const messageHandlers = [
export async function handleMessage(
message,
context: {
wallet;
messageProvider;
wallet: any;
messageProvider: any;
},
) {
const decoded = decodeMessage(message);
Expand Down
21 changes: 15 additions & 6 deletions packages/core/src/delegation/delegation-revocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export interface StatusList2021Entry {
statusListCredential: string;
}

export interface TruveraApiConfigs {
authKey: string;
apiUrl: string;
}

/**
* Common context for every signed revocation API call.
*
Expand All @@ -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;
}
Comment thread
maycon-mello marked this conversation as resolved.

/**
Expand All @@ -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,
Expand All @@ -97,16 +101,21 @@ async function postRevocation(
registryId: string,
body: Record<string, any>,
): Promise<any> {
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',
},
Expand Down
6 changes: 5 additions & 1 deletion packages/data-store/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,11 @@ export type DataStoreConfigs = {
cloudWallet?: {
edvUrl: string;
authKey: string;
}
};
truveraApi?: {
apiUrl: string;
authKey: string;
};
};

export type AnyJSON = any;
Expand Down
Loading