Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions docs/PolicyServer.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,31 @@ Called whenever a DDO is updated by indexer
}
```

### validateDDO

Called whenever a DDO is validated

```json
{
"action":"validateDDO",
"rawDDO": {..},
"publisherAddress": '0x001',
"policyServer": {}
}
```

### initialize

Called whenever a new initialize command is received by Ocean Node

```json
{
"action":"initialize",
"documentId": "did:op:123",
"ddo": {},
"serviceId": "0x123",
"consumerAddress": "0x123"
"policyServer": {}
"action": "initialize",
"documentId": "did:op:123",
"ddo": {},
"serviceId": "0x123",
"consumerAddress": "0x123",
"policyServer": {}
}
```

Expand Down
1 change: 1 addition & 0 deletions src/@types/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export interface ValidateDDOCommand extends Command {
nonce?: string
signature?: string
message?: string
policyServer?: any // object to pass to policy server
}

export interface StatusCommand extends Command {
Expand Down
28 changes: 27 additions & 1 deletion src/components/core/handler/ddoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import ERC721Template from '@oceanprotocol/contracts/artifacts/contracts/templat
// import lzma from 'lzma-native'
import lzmajs from 'lzma-purejs-requirejs'
import { getValidationSignature } from '../utils/validateDdoHandler.js'
import { getConfiguration, hasP2PInterface } from '../../../utils/config.js'
import {
getConfiguration,
hasP2PInterface,
isPolicyServerConfigured
} from '../../../utils/config.js'
import { PolicyServer } from '../../policyServer/index.js'
import {
GetDdoCommand,
FindDDOCommand,
Expand Down Expand Up @@ -839,6 +844,27 @@ export class ValidateDDOHandler extends CommandHandler {
status: { httpStatus: 400, error: `Validation error: ${validation[1]}` }
}
}
if (isPolicyServerConfigured()) {
const policyServer = new PolicyServer()
const response = await policyServer.validateDDO(
task.ddo,
task.publisherAddress,
task.policyServer
)
if (!response) {
CORE_LOGGER.logMessage(
`Error: Validation for ${task.publisherAddress} was denied`,
true
)
return {
stream: null,
status: {
httpStatus: 403,
error: `Error: Validation for ${task.publisherAddress} was denied`
}
}
}
}
return {
stream: shouldSign
? Readable.from(
Expand Down
14 changes: 14 additions & 0 deletions src/components/policyServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ export class PolicyServer {
return await this.askServer(command)
}

async validateDDO(
rawDDO: DDO,
publisherAddress: string,
policyServer: any
): Promise<PolicyServerResult> {
const command = {
action: 'validateDDO',
rawDDO,
publisherAddress,
policyServer
}
return await this.askServer(command)
}

async checkEncrypt(
consumerAddress: string,
policyServer: any
Expand Down
Loading