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): linking of ipex flows to contacts #422

Merged
merged 21 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6ef8a97
feat: rework some API in cred server
Sotatek-BaoHoanga Mar 4, 2024
ce55883
feat: add apply schema API
Sotatek-BaoHoanga Mar 5, 2024
e9e38eb
refactor: function and var name and dependency link
Sotatek-BaoHoanga Mar 5, 2024
814e78b
feat: add full ipex flow for idw and cred server
Sotatek-BaoHoanga Mar 11, 2024
c8ce453
refactor: testing and some missing logic
Sotatek-BaoHoanga Mar 11, 2024
4f0156e
feature: save linked IPEX messages for connections
Sotatek-HocNguyena Apr 16, 2024
6f29933
Merge branch 'develop' of github.com:cardano-foundation/cf-identity-w…
Sotatek-HocNguyena May 31, 2024
c035d41
refactor: change the file contruction
Sotatek-HocNguyena Jun 3, 2024
f66f763
Merge branch 'develop' of github.com:cardano-foundation/cf-identity-w…
Sotatek-HocNguyena Jun 20, 2024
5cd3036
Merge branch 'develop' of github.com:cardano-foundation/cf-identity-w…
Sotatek-TungNguyen2a Jul 26, 2024
44c7d0f
Merge branch 'develop' of github.com:cardano-foundation/cf-identity-w…
Sotatek-TungNguyen2a Jul 26, 2024
cc73acd
Merge branch 'develop' of github.com:cardano-foundation/cf-identity-w…
Sotatek-TungNguyen2a Jul 27, 2024
0caf0a4
feat: linking of IPEX flows to contacts
Sotatek-TungNguyen2a Jul 29, 2024
9bc6440
fix: update unit tests
Sotatek-TungNguyen2a Jul 29, 2024
5f71099
update: add isUpdate to linkedIpexMessage record
Sotatek-TungNguyen2a Jul 29, 2024
092ba49
update: add credentialType to linkedIpexMessageRecord
Sotatek-TungNguyen2a Jul 29, 2024
a6750ea
update: get linkedIpexRecord from exchange message
Sotatek-TungNguyen2a Jul 30, 2024
29115e5
update: get linkedIpexRecord id from exchange message SAID
Sotatek-TungNguyen2a Jul 30, 2024
78b490e
feat: resolve schema if we fail to get the schema
Sotatek-TungNguyen2a Jul 31, 2024
39739e0
Merge branch 'develop' of github.com:cardano-foundation/cf-identity-w…
Sotatek-TungNguyen2a Jul 31, 2024
ba8ddbc
feat: handle for apply and agree routes
Sotatek-TungNguyen2a Jul 31, 2024
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
1 change: 0 additions & 1 deletion src/core/agent/agent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface ConnectionHistoryItem {
type: ConnectionHistoryType;
credentialType?: string;
timestamp: string;
linkedIpexMessages?: IpexMessageDetails[];
}

enum MiscRecordId {
Expand Down
6 changes: 4 additions & 2 deletions src/core/agent/records/ipexMessageRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ import { IpexMessage } from "../agent.types";
interface IpexMessageProps {
id: string;
content: IpexMessage;
isUpdate?: boolean;
createdAt?: Date;
connectionId: string;
}

class IpexMessageRecord extends BaseRecord {
content!: IpexMessage;
connectionId!: string;
isUpdate?: boolean;
iFergal marked this conversation as resolved.
Show resolved Hide resolved

static readonly type = "IpexMessagMetadataRecord";
static readonly type = "IpexMessageRecord";
readonly type = IpexMessageRecord.type;

constructor(props: IpexMessageProps) {
Expand All @@ -22,6 +24,7 @@ class IpexMessageRecord extends BaseRecord {
this.id = props.id;
this.content = props.content;
this.connectionId = props.connectionId;
this.isUpdate = props.isUpdate ?? false;
this.createdAt = props.createdAt ?? new Date();
}
}
Expand All @@ -30,7 +33,6 @@ class IpexMessageRecord extends BaseRecord {
return {
...this._tags,
connectionId: this.connectionId,
id: this.id,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/agent/services/connection.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ interface KeriaContact {

enum ConnectionHistoryType {
CREDENTIAL_ISSUANCE,
CREDENTIAL_PRESENT,
CREDENTIAL_REQUEST_PRESENT,
CREDENTIAL_UPDATE,
}

Expand Down
3 changes: 2 additions & 1 deletion src/core/agent/services/connectionService.test.ts
iFergal marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,7 @@ describe("Connection service of agent", () => {
},
},
connectionId,
isUpdate: true,
createdAt: date3,
},
]);
Expand All @@ -698,7 +699,7 @@ describe("Connection service of agent", () => {
credentialType: "IIW 2024 Demo Day Attendee",
},
{
type: ConnectionHistoryType.CREDENTIAL_PRESENT,
type: ConnectionHistoryType.CREDENTIAL_REQUEST_PRESENT,
timestamp: date2.toISOString(),
credentialType: "IIW 2024 Demo Day Attendee",
},
Expand Down
45 changes: 13 additions & 32 deletions src/core/agent/services/connectionService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import {
AgentServicesProps,
OobiScan,
KeriConnectionType,
IpexMessageDetails,
NotificationRoute,
ExchangeRoute,
} from "../agent.types";
import { AgentService } from "./agentService";
Expand Down Expand Up @@ -310,45 +308,38 @@ class ConnectionService extends AgentService {
await this.credentialStorage.getCredentialMetadataByConnectionId(
connectionId
);
const credentialStatistics: {
[key: string]: { name: string; count: number };
} = {};
const credentialTypes: { [key: string]: string } = {};
iFergal marked this conversation as resolved.
Show resolved Hide resolved
credentialRecords.forEach((record) => {
if (!credentialStatistics[record.id.replace("metadata:", "")]) {
credentialStatistics[record.id.replace("metadata:", "")] = {
name: record.credentialType,
count: 0,
};
if (!credentialTypes[record.id.replace("metadata:", "")]) {
credentialTypes[record.id.replace("metadata:", "")] =
record.credentialType;
}
});

const linkedIpexMessages = await this.getLinkedIPEXMessageByConnectionId(
connectionId
);
const linkedIpexMessages =
await this.ipexMessageStorage.getIpexMessageMetadataByConnectionId(
connectionId
);

const requestMessages = linkedIpexMessages
.sort((a, b) => a.createdAt.getTime() - b.createdAt.getTime())
iFergal marked this conversation as resolved.
Show resolved Hide resolved
.map((messageRecord) => {
const credentialStatistic =
credentialStatistics[messageRecord.content.exn.e.acdc.d];
const credentialType =
credentialTypes[messageRecord.content.exn.e.acdc.d];
let historyType: ConnectionHistoryType;
const route = messageRecord.content.exn.r;
if (
route === ExchangeRoute.IpexGrant &&
credentialStatistic.count === 0
) {
if (route === ExchangeRoute.IpexGrant && !messageRecord.isUpdate) {
historyType = ConnectionHistoryType.CREDENTIAL_ISSUANCE;
iFergal marked this conversation as resolved.
Show resolved Hide resolved
} else if (route === ExchangeRoute.IpexApply) {
historyType = ConnectionHistoryType.CREDENTIAL_PRESENT;
historyType = ConnectionHistoryType.CREDENTIAL_REQUEST_PRESENT;
} else {
historyType = ConnectionHistoryType.CREDENTIAL_UPDATE;
}
credentialStatistic.count++;

return {
type: historyType,
timestamp: messageRecord.createdAt.toISOString(),
credentialType: credentialStatistic.name,
credentialType,
};
});
return requestMessages.reverse();
Expand Down Expand Up @@ -424,16 +415,6 @@ class ConnectionService extends AgentService {
};
});
}

private async getLinkedIPEXMessageByConnectionId(
connectionId: string
): Promise<IpexMessageDetails[]> {
const messages =
await this.ipexMessageStorage.getIpexMessageMetadataByConnectionId(
connectionId
);
return messages;
}
}

export { ConnectionService };
1 change: 0 additions & 1 deletion src/core/agent/services/ipexCommunicationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ describe("Ipex communication service of agent", () => {
connectionId: "i",
})
);
expect(ipexMessageRecordStorage.createIpexMessageRecord).toBeCalledTimes(1);
expect(operationPendingStorage.save).toBeCalledWith({
id: "opName",
recordType: OperationPendingRecordType.ExchangeReceiveCredential,
Expand Down
5 changes: 3 additions & 2 deletions src/core/agent/services/ipexCommunicationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ class IpexCommunicationService extends AgentService {
schema.title,
connectionId
);
await this.createLinkedIpexMessageRecord(exn.exn.i, exn);

this.props.eventService.emit<AcdcStateChangedEvent>({
type: AcdcEventTypes.AcdcStateChanged,
Expand Down Expand Up @@ -345,12 +344,14 @@ class IpexCommunicationService extends AgentService {

async createLinkedIpexMessageRecord(
iFergal marked this conversation as resolved.
Show resolved Hide resolved
iFergal marked this conversation as resolved.
Show resolved Hide resolved
connectionId: string,
message: IpexMessage
message: IpexMessage,
isUpdate = false
): Promise<void> {
await this.ipexMessageStorage.createIpexMessageRecord({
iFergal marked this conversation as resolved.
Show resolved Hide resolved
id: uuidv4(),
iFergal marked this conversation as resolved.
Show resolved Hide resolved
content: message,
connectionId,
isUpdate,
});
}
}
Expand Down
20 changes: 20 additions & 0 deletions src/core/agent/services/signifyNotificationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,20 @@ class SignifyNotificationService extends AgentService {
if (notif.r) {
return;
}
if (notif.a.r === NotificationRoute.ExnIpexApply) {
const existingNotficationRecord = await this.notificationStorage.findById(
notif.i
);
if (!existingNotficationRecord) {
iFergal marked this conversation as resolved.
Show resolved Hide resolved
const exchange = await this.props.signifyClient
.exchanges()
.get(notif.a.d);
await Agent.agent.ipexCommunications.createLinkedIpexMessageRecord(
exchange.exn.i,
exchange
);
}
}
if (notif.a.r === NotificationRoute.ExnIpexGrant) {
const exchange = await this.props.signifyClient
.exchanges()
Expand Down Expand Up @@ -208,6 +222,12 @@ class SignifyNotificationService extends AgentService {
);
await this.markNotification(notif.i);
return;
} else {
await Agent.agent.ipexCommunications.createLinkedIpexMessageRecord(
exchange.exn.i,
exchange,
true
iFergal marked this conversation as resolved.
Show resolved Hide resolved
);
}
}
if (notif.a.r === NotificationRoute.MultiSigRpy) {
Expand Down
Loading