Skip to content

Commit

Permalink
feat(claims): refactor towards unify off-chain and on-chain registration
Browse files Browse the repository at this point in the history
token becomes obsolete where claimType can be used. Code refactoring to simplify registration.
  • Loading branch information
Passerino committed Jan 21, 2022
1 parent b80446d commit 57151bf
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 114 deletions.
52 changes: 21 additions & 31 deletions docs/api/classes/ClaimsService.md
Expand Up @@ -27,7 +27,6 @@
- [publishPublicClaim](ClaimsService.md#publishpublicclaim)
- [registerOnchain](ClaimsService.md#registeronchain)
- [rejectClaimRequest](ClaimsService.md#rejectclaimrequest)
- [validatePublishPublicClaimRequest](ClaimsService.md#validatepublishpublicclaimrequest)
- [create](ClaimsService.md#create)

## Constructors
Expand All @@ -53,7 +52,7 @@

**`description`** allows subject to request for credential

**`deprecated`** fields - use requestorFields instead
**`field`** { claim: fields } - @deprecated - use requestorFields instead

#### Parameters

Expand Down Expand Up @@ -367,20 +366,22 @@ ___

### publishPublicClaim

**publishPublicClaim**(`__namedParameters`): `Promise`<`undefined` \| `string`\>
**publishPublicClaim**(`token`): `Promise`<`undefined` \| `string`\>

publishPublicClaim

**`description`** store claim data in ipfs and save url to DID document services
**`description`** publishes claim off-chain (by storing claim data in ipfs and save url to DID document services

#### Parameters

| Name | Type |
| :------ | :------ |
| `__namedParameters` | `Object` |
| `__namedParameters.claimType?` | `string` |
| `__namedParameters.registrationTypes?` | [`RegistrationTypes`](../enums/RegistrationTypes.md)[] |
| `__namedParameters.token?` | `string` |
| Name | Type | Description |
| :------ | :------ | :------ |
| `token` | `Object` | @deprecated - use claim with claimType instead |
| `token.claim` | `Object` | - |
| `token.claim.claimType?` | `string` | - |
| `token.claim.token?` | `string` | - |
| `token.registrationTypes?` | [`RegistrationTypes`](../enums/RegistrationTypes.md)[] | - |
| `token.token?` | `string` | - |

#### Returns

Expand All @@ -398,9 +399,16 @@ ___

#### Parameters

| Name | Type |
| :------ | :------ |
| `claim` | `Pick`<[`Claim`](../interfaces/Claim.md), ``"token"`` \| ``"subjectAgreement"`` \| ``"onChainProof"`` \| ``"acceptedBy"``\> |
| Name | Type | Description |
| :------ | :------ | :------ |
| `claim` | `Object` | id of signed onchain claim. |
| `claim.acceptedBy?` | `string` | - |
| `claim.claimType?` | `string` | - |
| `claim.claimTypeVersion?` | `string` | - |
| `claim.onChainProof?` | `string` | - |
| `claim.subject?` | `string` | - |
| `claim.subjectAgreement?` | `string` | - |
| `claim.token?` | `string` | - |

#### Returns

Expand All @@ -427,24 +435,6 @@ ___

___

### validatePublishPublicClaimRequest

**validatePublishPublicClaimRequest**(`registrationTypes`, `token?`, `claimType?`): `void`

#### Parameters

| Name | Type |
| :------ | :------ |
| `registrationTypes` | [`RegistrationTypes`](../enums/RegistrationTypes.md)[] |
| `token?` | `string` |
| `claimType?` | `string` |

#### Returns

`void`

___

### create

`Static` **create**(`signerService`, `domainsService`, `cacheClient`, `didRegistry`): `Promise`<[`ClaimsService`](ClaimsService.md)\>
Expand Down
21 changes: 21 additions & 0 deletions docs/api/enums/ERROR_MESSAGES.md
Expand Up @@ -6,6 +6,8 @@

- [APP\_WITH\_ROLES](ERROR_MESSAGES.md#app_with_roles)
- [CAN\_NOT\_UPDATE\_NOT\_CONTROLLED\_DOCUMENT](ERROR_MESSAGES.md#can_not_update_not_controlled_document)
- [CLAIM\_NOT\_FOUND](ERROR_MESSAGES.md#claim_not_found)
- [CLAIM\_TYPE\_REQUIRED\_FOR\_ON\_CHAIN\_REGISTRATION](ERROR_MESSAGES.md#claim_type_required_for_on_chain_registration)
- [CLAIM\_WAS\_NOT\_ISSUED](ERROR_MESSAGES.md#claim_was_not_issued)
- [ENS\_OWNER\_NOT\_VALID\_ADDRESS](ERROR_MESSAGES.md#ens_owner_not_valid_address)
- [ENS\_TYPE\_NOT\_SUPPORTED](ERROR_MESSAGES.md#ens_type_not_supported)
Expand All @@ -23,6 +25,7 @@
- [ROLE\_NOT\_EXISTS](ERROR_MESSAGES.md#role_not_exists)
- [ROLE\_PREREQUISITES\_NOT\_MET](ERROR_MESSAGES.md#role_prerequisites_not_met)
- [STAKE\_WAS\_NOT\_PUT](ERROR_MESSAGES.md#stake_was_not_put)
- [TOKEN\_REQUIRED\_FOR\_OFF\_CHAIN\_REGISTRATION](ERROR_MESSAGES.md#token_required_for_off_chain_registration)
- [UNKNOWN\_PROVIDER](ERROR_MESSAGES.md#unknown_provider)
- [WALLET\_PROVIDER\_NOT\_SUPPORTED](ERROR_MESSAGES.md#wallet_provider_not_supported)
- [WITHDRAWAL\_WAS\_NOT\_REQUESTED](ERROR_MESSAGES.md#withdrawal_was_not_requested)
Expand All @@ -41,6 +44,18 @@ ___

___

### CLAIM\_NOT\_FOUND

**CLAIM\_NOT\_FOUND** = `"Claim not found"`

___

### CLAIM\_TYPE\_REQUIRED\_FOR\_ON\_CHAIN\_REGISTRATION

**CLAIM\_TYPE\_REQUIRED\_FOR\_ON\_CHAIN\_REGISTRATION** = `"claimType required for on-chain registration"`

___

### CLAIM\_WAS\_NOT\_ISSUED

**CLAIM\_WAS\_NOT\_ISSUED** = `"Claim was not issued"`
Expand Down Expand Up @@ -143,6 +158,12 @@ ___

___

### TOKEN\_REQUIRED\_FOR\_OFF\_CHAIN\_REGISTRATION

**TOKEN\_REQUIRED\_FOR\_OFF\_CHAIN\_REGISTRATION** = `"token required for off-chain registration"`

___

### UNKNOWN\_PROVIDER

**UNKNOWN\_PROVIDER** = `"Unknown provider type"`
Expand Down
6 changes: 3 additions & 3 deletions docs/api/modules.md
Expand Up @@ -653,17 +653,17 @@ ___

### readyToBeRegisteredOnchain

`Const` **readyToBeRegisteredOnchain**(`claim`): claim is Required<Pick<Claim, "subjectAgreement" \| "onChainProof" \| "acceptedBy"\>\>
`Const` **readyToBeRegisteredOnchain**(`claim`): `Required`<`Pick`<[`Claim`](interfaces/Claim.md), ``"subject"`` \| ``"claimTypeVersion"`` \| ``"claimType"`` \| ``"onChainProof"`` \| ``"acceptedBy"`` \| ``"subjectAgreement"``\>\>

#### Parameters

| Name | Type |
| :------ | :------ |
| `claim` | `object` |
| `claim` | `any` |

#### Returns

claim is Required<Pick<Claim, "subjectAgreement" \| "onChainProof" \| "acceptedBy"\>\>
`Required`<`Pick`<[`Claim`](interfaces/Claim.md), ``"subject"`` \| ``"claimTypeVersion"`` \| ``"claimType"`` \| ``"onChainProof"`` \| ``"acceptedBy"`` \| ``"subjectAgreement"``\>\>

___

Expand Down
22 changes: 13 additions & 9 deletions e2e/claims.service.e2e.ts
Expand Up @@ -221,7 +221,6 @@ describe('Enrollment claim tests', () => {
}

async function enrolAndIssueWithoutRequest(
requestSigner: Required<ethers.Signer>,
issueSigner: Required<ethers.Signer>,
{
subjectDID,
Expand Down Expand Up @@ -278,16 +277,17 @@ describe('Enrollment claim tests', () => {
}
if (registrationTypes.includes(RegistrationTypes.OnChain)) {
expect(onChainProof).toHaveLength(132);
await signerService.connect(requestSigner, ProviderType.PrivateKey);

const mockedClaim = {
claimType,
isApproved: true,
onChainProof,
claimTypeVersion: version,
acceptedBy: issuerDID,
subject: requesterDID,
};
mockGetClaimsBySubject.mockReset().mockImplementationOnce(() => [mockedClaim]);
await claimsService.publishPublicClaim({ claimType, registrationTypes });

}
expect(requester).toEqual(subjectDID);
expect(claimIssuer).toEqual([issuerDID]);
Expand Down Expand Up @@ -397,8 +397,8 @@ describe('Enrollment claim tests', () => {
returnSteps: false,
});

mockGetClaimsBySubject.mockImplementationOnce(() => []);
mockGetClaimsBySubject.mockImplementationOnce(() => []);
mockGetClaimsBySubject.mockImplementation(() => []);
//mockGetClaimsBySubject.mockImplementationOnce(() => []);

return expect(
enrolAndIssue(rootOwner, staticIssuer, {
Expand All @@ -413,7 +413,9 @@ describe('Enrollment claim tests', () => {
const claimType = `${roleName1}.${root}`;
const role1Claim = {
claimType,
claimTypeVersion: version,
isAccepted: true,
subject: rootOwnerDID,
};

test('should be able to issue and publish onchain', async () => {
Expand All @@ -429,18 +431,20 @@ describe('Enrollment claim tests', () => {
});

test('should be able to issue and publish onchain without request', async () => {
mockGetClaimsBySubject.mockImplementationOnce(() => [role1Claim]); // to verify requesting
mockGetClaimsBySubject.mockImplementation(() => [role1Claim]); // to verify requesting

await enrolAndIssueWithoutRequest(rootOwner, staticIssuer, {
await enrolAndIssueWithoutRequest(staticIssuer, {
subjectDID: rootOwnerDID,
claimType,
registrationTypes,
});
await signerService.connect(rootOwner, ProviderType.PrivateKey);
await claimsService.publishPublicClaim({ claim: {claimType} , registrationTypes });
expect(await claimsService.hasOnChainRole(rootOwnerDID, claimType, version)).toBe(true);
});

test('should be able to issue without publishing onchain', async () => {
mockGetClaimsBySubject.mockImplementationOnce(() => [role1Claim]);
mockGetClaimsBySubject.mockImplementation(() => [role1Claim]);

await enrolAndIssue(rootOwner, staticIssuer, {
subjectDID: rootOwnerDID,
Expand Down Expand Up @@ -489,7 +493,7 @@ describe('Enrollment claim tests', () => {
mockCachedDocument.mockResolvedValueOnce(subjectDoc);

await signerService.connect(subject, ProviderType.PrivateKey);
const claimUrl = await claimsService.publishPublicClaim({ token: issuedToken });
const claimUrl = await claimsService.publishPublicClaim({ claim: { token: issuedToken } });

subjectDoc = await didRegistry.getDidDocument({ did: subjectDID, includeClaims: true });
expect(
Expand Down
3 changes: 3 additions & 0 deletions src/errors/ErrorMessages.ts
Expand Up @@ -19,6 +19,9 @@ export enum ERROR_MESSAGES {
ERROR_IN_AZURE_PROVIDER = 'Error in Azure Provider',
JWT_ALGORITHM_NOT_SUPPORTED = 'Jwt algorithm not supported',
CLAIM_WAS_NOT_ISSUED = 'Claim was not issued',
CLAIM_NOT_FOUND = 'Claim not found',
CLAIM_TYPE_REQUIRED_FOR_ON_CHAIN_REGISTRATION = 'claimType required for on-chain registration',
TOKEN_REQUIRED_FOR_OFF_CHAIN_REGISTRATION = 'token required for off-chain registration',
ENS_OWNER_NOT_VALID_ADDRESS = 'Provided owner is not a valid address. Owner of ENS domain must be an address',
IS_ETH_SIGNER_NOT_SET = 'Can not determine if signer is conformant with eth_sign specification',
}

0 comments on commit 57151bf

Please sign in to comment.