From 130b3e9fc1585da1ad5ac32ec56e08ec93b7d959 Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Tue, 16 Dec 2014 11:46:34 -0300 Subject: [PATCH] updates bitcore to 0d238f11 --- lib/bitcore.js | 352 +++++++++++++++++++++--------------------- package.json | 2 +- util/build_bitcore.js | 4 +- 3 files changed, 176 insertions(+), 182 deletions(-) diff --git a/lib/bitcore.js b/lib/bitcore.js index 1cc2a1bb4..1e350c2bc 100644 --- a/lib/bitcore.js +++ b/lib/bitcore.js @@ -1,6 +1,6 @@ require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;ot)return!0;if(t>n)return!1;var o=r.slice(4,8).readUInt32BE(0),i=e.slice(4,8).readUInt32BE(0);return o>i?!0:!1},a._encrypt=function(r,e,t,o){var i=n.encrypt(r,e,t,o);return i},a._decrypt=function(r,e){var t=n.decrypt(r,e);return t},a._sign=function(r,n){var t=e.sign(n,r);return t},a._verify=function(r,n,t){var o=e.verifyWithPubKey(r,t,n);return o},module.exports=a}).call(this,require("buffer").Buffer); -},{"./ECIES":"0Qraa1","./Key":"ALJ4PS","./Message":"CBDCgz","buffer":87,"preconditions":151}],"./lib/AuthMessage":[function(require,module,exports){ +},{"./ECIES":"0Qraa1","./Key":"ALJ4PS","./Message":"CBDCgz","buffer":138,"preconditions":169}],"./lib/AuthMessage":[function(require,module,exports){ module.exports=require('cBnJMk'); },{}],"Rpcuro":[function(require,module,exports){ "use strict";var URL=require("url"),Address=require("./Address"),BIP21=function(t){if(this.data={},this.address=void 0,"string"==typeof t)this.parse(t);else if("object"==typeof t)this.fromObj(t);else if("undefined"!=typeof t)throw new Error("Invalid argument")};BIP21.prototype.fromObj=function(t){for(var r in t)this.data[r]=t[r];t.address&&(delete this.data.address,this.setAddress(t.address))},BIP21.prototype.parse=function(t){var r=URL.parse(t,!0);if("bitcoin:"!=r.protocol)throw new Error("Invalid protocol");var e=/[^:]*:\/?\/?([^?]*)/.exec(t);this.setAddress(e&&e[1]);for(var s in r.query){var d=r.query[s];"amount"===s&&(d=Number(d)),"r"===s&&(this.data.merchant=d),this.data[s]=d}},BIP21.prototype.isValid=function(t){var r=t||[],e=!0;"undefined"!=typeof this.data.amount&&(e&=!isNaN(this.data.amount)),this.address&&(e&="object"==typeof this.address&&this.address.isValid()),e&=!(!this.address&&!this.data.r);for(var s in this.data)0==s.indexOf("req-")&&(e&=-1!=r.indexOf(s));return!!e},BIP21.prototype.setAddress=function(t){return t&&(this.address=Address.validate(t)?new Address(t):t),this},BIP21.prototype.getURI=function(){return URL.format({protocol:"bitcoin:",host:this.address,query:this.data})},module.exports=BIP21; -},{"./Address":"G+CcXD","url":113}],"./lib/BIP21":[function(require,module,exports){ +},{"./Address":"G+CcXD","url":163}],"./lib/BIP21":[function(require,module,exports){ module.exports=require('Rpcuro'); },{}],"./lib/Base58":[function(require,module,exports){ module.exports=require('6VqyzY'); },{}],"6VqyzY":[function(require,module,exports){ (function(e){function r(r){return new e(t.createHash("sha256").update(r).digest("binary"),"binary")}function n(e){return r(r(e))}for(var t=require("crypto"),o=require("bignum"),i=new e(1024),c=new e(0),f="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",u=f[0],a=new e(f,"ascii"),h={},d=0;d0){var i=new e(t);return i.fill(0),t==r.length?i:(n=n.toBuffer(),e.concat([i,n],t+n.length))}return n.toBuffer()}},s={encode:function(r){var t=new e(r.length+4),o=n(r);return r.copy(t),o.copy(t,r.length),l.encode(t)},decode:function(e){var r=l.decode(e);if(r.length<4)throw new Error("invalid input: too short");var t=r.slice(0,-4),o=r.slice(-4),i=n(t),c=i.slice(0,4);if(o.toString("hex")!==c.toString("hex"))throw new Error("checksum mismatch");return t}};exports.setBuffer=function(e){i=e},exports.base58=l,exports.base58Check=s,exports.encode=l.encode,exports.decode=l.decode}).call(this,require("buffer").Buffer); -},{"bignum":40,"buffer":87,"crypto":91}],"ez/meX":[function(require,module,exports){ +},{"bignum":40,"buffer":138,"crypto":142}],"ez/meX":[function(require,module,exports){ exports.intFromCompact=function(r){var t=(r>>>24&255)>>>0,n=(16777215&r)<<8*(t-3)>>>0;return n}; },{}],"./lib/Deserialize":[function(require,module,exports){ module.exports=require('ez/meX'); },{}],"x1O6JW":[function(require,module,exports){ (function(e){function i(e,i){if(e.lengthn;n++)t*=256,t+=e[n];return t}function t(e){return i(e,1)}function n(e){return i(e,4)}var r=require("./Base58").base58,s=require("../util"),h=require("./Key"),a=require("./Point"),c=require("./SecureRandom"),o=require("bignum"),d=require("../networks"),l=new o("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141",16),u=(new o("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798",16),function(i){if("undefined"==typeof i||"mainnet"==i||"livenet"==i?(i="livenet",this.version=d.livenet.hkeyPrivateVersion):"testnet"==i&&(this.version=d.testnet.hkeyPrivateVersion),"livenet"==i||"testnet"==i)return this.depth=0,this.parentFingerprint=new e([0,0,0,0]),this.childIndex=new e([0,0,0,0]),this.chainCode=c.getRandomBuffer(32),this.eckey=h.generateSync(),this.hasPrivateKey=!0,this.pubKeyHash=s.sha256ripe160(this.eckey.public),this.buildExtendedPublicKey(),void this.buildExtendedPrivateKey();if("string"==typeof i){var t=r.decode(i);if(82!=t.length)throw new Error("Not enough data, expected 82 and received "+t.length);var n=t.slice(78,82);i=t.slice(0,78);var a=s.sha256(s.sha256(i));if(a[0]!=n[0]||a[1]!=n[1]||a[2]!=n[2]||a[3]!=n[3])throw new Error("Invalid checksum")}void 0!==i&&null!==i&&this.initFromBytes(i)});u.seed=function(i,t){if(t||(t="livenet"),e.isBuffer(i)||(i=new e(i,"hex")),i.length<16)return!1;if(i.length>64)return!1;var n=s.sha512hmac(i,new e("Bitcoin seed")),r=new u(null);return r.depth=0,r.parentFingerprint=new e([0,0,0,0]),r.childIndex=new e([0,0,0,0]),r.chainCode=n.slice(32,64),r.version=d[t].hkeyPrivateVersion,r.eckey=new h,r.eckey.private=n.slice(0,32),r.eckey.regenerateSync(),r.hasPrivateKey=!0,r.pubKeyHash=s.sha256ripe160(r.eckey.public),r.buildExtendedPublicKey(),r.buildExtendedPrivateKey(),r},u.prototype.initFromBytes=function(e){if(78!=e.length)throw new Error("not enough data");this.version=n(e.slice(0,4)),this.depth=t(e.slice(4,5)),this.parentFingerprint=e.slice(5,9),this.childIndex=n(e.slice(9,13)),this.chainCode=e.slice(13,45);var i=e.slice(45,78),r=this.version==d.livenet.hkeyPrivateVersion||this.version==d.testnet.hkeyPrivateVersion,a=this.version==d.livenet.hkeyPublicVersion||this.version==d.testnet.hkeyPublicVersion;if(r&&0==i[0])this.eckey=new h,this.eckey.private=i.slice(1,33),this.eckey.compressed=!0,this.eckey.regenerateSync(),this.pubKeyHash=s.sha256ripe160(this.eckey.public),this.hasPrivateKey=!0;else{if(!a||2!=i[0]&&3!=i[0])throw new Error("Invalid key");this.eckey=new h,this.eckey.public=i,this.pubKeyHash=s.sha256ripe160(this.eckey.public),this.hasPrivateKey=!1}this.buildExtendedPublicKey(),this.buildExtendedPrivateKey()},u.prototype.buildExtendedPublicKey=function(){this.extendedPublicKey=new e([]);var i=null;switch(this.version){case d.livenet.hkeyPublicVersion:case d.livenet.hkeyPrivateVersion:i=d.livenet.hkeyPublicVersion;break;case d.testnet.hkeyPublicVersion:case d.testnet.hkeyPrivateVersion:i=d.testnet.hkeyPublicVersion;break;default:throw new Error("Unknown version")}this.extendedPublicKey=e.concat([new e([i>>24]),new e([i>>16&255]),new e([i>>8&255]),new e([255&i]),new e([this.depth]),this.parentFingerprint,new e([this.childIndex>>>24]),new e([this.childIndex>>>16&255]),new e([this.childIndex>>>8&255]),new e([255&this.childIndex]),this.chainCode,this.eckey.public])},u.prototype.extendedPublicKeyString=function(i){if(void 0===i||"base58"===i){var t=s.sha256(s.sha256(this.extendedPublicKey)),n=t.slice(0,4),h=e.concat([this.extendedPublicKey,n]);return r.encode(h)}if("hex"===i)return this.extendedPublicKey.toString("hex");throw new Error("bad format")},u.prototype.buildExtendedPrivateKey=function(){if(this.hasPrivateKey){this.extendedPrivateKey=new e([]);var i=this.version;this.extendedPrivateKey=e.concat([new e([i>>24]),new e([i>>16&255]),new e([i>>8&255]),new e([255&i]),new e([this.depth]),this.parentFingerprint,new e([this.childIndex>>>24]),new e([this.childIndex>>>16&255]),new e([this.childIndex>>>8&255]),new e([255&this.childIndex]),this.chainCode,new e([0]),this.eckey.private])}},u.prototype.extendedPrivateKeyString=function(i){if(void 0===i||"base58"===i){var t=s.sha256(s.sha256(this.extendedPrivateKey)),n=t.slice(0,4),h=e.concat([this.extendedPrivateKey,n]);return r.encode(h)}if("hex"===i)return this.extendedPrivateKey.toString("hex");throw new Error("bad format")},u.prototype.derive=function(e){var i=e.split("/");if("m"==e||"M"==e||"m'"==e||"M'"==e)return this;var t=this;for(var n in i){var r=i[n];if(0!=n){var s=r.length>1&&"'"==r[r.length-1],h=2147483647&parseInt(s?r.slice(0,r.length-1):r);s&&(h+=2147483648),t=t.deriveChild(h)}else if("m"!=r)throw new Error("invalid path")}return t},u.prototype.deriveChild=function(i){var t=[];t.push(i>>24&255),t.push(i>>16&255),t.push(i>>8&255),t.push(255&i),t=new e(t);var n=0!=(2147483648&i),r=this.version==d.livenet.hkeyPrivateVersion||this.version==d.testnet.hkeyPrivateVersion;if(n&&(!this.hasPrivateKey||!r))throw new Error("Cannot do private key derivation without private key");var c=null;if(this.hasPrivateKey){var y=null;y=e.concat(n?[new e([0]),this.eckey.private,t]:[this.eckey.public,t]);var v=s.sha512hmac(y,this.chainCode),p=o.fromBuffer(v.slice(0,32),{size:32}),w=v.slice(32,64),b=o.fromBuffer(this.eckey.private,{size:32}),f=p.add(b).mod(l);c=new u(null),c.chainCode=w,c.eckey=new h,c.eckey.private=f.toBuffer({size:32}),c.eckey.regenerateSync(),c.hasPrivateKey=!0}else{var y=e.concat([this.eckey.public,t]),v=s.sha512hmac(y,this.chainCode),p=v.slice(0,32),w=v.slice(32,64),k=new h;k.private=p,k.regenerateSync(),k.compressed=!1;var P=a.fromUncompressedPubKey(k.public),F=new h;F.public=this.eckey.public,F.compressed=!1;var x=a.fromUncompressedPubKey(F.public),K=a.add(P,x).toUncompressedPubKey();c=new u(null),c.chainCode=new e(w);var g=new h;g.public=K,g.compressed=!0,c.eckey=g,c.hasPrivateKey=!1}return c.childIndex=i,c.parentFingerprint=this.pubKeyHash.slice(0,4),c.version=this.version,c.depth=this.depth+1,c.eckey.compressed=!0,c.pubKeyHash=s.sha256ripe160(c.eckey.public),c.buildExtendedPublicKey(),c.buildExtendedPrivateKey(),c},module.exports=u}).call(this,require("buffer").Buffer); -},{"../networks":"ULNIu2","../util":171,"./Base58":"6VqyzY","./Key":"ALJ4PS","./Point":"6tXgqr","./SecureRandom":"p4SiC2","bignum":40,"buffer":87}],"./lib/HierarchicalKey":[function(require,module,exports){ +},{"../networks":"ULNIu2","../util":130,"./Base58":"6VqyzY","./Key":"ALJ4PS","./Point":"6tXgqr","./SecureRandom":"p4SiC2","bignum":40,"buffer":138}],"./lib/HierarchicalKey":[function(require,module,exports){ module.exports=require('x1O6JW'); },{}],"CBDCgz":[function(require,module,exports){ (function(e){"use strict";var r=require("../util"),i=require("./Key"),n=require("bignum"),r=require("../util"),t=function(){};t.sign=function(e,r){var i=t.magicHash(e),n=r.signSync(i);return n},t.verifyWithPubKey=function(e,r,n){var u=t.magicHash(r),a=new i;return 65==e.length&&(a.compressed=!1),a.public=e,a.verifySignatureSync(u,n)},t.signMessage=function(e,r){var u=t.magicHash(e),a=n.fromBuffer(r.private),s=i.signCompressed(u,a);return s},t.verifyMessage=function(e,r,n){var u=t.magicHash(r);return i.verifyCompressed(u,n,e)},t.magicBytes=new e("Bitcoin Signed Message:\n"),t.magicHash=function(i){var n=t.magicBytes,u=r.varIntBuf(n.length),a=new e(i),s=r.varIntBuf(a.length),c=e.concat([u,n,s,a]),f=r.twoSha256(c);return f},module.exports=t}).call(this,require("buffer").Buffer); -},{"../util":171,"./Key":"ALJ4PS","bignum":40,"buffer":87}],"./lib/Message":[function(require,module,exports){ +},{"../util":130,"./Key":"ALJ4PS","bignum":40,"buffer":138}],"./lib/Message":[function(require,module,exports){ module.exports=require('CBDCgz'); },{}],"Zm7/h9":[function(require,module,exports){ function Opcode(O){this.code=O}Opcode.prototype.toString=function(){return Opcode.reverseMap[this.code]},Opcode.map={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_NOP3:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},Opcode.reverseMap=[];for(var k in Opcode.map)Opcode.map.hasOwnProperty(k)&&(Opcode.reverseMap[Opcode.map[k]]=k.substr(3));Opcode.asList=function(){var O=[];for(var P in Opcode.map)Opcode.map.hasOwnProperty(P)&&O.push(P);return O},module.exports=Opcode; @@ -44,71 +44,71 @@ function Opcode(O){this.code=O}Opcode.prototype.toString=function(){return Opcod module.exports=require('Zm7/h9'); },{}],"izTl9z":[function(require,module,exports){ (function(t){function i(t,e,r){i.super_.call(this,t,e),void 0!==r&&this.compressed(r)}var e=require("../util/VersionedData"),r=require("../util/EncodedData"),n=require("../networks"),a=require("util");a.inherits(i,e),r.applyEncodingsTo(i),i.prototype.validate=function(){if(this.doAsBinary(function(){if(i.super_.prototype.validate.call(this),this.data.length<32||this.data.length>33&&!this.compressed()||34==this.data.length&&1!=this.data[33]||this.data.length>34)throw new Error("invalid data length")}),"undefined"==typeof this.network())throw new Error("invalid network")},i.prototype.payload=function(t){if(t)return this.doAsBinary(function(){t.copy(this.data,1)}),t;var i=this.as("binary");return 34==i.length?i.slice(1,33):33==i.length?i.slice(1):void 0},i.prototype.compressed=function(i){if(void 0===i){var e=34,r=this.as("binary");if(r.length==e&&1==r[e-1])return!0;if(r.length==e-1)return!1;throw new Error("invalid private key")}this.doAsBinary(function(){var e=34;if(i){var r=new t(e);this.data.copy(r),this.data=r,this.data[e-1]=1}else this.data=this.data.slice(0,e-1)})},i.prototype.network=function(){var t,i=this.version(),e=n.livenet,r=n.testnet;return i===e.privKeyVersion?t=e:i===r.privKeyVersion&&(t=r),t},module.exports=i}).call(this,require("buffer").Buffer); -},{"../networks":"ULNIu2","../util/EncodedData":"eLfUFE","../util/VersionedData":"QLzNQg","buffer":87,"util":115}],"./lib/PrivateKey":[function(require,module,exports){ +},{"../networks":"ULNIu2","../util/EncodedData":"eLfUFE","../util/VersionedData":"QLzNQg","buffer":138,"util":165}],"./lib/PrivateKey":[function(require,module,exports){ module.exports=require('izTl9z'); },{}],"./lib/SIN":[function(require,module,exports){ module.exports=require('tBM27q'); },{}],"tBM27q":[function(require,module,exports){ (function(t){"use strict";function i(n,r){if("number"!=typeof n)return void i.super_.call(this,n,r);if(!t.isBuffer(r)||20!=r.length)throw new Error("Payload must be 20 bytes");this.data=new t(2+r.length),this.converters=this.encodings.binary.converters,this._encoding=this.encodings.binary._encoding,this.encoding("binary"),this.prefix(15),this.type(n),this.payload(r)}var n=require("../util/VersionedData"),r=require("../util/EncodedData"),e=require("util"),o=require("../util");e.inherits(i,n),r.applyEncodingsTo(i),i.SIN_PERSIST_MAINNET=1,i.SIN_PERSIST_TESTNET=17,i.SIN_EPHEM=2,i.prototype.prefix=function(t){return t||0===t?(this.doAsBinary(function(){this.data.writeUInt8(t,0)}),t):this.as("binary").readUInt8(0)},i.prototype.type=function(t){return t||0===t?(this.doAsBinary(function(){this.data.writeUInt8(t,1)}),t):this.as("binary").readUInt8(1)},i.prototype.payload=function(t){return t?(this.doAsBinary(function(){t.copy(this.data,2)}),t):this.as("binary").slice(1)},i.prototype.validate=function(){this.doAsBinary(function(){if(i.super_.prototype.validate.call(this),22!=this.data.length)throw new Error("invalid data length")})},i.fromPubKey=function(n,r){if(r||(r=i.SIN_EPHEM),!t.isBuffer(n)||33!==n.length&&65!=n.length)throw new Error("Invalid public key");var e=o.sha256ripe160(n);return new i(e,r)},module.exports=i}).call(this,require("buffer").Buffer); -},{"../util":171,"../util/EncodedData":"eLfUFE","../util/VersionedData":"QLzNQg","buffer":87,"util":115}],"./lib/SINKey":[function(require,module,exports){ +},{"../util":130,"../util/EncodedData":"eLfUFE","../util/VersionedData":"QLzNQg","buffer":138,"util":165}],"./lib/SINKey":[function(require,module,exports){ module.exports=require('EyghZQ'); },{}],"EyghZQ":[function(require,module,exports){ function SINKey(e){"object"!=typeof e&&(e={}),this.created=e.created,this.privKey=e.privKey}var coinUtil=require("../util"),timeUtil=require("../util/time"),Key=require("./Key"),SIN=require("./SIN");SINKey.prototype.generate=function(){this.privKey=Key.generateSync(),this.created=timeUtil.curtime()},SINKey.prototype.pubkeyHash=function(){return coinUtil.sha256ripe160(this.privKey.public)},SINKey.prototype.storeObj=function(){var e=this.privKey.public.toString("hex"),t=this.pubkeyHash(),i=new SIN(SIN.SIN_EPHEM,t),r={created:this.created,priv:this.privKey.private.toString("hex"),pub:e,sin:i.toString()};return r},module.exports=SINKey; -},{"../util":171,"../util/time":174,"./Key":"ALJ4PS","./SIN":"tBM27q"}],"./lib/Script":[function(require,module,exports){ +},{"../util":130,"../util/time":133,"./Key":"ALJ4PS","./SIN":"tBM27q"}],"./lib/Script":[function(require,module,exports){ module.exports=require('hQ0t76'); },{}],"hQ0t76":[function(require,module,exports){ (function(t){function e(t){this.buffer=t?t:f.EMPTY_BUFFER,this.chunks=[],this.parse()}function r(t){return t==h.map.OP_0||t>=h.map.OP_1&&t<=h.map.OP_16}function n(t){return t=t?2:65535>=t?3:5}function s(e){var r=void 0;return e=e?(r=new t(2),r.writeUInt8(h.map.OP_PUSHDATA1,0),r.writeUInt8(e,1)):65535>=e?(r=new t(3),r.writeUInt8(h.map.OP_PUSHDATA2,0),r.writeUInt16LE(e,1)):(r=new t(5),r.writeUInt8(h.map.OP_PUSHDATA4,0),r.writeUInt32LE(e,1)),r}var u=(require("../config"),require("../util/log")),h=require("./Opcode"),o=require("buffertools"),f=require("../util/util"),c=require("../util/BinaryParser"),p=require("bufferput"),a=0,l=1,g=2,k=3,y=4,S=5,P=["unknown","pubkey","pubkeyhash","multisig","scripthash","return"];e.TX_UNKNOWN=a,e.TX_PUBKEY=l,e.TX_PUBKEYHASH=g,e.TX_MULTISIG=k,e.TX_SCRIPTHASH=y,e.TX_RETURN=S,e.prototype.parse=function(){this.chunks=[];for(var t=new c(this.buffer);!t.eof();){var e,r,n=t.word8();n>0&&nh.map.OP_16)return!1}return!0},e.prototype.isP2SH=function(){return 3==this.chunks.length&&this.chunks[0]==h.map.OP_HASH160&&t.isBuffer(this.chunks[1])&&20==this.chunks[1].length&&this.chunks[2]==h.map.OP_EQUAL},e.prototype.isPubkey=function(){return 2==this.chunks.length&&t.isBuffer(this.chunks[0])&&this.chunks[1]==h.map.OP_CHECKSIG},e.prototype.isReturn=function(){return 2==this.chunks.length&&t.isBuffer(this.chunks[1])&&this.chunks[0]==h.map.OP_RETURN},e.prototype.isPubkeyHash=function(){return 5==this.chunks.length&&this.chunks[0]==h.map.OP_DUP&&this.chunks[1]==h.map.OP_HASH160&&t.isBuffer(this.chunks[2])&&20==this.chunks[2].length&&this.chunks[3]==h.map.OP_EQUALVERIFY&&this.chunks[4]==h.map.OP_CHECKSIG},e.prototype.isMultiSig=function(){return this.chunks.length>3&&r(this.chunks[0])&&this.chunks.slice(1,this.chunks.length-2).every(function(e){return t.isBuffer(e)})&&r(this.chunks[this.chunks.length-2])&&this.chunks[this.chunks.length-1]==h.map.OP_CHECKMULTISIG},e.prototype.isPubkeyHashScriptSig=function(){return 2==this.chunks.length&&t.isBuffer(this.chunks[0])&&t.isBuffer(this.chunks[1])},e.prototype.isP2shScriptSig=function(){if(!r(this.chunks[0])||0!==this.chunks[0])return!1;var t=new e(this.chunks[this.chunks.length-1]),n=t.classify();return n!==a},e.prototype.isMultiSigScriptSig=function(){return r(this.chunks[0])&&0===this.chunks[0]?!this.isP2shScriptSig():!1},e.prototype.isPubkeyScriptSig=function(){return 1==this.chunks.length&&t.isBuffer(this.chunks[0])},e.prototype.countSignatures=function(){var t=0,e=this.chunks.length;return t=this.isMultiSigScriptSig()?e-1:this.isP2shScriptSig()?e-2:this.isPubkeyHashScriptSig()?1:0},e.prototype.getSignatures=function(){ret=[];var t=this.chunks.length;if(this.isMultiSigScriptSig())for(var e=1;t>e;e++)ret.push(this.chunks[e]);else if(this.isP2shScriptSig())for(var e=1;t-1>e;e++)ret.push(this.chunks[e]);else this.isPubkeyHashScriptSig()&&ret.push(this.chunks[0]);return ret},e.prototype.getHashType=function(){for(var t=this.getSignatures(),e=null,r=0;ri;i++){var u=this.chunks[i];if(i>0&&(n+=" "),n+=t.isBuffer(u)?"0x"+f.formatBuffer(u,e?null:0):h.reverseMap[u],r&&i>r){n+=" ...";break}}return n},e.prototype.toString=function(t,e){var r="