@wormhole-foundation/wormhole-connect 2.1.0-beta.1-development → 2.1.0-beta.2-development
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{ccip-j5QHovIT.js → ccip-DfI9A4kL.js} +1 -1
- package/dist/assets/{evm-B5I5ieRn.js → evm-CYICYl2d.js} +3 -3
- package/dist/assets/index-26ve8f2n.js +531 -0
- package/dist/assets/index-NqsKKz5-.js +14 -0
- package/dist/assets/index.es-CephYdxr.js +47 -0
- package/dist/assets/{solana-c_vE3Ye5.js → solana-DXbD7wpn.js} +2 -2
- package/dist/assets/{solanaEmbed.esm-Bx0ME0S1.js → solanaEmbed.esm-CcwIvLto.js} +10 -10
- package/dist/main.js +3 -3
- package/lib/{aptos-CzT6f7Ba.js → aptos-7G9wZkGW.js} +2 -2
- package/lib/{aptos-wFa1-xae.mjs → aptos-BlOWGpyT.mjs} +2 -2
- package/lib/{aptos-CqfHXKy7.js → aptos-CYxRBLR_.js} +1 -1
- package/lib/{aptos-DxhN-FI3.mjs → aptos-Ckopfy7I.mjs} +5 -5
- package/lib/{base64-C_XWimVd.js → base64-CFR5QWTY.js} +1 -1
- package/lib/{base64-L1vzz0KI.mjs → base64-HSuzVIKw.mjs} +1 -1
- package/lib/{ccip-z81HbzxN.mjs → ccip-Bntg_vPp.mjs} +1 -1
- package/lib/{ccip-D6aPw5Ue.js → ccip-CVUhxB0q.js} +1 -1
- package/lib/{chunk-IMTC3J2M-CazR2ogu.mjs → chunk-IMTC3J2M-BADDWO3l.mjs} +3 -3
- package/lib/{chunk-IMTC3J2M-WMj1Jt5m.js → chunk-IMTC3J2M-ByR5Yjf4.js} +1 -1
- package/lib/{events-D4Mv_WYU.js → events-jATx_JnD.js} +1 -1
- package/lib/{events-BrdIAbQL.mjs → events-lD3LhLH0.mjs} +1 -1
- package/lib/{evm-CB6zu7io.mjs → evm-BW0CHBCG.mjs} +5 -5
- package/lib/{evm-Fk4wBAda.js → evm-Bh1Y4eUx.js} +1 -1
- package/lib/{evm-CULALpUt.mjs → evm-ColKfWEz.mjs} +10 -6
- package/lib/{evm-BJL8RjTB.js → evm-z5yFHxM9.js} +3 -3
- package/lib/{index-D2y7My6x.mjs → index-2fBRXVP8.mjs} +2 -2
- package/lib/{index-Cuov-W4s.js → index-8-70GvMi.js} +1 -1
- package/lib/{index-Xy8XaqU-.js → index-8JCep4IW.js} +1 -1
- package/lib/{index-BTmEJpYG.mjs → index-B9GU1bLs.mjs} +1 -1
- package/lib/{index-CS3t6bxx.mjs → index-BXkdaYu_.mjs} +1 -1
- package/lib/{index-DEpSdwA-.mjs → index-BZ0W_BZS.mjs} +2 -2
- package/lib/{index-CtpCK8QC.js → index-BcdbCktu.js} +1 -1
- package/lib/{index-BnVRRJvv.js → index-BhexWYVn.js} +1 -1
- package/lib/{index-BT_eiQVC.js → index-C-OIv0gT.js} +1 -1
- package/lib/{index-CAqS4koK.js → index-C6WDEDwO.js} +1 -1
- package/lib/{index-BqaYMlOq.mjs → index-CAUvtNGE.mjs} +3 -3
- package/lib/{index-DpfI-2hT.mjs → index-CBxgME-2.mjs} +2 -2
- package/lib/{index-Dtg6idl8.js → index-CCUy1jes.js} +1 -1
- package/lib/{index-DGcrnWdu.mjs → index-CYBM2IeY.mjs} +13 -12
- package/lib/{index-DJJ3umH8.mjs → index-CcFpkXPM.mjs} +2 -2
- package/lib/{index-BqCducVx.mjs → index-CfnNi3Zd.mjs} +3 -3
- package/lib/{index-DdRe9fUB.mjs → index-Cl6LSKsg.mjs} +1 -1
- package/lib/{index-DtqIOAjg.mjs → index-CxQ-swIQ.mjs} +1 -1
- package/lib/index-Cxw9PIcl.js +531 -0
- package/lib/{index-CGdGYg5B.mjs → index-D0XcjaUl.mjs} +2 -2
- package/lib/{index-B9FwYN90.js → index-D7IcLxQc.js} +1 -1
- package/lib/index-DAzDpd7U.js +14 -0
- package/lib/{index-jC1hUxPJ.mjs → index-DB_r424l.mjs} +1 -1
- package/lib/{index-C_2eG0Va.mjs → index-DECw2aR6.mjs} +1 -1
- package/lib/{index-CuPOodtE.js → index-DGgQSMuG.js} +1 -1
- package/lib/{index-BsmdxKnE.mjs → index-DIAuhm70.mjs} +3008 -3525
- package/lib/{index-CuWt4RaJ.js → index-DOXMkFA4.js} +1 -1
- package/lib/{index-BGZONAdj.js → index-DQVQrflZ.js} +1 -1
- package/lib/{index-GM4m48QO.js → index-DUXnbpVg.js} +1 -1
- package/lib/{index-DUGwXho3.js → index-DZvLy2Dr.js} +3 -3
- package/lib/{index-BsYhqVq_.js → index-DjkMeATf.js} +1 -1
- package/lib/{index-C0MgLwy8.js → index-DleO04Ea.js} +1 -1
- package/lib/{index-HeldZ3mJ.mjs → index-InC6In6o.mjs} +2 -2
- package/lib/{index-CkUMgihl.js → index-V7kxzAZX.js} +1 -1
- package/lib/{index-B5TOuhBB.js → index-WLqZ1uO7.js} +1 -1
- package/lib/{index-Cf2BEUjb.mjs → index-gd_dleYk.mjs} +1 -1
- package/lib/{index-CayMgbM_.js → index-l0NqjNj9.js} +1 -1
- package/lib/{index-wAClTIQn.mjs → index-lEBTHIqm.mjs} +2 -2
- package/lib/{index-DsYAlD9Y.mjs → index-lHA40g0z.mjs} +2 -2
- package/lib/index-oPxOJfPK.mjs +3236 -0
- package/lib/{index-ChzkRsG0.js → index-rFhS51F6.js} +1 -1
- package/lib/{index-DXIpHh2N.mjs → index-y_DeeCWD.mjs} +4 -4
- package/lib/index.es-Doowrf9a.js +46 -0
- package/lib/index.es-YqKQxHG6.mjs +7725 -0
- package/lib/index.js +1 -1
- package/lib/index.mjs +1 -1
- package/lib/{signer-BBJR-S7u.mjs → signer-CfU9wW3f.mjs} +1 -1
- package/lib/{signer-D8m72nd4.js → signer-eoVHaZz7.js} +1 -1
- package/lib/{solana-DB5vwgKO.mjs → solana-CHUnEnef.mjs} +4 -4
- package/lib/{solana-tZZpsxE8.js → solana-C_d_AKET.js} +1 -1
- package/lib/solana-SFHXHGL2.js +1 -0
- package/lib/{solana-DdLCPKF2.mjs → solana-y-l38J4U.mjs} +5 -5
- package/lib/{solanaEmbed.esm-TpsYEDsw.js → solanaEmbed.esm-B4tNQ7S7.js} +10 -10
- package/lib/{solanaEmbed.esm-ANGjgiaN.mjs → solanaEmbed.esm-DVOHg5WI.mjs} +1559 -1560
- package/lib/{sui-BFNsLy1t.mjs → sui-1fbLRIUL.mjs} +5 -5
- package/lib/{sui-UELhAZj0.js → sui-BN1m6APK.js} +1 -1
- package/lib/{sui-DKw9LmTC.mjs → sui-D9frS9ki.mjs} +1 -1
- package/lib/{sui-D9F11hKw.js → sui-K20aVxqE.js} +2 -2
- package/package.json +5 -1
- package/dist/assets/index-BUd_4Lqz.js +0 -14
- package/dist/assets/index-Db_i6Hbk.js +0 -531
- package/dist/assets/index.es-BYwyqXqm.js +0 -47
- package/lib/index-5EBn2EJL.mjs +0 -2709
- package/lib/index-CYpOkqEl.js +0 -14
- package/lib/index-Cst2493l.js +0 -531
- package/lib/index.es-DG7BWZ8R.js +0 -46
- package/lib/index.es-IbuqEs8_.mjs +0 -8242
- package/lib/solana-521ACL4P.js +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const He=require("./events-jATx_JnD.js"),W=require("./index-DZvLy2Dr.js"),ze=require("./evm-z5yFHxM9.js"),j=require("./index-DQVQrflZ.js"),E=require("./index-DAzDpd7U.js");var ne={};Object.defineProperty(ne,"__esModule",{value:!0});ne.getLocalStorage=ne.getLocalStorageOrThrow=ne.getCrypto=ne.getCryptoOrThrow=ne.getLocation=ne.getLocationOrThrow=ne.getNavigator=ne.getNavigatorOrThrow=ne.getDocument=ne.getDocumentOrThrow=ne.getFromWindowOrThrow=ne.getFromWindow=void 0;function nr(a){let t;return typeof window<"u"&&typeof window[a]<"u"&&(t=window[a]),t}ne.getFromWindow=nr;function $r(a){const t=nr(a);if(!t)throw new Error(`${a} is not defined in Window`);return t}ne.getFromWindowOrThrow=$r;function rw(){return $r("document")}ne.getDocumentOrThrow=rw;function iw(){return nr("document")}ne.getDocument=iw;function sw(){return $r("navigator")}ne.getNavigatorOrThrow=sw;function nw(){return nr("navigator")}ne.getNavigator=nw;function ow(){return $r("location")}ne.getLocationOrThrow=ow;function aw(){return nr("location")}ne.getLocation=aw;function cw(){return $r("crypto")}ne.getCryptoOrThrow=cw;function uw(){return nr("crypto")}ne.getCrypto=uw;function hw(){return $r("localStorage")}ne.getLocalStorageOrThrow=hw;function lw(){return nr("localStorage")}ne.getLocalStorage=lw;var Eo={};Object.defineProperty(Eo,"__esModule",{value:!0});Eo.getWindowMetadata=void 0;const pu=ne;function pw(){let a,t;try{a=pu.getDocumentOrThrow(),t=pu.getLocationOrThrow()}catch{return null}function r(){const O=a.getElementsByTagName("link"),N=[];for(let q=0;q<O.length;q++){const x=O[q],K=x.getAttribute("rel");if(K&&K.toLowerCase().indexOf("icon")>-1){const D=x.getAttribute("href");if(D)if(D.toLowerCase().indexOf("https:")===-1&&D.toLowerCase().indexOf("http:")===-1&&D.indexOf("//")!==0){let Q=t.protocol+"//"+t.host;if(D.indexOf("/")===0)Q+=D;else{const fe=t.pathname.split("/");fe.pop();const Z=fe.join("/");Q+=Z+"/"+D}N.push(Q)}else if(D.indexOf("//")===0){const Q=t.protocol+D;N.push(Q)}else N.push(D)}}return N}function s(...O){const N=a.getElementsByTagName("meta");for(let q=0;q<N.length;q++){const x=N[q],K=["itemprop","property","name"].map(D=>x.getAttribute(D)).filter(D=>D?O.includes(D):!1);if(K.length&&K){const D=x.getAttribute("content");if(D)return D}}return""}function o(){let O=s("name","og:site_name","og:title","twitter:title");return O||(O=a.title),O}function u(){return s("description","og:description","twitter:description","keywords")}const l=o(),g=u(),w=t.origin,b=r();return{description:g,url:w,icons:b,name:l}}Eo.getWindowMetadata=pw;function fw(a,t=[]){const r=[];return Object.keys(a).forEach(s=>{if(t.length&&!t.includes(s))return;const o=a[s];r.push(...o.accounts)}),r}const dw={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}};function gw(a,t){const{message:r,code:s}=dw[a];return{message:r,code:s}}function uo(a,t){return!!Array.isArray(a)}var Tr={};/*! *****************************************************************************
|
|
2
|
+
Copyright (c) Microsoft Corporation.
|
|
3
|
+
|
|
4
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
5
|
+
purpose with or without fee is hereby granted.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
8
|
+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
9
|
+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
10
|
+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
11
|
+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
12
|
+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
13
|
+
PERFORMANCE OF THIS SOFTWARE.
|
|
14
|
+
***************************************************************************** */var ho=function(a,t){return ho=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,s){r.__proto__=s}||function(r,s){for(var o in s)s.hasOwnProperty(o)&&(r[o]=s[o])},ho(a,t)};function yw(a,t){ho(a,t);function r(){this.constructor=a}a.prototype=t===null?Object.create(t):(r.prototype=t.prototype,new r)}var lo=function(){return lo=Object.assign||function(t){for(var r,s=1,o=arguments.length;s<o;s++){r=arguments[s];for(var u in r)Object.prototype.hasOwnProperty.call(r,u)&&(t[u]=r[u])}return t},lo.apply(this,arguments)};function vw(a,t){var r={};for(var s in a)Object.prototype.hasOwnProperty.call(a,s)&&t.indexOf(s)<0&&(r[s]=a[s]);if(a!=null&&typeof Object.getOwnPropertySymbols=="function")for(var o=0,s=Object.getOwnPropertySymbols(a);o<s.length;o++)t.indexOf(s[o])<0&&Object.prototype.propertyIsEnumerable.call(a,s[o])&&(r[s[o]]=a[s[o]]);return r}function mw(a,t,r,s){var o=arguments.length,u=o<3?t:s===null?s=Object.getOwnPropertyDescriptor(t,r):s,l;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")u=Reflect.decorate(a,t,r,s);else for(var g=a.length-1;g>=0;g--)(l=a[g])&&(u=(o<3?l(u):o>3?l(t,r,u):l(t,r))||u);return o>3&&u&&Object.defineProperty(t,r,u),u}function ww(a,t){return function(r,s){t(r,s,a)}}function _w(a,t){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(a,t)}function bw(a,t,r,s){function o(u){return u instanceof r?u:new r(function(l){l(u)})}return new(r||(r=Promise))(function(u,l){function g(C){try{b(s.next(C))}catch(O){l(O)}}function w(C){try{b(s.throw(C))}catch(O){l(O)}}function b(C){C.done?u(C.value):o(C.value).then(g,w)}b((s=s.apply(a,t||[])).next())})}function Ew(a,t){var r={label:0,sent:function(){if(u[0]&1)throw u[1];return u[1]},trys:[],ops:[]},s,o,u,l;return l={next:g(0),throw:g(1),return:g(2)},typeof Symbol=="function"&&(l[Symbol.iterator]=function(){return this}),l;function g(b){return function(C){return w([b,C])}}function w(b){if(s)throw new TypeError("Generator is already executing.");for(;r;)try{if(s=1,o&&(u=b[0]&2?o.return:b[0]?o.throw||((u=o.return)&&u.call(o),0):o.next)&&!(u=u.call(o,b[1])).done)return u;switch(o=0,u&&(b=[b[0]&2,u.value]),b[0]){case 0:case 1:u=b;break;case 4:return r.label++,{value:b[1],done:!1};case 5:r.label++,o=b[1],b=[0];continue;case 7:b=r.ops.pop(),r.trys.pop();continue;default:if(u=r.trys,!(u=u.length>0&&u[u.length-1])&&(b[0]===6||b[0]===2)){r=0;continue}if(b[0]===3&&(!u||b[1]>u[0]&&b[1]<u[3])){r.label=b[1];break}if(b[0]===6&&r.label<u[1]){r.label=u[1],u=b;break}if(u&&r.label<u[2]){r.label=u[2],r.ops.push(b);break}u[2]&&r.ops.pop(),r.trys.pop();continue}b=t.call(a,r)}catch(C){b=[6,C],o=0}finally{s=u=0}if(b[0]&5)throw b[1];return{value:b[0]?b[1]:void 0,done:!0}}}function Iw(a,t,r,s){s===void 0&&(s=r),a[s]=t[r]}function Pw(a,t){for(var r in a)r!=="default"&&!t.hasOwnProperty(r)&&(t[r]=a[r])}function po(a){var t=typeof Symbol=="function"&&Symbol.iterator,r=t&&a[t],s=0;if(r)return r.call(a);if(a&&typeof a.length=="number")return{next:function(){return a&&s>=a.length&&(a=void 0),{value:a&&a[s++],done:!a}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function wh(a,t){var r=typeof Symbol=="function"&&a[Symbol.iterator];if(!r)return a;var s=r.call(a),o,u=[],l;try{for(;(t===void 0||t-- >0)&&!(o=s.next()).done;)u.push(o.value)}catch(g){l={error:g}}finally{try{o&&!o.done&&(r=s.return)&&r.call(s)}finally{if(l)throw l.error}}return u}function Sw(){for(var a=[],t=0;t<arguments.length;t++)a=a.concat(wh(arguments[t]));return a}function Ow(){for(var a=0,t=0,r=arguments.length;t<r;t++)a+=arguments[t].length;for(var s=Array(a),o=0,t=0;t<r;t++)for(var u=arguments[t],l=0,g=u.length;l<g;l++,o++)s[o]=u[l];return s}function di(a){return this instanceof di?(this.v=a,this):new di(a)}function Rw(a,t,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var s=r.apply(a,t||[]),o,u=[];return o={},l("next"),l("throw"),l("return"),o[Symbol.asyncIterator]=function(){return this},o;function l(N){s[N]&&(o[N]=function(q){return new Promise(function(x,K){u.push([N,q,x,K])>1||g(N,q)})})}function g(N,q){try{w(s[N](q))}catch(x){O(u[0][3],x)}}function w(N){N.value instanceof di?Promise.resolve(N.value.v).then(b,C):O(u[0][2],N)}function b(N){g("next",N)}function C(N){g("throw",N)}function O(N,q){N(q),u.shift(),u.length&&g(u[0][0],u[0][1])}}function Nw(a){var t,r;return t={},s("next"),s("throw",function(o){throw o}),s("return"),t[Symbol.iterator]=function(){return this},t;function s(o,u){t[o]=a[o]?function(l){return(r=!r)?{value:di(a[o](l)),done:o==="return"}:u?u(l):l}:u}}function Cw(a){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var t=a[Symbol.asyncIterator],r;return t?t.call(a):(a=typeof po=="function"?po(a):a[Symbol.iterator](),r={},s("next"),s("throw"),s("return"),r[Symbol.asyncIterator]=function(){return this},r);function s(u){r[u]=a[u]&&function(l){return new Promise(function(g,w){l=a[u](l),o(g,w,l.done,l.value)})}}function o(u,l,g,w){Promise.resolve(w).then(function(b){u({value:b,done:g})},l)}}function $w(a,t){return Object.defineProperty?Object.defineProperty(a,"raw",{value:t}):a.raw=t,a}function Tw(a){if(a&&a.__esModule)return a;var t={};if(a!=null)for(var r in a)Object.hasOwnProperty.call(a,r)&&(t[r]=a[r]);return t.default=a,t}function Aw(a){return a&&a.__esModule?a:{default:a}}function xw(a,t){if(!t.has(a))throw new TypeError("attempted to get private field on non-instance");return t.get(a)}function Dw(a,t,r){if(!t.has(a))throw new TypeError("attempted to set private field on non-instance");return t.set(a,r),r}const Fw=Object.freeze(Object.defineProperty({__proto__:null,get __assign(){return lo},__asyncDelegator:Nw,__asyncGenerator:Rw,__asyncValues:Cw,__await:di,__awaiter:bw,__classPrivateFieldGet:xw,__classPrivateFieldSet:Dw,__createBinding:Iw,__decorate:mw,__exportStar:Pw,__extends:yw,__generator:Ew,__importDefault:Aw,__importStar:Tw,__makeTemplateObject:$w,__metadata:_w,__param:ww,__read:wh,__rest:vw,__spread:Sw,__spreadArrays:Ow,__values:po},Symbol.toStringTag,{value:"Module"})),Ps=W.getAugmentedNamespace(Fw);var si={},Qn={},ni={};const jw=Object.freeze(Object.defineProperty({__proto__:null,IEvents:E.IEvents},Symbol.toStringTag,{value:"Module"})),qw=W.getAugmentedNamespace(jw);var fu;function Uw(){if(fu)return ni;fu=1,Object.defineProperty(ni,"__esModule",{value:!0}),ni.IHeartBeat=void 0;const a=qw;class t extends a.IEvents{constructor(s){super()}}return ni.IHeartBeat=t,ni}var du;function _h(){return du||(du=1,function(a){Object.defineProperty(a,"__esModule",{value:!0}),Ps.__exportStar(Uw(),a)}(Qn)),Qn}var Yn={},rr={},gu;function Mw(){if(gu)return rr;gu=1,Object.defineProperty(rr,"__esModule",{value:!0}),rr.HEARTBEAT_EVENTS=rr.HEARTBEAT_INTERVAL=void 0;const a=j.cjs;return rr.HEARTBEAT_INTERVAL=a.FIVE_SECONDS,rr.HEARTBEAT_EVENTS={pulse:"heartbeat_pulse"},rr}var yu;function bh(){return yu||(yu=1,function(a){Object.defineProperty(a,"__esModule",{value:!0}),Ps.__exportStar(Mw(),a)}(Yn)),Yn}var vu;function Lw(){if(vu)return si;vu=1,Object.defineProperty(si,"__esModule",{value:!0}),si.HeartBeat=void 0;const a=Ps,t=W.requireEvents(),r=j.cjs,s=_h(),o=bh();class u extends s.IHeartBeat{constructor(g){super(g),this.events=new t.EventEmitter,this.interval=o.HEARTBEAT_INTERVAL,this.interval=(g==null?void 0:g.interval)||o.HEARTBEAT_INTERVAL}static init(g){return a.__awaiter(this,void 0,void 0,function*(){const w=new u(g);return yield w.init(),w})}init(){return a.__awaiter(this,void 0,void 0,function*(){yield this.initialize()})}stop(){clearInterval(this.intervalRef)}on(g,w){this.events.on(g,w)}once(g,w){this.events.once(g,w)}off(g,w){this.events.off(g,w)}removeListener(g,w){this.events.removeListener(g,w)}initialize(){return a.__awaiter(this,void 0,void 0,function*(){this.intervalRef=setInterval(()=>this.pulse(),r.toMiliseconds(this.interval))})}pulse(){this.events.emit(o.HEARTBEAT_EVENTS.pulse)}}return si.HeartBeat=u,si}(function(a){Object.defineProperty(a,"__esModule",{value:!0});const t=Ps;t.__exportStar(Lw(),a),t.__exportStar(_h(),a),t.__exportStar(bh(),a)})(Tr);class kw extends E.IEvents{constructor(t){super(),this.opts=t,this.protocol="wc",this.version=2}}let zw=class extends E.IEvents{constructor(t,r){super(),this.core=t,this.logger=r,this.records=new Map}},Hw=class{constructor(t,r){this.logger=t,this.core=r}},Vw=class extends E.IEvents{constructor(t,r){super(),this.relayer=t,this.logger=r}},Kw=class extends E.IEvents{constructor(t){super()}},Bw=class{constructor(t,r,s,o){this.core=t,this.logger=r,this.name=s}},Ww=class extends E.IEvents{constructor(t,r){super(),this.relayer=t,this.logger=r}},Jw=class extends E.IEvents{constructor(t,r){super(),this.core=t,this.logger=r}},Gw=class{constructor(t,r){this.projectId=t,this.logger=r}},Qw=class{constructor(t,r){this.projectId=t,this.logger=r}},Yw=class{constructor(t){this.opts=t,this.protocol="wc",this.version=2}},Zw=class{constructor(t){this.client=t}};const Xw=a=>JSON.stringify(a,(t,r)=>typeof r=="bigint"?r.toString()+"n":r),e_=a=>{const t=/([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g,r=a.replace(t,'$1"$2n"$3');return JSON.parse(r,(s,o)=>typeof o=="string"&&o.match(/^\d+n$/)?BigInt(o.substring(0,o.length-1)):o)};function Eh(a){if(typeof a!="string")throw new Error(`Cannot safe json parse value of type ${typeof a}`);try{return e_(a)}catch{return a}}function Ih(a){return typeof a=="string"?a:Xw(a)||""}var oe={};Object.defineProperty(oe,"__esModule",{value:!0});oe.getLocalStorage=oe.getLocalStorageOrThrow=oe.getCrypto=oe.getCryptoOrThrow=Ph=oe.getLocation=oe.getLocationOrThrow=Po=oe.getNavigator=oe.getNavigatorOrThrow=Io=oe.getDocument=oe.getDocumentOrThrow=oe.getFromWindowOrThrow=oe.getFromWindow=void 0;function or(a){let t;return typeof window<"u"&&typeof window[a]<"u"&&(t=window[a]),t}oe.getFromWindow=or;function Ar(a){const t=or(a);if(!t)throw new Error(`${a} is not defined in Window`);return t}oe.getFromWindowOrThrow=Ar;function t_(){return Ar("document")}oe.getDocumentOrThrow=t_;function r_(){return or("document")}var Io=oe.getDocument=r_;function i_(){return Ar("navigator")}oe.getNavigatorOrThrow=i_;function s_(){return or("navigator")}var Po=oe.getNavigator=s_;function n_(){return Ar("location")}oe.getLocationOrThrow=n_;function o_(){return or("location")}var Ph=oe.getLocation=o_;function a_(){return Ar("crypto")}oe.getCryptoOrThrow=a_;function c_(){return or("crypto")}oe.getCrypto=c_;function u_(){return Ar("localStorage")}oe.getLocalStorageOrThrow=u_;function h_(){return or("localStorage")}oe.getLocalStorage=h_;var So={};Object.defineProperty(So,"__esModule",{value:!0});var Sh=So.getWindowMetadata=void 0;const mu=oe;function l_(){let a,t;try{a=mu.getDocumentOrThrow(),t=mu.getLocationOrThrow()}catch{return null}function r(){const O=a.getElementsByTagName("link"),N=[];for(let q=0;q<O.length;q++){const x=O[q],K=x.getAttribute("rel");if(K&&K.toLowerCase().indexOf("icon")>-1){const D=x.getAttribute("href");if(D)if(D.toLowerCase().indexOf("https:")===-1&&D.toLowerCase().indexOf("http:")===-1&&D.indexOf("//")!==0){let Q=t.protocol+"//"+t.host;if(D.indexOf("/")===0)Q+=D;else{const fe=t.pathname.split("/");fe.pop();const Z=fe.join("/");Q+=Z+"/"+D}N.push(Q)}else if(D.indexOf("//")===0){const Q=t.protocol+D;N.push(Q)}else N.push(D)}}return N}function s(...O){const N=a.getElementsByTagName("meta");for(let q=0;q<N.length;q++){const x=N[q],K=["itemprop","property","name"].map(D=>x.getAttribute(D)).filter(D=>D?O.includes(D):!1);if(K.length&&K){const D=x.getAttribute("content");if(D)return D}}return""}function o(){let O=s("name","og:site_name","og:title","twitter:title");return O||(O=a.title),O}function u(){return s("description","og:description","twitter:description","keywords")}const l=o(),g=u(),w=t.origin,b=r();return{description:g,url:w,icons:b,name:l}}Sh=So.getWindowMetadata=l_;const p_=":";function f_(a){const[t,r]=a.split(p_);return{namespace:t,reference:r}}function Oh(a,t){return a.includes(":")?[a]:t.chains||[]}const Rh="base10",De="base16",fo="base64pad",Oo="utf8",Nh=0,ar=1,d_=0,wu=1,go=12,Ro=32;function g_(){const a=ze.x25519.generateKeyPair();return{privateKey:E.toString(a.secretKey,De),publicKey:E.toString(a.publicKey,De)}}function yo(){const a=ze.random.randomBytes(Ro);return E.toString(a,De)}function y_(a,t){const r=ze.x25519.sharedKey(E.fromString(a,De),E.fromString(t,De),!0),s=new ze.HKDF_1(ze.sha256.SHA256,r).expand(Ro);return E.toString(s,De)}function v_(a){const t=ze.sha256.hash(E.fromString(a,De));return E.toString(t,De)}function Nr(a){const t=ze.sha256.hash(E.fromString(a,Oo));return E.toString(t,De)}function m_(a){return E.fromString(`${a}`,Rh)}function yi(a){return Number(E.toString(a,Rh))}function w_(a){const t=m_(typeof a.type<"u"?a.type:Nh);if(yi(t)===ar&&typeof a.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const r=typeof a.senderPublicKey<"u"?E.fromString(a.senderPublicKey,De):void 0,s=typeof a.iv<"u"?E.fromString(a.iv,De):ze.random.randomBytes(go),o=new ze.chacha20poly1305.ChaCha20Poly1305(E.fromString(a.symKey,De)).seal(s,E.fromString(a.message,Oo));return b_({type:t,sealed:o,iv:s,senderPublicKey:r})}function __(a){const t=new ze.chacha20poly1305.ChaCha20Poly1305(E.fromString(a.symKey,De)),{sealed:r,iv:s}=ws(a.encoded),o=t.open(s,r);if(o===null)throw new Error("Failed to decrypt");return E.toString(o,Oo)}function b_(a){if(yi(a.type)===ar){if(typeof a.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return E.toString(E.concat([a.type,a.senderPublicKey,a.iv,a.sealed]),fo)}return E.toString(E.concat([a.type,a.iv,a.sealed]),fo)}function ws(a){const t=E.fromString(a,fo),r=t.slice(d_,wu),s=wu;if(yi(r)===ar){const g=s+Ro,w=g+go,b=t.slice(s,g),C=t.slice(g,w),O=t.slice(w);return{type:r,sealed:O,iv:C,senderPublicKey:b}}const o=s+go,u=t.slice(s,o),l=t.slice(o);return{type:r,sealed:l,iv:u}}function E_(a,t){const r=ws(a);return Ch({type:yi(r.type),senderPublicKey:typeof r.senderPublicKey<"u"?E.toString(r.senderPublicKey,De):void 0,receiverPublicKey:t==null?void 0:t.receiverPublicKey})}function Ch(a){const t=(a==null?void 0:a.type)||Nh;if(t===ar){if(typeof(a==null?void 0:a.senderPublicKey)>"u")throw new Error("missing sender public key");if(typeof(a==null?void 0:a.receiverPublicKey)>"u")throw new Error("missing receiver public key")}return{type:t,senderPublicKey:a==null?void 0:a.senderPublicKey,receiverPublicKey:a==null?void 0:a.receiverPublicKey}}function _u(a){return a.type===ar&&typeof a.senderPublicKey=="string"&&typeof a.receiverPublicKey=="string"}var I_=Object.defineProperty,bu=Object.getOwnPropertySymbols,P_=Object.prototype.hasOwnProperty,S_=Object.prototype.propertyIsEnumerable,Eu=(a,t,r)=>t in a?I_(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,Iu=(a,t)=>{for(var r in t||(t={}))P_.call(t,r)&&Eu(a,r,t[r]);if(bu)for(var r of bu(t))S_.call(t,r)&&Eu(a,r,t[r]);return a};const O_="ReactNative",Qe={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},R_="js";function No(){return typeof W.dist.process<"u"&&typeof W.dist.process.versions<"u"&&typeof W.dist.process.versions.node<"u"}function xr(){return!Io()&&!!Po()&&navigator.product===O_}function Dr(){return!No()&&!!Po()&&!!Io()}function vi(){return xr()?Qe.reactNative:No()?Qe.node:Dr()?Qe.browser:Qe.unknown}function N_(){var a;try{return xr()&&typeof W.dist.global<"u"&&typeof(W.dist.global==null?void 0:W.dist.global.Application)<"u"?(a=W.dist.global.Application)==null?void 0:a.applicationId:void 0}catch{return}}function C_(a,t){let r=ze.queryString.parse(a);return r=Iu(Iu({},r),t),a=ze.queryString.stringify(r),a}function $_(){return Sh()||{name:"",description:"",url:"",icons:[""]}}function T_(){if(vi()===Qe.reactNative&&typeof W.dist.global<"u"&&typeof(W.dist.global==null?void 0:W.dist.global.Platform)<"u"){const{OS:r,Version:s}=W.dist.global.Platform;return[r,s].join("-")}const a=E.detect();if(a===null)return"unknown";const t=a.os?a.os.replace(" ","").toLowerCase():"unknown";return a.type==="browser"?[t,a.name,a.version].join("-"):[t,a.version].join("-")}function A_(){var a;const t=vi();return t===Qe.browser?[t,((a=Ph())==null?void 0:a.host)||"unknown"].join(":"):t}function x_(a,t,r){const s=T_(),o=A_();return[[a,t].join("-"),[R_,r].join("-"),s,o].join("/")}function D_({protocol:a,version:t,relayUrl:r,sdkVersion:s,auth:o,projectId:u,useOnCloseEvent:l,bundleId:g}){const w=r.split("?"),b=x_(a,t,s),C={auth:o,ua:b,projectId:u,useOnCloseEvent:l,origin:g||void 0},O=C_(w[1]||"",C);return w[0]+"?"+O}function ir(a,t){return a.filter(r=>t.includes(r)).length===a.length}function $h(a){return Object.fromEntries(a.entries())}function Th(a){return new Map(Object.entries(a))}function Or(a=j.cjs.FIVE_MINUTES,t){const r=j.cjs.toMiliseconds(a||j.cjs.FIVE_MINUTES);let s,o,u;return{resolve:l=>{u&&s&&(clearTimeout(u),s(l))},reject:l=>{u&&o&&(clearTimeout(u),o(l))},done:()=>new Promise((l,g)=>{u=setTimeout(()=>{g(new Error(t))},r),s=l,o=g})}}function gi(a,t,r){return new Promise(async(s,o)=>{const u=setTimeout(()=>o(new Error(r)),t);try{const l=await a;s(l)}catch(l){o(l)}clearTimeout(u)})}function Ah(a,t){if(typeof t=="string"&&t.startsWith(`${a}:`))return t;if(a.toLowerCase()==="topic"){if(typeof t!="string")throw new Error('Value must be "string" for expirer target type: topic');return`topic:${t}`}else if(a.toLowerCase()==="id"){if(typeof t!="number")throw new Error('Value must be "number" for expirer target type: id');return`id:${t}`}throw new Error(`Unknown expirer target type: ${a}`)}function F_(a){return Ah("topic",a)}function j_(a){return Ah("id",a)}function xh(a){const[t,r]=a.split(":"),s={id:void 0,topic:void 0};if(t==="topic"&&typeof r=="string")s.topic=r;else if(t==="id"&&Number.isInteger(Number(r)))s.id=Number(r);else throw new Error(`Invalid target, expected id:number or topic:string, got ${t}:${r}`);return s}function ft(a,t){return j.cjs.fromMiliseconds(Date.now()+j.cjs.toMiliseconds(a))}function Ht(a){return Date.now()>=j.cjs.toMiliseconds(a)}function me(a,t){return`${a}${t?`:${t}`:""}`}function Zn(a=[],t=[]){return[...new Set([...a,...t])]}async function q_({id:a,topic:t,wcDeepLink:r}){try{if(!r)return;const s=typeof r=="string"?JSON.parse(r):r;let o=s==null?void 0:s.href;if(typeof o!="string")return;o.endsWith("/")&&(o=o.slice(0,-1));const u=`${o}/wc?requestId=${a}&sessionTopic=${t}`,l=vi();l===Qe.browser?u.startsWith("https://")?window.open(u,"_blank","noreferrer noopener"):window.open(u,"_self","noreferrer noopener"):l===Qe.reactNative&&typeof(W.dist.global==null?void 0:W.dist.global.Linking)<"u"&&await W.dist.global.Linking.openURL(u)}catch(s){console.error(s)}}async function U_(a,t){try{return await a.getItem(t)||(Dr()?localStorage.getItem(t):void 0)}catch(r){console.error(r)}}const M_="irn";function vo(a){return(a==null?void 0:a.relay)||{protocol:M_}}function vs(a){const t=E.C[a];if(typeof t>"u")throw new Error(`Relay Protocol not supported: ${a}`);return t}var L_=Object.defineProperty,Pu=Object.getOwnPropertySymbols,k_=Object.prototype.hasOwnProperty,z_=Object.prototype.propertyIsEnumerable,Su=(a,t,r)=>t in a?L_(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,H_=(a,t)=>{for(var r in t||(t={}))k_.call(t,r)&&Su(a,r,t[r]);if(Pu)for(var r of Pu(t))z_.call(t,r)&&Su(a,r,t[r]);return a};function V_(a,t="-"){const r={},s="relay"+t;return Object.keys(a).forEach(o=>{if(o.startsWith(s)){const u=o.replace(s,""),l=a[o];r[u]=l}}),r}function Ou(a){a=a.includes("wc://")?a.replace("wc://",""):a,a=a.includes("wc:")?a.replace("wc:",""):a;const t=a.indexOf(":"),r=a.indexOf("?")!==-1?a.indexOf("?"):void 0,s=a.substring(0,t),o=a.substring(t+1,r).split("@"),u=typeof r<"u"?a.substring(r):"",l=ze.queryString.parse(u);return{protocol:s,topic:K_(o[0]),version:parseInt(o[1],10),symKey:l.symKey,relay:V_(l)}}function K_(a){return a.startsWith("//")?a.substring(2):a}function B_(a,t="-"){const r="relay",s={};return Object.keys(a).forEach(o=>{const u=r+t+o;a[o]&&(s[u]=a[o])}),s}function W_(a){return`${a.protocol}:${a.topic}@${a.version}?`+ze.queryString.stringify(H_({symKey:a.symKey},B_(a.relay)))}function Fr(a){const t=[];return a.forEach(r=>{const[s,o]=r.split(":");t.push(`${s}:${o}`)}),t}function J_(a){const t=[];return Object.values(a).forEach(r=>{t.push(...Fr(r.accounts))}),t}function G_(a,t){const r=[];return Object.values(a).forEach(s=>{Fr(s.accounts).includes(t)&&r.push(...s.methods)}),r}function Q_(a,t){const r=[];return Object.values(a).forEach(s=>{Fr(s.accounts).includes(t)&&r.push(...s.events)}),r}function Y_(a,t){const r=ms(a,t);if(r)throw new Error(r.message);const s={};for(const[o,u]of Object.entries(a))s[o]={methods:u.methods,events:u.events,chains:u.accounts.map(l=>`${l.split(":")[0]}:${l.split(":")[1]}`)};return s}function Co(a){return a.includes(":")}function li(a){return Co(a)?a.split(":")[0]:a}const Z_={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},X_={NOT_INITIALIZED:{message:"Not initialized.",code:1},NO_MATCHING_KEY:{message:"No matching key.",code:2},RESTORE_WILL_OVERRIDE:{message:"Restore will override.",code:3},RESUBSCRIBED:{message:"Resubscribed.",code:4},MISSING_OR_INVALID:{message:"Missing or invalid.",code:5},EXPIRED:{message:"Expired.",code:6},UNKNOWN_TYPE:{message:"Unknown type.",code:7},MISMATCHED_TOPIC:{message:"Mismatched topic.",code:8},NON_CONFORMING_NAMESPACES:{message:"Non conforming namespaces.",code:9}};function $(a,t){const{message:r,code:s}=X_[a];return{message:t?`${r} ${t}`:r,code:s}}function ve(a,t){const{message:r,code:s}=Z_[a];return{message:t?`${r} ${t}`:r,code:s}}function sr(a,t){return!!Array.isArray(a)}function Cr(a){return Object.getPrototypeOf(a)===Object.prototype&&Object.keys(a).length}function xe(a){return typeof a>"u"}function Ee(a,t){return t&&xe(a)?!0:typeof a=="string"&&!!a.trim().length}function $o(a,t){return t&&xe(a)?!0:typeof a=="number"&&!isNaN(a)}function e1(a,t){const{requiredNamespaces:r}=t,s=Object.keys(a.namespaces),o=Object.keys(r);let u=!0;return ir(o,s)?(s.forEach(l=>{const{accounts:g,methods:w,events:b}=a.namespaces[l],C=Fr(g),O=r[l];(!ir(Oh(l,O),C)||!ir(O.methods,w)||!ir(O.events,b))&&(u=!1)}),u):!1}function _s(a){return Ee(a,!1)&&a.includes(":")?a.split(":").length===2:!1}function t1(a){if(Ee(a,!1)&&a.includes(":")){const t=a.split(":");if(t.length===3){const r=t[0]+":"+t[1];return!!t[2]&&_s(r)}}return!1}function r1(a){if(Ee(a,!1))try{return typeof new URL(a)<"u"}catch{return!1}return!1}function i1(a){var t;return(t=a==null?void 0:a.proposer)==null?void 0:t.publicKey}function s1(a){return a==null?void 0:a.topic}function n1(a,t){let r=null;return Ee(a==null?void 0:a.publicKey,!1)||(r=$("MISSING_OR_INVALID",`${t} controller public key should be a string`)),r}function Ru(a){let t=!0;return sr(a)?a.length&&(t=a.every(r=>Ee(r,!1))):t=!1,t}function o1(a,t,r){let s=null;return sr(t)&&t.length?t.forEach(o=>{s||_s(o)||(s=ve("UNSUPPORTED_CHAINS",`${r}, chain ${o} should be a string and conform to "namespace:chainId" format`))}):_s(a)||(s=ve("UNSUPPORTED_CHAINS",`${r}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),s}function a1(a,t,r){let s=null;return Object.entries(a).forEach(([o,u])=>{if(s)return;const l=o1(o,Oh(o,u),`${t} ${r}`);l&&(s=l)}),s}function c1(a,t){let r=null;return sr(a)?a.forEach(s=>{r||t1(s)||(r=ve("UNSUPPORTED_ACCOUNTS",`${t}, account ${s} should be a string and conform to "namespace:chainId:address" format`))}):r=ve("UNSUPPORTED_ACCOUNTS",`${t}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),r}function u1(a,t){let r=null;return Object.values(a).forEach(s=>{if(r)return;const o=c1(s==null?void 0:s.accounts,`${t} namespace`);o&&(r=o)}),r}function h1(a,t){let r=null;return Ru(a==null?void 0:a.methods)?Ru(a==null?void 0:a.events)||(r=ve("UNSUPPORTED_EVENTS",`${t}, events should be an array of strings or empty array for no events`)):r=ve("UNSUPPORTED_METHODS",`${t}, methods should be an array of strings or empty array for no methods`),r}function Dh(a,t){let r=null;return Object.values(a).forEach(s=>{if(r)return;const o=h1(s,`${t}, namespace`);o&&(r=o)}),r}function l1(a,t,r){let s=null;if(a&&Cr(a)){const o=Dh(a,t);o&&(s=o);const u=a1(a,t,r);u&&(s=u)}else s=$("MISSING_OR_INVALID",`${t}, ${r} should be an object with data`);return s}function ms(a,t){let r=null;if(a&&Cr(a)){const s=Dh(a,t);s&&(r=s);const o=u1(a,t);o&&(r=o)}else r=$("MISSING_OR_INVALID",`${t}, namespaces should be an object with data`);return r}function Fh(a){return Ee(a.protocol,!0)}function p1(a,t){let r=!1;return a?a&&sr(a)&&a.length&&a.forEach(s=>{r=Fh(s)}):r=!0,r}function f1(a){return typeof a=="number"}function ke(a){return typeof a<"u"&&typeof a!==null}function d1(a){return!(!a||typeof a!="object"||!a.code||!$o(a.code,!1)||!a.message||!Ee(a.message,!1))}function g1(a){return!(xe(a)||!Ee(a.method,!1))}function y1(a){return!(xe(a)||xe(a.result)&&xe(a.error)||!$o(a.id,!1)||!Ee(a.jsonrpc,!1))}function v1(a){return!(xe(a)||!Ee(a.name,!1))}function Nu(a,t){return!(!_s(t)||!J_(a).includes(t))}function m1(a,t,r){return Ee(r,!1)?G_(a,t).includes(r):!1}function w1(a,t,r){return Ee(r,!1)?Q_(a,t).includes(r):!1}function Cu(a,t,r){let s=null;const o=_1(a),u=b1(t),l=Object.keys(o),g=Object.keys(u),w=$u(Object.keys(a)),b=$u(Object.keys(t)),C=w.filter(O=>!b.includes(O));return C.length&&(s=$("NON_CONFORMING_NAMESPACES",`${r} namespaces keys don't satisfy requiredNamespaces.
|
|
15
|
+
Required: ${C.toString()}
|
|
16
|
+
Received: ${Object.keys(t).toString()}`)),ir(l,g)||(s=$("NON_CONFORMING_NAMESPACES",`${r} namespaces chains don't satisfy required namespaces.
|
|
17
|
+
Required: ${l.toString()}
|
|
18
|
+
Approved: ${g.toString()}`)),Object.keys(t).forEach(O=>{if(!O.includes(":")||s)return;const N=Fr(t[O].accounts);N.includes(O)||(s=$("NON_CONFORMING_NAMESPACES",`${r} namespaces accounts don't satisfy namespace accounts for ${O}
|
|
19
|
+
Required: ${O}
|
|
20
|
+
Approved: ${N.toString()}`))}),l.forEach(O=>{s||(ir(o[O].methods,u[O].methods)?ir(o[O].events,u[O].events)||(s=$("NON_CONFORMING_NAMESPACES",`${r} namespaces events don't satisfy namespace events for ${O}`)):s=$("NON_CONFORMING_NAMESPACES",`${r} namespaces methods don't satisfy namespace methods for ${O}`))}),s}function _1(a){const t={};return Object.keys(a).forEach(r=>{var s;r.includes(":")?t[r]=a[r]:(s=a[r].chains)==null||s.forEach(o=>{t[o]={methods:a[r].methods,events:a[r].events}})}),t}function $u(a){return[...new Set(a.map(t=>t.includes(":")?t.split(":")[0]:t))]}function b1(a){const t={};return Object.keys(a).forEach(r=>{if(r.includes(":"))t[r]=a[r];else{const s=Fr(a[r].accounts);s==null||s.forEach(o=>{t[o]={accounts:a[r].accounts.filter(u=>u.includes(`${o}:`)),methods:a[r].methods,events:a[r].events}})}}),t}function E1(a,t){return $o(a,!1)&&a<=t.max&&a>=t.min}function Tu(){const a=vi();return new Promise(t=>{switch(a){case Qe.browser:t(I1());break;case Qe.reactNative:t(P1());break;case Qe.node:t(S1());break;default:t(!0)}})}function I1(){return Dr()&&(navigator==null?void 0:navigator.onLine)}async function P1(){if(xr()&&typeof W.dist.global<"u"&&W.dist.global!=null&&W.dist.global.NetInfo){const a=await(W.dist.global==null?void 0:W.dist.global.NetInfo.fetch());return a==null?void 0:a.isConnected}return!0}function S1(){return!0}function O1(a){switch(vi()){case Qe.browser:R1(a);break;case Qe.reactNative:N1(a);break}}function R1(a){!xr()&&Dr()&&(window.addEventListener("online",()=>a(!0)),window.addEventListener("offline",()=>a(!1)))}function N1(a){var t;xr()&&typeof W.dist.global<"u"&&W.dist.global!=null&&W.dist.global.NetInfo&&((t=W.dist.global)==null||t.NetInfo.addEventListener(r=>a(r==null?void 0:r.isConnected)))}const Xn={};let fs=class{static get(t){return Xn[t]}static set(t,r){Xn[t]=r}static delete(t){delete Xn[t]}};class Tt extends E.r{constructor(t){super(t),this.events=new He.eventsExports.EventEmitter,this.hasRegisteredEventListeners=!1,this.connection=this.setConnection(t),this.connection.connected&&this.registerEventListeners()}async connect(t=this.connection){await this.open(t)}async disconnect(){await this.close()}on(t,r){this.events.on(t,r)}once(t,r){this.events.once(t,r)}off(t,r){this.events.off(t,r)}removeListener(t,r){this.events.removeListener(t,r)}async request(t,r){return this.requestStrict(E.formatJsonRpcRequest(t.method,t.params||[],t.id||E.getBigIntRpcId().toString()),r)}async requestStrict(t,r){return new Promise(async(s,o)=>{if(!this.connection.connected)try{await this.open()}catch(u){o(u)}this.events.on(`${t.id}`,u=>{E.isJsonRpcError(u)?o(u.error):s(u.result)});try{await this.connection.send(t,r)}catch(u){o(u)}})}setConnection(t=this.connection){return t}onPayload(t){this.events.emit("payload",t),E.isJsonRpcResponse(t)?this.events.emit(`${t.id}`,t):this.events.emit("message",{type:t.method,data:t.params})}onClose(t){t&&t.code===3e3&&this.events.emit("error",new Error(`WebSocket connection closed abnormally with code: ${t.code} ${t.reason?`(${t.reason})`:""}`)),this.events.emit("disconnect")}async open(t=this.connection){this.connection===t&&this.connection.connected||(this.connection.connected&&this.close(),typeof t=="string"&&(await this.connection.open(t),t=this.connection),this.connection=this.setConnection(t),await this.connection.open(),this.registerEventListeners(),this.events.emit("connect"))}async close(){await this.connection.close()}registerEventListeners(){this.hasRegisteredEventListeners||(this.connection.on("payload",t=>this.onPayload(t)),this.connection.on("close",t=>this.onClose(t)),this.connection.on("error",t=>this.events.emit("error",t)),this.connection.on("register_error",t=>this.onClose()),this.hasRegisteredEventListeners=!0)}}const C1=()=>typeof WebSocket<"u"?WebSocket:typeof W.dist.global<"u"&&typeof W.dist.global.WebSocket<"u"?W.dist.global.WebSocket:typeof window<"u"&&typeof window.WebSocket<"u"?window.WebSocket:typeof self<"u"&&typeof self.WebSocket<"u"?self.WebSocket:require("ws"),$1=()=>typeof WebSocket<"u"||typeof W.dist.global<"u"&&typeof W.dist.global.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",Au=a=>a.split("?")[0],xu=10,T1=C1();let A1=class{constructor(t){if(this.url=t,this.events=new He.eventsExports.EventEmitter,this.registering=!1,!E.isWsUrl(t))throw new Error(`Provided URL is not compatible with WebSocket connection: ${t}`);this.url=t}get connected(){return typeof this.socket<"u"}get connecting(){return this.registering}on(t,r){this.events.on(t,r)}once(t,r){this.events.once(t,r)}off(t,r){this.events.off(t,r)}removeListener(t,r){this.events.removeListener(t,r)}async open(t=this.url){await this.register(t)}async close(){return new Promise((t,r)=>{if(typeof this.socket>"u"){r(new Error("Connection already closed"));return}this.socket.onclose=s=>{this.onClose(s),t()},this.socket.close()})}async send(t){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(Ih(t))}catch(r){this.onError(t.id,r)}}register(t=this.url){if(!E.isWsUrl(t))throw new Error(`Provided URL is not compatible with WebSocket connection: ${t}`);if(this.registering){const r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((s,o)=>{this.events.once("register_error",u=>{this.resetMaxListeners(),o(u)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.socket>"u")return o(new Error("WebSocket connection is missing or invalid"));s(this.socket)})})}return this.url=t,this.registering=!0,new Promise((r,s)=>{const o=new URLSearchParams(t).get("origin"),u=E.cjs.isReactNative()?{headers:{origin:o}}:{rejectUnauthorized:!E.isLocalhostUrl(t)},l=new T1(t,[],u);$1()?l.onerror=g=>{const w=g;s(this.emitError(w.error))}:l.on("error",g=>{s(this.emitError(g))}),l.onopen=()=>{this.onOpen(l),r(l)}})}onOpen(t){t.onmessage=r=>this.onPayload(r),t.onclose=r=>this.onClose(r),this.socket=t,this.registering=!1,this.events.emit("open")}onClose(t){this.socket=void 0,this.registering=!1,this.events.emit("close",t)}onPayload(t){if(typeof t.data>"u")return;const r=typeof t.data=="string"?Eh(t.data):t.data;this.events.emit("payload",r)}onError(t,r){const s=this.parseError(r),o=s.message||s.toString(),u=E.formatJsonRpcError(t,o);this.events.emit("payload",u)}parseError(t,r=this.url){return E.parseConnectionError(t,Au(r),"WS")}resetMaxListeners(){this.events.getMaxListeners()>xu&&this.events.setMaxListeners(xu)}emitError(t){const r=this.parseError(new Error((t==null?void 0:t.message)||`WebSocket connection failed for host: ${Au(this.url)}`));return this.events.emit("register_error",r),r}};function x1(a,t){return t=t||{},new Promise(function(r,s){var o=new XMLHttpRequest,u=[],l=[],g={},w=function(){return{ok:(o.status/100|0)==2,statusText:o.statusText,status:o.status,url:o.responseURL,text:function(){return Promise.resolve(o.responseText)},json:function(){return Promise.resolve(o.responseText).then(JSON.parse)},blob:function(){return Promise.resolve(new Blob([o.response]))},clone:w,headers:{keys:function(){return u},entries:function(){return l},get:function(C){return g[C.toLowerCase()]},has:function(C){return C.toLowerCase()in g}}}};for(var b in o.open(t.method||"get",a,!0),o.onload=function(){o.getAllResponseHeaders().replace(/^(.*?):[^\S\n]*([\s\S]*?)$/gm,function(C,O,N){u.push(O=O.toLowerCase()),l.push([O,N]),g[O]=g[O]?g[O]+","+N:N}),r(w())},o.onerror=s,o.withCredentials=t.credentials=="include",t.headers)o.setRequestHeader(b,t.headers[b]);o.send(t.body||null)})}const D1=Object.freeze(Object.defineProperty({__proto__:null,default:x1},Symbol.toStringTag,{value:"Module"})),Du=W.getAugmentedNamespace(D1);var F1=self.fetch||(self.fetch=Du.default||Du);const j1=W.getDefaultExportFromCjs(F1);function q1(a,t){if(a.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),s=0;s<r.length;s++)r[s]=255;for(var o=0;o<a.length;o++){var u=a.charAt(o),l=u.charCodeAt(0);if(r[l]!==255)throw new TypeError(u+" is ambiguous");r[l]=o}var g=a.length,w=a.charAt(0),b=Math.log(g)/Math.log(256),C=Math.log(256)/Math.log(g);function O(x){if(x instanceof Uint8Array||(ArrayBuffer.isView(x)?x=new Uint8Array(x.buffer,x.byteOffset,x.byteLength):Array.isArray(x)&&(x=Uint8Array.from(x))),!(x instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(x.length===0)return"";for(var K=0,D=0,Q=0,fe=x.length;Q!==fe&&x[Q]===0;)Q++,K++;for(var Z=(fe-Q)*C+1>>>0,ee=new Uint8Array(Z);Q!==fe;){for(var he=x[Q],Fe=0,de=Z-1;(he!==0||Fe<D)&&de!==-1;de--,Fe++)he+=256*ee[de]>>>0,ee[de]=he%g>>>0,he=he/g>>>0;if(he!==0)throw new Error("Non-zero carry");D=Fe,Q++}for(var Ce=Z-D;Ce!==Z&&ee[Ce]===0;)Ce++;for(var xt=w.repeat(K);Ce<Z;++Ce)xt+=a.charAt(ee[Ce]);return xt}function N(x){if(typeof x!="string")throw new TypeError("Expected String");if(x.length===0)return new Uint8Array;var K=0;if(x[K]!==" "){for(var D=0,Q=0;x[K]===w;)D++,K++;for(var fe=(x.length-K)*b+1>>>0,Z=new Uint8Array(fe);x[K];){var ee=r[x.charCodeAt(K)];if(ee===255)return;for(var he=0,Fe=fe-1;(ee!==0||he<Q)&&Fe!==-1;Fe--,he++)ee+=g*Z[Fe]>>>0,Z[Fe]=ee%256>>>0,ee=ee/256>>>0;if(ee!==0)throw new Error("Non-zero carry");Q=he,K++}if(x[K]!==" "){for(var de=fe-Q;de!==fe&&Z[de]===0;)de++;for(var Ce=new Uint8Array(D+(fe-de)),xt=D;de!==fe;)Ce[xt++]=Z[de++];return Ce}}}function q(x){var K=N(x);if(K)return K;throw new Error(`Non-${t} character`)}return{encode:O,decodeUnsafe:N,decode:q}}var U1=q1,M1=U1;const jh=a=>{if(a instanceof Uint8Array&&a.constructor.name==="Uint8Array")return a;if(a instanceof ArrayBuffer)return new Uint8Array(a);if(ArrayBuffer.isView(a))return new Uint8Array(a.buffer,a.byteOffset,a.byteLength);throw new Error("Unknown type, must be binary type")},L1=a=>new TextEncoder().encode(a),k1=a=>new TextDecoder().decode(a);class z1{constructor(t,r,s){this.name=t,this.prefix=r,this.baseEncode=s}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}}class H1{constructor(t,r,s){if(this.name=t,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=s}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return qh(this,t)}}class V1{constructor(t){this.decoders=t}or(t){return qh(this,t)}decode(t){const r=t[0],s=this.decoders[r];if(s)return s.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const qh=(a,t)=>new V1({...a.decoders||{[a.prefix]:a},...t.decoders||{[t.prefix]:t}});class K1{constructor(t,r,s,o){this.name=t,this.prefix=r,this.baseEncode=s,this.baseDecode=o,this.encoder=new z1(t,r,s),this.decoder=new H1(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}}const Ss=({name:a,prefix:t,encode:r,decode:s})=>new K1(a,t,r,s),mi=({prefix:a,name:t,alphabet:r})=>{const{encode:s,decode:o}=M1(r,t);return Ss({prefix:a,name:t,encode:s,decode:u=>jh(o(u))})},B1=(a,t,r,s)=>{const o={};for(let C=0;C<t.length;++C)o[t[C]]=C;let u=a.length;for(;a[u-1]==="=";)--u;const l=new Uint8Array(u*r/8|0);let g=0,w=0,b=0;for(let C=0;C<u;++C){const O=o[a[C]];if(O===void 0)throw new SyntaxError(`Non-${s} character`);w=w<<r|O,g+=r,g>=8&&(g-=8,l[b++]=255&w>>g)}if(g>=r||255&w<<8-g)throw new SyntaxError("Unexpected end of data");return l},W1=(a,t,r)=>{const s=t[t.length-1]==="=",o=(1<<r)-1;let u="",l=0,g=0;for(let w=0;w<a.length;++w)for(g=g<<8|a[w],l+=8;l>r;)l-=r,u+=t[o&g>>l];if(l&&(u+=t[o&g<<r-l]),s)for(;u.length*r&7;)u+="=";return u},Se=({name:a,prefix:t,bitsPerChar:r,alphabet:s})=>Ss({prefix:t,name:a,encode(o){return W1(o,s,r)},decode(o){return B1(o,s,r,a)}}),J1=Ss({prefix:"\0",name:"identity",encode:a=>k1(a),decode:a=>L1(a)});var G1=Object.freeze({__proto__:null,identity:J1});const Q1=Se({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Y1=Object.freeze({__proto__:null,base2:Q1});const Z1=Se({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var X1=Object.freeze({__proto__:null,base8:Z1});const e0=mi({prefix:"9",name:"base10",alphabet:"0123456789"});var t0=Object.freeze({__proto__:null,base10:e0});const r0=Se({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),i0=Se({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var s0=Object.freeze({__proto__:null,base16:r0,base16upper:i0});const n0=Se({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),o0=Se({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),a0=Se({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),c0=Se({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),u0=Se({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),h0=Se({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),l0=Se({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),p0=Se({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),f0=Se({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var d0=Object.freeze({__proto__:null,base32:n0,base32upper:o0,base32pad:a0,base32padupper:c0,base32hex:u0,base32hexupper:h0,base32hexpad:l0,base32hexpadupper:p0,base32z:f0});const g0=mi({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),y0=mi({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var v0=Object.freeze({__proto__:null,base36:g0,base36upper:y0});const m0=mi({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),w0=mi({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _0=Object.freeze({__proto__:null,base58btc:m0,base58flickr:w0});const b0=Se({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),E0=Se({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),I0=Se({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),P0=Se({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var S0=Object.freeze({__proto__:null,base64:b0,base64pad:E0,base64url:I0,base64urlpad:P0});const Uh=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),O0=Uh.reduce((a,t,r)=>(a[r]=t,a),[]),R0=Uh.reduce((a,t,r)=>(a[t.codePointAt(0)]=r,a),[]);function N0(a){return a.reduce((t,r)=>(t+=O0[r],t),"")}function C0(a){const t=[];for(const r of a){const s=R0[r.codePointAt(0)];if(s===void 0)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}const $0=Ss({prefix:"🚀",name:"base256emoji",encode:N0,decode:C0});var T0=Object.freeze({__proto__:null,base256emoji:$0}),A0=Mh,Fu=128,x0=-128,D0=Math.pow(2,31);function Mh(a,t,r){t=t||[],r=r||0;for(var s=r;a>=D0;)t[r++]=a&255|Fu,a/=128;for(;a&x0;)t[r++]=a&255|Fu,a>>>=7;return t[r]=a|0,Mh.bytes=r-s+1,t}var F0=mo,j0=128,ju=127;function mo(a,s){var r=0,s=s||0,o=0,u=s,l,g=a.length;do{if(u>=g)throw mo.bytes=0,new RangeError("Could not decode varint");l=a[u++],r+=o<28?(l&ju)<<o:(l&ju)*Math.pow(2,o),o+=7}while(l>=j0);return mo.bytes=u-s,r}var q0=Math.pow(2,7),U0=Math.pow(2,14),M0=Math.pow(2,21),L0=Math.pow(2,28),k0=Math.pow(2,35),z0=Math.pow(2,42),H0=Math.pow(2,49),V0=Math.pow(2,56),K0=Math.pow(2,63),B0=function(a){return a<q0?1:a<U0?2:a<M0?3:a<L0?4:a<k0?5:a<z0?6:a<H0?7:a<V0?8:a<K0?9:10},W0={encode:A0,decode:F0,encodingLength:B0},Lh=W0;const qu=(a,t,r=0)=>(Lh.encode(a,t,r),t),Uu=a=>Lh.encodingLength(a),wo=(a,t)=>{const r=t.byteLength,s=Uu(a),o=s+Uu(r),u=new Uint8Array(o+r);return qu(a,u,0),qu(r,u,s),u.set(t,o),new J0(a,r,t,u)};class J0{constructor(t,r,s,o){this.code=t,this.size=r,this.digest=s,this.bytes=o}}const kh=({name:a,code:t,encode:r})=>new G0(a,t,r);class G0{constructor(t,r,s){this.name=t,this.code=r,this.encode=s}digest(t){if(t instanceof Uint8Array){const r=this.encode(t);return r instanceof Uint8Array?wo(this.code,r):r.then(s=>wo(this.code,s))}else throw Error("Unknown type, must be binary type")}}const zh=a=>async t=>new Uint8Array(await crypto.subtle.digest(a,t)),Q0=kh({name:"sha2-256",code:18,encode:zh("SHA-256")}),Y0=kh({name:"sha2-512",code:19,encode:zh("SHA-512")});var Z0=Object.freeze({__proto__:null,sha256:Q0,sha512:Y0});const Hh=0,X0="identity",Vh=jh,eb=a=>wo(Hh,Vh(a)),tb={code:Hh,name:X0,encode:Vh,digest:eb};var rb=Object.freeze({__proto__:null,identity:tb});new TextEncoder,new TextDecoder;const Mu={...G1,...Y1,...X1,...t0,...s0,...d0,...v0,..._0,...S0,...T0};({...Z0,...rb});function Kh(a){return globalThis.Buffer!=null?new Uint8Array(a.buffer,a.byteOffset,a.byteLength):a}function ib(a=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Kh(globalThis.Buffer.allocUnsafe(a)):new Uint8Array(a)}function Bh(a,t,r,s){return{name:a,prefix:t,encoder:{name:a,prefix:t,encode:r},decoder:{decode:s}}}const Lu=Bh("utf8","u",a=>"u"+new TextDecoder("utf8").decode(a),a=>new TextEncoder().encode(a.substring(1))),eo=Bh("ascii","a",a=>{let t="a";for(let r=0;r<a.length;r++)t+=String.fromCharCode(a[r]);return t},a=>{a=a.substring(1);const t=ib(a.length);for(let r=0;r<a.length;r++)t[r]=a.charCodeAt(r);return t}),sb={utf8:Lu,"utf-8":Lu,hex:Mu.base16,latin1:eo,ascii:eo,binary:eo,...Mu};function nb(a,t="utf8"){const r=sb[t];if(!r)throw new Error(`Unsupported encoding "${t}"`);return(t==="utf8"||t==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Kh(globalThis.Buffer.from(a,"utf-8")):r.decoder.decode(`${r.prefix}${a}`)}const Wh="wc",ob=2,Jh="core",Vt=`${Wh}@2:${Jh}:`,ab={logger:"error"},cb={database:":memory:"},ub="crypto",ku="client_ed25519_seed",hb=j.cjs.ONE_DAY,lb="keychain",pb="0.3",fb="messages",db="0.3",gb=j.cjs.SIX_HOURS,yb="publisher",Gh="irn",vb="error",Qh="wss://relay.walletconnect.com",zu="wss://relay.walletconnect.org",mb="relayer",Ne={message:"relayer_message",message_ack:"relayer_message_ack",connect:"relayer_connect",disconnect:"relayer_disconnect",error:"relayer_error",connection_stalled:"relayer_connection_stalled",transport_closed:"relayer_transport_closed",publish:"relayer_publish"},wb="_subscription",Ct={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},_b=j.cjs.ONE_SECOND,bb="2.11.0",Eb=1e4,Ib="0.3",Pb="WALLETCONNECT_CLIENT_ID",pt={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},Sb="subscription",Ob="0.3",Rb=j.cjs.FIVE_SECONDS*1e3,Nb="pairing",Cb="0.3",oi={wc_pairingDelete:{req:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:1e3},res:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:1001}},wc_pairingPing:{req:{ttl:j.cjs.THIRTY_SECONDS,prompt:!1,tag:1002},res:{ttl:j.cjs.THIRTY_SECONDS,prompt:!1,tag:1003}},unregistered_method:{req:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:0},res:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:0}}},pi={create:"pairing_create",expire:"pairing_expire",delete:"pairing_delete",ping:"pairing_ping"},mt={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},$b="history",Tb="0.3",Ab="expirer",nt={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},xb="0.3",to="verify-api",Rr="https://verify.walletconnect.com",_o="https://verify.walletconnect.org",Db=[Rr,_o],Fb="echo",jb="https://echo.walletconnect.com";class qb{constructor(t,r){this.core=t,this.logger=r,this.keychain=new Map,this.name=lb,this.version=pb,this.initialized=!1,this.storagePrefix=Vt,this.init=async()=>{if(!this.initialized){const s=await this.getKeyChain();typeof s<"u"&&(this.keychain=s),this.initialized=!0}},this.has=s=>(this.isInitialized(),this.keychain.has(s)),this.set=async(s,o)=>{this.isInitialized(),this.keychain.set(s,o),await this.persist()},this.get=s=>{this.isInitialized();const o=this.keychain.get(s);if(typeof o>"u"){const{message:u}=$("NO_MATCHING_KEY",`${this.name}: ${s}`);throw new Error(u)}return o},this.del=async s=>{this.isInitialized(),this.keychain.delete(s),await this.persist()},this.core=t,this.logger=E.E(r,this.name)}get context(){return E.y(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(t){await this.core.storage.setItem(this.storageKey,$h(t))}async getKeyChain(){const t=await this.core.storage.getItem(this.storageKey);return typeof t<"u"?Th(t):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}}class Ub{constructor(t,r,s){this.core=t,this.logger=r,this.name=ub,this.initialized=!1,this.init=async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)},this.hasKeys=o=>(this.isInitialized(),this.keychain.has(o)),this.getClientId=async()=>{this.isInitialized();const o=await this.getClientSeed(),u=E.Po(o);return E.Qe(u.publicKey)},this.generateKeyPair=()=>{this.isInitialized();const o=g_();return this.setPrivateKey(o.publicKey,o.privateKey)},this.signJWT=async o=>{this.isInitialized();const u=await this.getClientSeed(),l=E.Po(u),g=yo(),w=hb;return await E.Qo(g,o,w,l)},this.generateSharedKey=(o,u,l)=>{this.isInitialized();const g=this.getPrivateKey(o),w=y_(g,u);return this.setSymKey(w,l)},this.setSymKey=async(o,u)=>{this.isInitialized();const l=u||v_(o);return await this.keychain.set(l,o),l},this.deleteKeyPair=async o=>{this.isInitialized(),await this.keychain.del(o)},this.deleteSymKey=async o=>{this.isInitialized(),await this.keychain.del(o)},this.encode=async(o,u,l)=>{this.isInitialized();const g=Ch(l),w=Ih(u);if(_u(g)){const N=g.senderPublicKey,q=g.receiverPublicKey;o=await this.generateSharedKey(N,q)}const b=this.getSymKey(o),{type:C,senderPublicKey:O}=g;return w_({type:C,symKey:b,message:w,senderPublicKey:O})},this.decode=async(o,u,l)=>{this.isInitialized();const g=E_(u,l);if(_u(g)){const w=g.receiverPublicKey,b=g.senderPublicKey;o=await this.generateSharedKey(w,b)}try{const w=this.getSymKey(o),b=__({symKey:w,encoded:u});return Eh(b)}catch(w){this.logger.error(`Failed to decode message from topic: '${o}', clientId: '${await this.getClientId()}'`),this.logger.error(w)}},this.getPayloadType=o=>{const u=ws(o);return yi(u.type)},this.getPayloadSenderPublicKey=o=>{const u=ws(o);return u.senderPublicKey?E.toString(u.senderPublicKey,De):void 0},this.core=t,this.logger=E.E(r,this.name),this.keychain=s||new qb(this.core,this.logger)}get context(){return E.y(this.logger)}async setPrivateKey(t,r){return await this.keychain.set(t,r),t}getPrivateKey(t){return this.keychain.get(t)}async getClientSeed(){let t="";try{t=this.keychain.get(ku)}catch{t=yo(),await this.keychain.set(ku,t)}return nb(t,"base16")}getSymKey(t){return this.keychain.get(t)}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}}class Mb extends Hw{constructor(t,r){super(t,r),this.logger=t,this.core=r,this.messages=new Map,this.name=fb,this.version=db,this.initialized=!1,this.storagePrefix=Vt,this.init=async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const s=await this.getRelayerMessages();typeof s<"u"&&(this.messages=s),this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",size:this.messages.size})}catch(s){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(s)}finally{this.initialized=!0}}},this.set=async(s,o)=>{this.isInitialized();const u=Nr(o);let l=this.messages.get(s);return typeof l>"u"&&(l={}),typeof l[u]<"u"||(l[u]=o,this.messages.set(s,l),await this.persist()),u},this.get=s=>{this.isInitialized();let o=this.messages.get(s);return typeof o>"u"&&(o={}),o},this.has=(s,o)=>{this.isInitialized();const u=this.get(s),l=Nr(o);return typeof u[l]<"u"},this.del=async s=>{this.isInitialized(),this.messages.delete(s),await this.persist()},this.logger=E.E(t,this.name),this.core=r}get context(){return E.y(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setRelayerMessages(t){await this.core.storage.setItem(this.storageKey,$h(t))}async getRelayerMessages(){const t=await this.core.storage.getItem(this.storageKey);return typeof t<"u"?Th(t):void 0}async persist(){await this.setRelayerMessages(this.messages)}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}}class Lb extends Vw{constructor(t,r){super(t,r),this.relayer=t,this.logger=r,this.events=new He.eventsExports.EventEmitter,this.name=yb,this.queue=new Map,this.publishTimeout=j.cjs.toMiliseconds(j.cjs.TEN_SECONDS),this.needsTransportRestart=!1,this.publish=async(s,o,u)=>{var l;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:s,message:o,opts:u}});try{const g=(u==null?void 0:u.ttl)||gb,w=vo(u),b=(u==null?void 0:u.prompt)||!1,C=(u==null?void 0:u.tag)||0,O=(u==null?void 0:u.id)||E.getBigIntRpcId().toString(),N={topic:s,message:o,opts:{ttl:g,relay:w,prompt:b,tag:C,id:O}},q=setTimeout(()=>this.queue.set(O,N),this.publishTimeout);try{await await gi(this.rpcPublish(s,o,g,w,b,C,O),this.publishTimeout,"Failed to publish payload, please try again."),this.removeRequestFromQueue(O),this.relayer.events.emit(Ne.publish,N)}catch(x){if(this.logger.debug("Publishing Payload stalled"),this.needsTransportRestart=!0,(l=u==null?void 0:u.internal)!=null&&l.throwOnFailedPublish)throw this.removeRequestFromQueue(O),x;return}finally{clearTimeout(q)}this.logger.debug("Successfully Published Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:s,message:o,opts:u}})}catch(g){throw this.logger.debug("Failed to Publish Payload"),this.logger.error(g),g}},this.on=(s,o)=>{this.events.on(s,o)},this.once=(s,o)=>{this.events.once(s,o)},this.off=(s,o)=>{this.events.off(s,o)},this.removeListener=(s,o)=>{this.events.removeListener(s,o)},this.relayer=t,this.logger=E.E(r,this.name),this.registerEventListeners()}get context(){return E.y(this.logger)}rpcPublish(t,r,s,o,u,l,g){var w,b,C,O;const N={method:vs(o.protocol).publish,params:{topic:t,message:r,ttl:s,prompt:u,tag:l},id:g};return xe((w=N.params)==null?void 0:w.prompt)&&((b=N.params)==null||delete b.prompt),xe((C=N.params)==null?void 0:C.tag)&&((O=N.params)==null||delete O.tag),this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:N}),this.relayer.request(N)}removeRequestFromQueue(t){this.queue.delete(t)}checkQueue(){this.queue.forEach(async t=>{const{topic:r,message:s,opts:o}=t;await this.publish(r,s,o)})}registerEventListeners(){this.relayer.core.heartbeat.on(Tr.HEARTBEAT_EVENTS.pulse,()=>{if(this.needsTransportRestart){this.needsTransportRestart=!1,this.relayer.events.emit(Ne.connection_stalled);return}this.checkQueue()}),this.relayer.on(Ne.message_ack,t=>{this.removeRequestFromQueue(t.id.toString())})}}class kb{constructor(){this.map=new Map,this.set=(t,r)=>{const s=this.get(t);this.exists(t,r)||this.map.set(t,[...s,r])},this.get=t=>this.map.get(t)||[],this.exists=(t,r)=>this.get(t).includes(r),this.delete=(t,r)=>{if(typeof r>"u"){this.map.delete(t);return}if(!this.map.has(t))return;const s=this.get(t);if(!this.exists(t,r))return;const o=s.filter(u=>u!==r);if(!o.length){this.map.delete(t);return}this.map.set(t,o)},this.clear=()=>{this.map.clear()}}get topics(){return Array.from(this.map.keys())}}var zb=Object.defineProperty,Hb=Object.defineProperties,Vb=Object.getOwnPropertyDescriptors,Hu=Object.getOwnPropertySymbols,Kb=Object.prototype.hasOwnProperty,Bb=Object.prototype.propertyIsEnumerable,Vu=(a,t,r)=>t in a?zb(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,ai=(a,t)=>{for(var r in t||(t={}))Kb.call(t,r)&&Vu(a,r,t[r]);if(Hu)for(var r of Hu(t))Bb.call(t,r)&&Vu(a,r,t[r]);return a},ro=(a,t)=>Hb(a,Vb(t));class Wb extends Ww{constructor(t,r){super(t,r),this.relayer=t,this.logger=r,this.subscriptions=new Map,this.topicMap=new kb,this.events=new He.eventsExports.EventEmitter,this.name=Sb,this.version=Ob,this.pending=new Map,this.cached=[],this.initialized=!1,this.pendingSubscriptionWatchLabel="pending_sub_watch_label",this.pollingInterval=20,this.storagePrefix=Vt,this.subscribeTimeout=1e4,this.restartInProgress=!1,this.batchSubscribeTopicsLimit=500,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),this.clientId=await this.relayer.core.crypto.getClientId())},this.subscribe=async(s,o)=>{await this.restartToComplete(),this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:s,opts:o}});try{const u=vo(o),l={topic:s,relay:u};this.pending.set(s,l);const g=await this.rpcSubscribe(s,u);return this.onSubscribe(g,l),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:s,opts:o}}),g}catch(u){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(u),u}},this.unsubscribe=async(s,o)=>{await this.restartToComplete(),this.isInitialized(),typeof(o==null?void 0:o.id)<"u"?await this.unsubscribeById(s,o.id,o):await this.unsubscribeByTopic(s,o)},this.isSubscribed=async s=>this.topics.includes(s)?!0:await new Promise((o,u)=>{const l=new j.cjs.Watch;l.start(this.pendingSubscriptionWatchLabel);const g=setInterval(()=>{!this.pending.has(s)&&this.topics.includes(s)&&(clearInterval(g),l.stop(this.pendingSubscriptionWatchLabel),o(!0)),l.elapsed(this.pendingSubscriptionWatchLabel)>=Rb&&(clearInterval(g),l.stop(this.pendingSubscriptionWatchLabel),u(new Error("Subscription resolution timeout")))},this.pollingInterval)}).catch(()=>!1),this.on=(s,o)=>{this.events.on(s,o)},this.once=(s,o)=>{this.events.once(s,o)},this.off=(s,o)=>{this.events.off(s,o)},this.removeListener=(s,o)=>{this.events.removeListener(s,o)},this.restart=async()=>{this.restartInProgress=!0,await this.restore(),await this.reset(),this.restartInProgress=!1},this.relayer=t,this.logger=E.E(r,this.name),this.clientId=""}get context(){return E.y(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.relayer.core.customStoragePrefix+"//"+this.name}get length(){return this.subscriptions.size}get ids(){return Array.from(this.subscriptions.keys())}get values(){return Array.from(this.subscriptions.values())}get topics(){return this.topicMap.topics}hasSubscription(t,r){let s=!1;try{s=this.getSubscription(t).topic===r}catch{}return s}onEnable(){this.cached=[],this.initialized=!0}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(t,r){const s=this.topicMap.get(t);await Promise.all(s.map(async o=>await this.unsubscribeById(t,o,r)))}async unsubscribeById(t,r,s){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:t,id:r,opts:s}});try{const o=vo(s);await this.rpcUnsubscribe(t,r,o);const u=ve("USER_DISCONNECTED",`${this.name}, ${t}`);await this.onUnsubscribe(t,r,u),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:t,id:r,opts:s}})}catch(o){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(o),o}}async rpcSubscribe(t,r){const s={method:vs(r.protocol).subscribe,params:{topic:t}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:s});try{await await gi(this.relayer.request(s),this.subscribeTimeout)}catch{this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(Ne.connection_stalled)}return Nr(t+this.clientId)}async rpcBatchSubscribe(t){if(!t.length)return;const r=t[0].relay,s={method:vs(r.protocol).batchSubscribe,params:{topics:t.map(o=>o.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:s});try{return await await gi(this.relayer.request(s),this.subscribeTimeout)}catch{this.logger.debug("Outgoing Relay Payload stalled"),this.relayer.events.emit(Ne.connection_stalled)}}rpcUnsubscribe(t,r,s){const o={method:vs(s.protocol).unsubscribe,params:{topic:t,id:r}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:o}),this.relayer.request(o)}onSubscribe(t,r){this.setSubscription(t,ro(ai({},r),{id:t})),this.pending.delete(r.topic)}onBatchSubscribe(t){t.length&&t.forEach(r=>{this.setSubscription(r.id,ai({},r)),this.pending.delete(r.topic)})}async onUnsubscribe(t,r,s){this.events.removeAllListeners(r),this.hasSubscription(r,t)&&this.deleteSubscription(r,s),await this.relayer.messages.del(t)}async setRelayerSubscriptions(t){await this.relayer.core.storage.setItem(this.storageKey,t)}async getRelayerSubscriptions(){return await this.relayer.core.storage.getItem(this.storageKey)}setSubscription(t,r){this.subscriptions.has(t)||(this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:t,subscription:r}),this.addSubscription(t,r))}addSubscription(t,r){this.subscriptions.set(t,ai({},r)),this.topicMap.set(r.topic,t),this.events.emit(pt.created,r)}getSubscription(t){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:t});const r=this.subscriptions.get(t);if(!r){const{message:s}=$("NO_MATCHING_KEY",`${this.name}: ${t}`);throw new Error(s)}return r}deleteSubscription(t,r){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:t,reason:r});const s=this.getSubscription(t);this.subscriptions.delete(t),this.topicMap.delete(s.topic,t),this.events.emit(pt.deleted,ro(ai({},s),{reason:r}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit(pt.sync)}async reset(){if(this.cached.length){const t=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let r=0;r<t;r++){const s=this.cached.splice(0,this.batchSubscribeTopicsLimit);await this.batchSubscribe(s)}}this.events.emit(pt.resubscribed)}async restore(){try{const t=await this.getRelayerSubscriptions();if(typeof t>"u"||!t.length)return;if(this.subscriptions.size){const{message:r}=$("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(r)}this.cached=t,this.logger.debug(`Successfully Restored subscriptions for ${this.name}`),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(t){this.logger.debug(`Failed to Restore subscriptions for ${this.name}`),this.logger.error(t)}}async batchSubscribe(t){if(!t.length)return;const r=await this.rpcBatchSubscribe(t);sr(r)&&this.onBatchSubscribe(r.map((s,o)=>ro(ai({},t[o]),{id:s})))}async onConnect(){this.restartInProgress||(await this.restart(),this.onEnable())}onDisconnect(){this.onDisable()}async checkPending(){if(!this.initialized||this.relayer.transportExplicitlyClosed)return;const t=[];this.pending.forEach(r=>{t.push(r)}),await this.batchSubscribe(t)}registerEventListeners(){this.relayer.core.heartbeat.on(Tr.HEARTBEAT_EVENTS.pulse,async()=>{await this.checkPending()}),this.relayer.on(Ne.connect,async()=>{await this.onConnect()}),this.relayer.on(Ne.disconnect,()=>{this.onDisconnect()}),this.events.on(pt.created,async t=>{const r=pt.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:t}),await this.persist()}),this.events.on(pt.deleted,async t=>{const r=pt.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:t}),await this.persist()})}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}async restartToComplete(){this.restartInProgress&&await new Promise(t=>{const r=setInterval(()=>{this.restartInProgress||(clearInterval(r),t())},this.pollingInterval)})}}var Jb=Object.defineProperty,Ku=Object.getOwnPropertySymbols,Gb=Object.prototype.hasOwnProperty,Qb=Object.prototype.propertyIsEnumerable,Bu=(a,t,r)=>t in a?Jb(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,Yb=(a,t)=>{for(var r in t||(t={}))Gb.call(t,r)&&Bu(a,r,t[r]);if(Ku)for(var r of Ku(t))Qb.call(t,r)&&Bu(a,r,t[r]);return a};class Zb extends Kw{constructor(t){super(t),this.protocol="wc",this.version=2,this.events=new He.eventsExports.EventEmitter,this.name=mb,this.transportExplicitlyClosed=!1,this.initialized=!1,this.connectionAttemptInProgress=!1,this.connectionStatusPollingInterval=20,this.staleConnectionErrors=["socket hang up","socket stalled"],this.hasExperiencedNetworkDisruption=!1,this.request=async r=>{this.logger.debug("Publishing Request Payload");try{return await this.toEstablishConnection(),await this.provider.request(r)}catch(s){throw this.logger.debug("Failed to Publish Request"),this.logger.error(s),s}},this.onPayloadHandler=r=>{this.onProviderPayload(r)},this.onConnectHandler=()=>{this.events.emit(Ne.connect)},this.onDisconnectHandler=()=>{this.onProviderDisconnect()},this.onProviderErrorHandler=r=>{this.logger.error(r),this.events.emit(Ne.error,r),this.logger.info("Fatal socket error received, closing transport"),this.transportClose()},this.registerProviderListeners=()=>{this.provider.on(Ct.payload,this.onPayloadHandler),this.provider.on(Ct.connect,this.onConnectHandler),this.provider.on(Ct.disconnect,this.onDisconnectHandler),this.provider.on(Ct.error,this.onProviderErrorHandler)},this.core=t.core,this.logger=typeof t.logger<"u"&&typeof t.logger!="string"?E.E(t.logger,this.name):E.Tt(E.k({level:t.logger||vb})),this.messages=new Mb(this.logger,t.core),this.subscriber=new Wb(this,this.logger),this.publisher=new Lb(this,this.logger),this.relayUrl=(t==null?void 0:t.relayUrl)||Qh,this.projectId=t.projectId,this.bundleId=N_(),this.provider={}}async init(){this.logger.trace("Initialized"),this.registerEventListeners(),await this.createProvider(),await Promise.all([this.messages.init(),this.subscriber.init()]);try{await this.transportOpen()}catch{this.logger.warn(`Connection via ${this.relayUrl} failed, attempting to connect via failover domain ${zu}...`),await this.restartTransport(zu)}this.initialized=!0,setTimeout(async()=>{this.subscriber.topics.length===0&&(this.logger.info("No topics subscribed to after init, closing transport"),await this.transportClose(),this.transportExplicitlyClosed=!1)},Eb)}get context(){return E.y(this.logger)}get connected(){return this.provider.connection.connected}get connecting(){return this.provider.connection.connecting}async publish(t,r,s){this.isInitialized(),await this.publisher.publish(t,r,s),await this.recordMessageEvent({topic:t,message:r,publishedAt:Date.now()})}async subscribe(t,r){var s;this.isInitialized();let o=((s=this.subscriber.topicMap.get(t))==null?void 0:s[0])||"";if(o)return o;let u;const l=g=>{g.topic===t&&(this.subscriber.off(pt.created,l),u())};return await Promise.all([new Promise(g=>{u=g,this.subscriber.on(pt.created,l)}),new Promise(async g=>{o=await this.subscriber.subscribe(t,r),g()})]),o}async unsubscribe(t,r){this.isInitialized(),await this.subscriber.unsubscribe(t,r)}on(t,r){this.events.on(t,r)}once(t,r){this.events.once(t,r)}off(t,r){this.events.off(t,r)}removeListener(t,r){this.events.removeListener(t,r)}async transportClose(){this.transportExplicitlyClosed=!0,this.hasExperiencedNetworkDisruption&&this.connected?await gi(this.provider.disconnect(),1e3,"provider.disconnect()").catch(()=>this.onProviderDisconnect()):this.connected&&await this.provider.disconnect()}async transportOpen(t){if(this.transportExplicitlyClosed=!1,await this.confirmOnlineStateOrThrow(),!this.connectionAttemptInProgress){t&&t!==this.relayUrl&&(this.relayUrl=t,await this.transportClose(),await this.createProvider()),this.connectionAttemptInProgress=!0;try{await Promise.all([new Promise(r=>{if(!this.initialized)return r();this.subscriber.once(pt.resubscribed,()=>{r()})}),new Promise(async(r,s)=>{try{await gi(this.provider.connect(),1e4,`Socket stalled when trying to connect to ${this.relayUrl}`)}catch(o){s(o);return}r()})])}catch(r){this.logger.error(r);const s=r;if(!this.isConnectionStalled(s.message))throw r;this.provider.events.emit(Ct.disconnect)}finally{this.connectionAttemptInProgress=!1,this.hasExperiencedNetworkDisruption=!1}}}async restartTransport(t){await this.confirmOnlineStateOrThrow(),!this.connectionAttemptInProgress&&(this.relayUrl=t||this.relayUrl,await this.transportClose(),await this.createProvider(),await this.transportOpen())}async confirmOnlineStateOrThrow(){if(!await Tu())throw new Error("No internet connection detected. Please restart your network and try again.")}isConnectionStalled(t){return this.staleConnectionErrors.some(r=>t.includes(r))}async createProvider(){this.provider.connection&&this.unregisterProviderListeners();const t=await this.core.crypto.signJWT(this.relayUrl);this.provider=new Tt(new A1(D_({sdkVersion:bb,protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:t,useOnCloseEvent:!0,bundleId:this.bundleId}))),this.registerProviderListeners()}async recordMessageEvent(t){const{topic:r,message:s}=t;await this.messages.set(r,s)}async shouldIgnoreMessageEvent(t){const{topic:r,message:s}=t;if(!s||s.length===0)return this.logger.debug(`Ignoring invalid/empty message: ${s}`),!0;if(!await this.subscriber.isSubscribed(r))return this.logger.debug(`Ignoring message for non-subscribed topic ${r}`),!0;const o=this.messages.has(r,s);return o&&this.logger.debug(`Ignoring duplicate message: ${s}`),o}async onProviderPayload(t){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:t}),E.isJsonRpcRequest(t)){if(!t.method.endsWith(wb))return;const r=t.params,{topic:s,message:o,publishedAt:u}=r.data,l={topic:s,message:o,publishedAt:u};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(Yb({type:"event",event:r.id},l)),this.events.emit(r.id,l),await this.acknowledgePayload(t),await this.onMessageEvent(l)}else E.isJsonRpcResponse(t)&&this.events.emit(Ne.message_ack,t)}async onMessageEvent(t){await this.shouldIgnoreMessageEvent(t)||(this.events.emit(Ne.message,t),await this.recordMessageEvent(t))}async acknowledgePayload(t){const r=E.formatJsonRpcResult(t.id,!0);await this.provider.connection.send(r)}unregisterProviderListeners(){this.provider.off(Ct.payload,this.onPayloadHandler),this.provider.off(Ct.connect,this.onConnectHandler),this.provider.off(Ct.disconnect,this.onDisconnectHandler),this.provider.off(Ct.error,this.onProviderErrorHandler)}async registerEventListeners(){this.events.on(Ne.connection_stalled,()=>{this.restartTransport().catch(r=>this.logger.error(r))});let t=await Tu();O1(async r=>{this.initialized&&t!==r&&(t=r,r?await this.restartTransport().catch(s=>this.logger.error(s)):(this.hasExperiencedNetworkDisruption=!0,await this.transportClose().catch(s=>this.logger.error(s))))})}onProviderDisconnect(){this.events.emit(Ne.disconnect),this.attemptToReconnect()}attemptToReconnect(){this.transportExplicitlyClosed||(this.logger.info("attemptToReconnect called. Connecting..."),setTimeout(async()=>{await this.restartTransport().catch(t=>this.logger.error(t))},j.cjs.toMiliseconds(_b)))}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}async toEstablishConnection(){if(await this.confirmOnlineStateOrThrow(),!this.connected){if(this.connectionAttemptInProgress)return await new Promise(t=>{const r=setInterval(()=>{this.connected&&(clearInterval(r),t())},this.connectionStatusPollingInterval)});await this.restartTransport()}}}var Xb=Object.defineProperty,Wu=Object.getOwnPropertySymbols,eE=Object.prototype.hasOwnProperty,tE=Object.prototype.propertyIsEnumerable,Ju=(a,t,r)=>t in a?Xb(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,Gu=(a,t)=>{for(var r in t||(t={}))eE.call(t,r)&&Ju(a,r,t[r]);if(Wu)for(var r of Wu(t))tE.call(t,r)&&Ju(a,r,t[r]);return a};class Os extends Bw{constructor(t,r,s,o=Vt,u=void 0){super(t,r,s,o),this.core=t,this.logger=r,this.name=s,this.map=new Map,this.version=Ib,this.cached=[],this.initialized=!1,this.storagePrefix=Vt,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(l=>{this.getKey&&l!==null&&!xe(l)?this.map.set(this.getKey(l),l):i1(l)?this.map.set(l.id,l):s1(l)&&this.map.set(l.topic,l)}),this.cached=[],this.initialized=!0)},this.set=async(l,g)=>{this.isInitialized(),this.map.has(l)?await this.update(l,g):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:l,value:g}),this.map.set(l,g),await this.persist())},this.get=l=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:l}),this.getData(l)),this.getAll=l=>(this.isInitialized(),l?this.values.filter(g=>Object.keys(l).every(w=>E._s(g[w],l[w]))):this.values),this.update=async(l,g)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:l,update:g});const w=Gu(Gu({},this.getData(l)),g);this.map.set(l,w),await this.persist()},this.delete=async(l,g)=>{this.isInitialized(),this.map.has(l)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:l,reason:g}),this.map.delete(l),await this.persist())},this.logger=E.E(r,this.name),this.storagePrefix=o,this.getKey=u}get context(){return E.y(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get length(){return this.map.size}get keys(){return Array.from(this.map.keys())}get values(){return Array.from(this.map.values())}async setDataStore(t){await this.core.storage.setItem(this.storageKey,t)}async getDataStore(){return await this.core.storage.getItem(this.storageKey)}getData(t){const r=this.map.get(t);if(!r){const{message:s}=$("NO_MATCHING_KEY",`${this.name}: ${t}`);throw this.logger.error(s),new Error(s)}return r}async persist(){await this.setDataStore(this.values)}async restore(){try{const t=await this.getDataStore();if(typeof t>"u"||!t.length)return;if(this.map.size){const{message:r}=$("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=t,this.logger.debug(`Successfully Restored value for ${this.name}`),this.logger.trace({type:"method",method:"restore",value:this.values})}catch(t){this.logger.debug(`Failed to Restore value for ${this.name}`),this.logger.error(t)}}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}}class rE{constructor(t,r){this.core=t,this.logger=r,this.name=Nb,this.version=Cb,this.events=new He.ss,this.initialized=!1,this.storagePrefix=Vt,this.ignoredPayloadTypes=[ar],this.registeredMethods=[],this.init=async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))},this.register=({methods:s})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...s])]},this.create=async()=>{this.isInitialized();const s=yo(),o=await this.core.crypto.setSymKey(s),u=ft(j.cjs.FIVE_MINUTES),l={protocol:Gh},g={topic:o,expiry:u,relay:l,active:!1},w=W_({protocol:this.core.protocol,version:this.core.version,topic:o,symKey:s,relay:l});return await this.pairings.set(o,g),await this.core.relayer.subscribe(o),this.core.expirer.set(o,u),{topic:o,uri:w}},this.pair=async s=>{this.isInitialized(),this.isValidPair(s);const{topic:o,symKey:u,relay:l}=Ou(s.uri);let g;if(this.pairings.keys.includes(o)&&(g=this.pairings.get(o),g.active))throw new Error(`Pairing already exists: ${o}. Please try again with a new connection URI.`);const w=ft(j.cjs.FIVE_MINUTES),b={topic:o,relay:l,expiry:w,active:!1};return await this.pairings.set(o,b),this.core.expirer.set(o,w),s.activatePairing&&await this.activate({topic:o}),this.events.emit(pi.create,b),this.core.crypto.keychain.has(o)||(await this.core.crypto.setSymKey(u,o),await this.core.relayer.subscribe(o,{relay:l})),b},this.activate=async({topic:s})=>{this.isInitialized();const o=ft(j.cjs.THIRTY_DAYS);await this.pairings.update(s,{active:!0,expiry:o}),this.core.expirer.set(s,o)},this.ping=async s=>{this.isInitialized(),await this.isValidPing(s);const{topic:o}=s;if(this.pairings.keys.includes(o)){const u=await this.sendRequest(o,"wc_pairingPing",{}),{done:l,resolve:g,reject:w}=Or();this.events.once(me("pairing_ping",u),({error:b})=>{b?w(b):g()}),await l()}},this.updateExpiry=async({topic:s,expiry:o})=>{this.isInitialized(),await this.pairings.update(s,{expiry:o})},this.updateMetadata=async({topic:s,metadata:o})=>{this.isInitialized(),await this.pairings.update(s,{peerMetadata:o})},this.getPairings=()=>(this.isInitialized(),this.pairings.values),this.disconnect=async s=>{this.isInitialized(),await this.isValidDisconnect(s);const{topic:o}=s;this.pairings.keys.includes(o)&&(await this.sendRequest(o,"wc_pairingDelete",ve("USER_DISCONNECTED")),await this.deletePairing(o))},this.sendRequest=async(s,o,u)=>{const l=E.formatJsonRpcRequest(o,u),g=await this.core.crypto.encode(s,l),w=oi[o].req;return this.core.history.set(s,l),this.core.relayer.publish(s,g,w),l.id},this.sendResult=async(s,o,u)=>{const l=E.formatJsonRpcResult(s,u),g=await this.core.crypto.encode(o,l),w=await this.core.history.get(o,s),b=oi[w.request.method].res;await this.core.relayer.publish(o,g,b),await this.core.history.resolve(l)},this.sendError=async(s,o,u)=>{const l=E.formatJsonRpcError(s,u),g=await this.core.crypto.encode(o,l),w=await this.core.history.get(o,s),b=oi[w.request.method]?oi[w.request.method].res:oi.unregistered_method.res;await this.core.relayer.publish(o,g,b),await this.core.history.resolve(l)},this.deletePairing=async(s,o)=>{await this.core.relayer.unsubscribe(s),await Promise.all([this.pairings.delete(s,ve("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(s),o?Promise.resolve():this.core.expirer.del(s)])},this.cleanup=async()=>{const s=this.pairings.getAll().filter(o=>Ht(o.expiry));await Promise.all(s.map(o=>this.deletePairing(o.topic)))},this.onRelayEventRequest=s=>{const{topic:o,payload:u}=s;switch(u.method){case"wc_pairingPing":return this.onPairingPingRequest(o,u);case"wc_pairingDelete":return this.onPairingDeleteRequest(o,u);default:return this.onUnknownRpcMethodRequest(o,u)}},this.onRelayEventResponse=async s=>{const{topic:o,payload:u}=s,l=(await this.core.history.get(o,u.id)).request.method;switch(l){case"wc_pairingPing":return this.onPairingPingResponse(o,u);default:return this.onUnknownRpcMethodResponse(l)}},this.onPairingPingRequest=async(s,o)=>{const{id:u}=o;try{this.isValidPing({topic:s}),await this.sendResult(u,s,!0),this.events.emit(pi.ping,{id:u,topic:s})}catch(l){await this.sendError(u,s,l),this.logger.error(l)}},this.onPairingPingResponse=(s,o)=>{const{id:u}=o;setTimeout(()=>{E.isJsonRpcResult(o)?this.events.emit(me("pairing_ping",u),{}):E.isJsonRpcError(o)&&this.events.emit(me("pairing_ping",u),{error:o.error})},500)},this.onPairingDeleteRequest=async(s,o)=>{const{id:u}=o;try{this.isValidDisconnect({topic:s}),await this.deletePairing(s),this.events.emit(pi.delete,{id:u,topic:s})}catch(l){await this.sendError(u,s,l),this.logger.error(l)}},this.onUnknownRpcMethodRequest=async(s,o)=>{const{id:u,method:l}=o;try{if(this.registeredMethods.includes(l))return;const g=ve("WC_METHOD_UNSUPPORTED",l);await this.sendError(u,s,g),this.logger.error(g)}catch(g){await this.sendError(u,s,g),this.logger.error(g)}},this.onUnknownRpcMethodResponse=s=>{this.registeredMethods.includes(s)||this.logger.error(ve("WC_METHOD_UNSUPPORTED",s))},this.isValidPair=s=>{var o;if(!ke(s)){const{message:l}=$("MISSING_OR_INVALID",`pair() params: ${s}`);throw new Error(l)}if(!r1(s.uri)){const{message:l}=$("MISSING_OR_INVALID",`pair() uri: ${s.uri}`);throw new Error(l)}const u=Ou(s.uri);if(!((o=u==null?void 0:u.relay)!=null&&o.protocol)){const{message:l}=$("MISSING_OR_INVALID","pair() uri#relay-protocol");throw new Error(l)}if(!(u!=null&&u.symKey)){const{message:l}=$("MISSING_OR_INVALID","pair() uri#symKey");throw new Error(l)}},this.isValidPing=async s=>{if(!ke(s)){const{message:u}=$("MISSING_OR_INVALID",`ping() params: ${s}`);throw new Error(u)}const{topic:o}=s;await this.isValidPairingTopic(o)},this.isValidDisconnect=async s=>{if(!ke(s)){const{message:u}=$("MISSING_OR_INVALID",`disconnect() params: ${s}`);throw new Error(u)}const{topic:o}=s;await this.isValidPairingTopic(o)},this.isValidPairingTopic=async s=>{if(!Ee(s,!1)){const{message:o}=$("MISSING_OR_INVALID",`pairing topic should be a string: ${s}`);throw new Error(o)}if(!this.pairings.keys.includes(s)){const{message:o}=$("NO_MATCHING_KEY",`pairing topic doesn't exist: ${s}`);throw new Error(o)}if(Ht(this.pairings.get(s).expiry)){await this.deletePairing(s);const{message:o}=$("EXPIRED",`pairing topic: ${s}`);throw new Error(o)}},this.core=t,this.logger=E.E(r,this.name),this.pairings=new Os(this.core,this.logger,this.name,this.storagePrefix)}get context(){return E.y(this.logger)}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}registerRelayerEvents(){this.core.relayer.on(Ne.message,async t=>{const{topic:r,message:s}=t;if(!this.pairings.keys.includes(r)||this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(s)))return;const o=await this.core.crypto.decode(r,s);try{E.isJsonRpcRequest(o)?(this.core.history.set(r,o),this.onRelayEventRequest({topic:r,payload:o})):E.isJsonRpcResponse(o)&&(await this.core.history.resolve(o),await this.onRelayEventResponse({topic:r,payload:o}),this.core.history.delete(r,o.id))}catch(u){this.logger.error(u)}})}registerExpirerEvents(){this.core.expirer.on(nt.expired,async t=>{const{topic:r}=xh(t.target);r&&this.pairings.keys.includes(r)&&(await this.deletePairing(r,!0),this.events.emit(pi.expire,{topic:r}))})}}class iE extends zw{constructor(t,r){super(t,r),this.core=t,this.logger=r,this.records=new Map,this.events=new He.eventsExports.EventEmitter,this.name=$b,this.version=Tb,this.cached=[],this.initialized=!1,this.storagePrefix=Vt,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(s=>this.records.set(s.id,s)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.set=(s,o,u)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:s,request:o,chainId:u}),this.records.has(o.id))return;const l={id:o.id,topic:s,request:{method:o.method,params:o.params||null},chainId:u,expiry:ft(j.cjs.THIRTY_DAYS)};this.records.set(l.id,l),this.events.emit(mt.created,l)},this.resolve=async s=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:s}),!this.records.has(s.id))return;const o=await this.getRecord(s.id);typeof o.response>"u"&&(o.response=E.isJsonRpcError(s)?{error:s.error}:{result:s.result},this.records.set(o.id,o),this.events.emit(mt.updated,o))},this.get=async(s,o)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:s,id:o}),await this.getRecord(o)),this.delete=(s,o)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:o}),this.values.forEach(u=>{if(u.topic===s){if(typeof o<"u"&&u.id!==o)return;this.records.delete(u.id),this.events.emit(mt.deleted,u)}})},this.exists=async(s,o)=>(this.isInitialized(),this.records.has(o)?(await this.getRecord(o)).topic===s:!1),this.on=(s,o)=>{this.events.on(s,o)},this.once=(s,o)=>{this.events.once(s,o)},this.off=(s,o)=>{this.events.off(s,o)},this.removeListener=(s,o)=>{this.events.removeListener(s,o)},this.logger=E.E(r,this.name)}get context(){return E.y(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get size(){return this.records.size}get keys(){return Array.from(this.records.keys())}get values(){return Array.from(this.records.values())}get pending(){const t=[];return this.values.forEach(r=>{if(typeof r.response<"u")return;const s={topic:r.topic,request:E.formatJsonRpcRequest(r.request.method,r.request.params,r.id),chainId:r.chainId};return t.push(s)}),t}async setJsonRpcRecords(t){await this.core.storage.setItem(this.storageKey,t)}async getJsonRpcRecords(){return await this.core.storage.getItem(this.storageKey)}getRecord(t){this.isInitialized();const r=this.records.get(t);if(!r){const{message:s}=$("NO_MATCHING_KEY",`${this.name}: ${t}`);throw new Error(s)}return r}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(mt.sync)}async restore(){try{const t=await this.getJsonRpcRecords();if(typeof t>"u"||!t.length)return;if(this.records.size){const{message:r}=$("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=t,this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(t){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(t)}}registerEventListeners(){this.events.on(mt.created,t=>{const r=mt.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:t}),this.persist()}),this.events.on(mt.updated,t=>{const r=mt.updated;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:t}),this.persist()}),this.events.on(mt.deleted,t=>{const r=mt.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:t}),this.persist()}),this.core.heartbeat.on(Tr.HEARTBEAT_EVENTS.pulse,()=>{this.cleanup()})}cleanup(){try{this.records.forEach(t=>{j.cjs.toMiliseconds(t.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${t.id}`),this.delete(t.topic,t.id))})}catch(t){this.logger.warn(t)}}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}}class sE extends Jw{constructor(t,r){super(t,r),this.core=t,this.logger=r,this.expirations=new Map,this.events=new He.eventsExports.EventEmitter,this.name=Ab,this.version=xb,this.cached=[],this.initialized=!1,this.storagePrefix=Vt,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(s=>this.expirations.set(s.target,s)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.has=s=>{try{const o=this.formatTarget(s);return typeof this.getExpiration(o)<"u"}catch{return!1}},this.set=(s,o)=>{this.isInitialized();const u=this.formatTarget(s),l={target:u,expiry:o};this.expirations.set(u,l),this.checkExpiry(u,l),this.events.emit(nt.created,{target:u,expiration:l})},this.get=s=>{this.isInitialized();const o=this.formatTarget(s);return this.getExpiration(o)},this.del=s=>{if(this.isInitialized(),this.has(s)){const o=this.formatTarget(s),u=this.getExpiration(o);this.expirations.delete(o),this.events.emit(nt.deleted,{target:o,expiration:u})}},this.on=(s,o)=>{this.events.on(s,o)},this.once=(s,o)=>{this.events.once(s,o)},this.off=(s,o)=>{this.events.off(s,o)},this.removeListener=(s,o)=>{this.events.removeListener(s,o)},this.logger=E.E(r,this.name)}get context(){return E.y(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get length(){return this.expirations.size}get keys(){return Array.from(this.expirations.keys())}get values(){return Array.from(this.expirations.values())}formatTarget(t){if(typeof t=="string")return F_(t);if(typeof t=="number")return j_(t);const{message:r}=$("UNKNOWN_TYPE",`Target type: ${typeof t}`);throw new Error(r)}async setExpirations(t){await this.core.storage.setItem(this.storageKey,t)}async getExpirations(){return await this.core.storage.getItem(this.storageKey)}async persist(){await this.setExpirations(this.values),this.events.emit(nt.sync)}async restore(){try{const t=await this.getExpirations();if(typeof t>"u"||!t.length)return;if(this.expirations.size){const{message:r}=$("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}this.cached=t,this.logger.debug(`Successfully Restored expirations for ${this.name}`),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(t){this.logger.debug(`Failed to Restore expirations for ${this.name}`),this.logger.error(t)}}getExpiration(t){const r=this.expirations.get(t);if(!r){const{message:s}=$("NO_MATCHING_KEY",`${this.name}: ${t}`);throw this.logger.error(s),new Error(s)}return r}checkExpiry(t,r){const{expiry:s}=r;j.cjs.toMiliseconds(s)-Date.now()<=0&&this.expire(t,r)}expire(t,r){this.expirations.delete(t),this.events.emit(nt.expired,{target:t,expiration:r})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((t,r)=>this.checkExpiry(r,t))}registerEventListeners(){this.core.heartbeat.on(Tr.HEARTBEAT_EVENTS.pulse,()=>this.checkExpirations()),this.events.on(nt.created,t=>{const r=nt.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:t}),this.persist()}),this.events.on(nt.expired,t=>{const r=nt.expired;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:t}),this.persist()}),this.events.on(nt.deleted,t=>{const r=nt.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:t}),this.persist()})}isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}}}class nE extends Gw{constructor(t,r){super(t,r),this.projectId=t,this.logger=r,this.name=to,this.initialized=!1,this.queue=[],this.verifyDisabled=!1,this.init=async s=>{if(this.verifyDisabled||xr()||!Dr())return;const o=this.getVerifyUrl(s==null?void 0:s.verifyUrl);this.verifyUrl!==o&&this.removeIframe(),this.verifyUrl=o;try{await this.createIframe()}catch(u){this.logger.info(`Verify iframe failed to load: ${this.verifyUrl}`),this.logger.info(u)}if(!this.initialized){this.removeIframe(),this.verifyUrl=_o;try{await this.createIframe()}catch(u){this.logger.info(`Verify iframe failed to load: ${this.verifyUrl}`),this.logger.info(u),this.verifyDisabled=!0}}},this.register=async s=>{this.initialized?this.sendPost(s.attestationId):(this.addToQueue(s.attestationId),await this.init())},this.resolve=async s=>{if(this.isDevEnv)return"";const o=this.getVerifyUrl(s==null?void 0:s.verifyUrl);let u;try{u=await this.fetchAttestation(s.attestationId,o)}catch(l){this.logger.info(`failed to resolve attestation: ${s.attestationId} from url: ${o}`),this.logger.info(l),u=await this.fetchAttestation(s.attestationId,_o)}return u},this.fetchAttestation=async(s,o)=>{this.logger.info(`resolving attestation: ${s} from url: ${o}`);const u=this.startAbortTimer(j.cjs.ONE_SECOND*2),l=await fetch(`${o}/attestation/${s}`,{signal:this.abortController.signal});return clearTimeout(u),l.status===200?await l.json():void 0},this.addToQueue=s=>{this.queue.push(s)},this.processQueue=()=>{this.queue.length!==0&&(this.queue.forEach(s=>this.sendPost(s)),this.queue=[])},this.sendPost=s=>{var o;try{if(!this.iframe)return;(o=this.iframe.contentWindow)==null||o.postMessage(s,"*"),this.logger.info(`postMessage sent: ${s} ${this.verifyUrl}`)}catch{}},this.createIframe=async()=>{let s;const o=u=>{u.data==="verify_ready"&&(this.initialized=!0,this.processQueue(),window.removeEventListener("message",o),s())};await Promise.race([new Promise(u=>{if(document.getElementById(to))return u();window.addEventListener("message",o);const l=document.createElement("iframe");l.id=to,l.src=`${this.verifyUrl}/${this.projectId}`,l.style.display="none",document.body.append(l),this.iframe=l,s=u}),new Promise((u,l)=>setTimeout(()=>{window.removeEventListener("message",o),l("verify iframe load timeout")},j.cjs.toMiliseconds(j.cjs.FIVE_SECONDS)))])},this.removeIframe=()=>{this.iframe&&(this.iframe.remove(),this.iframe=void 0,this.initialized=!1)},this.getVerifyUrl=s=>{let o=s||Rr;return Db.includes(o)||(this.logger.info(`verify url: ${o}, not included in trusted list, assigning default: ${Rr}`),o=Rr),o},this.logger=E.E(r,this.name),this.verifyUrl=Rr,this.abortController=new AbortController,this.isDevEnv=No()&&W.dist.process.env.IS_VITEST}get context(){return E.y(this.logger)}startAbortTimer(t){return this.abortController=new AbortController,setTimeout(()=>this.abortController.abort(),j.cjs.toMiliseconds(t))}}class oE extends Qw{constructor(t,r){super(t,r),this.projectId=t,this.logger=r,this.context=Fb,this.registerDeviceToken=async s=>{const{clientId:o,token:u,notificationType:l,enableEncrypted:g=!1}=s,w=`${jb}/${this.projectId}/clients`;await j1(w,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:o,type:l,token:u,always_raw:g})})},this.logger=E.E(r,this.context)}}var aE=Object.defineProperty,Qu=Object.getOwnPropertySymbols,cE=Object.prototype.hasOwnProperty,uE=Object.prototype.propertyIsEnumerable,Yu=(a,t,r)=>t in a?aE(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,Zu=(a,t)=>{for(var r in t||(t={}))cE.call(t,r)&&Yu(a,r,t[r]);if(Qu)for(var r of Qu(t))uE.call(t,r)&&Yu(a,r,t[r]);return a};class To extends kw{constructor(t){super(t),this.protocol=Wh,this.version=ob,this.name=Jh,this.events=new He.eventsExports.EventEmitter,this.initialized=!1,this.on=(s,o)=>this.events.on(s,o),this.once=(s,o)=>this.events.once(s,o),this.off=(s,o)=>this.events.off(s,o),this.removeListener=(s,o)=>this.events.removeListener(s,o),this.projectId=t==null?void 0:t.projectId,this.relayUrl=(t==null?void 0:t.relayUrl)||Qh,this.customStoragePrefix=t!=null&&t.customStoragePrefix?`:${t.customStoragePrefix}`:"";const r=typeof(t==null?void 0:t.logger)<"u"&&typeof(t==null?void 0:t.logger)!="string"?t.logger:E.Tt(E.k({level:(t==null?void 0:t.logger)||ab.logger}));this.logger=E.E(r,this.name),this.heartbeat=new Tr.HeartBeat,this.crypto=new Ub(this,this.logger,t==null?void 0:t.keychain),this.history=new iE(this,this.logger),this.expirer=new sE(this,this.logger),this.storage=t!=null&&t.storage?t.storage:new E.h(Zu(Zu({},cb),t==null?void 0:t.storageOptions)),this.relayer=new Zb({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new rE(this,this.logger),this.verify=new nE(this.projectId||"",this.logger),this.echoClient=new oE(this.projectId||"",this.logger)}static async init(t){const r=new To(t);await r.initialize();const s=await r.crypto.getClientId();return await r.storage.setItem(Pb,s),r}get context(){return E.y(this.logger)}async start(){this.initialized||await this.initialize()}async initialize(){this.logger.trace("Initialized");try{await this.crypto.init(),await this.history.init(),await this.expirer.init(),await this.relayer.init(),await this.heartbeat.init(),await this.pairing.init(),this.initialized=!0,this.logger.info("Core Initialization Success")}catch(t){throw this.logger.warn(`Core Initialization Failure at epoch ${Date.now()}`,t),this.logger.error(t.message),t}}}const hE=To,Yh="wc",Zh=2,Xh="client",Ao=`${Yh}@${Zh}:${Xh}:`,io={name:Xh,logger:"error"},Xu="WALLETCONNECT_DEEPLINK_CHOICE",lE="proposal",el="Proposal expired",pE="session",ds=j.cjs.SEVEN_DAYS,fE="engine",ci={wc_sessionPropose:{req:{ttl:j.cjs.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:j.cjs.FIVE_MINUTES,prompt:!1,tag:1101}},wc_sessionSettle:{req:{ttl:j.cjs.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:j.cjs.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:1104},res:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:1106},res:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:j.cjs.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:j.cjs.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:j.cjs.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:j.cjs.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:1112},res:{ttl:j.cjs.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:j.cjs.THIRTY_SECONDS,prompt:!1,tag:1114},res:{ttl:j.cjs.THIRTY_SECONDS,prompt:!1,tag:1115}}},so={min:j.cjs.FIVE_MINUTES,max:j.cjs.SEVEN_DAYS},$t={idle:"IDLE",active:"ACTIVE"},dE="request",gE=["wc_sessionPropose","wc_sessionRequest","wc_authRequest"];var yE=Object.defineProperty,vE=Object.defineProperties,mE=Object.getOwnPropertyDescriptors,eh=Object.getOwnPropertySymbols,wE=Object.prototype.hasOwnProperty,_E=Object.prototype.propertyIsEnumerable,th=(a,t,r)=>t in a?yE(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,Le=(a,t)=>{for(var r in t||(t={}))wE.call(t,r)&&th(a,r,t[r]);if(eh)for(var r of eh(t))_E.call(t,r)&&th(a,r,t[r]);return a},ui=(a,t)=>vE(a,mE(t));class bE extends Zw{constructor(t){super(t),this.name=fE,this.events=new He.ss,this.initialized=!1,this.ignoredPayloadTypes=[ar],this.requestQueue={state:$t.idle,queue:[]},this.sessionRequestQueue={state:$t.idle,queue:[]},this.requestQueueDelay=j.cjs.ONE_SECOND,this.init=async()=>{this.initialized||(await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.registerPairingEvents(),this.client.core.pairing.register({methods:Object.keys(ci)}),this.initialized=!0,setTimeout(()=>{this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()},j.cjs.toMiliseconds(this.requestQueueDelay)))},this.connect=async r=>{await this.isInitialized();const s=ui(Le({},r),{requiredNamespaces:r.requiredNamespaces||{},optionalNamespaces:r.optionalNamespaces||{}});await this.isValidConnect(s);const{pairingTopic:o,requiredNamespaces:u,optionalNamespaces:l,sessionProperties:g,relays:w}=s;let b=o,C,O=!1;if(b&&(O=this.client.core.pairing.pairings.get(b).active),!b||!O){const{topic:Z,uri:ee}=await this.client.core.pairing.create();b=Z,C=ee}const N=await this.client.core.crypto.generateKeyPair(),q=Le({requiredNamespaces:u,optionalNamespaces:l,relays:w??[{protocol:Gh}],proposer:{publicKey:N,metadata:this.client.metadata}},g&&{sessionProperties:g}),{reject:x,resolve:K,done:D}=Or(j.cjs.FIVE_MINUTES,el);if(this.events.once(me("session_connect"),async({error:Z,session:ee})=>{if(Z)x(Z);else if(ee){ee.self.publicKey=N;const he=ui(Le({},ee),{requiredNamespaces:ee.requiredNamespaces,optionalNamespaces:ee.optionalNamespaces});await this.client.session.set(ee.topic,he),await this.setExpiry(ee.topic,ee.expiry),b&&await this.client.core.pairing.updateMetadata({topic:b,metadata:ee.peer.metadata}),K(he)}}),!b){const{message:Z}=$("NO_MATCHING_KEY",`connect() pairing topic: ${b}`);throw new Error(Z)}const Q=await this.sendRequest({topic:b,method:"wc_sessionPropose",params:q}),fe=ft(j.cjs.FIVE_MINUTES);return await this.setProposal(Q,Le({id:Q,expiry:fe},q)),{uri:C,approval:D}},this.pair=async r=>(await this.isInitialized(),await this.client.core.pairing.pair(r)),this.approve=async r=>{await this.isInitialized(),await this.isValidApprove(r);const{id:s,relayProtocol:o,namespaces:u,sessionProperties:l}=r,g=this.client.proposal.get(s);let{pairingTopic:w,proposer:b,requiredNamespaces:C,optionalNamespaces:O}=g;w=w||"",Cr(C)||(C=Y_(u,"approve()"));const N=await this.client.core.crypto.generateKeyPair(),q=b.publicKey,x=await this.client.core.crypto.generateSharedKey(N,q);w&&s&&(await this.client.core.pairing.updateMetadata({topic:w,metadata:b.metadata}),await this.sendResult({id:s,topic:w,result:{relay:{protocol:o??"irn"},responderPublicKey:N}}),await this.client.proposal.delete(s,ve("USER_DISCONNECTED")),await this.client.core.pairing.activate({topic:w}));const K=Le({relay:{protocol:o??"irn"},namespaces:u,requiredNamespaces:C,optionalNamespaces:O,pairingTopic:w,controller:{publicKey:N,metadata:this.client.metadata},expiry:ft(ds)},l&&{sessionProperties:l});await this.client.core.relayer.subscribe(x),await this.sendRequest({topic:x,method:"wc_sessionSettle",params:K,throwOnFailedPublish:!0});const D=ui(Le({},K),{topic:x,pairingTopic:w,acknowledged:!1,self:K.controller,peer:{publicKey:b.publicKey,metadata:b.metadata},controller:N});return await this.client.session.set(x,D),await this.setExpiry(x,ft(ds)),{topic:x,acknowledged:()=>new Promise(Q=>setTimeout(()=>Q(this.client.session.get(x)),500))}},this.reject=async r=>{await this.isInitialized(),await this.isValidReject(r);const{id:s,reason:o}=r,{pairingTopic:u}=this.client.proposal.get(s);u&&(await this.sendError(s,u,o),await this.client.proposal.delete(s,ve("USER_DISCONNECTED")))},this.update=async r=>{await this.isInitialized(),await this.isValidUpdate(r);const{topic:s,namespaces:o}=r,u=await this.sendRequest({topic:s,method:"wc_sessionUpdate",params:{namespaces:o}}),{done:l,resolve:g,reject:w}=Or();return this.events.once(me("session_update",u),({error:b})=>{b?w(b):g()}),await this.client.session.update(s,{namespaces:o}),{acknowledged:l}},this.extend=async r=>{await this.isInitialized(),await this.isValidExtend(r);const{topic:s}=r,o=await this.sendRequest({topic:s,method:"wc_sessionExtend",params:{}}),{done:u,resolve:l,reject:g}=Or();return this.events.once(me("session_extend",o),({error:w})=>{w?g(w):l()}),await this.setExpiry(s,ft(ds)),{acknowledged:u}},this.request=async r=>{await this.isInitialized(),await this.isValidRequest(r);const{chainId:s,request:o,topic:u,expiry:l}=r,g=E.payloadId(),{done:w,resolve:b,reject:C}=Or(l,"Request expired. Please try again.");return this.events.once(me("session_request",g),({error:O,result:N})=>{O?C(O):b(N)}),await Promise.all([new Promise(async O=>{await this.sendRequest({clientRpcId:g,topic:u,method:"wc_sessionRequest",params:{request:o,chainId:s},expiry:l,throwOnFailedPublish:!0}).catch(N=>C(N)),this.client.events.emit("session_request_sent",{topic:u,request:o,chainId:s,id:g}),O()}),new Promise(async O=>{const N=await U_(this.client.core.storage,Xu);q_({id:g,topic:u,wcDeepLink:N}),O()}),w()]).then(O=>O[2])},this.respond=async r=>{await this.isInitialized(),await this.isValidRespond(r);const{topic:s,response:o}=r,{id:u}=o;E.isJsonRpcResult(o)?await this.sendResult({id:u,topic:s,result:o.result,throwOnFailedPublish:!0}):E.isJsonRpcError(o)&&await this.sendError(u,s,o.error),this.cleanupAfterResponse(r)},this.ping=async r=>{await this.isInitialized(),await this.isValidPing(r);const{topic:s}=r;if(this.client.session.keys.includes(s)){const o=await this.sendRequest({topic:s,method:"wc_sessionPing",params:{}}),{done:u,resolve:l,reject:g}=Or();this.events.once(me("session_ping",o),({error:w})=>{w?g(w):l()}),await u()}else this.client.core.pairing.pairings.keys.includes(s)&&await this.client.core.pairing.ping({topic:s})},this.emit=async r=>{await this.isInitialized(),await this.isValidEmit(r);const{topic:s,event:o,chainId:u}=r;await this.sendRequest({topic:s,method:"wc_sessionEvent",params:{event:o,chainId:u}})},this.disconnect=async r=>{await this.isInitialized(),await this.isValidDisconnect(r);const{topic:s}=r;this.client.session.keys.includes(s)?(await this.sendRequest({topic:s,method:"wc_sessionDelete",params:ve("USER_DISCONNECTED"),throwOnFailedPublish:!0}),await this.deleteSession(s)):await this.client.core.pairing.disconnect({topic:s})},this.find=r=>(this.isInitialized(),this.client.session.getAll().filter(s=>e1(s,r))),this.getPendingSessionRequests=()=>(this.isInitialized(),this.client.pendingRequest.getAll()),this.cleanupDuplicatePairings=async r=>{if(r.pairingTopic)try{const s=this.client.core.pairing.pairings.get(r.pairingTopic),o=this.client.core.pairing.pairings.getAll().filter(u=>{var l,g;return((l=u.peerMetadata)==null?void 0:l.url)&&((g=u.peerMetadata)==null?void 0:g.url)===r.peer.metadata.url&&u.topic&&u.topic!==s.topic});if(o.length===0)return;this.client.logger.info(`Cleaning up ${o.length} duplicate pairing(s)`),await Promise.all(o.map(u=>this.client.core.pairing.disconnect({topic:u.topic}))),this.client.logger.info("Duplicate pairings clean up finished")}catch(s){this.client.logger.error(s)}},this.deleteSession=async(r,s)=>{const{self:o}=this.client.session.get(r);await this.client.core.relayer.unsubscribe(r),this.client.session.delete(r,ve("USER_DISCONNECTED")),this.client.core.crypto.keychain.has(o.publicKey)&&await this.client.core.crypto.deleteKeyPair(o.publicKey),this.client.core.crypto.keychain.has(r)&&await this.client.core.crypto.deleteSymKey(r),s||this.client.core.expirer.del(r),this.client.core.storage.removeItem(Xu).catch(u=>this.client.logger.warn(u)),this.getPendingSessionRequests().forEach(u=>{u.topic===r&&this.deletePendingSessionRequest(u.id,ve("USER_DISCONNECTED"))})},this.deleteProposal=async(r,s)=>{await Promise.all([this.client.proposal.delete(r,ve("USER_DISCONNECTED")),s?Promise.resolve():this.client.core.expirer.del(r)])},this.deletePendingSessionRequest=async(r,s,o=!1)=>{await Promise.all([this.client.pendingRequest.delete(r,s),o?Promise.resolve():this.client.core.expirer.del(r)]),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter(u=>u.id!==r),o&&(this.sessionRequestQueue.state=$t.idle)},this.setExpiry=async(r,s)=>{this.client.session.keys.includes(r)&&await this.client.session.update(r,{expiry:s}),this.client.core.expirer.set(r,s)},this.setProposal=async(r,s)=>{await this.client.proposal.set(r,s),this.client.core.expirer.set(r,s.expiry)},this.setPendingSessionRequest=async r=>{const s=ci.wc_sessionRequest.req.ttl,{id:o,topic:u,params:l,verifyContext:g}=r;await this.client.pendingRequest.set(o,{id:o,topic:u,params:l,verifyContext:g}),s&&this.client.core.expirer.set(o,ft(s))},this.sendRequest=async r=>{const{topic:s,method:o,params:u,expiry:l,relayRpcId:g,clientRpcId:w,throwOnFailedPublish:b}=r,C=E.formatJsonRpcRequest(o,u,w);if(Dr()&&gE.includes(o)){const q=Nr(JSON.stringify(C));this.client.core.verify.register({attestationId:q})}const O=await this.client.core.crypto.encode(s,C),N=ci[o].req;return l&&(N.ttl=l),g&&(N.id=g),this.client.core.history.set(s,C),b?(N.internal=ui(Le({},N.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(s,O,N)):this.client.core.relayer.publish(s,O,N).catch(q=>this.client.logger.error(q)),C.id},this.sendResult=async r=>{const{id:s,topic:o,result:u,throwOnFailedPublish:l}=r,g=E.formatJsonRpcResult(s,u),w=await this.client.core.crypto.encode(o,g),b=await this.client.core.history.get(o,s),C=ci[b.request.method].res;l?(C.internal=ui(Le({},C.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(o,w,C)):this.client.core.relayer.publish(o,w,C).catch(O=>this.client.logger.error(O)),await this.client.core.history.resolve(g)},this.sendError=async(r,s,o)=>{const u=E.formatJsonRpcError(r,o),l=await this.client.core.crypto.encode(s,u),g=await this.client.core.history.get(s,r),w=ci[g.request.method].res;this.client.core.relayer.publish(s,l,w),await this.client.core.history.resolve(u)},this.cleanup=async()=>{const r=[],s=[];this.client.session.getAll().forEach(o=>{Ht(o.expiry)&&r.push(o.topic)}),this.client.proposal.getAll().forEach(o=>{Ht(o.expiry)&&s.push(o.id)}),await Promise.all([...r.map(o=>this.deleteSession(o)),...s.map(o=>this.deleteProposal(o))])},this.onRelayEventRequest=async r=>{this.requestQueue.queue.push(r),await this.processRequestsQueue()},this.processRequestsQueue=async()=>{if(this.requestQueue.state===$t.active){this.client.logger.info("Request queue already active, skipping...");return}for(this.client.logger.info(`Request queue starting with ${this.requestQueue.queue.length} requests`);this.requestQueue.queue.length>0;){this.requestQueue.state=$t.active;const r=this.requestQueue.queue.shift();if(r)try{this.processRequest(r),await new Promise(s=>setTimeout(s,300))}catch(s){this.client.logger.warn(s)}}this.requestQueue.state=$t.idle},this.processRequest=r=>{const{topic:s,payload:o}=r,u=o.method;switch(u){case"wc_sessionPropose":return this.onSessionProposeRequest(s,o);case"wc_sessionSettle":return this.onSessionSettleRequest(s,o);case"wc_sessionUpdate":return this.onSessionUpdateRequest(s,o);case"wc_sessionExtend":return this.onSessionExtendRequest(s,o);case"wc_sessionPing":return this.onSessionPingRequest(s,o);case"wc_sessionDelete":return this.onSessionDeleteRequest(s,o);case"wc_sessionRequest":return this.onSessionRequest(s,o);case"wc_sessionEvent":return this.onSessionEventRequest(s,o);default:return this.client.logger.info(`Unsupported request method ${u}`)}},this.onRelayEventResponse=async r=>{const{topic:s,payload:o}=r,u=(await this.client.core.history.get(s,o.id)).request.method;switch(u){case"wc_sessionPropose":return this.onSessionProposeResponse(s,o);case"wc_sessionSettle":return this.onSessionSettleResponse(s,o);case"wc_sessionUpdate":return this.onSessionUpdateResponse(s,o);case"wc_sessionExtend":return this.onSessionExtendResponse(s,o);case"wc_sessionPing":return this.onSessionPingResponse(s,o);case"wc_sessionRequest":return this.onSessionRequestResponse(s,o);default:return this.client.logger.info(`Unsupported response method ${u}`)}},this.onRelayEventUnknownPayload=r=>{const{topic:s}=r,{message:o}=$("MISSING_OR_INVALID",`Decoded payload on topic ${s} is not identifiable as a JSON-RPC request or a response.`);throw new Error(o)},this.onSessionProposeRequest=async(r,s)=>{const{params:o,id:u}=s;try{this.isValidConnect(Le({},s.params));const l=ft(j.cjs.FIVE_MINUTES),g=Le({id:u,pairingTopic:r,expiry:l},o);await this.setProposal(u,g);const w=Nr(JSON.stringify(s)),b=await this.getVerifyContext(w,g.proposer.metadata);this.client.events.emit("session_proposal",{id:u,params:g,verifyContext:b})}catch(l){await this.sendError(u,r,l),this.client.logger.error(l)}},this.onSessionProposeResponse=async(r,s)=>{const{id:o}=s;if(E.isJsonRpcResult(s)){const{result:u}=s;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:u});const l=this.client.proposal.get(o);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:l});const g=l.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:g});const w=u.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:w});const b=await this.client.core.crypto.generateSharedKey(g,w);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",sessionTopic:b});const C=await this.client.core.relayer.subscribe(b);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:C}),await this.client.core.pairing.activate({topic:r})}else E.isJsonRpcError(s)&&(await this.client.proposal.delete(o,ve("USER_DISCONNECTED")),this.events.emit(me("session_connect"),{error:s.error}))},this.onSessionSettleRequest=async(r,s)=>{const{id:o,params:u}=s;try{this.isValidSessionSettleRequest(u);const{relay:l,controller:g,expiry:w,namespaces:b,requiredNamespaces:C,optionalNamespaces:O,sessionProperties:N,pairingTopic:q}=s.params,x=Le({topic:r,relay:l,expiry:w,namespaces:b,acknowledged:!0,pairingTopic:q,requiredNamespaces:C,optionalNamespaces:O,controller:g.publicKey,self:{publicKey:"",metadata:this.client.metadata},peer:{publicKey:g.publicKey,metadata:g.metadata}},N&&{sessionProperties:N});await this.sendResult({id:s.id,topic:r,result:!0}),this.events.emit(me("session_connect"),{session:x}),this.cleanupDuplicatePairings(x)}catch(l){await this.sendError(o,r,l),this.client.logger.error(l)}},this.onSessionSettleResponse=async(r,s)=>{const{id:o}=s;E.isJsonRpcResult(s)?(await this.client.session.update(r,{acknowledged:!0}),this.events.emit(me("session_approve",o),{})):E.isJsonRpcError(s)&&(await this.client.session.delete(r,ve("USER_DISCONNECTED")),this.events.emit(me("session_approve",o),{error:s.error}))},this.onSessionUpdateRequest=async(r,s)=>{const{params:o,id:u}=s;try{const l=`${r}_session_update`,g=fs.get(l);if(g&&this.isRequestOutOfSync(g,u)){this.client.logger.info(`Discarding out of sync request - ${u}`);return}this.isValidUpdate(Le({topic:r},o)),await this.client.session.update(r,{namespaces:o.namespaces}),await this.sendResult({id:u,topic:r,result:!0}),this.client.events.emit("session_update",{id:u,topic:r,params:o}),fs.set(l,u)}catch(l){await this.sendError(u,r,l),this.client.logger.error(l)}},this.isRequestOutOfSync=(r,s)=>parseInt(s.toString().slice(0,-3))<=parseInt(r.toString().slice(0,-3)),this.onSessionUpdateResponse=(r,s)=>{const{id:o}=s;E.isJsonRpcResult(s)?this.events.emit(me("session_update",o),{}):E.isJsonRpcError(s)&&this.events.emit(me("session_update",o),{error:s.error})},this.onSessionExtendRequest=async(r,s)=>{const{id:o}=s;try{this.isValidExtend({topic:r}),await this.setExpiry(r,ft(ds)),await this.sendResult({id:o,topic:r,result:!0}),this.client.events.emit("session_extend",{id:o,topic:r})}catch(u){await this.sendError(o,r,u),this.client.logger.error(u)}},this.onSessionExtendResponse=(r,s)=>{const{id:o}=s;E.isJsonRpcResult(s)?this.events.emit(me("session_extend",o),{}):E.isJsonRpcError(s)&&this.events.emit(me("session_extend",o),{error:s.error})},this.onSessionPingRequest=async(r,s)=>{const{id:o}=s;try{this.isValidPing({topic:r}),await this.sendResult({id:o,topic:r,result:!0}),this.client.events.emit("session_ping",{id:o,topic:r})}catch(u){await this.sendError(o,r,u),this.client.logger.error(u)}},this.onSessionPingResponse=(r,s)=>{const{id:o}=s;setTimeout(()=>{E.isJsonRpcResult(s)?this.events.emit(me("session_ping",o),{}):E.isJsonRpcError(s)&&this.events.emit(me("session_ping",o),{error:s.error})},500)},this.onSessionDeleteRequest=async(r,s)=>{const{id:o}=s;try{this.isValidDisconnect({topic:r,reason:s.params}),await Promise.all([new Promise(u=>{this.client.core.relayer.once(Ne.publish,async()=>{u(await this.deleteSession(r))})}),this.sendResult({id:o,topic:r,result:!0})]),this.client.events.emit("session_delete",{id:o,topic:r})}catch(u){this.client.logger.error(u)}},this.onSessionRequest=async(r,s)=>{const{id:o,params:u}=s;try{this.isValidRequest(Le({topic:r},u));const l=Nr(JSON.stringify(E.formatJsonRpcRequest("wc_sessionRequest",u,o))),g=this.client.session.get(r),w=await this.getVerifyContext(l,g.peer.metadata),b={id:o,topic:r,params:u,verifyContext:w};await this.setPendingSessionRequest(b),this.addSessionRequestToSessionRequestQueue(b),this.processSessionRequestQueue()}catch(l){await this.sendError(o,r,l),this.client.logger.error(l)}},this.onSessionRequestResponse=(r,s)=>{const{id:o}=s;E.isJsonRpcResult(s)?this.events.emit(me("session_request",o),{result:s.result}):E.isJsonRpcError(s)&&this.events.emit(me("session_request",o),{error:s.error})},this.onSessionEventRequest=async(r,s)=>{const{id:o,params:u}=s;try{const l=`${r}_session_event_${u.event.name}`,g=fs.get(l);if(g&&this.isRequestOutOfSync(g,o)){this.client.logger.info(`Discarding out of sync request - ${o}`);return}this.isValidEmit(Le({topic:r},u)),this.client.events.emit("session_event",{id:o,topic:r,params:u}),fs.set(l,o)}catch(l){await this.sendError(o,r,l),this.client.logger.error(l)}},this.addSessionRequestToSessionRequestQueue=r=>{this.sessionRequestQueue.queue.push(r)},this.cleanupAfterResponse=r=>{this.deletePendingSessionRequest(r.response.id,{message:"fulfilled",code:0}),setTimeout(()=>{this.sessionRequestQueue.state=$t.idle,this.processSessionRequestQueue()},j.cjs.toMiliseconds(this.requestQueueDelay))},this.processSessionRequestQueue=()=>{if(this.sessionRequestQueue.state===$t.active){this.client.logger.info("session request queue is already active.");return}const r=this.sessionRequestQueue.queue[0];if(!r){this.client.logger.info("session request queue is empty.");return}try{this.sessionRequestQueue.state=$t.active,this.client.events.emit("session_request",r)}catch(s){this.client.logger.error(s)}},this.onPairingCreated=r=>{if(r.active)return;const s=this.client.proposal.getAll().find(o=>o.pairingTopic===r.topic);s&&this.onSessionProposeRequest(r.topic,E.formatJsonRpcRequest("wc_sessionPropose",{requiredNamespaces:s.requiredNamespaces,optionalNamespaces:s.optionalNamespaces,relays:s.relays,proposer:s.proposer,sessionProperties:s.sessionProperties},s.id))},this.isValidConnect=async r=>{if(!ke(r)){const{message:w}=$("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(r)}`);throw new Error(w)}const{pairingTopic:s,requiredNamespaces:o,optionalNamespaces:u,sessionProperties:l,relays:g}=r;if(xe(s)||await this.isValidPairingTopic(s),!p1(g)){const{message:w}=$("MISSING_OR_INVALID",`connect() relays: ${g}`);throw new Error(w)}!xe(o)&&Cr(o)!==0&&this.validateNamespaces(o,"requiredNamespaces"),!xe(u)&&Cr(u)!==0&&this.validateNamespaces(u,"optionalNamespaces"),xe(l)||this.validateSessionProps(l,"sessionProperties")},this.validateNamespaces=(r,s)=>{const o=l1(r,"connect()",s);if(o)throw new Error(o.message)},this.isValidApprove=async r=>{if(!ke(r))throw new Error($("MISSING_OR_INVALID",`approve() params: ${r}`).message);const{id:s,namespaces:o,relayProtocol:u,sessionProperties:l}=r;await this.isValidProposalId(s);const g=this.client.proposal.get(s),w=ms(o,"approve()");if(w)throw new Error(w.message);const b=Cu(g.requiredNamespaces,o,"approve()");if(b)throw new Error(b.message);if(!Ee(u,!0)){const{message:C}=$("MISSING_OR_INVALID",`approve() relayProtocol: ${u}`);throw new Error(C)}xe(l)||this.validateSessionProps(l,"sessionProperties")},this.isValidReject=async r=>{if(!ke(r)){const{message:u}=$("MISSING_OR_INVALID",`reject() params: ${r}`);throw new Error(u)}const{id:s,reason:o}=r;if(await this.isValidProposalId(s),!d1(o)){const{message:u}=$("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(o)}`);throw new Error(u)}},this.isValidSessionSettleRequest=r=>{if(!ke(r)){const{message:b}=$("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${r}`);throw new Error(b)}const{relay:s,controller:o,namespaces:u,expiry:l}=r;if(!Fh(s)){const{message:b}=$("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(b)}const g=n1(o,"onSessionSettleRequest()");if(g)throw new Error(g.message);const w=ms(u,"onSessionSettleRequest()");if(w)throw new Error(w.message);if(Ht(l)){const{message:b}=$("EXPIRED","onSessionSettleRequest()");throw new Error(b)}},this.isValidUpdate=async r=>{if(!ke(r)){const{message:w}=$("MISSING_OR_INVALID",`update() params: ${r}`);throw new Error(w)}const{topic:s,namespaces:o}=r;await this.isValidSessionTopic(s);const u=this.client.session.get(s),l=ms(o,"update()");if(l)throw new Error(l.message);const g=Cu(u.requiredNamespaces,o,"update()");if(g)throw new Error(g.message)},this.isValidExtend=async r=>{if(!ke(r)){const{message:o}=$("MISSING_OR_INVALID",`extend() params: ${r}`);throw new Error(o)}const{topic:s}=r;await this.isValidSessionTopic(s)},this.isValidRequest=async r=>{if(!ke(r)){const{message:w}=$("MISSING_OR_INVALID",`request() params: ${r}`);throw new Error(w)}const{topic:s,request:o,chainId:u,expiry:l}=r;await this.isValidSessionTopic(s);const{namespaces:g}=this.client.session.get(s);if(!Nu(g,u)){const{message:w}=$("MISSING_OR_INVALID",`request() chainId: ${u}`);throw new Error(w)}if(!g1(o)){const{message:w}=$("MISSING_OR_INVALID",`request() ${JSON.stringify(o)}`);throw new Error(w)}if(!m1(g,u,o.method)){const{message:w}=$("MISSING_OR_INVALID",`request() method: ${o.method}`);throw new Error(w)}if(l&&!E1(l,so)){const{message:w}=$("MISSING_OR_INVALID",`request() expiry: ${l}. Expiry must be a number (in seconds) between ${so.min} and ${so.max}`);throw new Error(w)}},this.isValidRespond=async r=>{var s;if(!ke(r)){const{message:l}=$("MISSING_OR_INVALID",`respond() params: ${r}`);throw new Error(l)}const{topic:o,response:u}=r;try{await this.isValidSessionTopic(o)}catch(l){throw(s=r==null?void 0:r.response)!=null&&s.id&&this.cleanupAfterResponse(r),l}if(!y1(u)){const{message:l}=$("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(u)}`);throw new Error(l)}},this.isValidPing=async r=>{if(!ke(r)){const{message:o}=$("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(o)}const{topic:s}=r;await this.isValidSessionOrPairingTopic(s)},this.isValidEmit=async r=>{if(!ke(r)){const{message:g}=$("MISSING_OR_INVALID",`emit() params: ${r}`);throw new Error(g)}const{topic:s,event:o,chainId:u}=r;await this.isValidSessionTopic(s);const{namespaces:l}=this.client.session.get(s);if(!Nu(l,u)){const{message:g}=$("MISSING_OR_INVALID",`emit() chainId: ${u}`);throw new Error(g)}if(!v1(o)){const{message:g}=$("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(o)}`);throw new Error(g)}if(!w1(l,u,o.name)){const{message:g}=$("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(o)}`);throw new Error(g)}},this.isValidDisconnect=async r=>{if(!ke(r)){const{message:o}=$("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(o)}const{topic:s}=r;await this.isValidSessionOrPairingTopic(s)},this.getVerifyContext=async(r,s)=>{const o={verified:{verifyUrl:s.verifyUrl||Rr,validation:"UNKNOWN",origin:s.url||""}};try{const u=await this.client.core.verify.resolve({attestationId:r,verifyUrl:s.verifyUrl});u&&(o.verified.origin=u.origin,o.verified.isScam=u.isScam,o.verified.validation=u.origin===new URL(s.url).origin?"VALID":"INVALID")}catch(u){this.client.logger.info(u)}return this.client.logger.info(`Verify context: ${JSON.stringify(o)}`),o},this.validateSessionProps=(r,s)=>{Object.values(r).forEach(o=>{if(!Ee(o,!1)){const{message:u}=$("MISSING_OR_INVALID",`${s} must be in Record<string, string> format. Received: ${JSON.stringify(o)}`);throw new Error(u)}})}}async isInitialized(){if(!this.initialized){const{message:t}=$("NOT_INITIALIZED",this.name);throw new Error(t)}await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(Ne.message,async t=>{const{topic:r,message:s}=t;if(this.ignoredPayloadTypes.includes(this.client.core.crypto.getPayloadType(s)))return;const o=await this.client.core.crypto.decode(r,s);try{E.isJsonRpcRequest(o)?(this.client.core.history.set(r,o),this.onRelayEventRequest({topic:r,payload:o})):E.isJsonRpcResponse(o)?(await this.client.core.history.resolve(o),await this.onRelayEventResponse({topic:r,payload:o}),this.client.core.history.delete(r,o.id)):this.onRelayEventUnknownPayload({topic:r,payload:o})}catch(u){this.client.logger.error(u)}})}registerExpirerEvents(){this.client.core.expirer.on(nt.expired,async t=>{const{topic:r,id:s}=xh(t.target);if(s&&this.client.pendingRequest.keys.includes(s))return await this.deletePendingSessionRequest(s,$("EXPIRED"),!0);r?this.client.session.keys.includes(r)&&(await this.deleteSession(r,!0),this.client.events.emit("session_expire",{topic:r})):s&&(await this.deleteProposal(s,!0),this.client.events.emit("proposal_expire",{id:s}))})}registerPairingEvents(){this.client.core.pairing.events.on(pi.create,t=>this.onPairingCreated(t))}isValidPairingTopic(t){if(!Ee(t,!1)){const{message:r}=$("MISSING_OR_INVALID",`pairing topic should be a string: ${t}`);throw new Error(r)}if(!this.client.core.pairing.pairings.keys.includes(t)){const{message:r}=$("NO_MATCHING_KEY",`pairing topic doesn't exist: ${t}`);throw new Error(r)}if(Ht(this.client.core.pairing.pairings.get(t).expiry)){const{message:r}=$("EXPIRED",`pairing topic: ${t}`);throw new Error(r)}}async isValidSessionTopic(t){if(!Ee(t,!1)){const{message:r}=$("MISSING_OR_INVALID",`session topic should be a string: ${t}`);throw new Error(r)}if(!this.client.session.keys.includes(t)){const{message:r}=$("NO_MATCHING_KEY",`session topic doesn't exist: ${t}`);throw new Error(r)}if(Ht(this.client.session.get(t).expiry)){await this.deleteSession(t);const{message:r}=$("EXPIRED",`session topic: ${t}`);throw new Error(r)}}async isValidSessionOrPairingTopic(t){if(this.client.session.keys.includes(t))await this.isValidSessionTopic(t);else if(this.client.core.pairing.pairings.keys.includes(t))this.isValidPairingTopic(t);else if(Ee(t,!1)){const{message:r}=$("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${t}`);throw new Error(r)}else{const{message:r}=$("MISSING_OR_INVALID",`session or pairing topic should be a string: ${t}`);throw new Error(r)}}async isValidProposalId(t){if(!f1(t)){const{message:r}=$("MISSING_OR_INVALID",`proposal id should be a number: ${t}`);throw new Error(r)}if(!this.client.proposal.keys.includes(t)){const{message:r}=$("NO_MATCHING_KEY",`proposal id doesn't exist: ${t}`);throw new Error(r)}if(Ht(this.client.proposal.get(t).expiry)){await this.deleteProposal(t);const{message:r}=$("EXPIRED",`proposal id: ${t}`);throw new Error(r)}}}class EE extends Os{constructor(t,r){super(t,r,lE,Ao),this.core=t,this.logger=r}}class IE extends Os{constructor(t,r){super(t,r,pE,Ao),this.core=t,this.logger=r}}class PE extends Os{constructor(t,r){super(t,r,dE,Ao,s=>s.id),this.core=t,this.logger=r}}let SE=class tl extends Yw{constructor(t){super(t),this.protocol=Yh,this.version=Zh,this.name=io.name,this.events=new He.eventsExports.EventEmitter,this.on=(s,o)=>this.events.on(s,o),this.once=(s,o)=>this.events.once(s,o),this.off=(s,o)=>this.events.off(s,o),this.removeListener=(s,o)=>this.events.removeListener(s,o),this.removeAllListeners=s=>this.events.removeAllListeners(s),this.connect=async s=>{try{return await this.engine.connect(s)}catch(o){throw this.logger.error(o.message),o}},this.pair=async s=>{try{return await this.engine.pair(s)}catch(o){throw this.logger.error(o.message),o}},this.approve=async s=>{try{return await this.engine.approve(s)}catch(o){throw this.logger.error(o.message),o}},this.reject=async s=>{try{return await this.engine.reject(s)}catch(o){throw this.logger.error(o.message),o}},this.update=async s=>{try{return await this.engine.update(s)}catch(o){throw this.logger.error(o.message),o}},this.extend=async s=>{try{return await this.engine.extend(s)}catch(o){throw this.logger.error(o.message),o}},this.request=async s=>{try{return await this.engine.request(s)}catch(o){throw this.logger.error(o.message),o}},this.respond=async s=>{try{return await this.engine.respond(s)}catch(o){throw this.logger.error(o.message),o}},this.ping=async s=>{try{return await this.engine.ping(s)}catch(o){throw this.logger.error(o.message),o}},this.emit=async s=>{try{return await this.engine.emit(s)}catch(o){throw this.logger.error(o.message),o}},this.disconnect=async s=>{try{return await this.engine.disconnect(s)}catch(o){throw this.logger.error(o.message),o}},this.find=s=>{try{return this.engine.find(s)}catch(o){throw this.logger.error(o.message),o}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(s){throw this.logger.error(s.message),s}},this.name=(t==null?void 0:t.name)||io.name,this.metadata=(t==null?void 0:t.metadata)||$_();const r=typeof(t==null?void 0:t.logger)<"u"&&typeof(t==null?void 0:t.logger)!="string"?t.logger:E.Tt(E.k({level:(t==null?void 0:t.logger)||io.logger}));this.core=(t==null?void 0:t.core)||new hE(t),this.logger=E.E(r,this.name),this.session=new IE(this.core,this.logger),this.proposal=new EE(this.core,this.logger),this.pendingRequest=new PE(this.core,this.logger),this.engine=new bE(this)}static async init(t){const r=new tl(t);return await r.initialize(),r}get context(){return E.y(this.logger)}get pairing(){return this.core.pairing.pairings}async initialize(){this.logger.trace("Initialized");try{await this.core.start(),await this.session.init(),await this.proposal.init(),await this.pendingRequest.init(),await this.engine.init(),this.core.verify.init({verifyUrl:this.metadata.verifyUrl}),this.logger.info("SignClient Initialization Success")}catch(t){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(t.message),t}}};const OE=a=>JSON.stringify(a,(t,r)=>typeof r=="bigint"?r.toString()+"n":r),RE=a=>{const t=/([\[:])?(\d{17,}|(?:[9](?:[1-9]07199254740991|0[1-9]7199254740991|00[8-9]199254740991|007[2-9]99254740991|007199[3-9]54740991|0071992[6-9]4740991|00719925[5-9]740991|007199254[8-9]40991|0071992547[5-9]0991|00719925474[1-9]991|00719925474099[2-9])))([,\}\]])/g,r=a.replace(t,'$1"$2n"$3');return JSON.parse(r,(s,o)=>typeof o=="string"&&o.match(/^\d+n$/)?BigInt(o.substring(0,o.length-1)):o)};function NE(a){if(typeof a!="string")throw new Error(`Cannot safe json parse value of type ${typeof a}`);try{return RE(a)}catch{return a}}function rh(a){return typeof a=="string"?a:OE(a)||""}var CE=Object.defineProperty,$E=Object.defineProperties,TE=Object.getOwnPropertyDescriptors,ih=Object.getOwnPropertySymbols,AE=Object.prototype.hasOwnProperty,xE=Object.prototype.propertyIsEnumerable,sh=(a,t,r)=>t in a?CE(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,nh=(a,t)=>{for(var r in t||(t={}))AE.call(t,r)&&sh(a,r,t[r]);if(ih)for(var r of ih(t))xE.call(t,r)&&sh(a,r,t[r]);return a},oh=(a,t)=>$E(a,TE(t));const DE={Accept:"application/json","Content-Type":"application/json"},FE="POST",ah={headers:DE,method:FE},ch=10;let Bt=class{constructor(t,r=!1){if(this.url=t,this.disableProviderPing=r,this.events=new He.eventsExports.EventEmitter,this.isAvailable=!1,this.registering=!1,!E.isHttpUrl(t))throw new Error(`Provided URL is not compatible with HTTP connection: ${t}`);this.url=t,this.disableProviderPing=r}get connected(){return this.isAvailable}get connecting(){return this.registering}on(t,r){this.events.on(t,r)}once(t,r){this.events.once(t,r)}off(t,r){this.events.off(t,r)}removeListener(t,r){this.events.removeListener(t,r)}async open(t=this.url){await this.register(t)}async close(){if(!this.isAvailable)throw new Error("Connection already closed");this.onClose()}async send(t){this.isAvailable||await this.register();try{const r=rh(t),s=await(await W.o(this.url,oh(nh({},ah),{body:r}))).json();this.onPayload({data:s})}catch(r){this.onError(t.id,r)}}async register(t=this.url){if(!E.isHttpUrl(t))throw new Error(`Provided URL is not compatible with HTTP connection: ${t}`);if(this.registering){const r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((s,o)=>{this.events.once("register_error",u=>{this.resetMaxListeners(),o(u)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.isAvailable>"u")return o(new Error("HTTP connection is missing or invalid"));s()})})}this.url=t,this.registering=!0;try{if(!this.disableProviderPing){const r=rh({id:1,jsonrpc:"2.0",method:"test",params:[]});await W.o(t,oh(nh({},ah),{body:r}))}this.onOpen()}catch(r){const s=this.parseError(r);throw this.events.emit("register_error",s),this.onClose(),s}}onOpen(){this.isAvailable=!0,this.registering=!1,this.events.emit("open")}onClose(){this.isAvailable=!1,this.registering=!1,this.events.emit("close")}onPayload(t){if(typeof t.data>"u")return;const r=typeof t.data=="string"?NE(t.data):t.data;this.events.emit("payload",r)}onError(t,r){const s=this.parseError(r),o=s.message||s.toString(),u=E.formatJsonRpcError(t,o);this.events.emit("payload",u)}parseError(t,r=this.url){return E.parseConnectionError(t,r,"HTTP")}resetMaxListeners(){this.events.getMaxListeners()>ch&&this.events.setMaxListeners(ch)}};const uh="error",jE="wss://relay.walletconnect.com",qE="wc",UE="universal_provider",hh=`${qE}@2:${UE}:`,ME="https://rpc.walletconnect.com/v1/",At={DEFAULT_CHAIN_CHANGED:"default_chain_changed"};var hi=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof W.dist.global<"u"?W.dist.global:typeof self<"u"?self:{},bo={exports:{}};/**
|
|
21
|
+
* @license
|
|
22
|
+
* Lodash <https://lodash.com/>
|
|
23
|
+
* Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
|
|
24
|
+
* Released under MIT license <https://lodash.com/license>
|
|
25
|
+
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
|
26
|
+
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
27
|
+
*/(function(a,t){(function(){var r,s="4.17.21",o=200,u="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",l="Expected a function",g="Invalid `variable` option passed into `_.template`",w="__lodash_hash_undefined__",b=500,C="__lodash_placeholder__",O=1,N=2,q=4,x=1,K=2,D=1,Q=2,fe=4,Z=8,ee=16,he=32,Fe=64,de=128,Ce=256,xt=512,ol=30,al="...",cl=800,ul=16,Do=1,hl=2,ll=3,wi=1/0,ur=9007199254740991,pl=17976931348623157e292,_i=NaN,dt=4294967295,fl=dt-1,dl=dt>>>1,gl=[["ary",de],["bind",D],["bindKey",Q],["curry",Z],["curryRight",ee],["flip",xt],["partial",he],["partialRight",Fe],["rearg",Ce]],hr="[object Arguments]",bi="[object Array]",yl="[object AsyncFunction]",jr="[object Boolean]",qr="[object Date]",vl="[object DOMException]",Ei="[object Error]",Ii="[object Function]",Fo="[object GeneratorFunction]",ot="[object Map]",Ur="[object Number]",ml="[object Null]",wt="[object Object]",jo="[object Promise]",wl="[object Proxy]",Mr="[object RegExp]",at="[object Set]",Lr="[object String]",Pi="[object Symbol]",_l="[object Undefined]",kr="[object WeakMap]",bl="[object WeakSet]",zr="[object ArrayBuffer]",lr="[object DataView]",Ns="[object Float32Array]",Cs="[object Float64Array]",$s="[object Int8Array]",Ts="[object Int16Array]",As="[object Int32Array]",xs="[object Uint8Array]",Ds="[object Uint8ClampedArray]",Fs="[object Uint16Array]",js="[object Uint32Array]",El=/\b__p \+= '';/g,Il=/\b(__p \+=) '' \+/g,Pl=/(__e\(.*?\)|\b__t\)) \+\n'';/g,qo=/&(?:amp|lt|gt|quot|#39);/g,Uo=/[&<>"']/g,Sl=RegExp(qo.source),Ol=RegExp(Uo.source),Rl=/<%-([\s\S]+?)%>/g,Nl=/<%([\s\S]+?)%>/g,Mo=/<%=([\s\S]+?)%>/g,Cl=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,$l=/^\w*$/,Tl=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,qs=/[\\^$.*+?()[\]{}|]/g,Al=RegExp(qs.source),Us=/^\s+/,xl=/\s/,Dl=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Fl=/\{\n\/\* \[wrapped with (.+)\] \*/,jl=/,? & /,ql=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Ul=/[()=,{}\[\]\/\s]/,Ml=/\\(\\)?/g,Ll=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,Lo=/\w*$/,kl=/^[-+]0x[0-9a-f]+$/i,zl=/^0b[01]+$/i,Hl=/^\[object .+?Constructor\]$/,Vl=/^0o[0-7]+$/i,Kl=/^(?:0|[1-9]\d*)$/,Bl=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Si=/($^)/,Wl=/['\n\r\u2028\u2029\\]/g,Oi="\\ud800-\\udfff",Jl="\\u0300-\\u036f",Gl="\\ufe20-\\ufe2f",Ql="\\u20d0-\\u20ff",ko=Jl+Gl+Ql,zo="\\u2700-\\u27bf",Ho="a-z\\xdf-\\xf6\\xf8-\\xff",Yl="\\xac\\xb1\\xd7\\xf7",Zl="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Xl="\\u2000-\\u206f",ep=" \\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",Vo="A-Z\\xc0-\\xd6\\xd8-\\xde",Ko="\\ufe0e\\ufe0f",Bo=Yl+Zl+Xl+ep,Ms="['’]",tp="["+Oi+"]",Wo="["+Bo+"]",Ri="["+ko+"]",Jo="\\d+",rp="["+zo+"]",Go="["+Ho+"]",Qo="[^"+Oi+Bo+Jo+zo+Ho+Vo+"]",Ls="\\ud83c[\\udffb-\\udfff]",ip="(?:"+Ri+"|"+Ls+")",Yo="[^"+Oi+"]",ks="(?:\\ud83c[\\udde6-\\uddff]){2}",zs="[\\ud800-\\udbff][\\udc00-\\udfff]",pr="["+Vo+"]",Zo="\\u200d",Xo="(?:"+Go+"|"+Qo+")",sp="(?:"+pr+"|"+Qo+")",ea="(?:"+Ms+"(?:d|ll|m|re|s|t|ve))?",ta="(?:"+Ms+"(?:D|LL|M|RE|S|T|VE))?",ra=ip+"?",ia="["+Ko+"]?",np="(?:"+Zo+"(?:"+[Yo,ks,zs].join("|")+")"+ia+ra+")*",op="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",ap="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",sa=ia+ra+np,cp="(?:"+[rp,ks,zs].join("|")+")"+sa,up="(?:"+[Yo+Ri+"?",Ri,ks,zs,tp].join("|")+")",hp=RegExp(Ms,"g"),lp=RegExp(Ri,"g"),Hs=RegExp(Ls+"(?="+Ls+")|"+up+sa,"g"),pp=RegExp([pr+"?"+Go+"+"+ea+"(?="+[Wo,pr,"$"].join("|")+")",sp+"+"+ta+"(?="+[Wo,pr+Xo,"$"].join("|")+")",pr+"?"+Xo+"+"+ea,pr+"+"+ta,ap,op,Jo,cp].join("|"),"g"),fp=RegExp("["+Zo+Oi+ko+Ko+"]"),dp=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,gp=["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"],yp=-1,ae={};ae[Ns]=ae[Cs]=ae[$s]=ae[Ts]=ae[As]=ae[xs]=ae[Ds]=ae[Fs]=ae[js]=!0,ae[hr]=ae[bi]=ae[zr]=ae[jr]=ae[lr]=ae[qr]=ae[Ei]=ae[Ii]=ae[ot]=ae[Ur]=ae[wt]=ae[Mr]=ae[at]=ae[Lr]=ae[kr]=!1;var se={};se[hr]=se[bi]=se[zr]=se[lr]=se[jr]=se[qr]=se[Ns]=se[Cs]=se[$s]=se[Ts]=se[As]=se[ot]=se[Ur]=se[wt]=se[Mr]=se[at]=se[Lr]=se[Pi]=se[xs]=se[Ds]=se[Fs]=se[js]=!0,se[Ei]=se[Ii]=se[kr]=!1;var vp={À:"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"},mp={"&":"&","<":"<",">":">",'"':""","'":"'"},wp={"&":"&","<":"<",">":">",""":'"',"'":"'"},_p={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},bp=parseFloat,Ep=parseInt,na=typeof hi=="object"&&hi&&hi.Object===Object&&hi,Ip=typeof self=="object"&&self&&self.Object===Object&&self,Ie=na||Ip||Function("return this")(),Vs=t&&!t.nodeType&&t,Wt=Vs&&!0&&a&&!a.nodeType&&a,oa=Wt&&Wt.exports===Vs,Ks=oa&&na.process,Ye=function(){try{var v=Wt&&Wt.require&&Wt.require("util").types;return v||Ks&&Ks.binding&&Ks.binding("util")}catch{}}(),aa=Ye&&Ye.isArrayBuffer,ca=Ye&&Ye.isDate,ua=Ye&&Ye.isMap,ha=Ye&&Ye.isRegExp,la=Ye&&Ye.isSet,pa=Ye&&Ye.isTypedArray;function Ve(v,I,_){switch(_.length){case 0:return v.call(I);case 1:return v.call(I,_[0]);case 2:return v.call(I,_[0],_[1]);case 3:return v.call(I,_[0],_[1],_[2])}return v.apply(I,_)}function Pp(v,I,_,A){for(var k=-1,X=v==null?0:v.length;++k<X;){var we=v[k];I(A,we,_(we),v)}return A}function Ze(v,I){for(var _=-1,A=v==null?0:v.length;++_<A&&I(v[_],_,v)!==!1;);return v}function Sp(v,I){for(var _=v==null?0:v.length;_--&&I(v[_],_,v)!==!1;);return v}function fa(v,I){for(var _=-1,A=v==null?0:v.length;++_<A;)if(!I(v[_],_,v))return!1;return!0}function Dt(v,I){for(var _=-1,A=v==null?0:v.length,k=0,X=[];++_<A;){var we=v[_];I(we,_,v)&&(X[k++]=we)}return X}function Ni(v,I){var _=v==null?0:v.length;return!!_&&fr(v,I,0)>-1}function Bs(v,I,_){for(var A=-1,k=v==null?0:v.length;++A<k;)if(_(I,v[A]))return!0;return!1}function ce(v,I){for(var _=-1,A=v==null?0:v.length,k=Array(A);++_<A;)k[_]=I(v[_],_,v);return k}function Ft(v,I){for(var _=-1,A=I.length,k=v.length;++_<A;)v[k+_]=I[_];return v}function Ws(v,I,_,A){var k=-1,X=v==null?0:v.length;for(A&&X&&(_=v[++k]);++k<X;)_=I(_,v[k],k,v);return _}function Op(v,I,_,A){var k=v==null?0:v.length;for(A&&k&&(_=v[--k]);k--;)_=I(_,v[k],k,v);return _}function Js(v,I){for(var _=-1,A=v==null?0:v.length;++_<A;)if(I(v[_],_,v))return!0;return!1}var Rp=Gs("length");function Np(v){return v.split("")}function Cp(v){return v.match(ql)||[]}function da(v,I,_){var A;return _(v,function(k,X,we){if(I(k,X,we))return A=X,!1}),A}function Ci(v,I,_,A){for(var k=v.length,X=_+(A?1:-1);A?X--:++X<k;)if(I(v[X],X,v))return X;return-1}function fr(v,I,_){return I===I?kp(v,I,_):Ci(v,ga,_)}function $p(v,I,_,A){for(var k=_-1,X=v.length;++k<X;)if(A(v[k],I))return k;return-1}function ga(v){return v!==v}function ya(v,I){var _=v==null?0:v.length;return _?Ys(v,I)/_:_i}function Gs(v){return function(I){return I==null?r:I[v]}}function Qs(v){return function(I){return v==null?r:v[I]}}function va(v,I,_,A,k){return k(v,function(X,we,ie){_=A?(A=!1,X):I(_,X,we,ie)}),_}function Tp(v,I){var _=v.length;for(v.sort(I);_--;)v[_]=v[_].value;return v}function Ys(v,I){for(var _,A=-1,k=v.length;++A<k;){var X=I(v[A]);X!==r&&(_=_===r?X:_+X)}return _}function Zs(v,I){for(var _=-1,A=Array(v);++_<v;)A[_]=I(_);return A}function Ap(v,I){return ce(I,function(_){return[_,v[_]]})}function ma(v){return v&&v.slice(0,Ea(v)+1).replace(Us,"")}function Ke(v){return function(I){return v(I)}}function Xs(v,I){return ce(I,function(_){return v[_]})}function Hr(v,I){return v.has(I)}function wa(v,I){for(var _=-1,A=v.length;++_<A&&fr(I,v[_],0)>-1;);return _}function _a(v,I){for(var _=v.length;_--&&fr(I,v[_],0)>-1;);return _}function xp(v,I){for(var _=v.length,A=0;_--;)v[_]===I&&++A;return A}var Dp=Qs(vp),Fp=Qs(mp);function jp(v){return"\\"+_p[v]}function qp(v,I){return v==null?r:v[I]}function dr(v){return fp.test(v)}function Up(v){return dp.test(v)}function Mp(v){for(var I,_=[];!(I=v.next()).done;)_.push(I.value);return _}function en(v){var I=-1,_=Array(v.size);return v.forEach(function(A,k){_[++I]=[k,A]}),_}function ba(v,I){return function(_){return v(I(_))}}function jt(v,I){for(var _=-1,A=v.length,k=0,X=[];++_<A;){var we=v[_];(we===I||we===C)&&(v[_]=C,X[k++]=_)}return X}function $i(v){var I=-1,_=Array(v.size);return v.forEach(function(A){_[++I]=A}),_}function Lp(v){var I=-1,_=Array(v.size);return v.forEach(function(A){_[++I]=[A,A]}),_}function kp(v,I,_){for(var A=_-1,k=v.length;++A<k;)if(v[A]===I)return A;return-1}function zp(v,I,_){for(var A=_+1;A--;)if(v[A]===I)return A;return A}function gr(v){return dr(v)?Vp(v):Rp(v)}function ct(v){return dr(v)?Kp(v):Np(v)}function Ea(v){for(var I=v.length;I--&&xl.test(v.charAt(I)););return I}var Hp=Qs(wp);function Vp(v){for(var I=Hs.lastIndex=0;Hs.test(v);)++I;return I}function Kp(v){return v.match(Hs)||[]}function Bp(v){return v.match(pp)||[]}var Wp=function v(I){I=I==null?Ie:yr.defaults(Ie.Object(),I,yr.pick(Ie,gp));var _=I.Array,A=I.Date,k=I.Error,X=I.Function,we=I.Math,ie=I.Object,tn=I.RegExp,Jp=I.String,Xe=I.TypeError,Ti=_.prototype,Gp=X.prototype,vr=ie.prototype,Ai=I["__core-js_shared__"],xi=Gp.toString,re=vr.hasOwnProperty,Qp=0,Ia=function(){var e=/[^.]+$/.exec(Ai&&Ai.keys&&Ai.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}(),Di=vr.toString,Yp=xi.call(ie),Zp=Ie._,Xp=tn("^"+xi.call(re).replace(qs,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),Fi=oa?I.Buffer:r,qt=I.Symbol,ji=I.Uint8Array,Pa=Fi?Fi.allocUnsafe:r,qi=ba(ie.getPrototypeOf,ie),Sa=ie.create,Oa=vr.propertyIsEnumerable,Ui=Ti.splice,Ra=qt?qt.isConcatSpreadable:r,Vr=qt?qt.iterator:r,Jt=qt?qt.toStringTag:r,Mi=function(){try{var e=Xt(ie,"defineProperty");return e({},"",{}),e}catch{}}(),ef=I.clearTimeout!==Ie.clearTimeout&&I.clearTimeout,tf=A&&A.now!==Ie.Date.now&&A.now,rf=I.setTimeout!==Ie.setTimeout&&I.setTimeout,Li=we.ceil,ki=we.floor,rn=ie.getOwnPropertySymbols,sf=Fi?Fi.isBuffer:r,Na=I.isFinite,nf=Ti.join,of=ba(ie.keys,ie),_e=we.max,Oe=we.min,af=A.now,cf=I.parseInt,Ca=we.random,uf=Ti.reverse,sn=Xt(I,"DataView"),Kr=Xt(I,"Map"),nn=Xt(I,"Promise"),mr=Xt(I,"Set"),Br=Xt(I,"WeakMap"),Wr=Xt(ie,"create"),zi=Br&&new Br,wr={},hf=er(sn),lf=er(Kr),pf=er(nn),ff=er(mr),df=er(Br),Hi=qt?qt.prototype:r,Jr=Hi?Hi.valueOf:r,$a=Hi?Hi.toString:r;function p(e){if(pe(e)&&!z(e)&&!(e instanceof G)){if(e instanceof et)return e;if(re.call(e,"__wrapped__"))return Tc(e)}return new et(e)}var _r=function(){function e(){}return function(i){if(!le(i))return{};if(Sa)return Sa(i);e.prototype=i;var n=new e;return e.prototype=r,n}}();function Vi(){}function et(e,i){this.__wrapped__=e,this.__actions__=[],this.__chain__=!!i,this.__index__=0,this.__values__=r}p.templateSettings={escape:Rl,evaluate:Nl,interpolate:Mo,variable:"",imports:{_:p}},p.prototype=Vi.prototype,p.prototype.constructor=p,et.prototype=_r(Vi.prototype),et.prototype.constructor=et;function G(e){this.__wrapped__=e,this.__actions__=[],this.__dir__=1,this.__filtered__=!1,this.__iteratees__=[],this.__takeCount__=dt,this.__views__=[]}function gf(){var e=new G(this.__wrapped__);return e.__actions__=je(this.__actions__),e.__dir__=this.__dir__,e.__filtered__=this.__filtered__,e.__iteratees__=je(this.__iteratees__),e.__takeCount__=this.__takeCount__,e.__views__=je(this.__views__),e}function yf(){if(this.__filtered__){var e=new G(this);e.__dir__=-1,e.__filtered__=!0}else e=this.clone(),e.__dir__*=-1;return e}function vf(){var e=this.__wrapped__.value(),i=this.__dir__,n=z(e),c=i<0,h=n?e.length:0,f=Cd(0,h,this.__views__),d=f.start,y=f.end,m=y-d,P=c?y:d-1,S=this.__iteratees__,R=S.length,T=0,F=Oe(m,this.__takeCount__);if(!n||!c&&h==m&&F==m)return ec(e,this.__actions__);var M=[];e:for(;m--&&T<F;){P+=i;for(var V=-1,L=e[P];++V<R;){var J=S[V],Y=J.iteratee,Je=J.type,Ae=Y(L);if(Je==hl)L=Ae;else if(!Ae){if(Je==Do)continue e;break e}}M[T++]=L}return M}G.prototype=_r(Vi.prototype),G.prototype.constructor=G;function Gt(e){var i=-1,n=e==null?0:e.length;for(this.clear();++i<n;){var c=e[i];this.set(c[0],c[1])}}function mf(){this.__data__=Wr?Wr(null):{},this.size=0}function wf(e){var i=this.has(e)&&delete this.__data__[e];return this.size-=i?1:0,i}function _f(e){var i=this.__data__;if(Wr){var n=i[e];return n===w?r:n}return re.call(i,e)?i[e]:r}function bf(e){var i=this.__data__;return Wr?i[e]!==r:re.call(i,e)}function Ef(e,i){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=Wr&&i===r?w:i,this}Gt.prototype.clear=mf,Gt.prototype.delete=wf,Gt.prototype.get=_f,Gt.prototype.has=bf,Gt.prototype.set=Ef;function _t(e){var i=-1,n=e==null?0:e.length;for(this.clear();++i<n;){var c=e[i];this.set(c[0],c[1])}}function If(){this.__data__=[],this.size=0}function Pf(e){var i=this.__data__,n=Ki(i,e);if(n<0)return!1;var c=i.length-1;return n==c?i.pop():Ui.call(i,n,1),--this.size,!0}function Sf(e){var i=this.__data__,n=Ki(i,e);return n<0?r:i[n][1]}function Of(e){return Ki(this.__data__,e)>-1}function Rf(e,i){var n=this.__data__,c=Ki(n,e);return c<0?(++this.size,n.push([e,i])):n[c][1]=i,this}_t.prototype.clear=If,_t.prototype.delete=Pf,_t.prototype.get=Sf,_t.prototype.has=Of,_t.prototype.set=Rf;function bt(e){var i=-1,n=e==null?0:e.length;for(this.clear();++i<n;){var c=e[i];this.set(c[0],c[1])}}function Nf(){this.size=0,this.__data__={hash:new Gt,map:new(Kr||_t),string:new Gt}}function Cf(e){var i=is(this,e).delete(e);return this.size-=i?1:0,i}function $f(e){return is(this,e).get(e)}function Tf(e){return is(this,e).has(e)}function Af(e,i){var n=is(this,e),c=n.size;return n.set(e,i),this.size+=n.size==c?0:1,this}bt.prototype.clear=Nf,bt.prototype.delete=Cf,bt.prototype.get=$f,bt.prototype.has=Tf,bt.prototype.set=Af;function Qt(e){var i=-1,n=e==null?0:e.length;for(this.__data__=new bt;++i<n;)this.add(e[i])}function xf(e){return this.__data__.set(e,w),this}function Df(e){return this.__data__.has(e)}Qt.prototype.add=Qt.prototype.push=xf,Qt.prototype.has=Df;function ut(e){var i=this.__data__=new _t(e);this.size=i.size}function Ff(){this.__data__=new _t,this.size=0}function jf(e){var i=this.__data__,n=i.delete(e);return this.size=i.size,n}function qf(e){return this.__data__.get(e)}function Uf(e){return this.__data__.has(e)}function Mf(e,i){var n=this.__data__;if(n instanceof _t){var c=n.__data__;if(!Kr||c.length<o-1)return c.push([e,i]),this.size=++n.size,this;n=this.__data__=new bt(c)}return n.set(e,i),this.size=n.size,this}ut.prototype.clear=Ff,ut.prototype.delete=jf,ut.prototype.get=qf,ut.prototype.has=Uf,ut.prototype.set=Mf;function Ta(e,i){var n=z(e),c=!n&&tr(e),h=!n&&!c&&zt(e),f=!n&&!c&&!h&&Pr(e),d=n||c||h||f,y=d?Zs(e.length,Jp):[],m=y.length;for(var P in e)(i||re.call(e,P))&&!(d&&(P=="length"||h&&(P=="offset"||P=="parent")||f&&(P=="buffer"||P=="byteLength"||P=="byteOffset")||St(P,m)))&&y.push(P);return y}function Aa(e){var i=e.length;return i?e[yn(0,i-1)]:r}function Lf(e,i){return ss(je(e),Yt(i,0,e.length))}function kf(e){return ss(je(e))}function on(e,i,n){(n!==r&&!ht(e[i],n)||n===r&&!(i in e))&&Et(e,i,n)}function Gr(e,i,n){var c=e[i];(!(re.call(e,i)&&ht(c,n))||n===r&&!(i in e))&&Et(e,i,n)}function Ki(e,i){for(var n=e.length;n--;)if(ht(e[n][0],i))return n;return-1}function zf(e,i,n,c){return Ut(e,function(h,f,d){i(c,h,n(h),d)}),c}function xa(e,i){return e&&yt(i,be(i),e)}function Hf(e,i){return e&&yt(i,Ue(i),e)}function Et(e,i,n){i=="__proto__"&&Mi?Mi(e,i,{configurable:!0,enumerable:!0,value:n,writable:!0}):e[i]=n}function an(e,i){for(var n=-1,c=i.length,h=_(c),f=e==null;++n<c;)h[n]=f?r:kn(e,i[n]);return h}function Yt(e,i,n){return e===e&&(n!==r&&(e=e<=n?e:n),i!==r&&(e=e>=i?e:i)),e}function tt(e,i,n,c,h,f){var d,y=i&O,m=i&N,P=i&q;if(n&&(d=h?n(e,c,h,f):n(e)),d!==r)return d;if(!le(e))return e;var S=z(e);if(S){if(d=Td(e),!y)return je(e,d)}else{var R=Re(e),T=R==Ii||R==Fo;if(zt(e))return ic(e,y);if(R==wt||R==hr||T&&!h){if(d=m||T?{}:Ec(e),!y)return m?_d(e,Hf(d,e)):wd(e,xa(d,e))}else{if(!se[R])return h?e:{};d=Ad(e,R,y)}}f||(f=new ut);var F=f.get(e);if(F)return F;f.set(e,d),Yc(e)?e.forEach(function(L){d.add(tt(L,i,n,L,e,f))}):Gc(e)&&e.forEach(function(L,J){d.set(J,tt(L,i,n,J,e,f))});var M=P?m?Rn:On:m?Ue:be,V=S?r:M(e);return Ze(V||e,function(L,J){V&&(J=L,L=e[J]),Gr(d,J,tt(L,i,n,J,e,f))}),d}function Vf(e){var i=be(e);return function(n){return Da(n,e,i)}}function Da(e,i,n){var c=n.length;if(e==null)return!c;for(e=ie(e);c--;){var h=n[c],f=i[h],d=e[h];if(d===r&&!(h in e)||!f(d))return!1}return!0}function Fa(e,i,n){if(typeof e!="function")throw new Xe(l);return ri(function(){e.apply(r,n)},i)}function Qr(e,i,n,c){var h=-1,f=Ni,d=!0,y=e.length,m=[],P=i.length;if(!y)return m;n&&(i=ce(i,Ke(n))),c?(f=Bs,d=!1):i.length>=o&&(f=Hr,d=!1,i=new Qt(i));e:for(;++h<y;){var S=e[h],R=n==null?S:n(S);if(S=c||S!==0?S:0,d&&R===R){for(var T=P;T--;)if(i[T]===R)continue e;m.push(S)}else f(i,R,c)||m.push(S)}return m}var Ut=cc(gt),ja=cc(un,!0);function Kf(e,i){var n=!0;return Ut(e,function(c,h,f){return n=!!i(c,h,f),n}),n}function Bi(e,i,n){for(var c=-1,h=e.length;++c<h;){var f=e[c],d=i(f);if(d!=null&&(y===r?d===d&&!We(d):n(d,y)))var y=d,m=f}return m}function Bf(e,i,n,c){var h=e.length;for(n=H(n),n<0&&(n=-n>h?0:h+n),c=c===r||c>h?h:H(c),c<0&&(c+=h),c=n>c?0:Xc(c);n<c;)e[n++]=i;return e}function qa(e,i){var n=[];return Ut(e,function(c,h,f){i(c,h,f)&&n.push(c)}),n}function Pe(e,i,n,c,h){var f=-1,d=e.length;for(n||(n=Dd),h||(h=[]);++f<d;){var y=e[f];i>0&&n(y)?i>1?Pe(y,i-1,n,c,h):Ft(h,y):c||(h[h.length]=y)}return h}var cn=uc(),Ua=uc(!0);function gt(e,i){return e&&cn(e,i,be)}function un(e,i){return e&&Ua(e,i,be)}function Wi(e,i){return Dt(i,function(n){return Ot(e[n])})}function Zt(e,i){i=Lt(i,e);for(var n=0,c=i.length;e!=null&&n<c;)e=e[vt(i[n++])];return n&&n==c?e:r}function Ma(e,i,n){var c=i(e);return z(e)?c:Ft(c,n(e))}function $e(e){return e==null?e===r?_l:ml:Jt&&Jt in ie(e)?Nd(e):kd(e)}function hn(e,i){return e>i}function Wf(e,i){return e!=null&&re.call(e,i)}function Jf(e,i){return e!=null&&i in ie(e)}function Gf(e,i,n){return e>=Oe(i,n)&&e<_e(i,n)}function ln(e,i,n){for(var c=n?Bs:Ni,h=e[0].length,f=e.length,d=f,y=_(f),m=1/0,P=[];d--;){var S=e[d];d&&i&&(S=ce(S,Ke(i))),m=Oe(S.length,m),y[d]=!n&&(i||h>=120&&S.length>=120)?new Qt(d&&S):r}S=e[0];var R=-1,T=y[0];e:for(;++R<h&&P.length<m;){var F=S[R],M=i?i(F):F;if(F=n||F!==0?F:0,!(T?Hr(T,M):c(P,M,n))){for(d=f;--d;){var V=y[d];if(!(V?Hr(V,M):c(e[d],M,n)))continue e}T&&T.push(M),P.push(F)}}return P}function Qf(e,i,n,c){return gt(e,function(h,f,d){i(c,n(h),f,d)}),c}function Yr(e,i,n){i=Lt(i,e),e=Oc(e,i);var c=e==null?e:e[vt(it(i))];return c==null?r:Ve(c,e,n)}function La(e){return pe(e)&&$e(e)==hr}function Yf(e){return pe(e)&&$e(e)==zr}function Zf(e){return pe(e)&&$e(e)==qr}function Zr(e,i,n,c,h){return e===i?!0:e==null||i==null||!pe(e)&&!pe(i)?e!==e&&i!==i:Xf(e,i,n,c,Zr,h)}function Xf(e,i,n,c,h,f){var d=z(e),y=z(i),m=d?bi:Re(e),P=y?bi:Re(i);m=m==hr?wt:m,P=P==hr?wt:P;var S=m==wt,R=P==wt,T=m==P;if(T&&zt(e)){if(!zt(i))return!1;d=!0,S=!1}if(T&&!S)return f||(f=new ut),d||Pr(e)?wc(e,i,n,c,h,f):Od(e,i,m,n,c,h,f);if(!(n&x)){var F=S&&re.call(e,"__wrapped__"),M=R&&re.call(i,"__wrapped__");if(F||M){var V=F?e.value():e,L=M?i.value():i;return f||(f=new ut),h(V,L,n,c,f)}}return T?(f||(f=new ut),Rd(e,i,n,c,h,f)):!1}function ed(e){return pe(e)&&Re(e)==ot}function pn(e,i,n,c){var h=n.length,f=h,d=!c;if(e==null)return!f;for(e=ie(e);h--;){var y=n[h];if(d&&y[2]?y[1]!==e[y[0]]:!(y[0]in e))return!1}for(;++h<f;){y=n[h];var m=y[0],P=e[m],S=y[1];if(d&&y[2]){if(P===r&&!(m in e))return!1}else{var R=new ut;if(c)var T=c(P,S,m,e,i,R);if(!(T===r?Zr(S,P,x|K,c,R):T))return!1}}return!0}function ka(e){if(!le(e)||jd(e))return!1;var i=Ot(e)?Xp:Hl;return i.test(er(e))}function td(e){return pe(e)&&$e(e)==Mr}function rd(e){return pe(e)&&Re(e)==at}function id(e){return pe(e)&&hs(e.length)&&!!ae[$e(e)]}function za(e){return typeof e=="function"?e:e==null?Me:typeof e=="object"?z(e)?Ka(e[0],e[1]):Va(e):hu(e)}function fn(e){if(!ti(e))return of(e);var i=[];for(var n in ie(e))re.call(e,n)&&n!="constructor"&&i.push(n);return i}function sd(e){if(!le(e))return Ld(e);var i=ti(e),n=[];for(var c in e)c=="constructor"&&(i||!re.call(e,c))||n.push(c);return n}function dn(e,i){return e<i}function Ha(e,i){var n=-1,c=qe(e)?_(e.length):[];return Ut(e,function(h,f,d){c[++n]=i(h,f,d)}),c}function Va(e){var i=Cn(e);return i.length==1&&i[0][2]?Pc(i[0][0],i[0][1]):function(n){return n===e||pn(n,e,i)}}function Ka(e,i){return Tn(e)&&Ic(i)?Pc(vt(e),i):function(n){var c=kn(n,e);return c===r&&c===i?zn(n,e):Zr(i,c,x|K)}}function Ji(e,i,n,c,h){e!==i&&cn(i,function(f,d){if(h||(h=new ut),le(f))nd(e,i,d,n,Ji,c,h);else{var y=c?c(xn(e,d),f,d+"",e,i,h):r;y===r&&(y=f),on(e,d,y)}},Ue)}function nd(e,i,n,c,h,f,d){var y=xn(e,n),m=xn(i,n),P=d.get(m);if(P){on(e,n,P);return}var S=f?f(y,m,n+"",e,i,d):r,R=S===r;if(R){var T=z(m),F=!T&&zt(m),M=!T&&!F&&Pr(m);S=m,T||F||M?z(y)?S=y:ge(y)?S=je(y):F?(R=!1,S=ic(m,!0)):M?(R=!1,S=sc(m,!0)):S=[]:ii(m)||tr(m)?(S=y,tr(y)?S=eu(y):(!le(y)||Ot(y))&&(S=Ec(m))):R=!1}R&&(d.set(m,S),h(S,m,c,f,d),d.delete(m)),on(e,n,S)}function Ba(e,i){var n=e.length;if(n)return i+=i<0?n:0,St(i,n)?e[i]:r}function Wa(e,i,n){i.length?i=ce(i,function(f){return z(f)?function(d){return Zt(d,f.length===1?f[0]:f)}:f}):i=[Me];var c=-1;i=ce(i,Ke(U()));var h=Ha(e,function(f,d,y){var m=ce(i,function(P){return P(f)});return{criteria:m,index:++c,value:f}});return Tp(h,function(f,d){return md(f,d,n)})}function od(e,i){return Ja(e,i,function(n,c){return zn(e,c)})}function Ja(e,i,n){for(var c=-1,h=i.length,f={};++c<h;){var d=i[c],y=Zt(e,d);n(y,d)&&Xr(f,Lt(d,e),y)}return f}function ad(e){return function(i){return Zt(i,e)}}function gn(e,i,n,c){var h=c?$p:fr,f=-1,d=i.length,y=e;for(e===i&&(i=je(i)),n&&(y=ce(e,Ke(n)));++f<d;)for(var m=0,P=i[f],S=n?n(P):P;(m=h(y,S,m,c))>-1;)y!==e&&Ui.call(y,m,1),Ui.call(e,m,1);return e}function Ga(e,i){for(var n=e?i.length:0,c=n-1;n--;){var h=i[n];if(n==c||h!==f){var f=h;St(h)?Ui.call(e,h,1):wn(e,h)}}return e}function yn(e,i){return e+ki(Ca()*(i-e+1))}function cd(e,i,n,c){for(var h=-1,f=_e(Li((i-e)/(n||1)),0),d=_(f);f--;)d[c?f:++h]=e,e+=n;return d}function vn(e,i){var n="";if(!e||i<1||i>ur)return n;do i%2&&(n+=e),i=ki(i/2),i&&(e+=e);while(i);return n}function B(e,i){return Dn(Sc(e,i,Me),e+"")}function ud(e){return Aa(Sr(e))}function hd(e,i){var n=Sr(e);return ss(n,Yt(i,0,n.length))}function Xr(e,i,n,c){if(!le(e))return e;i=Lt(i,e);for(var h=-1,f=i.length,d=f-1,y=e;y!=null&&++h<f;){var m=vt(i[h]),P=n;if(m==="__proto__"||m==="constructor"||m==="prototype")return e;if(h!=d){var S=y[m];P=c?c(S,m,y):r,P===r&&(P=le(S)?S:St(i[h+1])?[]:{})}Gr(y,m,P),y=y[m]}return e}var Qa=zi?function(e,i){return zi.set(e,i),e}:Me,ld=Mi?function(e,i){return Mi(e,"toString",{configurable:!0,enumerable:!1,value:Vn(i),writable:!0})}:Me;function pd(e){return ss(Sr(e))}function rt(e,i,n){var c=-1,h=e.length;i<0&&(i=-i>h?0:h+i),n=n>h?h:n,n<0&&(n+=h),h=i>n?0:n-i>>>0,i>>>=0;for(var f=_(h);++c<h;)f[c]=e[c+i];return f}function fd(e,i){var n;return Ut(e,function(c,h,f){return n=i(c,h,f),!n}),!!n}function Gi(e,i,n){var c=0,h=e==null?c:e.length;if(typeof i=="number"&&i===i&&h<=dl){for(;c<h;){var f=c+h>>>1,d=e[f];d!==null&&!We(d)&&(n?d<=i:d<i)?c=f+1:h=f}return h}return mn(e,i,Me,n)}function mn(e,i,n,c){var h=0,f=e==null?0:e.length;if(f===0)return 0;i=n(i);for(var d=i!==i,y=i===null,m=We(i),P=i===r;h<f;){var S=ki((h+f)/2),R=n(e[S]),T=R!==r,F=R===null,M=R===R,V=We(R);if(d)var L=c||M;else P?L=M&&(c||T):y?L=M&&T&&(c||!F):m?L=M&&T&&!F&&(c||!V):F||V?L=!1:L=c?R<=i:R<i;L?h=S+1:f=S}return Oe(f,fl)}function Ya(e,i){for(var n=-1,c=e.length,h=0,f=[];++n<c;){var d=e[n],y=i?i(d):d;if(!n||!ht(y,m)){var m=y;f[h++]=d===0?0:d}}return f}function Za(e){return typeof e=="number"?e:We(e)?_i:+e}function Be(e){if(typeof e=="string")return e;if(z(e))return ce(e,Be)+"";if(We(e))return $a?$a.call(e):"";var i=e+"";return i=="0"&&1/e==-1/0?"-0":i}function Mt(e,i,n){var c=-1,h=Ni,f=e.length,d=!0,y=[],m=y;if(n)d=!1,h=Bs;else if(f>=o){var P=i?null:Pd(e);if(P)return $i(P);d=!1,h=Hr,m=new Qt}else m=i?[]:y;e:for(;++c<f;){var S=e[c],R=i?i(S):S;if(S=n||S!==0?S:0,d&&R===R){for(var T=m.length;T--;)if(m[T]===R)continue e;i&&m.push(R),y.push(S)}else h(m,R,n)||(m!==y&&m.push(R),y.push(S))}return y}function wn(e,i){return i=Lt(i,e),e=Oc(e,i),e==null||delete e[vt(it(i))]}function Xa(e,i,n,c){return Xr(e,i,n(Zt(e,i)),c)}function Qi(e,i,n,c){for(var h=e.length,f=c?h:-1;(c?f--:++f<h)&&i(e[f],f,e););return n?rt(e,c?0:f,c?f+1:h):rt(e,c?f+1:0,c?h:f)}function ec(e,i){var n=e;return n instanceof G&&(n=n.value()),Ws(i,function(c,h){return h.func.apply(h.thisArg,Ft([c],h.args))},n)}function _n(e,i,n){var c=e.length;if(c<2)return c?Mt(e[0]):[];for(var h=-1,f=_(c);++h<c;)for(var d=e[h],y=-1;++y<c;)y!=h&&(f[h]=Qr(f[h]||d,e[y],i,n));return Mt(Pe(f,1),i,n)}function tc(e,i,n){for(var c=-1,h=e.length,f=i.length,d={};++c<h;){var y=c<f?i[c]:r;n(d,e[c],y)}return d}function bn(e){return ge(e)?e:[]}function En(e){return typeof e=="function"?e:Me}function Lt(e,i){return z(e)?e:Tn(e,i)?[e]:$c(te(e))}var dd=B;function kt(e,i,n){var c=e.length;return n=n===r?c:n,!i&&n>=c?e:rt(e,i,n)}var rc=ef||function(e){return Ie.clearTimeout(e)};function ic(e,i){if(i)return e.slice();var n=e.length,c=Pa?Pa(n):new e.constructor(n);return e.copy(c),c}function In(e){var i=new e.constructor(e.byteLength);return new ji(i).set(new ji(e)),i}function gd(e,i){var n=i?In(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.byteLength)}function yd(e){var i=new e.constructor(e.source,Lo.exec(e));return i.lastIndex=e.lastIndex,i}function vd(e){return Jr?ie(Jr.call(e)):{}}function sc(e,i){var n=i?In(e.buffer):e.buffer;return new e.constructor(n,e.byteOffset,e.length)}function nc(e,i){if(e!==i){var n=e!==r,c=e===null,h=e===e,f=We(e),d=i!==r,y=i===null,m=i===i,P=We(i);if(!y&&!P&&!f&&e>i||f&&d&&m&&!y&&!P||c&&d&&m||!n&&m||!h)return 1;if(!c&&!f&&!P&&e<i||P&&n&&h&&!c&&!f||y&&n&&h||!d&&h||!m)return-1}return 0}function md(e,i,n){for(var c=-1,h=e.criteria,f=i.criteria,d=h.length,y=n.length;++c<d;){var m=nc(h[c],f[c]);if(m){if(c>=y)return m;var P=n[c];return m*(P=="desc"?-1:1)}}return e.index-i.index}function oc(e,i,n,c){for(var h=-1,f=e.length,d=n.length,y=-1,m=i.length,P=_e(f-d,0),S=_(m+P),R=!c;++y<m;)S[y]=i[y];for(;++h<d;)(R||h<f)&&(S[n[h]]=e[h]);for(;P--;)S[y++]=e[h++];return S}function ac(e,i,n,c){for(var h=-1,f=e.length,d=-1,y=n.length,m=-1,P=i.length,S=_e(f-y,0),R=_(S+P),T=!c;++h<S;)R[h]=e[h];for(var F=h;++m<P;)R[F+m]=i[m];for(;++d<y;)(T||h<f)&&(R[F+n[d]]=e[h++]);return R}function je(e,i){var n=-1,c=e.length;for(i||(i=_(c));++n<c;)i[n]=e[n];return i}function yt(e,i,n,c){var h=!n;n||(n={});for(var f=-1,d=i.length;++f<d;){var y=i[f],m=c?c(n[y],e[y],y,n,e):r;m===r&&(m=e[y]),h?Et(n,y,m):Gr(n,y,m)}return n}function wd(e,i){return yt(e,$n(e),i)}function _d(e,i){return yt(e,_c(e),i)}function Yi(e,i){return function(n,c){var h=z(n)?Pp:zf,f=i?i():{};return h(n,e,U(c,2),f)}}function br(e){return B(function(i,n){var c=-1,h=n.length,f=h>1?n[h-1]:r,d=h>2?n[2]:r;for(f=e.length>3&&typeof f=="function"?(h--,f):r,d&&Te(n[0],n[1],d)&&(f=h<3?r:f,h=1),i=ie(i);++c<h;){var y=n[c];y&&e(i,y,c,f)}return i})}function cc(e,i){return function(n,c){if(n==null)return n;if(!qe(n))return e(n,c);for(var h=n.length,f=i?h:-1,d=ie(n);(i?f--:++f<h)&&c(d[f],f,d)!==!1;);return n}}function uc(e){return function(i,n,c){for(var h=-1,f=ie(i),d=c(i),y=d.length;y--;){var m=d[e?y:++h];if(n(f[m],m,f)===!1)break}return i}}function bd(e,i,n){var c=i&D,h=ei(e);function f(){var d=this&&this!==Ie&&this instanceof f?h:e;return d.apply(c?n:this,arguments)}return f}function hc(e){return function(i){i=te(i);var n=dr(i)?ct(i):r,c=n?n[0]:i.charAt(0),h=n?kt(n,1).join(""):i.slice(1);return c[e]()+h}}function Er(e){return function(i){return Ws(cu(au(i).replace(hp,"")),e,"")}}function ei(e){return function(){var i=arguments;switch(i.length){case 0:return new e;case 1:return new e(i[0]);case 2:return new e(i[0],i[1]);case 3:return new e(i[0],i[1],i[2]);case 4:return new e(i[0],i[1],i[2],i[3]);case 5:return new e(i[0],i[1],i[2],i[3],i[4]);case 6:return new e(i[0],i[1],i[2],i[3],i[4],i[5]);case 7:return new e(i[0],i[1],i[2],i[3],i[4],i[5],i[6])}var n=_r(e.prototype),c=e.apply(n,i);return le(c)?c:n}}function Ed(e,i,n){var c=ei(e);function h(){for(var f=arguments.length,d=_(f),y=f,m=Ir(h);y--;)d[y]=arguments[y];var P=f<3&&d[0]!==m&&d[f-1]!==m?[]:jt(d,m);if(f-=P.length,f<n)return gc(e,i,Zi,h.placeholder,r,d,P,r,r,n-f);var S=this&&this!==Ie&&this instanceof h?c:e;return Ve(S,this,d)}return h}function lc(e){return function(i,n,c){var h=ie(i);if(!qe(i)){var f=U(n,3);i=be(i),n=function(y){return f(h[y],y,h)}}var d=e(i,n,c);return d>-1?h[f?i[d]:d]:r}}function pc(e){return Pt(function(i){var n=i.length,c=n,h=et.prototype.thru;for(e&&i.reverse();c--;){var f=i[c];if(typeof f!="function")throw new Xe(l);if(h&&!d&&rs(f)=="wrapper")var d=new et([],!0)}for(c=d?c:n;++c<n;){f=i[c];var y=rs(f),m=y=="wrapper"?Nn(f):r;m&&An(m[0])&&m[1]==(de|Z|he|Ce)&&!m[4].length&&m[9]==1?d=d[rs(m[0])].apply(d,m[3]):d=f.length==1&&An(f)?d[y]():d.thru(f)}return function(){var P=arguments,S=P[0];if(d&&P.length==1&&z(S))return d.plant(S).value();for(var R=0,T=n?i[R].apply(this,P):S;++R<n;)T=i[R].call(this,T);return T}})}function Zi(e,i,n,c,h,f,d,y,m,P){var S=i&de,R=i&D,T=i&Q,F=i&(Z|ee),M=i&xt,V=T?r:ei(e);function L(){for(var J=arguments.length,Y=_(J),Je=J;Je--;)Y[Je]=arguments[Je];if(F)var Ae=Ir(L),Ge=xp(Y,Ae);if(c&&(Y=oc(Y,c,h,F)),f&&(Y=ac(Y,f,d,F)),J-=Ge,F&&J<P){var ye=jt(Y,Ae);return gc(e,i,Zi,L.placeholder,n,Y,ye,y,m,P-J)}var lt=R?n:this,Nt=T?lt[e]:e;return J=Y.length,y?Y=zd(Y,y):M&&J>1&&Y.reverse(),S&&m<J&&(Y.length=m),this&&this!==Ie&&this instanceof L&&(Nt=V||ei(Nt)),Nt.apply(lt,Y)}return L}function fc(e,i){return function(n,c){return Qf(n,e,i(c),{})}}function Xi(e,i){return function(n,c){var h;if(n===r&&c===r)return i;if(n!==r&&(h=n),c!==r){if(h===r)return c;typeof n=="string"||typeof c=="string"?(n=Be(n),c=Be(c)):(n=Za(n),c=Za(c)),h=e(n,c)}return h}}function Pn(e){return Pt(function(i){return i=ce(i,Ke(U())),B(function(n){var c=this;return e(i,function(h){return Ve(h,c,n)})})})}function es(e,i){i=i===r?" ":Be(i);var n=i.length;if(n<2)return n?vn(i,e):i;var c=vn(i,Li(e/gr(i)));return dr(i)?kt(ct(c),0,e).join(""):c.slice(0,e)}function Id(e,i,n,c){var h=i&D,f=ei(e);function d(){for(var y=-1,m=arguments.length,P=-1,S=c.length,R=_(S+m),T=this&&this!==Ie&&this instanceof d?f:e;++P<S;)R[P]=c[P];for(;m--;)R[P++]=arguments[++y];return Ve(T,h?n:this,R)}return d}function dc(e){return function(i,n,c){return c&&typeof c!="number"&&Te(i,n,c)&&(n=c=r),i=Rt(i),n===r?(n=i,i=0):n=Rt(n),c=c===r?i<n?1:-1:Rt(c),cd(i,n,c,e)}}function ts(e){return function(i,n){return typeof i=="string"&&typeof n=="string"||(i=st(i),n=st(n)),e(i,n)}}function gc(e,i,n,c,h,f,d,y,m,P){var S=i&Z,R=S?d:r,T=S?r:d,F=S?f:r,M=S?r:f;i|=S?he:Fe,i&=~(S?Fe:he),i&fe||(i&=-4);var V=[e,i,h,F,R,M,T,y,m,P],L=n.apply(r,V);return An(e)&&Rc(L,V),L.placeholder=c,Nc(L,e,i)}function Sn(e){var i=we[e];return function(n,c){if(n=st(n),c=c==null?0:Oe(H(c),292),c&&Na(n)){var h=(te(n)+"e").split("e"),f=i(h[0]+"e"+(+h[1]+c));return h=(te(f)+"e").split("e"),+(h[0]+"e"+(+h[1]-c))}return i(n)}}var Pd=mr&&1/$i(new mr([,-0]))[1]==wi?function(e){return new mr(e)}:Wn;function yc(e){return function(i){var n=Re(i);return n==ot?en(i):n==at?Lp(i):Ap(i,e(i))}}function It(e,i,n,c,h,f,d,y){var m=i&Q;if(!m&&typeof e!="function")throw new Xe(l);var P=c?c.length:0;if(P||(i&=-97,c=h=r),d=d===r?d:_e(H(d),0),y=y===r?y:H(y),P-=h?h.length:0,i&Fe){var S=c,R=h;c=h=r}var T=m?r:Nn(e),F=[e,i,n,c,h,S,R,f,d,y];if(T&&Md(F,T),e=F[0],i=F[1],n=F[2],c=F[3],h=F[4],y=F[9]=F[9]===r?m?0:e.length:_e(F[9]-P,0),!y&&i&(Z|ee)&&(i&=-25),!i||i==D)var M=bd(e,i,n);else i==Z||i==ee?M=Ed(e,i,y):(i==he||i==(D|he))&&!h.length?M=Id(e,i,n,c):M=Zi.apply(r,F);var V=T?Qa:Rc;return Nc(V(M,F),e,i)}function vc(e,i,n,c){return e===r||ht(e,vr[n])&&!re.call(c,n)?i:e}function mc(e,i,n,c,h,f){return le(e)&&le(i)&&(f.set(i,e),Ji(e,i,r,mc,f),f.delete(i)),e}function Sd(e){return ii(e)?r:e}function wc(e,i,n,c,h,f){var d=n&x,y=e.length,m=i.length;if(y!=m&&!(d&&m>y))return!1;var P=f.get(e),S=f.get(i);if(P&&S)return P==i&&S==e;var R=-1,T=!0,F=n&K?new Qt:r;for(f.set(e,i),f.set(i,e);++R<y;){var M=e[R],V=i[R];if(c)var L=d?c(V,M,R,i,e,f):c(M,V,R,e,i,f);if(L!==r){if(L)continue;T=!1;break}if(F){if(!Js(i,function(J,Y){if(!Hr(F,Y)&&(M===J||h(M,J,n,c,f)))return F.push(Y)})){T=!1;break}}else if(!(M===V||h(M,V,n,c,f))){T=!1;break}}return f.delete(e),f.delete(i),T}function Od(e,i,n,c,h,f,d){switch(n){case lr:if(e.byteLength!=i.byteLength||e.byteOffset!=i.byteOffset)return!1;e=e.buffer,i=i.buffer;case zr:return!(e.byteLength!=i.byteLength||!f(new ji(e),new ji(i)));case jr:case qr:case Ur:return ht(+e,+i);case Ei:return e.name==i.name&&e.message==i.message;case Mr:case Lr:return e==i+"";case ot:var y=en;case at:var m=c&x;if(y||(y=$i),e.size!=i.size&&!m)return!1;var P=d.get(e);if(P)return P==i;c|=K,d.set(e,i);var S=wc(y(e),y(i),c,h,f,d);return d.delete(e),S;case Pi:if(Jr)return Jr.call(e)==Jr.call(i)}return!1}function Rd(e,i,n,c,h,f){var d=n&x,y=On(e),m=y.length,P=On(i),S=P.length;if(m!=S&&!d)return!1;for(var R=m;R--;){var T=y[R];if(!(d?T in i:re.call(i,T)))return!1}var F=f.get(e),M=f.get(i);if(F&&M)return F==i&&M==e;var V=!0;f.set(e,i),f.set(i,e);for(var L=d;++R<m;){T=y[R];var J=e[T],Y=i[T];if(c)var Je=d?c(Y,J,T,i,e,f):c(J,Y,T,e,i,f);if(!(Je===r?J===Y||h(J,Y,n,c,f):Je)){V=!1;break}L||(L=T=="constructor")}if(V&&!L){var Ae=e.constructor,Ge=i.constructor;Ae!=Ge&&"constructor"in e&&"constructor"in i&&!(typeof Ae=="function"&&Ae instanceof Ae&&typeof Ge=="function"&&Ge instanceof Ge)&&(V=!1)}return f.delete(e),f.delete(i),V}function Pt(e){return Dn(Sc(e,r,Dc),e+"")}function On(e){return Ma(e,be,$n)}function Rn(e){return Ma(e,Ue,_c)}var Nn=zi?function(e){return zi.get(e)}:Wn;function rs(e){for(var i=e.name+"",n=wr[i],c=re.call(wr,i)?n.length:0;c--;){var h=n[c],f=h.func;if(f==null||f==e)return h.name}return i}function Ir(e){var i=re.call(p,"placeholder")?p:e;return i.placeholder}function U(){var e=p.iteratee||Kn;return e=e===Kn?za:e,arguments.length?e(arguments[0],arguments[1]):e}function is(e,i){var n=e.__data__;return Fd(i)?n[typeof i=="string"?"string":"hash"]:n.map}function Cn(e){for(var i=be(e),n=i.length;n--;){var c=i[n],h=e[c];i[n]=[c,h,Ic(h)]}return i}function Xt(e,i){var n=qp(e,i);return ka(n)?n:r}function Nd(e){var i=re.call(e,Jt),n=e[Jt];try{e[Jt]=r;var c=!0}catch{}var h=Di.call(e);return c&&(i?e[Jt]=n:delete e[Jt]),h}var $n=rn?function(e){return e==null?[]:(e=ie(e),Dt(rn(e),function(i){return Oa.call(e,i)}))}:Jn,_c=rn?function(e){for(var i=[];e;)Ft(i,$n(e)),e=qi(e);return i}:Jn,Re=$e;(sn&&Re(new sn(new ArrayBuffer(1)))!=lr||Kr&&Re(new Kr)!=ot||nn&&Re(nn.resolve())!=jo||mr&&Re(new mr)!=at||Br&&Re(new Br)!=kr)&&(Re=function(e){var i=$e(e),n=i==wt?e.constructor:r,c=n?er(n):"";if(c)switch(c){case hf:return lr;case lf:return ot;case pf:return jo;case ff:return at;case df:return kr}return i});function Cd(e,i,n){for(var c=-1,h=n.length;++c<h;){var f=n[c],d=f.size;switch(f.type){case"drop":e+=d;break;case"dropRight":i-=d;break;case"take":i=Oe(i,e+d);break;case"takeRight":e=_e(e,i-d);break}}return{start:e,end:i}}function $d(e){var i=e.match(Fl);return i?i[1].split(jl):[]}function bc(e,i,n){i=Lt(i,e);for(var c=-1,h=i.length,f=!1;++c<h;){var d=vt(i[c]);if(!(f=e!=null&&n(e,d)))break;e=e[d]}return f||++c!=h?f:(h=e==null?0:e.length,!!h&&hs(h)&&St(d,h)&&(z(e)||tr(e)))}function Td(e){var i=e.length,n=new e.constructor(i);return i&&typeof e[0]=="string"&&re.call(e,"index")&&(n.index=e.index,n.input=e.input),n}function Ec(e){return typeof e.constructor=="function"&&!ti(e)?_r(qi(e)):{}}function Ad(e,i,n){var c=e.constructor;switch(i){case zr:return In(e);case jr:case qr:return new c(+e);case lr:return gd(e,n);case Ns:case Cs:case $s:case Ts:case As:case xs:case Ds:case Fs:case js:return sc(e,n);case ot:return new c;case Ur:case Lr:return new c(e);case Mr:return yd(e);case at:return new c;case Pi:return vd(e)}}function xd(e,i){var n=i.length;if(!n)return e;var c=n-1;return i[c]=(n>1?"& ":"")+i[c],i=i.join(n>2?", ":" "),e.replace(Dl,`{
|
|
28
|
+
/* [wrapped with `+i+`] */
|
|
29
|
+
`)}function Dd(e){return z(e)||tr(e)||!!(Ra&&e&&e[Ra])}function St(e,i){var n=typeof e;return i=i??ur,!!i&&(n=="number"||n!="symbol"&&Kl.test(e))&&e>-1&&e%1==0&&e<i}function Te(e,i,n){if(!le(n))return!1;var c=typeof i;return(c=="number"?qe(n)&&St(i,n.length):c=="string"&&i in n)?ht(n[i],e):!1}function Tn(e,i){if(z(e))return!1;var n=typeof e;return n=="number"||n=="symbol"||n=="boolean"||e==null||We(e)?!0:$l.test(e)||!Cl.test(e)||i!=null&&e in ie(i)}function Fd(e){var i=typeof e;return i=="string"||i=="number"||i=="symbol"||i=="boolean"?e!=="__proto__":e===null}function An(e){var i=rs(e),n=p[i];if(typeof n!="function"||!(i in G.prototype))return!1;if(e===n)return!0;var c=Nn(n);return!!c&&e===c[0]}function jd(e){return!!Ia&&Ia in e}var qd=Ai?Ot:Gn;function ti(e){var i=e&&e.constructor,n=typeof i=="function"&&i.prototype||vr;return e===n}function Ic(e){return e===e&&!le(e)}function Pc(e,i){return function(n){return n==null?!1:n[e]===i&&(i!==r||e in ie(n))}}function Ud(e){var i=cs(e,function(c){return n.size===b&&n.clear(),c}),n=i.cache;return i}function Md(e,i){var n=e[1],c=i[1],h=n|c,f=h<(D|Q|de),d=c==de&&n==Z||c==de&&n==Ce&&e[7].length<=i[8]||c==(de|Ce)&&i[7].length<=i[8]&&n==Z;if(!(f||d))return e;c&D&&(e[2]=i[2],h|=n&D?0:fe);var y=i[3];if(y){var m=e[3];e[3]=m?oc(m,y,i[4]):y,e[4]=m?jt(e[3],C):i[4]}return y=i[5],y&&(m=e[5],e[5]=m?ac(m,y,i[6]):y,e[6]=m?jt(e[5],C):i[6]),y=i[7],y&&(e[7]=y),c&de&&(e[8]=e[8]==null?i[8]:Oe(e[8],i[8])),e[9]==null&&(e[9]=i[9]),e[0]=i[0],e[1]=h,e}function Ld(e){var i=[];if(e!=null)for(var n in ie(e))i.push(n);return i}function kd(e){return Di.call(e)}function Sc(e,i,n){return i=_e(i===r?e.length-1:i,0),function(){for(var c=arguments,h=-1,f=_e(c.length-i,0),d=_(f);++h<f;)d[h]=c[i+h];h=-1;for(var y=_(i+1);++h<i;)y[h]=c[h];return y[i]=n(d),Ve(e,this,y)}}function Oc(e,i){return i.length<2?e:Zt(e,rt(i,0,-1))}function zd(e,i){for(var n=e.length,c=Oe(i.length,n),h=je(e);c--;){var f=i[c];e[c]=St(f,n)?h[f]:r}return e}function xn(e,i){if(!(i==="constructor"&&typeof e[i]=="function")&&i!="__proto__")return e[i]}var Rc=Cc(Qa),ri=rf||function(e,i){return Ie.setTimeout(e,i)},Dn=Cc(ld);function Nc(e,i,n){var c=i+"";return Dn(e,xd(c,Hd($d(c),n)))}function Cc(e){var i=0,n=0;return function(){var c=af(),h=ul-(c-n);if(n=c,h>0){if(++i>=cl)return arguments[0]}else i=0;return e.apply(r,arguments)}}function ss(e,i){var n=-1,c=e.length,h=c-1;for(i=i===r?c:i;++n<i;){var f=yn(n,h),d=e[f];e[f]=e[n],e[n]=d}return e.length=i,e}var $c=Ud(function(e){var i=[];return e.charCodeAt(0)===46&&i.push(""),e.replace(Tl,function(n,c,h,f){i.push(h?f.replace(Ml,"$1"):c||n)}),i});function vt(e){if(typeof e=="string"||We(e))return e;var i=e+"";return i=="0"&&1/e==-1/0?"-0":i}function er(e){if(e!=null){try{return xi.call(e)}catch{}try{return e+""}catch{}}return""}function Hd(e,i){return Ze(gl,function(n){var c="_."+n[0];i&n[1]&&!Ni(e,c)&&e.push(c)}),e.sort()}function Tc(e){if(e instanceof G)return e.clone();var i=new et(e.__wrapped__,e.__chain__);return i.__actions__=je(e.__actions__),i.__index__=e.__index__,i.__values__=e.__values__,i}function Vd(e,i,n){(n?Te(e,i,n):i===r)?i=1:i=_e(H(i),0);var c=e==null?0:e.length;if(!c||i<1)return[];for(var h=0,f=0,d=_(Li(c/i));h<c;)d[f++]=rt(e,h,h+=i);return d}function Kd(e){for(var i=-1,n=e==null?0:e.length,c=0,h=[];++i<n;){var f=e[i];f&&(h[c++]=f)}return h}function Bd(){var e=arguments.length;if(!e)return[];for(var i=_(e-1),n=arguments[0],c=e;c--;)i[c-1]=arguments[c];return Ft(z(n)?je(n):[n],Pe(i,1))}var Wd=B(function(e,i){return ge(e)?Qr(e,Pe(i,1,ge,!0)):[]}),Jd=B(function(e,i){var n=it(i);return ge(n)&&(n=r),ge(e)?Qr(e,Pe(i,1,ge,!0),U(n,2)):[]}),Gd=B(function(e,i){var n=it(i);return ge(n)&&(n=r),ge(e)?Qr(e,Pe(i,1,ge,!0),r,n):[]});function Qd(e,i,n){var c=e==null?0:e.length;return c?(i=n||i===r?1:H(i),rt(e,i<0?0:i,c)):[]}function Yd(e,i,n){var c=e==null?0:e.length;return c?(i=n||i===r?1:H(i),i=c-i,rt(e,0,i<0?0:i)):[]}function Zd(e,i){return e&&e.length?Qi(e,U(i,3),!0,!0):[]}function Xd(e,i){return e&&e.length?Qi(e,U(i,3),!0):[]}function eg(e,i,n,c){var h=e==null?0:e.length;return h?(n&&typeof n!="number"&&Te(e,i,n)&&(n=0,c=h),Bf(e,i,n,c)):[]}function Ac(e,i,n){var c=e==null?0:e.length;if(!c)return-1;var h=n==null?0:H(n);return h<0&&(h=_e(c+h,0)),Ci(e,U(i,3),h)}function xc(e,i,n){var c=e==null?0:e.length;if(!c)return-1;var h=c-1;return n!==r&&(h=H(n),h=n<0?_e(c+h,0):Oe(h,c-1)),Ci(e,U(i,3),h,!0)}function Dc(e){var i=e==null?0:e.length;return i?Pe(e,1):[]}function tg(e){var i=e==null?0:e.length;return i?Pe(e,wi):[]}function rg(e,i){var n=e==null?0:e.length;return n?(i=i===r?1:H(i),Pe(e,i)):[]}function ig(e){for(var i=-1,n=e==null?0:e.length,c={};++i<n;){var h=e[i];c[h[0]]=h[1]}return c}function Fc(e){return e&&e.length?e[0]:r}function sg(e,i,n){var c=e==null?0:e.length;if(!c)return-1;var h=n==null?0:H(n);return h<0&&(h=_e(c+h,0)),fr(e,i,h)}function ng(e){var i=e==null?0:e.length;return i?rt(e,0,-1):[]}var og=B(function(e){var i=ce(e,bn);return i.length&&i[0]===e[0]?ln(i):[]}),ag=B(function(e){var i=it(e),n=ce(e,bn);return i===it(n)?i=r:n.pop(),n.length&&n[0]===e[0]?ln(n,U(i,2)):[]}),cg=B(function(e){var i=it(e),n=ce(e,bn);return i=typeof i=="function"?i:r,i&&n.pop(),n.length&&n[0]===e[0]?ln(n,r,i):[]});function ug(e,i){return e==null?"":nf.call(e,i)}function it(e){var i=e==null?0:e.length;return i?e[i-1]:r}function hg(e,i,n){var c=e==null?0:e.length;if(!c)return-1;var h=c;return n!==r&&(h=H(n),h=h<0?_e(c+h,0):Oe(h,c-1)),i===i?zp(e,i,h):Ci(e,ga,h,!0)}function lg(e,i){return e&&e.length?Ba(e,H(i)):r}var pg=B(jc);function jc(e,i){return e&&e.length&&i&&i.length?gn(e,i):e}function fg(e,i,n){return e&&e.length&&i&&i.length?gn(e,i,U(n,2)):e}function dg(e,i,n){return e&&e.length&&i&&i.length?gn(e,i,r,n):e}var gg=Pt(function(e,i){var n=e==null?0:e.length,c=an(e,i);return Ga(e,ce(i,function(h){return St(h,n)?+h:h}).sort(nc)),c});function yg(e,i){var n=[];if(!(e&&e.length))return n;var c=-1,h=[],f=e.length;for(i=U(i,3);++c<f;){var d=e[c];i(d,c,e)&&(n.push(d),h.push(c))}return Ga(e,h),n}function Fn(e){return e==null?e:uf.call(e)}function vg(e,i,n){var c=e==null?0:e.length;return c?(n&&typeof n!="number"&&Te(e,i,n)?(i=0,n=c):(i=i==null?0:H(i),n=n===r?c:H(n)),rt(e,i,n)):[]}function mg(e,i){return Gi(e,i)}function wg(e,i,n){return mn(e,i,U(n,2))}function _g(e,i){var n=e==null?0:e.length;if(n){var c=Gi(e,i);if(c<n&&ht(e[c],i))return c}return-1}function bg(e,i){return Gi(e,i,!0)}function Eg(e,i,n){return mn(e,i,U(n,2),!0)}function Ig(e,i){var n=e==null?0:e.length;if(n){var c=Gi(e,i,!0)-1;if(ht(e[c],i))return c}return-1}function Pg(e){return e&&e.length?Ya(e):[]}function Sg(e,i){return e&&e.length?Ya(e,U(i,2)):[]}function Og(e){var i=e==null?0:e.length;return i?rt(e,1,i):[]}function Rg(e,i,n){return e&&e.length?(i=n||i===r?1:H(i),rt(e,0,i<0?0:i)):[]}function Ng(e,i,n){var c=e==null?0:e.length;return c?(i=n||i===r?1:H(i),i=c-i,rt(e,i<0?0:i,c)):[]}function Cg(e,i){return e&&e.length?Qi(e,U(i,3),!1,!0):[]}function $g(e,i){return e&&e.length?Qi(e,U(i,3)):[]}var Tg=B(function(e){return Mt(Pe(e,1,ge,!0))}),Ag=B(function(e){var i=it(e);return ge(i)&&(i=r),Mt(Pe(e,1,ge,!0),U(i,2))}),xg=B(function(e){var i=it(e);return i=typeof i=="function"?i:r,Mt(Pe(e,1,ge,!0),r,i)});function Dg(e){return e&&e.length?Mt(e):[]}function Fg(e,i){return e&&e.length?Mt(e,U(i,2)):[]}function jg(e,i){return i=typeof i=="function"?i:r,e&&e.length?Mt(e,r,i):[]}function jn(e){if(!(e&&e.length))return[];var i=0;return e=Dt(e,function(n){if(ge(n))return i=_e(n.length,i),!0}),Zs(i,function(n){return ce(e,Gs(n))})}function qc(e,i){if(!(e&&e.length))return[];var n=jn(e);return i==null?n:ce(n,function(c){return Ve(i,r,c)})}var qg=B(function(e,i){return ge(e)?Qr(e,i):[]}),Ug=B(function(e){return _n(Dt(e,ge))}),Mg=B(function(e){var i=it(e);return ge(i)&&(i=r),_n(Dt(e,ge),U(i,2))}),Lg=B(function(e){var i=it(e);return i=typeof i=="function"?i:r,_n(Dt(e,ge),r,i)}),kg=B(jn);function zg(e,i){return tc(e||[],i||[],Gr)}function Hg(e,i){return tc(e||[],i||[],Xr)}var Vg=B(function(e){var i=e.length,n=i>1?e[i-1]:r;return n=typeof n=="function"?(e.pop(),n):r,qc(e,n)});function Uc(e){var i=p(e);return i.__chain__=!0,i}function Kg(e,i){return i(e),e}function ns(e,i){return i(e)}var Bg=Pt(function(e){var i=e.length,n=i?e[0]:0,c=this.__wrapped__,h=function(f){return an(f,e)};return i>1||this.__actions__.length||!(c instanceof G)||!St(n)?this.thru(h):(c=c.slice(n,+n+(i?1:0)),c.__actions__.push({func:ns,args:[h],thisArg:r}),new et(c,this.__chain__).thru(function(f){return i&&!f.length&&f.push(r),f}))});function Wg(){return Uc(this)}function Jg(){return new et(this.value(),this.__chain__)}function Gg(){this.__values__===r&&(this.__values__=Zc(this.value()));var e=this.__index__>=this.__values__.length,i=e?r:this.__values__[this.__index__++];return{done:e,value:i}}function Qg(){return this}function Yg(e){for(var i,n=this;n instanceof Vi;){var c=Tc(n);c.__index__=0,c.__values__=r,i?h.__wrapped__=c:i=c;var h=c;n=n.__wrapped__}return h.__wrapped__=e,i}function Zg(){var e=this.__wrapped__;if(e instanceof G){var i=e;return this.__actions__.length&&(i=new G(this)),i=i.reverse(),i.__actions__.push({func:ns,args:[Fn],thisArg:r}),new et(i,this.__chain__)}return this.thru(Fn)}function Xg(){return ec(this.__wrapped__,this.__actions__)}var ey=Yi(function(e,i,n){re.call(e,n)?++e[n]:Et(e,n,1)});function ty(e,i,n){var c=z(e)?fa:Kf;return n&&Te(e,i,n)&&(i=r),c(e,U(i,3))}function ry(e,i){var n=z(e)?Dt:qa;return n(e,U(i,3))}var iy=lc(Ac),sy=lc(xc);function ny(e,i){return Pe(os(e,i),1)}function oy(e,i){return Pe(os(e,i),wi)}function ay(e,i,n){return n=n===r?1:H(n),Pe(os(e,i),n)}function Mc(e,i){var n=z(e)?Ze:Ut;return n(e,U(i,3))}function Lc(e,i){var n=z(e)?Sp:ja;return n(e,U(i,3))}var cy=Yi(function(e,i,n){re.call(e,n)?e[n].push(i):Et(e,n,[i])});function uy(e,i,n,c){e=qe(e)?e:Sr(e),n=n&&!c?H(n):0;var h=e.length;return n<0&&(n=_e(h+n,0)),ls(e)?n<=h&&e.indexOf(i,n)>-1:!!h&&fr(e,i,n)>-1}var hy=B(function(e,i,n){var c=-1,h=typeof i=="function",f=qe(e)?_(e.length):[];return Ut(e,function(d){f[++c]=h?Ve(i,d,n):Yr(d,i,n)}),f}),ly=Yi(function(e,i,n){Et(e,n,i)});function os(e,i){var n=z(e)?ce:Ha;return n(e,U(i,3))}function py(e,i,n,c){return e==null?[]:(z(i)||(i=i==null?[]:[i]),n=c?r:n,z(n)||(n=n==null?[]:[n]),Wa(e,i,n))}var fy=Yi(function(e,i,n){e[n?0:1].push(i)},function(){return[[],[]]});function dy(e,i,n){var c=z(e)?Ws:va,h=arguments.length<3;return c(e,U(i,4),n,h,Ut)}function gy(e,i,n){var c=z(e)?Op:va,h=arguments.length<3;return c(e,U(i,4),n,h,ja)}function yy(e,i){var n=z(e)?Dt:qa;return n(e,us(U(i,3)))}function vy(e){var i=z(e)?Aa:ud;return i(e)}function my(e,i,n){(n?Te(e,i,n):i===r)?i=1:i=H(i);var c=z(e)?Lf:hd;return c(e,i)}function wy(e){var i=z(e)?kf:pd;return i(e)}function _y(e){if(e==null)return 0;if(qe(e))return ls(e)?gr(e):e.length;var i=Re(e);return i==ot||i==at?e.size:fn(e).length}function by(e,i,n){var c=z(e)?Js:fd;return n&&Te(e,i,n)&&(i=r),c(e,U(i,3))}var Ey=B(function(e,i){if(e==null)return[];var n=i.length;return n>1&&Te(e,i[0],i[1])?i=[]:n>2&&Te(i[0],i[1],i[2])&&(i=[i[0]]),Wa(e,Pe(i,1),[])}),as=tf||function(){return Ie.Date.now()};function Iy(e,i){if(typeof i!="function")throw new Xe(l);return e=H(e),function(){if(--e<1)return i.apply(this,arguments)}}function kc(e,i,n){return i=n?r:i,i=e&&i==null?e.length:i,It(e,de,r,r,r,r,i)}function zc(e,i){var n;if(typeof i!="function")throw new Xe(l);return e=H(e),function(){return--e>0&&(n=i.apply(this,arguments)),e<=1&&(i=r),n}}var qn=B(function(e,i,n){var c=D;if(n.length){var h=jt(n,Ir(qn));c|=he}return It(e,c,i,n,h)}),Hc=B(function(e,i,n){var c=D|Q;if(n.length){var h=jt(n,Ir(Hc));c|=he}return It(i,c,e,n,h)});function Vc(e,i,n){i=n?r:i;var c=It(e,Z,r,r,r,r,r,i);return c.placeholder=Vc.placeholder,c}function Kc(e,i,n){i=n?r:i;var c=It(e,ee,r,r,r,r,r,i);return c.placeholder=Kc.placeholder,c}function Bc(e,i,n){var c,h,f,d,y,m,P=0,S=!1,R=!1,T=!0;if(typeof e!="function")throw new Xe(l);i=st(i)||0,le(n)&&(S=!!n.leading,R="maxWait"in n,f=R?_e(st(n.maxWait)||0,i):f,T="trailing"in n?!!n.trailing:T);function F(ye){var lt=c,Nt=h;return c=h=r,P=ye,d=e.apply(Nt,lt),d}function M(ye){return P=ye,y=ri(J,i),S?F(ye):d}function V(ye){var lt=ye-m,Nt=ye-P,lu=i-lt;return R?Oe(lu,f-Nt):lu}function L(ye){var lt=ye-m,Nt=ye-P;return m===r||lt>=i||lt<0||R&&Nt>=f}function J(){var ye=as();if(L(ye))return Y(ye);y=ri(J,V(ye))}function Y(ye){return y=r,T&&c?F(ye):(c=h=r,d)}function Je(){y!==r&&rc(y),P=0,c=m=h=y=r}function Ae(){return y===r?d:Y(as())}function Ge(){var ye=as(),lt=L(ye);if(c=arguments,h=this,m=ye,lt){if(y===r)return M(m);if(R)return rc(y),y=ri(J,i),F(m)}return y===r&&(y=ri(J,i)),d}return Ge.cancel=Je,Ge.flush=Ae,Ge}var Py=B(function(e,i){return Fa(e,1,i)}),Sy=B(function(e,i,n){return Fa(e,st(i)||0,n)});function Oy(e){return It(e,xt)}function cs(e,i){if(typeof e!="function"||i!=null&&typeof i!="function")throw new Xe(l);var n=function(){var c=arguments,h=i?i.apply(this,c):c[0],f=n.cache;if(f.has(h))return f.get(h);var d=e.apply(this,c);return n.cache=f.set(h,d)||f,d};return n.cache=new(cs.Cache||bt),n}cs.Cache=bt;function us(e){if(typeof e!="function")throw new Xe(l);return function(){var i=arguments;switch(i.length){case 0:return!e.call(this);case 1:return!e.call(this,i[0]);case 2:return!e.call(this,i[0],i[1]);case 3:return!e.call(this,i[0],i[1],i[2])}return!e.apply(this,i)}}function Ry(e){return zc(2,e)}var Ny=dd(function(e,i){i=i.length==1&&z(i[0])?ce(i[0],Ke(U())):ce(Pe(i,1),Ke(U()));var n=i.length;return B(function(c){for(var h=-1,f=Oe(c.length,n);++h<f;)c[h]=i[h].call(this,c[h]);return Ve(e,this,c)})}),Un=B(function(e,i){var n=jt(i,Ir(Un));return It(e,he,r,i,n)}),Wc=B(function(e,i){var n=jt(i,Ir(Wc));return It(e,Fe,r,i,n)}),Cy=Pt(function(e,i){return It(e,Ce,r,r,r,i)});function $y(e,i){if(typeof e!="function")throw new Xe(l);return i=i===r?i:H(i),B(e,i)}function Ty(e,i){if(typeof e!="function")throw new Xe(l);return i=i==null?0:_e(H(i),0),B(function(n){var c=n[i],h=kt(n,0,i);return c&&Ft(h,c),Ve(e,this,h)})}function Ay(e,i,n){var c=!0,h=!0;if(typeof e!="function")throw new Xe(l);return le(n)&&(c="leading"in n?!!n.leading:c,h="trailing"in n?!!n.trailing:h),Bc(e,i,{leading:c,maxWait:i,trailing:h})}function xy(e){return kc(e,1)}function Dy(e,i){return Un(En(i),e)}function Fy(){if(!arguments.length)return[];var e=arguments[0];return z(e)?e:[e]}function jy(e){return tt(e,q)}function qy(e,i){return i=typeof i=="function"?i:r,tt(e,q,i)}function Uy(e){return tt(e,O|q)}function My(e,i){return i=typeof i=="function"?i:r,tt(e,O|q,i)}function Ly(e,i){return i==null||Da(e,i,be(i))}function ht(e,i){return e===i||e!==e&&i!==i}var ky=ts(hn),zy=ts(function(e,i){return e>=i}),tr=La(function(){return arguments}())?La:function(e){return pe(e)&&re.call(e,"callee")&&!Oa.call(e,"callee")},z=_.isArray,Hy=aa?Ke(aa):Yf;function qe(e){return e!=null&&hs(e.length)&&!Ot(e)}function ge(e){return pe(e)&&qe(e)}function Vy(e){return e===!0||e===!1||pe(e)&&$e(e)==jr}var zt=sf||Gn,Ky=ca?Ke(ca):Zf;function By(e){return pe(e)&&e.nodeType===1&&!ii(e)}function Wy(e){if(e==null)return!0;if(qe(e)&&(z(e)||typeof e=="string"||typeof e.splice=="function"||zt(e)||Pr(e)||tr(e)))return!e.length;var i=Re(e);if(i==ot||i==at)return!e.size;if(ti(e))return!fn(e).length;for(var n in e)if(re.call(e,n))return!1;return!0}function Jy(e,i){return Zr(e,i)}function Gy(e,i,n){n=typeof n=="function"?n:r;var c=n?n(e,i):r;return c===r?Zr(e,i,r,n):!!c}function Mn(e){if(!pe(e))return!1;var i=$e(e);return i==Ei||i==vl||typeof e.message=="string"&&typeof e.name=="string"&&!ii(e)}function Qy(e){return typeof e=="number"&&Na(e)}function Ot(e){if(!le(e))return!1;var i=$e(e);return i==Ii||i==Fo||i==yl||i==wl}function Jc(e){return typeof e=="number"&&e==H(e)}function hs(e){return typeof e=="number"&&e>-1&&e%1==0&&e<=ur}function le(e){var i=typeof e;return e!=null&&(i=="object"||i=="function")}function pe(e){return e!=null&&typeof e=="object"}var Gc=ua?Ke(ua):ed;function Yy(e,i){return e===i||pn(e,i,Cn(i))}function Zy(e,i,n){return n=typeof n=="function"?n:r,pn(e,i,Cn(i),n)}function Xy(e){return Qc(e)&&e!=+e}function ev(e){if(qd(e))throw new k(u);return ka(e)}function tv(e){return e===null}function rv(e){return e==null}function Qc(e){return typeof e=="number"||pe(e)&&$e(e)==Ur}function ii(e){if(!pe(e)||$e(e)!=wt)return!1;var i=qi(e);if(i===null)return!0;var n=re.call(i,"constructor")&&i.constructor;return typeof n=="function"&&n instanceof n&&xi.call(n)==Yp}var Ln=ha?Ke(ha):td;function iv(e){return Jc(e)&&e>=-9007199254740991&&e<=ur}var Yc=la?Ke(la):rd;function ls(e){return typeof e=="string"||!z(e)&&pe(e)&&$e(e)==Lr}function We(e){return typeof e=="symbol"||pe(e)&&$e(e)==Pi}var Pr=pa?Ke(pa):id;function sv(e){return e===r}function nv(e){return pe(e)&&Re(e)==kr}function ov(e){return pe(e)&&$e(e)==bl}var av=ts(dn),cv=ts(function(e,i){return e<=i});function Zc(e){if(!e)return[];if(qe(e))return ls(e)?ct(e):je(e);if(Vr&&e[Vr])return Mp(e[Vr]());var i=Re(e),n=i==ot?en:i==at?$i:Sr;return n(e)}function Rt(e){if(!e)return e===0?e:0;if(e=st(e),e===wi||e===-1/0){var i=e<0?-1:1;return i*pl}return e===e?e:0}function H(e){var i=Rt(e),n=i%1;return i===i?n?i-n:i:0}function Xc(e){return e?Yt(H(e),0,dt):0}function st(e){if(typeof e=="number")return e;if(We(e))return _i;if(le(e)){var i=typeof e.valueOf=="function"?e.valueOf():e;e=le(i)?i+"":i}if(typeof e!="string")return e===0?e:+e;e=ma(e);var n=zl.test(e);return n||Vl.test(e)?Ep(e.slice(2),n?2:8):kl.test(e)?_i:+e}function eu(e){return yt(e,Ue(e))}function uv(e){return e?Yt(H(e),-9007199254740991,ur):e===0?e:0}function te(e){return e==null?"":Be(e)}var hv=br(function(e,i){if(ti(i)||qe(i)){yt(i,be(i),e);return}for(var n in i)re.call(i,n)&&Gr(e,n,i[n])}),tu=br(function(e,i){yt(i,Ue(i),e)}),ps=br(function(e,i,n,c){yt(i,Ue(i),e,c)}),lv=br(function(e,i,n,c){yt(i,be(i),e,c)}),pv=Pt(an);function fv(e,i){var n=_r(e);return i==null?n:xa(n,i)}var dv=B(function(e,i){e=ie(e);var n=-1,c=i.length,h=c>2?i[2]:r;for(h&&Te(i[0],i[1],h)&&(c=1);++n<c;)for(var f=i[n],d=Ue(f),y=-1,m=d.length;++y<m;){var P=d[y],S=e[P];(S===r||ht(S,vr[P])&&!re.call(e,P))&&(e[P]=f[P])}return e}),gv=B(function(e){return e.push(r,mc),Ve(ru,r,e)});function yv(e,i){return da(e,U(i,3),gt)}function vv(e,i){return da(e,U(i,3),un)}function mv(e,i){return e==null?e:cn(e,U(i,3),Ue)}function wv(e,i){return e==null?e:Ua(e,U(i,3),Ue)}function _v(e,i){return e&>(e,U(i,3))}function bv(e,i){return e&&un(e,U(i,3))}function Ev(e){return e==null?[]:Wi(e,be(e))}function Iv(e){return e==null?[]:Wi(e,Ue(e))}function kn(e,i,n){var c=e==null?r:Zt(e,i);return c===r?n:c}function Pv(e,i){return e!=null&&bc(e,i,Wf)}function zn(e,i){return e!=null&&bc(e,i,Jf)}var Sv=fc(function(e,i,n){i!=null&&typeof i.toString!="function"&&(i=Di.call(i)),e[i]=n},Vn(Me)),Ov=fc(function(e,i,n){i!=null&&typeof i.toString!="function"&&(i=Di.call(i)),re.call(e,i)?e[i].push(n):e[i]=[n]},U),Rv=B(Yr);function be(e){return qe(e)?Ta(e):fn(e)}function Ue(e){return qe(e)?Ta(e,!0):sd(e)}function Nv(e,i){var n={};return i=U(i,3),gt(e,function(c,h,f){Et(n,i(c,h,f),c)}),n}function Cv(e,i){var n={};return i=U(i,3),gt(e,function(c,h,f){Et(n,h,i(c,h,f))}),n}var $v=br(function(e,i,n){Ji(e,i,n)}),ru=br(function(e,i,n,c){Ji(e,i,n,c)}),Tv=Pt(function(e,i){var n={};if(e==null)return n;var c=!1;i=ce(i,function(f){return f=Lt(f,e),c||(c=f.length>1),f}),yt(e,Rn(e),n),c&&(n=tt(n,O|N|q,Sd));for(var h=i.length;h--;)wn(n,i[h]);return n});function Av(e,i){return iu(e,us(U(i)))}var xv=Pt(function(e,i){return e==null?{}:od(e,i)});function iu(e,i){if(e==null)return{};var n=ce(Rn(e),function(c){return[c]});return i=U(i),Ja(e,n,function(c,h){return i(c,h[0])})}function Dv(e,i,n){i=Lt(i,e);var c=-1,h=i.length;for(h||(h=1,e=r);++c<h;){var f=e==null?r:e[vt(i[c])];f===r&&(c=h,f=n),e=Ot(f)?f.call(e):f}return e}function Fv(e,i,n){return e==null?e:Xr(e,i,n)}function jv(e,i,n,c){return c=typeof c=="function"?c:r,e==null?e:Xr(e,i,n,c)}var su=yc(be),nu=yc(Ue);function qv(e,i,n){var c=z(e),h=c||zt(e)||Pr(e);if(i=U(i,4),n==null){var f=e&&e.constructor;h?n=c?new f:[]:le(e)?n=Ot(f)?_r(qi(e)):{}:n={}}return(h?Ze:gt)(e,function(d,y,m){return i(n,d,y,m)}),n}function Uv(e,i){return e==null?!0:wn(e,i)}function Mv(e,i,n){return e==null?e:Xa(e,i,En(n))}function Lv(e,i,n,c){return c=typeof c=="function"?c:r,e==null?e:Xa(e,i,En(n),c)}function Sr(e){return e==null?[]:Xs(e,be(e))}function kv(e){return e==null?[]:Xs(e,Ue(e))}function zv(e,i,n){return n===r&&(n=i,i=r),n!==r&&(n=st(n),n=n===n?n:0),i!==r&&(i=st(i),i=i===i?i:0),Yt(st(e),i,n)}function Hv(e,i,n){return i=Rt(i),n===r?(n=i,i=0):n=Rt(n),e=st(e),Gf(e,i,n)}function Vv(e,i,n){if(n&&typeof n!="boolean"&&Te(e,i,n)&&(i=n=r),n===r&&(typeof i=="boolean"?(n=i,i=r):typeof e=="boolean"&&(n=e,e=r)),e===r&&i===r?(e=0,i=1):(e=Rt(e),i===r?(i=e,e=0):i=Rt(i)),e>i){var c=e;e=i,i=c}if(n||e%1||i%1){var h=Ca();return Oe(e+h*(i-e+bp("1e-"+((h+"").length-1))),i)}return yn(e,i)}var Kv=Er(function(e,i,n){return i=i.toLowerCase(),e+(n?ou(i):i)});function ou(e){return Hn(te(e).toLowerCase())}function au(e){return e=te(e),e&&e.replace(Bl,Dp).replace(lp,"")}function Bv(e,i,n){e=te(e),i=Be(i);var c=e.length;n=n===r?c:Yt(H(n),0,c);var h=n;return n-=i.length,n>=0&&e.slice(n,h)==i}function Wv(e){return e=te(e),e&&Ol.test(e)?e.replace(Uo,Fp):e}function Jv(e){return e=te(e),e&&Al.test(e)?e.replace(qs,"\\$&"):e}var Gv=Er(function(e,i,n){return e+(n?"-":"")+i.toLowerCase()}),Qv=Er(function(e,i,n){return e+(n?" ":"")+i.toLowerCase()}),Yv=hc("toLowerCase");function Zv(e,i,n){e=te(e),i=H(i);var c=i?gr(e):0;if(!i||c>=i)return e;var h=(i-c)/2;return es(ki(h),n)+e+es(Li(h),n)}function Xv(e,i,n){e=te(e),i=H(i);var c=i?gr(e):0;return i&&c<i?e+es(i-c,n):e}function em(e,i,n){e=te(e),i=H(i);var c=i?gr(e):0;return i&&c<i?es(i-c,n)+e:e}function tm(e,i,n){return n||i==null?i=0:i&&(i=+i),cf(te(e).replace(Us,""),i||0)}function rm(e,i,n){return(n?Te(e,i,n):i===r)?i=1:i=H(i),vn(te(e),i)}function im(){var e=arguments,i=te(e[0]);return e.length<3?i:i.replace(e[1],e[2])}var sm=Er(function(e,i,n){return e+(n?"_":"")+i.toLowerCase()});function nm(e,i,n){return n&&typeof n!="number"&&Te(e,i,n)&&(i=n=r),n=n===r?dt:n>>>0,n?(e=te(e),e&&(typeof i=="string"||i!=null&&!Ln(i))&&(i=Be(i),!i&&dr(e))?kt(ct(e),0,n):e.split(i,n)):[]}var om=Er(function(e,i,n){return e+(n?" ":"")+Hn(i)});function am(e,i,n){return e=te(e),n=n==null?0:Yt(H(n),0,e.length),i=Be(i),e.slice(n,n+i.length)==i}function cm(e,i,n){var c=p.templateSettings;n&&Te(e,i,n)&&(i=r),e=te(e),i=ps({},i,c,vc);var h=ps({},i.imports,c.imports,vc),f=be(h),d=Xs(h,f),y,m,P=0,S=i.interpolate||Si,R="__p += '",T=tn((i.escape||Si).source+"|"+S.source+"|"+(S===Mo?Ll:Si).source+"|"+(i.evaluate||Si).source+"|$","g"),F="//# sourceURL="+(re.call(i,"sourceURL")?(i.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++yp+"]")+`
|
|
30
|
+
`;e.replace(T,function(L,J,Y,Je,Ae,Ge){return Y||(Y=Je),R+=e.slice(P,Ge).replace(Wl,jp),J&&(y=!0,R+=`' +
|
|
31
|
+
__e(`+J+`) +
|
|
32
|
+
'`),Ae&&(m=!0,R+=`';
|
|
33
|
+
`+Ae+`;
|
|
34
|
+
__p += '`),Y&&(R+=`' +
|
|
35
|
+
((__t = (`+Y+`)) == null ? '' : __t) +
|
|
36
|
+
'`),P=Ge+L.length,L}),R+=`';
|
|
37
|
+
`;var M=re.call(i,"variable")&&i.variable;if(!M)R=`with (obj) {
|
|
38
|
+
`+R+`
|
|
39
|
+
}
|
|
40
|
+
`;else if(Ul.test(M))throw new k(g);R=(m?R.replace(El,""):R).replace(Il,"$1").replace(Pl,"$1;"),R="function("+(M||"obj")+`) {
|
|
41
|
+
`+(M?"":`obj || (obj = {});
|
|
42
|
+
`)+"var __t, __p = ''"+(y?", __e = _.escape":"")+(m?`, __j = Array.prototype.join;
|
|
43
|
+
function print() { __p += __j.call(arguments, '') }
|
|
44
|
+
`:`;
|
|
45
|
+
`)+R+`return __p
|
|
46
|
+
}`;var V=uu(function(){return X(f,F+"return "+R).apply(r,d)});if(V.source=R,Mn(V))throw V;return V}function um(e){return te(e).toLowerCase()}function hm(e){return te(e).toUpperCase()}function lm(e,i,n){if(e=te(e),e&&(n||i===r))return ma(e);if(!e||!(i=Be(i)))return e;var c=ct(e),h=ct(i),f=wa(c,h),d=_a(c,h)+1;return kt(c,f,d).join("")}function pm(e,i,n){if(e=te(e),e&&(n||i===r))return e.slice(0,Ea(e)+1);if(!e||!(i=Be(i)))return e;var c=ct(e),h=_a(c,ct(i))+1;return kt(c,0,h).join("")}function fm(e,i,n){if(e=te(e),e&&(n||i===r))return e.replace(Us,"");if(!e||!(i=Be(i)))return e;var c=ct(e),h=wa(c,ct(i));return kt(c,h).join("")}function dm(e,i){var n=ol,c=al;if(le(i)){var h="separator"in i?i.separator:h;n="length"in i?H(i.length):n,c="omission"in i?Be(i.omission):c}e=te(e);var f=e.length;if(dr(e)){var d=ct(e);f=d.length}if(n>=f)return e;var y=n-gr(c);if(y<1)return c;var m=d?kt(d,0,y).join(""):e.slice(0,y);if(h===r)return m+c;if(d&&(y+=m.length-y),Ln(h)){if(e.slice(y).search(h)){var P,S=m;for(h.global||(h=tn(h.source,te(Lo.exec(h))+"g")),h.lastIndex=0;P=h.exec(S);)var R=P.index;m=m.slice(0,R===r?y:R)}}else if(e.indexOf(Be(h),y)!=y){var T=m.lastIndexOf(h);T>-1&&(m=m.slice(0,T))}return m+c}function gm(e){return e=te(e),e&&Sl.test(e)?e.replace(qo,Hp):e}var ym=Er(function(e,i,n){return e+(n?" ":"")+i.toUpperCase()}),Hn=hc("toUpperCase");function cu(e,i,n){return e=te(e),i=n?r:i,i===r?Up(e)?Bp(e):Cp(e):e.match(i)||[]}var uu=B(function(e,i){try{return Ve(e,r,i)}catch(n){return Mn(n)?n:new k(n)}}),vm=Pt(function(e,i){return Ze(i,function(n){n=vt(n),Et(e,n,qn(e[n],e))}),e});function mm(e){var i=e==null?0:e.length,n=U();return e=i?ce(e,function(c){if(typeof c[1]!="function")throw new Xe(l);return[n(c[0]),c[1]]}):[],B(function(c){for(var h=-1;++h<i;){var f=e[h];if(Ve(f[0],this,c))return Ve(f[1],this,c)}})}function wm(e){return Vf(tt(e,O))}function Vn(e){return function(){return e}}function _m(e,i){return e==null||e!==e?i:e}var bm=pc(),Em=pc(!0);function Me(e){return e}function Kn(e){return za(typeof e=="function"?e:tt(e,O))}function Im(e){return Va(tt(e,O))}function Pm(e,i){return Ka(e,tt(i,O))}var Sm=B(function(e,i){return function(n){return Yr(n,e,i)}}),Om=B(function(e,i){return function(n){return Yr(e,n,i)}});function Bn(e,i,n){var c=be(i),h=Wi(i,c);n==null&&!(le(i)&&(h.length||!c.length))&&(n=i,i=e,e=this,h=Wi(i,be(i)));var f=!(le(n)&&"chain"in n)||!!n.chain,d=Ot(e);return Ze(h,function(y){var m=i[y];e[y]=m,d&&(e.prototype[y]=function(){var P=this.__chain__;if(f||P){var S=e(this.__wrapped__),R=S.__actions__=je(this.__actions__);return R.push({func:m,args:arguments,thisArg:e}),S.__chain__=P,S}return m.apply(e,Ft([this.value()],arguments))})}),e}function Rm(){return Ie._===this&&(Ie._=Zp),this}function Wn(){}function Nm(e){return e=H(e),B(function(i){return Ba(i,e)})}var Cm=Pn(ce),$m=Pn(fa),Tm=Pn(Js);function hu(e){return Tn(e)?Gs(vt(e)):ad(e)}function Am(e){return function(i){return e==null?r:Zt(e,i)}}var xm=dc(),Dm=dc(!0);function Jn(){return[]}function Gn(){return!1}function Fm(){return{}}function jm(){return""}function qm(){return!0}function Um(e,i){if(e=H(e),e<1||e>ur)return[];var n=dt,c=Oe(e,dt);i=U(i),e-=dt;for(var h=Zs(c,i);++n<e;)i(n);return h}function Mm(e){return z(e)?ce(e,vt):We(e)?[e]:je($c(te(e)))}function Lm(e){var i=++Qp;return te(e)+i}var km=Xi(function(e,i){return e+i},0),zm=Sn("ceil"),Hm=Xi(function(e,i){return e/i},1),Vm=Sn("floor");function Km(e){return e&&e.length?Bi(e,Me,hn):r}function Bm(e,i){return e&&e.length?Bi(e,U(i,2),hn):r}function Wm(e){return ya(e,Me)}function Jm(e,i){return ya(e,U(i,2))}function Gm(e){return e&&e.length?Bi(e,Me,dn):r}function Qm(e,i){return e&&e.length?Bi(e,U(i,2),dn):r}var Ym=Xi(function(e,i){return e*i},1),Zm=Sn("round"),Xm=Xi(function(e,i){return e-i},0);function ew(e){return e&&e.length?Ys(e,Me):0}function tw(e,i){return e&&e.length?Ys(e,U(i,2)):0}return p.after=Iy,p.ary=kc,p.assign=hv,p.assignIn=tu,p.assignInWith=ps,p.assignWith=lv,p.at=pv,p.before=zc,p.bind=qn,p.bindAll=vm,p.bindKey=Hc,p.castArray=Fy,p.chain=Uc,p.chunk=Vd,p.compact=Kd,p.concat=Bd,p.cond=mm,p.conforms=wm,p.constant=Vn,p.countBy=ey,p.create=fv,p.curry=Vc,p.curryRight=Kc,p.debounce=Bc,p.defaults=dv,p.defaultsDeep=gv,p.defer=Py,p.delay=Sy,p.difference=Wd,p.differenceBy=Jd,p.differenceWith=Gd,p.drop=Qd,p.dropRight=Yd,p.dropRightWhile=Zd,p.dropWhile=Xd,p.fill=eg,p.filter=ry,p.flatMap=ny,p.flatMapDeep=oy,p.flatMapDepth=ay,p.flatten=Dc,p.flattenDeep=tg,p.flattenDepth=rg,p.flip=Oy,p.flow=bm,p.flowRight=Em,p.fromPairs=ig,p.functions=Ev,p.functionsIn=Iv,p.groupBy=cy,p.initial=ng,p.intersection=og,p.intersectionBy=ag,p.intersectionWith=cg,p.invert=Sv,p.invertBy=Ov,p.invokeMap=hy,p.iteratee=Kn,p.keyBy=ly,p.keys=be,p.keysIn=Ue,p.map=os,p.mapKeys=Nv,p.mapValues=Cv,p.matches=Im,p.matchesProperty=Pm,p.memoize=cs,p.merge=$v,p.mergeWith=ru,p.method=Sm,p.methodOf=Om,p.mixin=Bn,p.negate=us,p.nthArg=Nm,p.omit=Tv,p.omitBy=Av,p.once=Ry,p.orderBy=py,p.over=Cm,p.overArgs=Ny,p.overEvery=$m,p.overSome=Tm,p.partial=Un,p.partialRight=Wc,p.partition=fy,p.pick=xv,p.pickBy=iu,p.property=hu,p.propertyOf=Am,p.pull=pg,p.pullAll=jc,p.pullAllBy=fg,p.pullAllWith=dg,p.pullAt=gg,p.range=xm,p.rangeRight=Dm,p.rearg=Cy,p.reject=yy,p.remove=yg,p.rest=$y,p.reverse=Fn,p.sampleSize=my,p.set=Fv,p.setWith=jv,p.shuffle=wy,p.slice=vg,p.sortBy=Ey,p.sortedUniq=Pg,p.sortedUniqBy=Sg,p.split=nm,p.spread=Ty,p.tail=Og,p.take=Rg,p.takeRight=Ng,p.takeRightWhile=Cg,p.takeWhile=$g,p.tap=Kg,p.throttle=Ay,p.thru=ns,p.toArray=Zc,p.toPairs=su,p.toPairsIn=nu,p.toPath=Mm,p.toPlainObject=eu,p.transform=qv,p.unary=xy,p.union=Tg,p.unionBy=Ag,p.unionWith=xg,p.uniq=Dg,p.uniqBy=Fg,p.uniqWith=jg,p.unset=Uv,p.unzip=jn,p.unzipWith=qc,p.update=Mv,p.updateWith=Lv,p.values=Sr,p.valuesIn=kv,p.without=qg,p.words=cu,p.wrap=Dy,p.xor=Ug,p.xorBy=Mg,p.xorWith=Lg,p.zip=kg,p.zipObject=zg,p.zipObjectDeep=Hg,p.zipWith=Vg,p.entries=su,p.entriesIn=nu,p.extend=tu,p.extendWith=ps,Bn(p,p),p.add=km,p.attempt=uu,p.camelCase=Kv,p.capitalize=ou,p.ceil=zm,p.clamp=zv,p.clone=jy,p.cloneDeep=Uy,p.cloneDeepWith=My,p.cloneWith=qy,p.conformsTo=Ly,p.deburr=au,p.defaultTo=_m,p.divide=Hm,p.endsWith=Bv,p.eq=ht,p.escape=Wv,p.escapeRegExp=Jv,p.every=ty,p.find=iy,p.findIndex=Ac,p.findKey=yv,p.findLast=sy,p.findLastIndex=xc,p.findLastKey=vv,p.floor=Vm,p.forEach=Mc,p.forEachRight=Lc,p.forIn=mv,p.forInRight=wv,p.forOwn=_v,p.forOwnRight=bv,p.get=kn,p.gt=ky,p.gte=zy,p.has=Pv,p.hasIn=zn,p.head=Fc,p.identity=Me,p.includes=uy,p.indexOf=sg,p.inRange=Hv,p.invoke=Rv,p.isArguments=tr,p.isArray=z,p.isArrayBuffer=Hy,p.isArrayLike=qe,p.isArrayLikeObject=ge,p.isBoolean=Vy,p.isBuffer=zt,p.isDate=Ky,p.isElement=By,p.isEmpty=Wy,p.isEqual=Jy,p.isEqualWith=Gy,p.isError=Mn,p.isFinite=Qy,p.isFunction=Ot,p.isInteger=Jc,p.isLength=hs,p.isMap=Gc,p.isMatch=Yy,p.isMatchWith=Zy,p.isNaN=Xy,p.isNative=ev,p.isNil=rv,p.isNull=tv,p.isNumber=Qc,p.isObject=le,p.isObjectLike=pe,p.isPlainObject=ii,p.isRegExp=Ln,p.isSafeInteger=iv,p.isSet=Yc,p.isString=ls,p.isSymbol=We,p.isTypedArray=Pr,p.isUndefined=sv,p.isWeakMap=nv,p.isWeakSet=ov,p.join=ug,p.kebabCase=Gv,p.last=it,p.lastIndexOf=hg,p.lowerCase=Qv,p.lowerFirst=Yv,p.lt=av,p.lte=cv,p.max=Km,p.maxBy=Bm,p.mean=Wm,p.meanBy=Jm,p.min=Gm,p.minBy=Qm,p.stubArray=Jn,p.stubFalse=Gn,p.stubObject=Fm,p.stubString=jm,p.stubTrue=qm,p.multiply=Ym,p.nth=lg,p.noConflict=Rm,p.noop=Wn,p.now=as,p.pad=Zv,p.padEnd=Xv,p.padStart=em,p.parseInt=tm,p.random=Vv,p.reduce=dy,p.reduceRight=gy,p.repeat=rm,p.replace=im,p.result=Dv,p.round=Zm,p.runInContext=v,p.sample=vy,p.size=_y,p.snakeCase=sm,p.some=by,p.sortedIndex=mg,p.sortedIndexBy=wg,p.sortedIndexOf=_g,p.sortedLastIndex=bg,p.sortedLastIndexBy=Eg,p.sortedLastIndexOf=Ig,p.startCase=om,p.startsWith=am,p.subtract=Xm,p.sum=ew,p.sumBy=tw,p.template=cm,p.times=Um,p.toFinite=Rt,p.toInteger=H,p.toLength=Xc,p.toLower=um,p.toNumber=st,p.toSafeInteger=uv,p.toString=te,p.toUpper=hm,p.trim=lm,p.trimEnd=pm,p.trimStart=fm,p.truncate=dm,p.unescape=gm,p.uniqueId=Lm,p.upperCase=ym,p.upperFirst=Hn,p.each=Mc,p.eachRight=Lc,p.first=Fc,Bn(p,function(){var e={};return gt(p,function(i,n){re.call(p.prototype,n)||(e[n]=i)}),e}(),{chain:!1}),p.VERSION=s,Ze(["bind","bindKey","curry","curryRight","partial","partialRight"],function(e){p[e].placeholder=p}),Ze(["drop","take"],function(e,i){G.prototype[e]=function(n){n=n===r?1:_e(H(n),0);var c=this.__filtered__&&!i?new G(this):this.clone();return c.__filtered__?c.__takeCount__=Oe(n,c.__takeCount__):c.__views__.push({size:Oe(n,dt),type:e+(c.__dir__<0?"Right":"")}),c},G.prototype[e+"Right"]=function(n){return this.reverse()[e](n).reverse()}}),Ze(["filter","map","takeWhile"],function(e,i){var n=i+1,c=n==Do||n==ll;G.prototype[e]=function(h){var f=this.clone();return f.__iteratees__.push({iteratee:U(h,3),type:n}),f.__filtered__=f.__filtered__||c,f}}),Ze(["head","last"],function(e,i){var n="take"+(i?"Right":"");G.prototype[e]=function(){return this[n](1).value()[0]}}),Ze(["initial","tail"],function(e,i){var n="drop"+(i?"":"Right");G.prototype[e]=function(){return this.__filtered__?new G(this):this[n](1)}}),G.prototype.compact=function(){return this.filter(Me)},G.prototype.find=function(e){return this.filter(e).head()},G.prototype.findLast=function(e){return this.reverse().find(e)},G.prototype.invokeMap=B(function(e,i){return typeof e=="function"?new G(this):this.map(function(n){return Yr(n,e,i)})}),G.prototype.reject=function(e){return this.filter(us(U(e)))},G.prototype.slice=function(e,i){e=H(e);var n=this;return n.__filtered__&&(e>0||i<0)?new G(n):(e<0?n=n.takeRight(-e):e&&(n=n.drop(e)),i!==r&&(i=H(i),n=i<0?n.dropRight(-i):n.take(i-e)),n)},G.prototype.takeRightWhile=function(e){return this.reverse().takeWhile(e).reverse()},G.prototype.toArray=function(){return this.take(dt)},gt(G.prototype,function(e,i){var n=/^(?:filter|find|map|reject)|While$/.test(i),c=/^(?:head|last)$/.test(i),h=p[c?"take"+(i=="last"?"Right":""):i],f=c||/^find/.test(i);h&&(p.prototype[i]=function(){var d=this.__wrapped__,y=c?[1]:arguments,m=d instanceof G,P=y[0],S=m||z(d),R=function(J){var Y=h.apply(p,Ft([J],y));return c&&T?Y[0]:Y};S&&n&&typeof P=="function"&&P.length!=1&&(m=S=!1);var T=this.__chain__,F=!!this.__actions__.length,M=f&&!T,V=m&&!F;if(!f&&S){d=V?d:new G(this);var L=e.apply(d,y);return L.__actions__.push({func:ns,args:[R],thisArg:r}),new et(L,T)}return M&&V?e.apply(this,y):(L=this.thru(R),M?c?L.value()[0]:L.value():L)})}),Ze(["pop","push","shift","sort","splice","unshift"],function(e){var i=Ti[e],n=/^(?:push|sort|unshift)$/.test(e)?"tap":"thru",c=/^(?:pop|shift)$/.test(e);p.prototype[e]=function(){var h=arguments;if(c&&!this.__chain__){var f=this.value();return i.apply(z(f)?f:[],h)}return this[n](function(d){return i.apply(z(d)?d:[],h)})}}),gt(G.prototype,function(e,i){var n=p[i];if(n){var c=n.name+"";re.call(wr,c)||(wr[c]=[]),wr[c].push({name:i,func:n})}}),wr[Zi(r,Q).name]=[{name:"wrapper",func:r}],G.prototype.clone=gf,G.prototype.reverse=yf,G.prototype.value=vf,p.prototype.at=Bg,p.prototype.chain=Wg,p.prototype.commit=Jg,p.prototype.next=Gg,p.prototype.plant=Yg,p.prototype.reverse=Zg,p.prototype.toJSON=p.prototype.valueOf=p.prototype.value=Xg,p.prototype.first=p.prototype.head,Vr&&(p.prototype[Vr]=Qg),p},yr=Wp();Wt?((Wt.exports=yr)._=yr,Vs._=yr):Ie._=yr}).call(hi)})(bo,bo.exports);var LE=Object.defineProperty,kE=Object.defineProperties,zE=Object.getOwnPropertyDescriptors,lh=Object.getOwnPropertySymbols,HE=Object.prototype.hasOwnProperty,VE=Object.prototype.propertyIsEnumerable,ph=(a,t,r)=>t in a?LE(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,gs=(a,t)=>{for(var r in t||(t={}))HE.call(t,r)&&ph(a,r,t[r]);if(lh)for(var r of lh(t))VE.call(t,r)&&ph(a,r,t[r]);return a},KE=(a,t)=>kE(a,zE(t));function Kt(a,t,r){var s;const o=f_(a);return((s=t.rpcMap)==null?void 0:s[o.reference])||`${ME}?chainId=${o.namespace}:${o.reference}&projectId=${r}`}function cr(a){return a.includes(":")?a.split(":")[1]:a}function rl(a){return a.map(t=>`${t.split(":")[0]}:${t.split(":")[1]}`)}function BE(a,t){const r=Object.keys(t.namespaces).filter(o=>o.includes(a));if(!r.length)return[];const s=[];return r.forEach(o=>{const u=t.namespaces[o].accounts;s.push(...u)}),s}function WE(a={},t={}){const r=fh(a),s=fh(t);return bo.exports.merge(r,s)}function fh(a){var t,r,s,o;const u={};if(!Cr(a))return u;for(const[l,g]of Object.entries(a)){const w=Co(l)?[l]:g.chains,b=g.methods||[],C=g.events||[],O=g.rpcMap||{},N=li(l);u[N]=KE(gs(gs({},u[N]),g),{chains:Zn(w,(t=u[N])==null?void 0:t.chains),methods:Zn(b,(r=u[N])==null?void 0:r.methods),events:Zn(C,(s=u[N])==null?void 0:s.events),rpcMap:gs(gs({},O),(o=u[N])==null?void 0:o.rpcMap)})}return u}function JE(a){return a.includes(":")?a.split(":")[2]:a}function GE(a){const t={};for(const[r,s]of Object.entries(a)){const o=s.methods||[],u=s.events||[],l=s.accounts||[],g=Co(r)?[r]:s.chains?s.chains:rl(s.accounts);t[r]={chains:g,methods:o,events:u,accounts:l}}return t}function no(a){return typeof a=="number"?a:a.includes("0x")?parseInt(a,16):a.includes(":")?Number(a.split(":")[1]):Number(a)}const il={},ue=a=>il[a],oo=(a,t)=>{il[a]=t};class QE{constructor(t){this.name="polkadot",this.namespace=t.namespace,this.events=ue("events"),this.client=ue("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,r){this.httpProviders[t]||this.setHttpProvider(t,r),this.chainId=t,this.events.emit(At.DEFAULT_CHAIN_CHANGED,`${this.name}:${t}`)}getAccounts(){const t=this.namespace.accounts;return t?t.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2])||[]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(r=>{var s;const o=cr(r);t[o]=this.createHttpProvider(o,(s=this.namespace.rpcMap)==null?void 0:s[r])}),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,r=this.httpProviders[t];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return r}setHttpProvider(t,r){const s=this.createHttpProvider(t,r);s&&(this.httpProviders[t]=s)}createHttpProvider(t,r){const s=r||Kt(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new Tt(new Bt(s,ue("disableProviderPing")))}}class YE{constructor(t){this.name="eip155",this.namespace=t.namespace,this.events=ue("events"),this.client=ue("client"),this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain())}async request(t){switch(t.request.method){case"eth_requestAccounts":return this.getAccounts();case"eth_accounts":return this.getAccounts();case"wallet_switchEthereumChain":return await this.handleSwitchChain(t);case"eth_chainId":return parseInt(this.getDefaultChain())}return this.namespace.methods.includes(t.request.method)?await this.client.request(t):this.getHttpProvider().request(t.request)}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}setDefaultChain(t,r){this.httpProviders[t]||this.setHttpProvider(parseInt(t),r),this.chainId=parseInt(t),this.events.emit(At.DEFAULT_CHAIN_CHANGED,`${this.name}:${t}`)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId.toString();if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}createHttpProvider(t,r){const s=r||Kt(`${this.name}:${t}`,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new Tt(new Bt(s,ue("disableProviderPing")))}setHttpProvider(t,r){const s=this.createHttpProvider(t,r);s&&(this.httpProviders[t]=s)}createHttpProviders(){const t={};return this.namespace.chains.forEach(r=>{var s;const o=parseInt(cr(r));t[o]=this.createHttpProvider(o,(s=this.namespace.rpcMap)==null?void 0:s[r])}),t}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}getHttpProvider(){const t=this.chainId,r=this.httpProviders[t];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return r}async handleSwitchChain(t){var r,s;let o=t.request.params?(r=t.request.params[0])==null?void 0:r.chainId:"0x0";o=o.startsWith("0x")?o:`0x${o}`;const u=parseInt(o,16);if(this.isChainApproved(u))this.setDefaultChain(`${u}`);else if(this.namespace.methods.includes("wallet_switchEthereumChain"))await this.client.request({topic:t.topic,request:{method:t.request.method,params:[{chainId:o}]},chainId:(s=this.namespace.chains)==null?void 0:s[0]}),this.setDefaultChain(`${u}`);else throw new Error(`Failed to switch to chain 'eip155:${u}'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.`);return null}isChainApproved(t){return this.namespace.chains.includes(`${this.name}:${t}`)}}class ZE{constructor(t){this.name="solana",this.namespace=t.namespace,this.events=ue("events"),this.client=ue("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,r){this.httpProviders[t]||this.setHttpProvider(t,r),this.chainId=t,this.events.emit(At.DEFAULT_CHAIN_CHANGED,`${this.name}:${t}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(r=>{var s;const o=cr(r);t[o]=this.createHttpProvider(o,(s=this.namespace.rpcMap)==null?void 0:s[r])}),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,r=this.httpProviders[t];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return r}setHttpProvider(t,r){const s=this.createHttpProvider(t,r);s&&(this.httpProviders[t]=s)}createHttpProvider(t,r){const s=r||Kt(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new Tt(new Bt(s,ue("disableProviderPing")))}}class XE{constructor(t){this.name="cosmos",this.namespace=t.namespace,this.events=ue("events"),this.client=ue("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,r){this.httpProviders[t]||this.setHttpProvider(t,r),this.chainId=t,this.events.emit(At.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(r=>{var s;const o=cr(r);t[o]=this.createHttpProvider(o,(s=this.namespace.rpcMap)==null?void 0:s[r])}),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,r=this.httpProviders[t];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return r}setHttpProvider(t,r){const s=this.createHttpProvider(t,r);s&&(this.httpProviders[t]=s)}createHttpProvider(t,r){const s=r||Kt(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new Tt(new Bt(s,ue("disableProviderPing")))}}class eI{constructor(t){this.name="cip34",this.namespace=t.namespace,this.events=ue("events"),this.client=ue("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,r){this.httpProviders[t]||this.setHttpProvider(t,r),this.chainId=t,this.events.emit(At.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(r=>{const s=this.getCardanoRPCUrl(r),o=cr(r);t[o]=this.createHttpProvider(o,s)}),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,r=this.httpProviders[t];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return r}getCardanoRPCUrl(t){const r=this.namespace.rpcMap;if(r)return r[t]}setHttpProvider(t,r){const s=this.createHttpProvider(t,r);s&&(this.httpProviders[t]=s)}createHttpProvider(t,r){const s=r||this.getCardanoRPCUrl(t);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new Tt(new Bt(s,ue("disableProviderPing")))}}class tI{constructor(t){this.name="elrond",this.namespace=t.namespace,this.events=ue("events"),this.client=ue("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,r){this.httpProviders[t]||this.setHttpProvider(t,r),this.chainId=t,this.events.emit(At.DEFAULT_CHAIN_CHANGED,`${this.name}:${t}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(r=>{var s;const o=cr(r);t[o]=this.createHttpProvider(o,(s=this.namespace.rpcMap)==null?void 0:s[r])}),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,r=this.httpProviders[t];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return r}setHttpProvider(t,r){const s=this.createHttpProvider(t,r);s&&(this.httpProviders[t]=s)}createHttpProvider(t,r){const s=r||Kt(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new Tt(new Bt(s,ue("disableProviderPing")))}}class rI{constructor(t){this.name="multiversx",this.namespace=t.namespace,this.events=ue("events"),this.client=ue("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,r){this.httpProviders[t]||this.setHttpProvider(t,r),this.chainId=t,this.events.emit(At.DEFAULT_CHAIN_CHANGED,`${this.name}:${t}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}getAccounts(){const t=this.namespace.accounts;return t?[...new Set(t.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2]))]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(r=>{var s;const o=cr(r);t[o]=this.createHttpProvider(o,(s=this.namespace.rpcMap)==null?void 0:s[r])}),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,r=this.httpProviders[t];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return r}setHttpProvider(t,r){const s=this.createHttpProvider(t,r);s&&(this.httpProviders[t]=s)}createHttpProvider(t,r){const s=r||Kt(t,this.namespace,this.client.core.projectId);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);return new Tt(new Bt(s,ue("disableProviderPing")))}}class iI{constructor(t){this.name="near",this.namespace=t.namespace,this.events=ue("events"),this.client=ue("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(t){this.namespace=Object.assign(this.namespace,t)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const t=this.namespace.chains[0];if(!t)throw new Error("ChainId not found");return t.split(":")[1]}request(t){return this.namespace.methods.includes(t.request.method)?this.client.request(t):this.getHttpProvider().request(t.request)}setDefaultChain(t,r){if(this.chainId=t,!this.httpProviders[t]){const s=r||Kt(`${this.name}:${t}`,this.namespace);if(!s)throw new Error(`No RPC url provided for chainId: ${t}`);this.setHttpProvider(t,s)}this.events.emit(At.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const t=this.namespace.accounts;return t?t.filter(r=>r.split(":")[1]===this.chainId.toString()).map(r=>r.split(":")[2])||[]:[]}createHttpProviders(){const t={};return this.namespace.chains.forEach(r=>{var s;t[r]=this.createHttpProvider(r,(s=this.namespace.rpcMap)==null?void 0:s[r])}),t}getHttpProvider(){const t=`${this.name}:${this.chainId}`,r=this.httpProviders[t];if(typeof r>"u")throw new Error(`JSON-RPC provider for ${t} not found`);return r}setHttpProvider(t,r){const s=this.createHttpProvider(t,r);s&&(this.httpProviders[t]=s)}createHttpProvider(t,r){const s=r||Kt(t,this.namespace);return typeof s>"u"?void 0:new Tt(new Bt(s,ue("disableProviderPing")))}}var sI=Object.defineProperty,nI=Object.defineProperties,oI=Object.getOwnPropertyDescriptors,dh=Object.getOwnPropertySymbols,aI=Object.prototype.hasOwnProperty,cI=Object.prototype.propertyIsEnumerable,gh=(a,t,r)=>t in a?sI(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,ys=(a,t)=>{for(var r in t||(t={}))aI.call(t,r)&&gh(a,r,t[r]);if(dh)for(var r of dh(t))cI.call(t,r)&&gh(a,r,t[r]);return a},ao=(a,t)=>nI(a,oI(t));class xo{constructor(t){this.events=new He.ss,this.rpcProviders={},this.shouldAbortPairingAttempt=!1,this.maxPairingAttempts=10,this.disableProviderPing=!1,this.providerOpts=t,this.logger=typeof(t==null?void 0:t.logger)<"u"&&typeof(t==null?void 0:t.logger)!="string"?t.logger:E.Tt(E.k({level:(t==null?void 0:t.logger)||uh})),this.disableProviderPing=(t==null?void 0:t.disableProviderPing)||!1}static async init(t){const r=new xo(t);return await r.initialize(),r}async request(t,r){const[s,o]=this.validateChain(r);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(s).request({request:ys({},t),chainId:`${s}:${o}`,topic:this.session.topic})}sendAsync(t,r,s){const o=new Date().getTime();this.request(t,s).then(u=>r(null,E.formatJsonRpcResult(o,u))).catch(u=>r(u,void 0))}async enable(){if(!this.client)throw new Error("Sign Client not initialized");return this.session||await this.connect({namespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties}),await this.requestAccounts()}async disconnect(){var t;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:(t=this.session)==null?void 0:t.topic,reason:ve("USER_DISCONNECTED")}),await this.cleanup()}async connect(t){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(t),await this.cleanupPendingPairings(),!t.skipPairing)return await this.pair(t.pairingTopic)}on(t,r){this.events.on(t,r)}once(t,r){this.events.once(t,r)}removeListener(t,r){this.events.removeListener(t,r)}off(t,r){this.events.off(t,r)}get isWalletConnect(){return!0}async pair(t){this.shouldAbortPairingAttempt=!1;let r=0;do{if(this.shouldAbortPairingAttempt)throw new Error("Pairing aborted");if(r>=this.maxPairingAttempts)throw new Error("Max auto pairing attempts reached");const{uri:s,approval:o}=await this.client.connect({pairingTopic:t,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties});s&&(this.uri=s,this.events.emit("display_uri",s)),await o().then(u=>{this.session=u,this.namespaces||(this.namespaces=GE(u.namespaces),this.persist("namespaces",this.namespaces))}).catch(u=>{if(u.message!==el)throw u;r++})}while(!this.session);return this.onConnect(),this.session}setDefaultChain(t,r){try{if(!this.session)return;const[s,o]=this.validateChain(t);this.getProvider(s).setDefaultChain(o,r)}catch(s){if(!/Please call connect/.test(s.message))throw s}}async cleanupPendingPairings(t={}){this.logger.info("Cleaning up inactive pairings...");const r=this.client.pairing.getAll();if(sr(r)){for(const s of r)t.deletePairings?this.client.core.expirer.set(s.topic,0):await this.client.core.relayer.subscriber.unsubscribe(s.topic);this.logger.info(`Inactive pairings cleared: ${r.length}`)}}abortPairingAttempt(){this.shouldAbortPairingAttempt=!0}async checkStorage(){if(this.namespaces=await this.getFromStore("namespaces"),this.optionalNamespaces=await this.getFromStore("optionalNamespaces")||{},this.client.session.length){const t=this.client.session.keys.length-1;this.session=this.client.session.get(this.client.session.keys[t]),this.createProviders()}}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){this.client=this.providerOpts.client||await SE.init({logger:this.providerOpts.logger||uh,relayUrl:this.providerOpts.relayUrl||jE,projectId:this.providerOpts.projectId,metadata:this.providerOpts.metadata,storageOptions:this.providerOpts.storageOptions,storage:this.providerOpts.storage,name:this.providerOpts.name}),this.logger.trace("SignClient Initialized")}createProviders(){if(!this.client)throw new Error("Sign Client not initialized");if(!this.session)throw new Error("Session not initialized. Please call connect() before enable()");const t=[...new Set(Object.keys(this.session.namespaces).map(r=>li(r)))];oo("client",this.client),oo("events",this.events),oo("disableProviderPing",this.disableProviderPing),t.forEach(r=>{if(!this.session)return;const s=BE(r,this.session),o=rl(s),u=WE(this.namespaces,this.optionalNamespaces),l=ao(ys({},u[r]),{accounts:s,chains:o});switch(r){case"eip155":this.rpcProviders[r]=new YE({namespace:l});break;case"solana":this.rpcProviders[r]=new ZE({namespace:l});break;case"cosmos":this.rpcProviders[r]=new XE({namespace:l});break;case"polkadot":this.rpcProviders[r]=new QE({namespace:l});break;case"cip34":this.rpcProviders[r]=new eI({namespace:l});break;case"elrond":this.rpcProviders[r]=new tI({namespace:l});break;case"multiversx":this.rpcProviders[r]=new rI({namespace:l});break;case"near":this.rpcProviders[r]=new iI({namespace:l});break}})}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",t=>{this.events.emit("session_ping",t)}),this.client.on("session_event",t=>{const{params:r}=t,{event:s}=r;if(s.name==="accountsChanged"){const o=s.data;o&&sr(o)&&this.events.emit("accountsChanged",o.map(JE))}else if(s.name==="chainChanged"){const o=r.chainId,u=r.event.data,l=li(o),g=no(o)!==no(u)?`${l}:${no(u)}`:o;this.onChainChanged(g)}else this.events.emit(s.name,s.data);this.events.emit("session_event",t)}),this.client.on("session_update",({topic:t,params:r})=>{var s;const{namespaces:o}=r,u=(s=this.client)==null?void 0:s.session.get(t);this.session=ao(ys({},u),{namespaces:o}),this.onSessionUpdate(),this.events.emit("session_update",{topic:t,params:r})}),this.client.on("session_delete",async t=>{await this.cleanup(),this.events.emit("session_delete",t),this.events.emit("disconnect",ao(ys({},ve("USER_DISCONNECTED")),{data:t.topic}))}),this.on(At.DEFAULT_CHAIN_CHANGED,t=>{this.onChainChanged(t,!0)})}getProvider(t){if(!this.rpcProviders[t])throw new Error(`Provider not found: ${t}`);return this.rpcProviders[t]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach(t=>{var r;this.getProvider(t).updateNamespace((r=this.session)==null?void 0:r.namespaces[t])})}setNamespaces(t){const{namespaces:r,optionalNamespaces:s,sessionProperties:o}=t;r&&Object.keys(r).length&&(this.namespaces=r),s&&Object.keys(s).length&&(this.optionalNamespaces=s),this.sessionProperties=o,this.persist("namespaces",r),this.persist("optionalNamespaces",s)}validateChain(t){const[r,s]=(t==null?void 0:t.split(":"))||["",""];if(!this.namespaces||!Object.keys(this.namespaces).length)return[r,s];if(r&&!Object.keys(this.namespaces||{}).map(l=>li(l)).includes(r))throw new Error(`Namespace '${r}' is not configured. Please call connect() first with namespace config.`);if(r&&s)return[r,s];const o=li(Object.keys(this.namespaces)[0]),u=this.rpcProviders[o].getDefaultChain();return[o,u]}async requestAccounts(){const[t]=this.validateChain();return await this.getProvider(t).requestAccounts()}onChainChanged(t,r=!1){var s;if(!this.namespaces)return;const[o,u]=this.validateChain(t);r||this.getProvider(o).setDefaultChain(u),((s=this.namespaces[o])!=null?s:this.namespaces[`${o}:${u}`]).defaultChain=u,this.persist("namespaces",this.namespaces),this.events.emit("chainChanged",u)}onConnect(){this.createProviders(),this.events.emit("connect",{session:this.session})}async cleanup(){this.session=void 0,this.namespaces=void 0,this.optionalNamespaces=void 0,this.sessionProperties=void 0,this.persist("namespaces",void 0),this.persist("optionalNamespaces",void 0),this.persist("sessionProperties",void 0),await this.cleanupPendingPairings({deletePairings:!0})}persist(t,r){this.client.core.storage.setItem(`${hh}/${t}`,r)}async getFromStore(t){return await this.client.core.storage.getItem(`${hh}/${t}`)}}const uI=xo,hI="wc",lI="ethereum_provider",pI=`${hI}@2:${lI}:`,fI="https://rpc.walletconnect.com/v1/",bs=["eth_sendTransaction","personal_sign"],sl=["eth_accounts","eth_requestAccounts","eth_sendRawTransaction","eth_sign","eth_signTransaction","eth_signTypedData","eth_signTypedData_v3","eth_signTypedData_v4","eth_sendTransaction","personal_sign","wallet_switchEthereumChain","wallet_addEthereumChain","wallet_getPermissions","wallet_requestPermissions","wallet_registerOnboarding","wallet_watchAsset","wallet_scanQRCode"],Es=["chainChanged","accountsChanged"],nl=["chainChanged","accountsChanged","message","disconnect","connect"];var dI=Object.defineProperty,gI=Object.defineProperties,yI=Object.getOwnPropertyDescriptors,yh=Object.getOwnPropertySymbols,vI=Object.prototype.hasOwnProperty,mI=Object.prototype.propertyIsEnumerable,vh=(a,t,r)=>t in a?dI(a,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[t]=r,fi=(a,t)=>{for(var r in t||(t={}))vI.call(t,r)&&vh(a,r,t[r]);if(yh)for(var r of yh(t))mI.call(t,r)&&vh(a,r,t[r]);return a},mh=(a,t)=>gI(a,yI(t));function Is(a){return Number(a[0].split(":")[1])}function co(a){return`0x${a.toString(16)}`}function wI(a){const{chains:t,optionalChains:r,methods:s,optionalMethods:o,events:u,optionalEvents:l,rpcMap:g}=a;if(!uo(t))throw new Error("Invalid chains");const w={chains:t,methods:s||bs,events:u||Es,rpcMap:fi({},t.length?{[Is(t)]:g[Is(t)]}:{})},b=u==null?void 0:u.filter(q=>!Es.includes(q)),C=s==null?void 0:s.filter(q=>!bs.includes(q));if(!r&&!l&&!o&&!(b!=null&&b.length)&&!(C!=null&&C.length))return{required:t.length?w:void 0};const O=(b==null?void 0:b.length)&&(C==null?void 0:C.length)||!r,N={chains:[...new Set(O?w.chains.concat(r||[]):r)],methods:[...new Set(w.methods.concat(o!=null&&o.length?o:sl))],events:[...new Set(w.events.concat(l!=null&&l.length?l:nl))],rpcMap:g};return{required:t.length?w:void 0,optional:r.length?N:void 0}}class Rs{constructor(){this.events=new He.eventsExports.EventEmitter,this.namespace="eip155",this.accounts=[],this.chainId=1,this.STORAGE_KEY=pI,this.on=(t,r)=>(this.events.on(t,r),this),this.once=(t,r)=>(this.events.once(t,r),this),this.removeListener=(t,r)=>(this.events.removeListener(t,r),this),this.off=(t,r)=>(this.events.off(t,r),this),this.parseAccount=t=>this.isCompatibleChainId(t)?this.parseAccountId(t).address:t,this.signer={},this.rpc={}}static async init(t){const r=new Rs;return await r.initialize(t),r}async request(t){return await this.signer.request(t,this.formatChainId(this.chainId))}sendAsync(t,r){this.signer.sendAsync(t,r,this.formatChainId(this.chainId))}get connected(){return this.signer.client?this.signer.client.core.relayer.connected:!1}get connecting(){return this.signer.client?this.signer.client.core.relayer.connecting:!1}async enable(){return this.session||await this.connect(),await this.request({method:"eth_requestAccounts"})}async connect(t){if(!this.signer.client)throw new Error("Provider not initialized. Call init() first");this.loadConnectOpts(t);const{required:r,optional:s}=wI(this.rpc);try{const o=await new Promise(async(l,g)=>{var w;this.rpc.showQrModal&&((w=this.modal)==null||w.subscribeModal(b=>{!b.open&&!this.signer.session&&(this.signer.abortPairingAttempt(),g(new Error("Connection request reset. Please try again.")))})),await this.signer.connect(mh(fi({namespaces:fi({},r&&{[this.namespace]:r})},s&&{optionalNamespaces:{[this.namespace]:s}}),{pairingTopic:t==null?void 0:t.pairingTopic})).then(b=>{l(b)}).catch(b=>{g(new Error(b.message))})});if(!o)return;const u=fw(o.namespaces,[this.namespace]);this.setChainIds(this.rpc.chains.length?this.rpc.chains:u),this.setAccounts(u),this.events.emit("connect",{chainId:co(this.chainId)})}catch(o){throw this.signer.logger.error(o),o}finally{this.modal&&this.modal.closeModal()}}async disconnect(){this.session&&await this.signer.disconnect(),this.reset()}get isWalletConnect(){return!0}get session(){return this.signer.session}registerEventListeners(){this.signer.on("session_event",t=>{const{params:r}=t,{event:s}=r;s.name==="accountsChanged"?(this.accounts=this.parseAccounts(s.data),this.events.emit("accountsChanged",this.accounts)):s.name==="chainChanged"?this.setChainId(this.formatChainId(s.data)):this.events.emit(s.name,s.data),this.events.emit("session_event",t)}),this.signer.on("chainChanged",t=>{const r=parseInt(t);this.chainId=r,this.events.emit("chainChanged",co(this.chainId)),this.persist()}),this.signer.on("session_update",t=>{this.events.emit("session_update",t)}),this.signer.on("session_delete",t=>{this.reset(),this.events.emit("session_delete",t),this.events.emit("disconnect",mh(fi({},gw("USER_DISCONNECTED")),{data:t.topic,name:"USER_DISCONNECTED"}))}),this.signer.on("display_uri",t=>{var r,s;this.rpc.showQrModal&&((r=this.modal)==null||r.closeModal(),(s=this.modal)==null||s.openModal({uri:t})),this.events.emit("display_uri",t)})}switchEthereumChain(t){this.request({method:"wallet_switchEthereumChain",params:[{chainId:t.toString(16)}]})}isCompatibleChainId(t){return typeof t=="string"?t.startsWith(`${this.namespace}:`):!1}formatChainId(t){return`${this.namespace}:${t}`}parseChainId(t){return Number(t.split(":")[1])}setChainIds(t){const r=t.filter(s=>this.isCompatibleChainId(s)).map(s=>this.parseChainId(s));r.length&&(this.chainId=r[0],this.events.emit("chainChanged",co(this.chainId)),this.persist())}setChainId(t){if(this.isCompatibleChainId(t)){const r=this.parseChainId(t);this.chainId=r,this.switchEthereumChain(r)}}parseAccountId(t){const[r,s,o]=t.split(":");return{chainId:`${r}:${s}`,address:o}}setAccounts(t){this.accounts=t.filter(r=>this.parseChainId(this.parseAccountId(r).chainId)===this.chainId).map(r=>this.parseAccountId(r).address),this.events.emit("accountsChanged",this.accounts)}getRpcConfig(t){var r,s;const o=(r=t==null?void 0:t.chains)!=null?r:[],u=(s=t==null?void 0:t.optionalChains)!=null?s:[],l=o.concat(u);if(!l.length)throw new Error("No chains specified in either `chains` or `optionalChains`");const g=o.length?(t==null?void 0:t.methods)||bs:[],w=o.length?(t==null?void 0:t.events)||Es:[],b=(t==null?void 0:t.optionalMethods)||[],C=(t==null?void 0:t.optionalEvents)||[],O=(t==null?void 0:t.rpcMap)||this.buildRpcMap(l,t.projectId),N=(t==null?void 0:t.qrModalOptions)||void 0;return{chains:o==null?void 0:o.map(q=>this.formatChainId(q)),optionalChains:u.map(q=>this.formatChainId(q)),methods:g,events:w,optionalMethods:b,optionalEvents:C,rpcMap:O,showQrModal:!!(t!=null&&t.showQrModal),qrModalOptions:N,projectId:t.projectId,metadata:t.metadata}}buildRpcMap(t,r){const s={};return t.forEach(o=>{s[o]=this.getRpcUrl(o,r)}),s}async initialize(t){if(this.rpc=this.getRpcConfig(t),this.chainId=this.rpc.chains.length?Is(this.rpc.chains):Is(this.rpc.optionalChains),this.signer=await uI.init({projectId:this.rpc.projectId,metadata:this.rpc.metadata,disableProviderPing:t.disableProviderPing,relayUrl:t.relayUrl,storageOptions:t.storageOptions}),this.registerEventListeners(),await this.loadPersistedSession(),this.rpc.showQrModal){let r;try{const{WalletConnectModal:s}=await Promise.resolve().then(()=>require("./index-8-70GvMi.js")).then(o=>o.index);r=s}catch{throw new Error("To use QR modal, please install @walletconnect/modal package")}if(r)try{this.modal=new r(fi({projectId:this.rpc.projectId},this.rpc.qrModalOptions))}catch(s){throw this.signer.logger.error(s),new Error("Could not generate WalletConnectModal Instance")}}}loadConnectOpts(t){if(!t)return;const{chains:r,optionalChains:s,rpcMap:o}=t;r&&uo(r)&&(this.rpc.chains=r.map(u=>this.formatChainId(u)),r.forEach(u=>{this.rpc.rpcMap[u]=(o==null?void 0:o[u])||this.getRpcUrl(u)})),s&&uo(s)&&(this.rpc.optionalChains=[],this.rpc.optionalChains=s==null?void 0:s.map(u=>this.formatChainId(u)),s.forEach(u=>{this.rpc.rpcMap[u]=(o==null?void 0:o[u])||this.getRpcUrl(u)}))}getRpcUrl(t,r){var s;return((s=this.rpc.rpcMap)==null?void 0:s[t])||`${fI}?chainId=eip155:${t}&projectId=${r||this.rpc.projectId}`}async loadPersistedSession(){if(!this.session)return;const t=await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`),r=this.session.namespaces[`${this.namespace}:${t}`]?this.session.namespaces[`${this.namespace}:${t}`]:this.session.namespaces[this.namespace];this.setChainIds(t?[this.formatChainId(t)]:r==null?void 0:r.accounts),this.setAccounts(r==null?void 0:r.accounts)}reset(){this.chainId=1,this.accounts=[]}persist(){this.session&&this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`,this.chainId)}parseAccounts(t){return typeof t=="string"||t instanceof String?[this.parseAccount(t)]:t.map(r=>this.parseAccount(r))}}const _I=Rs;exports.EthereumProvider=_I;exports.OPTIONAL_EVENTS=nl;exports.OPTIONAL_METHODS=sl;exports.REQUIRED_EVENTS=Es;exports.REQUIRED_METHODS=bs;exports.default=Rs;
|