const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/index-DiHOtb9W.js","assets/index-Dixv1Mqn.js","assets/index-Dt_CGZqf.css"])))=>i.map(i=>d[i]); import{g as Tv,o as U4,p as $4,d as ji,q as Ar,r as z4,h as S0,_ as j4}from"./index-Dixv1Mqn.js";import{e as Hi,J as I0}from"./events-B42VzzV1.js";import{r as M0,i as xh}from"./inherits_browser-DmlooEhV.js";var xe={};/*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var Vl=function(r,e){return Vl=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var n in i)i.hasOwnProperty(n)&&(t[n]=i[n])},Vl(r,e)};function k4(r,e){Vl(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}var Gl=function(){return Gl=Object.assign||function(e){for(var t,i=1,n=arguments.length;i=0;u--)(f=r[u])&&(a=(n<3?f(a):n>3?f(e,t,a):f(e,t))||a);return n>3&&a&&Object.defineProperty(e,t,a),a}function V4(r,e){return function(t,i){e(t,i,r)}}function G4(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)}function W4(r,e,t,i){function n(a){return a instanceof t?a:new t(function(f){f(a)})}return new(t||(t=Promise))(function(a,f){function u(y){try{p(i.next(y))}catch(A){f(A)}}function b(y){try{p(i.throw(y))}catch(A){f(A)}}function p(y){y.done?a(y.value):n(y.value).then(u,b)}p((i=i.apply(r,e||[])).next())})}function J4(r,e){var t={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,n,a,f;return f={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(f[Symbol.iterator]=function(){return this}),f;function u(p){return function(y){return b([p,y])}}function b(p){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,n&&(a=p[0]&2?n.return:p[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,p[1])).done)return a;switch(n=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return t.label++,{value:p[1],done:!1};case 5:t.label++,n=p[1],p=[0];continue;case 7:p=t.ops.pop(),t.trys.pop();continue;default:if(a=t.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){t=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]=r.length&&(r=void 0),{value:r&&r[i++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Dv(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var i=t.call(r),n,a=[],f;try{for(;(e===void 0||e-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(u){f={error:u}}finally{try{n&&!n.done&&(t=i.return)&&t.call(i)}finally{if(f)throw f.error}}return a}function X4(){for(var r=[],e=0;e1||u(R,O)})})}function u(R,O){try{b(i[R](O))}catch(N){A(a[0][3],N)}}function b(R){R.value instanceof lc?Promise.resolve(R.value.v).then(p,y):A(a[0][2],R)}function p(R){u("next",R)}function y(R){u("throw",R)}function A(R,O){R(O),a.shift(),a.length&&u(a[0][0],a[0][1])}}function t8(r){var e,t;return e={},i("next"),i("throw",function(n){throw n}),i("return"),e[Symbol.iterator]=function(){return this},e;function i(n,a){e[n]=r[n]?function(f){return(t=!t)?{value:lc(r[n](f)),done:n==="return"}:a?a(f):f}:a}}function r8(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof Wl=="function"?Wl(r):r[Symbol.iterator](),t={},i("next"),i("throw"),i("return"),t[Symbol.asyncIterator]=function(){return this},t);function i(a){t[a]=r[a]&&function(f){return new Promise(function(u,b){f=r[a](f),n(u,b,f.done,f.value)})}}function n(a,f,u,b){Promise.resolve(b).then(function(p){a({value:p,done:u})},f)}}function i8(r,e){return Object.defineProperty?Object.defineProperty(r,"raw",{value:e}):r.raw=e,r}function n8(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var t in r)Object.hasOwnProperty.call(r,t)&&(e[t]=r[t]);return e.default=r,e}function s8(r){return r&&r.__esModule?r:{default:r}}function a8(r,e){if(!e.has(r))throw new TypeError("attempted to get private field on non-instance");return e.get(r)}function o8(r,e,t){if(!e.has(r))throw new TypeError("attempted to set private field on non-instance");return e.set(r,t),t}const c8=Object.freeze(Object.defineProperty({__proto__:null,get __assign(){return Gl},__asyncDelegator:t8,__asyncGenerator:e8,__asyncValues:r8,__await:lc,__awaiter:W4,__classPrivateFieldGet:a8,__classPrivateFieldSet:o8,__createBinding:Y4,__decorate:K4,__exportStar:Q4,__extends:k4,__generator:J4,__importDefault:s8,__importStar:n8,__makeTemplateObject:i8,__metadata:G4,__param:V4,__read:Dv,__rest:H4,__spread:X4,__spreadArrays:Z4,__values:Wl},Symbol.toStringTag,{value:"Module"})),Sh=Tv(c8);var sl={},ko={},s1;function f8(){if(s1)return ko;s1=1,Object.defineProperty(ko,"__esModule",{value:!0}),ko.delay=void 0;function r(e){return new Promise(t=>{setTimeout(()=>{t(!0)},e)})}return ko.delay=r,ko}var ra={},al={},ia={},a1;function h8(){return a1||(a1=1,Object.defineProperty(ia,"__esModule",{value:!0}),ia.ONE_THOUSAND=ia.ONE_HUNDRED=void 0,ia.ONE_HUNDRED=100,ia.ONE_THOUSAND=1e3),ia}var ol={},o1;function u8(){return o1||(o1=1,function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.ONE_YEAR=r.FOUR_WEEKS=r.THREE_WEEKS=r.TWO_WEEKS=r.ONE_WEEK=r.THIRTY_DAYS=r.SEVEN_DAYS=r.FIVE_DAYS=r.THREE_DAYS=r.ONE_DAY=r.TWENTY_FOUR_HOURS=r.TWELVE_HOURS=r.SIX_HOURS=r.THREE_HOURS=r.ONE_HOUR=r.SIXTY_MINUTES=r.THIRTY_MINUTES=r.TEN_MINUTES=r.FIVE_MINUTES=r.ONE_MINUTE=r.SIXTY_SECONDS=r.THIRTY_SECONDS=r.TEN_SECONDS=r.FIVE_SECONDS=r.ONE_SECOND=void 0,r.ONE_SECOND=1,r.FIVE_SECONDS=5,r.TEN_SECONDS=10,r.THIRTY_SECONDS=30,r.SIXTY_SECONDS=60,r.ONE_MINUTE=r.SIXTY_SECONDS,r.FIVE_MINUTES=r.ONE_MINUTE*5,r.TEN_MINUTES=r.ONE_MINUTE*10,r.THIRTY_MINUTES=r.ONE_MINUTE*30,r.SIXTY_MINUTES=r.ONE_MINUTE*60,r.ONE_HOUR=r.SIXTY_MINUTES,r.THREE_HOURS=r.ONE_HOUR*3,r.SIX_HOURS=r.ONE_HOUR*6,r.TWELVE_HOURS=r.ONE_HOUR*12,r.TWENTY_FOUR_HOURS=r.ONE_HOUR*24,r.ONE_DAY=r.TWENTY_FOUR_HOURS,r.THREE_DAYS=r.ONE_DAY*3,r.FIVE_DAYS=r.ONE_DAY*5,r.SEVEN_DAYS=r.ONE_DAY*7,r.THIRTY_DAYS=r.ONE_DAY*30,r.ONE_WEEK=r.SEVEN_DAYS,r.TWO_WEEKS=r.ONE_WEEK*2,r.THREE_WEEKS=r.ONE_WEEK*3,r.FOUR_WEEKS=r.ONE_WEEK*4,r.ONE_YEAR=r.ONE_DAY*365}(ol)),ol}var c1;function Fv(){return c1||(c1=1,function(r){Object.defineProperty(r,"__esModule",{value:!0});const e=Sh;e.__exportStar(h8(),r),e.__exportStar(u8(),r)}(al)),al}var f1;function l8(){if(f1)return ra;f1=1,Object.defineProperty(ra,"__esModule",{value:!0}),ra.fromMiliseconds=ra.toMiliseconds=void 0;const r=Fv();function e(i){return i*r.ONE_THOUSAND}ra.toMiliseconds=e;function t(i){return Math.floor(i/r.ONE_THOUSAND)}return ra.fromMiliseconds=t,ra}var h1;function d8(){return h1||(h1=1,function(r){Object.defineProperty(r,"__esModule",{value:!0});const e=Sh;e.__exportStar(f8(),r),e.__exportStar(l8(),r)}(sl)),sl}var Ha={},u1;function p8(){if(u1)return Ha;u1=1,Object.defineProperty(Ha,"__esModule",{value:!0}),Ha.Watch=void 0;class r{constructor(){this.timestamps=new Map}start(t){if(this.timestamps.has(t))throw new Error(`Watch already started for label: ${t}`);this.timestamps.set(t,{started:Date.now()})}stop(t){const i=this.get(t);if(typeof i.elapsed<"u")throw new Error(`Watch already stopped for label: ${t}`);const n=Date.now()-i.started;this.timestamps.set(t,{started:i.started,elapsed:n})}get(t){const i=this.timestamps.get(t);if(typeof i>"u")throw new Error(`No timestamp found for label: ${t}`);return i}elapsed(t){const i=this.get(t);return i.elapsed||Date.now()-i.started}}return Ha.Watch=r,Ha.default=r,Ha}var cl={},Ho={},l1;function g8(){if(l1)return Ho;l1=1,Object.defineProperty(Ho,"__esModule",{value:!0}),Ho.IWatch=void 0;class r{}return Ho.IWatch=r,Ho}var d1;function v8(){return d1||(d1=1,function(r){Object.defineProperty(r,"__esModule",{value:!0}),Sh.__exportStar(g8(),r)}(cl)),cl}(function(r){Object.defineProperty(r,"__esModule",{value:!0});const e=Sh;e.__exportStar(d8(),r),e.__exportStar(p8(),r),e.__exportStar(v8(),r),e.__exportStar(Fv(),r)})(xe);var Vt={};Object.defineProperty(Vt,"__esModule",{value:!0});Vt.getLocalStorage=Vt.getLocalStorageOrThrow=Vt.getCrypto=Vt.getCryptoOrThrow=Bv=Vt.getLocation=Vt.getLocationOrThrow=P0=Vt.getNavigator=Vt.getNavigatorOrThrow=Ih=Vt.getDocument=Vt.getDocumentOrThrow=Vt.getFromWindowOrThrow=Vt.getFromWindow=void 0;function ma(r){let e;return typeof window<"u"&&typeof window[r]<"u"&&(e=window[r]),e}Vt.getFromWindow=ma;function co(r){const e=ma(r);if(!e)throw new Error(`${r} is not defined in Window`);return e}Vt.getFromWindowOrThrow=co;function b8(){return co("document")}Vt.getDocumentOrThrow=b8;function m8(){return ma("document")}var Ih=Vt.getDocument=m8;function y8(){return co("navigator")}Vt.getNavigatorOrThrow=y8;function w8(){return ma("navigator")}var P0=Vt.getNavigator=w8;function _8(){return co("location")}Vt.getLocationOrThrow=_8;function A8(){return ma("location")}var Bv=Vt.getLocation=A8;function E8(){return co("crypto")}Vt.getCryptoOrThrow=E8;function x8(){return ma("crypto")}Vt.getCrypto=x8;function S8(){return co("localStorage")}Vt.getLocalStorageOrThrow=S8;function I8(){return ma("localStorage")}Vt.getLocalStorage=I8;var O0={};Object.defineProperty(O0,"__esModule",{value:!0});var qv=O0.getWindowMetadata=void 0;const p1=Vt;function M8(){let r,e;try{r=p1.getDocumentOrThrow(),e=p1.getLocationOrThrow()}catch{return null}function t(){const A=r.getElementsByTagName("link"),R=[];for(let O=0;O-1){const W=N.getAttribute("href");if(W)if(W.toLowerCase().indexOf("https:")===-1&&W.toLowerCase().indexOf("http:")===-1&&W.indexOf("//")!==0){let Q=e.protocol+"//"+e.host;if(W.indexOf("/")===0)Q+=W;else{const j=e.pathname.split("/");j.pop();const Y=j.join("/");Q+=Y+"/"+W}R.push(Q)}else if(W.indexOf("//")===0){const Q=e.protocol+W;R.push(Q)}else R.push(W)}}return R}function i(...A){const R=r.getElementsByTagName("meta");for(let O=0;ON.getAttribute(W)).filter(W=>W?A.includes(W):!1);if(K.length&&K){const W=N.getAttribute("content");if(W)return W}}return""}function n(){let A=i("name","og:site_name","og:title","twitter:title");return A||(A=r.title),A}function a(){return i("description","og:description","twitter:description","keywords")}const f=n(),u=a(),b=e.origin,p=t();return{description:u,url:b,icons:p,name:f}}qv=O0.getWindowMetadata=M8;var dc={},P8=r=>encodeURIComponent(r).replace(/[!'()*]/g,e=>`%${e.charCodeAt(0).toString(16).toUpperCase()}`),Lv="%[a-f0-9]{2}",g1=new RegExp("("+Lv+")|([^%]+?)","gi"),v1=new RegExp("("+Lv+")+","gi");function Jl(r,e){try{return[decodeURIComponent(r.join(""))]}catch{}if(r.length===1)return r;e=e||1;var t=r.slice(0,e),i=r.slice(e);return Array.prototype.concat.call([],Jl(t),Jl(i))}function O8(r){try{return decodeURIComponent(r)}catch{for(var e=r.match(g1)||[],t=1;t{if(!(typeof r=="string"&&typeof e=="string"))throw new TypeError("Expected the arguments to be of type `string`");if(e==="")return[r];const t=r.indexOf(e);return t===-1?[r]:[r.slice(0,t),r.slice(t+e.length)]},T8=function(r,e){for(var t={},i=Object.keys(r),n=Array.isArray(e),a=0;aj==null,f=Symbol("encodeFragmentIdentifier");function u(j){switch(j.arrayFormat){case"index":return Y=>(U,k)=>{const G=U.length;return k===void 0||j.skipNull&&k===null||j.skipEmptyString&&k===""?U:k===null?[...U,[y(Y,j),"[",G,"]"].join("")]:[...U,[y(Y,j),"[",y(G,j),"]=",y(k,j)].join("")]};case"bracket":return Y=>(U,k)=>k===void 0||j.skipNull&&k===null||j.skipEmptyString&&k===""?U:k===null?[...U,[y(Y,j),"[]"].join("")]:[...U,[y(Y,j),"[]=",y(k,j)].join("")];case"colon-list-separator":return Y=>(U,k)=>k===void 0||j.skipNull&&k===null||j.skipEmptyString&&k===""?U:k===null?[...U,[y(Y,j),":list="].join("")]:[...U,[y(Y,j),":list=",y(k,j)].join("")];case"comma":case"separator":case"bracket-separator":{const Y=j.arrayFormat==="bracket-separator"?"[]=":"=";return U=>(k,G)=>G===void 0||j.skipNull&&G===null||j.skipEmptyString&&G===""?k:(G=G===null?"":G,k.length===0?[[y(U,j),Y,y(G,j)].join("")]:[[k,y(G,j)].join(j.arrayFormatSeparator)])}default:return Y=>(U,k)=>k===void 0||j.skipNull&&k===null||j.skipEmptyString&&k===""?U:k===null?[...U,y(Y,j)]:[...U,[y(Y,j),"=",y(k,j)].join("")]}}function b(j){let Y;switch(j.arrayFormat){case"index":return(U,k,G)=>{if(Y=/\[(\d*)\]$/.exec(U),U=U.replace(/\[\d*\]$/,""),!Y){G[U]=k;return}G[U]===void 0&&(G[U]={}),G[U][Y[1]]=k};case"bracket":return(U,k,G)=>{if(Y=/(\[\])$/.exec(U),U=U.replace(/\[\]$/,""),!Y){G[U]=k;return}if(G[U]===void 0){G[U]=[k];return}G[U]=[].concat(G[U],k)};case"colon-list-separator":return(U,k,G)=>{if(Y=/(:list)$/.exec(U),U=U.replace(/:list$/,""),!Y){G[U]=k;return}if(G[U]===void 0){G[U]=[k];return}G[U]=[].concat(G[U],k)};case"comma":case"separator":return(U,k,G)=>{const x=typeof k=="string"&&k.includes(j.arrayFormatSeparator),B=typeof k=="string"&&!x&&A(k,j).includes(j.arrayFormatSeparator);k=B?A(k,j):k;const ae=x||B?k.split(j.arrayFormatSeparator).map(le=>A(le,j)):k===null?k:A(k,j);G[U]=ae};case"bracket-separator":return(U,k,G)=>{const x=/(\[\])$/.test(U);if(U=U.replace(/\[\]$/,""),!x){G[U]=k&&A(k,j);return}const B=k===null?[]:k.split(j.arrayFormatSeparator).map(ae=>A(ae,j));if(G[U]===void 0){G[U]=B;return}G[U]=[].concat(G[U],B)};default:return(U,k,G)=>{if(G[U]===void 0){G[U]=k;return}G[U]=[].concat(G[U],k)}}}function p(j){if(typeof j!="string"||j.length!==1)throw new TypeError("arrayFormatSeparator must be single character string")}function y(j,Y){return Y.encode?Y.strict?e(j):encodeURIComponent(j):j}function A(j,Y){return Y.decode?t(j):j}function R(j){return Array.isArray(j)?j.sort():typeof j=="object"?R(Object.keys(j)).sort((Y,U)=>Number(Y)-Number(U)).map(Y=>j[Y]):j}function O(j){const Y=j.indexOf("#");return Y!==-1&&(j=j.slice(0,Y)),j}function N(j){let Y="";const U=j.indexOf("#");return U!==-1&&(Y=j.slice(U)),Y}function K(j){j=O(j);const Y=j.indexOf("?");return Y===-1?"":j.slice(Y+1)}function W(j,Y){return Y.parseNumbers&&!Number.isNaN(Number(j))&&typeof j=="string"&&j.trim()!==""?j=Number(j):Y.parseBooleans&&j!==null&&(j.toLowerCase()==="true"||j.toLowerCase()==="false")&&(j=j.toLowerCase()==="true"),j}function Q(j,Y){Y=Object.assign({decode:!0,sort:!0,arrayFormat:"none",arrayFormatSeparator:",",parseNumbers:!1,parseBooleans:!1},Y),p(Y.arrayFormatSeparator);const U=b(Y),k=Object.create(null);if(typeof j!="string"||(j=j.trim().replace(/^[?#&]/,""),!j))return k;for(const G of j.split("&")){if(G==="")continue;let[x,B]=i(Y.decode?G.replace(/\+/g," "):G,"=");B=B===void 0?null:["comma","separator","bracket-separator"].includes(Y.arrayFormat)?B:A(B,Y),U(A(x,Y),B,k)}for(const G of Object.keys(k)){const x=k[G];if(typeof x=="object"&&x!==null)for(const B of Object.keys(x))x[B]=W(x[B],Y);else k[G]=W(x,Y)}return Y.sort===!1?k:(Y.sort===!0?Object.keys(k).sort():Object.keys(k).sort(Y.sort)).reduce((G,x)=>{const B=k[x];return B&&typeof B=="object"&&!Array.isArray(B)?G[x]=R(B):G[x]=B,G},Object.create(null))}r.extract=K,r.parse=Q,r.stringify=(j,Y)=>{if(!j)return"";Y=Object.assign({encode:!0,strict:!0,arrayFormat:"none",arrayFormatSeparator:","},Y),p(Y.arrayFormatSeparator);const U=B=>Y.skipNull&&a(j[B])||Y.skipEmptyString&&j[B]==="",k=u(Y),G={};for(const B of Object.keys(j))U(B)||(G[B]=j[B]);const x=Object.keys(G);return Y.sort!==!1&&x.sort(Y.sort),x.map(B=>{const ae=j[B];return ae===void 0?"":ae===null?y(B,Y):Array.isArray(ae)?ae.length===0&&Y.arrayFormat==="bracket-separator"?y(B,Y)+"[]":ae.reduce(k(B),[]).join("&"):y(B,Y)+"="+y(ae,Y)}).filter(B=>B.length>0).join("&")},r.parseUrl=(j,Y)=>{Y=Object.assign({decode:!0},Y);const[U,k]=i(j,"#");return Object.assign({url:U.split("?")[0]||"",query:Q(K(j),Y)},Y&&Y.parseFragmentIdentifier&&k?{fragmentIdentifier:A(k,Y)}:{})},r.stringifyUrl=(j,Y)=>{Y=Object.assign({encode:!0,strict:!0,[f]:!0},Y);const U=O(j.url).split("?")[0]||"",k=r.extract(j.url),G=r.parse(k,{sort:!1}),x=Object.assign(G,j.query);let B=r.stringify(x,Y);B&&(B=`?${B}`);let ae=N(j.url);return j.fragmentIdentifier&&(ae=`#${Y[f]?y(j.fragmentIdentifier,Y):j.fragmentIdentifier}`),`${U}${B}${ae}`},r.pick=(j,Y,U)=>{U=Object.assign({parseFragmentIdentifier:!0,[f]:!1},U);const{url:k,query:G,fragmentIdentifier:x}=r.parseUrl(j,U);return r.stringifyUrl({url:k,query:n(G,Y),fragmentIdentifier:x},U)},r.exclude=(j,Y,U)=>{const k=Array.isArray(Y)?G=>!Y.includes(G):(G,x)=>!Y(G,x);return r.pick(j,k,U)}})(dc);var R0={},Mh={},mt={},Uv={};(function(r){Object.defineProperty(r,"__esModule",{value:!0});function e(u,b){var p=u>>>16&65535,y=u&65535,A=b>>>16&65535,R=b&65535;return y*R+(p*R+y*A<<16>>>0)|0}r.mul=Math.imul||e;function t(u,b){return u+b|0}r.add=t;function i(u,b){return u-b|0}r.sub=i;function n(u,b){return u<>>32-b}r.rotl=n;function a(u,b){return u<<32-b|u>>>b}r.rotr=a;function f(u){return typeof u=="number"&&isFinite(u)&&Math.floor(u)===u}r.isInteger=Number.isInteger||f,r.MAX_SAFE_INTEGER=9007199254740991,r.isSafeInteger=function(u){return r.isInteger(u)&&u>=-r.MAX_SAFE_INTEGER&&u<=r.MAX_SAFE_INTEGER}})(Uv);Object.defineProperty(mt,"__esModule",{value:!0});var $v=Uv;function D8(r,e){return e===void 0&&(e=0),(r[e+0]<<8|r[e+1])<<16>>16}mt.readInt16BE=D8;function F8(r,e){return e===void 0&&(e=0),(r[e+0]<<8|r[e+1])>>>0}mt.readUint16BE=F8;function B8(r,e){return e===void 0&&(e=0),(r[e+1]<<8|r[e])<<16>>16}mt.readInt16LE=B8;function q8(r,e){return e===void 0&&(e=0),(r[e+1]<<8|r[e])>>>0}mt.readUint16LE=q8;function zv(r,e,t){return e===void 0&&(e=new Uint8Array(2)),t===void 0&&(t=0),e[t+0]=r>>>8,e[t+1]=r>>>0,e}mt.writeUint16BE=zv;mt.writeInt16BE=zv;function jv(r,e,t){return e===void 0&&(e=new Uint8Array(2)),t===void 0&&(t=0),e[t+0]=r>>>0,e[t+1]=r>>>8,e}mt.writeUint16LE=jv;mt.writeInt16LE=jv;function Yl(r,e){return e===void 0&&(e=0),r[e]<<24|r[e+1]<<16|r[e+2]<<8|r[e+3]}mt.readInt32BE=Yl;function Ql(r,e){return e===void 0&&(e=0),(r[e]<<24|r[e+1]<<16|r[e+2]<<8|r[e+3])>>>0}mt.readUint32BE=Ql;function Xl(r,e){return e===void 0&&(e=0),r[e+3]<<24|r[e+2]<<16|r[e+1]<<8|r[e]}mt.readInt32LE=Xl;function Zl(r,e){return e===void 0&&(e=0),(r[e+3]<<24|r[e+2]<<16|r[e+1]<<8|r[e])>>>0}mt.readUint32LE=Zl;function ah(r,e,t){return e===void 0&&(e=new Uint8Array(4)),t===void 0&&(t=0),e[t+0]=r>>>24,e[t+1]=r>>>16,e[t+2]=r>>>8,e[t+3]=r>>>0,e}mt.writeUint32BE=ah;mt.writeInt32BE=ah;function oh(r,e,t){return e===void 0&&(e=new Uint8Array(4)),t===void 0&&(t=0),e[t+0]=r>>>0,e[t+1]=r>>>8,e[t+2]=r>>>16,e[t+3]=r>>>24,e}mt.writeUint32LE=oh;mt.writeInt32LE=oh;function L8(r,e){e===void 0&&(e=0);var t=Yl(r,e),i=Yl(r,e+4);return t*4294967296+i-(i>>31)*4294967296}mt.readInt64BE=L8;function U8(r,e){e===void 0&&(e=0);var t=Ql(r,e),i=Ql(r,e+4);return t*4294967296+i}mt.readUint64BE=U8;function $8(r,e){e===void 0&&(e=0);var t=Xl(r,e),i=Xl(r,e+4);return i*4294967296+t-(t>>31)*4294967296}mt.readInt64LE=$8;function z8(r,e){e===void 0&&(e=0);var t=Zl(r,e),i=Zl(r,e+4);return i*4294967296+t}mt.readUint64LE=z8;function kv(r,e,t){return e===void 0&&(e=new Uint8Array(8)),t===void 0&&(t=0),ah(r/4294967296>>>0,e,t),ah(r>>>0,e,t+4),e}mt.writeUint64BE=kv;mt.writeInt64BE=kv;function Hv(r,e,t){return e===void 0&&(e=new Uint8Array(8)),t===void 0&&(t=0),oh(r>>>0,e,t),oh(r/4294967296>>>0,e,t+4),e}mt.writeUint64LE=Hv;mt.writeInt64LE=Hv;function j8(r,e,t){if(t===void 0&&(t=0),r%8!==0)throw new Error("readUintBE supports only bitLengths divisible by 8");if(r/8>e.length-t)throw new Error("readUintBE: array is too short for the given bitLength");for(var i=0,n=1,a=r/8+t-1;a>=t;a--)i+=e[a]*n,n*=256;return i}mt.readUintBE=j8;function k8(r,e,t){if(t===void 0&&(t=0),r%8!==0)throw new Error("readUintLE supports only bitLengths divisible by 8");if(r/8>e.length-t)throw new Error("readUintLE: array is too short for the given bitLength");for(var i=0,n=1,a=t;a=i;a--)t[a]=e/n&255,n*=256;return t}mt.writeUintBE=H8;function K8(r,e,t,i){if(t===void 0&&(t=new Uint8Array(r/8)),i===void 0&&(i=0),r%8!==0)throw new Error("writeUintLE supports only bitLengths divisible by 8");if(!$v.isSafeInteger(e))throw new Error("writeUintLE value must be an integer");for(var n=1,a=i;a>>16|v<<16,F=F+v|0,x^=F,x=x>>>20|x<<12,U=U+B|0,_^=U,_=_>>>16|_<<16,m=m+_|0,B^=m,B=B>>>20|B<<12,k=k+ae|0,I^=k,I=I>>>16|I<<16,c=c+I|0,ae^=c,ae=ae>>>20|ae<<12,G=G+le|0,M^=G,M=M>>>16|M<<16,h=h+M|0,le^=h,le=le>>>20|le<<12,k=k+ae|0,I^=k,I=I>>>24|I<<8,c=c+I|0,ae^=c,ae=ae>>>25|ae<<7,G=G+le|0,M^=G,M=M>>>24|M<<8,h=h+M|0,le^=h,le=le>>>25|le<<7,U=U+B|0,_^=U,_=_>>>24|_<<8,m=m+_|0,B^=m,B=B>>>25|B<<7,Y=Y+x|0,v^=Y,v=v>>>24|v<<8,F=F+v|0,x^=F,x=x>>>25|x<<7,Y=Y+B|0,M^=Y,M=M>>>16|M<<16,c=c+M|0,B^=c,B=B>>>20|B<<12,U=U+ae|0,v^=U,v=v>>>16|v<<16,h=h+v|0,ae^=h,ae=ae>>>20|ae<<12,k=k+le|0,_^=k,_=_>>>16|_<<16,F=F+_|0,le^=F,le=le>>>20|le<<12,G=G+x|0,I^=G,I=I>>>16|I<<16,m=m+I|0,x^=m,x=x>>>20|x<<12,k=k+le|0,_^=k,_=_>>>24|_<<8,F=F+_|0,le^=F,le=le>>>25|le<<7,G=G+x|0,I^=G,I=I>>>24|I<<8,m=m+I|0,x^=m,x=x>>>25|x<<7,U=U+ae|0,v^=U,v=v>>>24|v<<8,h=h+v|0,ae^=h,ae=ae>>>25|ae<<7,Y=Y+B|0,M^=Y,M=M>>>24|M<<8,c=c+M|0,B^=c,B=B>>>25|B<<7;Ur.writeUint32LE(Y+i|0,r,0),Ur.writeUint32LE(U+n|0,r,4),Ur.writeUint32LE(k+a|0,r,8),Ur.writeUint32LE(G+f|0,r,12),Ur.writeUint32LE(x+u|0,r,16),Ur.writeUint32LE(B+b|0,r,20),Ur.writeUint32LE(ae+p|0,r,24),Ur.writeUint32LE(le+y|0,r,28),Ur.writeUint32LE(F+A|0,r,32),Ur.writeUint32LE(m+R|0,r,36),Ur.writeUint32LE(c+O|0,r,40),Ur.writeUint32LE(h+N|0,r,44),Ur.writeUint32LE(v+K|0,r,48),Ur.writeUint32LE(_+W|0,r,52),Ur.writeUint32LE(I+Q|0,r,56),Ur.writeUint32LE(M+j|0,r,60)}function Kv(r,e,t,i,n){if(n===void 0&&(n=0),r.length!==32)throw new Error("ChaCha: key size must be 32 bytes");if(i.length>>=8,e++;if(i>0)throw new Error("ChaCha: counter overflow")}var Vv={},Us={};Object.defineProperty(Us,"__esModule",{value:!0});function s_(r,e,t){return~(r-1)&e|r-1&t}Us.select=s_;function a_(r,e){return(r|0)-(e|0)-1>>>31&1}Us.lessOrEqual=a_;function Gv(r,e){if(r.length!==e.length)return 0;for(var t=0,i=0;i>>8}Us.compare=Gv;function o_(r,e){return r.length===0||e.length===0?!1:Gv(r,e)!==0}Us.equal=o_;(function(r){Object.defineProperty(r,"__esModule",{value:!0});var e=Us,t=Ei;r.DIGEST_LENGTH=16;var i=function(){function f(u){this.digestLength=r.DIGEST_LENGTH,this._buffer=new Uint8Array(16),this._r=new Uint16Array(10),this._h=new Uint16Array(10),this._pad=new Uint16Array(8),this._leftover=0,this._fin=0,this._finished=!1;var b=u[0]|u[1]<<8;this._r[0]=b&8191;var p=u[2]|u[3]<<8;this._r[1]=(b>>>13|p<<3)&8191;var y=u[4]|u[5]<<8;this._r[2]=(p>>>10|y<<6)&7939;var A=u[6]|u[7]<<8;this._r[3]=(y>>>7|A<<9)&8191;var R=u[8]|u[9]<<8;this._r[4]=(A>>>4|R<<12)&255,this._r[5]=R>>>1&8190;var O=u[10]|u[11]<<8;this._r[6]=(R>>>14|O<<2)&8191;var N=u[12]|u[13]<<8;this._r[7]=(O>>>11|N<<5)&8065;var K=u[14]|u[15]<<8;this._r[8]=(N>>>8|K<<8)&8191,this._r[9]=K>>>5&127,this._pad[0]=u[16]|u[17]<<8,this._pad[1]=u[18]|u[19]<<8,this._pad[2]=u[20]|u[21]<<8,this._pad[3]=u[22]|u[23]<<8,this._pad[4]=u[24]|u[25]<<8,this._pad[5]=u[26]|u[27]<<8,this._pad[6]=u[28]|u[29]<<8,this._pad[7]=u[30]|u[31]<<8}return f.prototype._blocks=function(u,b,p){for(var y=this._fin?0:2048,A=this._h[0],R=this._h[1],O=this._h[2],N=this._h[3],K=this._h[4],W=this._h[5],Q=this._h[6],j=this._h[7],Y=this._h[8],U=this._h[9],k=this._r[0],G=this._r[1],x=this._r[2],B=this._r[3],ae=this._r[4],le=this._r[5],F=this._r[6],m=this._r[7],c=this._r[8],h=this._r[9];p>=16;){var v=u[b+0]|u[b+1]<<8;A+=v&8191;var _=u[b+2]|u[b+3]<<8;R+=(v>>>13|_<<3)&8191;var I=u[b+4]|u[b+5]<<8;O+=(_>>>10|I<<6)&8191;var M=u[b+6]|u[b+7]<<8;N+=(I>>>7|M<<9)&8191;var S=u[b+8]|u[b+9]<<8;K+=(M>>>4|S<<12)&8191,W+=S>>>1&8191;var d=u[b+10]|u[b+11]<<8;Q+=(S>>>14|d<<2)&8191;var g=u[b+12]|u[b+13]<<8;j+=(d>>>11|g<<5)&8191;var T=u[b+14]|u[b+15]<<8;Y+=(g>>>8|T<<8)&8191,U+=T>>>5|y;var Z=0,se=Z;se+=A*k,se+=R*(5*h),se+=O*(5*c),se+=N*(5*m),se+=K*(5*F),Z=se>>>13,se&=8191,se+=W*(5*le),se+=Q*(5*ae),se+=j*(5*B),se+=Y*(5*x),se+=U*(5*G),Z+=se>>>13,se&=8191;var P=Z;P+=A*G,P+=R*k,P+=O*(5*h),P+=N*(5*c),P+=K*(5*m),Z=P>>>13,P&=8191,P+=W*(5*F),P+=Q*(5*le),P+=j*(5*ae),P+=Y*(5*B),P+=U*(5*x),Z+=P>>>13,P&=8191;var ee=Z;ee+=A*x,ee+=R*G,ee+=O*k,ee+=N*(5*h),ee+=K*(5*c),Z=ee>>>13,ee&=8191,ee+=W*(5*m),ee+=Q*(5*F),ee+=j*(5*le),ee+=Y*(5*ae),ee+=U*(5*B),Z+=ee>>>13,ee&=8191;var q=Z;q+=A*B,q+=R*x,q+=O*G,q+=N*k,q+=K*(5*h),Z=q>>>13,q&=8191,q+=W*(5*c),q+=Q*(5*m),q+=j*(5*F),q+=Y*(5*le),q+=U*(5*ae),Z+=q>>>13,q&=8191;var z=Z;z+=A*ae,z+=R*B,z+=O*x,z+=N*G,z+=K*k,Z=z>>>13,z&=8191,z+=W*(5*h),z+=Q*(5*c),z+=j*(5*m),z+=Y*(5*F),z+=U*(5*le),Z+=z>>>13,z&=8191;var H=Z;H+=A*le,H+=R*ae,H+=O*B,H+=N*x,H+=K*G,Z=H>>>13,H&=8191,H+=W*k,H+=Q*(5*h),H+=j*(5*c),H+=Y*(5*m),H+=U*(5*F),Z+=H>>>13,H&=8191;var w=Z;w+=A*F,w+=R*le,w+=O*ae,w+=N*B,w+=K*x,Z=w>>>13,w&=8191,w+=W*G,w+=Q*k,w+=j*(5*h),w+=Y*(5*c),w+=U*(5*m),Z+=w>>>13,w&=8191;var $=Z;$+=A*m,$+=R*F,$+=O*le,$+=N*ae,$+=K*B,Z=$>>>13,$&=8191,$+=W*x,$+=Q*G,$+=j*k,$+=Y*(5*h),$+=U*(5*c),Z+=$>>>13,$&=8191;var ne=Z;ne+=A*c,ne+=R*m,ne+=O*F,ne+=N*le,ne+=K*ae,Z=ne>>>13,ne&=8191,ne+=W*B,ne+=Q*x,ne+=j*G,ne+=Y*k,ne+=U*(5*h),Z+=ne>>>13,ne&=8191;var ce=Z;ce+=A*h,ce+=R*c,ce+=O*m,ce+=N*F,ce+=K*le,Z=ce>>>13,ce&=8191,ce+=W*ae,ce+=Q*B,ce+=j*x,ce+=Y*G,ce+=U*k,Z+=ce>>>13,ce&=8191,Z=(Z<<2)+Z|0,Z=Z+se|0,se=Z&8191,Z=Z>>>13,P+=Z,A=se,R=P,O=ee,N=q,K=z,W=H,Q=w,j=$,Y=ne,U=ce,b+=16,p-=16}this._h[0]=A,this._h[1]=R,this._h[2]=O,this._h[3]=N,this._h[4]=K,this._h[5]=W,this._h[6]=Q,this._h[7]=j,this._h[8]=Y,this._h[9]=U},f.prototype.finish=function(u,b){b===void 0&&(b=0);var p=new Uint16Array(10),y,A,R,O;if(this._leftover){for(O=this._leftover,this._buffer[O++]=1;O<16;O++)this._buffer[O]=0;this._fin=1,this._blocks(this._buffer,0,16)}for(y=this._h[1]>>>13,this._h[1]&=8191,O=2;O<10;O++)this._h[O]+=y,y=this._h[O]>>>13,this._h[O]&=8191;for(this._h[0]+=y*5,y=this._h[0]>>>13,this._h[0]&=8191,this._h[1]+=y,y=this._h[1]>>>13,this._h[1]&=8191,this._h[2]+=y,p[0]=this._h[0]+5,y=p[0]>>>13,p[0]&=8191,O=1;O<10;O++)p[O]=this._h[O]+y,y=p[O]>>>13,p[O]&=8191;for(p[9]-=8192,A=(y^1)-1,O=0;O<10;O++)p[O]&=A;for(A=~A,O=0;O<10;O++)this._h[O]=this._h[O]&A|p[O];for(this._h[0]=(this._h[0]|this._h[1]<<13)&65535,this._h[1]=(this._h[1]>>>3|this._h[2]<<10)&65535,this._h[2]=(this._h[2]>>>6|this._h[3]<<7)&65535,this._h[3]=(this._h[3]>>>9|this._h[4]<<4)&65535,this._h[4]=(this._h[4]>>>12|this._h[5]<<1|this._h[6]<<14)&65535,this._h[5]=(this._h[6]>>>2|this._h[7]<<11)&65535,this._h[6]=(this._h[7]>>>5|this._h[8]<<8)&65535,this._h[7]=(this._h[8]>>>8|this._h[9]<<5)&65535,R=this._h[0]+this._pad[0],this._h[0]=R&65535,O=1;O<8;O++)R=(this._h[O]+this._pad[O]|0)+(R>>>16)|0,this._h[O]=R&65535;return u[b+0]=this._h[0]>>>0,u[b+1]=this._h[0]>>>8,u[b+2]=this._h[1]>>>0,u[b+3]=this._h[1]>>>8,u[b+4]=this._h[2]>>>0,u[b+5]=this._h[2]>>>8,u[b+6]=this._h[3]>>>0,u[b+7]=this._h[3]>>>8,u[b+8]=this._h[4]>>>0,u[b+9]=this._h[4]>>>8,u[b+10]=this._h[5]>>>0,u[b+11]=this._h[5]>>>8,u[b+12]=this._h[6]>>>0,u[b+13]=this._h[6]>>>8,u[b+14]=this._h[7]>>>0,u[b+15]=this._h[7]>>>8,this._finished=!0,this},f.prototype.update=function(u){var b=0,p=u.length,y;if(this._leftover){y=16-this._leftover,y>p&&(y=p);for(var A=0;A=16&&(y=p-p%16,this._blocks(u,b,y),b+=y,p-=y),p){for(var A=0;A16)throw new Error("ChaCha20Poly1305: incorrect nonce length");var O=new Uint8Array(16);O.set(p,O.length-p.length);var N=new Uint8Array(32);e.stream(this._key,O,N,4);var K=y.length+this.tagLength,W;if(R){if(R.length!==K)throw new Error("ChaCha20Poly1305: incorrect destination length");W=R}else W=new Uint8Array(K);return e.streamXOR(this._key,O,y,W,4),this._authenticate(W.subarray(W.length-this.tagLength,W.length),N,W.subarray(0,W.length-this.tagLength),A),i.wipe(O),W},b.prototype.open=function(p,y,A,R){if(p.length>16)throw new Error("ChaCha20Poly1305: incorrect nonce length");if(y.length0&&O.update(f.subarray(R.length%16))),O.update(A),A.length%16>0&&O.update(f.subarray(A.length%16));var N=new Uint8Array(8);R&&n.writeUint64LE(R.length,N),O.update(N),n.writeUint64LE(A.length,N),O.update(N);for(var K=O.digest(),W=0;Wthis.blockSize?this._inner.update(t).finish(i).clean():i.set(t);for(var n=0;n1&&this._hmac.update(this._buffer),this._info&&this._hmac.update(this._info),this._hmac.update(this._counter),this._hmac.finish(this._buffer),this._bufpos=0},r.prototype.expand=function(e){for(var t=new Uint8Array(e),i=0;i256)throw new Error("randomString charset is too long");let R="";const O=y.length,N=256-256%O;for(;p>0;){const K=n(Math.ceil(p*256/N),A);for(let W=0;W0;W++){const Q=K[W];Q0){for(;this._bufferLength0;)this._buffer[this._bufferLength++]=b[y++],p--;this._bufferLength===this.blockSize&&(a(this._temp,this._state,this._buffer,0,this.blockSize),this._bufferLength=0)}for(p>=this.blockSize&&(y=a(this._temp,this._state,b,y,p),p%=this.blockSize);p>0;)this._buffer[this._bufferLength++]=b[y++],p--;return this},u.prototype.finish=function(b){if(!this._finished){var p=this._bytesHashed,y=this._bufferLength,A=p/536870912|0,R=p<<3,O=p%64<56?64:128;this._buffer[y]=128;for(var N=y+1;N0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}},u.prototype.restoreState=function(b){return this._state.set(b.state),this._bufferLength=b.bufferLength,b.buffer&&this._buffer.set(b.buffer),this._bytesHashed=b.bytesHashed,this._finished=!1,this},u.prototype.cleanSavedState=function(b){t.wipe(b.state),b.buffer&&t.wipe(b.buffer),b.bufferLength=0,b.bytesHashed=0},u}();r.SHA256=i;var n=new Int32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function a(u,b,p,y,A){for(;A>=64;){for(var R=b[0],O=b[1],N=b[2],K=b[3],W=b[4],Q=b[5],j=b[6],Y=b[7],U=0;U<16;U++){var k=y+U*4;u[U]=e.readUint32BE(p,k)}for(var U=16;U<64;U++){var G=u[U-2],x=(G>>>17|G<<15)^(G>>>19|G<<13)^G>>>10;G=u[U-15];var B=(G>>>7|G<<25)^(G>>>18|G<<14)^G>>>3;u[U]=(x+u[U-7]|0)+(B+u[U-16]|0)}for(var U=0;U<64;U++){var x=(((W>>>6|W<<26)^(W>>>11|W<<21)^(W>>>25|W<<7))+(W&Q^~W&j)|0)+(Y+(n[U]+u[U]|0)|0)|0,B=((R>>>2|R<<30)^(R>>>13|R<<19)^(R>>>22|R<<10))+(R&O^R&N^O&N)|0;Y=j,j=Q,Q=W,W=K+x|0,K=N,N=O,O=R,R=x+B|0}b[0]+=R,b[1]+=O,b[2]+=N,b[3]+=K,b[4]+=W,b[5]+=Q,b[6]+=j,b[7]+=Y,y+=64,A-=64}return y}function f(u){var b=new i;b.update(u);var p=b.digest();return b.clean(),p}r.hash=f})(Ac);var C0={};(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.sharedKey=r.generateKeyPair=r.generateKeyPairFromSeed=r.scalarMultBase=r.scalarMult=r.SHARED_KEY_LENGTH=r.SECRET_KEY_LENGTH=r.PUBLIC_KEY_LENGTH=void 0;const e=$s,t=Ei;r.PUBLIC_KEY_LENGTH=32,r.SECRET_KEY_LENGTH=32,r.SHARED_KEY_LENGTH=32;function i(U){const k=new Float64Array(16);if(U)for(let G=0;G>16&1),G[le-1]&=65535;G[15]=x[15]-32767-(G[14]>>16&1);const ae=G[15]>>16&1;G[14]&=65535,u(x,G,1-ae)}for(let B=0;B<16;B++)U[2*B]=x[B]&255,U[2*B+1]=x[B]>>8}function p(U,k){for(let G=0;G<16;G++)U[G]=k[2*G]+(k[2*G+1]<<8);U[15]&=32767}function y(U,k,G){for(let x=0;x<16;x++)U[x]=k[x]+G[x]}function A(U,k,G){for(let x=0;x<16;x++)U[x]=k[x]-G[x]}function R(U,k,G){let x,B,ae=0,le=0,F=0,m=0,c=0,h=0,v=0,_=0,I=0,M=0,S=0,d=0,g=0,T=0,Z=0,se=0,P=0,ee=0,q=0,z=0,H=0,w=0,$=0,ne=0,ce=0,he=0,ye=0,we=0,Ce=0,Qe=0,Oe=0,Te=G[0],Ie=G[1],me=G[2],Re=G[3],De=G[4],ve=G[5],Ne=G[6],Se=G[7],be=G[8],Le=G[9],Me=G[10],_e=G[11],He=G[12],Ve=G[13],Ee=G[14],Ke=G[15];x=k[0],ae+=x*Te,le+=x*Ie,F+=x*me,m+=x*Re,c+=x*De,h+=x*ve,v+=x*Ne,_+=x*Se,I+=x*be,M+=x*Le,S+=x*Me,d+=x*_e,g+=x*He,T+=x*Ve,Z+=x*Ee,se+=x*Ke,x=k[1],le+=x*Te,F+=x*Ie,m+=x*me,c+=x*Re,h+=x*De,v+=x*ve,_+=x*Ne,I+=x*Se,M+=x*be,S+=x*Le,d+=x*Me,g+=x*_e,T+=x*He,Z+=x*Ve,se+=x*Ee,P+=x*Ke,x=k[2],F+=x*Te,m+=x*Ie,c+=x*me,h+=x*Re,v+=x*De,_+=x*ve,I+=x*Ne,M+=x*Se,S+=x*be,d+=x*Le,g+=x*Me,T+=x*_e,Z+=x*He,se+=x*Ve,P+=x*Ee,ee+=x*Ke,x=k[3],m+=x*Te,c+=x*Ie,h+=x*me,v+=x*Re,_+=x*De,I+=x*ve,M+=x*Ne,S+=x*Se,d+=x*be,g+=x*Le,T+=x*Me,Z+=x*_e,se+=x*He,P+=x*Ve,ee+=x*Ee,q+=x*Ke,x=k[4],c+=x*Te,h+=x*Ie,v+=x*me,_+=x*Re,I+=x*De,M+=x*ve,S+=x*Ne,d+=x*Se,g+=x*be,T+=x*Le,Z+=x*Me,se+=x*_e,P+=x*He,ee+=x*Ve,q+=x*Ee,z+=x*Ke,x=k[5],h+=x*Te,v+=x*Ie,_+=x*me,I+=x*Re,M+=x*De,S+=x*ve,d+=x*Ne,g+=x*Se,T+=x*be,Z+=x*Le,se+=x*Me,P+=x*_e,ee+=x*He,q+=x*Ve,z+=x*Ee,H+=x*Ke,x=k[6],v+=x*Te,_+=x*Ie,I+=x*me,M+=x*Re,S+=x*De,d+=x*ve,g+=x*Ne,T+=x*Se,Z+=x*be,se+=x*Le,P+=x*Me,ee+=x*_e,q+=x*He,z+=x*Ve,H+=x*Ee,w+=x*Ke,x=k[7],_+=x*Te,I+=x*Ie,M+=x*me,S+=x*Re,d+=x*De,g+=x*ve,T+=x*Ne,Z+=x*Se,se+=x*be,P+=x*Le,ee+=x*Me,q+=x*_e,z+=x*He,H+=x*Ve,w+=x*Ee,$+=x*Ke,x=k[8],I+=x*Te,M+=x*Ie,S+=x*me,d+=x*Re,g+=x*De,T+=x*ve,Z+=x*Ne,se+=x*Se,P+=x*be,ee+=x*Le,q+=x*Me,z+=x*_e,H+=x*He,w+=x*Ve,$+=x*Ee,ne+=x*Ke,x=k[9],M+=x*Te,S+=x*Ie,d+=x*me,g+=x*Re,T+=x*De,Z+=x*ve,se+=x*Ne,P+=x*Se,ee+=x*be,q+=x*Le,z+=x*Me,H+=x*_e,w+=x*He,$+=x*Ve,ne+=x*Ee,ce+=x*Ke,x=k[10],S+=x*Te,d+=x*Ie,g+=x*me,T+=x*Re,Z+=x*De,se+=x*ve,P+=x*Ne,ee+=x*Se,q+=x*be,z+=x*Le,H+=x*Me,w+=x*_e,$+=x*He,ne+=x*Ve,ce+=x*Ee,he+=x*Ke,x=k[11],d+=x*Te,g+=x*Ie,T+=x*me,Z+=x*Re,se+=x*De,P+=x*ve,ee+=x*Ne,q+=x*Se,z+=x*be,H+=x*Le,w+=x*Me,$+=x*_e,ne+=x*He,ce+=x*Ve,he+=x*Ee,ye+=x*Ke,x=k[12],g+=x*Te,T+=x*Ie,Z+=x*me,se+=x*Re,P+=x*De,ee+=x*ve,q+=x*Ne,z+=x*Se,H+=x*be,w+=x*Le,$+=x*Me,ne+=x*_e,ce+=x*He,he+=x*Ve,ye+=x*Ee,we+=x*Ke,x=k[13],T+=x*Te,Z+=x*Ie,se+=x*me,P+=x*Re,ee+=x*De,q+=x*ve,z+=x*Ne,H+=x*Se,w+=x*be,$+=x*Le,ne+=x*Me,ce+=x*_e,he+=x*He,ye+=x*Ve,we+=x*Ee,Ce+=x*Ke,x=k[14],Z+=x*Te,se+=x*Ie,P+=x*me,ee+=x*Re,q+=x*De,z+=x*ve,H+=x*Ne,w+=x*Se,$+=x*be,ne+=x*Le,ce+=x*Me,he+=x*_e,ye+=x*He,we+=x*Ve,Ce+=x*Ee,Qe+=x*Ke,x=k[15],se+=x*Te,P+=x*Ie,ee+=x*me,q+=x*Re,z+=x*De,H+=x*ve,w+=x*Ne,$+=x*Se,ne+=x*be,ce+=x*Le,he+=x*Me,ye+=x*_e,we+=x*He,Ce+=x*Ve,Qe+=x*Ee,Oe+=x*Ke,ae+=38*P,le+=38*ee,F+=38*q,m+=38*z,c+=38*H,h+=38*w,v+=38*$,_+=38*ne,I+=38*ce,M+=38*he,S+=38*ye,d+=38*we,g+=38*Ce,T+=38*Qe,Z+=38*Oe,B=1,x=ae+B+65535,B=Math.floor(x/65536),ae=x-B*65536,x=le+B+65535,B=Math.floor(x/65536),le=x-B*65536,x=F+B+65535,B=Math.floor(x/65536),F=x-B*65536,x=m+B+65535,B=Math.floor(x/65536),m=x-B*65536,x=c+B+65535,B=Math.floor(x/65536),c=x-B*65536,x=h+B+65535,B=Math.floor(x/65536),h=x-B*65536,x=v+B+65535,B=Math.floor(x/65536),v=x-B*65536,x=_+B+65535,B=Math.floor(x/65536),_=x-B*65536,x=I+B+65535,B=Math.floor(x/65536),I=x-B*65536,x=M+B+65535,B=Math.floor(x/65536),M=x-B*65536,x=S+B+65535,B=Math.floor(x/65536),S=x-B*65536,x=d+B+65535,B=Math.floor(x/65536),d=x-B*65536,x=g+B+65535,B=Math.floor(x/65536),g=x-B*65536,x=T+B+65535,B=Math.floor(x/65536),T=x-B*65536,x=Z+B+65535,B=Math.floor(x/65536),Z=x-B*65536,x=se+B+65535,B=Math.floor(x/65536),se=x-B*65536,ae+=B-1+37*(B-1),B=1,x=ae+B+65535,B=Math.floor(x/65536),ae=x-B*65536,x=le+B+65535,B=Math.floor(x/65536),le=x-B*65536,x=F+B+65535,B=Math.floor(x/65536),F=x-B*65536,x=m+B+65535,B=Math.floor(x/65536),m=x-B*65536,x=c+B+65535,B=Math.floor(x/65536),c=x-B*65536,x=h+B+65535,B=Math.floor(x/65536),h=x-B*65536,x=v+B+65535,B=Math.floor(x/65536),v=x-B*65536,x=_+B+65535,B=Math.floor(x/65536),_=x-B*65536,x=I+B+65535,B=Math.floor(x/65536),I=x-B*65536,x=M+B+65535,B=Math.floor(x/65536),M=x-B*65536,x=S+B+65535,B=Math.floor(x/65536),S=x-B*65536,x=d+B+65535,B=Math.floor(x/65536),d=x-B*65536,x=g+B+65535,B=Math.floor(x/65536),g=x-B*65536,x=T+B+65535,B=Math.floor(x/65536),T=x-B*65536,x=Z+B+65535,B=Math.floor(x/65536),Z=x-B*65536,x=se+B+65535,B=Math.floor(x/65536),se=x-B*65536,ae+=B-1+37*(B-1),U[0]=ae,U[1]=le,U[2]=F,U[3]=m,U[4]=c,U[5]=h,U[6]=v,U[7]=_,U[8]=I,U[9]=M,U[10]=S,U[11]=d,U[12]=g,U[13]=T,U[14]=Z,U[15]=se}function O(U,k){R(U,k,k)}function N(U,k){const G=i();for(let x=0;x<16;x++)G[x]=k[x];for(let x=253;x>=0;x--)O(G,G),x!==2&&x!==4&&R(G,G,k);for(let x=0;x<16;x++)U[x]=G[x]}function K(U,k){const G=new Uint8Array(32),x=new Float64Array(80),B=i(),ae=i(),le=i(),F=i(),m=i(),c=i();for(let I=0;I<31;I++)G[I]=U[I];G[31]=U[31]&127|64,G[0]&=248,p(x,k);for(let I=0;I<16;I++)ae[I]=x[I];B[0]=F[0]=1;for(let I=254;I>=0;--I){const M=G[I>>>3]>>>(I&7)&1;u(B,ae,M),u(le,F,M),y(m,B,le),A(B,B,le),y(le,ae,F),A(ae,ae,F),O(F,m),O(c,B),R(B,le,B),R(le,ae,m),y(m,B,le),A(B,B,le),O(ae,B),A(le,F,c),R(B,le,a),y(B,B,F),R(le,le,B),R(B,F,c),R(F,ae,x),O(ae,m),u(B,ae,M),u(le,F,M)}for(let I=0;I<16;I++)x[I+16]=B[I],x[I+32]=le[I],x[I+48]=ae[I],x[I+64]=F[I];const h=x.subarray(32),v=x.subarray(16);N(h,h),R(v,v,h);const _=new Uint8Array(32);return b(_,v),_}r.scalarMult=K;function W(U){return K(U,n)}r.scalarMultBase=W;function Q(U){if(U.length!==r.SECRET_KEY_LENGTH)throw new Error(`x25519: seed must be ${r.SECRET_KEY_LENGTH} bytes`);const k=new Uint8Array(U);return{publicKey:W(k),secretKey:k}}r.generateKeyPairFromSeed=Q;function j(U){const k=(0,e.randomBytes)(32,U),G=Q(k);return(0,t.wipe)(k),G}r.generateKeyPair=j;function Y(U,k,G=!1){if(U.length!==r.PUBLIC_KEY_LENGTH)throw new Error("X25519: incorrect secret key length");if(k.length!==r.PUBLIC_KEY_LENGTH)throw new Error("X25519: incorrect public key length");const x=K(U,k);if(G){let B=0;for(let ae=0;aen+a.length,0));const t=U4(e);let i=0;for(const n of r)t.set(n,i),i+=n.length;return t}function Er(r,e="utf8"){const t=$4[e];if(!t)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(r.buffer,r.byteOffset,r.byteLength).toString("utf8"):t.encoder.encode(r).substring(1)}var Yv={};const __="elliptic",A_="6.5.7",E_="EC cryptography",x_="lib/elliptic.js",S_=["lib"],I_={lint:"eslint lib test","lint:fix":"npm run lint -- --fix",unit:"istanbul test _mocha --reporter=spec test/index.js",test:"npm run lint && npm run unit",version:"grunt dist && git add dist/"},M_={type:"git",url:"git@github.com:indutny/elliptic"},P_=["EC","Elliptic","curve","Cryptography"],O_="Fedor Indutny ",R_="MIT",N_={url:"https://github.com/indutny/elliptic/issues"},C_="https://github.com/indutny/elliptic",T_={brfs:"^2.0.2",coveralls:"^3.1.0",eslint:"^7.6.0",grunt:"^1.2.1","grunt-browserify":"^5.3.0","grunt-cli":"^1.3.2","grunt-contrib-connect":"^3.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^5.0.0","grunt-mocha-istanbul":"^5.0.2","grunt-saucelabs":"^9.0.1",istanbul:"^0.4.5",mocha:"^8.0.1"},D_={"bn.js":"^4.11.9",brorand:"^1.1.0","hash.js":"^1.0.0","hmac-drbg":"^1.0.1",inherits:"^2.0.4","minimalistic-assert":"^1.0.1","minimalistic-crypto-utils":"^1.0.1"},F_={name:__,version:A_,description:E_,main:x_,files:S_,scripts:I_,repository:M_,keywords:P_,author:O_,license:R_,bugs:N_,homepage:C_,devDependencies:T_,dependencies:D_};var xi={},T0={exports:{}};T0.exports;(function(r){(function(e,t){function i(F,m){if(!F)throw new Error(m||"Assertion failed")}function n(F,m){F.super_=m;var c=function(){};c.prototype=m.prototype,F.prototype=new c,F.prototype.constructor=F}function a(F,m,c){if(a.isBN(F))return F;this.negative=0,this.words=null,this.length=0,this.red=null,F!==null&&((m==="le"||m==="be")&&(c=m,m=10),this._init(F||0,m||10,c||"be"))}typeof e=="object"?e.exports=a:t.BN=a,a.BN=a,a.wordSize=26;var f;try{typeof window<"u"&&typeof window.Buffer<"u"?f=window.Buffer:f=M0.Buffer}catch{}a.isBN=function(m){return m instanceof a?!0:m!==null&&typeof m=="object"&&m.constructor.wordSize===a.wordSize&&Array.isArray(m.words)},a.max=function(m,c){return m.cmp(c)>0?m:c},a.min=function(m,c){return m.cmp(c)<0?m:c},a.prototype._init=function(m,c,h){if(typeof m=="number")return this._initNumber(m,c,h);if(typeof m=="object")return this._initArray(m,c,h);c==="hex"&&(c=16),i(c===(c|0)&&c>=2&&c<=36),m=m.toString().replace(/\s+/g,"");var v=0;m[0]==="-"&&(v++,this.negative=1),v=0;v-=3)I=m[v]|m[v-1]<<8|m[v-2]<<16,this.words[_]|=I<>>26-M&67108863,M+=24,M>=26&&(M-=26,_++);else if(h==="le")for(v=0,_=0;v>>26-M&67108863,M+=24,M>=26&&(M-=26,_++);return this.strip()};function u(F,m){var c=F.charCodeAt(m);return c>=65&&c<=70?c-55:c>=97&&c<=102?c-87:c-48&15}function b(F,m,c){var h=u(F,c);return c-1>=m&&(h|=u(F,c-1)<<4),h}a.prototype._parseHex=function(m,c,h){this.length=Math.ceil((m.length-c)/6),this.words=new Array(this.length);for(var v=0;v=c;v-=2)M=b(m,c,v)<<_,this.words[I]|=M&67108863,_>=18?(_-=18,I+=1,this.words[I]|=M>>>26):_+=8;else{var S=m.length-c;for(v=S%2===0?c+1:c;v=18?(_-=18,I+=1,this.words[I]|=M>>>26):_+=8}this.strip()};function p(F,m,c,h){for(var v=0,_=Math.min(F.length,c),I=m;I<_;I++){var M=F.charCodeAt(I)-48;v*=h,M>=49?v+=M-49+10:M>=17?v+=M-17+10:v+=M}return v}a.prototype._parseBase=function(m,c,h){this.words=[0],this.length=1;for(var v=0,_=1;_<=67108863;_*=c)v++;v--,_=_/c|0;for(var I=m.length-h,M=I%v,S=Math.min(I,I-M)+h,d=0,g=h;g1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},a.prototype.inspect=function(){return(this.red?""};var y=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],A=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],R=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];a.prototype.toString=function(m,c){m=m||10,c=c|0||1;var h;if(m===16||m==="hex"){h="";for(var v=0,_=0,I=0;I>>24-v&16777215,_!==0||I!==this.length-1?h=y[6-S.length]+S+h:h=S+h,v+=2,v>=26&&(v-=26,I--)}for(_!==0&&(h=_.toString(16)+h);h.length%c!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}if(m===(m|0)&&m>=2&&m<=36){var d=A[m],g=R[m];h="";var T=this.clone();for(T.negative=0;!T.isZero();){var Z=T.modn(g).toString(m);T=T.idivn(g),T.isZero()?h=Z+h:h=y[d-Z.length]+Z+h}for(this.isZero()&&(h="0"+h);h.length%c!==0;)h="0"+h;return this.negative!==0&&(h="-"+h),h}i(!1,"Base should be between 2 and 36")},a.prototype.toNumber=function(){var m=this.words[0];return this.length===2?m+=this.words[1]*67108864:this.length===3&&this.words[2]===1?m+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-m:m},a.prototype.toJSON=function(){return this.toString(16)},a.prototype.toBuffer=function(m,c){return i(typeof f<"u"),this.toArrayLike(f,m,c)},a.prototype.toArray=function(m,c){return this.toArrayLike(Array,m,c)},a.prototype.toArrayLike=function(m,c,h){var v=this.byteLength(),_=h||Math.max(1,v);i(v<=_,"byte array longer than desired length"),i(_>0,"Requested array length <= 0"),this.strip();var I=c==="le",M=new m(_),S,d,g=this.clone();if(I){for(d=0;!g.isZero();d++)S=g.andln(255),g.iushrn(8),M[d]=S;for(;d<_;d++)M[d]=0}else{for(d=0;d<_-v;d++)M[d]=0;for(d=0;!g.isZero();d++)S=g.andln(255),g.iushrn(8),M[_-d-1]=S}return M},Math.clz32?a.prototype._countBits=function(m){return 32-Math.clz32(m)}:a.prototype._countBits=function(m){var c=m,h=0;return c>=4096&&(h+=13,c>>>=13),c>=64&&(h+=7,c>>>=7),c>=8&&(h+=4,c>>>=4),c>=2&&(h+=2,c>>>=2),h+c},a.prototype._zeroBits=function(m){if(m===0)return 26;var c=m,h=0;return c&8191||(h+=13,c>>>=13),c&127||(h+=7,c>>>=7),c&15||(h+=4,c>>>=4),c&3||(h+=2,c>>>=2),c&1||h++,h},a.prototype.bitLength=function(){var m=this.words[this.length-1],c=this._countBits(m);return(this.length-1)*26+c};function O(F){for(var m=new Array(F.bitLength()),c=0;c>>v}return m}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var m=0,c=0;cm.length?this.clone().ior(m):m.clone().ior(this)},a.prototype.uor=function(m){return this.length>m.length?this.clone().iuor(m):m.clone().iuor(this)},a.prototype.iuand=function(m){var c;this.length>m.length?c=m:c=this;for(var h=0;hm.length?this.clone().iand(m):m.clone().iand(this)},a.prototype.uand=function(m){return this.length>m.length?this.clone().iuand(m):m.clone().iuand(this)},a.prototype.iuxor=function(m){var c,h;this.length>m.length?(c=this,h=m):(c=m,h=this);for(var v=0;vm.length?this.clone().ixor(m):m.clone().ixor(this)},a.prototype.uxor=function(m){return this.length>m.length?this.clone().iuxor(m):m.clone().iuxor(this)},a.prototype.inotn=function(m){i(typeof m=="number"&&m>=0);var c=Math.ceil(m/26)|0,h=m%26;this._expand(c),h>0&&c--;for(var v=0;v0&&(this.words[v]=~this.words[v]&67108863>>26-h),this.strip()},a.prototype.notn=function(m){return this.clone().inotn(m)},a.prototype.setn=function(m,c){i(typeof m=="number"&&m>=0);var h=m/26|0,v=m%26;return this._expand(h+1),c?this.words[h]=this.words[h]|1<m.length?(h=this,v=m):(h=m,v=this);for(var _=0,I=0;I>>26;for(;_!==0&&I>>26;if(this.length=h.length,_!==0)this.words[this.length]=_,this.length++;else if(h!==this)for(;Im.length?this.clone().iadd(m):m.clone().iadd(this)},a.prototype.isub=function(m){if(m.negative!==0){m.negative=0;var c=this.iadd(m);return m.negative=1,c._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(m),this.negative=1,this._normSign();var h=this.cmp(m);if(h===0)return this.negative=0,this.length=1,this.words[0]=0,this;var v,_;h>0?(v=this,_=m):(v=m,_=this);for(var I=0,M=0;M<_.length;M++)c=(v.words[M]|0)-(_.words[M]|0)+I,I=c>>26,this.words[M]=c&67108863;for(;I!==0&&M>26,this.words[M]=c&67108863;if(I===0&&M>>26,T=S&67108863,Z=Math.min(d,m.length-1),se=Math.max(0,d-F.length+1);se<=Z;se++){var P=d-se|0;v=F.words[P]|0,_=m.words[se]|0,I=v*_+T,g+=I/67108864|0,T=I&67108863}c.words[d]=T|0,S=g|0}return S!==0?c.words[d]=S|0:c.length--,c.strip()}var K=function(m,c,h){var v=m.words,_=c.words,I=h.words,M=0,S,d,g,T=v[0]|0,Z=T&8191,se=T>>>13,P=v[1]|0,ee=P&8191,q=P>>>13,z=v[2]|0,H=z&8191,w=z>>>13,$=v[3]|0,ne=$&8191,ce=$>>>13,he=v[4]|0,ye=he&8191,we=he>>>13,Ce=v[5]|0,Qe=Ce&8191,Oe=Ce>>>13,Te=v[6]|0,Ie=Te&8191,me=Te>>>13,Re=v[7]|0,De=Re&8191,ve=Re>>>13,Ne=v[8]|0,Se=Ne&8191,be=Ne>>>13,Le=v[9]|0,Me=Le&8191,_e=Le>>>13,He=_[0]|0,Ve=He&8191,Ee=He>>>13,Ke=_[1]|0,ut=Ke&8191,Ge=Ke>>>13,_t=_[2]|0,lt=_t&8191,Je=_t>>>13,Et=_[3]|0,It=Et&8191,Fe=Et>>>13,Xe=_[4]|0,tt=Xe&8191,Be=Xe>>>13,et=_[5]|0,Ze=et&8191,$e=et>>>13,ft=_[6]|0,rt=ft&8191,ze=ft>>>13,it=_[7]|0,st=it&8191,qe=it>>>13,Ye=_[8]|0,ht=Ye&8191,je=Ye>>>13,Tt=_[9]|0,Dt=Tt&8191,at=Tt>>>13;h.negative=m.negative^c.negative,h.length=19,S=Math.imul(Z,Ve),d=Math.imul(Z,Ee),d=d+Math.imul(se,Ve)|0,g=Math.imul(se,Ee);var bt=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(bt>>>26)|0,bt&=67108863,S=Math.imul(ee,Ve),d=Math.imul(ee,Ee),d=d+Math.imul(q,Ve)|0,g=Math.imul(q,Ee),S=S+Math.imul(Z,ut)|0,d=d+Math.imul(Z,Ge)|0,d=d+Math.imul(se,ut)|0,g=g+Math.imul(se,Ge)|0;var Cr=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Cr>>>26)|0,Cr&=67108863,S=Math.imul(H,Ve),d=Math.imul(H,Ee),d=d+Math.imul(w,Ve)|0,g=Math.imul(w,Ee),S=S+Math.imul(ee,ut)|0,d=d+Math.imul(ee,Ge)|0,d=d+Math.imul(q,ut)|0,g=g+Math.imul(q,Ge)|0,S=S+Math.imul(Z,lt)|0,d=d+Math.imul(Z,Je)|0,d=d+Math.imul(se,lt)|0,g=g+Math.imul(se,Je)|0;var Tr=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Tr>>>26)|0,Tr&=67108863,S=Math.imul(ne,Ve),d=Math.imul(ne,Ee),d=d+Math.imul(ce,Ve)|0,g=Math.imul(ce,Ee),S=S+Math.imul(H,ut)|0,d=d+Math.imul(H,Ge)|0,d=d+Math.imul(w,ut)|0,g=g+Math.imul(w,Ge)|0,S=S+Math.imul(ee,lt)|0,d=d+Math.imul(ee,Je)|0,d=d+Math.imul(q,lt)|0,g=g+Math.imul(q,Je)|0,S=S+Math.imul(Z,It)|0,d=d+Math.imul(Z,Fe)|0,d=d+Math.imul(se,It)|0,g=g+Math.imul(se,Fe)|0;var Dr=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Dr>>>26)|0,Dr&=67108863,S=Math.imul(ye,Ve),d=Math.imul(ye,Ee),d=d+Math.imul(we,Ve)|0,g=Math.imul(we,Ee),S=S+Math.imul(ne,ut)|0,d=d+Math.imul(ne,Ge)|0,d=d+Math.imul(ce,ut)|0,g=g+Math.imul(ce,Ge)|0,S=S+Math.imul(H,lt)|0,d=d+Math.imul(H,Je)|0,d=d+Math.imul(w,lt)|0,g=g+Math.imul(w,Je)|0,S=S+Math.imul(ee,It)|0,d=d+Math.imul(ee,Fe)|0,d=d+Math.imul(q,It)|0,g=g+Math.imul(q,Fe)|0,S=S+Math.imul(Z,tt)|0,d=d+Math.imul(Z,Be)|0,d=d+Math.imul(se,tt)|0,g=g+Math.imul(se,Be)|0;var Fr=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,S=Math.imul(Qe,Ve),d=Math.imul(Qe,Ee),d=d+Math.imul(Oe,Ve)|0,g=Math.imul(Oe,Ee),S=S+Math.imul(ye,ut)|0,d=d+Math.imul(ye,Ge)|0,d=d+Math.imul(we,ut)|0,g=g+Math.imul(we,Ge)|0,S=S+Math.imul(ne,lt)|0,d=d+Math.imul(ne,Je)|0,d=d+Math.imul(ce,lt)|0,g=g+Math.imul(ce,Je)|0,S=S+Math.imul(H,It)|0,d=d+Math.imul(H,Fe)|0,d=d+Math.imul(w,It)|0,g=g+Math.imul(w,Fe)|0,S=S+Math.imul(ee,tt)|0,d=d+Math.imul(ee,Be)|0,d=d+Math.imul(q,tt)|0,g=g+Math.imul(q,Be)|0,S=S+Math.imul(Z,Ze)|0,d=d+Math.imul(Z,$e)|0,d=d+Math.imul(se,Ze)|0,g=g+Math.imul(se,$e)|0;var Br=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Br>>>26)|0,Br&=67108863,S=Math.imul(Ie,Ve),d=Math.imul(Ie,Ee),d=d+Math.imul(me,Ve)|0,g=Math.imul(me,Ee),S=S+Math.imul(Qe,ut)|0,d=d+Math.imul(Qe,Ge)|0,d=d+Math.imul(Oe,ut)|0,g=g+Math.imul(Oe,Ge)|0,S=S+Math.imul(ye,lt)|0,d=d+Math.imul(ye,Je)|0,d=d+Math.imul(we,lt)|0,g=g+Math.imul(we,Je)|0,S=S+Math.imul(ne,It)|0,d=d+Math.imul(ne,Fe)|0,d=d+Math.imul(ce,It)|0,g=g+Math.imul(ce,Fe)|0,S=S+Math.imul(H,tt)|0,d=d+Math.imul(H,Be)|0,d=d+Math.imul(w,tt)|0,g=g+Math.imul(w,Be)|0,S=S+Math.imul(ee,Ze)|0,d=d+Math.imul(ee,$e)|0,d=d+Math.imul(q,Ze)|0,g=g+Math.imul(q,$e)|0,S=S+Math.imul(Z,rt)|0,d=d+Math.imul(Z,ze)|0,d=d+Math.imul(se,rt)|0,g=g+Math.imul(se,ze)|0;var er=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(er>>>26)|0,er&=67108863,S=Math.imul(De,Ve),d=Math.imul(De,Ee),d=d+Math.imul(ve,Ve)|0,g=Math.imul(ve,Ee),S=S+Math.imul(Ie,ut)|0,d=d+Math.imul(Ie,Ge)|0,d=d+Math.imul(me,ut)|0,g=g+Math.imul(me,Ge)|0,S=S+Math.imul(Qe,lt)|0,d=d+Math.imul(Qe,Je)|0,d=d+Math.imul(Oe,lt)|0,g=g+Math.imul(Oe,Je)|0,S=S+Math.imul(ye,It)|0,d=d+Math.imul(ye,Fe)|0,d=d+Math.imul(we,It)|0,g=g+Math.imul(we,Fe)|0,S=S+Math.imul(ne,tt)|0,d=d+Math.imul(ne,Be)|0,d=d+Math.imul(ce,tt)|0,g=g+Math.imul(ce,Be)|0,S=S+Math.imul(H,Ze)|0,d=d+Math.imul(H,$e)|0,d=d+Math.imul(w,Ze)|0,g=g+Math.imul(w,$e)|0,S=S+Math.imul(ee,rt)|0,d=d+Math.imul(ee,ze)|0,d=d+Math.imul(q,rt)|0,g=g+Math.imul(q,ze)|0,S=S+Math.imul(Z,st)|0,d=d+Math.imul(Z,qe)|0,d=d+Math.imul(se,st)|0,g=g+Math.imul(se,qe)|0;var Qr=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,S=Math.imul(Se,Ve),d=Math.imul(Se,Ee),d=d+Math.imul(be,Ve)|0,g=Math.imul(be,Ee),S=S+Math.imul(De,ut)|0,d=d+Math.imul(De,Ge)|0,d=d+Math.imul(ve,ut)|0,g=g+Math.imul(ve,Ge)|0,S=S+Math.imul(Ie,lt)|0,d=d+Math.imul(Ie,Je)|0,d=d+Math.imul(me,lt)|0,g=g+Math.imul(me,Je)|0,S=S+Math.imul(Qe,It)|0,d=d+Math.imul(Qe,Fe)|0,d=d+Math.imul(Oe,It)|0,g=g+Math.imul(Oe,Fe)|0,S=S+Math.imul(ye,tt)|0,d=d+Math.imul(ye,Be)|0,d=d+Math.imul(we,tt)|0,g=g+Math.imul(we,Be)|0,S=S+Math.imul(ne,Ze)|0,d=d+Math.imul(ne,$e)|0,d=d+Math.imul(ce,Ze)|0,g=g+Math.imul(ce,$e)|0,S=S+Math.imul(H,rt)|0,d=d+Math.imul(H,ze)|0,d=d+Math.imul(w,rt)|0,g=g+Math.imul(w,ze)|0,S=S+Math.imul(ee,st)|0,d=d+Math.imul(ee,qe)|0,d=d+Math.imul(q,st)|0,g=g+Math.imul(q,qe)|0,S=S+Math.imul(Z,ht)|0,d=d+Math.imul(Z,je)|0,d=d+Math.imul(se,ht)|0,g=g+Math.imul(se,je)|0;var Gi=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Gi>>>26)|0,Gi&=67108863,S=Math.imul(Me,Ve),d=Math.imul(Me,Ee),d=d+Math.imul(_e,Ve)|0,g=Math.imul(_e,Ee),S=S+Math.imul(Se,ut)|0,d=d+Math.imul(Se,Ge)|0,d=d+Math.imul(be,ut)|0,g=g+Math.imul(be,Ge)|0,S=S+Math.imul(De,lt)|0,d=d+Math.imul(De,Je)|0,d=d+Math.imul(ve,lt)|0,g=g+Math.imul(ve,Je)|0,S=S+Math.imul(Ie,It)|0,d=d+Math.imul(Ie,Fe)|0,d=d+Math.imul(me,It)|0,g=g+Math.imul(me,Fe)|0,S=S+Math.imul(Qe,tt)|0,d=d+Math.imul(Qe,Be)|0,d=d+Math.imul(Oe,tt)|0,g=g+Math.imul(Oe,Be)|0,S=S+Math.imul(ye,Ze)|0,d=d+Math.imul(ye,$e)|0,d=d+Math.imul(we,Ze)|0,g=g+Math.imul(we,$e)|0,S=S+Math.imul(ne,rt)|0,d=d+Math.imul(ne,ze)|0,d=d+Math.imul(ce,rt)|0,g=g+Math.imul(ce,ze)|0,S=S+Math.imul(H,st)|0,d=d+Math.imul(H,qe)|0,d=d+Math.imul(w,st)|0,g=g+Math.imul(w,qe)|0,S=S+Math.imul(ee,ht)|0,d=d+Math.imul(ee,je)|0,d=d+Math.imul(q,ht)|0,g=g+Math.imul(q,je)|0,S=S+Math.imul(Z,Dt)|0,d=d+Math.imul(Z,at)|0,d=d+Math.imul(se,Dt)|0,g=g+Math.imul(se,at)|0;var Xr=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Xr>>>26)|0,Xr&=67108863,S=Math.imul(Me,ut),d=Math.imul(Me,Ge),d=d+Math.imul(_e,ut)|0,g=Math.imul(_e,Ge),S=S+Math.imul(Se,lt)|0,d=d+Math.imul(Se,Je)|0,d=d+Math.imul(be,lt)|0,g=g+Math.imul(be,Je)|0,S=S+Math.imul(De,It)|0,d=d+Math.imul(De,Fe)|0,d=d+Math.imul(ve,It)|0,g=g+Math.imul(ve,Fe)|0,S=S+Math.imul(Ie,tt)|0,d=d+Math.imul(Ie,Be)|0,d=d+Math.imul(me,tt)|0,g=g+Math.imul(me,Be)|0,S=S+Math.imul(Qe,Ze)|0,d=d+Math.imul(Qe,$e)|0,d=d+Math.imul(Oe,Ze)|0,g=g+Math.imul(Oe,$e)|0,S=S+Math.imul(ye,rt)|0,d=d+Math.imul(ye,ze)|0,d=d+Math.imul(we,rt)|0,g=g+Math.imul(we,ze)|0,S=S+Math.imul(ne,st)|0,d=d+Math.imul(ne,qe)|0,d=d+Math.imul(ce,st)|0,g=g+Math.imul(ce,qe)|0,S=S+Math.imul(H,ht)|0,d=d+Math.imul(H,je)|0,d=d+Math.imul(w,ht)|0,g=g+Math.imul(w,je)|0,S=S+Math.imul(ee,Dt)|0,d=d+Math.imul(ee,at)|0,d=d+Math.imul(q,Dt)|0,g=g+Math.imul(q,at)|0;var Wi=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Wi>>>26)|0,Wi&=67108863,S=Math.imul(Me,lt),d=Math.imul(Me,Je),d=d+Math.imul(_e,lt)|0,g=Math.imul(_e,Je),S=S+Math.imul(Se,It)|0,d=d+Math.imul(Se,Fe)|0,d=d+Math.imul(be,It)|0,g=g+Math.imul(be,Fe)|0,S=S+Math.imul(De,tt)|0,d=d+Math.imul(De,Be)|0,d=d+Math.imul(ve,tt)|0,g=g+Math.imul(ve,Be)|0,S=S+Math.imul(Ie,Ze)|0,d=d+Math.imul(Ie,$e)|0,d=d+Math.imul(me,Ze)|0,g=g+Math.imul(me,$e)|0,S=S+Math.imul(Qe,rt)|0,d=d+Math.imul(Qe,ze)|0,d=d+Math.imul(Oe,rt)|0,g=g+Math.imul(Oe,ze)|0,S=S+Math.imul(ye,st)|0,d=d+Math.imul(ye,qe)|0,d=d+Math.imul(we,st)|0,g=g+Math.imul(we,qe)|0,S=S+Math.imul(ne,ht)|0,d=d+Math.imul(ne,je)|0,d=d+Math.imul(ce,ht)|0,g=g+Math.imul(ce,je)|0,S=S+Math.imul(H,Dt)|0,d=d+Math.imul(H,at)|0,d=d+Math.imul(w,Dt)|0,g=g+Math.imul(w,at)|0;var Ji=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Ji>>>26)|0,Ji&=67108863,S=Math.imul(Me,It),d=Math.imul(Me,Fe),d=d+Math.imul(_e,It)|0,g=Math.imul(_e,Fe),S=S+Math.imul(Se,tt)|0,d=d+Math.imul(Se,Be)|0,d=d+Math.imul(be,tt)|0,g=g+Math.imul(be,Be)|0,S=S+Math.imul(De,Ze)|0,d=d+Math.imul(De,$e)|0,d=d+Math.imul(ve,Ze)|0,g=g+Math.imul(ve,$e)|0,S=S+Math.imul(Ie,rt)|0,d=d+Math.imul(Ie,ze)|0,d=d+Math.imul(me,rt)|0,g=g+Math.imul(me,ze)|0,S=S+Math.imul(Qe,st)|0,d=d+Math.imul(Qe,qe)|0,d=d+Math.imul(Oe,st)|0,g=g+Math.imul(Oe,qe)|0,S=S+Math.imul(ye,ht)|0,d=d+Math.imul(ye,je)|0,d=d+Math.imul(we,ht)|0,g=g+Math.imul(we,je)|0,S=S+Math.imul(ne,Dt)|0,d=d+Math.imul(ne,at)|0,d=d+Math.imul(ce,Dt)|0,g=g+Math.imul(ce,at)|0;var Zr=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Zr>>>26)|0,Zr&=67108863,S=Math.imul(Me,tt),d=Math.imul(Me,Be),d=d+Math.imul(_e,tt)|0,g=Math.imul(_e,Be),S=S+Math.imul(Se,Ze)|0,d=d+Math.imul(Se,$e)|0,d=d+Math.imul(be,Ze)|0,g=g+Math.imul(be,$e)|0,S=S+Math.imul(De,rt)|0,d=d+Math.imul(De,ze)|0,d=d+Math.imul(ve,rt)|0,g=g+Math.imul(ve,ze)|0,S=S+Math.imul(Ie,st)|0,d=d+Math.imul(Ie,qe)|0,d=d+Math.imul(me,st)|0,g=g+Math.imul(me,qe)|0,S=S+Math.imul(Qe,ht)|0,d=d+Math.imul(Qe,je)|0,d=d+Math.imul(Oe,ht)|0,g=g+Math.imul(Oe,je)|0,S=S+Math.imul(ye,Dt)|0,d=d+Math.imul(ye,at)|0,d=d+Math.imul(we,Dt)|0,g=g+Math.imul(we,at)|0;var Si=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Si>>>26)|0,Si&=67108863,S=Math.imul(Me,Ze),d=Math.imul(Me,$e),d=d+Math.imul(_e,Ze)|0,g=Math.imul(_e,$e),S=S+Math.imul(Se,rt)|0,d=d+Math.imul(Se,ze)|0,d=d+Math.imul(be,rt)|0,g=g+Math.imul(be,ze)|0,S=S+Math.imul(De,st)|0,d=d+Math.imul(De,qe)|0,d=d+Math.imul(ve,st)|0,g=g+Math.imul(ve,qe)|0,S=S+Math.imul(Ie,ht)|0,d=d+Math.imul(Ie,je)|0,d=d+Math.imul(me,ht)|0,g=g+Math.imul(me,je)|0,S=S+Math.imul(Qe,Dt)|0,d=d+Math.imul(Qe,at)|0,d=d+Math.imul(Oe,Dt)|0,g=g+Math.imul(Oe,at)|0;var Ii=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Ii>>>26)|0,Ii&=67108863,S=Math.imul(Me,rt),d=Math.imul(Me,ze),d=d+Math.imul(_e,rt)|0,g=Math.imul(_e,ze),S=S+Math.imul(Se,st)|0,d=d+Math.imul(Se,qe)|0,d=d+Math.imul(be,st)|0,g=g+Math.imul(be,qe)|0,S=S+Math.imul(De,ht)|0,d=d+Math.imul(De,je)|0,d=d+Math.imul(ve,ht)|0,g=g+Math.imul(ve,je)|0,S=S+Math.imul(Ie,Dt)|0,d=d+Math.imul(Ie,at)|0,d=d+Math.imul(me,Dt)|0,g=g+Math.imul(me,at)|0;var lr=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(lr>>>26)|0,lr&=67108863,S=Math.imul(Me,st),d=Math.imul(Me,qe),d=d+Math.imul(_e,st)|0,g=Math.imul(_e,qe),S=S+Math.imul(Se,ht)|0,d=d+Math.imul(Se,je)|0,d=d+Math.imul(be,ht)|0,g=g+Math.imul(be,je)|0,S=S+Math.imul(De,Dt)|0,d=d+Math.imul(De,at)|0,d=d+Math.imul(ve,Dt)|0,g=g+Math.imul(ve,at)|0;var Yi=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Yi>>>26)|0,Yi&=67108863,S=Math.imul(Me,ht),d=Math.imul(Me,je),d=d+Math.imul(_e,ht)|0,g=Math.imul(_e,je),S=S+Math.imul(Se,Dt)|0,d=d+Math.imul(Se,at)|0,d=d+Math.imul(be,Dt)|0,g=g+Math.imul(be,at)|0;var Qi=(M+S|0)+((d&8191)<<13)|0;M=(g+(d>>>13)|0)+(Qi>>>26)|0,Qi&=67108863,S=Math.imul(Me,Dt),d=Math.imul(Me,at),d=d+Math.imul(_e,Dt)|0,g=Math.imul(_e,at);var Xi=(M+S|0)+((d&8191)<<13)|0;return M=(g+(d>>>13)|0)+(Xi>>>26)|0,Xi&=67108863,I[0]=bt,I[1]=Cr,I[2]=Tr,I[3]=Dr,I[4]=Fr,I[5]=Br,I[6]=er,I[7]=Qr,I[8]=Gi,I[9]=Xr,I[10]=Wi,I[11]=Ji,I[12]=Zr,I[13]=Si,I[14]=Ii,I[15]=lr,I[16]=Yi,I[17]=Qi,I[18]=Xi,M!==0&&(I[19]=M,h.length++),h};Math.imul||(K=N);function W(F,m,c){c.negative=m.negative^F.negative,c.length=F.length+m.length;for(var h=0,v=0,_=0;_>>26)|0,v+=I>>>26,I&=67108863}c.words[_]=M,h=I,I=v}return h!==0?c.words[_]=h:c.length--,c.strip()}function Q(F,m,c){var h=new j;return h.mulp(F,m,c)}a.prototype.mulTo=function(m,c){var h,v=this.length+m.length;return this.length===10&&m.length===10?h=K(this,m,c):v<63?h=N(this,m,c):v<1024?h=W(this,m,c):h=Q(this,m,c),h};function j(F,m){this.x=F,this.y=m}j.prototype.makeRBT=function(m){for(var c=new Array(m),h=a.prototype._countBits(m)-1,v=0;v>=1;return v},j.prototype.permute=function(m,c,h,v,_,I){for(var M=0;M>>1)_++;return 1<<_+1+v},j.prototype.conjugate=function(m,c,h){if(!(h<=1))for(var v=0;v>>13,h[2*I+1]=_&8191,_=_>>>13;for(I=2*c;I>=26,c+=v/67108864|0,c+=_>>>26,this.words[h]=_&67108863}return c!==0&&(this.words[h]=c,this.length++),this},a.prototype.muln=function(m){return this.clone().imuln(m)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(m){var c=O(m);if(c.length===0)return new a(1);for(var h=this,v=0;v=0);var c=m%26,h=(m-c)/26,v=67108863>>>26-c<<26-c,_;if(c!==0){var I=0;for(_=0;_>>26-c}I&&(this.words[_]=I,this.length++)}if(h!==0){for(_=this.length-1;_>=0;_--)this.words[_+h]=this.words[_];for(_=0;_=0);var v;c?v=(c-c%26)/26:v=0;var _=m%26,I=Math.min((m-_)/26,this.length),M=67108863^67108863>>>_<<_,S=h;if(v-=I,v=Math.max(0,v),S){for(var d=0;dI)for(this.length-=I,d=0;d=0&&(g!==0||d>=v);d--){var T=this.words[d]|0;this.words[d]=g<<26-_|T>>>_,g=T&M}return S&&g!==0&&(S.words[S.length++]=g),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},a.prototype.ishrn=function(m,c,h){return i(this.negative===0),this.iushrn(m,c,h)},a.prototype.shln=function(m){return this.clone().ishln(m)},a.prototype.ushln=function(m){return this.clone().iushln(m)},a.prototype.shrn=function(m){return this.clone().ishrn(m)},a.prototype.ushrn=function(m){return this.clone().iushrn(m)},a.prototype.testn=function(m){i(typeof m=="number"&&m>=0);var c=m%26,h=(m-c)/26,v=1<=0);var c=m%26,h=(m-c)/26;if(i(this.negative===0,"imaskn works only with positive numbers"),this.length<=h)return this;if(c!==0&&h++,this.length=Math.min(h,this.length),c!==0){var v=67108863^67108863>>>c<=67108864;c++)this.words[c]-=67108864,c===this.length-1?this.words[c+1]=1:this.words[c+1]++;return this.length=Math.max(this.length,c+1),this},a.prototype.isubn=function(m){if(i(typeof m=="number"),i(m<67108864),m<0)return this.iaddn(-m);if(this.negative!==0)return this.negative=0,this.iaddn(m),this.negative=1,this;if(this.words[0]-=m,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var c=0;c>26)-(S/67108864|0),this.words[_+h]=I&67108863}for(;_>26,this.words[_+h]=I&67108863;if(M===0)return this.strip();for(i(M===-1),M=0,_=0;_>26,this.words[_]=I&67108863;return this.negative=1,this.strip()},a.prototype._wordDiv=function(m,c){var h=this.length-m.length,v=this.clone(),_=m,I=_.words[_.length-1]|0,M=this._countBits(I);h=26-M,h!==0&&(_=_.ushln(h),v.iushln(h),I=_.words[_.length-1]|0);var S=v.length-_.length,d;if(c!=="mod"){d=new a(null),d.length=S+1,d.words=new Array(d.length);for(var g=0;g=0;Z--){var se=(v.words[_.length+Z]|0)*67108864+(v.words[_.length+Z-1]|0);for(se=Math.min(se/I|0,67108863),v._ishlnsubmul(_,se,Z);v.negative!==0;)se--,v.negative=0,v._ishlnsubmul(_,1,Z),v.isZero()||(v.negative^=1);d&&(d.words[Z]=se)}return d&&d.strip(),v.strip(),c!=="div"&&h!==0&&v.iushrn(h),{div:d||null,mod:v}},a.prototype.divmod=function(m,c,h){if(i(!m.isZero()),this.isZero())return{div:new a(0),mod:new a(0)};var v,_,I;return this.negative!==0&&m.negative===0?(I=this.neg().divmod(m,c),c!=="mod"&&(v=I.div.neg()),c!=="div"&&(_=I.mod.neg(),h&&_.negative!==0&&_.iadd(m)),{div:v,mod:_}):this.negative===0&&m.negative!==0?(I=this.divmod(m.neg(),c),c!=="mod"&&(v=I.div.neg()),{div:v,mod:I.mod}):this.negative&m.negative?(I=this.neg().divmod(m.neg(),c),c!=="div"&&(_=I.mod.neg(),h&&_.negative!==0&&_.isub(m)),{div:I.div,mod:_}):m.length>this.length||this.cmp(m)<0?{div:new a(0),mod:this}:m.length===1?c==="div"?{div:this.divn(m.words[0]),mod:null}:c==="mod"?{div:null,mod:new a(this.modn(m.words[0]))}:{div:this.divn(m.words[0]),mod:new a(this.modn(m.words[0]))}:this._wordDiv(m,c)},a.prototype.div=function(m){return this.divmod(m,"div",!1).div},a.prototype.mod=function(m){return this.divmod(m,"mod",!1).mod},a.prototype.umod=function(m){return this.divmod(m,"mod",!0).mod},a.prototype.divRound=function(m){var c=this.divmod(m);if(c.mod.isZero())return c.div;var h=c.div.negative!==0?c.mod.isub(m):c.mod,v=m.ushrn(1),_=m.andln(1),I=h.cmp(v);return I<0||_===1&&I===0?c.div:c.div.negative!==0?c.div.isubn(1):c.div.iaddn(1)},a.prototype.modn=function(m){i(m<=67108863);for(var c=(1<<26)%m,h=0,v=this.length-1;v>=0;v--)h=(c*h+(this.words[v]|0))%m;return h},a.prototype.idivn=function(m){i(m<=67108863);for(var c=0,h=this.length-1;h>=0;h--){var v=(this.words[h]|0)+c*67108864;this.words[h]=v/m|0,c=v%m}return this.strip()},a.prototype.divn=function(m){return this.clone().idivn(m)},a.prototype.egcd=function(m){i(m.negative===0),i(!m.isZero());var c=this,h=m.clone();c.negative!==0?c=c.umod(m):c=c.clone();for(var v=new a(1),_=new a(0),I=new a(0),M=new a(1),S=0;c.isEven()&&h.isEven();)c.iushrn(1),h.iushrn(1),++S;for(var d=h.clone(),g=c.clone();!c.isZero();){for(var T=0,Z=1;!(c.words[0]&Z)&&T<26;++T,Z<<=1);if(T>0)for(c.iushrn(T);T-- >0;)(v.isOdd()||_.isOdd())&&(v.iadd(d),_.isub(g)),v.iushrn(1),_.iushrn(1);for(var se=0,P=1;!(h.words[0]&P)&&se<26;++se,P<<=1);if(se>0)for(h.iushrn(se);se-- >0;)(I.isOdd()||M.isOdd())&&(I.iadd(d),M.isub(g)),I.iushrn(1),M.iushrn(1);c.cmp(h)>=0?(c.isub(h),v.isub(I),_.isub(M)):(h.isub(c),I.isub(v),M.isub(_))}return{a:I,b:M,gcd:h.iushln(S)}},a.prototype._invmp=function(m){i(m.negative===0),i(!m.isZero());var c=this,h=m.clone();c.negative!==0?c=c.umod(m):c=c.clone();for(var v=new a(1),_=new a(0),I=h.clone();c.cmpn(1)>0&&h.cmpn(1)>0;){for(var M=0,S=1;!(c.words[0]&S)&&M<26;++M,S<<=1);if(M>0)for(c.iushrn(M);M-- >0;)v.isOdd()&&v.iadd(I),v.iushrn(1);for(var d=0,g=1;!(h.words[0]&g)&&d<26;++d,g<<=1);if(d>0)for(h.iushrn(d);d-- >0;)_.isOdd()&&_.iadd(I),_.iushrn(1);c.cmp(h)>=0?(c.isub(h),v.isub(_)):(h.isub(c),_.isub(v))}var T;return c.cmpn(1)===0?T=v:T=_,T.cmpn(0)<0&&T.iadd(m),T},a.prototype.gcd=function(m){if(this.isZero())return m.abs();if(m.isZero())return this.abs();var c=this.clone(),h=m.clone();c.negative=0,h.negative=0;for(var v=0;c.isEven()&&h.isEven();v++)c.iushrn(1),h.iushrn(1);do{for(;c.isEven();)c.iushrn(1);for(;h.isEven();)h.iushrn(1);var _=c.cmp(h);if(_<0){var I=c;c=h,h=I}else if(_===0||h.cmpn(1)===0)break;c.isub(h)}while(!0);return h.iushln(v)},a.prototype.invm=function(m){return this.egcd(m).a.umod(m)},a.prototype.isEven=function(){return(this.words[0]&1)===0},a.prototype.isOdd=function(){return(this.words[0]&1)===1},a.prototype.andln=function(m){return this.words[0]&m},a.prototype.bincn=function(m){i(typeof m=="number");var c=m%26,h=(m-c)/26,v=1<>>26,M&=67108863,this.words[I]=M}return _!==0&&(this.words[I]=_,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(m){var c=m<0;if(this.negative!==0&&!c)return-1;if(this.negative===0&&c)return 1;this.strip();var h;if(this.length>1)h=1;else{c&&(m=-m),i(m<=67108863,"Number is too big");var v=this.words[0]|0;h=v===m?0:vm.length)return 1;if(this.length=0;h--){var v=this.words[h]|0,_=m.words[h]|0;if(v!==_){v<_?c=-1:v>_&&(c=1);break}}return c},a.prototype.gtn=function(m){return this.cmpn(m)===1},a.prototype.gt=function(m){return this.cmp(m)===1},a.prototype.gten=function(m){return this.cmpn(m)>=0},a.prototype.gte=function(m){return this.cmp(m)>=0},a.prototype.ltn=function(m){return this.cmpn(m)===-1},a.prototype.lt=function(m){return this.cmp(m)===-1},a.prototype.lten=function(m){return this.cmpn(m)<=0},a.prototype.lte=function(m){return this.cmp(m)<=0},a.prototype.eqn=function(m){return this.cmpn(m)===0},a.prototype.eq=function(m){return this.cmp(m)===0},a.red=function(m){return new ae(m)},a.prototype.toRed=function(m){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),m.convertTo(this)._forceRed(m)},a.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(m){return this.red=m,this},a.prototype.forceRed=function(m){return i(!this.red,"Already a number in reduction context"),this._forceRed(m)},a.prototype.redAdd=function(m){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,m)},a.prototype.redIAdd=function(m){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,m)},a.prototype.redSub=function(m){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,m)},a.prototype.redISub=function(m){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,m)},a.prototype.redShl=function(m){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,m)},a.prototype.redMul=function(m){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,m),this.red.mul(this,m)},a.prototype.redIMul=function(m){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,m),this.red.imul(this,m)},a.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(m){return i(this.red&&!m.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,m)};var Y={k256:null,p224:null,p192:null,p25519:null};function U(F,m){this.name=F,this.p=new a(m,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}U.prototype._tmp=function(){var m=new a(null);return m.words=new Array(Math.ceil(this.n/13)),m},U.prototype.ireduce=function(m){var c=m,h;do this.split(c,this.tmp),c=this.imulK(c),c=c.iadd(this.tmp),h=c.bitLength();while(h>this.n);var v=h0?c.isub(this.p):c.strip!==void 0?c.strip():c._strip(),c},U.prototype.split=function(m,c){m.iushrn(this.n,0,c)},U.prototype.imulK=function(m){return m.imul(this.k)};function k(){U.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(k,U),k.prototype.split=function(m,c){for(var h=4194303,v=Math.min(m.length,9),_=0;_>>22,I=M}I>>>=22,m.words[_-10]=I,I===0&&m.length>10?m.length-=10:m.length-=9},k.prototype.imulK=function(m){m.words[m.length]=0,m.words[m.length+1]=0,m.length+=2;for(var c=0,h=0;h>>=26,m.words[h]=_,c=v}return c!==0&&(m.words[m.length++]=c),m},a._prime=function(m){if(Y[m])return Y[m];var c;if(m==="k256")c=new k;else if(m==="p224")c=new G;else if(m==="p192")c=new x;else if(m==="p25519")c=new B;else throw new Error("Unknown prime "+m);return Y[m]=c,c};function ae(F){if(typeof F=="string"){var m=a._prime(F);this.m=m.p,this.prime=m}else i(F.gtn(1),"modulus must be greater than 1"),this.m=F,this.prime=null}ae.prototype._verify1=function(m){i(m.negative===0,"red works only with positives"),i(m.red,"red works only with red numbers")},ae.prototype._verify2=function(m,c){i((m.negative|c.negative)===0,"red works only with positives"),i(m.red&&m.red===c.red,"red works only with red numbers")},ae.prototype.imod=function(m){return this.prime?this.prime.ireduce(m)._forceRed(this):m.umod(this.m)._forceRed(this)},ae.prototype.neg=function(m){return m.isZero()?m.clone():this.m.sub(m)._forceRed(this)},ae.prototype.add=function(m,c){this._verify2(m,c);var h=m.add(c);return h.cmp(this.m)>=0&&h.isub(this.m),h._forceRed(this)},ae.prototype.iadd=function(m,c){this._verify2(m,c);var h=m.iadd(c);return h.cmp(this.m)>=0&&h.isub(this.m),h},ae.prototype.sub=function(m,c){this._verify2(m,c);var h=m.sub(c);return h.cmpn(0)<0&&h.iadd(this.m),h._forceRed(this)},ae.prototype.isub=function(m,c){this._verify2(m,c);var h=m.isub(c);return h.cmpn(0)<0&&h.iadd(this.m),h},ae.prototype.shl=function(m,c){return this._verify1(m),this.imod(m.ushln(c))},ae.prototype.imul=function(m,c){return this._verify2(m,c),this.imod(m.imul(c))},ae.prototype.mul=function(m,c){return this._verify2(m,c),this.imod(m.mul(c))},ae.prototype.isqr=function(m){return this.imul(m,m.clone())},ae.prototype.sqr=function(m){return this.mul(m,m)},ae.prototype.sqrt=function(m){if(m.isZero())return m.clone();var c=this.m.andln(3);if(i(c%2===1),c===3){var h=this.m.add(new a(1)).iushrn(2);return this.pow(m,h)}for(var v=this.m.subn(1),_=0;!v.isZero()&&v.andln(1)===0;)_++,v.iushrn(1);i(!v.isZero());var I=new a(1).toRed(this),M=I.redNeg(),S=this.m.subn(1).iushrn(1),d=this.m.bitLength();for(d=new a(2*d*d).toRed(this);this.pow(d,S).cmp(M)!==0;)d.redIAdd(M);for(var g=this.pow(d,v),T=this.pow(m,v.addn(1).iushrn(1)),Z=this.pow(m,v),se=_;Z.cmp(I)!==0;){for(var P=Z,ee=0;P.cmp(I)!==0;ee++)P=P.redSqr();i(ee=0;_--){for(var g=c.words[_],T=d-1;T>=0;T--){var Z=g>>T&1;if(I!==v[0]&&(I=this.sqr(I)),Z===0&&M===0){S=0;continue}M<<=1,M|=Z,S++,!(S!==h&&(_!==0||T!==0))&&(I=this.mul(I,v[M]),S=0,M=0)}d=26}return I},ae.prototype.convertTo=function(m){var c=m.umod(this.m);return c===m?c.clone():c},ae.prototype.convertFrom=function(m){var c=m.clone();return c.red=null,c},a.mont=function(m){return new le(m)};function le(F){ae.call(this,F),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}n(le,ae),le.prototype.convertTo=function(m){return this.imod(m.ushln(this.shift))},le.prototype.convertFrom=function(m){var c=this.imod(m.mul(this.rinv));return c.red=null,c},le.prototype.imul=function(m,c){if(m.isZero()||c.isZero())return m.words[0]=0,m.length=1,m;var h=m.imul(c),v=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=h.isub(v).iushrn(this.shift),I=_;return _.cmp(this.m)>=0?I=_.isub(this.m):_.cmpn(0)<0&&(I=_.iadd(this.m)),I._forceRed(this)},le.prototype.mul=function(m,c){if(m.isZero()||c.isZero())return new a(0)._forceRed(this);var h=m.mul(c),v=h.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),_=h.isub(v).iushrn(this.shift),I=_;return _.cmp(this.m)>=0?I=_.isub(this.m):_.cmpn(0)<0&&(I=_.iadd(this.m)),I._forceRed(this)},le.prototype.invm=function(m){var c=this.imod(m._invmp(this.m).mul(this.r2));return c._forceRed(this)}})(r,ji)})(T0);var bs=T0.exports,ya=Qv;function Qv(r,e){if(!r)throw new Error(e||"Assertion failed")}Qv.equal=function(e,t,i){if(e!=t)throw new Error(i||"Assertion failed: "+e+" != "+t)};var D0={};(function(r){var e=r;function t(a,f){if(Array.isArray(a))return a.slice();if(!a)return[];var u=[];if(typeof a!="string"){for(var b=0;b>8,A=p&255;y?u.push(y,A):u.push(A)}return u}e.toArray=t;function i(a){return a.length===1?"0"+a:a}e.zero2=i;function n(a){for(var f="",u=0;u(K>>1)-1?Q=(K>>1)-j:Q=j,W.isubn(Q)):Q=0,O[N]=Q,W.iushrn(1)}return O}e.getNAF=a;function f(y,A){var R=[[],[]];y=y.clone(),A=A.clone();for(var O=0,N=0,K;y.cmpn(-O)>0||A.cmpn(-N)>0;){var W=y.andln(3)+O&3,Q=A.andln(3)+N&3;W===3&&(W=-1),Q===3&&(Q=-1);var j;W&1?(K=y.andln(7)+O&7,(K===3||K===5)&&Q===2?j=-W:j=W):j=0,R[0].push(j);var Y;Q&1?(K=A.andln(7)+N&7,(K===3||K===5)&&W===2?Y=-Q:Y=Q):Y=0,R[1].push(Y),2*O===j+1&&(O=1-O),2*N===Y+1&&(N=1-N),y.iushrn(1),A.iushrn(1)}return R}e.getJSF=f;function u(y,A,R){var O="_"+A;y.prototype[A]=function(){return this[O]!==void 0?this[O]:this[O]=R.call(this)}}e.cachedProperty=u;function b(y){return typeof y=="string"?e.toArray(y,"hex"):y}e.parseBytes=b;function p(y){return new t(y,"hex","le")}e.intFromLE=p})(xi);var F0={exports:{}},fl;F0.exports=function(e){return fl||(fl=new Fs(null)),fl.generate(e)};function Fs(r){this.rand=r}F0.exports.Rand=Fs;Fs.prototype.generate=function(e){return this._rand(e)};Fs.prototype._rand=function(e){if(this.rand.getBytes)return this.rand.getBytes(e);for(var t=new Uint8Array(e),i=0;i0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var Nh=zs;zs.prototype.point=function(){throw new Error("Not implemented")};zs.prototype.validate=function(){throw new Error("Not implemented")};zs.prototype._fixedNafMul=function(e,t){fh(e.precomputed);var i=e._getDoubles(),n=ch(t,1,this._bitLength),a=(1<=u;p--)b=(b<<1)+n[p];f.push(b)}for(var y=this.jpoint(null,null,null),A=this.jpoint(null,null,null),R=a;R>0;R--){for(u=0;u=0;b--){for(var p=0;b>=0&&f[b]===0;b--)p++;if(b>=0&&p++,u=u.dblp(p),b<0)break;var y=f[b];fh(y!==0),e.type==="affine"?y>0?u=u.mixedAdd(a[y-1>>1]):u=u.mixedAdd(a[-y-1>>1].neg()):y>0?u=u.add(a[y-1>>1]):u=u.add(a[-y-1>>1].neg())}return e.type==="affine"?u.toP():u};zs.prototype._wnafMulAdd=function(e,t,i,n,a){var f=this._wnafT1,u=this._wnafT2,b=this._wnafT3,p=0,y,A,R;for(y=0;y=1;y-=2){var N=y-1,K=y;if(f[N]!==1||f[K]!==1){b[N]=ch(i[N],f[N],this._bitLength),b[K]=ch(i[K],f[K],this._bitLength),p=Math.max(b[N].length,p),p=Math.max(b[K].length,p);continue}var W=[t[N],null,null,t[K]];t[N].y.cmp(t[K].y)===0?(W[1]=t[N].add(t[K]),W[2]=t[N].toJ().mixedAdd(t[K].neg())):t[N].y.cmp(t[K].y.redNeg())===0?(W[1]=t[N].toJ().mixedAdd(t[K]),W[2]=t[N].add(t[K].neg())):(W[1]=t[N].toJ().mixedAdd(t[K]),W[2]=t[N].toJ().mixedAdd(t[K].neg()));var Q=[-3,-1,-5,-7,0,7,5,1,3],j=B_(i[N],i[K]);for(p=Math.max(j[0].length,p),b[N]=new Array(p),b[K]=new Array(p),A=0;A=0;y--){for(var x=0;y>=0;){var B=!0;for(A=0;A=0&&x++,k=k.dblp(x),y<0)break;for(A=0;A0?R=u[A][ae-1>>1]:ae<0&&(R=u[A][-ae-1>>1].neg()),R.type==="affine"?k=k.mixedAdd(R):k=k.add(R))}}for(y=0;y=Math.ceil((e.bitLength()+1)/t.step):!1};Ki.prototype._getDoubles=function(e,t){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var i=[this],n=this,a=0;a=0&&(O=p,N=y),A.negative&&(A=A.neg(),R=R.neg()),O.negative&&(O=O.neg(),N=N.neg()),[{a:A,b:R},{a:O,b:N}]};Vi.prototype._endoSplit=function(e){var t=this.endo.basis,i=t[0],n=t[1],a=n.b.mul(e).divRound(this.n),f=i.b.neg().mul(e).divRound(this.n),u=a.mul(i.a),b=f.mul(n.a),p=a.mul(i.b),y=f.mul(n.b),A=e.sub(u).sub(b),R=p.add(y).neg();return{k1:A,k2:R}};Vi.prototype.pointFromX=function(e,t){e=new nr(e,16),e.red||(e=e.toRed(this.red));var i=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),n=i.redSqrt();if(n.redSqr().redSub(i).cmp(this.zero)!==0)throw new Error("invalid point");var a=n.fromRed().isOdd();return(t&&!a||!t&&a)&&(n=n.redNeg()),this.point(e,n)};Vi.prototype.validate=function(e){if(e.inf)return!0;var t=e.x,i=e.y,n=this.a.redMul(t),a=t.redSqr().redMul(t).redIAdd(n).redIAdd(this.b);return i.redSqr().redISub(a).cmpn(0)===0};Vi.prototype._endoWnafMulAdd=function(e,t,i){for(var n=this._endoWnafT1,a=this._endoWnafT2,f=0;f":""};Ir.prototype.isInfinity=function(){return this.inf};Ir.prototype.add=function(e){if(this.inf)return e;if(e.inf)return this;if(this.eq(e))return this.dbl();if(this.neg().eq(e))return this.curve.point(null,null);if(this.x.cmp(e.x)===0)return this.curve.point(null,null);var t=this.y.redSub(e.y);t.cmpn(0)!==0&&(t=t.redMul(this.x.redSub(e.x).redInvm()));var i=t.redSqr().redISub(this.x).redISub(e.x),n=t.redMul(this.x.redSub(i)).redISub(this.y);return this.curve.point(i,n)};Ir.prototype.dbl=function(){if(this.inf)return this;var e=this.y.redAdd(this.y);if(e.cmpn(0)===0)return this.curve.point(null,null);var t=this.curve.a,i=this.x.redSqr(),n=e.redInvm(),a=i.redAdd(i).redIAdd(i).redIAdd(t).redMul(n),f=a.redSqr().redISub(this.x.redAdd(this.x)),u=a.redMul(this.x.redSub(f)).redISub(this.y);return this.curve.point(f,u)};Ir.prototype.getX=function(){return this.x.fromRed()};Ir.prototype.getY=function(){return this.y.fromRed()};Ir.prototype.mul=function(e){return e=new nr(e,16),this.isInfinity()?this:this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve.endo?this.curve._endoWnafMulAdd([this],[e]):this.curve._wnafMul(this,e)};Ir.prototype.mulAdd=function(e,t,i){var n=[this,t],a=[e,i];return this.curve.endo?this.curve._endoWnafMulAdd(n,a):this.curve._wnafMulAdd(1,n,a,2)};Ir.prototype.jmulAdd=function(e,t,i){var n=[this,t],a=[e,i];return this.curve.endo?this.curve._endoWnafMulAdd(n,a,!0):this.curve._wnafMulAdd(1,n,a,2,!0)};Ir.prototype.eq=function(e){return this===e||this.inf===e.inf&&(this.inf||this.x.cmp(e.x)===0&&this.y.cmp(e.y)===0)};Ir.prototype.neg=function(e){if(this.inf)return this;var t=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var i=this.precomputed,n=function(a){return a.neg()};t.precomputed={naf:i.naf&&{wnd:i.naf.wnd,points:i.naf.points.map(n)},doubles:i.doubles&&{step:i.doubles.step,points:i.doubles.points.map(n)}}}return t};Ir.prototype.toJ=function(){if(this.inf)return this.curve.jpoint(null,null,null);var e=this.curve.jpoint(this.x,this.y,this.curve.one);return e};function Rr(r,e,t,i){fo.BasePoint.call(this,r,"jacobian"),e===null&&t===null&&i===null?(this.x=this.curve.one,this.y=this.curve.one,this.z=new nr(0)):(this.x=new nr(e,16),this.y=new nr(t,16),this.z=new nr(i,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}q0(Rr,fo.BasePoint);Vi.prototype.jpoint=function(e,t,i){return new Rr(this,e,t,i)};Rr.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),t=e.redSqr(),i=this.x.redMul(t),n=this.y.redMul(t).redMul(e);return this.curve.point(i,n)};Rr.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)};Rr.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var t=e.z.redSqr(),i=this.z.redSqr(),n=this.x.redMul(t),a=e.x.redMul(i),f=this.y.redMul(t.redMul(e.z)),u=e.y.redMul(i.redMul(this.z)),b=n.redSub(a),p=f.redSub(u);if(b.cmpn(0)===0)return p.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var y=b.redSqr(),A=y.redMul(b),R=n.redMul(y),O=p.redSqr().redIAdd(A).redISub(R).redISub(R),N=p.redMul(R.redISub(O)).redISub(f.redMul(A)),K=this.z.redMul(e.z).redMul(b);return this.curve.jpoint(O,N,K)};Rr.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var t=this.z.redSqr(),i=this.x,n=e.x.redMul(t),a=this.y,f=e.y.redMul(t).redMul(this.z),u=i.redSub(n),b=a.redSub(f);if(u.cmpn(0)===0)return b.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var p=u.redSqr(),y=p.redMul(u),A=i.redMul(p),R=b.redSqr().redIAdd(y).redISub(A).redISub(A),O=b.redMul(A.redISub(R)).redISub(a.redMul(y)),N=this.z.redMul(u);return this.curve.jpoint(R,O,N)};Rr.prototype.dblp=function(e){if(e===0)return this;if(this.isInfinity())return this;if(!e)return this.dbl();var t;if(this.curve.zeroA||this.curve.threeA){var i=this;for(t=0;t=0)return!1;if(i.redIAdd(a),this.x.cmp(i)===0)return!0}};Rr.prototype.inspect=function(){return this.isInfinity()?"":""};Rr.prototype.isInfinity=function(){return this.z.cmpn(0)===0};var Xa=bs,Zv=xh,Ch=Nh,$_=xi;function ho(r){Ch.call(this,"mont",r),this.a=new Xa(r.a,16).toRed(this.red),this.b=new Xa(r.b,16).toRed(this.red),this.i4=new Xa(4).toRed(this.red).redInvm(),this.two=new Xa(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}Zv(ho,Ch);var z_=ho;ho.prototype.validate=function(e){var t=e.normalize().x,i=t.redSqr(),n=i.redMul(t).redAdd(i.redMul(this.a)).redAdd(t),a=n.redSqrt();return a.redSqr().cmp(n)===0};function Sr(r,e,t){Ch.BasePoint.call(this,r,"projective"),e===null&&t===null?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new Xa(e,16),this.z=new Xa(t,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}Zv(Sr,Ch.BasePoint);ho.prototype.decodePoint=function(e,t){return this.point($_.toArray(e,t),1)};ho.prototype.point=function(e,t){return new Sr(this,e,t)};ho.prototype.pointFromJSON=function(e){return Sr.fromJSON(this,e)};Sr.prototype.precompute=function(){};Sr.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())};Sr.fromJSON=function(e,t){return new Sr(e,t[0],t[1]||e.one)};Sr.prototype.inspect=function(){return this.isInfinity()?"":""};Sr.prototype.isInfinity=function(){return this.z.cmpn(0)===0};Sr.prototype.dbl=function(){var e=this.x.redAdd(this.z),t=e.redSqr(),i=this.x.redSub(this.z),n=i.redSqr(),a=t.redSub(n),f=t.redMul(n),u=a.redMul(n.redAdd(this.curve.a24.redMul(a)));return this.curve.point(f,u)};Sr.prototype.add=function(){throw new Error("Not supported on Montgomery curve")};Sr.prototype.diffAdd=function(e,t){var i=this.x.redAdd(this.z),n=this.x.redSub(this.z),a=e.x.redAdd(e.z),f=e.x.redSub(e.z),u=f.redMul(i),b=a.redMul(n),p=t.z.redMul(u.redAdd(b).redSqr()),y=t.x.redMul(u.redISub(b).redSqr());return this.curve.point(p,y)};Sr.prototype.mul=function(e){for(var t=e.clone(),i=this,n=this.curve.point(null,null),a=this,f=[];t.cmpn(0)!==0;t.iushrn(1))f.push(t.andln(1));for(var u=f.length-1;u>=0;u--)f[u]===0?(i=i.diffAdd(n,a),n=n.dbl()):(n=i.diffAdd(n,a),i=i.dbl());return n};Sr.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")};Sr.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")};Sr.prototype.eq=function(e){return this.getX().cmp(e.getX())===0};Sr.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this};Sr.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var j_=xi,ls=bs,eb=xh,Th=Nh,k_=j_.assert;function Hn(r){this.twisted=(r.a|0)!==1,this.mOneA=this.twisted&&(r.a|0)===-1,this.extended=this.mOneA,Th.call(this,"edwards",r),this.a=new ls(r.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new ls(r.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new ls(r.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),k_(!this.twisted||this.c.fromRed().cmpn(1)===0),this.oneC=(r.c|0)===1}eb(Hn,Th);var H_=Hn;Hn.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)};Hn.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)};Hn.prototype.jpoint=function(e,t,i,n){return this.point(e,t,i,n)};Hn.prototype.pointFromX=function(e,t){e=new ls(e,16),e.red||(e=e.toRed(this.red));var i=e.redSqr(),n=this.c2.redSub(this.a.redMul(i)),a=this.one.redSub(this.c2.redMul(this.d).redMul(i)),f=n.redMul(a.redInvm()),u=f.redSqrt();if(u.redSqr().redSub(f).cmp(this.zero)!==0)throw new Error("invalid point");var b=u.fromRed().isOdd();return(t&&!b||!t&&b)&&(u=u.redNeg()),this.point(e,u)};Hn.prototype.pointFromY=function(e,t){e=new ls(e,16),e.red||(e=e.toRed(this.red));var i=e.redSqr(),n=i.redSub(this.c2),a=i.redMul(this.d).redMul(this.c2).redSub(this.a),f=n.redMul(a.redInvm());if(f.cmp(this.zero)===0){if(t)throw new Error("invalid point");return this.point(this.zero,e)}var u=f.redSqrt();if(u.redSqr().redSub(f).cmp(this.zero)!==0)throw new Error("invalid point");return u.fromRed().isOdd()!==t&&(u=u.redNeg()),this.point(u,e)};Hn.prototype.validate=function(e){if(e.isInfinity())return!0;e.normalize();var t=e.x.redSqr(),i=e.y.redSqr(),n=t.redMul(this.a).redAdd(i),a=this.c2.redMul(this.one.redAdd(this.d.redMul(t).redMul(i)));return n.cmp(a)===0};function Wt(r,e,t,i,n){Th.BasePoint.call(this,r,"projective"),e===null&&t===null&&i===null?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new ls(e,16),this.y=new ls(t,16),this.z=i?new ls(i,16):this.curve.one,this.t=n&&new ls(n,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))))}eb(Wt,Th.BasePoint);Hn.prototype.pointFromJSON=function(e){return Wt.fromJSON(this,e)};Hn.prototype.point=function(e,t,i,n){return new Wt(this,e,t,i,n)};Wt.fromJSON=function(e,t){return new Wt(e,t[0],t[1],t[2])};Wt.prototype.inspect=function(){return this.isInfinity()?"":""};Wt.prototype.isInfinity=function(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)};Wt.prototype._extDbl=function(){var e=this.x.redSqr(),t=this.y.redSqr(),i=this.z.redSqr();i=i.redIAdd(i);var n=this.curve._mulA(e),a=this.x.redAdd(this.y).redSqr().redISub(e).redISub(t),f=n.redAdd(t),u=f.redSub(i),b=n.redSub(t),p=a.redMul(u),y=f.redMul(b),A=a.redMul(b),R=u.redMul(f);return this.curve.point(p,y,R,A)};Wt.prototype._projDbl=function(){var e=this.x.redAdd(this.y).redSqr(),t=this.x.redSqr(),i=this.y.redSqr(),n,a,f,u,b,p;if(this.curve.twisted){u=this.curve._mulA(t);var y=u.redAdd(i);this.zOne?(n=e.redSub(t).redSub(i).redMul(y.redSub(this.curve.two)),a=y.redMul(u.redSub(i)),f=y.redSqr().redSub(y).redSub(y)):(b=this.z.redSqr(),p=y.redSub(b).redISub(b),n=e.redSub(t).redISub(i).redMul(p),a=y.redMul(u.redSub(i)),f=y.redMul(p))}else u=t.redAdd(i),b=this.curve._mulC(this.z).redSqr(),p=u.redSub(b).redSub(b),n=this.curve._mulC(e.redISub(u)).redMul(p),a=this.curve._mulC(u).redMul(t.redISub(i)),f=u.redMul(p);return this.curve.point(n,a,f)};Wt.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()};Wt.prototype._extAdd=function(e){var t=this.y.redSub(this.x).redMul(e.y.redSub(e.x)),i=this.y.redAdd(this.x).redMul(e.y.redAdd(e.x)),n=this.t.redMul(this.curve.dd).redMul(e.t),a=this.z.redMul(e.z.redAdd(e.z)),f=i.redSub(t),u=a.redSub(n),b=a.redAdd(n),p=i.redAdd(t),y=f.redMul(u),A=b.redMul(p),R=f.redMul(p),O=u.redMul(b);return this.curve.point(y,A,O,R)};Wt.prototype._projAdd=function(e){var t=this.z.redMul(e.z),i=t.redSqr(),n=this.x.redMul(e.x),a=this.y.redMul(e.y),f=this.curve.d.redMul(n).redMul(a),u=i.redSub(f),b=i.redAdd(f),p=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(n).redISub(a),y=t.redMul(u).redMul(p),A,R;return this.curve.twisted?(A=t.redMul(b).redMul(a.redSub(this.curve._mulA(n))),R=u.redMul(b)):(A=t.redMul(b).redMul(a.redSub(n)),R=this.curve._mulC(u).redMul(b)),this.curve.point(y,A,R)};Wt.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)};Wt.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)};Wt.prototype.mulAdd=function(e,t,i){return this.curve._wnafMulAdd(1,[this,t],[e,i],2,!1)};Wt.prototype.jmulAdd=function(e,t,i){return this.curve._wnafMulAdd(1,[this,t],[e,i],2,!0)};Wt.prototype.normalize=function(){if(this.zOne)return this;var e=this.z.redInvm();return this.x=this.x.redMul(e),this.y=this.y.redMul(e),this.t&&(this.t=this.t.redMul(e)),this.z=this.curve.one,this.zOne=!0,this};Wt.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())};Wt.prototype.getX=function(){return this.normalize(),this.x.fromRed()};Wt.prototype.getY=function(){return this.normalize(),this.y.fromRed()};Wt.prototype.eq=function(e){return this===e||this.getX().cmp(e.getX())===0&&this.getY().cmp(e.getY())===0};Wt.prototype.eqXToP=function(e){var t=e.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(t)===0)return!0;for(var i=e.clone(),n=this.curve.redN.redMul(this.z);;){if(i.iadd(this.curve.n),i.cmp(this.curve.p)>=0)return!1;if(t.redIAdd(n),this.x.cmp(t)===0)return!0}};Wt.prototype.toP=Wt.prototype.normalize;Wt.prototype.mixedAdd=Wt.prototype.add;(function(r){var e=r;e.base=Nh,e.short=U_,e.mont=z_,e.edwards=H_})(B0);var Dh={},Fh={},Ot={},K_=ya,V_=xh;Ot.inherits=V_;function G_(r,e){return(r.charCodeAt(e)&64512)!==55296||e<0||e+1>=r.length?!1:(r.charCodeAt(e+1)&64512)===56320}function W_(r,e){if(Array.isArray(r))return r.slice();if(!r)return[];var t=[];if(typeof r=="string")if(e){if(e==="hex")for(r=r.replace(/[^a-z0-9]+/ig,""),r.length%2!==0&&(r="0"+r),n=0;n>6|192,t[i++]=a&63|128):G_(r,n)?(a=65536+((a&1023)<<10)+(r.charCodeAt(++n)&1023),t[i++]=a>>18|240,t[i++]=a>>12&63|128,t[i++]=a>>6&63|128,t[i++]=a&63|128):(t[i++]=a>>12|224,t[i++]=a>>6&63|128,t[i++]=a&63|128)}else for(n=0;n>>24|r>>>8&65280|r<<8&16711680|(r&255)<<24;return e>>>0}Ot.htonl=tb;function Y_(r,e){for(var t="",i=0;i>>0}return a}Ot.join32=Q_;function X_(r,e){for(var t=new Array(r.length*4),i=0,n=0;i>>24,t[n+1]=a>>>16&255,t[n+2]=a>>>8&255,t[n+3]=a&255):(t[n+3]=a>>>24,t[n+2]=a>>>16&255,t[n+1]=a>>>8&255,t[n]=a&255)}return t}Ot.split32=X_;function Z_(r,e){return r>>>e|r<<32-e}Ot.rotr32=Z_;function e7(r,e){return r<>>32-e}Ot.rotl32=e7;function t7(r,e){return r+e>>>0}Ot.sum32=t7;function r7(r,e,t){return r+e+t>>>0}Ot.sum32_3=r7;function i7(r,e,t,i){return r+e+t+i>>>0}Ot.sum32_4=i7;function n7(r,e,t,i,n){return r+e+t+i+n>>>0}Ot.sum32_5=n7;function s7(r,e,t,i){var n=r[e],a=r[e+1],f=i+a>>>0,u=(f>>0,r[e+1]=f}Ot.sum64=s7;function a7(r,e,t,i){var n=e+i>>>0,a=(n>>0}Ot.sum64_hi=a7;function o7(r,e,t,i){var n=e+i;return n>>>0}Ot.sum64_lo=o7;function c7(r,e,t,i,n,a,f,u){var b=0,p=e;p=p+i>>>0,b+=p>>0,b+=p>>0,b+=p>>0}Ot.sum64_4_hi=c7;function f7(r,e,t,i,n,a,f,u){var b=e+i+a+u;return b>>>0}Ot.sum64_4_lo=f7;function h7(r,e,t,i,n,a,f,u,b,p){var y=0,A=e;A=A+i>>>0,y+=A>>0,y+=A>>0,y+=A>>0,y+=A>>0}Ot.sum64_5_hi=h7;function u7(r,e,t,i,n,a,f,u,b,p){var y=e+i+a+u+p;return y>>>0}Ot.sum64_5_lo=u7;function l7(r,e,t){var i=e<<32-t|r>>>t;return i>>>0}Ot.rotr64_hi=l7;function d7(r,e,t){var i=r<<32-t|e>>>t;return i>>>0}Ot.rotr64_lo=d7;function p7(r,e,t){return r>>>t}Ot.shr64_hi=p7;function g7(r,e,t){var i=r<<32-t|e>>>t;return i>>>0}Ot.shr64_lo=g7;var uo={},_1=Ot,v7=ya;function Bh(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}uo.BlockHash=Bh;Bh.prototype.update=function(e,t){if(e=_1.toArray(e,t),this.pending?this.pending=this.pending.concat(e):this.pending=e,this.pendingTotal+=e.length,this.pending.length>=this._delta8){e=this.pending;var i=e.length%this._delta8;this.pending=e.slice(e.length-i,e.length),this.pending.length===0&&(this.pending=null),e=_1.join32(e,0,e.length-i,this.endian);for(var n=0;n>>24&255,n[a++]=e>>>16&255,n[a++]=e>>>8&255,n[a++]=e&255}else for(n[a++]=e&255,n[a++]=e>>>8&255,n[a++]=e>>>16&255,n[a++]=e>>>24&255,n[a++]=0,n[a++]=0,n[a++]=0,n[a++]=0,f=8;f>>3}Kn.g0_256=_7;function A7(r){return Nn(r,17)^Nn(r,19)^r>>>10}Kn.g1_256=A7;var ro=Ot,E7=uo,x7=Kn,hl=ro.rotl32,Ko=ro.sum32,S7=ro.sum32_5,I7=x7.ft_1,ob=E7.BlockHash,M7=[1518500249,1859775393,2400959708,3395469782];function Un(){if(!(this instanceof Un))return new Un;ob.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}ro.inherits(Un,ob);var P7=Un;Un.blockSize=512;Un.outSize=160;Un.hmacStrength=80;Un.padLength=64;Un.prototype._update=function(e,t){for(var i=this.W,n=0;n<16;n++)i[n]=e[t+n];for(;nthis.blockSize&&(e=new this.Hash().update(e).digest()),g9(e.length<=this.blockSize);for(var t=e.length;t=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,t,i)}var y9=Ls;Ls.prototype._init=function(e,t,i){var n=e.concat(t).concat(i);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var a=0;a=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(e.concat(i||[])),this._reseed=1};Ls.prototype.generate=function(e,t,i,n){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");typeof t!="string"&&(n=i,i=t,t=null),i&&(i=ua.toArray(i,n||"hex"),this._update(i));for(var a=[];a.length"};var hh=bs,L0=xi,E9=L0.assert;function qh(r,e){if(r instanceof qh)return r;this._importDER(r,e)||(E9(r.r&&r.s,"Signature without r or s"),this.r=new hh(r.r,16),this.s=new hh(r.s,16),r.recoveryParam===void 0?this.recoveryParam=null:this.recoveryParam=r.recoveryParam)}var x9=qh;function S9(){this.place=0}function pl(r,e){var t=r[e.place++];if(!(t&128))return t;var i=t&15;if(i===0||i>4||r[e.place]===0)return!1;for(var n=0,a=0,f=e.place;a>>=0;return n<=127?!1:(e.place=f,n)}function I1(r){for(var e=0,t=r.length-1;!r[e]&&!(r[e+1]&128)&&e>>3);for(r.push(t|128);--t;)r.push(e>>>(t<<3)&255);r.push(e)}qh.prototype.toDER=function(e){var t=this.r.toArray(),i=this.s.toArray();for(t[0]&128&&(t=[0].concat(t)),i[0]&128&&(i=[0].concat(i)),t=I1(t),i=I1(i);!i[0]&&!(i[1]&128);)i=i.slice(1);var n=[2];gl(n,t.length),n=n.concat(t),n.push(2),gl(n,i.length);var a=n.concat(i),f=[48];return gl(f,a.length),f=f.concat(a),L0.encode(f,e)};var la=bs,yb=y9,I9=xi,vl=Dh,M9=Xv,wb=I9.assert,U0=A9,Lh=x9;function ki(r){if(!(this instanceof ki))return new ki(r);typeof r=="string"&&(wb(Object.prototype.hasOwnProperty.call(vl,r),"Unknown curve "+r),r=vl[r]),r instanceof vl.PresetCurve&&(r={curve:r}),this.curve=r.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=r.curve.g,this.g.precompute(r.curve.n.bitLength()+1),this.hash=r.hash||r.curve.hash}var P9=ki;ki.prototype.keyPair=function(e){return new U0(this,e)};ki.prototype.keyFromPrivate=function(e,t){return U0.fromPrivate(this,e,t)};ki.prototype.keyFromPublic=function(e,t){return U0.fromPublic(this,e,t)};ki.prototype.genKeyPair=function(e){e||(e={});for(var t=new yb({hash:this.hash,pers:e.pers,persEnc:e.persEnc||"utf8",entropy:e.entropy||M9(this.hash.hmacStrength),entropyEnc:e.entropy&&e.entropyEnc||"utf8",nonce:this.n.toArray()}),i=this.n.byteLength(),n=this.n.sub(new la(2));;){var a=new la(t.generate(i));if(!(a.cmp(n)>0))return a.iaddn(1),this.keyFromPrivate(a)}};ki.prototype._truncateToN=function(e,t){var i=e.byteLength()*8-this.n.bitLength();return i>0&&(e=e.ushrn(i)),!t&&e.cmp(this.n)>=0?e.sub(this.n):e};ki.prototype.sign=function(e,t,i,n){typeof i=="object"&&(n=i,i=null),n||(n={}),t=this.keyFromPrivate(t,i),e=this._truncateToN(new la(e,16));for(var a=this.n.byteLength(),f=t.getPrivate().toArray("be",a),u=e.toArray("be",a),b=new yb({hash:this.hash,entropy:f,nonce:u,pers:n.pers,persEnc:n.persEnc||"utf8"}),p=this.n.sub(new la(1)),y=0;;y++){var A=n.k?n.k(y):new la(b.generate(this.n.byteLength()));if(A=this._truncateToN(A,!0),!(A.cmpn(1)<=0||A.cmp(p)>=0)){var R=this.g.mul(A);if(!R.isInfinity()){var O=R.getX(),N=O.umod(this.n);if(N.cmpn(0)!==0){var K=A.invm(this.n).mul(N.mul(t.getPrivate()).iadd(e));if(K=K.umod(this.n),K.cmpn(0)!==0){var W=(R.getY().isOdd()?1:0)|(O.cmp(N)!==0?2:0);return n.canonical&&K.cmp(this.nh)>0&&(K=this.n.sub(K),W^=1),new Lh({r:N,s:K,recoveryParam:W})}}}}}};ki.prototype.verify=function(e,t,i,n){e=this._truncateToN(new la(e,16)),i=this.keyFromPublic(i,n),t=new Lh(t,"hex");var a=t.r,f=t.s;if(a.cmpn(1)<0||a.cmp(this.n)>=0||f.cmpn(1)<0||f.cmp(this.n)>=0)return!1;var u=f.invm(this.n),b=u.mul(e).umod(this.n),p=u.mul(a).umod(this.n),y;return this.curve._maxwellTrick?(y=this.g.jmulAdd(b,i.getPublic(),p),y.isInfinity()?!1:y.eqXToP(a)):(y=this.g.mulAdd(b,i.getPublic(),p),y.isInfinity()?!1:y.getX().umod(this.n).cmp(a)===0)};ki.prototype.recoverPubKey=function(r,e,t,i){wb((3&t)===t,"The recovery param is more than two bits"),e=new Lh(e,i);var n=this.n,a=new la(r),f=e.r,u=e.s,b=t&1,p=t>>1;if(f.cmp(this.curve.p.umod(this.curve.n))>=0&&p)throw new Error("Unable to find sencond key candinate");p?f=this.curve.pointFromX(f.add(this.curve.n),b):f=this.curve.pointFromX(f,b);var y=e.r.invm(n),A=n.sub(a).mul(y).umod(n),R=u.mul(y).umod(n);return this.g.mulAdd(A,f,R)};ki.prototype.getKeyRecoveryParam=function(r,e,t,i){if(e=new Lh(e,i),e.recoveryParam!==null)return e.recoveryParam;for(var n=0;n<4;n++){var a;try{a=this.recoverPubKey(r,e,n)}catch{continue}if(a.eq(t))return n}throw new Error("Unable to find valid recovery factor")};var xc=xi,_b=xc.assert,M1=xc.parseBytes,go=xc.cachedProperty;function xr(r,e){this.eddsa=r,this._secret=M1(e.secret),r.isPoint(e.pub)?this._pub=e.pub:this._pubBytes=M1(e.pub)}xr.fromPublic=function(e,t){return t instanceof xr?t:new xr(e,{pub:t})};xr.fromSecret=function(e,t){return t instanceof xr?t:new xr(e,{secret:t})};xr.prototype.secret=function(){return this._secret};go(xr,"pubBytes",function(){return this.eddsa.encodePoint(this.pub())});go(xr,"pub",function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())});go(xr,"privBytes",function(){var e=this.eddsa,t=this.hash(),i=e.encodingLength-1,n=t.slice(0,e.encodingLength);return n[0]&=248,n[i]&=127,n[i]|=64,n});go(xr,"priv",function(){return this.eddsa.decodeInt(this.privBytes())});go(xr,"hash",function(){return this.eddsa.hash().update(this.secret()).digest()});go(xr,"messagePrefix",function(){return this.hash().slice(this.eddsa.encodingLength)});xr.prototype.sign=function(e){return _b(this._secret,"KeyPair can only verify"),this.eddsa.sign(e,this)};xr.prototype.verify=function(e,t){return this.eddsa.verify(e,t,this)};xr.prototype.getSecret=function(e){return _b(this._secret,"KeyPair is public only"),xc.encode(this.secret(),e)};xr.prototype.getPublic=function(e){return xc.encode(this.pubBytes(),e)};var O9=xr,R9=bs,Uh=xi,P1=Uh.assert,$h=Uh.cachedProperty,N9=Uh.parseBytes;function wa(r,e){this.eddsa=r,typeof e!="object"&&(e=N9(e)),Array.isArray(e)&&(P1(e.length===r.encodingLength*2,"Signature has invalid size"),e={R:e.slice(0,r.encodingLength),S:e.slice(r.encodingLength)}),P1(e.R&&e.S,"Signature without R or S"),r.isPoint(e.R)&&(this._R=e.R),e.S instanceof R9&&(this._S=e.S),this._Rencoded=Array.isArray(e.R)?e.R:e.Rencoded,this._Sencoded=Array.isArray(e.S)?e.S:e.Sencoded}$h(wa,"S",function(){return this.eddsa.decodeInt(this.Sencoded())});$h(wa,"R",function(){return this.eddsa.decodePoint(this.Rencoded())});$h(wa,"Rencoded",function(){return this.eddsa.encodePoint(this.R())});$h(wa,"Sencoded",function(){return this.eddsa.encodeInt(this.S())});wa.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())};wa.prototype.toHex=function(){return Uh.encode(this.toBytes(),"hex").toUpperCase()};var C9=wa,T9=Fh,D9=Dh,so=xi,F9=so.assert,Ab=so.parseBytes,Eb=O9,O1=C9;function ui(r){if(F9(r==="ed25519","only tested with ed25519 so far"),!(this instanceof ui))return new ui(r);r=D9[r].curve,this.curve=r,this.g=r.g,this.g.precompute(r.n.bitLength()+1),this.pointClass=r.point().constructor,this.encodingLength=Math.ceil(r.n.bitLength()/8),this.hash=T9.sha512}var B9=ui;ui.prototype.sign=function(e,t){e=Ab(e);var i=this.keyFromSecret(t),n=this.hashInt(i.messagePrefix(),e),a=this.g.mul(n),f=this.encodePoint(a),u=this.hashInt(f,i.pubBytes(),e).mul(i.priv()),b=n.add(u).umod(this.curve.n);return this.makeSignature({R:a,S:b,Rencoded:f})};ui.prototype.verify=function(e,t,i){if(e=Ab(e),t=this.makeSignature(t),t.S().gte(t.eddsa.curve.n)||t.S().isNeg())return!1;var n=this.keyFromPublic(i),a=this.hashInt(t.Rencoded(),n.pubBytes(),e),f=this.g.mul(t.S()),u=t.R().add(n.pub().mul(a));return u.eq(f)};ui.prototype.hashInt=function(){for(var e=this.hash(),t=0;t0){for(;this._bufferLength0;)this._buffer[this._bufferLength++]=b[y++],p--;this._bufferLength===this.blockSize&&(a(this._tempHi,this._tempLo,this._stateHi,this._stateLo,this._buffer,0,this.blockSize),this._bufferLength=0)}for(p>=this.blockSize&&(y=a(this._tempHi,this._tempLo,this._stateHi,this._stateLo,b,y,p),p%=this.blockSize);p>0;)this._buffer[this._bufferLength++]=b[y++],p--;return this},u.prototype.finish=function(b){if(!this._finished){var p=this._bytesHashed,y=this._bufferLength,A=p/536870912|0,R=p<<3,O=p%128<112?128:256;this._buffer[y]=128;for(var N=y+1;N0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}},u.prototype.restoreState=function(b){return this._stateHi.set(b.stateHi),this._stateLo.set(b.stateLo),this._bufferLength=b.bufferLength,b.buffer&&this._buffer.set(b.buffer),this._bytesHashed=b.bytesHashed,this._finished=!1,this},u.prototype.cleanSavedState=function(b){t.wipe(b.stateHi),t.wipe(b.stateLo),b.buffer&&t.wipe(b.buffer),b.bufferLength=0,b.bytesHashed=0},u}();r.SHA512=i;var n=new Int32Array([1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591]);function a(u,b,p,y,A,R,O){for(var N=p[0],K=p[1],W=p[2],Q=p[3],j=p[4],Y=p[5],U=p[6],k=p[7],G=y[0],x=y[1],B=y[2],ae=y[3],le=y[4],F=y[5],m=y[6],c=y[7],h,v,_,I,M,S,d,g;O>=128;){for(var T=0;T<16;T++){var Z=8*T+R;u[T]=e.readUint32BE(A,Z),b[T]=e.readUint32BE(A,Z+4)}for(var T=0;T<80;T++){var se=N,P=K,ee=W,q=Q,z=j,H=Y,w=U,$=k,ne=G,ce=x,he=B,ye=ae,we=le,Ce=F,Qe=m,Oe=c;if(h=k,v=c,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=(j>>>14|le<<18)^(j>>>18|le<<14)^(le>>>9|j<<23),v=(le>>>14|j<<18)^(le>>>18|j<<14)^(j>>>9|le<<23),M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,h=j&Y^~j&U,v=le&F^~le&m,M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,h=n[T*2],v=n[T*2+1],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,h=u[T%16],v=b[T%16],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,_=d&65535|g<<16,I=M&65535|S<<16,h=_,v=I,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=(N>>>28|G<<4)^(G>>>2|N<<30)^(G>>>7|N<<25),v=(G>>>28|N<<4)^(N>>>2|G<<30)^(N>>>7|G<<25),M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,h=N&K^N&W^K&W,v=G&x^G&B^x&B,M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,$=d&65535|g<<16,Oe=M&65535|S<<16,h=q,v=ye,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=_,v=I,M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,q=d&65535|g<<16,ye=M&65535|S<<16,K=se,W=P,Q=ee,j=q,Y=z,U=H,k=w,N=$,x=ne,B=ce,ae=he,le=ye,F=we,m=Ce,c=Qe,G=Oe,T%16===15)for(var Z=0;Z<16;Z++)h=u[Z],v=b[Z],M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=u[(Z+9)%16],v=b[(Z+9)%16],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,_=u[(Z+1)%16],I=b[(Z+1)%16],h=(_>>>1|I<<31)^(_>>>8|I<<24)^_>>>7,v=(I>>>1|_<<31)^(I>>>8|_<<24)^(I>>>7|_<<25),M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,_=u[(Z+14)%16],I=b[(Z+14)%16],h=(_>>>19|I<<13)^(I>>>29|_<<3)^_>>>6,v=(I>>>19|_<<13)^(_>>>29|I<<3)^(I>>>6|_<<26),M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,u[Z]=d&65535|g<<16,b[Z]=M&65535|S<<16}h=N,v=G,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=p[0],v=y[0],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,p[0]=N=d&65535|g<<16,y[0]=G=M&65535|S<<16,h=K,v=x,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=p[1],v=y[1],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,p[1]=K=d&65535|g<<16,y[1]=x=M&65535|S<<16,h=W,v=B,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=p[2],v=y[2],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,p[2]=W=d&65535|g<<16,y[2]=B=M&65535|S<<16,h=Q,v=ae,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=p[3],v=y[3],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,p[3]=Q=d&65535|g<<16,y[3]=ae=M&65535|S<<16,h=j,v=le,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=p[4],v=y[4],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,p[4]=j=d&65535|g<<16,y[4]=le=M&65535|S<<16,h=Y,v=F,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=p[5],v=y[5],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,p[5]=Y=d&65535|g<<16,y[5]=F=M&65535|S<<16,h=U,v=m,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=p[6],v=y[6],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,p[6]=U=d&65535|g<<16,y[6]=m=M&65535|S<<16,h=k,v=c,M=v&65535,S=v>>>16,d=h&65535,g=h>>>16,h=p[7],v=y[7],M+=v&65535,S+=v>>>16,d+=h&65535,g+=h>>>16,S+=M>>>16,d+=S>>>16,g+=d>>>16,p[7]=k=d&65535|g<<16,y[7]=c=M&65535|S<<16,R+=128,O-=128}return R}function f(u){var b=new i;b.update(u);var p=b.digest();return b.clean(),p}r.hash=f})(xb);(function(r){Object.defineProperty(r,"__esModule",{value:!0}),r.convertSecretKeyToX25519=r.convertPublicKeyToX25519=r.verify=r.sign=r.extractPublicKeyFromSecretKey=r.generateKeyPair=r.generateKeyPairFromSeed=r.SEED_LENGTH=r.SECRET_KEY_LENGTH=r.PUBLIC_KEY_LENGTH=r.SIGNATURE_LENGTH=void 0;const e=$s,t=xb,i=Ei;r.SIGNATURE_LENGTH=64,r.PUBLIC_KEY_LENGTH=32,r.SECRET_KEY_LENGTH=64,r.SEED_LENGTH=32;function n(q){const z=new Float64Array(16);if(q)for(let H=0;H>16&1),H[ce-1]&=65535;H[15]=w[15]-32767-(H[14]>>16&1);const ne=H[15]>>16&1;H[14]&=65535,K(w,H,1-ne)}for(let $=0;$<16;$++)q[2*$]=w[$]&255,q[2*$+1]=w[$]>>8}function Q(q,z){let H=0;for(let w=0;w<32;w++)H|=q[w]^z[w];return(1&H-1>>>8)-1}function j(q,z){const H=new Uint8Array(32),w=new Uint8Array(32);return W(H,q),W(w,z),Q(H,w)}function Y(q){const z=new Uint8Array(32);return W(z,q),z[0]&1}function U(q,z){for(let H=0;H<16;H++)q[H]=z[2*H]+(z[2*H+1]<<8);q[15]&=32767}function k(q,z,H){for(let w=0;w<16;w++)q[w]=z[w]+H[w]}function G(q,z,H){for(let w=0;w<16;w++)q[w]=z[w]-H[w]}function x(q,z,H){let w,$,ne=0,ce=0,he=0,ye=0,we=0,Ce=0,Qe=0,Oe=0,Te=0,Ie=0,me=0,Re=0,De=0,ve=0,Ne=0,Se=0,be=0,Le=0,Me=0,_e=0,He=0,Ve=0,Ee=0,Ke=0,ut=0,Ge=0,_t=0,lt=0,Je=0,Et=0,It=0,Fe=H[0],Xe=H[1],tt=H[2],Be=H[3],et=H[4],Ze=H[5],$e=H[6],ft=H[7],rt=H[8],ze=H[9],it=H[10],st=H[11],qe=H[12],Ye=H[13],ht=H[14],je=H[15];w=z[0],ne+=w*Fe,ce+=w*Xe,he+=w*tt,ye+=w*Be,we+=w*et,Ce+=w*Ze,Qe+=w*$e,Oe+=w*ft,Te+=w*rt,Ie+=w*ze,me+=w*it,Re+=w*st,De+=w*qe,ve+=w*Ye,Ne+=w*ht,Se+=w*je,w=z[1],ce+=w*Fe,he+=w*Xe,ye+=w*tt,we+=w*Be,Ce+=w*et,Qe+=w*Ze,Oe+=w*$e,Te+=w*ft,Ie+=w*rt,me+=w*ze,Re+=w*it,De+=w*st,ve+=w*qe,Ne+=w*Ye,Se+=w*ht,be+=w*je,w=z[2],he+=w*Fe,ye+=w*Xe,we+=w*tt,Ce+=w*Be,Qe+=w*et,Oe+=w*Ze,Te+=w*$e,Ie+=w*ft,me+=w*rt,Re+=w*ze,De+=w*it,ve+=w*st,Ne+=w*qe,Se+=w*Ye,be+=w*ht,Le+=w*je,w=z[3],ye+=w*Fe,we+=w*Xe,Ce+=w*tt,Qe+=w*Be,Oe+=w*et,Te+=w*Ze,Ie+=w*$e,me+=w*ft,Re+=w*rt,De+=w*ze,ve+=w*it,Ne+=w*st,Se+=w*qe,be+=w*Ye,Le+=w*ht,Me+=w*je,w=z[4],we+=w*Fe,Ce+=w*Xe,Qe+=w*tt,Oe+=w*Be,Te+=w*et,Ie+=w*Ze,me+=w*$e,Re+=w*ft,De+=w*rt,ve+=w*ze,Ne+=w*it,Se+=w*st,be+=w*qe,Le+=w*Ye,Me+=w*ht,_e+=w*je,w=z[5],Ce+=w*Fe,Qe+=w*Xe,Oe+=w*tt,Te+=w*Be,Ie+=w*et,me+=w*Ze,Re+=w*$e,De+=w*ft,ve+=w*rt,Ne+=w*ze,Se+=w*it,be+=w*st,Le+=w*qe,Me+=w*Ye,_e+=w*ht,He+=w*je,w=z[6],Qe+=w*Fe,Oe+=w*Xe,Te+=w*tt,Ie+=w*Be,me+=w*et,Re+=w*Ze,De+=w*$e,ve+=w*ft,Ne+=w*rt,Se+=w*ze,be+=w*it,Le+=w*st,Me+=w*qe,_e+=w*Ye,He+=w*ht,Ve+=w*je,w=z[7],Oe+=w*Fe,Te+=w*Xe,Ie+=w*tt,me+=w*Be,Re+=w*et,De+=w*Ze,ve+=w*$e,Ne+=w*ft,Se+=w*rt,be+=w*ze,Le+=w*it,Me+=w*st,_e+=w*qe,He+=w*Ye,Ve+=w*ht,Ee+=w*je,w=z[8],Te+=w*Fe,Ie+=w*Xe,me+=w*tt,Re+=w*Be,De+=w*et,ve+=w*Ze,Ne+=w*$e,Se+=w*ft,be+=w*rt,Le+=w*ze,Me+=w*it,_e+=w*st,He+=w*qe,Ve+=w*Ye,Ee+=w*ht,Ke+=w*je,w=z[9],Ie+=w*Fe,me+=w*Xe,Re+=w*tt,De+=w*Be,ve+=w*et,Ne+=w*Ze,Se+=w*$e,be+=w*ft,Le+=w*rt,Me+=w*ze,_e+=w*it,He+=w*st,Ve+=w*qe,Ee+=w*Ye,Ke+=w*ht,ut+=w*je,w=z[10],me+=w*Fe,Re+=w*Xe,De+=w*tt,ve+=w*Be,Ne+=w*et,Se+=w*Ze,be+=w*$e,Le+=w*ft,Me+=w*rt,_e+=w*ze,He+=w*it,Ve+=w*st,Ee+=w*qe,Ke+=w*Ye,ut+=w*ht,Ge+=w*je,w=z[11],Re+=w*Fe,De+=w*Xe,ve+=w*tt,Ne+=w*Be,Se+=w*et,be+=w*Ze,Le+=w*$e,Me+=w*ft,_e+=w*rt,He+=w*ze,Ve+=w*it,Ee+=w*st,Ke+=w*qe,ut+=w*Ye,Ge+=w*ht,_t+=w*je,w=z[12],De+=w*Fe,ve+=w*Xe,Ne+=w*tt,Se+=w*Be,be+=w*et,Le+=w*Ze,Me+=w*$e,_e+=w*ft,He+=w*rt,Ve+=w*ze,Ee+=w*it,Ke+=w*st,ut+=w*qe,Ge+=w*Ye,_t+=w*ht,lt+=w*je,w=z[13],ve+=w*Fe,Ne+=w*Xe,Se+=w*tt,be+=w*Be,Le+=w*et,Me+=w*Ze,_e+=w*$e,He+=w*ft,Ve+=w*rt,Ee+=w*ze,Ke+=w*it,ut+=w*st,Ge+=w*qe,_t+=w*Ye,lt+=w*ht,Je+=w*je,w=z[14],Ne+=w*Fe,Se+=w*Xe,be+=w*tt,Le+=w*Be,Me+=w*et,_e+=w*Ze,He+=w*$e,Ve+=w*ft,Ee+=w*rt,Ke+=w*ze,ut+=w*it,Ge+=w*st,_t+=w*qe,lt+=w*Ye,Je+=w*ht,Et+=w*je,w=z[15],Se+=w*Fe,be+=w*Xe,Le+=w*tt,Me+=w*Be,_e+=w*et,He+=w*Ze,Ve+=w*$e,Ee+=w*ft,Ke+=w*rt,ut+=w*ze,Ge+=w*it,_t+=w*st,lt+=w*qe,Je+=w*Ye,Et+=w*ht,It+=w*je,ne+=38*be,ce+=38*Le,he+=38*Me,ye+=38*_e,we+=38*He,Ce+=38*Ve,Qe+=38*Ee,Oe+=38*Ke,Te+=38*ut,Ie+=38*Ge,me+=38*_t,Re+=38*lt,De+=38*Je,ve+=38*Et,Ne+=38*It,$=1,w=ne+$+65535,$=Math.floor(w/65536),ne=w-$*65536,w=ce+$+65535,$=Math.floor(w/65536),ce=w-$*65536,w=he+$+65535,$=Math.floor(w/65536),he=w-$*65536,w=ye+$+65535,$=Math.floor(w/65536),ye=w-$*65536,w=we+$+65535,$=Math.floor(w/65536),we=w-$*65536,w=Ce+$+65535,$=Math.floor(w/65536),Ce=w-$*65536,w=Qe+$+65535,$=Math.floor(w/65536),Qe=w-$*65536,w=Oe+$+65535,$=Math.floor(w/65536),Oe=w-$*65536,w=Te+$+65535,$=Math.floor(w/65536),Te=w-$*65536,w=Ie+$+65535,$=Math.floor(w/65536),Ie=w-$*65536,w=me+$+65535,$=Math.floor(w/65536),me=w-$*65536,w=Re+$+65535,$=Math.floor(w/65536),Re=w-$*65536,w=De+$+65535,$=Math.floor(w/65536),De=w-$*65536,w=ve+$+65535,$=Math.floor(w/65536),ve=w-$*65536,w=Ne+$+65535,$=Math.floor(w/65536),Ne=w-$*65536,w=Se+$+65535,$=Math.floor(w/65536),Se=w-$*65536,ne+=$-1+37*($-1),$=1,w=ne+$+65535,$=Math.floor(w/65536),ne=w-$*65536,w=ce+$+65535,$=Math.floor(w/65536),ce=w-$*65536,w=he+$+65535,$=Math.floor(w/65536),he=w-$*65536,w=ye+$+65535,$=Math.floor(w/65536),ye=w-$*65536,w=we+$+65535,$=Math.floor(w/65536),we=w-$*65536,w=Ce+$+65535,$=Math.floor(w/65536),Ce=w-$*65536,w=Qe+$+65535,$=Math.floor(w/65536),Qe=w-$*65536,w=Oe+$+65535,$=Math.floor(w/65536),Oe=w-$*65536,w=Te+$+65535,$=Math.floor(w/65536),Te=w-$*65536,w=Ie+$+65535,$=Math.floor(w/65536),Ie=w-$*65536,w=me+$+65535,$=Math.floor(w/65536),me=w-$*65536,w=Re+$+65535,$=Math.floor(w/65536),Re=w-$*65536,w=De+$+65535,$=Math.floor(w/65536),De=w-$*65536,w=ve+$+65535,$=Math.floor(w/65536),ve=w-$*65536,w=Ne+$+65535,$=Math.floor(w/65536),Ne=w-$*65536,w=Se+$+65535,$=Math.floor(w/65536),Se=w-$*65536,ne+=$-1+37*($-1),q[0]=ne,q[1]=ce,q[2]=he,q[3]=ye,q[4]=we,q[5]=Ce,q[6]=Qe,q[7]=Oe,q[8]=Te,q[9]=Ie,q[10]=me,q[11]=Re,q[12]=De,q[13]=ve,q[14]=Ne,q[15]=Se}function B(q,z){x(q,z,z)}function ae(q,z){const H=n();let w;for(w=0;w<16;w++)H[w]=z[w];for(w=253;w>=0;w--)B(H,H),w!==2&&w!==4&&x(H,H,z);for(w=0;w<16;w++)q[w]=H[w]}function le(q,z){const H=n();let w;for(w=0;w<16;w++)H[w]=z[w];for(w=250;w>=0;w--)B(H,H),w!==1&&x(H,H,z);for(w=0;w<16;w++)q[w]=H[w]}function F(q,z){const H=n(),w=n(),$=n(),ne=n(),ce=n(),he=n(),ye=n(),we=n(),Ce=n();G(H,q[1],q[0]),G(Ce,z[1],z[0]),x(H,H,Ce),k(w,q[0],q[1]),k(Ce,z[0],z[1]),x(w,w,Ce),x($,q[3],z[3]),x($,$,p),x(ne,q[2],z[2]),k(ne,ne,ne),G(ce,w,H),G(he,ne,$),k(ye,ne,$),k(we,w,H),x(q[0],ce,he),x(q[1],we,ye),x(q[2],ye,he),x(q[3],ce,we)}function m(q,z,H){for(let w=0;w<4;w++)K(q[w],z[w],H)}function c(q,z){const H=n(),w=n(),$=n();ae($,z[2]),x(H,z[0],$),x(w,z[1],$),W(q,w),q[31]^=Y(H)<<7}function h(q,z,H){O(q[0],f),O(q[1],u),O(q[2],u),O(q[3],f);for(let w=255;w>=0;--w){const $=H[w/8|0]>>(w&7)&1;m(q,z,$),F(z,q),F(q,q),m(q,z,$)}}function v(q,z){const H=[n(),n(),n(),n()];O(H[0],y),O(H[1],A),O(H[2],u),x(H[3],y,A),h(q,H,z)}function _(q){if(q.length!==r.SEED_LENGTH)throw new Error(`ed25519: seed must be ${r.SEED_LENGTH} bytes`);const z=(0,t.hash)(q);z[0]&=248,z[31]&=127,z[31]|=64;const H=new Uint8Array(32),w=[n(),n(),n(),n()];v(w,z),c(H,w);const $=new Uint8Array(64);return $.set(q),$.set(H,32),{publicKey:H,secretKey:$}}r.generateKeyPairFromSeed=_;function I(q){const z=(0,e.randomBytes)(32,q),H=_(z);return(0,i.wipe)(z),H}r.generateKeyPair=I;function M(q){if(q.length!==r.SECRET_KEY_LENGTH)throw new Error(`ed25519: secret key must be ${r.SECRET_KEY_LENGTH} bytes`);return new Uint8Array(q.subarray(32))}r.extractPublicKeyFromSecretKey=M;const S=new Float64Array([237,211,245,92,26,99,18,88,214,156,247,162,222,249,222,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,16]);function d(q,z){let H,w,$,ne;for(w=63;w>=32;--w){for(H=0,$=w-32,ne=w-12;$>4)*S[$],H=z[$]>>8,z[$]&=255;for($=0;$<32;$++)z[$]-=H*S[$];for(w=0;w<32;w++)z[w+1]+=z[w]>>8,q[w]=z[w]&255}function g(q){const z=new Float64Array(64);for(let H=0;H<64;H++)z[H]=q[H];for(let H=0;H<64;H++)q[H]=0;d(q,z)}function T(q,z){const H=new Float64Array(64),w=[n(),n(),n(),n()],$=(0,t.hash)(q.subarray(0,32));$[0]&=248,$[31]&=127,$[31]|=64;const ne=new Uint8Array(64);ne.set($.subarray(32),32);const ce=new t.SHA512;ce.update(ne.subarray(32)),ce.update(z);const he=ce.digest();ce.clean(),g(he),v(w,he),c(ne,w),ce.reset(),ce.update(ne.subarray(0,32)),ce.update(q.subarray(32)),ce.update(z);const ye=ce.digest();g(ye);for(let we=0;we<32;we++)H[we]=he[we];for(let we=0;we<32;we++)for(let Ce=0;Ce<32;Ce++)H[we+Ce]+=ye[we]*$[Ce];return d(ne.subarray(32),H),ne}r.sign=T;function Z(q,z){const H=n(),w=n(),$=n(),ne=n(),ce=n(),he=n(),ye=n();return O(q[2],u),U(q[1],z),B($,q[1]),x(ne,$,b),G($,$,q[2]),k(ne,q[2],ne),B(ce,ne),B(he,ce),x(ye,he,ce),x(H,ye,$),x(H,H,ne),le(H,H),x(H,H,$),x(H,H,ne),x(H,H,ne),x(q[0],H,ne),B(w,q[0]),x(w,w,ne),j(w,$)&&x(q[0],q[0],R),B(w,q[0]),x(w,w,ne),j(w,$)?-1:(Y(q[0])===z[31]>>7&&G(q[0],f,q[0]),x(q[3],q[0],q[1]),0)}function se(q,z,H){const w=new Uint8Array(32),$=[n(),n(),n(),n()],ne=[n(),n(),n(),n()];if(H.length!==r.SIGNATURE_LENGTH)throw new Error(`ed25519: signature must be ${r.SIGNATURE_LENGTH} bytes`);if(Z(ne,q))return!1;const ce=new t.SHA512;ce.update(H.subarray(0,32)),ce.update(q),ce.update(z);const he=ce.digest();return g(he),h($,ne,he),v(ne,H.subarray(32)),F($,ne),c(w,$),!Q(H,w)}r.verify=se;function P(q){let z=[n(),n(),n(),n()];if(Z(z,q))throw new Error("Ed25519: invalid public key");let H=n(),w=n(),$=z[1];k(H,u,$),G(w,u,$),ae(w,w),x(H,H,w);let ne=new Uint8Array(32);return W(ne,H),ne}r.convertPublicKeyToX25519=P;function ee(q){const z=(0,t.hash)(q.subarray(0,32));z[0]&=248,z[31]&=127,z[31]|=64;const H=new Uint8Array(z.subarray(0,32));return(0,i.wipe)(z),H}r.convertSecretKeyToX25519=ee})($0);const q9="EdDSA",L9="JWT",uh=".",zh="base64url",Sb="utf8",Ib="utf8",U9=":",$9="did",z9="key",R1="base58btc",j9="z",k9="K36",H9=32,K9=r=>JSON.stringify(r,(e,t)=>typeof t=="bigint"?t.toString()+"n":t),V9=r=>{const e=/([\[:])?(\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,t=r.replace(e,'$1"$2n"$3');return JSON.parse(t,(i,n)=>typeof n=="string"&&n.match(/^\d+n$/)?BigInt(n.substring(0,n.length-1)):n)};function ga(r){if(typeof r!="string")throw new Error(`Cannot safe json parse value of type ${typeof r}`);try{return V9(r)}catch{return r}}function vs(r){return typeof r=="string"?r:K9(r)||""}function N1(r){return ga(Er(Ar(r,zh),Sb))}function lh(r){return Er(Ar(vs(r),Sb),zh)}function Mb(r){const e=Ar(k9,R1),t=j9+Er(Yf([e,r]),R1);return[$9,z9,t].join(U9)}function G9(r){return Er(r,zh)}function W9(r){return Ar(r,zh)}function J9(r){return Ar([lh(r.header),lh(r.payload)].join(uh),Ib)}function Y9(r){return[lh(r.header),lh(r.payload),G9(r.signature)].join(uh)}function n0(r){const e=r.split(uh),t=N1(e[0]),i=N1(e[1]),n=W9(e[2]),a=Ar(e.slice(0,2).join(uh),Ib);return{header:t,payload:i,signature:n,data:a}}function C1(r=$s.randomBytes(H9)){return $0.generateKeyPairFromSeed(r)}async function Q9(r,e,t,i,n=xe.fromMiliseconds(Date.now())){const a={alg:q9,typ:L9},f=Mb(i.publicKey),u=n+t,b={iss:f,sub:r,aud:e,iat:n,exp:u},p=J9({header:a,payload:b}),y=$0.sign(i.secretKey,p);return Y9({header:a,payload:b,signature:y})}const X9={waku:{publish:"waku_publish",batchPublish:"waku_batchPublish",subscribe:"waku_subscribe",batchSubscribe:"waku_batchSubscribe",subscription:"waku_subscription",unsubscribe:"waku_unsubscribe",batchUnsubscribe:"waku_batchUnsubscribe",batchFetchMessages:"waku_batchFetchMessages"},irn:{publish:"irn_publish",batchPublish:"irn_batchPublish",subscribe:"irn_subscribe",batchSubscribe:"irn_batchSubscribe",subscription:"irn_subscription",unsubscribe:"irn_unsubscribe",batchUnsubscribe:"irn_batchUnsubscribe",batchFetchMessages:"irn_batchFetchMessages"},iridium:{publish:"iridium_publish",batchPublish:"iridium_batchPublish",subscribe:"iridium_subscribe",batchSubscribe:"iridium_batchSubscribe",subscription:"iridium_subscription",unsubscribe:"iridium_unsubscribe",batchUnsubscribe:"iridium_batchUnsubscribe",batchFetchMessages:"iridium_batchFetchMessages"}};var Z9={};const eA=":";function ac(r){const[e,t]=r.split(eA);return{namespace:e,reference:t}}function T1(r,e=[]){const t=[];return Object.keys(r).forEach(i=>{if(e.length&&!e.includes(i))return;const n=r[i];t.push(...n.accounts)}),t}function Pb(r,e){return r.includes(":")?[r]:e.chains||[]}var tA=Object.defineProperty,D1=Object.getOwnPropertySymbols,rA=Object.prototype.hasOwnProperty,iA=Object.prototype.propertyIsEnumerable,F1=(r,e,t)=>e in r?tA(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,B1=(r,e)=>{for(var t in e||(e={}))rA.call(e,t)&&F1(r,t,e[t]);if(D1)for(var t of D1(e))iA.call(e,t)&&F1(r,t,e[t]);return r};const nA="ReactNative",wi={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},sA="js";function dh(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function vo(){return!Ih()&&!!P0()&&navigator.product===nA}function Sc(){return!dh()&&!!P0()&&!!Ih()}function Ic(){return vo()?wi.reactNative:dh()?wi.node:Sc()?wi.browser:wi.unknown}function aA(){var r;try{return vo()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(r=global.Application)==null?void 0:r.applicationId:void 0}catch{return}}function oA(r,e){let t=dc.parse(r);return t=B1(B1({},t),e),r=dc.stringify(t),r}function Ob(){return qv()||{name:"",description:"",url:"",icons:[""]}}function cA(){if(Ic()===wi.reactNative&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"){const{OS:t,Version:i}=global.Platform;return[t,i].join("-")}const r=z4();if(r===null)return"unknown";const e=r.os?r.os.replace(" ","").toLowerCase():"unknown";return r.type==="browser"?[e,r.name,r.version].join("-"):[e,r.version].join("-")}function fA(){var r;const e=Ic();return e===wi.browser?[e,((r=Bv())==null?void 0:r.host)||"unknown"].join(":"):e}function Rb(r,e,t){const i=cA(),n=fA();return[[r,e].join("-"),[sA,t].join("-"),i,n].join("/")}function hA({protocol:r,version:e,relayUrl:t,sdkVersion:i,auth:n,projectId:a,useOnCloseEvent:f,bundleId:u}){const b=t.split("?"),p=Rb(r,e,i),y={auth:n,ua:p,projectId:a,useOnCloseEvent:f||void 0,origin:u||void 0},A=oA(b[1]||"",y);return b[0]+"?"+A}function fa(r,e){return r.filter(t=>e.includes(t)).length===r.length}function Nb(r){return Object.fromEntries(r.entries())}function Cb(r){return new Map(Object.entries(r))}function oa(r=xe.FIVE_MINUTES,e){const t=xe.toMiliseconds(r||xe.FIVE_MINUTES);let i,n,a;return{resolve:f=>{a&&i&&(clearTimeout(a),i(f))},reject:f=>{a&&n&&(clearTimeout(a),n(f))},done:()=>new Promise((f,u)=>{a=setTimeout(()=>{u(new Error(e))},t),i=f,n=u})}}function Za(r,e,t){return new Promise(async(i,n)=>{const a=setTimeout(()=>n(new Error(t)),e);try{const f=await r;i(f)}catch(f){n(f)}clearTimeout(a)})}function Tb(r,e){if(typeof e=="string"&&e.startsWith(`${r}:`))return e;if(r.toLowerCase()==="topic"){if(typeof e!="string")throw new Error('Value must be "string" for expirer target type: topic');return`topic:${e}`}else if(r.toLowerCase()==="id"){if(typeof e!="number")throw new Error('Value must be "number" for expirer target type: id');return`id:${e}`}throw new Error(`Unknown expirer target type: ${r}`)}function uA(r){return Tb("topic",r)}function lA(r){return Tb("id",r)}function Db(r){const[e,t]=r.split(":"),i={id:void 0,topic:void 0};if(e==="topic"&&typeof t=="string")i.topic=t;else if(e==="id"&&Number.isInteger(Number(t)))i.id=Number(t);else throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${t}`);return i}function vr(r,e){return xe.fromMiliseconds(Date.now()+xe.toMiliseconds(r))}function Rs(r){return Date.now()>=xe.toMiliseconds(r)}function St(r,e){return`${r}${e?`:${e}`:""}`}function Qf(r=[],e=[]){return[...new Set([...r,...e])]}async function dA({id:r,topic:e,wcDeepLink:t}){var i;try{if(!t)return;const n=typeof t=="string"?JSON.parse(t):t,a=n==null?void 0:n.href;if(typeof a!="string")return;const f=pA(a,r,e),u=Ic();if(u===wi.browser){if(!((i=Ih())!=null&&i.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}f.startsWith("https://")||f.startsWith("http://")?window.open(f,"_blank","noreferrer noopener"):window.open(f,vA()?"_blank":"_self","noreferrer noopener")}else u===wi.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(f)}catch(n){console.error(n)}}function pA(r,e,t){const i=`requestId=${e}&sessionTopic=${t}`;r.endsWith("/")&&(r=r.slice(0,-1));let n=`${r}`;if(r.startsWith("https://t.me")){const a=r.includes("?")?"&startapp=":"?startapp=";n=`${n}${a}${bA(i,!0)}`}else n=`${n}/wc?${i}`;return n}async function gA(r,e){let t="";try{if(Sc()&&(t=localStorage.getItem(e),t))return t;t=await r.getItem(e)}catch(i){console.error(i)}return t}function q1(r,e){if(!r.includes(e))return null;const t=r.split(/([&,?,=])/),i=t.indexOf(e);return t[i+2]}function L1(){return typeof crypto<"u"&&crypto!=null&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/gu,r=>{const e=Math.random()*16|0;return(r==="x"?e:e&3|8).toString(16)})}function z0(){return typeof process<"u"&&Z9.IS_VITEST==="true"}function vA(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function bA(r,e=!1){const t=Buffer.from(r).toString("base64");return e?t.replace(/[=]/g,""):t}function Fb(r){return Buffer.from(r,"base64").toString("utf-8")}var Bb=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function mA(r){var e=r.default;if(typeof e=="function"){var t=function(){return e.apply(this,arguments)};t.prototype=e.prototype}else t={};return Object.defineProperty(t,"__esModule",{value:!0}),Object.keys(r).forEach(function(i){var n=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(t,i,n.get?n:{enumerable:!0,get:function(){return r[i]}})}),t}var qb={exports:{}};/** * [js-sha3]{@link https://github.com/emn178/js-sha3} * * @version 0.8.0 * @author Chen, Yi-Cyuan [emn178@gmail.com] * @copyright Chen, Yi-Cyuan 2015-2018 * @license MIT */(function(r){(function(){var e="input is invalid type",t="finalize already called",i=typeof window=="object",n=i?window:{};n.JS_SHA3_NO_WINDOW&&(i=!1);var a=!i&&typeof self=="object",f=!n.JS_SHA3_NO_NODE_JS&&typeof process=="object"&&process.versions&&process.versions.node;f?n=Bb:a&&(n=self);var u=!n.JS_SHA3_NO_COMMON_JS&&!0&&r.exports,b=!n.JS_SHA3_NO_ARRAY_BUFFER&&typeof ArrayBuffer<"u",p="0123456789abcdef".split(""),y=[31,7936,2031616,520093696],A=[4,1024,262144,67108864],R=[1,256,65536,16777216],O=[6,1536,393216,100663296],N=[0,8,16,24],K=[1,0,32898,0,32906,2147483648,2147516416,2147483648,32907,0,2147483649,0,2147516545,2147483648,32777,2147483648,138,0,136,0,2147516425,0,2147483658,0,2147516555,0,139,2147483648,32905,2147483648,32771,2147483648,32770,2147483648,128,2147483648,32778,0,2147483658,2147483648,2147516545,2147483648,32896,2147483648,2147483649,0,2147516424,2147483648],W=[224,256,384,512],Q=[128,256],j=["hex","buffer","arrayBuffer","array","digest"],Y={128:168,256:136};(n.JS_SHA3_NO_NODE_JS||!Array.isArray)&&(Array.isArray=function(P){return Object.prototype.toString.call(P)==="[object Array]"}),b&&(n.JS_SHA3_NO_ARRAY_BUFFER_IS_VIEW||!ArrayBuffer.isView)&&(ArrayBuffer.isView=function(P){return typeof P=="object"&&P.buffer&&P.buffer.constructor===ArrayBuffer});for(var U=function(P,ee,q){return function(z){return new T(P,ee,P).update(z)[q]()}},k=function(P,ee,q){return function(z,H){return new T(P,ee,H).update(z)[q]()}},G=function(P,ee,q){return function(z,H,w,$){return h["cshake"+P].update(z,H,w,$)[q]()}},x=function(P,ee,q){return function(z,H,w,$){return h["kmac"+P].update(z,H,w,$)[q]()}},B=function(P,ee,q,z){for(var H=0;H>5,this.byteCount=this.blockCount<<2,this.outputBlocks=q>>5,this.extraBytes=(q&31)>>3;for(var z=0;z<50;++z)this.s[z]=0}T.prototype.update=function(P){if(this.finalized)throw new Error(t);var ee,q=typeof P;if(q!=="string"){if(q==="object"){if(P===null)throw new Error(e);if(b&&P.constructor===ArrayBuffer)P=new Uint8Array(P);else if(!Array.isArray(P)&&(!b||!ArrayBuffer.isView(P)))throw new Error(e)}else throw new Error(e);ee=!0}for(var z=this.blocks,H=this.byteCount,w=P.length,$=this.blockCount,ne=0,ce=this.s,he,ye;ne>2]|=P[ne]<>2]|=ye<>2]|=(192|ye>>6)<>2]|=(128|ye&63)<=57344?(z[he>>2]|=(224|ye>>12)<>2]|=(128|ye>>6&63)<>2]|=(128|ye&63)<>2]|=(240|ye>>18)<>2]|=(128|ye>>12&63)<>2]|=(128|ye>>6&63)<>2]|=(128|ye&63)<=H){for(this.start=he-H,this.block=z[$],he=0;he<$;++he)ce[he]^=z[he];se(ce),this.reset=!0}else this.start=he}return this},T.prototype.encode=function(P,ee){var q=P&255,z=1,H=[q];for(P=P>>8,q=P&255;q>0;)H.unshift(q),P=P>>8,q=P&255,++z;return ee?H.push(z):H.unshift(z),this.update(H),H.length},T.prototype.encodeString=function(P){var ee,q=typeof P;if(q!=="string"){if(q==="object"){if(P===null)throw new Error(e);if(b&&P.constructor===ArrayBuffer)P=new Uint8Array(P);else if(!Array.isArray(P)&&(!b||!ArrayBuffer.isView(P)))throw new Error(e)}else throw new Error(e);ee=!0}var z=0,H=P.length;if(ee)z=H;else for(var w=0;w=57344?z+=3:($=65536+(($&1023)<<10|P.charCodeAt(++w)&1023),z+=4)}return z+=this.encode(z*8),this.update(P),z},T.prototype.bytepad=function(P,ee){for(var q=this.encode(ee),z=0;z>2]|=this.padding[ee&3],this.lastByteIndex===this.byteCount)for(P[0]=P[q],ee=1;ee>4&15]+p[ne&15]+p[ne>>12&15]+p[ne>>8&15]+p[ne>>20&15]+p[ne>>16&15]+p[ne>>28&15]+p[ne>>24&15];w%P===0&&(se(ee),H=0)}return z&&(ne=ee[H],$+=p[ne>>4&15]+p[ne&15],z>1&&($+=p[ne>>12&15]+p[ne>>8&15]),z>2&&($+=p[ne>>20&15]+p[ne>>16&15])),$},T.prototype.arrayBuffer=function(){this.finalize();var P=this.blockCount,ee=this.s,q=this.outputBlocks,z=this.extraBytes,H=0,w=0,$=this.outputBits>>3,ne;z?ne=new ArrayBuffer(q+1<<2):ne=new ArrayBuffer($);for(var ce=new Uint32Array(ne);w>8&255,$[ne+2]=ce>>16&255,$[ne+3]=ce>>24&255;w%P===0&&se(ee)}return z&&(ne=w<<2,ce=ee[H],$[ne]=ce&255,z>1&&($[ne+1]=ce>>8&255),z>2&&($[ne+2]=ce>>16&255)),$};function Z(P,ee,q){T.call(this,P,ee,q)}Z.prototype=new T,Z.prototype.finalize=function(){return this.encode(this.outputBits,!0),T.prototype.finalize.call(this)};var se=function(P){var ee,q,z,H,w,$,ne,ce,he,ye,we,Ce,Qe,Oe,Te,Ie,me,Re,De,ve,Ne,Se,be,Le,Me,_e,He,Ve,Ee,Ke,ut,Ge,_t,lt,Je,Et,It,Fe,Xe,tt,Be,et,Ze,$e,ft,rt,ze,it,st,qe,Ye,ht,je,Tt,Dt,at,bt,Cr,Tr,Dr,Fr,Br,er;for(z=0;z<48;z+=2)H=P[0]^P[10]^P[20]^P[30]^P[40],w=P[1]^P[11]^P[21]^P[31]^P[41],$=P[2]^P[12]^P[22]^P[32]^P[42],ne=P[3]^P[13]^P[23]^P[33]^P[43],ce=P[4]^P[14]^P[24]^P[34]^P[44],he=P[5]^P[15]^P[25]^P[35]^P[45],ye=P[6]^P[16]^P[26]^P[36]^P[46],we=P[7]^P[17]^P[27]^P[37]^P[47],Ce=P[8]^P[18]^P[28]^P[38]^P[48],Qe=P[9]^P[19]^P[29]^P[39]^P[49],ee=Ce^($<<1|ne>>>31),q=Qe^(ne<<1|$>>>31),P[0]^=ee,P[1]^=q,P[10]^=ee,P[11]^=q,P[20]^=ee,P[21]^=q,P[30]^=ee,P[31]^=q,P[40]^=ee,P[41]^=q,ee=H^(ce<<1|he>>>31),q=w^(he<<1|ce>>>31),P[2]^=ee,P[3]^=q,P[12]^=ee,P[13]^=q,P[22]^=ee,P[23]^=q,P[32]^=ee,P[33]^=q,P[42]^=ee,P[43]^=q,ee=$^(ye<<1|we>>>31),q=ne^(we<<1|ye>>>31),P[4]^=ee,P[5]^=q,P[14]^=ee,P[15]^=q,P[24]^=ee,P[25]^=q,P[34]^=ee,P[35]^=q,P[44]^=ee,P[45]^=q,ee=ce^(Ce<<1|Qe>>>31),q=he^(Qe<<1|Ce>>>31),P[6]^=ee,P[7]^=q,P[16]^=ee,P[17]^=q,P[26]^=ee,P[27]^=q,P[36]^=ee,P[37]^=q,P[46]^=ee,P[47]^=q,ee=ye^(H<<1|w>>>31),q=we^(w<<1|H>>>31),P[8]^=ee,P[9]^=q,P[18]^=ee,P[19]^=q,P[28]^=ee,P[29]^=q,P[38]^=ee,P[39]^=q,P[48]^=ee,P[49]^=q,Oe=P[0],Te=P[1],rt=P[11]<<4|P[10]>>>28,ze=P[10]<<4|P[11]>>>28,Ve=P[20]<<3|P[21]>>>29,Ee=P[21]<<3|P[20]>>>29,Dr=P[31]<<9|P[30]>>>23,Fr=P[30]<<9|P[31]>>>23,et=P[40]<<18|P[41]>>>14,Ze=P[41]<<18|P[40]>>>14,lt=P[2]<<1|P[3]>>>31,Je=P[3]<<1|P[2]>>>31,Ie=P[13]<<12|P[12]>>>20,me=P[12]<<12|P[13]>>>20,it=P[22]<<10|P[23]>>>22,st=P[23]<<10|P[22]>>>22,Ke=P[33]<<13|P[32]>>>19,ut=P[32]<<13|P[33]>>>19,Br=P[42]<<2|P[43]>>>30,er=P[43]<<2|P[42]>>>30,Tt=P[5]<<30|P[4]>>>2,Dt=P[4]<<30|P[5]>>>2,Et=P[14]<<6|P[15]>>>26,It=P[15]<<6|P[14]>>>26,Re=P[25]<<11|P[24]>>>21,De=P[24]<<11|P[25]>>>21,qe=P[34]<<15|P[35]>>>17,Ye=P[35]<<15|P[34]>>>17,Ge=P[45]<<29|P[44]>>>3,_t=P[44]<<29|P[45]>>>3,Le=P[6]<<28|P[7]>>>4,Me=P[7]<<28|P[6]>>>4,at=P[17]<<23|P[16]>>>9,bt=P[16]<<23|P[17]>>>9,Fe=P[26]<<25|P[27]>>>7,Xe=P[27]<<25|P[26]>>>7,ve=P[36]<<21|P[37]>>>11,Ne=P[37]<<21|P[36]>>>11,ht=P[47]<<24|P[46]>>>8,je=P[46]<<24|P[47]>>>8,$e=P[8]<<27|P[9]>>>5,ft=P[9]<<27|P[8]>>>5,_e=P[18]<<20|P[19]>>>12,He=P[19]<<20|P[18]>>>12,Cr=P[29]<<7|P[28]>>>25,Tr=P[28]<<7|P[29]>>>25,tt=P[38]<<8|P[39]>>>24,Be=P[39]<<8|P[38]>>>24,Se=P[48]<<14|P[49]>>>18,be=P[49]<<14|P[48]>>>18,P[0]=Oe^~Ie&Re,P[1]=Te^~me&De,P[10]=Le^~_e&Ve,P[11]=Me^~He&Ee,P[20]=lt^~Et&Fe,P[21]=Je^~It&Xe,P[30]=$e^~rt&it,P[31]=ft^~ze&st,P[40]=Tt^~at&Cr,P[41]=Dt^~bt&Tr,P[2]=Ie^~Re&ve,P[3]=me^~De&Ne,P[12]=_e^~Ve&Ke,P[13]=He^~Ee&ut,P[22]=Et^~Fe&tt,P[23]=It^~Xe&Be,P[32]=rt^~it&qe,P[33]=ze^~st&Ye,P[42]=at^~Cr&Dr,P[43]=bt^~Tr&Fr,P[4]=Re^~ve&Se,P[5]=De^~Ne&be,P[14]=Ve^~Ke&Ge,P[15]=Ee^~ut&_t,P[24]=Fe^~tt&et,P[25]=Xe^~Be&Ze,P[34]=it^~qe&ht,P[35]=st^~Ye&je,P[44]=Cr^~Dr&Br,P[45]=Tr^~Fr&er,P[6]=ve^~Se&Oe,P[7]=Ne^~be&Te,P[16]=Ke^~Ge&Le,P[17]=ut^~_t&Me,P[26]=tt^~et<,P[27]=Be^~Ze&Je,P[36]=qe^~ht&$e,P[37]=Ye^~je&ft,P[46]=Dr^~Br&Tt,P[47]=Fr^~er&Dt,P[8]=Se^~Oe&Ie,P[9]=be^~Te&me,P[18]=Ge^~Le&_e,P[19]=_t^~Me&He,P[28]=et^~lt&Et,P[29]=Ze^~Je&It,P[38]=ht^~$e&rt,P[39]=je^~ft&ze,P[48]=Br^~Tt&at,P[49]=er^~Dt&bt,P[0]^=K[z],P[1]^=K[z+1]};if(u)r.exports=h;else for(_=0;_{try{if("test".normalize(e)!=="test")throw new Error("bad normalize")}catch{r.push(e)}}),r.length)throw new Error("missing "+r.join(", "));if("é".normalize("NFD")!=="é")throw new Error("broken implementation")}catch(r){return r.message}return null}const j1=_A();var s0;(function(r){r.DEBUG="DEBUG",r.INFO="INFO",r.WARNING="WARNING",r.ERROR="ERROR",r.OFF="OFF"})(s0||(s0={}));var hn;(function(r){r.UNKNOWN_ERROR="UNKNOWN_ERROR",r.NOT_IMPLEMENTED="NOT_IMPLEMENTED",r.UNSUPPORTED_OPERATION="UNSUPPORTED_OPERATION",r.NETWORK_ERROR="NETWORK_ERROR",r.SERVER_ERROR="SERVER_ERROR",r.TIMEOUT="TIMEOUT",r.BUFFER_OVERRUN="BUFFER_OVERRUN",r.NUMERIC_FAULT="NUMERIC_FAULT",r.MISSING_NEW="MISSING_NEW",r.INVALID_ARGUMENT="INVALID_ARGUMENT",r.MISSING_ARGUMENT="MISSING_ARGUMENT",r.UNEXPECTED_ARGUMENT="UNEXPECTED_ARGUMENT",r.CALL_EXCEPTION="CALL_EXCEPTION",r.INSUFFICIENT_FUNDS="INSUFFICIENT_FUNDS",r.NONCE_EXPIRED="NONCE_EXPIRED",r.REPLACEMENT_UNDERPRICED="REPLACEMENT_UNDERPRICED",r.UNPREDICTABLE_GAS_LIMIT="UNPREDICTABLE_GAS_LIMIT",r.TRANSACTION_REPLACED="TRANSACTION_REPLACED",r.ACTION_REJECTED="ACTION_REJECTED"})(hn||(hn={}));const k1="0123456789abcdef";let Or=class gr{constructor(e){Object.defineProperty(this,"version",{enumerable:!0,value:e,writable:!1})}_log(e,t){const i=e.toLowerCase();Xf[i]==null&&this.throwArgumentError("invalid log level name","logLevel",e),!(z1>Xf[i])&&console.log.apply(console,t)}debug(...e){this._log(gr.levels.DEBUG,e)}info(...e){this._log(gr.levels.INFO,e)}warn(...e){this._log(gr.levels.WARNING,e)}makeError(e,t,i){if($1)return this.makeError("censored error",t,{});t||(t=gr.errors.UNKNOWN_ERROR),i||(i={});const n=[];Object.keys(i).forEach(b=>{const p=i[b];try{if(p instanceof Uint8Array){let y="";for(let A=0;A>4],y+=k1[p[A]&15];n.push(b+"=Uint8Array(0x"+y+")")}else n.push(b+"="+JSON.stringify(p))}catch{n.push(b+"="+JSON.stringify(i[b].toString()))}}),n.push(`code=${t}`),n.push(`version=${this.version}`);const a=e;let f="";switch(t){case hn.NUMERIC_FAULT:{f="NUMERIC_FAULT";const b=e;switch(b){case"overflow":case"underflow":case"division-by-zero":f+="-"+b;break;case"negative-power":case"negative-width":f+="-unsupported";break;case"unbound-bitwise-result":f+="-unbound-result";break}break}case hn.CALL_EXCEPTION:case hn.INSUFFICIENT_FUNDS:case hn.MISSING_NEW:case hn.NONCE_EXPIRED:case hn.REPLACEMENT_UNDERPRICED:case hn.TRANSACTION_REPLACED:case hn.UNPREDICTABLE_GAS_LIMIT:f=t;break}f&&(e+=" [ See: https://links.ethers.org/v5-errors-"+f+" ]"),n.length&&(e+=" ("+n.join(", ")+")");const u=new Error(e);return u.reason=a,u.code=t,Object.keys(i).forEach(function(b){u[b]=i[b]}),u}throwError(e,t,i){throw this.makeError(e,t,i)}throwArgumentError(e,t,i){return this.throwError(e,gr.errors.INVALID_ARGUMENT,{argument:t,value:i})}assert(e,t,i,n){e||this.throwError(t,i,n)}assertArgument(e,t,i,n){e||this.throwArgumentError(t,i,n)}checkNormalize(e){j1&&this.throwError("platform missing String.prototype.normalize",gr.errors.UNSUPPORTED_OPERATION,{operation:"String.prototype.normalize",form:j1})}checkSafeUint53(e,t){typeof e=="number"&&(t==null&&(t="value not safe"),(e<0||e>=9007199254740991)&&this.throwError(t,gr.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"out-of-safe-range",value:e}),e%1&&this.throwError(t,gr.errors.NUMERIC_FAULT,{operation:"checkSafeInteger",fault:"non-integer",value:e}))}checkArgumentCount(e,t,i){i?i=": "+i:i="",et&&this.throwError("too many arguments"+i,gr.errors.UNEXPECTED_ARGUMENT,{count:e,expectedCount:t})}checkNew(e,t){(e===Object||e==null)&&this.throwError("missing new",gr.errors.MISSING_NEW,{name:t.name})}checkAbstract(e,t){e===t?this.throwError("cannot instantiate abstract class "+JSON.stringify(t.name)+" directly; use a sub-class",gr.errors.UNSUPPORTED_OPERATION,{name:e.name,operation:"new"}):(e===Object||e==null)&&this.throwError("missing new",gr.errors.MISSING_NEW,{name:t.name})}static globalLogger(){return bl||(bl=new gr(wA)),bl}static setCensorship(e,t){if(!e&&t&&this.globalLogger().throwError("cannot permanently disable censorship",gr.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"}),U1){if(!e)return;this.globalLogger().throwError("error censorship permanent",gr.errors.UNSUPPORTED_OPERATION,{operation:"setCensorship"})}$1=!!e,U1=!!t}static setLogLevel(e){const t=Xf[e.toLowerCase()];if(t==null){gr.globalLogger().warn("invalid log level - "+e);return}z1=t}static from(e){return new gr(e)}};Or.errors=hn,Or.levels=s0;const AA="bytes/5.7.0",cr=new Or(AA);function Lb(r){return!!r.toHexString}function eo(r){return r.slice||(r.slice=function(){const e=Array.prototype.slice.call(arguments);return eo(new Uint8Array(Array.prototype.slice.apply(r,e)))}),r}function EA(r){return _i(r)&&!(r.length%2)||bo(r)}function H1(r){return typeof r=="number"&&r==r&&r%1===0}function bo(r){if(r==null)return!1;if(r.constructor===Uint8Array)return!0;if(typeof r=="string"||!H1(r.length)||r.length<0)return!1;for(let e=0;e=256)return!1}return!0}function ir(r,e){if(e||(e={}),typeof r=="number"){cr.checkSafeUint53(r,"invalid arrayify value");const t=[];for(;r;)t.unshift(r&255),r=parseInt(String(r/256));return t.length===0&&t.push(0),eo(new Uint8Array(t))}if(e.allowMissingPrefix&&typeof r=="string"&&r.substring(0,2)!=="0x"&&(r="0x"+r),Lb(r)&&(r=r.toHexString()),_i(r)){let t=r.substring(2);t.length%2&&(e.hexPad==="left"?t="0"+t:e.hexPad==="right"?t+="0":cr.throwArgumentError("hex data is odd-length","value",r));const i=[];for(let n=0;nir(n)),t=e.reduce((n,a)=>n+a.length,0),i=new Uint8Array(t);return e.reduce((n,a)=>(i.set(a,n),n+a.length),0),eo(i)}function SA(r,e){r=ir(r),r.length>e&&cr.throwArgumentError("value out of range","value",arguments[0]);const t=new Uint8Array(e);return t.set(r,e-r.length),eo(t)}function _i(r,e){return!(typeof r!="string"||!r.match(/^0x[0-9A-Fa-f]*$/)||e&&r.length!==2+2*e)}const ml="0123456789abcdef";function ci(r,e){if(e||(e={}),typeof r=="number"){cr.checkSafeUint53(r,"invalid hexlify value");let t="";for(;r;)t=ml[r&15]+t,r=Math.floor(r/16);return t.length?(t.length%2&&(t="0"+t),"0x"+t):"0x00"}if(typeof r=="bigint")return r=r.toString(16),r.length%2?"0x0"+r:"0x"+r;if(e.allowMissingPrefix&&typeof r=="string"&&r.substring(0,2)!=="0x"&&(r="0x"+r),Lb(r))return r.toHexString();if(_i(r))return r.length%2&&(e.hexPad==="left"?r="0x0"+r.substring(2):e.hexPad==="right"?r+="0":cr.throwArgumentError("hex data is odd-length","value",r)),r.toLowerCase();if(bo(r)){let t="0x";for(let i=0;i>4]+ml[n&15]}return t}return cr.throwArgumentError("invalid hexlify value","value",r)}function IA(r){if(typeof r!="string")r=ci(r);else if(!_i(r)||r.length%2)return null;return(r.length-2)/2}function K1(r,e,t){return typeof r!="string"?r=ci(r):(!_i(r)||r.length%2)&&cr.throwArgumentError("invalid hexData","value",r),e=2+2*e,t!=null?"0x"+r.substring(e,2+2*t):"0x"+r.substring(e)}function Dn(r,e){for(typeof r!="string"?r=ci(r):_i(r)||cr.throwArgumentError("invalid hex string","value",r),r.length>2*e+2&&cr.throwArgumentError("value out of range","value",arguments[1]);r.length<2*e+2;)r="0x0"+r.substring(2);return r}function Ub(r){const e={r:"0x",s:"0x",_vs:"0x",recoveryParam:0,v:0,yParityAndS:"0x",compact:"0x"};if(EA(r)){let t=ir(r);t.length===64?(e.v=27+(t[32]>>7),t[32]&=127,e.r=ci(t.slice(0,32)),e.s=ci(t.slice(32,64))):t.length===65?(e.r=ci(t.slice(0,32)),e.s=ci(t.slice(32,64)),e.v=t[64]):cr.throwArgumentError("invalid signature string","signature",r),e.v<27&&(e.v===0||e.v===1?e.v+=27:cr.throwArgumentError("signature invalid v byte","signature",r)),e.recoveryParam=1-e.v%2,e.recoveryParam&&(t[32]|=128),e._vs=ci(t.slice(32,64))}else{if(e.r=r.r,e.s=r.s,e.v=r.v,e.recoveryParam=r.recoveryParam,e._vs=r._vs,e._vs!=null){const n=SA(ir(e._vs),32);e._vs=ci(n);const a=n[0]>=128?1:0;e.recoveryParam==null?e.recoveryParam=a:e.recoveryParam!==a&&cr.throwArgumentError("signature recoveryParam mismatch _vs","signature",r),n[0]&=127;const f=ci(n);e.s==null?e.s=f:e.s!==f&&cr.throwArgumentError("signature v mismatch _vs","signature",r)}if(e.recoveryParam==null)e.v==null?cr.throwArgumentError("signature missing v and recoveryParam","signature",r):e.v===0||e.v===1?e.recoveryParam=e.v:e.recoveryParam=1-e.v%2;else if(e.v==null)e.v=27+e.recoveryParam;else{const n=e.v===0||e.v===1?e.v:1-e.v%2;e.recoveryParam!==n&&cr.throwArgumentError("signature recoveryParam mismatch v","signature",r)}e.r==null||!_i(e.r)?cr.throwArgumentError("signature missing or invalid r","signature",r):e.r=Dn(e.r,32),e.s==null||!_i(e.s)?cr.throwArgumentError("signature missing or invalid s","signature",r):e.s=Dn(e.s,32);const t=ir(e.s);t[0]>=128&&cr.throwArgumentError("signature s out of range","signature",r),e.recoveryParam&&(t[0]|=128);const i=ci(t);e._vs&&(_i(e._vs)||cr.throwArgumentError("signature invalid _vs","signature",r),e._vs=Dn(e._vs,32)),e._vs==null?e._vs=i:e._vs!==i&&cr.throwArgumentError("signature _vs mismatch v and s","signature",r)}return e.yParityAndS=e._vs,e.compact=e.r+e.yParityAndS.substring(2),e}function j0(r){return"0x"+yA.keccak_256(ir(r))}var $b={exports:{}},MA={},PA=Object.freeze({__proto__:null,default:MA}),OA=mA(PA);(function(r){(function(e,t){function i(c,h){if(!c)throw new Error(h||"Assertion failed")}function n(c,h){c.super_=h;var v=function(){};v.prototype=h.prototype,c.prototype=new v,c.prototype.constructor=c}function a(c,h,v){if(a.isBN(c))return c;this.negative=0,this.words=null,this.length=0,this.red=null,c!==null&&((h==="le"||h==="be")&&(v=h,h=10),this._init(c||0,h||10,v||"be"))}typeof e=="object"?e.exports=a:t.BN=a,a.BN=a,a.wordSize=26;var f;try{typeof window<"u"&&typeof window.Buffer<"u"?f=window.Buffer:f=OA.Buffer}catch{}a.isBN=function(c){return c instanceof a?!0:c!==null&&typeof c=="object"&&c.constructor.wordSize===a.wordSize&&Array.isArray(c.words)},a.max=function(c,h){return c.cmp(h)>0?c:h},a.min=function(c,h){return c.cmp(h)<0?c:h},a.prototype._init=function(c,h,v){if(typeof c=="number")return this._initNumber(c,h,v);if(typeof c=="object")return this._initArray(c,h,v);h==="hex"&&(h=16),i(h===(h|0)&&h>=2&&h<=36),c=c.toString().replace(/\s+/g,"");var _=0;c[0]==="-"&&(_++,this.negative=1),_=0;_-=3)M=c[_]|c[_-1]<<8|c[_-2]<<16,this.words[I]|=M<>>26-S&67108863,S+=24,S>=26&&(S-=26,I++);else if(v==="le")for(_=0,I=0;_>>26-S&67108863,S+=24,S>=26&&(S-=26,I++);return this._strip()};function u(c,h){var v=c.charCodeAt(h);if(v>=48&&v<=57)return v-48;if(v>=65&&v<=70)return v-55;if(v>=97&&v<=102)return v-87;i(!1,"Invalid character in "+c)}function b(c,h,v){var _=u(c,v);return v-1>=h&&(_|=u(c,v-1)<<4),_}a.prototype._parseHex=function(c,h,v){this.length=Math.ceil((c.length-h)/6),this.words=new Array(this.length);for(var _=0;_=h;_-=2)S=b(c,h,_)<=18?(I-=18,M+=1,this.words[M]|=S>>>26):I+=8;else{var d=c.length-h;for(_=d%2===0?h+1:h;_=18?(I-=18,M+=1,this.words[M]|=S>>>26):I+=8}this._strip()};function p(c,h,v,_){for(var I=0,M=0,S=Math.min(c.length,v),d=h;d=49?M=g-49+10:g>=17?M=g-17+10:M=g,i(g>=0&&M<_,"Invalid character"),I+=M}return I}a.prototype._parseBase=function(c,h,v){this.words=[0],this.length=1;for(var _=0,I=1;I<=67108863;I*=h)_++;_--,I=I/h|0;for(var M=c.length-v,S=M%_,d=Math.min(M,M-S)+v,g=0,T=v;T1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},a.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},typeof Symbol<"u"&&typeof Symbol.for=="function")try{a.prototype[Symbol.for("nodejs.util.inspect.custom")]=A}catch{a.prototype.inspect=A}else a.prototype.inspect=A;function A(){return(this.red?""}var R=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],O=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],N=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];a.prototype.toString=function(c,h){c=c||10,h=h|0||1;var v;if(c===16||c==="hex"){v="";for(var _=0,I=0,M=0;M>>24-_&16777215,_+=2,_>=26&&(_-=26,M--),I!==0||M!==this.length-1?v=R[6-d.length]+d+v:v=d+v}for(I!==0&&(v=I.toString(16)+v);v.length%h!==0;)v="0"+v;return this.negative!==0&&(v="-"+v),v}if(c===(c|0)&&c>=2&&c<=36){var g=O[c],T=N[c];v="";var Z=this.clone();for(Z.negative=0;!Z.isZero();){var se=Z.modrn(T).toString(c);Z=Z.idivn(T),Z.isZero()?v=se+v:v=R[g-se.length]+se+v}for(this.isZero()&&(v="0"+v);v.length%h!==0;)v="0"+v;return this.negative!==0&&(v="-"+v),v}i(!1,"Base should be between 2 and 36")},a.prototype.toNumber=function(){var c=this.words[0];return this.length===2?c+=this.words[1]*67108864:this.length===3&&this.words[2]===1?c+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-c:c},a.prototype.toJSON=function(){return this.toString(16,2)},f&&(a.prototype.toBuffer=function(c,h){return this.toArrayLike(f,c,h)}),a.prototype.toArray=function(c,h){return this.toArrayLike(Array,c,h)};var K=function(c,h){return c.allocUnsafe?c.allocUnsafe(h):new c(h)};a.prototype.toArrayLike=function(c,h,v){this._strip();var _=this.byteLength(),I=v||Math.max(1,_);i(_<=I,"byte array longer than desired length"),i(I>0,"Requested array length <= 0");var M=K(c,I),S=h==="le"?"LE":"BE";return this["_toArrayLike"+S](M,_),M},a.prototype._toArrayLikeLE=function(c,h){for(var v=0,_=0,I=0,M=0;I>8&255),v>16&255),M===6?(v>24&255),_=0,M=0):(_=S>>>24,M+=2)}if(v=0&&(c[v--]=S>>8&255),v>=0&&(c[v--]=S>>16&255),M===6?(v>=0&&(c[v--]=S>>24&255),_=0,M=0):(_=S>>>24,M+=2)}if(v>=0)for(c[v--]=_;v>=0;)c[v--]=0},Math.clz32?a.prototype._countBits=function(c){return 32-Math.clz32(c)}:a.prototype._countBits=function(c){var h=c,v=0;return h>=4096&&(v+=13,h>>>=13),h>=64&&(v+=7,h>>>=7),h>=8&&(v+=4,h>>>=4),h>=2&&(v+=2,h>>>=2),v+h},a.prototype._zeroBits=function(c){if(c===0)return 26;var h=c,v=0;return h&8191||(v+=13,h>>>=13),h&127||(v+=7,h>>>=7),h&15||(v+=4,h>>>=4),h&3||(v+=2,h>>>=2),h&1||v++,v},a.prototype.bitLength=function(){var c=this.words[this.length-1],h=this._countBits(c);return(this.length-1)*26+h};function W(c){for(var h=new Array(c.bitLength()),v=0;v>>I&1}return h}a.prototype.zeroBits=function(){if(this.isZero())return 0;for(var c=0,h=0;hc.length?this.clone().ior(c):c.clone().ior(this)},a.prototype.uor=function(c){return this.length>c.length?this.clone().iuor(c):c.clone().iuor(this)},a.prototype.iuand=function(c){var h;this.length>c.length?h=c:h=this;for(var v=0;vc.length?this.clone().iand(c):c.clone().iand(this)},a.prototype.uand=function(c){return this.length>c.length?this.clone().iuand(c):c.clone().iuand(this)},a.prototype.iuxor=function(c){var h,v;this.length>c.length?(h=this,v=c):(h=c,v=this);for(var _=0;_c.length?this.clone().ixor(c):c.clone().ixor(this)},a.prototype.uxor=function(c){return this.length>c.length?this.clone().iuxor(c):c.clone().iuxor(this)},a.prototype.inotn=function(c){i(typeof c=="number"&&c>=0);var h=Math.ceil(c/26)|0,v=c%26;this._expand(h),v>0&&h--;for(var _=0;_0&&(this.words[_]=~this.words[_]&67108863>>26-v),this._strip()},a.prototype.notn=function(c){return this.clone().inotn(c)},a.prototype.setn=function(c,h){i(typeof c=="number"&&c>=0);var v=c/26|0,_=c%26;return this._expand(v+1),h?this.words[v]=this.words[v]|1<<_:this.words[v]=this.words[v]&~(1<<_),this._strip()},a.prototype.iadd=function(c){var h;if(this.negative!==0&&c.negative===0)return this.negative=0,h=this.isub(c),this.negative^=1,this._normSign();if(this.negative===0&&c.negative!==0)return c.negative=0,h=this.isub(c),c.negative=1,h._normSign();var v,_;this.length>c.length?(v=this,_=c):(v=c,_=this);for(var I=0,M=0;M<_.length;M++)h=(v.words[M]|0)+(_.words[M]|0)+I,this.words[M]=h&67108863,I=h>>>26;for(;I!==0&&M>>26;if(this.length=v.length,I!==0)this.words[this.length]=I,this.length++;else if(v!==this)for(;Mc.length?this.clone().iadd(c):c.clone().iadd(this)},a.prototype.isub=function(c){if(c.negative!==0){c.negative=0;var h=this.iadd(c);return c.negative=1,h._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(c),this.negative=1,this._normSign();var v=this.cmp(c);if(v===0)return this.negative=0,this.length=1,this.words[0]=0,this;var _,I;v>0?(_=this,I=c):(_=c,I=this);for(var M=0,S=0;S>26,this.words[S]=h&67108863;for(;M!==0&&S<_.length;S++)h=(_.words[S]|0)+M,M=h>>26,this.words[S]=h&67108863;if(M===0&&S<_.length&&_!==this)for(;S<_.length;S++)this.words[S]=_.words[S];return this.length=Math.max(this.length,S),_!==this&&(this.negative=1),this._strip()},a.prototype.sub=function(c){return this.clone().isub(c)};function Q(c,h,v){v.negative=h.negative^c.negative;var _=c.length+h.length|0;v.length=_,_=_-1|0;var I=c.words[0]|0,M=h.words[0]|0,S=I*M,d=S&67108863,g=S/67108864|0;v.words[0]=d;for(var T=1;T<_;T++){for(var Z=g>>>26,se=g&67108863,P=Math.min(T,h.length-1),ee=Math.max(0,T-c.length+1);ee<=P;ee++){var q=T-ee|0;I=c.words[q]|0,M=h.words[ee]|0,S=I*M+se,Z+=S/67108864|0,se=S&67108863}v.words[T]=se|0,g=Z|0}return g!==0?v.words[T]=g|0:v.length--,v._strip()}var j=function(c,h,v){var _=c.words,I=h.words,M=v.words,S=0,d,g,T,Z=_[0]|0,se=Z&8191,P=Z>>>13,ee=_[1]|0,q=ee&8191,z=ee>>>13,H=_[2]|0,w=H&8191,$=H>>>13,ne=_[3]|0,ce=ne&8191,he=ne>>>13,ye=_[4]|0,we=ye&8191,Ce=ye>>>13,Qe=_[5]|0,Oe=Qe&8191,Te=Qe>>>13,Ie=_[6]|0,me=Ie&8191,Re=Ie>>>13,De=_[7]|0,ve=De&8191,Ne=De>>>13,Se=_[8]|0,be=Se&8191,Le=Se>>>13,Me=_[9]|0,_e=Me&8191,He=Me>>>13,Ve=I[0]|0,Ee=Ve&8191,Ke=Ve>>>13,ut=I[1]|0,Ge=ut&8191,_t=ut>>>13,lt=I[2]|0,Je=lt&8191,Et=lt>>>13,It=I[3]|0,Fe=It&8191,Xe=It>>>13,tt=I[4]|0,Be=tt&8191,et=tt>>>13,Ze=I[5]|0,$e=Ze&8191,ft=Ze>>>13,rt=I[6]|0,ze=rt&8191,it=rt>>>13,st=I[7]|0,qe=st&8191,Ye=st>>>13,ht=I[8]|0,je=ht&8191,Tt=ht>>>13,Dt=I[9]|0,at=Dt&8191,bt=Dt>>>13;v.negative=c.negative^h.negative,v.length=19,d=Math.imul(se,Ee),g=Math.imul(se,Ke),g=g+Math.imul(P,Ee)|0,T=Math.imul(P,Ke);var Cr=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Cr>>>26)|0,Cr&=67108863,d=Math.imul(q,Ee),g=Math.imul(q,Ke),g=g+Math.imul(z,Ee)|0,T=Math.imul(z,Ke),d=d+Math.imul(se,Ge)|0,g=g+Math.imul(se,_t)|0,g=g+Math.imul(P,Ge)|0,T=T+Math.imul(P,_t)|0;var Tr=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Tr>>>26)|0,Tr&=67108863,d=Math.imul(w,Ee),g=Math.imul(w,Ke),g=g+Math.imul($,Ee)|0,T=Math.imul($,Ke),d=d+Math.imul(q,Ge)|0,g=g+Math.imul(q,_t)|0,g=g+Math.imul(z,Ge)|0,T=T+Math.imul(z,_t)|0,d=d+Math.imul(se,Je)|0,g=g+Math.imul(se,Et)|0,g=g+Math.imul(P,Je)|0,T=T+Math.imul(P,Et)|0;var Dr=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Dr>>>26)|0,Dr&=67108863,d=Math.imul(ce,Ee),g=Math.imul(ce,Ke),g=g+Math.imul(he,Ee)|0,T=Math.imul(he,Ke),d=d+Math.imul(w,Ge)|0,g=g+Math.imul(w,_t)|0,g=g+Math.imul($,Ge)|0,T=T+Math.imul($,_t)|0,d=d+Math.imul(q,Je)|0,g=g+Math.imul(q,Et)|0,g=g+Math.imul(z,Je)|0,T=T+Math.imul(z,Et)|0,d=d+Math.imul(se,Fe)|0,g=g+Math.imul(se,Xe)|0,g=g+Math.imul(P,Fe)|0,T=T+Math.imul(P,Xe)|0;var Fr=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Fr>>>26)|0,Fr&=67108863,d=Math.imul(we,Ee),g=Math.imul(we,Ke),g=g+Math.imul(Ce,Ee)|0,T=Math.imul(Ce,Ke),d=d+Math.imul(ce,Ge)|0,g=g+Math.imul(ce,_t)|0,g=g+Math.imul(he,Ge)|0,T=T+Math.imul(he,_t)|0,d=d+Math.imul(w,Je)|0,g=g+Math.imul(w,Et)|0,g=g+Math.imul($,Je)|0,T=T+Math.imul($,Et)|0,d=d+Math.imul(q,Fe)|0,g=g+Math.imul(q,Xe)|0,g=g+Math.imul(z,Fe)|0,T=T+Math.imul(z,Xe)|0,d=d+Math.imul(se,Be)|0,g=g+Math.imul(se,et)|0,g=g+Math.imul(P,Be)|0,T=T+Math.imul(P,et)|0;var Br=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Br>>>26)|0,Br&=67108863,d=Math.imul(Oe,Ee),g=Math.imul(Oe,Ke),g=g+Math.imul(Te,Ee)|0,T=Math.imul(Te,Ke),d=d+Math.imul(we,Ge)|0,g=g+Math.imul(we,_t)|0,g=g+Math.imul(Ce,Ge)|0,T=T+Math.imul(Ce,_t)|0,d=d+Math.imul(ce,Je)|0,g=g+Math.imul(ce,Et)|0,g=g+Math.imul(he,Je)|0,T=T+Math.imul(he,Et)|0,d=d+Math.imul(w,Fe)|0,g=g+Math.imul(w,Xe)|0,g=g+Math.imul($,Fe)|0,T=T+Math.imul($,Xe)|0,d=d+Math.imul(q,Be)|0,g=g+Math.imul(q,et)|0,g=g+Math.imul(z,Be)|0,T=T+Math.imul(z,et)|0,d=d+Math.imul(se,$e)|0,g=g+Math.imul(se,ft)|0,g=g+Math.imul(P,$e)|0,T=T+Math.imul(P,ft)|0;var er=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(er>>>26)|0,er&=67108863,d=Math.imul(me,Ee),g=Math.imul(me,Ke),g=g+Math.imul(Re,Ee)|0,T=Math.imul(Re,Ke),d=d+Math.imul(Oe,Ge)|0,g=g+Math.imul(Oe,_t)|0,g=g+Math.imul(Te,Ge)|0,T=T+Math.imul(Te,_t)|0,d=d+Math.imul(we,Je)|0,g=g+Math.imul(we,Et)|0,g=g+Math.imul(Ce,Je)|0,T=T+Math.imul(Ce,Et)|0,d=d+Math.imul(ce,Fe)|0,g=g+Math.imul(ce,Xe)|0,g=g+Math.imul(he,Fe)|0,T=T+Math.imul(he,Xe)|0,d=d+Math.imul(w,Be)|0,g=g+Math.imul(w,et)|0,g=g+Math.imul($,Be)|0,T=T+Math.imul($,et)|0,d=d+Math.imul(q,$e)|0,g=g+Math.imul(q,ft)|0,g=g+Math.imul(z,$e)|0,T=T+Math.imul(z,ft)|0,d=d+Math.imul(se,ze)|0,g=g+Math.imul(se,it)|0,g=g+Math.imul(P,ze)|0,T=T+Math.imul(P,it)|0;var Qr=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,d=Math.imul(ve,Ee),g=Math.imul(ve,Ke),g=g+Math.imul(Ne,Ee)|0,T=Math.imul(Ne,Ke),d=d+Math.imul(me,Ge)|0,g=g+Math.imul(me,_t)|0,g=g+Math.imul(Re,Ge)|0,T=T+Math.imul(Re,_t)|0,d=d+Math.imul(Oe,Je)|0,g=g+Math.imul(Oe,Et)|0,g=g+Math.imul(Te,Je)|0,T=T+Math.imul(Te,Et)|0,d=d+Math.imul(we,Fe)|0,g=g+Math.imul(we,Xe)|0,g=g+Math.imul(Ce,Fe)|0,T=T+Math.imul(Ce,Xe)|0,d=d+Math.imul(ce,Be)|0,g=g+Math.imul(ce,et)|0,g=g+Math.imul(he,Be)|0,T=T+Math.imul(he,et)|0,d=d+Math.imul(w,$e)|0,g=g+Math.imul(w,ft)|0,g=g+Math.imul($,$e)|0,T=T+Math.imul($,ft)|0,d=d+Math.imul(q,ze)|0,g=g+Math.imul(q,it)|0,g=g+Math.imul(z,ze)|0,T=T+Math.imul(z,it)|0,d=d+Math.imul(se,qe)|0,g=g+Math.imul(se,Ye)|0,g=g+Math.imul(P,qe)|0,T=T+Math.imul(P,Ye)|0;var Gi=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Gi>>>26)|0,Gi&=67108863,d=Math.imul(be,Ee),g=Math.imul(be,Ke),g=g+Math.imul(Le,Ee)|0,T=Math.imul(Le,Ke),d=d+Math.imul(ve,Ge)|0,g=g+Math.imul(ve,_t)|0,g=g+Math.imul(Ne,Ge)|0,T=T+Math.imul(Ne,_t)|0,d=d+Math.imul(me,Je)|0,g=g+Math.imul(me,Et)|0,g=g+Math.imul(Re,Je)|0,T=T+Math.imul(Re,Et)|0,d=d+Math.imul(Oe,Fe)|0,g=g+Math.imul(Oe,Xe)|0,g=g+Math.imul(Te,Fe)|0,T=T+Math.imul(Te,Xe)|0,d=d+Math.imul(we,Be)|0,g=g+Math.imul(we,et)|0,g=g+Math.imul(Ce,Be)|0,T=T+Math.imul(Ce,et)|0,d=d+Math.imul(ce,$e)|0,g=g+Math.imul(ce,ft)|0,g=g+Math.imul(he,$e)|0,T=T+Math.imul(he,ft)|0,d=d+Math.imul(w,ze)|0,g=g+Math.imul(w,it)|0,g=g+Math.imul($,ze)|0,T=T+Math.imul($,it)|0,d=d+Math.imul(q,qe)|0,g=g+Math.imul(q,Ye)|0,g=g+Math.imul(z,qe)|0,T=T+Math.imul(z,Ye)|0,d=d+Math.imul(se,je)|0,g=g+Math.imul(se,Tt)|0,g=g+Math.imul(P,je)|0,T=T+Math.imul(P,Tt)|0;var Xr=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Xr>>>26)|0,Xr&=67108863,d=Math.imul(_e,Ee),g=Math.imul(_e,Ke),g=g+Math.imul(He,Ee)|0,T=Math.imul(He,Ke),d=d+Math.imul(be,Ge)|0,g=g+Math.imul(be,_t)|0,g=g+Math.imul(Le,Ge)|0,T=T+Math.imul(Le,_t)|0,d=d+Math.imul(ve,Je)|0,g=g+Math.imul(ve,Et)|0,g=g+Math.imul(Ne,Je)|0,T=T+Math.imul(Ne,Et)|0,d=d+Math.imul(me,Fe)|0,g=g+Math.imul(me,Xe)|0,g=g+Math.imul(Re,Fe)|0,T=T+Math.imul(Re,Xe)|0,d=d+Math.imul(Oe,Be)|0,g=g+Math.imul(Oe,et)|0,g=g+Math.imul(Te,Be)|0,T=T+Math.imul(Te,et)|0,d=d+Math.imul(we,$e)|0,g=g+Math.imul(we,ft)|0,g=g+Math.imul(Ce,$e)|0,T=T+Math.imul(Ce,ft)|0,d=d+Math.imul(ce,ze)|0,g=g+Math.imul(ce,it)|0,g=g+Math.imul(he,ze)|0,T=T+Math.imul(he,it)|0,d=d+Math.imul(w,qe)|0,g=g+Math.imul(w,Ye)|0,g=g+Math.imul($,qe)|0,T=T+Math.imul($,Ye)|0,d=d+Math.imul(q,je)|0,g=g+Math.imul(q,Tt)|0,g=g+Math.imul(z,je)|0,T=T+Math.imul(z,Tt)|0,d=d+Math.imul(se,at)|0,g=g+Math.imul(se,bt)|0,g=g+Math.imul(P,at)|0,T=T+Math.imul(P,bt)|0;var Wi=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Wi>>>26)|0,Wi&=67108863,d=Math.imul(_e,Ge),g=Math.imul(_e,_t),g=g+Math.imul(He,Ge)|0,T=Math.imul(He,_t),d=d+Math.imul(be,Je)|0,g=g+Math.imul(be,Et)|0,g=g+Math.imul(Le,Je)|0,T=T+Math.imul(Le,Et)|0,d=d+Math.imul(ve,Fe)|0,g=g+Math.imul(ve,Xe)|0,g=g+Math.imul(Ne,Fe)|0,T=T+Math.imul(Ne,Xe)|0,d=d+Math.imul(me,Be)|0,g=g+Math.imul(me,et)|0,g=g+Math.imul(Re,Be)|0,T=T+Math.imul(Re,et)|0,d=d+Math.imul(Oe,$e)|0,g=g+Math.imul(Oe,ft)|0,g=g+Math.imul(Te,$e)|0,T=T+Math.imul(Te,ft)|0,d=d+Math.imul(we,ze)|0,g=g+Math.imul(we,it)|0,g=g+Math.imul(Ce,ze)|0,T=T+Math.imul(Ce,it)|0,d=d+Math.imul(ce,qe)|0,g=g+Math.imul(ce,Ye)|0,g=g+Math.imul(he,qe)|0,T=T+Math.imul(he,Ye)|0,d=d+Math.imul(w,je)|0,g=g+Math.imul(w,Tt)|0,g=g+Math.imul($,je)|0,T=T+Math.imul($,Tt)|0,d=d+Math.imul(q,at)|0,g=g+Math.imul(q,bt)|0,g=g+Math.imul(z,at)|0,T=T+Math.imul(z,bt)|0;var Ji=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Ji>>>26)|0,Ji&=67108863,d=Math.imul(_e,Je),g=Math.imul(_e,Et),g=g+Math.imul(He,Je)|0,T=Math.imul(He,Et),d=d+Math.imul(be,Fe)|0,g=g+Math.imul(be,Xe)|0,g=g+Math.imul(Le,Fe)|0,T=T+Math.imul(Le,Xe)|0,d=d+Math.imul(ve,Be)|0,g=g+Math.imul(ve,et)|0,g=g+Math.imul(Ne,Be)|0,T=T+Math.imul(Ne,et)|0,d=d+Math.imul(me,$e)|0,g=g+Math.imul(me,ft)|0,g=g+Math.imul(Re,$e)|0,T=T+Math.imul(Re,ft)|0,d=d+Math.imul(Oe,ze)|0,g=g+Math.imul(Oe,it)|0,g=g+Math.imul(Te,ze)|0,T=T+Math.imul(Te,it)|0,d=d+Math.imul(we,qe)|0,g=g+Math.imul(we,Ye)|0,g=g+Math.imul(Ce,qe)|0,T=T+Math.imul(Ce,Ye)|0,d=d+Math.imul(ce,je)|0,g=g+Math.imul(ce,Tt)|0,g=g+Math.imul(he,je)|0,T=T+Math.imul(he,Tt)|0,d=d+Math.imul(w,at)|0,g=g+Math.imul(w,bt)|0,g=g+Math.imul($,at)|0,T=T+Math.imul($,bt)|0;var Zr=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Zr>>>26)|0,Zr&=67108863,d=Math.imul(_e,Fe),g=Math.imul(_e,Xe),g=g+Math.imul(He,Fe)|0,T=Math.imul(He,Xe),d=d+Math.imul(be,Be)|0,g=g+Math.imul(be,et)|0,g=g+Math.imul(Le,Be)|0,T=T+Math.imul(Le,et)|0,d=d+Math.imul(ve,$e)|0,g=g+Math.imul(ve,ft)|0,g=g+Math.imul(Ne,$e)|0,T=T+Math.imul(Ne,ft)|0,d=d+Math.imul(me,ze)|0,g=g+Math.imul(me,it)|0,g=g+Math.imul(Re,ze)|0,T=T+Math.imul(Re,it)|0,d=d+Math.imul(Oe,qe)|0,g=g+Math.imul(Oe,Ye)|0,g=g+Math.imul(Te,qe)|0,T=T+Math.imul(Te,Ye)|0,d=d+Math.imul(we,je)|0,g=g+Math.imul(we,Tt)|0,g=g+Math.imul(Ce,je)|0,T=T+Math.imul(Ce,Tt)|0,d=d+Math.imul(ce,at)|0,g=g+Math.imul(ce,bt)|0,g=g+Math.imul(he,at)|0,T=T+Math.imul(he,bt)|0;var Si=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Si>>>26)|0,Si&=67108863,d=Math.imul(_e,Be),g=Math.imul(_e,et),g=g+Math.imul(He,Be)|0,T=Math.imul(He,et),d=d+Math.imul(be,$e)|0,g=g+Math.imul(be,ft)|0,g=g+Math.imul(Le,$e)|0,T=T+Math.imul(Le,ft)|0,d=d+Math.imul(ve,ze)|0,g=g+Math.imul(ve,it)|0,g=g+Math.imul(Ne,ze)|0,T=T+Math.imul(Ne,it)|0,d=d+Math.imul(me,qe)|0,g=g+Math.imul(me,Ye)|0,g=g+Math.imul(Re,qe)|0,T=T+Math.imul(Re,Ye)|0,d=d+Math.imul(Oe,je)|0,g=g+Math.imul(Oe,Tt)|0,g=g+Math.imul(Te,je)|0,T=T+Math.imul(Te,Tt)|0,d=d+Math.imul(we,at)|0,g=g+Math.imul(we,bt)|0,g=g+Math.imul(Ce,at)|0,T=T+Math.imul(Ce,bt)|0;var Ii=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Ii>>>26)|0,Ii&=67108863,d=Math.imul(_e,$e),g=Math.imul(_e,ft),g=g+Math.imul(He,$e)|0,T=Math.imul(He,ft),d=d+Math.imul(be,ze)|0,g=g+Math.imul(be,it)|0,g=g+Math.imul(Le,ze)|0,T=T+Math.imul(Le,it)|0,d=d+Math.imul(ve,qe)|0,g=g+Math.imul(ve,Ye)|0,g=g+Math.imul(Ne,qe)|0,T=T+Math.imul(Ne,Ye)|0,d=d+Math.imul(me,je)|0,g=g+Math.imul(me,Tt)|0,g=g+Math.imul(Re,je)|0,T=T+Math.imul(Re,Tt)|0,d=d+Math.imul(Oe,at)|0,g=g+Math.imul(Oe,bt)|0,g=g+Math.imul(Te,at)|0,T=T+Math.imul(Te,bt)|0;var lr=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(lr>>>26)|0,lr&=67108863,d=Math.imul(_e,ze),g=Math.imul(_e,it),g=g+Math.imul(He,ze)|0,T=Math.imul(He,it),d=d+Math.imul(be,qe)|0,g=g+Math.imul(be,Ye)|0,g=g+Math.imul(Le,qe)|0,T=T+Math.imul(Le,Ye)|0,d=d+Math.imul(ve,je)|0,g=g+Math.imul(ve,Tt)|0,g=g+Math.imul(Ne,je)|0,T=T+Math.imul(Ne,Tt)|0,d=d+Math.imul(me,at)|0,g=g+Math.imul(me,bt)|0,g=g+Math.imul(Re,at)|0,T=T+Math.imul(Re,bt)|0;var Yi=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Yi>>>26)|0,Yi&=67108863,d=Math.imul(_e,qe),g=Math.imul(_e,Ye),g=g+Math.imul(He,qe)|0,T=Math.imul(He,Ye),d=d+Math.imul(be,je)|0,g=g+Math.imul(be,Tt)|0,g=g+Math.imul(Le,je)|0,T=T+Math.imul(Le,Tt)|0,d=d+Math.imul(ve,at)|0,g=g+Math.imul(ve,bt)|0,g=g+Math.imul(Ne,at)|0,T=T+Math.imul(Ne,bt)|0;var Qi=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Qi>>>26)|0,Qi&=67108863,d=Math.imul(_e,je),g=Math.imul(_e,Tt),g=g+Math.imul(He,je)|0,T=Math.imul(He,Tt),d=d+Math.imul(be,at)|0,g=g+Math.imul(be,bt)|0,g=g+Math.imul(Le,at)|0,T=T+Math.imul(Le,bt)|0;var Xi=(S+d|0)+((g&8191)<<13)|0;S=(T+(g>>>13)|0)+(Xi>>>26)|0,Xi&=67108863,d=Math.imul(_e,at),g=Math.imul(_e,bt),g=g+Math.imul(He,at)|0,T=Math.imul(He,bt);var js=(S+d|0)+((g&8191)<<13)|0;return S=(T+(g>>>13)|0)+(js>>>26)|0,js&=67108863,M[0]=Cr,M[1]=Tr,M[2]=Dr,M[3]=Fr,M[4]=Br,M[5]=er,M[6]=Qr,M[7]=Gi,M[8]=Xr,M[9]=Wi,M[10]=Ji,M[11]=Zr,M[12]=Si,M[13]=Ii,M[14]=lr,M[15]=Yi,M[16]=Qi,M[17]=Xi,M[18]=js,S!==0&&(M[19]=S,v.length++),v};Math.imul||(j=Q);function Y(c,h,v){v.negative=h.negative^c.negative,v.length=c.length+h.length;for(var _=0,I=0,M=0;M>>26)|0,I+=S>>>26,S&=67108863}v.words[M]=d,_=S,S=I}return _!==0?v.words[M]=_:v.length--,v._strip()}function U(c,h,v){return Y(c,h,v)}a.prototype.mulTo=function(c,h){var v,_=this.length+c.length;return this.length===10&&c.length===10?v=j(this,c,h):_<63?v=Q(this,c,h):_<1024?v=Y(this,c,h):v=U(this,c,h),v},a.prototype.mul=function(c){var h=new a(null);return h.words=new Array(this.length+c.length),this.mulTo(c,h)},a.prototype.mulf=function(c){var h=new a(null);return h.words=new Array(this.length+c.length),U(this,c,h)},a.prototype.imul=function(c){return this.clone().mulTo(c,this)},a.prototype.imuln=function(c){var h=c<0;h&&(c=-c),i(typeof c=="number"),i(c<67108864);for(var v=0,_=0;_>=26,v+=I/67108864|0,v+=M>>>26,this.words[_]=M&67108863}return v!==0&&(this.words[_]=v,this.length++),h?this.ineg():this},a.prototype.muln=function(c){return this.clone().imuln(c)},a.prototype.sqr=function(){return this.mul(this)},a.prototype.isqr=function(){return this.imul(this.clone())},a.prototype.pow=function(c){var h=W(c);if(h.length===0)return new a(1);for(var v=this,_=0;_=0);var h=c%26,v=(c-h)/26,_=67108863>>>26-h<<26-h,I;if(h!==0){var M=0;for(I=0;I>>26-h}M&&(this.words[I]=M,this.length++)}if(v!==0){for(I=this.length-1;I>=0;I--)this.words[I+v]=this.words[I];for(I=0;I=0);var _;h?_=(h-h%26)/26:_=0;var I=c%26,M=Math.min((c-I)/26,this.length),S=67108863^67108863>>>I<M)for(this.length-=M,g=0;g=0&&(T!==0||g>=_);g--){var Z=this.words[g]|0;this.words[g]=T<<26-I|Z>>>I,T=Z&S}return d&&T!==0&&(d.words[d.length++]=T),this.length===0&&(this.words[0]=0,this.length=1),this._strip()},a.prototype.ishrn=function(c,h,v){return i(this.negative===0),this.iushrn(c,h,v)},a.prototype.shln=function(c){return this.clone().ishln(c)},a.prototype.ushln=function(c){return this.clone().iushln(c)},a.prototype.shrn=function(c){return this.clone().ishrn(c)},a.prototype.ushrn=function(c){return this.clone().iushrn(c)},a.prototype.testn=function(c){i(typeof c=="number"&&c>=0);var h=c%26,v=(c-h)/26,_=1<=0);var h=c%26,v=(c-h)/26;if(i(this.negative===0,"imaskn works only with positive numbers"),this.length<=v)return this;if(h!==0&&v++,this.length=Math.min(v,this.length),h!==0){var _=67108863^67108863>>>h<=67108864;h++)this.words[h]-=67108864,h===this.length-1?this.words[h+1]=1:this.words[h+1]++;return this.length=Math.max(this.length,h+1),this},a.prototype.isubn=function(c){if(i(typeof c=="number"),i(c<67108864),c<0)return this.iaddn(-c);if(this.negative!==0)return this.negative=0,this.iaddn(c),this.negative=1,this;if(this.words[0]-=c,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var h=0;h>26)-(d/67108864|0),this.words[I+v]=M&67108863}for(;I>26,this.words[I+v]=M&67108863;if(S===0)return this._strip();for(i(S===-1),S=0,I=0;I>26,this.words[I]=M&67108863;return this.negative=1,this._strip()},a.prototype._wordDiv=function(c,h){var v=this.length-c.length,_=this.clone(),I=c,M=I.words[I.length-1]|0,S=this._countBits(M);v=26-S,v!==0&&(I=I.ushln(v),_.iushln(v),M=I.words[I.length-1]|0);var d=_.length-I.length,g;if(h!=="mod"){g=new a(null),g.length=d+1,g.words=new Array(g.length);for(var T=0;T=0;se--){var P=(_.words[I.length+se]|0)*67108864+(_.words[I.length+se-1]|0);for(P=Math.min(P/M|0,67108863),_._ishlnsubmul(I,P,se);_.negative!==0;)P--,_.negative=0,_._ishlnsubmul(I,1,se),_.isZero()||(_.negative^=1);g&&(g.words[se]=P)}return g&&g._strip(),_._strip(),h!=="div"&&v!==0&&_.iushrn(v),{div:g||null,mod:_}},a.prototype.divmod=function(c,h,v){if(i(!c.isZero()),this.isZero())return{div:new a(0),mod:new a(0)};var _,I,M;return this.negative!==0&&c.negative===0?(M=this.neg().divmod(c,h),h!=="mod"&&(_=M.div.neg()),h!=="div"&&(I=M.mod.neg(),v&&I.negative!==0&&I.iadd(c)),{div:_,mod:I}):this.negative===0&&c.negative!==0?(M=this.divmod(c.neg(),h),h!=="mod"&&(_=M.div.neg()),{div:_,mod:M.mod}):this.negative&c.negative?(M=this.neg().divmod(c.neg(),h),h!=="div"&&(I=M.mod.neg(),v&&I.negative!==0&&I.isub(c)),{div:M.div,mod:I}):c.length>this.length||this.cmp(c)<0?{div:new a(0),mod:this}:c.length===1?h==="div"?{div:this.divn(c.words[0]),mod:null}:h==="mod"?{div:null,mod:new a(this.modrn(c.words[0]))}:{div:this.divn(c.words[0]),mod:new a(this.modrn(c.words[0]))}:this._wordDiv(c,h)},a.prototype.div=function(c){return this.divmod(c,"div",!1).div},a.prototype.mod=function(c){return this.divmod(c,"mod",!1).mod},a.prototype.umod=function(c){return this.divmod(c,"mod",!0).mod},a.prototype.divRound=function(c){var h=this.divmod(c);if(h.mod.isZero())return h.div;var v=h.div.negative!==0?h.mod.isub(c):h.mod,_=c.ushrn(1),I=c.andln(1),M=v.cmp(_);return M<0||I===1&&M===0?h.div:h.div.negative!==0?h.div.isubn(1):h.div.iaddn(1)},a.prototype.modrn=function(c){var h=c<0;h&&(c=-c),i(c<=67108863);for(var v=(1<<26)%c,_=0,I=this.length-1;I>=0;I--)_=(v*_+(this.words[I]|0))%c;return h?-_:_},a.prototype.modn=function(c){return this.modrn(c)},a.prototype.idivn=function(c){var h=c<0;h&&(c=-c),i(c<=67108863);for(var v=0,_=this.length-1;_>=0;_--){var I=(this.words[_]|0)+v*67108864;this.words[_]=I/c|0,v=I%c}return this._strip(),h?this.ineg():this},a.prototype.divn=function(c){return this.clone().idivn(c)},a.prototype.egcd=function(c){i(c.negative===0),i(!c.isZero());var h=this,v=c.clone();h.negative!==0?h=h.umod(c):h=h.clone();for(var _=new a(1),I=new a(0),M=new a(0),S=new a(1),d=0;h.isEven()&&v.isEven();)h.iushrn(1),v.iushrn(1),++d;for(var g=v.clone(),T=h.clone();!h.isZero();){for(var Z=0,se=1;!(h.words[0]&se)&&Z<26;++Z,se<<=1);if(Z>0)for(h.iushrn(Z);Z-- >0;)(_.isOdd()||I.isOdd())&&(_.iadd(g),I.isub(T)),_.iushrn(1),I.iushrn(1);for(var P=0,ee=1;!(v.words[0]&ee)&&P<26;++P,ee<<=1);if(P>0)for(v.iushrn(P);P-- >0;)(M.isOdd()||S.isOdd())&&(M.iadd(g),S.isub(T)),M.iushrn(1),S.iushrn(1);h.cmp(v)>=0?(h.isub(v),_.isub(M),I.isub(S)):(v.isub(h),M.isub(_),S.isub(I))}return{a:M,b:S,gcd:v.iushln(d)}},a.prototype._invmp=function(c){i(c.negative===0),i(!c.isZero());var h=this,v=c.clone();h.negative!==0?h=h.umod(c):h=h.clone();for(var _=new a(1),I=new a(0),M=v.clone();h.cmpn(1)>0&&v.cmpn(1)>0;){for(var S=0,d=1;!(h.words[0]&d)&&S<26;++S,d<<=1);if(S>0)for(h.iushrn(S);S-- >0;)_.isOdd()&&_.iadd(M),_.iushrn(1);for(var g=0,T=1;!(v.words[0]&T)&&g<26;++g,T<<=1);if(g>0)for(v.iushrn(g);g-- >0;)I.isOdd()&&I.iadd(M),I.iushrn(1);h.cmp(v)>=0?(h.isub(v),_.isub(I)):(v.isub(h),I.isub(_))}var Z;return h.cmpn(1)===0?Z=_:Z=I,Z.cmpn(0)<0&&Z.iadd(c),Z},a.prototype.gcd=function(c){if(this.isZero())return c.abs();if(c.isZero())return this.abs();var h=this.clone(),v=c.clone();h.negative=0,v.negative=0;for(var _=0;h.isEven()&&v.isEven();_++)h.iushrn(1),v.iushrn(1);do{for(;h.isEven();)h.iushrn(1);for(;v.isEven();)v.iushrn(1);var I=h.cmp(v);if(I<0){var M=h;h=v,v=M}else if(I===0||v.cmpn(1)===0)break;h.isub(v)}while(!0);return v.iushln(_)},a.prototype.invm=function(c){return this.egcd(c).a.umod(c)},a.prototype.isEven=function(){return(this.words[0]&1)===0},a.prototype.isOdd=function(){return(this.words[0]&1)===1},a.prototype.andln=function(c){return this.words[0]&c},a.prototype.bincn=function(c){i(typeof c=="number");var h=c%26,v=(c-h)/26,_=1<>>26,S&=67108863,this.words[M]=S}return I!==0&&(this.words[M]=I,this.length++),this},a.prototype.isZero=function(){return this.length===1&&this.words[0]===0},a.prototype.cmpn=function(c){var h=c<0;if(this.negative!==0&&!h)return-1;if(this.negative===0&&h)return 1;this._strip();var v;if(this.length>1)v=1;else{h&&(c=-c),i(c<=67108863,"Number is too big");var _=this.words[0]|0;v=_===c?0:_c.length)return 1;if(this.length=0;v--){var _=this.words[v]|0,I=c.words[v]|0;if(_!==I){_I&&(h=1);break}}return h},a.prototype.gtn=function(c){return this.cmpn(c)===1},a.prototype.gt=function(c){return this.cmp(c)===1},a.prototype.gten=function(c){return this.cmpn(c)>=0},a.prototype.gte=function(c){return this.cmp(c)>=0},a.prototype.ltn=function(c){return this.cmpn(c)===-1},a.prototype.lt=function(c){return this.cmp(c)===-1},a.prototype.lten=function(c){return this.cmpn(c)<=0},a.prototype.lte=function(c){return this.cmp(c)<=0},a.prototype.eqn=function(c){return this.cmpn(c)===0},a.prototype.eq=function(c){return this.cmp(c)===0},a.red=function(c){return new F(c)},a.prototype.toRed=function(c){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),c.convertTo(this)._forceRed(c)},a.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},a.prototype._forceRed=function(c){return this.red=c,this},a.prototype.forceRed=function(c){return i(!this.red,"Already a number in reduction context"),this._forceRed(c)},a.prototype.redAdd=function(c){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,c)},a.prototype.redIAdd=function(c){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,c)},a.prototype.redSub=function(c){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,c)},a.prototype.redISub=function(c){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,c)},a.prototype.redShl=function(c){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,c)},a.prototype.redMul=function(c){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,c),this.red.mul(this,c)},a.prototype.redIMul=function(c){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,c),this.red.imul(this,c)},a.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},a.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},a.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},a.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},a.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},a.prototype.redPow=function(c){return i(this.red&&!c.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,c)};var k={k256:null,p224:null,p192:null,p25519:null};function G(c,h){this.name=c,this.p=new a(h,16),this.n=this.p.bitLength(),this.k=new a(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}G.prototype._tmp=function(){var c=new a(null);return c.words=new Array(Math.ceil(this.n/13)),c},G.prototype.ireduce=function(c){var h=c,v;do this.split(h,this.tmp),h=this.imulK(h),h=h.iadd(this.tmp),v=h.bitLength();while(v>this.n);var _=v0?h.isub(this.p):h.strip!==void 0?h.strip():h._strip(),h},G.prototype.split=function(c,h){c.iushrn(this.n,0,h)},G.prototype.imulK=function(c){return c.imul(this.k)};function x(){G.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(x,G),x.prototype.split=function(c,h){for(var v=4194303,_=Math.min(c.length,9),I=0;I<_;I++)h.words[I]=c.words[I];if(h.length=_,c.length<=9){c.words[0]=0,c.length=1;return}var M=c.words[9];for(h.words[h.length++]=M&v,I=10;I>>22,M=S}M>>>=22,c.words[I-10]=M,M===0&&c.length>10?c.length-=10:c.length-=9},x.prototype.imulK=function(c){c.words[c.length]=0,c.words[c.length+1]=0,c.length+=2;for(var h=0,v=0;v>>=26,c.words[v]=I,h=_}return h!==0&&(c.words[c.length++]=h),c},a._prime=function(c){if(k[c])return k[c];var h;if(c==="k256")h=new x;else if(c==="p224")h=new B;else if(c==="p192")h=new ae;else if(c==="p25519")h=new le;else throw new Error("Unknown prime "+c);return k[c]=h,h};function F(c){if(typeof c=="string"){var h=a._prime(c);this.m=h.p,this.prime=h}else i(c.gtn(1),"modulus must be greater than 1"),this.m=c,this.prime=null}F.prototype._verify1=function(c){i(c.negative===0,"red works only with positives"),i(c.red,"red works only with red numbers")},F.prototype._verify2=function(c,h){i((c.negative|h.negative)===0,"red works only with positives"),i(c.red&&c.red===h.red,"red works only with red numbers")},F.prototype.imod=function(c){return this.prime?this.prime.ireduce(c)._forceRed(this):(y(c,c.umod(this.m)._forceRed(this)),c)},F.prototype.neg=function(c){return c.isZero()?c.clone():this.m.sub(c)._forceRed(this)},F.prototype.add=function(c,h){this._verify2(c,h);var v=c.add(h);return v.cmp(this.m)>=0&&v.isub(this.m),v._forceRed(this)},F.prototype.iadd=function(c,h){this._verify2(c,h);var v=c.iadd(h);return v.cmp(this.m)>=0&&v.isub(this.m),v},F.prototype.sub=function(c,h){this._verify2(c,h);var v=c.sub(h);return v.cmpn(0)<0&&v.iadd(this.m),v._forceRed(this)},F.prototype.isub=function(c,h){this._verify2(c,h);var v=c.isub(h);return v.cmpn(0)<0&&v.iadd(this.m),v},F.prototype.shl=function(c,h){return this._verify1(c),this.imod(c.ushln(h))},F.prototype.imul=function(c,h){return this._verify2(c,h),this.imod(c.imul(h))},F.prototype.mul=function(c,h){return this._verify2(c,h),this.imod(c.mul(h))},F.prototype.isqr=function(c){return this.imul(c,c.clone())},F.prototype.sqr=function(c){return this.mul(c,c)},F.prototype.sqrt=function(c){if(c.isZero())return c.clone();var h=this.m.andln(3);if(i(h%2===1),h===3){var v=this.m.add(new a(1)).iushrn(2);return this.pow(c,v)}for(var _=this.m.subn(1),I=0;!_.isZero()&&_.andln(1)===0;)I++,_.iushrn(1);i(!_.isZero());var M=new a(1).toRed(this),S=M.redNeg(),d=this.m.subn(1).iushrn(1),g=this.m.bitLength();for(g=new a(2*g*g).toRed(this);this.pow(g,d).cmp(S)!==0;)g.redIAdd(S);for(var T=this.pow(g,_),Z=this.pow(c,_.addn(1).iushrn(1)),se=this.pow(c,_),P=I;se.cmp(M)!==0;){for(var ee=se,q=0;ee.cmp(M)!==0;q++)ee=ee.redSqr();i(q=0;I--){for(var T=h.words[I],Z=g-1;Z>=0;Z--){var se=T>>Z&1;if(M!==_[0]&&(M=this.sqr(M)),se===0&&S===0){d=0;continue}S<<=1,S|=se,d++,!(d!==v&&(I!==0||Z!==0))&&(M=this.mul(M,_[S]),d=0,S=0)}g=26}return M},F.prototype.convertTo=function(c){var h=c.umod(this.m);return h===c?h.clone():h},F.prototype.convertFrom=function(c){var h=c.clone();return h.red=null,h},a.mont=function(c){return new m(c)};function m(c){F.call(this,c),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new a(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}n(m,F),m.prototype.convertTo=function(c){return this.imod(c.ushln(this.shift))},m.prototype.convertFrom=function(c){var h=this.imod(c.mul(this.rinv));return h.red=null,h},m.prototype.imul=function(c,h){if(c.isZero()||h.isZero())return c.words[0]=0,c.length=1,c;var v=c.imul(h),_=v.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),I=v.isub(_).iushrn(this.shift),M=I;return I.cmp(this.m)>=0?M=I.isub(this.m):I.cmpn(0)<0&&(M=I.iadd(this.m)),M._forceRed(this)},m.prototype.mul=function(c,h){if(c.isZero()||h.isZero())return new a(0)._forceRed(this);var v=c.mul(h),_=v.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),I=v.isub(_).iushrn(this.shift),M=I;return I.cmp(this.m)>=0?M=I.isub(this.m):I.cmpn(0)<0&&(M=I.iadd(this.m)),M._forceRed(this)},m.prototype.invm=function(c){var h=this.imod(c._invmp(this.m).mul(this.r2));return h._forceRed(this)}})(r,Bb)})($b);var vt=$b.exports;const zb="bignumber/5.7.0";var ph=vt.BN;const cs=new Or(zb),yl={},V1=9007199254740991;function RA(r){return r!=null&&(Gt.isBigNumber(r)||typeof r=="number"&&r%1===0||typeof r=="string"&&!!r.match(/^-?[0-9]+$/)||_i(r)||typeof r=="bigint"||bo(r))}let G1=!1;class Gt{constructor(e,t){e!==yl&&cs.throwError("cannot call constructor directly; use BigNumber.from",Or.errors.UNSUPPORTED_OPERATION,{operation:"new (BigNumber)"}),this._hex=t,this._isBigNumber=!0,Object.freeze(this)}fromTwos(e){return si(Pt(this).fromTwos(e))}toTwos(e){return si(Pt(this).toTwos(e))}abs(){return this._hex[0]==="-"?Gt.from(this._hex.substring(1)):this}add(e){return si(Pt(this).add(Pt(e)))}sub(e){return si(Pt(this).sub(Pt(e)))}div(e){return Gt.from(e).isZero()&&Fi("division-by-zero","div"),si(Pt(this).div(Pt(e)))}mul(e){return si(Pt(this).mul(Pt(e)))}mod(e){const t=Pt(e);return t.isNeg()&&Fi("division-by-zero","mod"),si(Pt(this).umod(t))}pow(e){const t=Pt(e);return t.isNeg()&&Fi("negative-power","pow"),si(Pt(this).pow(t))}and(e){const t=Pt(e);return(this.isNegative()||t.isNeg())&&Fi("unbound-bitwise-result","and"),si(Pt(this).and(t))}or(e){const t=Pt(e);return(this.isNegative()||t.isNeg())&&Fi("unbound-bitwise-result","or"),si(Pt(this).or(t))}xor(e){const t=Pt(e);return(this.isNegative()||t.isNeg())&&Fi("unbound-bitwise-result","xor"),si(Pt(this).xor(t))}mask(e){return(this.isNegative()||e<0)&&Fi("negative-width","mask"),si(Pt(this).maskn(e))}shl(e){return(this.isNegative()||e<0)&&Fi("negative-width","shl"),si(Pt(this).shln(e))}shr(e){return(this.isNegative()||e<0)&&Fi("negative-width","shr"),si(Pt(this).shrn(e))}eq(e){return Pt(this).eq(Pt(e))}lt(e){return Pt(this).lt(Pt(e))}lte(e){return Pt(this).lte(Pt(e))}gt(e){return Pt(this).gt(Pt(e))}gte(e){return Pt(this).gte(Pt(e))}isNegative(){return this._hex[0]==="-"}isZero(){return Pt(this).isZero()}toNumber(){try{return Pt(this).toNumber()}catch{Fi("overflow","toNumber",this.toString())}return null}toBigInt(){try{return BigInt(this.toString())}catch{}return cs.throwError("this platform does not support BigInt",Or.errors.UNSUPPORTED_OPERATION,{value:this.toString()})}toString(){return arguments.length>0&&(arguments[0]===10?G1||(G1=!0,cs.warn("BigNumber.toString does not accept any parameters; base-10 is assumed")):arguments[0]===16?cs.throwError("BigNumber.toString does not accept any parameters; use bigNumber.toHexString()",Or.errors.UNEXPECTED_ARGUMENT,{}):cs.throwError("BigNumber.toString does not accept parameters",Or.errors.UNEXPECTED_ARGUMENT,{})),Pt(this).toString(10)}toHexString(){return this._hex}toJSON(e){return{type:"BigNumber",hex:this.toHexString()}}static from(e){if(e instanceof Gt)return e;if(typeof e=="string")return e.match(/^-?0x[0-9a-f]+$/i)?new Gt(yl,pc(e)):e.match(/^-?[0-9]+$/)?new Gt(yl,pc(new ph(e))):cs.throwArgumentError("invalid BigNumber string","value",e);if(typeof e=="number")return e%1&&Fi("underflow","BigNumber.from",e),(e>=V1||e<=-V1)&&Fi("overflow","BigNumber.from",e),Gt.from(String(e));const t=e;if(typeof t=="bigint")return Gt.from(t.toString());if(bo(t))return Gt.from(ci(t));if(t)if(t.toHexString){const i=t.toHexString();if(typeof i=="string")return Gt.from(i)}else{let i=t._hex;if(i==null&&t.type==="BigNumber"&&(i=t.hex),typeof i=="string"&&(_i(i)||i[0]==="-"&&_i(i.substring(1))))return Gt.from(i)}return cs.throwArgumentError("invalid BigNumber value","value",e)}static isBigNumber(e){return!!(e&&e._isBigNumber)}}function pc(r){if(typeof r!="string")return pc(r.toString(16));if(r[0]==="-")return r=r.substring(1),r[0]==="-"&&cs.throwArgumentError("invalid hex","value",r),r=pc(r),r==="0x00"?r:"-"+r;if(r.substring(0,2)!=="0x"&&(r="0x"+r),r==="0x")return"0x00";for(r.length%2&&(r="0x0"+r.substring(2));r.length>4&&r.substring(0,4)==="0x00";)r="0x"+r.substring(4);return r}function si(r){return Gt.from(pc(r))}function Pt(r){const e=Gt.from(r).toHexString();return e[0]==="-"?new ph("-"+e.substring(3),16):new ph(e.substring(2),16)}function Fi(r,e,t){const i={fault:r,operation:e};return t!=null&&(i.value=t),cs.throwError(r,Or.errors.NUMERIC_FAULT,i)}function NA(r){return new ph(r,36).toString(16)}const Wr=new Or(zb),oc={},jb=Gt.from(0),kb=Gt.from(-1);function Hb(r,e,t,i){const n={fault:e,operation:t};return i!==void 0&&(n.value=i),Wr.throwError(r,Or.errors.NUMERIC_FAULT,n)}let cc="0";for(;cc.length<256;)cc+=cc;function k0(r){if(typeof r!="number")try{r=Gt.from(r).toNumber()}catch{}return typeof r=="number"&&r>=0&&r<=256&&!(r%1)?"1"+cc.substring(0,r):Wr.throwArgumentError("invalid decimal size","decimals",r)}function wl(r,e){e==null&&(e=0);const t=k0(e);r=Gt.from(r);const i=r.lt(jb);i&&(r=r.mul(kb));let n=r.mod(t).toString();for(;n.length2&&Wr.throwArgumentError("too many decimal points","value",r);let a=n[0],f=n[1];for(a||(a="0"),f||(f="0");f[f.length-1]==="0";)f=f.substring(0,f.length-1);for(f.length>t.length-1&&Hb("fractional component exceeds decimals","underflow","parseFixed"),f===""&&(f="0");f.lengthe[f]==null?b:(typeof e[f]!==u&&Wr.throwArgumentError("invalid fixed format ("+f+" not "+u+")","format."+f,e[f]),e[f]);t=a("signed","boolean",t),i=a("width","number",i),n=a("decimals","number",n)}return i%8&&Wr.throwArgumentError("invalid fixed format width (not byte aligned)","format.width",i),n>80&&Wr.throwArgumentError("invalid fixed format (decimals too large)","format.decimals",n),new a0(oc,t,i,n)}},Kb=class Vr{constructor(e,t,i,n){e!==oc&&Wr.throwError("cannot use FixedNumber constructor; use FixedNumber.from",Or.errors.UNSUPPORTED_OPERATION,{operation:"new FixedFormat"}),this.format=n,this._hex=t,this._value=i,this._isFixedNumber=!0,Object.freeze(this)}_checkFormat(e){this.format.name!==e.format.name&&Wr.throwArgumentError("incompatible format; use fixedNumber.toFormat","other",e)}addUnsafe(e){this._checkFormat(e);const t=ns(this._value,this.format.decimals),i=ns(e._value,e.format.decimals);return Vr.fromValue(t.add(i),this.format.decimals,this.format)}subUnsafe(e){this._checkFormat(e);const t=ns(this._value,this.format.decimals),i=ns(e._value,e.format.decimals);return Vr.fromValue(t.sub(i),this.format.decimals,this.format)}mulUnsafe(e){this._checkFormat(e);const t=ns(this._value,this.format.decimals),i=ns(e._value,e.format.decimals);return Vr.fromValue(t.mul(i).div(this.format._multiplier),this.format.decimals,this.format)}divUnsafe(e){this._checkFormat(e);const t=ns(this._value,this.format.decimals),i=ns(e._value,e.format.decimals);return Vr.fromValue(t.mul(this.format._multiplier).div(i),this.format.decimals,this.format)}floor(){const e=this.toString().split(".");e.length===1&&e.push("0");let t=Vr.from(e[0],this.format);const i=!e[1].match(/^(0*)$/);return this.isNegative()&&i&&(t=t.subUnsafe(W1.toFormat(t.format))),t}ceiling(){const e=this.toString().split(".");e.length===1&&e.push("0");let t=Vr.from(e[0],this.format);const i=!e[1].match(/^(0*)$/);return!this.isNegative()&&i&&(t=t.addUnsafe(W1.toFormat(t.format))),t}round(e){e==null&&(e=0);const t=this.toString().split(".");if(t.length===1&&t.push("0"),(e<0||e>80||e%1)&&Wr.throwArgumentError("invalid decimal count","decimals",e),t[1].length<=e)return this;const i=Vr.from("1"+cc.substring(0,e),this.format),n=CA.toFormat(this.format);return this.mulUnsafe(i).addUnsafe(n).floor().divUnsafe(i)}isZero(){return this._value==="0.0"||this._value==="0"}isNegative(){return this._value[0]==="-"}toString(){return this._value}toHexString(e){if(e==null)return this._hex;e%8&&Wr.throwArgumentError("invalid byte width","width",e);const t=Gt.from(this._hex).fromTwos(this.format.width).toTwos(e).toHexString();return Dn(t,e/8)}toUnsafeFloat(){return parseFloat(this.toString())}toFormat(e){return Vr.fromString(this._value,e)}static fromValue(e,t,i){return i==null&&t!=null&&!RA(t)&&(i=t,t=null),t==null&&(t=0),i==null&&(i="fixed"),Vr.fromString(wl(e,t),_l.from(i))}static fromString(e,t){t==null&&(t="fixed");const i=_l.from(t),n=ns(e,i.decimals);!i.signed&&n.lt(jb)&&Hb("unsigned value cannot be negative","overflow","value",e);let a=null;i.signed?a=n.toTwos(i.width).toHexString():(a=n.toHexString(),a=Dn(a,i.width/8));const f=wl(n,i.decimals);return new Vr(oc,a,f,i)}static fromBytes(e,t){t==null&&(t="fixed");const i=_l.from(t);if(ir(e).length>i.width/8)throw new Error("overflow");let n=Gt.from(e);i.signed&&(n=n.fromTwos(i.width));const a=n.toTwos((i.signed?0:1)+i.width).toHexString(),f=wl(n,i.decimals);return new Vr(oc,a,f,i)}static from(e,t){if(typeof e=="string")return Vr.fromString(e,t);if(bo(e))return Vr.fromBytes(e,t);try{return Vr.fromValue(e,0,t)}catch(i){if(i.code!==Or.errors.INVALID_ARGUMENT)throw i}return Wr.throwArgumentError("invalid FixedNumber value","value",e)}static isFixedNumber(e){return!!(e&&e._isFixedNumber)}};const W1=Kb.from(1),CA=Kb.from("0.5"),TA="strings/5.7.0",DA=new Or(TA);var gh;(function(r){r.current="",r.NFC="NFC",r.NFD="NFD",r.NFKC="NFKC",r.NFKD="NFKD"})(gh||(gh={}));var J1;(function(r){r.UNEXPECTED_CONTINUE="unexpected continuation byte",r.BAD_PREFIX="bad codepoint prefix",r.OVERRUN="string overrun",r.MISSING_CONTINUE="missing continuation byte",r.OUT_OF_RANGE="out of UTF-8 range",r.UTF16_SURROGATE="UTF-16 surrogate",r.OVERLONG="overlong representation"})(J1||(J1={}));function Al(r,e=gh.current){e!=gh.current&&(DA.checkNormalize(),r=r.normalize(e));let t=[];for(let i=0;i>6|192),t.push(n&63|128);else if((n&64512)==55296){i++;const a=r.charCodeAt(i);if(i>=r.length||(a&64512)!==56320)throw new Error("invalid utf-8 string");const f=65536+((n&1023)<<10)+(a&1023);t.push(f>>18|240),t.push(f>>12&63|128),t.push(f>>6&63|128),t.push(f&63|128)}else t.push(n>>12|224),t.push(n>>6&63|128),t.push(n&63|128)}return ir(t)}function FA(r){if(r.length%4!==0)throw new Error("bad data");let e=[];for(let t=0;t{let a=n.split(":");t+=parseInt(a[0],16),i[t]=e(a[1])}),i}function Y1(r){let e=0;return r.split(",").map(t=>{let i=t.split("-");i.length===1?i[1]="0":i[1]===""&&(i[1]="1");let n=e+parseInt(i[0],16);return e=parseInt(i[1],16),{l:n,h:e}})}Y1("221,13-1b,5f-,40-10,51-f,11-3,3-3,2-2,2-4,8,2,15,2d,28-8,88,48,27-,3-5,11-20,27-,8,28,3-5,12,18,b-a,1c-4,6-16,2-d,2-2,2,1b-4,17-9,8f-,10,f,1f-2,1c-34,33-14e,4,36-,13-,6-2,1a-f,4,9-,3-,17,8,2-2,5-,2,8-,3-,4-8,2-3,3,6-,16-6,2-,7-3,3-,17,8,3,3,3-,2,6-3,3-,4-a,5,2-6,10-b,4,8,2,4,17,8,3,6-,b,4,4-,2-e,2-4,b-10,4,9-,3-,17,8,3-,5-,9-2,3-,4-7,3-3,3,4-3,c-10,3,7-2,4,5-2,3,2,3-2,3-2,4-2,9,4-3,6-2,4,5-8,2-e,d-d,4,9,4,18,b,6-3,8,4,5-6,3-8,3-3,b-11,3,9,4,18,b,6-3,8,4,5-6,3-6,2,3-3,b-11,3,9,4,18,11-3,7-,4,5-8,2-7,3-3,b-11,3,13-2,19,a,2-,8-2,2-3,7,2,9-11,4-b,3b-3,1e-24,3,2-,3,2-,2-5,5,8,4,2,2-,3,e,4-,6,2,7-,b-,3-21,49,23-5,1c-3,9,25,10-,2-2f,23,6,3,8-2,5-5,1b-45,27-9,2a-,2-3,5b-4,45-4,53-5,8,40,2,5-,8,2,5-,28,2,5-,20,2,5-,8,2,5-,8,8,18,20,2,5-,8,28,14-5,1d-22,56-b,277-8,1e-2,52-e,e,8-a,18-8,15-b,e,4,3-b,5e-2,b-15,10,b-5,59-7,2b-555,9d-3,5b-5,17-,7-,27-,7-,9,2,2,2,20-,36,10,f-,7,14-,4,a,54-3,2-6,6-5,9-,1c-10,13-1d,1c-14,3c-,10-6,32-b,240-30,28-18,c-14,a0,115-,3,66-,b-76,5,5-,1d,24,2,5-2,2,8-,35-2,19,f-10,1d-3,311-37f,1b,5a-b,d7-19,d-3,41,57-,68-4,29-3,5f,29-37,2e-2,25-c,2c-2,4e-3,30,78-3,64-,20,19b7-49,51a7-59,48e-2,38-738,2ba5-5b,222f-,3c-94,8-b,6-4,1b,6,2,3,3,6d-20,16e-f,41-,37-7,2e-2,11-f,5-b,18-,b,14,5-3,6,88-,2,bf-2,7-,7-,7-,4-2,8,8-9,8-2ff,20,5-b,1c-b4,27-,27-cbb1,f7-9,28-2,b5-221,56,48,3-,2-,3-,5,d,2,5,3,42,5-,9,8,1d,5,6,2-2,8,153-3,123-3,33-27fd,a6da-5128,21f-5df,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3-fffd,3,2-1d,61-ff7d"),"ad,34f,1806,180b,180c,180d,200b,200c,200d,2060,feff".split(",").map(r=>parseInt(r,16)),El("b5:3bc,c3:ff,7:73,2:253,5:254,3:256,1:257,5:259,1:25b,3:260,1:263,2:269,1:268,5:26f,1:272,2:275,7:280,3:283,5:288,3:28a,1:28b,5:292,3f:195,1:1bf,29:19e,125:3b9,8b:3b2,1:3b8,1:3c5,3:3c6,1:3c0,1a:3ba,1:3c1,1:3c3,2:3b8,1:3b5,1bc9:3b9,1c:1f76,1:1f77,f:1f7a,1:1f7b,d:1f78,1:1f79,1:1f7c,1:1f7d,107:63,5:25b,4:68,1:68,1:68,3:69,1:69,1:6c,3:6e,4:70,1:71,1:72,1:72,1:72,7:7a,2:3c9,2:7a,2:6b,1:e5,1:62,1:63,3:65,1:66,2:6d,b:3b3,1:3c0,6:64,1b574:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3,20:3b8,1a:3c3"),El("179:1,2:1,2:1,5:1,2:1,a:4f,a:1,8:1,2:1,2:1,3:1,5:1,3:1,4:1,2:1,3:1,4:1,8:2,1:1,2:2,1:1,2:2,27:2,195:26,2:25,1:25,1:25,2:40,2:3f,1:3f,33:1,11:-6,1:-9,1ac7:-3a,6d:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,b:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,c:-8,2:-8,2:-8,2:-8,9:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,1:-8,49:-8,1:-8,1:-4a,1:-4a,d:-56,1:-56,1:-56,1:-56,d:-8,1:-8,f:-8,1:-8,3:-7"),El("df:00730073,51:00690307,19:02BC006E,a7:006A030C,18a:002003B9,16:03B903080301,20:03C503080301,1d7:05650582,190f:00680331,1:00740308,1:0077030A,1:0079030A,1:006102BE,b6:03C50313,2:03C503130300,2:03C503130301,2:03C503130342,2a:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F0003B9,1:1F0103B9,1:1F0203B9,1:1F0303B9,1:1F0403B9,1:1F0503B9,1:1F0603B9,1:1F0703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F2003B9,1:1F2103B9,1:1F2203B9,1:1F2303B9,1:1F2403B9,1:1F2503B9,1:1F2603B9,1:1F2703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,1:1F6003B9,1:1F6103B9,1:1F6203B9,1:1F6303B9,1:1F6403B9,1:1F6503B9,1:1F6603B9,1:1F6703B9,3:1F7003B9,1:03B103B9,1:03AC03B9,2:03B10342,1:03B1034203B9,5:03B103B9,6:1F7403B9,1:03B703B9,1:03AE03B9,2:03B70342,1:03B7034203B9,5:03B703B9,6:03B903080300,1:03B903080301,3:03B90342,1:03B903080342,b:03C503080300,1:03C503080301,1:03C10313,2:03C50342,1:03C503080342,b:1F7C03B9,1:03C903B9,1:03CE03B9,2:03C90342,1:03C9034203B9,5:03C903B9,ac:00720073,5b:00B00063,6:00B00066,d:006E006F,a:0073006D,1:00740065006C,1:0074006D,124f:006800700061,2:00610075,2:006F0076,b:00700061,1:006E0061,1:03BC0061,1:006D0061,1:006B0061,1:006B0062,1:006D0062,1:00670062,3:00700066,1:006E0066,1:03BC0066,4:0068007A,1:006B0068007A,1:006D0068007A,1:00670068007A,1:00740068007A,15:00700061,1:006B00700061,1:006D00700061,1:006700700061,8:00700076,1:006E0076,1:03BC0076,1:006D0076,1:006B0076,1:006D0076,1:00700077,1:006E0077,1:03BC0077,1:006D0077,1:006B0077,1:006D0077,1:006B03C9,1:006D03C9,2:00620071,3:00632215006B0067,1:0063006F002E,1:00640062,1:00670079,2:00680070,2:006B006B,1:006B006D,9:00700068,2:00700070006D,1:00700072,2:00730076,1:00770062,c723:00660066,1:00660069,1:0066006C,1:006600660069,1:00660066006C,1:00730074,1:00730074,d:05740576,1:05740565,1:0574056B,1:057E0576,1:0574056D",FA),Y1("80-20,2a0-,39c,32,f71,18e,7f2-f,19-7,30-4,7-5,f81-b,5,a800-20ff,4d1-1f,110,fa-6,d174-7,2e84-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,ffff-,2,1f-5f,ff7f-20001");function BA(r){r=atob(r);const e=[];for(let t=0;t0&&Array.isArray(u)?n(u,f-1):t.push(u)})};return n(r,e),t}function qA(r){const e={};for(let t=0;t>--b&1}const A=31,R=Math.pow(2,A),O=R>>>1,N=O>>1,K=R-1;let W=0;for(let k=0;k1;){let le=G+x>>>1;k>>1|y(),B=B<<1^O,ae=(ae^O)<<1|O|1;j=B,Y=1+ae-B}let U=i-4;return Q.map(k=>{switch(k-U){case 3:return U+65792+(r[u++]<<16|r[u++]<<8|r[u++]);case 2:return U+256+(r[u++]<<8|r[u++]);case 1:return U+r[u++];default:return k-1}})}function UA(r){let e=0;return()=>r[e++]}function $A(r){return UA(LA(r))}function zA(r){return r&1?~r>>1:r>>1}function jA(r,e){let t=Array(r);for(let i=0;ie[f]):t}function HA(r){let e=[];for(;;){let t=r();if(t==0)break;e.push(VA(t,r))}for(;;){let t=r()-1;if(t<0)break;e.push(GA(t,r))}return qA(Vb(e))}function KA(r){let e=[];for(;;){let t=r();if(t==0)break;e.push(t)}return e}function Gb(r,e,t){let i=Array(r).fill(void 0).map(()=>[]);for(let n=0;ni[f].push(a));return i}function VA(r,e){let t=1+e(),i=e(),n=KA(e),a=Gb(n.length,1+r,e);return Vb(a.map((f,u)=>{const b=f[0],p=f.slice(1);return Array(n[u]).fill(void 0).map((y,A)=>{let R=A*i;return[b+A*t,p.map(O=>O+R)]})}))}function GA(r,e){let t=1+e();return Gb(t,1+r,e).map(i=>[i[0],i.slice(1)])}function WA(r){let e=vh(r).sort((i,n)=>i-n);return t();function t(){let i=[];for(;;){let p=vh(r,e);if(p.length==0)break;i.push({set:new Set(p),node:t()})}i.sort((p,y)=>y.set.size-p.set.size);let n=r(),a=n%3;n=n/3|0;let f=!!(n&1);n>>=1;let u=n==1,b=n==2;return{branches:i,valid:a,fe0f:f,save:u,check:b}}}function JA(){return $A(BA("AEQF2AO2DEsA2wIrAGsBRABxAN8AZwCcAEwAqgA0AGwAUgByADcATAAVAFYAIQAyACEAKAAYAFgAGwAjABQAMAAmADIAFAAfABQAKwATACoADgAbAA8AHQAYABoAGQAxADgALAAoADwAEwA9ABMAGgARAA4ADwAWABMAFgAIAA8AHgQXBYMA5BHJAS8JtAYoAe4AExozi0UAH21tAaMnBT8CrnIyhrMDhRgDygIBUAEHcoFHUPe8AXBjAewCjgDQR8IICIcEcQLwATXCDgzvHwBmBoHNAqsBdBcUAykgDhAMShskMgo8AY8jqAQfAUAfHw8BDw87MioGlCIPBwZCa4ELatMAAMspJVgsDl8AIhckSg8XAHdvTwBcIQEiDT4OPhUqbyECAEoAS34Aej8Ybx83JgT/Xw8gHxZ/7w8RICxPHA9vBw+Pfw8PHwAPFv+fAsAvCc8vEr8ivwD/EQ8Bol8OEBa/A78hrwAPCU8vESNvvwWfHwNfAVoDHr+ZAAED34YaAdJPAK7PLwSEgDLHAGo1Pz8Pvx9fUwMrpb8O/58VTzAPIBoXIyQJNF8hpwIVAT8YGAUADDNBaX3RAMomJCg9EhUeA29MABsZBTMNJipjOhc19gcIDR8bBwQHEggCWi6DIgLuAQYA+BAFCha3A5XiAEsqM7UFFgFLhAMjFTMYE1Klnw74nRVBG/ASCm0BYRN/BrsU3VoWy+S0vV8LQx+vN8gF2AC2AK5EAWwApgYDKmAAroQ0NDQ0AT+OCg7wAAIHRAbpNgVcBV0APTA5BfbPFgMLzcYL/QqqA82eBALKCjQCjqYCht0/k2+OAsXQAoP3ASTKDgDw6ACKAUYCMpIKJpRaAE4A5womABzZvs0REEKiACIQAd5QdAECAj4Ywg/wGqY2AVgAYADYvAoCGAEubA0gvAY2ALAAbpbvqpyEAGAEpgQAJgAG7gAgAEACmghUFwCqAMpAINQIwC4DthRAAPcycKgApoIdABwBfCisABoATwBqASIAvhnSBP8aH/ECeAKXAq40NjgDBTwFYQU6AXs3oABgAD4XNgmcCY1eCl5tIFZeUqGgyoNHABgAEQAaABNwWQAmABMATPMa3T34ADldyprmM1M2XociUQgLzvwAXT3xABgAEQAaABNwIGFAnADD8AAgAD4BBJWzaCcIAIEBFMAWwKoAAdq9BWAF5wLQpALEtQAKUSGkahR4GnJM+gsAwCgeFAiUAECQ0BQuL8AAIAAAADKeIheclvFqQAAETr4iAMxIARMgAMIoHhQIAn0E0pDQFC4HhznoAAAAIAI2C0/4lvFqQAAETgBJJwYCAy4ABgYAFAA8MBKYEH4eRhTkAjYeFcgACAYAeABsOqyQ5gRwDayqugEgaIIAtgoACgDmEABmBAWGme5OBJJA2m4cDeoAmITWAXwrMgOgAGwBCh6CBXYF1Tzg1wKAAFdiuABRAFwAXQBsAG8AdgBrAHYAbwCEAHEwfxQBVE5TEQADVFhTBwBDANILAqcCzgLTApQCrQL6vAAMAL8APLhNBKkE6glGKTAU4Dr4N2EYEwBCkABKk8rHAbYBmwIoAiU4Ajf/Aq4CowCAANIChzgaNBsCsTgeODcFXrgClQKdAqQBiQGYAqsCsjTsNHsfNPA0ixsAWTWiOAMFPDQSNCk2BDZHNow2TTZUNhk28Jk9VzI3QkEoAoICoQKwAqcAQAAxBV4FXbS9BW47YkIXP1ciUqs05DS/FwABUwJW11e6nHuYZmSh/RAYA8oMKvZ8KASoUAJYWAJ6ILAsAZSoqjpgA0ocBIhmDgDWAAawRDQoAAcuAj5iAHABZiR2AIgiHgCaAU68ACxuHAG0ygM8MiZIAlgBdF4GagJqAPZOHAMuBgoATkYAsABiAHgAMLoGDPj0HpKEBAAOJgAuALggTAHWAeAMEDbd20Uege0ADwAWADkAQgA9OHd+2MUQZBBhBgNNDkxxPxUQArEPqwvqERoM1irQ090ANK4H8ANYB/ADWANYB/AH8ANYB/ADWANYA1gDWBwP8B/YxRBkD00EcgWTBZAE2wiIJk4RhgctCNdUEnQjHEwDSgEBIypJITuYMxAlR0wRTQgIATZHbKx9PQNMMbBU+pCnA9AyVDlxBgMedhKlAC8PeCE1uk6DekxxpQpQT7NX9wBFBgASqwAS5gBJDSgAUCwGPQBI4zTYABNGAE2bAE3KAExdGABKaAbgAFBXAFCOAFBJABI2SWdObALDOq0//QomCZhvwHdTBkIQHCemEPgMNAG2ATwN7kvZBPIGPATKH34ZGg/OlZ0Ipi3eDO4m5C6igFsj9iqEBe5L9TzeC05RaQ9aC2YJ5DpkgU8DIgEOIowK3g06CG4Q9ArKbA3mEUYHOgPWSZsApgcCCxIdNhW2JhFirQsKOXgG/Br3C5AmsBMqev0F1BoiBk4BKhsAANAu6IWxWjJcHU9gBgQLJiPIFKlQIQ0mQLh4SRocBxYlqgKSQ3FKiFE3HpQh9zw+DWcuFFF9B/Y8BhlQC4I8n0asRQ8R0z6OPUkiSkwtBDaALDAnjAnQD4YMunxzAVoJIgmyDHITMhEYN8YIOgcaLpclJxYIIkaWYJsE+KAD9BPSAwwFQAlCBxQDthwuEy8VKgUOgSXYAvQ21i60ApBWgQEYBcwPJh/gEFFH4Q7qCJwCZgOEJewALhUiABginAhEZABgj9lTBi7MCMhqbSN1A2gU6GIRdAeSDlgHqBw0FcAc4nDJXgyGCSiksAlcAXYJmgFgBOQICjVcjKEgQmdUi1kYnCBiQUBd/QIyDGYVoES+h3kCjA9sEhwBNgF0BzoNAgJ4Ee4RbBCWCOyGBTW2M/k6JgRQIYQgEgooA1BszwsoJvoM+WoBpBJjAw00PnfvZ6xgtyUX/gcaMsZBYSHyC5NPzgydGsIYQ1QvGeUHwAP0GvQn60FYBgADpAQUOk4z7wS+C2oIjAlAAEoOpBgH2BhrCnKM0QEyjAG4mgNYkoQCcJAGOAcMAGgMiAV65gAeAqgIpAAGANADWAA6Aq4HngAaAIZCAT4DKDABIuYCkAOUCDLMAZYwAfQqBBzEDBYA+DhuSwLDsgKAa2ajBd5ZAo8CSjYBTiYEBk9IUgOwcuIA3ABMBhTgSAEWrEvMG+REAeBwLADIAPwABjYHBkIBzgH0bgC4AWALMgmjtLYBTuoqAIQAFmwB2AKKAN4ANgCA8gFUAE4FWvoF1AJQSgESMhksWGIBvAMgATQBDgB6BsyOpsoIIARuB9QCEBwV4gLvLwe2AgMi4BPOQsYCvd9WADIXUu5eZwqoCqdeaAC0YTQHMnM9UQAPH6k+yAdy/BZIiQImSwBQ5gBQQzSaNTFWSTYBpwGqKQK38AFtqwBI/wK37gK3rQK3sAK6280C0gK33AK3zxAAUEIAUD9SklKDArekArw5AEQAzAHCO147WTteO1k7XjtZO147WTteO1kDmChYI03AVU0oJqkKbV9GYewMpw3VRMk6ShPcYFJgMxPJLbgUwhXPJVcZPhq9JwYl5VUKDwUt1GYxCC00dhe9AEApaYNCY4ceMQpMHOhTklT5LRwAskujM7ANrRsWREEFSHXuYisWDwojAmSCAmJDXE6wXDchAqH4AmiZAmYKAp+FOBwMAmY8AmYnBG8EgAN/FAN+kzkHOXgYOYM6JCQCbB4CMjc4CwJtyAJtr/CLADRoRiwBaADfAOIASwYHmQyOAP8MwwAOtgJ3MAJ2o0ACeUxEAni7Hl3cRa9G9AJ8QAJ6yQJ9CgJ88UgBSH5kJQAsFklZSlwWGErNAtECAtDNSygDiFADh+dExpEzAvKiXQQDA69Lz0wuJgTQTU1NsAKLQAKK2cIcCB5EaAa4Ao44Ao5dQZiCAo7aAo5deVG1UzYLUtVUhgKT/AKTDQDqAB1VH1WwVdEHLBwplocy4nhnRTw6ApegAu+zWCKpAFomApaQApZ9nQCqWa1aCoJOADwClrYClk9cRVzSApnMApllXMtdCBoCnJw5wzqeApwXAp+cAp65iwAeEDIrEAKd8gKekwC2PmE1YfACntQCoG8BqgKeoCACnk+mY8lkKCYsAiewAiZ/AqD8AqBN2AKmMAKlzwKoAAB+AqfzaH1osgAESmodatICrOQCrK8CrWgCrQMCVx4CVd0CseLYAx9PbJgCsr4OArLpGGzhbWRtSWADJc4Ctl08QG6RAylGArhfArlIFgK5K3hwN3DiAr0aAy2zAzISAr6JcgMDM3ICvhtzI3NQAsPMAsMFc4N0TDZGdOEDPKgDPJsDPcACxX0CxkgCxhGKAshqUgLIRQLJUALJLwJkngLd03h6YniveSZL0QMYpGcDAmH1GfSVJXsMXpNevBICz2wCz20wTFTT9BSgAMeuAs90ASrrA04TfkwGAtwoAtuLAtJQA1JdA1NgAQIDVY2AikABzBfuYUZ2AILPg44C2sgC2d+EEYRKpz0DhqYAMANkD4ZyWvoAVgLfZgLeuXR4AuIw7RUB8zEoAfScAfLTiALr9ALpcXoAAur6AurlAPpIAboC7ooC652Wq5cEAu5AA4XhmHpw4XGiAvMEAGoDjheZlAL3FAORbwOSiAL3mQL52gL4Z5odmqy8OJsfA52EAv77ARwAOp8dn7QDBY4DpmsDptoA0sYDBmuhiaIGCgMMSgFgASACtgNGAJwEgLpoBgC8BGzAEowcggCEDC6kdjoAJAM0C5IKRoABZCgiAIzw3AYBLACkfng9ogigkgNmWAN6AEQCvrkEVqTGAwCsBRbAA+4iQkMCHR072jI2PTbUNsk2RjY5NvA23TZKNiU3EDcZN5I+RTxDRTBCJkK5VBYKFhZfwQCWygU3AJBRHpu+OytgNxa61A40GMsYjsn7BVwFXQVcBV0FaAVdBVwFXQVcBV0FXAVdBVwFXUsaCNyKAK4AAQUHBwKU7oICoW1e7jAEzgPxA+YDwgCkBFDAwADABKzAAOxFLhitA1UFTDeyPkM+bj51QkRCuwTQWWQ8X+0AWBYzsACNA8xwzAGm7EZ/QisoCTAbLDs6fnLfb8H2GccsbgFw13M1HAVkBW/Jxsm9CNRO8E8FDD0FBQw9FkcClOYCoMFegpDfADgcMiA2AJQACB8AsigKAIzIEAJKeBIApY5yPZQIAKQiHb4fvj5BKSRPQrZCOz0oXyxgOywfKAnGbgMClQaCAkILXgdeCD9IIGUgQj5fPoY+dT52Ao5CM0dAX9BTVG9SDzFwWTQAbxBzJF/lOEIQQglCCkKJIAls5AcClQICoKPMODEFxhi6KSAbiyfIRrMjtCgdWCAkPlFBIitCsEJRzAbMAV/OEyQzDg0OAQQEJ36i328/Mk9AybDJsQlq3tDRApUKAkFzXf1d/j9uALYP6hCoFgCTGD8kPsFKQiobrm0+zj0KSD8kPnVCRBwMDyJRTHFgMTJa5rwXQiQ2YfI/JD7BMEJEHGINTw4TOFlIRzwJO0icMQpyPyQ+wzJCRBv6DVgnKB01NgUKj2bwYzMqCoBkznBgEF+zYDIocwRIX+NgHj4HICNfh2C4CwdwFWpTG/lgUhYGAwRfv2Ts8mAaXzVgml/XYIJfuWC4HI1gUF9pYJZgMR6ilQHMAOwLAlDRefC0in4AXAEJA6PjCwc0IamOANMMCAECRQDFNRTZBgd+CwQlRA+r6+gLBDEFBnwUBXgKATIArwAGRAAHA3cDdAN2A3kDdwN9A3oDdQN7A30DfAN4A3oDfQAYEAAlAtYASwMAUAFsAHcKAHcAmgB3AHUAdQB2AHVu8UgAygDAAHcAdQB1AHYAdQALCgB3AAsAmgB3AAsCOwB3AAtu8UgAygDAAHgKAJoAdwB3AHUAdQB2AHUAeAB1AHUAdgB1bvFIAMoAwAALCgCaAHcACwB3AAsCOwB3AAtu8UgAygDAAH4ACwGgALcBpwC6AahdAu0COwLtbvFIAMoAwAALCgCaAu0ACwLtAAsCOwLtAAtu8UgAygDAA24ACwNvAAu0VsQAAzsAABCkjUIpAAsAUIusOggWcgMeBxVsGwL67U/2HlzmWOEeOgALASvuAAseAfpKUpnpGgYJDCIZM6YyARUE9ThqAD5iXQgnAJYJPnOzw0ZAEZxEKsIAkA4DhAHnTAIDxxUDK0lxCQlPYgIvIQVYJQBVqE1GakUAKGYiDToSBA1EtAYAXQJYAIF8GgMHRyAAIAjOe9YncekRAA0KACUrjwE7Ayc6AAYWAqaiKG4McEcqANoN3+Mg9TwCBhIkuCny+JwUQ29L008JluRxu3K+oAdqiHOqFH0AG5SUIfUJ5SxCGfxdipRzqTmT4V5Zb+r1Uo4Vm+NqSSEl2mNvR2JhIa8SpYO6ntdwFXHCWTCK8f2+Hxo7uiG3drDycAuKIMP5bhi06ACnqArH1rz4Rqg//lm6SgJGEVbF9xJHISaR6HxqxSnkw6shDnelHKNEfGUXSJRJ1GcsmtJw25xrZMDK9gXSm1/YMkdX4/6NKYOdtk/NQ3/NnDASjTc3fPjIjW/5sVfVObX2oTDWkr1dF9f3kxBsD3/3aQO8hPfRz+e0uEiJqt1161griu7gz8hDDwtpy+F+BWtefnKHZPAxcZoWbnznhJpy0e842j36bcNzGnIEusgGX0a8ZxsnjcSsPDZ09yZ36fCQbriHeQ72JRMILNl6ePPf2HWoVwgWAm1fb3V2sAY0+B6rAXqSwPBgseVmoqsBTSrm91+XasMYYySI8eeRxH3ZvHkMz3BQ5aJ3iUVbYPNM3/7emRtjlsMgv/9VyTsyt/mK+8fgWeT6SoFaclXqn42dAIsvAarF5vNNWHzKSkKQ/8Hfk5ZWK7r9yliOsooyBjRhfkHP4Q2DkWXQi6FG/9r/IwbmkV5T7JSopHKn1pJwm9tb5Ot0oyN1Z2mPpKXHTxx2nlK08fKk1hEYA8WgVVWL5lgx0iTv+KdojJeU23ZDjmiubXOxVXJKKi2Wjuh2HLZOFLiSC7Tls5SMh4f+Pj6xUSrNjFqLGehRNB8lC0QSLNmkJJx/wSG3MnjE9T1CkPwJI0wH2lfzwETIiVqUxg0dfu5q39Gt+hwdcxkhhNvQ4TyrBceof3Mhs/IxFci1HmHr4FMZgXEEczPiGCx0HRwzAqDq2j9AVm1kwN0mRVLWLylgtoPNapF5cY4Y1wJh/e0BBwZj44YgZrDNqvD/9Hv7GFYdUQeDJuQ3EWI4HaKqavU1XjC/n41kT4L79kqGq0kLhdTZvgP3TA3fS0ozVz+5piZsoOtIvBUFoMKbNcmBL6YxxaUAusHB38XrS8dQMnQwJfUUkpRoGr5AUeWicvBTzyK9g77+yCkf5PAysL7r/JjcZgrbvRpMW9iyaxZvKO6ceZN2EwIxKwVFPuvFuiEPGCoagbMo+SpydLrXqBzNCDGFCrO/rkcwa2xhokQZ5CdZ0AsU3JfSqJ6n5I14YA+P/uAgfhPU84Tlw7cEFfp7AEE8ey4sP12PTt4Cods1GRgDOB5xvyiR5m+Bx8O5nBCNctU8BevfV5A08x6RHd5jcwPTMDSZJOedIZ1cGQ704lxbAzqZOP05ZxaOghzSdvFBHYqomATARyAADK4elP8Ly3IrUZKfWh23Xy20uBUmLS4Pfagu9+oyVa2iPgqRP3F2CTUsvJ7+RYnN8fFZbU/HVvxvcFFDKkiTqV5UBZ3Gz54JAKByi9hkKMZJvuGgcSYXFmw08UyoQyVdfTD1/dMkCHXcTGAKeROgArsvmRrQTLUOXioOHGK2QkjHuoYFgXciZoTJd6Fs5q1QX1G+p/e26hYsEf7QZD1nnIyl/SFkNtYYmmBhpBrxl9WbY0YpHWRuw2Ll/tj9mD8P4snVzJl4F9J+1arVeTb9E5r2ILH04qStjxQNwn3m4YNqxmaNbLAqW2TN6LidwuJRqS+NXbtqxoeDXpxeGWmxzSkWxjkyCkX4NQRme6q5SAcC+M7+9ETfA/EwrzQajKakCwYyeunP6ZFlxU2oMEn1Pz31zeStW74G406ZJFCl1wAXIoUKkWotYEpOuXB1uVNxJ63dpJEqfxBeptwIHNrPz8BllZoIcBoXwgfJ+8VAUnVPvRvexnw0Ma/WiGYuJO5y8QTvEYBigFmhUxY5RqzE8OcywN/8m4UYrlaniJO75XQ6KSo9+tWHlu+hMi0UVdiKQp7NelnoZUzNaIyBPVeOwK6GNp+FfHuPOoyhaWuNvTYFkvxscMQWDh+zeFCFkgwbXftiV23ywJ4+uwRqmg9k3KzwIQpzppt8DBBOMbrqwQM5Gb05sEwdKzMiAqOloaA/lr0KA+1pr0/+HiWoiIjHA/wir2nIuS3PeU/ji3O6ZwoxcR1SZ9FhtLC5S0FIzFhbBWcGVP/KpxOPSiUoAdWUpqKH++6Scz507iCcxYI6rdMBICPJZea7OcmeFw5mObJSiqpjg2UoWNIs+cFhyDSt6geV5qgi3FunmwwDoGSMgerFOZGX1m0dMCYo5XOruxO063dwENK9DbnVM9wYFREzh4vyU1WYYJ/LRRp6oxgjqP/X5a8/4Af6p6NWkQferzBmXme0zY/4nwMJm/wd1tIqSwGz+E3xPEAOoZlJit3XddD7/BT1pllzOx+8bmQtANQ/S6fZexc6qi3W+Q2xcmXTUhuS5mpHQRvcxZUN0S5+PL9lXWUAaRZhEH8hTdAcuNMMCuVNKTEGtSUKNi3O6KhSaTzck8csZ2vWRZ+d7mW8c4IKwXIYd25S/zIftPkwPzufjEvOHWVD1m+FjpDVUTV0DGDuHj6QnaEwLu/dEgdLQOg9E1Sro9XHJ8ykLAwtPu+pxqKDuFexqON1sKQm7rwbE1E68UCfA/erovrTCG+DBSNg0l4goDQvZN6uNlbyLpcZAwj2UclycvLpIZMgv4yRlpb3YuMftozorbcGVHt/VeDV3+Fdf1TP0iuaCsPi2G4XeGhsyF1ubVDxkoJhmniQ0/jSg/eYML9KLfnCFgISWkp91eauR3IQvED0nAPXK+6hPCYs+n3+hCZbiskmVMG2da+0EsZPonUeIY8EbfusQXjsK/eFDaosbPjEfQS0RKG7yj5GG69M7MeO1HmiUYocgygJHL6M1qzUDDwUSmr99V7Sdr2F3JjQAJY+F0yH33Iv3+C9M38eML7gTgmNu/r2bUMiPvpYbZ6v1/IaESirBHNa7mPKn4dEmYg7v/+HQgPN1G79jBQ1+soydfDC2r+h2Bl/KIc5KjMK7OH6nb1jLsNf0EHVe2KBiE51ox636uyG6Lho0t3J34L5QY/ilE3mikaF4HKXG1mG1rCevT1Vv6GavltxoQe/bMrpZvRggnBxSEPEeEzkEdOxTnPXHVjUYdw8JYvjB/o7Eegc3Ma+NUxLLnsK0kJlinPmUHzHGtrk5+CAbVzFOBqpyy3QVUnzTDfC/0XD94/okH+OB+i7g9lolhWIjSnfIb+Eq43ZXOWmwvjyV/qqD+t0e+7mTEM74qP/Ozt8nmC7mRpyu63OB4KnUzFc074SqoyPUAgM+/TJGFo6T44EHnQU4X4z6qannVqgw/U7zCpwcmXV1AubIrvOmkKHazJAR55ePjp5tLBsN8vAqs3NAHdcEHOR2xQ0lsNAFzSUuxFQCFYvXLZJdOj9p4fNq6p0HBGUik2YzaI4xySy91KzhQ0+q1hjxvImRwPRf76tChlRkhRCi74NXZ9qUNeIwP+s5p+3m5nwPdNOHgSLD79n7O9m1n1uDHiMntq4nkYwV5OZ1ENbXxFd4PgrlvavZsyUO4MqYlqqn1O8W/I1dEZq5dXhrbETLaZIbC2Kj/Aa/QM+fqUOHdf0tXAQ1huZ3cmWECWSXy/43j35+Mvq9xws7JKseriZ1pEWKc8qlzNrGPUGcVgOa9cPJYIJsGnJTAUsEcDOEVULO5x0rXBijc1lgXEzQQKhROf8zIV82w8eswc78YX11KYLWQRcgHNJElBxfXr72lS2RBSl07qTKorO2uUDZr3sFhYsvnhLZn0A94KRzJ/7DEGIAhW5ZWFpL8gEwu1aLA9MuWZzNwl8Oze9Y+bX+v9gywRVnoB5I/8kXTXU3141yRLYrIOOz6SOnyHNy4SieqzkBXharjfjqq1q6tklaEbA8Qfm2DaIPs7OTq/nvJBjKfO2H9bH2cCMh1+5gspfycu8f/cuuRmtDjyqZ7uCIMyjdV3a+p3fqmXsRx4C8lujezIFHnQiVTXLXuI1XrwN3+siYYj2HHTvESUx8DlOTXpak9qFRK+L3mgJ1WsD7F4cu1aJoFoYQnu+wGDMOjJM3kiBQWHCcvhJ/HRdxodOQp45YZaOTA22Nb4XKCVxqkbwMYFhzYQYIAnCW8FW14uf98jhUG2zrKhQQ0q0CEq0t5nXyvUyvR8DvD69LU+g3i+HFWQMQ8PqZuHD+sNKAV0+M6EJC0szq7rEr7B5bQ8BcNHzvDMc9eqB5ZCQdTf80Obn4uzjwpYU7SISdtV0QGa9D3Wrh2BDQtpBKxaNFV+/Cy2P/Sv+8s7Ud0Fd74X4+o/TNztWgETUapy+majNQ68Lq3ee0ZO48VEbTZYiH1Co4OlfWef82RWeyUXo7woM03PyapGfikTnQinoNq5z5veLpeMV3HCAMTaZmA1oGLAn7XS3XYsz+XK7VMQsc4XKrmDXOLU/pSXVNUq8dIqTba///3x6LiLS6xs1xuCAYSfcQ3+rQgmu7uvf3THKt5Ooo97TqcbRqxx7EASizaQCBQllG/rYxVapMLgtLbZS64w1MDBMXX+PQpBKNwqUKOf2DDRDUXQf9EhOS0Qj4nTmlA8dzSLz/G1d+Ud8MTy/6ghhdiLpeerGY/UlDOfiuqFsMUU5/UYlP+BAmgRLuNpvrUaLlVkrqDievNVEAwF+4CoM1MZTmjxjJMsKJq+u8Zd7tNCUFy6LiyYXRJQ4VyvEQFFaCGKsxIwQkk7EzZ6LTJq2hUuPhvAW+gQnSG6J+MszC+7QCRHcnqDdyNRJ6T9xyS87A6MDutbzKGvGktpbXqtzWtXb9HsfK2cBMomjN9a4y+TaJLnXxAeX/HWzmf4cR4vALt/P4w4qgKY04ml4ZdLOinFYS6cup3G/1ie4+t1eOnpBNlqGqs75ilzkT4+DsZQxNvaSKJ//6zIbbk/M7LOhFmRc/1R+kBtz7JFGdZm/COotIdvQoXpTqP/1uqEUmCb/QWoGLMwO5ANcHzxdY48IGP5+J+zKOTBFZ4Pid+GTM+Wq12MV/H86xEJptBa6T+p3kgpwLedManBHC2GgNrFpoN2xnrMz9WFWX/8/ygSBkavq2Uv7FdCsLEYLu9LLIvAU0bNRDtzYl+/vXmjpIvuJFYjmI0im6QEYqnIeMsNjXG4vIutIGHijeAG/9EDBozKV5cldkHbLxHh25vT+ZEzbhXlqvpzKJwcEgfNwLAKFeo0/pvEE10XDB+EXRTXtSzJozQKFFAJhMxYkVaCW+E9AL7tMeU8acxidHqzb6lX4691UsDpy/LLRmT+epgW56+5Cw8tB4kMUv6s9lh3eRKbyGs+H/4mQMaYzPTf2OOdokEn+zzgvoD3FqNKk8QqGAXVsqcGdXrT62fSPkR2vROFi68A6se86UxRUk4cajfPyCC4G5wDhD+zNq4jodQ4u4n/m37Lr36n4LIAAsVr02dFi9AiwA81MYs2rm4eDlDNmdMRvEKRHfBwW5DdMNp0jPFZMeARqF/wL4XBfd+EMLBfMzpH5GH6NaW+1vrvMdg+VxDzatk3MXgO3ro3P/DpcC6+Mo4MySJhKJhSR01SGGGp5hPWmrrUgrv3lDnP+HhcI3nt3YqBoVAVTBAQT5iuhTg8nvPtd8ZeYj6w1x6RqGUBrSku7+N1+BaasZvjTk64RoIDlL8brpEcJx3OmY7jLoZsswdtmhfC/G21llXhITOwmvRDDeTTPbyASOa16cF5/A1fZAidJpqju3wYAy9avPR1ya6eNp9K8XYrrtuxlqi+bDKwlfrYdR0RRiKRVTLOH85+ZY7XSmzRpfZBJjaTa81VDcJHpZnZnSQLASGYW9l51ZV/h7eVzTi3Hv6hUsgc/51AqJRTkpbFVLXXszoBL8nBX0u/0jBLT8nH+fJePbrwURT58OY+UieRjd1vs04w0VG5VN2U6MoGZkQzKN/ptz0Q366dxoTGmj7i1NQGHi9GgnquXFYdrCfZBmeb7s0T6yrdlZH5cZuwHFyIJ/kAtGsTg0xH5taAAq44BAk1CPk9KVVbqQzrCUiFdF/6gtlPQ8bHHc1G1W92MXGZ5HEHftyLYs8mbD/9xYRUWkHmlM0zC2ilJlnNgV4bfALpQghxOUoZL7VTqtCHIaQSXm+YUMnpkXybnV+A6xlm2CVy8fn0Xlm2XRa0+zzOa21JWWmixfiPMSCZ7qA4rS93VN3pkpF1s5TonQjisHf7iU9ZGvUPOAKZcR1pbeVf/Ul7OhepGCaId9wOtqo7pJ7yLcBZ0pFkOF28y4zEI/kcUNmutBHaQpBdNM8vjCS6HZRokkeo88TBAjGyG7SR+6vUgTcyK9Imalj0kuxz0wmK+byQU11AiJFk/ya5dNduRClcnU64yGu/ieWSeOos1t3ep+RPIWQ2pyTYVbZltTbsb7NiwSi3AV+8KLWk7LxCnfZUetEM8ThnsSoGH38/nyAwFguJp8FjvlHtcWZuU4hPva0rHfr0UhOOJ/F6vS62FW7KzkmRll2HEc7oUq4fyi5T70Vl7YVIfsPHUCdHesf9Lk7WNVWO75JDkYbMI8TOW8JKVtLY9d6UJRITO8oKo0xS+o99Yy04iniGHAaGj88kEWgwv0OrHdY/nr76DOGNS59hXCGXzTKUvDl9iKpLSWYN1lxIeyywdNpTkhay74w2jFT6NS8qkjo5CxA1yfSYwp6AJIZNKIeEK5PJAW7ORgWgwp0VgzYpqovMrWxbu+DGZ6Lhie1RAqpzm8VUzKJOH3mCzWuTOLsN3VT/dv2eeYe9UjbR8YTBsLz7q60VN1sU51k+um1f8JxD5pPhbhSC8rRaB454tmh6YUWrJI3+GWY0qeWioj/tbkYITOkJaeuGt4JrJvHA+l0Gu7kY7XOaa05alMnRWVCXqFgLIwSY4uF59Ue5SU4QKuc/HamDxbr0x6csCetXGoP7Qn1Bk/J9DsynO/UD6iZ1Hyrz+jit0hDCwi/E9OjgKTbB3ZQKQ/0ZOvevfNHG0NK4Aj3Cp7NpRk07RT1i/S0EL93Ag8GRgKI9CfpajKyK6+Jj/PI1KO5/85VAwz2AwzP8FTBb075IxCXv6T9RVvWT2tUaqxDS92zrGUbWzUYk9mSs82pECH+fkqsDt93VW++4YsR/dHCYcQSYTO/KaBMDj9LSD/J/+z20Kq8XvZUAIHtm9hRPP3ItbuAu2Hm5lkPs92pd7kCxgRs0xOVBnZ13ccdA0aunrwv9SdqElJRC3g+oCu+nXyCgmXUs9yMjTMAIHfxZV+aPKcZeUBWt057Xo85Ks1Ir5gzEHCWqZEhrLZMuF11ziGtFQUds/EESajhagzcKsxamcSZxGth4UII+adPhQkUnx2WyN+4YWR+r3f8MnkyGFuR4zjzxJS8WsQYR5PTyRaD9ixa6Mh741nBHbzfjXHskGDq179xaRNrCIB1z1xRfWfjqw2pHc1zk9xlPpL8sQWAIuETZZhbnmL54rceXVNRvUiKrrqIkeogsl0XXb17ylNb0f4GA9Wd44vffEG8FSZGHEL2fbaTGRcSiCeA8PmA/f6Hz8HCS76fXUHwgwkzSwlI71ekZ7Fapmlk/KC+Hs8hUcw3N2LN5LhkVYyizYFl/uPeVP5lsoJHhhfWvvSWruCUW1ZcJOeuTbrDgywJ/qG07gZJplnTvLcYdNaH0KMYOYMGX+rB4NGPFmQsNaIwlWrfCezxre8zXBrsMT+edVLbLqN1BqB76JH4BvZTqUIMfGwPGEn+EnmTV86fPBaYbFL3DFEhjB45CewkXEAtJxk4/Ms2pPXnaRqdky0HOYdcUcE2zcXq4vaIvW2/v0nHFJH2XXe22ueDmq/18XGtELSq85j9X8q0tcNSSKJIX8FTuJF/Pf8j5PhqG2u+osvsLxYrvvfeVJL+4tkcXcr9JV7v0ERmj/X6fM3NC4j6dS1+9Umr2oPavqiAydTZPLMNRGY23LO9zAVDly7jD+70G5TPPLdhRIl4WxcYjLnM+SNcJ26FOrkrISUtPObIz5Zb3AG612krnpy15RMW+1cQjlnWFI6538qky9axd2oJmHIHP08KyP0ubGO+TQNOYuv2uh17yCIvR8VcStw7o1g0NM60sk+8Tq7YfIBJrtp53GkvzXH7OA0p8/n/u1satf/VJhtR1l8Wa6Gmaug7haSpaCaYQax6ta0mkutlb+eAOSG1aobM81D9A4iS1RRlzBBoVX6tU1S6WE2N9ORY6DfeLRC4l9Rvr5h95XDWB2mR1d4WFudpsgVYwiTwT31ljskD8ZyDOlm5DkGh9N/UB/0AI5Xvb8ZBmai2hQ4BWMqFwYnzxwB26YHSOv9WgY3JXnvoN+2R4rqGVh/LLDMtpFP+SpMGJNWvbIl5SOodbCczW2RKleksPoUeGEzrjtKHVdtZA+kfqO+rVx/iclCqwoopepvJpSTDjT+b9GWylGRF8EDbGlw6eUzmJM95Ovoz+kwLX3c2fTjFeYEsE7vUZm3mqdGJuKh2w9/QGSaqRHs99aScGOdDqkFcACoqdbBoQqqjamhH6Q9ng39JCg3lrGJwd50Qk9ovnqBTr8MME7Ps2wiVfygUmPoUBJJfJWX5Nda0nuncbFkA=="))}const Lf=JA();new Set(vh(Lf)),new Set(vh(Lf)),HA(Lf),WA(Lf);const YA=new Uint8Array(32);YA.fill(0);const QA=`Ethereum Signed Message: `;function Wb(r){return typeof r=="string"&&(r=Al(r)),j0(xA([Al(QA),Al(String(r.length)),r]))}const XA="address/5.7.0",ic=new Or(XA);function X1(r){_i(r,20)||ic.throwArgumentError("invalid address","address",r),r=r.toLowerCase();const e=r.substring(2).split(""),t=new Uint8Array(40);for(let n=0;n<40;n++)t[n]=e[n].charCodeAt(0);const i=ir(j0(t));for(let n=0;n<40;n+=2)i[n>>1]>>4>=8&&(e[n]=e[n].toUpperCase()),(i[n>>1]&15)>=8&&(e[n+1]=e[n+1].toUpperCase());return"0x"+e.join("")}const ZA=9007199254740991;function eE(r){return Math.log10?Math.log10(r):Math.log(r)/Math.LN10}const H0={};for(let r=0;r<10;r++)H0[String(r)]=String(r);for(let r=0;r<26;r++)H0[String.fromCharCode(65+r)]=String(10+r);const Z1=Math.floor(eE(ZA));function tE(r){r=r.toUpperCase(),r=r.substring(4)+r.substring(0,2)+"00";let e=r.split("").map(i=>H0[i]).join("");for(;e.length>=Z1;){let i=e.substring(0,Z1);e=parseInt(i,10)%97+e.substring(i.length)}let t=String(98-parseInt(e,10)%97);for(;t.length<2;)t="0"+t;return t}function rE(r){let e=null;if(typeof r!="string"&&ic.throwArgumentError("invalid address","address",r),r.match(/^(0x)?[0-9a-fA-F]{40}$/))r.substring(0,2)!=="0x"&&(r="0x"+r),e=X1(r),r.match(/([A-F].*[a-f])|([a-f].*[A-F])/)&&e!==r&&ic.throwArgumentError("bad address checksum","address",r);else if(r.match(/^XE[0-9]{2}[0-9A-Za-z]{30,31}$/)){for(r.substring(2,4)!==tE(r)&&ic.throwArgumentError("bad icap checksum","address",r),e=NA(r.substring(4));e.length<40;)e="0"+e;e=X1("0x"+e)}else ic.throwArgumentError("invalid address","address",r);return e}function Go(r,e,t){Object.defineProperty(r,e,{enumerable:!0,value:t,writable:!1})}const iE=new Uint8Array(32);iE.fill(0),Gt.from(-1);const nE=Gt.from(0),sE=Gt.from(1);Gt.from("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Dn(sE.toHexString(),32),Dn(nE.toHexString(),32);var Sn={},Rt={},Mc=Jb;function Jb(r,e){if(!r)throw new Error(e||"Assertion failed")}Jb.equal=function(r,e,t){if(r!=e)throw new Error(t||"Assertion failed: "+r+" != "+e)};var o0={exports:{}};typeof Object.create=="function"?o0.exports=function(r,e){e&&(r.super_=e,r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}))}:o0.exports=function(r,e){if(e){r.super_=e;var t=function(){};t.prototype=e.prototype,r.prototype=new t,r.prototype.constructor=r}};var aE=Mc,oE=o0.exports;Rt.inherits=oE;function cE(r,e){return(r.charCodeAt(e)&64512)!==55296||e<0||e+1>=r.length?!1:(r.charCodeAt(e+1)&64512)===56320}function fE(r,e){if(Array.isArray(r))return r.slice();if(!r)return[];var t=[];if(typeof r=="string")if(e){if(e==="hex")for(r=r.replace(/[^a-z0-9]+/ig,""),r.length%2!==0&&(r="0"+r),n=0;n>6|192,t[i++]=a&63|128):cE(r,n)?(a=65536+((a&1023)<<10)+(r.charCodeAt(++n)&1023),t[i++]=a>>18|240,t[i++]=a>>12&63|128,t[i++]=a>>6&63|128,t[i++]=a&63|128):(t[i++]=a>>12|224,t[i++]=a>>6&63|128,t[i++]=a&63|128)}else for(n=0;n>>24|r>>>8&65280|r<<8&16711680|(r&255)<<24;return e>>>0}Rt.htonl=Yb;function uE(r,e){for(var t="",i=0;i>>0}return a}Rt.join32=lE;function dE(r,e){for(var t=new Array(r.length*4),i=0,n=0;i>>24,t[n+1]=a>>>16&255,t[n+2]=a>>>8&255,t[n+3]=a&255):(t[n+3]=a>>>24,t[n+2]=a>>>16&255,t[n+1]=a>>>8&255,t[n]=a&255)}return t}Rt.split32=dE;function pE(r,e){return r>>>e|r<<32-e}Rt.rotr32=pE;function gE(r,e){return r<>>32-e}Rt.rotl32=gE;function vE(r,e){return r+e>>>0}Rt.sum32=vE;function bE(r,e,t){return r+e+t>>>0}Rt.sum32_3=bE;function mE(r,e,t,i){return r+e+t+i>>>0}Rt.sum32_4=mE;function yE(r,e,t,i,n){return r+e+t+i+n>>>0}Rt.sum32_5=yE;function wE(r,e,t,i){var n=r[e],a=r[e+1],f=i+a>>>0,u=(f>>0,r[e+1]=f}Rt.sum64=wE;function _E(r,e,t,i){var n=e+i>>>0,a=(n>>0}Rt.sum64_hi=_E;function AE(r,e,t,i){var n=e+i;return n>>>0}Rt.sum64_lo=AE;function EE(r,e,t,i,n,a,f,u){var b=0,p=e;p=p+i>>>0,b+=p>>0,b+=p>>0,b+=p>>0}Rt.sum64_4_hi=EE;function xE(r,e,t,i,n,a,f,u){var b=e+i+a+u;return b>>>0}Rt.sum64_4_lo=xE;function SE(r,e,t,i,n,a,f,u,b,p){var y=0,A=e;A=A+i>>>0,y+=A>>0,y+=A>>0,y+=A>>0,y+=A>>0}Rt.sum64_5_hi=SE;function IE(r,e,t,i,n,a,f,u,b,p){var y=e+i+a+u+p;return y>>>0}Rt.sum64_5_lo=IE;function ME(r,e,t){var i=e<<32-t|r>>>t;return i>>>0}Rt.rotr64_hi=ME;function PE(r,e,t){var i=r<<32-t|e>>>t;return i>>>0}Rt.rotr64_lo=PE;function OE(r,e,t){return r>>>t}Rt.shr64_hi=OE;function RE(r,e,t){var i=r<<32-t|e>>>t;return i>>>0}Rt.shr64_lo=RE;var mo={},eg=Rt,NE=Mc;function Uf(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32}mo.BlockHash=Uf,Uf.prototype.update=function(r,e){if(r=eg.toArray(r,e),this.pending?this.pending=this.pending.concat(r):this.pending=r,this.pendingTotal+=r.length,this.pending.length>=this._delta8){r=this.pending;var t=r.length%this._delta8;this.pending=r.slice(r.length-t,r.length),this.pending.length===0&&(this.pending=null),r=eg.join32(r,0,r.length-t,this.endian);for(var i=0;i>>24&255,i[n++]=r>>>16&255,i[n++]=r>>>8&255,i[n++]=r&255}else for(i[n++]=r&255,i[n++]=r>>>8&255,i[n++]=r>>>16&255,i[n++]=r>>>24&255,i[n++]=0,i[n++]=0,i[n++]=0,i[n++]=0,a=8;a>>3}Vn.g0_256=BE;function qE(r){return Fn(r,17)^Fn(r,19)^r>>>10}Vn.g1_256=qE;var ao=Rt,LE=mo,UE=Vn,xl=ao.rotl32,Wo=ao.sum32,$E=ao.sum32_5,zE=UE.ft_1,r2=LE.BlockHash,jE=[1518500249,1859775393,2400959708,3395469782];function On(){if(!(this instanceof On))return new On;r2.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}ao.inherits(On,r2);var kE=On;On.blockSize=512,On.outSize=160,On.hmacStrength=80,On.padLength=64,On.prototype._update=function(r,e){for(var t=this.W,i=0;i<16;i++)t[i]=r[e+i];for(;ithis.blockSize&&(r=new this.Hash().update(r).digest()),Rx(r.length<=this.blockSize);for(var e=r.length;e>8,R=y&255;A?b.push(A,R):b.push(R)}return b}t.toArray=i;function n(f){return f.length===1?"0"+f:f}t.zero2=n;function a(f){for(var u="",b=0;b(R>>1)-1?K=(R>>1)-W:K=W,O.isubn(K)):K=0,A[N]=K,O.iushrn(1)}return A}t.getNAF=i;function n(b,p){var y=[[],[]];b=b.clone(),p=p.clone();for(var A=0,R=0,O;b.cmpn(-A)>0||p.cmpn(-R)>0;){var N=b.andln(3)+A&3,K=p.andln(3)+R&3;N===3&&(N=-1),K===3&&(K=-1);var W;N&1?(O=b.andln(7)+A&7,(O===3||O===5)&&K===2?W=-N:W=N):W=0,y[0].push(W);var Q;K&1?(O=p.andln(7)+R&7,(O===3||O===5)&&N===2?Q=-K:Q=K):Q=0,y[1].push(Q),2*A===W+1&&(A=1-A),2*R===Q+1&&(R=1-R),b.iushrn(1),p.iushrn(1)}return y}t.getJSF=n;function a(b,p,y){var A="_"+p;b.prototype[p]=function(){return this[A]!==void 0?this[A]:this[A]=y.call(this)}}t.cachedProperty=a;function f(b){return typeof b=="string"?t.toArray(b,"hex"):b}t.parseBytes=f;function u(b){return new vt(b,"hex","le")}t.intFromLE=u}),zf=Ai.getNAF,Tx=Ai.getJSF,bh=Ai.assert;function Ts(r,e){this.type=r,this.p=new vt(e.p,16),this.red=e.prime?vt.red(e.prime):vt.mont(this.p),this.zero=new vt(0).toRed(this.red),this.one=new vt(1).toRed(this.red),this.two=new vt(2).toRed(this.red),this.n=e.n&&new vt(e.n,16),this.g=e.g&&this.pointFromJSON(e.g,e.gRed),this._wnafT1=new Array(4),this._wnafT2=new Array(4),this._wnafT3=new Array(4),this._wnafT4=new Array(4),this._bitLength=this.n?this.n.bitLength():0;var t=this.n&&this.p.div(this.n);!t||t.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var _a=Ts;Ts.prototype.point=function(){throw new Error("Not implemented")},Ts.prototype.validate=function(){throw new Error("Not implemented")},Ts.prototype._fixedNafMul=function(r,e){bh(r.precomputed);var t=r._getDoubles(),i=zf(e,1,this._bitLength),n=(1<=f;b--)u=(u<<1)+i[b];a.push(u)}for(var p=this.jpoint(null,null,null),y=this.jpoint(null,null,null),A=n;A>0;A--){for(f=0;f=0;u--){for(var b=0;u>=0&&a[u]===0;u--)b++;if(u>=0&&b++,f=f.dblp(b),u<0)break;var p=a[u];bh(p!==0),r.type==="affine"?p>0?f=f.mixedAdd(n[p-1>>1]):f=f.mixedAdd(n[-p-1>>1].neg()):p>0?f=f.add(n[p-1>>1]):f=f.add(n[-p-1>>1].neg())}return r.type==="affine"?f.toP():f},Ts.prototype._wnafMulAdd=function(r,e,t,i,n){var a=this._wnafT1,f=this._wnafT2,u=this._wnafT3,b=0,p,y,A;for(p=0;p=1;p-=2){var O=p-1,N=p;if(a[O]!==1||a[N]!==1){u[O]=zf(t[O],a[O],this._bitLength),u[N]=zf(t[N],a[N],this._bitLength),b=Math.max(u[O].length,b),b=Math.max(u[N].length,b);continue}var K=[e[O],null,null,e[N]];e[O].y.cmp(e[N].y)===0?(K[1]=e[O].add(e[N]),K[2]=e[O].toJ().mixedAdd(e[N].neg())):e[O].y.cmp(e[N].y.redNeg())===0?(K[1]=e[O].toJ().mixedAdd(e[N]),K[2]=e[O].add(e[N].neg())):(K[1]=e[O].toJ().mixedAdd(e[N]),K[2]=e[O].toJ().mixedAdd(e[N].neg()));var W=[-3,-1,-5,-7,0,7,5,1,3],Q=Tx(t[O],t[N]);for(b=Math.max(Q[0].length,b),u[O]=new Array(b),u[N]=new Array(b),y=0;y=0;p--){for(var G=0;p>=0;){var x=!0;for(y=0;y=0&&G++,U=U.dblp(G),p<0)break;for(y=0;y0?A=f[y][B-1>>1]:B<0&&(A=f[y][-B-1>>1].neg()),A.type==="affine"?U=U.mixedAdd(A):U=U.add(A))}}for(p=0;p=Math.ceil((r.bitLength()+1)/e.step):!1},Bi.prototype._getDoubles=function(r,e){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var t=[this],i=this,n=0;n=0&&(R=b,O=p),y.negative&&(y=y.neg(),A=A.neg()),R.negative&&(R=R.neg(),O=O.neg()),[{a:y,b:A},{a:R,b:O}]},zi.prototype._endoSplit=function(r){var e=this.endo.basis,t=e[0],i=e[1],n=i.b.mul(r).divRound(this.n),a=t.b.neg().mul(r).divRound(this.n),f=n.mul(t.a),u=a.mul(i.a),b=n.mul(t.b),p=a.mul(i.b),y=r.sub(f).sub(u),A=b.add(p).neg();return{k1:y,k2:A}},zi.prototype.pointFromX=function(r,e){r=new vt(r,16),r.red||(r=r.toRed(this.red));var t=r.redSqr().redMul(r).redIAdd(r.redMul(this.a)).redIAdd(this.b),i=t.redSqrt();if(i.redSqr().redSub(t).cmp(this.zero)!==0)throw new Error("invalid point");var n=i.fromRed().isOdd();return(e&&!n||!e&&n)&&(i=i.redNeg()),this.point(r,i)},zi.prototype.validate=function(r){if(r.inf)return!0;var e=r.x,t=r.y,i=this.a.redMul(e),n=e.redSqr().redMul(e).redIAdd(i).redIAdd(this.b);return t.redSqr().redISub(n).cmpn(0)===0},zi.prototype._endoWnafMulAdd=function(r,e,t){for(var i=this._endoWnafT1,n=this._endoWnafT2,a=0;a":""},yr.prototype.isInfinity=function(){return this.inf},yr.prototype.add=function(r){if(this.inf)return r;if(r.inf)return this;if(this.eq(r))return this.dbl();if(this.neg().eq(r))return this.curve.point(null,null);if(this.x.cmp(r.x)===0)return this.curve.point(null,null);var e=this.y.redSub(r.y);e.cmpn(0)!==0&&(e=e.redMul(this.x.redSub(r.x).redInvm()));var t=e.redSqr().redISub(this.x).redISub(r.x),i=e.redMul(this.x.redSub(t)).redISub(this.y);return this.curve.point(t,i)},yr.prototype.dbl=function(){if(this.inf)return this;var r=this.y.redAdd(this.y);if(r.cmpn(0)===0)return this.curve.point(null,null);var e=this.curve.a,t=this.x.redSqr(),i=r.redInvm(),n=t.redAdd(t).redIAdd(t).redIAdd(e).redMul(i),a=n.redSqr().redISub(this.x.redAdd(this.x)),f=n.redMul(this.x.redSub(a)).redISub(this.y);return this.curve.point(a,f)},yr.prototype.getX=function(){return this.x.fromRed()},yr.prototype.getY=function(){return this.y.fromRed()},yr.prototype.mul=function(r){return r=new vt(r,16),this.isInfinity()?this:this._hasDoubles(r)?this.curve._fixedNafMul(this,r):this.curve.endo?this.curve._endoWnafMulAdd([this],[r]):this.curve._wnafMul(this,r)},yr.prototype.mulAdd=function(r,e,t){var i=[this,e],n=[r,t];return this.curve.endo?this.curve._endoWnafMulAdd(i,n):this.curve._wnafMulAdd(1,i,n,2)},yr.prototype.jmulAdd=function(r,e,t){var i=[this,e],n=[r,t];return this.curve.endo?this.curve._endoWnafMulAdd(i,n,!0):this.curve._wnafMulAdd(1,i,n,2,!0)},yr.prototype.eq=function(r){return this===r||this.inf===r.inf&&(this.inf||this.x.cmp(r.x)===0&&this.y.cmp(r.y)===0)},yr.prototype.neg=function(r){if(this.inf)return this;var e=this.curve.point(this.x,this.y.redNeg());if(r&&this.precomputed){var t=this.precomputed,i=function(n){return n.neg()};e.precomputed={naf:t.naf&&{wnd:t.naf.wnd,points:t.naf.points.map(i)},doubles:t.doubles&&{step:t.doubles.step,points:t.doubles.points.map(i)}}}return e},yr.prototype.toJ=function(){if(this.inf)return this.curve.jpoint(null,null,null);var r=this.curve.jpoint(this.x,this.y,this.curve.one);return r};function Pr(r,e,t,i){_a.BasePoint.call(this,r,"jacobian"),e===null&&t===null&&i===null?(this.x=this.curve.one,this.y=this.curve.one,this.z=new vt(0)):(this.x=new vt(e,16),this.y=new vt(t,16),this.z=new vt(i,16)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.zOne=this.z===this.curve.one}V0(Pr,_a.BasePoint),zi.prototype.jpoint=function(r,e,t){return new Pr(this,r,e,t)},Pr.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var r=this.z.redInvm(),e=r.redSqr(),t=this.x.redMul(e),i=this.y.redMul(e).redMul(r);return this.curve.point(t,i)},Pr.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},Pr.prototype.add=function(r){if(this.isInfinity())return r;if(r.isInfinity())return this;var e=r.z.redSqr(),t=this.z.redSqr(),i=this.x.redMul(e),n=r.x.redMul(t),a=this.y.redMul(e.redMul(r.z)),f=r.y.redMul(t.redMul(this.z)),u=i.redSub(n),b=a.redSub(f);if(u.cmpn(0)===0)return b.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var p=u.redSqr(),y=p.redMul(u),A=i.redMul(p),R=b.redSqr().redIAdd(y).redISub(A).redISub(A),O=b.redMul(A.redISub(R)).redISub(a.redMul(y)),N=this.z.redMul(r.z).redMul(u);return this.curve.jpoint(R,O,N)},Pr.prototype.mixedAdd=function(r){if(this.isInfinity())return r.toJ();if(r.isInfinity())return this;var e=this.z.redSqr(),t=this.x,i=r.x.redMul(e),n=this.y,a=r.y.redMul(e).redMul(this.z),f=t.redSub(i),u=n.redSub(a);if(f.cmpn(0)===0)return u.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var b=f.redSqr(),p=b.redMul(f),y=t.redMul(b),A=u.redSqr().redIAdd(p).redISub(y).redISub(y),R=u.redMul(y.redISub(A)).redISub(n.redMul(p)),O=this.z.redMul(f);return this.curve.jpoint(A,R,O)},Pr.prototype.dblp=function(r){if(r===0)return this;if(this.isInfinity())return this;if(!r)return this.dbl();var e;if(this.curve.zeroA||this.curve.threeA){var t=this;for(e=0;e=0)return!1;if(t.redIAdd(n),this.x.cmp(t)===0)return!0}},Pr.prototype.inspect=function(){return this.isInfinity()?"":""},Pr.prototype.isInfinity=function(){return this.z.cmpn(0)===0};var Zf=wo(function(r,e){var t=e;t.base=_a,t.short=Fx,t.mont=null,t.edwards=null}),eh=wo(function(r,e){var t=e,i=Ai.assert;function n(u){u.type==="short"?this.curve=new Zf.short(u):u.type==="edwards"?this.curve=new Zf.edwards(u):this.curve=new Zf.mont(u),this.g=this.curve.g,this.n=this.curve.n,this.hash=u.hash,i(this.g.validate(),"Invalid curve"),i(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}t.PresetCurve=n;function a(u,b){Object.defineProperty(t,u,{configurable:!0,enumerable:!0,get:function(){var p=new n(b);return Object.defineProperty(t,u,{configurable:!0,enumerable:!0,value:p}),p}})}a("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:Sn.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),a("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:Sn.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),a("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:Sn.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),a("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:Sn.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),a("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:Sn.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),a("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:Sn.sha256,gRed:!1,g:["9"]}),a("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:Sn.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var f;try{f=null.crash()}catch{f=void 0}a("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:Sn.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",f]})});function Ds(r){if(!(this instanceof Ds))return new Ds(r);this.hash=r.hash,this.predResist=!!r.predResist,this.outLen=this.hash.outSize,this.minEntropy=r.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=ln.toArray(r.entropy,r.entropyEnc||"hex"),t=ln.toArray(r.nonce,r.nonceEnc||"hex"),i=ln.toArray(r.pers,r.persEnc||"hex");K0(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,t,i)}var ng=Ds;Ds.prototype._init=function(r,e,t){var i=r.concat(e).concat(t);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var n=0;n=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(r.concat(t||[])),this._reseed=1},Ds.prototype.generate=function(r,e,t,i){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");typeof e!="string"&&(i=t,t=e,e=null),t&&(t=ln.toArray(t,i||"hex"),this._update(t));for(var n=[];n.length"};var Bx=Ai.assert;function jh(r,e){if(r instanceof jh)return r;this._importDER(r,e)||(Bx(r.r&&r.s,"Signature without r or s"),this.r=new vt(r.r,16),this.s=new vt(r.s,16),r.recoveryParam===void 0?this.recoveryParam=null:this.recoveryParam=r.recoveryParam)}var jf=jh;function qx(){this.place=0}function Ol(r,e){var t=r[e.place++];if(!(t&128))return t;var i=t&15;if(i===0||i>4)return!1;for(var n=0,a=0,f=e.place;a>>=0;return n<=127?!1:(e.place=f,n)}function sg(r){for(var e=0,t=r.length-1;!r[e]&&!(r[e+1]&128)&&e>>3);for(r.push(t|128);--t;)r.push(e>>>(t<<3)&255);r.push(e)}jh.prototype.toDER=function(r){var e=this.r.toArray(),t=this.s.toArray();for(e[0]&128&&(e=[0].concat(e)),t[0]&128&&(t=[0].concat(t)),e=sg(e),t=sg(t);!t[0]&&!(t[1]&128);)t=t.slice(1);var i=[2];Rl(i,e.length),i=i.concat(e),i.push(2),Rl(i,t.length);var n=i.concat(t),a=[48];return Rl(a,n.length),a=a.concat(n),Ai.encode(a,r)};var Lx=function(){throw new Error("unsupported")},p2=Ai.assert;function Ui(r){if(!(this instanceof Ui))return new Ui(r);typeof r=="string"&&(p2(Object.prototype.hasOwnProperty.call(eh,r),"Unknown curve "+r),r=eh[r]),r instanceof eh.PresetCurve&&(r={curve:r}),this.curve=r.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=r.curve.g,this.g.precompute(r.curve.n.bitLength()+1),this.hash=r.hash||r.curve.hash}var Ux=Ui;Ui.prototype.keyPair=function(r){return new Pl(this,r)},Ui.prototype.keyFromPrivate=function(r,e){return Pl.fromPrivate(this,r,e)},Ui.prototype.keyFromPublic=function(r,e){return Pl.fromPublic(this,r,e)},Ui.prototype.genKeyPair=function(r){r||(r={});for(var e=new ng({hash:this.hash,pers:r.pers,persEnc:r.persEnc||"utf8",entropy:r.entropy||Lx(this.hash.hmacStrength),entropyEnc:r.entropy&&r.entropyEnc||"utf8",nonce:this.n.toArray()}),t=this.n.byteLength(),i=this.n.sub(new vt(2));;){var n=new vt(e.generate(t));if(!(n.cmp(i)>0))return n.iaddn(1),this.keyFromPrivate(n)}},Ui.prototype._truncateToN=function(r,e){var t=r.byteLength()*8-this.n.bitLength();return t>0&&(r=r.ushrn(t)),!e&&r.cmp(this.n)>=0?r.sub(this.n):r},Ui.prototype.sign=function(r,e,t,i){typeof t=="object"&&(i=t,t=null),i||(i={}),e=this.keyFromPrivate(e,t),r=this._truncateToN(new vt(r,16));for(var n=this.n.byteLength(),a=e.getPrivate().toArray("be",n),f=r.toArray("be",n),u=new ng({hash:this.hash,entropy:a,nonce:f,pers:i.pers,persEnc:i.persEnc||"utf8"}),b=this.n.sub(new vt(1)),p=0;;p++){var y=i.k?i.k(p):new vt(u.generate(this.n.byteLength()));if(y=this._truncateToN(y,!0),!(y.cmpn(1)<=0||y.cmp(b)>=0)){var A=this.g.mul(y);if(!A.isInfinity()){var R=A.getX(),O=R.umod(this.n);if(O.cmpn(0)!==0){var N=y.invm(this.n).mul(O.mul(e.getPrivate()).iadd(r));if(N=N.umod(this.n),N.cmpn(0)!==0){var K=(A.getY().isOdd()?1:0)|(R.cmp(O)!==0?2:0);return i.canonical&&N.cmp(this.nh)>0&&(N=this.n.sub(N),K^=1),new jf({r:O,s:N,recoveryParam:K})}}}}}},Ui.prototype.verify=function(r,e,t,i){r=this._truncateToN(new vt(r,16)),t=this.keyFromPublic(t,i),e=new jf(e,"hex");var n=e.r,a=e.s;if(n.cmpn(1)<0||n.cmp(this.n)>=0||a.cmpn(1)<0||a.cmp(this.n)>=0)return!1;var f=a.invm(this.n),u=f.mul(r).umod(this.n),b=f.mul(n).umod(this.n),p;return this.curve._maxwellTrick?(p=this.g.jmulAdd(u,t.getPublic(),b),p.isInfinity()?!1:p.eqXToP(n)):(p=this.g.mulAdd(u,t.getPublic(),b),p.isInfinity()?!1:p.getX().umod(this.n).cmp(n)===0)},Ui.prototype.recoverPubKey=function(r,e,t,i){p2((3&t)===t,"The recovery param is more than two bits"),e=new jf(e,i);var n=this.n,a=new vt(r),f=e.r,u=e.s,b=t&1,p=t>>1;if(f.cmp(this.curve.p.umod(this.curve.n))>=0&&p)throw new Error("Unable to find sencond key candinate");p?f=this.curve.pointFromX(f.add(this.curve.n),b):f=this.curve.pointFromX(f,b);var y=e.r.invm(n),A=n.sub(a).mul(y).umod(n),R=u.mul(y).umod(n);return this.g.mulAdd(A,f,R)},Ui.prototype.getKeyRecoveryParam=function(r,e,t,i){if(e=new jf(e,i),e.recoveryParam!==null)return e.recoveryParam;for(var n=0;n<4;n++){var a;try{a=this.recoverPubKey(r,e,n)}catch{continue}if(a.eq(t))return n}throw new Error("Unable to find valid recovery factor")};var $x=wo(function(r,e){var t=e;t.version="6.5.4",t.utils=Ai,t.rand=function(){throw new Error("unsupported")},t.curve=Zf,t.curves=eh,t.ec=Ux,t.eddsa=null}),zx=$x.ec;const jx="signing-key/5.7.0",h0=new Or(jx);let Nl=null;function Ns(){return Nl||(Nl=new zx("secp256k1")),Nl}class kx{constructor(e){Go(this,"curve","secp256k1"),Go(this,"privateKey",ci(e)),IA(this.privateKey)!==32&&h0.throwArgumentError("invalid private key","privateKey","[[ REDACTED ]]");const t=Ns().keyFromPrivate(ir(this.privateKey));Go(this,"publicKey","0x"+t.getPublic(!1,"hex")),Go(this,"compressedPublicKey","0x"+t.getPublic(!0,"hex")),Go(this,"_isSigningKey",!0)}_addPoint(e){const t=Ns().keyFromPublic(ir(this.publicKey)),i=Ns().keyFromPublic(ir(e));return"0x"+t.pub.add(i.pub).encodeCompressed("hex")}signDigest(e){const t=Ns().keyFromPrivate(ir(this.privateKey)),i=ir(e);i.length!==32&&h0.throwArgumentError("bad digest length","digest",e);const n=t.sign(i,{canonical:!0});return Ub({recoveryParam:n.recoveryParam,r:Dn("0x"+n.r.toString(16),32),s:Dn("0x"+n.s.toString(16),32)})}computeSharedSecret(e){const t=Ns().keyFromPrivate(ir(this.privateKey)),i=Ns().keyFromPublic(ir(g2(e)));return Dn("0x"+t.derive(i.getPublic()).toString(16),32)}static isSigningKey(e){return!!(e&&e._isSigningKey)}}function Hx(r,e){const t=Ub(e),i={r:ir(t.r),s:ir(t.s)};return"0x"+Ns().recoverPubKey(ir(r),i,t.recoveryParam).encode("hex",!1)}function g2(r,e){const t=ir(r);return t.length===32?new kx(t).publicKey:t.length===33?"0x"+Ns().keyFromPublic(t).getPublic(!1,"hex"):t.length===65?ci(t):h0.throwArgumentError("invalid public or private key","key","[REDACTED]")}var ag;(function(r){r[r.legacy=0]="legacy",r[r.eip2930=1]="eip2930",r[r.eip1559=2]="eip1559"})(ag||(ag={}));function Kx(r){const e=g2(r);return rE(K1(j0(K1(e,1)),12))}function Vx(r,e){return Kx(Hx(ir(r),e))}const Gx="https://rpc.walletconnect.org/v1";async function Wx(r,e,t,i,n,a){switch(t.t){case"eip191":return Jx(r,e,t.s);case"eip1271":return await Yx(r,e,t.s,i,n,a);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${t.t}`)}}function Jx(r,e,t){return Vx(Wb(e),t).toLowerCase()===r.toLowerCase()}async function Yx(r,e,t,i,n,a){try{const f="0x1626ba7e",u="0000000000000000000000000000000000000000000000000000000000000040",b="0000000000000000000000000000000000000000000000000000000000000041",p=t.substring(2),y=Wb(e).substring(2),A=f+y+u+b+p,R=await fetch(`${a||Gx}/?chainId=${i}&projectId=${n}`,{method:"POST",body:JSON.stringify({id:Qx(),jsonrpc:"2.0",method:"eth_call",params:[{to:r,data:A},"latest"]})}),{result:O}=await R.json();return O?O.slice(0,f.length).toLowerCase()===f.toLowerCase():!1}catch(f){return console.error("isValidEip1271Signature: ",f),!1}}function Qx(){return Date.now()+Math.floor(Math.random()*1e3)}var Xx=Object.defineProperty,Zx=Object.defineProperties,eS=Object.getOwnPropertyDescriptors,og=Object.getOwnPropertySymbols,tS=Object.prototype.hasOwnProperty,rS=Object.prototype.propertyIsEnumerable,cg=(r,e,t)=>e in r?Xx(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,iS=(r,e)=>{for(var t in e||(e={}))tS.call(e,t)&&cg(r,t,e[t]);if(og)for(var t of og(e))rS.call(e,t)&&cg(r,t,e[t]);return r},nS=(r,e)=>Zx(r,eS(e));const sS="did:pkh:",G0=r=>r==null?void 0:r.split(":"),v2=r=>{const e=r&&G0(r);if(e)return r.includes(sS)?e[3]:e[1]},fg=r=>{const e=r&&G0(r);if(e)return e[2]+":"+e[3]},mh=r=>{const e=r&&G0(r);if(e)return e.pop()};async function hg(r){const{cacao:e,projectId:t}=r,{s:i,p:n}=e,a=b2(n,n.iss),f=mh(n.iss);return await Wx(f,a,i,v2(n.iss),t)}const b2=(r,e)=>{const t=`${r.domain} wants you to sign in with your Ethereum account:`,i=mh(e);if(!r.aud&&!r.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let n=r.statement||void 0;const a=`URI: ${r.aud||r.uri}`,f=`Version: ${r.version}`,u=`Chain ID: ${v2(e)}`,b=`Nonce: ${r.nonce}`,p=`Issued At: ${r.iat}`,y=r.exp?`Expiration Time: ${r.exp}`:void 0,A=r.nbf?`Not Before: ${r.nbf}`:void 0,R=r.requestId?`Request ID: ${r.requestId}`:void 0,O=r.resources?`Resources:${r.resources.map(K=>` - ${K}`).join("")}`:void 0,N=th(r.resources);if(N){const K=gc(N);n=pS(n,K)}return[t,i,"",n,"",a,f,u,b,p,y,A,R,O].filter(K=>K!=null).join(` `)};function aS(r){return Buffer.from(JSON.stringify(r)).toString("base64")}function oS(r){return JSON.parse(Buffer.from(r,"base64").toString("utf-8"))}function va(r){if(!r)throw new Error("No recap provided, value is undefined");if(!r.att)throw new Error("No `att` property found");const e=Object.keys(r.att);if(!(e!=null&&e.length))throw new Error("No resources found in `att` property");e.forEach(t=>{const i=r.att[t];if(Array.isArray(i))throw new Error(`Resource must be an object: ${t}`);if(typeof i!="object")throw new Error(`Resource must be an object: ${t}`);if(!Object.keys(i).length)throw new Error(`Resource object is empty: ${t}`);Object.keys(i).forEach(n=>{const a=i[n];if(!Array.isArray(a))throw new Error(`Ability limits ${n} must be an array of objects, found: ${a}`);if(!a.length)throw new Error(`Value of ${n} is empty array, must be an array with objects`);a.forEach(f=>{if(typeof f!="object")throw new Error(`Ability limits (${n}) must be an array of objects, found: ${f}`)})})})}function cS(r,e,t,i={}){return t==null||t.sort((n,a)=>n.localeCompare(a)),{att:{[r]:fS(e,t,i)}}}function fS(r,e,t={}){e=e==null?void 0:e.sort((n,a)=>n.localeCompare(a));const i=e.map(n=>({[`${r}/${n}`]:[t]}));return Object.assign({},...i)}function m2(r){return va(r),`urn:recap:${aS(r).replace(/=/g,"")}`}function gc(r){const e=oS(r.replace("urn:recap:",""));return va(e),e}function hS(r,e,t){const i=cS(r,e,t);return m2(i)}function uS(r){return r&&r.includes("urn:recap:")}function lS(r,e){const t=gc(r),i=gc(e),n=dS(t,i);return m2(n)}function dS(r,e){va(r),va(e);const t=Object.keys(r.att).concat(Object.keys(e.att)).sort((n,a)=>n.localeCompare(a)),i={att:{}};return t.forEach(n=>{var a,f;Object.keys(((a=r.att)==null?void 0:a[n])||{}).concat(Object.keys(((f=e.att)==null?void 0:f[n])||{})).sort((u,b)=>u.localeCompare(b)).forEach(u=>{var b,p;i.att[n]=nS(iS({},i.att[n]),{[u]:((b=r.att[n])==null?void 0:b[u])||((p=e.att[n])==null?void 0:p[u])})})}),i}function pS(r="",e){va(e);const t="I further authorize the stated URI to perform the following actions on my behalf: ";if(r.includes(t))return r;const i=[];let n=0;Object.keys(e.att).forEach(u=>{const b=Object.keys(e.att[u]).map(A=>({ability:A.split("/")[0],action:A.split("/")[1]}));b.sort((A,R)=>A.action.localeCompare(R.action));const p={};b.forEach(A=>{p[A.ability]||(p[A.ability]=[]),p[A.ability].push(A.action)});const y=Object.keys(p).map(A=>(n++,`(${n}) '${A}': '${p[A].join("', '")}' for '${u}'.`));i.push(y.join(", ").replace(".,","."))});const a=i.join(" "),f=`${t}${a}`;return`${r?r+" ":""}${f}`}function ug(r){var e;const t=gc(r);va(t);const i=(e=t.att)==null?void 0:e.eip155;return i?Object.keys(i).map(n=>n.split("/")[1]):[]}function lg(r){const e=gc(r);va(e);const t=[];return Object.values(e.att).forEach(i=>{Object.values(i).forEach(n=>{var a;(a=n==null?void 0:n[0])!=null&&a.chains&&t.push(n[0].chains)})}),[...new Set(t.flat())]}function th(r){if(!r)return;const e=r==null?void 0:r[r.length-1];return uS(e)?e:void 0}const y2="base10",Jr="base16",Bs="base64pad",Yo="base64url",Pc="utf8",w2=0,ds=1,Oc=2,gS=0,dg=1,fc=12,W0=32;function vS(){const r=C0.generateKeyPair();return{privateKey:Er(r.secretKey,Jr),publicKey:Er(r.publicKey,Jr)}}function u0(){const r=$s.randomBytes(W0);return Er(r,Jr)}function bS(r,e){const t=C0.sharedKey(Ar(r,Jr),Ar(e,Jr),!0),i=new d_(Ac.SHA256,t).expand(W0);return Er(i,Jr)}function rh(r){const e=Ac.hash(Ar(r,Jr));return Er(e,Jr)}function fs(r){const e=Ac.hash(Ar(r,Pc));return Er(e,Jr)}function _2(r){return Ar(`${r}`,y2)}function ba(r){return Number(Er(r,y2))}function mS(r){const e=_2(typeof r.type<"u"?r.type:w2);if(ba(e)===ds&&typeof r.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const t=typeof r.senderPublicKey<"u"?Ar(r.senderPublicKey,Jr):void 0,i=typeof r.iv<"u"?Ar(r.iv,Jr):$s.randomBytes(fc),n=new R0.ChaCha20Poly1305(Ar(r.symKey,Jr)).seal(i,Ar(r.message,Pc));return A2({type:e,sealed:n,iv:i,senderPublicKey:t,encoding:r.encoding})}function yS(r,e){const t=_2(Oc),i=$s.randomBytes(fc),n=Ar(r,Pc);return A2({type:t,sealed:n,iv:i,encoding:e})}function wS(r){const e=new R0.ChaCha20Poly1305(Ar(r.symKey,Jr)),{sealed:t,iv:i}=vc({encoded:r.encoded,encoding:r==null?void 0:r.encoding}),n=e.open(i,t);if(n===null)throw new Error("Failed to decrypt");return Er(n,Pc)}function _S(r,e){const{sealed:t}=vc({encoded:r,encoding:e});return Er(t,Pc)}function A2(r){const{encoding:e=Bs}=r;if(ba(r.type)===Oc)return Er(Yf([r.type,r.sealed]),e);if(ba(r.type)===ds){if(typeof r.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return Er(Yf([r.type,r.senderPublicKey,r.iv,r.sealed]),e)}return Er(Yf([r.type,r.iv,r.sealed]),e)}function vc(r){const{encoded:e,encoding:t=Bs}=r,i=Ar(e,t),n=i.slice(gS,dg),a=dg;if(ba(n)===ds){const p=a+W0,y=p+fc,A=i.slice(a,p),R=i.slice(p,y),O=i.slice(y);return{type:n,sealed:O,iv:R,senderPublicKey:A}}if(ba(n)===Oc){const p=i.slice(a),y=$s.randomBytes(fc);return{type:n,sealed:p,iv:y}}const f=a+fc,u=i.slice(a,f),b=i.slice(f);return{type:n,sealed:b,iv:u}}function AS(r,e){const t=vc({encoded:r,encoding:e==null?void 0:e.encoding});return E2({type:ba(t.type),senderPublicKey:typeof t.senderPublicKey<"u"?Er(t.senderPublicKey,Jr):void 0,receiverPublicKey:e==null?void 0:e.receiverPublicKey})}function E2(r){const e=(r==null?void 0:r.type)||w2;if(e===ds){if(typeof(r==null?void 0:r.senderPublicKey)>"u")throw new Error("missing sender public key");if(typeof(r==null?void 0:r.receiverPublicKey)>"u")throw new Error("missing receiver public key")}return{type:e,senderPublicKey:r==null?void 0:r.senderPublicKey,receiverPublicKey:r==null?void 0:r.receiverPublicKey}}function pg(r){return r.type===ds&&typeof r.senderPublicKey=="string"&&typeof r.receiverPublicKey=="string"}function gg(r){return r.type===Oc}function ES(r){return new Yv.ec("p256").keyFromPublic({x:Buffer.from(r.x,"base64").toString("hex"),y:Buffer.from(r.y,"base64").toString("hex")},"hex")}function xS(r){let e=r.replace(/-/g,"+").replace(/_/g,"/");const t=e.length%4;return t>0&&(e+="=".repeat(4-t)),e}function SS(r){return Buffer.from(xS(r),"base64")}function IS(r,e){const[t,i,n]=r.split("."),a=SS(n);if(a.length!==64)throw new Error("Invalid signature length");const f=a.slice(0,32).toString("hex"),u=a.slice(32,64).toString("hex"),b=`${t}.${i}`,p=new Ac.SHA256().update(Buffer.from(b)).digest(),y=ES(e),A=Buffer.from(p).toString("hex");if(!y.verify(A,{r:f,s:u}))throw new Error("Invalid signature");return n0(r).payload}const MS="irn";function l0(r){return(r==null?void 0:r.relay)||{protocol:MS}}function nc(r){const e=X9[r];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${r}`);return e}var PS=Object.defineProperty,OS=Object.defineProperties,RS=Object.getOwnPropertyDescriptors,vg=Object.getOwnPropertySymbols,NS=Object.prototype.hasOwnProperty,CS=Object.prototype.propertyIsEnumerable,bg=(r,e,t)=>e in r?PS(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,mg=(r,e)=>{for(var t in e||(e={}))NS.call(e,t)&&bg(r,t,e[t]);if(vg)for(var t of vg(e))CS.call(e,t)&&bg(r,t,e[t]);return r},TS=(r,e)=>OS(r,RS(e));function DS(r,e="-"){const t={},i="relay"+e;return Object.keys(r).forEach(n=>{if(n.startsWith(i)){const a=n.replace(i,""),f=r[n];t[a]=f}}),t}function yg(r){if(!r.includes("wc:")){const b=Fb(r);b!=null&&b.includes("wc:")&&(r=b)}r=r.includes("wc://")?r.replace("wc://",""):r,r=r.includes("wc:")?r.replace("wc:",""):r;const e=r.indexOf(":"),t=r.indexOf("?")!==-1?r.indexOf("?"):void 0,i=r.substring(0,e),n=r.substring(e+1,t).split("@"),a=typeof t<"u"?r.substring(t):"",f=dc.parse(a),u=typeof f.methods=="string"?f.methods.split(","):void 0;return{protocol:i,topic:FS(n[0]),version:parseInt(n[1],10),symKey:f.symKey,relay:DS(f),methods:u,expiryTimestamp:f.expiryTimestamp?parseInt(f.expiryTimestamp,10):void 0}}function FS(r){return r.startsWith("//")?r.substring(2):r}function BS(r,e="-"){const t="relay",i={};return Object.keys(r).forEach(n=>{const a=t+e+n;r[n]&&(i[a]=r[n])}),i}function wg(r){return`${r.protocol}:${r.topic}@${r.version}?`+dc.stringify(mg(TS(mg({symKey:r.symKey},BS(r.relay)),{expiryTimestamp:r.expiryTimestamp}),r.methods?{methods:r.methods.join(",")}:{}))}function kf(r,e,t){return`${r}?wc_ev=${t}&topic=${e}`}function _o(r){const e=[];return r.forEach(t=>{const[i,n]=t.split(":");e.push(`${i}:${n}`)}),e}function qS(r){const e=[];return Object.values(r).forEach(t=>{e.push(..._o(t.accounts))}),e}function LS(r,e){const t=[];return Object.values(r).forEach(i=>{_o(i.accounts).includes(e)&&t.push(...i.methods)}),t}function US(r,e){const t=[];return Object.values(r).forEach(i=>{_o(i.accounts).includes(e)&&t.push(...i.events)}),t}function J0(r){return r.includes(":")}function sc(r){return J0(r)?r.split(":")[0]:r}function $S(r){const e={};return r==null||r.forEach(t=>{const[i,n]=t.split(":");e[i]||(e[i]={accounts:[],chains:[],events:[]}),e[i].accounts.push(t),e[i].chains.push(`${i}:${n}`)}),e}function _g(r,e){e=e.map(i=>i.replace("did:pkh:",""));const t=$S(e);for(const[i,n]of Object.entries(t))n.methods?n.methods=Qf(n.methods,r):n.methods=r,n.events=["chainChanged","accountsChanged"];return t}const zS={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}},jS={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 Ae(r,e){const{message:t,code:i}=jS[r];return{message:e?`${t} ${e}`:t,code:i}}function Ut(r,e){const{message:t,code:i}=zS[r];return{message:e?`${t} ${e}`:t,code:i}}function jn(r,e){return!!Array.isArray(r)}function bc(r){return Object.getPrototypeOf(r)===Object.prototype&&Object.keys(r).length}function fi(r){return typeof r>"u"}function fr(r,e){return e&&fi(r)?!0:typeof r=="string"&&!!r.trim().length}function Y0(r,e){return typeof r=="number"&&!isNaN(r)}function kS(r,e){const{requiredNamespaces:t}=e,i=Object.keys(r.namespaces),n=Object.keys(t);let a=!0;return fa(n,i)?(i.forEach(f=>{const{accounts:u,methods:b,events:p}=r.namespaces[f],y=_o(u),A=t[f];(!fa(Pb(f,A),y)||!fa(A.methods,b)||!fa(A.events,p))&&(a=!1)}),a):!1}function yh(r){return fr(r,!1)&&r.includes(":")?r.split(":").length===2:!1}function HS(r){if(fr(r,!1)&&r.includes(":")){const e=r.split(":");if(e.length===3){const t=e[0]+":"+e[1];return!!e[2]&&yh(t)}}return!1}function KS(r){function e(t){try{return typeof new URL(t)<"u"}catch{return!1}}try{if(fr(r,!1)){if(e(r))return!0;const t=Fb(r);return e(t)}}catch{}return!1}function VS(r){var e;return(e=r==null?void 0:r.proposer)==null?void 0:e.publicKey}function GS(r){return r==null?void 0:r.topic}function WS(r,e){let t=null;return fr(r==null?void 0:r.publicKey,!1)||(t=Ae("MISSING_OR_INVALID",`${e} controller public key should be a string`)),t}function Ag(r){let e=!0;return jn(r)?r.length&&(e=r.every(t=>fr(t,!1))):e=!1,e}function JS(r,e,t){let i=null;return jn(e)&&e.length?e.forEach(n=>{i||yh(n)||(i=Ut("UNSUPPORTED_CHAINS",`${t}, chain ${n} should be a string and conform to "namespace:chainId" format`))}):yh(r)||(i=Ut("UNSUPPORTED_CHAINS",`${t}, 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"] }`)),i}function YS(r,e,t){let i=null;return Object.entries(r).forEach(([n,a])=>{if(i)return;const f=JS(n,Pb(n,a),`${e} ${t}`);f&&(i=f)}),i}function QS(r,e){let t=null;return jn(r)?r.forEach(i=>{t||HS(i)||(t=Ut("UNSUPPORTED_ACCOUNTS",`${e}, account ${i} should be a string and conform to "namespace:chainId:address" format`))}):t=Ut("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),t}function XS(r,e){let t=null;return Object.values(r).forEach(i=>{if(t)return;const n=QS(i==null?void 0:i.accounts,`${e} namespace`);n&&(t=n)}),t}function ZS(r,e){let t=null;return Ag(r==null?void 0:r.methods)?Ag(r==null?void 0:r.events)||(t=Ut("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):t=Ut("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),t}function x2(r,e){let t=null;return Object.values(r).forEach(i=>{if(t)return;const n=ZS(i,`${e}, namespace`);n&&(t=n)}),t}function eI(r,e,t){let i=null;if(r&&bc(r)){const n=x2(r,e);n&&(i=n);const a=YS(r,e,t);a&&(i=a)}else i=Ae("MISSING_OR_INVALID",`${e}, ${t} should be an object with data`);return i}function Cl(r,e){let t=null;if(r&&bc(r)){const i=x2(r,e);i&&(t=i);const n=XS(r,e);n&&(t=n)}else t=Ae("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return t}function S2(r){return fr(r.protocol,!0)}function tI(r,e){let t=!1;return r?r&&jn(r)&&r.length&&r.forEach(i=>{t=S2(i)}):t=!0,t}function rI(r){return typeof r=="number"}function oi(r){return typeof r<"u"&&typeof r!==null}function iI(r){return!(!r||typeof r!="object"||!r.code||!Y0(r.code)||!r.message||!fr(r.message,!1))}function nI(r){return!(fi(r)||!fr(r.method,!1))}function sI(r){return!(fi(r)||fi(r.result)&&fi(r.error)||!Y0(r.id)||!fr(r.jsonrpc,!1))}function aI(r){return!(fi(r)||!fr(r.name,!1))}function Eg(r,e){return!(!yh(e)||!qS(r).includes(e))}function oI(r,e,t){return fr(t,!1)?LS(r,e).includes(t):!1}function cI(r,e,t){return fr(t,!1)?US(r,e).includes(t):!1}function xg(r,e,t){let i=null;const n=fI(r),a=hI(e),f=Object.keys(n),u=Object.keys(a),b=Sg(Object.keys(r)),p=Sg(Object.keys(e)),y=b.filter(A=>!p.includes(A));return y.length&&(i=Ae("NON_CONFORMING_NAMESPACES",`${t} namespaces keys don't satisfy requiredNamespaces. Required: ${y.toString()} Received: ${Object.keys(e).toString()}`)),fa(f,u)||(i=Ae("NON_CONFORMING_NAMESPACES",`${t} namespaces chains don't satisfy required namespaces. Required: ${f.toString()} Approved: ${u.toString()}`)),Object.keys(e).forEach(A=>{if(!A.includes(":")||i)return;const R=_o(e[A].accounts);R.includes(A)||(i=Ae("NON_CONFORMING_NAMESPACES",`${t} namespaces accounts don't satisfy namespace accounts for ${A} Required: ${A} Approved: ${R.toString()}`))}),f.forEach(A=>{i||(fa(n[A].methods,a[A].methods)?fa(n[A].events,a[A].events)||(i=Ae("NON_CONFORMING_NAMESPACES",`${t} namespaces events don't satisfy namespace events for ${A}`)):i=Ae("NON_CONFORMING_NAMESPACES",`${t} namespaces methods don't satisfy namespace methods for ${A}`))}),i}function fI(r){const e={};return Object.keys(r).forEach(t=>{var i;t.includes(":")?e[t]=r[t]:(i=r[t].chains)==null||i.forEach(n=>{e[n]={methods:r[t].methods,events:r[t].events}})}),e}function Sg(r){return[...new Set(r.map(e=>e.includes(":")?e.split(":")[0]:e))]}function hI(r){const e={};return Object.keys(r).forEach(t=>{if(t.includes(":"))e[t]=r[t];else{const i=_o(r[t].accounts);i==null||i.forEach(n=>{e[n]={accounts:r[t].accounts.filter(a=>a.includes(`${n}:`)),methods:r[t].methods,events:r[t].events}})}}),e}function uI(r,e){return Y0(r)&&r<=e.max&&r>=e.min}function Ig(){const r=Ic();return new Promise(e=>{switch(r){case wi.browser:e(lI());break;case wi.reactNative:e(dI());break;case wi.node:e(pI());break;default:e(!0)}})}function lI(){return Sc()&&(navigator==null?void 0:navigator.onLine)}async function dI(){if(vo()&&typeof global<"u"&&global!=null&&global.NetInfo){const r=await(global==null?void 0:global.NetInfo.fetch());return r==null?void 0:r.isConnected}return!0}function pI(){return!0}function gI(r){switch(Ic()){case wi.browser:vI(r);break;case wi.reactNative:bI(r);break}}function vI(r){!vo()&&Sc()&&(window.addEventListener("online",()=>r(!0)),window.addEventListener("offline",()=>r(!1)))}function bI(r){vo()&&typeof global<"u"&&global!=null&&global.NetInfo&&(global==null||global.NetInfo.addEventListener(e=>r(e==null?void 0:e.isConnected)))}const Tl={};class Qo{static get(e){return Tl[e]}static set(e,t){Tl[e]=t}static delete(e){delete Tl[e]}}class Aa{}let mI=class extends Aa{constructor(e){super()}};const Mg=xe.FIVE_SECONDS,Ao={pulse:"heartbeat_pulse"};let yI=class I2 extends mI{constructor(e){super(e),this.events=new Hi.EventEmitter,this.interval=Mg,this.interval=(e==null?void 0:e.interval)||Mg}static async init(e){const t=new I2(e);return await t.init(),t}async init(){await this.initialize()}stop(){clearInterval(this.intervalRef)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async initialize(){this.intervalRef=setInterval(()=>this.pulse(),xe.toMiliseconds(this.interval))}pulse(){this.events.emit(Ao.pulse)}};const wI=/"(?:_|\\u0{2}5[Ff]){2}(?:p|\\u0{2}70)(?:r|\\u0{2}72)(?:o|\\u0{2}6[Ff])(?:t|\\u0{2}74)(?:o|\\u0{2}6[Ff])(?:_|\\u0{2}5[Ff]){2}"\s*:/,_I=/"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/,AI=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function EI(r,e){if(r==="__proto__"||r==="constructor"&&e&&typeof e=="object"&&"prototype"in e){xI(r);return}return e}function xI(r){console.warn(`[destr] Dropping "${r}" key to prevent prototype pollution.`)}function Hf(r,e={}){if(typeof r!="string")return r;const t=r.trim();if(r[0]==='"'&&r.endsWith('"')&&!r.includes("\\"))return t.slice(1,-1);if(t.length<=9){const i=t.toLowerCase();if(i==="true")return!0;if(i==="false")return!1;if(i==="undefined")return;if(i==="null")return null;if(i==="nan")return Number.NaN;if(i==="infinity")return Number.POSITIVE_INFINITY;if(i==="-infinity")return Number.NEGATIVE_INFINITY}if(!AI.test(r)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return r}try{if(wI.test(r)||_I.test(r)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(r,EI)}return JSON.parse(r)}catch(i){if(e.strict)throw i;return r}}function SI(r){return!r||typeof r.then!="function"?Promise.resolve(r):r}function _r(r,...e){try{return SI(r(...e))}catch(t){return Promise.reject(t)}}function II(r){const e=typeof r;return r===null||e!=="object"&&e!=="function"}function MI(r){const e=Object.getPrototypeOf(r);return!e||e.isPrototypeOf(Object)}function ih(r){if(II(r))return String(r);if(MI(r)||Array.isArray(r))return JSON.stringify(r);if(typeof r.toJSON=="function")return ih(r.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function M2(){if(typeof Buffer>"u")throw new TypeError("[unstorage] Buffer is not supported!")}const d0="base64:";function PI(r){if(typeof r=="string")return r;M2();const e=Buffer.from(r).toString("base64");return d0+e}function OI(r){return typeof r!="string"||!r.startsWith(d0)?r:(M2(),Buffer.from(r.slice(d0.length),"base64"))}function ai(r){return r?r.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function RI(...r){return ai(r.join(":"))}function Kf(r){return r=ai(r),r?r+":":""}const NI="memory",CI=()=>{const r=new Map;return{name:NI,getInstance:()=>r,hasItem(e){return r.has(e)},getItem(e){return r.get(e)??null},getItemRaw(e){return r.get(e)??null},setItem(e,t){r.set(e,t)},setItemRaw(e,t){r.set(e,t)},removeItem(e){r.delete(e)},getKeys(){return[...r.keys()]},clear(){r.clear()},dispose(){r.clear()}}};function TI(r={}){const e={mounts:{"":r.driver||CI()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},t=p=>{for(const y of e.mountpoints)if(p.startsWith(y))return{base:y,relativeKey:p.slice(y.length),driver:e.mounts[y]};return{base:"",relativeKey:p,driver:e.mounts[""]}},i=(p,y)=>e.mountpoints.filter(A=>A.startsWith(p)||y&&p.startsWith(A)).map(A=>({relativeBase:p.length>A.length?p.slice(A.length):void 0,mountpoint:A,driver:e.mounts[A]})),n=(p,y)=>{if(e.watching){y=ai(y);for(const A of e.watchListeners)A(p,y)}},a=async()=>{if(!e.watching){e.watching=!0;for(const p in e.mounts)e.unwatch[p]=await Pg(e.mounts[p],n,p)}},f=async()=>{if(e.watching){for(const p in e.unwatch)await e.unwatch[p]();e.unwatch={},e.watching=!1}},u=(p,y,A)=>{const R=new Map,O=N=>{let K=R.get(N.base);return K||(K={driver:N.driver,base:N.base,items:[]},R.set(N.base,K)),K};for(const N of p){const K=typeof N=="string",W=ai(K?N:N.key),Q=K?void 0:N.value,j=K||!N.options?y:{...y,...N.options},Y=t(W);O(Y).items.push({key:W,value:Q,relativeKey:Y.relativeKey,options:j})}return Promise.all([...R.values()].map(N=>A(N))).then(N=>N.flat())},b={hasItem(p,y={}){p=ai(p);const{relativeKey:A,driver:R}=t(p);return _r(R.hasItem,A,y)},getItem(p,y={}){p=ai(p);const{relativeKey:A,driver:R}=t(p);return _r(R.getItem,A,y).then(O=>Hf(O))},getItems(p,y){return u(p,y,A=>A.driver.getItems?_r(A.driver.getItems,A.items.map(R=>({key:R.relativeKey,options:R.options})),y).then(R=>R.map(O=>({key:RI(A.base,O.key),value:Hf(O.value)}))):Promise.all(A.items.map(R=>_r(A.driver.getItem,R.relativeKey,R.options).then(O=>({key:R.key,value:Hf(O)})))))},getItemRaw(p,y={}){p=ai(p);const{relativeKey:A,driver:R}=t(p);return R.getItemRaw?_r(R.getItemRaw,A,y):_r(R.getItem,A,y).then(O=>OI(O))},async setItem(p,y,A={}){if(y===void 0)return b.removeItem(p);p=ai(p);const{relativeKey:R,driver:O}=t(p);O.setItem&&(await _r(O.setItem,R,ih(y),A),O.watch||n("update",p))},async setItems(p,y){await u(p,y,async A=>{if(A.driver.setItems)return _r(A.driver.setItems,A.items.map(R=>({key:R.relativeKey,value:ih(R.value),options:R.options})),y);A.driver.setItem&&await Promise.all(A.items.map(R=>_r(A.driver.setItem,R.relativeKey,ih(R.value),R.options)))})},async setItemRaw(p,y,A={}){if(y===void 0)return b.removeItem(p,A);p=ai(p);const{relativeKey:R,driver:O}=t(p);if(O.setItemRaw)await _r(O.setItemRaw,R,y,A);else if(O.setItem)await _r(O.setItem,R,PI(y),A);else return;O.watch||n("update",p)},async removeItem(p,y={}){typeof y=="boolean"&&(y={removeMeta:y}),p=ai(p);const{relativeKey:A,driver:R}=t(p);R.removeItem&&(await _r(R.removeItem,A,y),(y.removeMeta||y.removeMata)&&await _r(R.removeItem,A+"$",y),R.watch||n("remove",p))},async getMeta(p,y={}){typeof y=="boolean"&&(y={nativeOnly:y}),p=ai(p);const{relativeKey:A,driver:R}=t(p),O=Object.create(null);if(R.getMeta&&Object.assign(O,await _r(R.getMeta,A,y)),!y.nativeOnly){const N=await _r(R.getItem,A+"$",y).then(K=>Hf(K));N&&typeof N=="object"&&(typeof N.atime=="string"&&(N.atime=new Date(N.atime)),typeof N.mtime=="string"&&(N.mtime=new Date(N.mtime)),Object.assign(O,N))}return O},setMeta(p,y,A={}){return this.setItem(p+"$",y,A)},removeMeta(p,y={}){return this.removeItem(p+"$",y)},async getKeys(p,y={}){p=Kf(p);const A=i(p,!0);let R=[];const O=[];for(const N of A){const K=await _r(N.driver.getKeys,N.relativeBase,y);for(const W of K){const Q=N.mountpoint+ai(W);R.some(j=>Q.startsWith(j))||O.push(Q)}R=[N.mountpoint,...R.filter(W=>!W.startsWith(N.mountpoint))]}return p?O.filter(N=>N.startsWith(p)&&N[N.length-1]!=="$"):O.filter(N=>N[N.length-1]!=="$")},async clear(p,y={}){p=Kf(p),await Promise.all(i(p,!1).map(async A=>{if(A.driver.clear)return _r(A.driver.clear,A.relativeBase,y);if(A.driver.removeItem){const R=await A.driver.getKeys(A.relativeBase||"",y);return Promise.all(R.map(O=>A.driver.removeItem(O,y)))}}))},async dispose(){await Promise.all(Object.values(e.mounts).map(p=>Og(p)))},async watch(p){return await a(),e.watchListeners.push(p),async()=>{e.watchListeners=e.watchListeners.filter(y=>y!==p),e.watchListeners.length===0&&await f()}},async unwatch(){e.watchListeners=[],await f()},mount(p,y){if(p=Kf(p),p&&e.mounts[p])throw new Error(`already mounted at ${p}`);return p&&(e.mountpoints.push(p),e.mountpoints.sort((A,R)=>R.length-A.length)),e.mounts[p]=y,e.watching&&Promise.resolve(Pg(y,n,p)).then(A=>{e.unwatch[p]=A}).catch(console.error),b},async unmount(p,y=!0){p=Kf(p),!(!p||!e.mounts[p])&&(e.watching&&p in e.unwatch&&(e.unwatch[p](),delete e.unwatch[p]),y&&await Og(e.mounts[p]),e.mountpoints=e.mountpoints.filter(A=>A!==p),delete e.mounts[p])},getMount(p=""){p=ai(p)+":";const y=t(p);return{driver:y.driver,base:y.base}},getMounts(p="",y={}){return p=ai(p),i(p,y.parents).map(R=>({driver:R.driver,base:R.mountpoint}))},keys:(p,y={})=>b.getKeys(p,y),get:(p,y={})=>b.getItem(p,y),set:(p,y,A={})=>b.setItem(p,y,A),has:(p,y={})=>b.hasItem(p,y),del:(p,y={})=>b.removeItem(p,y),remove:(p,y={})=>b.removeItem(p,y)};return b}function Pg(r,e,t){return r.watch?r.watch((i,n)=>e(i,t+n)):()=>{}}async function Og(r){typeof r.dispose=="function"&&await _r(r.dispose)}function Ea(r){return new Promise((e,t)=>{r.oncomplete=r.onsuccess=()=>e(r.result),r.onabort=r.onerror=()=>t(r.error)})}function P2(r,e){const t=indexedDB.open(r);t.onupgradeneeded=()=>t.result.createObjectStore(e);const i=Ea(t);return(n,a)=>i.then(f=>a(f.transaction(e,n).objectStore(e)))}let Dl;function Rc(){return Dl||(Dl=P2("keyval-store","keyval")),Dl}function Rg(r,e=Rc()){return e("readonly",t=>Ea(t.get(r)))}function DI(r,e,t=Rc()){return t("readwrite",i=>(i.put(e,r),Ea(i.transaction)))}function FI(r,e=Rc()){return e("readwrite",t=>(t.delete(r),Ea(t.transaction)))}function BI(r=Rc()){return r("readwrite",e=>(e.clear(),Ea(e.transaction)))}function qI(r,e){return r.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},Ea(r.transaction)}function LI(r=Rc()){return r("readonly",e=>{if(e.getAllKeys)return Ea(e.getAllKeys());const t=[];return qI(e,i=>t.push(i.key)).then(()=>t)})}const UI="idb-keyval";var $I=(r={})=>{const e=r.base&&r.base.length>0?`${r.base}:`:"",t=n=>e+n;let i;return r.dbName&&r.storeName&&(i=P2(r.dbName,r.storeName)),{name:UI,options:r,async hasItem(n){return!(typeof await Rg(t(n),i)>"u")},async getItem(n){return await Rg(t(n),i)??null},setItem(n,a){return DI(t(n),a,i)},removeItem(n){return FI(t(n),i)},getKeys(){return LI(i)},clear(){return BI(i)}}};const zI="WALLET_CONNECT_V2_INDEXED_DB",jI="keyvaluestorage";let kI=class{constructor(){this.indexedDb=TI({driver:$I({dbName:zI,storeName:jI})})}async getKeys(){return this.indexedDb.getKeys()}async getEntries(){return(await this.indexedDb.getItems(await this.indexedDb.getKeys())).map(e=>[e.key,e.value])}async getItem(e){const t=await this.indexedDb.getItem(e);if(t!==null)return t}async setItem(e,t){await this.indexedDb.setItem(e,vs(t))}async removeItem(e){await this.indexedDb.removeItem(e)}};var Fl=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},nh={exports:{}};(function(){let r;function e(){}r=e,r.prototype.getItem=function(t){return this.hasOwnProperty(t)?String(this[t]):null},r.prototype.setItem=function(t,i){this[t]=String(i)},r.prototype.removeItem=function(t){delete this[t]},r.prototype.clear=function(){const t=this;Object.keys(t).forEach(function(i){t[i]=void 0,delete t[i]})},r.prototype.key=function(t){return t=t||0,Object.keys(this)[t]},r.prototype.__defineGetter__("length",function(){return Object.keys(this).length}),typeof Fl<"u"&&Fl.localStorage?nh.exports=Fl.localStorage:typeof window<"u"&&window.localStorage?nh.exports=window.localStorage:nh.exports=new e})();function HI(r){var e;return[r[0],ga((e=r[1])!=null?e:"")]}class KI{constructor(){this.localStorage=nh.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(HI)}async getItem(e){const t=this.localStorage.getItem(e);if(t!==null)return ga(t)}async setItem(e,t){this.localStorage.setItem(e,vs(t))}async removeItem(e){this.localStorage.removeItem(e)}}const VI="wc_storage_version",Ng=1,GI=async(r,e,t)=>{const i=VI,n=await e.getItem(i);if(n&&n>=Ng){t(e);return}const a=await r.getKeys();if(!a.length){t(e);return}const f=[];for(;a.length;){const u=a.shift();if(!u)continue;const b=u.toLowerCase();if(b.includes("wc@")||b.includes("walletconnect")||b.includes("wc_")||b.includes("wallet_connect")){const p=await r.getItem(u);await e.setItem(u,p),f.push(u)}}await e.setItem(i,Ng),t(e),WI(r,f)},WI=async(r,e)=>{e.length&&e.forEach(async t=>{await r.removeItem(t)})};let JI=class{constructor(){this.initialized=!1,this.setInitialized=t=>{this.storage=t,this.initialized=!0};const e=new KI;this.storage=e;try{const t=new kI;GI(e,t,this.setInitialized)}catch{this.initialized=!0}}async getKeys(){return await this.initialize(),this.storage.getKeys()}async getEntries(){return await this.initialize(),this.storage.getEntries()}async getItem(e){return await this.initialize(),this.storage.getItem(e)}async setItem(e,t){return await this.initialize(),this.storage.setItem(e,t)}async removeItem(e){return await this.initialize(),this.storage.removeItem(e)}async initialize(){this.initialized||await new Promise(e=>{const t=setInterval(()=>{this.initialized&&(clearInterval(t),e())},20)})}};function YI(r){try{return JSON.stringify(r)}catch{return'"[Circular]"'}}var QI=XI;function XI(r,e,t){var i=t&&t.stringify||YI,n=1;if(typeof r=="object"&&r!==null){var a=e.length+n;if(a===1)return r;var f=new Array(a);f[0]=i(r);for(var u=1;u-1?A:0,r.charCodeAt(O+1)){case 100:case 102:if(y>=b||e[y]==null)break;A=b||e[y]==null)break;A=b||e[y]===void 0)break;A",A=O+2,O++;break}p+=i(e[y]),A=O+2,O++;break;case 115:if(y>=b)break;A-1&&(a=!1);const f=["error","fatal","warn","info","debug","trace"];typeof t=="function"&&(t.error=t.fatal=t.warn=t.info=t.debug=t.trace=t),r.enabled===!1&&(r.level="silent");const u=r.level||"info",b=Object.create(t);b.log||(b.log=yc),Object.defineProperty(b,"levelVal",{get:y}),Object.defineProperty(b,"level",{get:A,set:R});const p={transmit:e,serialize:n,asObject:r.browser.asObject,levels:f,timestamp:sM(r)};b.levels=Ln.levels,b.level=u,b.setMaxListeners=b.getMaxListeners=b.emit=b.addListener=b.on=b.prependListener=b.once=b.prependOnceListener=b.removeListener=b.removeAllListeners=b.listeners=b.listenerCount=b.eventNames=b.write=b.flush=yc,b.serializers=i,b._serialize=n,b._stdErrSerialize=a,b.child=O,e&&(b._logEvent=p0());function y(){return this.level==="silent"?1/0:this.levels.values[this.level]}function A(){return this._level}function R(N){if(N!=="silent"&&!this.levels.values[N])throw Error("unknown level "+N);this._level=N,Ka(p,b,"error","log"),Ka(p,b,"fatal","error"),Ka(p,b,"warn","error"),Ka(p,b,"info","log"),Ka(p,b,"debug","log"),Ka(p,b,"trace","log")}function O(N,K){if(!N)throw new Error("missing bindings for child Pino");K=K||{},n&&N.serializers&&(K.serializers=N.serializers);const W=K.serializers;if(n&&W){var Q=Object.assign({},i,W),j=r.browser.serialize===!0?Object.keys(Q):n;delete N.serializers,kh([N],j,Q,this._stdErrSerialize)}function Y(U){this._childLevel=(U._childLevel|0)+1,this.error=Va(U,N,"error"),this.fatal=Va(U,N,"fatal"),this.warn=Va(U,N,"warn"),this.info=Va(U,N,"info"),this.debug=Va(U,N,"debug"),this.trace=Va(U,N,"trace"),Q&&(this.serializers=Q,this._serialize=j),e&&(this._logEvent=p0([].concat(U._logEvent.bindings,N)))}return Y.prototype=this,new Y(this)}return b}Ln.levels={values:{fatal:60,error:50,warn:40,info:30,debug:20,trace:10},labels:{10:"trace",20:"debug",30:"info",40:"warn",50:"error",60:"fatal"}};Ln.stdSerializers=ZI;Ln.stdTimeFunctions=Object.assign({},{nullTime:O2,epochTime:R2,unixTime:aM,isoTime:oM});function Ka(r,e,t,i){const n=Object.getPrototypeOf(e);e[t]=e.levelVal>e.levels.values[t]?yc:n[t]?n[t]:mc[t]||mc[i]||yc,tM(r,e,t)}function tM(r,e,t){!r.transmit&&e[t]===yc||(e[t]=function(i){return function(){const a=r.timestamp(),f=new Array(arguments.length),u=Object.getPrototypeOf&&Object.getPrototypeOf(this)===mc?mc:this;for(var b=0;b-1&&a in t&&(r[n][a]=t[a](r[n][a]))}function Va(r,e,t){return function(){const i=new Array(1+arguments.length);i[0]=e;for(var n=1;nthis.maxSizeInBytes)throw new Error(`[LinkedList] Value too big to insert into list: ${e} with size ${t.size}`);for(;this.size+t.size>this.maxSizeInBytes;)this.shift();this.head?(this.tail&&(this.tail.next=t),this.tail=t):(this.head=t,this.tail=t),this.lengthInNodes++,this.sizeInBytes+=t.size}shift(){if(!this.head)return;const e=this.head;this.head=this.head.next,this.head||(this.tail=null),this.lengthInNodes--,this.sizeInBytes-=e.size}toArray(){const e=[];let t=this.head;for(;t!==null;)e.push(t.value),t=t.next;return e}get length(){return this.lengthInNodes}get size(){return this.sizeInBytes}toOrderedArray(){return Array.from(this)}[Symbol.iterator](){let e=this.head;return{next:()=>{if(!e)return{done:!0,value:null};const t=e.value;return e=e.next,{done:!1,value:t}}}}},N2=class{constructor(e,t=Q0){this.level=e??"error",this.levelValue=Ja.levels.values[this.level],this.MAX_LOG_SIZE_IN_BYTES=t,this.logs=new Tg(this.MAX_LOG_SIZE_IN_BYTES)}forwardToConsole(e,t){t===Ja.levels.values.error?console.error(e):t===Ja.levels.values.warn?console.warn(e):t===Ja.levels.values.debug?console.debug(e):t===Ja.levels.values.trace?console.trace(e):console.log(e)}appendToLogs(e){this.logs.append(vs({timestamp:new Date().toISOString(),log:e}));const t=typeof e=="string"?JSON.parse(e).level:e.level;t>=this.levelValue&&this.forwardToConsole(e,t)}getLogs(){return this.logs}clearLogs(){this.logs=new Tg(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(e){const t=this.getLogArray();return t.push(vs({extraMetadata:e})),new Blob(t,{type:"application/json"})}},uM=class{constructor(e,t=Q0){this.baseChunkLogger=new N2(e,t)}write(e){this.baseChunkLogger.appendToLogs(e)}getLogs(){return this.baseChunkLogger.getLogs()}clearLogs(){this.baseChunkLogger.clearLogs()}getLogArray(){return this.baseChunkLogger.getLogArray()}logsToBlob(e){return this.baseChunkLogger.logsToBlob(e)}downloadLogsBlobInBrowser(e){const t=URL.createObjectURL(this.logsToBlob(e)),i=document.createElement("a");i.href=t,i.download=`walletconnect-logs-${new Date().toISOString()}.txt`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(t)}};class lM{constructor(e,t=Q0){this.baseChunkLogger=new N2(e,t)}write(e){this.baseChunkLogger.appendToLogs(e)}getLogs(){return this.baseChunkLogger.getLogs()}clearLogs(){this.baseChunkLogger.clearLogs()}getLogArray(){return this.baseChunkLogger.getLogArray()}logsToBlob(e){return this.baseChunkLogger.logsToBlob(e)}}var dM=Object.defineProperty,pM=Object.defineProperties,gM=Object.getOwnPropertyDescriptors,Dg=Object.getOwnPropertySymbols,vM=Object.prototype.hasOwnProperty,bM=Object.prototype.propertyIsEnumerable,Fg=(r,e,t)=>e in r?dM(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,wh=(r,e)=>{for(var t in e||(e={}))vM.call(e,t)&&Fg(r,t,e[t]);if(Dg)for(var t of Dg(e))bM.call(e,t)&&Fg(r,t,e[t]);return r},_h=(r,e)=>pM(r,gM(e));function Hh(r){return _h(wh({},r),{level:(r==null?void 0:r.level)||fM.level})}function mM(r,e=Cc){return r[e]||""}function yM(r,e,t=Cc){return r[t]=e,r}function di(r,e=Cc){let t="";return typeof r.bindings>"u"?t=mM(r,e):t=r.bindings().context||"",t}function wM(r,e,t=Cc){const i=di(r,t);return i.trim()?`${i}/${e}`:e}function Yr(r,e,t=Cc){const i=wM(r,e,t),n=r.child({context:i});return yM(n,i,t)}function _M(r){var e,t;const i=new uM((e=r.opts)==null?void 0:e.level,r.maxSizeInBytes);return{logger:Nc(_h(wh({},r.opts),{level:"trace",browser:_h(wh({},(t=r.opts)==null?void 0:t.browser),{write:n=>i.write(n)})})),chunkLoggerController:i}}function AM(r){var e;const t=new lM((e=r.opts)==null?void 0:e.level,r.maxSizeInBytes);return{logger:Nc(_h(wh({},r.opts),{level:"trace"}),t),chunkLoggerController:t}}function EM(r){return typeof r.loggerOverride<"u"&&typeof r.loggerOverride!="string"?{logger:r.loggerOverride,chunkLoggerController:null}:typeof window<"u"?_M(r):AM(r)}let xM=class extends Aa{constructor(e){super(),this.opts=e,this.protocol="wc",this.version=2}},SM=class extends Aa{constructor(e,t){super(),this.core=e,this.logger=t,this.records=new Map}},IM=class{constructor(e,t){this.logger=e,this.core=t}},MM=class extends Aa{constructor(e,t){super(),this.relayer=e,this.logger=t}},PM=class extends Aa{constructor(e){super()}},OM=class{constructor(e,t,i,n){this.core=e,this.logger=t,this.name=i}},RM=class extends Aa{constructor(e,t){super(),this.relayer=e,this.logger=t}},NM=class extends Aa{constructor(e,t){super(),this.core=e,this.logger=t}},CM=class{constructor(e,t,i){this.core=e,this.logger=t,this.store=i}},TM=class{constructor(e,t){this.projectId=e,this.logger=t}},DM=class{constructor(e,t,i){this.core=e,this.logger=t,this.telemetryEnabled=i}},FM=class{constructor(e){this.opts=e,this.protocol="wc",this.version=2}},BM=class{constructor(e){this.client=e}};const qM="PARSE_ERROR",LM="INVALID_REQUEST",UM="METHOD_NOT_FOUND",$M="INVALID_PARAMS",C2="INTERNAL_ERROR",X0="SERVER_ERROR",zM=[-32700,-32600,-32601,-32602,-32603],hc={[qM]:{code:-32700,message:"Parse error"},[LM]:{code:-32600,message:"Invalid Request"},[UM]:{code:-32601,message:"Method not found"},[$M]:{code:-32602,message:"Invalid params"},[C2]:{code:-32603,message:"Internal error"},[X0]:{code:-32e3,message:"Server error"}},T2=X0;function jM(r){return zM.includes(r)}function Bg(r){return Object.keys(hc).includes(r)?hc[r]:hc[T2]}function kM(r){const e=Object.values(hc).find(t=>t.code===r);return e||hc[T2]}function D2(r,e,t){return r.message.includes("getaddrinfo ENOTFOUND")||r.message.includes("connect ECONNREFUSED")?new Error(`Unavailable ${t} RPC url at ${e}`):r}var F2={};/*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */var g0=function(r,e){return g0=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,i){t.__proto__=i}||function(t,i){for(var n in i)i.hasOwnProperty(n)&&(t[n]=i[n])},g0(r,e)};function HM(r,e){g0(r,e);function t(){this.constructor=r}r.prototype=e===null?Object.create(e):(t.prototype=e.prototype,new t)}var v0=function(){return v0=Object.assign||function(e){for(var t,i=1,n=arguments.length;i=0;u--)(f=r[u])&&(a=(n<3?f(a):n>3?f(e,t,a):f(e,t))||a);return n>3&&a&&Object.defineProperty(e,t,a),a}function GM(r,e){return function(t,i){e(t,i,r)}}function WM(r,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(r,e)}function JM(r,e,t,i){function n(a){return a instanceof t?a:new t(function(f){f(a)})}return new(t||(t=Promise))(function(a,f){function u(y){try{p(i.next(y))}catch(A){f(A)}}function b(y){try{p(i.throw(y))}catch(A){f(A)}}function p(y){y.done?a(y.value):n(y.value).then(u,b)}p((i=i.apply(r,e||[])).next())})}function YM(r,e){var t={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},i,n,a,f;return f={next:u(0),throw:u(1),return:u(2)},typeof Symbol=="function"&&(f[Symbol.iterator]=function(){return this}),f;function u(p){return function(y){return b([p,y])}}function b(p){if(i)throw new TypeError("Generator is already executing.");for(;t;)try{if(i=1,n&&(a=p[0]&2?n.return:p[0]?n.throw||((a=n.return)&&a.call(n),0):n.next)&&!(a=a.call(n,p[1])).done)return a;switch(n=0,a&&(p=[p[0]&2,a.value]),p[0]){case 0:case 1:a=p;break;case 4:return t.label++,{value:p[1],done:!1};case 5:t.label++,n=p[1],p=[0];continue;case 7:p=t.ops.pop(),t.trys.pop();continue;default:if(a=t.trys,!(a=a.length>0&&a[a.length-1])&&(p[0]===6||p[0]===2)){t=0;continue}if(p[0]===3&&(!a||p[1]>a[0]&&p[1]=r.length&&(r=void 0),{value:r&&r[i++],done:!r}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function B2(r,e){var t=typeof Symbol=="function"&&r[Symbol.iterator];if(!t)return r;var i=t.call(r),n,a=[],f;try{for(;(e===void 0||e-- >0)&&!(n=i.next()).done;)a.push(n.value)}catch(u){f={error:u}}finally{try{n&&!n.done&&(t=i.return)&&t.call(i)}finally{if(f)throw f.error}}return a}function ZM(){for(var r=[],e=0;e1||u(R,O)})})}function u(R,O){try{b(i[R](O))}catch(N){A(a[0][3],N)}}function b(R){R.value instanceof wc?Promise.resolve(R.value.v).then(p,y):A(a[0][2],R)}function p(R){u("next",R)}function y(R){u("throw",R)}function A(R,O){R(O),a.shift(),a.length&&u(a[0][0],a[0][1])}}function rP(r){var e,t;return e={},i("next"),i("throw",function(n){throw n}),i("return"),e[Symbol.iterator]=function(){return this},e;function i(n,a){e[n]=r[n]?function(f){return(t=!t)?{value:wc(r[n](f)),done:n==="return"}:a?a(f):f}:a}}function iP(r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=r[Symbol.asyncIterator],t;return e?e.call(r):(r=typeof b0=="function"?b0(r):r[Symbol.iterator](),t={},i("next"),i("throw"),i("return"),t[Symbol.asyncIterator]=function(){return this},t);function i(a){t[a]=r[a]&&function(f){return new Promise(function(u,b){f=r[a](f),n(u,b,f.done,f.value)})}}function n(a,f,u,b){Promise.resolve(b).then(function(p){a({value:p,done:u})},f)}}function nP(r,e){return Object.defineProperty?Object.defineProperty(r,"raw",{value:e}):r.raw=e,r}function sP(r){if(r&&r.__esModule)return r;var e={};if(r!=null)for(var t in r)Object.hasOwnProperty.call(r,t)&&(e[t]=r[t]);return e.default=r,e}function aP(r){return r&&r.__esModule?r:{default:r}}function oP(r,e){if(!e.has(r))throw new TypeError("attempted to get private field on non-instance");return e.get(r)}function cP(r,e,t){if(!e.has(r))throw new TypeError("attempted to set private field on non-instance");return e.set(r,t),t}const fP=Object.freeze(Object.defineProperty({__proto__:null,get __assign(){return v0},__asyncDelegator:rP,__asyncGenerator:tP,__asyncValues:iP,__await:wc,__awaiter:JM,__classPrivateFieldGet:oP,__classPrivateFieldSet:cP,__createBinding:QM,__decorate:VM,__exportStar:XM,__extends:HM,__generator:YM,__importDefault:aP,__importStar:sP,__makeTemplateObject:nP,__metadata:WM,__param:GM,__read:B2,__rest:KM,__spread:ZM,__spreadArrays:eP,__values:b0},Symbol.toStringTag,{value:"Module"})),hP=Tv(fP);var ss={},qg;function uP(){if(qg)return ss;qg=1,Object.defineProperty(ss,"__esModule",{value:!0}),ss.isBrowserCryptoAvailable=ss.getSubtleCrypto=ss.getBrowerCrypto=void 0;function r(){return(ji===null||ji===void 0?void 0:ji.crypto)||(ji===null||ji===void 0?void 0:ji.msCrypto)||{}}ss.getBrowerCrypto=r;function e(){const i=r();return i.subtle||i.webkitSubtle}ss.getSubtleCrypto=e;function t(){return!!r()&&!!e()}return ss.isBrowserCryptoAvailable=t,ss}var as={},Lg;function lP(){if(Lg)return as;Lg=1,Object.defineProperty(as,"__esModule",{value:!0}),as.isBrowser=as.isNode=as.isReactNative=void 0;function r(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}as.isReactNative=r;function e(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}as.isNode=e;function t(){return!r()&&!e()}return as.isBrowser=t,as}(function(r){Object.defineProperty(r,"__esModule",{value:!0});const e=hP;e.__exportStar(uP(),r),e.__exportStar(lP(),r)})(F2);function Cs(r=3){const e=Date.now()*Math.pow(10,r),t=Math.floor(Math.random()*Math.pow(10,r));return e+t}function ha(r=6){return BigInt(Cs(r))}function qs(r,e,t){return{id:t||Cs(),jsonrpc:"2.0",method:r,params:e}}function Kh(r,e){return{id:r,jsonrpc:"2.0",result:e}}function Vh(r,e,t){return{id:r,jsonrpc:"2.0",error:dP(e)}}function dP(r,e){return typeof r>"u"?Bg(C2):(typeof r=="string"&&(r=Object.assign(Object.assign({},Bg(X0)),{message:r})),jM(r.code)&&(r=kM(r.code)),r)}class pP{}class gP extends pP{constructor(){super()}}class vP extends gP{constructor(e){super()}}const bP="^https?:",mP="^wss?:";function yP(r){const e=r.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function q2(r,e){const t=yP(r);return typeof t>"u"?!1:new RegExp(e).test(t)}function Ug(r){return q2(r,bP)}function $g(r){return q2(r,mP)}function wP(r){return new RegExp("wss?://localhost(:d{2,5})?").test(r)}function L2(r){return typeof r=="object"&&"id"in r&&"jsonrpc"in r&&r.jsonrpc==="2.0"}function Z0(r){return L2(r)&&"method"in r}function Gh(r){return L2(r)&&(Mn(r)||$i(r))}function Mn(r){return"result"in r}function $i(r){return"error"in r}let gn=class extends vP{constructor(e){super(e),this.events=new Hi.EventEmitter,this.hasRegisteredEventListeners=!1,this.connection=this.setConnection(e),this.connection.connected&&this.registerEventListeners()}async connect(e=this.connection){await this.open(e)}async disconnect(){await this.close()}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async request(e,t){return this.requestStrict(qs(e.method,e.params||[],e.id||ha().toString()),t)}async requestStrict(e,t){return new Promise(async(i,n)=>{if(!this.connection.connected)try{await this.open()}catch(a){n(a)}this.events.on(`${e.id}`,a=>{$i(a)?n(a.error):i(a.result)});try{await this.connection.send(e,t)}catch(a){n(a)}})}setConnection(e=this.connection){return e}onPayload(e){this.events.emit("payload",e),Gh(e)?this.events.emit(`${e.id}`,e):this.events.emit("message",{type:e.method,data:e.params})}onClose(e){e&&e.code===3e3&&this.events.emit("error",new Error(`WebSocket connection closed abnormally with code: ${e.code} ${e.reason?`(${e.reason})`:""}`)),this.events.emit("disconnect")}async open(e=this.connection){this.connection===e&&this.connection.connected||(this.connection.connected&&this.close(),typeof e=="string"&&(await this.connection.open(e),e=this.connection),this.connection=this.setConnection(e),await this.connection.open(),this.registerEventListeners(),this.events.emit("connect"))}async close(){await this.connection.close()}registerEventListeners(){this.hasRegisteredEventListeners||(this.connection.on("payload",e=>this.onPayload(e)),this.connection.on("close",e=>this.onClose(e)),this.connection.on("error",e=>this.events.emit("error",e)),this.connection.on("register_error",e=>this.onClose()),this.hasRegisteredEventListeners=!0)}};const _P=()=>typeof WebSocket<"u"?WebSocket:typeof global<"u"&&typeof global.WebSocket<"u"?global.WebSocket:typeof window<"u"&&typeof window.WebSocket<"u"?window.WebSocket:typeof self<"u"&&typeof self.WebSocket<"u"?self.WebSocket:require("ws"),AP=()=>typeof WebSocket<"u"||typeof global<"u"&&typeof global.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",zg=r=>r.split("?")[0],jg=10,EP=_P();let xP=class{constructor(e){if(this.url=e,this.events=new Hi.EventEmitter,this.registering=!1,!$g(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);this.url=e}get connected(){return typeof this.socket<"u"}get connecting(){return this.registering}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async open(e=this.url){await this.register(e)}async close(){return new Promise((e,t)=>{if(typeof this.socket>"u"){t(new Error("Connection already closed"));return}this.socket.onclose=i=>{this.onClose(i),e()},this.socket.close()})}async send(e){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(vs(e))}catch(t){this.onError(e.id,t)}}register(e=this.url){if(!$g(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);if(this.registering){const t=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=t||this.events.listenerCount("open")>=t)&&this.events.setMaxListeners(t+1),new Promise((i,n)=>{this.events.once("register_error",a=>{this.resetMaxListeners(),n(a)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.socket>"u")return n(new Error("WebSocket connection is missing or invalid"));i(this.socket)})})}return this.url=e,this.registering=!0,new Promise((t,i)=>{const n=new URLSearchParams(e).get("origin"),a=F2.isReactNative()?{headers:{origin:n}}:{rejectUnauthorized:!wP(e)},f=new EP(e,[],a);AP()?f.onerror=u=>{const b=u;i(this.emitError(b.error))}:f.on("error",u=>{i(this.emitError(u))}),f.onopen=()=>{this.onOpen(f),t(f)}})}onOpen(e){e.onmessage=t=>this.onPayload(t),e.onclose=t=>this.onClose(t),this.socket=e,this.registering=!1,this.events.emit("open")}onClose(e){this.socket=void 0,this.registering=!1,this.events.emit("close",e)}onPayload(e){if(typeof e.data>"u")return;const t=typeof e.data=="string"?ga(e.data):e.data;this.events.emit("payload",t)}onError(e,t){const i=this.parseError(t),n=i.message||i.toString(),a=Vh(e,n);this.events.emit("payload",a)}parseError(e,t=this.url){return D2(e,zg(t),"WS")}resetMaxListeners(){this.events.getMaxListeners()>jg&&this.events.setMaxListeners(jg)}emitError(e){const t=this.parseError(new Error((e==null?void 0:e.message)||`WebSocket connection failed for host: ${zg(this.url)}`));return this.events.emit("register_error",t),t}};var Ah={exports:{}};Ah.exports;(function(r,e){var t=200,i="__lodash_hash_undefined__",n=1,a=2,f=9007199254740991,u="[object Arguments]",b="[object Array]",p="[object AsyncFunction]",y="[object Boolean]",A="[object Date]",R="[object Error]",O="[object Function]",N="[object GeneratorFunction]",K="[object Map]",W="[object Number]",Q="[object Null]",j="[object Object]",Y="[object Promise]",U="[object Proxy]",k="[object RegExp]",G="[object Set]",x="[object String]",B="[object Symbol]",ae="[object Undefined]",le="[object WeakMap]",F="[object ArrayBuffer]",m="[object DataView]",c="[object Float32Array]",h="[object Float64Array]",v="[object Int8Array]",_="[object Int16Array]",I="[object Int32Array]",M="[object Uint8Array]",S="[object Uint8ClampedArray]",d="[object Uint16Array]",g="[object Uint32Array]",T=/[\\^$.*+?()[\]{}|]/g,Z=/^\[object .+?Constructor\]$/,se=/^(?:0|[1-9]\d*)$/,P={};P[c]=P[h]=P[v]=P[_]=P[I]=P[M]=P[S]=P[d]=P[g]=!0,P[u]=P[b]=P[F]=P[y]=P[m]=P[A]=P[R]=P[O]=P[K]=P[W]=P[j]=P[k]=P[G]=P[x]=P[le]=!1;var ee=typeof ji=="object"&&ji&&ji.Object===Object&&ji,q=typeof self=="object"&&self&&self.Object===Object&&self,z=ee||q||Function("return this")(),H=e&&!e.nodeType&&e,w=H&&!0&&r&&!r.nodeType&&r,$=w&&w.exports===H,ne=$&&ee.process,ce=function(){try{return ne&&ne.binding&&ne.binding("util")}catch{}}(),he=ce&&ce.isTypedArray;function ye(V,te){for(var pe=-1,Ue=V==null?0:V.length,jt=0,pt=[];++pe-1}function Br(V,te){var pe=this.__data__,Ue=ks(pe,V);return Ue<0?(++this.size,pe.push([V,te])):pe[Ue][1]=te,this}bt.prototype.clear=Cr,bt.prototype.delete=Tr,bt.prototype.get=Dr,bt.prototype.has=Fr,bt.prototype.set=Br;function er(V){var te=-1,pe=V==null?0:V.length;for(this.clear();++tehr))return!1;var kt=pt.get(V);if(kt&&pt.get(te))return kt==te;var sr=-1,ei=!0,ur=pe&a?new Zr:void 0;for(pt.set(V,te),pt.set(te,V);++sr-1&&V%1==0&&V-1&&V%1==0&&V<=f}function Jc(V){var te=typeof V;return V!=null&&(te=="object"||te=="function")}function Vs(V){return V!=null&&typeof V=="object"}var Yc=he?Oe(he):qc;function tu(V){return Zh(V)?Fc(V):Lc(V)}function zt(){return[]}function $t(){return!1}r.exports=eu})(Ah,Ah.exports);var SP=Ah.exports;const IP=S0(SP),U2="wc",$2=2,ed="core",kn=`${U2}@2:${ed}:`,MP={name:ed,logger:"error"},PP={database:":memory:"},OP="crypto",kg="client_ed25519_seed",RP=xe.ONE_DAY,NP="keychain",CP="0.3",TP="messages",DP="0.3",FP=xe.SIX_HOURS,BP="publisher",z2="irn",qP="error",j2="wss://relay.walletconnect.org",LP="relayer",Gr={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"},UP="_subscription",qi={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},$P=.1,m0="2.17.0",Kt={link_mode:"link_mode",relay:"relay"},zP="0.3",jP="WALLETCONNECT_CLIENT_ID",Hg="WALLETCONNECT_LINK_MODE_APPS",Pn={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},kP="subscription",HP="0.3",KP=xe.FIVE_SECONDS*1e3,VP="pairing",GP="0.3",Xo={wc_pairingDelete:{req:{ttl:xe.ONE_DAY,prompt:!1,tag:1e3},res:{ttl:xe.ONE_DAY,prompt:!1,tag:1001}},wc_pairingPing:{req:{ttl:xe.THIRTY_SECONDS,prompt:!1,tag:1002},res:{ttl:xe.THIRTY_SECONDS,prompt:!1,tag:1003}},unregistered_method:{req:{ttl:xe.ONE_DAY,prompt:!1,tag:0},res:{ttl:xe.ONE_DAY,prompt:!1,tag:0}}},ca={create:"pairing_create",expire:"pairing_expire",delete:"pairing_delete",ping:"pairing_ping"},on={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},WP="history",JP="0.3",YP="expirer",Li={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},QP="0.3",XP="verify-api",ZP="https://verify.walletconnect.com",k2="https://verify.walletconnect.org",uc=k2,eO=`${uc}/v3`,tO=[ZP,k2],rO="echo",iO="https://echo.walletconnect.com",xn={pairing_started:"pairing_started",pairing_uri_validation_success:"pairing_uri_validation_success",pairing_uri_not_expired:"pairing_uri_not_expired",store_new_pairing:"store_new_pairing",subscribing_pairing_topic:"subscribing_pairing_topic",subscribe_pairing_topic_success:"subscribe_pairing_topic_success",existing_pairing:"existing_pairing",pairing_not_expired:"pairing_not_expired",emit_inactive_pairing:"emit_inactive_pairing",emit_session_proposal:"emit_session_proposal",subscribing_to_pairing_topic:"subscribing_to_pairing_topic"},os={no_wss_connection:"no_wss_connection",no_internet_connection:"no_internet_connection",malformed_pairing_uri:"malformed_pairing_uri",active_pairing_already_exists:"active_pairing_already_exists",subscribe_pairing_topic_failure:"subscribe_pairing_topic_failure",pairing_expired:"pairing_expired",proposal_expired:"proposal_expired",proposal_listener_not_found:"proposal_listener_not_found"},cn={session_approve_started:"session_approve_started",proposal_not_expired:"proposal_not_expired",session_namespaces_validation_success:"session_namespaces_validation_success",create_session_topic:"create_session_topic",subscribing_session_topic:"subscribing_session_topic",subscribe_session_topic_success:"subscribe_session_topic_success",publishing_session_approve:"publishing_session_approve",session_approve_publish_success:"session_approve_publish_success",store_session:"store_session",publishing_session_settle:"publishing_session_settle",session_settle_publish_success:"session_settle_publish_success"},sa={no_internet_connection:"no_internet_connection",no_wss_connection:"no_wss_connection",proposal_expired:"proposal_expired",subscribe_session_topic_failure:"subscribe_session_topic_failure",session_approve_publish_failure:"session_approve_publish_failure",session_settle_publish_failure:"session_settle_publish_failure",session_approve_namespace_validation_failure:"session_approve_namespace_validation_failure",proposal_not_found:"proposal_not_found"},aa={authenticated_session_approve_started:"authenticated_session_approve_started",authenticated_session_not_expired:"authenticated_session_not_expired",chains_caip2_compliant:"chains_caip2_compliant",chains_evm_compliant:"chains_evm_compliant",create_authenticated_session_topic:"create_authenticated_session_topic",cacaos_verified:"cacaos_verified",store_authenticated_session:"store_authenticated_session",subscribing_authenticated_session_topic:"subscribing_authenticated_session_topic",subscribe_authenticated_session_topic_success:"subscribe_authenticated_session_topic_success",publishing_authenticated_session_approve:"publishing_authenticated_session_approve",authenticated_session_approve_publish_success:"authenticated_session_approve_publish_success"},Zo={no_internet_connection:"no_internet_connection",no_wss_connection:"no_wss_connection",missing_session_authenticate_request:"missing_session_authenticate_request",session_authenticate_request_expired:"session_authenticate_request_expired",chains_caip2_compliant_failure:"chains_caip2_compliant_failure",chains_evm_compliant_failure:"chains_evm_compliant_failure",invalid_cacao:"invalid_cacao",subscribe_authenticated_session_topic_failure:"subscribe_authenticated_session_topic_failure",authenticated_session_approve_publish_failure:"authenticated_session_approve_publish_failure",authenticated_session_pending_request_not_found:"authenticated_session_pending_request_not_found"},nO=.1,sO="event-client",aO=86400,oO="https://pulse.walletconnect.org/batch";function cO(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),i=0;i>>0,U=new Uint8Array(Y);Q!==j;){for(var k=N[Q],G=0,x=Y-1;(k!==0||G>>0,U[x]=k%u>>>0,k=k/u>>>0;if(k!==0)throw new Error("Non-zero carry");W=G,Q++}for(var B=Y-W;B!==Y&&U[B]===0;)B++;for(var ae=b.repeat(K);B>>0,Y=new Uint8Array(j);N[K];){var U=t[N.charCodeAt(K)];if(U===255)return;for(var k=0,G=j-1;(U!==0||k>>0,Y[G]=U%256>>>0,U=U/256>>>0;if(U!==0)throw new Error("Non-zero carry");Q=k,K++}if(N[K]!==" "){for(var x=j-Q;x!==j&&Y[x]===0;)x++;for(var B=new Uint8Array(W+(j-x)),ae=W;x!==j;)B[ae++]=Y[x++];return B}}}function O(N){var K=R(N);if(K)return K;throw new Error(`Non-${e} character`)}return{encode:A,decodeUnsafe:R,decode:O}}var fO=cO,hO=fO;const H2=r=>{if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")},uO=r=>new TextEncoder().encode(r),lO=r=>new TextDecoder().decode(r);class dO{constructor(e,t,i){this.name=e,this.prefix=t,this.baseEncode=i}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class pO{constructor(e,t,i){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=i}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return K2(this,e)}}class gO{constructor(e){this.decoders=e}or(e){return K2(this,e)}decode(e){const t=e[0],i=this.decoders[t];if(i)return i.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const K2=(r,e)=>new gO({...r.decoders||{[r.prefix]:r},...e.decoders||{[e.prefix]:e}});class vO{constructor(e,t,i,n){this.name=e,this.prefix=t,this.baseEncode=i,this.baseDecode=n,this.encoder=new dO(e,t,i),this.decoder=new pO(e,t,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Wh=({name:r,prefix:e,encode:t,decode:i})=>new vO(r,e,t,i),Tc=({prefix:r,name:e,alphabet:t})=>{const{encode:i,decode:n}=hO(t,e);return Wh({prefix:r,name:e,encode:i,decode:a=>H2(n(a))})},bO=(r,e,t,i)=>{const n={};for(let y=0;y=8&&(u-=8,f[p++]=255&b>>u)}if(u>=t||255&b<<8-u)throw new SyntaxError("Unexpected end of data");return f},mO=(r,e,t)=>{const i=e[e.length-1]==="=",n=(1<t;)f-=t,a+=e[n&u>>f];if(f&&(a+=e[n&u<Wh({prefix:e,name:r,encode(n){return mO(n,i,t)},decode(n){return bO(n,i,t,r)}}),yO=Wh({prefix:"\0",name:"identity",encode:r=>lO(r),decode:r=>uO(r)});var wO=Object.freeze({__proto__:null,identity:yO});const _O=Nr({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var AO=Object.freeze({__proto__:null,base2:_O});const EO=Nr({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var xO=Object.freeze({__proto__:null,base8:EO});const SO=Tc({prefix:"9",name:"base10",alphabet:"0123456789"});var IO=Object.freeze({__proto__:null,base10:SO});const MO=Nr({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),PO=Nr({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var OO=Object.freeze({__proto__:null,base16:MO,base16upper:PO});const RO=Nr({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),NO=Nr({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),CO=Nr({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),TO=Nr({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),DO=Nr({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),FO=Nr({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),BO=Nr({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qO=Nr({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),LO=Nr({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var UO=Object.freeze({__proto__:null,base32:RO,base32upper:NO,base32pad:CO,base32padupper:TO,base32hex:DO,base32hexupper:FO,base32hexpad:BO,base32hexpadupper:qO,base32z:LO});const $O=Tc({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zO=Tc({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var jO=Object.freeze({__proto__:null,base36:$O,base36upper:zO});const kO=Tc({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),HO=Tc({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var KO=Object.freeze({__proto__:null,base58btc:kO,base58flickr:HO});const VO=Nr({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),GO=Nr({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),WO=Nr({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),JO=Nr({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var YO=Object.freeze({__proto__:null,base64:VO,base64pad:GO,base64url:WO,base64urlpad:JO});const V2=Array.from("🚀🪐☄🛰🌌🌑🌒🌓🌔🌕🌖🌗🌘🌍🌏🌎🐉☀💻🖥💾💿😂❤😍🤣😊🙏💕😭😘👍😅👏😁🔥🥰💔💖💙😢🤔😆🙄💪😉☺👌🤗💜😔😎😇🌹🤦🎉💞✌✨🤷😱😌🌸🙌😋💗💚😏💛🙂💓🤩😄😀🖤😃💯🙈👇🎶😒🤭❣😜💋👀😪😑💥🙋😞😩😡🤪👊🥳😥🤤👉💃😳✋😚😝😴🌟😬🙃🍀🌷😻😓⭐✅🥺🌈😈🤘💦✔😣🏃💐☹🎊💘😠☝😕🌺🎂🌻😐🖕💝🙊😹🗣💫💀👑🎵🤞😛🔴😤🌼😫⚽🤙☕🏆🤫👈😮🙆🍻🍃🐶💁😲🌿🧡🎁⚡🌞🎈❌✊👋😰🤨😶🤝🚶💰🍓💢🤟🙁🚨💨🤬✈🎀🍺🤓😙💟🌱😖👶🥴▶➡❓💎💸⬇😨🌚🦋😷🕺⚠🙅😟😵👎🤲🤠🤧📌🔵💅🧐🐾🍒😗🤑🌊🤯🐷☎💧😯💆👆🎤🙇🍑❄🌴💣🐸💌📍🥀🤢👅💡💩👐📸👻🤐🤮🎼🥵🚩🍎🍊👼💍📣🥂"),QO=V2.reduce((r,e,t)=>(r[t]=e,r),[]),XO=V2.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function ZO(r){return r.reduce((e,t)=>(e+=QO[t],e),"")}function eR(r){const e=[];for(const t of r){const i=XO[t.codePointAt(0)];if(i===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}const tR=Wh({prefix:"🚀",name:"base256emoji",encode:ZO,decode:eR});var rR=Object.freeze({__proto__:null,base256emoji:tR}),iR=G2,Kg=128,nR=127,sR=~nR,aR=Math.pow(2,31);function G2(r,e,t){e=e||[],t=t||0;for(var i=t;r>=aR;)e[t++]=r&255|Kg,r/=128;for(;r&sR;)e[t++]=r&255|Kg,r>>>=7;return e[t]=r|0,G2.bytes=t-i+1,e}var oR=y0,cR=128,Vg=127;function y0(r,i){var t=0,i=i||0,n=0,a=i,f,u=r.length;do{if(a>=u)throw y0.bytes=0,new RangeError("Could not decode varint");f=r[a++],t+=n<28?(f&Vg)<=cR);return y0.bytes=a-i,t}var fR=Math.pow(2,7),hR=Math.pow(2,14),uR=Math.pow(2,21),lR=Math.pow(2,28),dR=Math.pow(2,35),pR=Math.pow(2,42),gR=Math.pow(2,49),vR=Math.pow(2,56),bR=Math.pow(2,63),mR=function(r){return r(W2.encode(r,e,t),e),Wg=r=>W2.encodingLength(r),w0=(r,e)=>{const t=e.byteLength,i=Wg(r),n=i+Wg(t),a=new Uint8Array(n+t);return Gg(r,a,0),Gg(t,a,i),a.set(e,n),new wR(r,t,e,a)};class wR{constructor(e,t,i,n){this.code=e,this.size=t,this.digest=i,this.bytes=n}}const J2=({name:r,code:e,encode:t})=>new _R(r,e,t);class _R{constructor(e,t,i){this.name=e,this.code=t,this.encode=i}digest(e){if(e instanceof Uint8Array){const t=this.encode(e);return t instanceof Uint8Array?w0(this.code,t):t.then(i=>w0(this.code,i))}else throw Error("Unknown type, must be binary type")}}const Y2=r=>async e=>new Uint8Array(await crypto.subtle.digest(r,e)),AR=J2({name:"sha2-256",code:18,encode:Y2("SHA-256")}),ER=J2({name:"sha2-512",code:19,encode:Y2("SHA-512")});var xR=Object.freeze({__proto__:null,sha256:AR,sha512:ER});const Q2=0,SR="identity",X2=H2,IR=r=>w0(Q2,X2(r)),MR={code:Q2,name:SR,encode:X2,digest:IR};var PR=Object.freeze({__proto__:null,identity:MR});new TextEncoder,new TextDecoder;const Jg={...wO,...AO,...xO,...IO,...OO,...UO,...jO,...KO,...YO,...rR};({...xR,...PR});function OR(r=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?globalThis.Buffer.allocUnsafe(r):new Uint8Array(r)}function Z2(r,e,t,i){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:i}}}const Yg=Z2("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),ql=Z2("ascii","a",r=>{let e="a";for(let t=0;t{r=r.substring(1);const e=OR(r.length);for(let t=0;t{if(!this.initialized){const i=await this.getKeyChain();typeof i<"u"&&(this.keychain=i),this.initialized=!0}},this.has=i=>(this.isInitialized(),this.keychain.has(i)),this.set=async(i,n)=>{this.isInitialized(),this.keychain.set(i,n),await this.persist()},this.get=i=>{this.isInitialized();const n=this.keychain.get(i);if(typeof n>"u"){const{message:a}=Ae("NO_MATCHING_KEY",`${this.name}: ${i}`);throw new Error(a)}return n},this.del=async i=>{this.isInitialized(),this.keychain.delete(i),await this.persist()},this.core=e,this.logger=Yr(t,this.name)}get context(){return di(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,Nb(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Cb(e):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}}class TR{constructor(e,t,i){this.core=e,this.logger=t,this.name=OP,this.randomSessionIdentifier=u0(),this.initialized=!1,this.init=async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)},this.hasKeys=n=>(this.isInitialized(),this.keychain.has(n)),this.getClientId=async()=>{this.isInitialized();const n=await this.getClientSeed(),a=C1(n);return Mb(a.publicKey)},this.generateKeyPair=()=>{this.isInitialized();const n=vS();return this.setPrivateKey(n.publicKey,n.privateKey)},this.signJWT=async n=>{this.isInitialized();const a=await this.getClientSeed(),f=C1(a),u=this.randomSessionIdentifier;return await Q9(u,n,RP,f)},this.generateSharedKey=(n,a,f)=>{this.isInitialized();const u=this.getPrivateKey(n),b=bS(u,a);return this.setSymKey(b,f)},this.setSymKey=async(n,a)=>{this.isInitialized();const f=a||rh(n);return await this.keychain.set(f,n),f},this.deleteKeyPair=async n=>{this.isInitialized(),await this.keychain.del(n)},this.deleteSymKey=async n=>{this.isInitialized(),await this.keychain.del(n)},this.encode=async(n,a,f)=>{this.isInitialized();const u=E2(f),b=vs(a);if(gg(u))return yS(b,f==null?void 0:f.encoding);if(pg(u)){const R=u.senderPublicKey,O=u.receiverPublicKey;n=await this.generateSharedKey(R,O)}const p=this.getSymKey(n),{type:y,senderPublicKey:A}=u;return mS({type:y,symKey:p,message:b,senderPublicKey:A,encoding:f==null?void 0:f.encoding})},this.decode=async(n,a,f)=>{this.isInitialized();const u=AS(a,f);if(gg(u)){const b=_S(a,f==null?void 0:f.encoding);return ga(b)}if(pg(u)){const b=u.receiverPublicKey,p=u.senderPublicKey;n=await this.generateSharedKey(b,p)}try{const b=this.getSymKey(n),p=wS({symKey:b,encoded:a,encoding:f==null?void 0:f.encoding});return ga(p)}catch(b){this.logger.error(`Failed to decode message from topic: '${n}', clientId: '${await this.getClientId()}'`),this.logger.error(b)}},this.getPayloadType=(n,a=Bs)=>{const f=vc({encoded:n,encoding:a});return ba(f.type)},this.getPayloadSenderPublicKey=(n,a=Bs)=>{const f=vc({encoded:n,encoding:a});return f.senderPublicKey?Er(f.senderPublicKey,Jr):void 0},this.core=e,this.logger=Yr(t,this.name),this.keychain=i||new CR(this.core,this.logger)}get context(){return di(this.logger)}async setPrivateKey(e,t){return await this.keychain.set(e,t),e}getPrivateKey(e){return this.keychain.get(e)}async getClientSeed(){let e="";try{e=this.keychain.get(kg)}catch{e=u0(),await this.keychain.set(kg,e)}return NR(e,"base16")}getSymKey(e){return this.keychain.get(e)}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}}class DR extends IM{constructor(e,t){super(e,t),this.logger=e,this.core=t,this.messages=new Map,this.name=TP,this.version=DP,this.initialized=!1,this.storagePrefix=kn,this.init=async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const i=await this.getRelayerMessages();typeof i<"u"&&(this.messages=i),this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",size:this.messages.size})}catch(i){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(i)}finally{this.initialized=!0}}},this.set=async(i,n)=>{this.isInitialized();const a=fs(n);let f=this.messages.get(i);return typeof f>"u"&&(f={}),typeof f[a]<"u"||(f[a]=n,this.messages.set(i,f),await this.persist()),a},this.get=i=>{this.isInitialized();let n=this.messages.get(i);return typeof n>"u"&&(n={}),n},this.has=(i,n)=>{this.isInitialized();const a=this.get(i),f=fs(n);return typeof a[f]<"u"},this.del=async i=>{this.isInitialized(),this.messages.delete(i),await this.persist()},this.logger=Yr(e,this.name),this.core=t}get context(){return di(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setRelayerMessages(e){await this.core.storage.setItem(this.storageKey,Nb(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Cb(e):void 0}async persist(){await this.setRelayerMessages(this.messages)}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}}class FR extends MM{constructor(e,t){super(e,t),this.relayer=e,this.logger=t,this.events=new Hi.EventEmitter,this.name=BP,this.queue=new Map,this.publishTimeout=xe.toMiliseconds(xe.ONE_MINUTE),this.failedPublishTimeout=xe.toMiliseconds(xe.ONE_SECOND),this.needsTransportRestart=!1,this.publish=async(i,n,a)=>{var f;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:i,message:n,opts:a}});const u=(a==null?void 0:a.ttl)||FP,b=l0(a),p=(a==null?void 0:a.prompt)||!1,y=(a==null?void 0:a.tag)||0,A=(a==null?void 0:a.id)||ha().toString(),R={topic:i,message:n,opts:{ttl:u,relay:b,prompt:p,tag:y,id:A,attestation:a==null?void 0:a.attestation}},O=`Failed to publish payload, please try again. id:${A} tag:${y}`,N=Date.now();let K,W=1;try{for(;K===void 0;){if(Date.now()-N>this.publishTimeout)throw new Error(O);this.logger.trace({id:A,attempts:W},`publisher.publish - attempt ${W}`),K=await await Za(this.rpcPublish(i,n,u,b,p,y,A,a==null?void 0:a.attestation).catch(Q=>this.logger.warn(Q)),this.publishTimeout,O),W++,K||await new Promise(Q=>setTimeout(Q,this.failedPublishTimeout))}this.relayer.events.emit(Gr.publish,R),this.logger.debug("Successfully Published Payload"),this.logger.trace({type:"method",method:"publish",params:{id:A,topic:i,message:n,opts:a}})}catch(Q){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(Q),(f=a==null?void 0:a.internal)!=null&&f.throwOnFailedPublish)throw Q;this.queue.set(A,R)}},this.on=(i,n)=>{this.events.on(i,n)},this.once=(i,n)=>{this.events.once(i,n)},this.off=(i,n)=>{this.events.off(i,n)},this.removeListener=(i,n)=>{this.events.removeListener(i,n)},this.relayer=e,this.logger=Yr(t,this.name),this.registerEventListeners()}get context(){return di(this.logger)}rpcPublish(e,t,i,n,a,f,u,b){var p,y,A,R;const O={method:nc(n.protocol).publish,params:{topic:e,message:t,ttl:i,prompt:a,tag:f,attestation:b},id:u};return fi((p=O.params)==null?void 0:p.prompt)&&((y=O.params)==null||delete y.prompt),fi((A=O.params)==null?void 0:A.tag)&&((R=O.params)==null||delete R.tag),this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:O}),this.relayer.request(O)}removeRequestFromQueue(e){this.queue.delete(e)}checkQueue(){this.queue.forEach(async e=>{const{topic:t,message:i,opts:n}=e;await this.publish(t,i,n)})}registerEventListeners(){this.relayer.core.heartbeat.on(Ao.pulse,()=>{if(this.needsTransportRestart){this.needsTransportRestart=!1,this.relayer.events.emit(Gr.connection_stalled);return}this.checkQueue()}),this.relayer.on(Gr.message_ack,e=>{this.removeRequestFromQueue(e.id.toString())})}}class BR{constructor(){this.map=new Map,this.set=(e,t)=>{const i=this.get(e);this.exists(e,t)||this.map.set(e,[...i,t])},this.get=e=>this.map.get(e)||[],this.exists=(e,t)=>this.get(e).includes(t),this.delete=(e,t)=>{if(typeof t>"u"){this.map.delete(e);return}if(!this.map.has(e))return;const i=this.get(e);if(!this.exists(e,t))return;const n=i.filter(a=>a!==t);if(!n.length){this.map.delete(e);return}this.map.set(e,n)},this.clear=()=>{this.map.clear()}}get topics(){return Array.from(this.map.keys())}}var qR=Object.defineProperty,LR=Object.defineProperties,UR=Object.getOwnPropertyDescriptors,Qg=Object.getOwnPropertySymbols,$R=Object.prototype.hasOwnProperty,zR=Object.prototype.propertyIsEnumerable,Xg=(r,e,t)=>e in r?qR(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ec=(r,e)=>{for(var t in e||(e={}))$R.call(e,t)&&Xg(r,t,e[t]);if(Qg)for(var t of Qg(e))zR.call(e,t)&&Xg(r,t,e[t]);return r},Ll=(r,e)=>LR(r,UR(e));class jR extends RM{constructor(e,t){super(e,t),this.relayer=e,this.logger=t,this.subscriptions=new Map,this.topicMap=new BR,this.events=new Hi.EventEmitter,this.name=kP,this.version=HP,this.pending=new Map,this.cached=[],this.initialized=!1,this.pendingSubscriptionWatchLabel="pending_sub_watch_label",this.pollingInterval=20,this.storagePrefix=kn,this.subscribeTimeout=xe.toMiliseconds(xe.ONE_MINUTE),this.restartInProgress=!1,this.batchSubscribeTopicsLimit=500,this.pendingBatchMessages=[],this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),this.clientId=await this.relayer.core.crypto.getClientId(),await this.restore()),this.initialized=!0},this.subscribe=async(i,n)=>{this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:i,opts:n}});try{const a=l0(n),f={topic:i,relay:a,transportType:n==null?void 0:n.transportType};this.pending.set(i,f);const u=await this.rpcSubscribe(i,a,n==null?void 0:n.transportType);return typeof u=="string"&&(this.onSubscribe(u,f),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:i,opts:n}})),u}catch(a){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(a),a}},this.unsubscribe=async(i,n)=>{await this.restartToComplete(),this.isInitialized(),typeof(n==null?void 0:n.id)<"u"?await this.unsubscribeById(i,n.id,n):await this.unsubscribeByTopic(i,n)},this.isSubscribed=async i=>{if(this.topics.includes(i))return!0;const n=`${this.pendingSubscriptionWatchLabel}_${i}`;return await new Promise((a,f)=>{const u=new xe.Watch;u.start(n);const b=setInterval(()=>{!this.pending.has(i)&&this.topics.includes(i)&&(clearInterval(b),u.stop(n),a(!0)),u.elapsed(n)>=KP&&(clearInterval(b),u.stop(n),f(new Error("Subscription resolution timeout")))},this.pollingInterval)}).catch(()=>!1)},this.on=(i,n)=>{this.events.on(i,n)},this.once=(i,n)=>{this.events.once(i,n)},this.off=(i,n)=>{this.events.off(i,n)},this.removeListener=(i,n)=>{this.events.removeListener(i,n)},this.start=async()=>{await this.onConnect()},this.stop=async()=>{await this.onDisconnect()},this.restart=async()=>{this.restartInProgress=!0,await this.restore(),await this.reset(),this.restartInProgress=!1},this.relayer=e,this.logger=Yr(t,this.name),this.clientId=""}get context(){return di(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(e,t){let i=!1;try{i=this.getSubscription(e).topic===t}catch{}return i}onEnable(){this.cached=[],this.initialized=!0}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(e,t){const i=this.topicMap.get(e);await Promise.all(i.map(async n=>await this.unsubscribeById(e,n,t)))}async unsubscribeById(e,t,i){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:t,opts:i}});try{const n=l0(i);await this.rpcUnsubscribe(e,t,n);const a=Ut("USER_DISCONNECTED",`${this.name}, ${e}`);await this.onUnsubscribe(e,t,a),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:t,opts:i}})}catch(n){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(n),n}}async rpcSubscribe(e,t,i=Kt.relay){i===Kt.relay&&await this.restartToComplete();const n={method:nc(t.protocol).subscribe,params:{topic:e}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});try{const a=fs(e+this.clientId);return i===Kt.link_mode?(setTimeout(()=>{(this.relayer.connected||this.relayer.connecting)&&this.relayer.request(n).catch(f=>this.logger.warn(f))},xe.toMiliseconds(xe.ONE_SECOND)),a):await await Za(this.relayer.request(n).catch(f=>this.logger.warn(f)),this.subscribeTimeout)?a:null}catch{this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(Gr.connection_stalled)}return null}async rpcBatchSubscribe(e){if(!e.length)return;const t=e[0].relay,i={method:nc(t.protocol).batchSubscribe,params:{topics:e.map(n=>n.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i});try{return await await Za(this.relayer.request(i).catch(n=>this.logger.warn(n)),this.subscribeTimeout)}catch{this.relayer.events.emit(Gr.connection_stalled)}}async rpcBatchFetchMessages(e){if(!e.length)return;const t=e[0].relay,i={method:nc(t.protocol).batchFetchMessages,params:{topics:e.map(a=>a.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i});let n;try{n=await await Za(this.relayer.request(i).catch(a=>this.logger.warn(a)),this.subscribeTimeout)}catch{this.relayer.events.emit(Gr.connection_stalled)}return n}rpcUnsubscribe(e,t,i){const n={method:nc(i.protocol).unsubscribe,params:{topic:e,id:t}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n}),this.relayer.request(n)}onSubscribe(e,t){this.setSubscription(e,Ll(ec({},t),{id:e})),this.pending.delete(t.topic)}onBatchSubscribe(e){e.length&&e.forEach(t=>{this.setSubscription(t.id,ec({},t)),this.pending.delete(t.topic)})}async onUnsubscribe(e,t,i){this.events.removeAllListeners(t),this.hasSubscription(t,e)&&this.deleteSubscription(t,i),await this.relayer.messages.del(e)}async setRelayerSubscriptions(e){await this.relayer.core.storage.setItem(this.storageKey,e)}async getRelayerSubscriptions(){return await this.relayer.core.storage.getItem(this.storageKey)}setSubscription(e,t){this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:t}),this.addSubscription(e,t)}addSubscription(e,t){this.subscriptions.set(e,ec({},t)),this.topicMap.set(t.topic,e),this.events.emit(Pn.created,t)}getSubscription(e){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const t=this.subscriptions.get(e);if(!t){const{message:i}=Ae("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(i)}return t}deleteSubscription(e,t){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:t});const i=this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(i.topic,e),this.events.emit(Pn.deleted,Ll(ec({},i),{reason:t}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit(Pn.sync)}async reset(){if(this.cached.length){const e=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let t=0;t"u"||!e.length)return;if(this.subscriptions.size){const{message:t}=Ae("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(t)}this.cached=e,this.logger.debug(`Successfully Restored subscriptions for ${this.name}`),this.logger.trace({type:"method",method:"restore",subscriptions:this.values})}catch(e){this.logger.debug(`Failed to Restore subscriptions for ${this.name}`),this.logger.error(e)}}async batchSubscribe(e){if(!e.length)return;const t=await this.rpcBatchSubscribe(e);jn(t)&&this.onBatchSubscribe(t.map((i,n)=>Ll(ec({},e[n]),{id:i})))}async batchFetchMessages(e){if(!e.length)return;this.logger.trace(`Fetching batch messages for ${e.length} subscriptions`);const t=await this.rpcBatchFetchMessages(e);t&&t.messages&&(this.pendingBatchMessages=this.pendingBatchMessages.concat(t.messages))}async onConnect(){await this.restart(),this.onEnable()}onDisconnect(){this.onDisable()}async checkPending(){if(!this.initialized||!this.relayer.connected)return;const e=[];this.pending.forEach(t=>{e.push(t)}),await this.batchSubscribe(e),this.pendingBatchMessages.length&&(await this.relayer.handleBatchMessageEvents(this.pendingBatchMessages),this.pendingBatchMessages=[])}registerEventListeners(){this.relayer.core.heartbeat.on(Ao.pulse,async()=>{await this.checkPending()}),this.events.on(Pn.created,async e=>{const t=Pn.created;this.logger.info(`Emitting ${t}`),this.logger.debug({type:"event",event:t,data:e}),await this.persist()}),this.events.on(Pn.deleted,async e=>{const t=Pn.deleted;this.logger.info(`Emitting ${t}`),this.logger.debug({type:"event",event:t,data:e}),await this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}async restartToComplete(){!this.relayer.connected&&!this.relayer.connecting&&await this.relayer.transportOpen(),this.restartInProgress&&await new Promise(e=>{const t=setInterval(()=>{this.restartInProgress||(clearInterval(t),e())},this.pollingInterval)})}}var kR=Object.defineProperty,Zg=Object.getOwnPropertySymbols,HR=Object.prototype.hasOwnProperty,KR=Object.prototype.propertyIsEnumerable,ev=(r,e,t)=>e in r?kR(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,VR=(r,e)=>{for(var t in e||(e={}))HR.call(e,t)&&ev(r,t,e[t]);if(Zg)for(var t of Zg(e))KR.call(e,t)&&ev(r,t,e[t]);return r};class GR extends PM{constructor(e){super(e),this.protocol="wc",this.version=2,this.events=new Hi.EventEmitter,this.name=LP,this.transportExplicitlyClosed=!1,this.initialized=!1,this.connectionAttemptInProgress=!1,this.connectionStatusPollingInterval=20,this.staleConnectionErrors=["socket hang up","stalled","interrupted"],this.hasExperiencedNetworkDisruption=!1,this.requestsInFlight=new Map,this.heartBeatTimeout=xe.toMiliseconds(xe.THIRTY_SECONDS+xe.ONE_SECOND),this.request=async t=>{var i,n;this.logger.debug("Publishing Request Payload");const a=t.id||ha().toString();await this.toEstablishConnection();try{const f=this.provider.request(t);this.requestsInFlight.set(a,{promise:f,request:t}),this.logger.trace({id:a,method:t.method,topic:(i=t.params)==null?void 0:i.topic},"relayer.request - attempt to publish...");const u=await new Promise(async(b,p)=>{const y=()=>{p(new Error(`relayer.request - publish interrupted, id: ${a}`))};this.provider.on(qi.disconnect,y);const A=await f;this.provider.off(qi.disconnect,y),b(A)});return this.logger.trace({id:a,method:t.method,topic:(n=t.params)==null?void 0:n.topic},"relayer.request - published"),u}catch(f){throw this.logger.debug(`Failed to Publish Request: ${a}`),f}finally{this.requestsInFlight.delete(a)}},this.resetPingTimeout=()=>{if(dh())try{clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{var t,i,n;(n=(i=(t=this.provider)==null?void 0:t.connection)==null?void 0:i.socket)==null||n.terminate()},this.heartBeatTimeout)}catch(t){this.logger.warn(t)}},this.onPayloadHandler=t=>{this.onProviderPayload(t),this.resetPingTimeout()},this.onConnectHandler=()=>{this.logger.trace("relayer connected"),this.startPingTimeout(),this.events.emit(Gr.connect)},this.onDisconnectHandler=()=>{this.logger.trace("relayer disconnected"),this.onProviderDisconnect()},this.onProviderErrorHandler=t=>{this.logger.error(t),this.events.emit(Gr.error,t),this.logger.info("Fatal socket error received, closing transport"),this.transportClose()},this.registerProviderListeners=()=>{this.provider.on(qi.payload,this.onPayloadHandler),this.provider.on(qi.connect,this.onConnectHandler),this.provider.on(qi.disconnect,this.onDisconnectHandler),this.provider.on(qi.error,this.onProviderErrorHandler)},this.core=e.core,this.logger=typeof e.logger<"u"&&typeof e.logger!="string"?Yr(e.logger,this.name):Nc(Hh({level:e.logger||qP})),this.messages=new DR(this.logger,e.core),this.subscriber=new jR(this,this.logger),this.publisher=new FR(this,this.logger),this.relayUrl=(e==null?void 0:e.relayUrl)||j2,this.projectId=e.projectId,this.bundleId=aA(),this.provider={}}async init(){if(this.logger.trace("Initialized"),this.registerEventListeners(),await Promise.all([this.messages.init(),this.subscriber.init()]),this.initialized=!0,this.subscriber.cached.length>0)try{await this.transportOpen()}catch(e){this.logger.warn(e)}}get context(){return di(this.logger)}get connected(){var e,t,i;return((i=(t=(e=this.provider)==null?void 0:e.connection)==null?void 0:t.socket)==null?void 0:i.readyState)===1}get connecting(){var e,t,i;return((i=(t=(e=this.provider)==null?void 0:e.connection)==null?void 0:t.socket)==null?void 0:i.readyState)===0}async publish(e,t,i){this.isInitialized(),await this.publisher.publish(e,t,i),await this.recordMessageEvent({topic:e,message:t,publishedAt:Date.now(),transportType:Kt.relay})}async subscribe(e,t){var i;this.isInitialized(),(t==null?void 0:t.transportType)==="relay"&&await this.toEstablishConnection();let n=((i=this.subscriber.topicMap.get(e))==null?void 0:i[0])||"",a;const f=u=>{u.topic===e&&(this.subscriber.off(Pn.created,f),a())};return await Promise.all([new Promise(u=>{a=u,this.subscriber.on(Pn.created,f)}),new Promise(async u=>{n=await this.subscriber.subscribe(e,t)||n,u()})]),n}async unsubscribe(e,t){this.isInitialized(),await this.subscriber.unsubscribe(e,t)}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async transportDisconnect(){if(!this.hasExperiencedNetworkDisruption&&this.connected&&this.requestsInFlight.size>0)try{await Promise.all(Array.from(this.requestsInFlight.values()).map(e=>e.promise))}catch(e){this.logger.warn(e)}this.hasExperiencedNetworkDisruption||this.connected?await Za(this.provider.disconnect(),2e3,"provider.disconnect()").catch(()=>this.onProviderDisconnect()):this.onProviderDisconnect()}async transportClose(){this.transportExplicitlyClosed=!0,await this.transportDisconnect()}async transportOpen(e){await this.confirmOnlineStateOrThrow(),e&&e!==this.relayUrl&&(this.relayUrl=e,await this.transportDisconnect()),await this.createProvider(),this.connectionAttemptInProgress=!0,this.transportExplicitlyClosed=!1;try{await new Promise(async(t,i)=>{const n=()=>{this.provider.off(qi.disconnect,n),i(new Error("Connection interrupted while trying to subscribe"))};this.provider.on(qi.disconnect,n),await Za(this.provider.connect(),xe.toMiliseconds(xe.ONE_MINUTE),`Socket stalled when trying to connect to ${this.relayUrl}`).catch(a=>{i(a)}).finally(()=>{clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0}),this.subscriber.start().catch(a=>{this.logger.error(a),this.onDisconnectHandler()}),this.hasExperiencedNetworkDisruption=!1,t()})}catch(t){this.logger.error(t);const i=t;if(this.hasExperiencedNetworkDisruption=!0,!this.isConnectionStalled(i.message))throw t}finally{this.connectionAttemptInProgress=!1}}async restartTransport(e){this.connectionAttemptInProgress||(this.relayUrl=e||this.relayUrl,await this.confirmOnlineStateOrThrow(),await this.transportClose(),await this.transportOpen())}async confirmOnlineStateOrThrow(){if(!await Ig())throw new Error("No internet connection detected. Please restart your network and try again.")}async handleBatchMessageEvents(e){if((e==null?void 0:e.length)===0){this.logger.trace("Batch message events is empty. Ignoring...");return}const t=e.sort((i,n)=>i.publishedAt-n.publishedAt);this.logger.trace(`Batch of ${t.length} message events sorted`);for(const i of t)try{await this.onMessageEvent(i)}catch(n){this.logger.warn(n)}this.logger.trace(`Batch of ${t.length} message events processed`)}async onLinkMessageEvent(e,t){const{topic:i}=e;if(!t.sessionExists){const n=vr(xe.FIVE_MINUTES),a={topic:i,expiry:n,relay:{protocol:"irn"},active:!1};await this.core.pairing.pairings.set(i,a)}this.events.emit(Gr.message,e),await this.recordMessageEvent(e)}startPingTimeout(){var e,t,i,n,a;if(dh())try{(t=(e=this.provider)==null?void 0:e.connection)!=null&&t.socket&&((a=(n=(i=this.provider)==null?void 0:i.connection)==null?void 0:n.socket)==null||a.once("ping",()=>{this.resetPingTimeout()})),this.resetPingTimeout()}catch(f){this.logger.warn(f)}}isConnectionStalled(e){return this.staleConnectionErrors.some(t=>e.includes(t))}async createProvider(){this.provider.connection&&this.unregisterProviderListeners();const e=await this.core.crypto.signJWT(this.relayUrl);this.provider=new gn(new xP(hA({sdkVersion:m0,protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:e,useOnCloseEvent:!0,bundleId:this.bundleId}))),this.registerProviderListeners()}async recordMessageEvent(e){const{topic:t,message:i}=e;await this.messages.set(t,i)}async shouldIgnoreMessageEvent(e){const{topic:t,message:i}=e;if(!i||i.length===0)return this.logger.debug(`Ignoring invalid/empty message: ${i}`),!0;if(!await this.subscriber.isSubscribed(t))return this.logger.debug(`Ignoring message for non-subscribed topic ${t}`),!0;const n=this.messages.has(t,i);return n&&this.logger.debug(`Ignoring duplicate message: ${i}`),n}async onProviderPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),Z0(e)){if(!e.method.endsWith(UP))return;const t=e.params,{topic:i,message:n,publishedAt:a,attestation:f}=t.data,u={topic:i,message:n,publishedAt:a,transportType:Kt.relay,attestation:f};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(VR({type:"event",event:t.id},u)),this.events.emit(t.id,u),await this.acknowledgePayload(e),await this.onMessageEvent(u)}else Gh(e)&&this.events.emit(Gr.message_ack,e)}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(this.events.emit(Gr.message,e),await this.recordMessageEvent(e))}async acknowledgePayload(e){const t=Kh(e.id,!0);await this.provider.connection.send(t)}unregisterProviderListeners(){this.provider.off(qi.payload,this.onPayloadHandler),this.provider.off(qi.connect,this.onConnectHandler),this.provider.off(qi.disconnect,this.onDisconnectHandler),this.provider.off(qi.error,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let e=await Ig();gI(async t=>{e!==t&&(e=t,t?await this.restartTransport().catch(i=>this.logger.error(i)):(this.hasExperiencedNetworkDisruption=!0,await this.transportDisconnect(),this.transportExplicitlyClosed=!1))})}async onProviderDisconnect(){await this.subscriber.stop(),this.requestsInFlight.clear(),clearTimeout(this.pingTimeout),this.events.emit(Gr.disconnect),this.connectionAttemptInProgress=!1,!this.transportExplicitlyClosed&&(this.reconnectTimeout||(this.reconnectTimeout=setTimeout(async()=>{await this.transportOpen().catch(e=>this.logger.error(e))},xe.toMiliseconds($P))))}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}async toEstablishConnection(){await this.confirmOnlineStateOrThrow(),!this.connected&&(this.connectionAttemptInProgress&&await new Promise(e=>{const t=setInterval(()=>{this.connected&&(clearInterval(t),e())},this.connectionStatusPollingInterval)}),await this.transportOpen())}}var WR=Object.defineProperty,tv=Object.getOwnPropertySymbols,JR=Object.prototype.hasOwnProperty,YR=Object.prototype.propertyIsEnumerable,rv=(r,e,t)=>e in r?WR(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,iv=(r,e)=>{for(var t in e||(e={}))JR.call(e,t)&&rv(r,t,e[t]);if(tv)for(var t of tv(e))YR.call(e,t)&&rv(r,t,e[t]);return r};class xa extends OM{constructor(e,t,i,n=kn,a=void 0){super(e,t,i,n),this.core=e,this.logger=t,this.name=i,this.map=new Map,this.version=zP,this.cached=[],this.initialized=!1,this.storagePrefix=kn,this.recentlyDeleted=[],this.recentlyDeletedLimit=200,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(f=>{this.getKey&&f!==null&&!fi(f)?this.map.set(this.getKey(f),f):VS(f)?this.map.set(f.id,f):GS(f)&&this.map.set(f.topic,f)}),this.cached=[],this.initialized=!0)},this.set=async(f,u)=>{this.isInitialized(),this.map.has(f)?await this.update(f,u):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:f,value:u}),this.map.set(f,u),await this.persist())},this.get=f=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:f}),this.getData(f)),this.getAll=f=>(this.isInitialized(),f?this.values.filter(u=>Object.keys(f).every(b=>IP(u[b],f[b]))):this.values),this.update=async(f,u)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:f,update:u});const b=iv(iv({},this.getData(f)),u);this.map.set(f,b),await this.persist()},this.delete=async(f,u)=>{this.isInitialized(),this.map.has(f)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:f,reason:u}),this.map.delete(f),this.addToRecentlyDeleted(f),await this.persist())},this.logger=Yr(t,this.name),this.storagePrefix=n,this.getKey=a}get context(){return di(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())}addToRecentlyDeleted(e){this.recentlyDeleted.push(e),this.recentlyDeleted.length>=this.recentlyDeletedLimit&&this.recentlyDeleted.splice(0,this.recentlyDeletedLimit/2)}async setDataStore(e){await this.core.storage.setItem(this.storageKey,e)}async getDataStore(){return await this.core.storage.getItem(this.storageKey)}getData(e){const t=this.map.get(e);if(!t){if(this.recentlyDeleted.includes(e)){const{message:n}=Ae("MISSING_OR_INVALID",`Record was recently deleted - ${this.name}: ${e}`);throw this.logger.error(n),new Error(n)}const{message:i}=Ae("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(i),new Error(i)}return t}async persist(){await this.setDataStore(this.values)}async restore(){try{const e=await this.getDataStore();if(typeof e>"u"||!e.length)return;if(this.map.size){const{message:t}=Ae("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=e,this.logger.debug(`Successfully Restored value for ${this.name}`),this.logger.trace({type:"method",method:"restore",value:this.values})}catch(e){this.logger.debug(`Failed to Restore value for ${this.name}`),this.logger.error(e)}}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}}class QR{constructor(e,t){this.core=e,this.logger=t,this.name=VP,this.version=GP,this.events=new I0,this.initialized=!1,this.storagePrefix=kn,this.ignoredPayloadTypes=[ds],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:i})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...i])]},this.create=async i=>{this.isInitialized();const n=u0(),a=await this.core.crypto.setSymKey(n),f=vr(xe.FIVE_MINUTES),u={protocol:z2},b={topic:a,expiry:f,relay:u,active:!1,methods:i==null?void 0:i.methods},p=wg({protocol:this.core.protocol,version:this.core.version,topic:a,symKey:n,relay:u,expiryTimestamp:f,methods:i==null?void 0:i.methods});return this.events.emit(ca.create,b),this.core.expirer.set(a,f),await this.pairings.set(a,b),await this.core.relayer.subscribe(a,{transportType:i==null?void 0:i.transportType}),{topic:a,uri:p}},this.pair=async i=>{this.isInitialized();const n=this.core.eventClient.createEvent({properties:{topic:i==null?void 0:i.uri,trace:[xn.pairing_started]}});this.isValidPair(i,n);const{topic:a,symKey:f,relay:u,expiryTimestamp:b,methods:p}=yg(i.uri);n.props.properties.topic=a,n.addTrace(xn.pairing_uri_validation_success),n.addTrace(xn.pairing_uri_not_expired);let y;if(this.pairings.keys.includes(a)){if(y=this.pairings.get(a),n.addTrace(xn.existing_pairing),y.active)throw n.setError(os.active_pairing_already_exists),new Error(`Pairing already exists: ${a}. Please try again with a new connection URI.`);n.addTrace(xn.pairing_not_expired)}const A=b||vr(xe.FIVE_MINUTES),R={topic:a,relay:u,expiry:A,active:!1,methods:p};this.core.expirer.set(a,A),await this.pairings.set(a,R),n.addTrace(xn.store_new_pairing),i.activatePairing&&await this.activate({topic:a}),this.events.emit(ca.create,R),n.addTrace(xn.emit_inactive_pairing),this.core.crypto.keychain.has(a)||await this.core.crypto.setSymKey(f,a),n.addTrace(xn.subscribing_pairing_topic);try{await this.core.relayer.confirmOnlineStateOrThrow()}catch{n.setError(os.no_internet_connection)}try{await this.core.relayer.subscribe(a,{relay:u})}catch(O){throw n.setError(os.subscribe_pairing_topic_failure),O}return n.addTrace(xn.subscribe_pairing_topic_success),R},this.activate=async({topic:i})=>{this.isInitialized();const n=vr(xe.THIRTY_DAYS);this.core.expirer.set(i,n),await this.pairings.update(i,{active:!0,expiry:n})},this.ping=async i=>{this.isInitialized(),await this.isValidPing(i);const{topic:n}=i;if(this.pairings.keys.includes(n)){const a=await this.sendRequest(n,"wc_pairingPing",{}),{done:f,resolve:u,reject:b}=oa();this.events.once(St("pairing_ping",a),({error:p})=>{p?b(p):u()}),await f()}},this.updateExpiry=async({topic:i,expiry:n})=>{this.isInitialized(),await this.pairings.update(i,{expiry:n})},this.updateMetadata=async({topic:i,metadata:n})=>{this.isInitialized(),await this.pairings.update(i,{peerMetadata:n})},this.getPairings=()=>(this.isInitialized(),this.pairings.values),this.disconnect=async i=>{this.isInitialized(),await this.isValidDisconnect(i);const{topic:n}=i;this.pairings.keys.includes(n)&&(await this.sendRequest(n,"wc_pairingDelete",Ut("USER_DISCONNECTED")),await this.deletePairing(n))},this.formatUriFromPairing=i=>{this.isInitialized();const{topic:n,relay:a,expiry:f,methods:u}=i,b=this.core.crypto.keychain.get(n);return wg({protocol:this.core.protocol,version:this.core.version,topic:n,symKey:b,relay:a,expiryTimestamp:f,methods:u})},this.sendRequest=async(i,n,a)=>{const f=qs(n,a),u=await this.core.crypto.encode(i,f),b=Xo[n].req;return this.core.history.set(i,f),this.core.relayer.publish(i,u,b),f.id},this.sendResult=async(i,n,a)=>{const f=Kh(i,a),u=await this.core.crypto.encode(n,f),b=await this.core.history.get(n,i),p=Xo[b.request.method].res;await this.core.relayer.publish(n,u,p),await this.core.history.resolve(f)},this.sendError=async(i,n,a)=>{const f=Vh(i,a),u=await this.core.crypto.encode(n,f),b=await this.core.history.get(n,i),p=Xo[b.request.method]?Xo[b.request.method].res:Xo.unregistered_method.res;await this.core.relayer.publish(n,u,p),await this.core.history.resolve(f)},this.deletePairing=async(i,n)=>{await this.core.relayer.unsubscribe(i),await Promise.all([this.pairings.delete(i,Ut("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(i),n?Promise.resolve():this.core.expirer.del(i)])},this.cleanup=async()=>{const i=this.pairings.getAll().filter(n=>Rs(n.expiry));await Promise.all(i.map(n=>this.deletePairing(n.topic)))},this.onRelayEventRequest=i=>{const{topic:n,payload:a}=i;switch(a.method){case"wc_pairingPing":return this.onPairingPingRequest(n,a);case"wc_pairingDelete":return this.onPairingDeleteRequest(n,a);default:return this.onUnknownRpcMethodRequest(n,a)}},this.onRelayEventResponse=async i=>{const{topic:n,payload:a}=i,f=(await this.core.history.get(n,a.id)).request.method;switch(f){case"wc_pairingPing":return this.onPairingPingResponse(n,a);default:return this.onUnknownRpcMethodResponse(f)}},this.onPairingPingRequest=async(i,n)=>{const{id:a}=n;try{this.isValidPing({topic:i}),await this.sendResult(a,i,!0),this.events.emit(ca.ping,{id:a,topic:i})}catch(f){await this.sendError(a,i,f),this.logger.error(f)}},this.onPairingPingResponse=(i,n)=>{const{id:a}=n;setTimeout(()=>{Mn(n)?this.events.emit(St("pairing_ping",a),{}):$i(n)&&this.events.emit(St("pairing_ping",a),{error:n.error})},500)},this.onPairingDeleteRequest=async(i,n)=>{const{id:a}=n;try{this.isValidDisconnect({topic:i}),await this.deletePairing(i),this.events.emit(ca.delete,{id:a,topic:i})}catch(f){await this.sendError(a,i,f),this.logger.error(f)}},this.onUnknownRpcMethodRequest=async(i,n)=>{const{id:a,method:f}=n;try{if(this.registeredMethods.includes(f))return;const u=Ut("WC_METHOD_UNSUPPORTED",f);await this.sendError(a,i,u),this.logger.error(u)}catch(u){await this.sendError(a,i,u),this.logger.error(u)}},this.onUnknownRpcMethodResponse=i=>{this.registeredMethods.includes(i)||this.logger.error(Ut("WC_METHOD_UNSUPPORTED",i))},this.isValidPair=(i,n)=>{var a;if(!oi(i)){const{message:u}=Ae("MISSING_OR_INVALID",`pair() params: ${i}`);throw n.setError(os.malformed_pairing_uri),new Error(u)}if(!KS(i.uri)){const{message:u}=Ae("MISSING_OR_INVALID",`pair() uri: ${i.uri}`);throw n.setError(os.malformed_pairing_uri),new Error(u)}const f=yg(i==null?void 0:i.uri);if(!((a=f==null?void 0:f.relay)!=null&&a.protocol)){const{message:u}=Ae("MISSING_OR_INVALID","pair() uri#relay-protocol");throw n.setError(os.malformed_pairing_uri),new Error(u)}if(!(f!=null&&f.symKey)){const{message:u}=Ae("MISSING_OR_INVALID","pair() uri#symKey");throw n.setError(os.malformed_pairing_uri),new Error(u)}if(f!=null&&f.expiryTimestamp&&xe.toMiliseconds(f==null?void 0:f.expiryTimestamp){if(!oi(i)){const{message:a}=Ae("MISSING_OR_INVALID",`ping() params: ${i}`);throw new Error(a)}const{topic:n}=i;await this.isValidPairingTopic(n)},this.isValidDisconnect=async i=>{if(!oi(i)){const{message:a}=Ae("MISSING_OR_INVALID",`disconnect() params: ${i}`);throw new Error(a)}const{topic:n}=i;await this.isValidPairingTopic(n)},this.isValidPairingTopic=async i=>{if(!fr(i,!1)){const{message:n}=Ae("MISSING_OR_INVALID",`pairing topic should be a string: ${i}`);throw new Error(n)}if(!this.pairings.keys.includes(i)){const{message:n}=Ae("NO_MATCHING_KEY",`pairing topic doesn't exist: ${i}`);throw new Error(n)}if(Rs(this.pairings.get(i).expiry)){await this.deletePairing(i);const{message:n}=Ae("EXPIRED",`pairing topic: ${i}`);throw new Error(n)}},this.core=e,this.logger=Yr(t,this.name),this.pairings=new xa(this.core,this.logger,this.name,this.storagePrefix)}get context(){return di(this.logger)}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(Gr.message,async e=>{const{topic:t,message:i,transportType:n}=e;if(!this.pairings.keys.includes(t)||n===Kt.link_mode||this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(i)))return;const a=await this.core.crypto.decode(t,i);try{Z0(a)?(this.core.history.set(t,a),this.onRelayEventRequest({topic:t,payload:a})):Gh(a)&&(await this.core.history.resolve(a),await this.onRelayEventResponse({topic:t,payload:a}),this.core.history.delete(t,a.id))}catch(f){this.logger.error(f)}})}registerExpirerEvents(){this.core.expirer.on(Li.expired,async e=>{const{topic:t}=Db(e.target);t&&this.pairings.keys.includes(t)&&(await this.deletePairing(t,!0),this.events.emit(ca.expire,{topic:t}))})}}class XR extends SM{constructor(e,t){super(e,t),this.core=e,this.logger=t,this.records=new Map,this.events=new Hi.EventEmitter,this.name=WP,this.version=JP,this.cached=[],this.initialized=!1,this.storagePrefix=kn,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(i=>this.records.set(i.id,i)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.set=(i,n,a)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:i,request:n,chainId:a}),this.records.has(n.id))return;const f={id:n.id,topic:i,request:{method:n.method,params:n.params||null},chainId:a,expiry:vr(xe.THIRTY_DAYS)};this.records.set(f.id,f),this.persist(),this.events.emit(on.created,f)},this.resolve=async i=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:i}),!this.records.has(i.id))return;const n=await this.getRecord(i.id);typeof n.response>"u"&&(n.response=$i(i)?{error:i.error}:{result:i.result},this.records.set(n.id,n),this.persist(),this.events.emit(on.updated,n))},this.get=async(i,n)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:i,id:n}),await this.getRecord(n)),this.delete=(i,n)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:n}),this.values.forEach(a=>{if(a.topic===i){if(typeof n<"u"&&a.id!==n)return;this.records.delete(a.id),this.events.emit(on.deleted,a)}}),this.persist()},this.exists=async(i,n)=>(this.isInitialized(),this.records.has(n)?(await this.getRecord(n)).topic===i:!1),this.on=(i,n)=>{this.events.on(i,n)},this.once=(i,n)=>{this.events.once(i,n)},this.off=(i,n)=>{this.events.off(i,n)},this.removeListener=(i,n)=>{this.events.removeListener(i,n)},this.logger=Yr(t,this.name)}get context(){return di(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 e=[];return this.values.forEach(t=>{if(typeof t.response<"u")return;const i={topic:t.topic,request:qs(t.request.method,t.request.params,t.id),chainId:t.chainId};return e.push(i)}),e}async setJsonRpcRecords(e){await this.core.storage.setItem(this.storageKey,e)}async getJsonRpcRecords(){return await this.core.storage.getItem(this.storageKey)}getRecord(e){this.isInitialized();const t=this.records.get(e);if(!t){const{message:i}=Ae("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(i)}return t}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(on.sync)}async restore(){try{const e=await this.getJsonRpcRecords();if(typeof e>"u"||!e.length)return;if(this.records.size){const{message:t}=Ae("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=e,this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",records:this.values})}catch(e){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(e)}}registerEventListeners(){this.events.on(on.created,e=>{const t=on.created;this.logger.info(`Emitting ${t}`),this.logger.debug({type:"event",event:t,record:e})}),this.events.on(on.updated,e=>{const t=on.updated;this.logger.info(`Emitting ${t}`),this.logger.debug({type:"event",event:t,record:e})}),this.events.on(on.deleted,e=>{const t=on.deleted;this.logger.info(`Emitting ${t}`),this.logger.debug({type:"event",event:t,record:e})}),this.core.heartbeat.on(Ao.pulse,()=>{this.cleanup()})}cleanup(){try{this.isInitialized();let e=!1;this.records.forEach(t=>{xe.toMiliseconds(t.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${t.id}`),this.records.delete(t.id),this.events.emit(on.deleted,t,!1),e=!0)}),e&&this.persist()}catch(e){this.logger.warn(e)}}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}}class ZR extends NM{constructor(e,t){super(e,t),this.core=e,this.logger=t,this.expirations=new Map,this.events=new Hi.EventEmitter,this.name=YP,this.version=QP,this.cached=[],this.initialized=!1,this.storagePrefix=kn,this.init=async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(i=>this.expirations.set(i.target,i)),this.cached=[],this.registerEventListeners(),this.initialized=!0)},this.has=i=>{try{const n=this.formatTarget(i);return typeof this.getExpiration(n)<"u"}catch{return!1}},this.set=(i,n)=>{this.isInitialized();const a=this.formatTarget(i),f={target:a,expiry:n};this.expirations.set(a,f),this.checkExpiry(a,f),this.events.emit(Li.created,{target:a,expiration:f})},this.get=i=>{this.isInitialized();const n=this.formatTarget(i);return this.getExpiration(n)},this.del=i=>{if(this.isInitialized(),this.has(i)){const n=this.formatTarget(i),a=this.getExpiration(n);this.expirations.delete(n),this.events.emit(Li.deleted,{target:n,expiration:a})}},this.on=(i,n)=>{this.events.on(i,n)},this.once=(i,n)=>{this.events.once(i,n)},this.off=(i,n)=>{this.events.off(i,n)},this.removeListener=(i,n)=>{this.events.removeListener(i,n)},this.logger=Yr(t,this.name)}get context(){return di(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(e){if(typeof e=="string")return uA(e);if(typeof e=="number")return lA(e);const{message:t}=Ae("UNKNOWN_TYPE",`Target type: ${typeof e}`);throw new Error(t)}async setExpirations(e){await this.core.storage.setItem(this.storageKey,e)}async getExpirations(){return await this.core.storage.getItem(this.storageKey)}async persist(){await this.setExpirations(this.values),this.events.emit(Li.sync)}async restore(){try{const e=await this.getExpirations();if(typeof e>"u"||!e.length)return;if(this.expirations.size){const{message:t}=Ae("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(t),new Error(t)}this.cached=e,this.logger.debug(`Successfully Restored expirations for ${this.name}`),this.logger.trace({type:"method",method:"restore",expirations:this.values})}catch(e){this.logger.debug(`Failed to Restore expirations for ${this.name}`),this.logger.error(e)}}getExpiration(e){const t=this.expirations.get(e);if(!t){const{message:i}=Ae("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.warn(i),new Error(i)}return t}checkExpiry(e,t){const{expiry:i}=t;xe.toMiliseconds(i)-Date.now()<=0&&this.expire(e,t)}expire(e,t){this.expirations.delete(e),this.events.emit(Li.expired,{target:e,expiration:t})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,t)=>this.checkExpiry(t,e))}registerEventListeners(){this.core.heartbeat.on(Ao.pulse,()=>this.checkExpirations()),this.events.on(Li.created,e=>{const t=Li.created;this.logger.info(`Emitting ${t}`),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(Li.expired,e=>{const t=Li.expired;this.logger.info(`Emitting ${t}`),this.logger.debug({type:"event",event:t,data:e}),this.persist()}),this.events.on(Li.deleted,e=>{const t=Li.deleted;this.logger.info(`Emitting ${t}`),this.logger.debug({type:"event",event:t,data:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}}var Qt={};Object.defineProperty(Qt,"__esModule",{value:!0}),Qt.getLocalStorage=Qt.getLocalStorageOrThrow=Qt.getCrypto=Qt.getCryptoOrThrow=Qt.getLocation=Qt.getLocationOrThrow=Qt.getNavigator=Qt.getNavigatorOrThrow=em=Qt.getDocument=Qt.getDocumentOrThrow=Qt.getFromWindowOrThrow=Qt.getFromWindow=void 0;function Sa(r){let e;return typeof window<"u"&&typeof window[r]<"u"&&(e=window[r]),e}Qt.getFromWindow=Sa;function Eo(r){const e=Sa(r);if(!e)throw new Error(`${r} is not defined in Window`);return e}Qt.getFromWindowOrThrow=Eo;function eN(){return Eo("document")}Qt.getDocumentOrThrow=eN;function tN(){return Sa("document")}var em=Qt.getDocument=tN;function rN(){return Eo("navigator")}Qt.getNavigatorOrThrow=rN;function iN(){return Sa("navigator")}Qt.getNavigator=iN;function nN(){return Eo("location")}Qt.getLocationOrThrow=nN;function sN(){return Sa("location")}Qt.getLocation=sN;function aN(){return Eo("crypto")}Qt.getCryptoOrThrow=aN;function oN(){return Sa("crypto")}Qt.getCrypto=oN;function cN(){return Eo("localStorage")}Qt.getLocalStorageOrThrow=cN;function fN(){return Sa("localStorage")}Qt.getLocalStorage=fN;class hN extends CM{constructor(e,t,i){super(e,t,i),this.core=e,this.logger=t,this.store=i,this.name=XP,this.verifyUrlV3=eO,this.storagePrefix=kn,this.version=$2,this.init=async()=>{var n;this.isDevEnv||(this.publicKey=await this.store.getItem(this.storeKey),this.publicKey&&xe.toMiliseconds((n=this.publicKey)==null?void 0:n.expiresAt){if(!Sc()||this.isDevEnv)return;const a=window.location.origin,{id:f,decryptedId:u}=n,b=`${this.verifyUrlV3}/attestation?projectId=${this.core.projectId}&origin=${a}&id=${f}&decryptedId=${u}`;try{const p=em(),y=this.startAbortTimer(xe.ONE_SECOND*5),A=await new Promise((R,O)=>{const N=()=>{window.removeEventListener("message",W),p.body.removeChild(K),O("attestation aborted")};this.abortController.signal.addEventListener("abort",N);const K=p.createElement("iframe");K.src=b,K.style.display="none",K.addEventListener("error",N,{signal:this.abortController.signal});const W=Q=>{if(Q.data&&typeof Q.data=="string")try{const j=JSON.parse(Q.data);if(j.type==="verify_attestation"){if(n0(j.attestation).payload.id!==f)return;clearInterval(y),p.body.removeChild(K),this.abortController.signal.removeEventListener("abort",N),window.removeEventListener("message",W),R(j.attestation===null?"":j.attestation)}}catch(j){this.logger.warn(j)}};p.body.appendChild(K),window.addEventListener("message",W,{signal:this.abortController.signal})});return this.logger.debug("jwt attestation",A),A}catch(p){this.logger.warn(p)}return""},this.resolve=async n=>{if(this.isDevEnv)return"";const{attestationId:a,hash:f,encryptedId:u}=n;if(a===""){this.logger.debug("resolve: attestationId is empty, skipping");return}if(a){if(n0(a).payload.id!==u)return;const p=await this.isValidJwtAttestation(a);if(p){if(!p.isVerified){this.logger.warn("resolve: jwt attestation: origin url not verified");return}return p}}if(!f)return;const b=this.getVerifyUrl(n==null?void 0:n.verifyUrl);return this.fetchAttestation(f,b)},this.fetchAttestation=async(n,a)=>{this.logger.debug(`resolving attestation: ${n} from url: ${a}`);const f=this.startAbortTimer(xe.ONE_SECOND*5),u=await fetch(`${a}/attestation/${n}?v2Supported=true`,{signal:this.abortController.signal});return clearTimeout(f),u.status===200?await u.json():void 0},this.getVerifyUrl=n=>{let a=n||uc;return tO.includes(a)||(this.logger.info(`verify url: ${a}, not included in trusted list, assigning default: ${uc}`),a=uc),a},this.fetchPublicKey=async()=>{try{this.logger.debug(`fetching public key from: ${this.verifyUrlV3}`);const n=this.startAbortTimer(xe.FIVE_SECONDS),a=await fetch(`${this.verifyUrlV3}/public-key`,{signal:this.abortController.signal});return clearTimeout(n),await a.json()}catch(n){this.logger.warn(n)}},this.persistPublicKey=async n=>{this.logger.debug("persisting public key to local storage",n),await this.store.setItem(this.storeKey,n),this.publicKey=n},this.removePublicKey=async()=>{this.logger.debug("removing verify v2 public key from storage"),await this.store.removeItem(this.storeKey),this.publicKey=void 0},this.isValidJwtAttestation=async n=>{const a=await this.getPublicKey();try{if(a)return this.validateAttestation(n,a)}catch(u){this.logger.error(u),this.logger.warn("error validating attestation")}const f=await this.fetchAndPersistPublicKey();try{if(f)return this.validateAttestation(n,f)}catch(u){this.logger.error(u),this.logger.warn("error validating attestation")}},this.getPublicKey=async()=>this.publicKey?this.publicKey:await this.fetchAndPersistPublicKey(),this.fetchAndPersistPublicKey=async()=>{if(this.fetchPromise)return await this.fetchPromise,this.publicKey;this.fetchPromise=new Promise(async a=>{const f=await this.fetchPublicKey();f&&(await this.persistPublicKey(f),a(f))});const n=await this.fetchPromise;return this.fetchPromise=void 0,n},this.validateAttestation=(n,a)=>{const f=IS(n,a.publicKey),u={hasExpired:xe.toMiliseconds(f.exp)this.abortController.abort(),xe.toMiliseconds(e))}}class uN extends TM{constructor(e,t){super(e,t),this.projectId=e,this.logger=t,this.context=rO,this.registerDeviceToken=async i=>{const{clientId:n,token:a,notificationType:f,enableEncrypted:u=!1}=i,b=`${iO}/${this.projectId}/clients`;await fetch(b,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:n,type:f,token:a,always_raw:u})})},this.logger=Yr(t,this.context)}}var lN=Object.defineProperty,nv=Object.getOwnPropertySymbols,dN=Object.prototype.hasOwnProperty,pN=Object.prototype.propertyIsEnumerable,sv=(r,e,t)=>e in r?lN(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,tc=(r,e)=>{for(var t in e||(e={}))dN.call(e,t)&&sv(r,t,e[t]);if(nv)for(var t of nv(e))pN.call(e,t)&&sv(r,t,e[t]);return r};class gN extends DM{constructor(e,t,i=!0){super(e,t,i),this.core=e,this.logger=t,this.context=sO,this.storagePrefix=kn,this.storageVersion=nO,this.events=new Map,this.shouldPersist=!1,this.init=async()=>{if(!z0())try{const n={eventId:L1(),timestamp:Date.now(),domain:this.getAppDomain(),props:{event:"INIT",type:"",properties:{client_id:await this.core.crypto.getClientId(),user_agent:Rb(this.core.relayer.protocol,this.core.relayer.version,m0)}}};await this.sendEvent([n])}catch(n){this.logger.warn(n)}},this.createEvent=n=>{const{event:a="ERROR",type:f="",properties:{topic:u,trace:b}}=n,p=L1(),y=this.core.projectId||"",A=Date.now(),R=tc({eventId:p,timestamp:A,props:{event:a,type:f,properties:{topic:u,trace:b}},bundleId:y,domain:this.getAppDomain()},this.setMethods(p));return this.telemetryEnabled&&(this.events.set(p,R),this.shouldPersist=!0),R},this.getEvent=n=>{const{eventId:a,topic:f}=n;if(a)return this.events.get(a);const u=Array.from(this.events.values()).find(b=>b.props.properties.topic===f);if(u)return tc(tc({},u),this.setMethods(u.eventId))},this.deleteEvent=n=>{const{eventId:a}=n;this.events.delete(a),this.shouldPersist=!0},this.setEventListeners=()=>{this.core.heartbeat.on(Ao.pulse,async()=>{this.shouldPersist&&await this.persist(),this.events.forEach(n=>{xe.fromMiliseconds(Date.now())-xe.fromMiliseconds(n.timestamp)>aO&&(this.events.delete(n.eventId),this.shouldPersist=!0)})})},this.setMethods=n=>({addTrace:a=>this.addTrace(n,a),setError:a=>this.setError(n,a)}),this.addTrace=(n,a)=>{const f=this.events.get(n);f&&(f.props.properties.trace.push(a),this.events.set(n,f),this.shouldPersist=!0)},this.setError=(n,a)=>{const f=this.events.get(n);f&&(f.props.type=a,f.timestamp=Date.now(),this.events.set(n,f),this.shouldPersist=!0)},this.persist=async()=>{await this.core.storage.setItem(this.storageKey,Array.from(this.events.values())),this.shouldPersist=!1},this.restore=async()=>{try{const n=await this.core.storage.getItem(this.storageKey)||[];if(!n.length)return;n.forEach(a=>{this.events.set(a.eventId,tc(tc({},a),this.setMethods(a.eventId)))})}catch(n){this.logger.warn(n)}},this.submit=async()=>{if(!this.telemetryEnabled||this.events.size===0)return;const n=[];for(const[a,f]of this.events)f.props.type&&n.push(f);if(n.length!==0)try{if((await this.sendEvent(n)).ok)for(const a of n)this.events.delete(a.eventId),this.shouldPersist=!0}catch(a){this.logger.warn(a)}},this.sendEvent=async n=>{const a=this.getAppDomain()?"":"&sp=desktop";return await fetch(`${oO}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${m0}${a}`,{method:"POST",body:JSON.stringify(n)})},this.getAppDomain=()=>Ob().url,this.logger=Yr(t,this.context),this.telemetryEnabled=i,i?this.restore().then(async()=>{await this.submit(),this.setEventListeners()}):this.persist()}get storageKey(){return this.storagePrefix+this.storageVersion+this.core.customStoragePrefix+"//"+this.context}}var vN=Object.defineProperty,av=Object.getOwnPropertySymbols,bN=Object.prototype.hasOwnProperty,mN=Object.prototype.propertyIsEnumerable,ov=(r,e,t)=>e in r?vN(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,cv=(r,e)=>{for(var t in e||(e={}))bN.call(e,t)&&ov(r,t,e[t]);if(av)for(var t of av(e))mN.call(e,t)&&ov(r,t,e[t]);return r};class td extends xM{constructor(e){var t;super(e),this.protocol=U2,this.version=$2,this.name=ed,this.events=new Hi.EventEmitter,this.initialized=!1,this.on=(f,u)=>this.events.on(f,u),this.once=(f,u)=>this.events.once(f,u),this.off=(f,u)=>this.events.off(f,u),this.removeListener=(f,u)=>this.events.removeListener(f,u),this.dispatchEnvelope=({topic:f,message:u,sessionExists:b})=>{if(!f||!u)return;const p={topic:f,message:u,publishedAt:Date.now(),transportType:Kt.link_mode};this.relayer.onLinkMessageEvent(p,{sessionExists:b})},this.projectId=e==null?void 0:e.projectId,this.relayUrl=(e==null?void 0:e.relayUrl)||j2,this.customStoragePrefix=e!=null&&e.customStoragePrefix?`:${e.customStoragePrefix}`:"";const i=Hh({level:typeof(e==null?void 0:e.logger)=="string"&&e.logger?e.logger:MP.logger}),{logger:n,chunkLoggerController:a}=EM({opts:i,maxSizeInBytes:e==null?void 0:e.maxLogBlobSizeInBytes,loggerOverride:e==null?void 0:e.logger});this.logChunkController=a,(t=this.logChunkController)!=null&&t.downloadLogsBlobInBrowser&&(window.downloadLogsBlobInBrowser=async()=>{var f,u;(f=this.logChunkController)!=null&&f.downloadLogsBlobInBrowser&&((u=this.logChunkController)==null||u.downloadLogsBlobInBrowser({clientId:await this.crypto.getClientId()}))}),this.logger=Yr(n,this.name),this.heartbeat=new yI,this.crypto=new TR(this,this.logger,e==null?void 0:e.keychain),this.history=new XR(this,this.logger),this.expirer=new ZR(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new JI(cv(cv({},PP),e==null?void 0:e.storageOptions)),this.relayer=new GR({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new QR(this,this.logger),this.verify=new hN(this,this.logger,this.storage),this.echoClient=new uN(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new gN(this,this.logger,e==null?void 0:e.telemetryEnabled)}static async init(e){const t=new td(e);await t.initialize();const i=await t.crypto.getClientId();return await t.storage.setItem(jP,i),t}get context(){return di(this.logger)}async start(){this.initialized||await this.initialize()}async getLogsBlob(){var e;return(e=this.logChunkController)==null?void 0:e.logsToBlob({clientId:await this.crypto.getClientId()})}async addLinkModeSupportedApp(e){this.linkModeSupportedApps.includes(e)||(this.linkModeSupportedApps.push(e),await this.storage.setItem(Hg,this.linkModeSupportedApps))}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.eventClient.init(),this.linkModeSupportedApps=await this.storage.getItem(Hg)||[],this.initialized=!0,this.logger.info("Core Initialization Success")}catch(e){throw this.logger.warn(`Core Initialization Failure at epoch ${Date.now()}`,e),this.logger.error(e.message),e}}}const yN=td,tm="wc",rm=2,im="client",rd=`${tm}@${rm}:${im}:`,Ul={name:im,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.org"},fv="WALLETCONNECT_DEEPLINK_CHOICE",wN="proposal",nm="Proposal expired",_N="session",Ga=xe.SEVEN_DAYS,AN="engine",wr={wc_sessionPropose:{req:{ttl:xe.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1101},reject:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1120},autoReject:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1121}},wc_sessionSettle:{req:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:xe.ONE_DAY,prompt:!1,tag:1104},res:{ttl:xe.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:xe.ONE_DAY,prompt:!1,tag:1106},res:{ttl:xe.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:xe.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:xe.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:xe.ONE_DAY,prompt:!1,tag:1112},res:{ttl:xe.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:xe.ONE_DAY,prompt:!1,tag:1114},res:{ttl:xe.ONE_DAY,prompt:!1,tag:1115}},wc_sessionAuthenticate:{req:{ttl:xe.ONE_HOUR,prompt:!0,tag:1116},res:{ttl:xe.ONE_HOUR,prompt:!1,tag:1117},reject:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1118},autoReject:{ttl:xe.FIVE_MINUTES,prompt:!1,tag:1119}}},$l={min:xe.FIVE_MINUTES,max:xe.SEVEN_DAYS},En={idle:"IDLE",active:"ACTIVE"},EN="request",xN=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],SN="wc",IN="auth",MN="authKeys",PN="pairingTopics",ON="requests",Jh=`${SN}@${1.5}:${IN}:`,sh=`${Jh}:PUB_KEY`;var RN=Object.defineProperty,NN=Object.defineProperties,CN=Object.getOwnPropertyDescriptors,hv=Object.getOwnPropertySymbols,TN=Object.prototype.hasOwnProperty,DN=Object.prototype.propertyIsEnumerable,uv=(r,e,t)=>e in r?RN(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,rr=(r,e)=>{for(var t in e||(e={}))TN.call(e,t)&&uv(r,t,e[t]);if(hv)for(var t of hv(e))DN.call(e,t)&&uv(r,t,e[t]);return r},fn=(r,e)=>NN(r,CN(e));class FN extends BM{constructor(e){super(e),this.name=AN,this.events=new I0,this.initialized=!1,this.requestQueue={state:En.idle,queue:[]},this.sessionRequestQueue={state:En.idle,queue:[]},this.requestQueueDelay=xe.ONE_SECOND,this.expectedPairingMethodMap=new Map,this.recentlyDeletedMap=new Map,this.recentlyDeletedLimit=200,this.relayMessageCache=[],this.init=async()=>{this.initialized||(await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.registerPairingEvents(),await this.registerLinkModeListeners(),this.client.core.pairing.register({methods:Object.keys(wr)}),this.initialized=!0,setTimeout(()=>{this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()},xe.toMiliseconds(this.requestQueueDelay)))},this.connect=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();const i=fn(rr({},t),{requiredNamespaces:t.requiredNamespaces||{},optionalNamespaces:t.optionalNamespaces||{}});await this.isValidConnect(i);const{pairingTopic:n,requiredNamespaces:a,optionalNamespaces:f,sessionProperties:u,relays:b}=i;let p=n,y,A=!1;try{p&&(A=this.client.core.pairing.pairings.get(p).active)}catch(U){throw this.client.logger.error(`connect() -> pairing.get(${p}) failed`),U}if(!p||!A){const{topic:U,uri:k}=await this.client.core.pairing.create();p=U,y=k}if(!p){const{message:U}=Ae("NO_MATCHING_KEY",`connect() pairing topic: ${p}`);throw new Error(U)}const R=await this.client.core.crypto.generateKeyPair(),O=wr.wc_sessionPropose.req.ttl||xe.FIVE_MINUTES,N=vr(O),K=rr({requiredNamespaces:a,optionalNamespaces:f,relays:b??[{protocol:z2}],proposer:{publicKey:R,metadata:this.client.metadata},expiryTimestamp:N,pairingTopic:p},u&&{sessionProperties:u}),{reject:W,resolve:Q,done:j}=oa(O,nm);this.events.once(St("session_connect"),async({error:U,session:k})=>{if(U)W(U);else if(k){k.self.publicKey=R;const G=fn(rr({},k),{pairingTopic:K.pairingTopic,requiredNamespaces:K.requiredNamespaces,optionalNamespaces:K.optionalNamespaces,transportType:Kt.relay});await this.client.session.set(k.topic,G),await this.setExpiry(k.topic,k.expiry),p&&await this.client.core.pairing.updateMetadata({topic:p,metadata:k.peer.metadata}),this.cleanupDuplicatePairings(G),Q(G)}});const Y=await this.sendRequest({topic:p,method:"wc_sessionPropose",params:K,throwOnFailedPublish:!0});return await this.setProposal(Y,rr({id:Y},K)),{uri:y,approval:j}},this.pair=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{return await this.client.core.pairing.pair(t)}catch(i){throw this.client.logger.error("pair() failed"),i}},this.approve=async t=>{var i,n,a;const f=this.client.core.eventClient.createEvent({properties:{topic:(i=t==null?void 0:t.id)==null?void 0:i.toString(),trace:[cn.session_approve_started]}});try{this.isInitialized(),await this.confirmOnlineStateOrThrow()}catch(B){throw f.setError(sa.no_internet_connection),B}try{await this.isValidProposalId(t==null?void 0:t.id)}catch(B){throw this.client.logger.error(`approve() -> proposal.get(${t==null?void 0:t.id}) failed`),f.setError(sa.proposal_not_found),B}try{await this.isValidApprove(t)}catch(B){throw this.client.logger.error("approve() -> isValidApprove() failed"),f.setError(sa.session_approve_namespace_validation_failure),B}const{id:u,relayProtocol:b,namespaces:p,sessionProperties:y,sessionConfig:A}=t,R=this.client.proposal.get(u);this.client.core.eventClient.deleteEvent({eventId:f.eventId});const{pairingTopic:O,proposer:N,requiredNamespaces:K,optionalNamespaces:W}=R;let Q=(n=this.client.core.eventClient)==null?void 0:n.getEvent({topic:O});Q||(Q=(a=this.client.core.eventClient)==null?void 0:a.createEvent({type:cn.session_approve_started,properties:{topic:O,trace:[cn.session_approve_started,cn.session_namespaces_validation_success]}}));const j=await this.client.core.crypto.generateKeyPair(),Y=N.publicKey,U=await this.client.core.crypto.generateSharedKey(j,Y),k=rr(rr({relay:{protocol:b??"irn"},namespaces:p,controller:{publicKey:j,metadata:this.client.metadata},expiry:vr(Ga)},y&&{sessionProperties:y}),A&&{sessionConfig:A}),G=Kt.relay;Q.addTrace(cn.subscribing_session_topic);try{await this.client.core.relayer.subscribe(U,{transportType:G})}catch(B){throw Q.setError(sa.subscribe_session_topic_failure),B}Q.addTrace(cn.subscribe_session_topic_success);const x=fn(rr({},k),{topic:U,requiredNamespaces:K,optionalNamespaces:W,pairingTopic:O,acknowledged:!1,self:k.controller,peer:{publicKey:N.publicKey,metadata:N.metadata},controller:j,transportType:Kt.relay});await this.client.session.set(U,x),Q.addTrace(cn.store_session);try{Q.addTrace(cn.publishing_session_settle),await this.sendRequest({topic:U,method:"wc_sessionSettle",params:k,throwOnFailedPublish:!0}).catch(B=>{throw Q==null||Q.setError(sa.session_settle_publish_failure),B}),Q.addTrace(cn.session_settle_publish_success),Q.addTrace(cn.publishing_session_approve),await this.sendResult({id:u,topic:O,result:{relay:{protocol:b??"irn"},responderPublicKey:j},throwOnFailedPublish:!0}).catch(B=>{throw Q==null||Q.setError(sa.session_approve_publish_failure),B}),Q.addTrace(cn.session_approve_publish_success)}catch(B){throw this.client.logger.error(B),this.client.session.delete(U,Ut("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe(U),B}return this.client.core.eventClient.deleteEvent({eventId:Q.eventId}),await this.client.core.pairing.updateMetadata({topic:O,metadata:N.metadata}),await this.client.proposal.delete(u,Ut("USER_DISCONNECTED")),await this.client.core.pairing.activate({topic:O}),await this.setExpiry(U,vr(Ga)),{topic:U,acknowledged:()=>Promise.resolve(this.client.session.get(U))}},this.reject=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidReject(t)}catch(f){throw this.client.logger.error("reject() -> isValidReject() failed"),f}const{id:i,reason:n}=t;let a;try{a=this.client.proposal.get(i).pairingTopic}catch(f){throw this.client.logger.error(`reject() -> proposal.get(${i}) failed`),f}a&&(await this.sendError({id:i,topic:a,error:n,rpcOpts:wr.wc_sessionPropose.reject}),await this.client.proposal.delete(i,Ut("USER_DISCONNECTED")))},this.update=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidUpdate(t)}catch(A){throw this.client.logger.error("update() -> isValidUpdate() failed"),A}const{topic:i,namespaces:n}=t,{done:a,resolve:f,reject:u}=oa(),b=Cs(),p=ha().toString(),y=this.client.session.get(i).namespaces;return this.events.once(St("session_update",b),({error:A})=>{A?u(A):f()}),await this.client.session.update(i,{namespaces:n}),await this.sendRequest({topic:i,method:"wc_sessionUpdate",params:{namespaces:n},throwOnFailedPublish:!0,clientRpcId:b,relayRpcId:p}).catch(A=>{this.client.logger.error(A),this.client.session.update(i,{namespaces:y}),u(A)}),{acknowledged:a}},this.extend=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidExtend(t)}catch(b){throw this.client.logger.error("extend() -> isValidExtend() failed"),b}const{topic:i}=t,n=Cs(),{done:a,resolve:f,reject:u}=oa();return this.events.once(St("session_extend",n),({error:b})=>{b?u(b):f()}),await this.setExpiry(i,vr(Ga)),this.sendRequest({topic:i,method:"wc_sessionExtend",params:{},clientRpcId:n,throwOnFailedPublish:!0}).catch(b=>{u(b)}),{acknowledged:a}},this.request=async t=>{this.isInitialized();try{await this.isValidRequest(t)}catch(N){throw this.client.logger.error("request() -> isValidRequest() failed"),N}const{chainId:i,request:n,topic:a,expiry:f=wr.wc_sessionRequest.req.ttl}=t,u=this.client.session.get(a);(u==null?void 0:u.transportType)===Kt.relay&&await this.confirmOnlineStateOrThrow();const b=Cs(),p=ha().toString(),{done:y,resolve:A,reject:R}=oa(f,"Request expired. Please try again.");this.events.once(St("session_request",b),({error:N,result:K})=>{N?R(N):A(K)});const O=this.getAppLinkIfEnabled(u.peer.metadata,u.transportType);return O?(await this.sendRequest({clientRpcId:b,relayRpcId:p,topic:a,method:"wc_sessionRequest",params:{request:fn(rr({},n),{expiryTimestamp:vr(f)}),chainId:i},expiry:f,throwOnFailedPublish:!0,appLink:O}).catch(N=>R(N)),this.client.events.emit("session_request_sent",{topic:a,request:n,chainId:i,id:b}),await y()):await Promise.all([new Promise(async N=>{await this.sendRequest({clientRpcId:b,relayRpcId:p,topic:a,method:"wc_sessionRequest",params:{request:fn(rr({},n),{expiryTimestamp:vr(f)}),chainId:i},expiry:f,throwOnFailedPublish:!0}).catch(K=>R(K)),this.client.events.emit("session_request_sent",{topic:a,request:n,chainId:i,id:b}),N()}),new Promise(async N=>{var K;if(!((K=u.sessionConfig)!=null&&K.disableDeepLink)){const W=await gA(this.client.core.storage,fv);await dA({id:b,topic:a,wcDeepLink:W})}N()}),y()]).then(N=>N[2])},this.respond=async t=>{this.isInitialized(),await this.isValidRespond(t);const{topic:i,response:n}=t,{id:a}=n,f=this.client.session.get(i);f.transportType===Kt.relay&&await this.confirmOnlineStateOrThrow();const u=this.getAppLinkIfEnabled(f.peer.metadata,f.transportType);Mn(n)?await this.sendResult({id:a,topic:i,result:n.result,throwOnFailedPublish:!0,appLink:u}):$i(n)&&await this.sendError({id:a,topic:i,error:n.error,appLink:u}),this.cleanupAfterResponse(t)},this.ping=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidPing(t)}catch(n){throw this.client.logger.error("ping() -> isValidPing() failed"),n}const{topic:i}=t;if(this.client.session.keys.includes(i)){const n=Cs(),a=ha().toString(),{done:f,resolve:u,reject:b}=oa();this.events.once(St("session_ping",n),({error:p})=>{p?b(p):u()}),await Promise.all([this.sendRequest({topic:i,method:"wc_sessionPing",params:{},throwOnFailedPublish:!0,clientRpcId:n,relayRpcId:a}),f()])}else this.client.core.pairing.pairings.keys.includes(i)&&await this.client.core.pairing.ping({topic:i})},this.emit=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidEmit(t);const{topic:i,event:n,chainId:a}=t,f=ha().toString();await this.sendRequest({topic:i,method:"wc_sessionEvent",params:{event:n,chainId:a},throwOnFailedPublish:!0,relayRpcId:f})},this.disconnect=async t=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidDisconnect(t);const{topic:i}=t;if(this.client.session.keys.includes(i))await this.sendRequest({topic:i,method:"wc_sessionDelete",params:Ut("USER_DISCONNECTED"),throwOnFailedPublish:!0}),await this.deleteSession({topic:i,emitEvent:!1});else if(this.client.core.pairing.pairings.keys.includes(i))await this.client.core.pairing.disconnect({topic:i});else{const{message:n}=Ae("MISMATCHED_TOPIC",`Session or pairing topic not found: ${i}`);throw new Error(n)}},this.find=t=>(this.isInitialized(),this.client.session.getAll().filter(i=>kS(i,t))),this.getPendingSessionRequests=()=>this.client.pendingRequest.getAll(),this.authenticate=async(t,i)=>{var n;this.isInitialized(),this.isValidAuthenticate(t);const a=i&&this.client.core.linkModeSupportedApps.includes(i)&&((n=this.client.metadata.redirect)==null?void 0:n.linkMode),f=a?Kt.link_mode:Kt.relay;f===Kt.relay&&await this.confirmOnlineStateOrThrow();const{chains:u,statement:b="",uri:p,domain:y,nonce:A,type:R,exp:O,nbf:N,methods:K=[],expiry:W}=t,Q=[...t.resources||[]],{topic:j,uri:Y}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:f});this.client.logger.info({message:"Generated new pairing",pairing:{topic:j,uri:Y}});const U=await this.client.core.crypto.generateKeyPair(),k=rh(U);if(await Promise.all([this.client.auth.authKeys.set(sh,{responseTopic:k,publicKey:U}),this.client.auth.pairingTopics.set(k,{topic:k,pairingTopic:j})]),await this.client.core.relayer.subscribe(k,{transportType:f}),this.client.logger.info(`sending request to new pairing topic: ${j}`),K.length>0){const{namespace:M}=ac(u[0]);let S=hS(M,"request",K);th(Q)&&(S=lS(S,Q.pop())),Q.push(S)}const G=W&&W>wr.wc_sessionAuthenticate.req.ttl?W:wr.wc_sessionAuthenticate.req.ttl,x={authPayload:{type:R??"caip122",chains:u,statement:b,aud:p,domain:y,version:"1",nonce:A,iat:new Date().toISOString(),exp:O,nbf:N,resources:Q},requester:{publicKey:U,metadata:this.client.metadata},expiryTimestamp:vr(G)},B={eip155:{chains:u,methods:[...new Set(["personal_sign",...K])],events:["chainChanged","accountsChanged"]}},ae={requiredNamespaces:{},optionalNamespaces:B,relays:[{protocol:"irn"}],pairingTopic:j,proposer:{publicKey:U,metadata:this.client.metadata},expiryTimestamp:vr(wr.wc_sessionPropose.req.ttl)},{done:le,resolve:F,reject:m}=oa(G,"Request expired"),c=async({error:M,session:S})=>{if(this.events.off(St("session_request",v),h),M)m(M);else if(S){S.self.publicKey=U,await this.client.session.set(S.topic,S),await this.setExpiry(S.topic,S.expiry),j&&await this.client.core.pairing.updateMetadata({topic:j,metadata:S.peer.metadata});const d=this.client.session.get(S.topic);await this.deleteProposal(_),F({session:d})}},h=async M=>{var S,d,g;if(await this.deletePendingAuthRequest(v,{message:"fulfilled",code:0}),M.error){const z=Ut("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return M.error.code===z.code?void 0:(this.events.off(St("session_connect"),c),m(M.error.message))}await this.deleteProposal(_),this.events.off(St("session_connect"),c);const{cacaos:T,responder:Z}=M.result,se=[],P=[];for(const z of T){await hg({cacao:z,projectId:this.client.core.projectId})||(this.client.logger.error(z,"Signature verification failed"),m(Ut("SESSION_SETTLEMENT_FAILED","Signature verification failed")));const{p:H}=z,w=th(H.resources),$=[fg(H.iss)],ne=mh(H.iss);if(w){const ce=ug(w),he=lg(w);se.push(...ce),$.push(...he)}for(const ce of $)P.push(`${ce}:${ne}`)}const ee=await this.client.core.crypto.generateSharedKey(U,Z.publicKey);let q;se.length>0&&(q={topic:ee,acknowledged:!0,self:{publicKey:U,metadata:this.client.metadata},peer:Z,controller:Z.publicKey,expiry:vr(Ga),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:j,namespaces:_g([...new Set(se)],[...new Set(P)]),transportType:f},await this.client.core.relayer.subscribe(ee,{transportType:f}),await this.client.session.set(ee,q),j&&await this.client.core.pairing.updateMetadata({topic:j,metadata:Z.metadata}),q=this.client.session.get(ee)),(S=this.client.metadata.redirect)!=null&&S.linkMode&&(d=Z.metadata.redirect)!=null&&d.linkMode&&(g=Z.metadata.redirect)!=null&&g.universal&&i&&(this.client.core.addLinkModeSupportedApp(Z.metadata.redirect.universal),this.client.session.update(ee,{transportType:Kt.link_mode})),F({auths:T,session:q})},v=Cs(),_=Cs();this.events.once(St("session_connect"),c),this.events.once(St("session_request",v),h);let I;try{if(a){const M=qs("wc_sessionAuthenticate",x,v);this.client.core.history.set(j,M);const S=await this.client.core.crypto.encode("",M,{type:Oc,encoding:Yo});I=kf(i,j,S)}else await Promise.all([this.sendRequest({topic:j,method:"wc_sessionAuthenticate",params:x,expiry:t.expiry,throwOnFailedPublish:!0,clientRpcId:v}),this.sendRequest({topic:j,method:"wc_sessionPropose",params:ae,expiry:wr.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:_})])}catch(M){throw this.events.off(St("session_connect"),c),this.events.off(St("session_request",v),h),M}return await this.setProposal(_,rr({id:_},ae)),await this.setAuthRequest(v,{request:fn(rr({},x),{verifyContext:{}}),pairingTopic:j,transportType:f}),{uri:I??Y,response:le}},this.approveSessionAuthenticate=async t=>{const{id:i,auths:n}=t,a=this.client.core.eventClient.createEvent({properties:{topic:i.toString(),trace:[aa.authenticated_session_approve_started]}});try{this.isInitialized()}catch(W){throw a.setError(Zo.no_internet_connection),W}const f=this.getPendingAuthRequest(i);if(!f)throw a.setError(Zo.authenticated_session_pending_request_not_found),new Error(`Could not find pending auth request with id ${i}`);const u=f.transportType||Kt.relay;u===Kt.relay&&await this.confirmOnlineStateOrThrow();const b=f.requester.publicKey,p=await this.client.core.crypto.generateKeyPair(),y=rh(b),A={type:ds,receiverPublicKey:b,senderPublicKey:p},R=[],O=[];for(const W of n){if(!await hg({cacao:W,projectId:this.client.core.projectId})){a.setError(Zo.invalid_cacao);const k=Ut("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:i,topic:y,error:k,encodeOpts:A}),new Error(k.message)}a.addTrace(aa.cacaos_verified);const{p:Q}=W,j=th(Q.resources),Y=[fg(Q.iss)],U=mh(Q.iss);if(j){const k=ug(j),G=lg(j);R.push(...k),Y.push(...G)}for(const k of Y)O.push(`${k}:${U}`)}const N=await this.client.core.crypto.generateSharedKey(p,b);a.addTrace(aa.create_authenticated_session_topic);let K;if((R==null?void 0:R.length)>0){K={topic:N,acknowledged:!0,self:{publicKey:p,metadata:this.client.metadata},peer:{publicKey:b,metadata:f.requester.metadata},controller:b,expiry:vr(Ga),authentication:n,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:f.pairingTopic,namespaces:_g([...new Set(R)],[...new Set(O)]),transportType:u},a.addTrace(aa.subscribing_authenticated_session_topic);try{await this.client.core.relayer.subscribe(N,{transportType:u})}catch(W){throw a.setError(Zo.subscribe_authenticated_session_topic_failure),W}a.addTrace(aa.subscribe_authenticated_session_topic_success),await this.client.session.set(N,K),a.addTrace(aa.store_authenticated_session),await this.client.core.pairing.updateMetadata({topic:f.pairingTopic,metadata:f.requester.metadata})}a.addTrace(aa.publishing_authenticated_session_approve);try{await this.sendResult({topic:y,id:i,result:{cacaos:n,responder:{publicKey:p,metadata:this.client.metadata}},encodeOpts:A,throwOnFailedPublish:!0,appLink:this.getAppLinkIfEnabled(f.requester.metadata,u)})}catch(W){throw a.setError(Zo.authenticated_session_approve_publish_failure),W}return await this.client.auth.requests.delete(i,{message:"fulfilled",code:0}),await this.client.core.pairing.activate({topic:f.pairingTopic}),this.client.core.eventClient.deleteEvent({eventId:a.eventId}),{session:K}},this.rejectSessionAuthenticate=async t=>{this.isInitialized();const{id:i,reason:n}=t,a=this.getPendingAuthRequest(i);if(!a)throw new Error(`Could not find pending auth request with id ${i}`);a.transportType===Kt.relay&&await this.confirmOnlineStateOrThrow();const f=a.requester.publicKey,u=await this.client.core.crypto.generateKeyPair(),b=rh(f),p={type:ds,receiverPublicKey:f,senderPublicKey:u};await this.sendError({id:i,topic:b,error:n,encodeOpts:p,rpcOpts:wr.wc_sessionAuthenticate.reject,appLink:this.getAppLinkIfEnabled(a.requester.metadata,a.transportType)}),await this.client.auth.requests.delete(i,{message:"rejected",code:0}),await this.client.proposal.delete(i,Ut("USER_DISCONNECTED"))},this.formatAuthMessage=t=>{this.isInitialized();const{request:i,iss:n}=t;return b2(i,n)},this.processRelayMessageCache=()=>{setTimeout(async()=>{if(this.relayMessageCache.length!==0)for(;this.relayMessageCache.length>0;)try{const t=this.relayMessageCache.shift();t&&await this.onRelayMessage(t)}catch(t){this.client.logger.error(t)}},50)},this.cleanupDuplicatePairings=async t=>{if(t.pairingTopic)try{const i=this.client.core.pairing.pairings.get(t.pairingTopic),n=this.client.core.pairing.pairings.getAll().filter(a=>{var f,u;return((f=a.peerMetadata)==null?void 0:f.url)&&((u=a.peerMetadata)==null?void 0:u.url)===t.peer.metadata.url&&a.topic&&a.topic!==i.topic});if(n.length===0)return;this.client.logger.info(`Cleaning up ${n.length} duplicate pairing(s)`),await Promise.all(n.map(a=>this.client.core.pairing.disconnect({topic:a.topic}))),this.client.logger.info("Duplicate pairings clean up finished")}catch(i){this.client.logger.error(i)}},this.deleteSession=async t=>{var i;const{topic:n,expirerHasDeleted:a=!1,emitEvent:f=!0,id:u=0}=t,{self:b}=this.client.session.get(n);await this.client.core.relayer.unsubscribe(n),await this.client.session.delete(n,Ut("USER_DISCONNECTED")),this.addToRecentlyDeleted(n,"session"),this.client.core.crypto.keychain.has(b.publicKey)&&await this.client.core.crypto.deleteKeyPair(b.publicKey),this.client.core.crypto.keychain.has(n)&&await this.client.core.crypto.deleteSymKey(n),a||this.client.core.expirer.del(n),this.client.core.storage.removeItem(fv).catch(p=>this.client.logger.warn(p)),this.getPendingSessionRequests().forEach(p=>{p.topic===n&&this.deletePendingSessionRequest(p.id,Ut("USER_DISCONNECTED"))}),n===((i=this.sessionRequestQueue.queue[0])==null?void 0:i.topic)&&(this.sessionRequestQueue.state=En.idle),f&&this.client.events.emit("session_delete",{id:u,topic:n})},this.deleteProposal=async(t,i)=>{if(i)try{const n=this.client.proposal.get(t),a=this.client.core.eventClient.getEvent({topic:n.pairingTopic});a==null||a.setError(sa.proposal_expired)}catch{}await Promise.all([this.client.proposal.delete(t,Ut("USER_DISCONNECTED")),i?Promise.resolve():this.client.core.expirer.del(t)]),this.addToRecentlyDeleted(t,"proposal")},this.deletePendingSessionRequest=async(t,i,n=!1)=>{await Promise.all([this.client.pendingRequest.delete(t,i),n?Promise.resolve():this.client.core.expirer.del(t)]),this.addToRecentlyDeleted(t,"request"),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter(a=>a.id!==t),n&&(this.sessionRequestQueue.state=En.idle,this.client.events.emit("session_request_expire",{id:t}))},this.deletePendingAuthRequest=async(t,i,n=!1)=>{await Promise.all([this.client.auth.requests.delete(t,i),n?Promise.resolve():this.client.core.expirer.del(t)])},this.setExpiry=async(t,i)=>{this.client.session.keys.includes(t)&&(this.client.core.expirer.set(t,i),await this.client.session.update(t,{expiry:i}))},this.setProposal=async(t,i)=>{this.client.core.expirer.set(t,vr(wr.wc_sessionPropose.req.ttl)),await this.client.proposal.set(t,i)},this.setAuthRequest=async(t,i)=>{const{request:n,pairingTopic:a,transportType:f=Kt.relay}=i;this.client.core.expirer.set(t,n.expiryTimestamp),await this.client.auth.requests.set(t,{authPayload:n.authPayload,requester:n.requester,expiryTimestamp:n.expiryTimestamp,id:t,pairingTopic:a,verifyContext:n.verifyContext,transportType:f})},this.setPendingSessionRequest=async t=>{const{id:i,topic:n,params:a,verifyContext:f}=t,u=a.request.expiryTimestamp||vr(wr.wc_sessionRequest.req.ttl);this.client.core.expirer.set(i,u),await this.client.pendingRequest.set(i,{id:i,topic:n,params:a,verifyContext:f})},this.sendRequest=async t=>{const{topic:i,method:n,params:a,expiry:f,relayRpcId:u,clientRpcId:b,throwOnFailedPublish:p,appLink:y}=t,A=qs(n,a,b);let R;const O=!!y;try{const W=O?Yo:Bs;R=await this.client.core.crypto.encode(i,A,{encoding:W})}catch(W){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${i} failed`),W}let N;if(xN.includes(n)){const W=fs(JSON.stringify(A)),Q=fs(R);N=await this.client.core.verify.register({id:Q,decryptedId:W})}const K=wr[n].req;if(K.attestation=N,f&&(K.ttl=f),u&&(K.id=u),this.client.core.history.set(i,A),O){const W=kf(y,i,R);await global.Linking.openURL(W,this.client.name)}else{const W=wr[n].req;f&&(W.ttl=f),u&&(W.id=u),p?(W.internal=fn(rr({},W.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(i,R,W)):this.client.core.relayer.publish(i,R,W).catch(Q=>this.client.logger.error(Q))}return A.id},this.sendResult=async t=>{const{id:i,topic:n,result:a,throwOnFailedPublish:f,encodeOpts:u,appLink:b}=t,p=Kh(i,a);let y;const A=b&&typeof(global==null?void 0:global.Linking)<"u";try{const O=A?Yo:Bs;y=await this.client.core.crypto.encode(n,p,fn(rr({},u||{}),{encoding:O}))}catch(O){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${n} failed`),O}let R;try{R=await this.client.core.history.get(n,i)}catch(O){throw this.client.logger.error(`sendResult() -> history.get(${n}, ${i}) failed`),O}if(A){const O=kf(b,n,y);await global.Linking.openURL(O,this.client.name)}else{const O=wr[R.request.method].res;f?(O.internal=fn(rr({},O.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(n,y,O)):this.client.core.relayer.publish(n,y,O).catch(N=>this.client.logger.error(N))}await this.client.core.history.resolve(p)},this.sendError=async t=>{const{id:i,topic:n,error:a,encodeOpts:f,rpcOpts:u,appLink:b}=t,p=Vh(i,a);let y;const A=b&&typeof(global==null?void 0:global.Linking)<"u";try{const O=A?Yo:Bs;y=await this.client.core.crypto.encode(n,p,fn(rr({},f||{}),{encoding:O}))}catch(O){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${n} failed`),O}let R;try{R=await this.client.core.history.get(n,i)}catch(O){throw this.client.logger.error(`sendError() -> history.get(${n}, ${i}) failed`),O}if(A){const O=kf(b,n,y);await global.Linking.openURL(O,this.client.name)}else{const O=u||wr[R.request.method].res;this.client.core.relayer.publish(n,y,O)}await this.client.core.history.resolve(p)},this.cleanup=async()=>{const t=[],i=[];this.client.session.getAll().forEach(n=>{let a=!1;Rs(n.expiry)&&(a=!0),this.client.core.crypto.keychain.has(n.topic)||(a=!0),a&&t.push(n.topic)}),this.client.proposal.getAll().forEach(n=>{Rs(n.expiryTimestamp)&&i.push(n.id)}),await Promise.all([...t.map(n=>this.deleteSession({topic:n})),...i.map(n=>this.deleteProposal(n))])},this.onRelayEventRequest=async t=>{this.requestQueue.queue.push(t),await this.processRequestsQueue()},this.processRequestsQueue=async()=>{if(this.requestQueue.state===En.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=En.active;const t=this.requestQueue.queue.shift();if(t)try{await this.processRequest(t)}catch(i){this.client.logger.warn(i)}}this.requestQueue.state=En.idle},this.processRequest=async t=>{const{topic:i,payload:n,attestation:a,transportType:f,encryptedId:u}=t,b=n.method;if(!this.shouldIgnorePairingRequest({topic:i,requestMethod:b}))switch(b){case"wc_sessionPropose":return await this.onSessionProposeRequest({topic:i,payload:n,attestation:a,encryptedId:u});case"wc_sessionSettle":return await this.onSessionSettleRequest(i,n);case"wc_sessionUpdate":return await this.onSessionUpdateRequest(i,n);case"wc_sessionExtend":return await this.onSessionExtendRequest(i,n);case"wc_sessionPing":return await this.onSessionPingRequest(i,n);case"wc_sessionDelete":return await this.onSessionDeleteRequest(i,n);case"wc_sessionRequest":return await this.onSessionRequest({topic:i,payload:n,attestation:a,encryptedId:u,transportType:f});case"wc_sessionEvent":return await this.onSessionEventRequest(i,n);case"wc_sessionAuthenticate":return await this.onSessionAuthenticateRequest({topic:i,payload:n,attestation:a,encryptedId:u,transportType:f});default:return this.client.logger.info(`Unsupported request method ${b}`)}},this.onRelayEventResponse=async t=>{const{topic:i,payload:n,transportType:a}=t,f=(await this.client.core.history.get(i,n.id)).request.method;switch(f){case"wc_sessionPropose":return this.onSessionProposeResponse(i,n,a);case"wc_sessionSettle":return this.onSessionSettleResponse(i,n);case"wc_sessionUpdate":return this.onSessionUpdateResponse(i,n);case"wc_sessionExtend":return this.onSessionExtendResponse(i,n);case"wc_sessionPing":return this.onSessionPingResponse(i,n);case"wc_sessionRequest":return this.onSessionRequestResponse(i,n);case"wc_sessionAuthenticate":return this.onSessionAuthenticateResponse(i,n);default:return this.client.logger.info(`Unsupported response method ${f}`)}},this.onRelayEventUnknownPayload=t=>{const{topic:i}=t,{message:n}=Ae("MISSING_OR_INVALID",`Decoded payload on topic ${i} is not identifiable as a JSON-RPC request or a response.`);throw new Error(n)},this.shouldIgnorePairingRequest=t=>{const{topic:i,requestMethod:n}=t,a=this.expectedPairingMethodMap.get(i);return!a||a.includes(n)?!1:!!(a.includes("wc_sessionAuthenticate")&&this.client.events.listenerCount("session_authenticate")>0)},this.onSessionProposeRequest=async t=>{const{topic:i,payload:n,attestation:a,encryptedId:f}=t,{params:u,id:b}=n;try{const p=this.client.core.eventClient.getEvent({topic:i});this.isValidConnect(rr({},n.params));const y=u.expiryTimestamp||vr(wr.wc_sessionPropose.req.ttl),A=rr({id:b,pairingTopic:i,expiryTimestamp:y},u);await this.setProposal(b,A);const R=await this.getVerifyContext({attestationId:a,hash:fs(JSON.stringify(n)),encryptedId:f,metadata:A.proposer.metadata});this.client.events.listenerCount("session_proposal")===0&&(console.warn("No listener for session_proposal event"),p==null||p.setError(os.proposal_listener_not_found)),p==null||p.addTrace(xn.emit_session_proposal),this.client.events.emit("session_proposal",{id:b,params:A,verifyContext:R})}catch(p){await this.sendError({id:b,topic:i,error:p,rpcOpts:wr.wc_sessionPropose.autoReject}),this.client.logger.error(p)}},this.onSessionProposeResponse=async(t,i,n)=>{const{id:a}=i;if(Mn(i)){const{result:f}=i;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:f});const u=this.client.proposal.get(a);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:u});const b=u.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:b});const p=f.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:p});const y=await this.client.core.crypto.generateSharedKey(b,p);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",sessionTopic:y});const A=await this.client.core.relayer.subscribe(y,{transportType:n});this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:A}),await this.client.core.pairing.activate({topic:t})}else if($i(i)){await this.client.proposal.delete(a,Ut("USER_DISCONNECTED"));const f=St("session_connect");if(this.events.listenerCount(f)===0)throw new Error(`emitting ${f} without any listeners, 954`);this.events.emit(St("session_connect"),{error:i.error})}},this.onSessionSettleRequest=async(t,i)=>{const{id:n,params:a}=i;try{this.isValidSessionSettleRequest(a);const{relay:f,controller:u,expiry:b,namespaces:p,sessionProperties:y,sessionConfig:A}=i.params,R=fn(rr(rr({topic:t,relay:f,expiry:b,namespaces:p,acknowledged:!0,pairingTopic:"",requiredNamespaces:{},optionalNamespaces:{},controller:u.publicKey,self:{publicKey:"",metadata:this.client.metadata},peer:{publicKey:u.publicKey,metadata:u.metadata}},y&&{sessionProperties:y}),A&&{sessionConfig:A}),{transportType:Kt.relay}),O=St("session_connect");if(this.events.listenerCount(O)===0)throw new Error(`emitting ${O} without any listeners 997`);this.events.emit(St("session_connect"),{session:R}),await this.sendResult({id:i.id,topic:t,result:!0,throwOnFailedPublish:!0})}catch(f){await this.sendError({id:n,topic:t,error:f}),this.client.logger.error(f)}},this.onSessionSettleResponse=async(t,i)=>{const{id:n}=i;Mn(i)?(await this.client.session.update(t,{acknowledged:!0}),this.events.emit(St("session_approve",n),{})):$i(i)&&(await this.client.session.delete(t,Ut("USER_DISCONNECTED")),this.events.emit(St("session_approve",n),{error:i.error}))},this.onSessionUpdateRequest=async(t,i)=>{const{params:n,id:a}=i;try{const f=`${t}_session_update`,u=Qo.get(f);if(u&&this.isRequestOutOfSync(u,a)){this.client.logger.info(`Discarding out of sync request - ${a}`),this.sendError({id:a,topic:t,error:Ut("INVALID_UPDATE_REQUEST")});return}this.isValidUpdate(rr({topic:t},n));try{Qo.set(f,a),await this.client.session.update(t,{namespaces:n.namespaces}),await this.sendResult({id:a,topic:t,result:!0,throwOnFailedPublish:!0})}catch(b){throw Qo.delete(f),b}this.client.events.emit("session_update",{id:a,topic:t,params:n})}catch(f){await this.sendError({id:a,topic:t,error:f}),this.client.logger.error(f)}},this.isRequestOutOfSync=(t,i)=>parseInt(i.toString().slice(0,-3))<=parseInt(t.toString().slice(0,-3)),this.onSessionUpdateResponse=(t,i)=>{const{id:n}=i,a=St("session_update",n);if(this.events.listenerCount(a)===0)throw new Error(`emitting ${a} without any listeners`);Mn(i)?this.events.emit(St("session_update",n),{}):$i(i)&&this.events.emit(St("session_update",n),{error:i.error})},this.onSessionExtendRequest=async(t,i)=>{const{id:n}=i;try{this.isValidExtend({topic:t}),await this.setExpiry(t,vr(Ga)),await this.sendResult({id:n,topic:t,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_extend",{id:n,topic:t})}catch(a){await this.sendError({id:n,topic:t,error:a}),this.client.logger.error(a)}},this.onSessionExtendResponse=(t,i)=>{const{id:n}=i,a=St("session_extend",n);if(this.events.listenerCount(a)===0)throw new Error(`emitting ${a} without any listeners`);Mn(i)?this.events.emit(St("session_extend",n),{}):$i(i)&&this.events.emit(St("session_extend",n),{error:i.error})},this.onSessionPingRequest=async(t,i)=>{const{id:n}=i;try{this.isValidPing({topic:t}),await this.sendResult({id:n,topic:t,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_ping",{id:n,topic:t})}catch(a){await this.sendError({id:n,topic:t,error:a}),this.client.logger.error(a)}},this.onSessionPingResponse=(t,i)=>{const{id:n}=i,a=St("session_ping",n);if(this.events.listenerCount(a)===0)throw new Error(`emitting ${a} without any listeners`);setTimeout(()=>{Mn(i)?this.events.emit(St("session_ping",n),{}):$i(i)&&this.events.emit(St("session_ping",n),{error:i.error})},500)},this.onSessionDeleteRequest=async(t,i)=>{const{id:n}=i;try{this.isValidDisconnect({topic:t,reason:i.params}),Promise.all([new Promise(a=>{this.client.core.relayer.once(Gr.publish,async()=>{a(await this.deleteSession({topic:t,id:n}))})}),this.sendResult({id:n,topic:t,result:!0,throwOnFailedPublish:!0}),this.cleanupPendingSentRequestsForTopic({topic:t,error:Ut("USER_DISCONNECTED")})]).catch(a=>this.client.logger.error(a))}catch(a){this.client.logger.error(a)}},this.onSessionRequest=async t=>{var i,n,a;const{topic:f,payload:u,attestation:b,encryptedId:p,transportType:y}=t,{id:A,params:R}=u;try{await this.isValidRequest(rr({topic:f},R));const O=this.client.session.get(f),N=await this.getVerifyContext({attestationId:b,hash:fs(JSON.stringify(qs("wc_sessionRequest",R,A))),encryptedId:p,metadata:O.peer.metadata,transportType:y}),K={id:A,topic:f,params:R,verifyContext:N};await this.setPendingSessionRequest(K),y===Kt.link_mode&&(i=O.peer.metadata.redirect)!=null&&i.universal&&this.client.core.addLinkModeSupportedApp((n=O.peer.metadata.redirect)==null?void 0:n.universal),(a=this.client.signConfig)!=null&&a.disableRequestQueue?this.emitSessionRequest(K):(this.addSessionRequestToSessionRequestQueue(K),this.processSessionRequestQueue())}catch(O){await this.sendError({id:A,topic:f,error:O}),this.client.logger.error(O)}},this.onSessionRequestResponse=(t,i)=>{const{id:n}=i,a=St("session_request",n);if(this.events.listenerCount(a)===0)throw new Error(`emitting ${a} without any listeners`);Mn(i)?this.events.emit(St("session_request",n),{result:i.result}):$i(i)&&this.events.emit(St("session_request",n),{error:i.error})},this.onSessionEventRequest=async(t,i)=>{const{id:n,params:a}=i;try{const f=`${t}_session_event_${a.event.name}`,u=Qo.get(f);if(u&&this.isRequestOutOfSync(u,n)){this.client.logger.info(`Discarding out of sync request - ${n}`);return}this.isValidEmit(rr({topic:t},a)),this.client.events.emit("session_event",{id:n,topic:t,params:a}),Qo.set(f,n)}catch(f){await this.sendError({id:n,topic:t,error:f}),this.client.logger.error(f)}},this.onSessionAuthenticateResponse=(t,i)=>{const{id:n}=i;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:t,payload:i}),Mn(i)?this.events.emit(St("session_request",n),{result:i.result}):$i(i)&&this.events.emit(St("session_request",n),{error:i.error})},this.onSessionAuthenticateRequest=async t=>{var i;const{topic:n,payload:a,attestation:f,encryptedId:u,transportType:b}=t;try{const{requester:p,authPayload:y,expiryTimestamp:A}=a.params,R=await this.getVerifyContext({attestationId:f,hash:fs(JSON.stringify(a)),encryptedId:u,metadata:p.metadata,transportType:b}),O={requester:p,pairingTopic:n,id:a.id,authPayload:y,verifyContext:R,expiryTimestamp:A};await this.setAuthRequest(a.id,{request:O,pairingTopic:n,transportType:b}),b===Kt.link_mode&&(i=p.metadata.redirect)!=null&&i.universal&&this.client.core.addLinkModeSupportedApp(p.metadata.redirect.universal),this.client.events.emit("session_authenticate",{topic:n,params:a.params,id:a.id,verifyContext:R})}catch(p){this.client.logger.error(p);const y=a.params.requester.publicKey,A=await this.client.core.crypto.generateKeyPair(),R=this.getAppLinkIfEnabled(a.params.requester.metadata,b),O={type:ds,receiverPublicKey:y,senderPublicKey:A};await this.sendError({id:a.id,topic:n,error:p,encodeOpts:O,rpcOpts:wr.wc_sessionAuthenticate.autoReject,appLink:R})}},this.addSessionRequestToSessionRequestQueue=t=>{this.sessionRequestQueue.queue.push(t)},this.cleanupAfterResponse=t=>{this.deletePendingSessionRequest(t.response.id,{message:"fulfilled",code:0}),setTimeout(()=>{this.sessionRequestQueue.state=En.idle,this.processSessionRequestQueue()},xe.toMiliseconds(this.requestQueueDelay))},this.cleanupPendingSentRequestsForTopic=({topic:t,error:i})=>{const n=this.client.core.history.pending;n.length>0&&n.filter(a=>a.topic===t&&a.request.method==="wc_sessionRequest").forEach(a=>{const f=a.request.id,u=St("session_request",f);if(this.events.listenerCount(u)===0)throw new Error(`emitting ${u} without any listeners`);this.events.emit(St("session_request",a.request.id),{error:i})})},this.processSessionRequestQueue=()=>{if(this.sessionRequestQueue.state===En.active){this.client.logger.info("session request queue is already active.");return}const t=this.sessionRequestQueue.queue[0];if(!t){this.client.logger.info("session request queue is empty.");return}try{this.sessionRequestQueue.state=En.active,this.emitSessionRequest(t)}catch(i){this.client.logger.error(i)}},this.emitSessionRequest=t=>{this.client.events.emit("session_request",t)},this.onPairingCreated=t=>{if(t.methods&&this.expectedPairingMethodMap.set(t.topic,t.methods),t.active)return;const i=this.client.proposal.getAll().find(n=>n.pairingTopic===t.topic);i&&this.onSessionProposeRequest({topic:t.topic,payload:qs("wc_sessionPropose",{requiredNamespaces:i.requiredNamespaces,optionalNamespaces:i.optionalNamespaces,relays:i.relays,proposer:i.proposer,sessionProperties:i.sessionProperties},i.id)})},this.isValidConnect=async t=>{if(!oi(t)){const{message:b}=Ae("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(t)}`);throw new Error(b)}const{pairingTopic:i,requiredNamespaces:n,optionalNamespaces:a,sessionProperties:f,relays:u}=t;if(fi(i)||await this.isValidPairingTopic(i),!tI(u)){const{message:b}=Ae("MISSING_OR_INVALID",`connect() relays: ${u}`);throw new Error(b)}!fi(n)&&bc(n)!==0&&this.validateNamespaces(n,"requiredNamespaces"),!fi(a)&&bc(a)!==0&&this.validateNamespaces(a,"optionalNamespaces"),fi(f)||this.validateSessionProps(f,"sessionProperties")},this.validateNamespaces=(t,i)=>{const n=eI(t,"connect()",i);if(n)throw new Error(n.message)},this.isValidApprove=async t=>{if(!oi(t))throw new Error(Ae("MISSING_OR_INVALID",`approve() params: ${t}`).message);const{id:i,namespaces:n,relayProtocol:a,sessionProperties:f}=t;this.checkRecentlyDeleted(i),await this.isValidProposalId(i);const u=this.client.proposal.get(i),b=Cl(n,"approve()");if(b)throw new Error(b.message);const p=xg(u.requiredNamespaces,n,"approve()");if(p)throw new Error(p.message);if(!fr(a,!0)){const{message:y}=Ae("MISSING_OR_INVALID",`approve() relayProtocol: ${a}`);throw new Error(y)}fi(f)||this.validateSessionProps(f,"sessionProperties")},this.isValidReject=async t=>{if(!oi(t)){const{message:a}=Ae("MISSING_OR_INVALID",`reject() params: ${t}`);throw new Error(a)}const{id:i,reason:n}=t;if(this.checkRecentlyDeleted(i),await this.isValidProposalId(i),!iI(n)){const{message:a}=Ae("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(n)}`);throw new Error(a)}},this.isValidSessionSettleRequest=t=>{if(!oi(t)){const{message:p}=Ae("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${t}`);throw new Error(p)}const{relay:i,controller:n,namespaces:a,expiry:f}=t;if(!S2(i)){const{message:p}=Ae("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(p)}const u=WS(n,"onSessionSettleRequest()");if(u)throw new Error(u.message);const b=Cl(a,"onSessionSettleRequest()");if(b)throw new Error(b.message);if(Rs(f)){const{message:p}=Ae("EXPIRED","onSessionSettleRequest()");throw new Error(p)}},this.isValidUpdate=async t=>{if(!oi(t)){const{message:b}=Ae("MISSING_OR_INVALID",`update() params: ${t}`);throw new Error(b)}const{topic:i,namespaces:n}=t;this.checkRecentlyDeleted(i),await this.isValidSessionTopic(i);const a=this.client.session.get(i),f=Cl(n,"update()");if(f)throw new Error(f.message);const u=xg(a.requiredNamespaces,n,"update()");if(u)throw new Error(u.message)},this.isValidExtend=async t=>{if(!oi(t)){const{message:n}=Ae("MISSING_OR_INVALID",`extend() params: ${t}`);throw new Error(n)}const{topic:i}=t;this.checkRecentlyDeleted(i),await this.isValidSessionTopic(i)},this.isValidRequest=async t=>{if(!oi(t)){const{message:b}=Ae("MISSING_OR_INVALID",`request() params: ${t}`);throw new Error(b)}const{topic:i,request:n,chainId:a,expiry:f}=t;this.checkRecentlyDeleted(i),await this.isValidSessionTopic(i);const{namespaces:u}=this.client.session.get(i);if(!Eg(u,a)){const{message:b}=Ae("MISSING_OR_INVALID",`request() chainId: ${a}`);throw new Error(b)}if(!nI(n)){const{message:b}=Ae("MISSING_OR_INVALID",`request() ${JSON.stringify(n)}`);throw new Error(b)}if(!oI(u,a,n.method)){const{message:b}=Ae("MISSING_OR_INVALID",`request() method: ${n.method}`);throw new Error(b)}if(f&&!uI(f,$l)){const{message:b}=Ae("MISSING_OR_INVALID",`request() expiry: ${f}. Expiry must be a number (in seconds) between ${$l.min} and ${$l.max}`);throw new Error(b)}},this.isValidRespond=async t=>{var i;if(!oi(t)){const{message:f}=Ae("MISSING_OR_INVALID",`respond() params: ${t}`);throw new Error(f)}const{topic:n,response:a}=t;try{await this.isValidSessionTopic(n)}catch(f){throw(i=t==null?void 0:t.response)!=null&&i.id&&this.cleanupAfterResponse(t),f}if(!sI(a)){const{message:f}=Ae("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(a)}`);throw new Error(f)}},this.isValidPing=async t=>{if(!oi(t)){const{message:n}=Ae("MISSING_OR_INVALID",`ping() params: ${t}`);throw new Error(n)}const{topic:i}=t;await this.isValidSessionOrPairingTopic(i)},this.isValidEmit=async t=>{if(!oi(t)){const{message:u}=Ae("MISSING_OR_INVALID",`emit() params: ${t}`);throw new Error(u)}const{topic:i,event:n,chainId:a}=t;await this.isValidSessionTopic(i);const{namespaces:f}=this.client.session.get(i);if(!Eg(f,a)){const{message:u}=Ae("MISSING_OR_INVALID",`emit() chainId: ${a}`);throw new Error(u)}if(!aI(n)){const{message:u}=Ae("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(n)}`);throw new Error(u)}if(!cI(f,a,n.name)){const{message:u}=Ae("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(n)}`);throw new Error(u)}},this.isValidDisconnect=async t=>{if(!oi(t)){const{message:n}=Ae("MISSING_OR_INVALID",`disconnect() params: ${t}`);throw new Error(n)}const{topic:i}=t;await this.isValidSessionOrPairingTopic(i)},this.isValidAuthenticate=t=>{const{chains:i,uri:n,domain:a,nonce:f}=t;if(!Array.isArray(i)||i.length===0)throw new Error("chains is required and must be a non-empty array");if(!fr(n,!1))throw new Error("uri is required parameter");if(!fr(a,!1))throw new Error("domain is required parameter");if(!fr(f,!1))throw new Error("nonce is required parameter");if([...new Set(i.map(b=>ac(b).namespace))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");const{namespace:u}=ac(i[0]);if(u!=="eip155")throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")},this.getVerifyContext=async t=>{const{attestationId:i,hash:n,encryptedId:a,metadata:f,transportType:u}=t,b={verified:{verifyUrl:f.verifyUrl||uc,validation:"UNKNOWN",origin:f.url||""}};try{if(u===Kt.link_mode){const y=this.getAppLinkIfEnabled(f,u);return b.verified.validation=y&&new URL(y).origin===new URL(f.url).origin?"VALID":"INVALID",b}const p=await this.client.core.verify.resolve({attestationId:i,hash:n,encryptedId:a,verifyUrl:f.verifyUrl});p&&(b.verified.origin=p.origin,b.verified.isScam=p.isScam,b.verified.validation=p.origin===new URL(f.url).origin?"VALID":"INVALID")}catch(p){this.client.logger.warn(p)}return this.client.logger.debug(`Verify context: ${JSON.stringify(b)}`),b},this.validateSessionProps=(t,i)=>{Object.values(t).forEach(n=>{if(!fr(n,!1)){const{message:a}=Ae("MISSING_OR_INVALID",`${i} must be in Record format. Received: ${JSON.stringify(n)}`);throw new Error(a)}})},this.getPendingAuthRequest=t=>{const i=this.client.auth.requests.get(t);return typeof i=="object"?i:void 0},this.addToRecentlyDeleted=(t,i)=>{if(this.recentlyDeletedMap.set(t,i),this.recentlyDeletedMap.size>=this.recentlyDeletedLimit){let n=0;const a=this.recentlyDeletedLimit/2;for(const f of this.recentlyDeletedMap.keys()){if(n++>=a)break;this.recentlyDeletedMap.delete(f)}}},this.checkRecentlyDeleted=t=>{const i=this.recentlyDeletedMap.get(t);if(i){const{message:n}=Ae("MISSING_OR_INVALID",`Record was recently deleted - ${i}: ${t}`);throw new Error(n)}},this.isLinkModeEnabled=(t,i)=>{var n,a,f,u,b,p,y,A,R;return!t||i!==Kt.link_mode?!1:((a=(n=this.client.metadata)==null?void 0:n.redirect)==null?void 0:a.linkMode)===!0&&((u=(f=this.client.metadata)==null?void 0:f.redirect)==null?void 0:u.universal)!==void 0&&((p=(b=this.client.metadata)==null?void 0:b.redirect)==null?void 0:p.universal)!==""&&((y=t==null?void 0:t.redirect)==null?void 0:y.universal)!==void 0&&((A=t==null?void 0:t.redirect)==null?void 0:A.universal)!==""&&((R=t==null?void 0:t.redirect)==null?void 0:R.linkMode)===!0&&this.client.core.linkModeSupportedApps.includes(t.redirect.universal)&&typeof(global==null?void 0:global.Linking)<"u"},this.getAppLinkIfEnabled=(t,i)=>{var n;return this.isLinkModeEnabled(t,i)?(n=t==null?void 0:t.redirect)==null?void 0:n.universal:void 0},this.handleLinkModeMessage=({url:t})=>{if(!t||!t.includes("wc_ev")||!t.includes("topic"))return;const i=q1(t,"topic")||"",n=decodeURIComponent(q1(t,"wc_ev")||""),a=this.client.session.keys.includes(i);a&&this.client.session.update(i,{transportType:Kt.link_mode}),this.client.core.dispatchEnvelope({topic:i,message:n,sessionExists:a})},this.registerLinkModeListeners=async()=>{var t;if(z0()||vo()&&(t=this.client.metadata.redirect)!=null&&t.linkMode){const i=global==null?void 0:global.Linking;if(typeof i<"u"){i.addEventListener("url",this.handleLinkModeMessage,this.client.name);const n=await i.getInitialURL();n&&setTimeout(()=>{this.handleLinkModeMessage({url:n})},50)}}}}isInitialized(){if(!this.initialized){const{message:e}=Ae("NOT_INITIALIZED",this.name);throw new Error(e)}}async confirmOnlineStateOrThrow(){await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(Gr.message,e=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(e):this.onRelayMessage(e)})}async onRelayMessage(e){const{topic:t,message:i,attestation:n,transportType:a}=e,{publicKey:f}=this.client.auth.authKeys.keys.includes(sh)?this.client.auth.authKeys.get(sh):{responseTopic:void 0,publicKey:void 0},u=await this.client.core.crypto.decode(t,i,{receiverPublicKey:f,encoding:a===Kt.link_mode?Yo:Bs});try{Z0(u)?(this.client.core.history.set(t,u),this.onRelayEventRequest({topic:t,payload:u,attestation:n,transportType:a,encryptedId:fs(i)})):Gh(u)?(await this.client.core.history.resolve(u),await this.onRelayEventResponse({topic:t,payload:u,transportType:a}),this.client.core.history.delete(t,u.id)):this.onRelayEventUnknownPayload({topic:t,payload:u,transportType:a})}catch(b){this.client.logger.error(b)}}registerExpirerEvents(){this.client.core.expirer.on(Li.expired,async e=>{const{topic:t,id:i}=Db(e.target);if(i&&this.client.pendingRequest.keys.includes(i))return await this.deletePendingSessionRequest(i,Ae("EXPIRED"),!0);if(i&&this.client.auth.requests.keys.includes(i))return await this.deletePendingAuthRequest(i,Ae("EXPIRED"),!0);t?this.client.session.keys.includes(t)&&(await this.deleteSession({topic:t,expirerHasDeleted:!0}),this.client.events.emit("session_expire",{topic:t})):i&&(await this.deleteProposal(i,!0),this.client.events.emit("proposal_expire",{id:i}))})}registerPairingEvents(){this.client.core.pairing.events.on(ca.create,e=>this.onPairingCreated(e)),this.client.core.pairing.events.on(ca.delete,e=>{this.addToRecentlyDeleted(e.topic,"pairing")})}isValidPairingTopic(e){if(!fr(e,!1)){const{message:t}=Ae("MISSING_OR_INVALID",`pairing topic should be a string: ${e}`);throw new Error(t)}if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:t}=Ae("NO_MATCHING_KEY",`pairing topic doesn't exist: ${e}`);throw new Error(t)}if(Rs(this.client.core.pairing.pairings.get(e).expiry)){const{message:t}=Ae("EXPIRED",`pairing topic: ${e}`);throw new Error(t)}}async isValidSessionTopic(e){if(!fr(e,!1)){const{message:t}=Ae("MISSING_OR_INVALID",`session topic should be a string: ${e}`);throw new Error(t)}if(this.checkRecentlyDeleted(e),!this.client.session.keys.includes(e)){const{message:t}=Ae("NO_MATCHING_KEY",`session topic doesn't exist: ${e}`);throw new Error(t)}if(Rs(this.client.session.get(e).expiry)){await this.deleteSession({topic:e});const{message:t}=Ae("EXPIRED",`session topic: ${e}`);throw new Error(t)}if(!this.client.core.crypto.keychain.has(e)){const{message:t}=Ae("MISSING_OR_INVALID",`session topic does not exist in keychain: ${e}`);throw await this.deleteSession({topic:e}),new Error(t)}}async isValidSessionOrPairingTopic(e){if(this.checkRecentlyDeleted(e),this.client.session.keys.includes(e))await this.isValidSessionTopic(e);else if(this.client.core.pairing.pairings.keys.includes(e))this.isValidPairingTopic(e);else if(fr(e,!1)){const{message:t}=Ae("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${e}`);throw new Error(t)}else{const{message:t}=Ae("MISSING_OR_INVALID",`session or pairing topic should be a string: ${e}`);throw new Error(t)}}async isValidProposalId(e){if(!rI(e)){const{message:t}=Ae("MISSING_OR_INVALID",`proposal id should be a number: ${e}`);throw new Error(t)}if(!this.client.proposal.keys.includes(e)){const{message:t}=Ae("NO_MATCHING_KEY",`proposal id doesn't exist: ${e}`);throw new Error(t)}if(Rs(this.client.proposal.get(e).expiryTimestamp)){await this.deleteProposal(e);const{message:t}=Ae("EXPIRED",`proposal id: ${e}`);throw new Error(t)}}}class BN extends xa{constructor(e,t){super(e,t,wN,rd),this.core=e,this.logger=t}}class qN extends xa{constructor(e,t){super(e,t,_N,rd),this.core=e,this.logger=t}}class LN extends xa{constructor(e,t){super(e,t,EN,rd,i=>i.id),this.core=e,this.logger=t}}class UN extends xa{constructor(e,t){super(e,t,MN,Jh,()=>sh),this.core=e,this.logger=t}}class $N extends xa{constructor(e,t){super(e,t,PN,Jh),this.core=e,this.logger=t}}class zN extends xa{constructor(e,t){super(e,t,ON,Jh,i=>i.id),this.core=e,this.logger=t}}class jN{constructor(e,t){this.core=e,this.logger=t,this.authKeys=new UN(this.core,this.logger),this.pairingTopics=new $N(this.core,this.logger),this.requests=new zN(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}class id extends FM{constructor(e){super(e),this.protocol=tm,this.version=rm,this.name=Ul.name,this.events=new Hi.EventEmitter,this.on=(i,n)=>this.events.on(i,n),this.once=(i,n)=>this.events.once(i,n),this.off=(i,n)=>this.events.off(i,n),this.removeListener=(i,n)=>this.events.removeListener(i,n),this.removeAllListeners=i=>this.events.removeAllListeners(i),this.connect=async i=>{try{return await this.engine.connect(i)}catch(n){throw this.logger.error(n.message),n}},this.pair=async i=>{try{return await this.engine.pair(i)}catch(n){throw this.logger.error(n.message),n}},this.approve=async i=>{try{return await this.engine.approve(i)}catch(n){throw this.logger.error(n.message),n}},this.reject=async i=>{try{return await this.engine.reject(i)}catch(n){throw this.logger.error(n.message),n}},this.update=async i=>{try{return await this.engine.update(i)}catch(n){throw this.logger.error(n.message),n}},this.extend=async i=>{try{return await this.engine.extend(i)}catch(n){throw this.logger.error(n.message),n}},this.request=async i=>{try{return await this.engine.request(i)}catch(n){throw this.logger.error(n.message),n}},this.respond=async i=>{try{return await this.engine.respond(i)}catch(n){throw this.logger.error(n.message),n}},this.ping=async i=>{try{return await this.engine.ping(i)}catch(n){throw this.logger.error(n.message),n}},this.emit=async i=>{try{return await this.engine.emit(i)}catch(n){throw this.logger.error(n.message),n}},this.disconnect=async i=>{try{return await this.engine.disconnect(i)}catch(n){throw this.logger.error(n.message),n}},this.find=i=>{try{return this.engine.find(i)}catch(n){throw this.logger.error(n.message),n}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(i){throw this.logger.error(i.message),i}},this.authenticate=async(i,n)=>{try{return await this.engine.authenticate(i,n)}catch(a){throw this.logger.error(a.message),a}},this.formatAuthMessage=i=>{try{return this.engine.formatAuthMessage(i)}catch(n){throw this.logger.error(n.message),n}},this.approveSessionAuthenticate=async i=>{try{return await this.engine.approveSessionAuthenticate(i)}catch(n){throw this.logger.error(n.message),n}},this.rejectSessionAuthenticate=async i=>{try{return await this.engine.rejectSessionAuthenticate(i)}catch(n){throw this.logger.error(n.message),n}},this.name=(e==null?void 0:e.name)||Ul.name,this.metadata=(e==null?void 0:e.metadata)||Ob(),this.signConfig=e==null?void 0:e.signConfig;const t=typeof(e==null?void 0:e.logger)<"u"&&typeof(e==null?void 0:e.logger)!="string"?e.logger:Nc(Hh({level:(e==null?void 0:e.logger)||Ul.logger}));this.core=(e==null?void 0:e.core)||new yN(e),this.logger=Yr(t,this.name),this.session=new qN(this.core,this.logger),this.proposal=new BN(this.core,this.logger),this.pendingRequest=new LN(this.core,this.logger),this.engine=new FN(this),this.auth=new jN(this.core,this.logger)}static async init(e){const t=new id(e);return await t.initialize(),t}get context(){return di(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.auth.init(),await this.engine.init(),this.logger.info("SignClient Initialization Success"),this.engine.processRelayMessageCache()}catch(e){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(e.message),e}}}var _0={exports:{}};(function(r,e){var t=typeof self<"u"?self:ji,i=function(){function a(){this.fetch=!1,this.DOMException=t.DOMException}return a.prototype=t,new a}();(function(a){(function(f){var u={searchParams:"URLSearchParams"in a,iterable:"Symbol"in a&&"iterator"in Symbol,blob:"FileReader"in a&&"Blob"in a&&function(){try{return new Blob,!0}catch{return!1}}(),formData:"FormData"in a,arrayBuffer:"ArrayBuffer"in a};function b(h){return h&&DataView.prototype.isPrototypeOf(h)}if(u.arrayBuffer)var p=["[object Int8Array]","[object Uint8Array]","[object Uint8ClampedArray]","[object Int16Array]","[object Uint16Array]","[object Int32Array]","[object Uint32Array]","[object Float32Array]","[object Float64Array]"],y=ArrayBuffer.isView||function(h){return h&&p.indexOf(Object.prototype.toString.call(h))>-1};function A(h){if(typeof h!="string"&&(h=String(h)),/[^a-z0-9\-#$%&'*+.^_`|~]/i.test(h))throw new TypeError("Invalid character in header field name");return h.toLowerCase()}function R(h){return typeof h!="string"&&(h=String(h)),h}function O(h){var v={next:function(){var _=h.shift();return{done:_===void 0,value:_}}};return u.iterable&&(v[Symbol.iterator]=function(){return v}),v}function N(h){this.map={},h instanceof N?h.forEach(function(v,_){this.append(_,v)},this):Array.isArray(h)?h.forEach(function(v){this.append(v[0],v[1])},this):h&&Object.getOwnPropertyNames(h).forEach(function(v){this.append(v,h[v])},this)}N.prototype.append=function(h,v){h=A(h),v=R(v);var _=this.map[h];this.map[h]=_?_+", "+v:v},N.prototype.delete=function(h){delete this.map[A(h)]},N.prototype.get=function(h){return h=A(h),this.has(h)?this.map[h]:null},N.prototype.has=function(h){return this.map.hasOwnProperty(A(h))},N.prototype.set=function(h,v){this.map[A(h)]=R(v)},N.prototype.forEach=function(h,v){for(var _ in this.map)this.map.hasOwnProperty(_)&&h.call(v,this.map[_],_,this)},N.prototype.keys=function(){var h=[];return this.forEach(function(v,_){h.push(_)}),O(h)},N.prototype.values=function(){var h=[];return this.forEach(function(v){h.push(v)}),O(h)},N.prototype.entries=function(){var h=[];return this.forEach(function(v,_){h.push([_,v])}),O(h)},u.iterable&&(N.prototype[Symbol.iterator]=N.prototype.entries);function K(h){if(h.bodyUsed)return Promise.reject(new TypeError("Already read"));h.bodyUsed=!0}function W(h){return new Promise(function(v,_){h.onload=function(){v(h.result)},h.onerror=function(){_(h.error)}})}function Q(h){var v=new FileReader,_=W(v);return v.readAsArrayBuffer(h),_}function j(h){var v=new FileReader,_=W(v);return v.readAsText(h),_}function Y(h){for(var v=new Uint8Array(h),_=new Array(v.length),I=0;I-1?v:h}function B(h,v){v=v||{};var _=v.body;if(h instanceof B){if(h.bodyUsed)throw new TypeError("Already read");this.url=h.url,this.credentials=h.credentials,v.headers||(this.headers=new N(h.headers)),this.method=h.method,this.mode=h.mode,this.signal=h.signal,!_&&h._bodyInit!=null&&(_=h._bodyInit,h.bodyUsed=!0)}else this.url=String(h);if(this.credentials=v.credentials||this.credentials||"same-origin",(v.headers||!this.headers)&&(this.headers=new N(v.headers)),this.method=x(v.method||this.method||"GET"),this.mode=v.mode||this.mode||null,this.signal=v.signal||this.signal,this.referrer=null,(this.method==="GET"||this.method==="HEAD")&&_)throw new TypeError("Body not allowed for GET or HEAD requests");this._initBody(_)}B.prototype.clone=function(){return new B(this,{body:this._bodyInit})};function ae(h){var v=new FormData;return h.trim().split("&").forEach(function(_){if(_){var I=_.split("="),M=I.shift().replace(/\+/g," "),S=I.join("=").replace(/\+/g," ");v.append(decodeURIComponent(M),decodeURIComponent(S))}}),v}function le(h){var v=new N,_=h.replace(/\r?\n[\t ]+/g," ");return _.split(/\r?\n/).forEach(function(I){var M=I.split(":"),S=M.shift().trim();if(S){var d=M.join(":").trim();v.append(S,d)}}),v}k.call(B.prototype);function F(h,v){v||(v={}),this.type="default",this.status=v.status===void 0?200:v.status,this.ok=this.status>=200&&this.status<300,this.statusText="statusText"in v?v.statusText:"OK",this.headers=new N(v.headers),this.url=v.url||"",this._initBody(h)}k.call(F.prototype),F.prototype.clone=function(){return new F(this._bodyInit,{status:this.status,statusText:this.statusText,headers:new N(this.headers),url:this.url})},F.error=function(){var h=new F(null,{status:0,statusText:""});return h.type="error",h};var m=[301,302,303,307,308];F.redirect=function(h,v){if(m.indexOf(v)===-1)throw new RangeError("Invalid status code");return new F(null,{status:v,headers:{location:h}})},f.DOMException=a.DOMException;try{new f.DOMException}catch{f.DOMException=function(v,_){this.message=v,this.name=_;var I=Error(v);this.stack=I.stack},f.DOMException.prototype=Object.create(Error.prototype),f.DOMException.prototype.constructor=f.DOMException}function c(h,v){return new Promise(function(_,I){var M=new B(h,v);if(M.signal&&M.signal.aborted)return I(new f.DOMException("Aborted","AbortError"));var S=new XMLHttpRequest;function d(){S.abort()}S.onload=function(){var g={status:S.status,statusText:S.statusText,headers:le(S.getAllResponseHeaders()||"")};g.url="responseURL"in S?S.responseURL:g.headers.get("X-Request-URL");var T="response"in S?S.response:S.responseText;_(new F(T,g))},S.onerror=function(){I(new TypeError("Network request failed"))},S.ontimeout=function(){I(new TypeError("Network request failed"))},S.onabort=function(){I(new f.DOMException("Aborted","AbortError"))},S.open(M.method,M.url,!0),M.credentials==="include"?S.withCredentials=!0:M.credentials==="omit"&&(S.withCredentials=!1),"responseType"in S&&u.blob&&(S.responseType="blob"),M.headers.forEach(function(g,T){S.setRequestHeader(T,g)}),M.signal&&(M.signal.addEventListener("abort",d),S.onreadystatechange=function(){S.readyState===4&&M.signal.removeEventListener("abort",d)}),S.send(typeof M._bodyInit>"u"?null:M._bodyInit)})}return c.polyfill=!0,a.fetch||(a.fetch=c,a.Headers=N,a.Request=B,a.Response=F),f.Headers=N,f.Request=B,f.Response=F,f.fetch=c,Object.defineProperty(f,"__esModule",{value:!0}),f})({})})(i),i.fetch.ponyfill=!0,delete i.fetch.polyfill;var n=i;e=n.fetch,e.default=n.fetch,e.fetch=n.fetch,e.Headers=n.Headers,e.Request=n.Request,e.Response=n.Response,r.exports=e})(_0,_0.exports);var kN=_0.exports;const lv=S0(kN);var HN=Object.defineProperty,KN=Object.defineProperties,VN=Object.getOwnPropertyDescriptors,dv=Object.getOwnPropertySymbols,GN=Object.prototype.hasOwnProperty,WN=Object.prototype.propertyIsEnumerable,pv=(r,e,t)=>e in r?HN(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,gv=(r,e)=>{for(var t in e||(e={}))GN.call(e,t)&&pv(r,t,e[t]);if(dv)for(var t of dv(e))WN.call(e,t)&&pv(r,t,e[t]);return r},vv=(r,e)=>KN(r,VN(e));const JN={Accept:"application/json","Content-Type":"application/json"},YN="POST",bv={headers:JN,method:YN},mv=10;class Gn{constructor(e,t=!1){if(this.url=e,this.disableProviderPing=t,this.events=new Hi.EventEmitter,this.isAvailable=!1,this.registering=!1,!Ug(e))throw new Error(`Provided URL is not compatible with HTTP connection: ${e}`);this.url=e,this.disableProviderPing=t}get connected(){return this.isAvailable}get connecting(){return this.registering}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}off(e,t){this.events.off(e,t)}removeListener(e,t){this.events.removeListener(e,t)}async open(e=this.url){await this.register(e)}async close(){if(!this.isAvailable)throw new Error("Connection already closed");this.onClose()}async send(e){this.isAvailable||await this.register();try{const t=vs(e),i=await(await lv(this.url,vv(gv({},bv),{body:t}))).json();this.onPayload({data:i})}catch(t){this.onError(e.id,t)}}async register(e=this.url){if(!Ug(e))throw new Error(`Provided URL is not compatible with HTTP connection: ${e}`);if(this.registering){const t=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=t||this.events.listenerCount("open")>=t)&&this.events.setMaxListeners(t+1),new Promise((i,n)=>{this.events.once("register_error",a=>{this.resetMaxListeners(),n(a)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.isAvailable>"u")return n(new Error("HTTP connection is missing or invalid"));i()})})}this.url=e,this.registering=!0;try{if(!this.disableProviderPing){const t=vs({id:1,jsonrpc:"2.0",method:"test",params:[]});await lv(e,vv(gv({},bv),{body:t}))}this.onOpen()}catch(t){const i=this.parseError(t);throw this.events.emit("register_error",i),this.onClose(),i}}onOpen(){this.isAvailable=!0,this.registering=!1,this.events.emit("open")}onClose(){this.isAvailable=!1,this.registering=!1,this.events.emit("close")}onPayload(e){if(typeof e.data>"u")return;const t=typeof e.data=="string"?ga(e.data):e.data;this.events.emit("payload",t)}onError(e,t){const i=this.parseError(t),n=i.message||i.toString(),a=Vh(e,n);this.events.emit("payload",a)}parseError(e,t=this.url){return D2(e,t,"HTTP")}resetMaxListeners(){this.events.getMaxListeners()>mv&&this.events.setMaxListeners(mv)}}const yv="error",QN="wss://relay.walletconnect.org",XN="wc",ZN="universal_provider",wv=`${XN}@2:${ZN}:`,sm="https://rpc.walletconnect.org/v1/",Ya="generic",eC=`${sm}bundler`,vn={DEFAULT_CHAIN_CHANGED:"default_chain_changed"};var rc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},A0={exports:{}};/** * @license * Lodash * Copyright OpenJS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors */(function(r,e){(function(){var t,i="4.17.21",n=200,a="Unsupported core-js use. Try https://npms.io/search?q=ponyfill.",f="Expected a function",u="Invalid `variable` option passed into `_.template`",b="__lodash_hash_undefined__",p=500,y="__lodash_placeholder__",A=1,R=2,O=4,N=1,K=2,W=1,Q=2,j=4,Y=8,U=16,k=32,G=64,x=128,B=256,ae=512,le=30,F="...",m=800,c=16,h=1,v=2,_=3,I=1/0,M=9007199254740991,S=17976931348623157e292,d=NaN,g=4294967295,T=g-1,Z=g>>>1,se=[["ary",x],["bind",W],["bindKey",Q],["curry",Y],["curryRight",U],["flip",ae],["partial",k],["partialRight",G],["rearg",B]],P="[object Arguments]",ee="[object Array]",q="[object AsyncFunction]",z="[object Boolean]",H="[object Date]",w="[object DOMException]",$="[object Error]",ne="[object Function]",ce="[object GeneratorFunction]",he="[object Map]",ye="[object Number]",we="[object Null]",Ce="[object Object]",Qe="[object Promise]",Oe="[object Proxy]",Te="[object RegExp]",Ie="[object Set]",me="[object String]",Re="[object Symbol]",De="[object Undefined]",ve="[object WeakMap]",Ne="[object WeakSet]",Se="[object ArrayBuffer]",be="[object DataView]",Le="[object Float32Array]",Me="[object Float64Array]",_e="[object Int8Array]",He="[object Int16Array]",Ve="[object Int32Array]",Ee="[object Uint8Array]",Ke="[object Uint8ClampedArray]",ut="[object Uint16Array]",Ge="[object Uint32Array]",_t=/\b__p \+= '';/g,lt=/\b(__p \+=) '' \+/g,Je=/(__e\(.*?\)|\b__t\)) \+\n'';/g,Et=/&(?:amp|lt|gt|quot|#39);/g,It=/[&<>"']/g,Fe=RegExp(Et.source),Xe=RegExp(It.source),tt=/<%-([\s\S]+?)%>/g,Be=/<%([\s\S]+?)%>/g,et=/<%=([\s\S]+?)%>/g,Ze=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,$e=/^\w*$/,ft=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,rt=/[\\^$.*+?()[\]{}|]/g,ze=RegExp(rt.source),it=/^\s+/,st=/\s/,qe=/\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,Ye=/\{\n\/\* \[wrapped with (.+)\] \*/,ht=/,? & /,je=/[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g,Tt=/[()=,{}\[\]\/\s]/,Dt=/\\(\\)?/g,at=/\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g,bt=/\w*$/,Cr=/^[-+]0x[0-9a-f]+$/i,Tr=/^0b[01]+$/i,Dr=/^\[object .+?Constructor\]$/,Fr=/^0o[0-7]+$/i,Br=/^(?:0|[1-9]\d*)$/,er=/[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g,Qr=/($^)/,Gi=/['\n\r\u2028\u2029\\]/g,Xr="\\ud800-\\udfff",Wi="\\u0300-\\u036f",Ji="\\ufe20-\\ufe2f",Zr="\\u20d0-\\u20ff",Si=Wi+Ji+Zr,Ii="\\u2700-\\u27bf",lr="a-z\\xdf-\\xf6\\xf8-\\xff",Yi="\\xac\\xb1\\xd7\\xf7",Qi="\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf",Xi="\\u2000-\\u206f",js=" \\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",Dc="A-Z\\xc0-\\xd6\\xd8-\\xde",Fc="\\ufe0e\\ufe0f",ks=Yi+Qi+Xi+js,xo="['’]",Hs="["+Xr+"]",So="["+ks+"]",Ks="["+Si+"]",Bc="\\d+",Yh="["+Ii+"]",qc="["+lr+"]",Lc="[^"+Xr+ks+Bc+Ii+lr+Dc+"]",Ma="\\ud83c[\\udffb-\\udfff]",Qh="(?:"+Ks+"|"+Ma+")",Uc="[^"+Xr+"]",Pa="(?:\\ud83c[\\udde6-\\uddff]){2}",ms="[\\ud800-\\udbff][\\udc00-\\udfff]",pi="["+Dc+"]",$c="\\u200d",zc="(?:"+qc+"|"+Lc+")",bn="(?:"+pi+"|"+Lc+")",jc="(?:"+xo+"(?:d|ll|m|re|s|t|ve))?",kc="(?:"+xo+"(?:D|LL|M|RE|S|T|VE))?",Hc=Qh+"?",Kc="["+Fc+"]?",Xh="(?:"+$c+"(?:"+[Uc,Pa,ms].join("|")+")"+Kc+Hc+")*",Wn="\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])",Vc="\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])",Gc=Kc+Hc+Xh,Oa="(?:"+[Yh,Pa,ms].join("|")+")"+Gc,Zh="(?:"+[Uc+Ks+"?",Ks,Pa,ms,Hs].join("|")+")",Io=RegExp(xo,"g"),eu=RegExp(Ks,"g"),Ra=RegExp(Ma+"(?="+Ma+")|"+Zh+Gc,"g"),Wc=RegExp([pi+"?"+qc+"+"+jc+"(?="+[So,pi,"$"].join("|")+")",bn+"+"+kc+"(?="+[So,pi+zc,"$"].join("|")+")",pi+"?"+zc+"+"+jc,pi+"+"+kc,Vc,Wn,Bc,Oa].join("|"),"g"),Jc=RegExp("["+$c+Xr+Si+Fc+"]"),Vs=/[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/,Yc=["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"],tu=-1,zt={};zt[Le]=zt[Me]=zt[_e]=zt[He]=zt[Ve]=zt[Ee]=zt[Ke]=zt[ut]=zt[Ge]=!0,zt[P]=zt[ee]=zt[Se]=zt[z]=zt[be]=zt[H]=zt[$]=zt[ne]=zt[he]=zt[ye]=zt[Ce]=zt[Te]=zt[Ie]=zt[me]=zt[ve]=!1;var $t={};$t[P]=$t[ee]=$t[Se]=$t[be]=$t[z]=$t[H]=$t[Le]=$t[Me]=$t[_e]=$t[He]=$t[Ve]=$t[he]=$t[ye]=$t[Ce]=$t[Te]=$t[Ie]=$t[me]=$t[Re]=$t[Ee]=$t[Ke]=$t[ut]=$t[Ge]=!0,$t[$]=$t[ne]=$t[ve]=!1;var V={À:"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"},te={"&":"&","<":"<",">":">",'"':""","'":"'"},pe={"&":"&","<":"<",">":">",""":'"',"'":"'"},Ue={"\\":"\\","'":"'","\n":"n","\r":"r","\u2028":"u2028","\u2029":"u2029"},jt=parseFloat,pt=parseInt,Jt=typeof rc=="object"&&rc&&rc.Object===Object&&rc,hr=typeof self=="object"&&self&&self.Object===Object&&self,Nt=Jt||hr||Function("return this")(),kt=e&&!e.nodeType&&e,sr=kt&&!0&&r&&!r.nodeType&&r,ei=sr&&sr.exports===kt,ur=ei&&Jt.process,Yt=function(){try{var re=sr&&sr.require&&sr.require("util").types;return re||ur&&ur.binding&&ur.binding("util")}catch{}}(),jr=Yt&&Yt.isArrayBuffer,Zi=Yt&&Yt.isDate,Mi=Yt&&Yt.isMap,mn=Yt&&Yt.isRegExp,Mo=Yt&&Yt.isSet,Gs=Yt&&Yt.isTypedArray;function br(re,fe,oe){switch(oe.length){case 0:return re.call(fe);case 1:return re.call(fe,oe[0]);case 2:return re.call(fe,oe[0],oe[1]);case 3:return re.call(fe,oe[0],oe[1],oe[2])}return re.apply(fe,oe)}function cm(re,fe,oe,ke){for(var dt=-1,Ft=re==null?0:re.length;++dt-1}function ru(re,fe,oe){for(var ke=-1,dt=re==null?0:re.length;++ke-1;);return oe}function dd(re,fe){for(var oe=re.length;oe--&&Na(fe,re[oe],0)>-1;);return oe}function bm(re,fe){for(var oe=re.length,ke=0;oe--;)re[oe]===fe&&++ke;return ke}var mm=au(V),ym=au(te);function wm(re){return"\\"+Ue[re]}function _m(re,fe){return re==null?t:re[fe]}function Ca(re){return Jc.test(re)}function Am(re){return Vs.test(re)}function Em(re){for(var fe,oe=[];!(fe=re.next()).done;)oe.push(fe.value);return oe}function hu(re){var fe=-1,oe=Array(re.size);return re.forEach(function(ke,dt){oe[++fe]=[dt,ke]}),oe}function pd(re,fe){return function(oe){return re(fe(oe))}}function _s(re,fe){for(var oe=-1,ke=re.length,dt=0,Ft=[];++oe-1}function h6(s,o){var l=this.__data__,E=gf(l,s);return E<0?(++this.size,l.push([s,o])):l[E][1]=o,this}Jn.prototype.clear=a6,Jn.prototype.delete=o6,Jn.prototype.get=c6,Jn.prototype.has=f6,Jn.prototype.set=h6;function Yn(s){var o=-1,l=s==null?0:s.length;for(this.clear();++o=o?s:o)),s}function Ni(s,o,l,E,C,L){var J,X=o&A,ie=o&R,ue=o&O;if(l&&(J=C?l(s,E,C,L):l(s)),J!==t)return J;if(!Zt(s))return s;var de=gt(s);if(de){if(J=py(s),!X)return ti(s,J)}else{var ge=Lr(s),Pe=ge==ne||ge==ce;if(Ms(s))return Yd(s,X);if(ge==Ce||ge==P||Pe&&!C){if(J=ie||Pe?{}:gp(s),!X)return ie?iy(s,I6(J,s)):ry(s,Id(J,s))}else{if(!$t[ge])return C?s:{};J=gy(s,ge,X)}}L||(L=new tn);var We=L.get(s);if(We)return We;L.set(s,J),Hp(s)?s.forEach(function(ct){J.add(Ni(ct,o,l,ct,s,L))}):jp(s)&&s.forEach(function(ct,xt){J.set(xt,Ni(ct,o,l,xt,s,L))});var ot=ue?ie?Bu:Fu:ie?ii:mr,wt=de?t:ot(s);return Pi(wt||s,function(ct,xt){wt&&(xt=ct,ct=s[xt]),Do(J,xt,Ni(ct,o,l,xt,s,L))}),J}function M6(s){var o=mr(s);return function(l){return Md(l,s,o)}}function Md(s,o,l){var E=l.length;if(s==null)return!E;for(s=Ht(s);E--;){var C=l[E],L=o[C],J=s[C];if(J===t&&!(C in s)||!L(J))return!1}return!0}function Pd(s,o,l){if(typeof s!="function")throw new Oi(f);return zo(function(){s.apply(t,l)},o)}function Fo(s,o,l,E){var C=-1,L=Qc,J=!0,X=s.length,ie=[],ue=o.length;if(!X)return ie;l&&(o=Xt(o,gi(l))),E?(L=ru,J=!1):o.length>=n&&(L=Po,J=!1,o=new Ys(o));e:for(;++CC?0:C+l),E=E===t||E>C?C:yt(E),E<0&&(E+=C),E=l>E?0:Vp(E);l0&&l(X)?o>1?Mr(X,o-1,l,E,C):ws(C,X):E||(C[C.length]=X)}return C}var bu=rp(),Nd=rp(!0);function yn(s,o){return s&&bu(s,o,mr)}function mu(s,o){return s&&Nd(s,o,mr)}function bf(s,o){return ys(o,function(l){return ts(s[l])})}function Xs(s,o){o=Ss(o,s);for(var l=0,E=o.length;s!=null&&lo}function R6(s,o){return s!=null&&Lt.call(s,o)}function N6(s,o){return s!=null&&o in Ht(s)}function C6(s,o,l){return s>=qr(o,l)&&s=120&&de.length>=120)?new Ys(J&&de):t}de=s[0];var ge=-1,Pe=X[0];e:for(;++ge-1;)X!==s&&cf.call(X,ie,1),cf.call(s,ie,1);return s}function jd(s,o){for(var l=s?o.length:0,E=l-1;l--;){var C=o[l];if(l==E||C!==L){var L=C;es(C)?cf.call(s,C,1):Pu(s,C)}}return s}function Su(s,o){return s+uf(Ad()*(o-s+1))}function K6(s,o,l,E){for(var C=-1,L=pr(hf((o-s)/(l||1)),0),J=oe(L);L--;)J[E?L:++C]=s,s+=l;return J}function Iu(s,o){var l="";if(!s||o<1||o>M)return l;do o%2&&(l+=s),o=uf(o/2),o&&(s+=s);while(o);return l}function At(s,o){return ku(mp(s,o,ni),s+"")}function V6(s){return Sd(ka(s))}function G6(s,o){var l=ka(s);return Pf(l,Qs(o,0,l.length))}function Lo(s,o,l,E){if(!Zt(s))return s;o=Ss(o,s);for(var C=-1,L=o.length,J=L-1,X=s;X!=null&&++CC?0:C+o),l=l>C?C:l,l<0&&(l+=C),C=o>l?0:l-o>>>0,o>>>=0;for(var L=oe(C);++E>>1,J=s[L];J!==null&&!bi(J)&&(l?J<=o:J=n){var ue=o?null:oy(s);if(ue)return Zc(ue);J=!1,C=Po,ie=new Ys}else ie=o?[]:X;e:for(;++E=E?s:Ci(s,o,l)}var Jd=Lm||function(s){return Nt.clearTimeout(s)};function Yd(s,o){if(o)return s.slice();var l=s.length,E=bd?bd(l):new s.constructor(l);return s.copy(E),E}function Cu(s){var o=new s.constructor(s.byteLength);return new af(o).set(new af(s)),o}function X6(s,o){var l=o?Cu(s.buffer):s.buffer;return new s.constructor(l,s.byteOffset,s.byteLength)}function Z6(s){var o=new s.constructor(s.source,bt.exec(s));return o.lastIndex=s.lastIndex,o}function ey(s){return To?Ht(To.call(s)):{}}function Qd(s,o){var l=o?Cu(s.buffer):s.buffer;return new s.constructor(l,s.byteOffset,s.length)}function Xd(s,o){if(s!==o){var l=s!==t,E=s===null,C=s===s,L=bi(s),J=o!==t,X=o===null,ie=o===o,ue=bi(o);if(!X&&!ue&&!L&&s>o||L&&J&&ie&&!X&&!ue||E&&J&&ie||!l&&ie||!C)return 1;if(!E&&!L&&!ue&&s=X)return ie;var ue=l[E];return ie*(ue=="desc"?-1:1)}}return s.index-o.index}function Zd(s,o,l,E){for(var C=-1,L=s.length,J=l.length,X=-1,ie=o.length,ue=pr(L-J,0),de=oe(ie+ue),ge=!E;++X1?l[C-1]:t,J=C>2?l[2]:t;for(L=s.length>3&&typeof L=="function"?(C--,L):t,J&&Hr(l[0],l[1],J)&&(L=C<3?t:L,C=1),o=Ht(o);++E-1?C[L?o[J]:J]:t}}function sp(s){return Zn(function(o){var l=o.length,E=l,C=Ri.prototype.thru;for(s&&o.reverse();E--;){var L=o[E];if(typeof L!="function")throw new Oi(f);if(C&&!J&&If(L)=="wrapper")var J=new Ri([],!0)}for(E=J?E:l;++E1&&Ct.reverse(),de&&ieX))return!1;var ue=L.get(s),de=L.get(o);if(ue&&de)return ue==o&&de==s;var ge=-1,Pe=!0,We=l&K?new Ys:t;for(L.set(s,o),L.set(o,s);++ge1?"& ":"")+o[E],o=o.join(l>2?", ":" "),s.replace(qe,`{ /* [wrapped with `+o+`] */ `)}function by(s){return gt(s)||ta(s)||!!(wd&&s&&s[wd])}function es(s,o){var l=typeof s;return o=o??M,!!o&&(l=="number"||l!="symbol"&&Br.test(s))&&s>-1&&s%1==0&&s0){if(++o>=m)return arguments[0]}else o=0;return s.apply(t,arguments)}}function Pf(s,o){var l=-1,E=s.length,C=E-1;for(o=o===t?E:o;++l1?s[o-1]:t;return l=typeof l=="function"?(s.pop(),l):t,Rp(s,l)});function Np(s){var o=D(s);return o.__chain__=!0,o}function P3(s,o){return o(s),s}function Of(s,o){return o(s)}var O3=Zn(function(s){var o=s.length,l=o?s[0]:0,E=this.__wrapped__,C=function(L){return vu(L,s)};return o>1||this.__actions__.length||!(E instanceof Mt)||!es(l)?this.thru(C):(E=E.slice(l,+l+(o?1:0)),E.__actions__.push({func:Of,args:[C],thisArg:t}),new Ri(E,this.__chain__).thru(function(L){return o&&!L.length&&L.push(t),L}))});function R3(){return Np(this)}function N3(){return new Ri(this.value(),this.__chain__)}function C3(){this.__values__===t&&(this.__values__=Kp(this.value()));var s=this.__index__>=this.__values__.length,o=s?t:this.__values__[this.__index__++];return{done:s,value:o}}function T3(){return this}function D3(s){for(var o,l=this;l instanceof pf;){var E=xp(l);E.__index__=0,E.__values__=t,o?C.__wrapped__=E:o=E;var C=E;l=l.__wrapped__}return C.__wrapped__=s,o}function F3(){var s=this.__wrapped__;if(s instanceof Mt){var o=s;return this.__actions__.length&&(o=new Mt(this)),o=o.reverse(),o.__actions__.push({func:Of,args:[Hu],thisArg:t}),new Ri(o,this.__chain__)}return this.thru(Hu)}function B3(){return Gd(this.__wrapped__,this.__actions__)}var q3=_f(function(s,o,l){Lt.call(s,l)?++s[l]:Qn(s,l,1)});function L3(s,o,l){var E=gt(s)?ad:P6;return l&&Hr(s,o,l)&&(o=t),E(s,nt(o,3))}function U3(s,o){var l=gt(s)?ys:Rd;return l(s,nt(o,3))}var $3=np(Sp),z3=np(Ip);function j3(s,o){return Mr(Rf(s,o),1)}function k3(s,o){return Mr(Rf(s,o),I)}function H3(s,o,l){return l=l===t?1:yt(l),Mr(Rf(s,o),l)}function Cp(s,o){var l=gt(s)?Pi:Es;return l(s,nt(o,3))}function Tp(s,o){var l=gt(s)?fm:Od;return l(s,nt(o,3))}var K3=_f(function(s,o,l){Lt.call(s,l)?s[l].push(o):Qn(s,l,[o])});function V3(s,o,l,E){s=ri(s)?s:ka(s),l=l&&!E?yt(l):0;var C=s.length;return l<0&&(l=pr(C+l,0)),Ff(s)?l<=C&&s.indexOf(o,l)>-1:!!C&&Na(s,o,l)>-1}var G3=At(function(s,o,l){var E=-1,C=typeof o=="function",L=ri(s)?oe(s.length):[];return Es(s,function(J){L[++E]=C?br(o,J,l):Bo(J,o,l)}),L}),W3=_f(function(s,o,l){Qn(s,l,o)});function Rf(s,o){var l=gt(s)?Xt:Bd;return l(s,nt(o,3))}function J3(s,o,l,E){return s==null?[]:(gt(o)||(o=o==null?[]:[o]),l=E?t:l,gt(l)||(l=l==null?[]:[l]),$d(s,o,l))}var Y3=_f(function(s,o,l){s[l?0:1].push(o)},function(){return[[],[]]});function Q3(s,o,l){var E=gt(s)?iu:hd,C=arguments.length<3;return E(s,nt(o,4),l,C,Es)}function X3(s,o,l){var E=gt(s)?hm:hd,C=arguments.length<3;return E(s,nt(o,4),l,C,Od)}function Z3(s,o){var l=gt(s)?ys:Rd;return l(s,Tf(nt(o,3)))}function ew(s){var o=gt(s)?Sd:V6;return o(s)}function tw(s,o,l){(l?Hr(s,o,l):o===t)?o=1:o=yt(o);var E=gt(s)?E6:G6;return E(s,o)}function rw(s){var o=gt(s)?x6:J6;return o(s)}function iw(s){if(s==null)return 0;if(ri(s))return Ff(s)?Ta(s):s.length;var o=Lr(s);return o==he||o==Ie?s.size:Au(s).length}function nw(s,o,l){var E=gt(s)?nu:Y6;return l&&Hr(s,o,l)&&(o=t),E(s,nt(o,3))}var sw=At(function(s,o){if(s==null)return[];var l=o.length;return l>1&&Hr(s,o[0],o[1])?o=[]:l>2&&Hr(o[0],o[1],o[2])&&(o=[o[0]]),$d(s,Mr(o,1),[])}),Nf=Um||function(){return Nt.Date.now()};function aw(s,o){if(typeof o!="function")throw new Oi(f);return s=yt(s),function(){if(--s<1)return o.apply(this,arguments)}}function Dp(s,o,l){return o=l?t:o,o=s&&o==null?s.length:o,Xn(s,x,t,t,t,t,o)}function Fp(s,o){var l;if(typeof o!="function")throw new Oi(f);return s=yt(s),function(){return--s>0&&(l=o.apply(this,arguments)),s<=1&&(o=t),l}}var Vu=At(function(s,o,l){var E=W;if(l.length){var C=_s(l,za(Vu));E|=k}return Xn(s,E,o,l,C)}),Bp=At(function(s,o,l){var E=W|Q;if(l.length){var C=_s(l,za(Bp));E|=k}return Xn(o,E,s,l,C)});function qp(s,o,l){o=l?t:o;var E=Xn(s,Y,t,t,t,t,t,o);return E.placeholder=qp.placeholder,E}function Lp(s,o,l){o=l?t:o;var E=Xn(s,U,t,t,t,t,t,o);return E.placeholder=Lp.placeholder,E}function Up(s,o,l){var E,C,L,J,X,ie,ue=0,de=!1,ge=!1,Pe=!0;if(typeof s!="function")throw new Oi(f);o=Di(o)||0,Zt(l)&&(de=!!l.leading,ge="maxWait"in l,L=ge?pr(Di(l.maxWait)||0,o):L,Pe="trailing"in l?!!l.trailing:Pe);function We(or){var nn=E,is=C;return E=C=t,ue=or,J=s.apply(is,nn),J}function ot(or){return ue=or,X=zo(xt,o),de?We(or):J}function wt(or){var nn=or-ie,is=or-ue,n1=o-nn;return ge?qr(n1,L-is):n1}function ct(or){var nn=or-ie,is=or-ue;return ie===t||nn>=o||nn<0||ge&&is>=L}function xt(){var or=Nf();if(ct(or))return Ct(or);X=zo(xt,wt(or))}function Ct(or){return X=t,Pe&&E?We(or):(E=C=t,J)}function mi(){X!==t&&Jd(X),ue=0,E=ie=C=X=t}function Kr(){return X===t?J:Ct(Nf())}function yi(){var or=Nf(),nn=ct(or);if(E=arguments,C=this,ie=or,nn){if(X===t)return ot(ie);if(ge)return Jd(X),X=zo(xt,o),We(ie)}return X===t&&(X=zo(xt,o)),J}return yi.cancel=mi,yi.flush=Kr,yi}var ow=At(function(s,o){return Pd(s,1,o)}),cw=At(function(s,o,l){return Pd(s,Di(o)||0,l)});function fw(s){return Xn(s,ae)}function Cf(s,o){if(typeof s!="function"||o!=null&&typeof o!="function")throw new Oi(f);var l=function(){var E=arguments,C=o?o.apply(this,E):E[0],L=l.cache;if(L.has(C))return L.get(C);var J=s.apply(this,E);return l.cache=L.set(C,J)||L,J};return l.cache=new(Cf.Cache||Yn),l}Cf.Cache=Yn;function Tf(s){if(typeof s!="function")throw new Oi(f);return function(){var o=arguments;switch(o.length){case 0:return!s.call(this);case 1:return!s.call(this,o[0]);case 2:return!s.call(this,o[0],o[1]);case 3:return!s.call(this,o[0],o[1],o[2])}return!s.apply(this,o)}}function hw(s){return Fp(2,s)}var uw=Q6(function(s,o){o=o.length==1&>(o[0])?Xt(o[0],gi(nt())):Xt(Mr(o,1),gi(nt()));var l=o.length;return At(function(E){for(var C=-1,L=qr(E.length,l);++C=o}),ta=Td(function(){return arguments}())?Td:function(s){return tr(s)&&Lt.call(s,"callee")&&!yd.call(s,"callee")},gt=oe.isArray,Iw=jr?gi(jr):D6;function ri(s){return s!=null&&Df(s.length)&&!ts(s)}function ar(s){return tr(s)&&ri(s)}function Mw(s){return s===!0||s===!1||tr(s)&&kr(s)==z}var Ms=zm||nl,Pw=Zi?gi(Zi):F6;function Ow(s){return tr(s)&&s.nodeType===1&&!jo(s)}function Rw(s){if(s==null)return!0;if(ri(s)&&(gt(s)||typeof s=="string"||typeof s.splice=="function"||Ms(s)||ja(s)||ta(s)))return!s.length;var o=Lr(s);if(o==he||o==Ie)return!s.size;if($o(s))return!Au(s).length;for(var l in s)if(Lt.call(s,l))return!1;return!0}function Nw(s,o){return qo(s,o)}function Cw(s,o,l){l=typeof l=="function"?l:t;var E=l?l(s,o):t;return E===t?qo(s,o,t,l):!!E}function Wu(s){if(!tr(s))return!1;var o=kr(s);return o==$||o==w||typeof s.message=="string"&&typeof s.name=="string"&&!jo(s)}function Tw(s){return typeof s=="number"&&_d(s)}function ts(s){if(!Zt(s))return!1;var o=kr(s);return o==ne||o==ce||o==q||o==Oe}function zp(s){return typeof s=="number"&&s==yt(s)}function Df(s){return typeof s=="number"&&s>-1&&s%1==0&&s<=M}function Zt(s){var o=typeof s;return s!=null&&(o=="object"||o=="function")}function tr(s){return s!=null&&typeof s=="object"}var jp=Mi?gi(Mi):q6;function Dw(s,o){return s===o||_u(s,o,Lu(o))}function Fw(s,o,l){return l=typeof l=="function"?l:t,_u(s,o,Lu(o),l)}function Bw(s){return kp(s)&&s!=+s}function qw(s){if(wy(s))throw new dt(a);return Dd(s)}function Lw(s){return s===null}function Uw(s){return s==null}function kp(s){return typeof s=="number"||tr(s)&&kr(s)==ye}function jo(s){if(!tr(s)||kr(s)!=Ce)return!1;var o=of(s);if(o===null)return!0;var l=Lt.call(o,"constructor")&&o.constructor;return typeof l=="function"&&l instanceof l&&rf.call(l)==Fm}var Ju=mn?gi(mn):L6;function $w(s){return zp(s)&&s>=-M&&s<=M}var Hp=Mo?gi(Mo):U6;function Ff(s){return typeof s=="string"||!gt(s)&&tr(s)&&kr(s)==me}function bi(s){return typeof s=="symbol"||tr(s)&&kr(s)==Re}var ja=Gs?gi(Gs):$6;function zw(s){return s===t}function jw(s){return tr(s)&&Lr(s)==ve}function kw(s){return tr(s)&&kr(s)==Ne}var Hw=Sf(Eu),Kw=Sf(function(s,o){return s<=o});function Kp(s){if(!s)return[];if(ri(s))return Ff(s)?en(s):ti(s);if(Oo&&s[Oo])return Em(s[Oo]());var o=Lr(s),l=o==he?hu:o==Ie?Zc:ka;return l(s)}function rs(s){if(!s)return s===0?s:0;if(s=Di(s),s===I||s===-I){var o=s<0?-1:1;return o*S}return s===s?s:0}function yt(s){var o=rs(s),l=o%1;return o===o?l?o-l:o:0}function Vp(s){return s?Qs(yt(s),0,g):0}function Di(s){if(typeof s=="number")return s;if(bi(s))return d;if(Zt(s)){var o=typeof s.valueOf=="function"?s.valueOf():s;s=Zt(o)?o+"":o}if(typeof s!="string")return s===0?s:+s;s=ud(s);var l=Tr.test(s);return l||Fr.test(s)?pt(s.slice(2),l?2:8):Cr.test(s)?d:+s}function Gp(s){return wn(s,ii(s))}function Vw(s){return s?Qs(yt(s),-M,M):s===0?s:0}function Bt(s){return s==null?"":vi(s)}var Gw=Ua(function(s,o){if($o(o)||ri(o)){wn(o,mr(o),s);return}for(var l in o)Lt.call(o,l)&&Do(s,l,o[l])}),Wp=Ua(function(s,o){wn(o,ii(o),s)}),Bf=Ua(function(s,o,l,E){wn(o,ii(o),s,E)}),Ww=Ua(function(s,o,l,E){wn(o,mr(o),s,E)}),Jw=Zn(vu);function Yw(s,o){var l=La(s);return o==null?l:Id(l,o)}var Qw=At(function(s,o){s=Ht(s);var l=-1,E=o.length,C=E>2?o[2]:t;for(C&&Hr(o[0],o[1],C)&&(E=1);++l1),L}),wn(s,Bu(s),l),E&&(l=Ni(l,A|R|O,cy));for(var C=o.length;C--;)Pu(l,o[C]);return l});function g5(s,o){return Yp(s,Tf(nt(o)))}var v5=Zn(function(s,o){return s==null?{}:k6(s,o)});function Yp(s,o){if(s==null)return{};var l=Xt(Bu(s),function(E){return[E]});return o=nt(o),zd(s,l,function(E,C){return o(E,C[0])})}function b5(s,o,l){o=Ss(o,s);var E=-1,C=o.length;for(C||(C=1,s=t);++Eo){var E=s;s=o,o=E}if(l||s%1||o%1){var C=Ad();return qr(s+C*(o-s+jt("1e-"+((C+"").length-1))),o)}return Su(s,o)}var P5=$a(function(s,o,l){return o=o.toLowerCase(),s+(l?Zp(o):o)});function Zp(s){return Xu(Bt(s).toLowerCase())}function e1(s){return s=Bt(s),s&&s.replace(er,mm).replace(eu,"")}function O5(s,o,l){s=Bt(s),o=vi(o);var E=s.length;l=l===t?E:Qs(yt(l),0,E);var C=l;return l-=o.length,l>=0&&s.slice(l,C)==o}function R5(s){return s=Bt(s),s&&Xe.test(s)?s.replace(It,ym):s}function N5(s){return s=Bt(s),s&&ze.test(s)?s.replace(rt,"\\$&"):s}var C5=$a(function(s,o,l){return s+(l?"-":"")+o.toLowerCase()}),T5=$a(function(s,o,l){return s+(l?" ":"")+o.toLowerCase()}),D5=ip("toLowerCase");function F5(s,o,l){s=Bt(s),o=yt(o);var E=o?Ta(s):0;if(!o||E>=o)return s;var C=(o-E)/2;return xf(uf(C),l)+s+xf(hf(C),l)}function B5(s,o,l){s=Bt(s),o=yt(o);var E=o?Ta(s):0;return o&&E>>0,l?(s=Bt(s),s&&(typeof o=="string"||o!=null&&!Ju(o))&&(o=vi(o),!o&&Ca(s))?Is(en(s),0,l):s.split(o,l)):[]}var k5=$a(function(s,o,l){return s+(l?" ":"")+Xu(o)});function H5(s,o,l){return s=Bt(s),l=l==null?0:Qs(yt(l),0,s.length),o=vi(o),s.slice(l,l+o.length)==o}function K5(s,o,l){var E=D.templateSettings;l&&Hr(s,o,l)&&(o=t),s=Bt(s),o=Bf({},o,E,hp);var C=Bf({},o.imports,E.imports,hp),L=mr(C),J=fu(C,L),X,ie,ue=0,de=o.interpolate||Qr,ge="__p += '",Pe=uu((o.escape||Qr).source+"|"+de.source+"|"+(de===et?at:Qr).source+"|"+(o.evaluate||Qr).source+"|$","g"),We="//# sourceURL="+(Lt.call(o,"sourceURL")?(o.sourceURL+"").replace(/\s/g," "):"lodash.templateSources["+ ++tu+"]")+` `;s.replace(Pe,function(ct,xt,Ct,mi,Kr,yi){return Ct||(Ct=mi),ge+=s.slice(ue,yi).replace(Gi,wm),xt&&(X=!0,ge+=`' + __e(`+xt+`) + '`),Kr&&(ie=!0,ge+=`'; `+Kr+`; __p += '`),Ct&&(ge+=`' + ((__t = (`+Ct+`)) == null ? '' : __t) + '`),ue=yi+ct.length,ct}),ge+=`'; `;var ot=Lt.call(o,"variable")&&o.variable;if(!ot)ge=`with (obj) { `+ge+` } `;else if(Tt.test(ot))throw new dt(u);ge=(ie?ge.replace(_t,""):ge).replace(lt,"$1").replace(Je,"$1;"),ge="function("+(ot||"obj")+`) { `+(ot?"":`obj || (obj = {}); `)+"var __t, __p = ''"+(X?", __e = _.escape":"")+(ie?`, __j = Array.prototype.join; function print() { __p += __j.call(arguments, '') } `:`; `)+ge+`return __p }`;var wt=r1(function(){return Ft(L,We+"return "+ge).apply(t,J)});if(wt.source=ge,Wu(wt))throw wt;return wt}function V5(s){return Bt(s).toLowerCase()}function G5(s){return Bt(s).toUpperCase()}function W5(s,o,l){if(s=Bt(s),s&&(l||o===t))return ud(s);if(!s||!(o=vi(o)))return s;var E=en(s),C=en(o),L=ld(E,C),J=dd(E,C)+1;return Is(E,L,J).join("")}function J5(s,o,l){if(s=Bt(s),s&&(l||o===t))return s.slice(0,gd(s)+1);if(!s||!(o=vi(o)))return s;var E=en(s),C=dd(E,en(o))+1;return Is(E,0,C).join("")}function Y5(s,o,l){if(s=Bt(s),s&&(l||o===t))return s.replace(it,"");if(!s||!(o=vi(o)))return s;var E=en(s),C=ld(E,en(o));return Is(E,C).join("")}function Q5(s,o){var l=le,E=F;if(Zt(o)){var C="separator"in o?o.separator:C;l="length"in o?yt(o.length):l,E="omission"in o?vi(o.omission):E}s=Bt(s);var L=s.length;if(Ca(s)){var J=en(s);L=J.length}if(l>=L)return s;var X=l-Ta(E);if(X<1)return E;var ie=J?Is(J,0,X).join(""):s.slice(0,X);if(C===t)return ie+E;if(J&&(X+=ie.length-X),Ju(C)){if(s.slice(X).search(C)){var ue,de=ie;for(C.global||(C=uu(C.source,Bt(bt.exec(C))+"g")),C.lastIndex=0;ue=C.exec(de);)var ge=ue.index;ie=ie.slice(0,ge===t?X:ge)}}else if(s.indexOf(vi(C),X)!=X){var Pe=ie.lastIndexOf(C);Pe>-1&&(ie=ie.slice(0,Pe))}return ie+E}function X5(s){return s=Bt(s),s&&Fe.test(s)?s.replace(Et,Mm):s}var Z5=$a(function(s,o,l){return s+(l?" ":"")+o.toUpperCase()}),Xu=ip("toUpperCase");function t1(s,o,l){return s=Bt(s),o=l?t:o,o===t?Am(s)?Rm(s):dm(s):s.match(o)||[]}var r1=At(function(s,o){try{return br(s,t,o)}catch(l){return Wu(l)?l:new dt(l)}}),e4=Zn(function(s,o){return Pi(o,function(l){l=_n(l),Qn(s,l,Vu(s[l],s))}),s});function t4(s){var o=s==null?0:s.length,l=nt();return s=o?Xt(s,function(E){if(typeof E[1]!="function")throw new Oi(f);return[l(E[0]),E[1]]}):[],At(function(E){for(var C=-1;++CM)return[];var l=g,E=qr(s,g);o=nt(o),s-=g;for(var C=cu(E,o);++l0||o<0)?new Mt(l):(s<0?l=l.takeRight(-s):s&&(l=l.drop(s)),o!==t&&(o=yt(o),l=o<0?l.dropRight(-o):l.take(o-s)),l)},Mt.prototype.takeRightWhile=function(s){return this.reverse().takeWhile(s).reverse()},Mt.prototype.toArray=function(){return this.take(g)},yn(Mt.prototype,function(s,o){var l=/^(?:filter|find|map|reject)|While$/.test(o),E=/^(?:head|last)$/.test(o),C=D[E?"take"+(o=="last"?"Right":""):o],L=E||/^find/.test(o);C&&(D.prototype[o]=function(){var J=this.__wrapped__,X=E?[1]:arguments,ie=J instanceof Mt,ue=X[0],de=ie||gt(J),ge=function(xt){var Ct=C.apply(D,ws([xt],X));return E&&Pe?Ct[0]:Ct};de&&l&&typeof ue=="function"&&ue.length!=1&&(ie=de=!1);var Pe=this.__chain__,We=!!this.__actions__.length,ot=L&&!Pe,wt=ie&&!We;if(!L&&de){J=wt?J:new Mt(this);var ct=s.apply(J,X);return ct.__actions__.push({func:Of,args:[ge],thisArg:t}),new Ri(ct,Pe)}return ot&&wt?s.apply(this,X):(ct=this.thru(ge),ot?E?ct.value()[0]:ct.value():ct)})}),Pi(["pop","push","shift","sort","splice","unshift"],function(s){var o=ef[s],l=/^(?:push|sort|unshift)$/.test(s)?"tap":"thru",E=/^(?:pop|shift)$/.test(s);D.prototype[s]=function(){var C=arguments;if(E&&!this.__chain__){var L=this.value();return o.apply(gt(L)?L:[],C)}return this[l](function(J){return o.apply(gt(J)?J:[],C)})}}),yn(Mt.prototype,function(s,o){var l=D[o];if(l){var E=l.name+"";Lt.call(qa,E)||(qa[E]=[]),qa[E].push({name:o,func:l})}}),qa[Af(t,Q).name]=[{name:"wrapper",func:t}],Mt.prototype.clone=Xm,Mt.prototype.reverse=Zm,Mt.prototype.value=e6,D.prototype.at=O3,D.prototype.chain=R3,D.prototype.commit=N3,D.prototype.next=C3,D.prototype.plant=D3,D.prototype.reverse=F3,D.prototype.toJSON=D.prototype.valueOf=D.prototype.value=B3,D.prototype.first=D.prototype.head,Oo&&(D.prototype[Oo]=T3),D},Da=Nm();sr?((sr.exports=Da)._=Da,kt._=Da):Nt._=Da}).call(rc)})(A0,A0.exports);var tC=Object.defineProperty,rC=Object.defineProperties,iC=Object.getOwnPropertyDescriptors,_v=Object.getOwnPropertySymbols,nC=Object.prototype.hasOwnProperty,sC=Object.prototype.propertyIsEnumerable,Av=(r,e,t)=>e in r?tC(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Gf=(r,e)=>{for(var t in e||(e={}))nC.call(e,t)&&Av(r,t,e[t]);if(_v)for(var t of _v(e))sC.call(e,t)&&Av(r,t,e[t]);return r},aC=(r,e)=>rC(r,iC(e));function pn(r,e,t){var i;const n=ac(r);return((i=e.rpcMap)==null?void 0:i[n.reference])||`${sm}?chainId=${n.namespace}:${n.reference}&projectId=${t}`}function Ia(r){return r.includes(":")?r.split(":")[1]:r}function am(r){return r.map(e=>`${e.split(":")[0]}:${e.split(":")[1]}`)}function oC(r,e){const t=Object.keys(e.namespaces).filter(n=>n.includes(r));if(!t.length)return[];const i=[];return t.forEach(n=>{const a=e.namespaces[n].accounts;i.push(...a)}),i}function zl(r={},e={}){const t=Ev(r),i=Ev(e);return A0.exports.merge(t,i)}function Ev(r){var e,t,i,n;const a={};if(!bc(r))return a;for(const[f,u]of Object.entries(r)){const b=J0(f)?[f]:u.chains,p=u.methods||[],y=u.events||[],A=u.rpcMap||{},R=sc(f);a[R]=aC(Gf(Gf({},a[R]),u),{chains:Qf(b,(e=a[R])==null?void 0:e.chains),methods:Qf(p,(t=a[R])==null?void 0:t.methods),events:Qf(y,(i=a[R])==null?void 0:i.events),rpcMap:Gf(Gf({},A),(n=a[R])==null?void 0:n.rpcMap)})}return a}function cC(r){return r.includes(":")?r.split(":")[2]:r}function xv(r){const e={};for(const[t,i]of Object.entries(r)){const n=i.methods||[],a=i.events||[],f=i.accounts||[],u=J0(t)?[t]:i.chains?i.chains:am(i.accounts);e[t]={chains:u,methods:n,events:a,accounts:f}}return e}function jl(r){return typeof r=="number"?r:r.includes("0x")?parseInt(r,16):(r=r.includes(":")?r.split(":")[1]:r,isNaN(Number(r))?r:Number(r))}const om={},qt=r=>om[r],kl=(r,e)=>{om[r]=e};class fC{constructor(e){this.name="polkadot",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider().request(e.request)}setDefaultChain(e,t){this.httpProviders[e]||this.setHttpProvider(e,t),this.chainId=e,this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${e}`)}getAccounts(){const e=this.namespace.accounts;return e?e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2])||[]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{var i;const n=Ia(t);e[n]=this.createHttpProvider(n,(i=this.namespace.rpcMap)==null?void 0:i[t])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||pn(e,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);return new gn(new Gn(i,qt("disableProviderPing")))}}var hC=Object.defineProperty,uC=Object.defineProperties,lC=Object.getOwnPropertyDescriptors,Sv=Object.getOwnPropertySymbols,dC=Object.prototype.hasOwnProperty,pC=Object.prototype.propertyIsEnumerable,Iv=(r,e,t)=>e in r?hC(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Mv=(r,e)=>{for(var t in e||(e={}))dC.call(e,t)&&Iv(r,t,e[t]);if(Sv)for(var t of Sv(e))pC.call(e,t)&&Iv(r,t,e[t]);return r},Pv=(r,e)=>uC(r,lC(e));class gC{constructor(e){this.name="eip155",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.httpProviders=this.createHttpProviders(),this.chainId=parseInt(this.getDefaultChain())}async request(e){switch(e.request.method){case"eth_requestAccounts":return this.getAccounts();case"eth_accounts":return this.getAccounts();case"wallet_switchEthereumChain":return await this.handleSwitchChain(e);case"eth_chainId":return parseInt(this.getDefaultChain());case"wallet_getCapabilities":return await this.getCapabilities(e);case"wallet_getCallsStatus":return await this.getCallStatus(e)}return this.namespace.methods.includes(e.request.method)?await this.client.request(e):this.getHttpProvider().request(e.request)}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}setDefaultChain(e,t){this.httpProviders[e]||this.setHttpProvider(parseInt(e),t),this.chainId=parseInt(e),this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${e}`)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId.toString();if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}createHttpProvider(e,t){const i=t||pn(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);return new gn(new Gn(i,qt("disableProviderPing")))}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{var i;const n=parseInt(Ia(t));e[n]=this.createHttpProvider(n,(i=this.namespace.rpcMap)==null?void 0:i[t])}),e}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2]))]:[]}getHttpProvider(){const e=this.chainId,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}async handleSwitchChain(e){var t,i;let n=e.request.params?(t=e.request.params[0])==null?void 0:t.chainId:"0x0";n=n.startsWith("0x")?n:`0x${n}`;const a=parseInt(n,16);if(this.isChainApproved(a))this.setDefaultChain(`${a}`);else if(this.namespace.methods.includes("wallet_switchEthereumChain"))await this.client.request({topic:e.topic,request:{method:e.request.method,params:[{chainId:n}]},chainId:(i=this.namespace.chains)==null?void 0:i[0]}),this.setDefaultChain(`${a}`);else throw new Error(`Failed to switch to chain 'eip155:${a}'. The chain is not approved or the wallet does not support 'wallet_switchEthereumChain' method.`);return null}isChainApproved(e){return this.namespace.chains.includes(`${this.name}:${e}`)}async getCapabilities(e){var t,i,n;const a=(i=(t=e.request)==null?void 0:t.params)==null?void 0:i[0];if(!a)throw new Error("Missing address parameter in `wallet_getCapabilities` request");const f=this.client.session.get(e.topic),u=((n=f==null?void 0:f.sessionProperties)==null?void 0:n.capabilities)||{};if(u!=null&&u[a])return u==null?void 0:u[a];const b=await this.client.request(e);try{await this.client.session.update(e.topic,{sessionProperties:Pv(Mv({},f.sessionProperties||{}),{capabilities:Pv(Mv({},u||{}),{[a]:b})})})}catch(p){console.warn("Failed to update session with capabilities",p)}return b}async getCallStatus(e){var t,i;const n=this.client.session.get(e.topic),a=(t=n.sessionProperties)==null?void 0:t.bundler_name;if(a){const u=this.getBundlerUrl(e.chainId,a);try{return await this.getUserOperationReceipt(u,e)}catch(b){console.warn("Failed to fetch call status from bundler",b,u)}}const f=(i=n.sessionProperties)==null?void 0:i.bundler_url;if(f)try{return await this.getUserOperationReceipt(f,e)}catch(u){console.warn("Failed to fetch call status from custom bundler",u,f)}if(this.namespace.methods.includes(e.request.method))return await this.client.request(e);throw new Error("Fetching call status not approved by the wallet.")}async getUserOperationReceipt(e,t){var i;const n=new URL(e),a=await fetch(n,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(qs("eth_getUserOperationReceipt",[(i=t.request.params)==null?void 0:i[0]]))});if(!a.ok)throw new Error(`Failed to fetch user operation receipt - ${a.status}`);return await a.json()}getBundlerUrl(e,t){return`${eC}?projectId=${this.client.core.projectId}&chainId=${e}&bundler=${t}`}}class vC{constructor(e){this.name="solana",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider().request(e.request)}setDefaultChain(e,t){this.httpProviders[e]||this.setHttpProvider(e,t),this.chainId=e,this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${e}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{var i;const n=Ia(t);e[n]=this.createHttpProvider(n,(i=this.namespace.rpcMap)==null?void 0:i[t])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||pn(e,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);return new gn(new Gn(i,qt("disableProviderPing")))}}class bC{constructor(e){this.name="cosmos",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider().request(e.request)}setDefaultChain(e,t){this.httpProviders[e]||this.setHttpProvider(e,t),this.chainId=e,this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{var i;const n=Ia(t);e[n]=this.createHttpProvider(n,(i=this.namespace.rpcMap)==null?void 0:i[t])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||pn(e,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);return new gn(new Gn(i,qt("disableProviderPing")))}}class mC{constructor(e){this.name="algorand",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider().request(e.request)}setDefaultChain(e,t){if(!this.httpProviders[e]){const i=t||pn(`${this.name}:${e}`,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,i)}this.chainId=e,this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{var i;e[t]=this.createHttpProvider(t,(i=this.namespace.rpcMap)==null?void 0:i[t])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||pn(e,this.namespace,this.client.core.projectId);return typeof i>"u"?void 0:new gn(new Gn(i,qt("disableProviderPing")))}}class yC{constructor(e){this.name="cip34",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider().request(e.request)}setDefaultChain(e,t){this.httpProviders[e]||this.setHttpProvider(e,t),this.chainId=e,this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{const i=this.getCardanoRPCUrl(t),n=Ia(t);e[n]=this.createHttpProvider(n,i)}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}getCardanoRPCUrl(e){const t=this.namespace.rpcMap;if(t)return t[e]}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||this.getCardanoRPCUrl(e);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);return new gn(new Gn(i,qt("disableProviderPing")))}}class wC{constructor(e){this.name="elrond",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider().request(e.request)}setDefaultChain(e,t){this.httpProviders[e]||this.setHttpProvider(e,t),this.chainId=e,this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${e}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{var i;const n=Ia(t);e[n]=this.createHttpProvider(n,(i=this.namespace.rpcMap)==null?void 0:i[t])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||pn(e,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);return new gn(new Gn(i,qt("disableProviderPing")))}}class _C{constructor(e){this.name="multiversx",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider().request(e.request)}setDefaultChain(e,t){this.httpProviders[e]||this.setHttpProvider(e,t),this.chainId=e,this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${e}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2]))]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{var i;const n=Ia(t);e[n]=this.createHttpProvider(n,(i=this.namespace.rpcMap)==null?void 0:i[t])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||pn(e,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);return new gn(new Gn(i,qt("disableProviderPing")))}}class AC{constructor(e){this.name="near",this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace=Object.assign(this.namespace,e)}requestAccounts(){return this.getAccounts()}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider().request(e.request)}setDefaultChain(e,t){if(this.chainId=e,!this.httpProviders[e]){const i=t||pn(`${this.name}:${e}`,this.namespace);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);this.setHttpProvider(e,i)}this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${this.chainId}`)}getAccounts(){const e=this.namespace.accounts;return e?e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2])||[]:[]}createHttpProviders(){const e={};return this.namespace.chains.forEach(t=>{var i;e[t]=this.createHttpProvider(t,(i=this.namespace.rpcMap)==null?void 0:i[t])}),e}getHttpProvider(){const e=`${this.name}:${this.chainId}`,t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||pn(e,this.namespace);return typeof i>"u"?void 0:new gn(new Gn(i,qt("disableProviderPing")))}}class EC{constructor(e){this.name=Ya,this.namespace=e.namespace,this.events=qt("events"),this.client=qt("client"),this.chainId=this.getDefaultChain(),this.httpProviders=this.createHttpProviders()}updateNamespace(e){this.namespace.chains=[...new Set((this.namespace.chains||[]).concat(e.chains||[]))],this.namespace.accounts=[...new Set((this.namespace.accounts||[]).concat(e.accounts||[]))],this.namespace.methods=[...new Set((this.namespace.methods||[]).concat(e.methods||[]))],this.namespace.events=[...new Set((this.namespace.events||[]).concat(e.events||[]))],this.httpProviders=this.createHttpProviders()}requestAccounts(){return this.getAccounts()}request(e){return this.namespace.methods.includes(e.request.method)?this.client.request(e):this.getHttpProvider(e.chainId).request(e.request)}setDefaultChain(e,t){this.httpProviders[e]||this.setHttpProvider(e,t),this.chainId=e,this.events.emit(vn.DEFAULT_CHAIN_CHANGED,`${this.name}:${e}`)}getDefaultChain(){if(this.chainId)return this.chainId;if(this.namespace.defaultChain)return this.namespace.defaultChain;const e=this.namespace.chains[0];if(!e)throw new Error("ChainId not found");return e.split(":")[1]}getAccounts(){const e=this.namespace.accounts;return e?[...new Set(e.filter(t=>t.split(":")[1]===this.chainId.toString()).map(t=>t.split(":")[2]))]:[]}createHttpProviders(){var e,t;const i={};return(t=(e=this.namespace)==null?void 0:e.accounts)==null||t.forEach(n=>{const a=ac(n);i[`${a.namespace}:${a.reference}`]=this.createHttpProvider(n)}),i}getHttpProvider(e){const t=this.httpProviders[e];if(typeof t>"u")throw new Error(`JSON-RPC provider for ${e} not found`);return t}setHttpProvider(e,t){const i=this.createHttpProvider(e,t);i&&(this.httpProviders[e]=i)}createHttpProvider(e,t){const i=t||pn(e,this.namespace,this.client.core.projectId);if(!i)throw new Error(`No RPC url provided for chainId: ${e}`);return new gn(new Gn(i,qt("disableProviderPing")))}}var xC=Object.defineProperty,SC=Object.defineProperties,IC=Object.getOwnPropertyDescriptors,Ov=Object.getOwnPropertySymbols,MC=Object.prototype.hasOwnProperty,PC=Object.prototype.propertyIsEnumerable,Rv=(r,e,t)=>e in r?xC(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Wf=(r,e)=>{for(var t in e||(e={}))MC.call(e,t)&&Rv(r,t,e[t]);if(Ov)for(var t of Ov(e))PC.call(e,t)&&Rv(r,t,e[t]);return r},Hl=(r,e)=>SC(r,IC(e));class nd{constructor(e){this.events=new I0,this.rpcProviders={},this.shouldAbortPairingAttempt=!1,this.maxPairingAttempts=10,this.disableProviderPing=!1,this.providerOpts=e,this.logger=typeof(e==null?void 0:e.logger)<"u"&&typeof(e==null?void 0:e.logger)!="string"?e.logger:Nc(Hh({level:(e==null?void 0:e.logger)||yv})),this.disableProviderPing=(e==null?void 0:e.disableProviderPing)||!1}static async init(e){const t=new nd(e);return await t.initialize(),t}async request(e,t,i){const[n,a]=this.validateChain(t);if(!this.session)throw new Error("Please call connect() before request()");return await this.getProvider(n).request({request:Wf({},e),chainId:`${n}:${a}`,topic:this.session.topic,expiry:i})}sendAsync(e,t,i,n){const a=new Date().getTime();this.request(e,i,n).then(f=>t(null,Kh(a,f))).catch(f=>t(f,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 e;if(!this.session)throw new Error("Please call connect() before enable()");await this.client.disconnect({topic:(e=this.session)==null?void 0:e.topic,reason:Ut("USER_DISCONNECTED")}),await this.cleanup()}async connect(e){if(!this.client)throw new Error("Sign Client not initialized");if(this.setNamespaces(e),await this.cleanupPendingPairings(),!e.skipPairing)return await this.pair(e.pairingTopic)}async authenticate(e,t){if(!this.client)throw new Error("Sign Client not initialized");this.setNamespaces(e),await this.cleanupPendingPairings();const{uri:i,response:n}=await this.client.authenticate(e,t);i&&(this.uri=i,this.events.emit("display_uri",i));const a=await n();if(this.session=a.session,this.session){const f=xv(this.session.namespaces);this.namespaces=zl(this.namespaces,f),this.persist("namespaces",this.namespaces),this.onConnect()}return a}on(e,t){this.events.on(e,t)}once(e,t){this.events.once(e,t)}removeListener(e,t){this.events.removeListener(e,t)}off(e,t){this.events.off(e,t)}get isWalletConnect(){return!0}async pair(e){this.shouldAbortPairingAttempt=!1;let t=0;do{if(this.shouldAbortPairingAttempt)throw new Error("Pairing aborted");if(t>=this.maxPairingAttempts)throw new Error("Max auto pairing attempts reached");const{uri:i,approval:n}=await this.client.connect({pairingTopic:e,requiredNamespaces:this.namespaces,optionalNamespaces:this.optionalNamespaces,sessionProperties:this.sessionProperties});i&&(this.uri=i,this.events.emit("display_uri",i)),await n().then(a=>{this.session=a;const f=xv(a.namespaces);this.namespaces=zl(this.namespaces,f),this.persist("namespaces",this.namespaces)}).catch(a=>{if(a.message!==nm)throw a;t++})}while(!this.session);return this.onConnect(),this.session}setDefaultChain(e,t){try{if(!this.session)return;const[i,n]=this.validateChain(e),a=this.getProvider(i);a.name===Ya?a.setDefaultChain(`${i}:${n}`,t):a.setDefaultChain(n,t)}catch(i){if(!/Please call connect/.test(i.message))throw i}}async cleanupPendingPairings(e={}){this.logger.info("Cleaning up inactive pairings...");const t=this.client.pairing.getAll();if(jn(t)){for(const i of t)e.deletePairings?this.client.core.expirer.set(i.topic,0):await this.client.core.relayer.subscriber.unsubscribe(i.topic);this.logger.info(`Inactive pairings cleared: ${t.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 e=this.client.session.keys.length-1;this.session=this.client.session.get(this.client.session.keys[e]),this.createProviders()}}async initialize(){this.logger.trace("Initialized"),await this.createClient(),await this.checkStorage(),this.registerEventListeners()}async createClient(){this.client=this.providerOpts.client||await id.init({core:this.providerOpts.core,logger:this.providerOpts.logger||yv,relayUrl:this.providerOpts.relayUrl||QN,projectId:this.providerOpts.projectId,metadata:this.providerOpts.metadata,storageOptions:this.providerOpts.storageOptions,storage:this.providerOpts.storage,name:this.providerOpts.name,customStoragePrefix:this.providerOpts.customStoragePrefix,telemetryEnabled:this.providerOpts.telemetryEnabled}),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 e=[...new Set(Object.keys(this.session.namespaces).map(t=>sc(t)))];kl("client",this.client),kl("events",this.events),kl("disableProviderPing",this.disableProviderPing),e.forEach(t=>{if(!this.session)return;const i=oC(t,this.session),n=am(i),a=zl(this.namespaces,this.optionalNamespaces),f=Hl(Wf({},a[t]),{accounts:i,chains:n});switch(t){case"eip155":this.rpcProviders[t]=new gC({namespace:f});break;case"algorand":this.rpcProviders[t]=new mC({namespace:f});break;case"solana":this.rpcProviders[t]=new vC({namespace:f});break;case"cosmos":this.rpcProviders[t]=new bC({namespace:f});break;case"polkadot":this.rpcProviders[t]=new fC({namespace:f});break;case"cip34":this.rpcProviders[t]=new yC({namespace:f});break;case"elrond":this.rpcProviders[t]=new wC({namespace:f});break;case"multiversx":this.rpcProviders[t]=new _C({namespace:f});break;case"near":this.rpcProviders[t]=new AC({namespace:f});break;default:this.rpcProviders[Ya]?this.rpcProviders[Ya].updateNamespace(f):this.rpcProviders[Ya]=new EC({namespace:f})}})}registerEventListeners(){if(typeof this.client>"u")throw new Error("Sign Client is not initialized");this.client.on("session_ping",e=>{this.events.emit("session_ping",e)}),this.client.on("session_event",e=>{const{params:t}=e,{event:i}=t;if(i.name==="accountsChanged"){const n=i.data;n&&jn(n)&&this.events.emit("accountsChanged",n.map(cC))}else if(i.name==="chainChanged"){const n=t.chainId,a=t.event.data,f=sc(n),u=jl(n)!==jl(a)?`${f}:${jl(a)}`:n;this.onChainChanged(u)}else this.events.emit(i.name,i.data);this.events.emit("session_event",e)}),this.client.on("session_update",({topic:e,params:t})=>{var i;const{namespaces:n}=t,a=(i=this.client)==null?void 0:i.session.get(e);this.session=Hl(Wf({},a),{namespaces:n}),this.onSessionUpdate(),this.events.emit("session_update",{topic:e,params:t})}),this.client.on("session_delete",async e=>{await this.cleanup(),this.events.emit("session_delete",e),this.events.emit("disconnect",Hl(Wf({},Ut("USER_DISCONNECTED")),{data:e.topic}))}),this.on(vn.DEFAULT_CHAIN_CHANGED,e=>{this.onChainChanged(e,!0)})}getProvider(e){return this.rpcProviders[e]||this.rpcProviders[Ya]}onSessionUpdate(){Object.keys(this.rpcProviders).forEach(e=>{var t;this.getProvider(e).updateNamespace((t=this.session)==null?void 0:t.namespaces[e])})}setNamespaces(e){const{namespaces:t,optionalNamespaces:i,sessionProperties:n}=e;t&&Object.keys(t).length&&(this.namespaces=t),i&&Object.keys(i).length&&(this.optionalNamespaces=i),this.sessionProperties=n,this.persist("namespaces",t),this.persist("optionalNamespaces",i)}validateChain(e){const[t,i]=(e==null?void 0:e.split(":"))||["",""];if(!this.namespaces||!Object.keys(this.namespaces).length)return[t,i];if(t&&!Object.keys(this.namespaces||{}).map(f=>sc(f)).includes(t))throw new Error(`Namespace '${t}' is not configured. Please call connect() first with namespace config.`);if(t&&i)return[t,i];const n=sc(Object.keys(this.namespaces)[0]),a=this.rpcProviders[n].getDefaultChain();return[n,a]}async requestAccounts(){const[e]=this.validateChain();return await this.getProvider(e).requestAccounts()}onChainChanged(e,t=!1){if(!this.namespaces)return;const[i,n]=this.validateChain(e);n&&(t||this.getProvider(i).setDefaultChain(n),this.namespaces[i]?this.namespaces[i].defaultChain=n:this.namespaces[`${i}:${n}`]?this.namespaces[`${i}:${n}`].defaultChain=n:this.namespaces[`${i}:${n}`]={defaultChain:n},this.persist("namespaces",this.namespaces),this.events.emit("chainChanged",n))}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(e,t){this.client.core.storage.setItem(`${wv}/${e}`,t)}async getFromStore(e){return await this.client.core.storage.getItem(`${wv}/${e}`)}}const OC=nd,RC="wc",NC="ethereum_provider",CC=`${RC}@2:${NC}:`,TC="https://rpc.walletconnect.org/v1/",E0=["eth_sendTransaction","personal_sign"],DC=["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","wallet_sendCalls","wallet_getCapabilities","wallet_getCallsStatus","wallet_showCallsStatus"],x0=["chainChanged","accountsChanged"],FC=["chainChanged","accountsChanged","message","disconnect","connect"];var BC=Object.defineProperty,qC=Object.defineProperties,LC=Object.getOwnPropertyDescriptors,Nv=Object.getOwnPropertySymbols,UC=Object.prototype.hasOwnProperty,$C=Object.prototype.propertyIsEnumerable,Cv=(r,e,t)=>e in r?BC(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Qa=(r,e)=>{for(var t in e||(e={}))UC.call(e,t)&&Cv(r,t,e[t]);if(Nv)for(var t of Nv(e))$C.call(e,t)&&Cv(r,t,e[t]);return r},Kl=(r,e)=>qC(r,LC(e));function Eh(r){return Number(r[0].split(":")[1])}function Jf(r){return`0x${r.toString(16)}`}function zC(r){const{chains:e,optionalChains:t,methods:i,optionalMethods:n,events:a,optionalEvents:f,rpcMap:u}=r;if(!jn(e))throw new Error("Invalid chains");const b={chains:e,methods:i||E0,events:a||x0,rpcMap:Qa({},e.length?{[Eh(e)]:u[Eh(e)]}:{})},p=a==null?void 0:a.filter(O=>!x0.includes(O)),y=i==null?void 0:i.filter(O=>!E0.includes(O));if(!t&&!f&&!n&&!(p!=null&&p.length)&&!(y!=null&&y.length))return{required:e.length?b:void 0};const A=(p==null?void 0:p.length)&&(y==null?void 0:y.length)||!t,R={chains:[...new Set(A?b.chains.concat(t||[]):t)],methods:[...new Set(b.methods.concat(n!=null&&n.length?n:DC))],events:[...new Set(b.events.concat(f!=null&&f.length?f:FC))],rpcMap:u};return{required:e.length?b:void 0,optional:t.length?R:void 0}}class sd{constructor(){this.events=new Hi.EventEmitter,this.namespace="eip155",this.accounts=[],this.chainId=1,this.STORAGE_KEY=CC,this.on=(e,t)=>(this.events.on(e,t),this),this.once=(e,t)=>(this.events.once(e,t),this),this.removeListener=(e,t)=>(this.events.removeListener(e,t),this),this.off=(e,t)=>(this.events.off(e,t),this),this.parseAccount=e=>this.isCompatibleChainId(e)?this.parseAccountId(e).address:e,this.signer={},this.rpc={}}static async init(e){const t=new sd;return await t.initialize(e),t}async request(e,t){return await this.signer.request(e,this.formatChainId(this.chainId),t)}sendAsync(e,t,i){this.signer.sendAsync(e,t,this.formatChainId(this.chainId),i)}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(e){if(!this.signer.client)throw new Error("Provider not initialized. Call init() first");this.loadConnectOpts(e);const{required:t,optional:i}=zC(this.rpc);try{const n=await new Promise(async(f,u)=>{var b;this.rpc.showQrModal&&((b=this.modal)==null||b.subscribeModal(p=>{!p.open&&!this.signer.session&&(this.signer.abortPairingAttempt(),u(new Error("Connection request reset. Please try again.")))})),await this.signer.connect(Kl(Qa({namespaces:Qa({},t&&{[this.namespace]:t})},i&&{optionalNamespaces:{[this.namespace]:i}}),{pairingTopic:e==null?void 0:e.pairingTopic})).then(p=>{f(p)}).catch(p=>{u(new Error(p.message))})});if(!n)return;const a=T1(n.namespaces,[this.namespace]);this.setChainIds(this.rpc.chains.length?this.rpc.chains:a),this.setAccounts(a),this.events.emit("connect",{chainId:Jf(this.chainId)})}catch(n){throw this.signer.logger.error(n),n}finally{this.modal&&this.modal.closeModal()}}async authenticate(e,t){if(!this.signer.client)throw new Error("Provider not initialized. Call init() first");this.loadConnectOpts({chains:e==null?void 0:e.chains});try{const i=await new Promise(async(a,f)=>{var u;this.rpc.showQrModal&&((u=this.modal)==null||u.subscribeModal(b=>{!b.open&&!this.signer.session&&(this.signer.abortPairingAttempt(),f(new Error("Connection request reset. Please try again.")))})),await this.signer.authenticate(Kl(Qa({},e),{chains:this.rpc.chains}),t).then(b=>{a(b)}).catch(b=>{f(new Error(b.message))})}),n=i.session;if(n){const a=T1(n.namespaces,[this.namespace]);this.setChainIds(this.rpc.chains.length?this.rpc.chains:a),this.setAccounts(a),this.events.emit("connect",{chainId:Jf(this.chainId)})}return i}catch(i){throw this.signer.logger.error(i),i}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",e=>{const{params:t}=e,{event:i}=t;i.name==="accountsChanged"?(this.accounts=this.parseAccounts(i.data),this.events.emit("accountsChanged",this.accounts)):i.name==="chainChanged"?this.setChainId(this.formatChainId(i.data)):this.events.emit(i.name,i.data),this.events.emit("session_event",e)}),this.signer.on("chainChanged",e=>{const t=parseInt(e);this.chainId=t,this.events.emit("chainChanged",Jf(this.chainId)),this.persist()}),this.signer.on("session_update",e=>{this.events.emit("session_update",e)}),this.signer.on("session_delete",e=>{this.reset(),this.events.emit("session_delete",e),this.events.emit("disconnect",Kl(Qa({},Ut("USER_DISCONNECTED")),{data:e.topic,name:"USER_DISCONNECTED"}))}),this.signer.on("display_uri",e=>{var t,i;this.rpc.showQrModal&&((t=this.modal)==null||t.closeModal(),(i=this.modal)==null||i.openModal({uri:e})),this.events.emit("display_uri",e)})}switchEthereumChain(e){this.request({method:"wallet_switchEthereumChain",params:[{chainId:e.toString(16)}]})}isCompatibleChainId(e){return typeof e=="string"?e.startsWith(`${this.namespace}:`):!1}formatChainId(e){return`${this.namespace}:${e}`}parseChainId(e){return Number(e.split(":")[1])}setChainIds(e){const t=e.filter(i=>this.isCompatibleChainId(i)).map(i=>this.parseChainId(i));t.length&&(this.chainId=t[0],this.events.emit("chainChanged",Jf(this.chainId)),this.persist())}setChainId(e){if(this.isCompatibleChainId(e)){const t=this.parseChainId(e);this.chainId=t,this.switchEthereumChain(t)}}parseAccountId(e){const[t,i,n]=e.split(":");return{chainId:`${t}:${i}`,address:n}}setAccounts(e){this.accounts=e.filter(t=>this.parseChainId(this.parseAccountId(t).chainId)===this.chainId).map(t=>this.parseAccountId(t).address),this.events.emit("accountsChanged",this.accounts)}getRpcConfig(e){var t,i;const n=(t=e==null?void 0:e.chains)!=null?t:[],a=(i=e==null?void 0:e.optionalChains)!=null?i:[],f=n.concat(a);if(!f.length)throw new Error("No chains specified in either `chains` or `optionalChains`");const u=n.length?(e==null?void 0:e.methods)||E0:[],b=n.length?(e==null?void 0:e.events)||x0:[],p=(e==null?void 0:e.optionalMethods)||[],y=(e==null?void 0:e.optionalEvents)||[],A=(e==null?void 0:e.rpcMap)||this.buildRpcMap(f,e.projectId),R=(e==null?void 0:e.qrModalOptions)||void 0;return{chains:n==null?void 0:n.map(O=>this.formatChainId(O)),optionalChains:a.map(O=>this.formatChainId(O)),methods:u,events:b,optionalMethods:p,optionalEvents:y,rpcMap:A,showQrModal:!!(e!=null&&e.showQrModal),qrModalOptions:R,projectId:e.projectId,metadata:e.metadata}}buildRpcMap(e,t){const i={};return e.forEach(n=>{i[n]=this.getRpcUrl(n,t)}),i}async initialize(e){if(this.rpc=this.getRpcConfig(e),this.chainId=this.rpc.chains.length?Eh(this.rpc.chains):Eh(this.rpc.optionalChains),this.signer=await OC.init({projectId:this.rpc.projectId,metadata:this.rpc.metadata,disableProviderPing:e.disableProviderPing,relayUrl:e.relayUrl,storageOptions:e.storageOptions,customStoragePrefix:e.customStoragePrefix,telemetryEnabled:e.telemetryEnabled}),this.registerEventListeners(),await this.loadPersistedSession(),this.rpc.showQrModal){let t;try{const{WalletConnectModal:i}=await j4(()=>import("./index-DiHOtb9W.js").then(n=>n.i),__vite__mapDeps([0,1,2]));t=i}catch{throw new Error("To use QR modal, please install @walletconnect/modal package")}if(t)try{this.modal=new t(Qa({projectId:this.rpc.projectId},this.rpc.qrModalOptions))}catch(i){throw this.signer.logger.error(i),new Error("Could not generate WalletConnectModal Instance")}}}loadConnectOpts(e){if(!e)return;const{chains:t,optionalChains:i,rpcMap:n}=e;t&&jn(t)&&(this.rpc.chains=t.map(a=>this.formatChainId(a)),t.forEach(a=>{this.rpc.rpcMap[a]=(n==null?void 0:n[a])||this.getRpcUrl(a)})),i&&jn(i)&&(this.rpc.optionalChains=[],this.rpc.optionalChains=i==null?void 0:i.map(a=>this.formatChainId(a)),i.forEach(a=>{this.rpc.rpcMap[a]=(n==null?void 0:n[a])||this.getRpcUrl(a)}))}getRpcUrl(e,t){var i;return((i=this.rpc.rpcMap)==null?void 0:i[e])||`${TC}?chainId=eip155:${e}&projectId=${t||this.rpc.projectId}`}async loadPersistedSession(){if(this.session)try{const e=await this.signer.client.core.storage.getItem(`${this.STORAGE_KEY}/chainId`),t=this.session.namespaces[`${this.namespace}:${e}`]?this.session.namespaces[`${this.namespace}:${e}`]:this.session.namespaces[this.namespace];this.setChainIds(e?[this.formatChainId(e)]:t==null?void 0:t.accounts),this.setAccounts(t==null?void 0:t.accounts)}catch(e){this.signer.logger.error("Failed to load persisted session, clearing state..."),this.signer.logger.error(e),await this.disconnect().catch(t=>this.signer.logger.warn(t))}}reset(){this.chainId=1,this.accounts=[]}persist(){this.session&&this.signer.client.core.storage.setItem(`${this.STORAGE_KEY}/chainId`,this.chainId)}parseAccounts(e){return typeof e=="string"||e instanceof String?[this.parseAccount(e)]:e.map(t=>this.parseAccount(t))}}const dT=sd;export{dT as EthereumProvider,FC as OPTIONAL_EVENTS,DC as OPTIONAL_METHODS,x0 as REQUIRED_EVENTS,E0 as REQUIRED_METHODS,sd as default};