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

improved exportation of typings related to DDOs

This commit is contained in:
Pedro Gutiérrez 2019-02-04 11:46:24 +01:00 committed by Pedro Gutiérrez
parent 9e51918f29
commit 518a784554
26 changed files with 413 additions and 433 deletions

View File

@ -1,5 +1,5 @@
import { URL } from "whatwg-url" import { URL } from "whatwg-url"
import DDO from "../ddo/DDO" import { DDO } from "../ddo/DDO"
import Config from "../models/Config" import Config from "../models/Config"
import DID from "../ocean/DID" import DID from "../ocean/DID"
import Logger from "../utils/Logger" import Logger from "../utils/Logger"

View File

@ -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
}

View File

@ -1,4 +1,4 @@
export default class Authentication { export interface Authentication {
public type: string = "RsaSignatureAuthentication2018" public type: string
public publicKey: string = "did:op:123456789abcdefghi#keys-1" public publicKey: string
} }

View File

@ -1,15 +1,48 @@
import Dependency from "./Dependency" import { Event } from "./Event"
import Event from "./Event"
import Parameter from "./Parameter"
export default class Condition { export interface Parameter {
public name: string name: string
public contractName: string = "AccessCondition" type: string
public functionName: string = "lockPayment" value: any
public timeout: number = 0 }
public conditionKey: string = "0x12122434"
public parameters: Parameter[] export interface Dependency {
public events: Event[] /**
public dependencies: Dependency[] = [] * @example "lockPayment"
public isTerminalCondition: boolean = false */
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
} }

View File

@ -1,7 +1,7 @@
import Event from "./Event" import Event from "./Event"
export default class Contract { export interface Contract {
public contractName: string contractName: string
public fulfillmentOperator: number fulfillmentOperator: number
public events: Event[] events: Event[]
} }

View File

@ -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"
}

View File

@ -1,12 +1,13 @@
import Authentication from "./Authentication" import { Authentication } from "./Authentication"
import PublicKey from "./PublicKey" import { PublicKey } from "./PublicKey"
import Service from "./Service" import { Service } from "./Service"
import { Proof } from "./Proof"
/** /**
* DID Descriptor Object. * DID Descriptor Object.
* Contains all the data related to an asset. * Contains all the data related to an asset.
*/ */
export default class DDO { export class DDO {
/** /**
* Serializes the DDO object. * Serializes the DDO object.
@ -29,6 +30,7 @@ export default class DDO {
} }
public "@context": string = "https://w3id.org/future-method/v1" public "@context": string = "https://w3id.org/future-method/v1"
/** /**
* DID, descentralized ID. * DID, descentralized ID.
* @type {string} * @type {string}
@ -37,13 +39,9 @@ export default class DDO {
public publicKey: PublicKey[] public publicKey: PublicKey[]
public authentication: Authentication[] public authentication: Authentication[]
public service: Service[] public service: Service[]
public proof: Proof
public constructor(ddo?: { public constructor(ddo?: Partial<DDO>) {
id?: string,
publicKey?: PublicKey[],
authentication?: Authentication[],
service?: Service[],
}) {
this.authentication = (ddo && ddo.authentication) || [] this.authentication = (ddo && ddo.authentication) || []
this.id = (ddo && ddo.id) || null this.id = (ddo && ddo.id) || null
this.publicKey = (ddo && ddo.publicKey) || [] this.publicKey = (ddo && ddo.publicKey) || []

View File

@ -1,4 +0,0 @@
export default class Dependency {
public name: string = "lockPayment"
public timeout: number = 0
}

View File

@ -1,7 +1,20 @@
import EventHandler from "./EventHandler" export interface EventHandler {
/**
export default class Event { * @example "serviceAgreement"
public name: string */
public actorType: string moduleName: string
public handler: EventHandler /**
* @example "fulfillAgreement"
*/
functionName: string
/**
* @example "0.1"
*/
version: string
}
export interface Event {
name: string
actorType: string
handler: EventHandler
} }

View File

@ -1,5 +0,0 @@
export default class EventHandler {
public moduleName: string = "serviceAgreement"
public functionName: string = "fulfillAgreement"
public version: string = "0.1"
}

View File

@ -1,65 +1,209 @@
import AdditionalInformation from "./AdditionalInformation" /**
import Curation from "./Curation" * Base attributes of Assets Metadata.
import MetaDataBase from "./MetaDataBase" * @see https://github.com/oceanprotocol/OEPs/tree/master/8#base-attributes
import StructuredMarkup from "./StructuredMarkup" */
export class MetaDataBase {
const base: MetaDataBase = { /**
name: "UK Weather information 2011", * Descriptive name of the Asset.
type: "dataset", * @type {string}
description: "Weather information of UK including temperature and humidity", * @example "UK Weather information 2011"
size: "3.1gb", */
dateCreated: "2012-02-01T10:55:11+00:00", name: string
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
const curation: Curation = { /**
rating: 0.93, * Type of the Asset. Helps to filter by the type of asset,
numVotes: 123, * initially ("dataset", "algorithm", "container", "workflow", "other").
schema: "Binary Votting", * @type {string}
} as Curation * @example "dataset"
*/
type: "dataset" | "algorithm" | "container" | "workflow" | "other"
const additionalInformation: AdditionalInformation = { /**
updateFrecuency: "yearly", * Details of what the resource is. For a dataset, this attribute
structuredMarkup: [ * explains what the data represents and what it can be used for.
{ * @type {string}
uri: "http://skos.um.es/unescothes/C01194/jsonld", * @example "Weather information of UK including temperature and humidity"
mediaType: "application/ld+json", */
} as StructuredMarkup, description?: string
{
uri: "http://skos.um.es/unescothes/C01194/turtle",
mediaType: "text/turtle",
} as StructuredMarkup,
],
} as AdditionalInformation
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 * Size of the asset (e.g. 18MB). In the absence of a unit (MB, kB etc.), kB will be assumed.
public curation: Curation * @type {string}
* @example "3.1gb"
*/
size: string
constructor(metaData?: MetaData) { /**
this.additionalInformation = (metaData && metaData.additionalInformation) || additionalInformation * Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.).
this.base = (metaData && metaData.base) || base * @type {string}
this.curation = (metaData && metaData.curation) || curation * @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
} }

View File

@ -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
}

View File

@ -1,5 +0,0 @@
export default class Parameter {
public name: string
public type: string
public value: any
}

6
src/ddo/Proof.ts Normal file
View File

@ -0,0 +1,6 @@
export interface Proof {
type: string
created: string
creator: string
signatureValue: string
}

View File

@ -1,7 +1,28 @@
export default class PublicKey { /**
public id: string = "did:op:123456789abcdefghi#keys-1" * Public key data.
public type: string = "Ed25519VerificationKey2018" */
public owner: string = "did:op:123456789abcdefghi" export interface PublicKey {
public publicKeyPem?: string = "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n" /**
public publicKeyBase58?: string = "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV" * 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
} }

View File

@ -1,15 +1,15 @@
import Condition from "./Condition" import { Condition } from "./Condition"
import Contract from "./Contract" import { Contract } from "./Contract"
import MetaData from "./MetaData" import { MetaData } from "./MetaData"
export default class Service { export interface Service {
public type: string = "OpenIdConnectVersion1.0Service" type: string
public serviceDefinitionId?: string serviceDefinitionId?: string
public templateId?: string templateId?: string
public serviceEndpoint: string = "https://openid.example.com/" serviceEndpoint: string
public purchaseEndpoint?: string purchaseEndpoint?: string
public description?: string = "My public social inbox" description?: string
public metadata?: MetaData = {} as MetaData metadata?: MetaData
public serviceAgreementContract?: Contract serviceAgreementContract?: Contract
public conditions?: Condition[] = [] conditions?: Condition[]
} }

View File

@ -1,4 +0,0 @@
export default class StructuredMarkup {
public uri: string = "http://skos.um.es/unescothes/C01194/jsonld"
public mediaType: string = "application/ld+json"
}

View File

@ -1,6 +1,6 @@
{ {
"nodeUri": "http://localhost:8545", "nodeUri": "http://localhost:8545",
"aquariusUri": "http://aquarius.dev-ocean.com:5000", "aquariusUri": "https://nginx-aquarius.dev-ocean.com",
"brizoUri": "http://localhost:8030", "brizoUri": "http://localhost:8030",
"parityUri": "http://localhost:9545", "parityUri": "http://localhost:9545",
"secretStoreUri": "http://localhost:12001", "secretStoreUri": "http://localhost:12001",

View File

@ -1,15 +1,10 @@
import AquariusProvider from "../aquarius/AquariusProvider" import AquariusProvider from "../aquarius/AquariusProvider"
import SearchQuery from "../aquarius/query/SearchQuery" import SearchQuery from "../aquarius/query/SearchQuery"
import BrizoProvider from "../brizo/BrizoProvider" import BrizoProvider from "../brizo/BrizoProvider"
import Authentication from "../ddo/Authentication" import { Condition } from "../ddo/Condition"
import Condition from "../ddo/Condition" import { DDO } from "../ddo/DDO"
import Contract from "../ddo/Contract" import { MetaData } from "../ddo/MetaData"
import DDO from "../ddo/DDO" import { Service } from "../ddo/Service"
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 ContractEvent from "../keeper/Event" import ContractEvent from "../keeper/Event"
import EventListener from "../keeper/EventListener" import EventListener from "../keeper/EventListener"
import Keeper from "../keeper/Keeper" import Keeper from "../keeper/Keeper"
@ -88,7 +83,7 @@ export default class OceanAssets {
authentication: [{ authentication: [{
type: "RsaSignatureAuthentication2018", type: "RsaSignatureAuthentication2018",
publicKey: did.getDid() + "#keys-1", publicKey: did.getDid() + "#keys-1",
} as Authentication], }],
id: did.getDid(), id: did.getDid(),
publicKey: [ publicKey: [
{ {
@ -96,7 +91,7 @@ export default class OceanAssets {
type: "Ed25519VerificationKey2018", type: "Ed25519VerificationKey2018",
owner: did.getDid(), owner: did.getDid(),
publicKeyBase58: await publisher.getPublicKey(), publicKeyBase58: await publisher.getPublicKey(),
} as PublicKey, },
], ],
service: [ service: [
{ {
@ -118,24 +113,24 @@ export default class OceanAssets {
moduleName: "payment", moduleName: "payment",
functionName: "lockPayment", functionName: "lockPayment",
version: "0.1", version: "0.1",
} as EventHandler, },
} as Event, },
], ],
} as Contract, },
conditions, conditions,
} as Service, },
{ {
type: "Compute", type: "Compute",
serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(), serviceEndpoint: brizo.getComputeEndpoint(publisher.getId(),
computeServiceDefintionId, "xxx", "xxx"), computeServiceDefintionId, "xxx", "xxx"),
serviceDefinitionId: computeServiceDefintionId, serviceDefinitionId: computeServiceDefintionId,
} as Service, },
{ {
type: "Metadata", type: "Metadata",
serviceEndpoint, serviceEndpoint,
serviceDefinitionId: metadataServiceDefinitionId, serviceDefinitionId: metadataServiceDefinitionId,
metadata, metadata,
} as Service, },
], ],
}) })

View File

@ -1,7 +1,7 @@
import * as assert from "assert" import * as assert from "assert"
import Aquarius from "../../src/aquarius/Aquarius" import Aquarius from "../../src/aquarius/Aquarius"
import SearchQuery from "../../src/aquarius/query/SearchQuery" 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 DID from "../../src/ocean/DID"
import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider" import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProvider"
import config from "../config" import config from "../config"
@ -10,6 +10,7 @@ import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
describe("Aquarius", () => { describe("Aquarius", () => {
const aquarius: Aquarius = new Aquarius(config) const aquarius: Aquarius = new Aquarius(config)
describe("#queryMetadata()", () => { describe("#queryMetadata()", () => {
const query = { const query = {
@ -40,6 +41,7 @@ describe("Aquarius", () => {
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()])) WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock([new DDO()]))
const result: DDO[] = await aquarius.queryMetadata(query) const result: DDO[] = await aquarius.queryMetadata(query)
console.log(result)
assert(result) assert(result)
assert(result[0].findServiceById) assert(result[0].findServiceById)
}) })

View File

@ -1,13 +1,9 @@
import {assert} from "chai" import {assert} from "chai"
import AdditionalInformation from "../../src/ddo/AdditionalInformation" import { Authentication} from "../../src/ddo/Authentication"
import Authentication from "../../src/ddo/Authentication" import { DDO } from "../../src/ddo/DDO"
import Curation from "../../src/ddo/Curation" import { MetaData, MetaDataBase, Curation, AdditionalInformation } from "../../src/ddo/MetaData"
import DDO from "../../src/ddo/DDO" import { PublicKey } from "../../src/ddo/PublicKey"
import MetaData from "../../src/ddo/MetaData" import { Service } from "../../src/ddo/Service"
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 * as jsonDDO from "../testdata/ddo.json" import * as jsonDDO from "../testdata/ddo.json"
describe("DDO", () => { describe("DDO", () => {
@ -26,12 +22,6 @@ describe("DDO", () => {
owner: "did:op:123456789abcdefghi", owner: "did:op:123456789abcdefghi",
publicKeyBase58: "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV", publicKeyBase58: "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV",
} as PublicKey, } 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: [ authentication: [
{ {
@ -137,11 +127,11 @@ describe("DDO", () => {
{ {
uri: "http://skos.um.es/unescothes/C01194/jsonld", uri: "http://skos.um.es/unescothes/C01194/jsonld",
mediaType: "application/ld+json", mediaType: "application/ld+json",
} as StructuredMarkup, },
{ {
uri: "http://skos.um.es/unescothes/C01194/turtle", uri: "http://skos.um.es/unescothes/C01194/turtle",
mediaType: "text/turtle", mediaType: "text/turtle",
} as StructuredMarkup, },
], ],
} as AdditionalInformation, } as AdditionalInformation,
} as MetaData, } as MetaData,

View File

@ -1,5 +1,5 @@
import Aquarius from "../../src/aquarius/Aquarius" import Aquarius from "../../src/aquarius/Aquarius"
import DDO from "../../src/ddo/DDO" import { DDO } from "../../src/ddo/DDO"
import DID from "../../src/ocean/DID" import DID from "../../src/ocean/DID"
const ddoStore: Map<string, any> = new Map<string, any>() const ddoStore: Map<string, any> = new Map<string, any>()

View File

@ -3,9 +3,8 @@ import AquariusProvider from "../../src/aquarius/AquariusProvider"
import SearchQuery from "../../src/aquarius/query/SearchQuery" import SearchQuery from "../../src/aquarius/query/SearchQuery"
import BrizoProvider from "../../src/brizo/BrizoProvider" import BrizoProvider from "../../src/brizo/BrizoProvider"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import DDO from "../../src/ddo/DDO" import { DDO } from "../../src/ddo/DDO"
import MetaData from "../../src/ddo/MetaData" import { Service } from "../../src/ddo/Service"
import Service from "../../src/ddo/Service"
import Account from "../../src/ocean/Account" import Account from "../../src/ocean/Account"
import Ocean from "../../src/ocean/Ocean" import Ocean from "../../src/ocean/Ocean"
import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement" import ServiceAgreement from "../../src/ocean/ServiceAgreements/ServiceAgreement"
@ -17,6 +16,7 @@ import AquariusMock from "../mocks/Aquarius.mock"
import BrizoMock from "../mocks/Brizo.mock" import BrizoMock from "../mocks/Brizo.mock"
import SecretStoreMock from "../mocks/SecretStore.mock" import SecretStoreMock from "../mocks/SecretStore.mock"
import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock" import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
import { metadataMock } from "../testdata/MetaData"
let ocean: Ocean let ocean: Ocean
let accounts: Account[] let accounts: Account[]
@ -24,6 +24,8 @@ let testPublisher: Account
describe("Ocean", () => { describe("Ocean", () => {
const metadata = metadataMock
before(async () => { before(async () => {
ConfigProvider.setConfig(config) ConfigProvider.setConfig(config)
AquariusProvider.setAquarius(new AquariusMock(config)) AquariusProvider.setAquarius(new AquariusMock(config))
@ -37,7 +39,6 @@ describe("Ocean", () => {
}) })
describe("#getInstance()", () => { describe("#getInstance()", () => {
it("should get an instance of cean", async () => { it("should get an instance of cean", async () => {
const oceanInstance: Ocean = await Ocean.getInstance(config) const oceanInstance: Ocean = await Ocean.getInstance(config)
@ -47,7 +48,6 @@ describe("Ocean", () => {
}) })
describe("#getAccounts()", () => { describe("#getAccounts()", () => {
it("should list accounts", async () => { it("should list accounts", async () => {
const accs: Account[] = await ocean.getAccounts() const accs: Account[] = await ocean.getAccounts()
@ -56,30 +56,22 @@ describe("Ocean", () => {
assert(0 === (await accs[5].getBalance()).ocn) assert(0 === (await accs[5].getBalance()).ocn)
assert("string" === typeof accs[0].getId()) assert("string" === typeof accs[0].getId())
}) })
}) })
describe("#resolveDID()", () => { describe("#resolveDID()", () => {
it("should resolve a did to a ddo", async () => { it("should resolve a did to a ddo", async () => {
const ddo: DDO = await ocean.registerAsset(metadata, testPublisher)
const metaData: MetaData = new MetaData()
const ddo: DDO = await ocean.registerAsset(metaData, testPublisher)
const resolvedDDO: DDO = await ocean.resolveDID(ddo.id) const resolvedDDO: DDO = await ocean.resolveDID(ddo.id)
assert(resolvedDDO) assert(resolvedDDO)
assert(resolvedDDO.id === ddo.id) assert(resolvedDDO.id === ddo.id)
}) })
}) })
describe("#registerAsset()", () => { describe("#registerAsset()", () => {
it("should register an asset", async () => { it("should register an asset", async () => {
const ddo: DDO = await ocean.registerAsset(metadata, testPublisher)
const metaData: MetaData = new MetaData()
const ddo: DDO = await ocean.registerAsset(metaData, testPublisher)
assert(ddo) assert(ddo)
assert(ddo.id.startsWith("did:op:")) assert(ddo.id.startsWith("did:op:"))
@ -87,9 +79,7 @@ describe("Ocean", () => {
}) })
describe("#searchAssets()", () => { describe("#searchAssets()", () => {
it("should search for assets", async () => { it("should search for assets", async () => {
const query = { const query = {
offset: 100, offset: 100,
page: 0, page: 0,
@ -106,36 +96,30 @@ describe("Ocean", () => {
assert(assets) assert(assets)
}) })
}) })
describe("#searchAssetsByText()", () => { describe("#searchAssetsByText()", () => {
it("should search for assets", async () => { it("should search for assets", async () => {
const text = "office" const text = "office"
const assets: any[] = await ocean.searchAssetsByText(text) const assets: any[] = await ocean.searchAssetsByText(text)
assert(assets) assert(assets)
}) })
}) })
describe("#signServiceAgreement()", () => { describe("#signServiceAgreement()", () => {
it("should sign an service agreement", async () => { it("should sign an service agreement", async () => {
const publisher = accounts[0] const publisher = accounts[0]
const consumer = accounts[1] 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") const service: Service = ddo.findServiceByType("Access")
// @ts-ignore // @ts-ignore
WebServiceConnectorProvider.setConnector(new WebServiceConnectorMock(ddo)) 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, const signServiceAgreementResult: any = await ocean.signServiceAgreement(ddo.id,
service.serviceDefinitionId, consumer) service.serviceDefinitionId, consumer)
@ -146,17 +130,14 @@ describe("Ocean", () => {
assert(signServiceAgreementResult.serviceAgreementSignature.startsWith("0x")) assert(signServiceAgreementResult.serviceAgreementSignature.startsWith("0x"))
assert(signServiceAgreementResult.serviceAgreementSignature.length === 132) assert(signServiceAgreementResult.serviceAgreementSignature.length === 132)
}) })
}) })
describe("#executeServiceAgreement()", () => { describe("#executeServiceAgreement()", () => {
it("should execute a service agreement", async () => { it("should execute a service agreement", async () => {
const publisher = accounts[0] const publisher = accounts[0]
const consumer = accounts[1] 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") const service: Service = ddo.findServiceByType("Access")
// @ts-ignore // @ts-ignore
@ -171,6 +152,5 @@ describe("Ocean", () => {
assert(serviceAgreement) assert(serviceAgreement)
}) })
}) })
}) })

View File

@ -1,9 +1,8 @@
import {assert} from "chai" import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import Condition from "../../src/ddo/Condition" import { Condition } from "../../src/ddo/Condition"
import DDO from "../../src/ddo/DDO" import { DDO } from "../../src/ddo/DDO"
import MetaData from "../../src/ddo/MetaData" import { Service } from "../../src/ddo/Service"
import Service from "../../src/ddo/Service"
import Account from "../../src/ocean/Account" import Account from "../../src/ocean/Account"
import DID from "../../src/ocean/DID" import DID from "../../src/ocean/DID"
import IdGenerator from "../../src/ocean/IdGenerator" import IdGenerator from "../../src/ocean/IdGenerator"
@ -15,6 +14,8 @@ import WebServiceConnectorProvider from "../../src/utils/WebServiceConnectorProv
import config from "../config" import config from "../config"
import TestContractHandler from "../keeper/TestContractHandler" import TestContractHandler from "../keeper/TestContractHandler"
import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock" import WebServiceConnectorMock from "../mocks/WebServiceConnector.mock"
import { metadataMock } from "../testdata/MetaData"
let ocean: Ocean let ocean: Ocean
let accounts: Account[] let accounts: Account[]
@ -28,6 +29,8 @@ const did: DID = DID.generate()
describe("ServiceAgreement", () => { describe("ServiceAgreement", () => {
const metadata = metadataMock
before(async () => { before(async () => {
ConfigProvider.setConfig(config) ConfigProvider.setConfig(config)
await TestContractHandler.prepareContracts() await TestContractHandler.prepareContracts()
@ -37,7 +40,6 @@ describe("ServiceAgreement", () => {
publisherAccount = accounts[1] publisherAccount = accounts[1]
consumerAccount = accounts[2] consumerAccount = accounts[2]
const metadata = new MetaData()
const serviceAgreementTemplate: ServiceAgreementTemplate = const serviceAgreementTemplate: ServiceAgreementTemplate =
new ServiceAgreementTemplate(new Access()) new ServiceAgreementTemplate(new Access())

View File

@ -1,6 +1,5 @@
import {assert} from "chai" import {assert} from "chai"
import ConfigProvider from "../../src/ConfigProvider" import ConfigProvider from "../../src/ConfigProvider"
import MetaData from "../../src/ddo/MetaData"
import Account from "../../src/ocean/Account" import Account from "../../src/ocean/Account"
import Ocean from "../../src/ocean/Ocean" import Ocean from "../../src/ocean/Ocean"
import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate" import ServiceAgreementTemplate from "../../src/ocean/ServiceAgreements/ServiceAgreementTemplate"
@ -9,12 +8,16 @@ import TemplateBase from "../../src/ocean/ServiceAgreements/Templates/TemplateBa
import config from "../config" import config from "../config"
import TestContractHandler from "../keeper/TestContractHandler" import TestContractHandler from "../keeper/TestContractHandler"
import TestIdGenerator from "../TestIdGenerator" import TestIdGenerator from "../TestIdGenerator"
import { metadataMock } from "../testdata/MetaData"
let ocean: Ocean let ocean: Ocean
let accounts: Account[] let accounts: Account[]
describe("ServiceAgreementTemplate", () => { describe("ServiceAgreementTemplate", () => {
const metadata = metadataMock
before(async () => { before(async () => {
ConfigProvider.setConfig(config) ConfigProvider.setConfig(config)
await TestContractHandler.prepareContracts() await TestContractHandler.prepareContracts()
@ -49,7 +52,7 @@ describe("ServiceAgreementTemplate", () => {
new ServiceAgreementTemplate(access) new ServiceAgreementTemplate(access)
assert(serviceAgreementTemplate) assert(serviceAgreementTemplate)
const conds = await serviceAgreementTemplate.getConditions(new MetaData(), const conds = await serviceAgreementTemplate.getConditions(metadata,
TestIdGenerator.generatePrefixedId()) TestIdGenerator.generatePrefixedId())
assert(conds) assert(conds)
}) })

View File

@ -1,34 +1,57 @@
import MetaDataModel from "../../src/ddo/MetaData" import { MetaData } from "../../src/ddo/MetaData"
import MetaDataBase from "../../src/ddo/MetaDataBase"
const MetaData = new MetaDataModel({ export const metadataMock: MetaData = {
base: { base: {
name: "Office Humidity", name: "UK Weather information 2011",
type: "dataset", type: "dataset",
description: "Weather information of UK including temperature and humidity", description: "Weather information of UK including temperature and humidity",
size: "3.1gb", size: "3.1gb",
dateCreated: "2012-02-01T10:55:11+00:00", dateCreated: "2012-10-10T17:00:000Z",
author: "Met Office", author: "Met Office",
license: "CC-BY", license: "CC-BY",
copyrightHolder: "Met Office", copyrightHolder: "Met Office",
encoding: "UTF-8", encoding: "UTF-8",
compression: "zip", compression: "zip",
contentType: "text/csv", contentType: "text/csv",
// tslint:disable-next-line workExample: "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
workExample: "stationId,latitude,longitude,datetime,temperature,humidity423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68",
contentUrls: [ contentUrls: [
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
"https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip",
], ],
links: [ 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/"}, // tslint:disable-next-line
{fieldsDescription: "http://data.ceda.ac.uk/badc/ukcp09/"}, 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", inLanguage: "en",
tags: "weather, uk, 2011, temperature, humidity", tags: "weather, uk, 2011, temperature, humidity",
price: 10, price: 10,
} as MetaDataBase, },
} as MetaDataModel) curation: {
rating: 0.93,
export default MetaData 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",
},
],
},
}