diff --git a/README.md b/README.md index c006389..59dd2a7 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,10 @@ -# qvi-ts - [![CI](https://github.com/GLEIF-IT/qvi-ts/actions/workflows/main.yml/badge.svg?branch=main)](https://github.com/GLEIF-IT/qvi-ts/actions/workflows/main.yml) +[![codecov](https://codecov.io/gh/GLEIF-IT/qvi-ts/graph/badge.svg?token=DKG7H94FLS)](https://codecov.io/gh/GLEIF-IT/qvi-ts) +[![Documentation](https://img.shields.io/badge/documentation-grey?)](https://gleif-it.github.io/qvi-ts/) -[![codecov](https://codecov.io/gh/m00sey/qvi-ts/graph/badge.svg?token=DKG7H94FLS)](https://codecov.io/gh/m00sey/qvi-ts) -[![Documentation](https://img.shields.io/badge/documentation-grey?)](https://gleif-it.github.io/qvi-ts/) +# qvi-ts +QVI SDK for the vLEI Ecosystem ### Development diff --git a/src/credentials.ts b/src/credentials.ts deleted file mode 100644 index 8e20f16..0000000 --- a/src/credentials.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { Saider } from 'signify-ts'; -import { Schema } from './schema'; - -export class LEvLEICredentialData { - readonly LEI: string; - - constructor(LEI: string) { - this.LEI = LEI; - } -} - -export class LEvLEICredentialEdge { - readonly d: string; - readonly qvi: QVIvLEIEdge; - - constructor(qviAID: string) { - this.qvi = new QVIvLEIEdge(qviAID); - // this needs to be better - this.d = Saider.saidify({ d: '', qvi: this.qvi })[1]['d']; - } -} - -export class QVIvLEIEdge { - n: string; - s: string; - - constructor(qviAID: string) { - this.n = qviAID; - this.s = Schema.QVI; - } -} - -export interface ECRvLEICredentialData { - i: string; - dt: string; - LEI: string; - personLegalName: string; - engagementContextRole: string; -} -export interface ECRAuthEdges { - d: string; - auth: ECRAuthEdge; -} -interface ECRAuthEdge { - n: string; //SAID of the ACDC to which the edge connects - s: 'EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g'; - o: 'I2I'; -} -export interface ECRLEEdges { - d: string; - le: ECRLEEdge; -} -interface ECRLEEdge { - n: string; //SAID of the ACDC to which the edge connects - s: 'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY'; -} - -export interface OORvLEICredential { - i: string; // issuer - dt: string; // date - LEI: string; // LEI - personLegalName: string; // person's legal name to which the role is assigned - officialRole: string; // TODO: find list of roles -} -export interface OORAuthEdges { - d: string; - auth: OORAuthEdge; -} -interface OORAuthEdge { - n: string; //SAID of the ACDC to which the edge connects - s: 'EKA57bKBKxr_kN7iN5i7lMUxpMG-s19dRcmov1iDxz-E'; - o: 'I2I'; -} diff --git a/src/index.ts b/src/index.ts index b9d80c1..209ffef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1 +1,2 @@ +export type AID = string; export * from './qvi/qvi'; diff --git a/src/le/credentials/ecr-auth.ts b/src/le/credentials/ecr-auth.ts new file mode 100644 index 0000000..095bf7a --- /dev/null +++ b/src/le/credentials/ecr-auth.ts @@ -0,0 +1,46 @@ +import { Saider } from 'signify-ts'; +import { AID } from '../../index'; + +export interface ECRAuthvLEICredentialArgs { + readonly qviAID: AID; + readonly timestamp: string; + readonly recipient: AID; + readonly LEI: string; + readonly personLegalName: string; + readonly engagementContextRole: string; +} + +export class ECRAuthvLEICredentialData { + readonly d: string; + readonly i: AID; + readonly dt: string; + readonly AID: AID; + readonly LEI: string; + readonly personLegalName: string; + readonly engagementContextRole: string; + + constructor({ + qviAID, + timestamp, + recipient, + LEI, + personLegalName, + engagementContextRole, + }: ECRAuthvLEICredentialArgs) { + this.i = qviAID; + this.dt = timestamp; + this.AID = recipient; + this.LEI = LEI; + this.personLegalName = personLegalName; + this.engagementContextRole = engagementContextRole; + this.d = Saider.saidify({ + d: '', + i: this.i, + dt: this.dt, + AID: this.AID, + LEI: this.LEI, + personLegalName: this.personLegalName, + officialOrganizationalRole: this.engagementContextRole, + })[1]['d']; + } +} diff --git a/src/le/credentials/oor-auth.ts b/src/le/credentials/oor-auth.ts new file mode 100644 index 0000000..f386312 --- /dev/null +++ b/src/le/credentials/oor-auth.ts @@ -0,0 +1,46 @@ +import { Saider } from 'signify-ts'; +import { AID } from '../../index'; + +export interface OORAuthvLEICredentialArgs { + readonly qviAID: AID; + readonly timestamp: string; + readonly recipient: AID; + readonly LEI: string; + readonly personLegalName: string; + readonly officialOrganizationalRole: string; +} + +export class OORAuthvLEICredentialData { + readonly d: string; + readonly i: AID; + readonly dt: string; + readonly AID: AID; + readonly LEI: string; + readonly personLegalName: string; + readonly officialOrganizationalRole: string; + + constructor({ + qviAID, + timestamp, + recipient, + LEI, + personLegalName, + officialOrganizationalRole, + }: OORAuthvLEICredentialArgs) { + this.i = qviAID; + this.dt = timestamp; + this.AID = recipient; + this.LEI = LEI; + this.personLegalName = personLegalName; + this.officialOrganizationalRole = officialOrganizationalRole; + this.d = Saider.saidify({ + d: '', + i: this.i, + dt: this.dt, + AID: this.AID, + LEI: this.LEI, + personLegalName: this.personLegalName, + officialOrganizationalRole: this.officialOrganizationalRole, + })[1]['d']; + } +} diff --git a/src/le/le.ts b/src/le/le.ts new file mode 100644 index 0000000..4c72754 --- /dev/null +++ b/src/le/le.ts @@ -0,0 +1,88 @@ +import { SignifyClient } from 'signify-ts'; +import { Schema } from '../schema'; +import { Rules } from '../rules'; +import { ECRAuthvLEICredentialData } from './credentials/ecr-auth'; +import { ECRAuthEdge } from '../qvi/credentials/ecr'; +import { AID } from '..'; +import { OORAuthvLEICredentialData } from './credentials/oor-auth'; +import { OORAuthEdge } from '../qvi/credentials/oor'; + +type qb64 = string; + +export class LE { + private readonly client: SignifyClient; + private readonly name: string; + private readonly registryAID: qb64; + + /** + * LE + * + * Class for performing LE as a QVI opertations: + * + * - Issue Engagement Context Role Auth Credential + * - Issue Official Organizational Role Auth Credential + * + * @param client + * @param name + * @param registryAID + */ + constructor(client: SignifyClient, name: string, registryAID: qb64) { + this.client = client; + this.name = name; + this.registryAID = registryAID; + } + + /** + * Create ECR Auth Credential + * + * @param {AID} issuee AID of QVI + * @param {ECRAuthvLEICredentialData} data + * @param {ECRAuthEdge} edge} + * @returns + */ + public async createECRAuthCredential( + issuee: AID, + data: ECRAuthvLEICredentialData, + edge: ECRAuthEdge + ) { + return await this.client + .credentials() + .issue( + this.name, + this.registryAID, + Schema.ECRAuth, + issuee, + data, + Rules.ECRAuth, + edge, + false + ); + } + + /** + * Create OOR Auth Credential + * + * @param {AID} issuee AID of QVI + * @param {OORAuthvLEICredentialData} data + * @param {OORAuthEdge} edge} + * @returns + */ + public async createOORAuthCredential( + issuee: AID, + data: OORAuthvLEICredentialData, + edge: OORAuthEdge + ) { + return await this.client + .credentials() + .issue( + this.name, + this.registryAID, + Schema.OORAuth, + issuee, + data, + Rules.OORAuth, + edge, + false + ); + } +} diff --git a/src/qvi/credentials/ecr.ts b/src/qvi/credentials/ecr.ts new file mode 100644 index 0000000..37a1241 --- /dev/null +++ b/src/qvi/credentials/ecr.ts @@ -0,0 +1,75 @@ +import { Saider } from 'signify-ts'; +import { Schema } from '../../schema'; +import { AID } from '../..'; + +export interface ECRvLEICredentialDataArgs { + nonce: string; + issuee: AID; + timestamp: string; + LEI: string; + personLegalName: string; + engagementContextRole: string; +} + +export class ECRvLEICredentialData { + readonly d: string; + readonly u: string; + readonly i: string; + readonly dt: string; + readonly LEI: string; + readonly personLegalName: string; + readonly engagementContextRole: string; + + constructor({ + nonce, + issuee, + timestamp, + LEI, + personLegalName, + engagementContextRole, + }: ECRvLEICredentialDataArgs) { + this.u = nonce; + this.i = issuee; + this.dt = timestamp; + this.LEI = LEI; + this.personLegalName = personLegalName; + this.engagementContextRole = engagementContextRole; + this.d = Saider.saidify({ + d: '', + u: this.u, + i: this.i, + dt: this.dt, + LEI: this.LEI, + personLegalName: this.personLegalName, + engagementContextRole: this.engagementContextRole, + })[1]['d']; + } +} + +export interface ECRAuthEdgeArgs { + auth: ECRAuthvLEIEdgeData; +} + +export class ECRAuthEdge { + readonly d: string; + readonly auth: ECRAuthvLEIEdgeData; + + constructor({ auth }: ECRAuthEdgeArgs) { + this.d = Saider.saidify({ d: '', auth: auth })[1]['d']; + this.auth = auth; + } +} + +export interface ECRAuthvLEIEdgeDataArgs { + legalEntity: AID; +} + +export class ECRAuthvLEIEdgeData { + readonly n: string; // SAID of the the issuing LEs Legal Entity vLEI Credential + readonly s: string = Schema.LE; + readonly o: string = 'I2I'; + + constructor({ legalEntity }: ECRAuthvLEIEdgeDataArgs) { + this.n = legalEntity; + } +} diff --git a/src/qvi/credentials/le.ts b/src/qvi/credentials/le.ts new file mode 100644 index 0000000..51b6a46 --- /dev/null +++ b/src/qvi/credentials/le.ts @@ -0,0 +1,38 @@ +import { Saider } from 'signify-ts'; +import { QVIvLEIEdge } from '../qvi'; +import { AID } from '../..'; + +export interface LEvLEICredentialDataArgs { + readonly issuee: AID; + readonly timestamp: string; + readonly LEI: string; +} + +export class LEvLEICredentialData { + readonly d: string; + readonly i: AID; + readonly dt: string; + readonly LEI: string; + + constructor({ issuee, timestamp, LEI }: LEvLEICredentialDataArgs) { + this.i = issuee; + this.dt = timestamp; + this.LEI = LEI; + this.d = Saider.saidify({ + d: '', + i: this.i, + dt: this.dt, + LEI: this.LEI, + })[1]['d']; + } +} + +export class LEvLEICredentialEdge { + readonly d: string; + readonly qvi: QVIvLEIEdge; + + constructor(qviAID: string) { + this.qvi = new QVIvLEIEdge(qviAID); + this.d = Saider.saidify({ d: '', qvi: this.qvi })[1]['d']; + } +} diff --git a/src/qvi/credentials/oor.ts b/src/qvi/credentials/oor.ts new file mode 100644 index 0000000..b9bfbc0 --- /dev/null +++ b/src/qvi/credentials/oor.ts @@ -0,0 +1,75 @@ +import { Saider } from 'signify-ts'; +import { Schema } from '../../schema'; +import { AID } from '../..'; + +export interface OORvLEICredentialDataArgs { + nonce: string; + issuee: AID; + timestamp: string; + LEI: string; + personLegalName: string; + officialOrganizationalRole: string; +} + +export class OORvLEICredentialData { + readonly d: string; + readonly u: string; + readonly i: string; + readonly dt: string; + readonly LEI: string; + readonly personLegalName: string; + readonly officialOrganizationalRole: string; + + constructor({ + nonce, + issuee, + timestamp, + LEI, + personLegalName, + officialOrganizationalRole, + }: OORvLEICredentialDataArgs) { + this.u = nonce; + this.i = issuee; + this.dt = timestamp; + this.LEI = LEI; + this.personLegalName = personLegalName; + this.officialOrganizationalRole = officialOrganizationalRole; + this.d = Saider.saidify({ + d: '', + u: this.u, + i: this.i, + dt: this.dt, + LEI: this.LEI, + personLegalName: this.personLegalName, + engagementContextRole: this.officialOrganizationalRole, + })[1]['d']; + } +} + +export interface OORAuthEdgeArgs { + auth: OORAuthvLEIEdgeData; +} + +export class OORAuthEdge { + readonly d: string; + readonly auth: OORAuthvLEIEdgeData; + + constructor({ auth }: OORAuthEdgeArgs) { + this.d = Saider.saidify({ d: '', auth: auth })[1]['d']; + this.auth = auth; + } +} + +export interface OORAuthvLEIEdgeDataArgs { + legalEntity: AID; +} + +export class OORAuthvLEIEdgeData { + readonly n: string; // SAID of the the issuing LEs Legal Entity vLEI Credential + readonly s: string = Schema.LE; + readonly o: string = 'I2I'; + + constructor({ legalEntity }: OORAuthvLEIEdgeDataArgs) { + this.n = legalEntity; + } +} diff --git a/src/qvi/qvi.ts b/src/qvi/qvi.ts index db3f6d5..a6a254f 100644 --- a/src/qvi/qvi.ts +++ b/src/qvi/qvi.ts @@ -1,15 +1,19 @@ import { SignifyClient, Siger, messagize, d } from 'signify-ts'; import { getAgentOperationResult, sendAgentMessage } from '../operations'; import { Schema } from '../schema'; -import { LEvLEICredentialData, LEvLEICredentialEdge } from '../credentials'; import { Rules } from '../rules'; +import { LEvLEICredentialData, LEvLEICredentialEdge } from './credentials/le'; +import { ECRAuthvLEIEdgeData, ECRvLEICredentialData } from './credentials/ecr'; +import { OORvLEICredentialData } from './credentials/oor'; +import { OORAuthvLEICredentialData } from '../le/credentials/oor-auth'; +import { AID } from '..'; type qb64 = string; export class QVI { private readonly client: SignifyClient; private readonly name: string; - private readonly registryAID: qb64; + private readonly registry: qb64; /** * QVI @@ -21,14 +25,14 @@ export class QVI { * - Issue Engagement Context Role Credential * - Issue Official Organizational Role Credential * - * @param client - * @param name - * @param registryAID + * @param {SignifyClient} client + * @param {string} name + * @param {qb64} registry */ - constructor(client: SignifyClient, name: string, registryAID: qb64) { + constructor(client: SignifyClient, name: string, registry: qb64) { this.client = client; this.name = name; - this.registryAID = registryAID; + this.registry = registry; } /** @@ -36,26 +40,21 @@ export class QVI { * * QVIs are required to be mutltisig groups by the vLEI Ecosystem Governance Framework * - * @param qviAID - * @param issuee - * @param credentialData + * @param {AID} issuee + * @param {LEvLEICredentialData} data + * @param {LEvLEICredentialEdge} edge} * @returns */ public async createLegalEntityCredential( - qviAID: qb64, - issuee: qb64, - LEI: string + issuee: AID, + data: LEvLEICredentialData, + edge: LEvLEICredentialEdge ) { - let data = new LEvLEICredentialData(LEI); - let edge = new LEvLEICredentialEdge(qviAID); - - // replace with signify-ts credential create - // should always called with a group AID to create the EXN (signify-ts) and send to others return await this.client .credentials() .issue( this.name, - this.registryAID, + this.registry, Schema.LE, issuee, data, @@ -65,6 +64,60 @@ export class QVI { ); } + /** + * Create Engagement Context Role Credential + * + * @param {AID} issuee + * @param {ECRvLEICredentialData} data + * @param {ECRAuthvLEIEdgeData} edge + * @returns + */ + public async createEngagementContextRoleCredential( + issuee: AID, + data: ECRvLEICredentialData, + edge: ECRAuthvLEIEdgeData + ) { + return await this.client + .credentials() + .issue( + this.name, + this.registry, + Schema.ECR, + issuee, + data, + Rules.ECR, + edge, + false + ); + } + + /** + * Create Official Organizational Role Credential + * + * @param {AID} issuee + * @param {OORvLEICredentialData}data`` + * @param {OORAuthvLEICredentialData} edge + * @returns + */ + public async createOfficialOrganizationRoleCredential( + issuee: AID, + data: OORvLEICredentialData, + edge: OORAuthvLEICredentialData + ) { + return await this.client + .credentials() + .issue( + this.name, + this.registry, + Schema.OOR, + issuee, + data, + Rules.OOR, + edge, + false + ); + } + public async sendLegalEntityCredential( alias: string, recipient: string, @@ -116,3 +169,13 @@ export class QVI { ); } } + +export class QVIvLEIEdge { + n: string; + s: string; + + constructor(qviAID: string) { + this.n = qviAID; + this.s = Schema.QVI; + } +} diff --git a/test/credentials.test.ts b/test/credentials.test.ts deleted file mode 100644 index 6b3c931..0000000 --- a/test/credentials.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { describe, expect, it } from '@jest/globals'; - -describe('credentials', () => { - it('should have a QVIvLEIEdge', () => { - expect(true).toBe(true); - }); -}); diff --git a/test/le/credentials/ecr-auth.test.ts b/test/le/credentials/ecr-auth.test.ts new file mode 100644 index 0000000..053f37c --- /dev/null +++ b/test/le/credentials/ecr-auth.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, it } from '@jest/globals'; +import { ECRAuthvLEICredentialData } from '../../../src/le/credentials/ecr-auth'; + +describe('le credentials', () => { + it('should create ecr auth edge', () => { + let auth = new ECRAuthvLEICredentialData({ + qviAID: 'qvi_aid', + timestamp: 'timestamp', + recipient: 'recipient', + LEI: 'an LEI', + personLegalName: 'My Legal Name', + engagementContextRole: 'my context role', + }); + + expect(auth.d).toBe('EB9QkDZJW5iS2vyiTJQ1lVAo1qImK_HteOXaZE9aQRjG'); + expect(auth.i).toBe('qvi_aid'); + expect(auth.dt).toBe('timestamp'); + expect(auth.LEI).toBe('an LEI'); + expect(auth.personLegalName).toBe('My Legal Name'); + expect(auth.engagementContextRole).toBe('my context role'); + }); +}); diff --git a/test/le/credentials/oor-auth.test.ts b/test/le/credentials/oor-auth.test.ts new file mode 100644 index 0000000..42c3b4a --- /dev/null +++ b/test/le/credentials/oor-auth.test.ts @@ -0,0 +1,22 @@ +import { describe, expect, it } from '@jest/globals'; +import { OORAuthvLEICredentialData } from '../../../src/le/credentials/oor-auth'; + +describe('le credentials', () => { + it('should create ecr auth edge', () => { + let auth = new OORAuthvLEICredentialData({ + qviAID: 'qvi_aid', + timestamp: 'timestamp', + recipient: 'recipient', + LEI: 'an LEI', + personLegalName: 'My Legal Name', + officialOrganizationalRole: 'my official role', + }); + + expect(auth.d).toBe('EKfY9zJk7F3KqOESHCLOf0HKofNfeigKveDMy-3QQGNt'); + expect(auth.i).toBe('qvi_aid'); + expect(auth.dt).toBe('timestamp'); + expect(auth.LEI).toBe('an LEI'); + expect(auth.personLegalName).toBe('My Legal Name'); + expect(auth.officialOrganizationalRole).toBe('my official role'); + }); +}); diff --git a/test/le/le.test.ts b/test/le/le.test.ts new file mode 100644 index 0000000..a891da1 --- /dev/null +++ b/test/le/le.test.ts @@ -0,0 +1,117 @@ +import { SignifyClient, Credentials } from 'signify-ts'; +import { describe, expect, it } from '@jest/globals'; +import { anyOfClass, capture, instance, mock, verify, when } from 'ts-mockito'; +import { LE } from '../../src/le/le'; +import { ECRAuthvLEICredentialData } from '../../src/le/credentials/ecr-auth'; +import { + ECRAuthEdge, + ECRAuthvLEIEdgeData, +} from '../../src/qvi/credentials/ecr'; +import { Rules } from '../../src/rules'; +import { OORAuthvLEICredentialData } from '../../src/le/credentials/oor-auth'; +import { + OORAuthEdge, + OORAuthvLEIEdgeData, +} from '../../src/qvi/credentials/oor'; + +describe('a legal entity', () => { + it('should create ecr auth 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, 'qvi_name', 'qvi_registry_aid'); + + let data = new ECRAuthvLEICredentialData({ + qviAID: 'qvi_aid', + timestamp: 'timestamp', + recipient: 'recipient', + LEI: 'lei', + personLegalName: 'my legal name', + engagementContextRole: 'context role', + }); + let auth = new ECRAuthvLEIEdgeData({ legalEntity: 'legal_entity_aid' }); + let edge = new ECRAuthEdge({ auth: auth }); + + le.createECRAuthCredential('issuee aid', data, edge); + + let cap = capture(c.issue).last(); + + verify( + c.issue( + 'qvi_name', + 'qvi_registry_aid', + 'EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g', + 'issuee aid', + anyOfClass(ECRAuthvLEICredentialData), + Rules.ECRAuth, + anyOfClass(ECRAuthEdge), + false + ) + ).once(); + + let DATA_ARG = 4; + expect(cap[DATA_ARG].LEI).toBe('lei'); + + let EDGE_ARG = 6; + expect(cap[EDGE_ARG].d).toBe( + 'ED1dQiXEfyqMu2sh1zz7RMv5GP4g5b8YGMLrNdIht-TP' + ); + expect(cap[EDGE_ARG].auth.n).toBe('legal_entity_aid'); + expect(cap[EDGE_ARG].auth.s).toBe( + 'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY' + ); + }); + + it('should create oor auth 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, 'qvi_name', 'qvi_registry_aid'); + + let data = new OORAuthvLEICredentialData({ + qviAID: 'qvi_aid', + timestamp: 'timestamp', + recipient: 'recipient', + LEI: 'lei', + personLegalName: 'my legal name', + officialOrganizationalRole: 'official role', + }); + let auth = new OORAuthvLEIEdgeData({ legalEntity: 'legal_entity_aid' }); + let edge = new OORAuthEdge({ auth: auth }); + + le.createOORAuthCredential('issuee aid', data, edge); + + let cap = capture(c.issue).last(); + + verify( + c.issue( + 'qvi_name', + 'qvi_registry_aid', + 'EKA57bKBKxr_kN7iN5i7lMUxpMG-s19dRcmov1iDxz-E', + 'issuee aid', + anyOfClass(OORAuthvLEICredentialData), + Rules.OORAuth, + anyOfClass(OORAuthEdge), + false + ) + ).once(); + + let DATA_ARG = 4; + expect(cap[DATA_ARG].LEI).toBe('lei'); + + let EDGE_ARG = 6; + expect(cap[EDGE_ARG].d).toBe( + 'ED1dQiXEfyqMu2sh1zz7RMv5GP4g5b8YGMLrNdIht-TP' + ); + expect(cap[EDGE_ARG].auth.n).toBe('legal_entity_aid'); + expect(cap[EDGE_ARG].auth.s).toBe( + 'ENPXp1vQzRF6JwIuS-mp2U8Uf1MoADoP_GqQ62VsDZWY' + ); + }); +}); diff --git a/test/qvi.test.ts b/test/qvi.test.ts index 2a6caae..4ed4a94 100644 --- a/test/qvi.test.ts +++ b/test/qvi.test.ts @@ -2,8 +2,11 @@ import { SignifyClient, Credentials } from 'signify-ts'; import { describe, expect, it } from '@jest/globals'; import { anyOfClass, capture, instance, mock, verify, when } from 'ts-mockito'; import { QVI } from '../src'; -import { LEvLEICredentialData, LEvLEICredentialEdge } from '../src/credentials'; import { Rules } from '../src/rules'; +import { + LEvLEICredentialData, + LEvLEICredentialEdge, +} from '../src/qvi/credentials/le'; describe('a qvi', () => { it('should create legal entity credential', () => { @@ -14,8 +17,10 @@ describe('a qvi', () => { let client = instance(mockedClient); let qvi = new QVI(client, 'qvi_name', 'qvi_registry_aid'); + let data = new LEvLEICredentialData({LEI: 'an LEI', issuee: 'issuee', timestamp: 'timestamp'}); + let edge = new LEvLEICredentialEdge('qvi_aid'); - qvi.createLegalEntityCredential('qvi aid', 'issuee aid', 'an LEI'); + qvi.createLegalEntityCredential('issuee aid', data, edge); let cap = capture(c.issue).last(); @@ -37,9 +42,9 @@ describe('a qvi', () => { let EDGE_ARG = 6; expect(cap[EDGE_ARG].d).toBe( - 'ENGyJEXhLMmS9UWNVmvDFfj95cvC1RCbomQHy-7bQrn8' + 'EPfoOyfjSMVJhdiuq1wlcHR1XB7KMrgzziWZqL0iYWyZ' ); - expect(cap[EDGE_ARG].qvi.n).toBe('qvi aid'); + expect(cap[EDGE_ARG].qvi.n).toBe('qvi_aid'); expect(cap[EDGE_ARG].qvi.s).toBe( 'EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao' ); diff --git a/test/qvi/credentials/ecr.test.ts b/test/qvi/credentials/ecr.test.ts new file mode 100644 index 0000000..778c4f9 --- /dev/null +++ b/test/qvi/credentials/ecr.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from '@jest/globals'; +import { ECRvLEICredentialData } from '../../../src/qvi/credentials/ecr'; + +describe('ecr credentials', () => { + it('should create ecr data', () => { + let data = new ECRvLEICredentialData({ + issuee: 'issuee', + nonce: 'a nonce', + timestamp: 'timestamp', + LEI: 'lei', + personLegalName: 'my legal name', + engagementContextRole: 'my context role', + }); + + expect(data.d).toBe('EJe2I27_e020_auO5pesYn7B23Ckdx2Cwu0kol4X-6zg'); + expect(data.u).toBe('a nonce'); + expect(data.i).toBe('issuee'); + expect(data.dt).toBe('timestamp'); + expect(data.LEI).toBe('lei'); + expect(data.personLegalName).toBe('my legal name'); + expect(data.engagementContextRole).toBe('my context role'); + }); +}); diff --git a/test/qvi/credentials/le.test.ts b/test/qvi/credentials/le.test.ts new file mode 100644 index 0000000..7fd8be8 --- /dev/null +++ b/test/qvi/credentials/le.test.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from '@jest/globals'; +import { LEvLEICredentialData } from '../../../src/qvi/credentials/le'; + +describe('ecr credentials', () => { + it('should create ecr data', () => { + let data = new LEvLEICredentialData({ + issuee: 'issuee', + timestamp: 'timestamp', + LEI: 'lei', + }); + + expect(data.d).toBe('EN04IEg4A-w_CN8-hb2YfZsl9k7pyH9uUOYJR2rhbWKn'); + expect(data.i).toBe('issuee'); + expect(data.dt).toBe('timestamp'); + expect(data.LEI).toBe('lei'); + }); +}); diff --git a/test/qvi/credentials/oor.test.ts b/test/qvi/credentials/oor.test.ts new file mode 100644 index 0000000..4079f0a --- /dev/null +++ b/test/qvi/credentials/oor.test.ts @@ -0,0 +1,23 @@ +import { describe, expect, it } from '@jest/globals'; +import { OORvLEICredentialData } from '../../../src/qvi/credentials/oor'; + +describe('ecr credentials', () => { + it('should create ecr data', () => { + let data = new OORvLEICredentialData({ + issuee: 'issuee', + nonce: 'a nonce', + timestamp: 'timestamp', + LEI: 'lei', + personLegalName: 'my legal name', + officialOrganizationalRole: 'my official role', + }); + + expect(data.d).toBe('EE-zF66f5qGrWfG5vnLH57gI0qcKqgV-PWxup_ctAjUy'); + expect(data.u).toBe('a nonce'); + expect(data.i).toBe('issuee'); + expect(data.dt).toBe('timestamp'); + expect(data.LEI).toBe('lei'); + expect(data.personLegalName).toBe('my legal name'); + expect(data.officialOrganizationalRole).toBe('my official role'); + }); +});