From f5d487912ea28c447b8492acdf54da1457b88754 Mon Sep 17 00:00:00 2001 From: JGiter Date: Wed, 15 Jan 2025 11:35:23 +0200 Subject: [PATCH] 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 {