JavaScript
DID Operations
Using the instance created on the previous pages you are able to execute the peaq DID functionalities that allow for the creation of a DID Document.
create(name, address, seed, customDocumentFields)
Enables the creation of a decentralized identity on-chain for your given entity.
Parameter | Type | EVM | Substrate | Description |
---|---|---|---|---|
name | string | Required | Required | Name of the DID to be created. |
address | string | Required | Optional | Wallet address that is used to create the DID Document. If seed set for substrate, defaults to public address for that seed. |
seed | string | N/A | Optional | Mnemonic phrase used in Substrate instances to execute write transactions on behalf of the wallet. Not necessary when seed set at instance creation. |
customDocumentFields | CustomDocumentFields | Optional | Optional | Used to set specific fields of the DID Document. If none is set, an empty document will be generated with id and controller set to the signer’s address. |
customDocumentFields
Parameter | Type | EVM | Substrate | Description |
---|---|---|---|---|
verifications | Verification[] | Optional | Optional | Stores the verification method that is tied to the wallet used to create this DID Document. |
signature | Signature | Optional | Optional | Used to store an issuer’s signature. |
services | Services[] | Optional | Optional | Links data, endpoints, or other metadata to the DID Document. |
Verification
Parameter | Type | EVM | Substrate | Description |
---|---|---|---|---|
type | string | Optional | Optional | Allows user to manually set the type of verification to be used with the public key tied to the DID Document. EVM Wallets: - EcdsaSecp256k1RecoveryMethod2020 Substrate Wallets: - Ed25519VerificationKey2020 - Sr25519VerificationKey2020 |
publicKeyMultibase | string | Optional | Optional | Allows user to manually set the public Key MultiBase they would like to use for their verification method. |
Signature
Parameter | Type | EVM | Substrate | Description |
---|---|---|---|---|
type | string | Required | Required | The algorithm used when generating a signature. |
issuer | string | Required | Required | Entity that issued the signature. |
hash | string | Required | Required | Hash value of the generated signature. |
Services
Parameter | Type | EVM | Substrate | Description |
---|---|---|---|---|
id | string | Required | Required | Identifier used to indicate what type of service is being used. |
type | string | Required | Required | Declares the type of service object being referenced. |
serviceEndpoint | string | Optional | Optional | URI/URL that is used to point to another data storage location. |
data | string | Optional | Optional | Data value that can be stored at this service. |
Create DID Code Examples
read(name, address, wssBaseUrl)
Allows a user to read a previously created DID from the chain.
Parameter | Type | EVM | Substrate | Description |
---|---|---|---|---|
name | string | Required | Required | Name of the DID stored. |
address | string | Required | Optional | Address of the wallet that created the DID Document. Reading from an EVM tx requires an address to be explicitly set. If a seed has been set for Substrate, the address tied to that phrase will be used. |
wssBaseUrl | string | Required | Optional | WSS URL must be used to read DID Document. EVM must explicitly set WSS (Substrate has it stored during instance creation). |
Read DID Code Examples
update(name, address, seed, customDocumentFields)
Allows the owner of the DID Document to update a previously created one. Uses the same parameters as createDid() function above for the Custom Document Fields.
Parameter | Type | EVM | Substrate | Description |
---|---|---|---|---|
name | string | Required | Required | Name of the DID to be updated. |
address | string | Required | Optional | Wallet address that has the authority to update the DID Document. If Substrate seed at initialization, will default to the public address for that seed. |
wssBaseUrl | string | Required | N/A | WSS URL must be used to read a DID Document. Used to read the previous DID Document at that location when updating a DID Document. |
seed | string | N/A | Optional | If not set at instance creation, allows user to define who sends the Substrate Transactions. |
customDocumentFields | CustomDocumentFields | Optional | Optional | Used to update specific fields of the DID Document. Overwrites the previous DID Document so make sure you keep track of data previously stored. |
Update DID Code Examples
remove(name, address, seed)
Deletes a previously created DID Document from the chain.
Parameter | Type | EVM | Substrate | Description |
---|---|---|---|---|
name | string | Required | Required | Name of the DID to be deleted. |
address | string | Required | Optional | Wallet address that has the authority to delete the DID Document. |
seed | string | N/A | Optional | If not set at instance creation, allows user to define who sends the Substrate Transactions. |