Skip to content
This repository has been archived by the owner on May 29, 2024. It is now read-only.

Direct issuance of ECR vLEI credential by a legal entity #20

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
60 changes: 60 additions & 0 deletions src/edges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
27 changes: 27 additions & 0 deletions src/le.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>} A promise to the long-running operation
*/
public async createDirectEngagementContextRoleCredential(
issuee: AID,
data: credentials.EngagementContextRoleCredentialData,
edge: edges.DirectEngagementContextRoleCredentialEdge
): Promise<any> {
return await this.client
.credentials()
.issue(
this.name,
this.registryAID,
schema.ECR,
issuee,
data,
rules.ECR,
edge,
true
);
}
}
15 changes: 15 additions & 0 deletions test/edges.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
54 changes: 54 additions & 0 deletions test/le.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});
});