mirror of
https://github.com/oceanprotocol/commons.git
synced 2023-03-15 18:03:00 +01:00
ddo path
This commit is contained in:
parent
92cfc80bec
commit
fb7914478d
@ -55,13 +55,12 @@ Url Checker returns if file exists, size and additional information about reques
|
|||||||
|
|
||||||
Retires asset from Commons Marketplace. To verify owner, he needs to sign `You are retiring <asset did>` with crypto wallet and send in both signature and did.
|
Retires asset from Commons Marketplace. To verify owner, he needs to sign `You are retiring <asset did>` with crypto wallet and send in both signature and did.
|
||||||
|
|
||||||
**Endpoint:** POST `/api/v1/retireddo`
|
**Endpoint:** DELETE `/api/v1/ddo/<asset did>`
|
||||||
|
|
||||||
**Input Parameters:**
|
**Input Parameters:**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"did": "did:op:1e69c2ae7cca4c0e852204443208c12c3aa58bfd67c7451cb1ee770df1dcae2b",
|
|
||||||
"signature": "<signature of `You are retiring <asset did>`>"
|
"signature": "<signature of `You are retiring <asset did>`>"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -87,13 +86,12 @@ Retires asset from Commons Marketplace. To verify owner, he needs to sign `You a
|
|||||||
|
|
||||||
Updates asset on Commons Marketplace. To verify owner, he needs to sign `You are updating <asset did>` with crypto wallet and send in both signature and did.
|
Updates asset on Commons Marketplace. To verify owner, he needs to sign `You are updating <asset did>` with crypto wallet and send in both signature and did.
|
||||||
|
|
||||||
**Endpoint:** POST `/api/v1/updateddo`
|
**Endpoint:** PUT `/api/v1/ddo/<asset did>`
|
||||||
|
|
||||||
**Input Parameters:**
|
**Input Parameters:**
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"did": "did:op:1e69c2ae7cca4c0e852204443208c12c3aa58bfd67c7451cb1ee770df1dcae2b",
|
|
||||||
"metadata": "TBD",
|
"metadata": "TBD",
|
||||||
"signature": "<signature of `You are retiring <asset did>`>"
|
"signature": "<signature of `You are retiring <asset did>`>"
|
||||||
}
|
}
|
||||||
|
104
server/src/routes/DdoRouter.ts
Normal file
104
server/src/routes/DdoRouter.ts
Normal file
@ -0,0 +1,104 @@
|
|||||||
|
import { Router, Request, Response } from 'express'
|
||||||
|
import { getProviders } from '../utils'
|
||||||
|
|
||||||
|
export class UpdateRouter {
|
||||||
|
public router: Router
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the UpdateRouter
|
||||||
|
*/
|
||||||
|
public constructor() {
|
||||||
|
this.router = Router()
|
||||||
|
}
|
||||||
|
|
||||||
|
public async updateDdo(req: Request, res: Response) {
|
||||||
|
if (!req.params.did || !req.body.signature) {
|
||||||
|
return res.send({
|
||||||
|
status: 'error',
|
||||||
|
message: 'Missing did or signature'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const providers = await getProviders()
|
||||||
|
try {
|
||||||
|
const userAccount = await providers.web3.eth.personal.ecRecover(
|
||||||
|
`You are updating ${req.params.did}`,
|
||||||
|
req.body.signature
|
||||||
|
)
|
||||||
|
const events = await providers.ocean.keeper.didRegistry.contract.getPastEvents(
|
||||||
|
'DIDAttributeRegistered',
|
||||||
|
{
|
||||||
|
filter: {
|
||||||
|
_owner: userAccount,
|
||||||
|
_did: req.params.did.replace('did:op:', '0x')
|
||||||
|
},
|
||||||
|
fromBlock: 0,
|
||||||
|
toBlock: 'latest'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (events.length > 0) {
|
||||||
|
// TODO: update asset in Aquarius
|
||||||
|
res.send({ status: 'success' })
|
||||||
|
} else {
|
||||||
|
return res.send({
|
||||||
|
status: 'error',
|
||||||
|
message: 'Not owner of asset'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return res.send({ status: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async retireDdo(req: Request, res: Response) {
|
||||||
|
if (!req.params.did || !req.body.signature) {
|
||||||
|
return res.send({
|
||||||
|
status: 'error',
|
||||||
|
message: 'Missing did or signature'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
const providers = await getProviders()
|
||||||
|
try {
|
||||||
|
const userAccount = await providers.web3.eth.personal.ecRecover(
|
||||||
|
`You are retiring ${req.params.did}`,
|
||||||
|
req.body.signature
|
||||||
|
)
|
||||||
|
const events = await providers.ocean.keeper.didRegistry.contract.getPastEvents(
|
||||||
|
'DIDAttributeRegistered',
|
||||||
|
{
|
||||||
|
filter: {
|
||||||
|
_owner: userAccount,
|
||||||
|
_did: req.params.did.replace('did:op:', '0x')
|
||||||
|
},
|
||||||
|
fromBlock: 0,
|
||||||
|
toBlock: 'latest'
|
||||||
|
}
|
||||||
|
)
|
||||||
|
if (events.length > 0) {
|
||||||
|
// TODO: retire asset in Aquarius
|
||||||
|
res.send({ status: 'success' })
|
||||||
|
} else {
|
||||||
|
return res.send({
|
||||||
|
status: 'error',
|
||||||
|
message: 'Not owner of asset'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
return res.send({ status: 'error' })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Take each handler, and attach to one of the Express.Router's
|
||||||
|
* endpoints.
|
||||||
|
*/
|
||||||
|
public init() {
|
||||||
|
this.router.put('/:did', this.updateDdo)
|
||||||
|
this.router.delete('/:did', this.retireDdo)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the updateRouter, and export its configured Express.Router
|
||||||
|
const updateRouter = new UpdateRouter()
|
||||||
|
updateRouter.init()
|
||||||
|
|
||||||
|
export default updateRouter.router
|
@ -1,65 +0,0 @@
|
|||||||
import { Router, Request, Response } from 'express'
|
|
||||||
import { getProviders } from '../utils'
|
|
||||||
|
|
||||||
export class RetireRouter {
|
|
||||||
public router: Router
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the RetireRouter
|
|
||||||
*/
|
|
||||||
public constructor() {
|
|
||||||
this.router = Router()
|
|
||||||
}
|
|
||||||
|
|
||||||
public async retireDid(req: Request, res: Response) {
|
|
||||||
if (!req.body.did || !req.body.signature) {
|
|
||||||
return res.send({
|
|
||||||
status: 'error',
|
|
||||||
message: 'Missing did or signature'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const providers = await getProviders()
|
|
||||||
try {
|
|
||||||
const userAccount = await providers.web3.eth.personal.ecRecover(
|
|
||||||
`You are retiring ${req.body.did}`,
|
|
||||||
req.body.signature
|
|
||||||
)
|
|
||||||
const events = await providers.ocean.keeper.didRegistry.contract.getPastEvents(
|
|
||||||
'DIDAttributeRegistered',
|
|
||||||
{
|
|
||||||
filter: {
|
|
||||||
_owner: userAccount,
|
|
||||||
_did: req.body.did.replace('did:op:', '0x')
|
|
||||||
},
|
|
||||||
fromBlock: 0,
|
|
||||||
toBlock: 'latest'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if (events.length > 0) {
|
|
||||||
// TODO: retire asset in Aquarius
|
|
||||||
res.send({ status: 'success' })
|
|
||||||
} else {
|
|
||||||
return res.send({
|
|
||||||
status: 'error',
|
|
||||||
message: 'Not owner of asset'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return res.send({ status: 'error' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Take each handler, and attach to one of the Express.Router's
|
|
||||||
* endpoints.
|
|
||||||
*/
|
|
||||||
public init() {
|
|
||||||
this.router.post('/', this.retireDid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the retireRouter, and export its configured Express.Router
|
|
||||||
const retireRouter = new RetireRouter()
|
|
||||||
retireRouter.init()
|
|
||||||
|
|
||||||
export default retireRouter.router
|
|
@ -1,65 +0,0 @@
|
|||||||
import { Router, Request, Response } from 'express'
|
|
||||||
import { getProviders } from '../utils'
|
|
||||||
|
|
||||||
export class UpdateRouter {
|
|
||||||
public router: Router
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the UpdateRouter
|
|
||||||
*/
|
|
||||||
public constructor() {
|
|
||||||
this.router = Router()
|
|
||||||
}
|
|
||||||
|
|
||||||
public async updateDid(req: Request, res: Response) {
|
|
||||||
if (!req.body.did || !req.body.signature) {
|
|
||||||
return res.send({
|
|
||||||
status: 'error',
|
|
||||||
message: 'Missing did or signature'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
const providers = await getProviders()
|
|
||||||
try {
|
|
||||||
const userAccount = await providers.web3.eth.personal.ecRecover(
|
|
||||||
`You are updating ${req.body.did}`,
|
|
||||||
req.body.signature
|
|
||||||
)
|
|
||||||
const events = await providers.ocean.keeper.didRegistry.contract.getPastEvents(
|
|
||||||
'DIDAttributeRegistered',
|
|
||||||
{
|
|
||||||
filter: {
|
|
||||||
_owner: userAccount,
|
|
||||||
_did: req.body.did.replace('did:op:', '0x')
|
|
||||||
},
|
|
||||||
fromBlock: 0,
|
|
||||||
toBlock: 'latest'
|
|
||||||
}
|
|
||||||
)
|
|
||||||
if (events.length > 0) {
|
|
||||||
// TODO: update asset in Aquarius
|
|
||||||
res.send({ status: 'success' })
|
|
||||||
} else {
|
|
||||||
return res.send({
|
|
||||||
status: 'error',
|
|
||||||
message: 'Not owner of asset'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} catch (error) {
|
|
||||||
return res.send({ status: 'error' })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Take each handler, and attach to one of the Express.Router's
|
|
||||||
* endpoints.
|
|
||||||
*/
|
|
||||||
public init() {
|
|
||||||
this.router.post('/', this.updateDid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create the updateRouter, and export its configured Express.Router
|
|
||||||
const updateRouter = new UpdateRouter()
|
|
||||||
updateRouter.init()
|
|
||||||
|
|
||||||
export default updateRouter.router
|
|
@ -6,8 +6,7 @@ import bodyParser from 'body-parser'
|
|||||||
|
|
||||||
// routes
|
// routes
|
||||||
import UrlCheckRouter from './routes/UrlCheckRouter'
|
import UrlCheckRouter from './routes/UrlCheckRouter'
|
||||||
import UpdateRouter from './routes/UpdateRouter'
|
import DdoRouter from './routes/DdoRouter'
|
||||||
import RetireRouter from './routes/RetireRouter'
|
|
||||||
|
|
||||||
// config
|
// config
|
||||||
import config from './config/config'
|
import config from './config/config'
|
||||||
@ -53,8 +52,7 @@ app.use(bodyParser.urlencoded({ extended: false }))
|
|||||||
app.use(compression())
|
app.use(compression())
|
||||||
// routes
|
// routes
|
||||||
app.use('/api/v1/urlcheck', UrlCheckRouter)
|
app.use('/api/v1/urlcheck', UrlCheckRouter)
|
||||||
app.use('/api/v1/updateddo', UpdateRouter)
|
app.use('/api/v1/ddo', DdoRouter)
|
||||||
app.use('/api/v1/retireddo', RetireRouter)
|
|
||||||
|
|
||||||
/// catch 404
|
/// catch 404
|
||||||
app.use((req, res) => {
|
app.use((req, res) => {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import * as Web3 from 'web3'
|
import Web3 from 'web3'
|
||||||
import { Ocean } from '@oceanprotocol/squid'
|
import { Ocean } from '@oceanprotocol/squid'
|
||||||
import config from './config/config'
|
import config from './config/config'
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user