diff --git a/src/edges.ts b/src/edges.ts index 1038ac0..876d7e5 100644 --- a/src/edges.ts +++ b/src/edges.ts @@ -120,6 +120,66 @@ namespace edges { } } + /** + * DirectEngagementContextRoleEdgeArgs + * + * Parameters for {@link DirectEngagementContextRoleCredentialEdge} + * + * @property {le DirectEngagementContextRoleCredentialEdgeData} data for the edge + */ + export interface DirectEngagementContextRoleCredentialEdgeArgs { + le: DirectEngagementContextRoleCredentialEdgeData; + } + + /** + * DirectEngagementContextRoleEdge + * + * Used as edge property for {@link createDirectEngagementContextRoleCredential} + * + * @property {d string} digest of {@link DirectEngagementContextRoleCredentialEdge} block + * @property {le DirectEngagementContextRoleCredentialEdgeData} nested block of {@link DirectEngagementContextRoleEdgeData} + */ + export class DirectEngagementContextRoleCredentialEdge { + readonly d: string; + readonly le: DirectEngagementContextRoleCredentialEdgeData; + + constructor({ le }: DirectEngagementContextRoleCredentialEdgeArgs) { + this.d = Saider.saidify({ d: '', le: le })[1]['d']; + this.le = le; + } + } + + /** + * DirectEngagementContextRoleCredentialEdgeDataArgs + * + * Parameters for {@link DirectEngagementContextRoleCredentialEdgeData} + * + * @property {legalEntityCredentialSAID string} SAID of previously issued Legal Entity credential + */ + export interface DirectEngagementContextRoleCredentialEdgeDataArgs { + legalEntityCredentialSAID: string; + } + + /** + * DirectEngagementContextRoleCredentialEdgeData + * + * Nested property for {@link DirectEngagementContextRoleCredentialEdge} + * + * @property {n string} SAID of previously issued Legal Entity credential + * @property {s string} SAID of Legal Entity credential schema + */ + export class DirectEngagementContextRoleCredentialEdgeData { + n: string; + s: string; + + constructor({ + legalEntityCredentialSAID, + }: DirectEngagementContextRoleCredentialEdgeDataArgs) { + this.n = legalEntityCredentialSAID; + this.s = schema.LE; + } + } + /** * EngagementContextRoleAuthorizationEdgeArgs * diff --git a/src/le.ts b/src/le.ts index 250f5bc..28b0d97 100644 --- a/src/le.ts +++ b/src/le.ts @@ -83,4 +83,31 @@ export class LE { false ); } + + /** + * Create Engagement Context Role Credential directly from LE + * + * @param {AID} issuee + * @param {credentials.EngagementContextRoleCredentialData} data + * @param {edges.DirectEngagementContextRoleCredentialEdge} edge + * @returns {Promise} A promise to the long-running operation + */ + public async createDirectEngagementContextRoleCredential( + issuee: AID, + data: credentials.EngagementContextRoleCredentialData, + edge: edges.DirectEngagementContextRoleCredentialEdge + ): Promise { + return await this.client + .credentials() + .issue( + this.name, + this.registryAID, + schema.ECR, + issuee, + data, + rules.ECR, + edge, + true + ); + } } diff --git a/test/edges.test.ts b/test/edges.test.ts index 5016537..e5c9bd2 100644 --- a/test/edges.test.ts +++ b/test/edges.test.ts @@ -30,6 +30,21 @@ describe('edges', () => { expect(edge.auth.s).toBe(schema.ECRAuth); }); + it('should create direct engagement context role credential edge', () => { + let data = new edges.DirectEngagementContextRoleCredentialEdgeData({ + legalEntityCredentialSAID: + 'my ecr auth credential said', + }); + + let edge = new edges.DirectEngagementContextRoleCredentialEdge({ + le: data, + }); + + expect(edge.d).toBe('EFmitYRo5Dgijnr0rtQ0QW0A-MGPxozV3e4F6BUSVWSR'); + expect(edge.le.n).toBe('my ecr auth credential said'); + expect(edge.le.s).toBe(schema.LE); + }); + it('should create official organizational role credential edge', () => { let data = new edges.OfficialOrganizationalRoleCredentialEdgeData({ officialOrganizationalRoleAuthorizationCredentialSAID: diff --git a/test/le.test.ts b/test/le.test.ts index 0776392..2f72791 100644 --- a/test/le.test.ts +++ b/test/le.test.ts @@ -122,4 +122,58 @@ describe('a legal entity', () => { 'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY' ); }); + + it('should create direct engagement context role credential', () => { + let mockedClient: SignifyClient = mock(SignifyClient); + + let c: Credentials = mock(Credentials); + when(mockedClient.credentials()).thenReturn(instance(c)); + + let client = instance(mockedClient); + let le = new LE(client, 'le_name', 'le_registry_aid'); + let data = new credentials.EngagementContextRoleCredentialData({ + issuee: 'issuee', + nonce: 'nonce', + timestamp: 'timestamp', + LEI: 'an LEI', + personLegalName: 'person legal name', + engagementContextRole: 'my context role', + }); + let edgeData = + new edges.DirectEngagementContextRoleCredentialEdgeData({ + legalEntityCredentialSAID: 'a SAID', + }); + let edge = new edges.DirectEngagementContextRoleCredentialEdge({ + le: edgeData, + }); + + le.createDirectEngagementContextRoleCredential('issuee aid', data, edge); + + let cap = capture(c.issue).last(); + + verify( + c.issue( + 'le_name', + 'le_registry_aid', + 'EEy9PkikFcANV1l7EHukCeXqrzT1hNZjGlUk7wuMO5jw', + 'issuee aid', + anyOfClass(credentials.EngagementContextRoleCredentialData), + rules.ECR, + anyOfClass(edges.DirectEngagementContextRoleCredentialEdge), + true + ) + ).once(); + + let DATA_ARG = 4; + expect(cap[DATA_ARG].LEI).toBe('an LEI'); + + let EDGE_ARG = 6; + expect(cap[EDGE_ARG].d).toBe( + 'ECz2B-zXe2GADR_sZ9WEjaf1WXPKcOBBdW6Qeb6TIkoA' + ); + expect(cap[EDGE_ARG].le.n).toBe('a SAID'); + expect(cap[EDGE_ARG].le.s).toBe( + 'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY' + ); + }); });