@coti-io/coti-snap
Version:
COTI Snap - MetaMask Snap for managing confidential tokens and confidential transactions
1 lines • 1.17 MB
JavaScript
(()=>{var e={18:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Mnemonic=void 0;const n=r(6468),s=r(8718),i=r(3318);function a(e){return(1<<e)-1<<8-e&255}function o(e){return(1<<e)-1&255}function c(e,t){(0,s.assertNormalize)("NFKD"),null==t&&(t=i.LangEn.wordlist());const r=t.split(e);(0,s.assertArgument)(r.length%3==0&&r.length>=12&&r.length<=24,"invalid mnemonic length","mnemonic","[ REDACTED ]");const o=new Uint8Array(Math.ceil(11*r.length/8));let c=0;for(let e=0;e<r.length;e++){let n=t.getWordIndex(r[e].normalize("NFKD"));(0,s.assertArgument)(n>=0,`invalid mnemonic word at index ${e}`,"mnemonic","[ REDACTED ]");for(let e=0;e<11;e++)n&1<<10-e&&(o[c>>3]|=1<<7-c%8),c++}const u=32*r.length/3,l=a(r.length/3),h=(0,s.getBytes)((0,n.sha256)(o.slice(0,u/8)))[0]&l;return(0,s.assertArgument)(h===(o[o.length-1]&l),"invalid mnemonic checksum","mnemonic","[ REDACTED ]"),(0,s.hexlify)(o.slice(0,u/8))}function u(e,t){(0,s.assertArgument)(e.length%4==0&&e.length>=16&&e.length<=32,"invalid entropy size","entropy","[ REDACTED ]"),null==t&&(t=i.LangEn.wordlist());const r=[0];let c=11;for(let t=0;t<e.length;t++)c>8?(r[r.length-1]<<=8,r[r.length-1]|=e[t],c-=8):(r[r.length-1]<<=c,r[r.length-1]|=e[t]>>8-c,r.push(e[t]&o(8-c)),c+=3);const u=e.length/4,l=parseInt((0,n.sha256)(e).substring(2,4),16)&a(u);return r[r.length-1]<<=u,r[r.length-1]|=l>>8-u,t.join(r.map(e=>t.getWord(e)))}const l={};class h{phrase;password;wordlist;entropy;constructor(e,t,r,n,a){null==n&&(n=""),null==a&&(a=i.LangEn.wordlist()),(0,s.assertPrivate)(e,l,"Mnemonic"),(0,s.defineProperties)(this,{phrase:r,password:n,wordlist:a,entropy:t})}computeSeed(){const e=(0,s.toUtf8Bytes)("mnemonic"+this.password,"NFKD");return(0,n.pbkdf2)((0,s.toUtf8Bytes)(this.phrase,"NFKD"),e,2048,64,"sha512")}static fromPhrase(e,t,r){const n=c(e,r);return e=u((0,s.getBytes)(n),r),new h(l,n,e,t,r)}static fromEntropy(e,t,r){const n=(0,s.getBytes)(e,"entropy"),i=u(n,r);return new h(l,(0,s.hexlify)(n),i,t,r)}static entropyToPhrase(e,t){return u((0,s.getBytes)(e,"entropy"),t)}static phraseToEntropy(e,t){return c(e,t)}static isValidMnemonic(e,t){try{return c(e,t),!0}catch(e){}return!1}}t.Mnemonic=h},24:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.JsonRpcProvider=t.JsonRpcApiPollingProvider=t.JsonRpcApiProvider=t.JsonRpcSigner=void 0;const n=r(333),s=r(6107),i=r(7477),a=r(203),o=r(8718),c=r(3633),u=r(5774),l=r(4391),h=r(5263),d=r(5737),f="bigint,boolean,function,number,string,symbol".split(/,/g);function p(e){if(null==e||f.indexOf(typeof e)>=0)return e;if("function"==typeof e.getAddress)return e;if(Array.isArray(e))return e.map(p);if("object"==typeof e)return Object.keys(e).reduce((t,r)=>(t[r]=e[r],t),{});throw new Error(`should not happen: ${e} (${typeof e})`)}function g(e){return new Promise(t=>{setTimeout(t,e)})}function y(e){return e?e.toLowerCase():e}function m(e){return e&&"number"==typeof e.pollingInterval}const b={polling:!1,staticNetwork:null,batchStallTime:10,batchMaxSize:1<<20,batchMaxCount:100,cacheTimeout:250,pollingInterval:4e3};class v extends u.AbstractSigner{address;constructor(e,t){super(e),t=(0,s.getAddress)(t),(0,o.defineProperties)(this,{address:t})}connect(e){(0,o.assert)(!1,"cannot reconnect JsonRpcSigner","UNSUPPORTED_OPERATION",{operation:"signer.connect"})}async getAddress(){return this.address}async populateTransaction(e){return await this.populateCall(e)}async sendUncheckedTransaction(e){const t=p(e),r=[];if(t.from){const n=t.from;r.push((async()=>{const r=await(0,s.resolveAddress)(n,this.provider);(0,o.assertArgument)(null!=r&&r.toLowerCase()===this.address.toLowerCase(),"from address mismatch","transaction",e),t.from=r})())}else t.from=this.address;if(null==t.gasLimit&&r.push((async()=>{t.gasLimit=await this.provider.estimateGas({...t,from:this.address})})()),null!=t.to){const e=t.to;r.push((async()=>{t.to=await(0,s.resolveAddress)(e,this.provider)})())}r.length&&await Promise.all(r);const n=this.provider.getRpcTransaction(t);return this.provider.send("eth_sendTransaction",[n])}async sendTransaction(e){const t=await this.provider.getBlockNumber(),r=await this.sendUncheckedTransaction(e);return await new Promise((e,n)=>{const s=[1e3,100];let i=0;const a=async()=>{try{const n=await this.provider.getTransaction(r);if(null!=n)return void e(n.replaceableTransaction(t))}catch(e){if((0,o.isError)(e,"CANCELLED")||(0,o.isError)(e,"BAD_DATA")||(0,o.isError)(e,"NETWORK_ERROR")||(0,o.isError)(e,"UNSUPPORTED_OPERATION"))return null==e.info&&(e.info={}),e.info.sendTransactionHash=r,void n(e);if((0,o.isError)(e,"INVALID_ARGUMENT")&&(i++,null==e.info&&(e.info={}),e.info.sendTransactionHash=r,i>10))return void n(e);this.provider.emit("error",(0,o.makeError)("failed to fetch transation after sending (will try again)","UNKNOWN_ERROR",{error:e}))}this.provider._setTimeout(()=>{a()},s.pop()||4e3)};a()})}async signTransaction(e){const t=p(e);if(t.from){const r=await(0,s.resolveAddress)(t.from,this.provider);(0,o.assertArgument)(null!=r&&r.toLowerCase()===this.address.toLowerCase(),"from address mismatch","transaction",e),t.from=r}else t.from=this.address;const r=this.provider.getRpcTransaction(t);return await this.provider.send("eth_signTransaction",[r])}async signMessage(e){const t="string"==typeof e?(0,o.toUtf8Bytes)(e):e;return await this.provider.send("personal_sign",[(0,o.hexlify)(t),this.address.toLowerCase()])}async signTypedData(e,t,r){const n=p(r),a=await i.TypedDataEncoder.resolveNames(e,t,n,async e=>{const t=await(0,s.resolveAddress)(e);return(0,o.assertArgument)(null!=t,"TypedData does not support null address","value",e),t});return await this.provider.send("eth_signTypedData_v4",[this.address.toLowerCase(),JSON.stringify(i.TypedDataEncoder.getPayload(a.domain,t,a.value))])}async unlock(e){return this.provider.send("personal_unlockAccount",[this.address.toLowerCase(),e,null])}async _legacySignMessage(e){const t="string"==typeof e?(0,o.toUtf8Bytes)(e):e;return await this.provider.send("eth_sign",[this.address.toLowerCase(),(0,o.hexlify)(t)])}}t.JsonRpcSigner=v;class w extends c.AbstractProvider{#e;#t;#r;#n;#s;#i;#a;#o(){if(this.#n)return;const e=1===this._getOption("batchMaxCount")?0:this._getOption("batchStallTime");this.#n=setTimeout(()=>{this.#n=null;const e=this.#r;for(this.#r=[];e.length;){const t=[e.shift()];for(;e.length&&t.length!==this.#e.batchMaxCount;){t.push(e.shift());if(JSON.stringify(t.map(e=>e.payload)).length>this.#e.batchMaxSize){e.unshift(t.pop());break}}(async()=>{const e=1===t.length?t[0].payload:t.map(e=>e.payload);this.emit("debug",{action:"sendRpcPayload",payload:e});try{const r=await this._send(e);this.emit("debug",{action:"receiveRpcResult",result:r});for(const{resolve:e,reject:n,payload:s}of t){if(this.destroyed){n((0,o.makeError)("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:s.method}));continue}const t=r.filter(e=>e.id===s.id)[0];if(null==t){const e=(0,o.makeError)("missing response for request","BAD_DATA",{value:r,info:{payload:s}});this.emit("error",e),n(e);continue}"error"in t?n(this.getRpcError(s,t)):e(t.result)}}catch(e){this.emit("debug",{action:"receiveRpcError",error:e});for(const{reject:r}of t)r(e)}})()}},e)}constructor(e,t){super(e,t),this.#t=1,this.#e=Object.assign({},b,t||{}),this.#r=[],this.#n=null,this.#i=null,this.#a=null;{let e=null;const t=new Promise(t=>{e=t});this.#s={promise:t,resolve:e}}const r=this._getOption("staticNetwork");"boolean"==typeof r?((0,o.assertArgument)(!r||"any"!==e,"staticNetwork cannot be used on special network 'any'","options",t),r&&null!=e&&(this.#i=l.Network.from(e))):r&&((0,o.assertArgument)(null==e||r.matches(e),"staticNetwork MUST match network object","options",t),this.#i=r)}_getOption(e){return this.#e[e]}get _network(){return(0,o.assert)(this.#i,"network is not available yet","NETWORK_ERROR"),this.#i}async _perform(e){if("call"===e.method||"estimateGas"===e.method){let t=e.transaction;if(t&&null!=t.type&&(0,o.getBigInt)(t.type)&&null==t.maxFeePerGas&&null==t.maxPriorityFeePerGas){const r=await this.getFeeData();null==r.maxFeePerGas&&null==r.maxPriorityFeePerGas&&(e=Object.assign({},e,{transaction:Object.assign({},t,{type:void 0})}))}}const t=this.getRpcRequest(e);return null!=t?await this.send(t.method,t.args):super._perform(e)}async _detectNetwork(){const e=this._getOption("staticNetwork");if(e){if(!0!==e)return e;if(this.#i)return this.#i}return this.#a?await this.#a:this.ready?(this.#a=(async()=>{try{const e=l.Network.from((0,o.getBigInt)(await this.send("eth_chainId",[])));return this.#a=null,e}catch(e){throw this.#a=null,e}})(),await this.#a):(this.#a=(async()=>{const e={id:this.#t++,method:"eth_chainId",params:[],jsonrpc:"2.0"};let t;this.emit("debug",{action:"sendRpcPayload",payload:e});try{t=(await this._send(e))[0],this.#a=null}catch(e){throw this.#a=null,this.emit("debug",{action:"receiveRpcError",error:e}),e}if(this.emit("debug",{action:"receiveRpcResult",result:t}),"result"in t)return l.Network.from((0,o.getBigInt)(t.result));throw this.getRpcError(e,t)})(),await this.#a)}_start(){null!=this.#s&&null!=this.#s.resolve&&(this.#s.resolve(),this.#s=null,(async()=>{for(;null==this.#i&&!this.destroyed;)try{this.#i=await this._detectNetwork()}catch(e){if(this.destroyed)break;console.log("JsonRpcProvider failed to detect network and cannot start up; retry in 1s (perhaps the URL is wrong or the node is not started)"),this.emit("error",(0,o.makeError)("failed to bootstrap network detection","NETWORK_ERROR",{event:"initial-network-discovery",info:{error:e}})),await g(1e3)}this.#o()})())}async _waitUntilReady(){if(null!=this.#s)return await this.#s.promise}_getSubscriber(e){return"pending"===e.type?new h.FilterIdPendingSubscriber(this):"event"===e.type?this._getOption("polling")?new d.PollingEventSubscriber(this,e.filter):new h.FilterIdEventSubscriber(this,e.filter):"orphan"===e.type&&"drop-log"===e.filter.orphan?new c.UnmanagedSubscriber("orphan"):super._getSubscriber(e)}get ready(){return null==this.#s}getRpcTransaction(e){const t={};return["chainId","gasLimit","gasPrice","type","maxFeePerGas","maxPriorityFeePerGas","nonce","value"].forEach(r=>{if(null==e[r])return;let n=r;"gasLimit"===r&&(n="gas"),t[n]=(0,o.toQuantity)((0,o.getBigInt)(e[r],`tx.${r}`))}),["from","to","data"].forEach(r=>{null!=e[r]&&(t[r]=(0,o.hexlify)(e[r]))}),e.accessList&&(t.accessList=(0,a.accessListify)(e.accessList)),e.blobVersionedHashes&&(t.blobVersionedHashes=e.blobVersionedHashes.map(e=>e.toLowerCase())),e.authorizationList&&(t.authorizationList=e.authorizationList.map(e=>{const t=(0,a.authorizationify)(e);return{address:t.address,nonce:(0,o.toQuantity)(t.nonce),chainId:(0,o.toQuantity)(t.chainId),yParity:(0,o.toQuantity)(t.signature.yParity),r:(0,o.toQuantity)(t.signature.r),s:(0,o.toQuantity)(t.signature.s)}})),t}getRpcRequest(e){switch(e.method){case"chainId":return{method:"eth_chainId",args:[]};case"getBlockNumber":return{method:"eth_blockNumber",args:[]};case"getGasPrice":return{method:"eth_gasPrice",args:[]};case"getPriorityFee":return{method:"eth_maxPriorityFeePerGas",args:[]};case"getBalance":return{method:"eth_getBalance",args:[y(e.address),e.blockTag]};case"getTransactionCount":return{method:"eth_getTransactionCount",args:[y(e.address),e.blockTag]};case"getCode":return{method:"eth_getCode",args:[y(e.address),e.blockTag]};case"getStorage":return{method:"eth_getStorageAt",args:[y(e.address),"0x"+e.position.toString(16),e.blockTag]};case"broadcastTransaction":return{method:"eth_sendRawTransaction",args:[e.signedTransaction]};case"getBlock":if("blockTag"in e)return{method:"eth_getBlockByNumber",args:[e.blockTag,!!e.includeTransactions]};if("blockHash"in e)return{method:"eth_getBlockByHash",args:[e.blockHash,!!e.includeTransactions]};break;case"getTransaction":return{method:"eth_getTransactionByHash",args:[e.hash]};case"getTransactionReceipt":return{method:"eth_getTransactionReceipt",args:[e.hash]};case"call":return{method:"eth_call",args:[this.getRpcTransaction(e.transaction),e.blockTag]};case"estimateGas":return{method:"eth_estimateGas",args:[this.getRpcTransaction(e.transaction)]};case"getLogs":return e.filter&&null!=e.filter.address&&(Array.isArray(e.filter.address)?e.filter.address=e.filter.address.map(y):e.filter.address=y(e.filter.address)),{method:"eth_getLogs",args:[e.filter]}}return null}getRpcError(e,t){const{method:r}=e,{error:s}=t;if("eth_estimateGas"===r&&s.message){const t=s.message;if(!t.match(/revert/i)&&t.match(/insufficient funds/i))return(0,o.makeError)("insufficient funds","INSUFFICIENT_FUNDS",{transaction:e.params[0],info:{payload:e,error:s}});if(t.match(/nonce/i)&&t.match(/too low/i))return(0,o.makeError)("nonce has already been used","NONCE_EXPIRED",{transaction:e.params[0],info:{payload:e,error:s}})}if("eth_call"===r||"eth_estimateGas"===r){const t=E(s),i=n.AbiCoder.getBuiltinCallException("eth_call"===r?"call":"estimateGas",e.params[0],t?t.data:null);return i.info={error:s,payload:e},i}const i=JSON.stringify(function(e){const t=[];return C(e,t),t}(s));if("string"==typeof s.message&&s.message.match(/user denied|ethers-user-denied/i)){const t={eth_sign:"signMessage",personal_sign:"signMessage",eth_signTypedData_v4:"signTypedData",eth_signTransaction:"signTransaction",eth_sendTransaction:"sendTransaction",eth_requestAccounts:"requestAccess",wallet_requestAccounts:"requestAccess"};return(0,o.makeError)("user rejected action","ACTION_REJECTED",{action:t[r]||"unknown",reason:"rejected",info:{payload:e,error:s}})}if("eth_sendRawTransaction"===r||"eth_sendTransaction"===r){const t=e.params[0];if(i.match(/insufficient funds|base fee exceeds gas limit/i))return(0,o.makeError)("insufficient funds for intrinsic transaction cost","INSUFFICIENT_FUNDS",{transaction:t,info:{error:s}});if(i.match(/nonce/i)&&i.match(/too low/i))return(0,o.makeError)("nonce has already been used","NONCE_EXPIRED",{transaction:t,info:{error:s}});if(i.match(/replacement transaction/i)&&i.match(/underpriced/i))return(0,o.makeError)("replacement fee too low","REPLACEMENT_UNDERPRICED",{transaction:t,info:{error:s}});if(i.match(/only replay-protected/i))return(0,o.makeError)("legacy pre-eip-155 transactions not supported","UNSUPPORTED_OPERATION",{operation:r,info:{transaction:t,info:{error:s}}})}let a=!!i.match(/the method .* does not exist/i);return a||s&&s.details&&s.details.startsWith("Unauthorized method:")&&(a=!0),a?(0,o.makeError)("unsupported operation","UNSUPPORTED_OPERATION",{operation:e.method,info:{error:s,payload:e}}):(0,o.makeError)("could not coalesce error","UNKNOWN_ERROR",{error:s,payload:e})}send(e,t){if(this.destroyed)return Promise.reject((0,o.makeError)("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:e}));const r=this.#t++,n=new Promise((n,s)=>{this.#r.push({resolve:n,reject:s,payload:{method:e,params:t,id:r,jsonrpc:"2.0"}})});return this.#o(),n}async getSigner(e){null==e&&(e=0);const t=this.send("eth_accounts",[]);if("number"==typeof e){const r=await t;if(e>=r.length)throw new Error("no such account");return new v(this,r[e])}const{accounts:r}=await(0,o.resolveProperties)({network:this.getNetwork(),accounts:t});e=(0,s.getAddress)(e);for(const t of r)if((0,s.getAddress)(t)===e)return new v(this,e);throw new Error("invalid account")}async listAccounts(){return(await this.send("eth_accounts",[])).map(e=>new v(this,e))}destroy(){this.#n&&(clearTimeout(this.#n),this.#n=null);for(const{payload:e,reject:t}of this.#r)t((0,o.makeError)("provider destroyed; cancelled request","UNSUPPORTED_OPERATION",{operation:e.method}));this.#r=[],super.destroy()}}t.JsonRpcApiProvider=w;class A extends w{#c;constructor(e,t){super(e,t);let r=this._getOption("pollingInterval");null==r&&(r=b.pollingInterval),this.#c=r}_getSubscriber(e){const t=super._getSubscriber(e);return m(t)&&(t.pollingInterval=this.#c),t}get pollingInterval(){return this.#c}set pollingInterval(e){if(!Number.isInteger(e)||e<0)throw new Error("invalid interval");this.#c=e,this._forEachSubscriber(e=>{m(e)&&(e.pollingInterval=this.#c)})}}t.JsonRpcApiPollingProvider=A;function E(e){if(null==e)return null;if("string"==typeof e.message&&e.message.match(/revert/i)&&(0,o.isHexString)(e.data))return{message:e.message,data:e.data};if("object"==typeof e){for(const t in e){const r=E(e[t]);if(r)return r}return null}if("string"==typeof e)try{return E(JSON.parse(e))}catch(e){}return null}function C(e,t){if(null!=e){if("string"==typeof e.message&&t.push(e.message),"object"==typeof e)for(const r in e)C(e[r],t);if("string"==typeof e)try{return C(JSON.parse(e),t)}catch(e){}}}t.JsonRpcProvider=class extends A{#u;constructor(e,t,r){null==e&&(e="http://localhost:8545"),super(t,r),this.#u="string"==typeof e?new o.FetchRequest(e):e.clone()}_getConnection(){return this.#u.clone()}async send(e,t){return await this._start(),await super.send(e,t)}async _send(e){const t=this._getConnection();t.body=JSON.stringify(e),t.setHeader("content-type","application/json");const r=await t.send();r.assertOk();let n=r.bodyJson;return Array.isArray(n)||(n=[n]),n}}},81:(e,t,r)=>{var n=r(4643);r(9679),r(8550),(e.exports=n.hmac=n.hmac||{}).create=function(){var e=null,t=null,r=null,s=null,i={start:function(i,a){if(null!==i)if("string"==typeof i){if(!((i=i.toLowerCase())in n.md.algorithms))throw new Error('Unknown hash algorithm "'+i+'"');t=n.md.algorithms[i].create()}else t=i;if(null===a)a=e;else{if("string"==typeof a)a=n.util.createBuffer(a);else if(n.util.isArray(a)){var o=a;a=n.util.createBuffer();for(var c=0;c<o.length;++c)a.putByte(o[c])}var u=a.length();u>t.blockLength&&(t.start(),t.update(a.bytes()),a=t.digest()),r=n.util.createBuffer(),s=n.util.createBuffer(),u=a.length();for(c=0;c<u;++c){o=a.at(c);r.putByte(54^o),s.putByte(92^o)}if(u<t.blockLength)for(o=t.blockLength-u,c=0;c<o;++c)r.putByte(54),s.putByte(92);e=a,r=r.bytes(),s=s.bytes()}t.start(),t.update(r)},update:function(e){t.update(e)},getMac:function(){var e=t.digest().bytes();return t.start(),t.update(s),t.update(e),t.digest()}};return i.digest=i.getMac,i}},121:(e,t,r)=>{var n,s=r(4643);e.exports=s.jsbn=s.jsbn||{};function i(e,t,r){this.data=[],null!=e&&("number"==typeof e?this.fromNumber(e,t,r):null==t&&"string"!=typeof e?this.fromString(e,256):this.fromString(e,t))}function a(){return new i(null)}function o(e,t,r,n,s,i){for(var a=16383&t,o=t>>14;--i>=0;){var c=16383&this.data[e],u=this.data[e++]>>14,l=o*c+u*a;s=((c=a*c+((16383&l)<<14)+r.data[n]+s)>>28)+(l>>14)+o*u,r.data[n++]=268435455&c}return s}s.jsbn.BigInteger=i,"undefined"==typeof navigator?(i.prototype.am=o,n=28):"Microsoft Internet Explorer"==navigator.appName?(i.prototype.am=function(e,t,r,n,s,i){for(var a=32767&t,o=t>>15;--i>=0;){var c=32767&this.data[e],u=this.data[e++]>>15,l=o*c+u*a;s=((c=a*c+((32767&l)<<15)+r.data[n]+(1073741823&s))>>>30)+(l>>>15)+o*u+(s>>>30),r.data[n++]=1073741823&c}return s},n=30):"Netscape"!=navigator.appName?(i.prototype.am=function(e,t,r,n,s,i){for(;--i>=0;){var a=t*this.data[e++]+r.data[n]+s;s=Math.floor(a/67108864),r.data[n++]=67108863&a}return s},n=26):(i.prototype.am=o,n=28),i.prototype.DB=n,i.prototype.DM=(1<<n)-1,i.prototype.DV=1<<n;i.prototype.FV=Math.pow(2,52),i.prototype.F1=52-n,i.prototype.F2=2*n-52;var c,u,l=new Array;for(c="0".charCodeAt(0),u=0;u<=9;++u)l[c++]=u;for(c="a".charCodeAt(0),u=10;u<36;++u)l[c++]=u;for(c="A".charCodeAt(0),u=10;u<36;++u)l[c++]=u;function h(e){return"0123456789abcdefghijklmnopqrstuvwxyz".charAt(e)}function d(e,t){var r=l[e.charCodeAt(t)];return null==r?-1:r}function f(e){var t=a();return t.fromInt(e),t}function p(e){var t,r=1;return 0!=(t=e>>>16)&&(e=t,r+=16),0!=(t=e>>8)&&(e=t,r+=8),0!=(t=e>>4)&&(e=t,r+=4),0!=(t=e>>2)&&(e=t,r+=2),0!=(t=e>>1)&&(e=t,r+=1),r}function g(e){this.m=e}function y(e){this.m=e,this.mp=e.invDigit(),this.mpl=32767&this.mp,this.mph=this.mp>>15,this.um=(1<<e.DB-15)-1,this.mt2=2*e.t}function m(e,t){return e&t}function b(e,t){return e|t}function v(e,t){return e^t}function w(e,t){return e&~t}function A(e){if(0==e)return-1;var t=0;return 65535&e||(e>>=16,t+=16),255&e||(e>>=8,t+=8),15&e||(e>>=4,t+=4),3&e||(e>>=2,t+=2),1&e||++t,t}function E(e){for(var t=0;0!=e;)e&=e-1,++t;return t}function C(){}function T(e){return e}function S(e){this.r2=a(),this.q3=a(),i.ONE.dlShiftTo(2*e.t,this.r2),this.mu=this.r2.divide(e),this.m=e}g.prototype.convert=function(e){return e.s<0||e.compareTo(this.m)>=0?e.mod(this.m):e},g.prototype.revert=function(e){return e},g.prototype.reduce=function(e){e.divRemTo(this.m,null,e)},g.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r),this.reduce(r)},g.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},y.prototype.convert=function(e){var t=a();return e.abs().dlShiftTo(this.m.t,t),t.divRemTo(this.m,null,t),e.s<0&&t.compareTo(i.ZERO)>0&&this.m.subTo(t,t),t},y.prototype.revert=function(e){var t=a();return e.copyTo(t),this.reduce(t),t},y.prototype.reduce=function(e){for(;e.t<=this.mt2;)e.data[e.t++]=0;for(var t=0;t<this.m.t;++t){var r=32767&e.data[t],n=r*this.mpl+((r*this.mph+(e.data[t]>>15)*this.mpl&this.um)<<15)&e.DM;for(r=t+this.m.t,e.data[r]+=this.m.am(0,n,e,t,0,this.m.t);e.data[r]>=e.DV;)e.data[r]-=e.DV,e.data[++r]++}e.clamp(),e.drShiftTo(this.m.t,e),e.compareTo(this.m)>=0&&e.subTo(this.m,e)},y.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r),this.reduce(r)},y.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)},i.prototype.copyTo=function(e){for(var t=this.t-1;t>=0;--t)e.data[t]=this.data[t];e.t=this.t,e.s=this.s},i.prototype.fromInt=function(e){this.t=1,this.s=e<0?-1:0,e>0?this.data[0]=e:e<-1?this.data[0]=e+this.DV:this.t=0},i.prototype.fromString=function(e,t){var r;if(16==t)r=4;else if(8==t)r=3;else if(256==t)r=8;else if(2==t)r=1;else if(32==t)r=5;else{if(4!=t)return void this.fromRadix(e,t);r=2}this.t=0,this.s=0;for(var n=e.length,s=!1,a=0;--n>=0;){var o=8==r?255&e[n]:d(e,n);o<0?"-"==e.charAt(n)&&(s=!0):(s=!1,0==a?this.data[this.t++]=o:a+r>this.DB?(this.data[this.t-1]|=(o&(1<<this.DB-a)-1)<<a,this.data[this.t++]=o>>this.DB-a):this.data[this.t-1]|=o<<a,(a+=r)>=this.DB&&(a-=this.DB))}8==r&&128&e[0]&&(this.s=-1,a>0&&(this.data[this.t-1]|=(1<<this.DB-a)-1<<a)),this.clamp(),s&&i.ZERO.subTo(this,this)},i.prototype.clamp=function(){for(var e=this.s&this.DM;this.t>0&&this.data[this.t-1]==e;)--this.t},i.prototype.dlShiftTo=function(e,t){var r;for(r=this.t-1;r>=0;--r)t.data[r+e]=this.data[r];for(r=e-1;r>=0;--r)t.data[r]=0;t.t=this.t+e,t.s=this.s},i.prototype.drShiftTo=function(e,t){for(var r=e;r<this.t;++r)t.data[r-e]=this.data[r];t.t=Math.max(this.t-e,0),t.s=this.s},i.prototype.lShiftTo=function(e,t){var r,n=e%this.DB,s=this.DB-n,i=(1<<s)-1,a=Math.floor(e/this.DB),o=this.s<<n&this.DM;for(r=this.t-1;r>=0;--r)t.data[r+a+1]=this.data[r]>>s|o,o=(this.data[r]&i)<<n;for(r=a-1;r>=0;--r)t.data[r]=0;t.data[a]=o,t.t=this.t+a+1,t.s=this.s,t.clamp()},i.prototype.rShiftTo=function(e,t){t.s=this.s;var r=Math.floor(e/this.DB);if(r>=this.t)t.t=0;else{var n=e%this.DB,s=this.DB-n,i=(1<<n)-1;t.data[0]=this.data[r]>>n;for(var a=r+1;a<this.t;++a)t.data[a-r-1]|=(this.data[a]&i)<<s,t.data[a-r]=this.data[a]>>n;n>0&&(t.data[this.t-r-1]|=(this.s&i)<<s),t.t=this.t-r,t.clamp()}},i.prototype.subTo=function(e,t){for(var r=0,n=0,s=Math.min(e.t,this.t);r<s;)n+=this.data[r]-e.data[r],t.data[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n-=e.s;r<this.t;)n+=this.data[r],t.data[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n-=e.data[r],t.data[r++]=n&this.DM,n>>=this.DB;n-=e.s}t.s=n<0?-1:0,n<-1?t.data[r++]=this.DV+n:n>0&&(t.data[r++]=n),t.t=r,t.clamp()},i.prototype.multiplyTo=function(e,t){var r=this.abs(),n=e.abs(),s=r.t;for(t.t=s+n.t;--s>=0;)t.data[s]=0;for(s=0;s<n.t;++s)t.data[s+r.t]=r.am(0,n.data[s],t,s,0,r.t);t.s=0,t.clamp(),this.s!=e.s&&i.ZERO.subTo(t,t)},i.prototype.squareTo=function(e){for(var t=this.abs(),r=e.t=2*t.t;--r>=0;)e.data[r]=0;for(r=0;r<t.t-1;++r){var n=t.am(r,t.data[r],e,2*r,0,1);(e.data[r+t.t]+=t.am(r+1,2*t.data[r],e,2*r+1,n,t.t-r-1))>=t.DV&&(e.data[r+t.t]-=t.DV,e.data[r+t.t+1]=1)}e.t>0&&(e.data[e.t-1]+=t.am(r,t.data[r],e,2*r,0,1)),e.s=0,e.clamp()},i.prototype.divRemTo=function(e,t,r){var n=e.abs();if(!(n.t<=0)){var s=this.abs();if(s.t<n.t)return null!=t&&t.fromInt(0),void(null!=r&&this.copyTo(r));null==r&&(r=a());var o=a(),c=this.s,u=e.s,l=this.DB-p(n.data[n.t-1]);l>0?(n.lShiftTo(l,o),s.lShiftTo(l,r)):(n.copyTo(o),s.copyTo(r));var h=o.t,d=o.data[h-1];if(0!=d){var f=d*(1<<this.F1)+(h>1?o.data[h-2]>>this.F2:0),g=this.FV/f,y=(1<<this.F1)/f,m=1<<this.F2,b=r.t,v=b-h,w=null==t?a():t;for(o.dlShiftTo(v,w),r.compareTo(w)>=0&&(r.data[r.t++]=1,r.subTo(w,r)),i.ONE.dlShiftTo(h,w),w.subTo(o,o);o.t<h;)o.data[o.t++]=0;for(;--v>=0;){var A=r.data[--b]==d?this.DM:Math.floor(r.data[b]*g+(r.data[b-1]+m)*y);if((r.data[b]+=o.am(0,A,r,v,0,h))<A)for(o.dlShiftTo(v,w),r.subTo(w,r);r.data[b]<--A;)r.subTo(w,r)}null!=t&&(r.drShiftTo(h,t),c!=u&&i.ZERO.subTo(t,t)),r.t=h,r.clamp(),l>0&&r.rShiftTo(l,r),c<0&&i.ZERO.subTo(r,r)}}},i.prototype.invDigit=function(){if(this.t<1)return 0;var e=this.data[0];if(!(1&e))return 0;var t=3&e;return(t=(t=(t=(t=t*(2-(15&e)*t)&15)*(2-(255&e)*t)&255)*(2-((65535&e)*t&65535))&65535)*(2-e*t%this.DV)%this.DV)>0?this.DV-t:-t},i.prototype.isEven=function(){return 0==(this.t>0?1&this.data[0]:this.s)},i.prototype.exp=function(e,t){if(e>4294967295||e<1)return i.ONE;var r=a(),n=a(),s=t.convert(this),o=p(e)-1;for(s.copyTo(r);--o>=0;)if(t.sqrTo(r,n),(e&1<<o)>0)t.mulTo(n,s,r);else{var c=r;r=n,n=c}return t.revert(r)},i.prototype.toString=function(e){if(this.s<0)return"-"+this.negate().toString(e);var t;if(16==e)t=4;else if(8==e)t=3;else if(2==e)t=1;else if(32==e)t=5;else{if(4!=e)return this.toRadix(e);t=2}var r,n=(1<<t)-1,s=!1,i="",a=this.t,o=this.DB-a*this.DB%t;if(a-- >0)for(o<this.DB&&(r=this.data[a]>>o)>0&&(s=!0,i=h(r));a>=0;)o<t?(r=(this.data[a]&(1<<o)-1)<<t-o,r|=this.data[--a]>>(o+=this.DB-t)):(r=this.data[a]>>(o-=t)&n,o<=0&&(o+=this.DB,--a)),r>0&&(s=!0),s&&(i+=h(r));return s?i:"0"},i.prototype.negate=function(){var e=a();return i.ZERO.subTo(this,e),e},i.prototype.abs=function(){return this.s<0?this.negate():this},i.prototype.compareTo=function(e){var t=this.s-e.s;if(0!=t)return t;var r=this.t;if(0!=(t=r-e.t))return this.s<0?-t:t;for(;--r>=0;)if(0!=(t=this.data[r]-e.data[r]))return t;return 0},i.prototype.bitLength=function(){return this.t<=0?0:this.DB*(this.t-1)+p(this.data[this.t-1]^this.s&this.DM)},i.prototype.mod=function(e){var t=a();return this.abs().divRemTo(e,null,t),this.s<0&&t.compareTo(i.ZERO)>0&&e.subTo(t,t),t},i.prototype.modPowInt=function(e,t){var r;return r=e<256||t.isEven()?new g(t):new y(t),this.exp(e,r)},i.ZERO=f(0),i.ONE=f(1),C.prototype.convert=T,C.prototype.revert=T,C.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r)},C.prototype.sqrTo=function(e,t){e.squareTo(t)},S.prototype.convert=function(e){if(e.s<0||e.t>2*this.m.t)return e.mod(this.m);if(e.compareTo(this.m)<0)return e;var t=a();return e.copyTo(t),this.reduce(t),t},S.prototype.revert=function(e){return e},S.prototype.reduce=function(e){for(e.drShiftTo(this.m.t-1,this.r2),e.t>this.m.t+1&&(e.t=this.m.t+1,e.clamp()),this.mu.multiplyUpperTo(this.r2,this.m.t+1,this.q3),this.m.multiplyLowerTo(this.q3,this.m.t+1,this.r2);e.compareTo(this.r2)<0;)e.dAddOffset(1,this.m.t+1);for(e.subTo(this.r2,e);e.compareTo(this.m)>=0;)e.subTo(this.m,e)},S.prototype.mulTo=function(e,t,r){e.multiplyTo(t,r),this.reduce(r)},S.prototype.sqrTo=function(e,t){e.squareTo(t),this.reduce(t)};var B=[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],P=(1<<26)/B[B.length-1];i.prototype.chunkSize=function(e){return Math.floor(Math.LN2*this.DB/Math.log(e))},i.prototype.toRadix=function(e){if(null==e&&(e=10),0==this.signum()||e<2||e>36)return"0";var t=this.chunkSize(e),r=Math.pow(e,t),n=f(r),s=a(),i=a(),o="";for(this.divRemTo(n,s,i);s.signum()>0;)o=(r+i.intValue()).toString(e).substr(1)+o,s.divRemTo(n,s,i);return i.intValue().toString(e)+o},i.prototype.fromRadix=function(e,t){this.fromInt(0),null==t&&(t=10);for(var r=this.chunkSize(t),n=Math.pow(t,r),s=!1,a=0,o=0,c=0;c<e.length;++c){var u=d(e,c);u<0?"-"==e.charAt(c)&&0==this.signum()&&(s=!0):(o=t*o+u,++a>=r&&(this.dMultiply(n),this.dAddOffset(o,0),a=0,o=0))}a>0&&(this.dMultiply(Math.pow(t,a)),this.dAddOffset(o,0)),s&&i.ZERO.subTo(this,this)},i.prototype.fromNumber=function(e,t,r){if("number"==typeof t)if(e<2)this.fromInt(1);else for(this.fromNumber(e,r),this.testBit(e-1)||this.bitwiseTo(i.ONE.shiftLeft(e-1),b,this),this.isEven()&&this.dAddOffset(1,0);!this.isProbablePrime(t);)this.dAddOffset(2,0),this.bitLength()>e&&this.subTo(i.ONE.shiftLeft(e-1),this);else{var n=new Array,s=7&e;n.length=1+(e>>3),t.nextBytes(n),s>0?n[0]&=(1<<s)-1:n[0]=0,this.fromString(n,256)}},i.prototype.bitwiseTo=function(e,t,r){var n,s,i=Math.min(e.t,this.t);for(n=0;n<i;++n)r.data[n]=t(this.data[n],e.data[n]);if(e.t<this.t){for(s=e.s&this.DM,n=i;n<this.t;++n)r.data[n]=t(this.data[n],s);r.t=this.t}else{for(s=this.s&this.DM,n=i;n<e.t;++n)r.data[n]=t(s,e.data[n]);r.t=e.t}r.s=t(this.s,e.s),r.clamp()},i.prototype.changeBit=function(e,t){var r=i.ONE.shiftLeft(e);return this.bitwiseTo(r,t,r),r},i.prototype.addTo=function(e,t){for(var r=0,n=0,s=Math.min(e.t,this.t);r<s;)n+=this.data[r]+e.data[r],t.data[r++]=n&this.DM,n>>=this.DB;if(e.t<this.t){for(n+=e.s;r<this.t;)n+=this.data[r],t.data[r++]=n&this.DM,n>>=this.DB;n+=this.s}else{for(n+=this.s;r<e.t;)n+=e.data[r],t.data[r++]=n&this.DM,n>>=this.DB;n+=e.s}t.s=n<0?-1:0,n>0?t.data[r++]=n:n<-1&&(t.data[r++]=this.DV+n),t.t=r,t.clamp()},i.prototype.dMultiply=function(e){this.data[this.t]=this.am(0,e-1,this,0,0,this.t),++this.t,this.clamp()},i.prototype.dAddOffset=function(e,t){if(0!=e){for(;this.t<=t;)this.data[this.t++]=0;for(this.data[t]+=e;this.data[t]>=this.DV;)this.data[t]-=this.DV,++t>=this.t&&(this.data[this.t++]=0),++this.data[t]}},i.prototype.multiplyLowerTo=function(e,t,r){var n,s=Math.min(this.t+e.t,t);for(r.s=0,r.t=s;s>0;)r.data[--s]=0;for(n=r.t-this.t;s<n;++s)r.data[s+this.t]=this.am(0,e.data[s],r,s,0,this.t);for(n=Math.min(e.t,t);s<n;++s)this.am(0,e.data[s],r,s,0,t-s);r.clamp()},i.prototype.multiplyUpperTo=function(e,t,r){--t;var n=r.t=this.t+e.t-t;for(r.s=0;--n>=0;)r.data[n]=0;for(n=Math.max(t-this.t,0);n<e.t;++n)r.data[this.t+n-t]=this.am(t-n,e.data[n],r,0,0,this.t+n-t);r.clamp(),r.drShiftTo(1,r)},i.prototype.modInt=function(e){if(e<=0)return 0;var t=this.DV%e,r=this.s<0?e-1:0;if(this.t>0)if(0==t)r=this.data[0]%e;else for(var n=this.t-1;n>=0;--n)r=(t*r+this.data[n])%e;return r},i.prototype.millerRabin=function(e){var t=this.subtract(i.ONE),r=t.getLowestSetBit();if(r<=0)return!1;for(var n,s=t.shiftRight(r),a={nextBytes:function(e){for(var t=0;t<e.length;++t)e[t]=Math.floor(256*Math.random())}},o=0;o<e;++o){do{n=new i(this.bitLength(),a)}while(n.compareTo(i.ONE)<=0||n.compareTo(t)>=0);var c=n.modPow(s,this);if(0!=c.compareTo(i.ONE)&&0!=c.compareTo(t)){for(var u=1;u++<r&&0!=c.compareTo(t);)if(0==(c=c.modPowInt(2,this)).compareTo(i.ONE))return!1;if(0!=c.compareTo(t))return!1}}return!0},i.prototype.clone=function(){var e=a();return this.copyTo(e),e},i.prototype.intValue=function(){if(this.s<0){if(1==this.t)return this.data[0]-this.DV;if(0==this.t)return-1}else{if(1==this.t)return this.data[0];if(0==this.t)return 0}return(this.data[1]&(1<<32-this.DB)-1)<<this.DB|this.data[0]},i.prototype.byteValue=function(){return 0==this.t?this.s:this.data[0]<<24>>24},i.prototype.shortValue=function(){return 0==this.t?this.s:this.data[0]<<16>>16},i.prototype.signum=function(){return this.s<0?-1:this.t<=0||1==this.t&&this.data[0]<=0?0:1},i.prototype.toByteArray=function(){var e=this.t,t=new Array;t[0]=this.s;var r,n=this.DB-e*this.DB%8,s=0;if(e-- >0)for(n<this.DB&&(r=this.data[e]>>n)!=(this.s&this.DM)>>n&&(t[s++]=r|this.s<<this.DB-n);e>=0;)n<8?(r=(this.data[e]&(1<<n)-1)<<8-n,r|=this.data[--e]>>(n+=this.DB-8)):(r=this.data[e]>>(n-=8)&255,n<=0&&(n+=this.DB,--e)),128&r&&(r|=-256),0==s&&(128&this.s)!=(128&r)&&++s,(s>0||r!=this.s)&&(t[s++]=r);return t},i.prototype.equals=function(e){return 0==this.compareTo(e)},i.prototype.min=function(e){return this.compareTo(e)<0?this:e},i.prototype.max=function(e){return this.compareTo(e)>0?this:e},i.prototype.and=function(e){var t=a();return this.bitwiseTo(e,m,t),t},i.prototype.or=function(e){var t=a();return this.bitwiseTo(e,b,t),t},i.prototype.xor=function(e){var t=a();return this.bitwiseTo(e,v,t),t},i.prototype.andNot=function(e){var t=a();return this.bitwiseTo(e,w,t),t},i.prototype.not=function(){for(var e=a(),t=0;t<this.t;++t)e.data[t]=this.DM&~this.data[t];return e.t=this.t,e.s=~this.s,e},i.prototype.shiftLeft=function(e){var t=a();return e<0?this.rShiftTo(-e,t):this.lShiftTo(e,t),t},i.prototype.shiftRight=function(e){var t=a();return e<0?this.lShiftTo(-e,t):this.rShiftTo(e,t),t},i.prototype.getLowestSetBit=function(){for(var e=0;e<this.t;++e)if(0!=this.data[e])return e*this.DB+A(this.data[e]);return this.s<0?this.t*this.DB:-1},i.prototype.bitCount=function(){for(var e=0,t=this.s&this.DM,r=0;r<this.t;++r)e+=E(this.data[r]^t);return e},i.prototype.testBit=function(e){var t=Math.floor(e/this.DB);return t>=this.t?0!=this.s:!!(this.data[t]&1<<e%this.DB)},i.prototype.setBit=function(e){return this.changeBit(e,b)},i.prototype.clearBit=function(e){return this.changeBit(e,w)},i.prototype.flipBit=function(e){return this.changeBit(e,v)},i.prototype.add=function(e){var t=a();return this.addTo(e,t),t},i.prototype.subtract=function(e){var t=a();return this.subTo(e,t),t},i.prototype.multiply=function(e){var t=a();return this.multiplyTo(e,t),t},i.prototype.divide=function(e){var t=a();return this.divRemTo(e,t,null),t},i.prototype.remainder=function(e){var t=a();return this.divRemTo(e,null,t),t},i.prototype.divideAndRemainder=function(e){var t=a(),r=a();return this.divRemTo(e,t,r),new Array(t,r)},i.prototype.modPow=function(e,t){var r,n,s=e.bitLength(),i=f(1);if(s<=0)return i;r=s<18?1:s<48?3:s<144?4:s<768?5:6,n=s<8?new g(t):t.isEven()?new S(t):new y(t);var o=new Array,c=3,u=r-1,l=(1<<r)-1;if(o[1]=n.convert(this),r>1){var h=a();for(n.sqrTo(o[1],h);c<=l;)o[c]=a(),n.mulTo(h,o[c-2],o[c]),c+=2}var d,m,b=e.t-1,v=!0,w=a();for(s=p(e.data[b])-1;b>=0;){for(s>=u?d=e.data[b]>>s-u&l:(d=(e.data[b]&(1<<s+1)-1)<<u-s,b>0&&(d|=e.data[b-1]>>this.DB+s-u)),c=r;!(1&d);)d>>=1,--c;if((s-=c)<0&&(s+=this.DB,--b),v)o[d].copyTo(i),v=!1;else{for(;c>1;)n.sqrTo(i,w),n.sqrTo(w,i),c-=2;c>0?n.sqrTo(i,w):(m=i,i=w,w=m),n.mulTo(w,o[d],i)}for(;b>=0&&!(e.data[b]&1<<s);)n.sqrTo(i,w),m=i,i=w,w=m,--s<0&&(s=this.DB-1,--b)}return n.revert(i)},i.prototype.modInverse=function(e){var t=e.isEven();if(this.isEven()&&t||0==e.signum())return i.ZERO;for(var r=e.clone(),n=this.clone(),s=f(1),a=f(0),o=f(0),c=f(1);0!=r.signum();){for(;r.isEven();)r.rShiftTo(1,r),t?(s.isEven()&&a.isEven()||(s.addTo(this,s),a.subTo(e,a)),s.rShiftTo(1,s)):a.isEven()||a.subTo(e,a),a.rShiftTo(1,a);for(;n.isEven();)n.rShiftTo(1,n),t?(o.isEven()&&c.isEven()||(o.addTo(this,o),c.subTo(e,c)),o.rShiftTo(1,o)):c.isEven()||c.subTo(e,c),c.rShiftTo(1,c);r.compareTo(n)>=0?(r.subTo(n,r),t&&s.subTo(o,s),a.subTo(c,a)):(n.subTo(r,n),t&&o.subTo(s,o),c.subTo(a,c))}return 0!=n.compareTo(i.ONE)?i.ZERO:c.compareTo(e)>=0?c.subtract(e):c.signum()<0?(c.addTo(e,c),c.signum()<0?c.add(e):c):c},i.prototype.pow=function(e){return this.exp(e,new C)},i.prototype.gcd=function(e){var t=this.s<0?this.negate():this.clone(),r=e.s<0?e.negate():e.clone();if(t.compareTo(r)<0){var n=t;t=r,r=n}var s=t.getLowestSetBit(),i=r.getLowestSetBit();if(i<0)return t;for(s<i&&(i=s),i>0&&(t.rShiftTo(i,t),r.rShiftTo(i,r));t.signum()>0;)(s=t.getLowestSetBit())>0&&t.rShiftTo(s,t),(s=r.getLowestSetBit())>0&&r.rShiftTo(s,r),t.compareTo(r)>=0?(t.subTo(r,t),t.rShiftTo(1,t)):(r.subTo(t,r),r.rShiftTo(1,r));return i>0&&r.lShiftTo(i,r),r},i.prototype.isProbablePrime=function(e){var t,r=this.abs();if(1==r.t&&r.data[0]<=B[B.length-1]){for(t=0;t<B.length;++t)if(r.data[0]==B[t])return!0;return!1}if(r.isEven())return!1;for(t=1;t<B.length;){for(var n=B[t],s=t+1;s<B.length&&n<P;)n*=B[s++];for(n=r.modInt(n);t<s;)if(n%B[t++]==0)return!1}return r.millerRabin(e)}},203:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Transaction=t.recoverAddress=t.computeAddress=t.authorizationify=t.accessListify=void 0;var n=r(5193);Object.defineProperty(t,"accessListify",{enumerable:!0,get:function(){return n.accessListify}});var s=r(3490);Object.defineProperty(t,"authorizationify",{enumerable:!0,get:function(){return s.authorizationify}});var i=r(4423);Object.defineProperty(t,"computeAddress",{enumerable:!0,get:function(){return i.computeAddress}}),Object.defineProperty(t,"recoverAddress",{enumerable:!0,get:function(){return i.recoverAddress}});var a=r(991);Object.defineProperty(t,"Transaction",{enumerable:!0,get:function(){return a.Transaction}})},260:(e,t,r)=>{var n=r(4643);r(9679),r(8550);var s=e.exports=n.sha512=n.sha512||{};n.md.sha512=n.md.algorithms.sha512=s;var i=n.sha384=n.sha512.sha384=n.sha512.sha384||{};i.create=function(){return s.create("SHA-384")},n.md.sha384=n.md.algorithms.sha384=i,n.sha512.sha256=n.sha512.sha256||{create:function(){return s.create("SHA-512/256")}},n.md["sha512/256"]=n.md.algorithms["sha512/256"]=n.sha512.sha256,n.sha512.sha224=n.sha512.sha224||{create:function(){return s.create("SHA-512/224")}},n.md["sha512/224"]=n.md.algorithms["sha512/224"]=n.sha512.sha224,s.create=function(e){if(o||(a=String.fromCharCode(128),a+=n.util.fillString(String.fromCharCode(0),128),c=[[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]],(u={})["SHA-512"]=[[1779033703,4089235720],[3144134277,2227873595],[1013904242,4271175723],[2773480762,1595750129],[1359893119,2917565137],[2600822924,725511199],[528734635,4215389547],[1541459225,327033209]],u["SHA-384"]=[[3418070365,3238371032],[1654270250,914150663],[2438529370,812702999],[355462360,4144912697],[1731405415,4290775857],[2394180231,1750603025],[3675008525,1694076839],[1203062813,3204075428]],u["SHA-512/256"]=[[573645204,4230739756],[2673172387,3360449730],[596883563,1867755857],[2520282905,1497426621],[2519219938,2827943907],[3193839141,1401305490],[721525244,746961066],[246885852,2177182882]],u["SHA-512/224"]=[[2352822216,424955298],[1944164710,2312950998],[502970286,855612546],[1738396948,1479516111],[258812777,2077511080],[2011393907,79989058],[1067287976,1780299464],[286451373,2446758561]],o=!0),void 0===e&&(e="SHA-512"),!(e in u))throw new Error("Invalid SHA-512 algorithm: "+e);for(var t=u[e],r=null,s=n.util.createBuffer(),i=new Array(80),h=0;h<80;++h)i[h]=new Array(2);var d=64;switch(e){case"SHA-384":d=48;break;case"SHA-512/256":d=32;break;case"SHA-512/224":d=28}var f={algorithm:e.replace("-","").toLowerCase(),blockLength:128,digestLength:d,messageLength:0,fullMessageLength:null,messageLengthSize:16,start:function(){f.messageLength=0,f.fullMessageLength=f.messageLength128=[];for(var e=f.messageLengthSize/4,i=0;i<e;++i)f.fullMessageLength.push(0);s=n.util.createBuffer(),r=new Array(t.length);for(i=0;i<t.length;++i)r[i]=t[i].slice(0);return f}};return f.start(),f.update=function(e,t){"utf8"===t&&(e=n.util.encodeUtf8(e));var a=e.length;f.messageLength+=a,a=[a/4294967296>>>0,a>>>0];for(var o=f.fullMessageLength.length-1;o>=0;--o)f.fullMessageLength[o]+=a[1],a[1]=a[0]+(f.fullMessageLength[o]/4294967296>>>0),f.fullMessageLength[o]=f.fullMessageLength[o]>>>0,a[0]=a[1]/4294967296>>>0;return s.putBytes(e),l(r,i,s),(s.read>2048||0===s.length())&&s.compact(),f},f.digest=function(){var t=n.util.createBuffer();t.putBytes(s.bytes());var o,c=f.fullMessageLength[f.fullMessageLength.length-1]+f.messageLengthSize&f.blockLength-1;t.putBytes(a.substr(0,f.blockLength-c));for(var u=8*f.fullMessageLength[0],h=0;h<f.fullMessageLength.length-1;++h)u+=(o=8*f.fullMessageLength[h+1])/4294967296>>>0,t.putInt32(u>>>0),u=o>>>0;t.putInt32(u);var d=new Array(r.length);for(h=0;h<r.length;++h)d[h]=r[h].slice(0);l(d,i,t);var p,g=n.util.createBuffer();p="SHA-512"===e?d.length:"SHA-384"===e?d.length-2:d.length-4;for(h=0;h<p;++h)g.putInt32(d[h][0]),h===p-1&&"SHA-512/224"===e||g.putInt32(d[h][1]);return g},f};var a=null,o=!1,c=null,u=null;function l(e,t,r){for(var n,s,i,a,o,u,l,h,d,f,p,g,y,m,b,v,w,A,E,C,T,S,B,P,k,I,N,O,R,x,U,L,D,F=r.length();F>=128;){for(N=0;N<16;++N)t[N][0]=r.getInt32()>>>0,t[N][1]=r.getInt32()>>>0;for(;N<80;++N)n=(((O=(x=t[N-2])[0])>>>19|(R=x[1])<<13)^(R>>>29|O<<3)^O>>>6)>>>0,s=((O<<13|R>>>19)^(R<<3|O>>>29)^(O<<26|R>>>6))>>>0,i=(((O=(L=t[N-15])[0])>>>1|(R=L[1])<<31)^(O>>>8|R<<24)^O>>>7)>>>0,a=((O<<31|R>>>1)^(O<<24|R>>>8)^(O<<25|R>>>7))>>>0,U=t[N-7],D=t[N-16],R=s+U[1]+a+D[1],t[N][0]=n+U[0]+i+D[0]+(R/4294967296>>>0)>>>0,t[N][1]=R>>>0;for(p=e[0][0],g=e[0][1],y=e[1][0],m=e[1][1],b=e[2][0],v=e[2][1],w=e[3][0],A=e[3][1],E=e[4][0],C=e[4][1],T=e[5][0],S=e[5][1],B=e[6][0],P=e[6][1],k=e[7][0],I=e[7][1],N=0;N<80;++N)l=((E>>>14|C<<18)^(E>>>18|C<<14)^(C>>>9|E<<23))>>>0,h=(B^E&(T^B))>>>0,o=((p>>>28|g<<4)^(g>>>2|p<<30)^(g>>>7|p<<25))>>>0,u=((p<<4|g>>>28)^(g<<30|p>>>2)^(g<<25|p>>>7))>>>0,d=(p&y|b&(p^y))>>>0,f=(g&m|v&(g^m))>>>0,R=I+(((E<<18|C>>>14)^(E<<14|C>>>18)^(C<<23|E>>>9))>>>0)+((P^C&(S^P))>>>0)+c[N][1]+t[N][1],n=k+l+h+c[N][0]+t[N][0]+(R/4294967296>>>0)>>>0,s=R>>>0,i=o+d+((R=u+f)/4294967296>>>0)>>>0,a=R>>>0,k=B,I=P,B=T,P=S,T=E,S=C,E=w+n+((R=A+s)/4294967296>>>0)>>>0,C=R>>>0,w=b,A=v,b=y,v=m,y=p,m=g,p=n+i+((R=s+a)/4294967296>>>0)>>>0,g=R>>>0;R=e[0][1]+g,e[0][0]=e[0][0]+p+(R/4294967296>>>0)>>>0,e[0][1]=R>>>0,R=e[1][1]+m,e[1][0]=e[1][0]+y+(R/4294967296>>>0)>>>0,e[1][1]=R>>>0,R=e[2][1]+v,e[2][0]=e[2][0]+b+(R/4294967296>>>0)>>>0,e[2][1]=R>>>0,R=e[3][1]+A,e[3][0]=e[3][0]+w+(R/4294967296>>>0)>>>0,e[3][1]=R>>>0,R=e[4][1]+C,e[4][0]=e[4][0]+E+(R/4294967296>>>0)>>>0,e[4][1]=R>>>0,R=e[5][1]+S,e[5][0]=e[5][0]+T+(R/4294967296>>>0)>>>0,e[5][1]=R>>>0,R=e[6][1]+P,e[6][0]=e[6][0]+B+(R/4294967296>>>0)>>>0,e[6][1]=R>>>0,R=e[7][1]+I,e[7][0]=e[7][0]+k+(R/4294967296>>>0)>>>0,e[7][1]=R>>>0,F-=128}}},313:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.SigningKey=void 0;const n=r(5484),s=r(8718),i=r(1154);class a{#l;constructor(e){(0,s.assertArgument)(32===(0,s.dataLength)(e),"invalid private key","privateKey","[REDACTED]"),this.#l=(0,s.hexlify)(e)}get privateKey(){return this.#l}get publicKey(){return a.computePublicKey(this.#l)}get compressedPublicKey(){return a.computePublicKey(this.#l,!0)}sign(e){(0,s.assertArgument)(32===(0,s.dataLength)(e),"invalid digest length","digest",e);const t=n.secp256k1.sign((0,s.getBytesCopy)(e),(0,s.getBytesCopy)(this.#l),{lowS:!0});return i.Signature.from({r:(0,s.toBeHex)(t.r,32),s:(0,s.toBeHex)(t.s,32),v:t.recovery?28:27})}computeSharedSecret(e){const t=a.computePublicKey(e);return(0,s.hexlify)(n.secp256k1.getSharedSecret((0,s.getBytesCopy)(this.#l),(0,s.getBytes)(t),!1))}static computePublicKey(e,t){let r=(0,s.getBytes)(e,"key");if(32===r.length){const e=n.secp256k1.getPublicKey(r,!!t);return(0,s.hexlify)(e)}if(64===r.length){const e=new Uint8Array(65);e[0]=4,e.set(r,1),r=e}const i=n.secp256k1.ProjectivePoint.fromHex(r);return(0,s.hexlify)(i.toRawBytes(t))}static recoverPublicKey(e,t){(0,s.assertArgument)(32===(0,s.dataLength)(e),"invalid digest length","digest",e);const r=i.Signature.from(t);let a=n.secp256k1.Signature.fromCompact((0,s.getBytesCopy)((0,s.concat)([r.r,r.s])));a=a.addRecoveryBit(r.yParity);const o=a.recoverPublicKey((0,s.getBytesCopy)(e));return(0,s.assertArgument)(null!=o,"invalid signature for digest","signature",t),"0x"+o.toHex(!1)}static addPoints(e,t,r){const s=n.secp256k1.ProjectivePoint.fromHex(a.computePublicKey(e).substring(2)),i=n.secp256k1.ProjectivePoint.fromHex(a.computePublicKey(t).substring(2));return"0x"+s.add(i).toHex(!!r)}}t.SigningKey=a},324:(e,t)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.showThrottleMessage=void 0;const r=new Set;t.showThrottleMessage=function(e){r.has(e)||(r.add(e),console.log("========= NOTICE ========="),console.log(`Request-Rate Exceeded for ${e} (this message will not be repeated)`),console.log(""),console.log("The default API keys for each service are provided as a highly-throttled,"),console.log("community resource for low-traffic projects and early prototyping."),console.log(""),console.log("While your application will continue to function, we highly recommended"),console.log("signing up for your own API keys to improve performance, increase your"),console.log("request rate/limit and enable other perks, such as metrics and advanced APIs."),console.log(""),console.log("For more details: https://docs.ethers.org/api-keys/"),console.log("=========================="))}},333:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.Typed=t.Result=t.TransactionDescription=t.LogDescription=t.ErrorDescription=t.Interface=t.Indexed=t.checkResultErrors=t.StructFragment=t.ParamType=t.NamedFragment=t.FunctionFragment=t.Fragment=t.FallbackFragment=t.EventFragment=t.ErrorFragment=t.ConstructorFragment=t.encodeBytes32String=t.decodeBytes32String=t.AbiCoder=void 0;var n=r(9895);Object.defineProperty(t,"AbiCoder",{enumerable:!0,get:function(){return n.AbiCoder}});var s=r(3743);Object.defineProperty(t,"decodeBytes32String",{enumerable:!0,get:function(){return s.decodeBytes32String}}),Object.defineProperty(t,"encodeBytes32String",{enumerable:!0,get:function(){return s.encodeBytes32String}});var i=r(3556);Object.defineProperty(t,"ConstructorFragment",{enumerable:!0,get:function(){return i.ConstructorFragment}}),Object.defineProperty(t,"ErrorFragment",{enumerable:!0,get:function(){return i.ErrorFragment}}),Object.defineProperty(t,"EventFragment",{enumerable:!0,get:function(){return i.EventFragment}}),Object.defineProperty(t,"FallbackFragment",{enumerable:!0,get:function(){return i.FallbackFragment}}),Object.defineProperty(t,"Fragment",{enumerable:!0,get:function(){return i.Fragment}}),Object.defineProperty(t,"FunctionFragment",{enumerable:!0,get:function(){return i.FunctionFragment}}),Object.defineProperty(t,"NamedFragment",{enumerable:!0,get:function(){return i.NamedFragment}}),Object.defineProperty(t,"ParamType",{enumerable:!0,get:function(){return i.ParamType}}),Object.defineProperty(t,"StructFragment",{enumerable:!0,get:function(){return i.StructFragment}});var a=r(9854);Object.defineProperty(t,"checkResultErrors",{enumerable:!0,get:function(){return a.checkResultErrors}}),Object.defineProperty(t,"Indexed",{enumerable:!0,get:function(){return a.Indexed}}),Object.defineProperty(t,"Interface",{enumerable:!0,get:function(){return a.Interface}}),Object.defineProperty(t,"ErrorDescription",{enumerable:!0,get:function(){return a.ErrorDescription}}),Object.defineProperty(t,"LogDescription",{enumerable:!0,get:function(){return a.LogDescription}}),Object.defineProperty(t,"TransactionDescription",{enumerable:!0,get:function(){return a.TransactionDescription}}),Object.defineProperty(t,"Result",{enumerable:!0,get:function(){return a.Result}});var o=r(3233);Object.defineProperty(t,"Typed",{enumerable:!0,get:function(){return o.Typed}})},339:(e,t,r)=>{var n=r(4643);r(8550),r(121),r(5417),function(){if(n.prime)e.exports=n.prime;else{var t=e.exports=n.prime=n.prime||{},r=n.jsbn.BigInteger,s=[6,4,2,4,2,4,6,2],i=new r(null);i.fromInt(30);var a=function(e,t){return e|t};t.generateProbablePrime=function(e,t,s){"function"==typeof t&&(s=t,t={});var i=(t=t||{}).algorithm||"PRIMEINC";"string"==typeof i&&(i={name:i}),i.options=i.options||{};var a=t.prng||n.random,c={nextBytes:function(e){for(var t=a.getBytesSync(e.length),r=0;r<e.length;++r)e[r]=t.charCodeAt(r)}};if("PRIMEINC"===i.name)return function(e,t,s,i){if("workers"in s)return function(e,t,s,i){if("undefined"==typeof Worker)return o(e,t,s,i);var a=u(e,t),c=s.workers,l=s.workLoad||100,h=30*l/8,d=s.workerScript||"forge/prime.worker.js";if(-1===c)return n.util.estimateCores(function(e,t){e&&(t=2),c=t-1,f()});function f(){c=Math.max(1,c);for(var n=[],s=0;s<c;++s)n[s]=new Worker(d);for(s=0;s<c;++s)n[s].addEventListener("message",f);var o=!1;function f(s){if(!o){0;var c=s.data;if(c.found){for(var d=0;d<n.length;++d)n[d].terminate();return o=!0,i(null,new r(c.prime,16))}a.bitLength()>e&&(a=u(e,t));var f=a.toString(16);s.target.postMessage({hex:f,workLoad:l}),