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

Commit

Permalink
added more schemas and interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexAndrei98 committed Sep 15, 2023
1 parent 05cae7d commit 8454c02
Show file tree
Hide file tree
Showing 8 changed files with 566 additions and 26 deletions.
3 changes: 0 additions & 3 deletions src/interfaces/client.ts

This file was deleted.

55 changes: 55 additions & 0 deletions src/interfaces/credentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export interface LEVLEICredential {
i: string;
dt: string;
LEI: string;
}
export interface LE_VLEI_EDGES {
d: string,
qvi: QVI_VLEI_EDGE
}
export interface QVI_VLEI_EDGE {
n: string,//issuer of the credential
s: "EBfdlu8R27Fbx-ehrqwImnK-8Cm79sqbAQ4MmvEAYqao", //subject of the credential
}

export interface ECRVLEICredential {
i: string; // issuer
dt: string; // date
LEI: string; // LEI
personLegalName: string; // person's legal name to which the role is assigned
engagementContextRole: string; // TODO: find list of roles
}
export interface ECR_AUTH_EDGES {
d: string,
auth: ECR_AUTH_EDGE,
}
interface ECR_AUTH_EDGE {
n: string, //SAID of the ACDC to which the edge connects
s: "EH6ekLjSr8V32WyFbGe1zXjTzFs9PkTYmupJ9H65O14g",
o: "I2I",
}
export interface ECR_LE_EDGES {
d: string,
le: ECR_LE_EDGE,
}
interface ECR_LE_EDGE {
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 OOR_AUTH_EDGES {
d: string,
auth: OOR_AUTH_EDGE,
}
interface OOR_AUTH_EDGE {
n: string, //SAID of the ACDC to which the edge connects
s: "EKA57bKBKxr_kN7iN5i7lMUxpMG-s19dRcmov1iDxz-E",
o: "I2I",
}
1 change: 0 additions & 1 deletion src/interfaces/index.ts

This file was deleted.

16 changes: 13 additions & 3 deletions src/operations.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
export const DONE = "done";
export const NAME = "name";
export const RESPONSE = "response";
const DONE = "done";
const NAME = "name";
const RESPONSE = "response";
import { SignifyClient } from "signify-ts";

export const waitKeriaOp = async (client: SignifyClient, op: any) => {
const ops = client.operations();
while (!op[DONE]) {
op = await ops.get(op[NAME]);
await new Promise((resolve) => setTimeout(resolve, 1000));
}
return op[RESPONSE];
}
80 changes: 62 additions & 18 deletions src/qvi/qvi.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
import {SignifyClient} from "signify-ts";
import {DONE, NAME, RESPONSE} from "../operations";
import { SignifyClient } from "signify-ts";
import { waitKeriaOp } from "../operations";
import { getQviRegistry } from "../registry";


import LE from "../schema/legal-entity-vLEI-credential.json";
import ECR from "../schema/legal-entity-engagement-context-role-vLEI-credential.json";
import OOR from "../schema/legal-entity-engagement-context-role-vLEI-credential.json";


import {LEVLEICredential, LE_VLEI_EDGES} from '../interfaces/credentials'

export class QVI {
private client: SignifyClient;
private readonly alias: string;
private readonly registryName: string;
private readonly registryNonce: string;
private registry: any;
private readonly SCHEMA_CACHE: { LEGAL_ENTITY: any; };
private readonly SCHEMA_CACHE: { LEGAL_ENTITY: any; ENGAGEMENT_CONTEXT_ROLE: any; OFFICIAL_ORGANIZATIONAL_ROLE: any; };

constructor(alias: string, registryName: string, registryNonce: string) {
this.alias = alias;
Expand All @@ -18,33 +25,69 @@ export class QVI {
this.SCHEMA_CACHE = {
LEGAL_ENTITY: {
LE: LE,
RULES: [
// no idea if this legal
JSON.stringify(LE.properties.r.oneOf[1].properties.usageDisclaimer.properties.l.const),
JSON.stringify(LE.properties.r.oneOf[1].properties.issuanceDisclaimer.properties.l.const),
],
RULES: {
"d": "EDIai3Wkd-Z_4cezz9nYEcCK3KNH5saLvZoS_84JL6NU",
"usageDisclaimer": {
"l": JSON.stringify(LE.properties.r.oneOf[1].properties.usageDisclaimer.properties.l.const)
},
"issuanceDisclaimer": {
"l": JSON.stringify(LE.properties.r.oneOf[1].properties.issuanceDisclaimer.properties.l.const)
}
}
,
STRING: JSON.stringify(LE)
}
// etc
},
ENGAGEMENT_CONTEXT_ROLE: {
ECR: ECR,
RULES:
{
"d": "EDIai3Wkd-Z_4cezz9nYEcCK3KNH5saLvZoS_84JL6NU",
"usageDisclaimer": {
"l": JSON.stringify(ECR.properties.r.oneOf[1].properties.usageDisclaimer.properties.l.const)
},
"issuanceDisclaimer": {
"l": JSON.stringify(ECR.properties.r.oneOf[1].properties.issuanceDisclaimer.properties.l.const)
},
"privacyDisclaimer": {
"l": JSON.stringify(ECR.properties.r.oneOf[1].properties.privacyDisclaimer.properties.l.const)
}
},
STRING: JSON.stringify(ECR)
},
OFFICIAL_ORGANIZATIONAL_ROLE: {
OOR: OOR,
RULES: {
"d": "EDIai3Wkd-Z_4cezz9nYEcCK3KNH5saLvZoS_84JL6NU",
"usageDisclaimer": {
"l": JSON.stringify(OOR.properties.r.oneOf[1].properties.usageDisclaimer.properties.l.const)
},
"issuanceDisclaimer": {
"l": JSON.stringify(OOR.properties.r.oneOf[1].properties.issuanceDisclaimer.properties.l.const)
}
},
STRING: JSON.stringify(OOR)
},
};
}

public async init(client: SignifyClient) {
let op = await this.client.registries().create(this.alias, this.registryName, this.registryNonce);
const ops = this.client.operations();
while (!op[DONE]) {
op = await ops.get(op[NAME]);
await new Promise((resolve) => setTimeout(resolve, 1000));
//check if registry already exists
let registry = await getQviRegistry(client, this.registryName);
if (registry) {
this.registry = registry;
return;
}
this.registry = op[RESPONSE];
let op = await this.client.registries().create(this.alias, this.registryName, this.registryNonce);
registry = await waitKeriaOp(this.client, op);
this.registry = registry;
}

public async issueLegalEntityCredential(
client: SignifyClient,
alias: string,
recipient: string,
credentialData: any,
source: any | undefined,
credentialData: LEVLEICredential,
source: LE_VLEI_EDGES,
_private?: boolean
) {
return await client
Expand All @@ -60,4 +103,5 @@ export class QVI {
_private
);
}

}
2 changes: 1 addition & 1 deletion src/registry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {SignifyClient} from "signify-ts";

export const QVI_CREDENTIAL_REGISTRY = "qvi_credential_registry";
export const registry = async (client: SignifyClient, name: string) => {
export const getQviRegistry = async (client: SignifyClient, name: string) => {
return await client.registries().list(name);
};
Loading

0 comments on commit 8454c02

Please sign in to comment.