Add methods to decode information from output scripts
This commit is contained in:
parent
53f08a7569
commit
27b48e8aa2
5 changed files with 252 additions and 82 deletions
test
|
@ -36,15 +36,6 @@ describe('address', function () {
|
|||
})
|
||||
})
|
||||
|
||||
fixtures.valid.forEach(function (f) {
|
||||
it('parses (as chunks) ' + f.script.slice(0, 30) + '... (' + f.network + ')', function () {
|
||||
var chunks = bscript.decompile(bscript.fromASM(f.script))
|
||||
var address = baddress.fromOutputScript(chunks, networks[f.network])
|
||||
|
||||
assert.strictEqual(address, f.base58check)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.fromOutputScript.forEach(function (f) {
|
||||
it('throws when ' + f.script.slice(0, 30) + '... ' + f.exception, function () {
|
||||
var script = bscript.fromASM(f.script)
|
||||
|
|
72
test/fixtures/script.json
vendored
72
test/fixtures/script.json
vendored
|
@ -226,18 +226,90 @@
|
|||
{
|
||||
"description": "non-canonical pubkey (too long)",
|
||||
"scriptPubKey": "02359c6e3f04cefbf089cf1d6670dc47c3fb4df68e2bad1fa5a369f9ce4b42bbd1ffffff OP_CHECKSIG"
|
||||
},
|
||||
{
|
||||
"description": "last operator is wrong for pubkey-output",
|
||||
"scriptPubKeyHex": "21027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752ae"
|
||||
},
|
||||
{
|
||||
"description": "missing OP_CHECKSIG",
|
||||
"scriptPubKeyHex": "21027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752"
|
||||
},
|
||||
{
|
||||
"description": "non-canonical pubkey (bad prefix)",
|
||||
"scriptPubKey": "427a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752 OP_CHECKSIG"
|
||||
},
|
||||
{
|
||||
"description": "has extra opcode at the end isPubKeyOutput",
|
||||
"scriptPubKey": "027a71801ab59336de37785c50005b6abd8ea859eecce1edbe8e81afa74ee5c752 OP_CHECKSIG OP_0"
|
||||
}
|
||||
],
|
||||
"isPubKeyHashOutput": [
|
||||
{
|
||||
"description": "non-minimal encoded isPubKeyHashOutput (non BIP62 compliant)",
|
||||
"scriptPubKeyHex": "76a94c14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_DUP isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "aca914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_HASH160 isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76ac14aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_EQUALVERIFY isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c5acac"
|
||||
},
|
||||
{
|
||||
"description": "bad OP_CHECKSIG isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a914aa4d7985c57e011a8b3dd8e0e5a73aaef41629c58888"
|
||||
},
|
||||
{
|
||||
"description": "bad length isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a920aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac"
|
||||
},
|
||||
{
|
||||
"description": "has something at the end isPubKeyHashOutput",
|
||||
"scriptPubKeyHex": "76a920aa4d7985c57e011a8b3dd8e0e5a73aaef41629c588ac00"
|
||||
}
|
||||
],
|
||||
"isScriptHashOutput": [
|
||||
{
|
||||
"description": "non-minimal encoded isScriptHashOutput (non BIP62 compliant)",
|
||||
"scriptPubKeyHex": "a94c14c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong OP_HASH160 opcode",
|
||||
"scriptPubKeyHex": "ac4c14c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "a916c286a1af0947f58d1ad787385b1c2c4a976f9e7187"
|
||||
},
|
||||
{
|
||||
"description": "wrong OP_EQUAL opcode",
|
||||
"scriptPubKeyHex": "a914c286a1af0947f58d1ad787385b1c2c4a976f9e7188"
|
||||
}
|
||||
],
|
||||
"isWitnessPubKeyHashOutput": [
|
||||
{
|
||||
"description": "wrong version",
|
||||
"scriptPubKeyHex": "51149090909090909090909090909090909090909090"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "00209090909090909090909090909090909090909090"
|
||||
}
|
||||
],
|
||||
"isWitnessScriptHashOutput": [
|
||||
{
|
||||
"description": "wrong version",
|
||||
"scriptPubKeyHex": "51209090909090909090909090909090909090909090909090909090909090909090"
|
||||
},
|
||||
{
|
||||
"description": "wrong length marker",
|
||||
"scriptPubKeyHex": "00219090909090909090909090909090909090909090909090909090909090909090"
|
||||
}
|
||||
],
|
||||
"isMultisigOutput": [
|
||||
|
|
|
@ -10,7 +10,16 @@ var fixtures = require('./fixtures/script.json')
|
|||
|
||||
describe('script', function () {
|
||||
// TODO
|
||||
describe.skip('isCanonicalPubKey', function () {})
|
||||
describe('isCanonicalPubKey', function () {
|
||||
it('rejects if not provided a Buffer', function () {
|
||||
assert.strictEqual(false, bscript.isCanonicalPubKey(0))
|
||||
})
|
||||
it('rejects smaller than 33', function () {
|
||||
for (var i = 0; i < 33; i++) {
|
||||
assert.strictEqual(false, bscript.isCanonicalPubKey(new Buffer('', i)))
|
||||
}
|
||||
})
|
||||
})
|
||||
describe.skip('isCanonicalSignature', function () {})
|
||||
|
||||
describe('fromASM/toASM', function () {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue