1
0
mirror of https://github.com/oceanprotocol/ocean.js.git synced 2024-11-26 20:39:05 +01:00

Merge pull request #1111 from oceanprotocol/feature/v4DDO

DDO typings
This commit is contained in:
Bogdan Fazakas 2021-11-22 12:05:41 +02:00 committed by GitHub
commit 3d23328637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 456 additions and 0 deletions

116
src/ddo/Asset.ts Normal file
View File

@ -0,0 +1,116 @@
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
/**
* 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}
*/
name: string
/**
* Symbol of NFT set in contract.
* @type {string}
*/
symbol: 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
datetime: 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: {
/**
* 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
}
}

9
src/ddo/Credentials.ts Normal file
View File

@ -0,0 +1,9 @@
export interface Credential {
type: string
values: string[]
}
export interface Credentials {
allow: Credential[]
deny: Credential[]
}

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

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

127
src/ddo/Metadata.ts Normal file
View File

@ -0,0 +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 its 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
}

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

@ -0,0 +1,145 @@
export interface PublisherTrustedAlgorithm {
/**
* The DID of the algorithm which is trusted by the publisher.
* @type {string}
*/
did: string
/**
* Hash of algorithms files section.
* @type {string}
*/
filesChecksum: string
/**
* Hash of algorithms 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 {
/**
* Unique ID
* @type {string}
*/
id: string
/**
* 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 {ServiceComputeOptions}
*/
compute?: ServiceComputeOptions
}

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

@ -0,0 +1,5 @@
export * from './DDO'
export * from './Asset'
export * from './Service'
export * from './Credentials'
export * from './Metadata'