From 63e8452d69ed9faac30b7214dee1275a8cd11224 Mon Sep 17 00:00:00 2001 From: Sebastian Gerske Date: Thu, 1 Nov 2018 11:04:59 +0100 Subject: [PATCH] added ddo business objects --- src/ddo/AdditionalInformation.ts | 15 ++ src/ddo/Authentication.ts | 4 + src/ddo/Curation.ts | 5 + src/ddo/DDO.ts | 35 +++++ src/ddo/MetaData.ts | 59 +++++++ src/ddo/MetaDataBase.ts | 31 ++++ src/ddo/PublicKey.ts | 7 + src/ddo/Service.ts | 8 + src/ddo/StructuredMarkup.ts | 4 + test/ddo/DDO.test.ts | 183 ++++++++++++++++++++++ test/ocean/Order.test.ts | 2 +- test/{ocean => testdata}/AccessToken.json | 0 test/testdata/ddo.json | 133 ++++++++++++++++ 13 files changed, 485 insertions(+), 1 deletion(-) create mode 100644 src/ddo/AdditionalInformation.ts create mode 100644 src/ddo/Authentication.ts create mode 100644 src/ddo/Curation.ts create mode 100644 src/ddo/DDO.ts create mode 100644 src/ddo/MetaData.ts create mode 100644 src/ddo/MetaDataBase.ts create mode 100644 src/ddo/PublicKey.ts create mode 100644 src/ddo/Service.ts create mode 100644 src/ddo/StructuredMarkup.ts create mode 100644 test/ddo/DDO.test.ts rename test/{ocean => testdata}/AccessToken.json (100%) create mode 100644 test/testdata/ddo.json diff --git a/src/ddo/AdditionalInformation.ts b/src/ddo/AdditionalInformation.ts new file mode 100644 index 0000000..f1212ce --- /dev/null +++ b/src/ddo/AdditionalInformation.ts @@ -0,0 +1,15 @@ +import StructuredMarkup from "./StructuredMarkup" + +export default class AdditionalInformation { + public updateFrecuency: string = "yearly" + 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, + ] +} diff --git a/src/ddo/Authentication.ts b/src/ddo/Authentication.ts new file mode 100644 index 0000000..bd4689a --- /dev/null +++ b/src/ddo/Authentication.ts @@ -0,0 +1,4 @@ +export default class Authentication { + public type: string = "RsaSignatureAuthentication2018" + public publicKey: string = "did:op:123456789abcdefghi#keys-1" +} diff --git a/src/ddo/Curation.ts b/src/ddo/Curation.ts new file mode 100644 index 0000000..bc40e86 --- /dev/null +++ b/src/ddo/Curation.ts @@ -0,0 +1,5 @@ +export default class Curation { + public rating: number = 0.93 + public numVotes: number = 123 + public schema: string = "Binary Votting" +} diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts new file mode 100644 index 0000000..d0febe6 --- /dev/null +++ b/src/ddo/DDO.ts @@ -0,0 +1,35 @@ +import Authentication from "./Authentication" +import PublicKey from "./PublicKey" +import Service from "./Service" + +export default class DDO { + + public static serialize(ddo: DDO): string { + return JSON.stringify(ddo, null, 2) + } + + public static deserialize(ddoString: string): DDO { + const ddo = JSON.parse(ddoString) + + return ddo as DDO + } + + public "@context": string = "https://w3id.org/future-method/v1" + public id: string + public publicKey: PublicKey[] + public authentication: Authentication[] + public service: Service[] + + // @ts-ignore + private assa: string + + public constructor(ddo: { + publicKey: PublicKey[], + authentication: Authentication[], + service: Service[], + }) { + this.publicKey = ddo.publicKey + this.authentication = ddo.authentication + this.service = ddo.service + } +} diff --git a/src/ddo/MetaData.ts b/src/ddo/MetaData.ts new file mode 100644 index 0000000..e1abd25 --- /dev/null +++ b/src/ddo/MetaData.ts @@ -0,0 +1,59 @@ +import Curation from "./Curation" +import StructuredMarkup from "./StructuredMarkup" +import AdditionalInformation from "./AdditionalInformation" +import MetaDataBase from "./MetaDataBase" + +export default class MetaData { + + public base: MetaDataBase = { + name: "UK Weather information 2011", + type: "dataset", + description: "Weather information of UK including temperature and humidity", + size: "3.1gb", + dateCreated: "2012-10-10T17:00:000Z", + author: "Met Office", + license: "CC-BY", + copyrightHolder: "Met Office", + encoding: "UTF-8", + compression: "zip", + contentType: "text/csv", + 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", + ], + 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 + + public curation: Curation = { + rating: 0.93, + numVotes: 123, + schema: "Binary Votting", + } as Curation + + public 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 +} diff --git a/src/ddo/MetaDataBase.ts b/src/ddo/MetaDataBase.ts new file mode 100644 index 0000000..212c4e8 --- /dev/null +++ b/src/ddo/MetaDataBase.ts @@ -0,0 +1,31 @@ +export default class MetaDataBase { + public name: string = "UK Weather information 2011" + public type: string = "dataset" + public description: string = "Weather information of UK including temperature and humidity" + public size: string = "3.1gb" + public dateCreated: string = "2012-10-10T17:00:000Z" + public author: string = "Met Office" + public license: string = "CC-BY" + public copyrightHolder: string = "Met Office" + public encoding: string = "UTF-8" + public compression: string = "zip" + public contentType: string = "text/csv" + public workExample: string = "423432fsd,51.509865,-0.118092,2011-01-01T10:55:11+00:00,7.2,68" + public contentUrls: string[] = [ + "https://testocnfiles.blob.core.windows.net/testfiles/testzkp.zip", + ] + 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/", + }, + ] + public inLanguage: string = "en" + public tags: string = "weather, uk, 2011, temperature, humidity" + public price: number = 10 +} diff --git a/src/ddo/PublicKey.ts b/src/ddo/PublicKey.ts new file mode 100644 index 0000000..4de771c --- /dev/null +++ b/src/ddo/PublicKey.ts @@ -0,0 +1,7 @@ +export default class PublicKey { + public id: string = "did:op:123456789abcdefghi#keys-1" + public type: string = "RsaVerificationKey2018" + public owner: string = "did:op:123456789abcdefghi" + public publicKeyPem?: string = "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n" + public publicKeyBase58?: string = "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV" +} diff --git a/src/ddo/Service.ts b/src/ddo/Service.ts new file mode 100644 index 0000000..b02192c --- /dev/null +++ b/src/ddo/Service.ts @@ -0,0 +1,8 @@ +import MetaData from "./MetaData" + +export default class Service { + public type: string = "OpenIdConnectVersion1.0Service" + public serviceEndpoint: string = "https://openid.example.com/" + public description?: string = "My public social inbox" + public metadata?: MetaData = {} as MetaData +} diff --git a/src/ddo/StructuredMarkup.ts b/src/ddo/StructuredMarkup.ts new file mode 100644 index 0000000..acf0c16 --- /dev/null +++ b/src/ddo/StructuredMarkup.ts @@ -0,0 +1,4 @@ +export default class StructuredMarkup { + public uri: string = "http://skos.um.es/unescothes/C01194/jsonld" + public mediaType: string = "application/ld+json" +} diff --git a/test/ddo/DDO.test.ts b/test/ddo/DDO.test.ts new file mode 100644 index 0000000..b729182 --- /dev/null +++ b/test/ddo/DDO.test.ts @@ -0,0 +1,183 @@ +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 Logger from "../../src/utils/Logger" +import * as jsonDDO from "../testdata/ddo.json" + +describe("DDO", () => { + + const testDDO: DDO = new DDO({ + publicKey: [ + { + id: "did:op:123456789abcdefghi#keys-1", + type: "RsaVerificationKey2018", + owner: "did:op:123456789abcdefghi", + publicKeyPem: "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n", + } as PublicKey, + { + id: "did:op:123456789abcdefghi#keys-2", + type: "Ed25519VerificationKey2018", + 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: [ + { + type: "RsaSignatureAuthentication2018", + publicKey: "did:op:123456789abcdefghi#keys-1", + } as Authentication, + { + type: "ieee2410Authentication2018", + publicKey: "did:op:123456789abcdefghi#keys-2", + } as Authentication, + ], + service: [ + { + type: "OpenIdConnectVersion1.0Service", + serviceEndpoint: "https://openid.example.com/", + } as Service, + { + type: "CredentialRepositoryService", + serviceEndpoint: "https://repository.example.com/service/8377464", + } as Service, + { + type: "XdiService", + serviceEndpoint: "https://xdi.example.com/8377464", + } as Service, + { + type: "HubService", + serviceEndpoint: "https://hub.example.com/.identity/did:op:0123456789abcdef/", + } as Service, + { + type: "MessagingService", + serviceEndpoint: "https://example.com/messages/8377464", + } as Service, + { + type: "SocialWebInboxService", + serviceEndpoint: "https://social.example.com/83hfh37dj", + description: "My public social inbox", + spamCost: { + amount: "0.50", + currency: "USD", + }, + } as Service, + { + id: "did:op:123456789abcdefghi;bops", + type: "BopsService", + serviceEndpoint: "https://bops.example.com/enterprise/", + } as Service, + { + type: "Consume", + // tslint:disable + serviceEndpoint: "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}", + } as Service, + { + type: "Compute", + serviceEndpoint: "http://mybrizo.org/api/v1/brizo/services/compute?pubKey=${pubKey}&serviceId={serviceId}&algo={algo}&container={container}", + } as Service, + { + type: "Metadata", + serviceEndpoint: "http://myaquarius.org/api/v1/provider/assets/metadata/{did}", + metadata: { + base: { + name: "UK Weather information 2011", + type: "dataset", + description: "Weather information of UK including temperature and humidity", + size: "3.1gb", + dateCreated: "2012-10-10T17:00:000Z", + author: "Met Office", + license: "CC-BY", + copyrightHolder: "Met Office", + encoding: "UTF-8", + compression: "zip", + contentType: "text/csv", + 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" + ], + 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, + curation: { + "rating": 0.93, + "numVotes": 123, + "schema": "Binary Votting" + } as Curation, + 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 + } as MetaData + } + ] + }) + + describe("#serialize()", () => { + + it("should properly serialize", async () => { + + const ddoString = DDO.serialize(testDDO) + Logger.log(ddoString) + assert(ddoString) + assert(ddoString.startsWith("{")) + }) + }) + + describe("#deserialize()", () => { + + it("should properly deserialize from serialized object", async () => { + + const ddoString = DDO.serialize(testDDO) + assert(ddoString) + + const ddo: DDO = DDO.deserialize(ddoString) + assert(ddo) + + assert(ddo.id == testDDO.id) + assert(ddo.publicKey[0].publicKeyPem == testDDO.publicKey[0].publicKeyPem) + }) + + it("should properly deserialize from json file", async () => { + + const ddo: DDO = DDO.deserialize(JSON.stringify(jsonDDO)) + assert(ddo) + + assert(ddo.id == jsonDDO.id) + assert(ddo.publicKey[0].publicKeyPem == jsonDDO.publicKey[0].publicKeyPem) + }) + }) +}) diff --git a/test/ocean/Order.test.ts b/test/ocean/Order.test.ts index a0bd013..75b0136 100644 --- a/test/ocean/Order.test.ts +++ b/test/ocean/Order.test.ts @@ -9,7 +9,7 @@ import Ocean from "../../src/ocean/Ocean" import Order from "../../src/ocean/Order" import config from "../config" import AquariusMock from "../mocks/Aquarius.mock" -import * as AccessToken from "./AccessToken.json" +import * as AccessToken from "../testdata/AccessToken.json" const testName = "Order Test Asset" const testDescription = "This asset is pure owange" diff --git a/test/ocean/AccessToken.json b/test/testdata/AccessToken.json similarity index 100% rename from test/ocean/AccessToken.json rename to test/testdata/AccessToken.json diff --git a/test/testdata/ddo.json b/test/testdata/ddo.json new file mode 100644 index 0000000..a52b407 --- /dev/null +++ b/test/testdata/ddo.json @@ -0,0 +1,133 @@ +{ + "@context": "https://w3id.org/future-method/v1", + "id": "did:op:123456789abcdefghi", + "publicKey": [ + { + "id": "did:op:123456789abcdefghi#keys-1", + "type": "RsaVerificationKey2018", + "owner": "did:op:123456789abcdefghi", + "publicKeyPem": "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n" + }, + { + "id": "did:op:123456789abcdefghi#keys-2", + "type": "Ed25519VerificationKey2018", + "owner": "did:op:123456789abcdefghi", + "publicKeyBase58": "H3C2AVvLMv6gmMNam3uVAjZpfkcJCwDwnZn6z3wXmqPV" + }, + { + "id": "did:op:123456789abcdefghi#keys-3", + "type": "RsaPublicKeyExchangeKey2018", + "owner": "did:op:123456789abcdefghi", + "publicKeyPem": "-----BEGIN PUBLIC KEY...END PUBLIC KEY-----\r\n" + } + ], + "authentication": [ + { + "type": "RsaSignatureAuthentication2018", + "publicKey": "did:op:123456789abcdefghi#keys-1" + }, + { + "type": "ieee2410Authentication2018", + "publicKey": "did:op:123456789abcdefghi#keys-2" + } + ], + "service": [ + { + "type": "OpenIdConnectVersion1.0Service", + "serviceEndpoint": "https://openid.example.com/" + }, + { + "type": "CredentialRepositoryService", + "serviceEndpoint": "https://repository.example.com/service/8377464" + }, + { + "type": "XdiService", + "serviceEndpoint": "https://xdi.example.com/8377464" + }, + { + "type": "HubService", + "serviceEndpoint": "https://hub.example.com/.identity/did:op:0123456789abcdef/" + }, + { + "type": "MessagingService", + "serviceEndpoint": "https://example.com/messages/8377464" + }, + { + "type": "SocialWebInboxService", + "serviceEndpoint": "https://social.example.com/83hfh37dj", + "description": "My public social inbox", + "spamCost": { + "amount": "0.50", + "currency": "USD" + } + }, + { + "id": "did:op:123456789abcdefghi;bops", + "type": "BopsService", + "serviceEndpoint": "https://bops.example.com/enterprise/" + }, + { + "type": "Consume", + "serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/consume?pubKey=${pubKey}&serviceId={serviceId}&url={url}" + }, + { + "type": "Compute", + "serviceEndpoint": "http://mybrizo.org/api/v1/brizo/services/compute?pubKey=${pubKey}&serviceId={serviceId}&algo={algo}&container={container}" + }, + { + "type": "Metadata", + "serviceEndpoint": "http://myaquarius.org/api/v1/provider/assets/metadata/{did}", + "metadata": { + "base": { + "name": "UK Weather information 2011", + "type": "dataset", + "description": "Weather information of UK including temperature and humidity", + "size": "3.1gb", + "dateCreated": "2012-10-10T17:00:000Z", + "author": "Met Office", + "license": "CC-BY", + "copyrightHolder": "Met Office", + "encoding": "UTF-8", + "compression": "zip", + "contentType": "text/csv", + "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" + ], + "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 + }, + "curation": { + "rating": 0.93, + "numVotes": 123, + "schema": "Binary Votting" + }, + "additionalInformation": { + "updateFrecuency": "yearly", + "structuredMarkup": [ + { + "uri": "http://skos.um.es/unescothes/C01194/jsonld", + "mediaType": "application/ld+json" + }, + { + "uri": "http://skos.um.es/unescothes/C01194/turtle", + "mediaType": "text/turtle" + } + ] + } + } + } + ] +}