Skip to content

Commit

Permalink
refactor: remove unnecessary cred metadata attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
iFergal committed Apr 30, 2024
1 parent c676ea8 commit 3d7c49b
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 93 deletions.
5 changes: 0 additions & 5 deletions services/credential-issuance-server/src/errors.ts

This file was deleted.

7 changes: 0 additions & 7 deletions src/core/agent/records/credentialMetadataRecord.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ const mockData: CredentialMetadataRecordProps = {
id: "credential:z6Mkpph7qyemfmHt5cSEXXbhm1VbSZT789X8Ep4eA7ndGxGh",
isArchived: true,
issuanceDate: "2010-01-01T19:23:24Z",
issuerLogo: "https://placehold.co/120x22",
credentialType: "test",
status: CredentialMetadataRecordStatus.CONFIRMED,
credentialRecordId: "1",
};

describe("Credential metadata record", () => {
Expand All @@ -26,7 +24,6 @@ describe("Credential metadata record", () => {
expect(settingsRecord.createdAt).toBe(createdAt);
expect(settingsRecord.isArchived).toBe(mockData.isArchived);
expect(settingsRecord.issuanceDate).toBe(mockData.issuanceDate);
expect(settingsRecord.issuerLogo).toBe(mockData.issuerLogo);
expect(settingsRecord.getTags()).toMatchObject({
isArchived: mockData.isArchived,
});
Expand All @@ -39,10 +36,8 @@ describe("Credential metadata record", () => {
id: mockData.id,
isArchived: mockData.isArchived,
issuanceDate: "2010-01-01T19:23:24Z",
issuerLogo: "https://placehold.co/120x22",
credentialType: "test",
status: CredentialMetadataRecordStatus.CONFIRMED,
credentialRecordId: "1",
});
expect(settingsRecord.createdAt.getTime()).toBeGreaterThan(
createdAt.getTime()
Expand All @@ -55,10 +50,8 @@ describe("Credential metadata record", () => {
id: mockData.id,
createdAt: createdAt,
issuanceDate: "2010-01-01T19:23:24Z",
issuerLogo: "https://placehold.co/120x22",
credentialType: "test",
status: CredentialMetadataRecordStatus.CONFIRMED,
credentialRecordId: "1",
});
expect(settingsRecord.isArchived).toBe(false);
});
Expand Down
5 changes: 0 additions & 5 deletions src/core/agent/records/credentialMetadataRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@ class CredentialMetadataRecord extends BaseRecord {
isArchived?: boolean;
isDeleted?: boolean;
issuanceDate!: string;
issuerLogo?: string;
credentialType!: string;
status!: CredentialMetadataRecordStatus;
credentialRecordId!: string;
connectionId?: string;

static readonly type = "CredentialMetadataRecord";
Expand All @@ -22,12 +20,10 @@ class CredentialMetadataRecord extends BaseRecord {

if (props) {
this.id = props.id;
this.credentialRecordId = props.credentialRecordId;
this.isArchived = props.isArchived ?? false;
this.isDeleted = props.isDeleted ?? false;
this.createdAt = props.createdAt ?? new Date();
this.issuanceDate = props.issuanceDate;
this.issuerLogo = props.issuerLogo;
this.credentialType = props.credentialType;
this.status = props.status;
this.connectionId = props.connectionId;
Expand All @@ -39,7 +35,6 @@ class CredentialMetadataRecord extends BaseRecord {
...this._tags,
isArchived: this.isArchived,
isDeleted: this.isDeleted,
credentialRecordId: this.credentialRecordId,
connectionId: this.connectionId,
};
}
Expand Down
2 changes: 0 additions & 2 deletions src/core/agent/records/credentialMetadataRecord.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ interface CredentialMetadataRecordProps {
isArchived?: boolean;
isDeleted?: boolean;
issuanceDate: string;
issuerLogo?: string;
credentialType: string;
credentialRecordId: string;
status: CredentialMetadataRecordStatus;
connectionId?: string;
}
Expand Down
25 changes: 0 additions & 25 deletions src/core/agent/records/credentialStorage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const credentialStorage = new CredentialStorage(storageService as any);

const id1 = "id1";
const id2 = "id2";
const credentialRecordId1 = "cId1";

const now = new Date();
const nowISO = now.toISOString();
Expand All @@ -28,10 +27,8 @@ const credentialMetadataProps: CredentialMetadataRecordProps = {
id: id1,
createdAt: now,
issuanceDate: nowISO,
issuerLogo: "issuerLogoHere",
credentialType: "credType",
status: CredentialMetadataRecordStatus.CONFIRMED,
credentialRecordId: credentialRecordId1,
};

const credentialMetadataRecordA = new CredentialMetadataRecord(
Expand Down Expand Up @@ -68,28 +65,6 @@ describe("Connection service of agent", () => {
).toEqual(credentialMetadataRecordA);
});

test("Should get credential metadata by credential record id", async () => {
storageService.findAllByQuery.mockResolvedValue([
credentialMetadataRecordA,
]);
expect(
await credentialStorage.getCredentialMetadataByCredentialRecordId(
credentialMetadataRecordA.id
)
).toEqual(credentialMetadataRecordA);
});

test("Should get credential metadata by connection record id", async () => {
storageService.findAllByQuery.mockResolvedValue([
credentialMetadataRecordB,
]);
expect(
await credentialStorage.getCredentialMetadataByCredentialRecordId(
credentialMetadataRecordB.id
)
).toEqual(credentialMetadataRecordB);
});

test("Should save credential metadata record", async () => {
await credentialStorage.saveCredentialMetadataRecord(
credentialMetadataProps
Expand Down
16 changes: 0 additions & 16 deletions src/core/agent/records/credentialStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,6 @@ class CredentialStorage {
return record;
}

async getCredentialMetadataByCredentialRecordId(
credentialRecordId: string
): Promise<CredentialMetadataRecord | null> {
const records = await this.storageService.findAllByQuery(
{
credentialRecordId,
},
CredentialMetadataRecord
);
const record = records[0];
if (!record) {
return null;
}
return record;
}

async getCredentialMetadataByConnectionId(connectionId: string) {
const record = await this.storageService.findAllByQuery(
{
Expand Down
4 changes: 0 additions & 4 deletions src/core/agent/services/credentialService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ const credentialStorage = jest.mocked({
getAllCredentialMetadata: jest.fn(),
deleteCredentialMetadata: jest.fn(),
getCredentialMetadata: jest.fn(),
getCredentialMetadataByCredentialRecordId: jest.fn(),
getCredentialMetadataByConnectionId: jest.fn(),
saveCredentialMetadataRecord: jest.fn(),
updateCredentialMetadata: jest.fn(),
Expand All @@ -126,15 +125,12 @@ const nowISO = now.toISOString();

const id1 = "id1";
const id2 = "id2";
const credentialRecordId1 = "cId1";
const credentialMetadataProps: CredentialMetadataRecordProps = {
id: id1,
createdAt: now,
issuanceDate: nowISO,
issuerLogo: "issuerLogoHere",
credentialType: "credType",
status: CredentialMetadataRecordStatus.CONFIRMED,
credentialRecordId: credentialRecordId1,
};

const credentialMetadataRecordA = new CredentialMetadataRecord(
Expand Down
11 changes: 4 additions & 7 deletions src/core/agent/services/credentialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class CredentialService extends AgentService {

const results = await this.signifyClient.credentials().list({
filter: {
"-d": { $eq: metadata.credentialRecordId },
"-d": { $eq: metadata.id.replace("metadata:", "") },
},
});
if (results.length > 0) {
Expand Down Expand Up @@ -162,17 +162,14 @@ class CredentialService extends AgentService {
credentialId: string,
dateTime: string
): Promise<void> {
const credentialDetails: CredentialShortDetails = {
const credentialDetails: CredentialMetadataRecordProps = {
id: `metadata:${credentialId}`,
isArchived: false,
credentialType: "",
issuanceDate: new Date(dateTime).toISOString(),
status: CredentialMetadataRecordStatus.PENDING,
};
await this.createMetadata({
...credentialDetails,
credentialRecordId: credentialId,
});
await this.createMetadata(credentialDetails);
}

async syncACDCs() {
Expand All @@ -182,7 +179,7 @@ class CredentialService extends AgentService {
const unSyncedData = signifyCredentials.filter(
(credential: any) =>
!storedCredentials.find(
(item) => credential.sad.d === item.credentialRecordId
(item) => credential.sad.d === item.id.replace("metadata:", "")
)
);
if (unSyncedData.length) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/agent/services/credentialService.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ enum CredentialStatus {

type CredentialShortDetails = Omit<
CredentialMetadataRecordProps,
"credentialRecordId" | "connectionId" | "createdAt" | "issuerLogo"
"connectionId" | "createdAt"
>;

type JSONValue =
Expand Down
1 change: 0 additions & 1 deletion src/core/agent/services/identifierService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ const credentialStorage = jest.mocked({
getAllCredentialMetadata: jest.fn(),
deleteCredentialMetadata: jest.fn(),
getCredentialMetadata: jest.fn(),
getCredentialMetadataByCredentialRecordId: jest.fn(),
getCredentialMetadataByConnectionId: jest.fn(),
saveCredentialMetadataRecord: jest.fn(),
updateCredentialMetadata: jest.fn(),
Expand Down
13 changes: 4 additions & 9 deletions src/core/agent/services/ipexCommunicationService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ const credentialStorage = jest.mocked({
getAllCredentialMetadata: jest.fn(),
deleteCredentialMetadata: jest.fn(),
getCredentialMetadata: jest.fn(),
getCredentialMetadataByCredentialRecordId: jest.fn(),
getCredentialMetadataByConnectionId: jest.fn(),
saveCredentialMetadataRecord: jest.fn(),
updateCredentialMetadata: jest.fn(),
Expand Down Expand Up @@ -168,11 +167,9 @@ describe("Ipex communication service of agent", () => {
},
},
]);
credentialStorage.getCredentialMetadataByCredentialRecordId = jest
.fn()
.mockResolvedValue({
id: "id",
});
credentialStorage.getCredentialMetadata = jest.fn().mockResolvedValue({
id: "id",
});
await ipexCommunicationService.acceptAcdc(id);
expect(credentialStorage.saveCredentialMetadataRecord).toBeCalled();
expect(credentialStorage.updateCredentialMetadata).toBeCalledWith("id", {
Expand Down Expand Up @@ -241,9 +238,7 @@ describe("Ipex communication service of agent", () => {
},
},
]);
credentialStorage.getCredentialMetadataByCredentialRecordId = jest
.fn()
.mockResolvedValue(null);
credentialStorage.getCredentialMetadata = jest.fn().mockResolvedValue(null);
await expect(ipexCommunicationService.acceptAcdc(id)).rejects.toThrowError(
IpexCommunicationService.CREDENTIAL_MISSING_METADATA_ERROR_MSG
);
Expand Down
21 changes: 11 additions & 10 deletions src/core/agent/services/ipexCommunicationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import {
AcdcStateChangedEvent,
KeriaNotification,
} from "../agent.types";
import { CredentialMetadataRecordStatus } from "../records/credentialMetadataRecord.types";
import {
CredentialMetadataRecordProps,
CredentialMetadataRecordStatus,
} from "../records/credentialMetadataRecord.types";
import { AgentService } from "./agentService";
import {
CredentialShortDetails,
Expand Down Expand Up @@ -117,10 +120,9 @@ class IpexCommunicationService extends AgentService {
id: string,
cred: any
): Promise<CredentialShortDetails> {
const metadata =
await this.credentialStorage.getCredentialMetadataByCredentialRecordId(
id
);
const metadata = await this.credentialStorage.getCredentialMetadata(
`metadata:${id}`
);
if (!metadata) {
throw new Error(
IpexCommunicationService.CREDENTIAL_MISSING_METADATA_ERROR_MSG
Expand All @@ -140,17 +142,16 @@ class IpexCommunicationService extends AgentService {
credentialId: string,
dateTime: string
): Promise<void> {
const credentialDetails: CredentialShortDetails = {
const credentialDetails: CredentialMetadataRecordProps = {
id: `metadata:${credentialId}`,
isArchived: false,
credentialType: "",
issuanceDate: new Date(dateTime).toISOString(),
status: CredentialMetadataRecordStatus.PENDING,
};
await this.credentialStorage.saveCredentialMetadataRecord({
...credentialDetails,
credentialRecordId: credentialId,
});
await this.credentialStorage.saveCredentialMetadataRecord(
credentialDetails
);
}

private async admitIpex(
Expand Down
1 change: 0 additions & 1 deletion src/ui/pages/IncomingRequest/IncomingRequest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ const credentialStorage = jest.mocked({
getAllCredentialMetadata: jest.fn(),
deleteCredentialMetadata: jest.fn(),
getCredentialMetadata: jest.fn(),
getCredentialMetadataByCredentialRecordId: jest.fn(),
getCredentialMetadataByConnectionId: jest.fn(),
saveCredentialMetadataRecord: jest.fn(),
updateCredentialMetadata: jest.fn(),
Expand Down

0 comments on commit 3d7c49b

Please sign in to comment.