ECSignature: add tests for scriptSignature
This commit is contained in:
parent
eb3d9a25f7
commit
626f8fb220
2 changed files with 65 additions and 0 deletions
|
@ -79,4 +79,41 @@ describe('ECSignature', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('toScriptSignature', function() {
|
||||||
|
it('encodes a script signature', function() {
|
||||||
|
fixtures.valid.forEach(function(f) {
|
||||||
|
var signature = new ECSignature(
|
||||||
|
new BigInteger(f.signature.r),
|
||||||
|
new BigInteger(f.signature.s)
|
||||||
|
)
|
||||||
|
|
||||||
|
var scriptSignature = signature.toScriptSignature(f.scriptSignature.hashType)
|
||||||
|
assert.equal(scriptSignature.toString('hex'), f.scriptSignature.hex)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('fromScriptSignature', function() {
|
||||||
|
it('decodes the correct signature', function() {
|
||||||
|
fixtures.valid.forEach(function(f) {
|
||||||
|
var buffer = new Buffer(f.scriptSignature.hex, 'hex')
|
||||||
|
var parsed = ECSignature.fromScriptSignature(buffer)
|
||||||
|
|
||||||
|
assert.equal(parsed.signature.r.toString(), f.signature.r)
|
||||||
|
assert.equal(parsed.signature.s.toString(), f.signature.s)
|
||||||
|
assert.equal(parsed.hashType, f.scriptSignature.hashType)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
fixtures.invalid.DER.forEach(function(f) {
|
||||||
|
it('throws on ' + f.hex, function() {
|
||||||
|
var buffer = new Buffer(f.hex + '01', 'hex')
|
||||||
|
|
||||||
|
assert.throws(function() {
|
||||||
|
ECSignature.fromScriptSignature(buffer)
|
||||||
|
}, new RegExp(f.exception))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
28
test/fixtures/ecsignature.json
vendored
28
test/fixtures/ecsignature.json
vendored
|
@ -6,6 +6,10 @@
|
||||||
"compressed": true,
|
"compressed": true,
|
||||||
"i": 0
|
"i": 0
|
||||||
},
|
},
|
||||||
|
"scriptSignature": {
|
||||||
|
"hex": "3044022033a69cd2065432a30f3d1ce4eb0d59b8ab58c74f27c41a7fdb5696ad4e6108c902206f807982866f785d3f6418d24163ddae117b7db4d5fdf0071de069fa5434226201",
|
||||||
|
"hashType": 1
|
||||||
|
},
|
||||||
"DER": "3044022033a69cd2065432a30f3d1ce4eb0d59b8ab58c74f27c41a7fdb5696ad4e6108c902206f807982866f785d3f6418d24163ddae117b7db4d5fdf0071de069fa54342262",
|
"DER": "3044022033a69cd2065432a30f3d1ce4eb0d59b8ab58c74f27c41a7fdb5696ad4e6108c902206f807982866f785d3f6418d24163ddae117b7db4d5fdf0071de069fa54342262",
|
||||||
"signature": {
|
"signature": {
|
||||||
"r": "23362334225185207751494092901091441011938859014081160902781146257181456271561",
|
"r": "23362334225185207751494092901091441011938859014081160902781146257181456271561",
|
||||||
|
@ -19,6 +23,10 @@
|
||||||
"i": 0
|
"i": 0
|
||||||
},
|
},
|
||||||
"DER": "3044022054c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed022007082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5",
|
"DER": "3044022054c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed022007082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a5",
|
||||||
|
"scriptSignature": {
|
||||||
|
"hex": "3044022054c4a33c6423d689378f160a7ff8b61330444abb58fb470f96ea16d99d4a2fed022007082304410efa6b2943111b6a4e0aaa7b7db55a07e9861d1fb3cb1f421044a502",
|
||||||
|
"hashType": 2
|
||||||
|
},
|
||||||
"signature": {
|
"signature": {
|
||||||
"r": "38341707918488238920692284707283974715538935465589664377561695343399725051885",
|
"r": "38341707918488238920692284707283974715538935465589664377561695343399725051885",
|
||||||
"s": "3180566392414476763164587487324397066658063772201694230600609996154610926757"
|
"s": "3180566392414476763164587487324397066658063772201694230600609996154610926757"
|
||||||
|
@ -30,6 +38,10 @@
|
||||||
"compressed": true,
|
"compressed": true,
|
||||||
"i": 0
|
"i": 0
|
||||||
},
|
},
|
||||||
|
"scriptSignature": {
|
||||||
|
"hex": "3045022100ff466a9f1b7b273e2f4c3ffe032eb2e814121ed18ef84665d0f515360dab3dd002206fc95f5132e5ecfdc8e5e6e616cc77151455d46ed48f5589b7db7771a332b28303",
|
||||||
|
"hashType": 3
|
||||||
|
},
|
||||||
"DER": "3045022100ff466a9f1b7b273e2f4c3ffe032eb2e814121ed18ef84665d0f515360dab3dd002206fc95f5132e5ecfdc8e5e6e616cc77151455d46ed48f5589b7db7771a332b283",
|
"DER": "3045022100ff466a9f1b7b273e2f4c3ffe032eb2e814121ed18ef84665d0f515360dab3dd002206fc95f5132e5ecfdc8e5e6e616cc77151455d46ed48f5589b7db7771a332b283",
|
||||||
"signature": {
|
"signature": {
|
||||||
"r": "115464191557905790016094131873849783294273568009648050793030031933291767741904",
|
"r": "115464191557905790016094131873849783294273568009648050793030031933291767741904",
|
||||||
|
@ -42,6 +54,10 @@
|
||||||
"compressed": false,
|
"compressed": false,
|
||||||
"i": 1
|
"i": 1
|
||||||
},
|
},
|
||||||
|
"scriptSignature": {
|
||||||
|
"hex": "3045022100c0dafec8251f1d5010289d210232220b03202cba34ec11fec58b3e93a85b91d3022075afdc06b7d6322a590955bf264e7aaa155847f614d80078a90292fe205064d381",
|
||||||
|
"hashType": 129
|
||||||
|
},
|
||||||
"DER": "3045022100c0dafec8251f1d5010289d210232220b03202cba34ec11fec58b3e93a85b91d3022075afdc06b7d6322a590955bf264e7aaa155847f614d80078a90292fe205064d3",
|
"DER": "3045022100c0dafec8251f1d5010289d210232220b03202cba34ec11fec58b3e93a85b91d3022075afdc06b7d6322a590955bf264e7aaa155847f614d80078a90292fe205064d3",
|
||||||
"signature": {
|
"signature": {
|
||||||
"r": "87230998027579607140680851455601772643840468630989315269459846730712163783123",
|
"r": "87230998027579607140680851455601772643840468630989315269459846730712163783123",
|
||||||
|
@ -54,6 +70,10 @@
|
||||||
"compressed": true,
|
"compressed": true,
|
||||||
"i": 0
|
"i": 0
|
||||||
},
|
},
|
||||||
|
"scriptSignature": {
|
||||||
|
"hex": "304402207186363571d65e084e7f02b0b77c3ec44fb1b257dee26274c38c928986fea45d02200de0b38e06807e46bda1f1e293f4f6323e854c86d58abdd00c46c16441085df682",
|
||||||
|
"hashType": 130
|
||||||
|
},
|
||||||
"DER": "304402207186363571d65e084e7f02b0b77c3ec44fb1b257dee26274c38c928986fea45d02200de0b38e06807e46bda1f1e293f4f6323e854c86d58abdd00c46c16441085df6",
|
"DER": "304402207186363571d65e084e7f02b0b77c3ec44fb1b257dee26274c38c928986fea45d02200de0b38e06807e46bda1f1e293f4f6323e854c86d58abdd00c46c16441085df6",
|
||||||
"signature": {
|
"signature": {
|
||||||
"r": "51348483531757779992459563033975330355971795607481991320287437101831125115997",
|
"r": "51348483531757779992459563033975330355971795607481991320287437101831125115997",
|
||||||
|
@ -66,6 +86,10 @@
|
||||||
"compressed": false,
|
"compressed": false,
|
||||||
"i": 1
|
"i": 1
|
||||||
},
|
},
|
||||||
|
"scriptSignature": {
|
||||||
|
"hex": "3045022100fbfe5076a15860ba8ed00e75e9bd22e05d230f02a936b653eb55b61c99dda48702200e68880ebb0050fe4312b1b1eb0899e1b82da89baa5b895f612619edf34cbd3783",
|
||||||
|
"hashType": 131
|
||||||
|
},
|
||||||
"DER": "3045022100fbfe5076a15860ba8ed00e75e9bd22e05d230f02a936b653eb55b61c99dda48702200e68880ebb0050fe4312b1b1eb0899e1b82da89baa5b895f612619edf34cbd37",
|
"DER": "3045022100fbfe5076a15860ba8ed00e75e9bd22e05d230f02a936b653eb55b61c99dda48702200e68880ebb0050fe4312b1b1eb0899e1b82da89baa5b895f612619edf34cbd37",
|
||||||
"signature": {
|
"signature": {
|
||||||
"r": "113979859486826658566290715281614250298918272782414232881639314569529560769671",
|
"r": "113979859486826658566290715281614250298918272782414232881639314569529560769671",
|
||||||
|
@ -78,6 +102,10 @@
|
||||||
"compressed": true,
|
"compressed": true,
|
||||||
"i": 1
|
"i": 1
|
||||||
},
|
},
|
||||||
|
"scriptSignature": {
|
||||||
|
"hex": "3045022100cde1302d83f8dd835d89aef803c74a119f561fbaef3eb9129e45f30de86abbf9022006ce643f5049ee1f27890467b77a6a8e11ec4661cc38cd8badf90115fbd03cefff",
|
||||||
|
"hashType": 255
|
||||||
|
},
|
||||||
"DER": "3045022100cde1302d83f8dd835d89aef803c74a119f561fbaef3eb9129e45f30de86abbf9022006ce643f5049ee1f27890467b77a6a8e11ec4661cc38cd8badf90115fbd03cef",
|
"DER": "3045022100cde1302d83f8dd835d89aef803c74a119f561fbaef3eb9129e45f30de86abbf9022006ce643f5049ee1f27890467b77a6a8e11ec4661cc38cd8badf90115fbd03cef",
|
||||||
"signature": {
|
"signature": {
|
||||||
"r": "93122007060065279508564838030979550535085999589142852106617159184757394422777",
|
"r": "93122007060065279508564838030979550535085999589142852106617159184757394422777",
|
||||||
|
|
Loading…
Reference in a new issue