decentralized-identity / did-jwt

Create and verify DID verifiable JWT's in Javascript
Apache License 2.0
331 stars 70 forks source link

[BUG] Error: resolver_error: Unable to resolve DID document for did:ethr:ethr:0x539:...: unknownNetwork, The DID resolver does not have a configuration for network: ethr:0x539 #276

Closed francesco-plt closed 1 year ago

francesco-plt commented 1 year ago

Note: this error happens when I use the did-jwt-vc library, but since the error itself happens inside the did-jwt library I opened the same issue in both repositories. I am trying to issue and verify VCs using EthrDID objects and did-jwt-vc library to sign and verify. I have create an issuer and a sub object as follows:

const issuer = new EthrDID({
    identifier: issuerAddress,
    privateKey: issuerPrivateKey,
    chainNameOrId: "0x539",
});

const sub = new EthrDID({
    identifier: subAddress,
    privateKey: subPrivateKey,
    chainNameOrId: "0x539",
});

The chain ID is 0x539 because I am deploying a local network with hardhat. Then I issue a VC:

const vcPayload: JwtCredentialPayload = {
  sub: sub.did,
  nbf: 1562950282,
  vc: {
    '@context': ['https://www.w3.org/2018/credentials/v1'],
    type: ['VerifiableCredential'],
    credentialSubject: {
      degree: {
        type: 'BachelorDegree',
        name: 'Baccalauréat en musiques numériques'
      }
    }
  }
}

const vcJwt = await createVerifiableCredentialJwt(vcPayload, issuer)
console.log(vcJwt)

And I verify it:

const providerConfig = {
    "networks": [{
      name: '0x539',
      chainId: 0x539,
      rpcUrl: 'http://127.0.0.1:8545',
      registry: contractAddress  // address printed by hardhat when I deployed EthereumDIDRegistry.sol
    }]
  }
const resolver = new Resolver(getResolver(providerConfig))
const verifiedVC = await verifyCredential(vcJwt, resolver)

Current Behavior

The library crashes with error:

Error: resolver_error: Unable to resolve DID document for did:ethr:ethr:0x539:...: unknownNetwork, The DID resolver does not have a configuration for network: ethr:0x539
    at node_modules/did-jwt-vc/node_modules/did-jwt/lib/index.module.js:885:15

Expected Behavior

The verification function should go ahead and perform the verification without issues. The error related to the resolution of the DID document makes no sense because the resolver is able to correctly resolve the DID and retrieve the document. If I run the following:

const providerConfig = {
    "networks": [{
      name: '0x539',
      chainId: 0x539,
      rpcUrl: 'http://127.0.0.1:8545',
      registry: contractAddress  // address printed by hardhat when I deployed EthereumDIDRegistry.sol
    }]
  }
const issuerDid = "did:ethr:0x539:..."
const resolver = new Resolver(getResolver(providerConfig))

const issuerDoc = await didResolver.resolve(issuerDid)

The document is retrieved correctly. Moreover, if I break at the line specified by the error, and I modify the calling funcion inside did-jwt/lib/index.module.js at resolveAuthenticator as follows:

const resolveAuthenticator = function (resolver, alg, issuer, proofPurpose) {
  // custom code to test resolver behaviour
  let result;
  resolver.resolve("did:ethr:0x539:...").then((data) => {
    result = data;
    console.log(JSON.stringify(result));
  }).catch((error) => {
    console.error(error);
  });
  // actual code of the function

The correct document is printed in the console. I suspect that this is a bug in the library.

Failure Information

I am using those versions of the libraries:

"ethers": "5.7.x",
"ethr-did": "^2.3.6",
"did-jwt-vc": "^3.1.2",
"ethr-did-resolver": "8.0.0"
mirceanis commented 1 year ago

Try to use 1337 instead of "0x539" for chainId in your providerConfig:

const providerConfig = {
    "networks": [{
      name: '0x539',
      chainId: 1337,
      rpcUrl: 'http://127.0.0.1:8545',
      registry: contractAddress  // address printed by hardhat when I deployed EthereumDIDRegistry.sol
    }]
  }

const issuerDid = "did:ethr:0x539:..."
const resolver = new Resolver(getResolver(providerConfig))

const issuerDoc = await didResolver.resolve(issuerDid)
francesco-plt commented 1 year ago

Try to use 1337 instead of "0x539" for chainId in your providerConfig:

const providerConfig = {
    "networks": [{
      name: '0x539',
      chainId: 1337,
      rpcUrl: 'http://127.0.0.1:8545',
      registry: contractAddress  // address printed by hardhat when I deployed EthereumDIDRegistry.sol
    }]
  }

const issuerDid = "did:ethr:0x539:..."
const resolver = new Resolver(getResolver(providerConfig))

const issuerDoc = await didResolver.resolve(issuerDid)

I get the same error. From the issue message:

Expected Behavior

The verification function should go ahead and perform the verification without issues. The error related to the resolution of the DID document makes no sense because the resolver is able to correctly resolve the DID and retrieve the document. If I run the following:

const providerConfig = {
    "networks": [{
      name: '0x539',
      chainId: 0x539,
      rpcUrl: 'http://127.0.0.1:8545',
      registry: contractAddress  // address printed by hardhat when I deployed EthereumDIDRegistry.sol
    }]
  }
const issuerDid = "did:ethr:0x539:..."
const resolver = new Resolver(getResolver(providerConfig))

const issuerDoc = await didResolver.resolve(issuerDid)

The document is retrieved correctly. Moreover, if I break at the line specified by the error, and I modify the calling funcion inside did-jwt/lib/index.module.js at resolveAuthenticator as follows:

const resolveAuthenticator = function (resolver, alg, issuer, proofPurpose) {
  // custom code to test resolver behaviour
  let result;
  resolver.resolve("did:ethr:0x539:...").then((data) => {
    result = data;
    console.log(JSON.stringify(result));
  }).catch((error) => {
    console.error(error);
  });
  // actual code of the function

The correct document is printed in the console. I suspect that this is a bug in the library.

The actual line in the library is the following one: https://github.com/decentralized-identity/did-jwt/blob/d898aa613a856cc7d3b2f2cc70ce4d8452b4e667/src/JWT.ts#L440

mirceanis commented 1 year ago

The error you posted is coming from ethr-did-resolver.

If the document is printed it means it was already resolved by the ethr-did-resolver so if you're getting the same error it means that your new configuration is not the one throwing the error.

Please rebuild your project.

francesco-plt commented 1 year ago

The error you posted is coming from ethr-did-resolver.

If the document is printed it means it was already resolved by the ethr-did-resolver so if you're getting the same error it means that your new configuration is not the one throwing the error.

Please rebuild your project.

I can confirm that by rebuilding and switching library versions I got it to verify succesfully without verification issues.