Skip to content

Commit

Permalink
feat: add full ipex flow
Browse files Browse the repository at this point in the history
  • Loading branch information
bao-sotatek committed May 6, 2024
1 parent 4b68285 commit 3054ec8
Show file tree
Hide file tree
Showing 11 changed files with 459 additions and 42 deletions.
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"react-qrcode-logo": "^2.9.0",
"react-redux": "^8.0.5",
"react-router-dom": "^5.3.4",
"signify-ts": "github:WebOfTrust/signify-ts#faeebad4bdb29832cb25b83e41db064ede07dd36",
"signify-ts": "github:cardano-foundation/signify-ts#c1422b041d2ff53b3d4456a29443722b95f35fb5",
"swiper": "^9.2.0",
"web-vitals": "^2.1.4"
},
Expand Down
8 changes: 4 additions & 4 deletions services/credential-issuance-server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion services/credential-issuance-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"net": "^1.0.2",
"node-cache": "^5.1.2",
"qrcode-terminal": "^0.12.0",
"signify-ts": "github:WebOfTrust/signify-ts#faeebad4bdb29832cb25b83e41db064ede07dd36",
"signify-ts": "github:cardano-foundation/signify-ts#c1422b041d2ff53b3d4456a29443722b95f35fb5",
"uuid": "^9.0.1",
"ws": "^8.13.0"
},
Expand Down
41 changes: 41 additions & 0 deletions services/credential-issuance-server/src/agent.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SignifyApi } from "./modules/signify/signifyApi";
import { NotificationRoute } from "./modules/signify/signifyApi.type";

class Agent {
static readonly ISSUER_AID_NAME = "issuer";
Expand Down Expand Up @@ -58,6 +59,45 @@ class Agent {
async contacts() {
return this.signifyApi.contacts();
}
async onNotificationKeriStateChanged() {
// eslint-disable-next-line no-constant-condition
while (true) {
const notifications = await this.signifyApi.getNotifications();
for (const notif of notifications.notes) {
await this.processNotification(notif);
}
await new Promise((rs) => {
setTimeout(() => {
rs(true);
}, 2000);
});
}
}

private async processNotification(notif: any) {
if (
Object.values(NotificationRoute).includes(
notif.a.r as NotificationRoute
) &&
!notif.r
) {
switch (notif.a.r) {
case NotificationRoute.ExnIpexOffer: {
const msg = await this.signifyApi.getExchangeMsg(notif.a.d!);
await this.signifyApi.agreeOffer(
Agent.ISSUER_AID_NAME,
msg.exn.d,
msg.exn.i,
msg.exn.e.acdc
);
break;
}
default:
break;
}
await this.signifyApi.deleteNotification(notif.i);
}
}
async initKeri(issuerName?: string) {
const AIDIssuerName = issuerName ? issuerName : Agent.ISSUER_AID_NAME;
const existedIndentifier = await this.signifyApi
Expand All @@ -66,6 +106,7 @@ class Agent {
if (existedIndentifier) return existedIndentifier;
const identifier = await this.signifyApi.createIdentifier(AIDIssuerName);
this.keriRegistryRegk = await this.signifyApi.createRegistry(AIDIssuerName);
this.onNotificationKeriStateChanged();
return identifier;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class SignifyApi {
static readonly DEFAULT_ROLE = "agent";
static readonly FAILED_TO_RESOLVE_OOBI =
"Failed to resolve OOBI, operation not completing...";
static readonly UNKNOW_SCHEMA_ID = "Unknow Schema ID: "
static readonly UNKNOW_SCHEMA_ID = "Unknow Schema ID: ";
private signifyClient!: SignifyClient;
private opTimeout: number;
private opRetryInterval: number;
Expand Down Expand Up @@ -104,8 +104,8 @@ export class SignifyApi {
name?: string
) {
await this.resolveOobi(`${config.endpoint}/oobi/${schemaId}`);
let vcdata = {}

let vcdata = {};
if (schemaId === "EBIFDhtSE0cM4nbTnaMqiV1vUIlcnbsqBMeVMmeGmXOu") {
vcdata = {
attendeeName: name,
Expand All @@ -117,12 +117,17 @@ export class SignifyApi {
} else {
throw new Error(SignifyApi.UNKNOW_SCHEMA_ID + schemaId);
}

const result = await this.signifyClient
.credentials()
.issue({ issuerName, registryId, schemaId, recipient, data: vcdata });
await waitAndGetDoneOp(this.signifyClient, result.op, this.opTimeout, this.opRetryInterval);

await waitAndGetDoneOp(
this.signifyClient,
result.op,
this.opTimeout,
this.opRetryInterval
);

const datetime = new Date().toISOString().replace("Z", "000+00:00");
const [grant, gsigs, gend] = await this.signifyClient.ipex().grant({
senderName: issuerName,
Expand All @@ -137,21 +142,57 @@ export class SignifyApi {
.submitGrant(issuerName, grant, gsigs, gend, [recipient]);
}

async requestDisclosure(senderName: string, schemaSaid: string, recipient: string) {
/*const [apply, sigs] = await this.signifyClient.ipex().apply({
async requestDisclosure(
senderName: string,
schemaSaid: string,
recipient: string
) {
const [apply, sigs] = await this.signifyClient.ipex().apply({
senderName,
recipient,
schema: schemaSaid,
});
await this.signifyClient
.ipex()
.submitApply(senderName, apply, sigs, [recipient]);*/
.submitApply(senderName, apply, sigs, [recipient]);
}

async contacts(): Promise<any> {
return this.signifyClient.contacts().list();
}

async agreeOffer(
senderName: string,
offerSaid: string,
recipient: string,
acdc: Object
) {
const [apply, sigs] = await this.signifyClient.ipex().agree({
senderName,
recipient,
offer: offerSaid,
message: JSON.stringify({
i: recipient,
acdc,
}),
});
await this.signifyClient
.ipex()
.submitAgree(senderName, apply, sigs, [recipient]);
}

async getNotifications() {
return this.signifyClient.notifications().list();
}

async deleteNotification(said: string) {
return this.signifyClient.notifications().delete(said);
}

async getExchangeMsg(said: string) {
return this.signifyClient.exchanges().get(said);
}

/**
* Note - op must be of type any here until Signify cleans up its typing.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
enum NotificationRoute {
ExnIpexOffer = "/exn/ipex/offer",
}
export { NotificationRoute };
2 changes: 2 additions & 0 deletions src/core/agent/agent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ enum NotificationRoute {
Credential = "/exn/ipex/grant",
MultiSigIcp = "/multisig/icp",
MultiSigRot = "/multisig/rot",
ExnIpexApply = "/exn/ipex/apply",
ExnIpexAgree = "/exn/ipex/agree",
}

export {
Expand Down

0 comments on commit 3054ec8

Please sign in to comment.