File tree Expand file tree Collapse file tree
packages/core/src/delegation Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { delegationPolicyTravelAgent } from './delegation-fixtures' ;
2+ import { createOOBInvitation , decodeMessage } from './delegation-offer' ;
3+
4+ const CORPORATE_ACCOUNT_MANAGER = '8e5abc88-7006-42ae-ae48-9e34f8f66124' ;
5+
6+ function getPreview ( offer ) {
7+ const url = createOOBInvitation ( 'did:issuer' , offer , { goal : 'delegate' } ) ;
8+ return decodeMessage ( url ) . attachments [ 0 ] . data . json ;
9+ }
10+
11+ describe ( 'createOOBInvitation roleLabel' , ( ) => {
12+ const baseOffer = {
13+ id : 'offer-1' ,
14+ issuerName : 'Issuer' ,
15+ delegationPolicy : delegationPolicyTravelAgent ,
16+ delegationRole : CORPORATE_ACCOUNT_MANAGER ,
17+ sentAt : '2026-01-01T00:00:00.000Z' ,
18+ expiresAt : '2026-01-02T00:00:00.000Z' ,
19+ } ;
20+
21+ it ( 'resolves roleLabel from the policy role' , ( ) => {
22+ const preview = getPreview ( baseOffer ) ;
23+ expect ( preview . role ) . toBe ( CORPORATE_ACCOUNT_MANAGER ) ;
24+ expect ( preview . roleLabel ) . toBe ( 'Corporate Account Manager' ) ;
25+ } ) ;
26+
27+ it ( 'leaves roleLabel undefined when the role is not in the policy' , ( ) => {
28+ const preview = getPreview ( { ...baseOffer , delegationRole : 'unknown-role-id' } ) ;
29+ expect ( preview . roleLabel ) . toBeUndefined ( ) ;
30+ } ) ;
31+ } ) ;
Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ import {logger} from '@docknetwork/wallet-sdk-data-store/src/logger';
44import { getAllDIDs , getDefaultDID } from '../did-provider' ;
55import { delegateCredential } from './delegation-issuance' ;
66import { getDelegationChain } from './delegation-chain' ;
7- import { getDelegationDetails } from './delegation-policy' ;
7+ import { getDelegationDetails , getRole } from './delegation-policy' ;
88import { isDelegatableCredential } from './delegation-utils' ;
99import {
1010 assertPolicyConformsToParent ,
@@ -52,6 +52,7 @@ export type DelegationOfferPreview = {
5252 issuerDID : string ;
5353 issuerName ?: string ;
5454 role : string ;
55+ roleLabel ?: string ;
5556 createdAt : string ;
5657 expiresAt ?: string ;
5758} ;
@@ -148,6 +149,8 @@ export function createOOBInvitation(
148149 issuerDID : issuerDID ,
149150 issuerName : finalIssuerName ,
150151 role : delegationOffer . delegationRole ,
152+ roleLabel : getRole ( delegationOffer . delegationRole , delegationOffer . delegationPolicy )
153+ ?. label ,
151154 createdAt : delegationOffer . sentAt ,
152155 expiresAt : delegationOffer . expiresAt ,
153156 } ;
You can’t perform that action at this time.
0 commit comments