mirror of
https://github.com/oceanprotocol/ocean.js.git
synced 2024-11-26 20:39:05 +01:00
chore: verifiableCredential struct
This commit is contained in:
parent
0fbc536d89
commit
696f4b5ca8
4
src/@types/DDO/AdditionalVerifiableCredentials.ts
Normal file
4
src/@types/DDO/AdditionalVerifiableCredentials.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export interface AdditionalVerifiableCredentials {
|
||||
type: string
|
||||
data: any
|
||||
}
|
51
src/@types/DDO/CredentialSubject.ts
Normal file
51
src/@types/DDO/CredentialSubject.ts
Normal file
@ -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
|
||||
}
|
@ -1,9 +1,20 @@
|
||||
export interface Credential {
|
||||
export interface RequestCredential {
|
||||
type: string
|
||||
format: string
|
||||
policies?: (string | Record<string, string | number | boolean>)[]
|
||||
}
|
||||
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[]
|
||||
}
|
||||
|
5
src/@types/DDO/LanguageValueObject.ts
Normal file
5
src/@types/DDO/LanguageValueObject.ts
Normal file
@ -0,0 +1,5 @@
|
||||
export interface LanguageValueObject {
|
||||
'@value': string
|
||||
'@language': string
|
||||
'@direction': string
|
||||
}
|
7
src/@types/DDO/License.ts
Normal file
7
src/@types/DDO/License.ts
Normal file
@ -0,0 +1,7 @@
|
||||
import { RemoteObject } from './RemoteObject'
|
||||
|
||||
export interface License {
|
||||
name: string
|
||||
ODRL?: unknown
|
||||
licenseDocuments?: RemoteObject[]
|
||||
}
|
@ -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 {
|
||||
|
12
src/@types/DDO/RemoteObject.ts
Normal file
12
src/@types/DDO/RemoteObject.ts
Normal file
@ -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<string, string | number | boolean>
|
||||
}
|
7
src/@types/DDO/RemoteSource.ts
Normal file
7
src/@types/DDO/RemoteSource.ts
Normal file
@ -0,0 +1,7 @@
|
||||
export interface RemoteSource {
|
||||
type: string
|
||||
url?: string
|
||||
method?: string
|
||||
headers?: string | Record<string, string | number | boolean>
|
||||
ipfsCid?: string
|
||||
}
|
@ -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
|
||||
}
|
||||
|
9
src/@types/DDO/State.ts
Normal file
9
src/@types/DDO/State.ts
Normal file
@ -0,0 +1,9 @@
|
||||
/* eslint-disable no-unused-vars */
|
||||
export enum State {
|
||||
Active,
|
||||
EndOfLife,
|
||||
Deprecated,
|
||||
RevokedByPublisher,
|
||||
OrderingIsTemporaryDisabled,
|
||||
AssetUnlisted
|
||||
}
|
40
src/@types/DDO/VerifiableCredential.ts
Normal file
40
src/@types/DDO/VerifiableCredential.ts
Normal file
@ -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[]
|
||||
}
|
@ -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',
|
||||
|
Loading…
x
Reference in New Issue
Block a user