Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ipfs.service): add timeout to get #677

Merged
merged 6 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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`[]\>
5 changes: 3 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -100,6 +100,7 @@
"didStoreCluster": "npm:@ew-did-registry/[email protected]",
"didStoreInfura": "npm:@ew-did-registry/[email protected]",
"dotenv": "^16.0.3",
"eth-ens-namehash": "^2.0.8",
jrhender marked this conversation as resolved.
Show resolved Hide resolved
"ethers": "5.7.2",
"graphql": "^16.6.0",
"graphql-fields": "^2.0.3",
Expand Down
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
25 changes: 16 additions & 9 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))
jrhender marked this conversation as resolved.
Show resolved Hide resolved
)
).filter(Boolean);
}

private async InitEventListeners(): Promise<void> {
Expand Down Expand Up @@ -439,7 +441,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 {
Expand Down
Loading
Loading