From 9a818a364eff02213a471b5c8d10288d66a388ae Mon Sep 17 00:00:00 2001 From: whitneypurdum Date: Mon, 12 Sep 2022 07:16:11 -0400 Subject: [PATCH] fix: update agreer for subjectAgreementCheck --- e2e/claims.service.e2e.ts | 48 +++++++++++++++++++++++++++- package-lock.json | 4 +-- src/modules/claims/claims.service.ts | 8 +++-- 3 files changed, 55 insertions(+), 5 deletions(-) diff --git a/e2e/claims.service.e2e.ts b/e2e/claims.service.e2e.ts index 4ed0ad3c6..e7f0602c2 100644 --- a/e2e/claims.service.e2e.ts +++ b/e2e/claims.service.e2e.ts @@ -58,6 +58,8 @@ const projectInstallerCandidate = Wallet.createRandom().connect(provider); const projectInstallerCandidateDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${projectInstallerCandidate.address}`; const rootOwner = Wallet.createRandom().connect(provider); const rootOwnerDID = `did:${Methods.Erc1056}:${Chain.VOLTA}:${rootOwner.address}`; +const myAsset = Wallet.createRandom().connect(provider); +const myAssetDid = `did:${Methods.Erc1056}:${Chain.VOLTA}:${myAsset.address}`; const roleName1 = 'myrole1'; const roleName2 = 'myrole2'; const roleName3 = 'myrole3'; @@ -73,6 +75,7 @@ const vcExpired = 'vcExpired'; const electrician = 'electrician'; const projectElectrician = 'projectElectrician'; const projectInstaller = 'projectInstaller'; +const roleForAsset = 'roleForAsset'; const namespace = root; const version = 1; const baseRoleDef = { @@ -160,6 +163,11 @@ const roles: Record = { roleName: projectInstaller, issuer: { issuerType: 'DID', did: [staticIssuerDID] }, }, + [`${roleForAsset}.${root}`]: { + ...baseRoleDef, + roleName: roleForAsset, + issuer: { issuerType: 'DID', did: [rootOwnerDID] }, + }, }; const mockGetRoleDefinition = jest .fn() @@ -244,6 +252,7 @@ describe('Сlaim tests', () => { await replenish(await rootOwner.getAddress()); await replenish(await dynamicIssuer.getAddress()); await replenish(await projectInstallerCandidate.getAddress()); + await replenish(await myAsset.getAddress()); await setupENS(await rootOwner.getAddress()); let connectToCacheServer; @@ -337,6 +346,12 @@ describe('Сlaim tests', () => { data: roles[`${projectInstaller}.${root}`], returnSteps: false, }); + await domainsService.createRole({ + roleName: roleForAsset, + namespace, + data: roles[`${roleForAsset}.${root}`], + returnSteps: false, + }); ({ didRegistry, claimsService } = await connectToDidRegistry( await spawnIpfsDaemon() @@ -495,7 +510,8 @@ describe('Сlaim tests', () => { requestorFields, }); - expirationTimestamp && expect(exp).toEqual(Math.floor(expirationTimestamp / 1000)); + expirationTimestamp && + expect(exp).toEqual(Math.floor(expirationTimestamp / 1000)); expect(claimData).not.toContain({ fields: [{ key: 'temperature', value: 36 }], @@ -947,6 +963,36 @@ describe('Сlaim tests', () => { ).toBe(true); }); + test('should be able to issue without request and publish onchain when signer is not subject (i.e. for asset)', async () => { + const claimType = `${roleForAsset}.${root}`; + const claim = await issueWithoutRequest(rootOwner, { + subjectDID: myAssetDid, + claimType, + registrationTypes, + }); + expect(claim.onChainProof).toHaveLength(132); + await signerService.connect(rootOwner, ProviderType.PrivateKey); + const mockedClaim = { + claimType, + isApproved: true, + onChainProof: claim.onChainProof, + claimTypeVersion: version, + acceptedBy: claim.acceptedBy, + subject: myAssetDid, + }; + mockGetClaimsBySubject + .mockReset() + .mockImplementationOnce(() => [mockedClaim]); + + 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]); diff --git a/package-lock.json b/package-lock.json index 3db8530a9..8949f78f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "iam-client-lib", - "version": "6.1.0", + "version": "6.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "iam-client-lib", - "version": "6.1.0", + "version": "6.2.0", "license": "GPL-3.0-or-later", "dependencies": { "@energyweb/credential-governance": "^2.2.1-alpha.293.0", diff --git a/src/modules/claims/claims.service.ts b/src/modules/claims/claims.service.ts index 1999dab5a..3c6ddea97 100644 --- a/src/modules/claims/claims.service.ts +++ b/src/modules/claims/claims.service.ts @@ -545,12 +545,16 @@ export class ClaimsService { return; } - if (!subjectAgreement && subject === this._signerService.did) { + if (!subjectAgreement) { + // If the signer is the subject, use the signer DID. If the signer is not the subject, use the subject DID: + const subjectAgreer = + subject === this._signerService.did ? this._signerService.did : subject; subjectAgreement = await this.approveRolePublishing({ - subject: this._signerService.did, + subject: subjectAgreer, role: claimType, version: +claimTypeVersion, }); + // } } const expiry = expirationTimestamp || eternityTimestamp;