Search code examples
javascriptnode.jscryptographysignecdsa

Cannot sign with ecdsa module in node js


I am trying to use the ecdsa module to sign some data with a crypto ecdh private key. My code is below:

shaMsg = crypto.createHash('sha256').update(myData).digest();
signed = ecdsa.sign(shaMsg, myECDHKey);

I am facing the following problem:

ERROR: Server - Caught exception: Error: Expected property "1" of type BigInteger, got Buffer

Can anyone help me?


Solution

  • As I did not receive any answer, I tried with other modules and get what I wanted with the elliptic module:

    var EC = require("elliptic").ec;
    var ec = new EC("secp256k1");
    
    var shaMsg = crypto.createHash("sha256").update(myData.toString()).digest();
    var mySign = ec.sign(shaMsg, privateKey, {canonical: true});
    

    I hope it can help someone else.