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:
parent
b86caf343a
commit
768c69bdbd
@ -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
|
||||
}
|
||||
|
||||
|
@ -7,52 +7,32 @@ export interface ServiceCommon {
|
||||
type: ServiceType
|
||||
index: number
|
||||
serviceEndpoint?: string
|
||||
attributes: any & {
|
||||
main: { [key: string]: any }
|
||||
additionalInformation?: { [key: string]: any }
|
||||
attributes: ServiceCommonAttributes
|
||||
}
|
||||
|
||||
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 {
|
||||
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: {
|
||||
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
|
||||
export interface ServiceComputeAttributes extends ServiceCommonAttributes {
|
||||
main: {
|
||||
creator: string
|
||||
datePublished: string
|
||||
price: string
|
||||
timeout: number
|
||||
provider?: 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'
|
||||
|
236
test/testdata/ddo.json
vendored
236
test/testdata/ddo.json
vendored
@ -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",
|
||||
"conditions": [
|
||||
{
|
||||
"name": "lockPayment",
|
||||
"timeout": 0,
|
||||
"conditionKey": {
|
||||
"contractAddress": "0x...",
|
||||
"fingerprint": "0x..."
|
||||
},
|
||||
"parameters": {
|
||||
"assetId": "bytes32",
|
||||
"price": "integer"
|
||||
},
|
||||
"events": {
|
||||
"PaymentLocked": {
|
||||
"actorType": ["publisher"],
|
||||
"handlers": [
|
||||
{
|
||||
"moduleName": "accessControl",
|
||||
"functionName": "grantAccess",
|
||||
"version": "0.1"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
"attributes": {
|
||||
"main": {
|
||||
"name": "dataAssetAccessServiceAgreement",
|
||||
"creator": "0x36A7f3383A63279cDaF4DfC0F3ABc07d90252C6b",
|
||||
"datePublished": "2019-11-15T14:11:23Z",
|
||||
"price": "",
|
||||
"timeout": 36000
|
||||
},
|
||||
{
|
||||
"name": "releasePayment",
|
||||
"timeout": 0,
|
||||
"conditionKey": {
|
||||
"contractAddress": "0x...",
|
||||
"fingerprint": "0xXXXXXXXX"
|
||||
"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"]
|
||||
},
|
||||
"parameters": {
|
||||
"assetId": "bytes32",
|
||||
"price": "integer"
|
||||
},
|
||||
"events": {
|
||||
"PaymentReleased": {
|
||||
"actorType": ["publisher"],
|
||||
"handlers": [
|
||||
"conditions": [
|
||||
{
|
||||
"name": "lockReward",
|
||||
"timelock": 0,
|
||||
"timeout": 0,
|
||||
"contractName": "LockRewardCondition",
|
||||
"functionName": "fulfill",
|
||||
"parameters": [
|
||||
{
|
||||
"moduleName": "serviceAgreement",
|
||||
"functionName": "fulfillAgreement",
|
||||
"version": "0.1"
|
||||
"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": "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",
|
||||
@ -354,7 +404,7 @@
|
||||
"dateCreated": "2012-10-10T17:00:000Z",
|
||||
"author": "Met Office",
|
||||
"license": "CC-BY",
|
||||
"price": 10,
|
||||
"price": "1000000000000000000",
|
||||
"files": [
|
||||
{
|
||||
"index": 0,
|
||||
|
Loading…
Reference in New Issue
Block a user