sdk-js

@nevermined-io/sdk - v3.0.44 / DDO

Class: DDO

DID Descriptor Object (DDO). Contains all the metadata related to an asset, including the description and the services available.

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new DDO(ddo?): DDO

Parameters

Name Type
ddo Partial<DDO>

Returns

DDO

Defined in

src/ddo/DDO.ts:235

Properties

@context

@context: string = 'https://w3id.org/did/v1'

Defined in

src/ddo/DDO.ts:212


_nvm

_nvm: NvmConfig

Defined in

src/ddo/DDO.ts:221


authentication

authentication: Authentication[] = []

Defined in

src/ddo/DDO.ts:229


created

created: string

Defined in

src/ddo/DDO.ts:223


didSeed

didSeed: string = ''

Defined in

src/ddo/DDO.ts:219


id

id: string = ''

DID, decentralizes ID.

Defined in

src/ddo/DDO.ts:217


proof

proof: Proof

Defined in

src/ddo/DDO.ts:233


publicKey

publicKey: PublicKey[] = []

Defined in

src/ddo/DDO.ts:227


service

service: ServiceCommon[] = []

Defined in

src/ddo/DDO.ts:231


updated

Optional updated: string

Defined in

src/ddo/DDO.ts:225

Methods

addDefaultMetadataService

addDefaultMetadataService(metadata, nftAttributes?): MetaDataMain

Adds a default metadata service to the DDO.

Parameters

Name Type Description
metadata MetaData metadata
nftAttributes? NFTAttributes nft attributes

Returns

MetaDataMain

main metadata attributes

Defined in

src/ddo/DDO.ts:477


addProof

addProof(publicKey): Promise<void>

Generates and adds a proof using personal sign on the DDO.

Parameters

Name Type Description
publicKey string Public key to be used on personal sign.

Returns

Promise<void>

void.

Defined in

src/ddo/DDO.ts:427


addService

addService(service): void

Adds a service to the DDO.

Parameters

Name Type
service ServiceCommon

Returns

void

Defined in

src/ddo/DDO.ts:449


addSignature

addSignature(nevermined, publicKey): Promise<void>

It adds a signature to the the proof object of the DDO

Parameters

Name Type Description
nevermined Nevermined nevermined object
publicKey string public key to sign the DDO

Returns

Promise<void>

Defined in

src/ddo/DDO.ts:559


assignDid

assignDid(didSeed, didRegistry, publisher): Promise<void>

Assign a DID to the DDO

Parameters

Name Type Description
didSeed string DID seed
didRegistry DIDRegistry DIDRegistry contract
publisher NvmAccount account registering the DID

Returns

Promise<void>

Defined in

src/ddo/DDO.ts:537


checksum

checksum(seed): string

Parameters

Name Type
seed string

Returns

string

Defined in

src/ddo/DDO.ts:389


findServiceByIndex

findServiceByIndex<T>(index): Service<T>

Finds a service of a DDO by index number.

Type parameters

Name Type
T extends ServiceType

Parameters

Name Type Description
index number index of the service in the DDO.

Returns

Service<T>

Service.

Defined in

src/ddo/DDO.ts:294


findServiceByReference

findServiceByReference<T>(serviceReference): Service<T>

Finds a service of a DDO by index.

Type parameters

Name Type
T extends ServiceType

Parameters

Name Type Description
serviceReference number | ServiceType reference to the service (index or type).

Returns

Service<T>

Service.

Defined in

src/ddo/DDO.ts:328


findServiceByType

findServiceByType<T>(serviceType): Service<T>

Finds the first service of a DDO by type.

Type parameters

Name Type
T extends ServiceType

Parameters

Name Type Description
serviceType T Service type used by find the service

Returns

Service<T>

Service.

Throws

DDOServiceNotFoundError If the service is not in the DDO.

Defined in

src/ddo/DDO.ts:314


generateDidSeed

generateDidSeed(seed): Promise<`0x${string}`>

It generates a DID seed from a seed

Parameters

Name Type Description
seed any the seed

Returns

Promise<`0x${string}`>

the string represeing the DID seed

Defined in

src/ddo/DDO.ts:550


generateProof

generateProof(publicKey): Promise<Proof>

Generates proof using personal sign.

Parameters

Name Type Description
publicKey string Public key to be used on personal sign.

Returns

Promise<Proof>

Proof object.

Defined in

src/ddo/DDO.ts:398


getAssetPriceFromDDOByServiceType

getAssetPriceFromDDOByServiceType(service): AssetPrice

It gets the AssetPrice from a service given the serviceType

Parameters

Name Type Description
service ServiceType the service to search in

Returns

AssetPrice

the AssetPrice object

Defined in

src/ddo/DDO.ts:714


getPriceByService

getPriceByService(serviceType?): bigint

Get the total price of a service.

Parameters

Name Type Default value Description
serviceType ServiceType 'access' Service type

Returns

bigint

bigint

Example

const price = ddo.getPriceByService('nft-access')

Throws

DDOPriceNotFoundError

Defined in

src/ddo/DDO.ts:379


getProofChecksum

getProofChecksum(): string

Get the checksum of the proof.

Returns

string

string containing the checksum of the proof.

Defined in

src/ddo/DDO.ts:418


getServicesByType

getServicesByType<T>(serviceType): Service<T>[]

Gets all the services of a DDO with a specific type.

Type parameters

Name Type
T extends ServiceType

Parameters

Name Type Description
serviceType T Service type.

Returns

Service<T>[]

Service.

Defined in

src/ddo/DDO.ts:344


reorderServices

reorderServices(): void

It reorders the services of the DDO using the service index

Returns

void

Defined in

src/ddo/DDO.ts:437


replaceService

replaceService(index, service): void

Replaces a service in the DDO.

Parameters

Name Type
index number
service any

Returns

void

Defined in

src/ddo/DDO.ts:465


serviceExists

serviceExists<T>(serviceType): boolean

Checks if a service exists in the DDO.

Type parameters

Name Type
T extends ServiceType

Parameters

Name Type Description
serviceType T Service type.

Returns

boolean

true if service exists.

Defined in

src/ddo/DDO.ts:354


serviceIndexExists

serviceIndexExists(serviceIndex): boolean

Checks if a service index in the DDO.

Parameters

Name Type Description
serviceIndex number Service index.

Returns

boolean

true if service exists.

Defined in

src/ddo/DDO.ts:364


setAssetPriceFromDDOByService

setAssetPriceFromDDOByService(serviceType, rewards): void

Given a service type, it sets the AssetPrice in the escrowPayment condition

Parameters

Name Type Description
serviceType ServiceType the service to search in
rewards AssetPrice the AssetPrice object to set

Returns

void

Defined in

src/ddo/DDO.ts:724


setNFTRewardsFromService

setNFTRewardsFromService(serviceType, rewards, holderAddress): undefined | DDOConditionNotFoundError

Given the service type it sets the AssetPrice and NFT holder

Parameters

Name Type Description
serviceType ServiceType the service type to search in
rewards AssetPrice the AssetPrice object to set
holderAddress string the NFT Holder address to set

Returns

undefined | DDOConditionNotFoundError

Defined in

src/ddo/DDO.ts:751


shortId

shortId(): string

It returns the DDO id without the prefix

Returns

string

the DID without the prefix

Defined in

src/ddo/DDO.ts:285


updateMetadataService

updateMetadataService(service): void

Updates a service in the DDO

Parameters

Name Type Description
service any the service to be updated

Returns

void

Defined in

src/ddo/DDO.ts:523


updateService

updateService(service, serviceIndex?): void

Parameters

Name Type Default value Description
service any undefined the service to be updated
serviceIndex number 0 the position of the service in the DDO.services array

Returns

void

Deprecated

use the updateMetadataService or replaceService methods instead Updates a service in the DDO

Defined in

src/ddo/DDO.ts:514


createAuthorizationService

createAuthorizationService(neverminedNodeUri, publicKey, method): ServiceCommon

It creates an authorization service that can be included later as part of a DDO

Parameters

Name Type Description
neverminedNodeUri string URL of the Nevermined Node managing this asset
publicKey string Public key of the user
method string Encryption method

Returns

ServiceCommon

The authorization service

Defined in

src/ddo/DDO.ts:193


deserialize

deserialize(ddoString): DDO

Deserializes the DDO object.

Parameters

Name Type Description
ddoString string The serialized DDO to be deserialized.

Returns

DDO

The deserialized DDO.

Defined in

src/ddo/DDO.ts:180


findAndReplaceDDOAttribute

findAndReplaceDDOAttribute(ddo, paramName, value): DDO

Finds an attribute in the DDO and replace it with the given value

Parameters

Name Type Description
ddo DDO the originial DDO
paramName string | RegExp the param name to replace
value string the new value

Returns

DDO

the DDO with the replaced attribute

Defined in

src/ddo/DDO.ts:774


findServiceConditionByName

findServiceConditionByName(service, name): ServiceAgreementTemplateCondition

If fins a service condition by name

Parameters

Name Type Description
service ServiceCommon the service to search in
name ConditionType the name of the condition

Returns

ServiceAgreementTemplateCondition

ServiceAgreementTemplateCondition the condition

Defined in

src/ddo/DDO.ts:571


getAssetPriceFromService

getAssetPriceFromService(service): AssetPrice

It gets the AssetPrice from a service with escrowPayment condition

Parameters

Name Type Description
service ServiceCommon the service to search in

Returns

AssetPrice

the AssetPrice object

Defined in

src/ddo/DDO.ts:689


getDIDFromService

getDIDFromService(service): string

Gets the DID in the escrowPayment condition of the service

Parameters

Name Type Description
service ServiceCommon the service to search in

Returns

string

the DID

Defined in

src/ddo/DDO.ts:587


getDurationFromService

getDurationFromService(service): number

Gets the duration parameter in the transferNFT condition of the service

Parameters

Name Type Description
service ServiceCommon the service to search in

Returns

number

the duration of the subscription

Defined in

src/ddo/DDO.ts:644


getInstance

getInstance(userId, publisherAddress, appId?): DDO

It gets an instance of a DDO with the basic structure

Parameters

Name Type Description
userId string The unique identifier of the user
publisherAddress string The address of the publisher
appId? string The application id

Returns

DDO

a DDO instance

Defined in

src/ddo/DDO.ts:248


getNFTTransferFromService

getNFTTransferFromService(service): boolean

Gets the nftTransfer parameter in the transferNFT condition of the service

Parameters

Name Type Description
service ServiceCommon the service to search in

Returns

boolean

if condition will do a nft transfer or a mint

Defined in

src/ddo/DDO.ts:633


getNewDateFormatted

getNewDateFormatted(date?): string

It gets a new date formatted

Parameters

Name Type Description
date Date the date to format

Returns

string

the date string formatted

Defined in

src/ddo/DDO.ts:277


getNftAmountFromService

getNftAmountFromService(service): bigint

Gets the number of NFTs in the transferNFT condition of the service

Parameters

Name Type Description
service ServiceCommon the service to search in

Returns

bigint

the number of NFTs

Defined in

src/ddo/DDO.ts:619


getNftContractAddressFromService

getNftContractAddressFromService(service): string

Gets the NFT Contract address used in the NFT Access or NFT Sales service

Parameters

Name Type Description
service ServiceNFTAccess | ServiceNFTSales the service to search in

Returns

string

the NFT contract address

Defined in

src/ddo/DDO.ts:673


getNftHolderFromService

getNftHolderFromService(service): string

Gets the NFT Holder in the transferNFT condition of the service

Parameters

Name Type Description
service ServiceCommon the service to search in

Returns

string

the NFT Holder address

Defined in

src/ddo/DDO.ts:597


getParameterFromCondition

getParameterFromCondition(service, conditionType, paramName): string | number | string[]

Given a service, condition and param name it returns the value

Parameters

Name Type Description
service ServiceCommon The service where the condition is
conditionType ConditionType the condition type
paramName string the param name

Returns

string | number | string[]

the value

Defined in

src/ddo/DDO.ts:655


getTokenIdFromService

getTokenIdFromService(service): string

Gets the NFT TokenId in the nftHolder condition of the service

Parameters

Name Type Description
service ServiceCommon the service to search in

Returns

string

the NFT Token Id

Defined in

src/ddo/DDO.ts:606


parseDDOWebServiceAttributes

parseDDOWebServiceAttributes(webService, did): WebService

Parameters

Name Type
webService WebService
did string

Returns

WebService

Defined in

src/ddo/DDO.ts:782


serialize

serialize(ddo): string

Serializes the DDO object.

Parameters

Name Type Description
ddo DDO The DDO to be serialized.

Returns

string

DDO serialized.

Defined in

src/ddo/DDO.ts:171