Skip to content
🐟 Tuna eat squid, so does this. Example showcase for squid
Java TypeScript Python JavaScript HTML Shell
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
browser
java
node
python
scripts
test
testdata
.eslintrc
.gitignore
.travis.yml
README.md
config.ini
package-lock.json
package.json
requirements.txt
tuna.py

README.md

banner

tuna

Cross environment samples of the πŸ¦‘ client library for Ocean Protocol oceanprotocol.com


πŸ²πŸ¦‘ THERE BE DRAGONS AND SQUIDS. This is in alpha state and you can expect running into problems. If you run into them, please open up a new issue. πŸ¦‘πŸ²


Table of Contents


Get started

Setup

virtualenv venv -p python3
source venv/bin/activate
python pip install -r requirements.txt
npm i
export CONFIG_FILE=<your_config_file.ini>

Usage

We're assuming two config files:

  • Consumer: config.development.consumer.ini
  • Provider: config.development.provider.ini
#!/usr/bin/env bash

CLIENT=node
CONFIG_FILE=config.development.provider.ini
./tuna.py assets/register -c ${CLIENT} -f testdata/metadata-example-weather.json > /tmp/did

CONFIG_FILE=config.development.consumer.ini
./tuna.py sea/create -c ${CLIENT} -f /tmp/did > /tmp/sea
./tuna.py sea/hash -c ${CLIENT} -f /tmp/sea > /tmp/hash
./tuna.py sea/sign -c ${CLIENT} -f /tmp/hash > /tmp/sign
#./tuna.py events/subscribe -c ${CLIENT} -f /tmp/hash
# same as above but more realtime output
node node/events/subscribe.js

# since the above listener is blocking the terminal, we'll open a second one
CLIENT=node
CONFIG_FILE=config.development.provider.ini
./tuna.py sea/execute -c ${CLIENT} -f /tmp/sign

CONFIG_FILE=config.development.consumer.ini
./tuna.py sea/pay -c ${CLIENT} -f /tmp/sign

CONFIG_FILE=config.development.provider.ini
./tuna.py sea/auth -c ${CLIENT} -f /tmp/sign

CONFIG_FILE=config.development.consumer.ini
./tuna.py assets/consume -c ${CLIENT} -f /tmp/sign

API

(*) means there's a bug

Accounts

List

> ./tuna.py accounts/list --client={node, python}

which outputs:

[
  {
    "id": "0x64137aF0104d2c96C44bb04AC06f09eC84CC5Ae4"
  }
]

Balance

> ./tuna.py accounts/balance -c {node, python}

which outputs:

{
  "eth": 1000000000,
  "ocn": 400
}

Tokens

Request

> ./tuna.py tokens/request -c {node, python} -i 42 

which outputs:

"42 tokens received"

Assets

Register

> ./tuna.py assets/register -c {browser, node, python} -f testdata/metadata-example-weather.json 

which outputs:

{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf"
}

Resolve

> ./tuna.py assets/resolve -c {node, python} -i did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf 

which outputs:

 {                                                                                                                                                                                                                                                                                                                       
  "@context": "https://w3id.org/future-method/v1",                                                                                                                                                                                                                                                                      
  "authentication": [...],
  "id": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "publicKey": [...],
  "service": [...]
 }

Search

> ./tuna.py assets/search -c {node, python} -i weather 

which outputs:

[  
  "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  ...
]

Consume

> ./tuna.py assets/consume -c {node, python*} -i '{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
}' 

which outputs:

[
    "list of files"
]

Service Execution Agreements

Create

> ./tuna.py sea/create -c {node, python} -i '{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf"
}'

which outputs:

{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementId": "0x27ba400f6c7a4f798d575d6019c76b1ed8953148a2d24feb949a1b6f538f13a9",
  "serviceDefinitionId": "0"
}

Hash

> ./tuna.py sea/hash -c {node, python} -i '{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
  "serviceDefinitionId": "0"
}' 

which outputs:

{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementHash": "0x46db8fc90fd0cc2b9bd958cb6caf00b922952ead5a61acfe996238c882359aaa",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
  "serviceDefinitionId": "0"
}

Sign

> ./tuna.py sea/sign -c {node, python} -i '{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementHash": "0x46db8fc90fd0cc2b9bd958cb6caf00b922952ead5a61acfe996238c882359aaa",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
  "serviceDefinitionId": "0"
}' 

which outputs:

{
  "consumerAddress": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementHash": "0x46db8fc90fd0cc2b9bd958cb6caf00b922952ead5a61acfe996238c882359aaa",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
  "serviceAgreementSignature": "0x9f88c3e4c69bcc4d7136415a1793da49c6e1432745f32bea4b5e4a1f231a2e5d5de162b2d103ea95394a0c867ef5545e54b12468a8700ee0a8f780c0593820191b",
  "serviceDefinitionId": "0"
}

Verify

> ./tuna.py sea/verify -c {python} -i '{
  "consumerAddress": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementHash": "0x46db8fc90fd0cc2b9bd958cb6caf00b922952ead5a61acfe996238c882359aaa",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
  "serviceAgreementSignature": "0x9f88c3e4c69bcc4d7136415a1793da49c6e1432745f32bea4b5e4a1f231a2e5d5de162b2d103ea95394a0c867ef5545e54b12468a8700ee0a8f780c0593820191b",
  "serviceDefinitionId": "0"
}' 

which outputs:

{
  "valid": true
}

Execute

> ./tuna.py sea/execute -c {node, python} -i '{
  "consumerAddress": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementHash": "0x46db8fc90fd0cc2b9bd958cb6caf00b922952ead5a61acfe996238c882359aaa",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
  "serviceAgreementSignature": "0x9f88c3e4c69bcc4d7136415a1793da49c6e1432745f32bea4b5e4a1f231a2e5d5de162b2d103ea95394a0c867ef5545e54b12468a8700ee0a8f780c0593820191b",
  "serviceDefinitionId": "0"
}' 

which outputs:

{
  "blockHash": "0xfc1a02350f7822b56ec499843317d3192d35767f236ac438a7f26376bd525244",
  "receiptStatus": 1,
  "transactionHash": "0x3d50131b165e2ef2f48e748ccde81e7122e910dd1bcf1a956c22f9a99503276f"
}

Send

> ./tuna.py sea/send -c {node*, python} -i '{
  "consumerAddress": "0x00Bd138aBD70e2F00903268F3Db08f2D25677C9e",
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementHash": "0x46db8fc90fd0cc2b9bd958cb6caf00b922952ead5a61acfe996238c882359aaa",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
  "serviceAgreementSignature": "0x9f88c3e4c69bcc4d7136415a1793da49c6e1432745f32bea4b5e4a1f231a2e5d5de162b2d103ea95394a0c867ef5545e54b12468a8700ee0a8f780c0593820191b",
  "serviceDefinitionId": "0"
}' 

which outputs:

{
  "response": 201
}

Pay

> ./tuna.py sea/pay -c {node, python*} -i '{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
}' 

which generates an PaymentLocked event

Auth

> ./tuna.py sea/auth -c {node, python*} -i '{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
}' 

which generates an AccessGranted event

SEA Templates

Register

> ./tuna.py template/register -c {node}

which outputs:

{
  "receiptStatus": "1",
  "templateId": "0x27ba400f6c7a4f798d575d6019c76b1ed8953148a2d24feb949a1b6f538f13a9"
}

Events

Subscribe

> ./tuna.py events/subscribe -c {node} -i '{
  "did": "did:op:0bd1318b7a324557ae311d40dad8cc890f4547dd125e413d8bbd42fc74ca8caf",
  "serviceAgreementId": "0xc8e5b66e157f4afe89b9c8673b01be034321fb8660a94bada3f13a606efffb72",
}' 

which listens to events and displays them for triggering callbacks manually

SecretStore

Encrypt

> ./tuna.py secretstore/encrypt -c {node, python} -i "much secret wow"

which outputs:

{
  "docId": "ded230e093653ae9c27bebe958fdb205a0e053cba8efa9a1c43bbbb5ef81f0d9",
  "encryptedDocument": "0x6653cf03fb81016ad86580c2db3645c6271b6f131c0cc862d5a129e48c861fbd7de40cceb5"
}

Decrypt

> ./tuna.py secretstore/decrypt -c {node, python} -i '{
  "docId": "ded230e093653ae9c27bebe958fdb205a0e053cba8efa9a1c43bbbb5ef81f0d9",
  "encryptedDocument": "0x6653cf03fb81016ad86580c2db3645c6271b6f131c0cc862d5a129e48c861fbd7de40cceb5"
}'

which outputs:

"much secret wow"

License

Copyright 2018 Ocean Protocol Foundation Ltd.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
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.
You can’t perform that action at this time.