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.

ParameterTypeEVMSubstrateDescription
namestringRequiredRequiredName of the DID to be created.
addressstringRequiredOptionalWallet address that is used to create the DID Document. If seed set for substrate, defaults to public address for that seed.
seedstringN/AOptionalMnemonic phrase used in Substrate instances to execute write transactions on behalf of the wallet. Not necessary when seed set at instance creation.
customDocumentFieldsCustomDocumentFieldsOptionalOptionalUsed 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

ParameterTypeEVMSubstrateDescription
verificationsVerification[]OptionalOptionalStores the verification method that is tied to the wallet used to create this DID Document.
signatureSignatureOptionalOptionalUsed to store an issuer’s signature.
servicesServices[]OptionalOptionalLinks data, endpoints, or other metadata to the DID Document.

Verification

ParameterTypeEVMSubstrateDescription
typestringOptionalOptionalAllows 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
publicKeyMultibasestringOptionalOptionalAllows user to manually set the public Key MultiBase they would like to use for their verification method.

Signature

ParameterTypeEVMSubstrateDescription
typestringRequiredRequiredThe algorithm used when generating a signature.
issuerstringRequiredRequiredEntity that issued the signature.
hashstringRequiredRequiredHash value of the generated signature.

Services

ParameterTypeEVMSubstrateDescription
idstringRequiredRequiredIdentifier used to indicate what type of service is being used.
typestringRequiredRequiredDeclares the type of service object being referenced.
serviceEndpointstringOptionalOptionalURI/URL that is used to point to another data storage location.
datastringOptionalOptionalData value that can be stored at this service.

Create DID Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const name = "DID_NAME";

// possible example of custom document fields a DePIN could create
const customFields = {
    services: [{
      id: "#ipfs",
      type: "machineData",
      serviceEndpoint: "https://ipfs.io/ipfs/QmYwAPJzv5CZsnAzt8auVTLv3jE9n1Tz8exzhTHtVMJd3t"
    }]
};

const tx = await sdk.did.create({
  name: name,
  address: EVM_ADDRESS,
  customDocumentFields: customFields
});

// Create DID using sendEvmTx() function
const receipt = await Sdk.sendEvmTx({
  tx: tx,
  baseUrl: HTTPS_BASE_URL,
  seed: EVM_PRIVATE
});

read(name, address, wssBaseUrl)

Allows a user to read a previously created DID from the chain.

ParameterTypeEVMSubstrateDescription
namestringRequiredRequiredName of the DID stored.
addressstringRequiredOptionalAddress 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.
wssBaseUrlstringRequiredOptionalWSS URL must be used to read DID Document. EVM must explicitly set WSS (Substrate has it stored during instance creation).

Read DID Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const name = "DID_NAME";

const document = await sdk.did.read({
  name: name,
  address: EVM_ADDRESS,
  wssBaseUrl: WSS_BASE_URL
});

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.

ParameterTypeEVMSubstrateDescription
namestringRequiredRequiredName of the DID to be updated.
addressstringRequiredOptionalWallet address that has the authority to update the DID Document. If Substrate seed at initialization, will default to the public address for that seed.
wssBaseUrlstringRequiredN/AWSS URL must be used to read a DID Document. Used to read the previous DID Document at that location when updating a DID Document.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.
customDocumentFieldsCustomDocumentFieldsOptionalOptionalUsed 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

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const WSS_BASE_URL = "wss://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];


const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const name = "DID_NAME";

// add a verification method and include the previosly set service
const customFields = {
    verificationMethods: [{
      type: "EcdsaSecp256k1RecoveryMethod2020"
    }],
    services: [{
      id: "#ipfs",
      type: "machineData",
      serviceEndpoint: "https://ipfs.io/ipfs/QmYwAPJzv5CZsnAzt8auVTLv3jE9n1Tz8exzhTHtVMJd3t"
    }]
};

const tx = await sdk.did.update({
  name: name,
  address: EVM_ADDRESS,
  wssBaseUrl: WSS_BASE_URL,
  customDocumentFields: customFields
});

// send using Sdk function
const receipt = await Sdk.sendEvmTx({
  tx: tx,
  baseUrl: HTTPS_BASE_URL,
  seed: EVM_PRIVATE
});

// read to see the updated document
const document = await sdk.did.read({
    name: name,
    address: EVM_ADDRESS,
    wssBaseUrl: WSS_BASE_URL
});

remove(name, address, seed)

Deletes a previously created DID Document from the chain.

ParameterTypeEVMSubstrateDescription
namestringRequiredRequiredName of the DID to be deleted.
addressstringRequiredOptionalWallet address that has the authority to delete the DID Document.
seedstringN/AOptionalIf not set at instance creation, allows user to define who sends the Substrate Transactions.

Remove DID Code Examples

import { Sdk } from "@peaq-network/sdk";

const HTTPS_BASE_URL = "https://peaq.api.onfinality.io/public";
const EVM_ADDRESS = process.env["EVM_ADDRESS"];
const EVM_PRIVATE = process.env["EVM_PRIVATE"];

const sdk = await Sdk.createInstance({
    baseUrl: HTTPS_BASE_URL,
    chainType: Sdk.ChainType.EVM
});

const name = "DID_NAME";

const tx = await sdk.did.remove({
  name: name,
  address: EVM_ADDRESS
});

// Send using Sdk function
const receipt = await Sdk.sendEvmTx({
  tx: tx,
  baseUrl: HTTPS_BASE_URL,
  seed: EVM_PRIVATE
});