From c0d51916df205bbdf205e6555bac499678cdcf0c Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Thu, 24 Jul 2014 16:16:47 -0300 Subject: [PATCH] add support code for copay's new tx proposal check --- lib/Script.js | 60 +++++++++++++++++++++++++++++++++++++--- lib/Transaction.js | 8 ++++++ test/test.Transaction.js | 2 +- 3 files changed, 65 insertions(+), 5 deletions(-) diff --git a/lib/Script.js b/lib/Script.js index c1ced7b..6f73243 100644 --- a/lib/Script.js +++ b/lib/Script.js @@ -115,6 +115,13 @@ Script.prototype.isMultiSig = function() { this.chunks[this.chunks.length - 1] == Opcode.map.OP_CHECKMULTISIG); }; +Script.prototype.isPubkeyHashScript = function() { + // TODO: add more restrictions to chunks + return (this.chunks.length == 2 && + Buffer.isBuffer(this.chunks[0]) && + Buffer.isBuffer(this.chunks[1])); +}; + Script.prototype.isP2shScriptSig = function() { if (!isSmallIntOp(this.chunks[0]) || this.chunks[0] !== 0) return false; @@ -133,20 +140,65 @@ Script.prototype.isMultiSigScriptSig = function() { Script.prototype.countSignatures = function() { var ret = 0; var l = this.chunks.length; - // Multisig? if (this.isMultiSigScriptSig()) { ret = l - 1; - } else if (this.isP2shScriptSig()) { + } + // p2sh + else if (this.isP2shScriptSig()) { ret = l - 2; } - // p2pubkey or p2pubkeyhash + // p2pubkeyhash + else if (this.isPubkeyHashScript()) { + ret = 1; + } + // p2pubkey else { - ret = buffertools.compare(this.getBuffer(), util.EMPTY_BUFFER) === 0 ? 0 : 1; + ret = 0; } return ret; }; + +Script.prototype.getSignatures = function() { + ret = []; + var l = this.chunks.length; + // Multisig? + if (this.isMultiSigScriptSig()) { + for(var i = 1; i