diff --git a/README.md b/README.md
index 6c160392..3b1b246b 100644
--- a/README.md
+++ b/README.md
@@ -1,100 +1,47 @@
[](https://oceanprotocol.com)
-|[](https://travis-ci.com/oceanprotocol/lib-js)
+[](https://travis-ci.com/oceanprotocol/lib-js)
-
Lib-js
+Ocean-lib
-> 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](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).
-## 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
-
-```
-
-Generate metadata:
-```bash
-
-./scripts/get-metadata.js > src/metadata.json
-
-```
-
-# 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.
@@ -107,4 +54,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
+```
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
diff --git a/package-lock.json b/package-lock.json
index 974ec4ac..c101b04b 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 9254a9f3..f98b1875 100644
--- a/package.json
+++ b/package.json
@@ -54,7 +54,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",
diff --git a/src/provider/Provider.ts b/src/provider/Provider.ts
index cbe39c44..96af5534 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/provider/services'
@@ -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 {
@@ -95,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()
}