ec: fix ecdh with secp256k1-node.
This commit is contained in:
parent
19f61773f7
commit
530fbd61dd
@ -10,7 +10,7 @@
|
||||
var elliptic = require('elliptic');
|
||||
var bn = require('bn.js');
|
||||
var utils = require('../utils/utils');
|
||||
var random = require('./random');
|
||||
var crypto = require('./crypto');
|
||||
var assert = utils.assert;
|
||||
var secp256k1;
|
||||
|
||||
@ -67,7 +67,7 @@ ec.generatePrivateKey = function generatePrivateKey() {
|
||||
|
||||
if (secp256k1) {
|
||||
do {
|
||||
priv = random.randomBytes(32);
|
||||
priv = crypto.randomBytes(32);
|
||||
} while (!secp256k1.privateKeyVerify(priv));
|
||||
} else {
|
||||
key = ec.elliptic.genKeyPair();
|
||||
@ -169,8 +169,13 @@ ec.publicKeyTweakAdd = function publicKeyTweakAdd(publicKey, tweak, compressed)
|
||||
*/
|
||||
|
||||
ec.ecdh = function ecdh(pub, priv) {
|
||||
if (secp256k1)
|
||||
return secp256k1.ecdh(pub, priv);
|
||||
var point;
|
||||
|
||||
if (secp256k1) {
|
||||
point = secp256k1.ecdhUnsafe(pub, priv, true);
|
||||
point = ec.curve.decodePoint(point);
|
||||
return point.getX().toArrayLike(Buffer, 'be', 32);
|
||||
}
|
||||
|
||||
priv = ec.elliptic.keyPair({ priv: priv });
|
||||
pub = ec.elliptic.keyPair({ pub: pub });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user