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

added ddo business objects

This commit is contained in:
Sebastian Gerske 2018-11-01 11:04:59 +01:00
parent b3f3a3547f
commit 63e8452d69
13 changed files with 485 additions and 1 deletions

View File

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

View File

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

5
src/ddo/Curation.ts Normal file
View File

@ -0,0 +1,5 @@
export default class Curation {
public rating: number = 0.93
public numVotes: number = 123
public schema: string = "Binary Votting"
}

35
src/ddo/DDO.ts Normal file
View File

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

59
src/ddo/MetaData.ts Normal file
View File

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

31
src/ddo/MetaDataBase.ts Normal file
View File

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

7
src/ddo/PublicKey.ts Normal file
View File

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

8
src/ddo/Service.ts Normal file
View File

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

View File

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

183
test/ddo/DDO.test.ts Normal file
View File

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

View File

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

133
test/testdata/ddo.json vendored Normal file
View File

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