Skip to main content

DID Methods

danger

TODO: Adding a key doesn't work. Can we get did:eth:sepolia to work? If not, can we use a different method (other than did:web) that supports rotation?

Introduction

The previous tutorial used did:key, which is a generative DID method that doesn't support the full range of DID lifecycle operations, such as update and delete.

This tutorial will demonstrate did:ethr:sepolia, part of the did:ethr method, which does support all CRUD operations. We're using Sepolia, a testnet, so that we can experiment without having to pay real money for transaction fees. This will require some setup in the Veramo project.

To see how to create a did:web DID, see Veramo's did:web documentation. did:web is a common choice for issung organizations who are looking to get started with DIDs that support all CRUD operations.

Steps

Prerequisites

Before you begin, follow the prerequisite steps for installation and configuration instructions.

A quick way to get started with Ethereum testing, as done in this spec, is to sign up for an Infura account. Once you've signed up:

  1. Create an API Key
  2. Ensure sepolia is selected in the Ethereum network options

Select sepolia in Ethereum networks

  1. In your Veramo agent.yml configuation, make the following changes. Note the project ID is also referred to as the API key in Infura.
    • infuraProjectId: INFURA_PROJECT_ID: find/replace with your Infura project id (everywhere in the file)
    • Under didManager, change defaultProvider to did:ethr:sepolia
    • Add a did:ethr:sepolia provider under providers:
   did:ethr:sepolia:
$require: "@veramo/did-provider-ethr#EthrDIDProvider"
$args:
- defaultKms: local
network: sepolia
rpcUrl: https://sepolia.infura.io/v3/<INFURA_API_KEY>
gas: 1000001
ttl: 31104001

Adding a DID Sepolia provider

Now you're ready to work with did:ethr:sepolia

1. Initialize a DID

First, create a did:ethr:sepolia DID.

veramo did create

Select the following options:

? Select identifier provider did:ethr:sepolia
? Select key management system local
? Enter alias tutorial2

The output will be similar to:

┌──────────────────┬───────────┬───────────────────────────────────────────────────────────────────────────────────────┐
│ provider │ alias │ did │
├──────────────────┼───────────┼───────────────────────────────────────────────────────────────────────────────────────┤
│ did:ethr:sepolia │ tutorial2 │ did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1 │
└──────────────────┴───────────┴───────────────────────────────────────────────────────────────────────────────────────┘

2. Resolve the DID

Type the following:

veramo did resolve <did:ethr:sepolia:...>

The input argument is the did:ethr:sepolia DID that was just created. Example:

veramo did resolve did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1

The result will be a DID Document, similar to the following:

{
"didDocumentMetadata": {},
"didResolutionMetadata": {
"contentType": "application/did+ld+json"
},
"didDocument": {
"id": "did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1",
"verificationMethod": [
{
"id": "did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1#controller",
"type": "EcdsaSecp256k1RecoveryMethod2020",
"controller": "did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1",
"blockchainAccountId": "eip155:11155111:0x313276BF4F7F46aB8984C4eA1180cc8837CC1d13"
},
{
"id": "did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1#controllerKey",
"type": "EcdsaSecp256k1VerificationKey2019",
"controller": "did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1",
"publicKeyHex": "02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1"
}
],
"authentication": [
"did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1#controller",
"did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1#controllerKey"
],
"assertionMethod": [
"did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1#controller",
"did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1#controllerKey"
],
"@context": [
"https://www.w3.org/ns/did/v1",
"https://w3id.org/security/suites/secp256k1recovery-2020/v2",
"https://w3id.org/security/v3-unstable"
]
}
}

Looking at the structure of a DID Document, you can see what it communicates:

  • Authentication methods
  • Assertion (or signing) methods
  • Verification methods

3. Aqcuire faucet funds for your Sepolia ETH address

The blockchainAccountId in the resolved DID document contains the Sepolia ETH address. In the above examples, the address is the part after the last colon; 0x313276BF4F7F46aB8984C4eA1180cc8837CC1d13

   "blockchainAccountId": "eip155:11155111:0x313276BF4F7F46aB8984C4eA1180cc8837CC1d13"
  1. Search for a "Sepolia faucet". At time of writing, the Google Sepolia Faucet worked, but be aware that you may need to find a backup
  2. Enter your Sepolia address (just the part after the last colon)

Now you have test funds to update your DID.

4. Add a Key to the DID

did-ethr supports updates, so now we'll add a key and look at the difference to the resolve DID Document.

veramo did add-key

Select the following options:

? Select DID did:ethr:sepolia:0x02c8c0aa6d4843f8068747b023ae4328bf487f8edc3394df712f9885ef9cb44ba1
? Service type DIDCommMessaging
? Endpoint <endpoint>

Expected output:

Success: { success: true }

TODO: Yikes, it doesn't work for me. I get this error. Should we try another DID method? did:dht?

Error: could not decode result data (value="0x", info={ "method": "identityOwner", "signature": "identityOwner(address)" }, code=BAD_DATA, version=6.12.2)