1
0
mirror of https://github.com/oceanprotocol-archive/squid-js.git synced 2024-02-02 15:31:51 +01:00

service interface refactor and cleanup

This commit is contained in:
Matthias Kretschmann 2020-01-29 13:34:12 +01:00
parent b86caf343a
commit 768c69bdbd
Signed by: m
GPG Key ID: 606EEEF3C479A91F
3 changed files with 193 additions and 162 deletions

View File

@ -1,24 +1,3 @@
export interface ServiceDefinition {
auth: {
type: string
user?: string
password?: string
token?: string
}
endpoints: {
index: number
url: string
method: string
contentTypes: string[]
}
}
export interface Service {
spec?: string
specChecksum?: string
definition: ServiceDefinition
}
export interface File {
/**
* File name.
@ -147,7 +126,7 @@ export interface MetaDataMain {
license: string
/**
* Price of the asset.
* Price of the asset in vodka (attoOCEAN). It must be an integer encoded as a string.
* @type {string}
* @example "1000000000000000000"
*/
@ -159,10 +138,10 @@ export interface MetaDataMain {
*/
files: File[]
encryptedService?: any
service?: Service
/**
* Metadata used only for assets with type `algorithm`.
* @type {MetaDataAlgorithm}
*/
algorithm?: MetaDataAlgorithm
}

View File

@ -7,26 +7,16 @@ export interface ServiceCommon {
type: ServiceType
index: number
serviceEndpoint?: string
attributes: any & {
attributes: ServiceCommonAttributes
}
export interface ServiceCommonAttributes {
main: { [key: string]: any }
additionalInformation?: { [key: string]: any }
}
serviceAgreementTemplate?: ServiceAgreementTemplate
}
export interface ServiceAuthorization extends ServiceCommon {
type: 'authorization'
service: 'SecretStore' | 'None' | 'RSAES-OAEP'
}
export interface ServiceMetadata extends ServiceCommon {
type: 'metadata'
attributes: MetaData
}
export interface ServiceAccess extends ServiceCommon {
type: 'access'
templateId?: string
attributes: {
export interface ServiceAccessAttributes extends ServiceCommonAttributes {
main: {
creator: string
name: string
@ -34,17 +24,9 @@ export interface ServiceAccess extends ServiceCommon {
price: string
timeout: number
}
additionalInformation: {
description: string
}
serviceAgreementTemplate?: ServiceAgreementTemplate
}
}
export interface ServiceCompute extends ServiceCommon {
type: 'compute'
templateId?: string
attributes: {
export interface ServiceComputeAttributes extends ServiceCommonAttributes {
main: {
creator: string
datePublished: string
@ -52,8 +34,6 @@ export interface ServiceCompute extends ServiceCommon {
timeout: number
provider?: ServiceComputeProvider
}
serviceAgreementTemplate?: ServiceAgreementTemplate
}
}
export interface ServiceComputeProvider {
@ -82,6 +62,28 @@ export interface ServiceComputeProvider {
}
}
export interface ServiceAuthorization extends ServiceCommon {
type: 'authorization'
service: 'SecretStore' | 'None' | 'RSAES-OAEP'
}
export interface ServiceMetadata extends ServiceCommon {
type: 'metadata'
attributes: MetaData
}
export interface ServiceAccess extends ServiceCommon {
type: 'access'
templateId?: string
attributes: ServiceAccessAttributes
}
export interface ServiceCompute extends ServiceCommon {
type: 'compute'
templateId?: string
attributes: ServiceComputeAttributes
}
export type Service<
T extends ServiceType | 'default' = 'default'
> = T extends 'authorization'

202
test/testdata/ddo.json vendored
View File

@ -42,106 +42,156 @@
"type": "access",
"index": 0,
"serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}",
"purchaseEndpoint": "http://mybrizo.org/api/v1/brizo/services/access/purchase?",
"templateId": "044852b2a670ade5407e78fb2863c51000000000000000000000000000000000",
"attributes": {
"main": {
"name": "dataAssetAccessServiceAgreement",
"creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b",
"datePublished": "2019-11-15T14:11:23Z",
"price": "",
"timeout": 36000
},
"serviceAgreementTemplate": {
"contractName": "EscrowAccessSecretStoreTemplate",
"events": [
{
"name": "AgreementCreated",
"actorType": "consumer",
"handler": {
"moduleName": "escrowAccessSecretStoreTemplate",
"functionName": "fulfillLockRewardCondition",
"version": "0.1"
}
}
],
"fulfillmentOrder": [
"lockReward.fulfill",
"accessSecretStore.fulfill",
"escrowReward.fulfill"
],
"conditionDependency": {
"lockReward": [],
"accessSecretStore": [],
"escrowReward": ["lockReward", "accessSecretStore"]
},
"conditions": [
{
"name": "lockPayment",
"name": "lockReward",
"timelock": 0,
"timeout": 0,
"conditionKey": {
"contractAddress": "0x...",
"fingerprint": "0x..."
},
"parameters": {
"assetId": "bytes32",
"price": "integer"
},
"events": {
"PaymentLocked": {
"actorType": ["publisher"],
"handlers": [
"contractName": "LockRewardCondition",
"functionName": "fulfill",
"parameters": [
{
"moduleName": "accessControl",
"functionName": "grantAccess",
"name": "_rewardAddress",
"type": "address",
"value": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b"
},
{
"name": "_amount",
"type": "uint256",
"value": "0"
}
],
"events": [
{
"name": "Fulfilled",
"actorType": "publisher",
"handler": {
"moduleName": "lockRewardCondition",
"functionName": "fulfillAccessSecretStoreCondition",
"version": "0.1"
}
}
]
}
}
},
{
"name": "releasePayment",
"name": "accessSecretStore",
"timelock": 0,
"timeout": 0,
"conditionKey": {
"contractAddress": "0x...",
"fingerprint": "0xXXXXXXXX"
},
"parameters": {
"assetId": "bytes32",
"price": "integer"
},
"events": {
"PaymentReleased": {
"actorType": ["publisher"],
"handlers": [
"contractName": "AccessSecretStoreCondition",
"functionName": "fulfill",
"parameters": [
{
"moduleName": "serviceAgreement",
"functionName": "fulfillAgreement",
"name": "_documentId",
"type": "bytes32",
"value": "c678e7e5963d4fdc99afea49ac221d4d4177790f30204417823319d4d35f851f"
},
{
"name": "_grantee",
"type": "address",
"value": ""
}
],
"events": [
{
"name": "Fulfilled",
"actorType": "publisher",
"handler": {
"moduleName": "accessSecretStore",
"functionName": "fulfillEscrowRewardCondition",
"version": "0.1"
}
]
}
}
},
{
"name": "grantAccess",
"name": "TimedOut",
"actorType": "consumer",
"handler": {
"moduleName": "accessSecretStore",
"functionName": "fulfillEscrowRewardCondition",
"version": "0.1"
}
}
]
},
{
"name": "escrowReward",
"timelock": 0,
"timeout": 0,
"conditionKey": {
"contractAddress": "0x",
"fingerprint": "0xXXXXXXXX"
},
"parameters": {
"assetId": "bytes32",
"documentKeyId": "bytes32"
},
"events": {
"AccessGranted": {
"actorType": ["consumer"],
"handlers": [
"contractName": "EscrowReward",
"functionName": "fulfill",
"parameters": [
{
"moduleName": "asset",
"functionName": "consumeService",
"name": "_amount",
"type": "uint256",
"value": "0"
},
{
"name": "_receiver",
"type": "address",
"value": ""
},
{
"name": "_sender",
"type": "address",
"value": ""
},
{
"name": "_lockCondition",
"type": "bytes32",
"value": ""
},
{
"name": "_releaseCondition",
"type": "bytes32",
"value": ""
}
],
"events": [
{
"name": "Fulfilled",
"actorType": "publisher",
"handler": {
"moduleName": "escrowRewardCondition",
"functionName": "verifyRewardTokens",
"version": "0.1"
}
}
]
}
}
},
{
"name": "refundPayment",
"timeout": 1,
"condition_key": {
"contractAddress": "0x...",
"fingerprint": "0xXXXXXXXX"
},
"parameters": {
"assetId": "bytes32",
"price": "int"
},
"events": {
"PaymentRefund": {
"actorType": ["consumer"],
"handlers": [
{
"moduleName": "serviceAgreement",
"functionName": "fulfillAgreement",
"version": "0.1"
}
]
}
}
}
]
},
{
"type": "compute",
@ -354,7 +404,7 @@
"dateCreated": "2012-10-10T17:00:000Z",
"author": "Met Office",
"license": "CC-BY",
"price": 10,
"price": "1000000000000000000",
"files": [
{
"index": 0,