|
|
@ -1,6 +1,9 @@ |
|
|
|
var BN = require('../lib/bn'); |
|
|
|
'use strict'; |
|
|
|
|
|
|
|
var should = require('chai').should(); |
|
|
|
var Signature = require('../lib/signature'); |
|
|
|
var bitcore = require('..'); |
|
|
|
var BN = bitcore.BN; |
|
|
|
var Signature = bitcore.Signature; |
|
|
|
|
|
|
|
describe('Signature', function() { |
|
|
|
|
|
|
@ -19,15 +22,17 @@ describe('Signature', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#set', function() { |
|
|
|
|
|
|
|
|
|
|
|
it('should set compressed', function() { |
|
|
|
should.exist(Signature().set({compressed: true})); |
|
|
|
should.exist(Signature().set({ |
|
|
|
compressed: true |
|
|
|
})); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
describe('#fromCompact', function() { |
|
|
|
|
|
|
|
|
|
|
|
it('should create a signature from a compressed signature', function() { |
|
|
|
var blank = new Buffer(32); |
|
|
|
blank.fill(0); |
|
|
@ -35,7 +40,7 @@ describe('Signature', function() { |
|
|
|
new Buffer([0 + 27 + 4]), |
|
|
|
blank, |
|
|
|
blank |
|
|
|
]); |
|
|
|
]); |
|
|
|
var sig = new Signature(); |
|
|
|
sig.fromCompact(compressed); |
|
|
|
sig.r.cmp(0).should.equal(0); |
|
|
@ -45,27 +50,35 @@ describe('Signature', function() { |
|
|
|
}); |
|
|
|
|
|
|
|
describe('#fromDER', function() { |
|
|
|
|
|
|
|
|
|
|
|
var buf = new Buffer('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex'); |
|
|
|
|
|
|
|
it('should parse this DER format signature', function() { |
|
|
|
var sig = new Signature(); |
|
|
|
sig.fromDER(buf); |
|
|
|
sig.r.toBuffer({size: 32}).toString('hex').should.equal('75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'); |
|
|
|
sig.s.toBuffer({size: 32}).toString('hex').should.equal('729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'); |
|
|
|
sig.r.toBuffer({ |
|
|
|
size: 32 |
|
|
|
}).toString('hex').should.equal('75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'); |
|
|
|
sig.s.toBuffer({ |
|
|
|
size: 32 |
|
|
|
}).toString('hex').should.equal('729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
describe('#fromString', function() { |
|
|
|
|
|
|
|
|
|
|
|
var buf = new Buffer('3044022075fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e62770220729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2', 'hex'); |
|
|
|
|
|
|
|
it('should parse this DER format signature in hex', function() { |
|
|
|
var sig = new Signature(); |
|
|
|
sig.fromString(buf.toString('hex')); |
|
|
|
sig.r.toBuffer({size: 32}).toString('hex').should.equal('75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'); |
|
|
|
sig.s.toBuffer({size: 32}).toString('hex').should.equal('729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'); |
|
|
|
sig.r.toBuffer({ |
|
|
|
size: 32 |
|
|
|
}).toString('hex').should.equal('75fc517e541bd54769c080b64397e32161c850f6c1b2b67a5c433affbb3e6277'); |
|
|
|
sig.s.toBuffer({ |
|
|
|
size: 32 |
|
|
|
}).toString('hex').should.equal('729e85cc46ffab881065ec07694220e71d4df9b2b8c8fd12c3122cf3a5efbcf2'); |
|
|
|
}); |
|
|
|
|
|
|
|
}); |
|
|
@ -127,7 +140,10 @@ describe('Signature', function() { |
|
|
|
it('should convert these known r and s values into a known signature', function() { |
|
|
|
var r = BN('63173831029936981022572627018246571655303050627048489594159321588908385378810'); |
|
|
|
var s = BN('4331694221846364448463828256391194279133231453999942381442030409253074198130'); |
|
|
|
var sig = new Signature({r: r, s: s}); |
|
|
|
var sig = new Signature({ |
|
|
|
r: r, |
|
|
|
s: s |
|
|
|
}); |
|
|
|
var der = sig.toDER(r, s); |
|
|
|
der.toString('hex').should.equal('30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'); |
|
|
|
}); |
|
|
@ -139,7 +155,10 @@ describe('Signature', function() { |
|
|
|
it('should convert this signature in to hex DER', function() { |
|
|
|
var r = BN('63173831029936981022572627018246571655303050627048489594159321588908385378810'); |
|
|
|
var s = BN('4331694221846364448463828256391194279133231453999942381442030409253074198130'); |
|
|
|
var sig = new Signature({r: r, s: s}); |
|
|
|
var sig = new Signature({ |
|
|
|
r: r, |
|
|
|
s: s |
|
|
|
}); |
|
|
|
var hex = sig.toString(); |
|
|
|
hex.should.equal('30450221008bab1f0a2ff2f9cb8992173d8ad73c229d31ea8e10b0f4d4ae1a0d8ed76021fa02200993a6ec81755b9111762fc2cf8e3ede73047515622792110867d12654275e72'); |
|
|
|
}); |
|
|
|