streamium
Version:
Decentralized trustless video streaming using bitcoin payment channels.
3 lines (2 loc) • 554 kB
JavaScript
require=function e(t,r,n){function i(o,a){if(!r[o]){if(!t[o]){var f="function"==typeof require&&require;if(!a&&f)return f(o,!0);if(s)return s(o,!0);var c=new Error("Cannot find module '"+o+"'");throw c.code="MODULE_NOT_FOUND",c}var u=r[o]={exports:{}};t[o][0].call(u.exports,function(e){var r=t[o][1][e];return i(r?r:e)},u,u.exports,e,t,r,n)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(e,t,r){(function(r){"use strict";function n(e,t,r){if(!(this instanceof n))return new n(e,t,r);if(i.isArray(e)&&i.isNumber(t))return n.createMultisig(e,t,r);if(e instanceof n)return e;if(s.checkArgument(e,"First argument is required, please include address data.","guide/address.html"),t&&!f.get(t))throw new TypeError('Second argument must be "livenet" or "testnet".');if(r&&r!==n.PayToPublicKeyHash&&r!==n.PayToScriptHash)throw new TypeError('Third argument must be "pubkeyhash" or "scripthash".');var o=this._classifyArguments(e,t,r);return o.network=o.network||f.get(t)||f.defaultNetwork,o.type=o.type||r||n.PayToPublicKeyHash,u.defineImmutable(this,{hashBuffer:o.hashBuffer,network:o.network,type:o.type}),this}var i=e("lodash"),s=e("./util/preconditions"),o=e("./errors"),a=e("./encoding/base58check"),f=e("./networks"),c=e("./crypto/hash"),u=e("./util/js"),d=e("./script"),h=e("./publickey");n.prototype._classifyArguments=function(e,t,s){if((e instanceof r||e instanceof Uint8Array)&&20===e.length)return n._transformHash(e);if((e instanceof r||e instanceof Uint8Array)&&21===e.length)return n._transformBuffer(e,t,s);if(e instanceof h)return n._transformPublicKey(e);if(e instanceof d)return n._transformScript(e,t);if("string"==typeof e)return n._transformString(e,t,s);if(i.isObject(e))return n._transformObject(e);throw new TypeError("First argument is an unrecognized data format.")},n.PayToPublicKeyHash="pubkeyhash",n.PayToScriptHash="scripthash",n._transformHash=function(e){var t={};if(!(e instanceof r||e instanceof Uint8Array))throw new TypeError("Address supplied is not a buffer.");if(20!==e.length)throw new TypeError("Address hashbuffers must be exactly 20 bytes.");return t.hashBuffer=e,t},n._transformObject=function(e){return s.checkArgument(e.hash||e.hashBuffer,"Must provide a `hash` or `hashBuffer` property"),s.checkArgument(e.type,"Must provide a `type` property"),{hashBuffer:e.hash?new r(e.hash,"hex"):e.hashBuffer,network:f.get(e.network)||f.defaultNetwork,type:e.type}},n._classifyFromVersion=function(e){var t={},r=f.get(e[0],"pubkeyhash"),i=f.get(e[0],"scripthash");return r?(t.network=r,t.type=n.PayToPublicKeyHash):i&&(t.network=i,t.type=n.PayToScriptHash),t},n._transformBuffer=function(e,t,i){var s={};if(!(e instanceof r||e instanceof Uint8Array))throw new TypeError("Address supplied is not a buffer.");if(21!==e.length)throw new TypeError("Address buffers must be exactly 21 bytes.");t=f.get(t);var o=n._classifyFromVersion(e);if(!o.network||t&&t!==o.network)throw new TypeError("Address has mismatched network type.");if(!o.type||i&&i!==o.type)throw new TypeError("Address has mismatched type.");return s.hashBuffer=e.slice(1),s.network=o.network,s.type=o.type,s},n._transformPublicKey=function(e){var t={};if(!(e instanceof h))throw new TypeError("Address must be an instance of PublicKey.");return t.hashBuffer=c.sha256ripemd160(e.toBuffer()),t.type=n.PayToPublicKeyHash,t},n._transformScript=function(e,t){s.checkArgument(e instanceof d,"script must be a Script instance");var r=e.getAddressInfo(t);if(!r)throw new o.Script.CantDeriveAddress(e);return r},n.createMultisig=function(e,t,r){return r=r||e[0].network||f.defaultNetwork,n.payingTo(d.buildMultisigOut(e,t),r)},n._transformString=function(e,t,r){if("string"!=typeof e)throw new TypeError("data parameter supplied is not a string.");e=e.trim();var i=a.decode(e),s=n._transformBuffer(i,t,r);return s},n.fromPublicKey=function(e,t){var r=n._transformPublicKey(e);return t=t||f.defaultNetwork,new n(r.hashBuffer,t,r.type)},n.fromPublicKeyHash=function(e,t){var r=n._transformHash(e);return new n(r.hashBuffer,t,n.PayToPublicKeyHash)},n.fromScriptHash=function(e,t){s.checkArgument(e,"hash parameter is required");var r=n._transformHash(e);return new n(r.hashBuffer,t,n.PayToScriptHash)},n.payingTo=function(e,t){return s.checkArgument(e,"script is required"),s.checkArgument(e instanceof d,"script must be instance of Script"),n.fromScriptHash(c.sha256ripemd160(e.toBuffer()),t)},n.fromScript=function(e,t){s.checkArgument(e instanceof d,"script must be a Script instance");var r=n._transformScript(e,t);return new n(r.hashBuffer,t,r.type)},n.fromBuffer=function(e,t,r){var i=n._transformBuffer(e,t,r);return new n(i.hashBuffer,i.network,i.type)},n.fromString=function(e,t,r){var i=n._transformString(e,t,r);return new n(i.hashBuffer,i.network,i.type)},n.fromJSON=function(e){u.isValidJSON(e)&&(e=JSON.parse(e)),s.checkState(u.isHexa(e.hash),'Unexpected hash property, "'+e.hash+'", expected to be hex.');var t=new r(e.hash,"hex");return new n(t,e.network,e.type)},n.getValidationError=function(e,t,r){var i;try{new n(e,t,r)}catch(s){i=s}return i},n.isValid=function(e,t,r){return!n.getValidationError(e,t,r)},n.prototype.isPayToPublicKeyHash=function(){return this.type===n.PayToPublicKeyHash},n.prototype.isPayToScriptHash=function(){return this.type===n.PayToScriptHash},n.prototype.toBuffer=function(){var e=new r([this.network[this.type]]),t=r.concat([e,this.hashBuffer]);return t},n.prototype.toObject=function(){return{hash:this.hashBuffer.toString("hex"),type:this.type,network:this.network.toString()}},n.prototype.toJSON=function(){return JSON.stringify(this.toObject())},n.prototype.toString=function(){return a.encode(this.toBuffer())},n.prototype.inspect=function(){return"<Address: "+this.toString()+", type: "+this.type+", network: "+this.network+">"},t.exports=n}).call(this,e("buffer").Buffer)},{"./crypto/hash":8,"./encoding/base58check":13,"./errors":17,"./networks":22,"./publickey":25,"./script":26,"./util/js":42,"./util/preconditions":43,buffer:45,lodash:223}],2:[function(e,t,r){(function(r){"use strict";function n(e){return this instanceof n?(i.extend(this,n._from(e)),this):new n(e)}var i=e("lodash"),s=e("./blockheader"),o=e("../crypto/bn"),a=e("../util/buffer"),f=e("../encoding/bufferreader"),c=e("../encoding/bufferwriter"),u=e("../crypto/hash"),d=e("../util/js"),h=e("../transaction"),p=e("../util/preconditions");n.MAX_BLOCK_SIZE=1e6,n._from=function(e){var t={};if(a.isBuffer(e))t=n._fromBufferReader(f(e));else if(d.isValidJSON(e))t=n._fromJSON(e);else{if(!i.isObject(e))throw new TypeError("Unrecognized argument for Block");t=n._fromObject(e)}return t},n._fromJSON=function(e){return p.checkArgument(d.isValidJSON(e),"data must be valid JSON"),e=JSON.parse(e),n._fromObject(e)},n._fromObject=function(e){var t=[];e.transactions.forEach(function(e){t.push(h().fromJSON(e))});var r={header:s.fromObject(e.header),transactions:t};return r},n.fromJSON=function(e){var t=n._fromJSON(e);return new n(t)},n.fromObject=function(e){var t=n._fromObject(e);return new n(t)},n._fromBufferReader=function(e){var t={};p.checkState(!e.finished(),"No block data received"),t.header=s.fromBufferReader(e);var r=e.readVarintNum();t.transactions=[];for(var n=0;r>n;n++)t.transactions.push(h().fromBufferReader(e));return t},n.fromBufferReader=function(e){p.checkArgument(e,"br is required");var t=n._fromBufferReader(e);return new n(t)},n.fromBuffer=function(e){return n.fromBufferReader(new f(e))},n.fromString=function(e){var t=new r(e,"hex");return n.fromBuffer(t)},n.fromRawBlock=function(e){a.isBuffer(e)||(e=new r(e,"binary"));var t=f(e);t.pos=n.Values.START_OF_BLOCK;var i=n._fromBufferReader(t);return new n(i)},n.prototype.toObject=function(){var e=[];return this.transactions.forEach(function(t){e.push(t.toObject())}),{header:this.header.toObject(),transactions:e}},n.prototype.toJSON=function(){return JSON.stringify(this.toObject())},n.prototype.toBuffer=function(){return this.toBufferWriter().concat()},n.prototype.toString=function(){return this.toBuffer().toString("hex")},n.prototype.toBufferWriter=function(e){e||(e=new c),e.write(this.header.toBuffer()),e.writeVarintNum(this.transactions.length);for(var t=0;t<this.transactions.length;t++)this.transactions[t].toBufferWriter(e);return e},n.prototype.getTransactionHashes=function(){var e=[];if(0===this.transactions.length)return[n.Values.NULL_HASH];for(var t=0;t<this.transactions.length;t++)e.push(this.transactions[t]._getHash());return e},n.prototype.getMerkleTree=function(){for(var e=this.getTransactionHashes(),t=0,n=this.transactions.length;n>1;n=Math.floor((n+1)/2)){for(var i=0;n>i;i+=2){var s=Math.min(i+1,n-1),o=r.concat([e[t+i],e[t+s]]);e.push(u.sha256sha256(o))}t+=n}return e},n.prototype.getMerkleRoot=function(){var e=this.getMerkleTree();return e[e.length-1]},n.prototype.validMerkleRoot=function(){var e=new o(this.header.merkleRoot.toString("hex"),"hex"),t=new o(this.getMerkleRoot().toString("hex"),"hex");return 0!==e.cmp(t)?!1:!0},n.prototype._getHash=function(){return this.header._getHash()};var l={configurable:!1,enumerable:!0,get:function(){return this._id||(this._id=this.header.id),this._id},set:i.noop};Object.defineProperty(n.prototype,"id",l),Object.defineProperty(n.prototype,"hash",l),n.prototype.inspect=function(){return"<Block "+this.id+">"},n.Values={START_OF_BLOCK:8,NULL_HASH:new r("0000000000000000000000000000000000000000000000000000000000000000","hex")},t.exports=n}).call(this,e("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../transaction":29,"../util/buffer":41,"../util/js":42,"../util/preconditions":43,"./blockheader":3,buffer:45,lodash:223}],3:[function(e,t,r){(function(r){"use strict";var n=e("lodash"),i=e("../crypto/bn"),s=e("../util/buffer"),o=e("../encoding/bufferreader"),a=e("../encoding/bufferwriter"),f=e("../crypto/hash"),c=e("../util/js"),u=e("../util/preconditions"),d=function p(e){return this instanceof p?(n.extend(this,p._from(e)),this):new p(e)};d._from=function(e){var t={};if(s.isBuffer(e))t=d._fromBufferReader(o(e));else if(c.isValidJSON(e))t=d._fromJSON(e);else{if(!n.isObject(e))throw new TypeError("Unrecognized argument for BlockHeader");t=d._fromObject(e)}return t},d._fromJSON=function(e){return u.checkArgument(c.isValidJSON(e),"data must be a valid JSON string"),e=JSON.parse(e),d._fromObject(e)},d._fromObject=function(e){u.checkArgument(e,"data is required");var t=e.prevHash,i=e.merkleRoot;n.isString(e.prevHash)&&(t=s.reverse(new r(e.prevHash,"hex"))),n.isString(e.merkleRoot)&&(i=s.reverse(new r(e.merkleRoot,"hex")));var o={version:e.version,prevHash:t,merkleRoot:i,time:e.time,timestamp:e.time,bits:e.bits,nonce:e.nonce};return o},d.fromJSON=function(e){var t=d._fromJSON(e);return new d(t)},d.fromObject=function(e){var t=d._fromObject(e);return new d(t)},d.fromRawBlock=function(e){s.isBuffer(e)||(e=new r(e,"binary"));var t=o(e);t.pos=d.Constants.START_OF_HEADER;var n=d._fromBufferReader(t);return new d(n)},d.fromBuffer=function(e){var t=d._fromBufferReader(o(e));return new d(t)},d.fromString=function(e){var t=new r(e,"hex");return d.fromBuffer(t)},d._fromBufferReader=function(e){var t={};return t.version=e.readUInt32LE(),t.prevHash=e.read(32),t.merkleRoot=e.read(32),t.time=e.readUInt32LE(),t.bits=e.readUInt32LE(),t.nonce=e.readUInt32LE(),t},d.fromBufferReader=function(e){var t=d._fromBufferReader(e);return new d(t)},d.prototype.toObject=function(){return{version:this.version,prevHash:s.reverse(this.prevHash).toString("hex"),merkleRoot:s.reverse(this.merkleRoot).toString("hex"),time:this.time,bits:this.bits,nonce:this.nonce}},d.prototype.toJSON=function(){return JSON.stringify(this.toObject())},d.prototype.toBuffer=function(){return this.toBufferWriter().concat()},d.prototype.toString=function(){return this.toBuffer().toString("hex")},d.prototype.toBufferWriter=function(e){return e||(e=new a),e.writeUInt32LE(this.version),e.write(this.prevHash),e.write(this.merkleRoot),e.writeUInt32LE(this.time),e.writeUInt32LE(this.bits),e.writeUInt32LE(this.nonce),e},d.prototype.getTargetDifficulty=function(e){for(var t=new i(16777215&this.bits),r=8*((this.bits>>>24)-3);r-->0;)t=t.mul(new i(2));return t},d.prototype._getHash=function(){var e=this.toBuffer();return f.sha256sha256(e)};var h={configurable:!1,enumerable:!0,get:function(){return this._id||(this._id=o(this._getHash()).readReverse().toString("hex")),this._id},set:n.noop};Object.defineProperty(d.prototype,"id",h),Object.defineProperty(d.prototype,"hash",h),d.prototype.validTimestamp=function(){var e=Math.round((new Date).getTime()/1e3);return this.time>e+d.Constants.MAX_TIME_OFFSET?!1:!0},d.prototype.validProofOfWork=function(){var e=new i(this.id,"hex"),t=this.getTargetDifficulty();return e.cmp(t)>0?!1:!0},d.prototype.inspect=function(){return"<BlockHeader "+this.id+">"},d.Constants={START_OF_HEADER:8,MAX_TIME_OFFSET:7200,LARGEST_HASH:new i("10000000000000000000000000000000000000000000000000000000000000000","hex")},t.exports=d}).call(this,e("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../util/buffer":41,"../util/js":42,"../util/preconditions":43,buffer:45,lodash:223}],4:[function(e,t,r){t.exports=e("./block"),t.exports.BlockHeader=e("./blockheader"),t.exports.MerkleBlock=e("./merkleblock")},{"./block":2,"./blockheader":3,"./merkleblock":5}],5:[function(e,t,r){(function(r){"use strict";function n(e){if(!(this instanceof n))return new n(e);var t={};if(o.isBuffer(e))t=n._fromBufferReader(a(e));else if(u.isValidJSON(e))t=n._fromJSON(e);else{if(!i.isObject(e))throw new TypeError("Unrecognized argument for MerkleBlock");var r;r=e.header instanceof s?e.header:s.fromJSON(JSON.stringify(e.header)),t={header:r,numTransactions:e.numTransactions,hashes:e.hashes,flags:e.flags}}return i.extend(this,t),this._flagBitsUsed=0,this._hashesUsed=0,this}var i=e("lodash"),s=e("./blockheader"),o=e("../util/buffer"),a=e("../encoding/bufferreader"),f=e("../encoding/bufferwriter"),c=e("../crypto/hash"),u=e("../util/js"),d=e("../transaction"),h=e("../util/preconditions");n.fromBuffer=function(e){return n.fromBufferReader(a(e))},n.fromBufferReader=function(e){return new n(n._fromBufferReader(e))},n.fromJSON=function(e){return new n(n._fromJSON(e))},n.prototype.toBuffer=function(){return this.toBufferWriter().concat()},n.prototype.toBufferWriter=function(e){e||(e=new f),e.write(this.header.toBuffer()),e.writeUInt32LE(this.numTransactions),e.writeVarintNum(this.hashes.length);for(var t=0;t<this.hashes.length;t++)e.write(new r(this.hashes[t],"hex"));for(e.writeVarintNum(this.flags.length),t=0;t<this.flags.length;t++)e.writeUInt8(this.flags[t]);return e},n.prototype.toObject=function(){return{header:this.header.toObject(),numTransactions:this.numTransactions,hashes:this.hashes,flags:this.flags}},n.prototype.toJSON=function(){return JSON.stringify(this.toObject())},n.prototype.validMerkleTree=function(){if(h.checkState(i.isArray(this.flags),"MerkleBlock flags is not an array"),h.checkState(i.isArray(this.hashes),"MerkleBlock hashes is not an array"),this.hashes.length>this.numTransactions)return!1;if(8*this.flags.length<this.hashes.length)return!1;var e=this._calcTreeHeight(),t={hashesUsed:0,flagBitsUsed:0},r=this._traverseMerkleTree(e,0,t);return t.hashesUsed!==this.hashes.length?!1:o.equals(r,this.header.merkleRoot)},n.prototype._traverseMerkleTree=function(e,t,n){if(n=n||{},n.txs=n.txs||[],n.flagBitsUsed=n.flagBitsUsed||0,n.hashesUsed=n.hashesUsed||0,n.flagBitsUsed>8*this.flags.length)return null;var i=this.flags[n.flagBitsUsed>>3]>>>(7&n.flagBitsUsed++)&1;if(0!==e&&i){var s=this._traverseMerkleTree(e-1,2*t,n),o=s;return 2*t+1<this._calcTreeWidth(e-1)&&(o=this._traverseMerkleTree(e-1,2*t+1,n)),c.sha256sha256(new r.concat([s,o]))}if(n.hashesUsed>=this.hashes.length)return null;var a=this.hashes[n.hashesUsed++];return 0===e&&i&&n.txs.push(a),new r(a,"hex")},n.prototype._calcTreeWidth=function(e){return this.numTransactions+(1<<e)-1>>e},n.prototype._calcTreeHeight=function(){for(var e=0;this._calcTreeWidth(e)>1;)e++;return e},n.prototype.hasTransaction=function(e){h.checkArgument(!i.isUndefined(e),"tx cannot be undefined"),h.checkArgument(e instanceof d||"string"==typeof e,'Invalid tx given, tx must be a "string" or "Transaction"');var t=e;e instanceof d&&(t=o.reverse(new r(e.id,"hex")).toString("hex"));var n=[],s=this._calcTreeHeight();return this._traverseMerkleTree(s,0,{txs:n}),-1!==n.indexOf(t)},n._fromBufferReader=function(e){h.checkState(!e.finished(),"No merkleblock data received");var t={};t.header=s.fromBufferReader(e),t.numTransactions=e.readUInt32LE();var r=e.readVarintNum();t.hashes=[];for(var n=0;r>n;n++)t.hashes.push(e.read(32).toString("hex"));var i=e.readVarintNum();for(t.flags=[],n=0;i>n;n++)t.flags.push(e.readUInt8());return t},n._fromJSON=function(e){u.isValidJSON(e)&&(e=JSON.parse(e));var t={header:s.fromObject(e.header),numTransactions:e.numTransactions,hashes:e.hashes,flags:e.flags};return t},t.exports=n}).call(this,e("buffer").Buffer)},{"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../transaction":29,"../util/buffer":41,"../util/js":42,"../util/preconditions":43,"./blockheader":3,buffer:45,lodash:223}],6:[function(e,t,r){(function(r){"use strict";var n=e("bn.js"),i=e("../util/preconditions"),s=e("lodash"),o=function(e){for(var t=new r(e.length),n=0;n<e.length;n++)t[n]=e[e.length-1-n];return t};n.Zero=new n(0),n.One=new n(1),n.Minus1=new n(-1),n.fromNumber=function(e){return i.checkArgument(s.isNumber(e)),new n(e)},n.fromString=function(e){return i.checkArgument(s.isString(e)),new n(e)},n.fromBuffer=function(e,t){"undefined"!=typeof t&&"little"===t.endian&&(e=o(e));var r=e.toString("hex"),i=new n(r,16);return i},n.fromSM=function(e,t){var i;if(0===e.length)return n.fromBuffer(new r([0]));var s="big";return t&&(s=t.endian),"little"===s&&(e=o(e)),128&e[0]?(e[0]=127&e[0],i=n.fromBuffer(e),i.neg().copy(i)):i=n.fromBuffer(e),i},n.prototype.toNumber=function(){return parseInt(this.toString(10),10)},n.prototype.toBuffer=function(e){var t,i;if(e&&e.size){i=this.toString(16,2);var s=i.length/2;t=new r(i,"hex"),s===e.size?t=t:s>e.size?t=n.trim(t,s):s<e.size&&(t=n.pad(t,s,e.size))}else i=this.toString(16,2),t=new r(i,"hex");return"undefined"!=typeof e&&"little"===e.endian&&(t=o(t)),t},n.prototype.toSMBigEndian=function(){var e;return-1===this.cmp(n.Zero)?(e=this.neg().toBuffer(),128&e[0]?e=r.concat([new r([128]),e]):e[0]=128|e[0]):(e=this.toBuffer(),128&e[0]&&(e=r.concat([new r([0]),e]))),1===e.length&0===e[0]&&(e=new r([])),e},n.prototype.toSM=function(e){var t=e?e.endian:"big",r=this.toSMBigEndian();return"little"===t&&(r=o(r)),r},n.fromScriptNumBuffer=function(e,t){var r=4;if(i.checkArgument(e.length<=r,new Error("script number overflow")),t&&e.length>0&&0===(127&e[e.length-1])&&(e.length<=1||0===(128&e[e.length-2])))throw new Error("non-minimally encoded script number");return n.fromSM(e,{endian:"little"})},n.prototype.toScriptNumBuffer=function(){return this.toSM({endian:"little"})},n.prototype.gt=function(e){return this.cmp(e)>0},n.prototype.lt=function(e){return this.cmp(e)<0},n.trim=function(e,t){return e.slice(t-e.length,e.length)},n.pad=function(e,t,n){for(var i=new r(n),s=0;s<e.length;s++)i[i.length-1-s]=e[e.length-1-s];for(s=0;n-t>s;s++)i[s]=0;return i},t.exports=n}).call(this,e("buffer").Buffer)},{"../util/preconditions":43,"bn.js":199,buffer:45,lodash:223}],7:[function(e,t,r){(function(r){"use strict";var n=e("./bn"),i=e("./point"),s=e("./signature"),o=e("../publickey"),a=e("./random"),f=e("./hash"),c=e("../util/buffer"),u=e("lodash"),d=e("../util/preconditions"),h=function p(e){return this instanceof p?void(e&&this.set(e)):new p(e)};h.prototype.set=function(e){return this.hashbuf=e.hashbuf||this.hashbuf,this.endian=e.endian||this.endian,this.privkey=e.privkey||this.privkey,this.pubkey=e.pubkey||(this.privkey?this.privkey.publicKey:this.pubkey),this.sig=e.sig||this.sig,this.k=e.k||this.k,this.verified=e.verified||this.verified,this},h.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()},h.prototype.calci=function(){for(var e=0;4>e;e++){this.sig.i=e;var t;try{t=this.toPublicKey()}catch(r){console.error(r);continue}if(t.point.eq(this.pubkey.point))return this.sig.compressed=this.pubkey.compressed,this}throw this.sig.i=void 0,new Error("Unable to find valid recovery factor")},h.fromString=function(e){var t=JSON.parse(e);return new h(t)},h.prototype.randomK=function(){var e,t=i.getN();do e=n.fromBuffer(a.getRandomBuffer(32));while(!e.lt(t)||!e.gt(n.Zero));return this.k=e,this},h.prototype.deterministicK=function(e){u.isUndefined(e)&&(e=0);var t=new r(32);t.fill(1);var s=new r(32);s.fill(0);var o=this.privkey.bn.toBuffer({size:32});s=f.sha256hmac(r.concat([t,new r([0]),o,this.hashbuf]),s),t=f.sha256hmac(t,s),s=f.sha256hmac(r.concat([t,new r([1]),o,this.hashbuf]),s),t=f.sha256hmac(t,s),t=f.sha256hmac(t,s);for(var a=n.fromBuffer(t),c=i.getN(),d=0;e>d||!a.lt(c)||!a.gt(n.Zero);d++)s=f.sha256hmac(r.concat([t,new r([0])]),s),t=f.sha256hmac(t,s),t=f.sha256hmac(t,s),a=n.fromBuffer(t);return this.k=a,this},h.prototype.toPublicKey=function(){var e=this.sig.i;d.checkArgument(0===e||1===e||2===e||3===e,new Error("i must be equal to 0, 1, 2, or 3"));var t=n.fromBuffer(this.hashbuf),r=this.sig.r,s=this.sig.s,a=1&e,f=e>>1,c=i.getN(),u=i.getG(),h=f?r.add(c):r,p=i.fromX(a,h),l=p.mul(c);if(!l.isInfinity())throw new Error("nR is not a valid curve point");var b=t.neg().mod(c),g=r.invm(c),m=p.mul(s).add(u.mul(b)).mul(g),y=o.fromPoint(m,this.sig.compressed);return y},h.prototype.sigError=function(){if(!c.isBuffer(this.hashbuf)||32!==this.hashbuf.length)return"hashbuf must be a 32 byte buffer";var e=this.sig.r,t=this.sig.s;if(!(e.gt(n.Zero)&&e.lt(i.getN())&&t.gt(n.Zero)&&t.lt(i.getN())))return"r and s not in range";var r=n.fromBuffer(this.hashbuf,this.endian?{endian:this.endian}:void 0),s=i.getN(),o=t.invm(s),a=o.mul(r).mod(s),f=o.mul(e).mod(s),u=i.getG().mulAdd(a,this.pubkey.point,f);return u.isInfinity()?"p is infinity":0!==u.getX().mod(s).cmp(e)?"Invalid signature":!1},h.toLowS=function(e){return e.gt(n.fromBuffer(new r("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))&&(e=i.getN().sub(e)),e},h.prototype._findSignature=function(e,t){var r,s,o,a,f=i.getN(),c=i.getG(),u=0;do(!this.k||u>0)&&this.deterministicK(u),u++,r=this.k,s=c.mul(r),o=s.x.mod(f),a=r.invm(f).mul(t.add(e.mul(o))).mod(f);while(o.cmp(n.Zero)<=0||a.cmp(n.Zero)<=0);return a=h.toLowS(a),{s:a,r:o}},h.prototype.sign=function(){var e=this.hashbuf,t=this.privkey,r=t.bn;d.checkState(e&&t&&r,new Error("invalid parameters")),d.checkState(c.isBuffer(e)&&32===e.length,new Error("hashbuf must be a 32 byte buffer"));var i=n.fromBuffer(e,this.endian?{endian:this.endian}:void 0),o=this._findSignature(r,i);return o.compressed=this.pubkey.compressed,this.sig=new s(o),this},h.prototype.signRandomK=function(){return this.randomK(),this.sign()},h.prototype.toString=function(){var e={};return this.hashbuf&&(e.hashbuf=this.hashbuf.toString("hex")),this.privkey&&(e.privkey=this.privkey.toString()),this.pubkey&&(e.pubkey=this.pubkey.toString()),this.sig&&(e.sig=this.sig.toString()),this.k&&(e.k=this.k.toString()),JSON.stringify(e)},h.prototype.verify=function(){return this.verified=this.sigError()?!1:!0,this},h.sign=function(e,t,r){return h().set({hashbuf:e,endian:r,privkey:t}).sign().sig},h.verify=function(e,t,r,n){return h().set({hashbuf:e,endian:n,sig:t,pubkey:r}).verify().verified},t.exports=h}).call(this,e("buffer").Buffer)},{"../publickey":25,"../util/buffer":41,"../util/preconditions":43,"./bn":6,"./hash":8,"./point":9,"./random":10,"./signature":11,buffer:45,lodash:223}],8:[function(e,t,r){(function(r){"use strict";var n=e("hash.js"),i=e("sha512"),s=e("crypto"),o=e("../util/buffer"),a=e("../util/preconditions"),f=t.exports;f.sha1=function(e){return a.checkArgument(o.isBuffer(e)),s.createHash("sha1").update(e).digest()},f.sha1.blocksize=512,f.sha256=function(e){return a.checkArgument(o.isBuffer(e)),s.createHash("sha256").update(e).digest()},f.sha256.blocksize=512,f.sha256sha256=function(e){return a.checkArgument(o.isBuffer(e)),f.sha256(f.sha256(e))},f.ripemd160=function(e){a.checkArgument(o.isBuffer(e));var t=(new n.ripemd160).update(e).digest();return new r(t)},f.sha256ripemd160=function(e){return a.checkArgument(o.isBuffer(e)),f.ripemd160(f.sha256(e))},f.sha512=function(e){a.checkArgument(o.isBuffer(e));var t=i(e);return new r(t)},f.sha512.blocksize=1024,f.hmac=function(e,t,n){a.checkArgument(o.isBuffer(t)),a.checkArgument(o.isBuffer(n)),a.checkArgument(e.blocksize);var i=e.blocksize/8;if(n.length>i)n=e(n);else if(i>n){var s=new r(i);s.fill(0),n.copy(s),n=s}var f=new r(i);f.fill(92);var c=new r(i);c.fill(54);for(var u=new r(i),d=new r(i),h=0;i>h;h++)u[h]=f[h]^n[h],d[h]=c[h]^n[h];return e(r.concat([u,e(r.concat([d,t]))]))},f.sha256hmac=function(e,t){return f.hmac(f.sha256,e,t)},f.sha512hmac=function(e,t){return f.hmac(f.sha512,e,t)}}).call(this,e("buffer").Buffer)},{"../util/buffer":41,"../util/preconditions":43,buffer:45,crypto:49,"hash.js":216,sha512:226}],9:[function(e,t,r){(function(r){"use strict";var n=e("./bn"),i=e("../util/buffer"),s=e("elliptic").curves.secp256k1,o=s.curve.point.bind(s.curve),a=s.curve.pointFromX.bind(s.curve),f=function(e,t,r){var n=o(e,t,r);return n.validate(),n};f.prototype=Object.getPrototypeOf(s.curve.point()),f.fromX=function(e,t){var r=a(e,t);return r.validate(),r},f.getG=function(){return s.curve.g},f.getN=function(){return new n(s.curve.n.toArray())},f.prototype._getX=f.prototype.getX,f.prototype.getX=function(){return new n(this._getX().toArray())},f.prototype._getY=f.prototype.getY,f.prototype.getY=function(){return new n(this._getY().toArray())},f.prototype.validate=function(){if(this.isInfinity())throw new Error("Point cannot be equal to Infinity");if(0===this.getX().cmp(n.Zero)||0===this.getY().cmp(n.Zero))throw new Error("Invalid x,y value for curve, cannot equal 0.");var e=a(this.getY().isOdd(),this.getX());if(0!==e.y.cmp(this.y))throw new Error("Invalid y value for curve.");var t=this.getX().gt(n.Minus1)&&this.getX().lt(f.getN()),r=this.getY().gt(n.Minus1)&&this.getY().lt(f.getN());if(!t||!r)throw new Error("Point does not lie on the curve");if(!this.mul(f.getN()).isInfinity())throw new Error("Point times N must be infinity");return this},f.pointToCompressed=function(e){var t,n=e.getX().toBuffer({size:32}),s=e.getY().toBuffer({size:32}),o=s[s.length-1]%2;return t=new r(o?[3]:[2]),i.concat([t,n])},t.exports=f}).call(this,e("buffer").Buffer)},{"../util/buffer":41,"./bn":6,buffer:45,elliptic:201}],10:[function(e,t,r){(function(r,n){"use strict";function i(){}i.getRandomBuffer=function(e){return r.browser?i.getRandomBufferBrowser(e):i.getRandomBufferNode(e)},i.getRandomBufferNode=function(t){var r=e("crypto");return r.randomBytes(t)},i.getRandomBufferBrowser=function(e){if(!window.crypto&&!window.msCrypto)throw new Error("window.crypto not available");if(window.crypto&&window.crypto.getRandomValues)var t=window.crypto;else{if(!window.msCrypto||!window.msCrypto.getRandomValues)throw new Error("window.crypto.getRandomValues not available");var t=window.msCrypto}var r=new Uint8Array(e);t.getRandomValues(r);var i=new n(r);return i},i.getPseudoRandomBuffer=function(e){for(var t,r=4294967296,i=new n(e),s=0;e>=s;s++){var o=Math.floor(s/4),a=s-4*o;0===a?(t=Math.random()*r,i[s]=255&t):i[s]=255&(t>>>=8)}return i},t.exports=i}).call(this,e("_process"),e("buffer").Buffer)},{_process:176,buffer:45,crypto:49}],11:[function(e,t,r){(function(r){"use strict";var n=e("./bn"),i=e("lodash"),s=e("../util/preconditions"),o=e("../util/buffer"),a=function f(e,t){if(!(this instanceof f))return new f(e,t);if(e instanceof n)this.set({r:e,s:t});else if(e){var r=e;this.set(r)}};a.prototype.set=function(e){return this.r=e.r||this.r||void 0,this.s=e.s||this.s||void 0,this.i="undefined"!=typeof e.i?e.i:this.i,this.compressed="undefined"!=typeof e.compressed?e.compressed:this.compressed,this},a.fromCompact=function(e){var t=new a,r=!0,i=e.slice(0,1)[0]-27-4,o=e.slice(1,33),f=e.slice(33,65);return s.checkArgument(0===i||1===i||2===i||3===i,new Error("i must be 0, 1, 2, or 3")),s.checkArgument(32===o.length,new Error("r must be 32 bytes")),s.checkArgument(32===f.length,new Error("s must be 32 bytes")),t.compressed=r,t.i=i,t.r=n.fromBuffer(o),t.s=n.fromBuffer(f),t},a.fromDER=a.fromBuffer=function(e,t){var r=a.parseDER(e,t),n=new a;return n.r=r.r,n.s=r.s,n},a.fromTxFormat=function(e){var t=e.readUInt8(e.length-1),r=e.slice(0,e.length-1),n=new a.fromDER(r,!1);return n.nhashtype=t,n},a.fromString=function(e){var t=new r(e,"hex");return a.fromDER(t)},a.parseDER=function(e,t){s.checkArgument(o.isBuffer(e),new Error("DER formatted signature should be a buffer")),i.isUndefined(t)&&(t=!0);var r=e[0];s.checkArgument(48===r,new Error("Header byte should be 0x30"));var a=e[1],f=e.slice(2).length;s.checkArgument(!t||a===f,new Error("Length byte should length of what follows")),a=f>a?a:f;var c=e[2];s.checkArgument(2===c,new Error("Integer byte for r should be 0x02"));var u=e[3],d=e.slice(4,4+u),h=n.fromBuffer(d),p=0===e[4]?!0:!1;s.checkArgument(u===d.length,new Error("Length of r incorrect"));var l=e[4+u+0];s.checkArgument(2===l,new Error("Integer byte for s should be 0x02"));var b=e[4+u+1],g=e.slice(4+u+2,4+u+2+b),m=n.fromBuffer(g),y=0===e[4+u+2+2]?!0:!1;s.checkArgument(b===g.length,new Error("Length of s incorrect"));var v=4+u+2+b;s.checkArgument(a===v-2,new Error("Length of signature incorrect"));var w={header:r,length:a,rheader:c,rlength:u,rneg:p,rbuf:d,r:h,sheader:l,slength:b,sneg:y,sbuf:g,s:m};return w},a.prototype.toCompact=function(e,t){if(e="number"==typeof e?e:this.i,t="boolean"==typeof t?t:this.compressed,0!==e&&1!==e&&2!==e&&3!==e)throw new Error("i must be equal to 0, 1, 2, or 3");var n=e+27+4;t===!1&&(n-=4);var i=new r([n]),s=this.r.toBuffer({size:32}),o=this.s.toBuffer({size:32});return r.concat([i,s,o])},a.prototype.toBuffer=a.prototype.toDER=function(){var e=this.r.toBuffer(),t=this.s.toBuffer(),n=128&e[0]?!0:!1,i=128&t[0]?!0:!1,s=n?r.concat([new r([0]),e]):e,o=i?r.concat([new r([0]),t]):t,a=s.length,f=o.length,c=2+a+2+f,u=2,d=2,h=48,p=r.concat([new r([h,c,u,a]),s,new r([d,f]),o]);return p},a.prototype.toString=function(){var e=this.toDER();return e.toString("hex")},a.isTxDER=function(e){if(e.length<9)return!1;if(e.length>73)return!1;if(48!==e[0])return!1;if(e[1]!==e.length-3)return!1;var t=e[3];if(5+t>=e.length)return!1;var r=e[5+t];if(t+r+7!==e.length)return!1;var n=e.slice(4);if(2!==e[2])return!1;if(0===t)return!1;if(128&n[0])return!1;if(t>1&&0===n[0]&&!(128&n[1]))return!1;var i=e.slice(6+t);return 2!==e[6+t-2]?!1:0===r?!1:128&i[0]?!1:r>1&&0===i[0]&&!(128&i[1])?!1:!0},a.prototype.hasLowS=function(){return this.s.lt(new n(1))||this.s.gt(new n("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0"))?!1:!0},a.prototype.hasDefinedHashtype=function(){return this.nhashtype<a.SIGHASH_ALL||this.nhashtype>a.SIGHASH_SINGLE?!1:!0},a.prototype.toTxFormat=function(){var e=this.toDER(),t=new r(1);return t.writeUInt8(this.nhashtype,0),r.concat([e,t])},a.SIGHASH_ALL=1,a.SIGHASH_NONE=2,a.SIGHASH_SINGLE=3,a.SIGHASH_ANYONECANPAY=128,t.exports=a}).call(this,e("buffer").Buffer)},{"../util/buffer":41,"../util/preconditions":43,"./bn":6,buffer:45,lodash:223}],12:[function(e,t,r){(function(r){"use strict";var n=e("lodash"),i=e("bs58"),s=e("buffer"),o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split(""),a=function f(e){if(!(this instanceof f))return new f(e);if(r.isBuffer(e)){var t=e;this.fromBuffer(t)}else if("string"==typeof e){var n=e;this.fromString(n)}else e&&this.set(e)};a.validCharacters=function(e){return s.Buffer.isBuffer(e)&&(e=e.toString()),n.all(n.map(e,function(e){return n.contains(o,e)}))},a.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this},a.encode=function(e){if(!s.Buffer.isBuffer(e))throw new Error("Input should be a buffer");
return i.encode(e)},a.decode=function(e){if("string"!=typeof e)throw new Error("Input should be a string");return new r(i.decode(e))},a.prototype.fromBuffer=function(e){return this.buf=e,this},a.prototype.fromString=function(e){var t=a.decode(e);return this.buf=t,this},a.prototype.toBuffer=function(){return this.buf},a.prototype.toString=function(){return a.encode(this.buf)},t.exports=a}).call(this,e("buffer").Buffer)},{bs58:200,buffer:45,lodash:223}],13:[function(e,t,r){(function(r){"use strict";var n=e("lodash"),i=e("./base58"),s=e("buffer"),o=e("../crypto/hash").sha256sha256,a=function f(e){if(!(this instanceof f))return new f(e);if(r.isBuffer(e)){var t=e;this.fromBuffer(t)}else if("string"==typeof e){var n=e;this.fromString(n)}else e&&this.set(e)};a.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this},a.validChecksum=function(e,t){return n.isString(e)&&(e=new s.Buffer(i.decode(e))),n.isString(t)&&(t=new s.Buffer(i.decode(t))),t||(t=e.slice(-4),e=e.slice(0,-4)),a.checksum(e).toString("hex")===t.toString("hex")},a.decode=function(e){if("string"!=typeof e)throw new Error("Input must be a string");var t=new r(i.decode(e));if(t.length<4)throw new Error("Input string too short");var n=t.slice(0,-4),s=t.slice(-4),a=o(n),f=a.slice(0,4);if(s.toString("hex")!==f.toString("hex"))throw new Error("Checksum mismatch");return n},a.checksum=function(e){return o(e).slice(0,4)},a.encode=function(e){if(!r.isBuffer(e))throw new Error("Input must be a buffer");var t=new r(e.length+4),n=a.checksum(e);return e.copy(t),n.copy(t,e.length),i.encode(t)},a.prototype.fromBuffer=function(e){return this.buf=e,this},a.prototype.fromString=function(e){var t=a.decode(e);return this.buf=t,this},a.prototype.toBuffer=function(){return this.buf},a.prototype.toString=function(){return a.encode(this.buf)},t.exports=a}).call(this,e("buffer").Buffer)},{"../crypto/hash":8,"./base58":12,buffer:45,lodash:223}],14:[function(e,t,r){(function(r){"use strict";var n=e("lodash"),i=e("../util/preconditions"),s=e("../util/buffer"),o=e("../crypto/bn"),a=function f(e){if(!(this instanceof f))return new f(e);if(!n.isUndefined(e))if(r.isBuffer(e))this.set({buf:e});else if(n.isString(e))this.set({buf:new r(e,"hex")});else{if(!n.isObject(e))throw new TypeError("Unrecognized argument for BufferReader");var t=e;this.set(t)}};a.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this.pos=e.pos||this.pos||0,this},a.prototype.eof=function(){return this.pos>=this.buf.length},a.prototype.finished=a.prototype.eof,a.prototype.read=function(e){i.checkArgument(!n.isUndefined(e),"Must specify a length");var t=this.buf.slice(this.pos,this.pos+e);return this.pos=this.pos+e,t},a.prototype.readAll=function(){var e=this.buf.slice(this.pos,this.buf.length);return this.pos=this.buf.length,e},a.prototype.readUInt8=function(){var e=this.buf.readUInt8(this.pos);return this.pos=this.pos+1,e},a.prototype.readUInt16BE=function(){var e=this.buf.readUInt16BE(this.pos);return this.pos=this.pos+2,e},a.prototype.readUInt16LE=function(){var e=this.buf.readUInt16LE(this.pos);return this.pos=this.pos+2,e},a.prototype.readUInt32BE=function(){var e=this.buf.readUInt32BE(this.pos);return this.pos=this.pos+4,e},a.prototype.readUInt32LE=function(){var e=this.buf.readUInt32LE(this.pos);return this.pos=this.pos+4,e},a.prototype.readUInt64BEBN=function(){var e=this.buf.slice(this.pos,this.pos+8),t=o.fromBuffer(e);return this.pos=this.pos+8,t},a.prototype.readUInt64LEBN=function(){var e=this.buf.slice(this.pos,this.pos+8),t=a({buf:e}).readReverse(),r=o.fromBuffer(t);return this.pos=this.pos+8,r},a.prototype.readVarintNum=function(){var e=this.readUInt8();switch(e){case 253:return this.readUInt16LE();case 254:return this.readUInt32LE();case 255:var t=this.readUInt64LEBN(),r=t.toNumber();if(r<=Math.pow(2,53))return r;throw new Error("number too large to retain precision - use readVarintBN");default:return e}},a.prototype.readVarLengthBuffer=function(){var e=this.readVarintNum(),t=this.read(e);return i.checkState(t.length===e,"Invalid length while reading varlength buffer. Expected to read: "+e+" and read "+t.length),t},a.prototype.readVarintBuf=function(){var e=this.buf.readUInt8(this.pos);switch(e){case 253:return this.read(3);case 254:return this.read(5);case 255:return this.read(9);default:return this.read(1)}},a.prototype.readVarintBN=function(){var e=this.readUInt8();switch(e){case 253:return new o(this.readUInt16LE());case 254:return new o(this.readUInt32LE());case 255:return this.readUInt64LEBN();default:return new o(e)}},a.prototype.reverse=function(){for(var e=new r(this.buf.length),t=0;t<e.length;t++)e[t]=this.buf[this.buf.length-1-t];return this.buf=e,this},a.prototype.readReverse=function(e){n.isUndefined(e)&&(e=this.buf.length);var t=this.buf.slice(this.pos,this.pos+e);return this.pos=this.pos+e,s.reverse(t)},t.exports=a}).call(this,e("buffer").Buffer)},{"../crypto/bn":6,"../util/buffer":41,"../util/preconditions":43,buffer:45,lodash:223}],15:[function(e,t,r){(function(r){"use strict";var n=e("../util/buffer"),i=e("assert"),s=function o(e){return this instanceof o?void(e?this.set(e):this.bufs=[]):new o(e)};s.prototype.set=function(e){return this.bufs=e.bufs||this.bufs||[],this},s.prototype.toBuffer=function(){return this.concat()},s.prototype.concat=function(){return r.concat(this.bufs)},s.prototype.write=function(e){return i(n.isBuffer(e)),this.bufs.push(e),this},s.prototype.writeReverse=function(e){return i(n.isBuffer(e)),this.bufs.push(n.reverse(e)),this},s.prototype.writeUInt8=function(e){var t=new r(1);return t.writeUInt8(e,0),this.write(t),this},s.prototype.writeUInt16BE=function(e){var t=new r(2);return t.writeUInt16BE(e,0),this.write(t),this},s.prototype.writeUInt16LE=function(e){var t=new r(2);return t.writeUInt16LE(e,0),this.write(t),this},s.prototype.writeUInt32BE=function(e){var t=new r(4);return t.writeUInt32BE(e,0),this.write(t),this},s.prototype.writeInt32LE=function(e){var t=new r(4);return t.writeInt32LE(e,0),this.write(t),this},s.prototype.writeUInt32LE=function(e){var t=new r(4);return t.writeUInt32LE(e,0),this.write(t),this},s.prototype.writeUInt64BEBN=function(e){var t=e.toBuffer({size:8});return this.write(t),this},s.prototype.writeUInt64LEBN=function(e){var t=e.toBuffer({size:8}),n=new r(Array.apply(new Array,t).reverse());return this.write(n),this},s.prototype.writeVarintNum=function(e){var t=s.varintBufNum(e);return this.write(t),this},s.prototype.writeVarintBN=function(e){var t=s.varintBufBN(e);return this.write(t),this},s.varintBufNum=function(e){var t=void 0;return 253>e?(t=new r(1),t.writeUInt8(e,0)):65536>e?(t=new r(3),t.writeUInt8(253,0),t.writeUInt16LE(e,1)):4294967296>e?(t=new r(5),t.writeUInt8(254,0),t.writeUInt32LE(e,1)):(t=new r(9),t.writeUInt8(255,0),t.writeInt32LE(-1&e,1),t.writeUInt32LE(Math.floor(e/4294967296),5)),t},s.varintBufBN=function(e){var t=void 0,n=e.toNumber();if(253>n)t=new r(1),t.writeUInt8(n,0);else if(65536>n)t=new r(3),t.writeUInt8(253,0),t.writeUInt16LE(n,1);else if(4294967296>n)t=new r(5),t.writeUInt8(254,0),t.writeUInt32LE(n,1);else{var i=new s;i.writeUInt8(255),i.writeUInt64LEBN(e);var t=i.concat()}return t},t.exports=s}).call(this,e("buffer").Buffer)},{"../util/buffer":41,assert:44,buffer:45}],16:[function(e,t,r){(function(r){"use strict";var n=e("./bufferwriter"),i=e("./bufferreader"),s=e("../crypto/bn"),o=function a(e){if(!(this instanceof a))return new a(e);if(r.isBuffer(e))this.buf=e;else if("number"==typeof e){var t=e;this.fromNumber(t)}else if(e instanceof s){var n=e;this.fromBN(n)}else if(e){var i=e;this.set(i)}};o.prototype.set=function(e){return this.buf=e.buf||this.buf,this},o.prototype.fromString=function(e){return this.set({buf:new r(e,"hex")}),this},o.prototype.toString=function(){return this.buf.toString("hex")},o.prototype.fromBuffer=function(e){return this.buf=e,this},o.prototype.fromBufferReader=function(e){return this.buf=e.readVarintBuf(),this},o.prototype.fromBN=function(e){return this.buf=n().writeVarintBN(e).concat(),this},o.prototype.fromNumber=function(e){return this.buf=n().writeVarintNum(e).concat(),this},o.prototype.toBuffer=function(){return this.buf},o.prototype.toBN=function(){return i(this.buf).readVarintBN()},o.prototype.toNumber=function(){return i(this.buf).readVarintNum()},t.exports=o}).call(this,e("buffer").Buffer)},{"../crypto/bn":6,"./bufferreader":14,"./bufferwriter":15,buffer:45}],17:[function(e,t,r){"use strict";function n(e,t){return e.replace("{0}",t[0]).replace("{1}",t[1]).replace("{2}",t[2])}var i=e("lodash"),s=function(e,t){var r=function(){if(i.isString(t.message))this.message=n(t.message,arguments);else{if(!i.isFunction(t.message))throw new Error("Invalid error definition for "+t.name);this.message=t.message.apply(null,arguments)}this.stack=this.message+"\n"+(new Error).stack};return r.prototype=Object.create(e.prototype),r.prototype.name=e.prototype.name+t.name,e[t.name]=r,t.errors&&o(r,t.errors),r},o=function(e,t){i.each(t,function(t){s(e,t)})},a=function(e,t){return o(e,t),e},f={};f.Error=function(){this.message="Internal error",this.stack=this.message+"\n"+(new Error).stack},f.Error.prototype=Object.create(Error.prototype),f.Error.prototype.name="bitcore.Error";var c=e("./spec");a(f.Error,c),t.exports=f.Error,t.exports.extend=function(e){return s(f.Error,e)}},{"./spec":18,lodash:223}],18:[function(e,t,r){"use strict";var n="http://bitcore.io/";t.exports=[{name:"InvalidB58Char",message:"Invalid Base58 character: {0} in {1}"},{name:"InvalidB58Checksum",message:"Invalid Base58 checksum for {0}"},{name:"InvalidNetwork",message:"Invalid version for network: got {0}"},{name:"InvalidState",message:"Invalid state: {0}"},{name:"NotImplemented",message:"Function {0} was not implemented yet"},{name:"InvalidNetworkArgument",message:'Invalid network: must be "livenet" or "testnet", got {0}'},{name:"InvalidArgument",message:function(){return"Invalid Argument"+(arguments[0]?": "+arguments[0]:"")+(arguments[1]?" Documentation: "+n+arguments[1]:"")}},{name:"AbstractMethodInvoked",message:"Abstract Method Invokation: {0}"},{name:"InvalidArgumentType",message:function(){return"Invalid Argument for "+arguments[2]+", expected "+arguments[1]+" but got "+typeof arguments[0]}},{name:"Unit",message:"Internal Error on Unit {0}",errors:[{name:"UnknownCode",message:"Unrecognized unit code: {0}"},{name:"InvalidRate",message:"Invalid exchange rate: {0}"}]},{name:"Transaction",message:"Internal Error on Transaction {0}",errors:[{name:"Input",message:"Internal Error on Input {0}",errors:[{name:"MissingScript",message:"Need a script to create an input"},{name:"UnsupportedScript",message:"Unsupported input script type: {0}"},{name:"MissingPreviousOutput",message:"No previous output information."}]},{name:"NeedMoreInfo",message:"{0}"},{name:"InvalidSorting",message:"The sorting function provided did not return the change output as one of the array elements"},{name:"InvalidOutputAmountSum",message:"{0}"},{name:"MissingSignatures",message:"Some inputs have not been fully signed"},{name:"InvalidIndex",message:"Invalid index: {0} is not between 0, {1}"},{name:"UnableToVerifySignature",message:"Unable to verify signature: {0}"},{name:"DustOutputs",message:"Dust amount detected in one output"},{name:"InvalidSatoshis",message:"Output satoshis are invalid"},{name:"FeeError",message:"Internal Error on Fee {0}",errors:[{name:"TooSmall",message:"Fee is too small: {0}"},{name:"TooLarge",message:"Fee is too large: {0}"},{name:"Different",message:"Unspent value is different from specified fee: {0}"}]},{name:"ChangeAddressMissing",message:"Change address is missing"},{name:"BlockHeightTooHigh",message:"Block Height can be at most 2^32 -1"},{name:"NLockTimeOutOfRange",message:"Block Height can only be between 0 and 499 999 999"},{name:"LockTimeTooEarly",message:"Lock Time can't be earlier than UNIX date 500 000 000"}]},{name:"Script",message:"Internal Error on Script {0}",errors:[{name:"UnrecognizedAddress",message:"Expected argument {0} to be an address"},{name:"CantDeriveAddress",message:"Can't derive address associated with script {0}, needs to be p2pkh in, p2pkh out, p2sh in, or p2sh out."},{name:"InvalidBuffer",message:"Invalid script buffer: can't parse valid script from given buffer {0}"}]},{name:"HDPrivateKey",message:"Internal Error on HDPrivateKey {0}",errors:[{name:"InvalidDerivationArgument",message:"Invalid derivation argument {0}, expected string, or number and boolean"},{name:"InvalidEntropyArgument",message:"Invalid entropy: must be an hexa string or binary buffer, got {0}",errors:[{name:"TooMuchEntropy",message:'Invalid entropy: more than 512 bits is non standard, got "{0}"'},{name:"NotEnoughEntropy",message:'Invalid entropy: at least 128 bits needed, got "{0}"'}]},{name:"InvalidLength",message:"Invalid length for xprivkey string in {0}"},{name:"InvalidPath",message:"Invalid derivation path: {0}"},{name:"UnrecognizedArgument",message:'Invalid argument: creating a HDPrivateKey requires a string, buffer, json or object, got "{0}"'}]},{name:"HDPublicKey",message:"Internal Error on HDPublicKey {0}",errors:[{name:"ArgumentIsPrivateExtended",message:"Argument is an extended private key: {0}"},{name:"InvalidDerivationArgument",message:"Invalid derivation argument: got {0}"},{name:"InvalidLength",message:'Invalid length for xpubkey: got "{0}"'},{name:"InvalidPath",message:'Invalid derivation path, it should look like: "m/1/100", got "{0}"'},{name:"MustSupplyArgument",message:"Must supply an argument to create a HDPublicKey"},{name:"UnrecognizedArgument",message:"Invalid argument for creation, must be string, json, buffer, or object"}]}]},{}],19:[function(e,t,r){"use strict";t.exports={_cache:{},_count:0,_eraseIndex:0,_usedList:{},_usedIndex:{},_CACHE_SIZE:5e3,get:function(e,t,r){r=!!r;var n=e+"/"+t+"/"+r;return this._cache[n]?(this._cacheHit(n),this._cache[n]):void 0},set:function(e,t,r,n){r=!!r;var i=e+"/"+t+"/"+r;this._cache[i]=n,this._cacheHit(i)},_cacheHit:function(e){this._usedIndex[e]&&delete this._usedList[this._usedIndex[e]],this._usedList[this._count]=e,this._usedIndex[e]=this._count,this._count++,this._cacheRemove()},_cacheRemove:function(){for(;this._eraseIndex<this._count-this._CACHE_SIZE;){if(this._usedList[this._eraseIndex]){var e=this._usedList[this._eraseIndex];delete this._usedIndex[e],delete this._cache[e]}delete this._usedList[this._eraseIndex],this._eraseIndex++}}}},{}],20:[function(e,t,r){(function(r){"use strict";function n(e){if(e instanceof n)return e;if(!(this instanceof n))return new n(e);if(!e)return this._generateRandomly();if(h.get(e))return this._generateRandomly(e);if(o.isString(e)||v.isBuffer(e))if(n.isValidSerialized(e))this._buildFromSerialized(e);else if(w.isValidJSON(e))this._buildFromJSON(e);else{if(!v.isBuffer(e)||!n.isValidSerialized(e.toString()))throw n.getSerializedError(e);this._buildFromSerialized(e.toString())}else{if(!o.isObject(e))throw new y.UnrecognizedArgument(e);this._buildFromObject(e)}}var i=e("assert"),s=e("buffer"),o=e("lodash"),a=e("./util/preconditions"),f=e("./crypto/bn"),c=e("./encoding/base58"),u=e("./encoding/base58check"),d=e("./crypto/hash"),h=e("./networks"),p=e("./hdkeycache"),l=e("./crypto/point"),b=e("./privatekey"),g=e("./crypto/random"),m=e("./errors"),y=m.HDPrivateKey,v=e("./util/buffer"),w=e("./util/js"),_=128,S=1/8,k=512;n.isValidPath=function(e,t){if(o.isString(e)){var r=n._getDerivationIndexes(e);return null!==r&&o.all(r,n.isValidPath)}return o.isNumber(e)?(e<n.Hardened&&t===!0&&(e+=n.Hardened),e>=0&&e<n.MaxIndex):!1},n._getDerivationIndexes=function(e){var t=e.split("/");if(o.contains(n.RootElementAlias,e))return[];if(!o.contains(n.RootElementAlias,t[0]))return null;var r=t.slice(1).map(function(e){var t="'"===e.slice(-1);if(t&&(e=e.slice(0,-1)),!e||"-"===e[0])return 0/0;var r=+e;return t&&(r+=n.Hardened),r});return o.any(r,isNaN)?null:r},n.prototype.derive=function(e,t){if(o.isNumber(e))return this._deriveWithNumber(e,t);if(o.isString(e))return this._deriveFromString(e);throw new y.InvalidDerivationArgument(e)},n.prototype._deriveWithNumber=function(e,t){if(!n.isValidPath(e,t))throw new y.InvalidPath(e);t=e>=n.Hardened?!0:t,e<n.Hardened&&t===!0&&(e+=n.Hardened);var r=p.get(this.xprivkey,e,t);if(r)return r;var i,o=v.integerAsBuffer(e);i=v.concat(t?[new s.Buffer([0]),this.privateKey.toBuffer(),o]:[this.publicKey.toBuffer(),o]);var a=d.sha512hmac(i,this._buffers.chainCode),c=f.fromBuffer(a.slice(0,32),{size:32}),u=a.slice(32,64),h=c.add(this.privateKey.toBigNumber()).mod(l.getN()).toBuffer({size:32}),b=new n({network:this.network,depth:this.depth+1,parentFingerPrint:this.fingerPrint,childIndex:e,chainCode:u,privateKey:h});return p.set(this.xprivkey,e,t,b),b},n.prototype._deriveFromString=function(e){if(!n.isValidPath(e))throw new y.InvalidPath(e);var t=n._getDerivationIndexes(e),r=t.reduce(function(e,t){return e._deriveWithNumber(t)},this);return r},n.isValidSerialized=function(e,t){return!n.getSerializedError(e,t)},n.getSerializedError=function(e,t){if(!o.isString(e)&&!v.isBuffer(e))return new y.UnrecognizedArgument("Expected string or buffer");if(!c.validCharacters(e))return new m.InvalidB58Char("(unknown)",e);try{e=u.decode(e)}catch(r){return new m.InvalidB58Checksum(e)}if(e.length!==n.DataLength)return new y.InvalidLength(e);if(!o.isUndefined(t)){var i=n._validateNetwork(e,t);if(i)return i}return null},n._validateNetwork=function(e,t){var r=h.get(t);if(!r)return new m.InvalidNetworkArgument(t);var n=e.slice(0,4);return v.integerFromBuffer(n)!==r.xprivkey?new m.InvalidNetwork(n):null},n.fromJSON=function(e){return a.checkArgument(w.isValidJSON(e),"No valid JSON string was provided"),new n(e)},n.fromString=function(e){return a.checkArgument(o.isString(e),"No valid string was provided"),new n(e)},n.fromObject=function(e){return a.checkArgument(o.isObject(e),"No valid argument was provided"),new n(e)},n.prototype._buildFromJSON=function(e){return this._buildFromObject(JSON.parse(e))},n.prototype._buildFromObject=function(e){var t={version:e.network