Skip to content

Commit

Permalink
fix: skip not resolved creds
Browse files Browse the repository at this point in the history
  • Loading branch information
JGiter committed Jan 16, 2025
1 parent 0b005a1 commit f5d4879
Show file tree
Hide file tree
Showing 4 changed files with 241 additions and 18 deletions.
223 changes: 223 additions & 0 deletions docs/api/classes/modules_auth_login_strategy.AuthStrategy.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<SiweMessage\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `payload` | `unknown` |

#### Returns

payload is Partial<SiweMessage\>

#### 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
10 changes: 5 additions & 5 deletions docs/api/classes/modules_did_did_service.DIDService.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -181,4 +181,4 @@ Resolves document service endponts

#### Returns

`Promise`<`string`[]\>
`Promise`<`any`[]\>
8 changes: 3 additions & 5 deletions src/modules/claim/resolvers/credential.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ export class RoleCredentialResolver implements CredentialResolver {
): Promise<
VerifiableCredential<RoleCredentialSubject> | 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
Expand Down Expand Up @@ -57,15 +55,15 @@ export class RoleCredentialResolver implements CredentialResolver {

async eip191JwtsOf(subject: string): Promise<RoleEIP191JWT[]> {
return this.serviceEndpointsToEIP191(
await this.didService.resolveServiceEndpoints(subject)
await this.didService.resolveCredentials(subject)
);
}

async credentialsOf(
subject: string
): Promise<VerifiableCredential<RoleCredentialSubject>[]> {
return this.serviceEndpointsToCredentials(
await this.didService.resolveServiceEndpoints(subject)
await this.didService.resolveCredentials(subject)
);
}

Expand Down
18 changes: 10 additions & 8 deletions src/modules/did/did.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down

0 comments on commit f5d4879

Please sign in to comment.