require= // modules are defined as an array // [ module function, map of requireuires ] // // map of requireuires is short require name -> numeric require // // anything defined in a previous bundle is accessed via the // orig method which is the requireuire for previous bundles (function outer (modules, cache, entry) { // Save the require from previous bundle to this closure if any var previousRequire = typeof require == "function" && require; function newRequire(name, jumped, inSkipCache){ var m, skipCache = inSkipCache; if (typeof name === 'string') { if (name.charAt(0) === '!' ) { name = name.substr(1); skipCache=true; } } if(skipCache || !cache[name]) { if(!modules[name]) { // if we cannot find the the module within our internal map or // cache jump to the current global require ie. the last bundle // that was added to the page. var currentRequire = typeof require == "function" && require; if (!jumped && currentRequire) return currentRequire(name, true); // If there are other bundles on this page the require from the // previous one is saved to 'previousRequire'. Repeat this as // many times as there are bundles until the module is found or // we exhaust the require chain. if (previousRequire) return previousRequire(name, true); throw new Error('Cannot find module \'' + name + '\''); } m = {exports:{}}; var nextSkipCache = inSkipCache ? false : skipCache; if (!skipCache) cache[name] = m; skipCache = false; modules[name][0].call(m.exports, function(x){ var id = modules[name][1][x]; return newRequire(id ? id : x, false, nextSkipCache); },m,m.exports,outer,modules,cache,entry); } return m ? m.exports:cache[name].exports; } for(var i=0;in;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("soop").imports(),s=r.base58||require("base58-native").base58,h=r.coinUtil||require("./util/util"),d=r.Key||require("./Key"),c=r.Point||require("./Point"),a=r.bignum||require("bignum"),o=(require("crypto"),require("./networks")),y=new a("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141",16),l=(new a("79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798",16),function(i){if("mainnet"==i||"livenet"==i?this.version=o.livenet.bip32privateVersion:"testnet"==i&&(this.version=o.testnet.bip32privateVersion),"mainnet"==i||"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=d.generateSync().private,this.eckey=d.generateSync(),this.hasPrivateKey=!0,this.pubKeyHash=h.sha256ripe160(this.eckey.public),this.buildExtendedPublicKey(),void this.buildExtendedPrivateKey();if("string"==typeof i){var t=s.decode(i);if(82!=t.length)throw new Error("Not enough data");var n=t.slice(78,82);i=t.slice(0,78);var r=h.sha256(h.sha256(i));if(r[0]!=n[0]||r[1]!=n[1]||r[2]!=n[2]||r[3]!=n[3])throw new Error("Invalid checksum")}void 0!==i&&this.initFromBytes(i)});l.seed=function(i,t){if(t||(t="livenet"),e.isBuffer(i)||(i=new e(i,"hex")),i.length<16)return!1;var n=h.sha512hmac(i,new e("Bitcoin seed")),r=new l;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=o[t].bip32privateVersion,r.eckey=new d,r.eckey.private=n.slice(0,32),r.eckey.regenerateSync(),r.hasPrivateKey=!0,r.pubKeyHash=h.sha256ripe160(r.eckey.public),r.buildExtendedPublicKey(),r.buildExtendedPrivateKey(),r},l.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==o.livenet.bip32privateVersion||this.version==o.testnet.bip32privateVersion,s=this.version==o.livenet.bip32publicVersion||this.version==o.testnet.bip32publicVersion;if(r&&0==i[0])this.eckey=new d,this.eckey.private=i.slice(1,33),this.eckey.compressed=!0,this.eckey.regenerateSync(),this.pubKeyHash=h.sha256ripe160(this.eckey.public),this.hasPrivateKey=!0;else{if(!s||2!=i[0]&&3!=i[0])throw new Error("Invalid key");this.eckey=new d,this.eckey.public=i,this.pubKeyHash=h.sha256ripe160(this.eckey.public),this.hasPrivateKey=!1}this.buildExtendedPublicKey(),this.buildExtendedPrivateKey()},l.prototype.buildExtendedPublicKey=function(){this.extendedPublicKey=new e([]);var i=null;switch(this.version){case o.livenet.bip32publicVersion:case o.livenet.bip32privateVersion:i=o.livenet.bip32publicVersion;break;case o.testnet.bip32publicVersion:case o.testnet.bip32privateVersion:i=o.testnet.bip32publicVersion;break;default:throw new Error("Unknown version")}this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([i>>24])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([i>>16&255])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([i>>8&255])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([255&i])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([this.depth])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,this.parentFingerprint]),this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([this.childIndex>>>24])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([this.childIndex>>>16&255])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([this.childIndex>>>8&255])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,new e([255&this.childIndex])]),this.extendedPublicKey=e.concat([this.extendedPublicKey,this.chainCode]),this.extendedPublicKey=e.concat([this.extendedPublicKey,this.eckey.public])},l.prototype.extendedPublicKeyString=function(i){if(void 0===i||"base58"===i){var t=h.sha256(h.sha256(this.extendedPublicKey)),n=t.slice(0,4),r=e.concat([this.extendedPublicKey,n]);return s.encode(r)}if("hex"===i)return this.extendedPublicKey.toString("hex");throw new Error("bad format")},l.prototype.buildExtendedPrivateKey=function(){if(this.hasPrivateKey){this.extendedPrivateKey=new e([]);var i=this.version;this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([i>>24])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([i>>16&255])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([i>>8&255])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([255&i])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([this.depth])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,this.parentFingerprint]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([this.childIndex>>>24])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([this.childIndex>>>16&255])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([this.childIndex>>>8&255])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([255&this.childIndex])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,this.chainCode]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,new e([0])]),this.extendedPrivateKey=e.concat([this.extendedPrivateKey,this.eckey.private])}},l.prototype.extendedPrivateKeyString=function(i){if(void 0===i||"base58"===i){var t=h.sha256(h.sha256(this.extendedPrivateKey)),n=t.slice(0,4),r=e.concat([this.extendedPrivateKey,n]);return s.encode(r)}if("hex"===i)return this.extendedPrivateKey.toString("hex");throw new Error("bad format")},l.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},l.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==o.livenet.bip32privateVersion||this.version==o.testnet.bip32privateVersion;if(n&&(!this.hasPrivateKey||!r))throw new Error("Cannot do private key derivation without private key");var s=null;if(this.hasPrivateKey){var u=null;u=e.concat(n?[new e([0]),this.eckey.private,t]:[this.eckey.public,t]);var v=h.sha512hmac(u,this.chainCode),p=a.fromBuffer(v.slice(0,32),{size:32}),b=v.slice(32,64),K=a.fromBuffer(this.eckey.private,{size:32}),x=p.add(K).mod(y);s=new l,s.chainCode=b,s.eckey=new d,s.eckey.private=x.toBuffer({size:32}),s.eckey.regenerateSync(),s.hasPrivateKey=!0}else{var u=e.concat([this.eckey.public,t]),v=h.sha512hmac(u,this.chainCode),p=a.fromBuffer(v.slice(0,32),{size:32}),b=v.slice(32,64),P=new d;P.private=p.toBuffer({size:32}),P.regenerateSync();var w=c.fromKey(P),f=new d;f.public=this.eckey.public;var F=c.fromKey(f),k=c.add(w,F).toKey().public;s=new l,s.chainCode=new e(b);var g=new d;g.public=k,s.eckey=g,s.hasPrivateKey=!1}return s.childIndex=i,s.parentFingerprint=this.pubKeyHash.slice(0,4),s.version=this.version,s.depth=this.depth+1,s.eckey.compressed=!0,s.pubKeyHash=h.sha256ripe160(s.eckey.public),s.buildExtendedPublicKey(),s.buildExtendedPrivateKey(),s},module.exports=require("soop")(l)}).call(this,require("buffer").Buffer); },{"./Key":"Af1Gom","./Point":"8PQ/SZ","./networks":"ULNIu2","./util/util":"ACyo5H","base58-native":"xtP2pj","bignum":"J4nwo8","buffer":75,"crypto":79,"soop":146}],"KqTx5b":[function(require,module,exports){ (function(t){function e(t){"object"!=typeof t&&(t={}),this.hash=t.hash||null,this.prev_hash=t.prev_hash||i.NULL_HASH,this.merkle_root=t.merkle_root||i.NULL_HASH,this.timestamp=t.timestamp||0,this.bits=t.bits||0,this.nonce=t.nonce||0,this.version=t.version||0,this.height=t.height||0,this.size=t.size||0,this.active=t.active||!1,this.chainWork=t.chainWork||i.EMPTY_BUFFER,this.txs=t.txs||[]}var r=require("soop").imports(),i=r.util||require("./util/util"),o=(r.Debug1||function(){},r.Script||require("./Script")),s=r.Bignum||require("bignum"),h=(r.Binary||require("binary"),r.Step||require("step"),r.buffertools||require("buffertools")),n=r.Transaction||require("./Transaction"),a=n.In,c=n.Out,u=n.COINBASE_OP,l=r.VerificationError||require("./util/error").VerificationError,f={maxTimeOffset:7200,largestHash:s(2).pow(256)};e.prototype.getHeader=function(){var e=new t(80),r=0;return e.writeUInt32LE(this.version,r),r+=4,this.prev_hash.copy(e,r),r+=32,this.merkle_root.copy(e,r),r+=32,e.writeUInt32LE(this.timestamp,r),r+=4,e.writeUInt32LE(this.bits,r),r+=4,e.writeUInt32LE(this.nonce,r),r+=4,e},e.prototype.parse=function(t,e){if(this.version=t.word32le(),this.prev_hash=t.buffer(32),this.merkle_root=t.buffer(32),this.timestamp=t.word32le(),this.bits=t.word32le(),this.nonce=t.word32le(),this.txs=[],this.size=0,!e)for(var r=t.varInt(),i=0;r>i;i++){var o=new n;o.parse(t),this.txs.push(o)}},e.prototype.calcHash=function(){var t=this.getHeader();return i.twoSha256(t)},e.prototype.checkHash=function(){return this.hash&&this.hash.length?0==h.compare(this.calcHash(),this.hash):!1},e.prototype.getHash=function(){return this.hash&&this.hash.length||(this.hash=this.calcHash()),this.hash},e.prototype.checkProofOfWork=function(){var t=i.decodeDiffBits(this.bits),e=h.reverse(this.hash);if(h.compare(e,t)>0)throw new l("Difficulty target not met");return!0},e.prototype.getWork=function(){var t=i.decodeDiffBits(this.bits,!0);return f.largestHash.div(t.add(1))},e.prototype.checkTimestamp=function(){var t=(new Date).getTime()/1e3;if(this.timestamp>t+f.maxTimeOffset)throw new l("Timestamp too far into the future");return!0},e.prototype.checkTransactions=function(t){if(!Array.isArray(t)||t.length<=0)throw new l("No transactions");if(!t[0].isCoinBase())throw new l("First tx must be coinbase");for(var e=1;e1;s=Math.floor((s+1)/2)){for(var h=0;s>h;h+=2){var a=Math.min(h+1,s-1),c=r[o+h],u=r[o+a];r.push(i.twoSha256(t.concat([c,u])))}o+=s}return r},e.prototype.calcMerkleRoot=function(t){var e=this.getMerkleTree(t);return e[e.length-1]},e.prototype.checkMerkleRoot=function(e){if(!this.merkle_root||!this.merkle_root.length)throw new l("No merkle root");if(0!==h.compare(this.calcMerkleRoot(e),new t(this.merkle_root)))throw new l("Merkle root incorrect");return!0},e.prototype.checkBlock=function(t){if(!this.checkHash())throw new l("Block hash invalid");if(this.checkProofOfWork(),this.checkTimestamp(),t&&(this.checkTransactions(t),!this.checkMerkleRoot(t)))throw new l("Merkle hash invalid");return!0},e.getBlockValue=function(t){var e=s(50).mul(i.COIN);return e=e.div(s(2).pow(Math.floor(t/21e4)))},e.prototype.getBlockValue=function(){return e.getBlockValue(this.height)},e.prototype.toString=function(){return""},e.prototype.createCoinbaseTx=function(t){var e=new n;return e.ins.push(new a({s:i.EMPTY_BUFFER,q:4294967295,o:u})),e.outs.push(new c({v:i.bigIntToValue(this.getBlockValue()),s:o.createPubKeyOut(t).getBuffer()})),e},e.prototype.solve=function(t,e){var r=this.getHeader(),o=i.decodeDiffBits(this.bits);t.solve(r,o,e)},e.prototype.getStandardizedObject=function(t){var e={hash:i.formatHashFull(this.getHash()),version:this.version,prev_block:i.formatHashFull(this.prev_hash),mrkl_root:i.formatHashFull(this.merkle_root),time:this.timestamp,bits:this.bits,nonce:this.nonce,height:this.height};if(t){var r=this.getMerkleTree(t).map(function(t){return i.formatHashFull(t)});e.mrkl_root=r[r.length-1],e.n_tx=t.length;var o=80;o+=i.getVarIntSize(t.length),t=t.map(function(t){return t=t.getStandardizedObject(),o+=t.size,t}),e.size=o,e.tx=t,e.mrkl_tree=r}else e.size=this.size;return e},module.exports=require("soop")(e)}).call(this,require("buffer").Buffer); },{"./Script":"clx6XL","./Transaction":"RNv6Te","./util/error":155,"./util/util":"ACyo5H","bignum":"J4nwo8","binary":62,"buffer":75,"buffertools":"fugeBw","soop":146,"step":147}],"./Block":[function(require,module,exports){ module.exports=require('KqTx5b'); },{}],"ZnXdbH":[function(require,module,exports){ function Bloom(){this.data="",this.hashFuncs=0}function ROTL32(t,n){return t<>32-n}function getBlockU32(t,n){var o=4*t,s=n[o+0]<<0|n[o+1]<<8|n[o+2]<<16|n[o+3]<<24;return s}function toInt(t){return~~t}function min(t,n){return n>t?t:n}var MAX_BLOOM_FILTER_SIZE=36e3,MAX_HASH_FUNCS=50,LN2SQUARED=.48045301391820144,LN2=.6931471805599453,bit_mask=[1,2,4,8,16,32,64,128];Bloom.prototype.hash=function(t,n){for(var o=t*(4294967295/(this.hashFuncs-1)),s=3432918353,a=461845907,h=n.length/4,i=-h;i;i++){var r=getBlockU32(i);r*=s,r=ROTLF32(r,15),r*=a,o^=r,o=ROTFL(o,13),o=5*o+3864292196}var e=n.slice(4*h),r=0;switch(3&n.length){case 3:r^=e[2]<<16;case 2:r^=e[1]<<8;case 1:r^=e[0],r*=s,r=ROTL32(r,15),r*=a,o^=r}return o^=n.length,o^=o>>16,o*=2246822507,o^=o>>13,o*=3266489909,o^=o>>16,o%(8*this.data.length)},Bloom.prototype.insert=function(t){for(var n=0;n>3]|=bit_mask[7&o]}},Bloom.prototype.contains=function(t){for(var n=0;n>3]&bit_mask[7&o]))return!1}return!0},Bloom.prototype.sizeOk=function(){return this.data.length<=MAX_BLOOM_FILTER_SIZE&&this.hashFuncs<=MAX_HASH_FUNCS},Bloom.prototype.init=function(t,n){var o=min(toInt(-1/LN2SQUARED*t*Math.log(n)),8*MAX_BLOOM_FILTER_SIZE)/8;this.data[o]=0,this.hashFuncs=min(toInt(8*this.data.length/t*LN2),MAX_HASH_FUNCS)},module.exports=require("soop")(Bloom); },{"soop":146}],"./Bloom":[function(require,module,exports){ module.exports=require('ZnXdbH'); },{}],"./Buffers.monkey":[function(require,module,exports){ module.exports=require('jmkPxi'); },{}],"jmkPxi":[function(require,module,exports){ (function(f){exports.patch=function(t){t.prototype.skip=function(t){if(0!=t){if(t==this.length)return this.buffers=[],void(this.length=0);var s=this.pos(t);this.buffers=this.buffers.slice(s.buf),this.buffers[0]=new f(this.buffers[0].slice(s.offset)),this.length-=t}}}}).call(this,require("buffer").Buffer); },{"buffer":75}],"./Connection":[function(require,module,exports){ module.exports=require('h81grl'); },{}],"h81grl":[function(require,module,exports){ (function(e){function t(e,r){t.super(this,arguments),this.socket=e,this.peer=r,this.active=!1,this.recvVer=0,this.sendVer=0,this.bestHeight=0,this.inbound=!!e.server,this.getaddr=!1,this.buffers=new c,(new Date).getTime()>1329696e6&&(this.recvVer=209,this.sendVer=209),this.setupHandlers()}var r=require("soop").imports(),s=r.config||require("./config"),n=r.log||require("./util/log"),i=r.network||require("./networks")[s.network],o=1e7,a=7e4,h=(r.Binary||require("binary"),r.Put||require("bufferput")),c=r.Buffers||require("buffers");require("./Buffers.monkey").patch(c);var d=require("./Block"),f=require("./Transaction"),u=r.util||require("./util/util"),p=r.Parser||require("./util/BinaryParser"),g=r.buffertools||require("buffertools"),l=r.doubleSha256||u.twoSha256,v=u.generateNonce(),b=6e4;t.parent=r.parent||require("events").EventEmitter,t.prototype.setupHandlers=function(){this.socket.addListener("connect",this.handleConnect.bind(this)),this.socket.addListener("error",this.handleError.bind(this)),this.socket.addListener("end",this.handleDisconnect.bind(this)),this.socket.addListener("data",function(e){var t=35;n.debug("["+this.peer+"] Recieved "+e.length+" bytes of data:"),n.debug("... "+g.toHex(e.slice(0,t>e.length?e.length:t))+(e.length>t?"...":""))}.bind(this)),this.socket.addListener("data",this.handleData.bind(this))},t.prototype.handleConnect=function(){this.inbound||this.sendVersion(),this.emit("connect",{conn:this,socket:this.socket,peer:this.peer})},t.prototype.handleError=function(e){110==e.errno||"ETIMEDOUT"==e.errno?n.info("connection timed out for "+this.peer):111==e.errno||"ECONNREFUSED"==e.errno?n.info("connection refused for "+this.peer):n.warn("connection with "+this.peer+" "+e.toString()),this.emit("error",{conn:this,socket:this.socket,peer:this.peer,err:e})},t.prototype.handleDisconnect=function(){this.emit("disconnect",{conn:this,socket:this.socket,peer:this.peer})},t.prototype.handleMessage=function(t){if(t){try{switch(t.command){case"version":if(0===g.compare(v,t.nonce))return void this.socket.end();this.inbound&&this.sendVersion(),t.version>=209&&this.sendMessage("verack",new e([])),this.sendVer=Math.min(t.version,a),t.version<209?this.recvVer=Math.min(t.version,a):this.once("verack",function(){this.recvVer=t.version}.bind(this)),this.bestHeight=t.start_height;break;case"verack":this.recvVer=Math.min(t.version,a),this.active=!0;break;case"ping":"object"==typeof t.nonce&&this.sendPong(t.nonce)}}catch(r){return void n.err('Error while handling "'+t.command+'" message from '+this.peer+":\n"+(r.stack?r.stack:r.toString()))}this.emit(t.command,{conn:this,socket:this.socket,peer:this.peer,message:t})}},t.prototype.sendPong=function(e){this.sendMessage("pong",e)},t.prototype.sendVersion=function(){var t="/BitcoinX:0.1/",r=new h;r.word32le(a),r.word64le(1),r.word64le(Math.round((new Date).getTime()/1e3)),r.pad(26),r.pad(26),r.put(v),r.varint(t.length),r.put(new e(t,"ascii")),r.word32le(0),this.sendMessage("version",r.buffer())},t.prototype.sendGetBlocks=function(t,r,s){r=r||u.NULL_HASH;var n=new h;n.word32le(this.sendVer),n.varint(t.length);for(var i=0;i12)throw"Command name too long";var a;a=this.sendVer>=209?l(r).slice(0,4):new e([]);var c=new h;c.put(s),c.put(o),c.pad(12-o.length),c.word32le(r.length),c.put(a),c.put(r);var d=c.buffer();n.debug("["+this.peer+"] Sending message "+t+" ("+r.length+" bytes)"),this.socket.write(d)}catch(f){n.err("Error while sending message to peer "+this.peer+": "+(f.stack?f.stack:f.toString()))}},t.prototype.handleData=function(e){return this.buffers.push(e),this.buffers.length>o?(n.err("Peer "+this.peer+" exceeded maxreceivebuffer, disconnecting."+(err.stack?err.stack:err.toString())),void this.socket.destroy()):void this.processData()},t.prototype.processData=function(){if(!(this.buffers.length<20)){for(var e=i.magic,t=0;;){if(this.buffers.get(t)===e[0]&&this.buffers.get(t+1)===e[1]&&this.buffers.get(t+2)===e[2]&&this.buffers.get(t+3)===e[3]){0!==t&&(n.debug("["+this.peer+"] Received "+t+" bytes of inter-message garbage: "),n.debug("... "+this.buffers.slice(0,t)),this.buffers.skip(t));break}if(t>this.buffers.length-4)return void this.buffers.skip(t);t++}var r=this.buffers.get(16)+(this.buffers.get(17)<<8)+(this.buffers.get(18)<<16)+(this.buffers.get(19)<<24),s=this.recvVer>=209?24:20,o=s+r;if(!(this.buffers.length=209?this.buffers.slice(20,24):null;if(n.debug("["+this.peer+"] Received message "+a+" ("+r+" bytes)"),null!==c){var d=l(h).slice(0,4);if(0!==g.compare(d,c))return void n.err("["+this.peer+"] Checksum failed",{cmd:a,expected:d.toString("hex"),actual:c.toString("hex")})}var f;try{f=this.parseMessage(a,h)}catch(u){n.err("Error while parsing message "+a+" from "+this.peer+":\n"+(u.stack?u.stack:u.toString()))}f&&this.handleMessage(f),this.buffers.skip(o),this.processData()}}},t.prototype.parseMessage=function(e,t){var r,s=new p(t),i={command:e};switch(e){case"version":i.version=s.word32le(),i.services=s.word64le(),i.timestamp=s.word64le(),i.addr_me=s.buffer(26),i.addr_you=s.buffer(26),i.nonce=s.buffer(8),i.subversion=s.varStr(),i.start_height=s.word32le();break;case"inv":case"getdata":for(i.count=s.varInt(),i.invs=[],r=0;rr;r++)i.starts.push(s.buffer(32));i.stop=s.buffer(32);break;case"addr":var u=s.varInt();for(u>1e3&&(u=1e3),i.addrs=[],r=0;u>r;r++)i.addrs.push({time:s.word32le(),services:s.word64le(),ip:s.buffer(16),port:s.word16be()});break;case"alert":i.payload=s.varStr(),i.signature=s.varStr();break;case"ping":this.recvVer>b&&(i.nonce=s.buffer(8));break;case"getaddr":case"verack":case"reject":break;default:return n.err("Connection.parseMessage(): Command not implemented",{cmd:e}),null}return i},module.exports=require("soop")(t)}).call(this,require("buffer").Buffer); },{"./Block":"KqTx5b","./Buffers.monkey":"jmkPxi","./Transaction":"RNv6Te","./config":"4itQ50","./networks":"ULNIu2","./util/BinaryParser":"b3ZSD7","./util/log":"AdF7pF","./util/util":"ACyo5H","binary":62,"buffer":75,"bufferput":"aXRuS6","buffers":"OBo3aV","buffertools":"fugeBw","events":84,"soop":146}],"ypnq12":[function(require,module,exports){ exports.intFromCompact=function(r){var t=(r>>>24&255)>>>0,n=(16777215&r)<<8*(t-3)>>>0;return n}; },{}],"./Deserialize":[function(require,module,exports){ module.exports=require('ypnq12'); },{}],"./Gruntfile":[function(require,module,exports){ module.exports=require('NbSoFu'); },{}],"NbSoFu":[function(require,module,exports){ "use strict";module.exports=function(s){s.loadNpmTasks("grunt-contrib-watch"),s.loadNpmTasks("grunt-mocha-test"),s.loadNpmTasks("grunt-markdown"),s.loadNpmTasks("grunt-shell"),s.initConfig({shell:{browserify:{options:{stdout:!0,stderr:!0},command:"dev"===s.option("target")?"node ./browser/build.js -a -d ":"node ./browser/build.js -a"}},watch:{readme:{files:["README.md"],tasks:["markdown"]},scripts:{files:["**/*.js","**/*.html","!**/node_modules/**","!browser/bundle.js","!browser/testdata.js","!browser/vendor-bundle.js"],tasks:["shell"]}},mochaTest:{options:{reporter:"spec"},src:["test/*.js"]},markdown:{all:{files:[{expand:!0,src:"README.md",dest:".",ext:".html"}]}}}),s.registerTask("default",["shell","watch"])}; },{}],"./Key":[function(require,module,exports){ module.exports=require('Af1Gom'); },{}],"Af1Gom":[function(require,module,exports){ (function(e,r){if(e.versions){var t=require("bindings")("KeyModule"),s=t.Key;module.exports=s}else{var o=require("./browser/vendor-bundle.js").ECKey,n=require("buffertools"),i=function(){this._pub=null,this.compressed=!0},u=i.bufferToArray=function(e){for(var r=[],t=e.length,s=0;t>s;s++)r.push(e.readUInt8(s));return r};Object.defineProperty(i.prototype,"public",{set:function(e){if(!r.isBuffer(e))throw new Error("Arg should be a buffer");var t=e[0];this.compressed=4!==t,this._pub=e},get:function(){return this._pub}}),i.generateSync=function(){var e=new o;e.setCompressed(!0);var t=e.getPub(),s=new i;return s.private=new r(e.priv.toByteArrayUnsigned()),s.public=new r(t),s},i.prototype.regenerateSync=function(){if(!this.private)throw new Error("Key does not have a private key set");var e=new o(n.toHex(this.private));return e.setCompressed(this.compressed),this.public=new r(e.getPub()),this},i.prototype.signSync=function(e){if(!this.private)throw new Error("Key does not have a private key set");if(!r.isBuffer(e)||32!==e.length)throw new Error("Arg should be a 32 bytes hash buffer");var t=new o(n.toHex(this.private));t.setCompressed(this.compressed);var s=t.sign(u(e));return new r(s)},i.prototype.verifySignature=function(e,r,t){try{var s=this.verifySignatureSync(e,r);t(null,s)}catch(o){t(o)}},i.prototype.verifySignatureSync=function(e,t){var s=this;if(!r.isBuffer(e)||32!==e.length)throw new Error("Arg 1 should be a 32 bytes hash buffer");if(!r.isBuffer(t))throw new Error("Arg 2 should be a buffer");if(!s.public)throw new Error("Key does not have a public key set");var n=new o;n.setPub(u(s.public)),n.setCompressed(s.compressed);var i=u(t),f=n.verify(u(e),i);return f},module.exports=i}}).call(this,require("/Users/ryanxcharles/dev/bitcore/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),require("buffer").Buffer); },{"./browser/vendor-bundle.js":53,"/Users/ryanxcharles/dev/bitcore/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":91,"bindings":66,"buffer":75,"buffertools":"fugeBw"}],"ahN55r":[function(require,module,exports){ exports.patch=function(t){t.prototype.round=function(t){if(!t)return Math.round(this);var r=Math.pow(10,t);return Math.round(this*r)/r}}; },{}],"./Number.monkey":[function(require,module,exports){ module.exports=require('ahN55r'); },{}],"./Opcode":[function(require,module,exports){ module.exports=require('zHwnes'); },{}],"zHwnes":[function(require,module,exports){ function Opcode(O){this.code=O}var imports=require("soop").imports();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=require("soop")(Opcode); },{"soop":146}],"6VMrjH":[function(require,module,exports){ (function(t){function e(r,o,i){if("string"==typeof r){if(r.indexOf(":")&&!o){var n=r.split(":");r=n[0],o=n[1]}this.host=r,this.port=+o||8333}else if(r instanceof e)this.host=r.host,this.port=r.port;else{if(!t.isBuffer(r))throw new Error("Could not instantiate peer, invalid parameter type: "+typeof r);if(0!=s.compare(e.IPV6_IPV4_PADDING,r.slice(0,12)))throw new Error("IPV6 not supported yet! Cannot instantiate host.");this.host=Array.prototype.slice.apply(r.slice(12)).join("."),this.port=+o||8333}this.services=i?i:null,this.lastSeen=0}var r=require("soop").imports(),o=r.Net||require("net"),i=r.Binary||require("binary"),s=r.buffertools||require("buffertools");e.IPV6_IPV4_PADDING=new t([0,0,0,0,0,0,0,0,0,0,255,255]),e.prototype.createConnection=function(){var t=o.createConnection(this.port,this.host);return t},e.prototype.getHostAsBuffer=function(){return new t(this.host.split("."))},e.prototype.toString=function(){return this.host+":"+this.port},e.prototype.toBuffer=function(){var t=i.put();return t.word32le(this.lastSeen),t.word64le(this.services),t.put(this.getHostAsBuffer()),t.word16be(this.port),t.buffer()},module.exports=require("soop")(e)}).call(this,require("buffer").Buffer); },{"binary":62,"buffer":75,"buffertools":"fugeBw","net":71,"soop":146}],"./Peer":[function(require,module,exports){ module.exports=require('6VMrjH'); },{}],"./PeerManager":[function(require,module,exports){ module.exports=require('z6R5yC'); },{}],"z6R5yC":[function(require,module,exports){ function PeerManager(){this.active=!1,this.timer=null,this.peers=[],this.connections=[],this.isConnected=!1,this.peerDiscovery=!1,this.interval=5e3,this.minConnections=8,this.minKnownPeers=10}var imports=require("soop").imports(),config=imports.config||require("./config"),log=imports.log||require("./util/log"),network=imports.network||require("./networks")[config.network],Connection=imports.Connection||require("soop").load("./Connection",{config:config,network:network})||require("./Connection"),Peer=imports.Peer||require("./Peer");GetAdjustedTime=imports.GetAdjustedTime||function(){return Math.floor((new Date).getTime()/1e3)},PeerManager.parent=imports.parent||require("events").EventEmitter,PeerManager.Connection=Connection,PeerManager.prototype.start=function(){this.active=!0,this.timer||(this.timer=setInterval(this.checkStatus.bind(this),this.interval))},PeerManager.prototype.stop=function(){this.active=!1,this.timer&&(clearInterval(this.timer),this.timer=null);for(var e=0;e=31402||this.peers.length<1e3)&&(e.conn.sendGetAddr(),e.conn.getaddr=!0)},PeerManager.prototype.handleReady=function(e){log.info("connected to "+e.conn.peer.host+":"+e.conn.peer.port),this.emit("connect",{pm:this,conn:e.conn,socket:e.socket,peer:e.peer}),0==this.isConnected&&(this.emit("netConnected",e),this.isConnected=!0)},PeerManager.prototype.handleAddr=function(e){if(this.peerDiscovery){var n=GetAdjustedTime();e.message.addrs.forEach(function(e){try{(e.time<=1e8||e.time>n+600)&&(e.time=n-432e3);var t=new Peer(e.ip,e.port,e.services);t.lastSeen=e.time,this.peers.push(t)}catch(r){log.warn("Invalid addr received: "+r.message)}}.bind(this)),e.message.addrs.length<1e3&&(e.conn.getaddr=!1)}},PeerManager.prototype.handleGetAddr=function(){},PeerManager.prototype.handleError=function(e){log.err("unkown error with peer "+e.peer+" (disconnecting): "+e.err),this.handleDisconnect.apply(this,[].slice.call(arguments))},PeerManager.prototype.handleDisconnect=function(e){log.info("disconnected from peer "+e.peer);var n=this.connections.indexOf(e.conn);-1!=n&&this.connections.splice(n,1),this.connections.length||(this.emit("netDisconnected"),this.isConnected=!1)},PeerManager.prototype.getActiveConnection=function(){var e=this.connections.filter(function(e){return e.active});if(e.length){var n=Math.floor(Math.random()*e.length),t=e[n];return t.socket.writable?t:(e.splice(n,1),this.getActiveConnection())}return null},PeerManager.prototype.getActiveConnections=function(){return this.connections.slice(0)},module.exports=require("soop")(PeerManager); },{"./Connection":"h81grl","./Peer":"6VMrjH","./config":"4itQ50","./networks":"ULNIu2","./util/log":"AdF7pF","events":84,"soop":146}],"./Point":[function(require,module,exports){ module.exports=require('8PQ/SZ'); },{}],"8PQ/SZ":[function(require,module,exports){ (function(e,r){"use strict";var s=require("soop").imports(),o=s.Key||require("./Key"),n=s.bignum||require("bignum"),t=require("assert");if(!e.versions){var i=require("./browser/vendor-bundle.js").ECKey,u=require("./browser/vendor-bundle.js").ECPointFp,f=require("./browser/vendor-bundle.js").ECFieldElementFp,d=require("./browser/vendor-bundle.js").getSECCurveByName,c=require("./browser/vendor-bundle.js").BigInteger;require("chai").should()}var l=function(e,r){this.x=e,this.y=r};l.add=function(s,i){if(e.versions){var g=s.toKey();g.compressed=!1;var p=i.toKey();p.compressed=!1;var w=o.addUncompressed(g.public,p.public),b=new o;return b.compressed=!1,b.public=w,b.compressed=!0,l.fromKey(b)}var m=d("secp256k1"),v=s.x.toBuffer({size:32}).toString("hex"),a=new c(v,16),y=s.y.toBuffer({size:32}).toString("hex"),B=new c(y,16),h=new f(m.getCurve().getQ(),a),C=new f(m.getCurve().getQ(),B),x=new u(m.getCurve(),h,C),z=i.x.toBuffer({size:32}).toString("hex"),q=new c(z,16),K=i.y.toBuffer({size:32}).toString("hex"),j=new c(K,16),P=new f(m.getCurve().getQ(),q),E=new f(m.getCurve().getQ(),j),S=new u(m.getCurve(),P,E),A=x.add(S),Q=new l,U=new r(A.getX().toBigInteger().toByteArrayUnsigned());Q.x=n.fromBuffer(U,{size:U.length}),t(U.length<=32);var F=new r(A.getY().toBigInteger().toByteArrayUnsigned());return t(F.length<=32),Q.y=n.fromBuffer(F,{size:F.length}),Q},l.fromKey=function(s){if(e.versions){var t=new l,u=new r(s.public),f=new o;return f.compressed=s.compressed,f.public=u,f.compressed=!1,t.x=n.fromBuffer(f.public.slice(1,33),{size:32}),t.y=n.fromBuffer(f.public.slice(33,65),{size:32}),t}var t=new l,u=new r(s.public),f=new i;return f.setCompressed(s.compressed),f.setPub(o.bufferToArray(u)),f.setCompressed(!1),t.x=n.fromBuffer(new r(f.getPub()).slice(1,33),{size:32}),t.y=n.fromBuffer(new r(f.getPub()).slice(33,65),{size:32}),t},l.prototype.toKey=function(){if(e.versions){var s=this.x.toBuffer({size:32}),n=this.y.toBuffer({size:32}),t=new o;t.compressed=!1;var u=new r([4]);return t.public=r.concat([u,s,n]),t.compressed=!0,t}var s=this.x.toBuffer({size:32}),n=this.y.toBuffer({size:32}),t=new i;t.setCompressed(!1);var u=new r([4]),f=r.concat([u,s,n]);t.setPub(o.bufferToArray(f)),t.setCompressed(!0);var d=new o;return d.public=new r(t.getPub()),d},module.exports=require("soop")(l)}).call(this,require("/Users/ryanxcharles/dev/bitcore/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),require("buffer").Buffer); },{"./Key":"Af1Gom","./browser/vendor-bundle.js":53,"/Users/ryanxcharles/dev/bitcore/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":91,"assert":72,"bignum":"J4nwo8","buffer":75,"chai":112,"soop":146}],"./PrivateKey":[function(require,module,exports){ module.exports=require('+A60Qr'); },{}],"+A60Qr":[function(require,module,exports){ (function(t){function e(t,i,r){e.super(this,arguments),void 0!==r&&this.compressed(r)}var i=require("soop").imports(),r=i.parent||require("./util/VersionedData"),n=i.networks||require("./networks");e.parent=r,r.applyEncodingsTo(e),e.prototype.validate=function(){if(this.doAsBinary(function(){if(e.super(this,"validate",arguments),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")},e.prototype.payload=function(t){if(t)return this.doAsBinary(function(){t.copy(this.data,1)}),t;var e=this.as("binary");return 34==e.length?e.slice(1,33):33==e.length?e.slice(1):void 0},e.prototype.compressed=function(e){if(void 0===e){var i=34,r=this.as("binary");if(r.length==i&&1==r[i-1])return!0;if(r.length==i-1)return!1;throw new Error("invalid private key")}this.doAsBinary(function(){var i=34;if(e){var r=new t(i);this.data.copy(r),this.data=r,this.data[i-1]=1}else this.data=this.data.slice(0,i-1)})},e.prototype.network=function(){var t,e=this.version(),i=n.livenet,r=n.testnet;return e===i.privKeyVersion?t=i:e===r.privKeyVersion&&(t=r),t},module.exports=require("soop")(e)}).call(this,require("buffer").Buffer); },{"./networks":"ULNIu2","./util/VersionedData":"QLzNQg","buffer":75,"soop":146}],"Svwrvc":[function(require,module,exports){ (function(t){function e(t){t=t||{},this.host=t.host||"127.0.0.1",this.port=t.port||8332,this.user=t.user||"user",this.pass=t.pass||"pass",this.protocol="http"==t.protocol?n:i,this.batchedCalls=null,this.disableAgent=t.disableAgent||!1}function r(t,e,r){function s(t,e){return function(){var s=arguments.length-1;if(this.batchedCalls)var s=arguments.length;for(var o=0;s>o;o++)e[o]&&(arguments[o]=e[o](arguments[o]));this.batchedCalls?this.batchedCalls.push({jsonrpc:"2.0",method:t,params:c(arguments)}):r.call(this,{method:t,params:c(arguments,0,arguments.length-1)},arguments[arguments.length-1])}}var o={str:function(t){return t.toString()},"int":function(t){return parseFloat(t)},"float":function(t){return parseFloat(t)},bool:function(t){return t===!0||"1"==t||"true"==t||"true"==t.toString().toLowerCase()}};for(var n in e)if(e.hasOwnProperty(n)){for(var i=e[n].split(" "),a=0;a=OP_1&&OP_16>=t}function prefixSize(t){return OP_PUSHDATA1>t?1:255>=t?2:65535>=t?3:5}function encodeLen(t){var r=void 0;return OP_PUSHDATA1>t?(r=new Buffer(1),r.writeUInt8(t,0)):255>=t?(r=new Buffer(2),r.writeUInt8(OP_PUSHDATA1,0),r.writeUInt8(t,1)):65535>=t?(r=new Buffer(3),r.writeUInt8(OP_PUSHDATA2,0),r.writeUInt16LE(t,1)):(r=new Buffer(5),r.writeUInt8(OP_PUSHDATA4,0),r.writeUInt32LE(t,1)),r}var imports=require("soop").imports(),config=imports.config||require("./config"),log=imports.log||require("./util/log"),Opcode=imports.Opcode||require("./Opcode"),buffertools=imports.buffertools||require("buffertools");for(var i in Opcode.map)eval(i+" = "+Opcode.map[i]+";");var util=imports.util||require("./util/util"),Parser=imports.Parser||require("./util/BinaryParser"),Put=imports.Put||require("bufferput"),TX_UNKNOWN=0,TX_PUBKEY=1,TX_PUBKEYHASH=2,TX_MULTISIG=3,TX_SCRIPTHASH=4,TX_TYPES=["unknown","pubkey","pubkeyhash","multisig","scripthash"];Script.TX_UNKNOWN=TX_UNKNOWN,Script.TX_PUBKEY=TX_PUBKEY,Script.TX_PUBKEYHASH=TX_PUBKEYHASH,Script.TX_MULTISIG=TX_MULTISIG,Script.TX_SCRIPTHASH=TX_SCRIPTHASH,Script.prototype.parse=function(){this.chunks=[];for(var t=new Parser(this.buffer);!t.eof();){var r,e,i=t.word8();i>0&&OP_PUSHDATA1>i?this.chunks.push(t.buffer(i)):i===OP_PUSHDATA1?(r=t.word8(),e=t.buffer(r),this.chunks.push(e)):i===OP_PUSHDATA2?(r=t.word16le(),e=t.buffer(r),this.chunks.push(e)):i===OP_PUSHDATA4?(r=t.word32le(),e=t.buffer(r),this.chunks.push(e)):this.chunks.push(i)}},Script.prototype.isPushOnly=function(){for(var t=0;tOP_16)return!1}return!0},Script.prototype.isP2SH=function(){return 3==this.chunks.length&&this.chunks[0]==OP_HASH160&&Buffer.isBuffer(this.chunks[1])&&20==this.chunks[1].length&&this.chunks[2]==OP_EQUAL},Script.prototype.isPubkey=function(){return 2==this.chunks.length&&Buffer.isBuffer(this.chunks[0])&&this.chunks[1]==OP_CHECKSIG},Script.prototype.isPubkeyHash=function(){return 5==this.chunks.length&&this.chunks[0]==OP_DUP&&this.chunks[1]==OP_HASH160&&Buffer.isBuffer(this.chunks[2])&&20==this.chunks[2].length&&this.chunks[3]==OP_EQUALVERIFY&&this.chunks[4]==OP_CHECKSIG},Script.prototype.isMultiSig=function(){return this.chunks.length>3&&isSmallIntOp(this.chunks[0])&&isSmallIntOp(this.chunks[this.chunks.length-2])&&this.chunks[this.chunks.length-1]==OP_CHECKMULTISIG},Script.prototype.finishedMultiSig=function(){for(var t=0,r=0;ri;i++){var u=this.chunks[i];if(i>0&&(e+=" "),e+=Buffer.isBuffer(u)?"0x"+util.formatBuffer(u,t?null:0):Opcode.reverseMap[u],r&&i>r){e+=" ...";break}}return e},Script.prototype.toString=function(t,r){var e="