HUB
Sign inSign up
rating_backend logo

oceanprotocol/rating_backend

By oceanprotocol

•Updated over 6 years ago

Image
0

1.3K

oceanprotocol/rating_backend repository overview

⁠Rating backend server

ENVS:

PORT = port to bind to
AQUARIUS_URI = aquarius_uri to update metadata
PRIVATE_KEY = private key or seed to generate one account (will be auth by aquarius to update ddo)
NODE_URI = Node RPC Uri

⁠Endpoints:

Swagger available at localhost:8000/docs/⁠

⁠POST ​/api​/v1​/rating

Add a rating or replace existing one

Params:

NameExample
did"did:op:1234"
vote1
comment"mycomment"
address"0x5CD7477d14F964F39949169E75C269965A953Bfc"
timestamp1583746239
signature"0x3dfefgafd43545"

Returns:

200 - Vote added

400 - Missing parameters or errors in parameters

401 - Invalid signature

500 - Server error

⁠GET ​/api​/v1​/rating

Get rating for a did and address

Params:

NameExample
did"did:op:1234"
address"0x5CD7477d14F964F39949169E75C269965A953Bfc"

Returns: Object :

{
    vote,
    comment,
    datepublished
}

⁠DELETE ​/api​/v1​/rating

Deletes a vote for a DID from an address

Params:

NameExample
did"did:op:1234"
address"0x5CD7477d14F964F39949169E75C269965A953Bfc"
timestamp1583746239
signature"0x3dfefgafd43545"

Returns:

200 - Vote added

400 - Missing parameters or errors in parameters

401 - Invalid signature

500 - Server error

⁠GET ​/api​/v1​/ratings

Get all rating for a DID Params:

NameExample
did"did:op:1234"

Returns: Array of Objects

{
    address,
    vote,
    comment,
    datepublished
}

⁠Signing

Every endpoint that needs to be authorized needs an timestamp and a signature.

Signature is composed using that timestamp as a message in function web3.eth.personal.sign

Use this sample to sign in js:

function gethash(message) {
    var hex = ''
    for(var i=0;i<message.length;i++) {
        hex += ''+message.charCodeAt(i).toString(16)
    }
    var hexMessage = "0x" + hex
    return hexMessage
}
var timestamp=Math.floor(new Date() / 1000)
var message=String(timestamp)
console.log("Message:"+message)
var accounts=await web3.eth.getAccounts()
var signature=await web3.eth.personal.sign(gethash(text), accounts[0], null)
console.log("Signature:"+signature)

⁠🏄 Get Started

To start local development:


npm install
npm run serve

This will launch the app under localhost:8000⁠.

Tag summary

Content type

Image

Digest

Size

371.2 MB

Last updated

over 6 years ago

docker pull oceanprotocol/rating_backend