|
@ -81,55 +81,6 @@ describe('ecdsa', function () { |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
describe('recoverPubKey', function () { |
|
|
|
|
|
fixtures.valid.ecdsa.forEach(function (f) { |
|
|
|
|
|
it('recovers the pubKey for ' + f.d, function () { |
|
|
|
|
|
var d = BigInteger.fromHex(f.d) |
|
|
|
|
|
var Q = curve.G.multiply(d) |
|
|
|
|
|
var signature = ECSignature.fromDER(new Buffer(f.signature, 'hex')) |
|
|
|
|
|
var h1 = bcrypto.sha256(f.message) |
|
|
|
|
|
var e = BigInteger.fromBuffer(h1) |
|
|
|
|
|
var Qprime = ecdsa.recoverPubKey(e, signature, f.i) |
|
|
|
|
|
|
|
|
|
|
|
assert(Qprime.equals(Q)) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('with i ∈ {0,1,2,3}', function () { |
|
|
|
|
|
var hash = new Buffer('feef89995d7575f12d65ccc9d28ccaf7ab224c2e59dad4cc7f6a2b0708d24696', 'hex') |
|
|
|
|
|
var e = BigInteger.fromBuffer(hash) |
|
|
|
|
|
|
|
|
|
|
|
var signatureBuffer = new Buffer('INcvXVVEFyIfHLbDX+xoxlKFn3Wzj9g0UbhObXdMq+YMKC252o5RHFr0/cKdQe1WsBLUBi4morhgZ77obDJVuV0=', 'base64') |
|
|
|
|
|
var signature = ECSignature.parseCompact(signatureBuffer).signature |
|
|
|
|
|
var points = [ |
|
|
|
|
|
'03e3a8c44a8bf712f1fbacee274fb19c0239b1a9e877eff0075ea335f2be8ff380', |
|
|
|
|
|
'0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798', |
|
|
|
|
|
'03d49e765f0bc27525c51a1b98fb1c99dacd59abe85a203af90f758260550b56c5', |
|
|
|
|
|
'027eea09d46ac7fb6aa2e96f9c576677214ffdc238eb167734a9b39d1eb4c3d30d' |
|
|
|
|
|
] |
|
|
|
|
|
|
|
|
|
|
|
points.forEach(function (expectedHex, i) { |
|
|
|
|
|
it('recovers an expected point for i of ' + i, function () { |
|
|
|
|
|
var Qprime = ecdsa.recoverPubKey(e, signature, i) |
|
|
|
|
|
var QprimeHex = Qprime.getEncoded().toString('hex') |
|
|
|
|
|
|
|
|
|
|
|
assert.strictEqual(QprimeHex, expectedHex) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
fixtures.invalid.recoverPubKey.forEach(function (f) { |
|
|
|
|
|
it('throws on ' + f.description + ' (' + f.exception + ')', function () { |
|
|
|
|
|
var e = BigInteger.fromHex(f.e) |
|
|
|
|
|
var signature = new ECSignature(new BigInteger(f.signatureRaw.r, 16), new BigInteger(f.signatureRaw.s, 16)) |
|
|
|
|
|
|
|
|
|
|
|
assert.throws(function () { |
|
|
|
|
|
ecdsa.recoverPubKey(e, signature, f.i) |
|
|
|
|
|
}, new RegExp(f.exception)) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
describe('sign', function () { |
|
|
describe('sign', function () { |
|
|
fixtures.valid.ecdsa.forEach(function (f) { |
|
|
fixtures.valid.ecdsa.forEach(function (f) { |
|
|
it('produces a deterministic signature for "' + f.message + '"', function () { |
|
|
it('produces a deterministic signature for "' + f.message + '"', function () { |
|
|