diff --git a/packages/anoncreds/src/anoncreds-rs/__tests__/AnonCredsRsServices.test.ts b/packages/anoncreds/src/anoncreds-rs/__tests__/AnonCredsRsServices.test.ts index a371e7189d..67df21076a 100644 --- a/packages/anoncreds/src/anoncreds-rs/__tests__/AnonCredsRsServices.test.ts +++ b/packages/anoncreds/src/anoncreds-rs/__tests__/AnonCredsRsServices.test.ts @@ -205,6 +205,8 @@ describe('AnonCredsRsServices', () => { revocationRegistryId: null, credentialRevocationId: null, methodName: 'inMemory', + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }) const proofRequest: AnonCredsProofRequest = { @@ -410,6 +412,8 @@ describe('AnonCredsRsServices', () => { revocationRegistryId: null, credentialRevocationId: null, methodName: 'inMemory', + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }) const proofRequest: AnonCredsProofRequest = { diff --git a/packages/anoncreds/src/anoncreds-rs/__tests__/helpers.ts b/packages/anoncreds/src/anoncreds-rs/__tests__/helpers.ts index d17de9534a..6369e11a39 100644 --- a/packages/anoncreds/src/anoncreds-rs/__tests__/helpers.ts +++ b/packages/anoncreds/src/anoncreds-rs/__tests__/helpers.ts @@ -174,6 +174,8 @@ export async function createCredentialForHolder(options: { methodName: 'inMemory', credentialRevocationId: null, revocationRegistryId: null, + createdAt: new Date('2024-01-01T00:00:00Z'), + updatedAt: new Date('2024-01-01T00:00:00Z'), } const returnObj = { credential: w3cJsonLdCredential, diff --git a/packages/anoncreds/src/formats/__tests__/legacy-indy-format-services.test.ts b/packages/anoncreds/src/formats/__tests__/legacy-indy-format-services.test.ts index 2aa9505ae8..6e8f607d58 100644 --- a/packages/anoncreds/src/formats/__tests__/legacy-indy-format-services.test.ts +++ b/packages/anoncreds/src/formats/__tests__/legacy-indy-format-services.test.ts @@ -314,6 +314,8 @@ describe('Legacy indy format services', () => { revocationRegistryId: null, credentialRevocationId: null, methodName: 'inMemory', + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }) expect(holderCredentialRecord.metadata.data).toEqual({ diff --git a/packages/anoncreds/src/models/internal.ts b/packages/anoncreds/src/models/internal.ts index ef815cbe9b..d626bd84b1 100644 --- a/packages/anoncreds/src/models/internal.ts +++ b/packages/anoncreds/src/models/internal.ts @@ -8,6 +8,8 @@ export interface AnonCredsCredentialInfo { revocationRegistryId: string | null credentialRevocationId: string | null methodName: string + createdAt: Date + updatedAt: Date linkSecretId: string } diff --git a/packages/anoncreds/src/utils/__tests__/sortRequestedCredentialsMatches.test.ts b/packages/anoncreds/src/utils/__tests__/sortRequestedCredentialsMatches.test.ts index 0bd658a646..89a56ab5c9 100644 --- a/packages/anoncreds/src/utils/__tests__/sortRequestedCredentialsMatches.test.ts +++ b/packages/anoncreds/src/utils/__tests__/sortRequestedCredentialsMatches.test.ts @@ -2,26 +2,29 @@ import type { AnonCredsCredentialInfo, AnonCredsRequestedAttributeMatch } from ' import { sortRequestedCredentialsMatches } from '../sortRequestedCredentialsMatches' -const credentialInfo = {} as unknown as AnonCredsCredentialInfo +const credentialInfo = { + updatedAt: new Date('2024-01-01T00:00:00Z'), + createdAt: new Date('2024-01-01T00:00:00Z'), +} as unknown as AnonCredsCredentialInfo const credentials: AnonCredsRequestedAttributeMatch[] = [ { credentialId: '1', revealed: true, revoked: true, - credentialInfo, + credentialInfo: { ...credentialInfo, updatedAt: new Date('2024-01-01T00:00:01Z') }, }, { credentialId: '2', revealed: true, revoked: undefined, - credentialInfo, + credentialInfo: { ...credentialInfo, updatedAt: new Date('2024-01-01T00:00:01Z') }, }, { credentialId: '3', revealed: true, revoked: false, - credentialInfo, + credentialInfo: { ...credentialInfo, updatedAt: new Date('2024-01-01T00:00:01Z') }, }, { credentialId: '4', diff --git a/packages/anoncreds/src/utils/sortRequestedCredentialsMatches.ts b/packages/anoncreds/src/utils/sortRequestedCredentialsMatches.ts index 1d190c7e31..e7f2d7a2f9 100644 --- a/packages/anoncreds/src/utils/sortRequestedCredentialsMatches.ts +++ b/packages/anoncreds/src/utils/sortRequestedCredentialsMatches.ts @@ -9,7 +9,6 @@ import type { AnonCredsRequestedAttributeMatch, AnonCredsRequestedPredicateMatch export function sortRequestedCredentialsMatches< Requested extends Array | Array >(credentials: Requested) { - const staySame = 0 const credentialGoUp = -1 const credentialGoDown = 1 @@ -18,7 +17,8 @@ export function sortRequestedCredentialsMatches< return credentialsClone.sort((credential, compareTo) => { // Nothing needs to happen if values are the same - if (credential.revoked === compareTo.revoked) return staySame + if (credential.revoked === compareTo.revoked) + return compareTo.credentialInfo.updatedAt.getTime() - credential.credentialInfo.updatedAt.getTime() // Undefined always is at the top if (credential.revoked === undefined) return credentialGoUp diff --git a/packages/anoncreds/src/utils/w3cAnonCredsUtils.ts b/packages/anoncreds/src/utils/w3cAnonCredsUtils.ts index eff87342f0..fe9bfa0c58 100644 --- a/packages/anoncreds/src/utils/w3cAnonCredsUtils.ts +++ b/packages/anoncreds/src/utils/w3cAnonCredsUtils.ts @@ -69,6 +69,8 @@ function anonCredsCredentialInfoFromW3cRecord(w3cCredentialRecord: W3cCredential revocationRegistryId: anonCredsTags.anonCredsRevocationRegistryId ?? null, methodName: anonCredsCredentialMetadata.methodName, linkSecretId: anonCredsCredentialMetadata.linkSecretId, + createdAt: w3cCredentialRecord.createdAt, + updatedAt: w3cCredentialRecord.updatedAt ?? w3cCredentialRecord.createdAt, } } @@ -89,6 +91,8 @@ function anonCredsCredentialInfoFromAnonCredsRecord( revocationRegistryId: anonCredsCredentialRecord.credential.rev_reg_id ?? null, methodName: anonCredsCredentialRecord.methodName, linkSecretId: anonCredsCredentialRecord.linkSecretId, + createdAt: anonCredsCredentialRecord.createdAt, + updatedAt: anonCredsCredentialRecord.updatedAt ?? anonCredsCredentialRecord.createdAt, } } diff --git a/packages/anoncreds/tests/anoncreds-flow.test.ts b/packages/anoncreds/tests/anoncreds-flow.test.ts index e17017a73c..70dc6372bd 100644 --- a/packages/anoncreds/tests/anoncreds-flow.test.ts +++ b/packages/anoncreds/tests/anoncreds-flow.test.ts @@ -373,6 +373,8 @@ async function anonCredsFlowTest(options: { issuerId: string; revocable: boolean revocationRegistryId: revocable ? revocationRegistryDefinitionId : null, credentialRevocationId: revocable ? '1' : null, methodName: 'inMemory', + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }) const expectedCredentialMetadata = revocable diff --git a/packages/anoncreds/tests/data-integrity-flow-anoncreds.test.ts b/packages/anoncreds/tests/data-integrity-flow-anoncreds.test.ts index 16fb05708d..47392a4af1 100644 --- a/packages/anoncreds/tests/data-integrity-flow-anoncreds.test.ts +++ b/packages/anoncreds/tests/data-integrity-flow-anoncreds.test.ts @@ -403,6 +403,8 @@ async function anonCredsFlowTest(options: { issuerId: string; revocable: boolean revocationRegistryId: revocable ? revocationRegistryDefinitionId : null, credentialRevocationId: revocable ? '1' : null, methodName: 'inMemory', + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }) const expectedCredentialMetadata = revocable diff --git a/packages/anoncreds/tests/indy-flow.test.ts b/packages/anoncreds/tests/indy-flow.test.ts index ec81e3cf85..c50e57d5ae 100644 --- a/packages/anoncreds/tests/indy-flow.test.ts +++ b/packages/anoncreds/tests/indy-flow.test.ts @@ -303,6 +303,8 @@ describe('Legacy indy format services using anoncreds-rs', () => { credentialRevocationId: null, methodName: 'inMemory', linkSecretId: 'linkSecretId', + createdAt: expect.any(Date), + updatedAt: expect.any(Date), }) expect(holderCredentialRecord.metadata.data).toEqual({