mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
fix readme
This commit is contained in:
commit
ae39f7df28
103
README.md
103
README.md
@ -1,100 +1,47 @@
|
|||||||
[](https://oceanprotocol.com)
|
[](https://oceanprotocol.com)
|
||||||
|
|
||||||
|[](https://travis-ci.com/oceanprotocol/lib-js)
|
[](https://travis-ci.com/oceanprotocol/lib-js)
|
||||||
|
|
||||||
<h1 align="center">Lib-js</h1>
|
<h1 align="center">Ocean-lib</h1>
|
||||||
|
|
||||||
> JavaScript client library for Ocean Protocol
|
`ocean-lib` is a Javascript library to privately & securely publish, exchange,
|
||||||
> [oceanprotocol.com](https://oceanprotocol.com)
|
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).
|
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)
|
```npm i @oceanprotocol/lib```
|
||||||
- [Local development](#local-development)
|
|
||||||
- [Testing](#testing)
|
|
||||||
- [Code Linting](#code-linting)
|
|
||||||
- [Packages](#packages)
|
|
||||||
- [Documentation](#documentation)
|
|
||||||
- [Contributing](#contributing)
|
|
||||||
- [Prior Art](#prior-art)
|
|
||||||
- [License](#license)
|
|
||||||
|
|
||||||
# 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
|
This batteries-included flow includes metadata, multiple services for one datatoken, and compute-to-data.
|
||||||
- npm
|
|
||||||
|
|
||||||
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
|
[Go to ocean-lib-developers flow](README_ocean-lib-developers.md)
|
||||||
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)
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
```
|
```
|
||||||
Copyright 2018 Ocean Protocol Foundation
|
Copyright ((C)) 2020 Ocean Protocol Foundation
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with 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.
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
```
|
```
|
||||||
|
6
package-lock.json
generated
6
package-lock.json
generated
@ -1548,9 +1548,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "14.0.13",
|
"version": "14.0.14",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.13.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.0.14.tgz",
|
||||||
"integrity": "sha512-rouEWBImiRaSJsVA+ITTFM6ZxibuAlTuNOCyxVbwreu6k6+ujs7DfnU9o+PShFhET78pMBl3eH+AGSI5eOTkPA=="
|
"integrity": "sha512-syUgf67ZQpaJj01/tRTknkMNoBBLWJOBODF0Zm4NrXmiSuxjymFrxnTu1QVYRubhVkRcZLYZG8STTwJRdVm/WQ=="
|
||||||
},
|
},
|
||||||
"@types/node-fetch": {
|
"@types/node-fetch": {
|
||||||
"version": "2.5.7",
|
"version": "2.5.7",
|
||||||
|
@ -54,7 +54,7 @@
|
|||||||
"@types/chai": "^4.2.11",
|
"@types/chai": "^4.2.11",
|
||||||
"@types/chai-spies": "^1.0.1",
|
"@types/chai-spies": "^1.0.1",
|
||||||
"@types/mocha": "^7.0.2",
|
"@types/mocha": "^7.0.2",
|
||||||
"@types/node": "^14.0.13",
|
"@types/node": "^14.0.14",
|
||||||
"@types/node-fetch": "^2.5.5",
|
"@types/node-fetch": "^2.5.5",
|
||||||
"@types/sinon": "^9.0.0",
|
"@types/sinon": "^9.0.0",
|
||||||
"@typescript-eslint/eslint-plugin": "^2.23.0",
|
"@typescript-eslint/eslint-plugin": "^2.23.0",
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import Account from '../ocean/Account'
|
import Account from '../ocean/Account'
|
||||||
import { noZeroX } from '../utils'
|
import { noZeroX } from '../utils'
|
||||||
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
import { Instantiable, InstantiableConfig } from '../Instantiable.abstract'
|
||||||
import { DDO } from '../ddo/DDO'
|
import { File } from '../ddo/interfaces/File'
|
||||||
|
|
||||||
const apiPath = '/api/v1/provider/services'
|
const apiPath = '/api/v1/provider/services'
|
||||||
|
|
||||||
@ -74,14 +74,21 @@ export class Provider extends Instantiable {
|
|||||||
serviceType: string,
|
serviceType: string,
|
||||||
consumerAddress: string
|
consumerAddress: string
|
||||||
): Promise<any> {
|
): Promise<any> {
|
||||||
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 { dtAddress } = DDO
|
||||||
|
|
||||||
const args = {
|
const args = {
|
||||||
did,
|
documentId: did,
|
||||||
dtAddress,
|
serviceId: serviceIndex,
|
||||||
serviceIndex,
|
serviceType: serviceType,
|
||||||
serviceType,
|
tokenAddress: dtAddress,
|
||||||
consumerAddress
|
consumerAddress: consumerAddress
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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<any> {
|
||||||
|
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() {
|
public async getVersionInfo() {
|
||||||
return (await this.ocean.utils.fetch.get(this.url)).json()
|
return (await this.ocean.utils.fetch.get(this.url)).json()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user