From f1962f710371679ca1fe9c65e5ddd1d4a80a348b Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Thu, 11 Nov 2021 17:12:24 +0200 Subject: [PATCH 1/3] initial commit for the DDO typings --- src/ddo/Credentials.ts | 9 +++++++ src/ddo/DDO.ts | 54 ++++++++++++++++++++++++++++++++++++++++++ src/ddo/Metadata.ts | 26 ++++++++++++++++++++ src/ddo/Service.ts | 29 +++++++++++++++++++++++ src/ddo/index.ts | 1 + 5 files changed, 119 insertions(+) create mode 100644 src/ddo/Credentials.ts create mode 100644 src/ddo/DDO.ts create mode 100644 src/ddo/Metadata.ts create mode 100644 src/ddo/Service.ts create mode 100644 src/ddo/index.ts diff --git a/src/ddo/Credentials.ts b/src/ddo/Credentials.ts new file mode 100644 index 00000000..9133f74e --- /dev/null +++ b/src/ddo/Credentials.ts @@ -0,0 +1,9 @@ +export interface Credential { + type: string + values: string[] +} + +export interface Credentials { + allow: Credential[] + deny: Credential[] +} diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts new file mode 100644 index 00000000..465e4aab --- /dev/null +++ b/src/ddo/DDO.ts @@ -0,0 +1,54 @@ +import { Service } from './Service' +import { Metadata } from './Metadata' +import { Credentials } from './Credentials' + +/** + * DID Descriptor Object. + * Contains metadata about the asset, and define access in at least one service. + */ +export class DDO { + /** + * Contexts used for validation.. + * @type {string[]} + */ + public '@context': string[] + + /** + * DID, descentralized ID. + * Computed as sha256(address of ERC721 contract + chainId) + * @type {string} + */ + public id: string + + /** + * Version information in SemVer notation + * referring to the DDO spec version + * @type {string} + */ + public version: string + + /** + * ChainId of the network the DDO was published to. + * @type {number} + */ + public chainId: number + + /** + * Stores an object describing the asset. + * @type {Metadata} + */ + public metadata: Metadata + + /** + * Stores an array of services defining access to the asset. + * @type {Service[]} + */ + public services: Service[] + + /** + * Describes the credentials needed to access a dataset + * in addition to the services definition. + * @type {Credentials} + */ + public credentials?: Credentials +} diff --git a/src/ddo/Metadata.ts b/src/ddo/Metadata.ts new file mode 100644 index 00000000..90b48326 --- /dev/null +++ b/src/ddo/Metadata.ts @@ -0,0 +1,26 @@ +export interface MetadataAlgorithm { + language?: string + version?: string + container: { + entrypoint: string + image: string + tag: string + checksum: string + } +} + +export interface Metadata { + created: string + updated: string + name: string + description: string + type: 'dataset' | 'algorithm' + author: string + license: string + links?: string[] + tags?: string[] + copyrightHolder?: string + contentLanguage?: string + algorithm?: MetadataAlgorithm + additionalInformation?: any +} diff --git a/src/ddo/Service.ts b/src/ddo/Service.ts new file mode 100644 index 00000000..0ba45317 --- /dev/null +++ b/src/ddo/Service.ts @@ -0,0 +1,29 @@ +export interface PublisherTrustedAlgorithm { + did: string + filesChecksum: string + containerSectionChecksum: string +} + +export interface ServiceComputeOptions { + namespace: string + cpu?: number + gpu?: number + gpuType?: string + memory?: string + volumeSize?: string + allowRawAlgorithm: boolean + allowNetworkAccess: boolean + publisherTrustedAlgorithmPublishers: string[] + publisherTrustedAlgorithms: PublisherTrustedAlgorithm[] +} + +export interface Service { + type: 'access' | 'compute' | string + files: string + datatokenAddress: string + serviceEndpoint: string + timeout: string + name?: string + description?: string + compute?: ServiceComputeOptions +} diff --git a/src/ddo/index.ts b/src/ddo/index.ts new file mode 100644 index 00000000..4bd3a54b --- /dev/null +++ b/src/ddo/index.ts @@ -0,0 +1 @@ +export * from './DDO' From cd942b7f100d9c2bb8ee18d36ed3157e02b9afe8 Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Sun, 14 Nov 2021 23:03:43 +0200 Subject: [PATCH 2/3] added asset class and docs --- src/ddo/Asset.ts | 109 +++++++++++++++++++++++++++++++++++++++++++ src/ddo/Metadata.ts | 101 ++++++++++++++++++++++++++++++++++++++++ src/ddo/Service.ts | 110 ++++++++++++++++++++++++++++++++++++++++++++ src/ddo/index.ts | 4 ++ 4 files changed, 324 insertions(+) create mode 100644 src/ddo/Asset.ts diff --git a/src/ddo/Asset.ts b/src/ddo/Asset.ts new file mode 100644 index 00000000..fa4deb23 --- /dev/null +++ b/src/ddo/Asset.ts @@ -0,0 +1,109 @@ +import { DDO } from './DDO' + +export interface AssetNft { + /** + * Contract address of the deployed ERC721 NFT contract. + * @type {string} + */ + address: string + + /** + * Name of NFT set in contract. + * @type {string} + */ + name: string + + /** + * Symbol of NFT set in contract. + * @type {string} + */ + symbol: string + + /** + * ETH account address of the NFT owner. + * @type {string} + */ + owner: string + + /** + * State of the asset reflecting the NFT contract value. + * 0 Active. + * 1 End-of-life. + * 2 Deprecated (by another asset). + * 3 Revoked by publisher. + * 4 Ordering is temporary disabled. + * @type {number} + */ + state: 0 | 1 | 2 | 3 | 4 +} + +export interface AssetDatatoken { + /** + * Name of NFT set in contract. + * @type {string} + */ + name: string + + /** + * Symbol of NFT set in contract. + * @type {string} + */ + symbol: string + + /** + * Contract address of the deployed ERC20 contract. + * @type {string} + */ + address: string + + /** + * ID of the service the datatoken is attached to. + * @type {string} + */ + serviceId: string +} + +export interface AssetLastEvent { + tx: string + block: number + from: string + contract: string +} + +export class Asset extends DDO { + /** + * Contains information about the ERC721 NFT contract which represents the intellectual property of the publisher. + * @type {string} + */ + nft: AssetNft + + /** + * Contains information about the ERC20 datatokens attached to asset services. + * @type {string} + */ + datatokens: AssetDatatoken[] + + /** + * Contains information about the last transaction that created or updated the DDO. + * @type {string} + */ + event: AssetLastEvent + + /** + * The stats section contains different statistics fields. + * @type {string} + */ + stats: { consume: number } + + /** + * If asset is listed in purgatory and reason. + * @type {string} + */ + isInPurgatory: string + + /** + * Name of NFT set in contract. + * @type {AssetDatatoken} + */ + dataTokenInfo: AssetDatatoken // To be removed +} diff --git a/src/ddo/Metadata.ts b/src/ddo/Metadata.ts index 90b48326..425592b8 100644 --- a/src/ddo/Metadata.ts +++ b/src/ddo/Metadata.ts @@ -1,26 +1,127 @@ export interface MetadataAlgorithm { + /** + * Language used to implement the software. + * @type {string} + */ language?: string + + /** + * Version of the software preferably in SemVer notation. + * @type {string} + */ version?: string + + /** + * Object describing the Docker container image. + * @type {Object} + */ container: { + /** + * The command to execute, or script to run inside the Docker image. + * @type {string} + */ entrypoint: string + + /** + * Name of the Docker image. + * @type {string} + */ image: string + + /** + * Tag of the Docker image. + * @type {string} + */ tag: string + + /** + * Checksum of the Docker image. + * @type {string} + */ checksum: string } } export interface Metadata { + /** + * Contains the date of publishing in ISO Date Time + * @type {string} + */ created: string + + /** + * Contains the the date of last update in ISO Date Time + * @type {string} + */ updated: string + + /** + * Descriptive name or title of the asset. + * @type {string} + */ name: string + + /** + * Details of what the resource is. + * @type {string} + */ description: string + + /** + * Asset type. Includes "dataset" (e.g. csv file), "algorithm" (e.g. Python script). + * Each type needs a different subset of metadata attributes. + * @type {'dataset' | 'algorithm'} + */ type: 'dataset' | 'algorithm' + + /** + * Name of the entity generating this data (e.g. Tfl, Disney Corp, etc.). + * @type {string} + */ author: string + + /** + * Short name referencing the license of the asset. + * If it’s not specified, the following value will be added: “No License Specified”. + * @type {string} + */ license: string + + /** + * Mapping of URL strings for data samples, or links to find out more information. + * Links may be to either a URL or another asset. + * @type {string[]} + */ links?: string[] + + /** + * Mapping of URL strings for data samples, or links to find out more information. + * Links may be to either a URL or another asset. + * @type {string[]} + */ tags?: string[] + + /** + * The party holding the legal copyright. Empty by default. + * @type {string} + */ copyrightHolder?: string + + /** + *The language of the content. Use one of the language codes from the IETF BCP 47 standard + * @type {string} + */ contentLanguage?: string + + /** + * Information about asset of typealgorithm + * @type {MetadataAlgorithm} + */ algorithm?: MetadataAlgorithm + + /** + * Stores additional information, this is customizable by publisher + * @type {any} + */ additionalInformation?: any } diff --git a/src/ddo/Service.ts b/src/ddo/Service.ts index 0ba45317..12922209 100644 --- a/src/ddo/Service.ts +++ b/src/ddo/Service.ts @@ -1,29 +1,139 @@ export interface PublisherTrustedAlgorithm { + /** + * The DID of the algorithm which is trusted by the publisher. + * @type {string} + */ did: string + + /** + * Hash of algorithm’s files section. + * @type {string} + */ filesChecksum: string + + /** + * Hash of algorithm’s metadata.algorithm.container section. + * @type {string} + */ containerSectionChecksum: string } export interface ServiceComputeOptions { + /** + * Namespaced used for the compute job. + * @type {string} + */ namespace: string + + /** + * Maximum number of CPUs allocated for a job + * @type {number} + */ cpu?: number + + /** + * Maximum number of GPUs allocated for a job + * @type {number} + */ gpu?: number + + /** + * Type of GPU (if any) + * @type {string} + */ gpuType?: string + + /** + * Maximum amount of memory allocated for a job. + * You can express memory as a plain integer or as a fixed-point number using one of these suffixes: E, P, T, G, M, k. + * You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki. + * For example, the following represent roughly the same value: 128974848, 129e6, 129M, 123Mi + * @type {string} + */ memory?: string + + /** + * Amount of disk space allocated. + * You can express it as a plain integer or as a fixed-point number using one of these suffixes: E, P, T, G, M, k. + * You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki. + * @type {string} + */ volumeSize?: string + + /** + * If true, any passed raw text will be allowed to run. + * Useful for an algorithm drag & drop use case, but increases risk of data escape through malicious user input. + * Should be false by default in all implementations. + * @type {boolean} + */ allowRawAlgorithm: boolean + + /** + * If true, the algorithm job will have network access. + * @type {boolean} + */ allowNetworkAccess: boolean + + /** + * If empty, then any published algorithm is allowed. + * Otherwise, only published algorithms by some publishers are allowed + * @type {string[]} + */ publisherTrustedAlgorithmPublishers: string[] + + /** + * If empty, then any published algorithm is allowed. (see below) + * @type {PublisherTrustedAlgorithm[]} + */ publisherTrustedAlgorithms: PublisherTrustedAlgorithm[] } export interface Service { + /** + * Type of service (access, compute, wss. + * @type {string} + */ type: 'access' | 'compute' | string + + /** + * Encrypted file URLs. + * @type {string} + */ files: string + + /** + * Datatoken address + * @type {string} + */ datatokenAddress: string + + /** + * Provider URL (schema + host). + * @type {string} + */ serviceEndpoint: string + + /** + * Describing how long the service can be used after consumption is initiated. + * @type {string} + */ timeout: string + + /** + * Service friendly name + * @type {string} + */ name?: string + + /** + * Service description + * @type {string} + */ description?: string + + /** + * If service is of typecompute, holds information about the compute-related privacy settings & resources. + * @type {string} + */ compute?: ServiceComputeOptions } diff --git a/src/ddo/index.ts b/src/ddo/index.ts index 4bd3a54b..06eb4fc6 100644 --- a/src/ddo/index.ts +++ b/src/ddo/index.ts @@ -1 +1,5 @@ export * from './DDO' +export * from './Asset' +export * from './Service' +export * from './Credentials' +export * from './Metadata' From 084076e938b6a433ede8a57b79d89b2c5aa9210a Mon Sep 17 00:00:00 2001 From: Bogdan Fazakas Date: Mon, 15 Nov 2021 10:51:26 +0200 Subject: [PATCH 3/3] small adjustments --- src/ddo/Asset.ts | 43 +++++++++++++++++++++++++------------------ src/ddo/DDO.ts | 2 +- src/ddo/Service.ts | 8 +++++++- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/ddo/Asset.ts b/src/ddo/Asset.ts index fa4deb23..180aeb0c 100644 --- a/src/ddo/Asset.ts +++ b/src/ddo/Asset.ts @@ -35,9 +35,21 @@ export interface AssetNft { * @type {number} */ state: 0 | 1 | 2 | 3 | 4 + + /** + * Contains the date of NFT creation. + * @type {string} + */ + created: string } export interface AssetDatatoken { + /** + * Contract address of the deployed ERC20 contract. + * @type {string} + */ + address: string + /** * Name of NFT set in contract. * @type {string} @@ -50,12 +62,6 @@ export interface AssetDatatoken { */ symbol: string - /** - * Contract address of the deployed ERC20 contract. - * @type {string} - */ - address: string - /** * ID of the service the datatoken is attached to. * @type {string} @@ -68,6 +74,7 @@ export interface AssetLastEvent { block: number from: string contract: string + datetime: string } export class Asset extends DDO { @@ -93,17 +100,17 @@ export class Asset extends DDO { * The stats section contains different statistics fields. * @type {string} */ - stats: { consume: number } + stats: { + /** + * How often an asset was consumed, meaning how often it was either downloaded or used as part of a compute job. + * @type {string} + */ + consume: number - /** - * If asset is listed in purgatory and reason. - * @type {string} - */ - isInPurgatory: string - - /** - * Name of NFT set in contract. - * @type {AssetDatatoken} - */ - dataTokenInfo: AssetDatatoken // To be removed + /** + * If asset is listed in purgatory and reason. + * @type {string} + */ + isInPurgatory: string + } } diff --git a/src/ddo/DDO.ts b/src/ddo/DDO.ts index 465e4aab..8808b384 100644 --- a/src/ddo/DDO.ts +++ b/src/ddo/DDO.ts @@ -8,7 +8,7 @@ import { Credentials } from './Credentials' */ export class DDO { /** - * Contexts used for validation.. + * Contexts used for validation. * @type {string[]} */ public '@context': string[] diff --git a/src/ddo/Service.ts b/src/ddo/Service.ts index 12922209..c5b447b7 100644 --- a/src/ddo/Service.ts +++ b/src/ddo/Service.ts @@ -89,6 +89,12 @@ export interface ServiceComputeOptions { } export interface Service { + /** + * Unique ID + * @type {string} + */ + id: string + /** * Type of service (access, compute, wss. * @type {string} @@ -133,7 +139,7 @@ export interface Service { /** * If service is of typecompute, holds information about the compute-related privacy settings & resources. - * @type {string} + * @type {ServiceComputeOptions} */ compute?: ServiceComputeOptions }