From 518a7845544531b0e8ef2fc30dc31657a39fe9c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Guti=C3=A9rrez?= Date: Mon, 4 Feb 2019 11:46:24 +0100 Subject: [PATCH] improved exportation of typings related to DDOs --- src/aquarius/Aquarius.ts | 4 +- src/ddo/AdditionalInformation.ts | 39 --- src/ddo/Authentication.ts | 6 +- src/ddo/Condition.ts | 59 ++++- src/ddo/Contract.ts | 8 +- src/ddo/Curation.ts | 26 -- src/ddo/DDO.ts | 18 +- src/ddo/Dependency.ts | 4 - src/ddo/Event.ts | 25 +- src/ddo/EventHandler.ts | 5 - src/ddo/MetaData.ts | 260 +++++++++++++++----- src/ddo/MetaDataBase.ts | 147 ----------- src/ddo/Parameter.ts | 5 - src/ddo/Proof.ts | 6 + src/ddo/PublicKey.ts | 33 ++- src/ddo/Service.ts | 26 +- src/ddo/StructuredMarkup.ts | 4 - src/examples/config/config.json | 2 +- src/ocean/OceanAssets.ts | 29 +-- test/aquarius/Aquarius.test.ts | 4 +- test/ddo/DDO.test.ts | 24 +- test/mocks/Aquarius.mock.ts | 2 +- test/ocean/Ocean.test.ts | 40 +-- test/ocean/ServiceAgreement.test.ts | 12 +- test/ocean/ServiceAgreementTemplate.test.ts | 7 +- test/testdata/MetaData.ts | 51 ++-- 26 files changed, 413 insertions(+), 433 deletions(-) delete mode 100644 src/ddo/AdditionalInformation.ts delete mode 100644 src/ddo/Curation.ts delete mode 100644 src/ddo/Dependency.ts delete mode 100644 src/ddo/EventHandler.ts delete mode 100644 src/ddo/MetaDataBase.ts delete mode 100644 src/ddo/Parameter.ts create mode 100644 src/ddo/Proof.ts delete mode 100644 src/ddo/StructuredMarkup.ts diff --git a/src/aquarius/Aquarius.ts b/src/aquarius/Aquarius.ts index abe61cb..cc3766e 100644 --- a/src/aquarius/Aquarius.ts +++ b/src/aquarius/Aquarius.ts @@ -1,5 +1,5 @@ -import {URL} from "whatwg-url" -import DDO from "../ddo/DDO" +import { URL } from "whatwg-url" +import { DDO } from "../ddo/DDO" import Config from "../models/Config" import DID from "../ocean/DID" import Logger from "../utils/Logger" diff --git a/src/ddo/AdditionalInformation.ts b/src/ddo/AdditionalInformation.ts deleted file mode 100644 index c4878eb..0000000 --- a/src/ddo/AdditionalInformation.ts +++ /dev/null @@ -1,39 +0,0 @@ -import StructuredMarkup from "./StructuredMarkup" - -/** - * Additional Information of Assets Metadata. - * @see https://github.com/oceanprotocol/OEPs/tree/master/8#additional-information - */ -export default class AdditionalInformation { - /** - * An indication of update latency - i.e. How often are updates expected (seldom, - * annually, quarterly, etc.), or is the resource static that is never expected - * to get updated. - * @type {string} - * @example "yearly" - */ - public updateFrecuency: string = "yearly" - - /** - * A link to machine-readable structured markup (such as ttl/json-ld/rdf) - * describing the dataset. - * @type {StructuredMarkup[]} - */ - public structuredMarkup: StructuredMarkup[] = [ - { - uri: "http://skos.um.es/unescothes/C01194/jsonld", - mediaType: "application/ld+json", - } as StructuredMarkup, - { - uri: "http://skos.um.es/unescothes/C01194/turtle", - mediaType: "text/turtle", - } as StructuredMarkup, - ] - - /** - * Checksum of attributes to be able to compare if there are changes in - * the asset that you are purchasing. - * @type {string} - */ - public checksum: string -} diff --git a/src/ddo/Authentication.ts b/src/ddo/Authentication.ts index bd4689a..b5e1869 100644 --- a/src/ddo/Authentication.ts +++ b/src/ddo/Authentication.ts @@ -1,4 +1,4 @@ -export default class Authentication { - public type: string = "RsaSignatureAuthentication2018" - public publicKey: string = "did:op:123456789abcdefghi#keys-1" +export interface Authentication { + public type: string + public publicKey: string } diff --git a/src/ddo/Condition.ts b/src/ddo/Condition.ts index ff88d89..e41168f 100644 --- a/src/ddo/Condition.ts +++ b/src/ddo/Condition.ts @@ -1,15 +1,48 @@ -import Dependency from "./Dependency" -import Event from "./Event" -import Parameter from "./Parameter" +import { Event } from "./Event" -export default class Condition { - public name: string - public contractName: string = "AccessCondition" - public functionName: string = "lockPayment" - public timeout: number = 0 - public conditionKey: string = "0x12122434" - public parameters: Parameter[] - public events: Event[] - public dependencies: Dependency[] = [] - public isTerminalCondition: boolean = false +export interface Parameter { + name: string + type: string + value: any +} + +export interface Dependency { + /** + * @example "lockPayment" + */ + name: string + /** + * @example 0 + */ + timeout: number +} + +export interface Condition { + name: string + /** + * @example "AccessCondition" + */ + contractName: string + /** + * @example "lockPayment" + */ + functionName: string + /** + * @example 0 + */ + timeout: number + /** + * @example "0x12122434" + */ + conditionKey: string + parameters: Parameter[] + events: Event[] + /** + * @example [] + */ + dependencies: Dependency[] + /** + * @example false + */ + isTerminalCondition: boolean } diff --git a/src/ddo/Contract.ts b/src/ddo/Contract.ts index 0396a1a..208f79e 100644 --- a/src/ddo/Contract.ts +++ b/src/ddo/Contract.ts @@ -1,7 +1,7 @@ import Event from "./Event" -export default class Contract { - public contractName: string - public fulfillmentOperator: number - public events: Event[] +export interface Contract { + contractName: string + fulfillmentOperator: number + events: Event[] } diff --git a/src/ddo/Curation.ts b/src/ddo/Curation.ts deleted file mode 100644 index 95e0cc0..0000000 --- a/src/ddo/Curation.ts +++ /dev/null @@ -1,26 +0,0 @@ -/** - * Curation attributes of Assets Metadata. - * @see https://github.com/oceanprotocol/OEPs/tree/master/8#curation-attributes - */ -export default class Curation { - /** - * Decimal value between 0 and 1. 0 is the default value. - * @type {number} - * @example 0.93 - */ - public rating: number = 0.93 - - /** - * Number of votes. 0 is the default value. - * @type {number} - * @example 123 - */ - public numVotes: number = 123 - - /** - * Schema applied to calculate the rating. - * @type {number} - * @example "Binary Votting" - */ - public schema?: string = "Binary Votting" -} diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index 94825b1..ee5c471 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -1,12 +1,13 @@ -import Authentication from "./Authentication" -import PublicKey from "./PublicKey" -import Service from "./Service" +import { Authentication } from "./Authentication" +import { PublicKey } from "./PublicKey" +import { Service } from "./Service" +import { Proof } from "./Proof" /** * DID Descriptor Object. * Contains all the data related to an asset. */ -export default class DDO { +export class DDO { /** * Serializes the DDO object. @@ -29,6 +30,7 @@ export default class DDO { } public "@context": string = "https://w3id.org/future-method/v1" + /** * DID, descentralized ID. * @type {string} @@ -37,13 +39,9 @@ export default class DDO { public publicKey: PublicKey[] public authentication: Authentication[] public service: Service[] + public proof: Proof - public constructor(ddo?: { - id?: string, - publicKey?: PublicKey[], - authentication?: Authentication[], - service?: Service[], - }) { + public constructor(ddo?: Partial) { this.authentication = (ddo && ddo.authentication) || [] this.id = (ddo && ddo.id) || null this.publicKey = (ddo && ddo.publicKey) || [] diff --git a/src/ddo/Dependency.ts b/src/ddo/Dependency.ts deleted file mode 100644 index 2a824f6..0000000 --- a/src/ddo/Dependency.ts +++ /dev/null @@ -1,4 +0,0 @@ -export default class Dependency { - public name: string = "lockPayment" - public timeout: number = 0 -} diff --git a/src/ddo/Event.ts b/src/ddo/Event.ts index 2195acf..ac70afe 100644 --- a/src/ddo/Event.ts +++ b/src/ddo/Event.ts @@ -1,7 +1,20 @@ -import EventHandler from "./EventHandler" - -export default class Event { - public name: string - public actorType: string - public handler: EventHandler +export interface EventHandler { + /** + * @example "serviceAgreement" + */ + moduleName: string + /** + * @example "fulfillAgreement" + */ + functionName: string + /** + * @example "0.1" + */ + version: string +} + +export interface Event { + name: string + actorType: string + handler: EventHandler } diff --git a/src/ddo/EventHandler.ts b/src/ddo/EventHandler.ts deleted file mode 100644 index 5819cda..0000000 --- a/src/ddo/EventHandler.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default class EventHandler { - public moduleName: string = "serviceAgreement" - public functionName: string = "fulfillAgreement" - public version: string = "0.1" -} diff --git a/src/ddo/MetaData.ts b/src/ddo/MetaData.ts index 5d89388..6cfbee1 100644 --- a/src/ddo/MetaData.ts +++ b/src/ddo/MetaData.ts @@ -1,65 +1,209 @@ -import AdditionalInformation from "./AdditionalInformation" -import Curation from "./Curation" -import MetaDataBase from "./MetaDataBase" -import StructuredMarkup from "./StructuredMarkup" +/** + * Base attributes of Assets Metadata. + * @see https://github.com/oceanprotocol/OEPs/tree/master/8#base-attributes + */ +export class MetaDataBase { -const base: MetaDataBase = { - name: "UK Weather information 2011", - type: "dataset", - description: "Weather information of UK including temperature and humidity", - size: "3.1gb", - dateCreated: "2012-02-01T10:55:11+00:00", - author: "Met Office", - license: "CC-BY", - copyrightHolder: "Met Office", - encoding: "UTF-8", - compression: "zip", - contentType: "text/csv", - // tslint:disable-next-line - workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68", - contentUrls: [ - "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", - "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", - ], - links: [ - {sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"}, - {sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"}, - {fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"}, - ], - inLanguage: "en", - tags: "weather, uk, 2011, temperature, humidity", - price: 10, -} as MetaDataBase + /** + * Descriptive name of the Asset. + * @type {string} + * @example "UK Weather information 2011" + */ + name: string -const curation: Curation = { - rating: 0.93, - numVotes: 123, - schema: "Binary Votting", -} as Curation + /** + * Type of the Asset. Helps to filter by the type of asset, + * initially ("dataset", "algorithm", "container", "workflow", "other"). + * @type {string} + * @example "dataset" + */ + type: "dataset" | "algorithm" | "container" | "workflow" | "other" -const additionalInformation: AdditionalInformation = { - updateFrecuency: "yearly", - structuredMarkup: [ - { - uri: "http://skos.um.es/unescothes/C01194/jsonld", - mediaType: "application/ld+json", - } as StructuredMarkup, - { - uri: "http://skos.um.es/unescothes/C01194/turtle", - mediaType: "text/turtle", - } as StructuredMarkup, - ], -} as AdditionalInformation + /** + * Details of what the resource is. For a dataset, this attribute + * explains what the data represents and what it can be used for. + * @type {string} + * @example "Weather information of UK including temperature and humidity" + */ + description?: string -export default class MetaData { + /** + * The date on which the asset was created or was added. + * @type {string} + * @example "2012-10-10T17:00:000Z" + */ + dateCreated: string - public additionalInformation: AdditionalInformation - public base: MetaDataBase - public curation: Curation + /** + * Size of the asset (e.g. 18MB). In the absence of a unit (MB, kB etc.), kB will be assumed. + * @type {string} + * @example "3.1gb" + */ + size: string - constructor(metaData?: MetaData) { - this.additionalInformation = (metaData && metaData.additionalInformation) || additionalInformation - this.base = (metaData && metaData.base) || base - this.curation = (metaData && metaData.curation) || curation - } + /** + * Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.). + * @type {string} + * @example "Met Office" + */ + author: string + + /** + * Short name referencing the license of the asset (e.g. Public Domain, CC-0, CC-BY, No License Specified, etc. ). + * If it's not specified, the following value will be added: "No License Specified". + * @type {string} + * @example "CC-BY" + */ + license: string + + /** + * The party holding the legal copyright. Empty by default. + * @type {string} + * @example "Met Office" + */ + copyrightHolder?: string + + /** + * File encoding. + * @type {string} + * @example "UTF-8" + */ + encoding?: string + + /** + * File compression (e.g. no, gzip, bzip2, etc). + * @type {string} + * @example "zip" + */ + compression?: string + + /** + * File format, if applicable. + * @type {string} + * @example "text/csv" + */ + contentType: string + + /** + * Example of the concept of this asset. This example is part + * of the metadata, not an external link. + * @type {string} + * @example "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68" + */ + workExample?: string + + /** + * List of content URLs resolving the Asset files. + * @type {string | string[]} + * @example "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip" + */ + contentUrls: string | string[] + + /** + * Mapping of links for data samples, or links to find out more information. + * Links may be to either a URL or another Asset. We expect marketplaces to + * converge on agreements of typical formats for linked data: The Ocean Protocol + * itself does not mandate any specific formats as these requirements are likely + * to be domain-specific. + * @type {any[]} + * @example + * [ + * { + * anotherSample: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/", + * }, + * { + * fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/", + * }, + * ] + */ + links?: {[name: string]: string}[] + + /** + * The language of the content. Please use one of the language + * codes from the {@link https://tools.ietf.org/html/bcp47 IETF BCP 47 standard}. + * @type {String} + * @example "en" + */ + inLanguage?: string + + /** + * Keywords or tags used to describe this content. Multiple entries in a keyword + * list are typically delimited by commas. Empty by default. + * @type {String} + * @example "weather, uk, 2011, temperature, humidity" + */ + tags?: string + + /** + * Price of the asset. + * @type {String} + * @example 10 + */ + price: number +} + +/** + * Curation attributes of Assets Metadata. + * @see https://github.com/oceanprotocol/OEPs/tree/master/8#curation-attributes + */ +export interface Curation { + /** + * Decimal value between 0 and 1. 0 is the default value. + * @type {number} + * @example 0.93 + */ + rating: number + + /** + * Number of votes. 0 is the default value. + * @type {number} + * @example 123 + */ + numVotes: number + + /** + * Schema applied to calculate the rating. + * @type {number} + * @example "Binary Votting" + */ + schema?: string +} + +/** + * Additional Information of Assets Metadata. + * @see https://github.com/oceanprotocol/OEPs/tree/master/8#additional-information + */ +export interface AdditionalInformation { + /** + * An indication of update latency - i.e. How often are updates expected (seldom, + * annually, quarterly, etc.), or is the resource static that is never expected + * to get updated. + * @type {string} + * @example "yearly" + */ + updateFrecuency: string + + /** + * A link to machine-readable structured markup (such as ttl/json-ld/rdf) + * describing the dataset. + * @type {StructuredMarkup[]} + */ + structuredMarkup: { + uri: string + mediaType: string + }[] + + + /** + * Checksum of attributes to be able to compare if there are changes in + * the asset that you are purchasing. + * @type {string} + */ + checksum: string +} + +export interface MetaData { + additionalInformation: AdditionalInformation + base: MetaDataBase + curation: Curation } diff --git a/src/ddo/MetaDataBase.ts b/src/ddo/MetaDataBase.ts deleted file mode 100644 index a20aad6..0000000 --- a/src/ddo/MetaDataBase.ts +++ /dev/null @@ -1,147 +0,0 @@ -/** - * Base attributes of Assets Metadata. - * @see https://github.com/oceanprotocol/OEPs/tree/master/8#base-attributes - */ -export default class MetaDataBase { - - /** - * Descriptive name of the Asset. - * @type {string} - * @example "UK Weather information 2011" - */ - public name: string = "UK Weather information 2011" - - /** - * Type of the Asset. Helps to filter by the type of asset, - * initially ("dataset", "algorithm", "container", "workflow", "other"). - * @type {string} - * @example "dataset" - */ - public type: "dataset" | "algorithm" | "container" | "workflow" | "other" = "dataset" - - /** - * Details of what the resource is. For a dataset, this attribute - * explains what the data represents and what it can be used for. - * @type {string} - * @example "Weather information of UK including temperature and humidity" - */ - public description?: string = "Weather information of UK including temperature and humidity" - - /** - * The date on which the asset was created or was added. - * @type {string} - * @example "2012-10-10T17:00:000Z" - */ - public dateCreated: string = "2012-10-10T17:00:000Z" - - /** - * Size of the asset (e.g. 18MB). In the absence of a unit (MB, kB etc.), kB will be assumed. - * @type {string} - * @example "3.1gb" - */ - public size: string = "3.1gb" - - /** - * Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.). - * @type {string} - * @example "Met Office" - */ - public author: string = "Met Office" - - /** - * Short name referencing the license of the asset (e.g. Public Domain, CC-0, CC-BY, No License Specified, etc. ). - * If it's not specified, the following value will be added: "No License Specified". - * @type {string} - * @example "CC-BY" - */ - public license: string = "CC-BY" - - /** - * The party holding the legal copyright. Empty by default. - * @type {string} - * @example "Met Office" - */ - public copyrightHolder?: string = "Met Office" - - /** - * File encoding. - * @type {string} - * @example "UTF-8" - */ - public encoding?: string = "UTF-8" - - /** - * File compression (e.g. no, gzip, bzip2, etc). - * @type {string} - * @example "zip" - */ - public compression?: string = "zip" - - /** - * File format, if applicable. - * @type {string} - * @example "text/csv" - */ - public contentType: string = "text/csv" - - /** - * Example of the concept of this asset. This example is part - * of the metadata, not an external link. - * @type {string} - * @example "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68" - */ - public workExample?: string = "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68" - - /** - * List of content URLs resolving the Asset files. - * @type {string | string[]} - * @example "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip" - */ - public contentUrls: string | string[] = [ - "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", - "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", - ] - - /** - * Mapping of links for data samples, or links to find out more information. - * Links may be to either a URL or another Asset. We expect marketplaces to - * converge on agreements of typical formats for linked data: The Ocean Protocol - * itself does not mandate any specific formats as these requirements are likely - * to be domain-specific. - * @type {any[]} - */ - public links?: any[] = [ - { - sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/", - }, - { - sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/", - }, - { - fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/", - }, - ] - - /** - * The language of the content. Please use one of the language - * codes from the {@link https://tools.ietf.org/html/bcp47 IETF BCP 47 standard}. - * @type {String} - * @example "en" - */ - public inLanguage?: string = "en" - - /** - * Keywords or tags used to describe this content. Multiple entries in a keyword - * list are typically delimited by commas. Empty by default. - * @type {String} - * @example "weather, uk, 2011, temperature, humidity" - */ - public tags?: string = "weather, uk, 2011, temperature, humidity" - - /** - * Price of the asset. - * @type {String} - * @example 10 - */ - public price: number = 10 -} diff --git a/src/ddo/Parameter.ts b/src/ddo/Parameter.ts deleted file mode 100644 index d067ed2..0000000 --- a/src/ddo/Parameter.ts +++ /dev/null @@ -1,5 +0,0 @@ -export default class Parameter { - public name: string - public type: string - public value: any -} diff --git a/src/ddo/Proof.ts b/src/ddo/Proof.ts new file mode 100644 index 0000000..c482b70 --- /dev/null +++ b/src/ddo/Proof.ts @@ -0,0 +1,6 @@ +export interface Proof { + type: string + created: string + creator: string + signatureValue: string +} diff --git a/src/ddo/PublicKey.ts b/src/ddo/PublicKey.ts index 81bf2f6..08d111c 100644 --- a/src/ddo/PublicKey.ts +++ b/src/ddo/PublicKey.ts @@ -1,7 +1,28 @@ -export default class PublicKey { - public id: string = "did:op:123456789abcdefghi#keys-1" - public type: string = "Ed25519VerificationKey2018" - public owner: string = "did:op:123456789abcdefghi" - public publicKeyPem?: string = "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n" - public publicKeyBase58?: string = "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV" +/** + * Public key data. + */ +export interface PublicKey { + /** + * ID of the key. + * @type {string} + * @example "did:op:123456789abcdefghi#keys-1" + */ + id: string + + /** + * Type of key. + * @type {string} + */ + type: 'Ed25519VerificationKey2018' | 'RsaVerificationKey2018' | 'EdDsaSAPublicKeySecp256k1' + + /** + * Key owner. + * @type {string} + * @example "did:op:123456789abcdefghi" + */ + owner: string + + publicKeyPem?: string + publicKeyBase58?: string + publicKeyHex?: string } diff --git a/src/ddo/Service.ts b/src/ddo/Service.ts index 4891d39..51da0a0 100644 --- a/src/ddo/Service.ts +++ b/src/ddo/Service.ts @@ -1,15 +1,15 @@ -import Condition from "./Condition" -import Contract from "./Contract" -import MetaData from "./MetaData" +import { Condition } from "./Condition" +import { Contract } from "./Contract" +import { MetaData } from "./MetaData" -export default class Service { - public type: string = "OpenIdConnectVersion1.0Service" - public serviceDefinitionId?: string - public templateId?: string - public serviceEndpoint: string = "https://openid.example.com/" - public purchaseEndpoint?: string - public description?: string = "My public social inbox" - public metadata?: MetaData = {} as MetaData - public serviceAgreementContract?: Contract - public conditions?: Condition[] = [] +export interface Service { + type: string + serviceDefinitionId?: string + templateId?: string + serviceEndpoint: string + purchaseEndpoint?: string + description?: string + metadata?: MetaData + serviceAgreementContract?: Contract + conditions?: Condition[] } diff --git a/src/ddo/StructuredMarkup.ts b/src/ddo/StructuredMarkup.ts deleted file mode 100644 index acf0c16..0000000 --- a/src/ddo/StructuredMarkup.ts +++ /dev/null @@ -1,4 +0,0 @@ -export default class StructuredMarkup { - public uri: string = "http://skos.um.es/unescothes/C01194/jsonld" - public mediaType: string = "application/ld+json" -} diff --git a/src/examples/config/config.json b/src/examples/config/config.json index b837e59..34f5721 100644 --- a/src/examples/config/config.json +++ b/src/examples/config/config.json @@ -1,6 +1,6 @@ { "nodeUri": "http://localhost:8545", - "aquariusUri": "http://aquarius.dev-ocean.com:5000", + "aquariusUri": "https://nginx-aquarius.dev-ocean.com", "brizoUri": "http://localhost:8030", "parityUri": "http://localhost:9545", "secretStoreUri": "http://localhost:12001", diff --git a/src/ocean/OceanAssets.ts b/src/ocean/OceanAssets.ts index 4b38632..9e6318e 100644 --- a/src/ocean/OceanAssets.ts +++ b/src/ocean/OceanAssets.ts @@ -1,15 +1,10 @@ import AquariusProvider from "../aquarius/AquariusProvider" import SearchQuery from "../aquarius/query/SearchQuery" import BrizoProvider from "../brizo/BrizoProvider" -import Authentication from "../ddo/Authentication" -import Condition from "../ddo/Condition" -import Contract from "../ddo/Contract" -import DDO from "../ddo/DDO" -import Event from "../ddo/Event" -import EventHandler from "../ddo/EventHandler" -import MetaData from "../ddo/MetaData" -import PublicKey from "../ddo/PublicKey" -import Service from "../ddo/Service" +import { Condition } from "../ddo/Condition" +import { DDO } from "../ddo/DDO" +import { MetaData } from "../ddo/MetaData" +import { Service } from "../ddo/Service" import ContractEvent from "../keeper/Event" import EventListener from "../keeper/EventListener" import Keeper from "../keeper/Keeper" @@ -88,7 +83,7 @@ export default class OceanAssets { authentication: [{ type: "RsaSignatureAuthentication2018", publicKey: did.getDid() + "#keys-1", - } as Authentication], + }], id: did.getDid(), publicKey: [ { @@ -96,7 +91,7 @@ export default class OceanAssets { type: "Ed25519VerificationKey2018", owner: did.getDid(), publicKeyBase58: await publisher.getPublicKey(), - } as PublicKey, + }, ], service: [ { @@ -118,24 +113,24 @@ export default class OceanAssets { moduleName: "payment", functionName: "lockPayment", version: "0.1", - } as EventHandler, - } as Event, + }, + }, ], - } as Contract, + }, conditions, - } as Service, + }, { type: "Compute", serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(), computeServiceDefintionId, "xxx", "xxx"), serviceDefinitionId: computeServiceDefintionId, - } as Service, + }, { type: "Metadata", serviceEndpoint, serviceDefinitionId: metadataServiceDefinitionId, metadata, - } as Service, + }, ], }) diff --git a/test/aquarius/Aquarius.test.ts b/test/aquarius/Aquarius.test.ts index f3a2868..08e11f9 100644 --- a/test/aquarius/Aquarius.test.ts +++ b/test/aquarius/Aquarius.test.ts @@ -1,7 +1,7 @@ import * as assert from "assert" import Aquarius from "../../src/aquarius/Aquarius" import SearchQuery from "../../src/aquarius/query/SearchQuery" -import DDO from "../../src/ddo/DDO" +import { DDO } from "../../src/ddo/DDO" import DID from "../../src/ocean/DID" import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider" import config from "../config" @@ -10,6 +10,7 @@ import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock" describe("Aquarius", () => { const aquarius: Aquarius = new Aquarius(config) + describe("#queryMetadata()", () => { const query = { @@ -40,6 +41,7 @@ describe("Aquarius", () => { WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()])) const result: DDO[] = await aquarius.queryMetadata(query) + console.log(result) assert(result) assert(result[0].findServiceById) }) diff --git a/test/ddo/DDO.test.ts b/test/ddo/DDO.test.ts index 8d24fd6..c47826f 100644 --- a/test/ddo/DDO.test.ts +++ b/test/ddo/DDO.test.ts @@ -1,13 +1,9 @@ import {assert} from "chai" -import AdditionalInformation from "../../src/ddo/AdditionalInformation" -import Authentication from "../../src/ddo/Authentication" -import Curation from "../../src/ddo/Curation" -import DDO from "../../src/ddo/DDO" -import MetaData from "../../src/ddo/MetaData" -import MetaDataBase from "../../src/ddo/MetaDataBase" -import PublicKey from "../../src/ddo/PublicKey" -import Service from "../../src/ddo/Service" -import StructuredMarkup from "../../src/ddo/StructuredMarkup" +import { Authentication} from "../../src/ddo/Authentication" +import { DDO } from "../../src/ddo/DDO" +import { MetaData, MetaDataBase, Curation, AdditionalInformation } from "../../src/ddo/MetaData" +import { PublicKey } from "../../src/ddo/PublicKey" +import { Service } from "../../src/ddo/Service" import * as jsonDDO from "../testdata/ddo.json" describe("DDO", () => { @@ -26,12 +22,6 @@ describe("DDO", () => { owner: "did:op:123456789abcdefghi", publicKeyBase58: "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV", } as PublicKey, - { - id: "did:op:123456789abcdefghi#keys-3", - type: "RsaPublicKeyExchangeKey2018", - owner: "did:op:123456789abcdefghi", - publicKeyPem: "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n", - } as PublicKey, ], authentication: [ { @@ -137,11 +127,11 @@ describe("DDO", () => { { uri: "http://skos.um.es/unescothes/C01194/jsonld", mediaType: "application/ld+json", - } as StructuredMarkup, + }, { uri: "http://skos.um.es/unescothes/C01194/turtle", mediaType: "text/turtle", - } as StructuredMarkup, + }, ], } as AdditionalInformation, } as MetaData, diff --git a/test/mocks/Aquarius.mock.ts b/test/mocks/Aquarius.mock.ts index 5418c9d..23e9e09 100644 --- a/test/mocks/Aquarius.mock.ts +++ b/test/mocks/Aquarius.mock.ts @@ -1,5 +1,5 @@ import Aquarius from "../../src/aquarius/Aquarius" -import DDO from "../../src/ddo/DDO" +import { DDO } from "../../src/ddo/DDO" import DID from "../../src/ocean/DID" const ddoStore: Map = new Map() diff --git a/test/ocean/Ocean.test.ts b/test/ocean/Ocean.test.ts index 986793c..ed1be31 100644 --- a/test/ocean/Ocean.test.ts +++ b/test/ocean/Ocean.test.ts @@ -3,9 +3,8 @@ import AquariusProvider from "../../src/aquarius/AquariusProvider" import SearchQuery from "../../src/aquarius/query/SearchQuery" import BrizoProvider from "../../src/brizo/BrizoProvider" import ConfigProvider from "../../src/ConfigProvider" -import DDO from "../../src/ddo/DDO" -import MetaData from "../../src/ddo/MetaData" -import Service from "../../src/ddo/Service" +import { DDO } from "../../src/ddo/DDO" +import { Service } from "../../src/ddo/Service" import Account from "../../src/ocean/Account" import Ocean from "../../src/ocean/Ocean" import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement" @@ -17,6 +16,7 @@ import AquariusMock from "../mocks/Aquarius.mock" import BrizoMock from "../mocks/Brizo.mock" import SecretStoreMock from "../mocks/SecretStore.mock" import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock" +import { metadataMock } from "../testdata/MetaData" let ocean: Ocean let accounts: Account[] @@ -24,6 +24,8 @@ let testPublisher: Account describe("Ocean", () => { + const metadata = metadataMock + before(async () => { ConfigProvider.setConfig(config) AquariusProvider.setAquarius(new AquariusMock(config)) @@ -37,7 +39,6 @@ describe("Ocean", () => { }) describe("#getInstance()", () => { - it("should get an instance of cean", async () => { const oceanInstance: Ocean = await Ocean.getInstance(config) @@ -47,7 +48,6 @@ describe("Ocean", () => { }) describe("#getAccounts()", () => { - it("should list accounts", async () => { const accs: Account[] = await ocean.getAccounts() @@ -56,30 +56,22 @@ describe("Ocean", () => { assert(0 === (await accs[5].getBalance()).ocn) assert("string" === typeof accs[0].getId()) }) - }) describe("#resolveDID()", () => { - it("should resolve a did to a ddo", async () => { - - const metaData: MetaData = new MetaData() - const ddo: DDO = await ocean.registerAsset(metaData, testPublisher) + const ddo: DDO = await ocean.registerAsset(metadata, testPublisher) const resolvedDDO: DDO = await ocean.resolveDID(ddo.id) assert(resolvedDDO) assert(resolvedDDO.id === ddo.id) }) - }) describe("#registerAsset()", () => { - it("should register an asset", async () => { - - const metaData: MetaData = new MetaData() - const ddo: DDO = await ocean.registerAsset(metaData, testPublisher) + const ddo: DDO = await ocean.registerAsset(metadata, testPublisher) assert(ddo) assert(ddo.id.startsWith("did:op:")) @@ -87,9 +79,7 @@ describe("Ocean", () => { }) describe("#searchAssets()", () => { - it("should search for assets", async () => { - const query = { offset: 100, page: 0, @@ -106,36 +96,30 @@ describe("Ocean", () => { assert(assets) }) - }) describe("#searchAssetsByText()", () => { - it("should search for assets", async () => { const text = "office" const assets: any[] = await ocean.searchAssetsByText(text) assert(assets) }) - }) describe("#signServiceAgreement()", () => { - it("should sign an service agreement", async () => { - const publisher = accounts[0] const consumer = accounts[1] - const metaData = new MetaData() - const ddo: DDO = await ocean.registerAsset(metaData, publisher) + const ddo: DDO = await ocean.registerAsset(metadata, publisher) const service: Service = ddo.findServiceByType("Access") // @ts-ignore WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) - await consumer.requestTokens(metaData.base.price) + await consumer.requestTokens(metadata.base.price) const signServiceAgreementResult: any = await ocean.signServiceAgreement(ddo.id, service.serviceDefinitionId, consumer) @@ -146,17 +130,14 @@ describe("Ocean", () => { assert(signServiceAgreementResult.serviceAgreementSignature.startsWith("0x")) assert(signServiceAgreementResult.serviceAgreementSignature.length === 132) }) - }) describe("#executeServiceAgreement()", () => { - it("should execute a service agreement", async () => { - const publisher = accounts[0] const consumer = accounts[1] - const ddo: DDO = await ocean.registerAsset(new MetaData(), publisher) + const ddo: DDO = await ocean.registerAsset(metadata, publisher) const service: Service = ddo.findServiceByType("Access") // @ts-ignore @@ -171,6 +152,5 @@ describe("Ocean", () => { assert(serviceAgreement) }) - }) }) diff --git a/test/ocean/ServiceAgreement.test.ts b/test/ocean/ServiceAgreement.test.ts index 5e86148..37d716a 100644 --- a/test/ocean/ServiceAgreement.test.ts +++ b/test/ocean/ServiceAgreement.test.ts @@ -1,9 +1,8 @@ import {assert} from "chai" import ConfigProvider from "../../src/ConfigProvider" -import Condition from "../../src/ddo/Condition" -import DDO from "../../src/ddo/DDO" -import MetaData from "../../src/ddo/MetaData" -import Service from "../../src/ddo/Service" +import { Condition } from "../../src/ddo/Condition" +import { DDO } from "../../src/ddo/DDO" +import { Service } from "../../src/ddo/Service" import Account from "../../src/ocean/Account" import DID from "../../src/ocean/DID" import IdGenerator from "../../src/ocean/IdGenerator" @@ -15,6 +14,8 @@ import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProv import config from "../config" import TestContractHandler from "../keeper/TestContractHandler" import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock" +import { metadataMock } from "../testdata/MetaData" + let ocean: Ocean let accounts: Account[] @@ -28,6 +29,8 @@ const did: DID = DID.generate() describe("ServiceAgreement", () => { + const metadata = metadataMock + before(async () => { ConfigProvider.setConfig(config) await TestContractHandler.prepareContracts() @@ -37,7 +40,6 @@ describe("ServiceAgreement", () => { publisherAccount = accounts[1] consumerAccount = accounts[2] - const metadata = new MetaData() const serviceAgreementTemplate: ServiceAgreementTemplate = new ServiceAgreementTemplate(new Access()) diff --git a/test/ocean/ServiceAgreementTemplate.test.ts b/test/ocean/ServiceAgreementTemplate.test.ts index 8a7cc27..0c30b51 100644 --- a/test/ocean/ServiceAgreementTemplate.test.ts +++ b/test/ocean/ServiceAgreementTemplate.test.ts @@ -1,6 +1,5 @@ import {assert} from "chai" import ConfigProvider from "../../src/ConfigProvider" -import MetaData from "../../src/ddo/MetaData" import Account from "../../src/ocean/Account" import Ocean from "../../src/ocean/Ocean" import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate" @@ -9,12 +8,16 @@ import TemplateBase from "../../src/ocean/ServiceAgreements/Templates/TemplateBa import config from "../config" import TestContractHandler from "../keeper/TestContractHandler" import TestIdGenerator from "../TestIdGenerator" +import { metadataMock } from "../testdata/MetaData" + let ocean: Ocean let accounts: Account[] describe("ServiceAgreementTemplate", () => { + const metadata = metadataMock + before(async () => { ConfigProvider.setConfig(config) await TestContractHandler.prepareContracts() @@ -49,7 +52,7 @@ describe("ServiceAgreementTemplate", () => { new ServiceAgreementTemplate(access) assert(serviceAgreementTemplate) - const conds = await serviceAgreementTemplate.getConditions(new MetaData(), + const conds = await serviceAgreementTemplate.getConditions(metadata, TestIdGenerator.generatePrefixedId()) assert(conds) }) diff --git a/test/testdata/MetaData.ts b/test/testdata/MetaData.ts index 1ea7eb0..610889d 100644 --- a/test/testdata/MetaData.ts +++ b/test/testdata/MetaData.ts @@ -1,34 +1,57 @@ -import MetaDataModel from "../../src/ddo/MetaData" -import MetaDataBase from "../../src/ddo/MetaDataBase" +import { MetaData } from "../../src/ddo/MetaData" -const MetaData = new MetaDataModel({ +export const metadataMock: MetaData = { base: { - name: "Office Humidity", + name: "UK Weather information 2011", type: "dataset", description: "Weather information of UK including temperature and humidity", size: "3.1gb", - dateCreated: "2012-02-01T10:55:11+00:00", + dateCreated: "2012-10-10T17:00:000Z", author: "Met Office", license: "CC-BY", copyrightHolder: "Met Office", encoding: "UTF-8", compression: "zip", contentType: "text/csv", - // tslint:disable-next-line - workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68", + workExample: "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68", contentUrls: [ "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", ], links: [ - {sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/"}, - {sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/"}, - {fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"}, + { + // tslint:disable-next-line + sample1: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-daily/" + }, + { + // tslint:disable-next-line + sample2: "http://data.ceda.ac.uk/badc/ukcp09/data/gridded-land-obs/gridded-land-obs-averages-25km/" + }, + { + fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/", + }, ], inLanguage: "en", tags: "weather, uk, 2011, temperature, humidity", price: 10, - } as MetaDataBase, -} as MetaDataModel) - -export default MetaData + }, + curation: { + rating: 0.93, + numVotes: 123, + schema: "Binary Votting", + }, + additionalInformation: { + updateFrecuency: "yearly", + checksum: "", + structuredMarkup: [ + { + uri: "http://skos.um.es/unescothes/C01194/jsonld", + mediaType: "application/ld+json", + }, + { + uri: "http://skos.um.es/unescothes/C01194/turtle", + mediaType: "text/turtle", + }, + ], + }, +}