From b4b3a98989b98b05d91d0158a31f1ef5c6ba4ad3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 25 Jun 2020 01:08:10 +0000 Subject: [PATCH 1/8] Bump @types/node from 14.0.13 to 14.0.14 Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.0.13 to 14.0.14. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot[bot] --- package-lock.json | 6 +++--- package.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8594e05c..3b2732fb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1548,9 +1548,9 @@ "dev": true }, "@types/node": { - "version": "14.0.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.13.tgz", - "integrity": "sha512-rouEWBImiRaSJsVA+ITTFM6ZxibuAlTuNOCyxVbwreu6k6+ujs7DfnU9o+PShFhET78pMBl3eH+AGSI5eOTkPA==" + "version": "14.0.14", + "resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.14.tgz", + "integrity": "sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ==" }, "@types/node-fetch": { "version": "2.5.7", diff --git a/package.json b/package.json index ab331669..72ab4004 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@types/chai": "^4.2.11", "@types/chai-spies": "^1.0.1", "@types/mocha": "^7.0.2", - "@types/node": "^14.0.13", + "@types/node": "^14.0.14", "@types/node-fetch": "^2.5.5", "@types/sinon": "^9.0.0", "@typescript-eslint/eslint-plugin": "^2.23.0", From a35740d1307af0f0a4e373c225de6439b9b51c02 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Thu, 25 Jun 2020 09:15:52 +0200 Subject: [PATCH 2/8] Update README.md --- README.md | 91 +++++++++++++++---------------------------------------- 1 file changed, 24 insertions(+), 67 deletions(-) diff --git a/README.md b/README.md index da9cef78..06bf73cf 100644 --- a/README.md +++ b/README.md @@ -7,87 +7,44 @@ > JavaScript client library for Ocean Protocol > [oceanprotocol.com](https://oceanprotocol.com) +`ocean-lib` is a Javascript library to privately & securely publish, exchange, +and consume data. With it, you can: +* **Publish** data services: downloadable files, streaming data, or compute-to-data. +Ocean creates a new [ERC20](https://github.com/ethereum/EIPs/blob/7f4f0377730f5fc266824084188cc17cf246932e/EIPS/eip-20.md) +data token for each data service or set of services. +* **Mint** data tokens for the service +* **Consume** data tokens, to access the service +* **Transfer** data tokens to another owner, and **all other ERC20 actions** +using [web3.js](https://web3js.readthedocs.io/en/v1.2.9/web3-eth-contract.html) etc. + +`ocean-lib` is part of the [Ocean Protocol](www.oceanprotocol.com) toolset. + This is in alpha state and you can expect running into problems. If you run into them, please open up a [new issue](/issues). -## Table of Contents +## Quick Install - - [Get Started](#get-started) - - [Local development](#local-development) - - [Testing](#testing) - - [Code Linting](#code-linting) - - [Packages](#packages) - - [Documentation](#documentation) - - [Contributing](#contributing) - - [Prior Art](#prior-art) - - [License](#license) +```npm i @oceanprotocol/lib``` -# Get Started +## Quickstart: Simple Flow -TBD +This stripped-down flow shows the essence of Ocean. Just downloading, no metadata. -### Local development +[Go to simple flow](README_simple_flow.md) -As a pre-requisite, you need: +## Quickstart: Marketplace Flow -- Node.js -- npm +This batteries-included flow includes metadata, multiple services for one datatoken, and compute-to-data. -Note: For MacOS, make sure to have `node@10` installed. +[Go to marketplace flow](README_marketplace_flow.md) -Clone the project and install all dependencies: +## For ocean-lib Developers -```bash -git clone git@github.com:oceanprotocol/ocean-js.git -cd ocean-js/ - -# install packages -npm i - -``` - -# Testing - -Run tests with - -```bash -# for unit tests -TBD - -# for test coverage -TBD -``` - -### Code Linting - -Linting is setup for `JavaScript` with [ESLint](https://eslint.org) - -```bash -# to check lint issues -npm run lint -``` -Code style is enforced through the CI test process, builds will fail if there're any linting errors. - -## Documentation - -* [Release process](doc/RELEASE_PROCESS.md) -* [Core Documentation](doc/contracts/README.md) -* [Packaging of libraries](doc/PACKAGING.md) - -## Contributing - -See the page titled "[Ways to Contribute](https://docs.oceanprotocol.com/concepts/contributing/)" in the Ocean Protocol documentation. - - - -## Prior Art - -This project builds on top of the work done in open source projects: -- [OpenZeppelin/openzeppelin-contracts](https://github.com/OpenZeppelin/openzeppelin-contracts) +[Go to ocean-lib-developers flow](README_ocean-lib-developers.md) ## License ``` -Copyright 2018 Ocean Protocol Foundation +Copyright ((C)) 2020 Ocean Protocol Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -100,4 +57,4 @@ distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -``` \ No newline at end of file +``` From bbd9067e3dd8a087787cc6e435060777eec31990 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Thu, 25 Jun 2020 09:17:34 +0200 Subject: [PATCH 3/8] minor fix --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 06bf73cf..50078aa3 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,8 @@ [![banner](https://raw.githubusercontent.com/oceanprotocol/art/master/github/repo-banner%402x.png)](https://oceanprotocol.com) -|[![Build Status](https://travis-ci.com/oceanprotocol/lib-js.svg?token=soMi2nNfCZq19zS1Rx4i&branch=develop)](https://travis-ci.com/oceanprotocol/lib-js) +|[![Build Status](https://travis-ci.com/oceanprotocol/ocean-lib-js.svg?token=soMi2nNfCZq19zS1Rx4i&branch=develop)](https://travis-ci.com/oceanprotocol/lib-js) -

Lib-js

- -> JavaScript client library for Ocean Protocol -> [oceanprotocol.com](https://oceanprotocol.com) +

Ocean-lib

`ocean-lib` is a Javascript library to privately & securely publish, exchange, and consume data. With it, you can: From 91c953485b7623b2fba5065409e99cfb21141878 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Thu, 25 Jun 2020 09:18:59 +0200 Subject: [PATCH 4/8] Rename README_simpleflow.md to README_simple_flow.md --- README_simpleflow.md => README_simple_flow.md | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename README_simpleflow.md => README_simple_flow.md (100%) diff --git a/README_simpleflow.md b/README_simple_flow.md similarity index 100% rename from README_simpleflow.md rename to README_simple_flow.md From ec5220c9ff9a6eec8671f011563245b8dba17561 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Thu, 25 Jun 2020 09:22:22 +0200 Subject: [PATCH 5/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 50078aa3..67ca98dc 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ [![banner](https://raw.githubusercontent.com/oceanprotocol/art/master/github/repo-banner%402x.png)](https://oceanprotocol.com) -|[![Build Status](https://travis-ci.com/oceanprotocol/ocean-lib-js.svg?token=soMi2nNfCZq19zS1Rx4i&branch=develop)](https://travis-ci.com/oceanprotocol/lib-js) +[![Build Status](https://travis-ci.com/oceanprotocol/ocean-lib-js.svg?token=soMi2nNfCZq19zS1Rx4i&branch=develop)](https://travis-ci.com/oceanprotocol/lib-js)

Ocean-lib

From f8121ce31c5556158166e274c9f4c88ea155acdc Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Thu, 25 Jun 2020 09:23:37 +0200 Subject: [PATCH 6/8] minor link fix --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 67ca98dc..3b1b246b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ data token for each data service or set of services. * **Transfer** data tokens to another owner, and **all other ERC20 actions** using [web3.js](https://web3js.readthedocs.io/en/v1.2.9/web3-eth-contract.html) etc. -`ocean-lib` is part of the [Ocean Protocol](www.oceanprotocol.com) toolset. +`ocean-lib` is part of the [Ocean Protocol](https://oceanprotocol.com) toolset. This is in alpha state and you can expect running into problems. If you run into them, please open up a [new issue](/issues). From 799c2e98f21a5290ef3ca0c97f7645124cbf2b4e Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Thu, 25 Jun 2020 12:10:53 +0200 Subject: [PATCH 7/8] fix initialize --- src/provider/Provider.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index 1d123a42..192fb8fe 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -74,14 +74,21 @@ export class Provider extends Instantiable { serviceType: string, consumerAddress: string ): Promise { - const DDO = await this.ocean.assets.resolve(did) + let DDO + try { + DDO = await this.ocean.assets.resolve(did) + } catch (e) { + this.logger.error(e) + throw new Error('Failed to resolve DID') + } const { dtAddress } = DDO + const args = { - did, - dtAddress, - serviceIndex, - serviceType, - consumerAddress + documentId: did, + serviceId: serviceIndex, + serviceType: serviceType, + tokenAddress: dtAddress, + consumerAddress: consumerAddress } try { From dd64062f8c0a1a0aea2cc182b1a1cb15c7694452 Mon Sep 17 00:00:00 2001 From: Ahmed Ali Date: Thu, 25 Jun 2020 13:29:32 +0200 Subject: [PATCH 8/8] add download method for provider --- src/provider/Provider.ts | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts index 192fb8fe..93613ec0 100644 --- a/src/provider/Provider.ts +++ b/src/provider/Provider.ts @@ -1,7 +1,7 @@ import Account from '../ocean/Account' import { noZeroX } from '../utils' import { Instantiable, InstantiableConfig } from '../Instantiable.abstract' -import { DDO } from '../ddo/DDO' +import { File } from '../ddo/interfaces/File' const apiPath = '/api/v1/services/' @@ -102,6 +102,43 @@ export class Provider extends Instantiable { } } + public async download( + did: string, + txId: string, + tokenAddress: string, + serviceType: string, + serviceIndex: string, + destination: string, + account: Account, + files: File[], + index: number = -1 + ): Promise { + const signature = await this.createSignature(account, did) + const filesPromises = files + .filter((_, i) => index === -1 || i === index) + .map(async ({ index: i }) => { + let consumeUrl = this.getDownloadEndpoint() + consumeUrl += `?index=${i}` + consumeUrl += `&documentId=${did}` + consumeUrl += `&serviceId=${serviceIndex}` + consumeUrl += `&serviceType=${serviceType}` + consumeUrl += `tokenAddress=${tokenAddress}` + consumeUrl += `&transferTxId=${txId}` + consumeUrl += `&consumerAddress=${account.getId()}` + consumeUrl += `&signature=${signature}` + + try { + await this.ocean.utils.fetch.downloadFile(consumeUrl, destination, i) + } catch (e) { + this.logger.error('Error consuming assets') + this.logger.error(e) + throw e + } + }) + await Promise.all(filesPromises) + return destination + } + public async getVersionInfo() { return (await this.ocean.utils.fetch.get(this.url)).json() }