UNPKG

bitcore-lib-excc

Version:

A pure and powerful JavaScript Bitcoin library.

2 lines 608 kB
require=function t(e,r,n){function i(o,f){if(!r[o]){if(!e[o]){var a="function"==typeof require&&require;if(!f&&a)return a(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var c=r[o]={exports:{}};e[o][0].call(c.exports,function(t){var r=e[o][1][t];return i(r?r:t)},c,c.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&&!a.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||a.get(e)||a.defaultNetwork,o.type=o.type||r||n.PayToPublicKeyHash,c.defineImmutable(this,{hashBuffer:o.hashBuffer,network:o.network,type:o.type}),this}var i=t("lodash"),s=t("./util/preconditions"),o=t("./errors"),f=t("./encoding/base58check"),a=t("./networks"),u=t("./crypto/hash"),c=t("./util/js"),h=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 h)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:a.get(t.network)||a.defaultNetwork,type:t.type}},n._classifyFromVersion=function(t){var e={},r=a.get(t[0],"pubkeyhash"),i=a.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=a.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 h))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||a.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=f.decode(t),s=n._transformBuffer(i,e,r);return s},n.fromPublicKey=function(t,e){var r=n._transformPublicKey(t);return e=e||a.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(c.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 f.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":21,"./publickey":24,"./script":25,"./util/js":43,"./util/preconditions":44,buffer:47,lodash:298}],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"),f=t("../util/buffer"),a=t("../encoding/bufferreader"),u=t("../encoding/bufferwriter"),c=t("../crypto/hash"),h=t("../transaction"),d=t("../util/preconditions");n.MAX_BLOCK_SIZE=1e6,n._from=function(t){var e={};if(f.isBuffer(t))e=n._fromBufferReader(a(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 h?e.push(t):e.push(h().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;n<r;n++)e.transactions.push(h().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 a(t))},n.fromString=function(t){var e=new r(t,"hex");return n.fromBuffer(e)},n.fromRawBlock=function(t){f.isBuffer(t)||(t=new r(t,"binary"));var e=a(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;i<n;i+=2){var s=Math.min(i+1,n-1),o=r.concat([t[e+i],t[e+s]]);t.push(c.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":28,"../util/buffer":42,"../util/preconditions":44,"./blockheader":3,buffer:47,lodash:298}],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"),f=t("../encoding/bufferwriter"),a=t("../crypto/hash"),u=(t("../util/js"),t("../util/preconditions")),c=486604799,h=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};h._from=function(t){var e={};if(s.isBuffer(t))e=h._fromBufferReader(o(t));else{if(!n.isObject(t))throw new TypeError("Unrecognized argument for BlockHeader");e=h._fromObject(t)}return e},h._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},h.fromObject=function(t){var e=h._fromObject(t);return new h(e)},h.fromRawBlock=function(t){s.isBuffer(t)||(t=new r(t,"binary"));var e=o(t);e.pos=h.Constants.START_OF_HEADER;var n=h._fromBufferReader(e);return new h(n)},h.fromBuffer=function(t){var e=h._fromBufferReader(o(t));return new h(e)},h.fromString=function(t){var e=new r(t,"hex");return h.fromBuffer(e)},h._fromBufferReader=function(t){var e={};return e.version=t.readInt32LE(),e.prevHash=t.read(32),e.merkleRoot=t.read(32),e.time=t.readUInt32LE(),e.bits=t.readUInt32LE(),e.nonce=t.readUInt32LE(),e},h.fromBufferReader=function(t){var e=h._fromBufferReader(t);return new h(e)},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(t){return t||(t=new f),t.writeInt32LE(this.version),t.write(this.prevHash),t.write(this.merkleRoot),t.writeUInt32LE(this.time),t.writeUInt32LE(this.bits),t.writeUInt32LE(this.nonce),t},h.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},h.prototype.getDifficulty=function(){var t=this.getTargetDifficulty(c).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)},h.prototype._getHash=function(){var t=this.toBuffer();return a.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(h.prototype,"id",d),Object.defineProperty(h.prototype,"hash",d),h.prototype.validTimestamp=function(){var t=Math.round((new Date).getTime()/1e3);return!(this.time>t+h.Constants.MAX_TIME_OFFSET)},h.prototype.validProofOfWork=function(){var t=new i(this.id,"hex"),e=this.getTargetDifficulty();return!(t.cmp(e)>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")},e.exports=h}).call(this,t("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../encoding/bufferreader":14,"../encoding/bufferwriter":15,"../util/buffer":42,"../util/js":43,"../util/preconditions":44,buffer:47,lodash:298}],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(f(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"),f=t("../encoding/bufferreader"),a=t("../encoding/bufferwriter"),u=t("../crypto/hash"),c=(t("../util/js"),t("../transaction")),h=t("../util/preconditions");n.fromBuffer=function(t){return n.fromBufferReader(f(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 a),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(h.checkState(i.isArray(this.flags),"MerkleBlock flags is not an array"),h.checkState(i.isArray(this.hashes),"MerkleBlock hashes is not an array"),this.hashes.length>this.numTransactions)return!1;if(8*this.flags.length<this.hashes.length)return!1;var t=this._calcTreeHeight(),e={hashesUsed:0,flagBitsUsed:0},r=this._traverseMerkleTree(t,0,e);return e.hashesUsed===this.hashes.length&&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 f=this.hashes[n.hashesUsed++];return 0===t&&i&&n.txs.push(f),new r(f,"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){h.checkArgument(!i.isUndefined(t),"tx cannot be undefined"),h.checkArgument(t instanceof c||"string"==typeof t,'Invalid tx given, tx must be a "string" or "Transaction"');var e=t;t instanceof c&&(e=o.reverse(new r(t.id,"hex")).toString("hex"));var n=[],s=this._calcTreeHeight();return this._traverseMerkleTree(s,0,{txs:n}),n.indexOf(e)!==-1},n._fromBufferReader=function(t){h.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;n<r;n++)e.hashes.push(t.read(32).toString("hex"));var i=t.readVarintNum();for(e.flags=[],n=0;n<i;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":28,"../util/buffer":42,"../util/js":43,"../util/preconditions":44,"./blockheader":3,buffer:47,lodash:298}],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 this.cmp(n.Zero)===-1?(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;s<n-e;s++)i[s]=0;return i},e.exports=n}).call(this,t("buffer").Buffer)},{"../util/preconditions":44,"bn.js":273,buffer:47,lodash:298}],7:[function(t,e,r){(function(r){"use strict";var n=t("./bn"),i=t("./point"),s=t("./signature"),o=t("../publickey"),f=t("./random"),a=t("./hash"),u=t("../util/buffer"),c=t("lodash"),h=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;t<4;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(f.getRandomBuffer(32));while(!t.lt(e)||!t.gt(n.Zero));return this.k=t,this},d.prototype.deterministicK=function(t){c.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}),f="little"===this.endian?u.reverse(this.hashbuf):this.hashbuf;s=a.sha256hmac(r.concat([e,new r([0]),o,f]),s),e=a.sha256hmac(e,s),s=a.sha256hmac(r.concat([e,new r([1]),o,f]),s),e=a.sha256hmac(e,s),e=a.sha256hmac(e,s);for(var h=n.fromBuffer(e),d=i.getN(),p=0;p<t||!h.lt(d)||!h.gt(n.Zero);p++)s=a.sha256hmac(r.concat([e,new r([0])]),s),e=a.sha256hmac(e,s),e=a.sha256hmac(e,s),h=n.fromBuffer(e);return this.k=h,this},d.prototype.toPublicKey=function(){var t=this.sig.i;h.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,f=1&t,a=t>>1,u=i.getN(),c=i.getG(),d=a?r.add(u):r,p=i.fromX(f,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),y=p.mul(s).add(c.mul(b)).mul(g),m=o.fromPoint(y,this.sig.compressed);return m},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),f=o.mul(r).mod(s),a=o.mul(t).mod(s),c=i.getG().mulAdd(f,this.pubkey.point,a);return c.isInfinity()?"p is infinity":0!==c.getX().mod(s).cmp(t)&&"Invalid signature"},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,f,a=i.getN(),u=i.getG(),c=0;do(!this.k||c>0)&&this.deterministicK(c),c++,r=this.k,s=u.mul(r),o=s.x.mod(a),f=r.invm(a).mul(e.add(t.mul(o))).mod(a);while(o.cmp(n.Zero)<=0||f.cmp(n.Zero)<=0);return f=d.toLowS(f),{s:f,r:o}},d.prototype.sign=function(){var t=this.hashbuf,e=this.privkey,r=e.bn;h.checkState(t&&e&&r,new Error("invalid parameters")),h.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":24,"../util/buffer":42,"../util/preconditions":44,"./bn":6,"./hash":8,"./point":9,"./random":10,"./signature":11,buffer:47,lodash:298}],8:[function(t,e,r){(function(r){"use strict";var n=t("crypto"),i=t("../util/buffer"),s=t("../util/preconditions"),o=e.exports;o.sha1=function(t){return s.checkArgument(i.isBuffer(t)),n.createHash("sha1").update(t).digest()},o.sha1.blocksize=512,o.sha256=function(t){return s.checkArgument(i.isBuffer(t)),n.createHash("sha256").update(t).digest()},o.sha256.blocksize=512,o.sha256sha256=function(t){return s.checkArgument(i.isBuffer(t)),o.sha256(o.sha256(t))},o.ripemd160=function(t){return s.checkArgument(i.isBuffer(t)),n.createHash("ripemd160").update(t).digest()},o.sha256ripemd160=function(t){return s.checkArgument(i.isBuffer(t)),o.ripemd160(o.sha256(t))},o.sha512=function(t){return s.checkArgument(i.isBuffer(t)),n.createHash("sha512").update(t).digest()},o.sha512.blocksize=1024,o.hmac=function(t,e,n){s.checkArgument(i.isBuffer(e)),s.checkArgument(i.isBuffer(n)),s.checkArgument(t.blocksize);var o=t.blocksize/8;if(n.length>o)n=t(n);else if(n<o){var f=new r(o);f.fill(0),n.copy(f),n=f}var a=new r(o);a.fill(92);var u=new r(o);u.fill(54);for(var c=new r(o),h=new r(o),d=0;d<o;d++)c[d]=a[d]^n[d],h[d]=u[d]^n[d];return t(r.concat([c,t(r.concat([h,e]))]))},o.sha256hmac=function(t,e){return o.hmac(o.sha256,t,e)},o.sha512hmac=function(t,e){return o.hmac(o.sha512,t,e)}}).call(this,t("buffer").Buffer)},{"../util/buffer":42,"../util/preconditions":44,buffer:47,crypto:51}],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),f=s.curve.pointFromX.bind(s.curve),a=function(t,e,r){var n=o(t,e,r);return n.validate(),n};a.prototype=Object.getPrototypeOf(s.curve.point()),a.fromX=function(t,e){var r=f(t,e);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.");var t=f(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(a.getN()),r=this.getY().gt(n.Minus1)&&this.getY().lt(a.getN());if(!e||!r)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(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=a}).call(this,t("buffer").Buffer)},{"../util/buffer":42,"./bn":6,buffer:47,elliptic:276}],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;s<=t;s++){var o=Math.floor(s/4),f=s-4*o;0===f?(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:245,buffer:47,crypto:51}],11:[function(t,e,r){(function(r){"use strict";var n=t("./bn"),i=t("lodash"),s=t("../util/preconditions"),o=t("../util/buffer"),f=t("../util/js"),a=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)}};a.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},a.fromCompact=function(t){s.checkArgument(o.isBuffer(t),"Argument is expected to be a Buffer");var e=new a,r=!0,i=t.slice(0,1)[0]-27-4;i<0&&(r=!1,i+=4);var f=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===f.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(f),e.s=n.fromBuffer(u),e},a.fromDER=a.fromBuffer=function(t,e){var r=a.parseDER(t,e),n=new a;return n.r=r.r,n.s=r.s,n},a.fromTxFormat=function(t){var e=t.readUInt8(t.length-1),r=t.slice(0,t.length-1),n=new a.fromDER(r,(!1));return n.nhashtype=e,n},a.fromString=function(t){var e=new r(t,"hex");return a.fromDER(e)},a.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 f=t[1],a=t.slice(2).length;s.checkArgument(!e||f===a,new Error("Length byte should length of what follows")),f=f<a?f:a;var u=t[2];s.checkArgument(2===u,new Error("Integer byte for r should be 0x02"));var c=t[3],h=t.slice(4,4+c),d=n.fromBuffer(h),p=0===t[4];s.checkArgument(c===h.length,new Error("Length of r incorrect"));var l=t[4+c+0];s.checkArgument(2===l,new Error("Integer byte for s should be 0x02"));var b=t[4+c+1],g=t.slice(4+c+2,4+c+2+b),y=n.fromBuffer(g),m=0===t[4+c+2+2];s.checkArgument(b===g.length,new Error("Length of s incorrect"));var v=4+c+2+b;s.checkArgument(f===v-2,new Error("Length of signature incorrect"));var _={header:r,length:f,rheader:u,rlength:c,rneg:p,rbuf:h,r:d,sheader:l,slength:b,sneg:m,sbuf:g,s:y};return _},a.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])},a.prototype.toBuffer=a.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,f=s.length,a=o.length,u=2+f+2+a,c=2,h=2,d=48,p=r.concat([new r([d,u,c,f]),s,new r([h,a]),o]);return p},a.prototype.toString=function(){var t=this.toDER();return t.toString("hex")},a.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]&&(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(!f.isNaturalNumber(this.nhashtype))return!1;var t=this.nhashtype&~a.SIGHASH_ANYONECANPAY;return!(t<a.SIGHASH_ALL||t>a.SIGHASH_SINGLE)},a.prototype.toTxFormat=function(){var t=this.toDER(),e=new r(1);return e.writeUInt8(this.nhashtype,0),r.concat([t,e])},a.SIGHASH_ALL=1,a.SIGHASH_NONE=2,a.SIGHASH_SINGLE=3,a.SIGHASH_ANYONECANPAY=128,e.exports=a}).call(this,t("buffer").Buffer)},{"../util/buffer":42,"../util/js":43,"../util/preconditions":44,"./bn":6,buffer:47,lodash:298}],12:[function(t,e,r){(function(r){"use strict";var n=t("lodash"),i=t("bs58"),s=t("buffer"),o="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split(""),f=function a(t){if(!(this instanceof a))return new a(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)};f.validCharacters=function(t){return s.Buffer.isBuffer(t)&&(t=t.toString()),n.all(n.map(t,function(t){return n.contains(o,t)}))},f.prototype.set=function(t){return this.buf=t.buf||this.buf||void 0,this},f.encode=function(t){if(!s.Buffer.isBuffer(t))throw new Error("Input should be a buffer");return i.encode(t)},f.decode=function(t){if("string"!=typeof t)throw new Error("Input should be a string");return new r(i.decode(t))},f.prototype.fromBuffer=function(t){ return this.buf=t,this},f.prototype.fromString=function(t){var e=f.decode(t);return this.buf=e,this},f.prototype.toBuffer=function(){return this.buf},f.prototype.toString=function(){return f.encode(this.buf)},e.exports=f}).call(this,t("buffer").Buffer)},{bs58:274,buffer:47,lodash:298}],13:[function(t,e,r){(function(r){"use strict";var n=t("lodash"),i=t("./base58"),s=t("buffer"),o=t("../crypto/hash").sha256sha256,f=function a(t){if(!(this instanceof a))return new a(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)};f.prototype.set=function(t){return this.buf=t.buf||this.buf||void 0,this},f.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)),f.checksum(t).toString("hex")===e.toString("hex")},f.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),f=o(n),a=f.slice(0,4);if(s.toString("hex")!==a.toString("hex"))throw new Error("Checksum mismatch");return n},f.checksum=function(t){return o(t).slice(0,4)},f.encode=function(t){if(!r.isBuffer(t))throw new Error("Input must be a buffer");var e=new r(t.length+4),n=f.checksum(t);return t.copy(e),n.copy(e,t.length),i.encode(e)},f.prototype.fromBuffer=function(t){return this.buf=t,this},f.prototype.fromString=function(t){var e=f.decode(t);return this.buf=e,this},f.prototype.toBuffer=function(){return this.buf},f.prototype.toString=function(){return f.encode(this.buf)},e.exports=f}).call(this,t("buffer").Buffer)},{"../crypto/hash":8,"./base58":12,buffer:47,lodash:298}],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"),f=function a(t){if(!(this instanceof a))return new a(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)}};f.prototype.set=function(t){return this.buf=t.buf||this.buf||void 0,this.pos=t.pos||this.pos||0,this},f.prototype.eof=function(){return this.pos>=this.buf.length},f.prototype.finished=f.prototype.eof,f.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},f.prototype.readAll=function(){var t=this.buf.slice(this.pos,this.buf.length);return this.pos=this.buf.length,t},f.prototype.readUInt8=function(){var t=this.buf.readUInt8(this.pos);return this.pos=this.pos+1,t},f.prototype.readUInt16BE=function(){var t=this.buf.readUInt16BE(this.pos);return this.pos=this.pos+2,t},f.prototype.readUInt16LE=function(){var t=this.buf.readUInt16LE(this.pos);return this.pos=this.pos+2,t},f.prototype.readUInt32BE=function(){var t=this.buf.readUInt32BE(this.pos);return this.pos=this.pos+4,t},f.prototype.readUInt32LE=function(){var t=this.buf.readUInt32LE(this.pos);return this.pos=this.pos+4,t},f.prototype.readInt32LE=function(){var t=this.buf.readInt32LE(this.pos);return this.pos=this.pos+4,t},f.prototype.readUInt64BEBN=function(){var t=this.buf.slice(this.pos,this.pos+8),e=o.fromBuffer(t);return this.pos=this.pos+8,e},f.prototype.readUInt64LEBN=function(){var t,e=this.buf.readUInt32LE(this.pos),r=this.buf.readUInt32LE(this.pos+4),n=4294967296*r+e;if(n<=9007199254740991)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},f.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}},f.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},f.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)}},f.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)}},f.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},f.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=f}).call(this,t("buffer").Buffer)},{"../crypto/bn":6,"../util/buffer":42,"../util/preconditions":44,buffer:47,lodash:298}],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 t<253?(e=new r(1),e.writeUInt8(t,0)):t<65536?(e=new r(3),e.writeUInt8(253,0),e.writeUInt16LE(t,1)):t<4294967296?(e=new r(5),e.writeUInt8(254,0),e.writeUInt32LE(t,1)):(e=new r(9),e.writeUInt8(255,0),e.writeInt32LE(t&-1,1),e.writeUInt32LE(Math.floor(t/4294967296),5)),e},s.varintBufBN=function(t){var e=void 0,n=t.toNumber();if(n<253)e=new r(1),e.writeUInt8(n,0);else if(n<65536)e=new r(3),e.writeUInt8(253,0),e.writeUInt16LE(n,1);else if(n<4294967296)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":42,assert:45,buffer:47}],16:[function(t,e,r){(function(r){"use strict";var n=t("./bufferwriter"),i=t("./bufferreader"),s=t("../crypto/bn"),o=function f(t){if(!(this instanceof f))return new f(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:47}],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)})},f=function(t,e){return o(t,e),t},a={};a.Error=function(){this.message="Internal error",this.stack=this.message+"\n"+(new Error).stack},a.Error.prototype=Object.create(Error.prototype),a.Error.prototype.name="bitcore.Error";var u=t("./spec");f(a.Error,u),e.exports=a.Error,e.exports.extend=function(t){return s(a.Error,t)}},{"./spec":18,lodash:298}],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){(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(v.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"),f=t("./util/preconditions"),a=t("./crypto/bn"),u=t("./encoding/base58"),c=t("./encoding/base58check"),h=t("./crypto/hash"),d=t("./networks"),p=t("./crypto/point"),l=t("./privatekey"),b=t("./crypto/random"),g=t("./errors"),y=g.HDPrivateKey,m=t("./util/buffer"),v=t("./util/js"),_=128,w=1/8,S=512;n.isValidPath=function(t,e){if(o.isString(t)){var r=n._getDerivationIndexes(t);return null!==r&&o.all(r,n.isValidPath)}return!!o.isNumber(t)&&(t<n.Hardened&&e===!0&&(t+=n.Hardened),t>=0&&t<n.MaxIndex)},n._getDerivationIndexes=function(t){var e=t.split("/");if(o.contains(n.RootElementAlias,t))return[];if(!o.contains(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.any(r,isNaN)?null:r},n.prototype.derive=function(t,e){return this.deriveNonCompliantChild(t,e)},n.prototype.deriveChild=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.deriveNonCompliantChild=function(t,e){if(o.isNumber(t))return this._deriveWithNumber(t,e,!0);if(o.isString(t))return this._deriveFromString(t,!0);throw new y.InvalidDerivationArgument(t)},n.prototype._deriveWithNumber=function(t,e,r){if(!n.isValidPath(t,e))throw new y.InvalidPath(t);e=t>=n.Hardened||e,t<n.Hardened&&e===!0&&(t+=n.Hardened);var o,f=m.integerAsBuffer(t);if(e&&r){var u=this.privateKey.bn.toBuffer();o=m.concat([new s.Buffer([0]),u,f])}else if(e){var c=this.privateKey.bn.toBuffer({size:32});i(32===c.length,"length of private key buffer is expected to be 32 bytes"),o=m.concat([new s.Buffer([0]),c,f])}else o=m.concat([this.publicKey.toBuffer(),f]);var d=h.sha512hmac(o,this._buffers.chainCode),b=a.fromBuffer(d.slice(0,32),{size:32}),g=d.slice(32,64),v=b.add(this.privateKey.toBigNumber()).mod(p.getN()).toBuffer({size:32});if(!l.isValid(v))return this._deriveWithNumber(t+1,null,r);var _=new n({network:this.network,depth:this.depth+1,parentFingerPrint:this.fingerPrint,childIndex:t,chainCode:g,privateKey:v});return _},n.prototype._deriveFromString=function(t,e){if(!n.isValidPath(t))throw new y.InvalidPath(t);var r=n._getDerivationIndexes(t),i=r.reduce(function(t,r){return t._deriveWithNumber(r,null,e)},this);return i},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 g.InvalidB58Char("(unknown)",t);try{t=c.decode(t)}catch(r){return new g.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 g.InvalidNetworkArgument(e);var n=t.slice(0,4);return m.integerFromBuffer(n)!==r.xprivkey?new g.InvalidNetwork(n):null},n.fromString=function(t){return f.checkArgument(o.isString(t),"No valid string was provided"),new n(t)},n.fromObject=function(t){return f.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.integerAsSingleByteBuffer(t.depth):t.depth,parentFingerPrint:o.isNumber(t.parentFingerPrint)?m.integerAsBuffer(t.parentFingerPrint):t.parentFingerPrint,childIndex:o.isNumber(t