Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 914
Dalton Cézane Avatar asked Oct 17 '25 06:10

Dalton Cézane


2 Answers

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.

like image 108
Dalton Cézane Avatar answered Oct 18 '25 21:10

Dalton Cézane


I got it working with:

var BigInteger = require('bigi');
var signature = ecdsa.sign(shaMsg, BigInteger.fromBuffer(privateKey));

But couldn´t verify with publicKey of type Buffer it expects Point.

like image 45
Fabio Avatar answered Oct 18 '25 20:10

Fabio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!