diff --git a/src/@types/DDO/AdditionalVerifiableCredentials.ts b/src/@types/DDO/AdditionalVerifiableCredentials.ts new file mode 100644 index 00000000..84a71367 --- /dev/null +++ b/src/@types/DDO/AdditionalVerifiableCredentials.ts @@ -0,0 +1,4 @@ +export interface AdditionalVerifiableCredentials { + type: string + data: any +} diff --git a/src/@types/DDO/CredentialSubject.ts b/src/@types/DDO/CredentialSubject.ts new file mode 100644 index 00000000..3076596f --- /dev/null +++ b/src/@types/DDO/CredentialSubject.ts @@ -0,0 +1,51 @@ +import { Service, Metadata, Credentials, Event } from '..' + +/** + * DID Descriptor Object. + * Contains metadata about the asset, and define access in at least one service. + */ +export interface CredentialSubject { + /** + * DID, descentralized ID. + * Computed as sha256(address of NFT contract + chainId) + * @type {string} + */ + id: string + + /** + * NFT contract address + * @type {string} + */ + nftAddress: string + + /** + * ChainId of the network the DDO was published to. + * @type {number} + */ + chainId: number + + /** + * Stores an object describing the asset. + * @type {Metadata} + */ + metadata: Metadata + + /** + * Stores an array of services defining access to the asset. + * @type {Service[]} + */ + services: Service[] + + /** + * Describes the credentials needed to access a dataset + * in addition to the services definition. + * @type {Credentials} + */ + credentials?: Credentials + + /** + * Describes the event of last metadata event + * @type {Event} + */ + event?: Event +} diff --git a/src/@types/DDO/Credentials.ts b/src/@types/DDO/Credentials.ts index 9133f74e..23b46009 100644 --- a/src/@types/DDO/Credentials.ts +++ b/src/@types/DDO/Credentials.ts @@ -1,9 +1,20 @@ -export interface Credential { +export interface RequestCredential { + type: string + format: string + policies?: (string | Record)[] +} +export interface CredentialAddressBased { type: string values: string[] } -export interface Credentials { - allow: Credential[] - deny: Credential[] +export interface CredentialPolicyBased { + vpPolicies?: string[] + vcPolicies?: string[] + requestCredentials: RequestCredential[] +} + +export interface Credentials { + allow: CredentialAddressBased[] | CredentialPolicyBased[] + deny: CredentialAddressBased[] | CredentialPolicyBased[] } diff --git a/src/@types/DDO/LanguageValueObject.ts b/src/@types/DDO/LanguageValueObject.ts new file mode 100644 index 00000000..a9f54ca2 --- /dev/null +++ b/src/@types/DDO/LanguageValueObject.ts @@ -0,0 +1,5 @@ +export interface LanguageValueObject { + '@value': string + '@language': string + '@direction': string +} diff --git a/src/@types/DDO/License.ts b/src/@types/DDO/License.ts new file mode 100644 index 00000000..f7e414f0 --- /dev/null +++ b/src/@types/DDO/License.ts @@ -0,0 +1,7 @@ +import { RemoteObject } from './RemoteObject' + +export interface License { + name: string + ODRL?: unknown + licenseDocuments?: RemoteObject[] +} diff --git a/src/@types/DDO/Metadata.ts b/src/@types/DDO/Metadata.ts index 49571a83..dca49fbe 100644 --- a/src/@types/DDO/Metadata.ts +++ b/src/@types/DDO/Metadata.ts @@ -1,4 +1,7 @@ import { ConsumerParameter } from './ConsumerParameter' +import { LanguageValueObject } from './LanguageValueObject' +import { License } from './License' +import { RemoteObject } from './RemoteObject' export interface MetadataAlgorithm { /** @@ -83,9 +86,9 @@ export interface Metadata { /** * Details of what the resource is. - * @type {string} + * @type {string | LanguageValueObject} */ - description: string + description: string | LanguageValueObject /** * Asset type. Includes "dataset" (e.g. csv file), "algorithm" (e.g. Python script). @@ -103,9 +106,9 @@ export interface Metadata { /** * Short name referencing the license of the asset. * If it’s not specified, the following value will be added: “No License Specified”. - * @type {string} + * @type {string | License} */ - license: string + license: string | License /** * Mapping of URL strings for data samples, or links to find out more information. @@ -149,6 +152,10 @@ export interface Metadata { * @type {any} */ additionalInformation?: any + + displayTitle?: LanguageValueObject + providedBy?: string + attachments?: RemoteObject[] } export interface MetadataProof { diff --git a/src/@types/DDO/RemoteObject.ts b/src/@types/DDO/RemoteObject.ts new file mode 100644 index 00000000..ff525c9d --- /dev/null +++ b/src/@types/DDO/RemoteObject.ts @@ -0,0 +1,12 @@ +import { LanguageValueObject } from './LanguageValueObject' +import { RemoteSource } from './RemoteSource' + +export interface RemoteObject { + name: string + displayName?: LanguageValueObject + description?: LanguageValueObject + fileType: string + sha256: string + mirrors: RemoteSource[] + additionalInformation?: Record +} diff --git a/src/@types/DDO/RemoteSource.ts b/src/@types/DDO/RemoteSource.ts new file mode 100644 index 00000000..71543359 --- /dev/null +++ b/src/@types/DDO/RemoteSource.ts @@ -0,0 +1,7 @@ +export interface RemoteSource { + type: string + url?: string + method?: string + headers?: string | Record + ipfsCid?: string +} diff --git a/src/@types/DDO/Service.ts b/src/@types/DDO/Service.ts index 6a794540..b0b66a2b 100644 --- a/src/@types/DDO/Service.ts +++ b/src/@types/DDO/Service.ts @@ -1,5 +1,8 @@ import { ConsumerParameter } from './ConsumerParameter' import { Credentials } from './Credentials' +import { LanguageValueObject } from './LanguageValueObject' +import { RemoteObject } from './RemoteObject' +import { State } from './State' export interface PublisherTrustedAlgorithm { /** @@ -101,9 +104,9 @@ export interface Service { /** * Service description - * @type {string} + * @type {string | LanguageValueObject} */ - description?: string + description?: string | LanguageValueObject /** * If service is of type compute, holds information about the compute-related privacy settings & resources. @@ -122,4 +125,29 @@ export interface Service { * @type {any} */ additionalInformation?: any + + /** + * @type {LanguageValueObject} + */ + displayName?: LanguageValueObject + + /** + * Required if type asset + * @type {RemoteObject} + */ + dataSchema?: RemoteObject + + /** + * Required if type algo + * @type {RemoteObject} + */ + inputSchema?: RemoteObject + + /** + * Required if type algo + * @type {RemoteObject} + */ + outputSchema?: RemoteObject + + state?: State } diff --git a/src/@types/DDO/State.ts b/src/@types/DDO/State.ts new file mode 100644 index 00000000..81bf7c74 --- /dev/null +++ b/src/@types/DDO/State.ts @@ -0,0 +1,9 @@ +/* eslint-disable no-unused-vars */ +export enum State { + Active, + EndOfLife, + Deprecated, + RevokedByPublisher, + OrderingIsTemporaryDisabled, + AssetUnlisted +} diff --git a/src/@types/DDO/VerifiableCredential.ts b/src/@types/DDO/VerifiableCredential.ts new file mode 100644 index 00000000..c18bf519 --- /dev/null +++ b/src/@types/DDO/VerifiableCredential.ts @@ -0,0 +1,40 @@ +import { AdditionalVerifiableCredentials } from './AdditionalVerifiableCredentials' +import { CredentialSubject } from './CredentialSubject' + +export interface VerifiableCredential { + /** + * Contexts used for validation. + * @type {string[]} + */ + '@context': string[] + + /** + * id optional for verifiable credential + * @type {string} + */ + id?: string + + /** + * @type {CredentialSubject} + */ + credentialSubject: CredentialSubject + + /** + * Version information in SemVer notation + * referring to the DDO spec version + * @type {string} + */ + version: string + + /** + * Id of issuer + * @type {string} + */ + issuer: string + + /** + * Additional ddos + * @type {AdditionalVerifiableCredentials[]} + */ + additionalDdos?: AdditionalVerifiableCredentials[] +} diff --git a/src/utils/OrderUtils.ts b/src/utils/OrderUtils.ts index 7bb1476c..57950a08 100644 --- a/src/utils/OrderUtils.ts +++ b/src/utils/OrderUtils.ts @@ -48,27 +48,23 @@ export async function orderAsset( serviceIndex: number = 0, fixedRateIndex: number = 0 ) { - let consumeMarketFeeToken: string let datatokenAddress: string let serviceId: string let dataTokenAddressFirstIndex: string let did: string if (isVerifiableCredential(asset)) { did = (asset as any).credentialSubject.id - consumeMarketFeeToken = - (asset as any).credentialSubject.stats.price.tokenAddress || - '0x0000000000000000000000000000000000000000' datatokenAddress = (asset as any).credentialSubject.datatokens[datatokenIndex].address dataTokenAddressFirstIndex = (asset as any).credentialSubject.datatokens[0].address serviceId = (asset as any).credentialSubject.services[serviceIndex].id } else { did = asset.id - consumeMarketFeeToken = - asset.stats.price.tokenAddress || '0x0000000000000000000000000000000000000000' datatokenAddress = asset.datatokens[datatokenIndex].address dataTokenAddressFirstIndex = asset.datatokens[0].address serviceId = asset.services[serviceIndex].id } + const consumeMarketFeeToken = + asset.stats.price.tokenAddress || '0x0000000000000000000000000000000000000000' if (!consumeMarketOrderFee) consumeMarketOrderFee = { consumeMarketFeeAddress: '0x0000000000000000000000000000000000000000',