|
|
@ -17,10 +17,10 @@ describe('ecdsa', function() { |
|
|
|
describe('deterministicGenerateK', function() { |
|
|
|
it('matches the test vectors', function() { |
|
|
|
fixtures.valid.forEach(function(f) { |
|
|
|
var priv = BigInteger.fromHex(f.D) |
|
|
|
var D = BigInteger.fromHex(f.D) |
|
|
|
var h1 = crypto.sha256(f.message) |
|
|
|
|
|
|
|
var k = ecdsa.deterministicGenerateK(h1, priv) |
|
|
|
var k = ecdsa.deterministicGenerateK(h1, D) |
|
|
|
assert.equal(k.toHex(), f.k) |
|
|
|
}) |
|
|
|
}) |
|
|
@ -28,15 +28,16 @@ describe('ecdsa', function() { |
|
|
|
|
|
|
|
describe('recoverPubKey', function() { |
|
|
|
it('succesfully recovers a public key', function() { |
|
|
|
var signature = new Buffer('H0PG6+PUo96UPTJ/DVj8aBU5it+Nuli4YdsLuTMvfJxoHH9Jb7jYTQXCCOX2jrTChD5S1ic3vCrUQHdmB5/sEQY=', 'base64') |
|
|
|
var D = BigInteger.ONE |
|
|
|
var signature = new Buffer('INcvXVVEFyIfHLbDX+xoxlKFn3Wzj9g0UbhObXdMq+YMKC252o5RHFr0/cKdQe1WsBLUBi4morhgZ77obDJVuV0=', 'base64') |
|
|
|
|
|
|
|
var obj = ecdsa.parseSigCompact(signature) |
|
|
|
var Q = ecparams.getG().multiply(D) |
|
|
|
var hash = message.magicHash('1111', networks.bitcoin) |
|
|
|
var e = BigInteger.fromBuffer(hash) |
|
|
|
var psig = ecdsa.parseSigCompact(signature) |
|
|
|
|
|
|
|
var pubKey = new ECPubKey(ecdsa.recoverPubKey(e, obj.r, obj.s, obj.i)) |
|
|
|
|
|
|
|
assert.equal(pubKey.toHex(), '02e8fcf4d749b35879bc1f3b14b49e67ab7301da3558c5a9b74a54f1e6339c334c') |
|
|
|
var Qprime = ecdsa.recoverPubKey(e, psig.r, psig.s, psig.i) |
|
|
|
assert(Q.equals(Qprime)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
@ -44,9 +45,8 @@ describe('ecdsa', function() { |
|
|
|
it('matches the test vectors', function() { |
|
|
|
fixtures.valid.forEach(function(f) { |
|
|
|
var D = BigInteger.fromHex(f.D) |
|
|
|
var priv = new ECKey(D) |
|
|
|
var hash = crypto.sha256(f.message) |
|
|
|
var sig = priv.sign(hash) |
|
|
|
var sig = ecdsa.sign(hash, D) |
|
|
|
|
|
|
|
assert.equal(sig.r.toString(), f.signature.r) |
|
|
|
assert.equal(sig.s.toString(), f.signature.s) |
|
|
@ -54,9 +54,8 @@ describe('ecdsa', function() { |
|
|
|
}) |
|
|
|
|
|
|
|
it('should sign with low S value', function() { |
|
|
|
var priv = ECKey.makeRandom() |
|
|
|
var hash = crypto.sha256('Vires in numeris') |
|
|
|
var sig = priv.sign(hash) |
|
|
|
var sig = ecdsa.sign(hash, BigInteger.ONE) |
|
|
|
|
|
|
|
// See BIP62 for more information
|
|
|
|
var N_OVER_TWO = ecparams.getN().shiftRight(1) |
|
|
@ -68,13 +67,13 @@ describe('ecdsa', function() { |
|
|
|
it('matches the test vectors', function() { |
|
|
|
fixtures.valid.forEach(function(f) { |
|
|
|
var D = BigInteger.fromHex(f.D) |
|
|
|
var priv = new ECKey(D) |
|
|
|
var Q = ecparams.getG().multiply(D) |
|
|
|
|
|
|
|
var r = new BigInteger(f.signature.r) |
|
|
|
var s = new BigInteger(f.signature.s) |
|
|
|
var e = BigInteger.fromBuffer(crypto.sha256(f.message)) |
|
|
|
|
|
|
|
assert(ecdsa.verifyRaw(e, r, s, priv.pub.Q)) |
|
|
|
assert(ecdsa.verifyRaw(e, r, s, Q)) |
|
|
|
}) |
|
|
|
}) |
|
|
|
}) |
|
|
|