uport-project / ethr-did

Create ethr DIDs
Apache License 2.0
259 stars 53 forks source link

(node:6329) UnhandledPromiseRejectionWarning: Error: Unsupported DID method: 'ethr' #33

Closed hsnhrn closed 5 years ago

hsnhrn commented 5 years ago

Describe the bug I am trying to verify the the JWT both with ethr-did and did-jwt but it is giving me an error about the Error: Unsupported DID method: 'ethr'.

I created the signer of my private key by

const didJWT = require('did-jwt') const signer = didJWT.SimpleSigner('fa09a3ff0d486be2eb69545c393e2cf47cb53feb44a3550199346bdfa6f53245');

and then created and decoded the JWT succesfully.

But it gaves me an error on verify method

Project link

https://github.com/hsnhrn/did

mirceanis commented 5 years ago

can please you post a gist or a project that is showing the error?

hsnhrn commented 5 years ago

can please you post a gist or a project that is showing the error?

https://github.com/hsnhrn/did

mirceanis commented 5 years ago

That project is showing a different error. I'm not able to understand what is the intent.

From what I can make of it, it looks like you are trying to add a signing delegate to a contract deployed to a local network at address 0xaa645fc3b17d9ee157f1f934b2cd800e55c172f5 For that to happen, you need to have the local network running and for the registry contract to have already been deployed at that address.

Note that creating a signing delegate for an ethr-did means that a keypair is created locally and then the registry contract is called to add that new key as a delegate.

Please cleanup that project to the bare minimum of what you intend to achieve and have it show the error that is blocking you. Otherwise, I can't help because I don't understand your blocker.

hsnhrn commented 5 years ago

Hi i cleaned the project and added some comments in it. Yes you are right i am using registry deployed in my own local network. Creating a signing delegate is working fine and i can see the transaction hash on my local network. I am only having problem in verifying the JWT after signing it. Signing the JWT also works fine. so here is the output i am logging in the console and the error below.. { kp: { address: '0x59f515285081931ebd1fb3ba7a0b9e35e926d84e', privateKey: '85407ecdd20a14b1f7d2e345fb93a56366a5cc37a2db07ced33b2eb8015edefb' }, txHash: '0x673d66c8f2d6e2afc4833eedd09a66b3293e5a31696c2bd56f1f4eafe0a29d69' } signed JWT:eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzI1NkstUiJ9.eyJpYXQiOjE1NjY5ODc5MDgsImhlbGxvIjoid29ybGQiLCJpc3MiOiJkaWQ6ZXRocjoweDI5RjQwMjQxMDI4N0U4MjBlRjIxRUQ2M2Q0MzFmMGNFMGI4RWIzMTQifQ.fPojiPfl3mvGdH979ivr7PpI6RygST_ZMa6xpDomaO2p97g8atFR6JzlmDNSMnPssgnNZRW1m5oZ4DoNKrl1_gA undefined (node:15341) UnhandledPromiseRejectionWarning: Error: Unsupported DID method: 'ethr' at /home/ubuntu/did_test/node_modules/did-jwt/node_modules/did-resolver/lib/resolver.js:87:31 at step (/home/ubuntu/did_test/node_modules/did-jwt/node_modules/did-resolver/lib/resolver.js:32:23) at Object.next (/home/ubuntu/did_test/node_modules/did-jwt/node_modules/did-resolver/lib/resolver.js:13:53) at /home/ubuntu/did_test/node_modules/did-jwt/node_modules/did-resolver/lib/resolver.js:7:71 at new Promise () at __awaiter (/home/ubuntu/did_test/node_modules/did-jwt/node_modules/did-resolver/lib/resolver.js:3:12) at resolve (/home/ubuntu/did_test/node_modules/did-jwt/node_modules/did-resolver/lib/resolver.js:77:12) at _callee3$ (/home/ubuntu/did_test/node_modules/did-jwt/lib/JWT.js:373:45) at tryCatch (/home/ubuntu/did_test/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:45:40) at Generator.invoke [as _invoke] (/home/ubuntu/did_test/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:271:22) at Generator.prototype.(anonymous function) [as next] (/home/ubuntu/did_test/node_modules/@babel/runtime/node_modules/regenerator-runtime/runtime.js:97:21) at asyncGeneratorStep (/home/ubuntu/did_test/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24) at _next (/home/ubuntu/did_test/node_modules/@babel/runtime/helpers/asyncToGenerator.js:25:9) at /home/ubuntu/did_test/node_modules/@babel/runtime/helpers/asyncToGenerator.js:32:7 at new Promise () at /home/ubuntu/did_test/node_modules/@babel/runtime/helpers/asyncToGenerator.js:21:12 (node:15341) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2) (node:15341) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

mirceanis commented 5 years ago

ok, I see. By default, did-jwt has no resolvers registered. They need to be added.

NOTE the registry contract may not work correctly with ganache if that is indeed your local network, so you may end up with "Invalid signature for JWT" errors when you try to verify.

hsnhrn commented 5 years ago

Hi @mirceanis , Thanks alot for your help.

I am using this Ethereum Volta network. https://volta-explorer.energyweb.org

And i am having the same error now you mentioned above. "Signature invalid for JWT" Is there any specific reason for that error? Will it be solved at Volta Network end? Should i ask them about it?

Thanks a lot!

mirceanis commented 5 years ago

I'm not sure yet why this is failing. The ethr-did-registry relies on transaction logs to build a DID document containing the delegate keys. I'm not familiar with the Volta network, but from what I'm seeing in ganache it appears this mechanism is not compatible. It needs a connection to a node that can answer with transaction logs.

Note that if you don't necessarily require key delegation you can use a SimpleSigner with the private key directly.

mirceanis commented 5 years ago

I'll close this since the original error was solved. Please open a new issue if you get stuck on something else.

m-yahya commented 5 years ago

the Signature invalid for JWT can be fixed by using registerResolver({provider : provider, registry:registryAddress})

mirceanis commented 5 years ago

Ah, yes. I missed the registry address config. Thank you for pointing it out. Even so, it still doesn't work for me in ganache 2.1.0

@hsnhrn can you please check that with your Volta network configuration?

hsnhrn commented 5 years ago

No, its still the same error