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

Set issuer resolver #762

Merged
merged 3 commits into from
Jul 16, 2024
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
49 changes: 49 additions & 0 deletions docs/api/classes/modules_claims.CachedIssuerResolver.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Class: CachedIssuerResolver

[modules/claims](../modules/modules_claims.md).CachedIssuerResolver

## Implements

- `IssuerResolver`

## Table of contents

### Constructors

- [constructor](modules_claims.CachedIssuerResolver.md#constructor)

### Methods

- [getIssuerDefinition](modules_claims.CachedIssuerResolver.md#getissuerdefinition)

## Constructors

### constructor

• **new CachedIssuerResolver**(`domainsService`)

#### Parameters

| Name | Type |
| :------ | :------ |
| `domainsService` | [`DomainsService`](modules_domains.DomainsService.md) |

## Methods

### getIssuerDefinition

▸ **getIssuerDefinition**(`namespace`): `Promise`<`IIssuerDefinition`\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `namespace` | `string` |

#### Returns

`Promise`<`IIssuerDefinition`\>

#### Implementation of

IssuerResolver.getIssuerDefinition
17 changes: 17 additions & 0 deletions docs/api/classes/modules_claims.ClaimsService.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ claimsService.getClaimById(claim.id);
- [resolveCredentialAndVerify](modules_claims.ClaimsService.md#resolvecredentialandverify)
- [revokeClaim](modules_claims.ClaimsService.md#revokeclaim)
- [revokeMultipleClaim](modules_claims.ClaimsService.md#revokemultipleclaim)
- [setIssuerResolver](modules_claims.ClaimsService.md#setissuerresolver)
- [verifyRoleEIP191JWT](modules_claims.ClaimsService.md#verifyroleeip191jwt)
- [verifyVc](modules_claims.ClaimsService.md#verifyvc)
- [create](modules_claims.ClaimsService.md#create)
Expand Down Expand Up @@ -820,6 +821,22 @@ claimsService.revokeMultipleClaim({

___

### setIssuerResolver

▸ **setIssuerResolver**(`issuerResolver`): `void`

#### Parameters

| Name | Type |
| :------ | :------ |
| `issuerResolver` | `IssuerResolver` |

#### Returns

`void`

___

### verifyRoleEIP191JWT

▸ **verifyRoleEIP191JWT**(`roleEIP191JWT`): `Promise`<[`CredentialVerificationResult`](../interfaces/modules_claims.CredentialVerificationResult.md)\>
Expand Down
8 changes: 4 additions & 4 deletions docs/api/classes/modules_signer.SignerService.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,14 +353,14 @@ ___

Add event handler for certain events

#### Returns

`void`

**`Requires`**

to be called after the connection to wallet was initialized

#### Returns

`void`

___

### on
Expand Down
16 changes: 8 additions & 8 deletions docs/api/classes/modules_staking.StakingFactoryService.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ Intended for staking pool

▸ **allServices**(): `Promise`<[`Service`](../modules/modules_staking.md#service)[]\>

#### Returns

`Promise`<[`Service`](../modules/modules_staking.md#service)[]\>

**`Description`**

Returns all services for which pools are launched

#### Returns

`Promise`<[`Service`](../modules/modules_staking.md#service)[]\>

___

### getPool

▸ **getPool**(): `Promise`<[`StakingPoolService`](modules_staking.StakingPoolService.md)\>

#### Returns

`Promise`<[`StakingPoolService`](modules_staking.StakingPoolService.md)\>

**`Description`**

Returns pool launched for energyweb org

#### Returns

`Promise`<[`StakingPoolService`](modules_staking.StakingPoolService.md)\>

___

### create
Expand Down
28 changes: 14 additions & 14 deletions docs/api/classes/modules_staking.StakingPoolService.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ ___

▸ **partialWithdraw**(`value`): `Promise`<`ContractReceipt`\>

**`Description`**

#### Parameters

| Name | Type |
Expand All @@ -137,14 +139,20 @@ ___

`Promise`<`ContractReceipt`\>

**`Description`**

___

### putStake

▸ **putStake**(`stake`): `Promise`<`void`\>

**`Description`**

Locks stake and starts accumulating reward

**`Emits`**

StakingPool.StakePut

#### Parameters

| Name | Type |
Expand All @@ -155,24 +163,16 @@ ___

`Promise`<`void`\>

**`Description`**

Locks stake and starts accumulating reward

**`Emits`**

StakingPool.StakePut

___

### withdraw

▸ **withdraw**(): `Promise`<`void`\>

#### Returns

`Promise`<`void`\>

**`Description`**

pays back stake with accumulated reward.

#### Returns

`Promise`<`void`\>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ verifiableCredentialsService.createRoleVC(...);

▸ **continueExchange**(`«destructured»`): `Promise`<`undefined` \| `VerifiablePresentation` \| `VpRequest`\>

**`Description`**

Sends credentials requested by issuer and returns either issued credentials or next credentials request

#### Parameters

| Name | Type |
Expand All @@ -62,10 +66,6 @@ verifiableCredentialsService.createRoleVC(...);

issued credentials or request of additional credentials

**`Description`**

Sends credentials requested by issuer and returns either issued credentials or next credentials request

___

### createCredential
Expand Down
1 change: 1 addition & 0 deletions docs/api/modules/modules_claims.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

### Classes

- [CachedIssuerResolver](../classes/modules_claims.CachedIssuerResolver.md)
- [ClaimsService](../classes/modules_claims.ClaimsService.md)

### Interfaces
Expand Down
10 changes: 5 additions & 5 deletions docs/api/modules/modules_signer.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ ___

▸ **fromGnosis**(`safeAppSdk`): `Promise`<[`SignerService`](../classes/modules_signer.SignerService.md)\>

**`Description`**

Intended for use in Volta Gnosis web interface(https://volta.gnosis-safe.io/).
Dapp should provide SafeAppSdk injected by Gnosis interface

#### Parameters

| Name | Type |
Expand All @@ -116,11 +121,6 @@ ___

`Promise`<[`SignerService`](../classes/modules_signer.SignerService.md)\>

**`Description`**

Intended for use in Volta Gnosis web interface(https://volta.gnosis-safe.io/).
Dapp should provide SafeAppSdk injected by Gnosis interface

___

### fromKms
Expand Down
18 changes: 18 additions & 0 deletions src/modules/claims/cached-issuer-resolver.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {
IIssuerDefinition,
IRoleDefinitionV2,
} from '@energyweb/credential-governance';
import { IssuerResolver } from '@energyweb/vc-verification';
import { DomainsService, NamespaceType } from '../domains';

export class CachedIssuerResolver implements IssuerResolver {
constructor(private readonly domainsService: DomainsService) {}

async getIssuerDefinition(namespace: string): Promise<IIssuerDefinition> {
const role = (await this.domainsService.getDefinition({
type: NamespaceType.Role,
namespace,
})) as IRoleDefinitionV2;
return role.issuer;
}
}
21 changes: 17 additions & 4 deletions src/modules/claims/claims.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
RevocationVerification,
RoleEIP191JWT,
isEIP191Jwt,
IssuerResolver,
} from '@energyweb/vc-verification';
import { DidRegistry } from '../did-registry/did-registry.service';
import { ClaimData, isClaimService } from '../did-registry/did.types';
Expand Down Expand Up @@ -109,7 +110,8 @@ export class ClaimsService {
private _claimManagerInterface = ClaimManager__factory.createInterface();
private _claimRevocation: ClaimRevocation;
private _issuerVerification: IssuerVerification;
private _issuerResolver: EthersProviderIssuerResolver;
// Overwritten issuer resolver
private _issuerResolver?: IssuerResolver;
Copy link
Collaborator

@jrhender jrhender Jul 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JGiter why the addition of the ? ? Is there a code path wherein _issuerResolver is undefined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed meaning of this field. Now this is overriding resolver, which might not be set. I will add comment. May be also rename it somehow?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So you're saying this code wouldn't work? From my reading of the code it should be fine. I'm testing it out locally....

Suggested change
private _issuerResolver?: IssuerResolver;
private _issuerResolver: IssuerResolver;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally typescript should error this when strictProperyInitialization is true. In our configuration it is false, but error is not thrown even if to change it to true. May be this rule overwritten somewhere

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually typescript indeed reject not initialized _issuerResolver if enable strictPropertyInitialization

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah okay, I see. Good point about strictPropertyInitialization. However, as I think we currently have strictPropertyInitialization = false and as this would affect all of the other private properties in this class (and several other of the service classes), I'm not sure it makes sense to deviate from the pattern here. Not a big deal though. I think we can proceed either way 👍

private _credentialResolver: CredentialResolver;
private _statusVerifier: StatusListEntryVerification;

Expand Down Expand Up @@ -172,6 +174,12 @@ export class ClaimsService {
);
}

public setIssuerResolver(issuerResolver: IssuerResolver): void {
this._issuerResolver = issuerResolver;

this._setIssuerVerifier();
}

/**
* A utility function to check the blockchain directly if a DID has a role.
*
Expand Down Expand Up @@ -1599,7 +1607,8 @@ export class ClaimsService {
this._didRegistry.ipfsStore
);
const domainReader = this._domainsService.domainReader;
this._issuerResolver = new EthersProviderIssuerResolver(domainReader);
const issuerResolver =
this._issuerResolver || this._getDefaultIssuerResolver();
const revokerResolver = new EthersProviderRevokerResolver(domainReader);
const verifyProof = (vc: string, proofOptions: string) =>
this._verifiableCredentialService.verify(
Expand All @@ -1608,12 +1617,12 @@ export class ClaimsService {
);
const revocationVerification = new RevocationVerification(
revokerResolver,
this._issuerResolver,
issuerResolver,
this._credentialResolver,
verifyProof
);
this._issuerVerification = new IssuerVerification(
this._issuerResolver,
issuerResolver,
this._credentialResolver,
this._signerService.provider,
this._didRegistry.registrySettings,
Expand All @@ -1632,4 +1641,8 @@ export class ClaimsService {
return JSON.stringify({ errors: [] });
});
}

private _getDefaultIssuerResolver(): IssuerResolver {
return new EthersProviderIssuerResolver(this._domainsService.domainReader);
}
}
1 change: 1 addition & 0 deletions src/modules/claims/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './claims.service';
export * from './claims.types';
export * from './cached-issuer-resolver';
Loading