Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): ensure KEL, ACDC, contact timestamps are used instead of record creation time #860

Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
iFergal marked this conversation as resolved.
Show resolved Hide resolved
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
12 changes: 10 additions & 2 deletions src/core/agent/services/identifierService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ class IdentifierService extends AgentService {
throw error;
});
const identifier = operation.serder.ked.i;
const identifierDetail = await this.props.signifyClient.identifiers().get(identifier) as HabState & { icp_dt: string };
iFergal marked this conversation as resolved.
Show resolved Hide resolved
const addRoleOperation = await this.props.signifyClient
.identifiers()
.addEndRole(identifier, "agent", this.props.signifyClient.agent!.pre);
Expand Down Expand Up @@ -211,8 +212,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 +395,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 +411,7 @@ class IdentifierService extends AgentService {
groupInitiator,
},
isPending,
createdAt: new Date(identifierDetail.icp_dt)
});

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

Expand All @@ -434,6 +439,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 +466,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
11 changes: 10 additions & 1 deletion src/core/agent/services/multiSigService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,17 @@ class MultiSigService extends AgentService {
const multisigId = op.name.split(".")[1];
const isPending = !op.done;

const multisigDetail = await this.props.signifyClient
.identifiers()
.get(multisigId as string) as HabState & { icp_dt: string };

await this.identifierStorage.createIdentifierMetadataRecord({
id: multisigId,
displayName: ourMetadata.displayName,
theme: ourMetadata.theme,
isPending,
multisigManageAid: ourIdentifier,
createdAt: new Date(multisigDetail.icp_dt)
iFergal marked this conversation as resolved.
Show resolved Hide resolved
});
ourMetadata.groupMetadata.groupCreated = true;
await this.identifierStorage.updateIdentifierMetadata(
Expand Down Expand Up @@ -368,13 +373,17 @@ class MultiSigService extends AgentService {
const op = res.op;
const multisigId = op.name.split(".")[1];
const isPending = !op.done;

const multisigDetail = await this.props.signifyClient
.identifiers()
.get(multisigId) as HabState & { icp_dt: string };

await this.identifierStorage.createIdentifierMetadataRecord({
id: multisigId,
displayName: meta.displayName,
theme: meta.theme,
isPending,
multisigManageAid: identifier.id,
createdAt: new Date(multisigDetail.icp_dt)
});
identifier.groupMetadata.groupCreated = true;
await this.identifierStorage.updateIdentifierMetadata(
Expand Down
4 changes: 2 additions & 2 deletions src/ui/components/CreateIdentifier/CreateIdentifier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const CreateIdentifier = ({
}
metadata.groupMetadata = groupMetadata;
try {
const { identifier, isPending } =
const { identifier, isPending, createdAt } =
await Agent.agent.identifiers.createIdentifier(metadata);

if(!identifier) {
Expand All @@ -148,7 +148,7 @@ const CreateIdentifier = ({
const newIdentifier: IdentifierShortDetails = {
id: identifier,
displayName: identifierData.displayName,
createdAtUTC: new Date().toISOString(),
createdAtUTC: createdAt,
theme: selectedTheme,
isPending: isPending,
};
Expand Down
Loading