How to verify signature after signMessage()? #27
-
Hi, this library has been great to connect a wallet and sign a message using the provided hooks. However, once I receive back a signed message I need to verify it. I cannot find any typescript examples on how to accomplish the verification that signature matches the expected address and message payload. For example, I have this callback to run after user provides signature. How would I go about validating the signature? I will want to verify also on a backend server once it is sent there.
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 8 replies
-
Hi @qrtp, typically you would send a request with that signature and key in a post body to your backend to check there if the public key (stake address) owner really signed that message. If you want to run your backend based on typescript/javascript I would suggest the cardano-serialization-lib to fulfill that task. Here is an stackexchange question+answer that shows it's usage. I think you need to adjust this solution a little bit, because the old nami wallet api held the key in the header part of the encoded signature. So you don't need to extract the key from the header anymore because since cip30 the key and signature is provided separately. Please let me know if this solution works for you. 😊 |
Beta Was this translation helpful? Give feedback.
-
Hey @qrtp, please checkout this solution. It's based on the @stricahq libs. They wrote really cool libraries (so many kudos to you if you read this guys!). I just committed the code with my account but tomorrow I will transfer it into the cardano-foundation namespace and also add the build pipeline (so there is no npm public package now but you can still copy the code snippet if it's urgent) 😊 |
Beta Was this translation helpful? Give feedback.
-
With the lastest release (1.0.4) of cardano-verify-datasignature you can just use: const verifyDataSignature = require('@cardano-foundation/cardano-verify-datasignature');
const key = '...';
const signature = '...';
const message = 'plain message or undefined';
const address = 'addr1qxytm5f2y5x2yjw3fx60musegxxcvst8m8ck7lv0l0mfd4t8uh26h6gx5mzrjhs59kc03d8h5ga9a6ul4ptvve566vssmff09g';
console.log(verifyDataSignature(signature, key, message, address)); Have a nice day and please contact me again if you have any question 😊 |
Beta Was this translation helpful? Give feedback.
With the lastest release (1.0.4) of cardano-verify-datasignature you can just use:
Have a nice day and please contact me again if you have any question 😊