Skip to content

Commit

Permalink
fix(claim): fix public claim publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Harasz committed Apr 12, 2022
1 parent 7733743 commit d77df34
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 3 deletions.
21 changes: 21 additions & 0 deletions docs/api/classes/ClaimsService.md
Expand Up @@ -19,6 +19,7 @@
- [getClaimsByRequester](ClaimsService.md#getclaimsbyrequester)
- [getClaimsBySubject](ClaimsService.md#getclaimsbysubject)
- [getClaimsBySubjects](ClaimsService.md#getclaimsbysubjects)
- [getNamespaceFromClaimType](ClaimsService.md#getnamespacefromclaimtype)
- [getUserClaims](ClaimsService.md#getuserclaims)
- [hasOnChainRole](ClaimsService.md#hasonchainrole)
- [init](ClaimsService.md#init)
Expand Down Expand Up @@ -260,6 +261,26 @@ ___

___

### getNamespaceFromClaimType

**getNamespaceFromClaimType**(`claimType`): `string`

**`description`** get `namespace` from claim type.

#### Parameters

| Name | Type |
| :------ | :------ |
| `claimType` | `string` |

#### Returns

`string`

namespace

___

### getUserClaims

**getUserClaims**(`__namedParameters?`): `Promise`<`IServiceEndpoint` & [`ClaimData`](../interfaces/ClaimData.md)[]\>
Expand Down
7 changes: 7 additions & 0 deletions docs/api/enums/ERROR_MESSAGES.md
Expand Up @@ -7,6 +7,7 @@
- [APP\_WITH\_ROLES](ERROR_MESSAGES.md#app_with_roles)
- [CAN\_NOT\_UPDATE\_DOCUMENT\_PROPERTIES\_INVALID\_OR\_MISSING](ERROR_MESSAGES.md#can_not_update_document_properties_invalid_or_missing)
- [CAN\_NOT\_UPDATE\_NOT\_CONTROLLED\_DOCUMENT](ERROR_MESSAGES.md#can_not_update_not_controlled_document)
- [CLAIM\_TYPE\_MISSING](ERROR_MESSAGES.md#claim_type_missing)
- [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)
Expand Down Expand Up @@ -52,6 +53,12 @@ ___

___

### CLAIM\_TYPE\_MISSING

**CLAIM\_TYPE\_MISSING** = `"Claim type is required for On-chain registration"`

___

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

**CLAIM\_TYPE\_REQUIRED\_FOR\_ON\_CHAIN\_REGISTRATION** = `"claimType required for on-chain registration"`
Expand Down
1 change: 1 addition & 0 deletions src/errors/ErrorMessages.ts
Expand Up @@ -26,4 +26,5 @@ export enum ERROR_MESSAGES {
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',
SIGN_TYPED_DATA_NOT_SUPPORTED = 'Sign typed data not supported',
CLAIM_TYPE_MISSING = 'Claim type is required for On-chain registration',
}
22 changes: 19 additions & 3 deletions src/modules/claims/claims.service.ts
Expand Up @@ -521,16 +521,21 @@ export class ClaimsService {
this.validatePublishPublicClaimRequest(registrationTypes, claim);
let url: string | undefined = undefined;
if (registrationTypes.includes(RegistrationTypes.OnChain)) {
if (!claim.claimType) {
throw new Error(ERROR_MESSAGES.CLAIM_TYPE_MISSING);
}

const claims = await this.getClaimsBySubject({
did: this._signerService.did,
namespace: claim.claimType,
namespace: this.getNamespaceFromClaimType(claim.claimType),
isAccepted: true,
});
if (claims.length < 1) {
const claimData = claims.find((c) => c.claimType === claim.claimType);

if (!claimData) {
throw new Error(ERROR_MESSAGES.PUBLISH_NOT_ISSUED_CLAIM);
}

const claimData = claims[0];
await this.registerOnchain({
...claimData,
onChainProof: claimData.onChainProof as string,
Expand Down Expand Up @@ -810,6 +815,17 @@ export class ClaimsService {
}
}

/**
*
* @description get `namespace` from claim type.
* @returns namespace
* @param {string} claimType
*
*/
getNamespaceFromClaimType(claimType: string) {
return claimType.split('.roles.')[1];
}

private stripClaimData(data: ClaimData): ClaimData {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { fields, ...claimData } = data;
Expand Down

0 comments on commit d77df34

Please sign in to comment.