UNPKG

@pushievo/pushicore-lib

Version:

A pure and powerful JavaScript Dash library.

2 lines 817 kB
require=function e(t,r,n){function i(o,u){if(!r[o]){if(!t[o]){var a="function"==typeof require&&require;if(!u&&a)return a(o,!0);if(s)return s(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var h=r[o]={exports:{}};t[o][0].call(h.exports,function(e){var r=t[o][1][e];return i(r||e)},h,h.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&&!a.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||a.get(t)||a.defaultNetwork,o.type=o.type||r||n.PayToPublicKeyHash,h.defineImmutable(this,{hashBuffer:o.hashBuffer,network:o.network,type:o.type}),this}var i=e("lodash"),s=e("./util/preconditions"),o=e("./errors"),u=e("./encoding/base58check"),a=e("./networks"),f=e("./crypto/hash"),h=e("./util/js"),c=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 c)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:a.get(e.network)||a.defaultNetwork,type:e.type}},n._classifyFromVersion=function(e){var t={},r=a.get(e[0],"pubkeyhash"),i=a.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=a.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 c))throw new TypeError("Address must be an instance of PublicKey.");return t.hashBuffer=f.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||a.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=u.decode(e);return n._transformBuffer(i,t,r)},n.fromPublicKey=function(e,t){var r=n._transformPublicKey(e);return t=t||a.defaultNetwork,new n(r.hashBuffer,t,r.type)},n.fromPublicKeyHash=function(e,t){return new n(n._transformHash(e).hashBuffer,t,n.PayToPublicKeyHash)},n.fromScriptHash=function(e,t){return s.checkArgument(e,"hash parameter is required"),new n(n._transformHash(e).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(f.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.fromObject=function(e){return s.checkState(h.isHexa(e.hash),'Unexpected hash property, "'+e.hash+'", expected to be hex.'),new n(new r(e.hash,"hex"),e.network,e.type)},n.getValidationError=function(e,t,r){var i;try{new n(e,t,r)}catch(e){i=e}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]]);return r.concat([e,this.hashBuffer])},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 u.encode(this.toBuffer())},n.prototype.inspect=function(){return"<Address: "+this.toString()+", type: "+this.type+", network: "+this.network+">"},t.exports=n;var d=e("./script")}).call(this,e("buffer").Buffer)},{"./crypto/hash":8,"./encoding/base58check":13,"./errors":17,"./networks":25,"./publickey":28,"./script":29,"./util/js":47,"./util/preconditions":48,buffer:118,lodash:192}],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"),u=e("../util/buffer"),a=e("../encoding/bufferreader"),f=e("../encoding/bufferwriter"),h=e("../crypto/hash"),c=e("../transaction"),d=e("../util/preconditions");n.MAX_BLOCK_SIZE=1e6,n._from=function(e){var t={};if(u.isBuffer(e))t=n._fromBufferReader(a(e));else{if(!i.isObject(e))throw new TypeError("Unrecognized argument for Block");t=n._fromObject(e)}return t},n._fromObject=function(e){var t=[];return e.transactions.forEach(function(e){e instanceof c?t.push(e):t.push(c().fromObject(e))}),{header:s.fromObject(e.header),transactions:t}},n.fromObject=function(e){return new n(n._fromObject(e))},n._fromBufferReader=function(e){var t={};d.checkState(!e.finished(),"No block data received"),t.header=s.fromBufferReader(e);var r=e.readVarintNum();t.transactions=[];for(var n=0;n<r;n++)t.transactions.push(c().fromBufferReader(e));return t},n.fromBufferReader=function(e){return d.checkArgument(e,"br is required"),new n(n._fromBufferReader(e))},n.fromBuffer=function(e){return n.fromBufferReader(new a(e))},n.fromString=function(e){var t=new r(e,"hex");return n.fromBuffer(t)},n.fromRawBlock=function(e){u.isBuffer(e)||(e=new r(e,"binary"));var t=a(e);return t.pos=n.Values.START_OF_BLOCK,new n(n._fromBufferReader(t))},n.prototype.toObject=n.prototype.toJSON=function(){var e=[];return this.transactions.forEach(function(t){e.push(t.toObject())}),{header:this.header.toObject(),transactions:e}},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 f),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;i<n;i+=2){var s=Math.min(i+1,n-1),o=r.concat([e[t+i],e[t+s]]);e.push(h.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)},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":32,"../util/buffer":46,"../util/preconditions":48,"./blockheader":3,buffer:118,lodash:192}],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"),u=e("../encoding/bufferwriter"),a=e("../crypto/hash"),f=(e("../util/js"),e("../util/preconditions")),h=function e(t){if(!(this instanceof e))return new e(t);var r=e._from(t);return this.version=r.version,this.prevHash=r.prevHash,this.merkleRoot=r.merkleRoot,this.time=r.time,this.timestamp=r.time,this.bits=r.bits,this.nonce=r.nonce,r.hash&&f.checkState(this.hash===r.hash,"Argument object hash property does not match block hash."),this};h._from=function(e){var t={};if(s.isBuffer(e))t=h._fromBufferReader(o(e));else{if(!n.isObject(e))throw new TypeError("Unrecognized argument for BlockHeader");t=h._fromObject(e)}return t},h._fromObject=function(e){f.checkArgument(e,"data is required");var t=e.prevHash,i=e.merkleRoot;return n.isString(e.prevHash)&&(t=s.reverse(new r(e.prevHash,"hex"))),n.isString(e.merkleRoot)&&(i=s.reverse(new r(e.merkleRoot,"hex"))),{hash:e.hash,version:e.version,prevHash:t,merkleRoot:i,time:e.time,timestamp:e.time,bits:e.bits,nonce:e.nonce}},h.fromObject=function(e){var t=h._fromObject(e);return new h(t)},h.fromRawBlock=function(e){s.isBuffer(e)||(e=new r(e,"binary"));var t=o(e);t.pos=h.Constants.START_OF_HEADER;var n=h._fromBufferReader(t);return new h(n)},h.fromBuffer=function(e){var t=h._fromBufferReader(o(e));return new h(t)},h.fromString=function(e){var t=new r(e,"hex");return h.fromBuffer(t)},h._fromBufferReader=function(e){var t={};return t.version=e.readInt32LE(),t.prevHash=e.read(32),t.merkleRoot=e.read(32),t.time=e.readUInt32LE(),t.bits=e.readUInt32LE(),t.nonce=e.readUInt32LE(),t},h.fromBufferReader=function(e){var t=h._fromBufferReader(e);return new h(t)},h.prototype.toObject=h.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}},h.prototype.toBuffer=function(){return this.toBufferWriter().concat()},h.prototype.toString=function(){return this.toBuffer().toString("hex")},h.prototype.toBufferWriter=function(e){return e||(e=new u),e.writeInt32LE(this.version),e.write(this.prevHash),e.write(this.merkleRoot),e.writeUInt32LE(this.time),e.writeUInt32LE(this.bits),e.writeUInt32LE(this.nonce),e},h.prototype.getTargetDifficulty=function(e){e=e||this.bits;for(var t=new i(16777215&e),r=8*((e>>>24)-3);r-- >0;)t=t.mul(new i(2));return t},h.prototype.getDifficulty=function(){var e=this.getTargetDifficulty(486604799).mul(new i(Math.pow(10,8))),t=this.getTargetDifficulty(),r=e.div(t).toString(10),n=r.length-8;return r=r.slice(0,n)+"."+r.slice(n),parseFloat(r)},h.prototype._getHash=function(){var e=this.toBuffer();return a.x11(e)};var c={configurable:!1,enumerable:!0,get:function(){return this._id||(this._id=o(this._getHash()).readReverse().toString("hex")),this._id},set:n.noop};Object.defineProperty(h.prototype,"id",c),Object.defineProperty(h.prototype,"hash",c),h.prototype.validTimestamp=function(){var e=Math.round((new Date).getTime()/1e3);return!(this.time>e+h.Constants.MAX_TIME_OFFSET)},h.prototype.validProofOfWork=function(){var e=new i(this.id,"hex"),t=this.getTargetDifficulty();return!(e.cmp(t)>0)},h.prototype.inspect=function(){return"<BlockHeader "+this.id+">"},h.Constants={START_OF_HEADER:8,MAX_TIME_OFFSET:7200,LARGEST_HASH:new i("10000000000000000000000000000000000000000000000000000000000000000","hex")},t.exports=h}).call(this,e("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../util/buffer":46,"../util/js":47,"../util/preconditions":48,buffer:118,lodash:192}],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(u(e));else{if(!i.isObject(e))throw new TypeError("Unrecognized argument for MerkleBlock");var r;r=e.header instanceof s?e.header:s.fromObject(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"),u=e("../encoding/bufferreader"),a=e("../encoding/bufferwriter"),f=e("../crypto/hash"),h=(e("../util/js"),e("../transaction")),c=e("../util/preconditions");n.fromBuffer=function(e){return n.fromBufferReader(u(e))},n.fromBufferReader=function(e){return new n(n._fromBufferReader(e))},n.prototype.toBuffer=function(){return this.toBufferWriter().concat()},n.prototype.toBufferWriter=function(e){e||(e=new a),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=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 e=this._calcTreeHeight(),t={hashesUsed:0,flagBitsUsed:0},r=this._traverseMerkleTree(e,0,t);return t.hashesUsed===this.hashes.length&&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)),f.sha256sha256(new r.concat([s,o]))}if(n.hashesUsed>=this.hashes.length)return null;var u=this.hashes[n.hashesUsed++];return 0===e&&i&&n.txs.push(u),new r(u,"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){c.checkArgument(!i.isUndefined(e),"tx cannot be undefined"),c.checkArgument(e instanceof h||"string"==typeof e,'Invalid tx given, tx must be a "string" or "Transaction"');var t=e;e instanceof h&&(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){c.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;n<r;n++)t.hashes.push(e.read(32).toString("hex"));var i=e.readVarintNum();for(t.flags=[],n=0;n<i;n++)t.flags.push(e.readUInt8());return t},n.fromObject=function(e){return new n(e)},t.exports=n}).call(this,e("buffer").Buffer)},{"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../transaction":32,"../util/buffer":46,"../util/js":47,"../util/preconditions":48,"./blockheader":3,buffer:118,lodash:192}],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,t){return i.checkArgument(s.isString(e)),new n(e,t)},n.fromBuffer=function(e,t){void 0!==t&&"little"===t.endian&&(e=o(e));var r=e.toString("hex");return new n(r,16)},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 void 0!==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,r){var s=r||4;if(i.checkArgument(e.length<=s,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.gte=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;s<n-t;s++)i[s]=0;return i},t.exports=n}).call(this,e("buffer").Buffer)},{"../util/preconditions":48,"bn.js":67,buffer:118,lodash:192}],7:[function(e,t,r){(function(r){"use strict";var n=e("./bn"),i=e("./point"),s=e("./signature"),o=e("../publickey"),u=e("./random"),a=e("./hash"),f=e("../util/buffer"),h=e("lodash"),c=e("../util/preconditions"),d=function e(t){if(!(this instanceof e))return new e(t);t&&this.set(t)};d.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},d.prototype.privkey2pubkey=function(){this.pubkey=this.privkey.toPublicKey()},d.prototype.calci=function(){for(var e=0;e<4;e++){this.sig.i=e;var t;try{t=this.toPublicKey()}catch(e){console.error(e);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")},d.fromString=function(e){var t=JSON.parse(e);return new d(t)},d.prototype.randomK=function(){var e,t=i.getN();do{e=n.fromBuffer(u.getRandomBuffer(32))}while(!e.lt(t)||!e.gt(n.Zero));return this.k=e,this},d.prototype.deterministicK=function(e){h.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}),u="little"===this.endian?f.reverse(this.hashbuf):this.hashbuf;s=a.sha256hmac(r.concat([t,new r([0]),o,u]),s),t=a.sha256hmac(t,s),s=a.sha256hmac(r.concat([t,new r([1]),o,u]),s),t=a.sha256hmac(t,s),t=a.sha256hmac(t,s);for(var c=n.fromBuffer(t),d=i.getN(),l=0;l<e||!c.lt(d)||!c.gt(n.Zero);l++)s=a.sha256hmac(r.concat([t,new r([0])]),s),t=a.sha256hmac(t,s),t=a.sha256hmac(t,s),c=n.fromBuffer(t);return this.k=c,this},d.prototype.toPublicKey=function(){var e=this.sig.i;c.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,u=1&e,a=e>>1,f=i.getN(),h=i.getG(),d=a?r.add(f):r,l=i.fromX(u,d);if(!l.mul(f).isInfinity())throw new Error("nR is not a valid curve point");var p=t.neg().mod(f),b=r.invm(f),w=l.mul(s).add(h.mul(p)).mul(b);return o.fromPoint(w,this.sig.compressed)},d.prototype.sigError=function(){if(!f.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),u=o.mul(r).mod(s),a=o.mul(e).mod(s),h=i.getG().mulAdd(u,this.pubkey.point,a);return h.isInfinity()?"p is infinity":0!==h.getX().mod(s).cmp(e)&&"Invalid signature"},d.toLowS=function(e){return e.gt(n.fromBuffer(new r("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))&&(e=i.getN().sub(e)),e},d.prototype._findSignature=function(e,t){var r,s,o,u,a=i.getN(),f=i.getG(),h=0;do{(!this.k||h>0)&&this.deterministicK(h),h++,r=this.k,s=f.mul(r),o=s.x.mod(a),u=r.invm(a).mul(t.add(e.mul(o))).mod(a)}while(o.cmp(n.Zero)<=0||u.cmp(n.Zero)<=0);return u=d.toLowS(u),{s:u,r:o}},d.prototype.sign=function(){var e=this.hashbuf,t=this.privkey,r=t.bn;c.checkState(e&&t&&r,new Error("invalid parameters")),c.checkState(f.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},d.prototype.signRandomK=function(){return this.randomK(),this.sign()},d.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)},d.prototype.verify=function(){return this.sigError()?this.verified=!1:this.verified=!0,this},d.sign=function(e,t,r){return d().set({hashbuf:e,endian:r,privkey:t}).sign().sig},d.verify=function(e,t,r,n){return d().set({hashbuf:e,endian:n,sig:t,pubkey:r}).verify().verified},t.exports=d}).call(this,e("buffer").Buffer)},{"../publickey":28,"../util/buffer":46,"../util/preconditions":48,"./bn":6,"./hash":8,"./point":9,"./random":10,"./signature":11,buffer:118,lodash:192}],8:[function(e,t,r){(function(r){"use strict";var n=(e("sha512"),e("x11-hash-js")),i=e("crypto"),s=e("../util/buffer"),o=e("../util/preconditions"),u=t.exports;u.sha1=function(e){return o.checkArgument(s.isBuffer(e)),i.createHash("sha1").update(e).digest()},u.sha1.blocksize=512,u.sha256=function(e){return o.checkArgument(s.isBuffer(e)),i.createHash("sha256").update(e).digest()},u.sha256.blocksize=512,u.sha256sha256=function(e){return o.checkArgument(s.isBuffer(e)),u.sha256(u.sha256(e))},u.x11=function(e){return o.checkArgument(s.isBuffer(e)),new r(n.digest(e,1,2))},u.ripemd160=function(e){return o.checkArgument(s.isBuffer(e)),i.createHash("ripemd160").update(e).digest()},u.sha256ripemd160=function(e){return o.checkArgument(s.isBuffer(e)),u.ripemd160(u.sha256(e))},u.sha512=function(e){return o.checkArgument(s.isBuffer(e)),i.createHash("sha512").update(e).digest()},u.sha512.blocksize=1024,u.hmac=function(e,t,n){o.checkArgument(s.isBuffer(t)),o.checkArgument(s.isBuffer(n)),o.checkArgument(e.blocksize);var i=e.blocksize/8;if(n.length>i)n=e(n);else if(n<i){var u=new r(i);u.fill(0),n.copy(u),n=u}var a=new r(i);a.fill(92);var f=new r(i);f.fill(54);for(var h=new r(i),c=new r(i),d=0;d<i;d++)h[d]=a[d]^n[d],c[d]=f[d]^n[d];return e(r.concat([h,e(r.concat([c,t]))]))},u.sha256hmac=function(e,t){return u.hmac(u.sha256,e,t)},u.sha512hmac=function(e,t){return u.hmac(u.sha512,e,t)}}).call(this,e("buffer").Buffer)},{"../util/buffer":46,"../util/preconditions":48,buffer:118,crypto:144,sha512:250,"x11-hash-js":262}],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),u=s.curve.pointFromX.bind(s.curve),a=function(e,t,r){var n=o(e,t,r);return n.validate(),n};a.prototype=Object.getPrototypeOf(s.curve.point()),a.fromX=function(e,t){var r=u(e,t);return r.validate(),r},a.getG=function(){return s.curve.g},a.getN=function(){return new n(s.curve.n.toArray())},a.prototype._getX=a.prototype.getX,a.prototype.getX=function(){return new n(this._getX().toArray())},a.prototype._getY=a.prototype.getY,a.prototype.getY=function(){return new n(this._getY().toArray())},a.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.");if(0!==u(this.getY().isOdd(),this.getX()).y.cmp(this.y))throw new Error("Invalid y value for curve.");var e=this.getX().gt(n.Minus1)&&this.getX().lt(a.getN()),t=this.getY().gt(n.Minus1)&&this.getY().lt(a.getN());if(!e||!t)throw new Error("Point does not lie on the curve");if(!this.mul(a.getN()).isInfinity())throw new Error("Point times N must be infinity");return this},a.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=a}).call(this,e("buffer").Buffer)},{"../util/buffer":46,"./bn":6,buffer:118,elliptic:156}],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){return e("crypto").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);return t.getRandomValues(r),new n(r)},i.getPseudoRandomBuffer=function(e){for(var t,r=new n(e),i=0;i<=e;i++){0===i-4*Math.floor(i/4)?(t=4294967296*Math.random(),r[i]=255&t):r[i]=255&(t>>>=8)}return r},t.exports=i}).call(this,e("_process"),e("buffer").Buffer)},{_process:210,buffer:118,crypto:144}],11:[function(e,t,r){(function(r){"use strict";var n=e("./bn"),i=e("lodash"),s=e("../util/preconditions"),o=e("../util/buffer"),u=e("../util/js"),a=function e(t,r){if(!(this instanceof e))return new e(t,r);if(t instanceof n)this.set({r:t,s:r});else if(t){var i=t;this.set(i)}};a.prototype.set=function(e){return this.r=e.r||this.r||void 0,this.s=e.s||this.s||void 0,this.i=void 0!==e.i?e.i:this.i,this.compressed=void 0!==e.compressed?e.compressed:this.compressed,this.nhashtype=e.nhashtype||this.nhashtype||void 0,this},a.fromCompact=function(e){s.checkArgument(o.isBuffer(e),"Argument is expected to be a Buffer");var t=new a,r=!0,i=e.slice(0,1)[0]-27-4;i<0&&(r=!1,i+=4);var u=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===u.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(u),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 u=e[1],a=e.slice(2).length;s.checkArgument(!t||u===a,new Error("Length byte should length of what follows")),u=u<a?u:a;var f=e[2];s.checkArgument(2===f,new Error("Integer byte for r should be 0x02"));var h=e[3],c=e.slice(4,4+h),d=n.fromBuffer(c),l=0===e[4];s.checkArgument(h===c.length,new Error("Length of r incorrect"));var p=e[4+h+0];s.checkArgument(2===p,new Error("Integer byte for s should be 0x02"));var b=e[4+h+1],w=e.slice(4+h+2,4+h+2+b),g=n.fromBuffer(w),y=0===e[4+h+2+2];s.checkArgument(b===w.length,new Error("Length of s incorrect"));var v=4+h+2+b;return s.checkArgument(u===v-2,new Error("Length of signature incorrect")),{header:r,length:u,rheader:f,rlength:h,rneg:l,rbuf:c,r:d,sheader:p,slength:b,sneg:y,sbuf:w,s:g}},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;!1===t&&(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]),i=!!(128&t[0]),s=n?r.concat([new r([0]),e]):e,o=i?r.concat([new r([0]),t]):t,u=s.length,a=o.length,f=2+u+2+a;return r.concat([new r([48,f,2,u]),s,new r([2,a]),o])},a.prototype.toString=function(){return this.toDER().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]&&(0!==r&&(!(128&i[0])&&!(r>1&&0===i[0]&&!(128&i[1]))))},a.prototype.hasLowS=function(){return!this.s.lt(new n(1))&&!this.s.gt(new n("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex"))},a.prototype.hasDefinedHashtype=function(){if(!u.isNaturalNumber(this.nhashtype))return!1;var e=this.nhashtype&~a.SIGHASH_ANYONECANPAY;return!(e<a.SIGHASH_ALL||e>a.SIGHASH_SINGLE)},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":46,"../util/js":47,"../util/preconditions":48,"./bn":6,buffer:118,lodash:192}],12:[function(e,t,r){(function(r){"use strict";var n=e("lodash"),i=e("bs58"),s=e("buffer"),o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split(""),u=function e(t){if(!(this instanceof e))return new e(t);if(r.isBuffer(t)){var n=t;this.fromBuffer(n)}else if("string"==typeof t){var i=t;this.fromString(i)}else t&&this.set(t)};u.validCharacters=function(e){return s.Buffer.isBuffer(e)&&(e=e.toString()),n.every(n.map(e,function(e){return n.includes(o,e)}))},u.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this},u.encode=function(e){if(!s.Buffer.isBuffer(e))throw new Error("Input should be a buffer");return i.encode(e)},u.decode=function(e){if("string"!=typeof e)throw new Error("Input should be a string");return new r(i.decode(e))},u.prototype.fromBuffer=function(e){return this.buf=e,this}, u.prototype.fromString=function(e){var t=u.decode(e);return this.buf=t,this},u.prototype.toBuffer=function(){return this.buf},u.prototype.toString=function(){return u.encode(this.buf)},t.exports=u}).call(this,e("buffer").Buffer)},{bs58:115,buffer:118,lodash:192}],13:[function(e,t,r){(function(r){"use strict";var n=e("lodash"),i=e("./base58"),s=e("buffer"),o=e("../crypto/hash").sha256sha256,u=function e(t){if(!(this instanceof e))return new e(t);if(r.isBuffer(t)){var n=t;this.fromBuffer(n)}else if("string"==typeof t){var i=t;this.fromString(i)}else t&&this.set(t)};u.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this},u.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)),u.checksum(e).toString("hex")===t.toString("hex")},u.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),u=o(n),a=u.slice(0,4);if(s.toString("hex")!==a.toString("hex"))throw new Error("Checksum mismatch");return n},u.checksum=function(e){return o(e).slice(0,4)},u.encode=function(e){if(!r.isBuffer(e))throw new Error("Input must be a buffer");var t=new r(e.length+4),n=u.checksum(e);return e.copy(t),n.copy(t,e.length),i.encode(t)},u.prototype.fromBuffer=function(e){return this.buf=e,this},u.prototype.fromString=function(e){var t=u.decode(e);return this.buf=t,this},u.prototype.toBuffer=function(){return this.buf},u.prototype.toString=function(){return u.encode(this.buf)},t.exports=u}).call(this,e("buffer").Buffer)},{"../crypto/hash":8,"./base58":12,buffer:118,lodash:192}],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"),u=function e(t){if(!(this instanceof e))return new e(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 i=t;this.set(i)}};u.prototype.set=function(e){return this.buf=e.buf||this.buf||void 0,this.pos=e.pos||this.pos||0,this},u.prototype.eof=function(){return this.pos>=this.buf.length},u.prototype.finished=u.prototype.eof,u.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},u.prototype.readAll=function(){var e=this.buf.slice(this.pos,this.buf.length);return this.pos=this.buf.length,e},u.prototype.readUInt8=function(){var e=this.buf.readUInt8(this.pos);return this.pos=this.pos+1,e},u.prototype.readUInt16BE=function(){var e=this.buf.readUInt16BE(this.pos);return this.pos=this.pos+2,e},u.prototype.readUInt16LE=function(){var e=this.buf.readUInt16LE(this.pos);return this.pos=this.pos+2,e},u.prototype.readUInt32BE=function(){var e=this.buf.readUInt32BE(this.pos);return this.pos=this.pos+4,e},u.prototype.readUInt32LE=function(){var e=this.buf.readUInt32LE(this.pos);return this.pos=this.pos+4,e},u.prototype.readInt32LE=function(){var e=this.buf.readInt32LE(this.pos);return this.pos=this.pos+4,e},u.prototype.readUInt64BEBN=function(){var e=this.buf.slice(this.pos,this.pos+8),t=o.fromBuffer(e);return this.pos=this.pos+8,t},u.prototype.readUInt64LEBN=function(){var e,t=this.buf.readUInt32LE(this.pos),r=this.buf.readUInt32LE(this.pos+4),n=4294967296*r+t;if(n<=9007199254740991)e=new o(n);else{var i=Array.prototype.slice.call(this.buf,this.pos,this.pos+8);e=new o(i,10,"le")}return this.pos=this.pos+8,e},u.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}},u.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},u.prototype.readVarintBuf=function(){switch(this.buf.readUInt8(this.pos)){case 253:return this.read(3);case 254:return this.read(5);case 255:return this.read(9);default:return this.read(1)}},u.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)}},u.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},u.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=u}).call(this,e("buffer").Buffer)},{"../crypto/bn":6,"../util/buffer":46,"../util/preconditions":48,buffer:118,lodash:192}],15:[function(e,t,r){(function(r){"use strict";var n=e("../util/buffer"),i=e("assert"),s=function e(t){if(!(this instanceof e))return new e(t);t?this.set(t):this.bufs=[]};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});return this.writeReverse(t),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 e<253?(t=new r(1),t.writeUInt8(e,0)):e<65536?(t=new r(3),t.writeUInt8(253,0),t.writeUInt16LE(e,1)):e<4294967296?(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(n<253)t=new r(1),t.writeUInt8(n,0);else if(n<65536)t=new r(3),t.writeUInt8(253,0),t.writeUInt16LE(n,1);else if(n<4294967296)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":46,assert:64,buffer:118}],16:[function(e,t,r){(function(r){"use strict";var n=e("./bufferwriter"),i=e("./bufferreader"),s=e("../crypto/bn"),o=function e(t){if(!(this instanceof e))return new e(t);if(r.isBuffer(t))this.buf=t;else if("number"==typeof t){var n=t;this.fromNumber(n)}else if(t instanceof s){var i=t;this.fromBN(i)}else if(t){var o=t;this.set(o)}};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:118}],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)})},u={};u.Error=function(){this.message="Internal error",this.stack=this.message+"\n"+(new Error).stack},u.Error.prototype=Object.create(Error.prototype),u.Error.prototype.name="bitcore.Error";var a=e("./spec");!function(e,t){o(e,t)}(u.Error,a),t.exports=u.Error,t.exports.extend=function(e){return s(u.Error,e)}},{"./spec":18,lodash:192}],18:[function(e,t,r){"use strict";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: http://bitcore.io/"+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:"GovObject",message:"Internal Error on GovObject {0}",errors:[{name:"Proposal",message:"Internal Error on Proposal {0}",errors:[{name:"invalidDate",message:"Invalid Date"},{name:"invalidDateWindow",message:"Invalid Timespan"},{name:"invalidAddress",message:"Invalid Address"},{name:"invalidP2SHAddress",message:"Invalid P2SHAddress"},{name:"invalidPayment",message:"Invalid Payment Amount"},{name:"invalidUrl",message:"Invalid URL"},{name:"invalidName",message:"Invalid Name"}]}]},{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(e,t,r){(function(r){"use strict";function n(e){if(e){if(e instanceof n)return n.shallowCopy(e);if(f.isHexa(e))return this.fromString(e);if(a.isBuffer(e))return this.fromBuffer(e);if(i.isObject(e))return this.fromObject(e);throw new u.InvalidArgument("Must provide an object or string to deserialize a transaction")}this._newGovObject()}var i=e("lodash"),s=e("../util/preconditions"),o=e("buffer"),u=(r.compare||e("buffer-compare"),e("../errors")),a=e("../util/buffer"),f=e("../util/js"),h=e("../encoding/bufferreader"),c=e("../encoding/bufferwriter"),d=e("../address");n.prototype.dataHex=function(){return null},n.prototype._newGovObject=function(){return null},n.prototype.fromObject=function(e){var t;if(!(i.isObject(e)||e instanceof n)){try{var r=JSON.parse(e)}catch(e){throw new Error("Must be a valid stringified JSON")}return this.fromObject(r)}var s=[["type","number"]];switch(t=e,i.each(s,function(e){var r=e[0],n=e[1];if(!t.hasOwnProperty(r))throw new Error("Must be a valid JSON - Property "+r+" missing");var i=typeof t[r];if(i!==n){var s="Must be a valid JSON - Expected property "+r+" to be a "+n+" received:"+i;throw new Error(s)}}),t.type){case 1:var o=new n.Proposal;return o=o.fromObject(t);default:throw new Error("Unhandled GovObject type")}},n.prototype.fromString=function(e){return this.fromBuffer(new o.Buffer(e,"hex"))},n.prototype.checkedSerialize=function(e){var t=this.getSerializationError(e);if(t)throw t;return this.uncheckedSerialize()},n.prototype.serialize=function(e){return!0===e||e&&e.disableAll?this.uncheckedSerialize():this.checkedSerialize(e)},n.prototype.uncheckedSerialize=n.prototype.toString=function(){return this.toBuffer().toString("hex")},n.prototype.inspect=function(){return"<GovObject: "+this.uncheckedSerialize()+">"},n.prototype.toBuffer=function(){var e=new c;return this.toBufferWriter(e).toBuffer()},n.prototype.toBufferWriter=function(e){return e.write(new r(this.dataHex())),e},n.prototype.fromBuffer=function(e){var t=new h(e);return this.fromBufferReader(t)},n.prototype.fromBufferReader=function(e){s.checkArgument(!e.finished(),"No data received");var t=e.read(e.buf.length),r=JSON.parse(t.toString("utf8")),n=r[0][1];return this.fromObject(n)},n.prototype._verifyDateFormat=function(e){return new Date(1e3*e)},n.prototype._verifyPayment=function(e){var t=parseFloat(e);return!!isNaN(t)||Boolean(t<=0)},n.prototype._verifyAddress=function(e,t){return d.isValid(e,t)},n.prototype._verifyPayToScriptHash=function(e,t){return new d(e,t).isPayToScriptHash()},n.prototype._verifyUrl=function(e){return/^(http|https):\/\/[^ "]{1,255}$/.test(e)},n.prototype._verifyName=function(e){return/^[-_a-zA-Z0-9]{1,40}$/.test(e)},n.shallowCopy=function(e){return new n(e.toBuffer())},t.exports=n}).call(this,e("buffer").Buffer)},{"../address":1,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../errors":17,"../util/buffer":46,"../util/js":47,"../util/preconditions":48,buffer:118,"buffer-compare":116,lodash:192}],20:[function(e,t,r){t.exports=e("./govobject"),t.exports.Proposal=e("./types/proposal")},{"./govobject":19,"./types/proposal":21}],21:[function(e,t,r){"use strict";function n(e){o.call(this,e)}var i=e("lodash"),s=e("../../util/preconditions"),o=e("../govobject"),u=e("../../errors");(0,e("util").inherits)(n,o),n.prototype.dataHex=function(){var e={end_epoch:this.end_epoch,name:this.name,payment_address:this.payment_address,payment_amount:this.payment_amount,start_epoch:this.start_epoch,type:this.type,url:this.url},t=["proposal",e],r=[t];return JSON.stringify(r)},n.prototype._newGovObject=function(){this.end_epoch="",this.name="",this.payment_address="",this.payment_amount="",this.start_epoch="",this.type="",this.url=""},n.prototype.fromObject=function(e){if(!(i.isObject(e)||e instanceof o)){try{var t=JSON.parse(e)}