mirror of
https://github.com/oceanprotocol-archive/squid-js.git
synced 2024-02-02 15:31:51 +01:00
Merge branch 'master' into feature/metadata_edit_and_delete
This commit is contained in:
commit
2100cc9de4
14
CHANGELOG.md
14
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)
|
||||
|
||||
|
17
package-lock.json
generated
17
package-lock.json
generated
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@oceanprotocol/squid",
|
||||
"version": "2.0.0-beta.5",
|
||||
"version": "2.0.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
@ -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": {
|
||||
|
@ -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",
|
||||
@ -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",
|
||||
|
@ -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<boolean> {
|
||||
|
@ -5,7 +5,7 @@ import { MetaData, EditableMetaData } 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'
|
||||
|
||||
@ -498,4 +498,67 @@ export class OceanAssets extends Instantiable {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get FreeWhiteList for a DID
|
||||
* @param {string} did Asset DID.
|
||||
* @return {Promise<string[]>} List of addresses.
|
||||
*/
|
||||
public async getFreeWhiteList(did: string): Promise<string[]> {
|
||||
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<TransactionReceipt> {
|
||||
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<TransactionReceipt> {
|
||||
await this.ocean.keeper.didRegistry.revokePermission(
|
||||
did,
|
||||
consumer,
|
||||
account.getId()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
@ -181,4 +185,21 @@ describe('Asset Owners', () => {
|
||||
|
||||
assert.equal(newDDO, null)
|
||||
})
|
||||
|
||||
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()))
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user