Skip to content

Commit

Permalink
feat(core): ensure KEL, ACDC, contact timestamps are used instead of …
Browse files Browse the repository at this point in the history
…record creation time (#860)

* update createdAt of records in our db

* update unit test credentialService

* fix unit test keriaNotificationService

* update unit test multiSigService
  • Loading branch information
Sotatek-TungNguyen2a authored Dec 13, 2024
1 parent f4b9438 commit cd53be8
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/core/__fixtures__/agent/keriaNotificationFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ const notificationIpexGrantProp = {

const notificationIpexAgreeProp = {
i: "string",
dt: "string",
dt: "2024-12-10T07:28:18.217384+00:00",
r: false,
a: {
r: NotificationRoute.ExnIpexAgree,
Expand Down
1 change: 1 addition & 0 deletions src/core/__fixtures__/agent/multSigFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ const getMemberIdentifierResponse = {
},
di: "",
},
icp_dt: "2024-08-09T07:23:52.839894+00:00"
};

const getMultisigIdentifierResponse = {
Expand Down
33 changes: 31 additions & 2 deletions src/core/agent/services/credentialService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ describe("Credential service of agent", () => {
},
schema: {
$id: "id-1",
tile: "title1",
title: "title1",
},
},
{
Expand All @@ -413,7 +413,7 @@ describe("Credential service of agent", () => {
},
schema: {
$id: "id-2",
tile: "title2",
title: "title2",
},
},
]);
Expand All @@ -424,6 +424,35 @@ describe("Credential service of agent", () => {
});
await credentialService.syncACDCs();
expect(credentialStorage.saveCredentialMetadataRecord).toBeCalledTimes(2);

expect(credentialStorage.saveCredentialMetadataRecord).toHaveBeenCalledWith(
expect.objectContaining({
id: "EIuZp_JvO5pbNmS8jyG96t3d4XENaFSJpLtbLySxvz-X",
isArchived: false,
issuanceDate: "2023-11-29T02:13:34.858Z",
credentialType: "title1",
status: CredentialStatus.CONFIRMED,
connectionId: "ECTcHGs3EhJEdVTW10vm5pkiDlOXlR8bPBj9-8LSpZ3W",
schema: "id-1",
identifierId: "EL-EboMhx-DaBLiAS_Vm3qtJOubb2rkcS3zLU_r7UXtl",
identifierType: IdentifierType.Individual,
createdAt: new Date("2023-11-29T02:13:34.858Z"),
}));

expect(credentialStorage.saveCredentialMetadataRecord).toHaveBeenCalledWith(
expect.objectContaining({
id: "EL24R3ECGtv_UzQmYUcu9AeP1ks2JPzTxgPcQPkadEPY",
isArchived: false,
issuanceDate: "2023-11-29T02:12:35.716Z",
credentialType: "title2",
status: CredentialStatus.CONFIRMED,
connectionId: "ECTcHGs3EhJEdVTW10vm5pkiDlOXlR8bPBj9-8LSpZ3W",
schema: "id-2",
identifierId: "EL-EboMhx-DaBLiAS_Vm3qtJOubb2rkcS3zLU_r7UXtl",
identifierType: IdentifierType.Individual,
createdAt: new Date("2023-11-29T02:12:35.716Z"),
})
);
});

test("Must throw 'Credential with given SAID not found on KERIA' when there's no KERI credential", async () => {
Expand Down
1 change: 1 addition & 0 deletions src/core/agent/services/credentialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class CredentialService extends AgentService {
identifierType: identifier.multisigManageAid
? IdentifierType.Group
: IdentifierType.Individual,
createdAt: new Date(credential.sad.a.dt),
});
} catch (error) {
/* eslint-disable no-console */
Expand Down
1 change: 1 addition & 0 deletions src/core/agent/services/identifier.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ interface MultiSigIcpRequestDetails {
interface CreateIdentifierResult {
identifier: string;
isPending: boolean;
createdAt: string;
}

enum IdentifierType {
Expand Down
10 changes: 10 additions & 0 deletions src/core/agent/services/identifierService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ describe("Single sig service of agent", () => {
}),
});

getIdentifiersMock.mockResolvedValue(groupIdentifierStateKeria);

expect(
await identifierService.createIdentifier({
displayName,
Expand Down Expand Up @@ -404,6 +406,7 @@ describe("Single sig service of agent", () => {
id: "op123",
recordType: OperationPendingRecordType.Witness,
});
getIdentifiersMock.mockResolvedValue(groupIdentifierStateKeria);

expect(
await identifierService.createIdentifier({
Expand Down Expand Up @@ -680,6 +683,10 @@ describe("Single sig service of agent", () => {
jest
.spyOn(signifyClient.operations(), "get")
.mockResolvedValue(mockOperation);

getIdentifiersMock.mockResolvedValue({
icp_dt: "2024-12-10T07:28:18.217384+00:00"
});

// Call the function to test
await identifierService.syncKeriaIdentifiers();
Expand All @@ -697,6 +704,7 @@ describe("Single sig service of agent", () => {
groupInitiator: true,
},
isPending: false,
createdAt: new Date("2024-12-10T07:28:18.217384+00:00")
});

expect(
Expand All @@ -706,6 +714,7 @@ describe("Single sig service of agent", () => {
displayName: "EJ9oenRW3_SNc0JkETnOegspNGaDCypBfTU1kJiL2AMs",
theme: 33,
isPending: false,
createdAt: new Date("2024-12-10T07:28:18.217384+00:00")
});

// sync data of group record
Expand All @@ -728,6 +737,7 @@ describe("Single sig service of agent", () => {
theme: 15,
multisigManageAid: "EL-EboMhx-DaBLiAS_Vm3qtJOubb2rkcS3zLU_r7UXtl",
isPending: false,
createdAt: new Date("2024-12-10T07:28:18.217384+00:00")
});
});

Expand Down
15 changes: 13 additions & 2 deletions src/core/agent/services/identifierService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,10 @@ class IdentifierService extends AgentService {
throw error;
});
const identifier = operation.serder.ked.i;

// @TODO - foconnor: Need update HabState interface on signify.
const identifierDetail = await this.props.signifyClient.identifiers().get(identifier) as HabState & { icp_dt: string };

const addRoleOperation = await this.props.signifyClient
.identifiers()
.addEndRole(identifier, "agent", this.props.signifyClient.agent!.pre);
Expand Down Expand Up @@ -211,8 +215,9 @@ class IdentifierService extends AgentService {
id: identifier,
...metadata,
isPending: !op.done,
createdAt: new Date(identifierDetail.icp_dt)
});
return { identifier, isPending: !op.done };
return { identifier, isPending: !op.done, createdAt: identifierDetail.icp_dt };
}

async deleteIdentifier(identifier: string): Promise<void> {
Expand Down Expand Up @@ -393,6 +398,7 @@ class IdentifierService extends AgentService {
const name = identifier.name.split(":");
const theme = parseInt(name[0], 10);
const isMultiSig = name.length === 3;
const identifierDetail = await this.props.signifyClient.identifiers().get(identifier) as HabState & { icp_dt: string };

if (isMultiSig) {
const groupId = identifier.name.split(":")[1];
Expand All @@ -408,6 +414,7 @@ class IdentifierService extends AgentService {
groupInitiator,
},
isPending,
createdAt: new Date(identifierDetail.icp_dt)
});

continue;
Expand All @@ -418,6 +425,7 @@ class IdentifierService extends AgentService {
displayName: identifier.prefix,
theme,
isPending,
createdAt: new Date(identifierDetail.icp_dt)
});
}

Expand All @@ -434,6 +442,7 @@ class IdentifierService extends AgentService {
.operations()
.get(`group.${identifier.prefix}`);
const isPending = !op.done;
const identifierDetail = await this.props.signifyClient.identifiers().get(identifier) as HabState & { icp_dt: string };

if (isPending) {
const pendingOperation = await this.operationPendingStorage.save({
Expand All @@ -460,7 +469,9 @@ class IdentifierService extends AgentService {
theme,
multisigManageAid,
isPending,
});
createdAt: new Date(identifierDetail.icp_dt
)
})
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/core/agent/services/ipexCommunicationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ describe("Receive individual ACDC actions", () => {
...credentialRecordProps,
identifierId: "identifierId",
identifierType: "individual",
createdAt: new Date(credentialRecordProps.issuanceDate)
});
expect(eventEmitter.emit).toHaveBeenCalledWith({
type: EventTypes.AcdcStateChanged,
Expand All @@ -362,6 +363,7 @@ describe("Receive individual ACDC actions", () => {
...credentialRecordProps,
identifierId: "identifierId",
identifierType: "individual",
createdAt: new Date(credentialRecordProps.issuanceDate)
},
status: CredentialStatus.PENDING,
},
Expand Down Expand Up @@ -551,6 +553,7 @@ describe("Receive group ACDC actions", () => {
...credentialRecordProps,
identifierId: "EC1cyV3zLnGs4B9AYgoGNjXESyQZrBWygz3jLlRD30bR",
identifierType: "group",
createdAt: new Date(credentialRecordProps.issuanceDate)
});
expect(eventEmitter.emit).toHaveBeenCalledWith({
type: EventTypes.AcdcStateChanged,
Expand All @@ -559,6 +562,7 @@ describe("Receive group ACDC actions", () => {
...credentialRecordProps,
identifierId: "EC1cyV3zLnGs4B9AYgoGNjXESyQZrBWygz3jLlRD30bR",
identifierType: "group",
createdAt: new Date(credentialRecordProps.issuanceDate)
},
status: CredentialStatus.PENDING,
},
Expand Down Expand Up @@ -744,6 +748,7 @@ describe("Receive group ACDC actions", () => {
...credentialRecordProps,
identifierId: "EC1cyV3zLnGs4B9AYgoGNjXESyQZrBWygz3jLlRD30bR",
identifierType: "group",
createdAt: new Date(credentialRecordProps.issuanceDate)
});
expect(eventEmitter.emit).toHaveBeenCalledWith({
type: EventTypes.AcdcStateChanged,
Expand All @@ -752,6 +757,7 @@ describe("Receive group ACDC actions", () => {
...credentialRecordProps,
identifierId: "EC1cyV3zLnGs4B9AYgoGNjXESyQZrBWygz3jLlRD30bR",
identifierType: "group",
createdAt: new Date(credentialRecordProps.issuanceDate)
},
status: CredentialStatus.PENDING,
},
Expand Down
1 change: 1 addition & 0 deletions src/core/agent/services/ipexCommunicationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,7 @@ class IpexCommunicationService extends AgentService {
identifierType: holder.multisigManageAid
? IdentifierType.Group
: IdentifierType.Individual,
createdAt: new Date(dateTime),
};
await this.credentialStorage.saveCredentialMetadataRecord(
credentialDetails
Expand Down
13 changes: 9 additions & 4 deletions src/core/agent/services/keriaNotificationService.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { create } from "domain";
import { Agent } from "../agent";
import {
ConnectionStatus,
Expand Down Expand Up @@ -1373,7 +1374,8 @@ describe("Signify notification service of agent", () => {
connectionId: "EC9bQGHShmp2Juayqp0C5XcheBiHyc1p54pZ_Op-B95x",
credentialId: undefined,
id: notificationIpexAgreeProp.i,
route: NotificationRoute.ExnIpexAgree
route: NotificationRoute.ExnIpexAgree,
createdAt: new Date(notificationIpexAgreeProp.dt)
});
expect(eventEmitter.emit).not.toBeCalled();
expect(ipexCommunications.grantAcdcFromAgree).toBeCalledWith("string");
Expand Down Expand Up @@ -1402,7 +1404,8 @@ describe("Signify notification service of agent", () => {
connectionId: "EC9bQGHShmp2Juayqp0C5XcheBiHyc1p54pZ_Op-B95x",
credentialId: undefined,
id: notificationIpexAgreeProp.i,
route: NotificationRoute.ExnIpexAgree
route: NotificationRoute.ExnIpexAgree,
createdAt: new Date(notificationIpexAgreeProp.dt)
});
expect(eventEmitter.emit).not.toBeCalled();
expect(ipexCommunications.grantAcdcFromAgree).toBeCalledWith("string");
Expand Down Expand Up @@ -1574,7 +1577,8 @@ describe("Group IPEX presentation", () => {
connectionId: "EC9bQGHShmp2Juayqp0C5XcheBiHyc1p54pZ_Op-B95x",
credentialId: undefined,
id: notificationIpexAgreeProp.i,
route: NotificationRoute.ExnIpexAgree
route: NotificationRoute.ExnIpexAgree,
createdAt: new Date(notificationIpexAgreeProp.dt)
});
expect(eventEmitter.emit).not.toBeCalled();
expect(identifiersMemberMock).toBeCalledWith("EBEWfIUOn789yJiNRnvKqpbWE3-m6fSDxtu6wggybbli");
Expand Down Expand Up @@ -1617,7 +1621,8 @@ describe("Group IPEX presentation", () => {
connectionId: "EC9bQGHShmp2Juayqp0C5XcheBiHyc1p54pZ_Op-B95x",
credentialId: undefined,
id: notificationIpexAgreeProp.i,
route: NotificationRoute.ExnIpexAgree
route: NotificationRoute.ExnIpexAgree,
createdAt: new Date(notificationIpexAgreeProp.dt)
});
expect(eventEmitter.emit).not.toBeCalled();
expect(identifiersMemberMock).toBeCalledWith("EBEWfIUOn789yJiNRnvKqpbWE3-m6fSDxtu6wggybbli");
Expand Down
1 change: 1 addition & 0 deletions src/core/agent/services/keriaNotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,7 @@ class KeriaNotificationService extends AgentService {
read: false,
route: event.a.r as NotificationRoute,
connectionId: exchange.exn.i,
createdAt: new Date(event.dt),
credentialId: exchange.exn.e?.acdc?.d,
};

Expand Down
30 changes: 29 additions & 1 deletion src/core/agent/services/multiSigService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,17 @@ describe("Oobi/endrole", () => {
);
expect(addEndRoleMock).toBeCalledTimes(1);
(memberMetadataRecord.groupMetadata as any).groupCreated = false;

expect(identifierStorage.createIdentifierMetadataRecord).toBeCalledWith(
{
id: "newMultisigIdentifierAid",
displayName: "Identifier 2",
theme: 0,
isPending: false,
multisigManageAid: "creatorIdentifier",
createdAt: new Date("2024-08-09T07:23:52.839894+00:00")
}
)
});

test("Can add end role authorization", async () => {
Expand Down Expand Up @@ -406,7 +417,14 @@ describe("Creation of multi-sig", () => {
isPending: true,
});
expect(identifierStorage.createIdentifierMetadataRecord).toBeCalledWith(
expect.objectContaining({ id: multisigIdentifier, isPending: true })
expect.objectContaining({
id: multisigIdentifier,
displayName: "Identifier 2",
theme: 0,
isPending: true,
multisigManageAid: "creatorIdentifier",
createdAt: new Date("2024-08-09T07:23:52.839Z")
})
);

expect(eventEmitter.emit).toHaveBeenCalledWith({
Expand Down Expand Up @@ -446,6 +464,11 @@ describe("Creation of multi-sig", () => {
expect(identifierStorage.createIdentifierMetadataRecord).toBeCalledWith(
expect.objectContaining({
id: `${multisigIdentifier}1`,
displayName: "Identifier 2",
theme: 0,
isPending: true,
multisigManageAid: "creatorIdentifier",
createdAt: new Date("2024-08-09T07:23:52.839Z")
})
);

Expand Down Expand Up @@ -477,6 +500,11 @@ describe("Creation of multi-sig", () => {
expect(identifierStorage.createIdentifierMetadataRecord).toBeCalledWith(
expect.objectContaining({
id: `${multisigIdentifier}2`,
displayName: "Identifier 2",
theme: 0,
isPending: true,
multisigManageAid: "creatorIdentifier",
createdAt: new Date("2024-08-09T07:23:52.839Z")
})
);

Expand Down
Loading

0 comments on commit cd53be8

Please sign in to comment.