From f42993297cf5bf6e6923ea19b0188f45bb6d5b35 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 16 Jun 2014 01:36:05 +1000 Subject: [PATCH] ecurve: upgrade to 0.9.0 --- package.json | 2 +- src/ecdsa.js | 14 +++++++------- src/eckey.js | 6 +++--- src/hdnode.js | 6 +++--- test/ecdsa.js | 8 ++++---- test/hdnode.js | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/package.json b/package.json index a63fdf2..12900bc 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ "dependencies": { "bigi": "1.1.0", "crypto-js": "3.1.2-3", - "ecurve": "0.7.0", + "ecurve": "0.9.0", "secure-random": "0.2.1" } } diff --git a/src/ecdsa.js b/src/ecdsa.js index e9769ba..60fe624 100644 --- a/src/ecdsa.js +++ b/src/ecdsa.js @@ -23,7 +23,7 @@ function deterministicGenerateK(curve, hash, d) { v = crypto.HmacSHA256(v, k) v = crypto.HmacSHA256(v, k) - var n = curve.params.n + var n = curve.n var kB = BigInteger.fromBuffer(v).mod(n) assert(kB.compareTo(BigInteger.ONE) > 0, 'Invalid k value') assert(kB.compareTo(n) < 0, 'Invalid k value') @@ -34,8 +34,8 @@ function deterministicGenerateK(curve, hash, d) { function sign(curve, hash, d) { var k = deterministicGenerateK(curve, hash, d) - var n = curve.params.n - var G = curve.params.G + var n = curve.n + var G = curve.G var Q = G.multiply(k) var e = BigInteger.fromBuffer(hash) @@ -62,8 +62,8 @@ function verify(curve, hash, signature, Q) { } function verifyRaw(curve, e, signature, Q) { - var n = curve.params.n - var G = curve.params.G + var n = curve.n + var G = curve.G var r = signature.r var s = signature.s @@ -104,8 +104,8 @@ function recoverPubKey(curve, e, signature, i) { // first or second candidate key. var isSecondKey = i >> 1 - var n = curve.params.n - var G = curve.params.G + var n = curve.n + var G = curve.G var p = curve.p var a = curve.a var b = curve.b diff --git a/src/eckey.js b/src/eckey.js index 166da09..c0a6a77 100644 --- a/src/eckey.js +++ b/src/eckey.js @@ -12,9 +12,9 @@ var curve = ecurve.getCurveByName('secp256k1') function ECKey(d, compressed) { assert(d.signum() > 0, 'Private key must be greater than 0') - assert(d.compareTo(curve.params.n) < 0, 'Private key must be less than the curve order') + assert(d.compareTo(curve.n) < 0, 'Private key must be less than the curve order') - var Q = curve.params.G.multiply(d) + var Q = curve.G.multiply(d) this.d = d this.pub = new ECPubKey(Q, compressed) @@ -47,7 +47,7 @@ ECKey.makeRandom = function(compressed, rng) { var buffer = new Buffer(rng(32)) var d = BigInteger.fromBuffer(buffer) - d = d.mod(curve.params.n) + d = d.mod(curve.n) return new ECKey(d, compressed) } diff --git a/src/hdnode.js b/src/hdnode.js index d36fe31..57d6dfa 100644 --- a/src/hdnode.js +++ b/src/hdnode.js @@ -222,7 +222,7 @@ HDNode.prototype.derive = function(index) { var pIL = BigInteger.fromBuffer(IL) // In case parse256(IL) >= n, proceed with the next value for i - if (pIL.compareTo(curve.params.n) >= 0) { + if (pIL.compareTo(curve.n) >= 0) { return this.derive(index + 1) } @@ -230,7 +230,7 @@ HDNode.prototype.derive = function(index) { var hd if (this.privKey) { // ki = parse256(IL) + kpar (mod n) - var ki = pIL.add(this.privKey.d).mod(curve.params.n) + var ki = pIL.add(this.privKey.d).mod(curve.n) // In case ki == 0, proceed with the next value for i if (ki.signum() === 0) { @@ -243,7 +243,7 @@ HDNode.prototype.derive = function(index) { } else { // Ki = point(parse256(IL)) + Kpar // = G*IL + Kpar - var Ki = curve.params.G.multiply(pIL).add(this.pubKey.Q) + var Ki = curve.G.multiply(pIL).add(this.pubKey.Q) // In case Ki is the point at infinity, proceed with the next value for i if (curve.isInfinity(Ki)) { diff --git a/test/ecdsa.js b/test/ecdsa.js index d5a7d0d..84ec699 100644 --- a/test/ecdsa.js +++ b/test/ecdsa.js @@ -29,7 +29,7 @@ describe('ecdsa', function() { fixtures.valid.forEach(function(f) { it('recovers the pubKey for ' + f.d, function() { var d = BigInteger.fromHex(f.d) - var Q = curve.params.G.multiply(d) + var Q = curve.G.multiply(d) var signature = { r: new BigInteger(f.signature.r), s: new BigInteger(f.signature.s) @@ -94,7 +94,7 @@ describe('ecdsa', function() { var sig = ecdsa.sign(curve, hash, BigInteger.ONE) // See BIP62 for more information - var N_OVER_TWO = curve.params.n.shiftRight(1) + var N_OVER_TWO = curve.n.shiftRight(1) assert(sig.s.compareTo(N_OVER_TWO) <= 0) }) }) @@ -108,7 +108,7 @@ describe('ecdsa', function() { new BigInteger(f.signature.r), new BigInteger(f.signature.s) ) - var Q = curve.params.G.multiply(d) + var Q = curve.G.multiply(d) assert(ecdsa.verifyRaw(curve, e, signature, Q)) }) @@ -122,7 +122,7 @@ describe('ecdsa', function() { new BigInteger(f.signature.r), new BigInteger(f.signature.s) ) - var Q = curve.params.G.multiply(d) + var Q = curve.G.multiply(d) assert.equal(ecdsa.verifyRaw(curve, e, signature, Q), false) }) diff --git a/test/hdnode.js b/test/hdnode.js index fb9a29f..d146d41 100644 --- a/test/hdnode.js +++ b/test/hdnode.js @@ -12,7 +12,7 @@ var fixtures = require('./fixtures/hdnode.json') describe('HDNode', function() { describe('Constructor', function() { var d = BigInteger.ONE - var Q = curve.params.G.multiply(d) + var Q = curve.G.multiply(d) var chainCode = new Buffer(32) chainCode.fill(1)