Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to verify signed message by public key #1

Open
bafu opened this issue Dec 10, 2019 · 1 comment
Open

How to verify signed message by public key #1

bafu opened this issue Dec 10, 2019 · 1 comment

Comments

@bafu
Copy link

bafu commented Dec 10, 2019

Hi Zion dev team,

I use zkma.signMessage (with Ethereum type) to sign the raw message and want to use a public key (e.g., from zkma.{getSendPublicKey, getReceivePublicKey}) to verify the signature of the signed message [1, 2].

How can I do verification with Zion SDK?

The idea is to leverage Zion as a tool to generate secure HW signatures of any small data (texts, images, etc.), like using the traditional GPG tool with a higher security level.

Any suggestion is welcome!


References

  1. Signing a message by Zion VaultSDK
  2. Signing a message by ZKMA
  3. EIP191
@htczion
Copy link
Owner

htczion commented Dec 11, 2019

Zion SDK doesn't provide any verify message method on it,

Refer to the below sample code (written in Node JS and use 3rd library 'eth-sig-util'), the original message and the output of signed message is required for the function "recoverPersonalSignature",

if the funciton result is equal to your eth address, it means verify success.

const sigUtil = require('eth-sig-util');
app.post('/eth_verifymsg', function (req, res) {
    console.log(JSON.stringify(req.body));
 
    const address = req.body.addr;
    const message = req.body.message;
    const msgParams = { data: message }
    msgParams.sig = req.body.signed;
    const recovered = sigUtil.recoverPersonalSignature(msgParams);
 
    var object = new Object();
    object.verified = (recovered == address.toLowerCase()); 
    res.writeHeader(200, { "Content-Type": "application/json" });
    res.write(JSON.stringify(object));
    res.end();
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants