From 87c40193b9d031fdc0ce480621d08e1431041339 Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 1 Dec 2014 11:49:44 -0300 Subject: [PATCH] add pubkey in pubkey out script types --- lib/script.js | 14 ++++++++------ test/script.js | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/script.js b/lib/script.js index 6bafe8cc8..8260ff618 100644 --- a/lib/script.js +++ b/lib/script.js @@ -124,7 +124,7 @@ Script.fromString = function(str) { }); i = i + 2; } else { - throw new Error('Invalid script: '+JSON.stringify(str)); + throw new Error('Invalid script: ' + JSON.stringify(str)); } } else if (opcodenum === Opcode.map.OP_PUSHDATA1 || opcodenum === Opcode.map.OP_PUSHDATA2 || @@ -200,14 +200,19 @@ Script.prototype.isPublicKeyHashIn = function() { * @returns true if this is a public key output script */ Script.prototype.isPublicKeyOut = function() { - return false; + return this.chunks.length === 2 && + Buffer.isBuffer(this.chunks[0].buf) && + this.chunks[0].buf.length === 0x41 && + this.chunks[1] === Opcode('OP_CHECKSIG').toNumber(); }; /** * @returns true if this is a pay to public key input script */ Script.prototype.isPublicKeyIn = function() { - return false; + return this.chunks.length === 1 && + Buffer.isBuffer(this.chunks[0].buf) && + this.chunks[0].buf.length === 0x47; }; @@ -238,11 +243,8 @@ Script.prototype.isScriptHashIn = function() { if (!scriptBuf) { return false; } - console.log(this.toString()); var redeemScript = new Script(scriptBuf); var type = redeemScript.classify(); - console.log(redeemScript.toString()); - console.log(redeemScript.classify()); return type !== Script.types.UNKNOWN; }; diff --git a/test/script.js b/test/script.js index 2b876bf81..5cec12aea 100644 --- a/test/script.js +++ b/test/script.js @@ -285,7 +285,7 @@ describe('Script', function() { }); }); - describe.only('#classify', function() { + describe('#classify', function() { it('should classify public key hash out', function() { Script('OP_DUP OP_HASH160 20 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG').classify().should.equal(Script.types.PUBKEYHASH_OUT); }); @@ -309,10 +309,10 @@ describe('Script', function() { Script('OP_RETURN 1 0x01').classify().should.equal(Script.types.OP_RETURN); }); it('should classify public key out', function() { - Script('').classify().should.equal(Script.types.PUBKEY_OUT); + Script('41 0x0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 OP_CHECKSIG').classify().should.equal(Script.types.PUBKEY_OUT); }); it('should classify public key in', function() { - Script('').classify().should.equal(Script.types.PUBKEY_IN); + Script('47 0x3044022007415aa37ce7eaa6146001ac8bdefca0ddcba0e37c5dc08c4ac99392124ebac802207d382307fd53f65778b07b9c63b6e196edeadf0be719130c5db21ff1e700d67501').classify().should.equal(Script.types.PUBKEY_IN); }); });