From dbd9a0e8001cee426a3d1fb1556e7569863a9aa1 Mon Sep 17 00:00:00 2001 From: jrhender Date: Tue, 14 Jan 2025 21:35:01 -0800 Subject: [PATCH 1/6] feat(ipfs.service): add timeout to get --- ...odules_auth_login_strategy.AuthStrategy.md | 223 ++++++++++++++++++ src/modules/ipfs/ipfs.service.ts | 12 +- 2 files changed, 234 insertions(+), 1 deletion(-) diff --git a/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md b/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md index 570a77fab..5844f88e5 100644 --- a/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md +++ b/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md @@ -14,6 +14,19 @@ - [constructor](modules_auth_login_strategy.AuthStrategy.md#constructor) +### Methods + +- [authenticate](modules_auth_login_strategy.AuthStrategy.md#authenticate) +- [decodeToken](modules_auth_login_strategy.AuthStrategy.md#decodetoken) +- [didUnification](modules_auth_login_strategy.AuthStrategy.md#didunification) +- [extractSiwe](modules_auth_login_strategy.AuthStrategy.md#extractsiwe) +- [extractToken](modules_auth_login_strategy.AuthStrategy.md#extracttoken) +- [getRoleDefinition](modules_auth_login_strategy.AuthStrategy.md#getroledefinition) +- [isEIP191TokenPayload](modules_auth_login_strategy.AuthStrategy.md#iseip191tokenpayload) +- [isSiweMessagePayload](modules_auth_login_strategy.AuthStrategy.md#issiwemessagepayload) +- [validate](modules_auth_login_strategy.AuthStrategy.md#validate) +- [verifyIssuer](modules_auth_login_strategy.AuthStrategy.md#verifyissuer) + ## Constructors ### constructor @@ -33,3 +46,213 @@ #### Overrides PassportStrategy(LoginStrategy, 'login').constructor + +## Methods + +### authenticate + +▸ **authenticate**(`req`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | + +#### Returns + +`void` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').authenticate + +___ + +### decodeToken + +▸ **decodeToken**<`T`\>(`token`, `options?`): `T` + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `token` | `string` | +| `options?` | `DecodeOptions` | + +#### Returns + +`T` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').decodeToken + +___ + +### didUnification + +▸ **didUnification**(`did`): `string` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `did` | `string` | + +#### Returns + +`string` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').didUnification + +___ + +### extractSiwe + +▸ **extractSiwe**(`req`): `SiweReqPayload` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | + +#### Returns + +`SiweReqPayload` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').extractSiwe + +___ + +### extractToken + +▸ **extractToken**(`req`): `string` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | + +#### Returns + +`string` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').extractToken + +___ + +### getRoleDefinition + +▸ **getRoleDefinition**(`namespace`): `Promise`<`IRoleDefinitionV2`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `namespace` | `string` | + +#### Returns + +`Promise`<`IRoleDefinitionV2`\> + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').getRoleDefinition + +___ + +### isEIP191TokenPayload + +▸ **isEIP191TokenPayload**(`payload`): payload is ITokenPayload + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `payload` | `unknown` | + +#### Returns + +payload is ITokenPayload + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').isEIP191TokenPayload + +___ + +### isSiweMessagePayload + +▸ **isSiweMessagePayload**(`payload`): payload is Partial + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `payload` | `unknown` | + +#### Returns + +payload is Partial + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').isSiweMessagePayload + +___ + +### validate + +▸ **validate**(`token`, `payload`, `done`): `Promise`<`void`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `token` | `string` | +| `payload` | `Partial`<`SiweMessage`\> \| `ITokenPayload` | +| `done` | (`err?`: `Error`, `user?`: `unknown`, `info?`: `unknown`) => `void` | + +#### Returns + +`Promise`<`void`\> + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').validate + +___ + +### verifyIssuer + +▸ **verifyIssuer**(`issuer`, `role`): `Promise`<`VerificationResult`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `issuer` | `string` | +| `role` | `string` | + +#### Returns + +`Promise`<`VerificationResult`\> + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').verifyIssuer diff --git a/src/modules/ipfs/ipfs.service.ts b/src/modules/ipfs/ipfs.service.ts index 14035e71d..2a68b6c16 100644 --- a/src/modules/ipfs/ipfs.service.ts +++ b/src/modules/ipfs/ipfs.service.ts @@ -60,12 +60,22 @@ export class IPFSService { let claim: string; const getFromCluster = this.didStoreCluster.get(cid); const getFromInfura = this.didStoreInfura.get(cid); + const timeout = new Promise( + (_, reject) => + setTimeout(() => reject(new Error('Request timed out')), 5000) // 5 seconds timeout + ); + + this.logger.debug(`trying to get ${cid}`); try { - claim = await Promise.any([getFromCluster, getFromInfura]); + claim = await Promise.race([ + Promise.any([getFromCluster, getFromInfura]), + timeout, + ]); } catch (e) { // TODO: catch this in DidService throw new HttpException(`Claim ${cid} not found`, HttpStatus.NOT_FOUND); } + this.logger.debug(`got ${cid}`); try { await this.pinsQueue.add(PIN_CLAIM_JOB_NAME, { cid, claim }); From 7bd7c35c3f9d471de7ae31ef6e63d44c1f25fa79 Mon Sep 17 00:00:00 2001 From: JGiter Date: Wed, 15 Jan 2025 10:30:47 +0200 Subject: [PATCH 2/6] feat: skip not resolved claim --- ...odules_auth_login_strategy.AuthStrategy.md | 223 ------------------ src/modules/did/did.service.ts | 7 +- src/modules/ipfs/ipfs.service.ts | 6 +- 3 files changed, 10 insertions(+), 226 deletions(-) diff --git a/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md b/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md index 5844f88e5..570a77fab 100644 --- a/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md +++ b/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md @@ -14,19 +14,6 @@ - [constructor](modules_auth_login_strategy.AuthStrategy.md#constructor) -### Methods - -- [authenticate](modules_auth_login_strategy.AuthStrategy.md#authenticate) -- [decodeToken](modules_auth_login_strategy.AuthStrategy.md#decodetoken) -- [didUnification](modules_auth_login_strategy.AuthStrategy.md#didunification) -- [extractSiwe](modules_auth_login_strategy.AuthStrategy.md#extractsiwe) -- [extractToken](modules_auth_login_strategy.AuthStrategy.md#extracttoken) -- [getRoleDefinition](modules_auth_login_strategy.AuthStrategy.md#getroledefinition) -- [isEIP191TokenPayload](modules_auth_login_strategy.AuthStrategy.md#iseip191tokenpayload) -- [isSiweMessagePayload](modules_auth_login_strategy.AuthStrategy.md#issiwemessagepayload) -- [validate](modules_auth_login_strategy.AuthStrategy.md#validate) -- [verifyIssuer](modules_auth_login_strategy.AuthStrategy.md#verifyissuer) - ## Constructors ### constructor @@ -46,213 +33,3 @@ #### Overrides PassportStrategy(LoginStrategy, 'login').constructor - -## Methods - -### authenticate - -▸ **authenticate**(`req`): `void` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | - -#### Returns - -`void` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').authenticate - -___ - -### decodeToken - -▸ **decodeToken**<`T`\>(`token`, `options?`): `T` - -#### Type parameters - -| Name | -| :------ | -| `T` | - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `token` | `string` | -| `options?` | `DecodeOptions` | - -#### Returns - -`T` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').decodeToken - -___ - -### didUnification - -▸ **didUnification**(`did`): `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `did` | `string` | - -#### Returns - -`string` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').didUnification - -___ - -### extractSiwe - -▸ **extractSiwe**(`req`): `SiweReqPayload` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | - -#### Returns - -`SiweReqPayload` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').extractSiwe - -___ - -### extractToken - -▸ **extractToken**(`req`): `string` - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | - -#### Returns - -`string` - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').extractToken - -___ - -### getRoleDefinition - -▸ **getRoleDefinition**(`namespace`): `Promise`<`IRoleDefinitionV2`\> - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `namespace` | `string` | - -#### Returns - -`Promise`<`IRoleDefinitionV2`\> - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').getRoleDefinition - -___ - -### isEIP191TokenPayload - -▸ **isEIP191TokenPayload**(`payload`): payload is ITokenPayload - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `payload` | `unknown` | - -#### Returns - -payload is ITokenPayload - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').isEIP191TokenPayload - -___ - -### isSiweMessagePayload - -▸ **isSiweMessagePayload**(`payload`): payload is Partial - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `payload` | `unknown` | - -#### Returns - -payload is Partial - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').isSiweMessagePayload - -___ - -### validate - -▸ **validate**(`token`, `payload`, `done`): `Promise`<`void`\> - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `token` | `string` | -| `payload` | `Partial`<`SiweMessage`\> \| `ITokenPayload` | -| `done` | (`err?`: `Error`, `user?`: `unknown`, `info?`: `unknown`) => `void` | - -#### Returns - -`Promise`<`void`\> - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').validate - -___ - -### verifyIssuer - -▸ **verifyIssuer**(`issuer`, `role`): `Promise`<`VerificationResult`\> - -#### Parameters - -| Name | Type | -| :------ | :------ | -| `issuer` | `string` | -| `role` | `string` | - -#### Returns - -`Promise`<`VerificationResult`\> - -#### Inherited from - -PassportStrategy(LoginStrategy, 'login').verifyIssuer diff --git a/src/modules/did/did.service.ts b/src/modules/did/did.service.ts index 0180e8b8f..395e4318f 100644 --- a/src/modules/did/did.service.ts +++ b/src/modules/did/did.service.ts @@ -439,7 +439,12 @@ export class DIDService implements OnModuleInit, OnModuleDestroy { return { serviceEndpoint, ...rest }; } - const token = await this.ipfsService.get(serviceEndpoint); + let token: string; + try { + token = await this.ipfsService.get(serviceEndpoint); + } catch (e) { + return { serviceEndpoint, ...rest }; + } if (isJWT(token)) { const decodedData = jwt.decode(token) as { diff --git a/src/modules/ipfs/ipfs.service.ts b/src/modules/ipfs/ipfs.service.ts index 2a68b6c16..21c1fdce9 100644 --- a/src/modules/ipfs/ipfs.service.ts +++ b/src/modules/ipfs/ipfs.service.ts @@ -72,8 +72,10 @@ export class IPFSService { timeout, ]); } catch (e) { - // TODO: catch this in DidService - throw new HttpException(`Claim ${cid} not found`, HttpStatus.NOT_FOUND); + throw new HttpException( + `Claim ${cid} not resolved`, + HttpStatus.NOT_FOUND + ); } this.logger.debug(`got ${cid}`); From 50520732cd9d960b498a2cd4742b005aba0fe222 Mon Sep 17 00:00:00 2001 From: JGiter Date: Wed, 15 Jan 2025 10:54:11 +0200 Subject: [PATCH 3/6] build: updgrade @energyweb/vc-verification@2.2.1-alpha.321 --- package-lock.json | 4 ++-- package.json | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0cc490866..eabdbe6bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,8 +9,8 @@ "version": "2.12.1", "license": "UNLICENSED", "dependencies": { - "@energyweb/credential-governance": "^2.2.1-alpha.316.0", - "@energyweb/vc-verification": "^2.2.1-alpha.316.0", + "@energyweb/credential-governance": "^2.2.1-alpha.321.0", + "@energyweb/vc-verification": "^2.2.1-alpha.321.0", "@ensdomains/ens-contracts": "^0.0.21", "@ensdomains/resolver": "^0.2.4", "@ew-did-registry/claims": "0.8.1-alpha.1140.0", diff --git a/package.json b/package.json index 0bc8b70b9..c71af350c 100644 --- a/package.json +++ b/package.json @@ -53,8 +53,8 @@ "db:truncate": "ts-node -P tsconfig.json src/scripts/truncate-db.ts" }, "dependencies": { - "@energyweb/credential-governance": "^2.2.1-alpha.316.0", - "@energyweb/vc-verification": "^2.2.1-alpha.316.0", + "@energyweb/credential-governance": "^2.2.1-alpha.321.0", + "@energyweb/vc-verification": "^2.2.1-alpha.321.0", "@ensdomains/ens-contracts": "^0.0.21", "@ensdomains/resolver": "^0.2.4", "@ew-did-registry/claims": "0.8.1-alpha.1140.0", From 0b005a1fcc8f5050a101763a3de228d3493e36c3 Mon Sep 17 00:00:00 2001 From: JGiter Date: Wed, 15 Jan 2025 10:55:54 +0200 Subject: [PATCH 4/6] build: install eth-ens-namehash --- package-lock.json | 1 + package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/package-lock.json b/package-lock.json index eabdbe6bc..d3843990d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -56,6 +56,7 @@ "didStoreCluster": "npm:@ew-did-registry/did-ipfs-store@0.8.1-alpha.1140.0", "didStoreInfura": "npm:@ew-did-registry/did-ipfs-store@0.7.1-alpha.795.0", "dotenv": "^16.0.3", + "eth-ens-namehash": "^2.0.8", "ethers": "5.7.2", "graphql": "^16.6.0", "graphql-fields": "^2.0.3", diff --git a/package.json b/package.json index c71af350c..281057056 100644 --- a/package.json +++ b/package.json @@ -100,6 +100,7 @@ "didStoreCluster": "npm:@ew-did-registry/did-ipfs-store@0.8.1-alpha.1140.0", "didStoreInfura": "npm:@ew-did-registry/did-ipfs-store@0.7.1-alpha.795.0", "dotenv": "^16.0.3", + "eth-ens-namehash": "^2.0.8", "ethers": "5.7.2", "graphql": "^16.6.0", "graphql-fields": "^2.0.3", From f5d487912ea28c447b8492acdf54da1457b88754 Mon Sep 17 00:00:00 2001 From: JGiter Date: Wed, 15 Jan 2025 11:35:23 +0200 Subject: [PATCH 5/6] fix: skip not resolved creds --- ...odules_auth_login_strategy.AuthStrategy.md | 223 ++++++++++++++++++ .../modules_did_did_service.DIDService.md | 10 +- .../claim/resolvers/credential.resolver.ts | 8 +- src/modules/did/did.service.ts | 18 +- 4 files changed, 241 insertions(+), 18 deletions(-) diff --git a/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md b/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md index 570a77fab..5844f88e5 100644 --- a/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md +++ b/docs/api/classes/modules_auth_login_strategy.AuthStrategy.md @@ -14,6 +14,19 @@ - [constructor](modules_auth_login_strategy.AuthStrategy.md#constructor) +### Methods + +- [authenticate](modules_auth_login_strategy.AuthStrategy.md#authenticate) +- [decodeToken](modules_auth_login_strategy.AuthStrategy.md#decodetoken) +- [didUnification](modules_auth_login_strategy.AuthStrategy.md#didunification) +- [extractSiwe](modules_auth_login_strategy.AuthStrategy.md#extractsiwe) +- [extractToken](modules_auth_login_strategy.AuthStrategy.md#extracttoken) +- [getRoleDefinition](modules_auth_login_strategy.AuthStrategy.md#getroledefinition) +- [isEIP191TokenPayload](modules_auth_login_strategy.AuthStrategy.md#iseip191tokenpayload) +- [isSiweMessagePayload](modules_auth_login_strategy.AuthStrategy.md#issiwemessagepayload) +- [validate](modules_auth_login_strategy.AuthStrategy.md#validate) +- [verifyIssuer](modules_auth_login_strategy.AuthStrategy.md#verifyissuer) + ## Constructors ### constructor @@ -33,3 +46,213 @@ #### Overrides PassportStrategy(LoginStrategy, 'login').constructor + +## Methods + +### authenticate + +▸ **authenticate**(`req`): `void` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | + +#### Returns + +`void` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').authenticate + +___ + +### decodeToken + +▸ **decodeToken**<`T`\>(`token`, `options?`): `T` + +#### Type parameters + +| Name | +| :------ | +| `T` | + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `token` | `string` | +| `options?` | `DecodeOptions` | + +#### Returns + +`T` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').decodeToken + +___ + +### didUnification + +▸ **didUnification**(`did`): `string` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `did` | `string` | + +#### Returns + +`string` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').didUnification + +___ + +### extractSiwe + +▸ **extractSiwe**(`req`): `SiweReqPayload` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | + +#### Returns + +`SiweReqPayload` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').extractSiwe + +___ + +### extractToken + +▸ **extractToken**(`req`): `string` + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `req` | `Request`<`ParamsDictionary`, `any`, `any`, `ParsedQs`, `Record`<`string`, `any`\>\> | + +#### Returns + +`string` + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').extractToken + +___ + +### getRoleDefinition + +▸ **getRoleDefinition**(`namespace`): `Promise`<`IRoleDefinitionV2`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `namespace` | `string` | + +#### Returns + +`Promise`<`IRoleDefinitionV2`\> + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').getRoleDefinition + +___ + +### isEIP191TokenPayload + +▸ **isEIP191TokenPayload**(`payload`): payload is ITokenPayload + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `payload` | `unknown` | + +#### Returns + +payload is ITokenPayload + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').isEIP191TokenPayload + +___ + +### isSiweMessagePayload + +▸ **isSiweMessagePayload**(`payload`): payload is Partial + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `payload` | `unknown` | + +#### Returns + +payload is Partial + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').isSiweMessagePayload + +___ + +### validate + +▸ **validate**(`token`, `payload`, `done`): `Promise`<`void`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `token` | `string` | +| `payload` | `Partial`<`SiweMessage`\> \| `ITokenPayload` | +| `done` | (`err?`: `Error`, `user?`: `unknown`, `info?`: `unknown`) => `void` | + +#### Returns + +`Promise`<`void`\> + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').validate + +___ + +### verifyIssuer + +▸ **verifyIssuer**(`issuer`, `role`): `Promise`<`VerificationResult`\> + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `issuer` | `string` | +| `role` | `string` | + +#### Returns + +`Promise`<`VerificationResult`\> + +#### Inherited from + +PassportStrategy(LoginStrategy, 'login').verifyIssuer diff --git a/docs/api/classes/modules_did_did_service.DIDService.md b/docs/api/classes/modules_did_did_service.DIDService.md index bb7ef485a..c89568193 100644 --- a/docs/api/classes/modules_did_did_service.DIDService.md +++ b/docs/api/classes/modules_did_did_service.DIDService.md @@ -22,7 +22,7 @@ - [obscureDid](modules_did_did_service.DIDService.md#obscuredid) - [onModuleDestroy](modules_did_did_service.DIDService.md#onmoduledestroy) - [onModuleInit](modules_did_did_service.DIDService.md#onmoduleinit) -- [resolveServiceEndpoints](modules_did_did_service.DIDService.md#resolveserviceendpoints) +- [resolveCredentials](modules_did_did_service.DIDService.md#resolvecredentials) ## Constructors @@ -167,11 +167,11 @@ OnModuleInit.onModuleInit ___ -### resolveServiceEndpoints +### resolveCredentials -▸ **resolveServiceEndpoints**(`did`): `Promise`<`string`[]\> +▸ **resolveCredentials**(`did`): `Promise`<`any`[]\> -Resolves document service endponts +Resolves service endponts, which represent credentials #### Parameters @@ -181,4 +181,4 @@ Resolves document service endponts #### Returns -`Promise`<`string`[]\> +`Promise`<`any`[]\> diff --git a/src/modules/claim/resolvers/credential.resolver.ts b/src/modules/claim/resolvers/credential.resolver.ts index 6fcc1358c..0e16bda91 100644 --- a/src/modules/claim/resolvers/credential.resolver.ts +++ b/src/modules/claim/resolvers/credential.resolver.ts @@ -23,9 +23,7 @@ export class RoleCredentialResolver implements CredentialResolver { ): Promise< VerifiableCredential | RoleEIP191JWT | null > { - const resolvedEndpoints = await this.didService.resolveServiceEndpoints( - did - ); + const resolvedEndpoints = await this.didService.resolveCredentials(did); return ( this.serviceEndpointsToCredentials(resolvedEndpoints).find( (cred) => cred?.credentialSubject?.role?.namespace === namespace @@ -57,7 +55,7 @@ export class RoleCredentialResolver implements CredentialResolver { async eip191JwtsOf(subject: string): Promise { return this.serviceEndpointsToEIP191( - await this.didService.resolveServiceEndpoints(subject) + await this.didService.resolveCredentials(subject) ); } @@ -65,7 +63,7 @@ export class RoleCredentialResolver implements CredentialResolver { subject: string ): Promise[]> { return this.serviceEndpointsToCredentials( - await this.didService.resolveServiceEndpoints(subject) + await this.didService.resolveCredentials(subject) ); } diff --git a/src/modules/did/did.service.ts b/src/modules/did/did.service.ts index 395e4318f..b4ef40891 100644 --- a/src/modules/did/did.service.ts +++ b/src/modules/did/did.service.ts @@ -322,18 +322,20 @@ export class DIDService implements OnModuleInit, OnModuleDestroy { } /** - * Resolves document service endponts + * Resolves service endponts, which represent credentials * * @param did DID of the document service endpoints */ - public async resolveServiceEndpoints(did: string) { + public async resolveCredentials(did: string) { const { service } = await this.getById(did); - return Promise.all( - service - .map(({ serviceEndpoint }) => serviceEndpoint) - .filter((endpoint) => IPFSService.isCID(endpoint)) - .map((cid) => this.ipfsService.get(cid)) - ); + return ( + await Promise.all( + service + .map(({ serviceEndpoint }) => serviceEndpoint) + .filter((endpoint) => IPFSService.isCID(endpoint)) + .map((cid) => this.ipfsService.get(cid).catch(() => null)) + ) + ).filter(Boolean); } private async InitEventListeners(): Promise { From 8e6cb8ca910ebea27ba7625c329931be3d702a36 Mon Sep 17 00:00:00 2001 From: JGiter Date: Thu, 16 Jan 2025 09:38:38 +0200 Subject: [PATCH 6/6] docs: log claim not resolved --- src/modules/ipfs/ipfs.service.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/modules/ipfs/ipfs.service.ts b/src/modules/ipfs/ipfs.service.ts index 21c1fdce9..1a377469d 100644 --- a/src/modules/ipfs/ipfs.service.ts +++ b/src/modules/ipfs/ipfs.service.ts @@ -72,6 +72,7 @@ export class IPFSService { timeout, ]); } catch (e) { + this.logger.debug(`Claim is not resolved in IPFS. Claim CID ${cid}`); throw new HttpException( `Claim ${cid} not resolved`, HttpStatus.NOT_FOUND