diff --git a/www/assets/js/bitcore-lib-doge.min.js b/www/assets/js/bitcore-lib-doge.min.js deleted file mode 100644 index d4f3ea5..0000000 --- a/www/assets/js/bitcore-lib-doge.min.js +++ /dev/null @@ -1 +0,0 @@ -require=function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i"};module.exports=Address;var Script=require("./script")}).call(this)}).call(this,require("buffer").Buffer)},{"./crypto/hash":9,"./encoding/base58check":14,"./errors":18,"./networks":23,"./publickey":26,"./script":27,"./util/js":46,"./util/preconditions":47,buffer:159,lodash:84}],2:[function(require,module,exports){"use strict";const BufferReader=require("../encoding/bufferreader");const BufferWriter=require("../encoding/bufferwriter");const $=require("../util/preconditions");const BufferUtil=require("../util/buffer");const Transaction=require("../transaction/transaction");const BlockHeader=require("./blockheader");function AuxPow(header,data){if(!(this instanceof AuxPow)){return new AuxPow(header,data)}$.checkArgument(header&&header.version,"version is missing from header");if(!(header.version&1<<8)){return}const info=this._from(data);this.coinbaseTxn=info.coinbaseTxn;this.coinbaseBranch=info.coinbaseBranch;this.blockchainBranch=info.blockchainBranch;this._blockHash=info.blockHashBuf;this._parentBlock=info.parentBlockBuf;return this}Object.defineProperty(AuxPow.prototype,"parentBlock",{enumerable:true,configurable:true,get:function(){return new BlockHeader(this._parentBlock)}});Object.defineProperty(AuxPow.prototype,"blockHash",{enumerable:true,configurable:false,get:function(){return this.parentBlock.hash}});AuxPow.prototype._from=function(data){let info={};if(data instanceof BufferReader||BufferUtil.isBuffer(data.buf)&&!isNaN(data.pos)){info=this._fromBufferReader(data)}else if(BufferUtil.isBuffer(data)){data=BufferReader(data);info=this._fromBufferReader(data)}else{throw new TypeError("Unrecognized argument for AuxPow")}return info};AuxPow.prototype._fromBufferReader=function(br){$.checkArgument(br&&br instanceof BufferReader,"A bufferreader is required");const info={coinbaseTxn:(new Transaction).fromBufferReader(br),blockHashBuf:br.read(32),coinbaseBranch:this._getMerkleBranch(br),blockchainBranch:this._getMerkleBranch(br),parentBlockBuf:br.read(80)};return info};AuxPow.prototype._getMerkleBranch=function(br){const branchLen=br.readVarintNum();const branchHashes=[];for(let j=0;j1;size=Math.floor((size+1)/2)){for(var i=0;i"};Block.Values={START_OF_BLOCK:0,NULL_HASH:Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex")};module.exports=Block}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/bn":7,"../crypto/hash":9,"../encoding/bufferreader":15,"../encoding/bufferwriter":16,"../transaction":30,"../util/buffer":45,"../util/preconditions":47,"./blockheader":4,buffer:159,lodash:84}],4:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var BN=require("../crypto/bn");var BufferUtil=require("../util/buffer");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var $=require("../util/preconditions");var Script=require("../script");var GENESIS_BITS=504365040;var BlockHeader=function BlockHeader(arg){if(!(this instanceof BlockHeader)){return new BlockHeader(arg)}var info=BlockHeader._from(arg);this.version=info.version;this.prevHash=info.prevHash;this.merkleRoot=info.merkleRoot;this.time=info.time;this.timestamp=info.time;this.bits=info.bits;this.nonce=info.nonce;this._auxpow=info.auxpow;if(info.hash){$.checkState(this.hash===info.hash,"Argument object hash property does not match block hash.")}return this};BlockHeader._from=function _from(arg){var info={};if(BufferUtil.isBuffer(arg)){info=BlockHeader._fromBufferReader(BufferReader(arg))}else if(_.isObject(arg)){info=BlockHeader._fromObject(arg)}else{throw new TypeError("Unrecognized argument for BlockHeader")}return info};BlockHeader._fromObject=function _fromObject(data){$.checkArgument(data,"data is required");var prevHash=data.prevHash;var merkleRoot=data.merkleRoot;if(_.isString(data.prevHash)){prevHash=BufferUtil.reverse(Buffer.from(data.prevHash,"hex"))}if(_.isString(data.merkleRoot)){merkleRoot=BufferUtil.reverse(Buffer.from(data.merkleRoot,"hex"))}var info={hash:data.hash,version:data.version,prevHash:prevHash,merkleRoot:merkleRoot,time:data.time,timestamp:data.time,bits:data.bits,nonce:data.nonce,auxpow:data.auxpow};return info};BlockHeader.fromObject=function fromObject(obj){var info=BlockHeader._fromObject(obj);return new BlockHeader(info)};BlockHeader.fromRawBlock=function fromRawBlock(data){if(!BufferUtil.isBuffer(data)){data=Buffer.from(data,"binary")}var br=BufferReader(data);br.pos=BlockHeader.Constants.START_OF_HEADER;var info=BlockHeader._fromBufferReader(br);return new BlockHeader(info)};BlockHeader.fromBuffer=function fromBuffer(buf){var info=BlockHeader._fromBufferReader(BufferReader(buf));return new BlockHeader(info)};BlockHeader.fromString=function fromString(str){var buf=Buffer.from(str,"hex");return BlockHeader.fromBuffer(buf)};BlockHeader._fromBufferReader=function _fromBufferReader(br){var info={};info.version=br.readInt32LE();info.prevHash=br.read(32);info.merkleRoot=br.read(32);info.time=br.readUInt32LE();info.bits=br.readUInt32LE();info.nonce=br.readUInt32LE();info.auxpow=new AuxPow(info,br);return info};BlockHeader.fromBufferReader=function fromBufferReader(br){var info=BlockHeader._fromBufferReader(br);return new BlockHeader(info)};BlockHeader.prototype.toObject=BlockHeader.prototype.toJSON=function toObject(){return{hash:this.hash,version:this.version,prevHash:BufferUtil.reverse(this.prevHash).toString("hex"),merkleRoot:BufferUtil.reverse(this.merkleRoot).toString("hex"),time:this.time,bits:this.bits,nonce:this.nonce}};BlockHeader.prototype.toBuffer=function toBuffer(includeAuxPow=true){return this.toBufferWriter(null,includeAuxPow).concat()};BlockHeader.prototype.toString=function toString(){return this.toBuffer().toString("hex")};BlockHeader.prototype.toBufferWriter=function toBufferWriter(bw,includeAuxPow=true){if(!bw){bw=new BufferWriter}bw.writeInt32LE(this.version);bw.write(this.prevHash);bw.write(this.merkleRoot);bw.writeUInt32LE(this.time);bw.writeUInt32LE(this.bits);bw.writeUInt32LE(this.nonce);if(includeAuxPow&&this.isAuxPow()){this.auxpow.toBufferWriter(bw)}return bw};BlockHeader.prototype.getTargetDifficulty=function getTargetDifficulty(bits){bits=bits||this.bits;var target=new BN(bits&16777215);var mov=8*((bits>>>24)-3);while(mov-- >0){target=target.mul(new BN(2))}return target};BlockHeader.prototype.getDifficulty=function getDifficulty(){if(!this.bits){return 1}let decimalShift=this.bits>>24&255;let difficulty=65535/(this.bits&16777215);while(decimalShift<29){difficulty*=256;decimalShift++}while(decimalShift>29){difficulty/=256;decimalShift--}return parseFloat(difficulty.toFixed(19))};BlockHeader.prototype._getHash=function hash(){var buf=this.toBuffer(false);return Hash.sha256sha256(buf)};var idProperty={configurable:false,enumerable:true,get:function(){if(!this._id){this._id=BufferReader(this._getHash()).readReverse().toString("hex")}return this._id},set:_.noop};Object.defineProperty(BlockHeader.prototype,"id",idProperty);Object.defineProperty(BlockHeader.prototype,"hash",idProperty);BlockHeader.prototype.validTimestamp=function validTimestamp(){var currentTime=Math.round((new Date).getTime()/1e3);if(this.time>currentTime+BlockHeader.Constants.MAX_TIME_OFFSET){return false}return true};BlockHeader.prototype.validProofOfWork=function validProofOfWork(){let hashBuf;if(this.isAuxPow()){hashBuf=this.auxpow.parentBlock.toBuffer()}else{hashBuf=this.toBuffer()}var pow=new BN(Hash.scrypt(hashBuf));var target=this.getTargetDifficulty();if(pow.cmp(target)>0){return false}return true};BlockHeader.prototype.inspect=function inspect(){return""};BlockHeader.prototype.isAuxPow=function(){return Boolean(this.version&1<<8)};Object.defineProperty(BlockHeader.prototype,"auxpow",{configurable:false,enumerable:true,get:function(){if(this.isAuxPow()){return this._auxpow}return null}});BlockHeader.Constants={START_OF_HEADER:0,MAX_TIME_OFFSET:2*60*60,LARGEST_HASH:new BN("10000000000000000000000000000000000000000000000000000000000000000","hex")};module.exports=BlockHeader;var AuxPow=require("./auxpow")}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/bn":7,"../crypto/hash":9,"../encoding/bufferreader":15,"../encoding/bufferwriter":16,"../script":27,"../util/buffer":45,"../util/preconditions":47,"./auxpow":2,buffer:159,lodash:84}],5:[function(require,module,exports){module.exports=require("./block");module.exports.BlockHeader=require("./blockheader");module.exports.MerkleBlock=require("./merkleblock")},{"./block":3,"./blockheader":4,"./merkleblock":6}],6:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var BlockHeader=require("./blockheader");var BufferUtil=require("../util/buffer");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var JSUtil=require("../util/js");var Transaction=require("../transaction");var $=require("../util/preconditions");function MerkleBlock(arg){if(!(this instanceof MerkleBlock)){return new MerkleBlock(arg)}var info={};if(BufferUtil.isBuffer(arg)){info=MerkleBlock._fromBufferReader(BufferReader(arg))}else if(_.isObject(arg)){var header;if(arg.header instanceof BlockHeader){header=arg.header}else{header=BlockHeader.fromObject(arg.header)}info={header:header,numTransactions:arg.numTransactions,hashes:arg.hashes,flags:arg.flags}}else{throw new TypeError("Unrecognized argument for MerkleBlock")}_.extend(this,info);this._flagBitsUsed=0;this._hashesUsed=0;return this}MerkleBlock.fromBuffer=function fromBuffer(buf){return MerkleBlock.fromBufferReader(BufferReader(buf))};MerkleBlock.fromBufferReader=function fromBufferReader(br){return new MerkleBlock(MerkleBlock._fromBufferReader(br))};MerkleBlock.prototype.toBuffer=function toBuffer(){return this.toBufferWriter().concat()};MerkleBlock.prototype.toBufferWriter=function toBufferWriter(bw){if(!bw){bw=new BufferWriter}bw.write(this.header.toBuffer());bw.writeUInt32LE(this.numTransactions);bw.writeVarintNum(this.hashes.length);for(var i=0;ithis.numTransactions){return false}if(this.flags.length*8this.flags.length*8){return null}var isParentOfMatch=this.flags[opts.flagBitsUsed>>3]>>>(opts.flagBitsUsed++&7)&1;if(depth===0||!isParentOfMatch){if(opts.hashesUsed>=this.hashes.length){return null}var hash=this.hashes[opts.hashesUsed++];if(depth===0&&isParentOfMatch){opts.txs.push(hash)}return new Buffer(hash,"hex")}else{var left=this._traverseMerkleTree(depth-1,pos*2,opts);var right=left;if(pos*2+1>height};MerkleBlock.prototype._calcTreeHeight=function calcTreeHeight(){var height=0;while(this._calcTreeWidth(height)>1){height++}return height};MerkleBlock.prototype.hasTransaction=function hasTransaction(tx){$.checkArgument(!_.isUndefined(tx),"tx cannot be undefined");$.checkArgument(tx instanceof Transaction||typeof tx==="string",'Invalid tx given, tx must be a "string" or "Transaction"');var hash=tx;if(tx instanceof Transaction){hash=BufferUtil.reverse(new Buffer(tx.id,"hex")).toString("hex")}var txs=[];var height=this._calcTreeHeight();this._traverseMerkleTree(height,0,{txs:txs});return txs.indexOf(hash)!==-1};MerkleBlock._fromBufferReader=function _fromBufferReader(br){$.checkState(!br.finished(),"No merkleblock data received");var info={};info.header=BlockHeader.fromBufferReader(br);info.numTransactions=br.readUInt32LE();var numHashes=br.readVarintNum();info.hashes=[];for(var i=0;iopts.size){buf=BN.trim(buf,natlen)}else if(natlen0){if((buf[buf.length-1]&127)===0){if(buf.length<=1||(buf[buf.length-2]&128)===0){throw new Error("non-minimally encoded script number")}}}return BN.fromSM(buf,{endian:"little"})};BN.prototype.toScriptNumBuffer=function(){return this.toSM({endian:"little"})};BN.prototype.gt=function(b){return this.cmp(b)>0};BN.prototype.gte=function(b){return this.cmp(b)>=0};BN.prototype.lt=function(b){return this.cmp(b)<0};BN.trim=function(buf,natlen){return buf.slice(natlen-buf.length,buf.length)};BN.pad=function(buf,natlen,size){var rbuf=Buffer.alloc(size);for(var i=0;i>1;var n=Point.getN();var G=Point.getG();var x=isSecondKey?r.add(n):r;var R=Point.fromX(isYOdd,x);var nR=R.mul(n);if(!nR.isInfinity()){throw new Error("nR is not a valid curve point")}var eNeg=e.neg().umod(n);var rInv=r.invm(n);var Q=R.mul(s).add(G.mul(eNeg)).mul(rInv);var pubkey=PublicKey.fromPoint(Q,this.sig.compressed);return pubkey};ECDSA.prototype.sigError=function(){if(!BufferUtil.isBuffer(this.hashbuf)||this.hashbuf.length!==32){return"hashbuf must be a 32 byte buffer"}var r=this.sig.r;var s=this.sig.s;if(!(r.gt(BN.Zero)&&r.lt(Point.getN()))||!(s.gt(BN.Zero)&&s.lt(Point.getN()))){return"r and s not in range"}var e=BN.fromBuffer(this.hashbuf,this.endian?{endian:this.endian}:undefined);var n=Point.getN();var sinv=s.invm(n);var u1=sinv.mul(e).umod(n);var u2=sinv.mul(r).umod(n);var p=Point.getG().mulAdd(u1,this.pubkey.point,u2);if(p.isInfinity()){return"p is infinity"}if(p.getX().umod(n).cmp(r)!==0){return"Invalid signature"}else{return false}};ECDSA.toLowS=function(s){if(s.gt(BN.fromBuffer(Buffer.from("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))){s=Point.getN().sub(s)}return s};ECDSA.prototype._findSignature=function(d,e){var N=Point.getN();var G=Point.getG();var badrs=0;var k,Q,r,s;do{if(!this.k||badrs>0){this.deterministicK(badrs)}badrs++;k=this.k;Q=G.mul(k);r=Q.x.umod(N);s=k.invm(N).mul(e.add(d.mul(r))).umod(N)}while(r.cmp(BN.Zero)<=0||s.cmp(BN.Zero)<=0);s=ECDSA.toLowS(s);return{s:s,r:r}};ECDSA.prototype.sign=function(){var hashbuf=this.hashbuf;var privkey=this.privkey;var d=privkey.bn;$.checkState(hashbuf&&privkey&&d,new Error("invalid parameters"));$.checkState(BufferUtil.isBuffer(hashbuf)&&hashbuf.length===32,new Error("hashbuf must be a 32 byte buffer"));var e=BN.fromBuffer(hashbuf,this.endian?{endian:this.endian}:undefined);var obj=this._findSignature(d,e);obj.compressed=this.pubkey.compressed;this.sig=new Signature(obj);return this};ECDSA.prototype.signRandomK=function(){this.randomK();return this.sign()};ECDSA.prototype.toString=function(){var obj={};if(this.hashbuf){obj.hashbuf=this.hashbuf.toString("hex")}if(this.privkey){obj.privkey=this.privkey.toString()}if(this.pubkey){obj.pubkey=this.pubkey.toString()}if(this.sig){obj.sig=this.sig.toString()}if(this.k){obj.k=this.k.toString()}return JSON.stringify(obj)};ECDSA.prototype.verify=function(){if(!this.sigError()){this.verified=true}else{this.verified=false}return this};ECDSA.sign=function(hashbuf,privkey,endian){return ECDSA().set({hashbuf:hashbuf,endian:endian,privkey:privkey}).sign().sig};ECDSA.verify=function(hashbuf,sig,pubkey,endian){return ECDSA().set({hashbuf:hashbuf,endian:endian,sig:sig,pubkey:pubkey}).verify().verified};module.exports=ECDSA}).call(this)}).call(this,require("buffer").Buffer)},{"../publickey":26,"../util/buffer":45,"../util/preconditions":47,"./bn":7,"./hash":9,"./point":10,"./random":11,"./signature":12,buffer:159,lodash:84}],9:[function(require,module,exports){(function(Buffer){(function(){"use strict";var crypto=require("crypto");var BufferUtil=require("../util/buffer");var Scrypt=require("scryptsy");var $=require("../util/preconditions");var Hash=module.exports;Hash.sha1=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha1").update(buf).digest()};Hash.sha1.blocksize=512;Hash.sha256=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha256").update(buf).digest()};Hash.sha256.blocksize=512;Hash.sha256sha256=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return Hash.sha256(Hash.sha256(buf))};Hash.ripemd160=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("ripemd160").update(buf).digest()};Hash.sha256ripemd160=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return Hash.ripemd160(Hash.sha256(buf))};Hash.sha512=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha512").update(buf).digest()};Hash.sha512.blocksize=1024;Hash.hmac=function(hashf,data,key){$.checkArgument(BufferUtil.isBuffer(data));$.checkArgument(BufferUtil.isBuffer(key));$.checkArgument(hashf.blocksize);var blocksize=hashf.blocksize/8;if(key.length>blocksize){key=hashf(key)}else if(key>>8)&255}}return b};module.exports=Random}).call(this)}).call(this,require("_process"),require("buffer").Buffer)},{_process:246,buffer:159,crypto:167}],12:[function(require,module,exports){(function(Buffer){(function(){"use strict";var BN=require("./bn");var _=require("lodash");var $=require("../util/preconditions");var BufferUtil=require("../util/buffer");var JSUtil=require("../util/js");var Signature=function Signature(r,s){if(!(this instanceof Signature)){return new Signature(r,s)}if(r instanceof BN){this.set({r:r,s:s})}else if(r){var obj=r;this.set(obj)}};Signature.prototype.set=function(obj){this.r=obj.r||this.r||undefined;this.s=obj.s||this.s||undefined;this.i=typeof obj.i!=="undefined"?obj.i:this.i;this.compressed=typeof obj.compressed!=="undefined"?obj.compressed:this.compressed;this.nhashtype=obj.nhashtype||this.nhashtype||undefined;return this};Signature.fromCompact=function(buf){$.checkArgument(BufferUtil.isBuffer(buf),"Argument is expected to be a Buffer");var sig=new Signature;var compressed=true;var i=buf.slice(0,1)[0]-27-4;if(i<0){compressed=false;i=i+4}var b2=buf.slice(1,33);var b3=buf.slice(33,65);$.checkArgument(i===0||i===1||i===2||i===3,new Error("i must be 0, 1, 2, or 3"));$.checkArgument(b2.length===32,new Error("r must be 32 bytes"));$.checkArgument(b3.length===32,new Error("s must be 32 bytes"));sig.compressed=compressed;sig.i=i;sig.r=BN.fromBuffer(b2);sig.s=BN.fromBuffer(b3);return sig};Signature.fromDER=Signature.fromBuffer=function(buf,strict){var obj=Signature.parseDER(buf,strict);var sig=new Signature;sig.r=obj.r;sig.s=obj.s;return sig};Signature.fromTxFormat=function(buf){var nhashtype=buf.readUInt8(buf.length-1);var derbuf=buf.slice(0,buf.length-1);var sig=new Signature.fromDER(derbuf,false);sig.nhashtype=nhashtype;return sig};Signature.fromString=function(str){var buf=Buffer.from(str,"hex");return Signature.fromDER(buf)};Signature.parseDER=function(buf,strict){$.checkArgument(BufferUtil.isBuffer(buf),new Error("DER formatted signature should be a buffer"));if(_.isUndefined(strict)){strict=true}var header=buf[0];$.checkArgument(header===48,new Error("Header byte should be 0x30"));var length=buf[1];var buflength=buf.slice(2).length;$.checkArgument(!strict||length===buflength,new Error("Length byte should length of what follows"));length=length73){return false}if(buf[0]!==48){return false}if(buf[1]!==buf.length-3){return false}var nLenR=buf[3];if(5+nLenR>=buf.length){return false}var nLenS=buf[5+nLenR];if(nLenR+nLenS+7!==buf.length){return false}var R=buf.slice(4);if(buf[4-2]!==2){return false}if(nLenR===0){return false}if(R[0]&128){return false}if(nLenR>1&&R[0]===0&&!(R[1]&128)){return false}var S=buf.slice(6+nLenR);if(buf[6+nLenR-2]!==2){return false}if(nLenS===0){return false}if(S[0]&128){return false}if(nLenS>1&&S[0]===0&&!(S[1]&128)){return false}return true};Signature.prototype.hasLowS=function(){if(this.s.lt(new BN(1))||this.s.gt(new BN("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex"))){return false}return true};Signature.prototype.hasDefinedHashtype=function(){if(!JSUtil.isNaturalNumber(this.nhashtype)){return false}var temp=this.nhashtype&~Signature.SIGHASH_ANYONECANPAY;if(tempSignature.SIGHASH_SINGLE){return false}return true};Signature.prototype.toTxFormat=function(){var derbuf=this.toDER();var buf=Buffer.alloc(1);buf.writeUInt8(this.nhashtype,0);return Buffer.concat([derbuf,buf])};Signature.SIGHASH_ALL=1;Signature.SIGHASH_NONE=2;Signature.SIGHASH_SINGLE=3;Signature.SIGHASH_ANYONECANPAY=128;module.exports=Signature}).call(this)}).call(this,require("buffer").Buffer)},{"../util/buffer":45,"../util/js":46,"../util/preconditions":47,"./bn":7,buffer:159,lodash:84}],13:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var bs58=require("bs58");var buffer=require("buffer");var ALPHABET="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split("");var Base58=function Base58(obj){if(!(this instanceof Base58)){return new Base58(obj)}if(Buffer.isBuffer(obj)){var buf=obj;this.fromBuffer(buf)}else if(typeof obj==="string"){var str=obj;this.fromString(str)}else if(obj){this.set(obj)}};Base58.validCharacters=function validCharacters(chars){if(buffer.Buffer.isBuffer(chars)){chars=chars.toString()}return _.every(_.map(chars,function(char){return ALPHABET.includes(char)}))};Base58.prototype.set=function(obj){this.buf=obj.buf||this.buf||undefined;return this};Base58.encode=function(buf){if(!buffer.Buffer.isBuffer(buf)){throw new Error("Input should be a buffer")}return bs58.encode(buf)};Base58.decode=function(str){if(typeof str!=="string"){throw new Error("Input should be a string")}return new Buffer(bs58.decode(str))};Base58.prototype.fromBuffer=function(buf){this.buf=buf;return this};Base58.prototype.fromString=function(str){var buf=Base58.decode(str);this.buf=buf;return this};Base58.prototype.toBuffer=function(){return this.buf};Base58.prototype.toString=function(){return Base58.encode(this.buf)};module.exports=Base58}).call(this)}).call(this,require("buffer").Buffer)},{bs58:51,buffer:159,lodash:84}],14:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var Base58=require("./base58");var buffer=require("buffer");var sha256sha256=require("../crypto/hash").sha256sha256;var Base58Check=function Base58Check(obj){if(!(this instanceof Base58Check))return new Base58Check(obj);if(Buffer.isBuffer(obj)){var buf=obj;this.fromBuffer(buf)}else if(typeof obj==="string"){var str=obj;this.fromString(str)}else if(obj){this.set(obj)}};Base58Check.prototype.set=function(obj){this.buf=obj.buf||this.buf||undefined;return this};Base58Check.validChecksum=function validChecksum(data,checksum){if(_.isString(data)){data=new buffer.Buffer(Base58.decode(data))}if(_.isString(checksum)){checksum=new buffer.Buffer(Base58.decode(checksum))}if(!checksum){checksum=data.slice(-4);data=data.slice(0,-4)}return Base58Check.checksum(data).toString("hex")===checksum.toString("hex")};Base58Check.decode=function(s){if(typeof s!=="string")throw new Error("Input must be a string");var buf=new Buffer(Base58.decode(s));if(buf.length<4)throw new Error("Input string too short");var data=buf.slice(0,-4);var csum=buf.slice(-4);var hash=sha256sha256(data);var hash4=hash.slice(0,4);if(csum.toString("hex")!==hash4.toString("hex"))throw new Error("Checksum mismatch");return data};Base58Check.checksum=function(buffer){return sha256sha256(buffer).slice(0,4)};Base58Check.encode=function(buf){if(!Buffer.isBuffer(buf))throw new Error("Input must be a buffer");var checkedBuf=new Buffer(buf.length+4);var hash=Base58Check.checksum(buf);buf.copy(checkedBuf);hash.copy(checkedBuf,buf.length);return Base58.encode(checkedBuf)};Base58Check.prototype.fromBuffer=function(buf){this.buf=buf;return this};Base58Check.prototype.fromString=function(str){var buf=Base58Check.decode(str);this.buf=buf;return this};Base58Check.prototype.toBuffer=function(){return this.buf};Base58Check.prototype.toString=function(){return Base58Check.encode(this.buf)};module.exports=Base58Check}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/hash":9,"./base58":13,buffer:159,lodash:84}],15:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var $=require("../util/preconditions");var BufferUtil=require("../util/buffer");var BN=require("../crypto/bn");var BufferReader=function BufferReader(buf){if(!(this instanceof BufferReader)){return new BufferReader(buf)}if(_.isUndefined(buf)){return}if(Buffer.isBuffer(buf)){this.set({buf:buf})}else if(_.isString(buf)){this.set({buf:Buffer.from(buf,"hex")})}else if(_.isObject(buf)){var obj=buf;this.set(obj)}else{throw new TypeError("Unrecognized argument for BufferReader")}};BufferReader.prototype.set=function(obj){this.buf=obj.buf||this.buf||undefined;this.pos=obj.pos||this.pos||0;return this};BufferReader.prototype.eof=function(){if(this.buf){return this.pos>=this.buf.length}else{return true}};BufferReader.prototype.finished=BufferReader.prototype.eof;BufferReader.prototype.read=function(len){$.checkArgument(!_.isUndefined(len),"Must specify a length");var buf=this.buf.slice(this.pos,this.pos+len);this.pos=this.pos+len;return buf};BufferReader.prototype.readAll=function(){var buf=this.buf.slice(this.pos,this.buf.length);this.pos=this.buf.length;return buf};BufferReader.prototype.readUInt8=function(){var val=this.buf.readUInt8(this.pos);this.pos=this.pos+1;return val};BufferReader.prototype.readUInt16BE=function(){var val=this.buf.readUInt16BE(this.pos);this.pos=this.pos+2;return val};BufferReader.prototype.readUInt16LE=function(){var val=this.buf.readUInt16LE(this.pos);this.pos=this.pos+2;return val};BufferReader.prototype.readUInt32BE=function(){var val=this.buf.readUInt32BE(this.pos);this.pos=this.pos+4;return val};BufferReader.prototype.readUInt32LE=function(){var val=this.buf.readUInt32LE(this.pos);this.pos=this.pos+4;return val};BufferReader.prototype.readInt32LE=function(){var val=this.buf.readInt32LE(this.pos);this.pos=this.pos+4;return val};BufferReader.prototype.readUInt64BEBN=function(){var buf=this.buf.slice(this.pos,this.pos+8);var bn=BN.fromBuffer(buf);this.pos=this.pos+8;return bn};BufferReader.prototype.readUInt64LEBN=function(){var second=this.buf.readUInt32LE(this.pos);var first=this.buf.readUInt32LE(this.pos+4);var combined=first*4294967296+second;var bn;if(combined<=9007199254740991){bn=new BN(combined)}else{var data=Array.prototype.slice.call(this.buf,this.pos,this.pos+8);bn=new BN(data,10,"le")}this.pos=this.pos+8;return bn};BufferReader.prototype.readVarintNum=function(){var first=this.readUInt8();switch(first){case 253:return this.readUInt16LE();case 254:return this.readUInt32LE();case 255:var bn=this.readUInt64LEBN();var n=bn.toNumber();if(n<=Math.pow(2,53)){return n}else{throw new Error("number too large to retain precision - use readVarintBN")}break;default:return first}};BufferReader.prototype.readVarLengthBuffer=function(){var len=this.readVarintNum();var buf=this.read(len);$.checkState(buf.length===len,"Invalid length while reading varlength buffer. "+"Expected to read: "+len+" and read "+buf.length);return buf};BufferReader.prototype.readVarintBuf=function(){var first=this.buf.readUInt8(this.pos);switch(first){case 253:return this.read(1+2);case 254:return this.read(1+4);case 255:return this.read(1+8);default:return this.read(1)}};BufferReader.prototype.readVarintBN=function(){var first=this.readUInt8();switch(first){case 253:return new BN(this.readUInt16LE());case 254:return new BN(this.readUInt32LE());case 255:return this.readUInt64LEBN();default:return new BN(first)}};BufferReader.prototype.reverse=function(){var buf=Buffer.alloc(this.buf.length);for(var i=0;i=0&&arg=HDPrivateKey.Hardened?true:hardened;if(indexMAXIMUM_ENTROPY_BITS*BITS_TO_BYTES){throw new hdErrors.InvalidEntropyArgument.TooMuchEntropy(hexa)}var hash=Hash.sha512hmac(hexa,new buffer.Buffer("Bitcoin seed"));return new HDPrivateKey({network:Network.get(network)||Network.defaultNetwork,depth:0,parentFingerPrint:0,childIndex:0,privateKey:hash.slice(0,32),chainCode:hash.slice(32,64)})};HDPrivateKey.prototype._calcHDPublicKey=function(){if(!this._hdPublicKey){var HDPublicKey=require("./hdpublickey");this._hdPublicKey=new HDPublicKey(this)}};HDPrivateKey.prototype._buildFromBuffers=function(arg){HDPrivateKey._validateBufferArguments(arg);JSUtil.defineImmutable(this,{_buffers:arg});var sequence=[arg.version,arg.depth,arg.parentFingerPrint,arg.childIndex,arg.chainCode,BufferUtil.emptyBuffer(1),arg.privateKey];var concat=buffer.Buffer.concat(sequence);if(!arg.checksum||!arg.checksum.length){arg.checksum=Base58Check.checksum(concat)}else{if(arg.checksum.toString()!==Base58Check.checksum(concat).toString()){throw new errors.InvalidB58Checksum(concat)}}var network=Network.get(BufferUtil.integerFromBuffer(arg.version));var xprivkey;xprivkey=Base58Check.encode(buffer.Buffer.concat(sequence));arg.xprivkey=Buffer.from(xprivkey);var privateKey=new PrivateKey(BN.fromBuffer(arg.privateKey),network);var publicKey=privateKey.toPublicKey();var size=HDPrivateKey.ParentFingerPrintSize;var fingerPrint=Hash.sha256ripemd160(publicKey.toBuffer()).slice(0,size);JSUtil.defineImmutable(this,{xprivkey:xprivkey,network:network,depth:BufferUtil.integerFromSingleByteBuffer(arg.depth),privateKey:privateKey,publicKey:publicKey,fingerPrint:fingerPrint});this._hdPublicKey=null;Object.defineProperty(this,"hdPublicKey",{configurable:false,enumerable:true,get:function(){this._calcHDPublicKey();return this._hdPublicKey}});Object.defineProperty(this,"xpubkey",{configurable:false,enumerable:true,get:function(){this._calcHDPublicKey();return this._hdPublicKey.xpubkey}});return this};HDPrivateKey._validateBufferArguments=function(arg){var checkBuffer=function(name,size){var buff=arg[name];assert(BufferUtil.isBuffer(buff),name+" argument is not a buffer");assert(buff.length===size,name+" has not the expected size: found "+buff.length+", expected "+size)};checkBuffer("version",HDPrivateKey.VersionSize);checkBuffer("depth",HDPrivateKey.DepthSize);checkBuffer("parentFingerPrint",HDPrivateKey.ParentFingerPrintSize);checkBuffer("childIndex",HDPrivateKey.ChildIndexSize);checkBuffer("chainCode",HDPrivateKey.ChainCodeSize);checkBuffer("privateKey",HDPrivateKey.PrivateKeySize);if(arg.checksum&&arg.checksum.length){checkBuffer("checksum",HDPrivateKey.CheckSumSize)}};HDPrivateKey.prototype.toString=function(){return this.xprivkey};HDPrivateKey.prototype.inspect=function(){return""};HDPrivateKey.prototype.toObject=HDPrivateKey.prototype.toJSON=function toObject(){return{network:Network.get(BufferUtil.integerFromBuffer(this._buffers.version),"xprivkey").name,depth:BufferUtil.integerFromSingleByteBuffer(this._buffers.depth),fingerPrint:BufferUtil.integerFromBuffer(this.fingerPrint),parentFingerPrint:BufferUtil.integerFromBuffer(this._buffers.parentFingerPrint),childIndex:BufferUtil.integerFromBuffer(this._buffers.childIndex),chainCode:BufferUtil.bufferToHex(this._buffers.chainCode),privateKey:this.privateKey.toBuffer().toString("hex"),checksum:BufferUtil.integerFromBuffer(this._buffers.checksum),xprivkey:this.xprivkey}};HDPrivateKey.fromBuffer=function(arg){return new HDPrivateKey(arg.toString())};HDPrivateKey.prototype.toBuffer=function(){return BufferUtil.copy(this._buffers.xprivkey)};HDPrivateKey.DefaultDepth=0;HDPrivateKey.DefaultFingerprint=0;HDPrivateKey.DefaultChildIndex=0;HDPrivateKey.Hardened=2147483648;HDPrivateKey.MaxIndex=2*HDPrivateKey.Hardened;HDPrivateKey.RootElementAlias=["m","M","m'","M'"];HDPrivateKey.VersionSize=4;HDPrivateKey.DepthSize=1;HDPrivateKey.ParentFingerPrintSize=4;HDPrivateKey.ChildIndexSize=4;HDPrivateKey.ChainCodeSize=32;HDPrivateKey.PrivateKeySize=32;HDPrivateKey.CheckSumSize=4;HDPrivateKey.DataLength=78;HDPrivateKey.SerializedByteSize=82;HDPrivateKey.VersionStart=0;HDPrivateKey.VersionEnd=HDPrivateKey.VersionStart+HDPrivateKey.VersionSize;HDPrivateKey.DepthStart=HDPrivateKey.VersionEnd;HDPrivateKey.DepthEnd=HDPrivateKey.DepthStart+HDPrivateKey.DepthSize;HDPrivateKey.ParentFingerPrintStart=HDPrivateKey.DepthEnd;HDPrivateKey.ParentFingerPrintEnd=HDPrivateKey.ParentFingerPrintStart+HDPrivateKey.ParentFingerPrintSize;HDPrivateKey.ChildIndexStart=HDPrivateKey.ParentFingerPrintEnd;HDPrivateKey.ChildIndexEnd=HDPrivateKey.ChildIndexStart+HDPrivateKey.ChildIndexSize;HDPrivateKey.ChainCodeStart=HDPrivateKey.ChildIndexEnd;HDPrivateKey.ChainCodeEnd=HDPrivateKey.ChainCodeStart+HDPrivateKey.ChainCodeSize;HDPrivateKey.PrivateKeyStart=HDPrivateKey.ChainCodeEnd+1;HDPrivateKey.PrivateKeyEnd=HDPrivateKey.PrivateKeyStart+HDPrivateKey.PrivateKeySize;HDPrivateKey.ChecksumStart=HDPrivateKey.PrivateKeyEnd;HDPrivateKey.ChecksumEnd=HDPrivateKey.ChecksumStart+HDPrivateKey.CheckSumSize;assert(HDPrivateKey.ChecksumEnd===HDPrivateKey.SerializedByteSize);module.exports=HDPrivateKey}).call(this)}).call(this,require("buffer").Buffer)},{"./crypto/bn":7,"./crypto/hash":9,"./crypto/point":10,"./crypto/random":11,"./encoding/base58":13,"./encoding/base58check":14,"./errors":18,"./hdkeycache":20,"./hdpublickey":22,"./networks":23,"./privatekey":25,"./util/buffer":45,"./util/js":46,"./util/preconditions":47,assert:108,buffer:159,lodash:84}],22:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var $=require("./util/preconditions");var BN=require("./crypto/bn");var Base58=require("./encoding/base58");var Base58Check=require("./encoding/base58check");var Hash=require("./crypto/hash");var HDPrivateKey=require("./hdprivatekey");var HDKeyCache=require("./hdkeycache");var Network=require("./networks");var Point=require("./crypto/point");var PublicKey=require("./publickey");var bitcoreErrors=require("./errors");var errors=bitcoreErrors;var hdErrors=bitcoreErrors.HDPublicKey;var assert=require("assert");var JSUtil=require("./util/js");var BufferUtil=require("./util/buffer");function HDPublicKey(arg){if(arg instanceof HDPublicKey){return arg}if(!(this instanceof HDPublicKey)){return new HDPublicKey(arg)}if(arg){if(_.isString(arg)||BufferUtil.isBuffer(arg)){var error=HDPublicKey.getSerializedError(arg);if(!error){return this._buildFromSerialized(arg)}else if(BufferUtil.isBuffer(arg)&&!HDPublicKey.getSerializedError(arg.toString())){return this._buildFromSerialized(arg.toString())}else{if(error instanceof hdErrors.ArgumentIsPrivateExtended){return new HDPrivateKey(arg).hdPublicKey}throw error}}else{if(_.isObject(arg)){if(arg instanceof HDPrivateKey){return this._buildFromPrivate(arg)}else{return this._buildFromObject(arg)}}else{throw new hdErrors.UnrecognizedArgument(arg)}}}else{throw new hdErrors.MustSupplyArgument}}HDPublicKey.isValidPath=function(arg){if(_.isString(arg)){var indexes=HDPrivateKey._getDerivationIndexes(arg);return indexes!==null&&_.every(indexes,HDPublicKey.isValidPath)}if(_.isNumber(arg)){return arg>=0&&arg=HDPublicKey.Hardened||hardened){throw new hdErrors.InvalidIndexCantDeriveHardened}if(index<0){throw new hdErrors.InvalidPath(index)}var cached=HDKeyCache.get(this.xpubkey,index,false);if(cached){return cached}var indexBuffer=BufferUtil.integerAsBuffer(index);var data=BufferUtil.concat([this.publicKey.toBuffer(),indexBuffer]);var hash=Hash.sha512hmac(data,this._buffers.chainCode);var leftPart=BN.fromBuffer(hash.slice(0,32),{size:32});var chainCode=hash.slice(32,64);var publicKey;try{publicKey=PublicKey.fromPoint(Point.getG().mul(leftPart).add(this.publicKey.point))}catch(e){return this._deriveWithNumber(index+1)}var derived=new HDPublicKey({network:this.network,depth:this.depth+1,parentFingerPrint:this.fingerPrint,childIndex:index,chainCode:chainCode,publicKey:publicKey});HDKeyCache.set(this.xpubkey,index,false,derived);return derived};HDPublicKey.prototype._deriveFromString=function(path){if(path.includes("'")){throw new hdErrors.InvalidIndexCantDeriveHardened}else if(!HDPublicKey.isValidPath(path)){throw new hdErrors.InvalidPath(path)}var indexes=HDPrivateKey._getDerivationIndexes(path);var derived=indexes.reduce(function(prev,index){return prev._deriveWithNumber(index)},this);return derived};HDPublicKey.isValidSerialized=function(data,network){return _.isNull(HDPublicKey.getSerializedError(data,network))};HDPublicKey.getSerializedError=function(data,network){if(!(_.isString(data)||BufferUtil.isBuffer(data))){return new hdErrors.UnrecognizedArgument("expected buffer or string")}if(!Base58.validCharacters(data)){return new errors.InvalidB58Char("(unknown)",data)}try{data=Base58Check.decode(data)}catch(e){return new errors.InvalidB58Checksum(data)}if(data.length!==HDPublicKey.DataSize){return new hdErrors.InvalidLength(data)}if(!_.isUndefined(network)){var error=HDPublicKey._validateNetwork(data,network);if(error){return error}}var version=BufferUtil.integerFromBuffer(data.slice(0,4));if(version===Network.livenet.xprivkey||version===Network.testnet.xprivkey){return new hdErrors.ArgumentIsPrivateExtended}return null};HDPublicKey._validateNetwork=function(data,networkArg){var network=Network.get(networkArg);if(!network){return new errors.InvalidNetworkArgument(networkArg)}var version=data.slice(HDPublicKey.VersionStart,HDPublicKey.VersionEnd);if(BufferUtil.integerFromBuffer(version)!==network.xpubkey){return new errors.InvalidNetwork(version)}return null};HDPublicKey.prototype._buildFromPrivate=function(arg){var args=_.clone(arg._buffers);var point=Point.getG().mul(BN.fromBuffer(args.privateKey));args.publicKey=Point.pointToCompressed(point);args.version=BufferUtil.integerAsBuffer(Network.get(BufferUtil.integerFromBuffer(args.version)).xpubkey);args.privateKey=undefined;args.checksum=undefined;args.xprivkey=undefined;return this._buildFromBuffers(args)};HDPublicKey.prototype._buildFromObject=function(arg){var buffers={version:arg.network?BufferUtil.integerAsBuffer(Network.get(arg.network).xpubkey):arg.version,depth:_.isNumber(arg.depth)?BufferUtil.integerAsSingleByteBuffer(arg.depth):arg.depth,parentFingerPrint:_.isNumber(arg.parentFingerPrint)?BufferUtil.integerAsBuffer(arg.parentFingerPrint):arg.parentFingerPrint,childIndex:_.isNumber(arg.childIndex)?BufferUtil.integerAsBuffer(arg.childIndex):arg.childIndex,chainCode:_.isString(arg.chainCode)?BufferUtil.hexToBuffer(arg.chainCode):arg.chainCode,publicKey:_.isString(arg.publicKey)?BufferUtil.hexToBuffer(arg.publicKey):BufferUtil.isBuffer(arg.publicKey)?arg.publicKey:arg.publicKey.toBuffer(),checksum:_.isNumber(arg.checksum)?BufferUtil.integerAsBuffer(arg.checksum):arg.checksum};return this._buildFromBuffers(buffers)};HDPublicKey.prototype._buildFromSerialized=function(arg){var decoded=Base58Check.decode(arg);var buffers={version:decoded.slice(HDPublicKey.VersionStart,HDPublicKey.VersionEnd),depth:decoded.slice(HDPublicKey.DepthStart,HDPublicKey.DepthEnd),parentFingerPrint:decoded.slice(HDPublicKey.ParentFingerPrintStart,HDPublicKey.ParentFingerPrintEnd),childIndex:decoded.slice(HDPublicKey.ChildIndexStart,HDPublicKey.ChildIndexEnd),chainCode:decoded.slice(HDPublicKey.ChainCodeStart,HDPublicKey.ChainCodeEnd),publicKey:decoded.slice(HDPublicKey.PublicKeyStart,HDPublicKey.PublicKeyEnd),checksum:decoded.slice(HDPublicKey.ChecksumStart,HDPublicKey.ChecksumEnd),xpubkey:arg};return this._buildFromBuffers(buffers)};HDPublicKey.prototype._buildFromBuffers=function(arg){HDPublicKey._validateBufferArguments(arg);JSUtil.defineImmutable(this,{_buffers:arg});var sequence=[arg.version,arg.depth,arg.parentFingerPrint,arg.childIndex,arg.chainCode,arg.publicKey];var concat=BufferUtil.concat(sequence);var checksum=Base58Check.checksum(concat);if(!arg.checksum||!arg.checksum.length){arg.checksum=checksum}else{if(arg.checksum.toString("hex")!==checksum.toString("hex")){throw new errors.InvalidB58Checksum(concat,checksum)}}var network=Network.get(BufferUtil.integerFromBuffer(arg.version));var xpubkey;xpubkey=Base58Check.encode(BufferUtil.concat(sequence));arg.xpubkey=new Buffer(xpubkey);var publicKey=new PublicKey(arg.publicKey,{network:network});var size=HDPublicKey.ParentFingerPrintSize;var fingerPrint=Hash.sha256ripemd160(publicKey.toBuffer()).slice(0,size);JSUtil.defineImmutable(this,{xpubkey:xpubkey,network:network,depth:BufferUtil.integerFromSingleByteBuffer(arg.depth),publicKey:publicKey,fingerPrint:fingerPrint});return this};HDPublicKey._validateBufferArguments=function(arg){var checkBuffer=function(name,size){var buff=arg[name];assert(BufferUtil.isBuffer(buff),name+" argument is not a buffer, it's "+typeof buff);assert(buff.length===size,name+" has not the expected size: found "+buff.length+", expected "+size)};checkBuffer("version",HDPublicKey.VersionSize);checkBuffer("depth",HDPublicKey.DepthSize);checkBuffer("parentFingerPrint",HDPublicKey.ParentFingerPrintSize);checkBuffer("childIndex",HDPublicKey.ChildIndexSize);checkBuffer("chainCode",HDPublicKey.ChainCodeSize);checkBuffer("publicKey",HDPublicKey.PublicKeySize);if(arg.checksum&&arg.checksum.length){checkBuffer("checksum",HDPublicKey.CheckSumSize)}};HDPublicKey.fromString=function(arg){$.checkArgument(_.isString(arg),"No valid string was provided");return new HDPublicKey(arg)};HDPublicKey.fromObject=function(arg){$.checkArgument(_.isObject(arg),"No valid argument was provided");return new HDPublicKey(arg)};HDPublicKey.prototype.toString=function(){return this.xpubkey};HDPublicKey.prototype.inspect=function(){return""};HDPublicKey.prototype.toObject=HDPublicKey.prototype.toJSON=function toObject(){return{network:Network.get(BufferUtil.integerFromBuffer(this._buffers.version)).name,depth:BufferUtil.integerFromSingleByteBuffer(this._buffers.depth),fingerPrint:BufferUtil.integerFromBuffer(this.fingerPrint),parentFingerPrint:BufferUtil.integerFromBuffer(this._buffers.parentFingerPrint),childIndex:BufferUtil.integerFromBuffer(this._buffers.childIndex),chainCode:BufferUtil.bufferToHex(this._buffers.chainCode),publicKey:this.publicKey.toString(),checksum:BufferUtil.integerFromBuffer(this._buffers.checksum),xpubkey:this.xpubkey}};HDPublicKey.fromBuffer=function(arg){return new HDPublicKey(arg)};HDPublicKey.prototype.toBuffer=function(){return BufferUtil.copy(this._buffers.xpubkey)};HDPublicKey.Hardened=2147483648;HDPublicKey.RootElementAlias=["m","M"];HDPublicKey.VersionSize=4;HDPublicKey.DepthSize=1;HDPublicKey.ParentFingerPrintSize=4;HDPublicKey.ChildIndexSize=4;HDPublicKey.ChainCodeSize=32;HDPublicKey.PublicKeySize=33;HDPublicKey.CheckSumSize=4;HDPublicKey.DataSize=78;HDPublicKey.SerializedByteSize=82;HDPublicKey.VersionStart=0;HDPublicKey.VersionEnd=HDPublicKey.VersionStart+HDPublicKey.VersionSize;HDPublicKey.DepthStart=HDPublicKey.VersionEnd;HDPublicKey.DepthEnd=HDPublicKey.DepthStart+HDPublicKey.DepthSize;HDPublicKey.ParentFingerPrintStart=HDPublicKey.DepthEnd;HDPublicKey.ParentFingerPrintEnd=HDPublicKey.ParentFingerPrintStart+HDPublicKey.ParentFingerPrintSize;HDPublicKey.ChildIndexStart=HDPublicKey.ParentFingerPrintEnd;HDPublicKey.ChildIndexEnd=HDPublicKey.ChildIndexStart+HDPublicKey.ChildIndexSize;HDPublicKey.ChainCodeStart=HDPublicKey.ChildIndexEnd;HDPublicKey.ChainCodeEnd=HDPublicKey.ChainCodeStart+HDPublicKey.ChainCodeSize;HDPublicKey.PublicKeyStart=HDPublicKey.ChainCodeEnd;HDPublicKey.PublicKeyEnd=HDPublicKey.PublicKeyStart+HDPublicKey.PublicKeySize;HDPublicKey.ChecksumStart=HDPublicKey.PublicKeyEnd;HDPublicKey.ChecksumEnd=HDPublicKey.ChecksumStart+HDPublicKey.CheckSumSize;assert(HDPublicKey.PublicKeyEnd===HDPublicKey.DataSize);assert(HDPublicKey.ChecksumEnd===HDPublicKey.SerializedByteSize);module.exports=HDPublicKey}).call(this)}).call(this,require("buffer").Buffer)},{"./crypto/bn":7,"./crypto/hash":9,"./crypto/point":10,"./encoding/base58":13,"./encoding/base58check":14,"./errors":18,"./hdkeycache":20,"./hdprivatekey":21,"./networks":23,"./publickey":26,"./util/buffer":45,"./util/js":46,"./util/preconditions":47,assert:108,buffer:159,lodash:84}],23:[function(require,module,exports){"use strict";var _=require("lodash");var BufferUtil=require("./util/buffer");var JSUtil=require("./util/js");var networks=[];var networkMaps={};function Network(){}Network.prototype.toString=function toString(){return this.name};function removeNetwork(network){for(var i=0;i=1){return networkMaps[arg][0]}else{return networkMaps[arg]}}function addNetwork(data){var network=new Network;JSUtil.defineImmutable(network,{name:data.name,alias:data.alias,pubkeyhash:data.pubkeyhash,privatekey:data.privatekey,scripthash:data.scripthash,xpubkey:data.xpubkey,xprivkey:data.xprivkey});if(data.networkMagic){JSUtil.defineImmutable(network,{networkMagic:BufferUtil.integerAsBuffer(data.networkMagic)})}if(data.port){JSUtil.defineImmutable(network,{port:data.port})}if(data.dnsSeeds){JSUtil.defineImmutable(network,{dnsSeeds:data.dnsSeeds})}_.each(network,function(value){if(!_.isUndefined(value)&&!_.isObject(value)){if(!networkMaps[value]){networkMaps[value]=[]}networkMaps[value].push(network)}});networks.push(network);return network}addNetwork({name:"livenet",alias:"mainnet",pubkeyhash:30,privatekey:158,scripthash:22,xpubkey:76067358,xprivkey:76066276,networkMagic:3233857728,port:22556,dnsSeeds:["seed.multidoge.org","seed2.multidoge.org","veryseed.denarius.pro","muchseed.denarius.pro","suchseed.denarius.pro","seed.dogecoin.com","seed.dogechain.info","seed.mophides.com","seed.dglibrary.org"]});var livenet=get("livenet");addNetwork({name:"testnet",alias:"test",pubkeyhash:113,privatekey:241,scripthash:196,xpubkey:70617039,xprivkey:70615956});var testnet=get("testnet");addNetwork({name:"regtest",alias:"dev",pubkeyhash:111,privatekey:239,scripthash:196,xpubkey:70617039,xprivkey:70615956});var regtest=get("regtest");var TESTNET={PORT:44556,NETWORK_MAGIC:BufferUtil.integerAsBuffer(4240553948),DNS_SEEDS:["testseed.jrn.me.uk"]};for(var key in TESTNET){if(!_.isObject(TESTNET[key])){networkMaps[TESTNET[key]]=testnet}}var REGTEST={PORT:18444,NETWORK_MAGIC:BufferUtil.integerAsBuffer(4206867930),DNS_SEEDS:[]};for(var key in REGTEST){if(!_.isObject(REGTEST[key])){networkMaps[REGTEST[key]]=testnet}}Object.defineProperty(testnet,"port",{enumerable:true,configurable:false,get:function(){if(this.regtestEnabled){return REGTEST.PORT}else{return TESTNET.PORT}}});Object.defineProperty(testnet,"networkMagic",{enumerable:true,configurable:false,get:function(){if(this.regtestEnabled){return REGTEST.NETWORK_MAGIC}else{return TESTNET.NETWORK_MAGIC}}});Object.defineProperty(testnet,"dnsSeeds",{enumerable:true,configurable:false,get:function(){if(this.regtestEnabled){return REGTEST.DNS_SEEDS}else{return TESTNET.DNS_SEEDS}}});Object.defineProperty(regtest,"networkMagic",{enumerable:true,configurable:false,get:function(){return REGTEST.NETWORK_MAGIC}});Object.defineProperty(regtest,"dnsSeeds",{enumerable:true,configurable:false,get:function(){return REGTEST.DNS_SEEDS}});Object.defineProperty(regtest,"port",{enumerable:true,configurable:false,get:function(){return REGTEST.PORT}});function enableRegtest(){testnet.regtestEnabled=true}function disableRegtest(){testnet.regtestEnabled=false}module.exports={add:addNetwork,remove:removeNetwork,defaultNetwork:livenet,livenet:livenet,mainnet:livenet,testnet:testnet,regtest:regtest,get:get,enableRegtest:enableRegtest,disableRegtest:disableRegtest}},{"./util/buffer":45,"./util/js":46,lodash:84}],24:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var $=require("./util/preconditions");var BufferUtil=require("./util/buffer");var JSUtil=require("./util/js");function Opcode(num){if(!(this instanceof Opcode)){return new Opcode(num)}var value;if(_.isNumber(num)){value=num}else if(_.isString(num)){value=Opcode.map[num]}else{throw new TypeError('Unrecognized num type: "'+typeof num+'" for Opcode')}JSUtil.defineImmutable(this,{num:value});return this}Opcode.fromBuffer=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return new Opcode(Number("0x"+buf.toString("hex")))};Opcode.fromNumber=function(num){$.checkArgument(_.isNumber(num));return new Opcode(num)};Opcode.fromString=function(str){$.checkArgument(_.isString(str));var value=Opcode.map[str];if(typeof value==="undefined"){throw new TypeError("Invalid opcodestr")}return new Opcode(value)};Opcode.prototype.toHex=function(){return this.num.toString(16)};Opcode.prototype.toBuffer=function(){return Buffer.from(this.toHex(),"hex")};Opcode.prototype.toNumber=function(){return this.num};Opcode.prototype.toString=function(){var str=Opcode.reverseMap[this.num];if(typeof str==="undefined"){throw new Error("Opcode does not have a string representation")}return str};Opcode.smallInt=function(n){$.checkArgument(_.isNumber(n),"Invalid Argument: n should be number");$.checkArgument(n>=0&&n<=16,"Invalid Argument: n must be between 0 and 16");if(n===0){return Opcode("OP_0")}return new Opcode(Opcode.map.OP_1+n-1)};Opcode.map={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_CHECKLOCKTIMEVERIFY:177,OP_CHECKSEQUENCEVERIFY:178,OP_NOP1:176,OP_NOP2:177,OP_NOP3:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};Opcode.reverseMap=[];for(var k in Opcode.map){Opcode.reverseMap[Opcode.map[k]]=k}_.extend(Opcode,Opcode.map);Opcode.isSmallIntOp=function(opcode){if(opcode instanceof Opcode){opcode=opcode.toNumber()}return opcode===Opcode.map.OP_0||opcode>=Opcode.map.OP_1&&opcode<=Opcode.map.OP_16};Opcode.prototype.inspect=function(){return""};module.exports=Opcode}).call(this)}).call(this,require("buffer").Buffer)},{"./util/buffer":45,"./util/js":46,"./util/preconditions":47,buffer:159,lodash:84}],25:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var Address=require("./address");var Base58Check=require("./encoding/base58check");var BN=require("./crypto/bn");var JSUtil=require("./util/js");var Networks=require("./networks");var Point=require("./crypto/point");var PublicKey=require("./publickey");var Random=require("./crypto/random");var $=require("./util/preconditions");function PrivateKey(data,network){if(!(this instanceof PrivateKey)){return new PrivateKey(data,network)}if(data instanceof PrivateKey){return data}var info=this._classifyArguments(data,network);if(!info.bn||info.bn.cmp(new BN(0))===0){throw new TypeError("Number can not be equal to zero, undefined, null or false")}if(!info.bn.lt(Point.getN())){throw new TypeError("Number must be less than N")}if(typeof info.network==="undefined"){throw new TypeError('Must specify the network ("livenet" or "testnet")')}JSUtil.defineImmutable(this,{bn:info.bn,compressed:info.compressed,network:info.network});Object.defineProperty(this,"publicKey",{configurable:false,enumerable:true,get:this.toPublicKey.bind(this)});return this}PrivateKey.prototype._classifyArguments=function(data,network){var info={compressed:true,network:network?Networks.get(network):Networks.defaultNetwork};if(_.isUndefined(data)||_.isNull(data)){info.bn=PrivateKey._getRandomBN()}else if(data instanceof BN){info.bn=data}else if(data instanceof Buffer||data instanceof Uint8Array){info=PrivateKey._transformBuffer(data,network)}else if(data.bn&&data.network){info=PrivateKey._transformObject(data)}else if(!network&&Networks.get(data)){info.bn=PrivateKey._getRandomBN();info.network=Networks.get(data)}else if(typeof data==="string"){if(JSUtil.isHexa(data)){info.bn=new BN(Buffer.from(data,"hex"))}else{info=PrivateKey._transformWIF(data,network)}}else{throw new TypeError("First argument is an unrecognized data type.")}return info};PrivateKey._getRandomBN=function(){var condition;var bn;do{var privbuf=Random.getRandomBuffer(32);bn=BN.fromBuffer(privbuf);condition=bn.lt(Point.getN())}while(!condition);return bn};PrivateKey._transformBuffer=function(buf,network){var info={};if(buf.length===32){return PrivateKey._transformBNBuffer(buf,network)}info.network=Networks.get(buf[0],"privatekey");if(!info.network){throw new Error("Invalid network")}if(network&&info.network!==Networks.get(network)){throw new TypeError("Private key network mismatch")}if(buf.length===1+32+1&&buf[1+32+1-1]===1){info.compressed=true}else if(buf.length===1+32){info.compressed=false}else{throw new Error("Length of buffer must be 33 (uncompressed) or 34 (compressed)")}info.bn=BN.fromBuffer(buf.slice(1,32+1));return info};PrivateKey._transformBNBuffer=function(buf,network){var info={};info.network=Networks.get(network)||Networks.defaultNetwork;info.bn=BN.fromBuffer(buf);info.compressed=false;return info};PrivateKey._transformWIF=function(str,network){return PrivateKey._transformBuffer(Base58Check.decode(str),network)};PrivateKey.fromBuffer=function(arg,network){return new PrivateKey(arg,network)};PrivateKey._transformObject=function(json){var bn=new BN(json.bn,"hex");var network=Networks.get(json.network);return{bn:bn,network:network,compressed:json.compressed}};PrivateKey.fromString=PrivateKey.fromWIF=function(str){$.checkArgument(_.isString(str),"First argument is expected to be a string.");return new PrivateKey(str)};PrivateKey.fromObject=function(obj){$.checkArgument(_.isObject(obj),"First argument is expected to be an object.");return new PrivateKey(obj)};PrivateKey.fromRandom=function(network){var bn=PrivateKey._getRandomBN();return new PrivateKey(bn,network)};PrivateKey.getValidationError=function(data,network){var error;try{new PrivateKey(data,network)}catch(e){error=e}return error};PrivateKey.isValid=function(data,network){if(!data){return false}return!PrivateKey.getValidationError(data,network)};PrivateKey.prototype.toString=function(){return this.toBuffer().toString("hex")};PrivateKey.prototype.toWIF=function(){var network=this.network;var compressed=this.compressed;var buf;if(compressed){buf=Buffer.concat([Buffer.from([network.privatekey]),this.bn.toBuffer({size:32}),Buffer.from([1])])}else{buf=Buffer.concat([Buffer.from([network.privatekey]),this.bn.toBuffer({size:32})])}return Base58Check.encode(buf)};PrivateKey.prototype.toBigNumber=function(){return this.bn};PrivateKey.prototype.toBuffer=function(){return this.bn.toBuffer({size:32})};PrivateKey.prototype.toBufferNoPadding=function(){return this.bn.toBuffer()};PrivateKey.prototype.toPublicKey=function(){if(!this._pubkey){this._pubkey=PublicKey.fromPrivateKey(this)}return this._pubkey};PrivateKey.prototype.toAddress=function(network){var pubkey=this.toPublicKey();return Address.fromPublicKey(pubkey,network||this.network)};PrivateKey.prototype.toObject=PrivateKey.prototype.toJSON=function toObject(){return{bn:this.bn.toString("hex"),compressed:this.compressed,network:this.network.toString()}};PrivateKey.prototype.inspect=function(){var uncompressed=!this.compressed?", uncompressed":"";return""};module.exports=PrivateKey}).call(this)}).call(this,require("buffer").Buffer)},{"./address":1,"./crypto/bn":7,"./crypto/point":10,"./crypto/random":11,"./encoding/base58check":14,"./networks":23,"./publickey":26,"./util/js":46,"./util/preconditions":47,buffer:159,lodash:84}],26:[function(require,module,exports){(function(Buffer){(function(){"use strict";var BN=require("./crypto/bn");var Point=require("./crypto/point");var Hash=require("./crypto/hash");var JSUtil=require("./util/js");var Network=require("./networks");var _=require("lodash");var $=require("./util/preconditions");function PublicKey(data,extra){if(!(this instanceof PublicKey)){return new PublicKey(data,extra)}$.checkArgument(data,"First argument is required, please include public key data.");if(data instanceof PublicKey){return data}extra=extra||{};var info=this._classifyArgs(data,extra);info.point.validate();JSUtil.defineImmutable(this,{point:info.point,compressed:info.compressed,network:info.network||Network.defaultNetwork});return this}PublicKey.prototype._classifyArgs=function(data,extra){var info={compressed:_.isUndefined(extra.compressed)||extra.compressed};if(data instanceof Point){info.point=data}else if(data.x&&data.y){info=PublicKey._transformObject(data)}else if(typeof data==="string"){info=PublicKey._transformDER(Buffer.from(data,"hex"))}else if(PublicKey._isBuffer(data)){info=PublicKey._transformDER(data)}else if(PublicKey._isPrivateKey(data)){info=PublicKey._transformPrivateKey(data)}else{throw new TypeError("First argument is an unrecognized data format.")}if(!info.network){info.network=_.isUndefined(extra.network)?undefined:Network.get(extra.network)}return info};PublicKey._isPrivateKey=function(param){var PrivateKey=require("./privatekey");return param instanceof PrivateKey};PublicKey._isBuffer=function(param){return param instanceof Buffer||param instanceof Uint8Array};PublicKey._transformPrivateKey=function(privkey){$.checkArgument(PublicKey._isPrivateKey(privkey),"Must be an instance of PrivateKey");var info={};info.point=Point.getG().mul(privkey.bn);info.compressed=privkey.compressed;info.network=privkey.network;return info};PublicKey._transformDER=function(buf,strict){$.checkArgument(PublicKey._isBuffer(buf),"Must be a hex buffer of DER encoded public key");var info={};strict=_.isUndefined(strict)?true:strict;var x;var y;var xbuf;var ybuf;if(buf[0]===4||!strict&&(buf[0]===6||buf[0]===7)){xbuf=buf.slice(1,33);ybuf=buf.slice(33,65);if(xbuf.length!==32||ybuf.length!==32||buf.length!==65){throw new TypeError("Length of x and y must be 32 bytes")}x=new BN(xbuf);y=new BN(ybuf);info.point=new Point(x,y);info.compressed=false}else if(buf[0]===3){xbuf=buf.slice(1);x=new BN(xbuf);info=PublicKey._transformX(true,x);info.compressed=true}else if(buf[0]===2){xbuf=buf.slice(1);x=new BN(xbuf);info=PublicKey._transformX(false,x);info.compressed=true}else{throw new TypeError("Invalid DER format public key")}return info};PublicKey._transformX=function(odd,x){$.checkArgument(typeof odd==="boolean","Must specify whether y is odd or not (true or false)");var info={};info.point=Point.fromX(odd,x);return info};PublicKey._transformObject=function(json){var x=new BN(json.x,"hex");var y=new BN(json.y,"hex");var point=new Point(x,y);return new PublicKey(point,{compressed:json.compressed})};PublicKey.fromPrivateKey=function(privkey){$.checkArgument(PublicKey._isPrivateKey(privkey),"Must be an instance of PrivateKey");var info=PublicKey._transformPrivateKey(privkey);return new PublicKey(info.point,{compressed:info.compressed,network:info.network})};PublicKey.fromDER=PublicKey.fromBuffer=function(buf,strict){$.checkArgument(PublicKey._isBuffer(buf),"Must be a hex buffer of DER encoded public key");var info=PublicKey._transformDER(buf,strict);return new PublicKey(info.point,{compressed:info.compressed})};PublicKey.fromPoint=function(point,compressed){$.checkArgument(point instanceof Point,"First argument must be an instance of Point.");return new PublicKey(point,{compressed:compressed})};PublicKey.fromString=function(str,encoding){var buf=Buffer.from(str,encoding||"hex");var info=PublicKey._transformDER(buf);return new PublicKey(info.point,{compressed:info.compressed})};PublicKey.fromX=function(odd,x){var info=PublicKey._transformX(odd,x);return new PublicKey(info.point,{compressed:info.compressed})};PublicKey.getValidationError=function(data){var error;try{new PublicKey(data)}catch(e){error=e}return error};PublicKey.isValid=function(data){return!PublicKey.getValidationError(data)};PublicKey.prototype.toObject=PublicKey.prototype.toJSON=function toObject(){return{x:this.point.getX().toString("hex",2),y:this.point.getY().toString("hex",2),compressed:this.compressed}};PublicKey.prototype.toBuffer=PublicKey.prototype.toDER=function(){var x=this.point.getX();var y=this.point.getY();var xbuf=x.toBuffer({size:32});var ybuf=y.toBuffer({size:32});var prefix;if(!this.compressed){prefix=Buffer.from([4]);return Buffer.concat([prefix,xbuf,ybuf])}else{var odd=ybuf[ybuf.length-1]%2;if(odd){prefix=Buffer.from([3])}else{prefix=Buffer.from([2])}return Buffer.concat([prefix,xbuf])}};PublicKey.prototype._getID=function _getID(){return Hash.sha256ripemd160(this.toBuffer())};PublicKey.prototype.toAddress=function(network){var Address=require("./address");return Address.fromPublicKey(this,network||this.network)};PublicKey.prototype.toString=function(){return this.toDER().toString("hex")};PublicKey.prototype.inspect=function(){return""};module.exports=PublicKey}).call(this)}).call(this,require("buffer").Buffer)},{"./address":1,"./crypto/bn":7,"./crypto/hash":9,"./crypto/point":10,"./networks":23,"./privatekey":25,"./util/js":46,"./util/preconditions":47,buffer:159,lodash:84}],27:[function(require,module,exports){module.exports=require("./script");module.exports.Interpreter=require("./interpreter")},{"./interpreter":28,"./script":29}],28:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var Script=require("./script");var Opcode=require("../opcode");var BN=require("../crypto/bn");var Hash=require("../crypto/hash");var Signature=require("../crypto/signature");var PublicKey=require("../publickey");var Interpreter=function Interpreter(obj){if(!(this instanceof Interpreter)){return new Interpreter(obj)}if(obj){this.initialize();this.set(obj)}else{this.initialize()}};Interpreter.prototype.verifyWitnessProgram=function(version,program,witness,satoshis,flags){var scriptPubKey=new Script;var stack=[];if(version===0){if(program.length===32){if(witness.length===0){this.errstr="SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY";return false}var scriptPubKeyBuffer=witness[witness.length-1];scriptPubKey=new Script(scriptPubKeyBuffer);var hash=Hash.sha256(scriptPubKeyBuffer);if(hash.toString("hex")!==program.toString("hex")){this.errstr="SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH";return false}stack=witness.slice(0,-1)}else if(program.length===20){if(witness.length!==2){this.errstr="SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH";return false}scriptPubKey.add(Opcode.OP_DUP);scriptPubKey.add(Opcode.OP_HASH160);scriptPubKey.add(program);scriptPubKey.add(Opcode.OP_EQUALVERIFY);scriptPubKey.add(Opcode.OP_CHECKSIG);stack=witness}else{this.errstr="SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH";return false}}else if(flags&Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM){this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM";return false}else{return true}this.initialize();this.set({script:scriptPubKey,stack:stack,sigversion:Interpreter.SIGVERSION_WITNESS_V0,satoshis:satoshis,flags:flags});for(let s of stack){if(s.length>Interpreter.MAX_SCRIPT_ELEMENT_SIZE){this.errstr="SCRIPT_ERR_PUSH_SIZE";return false}}if(!this.evaluate()){return false}if(this.stack.length!==1){this.errstr="SCRIPT_ERR_EVAL_FALSE";return false}var buf=this.stack[this.stack.length-1];if(!Interpreter.castToBool(buf)){this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_STACK";return false}return true};Interpreter.prototype.verify=function(scriptSig,scriptPubkey,tx,nin,flags,witness,satoshis){var Transaction=require("../transaction");if(_.isUndefined(tx)){tx=new Transaction}if(_.isUndefined(nin)){nin=0}if(_.isUndefined(flags)){flags=0}if(_.isUndefined(witness)){witness=null}if(_.isUndefined(satoshis)){satoshis=0}this.set({script:scriptSig,tx:tx,nin:nin,sigversion:Interpreter.SIGVERSION_BASE,satoshis:0,flags:flags});var stackCopy;if((flags&Interpreter.SCRIPT_VERIFY_SIGPUSHONLY)!==0&&!scriptSig.isPushOnly()){this.errstr="SCRIPT_ERR_SIG_PUSHONLY";return false}if(!this.evaluate()){return false}if(flags&Interpreter.SCRIPT_VERIFY_P2SH){stackCopy=this.stack.slice()}var stack=this.stack;this.initialize();this.set({script:scriptPubkey,stack:stack,tx:tx,nin:nin,flags:flags});if(!this.evaluate()){return false}if(this.stack.length===0){this.errstr="SCRIPT_ERR_EVAL_FALSE_NO_RESULT";return false}var buf=this.stack[this.stack.length-1];if(!Interpreter.castToBool(buf)){this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_STACK";return false}var hadWitness=false;if(flags&Interpreter.SCRIPT_VERIFY_WITNESS){var witnessValues={};if(scriptPubkey.isWitnessProgram(witnessValues)){hadWitness=true;if(scriptSig.toBuffer().length!==0){return false}if(!this.verifyWitnessProgram(witnessValues.version,witnessValues.program,witness,satoshis,this.flags)){return false}}}if(flags&Interpreter.SCRIPT_VERIFY_P2SH&&scriptPubkey.isScriptHashOut()){if(!scriptSig.isPushOnly()){this.errstr="SCRIPT_ERR_SIG_PUSHONLY";return false}if(stackCopy.length===0){throw new Error("internal error - stack copy empty")}var redeemScriptSerialized=stackCopy[stackCopy.length-1];var redeemScript=Script.fromBuffer(redeemScriptSerialized);stackCopy.pop();this.initialize();this.set({script:redeemScript,stack:stackCopy,tx:tx,nin:nin,flags:flags});if(!this.evaluate()){return false}if(stackCopy.length===0){this.errstr="SCRIPT_ERR_EVAL_FALSE_NO_P2SH_STACK";return false}if(!Interpreter.castToBool(stackCopy[stackCopy.length-1])){this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_P2SH_STACK";return false}if(flags&Interpreter.SCRIPT_VERIFY_WITNESS){var p2shWitnessValues={};if(redeemScript.isWitnessProgram(p2shWitnessValues)){hadWitness=true;var redeemScriptPush=new Script;redeemScriptPush.add(redeemScript.toBuffer());if(scriptSig.toHex()!==redeemScriptPush.toHex()){this.errstr="SCRIPT_ERR_WITNESS_MALLEATED_P2SH";return false}if(!this.verifyWitnessProgram(p2shWitnessValues.version,p2shWitnessValues.program,witness,satoshis,this.flags)){return false}stack=[stack[0]]}}}if((this.flags&Interpreter.SCRIPT_VERIFY_CLEANSTACK)!=0){if((this.flags&Interpreter.SCRIPT_VERIFY_P2SH)==0)throw"flags & SCRIPT_VERIFY_P2SH";if(stackCopy.length!=1){this.errstr="SCRIPT_ERR_CLEANSTACK";return false}}if(this.flags&Interpreter.SCRIPT_VERIFY_WITNESS){if(!hadWitness&&witness.length>0){this.errstr="SCRIPT_ERR_WITNESS_UNEXPECTED";return false}}return true};module.exports=Interpreter;Interpreter.prototype.initialize=function(obj){this.stack=[];this.altstack=[];this.pc=0;this.satoshis=0;this.sigversion=Interpreter.SIGVERSION_BASE;this.pbegincodehash=0;this.nOpCount=0;this.vfExec=[];this.errstr="";this.flags=0};Interpreter.prototype.set=function(obj){this.script=obj.script||this.script;this.tx=obj.tx||this.tx;this.nin=typeof obj.nin!=="undefined"?obj.nin:this.nin;this.stack=obj.stack||this.stack;this.altstack=obj.altack||this.altstack;this.pc=typeof obj.pc!=="undefined"?obj.pc:this.pc;this.pbegincodehash=typeof obj.pbegincodehash!=="undefined"?obj.pbegincodehash:this.pbegincodehash;this.sigversion=typeof obj.sigversion!=="undefined"?obj.sigversion:this.sigversion;this.satoshis=typeof obj.satoshis!=="undefined"?obj.satoshis:this.satoshis;this.nOpCount=typeof obj.nOpCount!=="undefined"?obj.nOpCount:this.nOpCount;this.vfExec=obj.vfExec||this.vfExec;this.errstr=obj.errstr||this.errstr;this.flags=typeof obj.flags!=="undefined"?obj.flags:this.flags};Interpreter.true=Buffer.from([1]);Interpreter.false=Buffer.from([]);Interpreter.MAX_SCRIPT_ELEMENT_SIZE=520;Interpreter.LOCKTIME_THRESHOLD=5e8;Interpreter.LOCKTIME_THRESHOLD_BN=new BN(Interpreter.LOCKTIME_THRESHOLD);Interpreter.SCRIPT_VERIFY_NONE=0;Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM=1<<12;Interpreter.SCRIPT_VERIFY_P2SH=1<<0;Interpreter.SCRIPT_VERIFY_STRICTENC=1<<1;Interpreter.SCRIPT_VERIFY_DERSIG=1<<2;Interpreter.SCRIPT_VERIFY_LOW_S=1<<3;Interpreter.SCRIPT_VERIFY_NULLDUMMY=1<<4;Interpreter.SCRIPT_VERIFY_SIGPUSHONLY=1<<5;Interpreter.SCRIPT_VERIFY_MINIMALDATA=1<<6;Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS=1<<7;Interpreter.SCRIPT_VERIFY_CLEANSTACK=1<<8,Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY=1<<9;Interpreter.SCRIPT_VERIFY_WITNESS=1<<11;Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS=1<<11;Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY=1<<10;Interpreter.SCRIPT_VERIFY_MINIMALIF=1<<13;Interpreter.SCRIPT_VERIFY_NULLFAIL=1<<14;Interpreter.SCRIPT_VERIFY_WITNESS_PUBKEYTYPE=1<<15;Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID=1<<16;Interpreter.SCRIPT_ENABLE_REPLAY_PROTECTION=1<<17;Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES=1<<18;Interpreter.SEQUENCE_LOCKTIME_DISABLE_FLAG=1<<31;Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG=1<<22;Interpreter.SEQUENCE_LOCKTIME_MASK=65535;Interpreter.SIGVERSION_BASE=0;Interpreter.SIGVERSION_WITNESS_V0=1;Interpreter.castToBool=function(buf){for(var i=0;i1e4){this.errstr="SCRIPT_ERR_SCRIPT_SIZE";return false}try{while(this.pc1e3){this.errstr="SCRIPT_ERR_STACK_SIZE";return false}}catch(e){this.errstr="SCRIPT_ERR_UNKNOWN_ERROR: "+e;return false}if(this.vfExec.length>0){this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL";return false}return true};Interpreter.prototype.checkLockTime=function(nLockTime){if(!(this.tx.nLockTime=Interpreter.LOCKTIME_THRESHOLD&&nLockTime.gte(Interpreter.LOCKTIME_THRESHOLD_BN))){return false}if(nLockTime.gt(new BN(this.tx.nLockTime))){return false}if(!this.tx.inputs[this.nin].isFinal()){return false}return true};Interpreter.prototype.checkSequence=function(nSequence){var txToSequence=this.tx.inputs[this.nin].sequenceNumber;if(this.tx.version<2){return false}var SEQUENCE_LOCKTIME_DISABLE_FLAG=Interpreter.SEQUENCE_LOCKTIME_DISABLE_FLAG;if(txToSequence&SEQUENCE_LOCKTIME_DISABLE_FLAG){return false}var nLockTimeMask=Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG|Interpreter.SEQUENCE_LOCKTIME_MASK;var txToSequenceMasked=new BN(txToSequence&nLockTimeMask);var nSequenceMasked=nSequence.and(new BN(nLockTimeMask));var SEQUENCE_LOCKTIME_TYPE_FLAG_BN=new BN(Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG);if(!(txToSequenceMasked.lt(SEQUENCE_LOCKTIME_TYPE_FLAG_BN)&&nSequenceMasked.lt(SEQUENCE_LOCKTIME_TYPE_FLAG_BN)||txToSequenceMasked.gte(SEQUENCE_LOCKTIME_TYPE_FLAG_BN)&&nSequenceMasked.gte(SEQUENCE_LOCKTIME_TYPE_FLAG_BN))){return false}if(nSequenceMasked.gt(txToSequenceMasked)){return false}return true};Interpreter.prototype.step=function(){var fRequireMinimal=(this.flags&Interpreter.SCRIPT_VERIFY_MINIMALDATA)!==0;var fExec=this.vfExec.indexOf(false)===-1;var buf,buf1,buf2,spliced,n,x1,x2,bn,bn1,bn2,bufSig,bufPubkey,subscript;var sig,pubkey;var fValue,fSuccess;var chunk=this.script.chunks[this.pc];this.pc++;var opcodenum=chunk.opcodenum;if(_.isUndefined(opcodenum)){this.errstr="SCRIPT_ERR_UNDEFINED_OPCODE";return false}if(chunk.buf&&chunk.buf.length>Interpreter.MAX_SCRIPT_ELEMENT_SIZE){this.errstr="SCRIPT_ERR_PUSH_SIZE";return false}if(opcodenum>Opcode.OP_16&&++this.nOpCount>201){this.errstr="SCRIPT_ERR_OP_COUNT";return false}if(opcodenum===Opcode.OP_CAT||opcodenum===Opcode.OP_SUBSTR||opcodenum===Opcode.OP_LEFT||opcodenum===Opcode.OP_RIGHT||opcodenum===Opcode.OP_INVERT||opcodenum===Opcode.OP_AND||opcodenum===Opcode.OP_OR||opcodenum===Opcode.OP_XOR||opcodenum===Opcode.OP_2MUL||opcodenum===Opcode.OP_2DIV||opcodenum===Opcode.OP_MUL||opcodenum===Opcode.OP_DIV||opcodenum===Opcode.OP_MOD||opcodenum===Opcode.OP_LSHIFT||opcodenum===Opcode.OP_RSHIFT){this.errstr="SCRIPT_ERR_DISABLED_OPCODE";return false}if(fExec&&0<=opcodenum&&opcodenum<=Opcode.OP_PUSHDATA4){if(fRequireMinimal&&!this.script.checkMinimalPush(this.pc-1)){this.errstr="SCRIPT_ERR_MINIMALDATA";return false}if(!chunk.buf){this.stack.push(Interpreter.false)}else if(chunk.len!==chunk.buf.length){throw new Error("Length of push value not equal to length of data")}else{this.stack.push(chunk.buf)}}else if(fExec||Opcode.OP_IF<=opcodenum&&opcodenum<=Opcode.OP_ENDIF){switch(opcodenum){case Opcode.OP_1NEGATE:case Opcode.OP_1:case Opcode.OP_2:case Opcode.OP_3:case Opcode.OP_4:case Opcode.OP_5:case Opcode.OP_6:case Opcode.OP_7:case Opcode.OP_8:case Opcode.OP_9:case Opcode.OP_10:case Opcode.OP_11:case Opcode.OP_12:case Opcode.OP_13:case Opcode.OP_14:case Opcode.OP_15:case Opcode.OP_16:{n=opcodenum-(Opcode.OP_1-1);buf=new BN(n).toScriptNumBuffer();this.stack.push(buf)}break;case Opcode.OP_NOP:break;case Opcode.OP_NOP2:case Opcode.OP_CHECKLOCKTIMEVERIFY:if(!(this.flags&Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY)){if(this.flags&Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS){this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS";return false}break}if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}var nLockTime=BN.fromScriptNumBuffer(this.stack[this.stack.length-1],fRequireMinimal,5);if(nLockTime.lt(new BN(0))){this.errstr="SCRIPT_ERR_NEGATIVE_LOCKTIME";return false}if(!this.checkLockTime(nLockTime)){this.errstr="SCRIPT_ERR_UNSATISFIED_LOCKTIME";return false}break;case Opcode.OP_NOP3:case Opcode.OP_CHECKSEQUENCEVERIFY:if(!(this.flags&Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY)){if(this.flags&Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS){this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS";return false}break}if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}var nSequence=BN.fromScriptNumBuffer(this.stack[this.stack.length-1],fRequireMinimal,5);if(nSequence.lt(new BN(0))){this.errstr="SCRIPT_ERR_NEGATIVE_LOCKTIME";return false}if((nSequence&Interpreter.SEQUENCE_LOCKTIME_DISABLE_FLAG)!=0){break}if(!this.checkSequence(nSequence)){this.errstr="SCRIPT_ERR_UNSATISFIED_LOCKTIME";return false}break;case Opcode.OP_NOP1:case Opcode.OP_NOP4:case Opcode.OP_NOP5:case Opcode.OP_NOP6:case Opcode.OP_NOP7:case Opcode.OP_NOP8:case Opcode.OP_NOP9:case Opcode.OP_NOP10:{if(this.flags&Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS){this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS";return false}}break;case Opcode.OP_IF:case Opcode.OP_NOTIF:{fValue=false;if(fExec){if(this.stack.length<1){this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL";return false}buf=this.stack[this.stack.length-1];if(this.flags&Interpreter.SCRIPT_VERIFY_MINIMALIF){buf=this.stack[this.stack.length-1];if(buf.length>1){this.errstr="SCRIPT_ERR_MINIMALIF";return false}if(buf.length==1&&buf[0]!=1){this.errstr="SCRIPT_ERR_MINIMALIF";return false}}fValue=Interpreter.castToBool(buf);if(opcodenum===Opcode.OP_NOTIF){fValue=!fValue}this.stack.pop()}this.vfExec.push(fValue)}break;case Opcode.OP_ELSE:{if(this.vfExec.length===0){this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL";return false}this.vfExec[this.vfExec.length-1]=!this.vfExec[this.vfExec.length-1]}break;case Opcode.OP_ENDIF:{if(this.vfExec.length===0){this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL";return false}this.vfExec.pop()}break;case Opcode.OP_VERIFY:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];fValue=Interpreter.castToBool(buf);if(fValue){this.stack.pop()}else{this.errstr="SCRIPT_ERR_VERIFY";return false}}break;case Opcode.OP_RETURN:{this.errstr="SCRIPT_ERR_OP_RETURN";return false}break;case Opcode.OP_TOALTSTACK:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.altstack.push(this.stack.pop())}break;case Opcode.OP_FROMALTSTACK:{if(this.altstack.length<1){this.errstr="SCRIPT_ERR_INVALID_ALTSTACK_OPERATION";return false}this.stack.push(this.altstack.pop())}break;case Opcode.OP_2DROP:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.pop();this.stack.pop()}break;case Opcode.OP_2DUP:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf1=this.stack[this.stack.length-2];buf2=this.stack[this.stack.length-1];this.stack.push(buf1);this.stack.push(buf2)}break;case Opcode.OP_3DUP:{if(this.stack.length<3){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf1=this.stack[this.stack.length-3];buf2=this.stack[this.stack.length-2];var buf3=this.stack[this.stack.length-1];this.stack.push(buf1);this.stack.push(buf2);this.stack.push(buf3)}break;case Opcode.OP_2OVER:{if(this.stack.length<4){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf1=this.stack[this.stack.length-4];buf2=this.stack[this.stack.length-3];this.stack.push(buf1);this.stack.push(buf2)}break;case Opcode.OP_2ROT:{if(this.stack.length<6){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}spliced=this.stack.splice(this.stack.length-6,2);this.stack.push(spliced[0]);this.stack.push(spliced[1])}break;case Opcode.OP_2SWAP:{if(this.stack.length<4){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}spliced=this.stack.splice(this.stack.length-4,2);this.stack.push(spliced[0]);this.stack.push(spliced[1])}break;case Opcode.OP_IFDUP:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];fValue=Interpreter.castToBool(buf);if(fValue){this.stack.push(buf)}}break;case Opcode.OP_DEPTH:{buf=new BN(this.stack.length).toScriptNumBuffer();this.stack.push(buf)}break;case Opcode.OP_DROP:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.pop()}break;case Opcode.OP_DUP:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.push(this.stack[this.stack.length-1])}break;case Opcode.OP_NIP:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.splice(this.stack.length-2,1)}break;case Opcode.OP_OVER:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.push(this.stack[this.stack.length-2])}break;case Opcode.OP_PICK:case Opcode.OP_ROLL:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];bn=BN.fromScriptNumBuffer(buf,fRequireMinimal);n=bn.toNumber();this.stack.pop();if(n<0||n>=this.stack.length){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-n-1];if(opcodenum===Opcode.OP_ROLL){this.stack.splice(this.stack.length-n-1,1)}this.stack.push(buf)}break;case Opcode.OP_ROT:{if(this.stack.length<3){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}x1=this.stack[this.stack.length-3];x2=this.stack[this.stack.length-2];var x3=this.stack[this.stack.length-1];this.stack[this.stack.length-3]=x2;this.stack[this.stack.length-2]=x3;this.stack[this.stack.length-1]=x1}break;case Opcode.OP_SWAP:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}x1=this.stack[this.stack.length-2];x2=this.stack[this.stack.length-1];this.stack[this.stack.length-2]=x2;this.stack[this.stack.length-1]=x1}break;case Opcode.OP_TUCK:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.splice(this.stack.length-2,0,this.stack[this.stack.length-1])}break;case Opcode.OP_SIZE:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}bn=new BN(this.stack[this.stack.length-1].length);this.stack.push(bn.toScriptNumBuffer())}break;case Opcode.OP_EQUAL:case Opcode.OP_EQUALVERIFY:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf1=this.stack[this.stack.length-2];buf2=this.stack[this.stack.length-1];var fEqual=buf1.toString("hex")===buf2.toString("hex");this.stack.pop();this.stack.pop();this.stack.push(fEqual?Interpreter.true:Interpreter.false);if(opcodenum===Opcode.OP_EQUALVERIFY){if(fEqual){this.stack.pop()}else{this.errstr="SCRIPT_ERR_EQUALVERIFY";return false}}}break;case Opcode.OP_1ADD:case Opcode.OP_1SUB:case Opcode.OP_NEGATE:case Opcode.OP_ABS:case Opcode.OP_NOT:case Opcode.OP_0NOTEQUAL:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];bn=BN.fromScriptNumBuffer(buf,fRequireMinimal);switch(opcodenum){case Opcode.OP_1ADD:bn=bn.add(BN.One);break;case Opcode.OP_1SUB:bn=bn.sub(BN.One);break;case Opcode.OP_NEGATE:bn=bn.neg();break;case Opcode.OP_ABS:if(bn.cmp(BN.Zero)<0){bn=bn.neg()}break;case Opcode.OP_NOT:bn=new BN((bn.cmp(BN.Zero)===0)+0);break;case Opcode.OP_0NOTEQUAL:bn=new BN((bn.cmp(BN.Zero)!==0)+0);break}this.stack.pop();this.stack.push(bn.toScriptNumBuffer())}break;case Opcode.OP_ADD:case Opcode.OP_SUB:case Opcode.OP_BOOLAND:case Opcode.OP_BOOLOR:case Opcode.OP_NUMEQUAL:case Opcode.OP_NUMEQUALVERIFY:case Opcode.OP_NUMNOTEQUAL:case Opcode.OP_LESSTHAN:case Opcode.OP_GREATERTHAN:case Opcode.OP_LESSTHANOREQUAL:case Opcode.OP_GREATERTHANOREQUAL:case Opcode.OP_MIN:case Opcode.OP_MAX:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}bn1=BN.fromScriptNumBuffer(this.stack[this.stack.length-2],fRequireMinimal);bn2=BN.fromScriptNumBuffer(this.stack[this.stack.length-1],fRequireMinimal);bn=new BN(0);switch(opcodenum){case Opcode.OP_ADD:bn=bn1.add(bn2);break;case Opcode.OP_SUB:bn=bn1.sub(bn2);break;case Opcode.OP_BOOLAND:bn=new BN((bn1.cmp(BN.Zero)!==0&&bn2.cmp(BN.Zero)!==0)+0);break;case Opcode.OP_BOOLOR:bn=new BN((bn1.cmp(BN.Zero)!==0||bn2.cmp(BN.Zero)!==0)+0);break;case Opcode.OP_NUMEQUAL:bn=new BN((bn1.cmp(bn2)===0)+0);break;case Opcode.OP_NUMEQUALVERIFY:bn=new BN((bn1.cmp(bn2)===0)+0);break;case Opcode.OP_NUMNOTEQUAL:bn=new BN((bn1.cmp(bn2)!==0)+0);break;case Opcode.OP_LESSTHAN:bn=new BN((bn1.cmp(bn2)<0)+0);break;case Opcode.OP_GREATERTHAN:bn=new BN((bn1.cmp(bn2)>0)+0);break;case Opcode.OP_LESSTHANOREQUAL:bn=new BN((bn1.cmp(bn2)<=0)+0);break;case Opcode.OP_GREATERTHANOREQUAL:bn=new BN((bn1.cmp(bn2)>=0)+0);break;case Opcode.OP_MIN:bn=bn1.cmp(bn2)<0?bn1:bn2;break;case Opcode.OP_MAX:bn=bn1.cmp(bn2)>0?bn1:bn2;break}this.stack.pop();this.stack.pop();this.stack.push(bn.toScriptNumBuffer());if(opcodenum===Opcode.OP_NUMEQUALVERIFY){if(Interpreter.castToBool(this.stack[this.stack.length-1])){this.stack.pop()}else{this.errstr="SCRIPT_ERR_NUMEQUALVERIFY";return false}}}break;case Opcode.OP_WITHIN:{if(this.stack.length<3){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}bn1=BN.fromScriptNumBuffer(this.stack[this.stack.length-3],fRequireMinimal);bn2=BN.fromScriptNumBuffer(this.stack[this.stack.length-2],fRequireMinimal);var bn3=BN.fromScriptNumBuffer(this.stack[this.stack.length-1],fRequireMinimal);fValue=bn2.cmp(bn1)<=0&&bn1.cmp(bn3)<0;this.stack.pop();this.stack.pop();this.stack.pop();this.stack.push(fValue?Interpreter.true:Interpreter.false)}break;case Opcode.OP_RIPEMD160:case Opcode.OP_SHA1:case Opcode.OP_SHA256:case Opcode.OP_HASH160:case Opcode.OP_HASH256:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];var bufHash;if(opcodenum===Opcode.OP_RIPEMD160){bufHash=Hash.ripemd160(buf)}else if(opcodenum===Opcode.OP_SHA1){bufHash=Hash.sha1(buf)}else if(opcodenum===Opcode.OP_SHA256){bufHash=Hash.sha256(buf)}else if(opcodenum===Opcode.OP_HASH160){bufHash=Hash.sha256ripemd160(buf)}else if(opcodenum===Opcode.OP_HASH256){bufHash=Hash.sha256sha256(buf)}this.stack.pop();this.stack.push(bufHash)}break;case Opcode.OP_CODESEPARATOR:{this.pbegincodehash=this.pc}break;case Opcode.OP_CHECKSIG:case Opcode.OP_CHECKSIGVERIFY:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}bufSig=this.stack[this.stack.length-2];bufPubkey=this.stack[this.stack.length-1];if(!this.checkSignatureEncoding(bufSig)||!this.checkPubkeyEncoding(bufPubkey)){return false}subscript=(new Script).set({chunks:this.script.chunks.slice(this.pbegincodehash)});if(this.sigversion===Interpreter.SIGVERSION_BASE){var tmpScript=(new Script).add(bufSig);subscript.findAndDelete(tmpScript)}try{sig=Signature.fromTxFormat(bufSig);pubkey=PublicKey.fromBuffer(bufPubkey,false);fSuccess=this.tx.verifySignature(sig,pubkey,this.nin,subscript,this.sigversion,this.satoshis)}catch(e){fSuccess=false}if(!fSuccess&&this.flags&Interpreter.SCRIPT_VERIFY_NULLFAIL&&bufSig.length){this.errstr="SCRIPT_ERR_NULLFAIL";return false}this.stack.pop();this.stack.pop();this.stack.push(fSuccess?Interpreter.true:Interpreter.false);if(opcodenum===Opcode.OP_CHECKSIGVERIFY){if(fSuccess){this.stack.pop()}else{this.errstr="SCRIPT_ERR_CHECKSIGVERIFY";return false}}}break;case Opcode.OP_CHECKMULTISIG:case Opcode.OP_CHECKMULTISIGVERIFY:{var i=1;if(this.stack.length20){this.errstr="SCRIPT_ERR_PUBKEY_COUNT";return false}this.nOpCount+=nKeysCount;if(this.nOpCount>201){this.errstr="SCRIPT_ERR_OP_COUNT";return false}var ikey=++i;i+=nKeysCount;var ikey2=nKeysCount+2;if(this.stack.lengthnKeysCount){this.errstr="SCRIPT_ERR_SIG_COUNT";return false}var isig=++i;i+=nSigsCount;if(this.stack.length0){bufSig=this.stack[this.stack.length-isig];bufPubkey=this.stack[this.stack.length-ikey];if(!this.checkSignatureEncoding(bufSig)||!this.checkPubkeyEncoding(bufPubkey)){return false}var fOk;try{sig=Signature.fromTxFormat(bufSig);pubkey=PublicKey.fromBuffer(bufPubkey,false);fOk=this.tx.verifySignature(sig,pubkey,this.nin,subscript,this.sigversion,this.satoshis)}catch(e){fOk=false}if(fOk){isig++;nSigsCount--}ikey++;nKeysCount--;if(nSigsCount>nKeysCount){fSuccess=false}}while(i-- >1){if(!fSuccess&&this.flags&Interpreter.SCRIPT_VERIFY_NULLFAIL&&!ikey2&&this.stack[this.stack.length-1].length){this.errstr="SCRIPT_ERR_NULLFAIL";return false}if(ikey2>0){ikey2--}this.stack.pop()}if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}if(this.flags&Interpreter.SCRIPT_VERIFY_NULLDUMMY&&this.stack[this.stack.length-1].length){this.errstr="SCRIPT_ERR_SIG_NULLDUMMY";return false}this.stack.pop();this.stack.push(fSuccess?Interpreter.true:Interpreter.false);if(opcodenum===Opcode.OP_CHECKMULTISIGVERIFY){if(fSuccess){this.stack.pop()}else{this.errstr="SCRIPT_ERR_CHECKMULTISIGVERIFY";return false}}}break;default:this.errstr="SCRIPT_ERR_BAD_OPCODE";return false}}return true}}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/bn":7,"../crypto/hash":9,"../crypto/signature":12,"../opcode":24,"../publickey":26,"../transaction":30,"./script":29,buffer:159,lodash:84}],29:[function(require,module,exports){(function(Buffer){(function(){"use strict";var Address=require("../address");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var Opcode=require("../opcode");var PublicKey=require("../publickey");var Signature=require("../crypto/signature");var Networks=require("../networks");var $=require("../util/preconditions");var _=require("lodash");var errors=require("../errors");var buffer=require("buffer");var BufferUtil=require("../util/buffer");var JSUtil=require("../util/js");var Script=function Script(from){if(!(this instanceof Script)){return new Script(from)}this.chunks=[];if(BufferUtil.isBuffer(from)){return Script.fromBuffer(from)}else if(from instanceof Address){return Script.fromAddress(from)}else if(from instanceof Script){return Script.fromBuffer(from.toBuffer())}else if(_.isString(from)){return Script.fromString(from)}else if(_.isObject(from)&&_.isArray(from.chunks)){this.set(from)}};Script.prototype.set=function(obj){$.checkArgument(_.isObject(obj));$.checkArgument(_.isArray(obj.chunks));this.chunks=obj.chunks;return this};Script.fromBuffer=function(buffer){var script=new Script;script.chunks=[];var br=new BufferReader(buffer);while(!br.finished()){try{var opcodenum=br.readUInt8();var len,buf;if(opcodenum>0&&opcodenum0&&opcodenum0){if(asm){str=str+" "+chunk.buf.toString("hex")}else{str=str+" "+chunk.len+" "+"0x"+chunk.buf.toString("hex")}}}return str};Script.prototype.toASM=function(){var str="";for(var i=0;i"};Script.prototype.isPublicKeyHashOut=function(){return!!(this.chunks.length===5&&this.chunks[0].opcodenum===Opcode.OP_DUP&&this.chunks[1].opcodenum===Opcode.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===Opcode.OP_EQUALVERIFY&&this.chunks[4].opcodenum===Opcode.OP_CHECKSIG)};Script.prototype.isPublicKeyHashIn=function(){if(this.chunks.length===2){var signatureBuf=this.chunks[0].buf;var pubkeyBuf=this.chunks[1].buf;if(signatureBuf&&signatureBuf.length&&signatureBuf[0]===48&&pubkeyBuf&&pubkeyBuf.length){var version=pubkeyBuf[0];if((version===4||version===6||version===7)&&pubkeyBuf.length===65){return true}else if((version===3||version===2)&&pubkeyBuf.length===33){return true}}}return false};Script.prototype.getPublicKey=function(){$.checkState(this.isPublicKeyOut(),"Can't retrieve PublicKey from a non-PK output");return this.chunks[0].buf};Script.prototype.getPublicKeyHash=function(){if(this.isPublicKeyHashOut()){return this.chunks[2].buf}else{throw new Error("Can't retrieve PublicKeyHash from a non-PKH output")}};Script.prototype.isPublicKeyOut=function(){if(this.chunks.length===2&&this.chunks[0].buf&&this.chunks[0].buf.length&&this.chunks[1].opcodenum===Opcode.OP_CHECKSIG){var pubkeyBuf=this.chunks[0].buf;var version=pubkeyBuf[0];var isVersion=false;if((version===4||version===6||version===7)&&pubkeyBuf.length===65){isVersion=true}else if((version===3||version===2)&&pubkeyBuf.length===33){isVersion=true}if(isVersion){return PublicKey.isValid(pubkeyBuf)}}return false};Script.prototype.isPublicKeyIn=function(){if(this.chunks.length===1){var signatureBuf=this.chunks[0].buf;if(signatureBuf&&signatureBuf.length&&signatureBuf[0]===48){return true}}return false};Script.prototype.isScriptHashOut=function(){var buf=this.toBuffer();return buf.length===23&&buf[0]===Opcode.OP_HASH160&&buf[1]===20&&buf[buf.length-1]===Opcode.OP_EQUAL};Script.prototype.isWitnessProgram=function(values){if(!values){values={}}var buf=this.toBuffer();if(buf.length<4||buf.length>42){return false}if(buf[0]!==Opcode.OP_0&&!(buf[0]>=Opcode.OP_1&&buf[0]<=Opcode.OP_16)){return false}if(buf.length===buf[1]+2){values.version=buf[0];values.program=buf.slice(2,buf.length);return true}return false};Script.prototype.isScriptHashIn=function(){if(this.chunks.length<=1){return false}var redeemChunk=this.chunks[this.chunks.length-1];var redeemBuf=redeemChunk.buf;if(!redeemBuf){return false}var redeemScript;try{redeemScript=Script.fromBuffer(redeemBuf)}catch(e){if(e instanceof errors.Script.InvalidBuffer){return false}throw e}var type=redeemScript.classify();return type!==Script.types.UNKNOWN};Script.prototype.isMultisigOut=function(){return this.chunks.length>3&&Opcode.isSmallIntOp(this.chunks[0].opcodenum)&&this.chunks.slice(1,this.chunks.length-2).every(function(obj){return obj.buf&&BufferUtil.isBuffer(obj.buf)})&&Opcode.isSmallIntOp(this.chunks[this.chunks.length-2].opcodenum)&&this.chunks[this.chunks.length-1].opcodenum===Opcode.OP_CHECKMULTISIG};Script.prototype.isMultisigIn=function(){return this.chunks.length>=2&&this.chunks[0].opcodenum===0&&this.chunks.slice(1,this.chunks.length).every(function(obj){return obj.buf&&BufferUtil.isBuffer(obj.buf)&&Signature.isTxDER(obj.buf)})};Script.prototype.isDataOut=function(){return this.chunks.length>=1&&this.chunks[0].opcodenum===Opcode.OP_RETURN&&(this.chunks.length===1||this.chunks.length===2&&this.chunks[1].buf&&this.chunks[1].buf.length<=Script.OP_RETURN_STANDARD_SIZE&&this.chunks[1].length===this.chunks.len)};Script.prototype.getData=function(){if(this.isDataOut()||this.isScriptHashOut()){if(_.isUndefined(this.chunks[1])){return Buffer.alloc(0)}else{return Buffer.from(this.chunks[1].buf)}}if(this.isPublicKeyHashOut()){return Buffer.from(this.chunks[2].buf)}throw new Error("Unrecognized script type to get data from")};Script.prototype.isPushOnly=function(){return _.every(this.chunks,function(chunk){return chunk.opcodenum<=Opcode.OP_16})};Script.types={};Script.types.UNKNOWN="Unknown";Script.types.PUBKEY_OUT="Pay to public key";Script.types.PUBKEY_IN="Spend from public key";Script.types.PUBKEYHASH_OUT="Pay to public key hash";Script.types.PUBKEYHASH_IN="Spend from public key hash";Script.types.SCRIPTHASH_OUT="Pay to script hash";Script.types.SCRIPTHASH_IN="Spend from script hash";Script.types.MULTISIG_OUT="Pay to multisig";Script.types.MULTISIG_IN="Spend from multisig";Script.types.DATA_OUT="Data push";Script.OP_RETURN_STANDARD_SIZE=80;Script.prototype.classify=function(){if(this._isInput){return this.classifyInput()}else if(this._isOutput){return this.classifyOutput()}else{var outputType=this.classifyOutput();return outputType!=Script.types.UNKNOWN?outputType:this.classifyInput()}};Script.outputIdentifiers={};Script.outputIdentifiers.PUBKEY_OUT=Script.prototype.isPublicKeyOut;Script.outputIdentifiers.PUBKEYHASH_OUT=Script.prototype.isPublicKeyHashOut;Script.outputIdentifiers.MULTISIG_OUT=Script.prototype.isMultisigOut;Script.outputIdentifiers.SCRIPTHASH_OUT=Script.prototype.isScriptHashOut;Script.outputIdentifiers.DATA_OUT=Script.prototype.isDataOut;Script.prototype.classifyOutput=function(){for(var type in Script.outputIdentifiers){if(Script.outputIdentifiers[type].bind(this)()){return Script.types[type]}}return Script.types.UNKNOWN};Script.inputIdentifiers={};Script.inputIdentifiers.PUBKEY_IN=Script.prototype.isPublicKeyIn;Script.inputIdentifiers.PUBKEYHASH_IN=Script.prototype.isPublicKeyHashIn;Script.inputIdentifiers.MULTISIG_IN=Script.prototype.isMultisigIn;Script.inputIdentifiers.SCRIPTHASH_IN=Script.prototype.isScriptHashIn;Script.prototype.classifyInput=function(){for(var type in Script.inputIdentifiers){if(Script.inputIdentifiers[type].bind(this)()){return Script.types[type]}}return Script.types.UNKNOWN};Script.prototype.isStandard=function(){return this.classify()!==Script.types.UNKNOWN};Script.prototype.prepend=function(obj){this._addByType(obj,true);return this};Script.prototype.equals=function(script){$.checkState(script instanceof Script,"Must provide another script");if(this.chunks.length!==script.chunks.length){return false}var i;for(i=0;i=0&&len=1&&buf[0]<=16){return opcodenum===Opcode.OP_1+(buf[0]-1)}else if(buf.length===1&&buf[0]===129){return opcodenum===Opcode.OP_1NEGATE}else if(buf.length<=75){return opcodenum===buf.length}else if(buf.length<=255){return opcodenum===Opcode.OP_PUSHDATA1}else if(buf.length<=65535){return opcodenum===Opcode.OP_PUSHDATA2}return true};Script.prototype._decodeOP_N=function(opcode){if(opcode===Opcode.OP_0){return 0}else if(opcode>=Opcode.OP_1&&opcode<=Opcode.OP_16){return opcode-(Opcode.OP_1-1)}else{throw new Error("Invalid opcode: "+JSON.stringify(opcode))}};Script.prototype.getSignatureOperationsCount=function(accurate){accurate=_.isUndefined(accurate)?true:accurate;var self=this;var n=0;var lastOpcode=Opcode.OP_INVALIDOPCODE;_.each(self.chunks,function getChunk(chunk){var opcode=chunk.opcodenum;if(opcode==Opcode.OP_CHECKSIG||opcode==Opcode.OP_CHECKSIGVERIFY){n++}else if(opcode==Opcode.OP_CHECKMULTISIG||opcode==Opcode.OP_CHECKMULTISIGVERIFY){if(accurate&&lastOpcode>=Opcode.OP_1&&lastOpcode<=Opcode.OP_16){n+=self._decodeOP_N(lastOpcode)}else{n+=20}}lastOpcode=opcode});return n};module.exports=Script}).call(this)}).call(this,require("buffer").Buffer)},{"../address":1,"../crypto/hash":9,"../crypto/signature":12,"../encoding/bufferreader":15,"../encoding/bufferwriter":16,"../errors":18,"../networks":23,"../opcode":24,"../publickey":26,"../util/buffer":45,"../util/js":46,"../util/preconditions":47,buffer:159,lodash:84}],30:[function(require,module,exports){module.exports=require("./transaction");module.exports.Input=require("./input");module.exports.Output=require("./output");module.exports.UnspentOutput=require("./unspentoutput");module.exports.Signature=require("./signature");module.exports.Sighash=require("./sighash")},{"./input":31,"./output":37,"./sighash":38,"./signature":40,"./transaction":41,"./unspentoutput":42}],31:[function(require,module,exports){module.exports=require("./input");module.exports.PublicKey=require("./publickey");module.exports.PublicKeyHash=require("./publickeyhash");module.exports.MultiSig=require("./multisig.js");module.exports.MultiSigScriptHash=require("./multisigscripthash.js")},{"./input":32,"./multisig.js":33,"./multisigscripthash.js":34,"./publickey":35,"./publickeyhash":36}],32:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var $=require("../../util/preconditions");const errors=require("../../errors");var BufferWriter=require("../../encoding/bufferwriter");var buffer=require("buffer");var BufferUtil=require("../../util/buffer");var JSUtil=require("../../util/js");var Script=require("../../script");var Sighash=require("../sighash");var Output=require("../output");var MAXINT=4294967295;var DEFAULT_SEQNUMBER=MAXINT;var DEFAULT_LOCKTIME_SEQNUMBER=MAXINT-1;var DEFAULT_RBF_SEQNUMBER=MAXINT-2;const SEQUENCE_LOCKTIME_DISABLE_FLAG=Math.pow(2,31);const SEQUENCE_LOCKTIME_TYPE_FLAG=Math.pow(2,22);const SEQUENCE_LOCKTIME_MASK=65535;const SEQUENCE_LOCKTIME_GRANULARITY=512;const SEQUENCE_BLOCKDIFF_LIMIT=Math.pow(2,16)-1;function Input(params){if(!(this instanceof Input)){return new Input(params)}if(params){return this._fromObject(params)}}Input.MAXINT=MAXINT;Input.DEFAULT_SEQNUMBER=DEFAULT_SEQNUMBER;Input.DEFAULT_LOCKTIME_SEQNUMBER=DEFAULT_LOCKTIME_SEQNUMBER;Input.DEFAULT_RBF_SEQNUMBER=DEFAULT_RBF_SEQNUMBER;Input.SEQUENCE_LOCKTIME_TYPE_FLAG=SEQUENCE_LOCKTIME_TYPE_FLAG;Object.defineProperty(Input.prototype,"script",{configurable:false,enumerable:true,get:function(){if(this.isNull()){return null}if(!this._script){this._script=new Script(this._scriptBuffer);this._script._isInput=true}return this._script}});Input.fromObject=function(obj){$.checkArgument(_.isObject(obj));var input=new Input;return input._fromObject(obj)};Input.prototype._fromObject=function(params){var prevTxId;if(_.isString(params.prevTxId)&&JSUtil.isHexa(params.prevTxId)){prevTxId=Buffer.from(params.prevTxId,"hex")}else{prevTxId=params.prevTxId}this.witnesses=[];this.output=params.output?params.output instanceof Output?params.output:new Output(params.output):undefined;this.prevTxId=prevTxId||params.txidbuf;this.outputIndex=_.isUndefined(params.outputIndex)?params.txoutnum:params.outputIndex;this.sequenceNumber=_.isUndefined(params.sequenceNumber)?_.isUndefined(params.seqnum)?DEFAULT_SEQNUMBER:params.seqnum:params.sequenceNumber;if(_.isUndefined(params.script)&&_.isUndefined(params.scriptBuffer)){throw new errors.Transaction.Input.MissingScript}this.setScript(params.scriptBuffer||params.script);return this};Input.prototype.toObject=Input.prototype.toJSON=function toObject(){var obj={prevTxId:this.prevTxId.toString("hex"),outputIndex:this.outputIndex,sequenceNumber:this.sequenceNumber,script:this._scriptBuffer.toString("hex")};if(this.script){obj.scriptString=this.script.toString()}if(this.output){obj.output=this.output.toObject()}return obj};Input.fromBufferReader=function(br){var input=new Input;input.prevTxId=br.readReverse(32);input.outputIndex=br.readUInt32LE();input._scriptBuffer=br.readVarLengthBuffer();input.sequenceNumber=br.readUInt32LE();return input};Input.prototype.toBufferWriter=function(writer){if(!writer){writer=new BufferWriter}writer.writeReverse(this.prevTxId);writer.writeUInt32LE(this.outputIndex);var script=this._scriptBuffer;writer.writeVarintNum(script.length);writer.write(script);writer.writeUInt32LE(this.sequenceNumber);return writer};Input.prototype.setScript=function(script){this._script=null;if(script instanceof Script){this._script=script;this._script._isInput=true;this._scriptBuffer=script.toBuffer()}else if(JSUtil.isHexa(script)){this._scriptBuffer=Buffer.from(script,"hex")}else if(_.isString(script)){this._script=new Script(script);this._script._isInput=true;this._scriptBuffer=this._script.toBuffer()}else if(BufferUtil.isBuffer(script)){this._scriptBuffer=Buffer.from(script)}else{throw new TypeError("Invalid argument type: script")}return this};Input.prototype.getSignatures=function(){throw new errors.AbstractMethodInvoked("Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported)"+" for input: "+JSON.stringify(this))};Input.prototype.getSatoshisBuffer=function(){$.checkState(this.output instanceof Output);$.checkState(this.output._satoshisBN);return(new BufferWriter).writeUInt64LEBN(this.output._satoshisBN).toBuffer()};Input.prototype.isFullySigned=function(){throw new errors.AbstractMethodInvoked("Input#isFullySigned")};Input.prototype.isFinal=function(){return this.sequenceNumber!==Input.MAXINT};Input.prototype.addSignature=function(){throw new errors.AbstractMethodInvoked("Input#addSignature")};Input.prototype.clearSignatures=function(){throw new errors.AbstractMethodInvoked("Input#clearSignatures")};Input.prototype.hasWitnesses=function(){if(this.witnesses&&this.witnesses.length>0){return true}return false};Input.prototype.getWitnesses=function(){return this.witnesses};Input.prototype.setWitnesses=function(witnesses){this.witnesses=witnesses};Input.prototype.isValidSignature=function(transaction,signature,signingMethod){signingMethod=signingMethod||"ecdsa";signature.signature.nhashtype=signature.sigtype;return Sighash.verify(transaction,signature.signature,signature.publicKey,signature.inputIndex,this.output.script,signingMethod)};Input.prototype.isNull=function(){return this.prevTxId.toString("hex")==="0000000000000000000000000000000000000000000000000000000000000000"&&this.outputIndex===4294967295};Input.prototype._estimateSize=function(){return this.toBufferWriter().toBuffer().length};Input.prototype.lockForSeconds=function(seconds){$.checkArgument(_.isNumber(seconds));if(seconds<0||seconds>=SEQUENCE_LOCKTIME_GRANULARITY*SEQUENCE_LOCKTIME_MASK){throw new errors.Transaction.Input.LockTimeRange}seconds=parseInt(Math.floor(seconds/SEQUENCE_LOCKTIME_GRANULARITY));this.sequenceNumber=seconds|SEQUENCE_LOCKTIME_TYPE_FLAG;return this};Input.prototype.lockUntilBlockHeight=function(heightDiff){$.checkArgument(_.isNumber(heightDiff));if(heightDiff<0||heightDiff>=SEQUENCE_BLOCKDIFF_LIMIT){throw new errors.Transaction.Input.BlockHeightOutOfRange}this.sequenceNumber=heightDiff;return this};Input.prototype.getLockTime=function(){if(this.sequenceNumber&SEQUENCE_LOCKTIME_DISABLE_FLAG){return null}if(this.sequenceNumber&SEQUENCE_LOCKTIME_TYPE_FLAG){var seconds=SEQUENCE_LOCKTIME_GRANULARITY*(this.sequenceNumber&SEQUENCE_LOCKTIME_MASK);return seconds}else{var blockHeight=this.sequenceNumber&SEQUENCE_LOCKTIME_MASK;return blockHeight}};module.exports=Input}).call(this)}).call(this,require("buffer").Buffer)},{"../../encoding/bufferwriter":16,"../../errors":18,"../../script":27,"../../util/buffer":45,"../../util/js":46,"../../util/preconditions":47,"../output":37,"../sighash":38,buffer:159,lodash:84}],33:[function(require,module,exports){"use strict";var _=require("lodash");var inherits=require("inherits");var Transaction=require("../transaction");var Input=require("./input");var Output=require("../output");var $=require("../../util/preconditions");var Script=require("../../script");var Signature=require("../../crypto/signature");var Sighash=require("../sighash");var PublicKey=require("../../publickey");var BufferUtil=require("../../util/buffer");var TransactionSignature=require("../signature");function MultiSigInput(input,pubkeys,threshold,signatures){Input.apply(this,arguments);var self=this;pubkeys=pubkeys||input.publicKeys;threshold=threshold||input.threshold;signatures=signatures||input.signatures;this.publicKeys=_.sortBy(pubkeys,function(publicKey){return publicKey.toString("hex")});$.checkState(Script.buildMultisigOut(this.publicKeys,threshold).equals(this.output.script),"Provided public keys don't match to the provided output script");this.publicKeyIndex={};_.each(this.publicKeys,function(publicKey,index){self.publicKeyIndex[publicKey.toString()]=index});this.threshold=threshold;this.signatures=signatures?this._deserializeSignatures(signatures):new Array(this.publicKeys.length)}inherits(MultiSigInput,Input);MultiSigInput.prototype.toObject=function(){var obj=Input.prototype.toObject.apply(this,arguments);obj.threshold=this.threshold;obj.publicKeys=_.map(this.publicKeys,function(publicKey){return publicKey.toString()});obj.signatures=this._serializeSignatures();return obj};MultiSigInput.prototype._deserializeSignatures=function(signatures){return _.map(signatures,function(signature){if(!signature){return undefined}return new TransactionSignature(signature)})};MultiSigInput.prototype._serializeSignatures=function(){return _.map(this.signatures,function(signature){if(!signature){return undefined}return signature.toObject()})};MultiSigInput.prototype.getSignatures=function(transaction,privateKey,index,sigtype){$.checkState(this.output instanceof Output);sigtype=sigtype||Signature.SIGHASH_ALL;var self=this;var results=[];_.each(this.publicKeys,function(publicKey){if(publicKey.toString()===privateKey.publicKey.toString()){results.push(new TransactionSignature({publicKey:privateKey.publicKey,prevTxId:self.prevTxId,outputIndex:self.outputIndex,inputIndex:index,signature:Sighash.sign(transaction,privateKey,sigtype,index,self.output.script),sigtype:sigtype}))}});return results};MultiSigInput.prototype.addSignature=function(transaction,signature){$.checkState(!this.isFullySigned(),"All needed signatures have already been added");$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()]),"Signature has no matching public key");$.checkState(this.isValidSignature(transaction,signature));this.signatures[this.publicKeyIndex[signature.publicKey.toString()]]=signature;this._updateScript();return this};MultiSigInput.prototype._updateScript=function(){this.setScript(Script.buildMultisigIn(this.publicKeys,this.threshold,this._createSignatures()));return this};MultiSigInput.prototype._createSignatures=function(){return _.map(_.filter(this.signatures,function(signature){return!_.isUndefined(signature)}),function(signature){return BufferUtil.concat([signature.signature.toDER(),BufferUtil.integerAsSingleByteBuffer(signature.sigtype)])})};MultiSigInput.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length);this._updateScript()};MultiSigInput.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};MultiSigInput.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};MultiSigInput.prototype.countSignatures=function(){return _.reduce(this.signatures,function(sum,signature){return sum+!!signature},0)};MultiSigInput.prototype.publicKeysWithoutSignature=function(){var self=this;return _.filter(this.publicKeys,function(publicKey){return!self.signatures[self.publicKeyIndex[publicKey.toString()]]})};MultiSigInput.prototype.isValidSignature=function(transaction,signature){signature.signature.nhashtype=signature.sigtype;return Sighash.verify(transaction,signature.signature,signature.publicKey,signature.inputIndex,this.output.script)};MultiSigInput.normalizeSignatures=function(transaction,input,inputIndex,signatures,publicKeys){return publicKeys.map(function(pubKey){var signatureMatch=null;signatures=signatures.filter(function(signatureBuffer){if(signatureMatch){return true}var signature=new TransactionSignature({signature:Signature.fromTxFormat(signatureBuffer),publicKey:pubKey,prevTxId:input.prevTxId,outputIndex:input.outputIndex,inputIndex:inputIndex,sigtype:Signature.SIGHASH_ALL});signature.signature.nhashtype=signature.sigtype;var isMatch=Sighash.verify(transaction,signature.signature,signature.publicKey,signature.inputIndex,input.output.script);if(isMatch){signatureMatch=signature;return false}return true});return signatureMatch?signatureMatch:null})};MultiSigInput.OPCODES_SIZE=1;MultiSigInput.SIGNATURE_SIZE=73;MultiSigInput.prototype._estimateSize=function(){return MultiSigInput.OPCODES_SIZE+this.threshold*MultiSigInput.SIGNATURE_SIZE};module.exports=MultiSigInput},{"../../crypto/signature":12,"../../publickey":26,"../../script":27,"../../util/buffer":45,"../../util/preconditions":47,"../output":37,"../sighash":38,"../signature":40,"../transaction":41,"./input":32,inherits:83,lodash:84}],34:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var inherits=require("inherits");var Input=require("./input");var Output=require("../output");var $=require("../../util/preconditions");var Address=require("../../address");var Script=require("../../script");var Signature=require("../../crypto/signature");var Sighash=require("../sighash");var SighashWitness=require("../sighashwitness");var BufferWriter=require("../../encoding/bufferwriter");var BufferUtil=require("../../util/buffer");var TransactionSignature=require("../signature");function MultiSigScriptHashInput(input,pubkeys,threshold,signatures,opts){opts=opts||{};Input.apply(this,arguments);var self=this;pubkeys=pubkeys||input.publicKeys;threshold=threshold||input.threshold;signatures=signatures||input.signatures;if(opts.noSorting){this.publicKeys=pubkeys}else{this.publicKeys=_.sortBy(pubkeys,function(publicKey){return publicKey.toString("hex")})}this.redeemScript=Script.buildMultisigOut(this.publicKeys,threshold,opts);var nested=Script.buildWitnessMultisigOutFromScript(this.redeemScript);if(Script.buildScriptHashOut(nested).equals(this.output.script)){this.nestedWitness=true;this.type=Address.PayToScriptHash}else if(Script.buildScriptHashOut(this.redeemScript).equals(this.output.script)){this.nestedWitness=false;this.type=Address.PayToScriptHash}else{throw new Error("Provided public keys don't hash to the provided output")}if(this.nestedWitness){var scriptSig=new Script;scriptSig.add(nested.toBuffer());this.setScript(scriptSig)}this.publicKeyIndex={};_.each(this.publicKeys,function(publicKey,index){self.publicKeyIndex[publicKey.toString()]=index});this.threshold=threshold;this.signatures=signatures?this._deserializeSignatures(signatures):new Array(this.publicKeys.length)}inherits(MultiSigScriptHashInput,Input);MultiSigScriptHashInput.prototype.toObject=function(){var obj=Input.prototype.toObject.apply(this,arguments);obj.threshold=this.threshold;obj.publicKeys=_.map(this.publicKeys,function(publicKey){return publicKey.toString()});obj.signatures=this._serializeSignatures();return obj};MultiSigScriptHashInput.prototype._deserializeSignatures=function(signatures){return _.map(signatures,function(signature){if(!signature){return undefined}return new TransactionSignature(signature)})};MultiSigScriptHashInput.prototype._serializeSignatures=function(){return _.map(this.signatures,function(signature){if(!signature){return undefined}return signature.toObject()})};MultiSigScriptHashInput.prototype.getScriptCode=function(){var writer=new BufferWriter;if(!this.redeemScript.hasCodeseparators()){var redeemScriptBuffer=this.redeemScript.toBuffer();writer.writeVarintNum(redeemScriptBuffer.length);writer.write(redeemScriptBuffer)}else{throw new Error("@TODO")}return writer.toBuffer()};MultiSigScriptHashInput.prototype.getSighash=function(transaction,privateKey,index,sigtype){var self=this;var hash;if(self.nestedWitness){var scriptCode=self.getScriptCode();var satoshisBuffer=self.getSatoshisBuffer();hash=SighashWitness.sighash(transaction,sigtype,index,scriptCode,satoshisBuffer)}else{hash=Sighash.sighash(transaction,sigtype,index,self.redeemScript)}return hash};MultiSigScriptHashInput.prototype.getSignatures=function(transaction,privateKey,index,sigtype){$.checkState(this.output instanceof Output);sigtype=sigtype||Signature.SIGHASH_ALL;var self=this;var results=[];_.each(this.publicKeys,function(publicKey){if(publicKey.toString()===privateKey.publicKey.toString()){var signature;if(self.nestedWitness){var scriptCode=self.getScriptCode();var satoshisBuffer=self.getSatoshisBuffer();signature=SighashWitness.sign(transaction,privateKey,sigtype,index,scriptCode,satoshisBuffer)}else{signature=Sighash.sign(transaction,privateKey,sigtype,index,self.redeemScript)}results.push(new TransactionSignature({publicKey:privateKey.publicKey,prevTxId:self.prevTxId,outputIndex:self.outputIndex,inputIndex:index,signature:signature,sigtype:sigtype}))}});return results};MultiSigScriptHashInput.prototype.addSignature=function(transaction,signature){$.checkState(!this.isFullySigned(),"All needed signatures have already been added");$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()]),"Signature has no matching public key");$.checkState(this.isValidSignature(transaction,signature));this.signatures[this.publicKeyIndex[signature.publicKey.toString()]]=signature;this._updateScript();return this};MultiSigScriptHashInput.prototype._updateScript=function(){if(this.nestedWitness){var stack=[Buffer.alloc(0)];var signatures=this._createSignatures();for(var i=0;iMAX_SAFE_INTEGER){return"transaction txout satoshis greater than max safe integer"}if(this._satoshis!==this._satoshisBN.toNumber()){return"transaction txout satoshis has corrupted value"}if(this._satoshis<0){return"transaction txout negative"}return false};Output.prototype.toObject=Output.prototype.toJSON=function toObject(){var obj={satoshis:this.satoshis};obj.script=this._scriptBuffer.toString("hex");return obj};Output.fromObject=function(data){return new Output(data)};Output.prototype.setScriptFromBuffer=function(buffer){this._scriptBuffer=buffer;try{this._script=Script.fromBuffer(this._scriptBuffer);this._script._isOutput=true}catch(e){if(e instanceof errors.Script.InvalidBuffer){this._script=null}else{throw e}}};Output.prototype.setScript=function(script){if(script instanceof Script){this._scriptBuffer=script.toBuffer();this._script=script;this._script._isOutput=true}else if(_.isString(script)){this._script=Script.fromString(script);this._scriptBuffer=this._script.toBuffer();this._script._isOutput=true}else if(bufferUtil.isBuffer(script)){this.setScriptFromBuffer(script)}else{throw new TypeError("Invalid argument type: script")}return this};Output.prototype.inspect=function(){var scriptStr;if(this.script){scriptStr=this.script.inspect()}else{scriptStr=this._scriptBuffer.toString("hex")}return""};Output.fromBufferReader=function(br){var obj={};obj.satoshis=br.readUInt64LEBN();var size=br.readVarintNum();if(size!==0){obj.script=br.read(size)}else{obj.script=new buffer.Buffer([])}return new Output(obj)};Output.prototype.toBufferWriter=function(writer){if(!writer){writer=new BufferWriter}writer.writeUInt64LEBN(this._satoshisBN);var script=this._scriptBuffer;writer.writeVarintNum(script.length);writer.write(script);return writer};module.exports=Output},{"../crypto/bn":7,"../encoding/bufferwriter":16,"../errors":18,"../script":27,"../util/buffer":45,"../util/js":46,"../util/preconditions":47,buffer:159,lodash:84}],38:[function(require,module,exports){(function(Buffer){(function(){"use strict";var buffer=require("buffer");var Signature=require("../crypto/signature");var Script=require("../script");var Output=require("./output");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var BN=require("../crypto/bn");var Hash=require("../crypto/hash");var ECDSA=require("../crypto/ecdsa");var $=require("../util/preconditions");var _=require("lodash");var SIGHASH_SINGLE_BUG="0000000000000000000000000000000000000000000000000000000000000001";var BITS_64_ON="ffffffffffffffff";var sighash=function sighash(transaction,sighashType,inputNumber,subscript){var Transaction=require("./transaction");var Input=require("./input");var i;var txcopy=Transaction.shallowCopy(transaction);subscript=new Script(subscript);subscript.removeCodeseparators();for(i=0;i=txcopy.outputs.length){return new Buffer(SIGHASH_SINGLE_BUG,"hex")}txcopy.outputs.length=inputNumber+1;for(i=0;imaximumFee){if(this._missingChange()){return new errors.Transaction.ChangeAddressMissing("Fee is too large and no change address was provided")}return new errors.Transaction.FeeError.TooLarge("expected less than "+maximumFee+" but got "+unspent)}}if(!opts.disableSmallFees){var minimumFee=Math.ceil(this._estimateFee()/Transaction.FEE_SECURITY_MARGIN);if(unspent"};Transaction.prototype.toBuffer=function(noWitness){var writer=new BufferWriter;return this.toBufferWriter(writer,noWitness).toBuffer()};Transaction.prototype.hasWitnesses=function(){for(var i=0;i=Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT){throw new errors.Transaction.BlockHeightTooHigh}if(height<0){throw new errors.Transaction.NLockTimeOutOfRange}for(var i=0;ii.prevTxId.toString("hex")===utxo.txId&&i.outputIndex===utxo.outputIndex);indexes.push(index);if(index>=0){this.inputs[index]=this._getInputFrom(utxo,pubkeys,threshold,opts)}}return indexes};Transaction.prototype._selectInputType=function(utxo,pubkeys,threshold){var clazz;utxo=new UnspentOutput(utxo);if(pubkeys&&threshold){if(utxo.script.isMultisigOut()){clazz=MultiSigInput}else if(utxo.script.isScriptHashOut()){clazz=MultiSigScriptHashInput}}else if(utxo.script.isPublicKeyHashOut()){clazz=PublicKeyHashInput}else if(utxo.script.isPublicKeyOut()){clazz=PublicKeyInput}else{clazz=Input}return clazz};Transaction.prototype._getInputFrom=function(utxo,pubkeys,threshold,opts){utxo=new UnspentOutput(utxo);const InputClass=this._selectInputType(utxo,pubkeys,threshold);const input={output:new Output({script:utxo.script,satoshis:utxo.satoshis}),prevTxId:utxo.txId,outputIndex:utxo.outputIndex,sequenceNumber:utxo.sequenceNumber,script:Script.empty()};let args=pubkeys&&threshold?[pubkeys,threshold,false,opts]:[];return new InputClass(input,...args)};Transaction.prototype._fromNonP2SH=function(utxo){const input=this._getInputFrom(utxo);this.addInput(input)};Transaction.prototype._fromMultisigUtxo=function(utxo,pubkeys,threshold,opts){$.checkArgument(threshold<=pubkeys.length,"Number of required signatures must be greater than the number of public keys");const input=this._getInputFrom(utxo,pubkeys,threshold,opts);this.addInput(input)};Transaction.prototype.addInput=function(input,outputScript,satoshis){$.checkArgumentType(input,Input,"input");if(!input.output&&(_.isUndefined(outputScript)||_.isUndefined(satoshis))){throw new errors.Transaction.NeedMoreInfo("Need information about the UTXO script and satoshis")}if(!input.output&&outputScript&&!_.isUndefined(satoshis)){outputScript=outputScript instanceof Script?outputScript:new Script(outputScript);$.checkArgumentType(satoshis,"number","satoshis");input.output=new Output({script:outputScript,satoshis:satoshis})}return this.uncheckedAddInput(input)};Transaction.prototype.uncheckedAddInput=function(input){$.checkArgumentType(input,Input,"input");this.inputs.push(input);this._inputAmount=undefined;this._updateChangeOutput();return this};Transaction.prototype.hasAllUtxoInfo=function(){return _.every(this.inputs.map(function(input){return!!input.output}))};Transaction.prototype.fee=function(amount){$.checkArgument(_.isNumber(amount),"amount must be a number");this._fee=amount;this._updateChangeOutput();return this};Transaction.prototype.feePerKb=function(amount){$.checkArgument(_.isNumber(amount),"amount must be a number");this._feePerKb=amount;this._updateChangeOutput();return this};Transaction.prototype.feePerByte=function(amount){$.checkArgument(_.isNumber(amount),"amount must be a number");this._feePerByte=amount;this._updateChangeOutput();return this};Transaction.prototype.change=function(address){$.checkArgument(address,"address is required");this._changeScript=Script.fromAddress(address);this._updateChangeOutput();return this};Transaction.prototype.getChangeOutput=function(){if(!_.isUndefined(this._changeIndex)){return this.outputs[this._changeIndex]}return null};Transaction.prototype.to=function(address,amount){if(_.isArray(address)){var self=this;_.each(address,function(to){self.to(to.address,to.satoshis)});return this}$.checkArgument(JSUtil.isNaturalNumber(amount),"Amount is expected to be a positive integer");this.addOutput(new Output({script:Script(new Address(address)),satoshis:amount}));return this};Transaction.prototype.addData=function(value){this.addOutput(new Output({script:Script.buildDataOut(value),satoshis:0}));return this};Transaction.prototype.addOutput=function(output){$.checkArgumentType(output,Output,"output");this._addOutput(output);this._updateChangeOutput();return this};Transaction.prototype.clearOutputs=function(){this.outputs=[];this._clearSignatures();this._outputAmount=undefined;this._changeIndex=undefined;this._updateChangeOutput();return this};Transaction.prototype._addOutput=function(output){this.outputs.push(output);this._outputAmount=undefined};Transaction.prototype._getOutputAmount=function(){if(_.isUndefined(this._outputAmount)){var self=this;this._outputAmount=0;_.each(this.outputs,function(output){self._outputAmount+=output.satoshis})}return this._outputAmount};Transaction.prototype._getInputAmount=function(){if(_.isUndefined(this._inputAmount)){this._inputAmount=_.sumBy(this.inputs,function(input){if(_.isUndefined(input.output)){throw new errors.Transaction.Input.MissingPreviousOutput}return input.output.satoshis})}return this._inputAmount};Transaction.prototype._updateChangeOutput=function(){if(!this._changeScript){return}this._clearSignatures();if(!_.isUndefined(this._changeIndex)){this._removeOutput(this._changeIndex)}var available=this._getUnspentValue();var fee=this.getFee();var changeAmount=available-fee;if(changeAmount>=Transaction.DUST_AMOUNT){this._changeIndex=this.outputs.length;this._addOutput(new Output({script:this._changeScript,satoshis:changeAmount}))}else{this._changeIndex=undefined;this._fee=fee+changeAmount}};Transaction.prototype.getFee=function(){if(this.isCoinbase()){return 0}if(!_.isUndefined(this._fee)){return this._fee}if(!this._changeScript){return this._getUnspentValue()}return this._estimateFee()};Transaction.prototype._estimateFee=function(){var estimatedSize=this._estimateSize();var available=this._getUnspentValue();var feeRate=this._feePerByte||(this._feePerKb||Transaction.FEE_PER_KB)/1e3;function getFee(size){return size*feeRate}var fee=Math.ceil(getFee(estimatedSize));var feeWithChange=Math.ceil(getFee(estimatedSize)+getFee(Transaction.CHANGE_OUTPUT_MAX_SIZE));if(!this._changeScript||available<=feeWithChange){return fee}return feeWithChange};Transaction.prototype._getUnspentValue=function(){return this._getInputAmount()-this._getOutputAmount()};Transaction.prototype._clearSignatures=function(){_.each(this.inputs,function(input){input.clearSignatures()})};Transaction.prototype._estimateSize=function(){var result=Transaction.MAXIMUM_EXTRA_SIZE;_.each(this.inputs,function(input){result+=32+4;result+=input._estimateSize()});_.each(this.outputs,function(output){result+=output.script.toBuffer().length+9});return Math.ceil(result)};Transaction.prototype._removeOutput=function(index){var output=this.outputs[index];this.outputs=_.without(this.outputs,output);this._outputAmount=undefined};Transaction.prototype.removeOutput=function(index){this._removeOutput(index);this._updateChangeOutput()};Transaction.prototype.sort=function(){this.sortInputs(function(inputs){var copy=Array.prototype.concat.apply([],inputs);let i=0;copy.forEach(x=>{x.i=i++});copy.sort(function(first,second){return compare(first.prevTxId,second.prevTxId)||first.outputIndex-second.outputIndex||first.i-second.i});return copy});this.sortOutputs(function(outputs){var copy=Array.prototype.concat.apply([],outputs);let i=0;copy.forEach(x=>{x.i=i++});copy.sort(function(first,second){return first.satoshis-second.satoshis||compare(first.script.toBuffer(),second.script.toBuffer())||first.i-second.i});return copy});return this};Transaction.prototype.shuffleOutputs=function(){return this.sortOutputs(_.shuffle)};Transaction.prototype.sortOutputs=function(sortingFunction){var outs=sortingFunction(this.outputs);return this._newOutputOrder(outs)};Transaction.prototype.sortInputs=function(sortingFunction){this.inputs=sortingFunction(this.inputs);this._clearSignatures();return this};Transaction.prototype._newOutputOrder=function(newOutputs){var isInvalidSorting=this.outputs.length!==newOutputs.length||_.difference(this.outputs,newOutputs).length!==0;if(isInvalidSorting){throw new errors.Transaction.InvalidSorting}if(!_.isUndefined(this._changeIndex)){var changeOutput=this.outputs[this._changeIndex];this._changeIndex=_.findIndex(newOutputs,changeOutput)}this.outputs=newOutputs;return this};Transaction.prototype.removeInput=function(txId,outputIndex){var index;if(!outputIndex&&_.isNumber(txId)){index=txId}else{index=_.findIndex(this.inputs,function(input){return input.prevTxId.toString("hex")===txId&&input.outputIndex===outputIndex})}if(index<0||index>=this.inputs.length){throw new errors.Transaction.InvalidIndex(index,this.inputs.length)}var input=this.inputs[index];this.inputs=_.without(this.inputs,input);this._inputAmount=undefined;this._updateChangeOutput()};Transaction.prototype.sign=function(privateKey,sigtype,signingMethod){$.checkState(this.hasAllUtxoInfo(),"Not all utxo information is available to sign the transaction.");var self=this;if(_.isArray(privateKey)){_.each(privateKey,function(privateKey){self.sign(privateKey,sigtype,signingMethod)});return this}_.each(this.getSignatures(privateKey,sigtype,signingMethod),function(signature){self.applySignature(signature,signingMethod)});return this};Transaction.prototype.getSignatures=function(privKey,sigtype,signingMethod){privKey=new PrivateKey(privKey);sigtype=sigtype||Signature.SIGHASH_ALL;var transaction=this;var results=[];var hashData=Hash.sha256ripemd160(privKey.publicKey.toBuffer());_.each(this.inputs,function forEachInput(input,index){_.each(input.getSignatures(transaction,privKey,index,sigtype,hashData,signingMethod),function(signature){results.push(signature)})});return results};Transaction.prototype.applySignature=function(signature,signingMethod){this.inputs[signature.inputIndex].addSignature(this,signature,signingMethod);return this};Transaction.prototype.isFullySigned=function(){_.each(this.inputs,function(input){if(input.isFullySigned===Input.prototype.isFullySigned){throw new errors.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script."+"This usually happens when creating a transaction from a serialized transaction")}});return _.every(_.map(this.inputs,function(input){return input.isFullySigned()}))};Transaction.prototype.isValidSignature=function(signature,signingMethod){var self=this;if(this.inputs[signature.inputIndex].isValidSignature===Input.prototype.isValidSignature){throw new errors.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script."+"This usually happens when creating a transaction from a serialized transaction")}return this.inputs[signature.inputIndex].isValidSignature(self,signature,signingMethod)};Transaction.prototype.verifySignature=function(sig,pubkey,nin,subscript,sigversion,satoshis,signingMethod){if(_.isUndefined(sigversion)){sigversion=Interpreter.SIGVERSION_BASE}if(sigversion===Interpreter.SIGVERSION_WITNESS_V0){var subscriptBuffer=subscript.toBuffer();var scriptCodeWriter=new BufferWriter;scriptCodeWriter.writeVarintNum(subscriptBuffer.length);scriptCodeWriter.write(subscriptBuffer);var satoshisBuffer;if(satoshis){$.checkState(JSUtil.isNaturalNumber(satoshis));satoshisBuffer=(new BufferWriter).writeUInt64LEBN(new BN(satoshis)).toBuffer()}else{satoshisBuffer=this.inputs[nin].getSatoshisBuffer()}var verified=SighashWitness.verify(this,sig,pubkey,nin,scriptCodeWriter.toBuffer(),satoshisBuffer,signingMethod);return verified}return Sighash.verify(this,sig,pubkey,nin,subscript,signingMethod)};Transaction.prototype.verify=function(){if(this.inputs.length===0){return"transaction txins empty"}if(this.outputs.length===0){return"transaction txouts empty"}var valueoutbn=new BN(0);for(var i=0;iMAX_BLOCK_SIZE){return"transaction over the maximum block size"}var txinmap={};for(i=0;i100){return"coinbase transaction script size invalid"}}else{for(i=0;i=Input.MAXINT-1){input.sequenceNumber=Input.DEFAULT_RBF_SEQNUMBER}}return this};Transaction.prototype.setVersion=function(version){$.checkArgument(JSUtil.isNaturalNumber(version)&&version<=CURRENT_VERSION,"Wrong version number");this.version=version;return this};module.exports=Transaction}).call(this)}).call(this,require("buffer").Buffer)},{"../address":1,"../crypto/bn":7,"../crypto/hash":9,"../crypto/signature":12,"../encoding/bufferreader":15,"../encoding/bufferwriter":16,"../errors":18,"../privatekey":25,"../script":27,"../script/interpreter":28,"../util/buffer":45,"../util/js":46,"../util/preconditions":47,"./input":31,"./output":37,"./sighash":38,"./sighashwitness":39,"./unspentoutput":42,buffer:159,"buffer-compare":52,lodash:84}],42:[function(require,module,exports){"use strict";var _=require("lodash");var $=require("../util/preconditions");var JSUtil=require("../util/js");var Script=require("../script");var Address=require("../address");var Unit=require("../unit");function UnspentOutput(data){if(!(this instanceof UnspentOutput)){return new UnspentOutput(data)}$.checkArgument(_.isObject(data),"Must provide an object from where to extract data");var address=data.address?new Address(data.address):undefined;var txId=data.txid?data.txid:data.txId;if(!txId||!JSUtil.isHexaString(txId)||txId.length>64){throw new Error("Invalid TXID in object",data)}var outputIndex=_.isUndefined(data.vout)?data.outputIndex:data.vout;if(!_.isNumber(outputIndex)){throw new Error("Invalid outputIndex, received "+outputIndex)}$.checkArgument(!_.isUndefined(data.scriptPubKey)||!_.isUndefined(data.script),"Must provide the scriptPubKey for that output!");var script=new Script(data.scriptPubKey||data.script);$.checkArgument(!_.isUndefined(data.amount)||!_.isUndefined(data.satoshis),"Must provide an amount for the output");var amount=!_.isUndefined(data.amount)?new Unit.fromBTC(data.amount).toSatoshis():data.satoshis;$.checkArgument(_.isNumber(amount),"Amount must be a number");JSUtil.defineImmutable(this,{address:address,txId:txId,outputIndex:outputIndex,script:script,satoshis:amount})}UnspentOutput.prototype.inspect=function(){return""};UnspentOutput.prototype.toString=function(){return this.txId+":"+this.outputIndex};UnspentOutput.fromObject=function(data){return new UnspentOutput(data)};UnspentOutput.prototype.toObject=UnspentOutput.prototype.toJSON=function toObject(){return{address:this.address?this.address.toString():undefined,txid:this.txId,vout:this.outputIndex,scriptPubKey:this.script.toBuffer().toString("hex"),amount:Unit.fromSatoshis(this.satoshis).toBTC()}};module.exports=UnspentOutput},{"../address":1,"../script":27,"../unit":43,"../util/js":46,"../util/preconditions":47,lodash:84}],43:[function(require,module,exports){"use strict";var _=require("lodash");var errors=require("./errors");var $=require("./util/preconditions");var UNITS={BTC:[1e8,8],mBTC:[1e5,5],uBTC:[100,2],bits:[100,2],satoshis:[1,0]};function Unit(amount,code){if(!(this instanceof Unit)){return new Unit(amount,code)}if(_.isNumber(code)){if(code<=0){throw new errors.Unit.InvalidRate(code)}amount=amount/code;code=Unit.BTC}this._value=this._from(amount,code);var self=this;var defineAccesor=function(key){Object.defineProperty(self,key,{get:function(){return self.to(key)},enumerable:true})};Object.keys(UNITS).forEach(defineAccesor)}Object.keys(UNITS).forEach(function(key){Unit[key]=key});Unit.fromObject=function fromObject(data){$.checkArgument(_.isObject(data),"Argument is expected to be an object");return new Unit(data.amount,data.code)};Unit.fromBTC=function(amount){return new Unit(amount,Unit.BTC)};Unit.fromMillis=Unit.fromMilis=function(amount){return new Unit(amount,Unit.mBTC)};Unit.fromMicros=Unit.fromBits=function(amount){return new Unit(amount,Unit.bits)};Unit.fromSatoshis=function(amount){return new Unit(amount,Unit.satoshis)};Unit.fromFiat=function(amount,rate){return new Unit(amount,rate)};Unit.prototype._from=function(amount,code){if(!UNITS[code]){throw new errors.Unit.UnknownCode(code)}return parseInt((amount*UNITS[code][0]).toFixed())};Unit.prototype.to=function(code){if(_.isNumber(code)){if(code<=0){throw new errors.Unit.InvalidRate(code)}return parseFloat((this.BTC*code).toFixed(2))}if(!UNITS[code]){throw new errors.Unit.UnknownCode(code)}var value=this._value/UNITS[code][0];return parseFloat(value.toFixed(UNITS[code][1]))};Unit.prototype.toBTC=function(){return this.to(Unit.BTC)};Unit.prototype.toMillis=Unit.prototype.toMilis=function(){return this.to(Unit.mBTC)};Unit.prototype.toMicros=Unit.prototype.toBits=function(){return this.to(Unit.bits)};Unit.prototype.toSatoshis=function(){return this.to(Unit.satoshis)};Unit.prototype.atRate=function(rate){return this.to(rate)};Unit.prototype.toString=function(){return this.satoshis+" satoshis"};Unit.prototype.toObject=Unit.prototype.toJSON=function toObject(){return{amount:this.BTC,code:Unit.BTC}};Unit.prototype.inspect=function(){return""};module.exports=Unit},{"./errors":18,"./util/preconditions":47,lodash:84}],44:[function(require,module,exports){"use strict";var _=require("lodash");var URL=require("url");var Address=require("./address");var Unit=require("./unit");var URI=function(data,knownParams){if(!(this instanceof URI)){return new URI(data,knownParams)}this.extras={};this.knownParams=knownParams||[];this.address=this.network=this.amount=this.message=null;if(typeof data==="string"){var params=URI.parse(data);if(params.amount){params.amount=this._parseAmount(params.amount)}this._fromObject(params)}else if(typeof data==="object"){this._fromObject(data)}else{throw new TypeError("Unrecognized data format.")}};URI.fromString=function fromString(str){if(typeof str!=="string"){throw new TypeError("Expected a string")}return new URI(str)};URI.fromObject=function fromObject(json){return new URI(json)};URI.isValid=function(arg,knownParams){try{new URI(arg,knownParams)}catch(err){return false}return true};URI.parse=function(uri){var info=URL.parse(uri,true);if(info.protocol!=="dogecoin:"){throw new TypeError("Invalid dogecoin URI")}var group=/[^:]*:\/?\/?([^?]*)/.exec(uri);info.query.address=group&&group[1]||undefined;return info.query};URI.Members=["address","amount","message","label","r"];URI.prototype._fromObject=function(obj){if(!Address.isValid(obj.address)){throw new TypeError("Invalid dogecoin address")}this.address=new Address(obj.address);this.network=this.address.network;this.amount=obj.amount;for(var key in obj){if(key==="address"||key==="amount"){continue}if(/^req-/.exec(key)&&this.knownParams.indexOf(key)===-1){throw Error("Unknown required argument "+key)}var destination=URI.Members.indexOf(key)>-1?this:this.extras;destination[key]=obj[key]}};URI.prototype._parseAmount=function(amount){amount=Number(amount);if(isNaN(amount)){throw new TypeError("Invalid amount")}return Unit.fromBTC(amount).toSatoshis()};URI.prototype.toObject=URI.prototype.toJSON=function toObject(){var json={};for(var i=0;i"};module.exports=URI},{"./address":1,"./unit":43,lodash:84,url:288}],45:[function(require,module,exports){(function(Buffer){(function(){"use strict";var buffer=require("buffer");var assert=require("assert");var js=require("./js");var $=require("./preconditions");function equals(a,b){if(a.length!==b.length){return false}var length=a.length;for(var i=0;i>24&255);bytes.push(integer>>16&255);bytes.push(integer>>8&255);bytes.push(integer&255);return Buffer.from(bytes)},integerFromBuffer:function integerFromBuffer(buffer){$.checkArgumentType(buffer,"Buffer","buffer");return buffer[0]<<24|buffer[1]<<16|buffer[2]<<8|buffer[3]},integerFromSingleByteBuffer:function integerFromBuffer(buffer){$.checkArgumentType(buffer,"Buffer","buffer");return buffer[0]},bufferToHex:function bufferToHex(buffer){$.checkArgumentType(buffer,"Buffer","buffer");return buffer.toString("hex")},reverse:function reverse(param){return Buffer.from(param).reverse()},hexToBuffer:function hexToBuffer(string){assert(js.isHexa(string));return new buffer.Buffer(string,"hex")}};module.exports.NULL_HASH=module.exports.fill(Buffer.alloc(32),0);module.exports.EMPTY_BUFFER=Buffer.alloc(0)}).call(this)}).call(this,require("buffer").Buffer)},{"./js":46,"./preconditions":47,assert:108,buffer:159}],46:[function(require,module,exports){"use strict";var _=require("lodash");var isHexa=function isHexa(value){if(!_.isString(value)){return false}return/^[0-9a-fA-F]+$/.test(value)};module.exports={isValidJSON:function isValidJSON(arg){var parsed;if(!_.isString(arg)){return false}try{parsed=JSON.parse(arg)}catch(e){return false}if(typeof parsed==="object"){return true}return false},isHexa:isHexa,isHexaString:isHexa,cloneArray:function(array){return[].concat(array)},defineImmutable:function defineImmutable(target,values){Object.keys(values).forEach(function(key){Object.defineProperty(target,key,{configurable:false,enumerable:true,value:values[key]})});return target},isNaturalNumber:function isNaturalNumber(value){return typeof value==="number"&&isFinite(value)&&Math.floor(value)===value&&value>=0}}},{lodash:84}],47:[function(require,module,exports){"use strict";var errors=require("../errors");var _=require("lodash");module.exports={checkState:function(condition,message){if(!condition){throw new errors.InvalidState(message)}},checkArgument:function(condition,argumentName,message,docsPath){if(!condition){throw new errors.InvalidArgument(argumentName,message,docsPath)}},checkArgumentType:function(argument,type,argumentName){argumentName=argumentName||"(unknown name)";if(_.isString(type)){if(type==="Buffer"){var BufferUtil=require("./buffer");if(!BufferUtil.isBuffer(argument)){throw new errors.InvalidArgumentType(argument,type,argumentName)}}else if(typeof argument!==type){throw new errors.InvalidArgumentType(argument,type,argumentName)}}else{if(!(argument instanceof type)){throw new errors.InvalidArgumentType(argument,type.name,argumentName)}}}}},{"../errors":18,"./buffer":45,lodash:84}],48:[function(require,module,exports){"use strict";var _Buffer=require("safe-buffer").Buffer;function base(ALPHABET){if(ALPHABET.length>=255){throw new TypeError("Alphabet too long")}var BASE_MAP=new Uint8Array(256);for(var j=0;j>>0;var b58=new Uint8Array(size);while(pbegin!==pend){var carry=source[pbegin];var i=0;for(var it1=size-1;(carry!==0||i>>0;b58[it1]=carry%BASE>>>0;carry=carry/BASE>>>0}if(carry!==0){throw new Error("Non-zero carry")}length=i;pbegin++}var it2=size-length;while(it2!==size&&b58[it2]===0){it2++}var str=LEADER.repeat(zeroes);for(;it2>>0;var b256=new Uint8Array(size);while(source[psz]){var carry=BASE_MAP[source.charCodeAt(psz)];if(carry===255){return}var i=0;for(var it3=size-1;(carry!==0||i>>0;b256[it3]=carry%256>>>0;carry=carry/256>>>0}if(carry!==0){throw new Error("Non-zero carry")}length=i;psz++}if(source[psz]===" "){return}var it4=size-length;while(it4!==size&&b256[it4]===0){it4++}var vch=_Buffer.allocUnsafe(zeroes+(size-it4));vch.fill(0,0,zeroes);var j=zeroes;while(it4!==size){vch[j++]=b256[it4++]}return vch}function decode(string){var buffer=decodeUnsafe(string);if(buffer){return buffer}throw new Error("Non-base"+BASE+" character")}return{encode:encode,decodeUnsafe:decodeUnsafe,decode:decode}}module.exports=base},{"safe-buffer":87}],49:[function(require,module,exports){(function(module,exports){"use strict";function assert(val,msg){if(!val)throw new Error(msg||"Assertion failed")}function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}function BN(number,base,endian){if(BN.isBN(number)){return number}this.negative=0;this.words=null;this.length=0;this.red=null;if(number!==null){if(base==="le"||base==="be"){endian=base;base=10}this._init(number||0,base||10,endian||"be")}}if(typeof module==="object"){module.exports=BN}else{exports.BN=BN}BN.BN=BN;BN.wordSize=26;var Buffer;try{Buffer=require("buffer").Buffer}catch(e){}BN.isBN=function isBN(num){if(num instanceof BN){return true}return num!==null&&typeof num==="object"&&num.constructor.wordSize===BN.wordSize&&Array.isArray(num.words)};BN.max=function max(left,right){if(left.cmp(right)>0)return left;return right};BN.min=function min(left,right){if(left.cmp(right)<0)return left;return right};BN.prototype._init=function init(number,base,endian){if(typeof number==="number"){return this._initNumber(number,base,endian)}if(typeof number==="object"){return this._initArray(number,base,endian)}if(base==="hex"){base=16}assert(base===(base|0)&&base>=2&&base<=36);number=number.toString().replace(/\s+/g,"");var start=0;if(number[0]==="-"){start++}if(base===16){this._parseHex(number,start)}else{this._parseBase(number,base,start)}if(number[0]==="-"){this.negative=1}this.strip();if(endian!=="le")return;this._initArray(this.toArray(),base,endian)};BN.prototype._initNumber=function _initNumber(number,base,endian){if(number<0){this.negative=1;number=-number}if(number<67108864){this.words=[number&67108863];this.length=1}else if(number<4503599627370496){this.words=[number&67108863,number/67108864&67108863];this.length=2}else{assert(number<9007199254740992);this.words=[number&67108863,number/67108864&67108863,1];this.length=3}if(endian!=="le")return;this._initArray(this.toArray(),base,endian)};BN.prototype._initArray=function _initArray(number,base,endian){assert(typeof number.length==="number");if(number.length<=0){this.words=[0];this.length=1;return this}this.length=Math.ceil(number.length/3);this.words=new Array(this.length);for(var i=0;i=0;i-=3){w=number[i]|number[i-1]<<8|number[i-2]<<16;this.words[j]|=w<>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}else if(endian==="le"){for(i=0,j=0;i>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}return this.strip()};function parseHex(str,start,end){var r=0;var len=Math.min(str.length,end);for(var i=start;i=49&&c<=54){r|=c-49+10}else if(c>=17&&c<=22){r|=c-17+10}else{r|=c&15}}return r}BN.prototype._parseHex=function _parseHex(number,start){this.length=Math.ceil((number.length-start)/6);this.words=new Array(this.length);for(var i=0;i=start;i-=6){w=parseHex(number,i,i+6);this.words[j]|=w<>>26-off&4194303;off+=24;if(off>=26){off-=26;j++}}if(i+6!==start){w=parseHex(number,start,i+6);this.words[j]|=w<>>26-off&4194303}this.strip()};function parseBase(str,start,end,mul){var r=0;var len=Math.min(str.length,end);for(var i=start;i=49){r+=c-49+10}else if(c>=17){r+=c-17+10}else{r+=c}}return r}BN.prototype._parseBase=function _parseBase(number,base,start){this.words=[0];this.length=1;for(var limbLen=0,limbPow=1;limbPow<=67108863;limbPow*=base){limbLen++}limbLen--;limbPow=limbPow/base|0;var total=number.length-start;var mod=total%limbLen;var end=Math.min(total,total-mod)+start;var word=0;for(var i=start;i1&&this.words[this.length-1]===0){this.length--}return this._normSign()};BN.prototype._normSign=function _normSign(){if(this.length===1&&this.words[0]===0){this.negative=0}return this};BN.prototype.inspect=function inspect(){return(this.red?""};var zeros=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"];var groupSizes=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5];var groupBases=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];BN.prototype.toString=function toString(base,padding){base=base||10;padding=padding|0||1;var out;if(base===16||base==="hex"){out="";var off=0;var carry=0;for(var i=0;i>>24-off&16777215;if(carry!==0||i!==this.length-1){out=zeros[6-word.length]+word+out}else{out=word+out}off+=2;if(off>=26){off-=26;i--}}if(carry!==0){out=carry.toString(16)+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}if(base===(base|0)&&base>=2&&base<=36){var groupSize=groupSizes[base];var groupBase=groupBases[base];out="";var c=this.clone();c.negative=0;while(!c.isZero()){var r=c.modn(groupBase).toString(base);c=c.idivn(groupBase);if(!c.isZero()){out=zeros[groupSize-r.length]+r+out}else{out=r+out}}if(this.isZero()){out="0"+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}assert(false,"Base should be between 2 and 36")};BN.prototype.toNumber=function toNumber(){var ret=this.words[0];if(this.length===2){ret+=this.words[1]*67108864}else if(this.length===3&&this.words[2]===1){ret+=4503599627370496+this.words[1]*67108864}else if(this.length>2){assert(false,"Number can only safely store up to 53 bits")}return this.negative!==0?-ret:ret};BN.prototype.toJSON=function toJSON(){return this.toString(16)};BN.prototype.toBuffer=function toBuffer(endian,length){assert(typeof Buffer!=="undefined");return this.toArrayLike(Buffer,endian,length)};BN.prototype.toArray=function toArray(endian,length){return this.toArrayLike(Array,endian,length)};BN.prototype.toArrayLike=function toArrayLike(ArrayType,endian,length){var byteLength=this.byteLength();var reqLength=length||Math.max(1,byteLength);assert(byteLength<=reqLength,"byte array longer than desired length");assert(reqLength>0,"Requested array length <= 0");this.strip();var littleEndian=endian==="le";var res=new ArrayType(reqLength);var b,i;var q=this.clone();if(!littleEndian){for(i=0;i=4096){r+=13;t>>>=13}if(t>=64){r+=7;t>>>=7}if(t>=8){r+=4;t>>>=4}if(t>=2){r+=2;t>>>=2}return r+t}}BN.prototype._zeroBits=function _zeroBits(w){if(w===0)return 26;var t=w;var r=0;if((t&8191)===0){r+=13;t>>>=13}if((t&127)===0){r+=7;t>>>=7}if((t&15)===0){r+=4;t>>>=4}if((t&3)===0){r+=2;t>>>=2}if((t&1)===0){r++}return r};BN.prototype.bitLength=function bitLength(){var w=this.words[this.length-1];var hi=this._countBits(w);return(this.length-1)*26+hi};function toBitArray(num){var w=new Array(num.bitLength());for(var bit=0;bit>>wbit}return w}BN.prototype.zeroBits=function zeroBits(){if(this.isZero())return 0;var r=0;for(var i=0;inum.length)return this.clone().ior(num);return num.clone().ior(this)};BN.prototype.uor=function uor(num){if(this.length>num.length)return this.clone().iuor(num);return num.clone().iuor(this)};BN.prototype.iuand=function iuand(num){var b;if(this.length>num.length){b=num}else{b=this}for(var i=0;inum.length)return this.clone().iand(num);return num.clone().iand(this)};BN.prototype.uand=function uand(num){if(this.length>num.length)return this.clone().iuand(num);return num.clone().iuand(this)};BN.prototype.iuxor=function iuxor(num){var a;var b;if(this.length>num.length){a=this;b=num}else{a=num;b=this}for(var i=0;inum.length)return this.clone().ixor(num);return num.clone().ixor(this)};BN.prototype.uxor=function uxor(num){if(this.length>num.length)return this.clone().iuxor(num);return num.clone().iuxor(this)};BN.prototype.inotn=function inotn(width){assert(typeof width==="number"&&width>=0);var bytesNeeded=Math.ceil(width/26)|0;var bitsLeft=width%26;this._expand(bytesNeeded);if(bitsLeft>0){bytesNeeded--}for(var i=0;i0){this.words[i]=~this.words[i]&67108863>>26-bitsLeft}return this.strip()};BN.prototype.notn=function notn(width){return this.clone().inotn(width)};BN.prototype.setn=function setn(bit,val){assert(typeof bit==="number"&&bit>=0);var off=bit/26|0;var wbit=bit%26;this._expand(off+1);if(val){this.words[off]=this.words[off]|1<num.length){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>>26}for(;carry!==0&&i>>26}this.length=a.length;if(carry!==0){this.words[this.length]=carry;this.length++}else if(a!==this){for(;inum.length)return this.clone().iadd(num);return num.clone().iadd(this)};BN.prototype.isub=function isub(num){if(num.negative!==0){num.negative=0;var r=this.iadd(num);num.negative=1;return r._normSign()}else if(this.negative!==0){this.negative=0;this.iadd(num);this.negative=1;return this._normSign()}var cmp=this.cmp(num);if(cmp===0){this.negative=0;this.length=1;this.words[0]=0;return this}var a,b;if(cmp>0){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>26;this.words[i]=r&67108863}for(;carry!==0&&i>26;this.words[i]=r&67108863}if(carry===0&&i>>26;var rword=carry&67108863;var maxJ=Math.min(k,num.length-1);for(var j=Math.max(0,k-self.length+1);j<=maxJ;j++){var i=k-j|0;a=self.words[i]|0;b=num.words[j]|0;r=a*b+rword;ncarry+=r/67108864|0;rword=r&67108863}out.words[k]=rword|0;carry=ncarry|0}if(carry!==0){out.words[k]=carry|0}else{out.length--}return out.strip()}var comb10MulTo=function comb10MulTo(self,num,out){var a=self.words;var b=num.words;var o=out.words;var c=0;var lo;var mid;var hi;var a0=a[0]|0;var al0=a0&8191;var ah0=a0>>>13;var a1=a[1]|0;var al1=a1&8191;var ah1=a1>>>13;var a2=a[2]|0;var al2=a2&8191;var ah2=a2>>>13;var a3=a[3]|0;var al3=a3&8191;var ah3=a3>>>13;var a4=a[4]|0;var al4=a4&8191;var ah4=a4>>>13;var a5=a[5]|0;var al5=a5&8191;var ah5=a5>>>13;var a6=a[6]|0;var al6=a6&8191;var ah6=a6>>>13;var a7=a[7]|0;var al7=a7&8191;var ah7=a7>>>13;var a8=a[8]|0;var al8=a8&8191;var ah8=a8>>>13;var a9=a[9]|0;var al9=a9&8191;var ah9=a9>>>13;var b0=b[0]|0;var bl0=b0&8191;var bh0=b0>>>13;var b1=b[1]|0;var bl1=b1&8191;var bh1=b1>>>13;var b2=b[2]|0;var bl2=b2&8191;var bh2=b2>>>13;var b3=b[3]|0;var bl3=b3&8191;var bh3=b3>>>13;var b4=b[4]|0;var bl4=b4&8191;var bh4=b4>>>13;var b5=b[5]|0;var bl5=b5&8191;var bh5=b5>>>13;var b6=b[6]|0;var bl6=b6&8191;var bh6=b6>>>13;var b7=b[7]|0;var bl7=b7&8191;var bh7=b7>>>13;var b8=b[8]|0;var bl8=b8&8191;var bh8=b8>>>13;var b9=b[9]|0;var bl9=b9&8191;var bh9=b9>>>13;out.negative=self.negative^num.negative;out.length=19;lo=Math.imul(al0,bl0);mid=Math.imul(al0,bh0);mid=mid+Math.imul(ah0,bl0)|0;hi=Math.imul(ah0,bh0);var w0=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w0>>>26)|0;w0&=67108863;lo=Math.imul(al1,bl0);mid=Math.imul(al1,bh0);mid=mid+Math.imul(ah1,bl0)|0;hi=Math.imul(ah1,bh0);lo=lo+Math.imul(al0,bl1)|0;mid=mid+Math.imul(al0,bh1)|0;mid=mid+Math.imul(ah0,bl1)|0;hi=hi+Math.imul(ah0,bh1)|0;var w1=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w1>>>26)|0;w1&=67108863;lo=Math.imul(al2,bl0);mid=Math.imul(al2,bh0);mid=mid+Math.imul(ah2,bl0)|0;hi=Math.imul(ah2,bh0);lo=lo+Math.imul(al1,bl1)|0;mid=mid+Math.imul(al1,bh1)|0;mid=mid+Math.imul(ah1,bl1)|0;hi=hi+Math.imul(ah1,bh1)|0;lo=lo+Math.imul(al0,bl2)|0;mid=mid+Math.imul(al0,bh2)|0;mid=mid+Math.imul(ah0,bl2)|0;hi=hi+Math.imul(ah0,bh2)|0;var w2=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w2>>>26)|0;w2&=67108863;lo=Math.imul(al3,bl0);mid=Math.imul(al3,bh0);mid=mid+Math.imul(ah3,bl0)|0;hi=Math.imul(ah3,bh0);lo=lo+Math.imul(al2,bl1)|0;mid=mid+Math.imul(al2,bh1)|0;mid=mid+Math.imul(ah2,bl1)|0;hi=hi+Math.imul(ah2,bh1)|0;lo=lo+Math.imul(al1,bl2)|0;mid=mid+Math.imul(al1,bh2)|0;mid=mid+Math.imul(ah1,bl2)|0;hi=hi+Math.imul(ah1,bh2)|0;lo=lo+Math.imul(al0,bl3)|0;mid=mid+Math.imul(al0,bh3)|0;mid=mid+Math.imul(ah0,bl3)|0;hi=hi+Math.imul(ah0,bh3)|0;var w3=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w3>>>26)|0;w3&=67108863;lo=Math.imul(al4,bl0);mid=Math.imul(al4,bh0);mid=mid+Math.imul(ah4,bl0)|0;hi=Math.imul(ah4,bh0);lo=lo+Math.imul(al3,bl1)|0;mid=mid+Math.imul(al3,bh1)|0;mid=mid+Math.imul(ah3,bl1)|0;hi=hi+Math.imul(ah3,bh1)|0;lo=lo+Math.imul(al2,bl2)|0;mid=mid+Math.imul(al2,bh2)|0;mid=mid+Math.imul(ah2,bl2)|0;hi=hi+Math.imul(ah2,bh2)|0;lo=lo+Math.imul(al1,bl3)|0;mid=mid+Math.imul(al1,bh3)|0;mid=mid+Math.imul(ah1,bl3)|0;hi=hi+Math.imul(ah1,bh3)|0;lo=lo+Math.imul(al0,bl4)|0;mid=mid+Math.imul(al0,bh4)|0;mid=mid+Math.imul(ah0,bl4)|0;hi=hi+Math.imul(ah0,bh4)|0;var w4=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w4>>>26)|0;w4&=67108863;lo=Math.imul(al5,bl0);mid=Math.imul(al5,bh0);mid=mid+Math.imul(ah5,bl0)|0;hi=Math.imul(ah5,bh0);lo=lo+Math.imul(al4,bl1)|0;mid=mid+Math.imul(al4,bh1)|0;mid=mid+Math.imul(ah4,bl1)|0;hi=hi+Math.imul(ah4,bh1)|0;lo=lo+Math.imul(al3,bl2)|0;mid=mid+Math.imul(al3,bh2)|0;mid=mid+Math.imul(ah3,bl2)|0;hi=hi+Math.imul(ah3,bh2)|0;lo=lo+Math.imul(al2,bl3)|0;mid=mid+Math.imul(al2,bh3)|0;mid=mid+Math.imul(ah2,bl3)|0;hi=hi+Math.imul(ah2,bh3)|0;lo=lo+Math.imul(al1,bl4)|0;mid=mid+Math.imul(al1,bh4)|0;mid=mid+Math.imul(ah1,bl4)|0;hi=hi+Math.imul(ah1,bh4)|0;lo=lo+Math.imul(al0,bl5)|0;mid=mid+Math.imul(al0,bh5)|0;mid=mid+Math.imul(ah0,bl5)|0;hi=hi+Math.imul(ah0,bh5)|0;var w5=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w5>>>26)|0;w5&=67108863;lo=Math.imul(al6,bl0);mid=Math.imul(al6,bh0);mid=mid+Math.imul(ah6,bl0)|0;hi=Math.imul(ah6,bh0);lo=lo+Math.imul(al5,bl1)|0;mid=mid+Math.imul(al5,bh1)|0;mid=mid+Math.imul(ah5,bl1)|0;hi=hi+Math.imul(ah5,bh1)|0;lo=lo+Math.imul(al4,bl2)|0;mid=mid+Math.imul(al4,bh2)|0;mid=mid+Math.imul(ah4,bl2)|0;hi=hi+Math.imul(ah4,bh2)|0;lo=lo+Math.imul(al3,bl3)|0;mid=mid+Math.imul(al3,bh3)|0;mid=mid+Math.imul(ah3,bl3)|0;hi=hi+Math.imul(ah3,bh3)|0;lo=lo+Math.imul(al2,bl4)|0;mid=mid+Math.imul(al2,bh4)|0;mid=mid+Math.imul(ah2,bl4)|0;hi=hi+Math.imul(ah2,bh4)|0;lo=lo+Math.imul(al1,bl5)|0;mid=mid+Math.imul(al1,bh5)|0;mid=mid+Math.imul(ah1,bl5)|0;hi=hi+Math.imul(ah1,bh5)|0;lo=lo+Math.imul(al0,bl6)|0;mid=mid+Math.imul(al0,bh6)|0;mid=mid+Math.imul(ah0,bl6)|0;hi=hi+Math.imul(ah0,bh6)|0;var w6=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w6>>>26)|0;w6&=67108863;lo=Math.imul(al7,bl0);mid=Math.imul(al7,bh0);mid=mid+Math.imul(ah7,bl0)|0;hi=Math.imul(ah7,bh0);lo=lo+Math.imul(al6,bl1)|0;mid=mid+Math.imul(al6,bh1)|0;mid=mid+Math.imul(ah6,bl1)|0;hi=hi+Math.imul(ah6,bh1)|0;lo=lo+Math.imul(al5,bl2)|0;mid=mid+Math.imul(al5,bh2)|0;mid=mid+Math.imul(ah5,bl2)|0;hi=hi+Math.imul(ah5,bh2)|0;lo=lo+Math.imul(al4,bl3)|0;mid=mid+Math.imul(al4,bh3)|0;mid=mid+Math.imul(ah4,bl3)|0;hi=hi+Math.imul(ah4,bh3)|0;lo=lo+Math.imul(al3,bl4)|0;mid=mid+Math.imul(al3,bh4)|0;mid=mid+Math.imul(ah3,bl4)|0;hi=hi+Math.imul(ah3,bh4)|0;lo=lo+Math.imul(al2,bl5)|0;mid=mid+Math.imul(al2,bh5)|0;mid=mid+Math.imul(ah2,bl5)|0;hi=hi+Math.imul(ah2,bh5)|0;lo=lo+Math.imul(al1,bl6)|0;mid=mid+Math.imul(al1,bh6)|0;mid=mid+Math.imul(ah1,bl6)|0;hi=hi+Math.imul(ah1,bh6)|0;lo=lo+Math.imul(al0,bl7)|0;mid=mid+Math.imul(al0,bh7)|0;mid=mid+Math.imul(ah0,bl7)|0;hi=hi+Math.imul(ah0,bh7)|0;var w7=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w7>>>26)|0;w7&=67108863;lo=Math.imul(al8,bl0);mid=Math.imul(al8,bh0);mid=mid+Math.imul(ah8,bl0)|0;hi=Math.imul(ah8,bh0);lo=lo+Math.imul(al7,bl1)|0;mid=mid+Math.imul(al7,bh1)|0;mid=mid+Math.imul(ah7,bl1)|0;hi=hi+Math.imul(ah7,bh1)|0;lo=lo+Math.imul(al6,bl2)|0;mid=mid+Math.imul(al6,bh2)|0;mid=mid+Math.imul(ah6,bl2)|0;hi=hi+Math.imul(ah6,bh2)|0;lo=lo+Math.imul(al5,bl3)|0;mid=mid+Math.imul(al5,bh3)|0;mid=mid+Math.imul(ah5,bl3)|0;hi=hi+Math.imul(ah5,bh3)|0;lo=lo+Math.imul(al4,bl4)|0;mid=mid+Math.imul(al4,bh4)|0;mid=mid+Math.imul(ah4,bl4)|0;hi=hi+Math.imul(ah4,bh4)|0;lo=lo+Math.imul(al3,bl5)|0;mid=mid+Math.imul(al3,bh5)|0;mid=mid+Math.imul(ah3,bl5)|0;hi=hi+Math.imul(ah3,bh5)|0;lo=lo+Math.imul(al2,bl6)|0;mid=mid+Math.imul(al2,bh6)|0;mid=mid+Math.imul(ah2,bl6)|0;hi=hi+Math.imul(ah2,bh6)|0;lo=lo+Math.imul(al1,bl7)|0;mid=mid+Math.imul(al1,bh7)|0;mid=mid+Math.imul(ah1,bl7)|0;hi=hi+Math.imul(ah1,bh7)|0;lo=lo+Math.imul(al0,bl8)|0;mid=mid+Math.imul(al0,bh8)|0;mid=mid+Math.imul(ah0,bl8)|0;hi=hi+Math.imul(ah0,bh8)|0;var w8=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w8>>>26)|0;w8&=67108863;lo=Math.imul(al9,bl0);mid=Math.imul(al9,bh0);mid=mid+Math.imul(ah9,bl0)|0;hi=Math.imul(ah9,bh0);lo=lo+Math.imul(al8,bl1)|0;mid=mid+Math.imul(al8,bh1)|0;mid=mid+Math.imul(ah8,bl1)|0;hi=hi+Math.imul(ah8,bh1)|0;lo=lo+Math.imul(al7,bl2)|0;mid=mid+Math.imul(al7,bh2)|0;mid=mid+Math.imul(ah7,bl2)|0;hi=hi+Math.imul(ah7,bh2)|0;lo=lo+Math.imul(al6,bl3)|0;mid=mid+Math.imul(al6,bh3)|0;mid=mid+Math.imul(ah6,bl3)|0;hi=hi+Math.imul(ah6,bh3)|0;lo=lo+Math.imul(al5,bl4)|0;mid=mid+Math.imul(al5,bh4)|0;mid=mid+Math.imul(ah5,bl4)|0;hi=hi+Math.imul(ah5,bh4)|0;lo=lo+Math.imul(al4,bl5)|0;mid=mid+Math.imul(al4,bh5)|0;mid=mid+Math.imul(ah4,bl5)|0;hi=hi+Math.imul(ah4,bh5)|0;lo=lo+Math.imul(al3,bl6)|0;mid=mid+Math.imul(al3,bh6)|0;mid=mid+Math.imul(ah3,bl6)|0;hi=hi+Math.imul(ah3,bh6)|0;lo=lo+Math.imul(al2,bl7)|0;mid=mid+Math.imul(al2,bh7)|0;mid=mid+Math.imul(ah2,bl7)|0;hi=hi+Math.imul(ah2,bh7)|0;lo=lo+Math.imul(al1,bl8)|0;mid=mid+Math.imul(al1,bh8)|0;mid=mid+Math.imul(ah1,bl8)|0;hi=hi+Math.imul(ah1,bh8)|0;lo=lo+Math.imul(al0,bl9)|0;mid=mid+Math.imul(al0,bh9)|0;mid=mid+Math.imul(ah0,bl9)|0;hi=hi+Math.imul(ah0,bh9)|0;var w9=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w9>>>26)|0;w9&=67108863;lo=Math.imul(al9,bl1);mid=Math.imul(al9,bh1);mid=mid+Math.imul(ah9,bl1)|0;hi=Math.imul(ah9,bh1);lo=lo+Math.imul(al8,bl2)|0;mid=mid+Math.imul(al8,bh2)|0;mid=mid+Math.imul(ah8,bl2)|0;hi=hi+Math.imul(ah8,bh2)|0;lo=lo+Math.imul(al7,bl3)|0;mid=mid+Math.imul(al7,bh3)|0;mid=mid+Math.imul(ah7,bl3)|0;hi=hi+Math.imul(ah7,bh3)|0;lo=lo+Math.imul(al6,bl4)|0;mid=mid+Math.imul(al6,bh4)|0;mid=mid+Math.imul(ah6,bl4)|0;hi=hi+Math.imul(ah6,bh4)|0;lo=lo+Math.imul(al5,bl5)|0;mid=mid+Math.imul(al5,bh5)|0;mid=mid+Math.imul(ah5,bl5)|0;hi=hi+Math.imul(ah5,bh5)|0;lo=lo+Math.imul(al4,bl6)|0;mid=mid+Math.imul(al4,bh6)|0;mid=mid+Math.imul(ah4,bl6)|0;hi=hi+Math.imul(ah4,bh6)|0;lo=lo+Math.imul(al3,bl7)|0;mid=mid+Math.imul(al3,bh7)|0;mid=mid+Math.imul(ah3,bl7)|0;hi=hi+Math.imul(ah3,bh7)|0;lo=lo+Math.imul(al2,bl8)|0;mid=mid+Math.imul(al2,bh8)|0;mid=mid+Math.imul(ah2,bl8)|0;hi=hi+Math.imul(ah2,bh8)|0;lo=lo+Math.imul(al1,bl9)|0;mid=mid+Math.imul(al1,bh9)|0;mid=mid+Math.imul(ah1,bl9)|0;hi=hi+Math.imul(ah1,bh9)|0;var w10=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w10>>>26)|0;w10&=67108863;lo=Math.imul(al9,bl2);mid=Math.imul(al9,bh2);mid=mid+Math.imul(ah9,bl2)|0;hi=Math.imul(ah9,bh2);lo=lo+Math.imul(al8,bl3)|0;mid=mid+Math.imul(al8,bh3)|0;mid=mid+Math.imul(ah8,bl3)|0;hi=hi+Math.imul(ah8,bh3)|0;lo=lo+Math.imul(al7,bl4)|0;mid=mid+Math.imul(al7,bh4)|0;mid=mid+Math.imul(ah7,bl4)|0;hi=hi+Math.imul(ah7,bh4)|0;lo=lo+Math.imul(al6,bl5)|0;mid=mid+Math.imul(al6,bh5)|0;mid=mid+Math.imul(ah6,bl5)|0;hi=hi+Math.imul(ah6,bh5)|0;lo=lo+Math.imul(al5,bl6)|0;mid=mid+Math.imul(al5,bh6)|0;mid=mid+Math.imul(ah5,bl6)|0;hi=hi+Math.imul(ah5,bh6)|0;lo=lo+Math.imul(al4,bl7)|0;mid=mid+Math.imul(al4,bh7)|0;mid=mid+Math.imul(ah4,bl7)|0;hi=hi+Math.imul(ah4,bh7)|0;lo=lo+Math.imul(al3,bl8)|0;mid=mid+Math.imul(al3,bh8)|0;mid=mid+Math.imul(ah3,bl8)|0;hi=hi+Math.imul(ah3,bh8)|0;lo=lo+Math.imul(al2,bl9)|0;mid=mid+Math.imul(al2,bh9)|0;mid=mid+Math.imul(ah2,bl9)|0;hi=hi+Math.imul(ah2,bh9)|0;var w11=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w11>>>26)|0;w11&=67108863;lo=Math.imul(al9,bl3);mid=Math.imul(al9,bh3);mid=mid+Math.imul(ah9,bl3)|0;hi=Math.imul(ah9,bh3);lo=lo+Math.imul(al8,bl4)|0;mid=mid+Math.imul(al8,bh4)|0;mid=mid+Math.imul(ah8,bl4)|0;hi=hi+Math.imul(ah8,bh4)|0;lo=lo+Math.imul(al7,bl5)|0;mid=mid+Math.imul(al7,bh5)|0;mid=mid+Math.imul(ah7,bl5)|0;hi=hi+Math.imul(ah7,bh5)|0;lo=lo+Math.imul(al6,bl6)|0;mid=mid+Math.imul(al6,bh6)|0;mid=mid+Math.imul(ah6,bl6)|0;hi=hi+Math.imul(ah6,bh6)|0;lo=lo+Math.imul(al5,bl7)|0;mid=mid+Math.imul(al5,bh7)|0;mid=mid+Math.imul(ah5,bl7)|0;hi=hi+Math.imul(ah5,bh7)|0;lo=lo+Math.imul(al4,bl8)|0;mid=mid+Math.imul(al4,bh8)|0;mid=mid+Math.imul(ah4,bl8)|0;hi=hi+Math.imul(ah4,bh8)|0;lo=lo+Math.imul(al3,bl9)|0;mid=mid+Math.imul(al3,bh9)|0;mid=mid+Math.imul(ah3,bl9)|0;hi=hi+Math.imul(ah3,bh9)|0;var w12=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w12>>>26)|0;w12&=67108863;lo=Math.imul(al9,bl4);mid=Math.imul(al9,bh4);mid=mid+Math.imul(ah9,bl4)|0;hi=Math.imul(ah9,bh4);lo=lo+Math.imul(al8,bl5)|0;mid=mid+Math.imul(al8,bh5)|0;mid=mid+Math.imul(ah8,bl5)|0;hi=hi+Math.imul(ah8,bh5)|0;lo=lo+Math.imul(al7,bl6)|0;mid=mid+Math.imul(al7,bh6)|0;mid=mid+Math.imul(ah7,bl6)|0;hi=hi+Math.imul(ah7,bh6)|0;lo=lo+Math.imul(al6,bl7)|0;mid=mid+Math.imul(al6,bh7)|0;mid=mid+Math.imul(ah6,bl7)|0;hi=hi+Math.imul(ah6,bh7)|0;lo=lo+Math.imul(al5,bl8)|0;mid=mid+Math.imul(al5,bh8)|0;mid=mid+Math.imul(ah5,bl8)|0;hi=hi+Math.imul(ah5,bh8)|0;lo=lo+Math.imul(al4,bl9)|0;mid=mid+Math.imul(al4,bh9)|0;mid=mid+Math.imul(ah4,bl9)|0;hi=hi+Math.imul(ah4,bh9)|0;var w13=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w13>>>26)|0;w13&=67108863;lo=Math.imul(al9,bl5);mid=Math.imul(al9,bh5);mid=mid+Math.imul(ah9,bl5)|0;hi=Math.imul(ah9,bh5);lo=lo+Math.imul(al8,bl6)|0;mid=mid+Math.imul(al8,bh6)|0;mid=mid+Math.imul(ah8,bl6)|0;hi=hi+Math.imul(ah8,bh6)|0;lo=lo+Math.imul(al7,bl7)|0;mid=mid+Math.imul(al7,bh7)|0;mid=mid+Math.imul(ah7,bl7)|0;hi=hi+Math.imul(ah7,bh7)|0;lo=lo+Math.imul(al6,bl8)|0;mid=mid+Math.imul(al6,bh8)|0;mid=mid+Math.imul(ah6,bl8)|0;hi=hi+Math.imul(ah6,bh8)|0;lo=lo+Math.imul(al5,bl9)|0;mid=mid+Math.imul(al5,bh9)|0;mid=mid+Math.imul(ah5,bl9)|0;hi=hi+Math.imul(ah5,bh9)|0;var w14=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w14>>>26)|0;w14&=67108863;lo=Math.imul(al9,bl6);mid=Math.imul(al9,bh6);mid=mid+Math.imul(ah9,bl6)|0;hi=Math.imul(ah9,bh6);lo=lo+Math.imul(al8,bl7)|0;mid=mid+Math.imul(al8,bh7)|0;mid=mid+Math.imul(ah8,bl7)|0;hi=hi+Math.imul(ah8,bh7)|0;lo=lo+Math.imul(al7,bl8)|0;mid=mid+Math.imul(al7,bh8)|0;mid=mid+Math.imul(ah7,bl8)|0;hi=hi+Math.imul(ah7,bh8)|0;lo=lo+Math.imul(al6,bl9)|0;mid=mid+Math.imul(al6,bh9)|0;mid=mid+Math.imul(ah6,bl9)|0;hi=hi+Math.imul(ah6,bh9)|0;var w15=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w15>>>26)|0;w15&=67108863;lo=Math.imul(al9,bl7);mid=Math.imul(al9,bh7);mid=mid+Math.imul(ah9,bl7)|0;hi=Math.imul(ah9,bh7);lo=lo+Math.imul(al8,bl8)|0;mid=mid+Math.imul(al8,bh8)|0;mid=mid+Math.imul(ah8,bl8)|0;hi=hi+Math.imul(ah8,bh8)|0;lo=lo+Math.imul(al7,bl9)|0;mid=mid+Math.imul(al7,bh9)|0;mid=mid+Math.imul(ah7,bl9)|0;hi=hi+Math.imul(ah7,bh9)|0;var w16=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w16>>>26)|0;w16&=67108863;lo=Math.imul(al9,bl8);mid=Math.imul(al9,bh8);mid=mid+Math.imul(ah9,bl8)|0;hi=Math.imul(ah9,bh8);lo=lo+Math.imul(al8,bl9)|0;mid=mid+Math.imul(al8,bh9)|0;mid=mid+Math.imul(ah8,bl9)|0;hi=hi+Math.imul(ah8,bh9)|0;var w17=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w17>>>26)|0;w17&=67108863;lo=Math.imul(al9,bl9);mid=Math.imul(al9,bh9);mid=mid+Math.imul(ah9,bl9)|0;hi=Math.imul(ah9,bh9);var w18=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w18>>>26)|0;w18&=67108863;o[0]=w0;o[1]=w1;o[2]=w2;o[3]=w3;o[4]=w4;o[5]=w5;o[6]=w6;o[7]=w7;o[8]=w8;o[9]=w9;o[10]=w10;o[11]=w11;o[12]=w12;o[13]=w13;o[14]=w14;o[15]=w15;o[16]=w16;o[17]=w17;o[18]=w18;if(c!==0){o[19]=c;out.length++}return out};if(!Math.imul){comb10MulTo=smallMulTo}function bigMulTo(self,num,out){out.negative=num.negative^self.negative;out.length=self.length+num.length;var carry=0;var hncarry=0;for(var k=0;k>>26)|0;hncarry+=ncarry>>>26;ncarry&=67108863}out.words[k]=rword;carry=ncarry;ncarry=hncarry}if(carry!==0){out.words[k]=carry}else{out.length--}return out.strip()}function jumboMulTo(self,num,out){var fftm=new FFTM;return fftm.mulp(self,num,out)}BN.prototype.mulTo=function mulTo(num,out){var res;var len=this.length+num.length;if(this.length===10&&num.length===10){res=comb10MulTo(this,num,out)}else if(len<63){res=smallMulTo(this,num,out)}else if(len<1024){res=bigMulTo(this,num,out)}else{res=jumboMulTo(this,num,out)}return res};function FFTM(x,y){this.x=x;this.y=y}FFTM.prototype.makeRBT=function makeRBT(N){var t=new Array(N);var l=BN.prototype._countBits(N)-1;for(var i=0;i>=1}return rb};FFTM.prototype.permute=function permute(rbt,rws,iws,rtws,itws,N){for(var i=0;i>>1){i++}return 1<>>13;rws[2*i+1]=carry&8191;carry=carry>>>13}for(i=2*len;i>=26;carry+=w/67108864|0;carry+=lo>>>26;this.words[i]=lo&67108863}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.muln=function muln(num){return this.clone().imuln(num)};BN.prototype.sqr=function sqr(){return this.mul(this)};BN.prototype.isqr=function isqr(){return this.imul(this.clone())};BN.prototype.pow=function pow(num){var w=toBitArray(num);if(w.length===0)return new BN(1);var res=this;for(var i=0;i=0);var r=bits%26;var s=(bits-r)/26;var carryMask=67108863>>>26-r<<26-r;var i;if(r!==0){var carry=0;for(i=0;i>>26-r}if(carry){this.words[i]=carry;this.length++}}if(s!==0){for(i=this.length-1;i>=0;i--){this.words[i+s]=this.words[i]}for(i=0;i=0);var h;if(hint){h=(hint-hint%26)/26}else{h=0}var r=bits%26;var s=Math.min((bits-r)/26,this.length);var mask=67108863^67108863>>>r<s){this.length-=s;for(i=0;i=0&&(carry!==0||i>=h);i--){var word=this.words[i]|0;this.words[i]=carry<<26-r|word>>>r;carry=word&mask}if(maskedWords&&carry!==0){maskedWords.words[maskedWords.length++]=carry}if(this.length===0){this.words[0]=0;this.length=1}return this.strip()};BN.prototype.ishrn=function ishrn(bits,hint,extended){assert(this.negative===0);return this.iushrn(bits,hint,extended)};BN.prototype.shln=function shln(bits){return this.clone().ishln(bits)};BN.prototype.ushln=function ushln(bits){return this.clone().iushln(bits)};BN.prototype.shrn=function shrn(bits){return this.clone().ishrn(bits)};BN.prototype.ushrn=function ushrn(bits){return this.clone().iushrn(bits)};BN.prototype.testn=function testn(bit){assert(typeof bit==="number"&&bit>=0);var r=bit%26;var s=(bit-r)/26;var q=1<=0);var r=bits%26;var s=(bits-r)/26;assert(this.negative===0,"imaskn works only with positive numbers");if(this.length<=s){return this}if(r!==0){s++}this.length=Math.min(s,this.length);if(r!==0){var mask=67108863^67108863>>>r<=67108864;i++){this.words[i]-=67108864;if(i===this.length-1){this.words[i+1]=1}else{this.words[i+1]++}}this.length=Math.max(this.length,i+1);return this};BN.prototype.isubn=function isubn(num){assert(typeof num==="number");assert(num<67108864);if(num<0)return this.iaddn(-num);if(this.negative!==0){this.negative=0;this.iaddn(num);this.negative=1;return this}this.words[0]-=num;if(this.length===1&&this.words[0]<0){this.words[0]=-this.words[0];this.negative=1}else{for(var i=0;i>26)-(right/67108864|0);this.words[i+shift]=w&67108863}for(;i>26;this.words[i+shift]=w&67108863}if(carry===0)return this.strip();assert(carry===-1);carry=0;for(i=0;i>26;this.words[i]=w&67108863}this.negative=1;return this.strip()};BN.prototype._wordDiv=function _wordDiv(num,mode){var shift=this.length-num.length;var a=this.clone();var b=num;var bhi=b.words[b.length-1]|0;var bhiBits=this._countBits(bhi);shift=26-bhiBits;if(shift!==0){b=b.ushln(shift);a.iushln(shift);bhi=b.words[b.length-1]|0}var m=a.length-b.length;var q;if(mode!=="mod"){q=new BN(null);q.length=m+1;q.words=new Array(q.length);for(var i=0;i=0;j--){var qj=(a.words[b.length+j]|0)*67108864+(a.words[b.length+j-1]|0);qj=Math.min(qj/bhi|0,67108863);a._ishlnsubmul(b,qj,j);while(a.negative!==0){qj--;a.negative=0;a._ishlnsubmul(b,1,j);if(!a.isZero()){a.negative^=1}}if(q){q.words[j]=qj}}if(q){q.strip()}a.strip();if(mode!=="div"&&shift!==0){a.iushrn(shift)}return{div:q||null,mod:a}};BN.prototype.divmod=function divmod(num,mode,positive){assert(!num.isZero());if(this.isZero()){return{div:new BN(0),mod:new BN(0)}}var div,mod,res;if(this.negative!==0&&num.negative===0){res=this.neg().divmod(num,mode);if(mode!=="mod"){div=res.div.neg()}if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.iadd(num)}}return{div:div,mod:mod}}if(this.negative===0&&num.negative!==0){res=this.divmod(num.neg(),mode);if(mode!=="mod"){div=res.div.neg()}return{div:div,mod:res.mod}}if((this.negative&num.negative)!==0){res=this.neg().divmod(num.neg(),mode);if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.isub(num)}}return{div:res.div,mod:mod}}if(num.length>this.length||this.cmp(num)<0){return{div:new BN(0),mod:this}}if(num.length===1){if(mode==="div"){return{div:this.divn(num.words[0]),mod:null}}if(mode==="mod"){return{div:null,mod:new BN(this.modn(num.words[0]))}}return{div:this.divn(num.words[0]),mod:new BN(this.modn(num.words[0]))}}return this._wordDiv(num,mode)};BN.prototype.div=function div(num){return this.divmod(num,"div",false).div};BN.prototype.mod=function mod(num){return this.divmod(num,"mod",false).mod};BN.prototype.umod=function umod(num){return this.divmod(num,"mod",true).mod};BN.prototype.divRound=function divRound(num){var dm=this.divmod(num);if(dm.mod.isZero())return dm.div;var mod=dm.div.negative!==0?dm.mod.isub(num):dm.mod;var half=num.ushrn(1);var r2=num.andln(1);var cmp=mod.cmp(half);if(cmp<0||r2===1&&cmp===0)return dm.div;return dm.div.negative!==0?dm.div.isubn(1):dm.div.iaddn(1)};BN.prototype.modn=function modn(num){assert(num<=67108863);var p=(1<<26)%num;var acc=0;for(var i=this.length-1;i>=0;i--){acc=(p*acc+(this.words[i]|0))%num}return acc};BN.prototype.idivn=function idivn(num){assert(num<=67108863);var carry=0;for(var i=this.length-1;i>=0;i--){var w=(this.words[i]|0)+carry*67108864;this.words[i]=w/num|0;carry=w%num}return this.strip()};BN.prototype.divn=function divn(num){return this.clone().idivn(num)};BN.prototype.egcd=function egcd(p){assert(p.negative===0);assert(!p.isZero());var x=this;var y=p.clone();if(x.negative!==0){x=x.umod(p)}else{x=x.clone()}var A=new BN(1);var B=new BN(0);var C=new BN(0);var D=new BN(1);var g=0;while(x.isEven()&&y.isEven()){x.iushrn(1);y.iushrn(1);++g}var yp=y.clone();var xp=x.clone();while(!x.isZero()){for(var i=0,im=1;(x.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){x.iushrn(i);while(i-- >0){if(A.isOdd()||B.isOdd()){A.iadd(yp);B.isub(xp)}A.iushrn(1);B.iushrn(1)}}for(var j=0,jm=1;(y.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){y.iushrn(j);while(j-- >0){if(C.isOdd()||D.isOdd()){C.iadd(yp);D.isub(xp)}C.iushrn(1);D.iushrn(1)}}if(x.cmp(y)>=0){x.isub(y);A.isub(C);B.isub(D)}else{y.isub(x);C.isub(A);D.isub(B)}}return{a:C,b:D,gcd:y.iushln(g)}};BN.prototype._invmp=function _invmp(p){assert(p.negative===0);assert(!p.isZero());var a=this;var b=p.clone();if(a.negative!==0){a=a.umod(p)}else{a=a.clone()}var x1=new BN(1);var x2=new BN(0);var delta=b.clone();while(a.cmpn(1)>0&&b.cmpn(1)>0){for(var i=0,im=1;(a.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){a.iushrn(i);while(i-- >0){if(x1.isOdd()){x1.iadd(delta)}x1.iushrn(1)}}for(var j=0,jm=1;(b.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){b.iushrn(j);while(j-- >0){if(x2.isOdd()){x2.iadd(delta)}x2.iushrn(1)}}if(a.cmp(b)>=0){a.isub(b);x1.isub(x2)}else{b.isub(a);x2.isub(x1)}}var res;if(a.cmpn(1)===0){res=x1}else{res=x2}if(res.cmpn(0)<0){res.iadd(p)}return res};BN.prototype.gcd=function gcd(num){if(this.isZero())return num.abs();if(num.isZero())return this.abs();var a=this.clone();var b=num.clone();a.negative=0;b.negative=0;for(var shift=0;a.isEven()&&b.isEven();shift++){a.iushrn(1);b.iushrn(1)}do{while(a.isEven()){a.iushrn(1)}while(b.isEven()){b.iushrn(1)}var r=a.cmp(b);if(r<0){var t=a;a=b;b=t}else if(r===0||b.cmpn(1)===0){break}a.isub(b)}while(true);return b.iushln(shift)};BN.prototype.invm=function invm(num){return this.egcd(num).a.umod(num)};BN.prototype.isEven=function isEven(){return(this.words[0]&1)===0};BN.prototype.isOdd=function isOdd(){return(this.words[0]&1)===1};BN.prototype.andln=function andln(num){return this.words[0]&num};BN.prototype.bincn=function bincn(bit){assert(typeof bit==="number");var r=bit%26;var s=(bit-r)/26;var q=1<>>26;w&=67108863;this.words[i]=w}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.isZero=function isZero(){return this.length===1&&this.words[0]===0};BN.prototype.cmpn=function cmpn(num){var negative=num<0;if(this.negative!==0&&!negative)return-1;if(this.negative===0&&negative)return 1;this.strip();var res;if(this.length>1){res=1}else{if(negative){num=-num}assert(num<=67108863,"Number is too big");var w=this.words[0]|0;res=w===num?0:wnum.length)return 1;if(this.length=0;i--){var a=this.words[i]|0;var b=num.words[i]|0;if(a===b)continue;if(ab){res=1}break}return res};BN.prototype.gtn=function gtn(num){return this.cmpn(num)===1};BN.prototype.gt=function gt(num){return this.cmp(num)===1};BN.prototype.gten=function gten(num){return this.cmpn(num)>=0};BN.prototype.gte=function gte(num){return this.cmp(num)>=0};BN.prototype.ltn=function ltn(num){return this.cmpn(num)===-1};BN.prototype.lt=function lt(num){return this.cmp(num)===-1};BN.prototype.lten=function lten(num){return this.cmpn(num)<=0};BN.prototype.lte=function lte(num){return this.cmp(num)<=0};BN.prototype.eqn=function eqn(num){return this.cmpn(num)===0};BN.prototype.eq=function eq(num){return this.cmp(num)===0};BN.red=function red(num){return new Red(num)};BN.prototype.toRed=function toRed(ctx){assert(!this.red,"Already a number in reduction context");assert(this.negative===0,"red works only with positives");return ctx.convertTo(this)._forceRed(ctx)};BN.prototype.fromRed=function fromRed(){assert(this.red,"fromRed works only with numbers in reduction context");return this.red.convertFrom(this)};BN.prototype._forceRed=function _forceRed(ctx){this.red=ctx;return this};BN.prototype.forceRed=function forceRed(ctx){assert(!this.red,"Already a number in reduction context");return this._forceRed(ctx)};BN.prototype.redAdd=function redAdd(num){assert(this.red,"redAdd works only with red numbers");return this.red.add(this,num)};BN.prototype.redIAdd=function redIAdd(num){assert(this.red,"redIAdd works only with red numbers");return this.red.iadd(this,num)};BN.prototype.redSub=function redSub(num){assert(this.red,"redSub works only with red numbers");return this.red.sub(this,num)};BN.prototype.redISub=function redISub(num){assert(this.red,"redISub works only with red numbers");return this.red.isub(this,num)};BN.prototype.redShl=function redShl(num){assert(this.red,"redShl works only with red numbers");return this.red.shl(this,num)};BN.prototype.redMul=function redMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.mul(this,num)};BN.prototype.redIMul=function redIMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.imul(this,num)};BN.prototype.redSqr=function redSqr(){assert(this.red,"redSqr works only with red numbers");this.red._verify1(this);return this.red.sqr(this)};BN.prototype.redISqr=function redISqr(){assert(this.red,"redISqr works only with red numbers");this.red._verify1(this);return this.red.isqr(this)};BN.prototype.redSqrt=function redSqrt(){assert(this.red,"redSqrt works only with red numbers");this.red._verify1(this);return this.red.sqrt(this)};BN.prototype.redInvm=function redInvm(){assert(this.red,"redInvm works only with red numbers");this.red._verify1(this);return this.red.invm(this)};BN.prototype.redNeg=function redNeg(){assert(this.red,"redNeg works only with red numbers");this.red._verify1(this);return this.red.neg(this)};BN.prototype.redPow=function redPow(num){assert(this.red&&!num.red,"redPow(normalNum)");this.red._verify1(this);return this.red.pow(this,num)};var primes={k256:null,p224:null,p192:null,p25519:null};function MPrime(name,p){this.name=name;this.p=new BN(p,16);this.n=this.p.bitLength();this.k=new BN(1).iushln(this.n).isub(this.p);this.tmp=this._tmp()}MPrime.prototype._tmp=function _tmp(){var tmp=new BN(null);tmp.words=new Array(Math.ceil(this.n/13));return tmp};MPrime.prototype.ireduce=function ireduce(num){var r=num;var rlen;do{this.split(r,this.tmp);r=this.imulK(r);r=r.iadd(this.tmp);rlen=r.bitLength()}while(rlen>this.n);var cmp=rlen0){r.isub(this.p)}else{r.strip()}return r};MPrime.prototype.split=function split(input,out){input.iushrn(this.n,0,out)};MPrime.prototype.imulK=function imulK(num){return num.imul(this.k)};function K256(){MPrime.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}inherits(K256,MPrime);K256.prototype.split=function split(input,output){var mask=4194303;var outLen=Math.min(input.length,9);for(var i=0;i>>22;prev=next}prev>>>=22;input.words[i-10]=prev;if(prev===0&&input.length>10){input.length-=10}else{input.length-=9}};K256.prototype.imulK=function imulK(num){num.words[num.length]=0;num.words[num.length+1]=0;num.length+=2;var lo=0;for(var i=0;i>>=26;num.words[i]=lo;carry=hi}if(carry!==0){num.words[num.length++]=carry}return num};BN._prime=function prime(name){if(primes[name])return primes[name];var prime;if(name==="k256"){prime=new K256}else if(name==="p224"){prime=new P224}else if(name==="p192"){prime=new P192}else if(name==="p25519"){prime=new P25519}else{throw new Error("Unknown prime "+name)}primes[name]=prime;return prime};function Red(m){if(typeof m==="string"){var prime=BN._prime(m);this.m=prime.p;this.prime=prime}else{assert(m.gtn(1),"modulus must be greater than 1");this.m=m;this.prime=null}}Red.prototype._verify1=function _verify1(a){assert(a.negative===0,"red works only with positives");assert(a.red,"red works only with red numbers")};Red.prototype._verify2=function _verify2(a,b){assert((a.negative|b.negative)===0,"red works only with positives");assert(a.red&&a.red===b.red,"red works only with red numbers")};Red.prototype.imod=function imod(a){if(this.prime)return this.prime.ireduce(a)._forceRed(this);return a.umod(this.m)._forceRed(this)};Red.prototype.neg=function neg(a){if(a.isZero()){return a.clone()}return this.m.sub(a)._forceRed(this)};Red.prototype.add=function add(a,b){this._verify2(a,b);var res=a.add(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res._forceRed(this)};Red.prototype.iadd=function iadd(a,b){this._verify2(a,b);var res=a.iadd(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res};Red.prototype.sub=function sub(a,b){this._verify2(a,b);var res=a.sub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res._forceRed(this)};Red.prototype.isub=function isub(a,b){this._verify2(a,b);var res=a.isub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res};Red.prototype.shl=function shl(a,num){this._verify1(a);return this.imod(a.ushln(num))};Red.prototype.imul=function imul(a,b){this._verify2(a,b);return this.imod(a.imul(b))};Red.prototype.mul=function mul(a,b){this._verify2(a,b);return this.imod(a.mul(b))};Red.prototype.isqr=function isqr(a){return this.imul(a,a.clone())};Red.prototype.sqr=function sqr(a){return this.mul(a,a)};Red.prototype.sqrt=function sqrt(a){if(a.isZero())return a.clone();var mod3=this.m.andln(3);assert(mod3%2===1);if(mod3===3){var pow=this.m.add(new BN(1)).iushrn(2);return this.pow(a,pow)}var q=this.m.subn(1);var s=0;while(!q.isZero()&&q.andln(1)===0){s++;q.iushrn(1)}assert(!q.isZero());var one=new BN(1).toRed(this);var nOne=one.redNeg();var lpow=this.m.subn(1).iushrn(1);var z=this.m.bitLength();z=new BN(2*z*z).toRed(this);while(this.pow(z,lpow).cmp(nOne)!==0){z.redIAdd(nOne)}var c=this.pow(z,q);var r=this.pow(a,q.addn(1).iushrn(1));var t=this.pow(a,q);var m=s;while(t.cmp(one)!==0){var tmp=t;for(var i=0;tmp.cmp(one)!==0;i++){tmp=tmp.redSqr()}assert(i=0;i--){var word=num.words[i];for(var j=start-1;j>=0;j--){var bit=word>>j&1;if(res!==wnd[0]){res=this.sqr(res)}if(bit===0&¤t===0){currentLen=0;continue}current<<=1;current|=bit;currentLen++;if(currentLen!==windowSize&&(i!==0||j!==0))continue;res=this.mul(res,wnd[current]);currentLen=0;current=0}start=26}return res};Red.prototype.convertTo=function convertTo(num){var r=num.umod(this.m);return r===num?r.clone():r};Red.prototype.convertFrom=function convertFrom(num){var res=num.clone();res.red=null;return res};BN.mont=function mont(num){return new Mont(num)};function Mont(m){Red.call(this,m);this.shift=this.m.bitLength();if(this.shift%26!==0){this.shift+=26-this.shift%26}this.r=new BN(1).iushln(this.shift);this.r2=this.imod(this.r.sqr());this.rinv=this.r._invmp(this.m);this.minv=this.rinv.mul(this.r).isubn(1).div(this.m);this.minv=this.minv.umod(this.r);this.minv=this.r.sub(this.minv)}inherits(Mont,Red);Mont.prototype.convertTo=function convertTo(num){return this.imod(num.ushln(this.shift))};Mont.prototype.convertFrom=function convertFrom(num){var r=this.imod(num.mul(this.rinv));r.red=null;return r};Mont.prototype.imul=function imul(a,b){if(a.isZero()||b.isZero()){a.words[0]=0;a.length=1;return a}var t=a.imul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.mul=function mul(a,b){if(a.isZero()||b.isZero())return new BN(0)._forceRed(this);var t=a.mul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.invm=function invm(a){var res=this.imod(a._invmp(this.m).mul(this.r2));return res._forceRed(this)}})(typeof module==="undefined"||module,this)},{buffer:115}],50:[function(require,module,exports){var r;module.exports=function rand(len){if(!r)r=new Rand(null);return r.generate(len)};function Rand(rand){this.rand=rand}module.exports.Rand=Rand;Rand.prototype.generate=function generate(len){return this._rand(len)};Rand.prototype._rand=function _rand(n){if(this.rand.getBytes)return this.rand.getBytes(n);var res=new Uint8Array(n);for(var i=0;i0){this.redN=null}else{this._maxwellTrick=true;this.redN=this.n.toRed(this.red)}}module.exports=BaseCurve;BaseCurve.prototype.point=function point(){throw new Error("Not implemented")};BaseCurve.prototype.validate=function validate(){throw new Error("Not implemented")};BaseCurve.prototype._fixedNafMul=function _fixedNafMul(p,k){assert(p.precomputed);var doubles=p._getDoubles();var naf=getNAF(k,1,this._bitLength);var I=(1<=j;k--)nafW=(nafW<<1)+naf[k];repr.push(nafW)}var a=this.jpoint(null,null,null);var b=this.jpoint(null,null,null);for(var i=I;i>0;i--){for(var j=0;j=0;i--){for(var k=0;i>=0&&naf[i]===0;i--)k++;if(i>=0)k++;acc=acc.dblp(k);if(i<0)break;var z=naf[i];assert(z!==0);if(p.type==="affine"){if(z>0)acc=acc.mixedAdd(wnd[z-1>>1]);else acc=acc.mixedAdd(wnd[-z-1>>1].neg())}else{if(z>0)acc=acc.add(wnd[z-1>>1]);else acc=acc.add(wnd[-z-1>>1].neg())}}return p.type==="affine"?acc.toP():acc};BaseCurve.prototype._wnafMulAdd=function _wnafMulAdd(defW,points,coeffs,len,jacobianResult){var wndWidth=this._wnafT1;var wnd=this._wnafT2;var naf=this._wnafT3;var max=0;for(var i=0;i=1;i-=2){var a=i-1;var b=i;if(wndWidth[a]!==1||wndWidth[b]!==1){naf[a]=getNAF(coeffs[a],wndWidth[a],this._bitLength);naf[b]=getNAF(coeffs[b],wndWidth[b],this._bitLength);max=Math.max(naf[a].length,max);max=Math.max(naf[b].length,max);continue}var comb=[points[a],null,null,points[b]];if(points[a].y.cmp(points[b].y)===0){comb[1]=points[a].add(points[b]);comb[2]=points[a].toJ().mixedAdd(points[b].neg())}else if(points[a].y.cmp(points[b].y.redNeg())===0){comb[1]=points[a].toJ().mixedAdd(points[b]);comb[2]=points[a].add(points[b].neg())}else{comb[1]=points[a].toJ().mixedAdd(points[b]);comb[2]=points[a].toJ().mixedAdd(points[b].neg())}var index=[-3,-1,-5,-7,0,7,5,1,3];var jsf=getJSF(coeffs[a],coeffs[b]);max=Math.max(jsf[0].length,max);naf[a]=new Array(max);naf[b]=new Array(max);for(var j=0;j=0;i--){var k=0;while(i>=0){var zero=true;for(var j=0;j=0)k++;acc=acc.dblp(k);if(i<0)break;for(var j=0;j0)p=wnd[j][z-1>>1];else if(z<0)p=wnd[j][-z-1>>1].neg();if(p.type==="affine")acc=acc.mixedAdd(p);else acc=acc.add(p)}}for(var i=0;i=Math.ceil((k.bitLength()+1)/doubles.step)};BasePoint.prototype._getDoubles=function _getDoubles(step,power){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;var doubles=[this];var acc=this;for(var i=0;i";return""};Point.prototype.isInfinity=function isInfinity(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)};Point.prototype._extDbl=function _extDbl(){var a=this.x.redSqr();var b=this.y.redSqr();var c=this.z.redSqr();c=c.redIAdd(c);var d=this.curve._mulA(a);var e=this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);var g=d.redAdd(b);var f=g.redSub(c);var h=d.redSub(b);var nx=e.redMul(f);var ny=g.redMul(h);var nt=e.redMul(h);var nz=f.redMul(g);return this.curve.point(nx,ny,nz,nt)};Point.prototype._projDbl=function _projDbl(){var b=this.x.redAdd(this.y).redSqr();var c=this.x.redSqr();var d=this.y.redSqr();var nx;var ny;var nz;if(this.curve.twisted){var e=this.curve._mulA(c);var f=e.redAdd(d);if(this.zOne){nx=b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));ny=f.redMul(e.redSub(d));nz=f.redSqr().redSub(f).redSub(f)}else{var h=this.z.redSqr();var j=f.redSub(h).redISub(h);nx=b.redSub(c).redISub(d).redMul(j);ny=f.redMul(e.redSub(d));nz=f.redMul(j)}}else{var e=c.redAdd(d);var h=this.curve._mulC(this.z).redSqr();var j=e.redSub(h).redSub(h);nx=this.curve._mulC(b.redISub(e)).redMul(j);ny=this.curve._mulC(e).redMul(c.redISub(d));nz=e.redMul(j)}return this.curve.point(nx,ny,nz)};Point.prototype.dbl=function dbl(){if(this.isInfinity())return this;if(this.curve.extended)return this._extDbl();else return this._projDbl()};Point.prototype._extAdd=function _extAdd(p){var a=this.y.redSub(this.x).redMul(p.y.redSub(p.x));var b=this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));var c=this.t.redMul(this.curve.dd).redMul(p.t);var d=this.z.redMul(p.z.redAdd(p.z));var e=b.redSub(a);var f=d.redSub(c);var g=d.redAdd(c);var h=b.redAdd(a);var nx=e.redMul(f);var ny=g.redMul(h);var nt=e.redMul(h);var nz=f.redMul(g);return this.curve.point(nx,ny,nz,nt)};Point.prototype._projAdd=function _projAdd(p){var a=this.z.redMul(p.z);var b=a.redSqr();var c=this.x.redMul(p.x);var d=this.y.redMul(p.y);var e=this.curve.d.redMul(c).redMul(d);var f=b.redSub(e);var g=b.redAdd(e);var tmp=this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);var nx=a.redMul(f).redMul(tmp);var ny;var nz;if(this.curve.twisted){ny=a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));nz=f.redMul(g)}else{ny=a.redMul(g).redMul(d.redSub(c));nz=this.curve._mulC(f).redMul(g)}return this.curve.point(nx,ny,nz)};Point.prototype.add=function add(p){if(this.isInfinity())return p;if(p.isInfinity())return this;if(this.curve.extended)return this._extAdd(p);else return this._projAdd(p)};Point.prototype.mul=function mul(k){if(this._hasDoubles(k))return this.curve._fixedNafMul(this,k);else return this.curve._wnafMul(this,k)};Point.prototype.mulAdd=function mulAdd(k1,p,k2){return this.curve._wnafMulAdd(1,[this,p],[k1,k2],2,false)};Point.prototype.jmulAdd=function jmulAdd(k1,p,k2){return this.curve._wnafMulAdd(1,[this,p],[k1,k2],2,true)};Point.prototype.normalize=function normalize(){if(this.zOne)return this;var zi=this.z.redInvm();this.x=this.x.redMul(zi);this.y=this.y.redMul(zi);if(this.t)this.t=this.t.redMul(zi);this.z=this.curve.one;this.zOne=true;return this};Point.prototype.neg=function neg(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())};Point.prototype.getX=function getX(){this.normalize();return this.x.fromRed()};Point.prototype.getY=function getY(){this.normalize();return this.y.fromRed()};Point.prototype.eq=function eq(other){return this===other||this.getX().cmp(other.getX())===0&&this.getY().cmp(other.getY())===0};Point.prototype.eqXToP=function eqXToP(x){var rx=x.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(rx)===0)return true;var xc=x.clone();var t=this.curve.redN.redMul(this.z);for(;;){xc.iadd(this.curve.n);if(xc.cmp(this.curve.p)>=0)return false;rx.redIAdd(t);if(this.x.cmp(rx)===0)return true}};Point.prototype.toP=Point.prototype.normalize;Point.prototype.mixedAdd=Point.prototype.add},{"../utils":67,"./base":54,"bn.js":49,inherits:83}],56:[function(require,module,exports){"use strict";var curve=exports;curve.base=require("./base");curve.short=require("./short");curve.mont=require("./mont");curve.edwards=require("./edwards")},{"./base":54,"./edwards":55,"./mont":57,"./short":58}],57:[function(require,module,exports){"use strict";var BN=require("bn.js");var inherits=require("inherits");var Base=require("./base");var utils=require("../utils");function MontCurve(conf){Base.call(this,"mont",conf);this.a=new BN(conf.a,16).toRed(this.red);this.b=new BN(conf.b,16).toRed(this.red);this.i4=new BN(4).toRed(this.red).redInvm();this.two=new BN(2).toRed(this.red);this.a24=this.i4.redMul(this.a.redAdd(this.two))}inherits(MontCurve,Base);module.exports=MontCurve;MontCurve.prototype.validate=function validate(point){var x=point.normalize().x;var x2=x.redSqr();var rhs=x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);var y=rhs.redSqrt();return y.redSqr().cmp(rhs)===0};function Point(curve,x,z){Base.BasePoint.call(this,curve,"projective");if(x===null&&z===null){this.x=this.curve.one;this.z=this.curve.zero}else{this.x=new BN(x,16);this.z=new BN(z,16);if(!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red)}}inherits(Point,Base.BasePoint);MontCurve.prototype.decodePoint=function decodePoint(bytes,enc){return this.point(utils.toArray(bytes,enc),1)};MontCurve.prototype.point=function point(x,z){return new Point(this,x,z)};MontCurve.prototype.pointFromJSON=function pointFromJSON(obj){return Point.fromJSON(this,obj)};Point.prototype.precompute=function precompute(){};Point.prototype._encode=function _encode(){return this.getX().toArray("be",this.curve.p.byteLength())};Point.fromJSON=function fromJSON(curve,obj){return new Point(curve,obj[0],obj[1]||curve.one)};Point.prototype.inspect=function inspect(){if(this.isInfinity())return"";return""};Point.prototype.isInfinity=function isInfinity(){return this.z.cmpn(0)===0};Point.prototype.dbl=function dbl(){var a=this.x.redAdd(this.z);var aa=a.redSqr();var b=this.x.redSub(this.z);var bb=b.redSqr();var c=aa.redSub(bb);var nx=aa.redMul(bb);var nz=c.redMul(bb.redAdd(this.curve.a24.redMul(c)));return this.curve.point(nx,nz)};Point.prototype.add=function add(){throw new Error("Not supported on Montgomery curve")};Point.prototype.diffAdd=function diffAdd(p,diff){var a=this.x.redAdd(this.z);var b=this.x.redSub(this.z);var c=p.x.redAdd(p.z);var d=p.x.redSub(p.z);var da=d.redMul(a);var cb=c.redMul(b);var nx=diff.z.redMul(da.redAdd(cb).redSqr());var nz=diff.x.redMul(da.redISub(cb).redSqr());return this.curve.point(nx,nz)};Point.prototype.mul=function mul(k){var t=k.clone();var a=this;var b=this.curve.point(null,null);var c=this;for(var bits=[];t.cmpn(0)!==0;t.iushrn(1))bits.push(t.andln(1));for(var i=bits.length-1;i>=0;i--){if(bits[i]===0){a=a.diffAdd(b,c);b=b.dbl()}else{b=a.diffAdd(b,c);a=a.dbl()}}return b};Point.prototype.mulAdd=function mulAdd(){throw new Error("Not supported on Montgomery curve")};Point.prototype.jumlAdd=function jumlAdd(){throw new Error("Not supported on Montgomery curve")};Point.prototype.eq=function eq(other){return this.getX().cmp(other.getX())===0};Point.prototype.normalize=function normalize(){this.x=this.x.redMul(this.z.redInvm());this.z=this.curve.one;return this};Point.prototype.getX=function getX(){this.normalize();return this.x.fromRed()}},{"../utils":67,"./base":54,"bn.js":49,inherits:83}],58:[function(require,module,exports){"use strict";var utils=require("../utils");var BN=require("bn.js");var inherits=require("inherits");var Base=require("./base");var assert=utils.assert;function ShortCurve(conf){Base.call(this,"short",conf);this.a=new BN(conf.a,16).toRed(this.red);this.b=new BN(conf.b,16).toRed(this.red);this.tinv=this.two.redInvm();this.zeroA=this.a.fromRed().cmpn(0)===0;this.threeA=this.a.fromRed().sub(this.p).cmpn(-3)===0;this.endo=this._getEndomorphism(conf);this._endoWnafT1=new Array(4);this._endoWnafT2=new Array(4)}inherits(ShortCurve,Base);module.exports=ShortCurve;ShortCurve.prototype._getEndomorphism=function _getEndomorphism(conf){if(!this.zeroA||!this.g||!this.n||this.p.modn(3)!==1)return;var beta;var lambda;if(conf.beta){beta=new BN(conf.beta,16).toRed(this.red)}else{var betas=this._getEndoRoots(this.p);beta=betas[0].cmp(betas[1])<0?betas[0]:betas[1];beta=beta.toRed(this.red)}if(conf.lambda){lambda=new BN(conf.lambda,16)}else{var lambdas=this._getEndoRoots(this.n);if(this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta))===0){lambda=lambdas[0]}else{lambda=lambdas[1];assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta))===0)}}var basis;if(conf.basis){basis=conf.basis.map(function(vec){return{a:new BN(vec.a,16),b:new BN(vec.b,16)}})}else{basis=this._getEndoBasis(lambda)}return{beta:beta,lambda:lambda,basis:basis}};ShortCurve.prototype._getEndoRoots=function _getEndoRoots(num){var red=num===this.p?this.red:BN.mont(num);var tinv=new BN(2).toRed(red).redInvm();var ntinv=tinv.redNeg();var s=new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);var l1=ntinv.redAdd(s).fromRed();var l2=ntinv.redSub(s).fromRed();return[l1,l2]};ShortCurve.prototype._getEndoBasis=function _getEndoBasis(lambda){var aprxSqrt=this.n.ushrn(Math.floor(this.n.bitLength()/2));var u=lambda;var v=this.n.clone();var x1=new BN(1);var y1=new BN(0);var x2=new BN(0);var y2=new BN(1);var a0;var b0;var a1;var b1;var a2;var b2;var prevR;var i=0;var r;var x;while(u.cmpn(0)!==0){var q=v.div(u);r=v.sub(q.mul(u));x=x2.sub(q.mul(x1));var y=y2.sub(q.mul(y1));if(!a1&&r.cmp(aprxSqrt)<0){a0=prevR.neg();b0=x1;a1=r.neg();b1=x}else if(a1&&++i===2){break}prevR=r;v=u;u=r;x2=x1;x1=x;y2=y1;y1=y}a2=r.neg();b2=x;var len1=a1.sqr().add(b1.sqr());var len2=a2.sqr().add(b2.sqr());if(len2.cmp(len1)>=0){a2=a0;b2=b0}if(a1.negative){a1=a1.neg();b1=b1.neg()}if(a2.negative){a2=a2.neg();b2=b2.neg()}return[{a:a1,b:b1},{a:a2,b:b2}]};ShortCurve.prototype._endoSplit=function _endoSplit(k){var basis=this.endo.basis;var v1=basis[0];var v2=basis[1];var c1=v2.b.mul(k).divRound(this.n);var c2=v1.b.neg().mul(k).divRound(this.n);var p1=c1.mul(v1.a);var p2=c2.mul(v2.a);var q1=c1.mul(v1.b);var q2=c2.mul(v2.b);var k1=k.sub(p1).sub(p2);var k2=q1.add(q2).neg();return{k1:k1,k2:k2}};ShortCurve.prototype.pointFromX=function pointFromX(x,odd){x=new BN(x,16);if(!x.red)x=x.toRed(this.red);var y2=x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);var y=y2.redSqrt();if(y.redSqr().redSub(y2).cmp(this.zero)!==0)throw new Error("invalid point");var isOdd=y.fromRed().isOdd();if(odd&&!isOdd||!odd&&isOdd)y=y.redNeg();return this.point(x,y)};ShortCurve.prototype.validate=function validate(point){if(point.inf)return true;var x=point.x;var y=point.y;var ax=this.a.redMul(x);var rhs=x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);return y.redSqr().redISub(rhs).cmpn(0)===0};ShortCurve.prototype._endoWnafMulAdd=function _endoWnafMulAdd(points,coeffs,jacobianResult){var npoints=this._endoWnafT1;var ncoeffs=this._endoWnafT2;for(var i=0;i";return""};Point.prototype.isInfinity=function isInfinity(){return this.inf};Point.prototype.add=function add(p){if(this.inf)return p;if(p.inf)return this;if(this.eq(p))return this.dbl();if(this.neg().eq(p))return this.curve.point(null,null);if(this.x.cmp(p.x)===0)return this.curve.point(null,null);var c=this.y.redSub(p.y);if(c.cmpn(0)!==0)c=c.redMul(this.x.redSub(p.x).redInvm());var nx=c.redSqr().redISub(this.x).redISub(p.x);var ny=c.redMul(this.x.redSub(nx)).redISub(this.y);return this.curve.point(nx,ny)};Point.prototype.dbl=function dbl(){if(this.inf)return this;var ys1=this.y.redAdd(this.y);if(ys1.cmpn(0)===0)return this.curve.point(null,null);var a=this.curve.a;var x2=this.x.redSqr();var dyinv=ys1.redInvm();var c=x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);var nx=c.redSqr().redISub(this.x.redAdd(this.x));var ny=c.redMul(this.x.redSub(nx)).redISub(this.y);return this.curve.point(nx,ny)};Point.prototype.getX=function getX(){return this.x.fromRed()};Point.prototype.getY=function getY(){return this.y.fromRed()};Point.prototype.mul=function mul(k){k=new BN(k,16);if(this.isInfinity())return this;else if(this._hasDoubles(k))return this.curve._fixedNafMul(this,k);else if(this.curve.endo)return this.curve._endoWnafMulAdd([this],[k]);else return this.curve._wnafMul(this,k)};Point.prototype.mulAdd=function mulAdd(k1,p2,k2){var points=[this,p2];var coeffs=[k1,k2];if(this.curve.endo)return this.curve._endoWnafMulAdd(points,coeffs);else return this.curve._wnafMulAdd(1,points,coeffs,2)};Point.prototype.jmulAdd=function jmulAdd(k1,p2,k2){var points=[this,p2];var coeffs=[k1,k2];if(this.curve.endo)return this.curve._endoWnafMulAdd(points,coeffs,true);else return this.curve._wnafMulAdd(1,points,coeffs,2,true)};Point.prototype.eq=function eq(p){return this===p||this.inf===p.inf&&(this.inf||this.x.cmp(p.x)===0&&this.y.cmp(p.y)===0)};Point.prototype.neg=function neg(_precompute){if(this.inf)return this;var res=this.curve.point(this.x,this.y.redNeg());if(_precompute&&this.precomputed){var pre=this.precomputed;var negate=function(p){return p.neg()};res.precomputed={naf:pre.naf&&{wnd:pre.naf.wnd,points:pre.naf.points.map(negate)},doubles:pre.doubles&&{step:pre.doubles.step,points:pre.doubles.points.map(negate)}}}return res};Point.prototype.toJ=function toJ(){if(this.inf)return this.curve.jpoint(null,null,null);var res=this.curve.jpoint(this.x,this.y,this.curve.one);return res};function JPoint(curve,x,y,z){Base.BasePoint.call(this,curve,"jacobian");if(x===null&&y===null&&z===null){this.x=this.curve.one;this.y=this.curve.one;this.z=new BN(0)}else{this.x=new BN(x,16);this.y=new BN(y,16);this.z=new BN(z,16)}if(!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.y.red)this.y=this.y.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red);this.zOne=this.z===this.curve.one}inherits(JPoint,Base.BasePoint);ShortCurve.prototype.jpoint=function jpoint(x,y,z){return new JPoint(this,x,y,z)};JPoint.prototype.toP=function toP(){if(this.isInfinity())return this.curve.point(null,null);var zinv=this.z.redInvm();var zinv2=zinv.redSqr();var ax=this.x.redMul(zinv2);var ay=this.y.redMul(zinv2).redMul(zinv);return this.curve.point(ax,ay)};JPoint.prototype.neg=function neg(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)};JPoint.prototype.add=function add(p){if(this.isInfinity())return p;if(p.isInfinity())return this;var pz2=p.z.redSqr();var z2=this.z.redSqr();var u1=this.x.redMul(pz2);var u2=p.x.redMul(z2);var s1=this.y.redMul(pz2.redMul(p.z));var s2=p.y.redMul(z2.redMul(this.z));var h=u1.redSub(u2);var r=s1.redSub(s2);if(h.cmpn(0)===0){if(r.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl()}var h2=h.redSqr();var h3=h2.redMul(h);var v=u1.redMul(h2);var nx=r.redSqr().redIAdd(h3).redISub(v).redISub(v);var ny=r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));var nz=this.z.redMul(p.z).redMul(h);return this.curve.jpoint(nx,ny,nz)};JPoint.prototype.mixedAdd=function mixedAdd(p){if(this.isInfinity())return p.toJ();if(p.isInfinity())return this;var z2=this.z.redSqr();var u1=this.x;var u2=p.x.redMul(z2);var s1=this.y;var s2=p.y.redMul(z2).redMul(this.z);var h=u1.redSub(u2);var r=s1.redSub(s2);if(h.cmpn(0)===0){if(r.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl()}var h2=h.redSqr();var h3=h2.redMul(h);var v=u1.redMul(h2);var nx=r.redSqr().redIAdd(h3).redISub(v).redISub(v);var ny=r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));var nz=this.z.redMul(h);return this.curve.jpoint(nx,ny,nz)};JPoint.prototype.dblp=function dblp(pow){if(pow===0)return this;if(this.isInfinity())return this;if(!pow)return this.dbl();if(this.curve.zeroA||this.curve.threeA){var r=this;for(var i=0;i=0)return false;rx.redIAdd(t);if(this.x.cmp(rx)===0)return true}};JPoint.prototype.inspect=function inspect(){if(this.isInfinity())return"";return""};JPoint.prototype.isInfinity=function isInfinity(){return this.z.cmpn(0)===0}},{"../utils":67,"./base":54,"bn.js":49,inherits:83}],59:[function(require,module,exports){"use strict";var curves=exports;var hash=require("hash.js");var curve=require("./curve");var utils=require("./utils");var assert=utils.assert;function PresetCurve(options){if(options.type==="short")this.curve=new curve.short(options);else if(options.type==="edwards")this.curve=new curve.edwards(options);else this.curve=new curve.mont(options);this.g=this.curve.g;this.n=this.curve.n;this.hash=options.hash;assert(this.g.validate(),"Invalid curve");assert(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}curves.PresetCurve=PresetCurve;function defineCurve(name,options){Object.defineProperty(curves,name,{configurable:true,enumerable:true,get:function(){var curve=new PresetCurve(options);Object.defineProperty(curves,name,{configurable:true,enumerable:true,value:curve});return curve}})}defineCurve("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:hash.sha256,gRed:false,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]});defineCurve("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:hash.sha256,gRed:false,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]});defineCurve("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:hash.sha256,gRed:false,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]});defineCurve("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f "+"5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 "+"f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:hash.sha384,gRed:false,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 "+"5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 "+"0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]});defineCurve("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b "+"99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd "+"3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 "+"f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:hash.sha512,gRed:false,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 "+"053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 "+"a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 "+"579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 "+"3fad0761 353c7086 a272c240 88be9476 9fd16650"]});defineCurve("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:hash.sha256,gRed:false,g:["9"]});defineCurve("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:hash.sha256,gRed:false,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var pre;try{pre=require("./precomputed/secp256k1")}catch(e){pre=undefined}defineCurve("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:hash.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:false,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",pre]})},{"./curve":56,"./precomputed/secp256k1":66,"./utils":67,"hash.js":69}],60:[function(require,module,exports){"use strict";var BN=require("bn.js");var HmacDRBG=require("hmac-drbg");var utils=require("../utils");var curves=require("../curves");var rand=require("brorand");var assert=utils.assert;var KeyPair=require("./key");var Signature=require("./signature");function EC(options){if(!(this instanceof EC))return new EC(options);if(typeof options==="string"){assert(curves.hasOwnProperty(options),"Unknown curve "+options);options=curves[options]}if(options instanceof curves.PresetCurve)options={curve:options};this.curve=options.curve.curve;this.n=this.curve.n;this.nh=this.n.ushrn(1);this.g=this.curve.g;this.g=options.curve.g;this.g.precompute(options.curve.n.bitLength()+1);this.hash=options.hash||options.curve.hash}module.exports=EC;EC.prototype.keyPair=function keyPair(options){return new KeyPair(this,options)};EC.prototype.keyFromPrivate=function keyFromPrivate(priv,enc){return KeyPair.fromPrivate(this,priv,enc)};EC.prototype.keyFromPublic=function keyFromPublic(pub,enc){return KeyPair.fromPublic(this,pub,enc)};EC.prototype.genKeyPair=function genKeyPair(options){if(!options)options={};var drbg=new HmacDRBG({hash:this.hash,pers:options.pers,persEnc:options.persEnc||"utf8",entropy:options.entropy||rand(this.hash.hmacStrength),entropyEnc:options.entropy&&options.entropyEnc||"utf8",nonce:this.n.toArray()});var bytes=this.n.byteLength();var ns2=this.n.sub(new BN(2));do{var priv=new BN(drbg.generate(bytes));if(priv.cmp(ns2)>0)continue;priv.iaddn(1);return this.keyFromPrivate(priv)}while(true)};EC.prototype._truncateToN=function truncateToN(msg,truncOnly){var delta=msg.byteLength()*8-this.n.bitLength();if(delta>0)msg=msg.ushrn(delta);if(!truncOnly&&msg.cmp(this.n)>=0)return msg.sub(this.n);else return msg};EC.prototype.sign=function sign(msg,key,enc,options){if(typeof enc==="object"){options=enc;enc=null}if(!options)options={};key=this.keyFromPrivate(key,enc);msg=this._truncateToN(new BN(msg,16));var bytes=this.n.byteLength();var bkey=key.getPrivate().toArray("be",bytes);var nonce=msg.toArray("be",bytes);var drbg=new HmacDRBG({hash:this.hash,entropy:bkey,nonce:nonce,pers:options.pers,persEnc:options.persEnc||"utf8"});var ns1=this.n.sub(new BN(1));for(var iter=0;true;iter++){var k=options.k?options.k(iter):new BN(drbg.generate(this.n.byteLength()));k=this._truncateToN(k,true);if(k.cmpn(1)<=0||k.cmp(ns1)>=0)continue;var kp=this.g.mul(k);if(kp.isInfinity())continue;var kpX=kp.getX();var r=kpX.umod(this.n);if(r.cmpn(0)===0)continue;var s=k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));s=s.umod(this.n);if(s.cmpn(0)===0)continue;var recoveryParam=(kp.getY().isOdd()?1:0)|(kpX.cmp(r)!==0?2:0);if(options.canonical&&s.cmp(this.nh)>0){s=this.n.sub(s);recoveryParam^=1}return new Signature({r:r,s:s,recoveryParam:recoveryParam})}};EC.prototype.verify=function verify(msg,signature,key,enc){msg=this._truncateToN(new BN(msg,16));key=this.keyFromPublic(key,enc);signature=new Signature(signature,"hex");var r=signature.r;var s=signature.s;if(r.cmpn(1)<0||r.cmp(this.n)>=0)return false;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return false;var sinv=s.invm(this.n);var u1=sinv.mul(msg).umod(this.n);var u2=sinv.mul(r).umod(this.n);if(!this.curve._maxwellTrick){var p=this.g.mulAdd(u1,key.getPublic(),u2);if(p.isInfinity())return false;return p.getX().umod(this.n).cmp(r)===0}var p=this.g.jmulAdd(u1,key.getPublic(),u2);if(p.isInfinity())return false;return p.eqXToP(r)};EC.prototype.recoverPubKey=function(msg,signature,j,enc){assert((3&j)===j,"The recovery param is more than two bits");signature=new Signature(signature,enc);var n=this.n;var e=new BN(msg);var r=signature.r;var s=signature.s;var isYOdd=j&1;var isSecondKey=j>>1;if(r.cmp(this.curve.p.umod(this.curve.n))>=0&&isSecondKey)throw new Error("Unable to find sencond key candinate");if(isSecondKey)r=this.curve.pointFromX(r.add(this.curve.n),isYOdd);else r=this.curve.pointFromX(r,isYOdd);var rInv=signature.r.invm(n);var s1=n.sub(e).mul(rInv).umod(n);var s2=s.mul(rInv).umod(n);return this.g.mulAdd(s1,r,s2)};EC.prototype.getKeyRecoveryParam=function(e,signature,Q,enc){signature=new Signature(signature,enc);if(signature.recoveryParam!==null)return signature.recoveryParam;for(var i=0;i<4;i++){var Qprime;try{Qprime=this.recoverPubKey(e,signature,i)}catch(e){continue}if(Qprime.eq(Q))return i}throw new Error("Unable to find valid recovery factor")}},{"../curves":59,"../utils":67,"./key":61,"./signature":62,"bn.js":49,brorand:50,"hmac-drbg":82}],61:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var assert=utils.assert;function KeyPair(ec,options){this.ec=ec;this.priv=null;this.pub=null;if(options.priv)this._importPrivate(options.priv,options.privEnc);if(options.pub)this._importPublic(options.pub,options.pubEnc)}module.exports=KeyPair;KeyPair.fromPublic=function fromPublic(ec,pub,enc){if(pub instanceof KeyPair)return pub;return new KeyPair(ec,{pub:pub,pubEnc:enc})};KeyPair.fromPrivate=function fromPrivate(ec,priv,enc){if(priv instanceof KeyPair)return priv;return new KeyPair(ec,{priv:priv,privEnc:enc})};KeyPair.prototype.validate=function validate(){var pub=this.getPublic();if(pub.isInfinity())return{result:false,reason:"Invalid public key"};if(!pub.validate())return{result:false,reason:"Public key is not a point"};if(!pub.mul(this.ec.curve.n).isInfinity())return{result:false,reason:"Public key * N != O"};return{result:true,reason:null}};KeyPair.prototype.getPublic=function getPublic(compact,enc){if(typeof compact==="string"){enc=compact;compact=null}if(!this.pub)this.pub=this.ec.g.mul(this.priv);if(!enc)return this.pub;return this.pub.encode(enc,compact)};KeyPair.prototype.getPrivate=function getPrivate(enc){if(enc==="hex")return this.priv.toString(16,2);else return this.priv};KeyPair.prototype._importPrivate=function _importPrivate(key,enc){this.priv=new BN(key,enc||16);this.priv=this.priv.umod(this.ec.curve.n)};KeyPair.prototype._importPublic=function _importPublic(key,enc){if(key.x||key.y){if(this.ec.curve.type==="mont"){assert(key.x,"Need x coordinate")}else if(this.ec.curve.type==="short"||this.ec.curve.type==="edwards"){assert(key.x&&key.y,"Need both x and y coordinate")}this.pub=this.ec.curve.point(key.x,key.y);return}this.pub=this.ec.curve.decodePoint(key,enc)};KeyPair.prototype.derive=function derive(pub){return pub.mul(this.priv).getX()};KeyPair.prototype.sign=function sign(msg,enc,options){return this.ec.sign(msg,this,enc,options)};KeyPair.prototype.verify=function verify(msg,signature){return this.ec.verify(msg,signature,this)};KeyPair.prototype.inspect=function inspect(){return""}},{"../utils":67,"bn.js":49}],62:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var assert=utils.assert;function Signature(options,enc){if(options instanceof Signature)return options;if(this._importDER(options,enc))return;assert(options.r&&options.s,"Signature without r or s");this.r=new BN(options.r,16);this.s=new BN(options.s,16);if(options.recoveryParam===undefined)this.recoveryParam=null;else this.recoveryParam=options.recoveryParam}module.exports=Signature;function Position(){this.place=0}function getLength(buf,p){var initial=buf[p.place++];if(!(initial&128)){return initial}var octetLen=initial&15;if(octetLen===0||octetLen>4){return false}var val=0;for(var i=0,off=p.place;i>>=0}if(val<=127){return false}p.place=off;return val}function rmPadding(buf){var i=0;var len=buf.length-1;while(!buf[i]&&!(buf[i+1]&128)&&i>>3);arr.push(octets|128);while(--octets){arr.push(len>>>(octets<<3)&255)}arr.push(len)}Signature.prototype.toDER=function toDER(enc){var r=this.r.toArray();var s=this.s.toArray();if(r[0]&128)r=[0].concat(r);if(s[0]&128)s=[0].concat(s);r=rmPadding(r);s=rmPadding(s);while(!s[0]&&!(s[1]&128)){s=s.slice(1)}var arr=[2];constructLength(arr,r.length);arr=arr.concat(r);arr.push(2);constructLength(arr,s.length);var backHalf=arr.concat(s);var res=[48];constructLength(res,backHalf.length);res=res.concat(backHalf);return utils.encode(res,enc)}},{"../utils":67,"bn.js":49}],63:[function(require,module,exports){"use strict";var hash=require("hash.js");var curves=require("../curves");var utils=require("../utils");var assert=utils.assert;var parseBytes=utils.parseBytes;var KeyPair=require("./key");var Signature=require("./signature");function EDDSA(curve){assert(curve==="ed25519","only tested with ed25519 so far");if(!(this instanceof EDDSA))return new EDDSA(curve);var curve=curves[curve].curve;this.curve=curve;this.g=curve.g;this.g.precompute(curve.n.bitLength()+1);this.pointClass=curve.point().constructor;this.encodingLength=Math.ceil(curve.n.bitLength()/8);this.hash=hash.sha512}module.exports=EDDSA;EDDSA.prototype.sign=function sign(message,secret){message=parseBytes(message);var key=this.keyFromSecret(secret);var r=this.hashInt(key.messagePrefix(),message);var R=this.g.mul(r);var Rencoded=this.encodePoint(R);var s_=this.hashInt(Rencoded,key.pubBytes(),message).mul(key.priv());var S=r.add(s_).umod(this.curve.n);return this.makeSignature({R:R,S:S,Rencoded:Rencoded})};EDDSA.prototype.verify=function verify(message,sig,pub){message=parseBytes(message);sig=this.makeSignature(sig);var key=this.keyFromPublic(pub);var h=this.hashInt(sig.Rencoded(),key.pubBytes(),message);var SG=this.g.mul(sig.S());var RplusAh=sig.R().add(key.pub().mul(h));return RplusAh.eq(SG)};EDDSA.prototype.hashInt=function hashInt(){var hash=this.hash();for(var i=0;i(ws>>1)-1)z=(ws>>1)-mod;else z=mod;k.isubn(z)}else{z=0}naf[i]=z;k.iushrn(1)}return naf}utils.getNAF=getNAF;function getJSF(k1,k2){var jsf=[[],[]];k1=k1.clone();k2=k2.clone();var d1=0;var d2=0;while(k1.cmpn(-d1)>0||k2.cmpn(-d2)>0){var m14=k1.andln(3)+d1&3;var m24=k2.andln(3)+d2&3;if(m14===3)m14=-1;if(m24===3)m24=-1;var u1;if((m14&1)===0){u1=0}else{var m8=k1.andln(7)+d1&7;if((m8===3||m8===5)&&m24===2)u1=-m14;else u1=m14}jsf[0].push(u1);var u2;if((m24&1)===0){u2=0}else{var m8=k2.andln(7)+d2&7;if((m8===3||m8===5)&&m14===2)u2=-m24;else u2=m24}jsf[1].push(u2);if(2*d1===u1+1)d1=1-d1;if(2*d2===u2+1)d2=1-d2;k1.iushrn(1);k2.iushrn(1)}return jsf}utils.getJSF=getJSF;function cachedProperty(obj,name,computer){var key="_"+name;obj.prototype[name]=function cachedProperty(){return this[key]!==undefined?this[key]:this[key]=computer.call(this)}}utils.cachedProperty=cachedProperty;function parseBytes(bytes){return typeof bytes==="string"?utils.toArray(bytes,"hex"):bytes}utils.parseBytes=parseBytes;function intFromLE(bytes){return new BN(bytes,"hex","le")}utils.intFromLE=intFromLE},{"bn.js":49,"minimalistic-assert":85,"minimalistic-crypto-utils":86}],68:[function(require,module,exports){module.exports={name:"elliptic",version:"6.5.3",description:"EC cryptography",main:"lib/elliptic.js",files:["lib"],scripts:{jscs:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",jshint:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",lint:"npm run jscs && npm run jshint",unit:"istanbul test _mocha --reporter=spec test/index.js",test:"npm run lint && npm run unit",version:"grunt dist && git add dist/"},repository:{type:"git",url:"git@github.com:indutny/elliptic"},keywords:["EC","Elliptic","curve","Cryptography"],author:"Fedor Indutny ",license:"MIT",bugs:{url:"https://github.com/indutny/elliptic/issues"},homepage:"https://github.com/indutny/elliptic",devDependencies:{brfs:"^1.4.3",coveralls:"^3.0.8",grunt:"^1.0.4","grunt-browserify":"^5.0.0","grunt-cli":"^1.2.0","grunt-contrib-connect":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^1.0.1","grunt-mocha-istanbul":"^3.0.1","grunt-saucelabs":"^9.0.1",istanbul:"^0.4.2",jscs:"^3.0.7",jshint:"^2.10.3",mocha:"^6.2.2"},dependencies:{"bn.js":"^4.4.0",brorand:"^1.0.1","hash.js":"^1.0.0","hmac-drbg":"^1.0.0",inherits:"^2.0.1","minimalistic-assert":"^1.0.0","minimalistic-crypto-utils":"^1.0.0"}}},{}],69:[function(require,module,exports){var hash=exports;hash.utils=require("./hash/utils");hash.common=require("./hash/common");hash.sha=require("./hash/sha");hash.ripemd=require("./hash/ripemd");hash.hmac=require("./hash/hmac");hash.sha1=hash.sha.sha1;hash.sha256=hash.sha.sha256;hash.sha224=hash.sha.sha224;hash.sha384=hash.sha.sha384;hash.sha512=hash.sha.sha512;hash.ripemd160=hash.ripemd.ripemd160},{"./hash/common":70,"./hash/hmac":71,"./hash/ripemd":72,"./hash/sha":73,"./hash/utils":80}],70:[function(require,module,exports){"use strict";var utils=require("./utils");var assert=require("minimalistic-assert");function BlockHash(){this.pending=null;this.pendingTotal=0;this.blockSize=this.constructor.blockSize;this.outSize=this.constructor.outSize;this.hmacStrength=this.constructor.hmacStrength;this.padLength=this.constructor.padLength/8;this.endian="big";this._delta8=this.blockSize/8;this._delta32=this.blockSize/32}exports.BlockHash=BlockHash;BlockHash.prototype.update=function update(msg,enc){msg=utils.toArray(msg,enc);if(!this.pending)this.pending=msg;else this.pending=this.pending.concat(msg);this.pendingTotal+=msg.length;if(this.pending.length>=this._delta8){msg=this.pending;var r=msg.length%this._delta8;this.pending=msg.slice(msg.length-r,msg.length);if(this.pending.length===0)this.pending=null;msg=utils.join32(msg,0,msg.length-r,this.endian);for(var i=0;i>>24&255;res[i++]=len>>>16&255;res[i++]=len>>>8&255;res[i++]=len&255}else{res[i++]=len&255;res[i++]=len>>>8&255;res[i++]=len>>>16&255;res[i++]=len>>>24&255;res[i++]=0;res[i++]=0;res[i++]=0;res[i++]=0;for(t=8;tthis.blockSize)key=(new this.Hash).update(key).digest();assert(key.length<=this.blockSize);for(var i=key.length;i>>3}exports.g0_256=g0_256;function g1_256(x){return rotr32(x,17)^rotr32(x,19)^x>>>10}exports.g1_256=g1_256},{"../utils":80}],80:[function(require,module,exports){"use strict";var assert=require("minimalistic-assert");var inherits=require("inherits");exports.inherits=inherits;function isSurrogatePair(msg,i){if((msg.charCodeAt(i)&64512)!==55296){return false}if(i<0||i+1>=msg.length){return false}return(msg.charCodeAt(i+1)&64512)===56320}function toArray(msg,enc){if(Array.isArray(msg))return msg.slice();if(!msg)return[];var res=[];if(typeof msg==="string"){if(!enc){var p=0;for(var i=0;i>6|192;res[p++]=c&63|128}else if(isSurrogatePair(msg,i)){c=65536+((c&1023)<<10)+(msg.charCodeAt(++i)&1023);res[p++]=c>>18|240;res[p++]=c>>12&63|128;res[p++]=c>>6&63|128;res[p++]=c&63|128}else{res[p++]=c>>12|224;res[p++]=c>>6&63|128;res[p++]=c&63|128}}}else if(enc==="hex"){msg=msg.replace(/[^a-z0-9]+/gi,"");if(msg.length%2!==0)msg="0"+msg;for(i=0;i>>24|w>>>8&65280|w<<8&16711680|(w&255)<<24;return res>>>0}exports.htonl=htonl;function toHex32(msg,endian){var res="";for(var i=0;i>>0}return res}exports.join32=join32;function split32(msg,endian){var res=new Array(msg.length*4);for(var i=0,k=0;i>>24;res[k+1]=m>>>16&255;res[k+2]=m>>>8&255;res[k+3]=m&255}else{res[k+3]=m>>>24;res[k+2]=m>>>16&255;res[k+1]=m>>>8&255;res[k]=m&255}}return res}exports.split32=split32;function rotr32(w,b){return w>>>b|w<<32-b}exports.rotr32=rotr32;function rotl32(w,b){return w<>>32-b}exports.rotl32=rotl32;function sum32(a,b){return a+b>>>0}exports.sum32=sum32;function sum32_3(a,b,c){return a+b+c>>>0}exports.sum32_3=sum32_3;function sum32_4(a,b,c,d){return a+b+c+d>>>0}exports.sum32_4=sum32_4;function sum32_5(a,b,c,d,e){return a+b+c+d+e>>>0}exports.sum32_5=sum32_5;function sum64(buf,pos,ah,al){var bh=buf[pos];var bl=buf[pos+1];var lo=al+bl>>>0;var hi=(lo>>0;buf[pos+1]=lo}exports.sum64=sum64;function sum64_hi(ah,al,bh,bl){var lo=al+bl>>>0;var hi=(lo>>0}exports.sum64_hi=sum64_hi;function sum64_lo(ah,al,bh,bl){var lo=al+bl;return lo>>>0}exports.sum64_lo=sum64_lo;function sum64_4_hi(ah,al,bh,bl,ch,cl,dh,dl){var carry=0;var lo=al;lo=lo+bl>>>0;carry+=lo>>0;carry+=lo>>0;carry+=lo>>0}exports.sum64_4_hi=sum64_4_hi;function sum64_4_lo(ah,al,bh,bl,ch,cl,dh,dl){var lo=al+bl+cl+dl;return lo>>>0}exports.sum64_4_lo=sum64_4_lo;function sum64_5_hi(ah,al,bh,bl,ch,cl,dh,dl,eh,el){var carry=0;var lo=al;lo=lo+bl>>>0;carry+=lo>>0;carry+=lo>>0;carry+=lo>>0;carry+=lo>>0}exports.sum64_5_hi=sum64_5_hi;function sum64_5_lo(ah,al,bh,bl,ch,cl,dh,dl,eh,el){var lo=al+bl+cl+dl+el;return lo>>>0}exports.sum64_5_lo=sum64_5_lo;function rotr64_hi(ah,al,num){var r=al<<32-num|ah>>>num;return r>>>0}exports.rotr64_hi=rotr64_hi;function rotr64_lo(ah,al,num){var r=ah<<32-num|al>>>num;return r>>>0}exports.rotr64_lo=rotr64_lo;function shr64_hi(ah,al,num){return ah>>>num}exports.shr64_hi=shr64_hi;function shr64_lo(ah,al,num){var r=ah<<32-num|al>>>num;return r>>>0}exports.shr64_lo=shr64_lo},{inherits:81,"minimalistic-assert":85}],81:[function(require,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){if(superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}}else{module.exports=function inherits(ctor,superCtor){if(superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}}},{}],82:[function(require,module,exports){"use strict";var hash=require("hash.js");var utils=require("minimalistic-crypto-utils");var assert=require("minimalistic-assert");function HmacDRBG(options){if(!(this instanceof HmacDRBG))return new HmacDRBG(options);this.hash=options.hash;this.predResist=!!options.predResist;this.outLen=this.hash.outSize;this.minEntropy=options.minEntropy||this.hash.hmacStrength;this._reseed=null;this.reseedInterval=null;this.K=null;this.V=null;var entropy=utils.toArray(options.entropy,options.entropyEnc||"hex");var nonce=utils.toArray(options.nonce,options.nonceEnc||"hex");var pers=utils.toArray(options.pers,options.persEnc||"hex");assert(entropy.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits");this._init(entropy,nonce,pers)}module.exports=HmacDRBG;HmacDRBG.prototype._init=function init(entropy,nonce,pers){var seed=entropy.concat(nonce).concat(pers);this.K=new Array(this.outLen/8);this.V=new Array(this.outLen/8);for(var i=0;i=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits");this._update(entropy.concat(add||[]));this._reseed=1};HmacDRBG.prototype.generate=function generate(len,enc,add,addEnc){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");if(typeof enc!=="string"){addEnc=add;add=enc;enc=null}if(add){add=utils.toArray(add,addEnc||"hex");this._update(add)}var temp=[];while(temp.length>>1;var wrapFlags=[["ary",WRAP_ARY_FLAG],["bind",WRAP_BIND_FLAG],["bindKey",WRAP_BIND_KEY_FLAG],["curry",WRAP_CURRY_FLAG],["curryRight",WRAP_CURRY_RIGHT_FLAG],["flip",WRAP_FLIP_FLAG],["partial",WRAP_PARTIAL_FLAG],["partialRight",WRAP_PARTIAL_RIGHT_FLAG],["rearg",WRAP_REARG_FLAG]];var argsTag="[object Arguments]",arrayTag="[object Array]",asyncTag="[object AsyncFunction]",boolTag="[object Boolean]",dateTag="[object Date]",domExcTag="[object DOMException]",errorTag="[object Error]",funcTag="[object Function]",genTag="[object GeneratorFunction]",mapTag="[object Map]",numberTag="[object Number]",nullTag="[object Null]",objectTag="[object Object]",promiseTag="[object Promise]",proxyTag="[object Proxy]",regexpTag="[object RegExp]",setTag="[object Set]",stringTag="[object String]",symbolTag="[object Symbol]",undefinedTag="[object Undefined]",weakMapTag="[object WeakMap]",weakSetTag="[object WeakSet]";var arrayBufferTag="[object ArrayBuffer]",dataViewTag="[object DataView]",float32Tag="[object Float32Array]",float64Tag="[object Float64Array]",int8Tag="[object Int8Array]",int16Tag="[object Int16Array]",int32Tag="[object Int32Array]",uint8Tag="[object Uint8Array]",uint8ClampedTag="[object Uint8ClampedArray]",uint16Tag="[object Uint16Array]",uint32Tag="[object Uint32Array]";var reEmptyStringLeading=/\b__p \+= '';/g,reEmptyStringMiddle=/\b(__p \+=) '' \+/g,reEmptyStringTrailing=/(__e\(.*?\)|\b__t\)) \+\n'';/g;var reEscapedHtml=/&(?:amp|lt|gt|quot|#39);/g,reUnescapedHtml=/[&<>"']/g,reHasEscapedHtml=RegExp(reEscapedHtml.source),reHasUnescapedHtml=RegExp(reUnescapedHtml.source);var reEscape=/<%-([\s\S]+?)%>/g,reEvaluate=/<%([\s\S]+?)%>/g,reInterpolate=/<%=([\s\S]+?)%>/g;var reIsDeepProp=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,reIsPlainProp=/^\w*$/,rePropName=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;var reRegExpChar=/[\\^$.*+?()[\]{}|]/g,reHasRegExpChar=RegExp(reRegExpChar.source);var reTrim=/^\s+|\s+$/g,reTrimStart=/^\s+/,reTrimEnd=/\s+$/;var reWrapComment=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,reWrapDetails=/\{\n\/\* \[wrapped with (.+)\] \*/,reSplitDetails=/,? & /;var reAsciiWord=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;var reEscapeChar=/\\(\\)?/g;var reEsTemplate=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;var reFlags=/\w*$/;var reIsBadHex=/^[-+]0x[0-9a-f]+$/i;var reIsBinary=/^0b[01]+$/i;var reIsHostCtor=/^\[object .+?Constructor\]$/;var reIsOctal=/^0o[0-7]+$/i;var reIsUint=/^(?:0|[1-9]\d*)$/;var reLatin=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;var reNoMatch=/($^)/;var reUnescapedString=/['\n\r\u2028\u2029\\]/g;var rsAstralRange="\\ud800-\\udfff",rsComboMarksRange="\\u0300-\\u036f",reComboHalfMarksRange="\\ufe20-\\ufe2f",rsComboSymbolsRange="\\u20d0-\\u20ff",rsComboRange=rsComboMarksRange+reComboHalfMarksRange+rsComboSymbolsRange,rsDingbatRange="\\u2700-\\u27bf",rsLowerRange="a-z\\xdf-\\xf6\\xf8-\\xff",rsMathOpRange="\\xac\\xb1\\xd7\\xf7",rsNonCharRange="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",rsPunctuationRange="\\u2000-\\u206f",rsSpaceRange=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",rsUpperRange="A-Z\\xc0-\\xd6\\xd8-\\xde",rsVarRange="\\ufe0e\\ufe0f",rsBreakRange=rsMathOpRange+rsNonCharRange+rsPunctuationRange+rsSpaceRange;var rsApos="['’]",rsAstral="["+rsAstralRange+"]",rsBreak="["+rsBreakRange+"]",rsCombo="["+rsComboRange+"]",rsDigits="\\d+",rsDingbat="["+rsDingbatRange+"]",rsLower="["+rsLowerRange+"]",rsMisc="[^"+rsAstralRange+rsBreakRange+rsDigits+rsDingbatRange+rsLowerRange+rsUpperRange+"]",rsFitz="\\ud83c[\\udffb-\\udfff]",rsModifier="(?:"+rsCombo+"|"+rsFitz+")",rsNonAstral="[^"+rsAstralRange+"]",rsRegional="(?:\\ud83c[\\udde6-\\uddff]){2}",rsSurrPair="[\\ud800-\\udbff][\\udc00-\\udfff]",rsUpper="["+rsUpperRange+"]",rsZWJ="\\u200d";var rsMiscLower="(?:"+rsLower+"|"+rsMisc+")",rsMiscUpper="(?:"+rsUpper+"|"+rsMisc+")",rsOptContrLower="(?:"+rsApos+"(?:d|ll|m|re|s|t|ve))?",rsOptContrUpper="(?:"+rsApos+"(?:D|LL|M|RE|S|T|VE))?",reOptMod=rsModifier+"?",rsOptVar="["+rsVarRange+"]?",rsOptJoin="(?:"+rsZWJ+"(?:"+[rsNonAstral,rsRegional,rsSurrPair].join("|")+")"+rsOptVar+reOptMod+")*",rsOrdLower="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",rsOrdUpper="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",rsSeq=rsOptVar+reOptMod+rsOptJoin,rsEmoji="(?:"+[rsDingbat,rsRegional,rsSurrPair].join("|")+")"+rsSeq,rsSymbol="(?:"+[rsNonAstral+rsCombo+"?",rsCombo,rsRegional,rsSurrPair,rsAstral].join("|")+")";var reApos=RegExp(rsApos,"g");var reComboMark=RegExp(rsCombo,"g");var reUnicode=RegExp(rsFitz+"(?="+rsFitz+")|"+rsSymbol+rsSeq,"g");var reUnicodeWord=RegExp([rsUpper+"?"+rsLower+"+"+rsOptContrLower+"(?="+[rsBreak,rsUpper,"$"].join("|")+")",rsMiscUpper+"+"+rsOptContrUpper+"(?="+[rsBreak,rsUpper+rsMiscLower,"$"].join("|")+")",rsUpper+"?"+rsMiscLower+"+"+rsOptContrLower,rsUpper+"+"+rsOptContrUpper,rsOrdUpper,rsOrdLower,rsDigits,rsEmoji].join("|"),"g");var reHasUnicode=RegExp("["+rsZWJ+rsAstralRange+rsComboRange+rsVarRange+"]");var reHasUnicodeWord=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;var contextProps=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"];var templateCounter=-1;var typedArrayTags={};typedArrayTags[float32Tag]=typedArrayTags[float64Tag]=typedArrayTags[int8Tag]=typedArrayTags[int16Tag]=typedArrayTags[int32Tag]=typedArrayTags[uint8Tag]=typedArrayTags[uint8ClampedTag]=typedArrayTags[uint16Tag]=typedArrayTags[uint32Tag]=true;typedArrayTags[argsTag]=typedArrayTags[arrayTag]=typedArrayTags[arrayBufferTag]=typedArrayTags[boolTag]=typedArrayTags[dataViewTag]=typedArrayTags[dateTag]=typedArrayTags[errorTag]=typedArrayTags[funcTag]=typedArrayTags[mapTag]=typedArrayTags[numberTag]=typedArrayTags[objectTag]=typedArrayTags[regexpTag]=typedArrayTags[setTag]=typedArrayTags[stringTag]=typedArrayTags[weakMapTag]=false;var cloneableTags={};cloneableTags[argsTag]=cloneableTags[arrayTag]=cloneableTags[arrayBufferTag]=cloneableTags[dataViewTag]=cloneableTags[boolTag]=cloneableTags[dateTag]=cloneableTags[float32Tag]=cloneableTags[float64Tag]=cloneableTags[int8Tag]=cloneableTags[int16Tag]=cloneableTags[int32Tag]=cloneableTags[mapTag]=cloneableTags[numberTag]=cloneableTags[objectTag]=cloneableTags[regexpTag]=cloneableTags[setTag]=cloneableTags[stringTag]=cloneableTags[symbolTag]=cloneableTags[uint8Tag]=cloneableTags[uint8ClampedTag]=cloneableTags[uint16Tag]=cloneableTags[uint32Tag]=true;cloneableTags[errorTag]=cloneableTags[funcTag]=cloneableTags[weakMapTag]=false;var deburredLetters={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","IJ":"IJ","ij":"ij","Œ":"Oe","œ":"oe","ʼn":"'n","ſ":"s"};var htmlEscapes={"&":"&","<":"<",">":">",'"':""","'":"'"};var htmlUnescapes={"&":"&","<":"<",">":">",""":'"',"'":"'"};var stringEscapes={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"};var freeParseFloat=parseFloat,freeParseInt=parseInt;var freeGlobal=typeof global=="object"&&global&&global.Object===Object&&global;var freeSelf=typeof self=="object"&&self&&self.Object===Object&&self;var root=freeGlobal||freeSelf||Function("return this")();var freeExports=typeof exports=="object"&&exports&&!exports.nodeType&&exports;var freeModule=freeExports&&typeof module=="object"&&module&&!module.nodeType&&module;var moduleExports=freeModule&&freeModule.exports===freeExports;var freeProcess=moduleExports&&freeGlobal.process;var nodeUtil=function(){try{var types=freeModule&&freeModule.require&&freeModule.require("util").types;if(types){return types}return freeProcess&&freeProcess.binding&&freeProcess.binding("util")}catch(e){}}();var nodeIsArrayBuffer=nodeUtil&&nodeUtil.isArrayBuffer,nodeIsDate=nodeUtil&&nodeUtil.isDate,nodeIsMap=nodeUtil&&nodeUtil.isMap,nodeIsRegExp=nodeUtil&&nodeUtil.isRegExp,nodeIsSet=nodeUtil&&nodeUtil.isSet,nodeIsTypedArray=nodeUtil&&nodeUtil.isTypedArray;function apply(func,thisArg,args){switch(args.length){case 0:return func.call(thisArg);case 1:return func.call(thisArg,args[0]);case 2:return func.call(thisArg,args[0],args[1]);case 3:return func.call(thisArg,args[0],args[1],args[2])}return func.apply(thisArg,args)}function arrayAggregator(array,setter,iteratee,accumulator){var index=-1,length=array==null?0:array.length;while(++index-1}function arrayIncludesWith(array,value,comparator){var index=-1,length=array==null?0:array.length;while(++index-1){}return index}function charsEndIndex(strSymbols,chrSymbols){var index=strSymbols.length;while(index--&&baseIndexOf(chrSymbols,strSymbols[index],0)>-1){}return index}function countHolders(array,placeholder){var length=array.length,result=0;while(length--){if(array[length]===placeholder){++result}}return result}var deburrLetter=basePropertyOf(deburredLetters);var escapeHtmlChar=basePropertyOf(htmlEscapes);function escapeStringChar(chr){return"\\"+stringEscapes[chr]}function getValue(object,key){return object==null?undefined:object[key]}function hasUnicode(string){return reHasUnicode.test(string)}function hasUnicodeWord(string){return reHasUnicodeWord.test(string)}function iteratorToArray(iterator){var data,result=[];while(!(data=iterator.next()).done){result.push(data.value)}return result}function mapToArray(map){var index=-1,result=Array(map.size);map.forEach(function(value,key){result[++index]=[key,value]});return result}function overArg(func,transform){return function(arg){return func(transform(arg))}}function replaceHolders(array,placeholder){var index=-1,length=array.length,resIndex=0,result=[];while(++index-1}function listCacheSet(key,value){var data=this.__data__,index=assocIndexOf(data,key);if(index<0){++this.size;data.push([key,value])}else{data[index][1]=value}return this}ListCache.prototype.clear=listCacheClear;ListCache.prototype["delete"]=listCacheDelete;ListCache.prototype.get=listCacheGet;ListCache.prototype.has=listCacheHas;ListCache.prototype.set=listCacheSet;function MapCache(entries){var index=-1,length=entries==null?0:entries.length;this.clear();while(++index=lower?number:lower}}return number}function baseClone(value,bitmask,customizer,key,object,stack){var result,isDeep=bitmask&CLONE_DEEP_FLAG,isFlat=bitmask&CLONE_FLAT_FLAG,isFull=bitmask&CLONE_SYMBOLS_FLAG;if(customizer){result=object?customizer(value,key,object,stack):customizer(value)}if(result!==undefined){return result}if(!isObject(value)){return value}var isArr=isArray(value);if(isArr){result=initCloneArray(value);if(!isDeep){return copyArray(value,result)}}else{var tag=getTag(value),isFunc=tag==funcTag||tag==genTag;if(isBuffer(value)){return cloneBuffer(value,isDeep)}if(tag==objectTag||tag==argsTag||isFunc&&!object){result=isFlat||isFunc?{}:initCloneObject(value);if(!isDeep){return isFlat?copySymbolsIn(value,baseAssignIn(result,value)):copySymbols(value,baseAssign(result,value))}}else{if(!cloneableTags[tag]){return object?value:{}}result=initCloneByTag(value,tag,isDeep)}}stack||(stack=new Stack);var stacked=stack.get(value);if(stacked){return stacked}stack.set(value,result);if(isSet(value)){value.forEach(function(subValue){result.add(baseClone(subValue,bitmask,customizer,subValue,value,stack))})}else if(isMap(value)){value.forEach(function(subValue,key){result.set(key,baseClone(subValue,bitmask,customizer,key,value,stack))})}var keysFunc=isFull?isFlat?getAllKeysIn:getAllKeys:isFlat?keysIn:keys;var props=isArr?undefined:keysFunc(value);arrayEach(props||value,function(subValue,key){if(props){key=subValue;subValue=value[key]}assignValue(result,key,baseClone(subValue,bitmask,customizer,key,value,stack))});return result}function baseConforms(source){var props=keys(source);return function(object){return baseConformsTo(object,source,props)}}function baseConformsTo(object,source,props){var length=props.length;if(object==null){return!length}object=Object(object);while(length--){var key=props[length],predicate=source[key],value=object[key];if(value===undefined&&!(key in object)||!predicate(value)){return false}}return true}function baseDelay(func,wait,args){if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}return setTimeout(function(){func.apply(undefined,args)},wait)}function baseDifference(array,values,iteratee,comparator){var index=-1,includes=arrayIncludes,isCommon=true,length=array.length,result=[],valuesLength=values.length;if(!length){return result}if(iteratee){values=arrayMap(values,baseUnary(iteratee))}if(comparator){includes=arrayIncludesWith;isCommon=false}else if(values.length>=LARGE_ARRAY_SIZE){includes=cacheHas;isCommon=false;values=new SetCache(values)}outer:while(++indexlength?0:length+start}end=end===undefined||end>length?length:toInteger(end);if(end<0){end+=length}end=start>end?0:toLength(end);while(start0&&predicate(value)){if(depth>1){baseFlatten(value,depth-1,predicate,isStrict,result)}else{arrayPush(result,value)}}else if(!isStrict){result[result.length]=value}}return result}var baseFor=createBaseFor();var baseForRight=createBaseFor(true);function baseForOwn(object,iteratee){return object&&baseFor(object,iteratee,keys)}function baseForOwnRight(object,iteratee){return object&&baseForRight(object,iteratee,keys)}function baseFunctions(object,props){return arrayFilter(props,function(key){return isFunction(object[key])})}function baseGet(object,path){path=castPath(path,object);var index=0,length=path.length;while(object!=null&&indexother}function baseHas(object,key){return object!=null&&hasOwnProperty.call(object,key)}function baseHasIn(object,key){return object!=null&&key in Object(object)}function baseInRange(number,start,end){return number>=nativeMin(start,end)&&number=120&&array.length>=120)?new SetCache(othIndex&&array):undefined}array=arrays[0];var index=-1,seen=caches[0];outer:while(++index-1){if(seen!==array){splice.call(seen,fromIndex,1)}splice.call(array,fromIndex,1)}}return array}function basePullAt(array,indexes){var length=array?indexes.length:0,lastIndex=length-1;while(length--){var index=indexes[length];if(length==lastIndex||index!==previous){var previous=index;if(isIndex(index)){splice.call(array,index,1)}else{baseUnset(array,index)}}}return array}function baseRandom(lower,upper){return lower+nativeFloor(nativeRandom()*(upper-lower+1))}function baseRange(start,end,step,fromRight){var index=-1,length=nativeMax(nativeCeil((end-start)/(step||1)),0),result=Array(length);while(length--){result[fromRight?length:++index]=start;start+=step}return result}function baseRepeat(string,n){var result="";if(!string||n<1||n>MAX_SAFE_INTEGER){return result}do{if(n%2){result+=string}n=nativeFloor(n/2);if(n){string+=string}}while(n);return result}function baseRest(func,start){return setToString(overRest(func,start,identity),func+"")}function baseSample(collection){return arraySample(values(collection))}function baseSampleSize(collection,n){var array=values(collection);return shuffleSelf(array,baseClamp(n,0,array.length))}function baseSet(object,path,value,customizer){if(!isObject(object)){return object}path=castPath(path,object);var index=-1,length=path.length,lastIndex=length-1,nested=object;while(nested!=null&&++indexlength?0:length+start}end=end>length?length:end;if(end<0){end+=length}length=start>end?0:end-start>>>0;start>>>=0;var result=Array(length);while(++index>>1,computed=array[mid];if(computed!==null&&!isSymbol(computed)&&(retHighest?computed<=value:computed=LARGE_ARRAY_SIZE){var set=iteratee?null:createSet(array);if(set){return setToArray(set)}isCommon=false;includes=cacheHas;seen=new SetCache}else{seen=iteratee?[]:result}outer:while(++index=length?array:baseSlice(array,start,end)}var clearTimeout=ctxClearTimeout||function(id){return root.clearTimeout(id)};function cloneBuffer(buffer,isDeep){if(isDeep){return buffer.slice()}var length=buffer.length,result=allocUnsafe?allocUnsafe(length):new buffer.constructor(length);buffer.copy(result);return result}function cloneArrayBuffer(arrayBuffer){var result=new arrayBuffer.constructor(arrayBuffer.byteLength);new Uint8Array(result).set(new Uint8Array(arrayBuffer));return result}function cloneDataView(dataView,isDeep){var buffer=isDeep?cloneArrayBuffer(dataView.buffer):dataView.buffer;return new dataView.constructor(buffer,dataView.byteOffset,dataView.byteLength)}function cloneRegExp(regexp){var result=new regexp.constructor(regexp.source,reFlags.exec(regexp));result.lastIndex=regexp.lastIndex;return result}function cloneSymbol(symbol){return symbolValueOf?Object(symbolValueOf.call(symbol)):{}}function cloneTypedArray(typedArray,isDeep){var buffer=isDeep?cloneArrayBuffer(typedArray.buffer):typedArray.buffer;return new typedArray.constructor(buffer,typedArray.byteOffset,typedArray.length)}function compareAscending(value,other){if(value!==other){var valIsDefined=value!==undefined,valIsNull=value===null,valIsReflexive=value===value,valIsSymbol=isSymbol(value);var othIsDefined=other!==undefined,othIsNull=other===null,othIsReflexive=other===other,othIsSymbol=isSymbol(other);if(!othIsNull&&!othIsSymbol&&!valIsSymbol&&value>other||valIsSymbol&&othIsDefined&&othIsReflexive&&!othIsNull&&!othIsSymbol||valIsNull&&othIsDefined&&othIsReflexive||!valIsDefined&&othIsReflexive||!valIsReflexive){return 1}if(!valIsNull&&!valIsSymbol&&!othIsSymbol&&value=ordersLength){return result}var order=orders[index];return result*(order=="desc"?-1:1)}}return object.index-other.index}function composeArgs(args,partials,holders,isCurried){var argsIndex=-1,argsLength=args.length,holdersLength=holders.length,leftIndex=-1,leftLength=partials.length,rangeLength=nativeMax(argsLength-holdersLength,0),result=Array(leftLength+rangeLength),isUncurried=!isCurried;while(++leftIndex1?sources[length-1]:undefined,guard=length>2?sources[2]:undefined;customizer=assigner.length>3&&typeof customizer=="function"?(length--,customizer):undefined;if(guard&&isIterateeCall(sources[0],sources[1],guard)){customizer=length<3?undefined:customizer;length=1}object=Object(object);while(++index-1?iterable[iteratee?collection[index]:index]:undefined}}function createFlow(fromRight){return flatRest(function(funcs){var length=funcs.length,index=length,prereq=LodashWrapper.prototype.thru;if(fromRight){funcs.reverse()}while(index--){var func=funcs[index];if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}if(prereq&&!wrapper&&getFuncName(func)=="wrapper"){var wrapper=new LodashWrapper([],true)}}index=wrapper?index:length;while(++index1){args.reverse()}if(isAry&&aryarrLength)){return false}var arrStacked=stack.get(array);var othStacked=stack.get(other);if(arrStacked&&othStacked){return arrStacked==other&&othStacked==array}var index=-1,result=true,seen=bitmask&COMPARE_UNORDERED_FLAG?new SetCache:undefined;stack.set(array,other);stack.set(other,array);while(++index1?"& ":"")+details[lastIndex];details=details.join(length>2?", ":" ");return source.replace(reWrapComment,"{\n/* [wrapped with "+details+"] */\n")}function isFlattenable(value){return isArray(value)||isArguments(value)||!!(spreadableSymbol&&value&&value[spreadableSymbol])}function isIndex(value,length){var type=typeof value;length=length==null?MAX_SAFE_INTEGER:length;return!!length&&(type=="number"||type!="symbol"&&reIsUint.test(value))&&(value>-1&&value%1==0&&value0){if(++count>=HOT_COUNT){return arguments[0]}}else{count=0}return func.apply(undefined,arguments)}}function shuffleSelf(array,size){var index=-1,length=array.length,lastIndex=length-1;size=size===undefined?length:size;while(++index1?arrays[length-1]:undefined;iteratee=typeof iteratee=="function"?(arrays.pop(),iteratee):undefined;return unzipWith(arrays,iteratee)});function chain(value){var result=lodash(value);result.__chain__=true;return result}function tap(value,interceptor){interceptor(value);return value}function thru(value,interceptor){return interceptor(value)}var wrapperAt=flatRest(function(paths){var length=paths.length,start=length?paths[0]:0,value=this.__wrapped__,interceptor=function(object){return baseAt(object,paths)};if(length>1||this.__actions__.length||!(value instanceof LazyWrapper)||!isIndex(start)){return this.thru(interceptor)}value=value.slice(start,+start+(length?1:0));value.__actions__.push({func:thru,args:[interceptor],thisArg:undefined});return new LodashWrapper(value,this.__chain__).thru(function(array){if(length&&!array.length){array.push(undefined)}return array})});function wrapperChain(){return chain(this)}function wrapperCommit(){return new LodashWrapper(this.value(),this.__chain__)}function wrapperNext(){if(this.__values__===undefined){this.__values__=toArray(this.value())}var done=this.__index__>=this.__values__.length,value=done?undefined:this.__values__[this.__index__++];return{done:done,value:value}}function wrapperToIterator(){return this}function wrapperPlant(value){var result,parent=this;while(parent instanceof baseLodash){var clone=wrapperClone(parent);clone.__index__=0;clone.__values__=undefined;if(result){previous.__wrapped__=clone}else{result=clone}var previous=clone;parent=parent.__wrapped__}previous.__wrapped__=value;return result}function wrapperReverse(){var value=this.__wrapped__;if(value instanceof LazyWrapper){var wrapped=value;if(this.__actions__.length){wrapped=new LazyWrapper(this)}wrapped=wrapped.reverse();wrapped.__actions__.push({func:thru,args:[reverse],thisArg:undefined});return new LodashWrapper(wrapped,this.__chain__)}return this.thru(reverse)}function wrapperValue(){return baseWrapperValue(this.__wrapped__,this.__actions__)}var countBy=createAggregator(function(result,value,key){if(hasOwnProperty.call(result,key)){++result[key]}else{baseAssignValue(result,key,1)}});function every(collection,predicate,guard){var func=isArray(collection)?arrayEvery:baseEvery;if(guard&&isIterateeCall(collection,predicate,guard)){predicate=undefined}return func(collection,getIteratee(predicate,3))}function filter(collection,predicate){var func=isArray(collection)?arrayFilter:baseFilter;return func(collection,getIteratee(predicate,3))}var find=createFind(findIndex);var findLast=createFind(findLastIndex);function flatMap(collection,iteratee){return baseFlatten(map(collection,iteratee),1)}function flatMapDeep(collection,iteratee){return baseFlatten(map(collection,iteratee),INFINITY)}function flatMapDepth(collection,iteratee,depth){depth=depth===undefined?1:toInteger(depth);return baseFlatten(map(collection,iteratee),depth)}function forEach(collection,iteratee){var func=isArray(collection)?arrayEach:baseEach;return func(collection,getIteratee(iteratee,3))}function forEachRight(collection,iteratee){var func=isArray(collection)?arrayEachRight:baseEachRight;return func(collection,getIteratee(iteratee,3))}var groupBy=createAggregator(function(result,value,key){if(hasOwnProperty.call(result,key)){result[key].push(value)}else{baseAssignValue(result,key,[value])}});function includes(collection,value,fromIndex,guard){collection=isArrayLike(collection)?collection:values(collection);fromIndex=fromIndex&&!guard?toInteger(fromIndex):0;var length=collection.length;if(fromIndex<0){fromIndex=nativeMax(length+fromIndex,0)}return isString(collection)?fromIndex<=length&&collection.indexOf(value,fromIndex)>-1:!!length&&baseIndexOf(collection,value,fromIndex)>-1}var invokeMap=baseRest(function(collection,path,args){var index=-1,isFunc=typeof path=="function",result=isArrayLike(collection)?Array(collection.length):[];baseEach(collection,function(value){result[++index]=isFunc?apply(path,value,args):baseInvoke(value,path,args)});return result});var keyBy=createAggregator(function(result,value,key){baseAssignValue(result,key,value)});function map(collection,iteratee){var func=isArray(collection)?arrayMap:baseMap;return func(collection,getIteratee(iteratee,3))}function orderBy(collection,iteratees,orders,guard){if(collection==null){return[]}if(!isArray(iteratees)){iteratees=iteratees==null?[]:[iteratees]}orders=guard?undefined:orders;if(!isArray(orders)){orders=orders==null?[]:[orders]}return baseOrderBy(collection,iteratees,orders)}var partition=createAggregator(function(result,value,key){result[key?0:1].push(value)},function(){return[[],[]]});function reduce(collection,iteratee,accumulator){var func=isArray(collection)?arrayReduce:baseReduce,initAccum=arguments.length<3;return func(collection,getIteratee(iteratee,4),accumulator,initAccum,baseEach)}function reduceRight(collection,iteratee,accumulator){var func=isArray(collection)?arrayReduceRight:baseReduce,initAccum=arguments.length<3;return func(collection,getIteratee(iteratee,4),accumulator,initAccum,baseEachRight)}function reject(collection,predicate){var func=isArray(collection)?arrayFilter:baseFilter;return func(collection,negate(getIteratee(predicate,3)))}function sample(collection){var func=isArray(collection)?arraySample:baseSample;return func(collection)}function sampleSize(collection,n,guard){if(guard?isIterateeCall(collection,n,guard):n===undefined){n=1}else{n=toInteger(n)}var func=isArray(collection)?arraySampleSize:baseSampleSize;return func(collection,n)}function shuffle(collection){var func=isArray(collection)?arrayShuffle:baseShuffle;return func(collection)}function size(collection){if(collection==null){return 0}if(isArrayLike(collection)){return isString(collection)?stringSize(collection):collection.length}var tag=getTag(collection);if(tag==mapTag||tag==setTag){return collection.size}return baseKeys(collection).length}function some(collection,predicate,guard){var func=isArray(collection)?arraySome:baseSome;if(guard&&isIterateeCall(collection,predicate,guard)){predicate=undefined}return func(collection,getIteratee(predicate,3))}var sortBy=baseRest(function(collection,iteratees){if(collection==null){return[]}var length=iteratees.length;if(length>1&&isIterateeCall(collection,iteratees[0],iteratees[1])){iteratees=[]}else if(length>2&&isIterateeCall(iteratees[0],iteratees[1],iteratees[2])){iteratees=[iteratees[0]]}return baseOrderBy(collection,baseFlatten(iteratees,1),[])});var now=ctxNow||function(){return root.Date.now()};function after(n,func){if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}n=toInteger(n);return function(){if(--n<1){return func.apply(this,arguments)}}}function ary(func,n,guard){n=guard?undefined:n;n=func&&n==null?func.length:n;return createWrap(func,WRAP_ARY_FLAG,undefined,undefined,undefined,undefined,n)}function before(n,func){var result;if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}n=toInteger(n);return function(){if(--n>0){result=func.apply(this,arguments)}if(n<=1){func=undefined}return result}}var bind=baseRest(function(func,thisArg,partials){var bitmask=WRAP_BIND_FLAG;if(partials.length){var holders=replaceHolders(partials,getHolder(bind));bitmask|=WRAP_PARTIAL_FLAG}return createWrap(func,bitmask,thisArg,partials,holders)});var bindKey=baseRest(function(object,key,partials){var bitmask=WRAP_BIND_FLAG|WRAP_BIND_KEY_FLAG;if(partials.length){var holders=replaceHolders(partials,getHolder(bindKey));bitmask|=WRAP_PARTIAL_FLAG}return createWrap(key,bitmask,object,partials,holders)});function curry(func,arity,guard){arity=guard?undefined:arity;var result=createWrap(func,WRAP_CURRY_FLAG,undefined,undefined,undefined,undefined,undefined,arity);result.placeholder=curry.placeholder;return result}function curryRight(func,arity,guard){arity=guard?undefined:arity;var result=createWrap(func,WRAP_CURRY_RIGHT_FLAG,undefined,undefined,undefined,undefined,undefined,arity);result.placeholder=curryRight.placeholder;return result}function debounce(func,wait,options){var lastArgs,lastThis,maxWait,result,timerId,lastCallTime,lastInvokeTime=0,leading=false,maxing=false,trailing=true;if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}wait=toNumber(wait)||0;if(isObject(options)){leading=!!options.leading;maxing="maxWait"in options;maxWait=maxing?nativeMax(toNumber(options.maxWait)||0,wait):maxWait;trailing="trailing"in options?!!options.trailing:trailing}function invokeFunc(time){var args=lastArgs,thisArg=lastThis;lastArgs=lastThis=undefined;lastInvokeTime=time;result=func.apply(thisArg,args);return result}function leadingEdge(time){lastInvokeTime=time;timerId=setTimeout(timerExpired,wait);return leading?invokeFunc(time):result}function remainingWait(time){var timeSinceLastCall=time-lastCallTime,timeSinceLastInvoke=time-lastInvokeTime,timeWaiting=wait-timeSinceLastCall;return maxing?nativeMin(timeWaiting,maxWait-timeSinceLastInvoke):timeWaiting}function shouldInvoke(time){var timeSinceLastCall=time-lastCallTime,timeSinceLastInvoke=time-lastInvokeTime;return lastCallTime===undefined||timeSinceLastCall>=wait||timeSinceLastCall<0||maxing&&timeSinceLastInvoke>=maxWait}function timerExpired(){var time=now();if(shouldInvoke(time)){return trailingEdge(time)}timerId=setTimeout(timerExpired,remainingWait(time))}function trailingEdge(time){timerId=undefined;if(trailing&&lastArgs){return invokeFunc(time)}lastArgs=lastThis=undefined;return result}function cancel(){if(timerId!==undefined){clearTimeout(timerId)}lastInvokeTime=0;lastArgs=lastCallTime=lastThis=timerId=undefined}function flush(){return timerId===undefined?result:trailingEdge(now())}function debounced(){var time=now(),isInvoking=shouldInvoke(time);lastArgs=arguments;lastThis=this;lastCallTime=time;if(isInvoking){if(timerId===undefined){return leadingEdge(lastCallTime)}if(maxing){clearTimeout(timerId);timerId=setTimeout(timerExpired,wait);return invokeFunc(lastCallTime)}}if(timerId===undefined){timerId=setTimeout(timerExpired,wait)}return result}debounced.cancel=cancel;debounced.flush=flush;return debounced}var defer=baseRest(function(func,args){return baseDelay(func,1,args)});var delay=baseRest(function(func,wait,args){return baseDelay(func,toNumber(wait)||0,args)});function flip(func){return createWrap(func,WRAP_FLIP_FLAG)}function memoize(func,resolver){if(typeof func!="function"||resolver!=null&&typeof resolver!="function"){throw new TypeError(FUNC_ERROR_TEXT)}var memoized=function(){var args=arguments,key=resolver?resolver.apply(this,args):args[0],cache=memoized.cache;if(cache.has(key)){return cache.get(key)}var result=func.apply(this,args);memoized.cache=cache.set(key,result)||cache;return result};memoized.cache=new(memoize.Cache||MapCache);return memoized}memoize.Cache=MapCache;function negate(predicate){if(typeof predicate!="function"){throw new TypeError(FUNC_ERROR_TEXT)}return function(){var args=arguments;switch(args.length){case 0:return!predicate.call(this);case 1:return!predicate.call(this,args[0]);case 2:return!predicate.call(this,args[0],args[1]);case 3:return!predicate.call(this,args[0],args[1],args[2])}return!predicate.apply(this,args)}}function once(func){return before(2,func)}var overArgs=castRest(function(func,transforms){transforms=transforms.length==1&&isArray(transforms[0])?arrayMap(transforms[0],baseUnary(getIteratee())):arrayMap(baseFlatten(transforms,1),baseUnary(getIteratee()));var funcsLength=transforms.length;return baseRest(function(args){var index=-1,length=nativeMin(args.length,funcsLength);while(++index=other});var isArguments=baseIsArguments(function(){return arguments}())?baseIsArguments:function(value){return isObjectLike(value)&&hasOwnProperty.call(value,"callee")&&!propertyIsEnumerable.call(value,"callee")};var isArray=Array.isArray;var isArrayBuffer=nodeIsArrayBuffer?baseUnary(nodeIsArrayBuffer):baseIsArrayBuffer;function isArrayLike(value){return value!=null&&isLength(value.length)&&!isFunction(value)}function isArrayLikeObject(value){return isObjectLike(value)&&isArrayLike(value)}function isBoolean(value){return value===true||value===false||isObjectLike(value)&&baseGetTag(value)==boolTag}var isBuffer=nativeIsBuffer||stubFalse;var isDate=nodeIsDate?baseUnary(nodeIsDate):baseIsDate;function isElement(value){return isObjectLike(value)&&value.nodeType===1&&!isPlainObject(value)}function isEmpty(value){if(value==null){return true}if(isArrayLike(value)&&(isArray(value)||typeof value=="string"||typeof value.splice=="function"||isBuffer(value)||isTypedArray(value)||isArguments(value))){return!value.length}var tag=getTag(value);if(tag==mapTag||tag==setTag){return!value.size}if(isPrototype(value)){return!baseKeys(value).length}for(var key in value){if(hasOwnProperty.call(value,key)){return false}}return true}function isEqual(value,other){return baseIsEqual(value,other)}function isEqualWith(value,other,customizer){customizer=typeof customizer=="function"?customizer:undefined;var result=customizer?customizer(value,other):undefined;return result===undefined?baseIsEqual(value,other,undefined,customizer):!!result}function isError(value){if(!isObjectLike(value)){return false}var tag=baseGetTag(value);return tag==errorTag||tag==domExcTag||typeof value.message=="string"&&typeof value.name=="string"&&!isPlainObject(value)}function isFinite(value){return typeof value=="number"&&nativeIsFinite(value)}function isFunction(value){if(!isObject(value)){return false}var tag=baseGetTag(value);return tag==funcTag||tag==genTag||tag==asyncTag||tag==proxyTag}function isInteger(value){return typeof value=="number"&&value==toInteger(value)}function isLength(value){return typeof value=="number"&&value>-1&&value%1==0&&value<=MAX_SAFE_INTEGER}function isObject(value){var type=typeof value;return value!=null&&(type=="object"||type=="function")}function isObjectLike(value){return value!=null&&typeof value=="object"}var isMap=nodeIsMap?baseUnary(nodeIsMap):baseIsMap;function isMatch(object,source){return object===source||baseIsMatch(object,source,getMatchData(source))}function isMatchWith(object,source,customizer){customizer=typeof customizer=="function"?customizer:undefined;return baseIsMatch(object,source,getMatchData(source),customizer)}function isNaN(value){return isNumber(value)&&value!=+value}function isNative(value){if(isMaskable(value)){throw new Error(CORE_ERROR_TEXT)}return baseIsNative(value)}function isNull(value){return value===null}function isNil(value){return value==null}function isNumber(value){return typeof value=="number"||isObjectLike(value)&&baseGetTag(value)==numberTag}function isPlainObject(value){if(!isObjectLike(value)||baseGetTag(value)!=objectTag){return false}var proto=getPrototype(value);if(proto===null){return true}var Ctor=hasOwnProperty.call(proto,"constructor")&&proto.constructor;return typeof Ctor=="function"&&Ctor instanceof Ctor&&funcToString.call(Ctor)==objectCtorString}var isRegExp=nodeIsRegExp?baseUnary(nodeIsRegExp):baseIsRegExp;function isSafeInteger(value){return isInteger(value)&&value>=-MAX_SAFE_INTEGER&&value<=MAX_SAFE_INTEGER}var isSet=nodeIsSet?baseUnary(nodeIsSet):baseIsSet;function isString(value){return typeof value=="string"||!isArray(value)&&isObjectLike(value)&&baseGetTag(value)==stringTag}function isSymbol(value){return typeof value=="symbol"||isObjectLike(value)&&baseGetTag(value)==symbolTag}var isTypedArray=nodeIsTypedArray?baseUnary(nodeIsTypedArray):baseIsTypedArray;function isUndefined(value){return value===undefined}function isWeakMap(value){return isObjectLike(value)&&getTag(value)==weakMapTag}function isWeakSet(value){return isObjectLike(value)&&baseGetTag(value)==weakSetTag}var lt=createRelationalOperation(baseLt);var lte=createRelationalOperation(function(value,other){return value<=other});function toArray(value){if(!value){return[]}if(isArrayLike(value)){return isString(value)?stringToArray(value):copyArray(value)}if(symIterator&&value[symIterator]){return iteratorToArray(value[symIterator]())}var tag=getTag(value),func=tag==mapTag?mapToArray:tag==setTag?setToArray:values;return func(value)}function toFinite(value){if(!value){return value===0?value:0}value=toNumber(value);if(value===INFINITY||value===-INFINITY){var sign=value<0?-1:1;return sign*MAX_INTEGER}return value===value?value:0}function toInteger(value){var result=toFinite(value),remainder=result%1;return result===result?remainder?result-remainder:result:0}function toLength(value){return value?baseClamp(toInteger(value),0,MAX_ARRAY_LENGTH):0}function toNumber(value){if(typeof value=="number"){return value}if(isSymbol(value)){return NAN}if(isObject(value)){var other=typeof value.valueOf=="function"?value.valueOf():value;value=isObject(other)?other+"":other}if(typeof value!="string"){return value===0?value:+value}value=value.replace(reTrim,"");var isBinary=reIsBinary.test(value);return isBinary||reIsOctal.test(value)?freeParseInt(value.slice(2),isBinary?2:8):reIsBadHex.test(value)?NAN:+value}function toPlainObject(value){return copyObject(value,keysIn(value))}function toSafeInteger(value){return value?baseClamp(toInteger(value),-MAX_SAFE_INTEGER,MAX_SAFE_INTEGER):value===0?value:0}function toString(value){return value==null?"":baseToString(value)}var assign=createAssigner(function(object,source){if(isPrototype(source)||isArrayLike(source)){copyObject(source,keys(source),object);return}for(var key in source){if(hasOwnProperty.call(source,key)){assignValue(object,key,source[key])}}});var assignIn=createAssigner(function(object,source){copyObject(source,keysIn(source),object)});var assignInWith=createAssigner(function(object,source,srcIndex,customizer){copyObject(source,keysIn(source),object,customizer)});var assignWith=createAssigner(function(object,source,srcIndex,customizer){copyObject(source,keys(source),object,customizer)});var at=flatRest(baseAt);function create(prototype,properties){var result=baseCreate(prototype);return properties==null?result:baseAssign(result,properties)}var defaults=baseRest(function(object,sources){object=Object(object);var index=-1;var length=sources.length;var guard=length>2?sources[2]:undefined;if(guard&&isIterateeCall(sources[0],sources[1],guard)){length=1}while(++index1);return path});copyObject(object,getAllKeysIn(object),result);if(isDeep){result=baseClone(result,CLONE_DEEP_FLAG|CLONE_FLAT_FLAG|CLONE_SYMBOLS_FLAG,customOmitClone)}var length=paths.length;while(length--){baseUnset(result,paths[length])}return result});function omitBy(object,predicate){return pickBy(object,negate(getIteratee(predicate)))}var pick=flatRest(function(object,paths){return object==null?{}:basePick(object,paths)});function pickBy(object,predicate){if(object==null){return{}}var props=arrayMap(getAllKeysIn(object),function(prop){return[prop]});predicate=getIteratee(predicate);return basePickBy(object,props,function(value,path){return predicate(value,path[0])})}function result(object,path,defaultValue){path=castPath(path,object);var index=-1,length=path.length;if(!length){length=1;object=undefined}while(++indexupper){var temp=lower;lower=upper;upper=temp}if(floating||lower%1||upper%1){var rand=nativeRandom();return nativeMin(lower+rand*(upper-lower+freeParseFloat("1e-"+((rand+"").length-1))),upper)}return baseRandom(lower,upper)}var camelCase=createCompounder(function(result,word,index){word=word.toLowerCase();return result+(index?capitalize(word):word)});function capitalize(string){return upperFirst(toString(string).toLowerCase())}function deburr(string){string=toString(string);return string&&string.replace(reLatin,deburrLetter).replace(reComboMark,"")}function endsWith(string,target,position){string=toString(string);target=baseToString(target);var length=string.length;position=position===undefined?length:baseClamp(toInteger(position),0,length);var end=position;position-=target.length;return position>=0&&string.slice(position,end)==target}function escape(string){string=toString(string);return string&&reHasUnescapedHtml.test(string)?string.replace(reUnescapedHtml,escapeHtmlChar):string}function escapeRegExp(string){string=toString(string);return string&&reHasRegExpChar.test(string)?string.replace(reRegExpChar,"\\$&"):string}var kebabCase=createCompounder(function(result,word,index){return result+(index?"-":"")+word.toLowerCase()});var lowerCase=createCompounder(function(result,word,index){return result+(index?" ":"")+word.toLowerCase()});var lowerFirst=createCaseFirst("toLowerCase");function pad(string,length,chars){string=toString(string);length=toInteger(length);var strLength=length?stringSize(string):0;if(!length||strLength>=length){return string}var mid=(length-strLength)/2;return createPadding(nativeFloor(mid),chars)+string+createPadding(nativeCeil(mid),chars)}function padEnd(string,length,chars){string=toString(string);length=toInteger(length);var strLength=length?stringSize(string):0;return length&&strLength>>0;if(!limit){return[]}string=toString(string);if(string&&(typeof separator=="string"||separator!=null&&!isRegExp(separator))){separator=baseToString(separator);if(!separator&&hasUnicode(string)){return castSlice(stringToArray(string),0,limit)}}return string.split(separator,limit)}var startCase=createCompounder(function(result,word,index){return result+(index?" ":"")+upperFirst(word)});function startsWith(string,target,position){string=toString(string);position=position==null?0:baseClamp(toInteger(position),0,string.length);target=baseToString(target);return string.slice(position,position+target.length)==target}function template(string,options,guard){var settings=lodash.templateSettings;if(guard&&isIterateeCall(string,options,guard)){options=undefined}string=toString(string);options=assignInWith({},options,settings,customDefaultsAssignIn);var imports=assignInWith({},options.imports,settings.imports,customDefaultsAssignIn),importsKeys=keys(imports),importsValues=baseValues(imports,importsKeys);var isEscaping,isEvaluating,index=0,interpolate=options.interpolate||reNoMatch,source="__p += '";var reDelimiters=RegExp((options.escape||reNoMatch).source+"|"+interpolate.source+"|"+(interpolate===reInterpolate?reEsTemplate:reNoMatch).source+"|"+(options.evaluate||reNoMatch).source+"|$","g");var sourceURL="//# sourceURL="+(hasOwnProperty.call(options,"sourceURL")?(options.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++templateCounter+"]")+"\n";string.replace(reDelimiters,function(match,escapeValue,interpolateValue,esTemplateValue,evaluateValue,offset){interpolateValue||(interpolateValue=esTemplateValue);source+=string.slice(index,offset).replace(reUnescapedString,escapeStringChar);if(escapeValue){isEscaping=true;source+="' +\n__e("+escapeValue+") +\n'"}if(evaluateValue){isEvaluating=true;source+="';\n"+evaluateValue+";\n__p += '"}if(interpolateValue){source+="' +\n((__t = ("+interpolateValue+")) == null ? '' : __t) +\n'"}index=offset+match.length;return match});source+="';\n";var variable=hasOwnProperty.call(options,"variable")&&options.variable;if(!variable){source="with (obj) {\n"+source+"\n}\n"}source=(isEvaluating?source.replace(reEmptyStringLeading,""):source).replace(reEmptyStringMiddle,"$1").replace(reEmptyStringTrailing,"$1;");source="function("+(variable||"obj")+") {\n"+(variable?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(isEscaping?", __e = _.escape":"")+(isEvaluating?", __j = Array.prototype.join;\n"+"function print() { __p += __j.call(arguments, '') }\n":";\n")+source+"return __p\n}";var result=attempt(function(){return Function(importsKeys,sourceURL+"return "+source).apply(undefined,importsValues)});result.source=source;if(isError(result)){throw result}return result}function toLower(value){return toString(value).toLowerCase()}function toUpper(value){return toString(value).toUpperCase()}function trim(string,chars,guard){string=toString(string);if(string&&(guard||chars===undefined)){return string.replace(reTrim,"")}if(!string||!(chars=baseToString(chars))){return string}var strSymbols=stringToArray(string),chrSymbols=stringToArray(chars),start=charsStartIndex(strSymbols,chrSymbols),end=charsEndIndex(strSymbols,chrSymbols)+1;return castSlice(strSymbols,start,end).join("")}function trimEnd(string,chars,guard){string=toString(string);if(string&&(guard||chars===undefined)){return string.replace(reTrimEnd,"")}if(!string||!(chars=baseToString(chars))){return string}var strSymbols=stringToArray(string),end=charsEndIndex(strSymbols,stringToArray(chars))+1;return castSlice(strSymbols,0,end).join("")}function trimStart(string,chars,guard){string=toString(string);if(string&&(guard||chars===undefined)){return string.replace(reTrimStart,"")}if(!string||!(chars=baseToString(chars))){return string}var strSymbols=stringToArray(string),start=charsStartIndex(strSymbols,stringToArray(chars));return castSlice(strSymbols,start).join("")}function truncate(string,options){var length=DEFAULT_TRUNC_LENGTH,omission=DEFAULT_TRUNC_OMISSION;if(isObject(options)){var separator="separator"in options?options.separator:separator;length="length"in options?toInteger(options.length):length;omission="omission"in options?baseToString(options.omission):omission}string=toString(string);var strLength=string.length;if(hasUnicode(string)){var strSymbols=stringToArray(string);strLength=strSymbols.length}if(length>=strLength){return string}var end=length-stringSize(omission);if(end<1){return omission}var result=strSymbols?castSlice(strSymbols,0,end).join(""):string.slice(0,end);if(separator===undefined){return result+omission}if(strSymbols){end+=result.length-end}if(isRegExp(separator)){if(string.slice(end).search(separator)){var match,substring=result;if(!separator.global){separator=RegExp(separator.source,toString(reFlags.exec(separator))+"g")}separator.lastIndex=0;while(match=separator.exec(substring)){var newEnd=match.index}result=result.slice(0,newEnd===undefined?end:newEnd)}}else if(string.indexOf(baseToString(separator),end)!=end){var index=result.lastIndexOf(separator);if(index>-1){result=result.slice(0,index)}}return result+omission}function unescape(string){string=toString(string);return string&&reHasEscapedHtml.test(string)?string.replace(reEscapedHtml,unescapeHtmlChar):string}var upperCase=createCompounder(function(result,word,index){return result+(index?" ":"")+word.toUpperCase()});var upperFirst=createCaseFirst("toUpperCase");function words(string,pattern,guard){string=toString(string);pattern=guard?undefined:pattern;if(pattern===undefined){return hasUnicodeWord(string)?unicodeWords(string):asciiWords(string)}return string.match(pattern)||[]}var attempt=baseRest(function(func,args){try{return apply(func,undefined,args)}catch(e){return isError(e)?e:new Error(e)}});var bindAll=flatRest(function(object,methodNames){arrayEach(methodNames,function(key){key=toKey(key);baseAssignValue(object,key,bind(object[key],object))});return object});function cond(pairs){var length=pairs==null?0:pairs.length,toIteratee=getIteratee();pairs=!length?[]:arrayMap(pairs,function(pair){if(typeof pair[1]!="function"){throw new TypeError(FUNC_ERROR_TEXT)}return[toIteratee(pair[0]),pair[1]]});return baseRest(function(args){var index=-1;while(++indexMAX_SAFE_INTEGER){return[]}var index=MAX_ARRAY_LENGTH,length=nativeMin(n,MAX_ARRAY_LENGTH);iteratee=getIteratee(iteratee);n-=MAX_ARRAY_LENGTH;var result=baseTimes(length,iteratee);while(++index0||end<0)){return new LazyWrapper(result)}if(start<0){result=result.takeRight(-start)}else if(start){result=result.drop(start)}if(end!==undefined){end=toInteger(end);result=end<0?result.dropRight(-end):result.take(end-start)}return result};LazyWrapper.prototype.takeRightWhile=function(predicate){return this.reverse().takeWhile(predicate).reverse()};LazyWrapper.prototype.toArray=function(){return this.take(MAX_ARRAY_LENGTH)};baseForOwn(LazyWrapper.prototype,function(func,methodName){var checkIteratee=/^(?:filter|find|map|reject)|While$/.test(methodName),isTaker=/^(?:head|last)$/.test(methodName),lodashFunc=lodash[isTaker?"take"+(methodName=="last"?"Right":""):methodName],retUnwrapped=isTaker||/^find/.test(methodName);if(!lodashFunc){return}lodash.prototype[methodName]=function(){var value=this.__wrapped__,args=isTaker?[1]:arguments,isLazy=value instanceof LazyWrapper,iteratee=args[0],useLazy=isLazy||isArray(value);var interceptor=function(value){var result=lodashFunc.apply(lodash,arrayPush([value],args));return isTaker&&chainAll?result[0]:result};if(useLazy&&checkIteratee&&typeof iteratee=="function"&&iteratee.length!=1){isLazy=useLazy=false}var chainAll=this.__chain__,isHybrid=!!this.__actions__.length,isUnwrapped=retUnwrapped&&!chainAll,onlyLazy=isLazy&&!isHybrid;if(!retUnwrapped&&useLazy){value=onlyLazy?value:new LazyWrapper(this);var result=func.apply(value,args);result.__actions__.push({func:thru,args:[interceptor],thisArg:undefined});return new LodashWrapper(result,chainAll)}if(isUnwrapped&&onlyLazy){return func.apply(this,args)}result=this.thru(interceptor);return isUnwrapped?isTaker?result.value()[0]:result.value():result}});arrayEach(["pop","push","shift","sort","splice","unshift"],function(methodName){var func=arrayProto[methodName],chainName=/^(?:push|sort|unshift)$/.test(methodName)?"tap":"thru",retUnwrapped=/^(?:pop|shift)$/.test(methodName);lodash.prototype[methodName]=function(){var args=arguments;if(retUnwrapped&&!this.__chain__){var value=this.value();return func.apply(isArray(value)?value:[],args)}return this[chainName](function(value){return func.apply(isArray(value)?value:[],args)})}});baseForOwn(LazyWrapper.prototype,function(func,methodName){var lodashFunc=lodash[methodName];if(lodashFunc){var key=lodashFunc.name+"";if(!hasOwnProperty.call(realNames,key)){realNames[key]=[]}realNames[key].push({name:methodName,func:lodashFunc})}});realNames[createHybrid(undefined,WRAP_BIND_KEY_FLAG).name]=[{name:"wrapper",func:undefined}];LazyWrapper.prototype.clone=lazyClone;LazyWrapper.prototype.reverse=lazyReverse;LazyWrapper.prototype.value=lazyValue;lodash.prototype.at=wrapperAt;lodash.prototype.chain=wrapperChain;lodash.prototype.commit=wrapperCommit;lodash.prototype.next=wrapperNext;lodash.prototype.plant=wrapperPlant;lodash.prototype.reverse=wrapperReverse;lodash.prototype.toJSON=lodash.prototype.valueOf=lodash.prototype.value=wrapperValue;lodash.prototype.first=lodash.prototype.head;if(symIterator){lodash.prototype[symIterator]=wrapperToIterator}return lodash};var _=runInContext();if(typeof define=="function"&&typeof define.amd=="object"&&define.amd){root._=_;define(function(){return _})}else if(freeModule){(freeModule.exports=_)._=_;freeExports._=_}else{root._=_}}).call(this)}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],85:[function(require,module,exports){module.exports=assert;function assert(val,msg){if(!val)throw new Error(msg||"Assertion failed")}assert.equal=function assertEqual(l,r,msg){if(l!=r)throw new Error(msg||"Assertion failed: "+l+" != "+r)}},{}],86:[function(require,module,exports){"use strict";var utils=exports;function toArray(msg,enc){if(Array.isArray(msg))return msg.slice();if(!msg)return[];var res=[];if(typeof msg!=="string"){for(var i=0;i>8;var lo=c&255;if(hi)res.push(hi,lo);else res.push(lo)}}return res}utils.toArray=toArray;function zero2(word){if(word.length===1)return"0"+word;else return word}utils.zero2=zero2;function toHex(msg){var res="";for(var i=0;i 0 and a power of 2");if(N>MAX_VALUE/128/r)throw Error("Parameter N is too large");if(r>MAX_VALUE/128/p)throw Error("Parameter r is too large");let XY=Buffer.alloc(256*r);let V=Buffer.alloc(128*r*N);let B32=new Int32Array(16);let x=new Int32Array(16);let _X=Buffer.alloc(64);let B=crypto.pbkdf2Sync(key,salt,1,p*128*r,"sha256");let tickCallback;if(progressCallback){let totalOps=p*N*2;let currentOp=0;tickCallback=function(){++currentOp;if(currentOp%1e3===0){progressCallback({current:currentOp,total:totalOps,percent:currentOp/totalOps*100})}}}return{XY:XY,V:V,B32:B32,x:x,_X:_X,B:B,tickCallback:tickCallback}}async function smix(B,Bi,r,N,V,XY,_X,B32,x,tickCallback,promiseInterval){promiseInterval=promiseInterval||DEFAULT_PROMISE_INTERVAL;let Xi=0;let Yi=128*r;let i;B.copy(XY,Xi,Bi,Bi+Yi);for(i=0;isetImmediate(resolve))}blockmix_salsa8(XY,Xi,Yi,r,_X,B32,x);if(tickCallback)tickCallback()}for(i=0;isetImmediate(resolve))}blockmix_salsa8(XY,Xi,Yi,r,_X,B32,x);if(tickCallback)tickCallback()}XY.copy(B,Bi,Xi,Xi+Yi)}function smixSync(B,Bi,r,N,V,XY,_X,B32,x,tickCallback){let Xi=0;let Yi=128*r;let i;B.copy(XY,Xi,Bi,Bi+Yi);for(i=0;i>>32-b}function salsa20_8(B,B32,x){let i;for(i=0;i<16;i++){B32[i]=(B[i*4+0]&255)<<0;B32[i]|=(B[i*4+1]&255)<<8;B32[i]|=(B[i*4+2]&255)<<16;B32[i]|=(B[i*4+3]&255)<<24}arraycopy(B32,0,x,0,16);for(i=8;i>0;i-=2){x[4]^=R(x[0]+x[12],7);x[8]^=R(x[4]+x[0],9);x[12]^=R(x[8]+x[4],13);x[0]^=R(x[12]+x[8],18);x[9]^=R(x[5]+x[1],7);x[13]^=R(x[9]+x[5],9);x[1]^=R(x[13]+x[9],13);x[5]^=R(x[1]+x[13],18);x[14]^=R(x[10]+x[6],7);x[2]^=R(x[14]+x[10],9);x[6]^=R(x[2]+x[14],13);x[10]^=R(x[6]+x[2],18);x[3]^=R(x[15]+x[11],7);x[7]^=R(x[3]+x[15],9);x[11]^=R(x[7]+x[3],13);x[15]^=R(x[11]+x[7],18);x[1]^=R(x[0]+x[3],7);x[2]^=R(x[1]+x[0],9);x[3]^=R(x[2]+x[1],13);x[0]^=R(x[3]+x[2],18);x[6]^=R(x[5]+x[4],7);x[7]^=R(x[6]+x[5],9);x[4]^=R(x[7]+x[6],13);x[5]^=R(x[4]+x[7],18);x[11]^=R(x[10]+x[9],7);x[8]^=R(x[11]+x[10],9);x[9]^=R(x[8]+x[11],13);x[10]^=R(x[9]+x[8],18);x[12]^=R(x[15]+x[14],7);x[13]^=R(x[12]+x[15],9);x[14]^=R(x[13]+x[12],13);x[15]^=R(x[14]+x[13],18)}for(i=0;i<16;++i)B32[i]=x[i]+B32[i];for(i=0;i<16;i++){let bi=i*4;B[bi+0]=B32[i]>>0&255;B[bi+1]=B32[i]>>8&255;B[bi+2]=B32[i]>>16&255;B[bi+3]=B32[i]>>24&255}}function blockxor(S,Si,D,Di,len){for(let i=0;i",main:"index.js",scripts:{test:"gulp --tasks && gulp test","test:ci":"npm run test",coverage:"gulp coverage",build:"gulp",pub:"npm run build && npm publish"},keywords:["dogecoin","bitcoin","transaction","address","p2p","ecies","cryptocurrency","blockchain","payment","bip21","bip32","bip37","bip69","bip70","multisig"],repository:{type:"git",url:"https://github.com/bitpay/bitcore/tree/master/packages/bitcore-lib-doge"},browser:{request:"browser-request"},dependencies:{"bn.js":"=4.11.8",bs58:"^4.0.1","buffer-compare":"=1.1.1",elliptic:"^6.5.3",inherits:"=2.0.1",lodash:"^4.17.20",scryptsy:"2.1.0"},devDependencies:{"bitcore-build":"^8.25.10",brfs:"^2.0.1",chai:"^4.2.0",gulp:"^4.0.0",sinon:"^7.1.1"},license:"MIT"}},{}],93:[function(require,module,exports){"use strict";const asn1=exports;asn1.bignum=require("bn.js");asn1.define=require("./asn1/api").define;asn1.base=require("./asn1/base");asn1.constants=require("./asn1/constants");asn1.decoders=require("./asn1/decoders");asn1.encoders=require("./asn1/encoders")},{"./asn1/api":94,"./asn1/base":96,"./asn1/constants":100,"./asn1/decoders":102,"./asn1/encoders":105,"bn.js":107}],94:[function(require,module,exports){"use strict";const encoders=require("./encoders");const decoders=require("./decoders");const inherits=require("inherits");const api=exports;api.define=function define(name,body){return new Entity(name,body)};function Entity(name,body){this.name=name;this.body=body;this.decoders={};this.encoders={}}Entity.prototype._createNamed=function createNamed(Base){const name=this.name;function Generated(entity){this._initNamed(entity,name)}inherits(Generated,Base);Generated.prototype._initNamed=function _initNamed(entity,name){Base.call(this,entity,name)};return new Generated(this)};Entity.prototype._getDecoder=function _getDecoder(enc){enc=enc||"der";if(!this.decoders.hasOwnProperty(enc))this.decoders[enc]=this._createNamed(decoders[enc]);return this.decoders[enc]};Entity.prototype.decode=function decode(data,enc,options){return this._getDecoder(enc).decode(data,options)};Entity.prototype._getEncoder=function _getEncoder(enc){enc=enc||"der";if(!this.encoders.hasOwnProperty(enc))this.encoders[enc]=this._createNamed(encoders[enc]);return this.encoders[enc]};Entity.prototype.encode=function encode(data,enc,reporter){return this._getEncoder(enc).encode(data,reporter)}},{"./decoders":102,"./encoders":105,inherits:228}],95:[function(require,module,exports){"use strict";const inherits=require("inherits");const Reporter=require("../base/reporter").Reporter;const Buffer=require("safer-buffer").Buffer;function DecoderBuffer(base,options){Reporter.call(this,options);if(!Buffer.isBuffer(base)){this.error("Input not Buffer");return}this.base=base;this.offset=0;this.length=base.length}inherits(DecoderBuffer,Reporter);exports.DecoderBuffer=DecoderBuffer;DecoderBuffer.isDecoderBuffer=function isDecoderBuffer(data){if(data instanceof DecoderBuffer){return true}const isCompatible=typeof data==="object"&&Buffer.isBuffer(data.base)&&data.constructor.name==="DecoderBuffer"&&typeof data.offset==="number"&&typeof data.length==="number"&&typeof data.save==="function"&&typeof data.restore==="function"&&typeof data.isEmpty==="function"&&typeof data.readUInt8==="function"&&typeof data.skip==="function"&&typeof data.raw==="function";return isCompatible};DecoderBuffer.prototype.save=function save(){return{offset:this.offset,reporter:Reporter.prototype.save.call(this)}};DecoderBuffer.prototype.restore=function restore(save){const res=new DecoderBuffer(this.base);res.offset=save.offset;res.length=this.offset;this.offset=save.offset;Reporter.prototype.restore.call(this,save.reporter);return res};DecoderBuffer.prototype.isEmpty=function isEmpty(){return this.offset===this.length};DecoderBuffer.prototype.readUInt8=function readUInt8(fail){if(this.offset+1<=this.length)return this.base.readUInt8(this.offset++,true);else return this.error(fail||"DecoderBuffer overrun")};DecoderBuffer.prototype.skip=function skip(bytes,fail){if(!(this.offset+bytes<=this.length))return this.error(fail||"DecoderBuffer overrun");const res=new DecoderBuffer(this.base);res._reporterState=this._reporterState;res.offset=this.offset;res.length=this.offset+bytes;this.offset+=bytes;return res};DecoderBuffer.prototype.raw=function raw(save){return this.base.slice(save?save.offset:this.offset,this.length)};function EncoderBuffer(value,reporter){if(Array.isArray(value)){this.length=0;this.value=value.map(function(item){if(!EncoderBuffer.isEncoderBuffer(item))item=new EncoderBuffer(item,reporter);this.length+=item.length;return item},this)}else if(typeof value==="number"){if(!(0<=value&&value<=255))return reporter.error("non-byte EncoderBuffer value");this.value=value;this.length=1}else if(typeof value==="string"){this.value=value;this.length=Buffer.byteLength(value)}else if(Buffer.isBuffer(value)){this.value=value;this.length=value.length}else{return reporter.error("Unsupported type: "+typeof value)}}exports.EncoderBuffer=EncoderBuffer;EncoderBuffer.isEncoderBuffer=function isEncoderBuffer(data){if(data instanceof EncoderBuffer){return true}const isCompatible=typeof data==="object"&&data.constructor.name==="EncoderBuffer"&&typeof data.length==="number"&&typeof data.join==="function";return isCompatible};EncoderBuffer.prototype.join=function join(out,offset){if(!out)out=Buffer.alloc(this.length);if(!offset)offset=0;if(this.length===0)return out;if(Array.isArray(this.value)){this.value.forEach(function(item){item.join(out,offset);offset+=item.length})}else{if(typeof this.value==="number")out[offset]=this.value;else if(typeof this.value==="string")out.write(this.value,offset);else if(Buffer.isBuffer(this.value))this.value.copy(out,offset);offset+=this.length}return out}},{"../base/reporter":98,inherits:228,"safer-buffer":262}],96:[function(require,module,exports){"use strict";const base=exports;base.Reporter=require("./reporter").Reporter;base.DecoderBuffer=require("./buffer").DecoderBuffer;base.EncoderBuffer=require("./buffer").EncoderBuffer;base.Node=require("./node")},{"./buffer":95,"./node":97,"./reporter":98}],97:[function(require,module,exports){"use strict";const Reporter=require("../base/reporter").Reporter;const EncoderBuffer=require("../base/buffer").EncoderBuffer;const DecoderBuffer=require("../base/buffer").DecoderBuffer;const assert=require("minimalistic-assert");const tags=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"];const methods=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(tags);const overrided=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];function Node(enc,parent,name){const state={};this._baseState=state;state.name=name;state.enc=enc;state.parent=parent||null;state.children=null;state.tag=null;state.args=null;state.reverseArgs=null;state.choice=null;state.optional=false;state.any=false;state.obj=false;state.use=null;state.useDecoder=null;state.key=null;state["default"]=null;state.explicit=null;state.implicit=null;state.contains=null;if(!state.parent){state.children=[];this._wrap()}}module.exports=Node;const stateProps=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];Node.prototype.clone=function clone(){const state=this._baseState;const cstate={};stateProps.forEach(function(prop){cstate[prop]=state[prop]});const res=new this.constructor(cstate.parent);res._baseState=cstate;return res};Node.prototype._wrap=function wrap(){const state=this._baseState;methods.forEach(function(method){this[method]=function _wrappedMethod(){const clone=new this.constructor(this);state.children.push(clone);return clone[method].apply(clone,arguments)}},this)};Node.prototype._init=function init(body){const state=this._baseState;assert(state.parent===null);body.call(this);state.children=state.children.filter(function(child){return child._baseState.parent===this},this);assert.equal(state.children.length,1,"Root node can have only one child")};Node.prototype._useArgs=function useArgs(args){const state=this._baseState;const children=args.filter(function(arg){return arg instanceof this.constructor},this);args=args.filter(function(arg){return!(arg instanceof this.constructor)},this);if(children.length!==0){assert(state.children===null);state.children=children;children.forEach(function(child){child._baseState.parent=this},this)}if(args.length!==0){assert(state.args===null);state.args=args;state.reverseArgs=args.map(function(arg){if(typeof arg!=="object"||arg.constructor!==Object)return arg;const res={};Object.keys(arg).forEach(function(key){if(key==(key|0))key|=0;const value=arg[key];res[value]=key});return res})}};overrided.forEach(function(method){Node.prototype[method]=function _overrided(){const state=this._baseState;throw new Error(method+" not implemented for encoding: "+state.enc)}});tags.forEach(function(tag){Node.prototype[tag]=function _tagMethod(){const state=this._baseState;const args=Array.prototype.slice.call(arguments);assert(state.tag===null);state.tag=tag;this._useArgs(args);return this}});Node.prototype.use=function use(item){assert(item);const state=this._baseState;assert(state.use===null);state.use=item;return this};Node.prototype.optional=function optional(){const state=this._baseState;state.optional=true;return this};Node.prototype.def=function def(val){const state=this._baseState;assert(state["default"]===null);state["default"]=val;state.optional=true;return this};Node.prototype.explicit=function explicit(num){const state=this._baseState;assert(state.explicit===null&&state.implicit===null);state.explicit=num;return this};Node.prototype.implicit=function implicit(num){const state=this._baseState;assert(state.explicit===null&&state.implicit===null);state.implicit=num;return this};Node.prototype.obj=function obj(){const state=this._baseState;const args=Array.prototype.slice.call(arguments);state.obj=true;if(args.length!==0)this._useArgs(args);return this};Node.prototype.key=function key(newKey){const state=this._baseState;assert(state.key===null);state.key=newKey;return this};Node.prototype.any=function any(){const state=this._baseState;state.any=true;return this};Node.prototype.choice=function choice(obj){const state=this._baseState;assert(state.choice===null);state.choice=obj;this._useArgs(Object.keys(obj).map(function(key){return obj[key]}));return this};Node.prototype.contains=function contains(item){const state=this._baseState;assert(state.use===null);state.contains=item;return this};Node.prototype._decode=function decode(input,options){const state=this._baseState;if(state.parent===null)return input.wrapResult(state.children[0]._decode(input,options));let result=state["default"];let present=true;let prevKey=null;if(state.key!==null)prevKey=input.enterKey(state.key);if(state.optional){let tag=null;if(state.explicit!==null)tag=state.explicit;else if(state.implicit!==null)tag=state.implicit;else if(state.tag!==null)tag=state.tag;if(tag===null&&!state.any){const save=input.save();try{if(state.choice===null)this._decodeGeneric(state.tag,input,options);else this._decodeChoice(input,options);present=true}catch(e){present=false}input.restore(save)}else{present=this._peekTag(input,tag,state.any);if(input.isError(present))return present}}let prevObj;if(state.obj&&present)prevObj=input.enterObject();if(present){if(state.explicit!==null){const explicit=this._decodeTag(input,state.explicit);if(input.isError(explicit))return explicit;input=explicit}const start=input.offset;if(state.use===null&&state.choice===null){let save;if(state.any)save=input.save();const body=this._decodeTag(input,state.implicit!==null?state.implicit:state.tag,state.any);if(input.isError(body))return body;if(state.any)result=input.raw(save);else input=body}if(options&&options.track&&state.tag!==null)options.track(input.path(),start,input.length,"tagged");if(options&&options.track&&state.tag!==null)options.track(input.path(),input.offset,input.length,"content");if(state.any){}else if(state.choice===null){result=this._decodeGeneric(state.tag,input,options)}else{result=this._decodeChoice(input,options)}if(input.isError(result))return result;if(!state.any&&state.choice===null&&state.children!==null){state.children.forEach(function decodeChildren(child){child._decode(input,options)})}if(state.contains&&(state.tag==="octstr"||state.tag==="bitstr")){const data=new DecoderBuffer(result);result=this._getUse(state.contains,input._reporterState.obj)._decode(data,options)}}if(state.obj&&present)result=input.leaveObject(prevObj);if(state.key!==null&&(result!==null||present===true))input.leaveKey(prevKey,state.key,result);else if(prevKey!==null)input.exitKey(prevKey);return result};Node.prototype._decodeGeneric=function decodeGeneric(tag,input,options){const state=this._baseState;if(tag==="seq"||tag==="set")return null;if(tag==="seqof"||tag==="setof")return this._decodeList(input,tag,state.args[0],options);else if(/str$/.test(tag))return this._decodeStr(input,tag,options);else if(tag==="objid"&&state.args)return this._decodeObjid(input,state.args[0],state.args[1],options);else if(tag==="objid")return this._decodeObjid(input,null,null,options);else if(tag==="gentime"||tag==="utctime")return this._decodeTime(input,tag,options);else if(tag==="null_")return this._decodeNull(input,options);else if(tag==="bool")return this._decodeBool(input,options);else if(tag==="objDesc")return this._decodeStr(input,tag,options);else if(tag==="int"||tag==="enum")return this._decodeInt(input,state.args&&state.args[0],options);if(state.use!==null){return this._getUse(state.use,input._reporterState.obj)._decode(input,options)}else{return input.error("unknown tag: "+tag)}};Node.prototype._getUse=function _getUse(entity,obj){const state=this._baseState;state.useDecoder=this._use(entity,obj);assert(state.useDecoder._baseState.parent===null);state.useDecoder=state.useDecoder._baseState.children[0];if(state.implicit!==state.useDecoder._baseState.implicit){state.useDecoder=state.useDecoder.clone();state.useDecoder._baseState.implicit=state.implicit}return state.useDecoder};Node.prototype._decodeChoice=function decodeChoice(input,options){const state=this._baseState;let result=null;let match=false;Object.keys(state.choice).some(function(key){const save=input.save();const node=state.choice[key];try{const value=node._decode(input,options);if(input.isError(value))return false;result={type:key,value:value};match=true}catch(e){input.restore(save);return false}return true},this);if(!match)return input.error("Choice not matched");return result};Node.prototype._createEncoderBuffer=function createEncoderBuffer(data){return new EncoderBuffer(data,this.reporter)};Node.prototype._encode=function encode(data,reporter,parent){const state=this._baseState;if(state["default"]!==null&&state["default"]===data)return;const result=this._encodeValue(data,reporter,parent);if(result===undefined)return;if(this._skipDefault(result,reporter,parent))return;return result};Node.prototype._encodeValue=function encode(data,reporter,parent){const state=this._baseState;if(state.parent===null)return state.children[0]._encode(data,reporter||new Reporter);let result=null;this.reporter=reporter;if(state.optional&&data===undefined){if(state["default"]!==null)data=state["default"];else return}let content=null;let primitive=false;if(state.any){result=this._createEncoderBuffer(data)}else if(state.choice){result=this._encodeChoice(data,reporter)}else if(state.contains){content=this._getUse(state.contains,parent)._encode(data,reporter);primitive=true}else if(state.children){content=state.children.map(function(child){if(child._baseState.tag==="null_")return child._encode(null,reporter,data);if(child._baseState.key===null)return reporter.error("Child should have a key");const prevKey=reporter.enterKey(child._baseState.key);if(typeof data!=="object")return reporter.error("Child expected, but input is not object");const res=child._encode(data[child._baseState.key],reporter,data);reporter.leaveKey(prevKey);return res},this).filter(function(child){return child});content=this._createEncoderBuffer(content)}else{if(state.tag==="seqof"||state.tag==="setof"){if(!(state.args&&state.args.length===1))return reporter.error("Too many args for : "+state.tag);if(!Array.isArray(data))return reporter.error("seqof/setof, but data is not Array");const child=this.clone();child._baseState.implicit=null;content=this._createEncoderBuffer(data.map(function(item){const state=this._baseState;return this._getUse(state.args[0],data)._encode(item,reporter)},child))}else if(state.use!==null){result=this._getUse(state.use,parent)._encode(data,reporter)}else{content=this._encodePrimitive(state.tag,data);primitive=true}}if(!state.any&&state.choice===null){const tag=state.implicit!==null?state.implicit:state.tag;const cls=state.implicit===null?"universal":"context";if(tag===null){if(state.use===null)reporter.error("Tag could be omitted only for .use()")}else{if(state.use===null)result=this._encodeComposite(tag,primitive,cls,content)}}if(state.explicit!==null)result=this._encodeComposite(state.explicit,false,"context",result);return result};Node.prototype._encodeChoice=function encodeChoice(data,reporter){const state=this._baseState;const node=state.choice[data.type];if(!node){assert(false,data.type+" not found in "+JSON.stringify(Object.keys(state.choice)))}return node._encode(data.value,reporter)};Node.prototype._encodePrimitive=function encodePrimitive(tag,data){const state=this._baseState;if(/str$/.test(tag))return this._encodeStr(data,tag);else if(tag==="objid"&&state.args)return this._encodeObjid(data,state.reverseArgs[0],state.args[1]);else if(tag==="objid")return this._encodeObjid(data,null,null);else if(tag==="gentime"||tag==="utctime")return this._encodeTime(data,tag);else if(tag==="null_")return this._encodeNull();else if(tag==="int"||tag==="enum")return this._encodeInt(data,state.args&&state.reverseArgs[0]);else if(tag==="bool")return this._encodeBool(data);else if(tag==="objDesc")return this._encodeStr(data,tag);else throw new Error("Unsupported tag: "+tag)};Node.prototype._isNumstr=function isNumstr(str){return/^[0-9 ]*$/.test(str)};Node.prototype._isPrintstr=function isPrintstr(str){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(str)}},{"../base/buffer":95,"../base/reporter":98,"minimalistic-assert":232}],98:[function(require,module,exports){"use strict";const inherits=require("inherits");function Reporter(options){this._reporterState={obj:null,path:[],options:options||{},errors:[]}}exports.Reporter=Reporter;Reporter.prototype.isError=function isError(obj){return obj instanceof ReporterError};Reporter.prototype.save=function save(){const state=this._reporterState;return{obj:state.obj,pathLen:state.path.length}};Reporter.prototype.restore=function restore(data){const state=this._reporterState;state.obj=data.obj;state.path=state.path.slice(0,data.pathLen)};Reporter.prototype.enterKey=function enterKey(key){return this._reporterState.path.push(key)};Reporter.prototype.exitKey=function exitKey(index){const state=this._reporterState;state.path=state.path.slice(0,index-1)};Reporter.prototype.leaveKey=function leaveKey(index,key,value){const state=this._reporterState;this.exitKey(index);if(state.obj!==null)state.obj[key]=value};Reporter.prototype.path=function path(){return this._reporterState.path.join("/")};Reporter.prototype.enterObject=function enterObject(){const state=this._reporterState;const prev=state.obj;state.obj={};return prev};Reporter.prototype.leaveObject=function leaveObject(prev){const state=this._reporterState;const now=state.obj;state.obj=prev;return now};Reporter.prototype.error=function error(msg){let err;const state=this._reporterState;const inherited=msg instanceof ReporterError;if(inherited){err=msg}else{err=new ReporterError(state.path.map(function(elem){return"["+JSON.stringify(elem)+"]"}).join(""),msg.message||msg,msg.stack)}if(!state.options.partial)throw err;if(!inherited)state.errors.push(err);return err};Reporter.prototype.wrapResult=function wrapResult(result){const state=this._reporterState;if(!state.options.partial)return result;return{result:this.isError(result)?null:result,errors:state.errors}};function ReporterError(path,msg){this.path=path;this.rethrow(msg)}inherits(ReporterError,Error);ReporterError.prototype.rethrow=function rethrow(msg){this.message=msg+" at: "+(this.path||"(shallow)");if(Error.captureStackTrace)Error.captureStackTrace(this,ReporterError);if(!this.stack){try{throw new Error(this.message)}catch(e){this.stack=e.stack}}return this}},{inherits:228}],99:[function(require,module,exports){"use strict";function reverse(map){const res={};Object.keys(map).forEach(function(key){if((key|0)==key)key=key|0;const value=map[key];res[value]=key});return res}exports.tagClass={0:"universal",1:"application",2:"context",3:"private"};exports.tagClassByName=reverse(exports.tagClass);exports.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"};exports.tagByName=reverse(exports.tag)},{}],100:[function(require,module,exports){"use strict";const constants=exports;constants._reverse=function reverse(map){const res={};Object.keys(map).forEach(function(key){if((key|0)==key)key=key|0;const value=map[key];res[value]=key});return res};constants.der=require("./der")},{"./der":99}],101:[function(require,module,exports){"use strict";const inherits=require("inherits");const bignum=require("bn.js");const DecoderBuffer=require("../base/buffer").DecoderBuffer;const Node=require("../base/node");const der=require("../constants/der");function DERDecoder(entity){this.enc="der";this.name=entity.name;this.entity=entity;this.tree=new DERNode;this.tree._init(entity.body)}module.exports=DERDecoder;DERDecoder.prototype.decode=function decode(data,options){if(!DecoderBuffer.isDecoderBuffer(data)){data=new DecoderBuffer(data,options)}return this.tree._decode(data,options)};function DERNode(parent){Node.call(this,"der",parent)}inherits(DERNode,Node);DERNode.prototype._peekTag=function peekTag(buffer,tag,any){if(buffer.isEmpty())return false;const state=buffer.save();const decodedTag=derDecodeTag(buffer,'Failed to peek tag: "'+tag+'"');if(buffer.isError(decodedTag))return decodedTag;buffer.restore(state);return decodedTag.tag===tag||decodedTag.tagStr===tag||decodedTag.tagStr+"of"===tag||any};DERNode.prototype._decodeTag=function decodeTag(buffer,tag,any){const decodedTag=derDecodeTag(buffer,'Failed to decode tag of "'+tag+'"');if(buffer.isError(decodedTag))return decodedTag;let len=derDecodeLen(buffer,decodedTag.primitive,'Failed to get length of "'+tag+'"');if(buffer.isError(len))return len;if(!any&&decodedTag.tag!==tag&&decodedTag.tagStr!==tag&&decodedTag.tagStr+"of"!==tag){return buffer.error('Failed to match tag: "'+tag+'"')}if(decodedTag.primitive||len!==null)return buffer.skip(len,'Failed to match body of: "'+tag+'"');const state=buffer.save();const res=this._skipUntilEnd(buffer,'Failed to skip indefinite length body: "'+this.tag+'"');if(buffer.isError(res))return res;len=buffer.offset-state.offset;buffer.restore(state);return buffer.skip(len,'Failed to match body of: "'+tag+'"')};DERNode.prototype._skipUntilEnd=function skipUntilEnd(buffer,fail){for(;;){const tag=derDecodeTag(buffer,fail);if(buffer.isError(tag))return tag;const len=derDecodeLen(buffer,tag.primitive,fail);if(buffer.isError(len))return len;let res;if(tag.primitive||len!==null)res=buffer.skip(len);else res=this._skipUntilEnd(buffer,fail);if(buffer.isError(res))return res;if(tag.tagStr==="end")break}};DERNode.prototype._decodeList=function decodeList(buffer,tag,decoder,options){const result=[];while(!buffer.isEmpty()){const possibleEnd=this._peekTag(buffer,"end");if(buffer.isError(possibleEnd))return possibleEnd;const res=decoder.decode(buffer,"der",options);if(buffer.isError(res)&&possibleEnd)break;result.push(res)}return result};DERNode.prototype._decodeStr=function decodeStr(buffer,tag){if(tag==="bitstr"){const unused=buffer.readUInt8();if(buffer.isError(unused))return unused;return{unused:unused,data:buffer.raw()}}else if(tag==="bmpstr"){const raw=buffer.raw();if(raw.length%2===1)return buffer.error("Decoding of string type: bmpstr length mismatch");let str="";for(let i=0;i>6];const primitive=(tag&32)===0;if((tag&31)===31){let oct=tag;tag=0;while((oct&128)===128){oct=buf.readUInt8(fail);if(buf.isError(oct))return oct;tag<<=7;tag|=oct&127}}else{tag&=31}const tagStr=der.tag[tag];return{cls:cls,primitive:primitive,tag:tag,tagStr:tagStr}}function derDecodeLen(buf,primitive,fail){let len=buf.readUInt8(fail);if(buf.isError(len))return len;if(!primitive&&len===128)return null;if((len&128)===0){return len}const num=len&127;if(num>4)return buf.error("length octect is too long");len=0;for(let i=0;i=256;i>>=8)lenOctets++;const header=Buffer.alloc(1+1+lenOctets);header[0]=encodedTag;header[1]=128|lenOctets;for(let i=1+lenOctets,j=content.length;j>0;i--,j>>=8)header[i]=j&255;return this._createEncoderBuffer([header,content])};DERNode.prototype._encodeStr=function encodeStr(str,tag){if(tag==="bitstr"){return this._createEncoderBuffer([str.unused|0,str.data])}else if(tag==="bmpstr"){const buf=Buffer.alloc(str.length*2);for(let i=0;i=40)return this.reporter.error("Second objid identifier OOB");id.splice(0,2,id[0]*40+id[1])}let size=0;for(let i=0;i=128;ident>>=7)size++}const objid=Buffer.alloc(size);let offset=objid.length-1;for(let i=id.length-1;i>=0;i--){let ident=id[i];objid[offset--]=ident&127;while((ident>>=7)>0)objid[offset--]=128|ident&127}return this._createEncoderBuffer(objid)};function two(num){if(num<10)return"0"+num;else return num}DERNode.prototype._encodeTime=function encodeTime(time,tag){let str;const date=new Date(time);if(tag==="gentime"){str=[two(date.getUTCFullYear()),two(date.getUTCMonth()+1),two(date.getUTCDate()),two(date.getUTCHours()),two(date.getUTCMinutes()),two(date.getUTCSeconds()),"Z"].join("")}else if(tag==="utctime"){str=[two(date.getUTCFullYear()%100),two(date.getUTCMonth()+1),two(date.getUTCDate()),two(date.getUTCHours()),two(date.getUTCMinutes()),two(date.getUTCSeconds()),"Z"].join("")}else{this.reporter.error("Encoding "+tag+" time is not supported yet")}return this._encodeStr(str,"octstr")};DERNode.prototype._encodeNull=function encodeNull(){return this._createEncoderBuffer("")};DERNode.prototype._encodeInt=function encodeInt(num,values){if(typeof num==="string"){if(!values)return this.reporter.error("String int or enum given, but no values map");if(!values.hasOwnProperty(num)){return this.reporter.error("Values map doesn't contain: "+JSON.stringify(num))}num=values[num]}if(typeof num!=="number"&&!Buffer.isBuffer(num)){const numArray=num.toArray();if(!num.sign&&numArray[0]&128){numArray.unshift(0)}num=Buffer.from(numArray)}if(Buffer.isBuffer(num)){let size=num.length;if(num.length===0)size++;const out=Buffer.alloc(size);num.copy(out);if(num.length===0)out[0]=0;return this._createEncoderBuffer(out)}if(num<128)return this._createEncoderBuffer(num);if(num<256)return this._createEncoderBuffer([0,num]);let size=1;for(let i=num;i>=256;i>>=8)size++;const out=new Array(size);for(let i=out.length-1;i>=0;i--){out[i]=num&255;num>>=8}if(out[0]&128){out.unshift(0)}return this._createEncoderBuffer(Buffer.from(out))};DERNode.prototype._encodeBool=function encodeBool(value){return this._createEncoderBuffer(value?255:0)};DERNode.prototype._use=function use(entity,obj){if(typeof entity==="function")entity=entity(obj);return entity._getEncoder("der").tree};DERNode.prototype._skipDefault=function skipDefault(dataBuffer,reporter,parent){const state=this._baseState;let i;if(state["default"]===null)return false;const data=dataBuffer.join();if(state.defaultBuffer===undefined)state.defaultBuffer=this._encodeValue(state["default"],reporter,parent).join();if(data.length!==state.defaultBuffer.length)return false;for(i=0;i=31)return reporter.error("Multi-octet tag encoding unsupported");if(!primitive)res|=32;res|=der.tagClassByName[cls||"universal"]<<6;return res}},{"../base/node":97,"../constants/der":99,inherits:228,"safer-buffer":262}],105:[function(require,module,exports){"use strict";const encoders=exports;encoders.der=require("./der");encoders.pem=require("./pem")},{"./der":104,"./pem":106}],106:[function(require,module,exports){"use strict";const inherits=require("inherits");const DEREncoder=require("./der");function PEMEncoder(entity){DEREncoder.call(this,entity);this.enc="pem"}inherits(PEMEncoder,DEREncoder);module.exports=PEMEncoder;PEMEncoder.prototype.encode=function encode(data,options){const buf=DEREncoder.prototype.encode.call(this,data);const p=buf.toString("base64");const out=["-----BEGIN "+options.label+"-----"];for(let i=0;i0)return left;return right};BN.min=function min(left,right){if(left.cmp(right)<0)return left;return right};BN.prototype._init=function init(number,base,endian){if(typeof number==="number"){return this._initNumber(number,base,endian)}if(typeof number==="object"){return this._initArray(number,base,endian)}if(base==="hex"){base=16}assert(base===(base|0)&&base>=2&&base<=36);number=number.toString().replace(/\s+/g,"");var start=0;if(number[0]==="-"){start++;this.negative=1}if(start=0;i-=3){w=number[i]|number[i-1]<<8|number[i-2]<<16;this.words[j]|=w<>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}else if(endian==="le"){for(i=0,j=0;i>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}return this.strip()};function parseHex4Bits(string,index){var c=string.charCodeAt(index);if(c>=65&&c<=70){return c-55}else if(c>=97&&c<=102){return c-87}else{return c-48&15}}function parseHexByte(string,lowerBound,index){var r=parseHex4Bits(string,index);if(index-1>=lowerBound){r|=parseHex4Bits(string,index-1)<<4}return r}BN.prototype._parseHex=function _parseHex(number,start,endian){this.length=Math.ceil((number.length-start)/6);this.words=new Array(this.length);for(var i=0;i=start;i-=2){w=parseHexByte(number,start,i)<=18){off-=18;j+=1;this.words[j]|=w>>>26}else{off+=8}}}else{var parseLength=number.length-start;for(i=parseLength%2===0?start+1:start;i=18){off-=18;j+=1;this.words[j]|=w>>>26}else{off+=8}}}this.strip()};function parseBase(str,start,end,mul){var r=0;var len=Math.min(str.length,end);for(var i=start;i=49){r+=c-49+10}else if(c>=17){r+=c-17+10}else{r+=c}}return r}BN.prototype._parseBase=function _parseBase(number,base,start){this.words=[0];this.length=1;for(var limbLen=0,limbPow=1;limbPow<=67108863;limbPow*=base){limbLen++}limbLen--;limbPow=limbPow/base|0;var total=number.length-start;var mod=total%limbLen;var end=Math.min(total,total-mod)+start;var word=0;for(var i=start;i1&&this.words[this.length-1]===0){this.length--}return this._normSign()};BN.prototype._normSign=function _normSign(){if(this.length===1&&this.words[0]===0){this.negative=0}return this};BN.prototype.inspect=function inspect(){return(this.red?""};var zeros=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"];var groupSizes=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5];var groupBases=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];BN.prototype.toString=function toString(base,padding){base=base||10;padding=padding|0||1;var out;if(base===16||base==="hex"){out="";var off=0;var carry=0;for(var i=0;i>>24-off&16777215;if(carry!==0||i!==this.length-1){out=zeros[6-word.length]+word+out}else{out=word+out}off+=2;if(off>=26){off-=26;i--}}if(carry!==0){out=carry.toString(16)+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}if(base===(base|0)&&base>=2&&base<=36){var groupSize=groupSizes[base];var groupBase=groupBases[base];out="";var c=this.clone();c.negative=0;while(!c.isZero()){var r=c.modn(groupBase).toString(base);c=c.idivn(groupBase);if(!c.isZero()){out=zeros[groupSize-r.length]+r+out}else{out=r+out}}if(this.isZero()){out="0"+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}assert(false,"Base should be between 2 and 36")};BN.prototype.toNumber=function toNumber(){var ret=this.words[0];if(this.length===2){ret+=this.words[1]*67108864}else if(this.length===3&&this.words[2]===1){ret+=4503599627370496+this.words[1]*67108864}else if(this.length>2){assert(false,"Number can only safely store up to 53 bits")}return this.negative!==0?-ret:ret};BN.prototype.toJSON=function toJSON(){return this.toString(16)};BN.prototype.toBuffer=function toBuffer(endian,length){assert(typeof Buffer!=="undefined");return this.toArrayLike(Buffer,endian,length)};BN.prototype.toArray=function toArray(endian,length){return this.toArrayLike(Array,endian,length)};BN.prototype.toArrayLike=function toArrayLike(ArrayType,endian,length){var byteLength=this.byteLength();var reqLength=length||Math.max(1,byteLength);assert(byteLength<=reqLength,"byte array longer than desired length");assert(reqLength>0,"Requested array length <= 0");this.strip();var littleEndian=endian==="le";var res=new ArrayType(reqLength);var b,i;var q=this.clone();if(!littleEndian){for(i=0;i=4096){r+=13;t>>>=13}if(t>=64){r+=7;t>>>=7}if(t>=8){r+=4;t>>>=4}if(t>=2){r+=2;t>>>=2}return r+t}}BN.prototype._zeroBits=function _zeroBits(w){if(w===0)return 26;var t=w;var r=0;if((t&8191)===0){r+=13;t>>>=13}if((t&127)===0){r+=7;t>>>=7}if((t&15)===0){r+=4;t>>>=4}if((t&3)===0){r+=2;t>>>=2}if((t&1)===0){r++}return r};BN.prototype.bitLength=function bitLength(){var w=this.words[this.length-1];var hi=this._countBits(w);return(this.length-1)*26+hi};function toBitArray(num){var w=new Array(num.bitLength());for(var bit=0;bit>>wbit}return w}BN.prototype.zeroBits=function zeroBits(){if(this.isZero())return 0;var r=0;for(var i=0;inum.length)return this.clone().ior(num);return num.clone().ior(this)};BN.prototype.uor=function uor(num){if(this.length>num.length)return this.clone().iuor(num);return num.clone().iuor(this)};BN.prototype.iuand=function iuand(num){var b;if(this.length>num.length){b=num}else{b=this}for(var i=0;inum.length)return this.clone().iand(num);return num.clone().iand(this)};BN.prototype.uand=function uand(num){if(this.length>num.length)return this.clone().iuand(num);return num.clone().iuand(this)};BN.prototype.iuxor=function iuxor(num){var a;var b;if(this.length>num.length){a=this;b=num}else{a=num;b=this}for(var i=0;inum.length)return this.clone().ixor(num);return num.clone().ixor(this)};BN.prototype.uxor=function uxor(num){if(this.length>num.length)return this.clone().iuxor(num);return num.clone().iuxor(this)};BN.prototype.inotn=function inotn(width){assert(typeof width==="number"&&width>=0);var bytesNeeded=Math.ceil(width/26)|0;var bitsLeft=width%26;this._expand(bytesNeeded);if(bitsLeft>0){bytesNeeded--}for(var i=0;i0){this.words[i]=~this.words[i]&67108863>>26-bitsLeft}return this.strip()};BN.prototype.notn=function notn(width){return this.clone().inotn(width)};BN.prototype.setn=function setn(bit,val){assert(typeof bit==="number"&&bit>=0);var off=bit/26|0;var wbit=bit%26;this._expand(off+1);if(val){this.words[off]=this.words[off]|1<num.length){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>>26}for(;carry!==0&&i>>26}this.length=a.length;if(carry!==0){this.words[this.length]=carry;this.length++}else if(a!==this){for(;inum.length)return this.clone().iadd(num);return num.clone().iadd(this)};BN.prototype.isub=function isub(num){if(num.negative!==0){num.negative=0;var r=this.iadd(num);num.negative=1;return r._normSign()}else if(this.negative!==0){this.negative=0;this.iadd(num);this.negative=1;return this._normSign()}var cmp=this.cmp(num);if(cmp===0){this.negative=0;this.length=1;this.words[0]=0;return this}var a,b;if(cmp>0){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>26;this.words[i]=r&67108863}for(;carry!==0&&i>26;this.words[i]=r&67108863}if(carry===0&&i>>26;var rword=carry&67108863;var maxJ=Math.min(k,num.length-1);for(var j=Math.max(0,k-self.length+1);j<=maxJ;j++){var i=k-j|0;a=self.words[i]|0;b=num.words[j]|0;r=a*b+rword;ncarry+=r/67108864|0;rword=r&67108863}out.words[k]=rword|0;carry=ncarry|0}if(carry!==0){out.words[k]=carry|0}else{out.length--}return out.strip()}var comb10MulTo=function comb10MulTo(self,num,out){var a=self.words;var b=num.words;var o=out.words;var c=0;var lo;var mid;var hi;var a0=a[0]|0;var al0=a0&8191;var ah0=a0>>>13;var a1=a[1]|0;var al1=a1&8191;var ah1=a1>>>13;var a2=a[2]|0;var al2=a2&8191;var ah2=a2>>>13;var a3=a[3]|0;var al3=a3&8191;var ah3=a3>>>13;var a4=a[4]|0;var al4=a4&8191;var ah4=a4>>>13;var a5=a[5]|0;var al5=a5&8191;var ah5=a5>>>13;var a6=a[6]|0;var al6=a6&8191;var ah6=a6>>>13;var a7=a[7]|0;var al7=a7&8191;var ah7=a7>>>13;var a8=a[8]|0;var al8=a8&8191;var ah8=a8>>>13;var a9=a[9]|0;var al9=a9&8191;var ah9=a9>>>13;var b0=b[0]|0;var bl0=b0&8191;var bh0=b0>>>13;var b1=b[1]|0;var bl1=b1&8191;var bh1=b1>>>13;var b2=b[2]|0;var bl2=b2&8191;var bh2=b2>>>13;var b3=b[3]|0;var bl3=b3&8191;var bh3=b3>>>13;var b4=b[4]|0;var bl4=b4&8191;var bh4=b4>>>13;var b5=b[5]|0;var bl5=b5&8191;var bh5=b5>>>13;var b6=b[6]|0;var bl6=b6&8191;var bh6=b6>>>13;var b7=b[7]|0;var bl7=b7&8191;var bh7=b7>>>13;var b8=b[8]|0;var bl8=b8&8191;var bh8=b8>>>13;var b9=b[9]|0;var bl9=b9&8191;var bh9=b9>>>13;out.negative=self.negative^num.negative;out.length=19;lo=Math.imul(al0,bl0);mid=Math.imul(al0,bh0);mid=mid+Math.imul(ah0,bl0)|0;hi=Math.imul(ah0,bh0);var w0=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w0>>>26)|0;w0&=67108863;lo=Math.imul(al1,bl0);mid=Math.imul(al1,bh0);mid=mid+Math.imul(ah1,bl0)|0;hi=Math.imul(ah1,bh0);lo=lo+Math.imul(al0,bl1)|0;mid=mid+Math.imul(al0,bh1)|0;mid=mid+Math.imul(ah0,bl1)|0;hi=hi+Math.imul(ah0,bh1)|0;var w1=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w1>>>26)|0;w1&=67108863;lo=Math.imul(al2,bl0);mid=Math.imul(al2,bh0);mid=mid+Math.imul(ah2,bl0)|0;hi=Math.imul(ah2,bh0);lo=lo+Math.imul(al1,bl1)|0;mid=mid+Math.imul(al1,bh1)|0;mid=mid+Math.imul(ah1,bl1)|0;hi=hi+Math.imul(ah1,bh1)|0;lo=lo+Math.imul(al0,bl2)|0;mid=mid+Math.imul(al0,bh2)|0;mid=mid+Math.imul(ah0,bl2)|0;hi=hi+Math.imul(ah0,bh2)|0;var w2=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w2>>>26)|0;w2&=67108863;lo=Math.imul(al3,bl0);mid=Math.imul(al3,bh0);mid=mid+Math.imul(ah3,bl0)|0;hi=Math.imul(ah3,bh0);lo=lo+Math.imul(al2,bl1)|0;mid=mid+Math.imul(al2,bh1)|0;mid=mid+Math.imul(ah2,bl1)|0;hi=hi+Math.imul(ah2,bh1)|0;lo=lo+Math.imul(al1,bl2)|0;mid=mid+Math.imul(al1,bh2)|0;mid=mid+Math.imul(ah1,bl2)|0;hi=hi+Math.imul(ah1,bh2)|0;lo=lo+Math.imul(al0,bl3)|0;mid=mid+Math.imul(al0,bh3)|0;mid=mid+Math.imul(ah0,bl3)|0;hi=hi+Math.imul(ah0,bh3)|0;var w3=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w3>>>26)|0;w3&=67108863;lo=Math.imul(al4,bl0);mid=Math.imul(al4,bh0);mid=mid+Math.imul(ah4,bl0)|0;hi=Math.imul(ah4,bh0);lo=lo+Math.imul(al3,bl1)|0;mid=mid+Math.imul(al3,bh1)|0;mid=mid+Math.imul(ah3,bl1)|0;hi=hi+Math.imul(ah3,bh1)|0;lo=lo+Math.imul(al2,bl2)|0;mid=mid+Math.imul(al2,bh2)|0;mid=mid+Math.imul(ah2,bl2)|0;hi=hi+Math.imul(ah2,bh2)|0;lo=lo+Math.imul(al1,bl3)|0;mid=mid+Math.imul(al1,bh3)|0;mid=mid+Math.imul(ah1,bl3)|0;hi=hi+Math.imul(ah1,bh3)|0;lo=lo+Math.imul(al0,bl4)|0;mid=mid+Math.imul(al0,bh4)|0;mid=mid+Math.imul(ah0,bl4)|0;hi=hi+Math.imul(ah0,bh4)|0;var w4=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w4>>>26)|0;w4&=67108863;lo=Math.imul(al5,bl0);mid=Math.imul(al5,bh0);mid=mid+Math.imul(ah5,bl0)|0;hi=Math.imul(ah5,bh0);lo=lo+Math.imul(al4,bl1)|0;mid=mid+Math.imul(al4,bh1)|0;mid=mid+Math.imul(ah4,bl1)|0;hi=hi+Math.imul(ah4,bh1)|0;lo=lo+Math.imul(al3,bl2)|0;mid=mid+Math.imul(al3,bh2)|0;mid=mid+Math.imul(ah3,bl2)|0;hi=hi+Math.imul(ah3,bh2)|0;lo=lo+Math.imul(al2,bl3)|0;mid=mid+Math.imul(al2,bh3)|0;mid=mid+Math.imul(ah2,bl3)|0;hi=hi+Math.imul(ah2,bh3)|0;lo=lo+Math.imul(al1,bl4)|0;mid=mid+Math.imul(al1,bh4)|0;mid=mid+Math.imul(ah1,bl4)|0;hi=hi+Math.imul(ah1,bh4)|0;lo=lo+Math.imul(al0,bl5)|0;mid=mid+Math.imul(al0,bh5)|0;mid=mid+Math.imul(ah0,bl5)|0;hi=hi+Math.imul(ah0,bh5)|0;var w5=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w5>>>26)|0;w5&=67108863;lo=Math.imul(al6,bl0);mid=Math.imul(al6,bh0);mid=mid+Math.imul(ah6,bl0)|0;hi=Math.imul(ah6,bh0);lo=lo+Math.imul(al5,bl1)|0;mid=mid+Math.imul(al5,bh1)|0;mid=mid+Math.imul(ah5,bl1)|0;hi=hi+Math.imul(ah5,bh1)|0;lo=lo+Math.imul(al4,bl2)|0;mid=mid+Math.imul(al4,bh2)|0;mid=mid+Math.imul(ah4,bl2)|0;hi=hi+Math.imul(ah4,bh2)|0;lo=lo+Math.imul(al3,bl3)|0;mid=mid+Math.imul(al3,bh3)|0;mid=mid+Math.imul(ah3,bl3)|0;hi=hi+Math.imul(ah3,bh3)|0;lo=lo+Math.imul(al2,bl4)|0;mid=mid+Math.imul(al2,bh4)|0;mid=mid+Math.imul(ah2,bl4)|0;hi=hi+Math.imul(ah2,bh4)|0;lo=lo+Math.imul(al1,bl5)|0;mid=mid+Math.imul(al1,bh5)|0;mid=mid+Math.imul(ah1,bl5)|0;hi=hi+Math.imul(ah1,bh5)|0;lo=lo+Math.imul(al0,bl6)|0;mid=mid+Math.imul(al0,bh6)|0;mid=mid+Math.imul(ah0,bl6)|0;hi=hi+Math.imul(ah0,bh6)|0;var w6=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w6>>>26)|0;w6&=67108863;lo=Math.imul(al7,bl0);mid=Math.imul(al7,bh0);mid=mid+Math.imul(ah7,bl0)|0;hi=Math.imul(ah7,bh0);lo=lo+Math.imul(al6,bl1)|0;mid=mid+Math.imul(al6,bh1)|0;mid=mid+Math.imul(ah6,bl1)|0;hi=hi+Math.imul(ah6,bh1)|0;lo=lo+Math.imul(al5,bl2)|0;mid=mid+Math.imul(al5,bh2)|0;mid=mid+Math.imul(ah5,bl2)|0;hi=hi+Math.imul(ah5,bh2)|0;lo=lo+Math.imul(al4,bl3)|0;mid=mid+Math.imul(al4,bh3)|0;mid=mid+Math.imul(ah4,bl3)|0;hi=hi+Math.imul(ah4,bh3)|0;lo=lo+Math.imul(al3,bl4)|0;mid=mid+Math.imul(al3,bh4)|0;mid=mid+Math.imul(ah3,bl4)|0;hi=hi+Math.imul(ah3,bh4)|0;lo=lo+Math.imul(al2,bl5)|0;mid=mid+Math.imul(al2,bh5)|0;mid=mid+Math.imul(ah2,bl5)|0;hi=hi+Math.imul(ah2,bh5)|0;lo=lo+Math.imul(al1,bl6)|0;mid=mid+Math.imul(al1,bh6)|0;mid=mid+Math.imul(ah1,bl6)|0;hi=hi+Math.imul(ah1,bh6)|0;lo=lo+Math.imul(al0,bl7)|0;mid=mid+Math.imul(al0,bh7)|0;mid=mid+Math.imul(ah0,bl7)|0;hi=hi+Math.imul(ah0,bh7)|0;var w7=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w7>>>26)|0;w7&=67108863;lo=Math.imul(al8,bl0);mid=Math.imul(al8,bh0);mid=mid+Math.imul(ah8,bl0)|0;hi=Math.imul(ah8,bh0);lo=lo+Math.imul(al7,bl1)|0;mid=mid+Math.imul(al7,bh1)|0;mid=mid+Math.imul(ah7,bl1)|0;hi=hi+Math.imul(ah7,bh1)|0;lo=lo+Math.imul(al6,bl2)|0;mid=mid+Math.imul(al6,bh2)|0;mid=mid+Math.imul(ah6,bl2)|0;hi=hi+Math.imul(ah6,bh2)|0;lo=lo+Math.imul(al5,bl3)|0;mid=mid+Math.imul(al5,bh3)|0;mid=mid+Math.imul(ah5,bl3)|0;hi=hi+Math.imul(ah5,bh3)|0;lo=lo+Math.imul(al4,bl4)|0;mid=mid+Math.imul(al4,bh4)|0;mid=mid+Math.imul(ah4,bl4)|0;hi=hi+Math.imul(ah4,bh4)|0;lo=lo+Math.imul(al3,bl5)|0;mid=mid+Math.imul(al3,bh5)|0;mid=mid+Math.imul(ah3,bl5)|0;hi=hi+Math.imul(ah3,bh5)|0;lo=lo+Math.imul(al2,bl6)|0;mid=mid+Math.imul(al2,bh6)|0;mid=mid+Math.imul(ah2,bl6)|0;hi=hi+Math.imul(ah2,bh6)|0;lo=lo+Math.imul(al1,bl7)|0;mid=mid+Math.imul(al1,bh7)|0;mid=mid+Math.imul(ah1,bl7)|0;hi=hi+Math.imul(ah1,bh7)|0;lo=lo+Math.imul(al0,bl8)|0;mid=mid+Math.imul(al0,bh8)|0;mid=mid+Math.imul(ah0,bl8)|0;hi=hi+Math.imul(ah0,bh8)|0;var w8=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w8>>>26)|0;w8&=67108863;lo=Math.imul(al9,bl0);mid=Math.imul(al9,bh0);mid=mid+Math.imul(ah9,bl0)|0;hi=Math.imul(ah9,bh0);lo=lo+Math.imul(al8,bl1)|0;mid=mid+Math.imul(al8,bh1)|0;mid=mid+Math.imul(ah8,bl1)|0;hi=hi+Math.imul(ah8,bh1)|0;lo=lo+Math.imul(al7,bl2)|0;mid=mid+Math.imul(al7,bh2)|0;mid=mid+Math.imul(ah7,bl2)|0;hi=hi+Math.imul(ah7,bh2)|0;lo=lo+Math.imul(al6,bl3)|0;mid=mid+Math.imul(al6,bh3)|0;mid=mid+Math.imul(ah6,bl3)|0;hi=hi+Math.imul(ah6,bh3)|0;lo=lo+Math.imul(al5,bl4)|0;mid=mid+Math.imul(al5,bh4)|0;mid=mid+Math.imul(ah5,bl4)|0;hi=hi+Math.imul(ah5,bh4)|0;lo=lo+Math.imul(al4,bl5)|0;mid=mid+Math.imul(al4,bh5)|0;mid=mid+Math.imul(ah4,bl5)|0;hi=hi+Math.imul(ah4,bh5)|0;lo=lo+Math.imul(al3,bl6)|0;mid=mid+Math.imul(al3,bh6)|0;mid=mid+Math.imul(ah3,bl6)|0;hi=hi+Math.imul(ah3,bh6)|0;lo=lo+Math.imul(al2,bl7)|0;mid=mid+Math.imul(al2,bh7)|0;mid=mid+Math.imul(ah2,bl7)|0;hi=hi+Math.imul(ah2,bh7)|0;lo=lo+Math.imul(al1,bl8)|0;mid=mid+Math.imul(al1,bh8)|0;mid=mid+Math.imul(ah1,bl8)|0;hi=hi+Math.imul(ah1,bh8)|0;lo=lo+Math.imul(al0,bl9)|0;mid=mid+Math.imul(al0,bh9)|0;mid=mid+Math.imul(ah0,bl9)|0;hi=hi+Math.imul(ah0,bh9)|0;var w9=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w9>>>26)|0;w9&=67108863;lo=Math.imul(al9,bl1);mid=Math.imul(al9,bh1);mid=mid+Math.imul(ah9,bl1)|0;hi=Math.imul(ah9,bh1);lo=lo+Math.imul(al8,bl2)|0;mid=mid+Math.imul(al8,bh2)|0;mid=mid+Math.imul(ah8,bl2)|0;hi=hi+Math.imul(ah8,bh2)|0;lo=lo+Math.imul(al7,bl3)|0;mid=mid+Math.imul(al7,bh3)|0;mid=mid+Math.imul(ah7,bl3)|0;hi=hi+Math.imul(ah7,bh3)|0;lo=lo+Math.imul(al6,bl4)|0;mid=mid+Math.imul(al6,bh4)|0;mid=mid+Math.imul(ah6,bl4)|0;hi=hi+Math.imul(ah6,bh4)|0;lo=lo+Math.imul(al5,bl5)|0;mid=mid+Math.imul(al5,bh5)|0;mid=mid+Math.imul(ah5,bl5)|0;hi=hi+Math.imul(ah5,bh5)|0;lo=lo+Math.imul(al4,bl6)|0;mid=mid+Math.imul(al4,bh6)|0;mid=mid+Math.imul(ah4,bl6)|0;hi=hi+Math.imul(ah4,bh6)|0;lo=lo+Math.imul(al3,bl7)|0;mid=mid+Math.imul(al3,bh7)|0;mid=mid+Math.imul(ah3,bl7)|0;hi=hi+Math.imul(ah3,bh7)|0;lo=lo+Math.imul(al2,bl8)|0;mid=mid+Math.imul(al2,bh8)|0;mid=mid+Math.imul(ah2,bl8)|0;hi=hi+Math.imul(ah2,bh8)|0;lo=lo+Math.imul(al1,bl9)|0;mid=mid+Math.imul(al1,bh9)|0;mid=mid+Math.imul(ah1,bl9)|0;hi=hi+Math.imul(ah1,bh9)|0;var w10=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w10>>>26)|0;w10&=67108863;lo=Math.imul(al9,bl2);mid=Math.imul(al9,bh2);mid=mid+Math.imul(ah9,bl2)|0;hi=Math.imul(ah9,bh2);lo=lo+Math.imul(al8,bl3)|0;mid=mid+Math.imul(al8,bh3)|0;mid=mid+Math.imul(ah8,bl3)|0;hi=hi+Math.imul(ah8,bh3)|0;lo=lo+Math.imul(al7,bl4)|0;mid=mid+Math.imul(al7,bh4)|0;mid=mid+Math.imul(ah7,bl4)|0;hi=hi+Math.imul(ah7,bh4)|0;lo=lo+Math.imul(al6,bl5)|0;mid=mid+Math.imul(al6,bh5)|0;mid=mid+Math.imul(ah6,bl5)|0;hi=hi+Math.imul(ah6,bh5)|0;lo=lo+Math.imul(al5,bl6)|0;mid=mid+Math.imul(al5,bh6)|0;mid=mid+Math.imul(ah5,bl6)|0;hi=hi+Math.imul(ah5,bh6)|0;lo=lo+Math.imul(al4,bl7)|0;mid=mid+Math.imul(al4,bh7)|0;mid=mid+Math.imul(ah4,bl7)|0;hi=hi+Math.imul(ah4,bh7)|0;lo=lo+Math.imul(al3,bl8)|0;mid=mid+Math.imul(al3,bh8)|0;mid=mid+Math.imul(ah3,bl8)|0;hi=hi+Math.imul(ah3,bh8)|0;lo=lo+Math.imul(al2,bl9)|0;mid=mid+Math.imul(al2,bh9)|0;mid=mid+Math.imul(ah2,bl9)|0;hi=hi+Math.imul(ah2,bh9)|0;var w11=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w11>>>26)|0;w11&=67108863;lo=Math.imul(al9,bl3);mid=Math.imul(al9,bh3);mid=mid+Math.imul(ah9,bl3)|0;hi=Math.imul(ah9,bh3);lo=lo+Math.imul(al8,bl4)|0;mid=mid+Math.imul(al8,bh4)|0;mid=mid+Math.imul(ah8,bl4)|0;hi=hi+Math.imul(ah8,bh4)|0;lo=lo+Math.imul(al7,bl5)|0;mid=mid+Math.imul(al7,bh5)|0;mid=mid+Math.imul(ah7,bl5)|0;hi=hi+Math.imul(ah7,bh5)|0;lo=lo+Math.imul(al6,bl6)|0;mid=mid+Math.imul(al6,bh6)|0;mid=mid+Math.imul(ah6,bl6)|0;hi=hi+Math.imul(ah6,bh6)|0;lo=lo+Math.imul(al5,bl7)|0;mid=mid+Math.imul(al5,bh7)|0;mid=mid+Math.imul(ah5,bl7)|0;hi=hi+Math.imul(ah5,bh7)|0;lo=lo+Math.imul(al4,bl8)|0;mid=mid+Math.imul(al4,bh8)|0;mid=mid+Math.imul(ah4,bl8)|0;hi=hi+Math.imul(ah4,bh8)|0;lo=lo+Math.imul(al3,bl9)|0;mid=mid+Math.imul(al3,bh9)|0;mid=mid+Math.imul(ah3,bl9)|0;hi=hi+Math.imul(ah3,bh9)|0;var w12=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w12>>>26)|0;w12&=67108863;lo=Math.imul(al9,bl4);mid=Math.imul(al9,bh4);mid=mid+Math.imul(ah9,bl4)|0;hi=Math.imul(ah9,bh4);lo=lo+Math.imul(al8,bl5)|0;mid=mid+Math.imul(al8,bh5)|0;mid=mid+Math.imul(ah8,bl5)|0;hi=hi+Math.imul(ah8,bh5)|0;lo=lo+Math.imul(al7,bl6)|0;mid=mid+Math.imul(al7,bh6)|0;mid=mid+Math.imul(ah7,bl6)|0;hi=hi+Math.imul(ah7,bh6)|0;lo=lo+Math.imul(al6,bl7)|0;mid=mid+Math.imul(al6,bh7)|0;mid=mid+Math.imul(ah6,bl7)|0;hi=hi+Math.imul(ah6,bh7)|0;lo=lo+Math.imul(al5,bl8)|0;mid=mid+Math.imul(al5,bh8)|0;mid=mid+Math.imul(ah5,bl8)|0;hi=hi+Math.imul(ah5,bh8)|0;lo=lo+Math.imul(al4,bl9)|0;mid=mid+Math.imul(al4,bh9)|0;mid=mid+Math.imul(ah4,bl9)|0;hi=hi+Math.imul(ah4,bh9)|0;var w13=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w13>>>26)|0;w13&=67108863;lo=Math.imul(al9,bl5);mid=Math.imul(al9,bh5);mid=mid+Math.imul(ah9,bl5)|0;hi=Math.imul(ah9,bh5);lo=lo+Math.imul(al8,bl6)|0;mid=mid+Math.imul(al8,bh6)|0;mid=mid+Math.imul(ah8,bl6)|0;hi=hi+Math.imul(ah8,bh6)|0;lo=lo+Math.imul(al7,bl7)|0;mid=mid+Math.imul(al7,bh7)|0;mid=mid+Math.imul(ah7,bl7)|0;hi=hi+Math.imul(ah7,bh7)|0;lo=lo+Math.imul(al6,bl8)|0;mid=mid+Math.imul(al6,bh8)|0;mid=mid+Math.imul(ah6,bl8)|0;hi=hi+Math.imul(ah6,bh8)|0;lo=lo+Math.imul(al5,bl9)|0;mid=mid+Math.imul(al5,bh9)|0;mid=mid+Math.imul(ah5,bl9)|0;hi=hi+Math.imul(ah5,bh9)|0;var w14=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w14>>>26)|0;w14&=67108863;lo=Math.imul(al9,bl6);mid=Math.imul(al9,bh6);mid=mid+Math.imul(ah9,bl6)|0;hi=Math.imul(ah9,bh6);lo=lo+Math.imul(al8,bl7)|0;mid=mid+Math.imul(al8,bh7)|0;mid=mid+Math.imul(ah8,bl7)|0;hi=hi+Math.imul(ah8,bh7)|0;lo=lo+Math.imul(al7,bl8)|0;mid=mid+Math.imul(al7,bh8)|0;mid=mid+Math.imul(ah7,bl8)|0;hi=hi+Math.imul(ah7,bh8)|0;lo=lo+Math.imul(al6,bl9)|0;mid=mid+Math.imul(al6,bh9)|0;mid=mid+Math.imul(ah6,bl9)|0;hi=hi+Math.imul(ah6,bh9)|0;var w15=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w15>>>26)|0;w15&=67108863;lo=Math.imul(al9,bl7);mid=Math.imul(al9,bh7);mid=mid+Math.imul(ah9,bl7)|0;hi=Math.imul(ah9,bh7);lo=lo+Math.imul(al8,bl8)|0;mid=mid+Math.imul(al8,bh8)|0;mid=mid+Math.imul(ah8,bl8)|0;hi=hi+Math.imul(ah8,bh8)|0;lo=lo+Math.imul(al7,bl9)|0;mid=mid+Math.imul(al7,bh9)|0;mid=mid+Math.imul(ah7,bl9)|0;hi=hi+Math.imul(ah7,bh9)|0;var w16=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w16>>>26)|0;w16&=67108863;lo=Math.imul(al9,bl8);mid=Math.imul(al9,bh8);mid=mid+Math.imul(ah9,bl8)|0;hi=Math.imul(ah9,bh8);lo=lo+Math.imul(al8,bl9)|0;mid=mid+Math.imul(al8,bh9)|0;mid=mid+Math.imul(ah8,bl9)|0;hi=hi+Math.imul(ah8,bh9)|0;var w17=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w17>>>26)|0;w17&=67108863;lo=Math.imul(al9,bl9);mid=Math.imul(al9,bh9);mid=mid+Math.imul(ah9,bl9)|0;hi=Math.imul(ah9,bh9);var w18=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w18>>>26)|0;w18&=67108863;o[0]=w0;o[1]=w1;o[2]=w2;o[3]=w3;o[4]=w4;o[5]=w5;o[6]=w6;o[7]=w7;o[8]=w8;o[9]=w9;o[10]=w10;o[11]=w11;o[12]=w12;o[13]=w13;o[14]=w14;o[15]=w15;o[16]=w16;o[17]=w17;o[18]=w18;if(c!==0){o[19]=c;out.length++}return out};if(!Math.imul){comb10MulTo=smallMulTo}function bigMulTo(self,num,out){out.negative=num.negative^self.negative;out.length=self.length+num.length;var carry=0;var hncarry=0;for(var k=0;k>>26)|0;hncarry+=ncarry>>>26;ncarry&=67108863}out.words[k]=rword;carry=ncarry;ncarry=hncarry}if(carry!==0){out.words[k]=carry}else{out.length--}return out.strip()}function jumboMulTo(self,num,out){var fftm=new FFTM;return fftm.mulp(self,num,out)}BN.prototype.mulTo=function mulTo(num,out){var res;var len=this.length+num.length;if(this.length===10&&num.length===10){res=comb10MulTo(this,num,out)}else if(len<63){res=smallMulTo(this,num,out)}else if(len<1024){res=bigMulTo(this,num,out)}else{res=jumboMulTo(this,num,out)}return res};function FFTM(x,y){this.x=x;this.y=y}FFTM.prototype.makeRBT=function makeRBT(N){var t=new Array(N);var l=BN.prototype._countBits(N)-1;for(var i=0;i>=1}return rb};FFTM.prototype.permute=function permute(rbt,rws,iws,rtws,itws,N){for(var i=0;i>>1){i++}return 1<>>13;rws[2*i+1]=carry&8191;carry=carry>>>13}for(i=2*len;i>=26;carry+=w/67108864|0;carry+=lo>>>26;this.words[i]=lo&67108863}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.muln=function muln(num){return this.clone().imuln(num)};BN.prototype.sqr=function sqr(){return this.mul(this)};BN.prototype.isqr=function isqr(){return this.imul(this.clone())};BN.prototype.pow=function pow(num){var w=toBitArray(num);if(w.length===0)return new BN(1);var res=this;for(var i=0;i=0);var r=bits%26;var s=(bits-r)/26;var carryMask=67108863>>>26-r<<26-r;var i;if(r!==0){var carry=0;for(i=0;i>>26-r}if(carry){this.words[i]=carry;this.length++}}if(s!==0){for(i=this.length-1;i>=0;i--){this.words[i+s]=this.words[i]}for(i=0;i=0);var h;if(hint){h=(hint-hint%26)/26}else{h=0}var r=bits%26;var s=Math.min((bits-r)/26,this.length);var mask=67108863^67108863>>>r<s){this.length-=s;for(i=0;i=0&&(carry!==0||i>=h);i--){var word=this.words[i]|0;this.words[i]=carry<<26-r|word>>>r;carry=word&mask}if(maskedWords&&carry!==0){maskedWords.words[maskedWords.length++]=carry}if(this.length===0){this.words[0]=0;this.length=1}return this.strip()};BN.prototype.ishrn=function ishrn(bits,hint,extended){assert(this.negative===0);return this.iushrn(bits,hint,extended)};BN.prototype.shln=function shln(bits){return this.clone().ishln(bits)};BN.prototype.ushln=function ushln(bits){return this.clone().iushln(bits)};BN.prototype.shrn=function shrn(bits){return this.clone().ishrn(bits)};BN.prototype.ushrn=function ushrn(bits){return this.clone().iushrn(bits)};BN.prototype.testn=function testn(bit){assert(typeof bit==="number"&&bit>=0);var r=bit%26;var s=(bit-r)/26;var q=1<=0);var r=bits%26;var s=(bits-r)/26;assert(this.negative===0,"imaskn works only with positive numbers");if(this.length<=s){return this}if(r!==0){s++}this.length=Math.min(s,this.length);if(r!==0){var mask=67108863^67108863>>>r<=67108864;i++){this.words[i]-=67108864;if(i===this.length-1){this.words[i+1]=1}else{this.words[i+1]++}}this.length=Math.max(this.length,i+1);return this};BN.prototype.isubn=function isubn(num){assert(typeof num==="number");assert(num<67108864);if(num<0)return this.iaddn(-num);if(this.negative!==0){this.negative=0;this.iaddn(num);this.negative=1;return this}this.words[0]-=num;if(this.length===1&&this.words[0]<0){this.words[0]=-this.words[0];this.negative=1}else{for(var i=0;i>26)-(right/67108864|0);this.words[i+shift]=w&67108863}for(;i>26;this.words[i+shift]=w&67108863}if(carry===0)return this.strip();assert(carry===-1);carry=0;for(i=0;i>26;this.words[i]=w&67108863}this.negative=1;return this.strip()};BN.prototype._wordDiv=function _wordDiv(num,mode){var shift=this.length-num.length;var a=this.clone();var b=num;var bhi=b.words[b.length-1]|0;var bhiBits=this._countBits(bhi);shift=26-bhiBits;if(shift!==0){b=b.ushln(shift);a.iushln(shift);bhi=b.words[b.length-1]|0}var m=a.length-b.length;var q;if(mode!=="mod"){q=new BN(null);q.length=m+1;q.words=new Array(q.length);for(var i=0;i=0;j--){var qj=(a.words[b.length+j]|0)*67108864+(a.words[b.length+j-1]|0);qj=Math.min(qj/bhi|0,67108863);a._ishlnsubmul(b,qj,j);while(a.negative!==0){qj--;a.negative=0;a._ishlnsubmul(b,1,j);if(!a.isZero()){a.negative^=1}}if(q){q.words[j]=qj}}if(q){q.strip()}a.strip();if(mode!=="div"&&shift!==0){a.iushrn(shift)}return{div:q||null,mod:a}};BN.prototype.divmod=function divmod(num,mode,positive){assert(!num.isZero());if(this.isZero()){return{div:new BN(0),mod:new BN(0)}}var div,mod,res;if(this.negative!==0&&num.negative===0){res=this.neg().divmod(num,mode);if(mode!=="mod"){div=res.div.neg()}if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.iadd(num)}}return{div:div,mod:mod}}if(this.negative===0&&num.negative!==0){res=this.divmod(num.neg(),mode);if(mode!=="mod"){div=res.div.neg()}return{div:div,mod:res.mod}}if((this.negative&num.negative)!==0){res=this.neg().divmod(num.neg(),mode);if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.isub(num)}}return{div:res.div,mod:mod}}if(num.length>this.length||this.cmp(num)<0){return{div:new BN(0),mod:this}}if(num.length===1){if(mode==="div"){return{div:this.divn(num.words[0]),mod:null}}if(mode==="mod"){return{div:null,mod:new BN(this.modn(num.words[0]))}}return{div:this.divn(num.words[0]),mod:new BN(this.modn(num.words[0]))}}return this._wordDiv(num,mode)};BN.prototype.div=function div(num){return this.divmod(num,"div",false).div};BN.prototype.mod=function mod(num){return this.divmod(num,"mod",false).mod};BN.prototype.umod=function umod(num){return this.divmod(num,"mod",true).mod};BN.prototype.divRound=function divRound(num){var dm=this.divmod(num);if(dm.mod.isZero())return dm.div;var mod=dm.div.negative!==0?dm.mod.isub(num):dm.mod;var half=num.ushrn(1);var r2=num.andln(1);var cmp=mod.cmp(half);if(cmp<0||r2===1&&cmp===0)return dm.div;return dm.div.negative!==0?dm.div.isubn(1):dm.div.iaddn(1)};BN.prototype.modn=function modn(num){assert(num<=67108863);var p=(1<<26)%num;var acc=0;for(var i=this.length-1;i>=0;i--){acc=(p*acc+(this.words[i]|0))%num}return acc};BN.prototype.idivn=function idivn(num){assert(num<=67108863);var carry=0;for(var i=this.length-1;i>=0;i--){var w=(this.words[i]|0)+carry*67108864;this.words[i]=w/num|0;carry=w%num}return this.strip()};BN.prototype.divn=function divn(num){return this.clone().idivn(num)};BN.prototype.egcd=function egcd(p){assert(p.negative===0);assert(!p.isZero());var x=this;var y=p.clone();if(x.negative!==0){x=x.umod(p)}else{x=x.clone()}var A=new BN(1);var B=new BN(0);var C=new BN(0);var D=new BN(1);var g=0;while(x.isEven()&&y.isEven()){x.iushrn(1);y.iushrn(1);++g}var yp=y.clone();var xp=x.clone();while(!x.isZero()){for(var i=0,im=1;(x.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){x.iushrn(i);while(i-- >0){if(A.isOdd()||B.isOdd()){A.iadd(yp);B.isub(xp)}A.iushrn(1);B.iushrn(1)}}for(var j=0,jm=1;(y.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){y.iushrn(j);while(j-- >0){if(C.isOdd()||D.isOdd()){C.iadd(yp);D.isub(xp)}C.iushrn(1);D.iushrn(1)}}if(x.cmp(y)>=0){x.isub(y);A.isub(C);B.isub(D)}else{y.isub(x);C.isub(A);D.isub(B)}}return{a:C,b:D,gcd:y.iushln(g)}};BN.prototype._invmp=function _invmp(p){assert(p.negative===0);assert(!p.isZero());var a=this;var b=p.clone();if(a.negative!==0){a=a.umod(p)}else{a=a.clone()}var x1=new BN(1);var x2=new BN(0);var delta=b.clone();while(a.cmpn(1)>0&&b.cmpn(1)>0){for(var i=0,im=1;(a.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){a.iushrn(i);while(i-- >0){if(x1.isOdd()){x1.iadd(delta)}x1.iushrn(1)}}for(var j=0,jm=1;(b.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){b.iushrn(j);while(j-- >0){if(x2.isOdd()){x2.iadd(delta)}x2.iushrn(1)}}if(a.cmp(b)>=0){a.isub(b);x1.isub(x2)}else{b.isub(a);x2.isub(x1)}}var res;if(a.cmpn(1)===0){res=x1}else{res=x2}if(res.cmpn(0)<0){res.iadd(p)}return res};BN.prototype.gcd=function gcd(num){if(this.isZero())return num.abs();if(num.isZero())return this.abs();var a=this.clone();var b=num.clone();a.negative=0;b.negative=0;for(var shift=0;a.isEven()&&b.isEven();shift++){a.iushrn(1);b.iushrn(1)}do{while(a.isEven()){a.iushrn(1)}while(b.isEven()){b.iushrn(1)}var r=a.cmp(b);if(r<0){var t=a;a=b;b=t}else if(r===0||b.cmpn(1)===0){break}a.isub(b)}while(true);return b.iushln(shift)};BN.prototype.invm=function invm(num){return this.egcd(num).a.umod(num)};BN.prototype.isEven=function isEven(){return(this.words[0]&1)===0};BN.prototype.isOdd=function isOdd(){return(this.words[0]&1)===1};BN.prototype.andln=function andln(num){return this.words[0]&num};BN.prototype.bincn=function bincn(bit){assert(typeof bit==="number");var r=bit%26;var s=(bit-r)/26;var q=1<>>26;w&=67108863;this.words[i]=w}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.isZero=function isZero(){return this.length===1&&this.words[0]===0};BN.prototype.cmpn=function cmpn(num){var negative=num<0;if(this.negative!==0&&!negative)return-1;if(this.negative===0&&negative)return 1;this.strip();var res;if(this.length>1){res=1}else{if(negative){num=-num}assert(num<=67108863,"Number is too big");var w=this.words[0]|0;res=w===num?0:wnum.length)return 1;if(this.length=0;i--){var a=this.words[i]|0;var b=num.words[i]|0;if(a===b)continue;if(ab){res=1}break}return res};BN.prototype.gtn=function gtn(num){return this.cmpn(num)===1};BN.prototype.gt=function gt(num){return this.cmp(num)===1};BN.prototype.gten=function gten(num){return this.cmpn(num)>=0};BN.prototype.gte=function gte(num){return this.cmp(num)>=0};BN.prototype.ltn=function ltn(num){return this.cmpn(num)===-1};BN.prototype.lt=function lt(num){return this.cmp(num)===-1};BN.prototype.lten=function lten(num){return this.cmpn(num)<=0};BN.prototype.lte=function lte(num){return this.cmp(num)<=0};BN.prototype.eqn=function eqn(num){return this.cmpn(num)===0};BN.prototype.eq=function eq(num){return this.cmp(num)===0};BN.red=function red(num){return new Red(num)};BN.prototype.toRed=function toRed(ctx){assert(!this.red,"Already a number in reduction context");assert(this.negative===0,"red works only with positives");return ctx.convertTo(this)._forceRed(ctx)};BN.prototype.fromRed=function fromRed(){assert(this.red,"fromRed works only with numbers in reduction context");return this.red.convertFrom(this)};BN.prototype._forceRed=function _forceRed(ctx){this.red=ctx;return this};BN.prototype.forceRed=function forceRed(ctx){assert(!this.red,"Already a number in reduction context");return this._forceRed(ctx)};BN.prototype.redAdd=function redAdd(num){assert(this.red,"redAdd works only with red numbers");return this.red.add(this,num)};BN.prototype.redIAdd=function redIAdd(num){assert(this.red,"redIAdd works only with red numbers");return this.red.iadd(this,num)};BN.prototype.redSub=function redSub(num){assert(this.red,"redSub works only with red numbers");return this.red.sub(this,num)};BN.prototype.redISub=function redISub(num){assert(this.red,"redISub works only with red numbers");return this.red.isub(this,num)};BN.prototype.redShl=function redShl(num){assert(this.red,"redShl works only with red numbers");return this.red.shl(this,num)};BN.prototype.redMul=function redMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.mul(this,num)};BN.prototype.redIMul=function redIMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.imul(this,num)};BN.prototype.redSqr=function redSqr(){assert(this.red,"redSqr works only with red numbers");this.red._verify1(this);return this.red.sqr(this)};BN.prototype.redISqr=function redISqr(){assert(this.red,"redISqr works only with red numbers");this.red._verify1(this);return this.red.isqr(this)};BN.prototype.redSqrt=function redSqrt(){assert(this.red,"redSqrt works only with red numbers");this.red._verify1(this);return this.red.sqrt(this)};BN.prototype.redInvm=function redInvm(){assert(this.red,"redInvm works only with red numbers");this.red._verify1(this);return this.red.invm(this)};BN.prototype.redNeg=function redNeg(){assert(this.red,"redNeg works only with red numbers");this.red._verify1(this);return this.red.neg(this)};BN.prototype.redPow=function redPow(num){assert(this.red&&!num.red,"redPow(normalNum)");this.red._verify1(this);return this.red.pow(this,num)};var primes={k256:null,p224:null,p192:null,p25519:null};function MPrime(name,p){this.name=name;this.p=new BN(p,16);this.n=this.p.bitLength();this.k=new BN(1).iushln(this.n).isub(this.p);this.tmp=this._tmp()}MPrime.prototype._tmp=function _tmp(){var tmp=new BN(null);tmp.words=new Array(Math.ceil(this.n/13));return tmp};MPrime.prototype.ireduce=function ireduce(num){var r=num;var rlen;do{this.split(r,this.tmp);r=this.imulK(r);r=r.iadd(this.tmp);rlen=r.bitLength()}while(rlen>this.n);var cmp=rlen0){r.isub(this.p)}else{if(r.strip!==undefined){r.strip()}else{r._strip()}}return r};MPrime.prototype.split=function split(input,out){input.iushrn(this.n,0,out)};MPrime.prototype.imulK=function imulK(num){return num.imul(this.k)};function K256(){MPrime.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}inherits(K256,MPrime);K256.prototype.split=function split(input,output){var mask=4194303;var outLen=Math.min(input.length,9);for(var i=0;i>>22;prev=next}prev>>>=22;input.words[i-10]=prev;if(prev===0&&input.length>10){input.length-=10}else{input.length-=9}};K256.prototype.imulK=function imulK(num){num.words[num.length]=0;num.words[num.length+1]=0;num.length+=2;var lo=0;for(var i=0;i>>=26;num.words[i]=lo;carry=hi}if(carry!==0){num.words[num.length++]=carry}return num};BN._prime=function prime(name){if(primes[name])return primes[name];var prime;if(name==="k256"){prime=new K256}else if(name==="p224"){prime=new P224}else if(name==="p192"){prime=new P192}else if(name==="p25519"){prime=new P25519}else{throw new Error("Unknown prime "+name)}primes[name]=prime;return prime};function Red(m){if(typeof m==="string"){var prime=BN._prime(m);this.m=prime.p;this.prime=prime}else{assert(m.gtn(1),"modulus must be greater than 1");this.m=m;this.prime=null}}Red.prototype._verify1=function _verify1(a){assert(a.negative===0,"red works only with positives");assert(a.red,"red works only with red numbers")};Red.prototype._verify2=function _verify2(a,b){assert((a.negative|b.negative)===0,"red works only with positives");assert(a.red&&a.red===b.red,"red works only with red numbers")};Red.prototype.imod=function imod(a){if(this.prime)return this.prime.ireduce(a)._forceRed(this);return a.umod(this.m)._forceRed(this)};Red.prototype.neg=function neg(a){if(a.isZero()){return a.clone()}return this.m.sub(a)._forceRed(this)};Red.prototype.add=function add(a,b){this._verify2(a,b);var res=a.add(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res._forceRed(this)};Red.prototype.iadd=function iadd(a,b){this._verify2(a,b);var res=a.iadd(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res};Red.prototype.sub=function sub(a,b){this._verify2(a,b);var res=a.sub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res._forceRed(this)};Red.prototype.isub=function isub(a,b){this._verify2(a,b);var res=a.isub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res};Red.prototype.shl=function shl(a,num){this._verify1(a);return this.imod(a.ushln(num))};Red.prototype.imul=function imul(a,b){this._verify2(a,b);return this.imod(a.imul(b))};Red.prototype.mul=function mul(a,b){this._verify2(a,b);return this.imod(a.mul(b))};Red.prototype.isqr=function isqr(a){return this.imul(a,a.clone())};Red.prototype.sqr=function sqr(a){return this.mul(a,a)};Red.prototype.sqrt=function sqrt(a){if(a.isZero())return a.clone();var mod3=this.m.andln(3);assert(mod3%2===1);if(mod3===3){var pow=this.m.add(new BN(1)).iushrn(2);return this.pow(a,pow)}var q=this.m.subn(1);var s=0;while(!q.isZero()&&q.andln(1)===0){s++;q.iushrn(1)}assert(!q.isZero());var one=new BN(1).toRed(this);var nOne=one.redNeg();var lpow=this.m.subn(1).iushrn(1);var z=this.m.bitLength();z=new BN(2*z*z).toRed(this);while(this.pow(z,lpow).cmp(nOne)!==0){z.redIAdd(nOne)}var c=this.pow(z,q);var r=this.pow(a,q.addn(1).iushrn(1));var t=this.pow(a,q);var m=s;while(t.cmp(one)!==0){var tmp=t;for(var i=0;tmp.cmp(one)!==0;i++){tmp=tmp.redSqr()}assert(i=0;i--){var word=num.words[i];for(var j=start-1;j>=0;j--){var bit=word>>j&1;if(res!==wnd[0]){res=this.sqr(res)}if(bit===0&¤t===0){currentLen=0;continue}current<<=1;current|=bit;currentLen++;if(currentLen!==windowSize&&(i!==0||j!==0))continue;res=this.mul(res,wnd[current]);currentLen=0;current=0}start=26}return res};Red.prototype.convertTo=function convertTo(num){var r=num.umod(this.m);return r===num?r.clone():r};Red.prototype.convertFrom=function convertFrom(num){var res=num.clone();res.red=null;return res};BN.mont=function mont(num){return new Mont(num)};function Mont(m){Red.call(this,m);this.shift=this.m.bitLength();if(this.shift%26!==0){this.shift+=26-this.shift%26}this.r=new BN(1).iushln(this.shift);this.r2=this.imod(this.r.sqr());this.rinv=this.r._invmp(this.m);this.minv=this.rinv.mul(this.r).isubn(1).div(this.m);this.minv=this.minv.umod(this.r);this.minv=this.r.sub(this.minv)}inherits(Mont,Red);Mont.prototype.convertTo=function convertTo(num){return this.imod(num.ushln(this.shift))};Mont.prototype.convertFrom=function convertFrom(num){var r=this.imod(num.mul(this.rinv));r.red=null;return r};Mont.prototype.imul=function imul(a,b){if(a.isZero()||b.isZero()){a.words[0]=0;a.length=1;return a}var t=a.imul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.mul=function mul(a,b){if(a.isZero()||b.isZero())return new BN(0)._forceRed(this);var t=a.mul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.invm=function invm(a){var res=this.imod(a._invmp(this.m).mul(this.r2));return res._forceRed(this)}})(typeof module==="undefined"||module,this)},{buffer:115}],108:[function(require,module,exports){(function(global){(function(){"use strict";var objectAssign=require("object-assign");function compare(a,b){if(a===b){return 0}var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i=0){var next_line=out.indexOf("\n",idx+1);out=out.substring(next_line+1)}this.stack=out}}};util.inherits(assert.AssertionError,Error);function truncate(s,n){if(typeof s==="string"){return s.length=0;i--){if(ka[i]!==kb[i])return false}for(i=ka.length-1;i>=0;i--){key=ka[i];if(!_deepEqual(a[key],b[key],strict,actualVisitedObjects))return false}return true}assert.notDeepEqual=function notDeepEqual(actual,expected,message){if(_deepEqual(actual,expected,false)){fail(actual,expected,message,"notDeepEqual",assert.notDeepEqual)}};assert.notDeepStrictEqual=notDeepStrictEqual;function notDeepStrictEqual(actual,expected,message){if(_deepEqual(actual,expected,true)){fail(actual,expected,message,"notDeepStrictEqual",notDeepStrictEqual)}}assert.strictEqual=function strictEqual(actual,expected,message){if(actual!==expected){fail(actual,expected,message,"===",assert.strictEqual)}};assert.notStrictEqual=function notStrictEqual(actual,expected,message){if(actual===expected){fail(actual,expected,message,"!==",assert.notStrictEqual)}};function expectedException(actual,expected){if(!actual||!expected){return false}if(Object.prototype.toString.call(expected)=="[object RegExp]"){return expected.test(actual)}try{if(actual instanceof expected){return true}}catch(e){}if(Error.isPrototypeOf(expected)){return false}return expected.call({},actual)===true}function _tryBlock(block){var error;try{block()}catch(e){error=e}return error}function _throws(shouldThrow,block,expected,message){var actual;if(typeof block!=="function"){throw new TypeError('"block" argument must be a function')}if(typeof expected==="string"){message=expected;expected=null}actual=_tryBlock(block);message=(expected&&expected.name?" ("+expected.name+").":".")+(message?" "+message:".");if(shouldThrow&&!actual){fail(actual,expected,"Missing expected exception"+message)}var userProvidedMessage=typeof message==="string";var isUnwantedException=!shouldThrow&&util.isError(actual);var isUnexpectedException=!shouldThrow&&actual&&!expected;if(isUnwantedException&&userProvidedMessage&&expectedException(actual,expected)||isUnexpectedException){fail(actual,expected,"Got unwanted exception"+message)}if(shouldThrow&&actual&&expected&&!expectedException(actual,expected)||!shouldThrow&&actual){throw actual}}assert.throws=function(block,error,message){_throws(true,block,error,message)};assert.doesNotThrow=function(block,error,message){_throws(false,block,error,message)};assert.ifError=function(err){if(err)throw err};function strict(value,message){if(!value)fail(value,true,message,"==",strict)}assert.strict=objectAssign(strict,assert,{equal:assert.strictEqual,deepEqual:assert.deepStrictEqual,notEqual:assert.notStrictEqual,notDeepEqual:assert.notDeepStrictEqual});assert.strict.strict=assert.strict;var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj){if(hasOwn.call(obj,key))keys.push(key)}return keys}}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"object-assign":234,"util/":111}],109:[function(require,module,exports){arguments[4][83][0].apply(exports,arguments)},{dup:83}],110:[function(require,module,exports){module.exports=function isBuffer(arg){return arg&&typeof arg==="object"&&typeof arg.copy==="function"&&typeof arg.fill==="function"&&typeof arg.readUInt8==="function"}},{}],111:[function(require,module,exports){(function(process,global){(function(){var formatRegExp=/%[sdj%]/g;exports.format=function(f){if(!isString(f)){var objects=[];for(var i=0;i=len)return x;switch(x){case"%s":return String(args[i++]);case"%d":return Number(args[i++]);case"%j":try{return JSON.stringify(args[i++])}catch(_){return"[Circular]"}default:return x}});for(var x=args[i];i=3)ctx.depth=arguments[2];if(arguments.length>=4)ctx.colors=arguments[3];if(isBoolean(opts)){ctx.showHidden=opts}else if(opts){exports._extend(ctx,opts)}if(isUndefined(ctx.showHidden))ctx.showHidden=false;if(isUndefined(ctx.depth))ctx.depth=2;if(isUndefined(ctx.colors))ctx.colors=false;if(isUndefined(ctx.customInspect))ctx.customInspect=true;if(ctx.colors)ctx.stylize=stylizeWithColor;return formatValue(ctx,obj,ctx.depth)}exports.inspect=inspect;inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};inspect.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};function stylizeWithColor(str,styleType){var style=inspect.styles[styleType];if(style){return"["+inspect.colors[style][0]+"m"+str+"["+inspect.colors[style][1]+"m"}else{return str}}function stylizeNoColor(str,styleType){return str}function arrayToHash(array){var hash={};array.forEach(function(val,idx){hash[val]=true});return hash}function formatValue(ctx,value,recurseTimes){if(ctx.customInspect&&value&&isFunction(value.inspect)&&value.inspect!==exports.inspect&&!(value.constructor&&value.constructor.prototype===value)){var ret=value.inspect(recurseTimes,ctx);if(!isString(ret)){ret=formatValue(ctx,ret,recurseTimes)}return ret}var primitive=formatPrimitive(ctx,value);if(primitive){return primitive}var keys=Object.keys(value);var visibleKeys=arrayToHash(keys);if(ctx.showHidden){keys=Object.getOwnPropertyNames(value)}if(isError(value)&&(keys.indexOf("message")>=0||keys.indexOf("description")>=0)){return formatError(value)}if(keys.length===0){if(isFunction(value)){var name=value.name?": "+value.name:"";return ctx.stylize("[Function"+name+"]","special")}if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}if(isDate(value)){return ctx.stylize(Date.prototype.toString.call(value),"date")}if(isError(value)){return formatError(value)}}var base="",array=false,braces=["{","}"];if(isArray(value)){array=true;braces=["[","]"]}if(isFunction(value)){var n=value.name?": "+value.name:"";base=" [Function"+n+"]"}if(isRegExp(value)){base=" "+RegExp.prototype.toString.call(value)}if(isDate(value)){base=" "+Date.prototype.toUTCString.call(value)}if(isError(value)){base=" "+formatError(value)}if(keys.length===0&&(!array||value.length==0)){return braces[0]+base+braces[1]}if(recurseTimes<0){if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}else{return ctx.stylize("[Object]","special")}}ctx.seen.push(value);var output;if(array){output=formatArray(ctx,value,recurseTimes,visibleKeys,keys)}else{output=keys.map(function(key){return formatProperty(ctx,value,recurseTimes,visibleKeys,key,array)})}ctx.seen.pop();return reduceToSingleString(output,base,braces)}function formatPrimitive(ctx,value){if(isUndefined(value))return ctx.stylize("undefined","undefined");if(isString(value)){var simple="'"+JSON.stringify(value).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return ctx.stylize(simple,"string")}if(isNumber(value))return ctx.stylize(""+value,"number");if(isBoolean(value))return ctx.stylize(""+value,"boolean");if(isNull(value))return ctx.stylize("null","null")}function formatError(value){return"["+Error.prototype.toString.call(value)+"]"}function formatArray(ctx,value,recurseTimes,visibleKeys,keys){var output=[];for(var i=0,l=value.length;i-1){if(array){str=str.split("\n").map(function(line){return" "+line}).join("\n").substr(2)}else{str="\n"+str.split("\n").map(function(line){return" "+line}).join("\n")}}}else{str=ctx.stylize("[Circular]","special")}}if(isUndefined(name)){if(array&&key.match(/^\d+$/)){return str}name=JSON.stringify(""+key);if(name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){name=name.substr(1,name.length-2);name=ctx.stylize(name,"name")}else{name=name.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");name=ctx.stylize(name,"string")}}return name+": "+str}function reduceToSingleString(output,base,braces){var numLinesEst=0;var length=output.reduce(function(prev,cur){numLinesEst++;if(cur.indexOf("\n")>=0)numLinesEst++;return prev+cur.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(length>60){return braces[0]+(base===""?"":base+"\n ")+" "+output.join(",\n ")+" "+braces[1]}return braces[0]+base+" "+output.join(", ")+" "+braces[1]}function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return typeof arg==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return typeof arg==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||typeof arg==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;exports.isBuffer=require("./support/isBuffer");function objectToString(o){return Object.prototype.toString.call(o)}function pad(n){return n<10?"0"+n.toString(10):n.toString(10)}var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var d=new Date;var time=[pad(d.getHours()),pad(d.getMinutes()),pad(d.getSeconds())].join(":");return[d.getDate(),months[d.getMonth()],time].join(" ")}exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))};exports.inherits=require("inherits");exports._extend=function(origin,add){if(!add||!isObject(add))return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin};function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}).call(this)}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":110,_process:246,inherits:109}],112:[function(require,module,exports){"use strict";exports.byteLength=byteLength;exports.toByteArray=toByteArray;exports.fromByteArray=fromByteArray;var lookup=[];var revLookup=[];var Arr=typeof Uint8Array!=="undefined"?Uint8Array:Array;var code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var i=0,len=code.length;i0){throw new Error("Invalid string. Length must be a multiple of 4")}var validLen=b64.indexOf("=");if(validLen===-1)validLen=len;var placeHoldersLen=validLen===len?0:4-validLen%4;return[validLen,placeHoldersLen]}function byteLength(b64){var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function _byteLength(b64,validLen,placeHoldersLen){return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function toByteArray(b64){var tmp;var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];var arr=new Arr(_byteLength(b64,validLen,placeHoldersLen));var curByte=0;var len=placeHoldersLen>0?validLen-4:validLen;var i;for(i=0;i>16&255;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}if(placeHoldersLen===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[curByte++]=tmp&255}if(placeHoldersLen===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}return arr}function tripletToBase64(num){return lookup[num>>18&63]+lookup[num>>12&63]+lookup[num>>6&63]+lookup[num&63]}function encodeChunk(uint8,start,end){var tmp;var output=[];for(var i=start;ilen2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];parts.push(lookup[tmp>>2]+lookup[tmp<<4&63]+"==")}else if(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];parts.push(lookup[tmp>>10]+lookup[tmp>>4&63]+lookup[tmp<<2&63]+"=")}return parts.join("")}},{}],113:[function(require,module,exports){(function(module,exports){"use strict";function assert(val,msg){if(!val)throw new Error(msg||"Assertion failed")}function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}function BN(number,base,endian){if(BN.isBN(number)){return number}this.negative=0;this.words=null;this.length=0;this.red=null;if(number!==null){if(base==="le"||base==="be"){endian=base;base=10}this._init(number||0,base||10,endian||"be")}}if(typeof module==="object"){module.exports=BN}else{exports.BN=BN}BN.BN=BN;BN.wordSize=26;var Buffer;try{if(typeof window!=="undefined"&&typeof window.Buffer!=="undefined"){Buffer=window.Buffer}else{Buffer=require("buffer").Buffer}}catch(e){}BN.isBN=function isBN(num){if(num instanceof BN){return true}return num!==null&&typeof num==="object"&&num.constructor.wordSize===BN.wordSize&&Array.isArray(num.words)};BN.max=function max(left,right){if(left.cmp(right)>0)return left;return right};BN.min=function min(left,right){if(left.cmp(right)<0)return left;return right};BN.prototype._init=function init(number,base,endian){if(typeof number==="number"){return this._initNumber(number,base,endian)}if(typeof number==="object"){return this._initArray(number,base,endian)}if(base==="hex"){base=16}assert(base===(base|0)&&base>=2&&base<=36);number=number.toString().replace(/\s+/g,"");var start=0;if(number[0]==="-"){start++;this.negative=1}if(start=0;i-=3){w=number[i]|number[i-1]<<8|number[i-2]<<16;this.words[j]|=w<>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}else if(endian==="le"){for(i=0,j=0;i>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}return this._strip()};function parseHex4Bits(string,index){var c=string.charCodeAt(index);if(c>=48&&c<=57){return c-48}else if(c>=65&&c<=70){return c-55}else if(c>=97&&c<=102){return c-87}else{assert(false,"Invalid character in "+string)}}function parseHexByte(string,lowerBound,index){var r=parseHex4Bits(string,index);if(index-1>=lowerBound){r|=parseHex4Bits(string,index-1)<<4}return r}BN.prototype._parseHex=function _parseHex(number,start,endian){this.length=Math.ceil((number.length-start)/6);this.words=new Array(this.length);for(var i=0;i=start;i-=2){w=parseHexByte(number,start,i)<=18){off-=18;j+=1;this.words[j]|=w>>>26}else{off+=8}}}else{var parseLength=number.length-start;for(i=parseLength%2===0?start+1:start;i=18){off-=18;j+=1;this.words[j]|=w>>>26}else{off+=8}}}this._strip()};function parseBase(str,start,end,mul){var r=0;var b=0;var len=Math.min(str.length,end);for(var i=start;i=49){b=c-49+10}else if(c>=17){b=c-17+10}else{b=c}assert(c>=0&&b1&&this.words[this.length-1]===0){this.length--}return this._normSign()};BN.prototype._normSign=function _normSign(){if(this.length===1&&this.words[0]===0){this.negative=0}return this};if(typeof Symbol!=="undefined"&&typeof Symbol.for==="function"){try{BN.prototype[Symbol.for("nodejs.util.inspect.custom")]=inspect}catch(e){BN.prototype.inspect=inspect}}else{BN.prototype.inspect=inspect}function inspect(){return(this.red?""}var zeros=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"];var groupSizes=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5];var groupBases=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];BN.prototype.toString=function toString(base,padding){base=base||10;padding=padding|0||1;var out;if(base===16||base==="hex"){out="";var off=0;var carry=0;for(var i=0;i>>24-off&16777215;if(carry!==0||i!==this.length-1){out=zeros[6-word.length]+word+out}else{out=word+out}off+=2;if(off>=26){off-=26;i--}}if(carry!==0){out=carry.toString(16)+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}if(base===(base|0)&&base>=2&&base<=36){var groupSize=groupSizes[base];var groupBase=groupBases[base];out="";var c=this.clone();c.negative=0;while(!c.isZero()){var r=c.modrn(groupBase).toString(base);c=c.idivn(groupBase);if(!c.isZero()){out=zeros[groupSize-r.length]+r+out}else{out=r+out}}if(this.isZero()){out="0"+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}assert(false,"Base should be between 2 and 36")};BN.prototype.toNumber=function toNumber(){var ret=this.words[0];if(this.length===2){ret+=this.words[1]*67108864}else if(this.length===3&&this.words[2]===1){ret+=4503599627370496+this.words[1]*67108864}else if(this.length>2){assert(false,"Number can only safely store up to 53 bits")}return this.negative!==0?-ret:ret};BN.prototype.toJSON=function toJSON(){return this.toString(16,2)};if(Buffer){BN.prototype.toBuffer=function toBuffer(endian,length){return this.toArrayLike(Buffer,endian,length)}}BN.prototype.toArray=function toArray(endian,length){return this.toArrayLike(Array,endian,length)};var allocate=function allocate(ArrayType,size){if(ArrayType.allocUnsafe){return ArrayType.allocUnsafe(size)}return new ArrayType(size)};BN.prototype.toArrayLike=function toArrayLike(ArrayType,endian,length){this._strip();var byteLength=this.byteLength();var reqLength=length||Math.max(1,byteLength);assert(byteLength<=reqLength,"byte array longer than desired length");assert(reqLength>0,"Requested array length <= 0");var res=allocate(ArrayType,reqLength);var postfix=endian==="le"?"LE":"BE";this["_toArrayLike"+postfix](res,byteLength);return res};BN.prototype._toArrayLikeLE=function _toArrayLikeLE(res,byteLength){var position=0;var carry=0;for(var i=0,shift=0;i>8&255}if(position>16&255}if(shift===6){if(position>24&255}carry=0;shift=0}else{carry=word>>>24;shift+=2}}if(position=0){res[position--]=word>>8&255}if(position>=0){res[position--]=word>>16&255}if(shift===6){if(position>=0){res[position--]=word>>24&255}carry=0;shift=0}else{carry=word>>>24;shift+=2}}if(position>=0){res[position--]=carry;while(position>=0){res[position--]=0}}};if(Math.clz32){BN.prototype._countBits=function _countBits(w){return 32-Math.clz32(w)}}else{BN.prototype._countBits=function _countBits(w){var t=w;var r=0;if(t>=4096){r+=13;t>>>=13}if(t>=64){r+=7;t>>>=7}if(t>=8){r+=4;t>>>=4}if(t>=2){r+=2;t>>>=2}return r+t}}BN.prototype._zeroBits=function _zeroBits(w){if(w===0)return 26;var t=w;var r=0;if((t&8191)===0){r+=13;t>>>=13}if((t&127)===0){r+=7;t>>>=7}if((t&15)===0){r+=4;t>>>=4}if((t&3)===0){r+=2;t>>>=2}if((t&1)===0){r++}return r};BN.prototype.bitLength=function bitLength(){var w=this.words[this.length-1];var hi=this._countBits(w);return(this.length-1)*26+hi};function toBitArray(num){var w=new Array(num.bitLength());for(var bit=0;bit>>wbit&1}return w}BN.prototype.zeroBits=function zeroBits(){if(this.isZero())return 0;var r=0;for(var i=0;inum.length)return this.clone().ior(num);return num.clone().ior(this)};BN.prototype.uor=function uor(num){if(this.length>num.length)return this.clone().iuor(num);return num.clone().iuor(this)};BN.prototype.iuand=function iuand(num){var b;if(this.length>num.length){b=num}else{b=this}for(var i=0;inum.length)return this.clone().iand(num);return num.clone().iand(this)};BN.prototype.uand=function uand(num){if(this.length>num.length)return this.clone().iuand(num);return num.clone().iuand(this)};BN.prototype.iuxor=function iuxor(num){var a;var b;if(this.length>num.length){a=this;b=num}else{a=num;b=this}for(var i=0;inum.length)return this.clone().ixor(num);return num.clone().ixor(this)};BN.prototype.uxor=function uxor(num){if(this.length>num.length)return this.clone().iuxor(num);return num.clone().iuxor(this)};BN.prototype.inotn=function inotn(width){assert(typeof width==="number"&&width>=0);var bytesNeeded=Math.ceil(width/26)|0;var bitsLeft=width%26;this._expand(bytesNeeded);if(bitsLeft>0){bytesNeeded--}for(var i=0;i0){this.words[i]=~this.words[i]&67108863>>26-bitsLeft}return this._strip()};BN.prototype.notn=function notn(width){return this.clone().inotn(width)};BN.prototype.setn=function setn(bit,val){assert(typeof bit==="number"&&bit>=0);var off=bit/26|0;var wbit=bit%26;this._expand(off+1);if(val){this.words[off]=this.words[off]|1<num.length){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>>26}for(;carry!==0&&i>>26}this.length=a.length;if(carry!==0){this.words[this.length]=carry;this.length++}else if(a!==this){for(;inum.length)return this.clone().iadd(num);return num.clone().iadd(this)};BN.prototype.isub=function isub(num){if(num.negative!==0){num.negative=0;var r=this.iadd(num);num.negative=1;return r._normSign()}else if(this.negative!==0){this.negative=0;this.iadd(num);this.negative=1;return this._normSign()}var cmp=this.cmp(num);if(cmp===0){this.negative=0;this.length=1;this.words[0]=0;return this}var a,b;if(cmp>0){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>26;this.words[i]=r&67108863}for(;carry!==0&&i>26;this.words[i]=r&67108863}if(carry===0&&i>>26;var rword=carry&67108863;var maxJ=Math.min(k,num.length-1);for(var j=Math.max(0,k-self.length+1);j<=maxJ;j++){var i=k-j|0;a=self.words[i]|0;b=num.words[j]|0;r=a*b+rword;ncarry+=r/67108864|0;rword=r&67108863}out.words[k]=rword|0;carry=ncarry|0}if(carry!==0){out.words[k]=carry|0}else{out.length--}return out._strip()}var comb10MulTo=function comb10MulTo(self,num,out){var a=self.words;var b=num.words;var o=out.words;var c=0;var lo;var mid;var hi;var a0=a[0]|0;var al0=a0&8191;var ah0=a0>>>13;var a1=a[1]|0;var al1=a1&8191;var ah1=a1>>>13;var a2=a[2]|0;var al2=a2&8191;var ah2=a2>>>13;var a3=a[3]|0;var al3=a3&8191;var ah3=a3>>>13;var a4=a[4]|0;var al4=a4&8191;var ah4=a4>>>13;var a5=a[5]|0;var al5=a5&8191;var ah5=a5>>>13;var a6=a[6]|0;var al6=a6&8191;var ah6=a6>>>13;var a7=a[7]|0;var al7=a7&8191;var ah7=a7>>>13;var a8=a[8]|0;var al8=a8&8191;var ah8=a8>>>13;var a9=a[9]|0;var al9=a9&8191;var ah9=a9>>>13;var b0=b[0]|0;var bl0=b0&8191;var bh0=b0>>>13;var b1=b[1]|0;var bl1=b1&8191;var bh1=b1>>>13;var b2=b[2]|0;var bl2=b2&8191;var bh2=b2>>>13;var b3=b[3]|0;var bl3=b3&8191;var bh3=b3>>>13;var b4=b[4]|0;var bl4=b4&8191;var bh4=b4>>>13;var b5=b[5]|0;var bl5=b5&8191;var bh5=b5>>>13;var b6=b[6]|0;var bl6=b6&8191;var bh6=b6>>>13;var b7=b[7]|0;var bl7=b7&8191;var bh7=b7>>>13;var b8=b[8]|0;var bl8=b8&8191;var bh8=b8>>>13;var b9=b[9]|0;var bl9=b9&8191;var bh9=b9>>>13;out.negative=self.negative^num.negative;out.length=19;lo=Math.imul(al0,bl0);mid=Math.imul(al0,bh0);mid=mid+Math.imul(ah0,bl0)|0;hi=Math.imul(ah0,bh0);var w0=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w0>>>26)|0;w0&=67108863;lo=Math.imul(al1,bl0);mid=Math.imul(al1,bh0);mid=mid+Math.imul(ah1,bl0)|0;hi=Math.imul(ah1,bh0);lo=lo+Math.imul(al0,bl1)|0;mid=mid+Math.imul(al0,bh1)|0;mid=mid+Math.imul(ah0,bl1)|0;hi=hi+Math.imul(ah0,bh1)|0;var w1=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w1>>>26)|0;w1&=67108863;lo=Math.imul(al2,bl0);mid=Math.imul(al2,bh0);mid=mid+Math.imul(ah2,bl0)|0;hi=Math.imul(ah2,bh0);lo=lo+Math.imul(al1,bl1)|0;mid=mid+Math.imul(al1,bh1)|0;mid=mid+Math.imul(ah1,bl1)|0;hi=hi+Math.imul(ah1,bh1)|0;lo=lo+Math.imul(al0,bl2)|0;mid=mid+Math.imul(al0,bh2)|0;mid=mid+Math.imul(ah0,bl2)|0;hi=hi+Math.imul(ah0,bh2)|0;var w2=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w2>>>26)|0;w2&=67108863;lo=Math.imul(al3,bl0);mid=Math.imul(al3,bh0);mid=mid+Math.imul(ah3,bl0)|0;hi=Math.imul(ah3,bh0);lo=lo+Math.imul(al2,bl1)|0;mid=mid+Math.imul(al2,bh1)|0;mid=mid+Math.imul(ah2,bl1)|0;hi=hi+Math.imul(ah2,bh1)|0;lo=lo+Math.imul(al1,bl2)|0;mid=mid+Math.imul(al1,bh2)|0;mid=mid+Math.imul(ah1,bl2)|0;hi=hi+Math.imul(ah1,bh2)|0;lo=lo+Math.imul(al0,bl3)|0;mid=mid+Math.imul(al0,bh3)|0;mid=mid+Math.imul(ah0,bl3)|0;hi=hi+Math.imul(ah0,bh3)|0;var w3=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w3>>>26)|0;w3&=67108863;lo=Math.imul(al4,bl0);mid=Math.imul(al4,bh0);mid=mid+Math.imul(ah4,bl0)|0;hi=Math.imul(ah4,bh0);lo=lo+Math.imul(al3,bl1)|0;mid=mid+Math.imul(al3,bh1)|0;mid=mid+Math.imul(ah3,bl1)|0;hi=hi+Math.imul(ah3,bh1)|0;lo=lo+Math.imul(al2,bl2)|0;mid=mid+Math.imul(al2,bh2)|0;mid=mid+Math.imul(ah2,bl2)|0;hi=hi+Math.imul(ah2,bh2)|0;lo=lo+Math.imul(al1,bl3)|0;mid=mid+Math.imul(al1,bh3)|0;mid=mid+Math.imul(ah1,bl3)|0;hi=hi+Math.imul(ah1,bh3)|0;lo=lo+Math.imul(al0,bl4)|0;mid=mid+Math.imul(al0,bh4)|0;mid=mid+Math.imul(ah0,bl4)|0;hi=hi+Math.imul(ah0,bh4)|0;var w4=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w4>>>26)|0;w4&=67108863;lo=Math.imul(al5,bl0);mid=Math.imul(al5,bh0);mid=mid+Math.imul(ah5,bl0)|0;hi=Math.imul(ah5,bh0);lo=lo+Math.imul(al4,bl1)|0;mid=mid+Math.imul(al4,bh1)|0;mid=mid+Math.imul(ah4,bl1)|0;hi=hi+Math.imul(ah4,bh1)|0;lo=lo+Math.imul(al3,bl2)|0;mid=mid+Math.imul(al3,bh2)|0;mid=mid+Math.imul(ah3,bl2)|0;hi=hi+Math.imul(ah3,bh2)|0;lo=lo+Math.imul(al2,bl3)|0;mid=mid+Math.imul(al2,bh3)|0;mid=mid+Math.imul(ah2,bl3)|0;hi=hi+Math.imul(ah2,bh3)|0;lo=lo+Math.imul(al1,bl4)|0;mid=mid+Math.imul(al1,bh4)|0;mid=mid+Math.imul(ah1,bl4)|0;hi=hi+Math.imul(ah1,bh4)|0;lo=lo+Math.imul(al0,bl5)|0;mid=mid+Math.imul(al0,bh5)|0;mid=mid+Math.imul(ah0,bl5)|0;hi=hi+Math.imul(ah0,bh5)|0;var w5=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w5>>>26)|0;w5&=67108863;lo=Math.imul(al6,bl0);mid=Math.imul(al6,bh0);mid=mid+Math.imul(ah6,bl0)|0;hi=Math.imul(ah6,bh0);lo=lo+Math.imul(al5,bl1)|0;mid=mid+Math.imul(al5,bh1)|0;mid=mid+Math.imul(ah5,bl1)|0;hi=hi+Math.imul(ah5,bh1)|0;lo=lo+Math.imul(al4,bl2)|0;mid=mid+Math.imul(al4,bh2)|0;mid=mid+Math.imul(ah4,bl2)|0;hi=hi+Math.imul(ah4,bh2)|0;lo=lo+Math.imul(al3,bl3)|0;mid=mid+Math.imul(al3,bh3)|0;mid=mid+Math.imul(ah3,bl3)|0;hi=hi+Math.imul(ah3,bh3)|0;lo=lo+Math.imul(al2,bl4)|0;mid=mid+Math.imul(al2,bh4)|0;mid=mid+Math.imul(ah2,bl4)|0;hi=hi+Math.imul(ah2,bh4)|0;lo=lo+Math.imul(al1,bl5)|0;mid=mid+Math.imul(al1,bh5)|0;mid=mid+Math.imul(ah1,bl5)|0;hi=hi+Math.imul(ah1,bh5)|0;lo=lo+Math.imul(al0,bl6)|0;mid=mid+Math.imul(al0,bh6)|0;mid=mid+Math.imul(ah0,bl6)|0;hi=hi+Math.imul(ah0,bh6)|0;var w6=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w6>>>26)|0;w6&=67108863;lo=Math.imul(al7,bl0);mid=Math.imul(al7,bh0);mid=mid+Math.imul(ah7,bl0)|0;hi=Math.imul(ah7,bh0);lo=lo+Math.imul(al6,bl1)|0;mid=mid+Math.imul(al6,bh1)|0;mid=mid+Math.imul(ah6,bl1)|0;hi=hi+Math.imul(ah6,bh1)|0;lo=lo+Math.imul(al5,bl2)|0;mid=mid+Math.imul(al5,bh2)|0;mid=mid+Math.imul(ah5,bl2)|0;hi=hi+Math.imul(ah5,bh2)|0;lo=lo+Math.imul(al4,bl3)|0;mid=mid+Math.imul(al4,bh3)|0;mid=mid+Math.imul(ah4,bl3)|0;hi=hi+Math.imul(ah4,bh3)|0;lo=lo+Math.imul(al3,bl4)|0;mid=mid+Math.imul(al3,bh4)|0;mid=mid+Math.imul(ah3,bl4)|0;hi=hi+Math.imul(ah3,bh4)|0;lo=lo+Math.imul(al2,bl5)|0;mid=mid+Math.imul(al2,bh5)|0;mid=mid+Math.imul(ah2,bl5)|0;hi=hi+Math.imul(ah2,bh5)|0;lo=lo+Math.imul(al1,bl6)|0;mid=mid+Math.imul(al1,bh6)|0;mid=mid+Math.imul(ah1,bl6)|0;hi=hi+Math.imul(ah1,bh6)|0;lo=lo+Math.imul(al0,bl7)|0;mid=mid+Math.imul(al0,bh7)|0;mid=mid+Math.imul(ah0,bl7)|0;hi=hi+Math.imul(ah0,bh7)|0;var w7=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w7>>>26)|0;w7&=67108863;lo=Math.imul(al8,bl0);mid=Math.imul(al8,bh0);mid=mid+Math.imul(ah8,bl0)|0;hi=Math.imul(ah8,bh0);lo=lo+Math.imul(al7,bl1)|0;mid=mid+Math.imul(al7,bh1)|0;mid=mid+Math.imul(ah7,bl1)|0;hi=hi+Math.imul(ah7,bh1)|0;lo=lo+Math.imul(al6,bl2)|0;mid=mid+Math.imul(al6,bh2)|0;mid=mid+Math.imul(ah6,bl2)|0;hi=hi+Math.imul(ah6,bh2)|0;lo=lo+Math.imul(al5,bl3)|0;mid=mid+Math.imul(al5,bh3)|0;mid=mid+Math.imul(ah5,bl3)|0;hi=hi+Math.imul(ah5,bh3)|0;lo=lo+Math.imul(al4,bl4)|0;mid=mid+Math.imul(al4,bh4)|0;mid=mid+Math.imul(ah4,bl4)|0;hi=hi+Math.imul(ah4,bh4)|0;lo=lo+Math.imul(al3,bl5)|0;mid=mid+Math.imul(al3,bh5)|0;mid=mid+Math.imul(ah3,bl5)|0;hi=hi+Math.imul(ah3,bh5)|0;lo=lo+Math.imul(al2,bl6)|0;mid=mid+Math.imul(al2,bh6)|0;mid=mid+Math.imul(ah2,bl6)|0;hi=hi+Math.imul(ah2,bh6)|0;lo=lo+Math.imul(al1,bl7)|0;mid=mid+Math.imul(al1,bh7)|0;mid=mid+Math.imul(ah1,bl7)|0;hi=hi+Math.imul(ah1,bh7)|0;lo=lo+Math.imul(al0,bl8)|0;mid=mid+Math.imul(al0,bh8)|0;mid=mid+Math.imul(ah0,bl8)|0;hi=hi+Math.imul(ah0,bh8)|0;var w8=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w8>>>26)|0;w8&=67108863;lo=Math.imul(al9,bl0);mid=Math.imul(al9,bh0);mid=mid+Math.imul(ah9,bl0)|0;hi=Math.imul(ah9,bh0);lo=lo+Math.imul(al8,bl1)|0;mid=mid+Math.imul(al8,bh1)|0;mid=mid+Math.imul(ah8,bl1)|0;hi=hi+Math.imul(ah8,bh1)|0;lo=lo+Math.imul(al7,bl2)|0;mid=mid+Math.imul(al7,bh2)|0;mid=mid+Math.imul(ah7,bl2)|0;hi=hi+Math.imul(ah7,bh2)|0;lo=lo+Math.imul(al6,bl3)|0;mid=mid+Math.imul(al6,bh3)|0;mid=mid+Math.imul(ah6,bl3)|0;hi=hi+Math.imul(ah6,bh3)|0;lo=lo+Math.imul(al5,bl4)|0;mid=mid+Math.imul(al5,bh4)|0;mid=mid+Math.imul(ah5,bl4)|0;hi=hi+Math.imul(ah5,bh4)|0;lo=lo+Math.imul(al4,bl5)|0;mid=mid+Math.imul(al4,bh5)|0;mid=mid+Math.imul(ah4,bl5)|0;hi=hi+Math.imul(ah4,bh5)|0;lo=lo+Math.imul(al3,bl6)|0;mid=mid+Math.imul(al3,bh6)|0;mid=mid+Math.imul(ah3,bl6)|0;hi=hi+Math.imul(ah3,bh6)|0;lo=lo+Math.imul(al2,bl7)|0;mid=mid+Math.imul(al2,bh7)|0;mid=mid+Math.imul(ah2,bl7)|0;hi=hi+Math.imul(ah2,bh7)|0;lo=lo+Math.imul(al1,bl8)|0;mid=mid+Math.imul(al1,bh8)|0;mid=mid+Math.imul(ah1,bl8)|0;hi=hi+Math.imul(ah1,bh8)|0;lo=lo+Math.imul(al0,bl9)|0;mid=mid+Math.imul(al0,bh9)|0;mid=mid+Math.imul(ah0,bl9)|0;hi=hi+Math.imul(ah0,bh9)|0;var w9=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w9>>>26)|0;w9&=67108863;lo=Math.imul(al9,bl1);mid=Math.imul(al9,bh1);mid=mid+Math.imul(ah9,bl1)|0;hi=Math.imul(ah9,bh1);lo=lo+Math.imul(al8,bl2)|0;mid=mid+Math.imul(al8,bh2)|0;mid=mid+Math.imul(ah8,bl2)|0;hi=hi+Math.imul(ah8,bh2)|0;lo=lo+Math.imul(al7,bl3)|0;mid=mid+Math.imul(al7,bh3)|0;mid=mid+Math.imul(ah7,bl3)|0;hi=hi+Math.imul(ah7,bh3)|0;lo=lo+Math.imul(al6,bl4)|0;mid=mid+Math.imul(al6,bh4)|0;mid=mid+Math.imul(ah6,bl4)|0;hi=hi+Math.imul(ah6,bh4)|0;lo=lo+Math.imul(al5,bl5)|0;mid=mid+Math.imul(al5,bh5)|0;mid=mid+Math.imul(ah5,bl5)|0;hi=hi+Math.imul(ah5,bh5)|0;lo=lo+Math.imul(al4,bl6)|0;mid=mid+Math.imul(al4,bh6)|0;mid=mid+Math.imul(ah4,bl6)|0;hi=hi+Math.imul(ah4,bh6)|0;lo=lo+Math.imul(al3,bl7)|0;mid=mid+Math.imul(al3,bh7)|0;mid=mid+Math.imul(ah3,bl7)|0;hi=hi+Math.imul(ah3,bh7)|0;lo=lo+Math.imul(al2,bl8)|0;mid=mid+Math.imul(al2,bh8)|0;mid=mid+Math.imul(ah2,bl8)|0;hi=hi+Math.imul(ah2,bh8)|0;lo=lo+Math.imul(al1,bl9)|0;mid=mid+Math.imul(al1,bh9)|0;mid=mid+Math.imul(ah1,bl9)|0;hi=hi+Math.imul(ah1,bh9)|0;var w10=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w10>>>26)|0;w10&=67108863;lo=Math.imul(al9,bl2);mid=Math.imul(al9,bh2);mid=mid+Math.imul(ah9,bl2)|0;hi=Math.imul(ah9,bh2);lo=lo+Math.imul(al8,bl3)|0;mid=mid+Math.imul(al8,bh3)|0;mid=mid+Math.imul(ah8,bl3)|0;hi=hi+Math.imul(ah8,bh3)|0;lo=lo+Math.imul(al7,bl4)|0;mid=mid+Math.imul(al7,bh4)|0;mid=mid+Math.imul(ah7,bl4)|0;hi=hi+Math.imul(ah7,bh4)|0;lo=lo+Math.imul(al6,bl5)|0;mid=mid+Math.imul(al6,bh5)|0;mid=mid+Math.imul(ah6,bl5)|0;hi=hi+Math.imul(ah6,bh5)|0;lo=lo+Math.imul(al5,bl6)|0;mid=mid+Math.imul(al5,bh6)|0;mid=mid+Math.imul(ah5,bl6)|0;hi=hi+Math.imul(ah5,bh6)|0;lo=lo+Math.imul(al4,bl7)|0;mid=mid+Math.imul(al4,bh7)|0;mid=mid+Math.imul(ah4,bl7)|0;hi=hi+Math.imul(ah4,bh7)|0;lo=lo+Math.imul(al3,bl8)|0;mid=mid+Math.imul(al3,bh8)|0;mid=mid+Math.imul(ah3,bl8)|0;hi=hi+Math.imul(ah3,bh8)|0;lo=lo+Math.imul(al2,bl9)|0;mid=mid+Math.imul(al2,bh9)|0;mid=mid+Math.imul(ah2,bl9)|0;hi=hi+Math.imul(ah2,bh9)|0;var w11=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w11>>>26)|0;w11&=67108863;lo=Math.imul(al9,bl3);mid=Math.imul(al9,bh3);mid=mid+Math.imul(ah9,bl3)|0;hi=Math.imul(ah9,bh3);lo=lo+Math.imul(al8,bl4)|0;mid=mid+Math.imul(al8,bh4)|0;mid=mid+Math.imul(ah8,bl4)|0;hi=hi+Math.imul(ah8,bh4)|0;lo=lo+Math.imul(al7,bl5)|0;mid=mid+Math.imul(al7,bh5)|0;mid=mid+Math.imul(ah7,bl5)|0;hi=hi+Math.imul(ah7,bh5)|0;lo=lo+Math.imul(al6,bl6)|0;mid=mid+Math.imul(al6,bh6)|0;mid=mid+Math.imul(ah6,bl6)|0;hi=hi+Math.imul(ah6,bh6)|0;lo=lo+Math.imul(al5,bl7)|0;mid=mid+Math.imul(al5,bh7)|0;mid=mid+Math.imul(ah5,bl7)|0;hi=hi+Math.imul(ah5,bh7)|0;lo=lo+Math.imul(al4,bl8)|0;mid=mid+Math.imul(al4,bh8)|0;mid=mid+Math.imul(ah4,bl8)|0;hi=hi+Math.imul(ah4,bh8)|0;lo=lo+Math.imul(al3,bl9)|0;mid=mid+Math.imul(al3,bh9)|0;mid=mid+Math.imul(ah3,bl9)|0;hi=hi+Math.imul(ah3,bh9)|0;var w12=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w12>>>26)|0;w12&=67108863;lo=Math.imul(al9,bl4);mid=Math.imul(al9,bh4);mid=mid+Math.imul(ah9,bl4)|0;hi=Math.imul(ah9,bh4);lo=lo+Math.imul(al8,bl5)|0;mid=mid+Math.imul(al8,bh5)|0;mid=mid+Math.imul(ah8,bl5)|0;hi=hi+Math.imul(ah8,bh5)|0;lo=lo+Math.imul(al7,bl6)|0;mid=mid+Math.imul(al7,bh6)|0;mid=mid+Math.imul(ah7,bl6)|0;hi=hi+Math.imul(ah7,bh6)|0;lo=lo+Math.imul(al6,bl7)|0;mid=mid+Math.imul(al6,bh7)|0;mid=mid+Math.imul(ah6,bl7)|0;hi=hi+Math.imul(ah6,bh7)|0;lo=lo+Math.imul(al5,bl8)|0;mid=mid+Math.imul(al5,bh8)|0;mid=mid+Math.imul(ah5,bl8)|0;hi=hi+Math.imul(ah5,bh8)|0;lo=lo+Math.imul(al4,bl9)|0;mid=mid+Math.imul(al4,bh9)|0;mid=mid+Math.imul(ah4,bl9)|0;hi=hi+Math.imul(ah4,bh9)|0;var w13=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w13>>>26)|0;w13&=67108863;lo=Math.imul(al9,bl5);mid=Math.imul(al9,bh5);mid=mid+Math.imul(ah9,bl5)|0;hi=Math.imul(ah9,bh5);lo=lo+Math.imul(al8,bl6)|0;mid=mid+Math.imul(al8,bh6)|0;mid=mid+Math.imul(ah8,bl6)|0;hi=hi+Math.imul(ah8,bh6)|0;lo=lo+Math.imul(al7,bl7)|0;mid=mid+Math.imul(al7,bh7)|0;mid=mid+Math.imul(ah7,bl7)|0;hi=hi+Math.imul(ah7,bh7)|0;lo=lo+Math.imul(al6,bl8)|0;mid=mid+Math.imul(al6,bh8)|0;mid=mid+Math.imul(ah6,bl8)|0;hi=hi+Math.imul(ah6,bh8)|0;lo=lo+Math.imul(al5,bl9)|0;mid=mid+Math.imul(al5,bh9)|0;mid=mid+Math.imul(ah5,bl9)|0;hi=hi+Math.imul(ah5,bh9)|0;var w14=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w14>>>26)|0;w14&=67108863;lo=Math.imul(al9,bl6);mid=Math.imul(al9,bh6);mid=mid+Math.imul(ah9,bl6)|0;hi=Math.imul(ah9,bh6);lo=lo+Math.imul(al8,bl7)|0;mid=mid+Math.imul(al8,bh7)|0;mid=mid+Math.imul(ah8,bl7)|0;hi=hi+Math.imul(ah8,bh7)|0;lo=lo+Math.imul(al7,bl8)|0;mid=mid+Math.imul(al7,bh8)|0;mid=mid+Math.imul(ah7,bl8)|0;hi=hi+Math.imul(ah7,bh8)|0;lo=lo+Math.imul(al6,bl9)|0;mid=mid+Math.imul(al6,bh9)|0;mid=mid+Math.imul(ah6,bl9)|0;hi=hi+Math.imul(ah6,bh9)|0;var w15=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w15>>>26)|0;w15&=67108863;lo=Math.imul(al9,bl7);mid=Math.imul(al9,bh7);mid=mid+Math.imul(ah9,bl7)|0;hi=Math.imul(ah9,bh7);lo=lo+Math.imul(al8,bl8)|0;mid=mid+Math.imul(al8,bh8)|0;mid=mid+Math.imul(ah8,bl8)|0;hi=hi+Math.imul(ah8,bh8)|0;lo=lo+Math.imul(al7,bl9)|0;mid=mid+Math.imul(al7,bh9)|0;mid=mid+Math.imul(ah7,bl9)|0;hi=hi+Math.imul(ah7,bh9)|0;var w16=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w16>>>26)|0;w16&=67108863;lo=Math.imul(al9,bl8);mid=Math.imul(al9,bh8);mid=mid+Math.imul(ah9,bl8)|0;hi=Math.imul(ah9,bh8);lo=lo+Math.imul(al8,bl9)|0;mid=mid+Math.imul(al8,bh9)|0;mid=mid+Math.imul(ah8,bl9)|0;hi=hi+Math.imul(ah8,bh9)|0;var w17=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w17>>>26)|0;w17&=67108863;lo=Math.imul(al9,bl9);mid=Math.imul(al9,bh9);mid=mid+Math.imul(ah9,bl9)|0;hi=Math.imul(ah9,bh9);var w18=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w18>>>26)|0;w18&=67108863;o[0]=w0;o[1]=w1;o[2]=w2;o[3]=w3;o[4]=w4;o[5]=w5;o[6]=w6;o[7]=w7;o[8]=w8;o[9]=w9;o[10]=w10;o[11]=w11;o[12]=w12;o[13]=w13;o[14]=w14;o[15]=w15;o[16]=w16;o[17]=w17;o[18]=w18;if(c!==0){o[19]=c;out.length++}return out};if(!Math.imul){comb10MulTo=smallMulTo}function bigMulTo(self,num,out){out.negative=num.negative^self.negative;out.length=self.length+num.length;var carry=0;var hncarry=0;for(var k=0;k>>26)|0;hncarry+=ncarry>>>26;ncarry&=67108863}out.words[k]=rword;carry=ncarry;ncarry=hncarry}if(carry!==0){out.words[k]=carry}else{out.length--}return out._strip()}function jumboMulTo(self,num,out){return bigMulTo(self,num,out)}BN.prototype.mulTo=function mulTo(num,out){var res;var len=this.length+num.length;if(this.length===10&&num.length===10){res=comb10MulTo(this,num,out)}else if(len<63){res=smallMulTo(this,num,out)}else if(len<1024){res=bigMulTo(this,num,out)}else{res=jumboMulTo(this,num,out)}return res};function FFTM(x,y){this.x=x;this.y=y}FFTM.prototype.makeRBT=function makeRBT(N){var t=new Array(N);var l=BN.prototype._countBits(N)-1;for(var i=0;i>=1}return rb};FFTM.prototype.permute=function permute(rbt,rws,iws,rtws,itws,N){for(var i=0;i>>1){i++}return 1<>>13;rws[2*i+1]=carry&8191;carry=carry>>>13}for(i=2*len;i>=26;carry+=w/67108864|0;carry+=lo>>>26;this.words[i]=lo&67108863}if(carry!==0){this.words[i]=carry;this.length++}return isNegNum?this.ineg():this};BN.prototype.muln=function muln(num){return this.clone().imuln(num)};BN.prototype.sqr=function sqr(){return this.mul(this)};BN.prototype.isqr=function isqr(){return this.imul(this.clone())};BN.prototype.pow=function pow(num){var w=toBitArray(num);if(w.length===0)return new BN(1);var res=this;for(var i=0;i=0);var r=bits%26;var s=(bits-r)/26;var carryMask=67108863>>>26-r<<26-r;var i;if(r!==0){var carry=0;for(i=0;i>>26-r}if(carry){this.words[i]=carry;this.length++}}if(s!==0){for(i=this.length-1;i>=0;i--){this.words[i+s]=this.words[i]}for(i=0;i=0);var h;if(hint){h=(hint-hint%26)/26}else{h=0}var r=bits%26;var s=Math.min((bits-r)/26,this.length);var mask=67108863^67108863>>>r<s){this.length-=s;for(i=0;i=0&&(carry!==0||i>=h);i--){var word=this.words[i]|0;this.words[i]=carry<<26-r|word>>>r;carry=word&mask}if(maskedWords&&carry!==0){maskedWords.words[maskedWords.length++]=carry}if(this.length===0){this.words[0]=0;this.length=1}return this._strip()};BN.prototype.ishrn=function ishrn(bits,hint,extended){assert(this.negative===0);return this.iushrn(bits,hint,extended)};BN.prototype.shln=function shln(bits){return this.clone().ishln(bits)};BN.prototype.ushln=function ushln(bits){return this.clone().iushln(bits)};BN.prototype.shrn=function shrn(bits){return this.clone().ishrn(bits)};BN.prototype.ushrn=function ushrn(bits){return this.clone().iushrn(bits)};BN.prototype.testn=function testn(bit){assert(typeof bit==="number"&&bit>=0);var r=bit%26;var s=(bit-r)/26;var q=1<=0);var r=bits%26;var s=(bits-r)/26;assert(this.negative===0,"imaskn works only with positive numbers");if(this.length<=s){return this}if(r!==0){s++}this.length=Math.min(s,this.length);if(r!==0){var mask=67108863^67108863>>>r<=67108864;i++){this.words[i]-=67108864;if(i===this.length-1){this.words[i+1]=1}else{this.words[i+1]++}}this.length=Math.max(this.length,i+1);return this};BN.prototype.isubn=function isubn(num){assert(typeof num==="number");assert(num<67108864);if(num<0)return this.iaddn(-num);if(this.negative!==0){this.negative=0;this.iaddn(num);this.negative=1;return this}this.words[0]-=num;if(this.length===1&&this.words[0]<0){this.words[0]=-this.words[0];this.negative=1}else{for(var i=0;i>26)-(right/67108864|0);this.words[i+shift]=w&67108863}for(;i>26;this.words[i+shift]=w&67108863}if(carry===0)return this._strip();assert(carry===-1);carry=0;for(i=0;i>26;this.words[i]=w&67108863}this.negative=1;return this._strip()};BN.prototype._wordDiv=function _wordDiv(num,mode){var shift=this.length-num.length;var a=this.clone();var b=num;var bhi=b.words[b.length-1]|0;var bhiBits=this._countBits(bhi);shift=26-bhiBits;if(shift!==0){b=b.ushln(shift);a.iushln(shift);bhi=b.words[b.length-1]|0}var m=a.length-b.length;var q;if(mode!=="mod"){q=new BN(null);q.length=m+1;q.words=new Array(q.length);for(var i=0;i=0;j--){var qj=(a.words[b.length+j]|0)*67108864+(a.words[b.length+j-1]|0);qj=Math.min(qj/bhi|0,67108863);a._ishlnsubmul(b,qj,j);while(a.negative!==0){qj--;a.negative=0;a._ishlnsubmul(b,1,j);if(!a.isZero()){a.negative^=1}}if(q){q.words[j]=qj}}if(q){q._strip()}a._strip();if(mode!=="div"&&shift!==0){a.iushrn(shift)}return{div:q||null,mod:a}};BN.prototype.divmod=function divmod(num,mode,positive){assert(!num.isZero());if(this.isZero()){return{div:new BN(0),mod:new BN(0)}}var div,mod,res;if(this.negative!==0&&num.negative===0){res=this.neg().divmod(num,mode);if(mode!=="mod"){div=res.div.neg()}if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.iadd(num)}}return{div:div,mod:mod}}if(this.negative===0&&num.negative!==0){res=this.divmod(num.neg(),mode);if(mode!=="mod"){div=res.div.neg()}return{div:div,mod:res.mod}}if((this.negative&num.negative)!==0){res=this.neg().divmod(num.neg(),mode);if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.isub(num)}}return{div:res.div,mod:mod}}if(num.length>this.length||this.cmp(num)<0){return{div:new BN(0),mod:this}}if(num.length===1){if(mode==="div"){return{div:this.divn(num.words[0]),mod:null}}if(mode==="mod"){return{div:null,mod:new BN(this.modrn(num.words[0]))}}return{div:this.divn(num.words[0]),mod:new BN(this.modrn(num.words[0]))}}return this._wordDiv(num,mode)};BN.prototype.div=function div(num){return this.divmod(num,"div",false).div};BN.prototype.mod=function mod(num){return this.divmod(num,"mod",false).mod};BN.prototype.umod=function umod(num){return this.divmod(num,"mod",true).mod};BN.prototype.divRound=function divRound(num){var dm=this.divmod(num);if(dm.mod.isZero())return dm.div;var mod=dm.div.negative!==0?dm.mod.isub(num):dm.mod;var half=num.ushrn(1);var r2=num.andln(1);var cmp=mod.cmp(half);if(cmp<0||r2===1&&cmp===0)return dm.div;return dm.div.negative!==0?dm.div.isubn(1):dm.div.iaddn(1)};BN.prototype.modrn=function modrn(num){var isNegNum=num<0;if(isNegNum)num=-num;assert(num<=67108863);var p=(1<<26)%num;var acc=0;for(var i=this.length-1;i>=0;i--){acc=(p*acc+(this.words[i]|0))%num}return isNegNum?-acc:acc};BN.prototype.modn=function modn(num){return this.modrn(num)};BN.prototype.idivn=function idivn(num){var isNegNum=num<0;if(isNegNum)num=-num;assert(num<=67108863);var carry=0;for(var i=this.length-1;i>=0;i--){var w=(this.words[i]|0)+carry*67108864;this.words[i]=w/num|0;carry=w%num}this._strip();return isNegNum?this.ineg():this};BN.prototype.divn=function divn(num){return this.clone().idivn(num)};BN.prototype.egcd=function egcd(p){assert(p.negative===0);assert(!p.isZero());var x=this;var y=p.clone();if(x.negative!==0){x=x.umod(p)}else{x=x.clone()}var A=new BN(1);var B=new BN(0);var C=new BN(0);var D=new BN(1);var g=0;while(x.isEven()&&y.isEven()){x.iushrn(1);y.iushrn(1);++g}var yp=y.clone();var xp=x.clone();while(!x.isZero()){for(var i=0,im=1;(x.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){x.iushrn(i);while(i-- >0){if(A.isOdd()||B.isOdd()){A.iadd(yp);B.isub(xp)}A.iushrn(1);B.iushrn(1)}}for(var j=0,jm=1;(y.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){y.iushrn(j);while(j-- >0){if(C.isOdd()||D.isOdd()){C.iadd(yp);D.isub(xp)}C.iushrn(1);D.iushrn(1)}}if(x.cmp(y)>=0){x.isub(y);A.isub(C);B.isub(D)}else{y.isub(x);C.isub(A);D.isub(B)}}return{a:C,b:D,gcd:y.iushln(g)}};BN.prototype._invmp=function _invmp(p){assert(p.negative===0);assert(!p.isZero());var a=this;var b=p.clone();if(a.negative!==0){a=a.umod(p)}else{a=a.clone()}var x1=new BN(1);var x2=new BN(0);var delta=b.clone();while(a.cmpn(1)>0&&b.cmpn(1)>0){for(var i=0,im=1;(a.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){a.iushrn(i);while(i-- >0){if(x1.isOdd()){x1.iadd(delta)}x1.iushrn(1)}}for(var j=0,jm=1;(b.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){b.iushrn(j);while(j-- >0){if(x2.isOdd()){x2.iadd(delta)}x2.iushrn(1)}}if(a.cmp(b)>=0){a.isub(b);x1.isub(x2)}else{b.isub(a);x2.isub(x1)}}var res;if(a.cmpn(1)===0){res=x1}else{res=x2}if(res.cmpn(0)<0){res.iadd(p)}return res};BN.prototype.gcd=function gcd(num){if(this.isZero())return num.abs();if(num.isZero())return this.abs();var a=this.clone();var b=num.clone();a.negative=0;b.negative=0;for(var shift=0;a.isEven()&&b.isEven();shift++){a.iushrn(1);b.iushrn(1)}do{while(a.isEven()){a.iushrn(1)}while(b.isEven()){b.iushrn(1)}var r=a.cmp(b);if(r<0){var t=a;a=b;b=t}else if(r===0||b.cmpn(1)===0){break}a.isub(b)}while(true);return b.iushln(shift)};BN.prototype.invm=function invm(num){return this.egcd(num).a.umod(num)};BN.prototype.isEven=function isEven(){return(this.words[0]&1)===0};BN.prototype.isOdd=function isOdd(){return(this.words[0]&1)===1};BN.prototype.andln=function andln(num){return this.words[0]&num};BN.prototype.bincn=function bincn(bit){assert(typeof bit==="number");var r=bit%26;var s=(bit-r)/26;var q=1<>>26;w&=67108863;this.words[i]=w}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.isZero=function isZero(){return this.length===1&&this.words[0]===0};BN.prototype.cmpn=function cmpn(num){var negative=num<0;if(this.negative!==0&&!negative)return-1;if(this.negative===0&&negative)return 1;this._strip();var res;if(this.length>1){res=1}else{if(negative){num=-num}assert(num<=67108863,"Number is too big");var w=this.words[0]|0;res=w===num?0:wnum.length)return 1;if(this.length=0;i--){var a=this.words[i]|0;var b=num.words[i]|0;if(a===b)continue;if(ab){res=1}break}return res};BN.prototype.gtn=function gtn(num){return this.cmpn(num)===1};BN.prototype.gt=function gt(num){return this.cmp(num)===1};BN.prototype.gten=function gten(num){return this.cmpn(num)>=0};BN.prototype.gte=function gte(num){return this.cmp(num)>=0};BN.prototype.ltn=function ltn(num){return this.cmpn(num)===-1};BN.prototype.lt=function lt(num){return this.cmp(num)===-1};BN.prototype.lten=function lten(num){return this.cmpn(num)<=0};BN.prototype.lte=function lte(num){return this.cmp(num)<=0};BN.prototype.eqn=function eqn(num){return this.cmpn(num)===0};BN.prototype.eq=function eq(num){return this.cmp(num)===0};BN.red=function red(num){return new Red(num)};BN.prototype.toRed=function toRed(ctx){assert(!this.red,"Already a number in reduction context");assert(this.negative===0,"red works only with positives");return ctx.convertTo(this)._forceRed(ctx)};BN.prototype.fromRed=function fromRed(){assert(this.red,"fromRed works only with numbers in reduction context");return this.red.convertFrom(this)};BN.prototype._forceRed=function _forceRed(ctx){this.red=ctx;return this};BN.prototype.forceRed=function forceRed(ctx){assert(!this.red,"Already a number in reduction context");return this._forceRed(ctx)};BN.prototype.redAdd=function redAdd(num){assert(this.red,"redAdd works only with red numbers");return this.red.add(this,num)};BN.prototype.redIAdd=function redIAdd(num){assert(this.red,"redIAdd works only with red numbers");return this.red.iadd(this,num)};BN.prototype.redSub=function redSub(num){assert(this.red,"redSub works only with red numbers");return this.red.sub(this,num)};BN.prototype.redISub=function redISub(num){assert(this.red,"redISub works only with red numbers");return this.red.isub(this,num)};BN.prototype.redShl=function redShl(num){assert(this.red,"redShl works only with red numbers");return this.red.shl(this,num)};BN.prototype.redMul=function redMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.mul(this,num)};BN.prototype.redIMul=function redIMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.imul(this,num)};BN.prototype.redSqr=function redSqr(){assert(this.red,"redSqr works only with red numbers");this.red._verify1(this);return this.red.sqr(this)};BN.prototype.redISqr=function redISqr(){assert(this.red,"redISqr works only with red numbers");this.red._verify1(this);return this.red.isqr(this)};BN.prototype.redSqrt=function redSqrt(){assert(this.red,"redSqrt works only with red numbers");this.red._verify1(this);return this.red.sqrt(this)};BN.prototype.redInvm=function redInvm(){assert(this.red,"redInvm works only with red numbers");this.red._verify1(this);return this.red.invm(this)};BN.prototype.redNeg=function redNeg(){assert(this.red,"redNeg works only with red numbers");this.red._verify1(this);return this.red.neg(this)};BN.prototype.redPow=function redPow(num){assert(this.red&&!num.red,"redPow(normalNum)");this.red._verify1(this);return this.red.pow(this,num)};var primes={k256:null,p224:null,p192:null,p25519:null};function MPrime(name,p){this.name=name;this.p=new BN(p,16);this.n=this.p.bitLength();this.k=new BN(1).iushln(this.n).isub(this.p);this.tmp=this._tmp()}MPrime.prototype._tmp=function _tmp(){var tmp=new BN(null);tmp.words=new Array(Math.ceil(this.n/13));return tmp};MPrime.prototype.ireduce=function ireduce(num){var r=num;var rlen;do{this.split(r,this.tmp);r=this.imulK(r);r=r.iadd(this.tmp);rlen=r.bitLength()}while(rlen>this.n);var cmp=rlen0){r.isub(this.p)}else{if(r.strip!==undefined){r.strip()}else{r._strip()}}return r};MPrime.prototype.split=function split(input,out){input.iushrn(this.n,0,out)};MPrime.prototype.imulK=function imulK(num){return num.imul(this.k)};function K256(){MPrime.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}inherits(K256,MPrime);K256.prototype.split=function split(input,output){var mask=4194303;var outLen=Math.min(input.length,9);for(var i=0;i>>22;prev=next}prev>>>=22;input.words[i-10]=prev;if(prev===0&&input.length>10){input.length-=10}else{input.length-=9}};K256.prototype.imulK=function imulK(num){num.words[num.length]=0;num.words[num.length+1]=0;num.length+=2;var lo=0;for(var i=0;i>>=26;num.words[i]=lo;carry=hi}if(carry!==0){num.words[num.length++]=carry}return num};BN._prime=function prime(name){if(primes[name])return primes[name];var prime;if(name==="k256"){prime=new K256}else if(name==="p224"){prime=new P224}else if(name==="p192"){prime=new P192}else if(name==="p25519"){prime=new P25519}else{throw new Error("Unknown prime "+name)}primes[name]=prime;return prime};function Red(m){if(typeof m==="string"){var prime=BN._prime(m);this.m=prime.p;this.prime=prime}else{assert(m.gtn(1),"modulus must be greater than 1");this.m=m;this.prime=null}}Red.prototype._verify1=function _verify1(a){assert(a.negative===0,"red works only with positives");assert(a.red,"red works only with red numbers")};Red.prototype._verify2=function _verify2(a,b){assert((a.negative|b.negative)===0,"red works only with positives");assert(a.red&&a.red===b.red,"red works only with red numbers")};Red.prototype.imod=function imod(a){if(this.prime)return this.prime.ireduce(a)._forceRed(this);move(a,a.umod(this.m)._forceRed(this));return a};Red.prototype.neg=function neg(a){if(a.isZero()){return a.clone()}return this.m.sub(a)._forceRed(this)};Red.prototype.add=function add(a,b){this._verify2(a,b);var res=a.add(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res._forceRed(this)};Red.prototype.iadd=function iadd(a,b){this._verify2(a,b);var res=a.iadd(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res};Red.prototype.sub=function sub(a,b){this._verify2(a,b);var res=a.sub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res._forceRed(this)};Red.prototype.isub=function isub(a,b){this._verify2(a,b);var res=a.isub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res};Red.prototype.shl=function shl(a,num){this._verify1(a);return this.imod(a.ushln(num))};Red.prototype.imul=function imul(a,b){this._verify2(a,b);return this.imod(a.imul(b))};Red.prototype.mul=function mul(a,b){this._verify2(a,b);return this.imod(a.mul(b))};Red.prototype.isqr=function isqr(a){return this.imul(a,a.clone())};Red.prototype.sqr=function sqr(a){return this.mul(a,a)};Red.prototype.sqrt=function sqrt(a){if(a.isZero())return a.clone();var mod3=this.m.andln(3);assert(mod3%2===1);if(mod3===3){var pow=this.m.add(new BN(1)).iushrn(2);return this.pow(a,pow)}var q=this.m.subn(1);var s=0;while(!q.isZero()&&q.andln(1)===0){s++;q.iushrn(1)}assert(!q.isZero());var one=new BN(1).toRed(this);var nOne=one.redNeg();var lpow=this.m.subn(1).iushrn(1);var z=this.m.bitLength();z=new BN(2*z*z).toRed(this);while(this.pow(z,lpow).cmp(nOne)!==0){z.redIAdd(nOne)}var c=this.pow(z,q);var r=this.pow(a,q.addn(1).iushrn(1));var t=this.pow(a,q);var m=s;while(t.cmp(one)!==0){var tmp=t;for(var i=0;tmp.cmp(one)!==0;i++){tmp=tmp.redSqr()}assert(i=0;i--){var word=num.words[i];for(var j=start-1;j>=0;j--){var bit=word>>j&1;if(res!==wnd[0]){res=this.sqr(res)}if(bit===0&¤t===0){currentLen=0;continue}current<<=1;current|=bit;currentLen++;if(currentLen!==windowSize&&(i!==0||j!==0))continue;res=this.mul(res,wnd[current]);currentLen=0;current=0}start=26}return res};Red.prototype.convertTo=function convertTo(num){var r=num.umod(this.m);return r===num?r.clone():r};Red.prototype.convertFrom=function convertFrom(num){var res=num.clone();res.red=null;return res};BN.mont=function mont(num){return new Mont(num)};function Mont(m){Red.call(this,m);this.shift=this.m.bitLength();if(this.shift%26!==0){this.shift+=26-this.shift%26}this.r=new BN(1).iushln(this.shift);this.r2=this.imod(this.r.sqr());this.rinv=this.r._invmp(this.m);this.minv=this.rinv.mul(this.r).isubn(1).div(this.m);this.minv=this.minv.umod(this.r);this.minv=this.r.sub(this.minv)}inherits(Mont,Red);Mont.prototype.convertTo=function convertTo(num){return this.imod(num.ushln(this.shift))};Mont.prototype.convertFrom=function convertFrom(num){var r=this.imod(num.mul(this.rinv));r.red=null;return r};Mont.prototype.imul=function imul(a,b){if(a.isZero()||b.isZero()){a.words[0]=0;a.length=1;return a}var t=a.imul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.mul=function mul(a,b){if(a.isZero()||b.isZero())return new BN(0)._forceRed(this);var t=a.mul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.invm=function invm(a){var res=this.imod(a._invmp(this.m).mul(this.r2));return res._forceRed(this)}})(typeof module==="undefined"||module,this)},{buffer:115}],114:[function(require,module,exports){arguments[4][50][0].apply(exports,arguments)},{crypto:115,dup:50}],115:[function(require,module,exports){},{}],116:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;function asUInt32Array(buf){if(!Buffer.isBuffer(buf))buf=Buffer.from(buf);var len=buf.length/4|0;var out=new Array(len);for(var i=0;i>>24]^SUB_MIX1[s1>>>16&255]^SUB_MIX2[s2>>>8&255]^SUB_MIX3[s3&255]^keySchedule[ksRow++];t1=SUB_MIX0[s1>>>24]^SUB_MIX1[s2>>>16&255]^SUB_MIX2[s3>>>8&255]^SUB_MIX3[s0&255]^keySchedule[ksRow++];t2=SUB_MIX0[s2>>>24]^SUB_MIX1[s3>>>16&255]^SUB_MIX2[s0>>>8&255]^SUB_MIX3[s1&255]^keySchedule[ksRow++];t3=SUB_MIX0[s3>>>24]^SUB_MIX1[s0>>>16&255]^SUB_MIX2[s1>>>8&255]^SUB_MIX3[s2&255]^keySchedule[ksRow++];s0=t0;s1=t1;s2=t2;s3=t3}t0=(SBOX[s0>>>24]<<24|SBOX[s1>>>16&255]<<16|SBOX[s2>>>8&255]<<8|SBOX[s3&255])^keySchedule[ksRow++];t1=(SBOX[s1>>>24]<<24|SBOX[s2>>>16&255]<<16|SBOX[s3>>>8&255]<<8|SBOX[s0&255])^keySchedule[ksRow++];t2=(SBOX[s2>>>24]<<24|SBOX[s3>>>16&255]<<16|SBOX[s0>>>8&255]<<8|SBOX[s1&255])^keySchedule[ksRow++];t3=(SBOX[s3>>>24]<<24|SBOX[s0>>>16&255]<<16|SBOX[s1>>>8&255]<<8|SBOX[s2&255])^keySchedule[ksRow++];t0=t0>>>0;t1=t1>>>0;t2=t2>>>0;t3=t3>>>0;return[t0,t1,t2,t3]}var RCON=[0,1,2,4,8,16,32,64,128,27,54];var G=function(){var d=new Array(256);for(var j=0;j<256;j++){if(j<128){d[j]=j<<1}else{d[j]=j<<1^283}}var SBOX=[];var INV_SBOX=[];var SUB_MIX=[[],[],[],[]];var INV_SUB_MIX=[[],[],[],[]];var x=0;var xi=0;for(var i=0;i<256;++i){var sx=xi^xi<<1^xi<<2^xi<<3^xi<<4;sx=sx>>>8^sx&255^99;SBOX[x]=sx;INV_SBOX[sx]=x;var x2=d[x];var x4=d[x2];var x8=d[x4];var t=d[sx]*257^sx*16843008;SUB_MIX[0][x]=t<<24|t>>>8;SUB_MIX[1][x]=t<<16|t>>>16;SUB_MIX[2][x]=t<<8|t>>>24;SUB_MIX[3][x]=t;t=x8*16843009^x4*65537^x2*257^x*16843008;INV_SUB_MIX[0][sx]=t<<24|t>>>8;INV_SUB_MIX[1][sx]=t<<16|t>>>16;INV_SUB_MIX[2][sx]=t<<8|t>>>24;INV_SUB_MIX[3][sx]=t;if(x===0){x=xi=1}else{x=x2^d[d[d[x8^x2]]];xi^=d[d[xi]]}}return{SBOX:SBOX,INV_SBOX:INV_SBOX,SUB_MIX:SUB_MIX,INV_SUB_MIX:INV_SUB_MIX}}();function AES(key){this._key=asUInt32Array(key);this._reset()}AES.blockSize=4*4;AES.keySize=256/8;AES.prototype.blockSize=AES.blockSize;AES.prototype.keySize=AES.keySize;AES.prototype._reset=function(){var keyWords=this._key;var keySize=keyWords.length;var nRounds=keySize+6;var ksRows=(nRounds+1)*4;var keySchedule=[];for(var k=0;k>>24;t=G.SBOX[t>>>24]<<24|G.SBOX[t>>>16&255]<<16|G.SBOX[t>>>8&255]<<8|G.SBOX[t&255];t^=RCON[k/keySize|0]<<24}else if(keySize>6&&k%keySize===4){t=G.SBOX[t>>>24]<<24|G.SBOX[t>>>16&255]<<16|G.SBOX[t>>>8&255]<<8|G.SBOX[t&255]}keySchedule[k]=keySchedule[k-keySize]^t}var invKeySchedule=[];for(var ik=0;ik>>24]]^G.INV_SUB_MIX[1][G.SBOX[tt>>>16&255]]^G.INV_SUB_MIX[2][G.SBOX[tt>>>8&255]]^G.INV_SUB_MIX[3][G.SBOX[tt&255]]}}this._nRounds=nRounds;this._keySchedule=keySchedule;this._invKeySchedule=invKeySchedule};AES.prototype.encryptBlockRaw=function(M){M=asUInt32Array(M);return cryptBlock(M,this._keySchedule,G.SUB_MIX,G.SBOX,this._nRounds)};AES.prototype.encryptBlock=function(M){var out=this.encryptBlockRaw(M);var buf=Buffer.allocUnsafe(16);buf.writeUInt32BE(out[0],0);buf.writeUInt32BE(out[1],4);buf.writeUInt32BE(out[2],8);buf.writeUInt32BE(out[3],12);return buf};AES.prototype.decryptBlock=function(M){M=asUInt32Array(M);var m1=M[1];M[1]=M[3];M[3]=m1;var out=cryptBlock(M,this._invKeySchedule,G.INV_SUB_MIX,G.INV_SBOX,this._nRounds);var buf=Buffer.allocUnsafe(16);buf.writeUInt32BE(out[0],0);buf.writeUInt32BE(out[3],4);buf.writeUInt32BE(out[2],8);buf.writeUInt32BE(out[1],12);return buf};AES.prototype.scrub=function(){scrubVec(this._keySchedule);scrubVec(this._invKeySchedule);scrubVec(this._key)};module.exports.AES=AES},{"safe-buffer":261}],117:[function(require,module,exports){var aes=require("./aes");var Buffer=require("safe-buffer").Buffer;var Transform=require("cipher-base");var inherits=require("inherits");var GHASH=require("./ghash");var xor=require("buffer-xor");var incr32=require("./incr32");function xorTest(a,b){var out=0;if(a.length!==b.length)out++;var len=Math.min(a.length,b.length);for(var i=0;i16){out=this.cache.slice(0,16);this.cache=this.cache.slice(16);return out}}else{if(this.cache.length>=16){out=this.cache.slice(0,16);this.cache=this.cache.slice(16);return out}}return null};Splitter.prototype.flush=function(){if(this.cache.length)return this.cache};function unpad(last){var padded=last[15];if(padded<1||padded>16){throw new Error("unable to decrypt data")}var i=-1;while(++i15){var out=this.cache.slice(0,16);this.cache=this.cache.slice(16);return out}return null};Splitter.prototype.flush=function(){var len=16-this.cache.length;var padBuff=Buffer.allocUnsafe(len);var i=-1;while(++i>>0,0);buf.writeUInt32BE(out[1]>>>0,4);buf.writeUInt32BE(out[2]>>>0,8);buf.writeUInt32BE(out[3]>>>0,12);return buf}function GHASH(key){this.h=key;this.state=Buffer.alloc(16,0);this.cache=Buffer.allocUnsafe(0)}GHASH.prototype.ghash=function(block){var i=-1;while(++i0;j--){Vi[j]=Vi[j]>>>1|(Vi[j-1]&1)<<31}Vi[0]=Vi[0]>>>1;if(lsbVi){Vi[0]=Vi[0]^225<<24}}this.state=fromArray(Zi)};GHASH.prototype.update=function(buf){this.cache=Buffer.concat([this.cache,buf]);var chunk;while(this.cache.length>=16){chunk=this.cache.slice(0,16);this.cache=this.cache.slice(16);this.ghash(chunk)}};GHASH.prototype.final=function(abl,bl){if(this.cache.length){this.ghash(Buffer.concat([this.cache,ZEROES],16))}this.ghash(fromArray([0,abl,0,bl]));return this.state};module.exports=GHASH},{"safe-buffer":261}],122:[function(require,module,exports){function incr32(iv){var len=iv.length;var item;while(len--){item=iv.readUInt8(len);if(item===255){iv.writeUInt8(0,len)}else{item++;iv.writeUInt8(item,len);break}}}module.exports=incr32},{}],123:[function(require,module,exports){var xor=require("buffer-xor");exports.encrypt=function(self,block){var data=xor(block,self._prev);self._prev=self._cipher.encryptBlock(data);return self._prev};exports.decrypt=function(self,block){var pad=self._prev;self._prev=block;var out=self._cipher.decryptBlock(block);return xor(out,pad)}},{"buffer-xor":158}],124:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;var xor=require("buffer-xor");function encryptStart(self,data,decrypt){var len=data.length;var out=xor(data,self._cache);self._cache=self._cache.slice(len);self._prev=Buffer.concat([self._prev,decrypt?data:out]);return out}exports.encrypt=function(self,data,decrypt){var out=Buffer.allocUnsafe(0);var len;while(data.length){if(self._cache.length===0){self._cache=self._cipher.encryptBlock(self._prev);self._prev=Buffer.allocUnsafe(0)}if(self._cache.length<=data.length){len=self._cache.length;out=Buffer.concat([out,encryptStart(self,data.slice(0,len),decrypt)]);data=data.slice(len)}else{out=Buffer.concat([out,encryptStart(self,data,decrypt)]);break}}return out}},{"buffer-xor":158,"safe-buffer":261}],125:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;function encryptByte(self,byteParam,decrypt){var pad;var i=-1;var len=8;var out=0;var bit,value;while(++i>i%8;self._prev=shiftIn(self._prev,decrypt?bit:value)}return out}function shiftIn(buffer,value){var len=buffer.length;var i=-1;var out=Buffer.allocUnsafe(buffer.length);buffer=Buffer.concat([buffer,Buffer.from([value])]);while(++i>7}return out}exports.encrypt=function(self,chunk,decrypt){var len=chunk.length;var out=Buffer.allocUnsafe(len);var i=-1;while(++i=0||!r.umod(priv.prime1)||!r.umod(priv.prime2));return r}function crt(msg,priv){var blinds=blind(priv);var len=priv.modulus.byteLength();var blinded=new BN(msg).mul(blinds.blinder).umod(priv.modulus);var c1=blinded.toRed(BN.mont(priv.prime1));var c2=blinded.toRed(BN.mont(priv.prime2));var qinv=priv.coefficient;var p=priv.prime1;var q=priv.prime2;var m1=c1.redPow(priv.exponent1).fromRed();var m2=c2.redPow(priv.exponent2).fromRed();var h=m1.isub(m2).imul(qinv).umod(p).imul(q);return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(Buffer,"be",len)}crt.getr=getr;module.exports=crt}).call(this)}).call(this,require("buffer").Buffer)},{"bn.js":113,buffer:159,randombytes:258}],137:[function(require,module,exports){module.exports=require("./browser/algorithms.json")},{"./browser/algorithms.json":138}],138:[function(require,module,exports){module.exports={sha224WithRSAEncryption:{sign:"rsa",hash:"sha224",id:"302d300d06096086480165030402040500041c"},"RSA-SHA224":{sign:"ecdsa/rsa",hash:"sha224",id:"302d300d06096086480165030402040500041c"},sha256WithRSAEncryption:{sign:"rsa",hash:"sha256",id:"3031300d060960864801650304020105000420"},"RSA-SHA256":{sign:"ecdsa/rsa",hash:"sha256",id:"3031300d060960864801650304020105000420"},sha384WithRSAEncryption:{sign:"rsa",hash:"sha384",id:"3041300d060960864801650304020205000430"},"RSA-SHA384":{sign:"ecdsa/rsa",hash:"sha384",id:"3041300d060960864801650304020205000430"},sha512WithRSAEncryption:{sign:"rsa",hash:"sha512",id:"3051300d060960864801650304020305000440"},"RSA-SHA512":{sign:"ecdsa/rsa",hash:"sha512",id:"3051300d060960864801650304020305000440"},"RSA-SHA1":{sign:"rsa",hash:"sha1",id:"3021300906052b0e03021a05000414"},"ecdsa-with-SHA1":{sign:"ecdsa",hash:"sha1",id:""},sha256:{sign:"ecdsa",hash:"sha256",id:""},sha224:{sign:"ecdsa",hash:"sha224",id:""},sha384:{sign:"ecdsa",hash:"sha384",id:""},sha512:{sign:"ecdsa",hash:"sha512",id:""},"DSA-SHA":{sign:"dsa",hash:"sha1",id:""},"DSA-SHA1":{sign:"dsa",hash:"sha1",id:""},DSA:{sign:"dsa",hash:"sha1",id:""},"DSA-WITH-SHA224":{sign:"dsa",hash:"sha224",id:""},"DSA-SHA224":{sign:"dsa",hash:"sha224",id:""},"DSA-WITH-SHA256":{sign:"dsa",hash:"sha256",id:""},"DSA-SHA256":{sign:"dsa",hash:"sha256",id:""},"DSA-WITH-SHA384":{sign:"dsa",hash:"sha384",id:""},"DSA-SHA384":{sign:"dsa",hash:"sha384",id:""},"DSA-WITH-SHA512":{sign:"dsa",hash:"sha512",id:""},"DSA-SHA512":{sign:"dsa",hash:"sha512",id:""},"DSA-RIPEMD160":{sign:"dsa",hash:"rmd160",id:""},ripemd160WithRSA:{sign:"rsa",hash:"rmd160",id:"3021300906052b2403020105000414"},"RSA-RIPEMD160":{sign:"rsa",hash:"rmd160",id:"3021300906052b2403020105000414"},md5WithRSAEncryption:{sign:"rsa",hash:"md5",id:"3020300c06082a864886f70d020505000410"},"RSA-MD5":{sign:"rsa",hash:"md5",id:"3020300c06082a864886f70d020505000410"}}},{}],139:[function(require,module,exports){module.exports={"1.3.132.0.10":"secp256k1","1.3.132.0.33":"p224","1.2.840.10045.3.1.1":"p192","1.2.840.10045.3.1.7":"p256","1.3.132.0.34":"p384","1.3.132.0.35":"p521"}},{}],140:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;var createHash=require("create-hash");var stream=require("readable-stream");var inherits=require("inherits");var sign=require("./sign");var verify=require("./verify");var algorithms=require("./algorithms.json");Object.keys(algorithms).forEach(function(key){algorithms[key].id=Buffer.from(algorithms[key].id,"hex");algorithms[key.toLowerCase()]=algorithms[key]});function Sign(algorithm){stream.Writable.call(this);var data=algorithms[algorithm];if(!data)throw new Error("Unknown message digest");this._hashType=data.hash;this._hash=createHash(data.hash);this._tag=data.id;this._signType=data.sign}inherits(Sign,stream.Writable);Sign.prototype._write=function _write(data,_,done){this._hash.update(data);done()};Sign.prototype.update=function update(data,enc){if(typeof data==="string")data=Buffer.from(data,enc);this._hash.update(data);return this};Sign.prototype.sign=function signMethod(key,enc){this.end();var hash=this._hash.digest();var sig=sign(hash,key,this._hashType,this._signType,this._tag);return enc?sig.toString(enc):sig};function Verify(algorithm){stream.Writable.call(this);var data=algorithms[algorithm];if(!data)throw new Error("Unknown message digest");this._hash=createHash(data.hash);this._tag=data.id;this._signType=data.sign}inherits(Verify,stream.Writable);Verify.prototype._write=function _write(data,_,done){this._hash.update(data);done()};Verify.prototype.update=function update(data,enc){if(typeof data==="string")data=Buffer.from(data,enc);this._hash.update(data);return this};Verify.prototype.verify=function verifyMethod(key,sig,enc){if(typeof sig==="string")sig=Buffer.from(sig,enc);this.end();var hash=this._hash.digest();return verify(sig,hash,key,this._signType,this._tag)};function createSign(algorithm){return new Sign(algorithm)}function createVerify(algorithm){return new Verify(algorithm)}module.exports={Sign:createSign,Verify:createVerify,createSign:createSign,createVerify:createVerify}},{"./algorithms.json":138,"./sign":141,"./verify":142,"create-hash":163,inherits:228,"readable-stream":157,"safe-buffer":261}],141:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;var createHmac=require("create-hmac");var crt=require("browserify-rsa");var EC=require("elliptic").ec;var BN=require("bn.js");var parseKeys=require("parse-asn1");var curves=require("./curves.json");function sign(hash,key,hashType,signType,tag){var priv=parseKeys(key);if(priv.curve){if(signType!=="ecdsa"&&signType!=="ecdsa/rsa")throw new Error("wrong private key type");return ecSign(hash,priv)}else if(priv.type==="dsa"){if(signType!=="dsa")throw new Error("wrong private key type");return dsaSign(hash,priv,hashType)}else{if(signType!=="rsa"&&signType!=="ecdsa/rsa")throw new Error("wrong private key type")}hash=Buffer.concat([tag,hash]);var len=priv.modulus.byteLength();var pad=[0,1];while(hash.length+pad.length+10)bits.ishrn(shift);return bits}function bits2octets(bits,q){bits=bits2int(bits,q);bits=bits.mod(q);var out=Buffer.from(bits.toArray());if(out.length=q)throw new Error("invalid sig")}module.exports=verify},{"./curves.json":139,"bn.js":113,elliptic:179,"parse-asn1":239,"safe-buffer":261}],143:[function(require,module,exports){"use strict";function _inheritsLoose(subClass,superClass){subClass.prototype=Object.create(superClass.prototype);subClass.prototype.constructor=subClass;subClass.__proto__=superClass}var codes={};function createErrorType(code,message,Base){if(!Base){Base=Error}function getMessage(arg1,arg2,arg3){if(typeof message==="string"){return message}else{return message(arg1,arg2,arg3)}}var NodeError=function(_Base){_inheritsLoose(NodeError,_Base);function NodeError(arg1,arg2,arg3){return _Base.call(this,getMessage(arg1,arg2,arg3))||this}return NodeError}(Base);NodeError.prototype.name=Base.name;NodeError.prototype.code=code;codes[code]=NodeError}function oneOf(expected,thing){if(Array.isArray(expected)){var len=expected.length;expected=expected.map(function(i){return String(i)});if(len>2){return"one of ".concat(thing," ").concat(expected.slice(0,len-1).join(", "),", or ")+expected[len-1]}else if(len===2){return"one of ".concat(thing," ").concat(expected[0]," or ").concat(expected[1])}else{return"of ".concat(thing," ").concat(expected[0])}}else{return"of ".concat(thing," ").concat(String(expected))}}function startsWith(str,search,pos){return str.substr(!pos||pos<0?0:+pos,search.length)===search}function endsWith(str,search,this_len){if(this_len===undefined||this_len>str.length){this_len=str.length}return str.substring(this_len-search.length,this_len)===search}function includes(str,search,start){if(typeof start!=="number"){start=0}if(start+search.length>str.length){return false}else{return str.indexOf(search,start)!==-1}}createErrorType("ERR_INVALID_OPT_VALUE",function(name,value){return'The value "'+value+'" is invalid for option "'+name+'"'},TypeError);createErrorType("ERR_INVALID_ARG_TYPE",function(name,expected,actual){var determiner;if(typeof expected==="string"&&startsWith(expected,"not ")){determiner="must not be";expected=expected.replace(/^not /,"")}else{determiner="must be"}var msg;if(endsWith(name," argument")){msg="The ".concat(name," ").concat(determiner," ").concat(oneOf(expected,"type"))}else{var type=includes(name,".")?"property":"argument";msg='The "'.concat(name,'" ').concat(type," ").concat(determiner," ").concat(oneOf(expected,"type"))}msg+=". Received type ".concat(typeof actual);return msg},TypeError);createErrorType("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");createErrorType("ERR_METHOD_NOT_IMPLEMENTED",function(name){return"The "+name+" method is not implemented"});createErrorType("ERR_STREAM_PREMATURE_CLOSE","Premature close");createErrorType("ERR_STREAM_DESTROYED",function(name){return"Cannot call "+name+" after a stream was destroyed"});createErrorType("ERR_MULTIPLE_CALLBACK","Callback called multiple times");createErrorType("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");createErrorType("ERR_STREAM_WRITE_AFTER_END","write after end");createErrorType("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);createErrorType("ERR_UNKNOWN_ENCODING",function(arg){return"Unknown encoding: "+arg},TypeError);createErrorType("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");module.exports.codes=codes},{}],144:[function(require,module,exports){(function(process){(function(){"use strict";var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj){keys.push(key)}return keys};module.exports=Duplex;var Readable=require("./_stream_readable");var Writable=require("./_stream_writable");require("inherits")(Duplex,Readable);{var keys=objectKeys(Writable.prototype);for(var v=0;v0){if(typeof chunk!=="string"&&!state.objectMode&&Object.getPrototypeOf(chunk)!==Buffer.prototype){chunk=_uint8ArrayToBuffer(chunk)}if(addToFront){if(state.endEmitted)errorOrDestroy(stream,new ERR_STREAM_UNSHIFT_AFTER_END_EVENT);else addChunk(stream,state,chunk,true)}else if(state.ended){errorOrDestroy(stream,new ERR_STREAM_PUSH_AFTER_EOF)}else if(state.destroyed){return false}else{state.reading=false;if(state.decoder&&!encoding){chunk=state.decoder.write(chunk);if(state.objectMode||chunk.length!==0)addChunk(stream,state,chunk,false);else maybeReadMore(stream,state)}else{addChunk(stream,state,chunk,false)}}}else if(!addToFront){state.reading=false;maybeReadMore(stream,state)}}return!state.ended&&(state.length=MAX_HWM){n=MAX_HWM}else{n--;n|=n>>>1;n|=n>>>2;n|=n>>>4;n|=n>>>8;n|=n>>>16;n++}return n}function howMuchToRead(n,state){if(n<=0||state.length===0&&state.ended)return 0;if(state.objectMode)return 1;if(n!==n){if(state.flowing&&state.length)return state.buffer.head.data.length;else return state.length}if(n>state.highWaterMark)state.highWaterMark=computeNewHighWaterMark(n);if(n<=state.length)return n;if(!state.ended){state.needReadable=true;return 0}return state.length}Readable.prototype.read=function(n){debug("read",n);n=parseInt(n,10);var state=this._readableState;var nOrig=n;if(n!==0)state.emittedReadable=false;if(n===0&&state.needReadable&&((state.highWaterMark!==0?state.length>=state.highWaterMark:state.length>0)||state.ended)){debug("read: emitReadable",state.length,state.ended);if(state.length===0&&state.ended)endReadable(this);else emitReadable(this);return null}n=howMuchToRead(n,state);if(n===0&&state.ended){if(state.length===0)endReadable(this);return null}var doRead=state.needReadable;debug("need readable",doRead);if(state.length===0||state.length-n0)ret=fromList(n,state);else ret=null;if(ret===null){state.needReadable=state.length<=state.highWaterMark;n=0}else{state.length-=n;state.awaitDrain=0}if(state.length===0){if(!state.ended)state.needReadable=true;if(nOrig!==n&&state.ended)endReadable(this)}if(ret!==null)this.emit("data",ret);return ret};function onEofChunk(stream,state){debug("onEofChunk");if(state.ended)return;if(state.decoder){var chunk=state.decoder.end();if(chunk&&chunk.length){state.buffer.push(chunk);state.length+=state.objectMode?1:chunk.length}}state.ended=true;if(state.sync){emitReadable(stream)}else{state.needReadable=false;if(!state.emittedReadable){state.emittedReadable=true;emitReadable_(stream)}}}function emitReadable(stream){var state=stream._readableState;debug("emitReadable",state.needReadable,state.emittedReadable);state.needReadable=false;if(!state.emittedReadable){debug("emitReadable",state.flowing);state.emittedReadable=true;process.nextTick(emitReadable_,stream)}}function emitReadable_(stream){var state=stream._readableState;debug("emitReadable_",state.destroyed,state.length,state.ended);if(!state.destroyed&&(state.length||state.ended)){stream.emit("readable");state.emittedReadable=false}state.needReadable=!state.flowing&&!state.ended&&state.length<=state.highWaterMark;flow(stream)}function maybeReadMore(stream,state){if(!state.readingMore){state.readingMore=true;process.nextTick(maybeReadMore_,stream,state)}}function maybeReadMore_(stream,state){while(!state.reading&&!state.ended&&(state.length1&&indexOf(state.pipes,dest)!==-1)&&!cleanedUp){debug("false write response, pause",state.awaitDrain);state.awaitDrain++}src.pause()}}function onerror(er){debug("onerror",er);unpipe();dest.removeListener("error",onerror);if(EElistenerCount(dest,"error")===0)errorOrDestroy(dest,er)}prependListener(dest,"error",onerror);function onclose(){dest.removeListener("finish",onfinish);unpipe()}dest.once("close",onclose);function onfinish(){debug("onfinish");dest.removeListener("close",onclose);unpipe()}dest.once("finish",onfinish);function unpipe(){debug("unpipe");src.unpipe(dest)}dest.emit("pipe",src);if(!state.flowing){debug("pipe resume");src.resume()}return dest};function pipeOnDrain(src){return function pipeOnDrainFunctionResult(){var state=src._readableState;debug("pipeOnDrain",state.awaitDrain);if(state.awaitDrain)state.awaitDrain--;if(state.awaitDrain===0&&EElistenerCount(src,"data")){state.flowing=true;flow(src)}}}Readable.prototype.unpipe=function(dest){var state=this._readableState;var unpipeInfo={hasUnpiped:false};if(state.pipesCount===0)return this;if(state.pipesCount===1){if(dest&&dest!==state.pipes)return this;if(!dest)dest=state.pipes;state.pipes=null;state.pipesCount=0;state.flowing=false;if(dest)dest.emit("unpipe",this,unpipeInfo);return this}if(!dest){var dests=state.pipes;var len=state.pipesCount;state.pipes=null;state.pipesCount=0;state.flowing=false;for(var i=0;i0;if(state.flowing!==false)this.resume()}else if(ev==="readable"){if(!state.endEmitted&&!state.readableListening){state.readableListening=state.needReadable=true;state.flowing=false;state.emittedReadable=false;debug("on readable",state.length,state.reading);if(state.length){emitReadable(this)}else if(!state.reading){process.nextTick(nReadingNextTick,this)}}}return res};Readable.prototype.addListener=Readable.prototype.on;Readable.prototype.removeListener=function(ev,fn){var res=Stream.prototype.removeListener.call(this,ev,fn);if(ev==="readable"){process.nextTick(updateReadableListening,this)}return res};Readable.prototype.removeAllListeners=function(ev){var res=Stream.prototype.removeAllListeners.apply(this,arguments);if(ev==="readable"||ev===undefined){process.nextTick(updateReadableListening,this)}return res};function updateReadableListening(self){var state=self._readableState;state.readableListening=self.listenerCount("readable")>0;if(state.resumeScheduled&&!state.paused){state.flowing=true}else if(self.listenerCount("data")>0){self.resume()}}function nReadingNextTick(self){debug("readable nexttick read 0");self.read(0)}Readable.prototype.resume=function(){var state=this._readableState;if(!state.flowing){debug("resume");state.flowing=!state.readableListening;resume(this,state)}state.paused=false;return this};function resume(stream,state){if(!state.resumeScheduled){state.resumeScheduled=true;process.nextTick(resume_,stream,state)}}function resume_(stream,state){debug("resume",state.reading);if(!state.reading){stream.read(0)}state.resumeScheduled=false;stream.emit("resume");flow(stream);if(state.flowing&&!state.reading)stream.read(0)}Readable.prototype.pause=function(){debug("call pause flowing=%j",this._readableState.flowing);if(this._readableState.flowing!==false){debug("pause");this._readableState.flowing=false;this.emit("pause")}this._readableState.paused=true;return this};function flow(stream){var state=stream._readableState;debug("flow",state.flowing);while(state.flowing&&stream.read()!==null){}}Readable.prototype.wrap=function(stream){var _this=this;var state=this._readableState;var paused=false;stream.on("end",function(){debug("wrapped end");if(state.decoder&&!state.ended){var chunk=state.decoder.end();if(chunk&&chunk.length)_this.push(chunk)}_this.push(null)});stream.on("data",function(chunk){debug("wrapped data");if(state.decoder)chunk=state.decoder.write(chunk);if(state.objectMode&&(chunk===null||chunk===undefined))return;else if(!state.objectMode&&(!chunk||!chunk.length))return;var ret=_this.push(chunk);if(!ret){paused=true;stream.pause()}});for(var i in stream){if(this[i]===undefined&&typeof stream[i]==="function"){this[i]=function methodWrap(method){return function methodWrapReturnFunction(){return stream[method].apply(stream,arguments)}}(i)}}for(var n=0;n=state.length){if(state.decoder)ret=state.buffer.join("");else if(state.buffer.length===1)ret=state.buffer.first();else ret=state.buffer.concat(state.length);state.buffer.clear()}else{ret=state.buffer.consume(n,state.decoder)}return ret}function endReadable(stream){var state=stream._readableState;debug("endReadable",state.endEmitted);if(!state.endEmitted){state.ended=true;process.nextTick(endReadableNT,state,stream)}}function endReadableNT(state,stream){debug("endReadableNT",state.endEmitted,state.length);if(!state.endEmitted&&state.length===0){state.endEmitted=true;stream.readable=false;stream.emit("end");if(state.autoDestroy){var wState=stream._writableState;if(!wState||wState.autoDestroy&&wState.finished){stream.destroy()}}}}if(typeof Symbol==="function"){Readable.from=function(iterable,opts){if(from===undefined){from=require("./internal/streams/from")}return from(Readable,iterable,opts)}}function indexOf(xs,x){for(var i=0,l=xs.length;i-1))throw new ERR_UNKNOWN_ENCODING(encoding);this._writableState.defaultEncoding=encoding;return this};Object.defineProperty(Writable.prototype,"writableBuffer",{enumerable:false,get:function get(){return this._writableState&&this._writableState.getBuffer()}});function decodeChunk(state,chunk,encoding){if(!state.objectMode&&state.decodeStrings!==false&&typeof chunk==="string"){chunk=Buffer.from(chunk,encoding)}return chunk}Object.defineProperty(Writable.prototype,"writableHighWaterMark",{enumerable:false,get:function get(){return this._writableState.highWaterMark}});function writeOrBuffer(stream,state,isBuf,chunk,encoding,cb){if(!isBuf){var newChunk=decodeChunk(state,chunk,encoding);if(chunk!==newChunk){isBuf=true;encoding="buffer";chunk=newChunk}}var len=state.objectMode?1:chunk.length;state.length+=len;var ret=state.length0)this.tail.next=entry;else this.head=entry;this.tail=entry;++this.length}},{key:"unshift",value:function unshift(v){var entry={data:v,next:this.head};if(this.length===0)this.tail=entry;this.head=entry;++this.length}},{key:"shift",value:function shift(){if(this.length===0)return;var ret=this.head.data;if(this.length===1)this.head=this.tail=null;else this.head=this.head.next;--this.length;return ret}},{key:"clear",value:function clear(){this.head=this.tail=null;this.length=0}},{key:"join",value:function join(s){if(this.length===0)return"";var p=this.head;var ret=""+p.data;while(p=p.next){ret+=s+p.data}return ret}},{key:"concat",value:function concat(n){if(this.length===0)return Buffer.alloc(0);var ret=Buffer.allocUnsafe(n>>>0);var p=this.head;var i=0;while(p){copyBuffer(p.data,ret,i);i+=p.data.length;p=p.next}return ret}},{key:"consume",value:function consume(n,hasStrings){var ret;if(nstr.length?str.length:n;if(nb===str.length)ret+=str;else ret+=str.slice(0,n);n-=nb;if(n===0){if(nb===str.length){++c;if(p.next)this.head=p.next;else this.head=this.tail=null}else{this.head=p;p.data=str.slice(nb)}break}++c}this.length-=c;return ret}},{key:"_getBuffer",value:function _getBuffer(n){var ret=Buffer.allocUnsafe(n);var p=this.head;var c=1;p.data.copy(ret);n-=p.data.length;while(p=p.next){var buf=p.data;var nb=n>buf.length?buf.length:n;buf.copy(ret,ret.length-n,0,nb);n-=nb;if(n===0){if(nb===buf.length){++c;if(p.next)this.head=p.next;else this.head=this.tail=null}else{this.head=p;p.data=buf.slice(nb)}break}++c}this.length-=c;return ret}},{key:custom,value:function value(_,options){return inspect(this,_objectSpread({},options,{depth:0,customInspect:false}))}}]);return BufferList}()},{buffer:159,util:115}],151:[function(require,module,exports){(function(process){(function(){"use strict";function destroy(err,cb){var _this=this;var readableDestroyed=this._readableState&&this._readableState.destroyed;var writableDestroyed=this._writableState&&this._writableState.destroyed;if(readableDestroyed||writableDestroyed){if(cb){cb(err)}else if(err){if(!this._writableState){process.nextTick(emitErrorNT,this,err)}else if(!this._writableState.errorEmitted){this._writableState.errorEmitted=true;process.nextTick(emitErrorNT,this,err)}}return this}if(this._readableState){this._readableState.destroyed=true}if(this._writableState){this._writableState.destroyed=true}this._destroy(err||null,function(err){if(!cb&&err){if(!_this._writableState){process.nextTick(emitErrorAndCloseNT,_this,err)}else if(!_this._writableState.errorEmitted){_this._writableState.errorEmitted=true;process.nextTick(emitErrorAndCloseNT,_this,err)}else{process.nextTick(emitCloseNT,_this)}}else if(cb){process.nextTick(emitCloseNT,_this);cb(err)}else{process.nextTick(emitCloseNT,_this)}});return this}function emitErrorAndCloseNT(self,err){emitErrorNT(self,err);emitCloseNT(self)}function emitCloseNT(self){if(self._writableState&&!self._writableState.emitClose)return;if(self._readableState&&!self._readableState.emitClose)return;self.emit("close")}function undestroy(){if(this._readableState){this._readableState.destroyed=false;this._readableState.reading=false;this._readableState.ended=false;this._readableState.endEmitted=false}if(this._writableState){this._writableState.destroyed=false;this._writableState.ended=false;this._writableState.ending=false;this._writableState.finalCalled=false;this._writableState.prefinished=false;this._writableState.finished=false;this._writableState.errorEmitted=false}}function emitErrorNT(self,err){self.emit("error",err)}function errorOrDestroy(stream,err){var rState=stream._readableState;var wState=stream._writableState;if(rState&&rState.autoDestroy||wState&&wState.autoDestroy)stream.destroy(err);else stream.emit("error",err)}module.exports={destroy:destroy,undestroy:undestroy,errorOrDestroy:errorOrDestroy}}).call(this)}).call(this,require("_process"))},{_process:246}],152:[function(require,module,exports){"use strict";var ERR_STREAM_PREMATURE_CLOSE=require("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;function once(callback){var called=false;return function(){if(called)return;called=true;for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}callback.apply(this,args)}}function noop(){}function isRequest(stream){return stream.setHeader&&typeof stream.abort==="function"}function eos(stream,opts,callback){if(typeof opts==="function")return eos(stream,null,opts);if(!opts)opts={};callback=once(callback||noop);var readable=opts.readable||opts.readable!==false&&stream.readable;var writable=opts.writable||opts.writable!==false&&stream.writable;var onlegacyfinish=function onlegacyfinish(){if(!stream.writable)onfinish()};var writableEnded=stream._writableState&&stream._writableState.finished;var onfinish=function onfinish(){writable=false;writableEnded=true;if(!readable)callback.call(stream)};var readableEnded=stream._readableState&&stream._readableState.endEmitted;var onend=function onend(){readable=false;readableEnded=true;if(!writable)callback.call(stream)};var onerror=function onerror(err){callback.call(stream,err)};var onclose=function onclose(){var err;if(readable&&!readableEnded){if(!stream._readableState||!stream._readableState.ended)err=new ERR_STREAM_PREMATURE_CLOSE;return callback.call(stream,err)}if(writable&&!writableEnded){if(!stream._writableState||!stream._writableState.ended)err=new ERR_STREAM_PREMATURE_CLOSE;return callback.call(stream,err)}};var onrequest=function onrequest(){stream.req.on("finish",onfinish)};if(isRequest(stream)){stream.on("complete",onfinish);stream.on("abort",onclose);if(stream.req)onrequest();else stream.on("request",onrequest)}else if(writable&&!stream._writableState){stream.on("end",onlegacyfinish);stream.on("close",onlegacyfinish)}stream.on("end",onend);stream.on("finish",onfinish);if(opts.error!==false)stream.on("error",onerror);stream.on("close",onclose);return function(){stream.removeListener("complete",onfinish);stream.removeListener("abort",onclose);stream.removeListener("request",onrequest);if(stream.req)stream.req.removeListener("finish",onfinish);stream.removeListener("end",onlegacyfinish);stream.removeListener("close",onlegacyfinish);stream.removeListener("finish",onfinish);stream.removeListener("end",onend);stream.removeListener("error",onerror);stream.removeListener("close",onclose)}}module.exports=eos},{"../../../errors":143}],153:[function(require,module,exports){module.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],154:[function(require,module,exports){"use strict";var eos;function once(callback){var called=false;return function(){if(called)return;called=true;callback.apply(void 0,arguments)}}var _require$codes=require("../../../errors").codes,ERR_MISSING_ARGS=_require$codes.ERR_MISSING_ARGS,ERR_STREAM_DESTROYED=_require$codes.ERR_STREAM_DESTROYED;function noop(err){if(err)throw err}function isRequest(stream){return stream.setHeader&&typeof stream.abort==="function"}function destroyer(stream,reading,writing,callback){callback=once(callback);var closed=false;stream.on("close",function(){closed=true});if(eos===undefined)eos=require("./end-of-stream");eos(stream,{readable:reading,writable:writing},function(err){if(err)return callback(err);closed=true;callback()});var destroyed=false;return function(err){if(closed)return;if(destroyed)return;destroyed=true;if(isRequest(stream))return stream.abort();if(typeof stream.destroy==="function")return stream.destroy();callback(err||new ERR_STREAM_DESTROYED("pipe"))}}function call(fn){fn()}function pipe(from,to){return from.pipe(to)}function popCallback(streams){if(!streams.length)return noop;if(typeof streams[streams.length-1]!=="function")return noop;return streams.pop()}function pipeline(){for(var _len=arguments.length,streams=new Array(_len),_key=0;_key<_len;_key++){streams[_key]=arguments[_key]}var callback=popCallback(streams);if(Array.isArray(streams[0]))streams=streams[0];if(streams.length<2){throw new ERR_MISSING_ARGS("streams")}var error;var destroys=streams.map(function(stream,i){var reading=i0;return destroyer(stream,reading,writing,function(err){if(!error)error=err;if(err)destroys.forEach(call);if(reading)return;destroys.forEach(call);callback(error)})});return streams.reduce(pipe)}module.exports=pipeline},{"../../../errors":143,"./end-of-stream":152}],155:[function(require,module,exports){"use strict";var ERR_INVALID_OPT_VALUE=require("../../../errors").codes.ERR_INVALID_OPT_VALUE;function highWaterMarkFrom(options,isDuplex,duplexKey){return options.highWaterMark!=null?options.highWaterMark:isDuplex?options[duplexKey]:null}function getHighWaterMark(state,options,duplexKey,isDuplex){var hwm=highWaterMarkFrom(options,isDuplex,duplexKey);if(hwm!=null){if(!(isFinite(hwm)&&Math.floor(hwm)===hwm)||hwm<0){var name=isDuplex?duplexKey:"highWaterMark";throw new ERR_INVALID_OPT_VALUE(name,hwm)}return Math.floor(hwm)}return state.objectMode?16:16*1024}module.exports={getHighWaterMark:getHighWaterMark}},{"../../../errors":143}],156:[function(require,module,exports){module.exports=require("events").EventEmitter},{events:196}],157:[function(require,module,exports){exports=module.exports=require("./lib/_stream_readable.js");exports.Stream=exports;exports.Readable=exports;exports.Writable=require("./lib/_stream_writable.js");exports.Duplex=require("./lib/_stream_duplex.js");exports.Transform=require("./lib/_stream_transform.js");exports.PassThrough=require("./lib/_stream_passthrough.js");exports.finished=require("./lib/internal/streams/end-of-stream.js");exports.pipeline=require("./lib/internal/streams/pipeline.js")},{"./lib/_stream_duplex.js":144,"./lib/_stream_passthrough.js":145,"./lib/_stream_readable.js":146,"./lib/_stream_transform.js":147,"./lib/_stream_writable.js":148,"./lib/internal/streams/end-of-stream.js":152,"./lib/internal/streams/pipeline.js":154}],158:[function(require,module,exports){(function(Buffer){(function(){module.exports=function xor(a,b){var length=Math.min(a.length,b.length);var buffer=new Buffer(length);for(var i=0;iK_MAX_LENGTH){throw new RangeError('The value "'+length+'" is invalid for option "size"')}var buf=new Uint8Array(length);buf.__proto__=Buffer.prototype;return buf}function Buffer(arg,encodingOrOffset,length){if(typeof arg==="number"){if(typeof encodingOrOffset==="string"){throw new TypeError('The "string" argument must be of type string. Received type number')}return allocUnsafe(arg)}return from(arg,encodingOrOffset,length)}if(typeof Symbol!=="undefined"&&Symbol.species!=null&&Buffer[Symbol.species]===Buffer){Object.defineProperty(Buffer,Symbol.species,{value:null,configurable:true,enumerable:false,writable:false})}Buffer.poolSize=8192;function from(value,encodingOrOffset,length){if(typeof value==="string"){return fromString(value,encodingOrOffset)}if(ArrayBuffer.isView(value)){return fromArrayLike(value)}if(value==null){throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof value)}if(isInstance(value,ArrayBuffer)||value&&isInstance(value.buffer,ArrayBuffer)){return fromArrayBuffer(value,encodingOrOffset,length)}if(typeof value==="number"){throw new TypeError('The "value" argument must not be of type number. Received type number')}var valueOf=value.valueOf&&value.valueOf();if(valueOf!=null&&valueOf!==value){return Buffer.from(valueOf,encodingOrOffset,length)}var b=fromObject(value);if(b)return b;if(typeof Symbol!=="undefined"&&Symbol.toPrimitive!=null&&typeof value[Symbol.toPrimitive]==="function"){return Buffer.from(value[Symbol.toPrimitive]("string"),encodingOrOffset,length)}throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof value)}Buffer.from=function(value,encodingOrOffset,length){return from(value,encodingOrOffset,length)};Buffer.prototype.__proto__=Uint8Array.prototype;Buffer.__proto__=Uint8Array;function assertSize(size){if(typeof size!=="number"){throw new TypeError('"size" argument must be of type number')}else if(size<0){throw new RangeError('The value "'+size+'" is invalid for option "size"')}}function alloc(size,fill,encoding){assertSize(size);if(size<=0){return createBuffer(size)}if(fill!==undefined){return typeof encoding==="string"?createBuffer(size).fill(fill,encoding):createBuffer(size).fill(fill)}return createBuffer(size)}Buffer.alloc=function(size,fill,encoding){return alloc(size,fill,encoding)};function allocUnsafe(size){assertSize(size);return createBuffer(size<0?0:checked(size)|0)}Buffer.allocUnsafe=function(size){return allocUnsafe(size)};Buffer.allocUnsafeSlow=function(size){return allocUnsafe(size)};function fromString(string,encoding){if(typeof encoding!=="string"||encoding===""){encoding="utf8"}if(!Buffer.isEncoding(encoding)){throw new TypeError("Unknown encoding: "+encoding)}var length=byteLength(string,encoding)|0;var buf=createBuffer(length);var actual=buf.write(string,encoding);if(actual!==length){buf=buf.slice(0,actual)}return buf}function fromArrayLike(array){var length=array.length<0?0:checked(array.length)|0;var buf=createBuffer(length);for(var i=0;i=K_MAX_LENGTH){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+K_MAX_LENGTH.toString(16)+" bytes")}return length|0}function SlowBuffer(length){if(+length!=length){length=0}return Buffer.alloc(+length)}Buffer.isBuffer=function isBuffer(b){return b!=null&&b._isBuffer===true&&b!==Buffer.prototype};Buffer.compare=function compare(a,b){if(isInstance(a,Uint8Array))a=Buffer.from(a,a.offset,a.byteLength);if(isInstance(b,Uint8Array))b=Buffer.from(b,b.offset,b.byteLength);if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b)){throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array')}if(a===b)return 0;var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i2&&arguments[2]===true;if(!mustMatch&&len===0)return 0;var loweredCase=false;for(;;){switch(encoding){case"ascii":case"latin1":case"binary":return len;case"utf8":case"utf-8":return utf8ToBytes(string).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return len*2;case"hex":return len>>>1;case"base64":return base64ToBytes(string).length;default:if(loweredCase){return mustMatch?-1:utf8ToBytes(string).length}encoding=(""+encoding).toLowerCase();loweredCase=true}}}Buffer.byteLength=byteLength;function slowToString(encoding,start,end){var loweredCase=false;if(start===undefined||start<0){start=0}if(start>this.length){return""}if(end===undefined||end>this.length){end=this.length}if(end<=0){return""}end>>>=0;start>>>=0;if(end<=start){return""}if(!encoding)encoding="utf8";while(true){switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"latin1":case"binary":return latin1Slice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase();loweredCase=true}}}Buffer.prototype._isBuffer=true;function swap(b,n,m){var i=b[n];b[n]=b[m];b[m]=i}Buffer.prototype.swap16=function swap16(){var len=this.length;if(len%2!==0){throw new RangeError("Buffer size must be a multiple of 16-bits")}for(var i=0;imax)str+=" ... ";return""};Buffer.prototype.compare=function compare(target,start,end,thisStart,thisEnd){if(isInstance(target,Uint8Array)){target=Buffer.from(target,target.offset,target.byteLength)}if(!Buffer.isBuffer(target)){throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. '+"Received type "+typeof target)}if(start===undefined){start=0}if(end===undefined){end=target?target.length:0}if(thisStart===undefined){thisStart=0}if(thisEnd===undefined){thisEnd=this.length}if(start<0||end>target.length||thisStart<0||thisEnd>this.length){throw new RangeError("out of range index")}if(thisStart>=thisEnd&&start>=end){return 0}if(thisStart>=thisEnd){return-1}if(start>=end){return 1}start>>>=0;end>>>=0;thisStart>>>=0;thisEnd>>>=0;if(this===target)return 0;var x=thisEnd-thisStart;var y=end-start;var len=Math.min(x,y);var thisCopy=this.slice(thisStart,thisEnd);var targetCopy=target.slice(start,end);for(var i=0;i2147483647){byteOffset=2147483647}else if(byteOffset<-2147483648){byteOffset=-2147483648}byteOffset=+byteOffset;if(numberIsNaN(byteOffset)){byteOffset=dir?0:buffer.length-1}if(byteOffset<0)byteOffset=buffer.length+byteOffset;if(byteOffset>=buffer.length){if(dir)return-1;else byteOffset=buffer.length-1}else if(byteOffset<0){if(dir)byteOffset=0;else return-1}if(typeof val==="string"){val=Buffer.from(val,encoding)}if(Buffer.isBuffer(val)){if(val.length===0){return-1}return arrayIndexOf(buffer,val,byteOffset,encoding,dir)}else if(typeof val==="number"){val=val&255;if(typeof Uint8Array.prototype.indexOf==="function"){if(dir){return Uint8Array.prototype.indexOf.call(buffer,val,byteOffset)}else{return Uint8Array.prototype.lastIndexOf.call(buffer,val,byteOffset)}}return arrayIndexOf(buffer,[val],byteOffset,encoding,dir)}throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(arr,val,byteOffset,encoding,dir){var indexSize=1;var arrLength=arr.length;var valLength=val.length;if(encoding!==undefined){encoding=String(encoding).toLowerCase();if(encoding==="ucs2"||encoding==="ucs-2"||encoding==="utf16le"||encoding==="utf-16le"){if(arr.length<2||val.length<2){return-1}indexSize=2;arrLength/=2;valLength/=2;byteOffset/=2}}function read(buf,i){if(indexSize===1){return buf[i]}else{return buf.readUInt16BE(i*indexSize)}}var i;if(dir){var foundIndex=-1;for(i=byteOffset;iarrLength)byteOffset=arrLength-valLength;for(i=byteOffset;i>=0;i--){var found=true;for(var j=0;jremaining){length=remaining}}var strLen=string.length;if(length>strLen/2){length=strLen/2}for(var i=0;i>>0;if(isFinite(length)){length=length>>>0;if(encoding===undefined)encoding="utf8"}else{encoding=length;length=undefined}}else{throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported")}var remaining=this.length-offset;if(length===undefined||length>remaining)length=remaining;if(string.length>0&&(length<0||offset<0)||offset>this.length){throw new RangeError("Attempt to write outside buffer bounds")}if(!encoding)encoding="utf8";var loweredCase=false;for(;;){switch(encoding){case"hex":return hexWrite(this,string,offset,length);case"utf8":case"utf-8":return utf8Write(this,string,offset,length);case"ascii":return asciiWrite(this,string,offset,length);case"latin1":case"binary":return latin1Write(this,string,offset,length);case"base64":return base64Write(this,string,offset,length);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,string,offset,length);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(""+encoding).toLowerCase();loweredCase=true}}};Buffer.prototype.toJSON=function toJSON(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function base64Slice(buf,start,end){if(start===0&&end===buf.length){return base64.fromByteArray(buf)}else{return base64.fromByteArray(buf.slice(start,end))}}function utf8Slice(buf,start,end){end=Math.min(buf.length,end);var res=[];var i=start;while(i239?4:firstByte>223?3:firstByte>191?2:1;if(i+bytesPerSequence<=end){var secondByte,thirdByte,fourthByte,tempCodePoint;switch(bytesPerSequence){case 1:if(firstByte<128){codePoint=firstByte}break;case 2:secondByte=buf[i+1];if((secondByte&192)===128){tempCodePoint=(firstByte&31)<<6|secondByte&63;if(tempCodePoint>127){codePoint=tempCodePoint}}break;case 3:secondByte=buf[i+1];thirdByte=buf[i+2];if((secondByte&192)===128&&(thirdByte&192)===128){tempCodePoint=(firstByte&15)<<12|(secondByte&63)<<6|thirdByte&63;if(tempCodePoint>2047&&(tempCodePoint<55296||tempCodePoint>57343)){codePoint=tempCodePoint}}break;case 4:secondByte=buf[i+1];thirdByte=buf[i+2];fourthByte=buf[i+3];if((secondByte&192)===128&&(thirdByte&192)===128&&(fourthByte&192)===128){tempCodePoint=(firstByte&15)<<18|(secondByte&63)<<12|(thirdByte&63)<<6|fourthByte&63;if(tempCodePoint>65535&&tempCodePoint<1114112){codePoint=tempCodePoint}}}}if(codePoint===null){codePoint=65533;bytesPerSequence=1}else if(codePoint>65535){codePoint-=65536;res.push(codePoint>>>10&1023|55296);codePoint=56320|codePoint&1023}res.push(codePoint);i+=bytesPerSequence}return decodeCodePointsArray(res)}var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(codePoints){var len=codePoints.length;if(len<=MAX_ARGUMENTS_LENGTH){return String.fromCharCode.apply(String,codePoints)}var res="";var i=0;while(ilen)end=len;var out="";for(var i=start;ilen){start=len}if(end<0){end+=len;if(end<0)end=0}else if(end>len){end=len}if(endlength)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function readUIntLE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i>>0;byteLength=byteLength>>>0;if(!noAssert){checkOffset(offset,byteLength,this.length)}var val=this[offset+--byteLength];var mul=1;while(byteLength>0&&(mul*=256)){val+=this[offset+--byteLength]*mul}return val};Buffer.prototype.readUInt8=function readUInt8(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function readUInt16LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function readUInt16BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function readUInt32LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function readUInt32BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function readIntLE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function readIntBE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256)){val+=this[offset+--i]*mul}mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function readInt8(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function readInt16LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function readInt16BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function readInt32LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function readInt32BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function readFloatLE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function readFloatBE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function readDoubleLE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function readDoubleBE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError('"buffer" argument must be a Buffer instance');if(value>max||valuebuf.length)throw new RangeError("Index out of range")}Buffer.prototype.writeUIntLE=function writeUIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var mul=1;var i=0;this[offset]=value&255;while(++i>>0;byteLength=byteLength>>>0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var i=byteLength-1;var mul=1;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){this[offset+i]=value/mul&255}return offset+byteLength};Buffer.prototype.writeUInt8=function writeUInt8(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,255,0);this[offset]=value&255;return offset+1};Buffer.prototype.writeUInt16LE=function writeUInt16LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);this[offset]=value&255;this[offset+1]=value>>>8;return offset+2};Buffer.prototype.writeUInt16BE=function writeUInt16BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);this[offset]=value>>>8;this[offset+1]=value&255;return offset+2};Buffer.prototype.writeUInt32LE=function writeUInt32LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value&255;return offset+4};Buffer.prototype.writeUInt32BE=function writeUInt32BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255;return offset+4};Buffer.prototype.writeIntLE=function writeIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=0;var mul=1;var sub=0;this[offset]=value&255;while(++i>0)-sub&255}return offset+byteLength};Buffer.prototype.writeIntBE=function writeIntBE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=byteLength-1;var mul=1;var sub=0;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){if(value<0&&sub===0&&this[offset+i+1]!==0){sub=1}this[offset+i]=(value/mul>>0)-sub&255}return offset+byteLength};Buffer.prototype.writeInt8=function writeInt8(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(value<0)value=255+value+1;this[offset]=value&255;return offset+1};Buffer.prototype.writeInt16LE=function writeInt16LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);this[offset]=value&255;this[offset+1]=value>>>8;return offset+2};Buffer.prototype.writeInt16BE=function writeInt16BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);this[offset]=value>>>8;this[offset+1]=value&255;return offset+2};Buffer.prototype.writeInt32LE=function writeInt32LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);this[offset]=value&255;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24;return offset+4};Buffer.prototype.writeInt32BE=function writeInt32BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255;return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(offset+ext>buf.length)throw new RangeError("Index out of range");if(offset<0)throw new RangeError("Index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkIEEE754(buf,value,offset,4,34028234663852886e22,-34028234663852886e22)}ieee754.write(buf,value,offset,littleEndian,23,4);return offset+4}Buffer.prototype.writeFloatLE=function writeFloatLE(value,offset,noAssert){return writeFloat(this,value,offset,true,noAssert)};Buffer.prototype.writeFloatBE=function writeFloatBE(value,offset,noAssert){return writeFloat(this,value,offset,false,noAssert)};function writeDouble(buf,value,offset,littleEndian,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkIEEE754(buf,value,offset,8,17976931348623157e292,-17976931348623157e292)}ieee754.write(buf,value,offset,littleEndian,52,8);return offset+8}Buffer.prototype.writeDoubleLE=function writeDoubleLE(value,offset,noAssert){return writeDouble(this,value,offset,true,noAssert)};Buffer.prototype.writeDoubleBE=function writeDoubleBE(value,offset,noAssert){return writeDouble(this,value,offset,false,noAssert)};Buffer.prototype.copy=function copy(target,targetStart,start,end){if(!Buffer.isBuffer(target))throw new TypeError("argument should be a Buffer");if(!start)start=0;if(!end&&end!==0)end=this.length;if(targetStart>=target.length)targetStart=target.length;if(!targetStart)targetStart=0;if(end>0&&end=this.length)throw new RangeError("Index out of range");if(end<0)throw new RangeError("sourceEnd out of bounds");if(end>this.length)end=this.length;if(target.length-targetStart=0;--i){target[i+targetStart]=this[i+start]}}else{Uint8Array.prototype.set.call(target,this.subarray(start,end),targetStart)}return len};Buffer.prototype.fill=function fill(val,start,end,encoding){if(typeof val==="string"){if(typeof start==="string"){encoding=start;start=0;end=this.length}else if(typeof end==="string"){encoding=end;end=this.length}if(encoding!==undefined&&typeof encoding!=="string"){throw new TypeError("encoding must be a string")}if(typeof encoding==="string"&&!Buffer.isEncoding(encoding)){throw new TypeError("Unknown encoding: "+encoding)}if(val.length===1){var code=val.charCodeAt(0);if(encoding==="utf8"&&code<128||encoding==="latin1"){val=code}}}else if(typeof val==="number"){val=val&255}if(start<0||this.length>>0;end=end===undefined?this.length:end>>>0;if(!val)val=0;var i;if(typeof val==="number"){for(i=start;i55295&&codePoint<57344){if(!leadSurrogate){if(codePoint>56319){if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}leadSurrogate=codePoint;continue}if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}codePoint=(leadSurrogate-55296<<10|codePoint-56320)+65536}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189)}leadSurrogate=null;if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<1114112){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i>8;lo=c%256;byteArray.push(lo);byteArray.push(hi)}return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length){for(var i=0;i=dst.length||i>=src.length)break;dst[i+offset]=src[i]}return i}function isInstance(obj,type){return obj instanceof type||obj!=null&&obj.constructor!=null&&obj.constructor.name!=null&&obj.constructor.name===type.name}function numberIsNaN(obj){return obj!==obj}}).call(this)}).call(this,require("buffer").Buffer)},{"base64-js":112,buffer:159,ieee754:227}],160:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;var Transform=require("stream").Transform;var StringDecoder=require("string_decoder").StringDecoder;var inherits=require("inherits");function CipherBase(hashMode){Transform.call(this);this.hashMode=typeof hashMode==="string";if(this.hashMode){this[hashMode]=this._finalOrDigest}else{this.final=this._finalOrDigest}if(this._final){this.__final=this._final;this._final=null}this._decoder=null;this._encoding=null}inherits(CipherBase,Transform);CipherBase.prototype.update=function(data,inputEnc,outputEnc){if(typeof data==="string"){data=Buffer.from(data,inputEnc)}var outData=this._update(data);if(this.hashMode)return this;if(outputEnc){outData=this._toString(outData,outputEnc)}return outData};CipherBase.prototype.setAutoPadding=function(){};CipherBase.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};CipherBase.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};CipherBase.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};CipherBase.prototype._transform=function(data,_,next){var err;try{if(this.hashMode){this._update(data)}else{this.push(this._update(data))}}catch(e){err=e}finally{next(err)}};CipherBase.prototype._flush=function(done){var err;try{this.push(this.__final())}catch(e){err=e}done(err)};CipherBase.prototype._finalOrDigest=function(outputEnc){var outData=this.__final()||Buffer.alloc(0);if(outputEnc){outData=this._toString(outData,outputEnc,true)}return outData};CipherBase.prototype._toString=function(value,enc,fin){if(!this._decoder){this._decoder=new StringDecoder(enc);this._encoding=enc}if(this._encoding!==enc)throw new Error("can't switch encodings");var out=this._decoder.write(value);if(fin){out+=this._decoder.end()}return out};module.exports=CipherBase},{inherits:228,"safe-buffer":261,stream:271,string_decoder:286}],161:[function(require,module,exports){(function(Buffer){(function(){var elliptic=require("elliptic");var BN=require("bn.js");module.exports=function createECDH(curve){return new ECDH(curve)};var aliases={secp256k1:{name:"secp256k1",byteLength:32},secp224r1:{name:"p224",byteLength:28},prime256v1:{name:"p256",byteLength:32},prime192v1:{name:"p192",byteLength:24},ed25519:{name:"ed25519",byteLength:32},secp384r1:{name:"p384",byteLength:48},secp521r1:{name:"p521",byteLength:66}};aliases.p224=aliases.secp224r1;aliases.p256=aliases.secp256r1=aliases.prime256v1;aliases.p192=aliases.secp192r1=aliases.prime192v1;aliases.p384=aliases.secp384r1;aliases.p521=aliases.secp521r1;function ECDH(curve){this.curveType=aliases[curve];if(!this.curveType){this.curveType={name:curve}}this.curve=new elliptic.ec(this.curveType.name);this.keys=void 0}ECDH.prototype.generateKeys=function(enc,format){this.keys=this.curve.genKeyPair();return this.getPublicKey(enc,format)};ECDH.prototype.computeSecret=function(other,inenc,enc){inenc=inenc||"utf8";if(!Buffer.isBuffer(other)){other=new Buffer(other,inenc)}var otherPub=this.curve.keyFromPublic(other).getPublic();var out=otherPub.mul(this.keys.getPrivate()).getX();return formatReturnValue(out,enc,this.curveType.byteLength)};ECDH.prototype.getPublicKey=function(enc,format){var key=this.keys.getPublic(format==="compressed",true);if(format==="hybrid"){if(key[key.length-1]%2){key[0]=7}else{key[0]=6}}return formatReturnValue(key,enc)};ECDH.prototype.getPrivateKey=function(enc){return formatReturnValue(this.keys.getPrivate(),enc)};ECDH.prototype.setPublicKey=function(pub,enc){enc=enc||"utf8";if(!Buffer.isBuffer(pub)){pub=new Buffer(pub,enc)}this.keys._importPublic(pub);return this};ECDH.prototype.setPrivateKey=function(priv,enc){enc=enc||"utf8";if(!Buffer.isBuffer(priv)){priv=new Buffer(priv,enc)}var _priv=new BN(priv);_priv=_priv.toString(16);this.keys=this.curve.genKeyPair();this.keys._importPrivate(_priv);return this};function formatReturnValue(bn,enc,len){if(!Array.isArray(bn)){bn=bn.toArray()}var buf=new Buffer(bn);if(len&&buf.lengthblocksize){var hash=alg==="rmd160"?new RIPEMD160:sha(alg);key=hash.update(key).digest()}else if(key.lengthblocksize){key=alg(key)}else if(key.length0;count--){inputOff+=this._buffer(data,inputOff);outputOff+=this._flushBuffer(out,outputOff)}inputOff+=this._buffer(data,inputOff);return out};Cipher.prototype.final=function final(buffer){var first;if(buffer)first=this.update(buffer);var last;if(this.type==="encrypt")last=this._finalEncrypt();else last=this._finalDecrypt();if(first)return first.concat(last);else return last};Cipher.prototype._pad=function _pad(buffer,off){if(off===0)return false;while(off>>1];kL=utils.r28shl(kL,shift);kR=utils.r28shl(kR,shift);utils.pc2(kL,kR,state.keys,i)}};DES.prototype._update=function _update(inp,inOff,out,outOff){var state=this._desState;var l=utils.readUInt32BE(inp,inOff);var r=utils.readUInt32BE(inp,inOff+4);utils.ip(l,r,state.tmp,0);l=state.tmp[0];r=state.tmp[1];if(this.type==="encrypt")this._encrypt(state,l,r,state.tmp,0);else this._decrypt(state,l,r,state.tmp,0);l=state.tmp[0];r=state.tmp[1];utils.writeUInt32BE(out,l,outOff);utils.writeUInt32BE(out,r,outOff+4)};DES.prototype._pad=function _pad(buffer,off){var value=buffer.length-off;for(var i=off;i>>0;l=t}utils.rip(r,l,out,off)};DES.prototype._decrypt=function _decrypt(state,lStart,rStart,out,off){var l=rStart;var r=lStart;for(var i=state.keys.length-2;i>=0;i-=2){var keyL=state.keys[i];var keyR=state.keys[i+1];utils.expand(l,state.tmp,0);keyL^=state.tmp[0];keyR^=state.tmp[1];var s=utils.substitute(keyL,keyR);var f=utils.permute(s);var t=l;l=(r^f)>>>0;r=t}utils.rip(l,r,out,off)}},{"./cipher":170,"./utils":173,inherits:228,"minimalistic-assert":232}],172:[function(require,module,exports){"use strict";var assert=require("minimalistic-assert");var inherits=require("inherits");var Cipher=require("./cipher");var DES=require("./des");function EDEState(type,key){assert.equal(key.length,24,"Invalid key length");var k1=key.slice(0,8);var k2=key.slice(8,16);var k3=key.slice(16,24);if(type==="encrypt"){this.ciphers=[DES.create({type:"encrypt",key:k1}),DES.create({type:"decrypt",key:k2}),DES.create({type:"encrypt",key:k3})]}else{this.ciphers=[DES.create({type:"decrypt",key:k3}),DES.create({type:"encrypt",key:k2}),DES.create({type:"decrypt",key:k1})]}}function EDE(options){Cipher.call(this,options);var state=new EDEState(this.type,this.options.key);this._edeState=state}inherits(EDE,Cipher);module.exports=EDE;EDE.create=function create(options){return new EDE(options)};EDE.prototype._update=function _update(inp,inOff,out,outOff){var state=this._edeState;state.ciphers[0]._update(inp,inOff,out,outOff);state.ciphers[1]._update(out,outOff,out,outOff);state.ciphers[2]._update(out,outOff,out,outOff)};EDE.prototype._pad=DES.prototype._pad;EDE.prototype._unpad=DES.prototype._unpad},{"./cipher":170,"./des":171,inherits:228,"minimalistic-assert":232}],173:[function(require,module,exports){"use strict";exports.readUInt32BE=function readUInt32BE(bytes,off){var res=bytes[0+off]<<24|bytes[1+off]<<16|bytes[2+off]<<8|bytes[3+off];return res>>>0};exports.writeUInt32BE=function writeUInt32BE(bytes,value,off){bytes[0+off]=value>>>24;bytes[1+off]=value>>>16&255;bytes[2+off]=value>>>8&255;bytes[3+off]=value&255};exports.ip=function ip(inL,inR,out,off){var outL=0;var outR=0;for(var i=6;i>=0;i-=2){for(var j=0;j<=24;j+=8){outL<<=1;outL|=inR>>>j+i&1}for(var j=0;j<=24;j+=8){outL<<=1;outL|=inL>>>j+i&1}}for(var i=6;i>=0;i-=2){for(var j=1;j<=25;j+=8){outR<<=1;outR|=inR>>>j+i&1}for(var j=1;j<=25;j+=8){outR<<=1;outR|=inL>>>j+i&1}}out[off+0]=outL>>>0;out[off+1]=outR>>>0};exports.rip=function rip(inL,inR,out,off){var outL=0;var outR=0;for(var i=0;i<4;i++){for(var j=24;j>=0;j-=8){outL<<=1;outL|=inR>>>j+i&1;outL<<=1;outL|=inL>>>j+i&1}}for(var i=4;i<8;i++){for(var j=24;j>=0;j-=8){outR<<=1;outR|=inR>>>j+i&1;outR<<=1;outR|=inL>>>j+i&1}}out[off+0]=outL>>>0;out[off+1]=outR>>>0};exports.pc1=function pc1(inL,inR,out,off){var outL=0;var outR=0;for(var i=7;i>=5;i--){for(var j=0;j<=24;j+=8){outL<<=1;outL|=inR>>j+i&1}for(var j=0;j<=24;j+=8){outL<<=1;outL|=inL>>j+i&1}}for(var j=0;j<=24;j+=8){outL<<=1;outL|=inR>>j+i&1}for(var i=1;i<=3;i++){for(var j=0;j<=24;j+=8){outR<<=1;outR|=inR>>j+i&1}for(var j=0;j<=24;j+=8){outR<<=1;outR|=inL>>j+i&1}}for(var j=0;j<=24;j+=8){outR<<=1;outR|=inL>>j+i&1}out[off+0]=outL>>>0;out[off+1]=outR>>>0};exports.r28shl=function r28shl(num,shift){return num<>>28-shift};var pc2table=[14,11,17,4,27,23,25,0,13,22,7,18,5,9,16,24,2,20,12,21,1,8,15,26,15,4,25,19,9,1,26,16,5,11,23,8,12,7,17,0,22,3,10,14,6,20,27,24];exports.pc2=function pc2(inL,inR,out,off){var outL=0;var outR=0;var len=pc2table.length>>>1;for(var i=0;i>>pc2table[i]&1}for(var i=len;i>>pc2table[i]&1}out[off+0]=outL>>>0;out[off+1]=outR>>>0};exports.expand=function expand(r,out,off){var outL=0;var outR=0;outL=(r&1)<<5|r>>>27;for(var i=23;i>=15;i-=4){outL<<=6;outL|=r>>>i&63}for(var i=11;i>=3;i-=4){outR|=r>>>i&63;outR<<=6}outR|=(r&31)<<1|r>>>31;out[off+0]=outL>>>0;out[off+1]=outR>>>0};var sTable=[14,0,4,15,13,7,1,4,2,14,15,2,11,13,8,1,3,10,10,6,6,12,12,11,5,9,9,5,0,3,7,8,4,15,1,12,14,8,8,2,13,4,6,9,2,1,11,7,15,5,12,11,9,3,7,14,3,10,10,0,5,6,0,13,15,3,1,13,8,4,14,7,6,15,11,2,3,8,4,14,9,12,7,0,2,1,13,10,12,6,0,9,5,11,10,5,0,13,14,8,7,10,11,1,10,3,4,15,13,4,1,2,5,11,8,6,12,7,6,12,9,0,3,5,2,14,15,9,10,13,0,7,9,0,14,9,6,3,3,4,15,6,5,10,1,2,13,8,12,5,7,14,11,12,4,11,2,15,8,1,13,1,6,10,4,13,9,0,8,6,15,9,3,8,0,7,11,4,1,15,2,14,12,3,5,11,10,5,14,2,7,12,7,13,13,8,14,11,3,5,0,6,6,15,9,0,10,3,1,4,2,7,8,2,5,12,11,1,12,10,4,14,15,9,10,3,6,15,9,0,0,6,12,10,11,1,7,13,13,8,15,9,1,4,3,5,14,11,5,12,2,7,8,2,4,14,2,14,12,11,4,2,1,12,7,4,10,7,11,13,6,1,8,5,5,0,3,15,15,10,13,3,0,9,14,8,9,6,4,11,2,8,1,12,11,7,10,1,13,14,7,2,8,13,15,6,9,15,12,0,5,9,6,10,3,4,0,5,14,3,12,10,1,15,10,4,15,2,9,7,2,12,6,9,8,5,0,6,13,1,3,13,4,14,14,0,7,11,5,3,11,8,9,4,14,3,15,2,5,12,2,9,8,5,12,15,3,10,7,11,0,14,4,1,10,7,1,6,13,0,11,8,6,13,4,13,11,0,2,11,14,7,15,4,0,9,8,1,13,10,3,14,12,3,9,5,7,12,5,2,10,15,6,8,1,6,1,6,4,11,11,13,13,8,12,1,3,4,7,10,14,7,10,9,15,5,6,0,8,15,0,14,5,2,9,3,2,12,13,1,2,15,8,13,4,8,6,10,15,3,11,7,1,4,10,12,9,5,3,6,14,11,5,0,0,14,12,9,7,2,7,2,11,1,4,14,1,7,9,4,12,10,14,8,2,13,0,15,6,12,10,9,13,0,15,3,3,5,5,6,8,11];exports.substitute=function substitute(inL,inR){var out=0;for(var i=0;i<4;i++){var b=inL>>>18-i*6&63;var sb=sTable[i*64+b];out<<=4;out|=sb}for(var i=0;i<4;i++){var b=inR>>>18-i*6&63;var sb=sTable[4*64+i*64+b];out<<=4;out|=sb}return out>>>0};var permuteTable=[16,25,12,11,3,20,4,15,31,17,9,6,27,14,1,22,30,24,8,18,0,5,29,23,13,19,2,26,10,21,28,7];exports.permute=function permute(num){var out=0;for(var i=0;i>>permuteTable[i]&1}return out>>>0};exports.padSplit=function padSplit(num,size,group){var str=num.toString(2);while(str.lengthbits){num.ishrn(1)}if(num.isEven()){num.iadd(ONE)}if(!num.testn(1)){num.iadd(TWO)}if(!gen.cmp(TWO)){while(num.mod(TWENTYFOUR).cmp(ELEVEN)){num.iadd(FOUR)}}else if(!gen.cmp(FIVE)){while(num.mod(TEN).cmp(THREE)){num.iadd(FOUR)}}n2=num.shrn(1);if(simpleSieve(n2)&&simpleSieve(num)&&fermatTest(n2)&&fermatTest(num)&&millerRabin.test(n2)&&millerRabin.test(num)){return num}}}},{"bn.js":178,"miller-rabin":230,randombytes:258}],177:[function(require,module,exports){module.exports={modp1:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"},modp2:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"},modp5:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"},modp14:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"},modp15:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"},modp16:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"},modp17:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"},modp18:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"}}},{}],178:[function(require,module,exports){arguments[4][107][0].apply(exports,arguments)},{buffer:115,dup:107}],179:[function(require,module,exports){arguments[4][53][0].apply(exports,arguments)},{"../package.json":195,"./elliptic/curve":182,"./elliptic/curves":185,"./elliptic/ec":186,"./elliptic/eddsa":189,"./elliptic/utils":193,brorand:114,dup:53}],180:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var getNAF=utils.getNAF;var getJSF=utils.getJSF;var assert=utils.assert;function BaseCurve(type,conf){this.type=type;this.p=new BN(conf.p,16);this.red=conf.prime?BN.red(conf.prime):BN.mont(this.p);this.zero=new BN(0).toRed(this.red);this.one=new BN(1).toRed(this.red);this.two=new BN(2).toRed(this.red);this.n=conf.n&&new BN(conf.n,16);this.g=conf.g&&this.pointFromJSON(conf.g,conf.gRed);this._wnafT1=new Array(4);this._wnafT2=new Array(4);this._wnafT3=new Array(4);this._wnafT4=new Array(4);this._bitLength=this.n?this.n.bitLength():0;var adjustCount=this.n&&this.p.div(this.n);if(!adjustCount||adjustCount.cmpn(100)>0){this.redN=null}else{this._maxwellTrick=true;this.redN=this.n.toRed(this.red)}}module.exports=BaseCurve;BaseCurve.prototype.point=function point(){throw new Error("Not implemented")};BaseCurve.prototype.validate=function validate(){throw new Error("Not implemented")};BaseCurve.prototype._fixedNafMul=function _fixedNafMul(p,k){assert(p.precomputed);var doubles=p._getDoubles();var naf=getNAF(k,1,this._bitLength);var I=(1<=j;l--)nafW=(nafW<<1)+naf[l];repr.push(nafW)}var a=this.jpoint(null,null,null);var b=this.jpoint(null,null,null);for(var i=I;i>0;i--){for(j=0;j=0;i--){for(var l=0;i>=0&&naf[i]===0;i--)l++;if(i>=0)l++;acc=acc.dblp(l);if(i<0)break;var z=naf[i];assert(z!==0);if(p.type==="affine"){if(z>0)acc=acc.mixedAdd(wnd[z-1>>1]);else acc=acc.mixedAdd(wnd[-z-1>>1].neg())}else{if(z>0)acc=acc.add(wnd[z-1>>1]);else acc=acc.add(wnd[-z-1>>1].neg())}}return p.type==="affine"?acc.toP():acc};BaseCurve.prototype._wnafMulAdd=function _wnafMulAdd(defW,points,coeffs,len,jacobianResult){var wndWidth=this._wnafT1;var wnd=this._wnafT2;var naf=this._wnafT3;var max=0;var i;var j;var p;for(i=0;i=1;i-=2){var a=i-1;var b=i;if(wndWidth[a]!==1||wndWidth[b]!==1){naf[a]=getNAF(coeffs[a],wndWidth[a],this._bitLength);naf[b]=getNAF(coeffs[b],wndWidth[b],this._bitLength);max=Math.max(naf[a].length,max);max=Math.max(naf[b].length,max);continue}var comb=[points[a],null,null,points[b]];if(points[a].y.cmp(points[b].y)===0){comb[1]=points[a].add(points[b]);comb[2]=points[a].toJ().mixedAdd(points[b].neg())}else if(points[a].y.cmp(points[b].y.redNeg())===0){comb[1]=points[a].toJ().mixedAdd(points[b]);comb[2]=points[a].add(points[b].neg())}else{comb[1]=points[a].toJ().mixedAdd(points[b]);comb[2]=points[a].toJ().mixedAdd(points[b].neg())}var index=[-3,-1,-5,-7,0,7,5,1,3];var jsf=getJSF(coeffs[a],coeffs[b]);max=Math.max(jsf[0].length,max);naf[a]=new Array(max);naf[b]=new Array(max);for(j=0;j=0;i--){var k=0;while(i>=0){var zero=true;for(j=0;j=0)k++;acc=acc.dblp(k);if(i<0)break;for(j=0;j0)p=wnd[j][z-1>>1];else if(z<0)p=wnd[j][-z-1>>1].neg();if(p.type==="affine")acc=acc.mixedAdd(p);else acc=acc.add(p)}}for(i=0;i=Math.ceil((k.bitLength()+1)/doubles.step)};BasePoint.prototype._getDoubles=function _getDoubles(step,power){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;var doubles=[this];var acc=this;for(var i=0;i";return""};Point.prototype.isInfinity=function isInfinity(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)};Point.prototype._extDbl=function _extDbl(){var a=this.x.redSqr();var b=this.y.redSqr();var c=this.z.redSqr();c=c.redIAdd(c);var d=this.curve._mulA(a);var e=this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);var g=d.redAdd(b);var f=g.redSub(c);var h=d.redSub(b);var nx=e.redMul(f);var ny=g.redMul(h);var nt=e.redMul(h);var nz=f.redMul(g);return this.curve.point(nx,ny,nz,nt)};Point.prototype._projDbl=function _projDbl(){var b=this.x.redAdd(this.y).redSqr();var c=this.x.redSqr();var d=this.y.redSqr();var nx;var ny;var nz;var e;var h;var j;if(this.curve.twisted){e=this.curve._mulA(c);var f=e.redAdd(d);if(this.zOne){nx=b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));ny=f.redMul(e.redSub(d));nz=f.redSqr().redSub(f).redSub(f)}else{h=this.z.redSqr();j=f.redSub(h).redISub(h);nx=b.redSub(c).redISub(d).redMul(j);ny=f.redMul(e.redSub(d));nz=f.redMul(j)}}else{e=c.redAdd(d);h=this.curve._mulC(this.z).redSqr();j=e.redSub(h).redSub(h);nx=this.curve._mulC(b.redISub(e)).redMul(j);ny=this.curve._mulC(e).redMul(c.redISub(d));nz=e.redMul(j)}return this.curve.point(nx,ny,nz)};Point.prototype.dbl=function dbl(){if(this.isInfinity())return this;if(this.curve.extended)return this._extDbl();else return this._projDbl()};Point.prototype._extAdd=function _extAdd(p){var a=this.y.redSub(this.x).redMul(p.y.redSub(p.x));var b=this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));var c=this.t.redMul(this.curve.dd).redMul(p.t);var d=this.z.redMul(p.z.redAdd(p.z));var e=b.redSub(a);var f=d.redSub(c);var g=d.redAdd(c);var h=b.redAdd(a);var nx=e.redMul(f);var ny=g.redMul(h);var nt=e.redMul(h);var nz=f.redMul(g);return this.curve.point(nx,ny,nz,nt)};Point.prototype._projAdd=function _projAdd(p){var a=this.z.redMul(p.z);var b=a.redSqr();var c=this.x.redMul(p.x);var d=this.y.redMul(p.y);var e=this.curve.d.redMul(c).redMul(d);var f=b.redSub(e);var g=b.redAdd(e);var tmp=this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);var nx=a.redMul(f).redMul(tmp);var ny;var nz;if(this.curve.twisted){ny=a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));nz=f.redMul(g)}else{ny=a.redMul(g).redMul(d.redSub(c));nz=this.curve._mulC(f).redMul(g)}return this.curve.point(nx,ny,nz)};Point.prototype.add=function add(p){if(this.isInfinity())return p;if(p.isInfinity())return this;if(this.curve.extended)return this._extAdd(p);else return this._projAdd(p)};Point.prototype.mul=function mul(k){if(this._hasDoubles(k))return this.curve._fixedNafMul(this,k);else return this.curve._wnafMul(this,k)};Point.prototype.mulAdd=function mulAdd(k1,p,k2){return this.curve._wnafMulAdd(1,[this,p],[k1,k2],2,false)};Point.prototype.jmulAdd=function jmulAdd(k1,p,k2){return this.curve._wnafMulAdd(1,[this,p],[k1,k2],2,true)};Point.prototype.normalize=function normalize(){if(this.zOne)return this;var zi=this.z.redInvm();this.x=this.x.redMul(zi);this.y=this.y.redMul(zi);if(this.t)this.t=this.t.redMul(zi);this.z=this.curve.one;this.zOne=true;return this};Point.prototype.neg=function neg(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())};Point.prototype.getX=function getX(){this.normalize();return this.x.fromRed()};Point.prototype.getY=function getY(){this.normalize();return this.y.fromRed()};Point.prototype.eq=function eq(other){return this===other||this.getX().cmp(other.getX())===0&&this.getY().cmp(other.getY())===0};Point.prototype.eqXToP=function eqXToP(x){var rx=x.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(rx)===0)return true;var xc=x.clone();var t=this.curve.redN.redMul(this.z);for(;;){xc.iadd(this.curve.n);if(xc.cmp(this.curve.p)>=0)return false;rx.redIAdd(t);if(this.x.cmp(rx)===0)return true}};Point.prototype.toP=Point.prototype.normalize;Point.prototype.mixedAdd=Point.prototype.add},{"../utils":193,"./base":180,"bn.js":194,inherits:228}],182:[function(require,module,exports){arguments[4][56][0].apply(exports,arguments)},{"./base":180,"./edwards":181,"./mont":183,"./short":184,dup:56}],183:[function(require,module,exports){arguments[4][57][0].apply(exports,arguments)},{"../utils":193,"./base":180,"bn.js":194,dup:57,inherits:228}],184:[function(require,module,exports){"use strict";var utils=require("../utils");var BN=require("bn.js");var inherits=require("inherits");var Base=require("./base");var assert=utils.assert;function ShortCurve(conf){Base.call(this,"short",conf);this.a=new BN(conf.a,16).toRed(this.red);this.b=new BN(conf.b,16).toRed(this.red);this.tinv=this.two.redInvm();this.zeroA=this.a.fromRed().cmpn(0)===0;this.threeA=this.a.fromRed().sub(this.p).cmpn(-3)===0;this.endo=this._getEndomorphism(conf);this._endoWnafT1=new Array(4);this._endoWnafT2=new Array(4)}inherits(ShortCurve,Base);module.exports=ShortCurve;ShortCurve.prototype._getEndomorphism=function _getEndomorphism(conf){if(!this.zeroA||!this.g||!this.n||this.p.modn(3)!==1)return;var beta;var lambda;if(conf.beta){beta=new BN(conf.beta,16).toRed(this.red)}else{var betas=this._getEndoRoots(this.p);beta=betas[0].cmp(betas[1])<0?betas[0]:betas[1];beta=beta.toRed(this.red)}if(conf.lambda){lambda=new BN(conf.lambda,16)}else{var lambdas=this._getEndoRoots(this.n);if(this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta))===0){lambda=lambdas[0]}else{lambda=lambdas[1];assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta))===0)}}var basis;if(conf.basis){basis=conf.basis.map(function(vec){return{a:new BN(vec.a,16),b:new BN(vec.b,16)}})}else{basis=this._getEndoBasis(lambda)}return{beta:beta,lambda:lambda,basis:basis}};ShortCurve.prototype._getEndoRoots=function _getEndoRoots(num){var red=num===this.p?this.red:BN.mont(num);var tinv=new BN(2).toRed(red).redInvm();var ntinv=tinv.redNeg();var s=new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);var l1=ntinv.redAdd(s).fromRed();var l2=ntinv.redSub(s).fromRed();return[l1,l2]};ShortCurve.prototype._getEndoBasis=function _getEndoBasis(lambda){var aprxSqrt=this.n.ushrn(Math.floor(this.n.bitLength()/2));var u=lambda;var v=this.n.clone();var x1=new BN(1);var y1=new BN(0);var x2=new BN(0);var y2=new BN(1);var a0;var b0;var a1;var b1;var a2;var b2;var prevR;var i=0;var r;var x;while(u.cmpn(0)!==0){var q=v.div(u);r=v.sub(q.mul(u));x=x2.sub(q.mul(x1));var y=y2.sub(q.mul(y1));if(!a1&&r.cmp(aprxSqrt)<0){a0=prevR.neg();b0=x1;a1=r.neg();b1=x}else if(a1&&++i===2){break}prevR=r;v=u;u=r;x2=x1;x1=x;y2=y1;y1=y}a2=r.neg();b2=x;var len1=a1.sqr().add(b1.sqr());var len2=a2.sqr().add(b2.sqr());if(len2.cmp(len1)>=0){a2=a0;b2=b0}if(a1.negative){a1=a1.neg();b1=b1.neg()}if(a2.negative){a2=a2.neg();b2=b2.neg()}return[{a:a1,b:b1},{a:a2,b:b2}]};ShortCurve.prototype._endoSplit=function _endoSplit(k){var basis=this.endo.basis;var v1=basis[0];var v2=basis[1];var c1=v2.b.mul(k).divRound(this.n);var c2=v1.b.neg().mul(k).divRound(this.n);var p1=c1.mul(v1.a);var p2=c2.mul(v2.a);var q1=c1.mul(v1.b);var q2=c2.mul(v2.b);var k1=k.sub(p1).sub(p2);var k2=q1.add(q2).neg();return{k1:k1,k2:k2}};ShortCurve.prototype.pointFromX=function pointFromX(x,odd){x=new BN(x,16);if(!x.red)x=x.toRed(this.red);var y2=x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);var y=y2.redSqrt();if(y.redSqr().redSub(y2).cmp(this.zero)!==0)throw new Error("invalid point");var isOdd=y.fromRed().isOdd();if(odd&&!isOdd||!odd&&isOdd)y=y.redNeg();return this.point(x,y)};ShortCurve.prototype.validate=function validate(point){if(point.inf)return true;var x=point.x;var y=point.y;var ax=this.a.redMul(x);var rhs=x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);return y.redSqr().redISub(rhs).cmpn(0)===0};ShortCurve.prototype._endoWnafMulAdd=function _endoWnafMulAdd(points,coeffs,jacobianResult){var npoints=this._endoWnafT1;var ncoeffs=this._endoWnafT2;for(var i=0;i";return""};Point.prototype.isInfinity=function isInfinity(){return this.inf};Point.prototype.add=function add(p){if(this.inf)return p;if(p.inf)return this;if(this.eq(p))return this.dbl();if(this.neg().eq(p))return this.curve.point(null,null);if(this.x.cmp(p.x)===0)return this.curve.point(null,null);var c=this.y.redSub(p.y);if(c.cmpn(0)!==0)c=c.redMul(this.x.redSub(p.x).redInvm());var nx=c.redSqr().redISub(this.x).redISub(p.x);var ny=c.redMul(this.x.redSub(nx)).redISub(this.y);return this.curve.point(nx,ny)};Point.prototype.dbl=function dbl(){if(this.inf)return this;var ys1=this.y.redAdd(this.y);if(ys1.cmpn(0)===0)return this.curve.point(null,null);var a=this.curve.a;var x2=this.x.redSqr();var dyinv=ys1.redInvm();var c=x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);var nx=c.redSqr().redISub(this.x.redAdd(this.x));var ny=c.redMul(this.x.redSub(nx)).redISub(this.y);return this.curve.point(nx,ny)};Point.prototype.getX=function getX(){return this.x.fromRed()};Point.prototype.getY=function getY(){return this.y.fromRed()};Point.prototype.mul=function mul(k){k=new BN(k,16);if(this.isInfinity())return this;else if(this._hasDoubles(k))return this.curve._fixedNafMul(this,k);else if(this.curve.endo)return this.curve._endoWnafMulAdd([this],[k]);else return this.curve._wnafMul(this,k)};Point.prototype.mulAdd=function mulAdd(k1,p2,k2){var points=[this,p2];var coeffs=[k1,k2];if(this.curve.endo)return this.curve._endoWnafMulAdd(points,coeffs);else return this.curve._wnafMulAdd(1,points,coeffs,2)};Point.prototype.jmulAdd=function jmulAdd(k1,p2,k2){var points=[this,p2];var coeffs=[k1,k2];if(this.curve.endo)return this.curve._endoWnafMulAdd(points,coeffs,true);else return this.curve._wnafMulAdd(1,points,coeffs,2,true)};Point.prototype.eq=function eq(p){return this===p||this.inf===p.inf&&(this.inf||this.x.cmp(p.x)===0&&this.y.cmp(p.y)===0)};Point.prototype.neg=function neg(_precompute){if(this.inf)return this;var res=this.curve.point(this.x,this.y.redNeg());if(_precompute&&this.precomputed){var pre=this.precomputed;var negate=function(p){return p.neg()};res.precomputed={naf:pre.naf&&{wnd:pre.naf.wnd,points:pre.naf.points.map(negate)},doubles:pre.doubles&&{step:pre.doubles.step,points:pre.doubles.points.map(negate)}}}return res};Point.prototype.toJ=function toJ(){if(this.inf)return this.curve.jpoint(null,null,null);var res=this.curve.jpoint(this.x,this.y,this.curve.one);return res};function JPoint(curve,x,y,z){Base.BasePoint.call(this,curve,"jacobian");if(x===null&&y===null&&z===null){this.x=this.curve.one;this.y=this.curve.one;this.z=new BN(0)}else{this.x=new BN(x,16);this.y=new BN(y,16);this.z=new BN(z,16)}if(!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.y.red)this.y=this.y.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red);this.zOne=this.z===this.curve.one}inherits(JPoint,Base.BasePoint);ShortCurve.prototype.jpoint=function jpoint(x,y,z){return new JPoint(this,x,y,z)};JPoint.prototype.toP=function toP(){if(this.isInfinity())return this.curve.point(null,null);var zinv=this.z.redInvm();var zinv2=zinv.redSqr();var ax=this.x.redMul(zinv2);var ay=this.y.redMul(zinv2).redMul(zinv);return this.curve.point(ax,ay)};JPoint.prototype.neg=function neg(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)};JPoint.prototype.add=function add(p){if(this.isInfinity())return p;if(p.isInfinity())return this;var pz2=p.z.redSqr();var z2=this.z.redSqr();var u1=this.x.redMul(pz2);var u2=p.x.redMul(z2);var s1=this.y.redMul(pz2.redMul(p.z));var s2=p.y.redMul(z2.redMul(this.z));var h=u1.redSub(u2);var r=s1.redSub(s2);if(h.cmpn(0)===0){if(r.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl()}var h2=h.redSqr();var h3=h2.redMul(h);var v=u1.redMul(h2);var nx=r.redSqr().redIAdd(h3).redISub(v).redISub(v);var ny=r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));var nz=this.z.redMul(p.z).redMul(h);return this.curve.jpoint(nx,ny,nz)};JPoint.prototype.mixedAdd=function mixedAdd(p){if(this.isInfinity())return p.toJ();if(p.isInfinity())return this;var z2=this.z.redSqr();var u1=this.x;var u2=p.x.redMul(z2);var s1=this.y;var s2=p.y.redMul(z2).redMul(this.z);var h=u1.redSub(u2);var r=s1.redSub(s2);if(h.cmpn(0)===0){if(r.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl()}var h2=h.redSqr();var h3=h2.redMul(h);var v=u1.redMul(h2);var nx=r.redSqr().redIAdd(h3).redISub(v).redISub(v);var ny=r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));var nz=this.z.redMul(h);return this.curve.jpoint(nx,ny,nz)};JPoint.prototype.dblp=function dblp(pow){if(pow===0)return this;if(this.isInfinity())return this;if(!pow)return this.dbl();var i;if(this.curve.zeroA||this.curve.threeA){var r=this;for(i=0;i=0)return false;rx.redIAdd(t);if(this.x.cmp(rx)===0)return true}};JPoint.prototype.inspect=function inspect(){if(this.isInfinity())return"";return""};JPoint.prototype.isInfinity=function isInfinity(){return this.z.cmpn(0)===0}},{"../utils":193,"./base":180,"bn.js":194,inherits:228}],185:[function(require,module,exports){"use strict";var curves=exports;var hash=require("hash.js");var curve=require("./curve");var utils=require("./utils");var assert=utils.assert;function PresetCurve(options){if(options.type==="short")this.curve=new curve.short(options);else if(options.type==="edwards")this.curve=new curve.edwards(options);else this.curve=new curve.mont(options);this.g=this.curve.g;this.n=this.curve.n;this.hash=options.hash;assert(this.g.validate(),"Invalid curve");assert(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}curves.PresetCurve=PresetCurve;function defineCurve(name,options){Object.defineProperty(curves,name,{configurable:true,enumerable:true,get:function(){var curve=new PresetCurve(options);Object.defineProperty(curves,name,{configurable:true,enumerable:true,value:curve});return curve}})}defineCurve("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:hash.sha256,gRed:false,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]});defineCurve("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:hash.sha256,gRed:false,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]});defineCurve("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:hash.sha256,gRed:false,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]});defineCurve("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f "+"5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 "+"f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:hash.sha384,gRed:false,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 "+"5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 "+"0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]});defineCurve("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b "+"99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd "+"3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 "+"f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:hash.sha512,gRed:false,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 "+"053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 "+"a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 "+"579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 "+"3fad0761 353c7086 a272c240 88be9476 9fd16650"]});defineCurve("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:hash.sha256,gRed:false,g:["9"]});defineCurve("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:hash.sha256,gRed:false,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var pre;try{pre=require("./precomputed/secp256k1")}catch(e){pre=undefined}defineCurve("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:hash.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:false,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",pre]})},{"./curve":182,"./precomputed/secp256k1":192,"./utils":193,"hash.js":214}],186:[function(require,module,exports){"use strict";var BN=require("bn.js");var HmacDRBG=require("hmac-drbg");var utils=require("../utils");var curves=require("../curves");var rand=require("brorand");var assert=utils.assert;var KeyPair=require("./key");var Signature=require("./signature");function EC(options){if(!(this instanceof EC))return new EC(options);if(typeof options==="string"){assert(Object.prototype.hasOwnProperty.call(curves,options),"Unknown curve "+options);options=curves[options]}if(options instanceof curves.PresetCurve)options={curve:options};this.curve=options.curve.curve;this.n=this.curve.n;this.nh=this.n.ushrn(1);this.g=this.curve.g;this.g=options.curve.g;this.g.precompute(options.curve.n.bitLength()+1);this.hash=options.hash||options.curve.hash}module.exports=EC;EC.prototype.keyPair=function keyPair(options){return new KeyPair(this,options)};EC.prototype.keyFromPrivate=function keyFromPrivate(priv,enc){return KeyPair.fromPrivate(this,priv,enc)};EC.prototype.keyFromPublic=function keyFromPublic(pub,enc){return KeyPair.fromPublic(this,pub,enc)};EC.prototype.genKeyPair=function genKeyPair(options){if(!options)options={};var drbg=new HmacDRBG({hash:this.hash,pers:options.pers,persEnc:options.persEnc||"utf8",entropy:options.entropy||rand(this.hash.hmacStrength),entropyEnc:options.entropy&&options.entropyEnc||"utf8",nonce:this.n.toArray()});var bytes=this.n.byteLength();var ns2=this.n.sub(new BN(2));for(;;){var priv=new BN(drbg.generate(bytes));if(priv.cmp(ns2)>0)continue;priv.iaddn(1);return this.keyFromPrivate(priv)}};EC.prototype._truncateToN=function _truncateToN(msg,truncOnly){var delta=msg.byteLength()*8-this.n.bitLength();if(delta>0)msg=msg.ushrn(delta);if(!truncOnly&&msg.cmp(this.n)>=0)return msg.sub(this.n);else return msg};EC.prototype.sign=function sign(msg,key,enc,options){if(typeof enc==="object"){options=enc;enc=null}if(!options)options={};key=this.keyFromPrivate(key,enc);msg=this._truncateToN(new BN(msg,16));var bytes=this.n.byteLength();var bkey=key.getPrivate().toArray("be",bytes);var nonce=msg.toArray("be",bytes);var drbg=new HmacDRBG({hash:this.hash,entropy:bkey,nonce:nonce,pers:options.pers,persEnc:options.persEnc||"utf8"});var ns1=this.n.sub(new BN(1));for(var iter=0;;iter++){var k=options.k?options.k(iter):new BN(drbg.generate(this.n.byteLength()));k=this._truncateToN(k,true);if(k.cmpn(1)<=0||k.cmp(ns1)>=0)continue;var kp=this.g.mul(k);if(kp.isInfinity())continue;var kpX=kp.getX();var r=kpX.umod(this.n);if(r.cmpn(0)===0)continue;var s=k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));s=s.umod(this.n);if(s.cmpn(0)===0)continue;var recoveryParam=(kp.getY().isOdd()?1:0)|(kpX.cmp(r)!==0?2:0);if(options.canonical&&s.cmp(this.nh)>0){s=this.n.sub(s);recoveryParam^=1}return new Signature({r:r,s:s,recoveryParam:recoveryParam})}};EC.prototype.verify=function verify(msg,signature,key,enc){msg=this._truncateToN(new BN(msg,16));key=this.keyFromPublic(key,enc);signature=new Signature(signature,"hex");var r=signature.r;var s=signature.s;if(r.cmpn(1)<0||r.cmp(this.n)>=0)return false;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return false;var sinv=s.invm(this.n);var u1=sinv.mul(msg).umod(this.n);var u2=sinv.mul(r).umod(this.n);var p;if(!this.curve._maxwellTrick){p=this.g.mulAdd(u1,key.getPublic(),u2);if(p.isInfinity())return false;return p.getX().umod(this.n).cmp(r)===0}p=this.g.jmulAdd(u1,key.getPublic(),u2);if(p.isInfinity())return false;return p.eqXToP(r)};EC.prototype.recoverPubKey=function(msg,signature,j,enc){assert((3&j)===j,"The recovery param is more than two bits");signature=new Signature(signature,enc);var n=this.n;var e=new BN(msg);var r=signature.r;var s=signature.s;var isYOdd=j&1;var isSecondKey=j>>1;if(r.cmp(this.curve.p.umod(this.curve.n))>=0&&isSecondKey)throw new Error("Unable to find sencond key candinate");if(isSecondKey)r=this.curve.pointFromX(r.add(this.curve.n),isYOdd);else r=this.curve.pointFromX(r,isYOdd);var rInv=signature.r.invm(n);var s1=n.sub(e).mul(rInv).umod(n);var s2=s.mul(rInv).umod(n);return this.g.mulAdd(s1,r,s2)};EC.prototype.getKeyRecoveryParam=function(e,signature,Q,enc){signature=new Signature(signature,enc);if(signature.recoveryParam!==null)return signature.recoveryParam;for(var i=0;i<4;i++){var Qprime;try{Qprime=this.recoverPubKey(e,signature,i)}catch(e){continue}if(Qprime.eq(Q))return i}throw new Error("Unable to find valid recovery factor")}},{"../curves":185,"../utils":193,"./key":187,"./signature":188,"bn.js":194,brorand:114,"hmac-drbg":226}],187:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var assert=utils.assert;function KeyPair(ec,options){this.ec=ec;this.priv=null;this.pub=null;if(options.priv)this._importPrivate(options.priv,options.privEnc);if(options.pub)this._importPublic(options.pub,options.pubEnc)}module.exports=KeyPair;KeyPair.fromPublic=function fromPublic(ec,pub,enc){if(pub instanceof KeyPair)return pub;return new KeyPair(ec,{pub:pub,pubEnc:enc})};KeyPair.fromPrivate=function fromPrivate(ec,priv,enc){if(priv instanceof KeyPair)return priv;return new KeyPair(ec,{priv:priv,privEnc:enc})};KeyPair.prototype.validate=function validate(){var pub=this.getPublic();if(pub.isInfinity())return{result:false,reason:"Invalid public key"};if(!pub.validate())return{result:false,reason:"Public key is not a point"};if(!pub.mul(this.ec.curve.n).isInfinity())return{result:false,reason:"Public key * N != O"};return{result:true,reason:null}};KeyPair.prototype.getPublic=function getPublic(compact,enc){if(typeof compact==="string"){enc=compact;compact=null}if(!this.pub)this.pub=this.ec.g.mul(this.priv);if(!enc)return this.pub;return this.pub.encode(enc,compact)};KeyPair.prototype.getPrivate=function getPrivate(enc){if(enc==="hex")return this.priv.toString(16,2);else return this.priv};KeyPair.prototype._importPrivate=function _importPrivate(key,enc){this.priv=new BN(key,enc||16);this.priv=this.priv.umod(this.ec.curve.n)};KeyPair.prototype._importPublic=function _importPublic(key,enc){if(key.x||key.y){if(this.ec.curve.type==="mont"){assert(key.x,"Need x coordinate")}else if(this.ec.curve.type==="short"||this.ec.curve.type==="edwards"){assert(key.x&&key.y,"Need both x and y coordinate")}this.pub=this.ec.curve.point(key.x,key.y);return}this.pub=this.ec.curve.decodePoint(key,enc)};KeyPair.prototype.derive=function derive(pub){if(!pub.validate()){assert(pub.validate(),"public point not validated")}return pub.mul(this.priv).getX()};KeyPair.prototype.sign=function sign(msg,enc,options){return this.ec.sign(msg,this,enc,options)};KeyPair.prototype.verify=function verify(msg,signature){return this.ec.verify(msg,signature,this)};KeyPair.prototype.inspect=function inspect(){return""}},{"../utils":193,"bn.js":194}],188:[function(require,module,exports){arguments[4][62][0].apply(exports,arguments)},{"../utils":193,"bn.js":194,dup:62}],189:[function(require,module,exports){"use strict";var hash=require("hash.js");var curves=require("../curves");var utils=require("../utils");var assert=utils.assert;var parseBytes=utils.parseBytes;var KeyPair=require("./key");var Signature=require("./signature");function EDDSA(curve){assert(curve==="ed25519","only tested with ed25519 so far");if(!(this instanceof EDDSA))return new EDDSA(curve);curve=curves[curve].curve;this.curve=curve;this.g=curve.g;this.g.precompute(curve.n.bitLength()+1);this.pointClass=curve.point().constructor;this.encodingLength=Math.ceil(curve.n.bitLength()/8);this.hash=hash.sha512}module.exports=EDDSA;EDDSA.prototype.sign=function sign(message,secret){message=parseBytes(message);var key=this.keyFromSecret(secret);var r=this.hashInt(key.messagePrefix(),message);var R=this.g.mul(r);var Rencoded=this.encodePoint(R);var s_=this.hashInt(Rencoded,key.pubBytes(),message).mul(key.priv());var S=r.add(s_).umod(this.curve.n);return this.makeSignature({R:R,S:S,Rencoded:Rencoded})};EDDSA.prototype.verify=function verify(message,sig,pub){message=parseBytes(message);sig=this.makeSignature(sig);var key=this.keyFromPublic(pub);var h=this.hashInt(sig.Rencoded(),key.pubBytes(),message);var SG=this.g.mul(sig.S());var RplusAh=sig.R().add(key.pub().mul(h));return RplusAh.eq(SG)};EDDSA.prototype.hashInt=function hashInt(){var hash=this.hash();for(var i=0;i(ws>>1)-1)z=(ws>>1)-mod;else z=mod;k.isubn(z)}else{z=0}naf[i]=z;k.iushrn(1)}return naf}utils.getNAF=getNAF;function getJSF(k1,k2){var jsf=[[],[]];k1=k1.clone();k2=k2.clone();var d1=0;var d2=0;var m8;while(k1.cmpn(-d1)>0||k2.cmpn(-d2)>0){var m14=k1.andln(3)+d1&3;var m24=k2.andln(3)+d2&3;if(m14===3)m14=-1;if(m24===3)m24=-1;var u1;if((m14&1)===0){u1=0}else{m8=k1.andln(7)+d1&7;if((m8===3||m8===5)&&m24===2)u1=-m14;else u1=m14}jsf[0].push(u1);var u2;if((m24&1)===0){u2=0}else{m8=k2.andln(7)+d2&7;if((m8===3||m8===5)&&m14===2)u2=-m24;else u2=m24}jsf[1].push(u2);if(2*d1===u1+1)d1=1-d1;if(2*d2===u2+1)d2=1-d2;k1.iushrn(1);k2.iushrn(1)}return jsf}utils.getJSF=getJSF;function cachedProperty(obj,name,computer){var key="_"+name;obj.prototype[name]=function cachedProperty(){return this[key]!==undefined?this[key]:this[key]=computer.call(this)}}utils.cachedProperty=cachedProperty;function parseBytes(bytes){return typeof bytes==="string"?utils.toArray(bytes,"hex"):bytes}utils.parseBytes=parseBytes;function intFromLE(bytes){return new BN(bytes,"hex","le")}utils.intFromLE=intFromLE},{"bn.js":194,"minimalistic-assert":232,"minimalistic-crypto-utils":233}],194:[function(require,module,exports){arguments[4][107][0].apply(exports,arguments)},{buffer:115,dup:107}],195:[function(require,module,exports){module.exports={name:"elliptic",version:"6.5.4",description:"EC cryptography",main:"lib/elliptic.js",files:["lib"],scripts:{lint:"eslint lib test","lint:fix":"npm run lint -- --fix",unit:"istanbul test _mocha --reporter=spec test/index.js",test:"npm run lint && npm run unit",version:"grunt dist && git add dist/"},repository:{type:"git",url:"git@github.com:indutny/elliptic"},keywords:["EC","Elliptic","curve","Cryptography"],author:"Fedor Indutny ",license:"MIT",bugs:{url:"https://github.com/indutny/elliptic/issues"},homepage:"https://github.com/indutny/elliptic",devDependencies:{brfs:"^2.0.2",coveralls:"^3.1.0",eslint:"^7.6.0",grunt:"^1.2.1","grunt-browserify":"^5.3.0","grunt-cli":"^1.3.2","grunt-contrib-connect":"^3.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^5.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-saucelabs":"^9.0.1",istanbul:"^0.4.5",mocha:"^8.0.1"},dependencies:{"bn.js":"^4.11.9",brorand:"^1.1.0","hash.js":"^1.0.0","hmac-drbg":"^1.0.1",inherits:"^2.0.4","minimalistic-assert":"^1.0.1","minimalistic-crypto-utils":"^1.0.1"}}},{}],196:[function(require,module,exports){"use strict";var R=typeof Reflect==="object"?Reflect:null;var ReflectApply=R&&typeof R.apply==="function"?R.apply:function ReflectApply(target,receiver,args){return Function.prototype.apply.call(target,receiver,args)};var ReflectOwnKeys;if(R&&typeof R.ownKeys==="function"){ReflectOwnKeys=R.ownKeys}else if(Object.getOwnPropertySymbols){ReflectOwnKeys=function ReflectOwnKeys(target){return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target))}}else{ReflectOwnKeys=function ReflectOwnKeys(target){return Object.getOwnPropertyNames(target)}}function ProcessEmitWarning(warning){if(console&&console.warn)console.warn(warning)}var NumberIsNaN=Number.isNaN||function NumberIsNaN(value){return value!==value};function EventEmitter(){EventEmitter.init.call(this)}module.exports=EventEmitter;module.exports.once=once;EventEmitter.EventEmitter=EventEmitter;EventEmitter.prototype._events=undefined;EventEmitter.prototype._eventsCount=0;EventEmitter.prototype._maxListeners=undefined;var defaultMaxListeners=10;function checkListener(listener){if(typeof listener!=="function"){throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof listener)}}Object.defineProperty(EventEmitter,"defaultMaxListeners",{enumerable:true,get:function(){return defaultMaxListeners},set:function(arg){if(typeof arg!=="number"||arg<0||NumberIsNaN(arg)){throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+arg+".")}defaultMaxListeners=arg}});EventEmitter.init=function(){if(this._events===undefined||this._events===Object.getPrototypeOf(this)._events){this._events=Object.create(null);this._eventsCount=0}this._maxListeners=this._maxListeners||undefined};EventEmitter.prototype.setMaxListeners=function setMaxListeners(n){if(typeof n!=="number"||n<0||NumberIsNaN(n)){throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+n+".")}this._maxListeners=n;return this};function _getMaxListeners(that){if(that._maxListeners===undefined)return EventEmitter.defaultMaxListeners;return that._maxListeners}EventEmitter.prototype.getMaxListeners=function getMaxListeners(){return _getMaxListeners(this)};EventEmitter.prototype.emit=function emit(type){var args=[];for(var i=1;i0)er=args[0];if(er instanceof Error){throw er}var err=new Error("Unhandled error."+(er?" ("+er.message+")":""));err.context=er;throw err}var handler=events[type];if(handler===undefined)return false;if(typeof handler==="function"){ReflectApply(handler,this,args)}else{var len=handler.length;var listeners=arrayClone(handler,len);for(var i=0;i0&&existing.length>m&&!existing.warned){existing.warned=true;var w=new Error("Possible EventEmitter memory leak detected. "+existing.length+" "+String(type)+" listeners "+"added. Use emitter.setMaxListeners() to "+"increase limit");w.name="MaxListenersExceededWarning";w.emitter=target;w.type=type;w.count=existing.length;ProcessEmitWarning(w)}}return target}EventEmitter.prototype.addListener=function addListener(type,listener){return _addListener(this,type,listener,false)};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.prependListener=function prependListener(type,listener){return _addListener(this,type,listener,true)};function onceWrapper(){if(!this.fired){this.target.removeListener(this.type,this.wrapFn);this.fired=true;if(arguments.length===0)return this.listener.call(this.target);return this.listener.apply(this.target,arguments)}}function _onceWrap(target,type,listener){var state={fired:false,wrapFn:undefined,target:target,type:type,listener:listener};var wrapped=onceWrapper.bind(state);wrapped.listener=listener;state.wrapFn=wrapped;return wrapped}EventEmitter.prototype.once=function once(type,listener){checkListener(listener);this.on(type,_onceWrap(this,type,listener));return this};EventEmitter.prototype.prependOnceListener=function prependOnceListener(type,listener){checkListener(listener);this.prependListener(type,_onceWrap(this,type,listener));return this};EventEmitter.prototype.removeListener=function removeListener(type,listener){var list,events,position,i,originalListener;checkListener(listener);events=this._events;if(events===undefined)return this;list=events[type];if(list===undefined)return this;if(list===listener||list.listener===listener){if(--this._eventsCount===0)this._events=Object.create(null);else{delete events[type];if(events.removeListener)this.emit("removeListener",type,list.listener||listener)}}else if(typeof list!=="function"){position=-1;for(i=list.length-1;i>=0;i--){if(list[i]===listener||list[i].listener===listener){originalListener=list[i].listener;position=i;break}}if(position<0)return this;if(position===0)list.shift();else{spliceOne(list,position)}if(list.length===1)events[type]=list[0];if(events.removeListener!==undefined)this.emit("removeListener",type,originalListener||listener)}return this};EventEmitter.prototype.off=EventEmitter.prototype.removeListener;EventEmitter.prototype.removeAllListeners=function removeAllListeners(type){var listeners,events,i;events=this._events;if(events===undefined)return this;if(events.removeListener===undefined){if(arguments.length===0){this._events=Object.create(null);this._eventsCount=0}else if(events[type]!==undefined){if(--this._eventsCount===0)this._events=Object.create(null);else delete events[type]}return this}if(arguments.length===0){var keys=Object.keys(events);var key;for(i=0;i=0;i--){this.removeListener(type,listeners[i])}}return this};function _listeners(target,type,unwrap){var events=target._events;if(events===undefined)return[];var evlistener=events[type];if(evlistener===undefined)return[];if(typeof evlistener==="function")return unwrap?[evlistener.listener||evlistener]:[evlistener];return unwrap?unwrapListeners(evlistener):arrayClone(evlistener,evlistener.length)}EventEmitter.prototype.listeners=function listeners(type){return _listeners(this,type,true)};EventEmitter.prototype.rawListeners=function rawListeners(type){return _listeners(this,type,false)};EventEmitter.listenerCount=function(emitter,type){if(typeof emitter.listenerCount==="function"){return emitter.listenerCount(type)}else{return listenerCount.call(emitter,type)}};EventEmitter.prototype.listenerCount=listenerCount;function listenerCount(type){var events=this._events;if(events!==undefined){var evlistener=events[type];if(typeof evlistener==="function"){return 1}else if(evlistener!==undefined){return evlistener.length}}return 0}EventEmitter.prototype.eventNames=function eventNames(){return this._eventsCount>0?ReflectOwnKeys(this._events):[]};function arrayClone(arr,n){var copy=new Array(n);for(var i=0;i0||ivLen>0){var hash=new MD5;hash.update(tmp);hash.update(password);if(salt)hash.update(salt);tmp=hash.digest();var used=0;if(keyLen>0){var keyStart=key.length-keyLen;used=Math.min(keyLen,tmp.length);tmp.copy(key,keyStart,0,used);keyLen-=used}if(used0){var ivStart=iv.length-ivLen;var length=Math.min(ivLen,tmp.length-used);tmp.copy(iv,ivStart,used,used+length);ivLen-=length}}tmp.fill(0);return{key:key,iv:iv}}module.exports=EVP_BytesToKey},{"md5.js":229,"safe-buffer":261}],198:[function(require,module,exports){"use strict";var Buffer=require("safe-buffer").Buffer;var Transform=require("readable-stream").Transform;var inherits=require("inherits");function throwIfNotStringOrBuffer(val,prefix){if(!Buffer.isBuffer(val)&&typeof val!=="string"){throw new TypeError(prefix+" must be a string or a buffer")}}function HashBase(blockSize){Transform.call(this);this._block=Buffer.allocUnsafe(blockSize);this._blockSize=blockSize;this._blockOffset=0;this._length=[0,0,0,0];this._finalized=false}inherits(HashBase,Transform);HashBase.prototype._transform=function(chunk,encoding,callback){var error=null;try{this.update(chunk,encoding)}catch(err){error=err}callback(error)};HashBase.prototype._flush=function(callback){var error=null;try{this.push(this.digest())}catch(err){error=err}callback(error)};HashBase.prototype.update=function(data,encoding){throwIfNotStringOrBuffer(data,"Data");if(this._finalized)throw new Error("Digest already called");if(!Buffer.isBuffer(data))data=Buffer.from(data,encoding);var block=this._block;var offset=0;while(this._blockOffset+data.length-offset>=this._blockSize){for(var i=this._blockOffset;i0;++j){this._length[j]+=carry;carry=this._length[j]/4294967296|0;if(carry>0)this._length[j]-=4294967296*carry}return this};HashBase.prototype._update=function(){throw new Error("_update is not implemented")};HashBase.prototype.digest=function(encoding){if(this._finalized)throw new Error("Digest already called");this._finalized=true;var digest=this._digest();if(encoding!==undefined)digest=digest.toString(encoding);this._block.fill(0);this._blockOffset=0;for(var i=0;i<4;++i)this._length[i]=0;return digest};HashBase.prototype._digest=function(){throw new Error("_digest is not implemented")};module.exports=HashBase},{inherits:228,"readable-stream":213,"safe-buffer":261}],199:[function(require,module,exports){arguments[4][143][0].apply(exports,arguments)},{dup:143}],200:[function(require,module,exports){arguments[4][144][0].apply(exports,arguments)},{"./_stream_readable":202,"./_stream_writable":204,_process:246,dup:144,inherits:228}],201:[function(require,module,exports){arguments[4][145][0].apply(exports,arguments)},{"./_stream_transform":203,dup:145,inherits:228}],202:[function(require,module,exports){arguments[4][146][0].apply(exports,arguments)},{"../errors":199,"./_stream_duplex":200,"./internal/streams/async_iterator":205,"./internal/streams/buffer_list":206,"./internal/streams/destroy":207,"./internal/streams/from":209,"./internal/streams/state":211,"./internal/streams/stream":212,_process:246,buffer:159,dup:146,events:196,inherits:228,"string_decoder/":286,util:115}],203:[function(require,module,exports){arguments[4][147][0].apply(exports,arguments)},{"../errors":199,"./_stream_duplex":200,dup:147,inherits:228}],204:[function(require,module,exports){arguments[4][148][0].apply(exports,arguments)},{"../errors":199,"./_stream_duplex":200,"./internal/streams/destroy":207,"./internal/streams/state":211,"./internal/streams/stream":212,_process:246,buffer:159,dup:148,inherits:228,"util-deprecate":290}],205:[function(require,module,exports){arguments[4][149][0].apply(exports,arguments)},{"./end-of-stream":208,_process:246,dup:149}],206:[function(require,module,exports){arguments[4][150][0].apply(exports,arguments)},{buffer:159,dup:150,util:115}],207:[function(require,module,exports){arguments[4][151][0].apply(exports,arguments)},{_process:246,dup:151}],208:[function(require,module,exports){arguments[4][152][0].apply(exports,arguments)},{"../../../errors":199,dup:152}],209:[function(require,module,exports){arguments[4][153][0].apply(exports,arguments)},{dup:153}],210:[function(require,module,exports){arguments[4][154][0].apply(exports,arguments)},{"../../../errors":199,"./end-of-stream":208,dup:154}],211:[function(require,module,exports){arguments[4][155][0].apply(exports,arguments)},{"../../../errors":199,dup:155}],212:[function(require,module,exports){arguments[4][156][0].apply(exports,arguments)},{dup:156,events:196}],213:[function(require,module,exports){arguments[4][157][0].apply(exports,arguments)},{"./lib/_stream_duplex.js":200,"./lib/_stream_passthrough.js":201,"./lib/_stream_readable.js":202,"./lib/_stream_transform.js":203,"./lib/_stream_writable.js":204,"./lib/internal/streams/end-of-stream.js":208,"./lib/internal/streams/pipeline.js":210,dup:157}],214:[function(require,module,exports){arguments[4][69][0].apply(exports,arguments)},{"./hash/common":215,"./hash/hmac":216,"./hash/ripemd":217,"./hash/sha":218,"./hash/utils":225,dup:69}],215:[function(require,module,exports){arguments[4][70][0].apply(exports,arguments)},{"./utils":225,dup:70,"minimalistic-assert":232}],216:[function(require,module,exports){arguments[4][71][0].apply(exports,arguments)},{"./utils":225,dup:71,"minimalistic-assert":232}],217:[function(require,module,exports){arguments[4][72][0].apply(exports,arguments)},{"./common":215,"./utils":225,dup:72}],218:[function(require,module,exports){arguments[4][73][0].apply(exports,arguments)},{"./sha/1":219,"./sha/224":220,"./sha/256":221,"./sha/384":222,"./sha/512":223,dup:73}],219:[function(require,module,exports){arguments[4][74][0].apply(exports,arguments)},{"../common":215,"../utils":225,"./common":224,dup:74}],220:[function(require,module,exports){arguments[4][75][0].apply(exports,arguments)},{"../utils":225,"./256":221,dup:75}],221:[function(require,module,exports){arguments[4][76][0].apply(exports,arguments)},{"../common":215,"../utils":225,"./common":224,dup:76,"minimalistic-assert":232}],222:[function(require,module,exports){arguments[4][77][0].apply(exports,arguments)},{"../utils":225,"./512":223,dup:77}],223:[function(require,module,exports){arguments[4][78][0].apply(exports,arguments)},{"../common":215,"../utils":225,dup:78,"minimalistic-assert":232}],224:[function(require,module,exports){arguments[4][79][0].apply(exports,arguments)},{"../utils":225,dup:79}],225:[function(require,module,exports){arguments[4][80][0].apply(exports,arguments)},{dup:80,inherits:228,"minimalistic-assert":232}],226:[function(require,module,exports){arguments[4][82][0].apply(exports,arguments)},{dup:82,"hash.js":214,"minimalistic-assert":232,"minimalistic-crypto-utils":233}],227:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m;var eLen=nBytes*8-mLen-1;var eMax=(1<>1;var nBits=-7;var i=isLE?nBytes-1:0;var d=isLE?-1:1;var s=buffer[offset+i];i+=d;e=s&(1<<-nBits)-1;s>>=-nBits;nBits+=eLen;for(;nBits>0;e=e*256+buffer[offset+i],i+=d,nBits-=8){}m=e&(1<<-nBits)-1;e>>=-nBits;nBits+=mLen;for(;nBits>0;m=m*256+buffer[offset+i],i+=d,nBits-=8){}if(e===0){e=1-eBias}else if(e===eMax){return m?NaN:(s?-1:1)*Infinity}else{m=m+Math.pow(2,mLen);e=e-eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)};exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c;var eLen=nBytes*8-mLen-1;var eMax=(1<>1;var rt=mLen===23?Math.pow(2,-24)-Math.pow(2,-77):0;var i=isLE?0:nBytes-1;var d=isLE?1:-1;var s=value<0||value===0&&1/value<0?1:0;value=Math.abs(value);if(isNaN(value)||value===Infinity){m=isNaN(value)?1:0;e=eMax}else{e=Math.floor(Math.log(value)/Math.LN2);if(value*(c=Math.pow(2,-e))<1){e--;c*=2}if(e+eBias>=1){value+=rt/c}else{value+=rt*Math.pow(2,1-eBias)}if(value*c>=2){e++;c/=2}if(e+eBias>=eMax){m=0;e=eMax}else if(e+eBias>=1){m=(value*c-1)*Math.pow(2,mLen);e=e+eBias}else{m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen);e=0}}for(;mLen>=8;buffer[offset+i]=m&255,i+=d,m/=256,mLen-=8){}e=e<0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8){}buffer[offset+i-d]|=s*128}},{}],228:[function(require,module,exports){arguments[4][81][0].apply(exports,arguments)},{dup:81}],229:[function(require,module,exports){"use strict";var inherits=require("inherits");var HashBase=require("hash-base");var Buffer=require("safe-buffer").Buffer;var ARRAY16=new Array(16);function MD5(){HashBase.call(this,64);this._a=1732584193;this._b=4023233417;this._c=2562383102;this._d=271733878}inherits(MD5,HashBase);MD5.prototype._update=function(){var M=ARRAY16;for(var i=0;i<16;++i)M[i]=this._block.readInt32LE(i*4);var a=this._a;var b=this._b;var c=this._c;var d=this._d;a=fnF(a,b,c,d,M[0],3614090360,7);d=fnF(d,a,b,c,M[1],3905402710,12);c=fnF(c,d,a,b,M[2],606105819,17);b=fnF(b,c,d,a,M[3],3250441966,22);a=fnF(a,b,c,d,M[4],4118548399,7);d=fnF(d,a,b,c,M[5],1200080426,12);c=fnF(c,d,a,b,M[6],2821735955,17);b=fnF(b,c,d,a,M[7],4249261313,22);a=fnF(a,b,c,d,M[8],1770035416,7);d=fnF(d,a,b,c,M[9],2336552879,12);c=fnF(c,d,a,b,M[10],4294925233,17);b=fnF(b,c,d,a,M[11],2304563134,22);a=fnF(a,b,c,d,M[12],1804603682,7);d=fnF(d,a,b,c,M[13],4254626195,12);c=fnF(c,d,a,b,M[14],2792965006,17);b=fnF(b,c,d,a,M[15],1236535329,22);a=fnG(a,b,c,d,M[1],4129170786,5);d=fnG(d,a,b,c,M[6],3225465664,9);c=fnG(c,d,a,b,M[11],643717713,14);b=fnG(b,c,d,a,M[0],3921069994,20);a=fnG(a,b,c,d,M[5],3593408605,5);d=fnG(d,a,b,c,M[10],38016083,9);c=fnG(c,d,a,b,M[15],3634488961,14);b=fnG(b,c,d,a,M[4],3889429448,20);a=fnG(a,b,c,d,M[9],568446438,5);d=fnG(d,a,b,c,M[14],3275163606,9);c=fnG(c,d,a,b,M[3],4107603335,14);b=fnG(b,c,d,a,M[8],1163531501,20);a=fnG(a,b,c,d,M[13],2850285829,5);d=fnG(d,a,b,c,M[2],4243563512,9);c=fnG(c,d,a,b,M[7],1735328473,14);b=fnG(b,c,d,a,M[12],2368359562,20);a=fnH(a,b,c,d,M[5],4294588738,4);d=fnH(d,a,b,c,M[8],2272392833,11);c=fnH(c,d,a,b,M[11],1839030562,16);b=fnH(b,c,d,a,M[14],4259657740,23);a=fnH(a,b,c,d,M[1],2763975236,4);d=fnH(d,a,b,c,M[4],1272893353,11);c=fnH(c,d,a,b,M[7],4139469664,16);b=fnH(b,c,d,a,M[10],3200236656,23);a=fnH(a,b,c,d,M[13],681279174,4);d=fnH(d,a,b,c,M[0],3936430074,11);c=fnH(c,d,a,b,M[3],3572445317,16);b=fnH(b,c,d,a,M[6],76029189,23);a=fnH(a,b,c,d,M[9],3654602809,4);d=fnH(d,a,b,c,M[12],3873151461,11);c=fnH(c,d,a,b,M[15],530742520,16);b=fnH(b,c,d,a,M[2],3299628645,23);a=fnI(a,b,c,d,M[0],4096336452,6);d=fnI(d,a,b,c,M[7],1126891415,10);c=fnI(c,d,a,b,M[14],2878612391,15);b=fnI(b,c,d,a,M[5],4237533241,21);a=fnI(a,b,c,d,M[12],1700485571,6);d=fnI(d,a,b,c,M[3],2399980690,10);c=fnI(c,d,a,b,M[10],4293915773,15);b=fnI(b,c,d,a,M[1],2240044497,21);a=fnI(a,b,c,d,M[8],1873313359,6);d=fnI(d,a,b,c,M[15],4264355552,10);c=fnI(c,d,a,b,M[6],2734768916,15);b=fnI(b,c,d,a,M[13],1309151649,21);a=fnI(a,b,c,d,M[4],4149444226,6);d=fnI(d,a,b,c,M[11],3174756917,10);c=fnI(c,d,a,b,M[2],718787259,15);b=fnI(b,c,d,a,M[9],3951481745,21);this._a=this._a+a|0;this._b=this._b+b|0;this._c=this._c+c|0;this._d=this._d+d|0};MD5.prototype._digest=function(){this._block[this._blockOffset++]=128;if(this._blockOffset>56){this._block.fill(0,this._blockOffset,64);this._update();this._blockOffset=0}this._block.fill(0,this._blockOffset,56);this._block.writeUInt32LE(this._length[0],56);this._block.writeUInt32LE(this._length[1],60);this._update();var buffer=Buffer.allocUnsafe(16);buffer.writeInt32LE(this._a,0);buffer.writeInt32LE(this._b,4);buffer.writeInt32LE(this._c,8);buffer.writeInt32LE(this._d,12);return buffer};function rotl(x,n){return x<>>32-n}function fnF(a,b,c,d,m,k,s){return rotl(a+(b&c|~b&d)+m+k|0,s)+b|0}function fnG(a,b,c,d,m,k,s){return rotl(a+(b&d|c&~d)+m+k|0,s)+b|0}function fnH(a,b,c,d,m,k,s){return rotl(a+(b^c^d)+m+k|0,s)+b|0}function fnI(a,b,c,d,m,k,s){return rotl(a+(c^(b|~d))+m+k|0,s)+b|0}module.exports=MD5},{"hash-base":198,inherits:228,"safe-buffer":261}],230:[function(require,module,exports){var bn=require("bn.js");var brorand=require("brorand");function MillerRabin(rand){this.rand=rand||new brorand.Rand}module.exports=MillerRabin;MillerRabin.create=function create(rand){return new MillerRabin(rand)};MillerRabin.prototype._randbelow=function _randbelow(n){var len=n.bitLength();var min_bytes=Math.ceil(len/8);do{var a=new bn(this.rand.generate(min_bytes))}while(a.cmp(n)>=0);return a};MillerRabin.prototype._randrange=function _randrange(start,stop){var size=stop.sub(start);return start.add(this._randbelow(size))};MillerRabin.prototype.test=function test(n,k,cb){var len=n.bitLength();var red=bn.mont(n);var rone=new bn(1).toRed(red);if(!k)k=Math.max(1,len/48|0);var n1=n.subn(1);for(var s=0;!n1.testn(s);s++){}var d=n.shrn(s);var rn1=n1.toRed(red);var prime=true;for(;k>0;k--){var a=this._randrange(new bn(2),n1);if(cb)cb(a);var x=a.toRed(red).redPow(d);if(x.cmp(rone)===0||x.cmp(rn1)===0)continue;for(var i=1;i0;k--){var a=this._randrange(new bn(2),n1);var g=n.gcd(a);if(g.cmpn(1)!==0)return g;var x=a.toRed(red).redPow(d);if(x.cmp(rone)===0||x.cmp(rn1)===0)continue;for(var i=1;i=6?"utf-8":"binary"}else{defaultEncoding="utf-8"}module.exports=defaultEncoding}).call(this)}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{_process:246}],243:[function(require,module,exports){var MAX_ALLOC=Math.pow(2,30)-1;module.exports=function(iterations,keylen){if(typeof iterations!=="number"){throw new TypeError("Iterations not a number")}if(iterations<0){throw new TypeError("Bad iterations")}if(typeof keylen!=="number"){throw new TypeError("Key length not a number")}if(keylen<0||keylen>MAX_ALLOC||keylen!==keylen){throw new TypeError("Bad key length")}}},{}],244:[function(require,module,exports){var md5=require("create-hash/md5");var RIPEMD160=require("ripemd160");var sha=require("sha.js");var Buffer=require("safe-buffer").Buffer;var checkParameters=require("./precondition");var defaultEncoding=require("./default-encoding");var toBuffer=require("./to-buffer");var ZEROS=Buffer.alloc(128);var sizes={md5:16,sha1:20,sha224:28,sha256:32,sha384:48,sha512:64,rmd160:20,ripemd160:20};function Hmac(alg,key,saltLen){var hash=getDigest(alg);var blocksize=alg==="sha512"||alg==="sha384"?128:64;if(key.length>blocksize){key=hash(key)}else if(key.length1){for(var i=1;ik||new BN(enc).cmp(key.modulus)>=0){throw new Error("decryption error")}var msg;if(reverse){msg=withPublic(new BN(enc),key)}else{msg=crt(enc,key)}var zBuffer=Buffer.alloc(k-msg.length);msg=Buffer.concat([zBuffer,msg],k);if(padding===4){return oaep(key,msg)}else if(padding===1){return pkcs1(key,msg,reverse)}else if(padding===3){return msg}else{throw new Error("unknown padding")}};function oaep(key,msg){var k=key.modulus.byteLength();var iHash=createHash("sha1").update(Buffer.alloc(0)).digest();var hLen=iHash.length;if(msg[0]!==0){throw new Error("decryption error")}var maskedSeed=msg.slice(1,hLen+1);var maskedDb=msg.slice(hLen+1);var seed=xor(maskedSeed,mgf(maskedDb,hLen));var db=xor(maskedDb,mgf(seed,k-hLen-1));if(compare(iHash,db.slice(0,hLen))){throw new Error("decryption error")}var i=hLen;while(db[i]===0){i++}if(db[i++]!==1){throw new Error("decryption error")}return db.slice(i)}function pkcs1(key,msg,reverse){var p1=msg.slice(0,2);var i=2;var status=0;while(msg[i++]!==0){if(i>=msg.length){status++;break}}var ps=msg.slice(2,i-1);if(p1.toString("hex")!=="0002"&&!reverse||p1.toString("hex")!=="0001"&&reverse){status++}if(ps.length<8){status++}if(status){throw new Error("decryption error")}return msg.slice(i)}function compare(a,b){a=Buffer.from(a);b=Buffer.from(b);var dif=0;var len=a.length;if(a.length!==b.length){dif++;len=Math.min(a.length,b.length)}var i=-1;while(++i=0){throw new Error("data too long for modulus")}}else{throw new Error("unknown padding")}if(reverse){return crt(paddedMsg,key)}else{return withPublic(paddedMsg,key)}};function oaep(key,msg){var k=key.modulus.byteLength();var mLen=msg.length;var iHash=createHash("sha1").update(Buffer.alloc(0)).digest();var hLen=iHash.length;var hLen2=2*hLen;if(mLen>k-hLen2-2){throw new Error("message too long")}var ps=Buffer.alloc(k-mLen-hLen2-2);var dblen=k-hLen-1;var seed=randomBytes(hLen);var maskedDb=xor(Buffer.concat([iHash,ps,Buffer.alloc(1,1),msg],dblen),mgf(seed,dblen));var maskedSeed=xor(seed,mgf(maskedDb,hLen));return new BN(Buffer.concat([Buffer.alloc(1),maskedSeed,maskedDb],k))}function pkcs1(key,msg,reverse){var mLen=msg.length;var k=key.modulus.byteLength();if(mLen>k-11){throw new Error("message too long")}var ps;if(reverse){ps=Buffer.alloc(k-mLen-3,255)}else{ps=nonZero(k-mLen-3)}return new BN(Buffer.concat([Buffer.from([0,reverse?1:2]),ps,Buffer.alloc(1),msg],k))}function nonZero(len){var out=Buffer.allocUnsafe(len);var i=0;var cache=randomBytes(len*2);var cur=0;var num;while(i= 0x80 (not a basic code point)","invalid-input":"Invalid input"},baseMinusTMin=base-tMin,floor=Math.floor,stringFromCharCode=String.fromCharCode,key;function error(type){throw new RangeError(errors[type])}function map(array,fn){var length=array.length;var result=[];while(length--){result[length]=fn(array[length])}return result}function mapDomain(string,fn){var parts=string.split("@");var result="";if(parts.length>1){result=parts[0]+"@";string=parts[1]}string=string.replace(regexSeparators,".");var labels=string.split(".");var encoded=map(labels,fn).join(".");return result+encoded}function ucs2decode(string){var output=[],counter=0,length=string.length,value,extra;while(counter=55296&&value<=56319&&counter65535){value-=65536;output+=stringFromCharCode(value>>>10&1023|55296);value=56320|value&1023}output+=stringFromCharCode(value);return output}).join("")}function basicToDigit(codePoint){if(codePoint-48<10){return codePoint-22}if(codePoint-65<26){return codePoint-65}if(codePoint-97<26){return codePoint-97}return base}function digitToBasic(digit,flag){return digit+22+75*(digit<26)-((flag!=0)<<5)}function adapt(delta,numPoints,firstTime){var k=0;delta=firstTime?floor(delta/damp):delta>>1;delta+=floor(delta/numPoints);for(;delta>baseMinusTMin*tMax>>1;k+=base){delta=floor(delta/baseMinusTMin)}return floor(k+(baseMinusTMin+1)*delta/(delta+skew))}function decode(input){var output=[],inputLength=input.length,out,i=0,n=initialN,bias=initialBias,basic,j,index,oldi,w,k,digit,t,baseMinusT;basic=input.lastIndexOf(delimiter);if(basic<0){basic=0}for(j=0;j=128){error("not-basic")}output.push(input.charCodeAt(j))}for(index=basic>0?basic+1:0;index=inputLength){error("invalid-input")}digit=basicToDigit(input.charCodeAt(index++));if(digit>=base||digit>floor((maxInt-i)/w)){error("overflow")}i+=digit*w;t=k<=bias?tMin:k>=bias+tMax?tMax:k-bias;if(digitfloor(maxInt/baseMinusT)){error("overflow")}w*=baseMinusT}out=output.length+1;bias=adapt(i-oldi,out,oldi==0);if(floor(i/out)>maxInt-n){error("overflow")}n+=floor(i/out);i%=out;output.splice(i++,0,n)}return ucs2encode(output)}function encode(input){var n,delta,handledCPCount,basicLength,bias,j,m,q,k,t,currentValue,output=[],inputLength,handledCPCountPlusOne,baseMinusT,qMinusT;input=ucs2decode(input);inputLength=input.length;n=initialN;delta=0;bias=initialBias;for(j=0;j=n&¤tValuefloor((maxInt-delta)/handledCPCountPlusOne)){error("overflow")}delta+=(m-n)*handledCPCountPlusOne;n=m;for(j=0;jmaxInt){error("overflow")}if(currentValue==n){for(q=delta,k=base;;k+=base){t=k<=bias?tMin:k>=bias+tMax?tMax:k-bias;if(q0&&len>maxKeys){len=maxKeys}for(var i=0;i=0){kstr=x.substr(0,idx);vstr=x.substr(idx+1)}else{kstr=x;vstr=""}k=decodeURIComponent(kstr);v=decodeURIComponent(vstr);if(!hasOwnProperty(obj,k)){obj[k]=v}else if(isArray(obj[k])){obj[k].push(v)}else{obj[k]=[obj[k],v]}}return obj};var isArray=Array.isArray||function(xs){return Object.prototype.toString.call(xs)==="[object Array]"}},{}],256:[function(require,module,exports){"use strict";var stringifyPrimitive=function(v){switch(typeof v){case"string":return v;case"boolean":return v?"true":"false";case"number":return isFinite(v)?v:"";default:return""}};module.exports=function(obj,sep,eq,name){sep=sep||"&";eq=eq||"=";if(obj===null){obj=undefined}if(typeof obj==="object"){return map(objectKeys(obj),function(k){var ks=encodeURIComponent(stringifyPrimitive(k))+eq;if(isArray(obj[k])){return map(obj[k],function(v){return ks+encodeURIComponent(stringifyPrimitive(v))}).join(sep)}else{return ks+encodeURIComponent(stringifyPrimitive(obj[k]))}}).join(sep)}if(!name)return"";return encodeURIComponent(stringifyPrimitive(name))+eq+encodeURIComponent(stringifyPrimitive(obj))};var isArray=Array.isArray||function(xs){return Object.prototype.toString.call(xs)==="[object Array]"};function map(xs,f){if(xs.map)return xs.map(f);var res=[];for(var i=0;iMAX_UINT32)throw new RangeError("requested too many random bytes");var bytes=Buffer.allocUnsafe(size);if(size>0){if(size>MAX_BYTES){for(var generated=0;generatedkMaxUint32||offset<0){throw new TypeError("offset must be a uint32")}if(offset>kBufferMaxLength||offset>length){throw new RangeError("offset out of range")}}function assertSize(size,offset,length){if(typeof size!=="number"||size!==size){throw new TypeError("size must be a number")}if(size>kMaxUint32||size<0){throw new TypeError("size must be a uint32")}if(size+offset>length||size>kBufferMaxLength){throw new RangeError("buffer too small")}}if(crypto&&crypto.getRandomValues||!process.browser){exports.randomFill=randomFill;exports.randomFillSync=randomFillSync}else{exports.randomFill=oldBrowser;exports.randomFillSync=oldBrowser}function randomFill(buf,offset,size,cb){if(!Buffer.isBuffer(buf)&&!(buf instanceof global.Uint8Array)){throw new TypeError('"buf" argument must be a Buffer or Uint8Array')}if(typeof offset==="function"){cb=offset;offset=0;size=buf.length}else if(typeof size==="function"){cb=size;size=buf.length-offset}else if(typeof cb!=="function"){throw new TypeError('"cb" argument must be a function')}assertOffset(offset,buf.length);assertSize(size,offset,buf.length);return actualFill(buf,offset,size,cb)}function actualFill(buf,offset,size,cb){if(process.browser){var ourBuf=buf.buffer;var uint=new Uint8Array(ourBuf,offset,size);crypto.getRandomValues(uint);if(cb){process.nextTick(function(){cb(null,buf)});return}return buf}if(cb){randombytes(size,function(err,bytes){if(err){return cb(err)}bytes.copy(buf,offset);cb(null,buf)});return}var bytes=randombytes(size);bytes.copy(buf,offset);return buf}function randomFillSync(buf,offset,size){if(typeof offset==="undefined"){offset=0}if(!Buffer.isBuffer(buf)&&!(buf instanceof global.Uint8Array)){throw new TypeError('"buf" argument must be a Buffer or Uint8Array')}assertOffset(offset,buf.length);if(size===undefined)size=buf.length-offset;assertSize(size,offset,buf.length);return actualFill(buf,offset,size)}}).call(this)}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{_process:246,randombytes:258,"safe-buffer":261}],260:[function(require,module,exports){"use strict";var Buffer=require("buffer").Buffer;var inherits=require("inherits");var HashBase=require("hash-base");var ARRAY16=new Array(16);var zl=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13];var zr=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11];var sl=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6];var sr=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11];var hl=[0,1518500249,1859775393,2400959708,2840853838];var hr=[1352829926,1548603684,1836072691,2053994217,0];function RIPEMD160(){HashBase.call(this,64);this._a=1732584193;this._b=4023233417;this._c=2562383102;this._d=271733878;this._e=3285377520}inherits(RIPEMD160,HashBase);RIPEMD160.prototype._update=function(){var words=ARRAY16;for(var j=0;j<16;++j)words[j]=this._block.readInt32LE(j*4);var al=this._a|0;var bl=this._b|0;var cl=this._c|0;var dl=this._d|0;var el=this._e|0;var ar=this._a|0;var br=this._b|0;var cr=this._c|0;var dr=this._d|0;var er=this._e|0;for(var i=0;i<80;i+=1){var tl;var tr;if(i<16){tl=fn1(al,bl,cl,dl,el,words[zl[i]],hl[0],sl[i]);tr=fn5(ar,br,cr,dr,er,words[zr[i]],hr[0],sr[i])}else if(i<32){tl=fn2(al,bl,cl,dl,el,words[zl[i]],hl[1],sl[i]);tr=fn4(ar,br,cr,dr,er,words[zr[i]],hr[1],sr[i])}else if(i<48){tl=fn3(al,bl,cl,dl,el,words[zl[i]],hl[2],sl[i]);tr=fn3(ar,br,cr,dr,er,words[zr[i]],hr[2],sr[i])}else if(i<64){tl=fn4(al,bl,cl,dl,el,words[zl[i]],hl[3],sl[i]);tr=fn2(ar,br,cr,dr,er,words[zr[i]],hr[3],sr[i])}else{tl=fn5(al,bl,cl,dl,el,words[zl[i]],hl[4],sl[i]);tr=fn1(ar,br,cr,dr,er,words[zr[i]],hr[4],sr[i])}al=el;el=dl;dl=rotl(cl,10);cl=bl;bl=tl;ar=er;er=dr;dr=rotl(cr,10);cr=br;br=tr}var t=this._b+cl+dr|0;this._b=this._c+dl+er|0;this._c=this._d+el+ar|0;this._d=this._e+al+br|0;this._e=this._a+bl+cr|0;this._a=t};RIPEMD160.prototype._digest=function(){this._block[this._blockOffset++]=128;if(this._blockOffset>56){this._block.fill(0,this._blockOffset,64);this._update();this._blockOffset=0}this._block.fill(0,this._blockOffset,56);this._block.writeUInt32LE(this._length[0],56);this._block.writeUInt32LE(this._length[1],60);this._update();var buffer=Buffer.alloc?Buffer.alloc(20):new Buffer(20);buffer.writeInt32LE(this._a,0);buffer.writeInt32LE(this._b,4);buffer.writeInt32LE(this._c,8);buffer.writeInt32LE(this._d,12);buffer.writeInt32LE(this._e,16);return buffer};function rotl(x,n){return x<>>32-n}function fn1(a,b,c,d,e,m,k,s){return rotl(a+(b^c^d)+m+k|0,s)+e|0}function fn2(a,b,c,d,e,m,k,s){return rotl(a+(b&c|~b&d)+m+k|0,s)+e|0}function fn3(a,b,c,d,e,m,k,s){return rotl(a+((b|~c)^d)+m+k|0,s)+e|0}function fn4(a,b,c,d,e,m,k,s){return rotl(a+(b&d|c&~d)+m+k|0,s)+e|0}function fn5(a,b,c,d,e,m,k,s){return rotl(a+(b^(c|~d))+m+k|0,s)+e|0}module.exports=RIPEMD160},{buffer:159,"hash-base":198,inherits:228}],261:[function(require,module,exports){var buffer=require("buffer");var Buffer=buffer.Buffer;function copyProps(src,dst){for(var key in src){dst[key]=src[key]}}if(Buffer.from&&Buffer.alloc&&Buffer.allocUnsafe&&Buffer.allocUnsafeSlow){module.exports=buffer}else{copyProps(buffer,exports);exports.Buffer=SafeBuffer}function SafeBuffer(arg,encodingOrOffset,length){return Buffer(arg,encodingOrOffset,length)}SafeBuffer.prototype=Object.create(Buffer.prototype);copyProps(Buffer,SafeBuffer);SafeBuffer.from=function(arg,encodingOrOffset,length){if(typeof arg==="number"){throw new TypeError("Argument must not be a number")}return Buffer(arg,encodingOrOffset,length)};SafeBuffer.alloc=function(size,fill,encoding){if(typeof size!=="number"){throw new TypeError("Argument must be a number")}var buf=Buffer(size);if(fill!==undefined){if(typeof encoding==="string"){buf.fill(fill,encoding)}else{buf.fill(fill)}}else{buf.fill(0)}return buf};SafeBuffer.allocUnsafe=function(size){if(typeof size!=="number"){throw new TypeError("Argument must be a number")}return Buffer(size)};SafeBuffer.allocUnsafeSlow=function(size){if(typeof size!=="number"){throw new TypeError("Argument must be a number")}return buffer.SlowBuffer(size)}},{buffer:159}],262:[function(require,module,exports){(function(process){(function(){"use strict";var buffer=require("buffer");var Buffer=buffer.Buffer;var safer={};var key;for(key in buffer){if(!buffer.hasOwnProperty(key))continue;if(key==="SlowBuffer"||key==="Buffer")continue;safer[key]=buffer[key]}var Safer=safer.Buffer={};for(key in Buffer){if(!Buffer.hasOwnProperty(key))continue;if(key==="allocUnsafe"||key==="allocUnsafeSlow")continue;Safer[key]=Buffer[key]}safer.Buffer.prototype=Buffer.prototype;if(!Safer.from||Safer.from===Uint8Array.from){Safer.from=function(value,encodingOrOffset,length){if(typeof value==="number"){throw new TypeError('The "value" argument must not be of type number. Received type '+typeof value)}if(value&&typeof value.length==="undefined"){throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof value)}return Buffer(value,encodingOrOffset,length)}}if(!Safer.alloc){Safer.alloc=function(size,fill,encoding){if(typeof size!=="number"){throw new TypeError('The "size" argument must be of type number. Received type '+typeof size)}if(size<0||size>=2*(1<<30)){throw new RangeError('The value "'+size+'" is invalid for option "size"')}var buf=Buffer(size);if(!fill||fill.length===0){buf.fill(0)}else if(typeof encoding==="string"){buf.fill(fill,encoding)}else{buf.fill(fill)}return buf}}if(!safer.kStringMaxLength){try{safer.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch(e){}}if(!safer.constants){safer.constants={MAX_LENGTH:safer.kMaxLength};if(safer.kStringMaxLength){safer.constants.MAX_STRING_LENGTH=safer.kStringMaxLength}}module.exports=safer}).call(this)}).call(this,require("_process"))},{_process:246,buffer:159}],263:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;function Hash(blockSize,finalSize){this._block=Buffer.alloc(blockSize);this._finalSize=finalSize;this._blockSize=blockSize;this._len=0}Hash.prototype.update=function(data,enc){if(typeof data==="string"){enc=enc||"utf8";data=Buffer.from(data,enc)}var block=this._block;var blockSize=this._blockSize;var length=data.length;var accum=this._len;for(var offset=0;offset=this._finalSize){this._update(this._block);this._block.fill(0)}var bits=this._len*8;if(bits<=4294967295){this._block.writeUInt32BE(bits,this._blockSize-4)}else{var lowBits=(bits&4294967295)>>>0;var highBits=(bits-lowBits)/4294967296;this._block.writeUInt32BE(highBits,this._blockSize-8);this._block.writeUInt32BE(lowBits,this._blockSize-4)}this._update(this._block);var hash=this._hash();return enc?hash.toString(enc):hash};Hash.prototype._update=function(){throw new Error("_update must be implemented by subclass")};module.exports=Hash},{"safe-buffer":261}],264:[function(require,module,exports){var exports=module.exports=function SHA(algorithm){algorithm=algorithm.toLowerCase();var Algorithm=exports[algorithm];if(!Algorithm)throw new Error(algorithm+" is not supported (we accept pull requests)");return new Algorithm};exports.sha=require("./sha");exports.sha1=require("./sha1");exports.sha224=require("./sha224");exports.sha256=require("./sha256");exports.sha384=require("./sha384");exports.sha512=require("./sha512")},{"./sha":265,"./sha1":266,"./sha224":267,"./sha256":268,"./sha384":269,"./sha512":270}],265:[function(require,module,exports){var inherits=require("inherits");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var K=[1518500249,1859775393,2400959708|0,3395469782|0];var W=new Array(80);function Sha(){this.init();this._w=W;Hash.call(this,64,56)}inherits(Sha,Hash);Sha.prototype.init=function(){this._a=1732584193;this._b=4023233417;this._c=2562383102;this._d=271733878;this._e=3285377520;return this};function rotl5(num){return num<<5|num>>>27}function rotl30(num){return num<<30|num>>>2}function ft(s,b,c,d){if(s===0)return b&c|~b&d;if(s===2)return b&c|b&d|c&d;return b^c^d}Sha.prototype._update=function(M){var W=this._w;var a=this._a|0;var b=this._b|0;var c=this._c|0;var d=this._d|0;var e=this._e|0;for(var i=0;i<16;++i)W[i]=M.readInt32BE(i*4);for(;i<80;++i)W[i]=W[i-3]^W[i-8]^W[i-14]^W[i-16];for(var j=0;j<80;++j){var s=~~(j/20);var t=rotl5(a)+ft(s,b,c,d)+e+W[j]+K[s]|0;e=d;d=c;c=rotl30(b);b=a;a=t}this._a=a+this._a|0;this._b=b+this._b|0;this._c=c+this._c|0;this._d=d+this._d|0;this._e=e+this._e|0};Sha.prototype._hash=function(){var H=Buffer.allocUnsafe(20);H.writeInt32BE(this._a|0,0);H.writeInt32BE(this._b|0,4);H.writeInt32BE(this._c|0,8);H.writeInt32BE(this._d|0,12);H.writeInt32BE(this._e|0,16);return H};module.exports=Sha},{"./hash":263,inherits:228,"safe-buffer":261}],266:[function(require,module,exports){var inherits=require("inherits");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var K=[1518500249,1859775393,2400959708|0,3395469782|0];var W=new Array(80);function Sha1(){this.init();this._w=W;Hash.call(this,64,56)}inherits(Sha1,Hash);Sha1.prototype.init=function(){this._a=1732584193;this._b=4023233417;this._c=2562383102;this._d=271733878;this._e=3285377520;return this};function rotl1(num){return num<<1|num>>>31}function rotl5(num){return num<<5|num>>>27}function rotl30(num){return num<<30|num>>>2}function ft(s,b,c,d){if(s===0)return b&c|~b&d;if(s===2)return b&c|b&d|c&d;return b^c^d}Sha1.prototype._update=function(M){var W=this._w;var a=this._a|0;var b=this._b|0;var c=this._c|0;var d=this._d|0;var e=this._e|0;for(var i=0;i<16;++i)W[i]=M.readInt32BE(i*4);for(;i<80;++i)W[i]=rotl1(W[i-3]^W[i-8]^W[i-14]^W[i-16]);for(var j=0;j<80;++j){var s=~~(j/20);var t=rotl5(a)+ft(s,b,c,d)+e+W[j]+K[s]|0;e=d;d=c;c=rotl30(b);b=a;a=t}this._a=a+this._a|0;this._b=b+this._b|0;this._c=c+this._c|0;this._d=d+this._d|0;this._e=e+this._e|0};Sha1.prototype._hash=function(){var H=Buffer.allocUnsafe(20);H.writeInt32BE(this._a|0,0);H.writeInt32BE(this._b|0,4);H.writeInt32BE(this._c|0,8);H.writeInt32BE(this._d|0,12);H.writeInt32BE(this._e|0,16);return H};module.exports=Sha1},{"./hash":263,inherits:228,"safe-buffer":261}],267:[function(require,module,exports){var inherits=require("inherits");var Sha256=require("./sha256");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var W=new Array(64);function Sha224(){this.init();this._w=W;Hash.call(this,64,56)}inherits(Sha224,Sha256);Sha224.prototype.init=function(){this._a=3238371032;this._b=914150663;this._c=812702999;this._d=4144912697;this._e=4290775857;this._f=1750603025;this._g=1694076839;this._h=3204075428;return this};Sha224.prototype._hash=function(){var H=Buffer.allocUnsafe(28);H.writeInt32BE(this._a,0);H.writeInt32BE(this._b,4);H.writeInt32BE(this._c,8);H.writeInt32BE(this._d,12);H.writeInt32BE(this._e,16);H.writeInt32BE(this._f,20);H.writeInt32BE(this._g,24);return H};module.exports=Sha224},{"./hash":263,"./sha256":268,inherits:228,"safe-buffer":261}],268:[function(require,module,exports){var inherits=require("inherits");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];var W=new Array(64);function Sha256(){this.init();this._w=W;Hash.call(this,64,56)}inherits(Sha256,Hash);Sha256.prototype.init=function(){this._a=1779033703;this._b=3144134277;this._c=1013904242;this._d=2773480762;this._e=1359893119;this._f=2600822924;this._g=528734635;this._h=1541459225;return this};function ch(x,y,z){return z^x&(y^z)}function maj(x,y,z){return x&y|z&(x|y)}function sigma0(x){return(x>>>2|x<<30)^(x>>>13|x<<19)^(x>>>22|x<<10)}function sigma1(x){return(x>>>6|x<<26)^(x>>>11|x<<21)^(x>>>25|x<<7)}function gamma0(x){return(x>>>7|x<<25)^(x>>>18|x<<14)^x>>>3}function gamma1(x){return(x>>>17|x<<15)^(x>>>19|x<<13)^x>>>10}Sha256.prototype._update=function(M){var W=this._w;var a=this._a|0;var b=this._b|0;var c=this._c|0;var d=this._d|0;var e=this._e|0;var f=this._f|0;var g=this._g|0;var h=this._h|0;for(var i=0;i<16;++i)W[i]=M.readInt32BE(i*4);for(;i<64;++i)W[i]=gamma1(W[i-2])+W[i-7]+gamma0(W[i-15])+W[i-16]|0;for(var j=0;j<64;++j){var T1=h+sigma1(e)+ch(e,f,g)+K[j]+W[j]|0;var T2=sigma0(a)+maj(a,b,c)|0;h=g;g=f;f=e;e=d+T1|0;d=c;c=b;b=a;a=T1+T2|0}this._a=a+this._a|0;this._b=b+this._b|0;this._c=c+this._c|0;this._d=d+this._d|0;this._e=e+this._e|0;this._f=f+this._f|0;this._g=g+this._g|0;this._h=h+this._h|0};Sha256.prototype._hash=function(){var H=Buffer.allocUnsafe(32);H.writeInt32BE(this._a,0);H.writeInt32BE(this._b,4);H.writeInt32BE(this._c,8);H.writeInt32BE(this._d,12);H.writeInt32BE(this._e,16);H.writeInt32BE(this._f,20);H.writeInt32BE(this._g,24);H.writeInt32BE(this._h,28);return H};module.exports=Sha256},{"./hash":263,inherits:228,"safe-buffer":261}],269:[function(require,module,exports){var inherits=require("inherits");var SHA512=require("./sha512");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var W=new Array(160);function Sha384(){this.init();this._w=W;Hash.call(this,128,112)}inherits(Sha384,SHA512);Sha384.prototype.init=function(){this._ah=3418070365;this._bh=1654270250;this._ch=2438529370;this._dh=355462360;this._eh=1731405415;this._fh=2394180231;this._gh=3675008525;this._hh=1203062813;this._al=3238371032;this._bl=914150663;this._cl=812702999;this._dl=4144912697;this._el=4290775857;this._fl=1750603025;this._gl=1694076839;this._hl=3204075428;return this};Sha384.prototype._hash=function(){var H=Buffer.allocUnsafe(48);function writeInt64BE(h,l,offset){H.writeInt32BE(h,offset);H.writeInt32BE(l,offset+4)}writeInt64BE(this._ah,this._al,0);writeInt64BE(this._bh,this._bl,8);writeInt64BE(this._ch,this._cl,16);writeInt64BE(this._dh,this._dl,24);writeInt64BE(this._eh,this._el,32);writeInt64BE(this._fh,this._fl,40);return H};module.exports=Sha384},{"./hash":263,"./sha512":270,inherits:228,"safe-buffer":261}],270:[function(require,module,exports){var inherits=require("inherits");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var K=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];var W=new Array(160);function Sha512(){this.init();this._w=W;Hash.call(this,128,112)}inherits(Sha512,Hash);Sha512.prototype.init=function(){this._ah=1779033703;this._bh=3144134277;this._ch=1013904242;this._dh=2773480762;this._eh=1359893119;this._fh=2600822924;this._gh=528734635;this._hh=1541459225;this._al=4089235720;this._bl=2227873595;this._cl=4271175723;this._dl=1595750129;this._el=2917565137;this._fl=725511199;this._gl=4215389547;this._hl=327033209;return this};function Ch(x,y,z){return z^x&(y^z)}function maj(x,y,z){return x&y|z&(x|y)}function sigma0(x,xl){return(x>>>28|xl<<4)^(xl>>>2|x<<30)^(xl>>>7|x<<25)}function sigma1(x,xl){return(x>>>14|xl<<18)^(x>>>18|xl<<14)^(xl>>>9|x<<23)}function Gamma0(x,xl){return(x>>>1|xl<<31)^(x>>>8|xl<<24)^x>>>7}function Gamma0l(x,xl){return(x>>>1|xl<<31)^(x>>>8|xl<<24)^(x>>>7|xl<<25)}function Gamma1(x,xl){return(x>>>19|xl<<13)^(xl>>>29|x<<3)^x>>>6}function Gamma1l(x,xl){return(x>>>19|xl<<13)^(xl>>>29|x<<3)^(x>>>6|xl<<26)}function getCarry(a,b){return a>>>0>>0?1:0}Sha512.prototype._update=function(M){var W=this._w;var ah=this._ah|0;var bh=this._bh|0;var ch=this._ch|0;var dh=this._dh|0;var eh=this._eh|0;var fh=this._fh|0;var gh=this._gh|0;var hh=this._hh|0;var al=this._al|0;var bl=this._bl|0;var cl=this._cl|0;var dl=this._dl|0;var el=this._el|0;var fl=this._fl|0;var gl=this._gl|0;var hl=this._hl|0;for(var i=0;i<32;i+=2){W[i]=M.readInt32BE(i*4);W[i+1]=M.readInt32BE(i*4+4)}for(;i<160;i+=2){var xh=W[i-15*2];var xl=W[i-15*2+1];var gamma0=Gamma0(xh,xl);var gamma0l=Gamma0l(xl,xh);xh=W[i-2*2];xl=W[i-2*2+1];var gamma1=Gamma1(xh,xl);var gamma1l=Gamma1l(xl,xh);var Wi7h=W[i-7*2];var Wi7l=W[i-7*2+1];var Wi16h=W[i-16*2];var Wi16l=W[i-16*2+1];var Wil=gamma0l+Wi7l|0;var Wih=gamma0+Wi7h+getCarry(Wil,gamma0l)|0;Wil=Wil+gamma1l|0;Wih=Wih+gamma1+getCarry(Wil,gamma1l)|0;Wil=Wil+Wi16l|0;Wih=Wih+Wi16h+getCarry(Wil,Wi16l)|0;W[i]=Wih;W[i+1]=Wil}for(var j=0;j<160;j+=2){Wih=W[j];Wil=W[j+1];var majh=maj(ah,bh,ch);var majl=maj(al,bl,cl);var sigma0h=sigma0(ah,al);var sigma0l=sigma0(al,ah);var sigma1h=sigma1(eh,el);var sigma1l=sigma1(el,eh);var Kih=K[j];var Kil=K[j+1];var chh=Ch(eh,fh,gh);var chl=Ch(el,fl,gl);var t1l=hl+sigma1l|0;var t1h=hh+sigma1h+getCarry(t1l,hl)|0;t1l=t1l+chl|0;t1h=t1h+chh+getCarry(t1l,chl)|0;t1l=t1l+Kil|0;t1h=t1h+Kih+getCarry(t1l,Kil)|0;t1l=t1l+Wil|0;t1h=t1h+Wih+getCarry(t1l,Wil)|0;var t2l=sigma0l+majl|0;var t2h=sigma0h+majh+getCarry(t2l,sigma0l)|0;hh=gh;hl=gl;gh=fh;gl=fl;fh=eh;fl=el;el=dl+t1l|0;eh=dh+t1h+getCarry(el,dl)|0;dh=ch;dl=cl;ch=bh;cl=bl;bh=ah;bl=al;al=t1l+t2l|0;ah=t1h+t2h+getCarry(al,t1l)|0}this._al=this._al+al|0;this._bl=this._bl+bl|0;this._cl=this._cl+cl|0;this._dl=this._dl+dl|0;this._el=this._el+el|0;this._fl=this._fl+fl|0;this._gl=this._gl+gl|0;this._hl=this._hl+hl|0;this._ah=this._ah+ah+getCarry(this._al,al)|0;this._bh=this._bh+bh+getCarry(this._bl,bl)|0;this._ch=this._ch+ch+getCarry(this._cl,cl)|0;this._dh=this._dh+dh+getCarry(this._dl,dl)|0;this._eh=this._eh+eh+getCarry(this._el,el)|0;this._fh=this._fh+fh+getCarry(this._fl,fl)|0;this._gh=this._gh+gh+getCarry(this._gl,gl)|0;this._hh=this._hh+hh+getCarry(this._hl,hl)|0};Sha512.prototype._hash=function(){var H=Buffer.allocUnsafe(64);function writeInt64BE(h,l,offset){H.writeInt32BE(h,offset);H.writeInt32BE(l,offset+4)}writeInt64BE(this._ah,this._al,0);writeInt64BE(this._bh,this._bl,8);writeInt64BE(this._ch,this._cl,16);writeInt64BE(this._dh,this._dl,24);writeInt64BE(this._eh,this._el,32);writeInt64BE(this._fh,this._fl,40);writeInt64BE(this._gh,this._gl,48);writeInt64BE(this._hh,this._hl,56);return H};module.exports=Sha512},{"./hash":263,inherits:228,"safe-buffer":261}],271:[function(require,module,exports){module.exports=Stream;var EE=require("events").EventEmitter;var inherits=require("inherits");inherits(Stream,EE);Stream.Readable=require("readable-stream/lib/_stream_readable.js");Stream.Writable=require("readable-stream/lib/_stream_writable.js");Stream.Duplex=require("readable-stream/lib/_stream_duplex.js");Stream.Transform=require("readable-stream/lib/_stream_transform.js");Stream.PassThrough=require("readable-stream/lib/_stream_passthrough.js");Stream.finished=require("readable-stream/lib/internal/streams/end-of-stream.js");Stream.pipeline=require("readable-stream/lib/internal/streams/pipeline.js");Stream.Stream=Stream;function Stream(){EE.call(this)}Stream.prototype.pipe=function(dest,options){var source=this;function ondata(chunk){if(dest.writable){if(false===dest.write(chunk)&&source.pause){source.pause()}}}source.on("data",ondata);function ondrain(){if(source.readable&&source.resume){source.resume()}}dest.on("drain",ondrain);if(!dest._isStdio&&(!options||options.end!==false)){source.on("end",onend);source.on("close",onclose)}var didOnEnd=false;function onend(){if(didOnEnd)return;didOnEnd=true;dest.end()}function onclose(){if(didOnEnd)return;didOnEnd=true;if(typeof dest.destroy==="function")dest.destroy()}function onerror(er){cleanup();if(EE.listenerCount(this,"error")===0){throw er}}source.on("error",onerror);dest.on("error",onerror);function cleanup(){source.removeListener("data",ondata);dest.removeListener("drain",ondrain);source.removeListener("end",onend);source.removeListener("close",onclose);source.removeListener("error",onerror);dest.removeListener("error",onerror);source.removeListener("end",cleanup);source.removeListener("close",cleanup);dest.removeListener("close",cleanup)}source.on("end",cleanup);source.on("close",cleanup);dest.on("close",cleanup);dest.emit("pipe",source);return dest}},{events:196,inherits:228,"readable-stream/lib/_stream_duplex.js":273,"readable-stream/lib/_stream_passthrough.js":274,"readable-stream/lib/_stream_readable.js":275,"readable-stream/lib/_stream_transform.js":276,"readable-stream/lib/_stream_writable.js":277,"readable-stream/lib/internal/streams/end-of-stream.js":281,"readable-stream/lib/internal/streams/pipeline.js":283}],272:[function(require,module,exports){arguments[4][143][0].apply(exports,arguments)},{dup:143}],273:[function(require,module,exports){arguments[4][144][0].apply(exports,arguments)},{"./_stream_readable":275,"./_stream_writable":277,_process:246,dup:144,inherits:228}],274:[function(require,module,exports){arguments[4][145][0].apply(exports,arguments)},{"./_stream_transform":276,dup:145,inherits:228}],275:[function(require,module,exports){arguments[4][146][0].apply(exports,arguments)},{"../errors":272,"./_stream_duplex":273,"./internal/streams/async_iterator":278,"./internal/streams/buffer_list":279,"./internal/streams/destroy":280,"./internal/streams/from":282,"./internal/streams/state":284,"./internal/streams/stream":285,_process:246,buffer:159,dup:146,events:196,inherits:228,"string_decoder/":286,util:115}],276:[function(require,module,exports){arguments[4][147][0].apply(exports,arguments)},{"../errors":272,"./_stream_duplex":273,dup:147,inherits:228}],277:[function(require,module,exports){arguments[4][148][0].apply(exports,arguments)},{"../errors":272,"./_stream_duplex":273,"./internal/streams/destroy":280,"./internal/streams/state":284,"./internal/streams/stream":285,_process:246,buffer:159,dup:148,inherits:228,"util-deprecate":290}],278:[function(require,module,exports){arguments[4][149][0].apply(exports,arguments)},{"./end-of-stream":281,_process:246,dup:149}],279:[function(require,module,exports){arguments[4][150][0].apply(exports,arguments)},{buffer:159,dup:150,util:115}],280:[function(require,module,exports){arguments[4][151][0].apply(exports,arguments)},{_process:246,dup:151}],281:[function(require,module,exports){arguments[4][152][0].apply(exports,arguments)},{"../../../errors":272,dup:152}],282:[function(require,module,exports){arguments[4][153][0].apply(exports,arguments)},{dup:153}],283:[function(require,module,exports){arguments[4][154][0].apply(exports,arguments)},{"../../../errors":272,"./end-of-stream":281,dup:154}],284:[function(require,module,exports){arguments[4][155][0].apply(exports,arguments)},{"../../../errors":272,dup:155}],285:[function(require,module,exports){arguments[4][156][0].apply(exports,arguments)},{dup:156,events:196}],286:[function(require,module,exports){"use strict";var Buffer=require("safe-buffer").Buffer;var isEncoding=Buffer.isEncoding||function(encoding){encoding=""+encoding;switch(encoding&&encoding.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return true;default:return false}};function _normalizeEncoding(enc){if(!enc)return"utf8";var retried;while(true){switch(enc){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return enc;default:if(retried)return;enc=(""+enc).toLowerCase();retried=true}}}function normalizeEncoding(enc){var nenc=_normalizeEncoding(enc);if(typeof nenc!=="string"&&(Buffer.isEncoding===isEncoding||!isEncoding(enc)))throw new Error("Unknown encoding: "+enc);return nenc||enc}exports.StringDecoder=StringDecoder;function StringDecoder(encoding){this.encoding=normalizeEncoding(encoding);var nb;switch(this.encoding){case"utf16le":this.text=utf16Text;this.end=utf16End;nb=4;break;case"utf8":this.fillLast=utf8FillLast;nb=4;break;case"base64":this.text=base64Text;this.end=base64End;nb=3;break;default:this.write=simpleWrite;this.end=simpleEnd;return}this.lastNeed=0;this.lastTotal=0;this.lastChar=Buffer.allocUnsafe(nb)}StringDecoder.prototype.write=function(buf){if(buf.length===0)return"";var r;var i;if(this.lastNeed){r=this.fillLast(buf);if(r===undefined)return"";i=this.lastNeed;this.lastNeed=0}else{i=0}if(i>5===6)return 2;else if(byte>>4===14)return 3;else if(byte>>3===30)return 4;return byte>>6===2?-1:-2}function utf8CheckIncomplete(self,buf,i){var j=buf.length-1;if(j=0){if(nb>0)self.lastNeed=nb-1;return nb}if(--j=0){if(nb>0)self.lastNeed=nb-2;return nb}if(--j=0){if(nb>0){if(nb===2)nb=0;else self.lastNeed=nb-3}return nb}return 0}function utf8CheckExtraBytes(self,buf,p){if((buf[0]&192)!==128){self.lastNeed=0;return"�"}if(self.lastNeed>1&&buf.length>1){if((buf[1]&192)!==128){self.lastNeed=1;return"�"}if(self.lastNeed>2&&buf.length>2){if((buf[2]&192)!==128){self.lastNeed=2;return"�"}}}}function utf8FillLast(buf){var p=this.lastTotal-this.lastNeed;var r=utf8CheckExtraBytes(this,buf,p);if(r!==undefined)return r;if(this.lastNeed<=buf.length){buf.copy(this.lastChar,p,0,this.lastNeed);return this.lastChar.toString(this.encoding,0,this.lastTotal)}buf.copy(this.lastChar,p,0,buf.length);this.lastNeed-=buf.length}function utf8Text(buf,i){var total=utf8CheckIncomplete(this,buf,i);if(!this.lastNeed)return buf.toString("utf8",i);this.lastTotal=total;var end=buf.length-(total-this.lastNeed);buf.copy(this.lastChar,0,end);return buf.toString("utf8",i,end)}function utf8End(buf){var r=buf&&buf.length?this.write(buf):"";if(this.lastNeed)return r+"�";return r}function utf16Text(buf,i){if((buf.length-i)%2===0){var r=buf.toString("utf16le",i);if(r){var c=r.charCodeAt(r.length-1);if(c>=55296&&c<=56319){this.lastNeed=2;this.lastTotal=4;this.lastChar[0]=buf[buf.length-2];this.lastChar[1]=buf[buf.length-1];return r.slice(0,-1)}}return r}this.lastNeed=1;this.lastTotal=2;this.lastChar[0]=buf[buf.length-1];return buf.toString("utf16le",i,buf.length-1)}function utf16End(buf){var r=buf&&buf.length?this.write(buf):"";if(this.lastNeed){var end=this.lastTotal-this.lastNeed;return r+this.lastChar.toString("utf16le",0,end)}return r}function base64Text(buf,i){var n=(buf.length-i)%3;if(n===0)return buf.toString("base64",i);this.lastNeed=3-n;this.lastTotal=3;if(n===1){this.lastChar[0]=buf[buf.length-1]}else{this.lastChar[0]=buf[buf.length-2];this.lastChar[1]=buf[buf.length-1]}return buf.toString("base64",i,buf.length-n)}function base64End(buf){var r=buf&&buf.length?this.write(buf):"";if(this.lastNeed)return r+this.lastChar.toString("base64",0,3-this.lastNeed);return r}function simpleWrite(buf){return buf.toString(this.encoding)}function simpleEnd(buf){return buf&&buf.length?this.write(buf):""}},{"safe-buffer":261}],287:[function(require,module,exports){(function(setImmediate,clearImmediate){(function(){var nextTick=require("process/browser.js").nextTick;var apply=Function.prototype.apply;var slice=Array.prototype.slice;var immediateIds={};var nextImmediateId=0;exports.setTimeout=function(){return new Timeout(apply.call(setTimeout,window,arguments),clearTimeout)};exports.setInterval=function(){return new Timeout(apply.call(setInterval,window,arguments),clearInterval)};exports.clearTimeout=exports.clearInterval=function(timeout){timeout.close()};function Timeout(id,clearFn){this._id=id;this._clearFn=clearFn}Timeout.prototype.unref=Timeout.prototype.ref=function(){};Timeout.prototype.close=function(){this._clearFn.call(window,this._id)};exports.enroll=function(item,msecs){clearTimeout(item._idleTimeoutId);item._idleTimeout=msecs};exports.unenroll=function(item){clearTimeout(item._idleTimeoutId);item._idleTimeout=-1};exports._unrefActive=exports.active=function(item){clearTimeout(item._idleTimeoutId);var msecs=item._idleTimeout;if(msecs>=0){item._idleTimeoutId=setTimeout(function onTimeout(){if(item._onTimeout)item._onTimeout()},msecs)}};exports.setImmediate=typeof setImmediate==="function"?setImmediate:function(fn){var id=nextImmediateId++;var args=arguments.length<2?false:slice.call(arguments,1);immediateIds[id]=true;nextTick(function onNextTick(){if(immediateIds[id]){if(args){fn.apply(null,args)}else{fn.call(null)}exports.clearImmediate(id)}});return id};exports.clearImmediate=typeof clearImmediate==="function"?clearImmediate:function(id){delete immediateIds[id]}}).call(this)}).call(this,require("timers").setImmediate,require("timers").clearImmediate)},{"process/browser.js":246,timers:287}],288:[function(require,module,exports){"use strict";var punycode=require("punycode");var util=require("./util");exports.parse=urlParse;exports.resolve=urlResolve;exports.resolveObject=urlResolveObject;exports.format=urlFormat;exports.Url=Url;function Url(){this.protocol=null;this.slashes=null;this.auth=null;this.host=null;this.port=null;this.hostname=null;this.hash=null;this.search=null;this.query=null;this.pathname=null;this.path=null;this.href=null}var protocolPattern=/^([a-z0-9.+-]+:)/i,portPattern=/:[0-9]*$/,simplePathPattern=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,delims=["<",">",'"',"`"," ","\r","\n","\t"],unwise=["{","}","|","\\","^","`"].concat(delims),autoEscape=["'"].concat(unwise),nonHostChars=["%","/","?",";","#"].concat(autoEscape),hostEndingChars=["/","?","#"],hostnameMaxLen=255,hostnamePartPattern=/^[+a-z0-9A-Z_-]{0,63}$/,hostnamePartStart=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,unsafeProtocol={javascript:true,"javascript:":true},hostlessProtocol={javascript:true,"javascript:":true},slashedProtocol={http:true,https:true,ftp:true,gopher:true,file:true,"http:":true,"https:":true,"ftp:":true,"gopher:":true,"file:":true},querystring=require("querystring");function urlParse(url,parseQueryString,slashesDenoteHost){if(url&&util.isObject(url)&&url instanceof Url)return url;var u=new Url;u.parse(url,parseQueryString,slashesDenoteHost);return u}Url.prototype.parse=function(url,parseQueryString,slashesDenoteHost){if(!util.isString(url)){throw new TypeError("Parameter 'url' must be a string, not "+typeof url)}var queryIndex=url.indexOf("?"),splitter=queryIndex!==-1&&queryIndex127){newpart+="x"}else{newpart+=part[j]}}if(!newpart.match(hostnamePartPattern)){var validParts=hostparts.slice(0,i);var notHost=hostparts.slice(i+1);var bit=part.match(hostnamePartStart);if(bit){validParts.push(bit[1]);notHost.unshift(bit[2])}if(notHost.length){rest="/"+notHost.join(".")+rest}this.hostname=validParts.join(".");break}}}}if(this.hostname.length>hostnameMaxLen){this.hostname=""}else{this.hostname=this.hostname.toLowerCase()}if(!ipv6Hostname){this.hostname=punycode.toASCII(this.hostname)}var p=this.port?":"+this.port:"";var h=this.hostname||"";this.host=h+p;this.href+=this.host;if(ipv6Hostname){this.hostname=this.hostname.substr(1,this.hostname.length-2);if(rest[0]!=="/"){rest="/"+rest}}}if(!unsafeProtocol[lowerProto]){for(var i=0,l=autoEscape.length;i0?result.host.split("@"):false;if(authInHost){result.auth=authInHost.shift();result.host=result.hostname=authInHost.shift()}}result.search=relative.search;result.query=relative.query;if(!util.isNull(result.pathname)||!util.isNull(result.search)){result.path=(result.pathname?result.pathname:"")+(result.search?result.search:"")}result.href=result.format();return result}if(!srcPath.length){result.pathname=null;if(result.search){result.path="/"+result.search}else{result.path=null}result.href=result.format();return result}var last=srcPath.slice(-1)[0];var hasTrailingSlash=(result.host||relative.host||srcPath.length>1)&&(last==="."||last==="..")||last==="";var up=0;for(var i=srcPath.length;i>=0;i--){last=srcPath[i];if(last==="."){srcPath.splice(i,1)}else if(last===".."){srcPath.splice(i,1);up++}else if(up){srcPath.splice(i,1);up--}}if(!mustEndAbs&&!removeAllDots){for(;up--;up){srcPath.unshift("..")}}if(mustEndAbs&&srcPath[0]!==""&&(!srcPath[0]||srcPath[0].charAt(0)!=="/")){srcPath.unshift("")}if(hasTrailingSlash&&srcPath.join("/").substr(-1)!=="/"){srcPath.push("")}var isAbsolute=srcPath[0]===""||srcPath[0]&&srcPath[0].charAt(0)==="/";if(psychotic){result.hostname=result.host=isAbsolute?"":srcPath.length?srcPath.shift():"";var authInHost=result.host&&result.host.indexOf("@")>0?result.host.split("@"):false;if(authInHost){result.auth=authInHost.shift();result.host=result.hostname=authInHost.shift()}}mustEndAbs=mustEndAbs||result.host&&srcPath.length;if(mustEndAbs&&!isAbsolute){srcPath.unshift("")}if(!srcPath.length){result.pathname=null;result.path=null}else{result.pathname=srcPath.join("/")}if(!util.isNull(result.pathname)||!util.isNull(result.search)){result.path=(result.pathname?result.pathname:"")+(result.search?result.search:"")}result.auth=relative.auth||result.auth;result.slashes=result.slashes||relative.slashes;result.href=result.format();return result};Url.prototype.parseHost=function(){var host=this.host;var port=portPattern.exec(host);if(port){port=port[0];if(port!==":"){this.port=port.substr(1)}host=host.substr(0,host.length-port.length)}if(host)this.hostname=host}},{"./util":289,punycode:254,querystring:257}],289:[function(require,module,exports){"use strict";module.exports={isString:function(arg){return typeof arg==="string"},isObject:function(arg){return typeof arg==="object"&&arg!==null},isNull:function(arg){return arg===null},isNullOrUndefined:function(arg){return arg==null}}},{}],290:[function(require,module,exports){(function(global){(function(){module.exports=deprecate;function deprecate(fn,msg){if(config("noDeprecation")){return fn}var warned=false;function deprecated(){if(!warned){if(config("throwDeprecation")){throw new Error(msg)}else if(config("traceDeprecation")){console.trace(msg)}else{console.warn(msg)}warned=true}return fn.apply(this,arguments)}return deprecated}function config(name){try{if(!global.localStorage)return false}catch(_){return false}var val=global.localStorage[name];if(null==val)return false;return String(val).toLowerCase()==="true"}}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],"bitcore-lib-doge":[function(require,module,exports){(function(global,Buffer){(function(){"use strict";var dogecore=module.exports;dogecore.version="v"+require("./package.json").version;dogecore.versionGuard=function(version){if(version!==undefined){var message="More than one instance of dogecore found. "+"Please make sure to require dogecore and check that submodules do"+" not also include their own dogecore dependency.";console.log(message)}};dogecore.versionGuard(global._dogecore);global._dogecore=dogecore.version;dogecore.crypto={};dogecore.crypto.BN=require("./lib/crypto/bn");dogecore.crypto.ECDSA=require("./lib/crypto/ecdsa");dogecore.crypto.Hash=require("./lib/crypto/hash");dogecore.crypto.Random=require("./lib/crypto/random");dogecore.crypto.Point=require("./lib/crypto/point");dogecore.crypto.Signature=require("./lib/crypto/signature");dogecore.encoding={};dogecore.encoding.Base58=require("./lib/encoding/base58");dogecore.encoding.Base58Check=require("./lib/encoding/base58check");dogecore.encoding.BufferReader=require("./lib/encoding/bufferreader");dogecore.encoding.BufferWriter=require("./lib/encoding/bufferwriter");dogecore.encoding.Varint=require("./lib/encoding/varint");dogecore.util={};dogecore.util.buffer=require("./lib/util/buffer");dogecore.util.js=require("./lib/util/js");dogecore.util.preconditions=require("./lib/util/preconditions");dogecore.errors=require("./lib/errors");dogecore.Address=require("./lib/address");dogecore.Block=require("./lib/block");dogecore.MerkleBlock=require("./lib/block/merkleblock");dogecore.BlockHeader=require("./lib/block/blockheader");dogecore.HDPrivateKey=require("./lib/hdprivatekey.js");dogecore.HDPublicKey=require("./lib/hdpublickey.js");dogecore.Networks=require("./lib/networks");dogecore.Opcode=require("./lib/opcode");dogecore.PrivateKey=require("./lib/privatekey");dogecore.PublicKey=require("./lib/publickey");dogecore.Script=require("./lib/script");dogecore.Transaction=require("./lib/transaction");dogecore.URI=require("./lib/uri");dogecore.Unit=require("./lib/unit");dogecore.deps={};dogecore.deps.bnjs=require("bn.js");dogecore.deps.bs58=require("bs58");dogecore.deps.Buffer=Buffer;dogecore.deps.elliptic=require("elliptic");dogecore.deps.scryptsy=require("scryptsy");dogecore.deps._=require("lodash");dogecore._HDKeyCache=require("./lib/hdkeycache");dogecore.Transaction.sighash=require("./lib/transaction/sighash")}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},require("buffer").Buffer)},{"./lib/address":1,"./lib/block":5,"./lib/block/blockheader":4,"./lib/block/merkleblock":6,"./lib/crypto/bn":7,"./lib/crypto/ecdsa":8,"./lib/crypto/hash":9,"./lib/crypto/point":10,"./lib/crypto/random":11,"./lib/crypto/signature":12,"./lib/encoding/base58":13,"./lib/encoding/base58check":14,"./lib/encoding/bufferreader":15,"./lib/encoding/bufferwriter":16,"./lib/encoding/varint":17,"./lib/errors":18,"./lib/hdkeycache":20,"./lib/hdprivatekey.js":21,"./lib/hdpublickey.js":22,"./lib/networks":23,"./lib/opcode":24,"./lib/privatekey":25,"./lib/publickey":26,"./lib/script":27,"./lib/transaction":30,"./lib/transaction/sighash":38,"./lib/unit":43,"./lib/uri":44,"./lib/util/buffer":45,"./lib/util/js":46,"./lib/util/preconditions":47,"./package.json":92,"bn.js":49,bs58:51,buffer:159,elliptic:53,lodash:84,scryptsy:88}]},{},[]); diff --git a/www/assets/js/bitcore-lib.min.js b/www/assets/js/bitcore-lib.min.js deleted file mode 100644 index 0a2ec01..0000000 --- a/www/assets/js/bitcore-lib.min.js +++ /dev/null @@ -1 +0,0 @@ -require=function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i=21){return Address._transformBuffer(data,network,type)}else if(data instanceof PublicKey){return Address._transformPublicKey(data,network,type)}else if(data instanceof Script){return Address._transformScript(data,network)}else if(typeof data==="string"){return Address._transformString(data,network,type)}else if(_.isObject(data)){return Address._transformObject(data)}else{throw new TypeError("First argument is an unrecognized data format.")}};Address.PayToPublicKeyHash="pubkeyhash";Address.PayToScriptHash="scripthash";Address.PayToWitnessPublicKeyHash="witnesspubkeyhash";Address.PayToWitnessScriptHash="witnessscripthash";Address.PayToTaproot="taproot";Address._transformHash=function(hash,network,type){var info={};if(!(hash instanceof Buffer)&&!(hash instanceof Uint8Array)){throw new TypeError("Address supplied is not a buffer.")}if(hash.length!==20&&hash.length!==32){throw new TypeError("Address hashbuffers must be either 20 or 32 bytes.")}info.hashBuffer=hash;info.network=Networks.get(network)||Networks.defaultNetwork;info.type=type;return info};Address._transformObject=function(data){$.checkArgument(data.hash||data.hashBuffer,"Must provide a `hash` or `hashBuffer` property");$.checkArgument(data.type,"Must provide a `type` property");return{hashBuffer:data.hash?Buffer.from(data.hash,"hex"):data.hashBuffer,network:Networks.get(data.network)||Networks.defaultNetwork,type:data.type}};Address._classifyFromVersion=function(buffer){var version={};if(buffer.length>21){var info=Bech32.decode(buffer.toString("utf8"));if(info.version!==0&&info.version!==1){throw new TypeError("Only witness v0 and v1 addresses are supported.")}if(info.version===0){if(info.data.length===20){version.type=Address.PayToWitnessPublicKeyHash}else if(info.data.length===32){version.type=Address.PayToWitnessScriptHash}else{throw new TypeError("Witness data must be either 20 or 32 bytes.")}}else if(info.version===1){if(info.data.length===32){version.type=Address.PayToTaproot}else{throw new TypeError("Witness data must be 32 bytes for v1")}}else{}version.network=Networks.get(info.prefix,"bech32prefix")}else{var pubkeyhashNetwork=Networks.get(buffer[0],"pubkeyhash");var scripthashNetwork=Networks.get(buffer[0],"scripthash");if(pubkeyhashNetwork){version.network=pubkeyhashNetwork;version.type=Address.PayToPublicKeyHash}else if(scripthashNetwork){version.network=scripthashNetwork;version.type=Address.PayToScriptHash}}return version};Address._transformBuffer=function(buffer,network,type){var info={};if(!(buffer instanceof Buffer)&&!(buffer instanceof Uint8Array)){throw new TypeError("Address supplied is not a buffer.")}if(buffer.length<21){throw new TypeError("Address buffer is incorrect length.")}var networkObj=Networks.get(network);var bufferVersion=Address._classifyFromVersion(buffer);if(network&&!networkObj){throw new TypeError("Unknown network")}if(!bufferVersion.network||networkObj&&networkObj.xpubkey!==bufferVersion.network.xpubkey){throw new TypeError("Address has mismatched network type.")}if(!bufferVersion.type||type&&type!==bufferVersion.type){throw new TypeError("Address has mismatched type.")}if(buffer.length>21){info.hashBuffer=Bech32.decode(buffer.toString("utf8")).data}else{info.hashBuffer=buffer.slice(1)}info.network=bufferVersion.network;info.type=bufferVersion.type;return info};Address._transformPublicKey=function(pubkey,network,type){var info={};if(!(pubkey instanceof PublicKey)){throw new TypeError("Address must be an instance of PublicKey.")}if(type&&type!==Address.PayToScriptHash&&type!==Address.PayToWitnessPublicKeyHash&&type!==Address.PayToPublicKeyHash&&type!==Address.PayToTaproot){throw new TypeError("Type must be either pubkeyhash, witnesspubkeyhash, scripthash, or taproot to transform public key.")}if(!pubkey.compressed&&(type===Address.PayToScriptHash||type===Address.PayToWitnessPublicKeyHash)){throw new TypeError("Witness addresses must use compressed public keys.")}if(type===Address.PayToScriptHash){info.hashBuffer=Hash.sha256ripemd160(Script.buildWitnessV0Out(pubkey).toBuffer())}else if(type===Address.PayToTaproot){info.hashBuffer=Hash.sha256ripemd160(Script.buildWitnessV1Out(pubkey).toBuffer())}else{info.hashBuffer=Hash.sha256ripemd160(pubkey.toBuffer())}info.type=type||Address.PayToPublicKeyHash;return info};Address._transformScript=function(script,network){$.checkArgument(script instanceof Script,"script must be a Script instance");var info=script.getAddressInfo(network);if(!info){throw new errors.Script.CantDeriveAddress(script)}return info};Address.createMultisig=function(publicKeys,threshold,network,nestedWitness,type){network=network||publicKeys[0].network||Networks.defaultNetwork;if(type&&type!==Address.PayToScriptHash&&type!==Address.PayToWitnessScriptHash){throw new TypeError("Type must be either scripthash or witnessscripthash to create multisig.")}if(nestedWitness||type===Address.PayToWitnessScriptHash){publicKeys=_.map(publicKeys,PublicKey);for(var i=0;i100){throw new TypeError("address string is too long")}if(network&&!Networks.get(network)){throw new TypeError("Unknown network")}data=data.trim();try{var info=Address._transformBuffer(Buffer.from(data,"utf8"),network,type);return info}catch(e){if(type===Address.PayToWitnessPublicKeyHash||type===Address.PayToWitnessScriptHash||type===Address.PayToTaproot){throw e}}var addressBuffer=Base58Check.decode(data);var info=Address._transformBuffer(addressBuffer,network,type);return info};Address.fromPublicKey=function(data,network,type){var info=Address._transformPublicKey(data,network,type);network=network||Networks.defaultNetwork;return new Address(info.hashBuffer,network,info.type)};Address.fromPublicKeyHash=function(hash,network){var info=Address._transformHash(hash);return new Address(info.hashBuffer,network,Address.PayToPublicKeyHash)};Address.fromScriptHash=function(hash,network,type){$.checkArgument(hash,"hash parameter is required");var info=Address._transformHash(hash);if(type===Address.PayToWitnessScriptHash&&hash.length!==32){throw new TypeError("Address hashbuffer must be exactly 32 bytes for v0 witness script hash.")}var type=type||Address.PayToScriptHash;return new Address(info.hashBuffer,network,type)};Address.payingTo=function(script,network,type){$.checkArgument(script,"script is required");$.checkArgument(script instanceof Script,"script must be instance of Script");var hash;if(type===Address.PayToWitnessScriptHash){hash=Hash.sha256(script.toBuffer())}else{hash=Hash.sha256ripemd160(script.toBuffer())}var type=type||Address.PayToScriptHash;return Address.fromScriptHash(hash,network,type)};Address.fromScript=function(script,network){$.checkArgument(script instanceof Script,"script must be a Script instance");var info=Address._transformScript(script,network);return new Address(info.hashBuffer,network,info.type)};Address.fromBuffer=function(buffer,network,type){var info=Address._transformBuffer(buffer,network,type);return new Address(info.hashBuffer,info.network,info.type)};Address.fromString=function(str,network,type){var info=Address._transformString(str,network,type);return new Address(info.hashBuffer,info.network,info.type)};Address.fromObject=function fromObject(obj){$.checkState(JSUtil.isHexa(obj.hash),'Unexpected hash property, "'+obj.hash+'", expected to be hex.');var hashBuffer=Buffer.from(obj.hash,"hex");return new Address(hashBuffer,obj.network,obj.type)};Address.getValidationError=function(data,network,type){var error;try{new Address(data,network,type)}catch(e){error=e}return error};Address.isValid=function(data,network,type){return!Address.getValidationError(data,network,type)};Address.prototype.isPayToPublicKeyHash=function(){return this.type===Address.PayToPublicKeyHash};Address.prototype.isPayToScriptHash=function(){return this.type===Address.PayToScriptHash};Address.prototype.isPayToWitnessPublicKeyHash=function(){return this.type===Address.PayToWitnessPublicKeyHash};Address.prototype.isPayToWitnessScriptHash=function(){return this.type===Address.PayToWitnessScriptHash};Address.prototype.isPayToTaproot=function(){return this.type===Address.PayToTaproot};Address.prototype.toBuffer=function(){if(this.isPayToWitnessPublicKeyHash()||this.isPayToWitnessScriptHash()){return Buffer.from(this.toString(),"utf8")}var version=Buffer.from([this.network[this.type]]);return Buffer.concat([version,this.hashBuffer])};Address.prototype.toObject=Address.prototype.toJSON=function toObject(){return{hash:this.hashBuffer.toString("hex"),type:this.type,network:this.network.toString()}};Address.prototype.toString=function(){if(this.isPayToWitnessPublicKeyHash()||this.isPayToWitnessScriptHash()||this.isPayToTaproot()){let prefix=this.network.bech32prefix;let version=0;let encoding=Bech32.encodings.BECH32;if(this.isPayToTaproot()){version=1;encoding=Bech32.encodings.BECH32M}return Bech32.encode(prefix,version,this.hashBuffer,encoding)}return Base58Check.encode(this.toBuffer())};Address.prototype.inspect=function(){return""};module.exports=Address;var Script=require("./script")}).call(this)}).call(this,require("buffer").Buffer)},{"./crypto/hash":8,"./encoding/base58check":13,"./encoding/bech32":14,"./errors":18,"./networks":23,"./publickey":26,"./script":27,"./util/js":46,"./util/preconditions":47,buffer:175,lodash:103}],2:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var BlockHeader=require("./blockheader");var BN=require("../crypto/bn");var BufferUtil=require("../util/buffer");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var Transaction=require("../transaction");var $=require("../util/preconditions");function Block(arg){if(!(this instanceof Block)){return new Block(arg)}_.extend(this,Block._from(arg));return this}Block.MAX_BLOCK_SIZE=1e6;Block._from=function _from(arg){var info={};if(BufferUtil.isBuffer(arg)){info=Block._fromBufferReader(BufferReader(arg))}else if(_.isObject(arg)){info=Block._fromObject(arg)}else{throw new TypeError("Unrecognized argument for Block")}return info};Block._fromObject=function _fromObject(data){var transactions=[];data.transactions.forEach(function(tx){if(tx instanceof Transaction){transactions.push(tx)}else{transactions.push(Transaction().fromObject(tx))}});var info={header:BlockHeader.fromObject(data.header),transactions:transactions};return info};Block.fromObject=function fromObject(obj){var info=Block._fromObject(obj);return new Block(info)};Block._fromBufferReader=function _fromBufferReader(br){var info={};$.checkState(!br.finished(),"No block data received");info.header=BlockHeader.fromBufferReader(br);var transactions=br.readVarintNum();info.transactions=[];for(var i=0;i1;size=Math.floor((size+1)/2)){for(var i=0;i"};Block.Values={START_OF_BLOCK:8,NULL_HASH:Buffer.from("0000000000000000000000000000000000000000000000000000000000000000","hex")};module.exports=Block}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../encoding/bufferreader":15,"../encoding/bufferwriter":16,"../transaction":30,"../util/buffer":45,"../util/preconditions":47,"./blockheader":3,buffer:175,lodash:103}],3:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var BN=require("../crypto/bn");var BufferUtil=require("../util/buffer");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var JSUtil=require("../util/js");var $=require("../util/preconditions");var GENESIS_BITS=486604799;var BlockHeader=function BlockHeader(arg){if(!(this instanceof BlockHeader)){return new BlockHeader(arg)}var info=BlockHeader._from(arg);this.version=info.version;this.prevHash=info.prevHash;this.merkleRoot=info.merkleRoot;this.time=info.time;this.timestamp=info.time;this.bits=info.bits;this.nonce=info.nonce;if(info.hash){$.checkState(this.hash===info.hash,"Argument object hash property does not match block hash.")}return this};BlockHeader._from=function _from(arg){var info={};if(BufferUtil.isBuffer(arg)){info=BlockHeader._fromBufferReader(BufferReader(arg))}else if(_.isObject(arg)){info=BlockHeader._fromObject(arg)}else{throw new TypeError("Unrecognized argument for BlockHeader")}return info};BlockHeader._fromObject=function _fromObject(data){$.checkArgument(data,"data is required");var prevHash=data.prevHash;var merkleRoot=data.merkleRoot;if(_.isString(data.prevHash)){prevHash=BufferUtil.reverse(Buffer.from(data.prevHash,"hex"))}if(_.isString(data.merkleRoot)){merkleRoot=BufferUtil.reverse(Buffer.from(data.merkleRoot,"hex"))}var info={hash:data.hash,version:data.version,prevHash:prevHash,merkleRoot:merkleRoot,time:data.time,timestamp:data.time,bits:data.bits,nonce:data.nonce};return info};BlockHeader.fromObject=function fromObject(obj){var info=BlockHeader._fromObject(obj);return new BlockHeader(info)};BlockHeader.fromRawBlock=function fromRawBlock(data){if(!BufferUtil.isBuffer(data)){data=Buffer.from(data,"binary")}var br=BufferReader(data);br.pos=BlockHeader.Constants.START_OF_HEADER;var info=BlockHeader._fromBufferReader(br);return new BlockHeader(info)};BlockHeader.fromBuffer=function fromBuffer(buf){var info=BlockHeader._fromBufferReader(BufferReader(buf));return new BlockHeader(info)};BlockHeader.fromString=function fromString(str){var buf=Buffer.from(str,"hex");return BlockHeader.fromBuffer(buf)};BlockHeader._fromBufferReader=function _fromBufferReader(br){var info={};info.version=br.readInt32LE();info.prevHash=br.read(32);info.merkleRoot=br.read(32);info.time=br.readUInt32LE();info.bits=br.readUInt32LE();info.nonce=br.readUInt32LE();return info};BlockHeader.fromBufferReader=function fromBufferReader(br){var info=BlockHeader._fromBufferReader(br);return new BlockHeader(info)};BlockHeader.prototype.toObject=BlockHeader.prototype.toJSON=function toObject(){return{hash:this.hash,version:this.version,prevHash:BufferUtil.reverse(this.prevHash).toString("hex"),merkleRoot:BufferUtil.reverse(this.merkleRoot).toString("hex"),time:this.time,bits:this.bits,nonce:this.nonce}};BlockHeader.prototype.toBuffer=function toBuffer(){return this.toBufferWriter().concat()};BlockHeader.prototype.toString=function toString(){return this.toBuffer().toString("hex")};BlockHeader.prototype.toBufferWriter=function toBufferWriter(bw){if(!bw){bw=new BufferWriter}bw.writeInt32LE(this.version);bw.write(this.prevHash);bw.write(this.merkleRoot);bw.writeUInt32LE(this.time);bw.writeUInt32LE(this.bits);bw.writeUInt32LE(this.nonce);return bw};BlockHeader.prototype.getTargetDifficulty=function getTargetDifficulty(bits){bits=bits||this.bits;var target=new BN(bits&16777215);var mov=8*((bits>>>24)-3);while(mov-- >0){target=target.mul(new BN(2))}return target};BlockHeader.prototype.getDifficulty=function getDifficulty(){var difficulty1TargetBN=this.getTargetDifficulty(GENESIS_BITS).mul(new BN(Math.pow(10,8)));var currentTargetBN=this.getTargetDifficulty();var difficultyString=difficulty1TargetBN.div(currentTargetBN).toString(10);var decimalPos=difficultyString.length-8;difficultyString=difficultyString.slice(0,decimalPos)+"."+difficultyString.slice(decimalPos);return parseFloat(difficultyString)};BlockHeader.prototype._getHash=function hash(){var buf=this.toBuffer();return Hash.sha256sha256(buf)};var idProperty={configurable:false,enumerable:true,get:function(){if(!this._id){this._id=BufferReader(this._getHash()).readReverse().toString("hex")}return this._id},set:_.noop};Object.defineProperty(BlockHeader.prototype,"id",idProperty);Object.defineProperty(BlockHeader.prototype,"hash",idProperty);BlockHeader.prototype.validTimestamp=function validTimestamp(){var currentTime=Math.round((new Date).getTime()/1e3);if(this.time>currentTime+BlockHeader.Constants.MAX_TIME_OFFSET){return false}return true};BlockHeader.prototype.validProofOfWork=function validProofOfWork(){var pow=new BN(this.id,"hex");var target=this.getTargetDifficulty();if(pow.cmp(target)>0){return false}return true};BlockHeader.prototype.inspect=function inspect(){return""};BlockHeader.Constants={START_OF_HEADER:8,MAX_TIME_OFFSET:2*60*60,LARGEST_HASH:new BN("10000000000000000000000000000000000000000000000000000000000000000","hex")};module.exports=BlockHeader}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../encoding/bufferreader":15,"../encoding/bufferwriter":16,"../util/buffer":45,"../util/js":46,"../util/preconditions":47,buffer:175,lodash:103}],4:[function(require,module,exports){module.exports=require("./block");module.exports.BlockHeader=require("./blockheader");module.exports.MerkleBlock=require("./merkleblock")},{"./block":2,"./blockheader":3,"./merkleblock":5}],5:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var BlockHeader=require("./blockheader");var BufferUtil=require("../util/buffer");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var JSUtil=require("../util/js");var Transaction=require("../transaction");var errors=require("../errors");var $=require("../util/preconditions");function MerkleBlock(arg){if(!(this instanceof MerkleBlock)){return new MerkleBlock(arg)}var info={};if(BufferUtil.isBuffer(arg)){info=MerkleBlock._fromBufferReader(BufferReader(arg))}else if(_.isObject(arg)){var header;if(arg.header instanceof BlockHeader){header=arg.header}else{header=BlockHeader.fromObject(arg.header)}info={header:header,numTransactions:arg.numTransactions,hashes:arg.hashes,flags:arg.flags}}else{throw new TypeError("Unrecognized argument for MerkleBlock")}_.extend(this,info);this._flagBitsUsed=0;this._hashesUsed=0;return this}MerkleBlock.fromBuffer=function fromBuffer(buf){return MerkleBlock.fromBufferReader(BufferReader(buf))};MerkleBlock.fromBufferReader=function fromBufferReader(br){return new MerkleBlock(MerkleBlock._fromBufferReader(br))};MerkleBlock.prototype.toBuffer=function toBuffer(){return this.toBufferWriter().concat()};MerkleBlock.prototype.toBufferWriter=function toBufferWriter(bw){if(!bw){bw=new BufferWriter}bw.write(this.header.toBuffer());bw.writeUInt32LE(this.numTransactions);bw.writeVarintNum(this.hashes.length);for(var i=0;ithis.numTransactions){return false}if(this.flags.length*8this.numTransactions){throw new errors.MerkleBlock.InvalidMerkleTree}if(this.flags.length*8this.flags.length*8){return null}var isParentOfMatch=this.flags[opts.flagBitsUsed>>3]>>>(opts.flagBitsUsed++&7)&1;if(depth===0||!isParentOfMatch){if(opts.hashesUsed>=this.hashes.length){return null}var hash=this.hashes[opts.hashesUsed++];if(depth===0&&isParentOfMatch){opts.txs.push(hash)}return Buffer.from(hash,"hex")}else{var left=this._traverseMerkleTree(depth-1,pos*2,opts);var right=left;if(pos*2+1>height};MerkleBlock.prototype._calcTreeHeight=function calcTreeHeight(){var height=0;while(this._calcTreeWidth(height)>1){height++}return height};MerkleBlock.prototype.hasTransaction=function hasTransaction(tx){$.checkArgument(!_.isUndefined(tx),"tx cannot be undefined");$.checkArgument(tx instanceof Transaction||typeof tx==="string",'Invalid tx given, tx must be a "string" or "Transaction"');var hash=tx;if(tx instanceof Transaction){hash=BufferUtil.reverse(Buffer.from(tx.id,"hex")).toString("hex")}var txs=[];var height=this._calcTreeHeight();this._traverseMerkleTree(height,0,{txs:txs});return txs.indexOf(hash)!==-1};MerkleBlock._fromBufferReader=function _fromBufferReader(br){$.checkState(!br.finished(),"No merkleblock data received");var info={};info.header=BlockHeader.fromBufferReader(br);info.numTransactions=br.readUInt32LE();var numHashes=br.readVarintNum();info.hashes=[];for(var i=0;iopts.size){buf=BN.trim(buf,natlen)}else if(natlen0){if((buf[buf.length-1]&127)===0){if(buf.length<=1||(buf[buf.length-2]&128)===0){throw new Error("non-minimally encoded script number")}}}return BN.fromSM(buf,{endian:"little"})};BN.prototype.toScriptNumBuffer=function(){return this.toSM({endian:"little"})};BN.trim=function(buf,natlen){return buf.slice(natlen-buf.length,buf.length)};BN.pad=function(buf,natlen,size){var rbuf=Buffer.alloc(size);for(var i=0;i>1;var n=Point.getN();var G=Point.getG();var x=isSecondKey?r.add(n):r;var R=Point.fromX(isYOdd,x);var nR=R.mul(n);if(!nR.isInfinity()){throw new Error("nR is not a valid curve point")}var eNeg=e.neg().umod(n);var rInv=r.invm(n);var Q=R.mul(s).add(G.mul(eNeg)).mul(rInv);var pubkey=PublicKey.fromPoint(Q,this.sig.compressed);return pubkey};ECDSA.prototype.sigError=function(){if(!BufferUtil.isBuffer(this.hashbuf)||this.hashbuf.length!==32){return"hashbuf must be a 32 byte buffer"}var r=this.sig.r;var s=this.sig.s;if(!(r.gt(BN.Zero)&&r.lt(Point.getN()))||!(s.gt(BN.Zero)&&s.lt(Point.getN()))){return"r and s not in range"}var e=BN.fromBuffer(this.hashbuf,this.endian?{endian:this.endian}:undefined);var n=Point.getN();var sinv=s.invm(n);var u1=sinv.mul(e).umod(n);var u2=sinv.mul(r).umod(n);var p=Point.getG().mulAdd(u1,this.pubkey.point,u2);if(p.isInfinity()){return"p is infinity"}if(p.getX().umod(n).cmp(r)!==0){return"Invalid signature"}else{return false}};ECDSA.toLowS=function(s){if(s.gt(BN.fromBuffer(Buffer.from("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex")))){s=Point.getN().sub(s)}return s};ECDSA.prototype._findSignature=function(d,e){var N=Point.getN();var G=Point.getG();var badrs=0;var k,Q,r,s;do{if(!this.k||badrs>0){this.deterministicK(badrs)}badrs++;k=this.k;Q=G.mul(k);r=Q.x.umod(N);s=k.invm(N).mul(e.add(d.mul(r))).umod(N)}while(r.cmp(BN.Zero)<=0||s.cmp(BN.Zero)<=0);s=ECDSA.toLowS(s);return{s:s,r:r}};ECDSA.prototype.sign=function(){var hashbuf=this.hashbuf;var privkey=this.privkey;var d=privkey.bn;$.checkState(hashbuf&&privkey&&d,new Error("invalid parameters"));$.checkState(BufferUtil.isBuffer(hashbuf)&&hashbuf.length===32,new Error("hashbuf must be a 32 byte buffer"));var e=BN.fromBuffer(hashbuf,this.endian?{endian:this.endian}:undefined);var obj=this._findSignature(d,e);obj.compressed=this.pubkey.compressed;this.sig=new Signature(obj);return this};ECDSA.prototype.signRandomK=function(){this.randomK();return this.sign()};ECDSA.prototype.toString=function(){var obj={};if(this.hashbuf){obj.hashbuf=this.hashbuf.toString("hex")}if(this.privkey){obj.privkey=this.privkey.toString()}if(this.pubkey){obj.pubkey=this.pubkey.toString()}if(this.sig){obj.sig=this.sig.toString()}if(this.k){obj.k=this.k.toString()}return JSON.stringify(obj)};ECDSA.prototype.verify=function(){if(!this.sigError()){this.verified=true}else{this.verified=false}return this};ECDSA.sign=function(hashbuf,privkey,endian){return ECDSA().set({hashbuf:hashbuf,endian:endian,privkey:privkey}).sign().sig};ECDSA.verify=function(hashbuf,sig,pubkey,endian){return ECDSA().set({hashbuf:hashbuf,endian:endian,sig:sig,pubkey:pubkey}).verify().verified};module.exports=ECDSA}).call(this)}).call(this,require("buffer").Buffer)},{"../publickey":26,"../util/buffer":45,"../util/preconditions":47,"./bn":6,"./hash":8,"./point":9,"./random":10,"./signature":11,buffer:175,lodash:103}],8:[function(require,module,exports){(function(Buffer){(function(){"use strict";var crypto=require("crypto");var BufferUtil=require("../util/buffer");var $=require("../util/preconditions");var Hash=module.exports;Hash.sha1=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha1").update(buf).digest()};Hash.sha1.blocksize=512;Hash.sha256=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha256").update(buf).digest()};Hash.sha256.blocksize=512;Hash.sha256sha256=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return Hash.sha256(Hash.sha256(buf))};Hash.ripemd160=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("ripemd160").update(buf).digest()};Hash.sha256ripemd160=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return Hash.ripemd160(Hash.sha256(buf))};Hash.sha512=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return crypto.createHash("sha512").update(buf).digest()};Hash.sha512.blocksize=1024;Hash.hmac=function(hashf,data,key){$.checkArgument(BufferUtil.isBuffer(data));$.checkArgument(BufferUtil.isBuffer(key));$.checkArgument(hashf.blocksize);var blocksize=hashf.blocksize/8;if(key.length>blocksize){key=hashf(key)}else if(key>>8)&255}}return b};module.exports=Random}).call(this)}).call(this,require("_process"),require("buffer").Buffer)},{_process:262,buffer:175,crypto:183}],11:[function(require,module,exports){(function(Buffer){(function(){"use strict";var BN=require("./bn");var _=require("lodash");var $=require("../util/preconditions");var BufferUtil=require("../util/buffer");var JSUtil=require("../util/js");var Signature=function Signature(r,s){if(!(this instanceof Signature)){return new Signature(r,s)}if(r instanceof BN){this.set({r:r,s:s})}else if(r){var obj=r;this.set(obj)}};Signature.prototype.set=function(obj){this.r=obj.r||this.r||undefined;this.s=obj.s||this.s||undefined;this.i=typeof obj.i!=="undefined"?obj.i:this.i;this.compressed=typeof obj.compressed!=="undefined"?obj.compressed:this.compressed;this.nhashtype=obj.nhashtype||this.nhashtype||undefined;return this};Signature.fromCompact=function(buf){$.checkArgument(BufferUtil.isBuffer(buf),"Argument is expected to be a Buffer");var sig=new Signature;var compressed=true;var i=buf.slice(0,1)[0]-27-4;if(i<0){compressed=false;i=i+4}var b2=buf.slice(1,33);var b3=buf.slice(33,65);$.checkArgument(i===0||i===1||i===2||i===3,new Error("i must be 0, 1, 2, or 3"));$.checkArgument(b2.length===32,new Error("r must be 32 bytes"));$.checkArgument(b3.length===32,new Error("s must be 32 bytes"));sig.compressed=compressed;sig.i=i;sig.r=BN.fromBuffer(b2);sig.s=BN.fromBuffer(b3);return sig};Signature.fromDER=Signature.fromBuffer=function(buf,strict){var obj=Signature.parseDER(buf,strict);var sig=new Signature;sig.r=obj.r;sig.s=obj.s;return sig};Signature.fromTxFormat=function(buf){var nhashtype=buf.readUInt8(buf.length-1);var derbuf=buf.slice(0,buf.length-1);var sig=new Signature.fromDER(derbuf,false);sig.nhashtype=nhashtype;return sig};Signature.fromString=function(str){var buf=Buffer.from(str,"hex");return Signature.fromDER(buf)};Signature.parseDER=function(buf,strict){$.checkArgument(BufferUtil.isBuffer(buf),new Error("DER formatted signature should be a buffer"));if(_.isUndefined(strict)){strict=true}var header=buf[0];$.checkArgument(header===48,new Error("Header byte should be 0x30"));var length=buf[1];var buflength=buf.slice(2).length;$.checkArgument(!strict||length===buflength,new Error("Length byte should length of what follows"));length=length73){return false}if(buf[0]!==48){return false}if(buf[1]!==buf.length-3){return false}var nLenR=buf[3];if(5+nLenR>=buf.length){return false}var nLenS=buf[5+nLenR];if(nLenR+nLenS+7!==buf.length){return false}var R=buf.slice(4);if(buf[4-2]!==2){return false}if(nLenR===0){return false}if(R[0]&128){return false}if(nLenR>1&&R[0]===0&&!(R[1]&128)){return false}var S=buf.slice(6+nLenR);if(buf[6+nLenR-2]!==2){return false}if(nLenS===0){return false}if(S[0]&128){return false}if(nLenS>1&&S[0]===0&&!(S[1]&128)){return false}return true};Signature.prototype.hasLowS=function(){if(this.s.lt(new BN(1))||this.s.gt(new BN("7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0","hex"))){return false}return true};Signature.prototype.hasDefinedHashtype=function(){if(!JSUtil.isNaturalNumber(this.nhashtype)){return false}var temp=this.nhashtype&~Signature.SIGHASH_ANYONECANPAY;if(tempSignature.SIGHASH_SINGLE){return false}return true};Signature.prototype.toTxFormat=function(){var derbuf=this.toDER();var buf=Buffer.alloc(1);buf.writeUInt8(this.nhashtype,0);return Buffer.concat([derbuf,buf])};Signature.SIGHASH_ALL=1;Signature.SIGHASH_NONE=2;Signature.SIGHASH_SINGLE=3;Signature.SIGHASH_ANYONECANPAY=128;module.exports=Signature}).call(this)}).call(this,require("buffer").Buffer)},{"../util/buffer":45,"../util/js":46,"../util/preconditions":47,"./bn":6,buffer:175,lodash:103}],12:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var bs58=require("bs58");var buffer=require("buffer");var ALPHABET="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".split("");var Base58=function Base58(obj){if(!(this instanceof Base58)){return new Base58(obj)}if(Buffer.isBuffer(obj)){var buf=obj;this.fromBuffer(buf)}else if(typeof obj==="string"){var str=obj;this.fromString(str)}else if(obj){this.set(obj)}};Base58.validCharacters=function validCharacters(chars){if(buffer.Buffer.isBuffer(chars)){chars=chars.toString()}return _.every(_.map(chars,function(char){return _.includes(ALPHABET,char)}))};Base58.prototype.set=function(obj){this.buf=obj.buf||this.buf||undefined;return this};Base58.encode=function(buf){if(!buffer.Buffer.isBuffer(buf)){throw new Error("Input should be a buffer")}return bs58.encode(buf)};Base58.decode=function(str){if(typeof str!=="string"){throw new Error("Input should be a string")}return Buffer.from(bs58.decode(str))};Base58.prototype.fromBuffer=function(buf){this.buf=buf;return this};Base58.prototype.fromString=function(str){var buf=Base58.decode(str);this.buf=buf;return this};Base58.prototype.toBuffer=function(){return this.buf};Base58.prototype.toString=function(){return Base58.encode(this.buf)};module.exports=Base58}).call(this)}).call(this,require("buffer").Buffer)},{bs58:64,buffer:175,lodash:103}],13:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var Base58=require("./base58");var buffer=require("buffer");var sha256sha256=require("../crypto/hash").sha256sha256;var Base58Check=function Base58Check(obj){if(!(this instanceof Base58Check))return new Base58Check(obj);if(Buffer.isBuffer(obj)){var buf=obj;this.fromBuffer(buf)}else if(typeof obj==="string"){var str=obj;this.fromString(str)}else if(obj){this.set(obj)}};Base58Check.prototype.set=function(obj){this.buf=obj.buf||this.buf||undefined;return this};Base58Check.validChecksum=function validChecksum(data,checksum){if(_.isString(data)){data=Buffer.from(Base58.decode(data))}if(_.isString(checksum)){checksum=Buffer.from(Base58.decode(checksum))}if(!checksum){checksum=data.slice(-4);data=data.slice(0,-4)}return Base58Check.checksum(data).toString("hex")===checksum.toString("hex")};Base58Check.decode=function(s){if(typeof s!=="string")throw new Error("Input must be a string");var buf=Buffer.from(Base58.decode(s));if(buf.length<4)throw new Error("Input string too short");var data=buf.slice(0,-4);var csum=buf.slice(-4);var hash=sha256sha256(data);var hash4=hash.slice(0,4);if(csum.toString("hex")!==hash4.toString("hex"))throw new Error("Checksum mismatch");return data};Base58Check.checksum=function(buffer){return sha256sha256(buffer).slice(0,4)};Base58Check.encode=function(buf){if(!Buffer.isBuffer(buf))throw new Error("Input must be a buffer");var checkedBuf=Buffer.alloc(buf.length+4);var hash=Base58Check.checksum(buf);buf.copy(checkedBuf);hash.copy(checkedBuf,buf.length);return Base58.encode(checkedBuf)};Base58Check.prototype.fromBuffer=function(buf){this.buf=buf;return this};Base58Check.prototype.fromString=function(str){var buf=Base58Check.decode(str);this.buf=buf;return this};Base58Check.prototype.toBuffer=function(){return this.buf};Base58Check.prototype.toString=function(){return Base58Check.encode(this.buf)};module.exports=Base58Check}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/hash":8,"./base58":12,buffer:175,lodash:103}],14:[function(require,module,exports){(function(Buffer){(function(){"use strict";var bech32=require("bech32");var decode=function(str){if(typeof str!=="string"){throw new Error("Input should be a string")}var decoded;let fromWords=bech32.bech32.fromWords;let encoding=encodings.BECH32;try{decoded=bech32.bech32.decode(str)}catch(e){if(e.message.indexOf("Invalid checksum")>-1){decoded=bech32.bech32m.decode(str);encoding=encodings.BECH32M;fromWords=bech32.bech32m.fromWords}else{throw e}}const version=decoded.words[0];if(version>=1&&encoding!==encodings.BECH32M){throw new Error("Version 1+ witness address must use Bech32m checksum")}return{prefix:decoded.prefix,data:Buffer.from(fromWords(decoded.words.slice(1))),version:version}};var encode=function(prefix,version,data,encoding){if(typeof prefix!=="string"){throw new Error("Prefix should be a string")}if(typeof version!=="number"){throw new Error("version should be a number")}if(encoding&&typeof encoding=="string"){encoding=encodings[encoding.toUpperCase()]||-1}if(encoding&&!(encoding==encodings.BECH32||encoding==encodings.BECH32M)){throw new Error("Invalid encoding specified")}let b32Variety=encoding==encodings.BECH32M?bech32.bech32m:bech32.bech32;let words=b32Variety.toWords(data);words.unshift(version);return b32Variety.encode(prefix,words)};const encodings={BECH32:1,BECH32M:2};module.exports={decode:decode,encode:encode,encodings:encodings}}).call(this)}).call(this,require("buffer").Buffer)},{bech32:49,buffer:175}],15:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var $=require("../util/preconditions");var BufferUtil=require("../util/buffer");var BN=require("../crypto/bn");var BufferReader=function BufferReader(buf){if(!(this instanceof BufferReader)){return new BufferReader(buf)}if(_.isUndefined(buf)){return}if(Buffer.isBuffer(buf)){this.set({buf:buf})}else if(_.isString(buf)){this.set({buf:Buffer.from(buf,"hex")})}else if(_.isObject(buf)){var obj=buf;this.set(obj)}else{throw new TypeError("Unrecognized argument for BufferReader")}};BufferReader.prototype.set=function(obj){this.buf=obj.buf||this.buf||undefined;this.pos=obj.pos||this.pos||0;return this};BufferReader.prototype.eof=function(){if(this.buf){return this.pos>=this.buf.length}else{return true}};BufferReader.prototype.finished=BufferReader.prototype.eof;BufferReader.prototype.read=function(len){$.checkArgument(!_.isUndefined(len),"Must specify a length");var buf=this.buf.slice(this.pos,this.pos+len);this.pos=this.pos+len;return buf};BufferReader.prototype.readAll=function(){var buf=this.buf.slice(this.pos,this.buf.length);this.pos=this.buf.length;return buf};BufferReader.prototype.readUInt8=function(){var val=this.buf.readUInt8(this.pos);this.pos=this.pos+1;return val};BufferReader.prototype.readUInt16BE=function(){var val=this.buf.readUInt16BE(this.pos);this.pos=this.pos+2;return val};BufferReader.prototype.readUInt16LE=function(){var val=this.buf.readUInt16LE(this.pos);this.pos=this.pos+2;return val};BufferReader.prototype.readUInt32BE=function(){var val=this.buf.readUInt32BE(this.pos);this.pos=this.pos+4;return val};BufferReader.prototype.readUInt32LE=function(){var val=this.buf.readUInt32LE(this.pos);this.pos=this.pos+4;return val};BufferReader.prototype.readInt32LE=function(){var val=this.buf.readInt32LE(this.pos);this.pos=this.pos+4;return val};BufferReader.prototype.readUInt64BEBN=function(){var buf=this.buf.slice(this.pos,this.pos+8);var bn=BN.fromBuffer(buf);this.pos=this.pos+8;return bn};BufferReader.prototype.readUInt64LEBN=function(){var second=this.buf.readUInt32LE(this.pos);var first=this.buf.readUInt32LE(this.pos+4);var combined=first*4294967296+second;var bn;if(combined<=9007199254740991){bn=new BN(combined)}else{var data=Array.prototype.slice.call(this.buf,this.pos,this.pos+8);bn=new BN(data,10,"le")}this.pos=this.pos+8;return bn};BufferReader.prototype.readVarintNum=function(){var first=this.readUInt8();switch(first){case 253:return this.readUInt16LE();case 254:return this.readUInt32LE();case 255:var bn=this.readUInt64LEBN();var n=bn.toNumber();if(n<=Math.pow(2,53)){return n}else{throw new Error("number too large to retain precision - use readVarintBN")}break;default:return first}};BufferReader.prototype.readVarLengthBuffer=function(){var len=this.readVarintNum();var buf=this.read(len);$.checkState(buf.length===len,"Invalid length while reading varlength buffer. "+"Expected to read: "+len+" and read "+buf.length);return buf};BufferReader.prototype.readVarintBuf=function(){var first=this.buf.readUInt8(this.pos);switch(first){case 253:return this.read(1+2);case 254:return this.read(1+4);case 255:return this.read(1+8);default:return this.read(1)}};BufferReader.prototype.readVarintBN=function(){var first=this.readUInt8();switch(first){case 253:return new BN(this.readUInt16LE());case 254:return new BN(this.readUInt32LE());case 255:return this.readUInt64LEBN();default:return new BN(first)}};BufferReader.prototype.reverse=function(){var buf=Buffer.alloc(this.buf.length);for(var i=0;i=0&&arg=HDPrivateKey.Hardened?true:hardened;if(indexMAXIMUM_ENTROPY_BITS*BITS_TO_BYTES){throw new hdErrors.InvalidEntropyArgument.TooMuchEntropy(hexa)}var hash=Hash.sha512hmac(hexa,Buffer.from("Bitcoin seed"));return new HDPrivateKey({network:Network.get(network)||Network.defaultNetwork,depth:0,parentFingerPrint:0,childIndex:0,privateKey:hash.slice(0,32),chainCode:hash.slice(32,64)})};HDPrivateKey.prototype._calcHDPublicKey=function(){if(!this._hdPublicKey){var HDPublicKey=require("./hdpublickey");this._hdPublicKey=new HDPublicKey(this)}};HDPrivateKey.prototype._buildFromBuffers=function(arg){HDPrivateKey._validateBufferArguments(arg);JSUtil.defineImmutable(this,{_buffers:arg});var sequence=[arg.version,arg.depth,arg.parentFingerPrint,arg.childIndex,arg.chainCode,BufferUtil.emptyBuffer(1),arg.privateKey];var concat=buffer.Buffer.concat(sequence);if(!arg.checksum||!arg.checksum.length){arg.checksum=Base58Check.checksum(concat)}else{if(arg.checksum.toString()!==Base58Check.checksum(concat).toString()){throw new errors.InvalidB58Checksum(concat)}}var network=Network.get(BufferUtil.integerFromBuffer(arg.version));var xprivkey;xprivkey=Base58Check.encode(buffer.Buffer.concat(sequence));arg.xprivkey=Buffer.from(xprivkey);var privateKey=new PrivateKey(BN.fromBuffer(arg.privateKey),network);var publicKey=privateKey.toPublicKey();var size=HDPrivateKey.ParentFingerPrintSize;var fingerPrint=Hash.sha256ripemd160(publicKey.toBuffer()).slice(0,size);JSUtil.defineImmutable(this,{xprivkey:xprivkey,network:network,depth:BufferUtil.integerFromSingleByteBuffer(arg.depth),privateKey:privateKey,publicKey:publicKey,fingerPrint:fingerPrint});this._hdPublicKey=null;Object.defineProperty(this,"hdPublicKey",{configurable:false,enumerable:true,get:function(){this._calcHDPublicKey();return this._hdPublicKey}});Object.defineProperty(this,"xpubkey",{configurable:false,enumerable:true,get:function(){this._calcHDPublicKey();return this._hdPublicKey.xpubkey}});return this};HDPrivateKey._validateBufferArguments=function(arg){var checkBuffer=function(name,size){var buff=arg[name];assert(BufferUtil.isBuffer(buff),name+" argument is not a buffer");assert(buff.length===size,name+" has not the expected size: found "+buff.length+", expected "+size)};checkBuffer("version",HDPrivateKey.VersionSize);checkBuffer("depth",HDPrivateKey.DepthSize);checkBuffer("parentFingerPrint",HDPrivateKey.ParentFingerPrintSize);checkBuffer("childIndex",HDPrivateKey.ChildIndexSize);checkBuffer("chainCode",HDPrivateKey.ChainCodeSize);checkBuffer("privateKey",HDPrivateKey.PrivateKeySize);if(arg.checksum&&arg.checksum.length){checkBuffer("checksum",HDPrivateKey.CheckSumSize)}};HDPrivateKey.prototype.toString=function(){return this.xprivkey};HDPrivateKey.prototype.inspect=function(){return""};HDPrivateKey.prototype.toObject=HDPrivateKey.prototype.toJSON=function toObject(){return{network:Network.get(BufferUtil.integerFromBuffer(this._buffers.version),"xprivkey").name,depth:BufferUtil.integerFromSingleByteBuffer(this._buffers.depth),fingerPrint:BufferUtil.integerFromBuffer(this.fingerPrint),parentFingerPrint:BufferUtil.integerFromBuffer(this._buffers.parentFingerPrint),childIndex:BufferUtil.integerFromBuffer(this._buffers.childIndex),chainCode:BufferUtil.bufferToHex(this._buffers.chainCode),privateKey:this.privateKey.toBuffer().toString("hex"),checksum:BufferUtil.integerFromBuffer(this._buffers.checksum),xprivkey:this.xprivkey}};HDPrivateKey.fromBuffer=function(arg){return new HDPrivateKey(arg.toString())};HDPrivateKey.prototype.toBuffer=function(){return BufferUtil.copy(this._buffers.xprivkey)};HDPrivateKey.DefaultDepth=0;HDPrivateKey.DefaultFingerprint=0;HDPrivateKey.DefaultChildIndex=0;HDPrivateKey.Hardened=2147483648;HDPrivateKey.MaxIndex=2*HDPrivateKey.Hardened;HDPrivateKey.RootElementAlias=["m","M","m'","M'"];HDPrivateKey.VersionSize=4;HDPrivateKey.DepthSize=1;HDPrivateKey.ParentFingerPrintSize=4;HDPrivateKey.ChildIndexSize=4;HDPrivateKey.ChainCodeSize=32;HDPrivateKey.PrivateKeySize=32;HDPrivateKey.CheckSumSize=4;HDPrivateKey.DataLength=78;HDPrivateKey.SerializedByteSize=82;HDPrivateKey.VersionStart=0;HDPrivateKey.VersionEnd=HDPrivateKey.VersionStart+HDPrivateKey.VersionSize;HDPrivateKey.DepthStart=HDPrivateKey.VersionEnd;HDPrivateKey.DepthEnd=HDPrivateKey.DepthStart+HDPrivateKey.DepthSize;HDPrivateKey.ParentFingerPrintStart=HDPrivateKey.DepthEnd;HDPrivateKey.ParentFingerPrintEnd=HDPrivateKey.ParentFingerPrintStart+HDPrivateKey.ParentFingerPrintSize;HDPrivateKey.ChildIndexStart=HDPrivateKey.ParentFingerPrintEnd;HDPrivateKey.ChildIndexEnd=HDPrivateKey.ChildIndexStart+HDPrivateKey.ChildIndexSize;HDPrivateKey.ChainCodeStart=HDPrivateKey.ChildIndexEnd;HDPrivateKey.ChainCodeEnd=HDPrivateKey.ChainCodeStart+HDPrivateKey.ChainCodeSize;HDPrivateKey.PrivateKeyStart=HDPrivateKey.ChainCodeEnd+1;HDPrivateKey.PrivateKeyEnd=HDPrivateKey.PrivateKeyStart+HDPrivateKey.PrivateKeySize;HDPrivateKey.ChecksumStart=HDPrivateKey.PrivateKeyEnd;HDPrivateKey.ChecksumEnd=HDPrivateKey.ChecksumStart+HDPrivateKey.CheckSumSize;assert(HDPrivateKey.ChecksumEnd===HDPrivateKey.SerializedByteSize);module.exports=HDPrivateKey}).call(this)}).call(this,require("buffer").Buffer)},{"./crypto/bn":6,"./crypto/hash":8,"./crypto/point":9,"./crypto/random":10,"./encoding/base58":12,"./encoding/base58check":13,"./errors":18,"./hdpublickey":21,"./networks":23,"./privatekey":25,"./util/buffer":45,"./util/js":46,"./util/preconditions":47,assert:124,buffer:175,lodash:103}],21:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var $=require("./util/preconditions");var BN=require("./crypto/bn");var Base58=require("./encoding/base58");var Base58Check=require("./encoding/base58check");var Hash=require("./crypto/hash");var HDPrivateKey=require("./hdprivatekey");var Network=require("./networks");var Point=require("./crypto/point");var PublicKey=require("./publickey");var bitcoreErrors=require("./errors");var errors=bitcoreErrors;var hdErrors=bitcoreErrors.HDPublicKey;var assert=require("assert");var JSUtil=require("./util/js");var BufferUtil=require("./util/buffer");function HDPublicKey(arg){if(arg instanceof HDPublicKey){return arg}if(!(this instanceof HDPublicKey)){return new HDPublicKey(arg)}if(arg){if(_.isString(arg)||BufferUtil.isBuffer(arg)){var error=HDPublicKey.getSerializedError(arg);if(!error){return this._buildFromSerialized(arg)}else if(BufferUtil.isBuffer(arg)&&!HDPublicKey.getSerializedError(arg.toString())){return this._buildFromSerialized(arg.toString())}else{if(error instanceof hdErrors.ArgumentIsPrivateExtended){return new HDPrivateKey(arg).hdPublicKey}throw error}}else{if(_.isObject(arg)){if(arg instanceof HDPrivateKey){return this._buildFromPrivate(arg)}else{return this._buildFromObject(arg)}}else{throw new hdErrors.UnrecognizedArgument(arg)}}}else{throw new hdErrors.MustSupplyArgument}}HDPublicKey.isValidPath=function(arg){if(_.isString(arg)){var indexes=HDPrivateKey._getDerivationIndexes(arg);return indexes!==null&&_.every(indexes,HDPublicKey.isValidPath)}if(_.isNumber(arg)){return arg>=0&&arg=HDPublicKey.Hardened||hardened){throw new hdErrors.InvalidIndexCantDeriveHardened}if(index<0){throw new hdErrors.InvalidPath(index)}var indexBuffer=BufferUtil.integerAsBuffer(index);var data=BufferUtil.concat([this.publicKey.toBuffer(),indexBuffer]);var hash=Hash.sha512hmac(data,this._buffers.chainCode);var leftPart=BN.fromBuffer(hash.slice(0,32),{size:32});var chainCode=hash.slice(32,64);var publicKey;try{publicKey=PublicKey.fromPoint(Point.getG().mul(leftPart).add(this.publicKey.point))}catch(e){return this._deriveWithNumber(index+1)}var derived=new HDPublicKey({network:this.network,depth:this.depth+1,parentFingerPrint:this.fingerPrint,childIndex:index,chainCode:chainCode,publicKey:publicKey});return derived};HDPublicKey.prototype._deriveFromString=function(path){if(_.includes(path,"'")){throw new hdErrors.InvalidIndexCantDeriveHardened}else if(!HDPublicKey.isValidPath(path)){throw new hdErrors.InvalidPath(path)}var indexes=HDPrivateKey._getDerivationIndexes(path);var derived=indexes.reduce(function(prev,index){return prev._deriveWithNumber(index)},this);return derived};HDPublicKey.isValidSerialized=function(data,network){return _.isNull(HDPublicKey.getSerializedError(data,network))};HDPublicKey.getSerializedError=function(data,network){if(!(_.isString(data)||BufferUtil.isBuffer(data))){return new hdErrors.UnrecognizedArgument("expected buffer or string")}if(!Base58.validCharacters(data)){return new errors.InvalidB58Char("(unknown)",data)}try{data=Base58Check.decode(data)}catch(e){return new errors.InvalidB58Checksum(data)}if(data.length!==HDPublicKey.DataSize){return new hdErrors.InvalidLength(data)}if(!_.isUndefined(network)){var error=HDPublicKey._validateNetwork(data,network);if(error){return error}}var version=BufferUtil.integerFromBuffer(data.slice(0,4));if(version===Network.livenet.xprivkey||version===Network.testnet.xprivkey){return new hdErrors.ArgumentIsPrivateExtended}return null};HDPublicKey._validateNetwork=function(data,networkArg){var network=Network.get(networkArg);if(!network){return new errors.InvalidNetworkArgument(networkArg)}var version=data.slice(HDPublicKey.VersionStart,HDPublicKey.VersionEnd);if(BufferUtil.integerFromBuffer(version)!==network.xpubkey){return new errors.InvalidNetwork(version)}return null};HDPublicKey.prototype._buildFromPrivate=function(arg){var args=_.clone(arg._buffers);var point=Point.getG().mul(BN.fromBuffer(args.privateKey));args.publicKey=Point.pointToCompressed(point);args.version=BufferUtil.integerAsBuffer(Network.get(BufferUtil.integerFromBuffer(args.version)).xpubkey);args.privateKey=undefined;args.checksum=undefined;args.xprivkey=undefined;return this._buildFromBuffers(args)};HDPublicKey.prototype._buildFromObject=function(arg){var buffers={version:arg.network?BufferUtil.integerAsBuffer(Network.get(arg.network).xpubkey):arg.version,depth:_.isNumber(arg.depth)?BufferUtil.integerAsSingleByteBuffer(arg.depth):arg.depth,parentFingerPrint:_.isNumber(arg.parentFingerPrint)?BufferUtil.integerAsBuffer(arg.parentFingerPrint):arg.parentFingerPrint,childIndex:_.isNumber(arg.childIndex)?BufferUtil.integerAsBuffer(arg.childIndex):arg.childIndex,chainCode:_.isString(arg.chainCode)?Buffer.from(arg.chainCode,"hex"):arg.chainCode,publicKey:_.isString(arg.publicKey)?Buffer.from(arg.publicKey,"hex"):BufferUtil.isBuffer(arg.publicKey)?arg.publicKey:arg.publicKey.toBuffer(),checksum:_.isNumber(arg.checksum)?BufferUtil.integerAsBuffer(arg.checksum):arg.checksum};return this._buildFromBuffers(buffers)};HDPublicKey.prototype._buildFromSerialized=function(arg){var decoded=Base58Check.decode(arg);var buffers={version:decoded.slice(HDPublicKey.VersionStart,HDPublicKey.VersionEnd),depth:decoded.slice(HDPublicKey.DepthStart,HDPublicKey.DepthEnd),parentFingerPrint:decoded.slice(HDPublicKey.ParentFingerPrintStart,HDPublicKey.ParentFingerPrintEnd),childIndex:decoded.slice(HDPublicKey.ChildIndexStart,HDPublicKey.ChildIndexEnd),chainCode:decoded.slice(HDPublicKey.ChainCodeStart,HDPublicKey.ChainCodeEnd),publicKey:decoded.slice(HDPublicKey.PublicKeyStart,HDPublicKey.PublicKeyEnd),checksum:decoded.slice(HDPublicKey.ChecksumStart,HDPublicKey.ChecksumEnd),xpubkey:arg};return this._buildFromBuffers(buffers)};HDPublicKey.prototype._buildFromBuffers=function(arg){HDPublicKey._validateBufferArguments(arg);JSUtil.defineImmutable(this,{_buffers:arg});var sequence=[arg.version,arg.depth,arg.parentFingerPrint,arg.childIndex,arg.chainCode,arg.publicKey];var concat=BufferUtil.concat(sequence);var checksum=Base58Check.checksum(concat);if(!arg.checksum||!arg.checksum.length){arg.checksum=checksum}else{if(arg.checksum.toString("hex")!==checksum.toString("hex")){throw new errors.InvalidB58Checksum(concat,checksum)}}var network=Network.get(BufferUtil.integerFromBuffer(arg.version));var xpubkey;xpubkey=Base58Check.encode(BufferUtil.concat(sequence));arg.xpubkey=Buffer.from(xpubkey);var publicKey=new PublicKey(arg.publicKey,{network:network});var size=HDPublicKey.ParentFingerPrintSize;var fingerPrint=Hash.sha256ripemd160(publicKey.toBuffer()).slice(0,size);JSUtil.defineImmutable(this,{xpubkey:xpubkey,network:network,depth:BufferUtil.integerFromSingleByteBuffer(arg.depth),publicKey:publicKey,fingerPrint:fingerPrint});return this};HDPublicKey._validateBufferArguments=function(arg){var checkBuffer=function(name,size){var buff=arg[name];assert(BufferUtil.isBuffer(buff),name+" argument is not a buffer, it's "+typeof buff);assert(buff.length===size,name+" has not the expected size: found "+buff.length+", expected "+size)};checkBuffer("version",HDPublicKey.VersionSize);checkBuffer("depth",HDPublicKey.DepthSize);checkBuffer("parentFingerPrint",HDPublicKey.ParentFingerPrintSize);checkBuffer("childIndex",HDPublicKey.ChildIndexSize);checkBuffer("chainCode",HDPublicKey.ChainCodeSize);checkBuffer("publicKey",HDPublicKey.PublicKeySize);if(arg.checksum&&arg.checksum.length){checkBuffer("checksum",HDPublicKey.CheckSumSize)}};HDPublicKey.fromString=function(arg){$.checkArgument(_.isString(arg),"No valid string was provided");return new HDPublicKey(arg)};HDPublicKey.fromObject=function(arg){$.checkArgument(_.isObject(arg),"No valid argument was provided");return new HDPublicKey(arg)};HDPublicKey.prototype.toString=function(){return this.xpubkey};HDPublicKey.prototype.inspect=function(){return""};HDPublicKey.prototype.toObject=HDPublicKey.prototype.toJSON=function toObject(){return{network:Network.get(BufferUtil.integerFromBuffer(this._buffers.version)).name,depth:BufferUtil.integerFromSingleByteBuffer(this._buffers.depth),fingerPrint:BufferUtil.integerFromBuffer(this.fingerPrint),parentFingerPrint:BufferUtil.integerFromBuffer(this._buffers.parentFingerPrint),childIndex:BufferUtil.integerFromBuffer(this._buffers.childIndex),chainCode:BufferUtil.bufferToHex(this._buffers.chainCode),publicKey:this.publicKey.toString(),checksum:BufferUtil.integerFromBuffer(this._buffers.checksum),xpubkey:this.xpubkey}};HDPublicKey.fromBuffer=function(arg){return new HDPublicKey(arg)};HDPublicKey.prototype.toBuffer=function(){return BufferUtil.copy(this._buffers.xpubkey)};HDPublicKey.Hardened=2147483648;HDPublicKey.RootElementAlias=["m","M"];HDPublicKey.VersionSize=4;HDPublicKey.DepthSize=1;HDPublicKey.ParentFingerPrintSize=4;HDPublicKey.ChildIndexSize=4;HDPublicKey.ChainCodeSize=32;HDPublicKey.PublicKeySize=33;HDPublicKey.CheckSumSize=4;HDPublicKey.DataSize=78;HDPublicKey.SerializedByteSize=82;HDPublicKey.VersionStart=0;HDPublicKey.VersionEnd=HDPublicKey.VersionStart+HDPublicKey.VersionSize;HDPublicKey.DepthStart=HDPublicKey.VersionEnd;HDPublicKey.DepthEnd=HDPublicKey.DepthStart+HDPublicKey.DepthSize;HDPublicKey.ParentFingerPrintStart=HDPublicKey.DepthEnd;HDPublicKey.ParentFingerPrintEnd=HDPublicKey.ParentFingerPrintStart+HDPublicKey.ParentFingerPrintSize;HDPublicKey.ChildIndexStart=HDPublicKey.ParentFingerPrintEnd;HDPublicKey.ChildIndexEnd=HDPublicKey.ChildIndexStart+HDPublicKey.ChildIndexSize;HDPublicKey.ChainCodeStart=HDPublicKey.ChildIndexEnd;HDPublicKey.ChainCodeEnd=HDPublicKey.ChainCodeStart+HDPublicKey.ChainCodeSize;HDPublicKey.PublicKeyStart=HDPublicKey.ChainCodeEnd;HDPublicKey.PublicKeyEnd=HDPublicKey.PublicKeyStart+HDPublicKey.PublicKeySize;HDPublicKey.ChecksumStart=HDPublicKey.PublicKeyEnd;HDPublicKey.ChecksumEnd=HDPublicKey.ChecksumStart+HDPublicKey.CheckSumSize;assert(HDPublicKey.PublicKeyEnd===HDPublicKey.DataSize);assert(HDPublicKey.ChecksumEnd===HDPublicKey.SerializedByteSize);module.exports=HDPublicKey}).call(this)}).call(this,require("buffer").Buffer)},{"./crypto/bn":6,"./crypto/hash":8,"./crypto/point":9,"./encoding/base58":12,"./encoding/base58check":13,"./errors":18,"./hdprivatekey":20,"./networks":23,"./publickey":26,"./util/buffer":45,"./util/js":46,"./util/preconditions":47,assert:124,buffer:175,lodash:103}],22:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var PrivateKey=require("./privatekey");var PublicKey=require("./publickey");var Address=require("./address");var BufferWriter=require("./encoding/bufferwriter");var ECDSA=require("./crypto/ecdsa");var Signature=require("./crypto/signature");var sha256sha256=require("./crypto/hash").sha256sha256;var JSUtil=require("./util/js");var $=require("./util/preconditions");function Message(message){if(!(this instanceof Message)){return new Message(message)}$.checkArgument(_.isString(message),"First argument should be a string");this.message=message;return this}Message.MAGIC_BYTES=Buffer.from("Bitcoin Signed Message:\n");Message.prototype.magicHash=function magicHash(){var prefix1=BufferWriter.varintBufNum(Message.MAGIC_BYTES.length);var messageBuffer=Buffer.from(this.message);var prefix2=BufferWriter.varintBufNum(messageBuffer.length);var buf=Buffer.concat([prefix1,Message.MAGIC_BYTES,prefix2,messageBuffer]);var hash=sha256sha256(buf);return hash};Message.prototype._sign=function _sign(privateKey){$.checkArgument(privateKey instanceof PrivateKey,"First argument should be an instance of PrivateKey");var hash=this.magicHash();var ecdsa=new ECDSA;ecdsa.hashbuf=hash;ecdsa.privkey=privateKey;ecdsa.pubkey=privateKey.toPublicKey();ecdsa.signRandomK();ecdsa.calci();return ecdsa.sig};Message.prototype.sign=function sign(privateKey){var signature=this._sign(privateKey);return signature.toCompact().toString("base64")};Message.prototype._verify=function _verify(publicKey,signature){$.checkArgument(publicKey instanceof PublicKey,"First argument should be an instance of PublicKey");$.checkArgument(signature instanceof Signature,"Second argument should be an instance of Signature");var hash=this.magicHash();var verified=ECDSA.verify(hash,signature,publicKey);if(!verified){this.error="The signature was invalid"}return verified};Message.prototype.verify=function verify(bitcoinAddress,signatureString){$.checkArgument(bitcoinAddress);$.checkArgument(signatureString&&_.isString(signatureString));if(_.isString(bitcoinAddress)){bitcoinAddress=Address.fromString(bitcoinAddress)}var signature=Signature.fromCompact(Buffer.from(signatureString,"base64"));var ecdsa=new ECDSA;ecdsa.hashbuf=this.magicHash();ecdsa.sig=signature;var publicKey=ecdsa.toPublicKey();var signatureAddress=Address.fromPublicKey(publicKey,bitcoinAddress.network);if(bitcoinAddress.toString()!==signatureAddress.toString()){this.error="The signature did not match the message digest";return false}return this._verify(publicKey,signature)};Message.prototype.recoverPublicKey=function recoverPublicKey(bitcoinAddress,signatureString){$.checkArgument(bitcoinAddress);$.checkArgument(signatureString&&_.isString(signatureString));if(_.isString(bitcoinAddress)){bitcoinAddress=Address.fromString(bitcoinAddress)}var signature=Signature.fromCompact(Buffer.from(signatureString,"base64"));var ecdsa=new ECDSA;ecdsa.hashbuf=this.magicHash();ecdsa.sig=signature;var publicKey=ecdsa.toPublicKey();var signatureAddress=Address.fromPublicKey(publicKey,bitcoinAddress.network);if(bitcoinAddress.toString()!==signatureAddress.toString()){this.error="The signature did not match the message digest"}return publicKey.toString()};Message.fromString=function(str){return new Message(str)};Message.fromJSON=function fromJSON(json){if(JSUtil.isValidJSON(json)){json=JSON.parse(json)}return new Message(json.message)};Message.prototype.toObject=function toObject(){return{message:this.message}};Message.prototype.toJSON=function toJSON(){return JSON.stringify(this.toObject())};Message.prototype.toString=function(){return this.message};Message.prototype.inspect=function(){return""};module.exports=Message;var Script=require("./script")}).call(this)}).call(this,require("buffer").Buffer)},{"./address":1,"./crypto/ecdsa":7,"./crypto/hash":8,"./crypto/signature":11,"./encoding/bufferwriter":16,"./privatekey":25,"./publickey":26,"./script":27,"./util/js":46,"./util/preconditions":47,buffer:175,lodash:103}],23:[function(require,module,exports){"use strict";var _=require("lodash");var BufferUtil=require("./util/buffer");var JSUtil=require("./util/js");var networks=[];var networkMaps={};function Network(){}Network.prototype.toString=function toString(){return this.name};function get(arg,keys){if(~networks.indexOf(arg)){return arg}if(keys){if(!_.isArray(keys)){keys=[keys]}var containsArg=function(key){return networks[index][key]===arg};for(var index in networks){if(_.some(keys,containsArg)){return networks[index]}}return undefined}if(networkMaps[arg]&&networkMaps[arg].length>=1){return networkMaps[arg][0]}else{return networkMaps[arg]}}function addNetwork(data){var network=new Network;JSUtil.defineImmutable(network,{name:data.name,alias:data.alias,pubkeyhash:data.pubkeyhash,privatekey:data.privatekey,scripthash:data.scripthash,bech32prefix:data.bech32prefix,xpubkey:data.xpubkey,xprivkey:data.xprivkey});if(data.networkMagic){JSUtil.defineImmutable(network,{networkMagic:BufferUtil.integerAsBuffer(data.networkMagic)})}if(data.port){JSUtil.defineImmutable(network,{port:data.port})}if(data.dnsSeeds){JSUtil.defineImmutable(network,{dnsSeeds:data.dnsSeeds})}_.each(network,function(value){if(!_.isUndefined(value)&&!_.isObject(value)){if(!networkMaps[value]){networkMaps[value]=[]}networkMaps[value].push(network)}});networks.push(network);return network}function removeNetwork(network){for(var i=0;i=0){delete networkMaps[key][index]}}}addNetwork({name:"livenet",alias:"mainnet",pubkeyhash:0,privatekey:128,scripthash:5,bech32prefix:"bc",xpubkey:76067358,xprivkey:76066276,networkMagic:4190024921,port:8333,dnsSeeds:["seed.bitcoin.sipa.be","dnsseed.bluematt.me","dnsseed.bitcoin.dashjr.org","seed.bitcoinstats.com","seed.bitnodes.io","bitseed.xf2.org"]});var livenet=get("livenet");addNetwork({name:"testnet",alias:"test",pubkeyhash:111,privatekey:239,scripthash:196,bech32prefix:"tb",xpubkey:70617039,xprivkey:70615956,networkMagic:185665799,port:18333,dnsSeeds:["testnet-seed.bitcoin.petertodd.org","testnet-seed.bluematt.me","testnet-seed.alexykot.me","testnet-seed.bitcoin.schildbach.de"]});var testnet=get("testnet");addNetwork({name:"regtest",alias:"dev",pubkeyhash:111,privatekey:239,scripthash:196,bech32prefix:"bcrt",xpubkey:70617039,xprivkey:70615956,networkMagic:4206867930,port:18444,dnsSeeds:[]});var regtest=get("regtest");function enableRegtest(){testnet.regtestEnabled=true}function disableRegtest(){testnet.regtestEnabled=false}module.exports={add:addNetwork,remove:removeNetwork,defaultNetwork:livenet,livenet:livenet,mainnet:livenet,testnet:testnet,regtest:regtest,get:get,enableRegtest:enableRegtest,disableRegtest:disableRegtest}},{"./util/buffer":45,"./util/js":46,lodash:103}],24:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var $=require("./util/preconditions");var BufferUtil=require("./util/buffer");var JSUtil=require("./util/js");function Opcode(num){if(!(this instanceof Opcode)){return new Opcode(num)}var value;if(_.isNumber(num)){value=num}else if(_.isString(num)){value=Opcode.map[num]}else{throw new TypeError('Unrecognized num type: "'+typeof num+'" for Opcode')}JSUtil.defineImmutable(this,{num:value});return this}Opcode.fromBuffer=function(buf){$.checkArgument(BufferUtil.isBuffer(buf));return new Opcode(Number("0x"+buf.toString("hex")))};Opcode.fromNumber=function(num){$.checkArgument(_.isNumber(num));return new Opcode(num)};Opcode.fromString=function(str){$.checkArgument(_.isString(str));var value=Opcode.map[str];if(typeof value==="undefined"){throw new TypeError("Invalid opcodestr")}return new Opcode(value)};Opcode.prototype.toHex=function(){return this.num.toString(16)};Opcode.prototype.toBuffer=function(){return Buffer.from(this.toHex(),"hex")};Opcode.prototype.toNumber=function(){return this.num};Opcode.prototype.toString=function(){var str=Opcode.reverseMap[this.num];if(typeof str==="undefined"){throw new Error("Opcode does not have a string representation")}return str};Opcode.smallInt=function(n){$.checkArgument(_.isNumber(n),"Invalid Argument: n should be number");$.checkArgument(n>=0&&n<=16,"Invalid Argument: n must be between 0 and 16");if(n===0){return Opcode("OP_0")}return new Opcode(Opcode.map.OP_1+n-1)};Opcode.map={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_CHECKLOCKTIMEVERIFY:177,OP_CHECKSEQUENCEVERIFY:178,OP_NOP1:176,OP_NOP2:177,OP_NOP3:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255};Opcode.reverseMap=[];for(var k in Opcode.map){Opcode.reverseMap[Opcode.map[k]]=k}_.extend(Opcode,Opcode.map);Opcode.isSmallIntOp=function(opcode){if(opcode instanceof Opcode){opcode=opcode.toNumber()}return opcode===Opcode.map.OP_0||opcode>=Opcode.map.OP_1&&opcode<=Opcode.map.OP_16};Opcode.prototype.inspect=function(){return""};module.exports=Opcode}).call(this)}).call(this,require("buffer").Buffer)},{"./util/buffer":45,"./util/js":46,"./util/preconditions":47,buffer:175,lodash:103}],25:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var Address=require("./address");var Base58Check=require("./encoding/base58check");var BN=require("./crypto/bn");var JSUtil=require("./util/js");var Networks=require("./networks");var Point=require("./crypto/point");var PublicKey=require("./publickey");var Random=require("./crypto/random");var $=require("./util/preconditions");function PrivateKey(data,network){if(!(this instanceof PrivateKey)){return new PrivateKey(data,network)}if(data instanceof PrivateKey){return data}var info=this._classifyArguments(data,network);if(!info.bn||info.bn.cmp(new BN(0))===0){throw new TypeError("Number can not be equal to zero, undefined, null or false")}if(!info.bn.lt(Point.getN())){throw new TypeError("Number must be less than N")}if(typeof info.network==="undefined"){throw new TypeError('Must specify the network ("livenet" or "testnet")')}JSUtil.defineImmutable(this,{bn:info.bn,compressed:info.compressed,network:info.network});Object.defineProperty(this,"publicKey",{configurable:false,enumerable:true,get:this.toPublicKey.bind(this)});return this}PrivateKey.prototype._classifyArguments=function(data,network){var info={compressed:true,network:network?Networks.get(network):Networks.defaultNetwork};if(_.isUndefined(data)||_.isNull(data)){info.bn=PrivateKey._getRandomBN()}else if(data instanceof BN){info.bn=data}else if(data instanceof Buffer||data instanceof Uint8Array){info=PrivateKey._transformBuffer(data,network)}else if(data.bn&&data.network){info=PrivateKey._transformObject(data)}else if(!network&&Networks.get(data)){info.bn=PrivateKey._getRandomBN();info.network=Networks.get(data)}else if(typeof data==="string"){if(JSUtil.isHexa(data)){info.bn=new BN(Buffer.from(data,"hex"))}else{info=PrivateKey._transformWIF(data,network)}}else{throw new TypeError("First argument is an unrecognized data type.")}return info};PrivateKey._getRandomBN=function(){var condition;var bn;do{var privbuf=Random.getRandomBuffer(32);bn=BN.fromBuffer(privbuf);condition=bn.lt(Point.getN())}while(!condition);return bn};PrivateKey._transformBuffer=function(buf,network){var info={};if(buf.length===32){return PrivateKey._transformBNBuffer(buf,network)}info.network=Networks.get(buf[0],"privatekey");if(!info.network){throw new Error("Invalid network")}if(network&&info.network!==Networks.get(network)){throw new TypeError("Private key network mismatch")}if(buf.length===1+32+1&&buf[1+32+1-1]===1){info.compressed=true}else if(buf.length===1+32){info.compressed=false}else{throw new Error("Length of buffer must be 33 (uncompressed) or 34 (compressed)")}info.bn=BN.fromBuffer(buf.slice(1,32+1));return info};PrivateKey._transformBNBuffer=function(buf,network){var info={};info.network=Networks.get(network)||Networks.defaultNetwork;info.bn=BN.fromBuffer(buf);info.compressed=false;return info};PrivateKey._transformWIF=function(str,network){return PrivateKey._transformBuffer(Base58Check.decode(str),network)};PrivateKey.fromBuffer=function(arg,network){return new PrivateKey(arg,network)};PrivateKey._transformObject=function(json){var bn=new BN(json.bn,"hex");var network=Networks.get(json.network);return{bn:bn,network:network,compressed:json.compressed}};PrivateKey.fromString=PrivateKey.fromWIF=function(str){$.checkArgument(_.isString(str),"First argument is expected to be a string.");return new PrivateKey(str)};PrivateKey.fromObject=function(obj){$.checkArgument(_.isObject(obj),"First argument is expected to be an object.");return new PrivateKey(obj)};PrivateKey.fromRandom=function(network){var bn=PrivateKey._getRandomBN();return new PrivateKey(bn,network)};PrivateKey.getValidationError=function(data,network){var error;try{new PrivateKey(data,network)}catch(e){error=e}return error};PrivateKey.isValid=function(data,network){if(!data){return false}return!PrivateKey.getValidationError(data,network)};PrivateKey.prototype.toString=function(){return this.toBuffer().toString("hex")};PrivateKey.prototype.toWIF=function(){var network=this.network;var compressed=this.compressed;var buf;if(compressed){buf=Buffer.concat([Buffer.from([network.privatekey]),this.bn.toBuffer({size:32}),Buffer.from([1])])}else{buf=Buffer.concat([Buffer.from([network.privatekey]),this.bn.toBuffer({size:32})])}return Base58Check.encode(buf)};PrivateKey.prototype.toBigNumber=function(){return this.bn};PrivateKey.prototype.toBuffer=function(){return this.bn.toBuffer({size:32})};PrivateKey.prototype.toBufferNoPadding=function(){return this.bn.toBuffer()};PrivateKey.prototype.toPublicKey=function(){if(!this._pubkey){this._pubkey=PublicKey.fromPrivateKey(this)}return this._pubkey};PrivateKey.prototype.toAddress=function(network,type){var pubkey=this.toPublicKey();return Address.fromPublicKey(pubkey,network||this.network,type)};PrivateKey.prototype.toObject=PrivateKey.prototype.toJSON=function toObject(){return{bn:this.bn.toString("hex"),compressed:this.compressed,network:this.network.toString()}};PrivateKey.prototype.inspect=function(){var uncompressed=!this.compressed?", uncompressed":"";return""};module.exports=PrivateKey}).call(this)}).call(this,require("buffer").Buffer)},{"./address":1,"./crypto/bn":6,"./crypto/point":9,"./crypto/random":10,"./encoding/base58check":13,"./networks":23,"./publickey":26,"./util/js":46,"./util/preconditions":47,buffer:175,lodash:103}],26:[function(require,module,exports){(function(Buffer){(function(){"use strict";var BN=require("./crypto/bn");var Point=require("./crypto/point");var Hash=require("./crypto/hash");var JSUtil=require("./util/js");var Network=require("./networks");var _=require("lodash");var $=require("./util/preconditions");function PublicKey(data,extra){if(!(this instanceof PublicKey)){return new PublicKey(data,extra)}$.checkArgument(data,"First argument is required, please include public key data.");if(data instanceof PublicKey){return data}extra=extra||{};var info=this._classifyArgs(data,extra);info.point.validate();JSUtil.defineImmutable(this,{point:info.point,compressed:info.compressed,network:info.network||Network.defaultNetwork});return this}PublicKey.prototype._classifyArgs=function(data,extra){var info={compressed:_.isUndefined(extra.compressed)||extra.compressed};if(data instanceof Point){info.point=data}else if(data.x&&data.y){info=PublicKey._transformObject(data)}else if(typeof data==="string"){info=PublicKey._transformDER(Buffer.from(data,"hex"))}else if(PublicKey._isBuffer(data)){info=PublicKey._transformDER(data)}else if(PublicKey._isPrivateKey(data)){info=PublicKey._transformPrivateKey(data)}else{throw new TypeError("First argument is an unrecognized data format.")}if(!info.network){info.network=_.isUndefined(extra.network)?undefined:Network.get(extra.network)}return info};PublicKey._isPrivateKey=function(param){var PrivateKey=require("./privatekey");return param instanceof PrivateKey};PublicKey._isBuffer=function(param){return param instanceof Buffer||param instanceof Uint8Array};PublicKey._transformPrivateKey=function(privkey){$.checkArgument(PublicKey._isPrivateKey(privkey),"Must be an instance of PrivateKey");var info={};info.point=Point.getG().mul(privkey.bn);info.compressed=privkey.compressed;info.network=privkey.network;return info};PublicKey._transformDER=function(buf,strict){$.checkArgument(PublicKey._isBuffer(buf),"Must be a hex buffer of DER encoded public key");var info={};strict=_.isUndefined(strict)?true:strict;var x;var y;var xbuf;var ybuf;if(buf[0]===4||!strict&&(buf[0]===6||buf[0]===7)){xbuf=buf.slice(1,33);ybuf=buf.slice(33,65);if(xbuf.length!==32||ybuf.length!==32||buf.length!==65){throw new TypeError("Length of x and y must be 32 bytes")}x=new BN(xbuf);y=new BN(ybuf);info.point=new Point(x,y);info.compressed=false}else if(buf[0]===3){xbuf=buf.slice(1);x=new BN(xbuf);info=PublicKey._transformX(true,x);info.compressed=true}else if(buf[0]===2){xbuf=buf.slice(1);x=new BN(xbuf);info=PublicKey._transformX(false,x);info.compressed=true}else{throw new TypeError("Invalid DER format public key")}return info};PublicKey._transformX=function(odd,x){$.checkArgument(typeof odd==="boolean","Must specify whether y is odd or not (true or false)");var info={};info.point=Point.fromX(odd,x);return info};PublicKey._transformObject=function(json){var x=new BN(json.x,"hex");var y=new BN(json.y,"hex");var point=new Point(x,y);return new PublicKey(point,{compressed:json.compressed})};PublicKey.fromPrivateKey=function(privkey){$.checkArgument(PublicKey._isPrivateKey(privkey),"Must be an instance of PrivateKey");var info=PublicKey._transformPrivateKey(privkey);return new PublicKey(info.point,{compressed:info.compressed,network:info.network})};PublicKey.fromDER=PublicKey.fromBuffer=function(buf,strict){$.checkArgument(PublicKey._isBuffer(buf),"Must be a hex buffer of DER encoded public key");var info=PublicKey._transformDER(buf,strict);return new PublicKey(info.point,{compressed:info.compressed})};PublicKey.fromPoint=function(point,compressed){$.checkArgument(point instanceof Point,"First argument must be an instance of Point.");return new PublicKey(point,{compressed:compressed})};PublicKey.fromString=function(str,encoding){var buf=Buffer.from(str,encoding||"hex");var info=PublicKey._transformDER(buf);return new PublicKey(info.point,{compressed:info.compressed})};PublicKey.fromX=function(odd,x){var info=PublicKey._transformX(odd,x);return new PublicKey(info.point,{compressed:info.compressed})};PublicKey.getValidationError=function(data){var error;try{new PublicKey(data)}catch(e){error=e}return error};PublicKey.isValid=function(data){return!PublicKey.getValidationError(data)};PublicKey.prototype.toObject=PublicKey.prototype.toJSON=function toObject(){return{x:this.point.getX().toString("hex",2),y:this.point.getY().toString("hex",2),compressed:this.compressed}};PublicKey.prototype.toBuffer=PublicKey.prototype.toDER=function(){var x=this.point.getX();var y=this.point.getY();var xbuf=x.toBuffer({size:32});var ybuf=y.toBuffer({size:32});var prefix;if(!this.compressed){prefix=Buffer.from([4]);return Buffer.concat([prefix,xbuf,ybuf])}else{var odd=ybuf[ybuf.length-1]%2;if(odd){prefix=Buffer.from([3])}else{prefix=Buffer.from([2])}return Buffer.concat([prefix,xbuf])}};PublicKey.prototype._getID=function _getID(){return Hash.sha256ripemd160(this.toBuffer())};PublicKey.prototype.toAddress=function(network,type){var Address=require("./address");return Address.fromPublicKey(this,network||this.network,type)};PublicKey.prototype.toString=function(){return this.toDER().toString("hex")};PublicKey.prototype.inspect=function(){return""};module.exports=PublicKey}).call(this)}).call(this,require("buffer").Buffer)},{"./address":1,"./crypto/bn":6,"./crypto/hash":8,"./crypto/point":9,"./networks":23,"./privatekey":25,"./util/js":46,"./util/preconditions":47,buffer:175,lodash:103}],27:[function(require,module,exports){module.exports=require("./script");module.exports.Interpreter=require("./interpreter")},{"./interpreter":28,"./script":29}],28:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var Script=require("./script");var Opcode=require("../opcode");var BN=require("../crypto/bn");var Hash=require("../crypto/hash");var Signature=require("../crypto/signature");var PublicKey=require("../publickey");var Interpreter=function Interpreter(obj){if(!(this instanceof Interpreter)){return new Interpreter(obj)}if(obj){this.initialize();this.set(obj)}else{this.initialize()}};Interpreter.SIGVERSION_BASE=0;Interpreter.SIGVERSION_WITNESS_V0=1;Interpreter.SIGVERSION_TAPROOT=2;Interpreter.SIGVERSION_TAPSCRIPT=3;Interpreter.prototype.verifyWitnessProgram=function(version,program,witness,satoshis,flags){var scriptPubKey=new Script;var stack=[];if(version===0){if(program.length===32){if(witness.length===0){this.errstr="SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY";return false}var scriptPubKeyBuffer=witness[witness.length-1];scriptPubKey=new Script(scriptPubKeyBuffer);var hash=Hash.sha256(scriptPubKeyBuffer);if(hash.toString("hex")!==program.toString("hex")){this.errstr="SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH";return false}stack=witness.slice(0,-1)}else if(program.length===20){if(witness.length!==2){this.errstr="SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH";return false}scriptPubKey.add(Opcode.OP_DUP);scriptPubKey.add(Opcode.OP_HASH160);scriptPubKey.add(program);scriptPubKey.add(Opcode.OP_EQUALVERIFY);scriptPubKey.add(Opcode.OP_CHECKSIG);stack=witness}else{this.errstr="SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH";return false}}else if(flags&Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM){this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM";return false}else{return true}this.initialize();this.set({script:scriptPubKey,stack:stack,sigversion:Interpreter.SIGVERSION_WITNESS_V0,satoshis:satoshis,flags:flags});if(!this.evaluate()){return false}if(this.stack.length!==1){this.errstr="SCRIPT_ERR_EVAL_FALSE";return false}var buf=this.stack[this.stack.length-1];if(!Interpreter.castToBool(buf)){this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_STACK";return false}return true};Interpreter.prototype.verify=function(scriptSig,scriptPubkey,tx,nin,flags,witness,satoshis){var Transaction=require("../transaction");if(_.isUndefined(tx)){tx=new Transaction}if(_.isUndefined(nin)){nin=0}if(_.isUndefined(flags)){flags=0}if(_.isUndefined(witness)){witness=null}if(_.isUndefined(satoshis)){satoshis=0}this.set({script:scriptSig,tx:tx,nin:nin,sigversion:Interpreter.SIGVERSION_BASE,satoshis:0,flags:flags});var stackCopy;if((flags&Interpreter.SCRIPT_VERIFY_SIGPUSHONLY)!==0&&!scriptSig.isPushOnly()){this.errstr="SCRIPT_ERR_SIG_PUSHONLY";return false}if(!this.evaluate()){return false}if(flags&Interpreter.SCRIPT_VERIFY_P2SH){stackCopy=this.stack.slice()}var stack=this.stack;this.initialize();this.set({script:scriptPubkey,stack:stack,tx:tx,nin:nin,flags:flags});if(!this.evaluate()){return false}if(this.stack.length===0){this.errstr="SCRIPT_ERR_EVAL_FALSE_NO_RESULT";return false}var buf=this.stack[this.stack.length-1];if(!Interpreter.castToBool(buf)){this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_STACK";return false}var hadWitness=false;if(flags&Interpreter.SCRIPT_VERIFY_WITNESS){var witnessValues={};if(scriptPubkey.isWitnessProgram(witnessValues)){hadWitness=true;if(scriptSig.toBuffer().length!==0){return false}if(!this.verifyWitnessProgram(witnessValues.version,witnessValues.program,witness,satoshis,this.flags)){return false}}}if(flags&Interpreter.SCRIPT_VERIFY_P2SH&&scriptPubkey.isScriptHashOut()){if(!scriptSig.isPushOnly()){this.errstr="SCRIPT_ERR_SIG_PUSHONLY";return false}if(stackCopy.length===0){throw new Error("internal error - stack copy empty")}var redeemScriptSerialized=stackCopy[stackCopy.length-1];var redeemScript=Script.fromBuffer(redeemScriptSerialized);stackCopy.pop();this.initialize();this.set({script:redeemScript,stack:stackCopy,tx:tx,nin:nin,flags:flags});if(!this.evaluate()){return false}if(stackCopy.length===0){this.errstr="SCRIPT_ERR_EVAL_FALSE_NO_P2SH_STACK";return false}if(!Interpreter.castToBool(stackCopy[stackCopy.length-1])){this.errstr="SCRIPT_ERR_EVAL_FALSE_IN_P2SH_STACK";return false}if(flags&Interpreter.SCRIPT_VERIFY_WITNESS){var p2shWitnessValues={};if(redeemScript.isWitnessProgram(p2shWitnessValues)){hadWitness=true;var redeemScriptPush=new Script;redeemScriptPush.add(redeemScript.toBuffer());if(scriptSig.toHex()!==redeemScriptPush.toHex()){this.errstr="SCRIPT_ERR_WITNESS_MALLEATED_P2SH";return false}if(!this.verifyWitnessProgram(p2shWitnessValues.version,p2shWitnessValues.program,witness,satoshis,this.flags)){return false}stack=[stack[0]]}}}if((this.flags&Interpreter.SCRIPT_VERIFY_CLEANSTACK)!=0){if((this.flags&Interpreter.SCRIPT_VERIFY_P2SH)==0)throw"flags & SCRIPT_VERIFY_P2SH";if(stackCopy.length!=1){this.errstr="SCRIPT_ERR_CLEANSTACK";return false}}if(this.flags&Interpreter.SCRIPT_VERIFY_WITNESS){if(!hadWitness&&witness.length>0){this.errstr="SCRIPT_ERR_WITNESS_UNEXPECTED";return false}}return true};module.exports=Interpreter;Interpreter.prototype.initialize=function(obj){this.stack=[];this.altstack=[];this.pc=0;this.satoshis=0;this.sigversion=Interpreter.SIGVERSION_BASE;this.pbegincodehash=0;this.nOpCount=0;this.vfExec=[];this.errstr="";this.flags=0};Interpreter.prototype.set=function(obj){this.script=obj.script||this.script;this.tx=obj.tx||this.tx;this.nin=typeof obj.nin!=="undefined"?obj.nin:this.nin;this.stack=obj.stack||this.stack;this.altstack=obj.altack||this.altstack;this.pc=typeof obj.pc!=="undefined"?obj.pc:this.pc;this.pbegincodehash=typeof obj.pbegincodehash!=="undefined"?obj.pbegincodehash:this.pbegincodehash;this.sigversion=typeof obj.sigversion!=="undefined"?obj.sigversion:this.sigversion;this.satoshis=typeof obj.satoshis!=="undefined"?obj.satoshis:this.satoshis;this.nOpCount=typeof obj.nOpCount!=="undefined"?obj.nOpCount:this.nOpCount;this.vfExec=obj.vfExec||this.vfExec;this.errstr=obj.errstr||this.errstr;this.flags=typeof obj.flags!=="undefined"?obj.flags:this.flags};Interpreter.true=Buffer.from([1]);Interpreter.false=Buffer.from([]);Interpreter.MAX_SCRIPT_ELEMENT_SIZE=520;Interpreter.LOCKTIME_THRESHOLD=5e8;Interpreter.LOCKTIME_THRESHOLD_BN=new BN(Interpreter.LOCKTIME_THRESHOLD);Interpreter.SCRIPT_VERIFY_NONE=0;Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_WITNESS_PROGRAM=1<<12;Interpreter.SCRIPT_VERIFY_P2SH=1<<0;Interpreter.SCRIPT_VERIFY_STRICTENC=1<<1;Interpreter.SCRIPT_VERIFY_DERSIG=1<<2;Interpreter.SCRIPT_VERIFY_LOW_S=1<<3;Interpreter.SCRIPT_VERIFY_NULLDUMMY=1<<4;Interpreter.SCRIPT_VERIFY_SIGPUSHONLY=1<<5;Interpreter.SCRIPT_VERIFY_MINIMALDATA=1<<6;Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS=1<<7;Interpreter.SCRIPT_VERIFY_CLEANSTACK=1<<8,Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY=1<<9;Interpreter.SCRIPT_VERIFY_WITNESS=1<<10;Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS=1<<11;Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY=1<<10;Interpreter.SCRIPT_VERIFY_MINIMALIF=1<<13;Interpreter.SCRIPT_VERIFY_NULLFAIL=1<<14;Interpreter.SCRIPT_VERIFY_WITNESS_PUBKEYTYPE=1<<15;Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID=1<<16;Interpreter.SCRIPT_ENABLE_REPLAY_PROTECTION=1<<17;Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES=1<<18;Interpreter.SEQUENCE_LOCKTIME_DISABLE_FLAG=1<<31;Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG=1<<22;Interpreter.SEQUENCE_LOCKTIME_MASK=65535;Interpreter.castToBool=function(buf){for(var i=0;i1e4){this.errstr="SCRIPT_ERR_SCRIPT_SIZE";return false}try{while(this.pc1e3){this.errstr="SCRIPT_ERR_STACK_SIZE";return false}}catch(e){this.errstr="SCRIPT_ERR_UNKNOWN_ERROR: "+e;return false}if(this.vfExec.length>0){this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL";return false}return true};Interpreter.prototype.checkLockTime=function(nLockTime){if(!(this.tx.nLockTime=Interpreter.LOCKTIME_THRESHOLD&&nLockTime.gte(Interpreter.LOCKTIME_THRESHOLD_BN))){return false}if(nLockTime.gt(new BN(this.tx.nLockTime))){return false}if(!this.tx.inputs[this.nin].isFinal()){return false}return true};Interpreter.prototype.checkSequence=function(nSequence){var txToSequence=this.tx.inputs[this.nin].sequenceNumber;if(this.tx.version<2){return false}if(txToSequence&SEQUENCE_LOCKTIME_DISABLE_FLAG){return false}var nLockTimeMask=Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG|Interpreter.SEQUENCE_LOCKTIME_MASK;var txToSequenceMasked=new BN(txToSequence&nLockTimeMask);var nSequenceMasked=nSequence.and(nLockTimeMask);var SEQUENCE_LOCKTIME_TYPE_FLAG_BN=new BN(Interpreter.SEQUENCE_LOCKTIME_TYPE_FLAG);if(!(txToSequenceMasked.lt(SEQUENCE_LOCKTIME_TYPE_FLAG_BN)&&nSequenceMasked.lt(SEQUENCE_LOCKTIME_TYPE_FLAG_BN)||txToSequenceMasked.gte(SEQUENCE_LOCKTIME_TYPE_FLAG_BN)&&nSequenceMasked.gte(SEQUENCE_LOCKTIME_TYPE_FLAG_BN))){return false}if(nSequenceMasked.gt(txToSequenceMasked)){return false}return true};Interpreter.prototype.step=function(){var fRequireMinimal=(this.flags&Interpreter.SCRIPT_VERIFY_MINIMALDATA)!==0;var fExec=this.vfExec.indexOf(false)===-1;var buf,buf1,buf2,spliced,n,x1,x2,bn,bn1,bn2,bufSig,bufPubkey,subscript;var sig,pubkey;var fValue,fSuccess;var chunk=this.script.chunks[this.pc];this.pc++;var opcodenum=chunk.opcodenum;if(_.isUndefined(opcodenum)){this.errstr="SCRIPT_ERR_UNDEFINED_OPCODE";return false}if(chunk.buf&&chunk.buf.length>Interpreter.MAX_SCRIPT_ELEMENT_SIZE){this.errstr="SCRIPT_ERR_PUSH_SIZE";return false}if(opcodenum>Opcode.OP_16&&++this.nOpCount>201){this.errstr="SCRIPT_ERR_OP_COUNT";return false}if(opcodenum===Opcode.OP_CAT||opcodenum===Opcode.OP_SUBSTR||opcodenum===Opcode.OP_LEFT||opcodenum===Opcode.OP_RIGHT||opcodenum===Opcode.OP_INVERT||opcodenum===Opcode.OP_AND||opcodenum===Opcode.OP_OR||opcodenum===Opcode.OP_XOR||opcodenum===Opcode.OP_2MUL||opcodenum===Opcode.OP_2DIV||opcodenum===Opcode.OP_MUL||opcodenum===Opcode.OP_DIV||opcodenum===Opcode.OP_MOD||opcodenum===Opcode.OP_LSHIFT||opcodenum===Opcode.OP_RSHIFT){this.errstr="SCRIPT_ERR_DISABLED_OPCODE";return false}if(fExec&&0<=opcodenum&&opcodenum<=Opcode.OP_PUSHDATA4){if(fRequireMinimal&&!this.script.checkMinimalPush(this.pc-1)){this.errstr="SCRIPT_ERR_MINIMALDATA";return false}if(!chunk.buf){this.stack.push(Interpreter.false)}else if(chunk.len!==chunk.buf.length){throw new Error("Length of push value not equal to length of data")}else{this.stack.push(chunk.buf)}}else if(fExec||Opcode.OP_IF<=opcodenum&&opcodenum<=Opcode.OP_ENDIF){switch(opcodenum){case Opcode.OP_1NEGATE:case Opcode.OP_1:case Opcode.OP_2:case Opcode.OP_3:case Opcode.OP_4:case Opcode.OP_5:case Opcode.OP_6:case Opcode.OP_7:case Opcode.OP_8:case Opcode.OP_9:case Opcode.OP_10:case Opcode.OP_11:case Opcode.OP_12:case Opcode.OP_13:case Opcode.OP_14:case Opcode.OP_15:case Opcode.OP_16:{n=opcodenum-(Opcode.OP_1-1);buf=new BN(n).toScriptNumBuffer();this.stack.push(buf)}break;case Opcode.OP_NOP:break;case Opcode.OP_NOP2:case Opcode.OP_CHECKLOCKTIMEVERIFY:if(!(this.flags&Interpreter.SCRIPT_VERIFY_CHECKLOCKTIMEVERIFY)){if(this.flags&Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS){this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS";return false}break}if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}var nLockTime=BN.fromScriptNumBuffer(this.stack[this.stack.length-1],fRequireMinimal,5);if(nLockTime.lt(new BN(0))){this.errstr="SCRIPT_ERR_NEGATIVE_LOCKTIME";return false}if(!this.checkLockTime(nLockTime)){this.errstr="SCRIPT_ERR_UNSATISFIED_LOCKTIME";return false}break;case Opcode.OP_NOP3:case Opcode.OP_CHECKSEQUENCEVERIFY:if(!(this.flags&Interpreter.SCRIPT_VERIFY_CHECKSEQUENCEVERIFY)){if(this.flags&Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS){this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS";return false}break}if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}var nSequence=BN.fromScriptNumBuffer(this.stack[this.stack.length-1],fRequireMinimal,5);if(nSequence.lt(new BN(0))){this.errstr="SCRIPT_ERR_NEGATIVE_LOCKTIME";return false}if((nSequence&Interpreter.SEQUENCE_LOCKTIME_DISABLE_FLAG)!=0){break}if(!this.checkSequence(nSequence)){this.errstr="SCRIPT_ERR_UNSATISFIED_LOCKTIME";return false}break;case Opcode.OP_NOP1:case Opcode.OP_NOP4:case Opcode.OP_NOP5:case Opcode.OP_NOP6:case Opcode.OP_NOP7:case Opcode.OP_NOP8:case Opcode.OP_NOP9:case Opcode.OP_NOP10:{if(this.flags&Interpreter.SCRIPT_VERIFY_DISCOURAGE_UPGRADABLE_NOPS){this.errstr="SCRIPT_ERR_DISCOURAGE_UPGRADABLE_NOPS";return false}}break;case Opcode.OP_IF:case Opcode.OP_NOTIF:{fValue=false;if(fExec){if(this.stack.length<1){this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL";return false}buf=this.stack[this.stack.length-1];if(this.flags&Interpreter.SCRIPT_VERIFY_MINIMALIF){buf=this.stack[this.stack.length-1];if(buf.length>1){this.errstr="SCRIPT_ERR_MINIMALIF";return false}if(buf.length==1&&buf[0]!=1){this.errstr="SCRIPT_ERR_MINIMALIF";return false}}fValue=Interpreter.castToBool(buf);if(opcodenum===Opcode.OP_NOTIF){fValue=!fValue}this.stack.pop()}this.vfExec.push(fValue)}break;case Opcode.OP_ELSE:{if(this.vfExec.length===0){this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL";return false}this.vfExec[this.vfExec.length-1]=!this.vfExec[this.vfExec.length-1]}break;case Opcode.OP_ENDIF:{if(this.vfExec.length===0){this.errstr="SCRIPT_ERR_UNBALANCED_CONDITIONAL";return false}this.vfExec.pop()}break;case Opcode.OP_VERIFY:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];fValue=Interpreter.castToBool(buf);if(fValue){this.stack.pop()}else{this.errstr="SCRIPT_ERR_VERIFY";return false}}break;case Opcode.OP_RETURN:{this.errstr="SCRIPT_ERR_OP_RETURN";return false}break;case Opcode.OP_TOALTSTACK:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.altstack.push(this.stack.pop())}break;case Opcode.OP_FROMALTSTACK:{if(this.altstack.length<1){this.errstr="SCRIPT_ERR_INVALID_ALTSTACK_OPERATION";return false}this.stack.push(this.altstack.pop())}break;case Opcode.OP_2DROP:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.pop();this.stack.pop()}break;case Opcode.OP_2DUP:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf1=this.stack[this.stack.length-2];buf2=this.stack[this.stack.length-1];this.stack.push(buf1);this.stack.push(buf2)}break;case Opcode.OP_3DUP:{if(this.stack.length<3){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf1=this.stack[this.stack.length-3];buf2=this.stack[this.stack.length-2];var buf3=this.stack[this.stack.length-1];this.stack.push(buf1);this.stack.push(buf2);this.stack.push(buf3)}break;case Opcode.OP_2OVER:{if(this.stack.length<4){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf1=this.stack[this.stack.length-4];buf2=this.stack[this.stack.length-3];this.stack.push(buf1);this.stack.push(buf2)}break;case Opcode.OP_2ROT:{if(this.stack.length<6){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}spliced=this.stack.splice(this.stack.length-6,2);this.stack.push(spliced[0]);this.stack.push(spliced[1])}break;case Opcode.OP_2SWAP:{if(this.stack.length<4){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}spliced=this.stack.splice(this.stack.length-4,2);this.stack.push(spliced[0]);this.stack.push(spliced[1])}break;case Opcode.OP_IFDUP:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];fValue=Interpreter.castToBool(buf);if(fValue){this.stack.push(buf)}}break;case Opcode.OP_DEPTH:{buf=new BN(this.stack.length).toScriptNumBuffer();this.stack.push(buf)}break;case Opcode.OP_DROP:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.pop()}break;case Opcode.OP_DUP:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.push(this.stack[this.stack.length-1])}break;case Opcode.OP_NIP:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.splice(this.stack.length-2,1)}break;case Opcode.OP_OVER:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.push(this.stack[this.stack.length-2])}break;case Opcode.OP_PICK:case Opcode.OP_ROLL:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];bn=BN.fromScriptNumBuffer(buf,fRequireMinimal);n=bn.toNumber();this.stack.pop();if(n<0||n>=this.stack.length){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-n-1];if(opcodenum===Opcode.OP_ROLL){this.stack.splice(this.stack.length-n-1,1)}this.stack.push(buf)}break;case Opcode.OP_ROT:{if(this.stack.length<3){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}x1=this.stack[this.stack.length-3];x2=this.stack[this.stack.length-2];var x3=this.stack[this.stack.length-1];this.stack[this.stack.length-3]=x2;this.stack[this.stack.length-2]=x3;this.stack[this.stack.length-1]=x1}break;case Opcode.OP_SWAP:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}x1=this.stack[this.stack.length-2];x2=this.stack[this.stack.length-1];this.stack[this.stack.length-2]=x2;this.stack[this.stack.length-1]=x1}break;case Opcode.OP_TUCK:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}this.stack.splice(this.stack.length-2,0,this.stack[this.stack.length-1])}break;case Opcode.OP_SIZE:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}bn=new BN(this.stack[this.stack.length-1].length);this.stack.push(bn.toScriptNumBuffer())}break;case Opcode.OP_EQUAL:case Opcode.OP_EQUALVERIFY:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf1=this.stack[this.stack.length-2];buf2=this.stack[this.stack.length-1];var fEqual=buf1.toString("hex")===buf2.toString("hex");this.stack.pop();this.stack.pop();this.stack.push(fEqual?Interpreter.true:Interpreter.false);if(opcodenum===Opcode.OP_EQUALVERIFY){if(fEqual){this.stack.pop()}else{this.errstr="SCRIPT_ERR_EQUALVERIFY";return false}}}break;case Opcode.OP_1ADD:case Opcode.OP_1SUB:case Opcode.OP_NEGATE:case Opcode.OP_ABS:case Opcode.OP_NOT:case Opcode.OP_0NOTEQUAL:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];bn=BN.fromScriptNumBuffer(buf,fRequireMinimal);switch(opcodenum){case Opcode.OP_1ADD:bn=bn.add(BN.One);break;case Opcode.OP_1SUB:bn=bn.sub(BN.One);break;case Opcode.OP_NEGATE:bn=bn.neg();break;case Opcode.OP_ABS:if(bn.cmp(BN.Zero)<0){bn=bn.neg()}break;case Opcode.OP_NOT:bn=new BN((bn.cmp(BN.Zero)===0)+0);break;case Opcode.OP_0NOTEQUAL:bn=new BN((bn.cmp(BN.Zero)!==0)+0);break}this.stack.pop();this.stack.push(bn.toScriptNumBuffer())}break;case Opcode.OP_ADD:case Opcode.OP_SUB:case Opcode.OP_BOOLAND:case Opcode.OP_BOOLOR:case Opcode.OP_NUMEQUAL:case Opcode.OP_NUMEQUALVERIFY:case Opcode.OP_NUMNOTEQUAL:case Opcode.OP_LESSTHAN:case Opcode.OP_GREATERTHAN:case Opcode.OP_LESSTHANOREQUAL:case Opcode.OP_GREATERTHANOREQUAL:case Opcode.OP_MIN:case Opcode.OP_MAX:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}bn1=BN.fromScriptNumBuffer(this.stack[this.stack.length-2],fRequireMinimal);bn2=BN.fromScriptNumBuffer(this.stack[this.stack.length-1],fRequireMinimal);bn=new BN(0);switch(opcodenum){case Opcode.OP_ADD:bn=bn1.add(bn2);break;case Opcode.OP_SUB:bn=bn1.sub(bn2);break;case Opcode.OP_BOOLAND:bn=new BN((bn1.cmp(BN.Zero)!==0&&bn2.cmp(BN.Zero)!==0)+0);break;case Opcode.OP_BOOLOR:bn=new BN((bn1.cmp(BN.Zero)!==0||bn2.cmp(BN.Zero)!==0)+0);break;case Opcode.OP_NUMEQUAL:bn=new BN((bn1.cmp(bn2)===0)+0);break;case Opcode.OP_NUMEQUALVERIFY:bn=new BN((bn1.cmp(bn2)===0)+0);break;case Opcode.OP_NUMNOTEQUAL:bn=new BN((bn1.cmp(bn2)!==0)+0);break;case Opcode.OP_LESSTHAN:bn=new BN((bn1.cmp(bn2)<0)+0);break;case Opcode.OP_GREATERTHAN:bn=new BN((bn1.cmp(bn2)>0)+0);break;case Opcode.OP_LESSTHANOREQUAL:bn=new BN((bn1.cmp(bn2)<=0)+0);break;case Opcode.OP_GREATERTHANOREQUAL:bn=new BN((bn1.cmp(bn2)>=0)+0);break;case Opcode.OP_MIN:bn=bn1.cmp(bn2)<0?bn1:bn2;break;case Opcode.OP_MAX:bn=bn1.cmp(bn2)>0?bn1:bn2;break}this.stack.pop();this.stack.pop();this.stack.push(bn.toScriptNumBuffer());if(opcodenum===Opcode.OP_NUMEQUALVERIFY){if(Interpreter.castToBool(this.stack[this.stack.length-1])){this.stack.pop()}else{this.errstr="SCRIPT_ERR_NUMEQUALVERIFY";return false}}}break;case Opcode.OP_WITHIN:{if(this.stack.length<3){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}bn1=BN.fromScriptNumBuffer(this.stack[this.stack.length-3],fRequireMinimal);bn2=BN.fromScriptNumBuffer(this.stack[this.stack.length-2],fRequireMinimal);var bn3=BN.fromScriptNumBuffer(this.stack[this.stack.length-1],fRequireMinimal);fValue=bn2.cmp(bn1)<=0&&bn1.cmp(bn3)<0;this.stack.pop();this.stack.pop();this.stack.pop();this.stack.push(fValue?Interpreter.true:Interpreter.false)}break;case Opcode.OP_RIPEMD160:case Opcode.OP_SHA1:case Opcode.OP_SHA256:case Opcode.OP_HASH160:case Opcode.OP_HASH256:{if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}buf=this.stack[this.stack.length-1];var bufHash;if(opcodenum===Opcode.OP_RIPEMD160){bufHash=Hash.ripemd160(buf)}else if(opcodenum===Opcode.OP_SHA1){bufHash=Hash.sha1(buf)}else if(opcodenum===Opcode.OP_SHA256){bufHash=Hash.sha256(buf)}else if(opcodenum===Opcode.OP_HASH160){bufHash=Hash.sha256ripemd160(buf)}else if(opcodenum===Opcode.OP_HASH256){bufHash=Hash.sha256sha256(buf)}this.stack.pop();this.stack.push(bufHash)}break;case Opcode.OP_CODESEPARATOR:{this.pbegincodehash=this.pc}break;case Opcode.OP_CHECKSIG:case Opcode.OP_CHECKSIGVERIFY:{if(this.stack.length<2){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}bufSig=this.stack[this.stack.length-2];bufPubkey=this.stack[this.stack.length-1];if(!this.checkSignatureEncoding(bufSig)||!this.checkPubkeyEncoding(bufPubkey)){return false}subscript=(new Script).set({chunks:this.script.chunks.slice(this.pbegincodehash)});var tmpScript=(new Script).add(bufSig);subscript.findAndDelete(tmpScript);try{sig=Signature.fromTxFormat(bufSig);pubkey=PublicKey.fromBuffer(bufPubkey,false);fSuccess=this.tx.verifySignature(sig,pubkey,this.nin,subscript,this.sigversion,this.satoshis)}catch(e){fSuccess=false}if(!fSuccess&&this.flags&Interpreter.SCRIPT_VERIFY_NULLFAIL&&bufSig.length){this.errstr="SCRIPT_ERR_NULLFAIL";return false}this.stack.pop();this.stack.pop();this.stack.push(fSuccess?Interpreter.true:Interpreter.false);if(opcodenum===Opcode.OP_CHECKSIGVERIFY){if(fSuccess){this.stack.pop()}else{this.errstr="SCRIPT_ERR_CHECKSIGVERIFY";return false}}}break;case Opcode.OP_CHECKMULTISIG:case Opcode.OP_CHECKMULTISIGVERIFY:{var i=1;if(this.stack.length20){this.errstr="SCRIPT_ERR_PUBKEY_COUNT";return false}this.nOpCount+=nKeysCount;if(this.nOpCount>201){this.errstr="SCRIPT_ERR_OP_COUNT";return false}var ikey=++i;i+=nKeysCount;var ikey2=nKeysCount+2;if(this.stack.lengthnKeysCount){this.errstr="SCRIPT_ERR_SIG_COUNT";return false}var isig=++i;i+=nSigsCount;if(this.stack.length0){bufSig=this.stack[this.stack.length-isig];bufPubkey=this.stack[this.stack.length-ikey];if(!this.checkSignatureEncoding(bufSig)||!this.checkPubkeyEncoding(bufPubkey)){return false}var fOk;try{sig=Signature.fromTxFormat(bufSig);pubkey=PublicKey.fromBuffer(bufPubkey,false);fOk=this.tx.verifySignature(sig,pubkey,this.nin,subscript,this.sigversion,this.satoshis)}catch(e){fOk=false}if(fOk){isig++;nSigsCount--}ikey++;nKeysCount--;if(nSigsCount>nKeysCount){fSuccess=false}}while(i-- >1){if(!fSuccess&&this.flags&Interpreter.SCRIPT_VERIFY_NULLFAIL&&!ikey2&&this.stack[this.stack.length-1].length){this.errstr="SCRIPT_ERR_NULLFAIL";return false}if(ikey2>0){ikey2--}this.stack.pop()}if(this.stack.length<1){this.errstr="SCRIPT_ERR_INVALID_STACK_OPERATION";return false}if(this.flags&Interpreter.SCRIPT_VERIFY_NULLDUMMY&&this.stack[this.stack.length-1].length){this.errstr="SCRIPT_ERR_SIG_NULLDUMMY";return false}this.stack.pop();this.stack.push(fSuccess?Interpreter.true:Interpreter.false);if(opcodenum===Opcode.OP_CHECKMULTISIGVERIFY){if(fSuccess){this.stack.pop()}else{this.errstr="SCRIPT_ERR_CHECKMULTISIGVERIFY";return false}}}break;default:this.errstr="SCRIPT_ERR_BAD_OPCODE";return false}}return true}}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/bn":6,"../crypto/hash":8,"../crypto/signature":11,"../opcode":24,"../publickey":26,"../transaction":30,"./script":29,buffer:175,lodash:103}],29:[function(require,module,exports){(function(Buffer){(function(){"use strict";var Address=require("../address");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var Hash=require("../crypto/hash");var Opcode=require("../opcode");var PublicKey=require("../publickey");var Signature=require("../crypto/signature");var Networks=require("../networks");var $=require("../util/preconditions");var _=require("lodash");var errors=require("../errors");var buffer=require("buffer");var BufferUtil=require("../util/buffer");var JSUtil=require("../util/js");var Script=function Script(from){if(!(this instanceof Script)){return new Script(from)}this.chunks=[];if(BufferUtil.isBuffer(from)){return Script.fromBuffer(from)}else if(from instanceof Address){return Script.fromAddress(from)}else if(from instanceof Script){return Script.fromBuffer(from.toBuffer())}else if(_.isString(from)){return Script.fromString(from)}else if(_.isObject(from)&&_.isArray(from.chunks)){this.set(from)}};Script.VERIFY_TAPROOT=1<<17;Script.prototype.set=function(obj){$.checkArgument(_.isObject(obj));$.checkArgument(_.isArray(obj.chunks));this.chunks=obj.chunks;return this};Script.fromBuffer=function(buffer){var script=new Script;script.chunks=[];var br=new BufferReader(buffer);while(!br.finished()){try{var opcodenum=br.readUInt8();var len,buf;if(opcodenum>0&&opcodenum0&&opcodenum0){if(asm){str=str+" "+chunk.buf.toString("hex")}else{str=str+" "+chunk.len+" "+"0x"+chunk.buf.toString("hex")}}}return str};Script.prototype.toASM=function(){var str="";for(var i=0;i"};Script.prototype.isPublicKeyHashOut=function(){return!!(this.chunks.length===5&&this.chunks[0].opcodenum===Opcode.OP_DUP&&this.chunks[1].opcodenum===Opcode.OP_HASH160&&this.chunks[2].buf&&this.chunks[2].buf.length===20&&this.chunks[3].opcodenum===Opcode.OP_EQUALVERIFY&&this.chunks[4].opcodenum===Opcode.OP_CHECKSIG)};Script.prototype.isPublicKeyHashIn=function(){if(this.chunks.length===2){var signatureBuf=this.chunks[0].buf;var pubkeyBuf=this.chunks[1].buf;if(signatureBuf&&signatureBuf.length&&signatureBuf[0]===48&&pubkeyBuf&&pubkeyBuf.length){var version=pubkeyBuf[0];if((version===4||version===6||version===7)&&pubkeyBuf.length===65){return true}else if((version===3||version===2)&&pubkeyBuf.length===33){return true}}}return false};Script.prototype.getPublicKey=function(){$.checkState(this.isPublicKeyOut(),"Can't retrieve PublicKey from a non-PK output");return this.chunks[0].buf};Script.prototype.getPublicKeyHash=function(){if(this.isPublicKeyHashOut()){return this.chunks[2].buf}else if(this.isWitnessPublicKeyHashOut()){return this.chunks[1].buf}else{throw new Error("Can't retrieve PublicKeyHash from a non-PKH output")}};Script.prototype.isPublicKeyOut=function(){if(this.chunks.length===2&&this.chunks[0].buf&&this.chunks[0].buf.length&&this.chunks[1].opcodenum===Opcode.OP_CHECKSIG){var pubkeyBuf=this.chunks[0].buf;var version=pubkeyBuf[0];var isVersion=false;if((version===4||version===6||version===7)&&pubkeyBuf.length===65){isVersion=true}else if((version===3||version===2)&&pubkeyBuf.length===33){isVersion=true}if(isVersion){return PublicKey.isValid(pubkeyBuf)}}return false};Script.prototype.isPublicKeyIn=function(){if(this.chunks.length===1){var signatureBuf=this.chunks[0].buf;if(signatureBuf&&signatureBuf.length&&signatureBuf[0]===48){return true}}return false};Script.prototype.isScriptHashOut=function(){var buf=this.toBuffer();return buf.length===23&&buf[0]===Opcode.OP_HASH160&&buf[1]===20&&buf[buf.length-1]===Opcode.OP_EQUAL};Script.prototype.isWitnessScriptHashOut=function(){var buf=this.toBuffer();return buf.length===34&&buf[0]===Opcode.OP_0&&buf[1]===32};Script.prototype.isWitnessPublicKeyHashOut=function(){var buf=this.toBuffer();return buf.length===22&&buf[0]===Opcode.OP_0&&buf[1]===20};Script.prototype.isTaproot=function(){var buf=this.toBuffer();return buf.length===34&&buf[0]===Opcode.OP_1&&buf[1]===32};Script.prototype.isWitnessProgram=function(values){if(!values){values={}}var buf=this.toBuffer();if(buf.length<4||buf.length>42){return false}if(buf[0]!==Opcode.OP_0&&!(buf[0]>=Opcode.OP_1&&buf[0]<=Opcode.OP_16)){return false}if(buf.length===buf[1]+2){values.version=buf[0];values.program=buf.slice(2,buf.length);return true}return false};Script.prototype.isScriptHashIn=function(){if(this.chunks.length<=1){return false}var redeemChunk=this.chunks[this.chunks.length-1];var redeemBuf=redeemChunk.buf;if(!redeemBuf){return false}var redeemScript;try{redeemScript=Script.fromBuffer(redeemBuf)}catch(e){if(e instanceof errors.Script.InvalidBuffer){return false}throw e}var type=redeemScript.classify();return type!==Script.types.UNKNOWN};Script.prototype.isMultisigOut=function(){return this.chunks.length>3&&Opcode.isSmallIntOp(this.chunks[0].opcodenum)&&this.chunks.slice(1,this.chunks.length-2).every(function(obj){return obj.buf&&BufferUtil.isBuffer(obj.buf)})&&Opcode.isSmallIntOp(this.chunks[this.chunks.length-2].opcodenum)&&this.chunks[this.chunks.length-1].opcodenum===Opcode.OP_CHECKMULTISIG};Script.prototype.isMultisigIn=function(){return this.chunks.length>=2&&this.chunks[0].opcodenum===0&&this.chunks.slice(1,this.chunks.length).every(function(obj){return obj.buf&&BufferUtil.isBuffer(obj.buf)&&Signature.isTxDER(obj.buf)})};Script.prototype.isDataOut=function(){return this.chunks.length>=1&&this.chunks[0].opcodenum===Opcode.OP_RETURN&&(this.chunks.length===1||this.chunks.length===2&&this.chunks[1].buf&&this.chunks[1].buf.length<=Script.OP_RETURN_STANDARD_SIZE&&this.chunks[1].length===this.chunks.len)};Script.prototype.getData=function(){if(this.isDataOut()||this.isScriptHashOut()||this.isWitnessScriptHashOut()||this.isWitnessPublicKeyHashOut()||this.isTaproot()){if(_.isUndefined(this.chunks[1])){return Buffer.alloc(0)}else{return Buffer.from(this.chunks[1].buf)}}if(this.isPublicKeyHashOut()){return Buffer.from(this.chunks[2].buf)}throw new Error("Unrecognized script type to get data from")};Script.prototype.isPushOnly=function(){return _.every(this.chunks,function(chunk){return chunk.opcodenum<=Opcode.OP_16})};Script.types={};Script.types.UNKNOWN="Unknown";Script.types.PUBKEY_OUT="Pay to public key";Script.types.PUBKEY_IN="Spend from public key";Script.types.PUBKEYHASH_OUT="Pay to public key hash";Script.types.PUBKEYHASH_IN="Spend from public key hash";Script.types.SCRIPTHASH_OUT="Pay to script hash";Script.types.SCRIPTHASH_IN="Spend from script hash";Script.types.MULTISIG_OUT="Pay to multisig";Script.types.MULTISIG_IN="Spend from multisig";Script.types.DATA_OUT="Data push";Script.OP_RETURN_STANDARD_SIZE=80;Script.prototype.classify=function(){if(this._isInput){return this.classifyInput()}else if(this._isOutput){return this.classifyOutput()}else{var outputType=this.classifyOutput();return outputType!=Script.types.UNKNOWN?outputType:this.classifyInput()}};Script.outputIdentifiers={};Script.outputIdentifiers.PUBKEY_OUT=Script.prototype.isPublicKeyOut;Script.outputIdentifiers.PUBKEYHASH_OUT=Script.prototype.isPublicKeyHashOut;Script.outputIdentifiers.MULTISIG_OUT=Script.prototype.isMultisigOut;Script.outputIdentifiers.SCRIPTHASH_OUT=Script.prototype.isScriptHashOut;Script.outputIdentifiers.DATA_OUT=Script.prototype.isDataOut;Script.prototype.classifyOutput=function(){for(var type in Script.outputIdentifiers){if(Script.outputIdentifiers[type].bind(this)()){return Script.types[type]}}return Script.types.UNKNOWN};Script.inputIdentifiers={};Script.inputIdentifiers.PUBKEY_IN=Script.prototype.isPublicKeyIn;Script.inputIdentifiers.PUBKEYHASH_IN=Script.prototype.isPublicKeyHashIn;Script.inputIdentifiers.MULTISIG_IN=Script.prototype.isMultisigIn;Script.inputIdentifiers.SCRIPTHASH_IN=Script.prototype.isScriptHashIn;Script.prototype.classifyInput=function(){for(var type in Script.inputIdentifiers){if(Script.inputIdentifiers[type].bind(this)()){return Script.types[type]}}return Script.types.UNKNOWN};Script.prototype.isStandard=function(){return this.classify()!==Script.types.UNKNOWN};Script.prototype.prepend=function(obj){this._addByType(obj,true);return this};Script.prototype.equals=function(script){$.checkState(script instanceof Script,"Must provide another script");if(this.chunks.length!==script.chunks.length){return false}var i;for(i=0;i=0&&len=1&&buf[0]<=16){return opcodenum===Opcode.OP_1+(buf[0]-1)}else if(buf.length===1&&buf[0]===129){return opcodenum===Opcode.OP_1NEGATE}else if(buf.length<=75){return opcodenum===buf.length}else if(buf.length<=255){return opcodenum===Opcode.OP_PUSHDATA1}else if(buf.length<=65535){return opcodenum===Opcode.OP_PUSHDATA2}return true};Script.prototype._decodeOP_N=function(opcode){if(opcode===Opcode.OP_0){return 0}else if(opcode>=Opcode.OP_1&&opcode<=Opcode.OP_16){return opcode-(Opcode.OP_1-1)}else{throw new Error("Invalid opcode: "+JSON.stringify(opcode))}};Script.prototype.getSignatureOperationsCount=function(accurate){accurate=_.isUndefined(accurate)?true:accurate;var self=this;var n=0;var lastOpcode=Opcode.OP_INVALIDOPCODE;_.each(self.chunks,function getChunk(chunk){var opcode=chunk.opcodenum;if(opcode==Opcode.OP_CHECKSIG||opcode==Opcode.OP_CHECKSIGVERIFY){n++}else if(opcode==Opcode.OP_CHECKMULTISIG||opcode==Opcode.OP_CHECKMULTISIGVERIFY){if(accurate&&lastOpcode>=Opcode.OP_1&&lastOpcode<=Opcode.OP_16){n+=self._decodeOP_N(lastOpcode)}else{n+=20}}lastOpcode=opcode});return n};module.exports=Script}).call(this)}).call(this,require("buffer").Buffer)},{"../address":1,"../crypto/hash":8,"../crypto/signature":11,"../encoding/bufferreader":15,"../encoding/bufferwriter":16,"../errors":18,"../networks":23,"../opcode":24,"../publickey":26,"../util/buffer":45,"../util/js":46,"../util/preconditions":47,buffer:175,lodash:103}],30:[function(require,module,exports){module.exports=require("./transaction");module.exports.Input=require("./input");module.exports.Output=require("./output");module.exports.UnspentOutput=require("./unspentoutput");module.exports.Signature=require("./signature");module.exports.Sighash=require("./sighash");module.exports.SighashWitness=require("./sighashwitness")},{"./input":31,"./output":37,"./sighash":38,"./sighashwitness":39,"./signature":40,"./transaction":41,"./unspentoutput":42}],31:[function(require,module,exports){module.exports=require("./input");module.exports.PublicKey=require("./publickey");module.exports.PublicKeyHash=require("./publickeyhash");module.exports.MultiSig=require("./multisig.js");module.exports.MultiSigScriptHash=require("./multisigscripthash.js")},{"./input":32,"./multisig.js":33,"./multisigscripthash.js":34,"./publickey":35,"./publickeyhash":36}],32:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var $=require("../../util/preconditions");const errors=require("../../errors");var BufferWriter=require("../../encoding/bufferwriter");var buffer=require("buffer");var BufferUtil=require("../../util/buffer");var JSUtil=require("../../util/js");var Script=require("../../script");var Sighash=require("../sighash");var Output=require("../output");var MAXINT=4294967295;var DEFAULT_SEQNUMBER=MAXINT;var DEFAULT_LOCKTIME_SEQNUMBER=MAXINT-1;var DEFAULT_RBF_SEQNUMBER=MAXINT-2;const SEQUENCE_LOCKTIME_DISABLE_FLAG=Math.pow(2,31);const SEQUENCE_LOCKTIME_TYPE_FLAG=Math.pow(2,22);const SEQUENCE_LOCKTIME_MASK=65535;const SEQUENCE_LOCKTIME_GRANULARITY=512;const SEQUENCE_BLOCKDIFF_LIMIT=Math.pow(2,16)-1;function Input(params){if(!(this instanceof Input)){return new Input(params)}if(params){return this._fromObject(params)}}Input.MAXINT=MAXINT;Input.DEFAULT_SEQNUMBER=DEFAULT_SEQNUMBER;Input.DEFAULT_LOCKTIME_SEQNUMBER=DEFAULT_LOCKTIME_SEQNUMBER;Input.DEFAULT_RBF_SEQNUMBER=DEFAULT_RBF_SEQNUMBER;Input.SEQUENCE_LOCKTIME_TYPE_FLAG=SEQUENCE_LOCKTIME_TYPE_FLAG;Object.defineProperty(Input.prototype,"script",{configurable:false,enumerable:true,get:function(){if(this.isNull()){return null}if(!this._script){this._script=new Script(this._scriptBuffer);this._script._isInput=true}return this._script}});Input.fromObject=function(obj){$.checkArgument(_.isObject(obj));var input=new Input;return input._fromObject(obj)};Input.prototype._fromObject=function(params){var prevTxId;if(_.isString(params.prevTxId)&&JSUtil.isHexa(params.prevTxId)){prevTxId=Buffer.from(params.prevTxId,"hex")}else{prevTxId=params.prevTxId}this.witnesses=[];this.output=params.output?params.output instanceof Output?params.output:new Output(params.output):undefined;this.prevTxId=prevTxId||params.txidbuf;this.outputIndex=_.isUndefined(params.outputIndex)?params.txoutnum:params.outputIndex;this.sequenceNumber=_.isUndefined(params.sequenceNumber)?_.isUndefined(params.seqnum)?DEFAULT_SEQNUMBER:params.seqnum:params.sequenceNumber;if(_.isUndefined(params.script)&&_.isUndefined(params.scriptBuffer)){throw new errors.Transaction.Input.MissingScript}this.setScript(params.scriptBuffer||params.script);return this};Input.prototype.toObject=Input.prototype.toJSON=function toObject(){var obj={prevTxId:this.prevTxId.toString("hex"),outputIndex:this.outputIndex,sequenceNumber:this.sequenceNumber,script:this._scriptBuffer.toString("hex")};if(this.script){obj.scriptString=this.script.toString()}if(this.output){obj.output=this.output.toObject()}return obj};Input.fromBufferReader=function(br){var input=new Input;input.prevTxId=br.readReverse(32);input.outputIndex=br.readUInt32LE();input._scriptBuffer=br.readVarLengthBuffer();input.sequenceNumber=br.readUInt32LE();return input};Input.prototype.toBufferWriter=function(writer){if(!writer){writer=new BufferWriter}writer.writeReverse(this.prevTxId);writer.writeUInt32LE(this.outputIndex);var script=this._scriptBuffer;writer.writeVarintNum(script.length);writer.write(script);writer.writeUInt32LE(this.sequenceNumber);return writer};Input.prototype.setScript=function(script){this._script=null;if(script instanceof Script){this._script=script;this._script._isInput=true;this._scriptBuffer=script.toBuffer()}else if(JSUtil.isHexa(script)){this._scriptBuffer=Buffer.from(script,"hex")}else if(_.isString(script)){this._script=new Script(script);this._script._isInput=true;this._scriptBuffer=this._script.toBuffer()}else if(BufferUtil.isBuffer(script)){this._scriptBuffer=Buffer.from(script)}else{throw new TypeError("Invalid argument type: script")}return this};Input.prototype.getSignatures=function(){throw new errors.AbstractMethodInvoked("Trying to sign unsupported output type (only P2PKH and P2SH multisig inputs are supported)"+" for input: "+JSON.stringify(this))};Input.prototype.getSatoshisBuffer=function(){$.checkState(this.output instanceof Output);$.checkState(this.output._satoshisBN);return(new BufferWriter).writeUInt64LEBN(this.output._satoshisBN).toBuffer()};Input.prototype.isFullySigned=function(){throw new errors.AbstractMethodInvoked("Input#isFullySigned")};Input.prototype.isFinal=function(){return this.sequenceNumber!==Input.MAXINT};Input.prototype.addSignature=function(){throw new errors.AbstractMethodInvoked("Input#addSignature")};Input.prototype.clearSignatures=function(){throw new errors.AbstractMethodInvoked("Input#clearSignatures")};Input.prototype.hasWitnesses=function(){if(this.witnesses&&this.witnesses.length>0){return true}return false};Input.prototype.getWitnesses=function(){return this.witnesses};Input.prototype.setWitnesses=function(witnesses){this.witnesses=witnesses};Input.prototype.isValidSignature=function(transaction,signature,signingMethod){signingMethod=signingMethod||"ecdsa";signature.signature.nhashtype=signature.sigtype;return Sighash.verify(transaction,signature.signature,signature.publicKey,signature.inputIndex,this.output.script,signingMethod)};Input.prototype.isNull=function(){return this.prevTxId.toString("hex")==="0000000000000000000000000000000000000000000000000000000000000000"&&this.outputIndex===4294967295};Input.prototype._estimateSize=function(){return this.toBufferWriter().toBuffer().length};Input.prototype.lockForSeconds=function(seconds){$.checkArgument(_.isNumber(seconds));if(seconds<0||seconds>=SEQUENCE_LOCKTIME_GRANULARITY*SEQUENCE_LOCKTIME_MASK){throw new errors.Transaction.Input.LockTimeRange}seconds=parseInt(Math.floor(seconds/SEQUENCE_LOCKTIME_GRANULARITY));this.sequenceNumber=seconds|SEQUENCE_LOCKTIME_TYPE_FLAG;return this};Input.prototype.lockUntilBlockHeight=function(heightDiff){$.checkArgument(_.isNumber(heightDiff));if(heightDiff<0||heightDiff>=SEQUENCE_BLOCKDIFF_LIMIT){throw new errors.Transaction.Input.BlockHeightOutOfRange}this.sequenceNumber=heightDiff;return this};Input.prototype.getLockTime=function(){if(this.sequenceNumber&SEQUENCE_LOCKTIME_DISABLE_FLAG){return null}if(this.sequenceNumber&SEQUENCE_LOCKTIME_TYPE_FLAG){var seconds=SEQUENCE_LOCKTIME_GRANULARITY*(this.sequenceNumber&SEQUENCE_LOCKTIME_MASK);return seconds}else{var blockHeight=this.sequenceNumber&SEQUENCE_LOCKTIME_MASK;return blockHeight}};module.exports=Input}).call(this)}).call(this,require("buffer").Buffer)},{"../../encoding/bufferwriter":16,"../../errors":18,"../../script":27,"../../util/buffer":45,"../../util/js":46,"../../util/preconditions":47,"../output":37,"../sighash":38,buffer:175,lodash:103}],33:[function(require,module,exports){"use strict";var _=require("lodash");var inherits=require("inherits");var Transaction=require("../transaction");var Input=require("./input");var Output=require("../output");var $=require("../../util/preconditions");var Script=require("../../script");var Signature=require("../../crypto/signature");var Sighash=require("../sighash");var PublicKey=require("../../publickey");var BufferUtil=require("../../util/buffer");var TransactionSignature=require("../signature");function MultiSigInput(input,pubkeys,threshold,signatures,opts){opts=opts||{};Input.apply(this,arguments);var self=this;pubkeys=pubkeys||input.publicKeys;threshold=threshold||input.threshold;signatures=signatures||input.signatures;if(opts.noSorting){this.publicKeys=pubkeys}else{this.publicKeys=_.sortBy(pubkeys,function(publicKey){return publicKey.toString("hex")})}$.checkState(Script.buildMultisigOut(this.publicKeys,threshold).equals(this.output.script),"Provided public keys don't match to the provided output script");this.publicKeyIndex={};_.each(this.publicKeys,function(publicKey,index){self.publicKeyIndex[publicKey.toString()]=index});this.threshold=threshold;this.signatures=signatures?this._deserializeSignatures(signatures):new Array(this.publicKeys.length)}inherits(MultiSigInput,Input);MultiSigInput.prototype.toObject=function(){var obj=Input.prototype.toObject.apply(this,arguments);obj.threshold=this.threshold;obj.publicKeys=_.map(this.publicKeys,function(publicKey){return publicKey.toString()});obj.signatures=this._serializeSignatures();return obj};MultiSigInput.prototype._deserializeSignatures=function(signatures){return _.map(signatures,function(signature){if(!signature){return undefined}return new TransactionSignature(signature)})};MultiSigInput.prototype._serializeSignatures=function(){return _.map(this.signatures,function(signature){if(!signature){return undefined}return signature.toObject()})};MultiSigInput.prototype.getSignatures=function(transaction,privateKey,index,sigtype,hashData,signingMethod){$.checkState(this.output instanceof Output);sigtype=sigtype||Signature.SIGHASH_ALL;signingMethod=signingMethod||"ecdsa";var self=this;var results=[];_.each(this.publicKeys,function(publicKey){if(publicKey.toString()===privateKey.publicKey.toString()){results.push(new TransactionSignature({publicKey:privateKey.publicKey,prevTxId:self.prevTxId,outputIndex:self.outputIndex,inputIndex:index,signature:Sighash.sign(transaction,privateKey,sigtype,index,self.output.script,signingMethod),sigtype:sigtype}))}});return results};MultiSigInput.prototype.addSignature=function(transaction,signature,signingMethod){$.checkState(!this.isFullySigned(),"All needed signatures have already been added");$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()],"Signature Undefined"),"Signature has no matching public key");$.checkState(this.isValidSignature(transaction,signature,signingMethod),"Invalid Signature");this.signatures[this.publicKeyIndex[signature.publicKey.toString()]]=signature;this._updateScript();return this};MultiSigInput.prototype._updateScript=function(){this.setScript(Script.buildMultisigIn(this.publicKeys,this.threshold,this._createSignatures()));return this};MultiSigInput.prototype._createSignatures=function(){return _.map(_.filter(this.signatures,function(signature){return!_.isUndefined(signature)}),function(signature){return BufferUtil.concat([signature.signature.toDER(),BufferUtil.integerAsSingleByteBuffer(signature.sigtype)])})};MultiSigInput.prototype.clearSignatures=function(){this.signatures=new Array(this.publicKeys.length);this._updateScript()};MultiSigInput.prototype.isFullySigned=function(){return this.countSignatures()===this.threshold};MultiSigInput.prototype.countMissingSignatures=function(){return this.threshold-this.countSignatures()};MultiSigInput.prototype.countSignatures=function(){return _.reduce(this.signatures,function(sum,signature){return sum+!!signature},0)};MultiSigInput.prototype.publicKeysWithoutSignature=function(){var self=this;return _.filter(this.publicKeys,function(publicKey){return!self.signatures[self.publicKeyIndex[publicKey.toString()]]})};MultiSigInput.prototype.isValidSignature=function(transaction,signature,signingMethod){signature.signature.nhashtype=signature.sigtype;return Sighash.verify(transaction,signature.signature,signature.publicKey,signature.inputIndex,this.output.script,signingMethod)};MultiSigInput.normalizeSignatures=function(transaction,input,inputIndex,signatures,publicKeys,signingMethod){return publicKeys.map(function(pubKey){var signatureMatch=null;signatures=signatures.filter(function(signatureBuffer){if(signatureMatch){return true}var signature=new TransactionSignature({signature:Signature.fromTxFormat(signatureBuffer),publicKey:pubKey,prevTxId:input.prevTxId,outputIndex:input.outputIndex,inputIndex:inputIndex,sigtype:Signature.SIGHASH_ALL});signature.signature.nhashtype=signature.sigtype;var isMatch=Sighash.verify(transaction,signature.signature,signature.publicKey,signature.inputIndex,input.output.script,signingMethod);if(isMatch){signatureMatch=signature;return false}return true});return signatureMatch?signatureMatch:null})};MultiSigInput.OPCODES_SIZE=1;MultiSigInput.SIGNATURE_SIZE=73;MultiSigInput.prototype._estimateSize=function(){return MultiSigInput.OPCODES_SIZE+this.threshold*MultiSigInput.SIGNATURE_SIZE};module.exports=MultiSigInput},{"../../crypto/signature":11,"../../publickey":26,"../../script":27,"../../util/buffer":45,"../../util/preconditions":47,"../output":37,"../sighash":38,"../signature":40,"../transaction":41,"./input":32,inherits:101,lodash:103}],34:[function(require,module,exports){(function(Buffer){(function(){"use strict";var _=require("lodash");var inherits=require("inherits");var Input=require("./input");var Output=require("../output");var $=require("../../util/preconditions");var Address=require("../../address");var Script=require("../../script");var Signature=require("../../crypto/signature");var Sighash=require("../sighash");var SighashWitness=require("../sighashwitness");var BufferWriter=require("../../encoding/bufferwriter");var BufferUtil=require("../../util/buffer");var TransactionSignature=require("../signature");function MultiSigScriptHashInput(input,pubkeys,threshold,signatures,opts){opts=opts||{};Input.apply(this,arguments);var self=this;pubkeys=pubkeys||input.publicKeys;threshold=threshold||input.threshold;signatures=signatures||input.signatures;if(opts.noSorting){this.publicKeys=pubkeys}else{this.publicKeys=_.sortBy(pubkeys,function(publicKey){return publicKey.toString("hex")})}this.redeemScript=Script.buildMultisigOut(this.publicKeys,threshold,opts);var nested=Script.buildWitnessMultisigOutFromScript(this.redeemScript);if(nested.equals(this.output.script)){this.nestedWitness=false;this.type=Address.PayToWitnessScriptHash}else if(Script.buildScriptHashOut(nested).equals(this.output.script)){this.nestedWitness=true;this.type=Address.PayToScriptHash}else if(Script.buildScriptHashOut(this.redeemScript).equals(this.output.script)){this.nestedWitness=false;this.type=Address.PayToScriptHash}else{throw new Error("Provided public keys don't hash to the provided output")}if(this.nestedWitness){var scriptSig=new Script;scriptSig.add(nested.toBuffer());this.setScript(scriptSig)}this.publicKeyIndex={};_.each(this.publicKeys,function(publicKey,index){self.publicKeyIndex[publicKey.toString()]=index});this.threshold=threshold;this.signatures=signatures?this._deserializeSignatures(signatures):new Array(this.publicKeys.length)}inherits(MultiSigScriptHashInput,Input);MultiSigScriptHashInput.prototype.toObject=function(){var obj=Input.prototype.toObject.apply(this,arguments);obj.threshold=this.threshold;obj.publicKeys=_.map(this.publicKeys,function(publicKey){return publicKey.toString()});obj.signatures=this._serializeSignatures();return obj};MultiSigScriptHashInput.prototype._deserializeSignatures=function(signatures){return _.map(signatures,function(signature){if(!signature){return undefined}return new TransactionSignature(signature)})};MultiSigScriptHashInput.prototype._serializeSignatures=function(){return _.map(this.signatures,function(signature){if(!signature){return undefined}return signature.toObject()})};MultiSigScriptHashInput.prototype.getScriptCode=function(){var writer=new BufferWriter;if(!this.redeemScript.hasCodeseparators()){var redeemScriptBuffer=this.redeemScript.toBuffer();writer.writeVarintNum(redeemScriptBuffer.length);writer.write(redeemScriptBuffer)}else{throw new Error("@TODO")}return writer.toBuffer()};MultiSigScriptHashInput.prototype.getSighash=function(transaction,privateKey,index,sigtype){var self=this;var hash;if(self.nestedWitness||self.type===Address.PayToWitnessScriptHash){var scriptCode=self.getScriptCode();var satoshisBuffer=self.getSatoshisBuffer();hash=SighashWitness.sighash(transaction,sigtype,index,scriptCode,satoshisBuffer)}else{hash=Sighash.sighash(transaction,sigtype,index,self.redeemScript)}return hash};MultiSigScriptHashInput.prototype.getSignatures=function(transaction,privateKey,index,sigtype,hashData,signingMethod){$.checkState(this.output instanceof Output);sigtype=sigtype||Signature.SIGHASH_ALL;signingMethod=signingMethod||"ecdsa";var self=this;var results=[];_.each(this.publicKeys,function(publicKey){if(publicKey.toString()===privateKey.publicKey.toString()){var signature;if(self.nestedWitness||self.type===Address.PayToWitnessScriptHash){var scriptCode=self.getScriptCode();var satoshisBuffer=self.getSatoshisBuffer();signature=SighashWitness.sign(transaction,privateKey,sigtype,index,scriptCode,satoshisBuffer,signingMethod)}else{signature=Sighash.sign(transaction,privateKey,sigtype,index,self.redeemScript,signingMethod)}results.push(new TransactionSignature({publicKey:privateKey.publicKey,prevTxId:self.prevTxId,outputIndex:self.outputIndex,inputIndex:index,signature:signature,sigtype:sigtype}))}});return results};MultiSigScriptHashInput.prototype.addSignature=function(transaction,signature,signingMethod){$.checkState(!this.isFullySigned(),"All needed signatures have already been added");$.checkArgument(!_.isUndefined(this.publicKeyIndex[signature.publicKey.toString()]),"Signature has no matching public key");$.checkState(this.isValidSignature(transaction,signature,signingMethod),"Invalid Signature!");this.signatures[this.publicKeyIndex[signature.publicKey.toString()]]=signature;this._updateScript();return this};MultiSigScriptHashInput.prototype._updateScript=function(){if(this.nestedWitness||this.type===Address.PayToWitnessScriptHash){var stack=[Buffer.alloc(0)];var signatures=this._createSignatures();for(var i=0;iMAX_SAFE_INTEGER){return"transaction txout satoshis greater than max safe integer"}if(this._satoshis!==this._satoshisBN.toNumber()){return"transaction txout satoshis has corrupted value"}if(this._satoshis<0){return"transaction txout negative"}return false};Output.prototype.toObject=Output.prototype.toJSON=function toObject(){var obj={satoshis:this.satoshis};obj.script=this._scriptBuffer.toString("hex");return obj};Output.fromObject=function(data){return new Output(data)};Output.prototype.setScriptFromBuffer=function(buffer){this._scriptBuffer=buffer;try{this._script=Script.fromBuffer(this._scriptBuffer);this._script._isOutput=true}catch(e){if(e instanceof errors.Script.InvalidBuffer){this._script=null}else{throw e}}};Output.prototype.setScript=function(script){if(script instanceof Script){this._scriptBuffer=script.toBuffer();this._script=script;this._script._isOutput=true}else if(_.isString(script)){this._script=Script.fromString(script);this._scriptBuffer=this._script.toBuffer();this._script._isOutput=true}else if(bufferUtil.isBuffer(script)){this.setScriptFromBuffer(script)}else{throw new TypeError("Invalid argument type: script")}return this};Output.prototype.inspect=function(){var scriptStr;if(this.script){scriptStr=this.script.inspect()}else{scriptStr=this._scriptBuffer.toString("hex")}return""};Output.fromBufferReader=function(br){var obj={};obj.satoshis=br.readUInt64LEBN();var size=br.readVarintNum();if(size!==0){obj.script=br.read(size)}else{obj.script=Buffer.from([])}return new Output(obj)};Output.prototype.toBufferWriter=function(writer){if(!writer){writer=new BufferWriter}writer.writeUInt64LEBN(this._satoshisBN);var script=this._scriptBuffer;writer.writeVarintNum(script.length);writer.write(script);return writer};module.exports=Output}).call(this)}).call(this,require("buffer").Buffer)},{"../crypto/bn":6,"../encoding/bufferwriter":16,"../errors":18,"../script":27,"../util/buffer":45,"../util/js":46,"../util/preconditions":47,buffer:175,lodash:103}],38:[function(require,module,exports){(function(Buffer){(function(){"use strict";var Signature=require("../crypto/signature");var Script=require("../script");var Output=require("./output");var BufferReader=require("../encoding/bufferreader");var BufferWriter=require("../encoding/bufferwriter");var BN=require("../crypto/bn");var Hash=require("../crypto/hash");var ECDSA=require("../crypto/ecdsa");var $=require("../util/preconditions");var _=require("lodash");const schnorr=require("bip-schnorr");var SIGHASH_SINGLE_BUG="0000000000000000000000000000000000000000000000000000000000000001";var BITS_64_ON="ffffffffffffffff";var sighash=function sighash(transaction,sighashType,inputNumber,subscript){var Transaction=require("./transaction");var Input=require("./input");var i;var txcopy=Transaction.shallowCopy(transaction);subscript=new Script(subscript);subscript.removeCodeseparators();for(i=0;i=txcopy.outputs.length){return Buffer.from(SIGHASH_SINGLE_BUG,"hex")}txcopy.outputs.length=inputNumber+1;for(i=0;imaximumFee){if(this._missingChange()){return new errors.Transaction.ChangeAddressMissing("Fee is too large and no change address was provided")}return new errors.Transaction.FeeError.TooLarge("expected less than "+maximumFee+" but got "+unspent)}}if(!opts.disableSmallFees){var minimumFee=Math.ceil(this._estimateFee()/Transaction.FEE_SECURITY_MARGIN);if(unspent"};Transaction.prototype.toBuffer=function(noWitness){var writer=new BufferWriter;return this.toBufferWriter(writer,noWitness).toBuffer()};Transaction.prototype.hasWitnesses=function(){for(var i=0;i=Transaction.NLOCKTIME_BLOCKHEIGHT_LIMIT){throw new errors.Transaction.BlockHeightTooHigh}if(height<0){throw new errors.Transaction.NLockTimeOutOfRange}for(var i=0;ii.prevTxId.toString("hex")===utxo.txId&&i.outputIndex===utxo.outputIndex);indexes.push(index);if(index>=0){this.inputs[index]=this._getInputFrom(utxo,pubkeys,threshold,opts)}}return indexes};Transaction.prototype._selectInputType=function(utxo,pubkeys,threshold){var clazz;utxo=new UnspentOutput(utxo);if(pubkeys&&threshold){if(utxo.script.isMultisigOut()){clazz=MultiSigInput}else if(utxo.script.isScriptHashOut()||utxo.script.isWitnessScriptHashOut()){clazz=MultiSigScriptHashInput}}else if(utxo.script.isPublicKeyHashOut()||utxo.script.isWitnessPublicKeyHashOut()||utxo.script.isScriptHashOut()){clazz=PublicKeyHashInput}else if(utxo.script.isPublicKeyOut()){clazz=PublicKeyInput}else{clazz=Input}return clazz};Transaction.prototype._getInputFrom=function(utxo,pubkeys,threshold,opts){utxo=new UnspentOutput(utxo);const InputClass=this._selectInputType(utxo,pubkeys,threshold);const input={output:new Output({script:utxo.script,satoshis:utxo.satoshis}),prevTxId:utxo.txId,outputIndex:utxo.outputIndex,sequenceNumber:utxo.sequenceNumber,script:Script.empty()};let args=pubkeys&&threshold?[pubkeys,threshold,false,opts]:[];return new InputClass(input,...args)};Transaction.prototype._fromNonP2SH=function(utxo){const input=this._getInputFrom(utxo);this.addInput(input)};Transaction.prototype._fromMultisigUtxo=function(utxo,pubkeys,threshold,opts){$.checkArgument(threshold<=pubkeys.length,"Number of required signatures must be greater than the number of public keys");const input=this._getInputFrom(utxo,pubkeys,threshold,opts);this.addInput(input)};Transaction.prototype.addInput=function(input,outputScript,satoshis){$.checkArgumentType(input,Input,"input");if(!input.output&&(_.isUndefined(outputScript)||_.isUndefined(satoshis))){throw new errors.Transaction.NeedMoreInfo("Need information about the UTXO script and satoshis")}if(!input.output&&outputScript&&!_.isUndefined(satoshis)){outputScript=outputScript instanceof Script?outputScript:new Script(outputScript);$.checkArgumentType(satoshis,"number","satoshis");input.output=new Output({script:outputScript,satoshis:satoshis})}return this.uncheckedAddInput(input)};Transaction.prototype.uncheckedAddInput=function(input){$.checkArgumentType(input,Input,"input");this.inputs.push(input);this._inputAmount=undefined;this._updateChangeOutput();return this};Transaction.prototype.hasAllUtxoInfo=function(){return _.every(this.inputs.map(function(input){return!!input.output}))};Transaction.prototype.fee=function(amount){$.checkArgument(_.isNumber(amount),"amount must be a number");this._fee=amount;this._updateChangeOutput();return this};Transaction.prototype.feePerKb=function(amount){$.checkArgument(_.isNumber(amount),"amount must be a number");this._feePerKb=amount;this._updateChangeOutput();return this};Transaction.prototype.feePerByte=function(amount){$.checkArgument(_.isNumber(amount),"amount must be a number");this._feePerByte=amount;this._updateChangeOutput();return this};Transaction.prototype.change=function(address){$.checkArgument(address,"address is required");this._changeScript=Script.fromAddress(address);this._updateChangeOutput();return this};Transaction.prototype.getChangeOutput=function(){if(!_.isUndefined(this._changeIndex)){return this.outputs[this._changeIndex]}return null};Transaction.prototype.to=function(address,amount){if(_.isArray(address)){var self=this;_.each(address,function(to){self.to(to.address,to.satoshis)});return this}$.checkArgument(JSUtil.isNaturalNumber(amount),"Amount is expected to be a positive integer");this.addOutput(new Output({script:Script(new Address(address)),satoshis:amount}));return this};Transaction.prototype.addData=function(value){this.addOutput(new Output({script:Script.buildDataOut(value),satoshis:0}));return this};Transaction.prototype.addOutput=function(output){$.checkArgumentType(output,Output,"output");this._addOutput(output);this._updateChangeOutput();return this};Transaction.prototype.clearOutputs=function(){this.outputs=[];this._clearSignatures();this._outputAmount=undefined;this._changeIndex=undefined;this._updateChangeOutput();return this};Transaction.prototype._addOutput=function(output){this.outputs.push(output);this._outputAmount=undefined};Transaction.prototype._getOutputAmount=function(){if(_.isUndefined(this._outputAmount)){var self=this;this._outputAmount=0;_.each(this.outputs,function(output){self._outputAmount+=output.satoshis})}return this._outputAmount};Transaction.prototype._getInputAmount=function(){if(_.isUndefined(this._inputAmount)){this._inputAmount=_.sumBy(this.inputs,function(input){if(_.isUndefined(input.output)){throw new errors.Transaction.Input.MissingPreviousOutput}return input.output.satoshis})}return this._inputAmount};Transaction.prototype._updateChangeOutput=function(){if(!this._changeScript){return}this._clearSignatures();if(!_.isUndefined(this._changeIndex)){this._removeOutput(this._changeIndex)}var available=this._getUnspentValue();var fee=this.getFee();var changeAmount=available-fee;if(changeAmount>Transaction.DUST_AMOUNT){this._changeIndex=this.outputs.length;this._addOutput(new Output({script:this._changeScript,satoshis:changeAmount}))}else{this._changeIndex=undefined}};Transaction.prototype.getFee=function(){if(this.isCoinbase()){return 0}if(!_.isUndefined(this._fee)){return this._fee}if(!this._changeScript){return this._getUnspentValue()}return this._estimateFee()};Transaction.prototype._estimateFee=function(){var estimatedSize=this._estimateSize();var available=this._getUnspentValue();var feeRate=this._feePerByte||(this._feePerKb||Transaction.FEE_PER_KB)/1e3;function getFee(size){return size*feeRate}var fee=Math.ceil(getFee(estimatedSize));var feeWithChange=Math.ceil(getFee(estimatedSize)+getFee(Transaction.CHANGE_OUTPUT_MAX_SIZE));if(!this._changeScript||available<=feeWithChange){return fee}return feeWithChange};Transaction.prototype._getUnspentValue=function(){return this._getInputAmount()-this._getOutputAmount()};Transaction.prototype._clearSignatures=function(){_.each(this.inputs,function(input){input.clearSignatures()})};Transaction.prototype._estimateSize=function(){var result=Transaction.MAXIMUM_EXTRA_SIZE;_.each(this.inputs,function(input){result+=32+4;result+=input._estimateSize()});_.each(this.outputs,function(output){result+=output.script.toBuffer().length+9});return Math.ceil(result)};Transaction.prototype._removeOutput=function(index){var output=this.outputs[index];this.outputs=_.without(this.outputs,output);this._outputAmount=undefined};Transaction.prototype.removeOutput=function(index){this._removeOutput(index);this._updateChangeOutput()};Transaction.prototype.sort=function(){this.sortInputs(function(inputs){var copy=Array.prototype.concat.apply([],inputs);let i=0;copy.forEach(x=>{x.i=i++});copy.sort(function(first,second){return compare(first.prevTxId,second.prevTxId)||first.outputIndex-second.outputIndex||first.i-second.i});return copy});this.sortOutputs(function(outputs){var copy=Array.prototype.concat.apply([],outputs);let i=0;copy.forEach(x=>{x.i=i++});copy.sort(function(first,second){return first.satoshis-second.satoshis||compare(first.script.toBuffer(),second.script.toBuffer())||first.i-second.i});return copy});return this};Transaction.prototype.shuffleOutputs=function(){return this.sortOutputs(_.shuffle)};Transaction.prototype.sortOutputs=function(sortingFunction){var outs=sortingFunction(this.outputs);return this._newOutputOrder(outs)};Transaction.prototype.sortInputs=function(sortingFunction){this.inputs=sortingFunction(this.inputs);this._clearSignatures();return this};Transaction.prototype._newOutputOrder=function(newOutputs){var isInvalidSorting=this.outputs.length!==newOutputs.length||_.difference(this.outputs,newOutputs).length!==0;if(isInvalidSorting){throw new errors.Transaction.InvalidSorting}if(!_.isUndefined(this._changeIndex)){var changeOutput=this.outputs[this._changeIndex];this._changeIndex=_.findIndex(newOutputs,changeOutput)}this.outputs=newOutputs;return this};Transaction.prototype.removeInput=function(txId,outputIndex){var index;if(!outputIndex&&_.isNumber(txId)){index=txId}else{index=_.findIndex(this.inputs,function(input){return input.prevTxId.toString("hex")===txId&&input.outputIndex===outputIndex})}if(index<0||index>=this.inputs.length){throw new errors.Transaction.InvalidIndex(index,this.inputs.length)}var input=this.inputs[index];this.inputs=_.without(this.inputs,input);this._inputAmount=undefined;this._updateChangeOutput()};Transaction.prototype.sign=function(privateKey,sigtype,signingMethod){$.checkState(this.hasAllUtxoInfo(),"Not all utxo information is available to sign the transaction.");var self=this;if(_.isArray(privateKey)){_.each(privateKey,function(privateKey){self.sign(privateKey,sigtype,signingMethod)});return this}_.each(this.getSignatures(privateKey,sigtype,signingMethod),function(signature){self.applySignature(signature,signingMethod)});return this};Transaction.prototype.getSignatures=function(privKey,sigtype,signingMethod){privKey=new PrivateKey(privKey);sigtype=sigtype||Signature.SIGHASH_ALL;var transaction=this;var results=[];var hashData=Hash.sha256ripemd160(privKey.publicKey.toBuffer());_.each(this.inputs,function forEachInput(input,index){_.each(input.getSignatures(transaction,privKey,index,sigtype,hashData,signingMethod),function(signature){results.push(signature)})});return results};Transaction.prototype.applySignature=function(signature,signingMethod){this.inputs[signature.inputIndex].addSignature(this,signature,signingMethod);return this};Transaction.prototype.isFullySigned=function(){_.each(this.inputs,function(input){if(input.isFullySigned===Input.prototype.isFullySigned){throw new errors.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script."+"This usually happens when creating a transaction from a serialized transaction")}});return _.every(_.map(this.inputs,function(input){return input.isFullySigned()}))};Transaction.prototype.isValidSignature=function(signature,signingMethod){var self=this;if(this.inputs[signature.inputIndex].isValidSignature===Input.prototype.isValidSignature){throw new errors.Transaction.UnableToVerifySignature("Unrecognized script kind, or not enough information to execute script."+"This usually happens when creating a transaction from a serialized transaction")}return this.inputs[signature.inputIndex].isValidSignature(self,signature,signingMethod)};Transaction.prototype.verifySignature=function(sig,pubkey,nin,subscript,sigversion,satoshis,signingMethod){if(_.isUndefined(sigversion)){sigversion=0}if(sigversion===1){var subscriptBuffer=subscript.toBuffer();var scriptCodeWriter=new BufferWriter;scriptCodeWriter.writeVarintNum(subscriptBuffer.length);scriptCodeWriter.write(subscriptBuffer);var satoshisBuffer;if(satoshis){$.checkState(JSUtil.isNaturalNumber(satoshis));satoshisBuffer=(new BufferWriter).writeUInt64LEBN(new BN(satoshis)).toBuffer()}else{satoshisBuffer=this.inputs[nin].getSatoshisBuffer()}var verified=SighashWitness.verify(this,sig,pubkey,nin,scriptCodeWriter.toBuffer(),satoshisBuffer,signingMethod);return verified}return Sighash.verify(this,sig,pubkey,nin,subscript,signingMethod)};Transaction.prototype.verify=function(){if(this.inputs.length===0){return"transaction txins empty"}if(this.outputs.length===0){return"transaction txouts empty"}var valueoutbn=new BN(0);for(var i=0;iMAX_BLOCK_SIZE){return"transaction over the maximum block size"}var txinmap={};for(i=0;i100){return"coinbase transaction script size invalid"}}else{for(i=0;i=Input.MAXINT-1){input.sequenceNumber=Input.DEFAULT_RBF_SEQNUMBER}}return this};Transaction.prototype.setVersion=function(version){$.checkArgument(JSUtil.isNaturalNumber(version)&&version<=CURRENT_VERSION,"Wrong version number");this.version=version;return this};module.exports=Transaction}).call(this)}).call(this,require("buffer").Buffer)},{"../address":1,"../crypto/bn":6,"../crypto/hash":8,"../crypto/signature":11,"../encoding/bufferreader":15,"../encoding/bufferwriter":16,"../errors":18,"../privatekey":25,"../script":27,"../util/buffer":45,"../util/js":46,"../util/preconditions":47,"./input":31,"./output":37,"./sighash":38,"./sighashwitness":39,"./unspentoutput":42,buffer:175,"buffer-compare":65,lodash:103}],42:[function(require,module,exports){"use strict";var _=require("lodash");var $=require("../util/preconditions");var JSUtil=require("../util/js");var Script=require("../script");var Address=require("../address");var Unit=require("../unit");function UnspentOutput(data){if(!(this instanceof UnspentOutput)){return new UnspentOutput(data)}$.checkArgument(_.isObject(data),"Must provide an object from where to extract data");var address=data.address?new Address(data.address):undefined;var txId=data.txid?data.txid:data.txId;if(!txId||!JSUtil.isHexaString(txId)||txId.length>64){throw new Error("Invalid TXID in object",data)}var outputIndex=_.isUndefined(data.vout)?data.outputIndex:data.vout;if(!_.isNumber(outputIndex)){throw new Error("Invalid outputIndex, received "+outputIndex)}$.checkArgument(!_.isUndefined(data.scriptPubKey)||!_.isUndefined(data.script),"Must provide the scriptPubKey for that output!");var script=new Script(data.scriptPubKey||data.script);$.checkArgument(!_.isUndefined(data.amount)||!_.isUndefined(data.satoshis),"Must provide an amount for the output");var amount=!_.isUndefined(data.amount)?new Unit.fromBTC(data.amount).toSatoshis():data.satoshis;$.checkArgument(_.isNumber(amount),"Amount must be a number");JSUtil.defineImmutable(this,{address:address,txId:txId,outputIndex:outputIndex,script:script,satoshis:amount})}UnspentOutput.prototype.inspect=function(){return""};UnspentOutput.prototype.toString=function(){return this.txId+":"+this.outputIndex};UnspentOutput.fromObject=function(data){return new UnspentOutput(data)};UnspentOutput.prototype.toObject=UnspentOutput.prototype.toJSON=function toObject(){return{address:this.address?this.address.toString():undefined,txid:this.txId,vout:this.outputIndex,scriptPubKey:this.script.toBuffer().toString("hex"),amount:Unit.fromSatoshis(this.satoshis).toBTC()}};module.exports=UnspentOutput},{"../address":1,"../script":27,"../unit":43,"../util/js":46,"../util/preconditions":47,lodash:103}],43:[function(require,module,exports){"use strict";var _=require("lodash");var errors=require("./errors");var $=require("./util/preconditions");var UNITS={BTC:[1e8,8],mBTC:[1e5,5],uBTC:[100,2],bits:[100,2],satoshis:[1,0]};function Unit(amount,code){if(!(this instanceof Unit)){return new Unit(amount,code)}if(_.isNumber(code)){if(code<=0){throw new errors.Unit.InvalidRate(code)}amount=amount/code;code=Unit.BTC}this._value=this._from(amount,code);var self=this;var defineAccesor=function(key){Object.defineProperty(self,key,{get:function(){return self.to(key)},enumerable:true})};Object.keys(UNITS).forEach(defineAccesor)}Object.keys(UNITS).forEach(function(key){Unit[key]=key});Unit.fromObject=function fromObject(data){$.checkArgument(_.isObject(data),"Argument is expected to be an object");return new Unit(data.amount,data.code)};Unit.fromBTC=function(amount){return new Unit(amount,Unit.BTC)};Unit.fromMillis=Unit.fromMilis=function(amount){return new Unit(amount,Unit.mBTC)};Unit.fromMicros=Unit.fromBits=function(amount){return new Unit(amount,Unit.bits)};Unit.fromSatoshis=function(amount){return new Unit(amount,Unit.satoshis)};Unit.fromFiat=function(amount,rate){return new Unit(amount,rate)};Unit.prototype._from=function(amount,code){if(!UNITS[code]){throw new errors.Unit.UnknownCode(code)}return parseInt((amount*UNITS[code][0]).toFixed())};Unit.prototype.to=function(code){if(_.isNumber(code)){if(code<=0){throw new errors.Unit.InvalidRate(code)}return parseFloat((this.BTC*code).toFixed(2))}if(!UNITS[code]){throw new errors.Unit.UnknownCode(code)}var value=this._value/UNITS[code][0];return parseFloat(value.toFixed(UNITS[code][1]))};Unit.prototype.toBTC=function(){return this.to(Unit.BTC)};Unit.prototype.toMillis=Unit.prototype.toMilis=function(){return this.to(Unit.mBTC)};Unit.prototype.toMicros=Unit.prototype.toBits=function(){return this.to(Unit.bits)};Unit.prototype.toSatoshis=function(){return this.to(Unit.satoshis)};Unit.prototype.atRate=function(rate){return this.to(rate)};Unit.prototype.toString=function(){return this.satoshis+" satoshis"};Unit.prototype.toObject=Unit.prototype.toJSON=function toObject(){return{amount:this.BTC,code:Unit.BTC}};Unit.prototype.inspect=function(){return""};module.exports=Unit},{"./errors":18,"./util/preconditions":47,lodash:103}],44:[function(require,module,exports){"use strict";var _=require("lodash");var URL=require("url");var Address=require("./address");var Unit=require("./unit");var URI=function(data,knownParams){if(!(this instanceof URI)){return new URI(data,knownParams)}this.extras={};this.knownParams=knownParams||[];this.address=this.network=this.amount=this.message=null;if(typeof data==="string"){var params=URI.parse(data);if(params.amount){params.amount=this._parseAmount(params.amount)}this._fromObject(params)}else if(typeof data==="object"){this._fromObject(data)}else{throw new TypeError("Unrecognized data format.")}};URI.fromString=function fromString(str){if(typeof str!=="string"){throw new TypeError("Expected a string")}return new URI(str)};URI.fromObject=function fromObject(json){return new URI(json)};URI.isValid=function(arg,knownParams){try{new URI(arg,knownParams)}catch(err){return false}return true};URI.parse=function(uri){var info=URL.parse(uri,true);if(info.protocol!=="bitcoin:"){throw new TypeError("Invalid bitcoin URI")}var group=/[^:]*:\/?\/?([^?]*)/.exec(uri);info.query.address=group&&group[1]||undefined;return info.query};URI.Members=["address","amount","message","label","r"];URI.prototype._fromObject=function(obj){if(!Address.isValid(obj.address)){throw new TypeError("Invalid bitcoin address")}this.address=new Address(obj.address);this.network=this.address.network;this.amount=obj.amount;for(var key in obj){if(key==="address"||key==="amount"){continue}if(/^req-/.exec(key)&&this.knownParams.indexOf(key)===-1){throw Error("Unknown required argument "+key)}var destination=URI.Members.indexOf(key)>-1?this:this.extras;destination[key]=obj[key]}};URI.prototype._parseAmount=function(amount){amount=Number(amount);if(isNaN(amount)){throw new TypeError("Invalid amount")}return Unit.fromBTC(amount).toSatoshis()};URI.prototype.toObject=URI.prototype.toJSON=function toObject(){var json={};for(var i=0;i"};module.exports=URI},{"./address":1,"./unit":43,lodash:103,url:303}],45:[function(require,module,exports){(function(Buffer){(function(){"use strict";var buffer=require("buffer");var assert=require("assert");var js=require("./js");var $=require("./preconditions");function equals(a,b){if(a.length!==b.length){return false}var length=a.length;for(var i=0;i>24&255);bytes.push(integer>>16&255);bytes.push(integer>>8&255);bytes.push(integer&255);return Buffer.from(bytes)},integerFromBuffer:function integerFromBuffer(buffer){$.checkArgumentType(buffer,"Buffer","buffer");return buffer[0]<<24|buffer[1]<<16|buffer[2]<<8|buffer[3]},integerFromSingleByteBuffer:function integerFromBuffer(buffer){$.checkArgumentType(buffer,"Buffer","buffer");return buffer[0]},bufferToHex:function bufferToHex(buffer){$.checkArgumentType(buffer,"Buffer","buffer");return buffer.toString("hex")},reverse:function reverse(param){return Buffer.from(param).reverse()}};module.exports.NULL_HASH=module.exports.fill(Buffer.alloc(32),0);module.exports.EMPTY_BUFFER=Buffer.alloc(0)}).call(this)}).call(this,require("buffer").Buffer)},{"./js":46,"./preconditions":47,assert:124,buffer:175}],46:[function(require,module,exports){"use strict";var _=require("lodash");var isHexa=function isHexa(value){if(!_.isString(value)){return false}return/^[0-9a-fA-F]+$/.test(value)};module.exports={isValidJSON:function isValidJSON(arg){var parsed;if(!_.isString(arg)){return false}try{parsed=JSON.parse(arg)}catch(e){return false}if(typeof parsed==="object"){return true}return false},isHexa:isHexa,isHexaString:isHexa,cloneArray:function(array){return[].concat(array)},defineImmutable:function defineImmutable(target,values){Object.keys(values).forEach(function(key){Object.defineProperty(target,key,{configurable:false,enumerable:true,value:values[key]})});return target},isNaturalNumber:function isNaturalNumber(value){return typeof value==="number"&&isFinite(value)&&Math.floor(value)===value&&value>=0}}},{lodash:103}],47:[function(require,module,exports){"use strict";var errors=require("../errors");var _=require("lodash");module.exports={checkState:function(condition,message){if(!condition){throw new errors.InvalidState(message)}},checkArgument:function(condition,argumentName,message,docsPath){if(!condition){throw new errors.InvalidArgument(argumentName,message,docsPath)}},checkArgumentType:function(argument,type,argumentName){argumentName=argumentName||"(unknown name)";if(_.isString(type)){if(type==="Buffer"){var buffer=require("buffer");if(!buffer.Buffer.isBuffer(argument)){throw new errors.InvalidArgumentType(argument,type,argumentName)}}else if(typeof argument!==type){throw new errors.InvalidArgumentType(argument,type,argumentName)}}else{if(!(argument instanceof type)){throw new errors.InvalidArgumentType(argument,type.name,argumentName)}}}}},{"../errors":18,buffer:175,lodash:103}],48:[function(require,module,exports){"use strict";var _Buffer=require("safe-buffer").Buffer;function base(ALPHABET){if(ALPHABET.length>=255){throw new TypeError("Alphabet too long")}var BASE_MAP=new Uint8Array(256);for(var j=0;j>>0;var b58=new Uint8Array(size);while(pbegin!==pend){var carry=source[pbegin];var i=0;for(var it1=size-1;(carry!==0||i>>0;b58[it1]=carry%BASE>>>0;carry=carry/BASE>>>0}if(carry!==0){throw new Error("Non-zero carry")}length=i;pbegin++}var it2=size-length;while(it2!==size&&b58[it2]===0){it2++}var str=LEADER.repeat(zeroes);for(;it2>>0;var b256=new Uint8Array(size);while(source[psz]){var carry=BASE_MAP[source.charCodeAt(psz)];if(carry===255){return}var i=0;for(var it3=size-1;(carry!==0||i>>0;b256[it3]=carry%256>>>0;carry=carry/256>>>0}if(carry!==0){throw new Error("Non-zero carry")}length=i;psz++}if(source[psz]===" "){return}var it4=size-length;while(it4!==size&&b256[it4]===0){it4++}var vch=_Buffer.allocUnsafe(zeroes+(size-it4));vch.fill(0,0,zeroes);var j=zeroes;while(it4!==size){vch[j++]=b256[it4++]}return vch}function decode(string){var buffer=decodeUnsafe(string);if(buffer){return buffer}throw new Error("Non-base"+BASE+" character")}return{encode:encode,decodeUnsafe:decodeUnsafe,decode:decode}}module.exports=base},{"safe-buffer":107}],49:[function(require,module,exports){"use strict";Object.defineProperty(exports,"__esModule",{value:true});exports.bech32m=exports.bech32=void 0;const ALPHABET="qpzry9x8gf2tvdw0s3jn54khce6mua7l";const ALPHABET_MAP={};for(let z=0;z>25;return(pre&33554431)<<5^-(b>>0&1)&996825010^-(b>>1&1)&642813549^-(b>>2&1)&513874426^-(b>>3&1)&1027748829^-(b>>4&1)&705979059}function prefixChk(prefix){let chk=1;for(let i=0;i126)return"Invalid prefix ("+prefix+")";chk=polymodStep(chk)^c>>5}chk=polymodStep(chk);for(let i=0;i=outBits){bits-=outBits;result.push(value>>bits&maxV)}}if(pad){if(bits>0){result.push(value<=inBits)return"Excess padding";if(value<LIMIT)throw new TypeError("Exceeds length limit");prefix=prefix.toLowerCase();let chk=prefixChk(prefix);if(typeof chk==="string")throw new Error(chk);let result=prefix+"1";for(let i=0;i>5!==0)throw new Error("Non 5-bit word");chk=polymodStep(chk)^x;result+=ALPHABET.charAt(x)}for(let i=0;i<6;++i){chk=polymodStep(chk)}chk^=ENCODING_CONST;for(let i=0;i<6;++i){const v=chk>>(5-i)*5&31;result+=ALPHABET.charAt(v)}return result}function __decode(str,LIMIT){LIMIT=LIMIT||90;if(str.length<8)return str+" too short";if(str.length>LIMIT)return"Exceeds length limit";const lowered=str.toLowerCase();const uppered=str.toUpperCase();if(str!==lowered&&str!==uppered)return"Mixed-case string "+str;str=lowered;const split=str.lastIndexOf("1");if(split===-1)return"No separator character for "+str;if(split===0)return"Missing prefix for "+str;const prefix=str.slice(0,split);const wordChars=str.slice(split+1);if(wordChars.length<6)return"Data too short";let chk=prefixChk(prefix);if(typeof chk==="string")return chk;const words=[];for(let i=0;i=wordChars.length)continue;words.push(v)}if(chk!==ENCODING_CONST)return"Invalid checksum for "+str;return{prefix:prefix,words:words}}function decodeUnsafe(str,LIMIT){const res=__decode(str,LIMIT);if(typeof res==="object")return res}function decode(str,LIMIT){const res=__decode(str,LIMIT);if(typeof res==="object")return res;throw new Error(res)}return{decodeUnsafe:decodeUnsafe,decode:decode,encode:encode,toWords:toWords,fromWordsUnsafe:fromWordsUnsafe,fromWords:fromWords}}exports.bech32=getLibraryFromEncoding("bech32");exports.bech32m=getLibraryFromEncoding("bech32m")},{}],50:[function(require,module,exports){function BigInteger(a,b,c){if(!(this instanceof BigInteger))return new BigInteger(a,b,c);if(a!=null){if("number"==typeof a)this.fromNumber(a,b,c);else if(b==null&&"string"!=typeof a)this.fromString(a,256);else this.fromString(a,b)}}var proto=BigInteger.prototype;proto.__bigi=require("../package.json").version;BigInteger.isBigInteger=function(obj,check_ver){return obj&&obj.__bigi&&(!check_ver||obj.__bigi===proto.__bigi)};var dbits;function am1(i,x,w,j,c,n){while(--n>=0){var v=x*this[i++]+w[j]+c;c=Math.floor(v/67108864);w[j++]=v&67108863}return c}function am2(i,x,w,j,c,n){var xl=x&32767,xh=x>>15;while(--n>=0){var l=this[i]&32767;var h=this[i++]>>15;var m=xh*l+h*xl;l=xl*l+((m&32767)<<15)+w[j]+(c&1073741823);c=(l>>>30)+(m>>>15)+xh*h+(c>>>30);w[j++]=l&1073741823}return c}function am3(i,x,w,j,c,n){var xl=x&16383,xh=x>>14;while(--n>=0){var l=this[i]&16383;var h=this[i++]>>14;var m=xh*l+h*xl;l=xl*l+((m&16383)<<14)+w[j]+c;c=(l>>28)+(m>>14)+xh*h;w[j++]=l&268435455}return c}BigInteger.prototype.am=am1;dbits=26;BigInteger.prototype.DB=dbits;BigInteger.prototype.DM=(1<=0;--i)r[i]=this[i];r.t=this.t;r.s=this.s}function bnpFromInt(x){this.t=1;this.s=x<0?-1:0;if(x>0)this[0]=x;else if(x<-1)this[0]=x+DV;else this.t=0}function nbv(i){var r=new BigInteger;r.fromInt(i);return r}function bnpFromString(s,b){var self=this;var k;if(b==16)k=4;else if(b==8)k=3;else if(b==256)k=8;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else{self.fromRadix(s,b);return}self.t=0;self.s=0;var i=s.length,mi=false,sh=0;while(--i>=0){var x=k==8?s[i]&255:intAt(s,i);if(x<0){if(s.charAt(i)=="-")mi=true;continue}mi=false;if(sh==0)self[self.t++]=x;else if(sh+k>self.DB){self[self.t-1]|=(x&(1<>self.DB-sh}else self[self.t-1]|=x<=self.DB)sh-=self.DB}if(k==8&&(s[0]&128)!=0){self.s=-1;if(sh>0)self[self.t-1]|=(1<0&&this[this.t-1]==c)--this.t}function bnToString(b){var self=this;if(self.s<0)return"-"+self.negate().toString(b);var k;if(b==16)k=4;else if(b==8)k=3;else if(b==2)k=1;else if(b==32)k=5;else if(b==4)k=2;else return self.toRadix(b);var km=(1<0){if(p>p)>0){m=true;r=int2char(d)}while(i>=0){if(p>(p+=self.DB-k)}else{d=self[i]>>(p-=k)&km;if(p<=0){p+=self.DB;--i}}if(d>0)m=true;if(m)r+=int2char(d)}}return m?r:"0"}function bnNegate(){var r=new BigInteger;BigInteger.ZERO.subTo(this,r);return r}function bnAbs(){return this.s<0?this.negate():this}function bnCompareTo(a){var r=this.s-a.s;if(r!=0)return r;var i=this.t;r=i-a.t;if(r!=0)return this.s<0?-r:r;while(--i>=0)if((r=this[i]-a[i])!=0)return r;return 0}function nbits(x){var r=1,t;if((t=x>>>16)!=0){x=t;r+=16}if((t=x>>8)!=0){x=t;r+=8}if((t=x>>4)!=0){x=t;r+=4}if((t=x>>2)!=0){x=t;r+=2}if((t=x>>1)!=0){x=t;r+=1}return r}function bnBitLength(){if(this.t<=0)return 0;return this.DB*(this.t-1)+nbits(this[this.t-1]^this.s&this.DM)}function bnByteLength(){return this.bitLength()>>3}function bnpDLShiftTo(n,r){var i;for(i=this.t-1;i>=0;--i)r[i+n]=this[i];for(i=n-1;i>=0;--i)r[i]=0;r.t=this.t+n;r.s=this.s}function bnpDRShiftTo(n,r){for(var i=n;i=0;--i){r[i+ds+1]=self[i]>>cbs|c;c=(self[i]&bm)<=0;--i)r[i]=0;r[ds]=c;r.t=self.t+ds+1;r.s=self.s;r.clamp()}function bnpRShiftTo(n,r){var self=this;r.s=self.s;var ds=Math.floor(n/self.DB);if(ds>=self.t){r.t=0;return}var bs=n%self.DB;var cbs=self.DB-bs;var bm=(1<>bs;for(var i=ds+1;i>bs}if(bs>0)r[self.t-ds-1]|=(self.s&bm)<>=self.DB}if(a.t>=self.DB}c+=self.s}else{c+=self.s;while(i>=self.DB}c-=a.s}r.s=c<0?-1:0;if(c<-1)r[i++]=self.DV+c;else if(c>0)r[i++]=c;r.t=i;r.clamp()}function bnpMultiplyTo(a,r){var x=this.abs(),y=a.abs();var i=x.t;r.t=i+y.t;while(--i>=0)r[i]=0;for(i=0;i=0)r[i]=0;for(i=0;i=x.DV){r[i+x.t]-=x.DV;r[i+x.t+1]=1}}if(r.t>0)r[r.t-1]+=x.am(i,x[i],r,2*i,0,1);r.s=0;r.clamp()}function bnpDivRemTo(m,q,r){var self=this;var pm=m.abs();if(pm.t<=0)return;var pt=self.abs();if(pt.t0){pm.lShiftTo(nsh,y);pt.lShiftTo(nsh,r)}else{pm.copyTo(y);pt.copyTo(r)}var ys=y.t;var y0=y[ys-1];if(y0==0)return;var yt=y0*(1<1?y[ys-2]>>self.F2:0);var d1=self.FV/yt,d2=(1<=0){r[r.t++]=1;r.subTo(t,r)}BigInteger.ONE.dlShiftTo(ys,t);t.subTo(y,y);while(y.t=0){var qd=r[--i]==y0?self.DM:Math.floor(r[i]*d1+(r[i-1]+e)*d2);if((r[i]+=y.am(0,qd,r,j,0,ys))0)r.rShiftTo(nsh,r);if(ts<0)BigInteger.ZERO.subTo(r,r)}function bnMod(a){var r=new BigInteger;this.abs().divRemTo(a,null,r);if(this.s<0&&r.compareTo(BigInteger.ZERO)>0)a.subTo(r,r);return r}function Classic(m){this.m=m}function cConvert(x){if(x.s<0||x.compareTo(this.m)>=0)return x.mod(this.m);else return x}function cRevert(x){return x}function cReduce(x){x.divRemTo(this.m,null,x)}function cMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r)}function cSqrTo(x,r){x.squareTo(r);this.reduce(r)}Classic.prototype.convert=cConvert;Classic.prototype.revert=cRevert;Classic.prototype.reduce=cReduce;Classic.prototype.mulTo=cMulTo;Classic.prototype.sqrTo=cSqrTo;function bnpInvDigit(){if(this.t<1)return 0;var x=this[0];if((x&1)==0)return 0;var y=x&3;y=y*(2-(x&15)*y)&15;y=y*(2-(x&255)*y)&255;y=y*(2-((x&65535)*y&65535))&65535;y=y*(2-x*y%this.DV)%this.DV;return y>0?this.DV-y:-y}function Montgomery(m){this.m=m;this.mp=m.invDigit();this.mpl=this.mp&32767;this.mph=this.mp>>15;this.um=(1<0)this.m.subTo(r,r);return r}function montRevert(x){var r=new BigInteger;x.copyTo(r);this.reduce(r);return r}function montReduce(x){while(x.t<=this.mt2)x[x.t++]=0;for(var i=0;i>15)*this.mpl&this.um)<<15)&x.DM;j=i+this.m.t;x[j]+=this.m.am(0,u0,x,i,0,this.m.t);while(x[j]>=x.DV){x[j]-=x.DV;x[++j]++}}x.clamp();x.drShiftTo(this.m.t,x);if(x.compareTo(this.m)>=0)x.subTo(this.m,x)}function montSqrTo(x,r){x.squareTo(r);this.reduce(r)}function montMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r)}Montgomery.prototype.convert=montConvert;Montgomery.prototype.revert=montRevert;Montgomery.prototype.reduce=montReduce;Montgomery.prototype.mulTo=montMulTo;Montgomery.prototype.sqrTo=montSqrTo;function bnpIsEven(){return(this.t>0?this[0]&1:this.s)==0}function bnpExp(e,z){if(e>4294967295||e<1)return BigInteger.ONE;var r=new BigInteger,r2=new BigInteger,g=z.convert(this),i=nbits(e)-1;g.copyTo(r);while(--i>=0){z.sqrTo(r,r2);if((e&1<0)z.mulTo(r2,g,r);else{var t=r;r=r2;r2=t}}return z.revert(r)}function bnModPowInt(e,m){var z;if(e<256||m.isEven())z=new Classic(m);else z=new Montgomery(m);return this.exp(e,z)}proto.copyTo=bnpCopyTo;proto.fromInt=bnpFromInt;proto.fromString=bnpFromString;proto.clamp=bnpClamp;proto.dlShiftTo=bnpDLShiftTo;proto.drShiftTo=bnpDRShiftTo;proto.lShiftTo=bnpLShiftTo;proto.rShiftTo=bnpRShiftTo;proto.subTo=bnpSubTo;proto.multiplyTo=bnpMultiplyTo;proto.squareTo=bnpSquareTo;proto.divRemTo=bnpDivRemTo;proto.invDigit=bnpInvDigit;proto.isEven=bnpIsEven;proto.exp=bnpExp;proto.toString=bnToString;proto.negate=bnNegate;proto.abs=bnAbs;proto.compareTo=bnCompareTo;proto.bitLength=bnBitLength;proto.byteLength=bnByteLength;proto.mod=bnMod;proto.modPowInt=bnModPowInt;function bnClone(){var r=new BigInteger;this.copyTo(r);return r}function bnIntValue(){if(this.s<0){if(this.t==1)return this[0]-this.DV;else if(this.t==0)return-1}else if(this.t==1)return this[0];else if(this.t==0)return 0;return(this[1]&(1<<32-this.DB)-1)<>24}function bnShortValue(){return this.t==0?this.s:this[0]<<16>>16}function bnpChunkSize(r){return Math.floor(Math.LN2*this.DB/Math.log(r))}function bnSigNum(){if(this.s<0)return-1;else if(this.t<=0||this.t==1&&this[0]<=0)return 0;else return 1}function bnpToRadix(b){if(b==null)b=10;if(this.signum()==0||b<2||b>36)return"0";var cs=this.chunkSize(b);var a=Math.pow(b,cs);var d=nbv(a),y=new BigInteger,z=new BigInteger,r="";this.divRemTo(d,y,z);while(y.signum()>0){r=(a+z.intValue()).toString(b).substr(1)+r;y.divRemTo(d,y,z)}return z.intValue().toString(b)+r}function bnpFromRadix(s,b){var self=this;self.fromInt(0);if(b==null)b=10;var cs=self.chunkSize(b);var d=Math.pow(b,cs),mi=false,j=0,w=0;for(var i=0;i=cs){self.dMultiply(d);self.dAddOffset(w,0);j=0;w=0}}if(j>0){self.dMultiply(Math.pow(b,j));self.dAddOffset(w,0)}if(mi)BigInteger.ZERO.subTo(self,self)}function bnpFromNumber(a,b,c){var self=this;if("number"==typeof b){if(a<2)self.fromInt(1);else{self.fromNumber(a,c);if(!self.testBit(a-1))self.bitwiseTo(BigInteger.ONE.shiftLeft(a-1),op_or,self);if(self.isEven())self.dAddOffset(1,0);while(!self.isProbablePrime(b)){self.dAddOffset(2,0);if(self.bitLength()>a)self.subTo(BigInteger.ONE.shiftLeft(a-1),self)}}}else{var x=new Array,t=a&7;x.length=(a>>3)+1;b.nextBytes(x);if(t>0)x[0]&=(1<0){if(p>p)!=(self.s&self.DM)>>p)r[k++]=d|self.s<=0){if(p<8){d=(self[i]&(1<>(p+=self.DB-8)}else{d=self[i]>>(p-=8)&255;if(p<=0){p+=self.DB;--i}}if((d&128)!=0)d|=-256;if(k===0&&(self.s&128)!=(d&128))++k;if(k>0||d!=self.s)r[k++]=d}}return r}function bnEquals(a){return this.compareTo(a)==0}function bnMin(a){return this.compareTo(a)<0?this:a}function bnMax(a){return this.compareTo(a)>0?this:a}function bnpBitwiseTo(a,op,r){var self=this;var i,f,m=Math.min(a.t,self.t);for(i=0;i>=16;r+=16}if((x&255)==0){x>>=8;r+=8}if((x&15)==0){x>>=4;r+=4}if((x&3)==0){x>>=2;r+=2}if((x&1)==0)++r;return r}function bnGetLowestSetBit(){for(var i=0;i=this.t)return this.s!=0;return(this[j]&1<>=self.DB}if(a.t>=self.DB}c+=self.s}else{c+=self.s;while(i>=self.DB}c+=a.s}r.s=c<0?-1:0;if(c>0)r[i++]=c;else if(c<-1)r[i++]=self.DV+c;r.t=i;r.clamp()}function bnAdd(a){var r=new BigInteger;this.addTo(a,r);return r}function bnSubtract(a){var r=new BigInteger;this.subTo(a,r);return r}function bnMultiply(a){var r=new BigInteger;this.multiplyTo(a,r);return r}function bnSquare(){var r=new BigInteger;this.squareTo(r);return r}function bnDivide(a){var r=new BigInteger;this.divRemTo(a,r,null);return r}function bnRemainder(a){var r=new BigInteger;this.divRemTo(a,null,r);return r}function bnDivideAndRemainder(a){var q=new BigInteger,r=new BigInteger;this.divRemTo(a,q,r);return new Array(q,r)}function bnpDMultiply(n){this[this.t]=this.am(0,n-1,this,0,0,this.t);++this.t;this.clamp()}function bnpDAddOffset(n,w){if(n==0)return;while(this.t<=w)this[this.t++]=0;this[w]+=n;while(this[w]>=this.DV){this[w]-=this.DV;if(++w>=this.t)this[this.t++]=0;++this[w]}}function NullExp(){}function nNop(x){return x}function nMulTo(x,y,r){x.multiplyTo(y,r)}function nSqrTo(x,r){x.squareTo(r)}NullExp.prototype.convert=nNop;NullExp.prototype.revert=nNop;NullExp.prototype.mulTo=nMulTo;NullExp.prototype.sqrTo=nSqrTo;function bnPow(e){return this.exp(e,new NullExp)}function bnpMultiplyLowerTo(a,n,r){var i=Math.min(this.t+a.t,n);r.s=0;r.t=i;while(i>0)r[--i]=0;var j;for(j=r.t-this.t;i=0)r[i]=0;for(i=Math.max(n-this.t,0);i2*this.m.t)return x.mod(this.m);else if(x.compareTo(this.m)<0)return x;else{var r=new BigInteger;x.copyTo(r);this.reduce(r);return r}}function barrettRevert(x){return x}function barrettReduce(x){var self=this;x.drShiftTo(self.m.t-1,self.r2);if(x.t>self.m.t+1){x.t=self.m.t+1;x.clamp()}self.mu.multiplyUpperTo(self.r2,self.m.t+1,self.q3);self.m.multiplyLowerTo(self.q3,self.m.t+1,self.r2);while(x.compareTo(self.r2)<0)x.dAddOffset(1,self.m.t+1);x.subTo(self.r2,x);while(x.compareTo(self.m)>=0)x.subTo(self.m,x)}function barrettSqrTo(x,r){x.squareTo(r);this.reduce(r)}function barrettMulTo(x,y,r){x.multiplyTo(y,r);this.reduce(r)}Barrett.prototype.convert=barrettConvert;Barrett.prototype.revert=barrettRevert;Barrett.prototype.reduce=barrettReduce;Barrett.prototype.mulTo=barrettMulTo;Barrett.prototype.sqrTo=barrettSqrTo;function bnModPow(e,m){var i=e.bitLength(),k,r=nbv(1),z;if(i<=0)return r;else if(i<18)k=1;else if(i<48)k=3;else if(i<144)k=4;else if(i<768)k=5;else k=6;if(i<8)z=new Classic(m);else if(m.isEven())z=new Barrett(m);else z=new Montgomery(m);var g=new Array,n=3,k1=k-1,km=(1<1){var g2=new BigInteger;z.sqrTo(g[1],g2);while(n<=km){g[n]=new BigInteger;z.mulTo(g2,g[n-2],g[n]);n+=2}}var j=e.t-1,w,is1=true,r2=new BigInteger,t;i=nbits(e[j])-1;while(j>=0){if(i>=k1)w=e[j]>>i-k1&km;else{w=(e[j]&(1<0)w|=e[j-1]>>this.DB+i-k1}n=k;while((w&1)==0){w>>=1;--n}if((i-=n)<0){i+=this.DB;--j}if(is1){g[w].copyTo(r);is1=false}else{while(n>1){z.sqrTo(r,r2);z.sqrTo(r2,r);n-=2}if(n>0)z.sqrTo(r,r2);else{t=r;r=r2;r2=t}z.mulTo(r2,g[w],r)}while(j>=0&&(e[j]&1<0){x.rShiftTo(g,x);y.rShiftTo(g,y)}while(x.signum()>0){if((i=x.getLowestSetBit())>0)x.rShiftTo(i,x);if((i=y.getLowestSetBit())>0)y.rShiftTo(i,y);if(x.compareTo(y)>=0){x.subTo(y,x);x.rShiftTo(1,x)}else{y.subTo(x,y);y.rShiftTo(1,y)}}if(g>0)y.lShiftTo(g,y);return y}function bnpModInt(n){if(n<=0)return 0;var d=this.DV%n,r=this.s<0?n-1:0;if(this.t>0)if(d==0)r=this[0]%n;else for(var i=this.t-1;i>=0;--i)r=(d*r+this[i])%n;return r}function bnModInverse(m){var ac=m.isEven();if(this.signum()===0)throw new Error("division by zero");if(this.isEven()&&ac||m.signum()==0)return BigInteger.ZERO;var u=m.clone(),v=this.clone();var a=nbv(1),b=nbv(0),c=nbv(0),d=nbv(1);while(u.signum()!=0){while(u.isEven()){u.rShiftTo(1,u);if(ac){if(!a.isEven()||!b.isEven()){a.addTo(this,a);b.subTo(m,b)}a.rShiftTo(1,a)}else if(!b.isEven())b.subTo(m,b);b.rShiftTo(1,b)}while(v.isEven()){v.rShiftTo(1,v);if(ac){if(!c.isEven()||!d.isEven()){c.addTo(this,c);d.subTo(m,d)}c.rShiftTo(1,c)}else if(!d.isEven())d.subTo(m,d);d.rShiftTo(1,d)}if(u.compareTo(v)>=0){u.subTo(v,u);if(ac)a.subTo(c,a);b.subTo(d,b)}else{v.subTo(u,v);if(ac)c.subTo(a,c);d.subTo(b,d)}}if(v.compareTo(BigInteger.ONE)!=0)return BigInteger.ZERO;while(d.compareTo(m)>=0)d.subTo(m,d);while(d.signum()<0)d.addTo(m,d);return d}var lowprimes=[2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997];var lplim=(1<<26)/lowprimes[lowprimes.length-1];function bnIsProbablePrime(t){var i,x=this.abs();if(x.t==1&&x[0]<=lowprimes[lowprimes.length-1]){for(i=0;i>1;if(t>lowprimes.length)t=lowprimes.length;var a=new BigInteger(null);var j,bases=[];for(var i=0;i0){throw new Error(name+" must be an integer in the range 1..n-1")}}function checkSignatureInput(r,s){if(r.compareTo(p)>=0){throw new Error("r is larger than or equal to field size")}if(s.compareTo(n)>=0){throw new Error("s is larger than or equal to curve order")}}function checkPointExists(pubKeyEven,P){if(P.curve.isInfinity(P)){throw new Error("point is at infinity")}const pEven=P.affineY.isEven();if(pubKeyEven!==pEven){throw new Error("point does not exist")}}function checkAux(aux){if(aux.length!==32){throw new Error("aux must be 32 bytes")}}module.exports={checkSessionParams:checkSessionParams,checkSignParams:checkSignParams,checkVerifyParams:checkVerifyParams,checkBatchVerifyParams:checkBatchVerifyParams,checkRange:checkRange,checkSignatureInput:checkSignatureInput,checkPointExists:checkPointExists,checkPubKeyArr:checkPubKeyArr,checkArray:checkArray,checkNonceArr:checkNonceArr,checkAux:checkAux}},{bigi:52,ecurve:68,"safe-buffer":54}],56:[function(require,module,exports){const BigInteger=require("bigi");const Buffer=require("safe-buffer").Buffer;const sha256=require("js-sha256");function bufferToInt(buffer){return BigInteger.fromBuffer(buffer)}function intToBuffer(bigInteger){return bigInteger.toBuffer(32)}function hash(buffer){return Buffer.from(sha256.create().update(buffer).array())}module.exports={bufferToInt:bufferToInt,intToBuffer:intToBuffer,hash:hash}},{bigi:52,"js-sha256":102,"safe-buffer":54}],57:[function(require,module,exports){const schnorr=require("./schnorr");schnorr.check=require("./check");schnorr.convert=require("./convert");schnorr.math=require("./math");schnorr.muSig=require("./mu-sig");schnorr.taproot=require("./taproot");module.exports=schnorr},{"./check":55,"./convert":56,"./math":58,"./mu-sig":59,"./schnorr":60,"./taproot":61}],58:[function(require,module,exports){const BigInteger=require("bigi");const Buffer=require("safe-buffer").Buffer;const ecurve=require("ecurve");const randomBytes=require("randombytes");const curve=ecurve.getCurveByName("secp256k1");const check=require("./check");const convert=require("./convert");const concat=Buffer.concat;const G=curve.G;const p=curve.p;const n=curve.n;const zero=BigInteger.ZERO;const one=BigInteger.ONE;const two=BigInteger.valueOf(2);const three=BigInteger.valueOf(3);const four=BigInteger.valueOf(4);const seven=BigInteger.valueOf(7);function deterministicGetK0(privateKey,publicKey,message){check.checkSignParams(privateKey,message);const h=taggedHash("BIP0340/nonce",concat([convert.intToBuffer(privateKey),publicKey,message]));const i=convert.bufferToInt(h);return i.mod(n)}function isEven(pubKey){return pubKey.affineY.mod(two).equals(zero)}function getEvenKey(pubKey,privateKey){if(isEven(pubKey)){return privateKey.clone()}return n.subtract(privateKey)}function getE(Rx,Px,m){const hash=taggedHash("BIP0340/challenge",concat([Rx,Px,m]));return convert.bufferToInt(hash).mod(n)}function getR(s,e,P){const sG=G.multiply(s);const eP=P.multiply(e);return sG.add(eP.negate())}function taggedHash(tag,msg){const tagHash=convert.hash(tag);return convert.hash(concat([tagHash,tagHash,Buffer.from(msg)]))}function liftX(Px){const x=convert.bufferToInt(Px);const c=x.pow(three).add(seven).mod(p);const y=c.modPow(p.add(one).divide(four),p);if(c.compareTo(y.modPow(two,p))!==0){throw new Error("c is not equal to y^2")}let P=ecurve.Point.fromAffine(curve,x,y);if(!isEven(P)){P=ecurve.Point.fromAffine(curve,x,p.subtract(y))}check.checkPointExists(true,P);return P}function randomA(){let a=null;for(;;){a=convert.bufferToInt(Buffer.from(randomBytes(32)));try{check.checkRange("a",a);return a}catch(e){}}}module.exports={deterministicGetK0:deterministicGetK0,isEven:isEven,getEvenKey:getEvenKey,getE:getE,getR:getR,taggedHash:taggedHash,liftX:liftX,randomA:randomA}},{"./check":55,"./convert":56,bigi:52,ecurve:68,randombytes:106,"safe-buffer":54}],59:[function(require,module,exports){const Buffer=require("safe-buffer").Buffer;const ecurve=require("ecurve");const curve=ecurve.getCurveByName("secp256k1");const math=require("./math");const check=require("./check");const convert=require("./convert");const concat=Buffer.concat;const G=curve.G;const n=curve.n;const MUSIG_TAG=convert.hash(Buffer.from("MuSig coefficient"));function computeEll(pubKeys){check.checkPubKeyArr(pubKeys);return convert.hash(concat(pubKeys))}function computeCoefficient(ell,idx){const idxBuf=Buffer.alloc(4);idxBuf.writeUInt32LE(idx);const data=concat([MUSIG_TAG,MUSIG_TAG,ell,idxBuf]);return convert.bufferToInt(convert.hash(data)).mod(n)}function pubKeyCombine(pubKeys,pubKeyHash){const ell=pubKeyHash||computeEll(pubKeys);let X=null;for(let i=0;i0)return left;return right};BN.min=function min(left,right){if(left.cmp(right)<0)return left;return right};BN.prototype._init=function init(number,base,endian){if(typeof number==="number"){return this._initNumber(number,base,endian)}if(typeof number==="object"){return this._initArray(number,base,endian)}if(base==="hex"){base=16}assert(base===(base|0)&&base>=2&&base<=36);number=number.toString().replace(/\s+/g,"");var start=0;if(number[0]==="-"){start++}if(base===16){this._parseHex(number,start)}else{this._parseBase(number,base,start)}if(number[0]==="-"){this.negative=1}this.strip();if(endian!=="le")return;this._initArray(this.toArray(),base,endian)};BN.prototype._initNumber=function _initNumber(number,base,endian){if(number<0){this.negative=1;number=-number}if(number<67108864){this.words=[number&67108863];this.length=1}else if(number<4503599627370496){this.words=[number&67108863,number/67108864&67108863];this.length=2}else{assert(number<9007199254740992);this.words=[number&67108863,number/67108864&67108863,1];this.length=3}if(endian!=="le")return;this._initArray(this.toArray(),base,endian)};BN.prototype._initArray=function _initArray(number,base,endian){assert(typeof number.length==="number");if(number.length<=0){this.words=[0];this.length=1;return this}this.length=Math.ceil(number.length/3);this.words=new Array(this.length);for(var i=0;i=0;i-=3){w=number[i]|number[i-1]<<8|number[i-2]<<16;this.words[j]|=w<>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}else if(endian==="le"){for(i=0,j=0;i>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}return this.strip()};function parseHex(str,start,end){var r=0;var len=Math.min(str.length,end);for(var i=start;i=49&&c<=54){r|=c-49+10}else if(c>=17&&c<=22){r|=c-17+10}else{r|=c&15}}return r}BN.prototype._parseHex=function _parseHex(number,start){this.length=Math.ceil((number.length-start)/6);this.words=new Array(this.length);for(var i=0;i=start;i-=6){w=parseHex(number,i,i+6);this.words[j]|=w<>>26-off&4194303;off+=24;if(off>=26){off-=26;j++}}if(i+6!==start){w=parseHex(number,start,i+6);this.words[j]|=w<>>26-off&4194303}this.strip()};function parseBase(str,start,end,mul){var r=0;var len=Math.min(str.length,end);for(var i=start;i=49){r+=c-49+10}else if(c>=17){r+=c-17+10}else{r+=c}}return r}BN.prototype._parseBase=function _parseBase(number,base,start){this.words=[0];this.length=1;for(var limbLen=0,limbPow=1;limbPow<=67108863;limbPow*=base){limbLen++}limbLen--;limbPow=limbPow/base|0;var total=number.length-start;var mod=total%limbLen;var end=Math.min(total,total-mod)+start;var word=0;for(var i=start;i1&&this.words[this.length-1]===0){this.length--}return this._normSign()};BN.prototype._normSign=function _normSign(){if(this.length===1&&this.words[0]===0){this.negative=0}return this};BN.prototype.inspect=function inspect(){return(this.red?""};var zeros=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"];var groupSizes=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5];var groupBases=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];BN.prototype.toString=function toString(base,padding){base=base||10;padding=padding|0||1;var out;if(base===16||base==="hex"){out="";var off=0;var carry=0;for(var i=0;i>>24-off&16777215;if(carry!==0||i!==this.length-1){out=zeros[6-word.length]+word+out}else{out=word+out}off+=2;if(off>=26){off-=26;i--}}if(carry!==0){out=carry.toString(16)+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}if(base===(base|0)&&base>=2&&base<=36){var groupSize=groupSizes[base];var groupBase=groupBases[base];out="";var c=this.clone();c.negative=0;while(!c.isZero()){var r=c.modn(groupBase).toString(base);c=c.idivn(groupBase);if(!c.isZero()){out=zeros[groupSize-r.length]+r+out}else{out=r+out}}if(this.isZero()){out="0"+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}assert(false,"Base should be between 2 and 36")};BN.prototype.toNumber=function toNumber(){var ret=this.words[0];if(this.length===2){ret+=this.words[1]*67108864}else if(this.length===3&&this.words[2]===1){ret+=4503599627370496+this.words[1]*67108864}else if(this.length>2){assert(false,"Number can only safely store up to 53 bits")}return this.negative!==0?-ret:ret};BN.prototype.toJSON=function toJSON(){return this.toString(16)};BN.prototype.toBuffer=function toBuffer(endian,length){assert(typeof Buffer!=="undefined");return this.toArrayLike(Buffer,endian,length)};BN.prototype.toArray=function toArray(endian,length){return this.toArrayLike(Array,endian,length)};BN.prototype.toArrayLike=function toArrayLike(ArrayType,endian,length){var byteLength=this.byteLength();var reqLength=length||Math.max(1,byteLength);assert(byteLength<=reqLength,"byte array longer than desired length");assert(reqLength>0,"Requested array length <= 0");this.strip();var littleEndian=endian==="le";var res=new ArrayType(reqLength);var b,i;var q=this.clone();if(!littleEndian){for(i=0;i=4096){r+=13;t>>>=13}if(t>=64){r+=7;t>>>=7}if(t>=8){r+=4;t>>>=4}if(t>=2){r+=2;t>>>=2}return r+t}}BN.prototype._zeroBits=function _zeroBits(w){if(w===0)return 26;var t=w;var r=0;if((t&8191)===0){r+=13;t>>>=13}if((t&127)===0){r+=7;t>>>=7}if((t&15)===0){r+=4;t>>>=4}if((t&3)===0){r+=2;t>>>=2}if((t&1)===0){r++}return r};BN.prototype.bitLength=function bitLength(){var w=this.words[this.length-1];var hi=this._countBits(w);return(this.length-1)*26+hi};function toBitArray(num){var w=new Array(num.bitLength());for(var bit=0;bit>>wbit}return w}BN.prototype.zeroBits=function zeroBits(){if(this.isZero())return 0;var r=0;for(var i=0;inum.length)return this.clone().ior(num);return num.clone().ior(this)};BN.prototype.uor=function uor(num){if(this.length>num.length)return this.clone().iuor(num);return num.clone().iuor(this)};BN.prototype.iuand=function iuand(num){var b;if(this.length>num.length){b=num}else{b=this}for(var i=0;inum.length)return this.clone().iand(num);return num.clone().iand(this)};BN.prototype.uand=function uand(num){if(this.length>num.length)return this.clone().iuand(num);return num.clone().iuand(this)};BN.prototype.iuxor=function iuxor(num){var a;var b;if(this.length>num.length){a=this;b=num}else{a=num;b=this}for(var i=0;inum.length)return this.clone().ixor(num);return num.clone().ixor(this)};BN.prototype.uxor=function uxor(num){if(this.length>num.length)return this.clone().iuxor(num);return num.clone().iuxor(this)};BN.prototype.inotn=function inotn(width){assert(typeof width==="number"&&width>=0);var bytesNeeded=Math.ceil(width/26)|0;var bitsLeft=width%26;this._expand(bytesNeeded);if(bitsLeft>0){bytesNeeded--}for(var i=0;i0){this.words[i]=~this.words[i]&67108863>>26-bitsLeft}return this.strip()};BN.prototype.notn=function notn(width){return this.clone().inotn(width)};BN.prototype.setn=function setn(bit,val){assert(typeof bit==="number"&&bit>=0);var off=bit/26|0;var wbit=bit%26;this._expand(off+1);if(val){this.words[off]=this.words[off]|1<num.length){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>>26}for(;carry!==0&&i>>26}this.length=a.length;if(carry!==0){this.words[this.length]=carry;this.length++}else if(a!==this){for(;inum.length)return this.clone().iadd(num);return num.clone().iadd(this)};BN.prototype.isub=function isub(num){if(num.negative!==0){num.negative=0;var r=this.iadd(num);num.negative=1;return r._normSign()}else if(this.negative!==0){this.negative=0;this.iadd(num);this.negative=1;return this._normSign()}var cmp=this.cmp(num);if(cmp===0){this.negative=0;this.length=1;this.words[0]=0;return this}var a,b;if(cmp>0){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>26;this.words[i]=r&67108863}for(;carry!==0&&i>26;this.words[i]=r&67108863}if(carry===0&&i>>26;var rword=carry&67108863;var maxJ=Math.min(k,num.length-1);for(var j=Math.max(0,k-self.length+1);j<=maxJ;j++){var i=k-j|0;a=self.words[i]|0;b=num.words[j]|0;r=a*b+rword;ncarry+=r/67108864|0;rword=r&67108863}out.words[k]=rword|0;carry=ncarry|0}if(carry!==0){out.words[k]=carry|0}else{out.length--}return out.strip()}var comb10MulTo=function comb10MulTo(self,num,out){var a=self.words;var b=num.words;var o=out.words;var c=0;var lo;var mid;var hi;var a0=a[0]|0;var al0=a0&8191;var ah0=a0>>>13;var a1=a[1]|0;var al1=a1&8191;var ah1=a1>>>13;var a2=a[2]|0;var al2=a2&8191;var ah2=a2>>>13;var a3=a[3]|0;var al3=a3&8191;var ah3=a3>>>13;var a4=a[4]|0;var al4=a4&8191;var ah4=a4>>>13;var a5=a[5]|0;var al5=a5&8191;var ah5=a5>>>13;var a6=a[6]|0;var al6=a6&8191;var ah6=a6>>>13;var a7=a[7]|0;var al7=a7&8191;var ah7=a7>>>13;var a8=a[8]|0;var al8=a8&8191;var ah8=a8>>>13;var a9=a[9]|0;var al9=a9&8191;var ah9=a9>>>13;var b0=b[0]|0;var bl0=b0&8191;var bh0=b0>>>13;var b1=b[1]|0;var bl1=b1&8191;var bh1=b1>>>13;var b2=b[2]|0;var bl2=b2&8191;var bh2=b2>>>13;var b3=b[3]|0;var bl3=b3&8191;var bh3=b3>>>13;var b4=b[4]|0;var bl4=b4&8191;var bh4=b4>>>13;var b5=b[5]|0;var bl5=b5&8191;var bh5=b5>>>13;var b6=b[6]|0;var bl6=b6&8191;var bh6=b6>>>13;var b7=b[7]|0;var bl7=b7&8191;var bh7=b7>>>13;var b8=b[8]|0;var bl8=b8&8191;var bh8=b8>>>13;var b9=b[9]|0;var bl9=b9&8191;var bh9=b9>>>13;out.negative=self.negative^num.negative;out.length=19;lo=Math.imul(al0,bl0);mid=Math.imul(al0,bh0);mid=mid+Math.imul(ah0,bl0)|0;hi=Math.imul(ah0,bh0);var w0=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w0>>>26)|0;w0&=67108863;lo=Math.imul(al1,bl0);mid=Math.imul(al1,bh0);mid=mid+Math.imul(ah1,bl0)|0;hi=Math.imul(ah1,bh0);lo=lo+Math.imul(al0,bl1)|0;mid=mid+Math.imul(al0,bh1)|0;mid=mid+Math.imul(ah0,bl1)|0;hi=hi+Math.imul(ah0,bh1)|0;var w1=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w1>>>26)|0;w1&=67108863;lo=Math.imul(al2,bl0);mid=Math.imul(al2,bh0);mid=mid+Math.imul(ah2,bl0)|0;hi=Math.imul(ah2,bh0);lo=lo+Math.imul(al1,bl1)|0;mid=mid+Math.imul(al1,bh1)|0;mid=mid+Math.imul(ah1,bl1)|0;hi=hi+Math.imul(ah1,bh1)|0;lo=lo+Math.imul(al0,bl2)|0;mid=mid+Math.imul(al0,bh2)|0;mid=mid+Math.imul(ah0,bl2)|0;hi=hi+Math.imul(ah0,bh2)|0;var w2=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w2>>>26)|0;w2&=67108863;lo=Math.imul(al3,bl0);mid=Math.imul(al3,bh0);mid=mid+Math.imul(ah3,bl0)|0;hi=Math.imul(ah3,bh0);lo=lo+Math.imul(al2,bl1)|0;mid=mid+Math.imul(al2,bh1)|0;mid=mid+Math.imul(ah2,bl1)|0;hi=hi+Math.imul(ah2,bh1)|0;lo=lo+Math.imul(al1,bl2)|0;mid=mid+Math.imul(al1,bh2)|0;mid=mid+Math.imul(ah1,bl2)|0;hi=hi+Math.imul(ah1,bh2)|0;lo=lo+Math.imul(al0,bl3)|0;mid=mid+Math.imul(al0,bh3)|0;mid=mid+Math.imul(ah0,bl3)|0;hi=hi+Math.imul(ah0,bh3)|0;var w3=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w3>>>26)|0;w3&=67108863;lo=Math.imul(al4,bl0);mid=Math.imul(al4,bh0);mid=mid+Math.imul(ah4,bl0)|0;hi=Math.imul(ah4,bh0);lo=lo+Math.imul(al3,bl1)|0;mid=mid+Math.imul(al3,bh1)|0;mid=mid+Math.imul(ah3,bl1)|0;hi=hi+Math.imul(ah3,bh1)|0;lo=lo+Math.imul(al2,bl2)|0;mid=mid+Math.imul(al2,bh2)|0;mid=mid+Math.imul(ah2,bl2)|0;hi=hi+Math.imul(ah2,bh2)|0;lo=lo+Math.imul(al1,bl3)|0;mid=mid+Math.imul(al1,bh3)|0;mid=mid+Math.imul(ah1,bl3)|0;hi=hi+Math.imul(ah1,bh3)|0;lo=lo+Math.imul(al0,bl4)|0;mid=mid+Math.imul(al0,bh4)|0;mid=mid+Math.imul(ah0,bl4)|0;hi=hi+Math.imul(ah0,bh4)|0;var w4=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w4>>>26)|0;w4&=67108863;lo=Math.imul(al5,bl0);mid=Math.imul(al5,bh0);mid=mid+Math.imul(ah5,bl0)|0;hi=Math.imul(ah5,bh0);lo=lo+Math.imul(al4,bl1)|0;mid=mid+Math.imul(al4,bh1)|0;mid=mid+Math.imul(ah4,bl1)|0;hi=hi+Math.imul(ah4,bh1)|0;lo=lo+Math.imul(al3,bl2)|0;mid=mid+Math.imul(al3,bh2)|0;mid=mid+Math.imul(ah3,bl2)|0;hi=hi+Math.imul(ah3,bh2)|0;lo=lo+Math.imul(al2,bl3)|0;mid=mid+Math.imul(al2,bh3)|0;mid=mid+Math.imul(ah2,bl3)|0;hi=hi+Math.imul(ah2,bh3)|0;lo=lo+Math.imul(al1,bl4)|0;mid=mid+Math.imul(al1,bh4)|0;mid=mid+Math.imul(ah1,bl4)|0;hi=hi+Math.imul(ah1,bh4)|0;lo=lo+Math.imul(al0,bl5)|0;mid=mid+Math.imul(al0,bh5)|0;mid=mid+Math.imul(ah0,bl5)|0;hi=hi+Math.imul(ah0,bh5)|0;var w5=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w5>>>26)|0;w5&=67108863;lo=Math.imul(al6,bl0);mid=Math.imul(al6,bh0);mid=mid+Math.imul(ah6,bl0)|0;hi=Math.imul(ah6,bh0);lo=lo+Math.imul(al5,bl1)|0;mid=mid+Math.imul(al5,bh1)|0;mid=mid+Math.imul(ah5,bl1)|0;hi=hi+Math.imul(ah5,bh1)|0;lo=lo+Math.imul(al4,bl2)|0;mid=mid+Math.imul(al4,bh2)|0;mid=mid+Math.imul(ah4,bl2)|0;hi=hi+Math.imul(ah4,bh2)|0;lo=lo+Math.imul(al3,bl3)|0;mid=mid+Math.imul(al3,bh3)|0;mid=mid+Math.imul(ah3,bl3)|0;hi=hi+Math.imul(ah3,bh3)|0;lo=lo+Math.imul(al2,bl4)|0;mid=mid+Math.imul(al2,bh4)|0;mid=mid+Math.imul(ah2,bl4)|0;hi=hi+Math.imul(ah2,bh4)|0;lo=lo+Math.imul(al1,bl5)|0;mid=mid+Math.imul(al1,bh5)|0;mid=mid+Math.imul(ah1,bl5)|0;hi=hi+Math.imul(ah1,bh5)|0;lo=lo+Math.imul(al0,bl6)|0;mid=mid+Math.imul(al0,bh6)|0;mid=mid+Math.imul(ah0,bl6)|0;hi=hi+Math.imul(ah0,bh6)|0;var w6=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w6>>>26)|0;w6&=67108863;lo=Math.imul(al7,bl0);mid=Math.imul(al7,bh0);mid=mid+Math.imul(ah7,bl0)|0;hi=Math.imul(ah7,bh0);lo=lo+Math.imul(al6,bl1)|0;mid=mid+Math.imul(al6,bh1)|0;mid=mid+Math.imul(ah6,bl1)|0;hi=hi+Math.imul(ah6,bh1)|0;lo=lo+Math.imul(al5,bl2)|0;mid=mid+Math.imul(al5,bh2)|0;mid=mid+Math.imul(ah5,bl2)|0;hi=hi+Math.imul(ah5,bh2)|0;lo=lo+Math.imul(al4,bl3)|0;mid=mid+Math.imul(al4,bh3)|0;mid=mid+Math.imul(ah4,bl3)|0;hi=hi+Math.imul(ah4,bh3)|0;lo=lo+Math.imul(al3,bl4)|0;mid=mid+Math.imul(al3,bh4)|0;mid=mid+Math.imul(ah3,bl4)|0;hi=hi+Math.imul(ah3,bh4)|0;lo=lo+Math.imul(al2,bl5)|0;mid=mid+Math.imul(al2,bh5)|0;mid=mid+Math.imul(ah2,bl5)|0;hi=hi+Math.imul(ah2,bh5)|0;lo=lo+Math.imul(al1,bl6)|0;mid=mid+Math.imul(al1,bh6)|0;mid=mid+Math.imul(ah1,bl6)|0;hi=hi+Math.imul(ah1,bh6)|0;lo=lo+Math.imul(al0,bl7)|0;mid=mid+Math.imul(al0,bh7)|0;mid=mid+Math.imul(ah0,bl7)|0;hi=hi+Math.imul(ah0,bh7)|0;var w7=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w7>>>26)|0;w7&=67108863;lo=Math.imul(al8,bl0);mid=Math.imul(al8,bh0);mid=mid+Math.imul(ah8,bl0)|0;hi=Math.imul(ah8,bh0);lo=lo+Math.imul(al7,bl1)|0;mid=mid+Math.imul(al7,bh1)|0;mid=mid+Math.imul(ah7,bl1)|0;hi=hi+Math.imul(ah7,bh1)|0;lo=lo+Math.imul(al6,bl2)|0;mid=mid+Math.imul(al6,bh2)|0;mid=mid+Math.imul(ah6,bl2)|0;hi=hi+Math.imul(ah6,bh2)|0;lo=lo+Math.imul(al5,bl3)|0;mid=mid+Math.imul(al5,bh3)|0;mid=mid+Math.imul(ah5,bl3)|0;hi=hi+Math.imul(ah5,bh3)|0;lo=lo+Math.imul(al4,bl4)|0;mid=mid+Math.imul(al4,bh4)|0;mid=mid+Math.imul(ah4,bl4)|0;hi=hi+Math.imul(ah4,bh4)|0;lo=lo+Math.imul(al3,bl5)|0;mid=mid+Math.imul(al3,bh5)|0;mid=mid+Math.imul(ah3,bl5)|0;hi=hi+Math.imul(ah3,bh5)|0;lo=lo+Math.imul(al2,bl6)|0;mid=mid+Math.imul(al2,bh6)|0;mid=mid+Math.imul(ah2,bl6)|0;hi=hi+Math.imul(ah2,bh6)|0;lo=lo+Math.imul(al1,bl7)|0;mid=mid+Math.imul(al1,bh7)|0;mid=mid+Math.imul(ah1,bl7)|0;hi=hi+Math.imul(ah1,bh7)|0;lo=lo+Math.imul(al0,bl8)|0;mid=mid+Math.imul(al0,bh8)|0;mid=mid+Math.imul(ah0,bl8)|0;hi=hi+Math.imul(ah0,bh8)|0;var w8=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w8>>>26)|0;w8&=67108863;lo=Math.imul(al9,bl0);mid=Math.imul(al9,bh0);mid=mid+Math.imul(ah9,bl0)|0;hi=Math.imul(ah9,bh0);lo=lo+Math.imul(al8,bl1)|0;mid=mid+Math.imul(al8,bh1)|0;mid=mid+Math.imul(ah8,bl1)|0;hi=hi+Math.imul(ah8,bh1)|0;lo=lo+Math.imul(al7,bl2)|0;mid=mid+Math.imul(al7,bh2)|0;mid=mid+Math.imul(ah7,bl2)|0;hi=hi+Math.imul(ah7,bh2)|0;lo=lo+Math.imul(al6,bl3)|0;mid=mid+Math.imul(al6,bh3)|0;mid=mid+Math.imul(ah6,bl3)|0;hi=hi+Math.imul(ah6,bh3)|0;lo=lo+Math.imul(al5,bl4)|0;mid=mid+Math.imul(al5,bh4)|0;mid=mid+Math.imul(ah5,bl4)|0;hi=hi+Math.imul(ah5,bh4)|0;lo=lo+Math.imul(al4,bl5)|0;mid=mid+Math.imul(al4,bh5)|0;mid=mid+Math.imul(ah4,bl5)|0;hi=hi+Math.imul(ah4,bh5)|0;lo=lo+Math.imul(al3,bl6)|0;mid=mid+Math.imul(al3,bh6)|0;mid=mid+Math.imul(ah3,bl6)|0;hi=hi+Math.imul(ah3,bh6)|0;lo=lo+Math.imul(al2,bl7)|0;mid=mid+Math.imul(al2,bh7)|0;mid=mid+Math.imul(ah2,bl7)|0;hi=hi+Math.imul(ah2,bh7)|0;lo=lo+Math.imul(al1,bl8)|0;mid=mid+Math.imul(al1,bh8)|0;mid=mid+Math.imul(ah1,bl8)|0;hi=hi+Math.imul(ah1,bh8)|0;lo=lo+Math.imul(al0,bl9)|0;mid=mid+Math.imul(al0,bh9)|0;mid=mid+Math.imul(ah0,bl9)|0;hi=hi+Math.imul(ah0,bh9)|0;var w9=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w9>>>26)|0;w9&=67108863;lo=Math.imul(al9,bl1);mid=Math.imul(al9,bh1);mid=mid+Math.imul(ah9,bl1)|0;hi=Math.imul(ah9,bh1);lo=lo+Math.imul(al8,bl2)|0;mid=mid+Math.imul(al8,bh2)|0;mid=mid+Math.imul(ah8,bl2)|0;hi=hi+Math.imul(ah8,bh2)|0;lo=lo+Math.imul(al7,bl3)|0;mid=mid+Math.imul(al7,bh3)|0;mid=mid+Math.imul(ah7,bl3)|0;hi=hi+Math.imul(ah7,bh3)|0;lo=lo+Math.imul(al6,bl4)|0;mid=mid+Math.imul(al6,bh4)|0;mid=mid+Math.imul(ah6,bl4)|0;hi=hi+Math.imul(ah6,bh4)|0;lo=lo+Math.imul(al5,bl5)|0;mid=mid+Math.imul(al5,bh5)|0;mid=mid+Math.imul(ah5,bl5)|0;hi=hi+Math.imul(ah5,bh5)|0;lo=lo+Math.imul(al4,bl6)|0;mid=mid+Math.imul(al4,bh6)|0;mid=mid+Math.imul(ah4,bl6)|0;hi=hi+Math.imul(ah4,bh6)|0;lo=lo+Math.imul(al3,bl7)|0;mid=mid+Math.imul(al3,bh7)|0;mid=mid+Math.imul(ah3,bl7)|0;hi=hi+Math.imul(ah3,bh7)|0;lo=lo+Math.imul(al2,bl8)|0;mid=mid+Math.imul(al2,bh8)|0;mid=mid+Math.imul(ah2,bl8)|0;hi=hi+Math.imul(ah2,bh8)|0;lo=lo+Math.imul(al1,bl9)|0;mid=mid+Math.imul(al1,bh9)|0;mid=mid+Math.imul(ah1,bl9)|0;hi=hi+Math.imul(ah1,bh9)|0;var w10=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w10>>>26)|0;w10&=67108863;lo=Math.imul(al9,bl2);mid=Math.imul(al9,bh2);mid=mid+Math.imul(ah9,bl2)|0;hi=Math.imul(ah9,bh2);lo=lo+Math.imul(al8,bl3)|0;mid=mid+Math.imul(al8,bh3)|0;mid=mid+Math.imul(ah8,bl3)|0;hi=hi+Math.imul(ah8,bh3)|0;lo=lo+Math.imul(al7,bl4)|0;mid=mid+Math.imul(al7,bh4)|0;mid=mid+Math.imul(ah7,bl4)|0;hi=hi+Math.imul(ah7,bh4)|0;lo=lo+Math.imul(al6,bl5)|0;mid=mid+Math.imul(al6,bh5)|0;mid=mid+Math.imul(ah6,bl5)|0;hi=hi+Math.imul(ah6,bh5)|0;lo=lo+Math.imul(al5,bl6)|0;mid=mid+Math.imul(al5,bh6)|0;mid=mid+Math.imul(ah5,bl6)|0;hi=hi+Math.imul(ah5,bh6)|0;lo=lo+Math.imul(al4,bl7)|0;mid=mid+Math.imul(al4,bh7)|0;mid=mid+Math.imul(ah4,bl7)|0;hi=hi+Math.imul(ah4,bh7)|0;lo=lo+Math.imul(al3,bl8)|0;mid=mid+Math.imul(al3,bh8)|0;mid=mid+Math.imul(ah3,bl8)|0;hi=hi+Math.imul(ah3,bh8)|0;lo=lo+Math.imul(al2,bl9)|0;mid=mid+Math.imul(al2,bh9)|0;mid=mid+Math.imul(ah2,bl9)|0;hi=hi+Math.imul(ah2,bh9)|0;var w11=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w11>>>26)|0;w11&=67108863;lo=Math.imul(al9,bl3);mid=Math.imul(al9,bh3);mid=mid+Math.imul(ah9,bl3)|0;hi=Math.imul(ah9,bh3);lo=lo+Math.imul(al8,bl4)|0;mid=mid+Math.imul(al8,bh4)|0;mid=mid+Math.imul(ah8,bl4)|0;hi=hi+Math.imul(ah8,bh4)|0;lo=lo+Math.imul(al7,bl5)|0;mid=mid+Math.imul(al7,bh5)|0;mid=mid+Math.imul(ah7,bl5)|0;hi=hi+Math.imul(ah7,bh5)|0;lo=lo+Math.imul(al6,bl6)|0;mid=mid+Math.imul(al6,bh6)|0;mid=mid+Math.imul(ah6,bl6)|0;hi=hi+Math.imul(ah6,bh6)|0;lo=lo+Math.imul(al5,bl7)|0;mid=mid+Math.imul(al5,bh7)|0;mid=mid+Math.imul(ah5,bl7)|0;hi=hi+Math.imul(ah5,bh7)|0;lo=lo+Math.imul(al4,bl8)|0;mid=mid+Math.imul(al4,bh8)|0;mid=mid+Math.imul(ah4,bl8)|0;hi=hi+Math.imul(ah4,bh8)|0;lo=lo+Math.imul(al3,bl9)|0;mid=mid+Math.imul(al3,bh9)|0;mid=mid+Math.imul(ah3,bl9)|0;hi=hi+Math.imul(ah3,bh9)|0;var w12=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w12>>>26)|0;w12&=67108863;lo=Math.imul(al9,bl4);mid=Math.imul(al9,bh4);mid=mid+Math.imul(ah9,bl4)|0;hi=Math.imul(ah9,bh4);lo=lo+Math.imul(al8,bl5)|0;mid=mid+Math.imul(al8,bh5)|0;mid=mid+Math.imul(ah8,bl5)|0;hi=hi+Math.imul(ah8,bh5)|0;lo=lo+Math.imul(al7,bl6)|0;mid=mid+Math.imul(al7,bh6)|0;mid=mid+Math.imul(ah7,bl6)|0;hi=hi+Math.imul(ah7,bh6)|0;lo=lo+Math.imul(al6,bl7)|0;mid=mid+Math.imul(al6,bh7)|0;mid=mid+Math.imul(ah6,bl7)|0;hi=hi+Math.imul(ah6,bh7)|0;lo=lo+Math.imul(al5,bl8)|0;mid=mid+Math.imul(al5,bh8)|0;mid=mid+Math.imul(ah5,bl8)|0;hi=hi+Math.imul(ah5,bh8)|0;lo=lo+Math.imul(al4,bl9)|0;mid=mid+Math.imul(al4,bh9)|0;mid=mid+Math.imul(ah4,bl9)|0;hi=hi+Math.imul(ah4,bh9)|0;var w13=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w13>>>26)|0;w13&=67108863;lo=Math.imul(al9,bl5);mid=Math.imul(al9,bh5);mid=mid+Math.imul(ah9,bl5)|0;hi=Math.imul(ah9,bh5);lo=lo+Math.imul(al8,bl6)|0;mid=mid+Math.imul(al8,bh6)|0;mid=mid+Math.imul(ah8,bl6)|0;hi=hi+Math.imul(ah8,bh6)|0;lo=lo+Math.imul(al7,bl7)|0;mid=mid+Math.imul(al7,bh7)|0;mid=mid+Math.imul(ah7,bl7)|0;hi=hi+Math.imul(ah7,bh7)|0;lo=lo+Math.imul(al6,bl8)|0;mid=mid+Math.imul(al6,bh8)|0;mid=mid+Math.imul(ah6,bl8)|0;hi=hi+Math.imul(ah6,bh8)|0;lo=lo+Math.imul(al5,bl9)|0;mid=mid+Math.imul(al5,bh9)|0;mid=mid+Math.imul(ah5,bl9)|0;hi=hi+Math.imul(ah5,bh9)|0;var w14=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w14>>>26)|0;w14&=67108863;lo=Math.imul(al9,bl6);mid=Math.imul(al9,bh6);mid=mid+Math.imul(ah9,bl6)|0;hi=Math.imul(ah9,bh6);lo=lo+Math.imul(al8,bl7)|0;mid=mid+Math.imul(al8,bh7)|0;mid=mid+Math.imul(ah8,bl7)|0;hi=hi+Math.imul(ah8,bh7)|0;lo=lo+Math.imul(al7,bl8)|0;mid=mid+Math.imul(al7,bh8)|0;mid=mid+Math.imul(ah7,bl8)|0;hi=hi+Math.imul(ah7,bh8)|0;lo=lo+Math.imul(al6,bl9)|0;mid=mid+Math.imul(al6,bh9)|0;mid=mid+Math.imul(ah6,bl9)|0;hi=hi+Math.imul(ah6,bh9)|0;var w15=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w15>>>26)|0;w15&=67108863;lo=Math.imul(al9,bl7);mid=Math.imul(al9,bh7);mid=mid+Math.imul(ah9,bl7)|0;hi=Math.imul(ah9,bh7);lo=lo+Math.imul(al8,bl8)|0;mid=mid+Math.imul(al8,bh8)|0;mid=mid+Math.imul(ah8,bl8)|0;hi=hi+Math.imul(ah8,bh8)|0;lo=lo+Math.imul(al7,bl9)|0;mid=mid+Math.imul(al7,bh9)|0;mid=mid+Math.imul(ah7,bl9)|0;hi=hi+Math.imul(ah7,bh9)|0;var w16=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w16>>>26)|0;w16&=67108863;lo=Math.imul(al9,bl8);mid=Math.imul(al9,bh8);mid=mid+Math.imul(ah9,bl8)|0;hi=Math.imul(ah9,bh8);lo=lo+Math.imul(al8,bl9)|0;mid=mid+Math.imul(al8,bh9)|0;mid=mid+Math.imul(ah8,bl9)|0;hi=hi+Math.imul(ah8,bh9)|0;var w17=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w17>>>26)|0;w17&=67108863;lo=Math.imul(al9,bl9);mid=Math.imul(al9,bh9);mid=mid+Math.imul(ah9,bl9)|0;hi=Math.imul(ah9,bh9);var w18=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w18>>>26)|0;w18&=67108863;o[0]=w0;o[1]=w1;o[2]=w2;o[3]=w3;o[4]=w4;o[5]=w5;o[6]=w6;o[7]=w7;o[8]=w8;o[9]=w9;o[10]=w10;o[11]=w11;o[12]=w12;o[13]=w13;o[14]=w14;o[15]=w15;o[16]=w16;o[17]=w17;o[18]=w18;if(c!==0){o[19]=c;out.length++}return out};if(!Math.imul){comb10MulTo=smallMulTo}function bigMulTo(self,num,out){out.negative=num.negative^self.negative;out.length=self.length+num.length;var carry=0;var hncarry=0;for(var k=0;k>>26)|0;hncarry+=ncarry>>>26;ncarry&=67108863}out.words[k]=rword;carry=ncarry;ncarry=hncarry}if(carry!==0){out.words[k]=carry}else{out.length--}return out.strip()}function jumboMulTo(self,num,out){var fftm=new FFTM;return fftm.mulp(self,num,out)}BN.prototype.mulTo=function mulTo(num,out){var res;var len=this.length+num.length;if(this.length===10&&num.length===10){res=comb10MulTo(this,num,out)}else if(len<63){res=smallMulTo(this,num,out)}else if(len<1024){res=bigMulTo(this,num,out)}else{res=jumboMulTo(this,num,out)}return res};function FFTM(x,y){this.x=x;this.y=y}FFTM.prototype.makeRBT=function makeRBT(N){var t=new Array(N);var l=BN.prototype._countBits(N)-1;for(var i=0;i>=1}return rb};FFTM.prototype.permute=function permute(rbt,rws,iws,rtws,itws,N){for(var i=0;i>>1){i++}return 1<>>13;rws[2*i+1]=carry&8191;carry=carry>>>13}for(i=2*len;i>=26;carry+=w/67108864|0;carry+=lo>>>26;this.words[i]=lo&67108863}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.muln=function muln(num){return this.clone().imuln(num)};BN.prototype.sqr=function sqr(){return this.mul(this)};BN.prototype.isqr=function isqr(){return this.imul(this.clone())};BN.prototype.pow=function pow(num){var w=toBitArray(num);if(w.length===0)return new BN(1);var res=this;for(var i=0;i=0);var r=bits%26;var s=(bits-r)/26;var carryMask=67108863>>>26-r<<26-r;var i;if(r!==0){var carry=0;for(i=0;i>>26-r}if(carry){this.words[i]=carry;this.length++}}if(s!==0){for(i=this.length-1;i>=0;i--){this.words[i+s]=this.words[i]}for(i=0;i=0);var h;if(hint){h=(hint-hint%26)/26}else{h=0}var r=bits%26;var s=Math.min((bits-r)/26,this.length);var mask=67108863^67108863>>>r<s){this.length-=s;for(i=0;i=0&&(carry!==0||i>=h);i--){var word=this.words[i]|0;this.words[i]=carry<<26-r|word>>>r;carry=word&mask}if(maskedWords&&carry!==0){maskedWords.words[maskedWords.length++]=carry}if(this.length===0){this.words[0]=0;this.length=1}return this.strip()};BN.prototype.ishrn=function ishrn(bits,hint,extended){assert(this.negative===0);return this.iushrn(bits,hint,extended)};BN.prototype.shln=function shln(bits){return this.clone().ishln(bits)};BN.prototype.ushln=function ushln(bits){return this.clone().iushln(bits)};BN.prototype.shrn=function shrn(bits){return this.clone().ishrn(bits)};BN.prototype.ushrn=function ushrn(bits){return this.clone().iushrn(bits)};BN.prototype.testn=function testn(bit){assert(typeof bit==="number"&&bit>=0);var r=bit%26;var s=(bit-r)/26;var q=1<=0);var r=bits%26;var s=(bits-r)/26;assert(this.negative===0,"imaskn works only with positive numbers");if(this.length<=s){return this}if(r!==0){s++}this.length=Math.min(s,this.length);if(r!==0){var mask=67108863^67108863>>>r<=67108864;i++){this.words[i]-=67108864;if(i===this.length-1){this.words[i+1]=1}else{this.words[i+1]++}}this.length=Math.max(this.length,i+1);return this};BN.prototype.isubn=function isubn(num){assert(typeof num==="number");assert(num<67108864);if(num<0)return this.iaddn(-num);if(this.negative!==0){this.negative=0;this.iaddn(num);this.negative=1;return this}this.words[0]-=num;if(this.length===1&&this.words[0]<0){this.words[0]=-this.words[0];this.negative=1}else{for(var i=0;i>26)-(right/67108864|0);this.words[i+shift]=w&67108863}for(;i>26;this.words[i+shift]=w&67108863}if(carry===0)return this.strip();assert(carry===-1);carry=0;for(i=0;i>26;this.words[i]=w&67108863}this.negative=1;return this.strip()};BN.prototype._wordDiv=function _wordDiv(num,mode){var shift=this.length-num.length;var a=this.clone();var b=num;var bhi=b.words[b.length-1]|0;var bhiBits=this._countBits(bhi);shift=26-bhiBits;if(shift!==0){b=b.ushln(shift);a.iushln(shift);bhi=b.words[b.length-1]|0}var m=a.length-b.length;var q;if(mode!=="mod"){q=new BN(null);q.length=m+1;q.words=new Array(q.length);for(var i=0;i=0;j--){var qj=(a.words[b.length+j]|0)*67108864+(a.words[b.length+j-1]|0);qj=Math.min(qj/bhi|0,67108863);a._ishlnsubmul(b,qj,j);while(a.negative!==0){qj--;a.negative=0;a._ishlnsubmul(b,1,j);if(!a.isZero()){a.negative^=1}}if(q){q.words[j]=qj}}if(q){q.strip()}a.strip();if(mode!=="div"&&shift!==0){a.iushrn(shift)}return{div:q||null,mod:a}};BN.prototype.divmod=function divmod(num,mode,positive){assert(!num.isZero());if(this.isZero()){return{div:new BN(0),mod:new BN(0)}}var div,mod,res;if(this.negative!==0&&num.negative===0){res=this.neg().divmod(num,mode);if(mode!=="mod"){div=res.div.neg()}if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.iadd(num)}}return{div:div,mod:mod}}if(this.negative===0&&num.negative!==0){res=this.divmod(num.neg(),mode);if(mode!=="mod"){div=res.div.neg()}return{div:div,mod:res.mod}}if((this.negative&num.negative)!==0){res=this.neg().divmod(num.neg(),mode);if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.isub(num)}}return{div:res.div,mod:mod}}if(num.length>this.length||this.cmp(num)<0){return{div:new BN(0),mod:this}}if(num.length===1){if(mode==="div"){return{div:this.divn(num.words[0]),mod:null}}if(mode==="mod"){return{div:null,mod:new BN(this.modn(num.words[0]))}}return{div:this.divn(num.words[0]),mod:new BN(this.modn(num.words[0]))}}return this._wordDiv(num,mode)};BN.prototype.div=function div(num){return this.divmod(num,"div",false).div};BN.prototype.mod=function mod(num){return this.divmod(num,"mod",false).mod};BN.prototype.umod=function umod(num){return this.divmod(num,"mod",true).mod};BN.prototype.divRound=function divRound(num){var dm=this.divmod(num);if(dm.mod.isZero())return dm.div;var mod=dm.div.negative!==0?dm.mod.isub(num):dm.mod;var half=num.ushrn(1);var r2=num.andln(1);var cmp=mod.cmp(half);if(cmp<0||r2===1&&cmp===0)return dm.div;return dm.div.negative!==0?dm.div.isubn(1):dm.div.iaddn(1)};BN.prototype.modn=function modn(num){assert(num<=67108863);var p=(1<<26)%num;var acc=0;for(var i=this.length-1;i>=0;i--){acc=(p*acc+(this.words[i]|0))%num}return acc};BN.prototype.idivn=function idivn(num){assert(num<=67108863);var carry=0;for(var i=this.length-1;i>=0;i--){var w=(this.words[i]|0)+carry*67108864;this.words[i]=w/num|0;carry=w%num}return this.strip()};BN.prototype.divn=function divn(num){return this.clone().idivn(num)};BN.prototype.egcd=function egcd(p){assert(p.negative===0);assert(!p.isZero());var x=this;var y=p.clone();if(x.negative!==0){x=x.umod(p)}else{x=x.clone()}var A=new BN(1);var B=new BN(0);var C=new BN(0);var D=new BN(1);var g=0;while(x.isEven()&&y.isEven()){x.iushrn(1);y.iushrn(1);++g}var yp=y.clone();var xp=x.clone();while(!x.isZero()){for(var i=0,im=1;(x.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){x.iushrn(i);while(i-- >0){if(A.isOdd()||B.isOdd()){A.iadd(yp);B.isub(xp)}A.iushrn(1);B.iushrn(1)}}for(var j=0,jm=1;(y.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){y.iushrn(j);while(j-- >0){if(C.isOdd()||D.isOdd()){C.iadd(yp);D.isub(xp)}C.iushrn(1);D.iushrn(1)}}if(x.cmp(y)>=0){x.isub(y);A.isub(C);B.isub(D)}else{y.isub(x);C.isub(A);D.isub(B)}}return{a:C,b:D,gcd:y.iushln(g)}};BN.prototype._invmp=function _invmp(p){assert(p.negative===0);assert(!p.isZero());var a=this;var b=p.clone();if(a.negative!==0){a=a.umod(p)}else{a=a.clone()}var x1=new BN(1);var x2=new BN(0);var delta=b.clone();while(a.cmpn(1)>0&&b.cmpn(1)>0){for(var i=0,im=1;(a.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){a.iushrn(i);while(i-- >0){if(x1.isOdd()){x1.iadd(delta)}x1.iushrn(1)}}for(var j=0,jm=1;(b.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){b.iushrn(j);while(j-- >0){if(x2.isOdd()){x2.iadd(delta)}x2.iushrn(1)}}if(a.cmp(b)>=0){a.isub(b);x1.isub(x2)}else{b.isub(a);x2.isub(x1)}}var res;if(a.cmpn(1)===0){res=x1}else{res=x2}if(res.cmpn(0)<0){res.iadd(p)}return res};BN.prototype.gcd=function gcd(num){if(this.isZero())return num.abs();if(num.isZero())return this.abs();var a=this.clone();var b=num.clone();a.negative=0;b.negative=0;for(var shift=0;a.isEven()&&b.isEven();shift++){a.iushrn(1);b.iushrn(1)}do{while(a.isEven()){a.iushrn(1)}while(b.isEven()){b.iushrn(1)}var r=a.cmp(b);if(r<0){var t=a;a=b;b=t}else if(r===0||b.cmpn(1)===0){break}a.isub(b)}while(true);return b.iushln(shift)};BN.prototype.invm=function invm(num){return this.egcd(num).a.umod(num)};BN.prototype.isEven=function isEven(){return(this.words[0]&1)===0};BN.prototype.isOdd=function isOdd(){return(this.words[0]&1)===1};BN.prototype.andln=function andln(num){return this.words[0]&num};BN.prototype.bincn=function bincn(bit){assert(typeof bit==="number");var r=bit%26;var s=(bit-r)/26;var q=1<>>26;w&=67108863;this.words[i]=w}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.isZero=function isZero(){return this.length===1&&this.words[0]===0};BN.prototype.cmpn=function cmpn(num){var negative=num<0;if(this.negative!==0&&!negative)return-1;if(this.negative===0&&negative)return 1;this.strip();var res;if(this.length>1){res=1}else{if(negative){num=-num}assert(num<=67108863,"Number is too big");var w=this.words[0]|0;res=w===num?0:wnum.length)return 1;if(this.length=0;i--){var a=this.words[i]|0;var b=num.words[i]|0;if(a===b)continue;if(ab){res=1}break}return res};BN.prototype.gtn=function gtn(num){return this.cmpn(num)===1};BN.prototype.gt=function gt(num){return this.cmp(num)===1};BN.prototype.gten=function gten(num){return this.cmpn(num)>=0};BN.prototype.gte=function gte(num){return this.cmp(num)>=0};BN.prototype.ltn=function ltn(num){return this.cmpn(num)===-1};BN.prototype.lt=function lt(num){return this.cmp(num)===-1};BN.prototype.lten=function lten(num){return this.cmpn(num)<=0};BN.prototype.lte=function lte(num){return this.cmp(num)<=0};BN.prototype.eqn=function eqn(num){return this.cmpn(num)===0};BN.prototype.eq=function eq(num){return this.cmp(num)===0};BN.red=function red(num){return new Red(num)};BN.prototype.toRed=function toRed(ctx){assert(!this.red,"Already a number in reduction context");assert(this.negative===0,"red works only with positives");return ctx.convertTo(this)._forceRed(ctx)};BN.prototype.fromRed=function fromRed(){assert(this.red,"fromRed works only with numbers in reduction context");return this.red.convertFrom(this)};BN.prototype._forceRed=function _forceRed(ctx){this.red=ctx;return this};BN.prototype.forceRed=function forceRed(ctx){assert(!this.red,"Already a number in reduction context");return this._forceRed(ctx)};BN.prototype.redAdd=function redAdd(num){assert(this.red,"redAdd works only with red numbers");return this.red.add(this,num)};BN.prototype.redIAdd=function redIAdd(num){assert(this.red,"redIAdd works only with red numbers");return this.red.iadd(this,num)};BN.prototype.redSub=function redSub(num){assert(this.red,"redSub works only with red numbers");return this.red.sub(this,num)};BN.prototype.redISub=function redISub(num){assert(this.red,"redISub works only with red numbers");return this.red.isub(this,num)};BN.prototype.redShl=function redShl(num){assert(this.red,"redShl works only with red numbers");return this.red.shl(this,num)};BN.prototype.redMul=function redMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.mul(this,num)};BN.prototype.redIMul=function redIMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.imul(this,num)};BN.prototype.redSqr=function redSqr(){assert(this.red,"redSqr works only with red numbers");this.red._verify1(this);return this.red.sqr(this)};BN.prototype.redISqr=function redISqr(){assert(this.red,"redISqr works only with red numbers");this.red._verify1(this);return this.red.isqr(this)};BN.prototype.redSqrt=function redSqrt(){assert(this.red,"redSqrt works only with red numbers");this.red._verify1(this);return this.red.sqrt(this)};BN.prototype.redInvm=function redInvm(){assert(this.red,"redInvm works only with red numbers");this.red._verify1(this);return this.red.invm(this)};BN.prototype.redNeg=function redNeg(){assert(this.red,"redNeg works only with red numbers");this.red._verify1(this);return this.red.neg(this)};BN.prototype.redPow=function redPow(num){assert(this.red&&!num.red,"redPow(normalNum)");this.red._verify1(this);return this.red.pow(this,num)};var primes={k256:null,p224:null,p192:null,p25519:null};function MPrime(name,p){this.name=name;this.p=new BN(p,16);this.n=this.p.bitLength();this.k=new BN(1).iushln(this.n).isub(this.p);this.tmp=this._tmp()}MPrime.prototype._tmp=function _tmp(){var tmp=new BN(null);tmp.words=new Array(Math.ceil(this.n/13));return tmp};MPrime.prototype.ireduce=function ireduce(num){var r=num;var rlen;do{this.split(r,this.tmp);r=this.imulK(r);r=r.iadd(this.tmp);rlen=r.bitLength()}while(rlen>this.n);var cmp=rlen0){r.isub(this.p)}else{r.strip()}return r};MPrime.prototype.split=function split(input,out){input.iushrn(this.n,0,out)};MPrime.prototype.imulK=function imulK(num){return num.imul(this.k)};function K256(){MPrime.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}inherits(K256,MPrime);K256.prototype.split=function split(input,output){var mask=4194303;var outLen=Math.min(input.length,9);for(var i=0;i>>22;prev=next}prev>>>=22;input.words[i-10]=prev;if(prev===0&&input.length>10){input.length-=10}else{input.length-=9}};K256.prototype.imulK=function imulK(num){num.words[num.length]=0;num.words[num.length+1]=0;num.length+=2;var lo=0;for(var i=0;i>>=26;num.words[i]=lo;carry=hi}if(carry!==0){num.words[num.length++]=carry}return num};BN._prime=function prime(name){if(primes[name])return primes[name];var prime;if(name==="k256"){prime=new K256}else if(name==="p224"){prime=new P224}else if(name==="p192"){prime=new P192}else if(name==="p25519"){prime=new P25519}else{throw new Error("Unknown prime "+name)}primes[name]=prime;return prime};function Red(m){if(typeof m==="string"){var prime=BN._prime(m);this.m=prime.p;this.prime=prime}else{assert(m.gtn(1),"modulus must be greater than 1");this.m=m;this.prime=null}}Red.prototype._verify1=function _verify1(a){assert(a.negative===0,"red works only with positives");assert(a.red,"red works only with red numbers")};Red.prototype._verify2=function _verify2(a,b){assert((a.negative|b.negative)===0,"red works only with positives");assert(a.red&&a.red===b.red,"red works only with red numbers")};Red.prototype.imod=function imod(a){if(this.prime)return this.prime.ireduce(a)._forceRed(this);return a.umod(this.m)._forceRed(this)};Red.prototype.neg=function neg(a){if(a.isZero()){return a.clone()}return this.m.sub(a)._forceRed(this)};Red.prototype.add=function add(a,b){this._verify2(a,b);var res=a.add(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res._forceRed(this)};Red.prototype.iadd=function iadd(a,b){this._verify2(a,b);var res=a.iadd(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res};Red.prototype.sub=function sub(a,b){this._verify2(a,b);var res=a.sub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res._forceRed(this)};Red.prototype.isub=function isub(a,b){this._verify2(a,b);var res=a.isub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res};Red.prototype.shl=function shl(a,num){this._verify1(a);return this.imod(a.ushln(num))};Red.prototype.imul=function imul(a,b){this._verify2(a,b);return this.imod(a.imul(b))};Red.prototype.mul=function mul(a,b){this._verify2(a,b);return this.imod(a.mul(b))};Red.prototype.isqr=function isqr(a){return this.imul(a,a.clone())};Red.prototype.sqr=function sqr(a){return this.mul(a,a)};Red.prototype.sqrt=function sqrt(a){if(a.isZero())return a.clone();var mod3=this.m.andln(3);assert(mod3%2===1);if(mod3===3){var pow=this.m.add(new BN(1)).iushrn(2);return this.pow(a,pow)}var q=this.m.subn(1);var s=0;while(!q.isZero()&&q.andln(1)===0){s++;q.iushrn(1)}assert(!q.isZero());var one=new BN(1).toRed(this);var nOne=one.redNeg();var lpow=this.m.subn(1).iushrn(1);var z=this.m.bitLength();z=new BN(2*z*z).toRed(this);while(this.pow(z,lpow).cmp(nOne)!==0){z.redIAdd(nOne)}var c=this.pow(z,q);var r=this.pow(a,q.addn(1).iushrn(1));var t=this.pow(a,q);var m=s;while(t.cmp(one)!==0){var tmp=t;for(var i=0;tmp.cmp(one)!==0;i++){tmp=tmp.redSqr()}assert(i=0;i--){var word=num.words[i];for(var j=start-1;j>=0;j--){var bit=word>>j&1;if(res!==wnd[0]){res=this.sqr(res)}if(bit===0&¤t===0){currentLen=0;continue}current<<=1;current|=bit;currentLen++;if(currentLen!==windowSize&&(i!==0||j!==0))continue;res=this.mul(res,wnd[current]);currentLen=0;current=0}start=26}return res};Red.prototype.convertTo=function convertTo(num){var r=num.umod(this.m);return r===num?r.clone():r};Red.prototype.convertFrom=function convertFrom(num){var res=num.clone();res.red=null;return res};BN.mont=function mont(num){return new Mont(num)};function Mont(m){Red.call(this,m);this.shift=this.m.bitLength();if(this.shift%26!==0){this.shift+=26-this.shift%26}this.r=new BN(1).iushln(this.shift);this.r2=this.imod(this.r.sqr());this.rinv=this.r._invmp(this.m);this.minv=this.rinv.mul(this.r).isubn(1).div(this.m);this.minv=this.minv.umod(this.r);this.minv=this.r.sub(this.minv)}inherits(Mont,Red);Mont.prototype.convertTo=function convertTo(num){return this.imod(num.ushln(this.shift))};Mont.prototype.convertFrom=function convertFrom(num){var r=this.imod(num.mul(this.rinv));r.red=null;return r};Mont.prototype.imul=function imul(a,b){if(a.isZero()||b.isZero()){a.words[0]=0;a.length=1;return a}var t=a.imul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.mul=function mul(a,b){if(a.isZero()||b.isZero())return new BN(0)._forceRed(this);var t=a.mul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.invm=function invm(a){var res=this.imod(a._invmp(this.m).mul(this.r2));return res._forceRed(this)}})(typeof module==="undefined"||module,this)},{buffer:131}],63:[function(require,module,exports){var r;module.exports=function rand(len){if(!r)r=new Rand(null);return r.generate(len)};function Rand(rand){this.rand=rand}module.exports.Rand=Rand;Rand.prototype.generate=function generate(len){return this._rand(len)};Rand.prototype._rand=function _rand(n){if(this.rand.getBytes)return this.rand.getBytes(n);var res=new Uint8Array(n);for(var i=0;i=0)return false;if(y.signum()<0||y.compareTo(p)>=0)return false;var lhs=y.square().mod(p);var rhs=x.pow(3).add(a.multiply(x)).add(b).mod(p);return lhs.equals(rhs)};Curve.prototype.validate=function(Q){assert(!this.isInfinity(Q),"Point is at infinity");assert(this.isOnCurve(Q),"Point is not on the curve");var nQ=Q.multiply(this.n);assert(this.isInfinity(nQ),"Point is not a scalar multiple of G");return true};module.exports=Curve},{"./point":70,assert:124,bigi:52}],67:[function(require,module,exports){module.exports={secp128r1:{p:"fffffffdffffffffffffffffffffffff",a:"fffffffdfffffffffffffffffffffffc",b:"e87579c11079f43dd824993c2cee5ed3",n:"fffffffe0000000075a30d1b9038a115",h:"01",Gx:"161ff7528b899b2d0c28607ca52c5b86",Gy:"cf5ac8395bafeb13c02da292dded7a83"},secp160k1:{p:"fffffffffffffffffffffffffffffffeffffac73",a:"00",b:"07",n:"0100000000000000000001b8fa16dfab9aca16b6b3",h:"01",Gx:"3b4c382ce37aa192a4019e763036f4f5dd4d7ebb",Gy:"938cf935318fdced6bc28286531733c3f03c4fee"},secp160r1:{p:"ffffffffffffffffffffffffffffffff7fffffff",a:"ffffffffffffffffffffffffffffffff7ffffffc",b:"1c97befc54bd7a8b65acf89f81d4d4adc565fa45",n:"0100000000000000000001f4c8f927aed3ca752257",h:"01",Gx:"4a96b5688ef573284664698968c38bb913cbfc82",Gy:"23a628553168947d59dcc912042351377ac5fb32"},secp192k1:{p:"fffffffffffffffffffffffffffffffffffffffeffffee37",a:"00",b:"03",n:"fffffffffffffffffffffffe26f2fc170f69466a74defd8d",h:"01",Gx:"db4ff10ec057e9ae26b07d0280b7f4341da5d1b1eae06c7d",Gy:"9b2f2f6d9c5628a7844163d015be86344082aa88d95e2f9d"},secp192r1:{p:"fffffffffffffffffffffffffffffffeffffffffffffffff",a:"fffffffffffffffffffffffffffffffefffffffffffffffc",b:"64210519e59c80e70fa7e9ab72243049feb8deecc146b9b1",n:"ffffffffffffffffffffffff99def836146bc9b1b4d22831",h:"01",Gx:"188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012",Gy:"07192b95ffc8da78631011ed6b24cdd573f977a11e794811"},secp256k1:{p:"fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f",a:"00",b:"07",n:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141",h:"01",Gx:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",Gy:"483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8"},secp256r1:{p:"ffffffff00000001000000000000000000000000ffffffffffffffffffffffff",a:"ffffffff00000001000000000000000000000000fffffffffffffffffffffffc",b:"5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b",n:"ffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551",h:"01",Gx:"6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296",Gy:"4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"}}},{}],68:[function(require,module,exports){var Point=require("./point");var Curve=require("./curve");var getCurveByName=require("./names");module.exports={Curve:Curve,Point:Point,getCurveByName:getCurveByName}},{"./curve":66,"./names":69,"./point":70}],69:[function(require,module,exports){var BigInteger=require("bigi");var curves=require("./curves.json");var Curve=require("./curve");function getCurveByName(name){var curve=curves[name];if(!curve)return null;var p=new BigInteger(curve.p,16);var a=new BigInteger(curve.a,16);var b=new BigInteger(curve.b,16);var n=new BigInteger(curve.n,16);var h=new BigInteger(curve.h,16);var Gx=new BigInteger(curve.Gx,16);var Gy=new BigInteger(curve.Gy,16);return new Curve(p,a,b,Gx,Gy,n,h)}module.exports=getCurveByName},{"./curve":66,"./curves.json":67,bigi:52}],70:[function(require,module,exports){var assert=require("assert");var Buffer=require("safe-buffer").Buffer;var BigInteger=require("bigi");var THREE=BigInteger.valueOf(3);function Point(curve,x,y,z){assert.notStrictEqual(z,undefined,"Missing Z coordinate");this.curve=curve;this.x=x;this.y=y;this.z=z;this._zInv=null;this.compressed=true}Object.defineProperty(Point.prototype,"zInv",{get:function(){if(this._zInv===null){this._zInv=this.z.modInverse(this.curve.p)}return this._zInv}});Object.defineProperty(Point.prototype,"affineX",{get:function(){return this.x.multiply(this.zInv).mod(this.curve.p)}});Object.defineProperty(Point.prototype,"affineY",{get:function(){return this.y.multiply(this.zInv).mod(this.curve.p)}});Point.fromAffine=function(curve,x,y){return new Point(curve,x,y,BigInteger.ONE)};Point.prototype.equals=function(other){if(other===this)return true;if(this.curve.isInfinity(this))return this.curve.isInfinity(other);if(this.curve.isInfinity(other))return this.curve.isInfinity(this);var u=other.y.multiply(this.z).subtract(this.y.multiply(other.z)).mod(this.curve.p);if(u.signum()!==0)return false;var v=other.x.multiply(this.z).subtract(this.x.multiply(other.z)).mod(this.curve.p);return v.signum()===0};Point.prototype.negate=function(){var y=this.curve.p.subtract(this.y);return new Point(this.curve,this.x,y,this.z)};Point.prototype.add=function(b){if(this.curve.isInfinity(this))return b;if(this.curve.isInfinity(b))return this;var x1=this.x;var y1=this.y;var x2=b.x;var y2=b.y;var u=y2.multiply(this.z).subtract(y1.multiply(b.z)).mod(this.curve.p);var v=x2.multiply(this.z).subtract(x1.multiply(b.z)).mod(this.curve.p);if(v.signum()===0){if(u.signum()===0){return this.twice()}return this.curve.infinity}var v2=v.square();var v3=v2.multiply(v);var x1v2=x1.multiply(v2);var zu2=u.square().multiply(this.z);var x3=zu2.subtract(x1v2.shiftLeft(1)).multiply(b.z).subtract(v3).multiply(v).mod(this.curve.p);var y3=x1v2.multiply(THREE).multiply(u).subtract(y1.multiply(v3)).subtract(zu2.multiply(u)).multiply(b.z).add(u.multiply(v3)).mod(this.curve.p);var z3=v3.multiply(this.z).multiply(b.z).mod(this.curve.p);return new Point(this.curve,x3,y3,z3)};Point.prototype.twice=function(){if(this.curve.isInfinity(this))return this;if(this.y.signum()===0)return this.curve.infinity;var x1=this.x;var y1=this.y;var y1z1=y1.multiply(this.z).mod(this.curve.p);var y1sqz1=y1z1.multiply(y1).mod(this.curve.p);var a=this.curve.a;var w=x1.square().multiply(THREE);if(a.signum()!==0){w=w.add(this.z.square().multiply(a))}w=w.mod(this.curve.p);var x3=w.square().subtract(x1.shiftLeft(3).multiply(y1sqz1)).shiftLeft(1).multiply(y1z1).mod(this.curve.p);var y3=w.multiply(THREE).multiply(x1).subtract(y1sqz1.shiftLeft(1)).shiftLeft(2).multiply(y1sqz1).subtract(w.pow(3)).mod(this.curve.p);var z3=y1z1.pow(3).shiftLeft(3).mod(this.curve.p);return new Point(this.curve,x3,y3,z3)};Point.prototype.multiply=function(k){if(this.curve.isInfinity(this))return this;if(k.signum()===0)return this.curve.infinity;var e=k;var h=e.multiply(THREE);var neg=this.negate();var R=this;for(var i=h.bitLength()-2;i>0;--i){var hBit=h.testBit(i);var eBit=e.testBit(i);R=R.twice();if(hBit!==eBit){R=R.add(hBit?this:neg)}}return R};Point.prototype.multiplyTwo=function(j,x,k){var i=Math.max(j.bitLength(),k.bitLength())-1;var R=this.curve.infinity;var both=this.add(x);while(i>=0){var jBit=j.testBit(i);var kBit=k.testBit(i);R=R.twice();if(jBit){if(kBit){R=R.add(both)}else{R=R.add(this)}}else if(kBit){R=R.add(x)}--i}return R};Point.prototype.getEncoded=function(compressed){if(compressed==null)compressed=this.compressed;if(this.curve.isInfinity(this))return Buffer.alloc(1,0);var x=this.affineX;var y=this.affineY;var byteLength=this.curve.pLength;var buffer;if(compressed){buffer=Buffer.allocUnsafe(1+byteLength);buffer.writeUInt8(y.isEven()?2:3,0)}else{buffer=Buffer.allocUnsafe(1+byteLength+byteLength);buffer.writeUInt8(4,0);y.toBuffer(byteLength).copy(buffer,1+byteLength)}x.toBuffer(byteLength).copy(buffer,1);return buffer};Point.decodeFrom=function(curve,buffer){var type=buffer.readUInt8(0);var compressed=type!==4;var byteLength=Math.floor((curve.p.bitLength()+7)/8);var x=BigInteger.fromBuffer(buffer.slice(1,1+byteLength));var Q;if(compressed){assert.equal(buffer.length,byteLength+1,"Invalid sequence length");assert(type===2||type===3,"Invalid sequence tag");var isOdd=type===3;Q=curve.pointFromX(isOdd,x)}else{assert.equal(buffer.length,1+byteLength+byteLength,"Invalid sequence length");var y=BigInteger.fromBuffer(buffer.slice(1+byteLength));Q=Point.fromAffine(curve,x,y)}Q.compressed=compressed;return Q};Point.prototype.toString=function(){if(this.curve.isInfinity(this))return"(INFINITY)";return"("+this.affineX.toString()+","+this.affineY.toString()+")"};module.exports=Point},{assert:124,bigi:52,"safe-buffer":107}],71:[function(require,module,exports){"use strict";var elliptic=exports;elliptic.version=require("../package.json").version;elliptic.utils=require("./elliptic/utils");elliptic.rand=require("brorand");elliptic.curve=require("./elliptic/curve");elliptic.curves=require("./elliptic/curves");elliptic.ec=require("./elliptic/ec");elliptic.eddsa=require("./elliptic/eddsa")},{"../package.json":86,"./elliptic/curve":74,"./elliptic/curves":77,"./elliptic/ec":78,"./elliptic/eddsa":81,"./elliptic/utils":85,brorand:63}],72:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var getNAF=utils.getNAF;var getJSF=utils.getJSF;var assert=utils.assert;function BaseCurve(type,conf){this.type=type;this.p=new BN(conf.p,16);this.red=conf.prime?BN.red(conf.prime):BN.mont(this.p);this.zero=new BN(0).toRed(this.red);this.one=new BN(1).toRed(this.red);this.two=new BN(2).toRed(this.red);this.n=conf.n&&new BN(conf.n,16);this.g=conf.g&&this.pointFromJSON(conf.g,conf.gRed);this._wnafT1=new Array(4);this._wnafT2=new Array(4);this._wnafT3=new Array(4);this._wnafT4=new Array(4);this._bitLength=this.n?this.n.bitLength():0;var adjustCount=this.n&&this.p.div(this.n);if(!adjustCount||adjustCount.cmpn(100)>0){this.redN=null}else{this._maxwellTrick=true;this.redN=this.n.toRed(this.red)}}module.exports=BaseCurve;BaseCurve.prototype.point=function point(){throw new Error("Not implemented")};BaseCurve.prototype.validate=function validate(){throw new Error("Not implemented")};BaseCurve.prototype._fixedNafMul=function _fixedNafMul(p,k){assert(p.precomputed);var doubles=p._getDoubles();var naf=getNAF(k,1,this._bitLength);var I=(1<=j;k--)nafW=(nafW<<1)+naf[k];repr.push(nafW)}var a=this.jpoint(null,null,null);var b=this.jpoint(null,null,null);for(var i=I;i>0;i--){for(var j=0;j=0;i--){for(var k=0;i>=0&&naf[i]===0;i--)k++;if(i>=0)k++;acc=acc.dblp(k);if(i<0)break;var z=naf[i];assert(z!==0);if(p.type==="affine"){if(z>0)acc=acc.mixedAdd(wnd[z-1>>1]);else acc=acc.mixedAdd(wnd[-z-1>>1].neg())}else{if(z>0)acc=acc.add(wnd[z-1>>1]);else acc=acc.add(wnd[-z-1>>1].neg())}}return p.type==="affine"?acc.toP():acc};BaseCurve.prototype._wnafMulAdd=function _wnafMulAdd(defW,points,coeffs,len,jacobianResult){var wndWidth=this._wnafT1;var wnd=this._wnafT2;var naf=this._wnafT3;var max=0;for(var i=0;i=1;i-=2){var a=i-1;var b=i;if(wndWidth[a]!==1||wndWidth[b]!==1){naf[a]=getNAF(coeffs[a],wndWidth[a],this._bitLength);naf[b]=getNAF(coeffs[b],wndWidth[b],this._bitLength);max=Math.max(naf[a].length,max);max=Math.max(naf[b].length,max);continue}var comb=[points[a],null,null,points[b]];if(points[a].y.cmp(points[b].y)===0){comb[1]=points[a].add(points[b]);comb[2]=points[a].toJ().mixedAdd(points[b].neg())}else if(points[a].y.cmp(points[b].y.redNeg())===0){comb[1]=points[a].toJ().mixedAdd(points[b]);comb[2]=points[a].add(points[b].neg())}else{comb[1]=points[a].toJ().mixedAdd(points[b]);comb[2]=points[a].toJ().mixedAdd(points[b].neg())}var index=[-3,-1,-5,-7,0,7,5,1,3];var jsf=getJSF(coeffs[a],coeffs[b]);max=Math.max(jsf[0].length,max);naf[a]=new Array(max);naf[b]=new Array(max);for(var j=0;j=0;i--){var k=0;while(i>=0){var zero=true;for(var j=0;j=0)k++;acc=acc.dblp(k);if(i<0)break;for(var j=0;j0)p=wnd[j][z-1>>1];else if(z<0)p=wnd[j][-z-1>>1].neg();if(p.type==="affine")acc=acc.mixedAdd(p);else acc=acc.add(p)}}for(var i=0;i=Math.ceil((k.bitLength()+1)/doubles.step)};BasePoint.prototype._getDoubles=function _getDoubles(step,power){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;var doubles=[this];var acc=this;for(var i=0;i";return""};Point.prototype.isInfinity=function isInfinity(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)};Point.prototype._extDbl=function _extDbl(){var a=this.x.redSqr();var b=this.y.redSqr();var c=this.z.redSqr();c=c.redIAdd(c);var d=this.curve._mulA(a);var e=this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);var g=d.redAdd(b);var f=g.redSub(c);var h=d.redSub(b);var nx=e.redMul(f);var ny=g.redMul(h);var nt=e.redMul(h);var nz=f.redMul(g);return this.curve.point(nx,ny,nz,nt)};Point.prototype._projDbl=function _projDbl(){var b=this.x.redAdd(this.y).redSqr();var c=this.x.redSqr();var d=this.y.redSqr();var nx;var ny;var nz;if(this.curve.twisted){var e=this.curve._mulA(c);var f=e.redAdd(d);if(this.zOne){nx=b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));ny=f.redMul(e.redSub(d));nz=f.redSqr().redSub(f).redSub(f)}else{var h=this.z.redSqr();var j=f.redSub(h).redISub(h);nx=b.redSub(c).redISub(d).redMul(j);ny=f.redMul(e.redSub(d));nz=f.redMul(j)}}else{var e=c.redAdd(d);var h=this.curve._mulC(this.z).redSqr();var j=e.redSub(h).redSub(h);nx=this.curve._mulC(b.redISub(e)).redMul(j);ny=this.curve._mulC(e).redMul(c.redISub(d));nz=e.redMul(j)}return this.curve.point(nx,ny,nz)};Point.prototype.dbl=function dbl(){if(this.isInfinity())return this;if(this.curve.extended)return this._extDbl();else return this._projDbl()};Point.prototype._extAdd=function _extAdd(p){var a=this.y.redSub(this.x).redMul(p.y.redSub(p.x));var b=this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));var c=this.t.redMul(this.curve.dd).redMul(p.t);var d=this.z.redMul(p.z.redAdd(p.z));var e=b.redSub(a);var f=d.redSub(c);var g=d.redAdd(c);var h=b.redAdd(a);var nx=e.redMul(f);var ny=g.redMul(h);var nt=e.redMul(h);var nz=f.redMul(g);return this.curve.point(nx,ny,nz,nt)};Point.prototype._projAdd=function _projAdd(p){var a=this.z.redMul(p.z);var b=a.redSqr();var c=this.x.redMul(p.x);var d=this.y.redMul(p.y);var e=this.curve.d.redMul(c).redMul(d);var f=b.redSub(e);var g=b.redAdd(e);var tmp=this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);var nx=a.redMul(f).redMul(tmp);var ny;var nz;if(this.curve.twisted){ny=a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));nz=f.redMul(g)}else{ny=a.redMul(g).redMul(d.redSub(c));nz=this.curve._mulC(f).redMul(g)}return this.curve.point(nx,ny,nz)};Point.prototype.add=function add(p){if(this.isInfinity())return p;if(p.isInfinity())return this;if(this.curve.extended)return this._extAdd(p);else return this._projAdd(p)};Point.prototype.mul=function mul(k){if(this._hasDoubles(k))return this.curve._fixedNafMul(this,k);else return this.curve._wnafMul(this,k)};Point.prototype.mulAdd=function mulAdd(k1,p,k2){return this.curve._wnafMulAdd(1,[this,p],[k1,k2],2,false)};Point.prototype.jmulAdd=function jmulAdd(k1,p,k2){return this.curve._wnafMulAdd(1,[this,p],[k1,k2],2,true)};Point.prototype.normalize=function normalize(){if(this.zOne)return this;var zi=this.z.redInvm();this.x=this.x.redMul(zi);this.y=this.y.redMul(zi);if(this.t)this.t=this.t.redMul(zi);this.z=this.curve.one;this.zOne=true;return this};Point.prototype.neg=function neg(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())};Point.prototype.getX=function getX(){this.normalize();return this.x.fromRed()};Point.prototype.getY=function getY(){this.normalize();return this.y.fromRed()};Point.prototype.eq=function eq(other){return this===other||this.getX().cmp(other.getX())===0&&this.getY().cmp(other.getY())===0};Point.prototype.eqXToP=function eqXToP(x){var rx=x.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(rx)===0)return true;var xc=x.clone();var t=this.curve.redN.redMul(this.z);for(;;){xc.iadd(this.curve.n);if(xc.cmp(this.curve.p)>=0)return false;rx.redIAdd(t);if(this.x.cmp(rx)===0)return true}};Point.prototype.toP=Point.prototype.normalize;Point.prototype.mixedAdd=Point.prototype.add},{"../utils":85,"./base":72,"bn.js":62,inherits:101}],74:[function(require,module,exports){"use strict";var curve=exports;curve.base=require("./base");curve.short=require("./short");curve.mont=require("./mont");curve.edwards=require("./edwards")},{"./base":72,"./edwards":73,"./mont":75,"./short":76}],75:[function(require,module,exports){"use strict";var BN=require("bn.js");var inherits=require("inherits");var Base=require("./base");var utils=require("../utils");function MontCurve(conf){Base.call(this,"mont",conf);this.a=new BN(conf.a,16).toRed(this.red);this.b=new BN(conf.b,16).toRed(this.red);this.i4=new BN(4).toRed(this.red).redInvm();this.two=new BN(2).toRed(this.red);this.a24=this.i4.redMul(this.a.redAdd(this.two))}inherits(MontCurve,Base);module.exports=MontCurve;MontCurve.prototype.validate=function validate(point){var x=point.normalize().x;var x2=x.redSqr();var rhs=x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x);var y=rhs.redSqrt();return y.redSqr().cmp(rhs)===0};function Point(curve,x,z){Base.BasePoint.call(this,curve,"projective");if(x===null&&z===null){this.x=this.curve.one;this.z=this.curve.zero}else{this.x=new BN(x,16);this.z=new BN(z,16);if(!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red)}}inherits(Point,Base.BasePoint);MontCurve.prototype.decodePoint=function decodePoint(bytes,enc){return this.point(utils.toArray(bytes,enc),1)};MontCurve.prototype.point=function point(x,z){return new Point(this,x,z)};MontCurve.prototype.pointFromJSON=function pointFromJSON(obj){return Point.fromJSON(this,obj)};Point.prototype.precompute=function precompute(){};Point.prototype._encode=function _encode(){return this.getX().toArray("be",this.curve.p.byteLength())};Point.fromJSON=function fromJSON(curve,obj){return new Point(curve,obj[0],obj[1]||curve.one)};Point.prototype.inspect=function inspect(){if(this.isInfinity())return"";return""};Point.prototype.isInfinity=function isInfinity(){return this.z.cmpn(0)===0};Point.prototype.dbl=function dbl(){var a=this.x.redAdd(this.z);var aa=a.redSqr();var b=this.x.redSub(this.z);var bb=b.redSqr();var c=aa.redSub(bb);var nx=aa.redMul(bb);var nz=c.redMul(bb.redAdd(this.curve.a24.redMul(c)));return this.curve.point(nx,nz)};Point.prototype.add=function add(){throw new Error("Not supported on Montgomery curve")};Point.prototype.diffAdd=function diffAdd(p,diff){var a=this.x.redAdd(this.z);var b=this.x.redSub(this.z);var c=p.x.redAdd(p.z);var d=p.x.redSub(p.z);var da=d.redMul(a);var cb=c.redMul(b);var nx=diff.z.redMul(da.redAdd(cb).redSqr());var nz=diff.x.redMul(da.redISub(cb).redSqr());return this.curve.point(nx,nz)};Point.prototype.mul=function mul(k){var t=k.clone();var a=this;var b=this.curve.point(null,null);var c=this;for(var bits=[];t.cmpn(0)!==0;t.iushrn(1))bits.push(t.andln(1));for(var i=bits.length-1;i>=0;i--){if(bits[i]===0){a=a.diffAdd(b,c);b=b.dbl()}else{b=a.diffAdd(b,c);a=a.dbl()}}return b};Point.prototype.mulAdd=function mulAdd(){throw new Error("Not supported on Montgomery curve")};Point.prototype.jumlAdd=function jumlAdd(){throw new Error("Not supported on Montgomery curve")};Point.prototype.eq=function eq(other){return this.getX().cmp(other.getX())===0};Point.prototype.normalize=function normalize(){this.x=this.x.redMul(this.z.redInvm());this.z=this.curve.one;return this};Point.prototype.getX=function getX(){this.normalize();return this.x.fromRed()}},{"../utils":85,"./base":72,"bn.js":62,inherits:101}],76:[function(require,module,exports){"use strict";var utils=require("../utils");var BN=require("bn.js");var inherits=require("inherits");var Base=require("./base");var assert=utils.assert;function ShortCurve(conf){Base.call(this,"short",conf);this.a=new BN(conf.a,16).toRed(this.red);this.b=new BN(conf.b,16).toRed(this.red);this.tinv=this.two.redInvm();this.zeroA=this.a.fromRed().cmpn(0)===0;this.threeA=this.a.fromRed().sub(this.p).cmpn(-3)===0;this.endo=this._getEndomorphism(conf);this._endoWnafT1=new Array(4);this._endoWnafT2=new Array(4)}inherits(ShortCurve,Base);module.exports=ShortCurve;ShortCurve.prototype._getEndomorphism=function _getEndomorphism(conf){if(!this.zeroA||!this.g||!this.n||this.p.modn(3)!==1)return;var beta;var lambda;if(conf.beta){beta=new BN(conf.beta,16).toRed(this.red)}else{var betas=this._getEndoRoots(this.p);beta=betas[0].cmp(betas[1])<0?betas[0]:betas[1];beta=beta.toRed(this.red)}if(conf.lambda){lambda=new BN(conf.lambda,16)}else{var lambdas=this._getEndoRoots(this.n);if(this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta))===0){lambda=lambdas[0]}else{lambda=lambdas[1];assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta))===0)}}var basis;if(conf.basis){basis=conf.basis.map(function(vec){return{a:new BN(vec.a,16),b:new BN(vec.b,16)}})}else{basis=this._getEndoBasis(lambda)}return{beta:beta,lambda:lambda,basis:basis}};ShortCurve.prototype._getEndoRoots=function _getEndoRoots(num){var red=num===this.p?this.red:BN.mont(num);var tinv=new BN(2).toRed(red).redInvm();var ntinv=tinv.redNeg();var s=new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);var l1=ntinv.redAdd(s).fromRed();var l2=ntinv.redSub(s).fromRed();return[l1,l2]};ShortCurve.prototype._getEndoBasis=function _getEndoBasis(lambda){var aprxSqrt=this.n.ushrn(Math.floor(this.n.bitLength()/2));var u=lambda;var v=this.n.clone();var x1=new BN(1);var y1=new BN(0);var x2=new BN(0);var y2=new BN(1);var a0;var b0;var a1;var b1;var a2;var b2;var prevR;var i=0;var r;var x;while(u.cmpn(0)!==0){var q=v.div(u);r=v.sub(q.mul(u));x=x2.sub(q.mul(x1));var y=y2.sub(q.mul(y1));if(!a1&&r.cmp(aprxSqrt)<0){a0=prevR.neg();b0=x1;a1=r.neg();b1=x}else if(a1&&++i===2){break}prevR=r;v=u;u=r;x2=x1;x1=x;y2=y1;y1=y}a2=r.neg();b2=x;var len1=a1.sqr().add(b1.sqr());var len2=a2.sqr().add(b2.sqr());if(len2.cmp(len1)>=0){a2=a0;b2=b0}if(a1.negative){a1=a1.neg();b1=b1.neg()}if(a2.negative){a2=a2.neg();b2=b2.neg()}return[{a:a1,b:b1},{a:a2,b:b2}]};ShortCurve.prototype._endoSplit=function _endoSplit(k){var basis=this.endo.basis;var v1=basis[0];var v2=basis[1];var c1=v2.b.mul(k).divRound(this.n);var c2=v1.b.neg().mul(k).divRound(this.n);var p1=c1.mul(v1.a);var p2=c2.mul(v2.a);var q1=c1.mul(v1.b);var q2=c2.mul(v2.b);var k1=k.sub(p1).sub(p2);var k2=q1.add(q2).neg();return{k1:k1,k2:k2}};ShortCurve.prototype.pointFromX=function pointFromX(x,odd){x=new BN(x,16);if(!x.red)x=x.toRed(this.red);var y2=x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);var y=y2.redSqrt();if(y.redSqr().redSub(y2).cmp(this.zero)!==0)throw new Error("invalid point");var isOdd=y.fromRed().isOdd();if(odd&&!isOdd||!odd&&isOdd)y=y.redNeg();return this.point(x,y)};ShortCurve.prototype.validate=function validate(point){if(point.inf)return true;var x=point.x;var y=point.y;var ax=this.a.redMul(x);var rhs=x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);return y.redSqr().redISub(rhs).cmpn(0)===0};ShortCurve.prototype._endoWnafMulAdd=function _endoWnafMulAdd(points,coeffs,jacobianResult){var npoints=this._endoWnafT1;var ncoeffs=this._endoWnafT2;for(var i=0;i";return""};Point.prototype.isInfinity=function isInfinity(){return this.inf};Point.prototype.add=function add(p){if(this.inf)return p;if(p.inf)return this;if(this.eq(p))return this.dbl();if(this.neg().eq(p))return this.curve.point(null,null);if(this.x.cmp(p.x)===0)return this.curve.point(null,null);var c=this.y.redSub(p.y);if(c.cmpn(0)!==0)c=c.redMul(this.x.redSub(p.x).redInvm());var nx=c.redSqr().redISub(this.x).redISub(p.x);var ny=c.redMul(this.x.redSub(nx)).redISub(this.y);return this.curve.point(nx,ny)};Point.prototype.dbl=function dbl(){if(this.inf)return this;var ys1=this.y.redAdd(this.y);if(ys1.cmpn(0)===0)return this.curve.point(null,null);var a=this.curve.a;var x2=this.x.redSqr();var dyinv=ys1.redInvm();var c=x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);var nx=c.redSqr().redISub(this.x.redAdd(this.x));var ny=c.redMul(this.x.redSub(nx)).redISub(this.y);return this.curve.point(nx,ny)};Point.prototype.getX=function getX(){return this.x.fromRed()};Point.prototype.getY=function getY(){return this.y.fromRed()};Point.prototype.mul=function mul(k){k=new BN(k,16);if(this.isInfinity())return this;else if(this._hasDoubles(k))return this.curve._fixedNafMul(this,k);else if(this.curve.endo)return this.curve._endoWnafMulAdd([this],[k]);else return this.curve._wnafMul(this,k)};Point.prototype.mulAdd=function mulAdd(k1,p2,k2){var points=[this,p2];var coeffs=[k1,k2];if(this.curve.endo)return this.curve._endoWnafMulAdd(points,coeffs);else return this.curve._wnafMulAdd(1,points,coeffs,2)};Point.prototype.jmulAdd=function jmulAdd(k1,p2,k2){var points=[this,p2];var coeffs=[k1,k2];if(this.curve.endo)return this.curve._endoWnafMulAdd(points,coeffs,true);else return this.curve._wnafMulAdd(1,points,coeffs,2,true)};Point.prototype.eq=function eq(p){return this===p||this.inf===p.inf&&(this.inf||this.x.cmp(p.x)===0&&this.y.cmp(p.y)===0)};Point.prototype.neg=function neg(_precompute){if(this.inf)return this;var res=this.curve.point(this.x,this.y.redNeg());if(_precompute&&this.precomputed){var pre=this.precomputed;var negate=function(p){return p.neg()};res.precomputed={naf:pre.naf&&{wnd:pre.naf.wnd,points:pre.naf.points.map(negate)},doubles:pre.doubles&&{step:pre.doubles.step,points:pre.doubles.points.map(negate)}}}return res};Point.prototype.toJ=function toJ(){if(this.inf)return this.curve.jpoint(null,null,null);var res=this.curve.jpoint(this.x,this.y,this.curve.one);return res};function JPoint(curve,x,y,z){Base.BasePoint.call(this,curve,"jacobian");if(x===null&&y===null&&z===null){this.x=this.curve.one;this.y=this.curve.one;this.z=new BN(0)}else{this.x=new BN(x,16);this.y=new BN(y,16);this.z=new BN(z,16)}if(!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.y.red)this.y=this.y.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red);this.zOne=this.z===this.curve.one}inherits(JPoint,Base.BasePoint);ShortCurve.prototype.jpoint=function jpoint(x,y,z){return new JPoint(this,x,y,z)};JPoint.prototype.toP=function toP(){if(this.isInfinity())return this.curve.point(null,null);var zinv=this.z.redInvm();var zinv2=zinv.redSqr();var ax=this.x.redMul(zinv2);var ay=this.y.redMul(zinv2).redMul(zinv);return this.curve.point(ax,ay)};JPoint.prototype.neg=function neg(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)};JPoint.prototype.add=function add(p){if(this.isInfinity())return p;if(p.isInfinity())return this;var pz2=p.z.redSqr();var z2=this.z.redSqr();var u1=this.x.redMul(pz2);var u2=p.x.redMul(z2);var s1=this.y.redMul(pz2.redMul(p.z));var s2=p.y.redMul(z2.redMul(this.z));var h=u1.redSub(u2);var r=s1.redSub(s2);if(h.cmpn(0)===0){if(r.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl()}var h2=h.redSqr();var h3=h2.redMul(h);var v=u1.redMul(h2);var nx=r.redSqr().redIAdd(h3).redISub(v).redISub(v);var ny=r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));var nz=this.z.redMul(p.z).redMul(h);return this.curve.jpoint(nx,ny,nz)};JPoint.prototype.mixedAdd=function mixedAdd(p){if(this.isInfinity())return p.toJ();if(p.isInfinity())return this;var z2=this.z.redSqr();var u1=this.x;var u2=p.x.redMul(z2);var s1=this.y;var s2=p.y.redMul(z2).redMul(this.z);var h=u1.redSub(u2);var r=s1.redSub(s2);if(h.cmpn(0)===0){if(r.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl()}var h2=h.redSqr();var h3=h2.redMul(h);var v=u1.redMul(h2);var nx=r.redSqr().redIAdd(h3).redISub(v).redISub(v);var ny=r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));var nz=this.z.redMul(h);return this.curve.jpoint(nx,ny,nz)};JPoint.prototype.dblp=function dblp(pow){if(pow===0)return this;if(this.isInfinity())return this;if(!pow)return this.dbl();if(this.curve.zeroA||this.curve.threeA){var r=this;for(var i=0;i=0)return false;rx.redIAdd(t);if(this.x.cmp(rx)===0)return true}};JPoint.prototype.inspect=function inspect(){if(this.isInfinity())return"";return""};JPoint.prototype.isInfinity=function isInfinity(){return this.z.cmpn(0)===0}},{"../utils":85,"./base":72,"bn.js":62,inherits:101}],77:[function(require,module,exports){"use strict";var curves=exports;var hash=require("hash.js");var curve=require("./curve");var utils=require("./utils");var assert=utils.assert;function PresetCurve(options){if(options.type==="short")this.curve=new curve.short(options);else if(options.type==="edwards")this.curve=new curve.edwards(options);else this.curve=new curve.mont(options);this.g=this.curve.g;this.n=this.curve.n;this.hash=options.hash;assert(this.g.validate(),"Invalid curve");assert(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}curves.PresetCurve=PresetCurve;function defineCurve(name,options){Object.defineProperty(curves,name,{configurable:true,enumerable:true,get:function(){var curve=new PresetCurve(options);Object.defineProperty(curves,name,{configurable:true,enumerable:true,value:curve});return curve}})}defineCurve("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:hash.sha256,gRed:false,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]});defineCurve("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:hash.sha256,gRed:false,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]});defineCurve("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:hash.sha256,gRed:false,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]});defineCurve("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f "+"5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 "+"f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:hash.sha384,gRed:false,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 "+"5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 "+"0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]});defineCurve("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b "+"99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd "+"3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 "+"f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:hash.sha512,gRed:false,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 "+"053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 "+"a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 "+"579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 "+"3fad0761 353c7086 a272c240 88be9476 9fd16650"]});defineCurve("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:hash.sha256,gRed:false,g:["9"]});defineCurve("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:hash.sha256,gRed:false,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var pre;try{pre=require("./precomputed/secp256k1")}catch(e){pre=undefined}defineCurve("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:hash.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:false,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",pre]})},{"./curve":74,"./precomputed/secp256k1":84,"./utils":85,"hash.js":87}],78:[function(require,module,exports){"use strict";var BN=require("bn.js");var HmacDRBG=require("hmac-drbg");var utils=require("../utils");var curves=require("../curves");var rand=require("brorand");var assert=utils.assert;var KeyPair=require("./key");var Signature=require("./signature");function EC(options){if(!(this instanceof EC))return new EC(options);if(typeof options==="string"){assert(curves.hasOwnProperty(options),"Unknown curve "+options);options=curves[options]}if(options instanceof curves.PresetCurve)options={curve:options};this.curve=options.curve.curve;this.n=this.curve.n;this.nh=this.n.ushrn(1);this.g=this.curve.g;this.g=options.curve.g;this.g.precompute(options.curve.n.bitLength()+1);this.hash=options.hash||options.curve.hash}module.exports=EC;EC.prototype.keyPair=function keyPair(options){return new KeyPair(this,options)};EC.prototype.keyFromPrivate=function keyFromPrivate(priv,enc){return KeyPair.fromPrivate(this,priv,enc)};EC.prototype.keyFromPublic=function keyFromPublic(pub,enc){return KeyPair.fromPublic(this,pub,enc)};EC.prototype.genKeyPair=function genKeyPair(options){if(!options)options={};var drbg=new HmacDRBG({hash:this.hash,pers:options.pers,persEnc:options.persEnc||"utf8",entropy:options.entropy||rand(this.hash.hmacStrength),entropyEnc:options.entropy&&options.entropyEnc||"utf8",nonce:this.n.toArray()});var bytes=this.n.byteLength();var ns2=this.n.sub(new BN(2));do{var priv=new BN(drbg.generate(bytes));if(priv.cmp(ns2)>0)continue;priv.iaddn(1);return this.keyFromPrivate(priv)}while(true)};EC.prototype._truncateToN=function truncateToN(msg,truncOnly){var delta=msg.byteLength()*8-this.n.bitLength();if(delta>0)msg=msg.ushrn(delta);if(!truncOnly&&msg.cmp(this.n)>=0)return msg.sub(this.n);else return msg};EC.prototype.sign=function sign(msg,key,enc,options){if(typeof enc==="object"){options=enc;enc=null}if(!options)options={};key=this.keyFromPrivate(key,enc);msg=this._truncateToN(new BN(msg,16));var bytes=this.n.byteLength();var bkey=key.getPrivate().toArray("be",bytes);var nonce=msg.toArray("be",bytes);var drbg=new HmacDRBG({hash:this.hash,entropy:bkey,nonce:nonce,pers:options.pers,persEnc:options.persEnc||"utf8"});var ns1=this.n.sub(new BN(1));for(var iter=0;true;iter++){var k=options.k?options.k(iter):new BN(drbg.generate(this.n.byteLength()));k=this._truncateToN(k,true);if(k.cmpn(1)<=0||k.cmp(ns1)>=0)continue;var kp=this.g.mul(k);if(kp.isInfinity())continue;var kpX=kp.getX();var r=kpX.umod(this.n);if(r.cmpn(0)===0)continue;var s=k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));s=s.umod(this.n);if(s.cmpn(0)===0)continue;var recoveryParam=(kp.getY().isOdd()?1:0)|(kpX.cmp(r)!==0?2:0);if(options.canonical&&s.cmp(this.nh)>0){s=this.n.sub(s);recoveryParam^=1}return new Signature({r:r,s:s,recoveryParam:recoveryParam})}};EC.prototype.verify=function verify(msg,signature,key,enc){msg=this._truncateToN(new BN(msg,16));key=this.keyFromPublic(key,enc);signature=new Signature(signature,"hex");var r=signature.r;var s=signature.s;if(r.cmpn(1)<0||r.cmp(this.n)>=0)return false;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return false;var sinv=s.invm(this.n);var u1=sinv.mul(msg).umod(this.n);var u2=sinv.mul(r).umod(this.n);if(!this.curve._maxwellTrick){var p=this.g.mulAdd(u1,key.getPublic(),u2);if(p.isInfinity())return false;return p.getX().umod(this.n).cmp(r)===0}var p=this.g.jmulAdd(u1,key.getPublic(),u2);if(p.isInfinity())return false;return p.eqXToP(r)};EC.prototype.recoverPubKey=function(msg,signature,j,enc){assert((3&j)===j,"The recovery param is more than two bits");signature=new Signature(signature,enc);var n=this.n;var e=new BN(msg);var r=signature.r;var s=signature.s;var isYOdd=j&1;var isSecondKey=j>>1;if(r.cmp(this.curve.p.umod(this.curve.n))>=0&&isSecondKey)throw new Error("Unable to find sencond key candinate");if(isSecondKey)r=this.curve.pointFromX(r.add(this.curve.n),isYOdd);else r=this.curve.pointFromX(r,isYOdd);var rInv=signature.r.invm(n);var s1=n.sub(e).mul(rInv).umod(n);var s2=s.mul(rInv).umod(n);return this.g.mulAdd(s1,r,s2)};EC.prototype.getKeyRecoveryParam=function(e,signature,Q,enc){signature=new Signature(signature,enc);if(signature.recoveryParam!==null)return signature.recoveryParam;for(var i=0;i<4;i++){var Qprime;try{Qprime=this.recoverPubKey(e,signature,i)}catch(e){continue}if(Qprime.eq(Q))return i}throw new Error("Unable to find valid recovery factor")}},{"../curves":77,"../utils":85,"./key":79,"./signature":80,"bn.js":62,brorand:63,"hmac-drbg":100}],79:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var assert=utils.assert;function KeyPair(ec,options){this.ec=ec;this.priv=null;this.pub=null;if(options.priv)this._importPrivate(options.priv,options.privEnc);if(options.pub)this._importPublic(options.pub,options.pubEnc)}module.exports=KeyPair;KeyPair.fromPublic=function fromPublic(ec,pub,enc){if(pub instanceof KeyPair)return pub;return new KeyPair(ec,{pub:pub,pubEnc:enc})};KeyPair.fromPrivate=function fromPrivate(ec,priv,enc){if(priv instanceof KeyPair)return priv;return new KeyPair(ec,{priv:priv,privEnc:enc})};KeyPair.prototype.validate=function validate(){var pub=this.getPublic();if(pub.isInfinity())return{result:false,reason:"Invalid public key"};if(!pub.validate())return{result:false,reason:"Public key is not a point"};if(!pub.mul(this.ec.curve.n).isInfinity())return{result:false,reason:"Public key * N != O"};return{result:true,reason:null}};KeyPair.prototype.getPublic=function getPublic(compact,enc){if(typeof compact==="string"){enc=compact;compact=null}if(!this.pub)this.pub=this.ec.g.mul(this.priv);if(!enc)return this.pub;return this.pub.encode(enc,compact)};KeyPair.prototype.getPrivate=function getPrivate(enc){if(enc==="hex")return this.priv.toString(16,2);else return this.priv};KeyPair.prototype._importPrivate=function _importPrivate(key,enc){this.priv=new BN(key,enc||16);this.priv=this.priv.umod(this.ec.curve.n)};KeyPair.prototype._importPublic=function _importPublic(key,enc){if(key.x||key.y){if(this.ec.curve.type==="mont"){assert(key.x,"Need x coordinate")}else if(this.ec.curve.type==="short"||this.ec.curve.type==="edwards"){assert(key.x&&key.y,"Need both x and y coordinate")}this.pub=this.ec.curve.point(key.x,key.y);return}this.pub=this.ec.curve.decodePoint(key,enc)};KeyPair.prototype.derive=function derive(pub){return pub.mul(this.priv).getX()};KeyPair.prototype.sign=function sign(msg,enc,options){return this.ec.sign(msg,this,enc,options)};KeyPair.prototype.verify=function verify(msg,signature){return this.ec.verify(msg,signature,this)};KeyPair.prototype.inspect=function inspect(){return""}},{"../utils":85,"bn.js":62}],80:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var assert=utils.assert;function Signature(options,enc){if(options instanceof Signature)return options;if(this._importDER(options,enc))return;assert(options.r&&options.s,"Signature without r or s");this.r=new BN(options.r,16);this.s=new BN(options.s,16);if(options.recoveryParam===undefined)this.recoveryParam=null;else this.recoveryParam=options.recoveryParam}module.exports=Signature;function Position(){this.place=0}function getLength(buf,p){var initial=buf[p.place++];if(!(initial&128)){return initial}var octetLen=initial&15;if(octetLen===0||octetLen>4){return false}var val=0;for(var i=0,off=p.place;i>>=0}if(val<=127){return false}p.place=off;return val}function rmPadding(buf){var i=0;var len=buf.length-1;while(!buf[i]&&!(buf[i+1]&128)&&i>>3);arr.push(octets|128);while(--octets){arr.push(len>>>(octets<<3)&255)}arr.push(len)}Signature.prototype.toDER=function toDER(enc){var r=this.r.toArray();var s=this.s.toArray();if(r[0]&128)r=[0].concat(r);if(s[0]&128)s=[0].concat(s);r=rmPadding(r);s=rmPadding(s);while(!s[0]&&!(s[1]&128)){s=s.slice(1)}var arr=[2];constructLength(arr,r.length);arr=arr.concat(r);arr.push(2);constructLength(arr,s.length);var backHalf=arr.concat(s);var res=[48];constructLength(res,backHalf.length);res=res.concat(backHalf);return utils.encode(res,enc)}},{"../utils":85,"bn.js":62}],81:[function(require,module,exports){"use strict";var hash=require("hash.js");var curves=require("../curves");var utils=require("../utils");var assert=utils.assert;var parseBytes=utils.parseBytes;var KeyPair=require("./key");var Signature=require("./signature");function EDDSA(curve){assert(curve==="ed25519","only tested with ed25519 so far");if(!(this instanceof EDDSA))return new EDDSA(curve);var curve=curves[curve].curve;this.curve=curve;this.g=curve.g;this.g.precompute(curve.n.bitLength()+1);this.pointClass=curve.point().constructor;this.encodingLength=Math.ceil(curve.n.bitLength()/8);this.hash=hash.sha512}module.exports=EDDSA;EDDSA.prototype.sign=function sign(message,secret){message=parseBytes(message);var key=this.keyFromSecret(secret);var r=this.hashInt(key.messagePrefix(),message);var R=this.g.mul(r);var Rencoded=this.encodePoint(R);var s_=this.hashInt(Rencoded,key.pubBytes(),message).mul(key.priv());var S=r.add(s_).umod(this.curve.n);return this.makeSignature({R:R,S:S,Rencoded:Rencoded})};EDDSA.prototype.verify=function verify(message,sig,pub){message=parseBytes(message);sig=this.makeSignature(sig);var key=this.keyFromPublic(pub);var h=this.hashInt(sig.Rencoded(),key.pubBytes(),message);var SG=this.g.mul(sig.S());var RplusAh=sig.R().add(key.pub().mul(h));return RplusAh.eq(SG)};EDDSA.prototype.hashInt=function hashInt(){var hash=this.hash();for(var i=0;i(ws>>1)-1)z=(ws>>1)-mod;else z=mod;k.isubn(z)}else{z=0}naf[i]=z;k.iushrn(1)}return naf}utils.getNAF=getNAF;function getJSF(k1,k2){var jsf=[[],[]];k1=k1.clone();k2=k2.clone();var d1=0;var d2=0;while(k1.cmpn(-d1)>0||k2.cmpn(-d2)>0){var m14=k1.andln(3)+d1&3;var m24=k2.andln(3)+d2&3;if(m14===3)m14=-1;if(m24===3)m24=-1;var u1;if((m14&1)===0){u1=0}else{var m8=k1.andln(7)+d1&7;if((m8===3||m8===5)&&m24===2)u1=-m14;else u1=m14}jsf[0].push(u1);var u2;if((m24&1)===0){u2=0}else{var m8=k2.andln(7)+d2&7;if((m8===3||m8===5)&&m14===2)u2=-m24;else u2=m24}jsf[1].push(u2);if(2*d1===u1+1)d1=1-d1;if(2*d2===u2+1)d2=1-d2;k1.iushrn(1);k2.iushrn(1)}return jsf}utils.getJSF=getJSF;function cachedProperty(obj,name,computer){var key="_"+name;obj.prototype[name]=function cachedProperty(){return this[key]!==undefined?this[key]:this[key]=computer.call(this)}}utils.cachedProperty=cachedProperty;function parseBytes(bytes){return typeof bytes==="string"?utils.toArray(bytes,"hex"):bytes}utils.parseBytes=parseBytes;function intFromLE(bytes){return new BN(bytes,"hex","le")}utils.intFromLE=intFromLE},{"bn.js":62,"minimalistic-assert":104,"minimalistic-crypto-utils":105}],86:[function(require,module,exports){module.exports={name:"elliptic",version:"6.5.3",description:"EC cryptography",main:"lib/elliptic.js",files:["lib"],scripts:{jscs:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",jshint:"jscs benchmarks/*.js lib/*.js lib/**/*.js lib/**/**/*.js test/index.js",lint:"npm run jscs && npm run jshint",unit:"istanbul test _mocha --reporter=spec test/index.js",test:"npm run lint && npm run unit",version:"grunt dist && git add dist/"},repository:{type:"git",url:"git@github.com:indutny/elliptic"},keywords:["EC","Elliptic","curve","Cryptography"],author:"Fedor Indutny ",license:"MIT",bugs:{url:"https://github.com/indutny/elliptic/issues"},homepage:"https://github.com/indutny/elliptic",devDependencies:{brfs:"^1.4.3",coveralls:"^3.0.8",grunt:"^1.0.4","grunt-browserify":"^5.0.0","grunt-cli":"^1.2.0","grunt-contrib-connect":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^1.0.1","grunt-mocha-istanbul":"^3.0.1","grunt-saucelabs":"^9.0.1",istanbul:"^0.4.2",jscs:"^3.0.7",jshint:"^2.10.3",mocha:"^6.2.2"},dependencies:{"bn.js":"^4.4.0",brorand:"^1.0.1","hash.js":"^1.0.0","hmac-drbg":"^1.0.0",inherits:"^2.0.1","minimalistic-assert":"^1.0.0","minimalistic-crypto-utils":"^1.0.0"}}},{}],87:[function(require,module,exports){var hash=exports;hash.utils=require("./hash/utils");hash.common=require("./hash/common");hash.sha=require("./hash/sha");hash.ripemd=require("./hash/ripemd");hash.hmac=require("./hash/hmac");hash.sha1=hash.sha.sha1;hash.sha256=hash.sha.sha256;hash.sha224=hash.sha.sha224;hash.sha384=hash.sha.sha384;hash.sha512=hash.sha.sha512;hash.ripemd160=hash.ripemd.ripemd160},{"./hash/common":88,"./hash/hmac":89,"./hash/ripemd":90,"./hash/sha":91,"./hash/utils":98}],88:[function(require,module,exports){"use strict";var utils=require("./utils");var assert=require("minimalistic-assert");function BlockHash(){this.pending=null;this.pendingTotal=0;this.blockSize=this.constructor.blockSize;this.outSize=this.constructor.outSize;this.hmacStrength=this.constructor.hmacStrength;this.padLength=this.constructor.padLength/8;this.endian="big";this._delta8=this.blockSize/8;this._delta32=this.blockSize/32}exports.BlockHash=BlockHash;BlockHash.prototype.update=function update(msg,enc){msg=utils.toArray(msg,enc);if(!this.pending)this.pending=msg;else this.pending=this.pending.concat(msg);this.pendingTotal+=msg.length;if(this.pending.length>=this._delta8){msg=this.pending;var r=msg.length%this._delta8;this.pending=msg.slice(msg.length-r,msg.length);if(this.pending.length===0)this.pending=null;msg=utils.join32(msg,0,msg.length-r,this.endian);for(var i=0;i>>24&255;res[i++]=len>>>16&255;res[i++]=len>>>8&255;res[i++]=len&255}else{res[i++]=len&255;res[i++]=len>>>8&255;res[i++]=len>>>16&255;res[i++]=len>>>24&255;res[i++]=0;res[i++]=0;res[i++]=0;res[i++]=0;for(t=8;tthis.blockSize)key=(new this.Hash).update(key).digest();assert(key.length<=this.blockSize);for(var i=key.length;i>>3}exports.g0_256=g0_256;function g1_256(x){return rotr32(x,17)^rotr32(x,19)^x>>>10}exports.g1_256=g1_256},{"../utils":98}],98:[function(require,module,exports){"use strict";var assert=require("minimalistic-assert");var inherits=require("inherits");exports.inherits=inherits;function isSurrogatePair(msg,i){if((msg.charCodeAt(i)&64512)!==55296){return false}if(i<0||i+1>=msg.length){return false}return(msg.charCodeAt(i+1)&64512)===56320}function toArray(msg,enc){if(Array.isArray(msg))return msg.slice();if(!msg)return[];var res=[];if(typeof msg==="string"){if(!enc){var p=0;for(var i=0;i>6|192;res[p++]=c&63|128}else if(isSurrogatePair(msg,i)){c=65536+((c&1023)<<10)+(msg.charCodeAt(++i)&1023);res[p++]=c>>18|240;res[p++]=c>>12&63|128;res[p++]=c>>6&63|128;res[p++]=c&63|128}else{res[p++]=c>>12|224;res[p++]=c>>6&63|128;res[p++]=c&63|128}}}else if(enc==="hex"){msg=msg.replace(/[^a-z0-9]+/gi,"");if(msg.length%2!==0)msg="0"+msg;for(i=0;i>>24|w>>>8&65280|w<<8&16711680|(w&255)<<24;return res>>>0}exports.htonl=htonl;function toHex32(msg,endian){var res="";for(var i=0;i>>0}return res}exports.join32=join32;function split32(msg,endian){var res=new Array(msg.length*4);for(var i=0,k=0;i>>24;res[k+1]=m>>>16&255;res[k+2]=m>>>8&255;res[k+3]=m&255}else{res[k+3]=m>>>24;res[k+2]=m>>>16&255;res[k+1]=m>>>8&255;res[k]=m&255}}return res}exports.split32=split32;function rotr32(w,b){return w>>>b|w<<32-b}exports.rotr32=rotr32;function rotl32(w,b){return w<>>32-b}exports.rotl32=rotl32;function sum32(a,b){return a+b>>>0}exports.sum32=sum32;function sum32_3(a,b,c){return a+b+c>>>0}exports.sum32_3=sum32_3;function sum32_4(a,b,c,d){return a+b+c+d>>>0}exports.sum32_4=sum32_4;function sum32_5(a,b,c,d,e){return a+b+c+d+e>>>0}exports.sum32_5=sum32_5;function sum64(buf,pos,ah,al){var bh=buf[pos];var bl=buf[pos+1];var lo=al+bl>>>0;var hi=(lo>>0;buf[pos+1]=lo}exports.sum64=sum64;function sum64_hi(ah,al,bh,bl){var lo=al+bl>>>0;var hi=(lo>>0}exports.sum64_hi=sum64_hi;function sum64_lo(ah,al,bh,bl){var lo=al+bl;return lo>>>0}exports.sum64_lo=sum64_lo;function sum64_4_hi(ah,al,bh,bl,ch,cl,dh,dl){var carry=0;var lo=al;lo=lo+bl>>>0;carry+=lo>>0;carry+=lo>>0;carry+=lo>>0}exports.sum64_4_hi=sum64_4_hi;function sum64_4_lo(ah,al,bh,bl,ch,cl,dh,dl){var lo=al+bl+cl+dl;return lo>>>0}exports.sum64_4_lo=sum64_4_lo;function sum64_5_hi(ah,al,bh,bl,ch,cl,dh,dl,eh,el){var carry=0;var lo=al;lo=lo+bl>>>0;carry+=lo>>0;carry+=lo>>0;carry+=lo>>0;carry+=lo>>0}exports.sum64_5_hi=sum64_5_hi;function sum64_5_lo(ah,al,bh,bl,ch,cl,dh,dl,eh,el){var lo=al+bl+cl+dl+el;return lo>>>0}exports.sum64_5_lo=sum64_5_lo;function rotr64_hi(ah,al,num){var r=al<<32-num|ah>>>num;return r>>>0}exports.rotr64_hi=rotr64_hi;function rotr64_lo(ah,al,num){var r=ah<<32-num|al>>>num;return r>>>0}exports.rotr64_lo=rotr64_lo;function shr64_hi(ah,al,num){return ah>>>num}exports.shr64_hi=shr64_hi;function shr64_lo(ah,al,num){var r=ah<<32-num|al>>>num;return r>>>0}exports.shr64_lo=shr64_lo},{inherits:99,"minimalistic-assert":104}],99:[function(require,module,exports){if(typeof Object.create==="function"){module.exports=function inherits(ctor,superCtor){if(superCtor){ctor.super_=superCtor;ctor.prototype=Object.create(superCtor.prototype,{constructor:{value:ctor,enumerable:false,writable:true,configurable:true}})}}}else{module.exports=function inherits(ctor,superCtor){if(superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}}}},{}],100:[function(require,module,exports){"use strict";var hash=require("hash.js");var utils=require("minimalistic-crypto-utils");var assert=require("minimalistic-assert");function HmacDRBG(options){if(!(this instanceof HmacDRBG))return new HmacDRBG(options);this.hash=options.hash;this.predResist=!!options.predResist;this.outLen=this.hash.outSize;this.minEntropy=options.minEntropy||this.hash.hmacStrength;this._reseed=null;this.reseedInterval=null;this.K=null;this.V=null;var entropy=utils.toArray(options.entropy,options.entropyEnc||"hex");var nonce=utils.toArray(options.nonce,options.nonceEnc||"hex");var pers=utils.toArray(options.pers,options.persEnc||"hex");assert(entropy.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits");this._init(entropy,nonce,pers)}module.exports=HmacDRBG;HmacDRBG.prototype._init=function init(entropy,nonce,pers){var seed=entropy.concat(nonce).concat(pers);this.K=new Array(this.outLen/8);this.V=new Array(this.outLen/8);for(var i=0;i=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits");this._update(entropy.concat(add||[]));this._reseed=1};HmacDRBG.prototype.generate=function generate(len,enc,add,addEnc){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");if(typeof enc!=="string"){addEnc=add;add=enc;enc=null}if(add){add=utils.toArray(add,addEnc||"hex");this._update(add)}var temp=[];while(temp.length>2]|=message[index]<>2]|=code<>2]|=(192|code>>6)<>2]|=(128|code&63)<=57344){blocks[i>>2]|=(224|code>>12)<>2]|=(128|code>>6&63)<>2]|=(128|code&63)<>2]|=(240|code>>18)<>2]|=(128|code>>12&63)<>2]|=(128|code>>6&63)<>2]|=(128|code&63)<=64){this.block=blocks[16];this.start=i-64;this.hash();this.hashed=true}else{this.start=i}}if(this.bytes>4294967295){this.hBytes+=this.bytes/4294967296<<0;this.bytes=this.bytes%4294967296}return this};Sha256.prototype.finalize=function(){if(this.finalized){return}this.finalized=true;var blocks=this.blocks,i=this.lastByteIndex;blocks[16]=this.block;blocks[i>>2]|=EXTRA[i&3];this.block=blocks[16];if(i>=56){if(!this.hashed){this.hash()}blocks[0]=this.block;blocks[16]=blocks[1]=blocks[2]=blocks[3]=blocks[4]=blocks[5]=blocks[6]=blocks[7]=blocks[8]=blocks[9]=blocks[10]=blocks[11]=blocks[12]=blocks[13]=blocks[14]=blocks[15]=0}blocks[14]=this.hBytes<<3|this.bytes>>>29;blocks[15]=this.bytes<<3;this.hash()};Sha256.prototype.hash=function(){var a=this.h0,b=this.h1,c=this.h2,d=this.h3,e=this.h4,f=this.h5,g=this.h6,h=this.h7,blocks=this.blocks,j,s0,s1,maj,t1,t2,ch,ab,da,cd,bc;for(j=16;j<64;++j){t1=blocks[j-15];s0=(t1>>>7|t1<<25)^(t1>>>18|t1<<14)^t1>>>3;t1=blocks[j-2];s1=(t1>>>17|t1<<15)^(t1>>>19|t1<<13)^t1>>>10;blocks[j]=blocks[j-16]+s0+blocks[j-7]+s1<<0}bc=b&c;for(j=0;j<64;j+=4){if(this.first){if(this.is224){ab=300032;t1=blocks[0]-1413257819;h=t1-150054599<<0;d=t1+24177077<<0}else{ab=704751109;t1=blocks[0]-210244248;h=t1-1521486534<<0;d=t1+143694565<<0}this.first=false}else{s0=(a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10);s1=(e>>>6|e<<26)^(e>>>11|e<<21)^(e>>>25|e<<7);ab=a&b;maj=ab^a&c^bc;ch=e&f^~e&g;t1=h+s1+ch+K[j]+blocks[j];t2=s0+maj;h=d+t1<<0;d=t1+t2<<0}s0=(d>>>2|d<<30)^(d>>>13|d<<19)^(d>>>22|d<<10);s1=(h>>>6|h<<26)^(h>>>11|h<<21)^(h>>>25|h<<7);da=d&a;maj=da^d&b^ab;ch=h&e^~h&f;t1=g+s1+ch+K[j+1]+blocks[j+1];t2=s0+maj;g=c+t1<<0;c=t1+t2<<0;s0=(c>>>2|c<<30)^(c>>>13|c<<19)^(c>>>22|c<<10);s1=(g>>>6|g<<26)^(g>>>11|g<<21)^(g>>>25|g<<7);cd=c&d;maj=cd^c&a^da;ch=g&h^~g&e;t1=f+s1+ch+K[j+2]+blocks[j+2];t2=s0+maj;f=b+t1<<0;b=t1+t2<<0;s0=(b>>>2|b<<30)^(b>>>13|b<<19)^(b>>>22|b<<10);s1=(f>>>6|f<<26)^(f>>>11|f<<21)^(f>>>25|f<<7);bc=b&c;maj=bc^b&d^cd;ch=f&g^~f&h;t1=e+s1+ch+K[j+3]+blocks[j+3];t2=s0+maj;e=a+t1<<0;a=t1+t2<<0}this.h0=this.h0+a<<0;this.h1=this.h1+b<<0;this.h2=this.h2+c<<0;this.h3=this.h3+d<<0;this.h4=this.h4+e<<0;this.h5=this.h5+f<<0;this.h6=this.h6+g<<0;this.h7=this.h7+h<<0};Sha256.prototype.hex=function(){this.finalize();var h0=this.h0,h1=this.h1,h2=this.h2,h3=this.h3,h4=this.h4,h5=this.h5,h6=this.h6,h7=this.h7;var hex=HEX_CHARS[h0>>28&15]+HEX_CHARS[h0>>24&15]+HEX_CHARS[h0>>20&15]+HEX_CHARS[h0>>16&15]+HEX_CHARS[h0>>12&15]+HEX_CHARS[h0>>8&15]+HEX_CHARS[h0>>4&15]+HEX_CHARS[h0&15]+HEX_CHARS[h1>>28&15]+HEX_CHARS[h1>>24&15]+HEX_CHARS[h1>>20&15]+HEX_CHARS[h1>>16&15]+HEX_CHARS[h1>>12&15]+HEX_CHARS[h1>>8&15]+HEX_CHARS[h1>>4&15]+HEX_CHARS[h1&15]+HEX_CHARS[h2>>28&15]+HEX_CHARS[h2>>24&15]+HEX_CHARS[h2>>20&15]+HEX_CHARS[h2>>16&15]+HEX_CHARS[h2>>12&15]+HEX_CHARS[h2>>8&15]+HEX_CHARS[h2>>4&15]+HEX_CHARS[h2&15]+HEX_CHARS[h3>>28&15]+HEX_CHARS[h3>>24&15]+HEX_CHARS[h3>>20&15]+HEX_CHARS[h3>>16&15]+HEX_CHARS[h3>>12&15]+HEX_CHARS[h3>>8&15]+HEX_CHARS[h3>>4&15]+HEX_CHARS[h3&15]+HEX_CHARS[h4>>28&15]+HEX_CHARS[h4>>24&15]+HEX_CHARS[h4>>20&15]+HEX_CHARS[h4>>16&15]+HEX_CHARS[h4>>12&15]+HEX_CHARS[h4>>8&15]+HEX_CHARS[h4>>4&15]+HEX_CHARS[h4&15]+HEX_CHARS[h5>>28&15]+HEX_CHARS[h5>>24&15]+HEX_CHARS[h5>>20&15]+HEX_CHARS[h5>>16&15]+HEX_CHARS[h5>>12&15]+HEX_CHARS[h5>>8&15]+HEX_CHARS[h5>>4&15]+HEX_CHARS[h5&15]+HEX_CHARS[h6>>28&15]+HEX_CHARS[h6>>24&15]+HEX_CHARS[h6>>20&15]+HEX_CHARS[h6>>16&15]+HEX_CHARS[h6>>12&15]+HEX_CHARS[h6>>8&15]+HEX_CHARS[h6>>4&15]+HEX_CHARS[h6&15];if(!this.is224){hex+=HEX_CHARS[h7>>28&15]+HEX_CHARS[h7>>24&15]+HEX_CHARS[h7>>20&15]+HEX_CHARS[h7>>16&15]+HEX_CHARS[h7>>12&15]+HEX_CHARS[h7>>8&15]+HEX_CHARS[h7>>4&15]+HEX_CHARS[h7&15]}return hex};Sha256.prototype.toString=Sha256.prototype.hex;Sha256.prototype.digest=function(){this.finalize();var h0=this.h0,h1=this.h1,h2=this.h2,h3=this.h3,h4=this.h4,h5=this.h5,h6=this.h6,h7=this.h7;var arr=[h0>>24&255,h0>>16&255,h0>>8&255,h0&255,h1>>24&255,h1>>16&255,h1>>8&255,h1&255,h2>>24&255,h2>>16&255,h2>>8&255,h2&255,h3>>24&255,h3>>16&255,h3>>8&255,h3&255,h4>>24&255,h4>>16&255,h4>>8&255,h4&255,h5>>24&255,h5>>16&255,h5>>8&255,h5&255,h6>>24&255,h6>>16&255,h6>>8&255,h6&255];if(!this.is224){arr.push(h7>>24&255,h7>>16&255,h7>>8&255,h7&255)}return arr};Sha256.prototype.array=Sha256.prototype.digest;Sha256.prototype.arrayBuffer=function(){this.finalize();var buffer=new ArrayBuffer(this.is224?28:32);var dataView=new DataView(buffer);dataView.setUint32(0,this.h0);dataView.setUint32(4,this.h1);dataView.setUint32(8,this.h2);dataView.setUint32(12,this.h3);dataView.setUint32(16,this.h4);dataView.setUint32(20,this.h5);dataView.setUint32(24,this.h6);if(!this.is224){dataView.setUint32(28,this.h7)}return buffer};function HmacSha256(key,is224,sharedMemory){var i,type=typeof key;if(type==="string"){var bytes=[],length=key.length,index=0,code;for(i=0;i>6;bytes[index++]=128|code&63}else if(code<55296||code>=57344){bytes[index++]=224|code>>12;bytes[index++]=128|code>>6&63;bytes[index++]=128|code&63}else{code=65536+((code&1023)<<10|key.charCodeAt(++i)&1023);bytes[index++]=240|code>>18;bytes[index++]=128|code>>12&63;bytes[index++]=128|code>>6&63;bytes[index++]=128|code&63}}key=bytes}else{if(type==="object"){if(key===null){throw new Error(ERROR)}else if(ARRAY_BUFFER&&key.constructor===ArrayBuffer){key=new Uint8Array(key)}else if(!Array.isArray(key)){if(!ARRAY_BUFFER||!ArrayBuffer.isView(key)){throw new Error(ERROR)}}}else{throw new Error(ERROR)}}if(key.length>64){key=new Sha256(is224,true).update(key).array()}var oKeyPad=[],iKeyPad=[];for(i=0;i<64;++i){var b=key[i]||0;oKeyPad[i]=92^b;iKeyPad[i]=54^b}Sha256.call(this,is224,sharedMemory);this.update(iKeyPad);this.oKeyPad=oKeyPad;this.inner=true;this.sharedMemory=sharedMemory}HmacSha256.prototype=new Sha256;HmacSha256.prototype.finalize=function(){Sha256.prototype.finalize.call(this);if(this.inner){this.inner=false;var innerHash=this.array();Sha256.call(this,this.is224,this.sharedMemory);this.update(this.oKeyPad);this.update(innerHash);Sha256.prototype.finalize.call(this)}};var exports=createMethod();exports.sha256=exports;exports.sha224=createMethod(true);exports.sha256.hmac=createHmacMethod();exports.sha224.hmac=createHmacMethod(true);if(COMMON_JS){module.exports=exports}else{root.sha256=exports.sha256;root.sha224=exports.sha224;if(AMD){define(function(){return exports})}}})()}).call(this)}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{_process:262}],103:[function(require,module,exports){(function(global){(function(){(function(){var undefined;var VERSION="4.17.20";var LARGE_ARRAY_SIZE=200;var CORE_ERROR_TEXT="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",FUNC_ERROR_TEXT="Expected a function";var HASH_UNDEFINED="__lodash_hash_undefined__";var MAX_MEMOIZE_SIZE=500;var PLACEHOLDER="__lodash_placeholder__";var CLONE_DEEP_FLAG=1,CLONE_FLAT_FLAG=2,CLONE_SYMBOLS_FLAG=4;var COMPARE_PARTIAL_FLAG=1,COMPARE_UNORDERED_FLAG=2;var WRAP_BIND_FLAG=1,WRAP_BIND_KEY_FLAG=2,WRAP_CURRY_BOUND_FLAG=4,WRAP_CURRY_FLAG=8,WRAP_CURRY_RIGHT_FLAG=16,WRAP_PARTIAL_FLAG=32,WRAP_PARTIAL_RIGHT_FLAG=64,WRAP_ARY_FLAG=128,WRAP_REARG_FLAG=256,WRAP_FLIP_FLAG=512;var DEFAULT_TRUNC_LENGTH=30,DEFAULT_TRUNC_OMISSION="...";var HOT_COUNT=800,HOT_SPAN=16;var LAZY_FILTER_FLAG=1,LAZY_MAP_FLAG=2,LAZY_WHILE_FLAG=3;var INFINITY=1/0,MAX_SAFE_INTEGER=9007199254740991,MAX_INTEGER=17976931348623157e292,NAN=0/0;var MAX_ARRAY_LENGTH=4294967295,MAX_ARRAY_INDEX=MAX_ARRAY_LENGTH-1,HALF_MAX_ARRAY_LENGTH=MAX_ARRAY_LENGTH>>>1;var wrapFlags=[["ary",WRAP_ARY_FLAG],["bind",WRAP_BIND_FLAG],["bindKey",WRAP_BIND_KEY_FLAG],["curry",WRAP_CURRY_FLAG],["curryRight",WRAP_CURRY_RIGHT_FLAG],["flip",WRAP_FLIP_FLAG],["partial",WRAP_PARTIAL_FLAG],["partialRight",WRAP_PARTIAL_RIGHT_FLAG],["rearg",WRAP_REARG_FLAG]];var argsTag="[object Arguments]",arrayTag="[object Array]",asyncTag="[object AsyncFunction]",boolTag="[object Boolean]",dateTag="[object Date]",domExcTag="[object DOMException]",errorTag="[object Error]",funcTag="[object Function]",genTag="[object GeneratorFunction]",mapTag="[object Map]",numberTag="[object Number]",nullTag="[object Null]",objectTag="[object Object]",promiseTag="[object Promise]",proxyTag="[object Proxy]",regexpTag="[object RegExp]",setTag="[object Set]",stringTag="[object String]",symbolTag="[object Symbol]",undefinedTag="[object Undefined]",weakMapTag="[object WeakMap]",weakSetTag="[object WeakSet]";var arrayBufferTag="[object ArrayBuffer]",dataViewTag="[object DataView]",float32Tag="[object Float32Array]",float64Tag="[object Float64Array]",int8Tag="[object Int8Array]",int16Tag="[object Int16Array]",int32Tag="[object Int32Array]",uint8Tag="[object Uint8Array]",uint8ClampedTag="[object Uint8ClampedArray]",uint16Tag="[object Uint16Array]",uint32Tag="[object Uint32Array]";var reEmptyStringLeading=/\b__p \+= '';/g,reEmptyStringMiddle=/\b(__p \+=) '' \+/g,reEmptyStringTrailing=/(__e\(.*?\)|\b__t\)) \+\n'';/g;var reEscapedHtml=/&(?:amp|lt|gt|quot|#39);/g,reUnescapedHtml=/[&<>"']/g,reHasEscapedHtml=RegExp(reEscapedHtml.source),reHasUnescapedHtml=RegExp(reUnescapedHtml.source);var reEscape=/<%-([\s\S]+?)%>/g,reEvaluate=/<%([\s\S]+?)%>/g,reInterpolate=/<%=([\s\S]+?)%>/g;var reIsDeepProp=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,reIsPlainProp=/^\w*$/,rePropName=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;var reRegExpChar=/[\\^$.*+?()[\]{}|]/g,reHasRegExpChar=RegExp(reRegExpChar.source);var reTrim=/^\s+|\s+$/g,reTrimStart=/^\s+/,reTrimEnd=/\s+$/;var reWrapComment=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,reWrapDetails=/\{\n\/\* \[wrapped with (.+)\] \*/,reSplitDetails=/,? & /;var reAsciiWord=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;var reEscapeChar=/\\(\\)?/g;var reEsTemplate=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;var reFlags=/\w*$/;var reIsBadHex=/^[-+]0x[0-9a-f]+$/i;var reIsBinary=/^0b[01]+$/i;var reIsHostCtor=/^\[object .+?Constructor\]$/;var reIsOctal=/^0o[0-7]+$/i;var reIsUint=/^(?:0|[1-9]\d*)$/;var reLatin=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;var reNoMatch=/($^)/;var reUnescapedString=/['\n\r\u2028\u2029\\]/g;var rsAstralRange="\\ud800-\\udfff",rsComboMarksRange="\\u0300-\\u036f",reComboHalfMarksRange="\\ufe20-\\ufe2f",rsComboSymbolsRange="\\u20d0-\\u20ff",rsComboRange=rsComboMarksRange+reComboHalfMarksRange+rsComboSymbolsRange,rsDingbatRange="\\u2700-\\u27bf",rsLowerRange="a-z\\xdf-\\xf6\\xf8-\\xff",rsMathOpRange="\\xac\\xb1\\xd7\\xf7",rsNonCharRange="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",rsPunctuationRange="\\u2000-\\u206f",rsSpaceRange=" \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000",rsUpperRange="A-Z\\xc0-\\xd6\\xd8-\\xde",rsVarRange="\\ufe0e\\ufe0f",rsBreakRange=rsMathOpRange+rsNonCharRange+rsPunctuationRange+rsSpaceRange;var rsApos="['’]",rsAstral="["+rsAstralRange+"]",rsBreak="["+rsBreakRange+"]",rsCombo="["+rsComboRange+"]",rsDigits="\\d+",rsDingbat="["+rsDingbatRange+"]",rsLower="["+rsLowerRange+"]",rsMisc="[^"+rsAstralRange+rsBreakRange+rsDigits+rsDingbatRange+rsLowerRange+rsUpperRange+"]",rsFitz="\\ud83c[\\udffb-\\udfff]",rsModifier="(?:"+rsCombo+"|"+rsFitz+")",rsNonAstral="[^"+rsAstralRange+"]",rsRegional="(?:\\ud83c[\\udde6-\\uddff]){2}",rsSurrPair="[\\ud800-\\udbff][\\udc00-\\udfff]",rsUpper="["+rsUpperRange+"]",rsZWJ="\\u200d";var rsMiscLower="(?:"+rsLower+"|"+rsMisc+")",rsMiscUpper="(?:"+rsUpper+"|"+rsMisc+")",rsOptContrLower="(?:"+rsApos+"(?:d|ll|m|re|s|t|ve))?",rsOptContrUpper="(?:"+rsApos+"(?:D|LL|M|RE|S|T|VE))?",reOptMod=rsModifier+"?",rsOptVar="["+rsVarRange+"]?",rsOptJoin="(?:"+rsZWJ+"(?:"+[rsNonAstral,rsRegional,rsSurrPair].join("|")+")"+rsOptVar+reOptMod+")*",rsOrdLower="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",rsOrdUpper="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",rsSeq=rsOptVar+reOptMod+rsOptJoin,rsEmoji="(?:"+[rsDingbat,rsRegional,rsSurrPair].join("|")+")"+rsSeq,rsSymbol="(?:"+[rsNonAstral+rsCombo+"?",rsCombo,rsRegional,rsSurrPair,rsAstral].join("|")+")";var reApos=RegExp(rsApos,"g");var reComboMark=RegExp(rsCombo,"g");var reUnicode=RegExp(rsFitz+"(?="+rsFitz+")|"+rsSymbol+rsSeq,"g");var reUnicodeWord=RegExp([rsUpper+"?"+rsLower+"+"+rsOptContrLower+"(?="+[rsBreak,rsUpper,"$"].join("|")+")",rsMiscUpper+"+"+rsOptContrUpper+"(?="+[rsBreak,rsUpper+rsMiscLower,"$"].join("|")+")",rsUpper+"?"+rsMiscLower+"+"+rsOptContrLower,rsUpper+"+"+rsOptContrUpper,rsOrdUpper,rsOrdLower,rsDigits,rsEmoji].join("|"),"g");var reHasUnicode=RegExp("["+rsZWJ+rsAstralRange+rsComboRange+rsVarRange+"]");var reHasUnicodeWord=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;var contextProps=["Array","Buffer","DataView","Date","Error","Float32Array","Float64Array","Function","Int8Array","Int16Array","Int32Array","Map","Math","Object","Promise","RegExp","Set","String","Symbol","TypeError","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","WeakMap","_","clearTimeout","isFinite","parseInt","setTimeout"];var templateCounter=-1;var typedArrayTags={};typedArrayTags[float32Tag]=typedArrayTags[float64Tag]=typedArrayTags[int8Tag]=typedArrayTags[int16Tag]=typedArrayTags[int32Tag]=typedArrayTags[uint8Tag]=typedArrayTags[uint8ClampedTag]=typedArrayTags[uint16Tag]=typedArrayTags[uint32Tag]=true;typedArrayTags[argsTag]=typedArrayTags[arrayTag]=typedArrayTags[arrayBufferTag]=typedArrayTags[boolTag]=typedArrayTags[dataViewTag]=typedArrayTags[dateTag]=typedArrayTags[errorTag]=typedArrayTags[funcTag]=typedArrayTags[mapTag]=typedArrayTags[numberTag]=typedArrayTags[objectTag]=typedArrayTags[regexpTag]=typedArrayTags[setTag]=typedArrayTags[stringTag]=typedArrayTags[weakMapTag]=false;var cloneableTags={};cloneableTags[argsTag]=cloneableTags[arrayTag]=cloneableTags[arrayBufferTag]=cloneableTags[dataViewTag]=cloneableTags[boolTag]=cloneableTags[dateTag]=cloneableTags[float32Tag]=cloneableTags[float64Tag]=cloneableTags[int8Tag]=cloneableTags[int16Tag]=cloneableTags[int32Tag]=cloneableTags[mapTag]=cloneableTags[numberTag]=cloneableTags[objectTag]=cloneableTags[regexpTag]=cloneableTags[setTag]=cloneableTags[stringTag]=cloneableTags[symbolTag]=cloneableTags[uint8Tag]=cloneableTags[uint8ClampedTag]=cloneableTags[uint16Tag]=cloneableTags[uint32Tag]=true;cloneableTags[errorTag]=cloneableTags[funcTag]=cloneableTags[weakMapTag]=false;var deburredLetters={"À":"A","Á":"A","Â":"A","Ã":"A","Ä":"A","Å":"A","à":"a","á":"a","â":"a","ã":"a","ä":"a","å":"a","Ç":"C","ç":"c","Ð":"D","ð":"d","È":"E","É":"E","Ê":"E","Ë":"E","è":"e","é":"e","ê":"e","ë":"e","Ì":"I","Í":"I","Î":"I","Ï":"I","ì":"i","í":"i","î":"i","ï":"i","Ñ":"N","ñ":"n","Ò":"O","Ó":"O","Ô":"O","Õ":"O","Ö":"O","Ø":"O","ò":"o","ó":"o","ô":"o","õ":"o","ö":"o","ø":"o","Ù":"U","Ú":"U","Û":"U","Ü":"U","ù":"u","ú":"u","û":"u","ü":"u","Ý":"Y","ý":"y","ÿ":"y","Æ":"Ae","æ":"ae","Þ":"Th","þ":"th","ß":"ss","Ā":"A","Ă":"A","Ą":"A","ā":"a","ă":"a","ą":"a","Ć":"C","Ĉ":"C","Ċ":"C","Č":"C","ć":"c","ĉ":"c","ċ":"c","č":"c","Ď":"D","Đ":"D","ď":"d","đ":"d","Ē":"E","Ĕ":"E","Ė":"E","Ę":"E","Ě":"E","ē":"e","ĕ":"e","ė":"e","ę":"e","ě":"e","Ĝ":"G","Ğ":"G","Ġ":"G","Ģ":"G","ĝ":"g","ğ":"g","ġ":"g","ģ":"g","Ĥ":"H","Ħ":"H","ĥ":"h","ħ":"h","Ĩ":"I","Ī":"I","Ĭ":"I","Į":"I","İ":"I","ĩ":"i","ī":"i","ĭ":"i","į":"i","ı":"i","Ĵ":"J","ĵ":"j","Ķ":"K","ķ":"k","ĸ":"k","Ĺ":"L","Ļ":"L","Ľ":"L","Ŀ":"L","Ł":"L","ĺ":"l","ļ":"l","ľ":"l","ŀ":"l","ł":"l","Ń":"N","Ņ":"N","Ň":"N","Ŋ":"N","ń":"n","ņ":"n","ň":"n","ŋ":"n","Ō":"O","Ŏ":"O","Ő":"O","ō":"o","ŏ":"o","ő":"o","Ŕ":"R","Ŗ":"R","Ř":"R","ŕ":"r","ŗ":"r","ř":"r","Ś":"S","Ŝ":"S","Ş":"S","Š":"S","ś":"s","ŝ":"s","ş":"s","š":"s","Ţ":"T","Ť":"T","Ŧ":"T","ţ":"t","ť":"t","ŧ":"t","Ũ":"U","Ū":"U","Ŭ":"U","Ů":"U","Ű":"U","Ų":"U","ũ":"u","ū":"u","ŭ":"u","ů":"u","ű":"u","ų":"u","Ŵ":"W","ŵ":"w","Ŷ":"Y","ŷ":"y","Ÿ":"Y","Ź":"Z","Ż":"Z","Ž":"Z","ź":"z","ż":"z","ž":"z","IJ":"IJ","ij":"ij","Œ":"Oe","œ":"oe","ʼn":"'n","ſ":"s"};var htmlEscapes={"&":"&","<":"<",">":">",'"':""","'":"'"};var htmlUnescapes={"&":"&","<":"<",">":">",""":'"',"'":"'"};var stringEscapes={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"};var freeParseFloat=parseFloat,freeParseInt=parseInt;var freeGlobal=typeof global=="object"&&global&&global.Object===Object&&global;var freeSelf=typeof self=="object"&&self&&self.Object===Object&&self;var root=freeGlobal||freeSelf||Function("return this")();var freeExports=typeof exports=="object"&&exports&&!exports.nodeType&&exports;var freeModule=freeExports&&typeof module=="object"&&module&&!module.nodeType&&module;var moduleExports=freeModule&&freeModule.exports===freeExports;var freeProcess=moduleExports&&freeGlobal.process;var nodeUtil=function(){try{var types=freeModule&&freeModule.require&&freeModule.require("util").types;if(types){return types}return freeProcess&&freeProcess.binding&&freeProcess.binding("util")}catch(e){}}();var nodeIsArrayBuffer=nodeUtil&&nodeUtil.isArrayBuffer,nodeIsDate=nodeUtil&&nodeUtil.isDate,nodeIsMap=nodeUtil&&nodeUtil.isMap,nodeIsRegExp=nodeUtil&&nodeUtil.isRegExp,nodeIsSet=nodeUtil&&nodeUtil.isSet,nodeIsTypedArray=nodeUtil&&nodeUtil.isTypedArray;function apply(func,thisArg,args){switch(args.length){case 0:return func.call(thisArg);case 1:return func.call(thisArg,args[0]);case 2:return func.call(thisArg,args[0],args[1]);case 3:return func.call(thisArg,args[0],args[1],args[2])}return func.apply(thisArg,args)}function arrayAggregator(array,setter,iteratee,accumulator){var index=-1,length=array==null?0:array.length;while(++index-1}function arrayIncludesWith(array,value,comparator){var index=-1,length=array==null?0:array.length;while(++index-1){}return index}function charsEndIndex(strSymbols,chrSymbols){var index=strSymbols.length;while(index--&&baseIndexOf(chrSymbols,strSymbols[index],0)>-1){}return index}function countHolders(array,placeholder){var length=array.length,result=0;while(length--){if(array[length]===placeholder){++result}}return result}var deburrLetter=basePropertyOf(deburredLetters);var escapeHtmlChar=basePropertyOf(htmlEscapes);function escapeStringChar(chr){return"\\"+stringEscapes[chr]}function getValue(object,key){return object==null?undefined:object[key]}function hasUnicode(string){return reHasUnicode.test(string)}function hasUnicodeWord(string){return reHasUnicodeWord.test(string)}function iteratorToArray(iterator){var data,result=[];while(!(data=iterator.next()).done){result.push(data.value)}return result}function mapToArray(map){var index=-1,result=Array(map.size);map.forEach(function(value,key){result[++index]=[key,value]});return result}function overArg(func,transform){return function(arg){return func(transform(arg))}}function replaceHolders(array,placeholder){var index=-1,length=array.length,resIndex=0,result=[];while(++index-1}function listCacheSet(key,value){var data=this.__data__,index=assocIndexOf(data,key);if(index<0){++this.size;data.push([key,value])}else{data[index][1]=value}return this}ListCache.prototype.clear=listCacheClear;ListCache.prototype["delete"]=listCacheDelete;ListCache.prototype.get=listCacheGet;ListCache.prototype.has=listCacheHas;ListCache.prototype.set=listCacheSet;function MapCache(entries){var index=-1,length=entries==null?0:entries.length;this.clear();while(++index=lower?number:lower}}return number}function baseClone(value,bitmask,customizer,key,object,stack){var result,isDeep=bitmask&CLONE_DEEP_FLAG,isFlat=bitmask&CLONE_FLAT_FLAG,isFull=bitmask&CLONE_SYMBOLS_FLAG;if(customizer){result=object?customizer(value,key,object,stack):customizer(value)}if(result!==undefined){return result}if(!isObject(value)){return value}var isArr=isArray(value);if(isArr){result=initCloneArray(value);if(!isDeep){return copyArray(value,result)}}else{var tag=getTag(value),isFunc=tag==funcTag||tag==genTag;if(isBuffer(value)){return cloneBuffer(value,isDeep)}if(tag==objectTag||tag==argsTag||isFunc&&!object){result=isFlat||isFunc?{}:initCloneObject(value);if(!isDeep){return isFlat?copySymbolsIn(value,baseAssignIn(result,value)):copySymbols(value,baseAssign(result,value))}}else{if(!cloneableTags[tag]){return object?value:{}}result=initCloneByTag(value,tag,isDeep)}}stack||(stack=new Stack);var stacked=stack.get(value);if(stacked){return stacked}stack.set(value,result);if(isSet(value)){value.forEach(function(subValue){result.add(baseClone(subValue,bitmask,customizer,subValue,value,stack))})}else if(isMap(value)){value.forEach(function(subValue,key){result.set(key,baseClone(subValue,bitmask,customizer,key,value,stack))})}var keysFunc=isFull?isFlat?getAllKeysIn:getAllKeys:isFlat?keysIn:keys;var props=isArr?undefined:keysFunc(value);arrayEach(props||value,function(subValue,key){if(props){key=subValue;subValue=value[key]}assignValue(result,key,baseClone(subValue,bitmask,customizer,key,value,stack))});return result}function baseConforms(source){var props=keys(source);return function(object){return baseConformsTo(object,source,props)}}function baseConformsTo(object,source,props){var length=props.length;if(object==null){return!length}object=Object(object);while(length--){var key=props[length],predicate=source[key],value=object[key];if(value===undefined&&!(key in object)||!predicate(value)){return false}}return true}function baseDelay(func,wait,args){if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}return setTimeout(function(){func.apply(undefined,args)},wait)}function baseDifference(array,values,iteratee,comparator){var index=-1,includes=arrayIncludes,isCommon=true,length=array.length,result=[],valuesLength=values.length;if(!length){return result}if(iteratee){values=arrayMap(values,baseUnary(iteratee))}if(comparator){includes=arrayIncludesWith;isCommon=false}else if(values.length>=LARGE_ARRAY_SIZE){includes=cacheHas;isCommon=false;values=new SetCache(values)}outer:while(++indexlength?0:length+start}end=end===undefined||end>length?length:toInteger(end);if(end<0){end+=length}end=start>end?0:toLength(end);while(start0&&predicate(value)){if(depth>1){baseFlatten(value,depth-1,predicate,isStrict,result)}else{arrayPush(result,value)}}else if(!isStrict){result[result.length]=value}}return result}var baseFor=createBaseFor();var baseForRight=createBaseFor(true);function baseForOwn(object,iteratee){return object&&baseFor(object,iteratee,keys)}function baseForOwnRight(object,iteratee){return object&&baseForRight(object,iteratee,keys)}function baseFunctions(object,props){return arrayFilter(props,function(key){return isFunction(object[key])})}function baseGet(object,path){path=castPath(path,object);var index=0,length=path.length;while(object!=null&&indexother}function baseHas(object,key){return object!=null&&hasOwnProperty.call(object,key)}function baseHasIn(object,key){return object!=null&&key in Object(object)}function baseInRange(number,start,end){return number>=nativeMin(start,end)&&number=120&&array.length>=120)?new SetCache(othIndex&&array):undefined}array=arrays[0];var index=-1,seen=caches[0];outer:while(++index-1){if(seen!==array){splice.call(seen,fromIndex,1)}splice.call(array,fromIndex,1)}}return array}function basePullAt(array,indexes){var length=array?indexes.length:0,lastIndex=length-1;while(length--){var index=indexes[length];if(length==lastIndex||index!==previous){var previous=index;if(isIndex(index)){splice.call(array,index,1)}else{baseUnset(array,index)}}}return array}function baseRandom(lower,upper){return lower+nativeFloor(nativeRandom()*(upper-lower+1))}function baseRange(start,end,step,fromRight){var index=-1,length=nativeMax(nativeCeil((end-start)/(step||1)),0),result=Array(length);while(length--){result[fromRight?length:++index]=start;start+=step}return result}function baseRepeat(string,n){var result="";if(!string||n<1||n>MAX_SAFE_INTEGER){return result}do{if(n%2){result+=string}n=nativeFloor(n/2);if(n){string+=string}}while(n);return result}function baseRest(func,start){return setToString(overRest(func,start,identity),func+"")}function baseSample(collection){return arraySample(values(collection))}function baseSampleSize(collection,n){var array=values(collection);return shuffleSelf(array,baseClamp(n,0,array.length))}function baseSet(object,path,value,customizer){if(!isObject(object)){return object}path=castPath(path,object);var index=-1,length=path.length,lastIndex=length-1,nested=object;while(nested!=null&&++indexlength?0:length+start}end=end>length?length:end;if(end<0){end+=length}length=start>end?0:end-start>>>0;start>>>=0;var result=Array(length);while(++index>>1,computed=array[mid];if(computed!==null&&!isSymbol(computed)&&(retHighest?computed<=value:computed=LARGE_ARRAY_SIZE){var set=iteratee?null:createSet(array);if(set){return setToArray(set)}isCommon=false;includes=cacheHas;seen=new SetCache}else{seen=iteratee?[]:result}outer:while(++index=length?array:baseSlice(array,start,end)}var clearTimeout=ctxClearTimeout||function(id){return root.clearTimeout(id)};function cloneBuffer(buffer,isDeep){if(isDeep){return buffer.slice()}var length=buffer.length,result=allocUnsafe?allocUnsafe(length):new buffer.constructor(length);buffer.copy(result);return result}function cloneArrayBuffer(arrayBuffer){var result=new arrayBuffer.constructor(arrayBuffer.byteLength);new Uint8Array(result).set(new Uint8Array(arrayBuffer));return result}function cloneDataView(dataView,isDeep){var buffer=isDeep?cloneArrayBuffer(dataView.buffer):dataView.buffer;return new dataView.constructor(buffer,dataView.byteOffset,dataView.byteLength)}function cloneRegExp(regexp){var result=new regexp.constructor(regexp.source,reFlags.exec(regexp));result.lastIndex=regexp.lastIndex;return result}function cloneSymbol(symbol){return symbolValueOf?Object(symbolValueOf.call(symbol)):{}}function cloneTypedArray(typedArray,isDeep){var buffer=isDeep?cloneArrayBuffer(typedArray.buffer):typedArray.buffer;return new typedArray.constructor(buffer,typedArray.byteOffset,typedArray.length)}function compareAscending(value,other){if(value!==other){var valIsDefined=value!==undefined,valIsNull=value===null,valIsReflexive=value===value,valIsSymbol=isSymbol(value);var othIsDefined=other!==undefined,othIsNull=other===null,othIsReflexive=other===other,othIsSymbol=isSymbol(other);if(!othIsNull&&!othIsSymbol&&!valIsSymbol&&value>other||valIsSymbol&&othIsDefined&&othIsReflexive&&!othIsNull&&!othIsSymbol||valIsNull&&othIsDefined&&othIsReflexive||!valIsDefined&&othIsReflexive||!valIsReflexive){return 1}if(!valIsNull&&!valIsSymbol&&!othIsSymbol&&value=ordersLength){return result}var order=orders[index];return result*(order=="desc"?-1:1)}}return object.index-other.index}function composeArgs(args,partials,holders,isCurried){var argsIndex=-1,argsLength=args.length,holdersLength=holders.length,leftIndex=-1,leftLength=partials.length,rangeLength=nativeMax(argsLength-holdersLength,0),result=Array(leftLength+rangeLength),isUncurried=!isCurried;while(++leftIndex1?sources[length-1]:undefined,guard=length>2?sources[2]:undefined;customizer=assigner.length>3&&typeof customizer=="function"?(length--,customizer):undefined;if(guard&&isIterateeCall(sources[0],sources[1],guard)){customizer=length<3?undefined:customizer;length=1}object=Object(object);while(++index-1?iterable[iteratee?collection[index]:index]:undefined}}function createFlow(fromRight){return flatRest(function(funcs){var length=funcs.length,index=length,prereq=LodashWrapper.prototype.thru;if(fromRight){funcs.reverse()}while(index--){var func=funcs[index];if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}if(prereq&&!wrapper&&getFuncName(func)=="wrapper"){var wrapper=new LodashWrapper([],true)}}index=wrapper?index:length;while(++index1){args.reverse()}if(isAry&&aryarrLength)){return false}var arrStacked=stack.get(array);var othStacked=stack.get(other);if(arrStacked&&othStacked){return arrStacked==other&&othStacked==array}var index=-1,result=true,seen=bitmask&COMPARE_UNORDERED_FLAG?new SetCache:undefined;stack.set(array,other);stack.set(other,array);while(++index1?"& ":"")+details[lastIndex];details=details.join(length>2?", ":" ");return source.replace(reWrapComment,"{\n/* [wrapped with "+details+"] */\n")}function isFlattenable(value){return isArray(value)||isArguments(value)||!!(spreadableSymbol&&value&&value[spreadableSymbol])}function isIndex(value,length){var type=typeof value;length=length==null?MAX_SAFE_INTEGER:length;return!!length&&(type=="number"||type!="symbol"&&reIsUint.test(value))&&(value>-1&&value%1==0&&value0){if(++count>=HOT_COUNT){return arguments[0]}}else{count=0}return func.apply(undefined,arguments)}}function shuffleSelf(array,size){var index=-1,length=array.length,lastIndex=length-1;size=size===undefined?length:size;while(++index1?arrays[length-1]:undefined;iteratee=typeof iteratee=="function"?(arrays.pop(),iteratee):undefined;return unzipWith(arrays,iteratee)});function chain(value){var result=lodash(value);result.__chain__=true;return result}function tap(value,interceptor){interceptor(value);return value}function thru(value,interceptor){return interceptor(value)}var wrapperAt=flatRest(function(paths){var length=paths.length,start=length?paths[0]:0,value=this.__wrapped__,interceptor=function(object){return baseAt(object,paths)};if(length>1||this.__actions__.length||!(value instanceof LazyWrapper)||!isIndex(start)){return this.thru(interceptor)}value=value.slice(start,+start+(length?1:0));value.__actions__.push({func:thru,args:[interceptor],thisArg:undefined});return new LodashWrapper(value,this.__chain__).thru(function(array){if(length&&!array.length){array.push(undefined)}return array})});function wrapperChain(){return chain(this)}function wrapperCommit(){return new LodashWrapper(this.value(),this.__chain__)}function wrapperNext(){if(this.__values__===undefined){this.__values__=toArray(this.value())}var done=this.__index__>=this.__values__.length,value=done?undefined:this.__values__[this.__index__++];return{done:done,value:value}}function wrapperToIterator(){return this}function wrapperPlant(value){var result,parent=this;while(parent instanceof baseLodash){var clone=wrapperClone(parent);clone.__index__=0;clone.__values__=undefined;if(result){previous.__wrapped__=clone}else{result=clone}var previous=clone;parent=parent.__wrapped__}previous.__wrapped__=value;return result}function wrapperReverse(){var value=this.__wrapped__;if(value instanceof LazyWrapper){var wrapped=value;if(this.__actions__.length){wrapped=new LazyWrapper(this)}wrapped=wrapped.reverse();wrapped.__actions__.push({func:thru,args:[reverse],thisArg:undefined});return new LodashWrapper(wrapped,this.__chain__)}return this.thru(reverse)}function wrapperValue(){return baseWrapperValue(this.__wrapped__,this.__actions__)}var countBy=createAggregator(function(result,value,key){if(hasOwnProperty.call(result,key)){++result[key]}else{baseAssignValue(result,key,1)}});function every(collection,predicate,guard){var func=isArray(collection)?arrayEvery:baseEvery;if(guard&&isIterateeCall(collection,predicate,guard)){predicate=undefined}return func(collection,getIteratee(predicate,3))}function filter(collection,predicate){var func=isArray(collection)?arrayFilter:baseFilter;return func(collection,getIteratee(predicate,3))}var find=createFind(findIndex);var findLast=createFind(findLastIndex);function flatMap(collection,iteratee){return baseFlatten(map(collection,iteratee),1)}function flatMapDeep(collection,iteratee){return baseFlatten(map(collection,iteratee),INFINITY)}function flatMapDepth(collection,iteratee,depth){depth=depth===undefined?1:toInteger(depth);return baseFlatten(map(collection,iteratee),depth)}function forEach(collection,iteratee){var func=isArray(collection)?arrayEach:baseEach;return func(collection,getIteratee(iteratee,3))}function forEachRight(collection,iteratee){var func=isArray(collection)?arrayEachRight:baseEachRight;return func(collection,getIteratee(iteratee,3))}var groupBy=createAggregator(function(result,value,key){if(hasOwnProperty.call(result,key)){result[key].push(value)}else{baseAssignValue(result,key,[value])}});function includes(collection,value,fromIndex,guard){collection=isArrayLike(collection)?collection:values(collection);fromIndex=fromIndex&&!guard?toInteger(fromIndex):0;var length=collection.length;if(fromIndex<0){fromIndex=nativeMax(length+fromIndex,0)}return isString(collection)?fromIndex<=length&&collection.indexOf(value,fromIndex)>-1:!!length&&baseIndexOf(collection,value,fromIndex)>-1}var invokeMap=baseRest(function(collection,path,args){var index=-1,isFunc=typeof path=="function",result=isArrayLike(collection)?Array(collection.length):[];baseEach(collection,function(value){result[++index]=isFunc?apply(path,value,args):baseInvoke(value,path,args)});return result});var keyBy=createAggregator(function(result,value,key){baseAssignValue(result,key,value)});function map(collection,iteratee){var func=isArray(collection)?arrayMap:baseMap;return func(collection,getIteratee(iteratee,3))}function orderBy(collection,iteratees,orders,guard){if(collection==null){return[]}if(!isArray(iteratees)){iteratees=iteratees==null?[]:[iteratees]}orders=guard?undefined:orders;if(!isArray(orders)){orders=orders==null?[]:[orders]}return baseOrderBy(collection,iteratees,orders)}var partition=createAggregator(function(result,value,key){result[key?0:1].push(value)},function(){return[[],[]]});function reduce(collection,iteratee,accumulator){var func=isArray(collection)?arrayReduce:baseReduce,initAccum=arguments.length<3;return func(collection,getIteratee(iteratee,4),accumulator,initAccum,baseEach)}function reduceRight(collection,iteratee,accumulator){var func=isArray(collection)?arrayReduceRight:baseReduce,initAccum=arguments.length<3;return func(collection,getIteratee(iteratee,4),accumulator,initAccum,baseEachRight)}function reject(collection,predicate){var func=isArray(collection)?arrayFilter:baseFilter;return func(collection,negate(getIteratee(predicate,3)))}function sample(collection){var func=isArray(collection)?arraySample:baseSample;return func(collection)}function sampleSize(collection,n,guard){if(guard?isIterateeCall(collection,n,guard):n===undefined){n=1}else{n=toInteger(n)}var func=isArray(collection)?arraySampleSize:baseSampleSize;return func(collection,n)}function shuffle(collection){var func=isArray(collection)?arrayShuffle:baseShuffle;return func(collection)}function size(collection){if(collection==null){return 0}if(isArrayLike(collection)){return isString(collection)?stringSize(collection):collection.length}var tag=getTag(collection);if(tag==mapTag||tag==setTag){return collection.size}return baseKeys(collection).length}function some(collection,predicate,guard){var func=isArray(collection)?arraySome:baseSome;if(guard&&isIterateeCall(collection,predicate,guard)){predicate=undefined}return func(collection,getIteratee(predicate,3))}var sortBy=baseRest(function(collection,iteratees){if(collection==null){return[]}var length=iteratees.length;if(length>1&&isIterateeCall(collection,iteratees[0],iteratees[1])){iteratees=[]}else if(length>2&&isIterateeCall(iteratees[0],iteratees[1],iteratees[2])){iteratees=[iteratees[0]]}return baseOrderBy(collection,baseFlatten(iteratees,1),[])});var now=ctxNow||function(){return root.Date.now()};function after(n,func){if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}n=toInteger(n);return function(){if(--n<1){return func.apply(this,arguments)}}}function ary(func,n,guard){n=guard?undefined:n;n=func&&n==null?func.length:n;return createWrap(func,WRAP_ARY_FLAG,undefined,undefined,undefined,undefined,n)}function before(n,func){var result;if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}n=toInteger(n);return function(){if(--n>0){result=func.apply(this,arguments)}if(n<=1){func=undefined}return result}}var bind=baseRest(function(func,thisArg,partials){var bitmask=WRAP_BIND_FLAG;if(partials.length){var holders=replaceHolders(partials,getHolder(bind));bitmask|=WRAP_PARTIAL_FLAG}return createWrap(func,bitmask,thisArg,partials,holders)});var bindKey=baseRest(function(object,key,partials){var bitmask=WRAP_BIND_FLAG|WRAP_BIND_KEY_FLAG;if(partials.length){var holders=replaceHolders(partials,getHolder(bindKey));bitmask|=WRAP_PARTIAL_FLAG}return createWrap(key,bitmask,object,partials,holders)});function curry(func,arity,guard){arity=guard?undefined:arity;var result=createWrap(func,WRAP_CURRY_FLAG,undefined,undefined,undefined,undefined,undefined,arity);result.placeholder=curry.placeholder;return result}function curryRight(func,arity,guard){arity=guard?undefined:arity;var result=createWrap(func,WRAP_CURRY_RIGHT_FLAG,undefined,undefined,undefined,undefined,undefined,arity);result.placeholder=curryRight.placeholder;return result}function debounce(func,wait,options){var lastArgs,lastThis,maxWait,result,timerId,lastCallTime,lastInvokeTime=0,leading=false,maxing=false,trailing=true;if(typeof func!="function"){throw new TypeError(FUNC_ERROR_TEXT)}wait=toNumber(wait)||0;if(isObject(options)){leading=!!options.leading;maxing="maxWait"in options;maxWait=maxing?nativeMax(toNumber(options.maxWait)||0,wait):maxWait;trailing="trailing"in options?!!options.trailing:trailing}function invokeFunc(time){var args=lastArgs,thisArg=lastThis;lastArgs=lastThis=undefined;lastInvokeTime=time;result=func.apply(thisArg,args);return result}function leadingEdge(time){lastInvokeTime=time;timerId=setTimeout(timerExpired,wait);return leading?invokeFunc(time):result}function remainingWait(time){var timeSinceLastCall=time-lastCallTime,timeSinceLastInvoke=time-lastInvokeTime,timeWaiting=wait-timeSinceLastCall;return maxing?nativeMin(timeWaiting,maxWait-timeSinceLastInvoke):timeWaiting}function shouldInvoke(time){var timeSinceLastCall=time-lastCallTime,timeSinceLastInvoke=time-lastInvokeTime;return lastCallTime===undefined||timeSinceLastCall>=wait||timeSinceLastCall<0||maxing&&timeSinceLastInvoke>=maxWait}function timerExpired(){var time=now();if(shouldInvoke(time)){return trailingEdge(time)}timerId=setTimeout(timerExpired,remainingWait(time))}function trailingEdge(time){timerId=undefined;if(trailing&&lastArgs){return invokeFunc(time)}lastArgs=lastThis=undefined;return result}function cancel(){if(timerId!==undefined){clearTimeout(timerId)}lastInvokeTime=0;lastArgs=lastCallTime=lastThis=timerId=undefined}function flush(){return timerId===undefined?result:trailingEdge(now())}function debounced(){var time=now(),isInvoking=shouldInvoke(time);lastArgs=arguments;lastThis=this;lastCallTime=time;if(isInvoking){if(timerId===undefined){return leadingEdge(lastCallTime)}if(maxing){clearTimeout(timerId);timerId=setTimeout(timerExpired,wait);return invokeFunc(lastCallTime)}}if(timerId===undefined){timerId=setTimeout(timerExpired,wait)}return result}debounced.cancel=cancel;debounced.flush=flush;return debounced}var defer=baseRest(function(func,args){return baseDelay(func,1,args)});var delay=baseRest(function(func,wait,args){return baseDelay(func,toNumber(wait)||0,args)});function flip(func){return createWrap(func,WRAP_FLIP_FLAG)}function memoize(func,resolver){if(typeof func!="function"||resolver!=null&&typeof resolver!="function"){throw new TypeError(FUNC_ERROR_TEXT)}var memoized=function(){var args=arguments,key=resolver?resolver.apply(this,args):args[0],cache=memoized.cache;if(cache.has(key)){return cache.get(key)}var result=func.apply(this,args);memoized.cache=cache.set(key,result)||cache;return result};memoized.cache=new(memoize.Cache||MapCache);return memoized}memoize.Cache=MapCache;function negate(predicate){if(typeof predicate!="function"){throw new TypeError(FUNC_ERROR_TEXT)}return function(){var args=arguments;switch(args.length){case 0:return!predicate.call(this);case 1:return!predicate.call(this,args[0]);case 2:return!predicate.call(this,args[0],args[1]);case 3:return!predicate.call(this,args[0],args[1],args[2])}return!predicate.apply(this,args)}}function once(func){return before(2,func)}var overArgs=castRest(function(func,transforms){transforms=transforms.length==1&&isArray(transforms[0])?arrayMap(transforms[0],baseUnary(getIteratee())):arrayMap(baseFlatten(transforms,1),baseUnary(getIteratee()));var funcsLength=transforms.length;return baseRest(function(args){var index=-1,length=nativeMin(args.length,funcsLength);while(++index=other});var isArguments=baseIsArguments(function(){return arguments}())?baseIsArguments:function(value){return isObjectLike(value)&&hasOwnProperty.call(value,"callee")&&!propertyIsEnumerable.call(value,"callee")};var isArray=Array.isArray;var isArrayBuffer=nodeIsArrayBuffer?baseUnary(nodeIsArrayBuffer):baseIsArrayBuffer;function isArrayLike(value){return value!=null&&isLength(value.length)&&!isFunction(value)}function isArrayLikeObject(value){return isObjectLike(value)&&isArrayLike(value)}function isBoolean(value){return value===true||value===false||isObjectLike(value)&&baseGetTag(value)==boolTag}var isBuffer=nativeIsBuffer||stubFalse;var isDate=nodeIsDate?baseUnary(nodeIsDate):baseIsDate;function isElement(value){return isObjectLike(value)&&value.nodeType===1&&!isPlainObject(value)}function isEmpty(value){if(value==null){return true}if(isArrayLike(value)&&(isArray(value)||typeof value=="string"||typeof value.splice=="function"||isBuffer(value)||isTypedArray(value)||isArguments(value))){return!value.length}var tag=getTag(value);if(tag==mapTag||tag==setTag){return!value.size}if(isPrototype(value)){return!baseKeys(value).length}for(var key in value){if(hasOwnProperty.call(value,key)){return false}}return true}function isEqual(value,other){return baseIsEqual(value,other)}function isEqualWith(value,other,customizer){customizer=typeof customizer=="function"?customizer:undefined;var result=customizer?customizer(value,other):undefined;return result===undefined?baseIsEqual(value,other,undefined,customizer):!!result}function isError(value){if(!isObjectLike(value)){return false}var tag=baseGetTag(value);return tag==errorTag||tag==domExcTag||typeof value.message=="string"&&typeof value.name=="string"&&!isPlainObject(value)}function isFinite(value){return typeof value=="number"&&nativeIsFinite(value)}function isFunction(value){if(!isObject(value)){return false}var tag=baseGetTag(value);return tag==funcTag||tag==genTag||tag==asyncTag||tag==proxyTag}function isInteger(value){return typeof value=="number"&&value==toInteger(value)}function isLength(value){return typeof value=="number"&&value>-1&&value%1==0&&value<=MAX_SAFE_INTEGER}function isObject(value){var type=typeof value;return value!=null&&(type=="object"||type=="function")}function isObjectLike(value){return value!=null&&typeof value=="object"}var isMap=nodeIsMap?baseUnary(nodeIsMap):baseIsMap;function isMatch(object,source){return object===source||baseIsMatch(object,source,getMatchData(source))}function isMatchWith(object,source,customizer){customizer=typeof customizer=="function"?customizer:undefined;return baseIsMatch(object,source,getMatchData(source),customizer)}function isNaN(value){return isNumber(value)&&value!=+value}function isNative(value){if(isMaskable(value)){throw new Error(CORE_ERROR_TEXT)}return baseIsNative(value)}function isNull(value){return value===null}function isNil(value){return value==null}function isNumber(value){return typeof value=="number"||isObjectLike(value)&&baseGetTag(value)==numberTag}function isPlainObject(value){if(!isObjectLike(value)||baseGetTag(value)!=objectTag){return false}var proto=getPrototype(value);if(proto===null){return true}var Ctor=hasOwnProperty.call(proto,"constructor")&&proto.constructor;return typeof Ctor=="function"&&Ctor instanceof Ctor&&funcToString.call(Ctor)==objectCtorString}var isRegExp=nodeIsRegExp?baseUnary(nodeIsRegExp):baseIsRegExp;function isSafeInteger(value){return isInteger(value)&&value>=-MAX_SAFE_INTEGER&&value<=MAX_SAFE_INTEGER}var isSet=nodeIsSet?baseUnary(nodeIsSet):baseIsSet;function isString(value){return typeof value=="string"||!isArray(value)&&isObjectLike(value)&&baseGetTag(value)==stringTag}function isSymbol(value){return typeof value=="symbol"||isObjectLike(value)&&baseGetTag(value)==symbolTag}var isTypedArray=nodeIsTypedArray?baseUnary(nodeIsTypedArray):baseIsTypedArray;function isUndefined(value){return value===undefined}function isWeakMap(value){return isObjectLike(value)&&getTag(value)==weakMapTag}function isWeakSet(value){return isObjectLike(value)&&baseGetTag(value)==weakSetTag}var lt=createRelationalOperation(baseLt);var lte=createRelationalOperation(function(value,other){return value<=other});function toArray(value){if(!value){return[]}if(isArrayLike(value)){return isString(value)?stringToArray(value):copyArray(value)}if(symIterator&&value[symIterator]){return iteratorToArray(value[symIterator]())}var tag=getTag(value),func=tag==mapTag?mapToArray:tag==setTag?setToArray:values;return func(value)}function toFinite(value){if(!value){return value===0?value:0}value=toNumber(value);if(value===INFINITY||value===-INFINITY){var sign=value<0?-1:1;return sign*MAX_INTEGER}return value===value?value:0}function toInteger(value){var result=toFinite(value),remainder=result%1;return result===result?remainder?result-remainder:result:0}function toLength(value){return value?baseClamp(toInteger(value),0,MAX_ARRAY_LENGTH):0}function toNumber(value){if(typeof value=="number"){return value}if(isSymbol(value)){return NAN}if(isObject(value)){var other=typeof value.valueOf=="function"?value.valueOf():value;value=isObject(other)?other+"":other}if(typeof value!="string"){return value===0?value:+value}value=value.replace(reTrim,"");var isBinary=reIsBinary.test(value);return isBinary||reIsOctal.test(value)?freeParseInt(value.slice(2),isBinary?2:8):reIsBadHex.test(value)?NAN:+value}function toPlainObject(value){return copyObject(value,keysIn(value))}function toSafeInteger(value){return value?baseClamp(toInteger(value),-MAX_SAFE_INTEGER,MAX_SAFE_INTEGER):value===0?value:0}function toString(value){return value==null?"":baseToString(value)}var assign=createAssigner(function(object,source){if(isPrototype(source)||isArrayLike(source)){copyObject(source,keys(source),object);return}for(var key in source){if(hasOwnProperty.call(source,key)){assignValue(object,key,source[key])}}});var assignIn=createAssigner(function(object,source){copyObject(source,keysIn(source),object)});var assignInWith=createAssigner(function(object,source,srcIndex,customizer){copyObject(source,keysIn(source),object,customizer)});var assignWith=createAssigner(function(object,source,srcIndex,customizer){copyObject(source,keys(source),object,customizer)});var at=flatRest(baseAt);function create(prototype,properties){var result=baseCreate(prototype);return properties==null?result:baseAssign(result,properties)}var defaults=baseRest(function(object,sources){object=Object(object);var index=-1;var length=sources.length;var guard=length>2?sources[2]:undefined;if(guard&&isIterateeCall(sources[0],sources[1],guard)){length=1}while(++index1);return path});copyObject(object,getAllKeysIn(object),result);if(isDeep){result=baseClone(result,CLONE_DEEP_FLAG|CLONE_FLAT_FLAG|CLONE_SYMBOLS_FLAG,customOmitClone)}var length=paths.length;while(length--){baseUnset(result,paths[length])}return result});function omitBy(object,predicate){return pickBy(object,negate(getIteratee(predicate)))}var pick=flatRest(function(object,paths){return object==null?{}:basePick(object,paths)});function pickBy(object,predicate){if(object==null){return{}}var props=arrayMap(getAllKeysIn(object),function(prop){return[prop]});predicate=getIteratee(predicate);return basePickBy(object,props,function(value,path){return predicate(value,path[0])})}function result(object,path,defaultValue){path=castPath(path,object);var index=-1,length=path.length;if(!length){length=1;object=undefined}while(++indexupper){var temp=lower;lower=upper;upper=temp}if(floating||lower%1||upper%1){var rand=nativeRandom();return nativeMin(lower+rand*(upper-lower+freeParseFloat("1e-"+((rand+"").length-1))),upper)}return baseRandom(lower,upper)}var camelCase=createCompounder(function(result,word,index){word=word.toLowerCase();return result+(index?capitalize(word):word)});function capitalize(string){return upperFirst(toString(string).toLowerCase())}function deburr(string){string=toString(string);return string&&string.replace(reLatin,deburrLetter).replace(reComboMark,"")}function endsWith(string,target,position){string=toString(string);target=baseToString(target);var length=string.length;position=position===undefined?length:baseClamp(toInteger(position),0,length);var end=position;position-=target.length;return position>=0&&string.slice(position,end)==target}function escape(string){string=toString(string);return string&&reHasUnescapedHtml.test(string)?string.replace(reUnescapedHtml,escapeHtmlChar):string}function escapeRegExp(string){string=toString(string);return string&&reHasRegExpChar.test(string)?string.replace(reRegExpChar,"\\$&"):string}var kebabCase=createCompounder(function(result,word,index){return result+(index?"-":"")+word.toLowerCase()});var lowerCase=createCompounder(function(result,word,index){return result+(index?" ":"")+word.toLowerCase()});var lowerFirst=createCaseFirst("toLowerCase");function pad(string,length,chars){string=toString(string);length=toInteger(length);var strLength=length?stringSize(string):0;if(!length||strLength>=length){return string}var mid=(length-strLength)/2;return createPadding(nativeFloor(mid),chars)+string+createPadding(nativeCeil(mid),chars)}function padEnd(string,length,chars){string=toString(string);length=toInteger(length);var strLength=length?stringSize(string):0;return length&&strLength>>0;if(!limit){return[]}string=toString(string);if(string&&(typeof separator=="string"||separator!=null&&!isRegExp(separator))){separator=baseToString(separator);if(!separator&&hasUnicode(string)){return castSlice(stringToArray(string),0,limit)}}return string.split(separator,limit)}var startCase=createCompounder(function(result,word,index){return result+(index?" ":"")+upperFirst(word)});function startsWith(string,target,position){string=toString(string);position=position==null?0:baseClamp(toInteger(position),0,string.length);target=baseToString(target);return string.slice(position,position+target.length)==target}function template(string,options,guard){var settings=lodash.templateSettings;if(guard&&isIterateeCall(string,options,guard)){options=undefined}string=toString(string);options=assignInWith({},options,settings,customDefaultsAssignIn);var imports=assignInWith({},options.imports,settings.imports,customDefaultsAssignIn),importsKeys=keys(imports),importsValues=baseValues(imports,importsKeys);var isEscaping,isEvaluating,index=0,interpolate=options.interpolate||reNoMatch,source="__p += '";var reDelimiters=RegExp((options.escape||reNoMatch).source+"|"+interpolate.source+"|"+(interpolate===reInterpolate?reEsTemplate:reNoMatch).source+"|"+(options.evaluate||reNoMatch).source+"|$","g");var sourceURL="//# sourceURL="+(hasOwnProperty.call(options,"sourceURL")?(options.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++templateCounter+"]")+"\n";string.replace(reDelimiters,function(match,escapeValue,interpolateValue,esTemplateValue,evaluateValue,offset){interpolateValue||(interpolateValue=esTemplateValue);source+=string.slice(index,offset).replace(reUnescapedString,escapeStringChar);if(escapeValue){isEscaping=true;source+="' +\n__e("+escapeValue+") +\n'"}if(evaluateValue){isEvaluating=true;source+="';\n"+evaluateValue+";\n__p += '"}if(interpolateValue){source+="' +\n((__t = ("+interpolateValue+")) == null ? '' : __t) +\n'"}index=offset+match.length;return match});source+="';\n";var variable=hasOwnProperty.call(options,"variable")&&options.variable;if(!variable){source="with (obj) {\n"+source+"\n}\n"}source=(isEvaluating?source.replace(reEmptyStringLeading,""):source).replace(reEmptyStringMiddle,"$1").replace(reEmptyStringTrailing,"$1;");source="function("+(variable||"obj")+") {\n"+(variable?"":"obj || (obj = {});\n")+"var __t, __p = ''"+(isEscaping?", __e = _.escape":"")+(isEvaluating?", __j = Array.prototype.join;\n"+"function print() { __p += __j.call(arguments, '') }\n":";\n")+source+"return __p\n}";var result=attempt(function(){return Function(importsKeys,sourceURL+"return "+source).apply(undefined,importsValues)});result.source=source;if(isError(result)){throw result}return result}function toLower(value){return toString(value).toLowerCase()}function toUpper(value){return toString(value).toUpperCase()}function trim(string,chars,guard){string=toString(string);if(string&&(guard||chars===undefined)){return string.replace(reTrim,"")}if(!string||!(chars=baseToString(chars))){return string}var strSymbols=stringToArray(string),chrSymbols=stringToArray(chars),start=charsStartIndex(strSymbols,chrSymbols),end=charsEndIndex(strSymbols,chrSymbols)+1;return castSlice(strSymbols,start,end).join("")}function trimEnd(string,chars,guard){string=toString(string);if(string&&(guard||chars===undefined)){return string.replace(reTrimEnd,"")}if(!string||!(chars=baseToString(chars))){return string}var strSymbols=stringToArray(string),end=charsEndIndex(strSymbols,stringToArray(chars))+1;return castSlice(strSymbols,0,end).join("")}function trimStart(string,chars,guard){string=toString(string);if(string&&(guard||chars===undefined)){return string.replace(reTrimStart,"")}if(!string||!(chars=baseToString(chars))){return string}var strSymbols=stringToArray(string),start=charsStartIndex(strSymbols,stringToArray(chars));return castSlice(strSymbols,start).join("")}function truncate(string,options){var length=DEFAULT_TRUNC_LENGTH,omission=DEFAULT_TRUNC_OMISSION;if(isObject(options)){var separator="separator"in options?options.separator:separator;length="length"in options?toInteger(options.length):length;omission="omission"in options?baseToString(options.omission):omission}string=toString(string);var strLength=string.length;if(hasUnicode(string)){var strSymbols=stringToArray(string);strLength=strSymbols.length}if(length>=strLength){return string}var end=length-stringSize(omission);if(end<1){return omission}var result=strSymbols?castSlice(strSymbols,0,end).join(""):string.slice(0,end);if(separator===undefined){return result+omission}if(strSymbols){end+=result.length-end}if(isRegExp(separator)){if(string.slice(end).search(separator)){var match,substring=result;if(!separator.global){separator=RegExp(separator.source,toString(reFlags.exec(separator))+"g")}separator.lastIndex=0;while(match=separator.exec(substring)){var newEnd=match.index}result=result.slice(0,newEnd===undefined?end:newEnd)}}else if(string.indexOf(baseToString(separator),end)!=end){var index=result.lastIndexOf(separator);if(index>-1){result=result.slice(0,index)}}return result+omission}function unescape(string){string=toString(string);return string&&reHasEscapedHtml.test(string)?string.replace(reEscapedHtml,unescapeHtmlChar):string}var upperCase=createCompounder(function(result,word,index){return result+(index?" ":"")+word.toUpperCase()});var upperFirst=createCaseFirst("toUpperCase");function words(string,pattern,guard){string=toString(string);pattern=guard?undefined:pattern;if(pattern===undefined){return hasUnicodeWord(string)?unicodeWords(string):asciiWords(string)}return string.match(pattern)||[]}var attempt=baseRest(function(func,args){try{return apply(func,undefined,args)}catch(e){return isError(e)?e:new Error(e)}});var bindAll=flatRest(function(object,methodNames){arrayEach(methodNames,function(key){key=toKey(key);baseAssignValue(object,key,bind(object[key],object))});return object});function cond(pairs){var length=pairs==null?0:pairs.length,toIteratee=getIteratee();pairs=!length?[]:arrayMap(pairs,function(pair){if(typeof pair[1]!="function"){throw new TypeError(FUNC_ERROR_TEXT)}return[toIteratee(pair[0]),pair[1]]});return baseRest(function(args){var index=-1;while(++indexMAX_SAFE_INTEGER){return[]}var index=MAX_ARRAY_LENGTH,length=nativeMin(n,MAX_ARRAY_LENGTH);iteratee=getIteratee(iteratee);n-=MAX_ARRAY_LENGTH;var result=baseTimes(length,iteratee);while(++index0||end<0)){return new LazyWrapper(result)}if(start<0){result=result.takeRight(-start)}else if(start){result=result.drop(start)}if(end!==undefined){end=toInteger(end);result=end<0?result.dropRight(-end):result.take(end-start)}return result};LazyWrapper.prototype.takeRightWhile=function(predicate){return this.reverse().takeWhile(predicate).reverse()};LazyWrapper.prototype.toArray=function(){return this.take(MAX_ARRAY_LENGTH)};baseForOwn(LazyWrapper.prototype,function(func,methodName){var checkIteratee=/^(?:filter|find|map|reject)|While$/.test(methodName),isTaker=/^(?:head|last)$/.test(methodName),lodashFunc=lodash[isTaker?"take"+(methodName=="last"?"Right":""):methodName],retUnwrapped=isTaker||/^find/.test(methodName);if(!lodashFunc){return}lodash.prototype[methodName]=function(){var value=this.__wrapped__,args=isTaker?[1]:arguments,isLazy=value instanceof LazyWrapper,iteratee=args[0],useLazy=isLazy||isArray(value);var interceptor=function(value){var result=lodashFunc.apply(lodash,arrayPush([value],args));return isTaker&&chainAll?result[0]:result};if(useLazy&&checkIteratee&&typeof iteratee=="function"&&iteratee.length!=1){isLazy=useLazy=false}var chainAll=this.__chain__,isHybrid=!!this.__actions__.length,isUnwrapped=retUnwrapped&&!chainAll,onlyLazy=isLazy&&!isHybrid;if(!retUnwrapped&&useLazy){value=onlyLazy?value:new LazyWrapper(this);var result=func.apply(value,args);result.__actions__.push({func:thru,args:[interceptor],thisArg:undefined});return new LodashWrapper(result,chainAll)}if(isUnwrapped&&onlyLazy){return func.apply(this,args)}result=this.thru(interceptor);return isUnwrapped?isTaker?result.value()[0]:result.value():result}});arrayEach(["pop","push","shift","sort","splice","unshift"],function(methodName){var func=arrayProto[methodName],chainName=/^(?:push|sort|unshift)$/.test(methodName)?"tap":"thru",retUnwrapped=/^(?:pop|shift)$/.test(methodName);lodash.prototype[methodName]=function(){var args=arguments;if(retUnwrapped&&!this.__chain__){var value=this.value();return func.apply(isArray(value)?value:[],args)}return this[chainName](function(value){return func.apply(isArray(value)?value:[],args)})}});baseForOwn(LazyWrapper.prototype,function(func,methodName){var lodashFunc=lodash[methodName];if(lodashFunc){var key=lodashFunc.name+"";if(!hasOwnProperty.call(realNames,key)){realNames[key]=[]}realNames[key].push({name:methodName,func:lodashFunc})}});realNames[createHybrid(undefined,WRAP_BIND_KEY_FLAG).name]=[{name:"wrapper",func:undefined}];LazyWrapper.prototype.clone=lazyClone;LazyWrapper.prototype.reverse=lazyReverse;LazyWrapper.prototype.value=lazyValue;lodash.prototype.at=wrapperAt;lodash.prototype.chain=wrapperChain;lodash.prototype.commit=wrapperCommit;lodash.prototype.next=wrapperNext;lodash.prototype.plant=wrapperPlant;lodash.prototype.reverse=wrapperReverse;lodash.prototype.toJSON=lodash.prototype.valueOf=lodash.prototype.value=wrapperValue;lodash.prototype.first=lodash.prototype.head;if(symIterator){lodash.prototype[symIterator]=wrapperToIterator}return lodash};var _=runInContext();if(typeof define=="function"&&typeof define.amd=="object"&&define.amd){root._=_;define(function(){return _})}else if(freeModule){(freeModule.exports=_)._=_;freeExports._=_}else{root._=_}}).call(this)}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],104:[function(require,module,exports){module.exports=assert;function assert(val,msg){if(!val)throw new Error(msg||"Assertion failed")}assert.equal=function assertEqual(l,r,msg){if(l!=r)throw new Error(msg||"Assertion failed: "+l+" != "+r)}},{}],105:[function(require,module,exports){"use strict";var utils=exports;function toArray(msg,enc){if(Array.isArray(msg))return msg.slice();if(!msg)return[];var res=[];if(typeof msg!=="string"){for(var i=0;i>8;var lo=c&255;if(hi)res.push(hi,lo);else res.push(lo)}}return res}utils.toArray=toArray;function zero2(word){if(word.length===1)return"0"+word;else return word}utils.zero2=zero2;function toHex(msg){var res="";for(var i=0;iMAX_UINT32)throw new RangeError("requested too many random bytes");var bytes=Buffer.allocUnsafe(size);if(size>0){if(size>MAX_BYTES){for(var generated=0;generated",main:"index.js",scripts:{test:"gulp test","test:ci":"npm run test",coverage:"gulp coverage",build:"gulp",pub:"npm run build && npm publish"},keywords:["bitcoin","transaction","address","p2p","ecies","cryptocurrency","blockchain","payment","bip21","bip32","bip37","bip69","bip70","multisig"],repository:{type:"git",url:"https://github.com/bitpay/bitcore/tree/master/packages/bitcore-lib"},browser:{request:"browser-request"},dependencies:{bech32:"=2.0.0","bip-schnorr":"=0.6.4","bn.js":"=4.11.8",bs58:"^4.0.1","buffer-compare":"=1.1.1",elliptic:"^6.5.3",inherits:"=2.0.1",lodash:"^4.17.20"},devDependencies:{"bitcore-build":"^8.25.10",brfs:"^2.0.1",chai:"^4.2.0",gulp:"^4.0.0",sinon:"^7.1.1"},license:"MIT",gitHead:"012cc0216a9bc6b195035855bd17149bad41acd1"}},{}],109:[function(require,module,exports){"use strict";const asn1=exports;asn1.bignum=require("bn.js");asn1.define=require("./asn1/api").define;asn1.base=require("./asn1/base");asn1.constants=require("./asn1/constants");asn1.decoders=require("./asn1/decoders");asn1.encoders=require("./asn1/encoders")},{"./asn1/api":110,"./asn1/base":112,"./asn1/constants":116,"./asn1/decoders":118,"./asn1/encoders":121,"bn.js":123}],110:[function(require,module,exports){"use strict";const encoders=require("./encoders");const decoders=require("./decoders");const inherits=require("inherits");const api=exports;api.define=function define(name,body){return new Entity(name,body)};function Entity(name,body){this.name=name;this.body=body;this.decoders={};this.encoders={}}Entity.prototype._createNamed=function createNamed(Base){const name=this.name;function Generated(entity){this._initNamed(entity,name)}inherits(Generated,Base);Generated.prototype._initNamed=function _initNamed(entity,name){Base.call(this,entity,name)};return new Generated(this)};Entity.prototype._getDecoder=function _getDecoder(enc){enc=enc||"der";if(!this.decoders.hasOwnProperty(enc))this.decoders[enc]=this._createNamed(decoders[enc]);return this.decoders[enc]};Entity.prototype.decode=function decode(data,enc,options){return this._getDecoder(enc).decode(data,options)};Entity.prototype._getEncoder=function _getEncoder(enc){enc=enc||"der";if(!this.encoders.hasOwnProperty(enc))this.encoders[enc]=this._createNamed(encoders[enc]);return this.encoders[enc]};Entity.prototype.encode=function encode(data,enc,reporter){return this._getEncoder(enc).encode(data,reporter)}},{"./decoders":118,"./encoders":121,inherits:244}],111:[function(require,module,exports){"use strict";const inherits=require("inherits");const Reporter=require("../base/reporter").Reporter;const Buffer=require("safer-buffer").Buffer;function DecoderBuffer(base,options){Reporter.call(this,options);if(!Buffer.isBuffer(base)){this.error("Input not Buffer");return}this.base=base;this.offset=0;this.length=base.length}inherits(DecoderBuffer,Reporter);exports.DecoderBuffer=DecoderBuffer;DecoderBuffer.isDecoderBuffer=function isDecoderBuffer(data){if(data instanceof DecoderBuffer){return true}const isCompatible=typeof data==="object"&&Buffer.isBuffer(data.base)&&data.constructor.name==="DecoderBuffer"&&typeof data.offset==="number"&&typeof data.length==="number"&&typeof data.save==="function"&&typeof data.restore==="function"&&typeof data.isEmpty==="function"&&typeof data.readUInt8==="function"&&typeof data.skip==="function"&&typeof data.raw==="function";return isCompatible};DecoderBuffer.prototype.save=function save(){return{offset:this.offset,reporter:Reporter.prototype.save.call(this)}};DecoderBuffer.prototype.restore=function restore(save){const res=new DecoderBuffer(this.base);res.offset=save.offset;res.length=this.offset;this.offset=save.offset;Reporter.prototype.restore.call(this,save.reporter);return res};DecoderBuffer.prototype.isEmpty=function isEmpty(){return this.offset===this.length};DecoderBuffer.prototype.readUInt8=function readUInt8(fail){if(this.offset+1<=this.length)return this.base.readUInt8(this.offset++,true);else return this.error(fail||"DecoderBuffer overrun")};DecoderBuffer.prototype.skip=function skip(bytes,fail){if(!(this.offset+bytes<=this.length))return this.error(fail||"DecoderBuffer overrun");const res=new DecoderBuffer(this.base);res._reporterState=this._reporterState;res.offset=this.offset;res.length=this.offset+bytes;this.offset+=bytes;return res};DecoderBuffer.prototype.raw=function raw(save){return this.base.slice(save?save.offset:this.offset,this.length)};function EncoderBuffer(value,reporter){if(Array.isArray(value)){this.length=0;this.value=value.map(function(item){if(!EncoderBuffer.isEncoderBuffer(item))item=new EncoderBuffer(item,reporter);this.length+=item.length;return item},this)}else if(typeof value==="number"){if(!(0<=value&&value<=255))return reporter.error("non-byte EncoderBuffer value");this.value=value;this.length=1}else if(typeof value==="string"){this.value=value;this.length=Buffer.byteLength(value)}else if(Buffer.isBuffer(value)){this.value=value;this.length=value.length}else{return reporter.error("Unsupported type: "+typeof value)}}exports.EncoderBuffer=EncoderBuffer;EncoderBuffer.isEncoderBuffer=function isEncoderBuffer(data){if(data instanceof EncoderBuffer){return true}const isCompatible=typeof data==="object"&&data.constructor.name==="EncoderBuffer"&&typeof data.length==="number"&&typeof data.join==="function";return isCompatible};EncoderBuffer.prototype.join=function join(out,offset){if(!out)out=Buffer.alloc(this.length);if(!offset)offset=0;if(this.length===0)return out;if(Array.isArray(this.value)){this.value.forEach(function(item){item.join(out,offset);offset+=item.length})}else{if(typeof this.value==="number")out[offset]=this.value;else if(typeof this.value==="string")out.write(this.value,offset);else if(Buffer.isBuffer(this.value))this.value.copy(out,offset);offset+=this.length}return out}},{"../base/reporter":114,inherits:244,"safer-buffer":278}],112:[function(require,module,exports){"use strict";const base=exports;base.Reporter=require("./reporter").Reporter;base.DecoderBuffer=require("./buffer").DecoderBuffer;base.EncoderBuffer=require("./buffer").EncoderBuffer;base.Node=require("./node")},{"./buffer":111,"./node":113,"./reporter":114}],113:[function(require,module,exports){"use strict";const Reporter=require("../base/reporter").Reporter;const EncoderBuffer=require("../base/buffer").EncoderBuffer;const DecoderBuffer=require("../base/buffer").DecoderBuffer;const assert=require("minimalistic-assert");const tags=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"];const methods=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(tags);const overrided=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];function Node(enc,parent,name){const state={};this._baseState=state;state.name=name;state.enc=enc;state.parent=parent||null;state.children=null;state.tag=null;state.args=null;state.reverseArgs=null;state.choice=null;state.optional=false;state.any=false;state.obj=false;state.use=null;state.useDecoder=null;state.key=null;state["default"]=null;state.explicit=null;state.implicit=null;state.contains=null;if(!state.parent){state.children=[];this._wrap()}}module.exports=Node;const stateProps=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];Node.prototype.clone=function clone(){const state=this._baseState;const cstate={};stateProps.forEach(function(prop){cstate[prop]=state[prop]});const res=new this.constructor(cstate.parent);res._baseState=cstate;return res};Node.prototype._wrap=function wrap(){const state=this._baseState;methods.forEach(function(method){this[method]=function _wrappedMethod(){const clone=new this.constructor(this);state.children.push(clone);return clone[method].apply(clone,arguments)}},this)};Node.prototype._init=function init(body){const state=this._baseState;assert(state.parent===null);body.call(this);state.children=state.children.filter(function(child){return child._baseState.parent===this},this);assert.equal(state.children.length,1,"Root node can have only one child")};Node.prototype._useArgs=function useArgs(args){const state=this._baseState;const children=args.filter(function(arg){return arg instanceof this.constructor},this);args=args.filter(function(arg){return!(arg instanceof this.constructor)},this);if(children.length!==0){assert(state.children===null);state.children=children;children.forEach(function(child){child._baseState.parent=this},this)}if(args.length!==0){assert(state.args===null);state.args=args;state.reverseArgs=args.map(function(arg){if(typeof arg!=="object"||arg.constructor!==Object)return arg;const res={};Object.keys(arg).forEach(function(key){if(key==(key|0))key|=0;const value=arg[key];res[value]=key});return res})}};overrided.forEach(function(method){Node.prototype[method]=function _overrided(){const state=this._baseState;throw new Error(method+" not implemented for encoding: "+state.enc)}});tags.forEach(function(tag){Node.prototype[tag]=function _tagMethod(){const state=this._baseState;const args=Array.prototype.slice.call(arguments);assert(state.tag===null);state.tag=tag;this._useArgs(args);return this}});Node.prototype.use=function use(item){assert(item);const state=this._baseState;assert(state.use===null);state.use=item;return this};Node.prototype.optional=function optional(){const state=this._baseState;state.optional=true;return this};Node.prototype.def=function def(val){const state=this._baseState;assert(state["default"]===null);state["default"]=val;state.optional=true;return this};Node.prototype.explicit=function explicit(num){const state=this._baseState;assert(state.explicit===null&&state.implicit===null);state.explicit=num;return this};Node.prototype.implicit=function implicit(num){const state=this._baseState;assert(state.explicit===null&&state.implicit===null);state.implicit=num;return this};Node.prototype.obj=function obj(){const state=this._baseState;const args=Array.prototype.slice.call(arguments);state.obj=true;if(args.length!==0)this._useArgs(args);return this};Node.prototype.key=function key(newKey){const state=this._baseState;assert(state.key===null);state.key=newKey;return this};Node.prototype.any=function any(){const state=this._baseState;state.any=true;return this};Node.prototype.choice=function choice(obj){const state=this._baseState;assert(state.choice===null);state.choice=obj;this._useArgs(Object.keys(obj).map(function(key){return obj[key]}));return this};Node.prototype.contains=function contains(item){const state=this._baseState;assert(state.use===null);state.contains=item;return this};Node.prototype._decode=function decode(input,options){const state=this._baseState;if(state.parent===null)return input.wrapResult(state.children[0]._decode(input,options));let result=state["default"];let present=true;let prevKey=null;if(state.key!==null)prevKey=input.enterKey(state.key);if(state.optional){let tag=null;if(state.explicit!==null)tag=state.explicit;else if(state.implicit!==null)tag=state.implicit;else if(state.tag!==null)tag=state.tag;if(tag===null&&!state.any){const save=input.save();try{if(state.choice===null)this._decodeGeneric(state.tag,input,options);else this._decodeChoice(input,options);present=true}catch(e){present=false}input.restore(save)}else{present=this._peekTag(input,tag,state.any);if(input.isError(present))return present}}let prevObj;if(state.obj&&present)prevObj=input.enterObject();if(present){if(state.explicit!==null){const explicit=this._decodeTag(input,state.explicit);if(input.isError(explicit))return explicit;input=explicit}const start=input.offset;if(state.use===null&&state.choice===null){let save;if(state.any)save=input.save();const body=this._decodeTag(input,state.implicit!==null?state.implicit:state.tag,state.any);if(input.isError(body))return body;if(state.any)result=input.raw(save);else input=body}if(options&&options.track&&state.tag!==null)options.track(input.path(),start,input.length,"tagged");if(options&&options.track&&state.tag!==null)options.track(input.path(),input.offset,input.length,"content");if(state.any){}else if(state.choice===null){result=this._decodeGeneric(state.tag,input,options)}else{result=this._decodeChoice(input,options)}if(input.isError(result))return result;if(!state.any&&state.choice===null&&state.children!==null){state.children.forEach(function decodeChildren(child){child._decode(input,options)})}if(state.contains&&(state.tag==="octstr"||state.tag==="bitstr")){const data=new DecoderBuffer(result);result=this._getUse(state.contains,input._reporterState.obj)._decode(data,options)}}if(state.obj&&present)result=input.leaveObject(prevObj);if(state.key!==null&&(result!==null||present===true))input.leaveKey(prevKey,state.key,result);else if(prevKey!==null)input.exitKey(prevKey);return result};Node.prototype._decodeGeneric=function decodeGeneric(tag,input,options){const state=this._baseState;if(tag==="seq"||tag==="set")return null;if(tag==="seqof"||tag==="setof")return this._decodeList(input,tag,state.args[0],options);else if(/str$/.test(tag))return this._decodeStr(input,tag,options);else if(tag==="objid"&&state.args)return this._decodeObjid(input,state.args[0],state.args[1],options);else if(tag==="objid")return this._decodeObjid(input,null,null,options);else if(tag==="gentime"||tag==="utctime")return this._decodeTime(input,tag,options);else if(tag==="null_")return this._decodeNull(input,options);else if(tag==="bool")return this._decodeBool(input,options);else if(tag==="objDesc")return this._decodeStr(input,tag,options);else if(tag==="int"||tag==="enum")return this._decodeInt(input,state.args&&state.args[0],options);if(state.use!==null){return this._getUse(state.use,input._reporterState.obj)._decode(input,options)}else{return input.error("unknown tag: "+tag)}};Node.prototype._getUse=function _getUse(entity,obj){const state=this._baseState;state.useDecoder=this._use(entity,obj);assert(state.useDecoder._baseState.parent===null);state.useDecoder=state.useDecoder._baseState.children[0];if(state.implicit!==state.useDecoder._baseState.implicit){state.useDecoder=state.useDecoder.clone();state.useDecoder._baseState.implicit=state.implicit}return state.useDecoder};Node.prototype._decodeChoice=function decodeChoice(input,options){const state=this._baseState;let result=null;let match=false;Object.keys(state.choice).some(function(key){const save=input.save();const node=state.choice[key];try{const value=node._decode(input,options);if(input.isError(value))return false;result={type:key,value:value};match=true}catch(e){input.restore(save);return false}return true},this);if(!match)return input.error("Choice not matched");return result};Node.prototype._createEncoderBuffer=function createEncoderBuffer(data){return new EncoderBuffer(data,this.reporter)};Node.prototype._encode=function encode(data,reporter,parent){const state=this._baseState;if(state["default"]!==null&&state["default"]===data)return;const result=this._encodeValue(data,reporter,parent);if(result===undefined)return;if(this._skipDefault(result,reporter,parent))return;return result};Node.prototype._encodeValue=function encode(data,reporter,parent){const state=this._baseState;if(state.parent===null)return state.children[0]._encode(data,reporter||new Reporter);let result=null;this.reporter=reporter;if(state.optional&&data===undefined){if(state["default"]!==null)data=state["default"];else return}let content=null;let primitive=false;if(state.any){result=this._createEncoderBuffer(data)}else if(state.choice){result=this._encodeChoice(data,reporter)}else if(state.contains){content=this._getUse(state.contains,parent)._encode(data,reporter);primitive=true}else if(state.children){content=state.children.map(function(child){if(child._baseState.tag==="null_")return child._encode(null,reporter,data);if(child._baseState.key===null)return reporter.error("Child should have a key");const prevKey=reporter.enterKey(child._baseState.key);if(typeof data!=="object")return reporter.error("Child expected, but input is not object");const res=child._encode(data[child._baseState.key],reporter,data);reporter.leaveKey(prevKey);return res},this).filter(function(child){return child});content=this._createEncoderBuffer(content)}else{if(state.tag==="seqof"||state.tag==="setof"){if(!(state.args&&state.args.length===1))return reporter.error("Too many args for : "+state.tag);if(!Array.isArray(data))return reporter.error("seqof/setof, but data is not Array");const child=this.clone();child._baseState.implicit=null;content=this._createEncoderBuffer(data.map(function(item){const state=this._baseState;return this._getUse(state.args[0],data)._encode(item,reporter)},child))}else if(state.use!==null){result=this._getUse(state.use,parent)._encode(data,reporter)}else{content=this._encodePrimitive(state.tag,data);primitive=true}}if(!state.any&&state.choice===null){const tag=state.implicit!==null?state.implicit:state.tag;const cls=state.implicit===null?"universal":"context";if(tag===null){if(state.use===null)reporter.error("Tag could be omitted only for .use()")}else{if(state.use===null)result=this._encodeComposite(tag,primitive,cls,content)}}if(state.explicit!==null)result=this._encodeComposite(state.explicit,false,"context",result);return result};Node.prototype._encodeChoice=function encodeChoice(data,reporter){const state=this._baseState;const node=state.choice[data.type];if(!node){assert(false,data.type+" not found in "+JSON.stringify(Object.keys(state.choice)))}return node._encode(data.value,reporter)};Node.prototype._encodePrimitive=function encodePrimitive(tag,data){const state=this._baseState;if(/str$/.test(tag))return this._encodeStr(data,tag);else if(tag==="objid"&&state.args)return this._encodeObjid(data,state.reverseArgs[0],state.args[1]);else if(tag==="objid")return this._encodeObjid(data,null,null);else if(tag==="gentime"||tag==="utctime")return this._encodeTime(data,tag);else if(tag==="null_")return this._encodeNull();else if(tag==="int"||tag==="enum")return this._encodeInt(data,state.args&&state.reverseArgs[0]);else if(tag==="bool")return this._encodeBool(data);else if(tag==="objDesc")return this._encodeStr(data,tag);else throw new Error("Unsupported tag: "+tag)};Node.prototype._isNumstr=function isNumstr(str){return/^[0-9 ]*$/.test(str)};Node.prototype._isPrintstr=function isPrintstr(str){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(str)}},{"../base/buffer":111,"../base/reporter":114,"minimalistic-assert":248}],114:[function(require,module,exports){"use strict";const inherits=require("inherits");function Reporter(options){this._reporterState={obj:null,path:[],options:options||{},errors:[]}}exports.Reporter=Reporter;Reporter.prototype.isError=function isError(obj){return obj instanceof ReporterError};Reporter.prototype.save=function save(){const state=this._reporterState;return{obj:state.obj,pathLen:state.path.length}};Reporter.prototype.restore=function restore(data){const state=this._reporterState;state.obj=data.obj;state.path=state.path.slice(0,data.pathLen)};Reporter.prototype.enterKey=function enterKey(key){return this._reporterState.path.push(key)};Reporter.prototype.exitKey=function exitKey(index){const state=this._reporterState;state.path=state.path.slice(0,index-1)};Reporter.prototype.leaveKey=function leaveKey(index,key,value){const state=this._reporterState;this.exitKey(index);if(state.obj!==null)state.obj[key]=value};Reporter.prototype.path=function path(){return this._reporterState.path.join("/")};Reporter.prototype.enterObject=function enterObject(){const state=this._reporterState;const prev=state.obj;state.obj={};return prev};Reporter.prototype.leaveObject=function leaveObject(prev){const state=this._reporterState;const now=state.obj;state.obj=prev;return now};Reporter.prototype.error=function error(msg){let err;const state=this._reporterState;const inherited=msg instanceof ReporterError;if(inherited){err=msg}else{err=new ReporterError(state.path.map(function(elem){return"["+JSON.stringify(elem)+"]"}).join(""),msg.message||msg,msg.stack)}if(!state.options.partial)throw err;if(!inherited)state.errors.push(err);return err};Reporter.prototype.wrapResult=function wrapResult(result){const state=this._reporterState;if(!state.options.partial)return result;return{result:this.isError(result)?null:result,errors:state.errors}};function ReporterError(path,msg){this.path=path;this.rethrow(msg)}inherits(ReporterError,Error);ReporterError.prototype.rethrow=function rethrow(msg){this.message=msg+" at: "+(this.path||"(shallow)");if(Error.captureStackTrace)Error.captureStackTrace(this,ReporterError);if(!this.stack){try{throw new Error(this.message)}catch(e){this.stack=e.stack}}return this}},{inherits:244}],115:[function(require,module,exports){"use strict";function reverse(map){const res={};Object.keys(map).forEach(function(key){if((key|0)==key)key=key|0;const value=map[key];res[value]=key});return res}exports.tagClass={0:"universal",1:"application",2:"context",3:"private"};exports.tagClassByName=reverse(exports.tagClass);exports.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"};exports.tagByName=reverse(exports.tag)},{}],116:[function(require,module,exports){"use strict";const constants=exports;constants._reverse=function reverse(map){const res={};Object.keys(map).forEach(function(key){if((key|0)==key)key=key|0;const value=map[key];res[value]=key});return res};constants.der=require("./der")},{"./der":115}],117:[function(require,module,exports){"use strict";const inherits=require("inherits");const bignum=require("bn.js");const DecoderBuffer=require("../base/buffer").DecoderBuffer;const Node=require("../base/node");const der=require("../constants/der");function DERDecoder(entity){this.enc="der";this.name=entity.name;this.entity=entity;this.tree=new DERNode;this.tree._init(entity.body)}module.exports=DERDecoder;DERDecoder.prototype.decode=function decode(data,options){if(!DecoderBuffer.isDecoderBuffer(data)){data=new DecoderBuffer(data,options)}return this.tree._decode(data,options)};function DERNode(parent){Node.call(this,"der",parent)}inherits(DERNode,Node);DERNode.prototype._peekTag=function peekTag(buffer,tag,any){if(buffer.isEmpty())return false;const state=buffer.save();const decodedTag=derDecodeTag(buffer,'Failed to peek tag: "'+tag+'"');if(buffer.isError(decodedTag))return decodedTag;buffer.restore(state);return decodedTag.tag===tag||decodedTag.tagStr===tag||decodedTag.tagStr+"of"===tag||any};DERNode.prototype._decodeTag=function decodeTag(buffer,tag,any){const decodedTag=derDecodeTag(buffer,'Failed to decode tag of "'+tag+'"');if(buffer.isError(decodedTag))return decodedTag;let len=derDecodeLen(buffer,decodedTag.primitive,'Failed to get length of "'+tag+'"');if(buffer.isError(len))return len;if(!any&&decodedTag.tag!==tag&&decodedTag.tagStr!==tag&&decodedTag.tagStr+"of"!==tag){return buffer.error('Failed to match tag: "'+tag+'"')}if(decodedTag.primitive||len!==null)return buffer.skip(len,'Failed to match body of: "'+tag+'"');const state=buffer.save();const res=this._skipUntilEnd(buffer,'Failed to skip indefinite length body: "'+this.tag+'"');if(buffer.isError(res))return res;len=buffer.offset-state.offset;buffer.restore(state);return buffer.skip(len,'Failed to match body of: "'+tag+'"')};DERNode.prototype._skipUntilEnd=function skipUntilEnd(buffer,fail){for(;;){const tag=derDecodeTag(buffer,fail);if(buffer.isError(tag))return tag;const len=derDecodeLen(buffer,tag.primitive,fail);if(buffer.isError(len))return len;let res;if(tag.primitive||len!==null)res=buffer.skip(len);else res=this._skipUntilEnd(buffer,fail);if(buffer.isError(res))return res;if(tag.tagStr==="end")break}};DERNode.prototype._decodeList=function decodeList(buffer,tag,decoder,options){const result=[];while(!buffer.isEmpty()){const possibleEnd=this._peekTag(buffer,"end");if(buffer.isError(possibleEnd))return possibleEnd;const res=decoder.decode(buffer,"der",options);if(buffer.isError(res)&&possibleEnd)break;result.push(res)}return result};DERNode.prototype._decodeStr=function decodeStr(buffer,tag){if(tag==="bitstr"){const unused=buffer.readUInt8();if(buffer.isError(unused))return unused;return{unused:unused,data:buffer.raw()}}else if(tag==="bmpstr"){const raw=buffer.raw();if(raw.length%2===1)return buffer.error("Decoding of string type: bmpstr length mismatch");let str="";for(let i=0;i>6];const primitive=(tag&32)===0;if((tag&31)===31){let oct=tag;tag=0;while((oct&128)===128){oct=buf.readUInt8(fail);if(buf.isError(oct))return oct;tag<<=7;tag|=oct&127}}else{tag&=31}const tagStr=der.tag[tag];return{cls:cls,primitive:primitive,tag:tag,tagStr:tagStr}}function derDecodeLen(buf,primitive,fail){let len=buf.readUInt8(fail);if(buf.isError(len))return len;if(!primitive&&len===128)return null;if((len&128)===0){return len}const num=len&127;if(num>4)return buf.error("length octect is too long");len=0;for(let i=0;i=256;i>>=8)lenOctets++;const header=Buffer.alloc(1+1+lenOctets);header[0]=encodedTag;header[1]=128|lenOctets;for(let i=1+lenOctets,j=content.length;j>0;i--,j>>=8)header[i]=j&255;return this._createEncoderBuffer([header,content])};DERNode.prototype._encodeStr=function encodeStr(str,tag){if(tag==="bitstr"){return this._createEncoderBuffer([str.unused|0,str.data])}else if(tag==="bmpstr"){const buf=Buffer.alloc(str.length*2);for(let i=0;i=40)return this.reporter.error("Second objid identifier OOB");id.splice(0,2,id[0]*40+id[1])}let size=0;for(let i=0;i=128;ident>>=7)size++}const objid=Buffer.alloc(size);let offset=objid.length-1;for(let i=id.length-1;i>=0;i--){let ident=id[i];objid[offset--]=ident&127;while((ident>>=7)>0)objid[offset--]=128|ident&127}return this._createEncoderBuffer(objid)};function two(num){if(num<10)return"0"+num;else return num}DERNode.prototype._encodeTime=function encodeTime(time,tag){let str;const date=new Date(time);if(tag==="gentime"){str=[two(date.getUTCFullYear()),two(date.getUTCMonth()+1),two(date.getUTCDate()),two(date.getUTCHours()),two(date.getUTCMinutes()),two(date.getUTCSeconds()),"Z"].join("")}else if(tag==="utctime"){str=[two(date.getUTCFullYear()%100),two(date.getUTCMonth()+1),two(date.getUTCDate()),two(date.getUTCHours()),two(date.getUTCMinutes()),two(date.getUTCSeconds()),"Z"].join("")}else{this.reporter.error("Encoding "+tag+" time is not supported yet")}return this._encodeStr(str,"octstr")};DERNode.prototype._encodeNull=function encodeNull(){return this._createEncoderBuffer("")};DERNode.prototype._encodeInt=function encodeInt(num,values){if(typeof num==="string"){if(!values)return this.reporter.error("String int or enum given, but no values map");if(!values.hasOwnProperty(num)){return this.reporter.error("Values map doesn't contain: "+JSON.stringify(num))}num=values[num]}if(typeof num!=="number"&&!Buffer.isBuffer(num)){const numArray=num.toArray();if(!num.sign&&numArray[0]&128){numArray.unshift(0)}num=Buffer.from(numArray)}if(Buffer.isBuffer(num)){let size=num.length;if(num.length===0)size++;const out=Buffer.alloc(size);num.copy(out);if(num.length===0)out[0]=0;return this._createEncoderBuffer(out)}if(num<128)return this._createEncoderBuffer(num);if(num<256)return this._createEncoderBuffer([0,num]);let size=1;for(let i=num;i>=256;i>>=8)size++;const out=new Array(size);for(let i=out.length-1;i>=0;i--){out[i]=num&255;num>>=8}if(out[0]&128){out.unshift(0)}return this._createEncoderBuffer(Buffer.from(out))};DERNode.prototype._encodeBool=function encodeBool(value){return this._createEncoderBuffer(value?255:0)};DERNode.prototype._use=function use(entity,obj){if(typeof entity==="function")entity=entity(obj);return entity._getEncoder("der").tree};DERNode.prototype._skipDefault=function skipDefault(dataBuffer,reporter,parent){const state=this._baseState;let i;if(state["default"]===null)return false;const data=dataBuffer.join();if(state.defaultBuffer===undefined)state.defaultBuffer=this._encodeValue(state["default"],reporter,parent).join();if(data.length!==state.defaultBuffer.length)return false;for(i=0;i=31)return reporter.error("Multi-octet tag encoding unsupported");if(!primitive)res|=32;res|=der.tagClassByName[cls||"universal"]<<6;return res}},{"../base/node":113,"../constants/der":115,inherits:244,"safer-buffer":278}],121:[function(require,module,exports){"use strict";const encoders=exports;encoders.der=require("./der");encoders.pem=require("./pem")},{"./der":120,"./pem":122}],122:[function(require,module,exports){"use strict";const inherits=require("inherits");const DEREncoder=require("./der");function PEMEncoder(entity){DEREncoder.call(this,entity);this.enc="pem"}inherits(PEMEncoder,DEREncoder);module.exports=PEMEncoder;PEMEncoder.prototype.encode=function encode(data,options){const buf=DEREncoder.prototype.encode.call(this,data);const p=buf.toString("base64");const out=["-----BEGIN "+options.label+"-----"];for(let i=0;i0)return left;return right};BN.min=function min(left,right){if(left.cmp(right)<0)return left;return right};BN.prototype._init=function init(number,base,endian){if(typeof number==="number"){return this._initNumber(number,base,endian)}if(typeof number==="object"){return this._initArray(number,base,endian)}if(base==="hex"){base=16}assert(base===(base|0)&&base>=2&&base<=36);number=number.toString().replace(/\s+/g,"");var start=0;if(number[0]==="-"){start++;this.negative=1}if(start=0;i-=3){w=number[i]|number[i-1]<<8|number[i-2]<<16;this.words[j]|=w<>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}else if(endian==="le"){for(i=0,j=0;i>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}return this.strip()};function parseHex4Bits(string,index){var c=string.charCodeAt(index);if(c>=65&&c<=70){return c-55}else if(c>=97&&c<=102){return c-87}else{return c-48&15}}function parseHexByte(string,lowerBound,index){var r=parseHex4Bits(string,index);if(index-1>=lowerBound){r|=parseHex4Bits(string,index-1)<<4}return r}BN.prototype._parseHex=function _parseHex(number,start,endian){this.length=Math.ceil((number.length-start)/6);this.words=new Array(this.length);for(var i=0;i=start;i-=2){w=parseHexByte(number,start,i)<=18){off-=18;j+=1;this.words[j]|=w>>>26}else{off+=8}}}else{var parseLength=number.length-start;for(i=parseLength%2===0?start+1:start;i=18){off-=18;j+=1;this.words[j]|=w>>>26}else{off+=8}}}this.strip()};function parseBase(str,start,end,mul){var r=0;var len=Math.min(str.length,end);for(var i=start;i=49){r+=c-49+10}else if(c>=17){r+=c-17+10}else{r+=c}}return r}BN.prototype._parseBase=function _parseBase(number,base,start){this.words=[0];this.length=1;for(var limbLen=0,limbPow=1;limbPow<=67108863;limbPow*=base){limbLen++}limbLen--;limbPow=limbPow/base|0;var total=number.length-start;var mod=total%limbLen;var end=Math.min(total,total-mod)+start;var word=0;for(var i=start;i1&&this.words[this.length-1]===0){this.length--}return this._normSign()};BN.prototype._normSign=function _normSign(){if(this.length===1&&this.words[0]===0){this.negative=0}return this};BN.prototype.inspect=function inspect(){return(this.red?""};var zeros=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"];var groupSizes=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5];var groupBases=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];BN.prototype.toString=function toString(base,padding){base=base||10;padding=padding|0||1;var out;if(base===16||base==="hex"){out="";var off=0;var carry=0;for(var i=0;i>>24-off&16777215;if(carry!==0||i!==this.length-1){out=zeros[6-word.length]+word+out}else{out=word+out}off+=2;if(off>=26){off-=26;i--}}if(carry!==0){out=carry.toString(16)+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}if(base===(base|0)&&base>=2&&base<=36){var groupSize=groupSizes[base];var groupBase=groupBases[base];out="";var c=this.clone();c.negative=0;while(!c.isZero()){var r=c.modn(groupBase).toString(base);c=c.idivn(groupBase);if(!c.isZero()){out=zeros[groupSize-r.length]+r+out}else{out=r+out}}if(this.isZero()){out="0"+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}assert(false,"Base should be between 2 and 36")};BN.prototype.toNumber=function toNumber(){var ret=this.words[0];if(this.length===2){ret+=this.words[1]*67108864}else if(this.length===3&&this.words[2]===1){ret+=4503599627370496+this.words[1]*67108864}else if(this.length>2){assert(false,"Number can only safely store up to 53 bits")}return this.negative!==0?-ret:ret};BN.prototype.toJSON=function toJSON(){return this.toString(16)};BN.prototype.toBuffer=function toBuffer(endian,length){assert(typeof Buffer!=="undefined");return this.toArrayLike(Buffer,endian,length)};BN.prototype.toArray=function toArray(endian,length){return this.toArrayLike(Array,endian,length)};BN.prototype.toArrayLike=function toArrayLike(ArrayType,endian,length){var byteLength=this.byteLength();var reqLength=length||Math.max(1,byteLength);assert(byteLength<=reqLength,"byte array longer than desired length");assert(reqLength>0,"Requested array length <= 0");this.strip();var littleEndian=endian==="le";var res=new ArrayType(reqLength);var b,i;var q=this.clone();if(!littleEndian){for(i=0;i=4096){r+=13;t>>>=13}if(t>=64){r+=7;t>>>=7}if(t>=8){r+=4;t>>>=4}if(t>=2){r+=2;t>>>=2}return r+t}}BN.prototype._zeroBits=function _zeroBits(w){if(w===0)return 26;var t=w;var r=0;if((t&8191)===0){r+=13;t>>>=13}if((t&127)===0){r+=7;t>>>=7}if((t&15)===0){r+=4;t>>>=4}if((t&3)===0){r+=2;t>>>=2}if((t&1)===0){r++}return r};BN.prototype.bitLength=function bitLength(){var w=this.words[this.length-1];var hi=this._countBits(w);return(this.length-1)*26+hi};function toBitArray(num){var w=new Array(num.bitLength());for(var bit=0;bit>>wbit}return w}BN.prototype.zeroBits=function zeroBits(){if(this.isZero())return 0;var r=0;for(var i=0;inum.length)return this.clone().ior(num);return num.clone().ior(this)};BN.prototype.uor=function uor(num){if(this.length>num.length)return this.clone().iuor(num);return num.clone().iuor(this)};BN.prototype.iuand=function iuand(num){var b;if(this.length>num.length){b=num}else{b=this}for(var i=0;inum.length)return this.clone().iand(num);return num.clone().iand(this)};BN.prototype.uand=function uand(num){if(this.length>num.length)return this.clone().iuand(num);return num.clone().iuand(this)};BN.prototype.iuxor=function iuxor(num){var a;var b;if(this.length>num.length){a=this;b=num}else{a=num;b=this}for(var i=0;inum.length)return this.clone().ixor(num);return num.clone().ixor(this)};BN.prototype.uxor=function uxor(num){if(this.length>num.length)return this.clone().iuxor(num);return num.clone().iuxor(this)};BN.prototype.inotn=function inotn(width){assert(typeof width==="number"&&width>=0);var bytesNeeded=Math.ceil(width/26)|0;var bitsLeft=width%26;this._expand(bytesNeeded);if(bitsLeft>0){bytesNeeded--}for(var i=0;i0){this.words[i]=~this.words[i]&67108863>>26-bitsLeft}return this.strip()};BN.prototype.notn=function notn(width){return this.clone().inotn(width)};BN.prototype.setn=function setn(bit,val){assert(typeof bit==="number"&&bit>=0);var off=bit/26|0;var wbit=bit%26;this._expand(off+1);if(val){this.words[off]=this.words[off]|1<num.length){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>>26}for(;carry!==0&&i>>26}this.length=a.length;if(carry!==0){this.words[this.length]=carry;this.length++}else if(a!==this){for(;inum.length)return this.clone().iadd(num);return num.clone().iadd(this)};BN.prototype.isub=function isub(num){if(num.negative!==0){num.negative=0;var r=this.iadd(num);num.negative=1;return r._normSign()}else if(this.negative!==0){this.negative=0;this.iadd(num);this.negative=1;return this._normSign()}var cmp=this.cmp(num);if(cmp===0){this.negative=0;this.length=1;this.words[0]=0;return this}var a,b;if(cmp>0){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>26;this.words[i]=r&67108863}for(;carry!==0&&i>26;this.words[i]=r&67108863}if(carry===0&&i>>26;var rword=carry&67108863;var maxJ=Math.min(k,num.length-1);for(var j=Math.max(0,k-self.length+1);j<=maxJ;j++){var i=k-j|0;a=self.words[i]|0;b=num.words[j]|0;r=a*b+rword;ncarry+=r/67108864|0;rword=r&67108863}out.words[k]=rword|0;carry=ncarry|0}if(carry!==0){out.words[k]=carry|0}else{out.length--}return out.strip()}var comb10MulTo=function comb10MulTo(self,num,out){var a=self.words;var b=num.words;var o=out.words;var c=0;var lo;var mid;var hi;var a0=a[0]|0;var al0=a0&8191;var ah0=a0>>>13;var a1=a[1]|0;var al1=a1&8191;var ah1=a1>>>13;var a2=a[2]|0;var al2=a2&8191;var ah2=a2>>>13;var a3=a[3]|0;var al3=a3&8191;var ah3=a3>>>13;var a4=a[4]|0;var al4=a4&8191;var ah4=a4>>>13;var a5=a[5]|0;var al5=a5&8191;var ah5=a5>>>13;var a6=a[6]|0;var al6=a6&8191;var ah6=a6>>>13;var a7=a[7]|0;var al7=a7&8191;var ah7=a7>>>13;var a8=a[8]|0;var al8=a8&8191;var ah8=a8>>>13;var a9=a[9]|0;var al9=a9&8191;var ah9=a9>>>13;var b0=b[0]|0;var bl0=b0&8191;var bh0=b0>>>13;var b1=b[1]|0;var bl1=b1&8191;var bh1=b1>>>13;var b2=b[2]|0;var bl2=b2&8191;var bh2=b2>>>13;var b3=b[3]|0;var bl3=b3&8191;var bh3=b3>>>13;var b4=b[4]|0;var bl4=b4&8191;var bh4=b4>>>13;var b5=b[5]|0;var bl5=b5&8191;var bh5=b5>>>13;var b6=b[6]|0;var bl6=b6&8191;var bh6=b6>>>13;var b7=b[7]|0;var bl7=b7&8191;var bh7=b7>>>13;var b8=b[8]|0;var bl8=b8&8191;var bh8=b8>>>13;var b9=b[9]|0;var bl9=b9&8191;var bh9=b9>>>13;out.negative=self.negative^num.negative;out.length=19;lo=Math.imul(al0,bl0);mid=Math.imul(al0,bh0);mid=mid+Math.imul(ah0,bl0)|0;hi=Math.imul(ah0,bh0);var w0=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w0>>>26)|0;w0&=67108863;lo=Math.imul(al1,bl0);mid=Math.imul(al1,bh0);mid=mid+Math.imul(ah1,bl0)|0;hi=Math.imul(ah1,bh0);lo=lo+Math.imul(al0,bl1)|0;mid=mid+Math.imul(al0,bh1)|0;mid=mid+Math.imul(ah0,bl1)|0;hi=hi+Math.imul(ah0,bh1)|0;var w1=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w1>>>26)|0;w1&=67108863;lo=Math.imul(al2,bl0);mid=Math.imul(al2,bh0);mid=mid+Math.imul(ah2,bl0)|0;hi=Math.imul(ah2,bh0);lo=lo+Math.imul(al1,bl1)|0;mid=mid+Math.imul(al1,bh1)|0;mid=mid+Math.imul(ah1,bl1)|0;hi=hi+Math.imul(ah1,bh1)|0;lo=lo+Math.imul(al0,bl2)|0;mid=mid+Math.imul(al0,bh2)|0;mid=mid+Math.imul(ah0,bl2)|0;hi=hi+Math.imul(ah0,bh2)|0;var w2=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w2>>>26)|0;w2&=67108863;lo=Math.imul(al3,bl0);mid=Math.imul(al3,bh0);mid=mid+Math.imul(ah3,bl0)|0;hi=Math.imul(ah3,bh0);lo=lo+Math.imul(al2,bl1)|0;mid=mid+Math.imul(al2,bh1)|0;mid=mid+Math.imul(ah2,bl1)|0;hi=hi+Math.imul(ah2,bh1)|0;lo=lo+Math.imul(al1,bl2)|0;mid=mid+Math.imul(al1,bh2)|0;mid=mid+Math.imul(ah1,bl2)|0;hi=hi+Math.imul(ah1,bh2)|0;lo=lo+Math.imul(al0,bl3)|0;mid=mid+Math.imul(al0,bh3)|0;mid=mid+Math.imul(ah0,bl3)|0;hi=hi+Math.imul(ah0,bh3)|0;var w3=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w3>>>26)|0;w3&=67108863;lo=Math.imul(al4,bl0);mid=Math.imul(al4,bh0);mid=mid+Math.imul(ah4,bl0)|0;hi=Math.imul(ah4,bh0);lo=lo+Math.imul(al3,bl1)|0;mid=mid+Math.imul(al3,bh1)|0;mid=mid+Math.imul(ah3,bl1)|0;hi=hi+Math.imul(ah3,bh1)|0;lo=lo+Math.imul(al2,bl2)|0;mid=mid+Math.imul(al2,bh2)|0;mid=mid+Math.imul(ah2,bl2)|0;hi=hi+Math.imul(ah2,bh2)|0;lo=lo+Math.imul(al1,bl3)|0;mid=mid+Math.imul(al1,bh3)|0;mid=mid+Math.imul(ah1,bl3)|0;hi=hi+Math.imul(ah1,bh3)|0;lo=lo+Math.imul(al0,bl4)|0;mid=mid+Math.imul(al0,bh4)|0;mid=mid+Math.imul(ah0,bl4)|0;hi=hi+Math.imul(ah0,bh4)|0;var w4=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w4>>>26)|0;w4&=67108863;lo=Math.imul(al5,bl0);mid=Math.imul(al5,bh0);mid=mid+Math.imul(ah5,bl0)|0;hi=Math.imul(ah5,bh0);lo=lo+Math.imul(al4,bl1)|0;mid=mid+Math.imul(al4,bh1)|0;mid=mid+Math.imul(ah4,bl1)|0;hi=hi+Math.imul(ah4,bh1)|0;lo=lo+Math.imul(al3,bl2)|0;mid=mid+Math.imul(al3,bh2)|0;mid=mid+Math.imul(ah3,bl2)|0;hi=hi+Math.imul(ah3,bh2)|0;lo=lo+Math.imul(al2,bl3)|0;mid=mid+Math.imul(al2,bh3)|0;mid=mid+Math.imul(ah2,bl3)|0;hi=hi+Math.imul(ah2,bh3)|0;lo=lo+Math.imul(al1,bl4)|0;mid=mid+Math.imul(al1,bh4)|0;mid=mid+Math.imul(ah1,bl4)|0;hi=hi+Math.imul(ah1,bh4)|0;lo=lo+Math.imul(al0,bl5)|0;mid=mid+Math.imul(al0,bh5)|0;mid=mid+Math.imul(ah0,bl5)|0;hi=hi+Math.imul(ah0,bh5)|0;var w5=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w5>>>26)|0;w5&=67108863;lo=Math.imul(al6,bl0);mid=Math.imul(al6,bh0);mid=mid+Math.imul(ah6,bl0)|0;hi=Math.imul(ah6,bh0);lo=lo+Math.imul(al5,bl1)|0;mid=mid+Math.imul(al5,bh1)|0;mid=mid+Math.imul(ah5,bl1)|0;hi=hi+Math.imul(ah5,bh1)|0;lo=lo+Math.imul(al4,bl2)|0;mid=mid+Math.imul(al4,bh2)|0;mid=mid+Math.imul(ah4,bl2)|0;hi=hi+Math.imul(ah4,bh2)|0;lo=lo+Math.imul(al3,bl3)|0;mid=mid+Math.imul(al3,bh3)|0;mid=mid+Math.imul(ah3,bl3)|0;hi=hi+Math.imul(ah3,bh3)|0;lo=lo+Math.imul(al2,bl4)|0;mid=mid+Math.imul(al2,bh4)|0;mid=mid+Math.imul(ah2,bl4)|0;hi=hi+Math.imul(ah2,bh4)|0;lo=lo+Math.imul(al1,bl5)|0;mid=mid+Math.imul(al1,bh5)|0;mid=mid+Math.imul(ah1,bl5)|0;hi=hi+Math.imul(ah1,bh5)|0;lo=lo+Math.imul(al0,bl6)|0;mid=mid+Math.imul(al0,bh6)|0;mid=mid+Math.imul(ah0,bl6)|0;hi=hi+Math.imul(ah0,bh6)|0;var w6=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w6>>>26)|0;w6&=67108863;lo=Math.imul(al7,bl0);mid=Math.imul(al7,bh0);mid=mid+Math.imul(ah7,bl0)|0;hi=Math.imul(ah7,bh0);lo=lo+Math.imul(al6,bl1)|0;mid=mid+Math.imul(al6,bh1)|0;mid=mid+Math.imul(ah6,bl1)|0;hi=hi+Math.imul(ah6,bh1)|0;lo=lo+Math.imul(al5,bl2)|0;mid=mid+Math.imul(al5,bh2)|0;mid=mid+Math.imul(ah5,bl2)|0;hi=hi+Math.imul(ah5,bh2)|0;lo=lo+Math.imul(al4,bl3)|0;mid=mid+Math.imul(al4,bh3)|0;mid=mid+Math.imul(ah4,bl3)|0;hi=hi+Math.imul(ah4,bh3)|0;lo=lo+Math.imul(al3,bl4)|0;mid=mid+Math.imul(al3,bh4)|0;mid=mid+Math.imul(ah3,bl4)|0;hi=hi+Math.imul(ah3,bh4)|0;lo=lo+Math.imul(al2,bl5)|0;mid=mid+Math.imul(al2,bh5)|0;mid=mid+Math.imul(ah2,bl5)|0;hi=hi+Math.imul(ah2,bh5)|0;lo=lo+Math.imul(al1,bl6)|0;mid=mid+Math.imul(al1,bh6)|0;mid=mid+Math.imul(ah1,bl6)|0;hi=hi+Math.imul(ah1,bh6)|0;lo=lo+Math.imul(al0,bl7)|0;mid=mid+Math.imul(al0,bh7)|0;mid=mid+Math.imul(ah0,bl7)|0;hi=hi+Math.imul(ah0,bh7)|0;var w7=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w7>>>26)|0;w7&=67108863;lo=Math.imul(al8,bl0);mid=Math.imul(al8,bh0);mid=mid+Math.imul(ah8,bl0)|0;hi=Math.imul(ah8,bh0);lo=lo+Math.imul(al7,bl1)|0;mid=mid+Math.imul(al7,bh1)|0;mid=mid+Math.imul(ah7,bl1)|0;hi=hi+Math.imul(ah7,bh1)|0;lo=lo+Math.imul(al6,bl2)|0;mid=mid+Math.imul(al6,bh2)|0;mid=mid+Math.imul(ah6,bl2)|0;hi=hi+Math.imul(ah6,bh2)|0;lo=lo+Math.imul(al5,bl3)|0;mid=mid+Math.imul(al5,bh3)|0;mid=mid+Math.imul(ah5,bl3)|0;hi=hi+Math.imul(ah5,bh3)|0;lo=lo+Math.imul(al4,bl4)|0;mid=mid+Math.imul(al4,bh4)|0;mid=mid+Math.imul(ah4,bl4)|0;hi=hi+Math.imul(ah4,bh4)|0;lo=lo+Math.imul(al3,bl5)|0;mid=mid+Math.imul(al3,bh5)|0;mid=mid+Math.imul(ah3,bl5)|0;hi=hi+Math.imul(ah3,bh5)|0;lo=lo+Math.imul(al2,bl6)|0;mid=mid+Math.imul(al2,bh6)|0;mid=mid+Math.imul(ah2,bl6)|0;hi=hi+Math.imul(ah2,bh6)|0;lo=lo+Math.imul(al1,bl7)|0;mid=mid+Math.imul(al1,bh7)|0;mid=mid+Math.imul(ah1,bl7)|0;hi=hi+Math.imul(ah1,bh7)|0;lo=lo+Math.imul(al0,bl8)|0;mid=mid+Math.imul(al0,bh8)|0;mid=mid+Math.imul(ah0,bl8)|0;hi=hi+Math.imul(ah0,bh8)|0;var w8=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w8>>>26)|0;w8&=67108863;lo=Math.imul(al9,bl0);mid=Math.imul(al9,bh0);mid=mid+Math.imul(ah9,bl0)|0;hi=Math.imul(ah9,bh0);lo=lo+Math.imul(al8,bl1)|0;mid=mid+Math.imul(al8,bh1)|0;mid=mid+Math.imul(ah8,bl1)|0;hi=hi+Math.imul(ah8,bh1)|0;lo=lo+Math.imul(al7,bl2)|0;mid=mid+Math.imul(al7,bh2)|0;mid=mid+Math.imul(ah7,bl2)|0;hi=hi+Math.imul(ah7,bh2)|0;lo=lo+Math.imul(al6,bl3)|0;mid=mid+Math.imul(al6,bh3)|0;mid=mid+Math.imul(ah6,bl3)|0;hi=hi+Math.imul(ah6,bh3)|0;lo=lo+Math.imul(al5,bl4)|0;mid=mid+Math.imul(al5,bh4)|0;mid=mid+Math.imul(ah5,bl4)|0;hi=hi+Math.imul(ah5,bh4)|0;lo=lo+Math.imul(al4,bl5)|0;mid=mid+Math.imul(al4,bh5)|0;mid=mid+Math.imul(ah4,bl5)|0;hi=hi+Math.imul(ah4,bh5)|0;lo=lo+Math.imul(al3,bl6)|0;mid=mid+Math.imul(al3,bh6)|0;mid=mid+Math.imul(ah3,bl6)|0;hi=hi+Math.imul(ah3,bh6)|0;lo=lo+Math.imul(al2,bl7)|0;mid=mid+Math.imul(al2,bh7)|0;mid=mid+Math.imul(ah2,bl7)|0;hi=hi+Math.imul(ah2,bh7)|0;lo=lo+Math.imul(al1,bl8)|0;mid=mid+Math.imul(al1,bh8)|0;mid=mid+Math.imul(ah1,bl8)|0;hi=hi+Math.imul(ah1,bh8)|0;lo=lo+Math.imul(al0,bl9)|0;mid=mid+Math.imul(al0,bh9)|0;mid=mid+Math.imul(ah0,bl9)|0;hi=hi+Math.imul(ah0,bh9)|0;var w9=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w9>>>26)|0;w9&=67108863;lo=Math.imul(al9,bl1);mid=Math.imul(al9,bh1);mid=mid+Math.imul(ah9,bl1)|0;hi=Math.imul(ah9,bh1);lo=lo+Math.imul(al8,bl2)|0;mid=mid+Math.imul(al8,bh2)|0;mid=mid+Math.imul(ah8,bl2)|0;hi=hi+Math.imul(ah8,bh2)|0;lo=lo+Math.imul(al7,bl3)|0;mid=mid+Math.imul(al7,bh3)|0;mid=mid+Math.imul(ah7,bl3)|0;hi=hi+Math.imul(ah7,bh3)|0;lo=lo+Math.imul(al6,bl4)|0;mid=mid+Math.imul(al6,bh4)|0;mid=mid+Math.imul(ah6,bl4)|0;hi=hi+Math.imul(ah6,bh4)|0;lo=lo+Math.imul(al5,bl5)|0;mid=mid+Math.imul(al5,bh5)|0;mid=mid+Math.imul(ah5,bl5)|0;hi=hi+Math.imul(ah5,bh5)|0;lo=lo+Math.imul(al4,bl6)|0;mid=mid+Math.imul(al4,bh6)|0;mid=mid+Math.imul(ah4,bl6)|0;hi=hi+Math.imul(ah4,bh6)|0;lo=lo+Math.imul(al3,bl7)|0;mid=mid+Math.imul(al3,bh7)|0;mid=mid+Math.imul(ah3,bl7)|0;hi=hi+Math.imul(ah3,bh7)|0;lo=lo+Math.imul(al2,bl8)|0;mid=mid+Math.imul(al2,bh8)|0;mid=mid+Math.imul(ah2,bl8)|0;hi=hi+Math.imul(ah2,bh8)|0;lo=lo+Math.imul(al1,bl9)|0;mid=mid+Math.imul(al1,bh9)|0;mid=mid+Math.imul(ah1,bl9)|0;hi=hi+Math.imul(ah1,bh9)|0;var w10=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w10>>>26)|0;w10&=67108863;lo=Math.imul(al9,bl2);mid=Math.imul(al9,bh2);mid=mid+Math.imul(ah9,bl2)|0;hi=Math.imul(ah9,bh2);lo=lo+Math.imul(al8,bl3)|0;mid=mid+Math.imul(al8,bh3)|0;mid=mid+Math.imul(ah8,bl3)|0;hi=hi+Math.imul(ah8,bh3)|0;lo=lo+Math.imul(al7,bl4)|0;mid=mid+Math.imul(al7,bh4)|0;mid=mid+Math.imul(ah7,bl4)|0;hi=hi+Math.imul(ah7,bh4)|0;lo=lo+Math.imul(al6,bl5)|0;mid=mid+Math.imul(al6,bh5)|0;mid=mid+Math.imul(ah6,bl5)|0;hi=hi+Math.imul(ah6,bh5)|0;lo=lo+Math.imul(al5,bl6)|0;mid=mid+Math.imul(al5,bh6)|0;mid=mid+Math.imul(ah5,bl6)|0;hi=hi+Math.imul(ah5,bh6)|0;lo=lo+Math.imul(al4,bl7)|0;mid=mid+Math.imul(al4,bh7)|0;mid=mid+Math.imul(ah4,bl7)|0;hi=hi+Math.imul(ah4,bh7)|0;lo=lo+Math.imul(al3,bl8)|0;mid=mid+Math.imul(al3,bh8)|0;mid=mid+Math.imul(ah3,bl8)|0;hi=hi+Math.imul(ah3,bh8)|0;lo=lo+Math.imul(al2,bl9)|0;mid=mid+Math.imul(al2,bh9)|0;mid=mid+Math.imul(ah2,bl9)|0;hi=hi+Math.imul(ah2,bh9)|0;var w11=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w11>>>26)|0;w11&=67108863;lo=Math.imul(al9,bl3);mid=Math.imul(al9,bh3);mid=mid+Math.imul(ah9,bl3)|0;hi=Math.imul(ah9,bh3);lo=lo+Math.imul(al8,bl4)|0;mid=mid+Math.imul(al8,bh4)|0;mid=mid+Math.imul(ah8,bl4)|0;hi=hi+Math.imul(ah8,bh4)|0;lo=lo+Math.imul(al7,bl5)|0;mid=mid+Math.imul(al7,bh5)|0;mid=mid+Math.imul(ah7,bl5)|0;hi=hi+Math.imul(ah7,bh5)|0;lo=lo+Math.imul(al6,bl6)|0;mid=mid+Math.imul(al6,bh6)|0;mid=mid+Math.imul(ah6,bl6)|0;hi=hi+Math.imul(ah6,bh6)|0;lo=lo+Math.imul(al5,bl7)|0;mid=mid+Math.imul(al5,bh7)|0;mid=mid+Math.imul(ah5,bl7)|0;hi=hi+Math.imul(ah5,bh7)|0;lo=lo+Math.imul(al4,bl8)|0;mid=mid+Math.imul(al4,bh8)|0;mid=mid+Math.imul(ah4,bl8)|0;hi=hi+Math.imul(ah4,bh8)|0;lo=lo+Math.imul(al3,bl9)|0;mid=mid+Math.imul(al3,bh9)|0;mid=mid+Math.imul(ah3,bl9)|0;hi=hi+Math.imul(ah3,bh9)|0;var w12=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w12>>>26)|0;w12&=67108863;lo=Math.imul(al9,bl4);mid=Math.imul(al9,bh4);mid=mid+Math.imul(ah9,bl4)|0;hi=Math.imul(ah9,bh4);lo=lo+Math.imul(al8,bl5)|0;mid=mid+Math.imul(al8,bh5)|0;mid=mid+Math.imul(ah8,bl5)|0;hi=hi+Math.imul(ah8,bh5)|0;lo=lo+Math.imul(al7,bl6)|0;mid=mid+Math.imul(al7,bh6)|0;mid=mid+Math.imul(ah7,bl6)|0;hi=hi+Math.imul(ah7,bh6)|0;lo=lo+Math.imul(al6,bl7)|0;mid=mid+Math.imul(al6,bh7)|0;mid=mid+Math.imul(ah6,bl7)|0;hi=hi+Math.imul(ah6,bh7)|0;lo=lo+Math.imul(al5,bl8)|0;mid=mid+Math.imul(al5,bh8)|0;mid=mid+Math.imul(ah5,bl8)|0;hi=hi+Math.imul(ah5,bh8)|0;lo=lo+Math.imul(al4,bl9)|0;mid=mid+Math.imul(al4,bh9)|0;mid=mid+Math.imul(ah4,bl9)|0;hi=hi+Math.imul(ah4,bh9)|0;var w13=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w13>>>26)|0;w13&=67108863;lo=Math.imul(al9,bl5);mid=Math.imul(al9,bh5);mid=mid+Math.imul(ah9,bl5)|0;hi=Math.imul(ah9,bh5);lo=lo+Math.imul(al8,bl6)|0;mid=mid+Math.imul(al8,bh6)|0;mid=mid+Math.imul(ah8,bl6)|0;hi=hi+Math.imul(ah8,bh6)|0;lo=lo+Math.imul(al7,bl7)|0;mid=mid+Math.imul(al7,bh7)|0;mid=mid+Math.imul(ah7,bl7)|0;hi=hi+Math.imul(ah7,bh7)|0;lo=lo+Math.imul(al6,bl8)|0;mid=mid+Math.imul(al6,bh8)|0;mid=mid+Math.imul(ah6,bl8)|0;hi=hi+Math.imul(ah6,bh8)|0;lo=lo+Math.imul(al5,bl9)|0;mid=mid+Math.imul(al5,bh9)|0;mid=mid+Math.imul(ah5,bl9)|0;hi=hi+Math.imul(ah5,bh9)|0;var w14=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w14>>>26)|0;w14&=67108863;lo=Math.imul(al9,bl6);mid=Math.imul(al9,bh6);mid=mid+Math.imul(ah9,bl6)|0;hi=Math.imul(ah9,bh6);lo=lo+Math.imul(al8,bl7)|0;mid=mid+Math.imul(al8,bh7)|0;mid=mid+Math.imul(ah8,bl7)|0;hi=hi+Math.imul(ah8,bh7)|0;lo=lo+Math.imul(al7,bl8)|0;mid=mid+Math.imul(al7,bh8)|0;mid=mid+Math.imul(ah7,bl8)|0;hi=hi+Math.imul(ah7,bh8)|0;lo=lo+Math.imul(al6,bl9)|0;mid=mid+Math.imul(al6,bh9)|0;mid=mid+Math.imul(ah6,bl9)|0;hi=hi+Math.imul(ah6,bh9)|0;var w15=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w15>>>26)|0;w15&=67108863;lo=Math.imul(al9,bl7);mid=Math.imul(al9,bh7);mid=mid+Math.imul(ah9,bl7)|0;hi=Math.imul(ah9,bh7);lo=lo+Math.imul(al8,bl8)|0;mid=mid+Math.imul(al8,bh8)|0;mid=mid+Math.imul(ah8,bl8)|0;hi=hi+Math.imul(ah8,bh8)|0;lo=lo+Math.imul(al7,bl9)|0;mid=mid+Math.imul(al7,bh9)|0;mid=mid+Math.imul(ah7,bl9)|0;hi=hi+Math.imul(ah7,bh9)|0;var w16=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w16>>>26)|0;w16&=67108863;lo=Math.imul(al9,bl8);mid=Math.imul(al9,bh8);mid=mid+Math.imul(ah9,bl8)|0;hi=Math.imul(ah9,bh8);lo=lo+Math.imul(al8,bl9)|0;mid=mid+Math.imul(al8,bh9)|0;mid=mid+Math.imul(ah8,bl9)|0;hi=hi+Math.imul(ah8,bh9)|0;var w17=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w17>>>26)|0;w17&=67108863;lo=Math.imul(al9,bl9);mid=Math.imul(al9,bh9);mid=mid+Math.imul(ah9,bl9)|0;hi=Math.imul(ah9,bh9);var w18=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w18>>>26)|0;w18&=67108863;o[0]=w0;o[1]=w1;o[2]=w2;o[3]=w3;o[4]=w4;o[5]=w5;o[6]=w6;o[7]=w7;o[8]=w8;o[9]=w9;o[10]=w10;o[11]=w11;o[12]=w12;o[13]=w13;o[14]=w14;o[15]=w15;o[16]=w16;o[17]=w17;o[18]=w18;if(c!==0){o[19]=c;out.length++}return out};if(!Math.imul){comb10MulTo=smallMulTo}function bigMulTo(self,num,out){out.negative=num.negative^self.negative;out.length=self.length+num.length;var carry=0;var hncarry=0;for(var k=0;k>>26)|0;hncarry+=ncarry>>>26;ncarry&=67108863}out.words[k]=rword;carry=ncarry;ncarry=hncarry}if(carry!==0){out.words[k]=carry}else{out.length--}return out.strip()}function jumboMulTo(self,num,out){var fftm=new FFTM;return fftm.mulp(self,num,out)}BN.prototype.mulTo=function mulTo(num,out){var res;var len=this.length+num.length;if(this.length===10&&num.length===10){res=comb10MulTo(this,num,out)}else if(len<63){res=smallMulTo(this,num,out)}else if(len<1024){res=bigMulTo(this,num,out)}else{res=jumboMulTo(this,num,out)}return res};function FFTM(x,y){this.x=x;this.y=y}FFTM.prototype.makeRBT=function makeRBT(N){var t=new Array(N);var l=BN.prototype._countBits(N)-1;for(var i=0;i>=1}return rb};FFTM.prototype.permute=function permute(rbt,rws,iws,rtws,itws,N){for(var i=0;i>>1){i++}return 1<>>13;rws[2*i+1]=carry&8191;carry=carry>>>13}for(i=2*len;i>=26;carry+=w/67108864|0;carry+=lo>>>26;this.words[i]=lo&67108863}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.muln=function muln(num){return this.clone().imuln(num)};BN.prototype.sqr=function sqr(){return this.mul(this)};BN.prototype.isqr=function isqr(){return this.imul(this.clone())};BN.prototype.pow=function pow(num){var w=toBitArray(num);if(w.length===0)return new BN(1);var res=this;for(var i=0;i=0);var r=bits%26;var s=(bits-r)/26;var carryMask=67108863>>>26-r<<26-r;var i;if(r!==0){var carry=0;for(i=0;i>>26-r}if(carry){this.words[i]=carry;this.length++}}if(s!==0){for(i=this.length-1;i>=0;i--){this.words[i+s]=this.words[i]}for(i=0;i=0);var h;if(hint){h=(hint-hint%26)/26}else{h=0}var r=bits%26;var s=Math.min((bits-r)/26,this.length);var mask=67108863^67108863>>>r<s){this.length-=s;for(i=0;i=0&&(carry!==0||i>=h);i--){var word=this.words[i]|0;this.words[i]=carry<<26-r|word>>>r;carry=word&mask}if(maskedWords&&carry!==0){maskedWords.words[maskedWords.length++]=carry}if(this.length===0){this.words[0]=0;this.length=1}return this.strip()};BN.prototype.ishrn=function ishrn(bits,hint,extended){assert(this.negative===0);return this.iushrn(bits,hint,extended)};BN.prototype.shln=function shln(bits){return this.clone().ishln(bits)};BN.prototype.ushln=function ushln(bits){return this.clone().iushln(bits)};BN.prototype.shrn=function shrn(bits){return this.clone().ishrn(bits)};BN.prototype.ushrn=function ushrn(bits){return this.clone().iushrn(bits)};BN.prototype.testn=function testn(bit){assert(typeof bit==="number"&&bit>=0);var r=bit%26;var s=(bit-r)/26;var q=1<=0);var r=bits%26;var s=(bits-r)/26;assert(this.negative===0,"imaskn works only with positive numbers");if(this.length<=s){return this}if(r!==0){s++}this.length=Math.min(s,this.length);if(r!==0){var mask=67108863^67108863>>>r<=67108864;i++){this.words[i]-=67108864;if(i===this.length-1){this.words[i+1]=1}else{this.words[i+1]++}}this.length=Math.max(this.length,i+1);return this};BN.prototype.isubn=function isubn(num){assert(typeof num==="number");assert(num<67108864);if(num<0)return this.iaddn(-num);if(this.negative!==0){this.negative=0;this.iaddn(num);this.negative=1;return this}this.words[0]-=num;if(this.length===1&&this.words[0]<0){this.words[0]=-this.words[0];this.negative=1}else{for(var i=0;i>26)-(right/67108864|0);this.words[i+shift]=w&67108863}for(;i>26;this.words[i+shift]=w&67108863}if(carry===0)return this.strip();assert(carry===-1);carry=0;for(i=0;i>26;this.words[i]=w&67108863}this.negative=1;return this.strip()};BN.prototype._wordDiv=function _wordDiv(num,mode){var shift=this.length-num.length;var a=this.clone();var b=num;var bhi=b.words[b.length-1]|0;var bhiBits=this._countBits(bhi);shift=26-bhiBits;if(shift!==0){b=b.ushln(shift);a.iushln(shift);bhi=b.words[b.length-1]|0}var m=a.length-b.length;var q;if(mode!=="mod"){q=new BN(null);q.length=m+1;q.words=new Array(q.length);for(var i=0;i=0;j--){var qj=(a.words[b.length+j]|0)*67108864+(a.words[b.length+j-1]|0);qj=Math.min(qj/bhi|0,67108863);a._ishlnsubmul(b,qj,j);while(a.negative!==0){qj--;a.negative=0;a._ishlnsubmul(b,1,j);if(!a.isZero()){a.negative^=1}}if(q){q.words[j]=qj}}if(q){q.strip()}a.strip();if(mode!=="div"&&shift!==0){a.iushrn(shift)}return{div:q||null,mod:a}};BN.prototype.divmod=function divmod(num,mode,positive){assert(!num.isZero());if(this.isZero()){return{div:new BN(0),mod:new BN(0)}}var div,mod,res;if(this.negative!==0&&num.negative===0){res=this.neg().divmod(num,mode);if(mode!=="mod"){div=res.div.neg()}if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.iadd(num)}}return{div:div,mod:mod}}if(this.negative===0&&num.negative!==0){res=this.divmod(num.neg(),mode);if(mode!=="mod"){div=res.div.neg()}return{div:div,mod:res.mod}}if((this.negative&num.negative)!==0){res=this.neg().divmod(num.neg(),mode);if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.isub(num)}}return{div:res.div,mod:mod}}if(num.length>this.length||this.cmp(num)<0){return{div:new BN(0),mod:this}}if(num.length===1){if(mode==="div"){return{div:this.divn(num.words[0]),mod:null}}if(mode==="mod"){return{div:null,mod:new BN(this.modn(num.words[0]))}}return{div:this.divn(num.words[0]),mod:new BN(this.modn(num.words[0]))}}return this._wordDiv(num,mode)};BN.prototype.div=function div(num){return this.divmod(num,"div",false).div};BN.prototype.mod=function mod(num){return this.divmod(num,"mod",false).mod};BN.prototype.umod=function umod(num){return this.divmod(num,"mod",true).mod};BN.prototype.divRound=function divRound(num){var dm=this.divmod(num);if(dm.mod.isZero())return dm.div;var mod=dm.div.negative!==0?dm.mod.isub(num):dm.mod;var half=num.ushrn(1);var r2=num.andln(1);var cmp=mod.cmp(half);if(cmp<0||r2===1&&cmp===0)return dm.div;return dm.div.negative!==0?dm.div.isubn(1):dm.div.iaddn(1)};BN.prototype.modn=function modn(num){assert(num<=67108863);var p=(1<<26)%num;var acc=0;for(var i=this.length-1;i>=0;i--){acc=(p*acc+(this.words[i]|0))%num}return acc};BN.prototype.idivn=function idivn(num){assert(num<=67108863);var carry=0;for(var i=this.length-1;i>=0;i--){var w=(this.words[i]|0)+carry*67108864;this.words[i]=w/num|0;carry=w%num}return this.strip()};BN.prototype.divn=function divn(num){return this.clone().idivn(num)};BN.prototype.egcd=function egcd(p){assert(p.negative===0);assert(!p.isZero());var x=this;var y=p.clone();if(x.negative!==0){x=x.umod(p)}else{x=x.clone()}var A=new BN(1);var B=new BN(0);var C=new BN(0);var D=new BN(1);var g=0;while(x.isEven()&&y.isEven()){x.iushrn(1);y.iushrn(1);++g}var yp=y.clone();var xp=x.clone();while(!x.isZero()){for(var i=0,im=1;(x.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){x.iushrn(i);while(i-- >0){if(A.isOdd()||B.isOdd()){A.iadd(yp);B.isub(xp)}A.iushrn(1);B.iushrn(1)}}for(var j=0,jm=1;(y.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){y.iushrn(j);while(j-- >0){if(C.isOdd()||D.isOdd()){C.iadd(yp);D.isub(xp)}C.iushrn(1);D.iushrn(1)}}if(x.cmp(y)>=0){x.isub(y);A.isub(C);B.isub(D)}else{y.isub(x);C.isub(A);D.isub(B)}}return{a:C,b:D,gcd:y.iushln(g)}};BN.prototype._invmp=function _invmp(p){assert(p.negative===0);assert(!p.isZero());var a=this;var b=p.clone();if(a.negative!==0){a=a.umod(p)}else{a=a.clone()}var x1=new BN(1);var x2=new BN(0);var delta=b.clone();while(a.cmpn(1)>0&&b.cmpn(1)>0){for(var i=0,im=1;(a.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){a.iushrn(i);while(i-- >0){if(x1.isOdd()){x1.iadd(delta)}x1.iushrn(1)}}for(var j=0,jm=1;(b.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){b.iushrn(j);while(j-- >0){if(x2.isOdd()){x2.iadd(delta)}x2.iushrn(1)}}if(a.cmp(b)>=0){a.isub(b);x1.isub(x2)}else{b.isub(a);x2.isub(x1)}}var res;if(a.cmpn(1)===0){res=x1}else{res=x2}if(res.cmpn(0)<0){res.iadd(p)}return res};BN.prototype.gcd=function gcd(num){if(this.isZero())return num.abs();if(num.isZero())return this.abs();var a=this.clone();var b=num.clone();a.negative=0;b.negative=0;for(var shift=0;a.isEven()&&b.isEven();shift++){a.iushrn(1);b.iushrn(1)}do{while(a.isEven()){a.iushrn(1)}while(b.isEven()){b.iushrn(1)}var r=a.cmp(b);if(r<0){var t=a;a=b;b=t}else if(r===0||b.cmpn(1)===0){break}a.isub(b)}while(true);return b.iushln(shift)};BN.prototype.invm=function invm(num){return this.egcd(num).a.umod(num)};BN.prototype.isEven=function isEven(){return(this.words[0]&1)===0};BN.prototype.isOdd=function isOdd(){return(this.words[0]&1)===1};BN.prototype.andln=function andln(num){return this.words[0]&num};BN.prototype.bincn=function bincn(bit){assert(typeof bit==="number");var r=bit%26;var s=(bit-r)/26;var q=1<>>26;w&=67108863;this.words[i]=w}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.isZero=function isZero(){return this.length===1&&this.words[0]===0};BN.prototype.cmpn=function cmpn(num){var negative=num<0;if(this.negative!==0&&!negative)return-1;if(this.negative===0&&negative)return 1;this.strip();var res;if(this.length>1){res=1}else{if(negative){num=-num}assert(num<=67108863,"Number is too big");var w=this.words[0]|0;res=w===num?0:wnum.length)return 1;if(this.length=0;i--){var a=this.words[i]|0;var b=num.words[i]|0;if(a===b)continue;if(ab){res=1}break}return res};BN.prototype.gtn=function gtn(num){return this.cmpn(num)===1};BN.prototype.gt=function gt(num){return this.cmp(num)===1};BN.prototype.gten=function gten(num){return this.cmpn(num)>=0};BN.prototype.gte=function gte(num){return this.cmp(num)>=0};BN.prototype.ltn=function ltn(num){return this.cmpn(num)===-1};BN.prototype.lt=function lt(num){return this.cmp(num)===-1};BN.prototype.lten=function lten(num){return this.cmpn(num)<=0};BN.prototype.lte=function lte(num){return this.cmp(num)<=0};BN.prototype.eqn=function eqn(num){return this.cmpn(num)===0};BN.prototype.eq=function eq(num){return this.cmp(num)===0};BN.red=function red(num){return new Red(num)};BN.prototype.toRed=function toRed(ctx){assert(!this.red,"Already a number in reduction context");assert(this.negative===0,"red works only with positives");return ctx.convertTo(this)._forceRed(ctx)};BN.prototype.fromRed=function fromRed(){assert(this.red,"fromRed works only with numbers in reduction context");return this.red.convertFrom(this)};BN.prototype._forceRed=function _forceRed(ctx){this.red=ctx;return this};BN.prototype.forceRed=function forceRed(ctx){assert(!this.red,"Already a number in reduction context");return this._forceRed(ctx)};BN.prototype.redAdd=function redAdd(num){assert(this.red,"redAdd works only with red numbers");return this.red.add(this,num)};BN.prototype.redIAdd=function redIAdd(num){assert(this.red,"redIAdd works only with red numbers");return this.red.iadd(this,num)};BN.prototype.redSub=function redSub(num){assert(this.red,"redSub works only with red numbers");return this.red.sub(this,num)};BN.prototype.redISub=function redISub(num){assert(this.red,"redISub works only with red numbers");return this.red.isub(this,num)};BN.prototype.redShl=function redShl(num){assert(this.red,"redShl works only with red numbers");return this.red.shl(this,num)};BN.prototype.redMul=function redMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.mul(this,num)};BN.prototype.redIMul=function redIMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.imul(this,num)};BN.prototype.redSqr=function redSqr(){assert(this.red,"redSqr works only with red numbers");this.red._verify1(this);return this.red.sqr(this)};BN.prototype.redISqr=function redISqr(){assert(this.red,"redISqr works only with red numbers");this.red._verify1(this);return this.red.isqr(this)};BN.prototype.redSqrt=function redSqrt(){assert(this.red,"redSqrt works only with red numbers");this.red._verify1(this);return this.red.sqrt(this)};BN.prototype.redInvm=function redInvm(){assert(this.red,"redInvm works only with red numbers");this.red._verify1(this);return this.red.invm(this)};BN.prototype.redNeg=function redNeg(){assert(this.red,"redNeg works only with red numbers");this.red._verify1(this);return this.red.neg(this)};BN.prototype.redPow=function redPow(num){assert(this.red&&!num.red,"redPow(normalNum)");this.red._verify1(this);return this.red.pow(this,num)};var primes={k256:null,p224:null,p192:null,p25519:null};function MPrime(name,p){this.name=name;this.p=new BN(p,16);this.n=this.p.bitLength();this.k=new BN(1).iushln(this.n).isub(this.p);this.tmp=this._tmp()}MPrime.prototype._tmp=function _tmp(){var tmp=new BN(null);tmp.words=new Array(Math.ceil(this.n/13));return tmp};MPrime.prototype.ireduce=function ireduce(num){var r=num;var rlen;do{this.split(r,this.tmp);r=this.imulK(r);r=r.iadd(this.tmp);rlen=r.bitLength()}while(rlen>this.n);var cmp=rlen0){r.isub(this.p)}else{if(r.strip!==undefined){r.strip()}else{r._strip()}}return r};MPrime.prototype.split=function split(input,out){input.iushrn(this.n,0,out)};MPrime.prototype.imulK=function imulK(num){return num.imul(this.k)};function K256(){MPrime.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}inherits(K256,MPrime);K256.prototype.split=function split(input,output){var mask=4194303;var outLen=Math.min(input.length,9);for(var i=0;i>>22;prev=next}prev>>>=22;input.words[i-10]=prev;if(prev===0&&input.length>10){input.length-=10}else{input.length-=9}};K256.prototype.imulK=function imulK(num){num.words[num.length]=0;num.words[num.length+1]=0;num.length+=2;var lo=0;for(var i=0;i>>=26;num.words[i]=lo;carry=hi}if(carry!==0){num.words[num.length++]=carry}return num};BN._prime=function prime(name){if(primes[name])return primes[name];var prime;if(name==="k256"){prime=new K256}else if(name==="p224"){prime=new P224}else if(name==="p192"){prime=new P192}else if(name==="p25519"){prime=new P25519}else{throw new Error("Unknown prime "+name)}primes[name]=prime;return prime};function Red(m){if(typeof m==="string"){var prime=BN._prime(m);this.m=prime.p;this.prime=prime}else{assert(m.gtn(1),"modulus must be greater than 1");this.m=m;this.prime=null}}Red.prototype._verify1=function _verify1(a){assert(a.negative===0,"red works only with positives");assert(a.red,"red works only with red numbers")};Red.prototype._verify2=function _verify2(a,b){assert((a.negative|b.negative)===0,"red works only with positives");assert(a.red&&a.red===b.red,"red works only with red numbers")};Red.prototype.imod=function imod(a){if(this.prime)return this.prime.ireduce(a)._forceRed(this);return a.umod(this.m)._forceRed(this)};Red.prototype.neg=function neg(a){if(a.isZero()){return a.clone()}return this.m.sub(a)._forceRed(this)};Red.prototype.add=function add(a,b){this._verify2(a,b);var res=a.add(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res._forceRed(this)};Red.prototype.iadd=function iadd(a,b){this._verify2(a,b);var res=a.iadd(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res};Red.prototype.sub=function sub(a,b){this._verify2(a,b);var res=a.sub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res._forceRed(this)};Red.prototype.isub=function isub(a,b){this._verify2(a,b);var res=a.isub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res};Red.prototype.shl=function shl(a,num){this._verify1(a);return this.imod(a.ushln(num))};Red.prototype.imul=function imul(a,b){this._verify2(a,b);return this.imod(a.imul(b))};Red.prototype.mul=function mul(a,b){this._verify2(a,b);return this.imod(a.mul(b))};Red.prototype.isqr=function isqr(a){return this.imul(a,a.clone())};Red.prototype.sqr=function sqr(a){return this.mul(a,a)};Red.prototype.sqrt=function sqrt(a){if(a.isZero())return a.clone();var mod3=this.m.andln(3);assert(mod3%2===1);if(mod3===3){var pow=this.m.add(new BN(1)).iushrn(2);return this.pow(a,pow)}var q=this.m.subn(1);var s=0;while(!q.isZero()&&q.andln(1)===0){s++;q.iushrn(1)}assert(!q.isZero());var one=new BN(1).toRed(this);var nOne=one.redNeg();var lpow=this.m.subn(1).iushrn(1);var z=this.m.bitLength();z=new BN(2*z*z).toRed(this);while(this.pow(z,lpow).cmp(nOne)!==0){z.redIAdd(nOne)}var c=this.pow(z,q);var r=this.pow(a,q.addn(1).iushrn(1));var t=this.pow(a,q);var m=s;while(t.cmp(one)!==0){var tmp=t;for(var i=0;tmp.cmp(one)!==0;i++){tmp=tmp.redSqr()}assert(i=0;i--){var word=num.words[i];for(var j=start-1;j>=0;j--){var bit=word>>j&1;if(res!==wnd[0]){res=this.sqr(res)}if(bit===0&¤t===0){currentLen=0;continue}current<<=1;current|=bit;currentLen++;if(currentLen!==windowSize&&(i!==0||j!==0))continue;res=this.mul(res,wnd[current]);currentLen=0;current=0}start=26}return res};Red.prototype.convertTo=function convertTo(num){var r=num.umod(this.m);return r===num?r.clone():r};Red.prototype.convertFrom=function convertFrom(num){var res=num.clone();res.red=null;return res};BN.mont=function mont(num){return new Mont(num)};function Mont(m){Red.call(this,m);this.shift=this.m.bitLength();if(this.shift%26!==0){this.shift+=26-this.shift%26}this.r=new BN(1).iushln(this.shift);this.r2=this.imod(this.r.sqr());this.rinv=this.r._invmp(this.m);this.minv=this.rinv.mul(this.r).isubn(1).div(this.m);this.minv=this.minv.umod(this.r);this.minv=this.r.sub(this.minv)}inherits(Mont,Red);Mont.prototype.convertTo=function convertTo(num){return this.imod(num.ushln(this.shift))};Mont.prototype.convertFrom=function convertFrom(num){var r=this.imod(num.mul(this.rinv));r.red=null;return r};Mont.prototype.imul=function imul(a,b){if(a.isZero()||b.isZero()){a.words[0]=0;a.length=1;return a}var t=a.imul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.mul=function mul(a,b){if(a.isZero()||b.isZero())return new BN(0)._forceRed(this);var t=a.mul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.invm=function invm(a){var res=this.imod(a._invmp(this.m).mul(this.r2));return res._forceRed(this)}})(typeof module==="undefined"||module,this)},{buffer:131}],124:[function(require,module,exports){(function(global){(function(){"use strict";var objectAssign=require("object-assign");function compare(a,b){if(a===b){return 0}var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i=0){var next_line=out.indexOf("\n",idx+1);out=out.substring(next_line+1)}this.stack=out}}};util.inherits(assert.AssertionError,Error);function truncate(s,n){if(typeof s==="string"){return s.length=0;i--){if(ka[i]!==kb[i])return false}for(i=ka.length-1;i>=0;i--){key=ka[i];if(!_deepEqual(a[key],b[key],strict,actualVisitedObjects))return false}return true}assert.notDeepEqual=function notDeepEqual(actual,expected,message){if(_deepEqual(actual,expected,false)){fail(actual,expected,message,"notDeepEqual",assert.notDeepEqual)}};assert.notDeepStrictEqual=notDeepStrictEqual;function notDeepStrictEqual(actual,expected,message){if(_deepEqual(actual,expected,true)){fail(actual,expected,message,"notDeepStrictEqual",notDeepStrictEqual)}}assert.strictEqual=function strictEqual(actual,expected,message){if(actual!==expected){fail(actual,expected,message,"===",assert.strictEqual)}};assert.notStrictEqual=function notStrictEqual(actual,expected,message){if(actual===expected){fail(actual,expected,message,"!==",assert.notStrictEqual)}};function expectedException(actual,expected){if(!actual||!expected){return false}if(Object.prototype.toString.call(expected)=="[object RegExp]"){return expected.test(actual)}try{if(actual instanceof expected){return true}}catch(e){}if(Error.isPrototypeOf(expected)){return false}return expected.call({},actual)===true}function _tryBlock(block){var error;try{block()}catch(e){error=e}return error}function _throws(shouldThrow,block,expected,message){var actual;if(typeof block!=="function"){throw new TypeError('"block" argument must be a function')}if(typeof expected==="string"){message=expected;expected=null}actual=_tryBlock(block);message=(expected&&expected.name?" ("+expected.name+").":".")+(message?" "+message:".");if(shouldThrow&&!actual){fail(actual,expected,"Missing expected exception"+message)}var userProvidedMessage=typeof message==="string";var isUnwantedException=!shouldThrow&&util.isError(actual);var isUnexpectedException=!shouldThrow&&actual&&!expected;if(isUnwantedException&&userProvidedMessage&&expectedException(actual,expected)||isUnexpectedException){fail(actual,expected,"Got unwanted exception"+message)}if(shouldThrow&&actual&&expected&&!expectedException(actual,expected)||!shouldThrow&&actual){throw actual}}assert.throws=function(block,error,message){_throws(true,block,error,message)};assert.doesNotThrow=function(block,error,message){_throws(false,block,error,message)};assert.ifError=function(err){if(err)throw err};function strict(value,message){if(!value)fail(value,true,message,"==",strict)}assert.strict=objectAssign(strict,assert,{equal:assert.strictEqual,deepEqual:assert.deepStrictEqual,notEqual:assert.notStrictEqual,notDeepEqual:assert.notDeepStrictEqual});assert.strict.strict=assert.strict;var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj){if(hasOwn.call(obj,key))keys.push(key)}return keys}}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"object-assign":250,"util/":127}],125:[function(require,module,exports){arguments[4][101][0].apply(exports,arguments)},{dup:101}],126:[function(require,module,exports){module.exports=function isBuffer(arg){return arg&&typeof arg==="object"&&typeof arg.copy==="function"&&typeof arg.fill==="function"&&typeof arg.readUInt8==="function"}},{}],127:[function(require,module,exports){(function(process,global){(function(){var formatRegExp=/%[sdj%]/g;exports.format=function(f){if(!isString(f)){var objects=[];for(var i=0;i=len)return x;switch(x){case"%s":return String(args[i++]);case"%d":return Number(args[i++]);case"%j":try{return JSON.stringify(args[i++])}catch(_){return"[Circular]"}default:return x}});for(var x=args[i];i=3)ctx.depth=arguments[2];if(arguments.length>=4)ctx.colors=arguments[3];if(isBoolean(opts)){ctx.showHidden=opts}else if(opts){exports._extend(ctx,opts)}if(isUndefined(ctx.showHidden))ctx.showHidden=false;if(isUndefined(ctx.depth))ctx.depth=2;if(isUndefined(ctx.colors))ctx.colors=false;if(isUndefined(ctx.customInspect))ctx.customInspect=true;if(ctx.colors)ctx.stylize=stylizeWithColor;return formatValue(ctx,obj,ctx.depth)}exports.inspect=inspect;inspect.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]};inspect.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};function stylizeWithColor(str,styleType){var style=inspect.styles[styleType];if(style){return"["+inspect.colors[style][0]+"m"+str+"["+inspect.colors[style][1]+"m"}else{return str}}function stylizeNoColor(str,styleType){return str}function arrayToHash(array){var hash={};array.forEach(function(val,idx){hash[val]=true});return hash}function formatValue(ctx,value,recurseTimes){if(ctx.customInspect&&value&&isFunction(value.inspect)&&value.inspect!==exports.inspect&&!(value.constructor&&value.constructor.prototype===value)){var ret=value.inspect(recurseTimes,ctx);if(!isString(ret)){ret=formatValue(ctx,ret,recurseTimes)}return ret}var primitive=formatPrimitive(ctx,value);if(primitive){return primitive}var keys=Object.keys(value);var visibleKeys=arrayToHash(keys);if(ctx.showHidden){keys=Object.getOwnPropertyNames(value)}if(isError(value)&&(keys.indexOf("message")>=0||keys.indexOf("description")>=0)){return formatError(value)}if(keys.length===0){if(isFunction(value)){var name=value.name?": "+value.name:"";return ctx.stylize("[Function"+name+"]","special")}if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}if(isDate(value)){return ctx.stylize(Date.prototype.toString.call(value),"date")}if(isError(value)){return formatError(value)}}var base="",array=false,braces=["{","}"];if(isArray(value)){array=true;braces=["[","]"]}if(isFunction(value)){var n=value.name?": "+value.name:"";base=" [Function"+n+"]"}if(isRegExp(value)){base=" "+RegExp.prototype.toString.call(value)}if(isDate(value)){base=" "+Date.prototype.toUTCString.call(value)}if(isError(value)){base=" "+formatError(value)}if(keys.length===0&&(!array||value.length==0)){return braces[0]+base+braces[1]}if(recurseTimes<0){if(isRegExp(value)){return ctx.stylize(RegExp.prototype.toString.call(value),"regexp")}else{return ctx.stylize("[Object]","special")}}ctx.seen.push(value);var output;if(array){output=formatArray(ctx,value,recurseTimes,visibleKeys,keys)}else{output=keys.map(function(key){return formatProperty(ctx,value,recurseTimes,visibleKeys,key,array)})}ctx.seen.pop();return reduceToSingleString(output,base,braces)}function formatPrimitive(ctx,value){if(isUndefined(value))return ctx.stylize("undefined","undefined");if(isString(value)){var simple="'"+JSON.stringify(value).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return ctx.stylize(simple,"string")}if(isNumber(value))return ctx.stylize(""+value,"number");if(isBoolean(value))return ctx.stylize(""+value,"boolean");if(isNull(value))return ctx.stylize("null","null")}function formatError(value){return"["+Error.prototype.toString.call(value)+"]"}function formatArray(ctx,value,recurseTimes,visibleKeys,keys){var output=[];for(var i=0,l=value.length;i-1){if(array){str=str.split("\n").map(function(line){return" "+line}).join("\n").substr(2)}else{str="\n"+str.split("\n").map(function(line){return" "+line}).join("\n")}}}else{str=ctx.stylize("[Circular]","special")}}if(isUndefined(name)){if(array&&key.match(/^\d+$/)){return str}name=JSON.stringify(""+key);if(name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)){name=name.substr(1,name.length-2);name=ctx.stylize(name,"name")}else{name=name.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'");name=ctx.stylize(name,"string")}}return name+": "+str}function reduceToSingleString(output,base,braces){var numLinesEst=0;var length=output.reduce(function(prev,cur){numLinesEst++;if(cur.indexOf("\n")>=0)numLinesEst++;return prev+cur.replace(/\u001b\[\d\d?m/g,"").length+1},0);if(length>60){return braces[0]+(base===""?"":base+"\n ")+" "+output.join(",\n ")+" "+braces[1]}return braces[0]+base+" "+output.join(", ")+" "+braces[1]}function isArray(ar){return Array.isArray(ar)}exports.isArray=isArray;function isBoolean(arg){return typeof arg==="boolean"}exports.isBoolean=isBoolean;function isNull(arg){return arg===null}exports.isNull=isNull;function isNullOrUndefined(arg){return arg==null}exports.isNullOrUndefined=isNullOrUndefined;function isNumber(arg){return typeof arg==="number"}exports.isNumber=isNumber;function isString(arg){return typeof arg==="string"}exports.isString=isString;function isSymbol(arg){return typeof arg==="symbol"}exports.isSymbol=isSymbol;function isUndefined(arg){return arg===void 0}exports.isUndefined=isUndefined;function isRegExp(re){return isObject(re)&&objectToString(re)==="[object RegExp]"}exports.isRegExp=isRegExp;function isObject(arg){return typeof arg==="object"&&arg!==null}exports.isObject=isObject;function isDate(d){return isObject(d)&&objectToString(d)==="[object Date]"}exports.isDate=isDate;function isError(e){return isObject(e)&&(objectToString(e)==="[object Error]"||e instanceof Error)}exports.isError=isError;function isFunction(arg){return typeof arg==="function"}exports.isFunction=isFunction;function isPrimitive(arg){return arg===null||typeof arg==="boolean"||typeof arg==="number"||typeof arg==="string"||typeof arg==="symbol"||typeof arg==="undefined"}exports.isPrimitive=isPrimitive;exports.isBuffer=require("./support/isBuffer");function objectToString(o){return Object.prototype.toString.call(o)}function pad(n){return n<10?"0"+n.toString(10):n.toString(10)}var months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function timestamp(){var d=new Date;var time=[pad(d.getHours()),pad(d.getMinutes()),pad(d.getSeconds())].join(":");return[d.getDate(),months[d.getMonth()],time].join(" ")}exports.log=function(){console.log("%s - %s",timestamp(),exports.format.apply(exports,arguments))};exports.inherits=require("inherits");exports._extend=function(origin,add){if(!add||!isObject(add))return origin;var keys=Object.keys(add);var i=keys.length;while(i--){origin[keys[i]]=add[keys[i]]}return origin};function hasOwnProperty(obj,prop){return Object.prototype.hasOwnProperty.call(obj,prop)}}).call(this)}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{"./support/isBuffer":126,_process:262,inherits:125}],128:[function(require,module,exports){"use strict";exports.byteLength=byteLength;exports.toByteArray=toByteArray;exports.fromByteArray=fromByteArray;var lookup=[];var revLookup=[];var Arr=typeof Uint8Array!=="undefined"?Uint8Array:Array;var code="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(var i=0,len=code.length;i0){throw new Error("Invalid string. Length must be a multiple of 4")}var validLen=b64.indexOf("=");if(validLen===-1)validLen=len;var placeHoldersLen=validLen===len?0:4-validLen%4;return[validLen,placeHoldersLen]}function byteLength(b64){var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function _byteLength(b64,validLen,placeHoldersLen){return(validLen+placeHoldersLen)*3/4-placeHoldersLen}function toByteArray(b64){var tmp;var lens=getLens(b64);var validLen=lens[0];var placeHoldersLen=lens[1];var arr=new Arr(_byteLength(b64,validLen,placeHoldersLen));var curByte=0;var len=placeHoldersLen>0?validLen-4:validLen;var i;for(i=0;i>16&255;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}if(placeHoldersLen===2){tmp=revLookup[b64.charCodeAt(i)]<<2|revLookup[b64.charCodeAt(i+1)]>>4;arr[curByte++]=tmp&255}if(placeHoldersLen===1){tmp=revLookup[b64.charCodeAt(i)]<<10|revLookup[b64.charCodeAt(i+1)]<<4|revLookup[b64.charCodeAt(i+2)]>>2;arr[curByte++]=tmp>>8&255;arr[curByte++]=tmp&255}return arr}function tripletToBase64(num){return lookup[num>>18&63]+lookup[num>>12&63]+lookup[num>>6&63]+lookup[num&63]}function encodeChunk(uint8,start,end){var tmp;var output=[];for(var i=start;ilen2?len2:i+maxChunkLength))}if(extraBytes===1){tmp=uint8[len-1];parts.push(lookup[tmp>>2]+lookup[tmp<<4&63]+"==")}else if(extraBytes===2){tmp=(uint8[len-2]<<8)+uint8[len-1];parts.push(lookup[tmp>>10]+lookup[tmp>>4&63]+lookup[tmp<<2&63]+"=")}return parts.join("")}},{}],129:[function(require,module,exports){(function(module,exports){"use strict";function assert(val,msg){if(!val)throw new Error(msg||"Assertion failed")}function inherits(ctor,superCtor){ctor.super_=superCtor;var TempCtor=function(){};TempCtor.prototype=superCtor.prototype;ctor.prototype=new TempCtor;ctor.prototype.constructor=ctor}function BN(number,base,endian){if(BN.isBN(number)){return number}this.negative=0;this.words=null;this.length=0;this.red=null;if(number!==null){if(base==="le"||base==="be"){endian=base;base=10}this._init(number||0,base||10,endian||"be")}}if(typeof module==="object"){module.exports=BN}else{exports.BN=BN}BN.BN=BN;BN.wordSize=26;var Buffer;try{if(typeof window!=="undefined"&&typeof window.Buffer!=="undefined"){Buffer=window.Buffer}else{Buffer=require("buffer").Buffer}}catch(e){}BN.isBN=function isBN(num){if(num instanceof BN){return true}return num!==null&&typeof num==="object"&&num.constructor.wordSize===BN.wordSize&&Array.isArray(num.words)};BN.max=function max(left,right){if(left.cmp(right)>0)return left;return right};BN.min=function min(left,right){if(left.cmp(right)<0)return left;return right};BN.prototype._init=function init(number,base,endian){if(typeof number==="number"){return this._initNumber(number,base,endian)}if(typeof number==="object"){return this._initArray(number,base,endian)}if(base==="hex"){base=16}assert(base===(base|0)&&base>=2&&base<=36);number=number.toString().replace(/\s+/g,"");var start=0;if(number[0]==="-"){start++;this.negative=1}if(start=0;i-=3){w=number[i]|number[i-1]<<8|number[i-2]<<16;this.words[j]|=w<>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}else if(endian==="le"){for(i=0,j=0;i>>26-off&67108863;off+=24;if(off>=26){off-=26;j++}}}return this._strip()};function parseHex4Bits(string,index){var c=string.charCodeAt(index);if(c>=48&&c<=57){return c-48}else if(c>=65&&c<=70){return c-55}else if(c>=97&&c<=102){return c-87}else{assert(false,"Invalid character in "+string)}}function parseHexByte(string,lowerBound,index){var r=parseHex4Bits(string,index);if(index-1>=lowerBound){r|=parseHex4Bits(string,index-1)<<4}return r}BN.prototype._parseHex=function _parseHex(number,start,endian){this.length=Math.ceil((number.length-start)/6);this.words=new Array(this.length);for(var i=0;i=start;i-=2){w=parseHexByte(number,start,i)<=18){off-=18;j+=1;this.words[j]|=w>>>26}else{off+=8}}}else{var parseLength=number.length-start;for(i=parseLength%2===0?start+1:start;i=18){off-=18;j+=1;this.words[j]|=w>>>26}else{off+=8}}}this._strip()};function parseBase(str,start,end,mul){var r=0;var b=0;var len=Math.min(str.length,end);for(var i=start;i=49){b=c-49+10}else if(c>=17){b=c-17+10}else{b=c}assert(c>=0&&b1&&this.words[this.length-1]===0){this.length--}return this._normSign()};BN.prototype._normSign=function _normSign(){if(this.length===1&&this.words[0]===0){this.negative=0}return this};if(typeof Symbol!=="undefined"&&typeof Symbol.for==="function"){try{BN.prototype[Symbol.for("nodejs.util.inspect.custom")]=inspect}catch(e){BN.prototype.inspect=inspect}}else{BN.prototype.inspect=inspect}function inspect(){return(this.red?""}var zeros=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"];var groupSizes=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5];var groupBases=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];BN.prototype.toString=function toString(base,padding){base=base||10;padding=padding|0||1;var out;if(base===16||base==="hex"){out="";var off=0;var carry=0;for(var i=0;i>>24-off&16777215;if(carry!==0||i!==this.length-1){out=zeros[6-word.length]+word+out}else{out=word+out}off+=2;if(off>=26){off-=26;i--}}if(carry!==0){out=carry.toString(16)+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}if(base===(base|0)&&base>=2&&base<=36){var groupSize=groupSizes[base];var groupBase=groupBases[base];out="";var c=this.clone();c.negative=0;while(!c.isZero()){var r=c.modrn(groupBase).toString(base);c=c.idivn(groupBase);if(!c.isZero()){out=zeros[groupSize-r.length]+r+out}else{out=r+out}}if(this.isZero()){out="0"+out}while(out.length%padding!==0){out="0"+out}if(this.negative!==0){out="-"+out}return out}assert(false,"Base should be between 2 and 36")};BN.prototype.toNumber=function toNumber(){var ret=this.words[0];if(this.length===2){ret+=this.words[1]*67108864}else if(this.length===3&&this.words[2]===1){ret+=4503599627370496+this.words[1]*67108864}else if(this.length>2){assert(false,"Number can only safely store up to 53 bits")}return this.negative!==0?-ret:ret};BN.prototype.toJSON=function toJSON(){return this.toString(16,2)};if(Buffer){BN.prototype.toBuffer=function toBuffer(endian,length){return this.toArrayLike(Buffer,endian,length)}}BN.prototype.toArray=function toArray(endian,length){return this.toArrayLike(Array,endian,length)};var allocate=function allocate(ArrayType,size){if(ArrayType.allocUnsafe){return ArrayType.allocUnsafe(size)}return new ArrayType(size)};BN.prototype.toArrayLike=function toArrayLike(ArrayType,endian,length){this._strip();var byteLength=this.byteLength();var reqLength=length||Math.max(1,byteLength);assert(byteLength<=reqLength,"byte array longer than desired length");assert(reqLength>0,"Requested array length <= 0");var res=allocate(ArrayType,reqLength);var postfix=endian==="le"?"LE":"BE";this["_toArrayLike"+postfix](res,byteLength);return res};BN.prototype._toArrayLikeLE=function _toArrayLikeLE(res,byteLength){var position=0;var carry=0;for(var i=0,shift=0;i>8&255}if(position>16&255}if(shift===6){if(position>24&255}carry=0;shift=0}else{carry=word>>>24;shift+=2}}if(position=0){res[position--]=word>>8&255}if(position>=0){res[position--]=word>>16&255}if(shift===6){if(position>=0){res[position--]=word>>24&255}carry=0;shift=0}else{carry=word>>>24;shift+=2}}if(position>=0){res[position--]=carry;while(position>=0){res[position--]=0}}};if(Math.clz32){BN.prototype._countBits=function _countBits(w){return 32-Math.clz32(w)}}else{BN.prototype._countBits=function _countBits(w){var t=w;var r=0;if(t>=4096){r+=13;t>>>=13}if(t>=64){r+=7;t>>>=7}if(t>=8){r+=4;t>>>=4}if(t>=2){r+=2;t>>>=2}return r+t}}BN.prototype._zeroBits=function _zeroBits(w){if(w===0)return 26;var t=w;var r=0;if((t&8191)===0){r+=13;t>>>=13}if((t&127)===0){r+=7;t>>>=7}if((t&15)===0){r+=4;t>>>=4}if((t&3)===0){r+=2;t>>>=2}if((t&1)===0){r++}return r};BN.prototype.bitLength=function bitLength(){var w=this.words[this.length-1];var hi=this._countBits(w);return(this.length-1)*26+hi};function toBitArray(num){var w=new Array(num.bitLength());for(var bit=0;bit>>wbit&1}return w}BN.prototype.zeroBits=function zeroBits(){if(this.isZero())return 0;var r=0;for(var i=0;inum.length)return this.clone().ior(num);return num.clone().ior(this)};BN.prototype.uor=function uor(num){if(this.length>num.length)return this.clone().iuor(num);return num.clone().iuor(this)};BN.prototype.iuand=function iuand(num){var b;if(this.length>num.length){b=num}else{b=this}for(var i=0;inum.length)return this.clone().iand(num);return num.clone().iand(this)};BN.prototype.uand=function uand(num){if(this.length>num.length)return this.clone().iuand(num);return num.clone().iuand(this)};BN.prototype.iuxor=function iuxor(num){var a;var b;if(this.length>num.length){a=this;b=num}else{a=num;b=this}for(var i=0;inum.length)return this.clone().ixor(num);return num.clone().ixor(this)};BN.prototype.uxor=function uxor(num){if(this.length>num.length)return this.clone().iuxor(num);return num.clone().iuxor(this)};BN.prototype.inotn=function inotn(width){assert(typeof width==="number"&&width>=0);var bytesNeeded=Math.ceil(width/26)|0;var bitsLeft=width%26;this._expand(bytesNeeded);if(bitsLeft>0){bytesNeeded--}for(var i=0;i0){this.words[i]=~this.words[i]&67108863>>26-bitsLeft}return this._strip()};BN.prototype.notn=function notn(width){return this.clone().inotn(width)};BN.prototype.setn=function setn(bit,val){assert(typeof bit==="number"&&bit>=0);var off=bit/26|0;var wbit=bit%26;this._expand(off+1);if(val){this.words[off]=this.words[off]|1<num.length){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>>26}for(;carry!==0&&i>>26}this.length=a.length;if(carry!==0){this.words[this.length]=carry;this.length++}else if(a!==this){for(;inum.length)return this.clone().iadd(num);return num.clone().iadd(this)};BN.prototype.isub=function isub(num){if(num.negative!==0){num.negative=0;var r=this.iadd(num);num.negative=1;return r._normSign()}else if(this.negative!==0){this.negative=0;this.iadd(num);this.negative=1;return this._normSign()}var cmp=this.cmp(num);if(cmp===0){this.negative=0;this.length=1;this.words[0]=0;return this}var a,b;if(cmp>0){a=this;b=num}else{a=num;b=this}var carry=0;for(var i=0;i>26;this.words[i]=r&67108863}for(;carry!==0&&i>26;this.words[i]=r&67108863}if(carry===0&&i>>26;var rword=carry&67108863;var maxJ=Math.min(k,num.length-1);for(var j=Math.max(0,k-self.length+1);j<=maxJ;j++){var i=k-j|0;a=self.words[i]|0;b=num.words[j]|0;r=a*b+rword;ncarry+=r/67108864|0;rword=r&67108863}out.words[k]=rword|0;carry=ncarry|0}if(carry!==0){out.words[k]=carry|0}else{out.length--}return out._strip()}var comb10MulTo=function comb10MulTo(self,num,out){var a=self.words;var b=num.words;var o=out.words;var c=0;var lo;var mid;var hi;var a0=a[0]|0;var al0=a0&8191;var ah0=a0>>>13;var a1=a[1]|0;var al1=a1&8191;var ah1=a1>>>13;var a2=a[2]|0;var al2=a2&8191;var ah2=a2>>>13;var a3=a[3]|0;var al3=a3&8191;var ah3=a3>>>13;var a4=a[4]|0;var al4=a4&8191;var ah4=a4>>>13;var a5=a[5]|0;var al5=a5&8191;var ah5=a5>>>13;var a6=a[6]|0;var al6=a6&8191;var ah6=a6>>>13;var a7=a[7]|0;var al7=a7&8191;var ah7=a7>>>13;var a8=a[8]|0;var al8=a8&8191;var ah8=a8>>>13;var a9=a[9]|0;var al9=a9&8191;var ah9=a9>>>13;var b0=b[0]|0;var bl0=b0&8191;var bh0=b0>>>13;var b1=b[1]|0;var bl1=b1&8191;var bh1=b1>>>13;var b2=b[2]|0;var bl2=b2&8191;var bh2=b2>>>13;var b3=b[3]|0;var bl3=b3&8191;var bh3=b3>>>13;var b4=b[4]|0;var bl4=b4&8191;var bh4=b4>>>13;var b5=b[5]|0;var bl5=b5&8191;var bh5=b5>>>13;var b6=b[6]|0;var bl6=b6&8191;var bh6=b6>>>13;var b7=b[7]|0;var bl7=b7&8191;var bh7=b7>>>13;var b8=b[8]|0;var bl8=b8&8191;var bh8=b8>>>13;var b9=b[9]|0;var bl9=b9&8191;var bh9=b9>>>13;out.negative=self.negative^num.negative;out.length=19;lo=Math.imul(al0,bl0);mid=Math.imul(al0,bh0);mid=mid+Math.imul(ah0,bl0)|0;hi=Math.imul(ah0,bh0);var w0=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w0>>>26)|0;w0&=67108863;lo=Math.imul(al1,bl0);mid=Math.imul(al1,bh0);mid=mid+Math.imul(ah1,bl0)|0;hi=Math.imul(ah1,bh0);lo=lo+Math.imul(al0,bl1)|0;mid=mid+Math.imul(al0,bh1)|0;mid=mid+Math.imul(ah0,bl1)|0;hi=hi+Math.imul(ah0,bh1)|0;var w1=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w1>>>26)|0;w1&=67108863;lo=Math.imul(al2,bl0);mid=Math.imul(al2,bh0);mid=mid+Math.imul(ah2,bl0)|0;hi=Math.imul(ah2,bh0);lo=lo+Math.imul(al1,bl1)|0;mid=mid+Math.imul(al1,bh1)|0;mid=mid+Math.imul(ah1,bl1)|0;hi=hi+Math.imul(ah1,bh1)|0;lo=lo+Math.imul(al0,bl2)|0;mid=mid+Math.imul(al0,bh2)|0;mid=mid+Math.imul(ah0,bl2)|0;hi=hi+Math.imul(ah0,bh2)|0;var w2=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w2>>>26)|0;w2&=67108863;lo=Math.imul(al3,bl0);mid=Math.imul(al3,bh0);mid=mid+Math.imul(ah3,bl0)|0;hi=Math.imul(ah3,bh0);lo=lo+Math.imul(al2,bl1)|0;mid=mid+Math.imul(al2,bh1)|0;mid=mid+Math.imul(ah2,bl1)|0;hi=hi+Math.imul(ah2,bh1)|0;lo=lo+Math.imul(al1,bl2)|0;mid=mid+Math.imul(al1,bh2)|0;mid=mid+Math.imul(ah1,bl2)|0;hi=hi+Math.imul(ah1,bh2)|0;lo=lo+Math.imul(al0,bl3)|0;mid=mid+Math.imul(al0,bh3)|0;mid=mid+Math.imul(ah0,bl3)|0;hi=hi+Math.imul(ah0,bh3)|0;var w3=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w3>>>26)|0;w3&=67108863;lo=Math.imul(al4,bl0);mid=Math.imul(al4,bh0);mid=mid+Math.imul(ah4,bl0)|0;hi=Math.imul(ah4,bh0);lo=lo+Math.imul(al3,bl1)|0;mid=mid+Math.imul(al3,bh1)|0;mid=mid+Math.imul(ah3,bl1)|0;hi=hi+Math.imul(ah3,bh1)|0;lo=lo+Math.imul(al2,bl2)|0;mid=mid+Math.imul(al2,bh2)|0;mid=mid+Math.imul(ah2,bl2)|0;hi=hi+Math.imul(ah2,bh2)|0;lo=lo+Math.imul(al1,bl3)|0;mid=mid+Math.imul(al1,bh3)|0;mid=mid+Math.imul(ah1,bl3)|0;hi=hi+Math.imul(ah1,bh3)|0;lo=lo+Math.imul(al0,bl4)|0;mid=mid+Math.imul(al0,bh4)|0;mid=mid+Math.imul(ah0,bl4)|0;hi=hi+Math.imul(ah0,bh4)|0;var w4=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w4>>>26)|0;w4&=67108863;lo=Math.imul(al5,bl0);mid=Math.imul(al5,bh0);mid=mid+Math.imul(ah5,bl0)|0;hi=Math.imul(ah5,bh0);lo=lo+Math.imul(al4,bl1)|0;mid=mid+Math.imul(al4,bh1)|0;mid=mid+Math.imul(ah4,bl1)|0;hi=hi+Math.imul(ah4,bh1)|0;lo=lo+Math.imul(al3,bl2)|0;mid=mid+Math.imul(al3,bh2)|0;mid=mid+Math.imul(ah3,bl2)|0;hi=hi+Math.imul(ah3,bh2)|0;lo=lo+Math.imul(al2,bl3)|0;mid=mid+Math.imul(al2,bh3)|0;mid=mid+Math.imul(ah2,bl3)|0;hi=hi+Math.imul(ah2,bh3)|0;lo=lo+Math.imul(al1,bl4)|0;mid=mid+Math.imul(al1,bh4)|0;mid=mid+Math.imul(ah1,bl4)|0;hi=hi+Math.imul(ah1,bh4)|0;lo=lo+Math.imul(al0,bl5)|0;mid=mid+Math.imul(al0,bh5)|0;mid=mid+Math.imul(ah0,bl5)|0;hi=hi+Math.imul(ah0,bh5)|0;var w5=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w5>>>26)|0;w5&=67108863;lo=Math.imul(al6,bl0);mid=Math.imul(al6,bh0);mid=mid+Math.imul(ah6,bl0)|0;hi=Math.imul(ah6,bh0);lo=lo+Math.imul(al5,bl1)|0;mid=mid+Math.imul(al5,bh1)|0;mid=mid+Math.imul(ah5,bl1)|0;hi=hi+Math.imul(ah5,bh1)|0;lo=lo+Math.imul(al4,bl2)|0;mid=mid+Math.imul(al4,bh2)|0;mid=mid+Math.imul(ah4,bl2)|0;hi=hi+Math.imul(ah4,bh2)|0;lo=lo+Math.imul(al3,bl3)|0;mid=mid+Math.imul(al3,bh3)|0;mid=mid+Math.imul(ah3,bl3)|0;hi=hi+Math.imul(ah3,bh3)|0;lo=lo+Math.imul(al2,bl4)|0;mid=mid+Math.imul(al2,bh4)|0;mid=mid+Math.imul(ah2,bl4)|0;hi=hi+Math.imul(ah2,bh4)|0;lo=lo+Math.imul(al1,bl5)|0;mid=mid+Math.imul(al1,bh5)|0;mid=mid+Math.imul(ah1,bl5)|0;hi=hi+Math.imul(ah1,bh5)|0;lo=lo+Math.imul(al0,bl6)|0;mid=mid+Math.imul(al0,bh6)|0;mid=mid+Math.imul(ah0,bl6)|0;hi=hi+Math.imul(ah0,bh6)|0;var w6=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w6>>>26)|0;w6&=67108863;lo=Math.imul(al7,bl0);mid=Math.imul(al7,bh0);mid=mid+Math.imul(ah7,bl0)|0;hi=Math.imul(ah7,bh0);lo=lo+Math.imul(al6,bl1)|0;mid=mid+Math.imul(al6,bh1)|0;mid=mid+Math.imul(ah6,bl1)|0;hi=hi+Math.imul(ah6,bh1)|0;lo=lo+Math.imul(al5,bl2)|0;mid=mid+Math.imul(al5,bh2)|0;mid=mid+Math.imul(ah5,bl2)|0;hi=hi+Math.imul(ah5,bh2)|0;lo=lo+Math.imul(al4,bl3)|0;mid=mid+Math.imul(al4,bh3)|0;mid=mid+Math.imul(ah4,bl3)|0;hi=hi+Math.imul(ah4,bh3)|0;lo=lo+Math.imul(al3,bl4)|0;mid=mid+Math.imul(al3,bh4)|0;mid=mid+Math.imul(ah3,bl4)|0;hi=hi+Math.imul(ah3,bh4)|0;lo=lo+Math.imul(al2,bl5)|0;mid=mid+Math.imul(al2,bh5)|0;mid=mid+Math.imul(ah2,bl5)|0;hi=hi+Math.imul(ah2,bh5)|0;lo=lo+Math.imul(al1,bl6)|0;mid=mid+Math.imul(al1,bh6)|0;mid=mid+Math.imul(ah1,bl6)|0;hi=hi+Math.imul(ah1,bh6)|0;lo=lo+Math.imul(al0,bl7)|0;mid=mid+Math.imul(al0,bh7)|0;mid=mid+Math.imul(ah0,bl7)|0;hi=hi+Math.imul(ah0,bh7)|0;var w7=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w7>>>26)|0;w7&=67108863;lo=Math.imul(al8,bl0);mid=Math.imul(al8,bh0);mid=mid+Math.imul(ah8,bl0)|0;hi=Math.imul(ah8,bh0);lo=lo+Math.imul(al7,bl1)|0;mid=mid+Math.imul(al7,bh1)|0;mid=mid+Math.imul(ah7,bl1)|0;hi=hi+Math.imul(ah7,bh1)|0;lo=lo+Math.imul(al6,bl2)|0;mid=mid+Math.imul(al6,bh2)|0;mid=mid+Math.imul(ah6,bl2)|0;hi=hi+Math.imul(ah6,bh2)|0;lo=lo+Math.imul(al5,bl3)|0;mid=mid+Math.imul(al5,bh3)|0;mid=mid+Math.imul(ah5,bl3)|0;hi=hi+Math.imul(ah5,bh3)|0;lo=lo+Math.imul(al4,bl4)|0;mid=mid+Math.imul(al4,bh4)|0;mid=mid+Math.imul(ah4,bl4)|0;hi=hi+Math.imul(ah4,bh4)|0;lo=lo+Math.imul(al3,bl5)|0;mid=mid+Math.imul(al3,bh5)|0;mid=mid+Math.imul(ah3,bl5)|0;hi=hi+Math.imul(ah3,bh5)|0;lo=lo+Math.imul(al2,bl6)|0;mid=mid+Math.imul(al2,bh6)|0;mid=mid+Math.imul(ah2,bl6)|0;hi=hi+Math.imul(ah2,bh6)|0;lo=lo+Math.imul(al1,bl7)|0;mid=mid+Math.imul(al1,bh7)|0;mid=mid+Math.imul(ah1,bl7)|0;hi=hi+Math.imul(ah1,bh7)|0;lo=lo+Math.imul(al0,bl8)|0;mid=mid+Math.imul(al0,bh8)|0;mid=mid+Math.imul(ah0,bl8)|0;hi=hi+Math.imul(ah0,bh8)|0;var w8=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w8>>>26)|0;w8&=67108863;lo=Math.imul(al9,bl0);mid=Math.imul(al9,bh0);mid=mid+Math.imul(ah9,bl0)|0;hi=Math.imul(ah9,bh0);lo=lo+Math.imul(al8,bl1)|0;mid=mid+Math.imul(al8,bh1)|0;mid=mid+Math.imul(ah8,bl1)|0;hi=hi+Math.imul(ah8,bh1)|0;lo=lo+Math.imul(al7,bl2)|0;mid=mid+Math.imul(al7,bh2)|0;mid=mid+Math.imul(ah7,bl2)|0;hi=hi+Math.imul(ah7,bh2)|0;lo=lo+Math.imul(al6,bl3)|0;mid=mid+Math.imul(al6,bh3)|0;mid=mid+Math.imul(ah6,bl3)|0;hi=hi+Math.imul(ah6,bh3)|0;lo=lo+Math.imul(al5,bl4)|0;mid=mid+Math.imul(al5,bh4)|0;mid=mid+Math.imul(ah5,bl4)|0;hi=hi+Math.imul(ah5,bh4)|0;lo=lo+Math.imul(al4,bl5)|0;mid=mid+Math.imul(al4,bh5)|0;mid=mid+Math.imul(ah4,bl5)|0;hi=hi+Math.imul(ah4,bh5)|0;lo=lo+Math.imul(al3,bl6)|0;mid=mid+Math.imul(al3,bh6)|0;mid=mid+Math.imul(ah3,bl6)|0;hi=hi+Math.imul(ah3,bh6)|0;lo=lo+Math.imul(al2,bl7)|0;mid=mid+Math.imul(al2,bh7)|0;mid=mid+Math.imul(ah2,bl7)|0;hi=hi+Math.imul(ah2,bh7)|0;lo=lo+Math.imul(al1,bl8)|0;mid=mid+Math.imul(al1,bh8)|0;mid=mid+Math.imul(ah1,bl8)|0;hi=hi+Math.imul(ah1,bh8)|0;lo=lo+Math.imul(al0,bl9)|0;mid=mid+Math.imul(al0,bh9)|0;mid=mid+Math.imul(ah0,bl9)|0;hi=hi+Math.imul(ah0,bh9)|0;var w9=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w9>>>26)|0;w9&=67108863;lo=Math.imul(al9,bl1);mid=Math.imul(al9,bh1);mid=mid+Math.imul(ah9,bl1)|0;hi=Math.imul(ah9,bh1);lo=lo+Math.imul(al8,bl2)|0;mid=mid+Math.imul(al8,bh2)|0;mid=mid+Math.imul(ah8,bl2)|0;hi=hi+Math.imul(ah8,bh2)|0;lo=lo+Math.imul(al7,bl3)|0;mid=mid+Math.imul(al7,bh3)|0;mid=mid+Math.imul(ah7,bl3)|0;hi=hi+Math.imul(ah7,bh3)|0;lo=lo+Math.imul(al6,bl4)|0;mid=mid+Math.imul(al6,bh4)|0;mid=mid+Math.imul(ah6,bl4)|0;hi=hi+Math.imul(ah6,bh4)|0;lo=lo+Math.imul(al5,bl5)|0;mid=mid+Math.imul(al5,bh5)|0;mid=mid+Math.imul(ah5,bl5)|0;hi=hi+Math.imul(ah5,bh5)|0;lo=lo+Math.imul(al4,bl6)|0;mid=mid+Math.imul(al4,bh6)|0;mid=mid+Math.imul(ah4,bl6)|0;hi=hi+Math.imul(ah4,bh6)|0;lo=lo+Math.imul(al3,bl7)|0;mid=mid+Math.imul(al3,bh7)|0;mid=mid+Math.imul(ah3,bl7)|0;hi=hi+Math.imul(ah3,bh7)|0;lo=lo+Math.imul(al2,bl8)|0;mid=mid+Math.imul(al2,bh8)|0;mid=mid+Math.imul(ah2,bl8)|0;hi=hi+Math.imul(ah2,bh8)|0;lo=lo+Math.imul(al1,bl9)|0;mid=mid+Math.imul(al1,bh9)|0;mid=mid+Math.imul(ah1,bl9)|0;hi=hi+Math.imul(ah1,bh9)|0;var w10=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w10>>>26)|0;w10&=67108863;lo=Math.imul(al9,bl2);mid=Math.imul(al9,bh2);mid=mid+Math.imul(ah9,bl2)|0;hi=Math.imul(ah9,bh2);lo=lo+Math.imul(al8,bl3)|0;mid=mid+Math.imul(al8,bh3)|0;mid=mid+Math.imul(ah8,bl3)|0;hi=hi+Math.imul(ah8,bh3)|0;lo=lo+Math.imul(al7,bl4)|0;mid=mid+Math.imul(al7,bh4)|0;mid=mid+Math.imul(ah7,bl4)|0;hi=hi+Math.imul(ah7,bh4)|0;lo=lo+Math.imul(al6,bl5)|0;mid=mid+Math.imul(al6,bh5)|0;mid=mid+Math.imul(ah6,bl5)|0;hi=hi+Math.imul(ah6,bh5)|0;lo=lo+Math.imul(al5,bl6)|0;mid=mid+Math.imul(al5,bh6)|0;mid=mid+Math.imul(ah5,bl6)|0;hi=hi+Math.imul(ah5,bh6)|0;lo=lo+Math.imul(al4,bl7)|0;mid=mid+Math.imul(al4,bh7)|0;mid=mid+Math.imul(ah4,bl7)|0;hi=hi+Math.imul(ah4,bh7)|0;lo=lo+Math.imul(al3,bl8)|0;mid=mid+Math.imul(al3,bh8)|0;mid=mid+Math.imul(ah3,bl8)|0;hi=hi+Math.imul(ah3,bh8)|0;lo=lo+Math.imul(al2,bl9)|0;mid=mid+Math.imul(al2,bh9)|0;mid=mid+Math.imul(ah2,bl9)|0;hi=hi+Math.imul(ah2,bh9)|0;var w11=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w11>>>26)|0;w11&=67108863;lo=Math.imul(al9,bl3);mid=Math.imul(al9,bh3);mid=mid+Math.imul(ah9,bl3)|0;hi=Math.imul(ah9,bh3);lo=lo+Math.imul(al8,bl4)|0;mid=mid+Math.imul(al8,bh4)|0;mid=mid+Math.imul(ah8,bl4)|0;hi=hi+Math.imul(ah8,bh4)|0;lo=lo+Math.imul(al7,bl5)|0;mid=mid+Math.imul(al7,bh5)|0;mid=mid+Math.imul(ah7,bl5)|0;hi=hi+Math.imul(ah7,bh5)|0;lo=lo+Math.imul(al6,bl6)|0;mid=mid+Math.imul(al6,bh6)|0;mid=mid+Math.imul(ah6,bl6)|0;hi=hi+Math.imul(ah6,bh6)|0;lo=lo+Math.imul(al5,bl7)|0;mid=mid+Math.imul(al5,bh7)|0;mid=mid+Math.imul(ah5,bl7)|0;hi=hi+Math.imul(ah5,bh7)|0;lo=lo+Math.imul(al4,bl8)|0;mid=mid+Math.imul(al4,bh8)|0;mid=mid+Math.imul(ah4,bl8)|0;hi=hi+Math.imul(ah4,bh8)|0;lo=lo+Math.imul(al3,bl9)|0;mid=mid+Math.imul(al3,bh9)|0;mid=mid+Math.imul(ah3,bl9)|0;hi=hi+Math.imul(ah3,bh9)|0;var w12=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w12>>>26)|0;w12&=67108863;lo=Math.imul(al9,bl4);mid=Math.imul(al9,bh4);mid=mid+Math.imul(ah9,bl4)|0;hi=Math.imul(ah9,bh4);lo=lo+Math.imul(al8,bl5)|0;mid=mid+Math.imul(al8,bh5)|0;mid=mid+Math.imul(ah8,bl5)|0;hi=hi+Math.imul(ah8,bh5)|0;lo=lo+Math.imul(al7,bl6)|0;mid=mid+Math.imul(al7,bh6)|0;mid=mid+Math.imul(ah7,bl6)|0;hi=hi+Math.imul(ah7,bh6)|0;lo=lo+Math.imul(al6,bl7)|0;mid=mid+Math.imul(al6,bh7)|0;mid=mid+Math.imul(ah6,bl7)|0;hi=hi+Math.imul(ah6,bh7)|0;lo=lo+Math.imul(al5,bl8)|0;mid=mid+Math.imul(al5,bh8)|0;mid=mid+Math.imul(ah5,bl8)|0;hi=hi+Math.imul(ah5,bh8)|0;lo=lo+Math.imul(al4,bl9)|0;mid=mid+Math.imul(al4,bh9)|0;mid=mid+Math.imul(ah4,bl9)|0;hi=hi+Math.imul(ah4,bh9)|0;var w13=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w13>>>26)|0;w13&=67108863;lo=Math.imul(al9,bl5);mid=Math.imul(al9,bh5);mid=mid+Math.imul(ah9,bl5)|0;hi=Math.imul(ah9,bh5);lo=lo+Math.imul(al8,bl6)|0;mid=mid+Math.imul(al8,bh6)|0;mid=mid+Math.imul(ah8,bl6)|0;hi=hi+Math.imul(ah8,bh6)|0;lo=lo+Math.imul(al7,bl7)|0;mid=mid+Math.imul(al7,bh7)|0;mid=mid+Math.imul(ah7,bl7)|0;hi=hi+Math.imul(ah7,bh7)|0;lo=lo+Math.imul(al6,bl8)|0;mid=mid+Math.imul(al6,bh8)|0;mid=mid+Math.imul(ah6,bl8)|0;hi=hi+Math.imul(ah6,bh8)|0;lo=lo+Math.imul(al5,bl9)|0;mid=mid+Math.imul(al5,bh9)|0;mid=mid+Math.imul(ah5,bl9)|0;hi=hi+Math.imul(ah5,bh9)|0;var w14=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w14>>>26)|0;w14&=67108863;lo=Math.imul(al9,bl6);mid=Math.imul(al9,bh6);mid=mid+Math.imul(ah9,bl6)|0;hi=Math.imul(ah9,bh6);lo=lo+Math.imul(al8,bl7)|0;mid=mid+Math.imul(al8,bh7)|0;mid=mid+Math.imul(ah8,bl7)|0;hi=hi+Math.imul(ah8,bh7)|0;lo=lo+Math.imul(al7,bl8)|0;mid=mid+Math.imul(al7,bh8)|0;mid=mid+Math.imul(ah7,bl8)|0;hi=hi+Math.imul(ah7,bh8)|0;lo=lo+Math.imul(al6,bl9)|0;mid=mid+Math.imul(al6,bh9)|0;mid=mid+Math.imul(ah6,bl9)|0;hi=hi+Math.imul(ah6,bh9)|0;var w15=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w15>>>26)|0;w15&=67108863;lo=Math.imul(al9,bl7);mid=Math.imul(al9,bh7);mid=mid+Math.imul(ah9,bl7)|0;hi=Math.imul(ah9,bh7);lo=lo+Math.imul(al8,bl8)|0;mid=mid+Math.imul(al8,bh8)|0;mid=mid+Math.imul(ah8,bl8)|0;hi=hi+Math.imul(ah8,bh8)|0;lo=lo+Math.imul(al7,bl9)|0;mid=mid+Math.imul(al7,bh9)|0;mid=mid+Math.imul(ah7,bl9)|0;hi=hi+Math.imul(ah7,bh9)|0;var w16=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w16>>>26)|0;w16&=67108863;lo=Math.imul(al9,bl8);mid=Math.imul(al9,bh8);mid=mid+Math.imul(ah9,bl8)|0;hi=Math.imul(ah9,bh8);lo=lo+Math.imul(al8,bl9)|0;mid=mid+Math.imul(al8,bh9)|0;mid=mid+Math.imul(ah8,bl9)|0;hi=hi+Math.imul(ah8,bh9)|0;var w17=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w17>>>26)|0;w17&=67108863;lo=Math.imul(al9,bl9);mid=Math.imul(al9,bh9);mid=mid+Math.imul(ah9,bl9)|0;hi=Math.imul(ah9,bh9);var w18=(c+lo|0)+((mid&8191)<<13)|0;c=(hi+(mid>>>13)|0)+(w18>>>26)|0;w18&=67108863;o[0]=w0;o[1]=w1;o[2]=w2;o[3]=w3;o[4]=w4;o[5]=w5;o[6]=w6;o[7]=w7;o[8]=w8;o[9]=w9;o[10]=w10;o[11]=w11;o[12]=w12;o[13]=w13;o[14]=w14;o[15]=w15;o[16]=w16;o[17]=w17;o[18]=w18;if(c!==0){o[19]=c;out.length++}return out};if(!Math.imul){comb10MulTo=smallMulTo}function bigMulTo(self,num,out){out.negative=num.negative^self.negative;out.length=self.length+num.length;var carry=0;var hncarry=0;for(var k=0;k>>26)|0;hncarry+=ncarry>>>26;ncarry&=67108863}out.words[k]=rword;carry=ncarry;ncarry=hncarry}if(carry!==0){out.words[k]=carry}else{out.length--}return out._strip()}function jumboMulTo(self,num,out){return bigMulTo(self,num,out)}BN.prototype.mulTo=function mulTo(num,out){var res;var len=this.length+num.length;if(this.length===10&&num.length===10){res=comb10MulTo(this,num,out)}else if(len<63){res=smallMulTo(this,num,out)}else if(len<1024){res=bigMulTo(this,num,out)}else{res=jumboMulTo(this,num,out)}return res};function FFTM(x,y){this.x=x;this.y=y}FFTM.prototype.makeRBT=function makeRBT(N){var t=new Array(N);var l=BN.prototype._countBits(N)-1;for(var i=0;i>=1}return rb};FFTM.prototype.permute=function permute(rbt,rws,iws,rtws,itws,N){for(var i=0;i>>1){i++}return 1<>>13;rws[2*i+1]=carry&8191;carry=carry>>>13}for(i=2*len;i>=26;carry+=w/67108864|0;carry+=lo>>>26;this.words[i]=lo&67108863}if(carry!==0){this.words[i]=carry;this.length++}return isNegNum?this.ineg():this};BN.prototype.muln=function muln(num){return this.clone().imuln(num)};BN.prototype.sqr=function sqr(){return this.mul(this)};BN.prototype.isqr=function isqr(){return this.imul(this.clone())};BN.prototype.pow=function pow(num){var w=toBitArray(num);if(w.length===0)return new BN(1);var res=this;for(var i=0;i=0);var r=bits%26;var s=(bits-r)/26;var carryMask=67108863>>>26-r<<26-r;var i;if(r!==0){var carry=0;for(i=0;i>>26-r}if(carry){this.words[i]=carry;this.length++}}if(s!==0){for(i=this.length-1;i>=0;i--){this.words[i+s]=this.words[i]}for(i=0;i=0);var h;if(hint){h=(hint-hint%26)/26}else{h=0}var r=bits%26;var s=Math.min((bits-r)/26,this.length);var mask=67108863^67108863>>>r<s){this.length-=s;for(i=0;i=0&&(carry!==0||i>=h);i--){var word=this.words[i]|0;this.words[i]=carry<<26-r|word>>>r;carry=word&mask}if(maskedWords&&carry!==0){maskedWords.words[maskedWords.length++]=carry}if(this.length===0){this.words[0]=0;this.length=1}return this._strip()};BN.prototype.ishrn=function ishrn(bits,hint,extended){assert(this.negative===0);return this.iushrn(bits,hint,extended)};BN.prototype.shln=function shln(bits){return this.clone().ishln(bits)};BN.prototype.ushln=function ushln(bits){return this.clone().iushln(bits)};BN.prototype.shrn=function shrn(bits){return this.clone().ishrn(bits)};BN.prototype.ushrn=function ushrn(bits){return this.clone().iushrn(bits)};BN.prototype.testn=function testn(bit){assert(typeof bit==="number"&&bit>=0);var r=bit%26;var s=(bit-r)/26;var q=1<=0);var r=bits%26;var s=(bits-r)/26;assert(this.negative===0,"imaskn works only with positive numbers");if(this.length<=s){return this}if(r!==0){s++}this.length=Math.min(s,this.length);if(r!==0){var mask=67108863^67108863>>>r<=67108864;i++){this.words[i]-=67108864;if(i===this.length-1){this.words[i+1]=1}else{this.words[i+1]++}}this.length=Math.max(this.length,i+1);return this};BN.prototype.isubn=function isubn(num){assert(typeof num==="number");assert(num<67108864);if(num<0)return this.iaddn(-num);if(this.negative!==0){this.negative=0;this.iaddn(num);this.negative=1;return this}this.words[0]-=num;if(this.length===1&&this.words[0]<0){this.words[0]=-this.words[0];this.negative=1}else{for(var i=0;i>26)-(right/67108864|0);this.words[i+shift]=w&67108863}for(;i>26;this.words[i+shift]=w&67108863}if(carry===0)return this._strip();assert(carry===-1);carry=0;for(i=0;i>26;this.words[i]=w&67108863}this.negative=1;return this._strip()};BN.prototype._wordDiv=function _wordDiv(num,mode){var shift=this.length-num.length;var a=this.clone();var b=num;var bhi=b.words[b.length-1]|0;var bhiBits=this._countBits(bhi);shift=26-bhiBits;if(shift!==0){b=b.ushln(shift);a.iushln(shift);bhi=b.words[b.length-1]|0}var m=a.length-b.length;var q;if(mode!=="mod"){q=new BN(null);q.length=m+1;q.words=new Array(q.length);for(var i=0;i=0;j--){var qj=(a.words[b.length+j]|0)*67108864+(a.words[b.length+j-1]|0);qj=Math.min(qj/bhi|0,67108863);a._ishlnsubmul(b,qj,j);while(a.negative!==0){qj--;a.negative=0;a._ishlnsubmul(b,1,j);if(!a.isZero()){a.negative^=1}}if(q){q.words[j]=qj}}if(q){q._strip()}a._strip();if(mode!=="div"&&shift!==0){a.iushrn(shift)}return{div:q||null,mod:a}};BN.prototype.divmod=function divmod(num,mode,positive){assert(!num.isZero());if(this.isZero()){return{div:new BN(0),mod:new BN(0)}}var div,mod,res;if(this.negative!==0&&num.negative===0){res=this.neg().divmod(num,mode);if(mode!=="mod"){div=res.div.neg()}if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.iadd(num)}}return{div:div,mod:mod}}if(this.negative===0&&num.negative!==0){res=this.divmod(num.neg(),mode);if(mode!=="mod"){div=res.div.neg()}return{div:div,mod:res.mod}}if((this.negative&num.negative)!==0){res=this.neg().divmod(num.neg(),mode);if(mode!=="div"){mod=res.mod.neg();if(positive&&mod.negative!==0){mod.isub(num)}}return{div:res.div,mod:mod}}if(num.length>this.length||this.cmp(num)<0){return{div:new BN(0),mod:this}}if(num.length===1){if(mode==="div"){return{div:this.divn(num.words[0]),mod:null}}if(mode==="mod"){return{div:null,mod:new BN(this.modrn(num.words[0]))}}return{div:this.divn(num.words[0]),mod:new BN(this.modrn(num.words[0]))}}return this._wordDiv(num,mode)};BN.prototype.div=function div(num){return this.divmod(num,"div",false).div};BN.prototype.mod=function mod(num){return this.divmod(num,"mod",false).mod};BN.prototype.umod=function umod(num){return this.divmod(num,"mod",true).mod};BN.prototype.divRound=function divRound(num){var dm=this.divmod(num);if(dm.mod.isZero())return dm.div;var mod=dm.div.negative!==0?dm.mod.isub(num):dm.mod;var half=num.ushrn(1);var r2=num.andln(1);var cmp=mod.cmp(half);if(cmp<0||r2===1&&cmp===0)return dm.div;return dm.div.negative!==0?dm.div.isubn(1):dm.div.iaddn(1)};BN.prototype.modrn=function modrn(num){var isNegNum=num<0;if(isNegNum)num=-num;assert(num<=67108863);var p=(1<<26)%num;var acc=0;for(var i=this.length-1;i>=0;i--){acc=(p*acc+(this.words[i]|0))%num}return isNegNum?-acc:acc};BN.prototype.modn=function modn(num){return this.modrn(num)};BN.prototype.idivn=function idivn(num){var isNegNum=num<0;if(isNegNum)num=-num;assert(num<=67108863);var carry=0;for(var i=this.length-1;i>=0;i--){var w=(this.words[i]|0)+carry*67108864;this.words[i]=w/num|0;carry=w%num}this._strip();return isNegNum?this.ineg():this};BN.prototype.divn=function divn(num){return this.clone().idivn(num)};BN.prototype.egcd=function egcd(p){assert(p.negative===0);assert(!p.isZero());var x=this;var y=p.clone();if(x.negative!==0){x=x.umod(p)}else{x=x.clone()}var A=new BN(1);var B=new BN(0);var C=new BN(0);var D=new BN(1);var g=0;while(x.isEven()&&y.isEven()){x.iushrn(1);y.iushrn(1);++g}var yp=y.clone();var xp=x.clone();while(!x.isZero()){for(var i=0,im=1;(x.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){x.iushrn(i);while(i-- >0){if(A.isOdd()||B.isOdd()){A.iadd(yp);B.isub(xp)}A.iushrn(1);B.iushrn(1)}}for(var j=0,jm=1;(y.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){y.iushrn(j);while(j-- >0){if(C.isOdd()||D.isOdd()){C.iadd(yp);D.isub(xp)}C.iushrn(1);D.iushrn(1)}}if(x.cmp(y)>=0){x.isub(y);A.isub(C);B.isub(D)}else{y.isub(x);C.isub(A);D.isub(B)}}return{a:C,b:D,gcd:y.iushln(g)}};BN.prototype._invmp=function _invmp(p){assert(p.negative===0);assert(!p.isZero());var a=this;var b=p.clone();if(a.negative!==0){a=a.umod(p)}else{a=a.clone()}var x1=new BN(1);var x2=new BN(0);var delta=b.clone();while(a.cmpn(1)>0&&b.cmpn(1)>0){for(var i=0,im=1;(a.words[0]&im)===0&&i<26;++i,im<<=1);if(i>0){a.iushrn(i);while(i-- >0){if(x1.isOdd()){x1.iadd(delta)}x1.iushrn(1)}}for(var j=0,jm=1;(b.words[0]&jm)===0&&j<26;++j,jm<<=1);if(j>0){b.iushrn(j);while(j-- >0){if(x2.isOdd()){x2.iadd(delta)}x2.iushrn(1)}}if(a.cmp(b)>=0){a.isub(b);x1.isub(x2)}else{b.isub(a);x2.isub(x1)}}var res;if(a.cmpn(1)===0){res=x1}else{res=x2}if(res.cmpn(0)<0){res.iadd(p)}return res};BN.prototype.gcd=function gcd(num){if(this.isZero())return num.abs();if(num.isZero())return this.abs();var a=this.clone();var b=num.clone();a.negative=0;b.negative=0;for(var shift=0;a.isEven()&&b.isEven();shift++){a.iushrn(1);b.iushrn(1)}do{while(a.isEven()){a.iushrn(1)}while(b.isEven()){b.iushrn(1)}var r=a.cmp(b);if(r<0){var t=a;a=b;b=t}else if(r===0||b.cmpn(1)===0){break}a.isub(b)}while(true);return b.iushln(shift)};BN.prototype.invm=function invm(num){return this.egcd(num).a.umod(num)};BN.prototype.isEven=function isEven(){return(this.words[0]&1)===0};BN.prototype.isOdd=function isOdd(){return(this.words[0]&1)===1};BN.prototype.andln=function andln(num){return this.words[0]&num};BN.prototype.bincn=function bincn(bit){assert(typeof bit==="number");var r=bit%26;var s=(bit-r)/26;var q=1<>>26;w&=67108863;this.words[i]=w}if(carry!==0){this.words[i]=carry;this.length++}return this};BN.prototype.isZero=function isZero(){return this.length===1&&this.words[0]===0};BN.prototype.cmpn=function cmpn(num){var negative=num<0;if(this.negative!==0&&!negative)return-1;if(this.negative===0&&negative)return 1;this._strip();var res;if(this.length>1){res=1}else{if(negative){num=-num}assert(num<=67108863,"Number is too big");var w=this.words[0]|0;res=w===num?0:wnum.length)return 1;if(this.length=0;i--){var a=this.words[i]|0;var b=num.words[i]|0;if(a===b)continue;if(ab){res=1}break}return res};BN.prototype.gtn=function gtn(num){return this.cmpn(num)===1};BN.prototype.gt=function gt(num){return this.cmp(num)===1};BN.prototype.gten=function gten(num){return this.cmpn(num)>=0};BN.prototype.gte=function gte(num){return this.cmp(num)>=0};BN.prototype.ltn=function ltn(num){return this.cmpn(num)===-1};BN.prototype.lt=function lt(num){return this.cmp(num)===-1};BN.prototype.lten=function lten(num){return this.cmpn(num)<=0};BN.prototype.lte=function lte(num){return this.cmp(num)<=0};BN.prototype.eqn=function eqn(num){return this.cmpn(num)===0};BN.prototype.eq=function eq(num){return this.cmp(num)===0};BN.red=function red(num){return new Red(num)};BN.prototype.toRed=function toRed(ctx){assert(!this.red,"Already a number in reduction context");assert(this.negative===0,"red works only with positives");return ctx.convertTo(this)._forceRed(ctx)};BN.prototype.fromRed=function fromRed(){assert(this.red,"fromRed works only with numbers in reduction context");return this.red.convertFrom(this)};BN.prototype._forceRed=function _forceRed(ctx){this.red=ctx;return this};BN.prototype.forceRed=function forceRed(ctx){assert(!this.red,"Already a number in reduction context");return this._forceRed(ctx)};BN.prototype.redAdd=function redAdd(num){assert(this.red,"redAdd works only with red numbers");return this.red.add(this,num)};BN.prototype.redIAdd=function redIAdd(num){assert(this.red,"redIAdd works only with red numbers");return this.red.iadd(this,num)};BN.prototype.redSub=function redSub(num){assert(this.red,"redSub works only with red numbers");return this.red.sub(this,num)};BN.prototype.redISub=function redISub(num){assert(this.red,"redISub works only with red numbers");return this.red.isub(this,num)};BN.prototype.redShl=function redShl(num){assert(this.red,"redShl works only with red numbers");return this.red.shl(this,num)};BN.prototype.redMul=function redMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.mul(this,num)};BN.prototype.redIMul=function redIMul(num){assert(this.red,"redMul works only with red numbers");this.red._verify2(this,num);return this.red.imul(this,num)};BN.prototype.redSqr=function redSqr(){assert(this.red,"redSqr works only with red numbers");this.red._verify1(this);return this.red.sqr(this)};BN.prototype.redISqr=function redISqr(){assert(this.red,"redISqr works only with red numbers");this.red._verify1(this);return this.red.isqr(this)};BN.prototype.redSqrt=function redSqrt(){assert(this.red,"redSqrt works only with red numbers");this.red._verify1(this);return this.red.sqrt(this)};BN.prototype.redInvm=function redInvm(){assert(this.red,"redInvm works only with red numbers");this.red._verify1(this);return this.red.invm(this)};BN.prototype.redNeg=function redNeg(){assert(this.red,"redNeg works only with red numbers");this.red._verify1(this);return this.red.neg(this)};BN.prototype.redPow=function redPow(num){assert(this.red&&!num.red,"redPow(normalNum)");this.red._verify1(this);return this.red.pow(this,num)};var primes={k256:null,p224:null,p192:null,p25519:null};function MPrime(name,p){this.name=name;this.p=new BN(p,16);this.n=this.p.bitLength();this.k=new BN(1).iushln(this.n).isub(this.p);this.tmp=this._tmp()}MPrime.prototype._tmp=function _tmp(){var tmp=new BN(null);tmp.words=new Array(Math.ceil(this.n/13));return tmp};MPrime.prototype.ireduce=function ireduce(num){var r=num;var rlen;do{this.split(r,this.tmp);r=this.imulK(r);r=r.iadd(this.tmp);rlen=r.bitLength()}while(rlen>this.n);var cmp=rlen0){r.isub(this.p)}else{if(r.strip!==undefined){r.strip()}else{r._strip()}}return r};MPrime.prototype.split=function split(input,out){input.iushrn(this.n,0,out)};MPrime.prototype.imulK=function imulK(num){return num.imul(this.k)};function K256(){MPrime.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}inherits(K256,MPrime);K256.prototype.split=function split(input,output){var mask=4194303;var outLen=Math.min(input.length,9);for(var i=0;i>>22;prev=next}prev>>>=22;input.words[i-10]=prev;if(prev===0&&input.length>10){input.length-=10}else{input.length-=9}};K256.prototype.imulK=function imulK(num){num.words[num.length]=0;num.words[num.length+1]=0;num.length+=2;var lo=0;for(var i=0;i>>=26;num.words[i]=lo;carry=hi}if(carry!==0){num.words[num.length++]=carry}return num};BN._prime=function prime(name){if(primes[name])return primes[name];var prime;if(name==="k256"){prime=new K256}else if(name==="p224"){prime=new P224}else if(name==="p192"){prime=new P192}else if(name==="p25519"){prime=new P25519}else{throw new Error("Unknown prime "+name)}primes[name]=prime;return prime};function Red(m){if(typeof m==="string"){var prime=BN._prime(m);this.m=prime.p;this.prime=prime}else{assert(m.gtn(1),"modulus must be greater than 1");this.m=m;this.prime=null}}Red.prototype._verify1=function _verify1(a){assert(a.negative===0,"red works only with positives");assert(a.red,"red works only with red numbers")};Red.prototype._verify2=function _verify2(a,b){assert((a.negative|b.negative)===0,"red works only with positives");assert(a.red&&a.red===b.red,"red works only with red numbers")};Red.prototype.imod=function imod(a){if(this.prime)return this.prime.ireduce(a)._forceRed(this);move(a,a.umod(this.m)._forceRed(this));return a};Red.prototype.neg=function neg(a){if(a.isZero()){return a.clone()}return this.m.sub(a)._forceRed(this)};Red.prototype.add=function add(a,b){this._verify2(a,b);var res=a.add(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res._forceRed(this)};Red.prototype.iadd=function iadd(a,b){this._verify2(a,b);var res=a.iadd(b);if(res.cmp(this.m)>=0){res.isub(this.m)}return res};Red.prototype.sub=function sub(a,b){this._verify2(a,b);var res=a.sub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res._forceRed(this)};Red.prototype.isub=function isub(a,b){this._verify2(a,b);var res=a.isub(b);if(res.cmpn(0)<0){res.iadd(this.m)}return res};Red.prototype.shl=function shl(a,num){this._verify1(a);return this.imod(a.ushln(num))};Red.prototype.imul=function imul(a,b){this._verify2(a,b);return this.imod(a.imul(b))};Red.prototype.mul=function mul(a,b){this._verify2(a,b);return this.imod(a.mul(b))};Red.prototype.isqr=function isqr(a){return this.imul(a,a.clone())};Red.prototype.sqr=function sqr(a){return this.mul(a,a)};Red.prototype.sqrt=function sqrt(a){if(a.isZero())return a.clone();var mod3=this.m.andln(3);assert(mod3%2===1);if(mod3===3){var pow=this.m.add(new BN(1)).iushrn(2);return this.pow(a,pow)}var q=this.m.subn(1);var s=0;while(!q.isZero()&&q.andln(1)===0){s++;q.iushrn(1)}assert(!q.isZero());var one=new BN(1).toRed(this);var nOne=one.redNeg();var lpow=this.m.subn(1).iushrn(1);var z=this.m.bitLength();z=new BN(2*z*z).toRed(this);while(this.pow(z,lpow).cmp(nOne)!==0){z.redIAdd(nOne)}var c=this.pow(z,q);var r=this.pow(a,q.addn(1).iushrn(1));var t=this.pow(a,q);var m=s;while(t.cmp(one)!==0){var tmp=t;for(var i=0;tmp.cmp(one)!==0;i++){tmp=tmp.redSqr()}assert(i=0;i--){var word=num.words[i];for(var j=start-1;j>=0;j--){var bit=word>>j&1;if(res!==wnd[0]){res=this.sqr(res)}if(bit===0&¤t===0){currentLen=0;continue}current<<=1;current|=bit;currentLen++;if(currentLen!==windowSize&&(i!==0||j!==0))continue;res=this.mul(res,wnd[current]);currentLen=0;current=0}start=26}return res};Red.prototype.convertTo=function convertTo(num){var r=num.umod(this.m);return r===num?r.clone():r};Red.prototype.convertFrom=function convertFrom(num){var res=num.clone();res.red=null;return res};BN.mont=function mont(num){return new Mont(num)};function Mont(m){Red.call(this,m);this.shift=this.m.bitLength();if(this.shift%26!==0){this.shift+=26-this.shift%26}this.r=new BN(1).iushln(this.shift);this.r2=this.imod(this.r.sqr());this.rinv=this.r._invmp(this.m);this.minv=this.rinv.mul(this.r).isubn(1).div(this.m);this.minv=this.minv.umod(this.r);this.minv=this.r.sub(this.minv)}inherits(Mont,Red);Mont.prototype.convertTo=function convertTo(num){return this.imod(num.ushln(this.shift))};Mont.prototype.convertFrom=function convertFrom(num){var r=this.imod(num.mul(this.rinv));r.red=null;return r};Mont.prototype.imul=function imul(a,b){if(a.isZero()||b.isZero()){a.words[0]=0;a.length=1;return a}var t=a.imul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.mul=function mul(a,b){if(a.isZero()||b.isZero())return new BN(0)._forceRed(this);var t=a.mul(b);var c=t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m);var u=t.isub(c).iushrn(this.shift);var res=u;if(u.cmp(this.m)>=0){res=u.isub(this.m)}else if(u.cmpn(0)<0){res=u.iadd(this.m)}return res._forceRed(this)};Mont.prototype.invm=function invm(a){var res=this.imod(a._invmp(this.m).mul(this.r2));return res._forceRed(this)}})(typeof module==="undefined"||module,this)},{buffer:131}],130:[function(require,module,exports){arguments[4][63][0].apply(exports,arguments)},{crypto:131,dup:63}],131:[function(require,module,exports){},{}],132:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;function asUInt32Array(buf){if(!Buffer.isBuffer(buf))buf=Buffer.from(buf);var len=buf.length/4|0;var out=new Array(len);for(var i=0;i>>24]^SUB_MIX1[s1>>>16&255]^SUB_MIX2[s2>>>8&255]^SUB_MIX3[s3&255]^keySchedule[ksRow++];t1=SUB_MIX0[s1>>>24]^SUB_MIX1[s2>>>16&255]^SUB_MIX2[s3>>>8&255]^SUB_MIX3[s0&255]^keySchedule[ksRow++];t2=SUB_MIX0[s2>>>24]^SUB_MIX1[s3>>>16&255]^SUB_MIX2[s0>>>8&255]^SUB_MIX3[s1&255]^keySchedule[ksRow++];t3=SUB_MIX0[s3>>>24]^SUB_MIX1[s0>>>16&255]^SUB_MIX2[s1>>>8&255]^SUB_MIX3[s2&255]^keySchedule[ksRow++];s0=t0;s1=t1;s2=t2;s3=t3}t0=(SBOX[s0>>>24]<<24|SBOX[s1>>>16&255]<<16|SBOX[s2>>>8&255]<<8|SBOX[s3&255])^keySchedule[ksRow++];t1=(SBOX[s1>>>24]<<24|SBOX[s2>>>16&255]<<16|SBOX[s3>>>8&255]<<8|SBOX[s0&255])^keySchedule[ksRow++];t2=(SBOX[s2>>>24]<<24|SBOX[s3>>>16&255]<<16|SBOX[s0>>>8&255]<<8|SBOX[s1&255])^keySchedule[ksRow++];t3=(SBOX[s3>>>24]<<24|SBOX[s0>>>16&255]<<16|SBOX[s1>>>8&255]<<8|SBOX[s2&255])^keySchedule[ksRow++];t0=t0>>>0;t1=t1>>>0;t2=t2>>>0;t3=t3>>>0;return[t0,t1,t2,t3]}var RCON=[0,1,2,4,8,16,32,64,128,27,54];var G=function(){var d=new Array(256);for(var j=0;j<256;j++){if(j<128){d[j]=j<<1}else{d[j]=j<<1^283}}var SBOX=[];var INV_SBOX=[];var SUB_MIX=[[],[],[],[]];var INV_SUB_MIX=[[],[],[],[]];var x=0;var xi=0;for(var i=0;i<256;++i){var sx=xi^xi<<1^xi<<2^xi<<3^xi<<4;sx=sx>>>8^sx&255^99;SBOX[x]=sx;INV_SBOX[sx]=x;var x2=d[x];var x4=d[x2];var x8=d[x4];var t=d[sx]*257^sx*16843008;SUB_MIX[0][x]=t<<24|t>>>8;SUB_MIX[1][x]=t<<16|t>>>16;SUB_MIX[2][x]=t<<8|t>>>24;SUB_MIX[3][x]=t;t=x8*16843009^x4*65537^x2*257^x*16843008;INV_SUB_MIX[0][sx]=t<<24|t>>>8;INV_SUB_MIX[1][sx]=t<<16|t>>>16;INV_SUB_MIX[2][sx]=t<<8|t>>>24;INV_SUB_MIX[3][sx]=t;if(x===0){x=xi=1}else{x=x2^d[d[d[x8^x2]]];xi^=d[d[xi]]}}return{SBOX:SBOX,INV_SBOX:INV_SBOX,SUB_MIX:SUB_MIX,INV_SUB_MIX:INV_SUB_MIX}}();function AES(key){this._key=asUInt32Array(key);this._reset()}AES.blockSize=4*4;AES.keySize=256/8;AES.prototype.blockSize=AES.blockSize;AES.prototype.keySize=AES.keySize;AES.prototype._reset=function(){var keyWords=this._key;var keySize=keyWords.length;var nRounds=keySize+6;var ksRows=(nRounds+1)*4;var keySchedule=[];for(var k=0;k>>24;t=G.SBOX[t>>>24]<<24|G.SBOX[t>>>16&255]<<16|G.SBOX[t>>>8&255]<<8|G.SBOX[t&255];t^=RCON[k/keySize|0]<<24}else if(keySize>6&&k%keySize===4){t=G.SBOX[t>>>24]<<24|G.SBOX[t>>>16&255]<<16|G.SBOX[t>>>8&255]<<8|G.SBOX[t&255]}keySchedule[k]=keySchedule[k-keySize]^t}var invKeySchedule=[];for(var ik=0;ik>>24]]^G.INV_SUB_MIX[1][G.SBOX[tt>>>16&255]]^G.INV_SUB_MIX[2][G.SBOX[tt>>>8&255]]^G.INV_SUB_MIX[3][G.SBOX[tt&255]]}}this._nRounds=nRounds;this._keySchedule=keySchedule;this._invKeySchedule=invKeySchedule};AES.prototype.encryptBlockRaw=function(M){M=asUInt32Array(M);return cryptBlock(M,this._keySchedule,G.SUB_MIX,G.SBOX,this._nRounds)};AES.prototype.encryptBlock=function(M){var out=this.encryptBlockRaw(M);var buf=Buffer.allocUnsafe(16);buf.writeUInt32BE(out[0],0);buf.writeUInt32BE(out[1],4);buf.writeUInt32BE(out[2],8);buf.writeUInt32BE(out[3],12);return buf};AES.prototype.decryptBlock=function(M){M=asUInt32Array(M);var m1=M[1];M[1]=M[3];M[3]=m1;var out=cryptBlock(M,this._invKeySchedule,G.INV_SUB_MIX,G.INV_SBOX,this._nRounds);var buf=Buffer.allocUnsafe(16);buf.writeUInt32BE(out[0],0);buf.writeUInt32BE(out[3],4);buf.writeUInt32BE(out[2],8);buf.writeUInt32BE(out[1],12);return buf};AES.prototype.scrub=function(){scrubVec(this._keySchedule);scrubVec(this._invKeySchedule);scrubVec(this._key)};module.exports.AES=AES},{"safe-buffer":277}],133:[function(require,module,exports){var aes=require("./aes");var Buffer=require("safe-buffer").Buffer;var Transform=require("cipher-base");var inherits=require("inherits");var GHASH=require("./ghash");var xor=require("buffer-xor");var incr32=require("./incr32");function xorTest(a,b){var out=0;if(a.length!==b.length)out++;var len=Math.min(a.length,b.length);for(var i=0;i16){out=this.cache.slice(0,16);this.cache=this.cache.slice(16);return out}}else{if(this.cache.length>=16){out=this.cache.slice(0,16);this.cache=this.cache.slice(16);return out}}return null};Splitter.prototype.flush=function(){if(this.cache.length)return this.cache};function unpad(last){var padded=last[15];if(padded<1||padded>16){throw new Error("unable to decrypt data")}var i=-1;while(++i15){var out=this.cache.slice(0,16);this.cache=this.cache.slice(16);return out}return null};Splitter.prototype.flush=function(){var len=16-this.cache.length;var padBuff=Buffer.allocUnsafe(len);var i=-1;while(++i>>0,0);buf.writeUInt32BE(out[1]>>>0,4);buf.writeUInt32BE(out[2]>>>0,8);buf.writeUInt32BE(out[3]>>>0,12);return buf}function GHASH(key){this.h=key;this.state=Buffer.alloc(16,0);this.cache=Buffer.allocUnsafe(0)}GHASH.prototype.ghash=function(block){var i=-1;while(++i0;j--){Vi[j]=Vi[j]>>>1|(Vi[j-1]&1)<<31}Vi[0]=Vi[0]>>>1;if(lsbVi){Vi[0]=Vi[0]^225<<24}}this.state=fromArray(Zi)};GHASH.prototype.update=function(buf){this.cache=Buffer.concat([this.cache,buf]);var chunk;while(this.cache.length>=16){chunk=this.cache.slice(0,16);this.cache=this.cache.slice(16);this.ghash(chunk)}};GHASH.prototype.final=function(abl,bl){if(this.cache.length){this.ghash(Buffer.concat([this.cache,ZEROES],16))}this.ghash(fromArray([0,abl,0,bl]));return this.state};module.exports=GHASH},{"safe-buffer":277}],138:[function(require,module,exports){function incr32(iv){var len=iv.length;var item;while(len--){item=iv.readUInt8(len);if(item===255){iv.writeUInt8(0,len)}else{item++;iv.writeUInt8(item,len);break}}}module.exports=incr32},{}],139:[function(require,module,exports){var xor=require("buffer-xor");exports.encrypt=function(self,block){var data=xor(block,self._prev);self._prev=self._cipher.encryptBlock(data);return self._prev};exports.decrypt=function(self,block){var pad=self._prev;self._prev=block;var out=self._cipher.decryptBlock(block);return xor(out,pad)}},{"buffer-xor":174}],140:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;var xor=require("buffer-xor");function encryptStart(self,data,decrypt){var len=data.length;var out=xor(data,self._cache);self._cache=self._cache.slice(len);self._prev=Buffer.concat([self._prev,decrypt?data:out]);return out}exports.encrypt=function(self,data,decrypt){var out=Buffer.allocUnsafe(0);var len;while(data.length){if(self._cache.length===0){self._cache=self._cipher.encryptBlock(self._prev);self._prev=Buffer.allocUnsafe(0)}if(self._cache.length<=data.length){len=self._cache.length;out=Buffer.concat([out,encryptStart(self,data.slice(0,len),decrypt)]);data=data.slice(len)}else{out=Buffer.concat([out,encryptStart(self,data,decrypt)]);break}}return out}},{"buffer-xor":174,"safe-buffer":277}],141:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;function encryptByte(self,byteParam,decrypt){var pad;var i=-1;var len=8;var out=0;var bit,value;while(++i>i%8;self._prev=shiftIn(self._prev,decrypt?bit:value)}return out}function shiftIn(buffer,value){var len=buffer.length;var i=-1;var out=Buffer.allocUnsafe(buffer.length);buffer=Buffer.concat([buffer,Buffer.from([value])]);while(++i>7}return out}exports.encrypt=function(self,chunk,decrypt){var len=chunk.length;var out=Buffer.allocUnsafe(len);var i=-1;while(++i=0||!r.umod(priv.prime1)||!r.umod(priv.prime2));return r}function crt(msg,priv){var blinds=blind(priv);var len=priv.modulus.byteLength();var blinded=new BN(msg).mul(blinds.blinder).umod(priv.modulus);var c1=blinded.toRed(BN.mont(priv.prime1));var c2=blinded.toRed(BN.mont(priv.prime2));var qinv=priv.coefficient;var p=priv.prime1;var q=priv.prime2;var m1=c1.redPow(priv.exponent1).fromRed();var m2=c2.redPow(priv.exponent2).fromRed();var h=m1.isub(m2).imul(qinv).umod(p).imul(q);return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(Buffer,"be",len)}crt.getr=getr;module.exports=crt}).call(this)}).call(this,require("buffer").Buffer)},{"bn.js":129,buffer:175,randombytes:274}],153:[function(require,module,exports){module.exports=require("./browser/algorithms.json")},{"./browser/algorithms.json":154}],154:[function(require,module,exports){module.exports={sha224WithRSAEncryption:{sign:"rsa",hash:"sha224",id:"302d300d06096086480165030402040500041c"},"RSA-SHA224":{sign:"ecdsa/rsa",hash:"sha224",id:"302d300d06096086480165030402040500041c"},sha256WithRSAEncryption:{sign:"rsa",hash:"sha256",id:"3031300d060960864801650304020105000420"},"RSA-SHA256":{sign:"ecdsa/rsa",hash:"sha256",id:"3031300d060960864801650304020105000420"},sha384WithRSAEncryption:{sign:"rsa",hash:"sha384",id:"3041300d060960864801650304020205000430"},"RSA-SHA384":{sign:"ecdsa/rsa",hash:"sha384",id:"3041300d060960864801650304020205000430"},sha512WithRSAEncryption:{sign:"rsa",hash:"sha512",id:"3051300d060960864801650304020305000440"},"RSA-SHA512":{sign:"ecdsa/rsa",hash:"sha512",id:"3051300d060960864801650304020305000440"},"RSA-SHA1":{sign:"rsa",hash:"sha1",id:"3021300906052b0e03021a05000414"},"ecdsa-with-SHA1":{sign:"ecdsa",hash:"sha1",id:""},sha256:{sign:"ecdsa",hash:"sha256",id:""},sha224:{sign:"ecdsa",hash:"sha224",id:""},sha384:{sign:"ecdsa",hash:"sha384",id:""},sha512:{sign:"ecdsa",hash:"sha512",id:""},"DSA-SHA":{sign:"dsa",hash:"sha1",id:""},"DSA-SHA1":{sign:"dsa",hash:"sha1",id:""},DSA:{sign:"dsa",hash:"sha1",id:""},"DSA-WITH-SHA224":{sign:"dsa",hash:"sha224",id:""},"DSA-SHA224":{sign:"dsa",hash:"sha224",id:""},"DSA-WITH-SHA256":{sign:"dsa",hash:"sha256",id:""},"DSA-SHA256":{sign:"dsa",hash:"sha256",id:""},"DSA-WITH-SHA384":{sign:"dsa",hash:"sha384",id:""},"DSA-SHA384":{sign:"dsa",hash:"sha384",id:""},"DSA-WITH-SHA512":{sign:"dsa",hash:"sha512",id:""},"DSA-SHA512":{sign:"dsa",hash:"sha512",id:""},"DSA-RIPEMD160":{sign:"dsa",hash:"rmd160",id:""},ripemd160WithRSA:{sign:"rsa",hash:"rmd160",id:"3021300906052b2403020105000414"},"RSA-RIPEMD160":{sign:"rsa",hash:"rmd160",id:"3021300906052b2403020105000414"},md5WithRSAEncryption:{sign:"rsa",hash:"md5",id:"3020300c06082a864886f70d020505000410"},"RSA-MD5":{sign:"rsa",hash:"md5",id:"3020300c06082a864886f70d020505000410"}}},{}],155:[function(require,module,exports){module.exports={"1.3.132.0.10":"secp256k1","1.3.132.0.33":"p224","1.2.840.10045.3.1.1":"p192","1.2.840.10045.3.1.7":"p256","1.3.132.0.34":"p384","1.3.132.0.35":"p521"}},{}],156:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;var createHash=require("create-hash");var stream=require("readable-stream");var inherits=require("inherits");var sign=require("./sign");var verify=require("./verify");var algorithms=require("./algorithms.json");Object.keys(algorithms).forEach(function(key){algorithms[key].id=Buffer.from(algorithms[key].id,"hex");algorithms[key.toLowerCase()]=algorithms[key]});function Sign(algorithm){stream.Writable.call(this);var data=algorithms[algorithm];if(!data)throw new Error("Unknown message digest");this._hashType=data.hash;this._hash=createHash(data.hash);this._tag=data.id;this._signType=data.sign}inherits(Sign,stream.Writable);Sign.prototype._write=function _write(data,_,done){this._hash.update(data);done()};Sign.prototype.update=function update(data,enc){if(typeof data==="string")data=Buffer.from(data,enc);this._hash.update(data);return this};Sign.prototype.sign=function signMethod(key,enc){this.end();var hash=this._hash.digest();var sig=sign(hash,key,this._hashType,this._signType,this._tag);return enc?sig.toString(enc):sig};function Verify(algorithm){stream.Writable.call(this);var data=algorithms[algorithm];if(!data)throw new Error("Unknown message digest");this._hash=createHash(data.hash);this._tag=data.id;this._signType=data.sign}inherits(Verify,stream.Writable);Verify.prototype._write=function _write(data,_,done){this._hash.update(data);done()};Verify.prototype.update=function update(data,enc){if(typeof data==="string")data=Buffer.from(data,enc);this._hash.update(data);return this};Verify.prototype.verify=function verifyMethod(key,sig,enc){if(typeof sig==="string")sig=Buffer.from(sig,enc);this.end();var hash=this._hash.digest();return verify(sig,hash,key,this._signType,this._tag)};function createSign(algorithm){return new Sign(algorithm)}function createVerify(algorithm){return new Verify(algorithm)}module.exports={Sign:createSign,Verify:createVerify,createSign:createSign,createVerify:createVerify}},{"./algorithms.json":154,"./sign":157,"./verify":158,"create-hash":179,inherits:244,"readable-stream":173,"safe-buffer":277}],157:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;var createHmac=require("create-hmac");var crt=require("browserify-rsa");var EC=require("elliptic").ec;var BN=require("bn.js");var parseKeys=require("parse-asn1");var curves=require("./curves.json");function sign(hash,key,hashType,signType,tag){var priv=parseKeys(key);if(priv.curve){if(signType!=="ecdsa"&&signType!=="ecdsa/rsa")throw new Error("wrong private key type");return ecSign(hash,priv)}else if(priv.type==="dsa"){if(signType!=="dsa")throw new Error("wrong private key type");return dsaSign(hash,priv,hashType)}else{if(signType!=="rsa"&&signType!=="ecdsa/rsa")throw new Error("wrong private key type")}hash=Buffer.concat([tag,hash]);var len=priv.modulus.byteLength();var pad=[0,1];while(hash.length+pad.length+10)bits.ishrn(shift);return bits}function bits2octets(bits,q){bits=bits2int(bits,q);bits=bits.mod(q);var out=Buffer.from(bits.toArray());if(out.length=q)throw new Error("invalid sig")}module.exports=verify},{"./curves.json":155,"bn.js":129,elliptic:195,"parse-asn1":255,"safe-buffer":277}],159:[function(require,module,exports){"use strict";function _inheritsLoose(subClass,superClass){subClass.prototype=Object.create(superClass.prototype);subClass.prototype.constructor=subClass;subClass.__proto__=superClass}var codes={};function createErrorType(code,message,Base){if(!Base){Base=Error}function getMessage(arg1,arg2,arg3){if(typeof message==="string"){return message}else{return message(arg1,arg2,arg3)}}var NodeError=function(_Base){_inheritsLoose(NodeError,_Base);function NodeError(arg1,arg2,arg3){return _Base.call(this,getMessage(arg1,arg2,arg3))||this}return NodeError}(Base);NodeError.prototype.name=Base.name;NodeError.prototype.code=code;codes[code]=NodeError}function oneOf(expected,thing){if(Array.isArray(expected)){var len=expected.length;expected=expected.map(function(i){return String(i)});if(len>2){return"one of ".concat(thing," ").concat(expected.slice(0,len-1).join(", "),", or ")+expected[len-1]}else if(len===2){return"one of ".concat(thing," ").concat(expected[0]," or ").concat(expected[1])}else{return"of ".concat(thing," ").concat(expected[0])}}else{return"of ".concat(thing," ").concat(String(expected))}}function startsWith(str,search,pos){return str.substr(!pos||pos<0?0:+pos,search.length)===search}function endsWith(str,search,this_len){if(this_len===undefined||this_len>str.length){this_len=str.length}return str.substring(this_len-search.length,this_len)===search}function includes(str,search,start){if(typeof start!=="number"){start=0}if(start+search.length>str.length){return false}else{return str.indexOf(search,start)!==-1}}createErrorType("ERR_INVALID_OPT_VALUE",function(name,value){return'The value "'+value+'" is invalid for option "'+name+'"'},TypeError);createErrorType("ERR_INVALID_ARG_TYPE",function(name,expected,actual){var determiner;if(typeof expected==="string"&&startsWith(expected,"not ")){determiner="must not be";expected=expected.replace(/^not /,"")}else{determiner="must be"}var msg;if(endsWith(name," argument")){msg="The ".concat(name," ").concat(determiner," ").concat(oneOf(expected,"type"))}else{var type=includes(name,".")?"property":"argument";msg='The "'.concat(name,'" ').concat(type," ").concat(determiner," ").concat(oneOf(expected,"type"))}msg+=". Received type ".concat(typeof actual);return msg},TypeError);createErrorType("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF");createErrorType("ERR_METHOD_NOT_IMPLEMENTED",function(name){return"The "+name+" method is not implemented"});createErrorType("ERR_STREAM_PREMATURE_CLOSE","Premature close");createErrorType("ERR_STREAM_DESTROYED",function(name){return"Cannot call "+name+" after a stream was destroyed"});createErrorType("ERR_MULTIPLE_CALLBACK","Callback called multiple times");createErrorType("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable");createErrorType("ERR_STREAM_WRITE_AFTER_END","write after end");createErrorType("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError);createErrorType("ERR_UNKNOWN_ENCODING",function(arg){return"Unknown encoding: "+arg},TypeError);createErrorType("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event");module.exports.codes=codes},{}],160:[function(require,module,exports){(function(process){(function(){"use strict";var objectKeys=Object.keys||function(obj){var keys=[];for(var key in obj){keys.push(key)}return keys};module.exports=Duplex;var Readable=require("./_stream_readable");var Writable=require("./_stream_writable");require("inherits")(Duplex,Readable);{var keys=objectKeys(Writable.prototype);for(var v=0;v0){if(typeof chunk!=="string"&&!state.objectMode&&Object.getPrototypeOf(chunk)!==Buffer.prototype){chunk=_uint8ArrayToBuffer(chunk)}if(addToFront){if(state.endEmitted)errorOrDestroy(stream,new ERR_STREAM_UNSHIFT_AFTER_END_EVENT);else addChunk(stream,state,chunk,true)}else if(state.ended){errorOrDestroy(stream,new ERR_STREAM_PUSH_AFTER_EOF)}else if(state.destroyed){return false}else{state.reading=false;if(state.decoder&&!encoding){chunk=state.decoder.write(chunk);if(state.objectMode||chunk.length!==0)addChunk(stream,state,chunk,false);else maybeReadMore(stream,state)}else{addChunk(stream,state,chunk,false)}}}else if(!addToFront){state.reading=false;maybeReadMore(stream,state)}}return!state.ended&&(state.length=MAX_HWM){n=MAX_HWM}else{n--;n|=n>>>1;n|=n>>>2;n|=n>>>4;n|=n>>>8;n|=n>>>16;n++}return n}function howMuchToRead(n,state){if(n<=0||state.length===0&&state.ended)return 0;if(state.objectMode)return 1;if(n!==n){if(state.flowing&&state.length)return state.buffer.head.data.length;else return state.length}if(n>state.highWaterMark)state.highWaterMark=computeNewHighWaterMark(n);if(n<=state.length)return n;if(!state.ended){state.needReadable=true;return 0}return state.length}Readable.prototype.read=function(n){debug("read",n);n=parseInt(n,10);var state=this._readableState;var nOrig=n;if(n!==0)state.emittedReadable=false;if(n===0&&state.needReadable&&((state.highWaterMark!==0?state.length>=state.highWaterMark:state.length>0)||state.ended)){debug("read: emitReadable",state.length,state.ended);if(state.length===0&&state.ended)endReadable(this);else emitReadable(this);return null}n=howMuchToRead(n,state);if(n===0&&state.ended){if(state.length===0)endReadable(this);return null}var doRead=state.needReadable;debug("need readable",doRead);if(state.length===0||state.length-n0)ret=fromList(n,state);else ret=null;if(ret===null){state.needReadable=state.length<=state.highWaterMark;n=0}else{state.length-=n;state.awaitDrain=0}if(state.length===0){if(!state.ended)state.needReadable=true;if(nOrig!==n&&state.ended)endReadable(this)}if(ret!==null)this.emit("data",ret);return ret};function onEofChunk(stream,state){debug("onEofChunk");if(state.ended)return;if(state.decoder){var chunk=state.decoder.end();if(chunk&&chunk.length){state.buffer.push(chunk);state.length+=state.objectMode?1:chunk.length}}state.ended=true;if(state.sync){emitReadable(stream)}else{state.needReadable=false;if(!state.emittedReadable){state.emittedReadable=true;emitReadable_(stream)}}}function emitReadable(stream){var state=stream._readableState;debug("emitReadable",state.needReadable,state.emittedReadable);state.needReadable=false;if(!state.emittedReadable){debug("emitReadable",state.flowing);state.emittedReadable=true;process.nextTick(emitReadable_,stream)}}function emitReadable_(stream){var state=stream._readableState;debug("emitReadable_",state.destroyed,state.length,state.ended);if(!state.destroyed&&(state.length||state.ended)){stream.emit("readable");state.emittedReadable=false}state.needReadable=!state.flowing&&!state.ended&&state.length<=state.highWaterMark;flow(stream)}function maybeReadMore(stream,state){if(!state.readingMore){state.readingMore=true;process.nextTick(maybeReadMore_,stream,state)}}function maybeReadMore_(stream,state){while(!state.reading&&!state.ended&&(state.length1&&indexOf(state.pipes,dest)!==-1)&&!cleanedUp){debug("false write response, pause",state.awaitDrain);state.awaitDrain++}src.pause()}}function onerror(er){debug("onerror",er);unpipe();dest.removeListener("error",onerror);if(EElistenerCount(dest,"error")===0)errorOrDestroy(dest,er)}prependListener(dest,"error",onerror);function onclose(){dest.removeListener("finish",onfinish);unpipe()}dest.once("close",onclose);function onfinish(){debug("onfinish");dest.removeListener("close",onclose);unpipe()}dest.once("finish",onfinish);function unpipe(){debug("unpipe");src.unpipe(dest)}dest.emit("pipe",src);if(!state.flowing){debug("pipe resume");src.resume()}return dest};function pipeOnDrain(src){return function pipeOnDrainFunctionResult(){var state=src._readableState;debug("pipeOnDrain",state.awaitDrain);if(state.awaitDrain)state.awaitDrain--;if(state.awaitDrain===0&&EElistenerCount(src,"data")){state.flowing=true;flow(src)}}}Readable.prototype.unpipe=function(dest){var state=this._readableState;var unpipeInfo={hasUnpiped:false};if(state.pipesCount===0)return this;if(state.pipesCount===1){if(dest&&dest!==state.pipes)return this;if(!dest)dest=state.pipes;state.pipes=null;state.pipesCount=0;state.flowing=false;if(dest)dest.emit("unpipe",this,unpipeInfo);return this}if(!dest){var dests=state.pipes;var len=state.pipesCount;state.pipes=null;state.pipesCount=0;state.flowing=false;for(var i=0;i0;if(state.flowing!==false)this.resume()}else if(ev==="readable"){if(!state.endEmitted&&!state.readableListening){state.readableListening=state.needReadable=true;state.flowing=false;state.emittedReadable=false;debug("on readable",state.length,state.reading);if(state.length){emitReadable(this)}else if(!state.reading){process.nextTick(nReadingNextTick,this)}}}return res};Readable.prototype.addListener=Readable.prototype.on;Readable.prototype.removeListener=function(ev,fn){var res=Stream.prototype.removeListener.call(this,ev,fn);if(ev==="readable"){process.nextTick(updateReadableListening,this)}return res};Readable.prototype.removeAllListeners=function(ev){var res=Stream.prototype.removeAllListeners.apply(this,arguments);if(ev==="readable"||ev===undefined){process.nextTick(updateReadableListening,this)}return res};function updateReadableListening(self){var state=self._readableState;state.readableListening=self.listenerCount("readable")>0;if(state.resumeScheduled&&!state.paused){state.flowing=true}else if(self.listenerCount("data")>0){self.resume()}}function nReadingNextTick(self){debug("readable nexttick read 0");self.read(0)}Readable.prototype.resume=function(){var state=this._readableState;if(!state.flowing){debug("resume");state.flowing=!state.readableListening;resume(this,state)}state.paused=false;return this};function resume(stream,state){if(!state.resumeScheduled){state.resumeScheduled=true;process.nextTick(resume_,stream,state)}}function resume_(stream,state){debug("resume",state.reading);if(!state.reading){stream.read(0)}state.resumeScheduled=false;stream.emit("resume");flow(stream);if(state.flowing&&!state.reading)stream.read(0)}Readable.prototype.pause=function(){debug("call pause flowing=%j",this._readableState.flowing);if(this._readableState.flowing!==false){debug("pause");this._readableState.flowing=false;this.emit("pause")}this._readableState.paused=true;return this};function flow(stream){var state=stream._readableState;debug("flow",state.flowing);while(state.flowing&&stream.read()!==null){}}Readable.prototype.wrap=function(stream){var _this=this;var state=this._readableState;var paused=false;stream.on("end",function(){debug("wrapped end");if(state.decoder&&!state.ended){var chunk=state.decoder.end();if(chunk&&chunk.length)_this.push(chunk)}_this.push(null)});stream.on("data",function(chunk){debug("wrapped data");if(state.decoder)chunk=state.decoder.write(chunk);if(state.objectMode&&(chunk===null||chunk===undefined))return;else if(!state.objectMode&&(!chunk||!chunk.length))return;var ret=_this.push(chunk);if(!ret){paused=true;stream.pause()}});for(var i in stream){if(this[i]===undefined&&typeof stream[i]==="function"){this[i]=function methodWrap(method){return function methodWrapReturnFunction(){return stream[method].apply(stream,arguments)}}(i)}}for(var n=0;n=state.length){if(state.decoder)ret=state.buffer.join("");else if(state.buffer.length===1)ret=state.buffer.first();else ret=state.buffer.concat(state.length);state.buffer.clear()}else{ret=state.buffer.consume(n,state.decoder)}return ret}function endReadable(stream){var state=stream._readableState;debug("endReadable",state.endEmitted);if(!state.endEmitted){state.ended=true;process.nextTick(endReadableNT,state,stream)}}function endReadableNT(state,stream){debug("endReadableNT",state.endEmitted,state.length);if(!state.endEmitted&&state.length===0){state.endEmitted=true;stream.readable=false;stream.emit("end");if(state.autoDestroy){var wState=stream._writableState;if(!wState||wState.autoDestroy&&wState.finished){stream.destroy()}}}}if(typeof Symbol==="function"){Readable.from=function(iterable,opts){if(from===undefined){from=require("./internal/streams/from")}return from(Readable,iterable,opts)}}function indexOf(xs,x){for(var i=0,l=xs.length;i-1))throw new ERR_UNKNOWN_ENCODING(encoding);this._writableState.defaultEncoding=encoding;return this};Object.defineProperty(Writable.prototype,"writableBuffer",{enumerable:false,get:function get(){return this._writableState&&this._writableState.getBuffer()}});function decodeChunk(state,chunk,encoding){if(!state.objectMode&&state.decodeStrings!==false&&typeof chunk==="string"){chunk=Buffer.from(chunk,encoding)}return chunk}Object.defineProperty(Writable.prototype,"writableHighWaterMark",{enumerable:false,get:function get(){return this._writableState.highWaterMark}});function writeOrBuffer(stream,state,isBuf,chunk,encoding,cb){if(!isBuf){var newChunk=decodeChunk(state,chunk,encoding);if(chunk!==newChunk){isBuf=true;encoding="buffer";chunk=newChunk}}var len=state.objectMode?1:chunk.length;state.length+=len;var ret=state.length0)this.tail.next=entry;else this.head=entry;this.tail=entry;++this.length}},{key:"unshift",value:function unshift(v){var entry={data:v,next:this.head};if(this.length===0)this.tail=entry;this.head=entry;++this.length}},{key:"shift",value:function shift(){if(this.length===0)return;var ret=this.head.data;if(this.length===1)this.head=this.tail=null;else this.head=this.head.next;--this.length;return ret}},{key:"clear",value:function clear(){this.head=this.tail=null;this.length=0}},{key:"join",value:function join(s){if(this.length===0)return"";var p=this.head;var ret=""+p.data;while(p=p.next){ret+=s+p.data}return ret}},{key:"concat",value:function concat(n){if(this.length===0)return Buffer.alloc(0);var ret=Buffer.allocUnsafe(n>>>0);var p=this.head;var i=0;while(p){copyBuffer(p.data,ret,i);i+=p.data.length;p=p.next}return ret}},{key:"consume",value:function consume(n,hasStrings){var ret;if(nstr.length?str.length:n;if(nb===str.length)ret+=str;else ret+=str.slice(0,n);n-=nb;if(n===0){if(nb===str.length){++c;if(p.next)this.head=p.next;else this.head=this.tail=null}else{this.head=p;p.data=str.slice(nb)}break}++c}this.length-=c;return ret}},{key:"_getBuffer",value:function _getBuffer(n){var ret=Buffer.allocUnsafe(n);var p=this.head;var c=1;p.data.copy(ret);n-=p.data.length;while(p=p.next){var buf=p.data;var nb=n>buf.length?buf.length:n;buf.copy(ret,ret.length-n,0,nb);n-=nb;if(n===0){if(nb===buf.length){++c;if(p.next)this.head=p.next;else this.head=this.tail=null}else{this.head=p;p.data=buf.slice(nb)}break}++c}this.length-=c;return ret}},{key:custom,value:function value(_,options){return inspect(this,_objectSpread({},options,{depth:0,customInspect:false}))}}]);return BufferList}()},{buffer:175,util:131}],167:[function(require,module,exports){(function(process){(function(){"use strict";function destroy(err,cb){var _this=this;var readableDestroyed=this._readableState&&this._readableState.destroyed;var writableDestroyed=this._writableState&&this._writableState.destroyed;if(readableDestroyed||writableDestroyed){if(cb){cb(err)}else if(err){if(!this._writableState){process.nextTick(emitErrorNT,this,err)}else if(!this._writableState.errorEmitted){this._writableState.errorEmitted=true;process.nextTick(emitErrorNT,this,err)}}return this}if(this._readableState){this._readableState.destroyed=true}if(this._writableState){this._writableState.destroyed=true}this._destroy(err||null,function(err){if(!cb&&err){if(!_this._writableState){process.nextTick(emitErrorAndCloseNT,_this,err)}else if(!_this._writableState.errorEmitted){_this._writableState.errorEmitted=true;process.nextTick(emitErrorAndCloseNT,_this,err)}else{process.nextTick(emitCloseNT,_this)}}else if(cb){process.nextTick(emitCloseNT,_this);cb(err)}else{process.nextTick(emitCloseNT,_this)}});return this}function emitErrorAndCloseNT(self,err){emitErrorNT(self,err);emitCloseNT(self)}function emitCloseNT(self){if(self._writableState&&!self._writableState.emitClose)return;if(self._readableState&&!self._readableState.emitClose)return;self.emit("close")}function undestroy(){if(this._readableState){this._readableState.destroyed=false;this._readableState.reading=false;this._readableState.ended=false;this._readableState.endEmitted=false}if(this._writableState){this._writableState.destroyed=false;this._writableState.ended=false;this._writableState.ending=false;this._writableState.finalCalled=false;this._writableState.prefinished=false;this._writableState.finished=false;this._writableState.errorEmitted=false}}function emitErrorNT(self,err){self.emit("error",err)}function errorOrDestroy(stream,err){var rState=stream._readableState;var wState=stream._writableState;if(rState&&rState.autoDestroy||wState&&wState.autoDestroy)stream.destroy(err);else stream.emit("error",err)}module.exports={destroy:destroy,undestroy:undestroy,errorOrDestroy:errorOrDestroy}}).call(this)}).call(this,require("_process"))},{_process:262}],168:[function(require,module,exports){"use strict";var ERR_STREAM_PREMATURE_CLOSE=require("../../../errors").codes.ERR_STREAM_PREMATURE_CLOSE;function once(callback){var called=false;return function(){if(called)return;called=true;for(var _len=arguments.length,args=new Array(_len),_key=0;_key<_len;_key++){args[_key]=arguments[_key]}callback.apply(this,args)}}function noop(){}function isRequest(stream){return stream.setHeader&&typeof stream.abort==="function"}function eos(stream,opts,callback){if(typeof opts==="function")return eos(stream,null,opts);if(!opts)opts={};callback=once(callback||noop);var readable=opts.readable||opts.readable!==false&&stream.readable;var writable=opts.writable||opts.writable!==false&&stream.writable;var onlegacyfinish=function onlegacyfinish(){if(!stream.writable)onfinish()};var writableEnded=stream._writableState&&stream._writableState.finished;var onfinish=function onfinish(){writable=false;writableEnded=true;if(!readable)callback.call(stream)};var readableEnded=stream._readableState&&stream._readableState.endEmitted;var onend=function onend(){readable=false;readableEnded=true;if(!writable)callback.call(stream)};var onerror=function onerror(err){callback.call(stream,err)};var onclose=function onclose(){var err;if(readable&&!readableEnded){if(!stream._readableState||!stream._readableState.ended)err=new ERR_STREAM_PREMATURE_CLOSE;return callback.call(stream,err)}if(writable&&!writableEnded){if(!stream._writableState||!stream._writableState.ended)err=new ERR_STREAM_PREMATURE_CLOSE;return callback.call(stream,err)}};var onrequest=function onrequest(){stream.req.on("finish",onfinish)};if(isRequest(stream)){stream.on("complete",onfinish);stream.on("abort",onclose);if(stream.req)onrequest();else stream.on("request",onrequest)}else if(writable&&!stream._writableState){stream.on("end",onlegacyfinish);stream.on("close",onlegacyfinish)}stream.on("end",onend);stream.on("finish",onfinish);if(opts.error!==false)stream.on("error",onerror);stream.on("close",onclose);return function(){stream.removeListener("complete",onfinish);stream.removeListener("abort",onclose);stream.removeListener("request",onrequest);if(stream.req)stream.req.removeListener("finish",onfinish);stream.removeListener("end",onlegacyfinish);stream.removeListener("close",onlegacyfinish);stream.removeListener("finish",onfinish);stream.removeListener("end",onend);stream.removeListener("error",onerror);stream.removeListener("close",onclose)}}module.exports=eos},{"../../../errors":159}],169:[function(require,module,exports){module.exports=function(){throw new Error("Readable.from is not available in the browser")}},{}],170:[function(require,module,exports){"use strict";var eos;function once(callback){var called=false;return function(){if(called)return;called=true;callback.apply(void 0,arguments)}}var _require$codes=require("../../../errors").codes,ERR_MISSING_ARGS=_require$codes.ERR_MISSING_ARGS,ERR_STREAM_DESTROYED=_require$codes.ERR_STREAM_DESTROYED;function noop(err){if(err)throw err}function isRequest(stream){return stream.setHeader&&typeof stream.abort==="function"}function destroyer(stream,reading,writing,callback){callback=once(callback);var closed=false;stream.on("close",function(){closed=true});if(eos===undefined)eos=require("./end-of-stream");eos(stream,{readable:reading,writable:writing},function(err){if(err)return callback(err);closed=true;callback()});var destroyed=false;return function(err){if(closed)return;if(destroyed)return;destroyed=true;if(isRequest(stream))return stream.abort();if(typeof stream.destroy==="function")return stream.destroy();callback(err||new ERR_STREAM_DESTROYED("pipe"))}}function call(fn){fn()}function pipe(from,to){return from.pipe(to)}function popCallback(streams){if(!streams.length)return noop;if(typeof streams[streams.length-1]!=="function")return noop;return streams.pop()}function pipeline(){for(var _len=arguments.length,streams=new Array(_len),_key=0;_key<_len;_key++){streams[_key]=arguments[_key]}var callback=popCallback(streams);if(Array.isArray(streams[0]))streams=streams[0];if(streams.length<2){throw new ERR_MISSING_ARGS("streams")}var error;var destroys=streams.map(function(stream,i){var reading=i0;return destroyer(stream,reading,writing,function(err){if(!error)error=err;if(err)destroys.forEach(call);if(reading)return;destroys.forEach(call);callback(error)})});return streams.reduce(pipe)}module.exports=pipeline},{"../../../errors":159,"./end-of-stream":168}],171:[function(require,module,exports){"use strict";var ERR_INVALID_OPT_VALUE=require("../../../errors").codes.ERR_INVALID_OPT_VALUE;function highWaterMarkFrom(options,isDuplex,duplexKey){return options.highWaterMark!=null?options.highWaterMark:isDuplex?options[duplexKey]:null}function getHighWaterMark(state,options,duplexKey,isDuplex){var hwm=highWaterMarkFrom(options,isDuplex,duplexKey);if(hwm!=null){if(!(isFinite(hwm)&&Math.floor(hwm)===hwm)||hwm<0){var name=isDuplex?duplexKey:"highWaterMark";throw new ERR_INVALID_OPT_VALUE(name,hwm)}return Math.floor(hwm)}return state.objectMode?16:16*1024}module.exports={getHighWaterMark:getHighWaterMark}},{"../../../errors":159}],172:[function(require,module,exports){module.exports=require("events").EventEmitter},{events:212}],173:[function(require,module,exports){exports=module.exports=require("./lib/_stream_readable.js");exports.Stream=exports;exports.Readable=exports;exports.Writable=require("./lib/_stream_writable.js");exports.Duplex=require("./lib/_stream_duplex.js");exports.Transform=require("./lib/_stream_transform.js");exports.PassThrough=require("./lib/_stream_passthrough.js");exports.finished=require("./lib/internal/streams/end-of-stream.js");exports.pipeline=require("./lib/internal/streams/pipeline.js")},{"./lib/_stream_duplex.js":160,"./lib/_stream_passthrough.js":161,"./lib/_stream_readable.js":162,"./lib/_stream_transform.js":163,"./lib/_stream_writable.js":164,"./lib/internal/streams/end-of-stream.js":168,"./lib/internal/streams/pipeline.js":170}],174:[function(require,module,exports){(function(Buffer){(function(){module.exports=function xor(a,b){var length=Math.min(a.length,b.length);var buffer=new Buffer(length);for(var i=0;iK_MAX_LENGTH){throw new RangeError('The value "'+length+'" is invalid for option "size"')}var buf=new Uint8Array(length);buf.__proto__=Buffer.prototype;return buf}function Buffer(arg,encodingOrOffset,length){if(typeof arg==="number"){if(typeof encodingOrOffset==="string"){throw new TypeError('The "string" argument must be of type string. Received type number')}return allocUnsafe(arg)}return from(arg,encodingOrOffset,length)}if(typeof Symbol!=="undefined"&&Symbol.species!=null&&Buffer[Symbol.species]===Buffer){Object.defineProperty(Buffer,Symbol.species,{value:null,configurable:true,enumerable:false,writable:false})}Buffer.poolSize=8192;function from(value,encodingOrOffset,length){if(typeof value==="string"){return fromString(value,encodingOrOffset)}if(ArrayBuffer.isView(value)){return fromArrayLike(value)}if(value==null){throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof value)}if(isInstance(value,ArrayBuffer)||value&&isInstance(value.buffer,ArrayBuffer)){return fromArrayBuffer(value,encodingOrOffset,length)}if(typeof value==="number"){throw new TypeError('The "value" argument must not be of type number. Received type number')}var valueOf=value.valueOf&&value.valueOf();if(valueOf!=null&&valueOf!==value){return Buffer.from(valueOf,encodingOrOffset,length)}var b=fromObject(value);if(b)return b;if(typeof Symbol!=="undefined"&&Symbol.toPrimitive!=null&&typeof value[Symbol.toPrimitive]==="function"){return Buffer.from(value[Symbol.toPrimitive]("string"),encodingOrOffset,length)}throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, "+"or Array-like Object. Received type "+typeof value)}Buffer.from=function(value,encodingOrOffset,length){return from(value,encodingOrOffset,length)};Buffer.prototype.__proto__=Uint8Array.prototype;Buffer.__proto__=Uint8Array;function assertSize(size){if(typeof size!=="number"){throw new TypeError('"size" argument must be of type number')}else if(size<0){throw new RangeError('The value "'+size+'" is invalid for option "size"')}}function alloc(size,fill,encoding){assertSize(size);if(size<=0){return createBuffer(size)}if(fill!==undefined){return typeof encoding==="string"?createBuffer(size).fill(fill,encoding):createBuffer(size).fill(fill)}return createBuffer(size)}Buffer.alloc=function(size,fill,encoding){return alloc(size,fill,encoding)};function allocUnsafe(size){assertSize(size);return createBuffer(size<0?0:checked(size)|0)}Buffer.allocUnsafe=function(size){return allocUnsafe(size)};Buffer.allocUnsafeSlow=function(size){return allocUnsafe(size)};function fromString(string,encoding){if(typeof encoding!=="string"||encoding===""){encoding="utf8"}if(!Buffer.isEncoding(encoding)){throw new TypeError("Unknown encoding: "+encoding)}var length=byteLength(string,encoding)|0;var buf=createBuffer(length);var actual=buf.write(string,encoding);if(actual!==length){buf=buf.slice(0,actual)}return buf}function fromArrayLike(array){var length=array.length<0?0:checked(array.length)|0;var buf=createBuffer(length);for(var i=0;i=K_MAX_LENGTH){throw new RangeError("Attempt to allocate Buffer larger than maximum "+"size: 0x"+K_MAX_LENGTH.toString(16)+" bytes")}return length|0}function SlowBuffer(length){if(+length!=length){length=0}return Buffer.alloc(+length)}Buffer.isBuffer=function isBuffer(b){return b!=null&&b._isBuffer===true&&b!==Buffer.prototype};Buffer.compare=function compare(a,b){if(isInstance(a,Uint8Array))a=Buffer.from(a,a.offset,a.byteLength);if(isInstance(b,Uint8Array))b=Buffer.from(b,b.offset,b.byteLength);if(!Buffer.isBuffer(a)||!Buffer.isBuffer(b)){throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array')}if(a===b)return 0;var x=a.length;var y=b.length;for(var i=0,len=Math.min(x,y);i2&&arguments[2]===true;if(!mustMatch&&len===0)return 0;var loweredCase=false;for(;;){switch(encoding){case"ascii":case"latin1":case"binary":return len;case"utf8":case"utf-8":return utf8ToBytes(string).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return len*2;case"hex":return len>>>1;case"base64":return base64ToBytes(string).length;default:if(loweredCase){return mustMatch?-1:utf8ToBytes(string).length}encoding=(""+encoding).toLowerCase();loweredCase=true}}}Buffer.byteLength=byteLength;function slowToString(encoding,start,end){var loweredCase=false;if(start===undefined||start<0){start=0}if(start>this.length){return""}if(end===undefined||end>this.length){end=this.length}if(end<=0){return""}end>>>=0;start>>>=0;if(end<=start){return""}if(!encoding)encoding="utf8";while(true){switch(encoding){case"hex":return hexSlice(this,start,end);case"utf8":case"utf-8":return utf8Slice(this,start,end);case"ascii":return asciiSlice(this,start,end);case"latin1":case"binary":return latin1Slice(this,start,end);case"base64":return base64Slice(this,start,end);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return utf16leSlice(this,start,end);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(encoding+"").toLowerCase();loweredCase=true}}}Buffer.prototype._isBuffer=true;function swap(b,n,m){var i=b[n];b[n]=b[m];b[m]=i}Buffer.prototype.swap16=function swap16(){var len=this.length;if(len%2!==0){throw new RangeError("Buffer size must be a multiple of 16-bits")}for(var i=0;imax)str+=" ... ";return""};Buffer.prototype.compare=function compare(target,start,end,thisStart,thisEnd){if(isInstance(target,Uint8Array)){target=Buffer.from(target,target.offset,target.byteLength)}if(!Buffer.isBuffer(target)){throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. '+"Received type "+typeof target)}if(start===undefined){start=0}if(end===undefined){end=target?target.length:0}if(thisStart===undefined){thisStart=0}if(thisEnd===undefined){thisEnd=this.length}if(start<0||end>target.length||thisStart<0||thisEnd>this.length){throw new RangeError("out of range index")}if(thisStart>=thisEnd&&start>=end){return 0}if(thisStart>=thisEnd){return-1}if(start>=end){return 1}start>>>=0;end>>>=0;thisStart>>>=0;thisEnd>>>=0;if(this===target)return 0;var x=thisEnd-thisStart;var y=end-start;var len=Math.min(x,y);var thisCopy=this.slice(thisStart,thisEnd);var targetCopy=target.slice(start,end);for(var i=0;i2147483647){byteOffset=2147483647}else if(byteOffset<-2147483648){byteOffset=-2147483648}byteOffset=+byteOffset;if(numberIsNaN(byteOffset)){byteOffset=dir?0:buffer.length-1}if(byteOffset<0)byteOffset=buffer.length+byteOffset;if(byteOffset>=buffer.length){if(dir)return-1;else byteOffset=buffer.length-1}else if(byteOffset<0){if(dir)byteOffset=0;else return-1}if(typeof val==="string"){val=Buffer.from(val,encoding)}if(Buffer.isBuffer(val)){if(val.length===0){return-1}return arrayIndexOf(buffer,val,byteOffset,encoding,dir)}else if(typeof val==="number"){val=val&255;if(typeof Uint8Array.prototype.indexOf==="function"){if(dir){return Uint8Array.prototype.indexOf.call(buffer,val,byteOffset)}else{return Uint8Array.prototype.lastIndexOf.call(buffer,val,byteOffset)}}return arrayIndexOf(buffer,[val],byteOffset,encoding,dir)}throw new TypeError("val must be string, number or Buffer")}function arrayIndexOf(arr,val,byteOffset,encoding,dir){var indexSize=1;var arrLength=arr.length;var valLength=val.length;if(encoding!==undefined){encoding=String(encoding).toLowerCase();if(encoding==="ucs2"||encoding==="ucs-2"||encoding==="utf16le"||encoding==="utf-16le"){if(arr.length<2||val.length<2){return-1}indexSize=2;arrLength/=2;valLength/=2;byteOffset/=2}}function read(buf,i){if(indexSize===1){return buf[i]}else{return buf.readUInt16BE(i*indexSize)}}var i;if(dir){var foundIndex=-1;for(i=byteOffset;iarrLength)byteOffset=arrLength-valLength;for(i=byteOffset;i>=0;i--){var found=true;for(var j=0;jremaining){length=remaining}}var strLen=string.length;if(length>strLen/2){length=strLen/2}for(var i=0;i>>0;if(isFinite(length)){length=length>>>0;if(encoding===undefined)encoding="utf8"}else{encoding=length;length=undefined}}else{throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported")}var remaining=this.length-offset;if(length===undefined||length>remaining)length=remaining;if(string.length>0&&(length<0||offset<0)||offset>this.length){throw new RangeError("Attempt to write outside buffer bounds")}if(!encoding)encoding="utf8";var loweredCase=false;for(;;){switch(encoding){case"hex":return hexWrite(this,string,offset,length);case"utf8":case"utf-8":return utf8Write(this,string,offset,length);case"ascii":return asciiWrite(this,string,offset,length);case"latin1":case"binary":return latin1Write(this,string,offset,length);case"base64":return base64Write(this,string,offset,length);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return ucs2Write(this,string,offset,length);default:if(loweredCase)throw new TypeError("Unknown encoding: "+encoding);encoding=(""+encoding).toLowerCase();loweredCase=true}}};Buffer.prototype.toJSON=function toJSON(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function base64Slice(buf,start,end){if(start===0&&end===buf.length){return base64.fromByteArray(buf)}else{return base64.fromByteArray(buf.slice(start,end))}}function utf8Slice(buf,start,end){end=Math.min(buf.length,end);var res=[];var i=start;while(i239?4:firstByte>223?3:firstByte>191?2:1;if(i+bytesPerSequence<=end){var secondByte,thirdByte,fourthByte,tempCodePoint;switch(bytesPerSequence){case 1:if(firstByte<128){codePoint=firstByte}break;case 2:secondByte=buf[i+1];if((secondByte&192)===128){tempCodePoint=(firstByte&31)<<6|secondByte&63;if(tempCodePoint>127){codePoint=tempCodePoint}}break;case 3:secondByte=buf[i+1];thirdByte=buf[i+2];if((secondByte&192)===128&&(thirdByte&192)===128){tempCodePoint=(firstByte&15)<<12|(secondByte&63)<<6|thirdByte&63;if(tempCodePoint>2047&&(tempCodePoint<55296||tempCodePoint>57343)){codePoint=tempCodePoint}}break;case 4:secondByte=buf[i+1];thirdByte=buf[i+2];fourthByte=buf[i+3];if((secondByte&192)===128&&(thirdByte&192)===128&&(fourthByte&192)===128){tempCodePoint=(firstByte&15)<<18|(secondByte&63)<<12|(thirdByte&63)<<6|fourthByte&63;if(tempCodePoint>65535&&tempCodePoint<1114112){codePoint=tempCodePoint}}}}if(codePoint===null){codePoint=65533;bytesPerSequence=1}else if(codePoint>65535){codePoint-=65536;res.push(codePoint>>>10&1023|55296);codePoint=56320|codePoint&1023}res.push(codePoint);i+=bytesPerSequence}return decodeCodePointsArray(res)}var MAX_ARGUMENTS_LENGTH=4096;function decodeCodePointsArray(codePoints){var len=codePoints.length;if(len<=MAX_ARGUMENTS_LENGTH){return String.fromCharCode.apply(String,codePoints)}var res="";var i=0;while(ilen)end=len;var out="";for(var i=start;ilen){start=len}if(end<0){end+=len;if(end<0)end=0}else if(end>len){end=len}if(endlength)throw new RangeError("Trying to access beyond buffer length")}Buffer.prototype.readUIntLE=function readUIntLE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i>>0;byteLength=byteLength>>>0;if(!noAssert){checkOffset(offset,byteLength,this.length)}var val=this[offset+--byteLength];var mul=1;while(byteLength>0&&(mul*=256)){val+=this[offset+--byteLength]*mul}return val};Buffer.prototype.readUInt8=function readUInt8(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,1,this.length);return this[offset]};Buffer.prototype.readUInt16LE=function readUInt16LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);return this[offset]|this[offset+1]<<8};Buffer.prototype.readUInt16BE=function readUInt16BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);return this[offset]<<8|this[offset+1]};Buffer.prototype.readUInt32LE=function readUInt32LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return(this[offset]|this[offset+1]<<8|this[offset+2]<<16)+this[offset+3]*16777216};Buffer.prototype.readUInt32BE=function readUInt32BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]*16777216+(this[offset+1]<<16|this[offset+2]<<8|this[offset+3])};Buffer.prototype.readIntLE=function readIntLE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var val=this[offset];var mul=1;var i=0;while(++i=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readIntBE=function readIntBE(offset,byteLength,noAssert){offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert)checkOffset(offset,byteLength,this.length);var i=byteLength;var mul=1;var val=this[offset+--i];while(i>0&&(mul*=256)){val+=this[offset+--i]*mul}mul*=128;if(val>=mul)val-=Math.pow(2,8*byteLength);return val};Buffer.prototype.readInt8=function readInt8(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,1,this.length);if(!(this[offset]&128))return this[offset];return(255-this[offset]+1)*-1};Buffer.prototype.readInt16LE=function readInt16LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset]|this[offset+1]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt16BE=function readInt16BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,2,this.length);var val=this[offset+1]|this[offset]<<8;return val&32768?val|4294901760:val};Buffer.prototype.readInt32LE=function readInt32LE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]|this[offset+1]<<8|this[offset+2]<<16|this[offset+3]<<24};Buffer.prototype.readInt32BE=function readInt32BE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return this[offset]<<24|this[offset+1]<<16|this[offset+2]<<8|this[offset+3]};Buffer.prototype.readFloatLE=function readFloatLE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,true,23,4)};Buffer.prototype.readFloatBE=function readFloatBE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,4,this.length);return ieee754.read(this,offset,false,23,4)};Buffer.prototype.readDoubleLE=function readDoubleLE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,true,52,8)};Buffer.prototype.readDoubleBE=function readDoubleBE(offset,noAssert){offset=offset>>>0;if(!noAssert)checkOffset(offset,8,this.length);return ieee754.read(this,offset,false,52,8)};function checkInt(buf,value,offset,ext,max,min){if(!Buffer.isBuffer(buf))throw new TypeError('"buffer" argument must be a Buffer instance');if(value>max||valuebuf.length)throw new RangeError("Index out of range")}Buffer.prototype.writeUIntLE=function writeUIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;byteLength=byteLength>>>0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var mul=1;var i=0;this[offset]=value&255;while(++i>>0;byteLength=byteLength>>>0;if(!noAssert){var maxBytes=Math.pow(2,8*byteLength)-1;checkInt(this,value,offset,byteLength,maxBytes,0)}var i=byteLength-1;var mul=1;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){this[offset+i]=value/mul&255}return offset+byteLength};Buffer.prototype.writeUInt8=function writeUInt8(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,255,0);this[offset]=value&255;return offset+1};Buffer.prototype.writeUInt16LE=function writeUInt16LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);this[offset]=value&255;this[offset+1]=value>>>8;return offset+2};Buffer.prototype.writeUInt16BE=function writeUInt16BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,65535,0);this[offset]=value>>>8;this[offset+1]=value&255;return offset+2};Buffer.prototype.writeUInt32LE=function writeUInt32LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);this[offset+3]=value>>>24;this[offset+2]=value>>>16;this[offset+1]=value>>>8;this[offset]=value&255;return offset+4};Buffer.prototype.writeUInt32BE=function writeUInt32BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,4294967295,0);this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255;return offset+4};Buffer.prototype.writeIntLE=function writeIntLE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=0;var mul=1;var sub=0;this[offset]=value&255;while(++i>0)-sub&255}return offset+byteLength};Buffer.prototype.writeIntBE=function writeIntBE(value,offset,byteLength,noAssert){value=+value;offset=offset>>>0;if(!noAssert){var limit=Math.pow(2,8*byteLength-1);checkInt(this,value,offset,byteLength,limit-1,-limit)}var i=byteLength-1;var mul=1;var sub=0;this[offset+i]=value&255;while(--i>=0&&(mul*=256)){if(value<0&&sub===0&&this[offset+i+1]!==0){sub=1}this[offset+i]=(value/mul>>0)-sub&255}return offset+byteLength};Buffer.prototype.writeInt8=function writeInt8(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,1,127,-128);if(value<0)value=255+value+1;this[offset]=value&255;return offset+1};Buffer.prototype.writeInt16LE=function writeInt16LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);this[offset]=value&255;this[offset+1]=value>>>8;return offset+2};Buffer.prototype.writeInt16BE=function writeInt16BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,2,32767,-32768);this[offset]=value>>>8;this[offset+1]=value&255;return offset+2};Buffer.prototype.writeInt32LE=function writeInt32LE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);this[offset]=value&255;this[offset+1]=value>>>8;this[offset+2]=value>>>16;this[offset+3]=value>>>24;return offset+4};Buffer.prototype.writeInt32BE=function writeInt32BE(value,offset,noAssert){value=+value;offset=offset>>>0;if(!noAssert)checkInt(this,value,offset,4,2147483647,-2147483648);if(value<0)value=4294967295+value+1;this[offset]=value>>>24;this[offset+1]=value>>>16;this[offset+2]=value>>>8;this[offset+3]=value&255;return offset+4};function checkIEEE754(buf,value,offset,ext,max,min){if(offset+ext>buf.length)throw new RangeError("Index out of range");if(offset<0)throw new RangeError("Index out of range")}function writeFloat(buf,value,offset,littleEndian,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkIEEE754(buf,value,offset,4,34028234663852886e22,-34028234663852886e22)}ieee754.write(buf,value,offset,littleEndian,23,4);return offset+4}Buffer.prototype.writeFloatLE=function writeFloatLE(value,offset,noAssert){return writeFloat(this,value,offset,true,noAssert)};Buffer.prototype.writeFloatBE=function writeFloatBE(value,offset,noAssert){return writeFloat(this,value,offset,false,noAssert)};function writeDouble(buf,value,offset,littleEndian,noAssert){value=+value;offset=offset>>>0;if(!noAssert){checkIEEE754(buf,value,offset,8,17976931348623157e292,-17976931348623157e292)}ieee754.write(buf,value,offset,littleEndian,52,8);return offset+8}Buffer.prototype.writeDoubleLE=function writeDoubleLE(value,offset,noAssert){return writeDouble(this,value,offset,true,noAssert)};Buffer.prototype.writeDoubleBE=function writeDoubleBE(value,offset,noAssert){return writeDouble(this,value,offset,false,noAssert)};Buffer.prototype.copy=function copy(target,targetStart,start,end){if(!Buffer.isBuffer(target))throw new TypeError("argument should be a Buffer");if(!start)start=0;if(!end&&end!==0)end=this.length;if(targetStart>=target.length)targetStart=target.length;if(!targetStart)targetStart=0;if(end>0&&end=this.length)throw new RangeError("Index out of range");if(end<0)throw new RangeError("sourceEnd out of bounds");if(end>this.length)end=this.length;if(target.length-targetStart=0;--i){target[i+targetStart]=this[i+start]}}else{Uint8Array.prototype.set.call(target,this.subarray(start,end),targetStart)}return len};Buffer.prototype.fill=function fill(val,start,end,encoding){if(typeof val==="string"){if(typeof start==="string"){encoding=start;start=0;end=this.length}else if(typeof end==="string"){encoding=end;end=this.length}if(encoding!==undefined&&typeof encoding!=="string"){throw new TypeError("encoding must be a string")}if(typeof encoding==="string"&&!Buffer.isEncoding(encoding)){throw new TypeError("Unknown encoding: "+encoding)}if(val.length===1){var code=val.charCodeAt(0);if(encoding==="utf8"&&code<128||encoding==="latin1"){val=code}}}else if(typeof val==="number"){val=val&255}if(start<0||this.length>>0;end=end===undefined?this.length:end>>>0;if(!val)val=0;var i;if(typeof val==="number"){for(i=start;i55295&&codePoint<57344){if(!leadSurrogate){if(codePoint>56319){if((units-=3)>-1)bytes.push(239,191,189);continue}else if(i+1===length){if((units-=3)>-1)bytes.push(239,191,189);continue}leadSurrogate=codePoint;continue}if(codePoint<56320){if((units-=3)>-1)bytes.push(239,191,189);leadSurrogate=codePoint;continue}codePoint=(leadSurrogate-55296<<10|codePoint-56320)+65536}else if(leadSurrogate){if((units-=3)>-1)bytes.push(239,191,189)}leadSurrogate=null;if(codePoint<128){if((units-=1)<0)break;bytes.push(codePoint)}else if(codePoint<2048){if((units-=2)<0)break;bytes.push(codePoint>>6|192,codePoint&63|128)}else if(codePoint<65536){if((units-=3)<0)break;bytes.push(codePoint>>12|224,codePoint>>6&63|128,codePoint&63|128)}else if(codePoint<1114112){if((units-=4)<0)break;bytes.push(codePoint>>18|240,codePoint>>12&63|128,codePoint>>6&63|128,codePoint&63|128)}else{throw new Error("Invalid code point")}}return bytes}function asciiToBytes(str){var byteArray=[];for(var i=0;i>8;lo=c%256;byteArray.push(lo);byteArray.push(hi)}return byteArray}function base64ToBytes(str){return base64.toByteArray(base64clean(str))}function blitBuffer(src,dst,offset,length){for(var i=0;i=dst.length||i>=src.length)break;dst[i+offset]=src[i]}return i}function isInstance(obj,type){return obj instanceof type||obj!=null&&obj.constructor!=null&&obj.constructor.name!=null&&obj.constructor.name===type.name}function numberIsNaN(obj){return obj!==obj}}).call(this)}).call(this,require("buffer").Buffer)},{"base64-js":128,buffer:175,ieee754:243}],176:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;var Transform=require("stream").Transform;var StringDecoder=require("string_decoder").StringDecoder;var inherits=require("inherits");function CipherBase(hashMode){Transform.call(this);this.hashMode=typeof hashMode==="string";if(this.hashMode){this[hashMode]=this._finalOrDigest}else{this.final=this._finalOrDigest}if(this._final){this.__final=this._final;this._final=null}this._decoder=null;this._encoding=null}inherits(CipherBase,Transform);CipherBase.prototype.update=function(data,inputEnc,outputEnc){if(typeof data==="string"){data=Buffer.from(data,inputEnc)}var outData=this._update(data);if(this.hashMode)return this;if(outputEnc){outData=this._toString(outData,outputEnc)}return outData};CipherBase.prototype.setAutoPadding=function(){};CipherBase.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")};CipherBase.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")};CipherBase.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")};CipherBase.prototype._transform=function(data,_,next){var err;try{if(this.hashMode){this._update(data)}else{this.push(this._update(data))}}catch(e){err=e}finally{next(err)}};CipherBase.prototype._flush=function(done){var err;try{this.push(this.__final())}catch(e){err=e}done(err)};CipherBase.prototype._finalOrDigest=function(outputEnc){var outData=this.__final()||Buffer.alloc(0);if(outputEnc){outData=this._toString(outData,outputEnc,true)}return outData};CipherBase.prototype._toString=function(value,enc,fin){if(!this._decoder){this._decoder=new StringDecoder(enc);this._encoding=enc}if(this._encoding!==enc)throw new Error("can't switch encodings");var out=this._decoder.write(value);if(fin){out+=this._decoder.end()}return out};module.exports=CipherBase},{inherits:244,"safe-buffer":277,stream:287,string_decoder:302}],177:[function(require,module,exports){(function(Buffer){(function(){var elliptic=require("elliptic");var BN=require("bn.js");module.exports=function createECDH(curve){return new ECDH(curve)};var aliases={secp256k1:{name:"secp256k1",byteLength:32},secp224r1:{name:"p224",byteLength:28},prime256v1:{name:"p256",byteLength:32},prime192v1:{name:"p192",byteLength:24},ed25519:{name:"ed25519",byteLength:32},secp384r1:{name:"p384",byteLength:48},secp521r1:{name:"p521",byteLength:66}};aliases.p224=aliases.secp224r1;aliases.p256=aliases.secp256r1=aliases.prime256v1;aliases.p192=aliases.secp192r1=aliases.prime192v1;aliases.p384=aliases.secp384r1;aliases.p521=aliases.secp521r1;function ECDH(curve){this.curveType=aliases[curve];if(!this.curveType){this.curveType={name:curve}}this.curve=new elliptic.ec(this.curveType.name);this.keys=void 0}ECDH.prototype.generateKeys=function(enc,format){this.keys=this.curve.genKeyPair();return this.getPublicKey(enc,format)};ECDH.prototype.computeSecret=function(other,inenc,enc){inenc=inenc||"utf8";if(!Buffer.isBuffer(other)){other=new Buffer(other,inenc)}var otherPub=this.curve.keyFromPublic(other).getPublic();var out=otherPub.mul(this.keys.getPrivate()).getX();return formatReturnValue(out,enc,this.curveType.byteLength)};ECDH.prototype.getPublicKey=function(enc,format){var key=this.keys.getPublic(format==="compressed",true);if(format==="hybrid"){if(key[key.length-1]%2){key[0]=7}else{key[0]=6}}return formatReturnValue(key,enc)};ECDH.prototype.getPrivateKey=function(enc){return formatReturnValue(this.keys.getPrivate(),enc)};ECDH.prototype.setPublicKey=function(pub,enc){enc=enc||"utf8";if(!Buffer.isBuffer(pub)){pub=new Buffer(pub,enc)}this.keys._importPublic(pub);return this};ECDH.prototype.setPrivateKey=function(priv,enc){enc=enc||"utf8";if(!Buffer.isBuffer(priv)){priv=new Buffer(priv,enc)}var _priv=new BN(priv);_priv=_priv.toString(16);this.keys=this.curve.genKeyPair();this.keys._importPrivate(_priv);return this};function formatReturnValue(bn,enc,len){if(!Array.isArray(bn)){bn=bn.toArray()}var buf=new Buffer(bn);if(len&&buf.lengthblocksize){var hash=alg==="rmd160"?new RIPEMD160:sha(alg);key=hash.update(key).digest()}else if(key.lengthblocksize){key=alg(key)}else if(key.length0;count--){inputOff+=this._buffer(data,inputOff);outputOff+=this._flushBuffer(out,outputOff)}inputOff+=this._buffer(data,inputOff);return out};Cipher.prototype.final=function final(buffer){var first;if(buffer)first=this.update(buffer);var last;if(this.type==="encrypt")last=this._finalEncrypt();else last=this._finalDecrypt();if(first)return first.concat(last);else return last};Cipher.prototype._pad=function _pad(buffer,off){if(off===0)return false;while(off>>1];kL=utils.r28shl(kL,shift);kR=utils.r28shl(kR,shift);utils.pc2(kL,kR,state.keys,i)}};DES.prototype._update=function _update(inp,inOff,out,outOff){var state=this._desState;var l=utils.readUInt32BE(inp,inOff);var r=utils.readUInt32BE(inp,inOff+4);utils.ip(l,r,state.tmp,0);l=state.tmp[0];r=state.tmp[1];if(this.type==="encrypt")this._encrypt(state,l,r,state.tmp,0);else this._decrypt(state,l,r,state.tmp,0);l=state.tmp[0];r=state.tmp[1];utils.writeUInt32BE(out,l,outOff);utils.writeUInt32BE(out,r,outOff+4)};DES.prototype._pad=function _pad(buffer,off){var value=buffer.length-off;for(var i=off;i>>0;l=t}utils.rip(r,l,out,off)};DES.prototype._decrypt=function _decrypt(state,lStart,rStart,out,off){var l=rStart;var r=lStart;for(var i=state.keys.length-2;i>=0;i-=2){var keyL=state.keys[i];var keyR=state.keys[i+1];utils.expand(l,state.tmp,0);keyL^=state.tmp[0];keyR^=state.tmp[1];var s=utils.substitute(keyL,keyR);var f=utils.permute(s);var t=l;l=(r^f)>>>0;r=t}utils.rip(l,r,out,off)}},{"./cipher":186,"./utils":189,inherits:244,"minimalistic-assert":248}],188:[function(require,module,exports){"use strict";var assert=require("minimalistic-assert");var inherits=require("inherits");var Cipher=require("./cipher");var DES=require("./des");function EDEState(type,key){assert.equal(key.length,24,"Invalid key length");var k1=key.slice(0,8);var k2=key.slice(8,16);var k3=key.slice(16,24);if(type==="encrypt"){this.ciphers=[DES.create({type:"encrypt",key:k1}),DES.create({type:"decrypt",key:k2}),DES.create({type:"encrypt",key:k3})]}else{this.ciphers=[DES.create({type:"decrypt",key:k3}),DES.create({type:"encrypt",key:k2}),DES.create({type:"decrypt",key:k1})]}}function EDE(options){Cipher.call(this,options);var state=new EDEState(this.type,this.options.key);this._edeState=state}inherits(EDE,Cipher);module.exports=EDE;EDE.create=function create(options){return new EDE(options)};EDE.prototype._update=function _update(inp,inOff,out,outOff){var state=this._edeState;state.ciphers[0]._update(inp,inOff,out,outOff);state.ciphers[1]._update(out,outOff,out,outOff);state.ciphers[2]._update(out,outOff,out,outOff)};EDE.prototype._pad=DES.prototype._pad;EDE.prototype._unpad=DES.prototype._unpad},{"./cipher":186,"./des":187,inherits:244,"minimalistic-assert":248}],189:[function(require,module,exports){"use strict";exports.readUInt32BE=function readUInt32BE(bytes,off){var res=bytes[0+off]<<24|bytes[1+off]<<16|bytes[2+off]<<8|bytes[3+off];return res>>>0};exports.writeUInt32BE=function writeUInt32BE(bytes,value,off){bytes[0+off]=value>>>24;bytes[1+off]=value>>>16&255;bytes[2+off]=value>>>8&255;bytes[3+off]=value&255};exports.ip=function ip(inL,inR,out,off){var outL=0;var outR=0;for(var i=6;i>=0;i-=2){for(var j=0;j<=24;j+=8){outL<<=1;outL|=inR>>>j+i&1}for(var j=0;j<=24;j+=8){outL<<=1;outL|=inL>>>j+i&1}}for(var i=6;i>=0;i-=2){for(var j=1;j<=25;j+=8){outR<<=1;outR|=inR>>>j+i&1}for(var j=1;j<=25;j+=8){outR<<=1;outR|=inL>>>j+i&1}}out[off+0]=outL>>>0;out[off+1]=outR>>>0};exports.rip=function rip(inL,inR,out,off){var outL=0;var outR=0;for(var i=0;i<4;i++){for(var j=24;j>=0;j-=8){outL<<=1;outL|=inR>>>j+i&1;outL<<=1;outL|=inL>>>j+i&1}}for(var i=4;i<8;i++){for(var j=24;j>=0;j-=8){outR<<=1;outR|=inR>>>j+i&1;outR<<=1;outR|=inL>>>j+i&1}}out[off+0]=outL>>>0;out[off+1]=outR>>>0};exports.pc1=function pc1(inL,inR,out,off){var outL=0;var outR=0;for(var i=7;i>=5;i--){for(var j=0;j<=24;j+=8){outL<<=1;outL|=inR>>j+i&1}for(var j=0;j<=24;j+=8){outL<<=1;outL|=inL>>j+i&1}}for(var j=0;j<=24;j+=8){outL<<=1;outL|=inR>>j+i&1}for(var i=1;i<=3;i++){for(var j=0;j<=24;j+=8){outR<<=1;outR|=inR>>j+i&1}for(var j=0;j<=24;j+=8){outR<<=1;outR|=inL>>j+i&1}}for(var j=0;j<=24;j+=8){outR<<=1;outR|=inL>>j+i&1}out[off+0]=outL>>>0;out[off+1]=outR>>>0};exports.r28shl=function r28shl(num,shift){return num<>>28-shift};var pc2table=[14,11,17,4,27,23,25,0,13,22,7,18,5,9,16,24,2,20,12,21,1,8,15,26,15,4,25,19,9,1,26,16,5,11,23,8,12,7,17,0,22,3,10,14,6,20,27,24];exports.pc2=function pc2(inL,inR,out,off){var outL=0;var outR=0;var len=pc2table.length>>>1;for(var i=0;i>>pc2table[i]&1}for(var i=len;i>>pc2table[i]&1}out[off+0]=outL>>>0;out[off+1]=outR>>>0};exports.expand=function expand(r,out,off){var outL=0;var outR=0;outL=(r&1)<<5|r>>>27;for(var i=23;i>=15;i-=4){outL<<=6;outL|=r>>>i&63}for(var i=11;i>=3;i-=4){outR|=r>>>i&63;outR<<=6}outR|=(r&31)<<1|r>>>31;out[off+0]=outL>>>0;out[off+1]=outR>>>0};var sTable=[14,0,4,15,13,7,1,4,2,14,15,2,11,13,8,1,3,10,10,6,6,12,12,11,5,9,9,5,0,3,7,8,4,15,1,12,14,8,8,2,13,4,6,9,2,1,11,7,15,5,12,11,9,3,7,14,3,10,10,0,5,6,0,13,15,3,1,13,8,4,14,7,6,15,11,2,3,8,4,14,9,12,7,0,2,1,13,10,12,6,0,9,5,11,10,5,0,13,14,8,7,10,11,1,10,3,4,15,13,4,1,2,5,11,8,6,12,7,6,12,9,0,3,5,2,14,15,9,10,13,0,7,9,0,14,9,6,3,3,4,15,6,5,10,1,2,13,8,12,5,7,14,11,12,4,11,2,15,8,1,13,1,6,10,4,13,9,0,8,6,15,9,3,8,0,7,11,4,1,15,2,14,12,3,5,11,10,5,14,2,7,12,7,13,13,8,14,11,3,5,0,6,6,15,9,0,10,3,1,4,2,7,8,2,5,12,11,1,12,10,4,14,15,9,10,3,6,15,9,0,0,6,12,10,11,1,7,13,13,8,15,9,1,4,3,5,14,11,5,12,2,7,8,2,4,14,2,14,12,11,4,2,1,12,7,4,10,7,11,13,6,1,8,5,5,0,3,15,15,10,13,3,0,9,14,8,9,6,4,11,2,8,1,12,11,7,10,1,13,14,7,2,8,13,15,6,9,15,12,0,5,9,6,10,3,4,0,5,14,3,12,10,1,15,10,4,15,2,9,7,2,12,6,9,8,5,0,6,13,1,3,13,4,14,14,0,7,11,5,3,11,8,9,4,14,3,15,2,5,12,2,9,8,5,12,15,3,10,7,11,0,14,4,1,10,7,1,6,13,0,11,8,6,13,4,13,11,0,2,11,14,7,15,4,0,9,8,1,13,10,3,14,12,3,9,5,7,12,5,2,10,15,6,8,1,6,1,6,4,11,11,13,13,8,12,1,3,4,7,10,14,7,10,9,15,5,6,0,8,15,0,14,5,2,9,3,2,12,13,1,2,15,8,13,4,8,6,10,15,3,11,7,1,4,10,12,9,5,3,6,14,11,5,0,0,14,12,9,7,2,7,2,11,1,4,14,1,7,9,4,12,10,14,8,2,13,0,15,6,12,10,9,13,0,15,3,3,5,5,6,8,11];exports.substitute=function substitute(inL,inR){var out=0;for(var i=0;i<4;i++){var b=inL>>>18-i*6&63;var sb=sTable[i*64+b];out<<=4;out|=sb}for(var i=0;i<4;i++){var b=inR>>>18-i*6&63;var sb=sTable[4*64+i*64+b];out<<=4;out|=sb}return out>>>0};var permuteTable=[16,25,12,11,3,20,4,15,31,17,9,6,27,14,1,22,30,24,8,18,0,5,29,23,13,19,2,26,10,21,28,7];exports.permute=function permute(num){var out=0;for(var i=0;i>>permuteTable[i]&1}return out>>>0};exports.padSplit=function padSplit(num,size,group){var str=num.toString(2);while(str.lengthbits){num.ishrn(1)}if(num.isEven()){num.iadd(ONE)}if(!num.testn(1)){num.iadd(TWO)}if(!gen.cmp(TWO)){while(num.mod(TWENTYFOUR).cmp(ELEVEN)){num.iadd(FOUR)}}else if(!gen.cmp(FIVE)){while(num.mod(TEN).cmp(THREE)){num.iadd(FOUR)}}n2=num.shrn(1);if(simpleSieve(n2)&&simpleSieve(num)&&fermatTest(n2)&&fermatTest(num)&&millerRabin.test(n2)&&millerRabin.test(num)){return num}}}},{"bn.js":194,"miller-rabin":246,randombytes:274}],193:[function(require,module,exports){module.exports={modp1:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff"},modp2:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff"},modp5:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff"},modp14:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff"},modp15:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff"},modp16:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff"},modp17:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff"},modp18:{gen:"02",prime:"ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff"}}},{}],194:[function(require,module,exports){arguments[4][123][0].apply(exports,arguments)},{buffer:131,dup:123}],195:[function(require,module,exports){arguments[4][71][0].apply(exports,arguments)},{"../package.json":211,"./elliptic/curve":198,"./elliptic/curves":201,"./elliptic/ec":202,"./elliptic/eddsa":205,"./elliptic/utils":209,brorand:130,dup:71}],196:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var getNAF=utils.getNAF;var getJSF=utils.getJSF;var assert=utils.assert;function BaseCurve(type,conf){this.type=type;this.p=new BN(conf.p,16);this.red=conf.prime?BN.red(conf.prime):BN.mont(this.p);this.zero=new BN(0).toRed(this.red);this.one=new BN(1).toRed(this.red);this.two=new BN(2).toRed(this.red);this.n=conf.n&&new BN(conf.n,16);this.g=conf.g&&this.pointFromJSON(conf.g,conf.gRed);this._wnafT1=new Array(4);this._wnafT2=new Array(4);this._wnafT3=new Array(4);this._wnafT4=new Array(4);this._bitLength=this.n?this.n.bitLength():0;var adjustCount=this.n&&this.p.div(this.n);if(!adjustCount||adjustCount.cmpn(100)>0){this.redN=null}else{this._maxwellTrick=true;this.redN=this.n.toRed(this.red)}}module.exports=BaseCurve;BaseCurve.prototype.point=function point(){throw new Error("Not implemented")};BaseCurve.prototype.validate=function validate(){throw new Error("Not implemented")};BaseCurve.prototype._fixedNafMul=function _fixedNafMul(p,k){assert(p.precomputed);var doubles=p._getDoubles();var naf=getNAF(k,1,this._bitLength);var I=(1<=j;l--)nafW=(nafW<<1)+naf[l];repr.push(nafW)}var a=this.jpoint(null,null,null);var b=this.jpoint(null,null,null);for(var i=I;i>0;i--){for(j=0;j=0;i--){for(var l=0;i>=0&&naf[i]===0;i--)l++;if(i>=0)l++;acc=acc.dblp(l);if(i<0)break;var z=naf[i];assert(z!==0);if(p.type==="affine"){if(z>0)acc=acc.mixedAdd(wnd[z-1>>1]);else acc=acc.mixedAdd(wnd[-z-1>>1].neg())}else{if(z>0)acc=acc.add(wnd[z-1>>1]);else acc=acc.add(wnd[-z-1>>1].neg())}}return p.type==="affine"?acc.toP():acc};BaseCurve.prototype._wnafMulAdd=function _wnafMulAdd(defW,points,coeffs,len,jacobianResult){var wndWidth=this._wnafT1;var wnd=this._wnafT2;var naf=this._wnafT3;var max=0;var i;var j;var p;for(i=0;i=1;i-=2){var a=i-1;var b=i;if(wndWidth[a]!==1||wndWidth[b]!==1){naf[a]=getNAF(coeffs[a],wndWidth[a],this._bitLength);naf[b]=getNAF(coeffs[b],wndWidth[b],this._bitLength);max=Math.max(naf[a].length,max);max=Math.max(naf[b].length,max);continue}var comb=[points[a],null,null,points[b]];if(points[a].y.cmp(points[b].y)===0){comb[1]=points[a].add(points[b]);comb[2]=points[a].toJ().mixedAdd(points[b].neg())}else if(points[a].y.cmp(points[b].y.redNeg())===0){comb[1]=points[a].toJ().mixedAdd(points[b]);comb[2]=points[a].add(points[b].neg())}else{comb[1]=points[a].toJ().mixedAdd(points[b]);comb[2]=points[a].toJ().mixedAdd(points[b].neg())}var index=[-3,-1,-5,-7,0,7,5,1,3];var jsf=getJSF(coeffs[a],coeffs[b]);max=Math.max(jsf[0].length,max);naf[a]=new Array(max);naf[b]=new Array(max);for(j=0;j=0;i--){var k=0;while(i>=0){var zero=true;for(j=0;j=0)k++;acc=acc.dblp(k);if(i<0)break;for(j=0;j0)p=wnd[j][z-1>>1];else if(z<0)p=wnd[j][-z-1>>1].neg();if(p.type==="affine")acc=acc.mixedAdd(p);else acc=acc.add(p)}}for(i=0;i=Math.ceil((k.bitLength()+1)/doubles.step)};BasePoint.prototype._getDoubles=function _getDoubles(step,power){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;var doubles=[this];var acc=this;for(var i=0;i";return""};Point.prototype.isInfinity=function isInfinity(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)};Point.prototype._extDbl=function _extDbl(){var a=this.x.redSqr();var b=this.y.redSqr();var c=this.z.redSqr();c=c.redIAdd(c);var d=this.curve._mulA(a);var e=this.x.redAdd(this.y).redSqr().redISub(a).redISub(b);var g=d.redAdd(b);var f=g.redSub(c);var h=d.redSub(b);var nx=e.redMul(f);var ny=g.redMul(h);var nt=e.redMul(h);var nz=f.redMul(g);return this.curve.point(nx,ny,nz,nt)};Point.prototype._projDbl=function _projDbl(){var b=this.x.redAdd(this.y).redSqr();var c=this.x.redSqr();var d=this.y.redSqr();var nx;var ny;var nz;var e;var h;var j;if(this.curve.twisted){e=this.curve._mulA(c);var f=e.redAdd(d);if(this.zOne){nx=b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two));ny=f.redMul(e.redSub(d));nz=f.redSqr().redSub(f).redSub(f)}else{h=this.z.redSqr();j=f.redSub(h).redISub(h);nx=b.redSub(c).redISub(d).redMul(j);ny=f.redMul(e.redSub(d));nz=f.redMul(j)}}else{e=c.redAdd(d);h=this.curve._mulC(this.z).redSqr();j=e.redSub(h).redSub(h);nx=this.curve._mulC(b.redISub(e)).redMul(j);ny=this.curve._mulC(e).redMul(c.redISub(d));nz=e.redMul(j)}return this.curve.point(nx,ny,nz)};Point.prototype.dbl=function dbl(){if(this.isInfinity())return this;if(this.curve.extended)return this._extDbl();else return this._projDbl()};Point.prototype._extAdd=function _extAdd(p){var a=this.y.redSub(this.x).redMul(p.y.redSub(p.x));var b=this.y.redAdd(this.x).redMul(p.y.redAdd(p.x));var c=this.t.redMul(this.curve.dd).redMul(p.t);var d=this.z.redMul(p.z.redAdd(p.z));var e=b.redSub(a);var f=d.redSub(c);var g=d.redAdd(c);var h=b.redAdd(a);var nx=e.redMul(f);var ny=g.redMul(h);var nt=e.redMul(h);var nz=f.redMul(g);return this.curve.point(nx,ny,nz,nt)};Point.prototype._projAdd=function _projAdd(p){var a=this.z.redMul(p.z);var b=a.redSqr();var c=this.x.redMul(p.x);var d=this.y.redMul(p.y);var e=this.curve.d.redMul(c).redMul(d);var f=b.redSub(e);var g=b.redAdd(e);var tmp=this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d);var nx=a.redMul(f).redMul(tmp);var ny;var nz;if(this.curve.twisted){ny=a.redMul(g).redMul(d.redSub(this.curve._mulA(c)));nz=f.redMul(g)}else{ny=a.redMul(g).redMul(d.redSub(c));nz=this.curve._mulC(f).redMul(g)}return this.curve.point(nx,ny,nz)};Point.prototype.add=function add(p){if(this.isInfinity())return p;if(p.isInfinity())return this;if(this.curve.extended)return this._extAdd(p);else return this._projAdd(p)};Point.prototype.mul=function mul(k){if(this._hasDoubles(k))return this.curve._fixedNafMul(this,k);else return this.curve._wnafMul(this,k)};Point.prototype.mulAdd=function mulAdd(k1,p,k2){return this.curve._wnafMulAdd(1,[this,p],[k1,k2],2,false)};Point.prototype.jmulAdd=function jmulAdd(k1,p,k2){return this.curve._wnafMulAdd(1,[this,p],[k1,k2],2,true)};Point.prototype.normalize=function normalize(){if(this.zOne)return this;var zi=this.z.redInvm();this.x=this.x.redMul(zi);this.y=this.y.redMul(zi);if(this.t)this.t=this.t.redMul(zi);this.z=this.curve.one;this.zOne=true;return this};Point.prototype.neg=function neg(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())};Point.prototype.getX=function getX(){this.normalize();return this.x.fromRed()};Point.prototype.getY=function getY(){this.normalize();return this.y.fromRed()};Point.prototype.eq=function eq(other){return this===other||this.getX().cmp(other.getX())===0&&this.getY().cmp(other.getY())===0};Point.prototype.eqXToP=function eqXToP(x){var rx=x.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(rx)===0)return true;var xc=x.clone();var t=this.curve.redN.redMul(this.z);for(;;){xc.iadd(this.curve.n);if(xc.cmp(this.curve.p)>=0)return false;rx.redIAdd(t);if(this.x.cmp(rx)===0)return true}};Point.prototype.toP=Point.prototype.normalize;Point.prototype.mixedAdd=Point.prototype.add},{"../utils":209,"./base":196,"bn.js":210,inherits:244}],198:[function(require,module,exports){arguments[4][74][0].apply(exports,arguments)},{"./base":196,"./edwards":197,"./mont":199,"./short":200,dup:74}],199:[function(require,module,exports){arguments[4][75][0].apply(exports,arguments)},{"../utils":209,"./base":196,"bn.js":210,dup:75,inherits:244}],200:[function(require,module,exports){"use strict";var utils=require("../utils");var BN=require("bn.js");var inherits=require("inherits");var Base=require("./base");var assert=utils.assert;function ShortCurve(conf){Base.call(this,"short",conf);this.a=new BN(conf.a,16).toRed(this.red);this.b=new BN(conf.b,16).toRed(this.red);this.tinv=this.two.redInvm();this.zeroA=this.a.fromRed().cmpn(0)===0;this.threeA=this.a.fromRed().sub(this.p).cmpn(-3)===0;this.endo=this._getEndomorphism(conf);this._endoWnafT1=new Array(4);this._endoWnafT2=new Array(4)}inherits(ShortCurve,Base);module.exports=ShortCurve;ShortCurve.prototype._getEndomorphism=function _getEndomorphism(conf){if(!this.zeroA||!this.g||!this.n||this.p.modn(3)!==1)return;var beta;var lambda;if(conf.beta){beta=new BN(conf.beta,16).toRed(this.red)}else{var betas=this._getEndoRoots(this.p);beta=betas[0].cmp(betas[1])<0?betas[0]:betas[1];beta=beta.toRed(this.red)}if(conf.lambda){lambda=new BN(conf.lambda,16)}else{var lambdas=this._getEndoRoots(this.n);if(this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta))===0){lambda=lambdas[0]}else{lambda=lambdas[1];assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta))===0)}}var basis;if(conf.basis){basis=conf.basis.map(function(vec){return{a:new BN(vec.a,16),b:new BN(vec.b,16)}})}else{basis=this._getEndoBasis(lambda)}return{beta:beta,lambda:lambda,basis:basis}};ShortCurve.prototype._getEndoRoots=function _getEndoRoots(num){var red=num===this.p?this.red:BN.mont(num);var tinv=new BN(2).toRed(red).redInvm();var ntinv=tinv.redNeg();var s=new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv);var l1=ntinv.redAdd(s).fromRed();var l2=ntinv.redSub(s).fromRed();return[l1,l2]};ShortCurve.prototype._getEndoBasis=function _getEndoBasis(lambda){var aprxSqrt=this.n.ushrn(Math.floor(this.n.bitLength()/2));var u=lambda;var v=this.n.clone();var x1=new BN(1);var y1=new BN(0);var x2=new BN(0);var y2=new BN(1);var a0;var b0;var a1;var b1;var a2;var b2;var prevR;var i=0;var r;var x;while(u.cmpn(0)!==0){var q=v.div(u);r=v.sub(q.mul(u));x=x2.sub(q.mul(x1));var y=y2.sub(q.mul(y1));if(!a1&&r.cmp(aprxSqrt)<0){a0=prevR.neg();b0=x1;a1=r.neg();b1=x}else if(a1&&++i===2){break}prevR=r;v=u;u=r;x2=x1;x1=x;y2=y1;y1=y}a2=r.neg();b2=x;var len1=a1.sqr().add(b1.sqr());var len2=a2.sqr().add(b2.sqr());if(len2.cmp(len1)>=0){a2=a0;b2=b0}if(a1.negative){a1=a1.neg();b1=b1.neg()}if(a2.negative){a2=a2.neg();b2=b2.neg()}return[{a:a1,b:b1},{a:a2,b:b2}]};ShortCurve.prototype._endoSplit=function _endoSplit(k){var basis=this.endo.basis;var v1=basis[0];var v2=basis[1];var c1=v2.b.mul(k).divRound(this.n);var c2=v1.b.neg().mul(k).divRound(this.n);var p1=c1.mul(v1.a);var p2=c2.mul(v2.a);var q1=c1.mul(v1.b);var q2=c2.mul(v2.b);var k1=k.sub(p1).sub(p2);var k2=q1.add(q2).neg();return{k1:k1,k2:k2}};ShortCurve.prototype.pointFromX=function pointFromX(x,odd){x=new BN(x,16);if(!x.red)x=x.toRed(this.red);var y2=x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b);var y=y2.redSqrt();if(y.redSqr().redSub(y2).cmp(this.zero)!==0)throw new Error("invalid point");var isOdd=y.fromRed().isOdd();if(odd&&!isOdd||!odd&&isOdd)y=y.redNeg();return this.point(x,y)};ShortCurve.prototype.validate=function validate(point){if(point.inf)return true;var x=point.x;var y=point.y;var ax=this.a.redMul(x);var rhs=x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b);return y.redSqr().redISub(rhs).cmpn(0)===0};ShortCurve.prototype._endoWnafMulAdd=function _endoWnafMulAdd(points,coeffs,jacobianResult){var npoints=this._endoWnafT1;var ncoeffs=this._endoWnafT2;for(var i=0;i";return""};Point.prototype.isInfinity=function isInfinity(){return this.inf};Point.prototype.add=function add(p){if(this.inf)return p;if(p.inf)return this;if(this.eq(p))return this.dbl();if(this.neg().eq(p))return this.curve.point(null,null);if(this.x.cmp(p.x)===0)return this.curve.point(null,null);var c=this.y.redSub(p.y);if(c.cmpn(0)!==0)c=c.redMul(this.x.redSub(p.x).redInvm());var nx=c.redSqr().redISub(this.x).redISub(p.x);var ny=c.redMul(this.x.redSub(nx)).redISub(this.y);return this.curve.point(nx,ny)};Point.prototype.dbl=function dbl(){if(this.inf)return this;var ys1=this.y.redAdd(this.y);if(ys1.cmpn(0)===0)return this.curve.point(null,null);var a=this.curve.a;var x2=this.x.redSqr();var dyinv=ys1.redInvm();var c=x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv);var nx=c.redSqr().redISub(this.x.redAdd(this.x));var ny=c.redMul(this.x.redSub(nx)).redISub(this.y);return this.curve.point(nx,ny)};Point.prototype.getX=function getX(){return this.x.fromRed()};Point.prototype.getY=function getY(){return this.y.fromRed()};Point.prototype.mul=function mul(k){k=new BN(k,16);if(this.isInfinity())return this;else if(this._hasDoubles(k))return this.curve._fixedNafMul(this,k);else if(this.curve.endo)return this.curve._endoWnafMulAdd([this],[k]);else return this.curve._wnafMul(this,k)};Point.prototype.mulAdd=function mulAdd(k1,p2,k2){var points=[this,p2];var coeffs=[k1,k2];if(this.curve.endo)return this.curve._endoWnafMulAdd(points,coeffs);else return this.curve._wnafMulAdd(1,points,coeffs,2)};Point.prototype.jmulAdd=function jmulAdd(k1,p2,k2){var points=[this,p2];var coeffs=[k1,k2];if(this.curve.endo)return this.curve._endoWnafMulAdd(points,coeffs,true);else return this.curve._wnafMulAdd(1,points,coeffs,2,true)};Point.prototype.eq=function eq(p){return this===p||this.inf===p.inf&&(this.inf||this.x.cmp(p.x)===0&&this.y.cmp(p.y)===0)};Point.prototype.neg=function neg(_precompute){if(this.inf)return this;var res=this.curve.point(this.x,this.y.redNeg());if(_precompute&&this.precomputed){var pre=this.precomputed;var negate=function(p){return p.neg()};res.precomputed={naf:pre.naf&&{wnd:pre.naf.wnd,points:pre.naf.points.map(negate)},doubles:pre.doubles&&{step:pre.doubles.step,points:pre.doubles.points.map(negate)}}}return res};Point.prototype.toJ=function toJ(){if(this.inf)return this.curve.jpoint(null,null,null);var res=this.curve.jpoint(this.x,this.y,this.curve.one);return res};function JPoint(curve,x,y,z){Base.BasePoint.call(this,curve,"jacobian");if(x===null&&y===null&&z===null){this.x=this.curve.one;this.y=this.curve.one;this.z=new BN(0)}else{this.x=new BN(x,16);this.y=new BN(y,16);this.z=new BN(z,16)}if(!this.x.red)this.x=this.x.toRed(this.curve.red);if(!this.y.red)this.y=this.y.toRed(this.curve.red);if(!this.z.red)this.z=this.z.toRed(this.curve.red);this.zOne=this.z===this.curve.one}inherits(JPoint,Base.BasePoint);ShortCurve.prototype.jpoint=function jpoint(x,y,z){return new JPoint(this,x,y,z)};JPoint.prototype.toP=function toP(){if(this.isInfinity())return this.curve.point(null,null);var zinv=this.z.redInvm();var zinv2=zinv.redSqr();var ax=this.x.redMul(zinv2);var ay=this.y.redMul(zinv2).redMul(zinv);return this.curve.point(ax,ay)};JPoint.prototype.neg=function neg(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)};JPoint.prototype.add=function add(p){if(this.isInfinity())return p;if(p.isInfinity())return this;var pz2=p.z.redSqr();var z2=this.z.redSqr();var u1=this.x.redMul(pz2);var u2=p.x.redMul(z2);var s1=this.y.redMul(pz2.redMul(p.z));var s2=p.y.redMul(z2.redMul(this.z));var h=u1.redSub(u2);var r=s1.redSub(s2);if(h.cmpn(0)===0){if(r.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl()}var h2=h.redSqr();var h3=h2.redMul(h);var v=u1.redMul(h2);var nx=r.redSqr().redIAdd(h3).redISub(v).redISub(v);var ny=r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));var nz=this.z.redMul(p.z).redMul(h);return this.curve.jpoint(nx,ny,nz)};JPoint.prototype.mixedAdd=function mixedAdd(p){if(this.isInfinity())return p.toJ();if(p.isInfinity())return this;var z2=this.z.redSqr();var u1=this.x;var u2=p.x.redMul(z2);var s1=this.y;var s2=p.y.redMul(z2).redMul(this.z);var h=u1.redSub(u2);var r=s1.redSub(s2);if(h.cmpn(0)===0){if(r.cmpn(0)!==0)return this.curve.jpoint(null,null,null);else return this.dbl()}var h2=h.redSqr();var h3=h2.redMul(h);var v=u1.redMul(h2);var nx=r.redSqr().redIAdd(h3).redISub(v).redISub(v);var ny=r.redMul(v.redISub(nx)).redISub(s1.redMul(h3));var nz=this.z.redMul(h);return this.curve.jpoint(nx,ny,nz)};JPoint.prototype.dblp=function dblp(pow){if(pow===0)return this;if(this.isInfinity())return this;if(!pow)return this.dbl();var i;if(this.curve.zeroA||this.curve.threeA){var r=this;for(i=0;i=0)return false;rx.redIAdd(t);if(this.x.cmp(rx)===0)return true}};JPoint.prototype.inspect=function inspect(){if(this.isInfinity())return"";return""};JPoint.prototype.isInfinity=function isInfinity(){return this.z.cmpn(0)===0}},{"../utils":209,"./base":196,"bn.js":210,inherits:244}],201:[function(require,module,exports){"use strict";var curves=exports;var hash=require("hash.js");var curve=require("./curve");var utils=require("./utils");var assert=utils.assert;function PresetCurve(options){if(options.type==="short")this.curve=new curve.short(options);else if(options.type==="edwards")this.curve=new curve.edwards(options);else this.curve=new curve.mont(options);this.g=this.curve.g;this.n=this.curve.n;this.hash=options.hash;assert(this.g.validate(),"Invalid curve");assert(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}curves.PresetCurve=PresetCurve;function defineCurve(name,options){Object.defineProperty(curves,name,{configurable:true,enumerable:true,get:function(){var curve=new PresetCurve(options);Object.defineProperty(curves,name,{configurable:true,enumerable:true,value:curve});return curve}})}defineCurve("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:hash.sha256,gRed:false,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]});defineCurve("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:hash.sha256,gRed:false,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]});defineCurve("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:hash.sha256,gRed:false,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]});defineCurve("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f "+"5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 "+"f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:hash.sha384,gRed:false,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 "+"5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 "+"0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]});defineCurve("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b "+"99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd "+"3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff "+"ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 "+"f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:hash.sha512,gRed:false,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 "+"053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 "+"a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 "+"579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 "+"3fad0761 353c7086 a272c240 88be9476 9fd16650"]});defineCurve("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:hash.sha256,gRed:false,g:["9"]});defineCurve("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:hash.sha256,gRed:false,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var pre;try{pre=require("./precomputed/secp256k1")}catch(e){pre=undefined}defineCurve("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:hash.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:false,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",pre]})},{"./curve":198,"./precomputed/secp256k1":208,"./utils":209,"hash.js":230}],202:[function(require,module,exports){"use strict";var BN=require("bn.js");var HmacDRBG=require("hmac-drbg");var utils=require("../utils");var curves=require("../curves");var rand=require("brorand");var assert=utils.assert;var KeyPair=require("./key");var Signature=require("./signature");function EC(options){if(!(this instanceof EC))return new EC(options);if(typeof options==="string"){assert(Object.prototype.hasOwnProperty.call(curves,options),"Unknown curve "+options);options=curves[options]}if(options instanceof curves.PresetCurve)options={curve:options};this.curve=options.curve.curve;this.n=this.curve.n;this.nh=this.n.ushrn(1);this.g=this.curve.g;this.g=options.curve.g;this.g.precompute(options.curve.n.bitLength()+1);this.hash=options.hash||options.curve.hash}module.exports=EC;EC.prototype.keyPair=function keyPair(options){return new KeyPair(this,options)};EC.prototype.keyFromPrivate=function keyFromPrivate(priv,enc){return KeyPair.fromPrivate(this,priv,enc)};EC.prototype.keyFromPublic=function keyFromPublic(pub,enc){return KeyPair.fromPublic(this,pub,enc)};EC.prototype.genKeyPair=function genKeyPair(options){if(!options)options={};var drbg=new HmacDRBG({hash:this.hash,pers:options.pers,persEnc:options.persEnc||"utf8",entropy:options.entropy||rand(this.hash.hmacStrength),entropyEnc:options.entropy&&options.entropyEnc||"utf8",nonce:this.n.toArray()});var bytes=this.n.byteLength();var ns2=this.n.sub(new BN(2));for(;;){var priv=new BN(drbg.generate(bytes));if(priv.cmp(ns2)>0)continue;priv.iaddn(1);return this.keyFromPrivate(priv)}};EC.prototype._truncateToN=function _truncateToN(msg,truncOnly){var delta=msg.byteLength()*8-this.n.bitLength();if(delta>0)msg=msg.ushrn(delta);if(!truncOnly&&msg.cmp(this.n)>=0)return msg.sub(this.n);else return msg};EC.prototype.sign=function sign(msg,key,enc,options){if(typeof enc==="object"){options=enc;enc=null}if(!options)options={};key=this.keyFromPrivate(key,enc);msg=this._truncateToN(new BN(msg,16));var bytes=this.n.byteLength();var bkey=key.getPrivate().toArray("be",bytes);var nonce=msg.toArray("be",bytes);var drbg=new HmacDRBG({hash:this.hash,entropy:bkey,nonce:nonce,pers:options.pers,persEnc:options.persEnc||"utf8"});var ns1=this.n.sub(new BN(1));for(var iter=0;;iter++){var k=options.k?options.k(iter):new BN(drbg.generate(this.n.byteLength()));k=this._truncateToN(k,true);if(k.cmpn(1)<=0||k.cmp(ns1)>=0)continue;var kp=this.g.mul(k);if(kp.isInfinity())continue;var kpX=kp.getX();var r=kpX.umod(this.n);if(r.cmpn(0)===0)continue;var s=k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg));s=s.umod(this.n);if(s.cmpn(0)===0)continue;var recoveryParam=(kp.getY().isOdd()?1:0)|(kpX.cmp(r)!==0?2:0);if(options.canonical&&s.cmp(this.nh)>0){s=this.n.sub(s);recoveryParam^=1}return new Signature({r:r,s:s,recoveryParam:recoveryParam})}};EC.prototype.verify=function verify(msg,signature,key,enc){msg=this._truncateToN(new BN(msg,16));key=this.keyFromPublic(key,enc);signature=new Signature(signature,"hex");var r=signature.r;var s=signature.s;if(r.cmpn(1)<0||r.cmp(this.n)>=0)return false;if(s.cmpn(1)<0||s.cmp(this.n)>=0)return false;var sinv=s.invm(this.n);var u1=sinv.mul(msg).umod(this.n);var u2=sinv.mul(r).umod(this.n);var p;if(!this.curve._maxwellTrick){p=this.g.mulAdd(u1,key.getPublic(),u2);if(p.isInfinity())return false;return p.getX().umod(this.n).cmp(r)===0}p=this.g.jmulAdd(u1,key.getPublic(),u2);if(p.isInfinity())return false;return p.eqXToP(r)};EC.prototype.recoverPubKey=function(msg,signature,j,enc){assert((3&j)===j,"The recovery param is more than two bits");signature=new Signature(signature,enc);var n=this.n;var e=new BN(msg);var r=signature.r;var s=signature.s;var isYOdd=j&1;var isSecondKey=j>>1;if(r.cmp(this.curve.p.umod(this.curve.n))>=0&&isSecondKey)throw new Error("Unable to find sencond key candinate");if(isSecondKey)r=this.curve.pointFromX(r.add(this.curve.n),isYOdd);else r=this.curve.pointFromX(r,isYOdd);var rInv=signature.r.invm(n);var s1=n.sub(e).mul(rInv).umod(n);var s2=s.mul(rInv).umod(n);return this.g.mulAdd(s1,r,s2)};EC.prototype.getKeyRecoveryParam=function(e,signature,Q,enc){signature=new Signature(signature,enc);if(signature.recoveryParam!==null)return signature.recoveryParam;for(var i=0;i<4;i++){var Qprime;try{Qprime=this.recoverPubKey(e,signature,i)}catch(e){continue}if(Qprime.eq(Q))return i}throw new Error("Unable to find valid recovery factor")}},{"../curves":201,"../utils":209,"./key":203,"./signature":204,"bn.js":210,brorand:130,"hmac-drbg":242}],203:[function(require,module,exports){"use strict";var BN=require("bn.js");var utils=require("../utils");var assert=utils.assert;function KeyPair(ec,options){this.ec=ec;this.priv=null;this.pub=null;if(options.priv)this._importPrivate(options.priv,options.privEnc);if(options.pub)this._importPublic(options.pub,options.pubEnc)}module.exports=KeyPair;KeyPair.fromPublic=function fromPublic(ec,pub,enc){if(pub instanceof KeyPair)return pub;return new KeyPair(ec,{pub:pub,pubEnc:enc})};KeyPair.fromPrivate=function fromPrivate(ec,priv,enc){if(priv instanceof KeyPair)return priv;return new KeyPair(ec,{priv:priv,privEnc:enc})};KeyPair.prototype.validate=function validate(){var pub=this.getPublic();if(pub.isInfinity())return{result:false,reason:"Invalid public key"};if(!pub.validate())return{result:false,reason:"Public key is not a point"};if(!pub.mul(this.ec.curve.n).isInfinity())return{result:false,reason:"Public key * N != O"};return{result:true,reason:null}};KeyPair.prototype.getPublic=function getPublic(compact,enc){if(typeof compact==="string"){enc=compact;compact=null}if(!this.pub)this.pub=this.ec.g.mul(this.priv);if(!enc)return this.pub;return this.pub.encode(enc,compact)};KeyPair.prototype.getPrivate=function getPrivate(enc){if(enc==="hex")return this.priv.toString(16,2);else return this.priv};KeyPair.prototype._importPrivate=function _importPrivate(key,enc){this.priv=new BN(key,enc||16);this.priv=this.priv.umod(this.ec.curve.n)};KeyPair.prototype._importPublic=function _importPublic(key,enc){if(key.x||key.y){if(this.ec.curve.type==="mont"){assert(key.x,"Need x coordinate")}else if(this.ec.curve.type==="short"||this.ec.curve.type==="edwards"){assert(key.x&&key.y,"Need both x and y coordinate")}this.pub=this.ec.curve.point(key.x,key.y);return}this.pub=this.ec.curve.decodePoint(key,enc)};KeyPair.prototype.derive=function derive(pub){if(!pub.validate()){assert(pub.validate(),"public point not validated")}return pub.mul(this.priv).getX()};KeyPair.prototype.sign=function sign(msg,enc,options){return this.ec.sign(msg,this,enc,options)};KeyPair.prototype.verify=function verify(msg,signature){return this.ec.verify(msg,signature,this)};KeyPair.prototype.inspect=function inspect(){return""}},{"../utils":209,"bn.js":210}],204:[function(require,module,exports){arguments[4][80][0].apply(exports,arguments)},{"../utils":209,"bn.js":210,dup:80}],205:[function(require,module,exports){"use strict";var hash=require("hash.js");var curves=require("../curves");var utils=require("../utils");var assert=utils.assert;var parseBytes=utils.parseBytes;var KeyPair=require("./key");var Signature=require("./signature");function EDDSA(curve){assert(curve==="ed25519","only tested with ed25519 so far");if(!(this instanceof EDDSA))return new EDDSA(curve);curve=curves[curve].curve;this.curve=curve;this.g=curve.g;this.g.precompute(curve.n.bitLength()+1);this.pointClass=curve.point().constructor;this.encodingLength=Math.ceil(curve.n.bitLength()/8);this.hash=hash.sha512}module.exports=EDDSA;EDDSA.prototype.sign=function sign(message,secret){message=parseBytes(message);var key=this.keyFromSecret(secret);var r=this.hashInt(key.messagePrefix(),message);var R=this.g.mul(r);var Rencoded=this.encodePoint(R);var s_=this.hashInt(Rencoded,key.pubBytes(),message).mul(key.priv());var S=r.add(s_).umod(this.curve.n);return this.makeSignature({R:R,S:S,Rencoded:Rencoded})};EDDSA.prototype.verify=function verify(message,sig,pub){message=parseBytes(message);sig=this.makeSignature(sig);var key=this.keyFromPublic(pub);var h=this.hashInt(sig.Rencoded(),key.pubBytes(),message);var SG=this.g.mul(sig.S());var RplusAh=sig.R().add(key.pub().mul(h));return RplusAh.eq(SG)};EDDSA.prototype.hashInt=function hashInt(){var hash=this.hash();for(var i=0;i(ws>>1)-1)z=(ws>>1)-mod;else z=mod;k.isubn(z)}else{z=0}naf[i]=z;k.iushrn(1)}return naf}utils.getNAF=getNAF;function getJSF(k1,k2){var jsf=[[],[]];k1=k1.clone();k2=k2.clone();var d1=0;var d2=0;var m8;while(k1.cmpn(-d1)>0||k2.cmpn(-d2)>0){var m14=k1.andln(3)+d1&3;var m24=k2.andln(3)+d2&3;if(m14===3)m14=-1;if(m24===3)m24=-1;var u1;if((m14&1)===0){u1=0}else{m8=k1.andln(7)+d1&7;if((m8===3||m8===5)&&m24===2)u1=-m14;else u1=m14}jsf[0].push(u1);var u2;if((m24&1)===0){u2=0}else{m8=k2.andln(7)+d2&7;if((m8===3||m8===5)&&m14===2)u2=-m24;else u2=m24}jsf[1].push(u2);if(2*d1===u1+1)d1=1-d1;if(2*d2===u2+1)d2=1-d2;k1.iushrn(1);k2.iushrn(1)}return jsf}utils.getJSF=getJSF;function cachedProperty(obj,name,computer){var key="_"+name;obj.prototype[name]=function cachedProperty(){return this[key]!==undefined?this[key]:this[key]=computer.call(this)}}utils.cachedProperty=cachedProperty;function parseBytes(bytes){return typeof bytes==="string"?utils.toArray(bytes,"hex"):bytes}utils.parseBytes=parseBytes;function intFromLE(bytes){return new BN(bytes,"hex","le")}utils.intFromLE=intFromLE},{"bn.js":210,"minimalistic-assert":248,"minimalistic-crypto-utils":249}],210:[function(require,module,exports){arguments[4][123][0].apply(exports,arguments)},{buffer:131,dup:123}],211:[function(require,module,exports){module.exports={name:"elliptic",version:"6.5.4",description:"EC cryptography",main:"lib/elliptic.js",files:["lib"],scripts:{lint:"eslint lib test","lint:fix":"npm run lint -- --fix",unit:"istanbul test _mocha --reporter=spec test/index.js",test:"npm run lint && npm run unit",version:"grunt dist && git add dist/"},repository:{type:"git",url:"git@github.com:indutny/elliptic"},keywords:["EC","Elliptic","curve","Cryptography"],author:"Fedor Indutny ",license:"MIT",bugs:{url:"https://github.com/indutny/elliptic/issues"},homepage:"https://github.com/indutny/elliptic",devDependencies:{brfs:"^2.0.2",coveralls:"^3.1.0",eslint:"^7.6.0",grunt:"^1.2.1","grunt-browserify":"^5.3.0","grunt-cli":"^1.3.2","grunt-contrib-connect":"^3.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^5.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-saucelabs":"^9.0.1",istanbul:"^0.4.5",mocha:"^8.0.1"},dependencies:{"bn.js":"^4.11.9",brorand:"^1.1.0","hash.js":"^1.0.0","hmac-drbg":"^1.0.1",inherits:"^2.0.4","minimalistic-assert":"^1.0.1","minimalistic-crypto-utils":"^1.0.1"}}},{}],212:[function(require,module,exports){"use strict";var R=typeof Reflect==="object"?Reflect:null;var ReflectApply=R&&typeof R.apply==="function"?R.apply:function ReflectApply(target,receiver,args){return Function.prototype.apply.call(target,receiver,args)};var ReflectOwnKeys;if(R&&typeof R.ownKeys==="function"){ReflectOwnKeys=R.ownKeys}else if(Object.getOwnPropertySymbols){ReflectOwnKeys=function ReflectOwnKeys(target){return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target))}}else{ReflectOwnKeys=function ReflectOwnKeys(target){return Object.getOwnPropertyNames(target)}}function ProcessEmitWarning(warning){if(console&&console.warn)console.warn(warning)}var NumberIsNaN=Number.isNaN||function NumberIsNaN(value){return value!==value};function EventEmitter(){EventEmitter.init.call(this)}module.exports=EventEmitter;module.exports.once=once;EventEmitter.EventEmitter=EventEmitter;EventEmitter.prototype._events=undefined;EventEmitter.prototype._eventsCount=0;EventEmitter.prototype._maxListeners=undefined;var defaultMaxListeners=10;function checkListener(listener){if(typeof listener!=="function"){throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof listener)}}Object.defineProperty(EventEmitter,"defaultMaxListeners",{enumerable:true,get:function(){return defaultMaxListeners},set:function(arg){if(typeof arg!=="number"||arg<0||NumberIsNaN(arg)){throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+arg+".")}defaultMaxListeners=arg}});EventEmitter.init=function(){if(this._events===undefined||this._events===Object.getPrototypeOf(this)._events){this._events=Object.create(null);this._eventsCount=0}this._maxListeners=this._maxListeners||undefined};EventEmitter.prototype.setMaxListeners=function setMaxListeners(n){if(typeof n!=="number"||n<0||NumberIsNaN(n)){throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+n+".")}this._maxListeners=n;return this};function _getMaxListeners(that){if(that._maxListeners===undefined)return EventEmitter.defaultMaxListeners;return that._maxListeners}EventEmitter.prototype.getMaxListeners=function getMaxListeners(){return _getMaxListeners(this)};EventEmitter.prototype.emit=function emit(type){var args=[];for(var i=1;i0)er=args[0];if(er instanceof Error){throw er}var err=new Error("Unhandled error."+(er?" ("+er.message+")":""));err.context=er;throw err}var handler=events[type];if(handler===undefined)return false;if(typeof handler==="function"){ReflectApply(handler,this,args)}else{var len=handler.length;var listeners=arrayClone(handler,len);for(var i=0;i0&&existing.length>m&&!existing.warned){existing.warned=true;var w=new Error("Possible EventEmitter memory leak detected. "+existing.length+" "+String(type)+" listeners "+"added. Use emitter.setMaxListeners() to "+"increase limit");w.name="MaxListenersExceededWarning";w.emitter=target;w.type=type;w.count=existing.length;ProcessEmitWarning(w)}}return target}EventEmitter.prototype.addListener=function addListener(type,listener){return _addListener(this,type,listener,false)};EventEmitter.prototype.on=EventEmitter.prototype.addListener;EventEmitter.prototype.prependListener=function prependListener(type,listener){return _addListener(this,type,listener,true)};function onceWrapper(){if(!this.fired){this.target.removeListener(this.type,this.wrapFn);this.fired=true;if(arguments.length===0)return this.listener.call(this.target);return this.listener.apply(this.target,arguments)}}function _onceWrap(target,type,listener){var state={fired:false,wrapFn:undefined,target:target,type:type,listener:listener};var wrapped=onceWrapper.bind(state);wrapped.listener=listener;state.wrapFn=wrapped;return wrapped}EventEmitter.prototype.once=function once(type,listener){checkListener(listener);this.on(type,_onceWrap(this,type,listener));return this};EventEmitter.prototype.prependOnceListener=function prependOnceListener(type,listener){checkListener(listener);this.prependListener(type,_onceWrap(this,type,listener));return this};EventEmitter.prototype.removeListener=function removeListener(type,listener){var list,events,position,i,originalListener;checkListener(listener);events=this._events;if(events===undefined)return this;list=events[type];if(list===undefined)return this;if(list===listener||list.listener===listener){if(--this._eventsCount===0)this._events=Object.create(null);else{delete events[type];if(events.removeListener)this.emit("removeListener",type,list.listener||listener)}}else if(typeof list!=="function"){position=-1;for(i=list.length-1;i>=0;i--){if(list[i]===listener||list[i].listener===listener){originalListener=list[i].listener;position=i;break}}if(position<0)return this;if(position===0)list.shift();else{spliceOne(list,position)}if(list.length===1)events[type]=list[0];if(events.removeListener!==undefined)this.emit("removeListener",type,originalListener||listener)}return this};EventEmitter.prototype.off=EventEmitter.prototype.removeListener;EventEmitter.prototype.removeAllListeners=function removeAllListeners(type){var listeners,events,i;events=this._events;if(events===undefined)return this;if(events.removeListener===undefined){if(arguments.length===0){this._events=Object.create(null);this._eventsCount=0}else if(events[type]!==undefined){if(--this._eventsCount===0)this._events=Object.create(null);else delete events[type]}return this}if(arguments.length===0){var keys=Object.keys(events);var key;for(i=0;i=0;i--){this.removeListener(type,listeners[i])}}return this};function _listeners(target,type,unwrap){var events=target._events;if(events===undefined)return[];var evlistener=events[type];if(evlistener===undefined)return[];if(typeof evlistener==="function")return unwrap?[evlistener.listener||evlistener]:[evlistener];return unwrap?unwrapListeners(evlistener):arrayClone(evlistener,evlistener.length)}EventEmitter.prototype.listeners=function listeners(type){return _listeners(this,type,true)};EventEmitter.prototype.rawListeners=function rawListeners(type){return _listeners(this,type,false)};EventEmitter.listenerCount=function(emitter,type){if(typeof emitter.listenerCount==="function"){return emitter.listenerCount(type)}else{return listenerCount.call(emitter,type)}};EventEmitter.prototype.listenerCount=listenerCount;function listenerCount(type){var events=this._events;if(events!==undefined){var evlistener=events[type];if(typeof evlistener==="function"){return 1}else if(evlistener!==undefined){return evlistener.length}}return 0}EventEmitter.prototype.eventNames=function eventNames(){return this._eventsCount>0?ReflectOwnKeys(this._events):[]};function arrayClone(arr,n){var copy=new Array(n);for(var i=0;i0||ivLen>0){var hash=new MD5;hash.update(tmp);hash.update(password);if(salt)hash.update(salt);tmp=hash.digest();var used=0;if(keyLen>0){var keyStart=key.length-keyLen;used=Math.min(keyLen,tmp.length);tmp.copy(key,keyStart,0,used);keyLen-=used}if(used0){var ivStart=iv.length-ivLen;var length=Math.min(ivLen,tmp.length-used);tmp.copy(iv,ivStart,used,used+length);ivLen-=length}}tmp.fill(0);return{key:key,iv:iv}}module.exports=EVP_BytesToKey},{"md5.js":245,"safe-buffer":277}],214:[function(require,module,exports){"use strict";var Buffer=require("safe-buffer").Buffer;var Transform=require("readable-stream").Transform;var inherits=require("inherits");function throwIfNotStringOrBuffer(val,prefix){if(!Buffer.isBuffer(val)&&typeof val!=="string"){throw new TypeError(prefix+" must be a string or a buffer")}}function HashBase(blockSize){Transform.call(this);this._block=Buffer.allocUnsafe(blockSize);this._blockSize=blockSize;this._blockOffset=0;this._length=[0,0,0,0];this._finalized=false}inherits(HashBase,Transform);HashBase.prototype._transform=function(chunk,encoding,callback){var error=null;try{this.update(chunk,encoding)}catch(err){error=err}callback(error)};HashBase.prototype._flush=function(callback){var error=null;try{this.push(this.digest())}catch(err){error=err}callback(error)};HashBase.prototype.update=function(data,encoding){throwIfNotStringOrBuffer(data,"Data");if(this._finalized)throw new Error("Digest already called");if(!Buffer.isBuffer(data))data=Buffer.from(data,encoding);var block=this._block;var offset=0;while(this._blockOffset+data.length-offset>=this._blockSize){for(var i=this._blockOffset;i0;++j){this._length[j]+=carry;carry=this._length[j]/4294967296|0;if(carry>0)this._length[j]-=4294967296*carry}return this};HashBase.prototype._update=function(){throw new Error("_update is not implemented")};HashBase.prototype.digest=function(encoding){if(this._finalized)throw new Error("Digest already called");this._finalized=true;var digest=this._digest();if(encoding!==undefined)digest=digest.toString(encoding);this._block.fill(0);this._blockOffset=0;for(var i=0;i<4;++i)this._length[i]=0;return digest};HashBase.prototype._digest=function(){throw new Error("_digest is not implemented")};module.exports=HashBase},{inherits:244,"readable-stream":229,"safe-buffer":277}],215:[function(require,module,exports){arguments[4][159][0].apply(exports,arguments)},{dup:159}],216:[function(require,module,exports){arguments[4][160][0].apply(exports,arguments)},{"./_stream_readable":218,"./_stream_writable":220,_process:262,dup:160,inherits:244}],217:[function(require,module,exports){arguments[4][161][0].apply(exports,arguments)},{"./_stream_transform":219,dup:161,inherits:244}],218:[function(require,module,exports){arguments[4][162][0].apply(exports,arguments)},{"../errors":215,"./_stream_duplex":216,"./internal/streams/async_iterator":221,"./internal/streams/buffer_list":222,"./internal/streams/destroy":223,"./internal/streams/from":225,"./internal/streams/state":227,"./internal/streams/stream":228,_process:262,buffer:175,dup:162,events:212,inherits:244,"string_decoder/":302,util:131}],219:[function(require,module,exports){arguments[4][163][0].apply(exports,arguments)},{"../errors":215,"./_stream_duplex":216,dup:163,inherits:244}],220:[function(require,module,exports){arguments[4][164][0].apply(exports,arguments)},{"../errors":215,"./_stream_duplex":216,"./internal/streams/destroy":223,"./internal/streams/state":227,"./internal/streams/stream":228,_process:262,buffer:175,dup:164,inherits:244,"util-deprecate":305}],221:[function(require,module,exports){arguments[4][165][0].apply(exports,arguments)},{"./end-of-stream":224,_process:262,dup:165}],222:[function(require,module,exports){arguments[4][166][0].apply(exports,arguments)},{buffer:175,dup:166,util:131}],223:[function(require,module,exports){arguments[4][167][0].apply(exports,arguments)},{_process:262,dup:167}],224:[function(require,module,exports){arguments[4][168][0].apply(exports,arguments)},{"../../../errors":215,dup:168}],225:[function(require,module,exports){arguments[4][169][0].apply(exports,arguments)},{dup:169}],226:[function(require,module,exports){arguments[4][170][0].apply(exports,arguments)},{"../../../errors":215,"./end-of-stream":224,dup:170}],227:[function(require,module,exports){arguments[4][171][0].apply(exports,arguments)},{"../../../errors":215,dup:171}],228:[function(require,module,exports){arguments[4][172][0].apply(exports,arguments)},{dup:172,events:212}],229:[function(require,module,exports){arguments[4][173][0].apply(exports,arguments)},{"./lib/_stream_duplex.js":216,"./lib/_stream_passthrough.js":217,"./lib/_stream_readable.js":218,"./lib/_stream_transform.js":219,"./lib/_stream_writable.js":220,"./lib/internal/streams/end-of-stream.js":224,"./lib/internal/streams/pipeline.js":226,dup:173}],230:[function(require,module,exports){arguments[4][87][0].apply(exports,arguments)},{"./hash/common":231,"./hash/hmac":232,"./hash/ripemd":233,"./hash/sha":234,"./hash/utils":241,dup:87}],231:[function(require,module,exports){arguments[4][88][0].apply(exports,arguments)},{"./utils":241,dup:88,"minimalistic-assert":248}],232:[function(require,module,exports){arguments[4][89][0].apply(exports,arguments)},{"./utils":241,dup:89,"minimalistic-assert":248}],233:[function(require,module,exports){arguments[4][90][0].apply(exports,arguments)},{"./common":231,"./utils":241,dup:90}],234:[function(require,module,exports){arguments[4][91][0].apply(exports,arguments)},{"./sha/1":235,"./sha/224":236,"./sha/256":237,"./sha/384":238,"./sha/512":239,dup:91}],235:[function(require,module,exports){arguments[4][92][0].apply(exports,arguments)},{"../common":231,"../utils":241,"./common":240,dup:92}],236:[function(require,module,exports){arguments[4][93][0].apply(exports,arguments)},{"../utils":241,"./256":237,dup:93}],237:[function(require,module,exports){arguments[4][94][0].apply(exports,arguments)},{"../common":231,"../utils":241,"./common":240,dup:94,"minimalistic-assert":248}],238:[function(require,module,exports){arguments[4][95][0].apply(exports,arguments)},{"../utils":241,"./512":239,dup:95}],239:[function(require,module,exports){arguments[4][96][0].apply(exports,arguments)},{"../common":231,"../utils":241,dup:96,"minimalistic-assert":248}],240:[function(require,module,exports){arguments[4][97][0].apply(exports,arguments)},{"../utils":241,dup:97}],241:[function(require,module,exports){arguments[4][98][0].apply(exports,arguments)},{dup:98,inherits:244,"minimalistic-assert":248}],242:[function(require,module,exports){arguments[4][100][0].apply(exports,arguments)},{dup:100,"hash.js":230,"minimalistic-assert":248,"minimalistic-crypto-utils":249}],243:[function(require,module,exports){exports.read=function(buffer,offset,isLE,mLen,nBytes){var e,m;var eLen=nBytes*8-mLen-1;var eMax=(1<>1;var nBits=-7;var i=isLE?nBytes-1:0;var d=isLE?-1:1;var s=buffer[offset+i];i+=d;e=s&(1<<-nBits)-1;s>>=-nBits;nBits+=eLen;for(;nBits>0;e=e*256+buffer[offset+i],i+=d,nBits-=8){}m=e&(1<<-nBits)-1;e>>=-nBits;nBits+=mLen;for(;nBits>0;m=m*256+buffer[offset+i],i+=d,nBits-=8){}if(e===0){e=1-eBias}else if(e===eMax){return m?NaN:(s?-1:1)*Infinity}else{m=m+Math.pow(2,mLen);e=e-eBias}return(s?-1:1)*m*Math.pow(2,e-mLen)};exports.write=function(buffer,value,offset,isLE,mLen,nBytes){var e,m,c;var eLen=nBytes*8-mLen-1;var eMax=(1<>1;var rt=mLen===23?Math.pow(2,-24)-Math.pow(2,-77):0;var i=isLE?0:nBytes-1;var d=isLE?1:-1;var s=value<0||value===0&&1/value<0?1:0;value=Math.abs(value);if(isNaN(value)||value===Infinity){m=isNaN(value)?1:0;e=eMax}else{e=Math.floor(Math.log(value)/Math.LN2);if(value*(c=Math.pow(2,-e))<1){e--;c*=2}if(e+eBias>=1){value+=rt/c}else{value+=rt*Math.pow(2,1-eBias)}if(value*c>=2){e++;c/=2}if(e+eBias>=eMax){m=0;e=eMax}else if(e+eBias>=1){m=(value*c-1)*Math.pow(2,mLen);e=e+eBias}else{m=value*Math.pow(2,eBias-1)*Math.pow(2,mLen);e=0}}for(;mLen>=8;buffer[offset+i]=m&255,i+=d,m/=256,mLen-=8){}e=e<0;buffer[offset+i]=e&255,i+=d,e/=256,eLen-=8){}buffer[offset+i-d]|=s*128}},{}],244:[function(require,module,exports){arguments[4][99][0].apply(exports,arguments)},{dup:99}],245:[function(require,module,exports){"use strict";var inherits=require("inherits");var HashBase=require("hash-base");var Buffer=require("safe-buffer").Buffer;var ARRAY16=new Array(16);function MD5(){HashBase.call(this,64);this._a=1732584193;this._b=4023233417;this._c=2562383102;this._d=271733878}inherits(MD5,HashBase);MD5.prototype._update=function(){var M=ARRAY16;for(var i=0;i<16;++i)M[i]=this._block.readInt32LE(i*4);var a=this._a;var b=this._b;var c=this._c;var d=this._d;a=fnF(a,b,c,d,M[0],3614090360,7);d=fnF(d,a,b,c,M[1],3905402710,12);c=fnF(c,d,a,b,M[2],606105819,17);b=fnF(b,c,d,a,M[3],3250441966,22);a=fnF(a,b,c,d,M[4],4118548399,7);d=fnF(d,a,b,c,M[5],1200080426,12);c=fnF(c,d,a,b,M[6],2821735955,17);b=fnF(b,c,d,a,M[7],4249261313,22);a=fnF(a,b,c,d,M[8],1770035416,7);d=fnF(d,a,b,c,M[9],2336552879,12);c=fnF(c,d,a,b,M[10],4294925233,17);b=fnF(b,c,d,a,M[11],2304563134,22);a=fnF(a,b,c,d,M[12],1804603682,7);d=fnF(d,a,b,c,M[13],4254626195,12);c=fnF(c,d,a,b,M[14],2792965006,17);b=fnF(b,c,d,a,M[15],1236535329,22);a=fnG(a,b,c,d,M[1],4129170786,5);d=fnG(d,a,b,c,M[6],3225465664,9);c=fnG(c,d,a,b,M[11],643717713,14);b=fnG(b,c,d,a,M[0],3921069994,20);a=fnG(a,b,c,d,M[5],3593408605,5);d=fnG(d,a,b,c,M[10],38016083,9);c=fnG(c,d,a,b,M[15],3634488961,14);b=fnG(b,c,d,a,M[4],3889429448,20);a=fnG(a,b,c,d,M[9],568446438,5);d=fnG(d,a,b,c,M[14],3275163606,9);c=fnG(c,d,a,b,M[3],4107603335,14);b=fnG(b,c,d,a,M[8],1163531501,20);a=fnG(a,b,c,d,M[13],2850285829,5);d=fnG(d,a,b,c,M[2],4243563512,9);c=fnG(c,d,a,b,M[7],1735328473,14);b=fnG(b,c,d,a,M[12],2368359562,20);a=fnH(a,b,c,d,M[5],4294588738,4);d=fnH(d,a,b,c,M[8],2272392833,11);c=fnH(c,d,a,b,M[11],1839030562,16);b=fnH(b,c,d,a,M[14],4259657740,23);a=fnH(a,b,c,d,M[1],2763975236,4);d=fnH(d,a,b,c,M[4],1272893353,11);c=fnH(c,d,a,b,M[7],4139469664,16);b=fnH(b,c,d,a,M[10],3200236656,23);a=fnH(a,b,c,d,M[13],681279174,4);d=fnH(d,a,b,c,M[0],3936430074,11);c=fnH(c,d,a,b,M[3],3572445317,16);b=fnH(b,c,d,a,M[6],76029189,23);a=fnH(a,b,c,d,M[9],3654602809,4);d=fnH(d,a,b,c,M[12],3873151461,11);c=fnH(c,d,a,b,M[15],530742520,16);b=fnH(b,c,d,a,M[2],3299628645,23);a=fnI(a,b,c,d,M[0],4096336452,6);d=fnI(d,a,b,c,M[7],1126891415,10);c=fnI(c,d,a,b,M[14],2878612391,15);b=fnI(b,c,d,a,M[5],4237533241,21);a=fnI(a,b,c,d,M[12],1700485571,6);d=fnI(d,a,b,c,M[3],2399980690,10);c=fnI(c,d,a,b,M[10],4293915773,15);b=fnI(b,c,d,a,M[1],2240044497,21);a=fnI(a,b,c,d,M[8],1873313359,6);d=fnI(d,a,b,c,M[15],4264355552,10);c=fnI(c,d,a,b,M[6],2734768916,15);b=fnI(b,c,d,a,M[13],1309151649,21);a=fnI(a,b,c,d,M[4],4149444226,6);d=fnI(d,a,b,c,M[11],3174756917,10);c=fnI(c,d,a,b,M[2],718787259,15);b=fnI(b,c,d,a,M[9],3951481745,21);this._a=this._a+a|0;this._b=this._b+b|0;this._c=this._c+c|0;this._d=this._d+d|0};MD5.prototype._digest=function(){this._block[this._blockOffset++]=128;if(this._blockOffset>56){this._block.fill(0,this._blockOffset,64);this._update();this._blockOffset=0}this._block.fill(0,this._blockOffset,56);this._block.writeUInt32LE(this._length[0],56);this._block.writeUInt32LE(this._length[1],60);this._update();var buffer=Buffer.allocUnsafe(16);buffer.writeInt32LE(this._a,0);buffer.writeInt32LE(this._b,4);buffer.writeInt32LE(this._c,8);buffer.writeInt32LE(this._d,12);return buffer};function rotl(x,n){return x<>>32-n}function fnF(a,b,c,d,m,k,s){return rotl(a+(b&c|~b&d)+m+k|0,s)+b|0}function fnG(a,b,c,d,m,k,s){return rotl(a+(b&d|c&~d)+m+k|0,s)+b|0}function fnH(a,b,c,d,m,k,s){return rotl(a+(b^c^d)+m+k|0,s)+b|0}function fnI(a,b,c,d,m,k,s){return rotl(a+(c^(b|~d))+m+k|0,s)+b|0}module.exports=MD5},{"hash-base":214,inherits:244,"safe-buffer":277}],246:[function(require,module,exports){var bn=require("bn.js");var brorand=require("brorand");function MillerRabin(rand){this.rand=rand||new brorand.Rand}module.exports=MillerRabin;MillerRabin.create=function create(rand){return new MillerRabin(rand)};MillerRabin.prototype._randbelow=function _randbelow(n){var len=n.bitLength();var min_bytes=Math.ceil(len/8);do{var a=new bn(this.rand.generate(min_bytes))}while(a.cmp(n)>=0);return a};MillerRabin.prototype._randrange=function _randrange(start,stop){var size=stop.sub(start);return start.add(this._randbelow(size))};MillerRabin.prototype.test=function test(n,k,cb){var len=n.bitLength();var red=bn.mont(n);var rone=new bn(1).toRed(red);if(!k)k=Math.max(1,len/48|0);var n1=n.subn(1);for(var s=0;!n1.testn(s);s++){}var d=n.shrn(s);var rn1=n1.toRed(red);var prime=true;for(;k>0;k--){var a=this._randrange(new bn(2),n1);if(cb)cb(a);var x=a.toRed(red).redPow(d);if(x.cmp(rone)===0||x.cmp(rn1)===0)continue;for(var i=1;i0;k--){var a=this._randrange(new bn(2),n1);var g=n.gcd(a);if(g.cmpn(1)!==0)return g;var x=a.toRed(red).redPow(d);if(x.cmp(rone)===0||x.cmp(rn1)===0)continue;for(var i=1;i=6?"utf-8":"binary"}else{defaultEncoding="utf-8"}module.exports=defaultEncoding}).call(this)}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{_process:262}],259:[function(require,module,exports){var MAX_ALLOC=Math.pow(2,30)-1;module.exports=function(iterations,keylen){if(typeof iterations!=="number"){throw new TypeError("Iterations not a number")}if(iterations<0){throw new TypeError("Bad iterations")}if(typeof keylen!=="number"){throw new TypeError("Key length not a number")}if(keylen<0||keylen>MAX_ALLOC||keylen!==keylen){throw new TypeError("Bad key length")}}},{}],260:[function(require,module,exports){var md5=require("create-hash/md5");var RIPEMD160=require("ripemd160");var sha=require("sha.js");var Buffer=require("safe-buffer").Buffer;var checkParameters=require("./precondition");var defaultEncoding=require("./default-encoding");var toBuffer=require("./to-buffer");var ZEROS=Buffer.alloc(128);var sizes={md5:16,sha1:20,sha224:28,sha256:32,sha384:48,sha512:64,rmd160:20,ripemd160:20};function Hmac(alg,key,saltLen){var hash=getDigest(alg);var blocksize=alg==="sha512"||alg==="sha384"?128:64;if(key.length>blocksize){key=hash(key)}else if(key.length1){for(var i=1;ik||new BN(enc).cmp(key.modulus)>=0){throw new Error("decryption error")}var msg;if(reverse){msg=withPublic(new BN(enc),key)}else{msg=crt(enc,key)}var zBuffer=Buffer.alloc(k-msg.length);msg=Buffer.concat([zBuffer,msg],k);if(padding===4){return oaep(key,msg)}else if(padding===1){return pkcs1(key,msg,reverse)}else if(padding===3){return msg}else{throw new Error("unknown padding")}};function oaep(key,msg){var k=key.modulus.byteLength();var iHash=createHash("sha1").update(Buffer.alloc(0)).digest();var hLen=iHash.length;if(msg[0]!==0){throw new Error("decryption error")}var maskedSeed=msg.slice(1,hLen+1);var maskedDb=msg.slice(hLen+1);var seed=xor(maskedSeed,mgf(maskedDb,hLen));var db=xor(maskedDb,mgf(seed,k-hLen-1));if(compare(iHash,db.slice(0,hLen))){throw new Error("decryption error")}var i=hLen;while(db[i]===0){i++}if(db[i++]!==1){throw new Error("decryption error")}return db.slice(i)}function pkcs1(key,msg,reverse){var p1=msg.slice(0,2);var i=2;var status=0;while(msg[i++]!==0){if(i>=msg.length){status++;break}}var ps=msg.slice(2,i-1);if(p1.toString("hex")!=="0002"&&!reverse||p1.toString("hex")!=="0001"&&reverse){status++}if(ps.length<8){status++}if(status){throw new Error("decryption error")}return msg.slice(i)}function compare(a,b){a=Buffer.from(a);b=Buffer.from(b);var dif=0;var len=a.length;if(a.length!==b.length){dif++;len=Math.min(a.length,b.length)}var i=-1;while(++i=0){throw new Error("data too long for modulus")}}else{throw new Error("unknown padding")}if(reverse){return crt(paddedMsg,key)}else{return withPublic(paddedMsg,key)}};function oaep(key,msg){var k=key.modulus.byteLength();var mLen=msg.length;var iHash=createHash("sha1").update(Buffer.alloc(0)).digest();var hLen=iHash.length;var hLen2=2*hLen;if(mLen>k-hLen2-2){throw new Error("message too long")}var ps=Buffer.alloc(k-mLen-hLen2-2);var dblen=k-hLen-1;var seed=randomBytes(hLen);var maskedDb=xor(Buffer.concat([iHash,ps,Buffer.alloc(1,1),msg],dblen),mgf(seed,dblen));var maskedSeed=xor(seed,mgf(maskedDb,hLen));return new BN(Buffer.concat([Buffer.alloc(1),maskedSeed,maskedDb],k))}function pkcs1(key,msg,reverse){var mLen=msg.length;var k=key.modulus.byteLength();if(mLen>k-11){throw new Error("message too long")}var ps;if(reverse){ps=Buffer.alloc(k-mLen-3,255)}else{ps=nonZero(k-mLen-3)}return new BN(Buffer.concat([Buffer.from([0,reverse?1:2]),ps,Buffer.alloc(1),msg],k))}function nonZero(len){var out=Buffer.allocUnsafe(len);var i=0;var cache=randomBytes(len*2);var cur=0;var num;while(i= 0x80 (not a basic code point)","invalid-input":"Invalid input"},baseMinusTMin=base-tMin,floor=Math.floor,stringFromCharCode=String.fromCharCode,key;function error(type){throw new RangeError(errors[type])}function map(array,fn){var length=array.length;var result=[];while(length--){result[length]=fn(array[length])}return result}function mapDomain(string,fn){var parts=string.split("@");var result="";if(parts.length>1){result=parts[0]+"@";string=parts[1]}string=string.replace(regexSeparators,".");var labels=string.split(".");var encoded=map(labels,fn).join(".");return result+encoded}function ucs2decode(string){var output=[],counter=0,length=string.length,value,extra;while(counter=55296&&value<=56319&&counter65535){value-=65536;output+=stringFromCharCode(value>>>10&1023|55296);value=56320|value&1023}output+=stringFromCharCode(value);return output}).join("")}function basicToDigit(codePoint){if(codePoint-48<10){return codePoint-22}if(codePoint-65<26){return codePoint-65}if(codePoint-97<26){return codePoint-97}return base}function digitToBasic(digit,flag){return digit+22+75*(digit<26)-((flag!=0)<<5)}function adapt(delta,numPoints,firstTime){var k=0;delta=firstTime?floor(delta/damp):delta>>1;delta+=floor(delta/numPoints);for(;delta>baseMinusTMin*tMax>>1;k+=base){delta=floor(delta/baseMinusTMin)}return floor(k+(baseMinusTMin+1)*delta/(delta+skew))}function decode(input){var output=[],inputLength=input.length,out,i=0,n=initialN,bias=initialBias,basic,j,index,oldi,w,k,digit,t,baseMinusT;basic=input.lastIndexOf(delimiter);if(basic<0){basic=0}for(j=0;j=128){error("not-basic")}output.push(input.charCodeAt(j))}for(index=basic>0?basic+1:0;index=inputLength){error("invalid-input")}digit=basicToDigit(input.charCodeAt(index++));if(digit>=base||digit>floor((maxInt-i)/w)){error("overflow")}i+=digit*w;t=k<=bias?tMin:k>=bias+tMax?tMax:k-bias;if(digitfloor(maxInt/baseMinusT)){error("overflow")}w*=baseMinusT}out=output.length+1;bias=adapt(i-oldi,out,oldi==0);if(floor(i/out)>maxInt-n){error("overflow")}n+=floor(i/out);i%=out;output.splice(i++,0,n)}return ucs2encode(output)}function encode(input){var n,delta,handledCPCount,basicLength,bias,j,m,q,k,t,currentValue,output=[],inputLength,handledCPCountPlusOne,baseMinusT,qMinusT;input=ucs2decode(input);inputLength=input.length;n=initialN;delta=0;bias=initialBias;for(j=0;j=n&¤tValuefloor((maxInt-delta)/handledCPCountPlusOne)){error("overflow")}delta+=(m-n)*handledCPCountPlusOne;n=m;for(j=0;jmaxInt){error("overflow")}if(currentValue==n){for(q=delta,k=base;;k+=base){t=k<=bias?tMin:k>=bias+tMax?tMax:k-bias;if(q0&&len>maxKeys){len=maxKeys}for(var i=0;i=0){kstr=x.substr(0,idx);vstr=x.substr(idx+1)}else{kstr=x;vstr=""}k=decodeURIComponent(kstr);v=decodeURIComponent(vstr);if(!hasOwnProperty(obj,k)){obj[k]=v}else if(isArray(obj[k])){obj[k].push(v)}else{obj[k]=[obj[k],v]}}return obj};var isArray=Array.isArray||function(xs){return Object.prototype.toString.call(xs)==="[object Array]"}},{}],272:[function(require,module,exports){"use strict";var stringifyPrimitive=function(v){switch(typeof v){case"string":return v;case"boolean":return v?"true":"false";case"number":return isFinite(v)?v:"";default:return""}};module.exports=function(obj,sep,eq,name){sep=sep||"&";eq=eq||"=";if(obj===null){obj=undefined}if(typeof obj==="object"){return map(objectKeys(obj),function(k){var ks=encodeURIComponent(stringifyPrimitive(k))+eq;if(isArray(obj[k])){return map(obj[k],function(v){return ks+encodeURIComponent(stringifyPrimitive(v))}).join(sep)}else{return ks+encodeURIComponent(stringifyPrimitive(obj[k]))}}).join(sep)}if(!name)return"";return encodeURIComponent(stringifyPrimitive(name))+eq+encodeURIComponent(stringifyPrimitive(obj))};var isArray=Array.isArray||function(xs){return Object.prototype.toString.call(xs)==="[object Array]"};function map(xs,f){if(xs.map)return xs.map(f);var res=[];for(var i=0;ikMaxUint32||offset<0){throw new TypeError("offset must be a uint32")}if(offset>kBufferMaxLength||offset>length){throw new RangeError("offset out of range")}}function assertSize(size,offset,length){if(typeof size!=="number"||size!==size){throw new TypeError("size must be a number")}if(size>kMaxUint32||size<0){throw new TypeError("size must be a uint32")}if(size+offset>length||size>kBufferMaxLength){throw new RangeError("buffer too small")}}if(crypto&&crypto.getRandomValues||!process.browser){exports.randomFill=randomFill;exports.randomFillSync=randomFillSync}else{exports.randomFill=oldBrowser;exports.randomFillSync=oldBrowser}function randomFill(buf,offset,size,cb){if(!Buffer.isBuffer(buf)&&!(buf instanceof global.Uint8Array)){throw new TypeError('"buf" argument must be a Buffer or Uint8Array')}if(typeof offset==="function"){cb=offset;offset=0;size=buf.length}else if(typeof size==="function"){cb=size;size=buf.length-offset}else if(typeof cb!=="function"){throw new TypeError('"cb" argument must be a function')}assertOffset(offset,buf.length);assertSize(size,offset,buf.length);return actualFill(buf,offset,size,cb)}function actualFill(buf,offset,size,cb){if(process.browser){var ourBuf=buf.buffer;var uint=new Uint8Array(ourBuf,offset,size);crypto.getRandomValues(uint);if(cb){process.nextTick(function(){cb(null,buf)});return}return buf}if(cb){randombytes(size,function(err,bytes){if(err){return cb(err)}bytes.copy(buf,offset);cb(null,buf)});return}var bytes=randombytes(size);bytes.copy(buf,offset);return buf}function randomFillSync(buf,offset,size){if(typeof offset==="undefined"){offset=0}if(!Buffer.isBuffer(buf)&&!(buf instanceof global.Uint8Array)){throw new TypeError('"buf" argument must be a Buffer or Uint8Array')}assertOffset(offset,buf.length);if(size===undefined)size=buf.length-offset;assertSize(size,offset,buf.length);return actualFill(buf,offset,size)}}).call(this)}).call(this,require("_process"),typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{_process:262,randombytes:274,"safe-buffer":277}],276:[function(require,module,exports){"use strict";var Buffer=require("buffer").Buffer;var inherits=require("inherits");var HashBase=require("hash-base");var ARRAY16=new Array(16);var zl=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13];var zr=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11];var sl=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6];var sr=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11];var hl=[0,1518500249,1859775393,2400959708,2840853838];var hr=[1352829926,1548603684,1836072691,2053994217,0];function RIPEMD160(){HashBase.call(this,64);this._a=1732584193;this._b=4023233417;this._c=2562383102;this._d=271733878;this._e=3285377520}inherits(RIPEMD160,HashBase);RIPEMD160.prototype._update=function(){var words=ARRAY16;for(var j=0;j<16;++j)words[j]=this._block.readInt32LE(j*4);var al=this._a|0;var bl=this._b|0;var cl=this._c|0;var dl=this._d|0;var el=this._e|0;var ar=this._a|0;var br=this._b|0;var cr=this._c|0;var dr=this._d|0;var er=this._e|0;for(var i=0;i<80;i+=1){var tl;var tr;if(i<16){tl=fn1(al,bl,cl,dl,el,words[zl[i]],hl[0],sl[i]);tr=fn5(ar,br,cr,dr,er,words[zr[i]],hr[0],sr[i])}else if(i<32){tl=fn2(al,bl,cl,dl,el,words[zl[i]],hl[1],sl[i]);tr=fn4(ar,br,cr,dr,er,words[zr[i]],hr[1],sr[i])}else if(i<48){tl=fn3(al,bl,cl,dl,el,words[zl[i]],hl[2],sl[i]);tr=fn3(ar,br,cr,dr,er,words[zr[i]],hr[2],sr[i])}else if(i<64){tl=fn4(al,bl,cl,dl,el,words[zl[i]],hl[3],sl[i]);tr=fn2(ar,br,cr,dr,er,words[zr[i]],hr[3],sr[i])}else{tl=fn5(al,bl,cl,dl,el,words[zl[i]],hl[4],sl[i]);tr=fn1(ar,br,cr,dr,er,words[zr[i]],hr[4],sr[i])}al=el;el=dl;dl=rotl(cl,10);cl=bl;bl=tl;ar=er;er=dr;dr=rotl(cr,10);cr=br;br=tr}var t=this._b+cl+dr|0;this._b=this._c+dl+er|0;this._c=this._d+el+ar|0;this._d=this._e+al+br|0;this._e=this._a+bl+cr|0;this._a=t};RIPEMD160.prototype._digest=function(){this._block[this._blockOffset++]=128;if(this._blockOffset>56){this._block.fill(0,this._blockOffset,64);this._update();this._blockOffset=0}this._block.fill(0,this._blockOffset,56);this._block.writeUInt32LE(this._length[0],56);this._block.writeUInt32LE(this._length[1],60);this._update();var buffer=Buffer.alloc?Buffer.alloc(20):new Buffer(20);buffer.writeInt32LE(this._a,0);buffer.writeInt32LE(this._b,4);buffer.writeInt32LE(this._c,8);buffer.writeInt32LE(this._d,12);buffer.writeInt32LE(this._e,16);return buffer};function rotl(x,n){return x<>>32-n}function fn1(a,b,c,d,e,m,k,s){return rotl(a+(b^c^d)+m+k|0,s)+e|0}function fn2(a,b,c,d,e,m,k,s){return rotl(a+(b&c|~b&d)+m+k|0,s)+e|0}function fn3(a,b,c,d,e,m,k,s){return rotl(a+((b|~c)^d)+m+k|0,s)+e|0}function fn4(a,b,c,d,e,m,k,s){return rotl(a+(b&d|c&~d)+m+k|0,s)+e|0}function fn5(a,b,c,d,e,m,k,s){return rotl(a+(b^(c|~d))+m+k|0,s)+e|0}module.exports=RIPEMD160},{buffer:175,"hash-base":214,inherits:244}],277:[function(require,module,exports){arguments[4][54][0].apply(exports,arguments)},{buffer:175,dup:54}],278:[function(require,module,exports){(function(process){(function(){"use strict";var buffer=require("buffer");var Buffer=buffer.Buffer;var safer={};var key;for(key in buffer){if(!buffer.hasOwnProperty(key))continue;if(key==="SlowBuffer"||key==="Buffer")continue;safer[key]=buffer[key]}var Safer=safer.Buffer={};for(key in Buffer){if(!Buffer.hasOwnProperty(key))continue;if(key==="allocUnsafe"||key==="allocUnsafeSlow")continue;Safer[key]=Buffer[key]}safer.Buffer.prototype=Buffer.prototype;if(!Safer.from||Safer.from===Uint8Array.from){Safer.from=function(value,encodingOrOffset,length){if(typeof value==="number"){throw new TypeError('The "value" argument must not be of type number. Received type '+typeof value)}if(value&&typeof value.length==="undefined"){throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof value)}return Buffer(value,encodingOrOffset,length)}}if(!Safer.alloc){Safer.alloc=function(size,fill,encoding){if(typeof size!=="number"){throw new TypeError('The "size" argument must be of type number. Received type '+typeof size)}if(size<0||size>=2*(1<<30)){throw new RangeError('The value "'+size+'" is invalid for option "size"')}var buf=Buffer(size);if(!fill||fill.length===0){buf.fill(0)}else if(typeof encoding==="string"){buf.fill(fill,encoding)}else{buf.fill(fill)}return buf}}if(!safer.kStringMaxLength){try{safer.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch(e){}}if(!safer.constants){safer.constants={MAX_LENGTH:safer.kMaxLength};if(safer.kStringMaxLength){safer.constants.MAX_STRING_LENGTH=safer.kStringMaxLength}}module.exports=safer}).call(this)}).call(this,require("_process"))},{_process:262,buffer:175}],279:[function(require,module,exports){var Buffer=require("safe-buffer").Buffer;function Hash(blockSize,finalSize){this._block=Buffer.alloc(blockSize);this._finalSize=finalSize;this._blockSize=blockSize;this._len=0}Hash.prototype.update=function(data,enc){if(typeof data==="string"){enc=enc||"utf8";data=Buffer.from(data,enc)}var block=this._block;var blockSize=this._blockSize;var length=data.length;var accum=this._len;for(var offset=0;offset=this._finalSize){this._update(this._block);this._block.fill(0)}var bits=this._len*8;if(bits<=4294967295){this._block.writeUInt32BE(bits,this._blockSize-4)}else{var lowBits=(bits&4294967295)>>>0;var highBits=(bits-lowBits)/4294967296;this._block.writeUInt32BE(highBits,this._blockSize-8);this._block.writeUInt32BE(lowBits,this._blockSize-4)}this._update(this._block);var hash=this._hash();return enc?hash.toString(enc):hash};Hash.prototype._update=function(){throw new Error("_update must be implemented by subclass")};module.exports=Hash},{"safe-buffer":277}],280:[function(require,module,exports){var exports=module.exports=function SHA(algorithm){algorithm=algorithm.toLowerCase();var Algorithm=exports[algorithm];if(!Algorithm)throw new Error(algorithm+" is not supported (we accept pull requests)");return new Algorithm};exports.sha=require("./sha");exports.sha1=require("./sha1");exports.sha224=require("./sha224");exports.sha256=require("./sha256");exports.sha384=require("./sha384");exports.sha512=require("./sha512")},{"./sha":281,"./sha1":282,"./sha224":283,"./sha256":284,"./sha384":285,"./sha512":286}],281:[function(require,module,exports){var inherits=require("inherits");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var K=[1518500249,1859775393,2400959708|0,3395469782|0];var W=new Array(80);function Sha(){this.init();this._w=W;Hash.call(this,64,56)}inherits(Sha,Hash);Sha.prototype.init=function(){this._a=1732584193;this._b=4023233417;this._c=2562383102;this._d=271733878;this._e=3285377520;return this};function rotl5(num){return num<<5|num>>>27}function rotl30(num){return num<<30|num>>>2}function ft(s,b,c,d){if(s===0)return b&c|~b&d;if(s===2)return b&c|b&d|c&d;return b^c^d}Sha.prototype._update=function(M){var W=this._w;var a=this._a|0;var b=this._b|0;var c=this._c|0;var d=this._d|0;var e=this._e|0;for(var i=0;i<16;++i)W[i]=M.readInt32BE(i*4);for(;i<80;++i)W[i]=W[i-3]^W[i-8]^W[i-14]^W[i-16];for(var j=0;j<80;++j){var s=~~(j/20);var t=rotl5(a)+ft(s,b,c,d)+e+W[j]+K[s]|0;e=d;d=c;c=rotl30(b);b=a;a=t}this._a=a+this._a|0;this._b=b+this._b|0;this._c=c+this._c|0;this._d=d+this._d|0;this._e=e+this._e|0};Sha.prototype._hash=function(){var H=Buffer.allocUnsafe(20);H.writeInt32BE(this._a|0,0);H.writeInt32BE(this._b|0,4);H.writeInt32BE(this._c|0,8);H.writeInt32BE(this._d|0,12);H.writeInt32BE(this._e|0,16);return H};module.exports=Sha},{"./hash":279,inherits:244,"safe-buffer":277}],282:[function(require,module,exports){var inherits=require("inherits");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var K=[1518500249,1859775393,2400959708|0,3395469782|0];var W=new Array(80);function Sha1(){this.init();this._w=W;Hash.call(this,64,56)}inherits(Sha1,Hash);Sha1.prototype.init=function(){this._a=1732584193;this._b=4023233417;this._c=2562383102;this._d=271733878;this._e=3285377520;return this};function rotl1(num){return num<<1|num>>>31}function rotl5(num){return num<<5|num>>>27}function rotl30(num){return num<<30|num>>>2}function ft(s,b,c,d){if(s===0)return b&c|~b&d;if(s===2)return b&c|b&d|c&d;return b^c^d}Sha1.prototype._update=function(M){var W=this._w;var a=this._a|0;var b=this._b|0;var c=this._c|0;var d=this._d|0;var e=this._e|0;for(var i=0;i<16;++i)W[i]=M.readInt32BE(i*4);for(;i<80;++i)W[i]=rotl1(W[i-3]^W[i-8]^W[i-14]^W[i-16]);for(var j=0;j<80;++j){var s=~~(j/20);var t=rotl5(a)+ft(s,b,c,d)+e+W[j]+K[s]|0;e=d;d=c;c=rotl30(b);b=a;a=t}this._a=a+this._a|0;this._b=b+this._b|0;this._c=c+this._c|0;this._d=d+this._d|0;this._e=e+this._e|0};Sha1.prototype._hash=function(){var H=Buffer.allocUnsafe(20);H.writeInt32BE(this._a|0,0);H.writeInt32BE(this._b|0,4);H.writeInt32BE(this._c|0,8);H.writeInt32BE(this._d|0,12);H.writeInt32BE(this._e|0,16);return H};module.exports=Sha1},{"./hash":279,inherits:244,"safe-buffer":277}],283:[function(require,module,exports){var inherits=require("inherits");var Sha256=require("./sha256");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var W=new Array(64);function Sha224(){this.init();this._w=W;Hash.call(this,64,56)}inherits(Sha224,Sha256);Sha224.prototype.init=function(){this._a=3238371032;this._b=914150663;this._c=812702999;this._d=4144912697;this._e=4290775857;this._f=1750603025;this._g=1694076839;this._h=3204075428;return this};Sha224.prototype._hash=function(){var H=Buffer.allocUnsafe(28);H.writeInt32BE(this._a,0);H.writeInt32BE(this._b,4);H.writeInt32BE(this._c,8);H.writeInt32BE(this._d,12);H.writeInt32BE(this._e,16);H.writeInt32BE(this._f,20);H.writeInt32BE(this._g,24);return H};module.exports=Sha224},{"./hash":279,"./sha256":284,inherits:244,"safe-buffer":277}],284:[function(require,module,exports){var inherits=require("inherits");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var K=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];var W=new Array(64);function Sha256(){this.init();this._w=W;Hash.call(this,64,56)}inherits(Sha256,Hash);Sha256.prototype.init=function(){this._a=1779033703;this._b=3144134277;this._c=1013904242;this._d=2773480762;this._e=1359893119;this._f=2600822924;this._g=528734635;this._h=1541459225;return this};function ch(x,y,z){return z^x&(y^z)}function maj(x,y,z){return x&y|z&(x|y)}function sigma0(x){return(x>>>2|x<<30)^(x>>>13|x<<19)^(x>>>22|x<<10)}function sigma1(x){return(x>>>6|x<<26)^(x>>>11|x<<21)^(x>>>25|x<<7)}function gamma0(x){return(x>>>7|x<<25)^(x>>>18|x<<14)^x>>>3}function gamma1(x){return(x>>>17|x<<15)^(x>>>19|x<<13)^x>>>10}Sha256.prototype._update=function(M){var W=this._w;var a=this._a|0;var b=this._b|0;var c=this._c|0;var d=this._d|0;var e=this._e|0;var f=this._f|0;var g=this._g|0;var h=this._h|0;for(var i=0;i<16;++i)W[i]=M.readInt32BE(i*4);for(;i<64;++i)W[i]=gamma1(W[i-2])+W[i-7]+gamma0(W[i-15])+W[i-16]|0;for(var j=0;j<64;++j){var T1=h+sigma1(e)+ch(e,f,g)+K[j]+W[j]|0;var T2=sigma0(a)+maj(a,b,c)|0;h=g;g=f;f=e;e=d+T1|0;d=c;c=b;b=a;a=T1+T2|0}this._a=a+this._a|0;this._b=b+this._b|0;this._c=c+this._c|0;this._d=d+this._d|0;this._e=e+this._e|0;this._f=f+this._f|0;this._g=g+this._g|0;this._h=h+this._h|0};Sha256.prototype._hash=function(){var H=Buffer.allocUnsafe(32);H.writeInt32BE(this._a,0);H.writeInt32BE(this._b,4);H.writeInt32BE(this._c,8);H.writeInt32BE(this._d,12);H.writeInt32BE(this._e,16);H.writeInt32BE(this._f,20);H.writeInt32BE(this._g,24);H.writeInt32BE(this._h,28);return H};module.exports=Sha256},{"./hash":279,inherits:244,"safe-buffer":277}],285:[function(require,module,exports){var inherits=require("inherits");var SHA512=require("./sha512");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var W=new Array(160);function Sha384(){this.init();this._w=W;Hash.call(this,128,112)}inherits(Sha384,SHA512);Sha384.prototype.init=function(){this._ah=3418070365;this._bh=1654270250;this._ch=2438529370;this._dh=355462360;this._eh=1731405415;this._fh=2394180231;this._gh=3675008525;this._hh=1203062813;this._al=3238371032;this._bl=914150663;this._cl=812702999;this._dl=4144912697;this._el=4290775857;this._fl=1750603025;this._gl=1694076839;this._hl=3204075428;return this};Sha384.prototype._hash=function(){var H=Buffer.allocUnsafe(48);function writeInt64BE(h,l,offset){H.writeInt32BE(h,offset);H.writeInt32BE(l,offset+4)}writeInt64BE(this._ah,this._al,0);writeInt64BE(this._bh,this._bl,8);writeInt64BE(this._ch,this._cl,16);writeInt64BE(this._dh,this._dl,24);writeInt64BE(this._eh,this._el,32);writeInt64BE(this._fh,this._fl,40);return H};module.exports=Sha384},{"./hash":279,"./sha512":286,inherits:244,"safe-buffer":277}],286:[function(require,module,exports){var inherits=require("inherits");var Hash=require("./hash");var Buffer=require("safe-buffer").Buffer;var K=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591];var W=new Array(160);function Sha512(){this.init();this._w=W;Hash.call(this,128,112)}inherits(Sha512,Hash);Sha512.prototype.init=function(){this._ah=1779033703;this._bh=3144134277;this._ch=1013904242;this._dh=2773480762;this._eh=1359893119;this._fh=2600822924;this._gh=528734635;this._hh=1541459225;this._al=4089235720;this._bl=2227873595;this._cl=4271175723;this._dl=1595750129;this._el=2917565137;this._fl=725511199;this._gl=4215389547;this._hl=327033209;return this};function Ch(x,y,z){return z^x&(y^z)}function maj(x,y,z){return x&y|z&(x|y)}function sigma0(x,xl){return(x>>>28|xl<<4)^(xl>>>2|x<<30)^(xl>>>7|x<<25)}function sigma1(x,xl){return(x>>>14|xl<<18)^(x>>>18|xl<<14)^(xl>>>9|x<<23)}function Gamma0(x,xl){return(x>>>1|xl<<31)^(x>>>8|xl<<24)^x>>>7}function Gamma0l(x,xl){return(x>>>1|xl<<31)^(x>>>8|xl<<24)^(x>>>7|xl<<25)}function Gamma1(x,xl){return(x>>>19|xl<<13)^(xl>>>29|x<<3)^x>>>6}function Gamma1l(x,xl){return(x>>>19|xl<<13)^(xl>>>29|x<<3)^(x>>>6|xl<<26)}function getCarry(a,b){return a>>>0>>0?1:0}Sha512.prototype._update=function(M){var W=this._w;var ah=this._ah|0;var bh=this._bh|0;var ch=this._ch|0;var dh=this._dh|0;var eh=this._eh|0;var fh=this._fh|0;var gh=this._gh|0;var hh=this._hh|0;var al=this._al|0;var bl=this._bl|0;var cl=this._cl|0;var dl=this._dl|0;var el=this._el|0;var fl=this._fl|0;var gl=this._gl|0;var hl=this._hl|0;for(var i=0;i<32;i+=2){W[i]=M.readInt32BE(i*4);W[i+1]=M.readInt32BE(i*4+4)}for(;i<160;i+=2){var xh=W[i-15*2];var xl=W[i-15*2+1];var gamma0=Gamma0(xh,xl);var gamma0l=Gamma0l(xl,xh);xh=W[i-2*2];xl=W[i-2*2+1];var gamma1=Gamma1(xh,xl);var gamma1l=Gamma1l(xl,xh);var Wi7h=W[i-7*2];var Wi7l=W[i-7*2+1];var Wi16h=W[i-16*2];var Wi16l=W[i-16*2+1];var Wil=gamma0l+Wi7l|0;var Wih=gamma0+Wi7h+getCarry(Wil,gamma0l)|0;Wil=Wil+gamma1l|0;Wih=Wih+gamma1+getCarry(Wil,gamma1l)|0;Wil=Wil+Wi16l|0;Wih=Wih+Wi16h+getCarry(Wil,Wi16l)|0;W[i]=Wih;W[i+1]=Wil}for(var j=0;j<160;j+=2){Wih=W[j];Wil=W[j+1];var majh=maj(ah,bh,ch);var majl=maj(al,bl,cl);var sigma0h=sigma0(ah,al);var sigma0l=sigma0(al,ah);var sigma1h=sigma1(eh,el);var sigma1l=sigma1(el,eh);var Kih=K[j];var Kil=K[j+1];var chh=Ch(eh,fh,gh);var chl=Ch(el,fl,gl);var t1l=hl+sigma1l|0;var t1h=hh+sigma1h+getCarry(t1l,hl)|0;t1l=t1l+chl|0;t1h=t1h+chh+getCarry(t1l,chl)|0;t1l=t1l+Kil|0;t1h=t1h+Kih+getCarry(t1l,Kil)|0;t1l=t1l+Wil|0;t1h=t1h+Wih+getCarry(t1l,Wil)|0;var t2l=sigma0l+majl|0;var t2h=sigma0h+majh+getCarry(t2l,sigma0l)|0;hh=gh;hl=gl;gh=fh;gl=fl;fh=eh;fl=el;el=dl+t1l|0;eh=dh+t1h+getCarry(el,dl)|0;dh=ch;dl=cl;ch=bh;cl=bl;bh=ah;bl=al;al=t1l+t2l|0;ah=t1h+t2h+getCarry(al,t1l)|0}this._al=this._al+al|0;this._bl=this._bl+bl|0;this._cl=this._cl+cl|0;this._dl=this._dl+dl|0;this._el=this._el+el|0;this._fl=this._fl+fl|0;this._gl=this._gl+gl|0;this._hl=this._hl+hl|0;this._ah=this._ah+ah+getCarry(this._al,al)|0;this._bh=this._bh+bh+getCarry(this._bl,bl)|0;this._ch=this._ch+ch+getCarry(this._cl,cl)|0;this._dh=this._dh+dh+getCarry(this._dl,dl)|0;this._eh=this._eh+eh+getCarry(this._el,el)|0;this._fh=this._fh+fh+getCarry(this._fl,fl)|0;this._gh=this._gh+gh+getCarry(this._gl,gl)|0;this._hh=this._hh+hh+getCarry(this._hl,hl)|0};Sha512.prototype._hash=function(){var H=Buffer.allocUnsafe(64);function writeInt64BE(h,l,offset){H.writeInt32BE(h,offset);H.writeInt32BE(l,offset+4)}writeInt64BE(this._ah,this._al,0);writeInt64BE(this._bh,this._bl,8);writeInt64BE(this._ch,this._cl,16);writeInt64BE(this._dh,this._dl,24);writeInt64BE(this._eh,this._el,32);writeInt64BE(this._fh,this._fl,40);writeInt64BE(this._gh,this._gl,48);writeInt64BE(this._hh,this._hl,56);return H};module.exports=Sha512},{"./hash":279,inherits:244,"safe-buffer":277}],287:[function(require,module,exports){module.exports=Stream;var EE=require("events").EventEmitter;var inherits=require("inherits");inherits(Stream,EE);Stream.Readable=require("readable-stream/lib/_stream_readable.js");Stream.Writable=require("readable-stream/lib/_stream_writable.js");Stream.Duplex=require("readable-stream/lib/_stream_duplex.js");Stream.Transform=require("readable-stream/lib/_stream_transform.js");Stream.PassThrough=require("readable-stream/lib/_stream_passthrough.js");Stream.finished=require("readable-stream/lib/internal/streams/end-of-stream.js");Stream.pipeline=require("readable-stream/lib/internal/streams/pipeline.js");Stream.Stream=Stream;function Stream(){EE.call(this)}Stream.prototype.pipe=function(dest,options){var source=this;function ondata(chunk){if(dest.writable){if(false===dest.write(chunk)&&source.pause){source.pause()}}}source.on("data",ondata);function ondrain(){if(source.readable&&source.resume){source.resume()}}dest.on("drain",ondrain);if(!dest._isStdio&&(!options||options.end!==false)){source.on("end",onend);source.on("close",onclose)}var didOnEnd=false;function onend(){if(didOnEnd)return;didOnEnd=true;dest.end()}function onclose(){if(didOnEnd)return;didOnEnd=true;if(typeof dest.destroy==="function")dest.destroy()}function onerror(er){cleanup();if(EE.listenerCount(this,"error")===0){throw er}}source.on("error",onerror);dest.on("error",onerror);function cleanup(){source.removeListener("data",ondata);dest.removeListener("drain",ondrain);source.removeListener("end",onend);source.removeListener("close",onclose);source.removeListener("error",onerror);dest.removeListener("error",onerror);source.removeListener("end",cleanup);source.removeListener("close",cleanup);dest.removeListener("close",cleanup)}source.on("end",cleanup);source.on("close",cleanup);dest.on("close",cleanup);dest.emit("pipe",source);return dest}},{events:212,inherits:244,"readable-stream/lib/_stream_duplex.js":289,"readable-stream/lib/_stream_passthrough.js":290,"readable-stream/lib/_stream_readable.js":291,"readable-stream/lib/_stream_transform.js":292,"readable-stream/lib/_stream_writable.js":293,"readable-stream/lib/internal/streams/end-of-stream.js":297,"readable-stream/lib/internal/streams/pipeline.js":299}],288:[function(require,module,exports){arguments[4][159][0].apply(exports,arguments)},{dup:159}],289:[function(require,module,exports){arguments[4][160][0].apply(exports,arguments)},{"./_stream_readable":291,"./_stream_writable":293,_process:262,dup:160,inherits:244}],290:[function(require,module,exports){arguments[4][161][0].apply(exports,arguments)},{"./_stream_transform":292,dup:161,inherits:244}],291:[function(require,module,exports){arguments[4][162][0].apply(exports,arguments)},{"../errors":288,"./_stream_duplex":289,"./internal/streams/async_iterator":294,"./internal/streams/buffer_list":295,"./internal/streams/destroy":296,"./internal/streams/from":298,"./internal/streams/state":300,"./internal/streams/stream":301,_process:262,buffer:175,dup:162,events:212,inherits:244,"string_decoder/":302,util:131}],292:[function(require,module,exports){arguments[4][163][0].apply(exports,arguments)},{"../errors":288,"./_stream_duplex":289,dup:163,inherits:244}],293:[function(require,module,exports){arguments[4][164][0].apply(exports,arguments)},{"../errors":288,"./_stream_duplex":289,"./internal/streams/destroy":296,"./internal/streams/state":300,"./internal/streams/stream":301,_process:262,buffer:175,dup:164,inherits:244,"util-deprecate":305}],294:[function(require,module,exports){arguments[4][165][0].apply(exports,arguments)},{"./end-of-stream":297,_process:262,dup:165}],295:[function(require,module,exports){arguments[4][166][0].apply(exports,arguments)},{buffer:175,dup:166,util:131}],296:[function(require,module,exports){arguments[4][167][0].apply(exports,arguments)},{_process:262,dup:167}],297:[function(require,module,exports){arguments[4][168][0].apply(exports,arguments)},{"../../../errors":288,dup:168}],298:[function(require,module,exports){arguments[4][169][0].apply(exports,arguments)},{dup:169}],299:[function(require,module,exports){arguments[4][170][0].apply(exports,arguments)},{"../../../errors":288,"./end-of-stream":297,dup:170}],300:[function(require,module,exports){arguments[4][171][0].apply(exports,arguments)},{"../../../errors":288,dup:171}],301:[function(require,module,exports){arguments[4][172][0].apply(exports,arguments)},{dup:172,events:212}],302:[function(require,module,exports){"use strict";var Buffer=require("safe-buffer").Buffer;var isEncoding=Buffer.isEncoding||function(encoding){encoding=""+encoding;switch(encoding&&encoding.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return true;default:return false}};function _normalizeEncoding(enc){if(!enc)return"utf8";var retried;while(true){switch(enc){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return enc;default:if(retried)return;enc=(""+enc).toLowerCase();retried=true}}}function normalizeEncoding(enc){var nenc=_normalizeEncoding(enc);if(typeof nenc!=="string"&&(Buffer.isEncoding===isEncoding||!isEncoding(enc)))throw new Error("Unknown encoding: "+enc);return nenc||enc}exports.StringDecoder=StringDecoder;function StringDecoder(encoding){this.encoding=normalizeEncoding(encoding);var nb;switch(this.encoding){case"utf16le":this.text=utf16Text;this.end=utf16End;nb=4;break;case"utf8":this.fillLast=utf8FillLast;nb=4;break;case"base64":this.text=base64Text;this.end=base64End;nb=3;break;default:this.write=simpleWrite;this.end=simpleEnd;return}this.lastNeed=0;this.lastTotal=0;this.lastChar=Buffer.allocUnsafe(nb)}StringDecoder.prototype.write=function(buf){if(buf.length===0)return"";var r;var i;if(this.lastNeed){r=this.fillLast(buf);if(r===undefined)return"";i=this.lastNeed;this.lastNeed=0}else{i=0}if(i>5===6)return 2;else if(byte>>4===14)return 3;else if(byte>>3===30)return 4;return byte>>6===2?-1:-2}function utf8CheckIncomplete(self,buf,i){var j=buf.length-1;if(j=0){if(nb>0)self.lastNeed=nb-1;return nb}if(--j=0){if(nb>0)self.lastNeed=nb-2;return nb}if(--j=0){if(nb>0){if(nb===2)nb=0;else self.lastNeed=nb-3}return nb}return 0}function utf8CheckExtraBytes(self,buf,p){if((buf[0]&192)!==128){self.lastNeed=0;return"�"}if(self.lastNeed>1&&buf.length>1){if((buf[1]&192)!==128){self.lastNeed=1;return"�"}if(self.lastNeed>2&&buf.length>2){if((buf[2]&192)!==128){self.lastNeed=2;return"�"}}}}function utf8FillLast(buf){var p=this.lastTotal-this.lastNeed;var r=utf8CheckExtraBytes(this,buf,p);if(r!==undefined)return r;if(this.lastNeed<=buf.length){buf.copy(this.lastChar,p,0,this.lastNeed);return this.lastChar.toString(this.encoding,0,this.lastTotal)}buf.copy(this.lastChar,p,0,buf.length);this.lastNeed-=buf.length}function utf8Text(buf,i){var total=utf8CheckIncomplete(this,buf,i);if(!this.lastNeed)return buf.toString("utf8",i);this.lastTotal=total;var end=buf.length-(total-this.lastNeed);buf.copy(this.lastChar,0,end);return buf.toString("utf8",i,end)}function utf8End(buf){var r=buf&&buf.length?this.write(buf):"";if(this.lastNeed)return r+"�";return r}function utf16Text(buf,i){if((buf.length-i)%2===0){var r=buf.toString("utf16le",i);if(r){var c=r.charCodeAt(r.length-1);if(c>=55296&&c<=56319){this.lastNeed=2;this.lastTotal=4;this.lastChar[0]=buf[buf.length-2];this.lastChar[1]=buf[buf.length-1];return r.slice(0,-1)}}return r}this.lastNeed=1;this.lastTotal=2;this.lastChar[0]=buf[buf.length-1];return buf.toString("utf16le",i,buf.length-1)}function utf16End(buf){var r=buf&&buf.length?this.write(buf):"";if(this.lastNeed){var end=this.lastTotal-this.lastNeed;return r+this.lastChar.toString("utf16le",0,end)}return r}function base64Text(buf,i){var n=(buf.length-i)%3;if(n===0)return buf.toString("base64",i);this.lastNeed=3-n;this.lastTotal=3;if(n===1){this.lastChar[0]=buf[buf.length-1]}else{this.lastChar[0]=buf[buf.length-2];this.lastChar[1]=buf[buf.length-1]}return buf.toString("base64",i,buf.length-n)}function base64End(buf){var r=buf&&buf.length?this.write(buf):"";if(this.lastNeed)return r+this.lastChar.toString("base64",0,3-this.lastNeed);return r}function simpleWrite(buf){return buf.toString(this.encoding)}function simpleEnd(buf){return buf&&buf.length?this.write(buf):""}},{"safe-buffer":277}],303:[function(require,module,exports){"use strict";var punycode=require("punycode");var util=require("./util");exports.parse=urlParse;exports.resolve=urlResolve;exports.resolveObject=urlResolveObject;exports.format=urlFormat;exports.Url=Url;function Url(){this.protocol=null;this.slashes=null;this.auth=null;this.host=null;this.port=null;this.hostname=null;this.hash=null;this.search=null;this.query=null;this.pathname=null;this.path=null;this.href=null}var protocolPattern=/^([a-z0-9.+-]+:)/i,portPattern=/:[0-9]*$/,simplePathPattern=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,delims=["<",">",'"',"`"," ","\r","\n","\t"],unwise=["{","}","|","\\","^","`"].concat(delims),autoEscape=["'"].concat(unwise),nonHostChars=["%","/","?",";","#"].concat(autoEscape),hostEndingChars=["/","?","#"],hostnameMaxLen=255,hostnamePartPattern=/^[+a-z0-9A-Z_-]{0,63}$/,hostnamePartStart=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,unsafeProtocol={javascript:true,"javascript:":true},hostlessProtocol={javascript:true,"javascript:":true},slashedProtocol={http:true,https:true,ftp:true,gopher:true,file:true,"http:":true,"https:":true,"ftp:":true,"gopher:":true,"file:":true},querystring=require("querystring");function urlParse(url,parseQueryString,slashesDenoteHost){if(url&&util.isObject(url)&&url instanceof Url)return url;var u=new Url;u.parse(url,parseQueryString,slashesDenoteHost);return u}Url.prototype.parse=function(url,parseQueryString,slashesDenoteHost){if(!util.isString(url)){throw new TypeError("Parameter 'url' must be a string, not "+typeof url)}var queryIndex=url.indexOf("?"),splitter=queryIndex!==-1&&queryIndex127){newpart+="x"}else{newpart+=part[j]}}if(!newpart.match(hostnamePartPattern)){var validParts=hostparts.slice(0,i);var notHost=hostparts.slice(i+1);var bit=part.match(hostnamePartStart);if(bit){validParts.push(bit[1]);notHost.unshift(bit[2])}if(notHost.length){rest="/"+notHost.join(".")+rest}this.hostname=validParts.join(".");break}}}}if(this.hostname.length>hostnameMaxLen){this.hostname=""}else{this.hostname=this.hostname.toLowerCase()}if(!ipv6Hostname){this.hostname=punycode.toASCII(this.hostname)}var p=this.port?":"+this.port:"";var h=this.hostname||"";this.host=h+p;this.href+=this.host;if(ipv6Hostname){this.hostname=this.hostname.substr(1,this.hostname.length-2);if(rest[0]!=="/"){rest="/"+rest}}}if(!unsafeProtocol[lowerProto]){for(var i=0,l=autoEscape.length;i0?result.host.split("@"):false;if(authInHost){result.auth=authInHost.shift();result.host=result.hostname=authInHost.shift()}}result.search=relative.search;result.query=relative.query;if(!util.isNull(result.pathname)||!util.isNull(result.search)){result.path=(result.pathname?result.pathname:"")+(result.search?result.search:"")}result.href=result.format();return result}if(!srcPath.length){result.pathname=null;if(result.search){result.path="/"+result.search}else{result.path=null}result.href=result.format();return result}var last=srcPath.slice(-1)[0];var hasTrailingSlash=(result.host||relative.host||srcPath.length>1)&&(last==="."||last==="..")||last==="";var up=0;for(var i=srcPath.length;i>=0;i--){last=srcPath[i];if(last==="."){srcPath.splice(i,1)}else if(last===".."){srcPath.splice(i,1);up++}else if(up){srcPath.splice(i,1);up--}}if(!mustEndAbs&&!removeAllDots){for(;up--;up){srcPath.unshift("..")}}if(mustEndAbs&&srcPath[0]!==""&&(!srcPath[0]||srcPath[0].charAt(0)!=="/")){srcPath.unshift("")}if(hasTrailingSlash&&srcPath.join("/").substr(-1)!=="/"){srcPath.push("")}var isAbsolute=srcPath[0]===""||srcPath[0]&&srcPath[0].charAt(0)==="/";if(psychotic){result.hostname=result.host=isAbsolute?"":srcPath.length?srcPath.shift():"";var authInHost=result.host&&result.host.indexOf("@")>0?result.host.split("@"):false;if(authInHost){result.auth=authInHost.shift();result.host=result.hostname=authInHost.shift()}}mustEndAbs=mustEndAbs||result.host&&srcPath.length;if(mustEndAbs&&!isAbsolute){srcPath.unshift("")}if(!srcPath.length){result.pathname=null;result.path=null}else{result.pathname=srcPath.join("/")}if(!util.isNull(result.pathname)||!util.isNull(result.search)){result.path=(result.pathname?result.pathname:"")+(result.search?result.search:"")}result.auth=relative.auth||result.auth;result.slashes=result.slashes||relative.slashes;result.href=result.format();return result};Url.prototype.parseHost=function(){var host=this.host;var port=portPattern.exec(host);if(port){port=port[0];if(port!==":"){this.port=port.substr(1)}host=host.substr(0,host.length-port.length)}if(host)this.hostname=host}},{"./util":304,punycode:270,querystring:273}],304:[function(require,module,exports){"use strict";module.exports={isString:function(arg){return typeof arg==="string"},isObject:function(arg){return typeof arg==="object"&&arg!==null},isNull:function(arg){return arg===null},isNullOrUndefined:function(arg){return arg==null}}},{}],305:[function(require,module,exports){(function(global){(function(){module.exports=deprecate;function deprecate(fn,msg){if(config("noDeprecation")){return fn}var warned=false;function deprecated(){if(!warned){if(config("throwDeprecation")){throw new Error(msg)}else if(config("traceDeprecation")){console.trace(msg)}else{console.warn(msg)}warned=true}return fn.apply(this,arguments)}return deprecated}function config(name){try{if(!global.localStorage)return false}catch(_){return false}var val=global.localStorage[name];if(null==val)return false;return String(val).toLowerCase()==="true"}}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{})},{}],"bitcore-lib":[function(require,module,exports){(function(global,Buffer){(function(){"use strict";var bitcore=module.exports;bitcore.version="v"+require("./package.json").version;bitcore.versionGuard=function(version){if(version!==undefined){var message="More than one instance of bitcore-lib found. "+"Please make sure to require bitcore-lib and check that submodules do"+" not also include their own bitcore-lib dependency.";console.log(message)}};bitcore.versionGuard(global._bitcore);global._bitcore=bitcore.version;bitcore.crypto={};bitcore.crypto.BN=require("./lib/crypto/bn");bitcore.crypto.ECDSA=require("./lib/crypto/ecdsa");bitcore.crypto.Hash=require("./lib/crypto/hash");bitcore.crypto.Random=require("./lib/crypto/random");bitcore.crypto.Point=require("./lib/crypto/point");bitcore.crypto.Signature=require("./lib/crypto/signature");bitcore.encoding={};bitcore.encoding.Base58=require("./lib/encoding/base58");bitcore.encoding.Base58Check=require("./lib/encoding/base58check");bitcore.encoding.BufferReader=require("./lib/encoding/bufferreader");bitcore.encoding.BufferWriter=require("./lib/encoding/bufferwriter");bitcore.encoding.Varint=require("./lib/encoding/varint");bitcore.util={};bitcore.util.buffer=require("./lib/util/buffer");bitcore.util.js=require("./lib/util/js");bitcore.util.preconditions=require("./lib/util/preconditions");bitcore.errors=require("./lib/errors");bitcore.Address=require("./lib/address");bitcore.Block=require("./lib/block");bitcore.MerkleBlock=require("./lib/block/merkleblock");bitcore.BlockHeader=require("./lib/block/blockheader");bitcore.HDPrivateKey=require("./lib/hdprivatekey.js");bitcore.HDPublicKey=require("./lib/hdpublickey.js");bitcore.Message=require("./lib/message");bitcore.Networks=require("./lib/networks");bitcore.Opcode=require("./lib/opcode");bitcore.PrivateKey=require("./lib/privatekey");bitcore.PublicKey=require("./lib/publickey");bitcore.Script=require("./lib/script");bitcore.Transaction=require("./lib/transaction");bitcore.URI=require("./lib/uri");bitcore.Unit=require("./lib/unit");bitcore.deps={};bitcore.deps.bnjs=require("bn.js");bitcore.deps.bs58=require("bs58");bitcore.deps.Buffer=Buffer;bitcore.deps.elliptic=require("elliptic");bitcore.deps._=require("lodash");bitcore.Transaction.sighash=require("./lib/transaction/sighash")}).call(this)}).call(this,typeof global!=="undefined"?global:typeof self!=="undefined"?self:typeof window!=="undefined"?window:{},require("buffer").Buffer)},{"./lib/address":1,"./lib/block":4,"./lib/block/blockheader":3,"./lib/block/merkleblock":5,"./lib/crypto/bn":6,"./lib/crypto/ecdsa":7,"./lib/crypto/hash":8,"./lib/crypto/point":9,"./lib/crypto/random":10,"./lib/crypto/signature":11,"./lib/encoding/base58":12,"./lib/encoding/base58check":13,"./lib/encoding/bufferreader":15,"./lib/encoding/bufferwriter":16,"./lib/encoding/varint":17,"./lib/errors":18,"./lib/hdprivatekey.js":20,"./lib/hdpublickey.js":21,"./lib/message":22,"./lib/networks":23,"./lib/opcode":24,"./lib/privatekey":25,"./lib/publickey":26,"./lib/script":27,"./lib/transaction":30,"./lib/transaction/sighash":38,"./lib/unit":43,"./lib/uri":44,"./lib/util/buffer":45,"./lib/util/js":46,"./lib/util/preconditions":47,"./package.json":108,"bn.js":62,bs58:64,buffer:175,elliptic:71,lodash:103}]},{},[]); diff --git a/www/assets/js/crypto.js b/www/assets/js/crypto.js deleted file mode 100644 index c24de2c..0000000 --- a/www/assets/js/crypto.js +++ /dev/null @@ -1,523 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -var walletPubKeyRegex = /^(bc1|[13]|D)[a-zA-HJ-NP-Z0-9]{25,}$/; -var paymentRequestRegex = /^(?:bitcoin|dogecoin):([a-zA-Z0-9]{20,40})(?:\?(.*))?$/; -var walletPrivateKeyRegex = /^[0-9A-Za-z]+$/; - -/** - * Parse a crypto URI and extract the info in it. - * Copyright (c) 2019 Robin Linus, MIT license, https://github.com/coins/bitcoin-uri-js - * @param {type} uri - * @returns {parsePaymentURI.parsed} - */ -function parsePaymentURI(uri) { - const legalKeys = ['address', 'amount', 'value', 'message', 'send', 'tx']; - const match = paymentRequestRegex.exec(uri); - if (!match) { - return null; - } - - const parsed = {uri: uri} - if (match[2]) { - const queries = match[2].split('&'); - for (let i = 0; i < queries.length; i++) { - const query = queries[i].split('='); - const key = query[0]; - if (query.length === 2 && legalKeys.includes(key)) { - parsed[key] = decodeURIComponent(query[1].replace(/\+/g, '%20')); - } - } - } - - parsed.address = match[1]; - return parsed; -} - -function openWalletPage(walletaddress) { - var navuri = '/crypto/' + walletaddress; - if (typeof router.currentRoute.query.paymenturi != 'undefined') { - var parsed = parsePaymentURI(router.currentRoute.query.paymenturi); - if (parsed != null) { - navuri += '/' + parsed.address; - if (typeof parsed['amount'] != 'undefined') { - navuri += '/' + parsed.amount; - } - } - } - router.navigate(navuri); -} - -function scanWalletQrCode(callback) { - scanBarcode(function (result) { - if (walletPubKeyRegex.test(result)) { - callback(result); - } else { - app.dialog.alert("That doesn't look like a valid wallet address.", "Error"); - return; - } - }, function () { - app.dialog.alert("Something went wrong and we can't scan right now.", "Error"); - }); -} - -function scanPrivateKeyQrCode(callback) { - scanBarcode(function (result) { - if (walletPrivateKeyRegex.test(result)) { - callback(result); - } else { - app.dialog.alert("That doesn't look like a valid wallet address.", "Error"); - return; - } - }, function () { - app.dialog.alert("Something went wrong and we can't scan right now.", "Error"); - }); -} - -/** - * Create and sign a crypto transaction. - * - * @param {type} bitcoreLib Bitcore, Litecore, Dogecore, etc. - * @param {type} privateKeyString Private key from wallet QR code - * @param {type} sourceAddress Sender's wallet address - * @param {type} destinationAddress Recipient's wallet address - * @param {Array} utxos Unspent transaction inputs, as array. See createUtxo() - * @param {type} outputSatoshis Amount to send to recipient's wallet - * @returns {string} Hex of serialized transaction, suitable for broadcast via Bitcoin Core or an API. - */ -function createSignedTransaction(bitcoreLib, privateKeyString, sourceAddress, destinationAddress, utxos, outputSatoshis, feePerByte) { - if (typeof feePerByte == "undefined") { - feePerByte = -1; - } - try { - var privateKey = new bitcoreLib.PrivateKey(privateKeyString); - - var transaction = new bitcoreLib.Transaction() - .from(utxos) - .to(destinationAddress, outputSatoshis) - .change(sourceAddress); - - var size = transaction._estimateSize(); - var fee = size * feePerByte; - - if (feePerByte > -1) { - // use our fee - transaction = transaction.fee(fee); - } else { - // use lib's fee - fee = transaction.getFee(); - } - - transaction = transaction.sign(privateKey); - - var inputTotal = transaction._getInputAmount(); - - var outputTotal = fee + outputSatoshis; - } catch (ex) { - throw new Error("There was an internal error while creating the transaction. Details: " + ex.message); - } - console.log(inputTotal, outputTotal); - if (outputTotal > inputTotal) { - throw new Error("You have insufficient funds to cover the payment and transaction fees."); - } - - try { - return {serialized: transaction.serialize(), fee: fee, sendamount: outputSatoshis, totalspent: outputTotal}; - } catch (ex) { - throw new Error("Couldn't create the transaction. It's likely you typed something wrong. Check that you have enough funds."); - } -} - -/** - * Create a UTXO. - * - * @param {type} sourceAddress Sender's wallet address - * @param {type} txHash From UTXO (unspent output) - * @param {type} txOutputIndex From UTXO (unspent output) - * @param {type} script From UTXO (unspent output) - * @param {type} inputSatoshis From UTXO (unspent output) - * @returns {createUtxo.utxo} - */ -function createUtxo(sourceAddress, txHash, txOutputIndex, script, inputSatoshis) { - var utxo = { - "txId": txHash, - "outputIndex": txOutputIndex, - "address": sourceAddress, - "script": script, - "satoshis": inputSatoshis - }; - return utxo; -} - -/** - * Get unspent outputs for a wallet address. - * @param {string} walletaddress - * @param {function} successCallback Passes object with {utxos: [{txHash,txOutputIndex,script,value}], currency: "DOGE", label: "Dogecoin"} - * @param {function} errorCallback Passes string error message suitable for display - * @returns {undefined} - */ -function getUTXOData(walletaddress, successCallback, errorCallback) { - apirequest(SETTINGS.apis.getutxo, { - walletaddress: walletaddress - }, function (resp) { - if (resp.status == "OK") { - successCallback({ - utxos: resp.unspent_outputs, - currency: resp.currency, - label: resp.label - }); - } else { - errorCallback(resp.msg); - } - }, function (errorData) { - try { - var error = $.parseJSON(errorData.responseText); - if (error && typeof error.msg != 'undefined') { - errorCallback(resp.msg); - sendErrorReport("Crypto", "Couldn't get UTXO data", error.msg); - } else { - errorCallback("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe."); - sendErrorReport("Crypto", "Couldn't get UTXO data", "Server/network problem: " + errorData.status + ": " + errorData.statusText); - } - } catch (ex) { - errorCallback("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe."); - sendErrorReport("Crypto", "Couldn't get UTXO data", "Server/network problem: " + errorData.status + ": " + errorData.statusText); - } - }); -} - -function sendCoins(privatekey, fromaddress, toaddress, amount) { - var progressdialog = app.dialog.progress("Querying blockchain...", 20); - getUTXOData(fromaddress, function (success) { - progressdialog.setProgress(40); - progressdialog.setText("Creating transaction..."); - if (success.utxos.length == 0) { - app.dialog.close(); - app.dialog.alert("Your wallet has no available funds (ZERO_LENGTH_UTXO).", "Error"); - return; - } - var utxos = []; - for (var i = 0; i < success.utxos.length; i++) { - utxos.push(createUtxo(fromaddress, success.utxos[i].txHash, success.utxos[i].txOutputIndex, success.utxos[i].script, success.utxos[i].value)); - } - var bitcore = null; - var satoshis = parseInt((amount * 100000000).toFixed(0)); // Make sure it's an int and not something like 10.0000000001 or 9.532999999999 - switch (success.currency) { - case "DOGE": - bitcore = require("bitcore-lib-doge"); - break; - case "BTC": - bitcore = require("bitcore-lib"); - break; - default: - app.dialog.close(); - app.dialog.alert("This app version doesn't support " + success.currency + ".", "Error"); - return; - } - - progressdialog.setProgress(60); - progressdialog.setText("Calculating fees..."); - apirequest(SETTINGS.apis.cryptofees, { - currency: success.currency - }, function (resp) { - if (resp.status == "OK") { - try { - var txdata = createSignedTransaction(bitcore, privatekey, fromaddress, toaddress, utxos, satoshis, resp.feePerByte); - } catch (ex) { - console.error(ex); - app.dialog.close(); - app.dialog.alert(ex.message, "Error"); - return; - } - - progressdialog.close(); - - app.dialog.confirm("Sending " + (txdata.sendamount / 100000000) + " " + success.currency - + " with a fee of " + (txdata.fee / 100000000) + " " + success.currency - + " for a total spend of " + (txdata.totalspent / 100000000) + " " + success.currency + ".", - "Confirm Transaction", - function (ok) { - progressdialog = app.dialog.progress("Sending payment...", 80); - - apirequest(SETTINGS.apis.broadcasttransaction, { - transactiondata: txdata.serialized, - currency: success.currency - }, function (resp) { - if (resp.status == "OK") { - app.dialog.close(); - app.dialog.alert("Sent " + amount + " " + success.currency + " to " + toaddress.substring(0, 5) + "..." + toaddress.substring(toaddress.length - 5, 999), "Success!"); - $('#walletPrivateKey').val(""); // clear private key input box - app.popup.close(); - return; - } else { - app.dialog.close(); - app.dialog.alert(resp.msg, "Error"); - } - }, function (errorData) { - app.dialog.close(); - try { - var error = $.parseJSON(errorData.responseText); - if (error && typeof error.msg != 'undefined') { - app.dialog.alert(error.msg, "Error"); - sendErrorReport("Crypto", "Couldn't broadcast transaction", error.msg); - } else { - app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe.", "Error"); - sendErrorReport("Crypto", "Couldn't broadcast transaction", "Server/network problem: " + errorData.status + ": " + errorData.statusText); - } - } catch (ex) { - app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe.", "Error"); - sendErrorReport("Crypto", "Couldn't broadcast transaction", "Server/network problem: " + errorData.status + ": " + errorData.statusText); - } - }); - }); - } else { - app.dialog.close(); - app.dialog.alert(resp.msg, "Error"); - } - }, function (errorData) { - app.dialog.close(); - try { - var error = $.parseJSON(errorData.responseText); - if (error && typeof error.msg != 'undefined') { - app.dialog.alert(error.msg, "Error"); - sendErrorReport("Crypto", "Couldn't get transaction fees", error.msg); - } else { - app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe.", "Error"); - sendErrorReport("Crypto", "Couldn't get transaction fees", "Server/network problem: " + errorData.status + ": " + errorData.statusText); - } - } catch (ex) { - app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe.", "Error"); - sendErrorReport("Crypto", "Couldn't get transaction fees", "Server/network problem: " + errorData.status + ": " + errorData.statusText); - } - }); - }, function (error) { - app.dialog.close(); - app.dialog.alert(error, "Error"); - }); -} - -function walletGUISendCoins() { - if (!walletPubKeyRegex.test($('#walletAddress').text())) { - app.dialog.alert("Your wallet address doesn't look right. Check it and try again.", "Error"); - return; - } - - if (isNaN($('#transactionAmount').val()) || $('#transactionAmount').val() < 0.00000001) { - app.dialog.alert("The amount to send doesn't look right. Check it and try again.", "Error"); - return; - } - - // Remove payment request URL stuff - if ($('#walletToAddress').val().startsWith("bitcoin:")) { - $('#walletToAddress').val($('#walletToAddress').val().replace("bitcoin:", "")); - } - if ($('#walletToAddress').val().startsWith("dogecoin:")) { - $('#walletToAddress').val($('#walletToAddress').val().replace("dogecoin:", "")); - } - - if (!walletPubKeyRegex.test($('#walletToAddress').val())) { - app.dialog.alert("The recipient's wallet address doesn't look right. Check it and try again.", "Error"); - return; - } - sendCoins($('#walletPrivateKey').val(), $('#walletAddress').text(), $('#walletToAddress').val(), parseFloat($('#transactionAmount').val())); -} - -function openWalletBalancePage( {to, resolve, reject}) { - var address = to.params.walletaddress; - if (!walletPubKeyRegex.test(address)) { - app.dialog.alert("That doesn't look like a valid wallet address.", "Error"); - reject(); - return; - } - - app.dialog.preloader("Loading..."); - apirequest(SETTINGS.apis.walletbalance, { - walletaddress: address - }, function (resp) { - app.dialog.close(); - if (resp.status == "OK") { - var context = { - balance: resp.balance, - currencyunit: resp.currency, - fiatvalue: resp.usdvalue, - currencyname: resp.label, - attribution: resp.attribution, - exchangerate: resp.exchangerates.usd, - logo: "./assets/images/crypto/" + resp.currency + ".svg", - walletaddress: to.params.walletaddress, - sendtoaddress: (typeof to.params.toaddress != "undefined" ? to.params.toaddress : ""), - sendtoamount: (typeof to.params.amount != "undefined" ? to.params.amount : "") - }; - resolve({ - content: compiledPages.crypto_wallet(context) - }); - - } else { - reject(); - app.dialog.alert(resp.msg, "Error"); - } - }, function (error) { - reject(); - app.dialog.close(); - try { - var error = $.parseJSON(error.responseText); - if (error && typeof error.msg != 'undefined') { - app.dialog.alert(error.msg, "Error"); - sendErrorReport("Crypto", "Couldn't get wallet balance", error.msg); - } else { - app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe.", "Error"); - sendErrorReport("Crypto", "Couldn't get wallet balance", "Server/network problem: " + error.status + ": " + error.statusText); - } - } catch (ex) { - app.dialog.alert("There's a server or network problem. Check your Internet connection or try again later. Your funds are safe.", "Error"); - sendErrorReport("Crypto", "Couldn't get wallet balance", "Server/network problem: " + error.status + ": " + error.statusText); - } - }); -} - -/** - * Setup an input for specifying amount to send in USD, with conversion to crypto. - * @param {string} walletAddress Detects cryptocurrency from wallet address - * @returns {undefined} - */ -function setupFiatConversion(walletAddress) { - apirequest(SETTINGS.apis.walletbalance, { - walletaddress: walletAddress - }, function (resp) { - if (resp.status != "OK") { - return; - } - if (resp.exchangerates.usd == -1) { - return; - } - $("#cryptoFiatInputItem").css("display", ""); - $("#cryptoAmountSendCurrencyLabel").text(resp.currency); - $("#cryptoAmountSendFiatLabel").text("$"); - $("#transactionAmountFiat").data("exchange-rate", resp.exchangerates.usd); - $("#transactionAmountFiat").data("cryptocurrency", resp.currency); - - $("#transactionAmount").off("input change paste keyup"); - $("#transactionAmountFiat").off("input change paste keyup"); - - $("#transactionAmount").on("input change paste keyup", function () { - if ($("#cryptoFiatInputItem").css("display") == "none") { - return; - } - var amount = parseFloat($("#transactionAmount").val()); - var exchangerate = parseFloat($("#transactionAmountFiat").data("exchange-rate")); - $("#transactionAmountFiat").val((amount * exchangerate).toFixed(2)); - //$("#transactionAmount").val(amount.toFixed(8)); - }); - $("#transactionAmountFiat").on("input change paste keyup", function () { - if ($("#cryptoFiatInputItem").css("display") == "none") { - return; - } - var fiatamount = parseFloat($("#transactionAmountFiat").val()); - var exchangerate = parseFloat($("#transactionAmountFiat").data("exchange-rate")); - $("#transactionAmount").val((fiatamount / exchangerate).toFixed(8)); - }); - if ($("#transactionAmount").val() != "") { - // Update the fiat conversion calculation if there's an amount prefilled - $("#transactionAmount").trigger("input"); - } - }); -} - -function setupReceiveFiatConversion() { - var exchangerate = $("#receiveAmountFiat").data("exchangerate"); - var fiatlabel = $("#receiveAmountFiat").data("currencylabel"); - - if (exchangerate == -1) { - return; - } - $("#cryptoAmountReceiveFiatLI").css("display", ""); - $("#cryptoAmountReceiveFiatLabel").text(fiatlabel); - - $("#receiveAmount").off("input change paste keyup"); - $("#receiveAmountFiat").off("input change paste keyup"); - - $("#receiveAmount").on("input change paste keyup", function () { - if ($("#cryptoAmountReceiveFiatLI").css("display") == "none") { - return; - } - var amount = parseFloat($("#receiveAmount").val()); - var exchangerate = parseFloat($("#receiveAmountFiat").data("exchangerate")); - $("#receiveAmountFiat").val((amount * exchangerate).toFixed(2)); - }); - $("#receiveAmountFiat").on("input change paste keyup", function () { - var fiatamount = parseFloat($("#receiveAmountFiat").val()); - var exchangerate = parseFloat($("#receiveAmountFiat").data("exchangerate")); - $("#receiveAmount").val((fiatamount / exchangerate).toFixed(8)); - }); - if ($("#receiveAmount").val() != "") { - // Update the fiat conversion calculation if there's an amount prefilled - $("#receiveAmount").trigger("input"); - } -} - -/** - * Hides the fiat conversion input box. - * @returns {undefined} - */ -function unsetupFiatConversion() { - $("#cryptoFiatInputItem").css("display", "none"); - $("#cryptoAmountSendCurrencyLabel").text(""); - $("#transactionAmountFiat").removeData("exchange-rate"); - $("#transactionAmountFiat").removeData("cryptocurrency"); - $("#transactionAmount").off("input change paste keyup"); - $("#transactionAmountFiat").off("input change paste keyup"); -} - -function showPaymentRequestQRCode() { - var paymenturi = ""; - switch ($("#receiveAmount").data("currency")) { - case "DOGE": - paymenturi = "dogecoin:"; - break; - case "BTC": - paymenturi = "bitcoin:"; - break; - } - paymenturi += $('#walletAddress').text(); - if ($("#receiveAmount").val() > 0) { - paymenturi += "?amount=" + $("#receiveAmount").val(); - } - $("#paymentRequestQRCodeContainer").html(""); - new QRCode(document.getElementById("paymentRequestQRCodeContainer"), paymenturi); -} - -$("#app").on("click", "#sendCryptoOpenPopupBtn", function () { - if (platform_type == "cordova") { - if (cordova.platformId == "ios") { - app.dialog.create({ - title: "Switch to Web Version", - text: "Apple doesn't allow this feature on the App Store. Tap Continue to launch the web version of this app instead, which is allowed to send crypto. We're sorry for the inconvenience.", - verticalButtons: true, - buttons: [ - { - text: "Continue", - bold: true, - keyCodes: [13], - onClick: function () { - openExternalBrowser("https://app.helena.express/?startpage=crypto"); - } - }, - { - text: "Cancel", - color: "red" - } - ] - }).open(); - return; - } - } - app.popup.open("#sendCryptoPopup"); - if (walletPubKeyRegex.test($("#walletAddress").text())) { - setupFiatConversion($("#walletAddress").text()); - } else { - unsetupFiatConversion(); - } -}); \ No newline at end of file diff --git a/www/assets/js/moneyorder.js b/www/assets/js/moneyorder.js deleted file mode 100644 index c48ea4d..0000000 --- a/www/assets/js/moneyorder.js +++ /dev/null @@ -1,36 +0,0 @@ -/* - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -$("#app").on("submit", "#moneyorderForm", function (e) { - e.preventDefault(); - verifyMoneyOrder($('#moneyorderserial').val()); - return false; -}); - -function verifyMoneyOrder(serial) { - if (typeof serial != "string" || serial == "" || /^[0-9]{3,8}$/.test(serial) == false) { - app.dialog.alert("Enter a valid Helena Express money order serial number.", "Whoops!"); - return; - } - app.dialog.preloader("Working..."); - apirequest(SETTINGS.apis.moneyorderverify, { - serial: serial - }, function (resp) { - app.dialog.close(); - if (resp.status == "OK") { - app.dialog.alert("Amount: $" + resp.amount - + "
Issued: " + resp.issued_date + " UTC" - + (resp.mo_status == "" ? "" : "
Status: " + resp.mo_status), - "Money Order #" + resp.serial); - } else { - app.dialog.alert(resp.msg, "Error"); - } - }, function (error) { - app.dialog.close(); - app.dialog.alert("Connection or server error. Try again later.", "Whoops!"); - sendErrorReport("Money Order", "Verification"); - }); -} \ No newline at end of file diff --git a/www/index.html b/www/index.html index df81d4b..113432d 100644 --- a/www/index.html +++ b/www/index.html @@ -46,8 +46,6 @@ - - @@ -68,13 +66,9 @@ - - - - diff --git a/www/pages/crypto.html b/www/pages/crypto.html deleted file mode 100644 index d0e8c23..0000000 --- a/www/pages/crypto.html +++ /dev/null @@ -1,67 +0,0 @@ - - -
- - - - -
-
-
-
-
- {{#each slideshow}} -
- -

{{text}}

-
- {{/each}} -
-
-
-
-
-
-
Scan Wallet
-
- -
- - -
-
-
-
-
\ No newline at end of file diff --git a/www/pages/crypto_wallet.html b/www/pages/crypto_wallet.html deleted file mode 100644 index 830fb40..0000000 --- a/www/pages/crypto_wallet.html +++ /dev/null @@ -1,209 +0,0 @@ - - -
- - - - -
- -
- -

This {{currencyname}} wallet contains

-

{{balance}} {{currencyunit}}

-

currently worth

-

{{fiatvalue}}

-
- -
-
-
- -
-
- -
-
-
- -
{{walletaddress}}
- -
- {{attribution}} -
-
- - - - -
\ No newline at end of file diff --git a/www/pages/money.html b/www/pages/money.html deleted file mode 100644 index 8f21de4..0000000 --- a/www/pages/money.html +++ /dev/null @@ -1,42 +0,0 @@ - - -
- - - -
-
-
-
- {{#each pages}} -
-
-
-

-
- {{title}} -
- {{text}} -
-
-
- {{/each}} -
-
-
-
- -
\ No newline at end of file diff --git a/www/pages/moneyorder.html b/www/pages/moneyorder.html deleted file mode 100644 index 91d70b6..0000000 --- a/www/pages/moneyorder.html +++ /dev/null @@ -1,70 +0,0 @@ - - -
- - - - -
-
-
-
-
-
-
How do I purchase a money order?
-
You can buy a money order during any notary or shipping appointment. You can also call us to schedule a visit. We’re available where you are and on your schedule.
- -
How can I pay for my money order?
-
We only accept cash payment for money orders at this time.
- -
How much does a money order cost?
-
You can send money orders up to $500 with Helena Express for a $3 fee ($6 if by appointment).
- -
How can a recipient cash a Helena Express money order?
-
Our money orders can be cashed like a check. Just bring it to your bank or any business offering check cashing services.
-
-
-
-
-
-
Verify Money Order
-
-
- Enter the serial number from the top-right corner of the money order. -
-
-
    -
  • -
    -
    Serial Number
    -
    - - -
    -
    -
  • -
  • -
    Verify
    -
  • -
-
-
-
-
-
-
- -
\ No newline at end of file diff --git a/www/routes.js b/www/routes.js index 5fb9ac1..eb8ba19 100644 --- a/www/routes.js +++ b/www/routes.js @@ -7,8 +7,7 @@ var dynamicPages = [ "notary", "telegram", - "trailer", - "moneyorder" + "trailer" ]; var compiledPages = {}; var pagesToCompile = [ @@ -23,16 +22,12 @@ var pagesToCompile = [ "shop", "shoppingcart_fragment", "rateresult", - "crypto", - "crypto_wallet", "account", "trackresult", "settings", "receipts", "trailer", "kiosk", - "money", - "moneyorder", "locations", "quicksend" ]; @@ -57,82 +52,6 @@ var routes = [ } } }, - { - path: '/crypto', - name: 'crypto', - async: function ( {resolve, reject}) { - resolve({ - content: compiledPages.crypto({ - slideshow: [ - { - image: "assets/images/crypto/slides/intro.svg", - text: "Bitcoin and cryptocurrency can be complicated. We've made it simple. Swipe left for more." - }, - { - image: "assets/images/crypto/slides/vault.svg", - text: "With your Helena Express paper wallet, you can save..." - }, - { - image: "assets/images/crypto/slides/spend.svg", - text: "...or spend, without worrying about hackers..." - }, - { - image: "assets/images/crypto/slides/secure.svg", - text: "...because paper can't be hacked." - }, - { - image: "assets/images/crypto/slides/scantostart.svg", - text: "Scan your paper wallet to get started, or order one in the shop." - } - ] - }) - }, {}); - }, - on: { - pageAfterIn: function () { - app.swiper.destroy("#crypto-intro-swiper"); - app.swiper.create("#crypto-intro-swiper", { - pagination: { - el: "#crypto-intro-swiper-pagination", - type: "bullets", - clickable: true - } - }); - } - } - }, - { - path: '/crypto/:walletaddress/:toaddress', - async: openWalletBalancePage, - name: 'crypto_wallet', - on: { - pageAfterIn: function () { - $("#sendCryptoOpenPopupBtn").click(); - setupReceiveFiatConversion(); - } - } - }, - { - path: '/crypto/:walletaddress/:toaddress/:amount', - async: openWalletBalancePage, - name: 'crypto_wallet', - on: { - pageAfterIn: function () { - $("#sendCryptoOpenPopupBtn").click(); - setupReceiveFiatConversion(); - } - } - }, - { - path: '/crypto/:walletaddress', - async: openWalletBalancePage, - name: 'crypto_wallet', - on: { - pageAfterIn: function () { - setupReceiveFiatConversion(); - } - } - }, { path: '/home', name: 'home', @@ -242,43 +161,6 @@ var routes = [ }, {}); } }, - { - path: '/money', - name: 'money', - async: function ( { resolve, reject }) { - resolve({ - content: compiledPages.money({ - pages: [ - { - title: "Money Orders", - href: "/moneyorder", - icon: "fa-duotone fa-money-check-dollar", - text: "Check and verify a Helena Express money order." - }, - { - title: "Crypto Wallet", - href: "/crypto", - icon: "fa-duotone fa-wallet", - text: "Check your crypto wallet balance and pay people with cryptocurrency." - } - ] - }) - }, {}); - } - }, - { - path: '/moneyorder', - content: compiledPages.moneyorder(), - name: 'moneyorder', - on: { - pageBeforeIn: function () { - dyncontent = getDynamicPageContent("moneyorder"); - if (dyncontent != null) { - $("#moneyorder-dyncontent").html(dyncontent); - } - } - } - }, { path: '/notary', content: compiledPages.notary(), @@ -632,25 +514,6 @@ var routes = [ } } }, -// { -// path: '/labelmaker', -// url: './pages/labelmaker.html', -// name: 'labelmaker', -// on: { -// pageBeforeIn: function () { -// checkIfAccountGoodWithPaymentMethod(function (ok) { -// if (!ok) { -// $("#addPaymentMethodNag").css("display", ""); -// } -// }, function (error) { -// $("#addPaymentMethodNag").css("display", ""); -// }); -// }, -// pageAfterIn: function () { -// initLabelMakerForm(); -// } -// } -// }, { path: '/account', name: 'account', diff --git a/www/settings.js b/www/settings.js index a97d4b2..b2d7983 100644 --- a/www/settings.js +++ b/www/settings.js @@ -42,17 +42,11 @@ var SETTINGS = { // Get receipts linked with account getreceipts: "https://apis.helena.express/v1/account/getreceipts/", getreceipt: "https://apis.helena.express/v1/account/getreceipt/", - // Crypto: check balance and send transactions - walletbalance: "https://apis.helena.express/v1/crypto/walletbalance/", - getutxo: "https://apis.helena.express/v1/crypto/getutxo/", - broadcasttransaction: "https://apis.helena.express/v1/crypto/broadcasttransaction/", - cryptofees: "https://apis.helena.express/v1/crypto/fees/", // Service area map servicearea: "https://apis.helena.express/v1/servicearea/", // Trailer schedule/dates/times/locations trailerschedule: "https://helena.express/mobile/schedule.json", - // Money order verification - moneyorderverify: "https://apis.helena.express/v1/moneyorder/verify/", + // Physical locations locations: "https://apis.helena.express/v1/locations/" }, stripe_pubkey: "pk_test_51J6qFXCa1Fboir5UzPO3LCiMsVNiFP2lq4wR0dEcjJJVzAaJ3uRggDekZPB3qeYpMD3ayIYHKyD5sSn0IFLlEXMW001LqrvGSH",