ecdsa: add serializeSigCompact and tests

This also adds tests for all other ECDSA serialize/parsing functions.
The k, r, s and D values were sourced from test vectors on
https://bitcointalk.org/index.php?topic=285142.40 .

The compact signatures (aka, i values) were generated from bitcoinjslib, but they
are straight forward anyway.
This commit is contained in:
Daniel Cousens 2014-05-16 23:11:04 +10:00
parent b208a6ab78
commit 4c7108d561
3 changed files with 233 additions and 58 deletions

View file

@ -204,6 +204,21 @@ var ecdsa = {
return {r: r, s: s}
},
serializeSigCompact: function(r, s, i, compressed) {
if (compressed) {
i += 4
}
i += 27
var buffer = new Buffer(65)
buffer.writeUInt8(i, 0)
r.toBuffer(32).copy(buffer, 1)
s.toBuffer(32).copy(buffer, 33)
return buffer
},
parseSigCompact: function (sig) {
if (sig.length !== 65) {
throw new Error("Signature has the wrong length")