DDO
@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
- addDefaultMetadataService
- addProof
- addService
- addSignature
- assignDid
- checksum
- findServiceByIndex
- findServiceByReference
- findServiceByType
- generateDidSeed
- generateProof
- getAssetPriceFromDDOByServiceType
- getPriceByService
- getProofChecksum
- getServicesByType
- reorderServices
- replaceService
- serviceExists
- serviceIndexExists
- setAssetPriceFromDDOByService
- setNFTRewardsFromService
- shortId
- updateMetadataService
- updateService
- createAuthorizationService
- deserialize
- findAndReplaceDDOAttribute
- findServiceConditionByName
- getAssetPriceFromService
- getDIDFromService
- getDurationFromService
- getInstance
- getNFTTransferFromService
- getNewDateFormatted
- getNftAmountFromService
- getNftContractAddressFromService
- getNftHolderFromService
- getParameterFromCondition
- getTokenIdFromService
- parseDDOWebServiceAttributes
- serialize
Constructors
constructor
• new DDO(ddo?
): DDO
Parameters
Name | Type |
---|---|
ddo | Partial \<DDO > |
Returns
Defined in
Properties
@context
• @context: string
= 'https://w3id.org/did/v1'
Defined in
_nvm
• _nvm: NvmConfig
Defined in
authentication
• authentication: Authentication
[] = []
Defined in
created
• created: string
Defined in
didSeed
• didSeed: string
= ''
Defined in
id
• id: string
= ''
DID, decentralizes ID.
Defined in
proof
• proof: Proof
Defined in
publicKey
• publicKey: PublicKey
[] = []
Defined in
service
• service: ServiceCommon
[] = []
Defined in
updated
• Optional
updated: string
Defined in
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
main metadata attributes
Defined in
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
addService
▸ addService(service
): void
Adds a service to the DDO.
Parameters
Name | Type |
---|---|
service | ServiceCommon |
Returns
void
Defined in
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
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
checksum
▸ checksum(seed
): string
Parameters
Name | Type |
---|---|
seed | string |
Returns
string
Defined in
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
>
Defined in
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
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
>
Throws
DDOServiceNotFoundError If the service is not in the DDO.
Defined in
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
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
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
the AssetPrice object
Defined in
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
Defined in
getProofChecksum
▸ getProofChecksum(): string
Get the checksum of the proof.
Returns
string
string containing the checksum of the proof.
Defined in
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
>[]
Defined in
reorderServices
▸ reorderServices(): void
It reorders the services of the DDO using the service index
Returns
void
Defined in
replaceService
▸ replaceService(index
, service
): void
Replaces a service in the DDO.
Parameters
Name | Type |
---|---|
index | number |
service | any |
Returns
void
Defined in
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
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
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
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
shortId
▸ shortId(): string
It returns the DDO id without the prefix
Returns
string
the DID without the prefix
Defined in
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
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
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
The authorization service
Defined in
deserialize
▸ deserialize(ddoString
): DDO
Deserializes the DDO object.
Parameters
Name | Type | Description |
---|---|---|
ddoString | string | The serialized DDO to be deserialized. |
Returns
The deserialized DDO.
Defined in
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
the DDO with the replaced attribute
Defined in
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
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
the AssetPrice object
Defined in
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
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
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
a DDO instance
Defined in
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
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
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
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
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
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
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
parseDDOWebServiceAttributes
▸ parseDDOWebServiceAttributes(webService
, did
): WebService
Parameters
Name | Type |
---|---|
webService | WebService |
did | string |
Returns
Defined in
serialize
▸ serialize(ddo
): string
Serializes the DDO object.
Parameters
Name | Type | Description |
---|---|---|
ddo | DDO | The DDO to be serialized. |
Returns
string
DDO serialized.