Skip to content

Commit

Permalink
fix searchStatusList2021
Browse files Browse the repository at this point in the history
  • Loading branch information
DaevMithran committed Mar 3, 2025
1 parent ba4653b commit 70e4bfa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 15 deletions.
23 changes: 13 additions & 10 deletions src/services/identity/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,14 @@ import {
DefaultStatusList2021Encodings,
ICheqdSuspendBulkCredentialsWithStatusList2021Args,
ICheqdUnsuspendBulkCredentialsWithStatusList2021Args,
DIDMetadataDereferencingResult,
StatusList2021Revocation,
StatusList2021Suspension,
DefaultStatusList2021StatusPurposeType,
TransactionResult,
} from '@cheqd/did-provider-cheqd';
import { ResourceModule, type CheqdNetwork } from '@cheqd/sdk';
import { getDidKeyResolver as KeyDidResolver } from '@veramo/did-provider-key';
import { Resolver, ResolverRegistry } from 'did-resolver';
import { DIDResolutionResult, Resolver, ResolverRegistry } from 'did-resolver';
import { DefaultDidUrlPattern, CreateAgentRequest, VeramoAgent } from '../../types/shared.js';
import type { VerificationOptions } from '../../types/shared.js';
import type { FeePaymentOptions } from '../../types/credential-status.js';
Expand Down Expand Up @@ -829,15 +828,19 @@ export class Veramo {
const url = new URL(
`${process.env.RESOLVER_URL || DefaultResolverUrl}${did}?resourceName=${statusListName}&resourceType=${
DefaultStatusList2021ResourceTypes[statusPurpose]
}&resourceMetadata=true`
}`
);

try {
// fetch resource metadata
const resourceMetadataVersioned = (await (await fetch(url)).json()) as DIDMetadataDereferencingResult;
const resourceMetadataVersioned = (await (await fetch(url, {
headers: {
"Accept": "application/ld+json;profile=https://w3id.org/did-resolution"
}
})).json()) as DIDResolutionResult;

// define arbitrary error
const arbitraryError = resourceMetadataVersioned?.dereferencingMetadata?.error;
const arbitraryError = resourceMetadataVersioned?.didResolutionMetadata?.error;

// handle error
if (arbitraryError) {
Expand All @@ -848,16 +851,16 @@ export class Veramo {
}

// early return, if no resource metadata
if (!resourceMetadataVersioned?.contentStream?.linkedResourceMetadata)
if (!resourceMetadataVersioned?.didDocumentMetadata?.linkedResourceMetadata)
return { found: false, error: 'notFound' } satisfies SearchStatusListResult;

// get latest resource version by nextVersionId null pointer, or by latest created date as fallback
const resourceMetadata =
resourceMetadataVersioned.contentStream.linkedResourceMetadata.find(
(resource) => !resource.nextVersionId
resourceMetadataVersioned.didDocumentMetadata.linkedResourceMetadata.find(
(resource: any) => !resource.nextVersionId
) ||
resourceMetadataVersioned.contentStream.linkedResourceMetadata.sort(
(a, b) => new Date(b.created).getTime() - new Date(a.created).getTime()
resourceMetadataVersioned.didDocumentMetadata.linkedResourceMetadata.sort(
(a: any, b: any) => new Date(b.created).getTime() - new Date(a.created).getTime()
)[0];

// unset resourceMetadata
Expand Down
1 change: 1 addition & 0 deletions tests/e2e/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum GENERATED_PATH {

export enum CONTENT_TYPE {
APPLICATION_JSON = 'application/json',
APPLICATION_LD_JSON = 'application/ld+json',
APPLICATION_DID_LD_JSON = 'application/did+ld+json',
APPLICATION_X_WWW_FORM_URLENCODED = 'application/x-www-form-urlencoded',
}
Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/parallel/did/search-no-auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test('[Positive] It can search with an existent DID', async ({ request }) => {

const body = await response.json();

expect(body.didResolutionMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_DID_LD_JSON);
expect(body.didResolutionMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON);
expect(body.didResolutionMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID);
expect(body.didResolutionMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER);
expect(body.didResolutionMetadata.did.method).toBe(DID_METHOD);
Expand All @@ -32,7 +32,7 @@ test('[Positive] It can search with an existent DID and metadata=true query para

const body = await response.json();

expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_DID_LD_JSON);
expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON);

Check failure on line 35 in tests/e2e/parallel/did/search-no-auth.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › tests/e2e/parallel/did/search-no-auth.spec.ts:29:1 › [Positive] It can search with an existent DID and metadata=true query parameter

2) [Parallel Logged In User Tests] › tests/e2e/parallel/did/search-no-auth.spec.ts:29:1 › [Positive] It can search with an existent DID and metadata=true query parameter TypeError: Cannot read properties of undefined (reading 'contentType') 33 | const body = await response.json(); 34 | > 35 | expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON); | ^ 36 | expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID); 37 | expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER); 38 | expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD); at /home/runner/work/studio/studio/tests/e2e/parallel/did/search-no-auth.spec.ts:35:36

Check failure on line 35 in tests/e2e/parallel/did/search-no-auth.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › tests/e2e/parallel/did/search-no-auth.spec.ts:29:1 › [Positive] It can search with an existent DID and metadata=true query parameter

2) [Parallel Logged In User Tests] › tests/e2e/parallel/did/search-no-auth.spec.ts:29:1 › [Positive] It can search with an existent DID and metadata=true query parameter Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'contentType') 33 | const body = await response.json(); 34 | > 35 | expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON); | ^ 36 | expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID); 37 | expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER); 38 | expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD); at /home/runner/work/studio/studio/tests/e2e/parallel/did/search-no-auth.spec.ts:35:36

Check failure on line 35 in tests/e2e/parallel/did/search-no-auth.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › tests/e2e/parallel/did/search-no-auth.spec.ts:29:1 › [Positive] It can search with an existent DID and metadata=true query parameter

2) [Parallel Logged In User Tests] › tests/e2e/parallel/did/search-no-auth.spec.ts:29:1 › [Positive] It can search with an existent DID and metadata=true query parameter Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'contentType') 33 | const body = await response.json(); 34 | > 35 | expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON); | ^ 36 | expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID); 37 | expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER); 38 | expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD); at /home/runner/work/studio/studio/tests/e2e/parallel/did/search-no-auth.spec.ts:35:36
expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID);
expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER);
expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD);
Expand All @@ -49,7 +49,7 @@ test('[Positive] It can search with an existent DID and fragment', async ({ requ

const body = await response.json();

expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_DID_LD_JSON);
expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON);
expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID);
expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER);
expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD);
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/parallel/resource/search-no-auth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ test('[Positive] It can search resource with an existent DID and resourceMetadat

const body = await response.json();

expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_DID_LD_JSON);
expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON);

Check failure on line 53 in tests/e2e/parallel/resource/search-no-auth.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › tests/e2e/parallel/resource/search-no-auth.spec.ts:45:1 › [Positive] It can search resource with an existent DID and resourceMetadata=true query parameter

3) [Parallel Logged In User Tests] › tests/e2e/parallel/resource/search-no-auth.spec.ts:45:1 › [Positive] It can search resource with an existent DID and resourceMetadata=true query parameter TypeError: Cannot read properties of undefined (reading 'contentType') 51 | const body = await response.json(); 52 | > 53 | expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON); | ^ 54 | expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID); 55 | expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER); 56 | expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD); at /home/runner/work/studio/studio/tests/e2e/parallel/resource/search-no-auth.spec.ts:53:36

Check failure on line 53 in tests/e2e/parallel/resource/search-no-auth.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › tests/e2e/parallel/resource/search-no-auth.spec.ts:45:1 › [Positive] It can search resource with an existent DID and resourceMetadata=true query parameter

3) [Parallel Logged In User Tests] › tests/e2e/parallel/resource/search-no-auth.spec.ts:45:1 › [Positive] It can search resource with an existent DID and resourceMetadata=true query parameter Retry #1 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'contentType') 51 | const body = await response.json(); 52 | > 53 | expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON); | ^ 54 | expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID); 55 | expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER); 56 | expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD); at /home/runner/work/studio/studio/tests/e2e/parallel/resource/search-no-auth.spec.ts:53:36

Check failure on line 53 in tests/e2e/parallel/resource/search-no-auth.spec.ts

View workflow job for this annotation

GitHub Actions / Build & Test / Build Node.js

[Parallel Logged In User Tests] › tests/e2e/parallel/resource/search-no-auth.spec.ts:45:1 › [Positive] It can search resource with an existent DID and resourceMetadata=true query parameter

3) [Parallel Logged In User Tests] › tests/e2e/parallel/resource/search-no-auth.spec.ts:45:1 › [Positive] It can search resource with an existent DID and resourceMetadata=true query parameter Retry #2 ─────────────────────────────────────────────────────────────────────────────────────── TypeError: Cannot read properties of undefined (reading 'contentType') 51 | const body = await response.json(); 52 | > 53 | expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON); | ^ 54 | expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID); 55 | expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER); 56 | expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD); at /home/runner/work/studio/studio/tests/e2e/parallel/resource/search-no-auth.spec.ts:53:36
expect(body.dereferencingMetadata.did.didString).toStrictEqual(DEFAULT_TESTNET_DID);
expect(body.dereferencingMetadata.did.methodSpecificId).toBe(DEFAULT_TESTNET_DID_IDENTIFIER);
expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD);
Expand All @@ -66,7 +66,7 @@ test('[Negative] It cannot search not existent {did} and {resourceId}', async ({

const body = await response.json();

expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_DID_LD_JSON);
expect(body.dereferencingMetadata.contentType).toBe(CONTENT_TYPE.APPLICATION_LD_JSON);
expect(body.dereferencingMetadata.did.didString).toStrictEqual(NOT_EXISTENT_TESTNET_DID);
expect(body.dereferencingMetadata.did.methodSpecificId).toBe(NOT_EXISTENT_TESTNET_DID_IDENTIFIER);
expect(body.dereferencingMetadata.did.method).toBe(DID_METHOD);
Expand Down

0 comments on commit 70e4bfa

Please sign in to comment.