From 52fa436b87e2a4cc0e2dcf4d42cb44de3a5440ef Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 26 Mar 2020 00:34:34 +0200 Subject: [PATCH 1/4] freeWhiteList --- src/keeper/contracts/DIDRegistry.ts | 5 +- src/ocean/OceanAssets.ts | 65 +++++++++++++++++++++- test/integration/ocean/AssetOwners.test.ts | 21 +++++++ 3 files changed, 89 insertions(+), 2 deletions(-) diff --git a/src/keeper/contracts/DIDRegistry.ts b/src/keeper/contracts/DIDRegistry.ts index 026491d..5d98049 100644 --- a/src/keeper/contracts/DIDRegistry.ts +++ b/src/keeper/contracts/DIDRegistry.ts @@ -75,7 +75,10 @@ export default class DIDRegistry extends ContractBase { } public async revokePermission(did: string, grantee: string, ownerAddress: string) { - return this.send('revokePermission', ownerAddress, [zeroX(did), zeroX(grantee)]) + return this.send('revokePermission', ownerAddress, [ + didZeroX(did), + zeroX(grantee) + ]) } public async getPermission(did: string, grantee: string): Promise { diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index b171ca0..2515855 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -5,7 +5,7 @@ import { MetaData } from '../ddo/MetaData' import { Service, ServiceAccess } from '../ddo/Service' import Account from './Account' import DID from './DID' -import { fillConditionsWithDDO, SubscribablePromise } from '../utils' +import { fillConditionsWithDDO, SubscribablePromise, didZeroX } from '../utils' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' import { OrderProgressStep } from './utils/ServiceUtils' @@ -416,4 +416,67 @@ export class OceanAssets extends Instantiable { } } } + + /** + * Get FreeWhiteList for a DID + * @param {string} did Asset DID. + * @return {Promise} List of addresses. + */ + public async getFreeWhiteList(did: string): Promise { + const events = await this.ocean.keeper.didRegistry.getPastEvents( + 'DIDPermissionGranted', + { + _did: didZeroX(did) + } + ) + const list = events.map(({ returnValues }) => returnValues._grantee) + const filteredList = [] + for (let index = 0; index < list.length; index++) { + const address = list[index] + const hasPermission = await this.ocean.keeper.didRegistry.getPermission( + did, + address + ) + if (hasPermission) filteredList.push(address) + } + return filteredList + } + + /** + * Add consumer to FreeWhiteList for a DID + * @param {string} did Asset DID. + * @param {string} consumer Ethereum address to add to the list. + * @param {Account} account Ethereum account of DID owner + * @return None + */ + public async addConsumerToFreeWhiteList( + did: string, + consumer: string, + account: Account + ): Promise { + await this.ocean.keeper.didRegistry.grantPermission( + did, + consumer, + account.getId() + ) + } + + /** + * Remove consumer from DID's FreeWhiteList + * @param {string} did Asset DID. + * @param {string} consumer Ethereum address to add to the list. + * @param {Account} account Ethereum account of DID owner + * @return None + */ + public async removeConsumerFromFreeWhiteList( + did: string, + consumer: string, + account: Account + ): Promise { + await this.ocean.keeper.didRegistry.revokePermission( + did, + consumer, + account.getId() + ) + } } diff --git a/test/integration/ocean/AssetOwners.test.ts b/test/integration/ocean/AssetOwners.test.ts index 33297cb..215c197 100644 --- a/test/integration/ocean/AssetOwners.test.ts +++ b/test/integration/ocean/AssetOwners.test.ts @@ -8,6 +8,8 @@ describe('Asset Owners', () => { let account1: Account let account2: Account + let consumer1: Account + let consumer2: Account let metadata = getMetadata() @@ -16,6 +18,8 @@ describe('Asset Owners', () => { // Accounts ;[account1, account2] = await ocean.accounts.list() + consumer1 = (await ocean.accounts.list())[3] + consumer2 = (await ocean.accounts.list())[4] if (!ocean.keeper.dispenser) { metadata = getMetadata(0) @@ -113,4 +117,21 @@ describe('Asset Owners', () => { assert.equal(newOwner, account2.getId()) }) + + it('should add and remove correctly an address to/from FreeWhiteList on an asset', async () => { + const ddo = await ocean.assets.create(metadata as any, account1) + await ocean.assets.addConsumerToFreeWhiteList(ddo.id, consumer1.getId(), account1) + await ocean.assets.addConsumerToFreeWhiteList(ddo.id, consumer2.getId(), account1) + const list = await ocean.assets.getFreeWhiteList(ddo.id) + assert.notEqual(-1, list.indexOf(consumer1.getId())) + assert.notEqual(-1, list.indexOf(consumer2.getId())) + await ocean.assets.removeConsumerFromFreeWhiteList( + ddo.id, + consumer1.getId(), + account1 + ) + const remList = await ocean.assets.getFreeWhiteList(ddo.id) + assert.equal(-1, remList.indexOf(consumer1.getId())) + assert.notEqual(-1, remList.indexOf(consumer2.getId())) + }) }) From b8fad6bf4a5b40d38c78caea8b512a0330e05983 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Thu, 26 Mar 2020 12:05:16 +0100 Subject: [PATCH 2/4] Release 2.0.0 --- CHANGELOG.md | 14 +++++++++++--- package-lock.json | 2 +- package.json | 2 +- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 52aa38e..c0411af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,11 +4,19 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). -#### [v2.0.0-beta.5](https://github.com/oceanprotocol/squid-js/compare/2.0.0-beta.4...v2.0.0-beta.5) +#### [v2.0.0](https://github.com/oceanprotocol/squid-js/compare/2.0.0-beta.4...v2.0.0) -> 10 March 2020 +> 26 March 2020 -- Update the compute condition name in ddo jason definition. [`#380`](https://github.com/oceanprotocol/squid-js/pull/380) +- add encodeURIComponent if AlgoMetadata is used [`#390`](https://github.com/oceanprotocol/squid-js/pull/390) +- Feature/compute service [`#381`](https://github.com/oceanprotocol/squid-js/pull/381) +- Update typedoc to the latest version 🚀 [`#389`](https://github.com/oceanprotocol/squid-js/pull/389) +- package updates [`#384`](https://github.com/oceanprotocol/squid-js/pull/384) +- Fix compute when not using published algo [`#387`](https://github.com/oceanprotocol/squid-js/pull/387) +- Replace serviceExecution with computeExecution. [`#380`](https://github.com/oceanprotocol/squid-js/pull/380) +- fix compute & added createAccessServiceAttributes [`e787266`](https://github.com/oceanprotocol/squid-js/commit/e7872666faf6e1b0c9868613823bb843d8609756) +- chore(package): update lockfile package-lock.json [`fd77a00`](https://github.com/oceanprotocol/squid-js/commit/fd77a00e1b06b25b45030453107eb8252ba0b590) +- add integration test for compute with a rawcode algo [`40b2ccf`](https://github.com/oceanprotocol/squid-js/commit/40b2ccffeacd31ab46f2ae3180f7d5c8550ebd98) #### [2.0.0-beta.4](https://github.com/oceanprotocol/squid-js/compare/v2.0.0-beta.3...2.0.0-beta.4) diff --git a/package-lock.json b/package-lock.json index 261b931..f9ef43c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "2.0.0-beta.5", + "version": "2.0.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 3d8dbf2..96eb52c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@oceanprotocol/squid", - "version": "2.0.0-beta.5", + "version": "2.0.0", "description": "JavaScript client library for Ocean Protocol", "main": "./dist/node/squid.js", "typings": "./dist/node/squid.d.ts", From db26264d426d3e31062cb5b74ad2ffcd04f46021 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2020 00:07:51 +0000 Subject: [PATCH 3/4] chore(package): update @types/sinon to version 9.0.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 96eb52c..bfd9cc1 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "@types/mocha": "^7.0.2", "@types/node": "^13.9.1", "@types/node-fetch": "^2.5.5", - "@types/sinon": "^7.5.2", + "@types/sinon": "^9.0.0", "@typescript-eslint/eslint-plugin": "^2.23.0", "@typescript-eslint/parser": "^2.23.0", "auto-changelog": "^1.16.2", From b18412fc814e4350bbdddba899d229e2b4c24d9f Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" <23040076+greenkeeper[bot]@users.noreply.github.com> Date: Wed, 1 Apr 2020 00:07:55 +0000 Subject: [PATCH 4/4] chore(package): update lockfile package-lock.json --- package-lock.json | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index f9ef43c..10fb1de 100644 --- a/package-lock.json +++ b/package-lock.json @@ -635,9 +635,18 @@ } }, "@types/sinon": { - "version": "7.5.2", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-7.5.2.tgz", - "integrity": "sha512-T+m89VdXj/eidZyejvmoP9jivXgBDdkOSBVQjU9kF349NEx10QdPNGxHeZUaj1IlJ32/ewdyXJjnJxyxJroYwg==", + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-9.0.0.tgz", + "integrity": "sha512-v2TkYHkts4VXshMkcmot/H+ERZ2SevKa10saGaJPGCJ8vh3lKrC4u663zYEeRZxep+VbG6YRDtQ6gVqw9dYzPA==", + "dev": true, + "requires": { + "@types/sinonjs__fake-timers": "*" + } + }, + "@types/sinonjs__fake-timers": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/@types/sinonjs__fake-timers/-/sinonjs__fake-timers-6.0.1.tgz", + "integrity": "sha512-yYezQwGWty8ziyYLdZjwxyMb0CZR49h8JALHGrxjQHWlqGgc8kLdHEgWrgL0uZ29DMvEVBDnHU2Wg36zKSIUtA==", "dev": true }, "@typescript-eslint/eslint-plugin": {