streamium
Version:
Decentralized trustless video streaming using bitcoin payment channels.
2 lines • 605 kB
JavaScript
require=function t(e,r,n){function i(o,a){if(!r[o]){if(!e[o]){var f="function"==typeof require&&require;if(!a&&f)return f(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=r[o]={exports:{}};e[o][0].call(h.exports,function(t){var r=e[o][1][t];return i(r?r:t)},h,h.exports,t,e,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(t,e,r){(function(r){"use strict";function n(t,e,r){if(!(this instanceof n))return new n(t,e,r);if(i.isArray(t)&&i.isNumber(e))return n.createMultisig(t,e,r);if(t instanceof n)return t;if(s.checkArgument(t,"First argument is required, please include address data.","guide/address.html"),e&&!f.get(e))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(t,e,r);return o.network=o.network||f.get(e)||f.defaultNetwork,o.type=o.type||r||n.PayToPublicKeyHash,h.defineImmutable(this,{hashBuffer:o.hashBuffer,network:o.network,type:o.type}),this}var i=t("lodash"),s=t("./util/preconditions"),o=t("./errors"),a=t("./encoding/base58check"),f=t("./networks"),u=t("./crypto/hash"),h=t("./util/js"),c=t("./publickey");n.prototype._classifyArguments=function(t,e,s){if((t instanceof r||t instanceof Uint8Array)&&20===t.length)return n._transformHash(t);if((t instanceof r||t instanceof Uint8Array)&&21===t.length)return n._transformBuffer(t,e,s);if(t instanceof c)return n._transformPublicKey(t);if(t instanceof d)return n._transformScript(t,e);if("string"==typeof t)return n._transformString(t,e,s);if(i.isObject(t))return n._transformObject(t);throw new TypeError("First argument is an unrecognized data format.")},n.PayToPublicKeyHash="pubkeyhash",n.PayToScriptHash="scripthash",n._transformHash=function(t){var e={};if(!(t instanceof r||t instanceof Uint8Array))throw new TypeError("Address supplied is not a buffer.");if(20!==t.length)throw new TypeError("Address hashbuffers must be exactly 20 bytes.");return e.hashBuffer=t,e},n._transformObject=function(t){return s.checkArgument(t.hash||t.hashBuffer,"Must provide a `hash` or `hashBuffer` property"),s.checkArgument(t.type,"Must provide a `type` property"),{hashBuffer:t.hash?new r(t.hash,"hex"):t.hashBuffer,network:f.get(t.network)||f.defaultNetwork,type:t.type}},n._classifyFromVersion=function(t){var e={},r=f.get(t[0],"pubkeyhash"),i=f.get(t[0],"scripthash");return r?(e.network=r,e.type=n.PayToPublicKeyHash):i&&(e.network=i,e.type=n.PayToScriptHash),e},n._transformBuffer=function(t,e,i){var s={};if(!(t instanceof r||t instanceof Uint8Array))throw new TypeError("Address supplied is not a buffer.");if(21!==t.length)throw new TypeError("Address buffers must be exactly 21 bytes.");e=f.get(e);var o=n._classifyFromVersion(t);if(!o.network||e&&e!==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=t.slice(1),s.network=o.network,s.type=o.type,s},n._transformPublicKey=function(t){var e={};if(!(t instanceof c))throw new TypeError("Address must be an instance of PublicKey.");return e.hashBuffer=u.sha256ripemd160(t.toBuffer()),e.type=n.PayToPublicKeyHash,e},n._transformScript=function(t,e){s.checkArgument(t instanceof d,"script must be a Script instance");var r=t.getAddressInfo(e);if(!r)throw new o.Script.CantDeriveAddress(t);return r},n.createMultisig=function(t,e,r){return r=r||t[0].network||f.defaultNetwork,n.payingTo(d.buildMultisigOut(t,e),r)},n._transformString=function(t,e,r){if("string"!=typeof t)throw new TypeError("data parameter supplied is not a string.");t=t.trim();var i=a.decode(t),s=n._transformBuffer(i,e,r);return s},n.fromPublicKey=function(t,e){var r=n._transformPublicKey(t);return e=e||f.defaultNetwork,new n(r.hashBuffer,e,r.type)},n.fromPublicKeyHash=function(t,e){var r=n._transformHash(t);return new n(r.hashBuffer,e,n.PayToPublicKeyHash)},n.fromScriptHash=function(t,e){s.checkArgument(t,"hash parameter is required");var r=n._transformHash(t);return new n(r.hashBuffer,e,n.PayToScriptHash)},n.payingTo=function(t,e){return s.checkArgument(t,"script is required"),s.checkArgument(t instanceof d,"script must be instance of Script"),n.fromScriptHash(u.sha256ripemd160(t.toBuffer()),e)},n.fromScript=function(t,e){s.checkArgument(t instanceof d,"script must be a Script instance");var r=n._transformScript(t,e);return new n(r.hashBuffer,e,r.type)},n.fromBuffer=function(t,e,r){var i=n._transformBuffer(t,e,r);return new n(i.hashBuffer,i.network,i.type)},n.fromString=function(t,e,r){var i=n._transformString(t,e,r);return new n(i.hashBuffer,i.network,i.type)},n.fromObject=function(t){s.checkState(h.isHexa(t.hash),'Unexpected hash property, "'+t.hash+'", expected to be hex.');var e=new r(t.hash,"hex");return new n(e,t.network,t.type)},n.getValidationError=function(t,e,r){var i;try{new n(t,e,r)}catch(s){i=s}return i},n.isValid=function(t,e,r){return!n.getValidationError(t,e,r)},n.prototype.isPayToPublicKeyHash=function(){return this.type===n.PayToPublicKeyHash},n.prototype.isPayToScriptHash=function(){return this.type===n.PayToScriptHash},n.prototype.toBuffer=function(){var t=new r([this.network[this.type]]),e=r.concat([t,this.hashBuffer]);return e},n.prototype.toObject=n.prototype.toJSON=function(){return{hash:this.hashBuffer.toString("hex"),type:this.type,network:this.network.toString()}},n.prototype.toString=function(){return a.encode(this.toBuffer())},n.prototype.inspect=function(){return"<Address: "+this.toString()+", type: "+this.type+", network: "+this.network+">"},e.exports=n;var d=t("./script")}).call(this,t("buffer").Buffer)},{"./crypto/hash":8,"./encoding/base58check":13,"./errors":17,"./networks":22,"./publickey":25,"./script":26,"./util/js":44,"./util/preconditions":45,buffer:90,lodash:211}],2:[function(t,e,r){(function(r){"use strict";function n(t){return this instanceof n?(i.extend(this,n._from(t)),this):new n(t)}var i=t("lodash"),s=t("./blockheader"),o=t("../crypto/bn"),a=t("../util/buffer"),f=t("../encoding/bufferreader"),u=t("../encoding/bufferwriter"),h=t("../crypto/hash"),c=t("../transaction"),d=t("../util/preconditions");n.MAX_BLOCK_SIZE=1e6,n._from=function(t){var e={};if(a.isBuffer(t))e=n._fromBufferReader(f(t));else{if(!i.isObject(t))throw new TypeError("Unrecognized argument for Block");e=n._fromObject(t)}return e},n._fromObject=function(t){var e=[];t.transactions.forEach(function(t){t instanceof c?e.push(t):e.push(c().fromObject(t))});var r={header:s.fromObject(t.header),transactions:e};return r},n.fromObject=function(t){var e=n._fromObject(t);return new n(e)},n._fromBufferReader=function(t){var e={};d.checkState(!t.finished(),"No block data received"),e.header=s.fromBufferReader(t);var r=t.readVarintNum();e.transactions=[];for(var n=0;r>n;n++)e.transactions.push(c().fromBufferReader(t));return e},n.fromBufferReader=function(t){d.checkArgument(t,"br is required");var e=n._fromBufferReader(t);return new n(e)},n.fromBuffer=function(t){return n.fromBufferReader(new f(t))},n.fromString=function(t){var e=new r(t,"hex");return n.fromBuffer(e)},n.fromRawBlock=function(t){a.isBuffer(t)||(t=new r(t,"binary"));var e=f(t);e.pos=n.Values.START_OF_BLOCK;var i=n._fromBufferReader(e);return new n(i)},n.prototype.toObject=n.prototype.toJSON=function(){var t=[];return this.transactions.forEach(function(e){t.push(e.toObject())}),{header:this.header.toObject(),transactions:t}},n.prototype.toBuffer=function(){return this.toBufferWriter().concat()},n.prototype.toString=function(){return this.toBuffer().toString("hex")},n.prototype.toBufferWriter=function(t){t||(t=new u),t.write(this.header.toBuffer()),t.writeVarintNum(this.transactions.length);for(var e=0;e<this.transactions.length;e++)this.transactions[e].toBufferWriter(t);return t},n.prototype.getTransactionHashes=function(){var t=[];if(0===this.transactions.length)return[n.Values.NULL_HASH];for(var e=0;e<this.transactions.length;e++)t.push(this.transactions[e]._getHash());return t},n.prototype.getMerkleTree=function(){for(var t=this.getTransactionHashes(),e=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([t[e+i],t[e+s]]);t.push(h.sha256sha256(o))}e+=n}return t},n.prototype.getMerkleRoot=function(){var t=this.getMerkleTree();return t[t.length-1]},n.prototype.validMerkleRoot=function(){var t=new o(this.header.merkleRoot.toString("hex"),"hex"),e=new o(this.getMerkleRoot().toString("hex"),"hex");return 0===t.cmp(e)},n.prototype._getHash=function(){return this.header._getHash()};var p={configurable:!1,enumerable:!0,get:function(){return this._id||(this._id=this.header.id),this._id},set:i.noop};Object.defineProperty(n.prototype,"id",p),Object.defineProperty(n.prototype,"hash",p),n.prototype.inspect=function(){return"<Block "+this.id+">"},n.Values={START_OF_BLOCK:8,NULL_HASH:new r("0000000000000000000000000000000000000000000000000000000000000000","hex")},e.exports=n}).call(this,t("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../transaction":29,"../util/buffer":43,"../util/preconditions":45,"./blockheader":3,buffer:90,lodash:211}],3:[function(t,e,r){(function(r){"use strict";var n=t("lodash"),i=t("../crypto/bn"),s=t("../util/buffer"),o=t("../encoding/bufferreader"),a=t("../encoding/bufferwriter"),f=t("../crypto/hash"),u=(t("../util/js"),t("../util/preconditions")),h=486604799,c=function p(t){if(!(this instanceof p))return new p(t);var e=p._from(t);return this.version=e.version,this.prevHash=e.prevHash,this.merkleRoot=e.merkleRoot,this.time=e.time,this.timestamp=e.time,this.bits=e.bits,this.nonce=e.nonce,e.hash&&u.checkState(this.hash===e.hash,"Argument object hash property does not match block hash."),this};c._from=function(t){var e={};if(s.isBuffer(t))e=c._fromBufferReader(o(t));else{if(!n.isObject(t))throw new TypeError("Unrecognized argument for BlockHeader");e=c._fromObject(t)}return e},c._fromObject=function(t){u.checkArgument(t,"data is required");var e=t.prevHash,i=t.merkleRoot;n.isString(t.prevHash)&&(e=s.reverse(new r(t.prevHash,"hex"))),n.isString(t.merkleRoot)&&(i=s.reverse(new r(t.merkleRoot,"hex")));var o={hash:t.hash,version:t.version,prevHash:e,merkleRoot:i,time:t.time,timestamp:t.time,bits:t.bits,nonce:t.nonce};return o},c.fromObject=function(t){var e=c._fromObject(t);return new c(e)},c.fromRawBlock=function(t){s.isBuffer(t)||(t=new r(t,"binary"));var e=o(t);e.pos=c.Constants.START_OF_HEADER;var n=c._fromBufferReader(e);return new c(n)},c.fromBuffer=function(t){var e=c._fromBufferReader(o(t));return new c(e)},c.fromString=function(t){var e=new r(t,"hex");return c.fromBuffer(e)},c._fromBufferReader=function(t){var e={};return e.version=t.readUInt32LE(),e.prevHash=t.read(32),e.merkleRoot=t.read(32),e.time=t.readUInt32LE(),e.bits=t.readUInt32LE(),e.nonce=t.readUInt32LE(),e},c.fromBufferReader=function(t){var e=c._fromBufferReader(t);return new c(e)},c.prototype.toObject=c.prototype.toJSON=function(){return{hash:this.hash,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}},c.prototype.toBuffer=function(){return this.toBufferWriter().concat()},c.prototype.toString=function(){return this.toBuffer().toString("hex")},c.prototype.toBufferWriter=function(t){return t||(t=new a),t.writeUInt32LE(this.version),t.write(this.prevHash),t.write(this.merkleRoot),t.writeUInt32LE(this.time),t.writeUInt32LE(this.bits),t.writeUInt32LE(this.nonce),t},c.prototype.getTargetDifficulty=function(t){t=t||this.bits;for(var e=new i(16777215&t),r=8*((t>>>24)-3);r-- >0;)e=e.mul(new i(2));return e},c.prototype.getDifficulty=function(){var t=this.getTargetDifficulty(h).mul(new i(Math.pow(10,8))),e=this.getTargetDifficulty(),r=t.div(e).toString(10),n=r.length-8;return r=r.slice(0,n)+"."+r.slice(n),parseFloat(r)},c.prototype._getHash=function(){var t=this.toBuffer();return f.sha256sha256(t)};var d={configurable:!1,enumerable:!0,get:function(){return this._id||(this._id=o(this._getHash()).readReverse().toString("hex")),this._id},set:n.noop};Object.defineProperty(c.prototype,"id",d),Object.defineProperty(c.prototype,"hash",d),c.prototype.validTimestamp=function(){var t=Math.round((new Date).getTime()/1e3);return!(this.time>t+c.Constants.MAX_TIME_OFFSET)},c.prototype.validProofOfWork=function(){var t=new i(this.id,"hex"),e=this.getTargetDifficulty();return!(t.cmp(e)>0)},c.prototype.inspect=function(){return"<BlockHeader "+this.id+">"},c.Constants={START_OF_HEADER:8,MAX_TIME_OFFSET:7200,LARGEST_HASH:new i("10000000000000000000000000000000000000000000000000000000000000000","hex")},e.exports=c}).call(this,t("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../util/buffer":43,"../util/js":44,"../util/preconditions":45,buffer:90,lodash:211}],4:[function(t,e,r){e.exports=t("./block"),e.exports.BlockHeader=t("./blockheader"),e.exports.MerkleBlock=t("./merkleblock")},{"./block":2,"./blockheader":3,"./merkleblock":5}],5:[function(t,e,r){(function(r){"use strict";function n(t){if(!(this instanceof n))return new n(t);var e={};if(o.isBuffer(t))e=n._fromBufferReader(a(t));else{if(!i.isObject(t))throw new TypeError("Unrecognized argument for MerkleBlock");var r;r=t.header instanceof s?t.header:s.fromObject(t.header),e={header:r,numTransactions:t.numTransactions,hashes:t.hashes,flags:t.flags}}return i.extend(this,e),this._flagBitsUsed=0,this._hashesUsed=0,this}var i=t("lodash"),s=t("./blockheader"),o=t("../util/buffer"),a=t("../encoding/bufferreader"),f=t("../encoding/bufferwriter"),u=t("../crypto/hash"),h=(t("../util/js"),t("../transaction")),c=t("../util/preconditions");n.fromBuffer=function(t){return n.fromBufferReader(a(t))},n.fromBufferReader=function(t){return new n(n._fromBufferReader(t))},n.prototype.toBuffer=function(){return this.toBufferWriter().concat()},n.prototype.toBufferWriter=function(t){t||(t=new f),t.write(this.header.toBuffer()),t.writeUInt32LE(this.numTransactions),t.writeVarintNum(this.hashes.length);for(var e=0;e<this.hashes.length;e++)t.write(new r(this.hashes[e],"hex"));for(t.writeVarintNum(this.flags.length),e=0;e<this.flags.length;e++)t.writeUInt8(this.flags[e]);return t},n.prototype.toObject=n.prototype.toJSON=function(){return{header:this.header.toObject(),numTransactions:this.numTransactions,hashes:this.hashes,flags:this.flags}},n.prototype.validMerkleTree=function(){if(c.checkState(i.isArray(this.flags),"MerkleBlock flags is not an array"),c.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 t=this._calcTreeHeight(),e={hashesUsed:0,flagBitsUsed:0},r=this._traverseMerkleTree(t,0,e);return e.hashesUsed!==this.hashes.length?!1:o.equals(r,this.header.merkleRoot)},n.prototype._traverseMerkleTree=function(t,e,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!==t&&i){var s=this._traverseMerkleTree(t-1,2*e,n),o=s;return 2*e+1<this._calcTreeWidth(t-1)&&(o=this._traverseMerkleTree(t-1,2*e+1,n)),u.sha256sha256(new r.concat([s,o]))}if(n.hashesUsed>=this.hashes.length)return null;var a=this.hashes[n.hashesUsed++];return 0===t&&i&&n.txs.push(a),new r(a,"hex")},n.prototype._calcTreeWidth=function(t){return this.numTransactions+(1<<t)-1>>t},n.prototype._calcTreeHeight=function(){for(var t=0;this._calcTreeWidth(t)>1;)t++;return t},n.prototype.hasTransaction=function(t){c.checkArgument(!i.isUndefined(t),"tx cannot be undefined"),c.checkArgument(t instanceof h||"string"==typeof t,'Invalid tx given, tx must be a "string" or "Transaction"');var e=t;t instanceof h&&(e=o.reverse(new r(t.id,"hex")).toString("hex"));var n=[],s=this._calcTreeHeight();return this._traverseMerkleTree(s,0,{txs:n}),-1!==n.indexOf(e)},n._fromBufferReader=function(t){c.checkState(!t.finished(),"No merkleblock data received");var e={};e.header=s.fromBufferReader(t),e.numTransactions=t.readUInt32LE();var r=t.readVarintNum();e.hashes=[];for(var n=0;r>n;n++)e.hashes.push(t.read(32).toString("hex"));var i=t.readVarintNum();for(e.flags=[],n=0;i>n;n++)e.flags.push(t.readUInt8());return e},n.fromObject=function(t){return new n(t)},e.exports=n}).call(this,t("buffer").Buffer)},{"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../transaction":29,"../util/buffer":43,"../util/js":44,"../util/preconditions":45,"./blockheader":3,buffer:90,lodash:211}],6:[function(t,e,r){(function(r){"use strict";var n=t("bn.js"),i=t("../util/preconditions"),s=t("lodash"),o=function(t){for(var e=new r(t.length),n=0;n<t.length;n++)e[n]=t[t.length-1-n];return e};n.Zero=new n(0),n.One=new n(1),n.Minus1=new n(-1),n.fromNumber=function(t){return i.checkArgument(s.isNumber(t)),new n(t)},n.fromString=function(t,e){return i.checkArgument(s.isString(t)),new n(t,e)},n.fromBuffer=function(t,e){"undefined"!=typeof e&&"little"===e.endian&&(t=o(t));var r=t.toString("hex"),i=new n(r,16);return i},n.fromSM=function(t,e){var i;if(0===t.length)return n.fromBuffer(new r([0]));var s="big";return e&&(s=e.endian),"little"===s&&(t=o(t)),128&t[0]?(t[0]=127&t[0],i=n.fromBuffer(t),i.neg().copy(i)):i=n.fromBuffer(t),i},n.prototype.toNumber=function(){return parseInt(this.toString(10),10)},n.prototype.toBuffer=function(t){var e,i;if(t&&t.size){i=this.toString(16,2);var s=i.length/2;e=new r(i,"hex"),s===t.size?e=e:s>t.size?e=n.trim(e,s):s<t.size&&(e=n.pad(e,s,t.size))}else i=this.toString(16,2),e=new r(i,"hex");return"undefined"!=typeof t&&"little"===t.endian&&(e=o(e)),e},n.prototype.toSMBigEndian=function(){var t;return-1===this.cmp(n.Zero)?(t=this.neg().toBuffer(),128&t[0]?t=r.concat([new r([128]),t]):t[0]=128|t[0]):(t=this.toBuffer(),128&t[0]&&(t=r.concat([new r([0]),t]))),1===t.length&0===t[0]&&(t=new r([])),t},n.prototype.toSM=function(t){var e=t?t.endian:"big",r=this.toSMBigEndian();return"little"===e&&(r=o(r)),r},n.fromScriptNumBuffer=function(t,e,r){var s=r||4;if(i.checkArgument(t.length<=s,new Error("script number overflow")),e&&t.length>0&&0===(127&t[t.length-1])&&(t.length<=1||0===(128&t[t.length-2])))throw new Error("non-minimally encoded script number");return n.fromSM(t,{endian:"little"})},n.prototype.toScriptNumBuffer=function(){return this.toSM({endian:"little"})},n.prototype.gt=function(t){return this.cmp(t)>0},n.prototype.gte=function(t){return this.cmp(t)>=0},n.prototype.lt=function(t){return this.cmp(t)<0},n.trim=function(t,e){return t.slice(e-t.length,t.length)},n.pad=function(t,e,n){for(var i=new r(n),s=0;s<t.length;s++)i[i.length-1-s]=t[t.length-1-s];for(s=0;n-e>s;s++)i[s]=0;return i},e.exports=n}).call(this,t("buffer").Buffer)},{"../util/preconditions":45,"bn.js":186,buffer:90,lodash:211}],7:[function(t,e,r){(function(r){"use strict";var n=t("./bn"),i=t("./point"),s=t("./signature"),o=t("../publickey"),a=t("./random"),f=t("./hash"),u=t("../util/buffer"),h=t("lodash"),c=t("../util/preconditions"),d=function p(t){return this instanceof p?void(t&&this.set(t)):new p(t)};d.prototype.set=function(t){return this.hashbuf=t.hashbuf||this.hashbuf,this.endian=t.endian||this.endian,this.privkey=t.privkey||this.privkey,this.pubkey=t.pubkey||(this.privkey?this.privkey.publicKey:this.pubkey),this.sig=t.sig||this.sig,this.k=t.k||this.k,this.verified=t.verified||this.verified,this},d.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()},d.prototype.calci=function(){for(var t=0;4>t;t++){this.sig.i=t;var e;try{e=this.toPublicKey()}catch(r){console.error(r);continue}if(e.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")},d.fromString=function(t){var e=JSON.parse(t);return new d(e)},d.prototype.randomK=function(){var t,e=i.getN();do t=n.fromBuffer(a.getRandomBuffer(32));while(!t.lt(e)||!t.gt(n.Zero));return this.k=t,this},d.prototype.deterministicK=function(t){h.isUndefined(t)&&(t=0);var e=new r(32);e.fill(1);var s=new r(32);s.fill(0);var o=this.privkey.bn.toBuffer({size:32});s=f.sha256hmac(r.concat([e,new r([0]),o,this.hashbuf]),s),e=f.sha256hmac(e,s),s=f.sha256hmac(r.concat([e,new r([1]),o,this.hashbuf]),s),e=f.sha256hmac(e,s),e=f.sha256hmac(e,s);for(var a=n.fromBuffer(e),u=i.getN(),c=0;t>c||!a.lt(u)||!a.gt(n.Zero);c++)s=f.sha256hmac(r.concat([e,new r([0])]),s),e=f.sha256hmac(e,s),e=f.sha256hmac(e,s),a=n.fromBuffer(e);return this.k=a,this},d.prototype.toPublicKey=function(){var t=this.sig.i;c.checkArgument(0===t||1===t||2===t||3===t,new Error("i must be equal to 0, 1, 2, or 3"));var e=n.fromBuffer(this.hashbuf),r=this.sig.r,s=this.sig.s,a=1&t,f=t>>1,u=i.getN(),h=i.getG(),d=f?r.add(u):r,p=i.fromX(a,d),l=p.mul(u);if(!l.isInfinity())throw new Error("nR is not a valid curve point");var b=e.neg().mod(u),g=r.invm(u),v=p.mul(s).add(h.mul(b)).mul(g),y=o.fromPoint(v,this.sig.compressed);return y},d.prototype.sigError=function(){if(!u.isBuffer(this.hashbuf)||32!==this.hashbuf.length)return"hashbuf must be a 32 byte buffer";var t=this.sig.r,e=this.sig.s;if(!(t.gt(n.Zero)&&t.lt(i.getN())&&e.gt(n.Zero)&&e.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=e.invm(s),a=o.mul(r).mod(s),f=o.mul(t).mod(s),h=i.getG().mulAdd(a,this.pubkey.point,f);return h.isInfinity()?"p is infinity":0!==h.getX().mod(s).cmp(t)?"Invalid signature":!1},d.toLowS=function(t){return t.gt(n.fromBuffer(new r("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))&&(t=i.getN().sub(t)),t},d.prototype._findSignature=function(t,e){var r,s,o,a,f=i.getN(),u=i.getG(),h=0;do(!this.k||h>0)&&this.deterministicK(h),h++,r=this.k,s=u.mul(r),o=s.x.mod(f),a=r.invm(f).mul(e.add(t.mul(o))).mod(f);while(o.cmp(n.Zero)<=0||a.cmp(n.Zero)<=0);return a=d.toLowS(a),{s:a,r:o}},d.prototype.sign=function(){var t=this.hashbuf,e=this.privkey,r=e.bn;c.checkState(t&&e&&r,new Error("invalid parameters")),c.checkState(u.isBuffer(t)&&32===t.length,new Error("hashbuf must be a 32 byte buffer"));var i=n.fromBuffer(t,this.endian?{endian:this.endian}:void 0),o=this._findSignature(r,i);return o.compressed=this.pubkey.compressed,this.sig=new s(o),this},d.prototype.signRandomK=function(){return this.randomK(),this.sign()},d.prototype.toString=function(){var t={};return this.hashbuf&&(t.hashbuf=this.hashbuf.toString("hex")),this.privkey&&(t.privkey=this.privkey.toString()),this.pubkey&&(t.pubkey=this.pubkey.toString()),this.sig&&(t.sig=this.sig.toString()),this.k&&(t.k=this.k.toString()),JSON.stringify(t)},d.prototype.verify=function(){return this.sigError()?this.verified=!1:this.verified=!0,this},d.sign=function(t,e,r){return d().set({hashbuf:t,endian:r,privkey:e}).sign().sig},d.verify=function(t,e,r,n){return d().set({hashbuf:t,endian:n,sig:e,pubkey:r}).verify().verified},e.exports=d}).call(this,t("buffer").Buffer)},{"../publickey":25,"../util/buffer":43,"../util/preconditions":45,"./bn":6,"./hash":8,"./point":9,"./random":10,"./signature":11,buffer:90,lodash:211}],8:[function(t,e,r){(function(r){"use strict";var n=t("sha512"),i=t("crypto"),s=t("../util/buffer"),o=t("../util/preconditions"),a=e.exports;a.sha1=function(t){return o.checkArgument(s.isBuffer(t)),i.createHash("sha1").update(t).digest()},a.sha1.blocksize=512,a.sha256=function(t){return o.checkArgument(s.isBuffer(t)),i.createHash("sha256").update(t).digest()},a.sha256.blocksize=512,a.sha256sha256=function(t){return o.checkArgument(s.isBuffer(t)),a.sha256(a.sha256(t))},a.ripemd160=function(t){return o.checkArgument(s.isBuffer(t)),i.createHash("rmd160").update(t).digest()},a.sha256ripemd160=function(t){return o.checkArgument(s.isBuffer(t)),a.ripemd160(a.sha256(t))},a.sha512=function(t){o.checkArgument(s.isBuffer(t));var e=n(t);return new r(e)},a.sha512.blocksize=1024,a.hmac=function(t,e,n){o.checkArgument(s.isBuffer(e)),o.checkArgument(s.isBuffer(n)),o.checkArgument(t.blocksize);var i=t.blocksize/8;if(n.length>i)n=t(n);else if(i>n){var a=new r(i);a.fill(0),n.copy(a),n=a}var f=new r(i);f.fill(92);var u=new r(i);u.fill(54);for(var h=new r(i),c=new r(i),d=0;i>d;d++)h[d]=f[d]^n[d],c[d]=u[d]^n[d];return t(r.concat([h,t(r.concat([c,e]))]))},a.sha256hmac=function(t,e){return a.hmac(a.sha256,t,e)},a.sha512hmac=function(t,e){return a.hmac(a.sha512,t,e)}}).call(this,t("buffer").Buffer)},{"../util/buffer":43,"../util/preconditions":45,buffer:90,crypto:99,sha512:214}],9:[function(t,e,r){(function(r){"use strict";var n=t("./bn"),i=t("../util/buffer"),s=t("elliptic").curves.secp256k1,o=s.curve.point.bind(s.curve),a=s.curve.pointFromX.bind(s.curve),f=function(t,e,r){var n=o(t,e,r);return n.validate(),n};f.prototype=Object.getPrototypeOf(s.curve.point()),f.fromX=function(t,e){var r=a(t,e);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 t=a(this.getY().isOdd(),this.getX());if(0!==t.y.cmp(this.y))throw new Error("Invalid y value for curve.");var e=this.getX().gt(n.Minus1)&&this.getX().lt(f.getN()),r=this.getY().gt(n.Minus1)&&this.getY().lt(f.getN());if(!e||!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(t){var e,n=t.getX().toBuffer({size:32}),s=t.getY().toBuffer({size:32}),o=s[s.length-1]%2;return e=new r(o?[3]:[2]),i.concat([e,n])},e.exports=f}).call(this,t("buffer").Buffer)},{"../util/buffer":43,"./bn":6,buffer:90,elliptic:190}],10:[function(t,e,r){(function(r,n){"use strict";function i(){}i.getRandomBuffer=function(t){return r.browser?i.getRandomBufferBrowser(t):i.getRandomBufferNode(t)},i.getRandomBufferNode=function(e){var r=t("crypto");return r.randomBytes(e)},i.getRandomBufferBrowser=function(t){if(!window.crypto&&!window.msCrypto)throw new Error("window.crypto not available");if(window.crypto&&window.crypto.getRandomValues)var e=window.crypto;else{if(!window.msCrypto||!window.msCrypto.getRandomValues)throw new Error("window.crypto.getRandomValues not available");var e=window.msCrypto}var r=new Uint8Array(t);e.getRandomValues(r);var i=new n(r);return i},i.getPseudoRandomBuffer=function(t){for(var e,r=4294967296,i=new n(t),s=0;t>=s;s++){var o=Math.floor(s/4),a=s-4*o;0===a?(e=Math.random()*r,i[s]=255&e):i[s]=255&(e>>>=8)}return i},e.exports=i}).call(this,t("_process"),t("buffer").Buffer)},{_process:148,buffer:90,crypto:99}],11:[function(t,e,r){(function(r){"use strict";var n=t("./bn"),i=t("lodash"),s=t("../util/preconditions"),o=t("../util/buffer"),a=t("../util/js"),f=function u(t,e){if(!(this instanceof u))return new u(t,e);if(t instanceof n)this.set({r:t,s:e});else if(t){var r=t;this.set(r)}};f.prototype.set=function(t){return this.r=t.r||this.r||void 0,this.s=t.s||this.s||void 0,this.i="undefined"!=typeof t.i?t.i:this.i,this.compressed="undefined"!=typeof t.compressed?t.compressed:this.compressed,this.nhashtype=t.nhashtype||this.nhashtype||void 0,this},f.fromCompact=function(t){s.checkArgument(o.isBuffer(t),"Argument is expected to be a Buffer");var e=new f,r=!0,i=t.slice(0,1)[0]-27-4;0>i&&(r=!1,i+=4);var a=t.slice(1,33),u=t.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===a.length,new Error("r must be 32 bytes")),s.checkArgument(32===u.length,new Error("s must be 32 bytes")),e.compressed=r,e.i=i,e.r=n.fromBuffer(a),e.s=n.fromBuffer(u),e},f.fromDER=f.fromBuffer=function(t,e){var r=f.parseDER(t,e),n=new f;return n.r=r.r,n.s=r.s,n},f.fromTxFormat=function(t){var e=t.readUInt8(t.length-1),r=t.slice(0,t.length-1),n=new f.fromDER(r,!1);return n.nhashtype=e,n},f.fromString=function(t){var e=new r(t,"hex");return f.fromDER(e)},f.parseDER=function(t,e){s.checkArgument(o.isBuffer(t),new Error("DER formatted signature should be a buffer")),i.isUndefined(e)&&(e=!0);var r=t[0];s.checkArgument(48===r,new Error("Header byte should be 0x30"));var a=t[1],f=t.slice(2).length;s.checkArgument(!e||a===f,new Error("Length byte should length of what follows")),a=f>a?a:f;var u=t[2];s.checkArgument(2===u,new Error("Integer byte for r should be 0x02"));var h=t[3],c=t.slice(4,4+h),d=n.fromBuffer(c),p=0===t[4];s.checkArgument(h===c.length,new Error("Length of r incorrect"));var l=t[4+h+0];s.checkArgument(2===l,new Error("Integer byte for s should be 0x02"));var b=t[4+h+1],g=t.slice(4+h+2,4+h+2+b),v=n.fromBuffer(g),y=0===t[4+h+2+2];s.checkArgument(b===g.length,new Error("Length of s incorrect"));var m=4+h+2+b;s.checkArgument(a===m-2,new Error("Length of signature incorrect"));var _={header:r,length:a,rheader:u,rlength:h,rneg:p,rbuf:c,r:d,sheader:l,slength:b,sneg:y,sbuf:g,s:v};return _},f.prototype.toCompact=function(t,e){if(t="number"==typeof t?t:this.i,e="boolean"==typeof e?e:this.compressed,0!==t&&1!==t&&2!==t&&3!==t)throw new Error("i must be equal to 0, 1, 2, or 3");var n=t+27+4;e===!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])},f.prototype.toBuffer=f.prototype.toDER=function(){var t=this.r.toBuffer(),e=this.s.toBuffer(),n=!!(128&t[0]),i=!!(128&e[0]),s=n?r.concat([new r([0]),t]):t,o=i?r.concat([new r([0]),e]):e,a=s.length,f=o.length,u=2+a+2+f,h=2,c=2,d=48,p=r.concat([new r([d,u,h,a]),s,new r([c,f]),o]);return p},f.prototype.toString=function(){var t=this.toDER();return t.toString("hex")},f.isTxDER=function(t){if(t.length<9)return!1;if(t.length>73)return!1;if(48!==t[0])return!1;if(t[1]!==t.length-3)return!1;var e=t[3];if(5+e>=t.length)return!1;var r=t[5+e];if(e+r+7!==t.length)return!1;var n=t.slice(4);if(2!==t[2])return!1;if(0===e)return!1;if(128&n[0])return!1;if(e>1&&0===n[0]&&!(128&n[1]))return!1;var i=t.slice(6+e);return 2!==t[6+e-2]?!1:0===r?!1:128&i[0]?!1:!(r>1&&0===i[0])||128&i[1]},f.prototype.hasLowS=function(){return!this.s.lt(new n(1))&&!this.s.gt(new n("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex"))},f.prototype.hasDefinedHashtype=function(){if(!a.isNaturalNumber(this.nhashtype))return!1;var t=this.nhashtype&~f.SIGHASH_ANYONECANPAY;return!(t<f.SIGHASH_ALL||t>f.SIGHASH_SINGLE)},f.prototype.toTxFormat=function(){var t=this.toDER(),e=new r(1);return e.writeUInt8(this.nhashtype,0),r.concat([t,e])},f.SIGHASH_ALL=1,f.SIGHASH_NONE=2,f.SIGHASH_SINGLE=3,f.SIGHASH_ANYONECANPAY=128,e.exports=f}).call(this,t("buffer").Buffer)},{"../util/buffer":43,"../util/js":44,"../util/preconditions":45,"./bn":6,buffer:90,lodash:211}],12:[function(t,e,r){(function(r){"use strict";var n=t("lodash"),i=t("bs58"),s=t("buffer"),o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split(""),a=function f(t){if(!(this instanceof f))return new f(t);if(r.isBuffer(t)){var e=t;this.fromBuffer(e)}else if("string"==typeof t){var n=t;this.fromString(n)}else t&&this.set(t)};a.validCharacters=function(t){return s.Buffer.isBuffer(t)&&(t=t.toString()),n.every(n.map(t,function(t){return n.includes(o,t)}))},a.prototype.set=function(t){return this.buf=t.buf||this.buf||void 0,this},a.encode=function(t){if(!s.Buffer.isBuffer(t))throw new Error("Input should be a buffer");return i.encode(t)},a.decode=function(t){if("string"!=typeof t)throw new Error("Input should be a string");return new r(i.decode(t))},a.prototype.fromBuffer=function(t){return this.buf=t,
this},a.prototype.fromString=function(t){var e=a.decode(t);return this.buf=e,this},a.prototype.toBuffer=function(){return this.buf},a.prototype.toString=function(){return a.encode(this.buf)},e.exports=a}).call(this,t("buffer").Buffer)},{bs58:188,buffer:90,lodash:211}],13:[function(t,e,r){(function(r){"use strict";var n=t("lodash"),i=t("./base58"),s=t("buffer"),o=t("../crypto/hash").sha256sha256,a=function f(t){if(!(this instanceof f))return new f(t);if(r.isBuffer(t)){var e=t;this.fromBuffer(e)}else if("string"==typeof t){var n=t;this.fromString(n)}else t&&this.set(t)};a.prototype.set=function(t){return this.buf=t.buf||this.buf||void 0,this},a.validChecksum=function(t,e){return n.isString(t)&&(t=new s.Buffer(i.decode(t))),n.isString(e)&&(e=new s.Buffer(i.decode(e))),e||(e=t.slice(-4),t=t.slice(0,-4)),a.checksum(t).toString("hex")===e.toString("hex")},a.decode=function(t){if("string"!=typeof t)throw new Error("Input must be a string");var e=new r(i.decode(t));if(e.length<4)throw new Error("Input string too short");var n=e.slice(0,-4),s=e.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(t){return o(t).slice(0,4)},a.encode=function(t){if(!r.isBuffer(t))throw new Error("Input must be a buffer");var e=new r(t.length+4),n=a.checksum(t);return t.copy(e),n.copy(e,t.length),i.encode(e)},a.prototype.fromBuffer=function(t){return this.buf=t,this},a.prototype.fromString=function(t){var e=a.decode(t);return this.buf=e,this},a.prototype.toBuffer=function(){return this.buf},a.prototype.toString=function(){return a.encode(this.buf)},e.exports=a}).call(this,t("buffer").Buffer)},{"../crypto/hash":8,"./base58":12,buffer:90,lodash:211}],14:[function(t,e,r){(function(r){"use strict";var n=t("lodash"),i=t("../util/preconditions"),s=t("../util/buffer"),o=t("../crypto/bn"),a=function f(t){if(!(this instanceof f))return new f(t);if(!n.isUndefined(t))if(r.isBuffer(t))this.set({buf:t});else if(n.isString(t))this.set({buf:new r(t,"hex")});else{if(!n.isObject(t))throw new TypeError("Unrecognized argument for BufferReader");var e=t;this.set(e)}};a.prototype.set=function(t){return this.buf=t.buf||this.buf||void 0,this.pos=t.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(t){i.checkArgument(!n.isUndefined(t),"Must specify a length");var e=this.buf.slice(this.pos,this.pos+t);return this.pos=this.pos+t,e},a.prototype.readAll=function(){var t=this.buf.slice(this.pos,this.buf.length);return this.pos=this.buf.length,t},a.prototype.readUInt8=function(){var t=this.buf.readUInt8(this.pos);return this.pos=this.pos+1,t},a.prototype.readUInt16BE=function(){var t=this.buf.readUInt16BE(this.pos);return this.pos=this.pos+2,t},a.prototype.readUInt16LE=function(){var t=this.buf.readUInt16LE(this.pos);return this.pos=this.pos+2,t},a.prototype.readUInt32BE=function(){var t=this.buf.readUInt32BE(this.pos);return this.pos=this.pos+4,t},a.prototype.readUInt32LE=function(){var t=this.buf.readUInt32LE(this.pos);return this.pos=this.pos+4,t},a.prototype.readUInt64BEBN=function(){var t=this.buf.slice(this.pos,this.pos+8),e=o.fromBuffer(t);return this.pos=this.pos+8,e},a.prototype.readUInt64LEBN=function(){var t,e=this.buf.readUInt32LE(this.pos),r=this.buf.readUInt32LE(this.pos+4),n=4294967296*r+e;if(9007199254740991>=n)t=new o(n);else{var i=Array.prototype.slice.call(this.buf,this.pos,this.pos+8);t=new o(i,10,"le")}return this.pos=this.pos+8,t},a.prototype.readVarintNum=function(){var t=this.readUInt8();switch(t){case 253:return this.readUInt16LE();case 254:return this.readUInt32LE();case 255:var e=this.readUInt64LEBN(),r=e.toNumber();if(r<=Math.pow(2,53))return r;throw new Error("number too large to retain precision - use readVarintBN");default:return t}},a.prototype.readVarLengthBuffer=function(){var t=this.readVarintNum(),e=this.read(t);return i.checkState(e.length===t,"Invalid length while reading varlength buffer. Expected to read: "+t+" and read "+e.length),e},a.prototype.readVarintBuf=function(){var t=this.buf.readUInt8(this.pos);switch(t){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 t=this.readUInt8();switch(t){case 253:return new o(this.readUInt16LE());case 254:return new o(this.readUInt32LE());case 255:return this.readUInt64LEBN();default:return new o(t)}},a.prototype.reverse=function(){for(var t=new r(this.buf.length),e=0;e<t.length;e++)t[e]=this.buf[this.buf.length-1-e];return this.buf=t,this},a.prototype.readReverse=function(t){n.isUndefined(t)&&(t=this.buf.length);var e=this.buf.slice(this.pos,this.pos+t);return this.pos=this.pos+t,s.reverse(e)},e.exports=a}).call(this,t("buffer").Buffer)},{"../crypto/bn":6,"../util/buffer":43,"../util/preconditions":45,buffer:90,lodash:211}],15:[function(t,e,r){(function(r){"use strict";var n=t("../util/buffer"),i=t("assert"),s=function o(t){return this instanceof o?void(t?this.set(t):this.bufs=[]):new o(t)};s.prototype.set=function(t){return this.bufs=t.bufs||this.bufs||[],this},s.prototype.toBuffer=function(){return this.concat()},s.prototype.concat=function(){return r.concat(this.bufs)},s.prototype.write=function(t){return i(n.isBuffer(t)),this.bufs.push(t),this},s.prototype.writeReverse=function(t){return i(n.isBuffer(t)),this.bufs.push(n.reverse(t)),this},s.prototype.writeUInt8=function(t){var e=new r(1);return e.writeUInt8(t,0),this.write(e),this},s.prototype.writeUInt16BE=function(t){var e=new r(2);return e.writeUInt16BE(t,0),this.write(e),this},s.prototype.writeUInt16LE=function(t){var e=new r(2);return e.writeUInt16LE(t,0),this.write(e),this},s.prototype.writeUInt32BE=function(t){var e=new r(4);return e.writeUInt32BE(t,0),this.write(e),this},s.prototype.writeInt32LE=function(t){var e=new r(4);return e.writeInt32LE(t,0),this.write(e),this},s.prototype.writeUInt32LE=function(t){var e=new r(4);return e.writeUInt32LE(t,0),this.write(e),this},s.prototype.writeUInt64BEBN=function(t){var e=t.toBuffer({size:8});return this.write(e),this},s.prototype.writeUInt64LEBN=function(t){var e=t.toBuffer({size:8});return this.writeReverse(e),this},s.prototype.writeVarintNum=function(t){var e=s.varintBufNum(t);return this.write(e),this},s.prototype.writeVarintBN=function(t){var e=s.varintBufBN(t);return this.write(e),this},s.varintBufNum=function(t){var e=void 0;return 253>t?(e=new r(1),e.writeUInt8(t,0)):65536>t?(e=new r(3),e.writeUInt8(253,0),e.writeUInt16LE(t,1)):4294967296>t?(e=new r(5),e.writeUInt8(254,0),e.writeUInt32LE(t,1)):(e=new r(9),e.writeUInt8(255,0),e.writeInt32LE(-1&t,1),e.writeUInt32LE(Math.floor(t/4294967296),5)),e},s.varintBufBN=function(t){var e=void 0,n=t.toNumber();if(253>n)e=new r(1),e.writeUInt8(n,0);else if(65536>n)e=new r(3),e.writeUInt8(253,0),e.writeUInt16LE(n,1);else if(4294967296>n)e=new r(5),e.writeUInt8(254,0),e.writeUInt32LE(n,1);else{var i=new s;i.writeUInt8(255),i.writeUInt64LEBN(t);var e=i.concat()}return e},e.exports=s}).call(this,t("buffer").Buffer)},{"../util/buffer":43,assert:60,buffer:90}],16:[function(t,e,r){(function(r){"use strict";var n=t("./bufferwriter"),i=t("./bufferreader"),s=t("../crypto/bn"),o=function a(t){if(!(this instanceof a))return new a(t);if(r.isBuffer(t))this.buf=t;else if("number"==typeof t){var e=t;this.fromNumber(e)}else if(t instanceof s){var n=t;this.fromBN(n)}else if(t){var i=t;this.set(i)}};o.prototype.set=function(t){return this.buf=t.buf||this.buf,this},o.prototype.fromString=function(t){return this.set({buf:new r(t,"hex")}),this},o.prototype.toString=function(){return this.buf.toString("hex")},o.prototype.fromBuffer=function(t){return this.buf=t,this},o.prototype.fromBufferReader=function(t){return this.buf=t.readVarintBuf(),this},o.prototype.fromBN=function(t){return this.buf=n().writeVarintBN(t).concat(),this},o.prototype.fromNumber=function(t){return this.buf=n().writeVarintNum(t).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()},e.exports=o}).call(this,t("buffer").Buffer)},{"../crypto/bn":6,"./bufferreader":14,"./bufferwriter":15,buffer:90}],17:[function(t,e,r){"use strict";function n(t,e){return t.replace("{0}",e[0]).replace("{1}",e[1]).replace("{2}",e[2])}var i=t("lodash"),s=function(t,e){var r=function(){if(i.isString(e.message))this.message=n(e.message,arguments);else{if(!i.isFunction(e.message))throw new Error("Invalid error definition for "+e.name);this.message=e.message.apply(null,arguments)}this.stack=this.message+"\n"+(new Error).stack};return r.prototype=Object.create(t.prototype),r.prototype.name=t.prototype.name+e.name,t[e.name]=r,e.errors&&o(r,e.errors),r},o=function(t,e){i.each(e,function(e){s(t,e)})},a=function(t,e){return o(t,e),t},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 u=t("./spec");a(f.Error,u),e.exports=f.Error,e.exports.extend=function(t){return s(f.Error,t)}},{"./spec":18,lodash:211}],18:[function(t,e,r){"use strict";var n="http://bitcore.io/";e.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 Invocation: {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:"InvalidIndexCantDeriveHardened",message:"Invalid argument: creating a hardened path requires an HDPrivateKey"},{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(t,e,r){"use strict";e.exports={_cache:{},_count:0,_eraseIndex:0,_usedList:{},_usedIndex:{},_CACHE_SIZE:5e3,get:function(t,e,r){r=!!r;var n=t+"/"+e+"/"+r;return this._cache[n]?(this._cacheHit(n),this._cache[n]):void 0},set:function(t,e,r,n){r=!!r;var i=t+"/"+e+"/"+r;this._cache[i]=n,this._cacheHit(i)},_cacheHit:function(t){this._usedIndex[t]&&delete this._usedList[this._usedIndex[t]],this._usedList[this._count]=t,this._usedIndex[t]=this._count,this._count++,this._cacheRemove()},_cacheRemove:function(){for(;this._eraseIndex<this._count-this._CACHE_SIZE;){if(this._usedList[this._eraseIndex]){var t=this._usedList[this._eraseIndex];delete this._usedIndex[t],delete this._cache[t]}delete this._usedList[this._eraseIndex],this._eraseIndex++}}}},{}],20:[function(t,e,r){(function(r){"use strict";function n(t){if(t instanceof n)return t;if(!(this instanceof n))return new n(t);if(!t)return this._generateRandomly();if(d.get(t))return this._generateRandomly(t);if(o.isString(t)||m.isBuffer(t))if(n.isValidSerialized(t))this._buildFromSerialized(t);else if(_.isValidJSON(t))this._buildFromJSON(t);else{if(!m.isBuffer(t)||!n.isValidSerialized(t.toString()))throw n.getSerializedError(t);this._buildFromSerialized(t.toString())}else{if(!o.isObject(t))throw new y.UnrecognizedArgument(t);this._buildFromObject(t)}}var i=t("assert"),s=t("buffer"),o=t("lodash"),a=t("./util/preconditions"),f=t("./crypto/bn"),u=t("./encoding/base58"),h=t("./encoding/base58check"),c=t("./crypto/hash"),d=t("./networks"),p=t("./hdkeycache"),l=t("./crypto/point"),b=t("./privatekey"),g=t("./crypto/random"),v=t("./errors"),y=v.HDPrivateKey,m=t("./util/buffer"),_=t("./util/js"),w=128,S=1/8,k=512;n.isValidPath=function(t,e){if(o.isString(t)){var r=n._getDerivationIndexes(t);return null!==r&&o.every(r,n.isValidPath)}return o.isNumber(t)?(t<n.Hardened&&e===!0&&(t+=n.Hardened),t>=0&&t<n.MaxIndex):!1},n._getDerivationIndexes=function(t){var e=t.split("/");if(o.includes(n.RootElementAlias,t))return[];if(!o.includes(n.RootElementAlias,e[0]))return null;var r=e.slice(1).map(function(t){var e="'"===t.slice(-1);if(e&&(t=t.slice(0,-1)),!t||"-"===t[0])return NaN;var r=+t;return e&&(r+=n.Hardened),r});return o.some(r,isNaN)?null:r},n.prototype.derive=function(t,e){if(o.isNumber(t))return this._deriveWithNumber(t,e);if(o.isString(t))return this._deriveFromString(t);throw new y.InvalidDerivationArgument(t)},n.prototype._deriveWithNumber=function(t,e){if(!n.isValidPath(t,e))throw new y.InvalidPath(t);e=t>=n.Hardened?!0:e,t<n.Hardened&&e===!0&&(t+=n.Hardened);var r=p.get(this.xprivkey,t,e);if(r)return r;var i,o=m.integerAsBuffer(t);i=e?m.concat([new s.Buffer([0]),this.privateKey.toBuffer(),o]):m.concat([this.publicKey.toBuffer(),o]);var a=c.sha512hmac(i,this._buffers.chainCode),u=f.fromBuffer(a.slice(0,32),{size:32}),h=a.slice(32,64),d=u.add(this.privateKey.toBigNumber()).mod(l.getN()).toBuffer({size:32}),b=new n({network:this.network,depth:this.depth+1,parentFingerPrint:this.fingerPrint,childIndex:t,chainCode:h,privateKey:d});return p.set(this.xprivkey,t,e,b),b},n.prototype._deriveFromString=function(t){if(!n.isValidPath(t))throw new y.InvalidPath(t);var e=n._getDerivationIndexes(t),r=e.reduce(function(t,e){return t._deriveWithNumber(e)},this);return r},n.isValidSerialized=function(t,e){return!n.getSerializedError(t,e)},n.getSerializedError=function(t,e){if(!o.isString(t)&&!m.isBuffer(t))return new y.UnrecognizedArgument("Expected string or buffer");if(!u.validCharacters(t))return new v.InvalidB58Char("(unknown)",t);try{t=h.decode(t)}catch(r){return new v.InvalidB58Checksum(t)}if(t.length!==n.DataLength)return new y.InvalidLength(t);if(!o.isUndefined(e)){var i=n._validateNetwork(t,e);if(i)return i}return null},n._validateNetwork=function(t,e){var r=d.get(e);if(!r)return new v.InvalidNetworkArgument(e);var n=t.slice(0,4);return m.integerFromBuffer(n)!==r.xprivkey?new v.InvalidNetwork(n):null},n.fromString=function(t){return a.checkArgument(o.isString(t),"No valid string was provided"),new n(t)},n.fromObject=function(t){return a.checkArgument(o.isObject(t),"No valid argument was provided"),new n(t)},n.prototype._buildFromJSON=function(t){return this._buildFromObject(JSON.parse(t))},n.prototype._buildFromObject=function(t){var e={version:t.network?m.integerAsBuffer(d.get(t.network).xprivkey):t.version,depth:o.isNumber(t.depth)?m.int