Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ethr-did-resolver

decentralized-identity39.6kApache-2.011.0.3TypeScript support: included

Resolve DID documents for ethereum addresses and public keys

did:ethr, DID, DID document, PKI, resolver, Verifiable Credential, W3C, ethereum, ethereumAddress, blockchainAccountId, registry, EIP1056, EcdsaSecp256k1RecoveryMethod2020, EcdsaSecp256k1VerificationKey2019, Ed25519VerificationKey2018

readme

npm npm codecov

ethr DID Resolver

This library is intended to use ethereum addresses or secp256k1 publicKeys as fully self-managed Decentralized Identifiers and wrap them in a DID Document

It supports the proposed Decentralized Identifiers spec from the W3C Credentials Community Group.

It requires the did-resolver library, which is the primary interface for resolving DIDs.

This DID method relies on the ethr-did-registry.

DID method

To encode a DID for an Ethereum address on the ethereum mainnet, simply prepend did:ethr:

eg:

did:ethr:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74

Multi-network DIDs are also supported, if the proper configuration is provided during setup.

For example: did:ethr:0x5:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74 gets resolved on the goerli testnet (chainID=0x5), and represents a distinct identifier than the generic one, with different DID documents and different key rotation history.

DID Document

The did resolver takes the ethereum address, looks at contract events and builds a DID document based on the ERC1056 Events corresponding to the address. When an identifier is a full publicKey, the corresponding ethereumAddress is computed and checked in the same manner.

The minimal DID document for an ethereum address 0xb9c5714089478a327f09197987f16f9e5d936e8a with no transactions to the registry looks like this:

{
  "@context": [
    "https://www.w3.org/ns/did/v1",
    "https://w3id.org/security/suites/secp256k1recovery-2020/v2"
  ],
  "id": "did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a",
  "verificationMethod": [
    {
      "id": "did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a#controller",
      "type": "EcdsaSecp256k1RecoveryMethod2020",
      "controller": "did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a",
      "blockchainAccountId": "eip155:1:0xb9c5714089478a327f09197987f16f9e5d936e8a"
    }
  ],
  "authentication": [
    "did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a#controller"
  ],
  "assertionMethod": [
    "did:ethr:0xb9c5714089478a327f09197987f16f9e5d936e8a#controller"
  ]
}

Note this resolver uses the EcdsaSecp256k1RecoveryMethod2020 type and an blockchainAccountId to represent the default verificationMethod, assertionMethod, and authentication entry. Any value from the registry that returns an ethereum address will be added to the verificationMethod array of the DID document with type EcdsaSecp256k1RecoveryMethod2020 and an blockchainAccountId attribute containing the address.

Building a DID document

The DID document is not stored as a file, but is built by using read only functions and contract events on the ethr-did-registry Ethereum smart contract.

Please see the spec for details of how the DID document and corresponding metadata are computed.

Resolving a DID document

The library presents a resolve() function that returns a Promise returning the DID document. It is not meant to be used directly but through the did-resolver aggregator.

You can use the getResolver(config) method to produce an entry that can be used with the Resolver constructor:

import { Resolver } from 'did-resolver'
import { getResolver } from 'ethr-did-resolver'

const providerConfig = {
// While experimenting, you can set a rpc endpoint to be used by the web3 provider
  rpcUrl: 'http://localhost:7545', 
// You can also set the address for your own ethr-did-registry (ERC1056) contract
  registry: registry.address,
  name: 'development' // this becomes did:ethr:development:0x...
}
// It's recommended to use the multi-network configuration when using this in production
// since that allows you to resolve on multiple public and private networks at the same time.

// getResolver will return an object with a key/value pair of { "ethr": resolver } where resolver is a function used by the generic did resolver.
const ethrDidResolver = getResolver(providerConfig)
const didResolver = new Resolver(ethrDidResolver)

didResolver
  .resolve('did:ethr:development:0xf3beac30c498d9e26865f34fcaa57dbb935b0d74')
  .then((result) => console.dir(result, { depth: 3 }))

Multi-network configuration

In production, you will most likely want the ability to resolve DIDs that are based in different ethereum networks. To do this, you need a configuration that sets the network name or chain ID (and even the registry address) for each network. An example configuration for multi-network DID resolving would look like this:

const providerConfig = {
  networks: [
    { name: "mainnet", provider: web3.currentProvider },
    { name: "0x5", rpcUrl: "https://goerli.infura.io/v3/<YOUR PROJECT ID>" },
    { name: "rsk:testnet", chainId: "0x1f", rpcUrl: "https://did.testnet.rsk.co:4444" },
    { name: "development", rpcUrl: "http://localhost:7545", registry: "0xdca7ef03e98e0dc2b855be647c39abe984fcf21b" },
    { name: "myprivatenet", chainId: 123456, rpcUrl: "https://my.private.net.json.rpc.url" }
  ]
}

const ethrDidResolver = getResolver(providerConfig)

The configuration from above allows you to resolve ethr-did's of the following formats:

  • did:ethr:mainnet:0xabcabc03e98e0dc2b855be647c39abe984193675
  • did:ethr:0xabcabc03e98e0dc2b855be647c39abe984193675 (defaults to mainnet configuration)
  • did:ethr:0x5:0xabcabc03e98e0dc2b855be647c39abe984193675 (refer to the goerli network by chainID)
  • did:ethr:rsk:testnet:0xabcabc03e98e0dc2b855be647c39abe984193675
  • did:ethr:0x1f:0xabcabc03e98e0dc2b855be647c39abe984193675 (refer to the rsk:testnet by chainID)
  • did:ethr:development:0xabcabc03e98e0dc2b855be647c39abe984193675
  • did:ethr:myprivatenet:0xabcabc03e98e0dc2b855be647c39abe984193675
  • did:ethr:0x1e240:0xabcabc03e98e0dc2b855be647c39abe984193675 (refer to myprivatenet by chainID)

For each network you can specify either an rpcUrl, a provider or a web3 instance that can be used to access that particular network. At least one of name or chainId must be specified per network.

These providers will have to support eth_call and eth_getLogs to be able to resolve DIDs specific to that network.

You can also override the default registry address by specifying a registry attribute per network.

changelog

11.0.3 (2025-01-06)

Bug Fixes

  • deps: update dependency ethers to v6.13.5 (36f50af)

11.0.2 (2024-10-12)

Bug Fixes

  • deps: update dependency ethers to v6.13.4 (f940b8e)

11.0.1 (2024-10-01)

Bug Fixes

  • deps: update dependency ethers to v6.13.3 (840f6d4)

11.0.0 (2024-09-30)

Bug Fixes

  • add esm wrapper instead of double transpile (d2bbeaf)
  • build: build commonjs and also expose esm wrapper (522c199)
  • build: include default export to work around some bundler issues (#205) (1e9e4ef), closes #186
  • build: use commonjs module in tsconfig (e66d054)
  • ci: run tests on a matrix of node versions (3825ac0)
  • create alpha release (1d5d5f2)

Features

  • deployment: add gnosischain and holesky deployments (#206) (4992094)

BREAKING CHANGES

  • ESM is only supported through a wrapper

11.0.0-alpha.3 (2024-09-30)

Features

  • deployment: add gnosischain and holesky deployments (#206) (4992094)

11.0.0-alpha.2 (2024-09-30)

Bug Fixes

  • build: include default export to work around some bundler issues (#205) (1e9e4ef), closes #186

11.0.0-alpha.1 (2024-09-30)

Bug Fixes

  • add esm wrapper instead of double transpile (d2bbeaf)
  • build: build commonjs and also expose esm wrapper (522c199)
  • build: use commonjs module in tsconfig (e66d054)
  • ci: run tests on a matrix of node versions (3825ac0)
  • create alpha release (1d5d5f2)

BREAKING CHANGES

  • ESM is only supported through a wrapper

10.1.10 (2024-07-26)

Bug Fixes

  • deps: update dependency ethers to v6.13.2 (c9d253f)

10.1.9 (2024-06-18)

Bug Fixes

  • deps: update dependency ethers to v6.13.1 (e6885b9)

10.1.8 (2024-06-13)

Bug Fixes

  • deps: update dependency ethers to v6.13.0 (9c9d978)

10.1.7 (2024-06-13)

Bug Fixes

  • test: remove the connection test for goerli network (#201) (c861026)

10.1.6 (2024-06-13)

Bug Fixes

  • consistent Encoding of attrValue on createRevokeAttributeHash (#200) (81363d0)

10.1.5 (2024-02-14)

Bug Fixes

  • deps: update dependency ethers to v6.11.1 (d22fd46)

10.1.4 (2024-02-09)

Bug Fixes

  • deps: update dependency ethers to v6.11.0 (35620c9)

10.1.3 (2024-01-13)

Bug Fixes

  • deps: update dependency ethers to v6.10.0 (435ae92)

10.1.2 (2024-01-03)

Bug Fixes

  • deps: update dependency ethers to v6.9.2 (0e69c5b)

10.1.1 (2023-12-20)

Bug Fixes

  • deps: update dependency ethers to v6.9.1 (01e0006)

10.1.0 (2023-12-05)

Features

10.0.1 (2023-11-27)

Bug Fixes

  • deps: update dependency ethers to v6.9.0 (0ca70ec)

10.0.0 (2023-11-08)

Features

BREAKING CHANGES

  • the keys in the verificationMethod array are no longer all referenced in the assertionMethod array. Only authentication (sigAuth) or signing keys (veriKey) are added.

9.1.1 (2023-11-08)

Bug Fixes

  • deps: bump dependencies and adapt code (#193) (0a8da00)

9.1.0 (2023-11-08)

Features

  • add JSON-LD contexts that define all the terms being used (#192) (cd49ab8)

9.0.0 (2023-09-27)

Bug Fixes

BREAKING CHANGES

  • deps: this update uses ethers v6 which has a sufficiently different API from v5 that will likely need attention. While the API of this library hasn't changed, it is likely that an update will need attention so this is marked as a breaking change and a new major version is released.

8.1.2 (2023-07-13)

Bug Fixes

  • deps: update all non-major dependencies (5d1be47)

8.1.1 (2023-07-12)

Bug Fixes

  • deps: Update dependency did-resolver to v4.1.0 (ea501e1)

8.1.0 (2023-07-12)

Features

  • add linea:goerli deployment (b7a36b3)

8.0.0 (2022-11-07)

Bug Fixes

BREAKING CHANGES

  • spec: This is a breaking change of the spec as "soft deletion" of non-updated DIDs is no longer considered valid.

7.0.2 (2022-10-24)

Bug Fixes

7.0.1 (2022-10-17)

Bug Fixes

7.0.0 (2022-10-17)

Bug Fixes

  • build: transpile for commonjs, use wrapper for esm (#170) (5eba679)

BREAKING CHANGES

  • build: previous versions (<7.0.0) would be transpiled twice by microbundle, but this seems to be anti-pattern

Please raise an issue on https://github.com/decentralized-identity/ethr-did-resolver if this change is incompatible with your tech stack and there are no workarounds.

7.0.0-alpha.3 (2022-10-14)

Bug Fixes

  • build: use commonjs module in tsconfig (e66d054)
  • ci: run tests on a matrix of node versions (3825ac0)

7.0.0-alpha.2 (2022-10-14)

Bug Fixes

  • build: build commonjs and also expose esm wrapper (522c199)

7.0.0-alpha.1 (2022-10-13)

Bug Fixes

  • add esm wrapper instead of double transpile (d2bbeaf)

BREAKING CHANGES

  • ESM is only supported through a wrapper

6.2.4-alpha.1 (2022-10-13)

Bug Fixes

6.2.3 (2022-10-12)

Bug Fixes

  • e2e tests with deprecated ethr test networks (0fd9915)
  • hex values getting wrongly encoded to utf8 for setAttributeSigned (c5c8989)

6.2.2 (2022-09-07)

Bug Fixes

  • export MetaSignature type (62f250a)

6.2.1 (2022-09-06)

Bug Fixes

  • track legacy deployments, fix nonce calculation, export contract (#167) (c0d0366), closes #165 #166

6.2.0 (2022-09-05)

Features

  • add controller support for meta/signed transactions (#164) (ce93e70)

6.1.0 (2022-08-04)

Features

  • add experimental support for ServiceEndpoint objects (#163) (3919a25)

6.0.2 (2022-07-08)

Bug Fixes

  • revert aurora tweaks and use known deployments in config (#161) (e238a9f)

6.0.1 (2022-06-06)

Bug Fixes

  • ci: groom the build scripts and dependencies (#156) (9a53958)

6.0.0 (2022-06-05)

Bug Fixes

BREAKING CHANGES

  • doc: Since the context definitions most often have to be embedded in apps, this requires apps to download the new definition.
  • Apps have to update their processing of blockchainAccountId to use the new CAIP10 format

5.0.4 (2022-01-20)

Bug Fixes

  • broaden window for event logs processing (fix Aurora) (#149) (5ee6bed)

5.0.3 (2022-01-13)

Bug Fixes

  • deps: remove querystring in favor of UrlSearchParams (cd5e596)

5.0.2 (2021-11-10)

Bug Fixes

  • deps: bump ethers to ^5.5.0 (c39788a)

5.0.1 (2021-11-10)

Bug Fixes

  • deps: bump did-resolver to 3.1.3+ (0ddde4b)

5.0.0 (2021-11-10)

Bug Fixes

BREAKING CHANGES

  • publicKeyHex values in the DID document no longer contain a 0x prefix

4.3.5 (2021-11-10)

Bug Fixes

  • reference /enc/ keys in keyAgreement section of DID doc (#146) (5d507ef), closes #145

4.3.4 (2021-06-24)

Bug Fixes

  • maintenance of dependencies, bots and build scripts (#136) (0d3fcf7)

4.3.3 (2021-04-23)

Bug Fixes

4.3.2 (2021-04-22)

Bug Fixes

4.3.1 (2021-04-22)

Bug Fixes

  • ignore query string when interpreting identifiers (#123) (5508f8a), closes #122

4.3.0 (2021-04-20)

Features

4.2.0 (2021-04-16)

Features

4.1.0 (2021-04-14)

Features

  • export EthrDidController helper class (#120) (745100d)

4.0.1 (2021-03-26)

Bug Fixes

  • deps: use Resolvable type from did-resolver (d213ae6)

4.0.0 (2021-03-15)

Features

BREAKING CHANGES

  • The return type is DIDResolutionResult which wraps a DIDDocument.
  • No errors are thrown during DID resolution. Please check result.didResolutionMetadata.error instead.
  • This DID core spec requirement will break for users expecting publicKey, ethereumAddress, Secp256k1VerificationKey2018 entries in the DID document. They are replaced with verificationMethod, blockchainAccountId and EcdsaSecp256k1VerificationKey2019 and EcdsaSecp256k1RecoveryMethod2020 depending on the content.

3.1.0 (2021-03-15)

Features

3.0.3 (2020-12-17)

Bug Fixes

3.0.2 (2020-12-09)

Bug Fixes

  • deps: update dependency did-resolver to v2.1.2 (8c2294e)

3.0.1 (2020-11-09)

Bug Fixes

3.0.0 (2020-08-24)

Bug Fixes

  • change 'owner' to 'controller' to follow W3C Spec (#75) (#81) (af37b3f)

BREAKING CHANGES

  • JWTs that refer to the did:ethr:...#owner key in their header may be considered invalid after this upgrade, as the key id is now did:ethr:...#controller

2.4.0 (2020-08-21)

Features

  • add ability to use a compressed publicKey as identifier (#73) (e257eb3), closes #56

2.3.4 (2020-08-19)

Bug Fixes

  • deps: update dependency did-resolver to v2.1.1 (1a4cbca)

2.3.3 (2020-08-14)

Bug Fixes

  • deps: update dependency did-resolver to v2.1.0 (b26d387)

2.3.2 (2020-07-07)

Bug Fixes

  • deps: update dependency did-resolver to v2 (#68) (831ec17)

2.3.1 (2020-07-04)

Bug Fixes

  • deps: update dependency ethjs-contract to ^0.2.0 (b667ce6)

2.3.0 (2020-07-03)

Bug Fixes

  • deps: update dependency did-resolver to v1.1.0 (ab47058)

Features

  • add encryption key support for ethr-did-documents (2f5825c), closes #52

2.2.0 (2020-02-25)

Features

  • add encryption key support for ethr-did-documents (dff7b0f), closes #52

2.1.0 (2020-02-10)

Features

  • Add types declaration stubb (05944b1)

2.0.0 (2020-01-24)

Bug Fixes

  • require a configuration to be used when initializing the resolver (3adc029)

BREAKING CHANGES

  • this removes the fallback hardcoded RPC URLs and will fail early when a wrong configuration (or none) is provided to getResolver()

1.0.3 (2019-11-11)

Bug Fixes

  • remove ejs module distribution (780ec08), closes #39