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 { export interface File {
/** /**
* File name. * File name.
@ -147,7 +126,7 @@ export interface MetaDataMain {
license: string license: string
/** /**
* Price of the asset. * Price of the asset in vodka (attoOCEAN). It must be an integer encoded as a string.
* @type {string} * @type {string}
* @example "1000000000000000000" * @example "1000000000000000000"
*/ */
@ -159,10 +138,10 @@ export interface MetaDataMain {
*/ */
files: File[] files: File[]
encryptedService?: any /**
* Metadata used only for assets with type `algorithm`.
service?: Service * @type {MetaDataAlgorithm}
*/
algorithm?: MetaDataAlgorithm algorithm?: MetaDataAlgorithm
} }

View File

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

236
test/testdata/ddo.json vendored
View File

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