@nevermined-io/sdk - v3.0.44 / DDO
DID Descriptor Object (DDO). Contains all the metadata related to an asset, including the description and the services available.
• new DDO(ddo?
): DDO
Name | Type |
---|---|
ddo |
Partial <DDO > |
• @context: string
= 'https://w3id.org/did/v1'
• _nvm: NvmConfig
• authentication: Authentication
[] = []
• created: string
• didSeed: string
= ''
• id: string
= ''
DID, decentralizes ID.
• proof: Proof
• publicKey: PublicKey
[] = []
• service: ServiceCommon
[] = []
• Optional
updated: string
▸ addDefaultMetadataService(metadata
, nftAttributes?
): MetaDataMain
Adds a default metadata service to the DDO.
Name | Type | Description |
---|---|---|
metadata |
MetaData |
metadata |
nftAttributes? |
NFTAttributes |
nft attributes |
main metadata attributes
▸ addProof(publicKey
): Promise
<void
>
Generates and adds a proof using personal sign on the DDO.
Name | Type | Description |
---|---|---|
publicKey |
string |
Public key to be used on personal sign. |
Promise
<void
>
void.
▸ addService(service
): void
Adds a service to the DDO.
Name | Type |
---|---|
service |
ServiceCommon |
void
▸ addSignature(nevermined
, publicKey
): Promise
<void
>
It adds a signature to the the proof object of the DDO
Name | Type | Description |
---|---|---|
nevermined |
Nevermined |
nevermined object |
publicKey |
string |
public key to sign the DDO |
Promise
<void
>
▸ assignDid(didSeed
, didRegistry
, publisher
): Promise
<void
>
Assign a DID to the DDO
Name | Type | Description |
---|---|---|
didSeed |
string |
DID seed |
didRegistry |
DIDRegistry |
DIDRegistry contract |
publisher |
NvmAccount |
account registering the DID |
Promise
<void
>
▸ checksum(seed
): string
Name | Type |
---|---|
seed |
string |
string
▸ findServiceByIndex<T
>(index
): Service
<T
>
Finds a service of a DDO by index number.
Name | Type |
---|---|
T |
extends ServiceType |
Name | Type | Description |
---|---|---|
index |
number |
index of the service in the DDO. |
Service
<T
>
▸ findServiceByReference<T
>(serviceReference
): Service
<T
>
Finds a service of a DDO by index.
Name | Type |
---|---|
T |
extends ServiceType |
Name | Type | Description |
---|---|---|
serviceReference |
number | ServiceType |
reference to the service (index or type). |
Service
<T
>
Service.
▸ findServiceByType<T
>(serviceType
): Service
<T
>
Finds the first service of a DDO by type.
Name | Type |
---|---|
T |
extends ServiceType |
Name | Type | Description |
---|---|---|
serviceType |
T |
Service type used by find the service |
Service
<T
>
Throws
DDOServiceNotFoundError If the service is not in the DDO.
▸ generateDidSeed(seed
): Promise
<`0x${string}`>
It generates a DID seed from a seed
Name | Type | Description |
---|---|---|
seed |
any |
the seed |
Promise
<`0x${string}`>
the string represeing the DID seed
▸ generateProof(publicKey
): Promise
<Proof
>
Generates proof using personal sign.
Name | Type | Description |
---|---|---|
publicKey |
string |
Public key to be used on personal sign. |
Promise
<Proof
>
Proof object.
▸ getAssetPriceFromDDOByServiceType(service
): AssetPrice
It gets the AssetPrice from a service given the serviceType
Name | Type | Description |
---|---|---|
service |
ServiceType |
the service to search in |
the AssetPrice object
▸ getPriceByService(serviceType?
): bigint
Get the total price of a service.
Name | Type | Default value | Description |
---|---|---|---|
serviceType |
ServiceType |
'access' |
Service type |
bigint
bigint
Example
const price = ddo.getPriceByService('nft-access')
Throws
▸ getProofChecksum(): string
Get the checksum of the proof.
string
string containing the checksum of the proof.
▸ getServicesByType<T
>(serviceType
): Service
<T
>[]
Gets all the services of a DDO with a specific type.
Name | Type |
---|---|
T |
extends ServiceType |
Name | Type | Description |
---|---|---|
serviceType |
T |
Service type. |
Service
<T
>[]
▸ reorderServices(): void
It reorders the services of the DDO using the service index
void
▸ replaceService(index
, service
): void
Replaces a service in the DDO.
Name | Type |
---|---|
index |
number |
service |
any |
void
▸ serviceExists<T
>(serviceType
): boolean
Checks if a service exists in the DDO.
Name | Type |
---|---|
T |
extends ServiceType |
Name | Type | Description |
---|---|---|
serviceType |
T |
Service type. |
boolean
true if service exists.
▸ serviceIndexExists(serviceIndex
): boolean
Checks if a service index in the DDO.
Name | Type | Description |
---|---|---|
serviceIndex |
number |
Service index. |
boolean
true if service exists.
▸ setAssetPriceFromDDOByService(serviceType
, rewards
): void
Given a service type, it sets the AssetPrice in the escrowPayment condition
Name | Type | Description |
---|---|---|
serviceType |
ServiceType |
the service to search in |
rewards |
AssetPrice |
the AssetPrice object to set |
void
▸ setNFTRewardsFromService(serviceType
, rewards
, holderAddress
): undefined
| DDOConditionNotFoundError
Given the service type it sets the AssetPrice and NFT holder
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 |
undefined
| DDOConditionNotFoundError
▸ shortId(): string
It returns the DDO id without the prefix
string
the DID without the prefix
▸ updateMetadataService(service
): void
Updates a service in the DDO
Name | Type | Description |
---|---|---|
service |
any |
the service to be updated |
void
▸ updateService(service
, serviceIndex?
): void
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 |
void
Deprecated
use the updateMetadataService
or replaceService
methods instead
Updates a service in the DDO
▸ createAuthorizationService(neverminedNodeUri
, publicKey
, method
): ServiceCommon
It creates an authorization service that can be included later as part of a DDO
Name | Type | Description |
---|---|---|
neverminedNodeUri |
string |
URL of the Nevermined Node managing this asset |
publicKey |
string |
Public key of the user |
method |
string |
Encryption method |
The authorization service
▸ deserialize(ddoString
): DDO
Deserializes the DDO object.
Name | Type | Description |
---|---|---|
ddoString |
string |
The serialized DDO to be deserialized. |
The deserialized DDO.
▸ findAndReplaceDDOAttribute(ddo
, paramName
, value
): DDO
Finds an attribute in the DDO and replace it with the given value
Name | Type | Description |
---|---|---|
ddo |
DDO |
the originial DDO |
paramName |
string | RegExp |
the param name to replace |
value |
string |
the new value |
the DDO with the replaced attribute
▸ findServiceConditionByName(service
, name
): ServiceAgreementTemplateCondition
If fins a service condition by name
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
the service to search in |
name |
ConditionType |
the name of the condition |
ServiceAgreementTemplateCondition
ServiceAgreementTemplateCondition the condition
▸ getAssetPriceFromService(service
): AssetPrice
It gets the AssetPrice from a service with escrowPayment condition
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
the service to search in |
the AssetPrice object
▸ getDIDFromService(service
): string
Gets the DID in the escrowPayment condition of the service
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
the service to search in |
string
the DID
▸ getDurationFromService(service
): number
Gets the duration parameter in the transferNFT condition of the service
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
the service to search in |
number
the duration of the subscription
▸ getInstance(userId
, publisherAddress
, appId?
): DDO
It gets an instance of a DDO with the basic structure
Name | Type | Description |
---|---|---|
userId |
string |
The unique identifier of the user |
publisherAddress |
string |
The address of the publisher |
appId? |
string |
The application id |
a DDO instance
▸ getNFTTransferFromService(service
): boolean
Gets the nftTransfer parameter in the transferNFT condition of the service
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
the service to search in |
boolean
if condition will do a nft transfer or a mint
▸ getNewDateFormatted(date?
): string
It gets a new date formatted
Name | Type | Description |
---|---|---|
date |
Date |
the date to format |
string
the date string formatted
▸ getNftAmountFromService(service
): bigint
Gets the number of NFTs in the transferNFT condition of the service
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
the service to search in |
bigint
the number of NFTs
▸ getNftContractAddressFromService(service
): string
Gets the NFT Contract address used in the NFT Access or NFT Sales service
Name | Type | Description |
---|---|---|
service |
ServiceNFTAccess | ServiceNFTSales |
the service to search in |
string
the NFT contract address
▸ getNftHolderFromService(service
): string
Gets the NFT Holder in the transferNFT condition of the service
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
the service to search in |
string
the NFT Holder address
▸ getParameterFromCondition(service
, conditionType
, paramName
): string
| number
| string
[]
Given a service, condition and param name it returns the value
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
The service where the condition is |
conditionType |
ConditionType |
the condition type |
paramName |
string |
the param name |
string
| number
| string
[]
the value
▸ getTokenIdFromService(service
): string
Gets the NFT TokenId in the nftHolder condition of the service
Name | Type | Description |
---|---|---|
service |
ServiceCommon |
the service to search in |
string
the NFT Token Id
▸ parseDDOWebServiceAttributes(webService
, did
): WebService
Name | Type |
---|---|
webService |
WebService |
did |
string |
▸ serialize(ddo
): string
Serializes the DDO object.
Name | Type | Description |
---|---|---|
ddo |
DDO |
The DDO to be serialized. |
string
DDO serialized.