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

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Kevin Griffin <[email protected]>
  • Loading branch information
m00sey committed Oct 2, 2023
1 parent 3811bd8 commit f53660b
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 33 deletions.
26 changes: 12 additions & 14 deletions src/le/le.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ import { SignifyClient } from 'signify-ts';
import { Schema } from '../schema';
import { Rules } from '../rules';
import { ECRAuthvLEICredentialData } from './credentials/ecr-auth';
import { ECRAuthEdges } from '../qvi/credentials/ecr';
import { AID, QVIvLEIEdge } from '..';
import {
LEvLEICredentialData,
LEvLEICredentialEdge,
} from '../qvi/credentials/le';
import { ECRAuthEdge } from '../qvi/credentials/ecr';
import { AID } from '..';
import { OORAuthvLEICredentialData } from './credentials/oor-auth';
import { OORAuthEdge } from '../qvi/credentials/oor';

type qb64 = string;

Expand Down Expand Up @@ -39,13 +37,13 @@ export class LE {
*
* @param {AID} issuee AID of QVI
* @param {ECRAuthvLEICredentialData} data
* @param {QVIvLEIEdge} edge}
* @param {ECRAuthEdge} edge}
* @returns
*/
public async createECRAuthCredential(
issuee: AID,
data: ECRAuthvLEICredentialData,
edge: ECRAuthEdges
edge: ECRAuthEdge
) {
return await this.client
.credentials()
Expand All @@ -65,24 +63,24 @@ export class LE {
* Create OOR Auth Credential
*
* @param {AID} issuee AID of QVI
* @param {LEvLEICredentialData} data
* @param {LEvLEICredentialEdge} edge}
* @param {OORAuthvLEICredentialData} data
* @param {OORAuthEdge} edge}
* @returns
*/
public async createOORAuthCredential(
issuee: AID,
data: LEvLEICredentialData,
edge: LEvLEICredentialEdge
data: OORAuthvLEICredentialData,
edge: OORAuthEdge
) {
return await this.client
.credentials()
.issue(
this.name,
this.registryAID,
Schema.LE,
Schema.OORAuth,
issuee,
data,
Rules.LE,
Rules.OORAuth,
edge,
false
);
Expand Down
26 changes: 18 additions & 8 deletions src/qvi/credentials/ecr.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { Saider } from 'signify-ts';
import { Schema } from '../../schema';
import { AID } from '../..';

export class ECRvLEICredentialData {
readonly LEI: string;
Expand All @@ -16,22 +18,30 @@ export class ECRvLEICredentialData {
}
}

export class ECRAuthEdges {
export interface ECRAuthEdgeArgs {
auth: ECRAuthvLEIEdgeData;
}

export class ECRAuthEdge {
readonly d: string;
readonly auth: ECRvLEIAuthEdge;
readonly auth: ECRAuthvLEIEdgeData;

constructor(auth: ECRvLEIAuthEdge) {
constructor({ auth }: ECRAuthEdgeArgs) {
this.d = Saider.saidify({ d: '', auth: auth })[1]['d'];
this.auth = auth;
}
}

export class ECRvLEIAuthEdge {
readonly n: string; // AID of the issuing Legal Entity
readonly s: string = 'EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g';
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(legalEntityAID: string) {
this.n = legalEntityAID;
constructor({ legalEntity }: ECRAuthvLEIEdgeDataArgs) {
this.n = legalEntity;
}
}
33 changes: 25 additions & 8 deletions src/qvi/credentials/oor.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { Saider } from 'signify-ts';
import { Schema } from '../../schema';
import { AID } from '../..';

export class OORvLEICredentialData {
readonly LEI: string;
readonly personLegalName: string;
Expand All @@ -14,17 +18,30 @@ export class OORvLEICredentialData {
}
}

export interface OORAuthEdges {
d: string;
auth: OORvLEIAuthEdge;
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 OORvLEIAuthEdge {
readonly n: string; // AID of the issuing Legal Entity
readonly s: string = 'EKA57bKBKxr_kN7iN5i7lMUxpMG-s19dRcmov1iDxz-E';
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(legalEntityAID: string) {
this.n = legalEntityAID;
constructor({ legalEntity }: OORAuthvLEIEdgeDataArgs) {
this.n = legalEntity;
}
}
6 changes: 3 additions & 3 deletions src/qvi/qvi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { getAgentOperationResult, sendAgentMessage } from '../operations';
import { Schema } from '../schema';
import { Rules } from '../rules';
import { LEvLEICredentialData, LEvLEICredentialEdge } from './credentials/le';
import { ECRvLEIAuthEdge, ECRvLEICredentialData } from './credentials/ecr';
import { ECRAuthvLEIEdgeData, ECRvLEICredentialData } from './credentials/ecr';
import { OORvLEICredentialData } from './credentials/oor';
import { OORAuthvLEICredentialData } from '../le/credentials/oor-auth';
import { AID } from '..';
Expand Down Expand Up @@ -69,13 +69,13 @@ export class QVI {
*
* @param {AID} issuee
* @param {ECRvLEICredentialData} data
* @param {ECRvLEIAuthEdge} edge
* @param {ECRAuthvLEIEdgeData} edge
* @returns
*/
public async createEngagementContextRoleCredential(
issuee: AID,
data: ECRvLEICredentialData,
edge: ECRvLEIAuthEdge
edge: ECRAuthvLEIEdgeData
) {
return await this.client
.credentials()
Expand Down
117 changes: 117 additions & 0 deletions test/le/le.test.ts
Original file line number Diff line number Diff line change
@@ -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'
);
});
});

0 comments on commit f53660b

Please sign in to comment.