Skip to content

Commit

Permalink
feat: update IPEX history when long running operations complete
Browse files Browse the repository at this point in the history
  • Loading branch information
Sotatek-TungNguyen2a committed Dec 23, 2024
1 parent 23b25f2 commit 7fc735a
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/core/__fixtures__/agent/ipexCommunicationFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,25 @@ const offerForPresentingExnMessage = {
},
};

const admitForIssuanceExnMessage = {
"exn": {
"v": "KERI10JSON000178_",
"t": "exn",
"d": "EEqJBi-JmK5IG-rU4wnn5cplcnmAk6exhAwE2GkAG895",
"i": "EJHe0vp6WOPgBNjJEakNTW2xVPwKNRJfZ1q4DhoXem3D",
"rp": "EI6lgpgvnVbl6hdfJNWCxlWEz9il1S1mu89XBBjvUBwK",
"p": "EFYtFiqA6l2xlCtTwKksHpWtTSvIilwQGamB_qFvPuER",
"dt": "2024-12-23T07:42:34.448000+00:00",
"r": ExchangeRoute.IpexAdmit,
"q": {},
"a": {
"i": "EI6lgpgvnVbl6hdfJNWCxlWEz9il1S1mu89XBBjvUBwK",
"m": ""
},
"e": {}
},
"pathed": {}
}
// @TODO - foconnor: Agree must have valid p, and no embeds - but causing tests to fail right now.
const agreeForPresentingExnMessage = {
exn: {
Expand Down Expand Up @@ -720,6 +739,7 @@ export {
applyForPresentingExnMessage,
offerForPresentingExnMessage,
agreeForPresentingExnMessage,
admitForIssuanceExnMessage,
groupIdentifierMetadataRecord,
multisigExnOfferForPresenting,
multisigExnAdmitForIssuance,
Expand Down
1 change: 1 addition & 0 deletions src/core/agent/services/connectionService.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum ConnectionHistoryType {
CREDENTIAL_REQUEST_PRESENT,
CREDENTIAL_REVOKED,
CREDENTIAL_PRESENTED,
CREDENTIAL_ADMITTED,
}

export { ConnectionHistoryType, KeriaContactKeyPrefix };
Expand Down
26 changes: 26 additions & 0 deletions src/core/agent/services/ipexCommunicationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import {
ipexSubmitAdmitEnd,
credentialStateIssued,
credentialStateRevoked,
admitForIssuanceExnMessage,
} from "../../__fixtures__/agent/ipexCommunicationFixtures";
import { NotificationRoute } from "../agent.types";
import {
Expand Down Expand Up @@ -2124,6 +2125,31 @@ describe("IPEX communication service of agent", () => {
expect(connections.resolveOobi).toBeCalledTimes(1);
});

test("Can create linked ipex message record with history type is credential admitted", async () => {
schemaGetMock.mockResolvedValueOnce(QVISchema);
getExchangeMock.mockResolvedValueOnce(admitForIssuanceExnMessage);
await ipexCommunicationService.createLinkedIpexMessageRecord(
admitForIssuanceExnMessage,
ConnectionHistoryType.CREDENTIAL_ADMITTED
);

expect(updateContactMock).toBeCalledWith(
admitForIssuanceExnMessage.exn.rp,
{
[`${KeriaContactKeyPrefix.HISTORY_IPEX}${admitForIssuanceExnMessage.exn.d}`]:
JSON.stringify({
id: admitForIssuanceExnMessage.exn.d,
dt: admitForIssuanceExnMessage.exn.dt,
credentialType: QVISchema.title,
connectionId: admitForIssuanceExnMessage.exn.rp,
historyType: ConnectionHistoryType.CREDENTIAL_ADMITTED,
}),
}
);
expect(schemaGetMock).toBeCalledTimes(1);
expect(connections.resolveOobi).toBeCalledTimes(1);
});

test("Should throw error if history type invalid", async () => {
schemaGetMock.mockResolvedValueOnce(QVISchema);
getExchangeMock.mockResolvedValueOnce(agreeForPresentingExnMessage);
Expand Down
9 changes: 7 additions & 2 deletions src/core/agent/services/ipexCommunicationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,18 @@ class IpexCommunicationService extends AgentService {
): Promise<void> {
let schemaSaid;
const connectionId =
historyType === ConnectionHistoryType.CREDENTIAL_PRESENTED
historyType === ConnectionHistoryType.CREDENTIAL_PRESENTED ||
historyType === ConnectionHistoryType.CREDENTIAL_ADMITTED
? message.exn.rp
: message.exn.i;
if (message.exn.r === ExchangeRoute.IpexGrant) {
schemaSaid = message.exn.e.acdc.s;
} else if (message.exn.r === ExchangeRoute.IpexApply) {
schemaSaid = message.exn.a.s;
} else if (message.exn.r === ExchangeRoute.IpexAgree) {
} else if (
message.exn.r === ExchangeRoute.IpexAgree ||
message.exn.r === ExchangeRoute.IpexAdmit
) {
const previousExchange = await this.props.signifyClient
.exchanges()
.get(message.exn.p);
Expand All @@ -515,6 +519,7 @@ class IpexCommunicationService extends AgentService {
case ConnectionHistoryType.CREDENTIAL_ISSUANCE:
case ConnectionHistoryType.CREDENTIAL_REQUEST_PRESENT:
case ConnectionHistoryType.CREDENTIAL_PRESENTED:
case ConnectionHistoryType.CREDENTIAL_ADMITTED:
prefix = KeriaContactKeyPrefix.HISTORY_IPEX;
key = message.exn.d;
break;
Expand Down
9 changes: 9 additions & 0 deletions src/core/agent/services/keriaNotificationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,15 @@ describe("Long running operation tracker", () => {
credentialIdMock,
CredentialStatus.CONFIRMED
);
expect(ipexCommunications.createLinkedIpexMessageRecord).toBeCalledWith(
{
exn: {
r: ExchangeRoute.IpexAdmit,
p: "p",
},
},
ConnectionHistoryType.CREDENTIAL_ADMITTED
);
expect(notificationStorage.save).not.toBeCalled();
expect(operationPendingStorage.deleteById).toBeCalledTimes(1);
});
Expand Down
6 changes: 6 additions & 0 deletions src/core/agent/services/keriaNotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,12 @@ class KeriaNotificationService extends AgentService {
});
}
}

await this.ipexCommunications.createLinkedIpexMessageRecord(
admitExchange,
ConnectionHistoryType.CREDENTIAL_ADMITTED
);

await this.credentialService.markAcdc(
credentialId,
CredentialStatus.CONFIRMED
Expand Down
1 change: 1 addition & 0 deletions src/locales/en/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1458,6 +1458,7 @@
"history": "Connection History",
"connectedwith": "Connected with “{{ issuer }}“",
"issuance": "Received a “{{ credential }}“",
"admitted": "Admitted “{{ credential }}“ credential",
"requestpresent": "“{{ issuer }}“ has requested a credential presentation",
"update": "“{{ credential }}“ has been revoked",
"presented": "Presented “{{ credentialType }}“ credential",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ const ConnectionHistoryEvent = ({
.replace(/(\d)/g, "$1")
.replace(/ {2,}/g, " "),
})}
{historyItem.type === ConnectionHistoryType.CREDENTIAL_ADMITTED &&
i18next.t("connections.details.admitted", {
credential: historyItem.credentialType
?.replace(/([A-Z][a-z])/g, " $1")
.replace(/^ /, "")
.replace(/(\d)/g, "$1")
.replace(/ {2,}/g, " "),
})}
{historyItem.type ===
ConnectionHistoryType.CREDENTIAL_REQUEST_PRESENT &&
i18next.t("connections.details.requestpresent", {
Expand Down

0 comments on commit 7fc735a

Please sign in to comment.