@reown/walletkit 1.2.2 → 1.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -1,4 +1,4 @@
1
- (function(vt,Zt){typeof exports=="object"&&typeof module<"u"?Zt(exports):typeof define=="function"&&define.amd?define(["exports"],Zt):(vt=typeof globalThis<"u"?globalThis:vt||self,Zt(vt["@reown/walletkit"]={}))})(this,function(vt){"use strict";var Zt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Lo(t){var e=t.default;if(typeof e=="function"){var r=function(){return e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(i){var n=Object.getOwnPropertyDescriptor(t,i);Object.defineProperty(r,i,n.get?n:{enumerable:!0,get:function(){return t[i]}})}),r}var mt={exports:{}},Ci=typeof Reflect=="object"?Reflect:null,zf=Ci&&typeof Ci.apply=="function"?Ci.apply:function(e,r,i){return Function.prototype.apply.call(e,r,i)},ms;Ci&&typeof Ci.ownKeys=="function"?ms=Ci.ownKeys:Object.getOwnPropertySymbols?ms=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:ms=function(e){return Object.getOwnPropertyNames(e)};function d1(t){console&&console.warn&&console.warn(t)}var Uf=Number.isNaN||function(e){return e!==e};function se(){se.init.call(this)}mt.exports=se,mt.exports.once=g1,se.EventEmitter=se,se.prototype._events=void 0,se.prototype._eventsCount=0,se.prototype._maxListeners=void 0;var jf=10;function ws(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(se,"defaultMaxListeners",{enumerable:!0,get:function(){return jf},set:function(t){if(typeof t!="number"||t<0||Uf(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");jf=t}}),se.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},se.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Uf(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function Vf(t){return t._maxListeners===void 0?se.defaultMaxListeners:t._maxListeners}se.prototype.getMaxListeners=function(){return Vf(this)},se.prototype.emit=function(e){for(var r=[],i=1;i<arguments.length;i++)r.push(arguments[i]);var n=e==="error",s=this._events;if(s!==void 0)n=n&&s.error===void 0;else if(!n)return!1;if(n){var o;if(r.length>0&&(o=r[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=s[e];if(c===void 0)return!1;if(typeof c=="function")zf(c,this,r);else for(var f=c.length,u=Yf(c,f),i=0;i<f;++i)zf(u[i],this,r);return!0};function Kf(t,e,r,i){var n,s,o;if(ws(r),s=t._events,s===void 0?(s=t._events=Object.create(null),t._eventsCount=0):(s.newListener!==void 0&&(t.emit("newListener",e,r.listener?r.listener:r),s=t._events),o=s[e]),o===void 0)o=s[e]=r,++t._eventsCount;else if(typeof o=="function"?o=s[e]=i?[r,o]:[o,r]:i?o.unshift(r):o.push(r),n=Vf(t),n>0&&o.length>n&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=o.length,d1(a)}return t}se.prototype.addListener=function(e,r){return Kf(this,e,r,!1)},se.prototype.on=se.prototype.addListener,se.prototype.prependListener=function(e,r){return Kf(this,e,r,!0)};function l1(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Hf(t,e,r){var i={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},n=l1.bind(i);return n.listener=r,i.wrapFn=n,n}se.prototype.once=function(e,r){return ws(r),this.on(e,Hf(this,e,r)),this},se.prototype.prependOnceListener=function(e,r){return ws(r),this.prependListener(e,Hf(this,e,r)),this},se.prototype.removeListener=function(e,r){var i,n,s,o,a;if(ws(r),n=this._events,n===void 0)return this;if(i=n[e],i===void 0)return this;if(i===r||i.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete n[e],n.removeListener&&this.emit("removeListener",e,i.listener||r));else if(typeof i!="function"){for(s=-1,o=i.length-1;o>=0;o--)if(i[o]===r||i[o].listener===r){a=i[o].listener,s=o;break}if(s<0)return this;s===0?i.shift():p1(i,s),i.length===1&&(n[e]=i[0]),n.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this},se.prototype.off=se.prototype.removeListener,se.prototype.removeAllListeners=function(e){var r,i,n;if(i=this._events,i===void 0)return this;if(i.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):i[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete i[e]),this;if(arguments.length===0){var s=Object.keys(i),o;for(n=0;n<s.length;++n)o=s[n],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=i[e],typeof r=="function")this.removeListener(e,r);else if(r!==void 0)for(n=r.length-1;n>=0;n--)this.removeListener(e,r[n]);return this};function Wf(t,e,r){var i=t._events;if(i===void 0)return[];var n=i[e];return n===void 0?[]:typeof n=="function"?r?[n.listener||n]:[n]:r?b1(n):Yf(n,n.length)}se.prototype.listeners=function(e){return Wf(this,e,!0)},se.prototype.rawListeners=function(e){return Wf(this,e,!1)},se.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Gf.call(t,e)},se.prototype.listenerCount=Gf;function Gf(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}se.prototype.eventNames=function(){return this._eventsCount>0?ms(this._events):[]};function Yf(t,e){for(var r=new Array(e),i=0;i<e;++i)r[i]=t[i];return r}function p1(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function b1(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function g1(t,e){return new Promise(function(r,i){function n(o){t.removeListener(e,s),i(o)}function s(){typeof t.removeListener=="function"&&t.removeListener("error",n),r([].slice.call(arguments))}Zf(t,e,s,{once:!0}),e!=="error"&&y1(t,n,{once:!0})})}function y1(t,e,r){typeof t.on=="function"&&Zf(t,"error",e,r)}function Zf(t,e,r,i){if(typeof t.on=="function")i.once?t.once(e,r):t.on(e,r);else if(typeof t.addEventListener=="function")t.addEventListener(e,function n(s){i.once&&t.removeEventListener(e,n),r(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}const Jf="wc",v1=2,qo="WalletKit",m1=`${Jf}@2:${qo}:`,w1={database:":memory:"},_1="request";var z={};/*! *****************************************************************************
1
+ (function(Fe,yt){typeof exports=="object"&&typeof module<"u"?yt(exports):typeof define=="function"&&define.amd?define(["exports"],yt):(Fe=typeof globalThis<"u"?globalThis:Fe||self,yt(Fe["@reown/walletkit"]={}))})(this,function(Fe){"use strict";var yt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ka(t){var e=t.default;if(typeof e=="function"){var r=function(){return e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}),r}var Le={exports:{}},Tr=typeof Reflect=="object"?Reflect:null,Ma=Tr&&typeof Tr.apply=="function"?Tr.apply:function(e,r,n){return Function.prototype.apply.call(e,r,n)},oi;Tr&&typeof Tr.ownKeys=="function"?oi=Tr.ownKeys:Object.getOwnPropertySymbols?oi=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:oi=function(e){return Object.getOwnPropertyNames(e)};function jf(t){console&&console.warn&&console.warn(t)}var ja=Number.isNaN||function(e){return e!==e};function te(){te.init.call(this)}Le.exports=te,Le.exports.once=Kf,te.EventEmitter=te,te.prototype._events=void 0,te.prototype._eventsCount=0,te.prototype._maxListeners=void 0;var qa=10;function ai(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(te,"defaultMaxListeners",{enumerable:!0,get:function(){return qa},set:function(t){if(typeof t!="number"||t<0||ja(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");qa=t}}),te.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},te.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||ja(e))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+e+".");return this._maxListeners=e,this};function za(t){return t._maxListeners===void 0?te.defaultMaxListeners:t._maxListeners}te.prototype.getMaxListeners=function(){return za(this)},te.prototype.emit=function(e){for(var r=[],n=1;n<arguments.length;n++)r.push(arguments[n]);var i=e==="error",s=this._events;if(s!==void 0)i=i&&s.error===void 0;else if(!i)return!1;if(i){var o;if(r.length>0&&(o=r[0]),o instanceof Error)throw o;var a=new Error("Unhandled error."+(o?" ("+o.message+")":""));throw a.context=o,a}var c=s[e];if(c===void 0)return!1;if(typeof c=="function")Ma(c,this,r);else for(var u=c.length,l=Ga(c,u),n=0;n<u;++n)Ma(l[n],this,r);return!0};function Va(t,e,r,n){var i,s,o;if(ai(r),s=t._events,s===void 0?(s=t._events=Object.create(null),t._eventsCount=0):(s.newListener!==void 0&&(t.emit("newListener",e,r.listener?r.listener:r),s=t._events),o=s[e]),o===void 0)o=s[e]=r,++t._eventsCount;else if(typeof o=="function"?o=s[e]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),i=za(t),i>0&&o.length>i&&!o.warned){o.warned=!0;var a=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+String(e)+" listeners added. Use emitter.setMaxListeners() to increase limit");a.name="MaxListenersExceededWarning",a.emitter=t,a.type=e,a.count=o.length,jf(a)}return t}te.prototype.addListener=function(e,r){return Va(this,e,r,!1)},te.prototype.on=te.prototype.addListener,te.prototype.prependListener=function(e,r){return Va(this,e,r,!0)};function qf(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function Ka(t,e,r){var n={fired:!1,wrapFn:void 0,target:t,type:e,listener:r},i=qf.bind(n);return i.listener=r,n.wrapFn=i,i}te.prototype.once=function(e,r){return ai(r),this.on(e,Ka(this,e,r)),this},te.prototype.prependOnceListener=function(e,r){return ai(r),this.prependListener(e,Ka(this,e,r)),this},te.prototype.removeListener=function(e,r){var n,i,s,o,a;if(ai(r),i=this._events,i===void 0)return this;if(n=i[e],n===void 0)return this;if(n===r||n.listener===r)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,n.listener||r));else if(typeof n!="function"){for(s=-1,o=n.length-1;o>=0;o--)if(n[o]===r||n[o].listener===r){a=n[o].listener,s=o;break}if(s<0)return this;s===0?n.shift():zf(n,s),n.length===1&&(i[e]=n[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||r)}return this},te.prototype.off=te.prototype.removeListener,te.prototype.removeAllListeners=function(e){var r,n,i;if(n=this._events,n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var s=Object.keys(n),o;for(i=0;i<s.length;++i)o=s[i],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(r=n[e],typeof r=="function")this.removeListener(e,r);else if(r!==void 0)for(i=r.length-1;i>=0;i--)this.removeListener(e,r[i]);return this};function Ha(t,e,r){var n=t._events;if(n===void 0)return[];var i=n[e];return i===void 0?[]:typeof i=="function"?r?[i.listener||i]:[i]:r?Vf(i):Ga(i,i.length)}te.prototype.listeners=function(e){return Ha(this,e,!0)},te.prototype.rawListeners=function(e){return Ha(this,e,!1)},te.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):Wa.call(t,e)},te.prototype.listenerCount=Wa;function Wa(t){var e=this._events;if(e!==void 0){var r=e[t];if(typeof r=="function")return 1;if(r!==void 0)return r.length}return 0}te.prototype.eventNames=function(){return this._eventsCount>0?oi(this._events):[]};function Ga(t,e){for(var r=new Array(e),n=0;n<e;++n)r[n]=t[n];return r}function zf(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function Vf(t){for(var e=new Array(t.length),r=0;r<e.length;++r)e[r]=t[r].listener||t[r];return e}function Kf(t,e){return new Promise(function(r,n){function i(o){t.removeListener(e,s),n(o)}function s(){typeof t.removeListener=="function"&&t.removeListener("error",i),r([].slice.call(arguments))}Ya(t,e,s,{once:!0}),e!=="error"&&Hf(t,i,{once:!0})})}function Hf(t,e,r){typeof t.on=="function"&&Ya(t,"error",e,r)}function Ya(t,e,r,n){if(typeof t.on=="function")n.once?t.once(e,r):t.on(e,r);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(s){n.once&&t.removeEventListener(e,i),r(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}const Za="wc",Wf=2,ls="WalletKit",Gf=`${Za}@2:${ls}:`,Yf={database:":memory:"},Zf="request";var L={};/*! *****************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -11,19 +11,19 @@
11
11
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
12
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
13
  PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */var ko=function(t,e){return ko=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var n in i)i.hasOwnProperty(n)&&(r[n]=i[n])},ko(t,e)};function x1(t,e){ko(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}var zo=function(){return zo=Object.assign||function(e){for(var r,i=1,n=arguments.length;i<n;i++){r=arguments[i];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},zo.apply(this,arguments)};function E1(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]]);return r}function S1(t,e,r,i){var n=arguments.length,s=n<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,r):i,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,r,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(n<3?o(s):n>3?o(e,r,s):o(e,r))||s);return n>3&&s&&Object.defineProperty(e,r,s),s}function I1(t,e){return function(r,i){e(r,i,t)}}function A1(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function $1(t,e,r,i){function n(s){return s instanceof r?s:new r(function(o){o(s)})}return new(r||(r=Promise))(function(s,o){function a(u){try{f(i.next(u))}catch(d){o(d)}}function c(u){try{f(i.throw(u))}catch(d){o(d)}}function f(u){u.done?s(u.value):n(u.value).then(a,c)}f((i=i.apply(t,e||[])).next())})}function D1(t,e){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},i,n,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(f){return function(u){return c([f,u])}}function c(f){if(i)throw new TypeError("Generator is already executing.");for(;r;)try{if(i=1,n&&(s=f[0]&2?n.return:f[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,f[1])).done)return s;switch(n=0,s&&(f=[f[0]&2,s.value]),f[0]){case 0:case 1:s=f;break;case 4:return r.label++,{value:f[1],done:!1};case 5:r.label++,n=f[1],f=[0];continue;case 7:f=r.ops.pop(),r.trys.pop();continue;default:if(s=r.trys,!(s=s.length>0&&s[s.length-1])&&(f[0]===6||f[0]===2)){r=0;continue}if(f[0]===3&&(!s||f[1]>s[0]&&f[1]<s[3])){r.label=f[1];break}if(f[0]===6&&r.label<s[1]){r.label=s[1],s=f;break}if(s&&r.label<s[2]){r.label=s[2],r.ops.push(f);break}s[2]&&r.ops.pop(),r.trys.pop();continue}f=e.call(t,r)}catch(u){f=[6,u],n=0}finally{i=s=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}function O1(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}function M1(t,e){for(var r in t)r!=="default"&&!e.hasOwnProperty(r)&&(e[r]=t[r])}function Uo(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],i=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Xf(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var i=r.call(t),n,s=[],o;try{for(;(e===void 0||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(a){o={error:a}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function P1(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(Xf(arguments[e]));return t}function R1(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var i=Array(t),n=0,e=0;e<r;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,n++)i[n]=s[o];return i}function En(t){return this instanceof En?(this.v=t,this):new En(t)}function T1(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=r.apply(t,e||[]),n,s=[];return n={},o("next"),o("throw"),o("return"),n[Symbol.asyncIterator]=function(){return this},n;function o(b){i[b]&&(n[b]=function(v){return new Promise(function(g,x){s.push([b,v,g,x])>1||a(b,v)})})}function a(b,v){try{c(i[b](v))}catch(g){d(s[0][3],g)}}function c(b){b.value instanceof En?Promise.resolve(b.value.v).then(f,u):d(s[0][2],b)}function f(b){a("next",b)}function u(b){a("throw",b)}function d(b,v){b(v),s.shift(),s.length&&a(s[0][0],s[0][1])}}function N1(t){var e,r;return e={},i("next"),i("throw",function(n){throw n}),i("return"),e[Symbol.iterator]=function(){return this},e;function i(n,s){e[n]=t[n]?function(o){return(r=!r)?{value:En(t[n](o)),done:n==="return"}:s?s(o):o}:s}}function C1(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof Uo=="function"?Uo(t):t[Symbol.iterator](),r={},i("next"),i("throw"),i("return"),r[Symbol.asyncIterator]=function(){return this},r);function i(s){r[s]=t[s]&&function(o){return new Promise(function(a,c){o=t[s](o),n(a,c,o.done,o.value)})}}function n(s,o,a,c){Promise.resolve(c).then(function(f){s({value:f,done:a})},o)}}function B1(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function F1(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function L1(t){return t&&t.__esModule?t:{default:t}}function q1(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function k1(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}var z1=Object.freeze({__proto__:null,__extends:x1,get __assign(){return zo},__rest:E1,__decorate:S1,__param:I1,__metadata:A1,__awaiter:$1,__generator:D1,__createBinding:O1,__exportStar:M1,__values:Uo,__read:Xf,__spread:P1,__spreadArrays:R1,__await:En,__asyncGenerator:T1,__asyncDelegator:N1,__asyncValues:C1,__makeTemplateObject:B1,__importStar:F1,__importDefault:L1,__classPrivateFieldGet:q1,__classPrivateFieldSet:k1}),_s=Lo(z1),jo={},Sn={},Qf;function U1(){if(Qf)return Sn;Qf=1,Object.defineProperty(Sn,"__esModule",{value:!0}),Sn.delay=void 0;function t(e){return new Promise(r=>{setTimeout(()=>{r(!0)},e)})}return Sn.delay=t,Sn}var fi={},Vo={},ui={},eu;function j1(){return eu||(eu=1,Object.defineProperty(ui,"__esModule",{value:!0}),ui.ONE_THOUSAND=ui.ONE_HUNDRED=void 0,ui.ONE_HUNDRED=100,ui.ONE_THOUSAND=1e3),ui}var Ko={},tu;function V1(){return tu||(tu=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.ONE_YEAR=t.FOUR_WEEKS=t.THREE_WEEKS=t.TWO_WEEKS=t.ONE_WEEK=t.THIRTY_DAYS=t.SEVEN_DAYS=t.FIVE_DAYS=t.THREE_DAYS=t.ONE_DAY=t.TWENTY_FOUR_HOURS=t.TWELVE_HOURS=t.SIX_HOURS=t.THREE_HOURS=t.ONE_HOUR=t.SIXTY_MINUTES=t.THIRTY_MINUTES=t.TEN_MINUTES=t.FIVE_MINUTES=t.ONE_MINUTE=t.SIXTY_SECONDS=t.THIRTY_SECONDS=t.TEN_SECONDS=t.FIVE_SECONDS=t.ONE_SECOND=void 0,t.ONE_SECOND=1,t.FIVE_SECONDS=5,t.TEN_SECONDS=10,t.THIRTY_SECONDS=30,t.SIXTY_SECONDS=60,t.ONE_MINUTE=t.SIXTY_SECONDS,t.FIVE_MINUTES=t.ONE_MINUTE*5,t.TEN_MINUTES=t.ONE_MINUTE*10,t.THIRTY_MINUTES=t.ONE_MINUTE*30,t.SIXTY_MINUTES=t.ONE_MINUTE*60,t.ONE_HOUR=t.SIXTY_MINUTES,t.THREE_HOURS=t.ONE_HOUR*3,t.SIX_HOURS=t.ONE_HOUR*6,t.TWELVE_HOURS=t.ONE_HOUR*12,t.TWENTY_FOUR_HOURS=t.ONE_HOUR*24,t.ONE_DAY=t.TWENTY_FOUR_HOURS,t.THREE_DAYS=t.ONE_DAY*3,t.FIVE_DAYS=t.ONE_DAY*5,t.SEVEN_DAYS=t.ONE_DAY*7,t.THIRTY_DAYS=t.ONE_DAY*30,t.ONE_WEEK=t.SEVEN_DAYS,t.TWO_WEEKS=t.ONE_WEEK*2,t.THREE_WEEKS=t.ONE_WEEK*3,t.FOUR_WEEKS=t.ONE_WEEK*4,t.ONE_YEAR=t.ONE_DAY*365}(Ko)),Ko}var ru;function iu(){return ru||(ru=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=_s;e.__exportStar(j1(),t),e.__exportStar(V1(),t)}(Vo)),Vo}var nu;function K1(){if(nu)return fi;nu=1,Object.defineProperty(fi,"__esModule",{value:!0}),fi.fromMiliseconds=fi.toMiliseconds=void 0;const t=iu();function e(i){return i*t.ONE_THOUSAND}fi.toMiliseconds=e;function r(i){return Math.floor(i/t.ONE_THOUSAND)}return fi.fromMiliseconds=r,fi}var su;function H1(){return su||(su=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=_s;e.__exportStar(U1(),t),e.__exportStar(K1(),t)}(jo)),jo}var Bi={},ou;function W1(){if(ou)return Bi;ou=1,Object.defineProperty(Bi,"__esModule",{value:!0}),Bi.Watch=void 0;class t{constructor(){this.timestamps=new Map}start(r){if(this.timestamps.has(r))throw new Error(`Watch already started for label: ${r}`);this.timestamps.set(r,{started:Date.now()})}stop(r){const i=this.get(r);if(typeof i.elapsed<"u")throw new Error(`Watch already stopped for label: ${r}`);const n=Date.now()-i.started;this.timestamps.set(r,{started:i.started,elapsed:n})}get(r){const i=this.timestamps.get(r);if(typeof i>"u")throw new Error(`No timestamp found for label: ${r}`);return i}elapsed(r){const i=this.get(r);return i.elapsed||Date.now()-i.started}}return Bi.Watch=t,Bi.default=t,Bi}var Ho={},In={},au;function G1(){if(au)return In;au=1,Object.defineProperty(In,"__esModule",{value:!0}),In.IWatch=void 0;class t{}return In.IWatch=t,In}var cu;function Y1(){return cu||(cu=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),_s.__exportStar(G1(),t)}(Ho)),Ho}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=_s;e.__exportStar(H1(),t),e.__exportStar(W1(),t),e.__exportStar(Y1(),t),e.__exportStar(iu(),t)})(z);class hi{}class Z1 extends hi{constructor(e){super()}}const fu=z.FIVE_SECONDS,Fi={pulse:"heartbeat_pulse"};class Wo extends Z1{constructor(e){super(e),this.events=new mt.exports.EventEmitter,this.interval=fu,this.interval=e?.interval||fu}static async init(e){const r=new Wo(e);return await r.init(),r}async init(){await this.initialize()}stop(){clearInterval(this.intervalRef)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async initialize(){this.intervalRef=setInterval(()=>this.pulse(),z.toMiliseconds(this.interval))}pulse(){this.events.emit(Fi.pulse)}}const J1=/"(?:_|\\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*:/,X1=/"(?: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*:/,Q1=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function eb(t,e){if(t==="__proto__"||t==="constructor"&&e&&typeof e=="object"&&"prototype"in e){tb(t);return}return e}function tb(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}function xs(t,e={}){if(typeof t!="string")return t;const r=t.trim();if(t[0]==='"'&&t.endsWith('"')&&!t.includes("\\"))return r.slice(1,-1);if(r.length<=9){const i=r.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(!Q1.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(J1.test(t)||X1.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,eb)}return JSON.parse(t)}catch(i){if(e.strict)throw i;return t}}function rb(t){return!t||typeof t.then!="function"?Promise.resolve(t):t}function et(t,...e){try{return rb(t(...e))}catch(r){return Promise.reject(r)}}function ib(t){const e=typeof t;return t===null||e!=="object"&&e!=="function"}function nb(t){const e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}function Es(t){if(ib(t))return String(t);if(nb(t)||Array.isArray(t))return JSON.stringify(t);if(typeof t.toJSON=="function")return Es(t.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function uu(){if(typeof Buffer>"u")throw new TypeError("[unstorage] Buffer is not supported!")}const Go="base64:";function sb(t){if(typeof t=="string")return t;uu();const e=Buffer.from(t).toString("base64");return Go+e}function ob(t){return typeof t!="string"||!t.startsWith(Go)?t:(uu(),Buffer.from(t.slice(Go.length),"base64"))}function Ot(t){return t?t.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function ab(...t){return Ot(t.join(":"))}function Ss(t){return t=Ot(t),t?t+":":""}function WI(t){return t}const cb="memory",fb=()=>{const t=new Map;return{name:cb,getInstance:()=>t,hasItem(e){return t.has(e)},getItem(e){return t.get(e)??null},getItemRaw(e){return t.get(e)??null},setItem(e,r){t.set(e,r)},setItemRaw(e,r){t.set(e,r)},removeItem(e){t.delete(e)},getKeys(){return[...t.keys()]},clear(){t.clear()},dispose(){t.clear()}}};function ub(t={}){const e={mounts:{"":t.driver||fb()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},r=f=>{for(const u of e.mountpoints)if(f.startsWith(u))return{base:u,relativeKey:f.slice(u.length),driver:e.mounts[u]};return{base:"",relativeKey:f,driver:e.mounts[""]}},i=(f,u)=>e.mountpoints.filter(d=>d.startsWith(f)||u&&f.startsWith(d)).map(d=>({relativeBase:f.length>d.length?f.slice(d.length):void 0,mountpoint:d,driver:e.mounts[d]})),n=(f,u)=>{if(e.watching){u=Ot(u);for(const d of e.watchListeners)d(f,u)}},s=async()=>{if(!e.watching){e.watching=!0;for(const f in e.mounts)e.unwatch[f]=await hu(e.mounts[f],n,f)}},o=async()=>{if(e.watching){for(const f in e.unwatch)await e.unwatch[f]();e.unwatch={},e.watching=!1}},a=(f,u,d)=>{const b=new Map,v=g=>{let x=b.get(g.base);return x||(x={driver:g.driver,base:g.base,items:[]},b.set(g.base,x)),x};for(const g of f){const x=typeof g=="string",I=Ot(x?g:g.key),D=x?void 0:g.value,O=x||!g.options?u:{...u,...g.options},M=r(I);v(M).items.push({key:I,value:D,relativeKey:M.relativeKey,options:O})}return Promise.all([...b.values()].map(g=>d(g))).then(g=>g.flat())},c={hasItem(f,u={}){f=Ot(f);const{relativeKey:d,driver:b}=r(f);return et(b.hasItem,d,u)},getItem(f,u={}){f=Ot(f);const{relativeKey:d,driver:b}=r(f);return et(b.getItem,d,u).then(v=>xs(v))},getItems(f,u){return a(f,u,d=>d.driver.getItems?et(d.driver.getItems,d.items.map(b=>({key:b.relativeKey,options:b.options})),u).then(b=>b.map(v=>({key:ab(d.base,v.key),value:xs(v.value)}))):Promise.all(d.items.map(b=>et(d.driver.getItem,b.relativeKey,b.options).then(v=>({key:b.key,value:xs(v)})))))},getItemRaw(f,u={}){f=Ot(f);const{relativeKey:d,driver:b}=r(f);return b.getItemRaw?et(b.getItemRaw,d,u):et(b.getItem,d,u).then(v=>ob(v))},async setItem(f,u,d={}){if(u===void 0)return c.removeItem(f);f=Ot(f);const{relativeKey:b,driver:v}=r(f);v.setItem&&(await et(v.setItem,b,Es(u),d),v.watch||n("update",f))},async setItems(f,u){await a(f,u,async d=>{if(d.driver.setItems)return et(d.driver.setItems,d.items.map(b=>({key:b.relativeKey,value:Es(b.value),options:b.options})),u);d.driver.setItem&&await Promise.all(d.items.map(b=>et(d.driver.setItem,b.relativeKey,Es(b.value),b.options)))})},async setItemRaw(f,u,d={}){if(u===void 0)return c.removeItem(f,d);f=Ot(f);const{relativeKey:b,driver:v}=r(f);if(v.setItemRaw)await et(v.setItemRaw,b,u,d);else if(v.setItem)await et(v.setItem,b,sb(u),d);else return;v.watch||n("update",f)},async removeItem(f,u={}){typeof u=="boolean"&&(u={removeMeta:u}),f=Ot(f);const{relativeKey:d,driver:b}=r(f);b.removeItem&&(await et(b.removeItem,d,u),(u.removeMeta||u.removeMata)&&await et(b.removeItem,d+"$",u),b.watch||n("remove",f))},async getMeta(f,u={}){typeof u=="boolean"&&(u={nativeOnly:u}),f=Ot(f);const{relativeKey:d,driver:b}=r(f),v=Object.create(null);if(b.getMeta&&Object.assign(v,await et(b.getMeta,d,u)),!u.nativeOnly){const g=await et(b.getItem,d+"$",u).then(x=>xs(x));g&&typeof g=="object"&&(typeof g.atime=="string"&&(g.atime=new Date(g.atime)),typeof g.mtime=="string"&&(g.mtime=new Date(g.mtime)),Object.assign(v,g))}return v},setMeta(f,u,d={}){return this.setItem(f+"$",u,d)},removeMeta(f,u={}){return this.removeItem(f+"$",u)},async getKeys(f,u={}){f=Ss(f);const d=i(f,!0);let b=[];const v=[];for(const g of d){const x=await et(g.driver.getKeys,g.relativeBase,u);for(const I of x){const D=g.mountpoint+Ot(I);b.some(O=>D.startsWith(O))||v.push(D)}b=[g.mountpoint,...b.filter(I=>!I.startsWith(g.mountpoint))]}return f?v.filter(g=>g.startsWith(f)&&g[g.length-1]!=="$"):v.filter(g=>g[g.length-1]!=="$")},async clear(f,u={}){f=Ss(f),await Promise.all(i(f,!1).map(async d=>{if(d.driver.clear)return et(d.driver.clear,d.relativeBase,u);if(d.driver.removeItem){const b=await d.driver.getKeys(d.relativeBase||"",u);return Promise.all(b.map(v=>d.driver.removeItem(v,u)))}}))},async dispose(){await Promise.all(Object.values(e.mounts).map(f=>du(f)))},async watch(f){return await s(),e.watchListeners.push(f),async()=>{e.watchListeners=e.watchListeners.filter(u=>u!==f),e.watchListeners.length===0&&await o()}},async unwatch(){e.watchListeners=[],await o()},mount(f,u){if(f=Ss(f),f&&e.mounts[f])throw new Error(`already mounted at ${f}`);return f&&(e.mountpoints.push(f),e.mountpoints.sort((d,b)=>b.length-d.length)),e.mounts[f]=u,e.watching&&Promise.resolve(hu(u,n,f)).then(d=>{e.unwatch[f]=d}).catch(console.error),c},async unmount(f,u=!0){f=Ss(f),!(!f||!e.mounts[f])&&(e.watching&&f in e.unwatch&&(e.unwatch[f](),delete e.unwatch[f]),u&&await du(e.mounts[f]),e.mountpoints=e.mountpoints.filter(d=>d!==f),delete e.mounts[f])},getMount(f=""){f=Ot(f)+":";const u=r(f);return{driver:u.driver,base:u.base}},getMounts(f="",u={}){return f=Ot(f),i(f,u.parents).map(b=>({driver:b.driver,base:b.mountpoint}))},keys:(f,u={})=>c.getKeys(f,u),get:(f,u={})=>c.getItem(f,u),set:(f,u,d={})=>c.setItem(f,u,d),has:(f,u={})=>c.hasItem(f,u),del:(f,u={})=>c.removeItem(f,u),remove:(f,u={})=>c.removeItem(f,u)};return c}function hu(t,e,r){return t.watch?t.watch((i,n)=>e(i,r+n)):()=>{}}async function du(t){typeof t.dispose=="function"&&await et(t.dispose)}function di(t){return new Promise((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)})}function lu(t,e){const r=indexedDB.open(t);r.onupgradeneeded=()=>r.result.createObjectStore(e);const i=di(r);return(n,s)=>i.then(o=>s(o.transaction(e,n).objectStore(e)))}let Yo;function An(){return Yo||(Yo=lu("keyval-store","keyval")),Yo}function pu(t,e=An()){return e("readonly",r=>di(r.get(t)))}function hb(t,e,r=An()){return r("readwrite",i=>(i.put(e,t),di(i.transaction)))}function db(t,e=An()){return e("readwrite",r=>(r.delete(t),di(r.transaction)))}function lb(t=An()){return t("readwrite",e=>(e.clear(),di(e.transaction)))}function pb(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},di(t.transaction)}function bb(t=An()){return t("readonly",e=>{if(e.getAllKeys)return di(e.getAllKeys());const r=[];return pb(e,i=>r.push(i.key)).then(()=>r)})}const gb=t=>JSON.stringify(t,(e,r)=>typeof r=="bigint"?r.toString()+"n":r),yb=t=>{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,r=t.replace(e,'$1"$2n"$3');return JSON.parse(r,(i,n)=>typeof n=="string"&&n.match(/^\d+n$/)?BigInt(n.substring(0,n.length-1)):n)};function Li(t){if(typeof t!="string")throw new Error(`Cannot safe json parse value of type ${typeof t}`);try{return yb(t)}catch{return t}}function li(t){return typeof t=="string"?t:gb(t)||""}const vb="idb-keyval";var mb=(t={})=>{const e=t.base&&t.base.length>0?`${t.base}:`:"",r=n=>e+n;let i;return t.dbName&&t.storeName&&(i=lu(t.dbName,t.storeName)),{name:vb,options:t,async hasItem(n){return!(typeof await pu(r(n),i)>"u")},async getItem(n){return await pu(r(n),i)??null},setItem(n,s){return hb(r(n),s,i)},removeItem(n){return db(r(n),i)},getKeys(){return bb(i)},clear(){return lb(i)}}};const wb="WALLET_CONNECT_V2_INDEXED_DB",_b="keyvaluestorage";class xb{constructor(){this.indexedDb=ub({driver:mb({dbName:wb,storeName:_b})})}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 r=await this.indexedDb.getItem(e);if(r!==null)return r}async setItem(e,r){await this.indexedDb.setItem(e,li(r))}async removeItem(e){await this.indexedDb.removeItem(e)}}var Zo=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Is={exports:{}};(function(){let t;function e(){}t=e,t.prototype.getItem=function(r){return this.hasOwnProperty(r)?String(this[r]):null},t.prototype.setItem=function(r,i){this[r]=String(i)},t.prototype.removeItem=function(r){delete this[r]},t.prototype.clear=function(){const r=this;Object.keys(r).forEach(function(i){r[i]=void 0,delete r[i]})},t.prototype.key=function(r){return r=r||0,Object.keys(this)[r]},t.prototype.__defineGetter__("length",function(){return Object.keys(this).length}),typeof Zo<"u"&&Zo.localStorage?Is.exports=Zo.localStorage:typeof window<"u"&&window.localStorage?Is.exports=window.localStorage:Is.exports=new e})();function Eb(t){var e;return[t[0],Li((e=t[1])!=null?e:"")]}class Sb{constructor(){this.localStorage=Is.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(Eb)}async getItem(e){const r=this.localStorage.getItem(e);if(r!==null)return Li(r)}async setItem(e,r){this.localStorage.setItem(e,li(r))}async removeItem(e){this.localStorage.removeItem(e)}}const Ib="wc_storage_version",bu=1,Ab=async(t,e,r)=>{const i=Ib,n=await e.getItem(i);if(n&&n>=bu){r(e);return}const s=await t.getKeys();if(!s.length){r(e);return}const o=[];for(;s.length;){const a=s.shift();if(!a)continue;const c=a.toLowerCase();if(c.includes("wc@")||c.includes("walletconnect")||c.includes("wc_")||c.includes("wallet_connect")){const f=await t.getItem(a);await e.setItem(a,f),o.push(a)}}await e.setItem(i,bu),r(e),$b(t,o)},$b=async(t,e)=>{e.length&&e.forEach(async r=>{await t.removeItem(r)})};class Db{constructor(){this.initialized=!1,this.setInitialized=r=>{this.storage=r,this.initialized=!0};const e=new Sb;this.storage=e;try{const r=new xb;Ab(e,r,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,r){return await this.initialize(),this.storage.setItem(e,r)}async removeItem(e){return await this.initialize(),this.storage.removeItem(e)}async initialize(){this.initialized||await new Promise(e=>{const r=setInterval(()=>{this.initialized&&(clearInterval(r),e())},20)})}}function Ob(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}var Mb=Pb;function Pb(t,e,r){var i=r&&r.stringify||Ob,n=1;if(typeof t=="object"&&t!==null){var s=e.length+n;if(s===1)return t;var o=new Array(s);o[0]=i(t);for(var a=1;a<s;a++)o[a]=i(e[a]);return o.join(" ")}if(typeof t!="string")return t;var c=e.length;if(c===0)return t;for(var f="",u=1-n,d=-1,b=t&&t.length||0,v=0;v<b;){if(t.charCodeAt(v)===37&&v+1<b){switch(d=d>-1?d:0,t.charCodeAt(v+1)){case 100:case 102:if(u>=c||e[u]==null)break;d<v&&(f+=t.slice(d,v)),f+=Number(e[u]),d=v+2,v++;break;case 105:if(u>=c||e[u]==null)break;d<v&&(f+=t.slice(d,v)),f+=Math.floor(Number(e[u])),d=v+2,v++;break;case 79:case 111:case 106:if(u>=c||e[u]===void 0)break;d<v&&(f+=t.slice(d,v));var g=typeof e[u];if(g==="string"){f+="'"+e[u]+"'",d=v+2,v++;break}if(g==="function"){f+=e[u].name||"<anonymous>",d=v+2,v++;break}f+=i(e[u]),d=v+2,v++;break;case 115:if(u>=c)break;d<v&&(f+=t.slice(d,v)),f+=String(e[u]),d=v+2,v++;break;case 37:d<v&&(f+=t.slice(d,v)),f+="%",d=v+2,v++,u--;break}++u}++v}return d===-1?t:(d<b&&(f+=t.slice(d)),f)}const gu=Mb;var Dr=or;const $n=zb().console||{},Rb={mapHttpRequest:$s,mapHttpResponse:$s,wrapRequestSerializer:Xo,wrapResponseSerializer:Xo,wrapErrorSerializer:Xo,req:$s,res:$s,err:Fb};function Tb(t,e){return Array.isArray(t)?t.filter(function(i){return i!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function or(t){t=t||{},t.browser=t.browser||{};const e=t.browser.transmit;if(e&&typeof e.send!="function")throw Error("pino: transmit option must have a send function");const r=t.browser.write||$n;t.browser.write&&(t.browser.asObject=!0);const i=t.serializers||{},n=Tb(t.browser.serialize,i);let s=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(s=!1);const o=["error","fatal","warn","info","debug","trace"];typeof r=="function"&&(r.error=r.fatal=r.warn=r.info=r.debug=r.trace=r),t.enabled===!1&&(t.level="silent");const a=t.level||"info",c=Object.create(r);c.log||(c.log=Dn),Object.defineProperty(c,"levelVal",{get:u}),Object.defineProperty(c,"level",{get:d,set:b});const f={transmit:e,serialize:n,asObject:t.browser.asObject,levels:o,timestamp:Lb(t)};c.levels=or.levels,c.level=a,c.setMaxListeners=c.getMaxListeners=c.emit=c.addListener=c.on=c.prependListener=c.once=c.prependOnceListener=c.removeListener=c.removeAllListeners=c.listeners=c.listenerCount=c.eventNames=c.write=c.flush=Dn,c.serializers=i,c._serialize=n,c._stdErrSerialize=s,c.child=v,e&&(c._logEvent=Jo());function u(){return this.level==="silent"?1/0:this.levels.values[this.level]}function d(){return this._level}function b(g){if(g!=="silent"&&!this.levels.values[g])throw Error("unknown level "+g);this._level=g,qi(f,c,"error","log"),qi(f,c,"fatal","error"),qi(f,c,"warn","error"),qi(f,c,"info","log"),qi(f,c,"debug","log"),qi(f,c,"trace","log")}function v(g,x){if(!g)throw new Error("missing bindings for child Pino");x=x||{},n&&g.serializers&&(x.serializers=g.serializers);const I=x.serializers;if(n&&I){var D=Object.assign({},i,I),O=t.browser.serialize===!0?Object.keys(D):n;delete g.serializers,As([g],O,D,this._stdErrSerialize)}function M(P){this._childLevel=(P._childLevel|0)+1,this.error=ki(P,g,"error"),this.fatal=ki(P,g,"fatal"),this.warn=ki(P,g,"warn"),this.info=ki(P,g,"info"),this.debug=ki(P,g,"debug"),this.trace=ki(P,g,"trace"),D&&(this.serializers=D,this._serialize=O),e&&(this._logEvent=Jo([].concat(P._logEvent.bindings,g)))}return M.prototype=this,new M(this)}return c}or.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"}},or.stdSerializers=Rb,or.stdTimeFunctions=Object.assign({},{nullTime:yu,epochTime:vu,unixTime:qb,isoTime:kb});function qi(t,e,r,i){const n=Object.getPrototypeOf(e);e[r]=e.levelVal>e.levels.values[r]?Dn:n[r]?n[r]:$n[r]||$n[i]||Dn,Nb(t,e,r)}function Nb(t,e,r){!t.transmit&&e[r]===Dn||(e[r]=function(i){return function(){const s=t.timestamp(),o=new Array(arguments.length),a=Object.getPrototypeOf&&Object.getPrototypeOf(this)===$n?$n:this;for(var c=0;c<o.length;c++)o[c]=arguments[c];if(t.serialize&&!t.asObject&&As(o,this._serialize,this.serializers,this._stdErrSerialize),t.asObject?i.call(a,Cb(this,r,o,s)):i.apply(a,o),t.transmit){const f=t.transmit.level||e.level,u=or.levels.values[f],d=or.levels.values[r];if(d<u)return;Bb(this,{ts:s,methodLevel:r,methodValue:d,transmitLevel:f,transmitValue:or.levels.values[t.transmit.level||e.level],send:t.transmit.send,val:e.levelVal},o)}}}(e[r]))}function Cb(t,e,r,i){t._serialize&&As(r,t._serialize,t.serializers,t._stdErrSerialize);const n=r.slice();let s=n[0];const o={};i&&(o.time=i),o.level=or.levels.values[e];let a=(t._childLevel|0)+1;if(a<1&&(a=1),s!==null&&typeof s=="object"){for(;a--&&typeof n[0]=="object";)Object.assign(o,n.shift());s=n.length?gu(n.shift(),n):void 0}else typeof s=="string"&&(s=gu(n.shift(),n));return s!==void 0&&(o.msg=s),o}function As(t,e,r,i){for(const n in t)if(i&&t[n]instanceof Error)t[n]=or.stdSerializers.err(t[n]);else if(typeof t[n]=="object"&&!Array.isArray(t[n]))for(const s in t[n])e&&e.indexOf(s)>-1&&s in r&&(t[n][s]=r[s](t[n][s]))}function ki(t,e,r){return function(){const i=new Array(1+arguments.length);i[0]=e;for(var n=1;n<i.length;n++)i[n]=arguments[n-1];return t[r].apply(this,i)}}function Bb(t,e,r){const i=e.send,n=e.ts,s=e.methodLevel,o=e.methodValue,a=e.val,c=t._logEvent.bindings;As(r,t._serialize||Object.keys(t.serializers),t.serializers,t._stdErrSerialize===void 0?!0:t._stdErrSerialize),t._logEvent.ts=n,t._logEvent.messages=r.filter(function(f){return c.indexOf(f)===-1}),t._logEvent.level.label=s,t._logEvent.level.value=o,i(s,t._logEvent,a),t._logEvent=Jo(c)}function Jo(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function Fb(t){const e={type:t.constructor.name,msg:t.message,stack:t.stack};for(const r in t)e[r]===void 0&&(e[r]=t[r]);return e}function Lb(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?yu:vu}function $s(){return{}}function Xo(t){return t}function Dn(){}function yu(){return!1}function vu(){return Date.now()}function qb(){return Math.round(Date.now()/1e3)}function kb(){return new Date(Date.now()).toISOString()}function zb(){function t(e){return typeof e<"u"&&e}try{return typeof globalThis<"u"||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch{return t(self)||t(window)||t(this)||{}}}const Ub={level:"info"},On="custom_context",Qo=1e3*1024;class jb{constructor(e){this.nodeValue=e,this.sizeInBytes=new TextEncoder().encode(this.nodeValue).length,this.next=null}get value(){return this.nodeValue}get size(){return this.sizeInBytes}}class mu{constructor(e){this.head=null,this.tail=null,this.lengthInNodes=0,this.maxSizeInBytes=e,this.sizeInBytes=0}append(e){const r=new jb(e);if(r.size>this.maxSizeInBytes)throw new Error(`[LinkedList] Value too big to insert into list: ${e} with size ${r.size}`);for(;this.size+r.size>this.maxSizeInBytes;)this.shift();this.head?(this.tail&&(this.tail.next=r),this.tail=r):(this.head=r,this.tail=r),this.lengthInNodes++,this.sizeInBytes+=r.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 r=this.head;for(;r!==null;)e.push(r.value),r=r.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 r=e.value;return e=e.next,{done:!1,value:r}}}}}class wu{constructor(e,r=Qo){this.level=e??"error",this.levelValue=Dr.levels.values[this.level],this.MAX_LOG_SIZE_IN_BYTES=r,this.logs=new mu(this.MAX_LOG_SIZE_IN_BYTES)}forwardToConsole(e,r){r===Dr.levels.values.error?console.error(e):r===Dr.levels.values.warn?console.warn(e):r===Dr.levels.values.debug?console.debug(e):r===Dr.levels.values.trace?console.trace(e):console.log(e)}appendToLogs(e){this.logs.append(li({timestamp:new Date().toISOString(),log:e}));const r=typeof e=="string"?JSON.parse(e).level:e.level;r>=this.levelValue&&this.forwardToConsole(e,r)}getLogs(){return this.logs}clearLogs(){this.logs=new mu(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(e){const r=this.getLogArray();return r.push(li({extraMetadata:e})),new Blob(r,{type:"application/json"})}}class Vb{constructor(e,r=Qo){this.baseChunkLogger=new wu(e,r)}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 r=URL.createObjectURL(this.logsToBlob(e)),i=document.createElement("a");i.href=r,i.download=`walletconnect-logs-${new Date().toISOString()}.txt`,document.body.appendChild(i),i.click(),document.body.removeChild(i),URL.revokeObjectURL(r)}}class Kb{constructor(e,r=Qo){this.baseChunkLogger=new wu(e,r)}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 Hb=Object.defineProperty,Wb=Object.defineProperties,Gb=Object.getOwnPropertyDescriptors,_u=Object.getOwnPropertySymbols,Yb=Object.prototype.hasOwnProperty,Zb=Object.prototype.propertyIsEnumerable,xu=(t,e,r)=>e in t?Hb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ds=(t,e)=>{for(var r in e||(e={}))Yb.call(e,r)&&xu(t,r,e[r]);if(_u)for(var r of _u(e))Zb.call(e,r)&&xu(t,r,e[r]);return t},Os=(t,e)=>Wb(t,Gb(e));function ea(t){return Os(Ds({},t),{level:t?.level||Ub.level})}function Jb(t,e=On){return t[e]||""}function Xb(t,e,r=On){return t[r]=e,t}function Mt(t,e=On){let r="";return typeof t.bindings>"u"?r=Jb(t,e):r=t.bindings().context||"",r}function Qb(t,e,r=On){const i=Mt(t,r);return i.trim()?`${i}/${e}`:e}function It(t,e,r=On){const i=Qb(t,e,r),n=t.child({context:i});return Xb(n,i,r)}function eg(t){var e,r;const i=new Vb((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:Dr(Os(Ds({},t.opts),{level:"trace",browser:Os(Ds({},(r=t.opts)==null?void 0:r.browser),{write:n=>i.write(n)})})),chunkLoggerController:i}}function tg(t){var e;const r=new Kb((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:Dr(Os(Ds({},t.opts),{level:"trace"})),chunkLoggerController:r}}function rg(t){return typeof t.loggerOverride<"u"&&typeof t.loggerOverride!="string"?{logger:t.loggerOverride,chunkLoggerController:null}:typeof window<"u"?eg(t):tg(t)}var ig=Object.defineProperty,ng=(t,e,r)=>e in t?ig(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Eu=(t,e,r)=>ng(t,typeof e!="symbol"?e+"":e,r);class sg extends hi{constructor(e){super(),this.opts=e,Eu(this,"protocol","wc"),Eu(this,"version",2)}}var og=Object.defineProperty,ag=(t,e,r)=>e in t?og(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,cg=(t,e,r)=>ag(t,typeof e!="symbol"?e+"":e,r);class fg extends hi{constructor(e,r){super(),this.core=e,this.logger=r,cg(this,"records",new Map)}}class ug{constructor(e,r){this.logger=e,this.core=r}}class hg extends hi{constructor(e,r){super(),this.relayer=e,this.logger=r}}class dg extends hi{constructor(e){super()}}class lg{constructor(e,r,i,n){this.core=e,this.logger=r,this.name=i}}class pg extends hi{constructor(e,r){super(),this.relayer=e,this.logger=r}}class bg extends hi{constructor(e,r){super(),this.core=e,this.logger=r}}class gg{constructor(e,r,i){this.core=e,this.logger=r,this.store=i}}class yg{constructor(e,r){this.projectId=e,this.logger=r}}class vg{constructor(e,r,i){this.core=e,this.logger=r,this.telemetryEnabled=i}}var mg=Object.defineProperty,wg=(t,e,r)=>e in t?mg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Su=(t,e,r)=>wg(t,typeof e!="symbol"?e+"":e,r);class _g{constructor(e){this.opts=e,Su(this,"protocol","wc"),Su(this,"version",2)}}class xg{constructor(e){this.client=e}}function Eg(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Iu(t,...e){if(!Eg(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Au(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Sg(t,e){Iu(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const zi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ta=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function Ig(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function $u(t){return typeof t=="string"&&(t=Ig(t)),Iu(t),t}class Ag{clone(){return this._cloneInto()}}function $g(t){const e=i=>t().update($u(i)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Du(t=32){if(zi&&typeof zi.getRandomValues=="function")return zi.getRandomValues(new Uint8Array(t));if(zi&&typeof zi.randomBytes=="function")return zi.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function Dg(t,e,r,i){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,i);const n=BigInt(32),s=BigInt(4294967295),o=Number(r>>n&s),a=Number(r&s),c=i?4:0,f=i?0:4;t.setUint32(e+c,o,i),t.setUint32(e+f,a,i)}class Og extends Ag{constructor(e,r,i,n){super(),this.blockLen=e,this.outputLen=r,this.padOffset=i,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=ta(this.buffer)}update(e){Au(this);const{view:r,buffer:i,blockLen:n}=this;e=$u(e);const s=e.length;for(let o=0;o<s;){const a=Math.min(n-this.pos,s-o);if(a===n){const c=ta(e);for(;n<=s-o;o+=n)this.process(c,o);continue}i.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===n&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Au(this),Sg(e,this),this.finished=!0;const{buffer:r,view:i,blockLen:n,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>n-o&&(this.process(i,0),o=0);for(let d=o;d<n;d++)r[d]=0;Dg(i,n-8,BigInt(this.length*8),s),this.process(i,0);const a=ta(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],s)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const i=e.slice(0,r);return this.destroy(),i}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:r,buffer:i,length:n,finished:s,destroyed:o,pos:a}=this;return e.length=n,e.pos=a,e.finished=s,e.destroyed=o,n%r&&e.buffer.set(i),e}}const Ms=BigInt(2**32-1),ra=BigInt(32);function Ou(t,e=!1){return e?{h:Number(t&Ms),l:Number(t>>ra&Ms)}:{h:Number(t>>ra&Ms)|0,l:Number(t&Ms)|0}}function Mg(t,e=!1){let r=new Uint32Array(t.length),i=new Uint32Array(t.length);for(let n=0;n<t.length;n++){const{h:s,l:o}=Ou(t[n],e);[r[n],i[n]]=[s,o]}return[r,i]}const Pg=(t,e)=>BigInt(t>>>0)<<ra|BigInt(e>>>0),Rg=(t,e,r)=>t>>>r,Tg=(t,e,r)=>t<<32-r|e>>>r,Ng=(t,e,r)=>t>>>r|e<<32-r,Cg=(t,e,r)=>t<<32-r|e>>>r,Bg=(t,e,r)=>t<<64-r|e>>>r-32,Fg=(t,e,r)=>t>>>r-32|e<<64-r,Lg=(t,e)=>e,qg=(t,e)=>t,kg=(t,e,r)=>t<<r|e>>>32-r,zg=(t,e,r)=>e<<r|t>>>32-r,Ug=(t,e,r)=>e<<r-32|t>>>64-r,jg=(t,e,r)=>t<<r-32|e>>>64-r;function Vg(t,e,r,i){const n=(e>>>0)+(i>>>0);return{h:t+r+(n/2**32|0)|0,l:n|0}}const Kg=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Hg=(t,e,r,i)=>e+r+i+(t/2**32|0)|0,Wg=(t,e,r,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(i>>>0),Gg=(t,e,r,i,n)=>e+r+i+n+(t/2**32|0)|0,Yg=(t,e,r,i,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(i>>>0)+(n>>>0),Zg=(t,e,r,i,n,s)=>e+r+i+n+s+(t/2**32|0)|0,Y={fromBig:Ou,split:Mg,toBig:Pg,shrSH:Rg,shrSL:Tg,rotrSH:Ng,rotrSL:Cg,rotrBH:Bg,rotrBL:Fg,rotr32H:Lg,rotr32L:qg,rotlSH:kg,rotlSL:zg,rotlBH:Ug,rotlBL:jg,add:Vg,add3L:Kg,add3H:Hg,add4L:Wg,add4H:Gg,add5H:Zg,add5L:Yg},[Jg,Xg]=(()=>Y.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))))(),jr=new Uint32Array(80),Vr=new Uint32Array(80);class Qg extends Og{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:r,Bh:i,Bl:n,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:d,Fl:b,Gh:v,Gl:g,Hh:x,Hl:I}=this;return[e,r,i,n,s,o,a,c,f,u,d,b,v,g,x,I]}set(e,r,i,n,s,o,a,c,f,u,d,b,v,g,x,I){this.Ah=e|0,this.Al=r|0,this.Bh=i|0,this.Bl=n|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=u|0,this.Fh=d|0,this.Fl=b|0,this.Gh=v|0,this.Gl=g|0,this.Hh=x|0,this.Hl=I|0}process(e,r){for(let M=0;M<16;M++,r+=4)jr[M]=e.getUint32(r),Vr[M]=e.getUint32(r+=4);for(let M=16;M<80;M++){const P=jr[M-15]|0,T=Vr[M-15]|0,N=Y.rotrSH(P,T,1)^Y.rotrSH(P,T,8)^Y.shrSH(P,T,7),C=Y.rotrSL(P,T,1)^Y.rotrSL(P,T,8)^Y.shrSL(P,T,7),B=jr[M-2]|0,R=Vr[M-2]|0,V=Y.rotrSH(B,R,19)^Y.rotrBH(B,R,61)^Y.shrSH(B,R,6),A=Y.rotrSL(B,R,19)^Y.rotrBL(B,R,61)^Y.shrSL(B,R,6),h=Y.add4L(C,A,Vr[M-7],Vr[M-16]),p=Y.add4H(h,N,V,jr[M-7],jr[M-16]);jr[M]=p|0,Vr[M]=h|0}let{Ah:i,Al:n,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:d,El:b,Fh:v,Fl:g,Gh:x,Gl:I,Hh:D,Hl:O}=this;for(let M=0;M<80;M++){const P=Y.rotrSH(d,b,14)^Y.rotrSH(d,b,18)^Y.rotrBH(d,b,41),T=Y.rotrSL(d,b,14)^Y.rotrSL(d,b,18)^Y.rotrBL(d,b,41),N=d&v^~d&x,C=b&g^~b&I,B=Y.add5L(O,T,C,Xg[M],Vr[M]),R=Y.add5H(B,D,P,N,Jg[M],jr[M]),V=B|0,A=Y.rotrSH(i,n,28)^Y.rotrBH(i,n,34)^Y.rotrBH(i,n,39),h=Y.rotrSL(i,n,28)^Y.rotrBL(i,n,34)^Y.rotrBL(i,n,39),p=i&s^i&a^s&a,m=n&o^n&c^o&c;D=x|0,O=I|0,x=v|0,I=g|0,v=d|0,g=b|0,{h:d,l:b}=Y.add(f|0,u|0,R|0,V|0),f=a|0,u=c|0,a=s|0,c=o|0,s=i|0,o=n|0;const y=Y.add3L(V,h,m);i=Y.add3H(y,R,A,p),n=y|0}({h:i,l:n}=Y.add(this.Ah|0,this.Al|0,i|0,n|0)),{h:s,l:o}=Y.add(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=Y.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Y.add(this.Dh|0,this.Dl|0,f|0,u|0),{h:d,l:b}=Y.add(this.Eh|0,this.El|0,d|0,b|0),{h:v,l:g}=Y.add(this.Fh|0,this.Fl|0,v|0,g|0),{h:x,l:I}=Y.add(this.Gh|0,this.Gl|0,x|0,I|0),{h:D,l:O}=Y.add(this.Hh|0,this.Hl|0,D|0,O|0),this.set(i,n,s,o,a,c,f,u,d,b,v,g,x,I,D,O)}roundClean(){jr.fill(0),Vr.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const ey=$g(()=>new Qg);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ia=BigInt(0),Mu=BigInt(1),ty=BigInt(2);function na(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function sa(t){if(!na(t))throw new Error("Uint8Array expected")}function oa(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const ry=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function aa(t){sa(t);let e="";for(let r=0;r<t.length;r++)e+=ry[t[r]];return e}function Pu(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?ia:BigInt("0x"+t)}const Or={_0:48,_9:57,A:65,F:70,a:97,f:102};function Ru(t){if(t>=Or._0&&t<=Or._9)return t-Or._0;if(t>=Or.A&&t<=Or.F)return t-(Or.A-10);if(t>=Or.a&&t<=Or.f)return t-(Or.a-10)}function Tu(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const i=new Uint8Array(r);for(let n=0,s=0;n<r;n++,s+=2){const o=Ru(t.charCodeAt(s)),a=Ru(t.charCodeAt(s+1));if(o===void 0||a===void 0){const c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}i[n]=o*16+a}return i}function iy(t){return Pu(aa(t))}function Ps(t){return sa(t),Pu(aa(Uint8Array.from(t).reverse()))}function Nu(t,e){return Tu(t.toString(16).padStart(e*2,"0"))}function ca(t,e){return Nu(t,e).reverse()}function Mr(t,e,r){let i;if(typeof e=="string")try{i=Tu(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(na(e))i=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const n=i.length;if(typeof r=="number"&&n!==r)throw new Error(t+" of length "+r+" expected, got "+n);return i}function Cu(...t){let e=0;for(let i=0;i<t.length;i++){const n=t[i];sa(n),e+=n.length}const r=new Uint8Array(e);for(let i=0,n=0;i<t.length;i++){const s=t[i];r.set(s,n),n+=s.length}return r}const fa=t=>typeof t=="bigint"&&ia<=t;function ny(t,e,r){return fa(t)&&fa(e)&&fa(r)&&e<=t&&t<r}function Mn(t,e,r,i){if(!ny(e,r,i))throw new Error("expected valid "+t+": "+r+" <= n < "+i+", got "+e)}function sy(t){let e;for(e=0;t>ia;t>>=Mu,e+=1);return e}const oy=t=>(ty<<BigInt(t-1))-Mu,ay={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||na(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function ua(t,e,r={}){const i=(n,s,o)=>{const a=ay[s];if(typeof a!="function")throw new Error("invalid validator function");const c=t[n];if(!(o&&c===void 0)&&!a(c,t))throw new Error("param "+String(n)+" is invalid. Expected "+s+", got "+c)};for(const[n,s]of Object.entries(e))i(n,s,!1);for(const[n,s]of Object.entries(r))i(n,s,!0);return t}function Bu(t){const e=new WeakMap;return(r,...i)=>{const n=e.get(r);if(n!==void 0)return n;const s=t(r,...i);return e.set(r,s),s}}const tt=BigInt(0),Ae=BigInt(1),pi=BigInt(2),cy=BigInt(3),ha=BigInt(4),Fu=BigInt(5),Lu=BigInt(8);function Xe(t,e){const r=t%e;return r>=tt?r:e+r}function fy(t,e,r){if(e<tt)throw new Error("invalid exponent, negatives unsupported");if(r<=tt)throw new Error("invalid modulus");if(r===Ae)return tt;let i=Ae;for(;e>tt;)e&Ae&&(i=i*t%r),t=t*t%r,e>>=Ae;return i}function ar(t,e,r){let i=t;for(;e-- >tt;)i*=i,i%=r;return i}function qu(t,e){if(t===tt)throw new Error("invert: expected non-zero number");if(e<=tt)throw new Error("invert: expected positive modulus, got "+e);let r=Xe(t,e),i=e,n=tt,s=Ae;for(;r!==tt;){const o=i/r,a=i%r,c=n-s*o;i=r,r=a,n=s,s=c}if(i!==Ae)throw new Error("invert: does not exist");return Xe(n,e)}function uy(t){const e=(t-Ae)/pi;let r,i,n;for(r=t-Ae,i=0;r%pi===tt;r/=pi,i++);for(n=pi;n<t&&fy(n,e,t)!==t-Ae;n++)if(n>1e3)throw new Error("Cannot find square root: likely non-prime P");if(i===1){const o=(t+Ae)/ha;return function(a,c){const f=a.pow(c,o);if(!a.eql(a.sqr(f),c))throw new Error("Cannot find square root");return f}}const s=(r+Ae)/pi;return function(o,a){if(o.pow(a,e)===o.neg(o.ONE))throw new Error("Cannot find square root");let c=i,f=o.pow(o.mul(o.ONE,n),r),u=o.pow(a,s),d=o.pow(a,r);for(;!o.eql(d,o.ONE);){if(o.eql(d,o.ZERO))return o.ZERO;let b=1;for(let g=o.sqr(d);b<c&&!o.eql(g,o.ONE);b++)g=o.sqr(g);const v=o.pow(f,Ae<<BigInt(c-b-1));f=o.sqr(v),u=o.mul(u,v),d=o.mul(d,f),c=b}return u}}function hy(t){if(t%ha===cy){const e=(t+Ae)/ha;return function(r,i){const n=r.pow(i,e);if(!r.eql(r.sqr(n),i))throw new Error("Cannot find square root");return n}}if(t%Lu===Fu){const e=(t-Fu)/Lu;return function(r,i){const n=r.mul(i,pi),s=r.pow(n,e),o=r.mul(i,s),a=r.mul(r.mul(o,pi),s),c=r.mul(o,r.sub(a,r.ONE));if(!r.eql(r.sqr(c),i))throw new Error("Cannot find square root");return c}}return uy(t)}const dy=(t,e)=>(Xe(t,e)&Ae)===Ae,ly=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function py(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=ly.reduce((i,n)=>(i[n]="function",i),e);return ua(t,r)}function by(t,e,r){if(r<tt)throw new Error("invalid exponent, negatives unsupported");if(r===tt)return t.ONE;if(r===Ae)return e;let i=t.ONE,n=e;for(;r>tt;)r&Ae&&(i=t.mul(i,n)),n=t.sqr(n),r>>=Ae;return i}function gy(t,e){const r=new Array(e.length),i=e.reduce((s,o,a)=>t.is0(o)?s:(r[a]=s,t.mul(s,o)),t.ONE),n=t.inv(i);return e.reduceRight((s,o,a)=>t.is0(o)?s:(r[a]=t.mul(s,r[a]),t.mul(s,o)),n),r}function ku(t,e){const r=e!==void 0?e:t.toString(2).length,i=Math.ceil(r/8);return{nBitLength:r,nByteLength:i}}function zu(t,e,r=!1,i={}){if(t<=tt)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:n,nByteLength:s}=ku(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:r,BITS:n,BYTES:s,MASK:oy(n),ZERO:tt,ONE:Ae,create:c=>Xe(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return tt<=c&&c<t},is0:c=>c===tt,isOdd:c=>(c&Ae)===Ae,neg:c=>Xe(-c,t),eql:(c,f)=>c===f,sqr:c=>Xe(c*c,t),add:(c,f)=>Xe(c+f,t),sub:(c,f)=>Xe(c-f,t),mul:(c,f)=>Xe(c*f,t),pow:(c,f)=>by(a,c,f),div:(c,f)=>Xe(c*qu(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>qu(c,t),sqrt:i.sqrt||(c=>(o||(o=hy(t)),o(a,c))),invertBatch:c=>gy(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>r?ca(c,s):Nu(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?Ps(c):iy(c)}});return Object.freeze(a)}const Uu=BigInt(0),Rs=BigInt(1);function da(t,e){const r=e.negate();return t?r:e}function ju(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function la(t,e){ju(t,e);const r=Math.ceil(e/t)+1,i=2**(t-1);return{windows:r,windowSize:i}}function yy(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,i)=>{if(!(r instanceof e))throw new Error("invalid point at index "+i)})}function vy(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,i)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+i)})}const pa=new WeakMap,Vu=new WeakMap;function ba(t){return Vu.get(t)||1}function my(t,e){return{constTimeNegate:da,hasPrecomputes(r){return ba(r)!==1},unsafeLadder(r,i,n=t.ZERO){let s=r;for(;i>Uu;)i&Rs&&(n=n.add(s)),s=s.double(),i>>=Rs;return n},precomputeWindow(r,i){const{windows:n,windowSize:s}=la(i,e),o=[];let a=r,c=a;for(let f=0;f<n;f++){c=a,o.push(c);for(let u=1;u<s;u++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(r,i,n){const{windows:s,windowSize:o}=la(r,e);let a=t.ZERO,c=t.BASE;const f=BigInt(2**r-1),u=2**r,d=BigInt(r);for(let b=0;b<s;b++){const v=b*o;let g=Number(n&f);n>>=d,g>o&&(g-=u,n+=Rs);const x=v,I=v+Math.abs(g)-1,D=b%2!==0,O=g<0;g===0?c=c.add(da(D,i[x])):a=a.add(da(O,i[I]))}return{p:a,f:c}},wNAFUnsafe(r,i,n,s=t.ZERO){const{windows:o,windowSize:a}=la(r,e),c=BigInt(2**r-1),f=2**r,u=BigInt(r);for(let d=0;d<o;d++){const b=d*a;if(n===Uu)break;let v=Number(n&c);if(n>>=u,v>a&&(v-=f,n+=Rs),v===0)continue;let g=i[b+Math.abs(v)-1];v<0&&(g=g.negate()),s=s.add(g)}return s},getPrecomputes(r,i,n){let s=pa.get(i);return s||(s=this.precomputeWindow(i,r),r!==1&&pa.set(i,n(s))),s},wNAFCached(r,i,n){const s=ba(r);return this.wNAF(s,this.getPrecomputes(s,r,n),i)},wNAFCachedUnsafe(r,i,n,s){const o=ba(r);return o===1?this.unsafeLadder(r,i,s):this.wNAFUnsafe(o,this.getPrecomputes(o,r,n),i,s)},setWindowSize(r,i){ju(i,e),Vu.set(r,i),pa.delete(r)}}}function wy(t,e,r,i){if(yy(r,t),vy(i,e),r.length!==i.length)throw new Error("arrays of points and scalars must have equal length");const n=t.ZERO,s=sy(BigInt(r.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=(1<<o)-1,c=new Array(a+1).fill(n),f=Math.floor((e.BITS-1)/o)*o;let u=n;for(let d=f;d>=0;d-=o){c.fill(n);for(let v=0;v<i.length;v++){const g=i[v],x=Number(g>>BigInt(d)&BigInt(a));c[x]=c[x].add(r[v])}let b=n;for(let v=c.length-1,g=n;v>0;v--)g=g.add(c[v]),b=b.add(g);if(u=u.add(b),d!==0)for(let v=0;v<o;v++)u=u.double()}return u}function _y(t){return py(t.Fp),ua(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ku(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}const Jt=BigInt(0),Pt=BigInt(1),Ts=BigInt(2),xy=BigInt(8),Ey={zip215:!0};function Sy(t){const e=_y(t);return ua(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Iy(t){const e=Sy(t),{Fp:r,n:i,prehash:n,hash:s,randomBytes:o,nByteLength:a,h:c}=e,f=Ts<<BigInt(a*8)-Pt,u=r.create,d=zu(e.n,e.nBitLength),b=e.uvRatio||((y,w)=>{try{return{isValid:!0,value:r.sqrt(y*r.inv(w))}}catch{return{isValid:!1,value:Jt}}}),v=e.adjustScalarBytes||(y=>y),g=e.domain||((y,w,S)=>{if(oa("phflag",S),w.length||S)throw new Error("Contexts/pre-hash are not supported");return y});function x(y,w){Mn("coordinate "+y,w,Jt,f)}function I(y){if(!(y instanceof M))throw new Error("ExtendedPoint expected")}const D=Bu((y,w)=>{const{ex:S,ey:$,ez:_}=y,l=y.is0();w==null&&(w=l?xy:r.inv(_));const E=u(S*w),F=u($*w),L=u(_*w);if(l)return{x:Jt,y:Pt};if(L!==Pt)throw new Error("invZ was invalid");return{x:E,y:F}}),O=Bu(y=>{const{a:w,d:S}=e;if(y.is0())throw new Error("bad point: ZERO");const{ex:$,ey:_,ez:l,et:E}=y,F=u($*$),L=u(_*_),q=u(l*l),j=u(q*q),K=u(F*w),W=u(q*u(K+L)),Z=u(j+u(S*u(F*L)));if(W!==Z)throw new Error("bad point: equation left != right (1)");const H=u($*_),G=u(l*E);if(H!==G)throw new Error("bad point: equation left != right (2)");return!0});class M{constructor(w,S,$,_){this.ex=w,this.ey=S,this.ez=$,this.et=_,x("x",w),x("y",S),x("z",$),x("t",_),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof M)throw new Error("extended point not allowed");const{x:S,y:$}=w||{};return x("x",S),x("y",$),new M(S,$,Pt,u(S*$))}static normalizeZ(w){const S=r.invertBatch(w.map($=>$.ez));return w.map(($,_)=>$.toAffine(S[_])).map(M.fromAffine)}static msm(w,S){return wy(M,d,w,S)}_setWindowSize(w){N.setWindowSize(this,w)}assertValidity(){O(this)}equals(w){I(w);const{ex:S,ey:$,ez:_}=this,{ex:l,ey:E,ez:F}=w,L=u(S*F),q=u(l*_),j=u($*F),K=u(E*_);return L===q&&j===K}is0(){return this.equals(M.ZERO)}negate(){return new M(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){const{a:w}=e,{ex:S,ey:$,ez:_}=this,l=u(S*S),E=u($*$),F=u(Ts*u(_*_)),L=u(w*l),q=S+$,j=u(u(q*q)-l-E),K=L+E,W=K-F,Z=L-E,H=u(j*W),G=u(K*Z),Me=u(j*Z),X=u(W*K);return new M(H,G,X,Me)}add(w){I(w);const{a:S,d:$}=e,{ex:_,ey:l,ez:E,et:F}=this,{ex:L,ey:q,ez:j,et:K}=w;if(S===BigInt(-1)){const ge=u((l-_)*(q+L)),gs=u((l+_)*(q-L)),be=u(gs-ge);if(be===Jt)return this.double();const ye=u(E*Ts*K),ys=u(F*Ts*j),ve=ys+ye,me=gs+ge,vs=ys-ye,Ee=u(ve*be),Se=u(me*vs),Fo=u(ve*vs),Ie=u(be*me);return new M(Ee,Se,Ie,Fo)}const W=u(_*L),Z=u(l*q),H=u(F*$*K),G=u(E*j),Me=u((_+l)*(L+q)-W-Z),X=G-H,ie=G+H,St=u(Z-S*W),fe=u(Me*X),_e=u(ie*St),Bo=u(Me*St),xe=u(X*ie);return new M(fe,_e,xe,Bo)}subtract(w){return this.add(w.negate())}wNAF(w){return N.wNAFCached(this,w,M.normalizeZ)}multiply(w){const S=w;Mn("scalar",S,Pt,i);const{p:$,f:_}=this.wNAF(S);return M.normalizeZ([$,_])[0]}multiplyUnsafe(w,S=M.ZERO){const $=w;return Mn("scalar",$,Jt,i),$===Jt?T:this.is0()||$===Pt?this:N.wNAFCachedUnsafe(this,$,M.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return N.unsafeLadder(this,i).is0()}toAffine(w){return D(this,w)}clearCofactor(){const{h:w}=e;return w===Pt?this:this.multiplyUnsafe(w)}static fromHex(w,S=!1){const{d:$,a:_}=e,l=r.BYTES;w=Mr("pointHex",w,l),oa("zip215",S);const E=w.slice(),F=w[l-1];E[l-1]=F&-129;const L=Ps(E),q=S?f:r.ORDER;Mn("pointHex.y",L,Jt,q);const j=u(L*L),K=u(j-Pt),W=u($*j-_);let{isValid:Z,value:H}=b(K,W);if(!Z)throw new Error("Point.fromHex: invalid y coordinate");const G=(H&Pt)===Pt,Me=(F&128)!==0;if(!S&&H===Jt&&Me)throw new Error("Point.fromHex: x=0 and x_0=1");return Me!==G&&(H=u(-H)),M.fromAffine({x:H,y:L})}static fromPrivateKey(w){return R(w).point}toRawBytes(){const{x:w,y:S}=this.toAffine(),$=ca(S,r.BYTES);return $[$.length-1]|=w&Pt?128:0,$}toHex(){return aa(this.toRawBytes())}}M.BASE=new M(e.Gx,e.Gy,Pt,u(e.Gx*e.Gy)),M.ZERO=new M(Jt,Pt,Pt,Jt);const{BASE:P,ZERO:T}=M,N=my(M,a*8);function C(y){return Xe(y,i)}function B(y){return C(Ps(y))}function R(y){const w=r.BYTES;y=Mr("private key",y,w);const S=Mr("hashed private key",s(y),2*w),$=v(S.slice(0,w)),_=S.slice(w,2*w),l=B($),E=P.multiply(l),F=E.toRawBytes();return{head:$,prefix:_,scalar:l,point:E,pointBytes:F}}function V(y){return R(y).pointBytes}function A(y=new Uint8Array,...w){const S=Cu(...w);return B(s(g(S,Mr("context",y),!!n)))}function h(y,w,S={}){y=Mr("message",y),n&&(y=n(y));const{prefix:$,scalar:_,pointBytes:l}=R(w),E=A(S.context,$,y),F=P.multiply(E).toRawBytes(),L=A(S.context,F,l,y),q=C(E+L*_);Mn("signature.s",q,Jt,i);const j=Cu(F,ca(q,r.BYTES));return Mr("result",j,r.BYTES*2)}const p=Ey;function m(y,w,S,$=p){const{context:_,zip215:l}=$,E=r.BYTES;y=Mr("signature",y,2*E),w=Mr("message",w),S=Mr("publicKey",S,E),l!==void 0&&oa("zip215",l),n&&(w=n(w));const F=Ps(y.slice(E,2*E));let L,q,j;try{L=M.fromHex(S,l),q=M.fromHex(y.slice(0,E),l),j=P.multiplyUnsafe(F)}catch{return!1}if(!l&&L.isSmallOrder())return!1;const K=A(_,q.toRawBytes(),L.toRawBytes(),w);return q.add(L.multiplyUnsafe(K)).subtract(j).clearCofactor().equals(M.ZERO)}return P._setWindowSize(8),{CURVE:e,getPublicKey:V,sign:h,verify:m,ExtendedPoint:M,utils:{getExtendedPublicKey:R,randomPrivateKey:()=>o(r.BYTES),precompute(y=8,w=M.BASE){return w._setWindowSize(y),w.multiply(BigInt(3)),w}}}}BigInt(0),BigInt(1);const ga=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Ku=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);const Ay=BigInt(1),Hu=BigInt(2);BigInt(3);const $y=BigInt(5),Dy=BigInt(8);function Oy(t){const e=BigInt(10),r=BigInt(20),i=BigInt(40),n=BigInt(80),s=ga,o=t*t%s*t%s,a=ar(o,Hu,s)*o%s,c=ar(a,Ay,s)*t%s,f=ar(c,$y,s)*c%s,u=ar(f,e,s)*f%s,d=ar(u,r,s)*u%s,b=ar(d,i,s)*d%s,v=ar(b,n,s)*b%s,g=ar(v,n,s)*b%s,x=ar(g,e,s)*f%s;return{pow_p_5_8:ar(x,Hu,s)*t%s,b2:o}}function My(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function Py(t,e){const r=ga,i=Xe(e*e*e,r),n=Xe(i*i*e,r),s=Oy(t*n).pow_p_5_8;let o=Xe(t*i*s,r);const a=Xe(e*o*o,r),c=o,f=Xe(o*Ku,r),u=a===t,d=a===Xe(-t,r),b=a===Xe(-t*Ku,r);return u&&(o=c),(d||b)&&(o=f),dy(o,r)&&(o=Xe(-o,r)),{isValid:u||d,value:o}}const Ry=(()=>zu(ga,void 0,!0))(),Ty=(()=>({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:Ry,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:Dy,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:ey,randomBytes:Du,adjustScalarBytes:My,uvRatio:Py}))(),Wu=(()=>Iy(Ty))(),Ny="EdDSA",Cy="JWT",Ns=".",Cs="base64url",Gu="utf8",Yu="utf8",By=":",Fy="did",Ly="key",Zu="base58btc",qy="z",ky="K36",zy=32;function ya(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Ju(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?ya(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function Xu(t,e){e||(e=t.reduce((n,s)=>n+s.length,0));const r=Ju(e);let i=0;for(const n of t)r.set(n,i),i+=n.length;return ya(r)}function Uy(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i<r.length;i++)r[i]=255;for(var n=0;n<t.length;n++){var s=t.charAt(n),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=n}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var x=0,I=0,D=0,O=g.length;D!==O&&g[D]===0;)D++,x++;for(var M=(O-D)*u+1>>>0,P=new Uint8Array(M);D!==O;){for(var T=g[D],N=0,C=M-1;(T!==0||N<I)&&C!==-1;C--,N++)T+=256*P[C]>>>0,P[C]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");I=N,D++}for(var B=M-I;B!==M&&P[B]===0;)B++;for(var R=c.repeat(x);B<M;++B)R+=t.charAt(P[B]);return R}function b(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var x=0;if(g[x]!==" "){for(var I=0,D=0;g[x]===c;)I++,x++;for(var O=(g.length-x)*f+1>>>0,M=new Uint8Array(O);g[x];){var P=r[g.charCodeAt(x)];if(P===255)return;for(var T=0,N=O-1;(P!==0||T<D)&&N!==-1;N--,T++)P+=a*M[N]>>>0,M[N]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");D=T,x++}if(g[x]!==" "){for(var C=O-D;C!==O&&M[C]===0;)C++;for(var B=new Uint8Array(I+(O-C)),R=I;C!==O;)B[R++]=M[C++];return B}}}function v(g){var x=b(g);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:b,decode:v}}var jy=Uy,Vy=jy;const Qu=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},Ky=t=>new TextEncoder().encode(t),Hy=t=>new TextDecoder().decode(t);class Wy{constructor(e,r,i){this.name=e,this.prefix=r,this.baseEncode=i}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class Gy{constructor(e,r,i){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.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 eh(this,e)}}class Yy{constructor(e){this.decoders=e}or(e){return eh(this,e)}decode(e){const r=e[0],i=this.decoders[r];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 eh=(t,e)=>new Yy({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class Zy{constructor(e,r,i,n){this.name=e,this.prefix=r,this.baseEncode=i,this.baseDecode=n,this.encoder=new Wy(e,r,i),this.decoder=new Gy(e,r,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Bs=({name:t,prefix:e,encode:r,decode:i})=>new Zy(t,e,r,i),Pn=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=Vy(r,e);return Bs({prefix:t,name:e,encode:i,decode:s=>Qu(n(s))})},Jy=(t,e,r,i)=>{const n={};for(let u=0;u<e.length;++u)n[e[u]]=u;let s=t.length;for(;t[s-1]==="=";)--s;const o=new Uint8Array(s*r/8|0);let a=0,c=0,f=0;for(let u=0;u<s;++u){const d=n[t[u]];if(d===void 0)throw new SyntaxError(`Non-${i} character`);c=c<<r|d,a+=r,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},Xy=(t,e,r)=>{const i=e[e.length-1]==="=",n=(1<<r)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<<r-o]),i)for(;s.length*r&7;)s+="=";return s},ut=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>Bs({prefix:e,name:t,encode(n){return Xy(n,i,r)},decode(n){return Jy(n,i,r,t)}}),Qy=Bs({prefix:"\0",name:"identity",encode:t=>Hy(t),decode:t=>Ky(t)});var e2=Object.freeze({__proto__:null,identity:Qy});const t2=ut({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var r2=Object.freeze({__proto__:null,base2:t2});const i2=ut({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var n2=Object.freeze({__proto__:null,base8:i2});const s2=Pn({prefix:"9",name:"base10",alphabet:"0123456789"});var o2=Object.freeze({__proto__:null,base10:s2});const a2=ut({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),c2=ut({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var f2=Object.freeze({__proto__:null,base16:a2,base16upper:c2});const u2=ut({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),h2=ut({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),d2=ut({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),l2=ut({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),p2=ut({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),b2=ut({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),g2=ut({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),y2=ut({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),v2=ut({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var m2=Object.freeze({__proto__:null,base32:u2,base32upper:h2,base32pad:d2,base32padupper:l2,base32hex:p2,base32hexupper:b2,base32hexpad:g2,base32hexpadupper:y2,base32z:v2});const w2=Pn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),_2=Pn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var x2=Object.freeze({__proto__:null,base36:w2,base36upper:_2});const E2=Pn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),S2=Pn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var I2=Object.freeze({__proto__:null,base58btc:E2,base58flickr:S2});const A2=ut({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),$2=ut({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),D2=ut({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),O2=ut({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var M2=Object.freeze({__proto__:null,base64:A2,base64pad:$2,base64url:D2,base64urlpad:O2});const th=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),P2=th.reduce((t,e,r)=>(t[r]=e,t),[]),R2=th.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function T2(t){return t.reduce((e,r)=>(e+=P2[r],e),"")}function N2(t){const e=[];for(const r of t){const i=R2[r.codePointAt(0)];if(i===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}const C2=Bs({prefix:"\u{1F680}",name:"base256emoji",encode:T2,decode:N2});var B2=Object.freeze({__proto__:null,base256emoji:C2}),F2=ih,rh=128,L2=127,q2=~L2,k2=Math.pow(2,31);function ih(t,e,r){e=e||[],r=r||0;for(var i=r;t>=k2;)e[r++]=t&255|rh,t/=128;for(;t&q2;)e[r++]=t&255|rh,t>>>=7;return e[r]=t|0,ih.bytes=r-i+1,e}var z2=va,U2=128,nh=127;function va(t,i){var r=0,i=i||0,n=0,s=i,o,a=t.length;do{if(s>=a)throw va.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=n<28?(o&nh)<<n:(o&nh)*Math.pow(2,n),n+=7}while(o>=U2);return va.bytes=s-i,r}var j2=Math.pow(2,7),V2=Math.pow(2,14),K2=Math.pow(2,21),H2=Math.pow(2,28),W2=Math.pow(2,35),G2=Math.pow(2,42),Y2=Math.pow(2,49),Z2=Math.pow(2,56),J2=Math.pow(2,63),X2=function(t){return t<j2?1:t<V2?2:t<K2?3:t<H2?4:t<W2?5:t<G2?6:t<Y2?7:t<Z2?8:t<J2?9:10},Q2={encode:F2,decode:z2,encodingLength:X2},sh=Q2;const oh=(t,e,r=0)=>(sh.encode(t,e,r),e),ah=t=>sh.encodingLength(t),ma=(t,e)=>{const r=e.byteLength,i=ah(t),n=i+ah(r),s=new Uint8Array(n+r);return oh(t,s,0),oh(r,s,i),s.set(e,n),new ev(t,r,e,s)};class ev{constructor(e,r,i,n){this.code=e,this.size=r,this.digest=i,this.bytes=n}}const ch=({name:t,code:e,encode:r})=>new tv(t,e,r);class tv{constructor(e,r,i){this.name=e,this.code=r,this.encode=i}digest(e){if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?ma(this.code,r):r.then(i=>ma(this.code,i))}else throw Error("Unknown type, must be binary type")}}const fh=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),rv=ch({name:"sha2-256",code:18,encode:fh("SHA-256")}),iv=ch({name:"sha2-512",code:19,encode:fh("SHA-512")});var nv=Object.freeze({__proto__:null,sha256:rv,sha512:iv});const uh=0,sv="identity",hh=Qu;var ov=Object.freeze({__proto__:null,identity:{code:uh,name:sv,encode:hh,digest:t=>ma(uh,hh(t))}});new TextEncoder,new TextDecoder;const dh={...e2,...r2,...n2,...o2,...f2,...m2,...x2,...I2,...M2,...B2};({...nv,...ov});function lh(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const ph=lh("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),wa=lh("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);const e=Ju(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),bh={utf8:ph,"utf-8":ph,hex:dh.base16,latin1:wa,ascii:wa,binary:wa,...dh};function Fs(t,e="utf8"){const r=bh[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}function Ui(t,e="utf8"){const r=bh[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?ya(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}function gh(t){return Li(Fs(Ui(t,Cs),Gu))}function Ls(t){return Fs(Ui(li(t),Gu),Cs)}function yh(t){const e=Ui(ky,Zu),r=qy+Fs(Xu([e,t]),Zu);return[Fy,Ly,r].join(By)}function av(t){return Fs(t,Cs)}function cv(t){return Ui(t,Cs)}function fv(t){return Ui([Ls(t.header),Ls(t.payload)].join(Ns),Yu)}function uv(t){return[Ls(t.header),Ls(t.payload),av(t.signature)].join(Ns)}function _a(t){const e=t.split(Ns),r=gh(e[0]),i=gh(e[1]),n=cv(e[2]),s=Ui(e.slice(0,2).join(Ns),Yu);return{header:r,payload:i,signature:n,data:s}}function vh(t=Du(zy)){const e=Wu.getPublicKey(t);return{secretKey:Xu([t,e]),publicKey:e}}async function hv(t,e,r,i,n=z.fromMiliseconds(Date.now())){const s={alg:Ny,typ:Cy},o=yh(i.publicKey),a=n+r,c={iss:o,sub:t,aud:e,iat:n,exp:a},f=fv({header:s,payload:c}),u=Wu.sign(f,i.secretKey.slice(0,32));return uv({header:s,payload:c,signature:u})}var mh=function(t,e,r){if(r||arguments.length===2)for(var i=0,n=e.length,s;i<n;i++)(s||!(i in e))&&(s||(s=Array.prototype.slice.call(e,0,i)),s[i]=e[i]);return t.concat(s||Array.prototype.slice.call(e))},dv=function(){function t(e,r,i){this.name=e,this.version=r,this.os=i,this.type="browser"}return t}(),lv=function(){function t(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return t}(),pv=function(){function t(e,r,i,n){this.name=e,this.version=r,this.os=i,this.bot=n,this.type="bot-device"}return t}(),bv=function(){function t(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return t}(),gv=function(){function t(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return t}(),yv=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,vv=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,wh=3,mv=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",yv]],_h=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function wv(t){return t?xh(t):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new gv:typeof navigator<"u"?xh(navigator.userAgent):Ev()}function _v(t){return t!==""&&mv.reduce(function(e,r){var i=r[0],n=r[1];if(e)return e;var s=n.exec(t);return!!s&&[i,s]},!1)}function xh(t){var e=_v(t);if(!e)return null;var r=e[0],i=e[1];if(r==="searchbot")return new bv;var n=i[1]&&i[1].split(".").join("_").split("_").slice(0,3);n?n.length<wh&&(n=mh(mh([],n,!0),Sv(wh-n.length),!0)):n=[];var s=n.join("."),o=xv(t),a=vv.exec(t);return a&&a[1]?new pv(r,s,o,a[1]):new dv(r,s,o)}function xv(t){for(var e=0,r=_h.length;e<r;e++){var i=_h[e],n=i[0],s=i[1],o=s.exec(t);if(o)return n}return null}function Ev(){var t=typeof process<"u"&&process.version;return t?new lv(process.version.slice(1)):null}function Sv(t){for(var e=[],r=0;r<t;r++)e.push("0");return e}var ue={};Object.defineProperty(ue,"__esModule",{value:!0}),ue.getLocalStorage=ue.getLocalStorageOrThrow=ue.getCrypto=ue.getCryptoOrThrow=Eh=ue.getLocation=ue.getLocationOrThrow=xa=ue.getNavigator=ue.getNavigatorOrThrow=Rn=ue.getDocument=ue.getDocumentOrThrow=ue.getFromWindowOrThrow=ue.getFromWindow=void 0;function bi(t){let e;return typeof window<"u"&&typeof window[t]<"u"&&(e=window[t]),e}ue.getFromWindow=bi;function ji(t){const e=bi(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}ue.getFromWindowOrThrow=ji;function Iv(){return ji("document")}ue.getDocumentOrThrow=Iv;function Av(){return bi("document")}var Rn=ue.getDocument=Av;function $v(){return ji("navigator")}ue.getNavigatorOrThrow=$v;function Dv(){return bi("navigator")}var xa=ue.getNavigator=Dv;function Ov(){return ji("location")}ue.getLocationOrThrow=Ov;function Mv(){return bi("location")}var Eh=ue.getLocation=Mv;function Pv(){return ji("crypto")}ue.getCryptoOrThrow=Pv;function Rv(){return bi("crypto")}ue.getCrypto=Rv;function Tv(){return ji("localStorage")}ue.getLocalStorageOrThrow=Tv;function Nv(){return bi("localStorage")}ue.getLocalStorage=Nv;var Ea={};Object.defineProperty(Ea,"__esModule",{value:!0});var Sh=Ea.getWindowMetadata=void 0;const Ih=ue;function Cv(){let t,e;try{t=Ih.getDocumentOrThrow(),e=Ih.getLocationOrThrow()}catch{return null}function r(){const d=t.getElementsByTagName("link"),b=[];for(let v=0;v<d.length;v++){const g=d[v],x=g.getAttribute("rel");if(x&&x.toLowerCase().indexOf("icon")>-1){const I=g.getAttribute("href");if(I)if(I.toLowerCase().indexOf("https:")===-1&&I.toLowerCase().indexOf("http:")===-1&&I.indexOf("//")!==0){let D=e.protocol+"//"+e.host;if(I.indexOf("/")===0)D+=I;else{const O=e.pathname.split("/");O.pop();const M=O.join("/");D+=M+"/"+I}b.push(D)}else if(I.indexOf("//")===0){const D=e.protocol+I;b.push(D)}else b.push(I)}}return b}function i(...d){const b=t.getElementsByTagName("meta");for(let v=0;v<b.length;v++){const g=b[v],x=["itemprop","property","name"].map(I=>g.getAttribute(I)).filter(I=>I?d.includes(I):!1);if(x.length&&x){const I=g.getAttribute("content");if(I)return I}}return""}function n(){let d=i("name","og:site_name","og:title","twitter:title");return d||(d=t.title),d}function s(){return i("description","og:description","twitter:description","keywords")}const o=n(),a=s(),c=e.origin,f=r();return{description:a,url:c,icons:f,name:o}}Sh=Ea.getWindowMetadata=Cv;function Tn(t,{strict:e=!0}={}){return!t||typeof t!="string"?!1:e?/^0x[0-9a-fA-F]*$/.test(t):t.startsWith("0x")}function Ah(t){return Tn(t,{strict:!1})?Math.ceil((t.length-2)/2):t.length}const $h="2.23.2";let Sa={getDocsUrl:({docsBaseUrl:t,docsPath:e="",docsSlug:r})=>e?`${t??"https://viem.sh"}${e}${r?`#${r}`:""}`:void 0,version:`viem@${$h}`};class gi extends Error{constructor(e,r={}){const i=(()=>r.cause instanceof gi?r.cause.details:r.cause?.message?r.cause.message:r.details)(),n=(()=>r.cause instanceof gi&&r.cause.docsPath||r.docsPath)(),s=Sa.getDocsUrl?.({...r,docsPath:n}),o=[e||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...i?[`Details: ${i}`]:[],...Sa.version?[`Version: ${Sa.version}`]:[]].join(`
15
- `);super(o,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=i,this.docsPath=n,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=e,this.version=$h}walk(e){return Dh(this,e)}}function Dh(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause!==void 0?Dh(t.cause,e):e?null:t}class Oh extends gi{constructor({size:e,targetSize:r,type:i}){super(`${i.charAt(0).toUpperCase()}${i.slice(1).toLowerCase()} size (${e}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}function Vi(t,{dir:e,size:r=32}={}){return typeof t=="string"?Bv(t,{dir:e,size:r}):Fv(t,{dir:e,size:r})}function Bv(t,{dir:e,size:r=32}={}){if(r===null)return t;const i=t.replace("0x","");if(i.length>r*2)throw new Oh({size:Math.ceil(i.length/2),targetSize:r,type:"hex"});return`0x${i[e==="right"?"padEnd":"padStart"](r*2,"0")}`}function Fv(t,{dir:e,size:r=32}={}){if(r===null)return t;if(t.length>r)throw new Oh({size:t.length,targetSize:r,type:"bytes"});const i=new Uint8Array(r);for(let n=0;n<r;n++){const s=e==="right";i[s?n:r-n-1]=t[s?n:t.length-n-1]}return i}class Lv extends gi{constructor({max:e,min:r,signed:i,size:n,value:s}){super(`Number "${s}" is not in safe ${n?`${n*8}-bit ${i?"signed":"unsigned"} `:""}integer range ${e?`(${r} to ${e})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}class qv extends gi{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function Ki(t,{size:e}){if(Ah(t)>e)throw new qv({givenSize:Ah(t),maxSize:e})}function Ia(t,e={}){const{signed:r}=e;e.size&&Ki(t,{size:e.size});const i=BigInt(t);if(!r)return i;const n=(t.length-2)/2,s=(1n<<BigInt(n)*8n-1n)-1n;return i<=s?i:i-BigInt(`0x${"f".padStart(n*2,"f")}`)-1n}function kv(t,e={}){return Number(Ia(t,e))}const zv=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Aa(t,e={}){return typeof t=="number"||typeof t=="bigint"?Ph(t,e):typeof t=="string"?Vv(t,e):typeof t=="boolean"?Uv(t,e):Mh(t,e)}function Uv(t,e={}){const r=`0x${Number(t)}`;return typeof e.size=="number"?(Ki(r,{size:e.size}),Vi(r,{size:e.size})):r}function Mh(t,e={}){let r="";for(let n=0;n<t.length;n++)r+=zv[t[n]];const i=`0x${r}`;return typeof e.size=="number"?(Ki(i,{size:e.size}),Vi(i,{dir:"right",size:e.size})):i}function Ph(t,e={}){const{signed:r,size:i}=e,n=BigInt(t);let s;i?r?s=(1n<<BigInt(i)*8n-1n)-1n:s=2n**(BigInt(i)*8n)-1n:typeof t=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&n>s||n<o){const c=typeof t=="bigint"?"n":"";throw new Lv({max:s?`${s}${c}`:void 0,min:`${o}${c}`,signed:r,size:i,value:`${t}${c}`})}const a=`0x${(r&&n<0?(1n<<BigInt(i*8))+BigInt(n):n).toString(16)}`;return i?Vi(a,{size:i}):a}const jv=new TextEncoder;function Vv(t,e={}){const r=jv.encode(t);return Mh(r,e)}const Kv=new TextEncoder;function Hv(t,e={}){return typeof t=="number"||typeof t=="bigint"?Gv(t,e):typeof t=="boolean"?Wv(t,e):Tn(t)?Th(t,e):Nh(t,e)}function Wv(t,e={}){const r=new Uint8Array(1);return r[0]=Number(t),typeof e.size=="number"?(Ki(r,{size:e.size}),Vi(r,{size:e.size})):r}const Pr={zero:48,nine:57,A:65,F:70,a:97,f:102};function Rh(t){if(t>=Pr.zero&&t<=Pr.nine)return t-Pr.zero;if(t>=Pr.A&&t<=Pr.F)return t-(Pr.A-10);if(t>=Pr.a&&t<=Pr.f)return t-(Pr.a-10)}function Th(t,e={}){let r=t;e.size&&(Ki(r,{size:e.size}),r=Vi(r,{dir:"right",size:e.size}));let i=r.slice(2);i.length%2&&(i=`0${i}`);const n=i.length/2,s=new Uint8Array(n);for(let o=0,a=0;o<n;o++){const c=Rh(i.charCodeAt(a++)),f=Rh(i.charCodeAt(a++));if(c===void 0||f===void 0)throw new gi(`Invalid byte sequence ("${i[a-2]}${i[a-1]}" in "${i}").`);s[o]=c*16+f}return s}function Gv(t,e){const r=Ph(t,e);return Th(r)}function Nh(t,e={}){const r=Kv.encode(t);return typeof e.size=="number"?(Ki(r,{size:e.size}),Vi(r,{dir:"right",size:e.size})):r}function qs(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Yv(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Nn(t,...e){if(!Yv(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Zv(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");qs(t.outputLen),qs(t.blockLen)}function Hi(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Ch(t,e){Nn(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const ks=BigInt(2**32-1),Bh=BigInt(32);function Jv(t,e=!1){return e?{h:Number(t&ks),l:Number(t>>Bh&ks)}:{h:Number(t>>Bh&ks)|0,l:Number(t&ks)|0}}function Xv(t,e=!1){let r=new Uint32Array(t.length),i=new Uint32Array(t.length);for(let n=0;n<t.length;n++){const{h:s,l:o}=Jv(t[n],e);[r[n],i[n]]=[s,o]}return[r,i]}const Qv=(t,e,r)=>t<<r|e>>>32-r,em=(t,e,r)=>e<<r|t>>>32-r,tm=(t,e,r)=>e<<r-32|t>>>64-r,rm=(t,e,r)=>t<<r-32|e>>>64-r,Wi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function im(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function $a(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function cr(t,e){return t<<32-e|t>>>e}const Fh=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function nm(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Lh(t){for(let e=0;e<t.length;e++)t[e]=nm(t[e])}function sm(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function zs(t){return typeof t=="string"&&(t=sm(t)),Nn(t),t}function om(...t){let e=0;for(let i=0;i<t.length;i++){const n=t[i];Nn(n),e+=n.length}const r=new Uint8Array(e);for(let i=0,n=0;i<t.length;i++){const s=t[i];r.set(s,n),n+=s.length}return r}class Da{clone(){return this._cloneInto()}}function qh(t){const e=i=>t().update(zs(i)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function kh(t=32){if(Wi&&typeof Wi.getRandomValues=="function")return Wi.getRandomValues(new Uint8Array(t));if(Wi&&typeof Wi.randomBytes=="function")return Wi.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}const zh=[],Uh=[],jh=[],am=BigInt(0),Cn=BigInt(1),cm=BigInt(2),fm=BigInt(7),um=BigInt(256),hm=BigInt(113);for(let t=0,e=Cn,r=1,i=0;t<24;t++){[r,i]=[i,(2*r+3*i)%5],zh.push(2*(5*i+r)),Uh.push((t+1)*(t+2)/2%64);let n=am;for(let s=0;s<7;s++)e=(e<<Cn^(e>>fm)*hm)%um,e&cm&&(n^=Cn<<(Cn<<BigInt(s))-Cn);jh.push(n)}const[dm,lm]=Xv(jh,!0),Vh=(t,e,r)=>r>32?tm(t,e,r):Qv(t,e,r),Kh=(t,e,r)=>r>32?rm(t,e,r):em(t,e,r);function pm(t,e=24){const r=new Uint32Array(10);for(let i=24-e;i<24;i++){for(let o=0;o<10;o++)r[o]=t[o]^t[o+10]^t[o+20]^t[o+30]^t[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,c=(o+2)%10,f=r[c],u=r[c+1],d=Vh(f,u,1)^r[a],b=Kh(f,u,1)^r[a+1];for(let v=0;v<50;v+=10)t[o+v]^=d,t[o+v+1]^=b}let n=t[2],s=t[3];for(let o=0;o<24;o++){const a=Uh[o],c=Vh(n,s,a),f=Kh(n,s,a),u=zh[o];n=t[u],s=t[u+1],t[u]=c,t[u+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}t[0]^=dm[i],t[1]^=lm[i]}r.fill(0)}class Oa extends Da{constructor(e,r,i,n=!1,s=24){if(super(),this.blockLen=e,this.suffix=r,this.outputLen=i,this.enableXOF=n,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,qs(i),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=im(this.state)}keccak(){Fh||Lh(this.state32),pm(this.state32,this.rounds),Fh||Lh(this.state32),this.posOut=0,this.pos=0}update(e){Hi(this);const{blockLen:r,state:i}=this;e=zs(e);const n=e.length;for(let s=0;s<n;){const o=Math.min(r-this.pos,n-s);for(let a=0;a<o;a++)i[this.pos++]^=e[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:r,pos:i,blockLen:n}=this;e[i]^=r,r&128&&i===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){Hi(this,!1),Nn(e),this.finish();const r=this.state,{blockLen:i}=this;for(let n=0,s=e.length;n<s;){this.posOut>=i&&this.keccak();const o=Math.min(i-this.posOut,s-n);e.set(r.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return qs(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Ch(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:r,suffix:i,outputLen:n,rounds:s,enableXOF:o}=this;return e||(e=new Oa(r,i,n,o,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=i,e.outputLen=n,e.enableXOF=o,e.destroyed=this.destroyed,e}}const Hh=((t,e,r)=>qh(()=>new Oa(e,t,r)))(1,136,256/8);function Wh(t,e){const r=e||"hex",i=Hh(Tn(t,{strict:!1})?Hv(t):t);return r==="bytes"?i:Aa(i)}class Gh extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const r=super.get(e);return super.has(e)&&r!==void 0&&(this.delete(e),super.set(e,r)),r}set(e,r){if(super.set(e,r),this.maxSize&&this.size>this.maxSize){const i=this.keys().next().value;i&&this.delete(i)}return this}}const Ma=new Gh(8192);function bm(t,e){if(Ma.has(`${t}.${e}`))return Ma.get(`${t}.${e}`);const r=e?`${e}${t.toLowerCase()}`:t.substring(2).toLowerCase(),i=Wh(Nh(r),"bytes"),n=(e?r.substring(`${e}0x`.length):r).split("");for(let o=0;o<40;o+=2)i[o>>1]>>4>=8&&n[o]&&(n[o]=n[o].toUpperCase()),(i[o>>1]&15)>=8&&n[o+1]&&(n[o+1]=n[o+1].toUpperCase());const s=`0x${n.join("")}`;return Ma.set(`${t}.${e}`,s),s}function gm(t){const e=Wh(`0x${t.substring(4)}`).substring(26);return bm(`0x${e}`)}async function ym({hash:t,signature:e}){const r=Tn(t)?t:Aa(t),{secp256k1:i}=await Promise.resolve().then(function(){return Jw});return`0x${(()=>{if(typeof e=="object"&&"r"in e&&"s"in e){const{r:f,s:u,v:d,yParity:b}=e,v=Number(b??d),g=Yh(v);return new i.Signature(Ia(f),Ia(u)).addRecoveryBit(g)}const o=Tn(e)?e:Aa(e),a=kv(`0x${o.slice(130)}`),c=Yh(a);return i.Signature.fromCompact(o.substring(2,130)).addRecoveryBit(c)})().recoverPublicKey(r.substring(2)).toHex(!1)}`}function Yh(t){if(t===0||t===1)return t;if(t===27)return 0;if(t===28)return 1;throw new Error("Invalid yParityOrV value")}async function vm({hash:t,signature:e}){return gm(await ym({hash:t,signature:e}))}function mm(t,e,r,i){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,i);const n=BigInt(32),s=BigInt(4294967295),o=Number(r>>n&s),a=Number(r&s),c=i?4:0,f=i?0:4;t.setUint32(e+c,o,i),t.setUint32(e+f,a,i)}function wm(t,e,r){return t&e^~t&r}function _m(t,e,r){return t&e^t&r^e&r}class xm extends Da{constructor(e,r,i,n){super(),this.blockLen=e,this.outputLen=r,this.padOffset=i,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=$a(this.buffer)}update(e){Hi(this);const{view:r,buffer:i,blockLen:n}=this;e=zs(e);const s=e.length;for(let o=0;o<s;){const a=Math.min(n-this.pos,s-o);if(a===n){const c=$a(e);for(;n<=s-o;o+=n)this.process(c,o);continue}i.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===n&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Hi(this),Ch(e,this),this.finished=!0;const{buffer:r,view:i,blockLen:n,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>n-o&&(this.process(i,0),o=0);for(let d=o;d<n;d++)r[d]=0;mm(i,n-8,BigInt(this.length*8),s),this.process(i,0);const a=$a(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],s)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const i=e.slice(0,r);return this.destroy(),i}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:r,buffer:i,length:n,finished:s,destroyed:o,pos:a}=this;return e.length=n,e.pos=a,e.finished=s,e.destroyed=o,n%r&&e.buffer.set(i),e}}const Em=new Uint32Array([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]),Kr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Hr=new Uint32Array(64);class Sm extends xm{constructor(){super(64,32,8,!1),this.A=Kr[0]|0,this.B=Kr[1]|0,this.C=Kr[2]|0,this.D=Kr[3]|0,this.E=Kr[4]|0,this.F=Kr[5]|0,this.G=Kr[6]|0,this.H=Kr[7]|0}get(){const{A:e,B:r,C:i,D:n,E:s,F:o,G:a,H:c}=this;return[e,r,i,n,s,o,a,c]}set(e,r,i,n,s,o,a,c){this.A=e|0,this.B=r|0,this.C=i|0,this.D=n|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let d=0;d<16;d++,r+=4)Hr[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){const b=Hr[d-15],v=Hr[d-2],g=cr(b,7)^cr(b,18)^b>>>3,x=cr(v,17)^cr(v,19)^v>>>10;Hr[d]=x+Hr[d-7]+g+Hr[d-16]|0}let{A:i,B:n,C:s,D:o,E:a,F:c,G:f,H:u}=this;for(let d=0;d<64;d++){const b=cr(a,6)^cr(a,11)^cr(a,25),v=u+b+wm(a,c,f)+Em[d]+Hr[d]|0,x=(cr(i,2)^cr(i,13)^cr(i,22))+_m(i,n,s)|0;u=f,f=c,c=a,a=o+v|0,o=s,s=n,n=i,i=v+x|0}i=i+this.A|0,n=n+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(i,n,s,o,a,c,f,u)}roundClean(){Hr.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Us=qh(()=>new Sm);new Gh(128);const Im=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Zh=new Uint8Array(new Array(16).fill(0).map((t,e)=>e)),Am=Zh.map(t=>(9*t+5)%16);let $m=[Zh],Dm=[Am];for(let t=0;t<4;t++)for(let e of[$m,Dm])e.push(e[t].map(r=>Im[r]));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const js=BigInt(0),Vs=BigInt(1),Om=BigInt(2);function yi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function fr(t){if(!yi(t))throw new Error("Uint8Array expected")}function Gi(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const Mm=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Yi(t){fr(t);let e="";for(let r=0;r<t.length;r++)e+=Mm[t[r]];return e}function Zi(t){const e=t.toString(16);return e.length&1?"0"+e:e}function Pa(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?js:BigInt("0x"+t)}const Rr={_0:48,_9:57,A:65,F:70,a:97,f:102};function Jh(t){if(t>=Rr._0&&t<=Rr._9)return t-Rr._0;if(t>=Rr.A&&t<=Rr.F)return t-(Rr.A-10);if(t>=Rr.a&&t<=Rr.f)return t-(Rr.a-10)}function Ji(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const i=new Uint8Array(r);for(let n=0,s=0;n<r;n++,s+=2){const o=Jh(t.charCodeAt(s)),a=Jh(t.charCodeAt(s+1));if(o===void 0||a===void 0){const c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}i[n]=o*16+a}return i}function ur(t){return Pa(Yi(t))}function Ra(t){return fr(t),Pa(Yi(Uint8Array.from(t).reverse()))}function Wr(t,e){return Ji(t.toString(16).padStart(e*2,"0"))}function Ta(t,e){return Wr(t,e).reverse()}function Pm(t){return Ji(Zi(t))}function wt(t,e,r){let i;if(typeof e=="string")try{i=Ji(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(yi(e))i=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const n=i.length;if(typeof r=="number"&&n!==r)throw new Error(t+" of length "+r+" expected, got "+n);return i}function Bt(...t){let e=0;for(let i=0;i<t.length;i++){const n=t[i];fr(n),e+=n.length}const r=new Uint8Array(e);for(let i=0,n=0;i<t.length;i++){const s=t[i];r.set(s,n),n+=s.length}return r}function Rm(t,e){if(t.length!==e.length)return!1;let r=0;for(let i=0;i<t.length;i++)r|=t[i]^e[i];return r===0}function Ks(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}const Na=t=>typeof t=="bigint"&&js<=t;function Xi(t,e,r){return Na(t)&&Na(e)&&Na(r)&&e<=t&&t<r}function Gr(t,e,r,i){if(!Xi(e,r,i))throw new Error("expected valid "+t+": "+r+" <= n < "+i+", got "+e)}function Xh(t){let e;for(e=0;t>js;t>>=Vs,e+=1);return e}function Tm(t,e){return t>>BigInt(e)&Vs}function Nm(t,e,r){return t|(r?Vs:js)<<BigInt(e)}const Ca=t=>(Om<<BigInt(t-1))-Vs,Ba=t=>new Uint8Array(t),Qh=t=>Uint8Array.from(t);function ed(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let i=Ba(t),n=Ba(t),s=0;const o=()=>{i.fill(1),n.fill(0),s=0},a=(...d)=>r(n,i,...d),c=(d=Ba())=>{n=a(Qh([0]),d),i=a(),d.length!==0&&(n=a(Qh([1]),d),i=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let d=0;const b=[];for(;d<e;){i=a();const v=i.slice();b.push(v),d+=i.length}return Bt(...b)};return(d,b)=>{o(),c(d);let v;for(;!(v=b(f()));)c();return o(),v}}const Cm={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||yi(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function Qi(t,e,r={}){const i=(n,s,o)=>{const a=Cm[s];if(typeof a!="function")throw new Error("invalid validator function");const c=t[n];if(!(o&&c===void 0)&&!a(c,t))throw new Error("param "+String(n)+" is invalid. Expected "+s+", got "+c)};for(const[n,s]of Object.entries(e))i(n,s,!1);for(const[n,s]of Object.entries(r))i(n,s,!0);return t}const Bm=()=>{throw new Error("not implemented")};function Fa(t){const e=new WeakMap;return(r,...i)=>{const n=e.get(r);if(n!==void 0)return n;const s=t(r,...i);return e.set(r,s),s}}var Fm=Object.freeze({__proto__:null,isBytes:yi,abytes:fr,abool:Gi,bytesToHex:Yi,numberToHexUnpadded:Zi,hexToNumber:Pa,hexToBytes:Ji,bytesToNumberBE:ur,bytesToNumberLE:Ra,numberToBytesBE:Wr,numberToBytesLE:Ta,numberToVarBytesBE:Pm,ensureBytes:wt,concatBytes:Bt,equalBytes:Rm,utf8ToBytes:Ks,inRange:Xi,aInRange:Gr,bitLen:Xh,bitGet:Tm,bitSet:Nm,bitMask:Ca,createHmacDrbg:ed,validateObject:Qi,notImplemented:Bm,memoized:Fa});const Lm="0.1.1";function qm(){return Lm}class At extends Error{constructor(e,r={}){const i=(()=>{if(r.cause instanceof At){if(r.cause.details)return r.cause.details;if(r.cause.shortMessage)return r.cause.shortMessage}return r.cause?.message?r.cause.message:r.details})(),n=(()=>r.cause instanceof At&&r.cause.docsPath||r.docsPath)(),o=`https://oxlib.sh${n??""}`,a=[e||"An error occurred.",...r.metaMessages?["",...r.metaMessages]:[],...i||n?["",i?`Details: ${i}`:void 0,n?`See: ${o}`:void 0]:[]].filter(c=>typeof c=="string").join(`
16
- `);super(a,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:`ox@${qm()}`}),this.cause=r.cause,this.details=i,this.docs=o,this.docsPath=n,this.shortMessage=e}walk(e){return td(this,e)}}function td(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause?td(t.cause,e):e?null:t}function km(t,e){if(nd(t)>e)throw new Gm({givenSize:nd(t),maxSize:e})}const Tr={zero:48,nine:57,A:65,F:70,a:97,f:102};function rd(t){if(t>=Tr.zero&&t<=Tr.nine)return t-Tr.zero;if(t>=Tr.A&&t<=Tr.F)return t-(Tr.A-10);if(t>=Tr.a&&t<=Tr.f)return t-(Tr.a-10)}function zm(t,e={}){const{dir:r,size:i=32}=e;if(i===0)return t;if(t.length>i)throw new Ym({size:t.length,targetSize:i,type:"Bytes"});const n=new Uint8Array(i);for(let s=0;s<i;s++){const o=r==="right";n[o?s:i-s-1]=t[o?s:t.length-s-1]}return n}function La(t,e){if(ka(t)>e)throw new rw({givenSize:ka(t),maxSize:e})}function id(t,e={}){const{dir:r,size:i=32}=e;if(i===0)return t;const n=t.replace("0x","");if(n.length>i*2)throw new iw({size:Math.ceil(n.length/2),targetSize:i,type:"Hex"});return`0x${n[r==="right"?"padEnd":"padStart"](i*2,"0")}`}const Um=new TextEncoder;function jm(t){return t instanceof Uint8Array?t:typeof t=="string"?Km(t):Vm(t)}function Vm(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function Km(t,e={}){const{size:r}=e;let i=t;r&&(La(t,r),i=qa(t,r));let n=i.slice(2);n.length%2&&(n=`0${n}`);const s=n.length/2,o=new Uint8Array(s);for(let a=0,c=0;a<s;a++){const f=rd(n.charCodeAt(c++)),u=rd(n.charCodeAt(c++));if(f===void 0||u===void 0)throw new At(`Invalid byte sequence ("${n[c-2]}${n[c-1]}" in "${n}").`);o[a]=f*16+u}return o}function Hm(t,e={}){const{size:r}=e,i=Um.encode(t);return typeof r=="number"?(km(i,r),Wm(i,r)):i}function Wm(t,e){return zm(t,{dir:"right",size:e})}function nd(t){return t.length}class Gm extends At{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}}class Ym extends At{constructor({size:e,targetSize:r,type:i}){super(`${i.charAt(0).toUpperCase()}${i.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}const Zm=new TextEncoder,Jm=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function sd(...t){return`0x${t.reduce((e,r)=>e+r.replace("0x",""),"")}`}function Xm(t,e={}){const r=`0x${Number(t)}`;return typeof e.size=="number"?(La(r,e.size),Hs(r,e.size)):r}function od(t,e={}){let r="";for(let n=0;n<t.length;n++)r+=Jm[t[n]];const i=`0x${r}`;return typeof e.size=="number"?(La(i,e.size),qa(i,e.size)):i}function Qm(t,e={}){const{signed:r,size:i}=e,n=BigInt(t);let s;i?r?s=(1n<<BigInt(i)*8n-1n)-1n:s=2n**(BigInt(i)*8n)-1n:typeof t=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&n>s||n<o){const f=typeof t=="bigint"?"n":"";throw new tw({max:s?`${s}${f}`:void 0,min:`${o}${f}`,signed:r,size:i,value:`${t}${f}`})}const c=`0x${(r&&n<0?(1n<<BigInt(i*8))+BigInt(n):n).toString(16)}`;return i?Hs(c,i):c}function ew(t,e={}){return od(Zm.encode(t),e)}function Hs(t,e){return id(t,{dir:"left",size:e})}function qa(t,e){return id(t,{dir:"right",size:e})}function ka(t){return Math.ceil((t.length-2)/2)}class tw extends At{constructor({max:e,min:r,signed:i,size:n,value:s}){super(`Number \`${s}\` is not in safe${n?` ${n*8}-bit`:""}${i?" signed":" unsigned"} integer range ${e?`(\`${r}\` to \`${e}\`)`:`(above \`${r}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class rw extends At{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}}class iw extends At{constructor({size:e,targetSize:r,type:i}){super(`${i.charAt(0).toUpperCase()}${i.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}function nw(t,e={}){const{as:r=typeof t=="string"?"Hex":"Bytes"}=e,i=Hh(jm(t));return r==="Bytes"?i:od(i)}class sw extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const r=super.get(e);return super.has(e)&&r!==void 0&&(this.delete(e),super.set(e,r)),r}set(e,r){if(super.set(e,r),this.maxSize&&this.size>this.maxSize){const i=this.keys().next().value;i&&this.delete(i)}return this}}const za={checksum:new sw(8192)}.checksum,ow=/^0x[a-fA-F0-9]{40}$/;function ad(t,e={}){const{strict:r=!0}=e;if(!ow.test(t))throw new cd({address:t,cause:new cw});if(r){if(t.toLowerCase()===t)return;if(aw(t)!==t)throw new cd({address:t,cause:new fw})}}function aw(t){if(za.has(t))return za.get(t);ad(t,{strict:!1});const e=t.substring(2).toLowerCase(),r=nw(Hm(e),{as:"Bytes"}),i=e.split("");for(let s=0;s<40;s+=2)r[s>>1]>>4>=8&&i[s]&&(i[s]=i[s].toUpperCase()),(r[s>>1]&15)>=8&&i[s+1]&&(i[s+1]=i[s+1].toUpperCase());const n=`0x${i.join("")}`;return za.set(t,n),n}class cd extends At{constructor({address:e,cause:r}){super(`Address "${e}" is invalid.`,{cause:r}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class cw extends At{constructor(){super("Address is not a 20 byte (40 hexadecimal character) value."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidInputError"})}}class fw extends At{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}const uw=/^(.*)\[([0-9]*)\]$/,hw=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,dw=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function Ua(t,e){if(t.length!==e.length)throw new pw({expectedLength:t.length,givenLength:e.length});const r=[];for(let i=0;i<t.length;i++){const n=t[i],s=e[i];r.push(Ua.encode(n,s))}return sd(...r)}(function(t){function e(r,i,n=!1){if(r==="address"){const c=i;return ad(c),Hs(c.toLowerCase(),n?32:0)}if(r==="string")return ew(i);if(r==="bytes")return i;if(r==="bool")return Hs(Xm(i),n?32:1);const s=r.match(dw);if(s){const[c,f,u="256"]=s,d=Number.parseInt(u)/8;return Qm(i,{size:n?32:d,signed:f==="int"})}const o=r.match(hw);if(o){const[c,f]=o;if(Number.parseInt(f)!==(i.length-2)/2)throw new lw({expectedSize:Number.parseInt(f),value:i});return qa(i,n?32:0)}const a=r.match(uw);if(a&&Array.isArray(i)){const[c,f]=a,u=[];for(let d=0;d<i.length;d++)u.push(e(f,i[d],!0));return u.length===0?"0x":sd(...u)}throw new bw(r)}t.encode=e})(Ua||(Ua={}));class lw extends At{constructor({expectedSize:e,value:r}){super(`Size of bytes "${r}" (bytes${ka(r)}) does not match expected size (bytes${e}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class pw extends At{constructor({expectedLength:e,givenLength:r}){super(["ABI encoding parameters/values length mismatch.",`Expected length (parameters): ${e}`,`Given length (values): ${r}`].join(`
17
- `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.LengthMismatchError"})}}class bw extends At{constructor(e){super(`Type \`${e}\` is not a valid ABI Type.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.InvalidTypeError"})}}class fd extends Da{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Zv(e);const i=zs(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,s=new Uint8Array(n);s.set(i.length>n?e.create().update(i).digest():i);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(e){return Hi(this),this.iHash.update(e),this}digestInto(e){Hi(this),Nn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:i,finished:n,destroyed:s,blockLen:o,outputLen:a}=this;return e=e,e.finished=n,e.destroyed=s,e.blockLen=o,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=i._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const ud=(t,e,r)=>new fd(t,e).update(r).digest();ud.create=(t,e)=>new fd(t,e);const rt=BigInt(0),$e=BigInt(1),vi=BigInt(2),gw=BigInt(3),ja=BigInt(4),hd=BigInt(5),dd=BigInt(8);function it(t,e){const r=t%e;return r>=rt?r:e+r}function yw(t,e,r){if(e<rt)throw new Error("invalid exponent, negatives unsupported");if(r<=rt)throw new Error("invalid modulus");if(r===$e)return rt;let i=$e;for(;e>rt;)e&$e&&(i=i*t%r),t=t*t%r,e>>=$e;return i}function Ut(t,e,r){let i=t;for(;e-- >rt;)i*=i,i%=r;return i}function Va(t,e){if(t===rt)throw new Error("invert: expected non-zero number");if(e<=rt)throw new Error("invert: expected positive modulus, got "+e);let r=it(t,e),i=e,n=rt,s=$e;for(;r!==rt;){const a=i/r,c=i%r,f=n-s*a;i=r,r=c,n=s,s=f}if(i!==$e)throw new Error("invert: does not exist");return it(n,e)}function vw(t){const e=(t-$e)/vi;let r,i,n;for(r=t-$e,i=0;r%vi===rt;r/=vi,i++);for(n=vi;n<t&&yw(n,e,t)!==t-$e;n++)if(n>1e3)throw new Error("Cannot find square root: likely non-prime P");if(i===1){const o=(t+$e)/ja;return function(c,f){const u=c.pow(f,o);if(!c.eql(c.sqr(u),f))throw new Error("Cannot find square root");return u}}const s=(r+$e)/vi;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let f=i,u=a.pow(a.mul(a.ONE,n),r),d=a.pow(c,s),b=a.pow(c,r);for(;!a.eql(b,a.ONE);){if(a.eql(b,a.ZERO))return a.ZERO;let v=1;for(let x=a.sqr(b);v<f&&!a.eql(x,a.ONE);v++)x=a.sqr(x);const g=a.pow(u,$e<<BigInt(f-v-1));u=a.sqr(g),d=a.mul(d,g),b=a.mul(b,u),f=v}return d}}function mw(t){if(t%ja===gw){const e=(t+$e)/ja;return function(i,n){const s=i.pow(n,e);if(!i.eql(i.sqr(s),n))throw new Error("Cannot find square root");return s}}if(t%dd===hd){const e=(t-hd)/dd;return function(i,n){const s=i.mul(n,vi),o=i.pow(s,e),a=i.mul(n,o),c=i.mul(i.mul(a,vi),o),f=i.mul(a,i.sub(c,i.ONE));if(!i.eql(i.sqr(f),n))throw new Error("Cannot find square root");return f}}return vw(t)}const ww=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ld(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=ww.reduce((i,n)=>(i[n]="function",i),e);return Qi(t,r)}function _w(t,e,r){if(r<rt)throw new Error("invalid exponent, negatives unsupported");if(r===rt)return t.ONE;if(r===$e)return e;let i=t.ONE,n=e;for(;r>rt;)r&$e&&(i=t.mul(i,n)),n=t.sqr(n),r>>=$e;return i}function xw(t,e){const r=new Array(e.length),i=e.reduce((s,o,a)=>t.is0(o)?s:(r[a]=s,t.mul(s,o)),t.ONE),n=t.inv(i);return e.reduceRight((s,o,a)=>t.is0(o)?s:(r[a]=t.mul(s,r[a]),t.mul(s,o)),n),r}function pd(t,e){const r=e!==void 0?e:t.toString(2).length,i=Math.ceil(r/8);return{nBitLength:r,nByteLength:i}}function bd(t,e,r=!1,i={}){if(t<=rt)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:n,nByteLength:s}=pd(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:r,BITS:n,BYTES:s,MASK:Ca(n),ZERO:rt,ONE:$e,create:c=>it(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return rt<=c&&c<t},is0:c=>c===rt,isOdd:c=>(c&$e)===$e,neg:c=>it(-c,t),eql:(c,f)=>c===f,sqr:c=>it(c*c,t),add:(c,f)=>it(c+f,t),sub:(c,f)=>it(c-f,t),mul:(c,f)=>it(c*f,t),pow:(c,f)=>_w(a,c,f),div:(c,f)=>it(c*Va(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Va(c,t),sqrt:i.sqrt||(c=>(o||(o=mw(t)),o(a,c))),invertBatch:c=>xw(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>r?Ta(c,s):Wr(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?Ra(c):ur(c)}});return Object.freeze(a)}function gd(t){if(typeof t!="bigint")throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function yd(t){const e=gd(t);return e+Math.ceil(e/2)}function Ew(t,e,r=!1){const i=t.length,n=gd(e),s=yd(e);if(i<16||i<s||i>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+i);const o=r?Ra(t):ur(t),a=it(o,e-$e)+$e;return r?Ta(a,n):Wr(a,n)}const vd=BigInt(0),Ws=BigInt(1);function Ka(t,e){const r=e.negate();return t?r:e}function md(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Ha(t,e){md(t,e);const r=Math.ceil(e/t)+1,i=2**(t-1);return{windows:r,windowSize:i}}function Sw(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,i)=>{if(!(r instanceof e))throw new Error("invalid point at index "+i)})}function Iw(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,i)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+i)})}const Wa=new WeakMap,wd=new WeakMap;function Ga(t){return wd.get(t)||1}function Aw(t,e){return{constTimeNegate:Ka,hasPrecomputes(r){return Ga(r)!==1},unsafeLadder(r,i,n=t.ZERO){let s=r;for(;i>vd;)i&Ws&&(n=n.add(s)),s=s.double(),i>>=Ws;return n},precomputeWindow(r,i){const{windows:n,windowSize:s}=Ha(i,e),o=[];let a=r,c=a;for(let f=0;f<n;f++){c=a,o.push(c);for(let u=1;u<s;u++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(r,i,n){const{windows:s,windowSize:o}=Ha(r,e);let a=t.ZERO,c=t.BASE;const f=BigInt(2**r-1),u=2**r,d=BigInt(r);for(let b=0;b<s;b++){const v=b*o;let g=Number(n&f);n>>=d,g>o&&(g-=u,n+=Ws);const x=v,I=v+Math.abs(g)-1,D=b%2!==0,O=g<0;g===0?c=c.add(Ka(D,i[x])):a=a.add(Ka(O,i[I]))}return{p:a,f:c}},wNAFUnsafe(r,i,n,s=t.ZERO){const{windows:o,windowSize:a}=Ha(r,e),c=BigInt(2**r-1),f=2**r,u=BigInt(r);for(let d=0;d<o;d++){const b=d*a;if(n===vd)break;let v=Number(n&c);if(n>>=u,v>a&&(v-=f,n+=Ws),v===0)continue;let g=i[b+Math.abs(v)-1];v<0&&(g=g.negate()),s=s.add(g)}return s},getPrecomputes(r,i,n){let s=Wa.get(i);return s||(s=this.precomputeWindow(i,r),r!==1&&Wa.set(i,n(s))),s},wNAFCached(r,i,n){const s=Ga(r);return this.wNAF(s,this.getPrecomputes(s,r,n),i)},wNAFCachedUnsafe(r,i,n,s){const o=Ga(r);return o===1?this.unsafeLadder(r,i,s):this.wNAFUnsafe(o,this.getPrecomputes(o,r,n),i,s)},setWindowSize(r,i){md(i,e),wd.set(r,i),Wa.delete(r)}}}function $w(t,e,r,i){if(Sw(r,t),Iw(i,e),r.length!==i.length)throw new Error("arrays of points and scalars must have equal length");const n=t.ZERO,s=Xh(BigInt(r.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=(1<<o)-1,c=new Array(a+1).fill(n),f=Math.floor((e.BITS-1)/o)*o;let u=n;for(let d=f;d>=0;d-=o){c.fill(n);for(let v=0;v<i.length;v++){const g=i[v],x=Number(g>>BigInt(d)&BigInt(a));c[x]=c[x].add(r[v])}let b=n;for(let v=c.length-1,g=n;v>0;v--)g=g.add(c[v]),b=b.add(g);if(u=u.add(b),d!==0)for(let v=0;v<o;v++)u=u.double()}return u}function _d(t){return ld(t.Fp),Qi(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...pd(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function xd(t){t.lowS!==void 0&&Gi("lowS",t.lowS),t.prehash!==void 0&&Gi("prehash",t.prehash)}function Dw(t){const e=_d(t);Qi(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:i,a:n}=e;if(r){if(!i.eql(n,i.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:Ow,hexToBytes:Mw}=Fm;class Pw extends Error{constructor(e=""){super(e)}}const Nr={Err:Pw,_tlv:{encode:(t,e)=>{const{Err:r}=Nr;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");const i=e.length/2,n=Zi(i);if(n.length/2&128)throw new r("tlv.encode: long form length too big");const s=i>127?Zi(n.length/2|128):"";return Zi(t)+s+n+e},decode(t,e){const{Err:r}=Nr;let i=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[i++]!==t)throw new r("tlv.decode: wrong tlv");const n=e[i++],s=!!(n&128);let o=0;if(!s)o=n;else{const c=n&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");const f=e.subarray(i,i+c);if(f.length!==c)throw new r("tlv.decode: length bytes not complete");if(f[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const u of f)o=o<<8|u;if(i+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}const a=e.subarray(i,i+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(i+o)}}},_int:{encode(t){const{Err:e}=Nr;if(t<Xt)throw new e("integer: negative integers are not allowed");let r=Zi(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){const{Err:e}=Nr;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return Ow(t)}},toSig(t){const{Err:e,_int:r,_tlv:i}=Nr,n=typeof t=="string"?Mw(t):t;fr(n);const{v:s,l:o}=i.decode(48,n);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=i.decode(2,s),{v:f,l:u}=i.decode(2,c);if(u.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(f)}},hexFromSig(t){const{_tlv:e,_int:r}=Nr,i=e.encode(2,r.encode(t.r)),n=e.encode(2,r.encode(t.s)),s=i+n;return e.encode(48,s)}},Xt=BigInt(0),oe=BigInt(1),Yr=BigInt(2),Gs=BigInt(3),Ed=BigInt(4);function Rw(t){const e=Dw(t),{Fp:r}=e,i=bd(e.n,e.nBitLength),n=e.toBytes||((x,I,D)=>{const O=I.toAffine();return Bt(Uint8Array.from([4]),r.toBytes(O.x),r.toBytes(O.y))}),s=e.fromBytes||(x=>{const I=x.subarray(1),D=r.fromBytes(I.subarray(0,r.BYTES)),O=r.fromBytes(I.subarray(r.BYTES,2*r.BYTES));return{x:D,y:O}});function o(x){const{a:I,b:D}=e,O=r.sqr(x),M=r.mul(O,x);return r.add(r.add(M,r.mul(x,I)),D)}if(!r.eql(r.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(x){return Xi(x,oe,e.n)}function c(x){const{allowedPrivateKeyLengths:I,nByteLength:D,wrapPrivateKey:O,n:M}=e;if(I&&typeof x!="bigint"){if(yi(x)&&(x=Yi(x)),typeof x!="string"||!I.includes(x.length))throw new Error("invalid private key");x=x.padStart(D*2,"0")}let P;try{P=typeof x=="bigint"?x:ur(wt("private key",x,D))}catch{throw new Error("invalid private key, expected hex or "+D+" bytes, got "+typeof x)}return O&&(P=it(P,M)),Gr("private key",P,oe,M),P}function f(x){if(!(x instanceof b))throw new Error("ProjectivePoint expected")}const u=Fa((x,I)=>{const{px:D,py:O,pz:M}=x;if(r.eql(M,r.ONE))return{x:D,y:O};const P=x.is0();I==null&&(I=P?r.ONE:r.inv(M));const T=r.mul(D,I),N=r.mul(O,I),C=r.mul(M,I);if(P)return{x:r.ZERO,y:r.ZERO};if(!r.eql(C,r.ONE))throw new Error("invZ was invalid");return{x:T,y:N}}),d=Fa(x=>{if(x.is0()){if(e.allowInfinityPoint&&!r.is0(x.py))return;throw new Error("bad point: ZERO")}const{x:I,y:D}=x.toAffine();if(!r.isValid(I)||!r.isValid(D))throw new Error("bad point: x or y not FE");const O=r.sqr(D),M=o(I);if(!r.eql(O,M))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class b{constructor(I,D,O){if(this.px=I,this.py=D,this.pz=O,I==null||!r.isValid(I))throw new Error("x required");if(D==null||!r.isValid(D))throw new Error("y required");if(O==null||!r.isValid(O))throw new Error("z required");Object.freeze(this)}static fromAffine(I){const{x:D,y:O}=I||{};if(!I||!r.isValid(D)||!r.isValid(O))throw new Error("invalid affine point");if(I instanceof b)throw new Error("projective point not allowed");const M=P=>r.eql(P,r.ZERO);return M(D)&&M(O)?b.ZERO:new b(D,O,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(I){const D=r.invertBatch(I.map(O=>O.pz));return I.map((O,M)=>O.toAffine(D[M])).map(b.fromAffine)}static fromHex(I){const D=b.fromAffine(s(wt("pointHex",I)));return D.assertValidity(),D}static fromPrivateKey(I){return b.BASE.multiply(c(I))}static msm(I,D){return $w(b,i,I,D)}_setWindowSize(I){g.setWindowSize(this,I)}assertValidity(){d(this)}hasEvenY(){const{y:I}=this.toAffine();if(r.isOdd)return!r.isOdd(I);throw new Error("Field doesn't support isOdd")}equals(I){f(I);const{px:D,py:O,pz:M}=this,{px:P,py:T,pz:N}=I,C=r.eql(r.mul(D,N),r.mul(P,M)),B=r.eql(r.mul(O,N),r.mul(T,M));return C&&B}negate(){return new b(this.px,r.neg(this.py),this.pz)}double(){const{a:I,b:D}=e,O=r.mul(D,Gs),{px:M,py:P,pz:T}=this;let N=r.ZERO,C=r.ZERO,B=r.ZERO,R=r.mul(M,M),V=r.mul(P,P),A=r.mul(T,T),h=r.mul(M,P);return h=r.add(h,h),B=r.mul(M,T),B=r.add(B,B),N=r.mul(I,B),C=r.mul(O,A),C=r.add(N,C),N=r.sub(V,C),C=r.add(V,C),C=r.mul(N,C),N=r.mul(h,N),B=r.mul(O,B),A=r.mul(I,A),h=r.sub(R,A),h=r.mul(I,h),h=r.add(h,B),B=r.add(R,R),R=r.add(B,R),R=r.add(R,A),R=r.mul(R,h),C=r.add(C,R),A=r.mul(P,T),A=r.add(A,A),R=r.mul(A,h),N=r.sub(N,R),B=r.mul(A,V),B=r.add(B,B),B=r.add(B,B),new b(N,C,B)}add(I){f(I);const{px:D,py:O,pz:M}=this,{px:P,py:T,pz:N}=I;let C=r.ZERO,B=r.ZERO,R=r.ZERO;const V=e.a,A=r.mul(e.b,Gs);let h=r.mul(D,P),p=r.mul(O,T),m=r.mul(M,N),y=r.add(D,O),w=r.add(P,T);y=r.mul(y,w),w=r.add(h,p),y=r.sub(y,w),w=r.add(D,M);let S=r.add(P,N);return w=r.mul(w,S),S=r.add(h,m),w=r.sub(w,S),S=r.add(O,M),C=r.add(T,N),S=r.mul(S,C),C=r.add(p,m),S=r.sub(S,C),R=r.mul(V,w),C=r.mul(A,m),R=r.add(C,R),C=r.sub(p,R),R=r.add(p,R),B=r.mul(C,R),p=r.add(h,h),p=r.add(p,h),m=r.mul(V,m),w=r.mul(A,w),p=r.add(p,m),m=r.sub(h,m),m=r.mul(V,m),w=r.add(w,m),h=r.mul(p,w),B=r.add(B,h),h=r.mul(S,w),C=r.mul(y,C),C=r.sub(C,h),h=r.mul(y,p),R=r.mul(S,R),R=r.add(R,h),new b(C,B,R)}subtract(I){return this.add(I.negate())}is0(){return this.equals(b.ZERO)}wNAF(I){return g.wNAFCached(this,I,b.normalizeZ)}multiplyUnsafe(I){const{endo:D,n:O}=e;Gr("scalar",I,Xt,O);const M=b.ZERO;if(I===Xt)return M;if(this.is0()||I===oe)return this;if(!D||g.hasPrecomputes(this))return g.wNAFCachedUnsafe(this,I,b.normalizeZ);let{k1neg:P,k1:T,k2neg:N,k2:C}=D.splitScalar(I),B=M,R=M,V=this;for(;T>Xt||C>Xt;)T&oe&&(B=B.add(V)),C&oe&&(R=R.add(V)),V=V.double(),T>>=oe,C>>=oe;return P&&(B=B.negate()),N&&(R=R.negate()),R=new b(r.mul(R.px,D.beta),R.py,R.pz),B.add(R)}multiply(I){const{endo:D,n:O}=e;Gr("scalar",I,oe,O);let M,P;if(D){const{k1neg:T,k1:N,k2neg:C,k2:B}=D.splitScalar(I);let{p:R,f:V}=this.wNAF(N),{p:A,f:h}=this.wNAF(B);R=g.constTimeNegate(T,R),A=g.constTimeNegate(C,A),A=new b(r.mul(A.px,D.beta),A.py,A.pz),M=R.add(A),P=V.add(h)}else{const{p:T,f:N}=this.wNAF(I);M=T,P=N}return b.normalizeZ([M,P])[0]}multiplyAndAddUnsafe(I,D,O){const M=b.BASE,P=(N,C)=>C===Xt||C===oe||!N.equals(M)?N.multiplyUnsafe(C):N.multiply(C),T=P(this,D).add(P(I,O));return T.is0()?void 0:T}toAffine(I){return u(this,I)}isTorsionFree(){const{h:I,isTorsionFree:D}=e;if(I===oe)return!0;if(D)return D(b,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:I,clearCofactor:D}=e;return I===oe?this:D?D(b,this):this.multiplyUnsafe(e.h)}toRawBytes(I=!0){return Gi("isCompressed",I),this.assertValidity(),n(b,this,I)}toHex(I=!0){return Gi("isCompressed",I),Yi(this.toRawBytes(I))}}b.BASE=new b(e.Gx,e.Gy,r.ONE),b.ZERO=new b(r.ZERO,r.ONE,r.ZERO);const v=e.nBitLength,g=Aw(b,e.endo?Math.ceil(v/2):v);return{CURVE:e,ProjectivePoint:b,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function Tw(t){const e=_d(t);return Qi(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function Nw(t){const e=Tw(t),{Fp:r,n:i}=e,n=r.BYTES+1,s=2*r.BYTES+1;function o(m){return it(m,i)}function a(m){return Va(m,i)}const{ProjectivePoint:c,normPrivateKeyToScalar:f,weierstrassEquation:u,isWithinCurveOrder:d}=Rw({...e,toBytes(m,y,w){const S=y.toAffine(),$=r.toBytes(S.x),_=Bt;return Gi("isCompressed",w),w?_(Uint8Array.from([y.hasEvenY()?2:3]),$):_(Uint8Array.from([4]),$,r.toBytes(S.y))},fromBytes(m){const y=m.length,w=m[0],S=m.subarray(1);if(y===n&&(w===2||w===3)){const $=ur(S);if(!Xi($,oe,r.ORDER))throw new Error("Point is not on curve");const _=u($);let l;try{l=r.sqrt(_)}catch(L){const q=L instanceof Error?": "+L.message:"";throw new Error("Point is not on curve"+q)}const E=(l&oe)===oe;return(w&1)===1!==E&&(l=r.neg(l)),{x:$,y:l}}else if(y===s&&w===4){const $=r.fromBytes(S.subarray(0,r.BYTES)),_=r.fromBytes(S.subarray(r.BYTES,2*r.BYTES));return{x:$,y:_}}else{const $=n,_=s;throw new Error("invalid Point, expected length of "+$+", or uncompressed "+_+", got "+y)}}}),b=m=>Yi(Wr(m,e.nByteLength));function v(m){const y=i>>oe;return m>y}function g(m){return v(m)?o(-m):m}const x=(m,y,w)=>ur(m.slice(y,w));class I{constructor(y,w,S){this.r=y,this.s=w,this.recovery=S,this.assertValidity()}static fromCompact(y){const w=e.nByteLength;return y=wt("compactSignature",y,w*2),new I(x(y,0,w),x(y,w,2*w))}static fromDER(y){const{r:w,s:S}=Nr.toSig(wt("DER",y));return new I(w,S)}assertValidity(){Gr("r",this.r,oe,i),Gr("s",this.s,oe,i)}addRecoveryBit(y){return new I(this.r,this.s,y)}recoverPublicKey(y){const{r:w,s:S,recovery:$}=this,_=N(wt("msgHash",y));if($==null||![0,1,2,3].includes($))throw new Error("recovery id invalid");const l=$===2||$===3?w+e.n:w;if(l>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const E=$&1?"03":"02",F=c.fromHex(E+b(l)),L=a(l),q=o(-_*L),j=o(S*L),K=c.BASE.multiplyAndAddUnsafe(F,q,j);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return v(this.s)}normalizeS(){return this.hasHighS()?new I(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return Ji(this.toDERHex())}toDERHex(){return Nr.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Ji(this.toCompactHex())}toCompactHex(){return b(this.r)+b(this.s)}}const D={isValidPrivateKey(m){try{return f(m),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const m=yd(e.n);return Ew(e.randomBytes(m),e.n)},precompute(m=8,y=c.BASE){return y._setWindowSize(m),y.multiply(BigInt(3)),y}};function O(m,y=!0){return c.fromPrivateKey(m).toRawBytes(y)}function M(m){const y=yi(m),w=typeof m=="string",S=(y||w)&&m.length;return y?S===n||S===s:w?S===2*n||S===2*s:m instanceof c}function P(m,y,w=!0){if(M(m))throw new Error("first arg must be private key");if(!M(y))throw new Error("second arg must be public key");return c.fromHex(y).multiply(f(m)).toRawBytes(w)}const T=e.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");const y=ur(m),w=m.length*8-e.nBitLength;return w>0?y>>BigInt(w):y},N=e.bits2int_modN||function(m){return o(T(m))},C=Ca(e.nBitLength);function B(m){return Gr("num < 2^"+e.nBitLength,m,Xt,C),Wr(m,e.nByteLength)}function R(m,y,w=V){if(["recovered","canonical"].some(Z=>Z in w))throw new Error("sign() legacy options not supported");const{hash:S,randomBytes:$}=e;let{lowS:_,prehash:l,extraEntropy:E}=w;_==null&&(_=!0),m=wt("msgHash",m),xd(w),l&&(m=wt("prehashed msgHash",S(m)));const F=N(m),L=f(y),q=[B(L),B(F)];if(E!=null&&E!==!1){const Z=E===!0?$(r.BYTES):E;q.push(wt("extraEntropy",Z))}const j=Bt(...q),K=F;function W(Z){const H=T(Z);if(!d(H))return;const G=a(H),Me=c.BASE.multiply(H).toAffine(),X=o(Me.x);if(X===Xt)return;const ie=o(G*o(K+X*L));if(ie===Xt)return;let St=(Me.x===X?0:2)|Number(Me.y&oe),fe=ie;return _&&v(ie)&&(fe=g(ie),St^=1),new I(X,fe,St)}return{seed:j,k2sig:W}}const V={lowS:e.lowS,prehash:!1},A={lowS:e.lowS,prehash:!1};function h(m,y,w=V){const{seed:S,k2sig:$}=R(m,y,w),_=e;return ed(_.hash.outputLen,_.nByteLength,_.hmac)(S,$)}c.BASE._setWindowSize(8);function p(m,y,w,S=A){const $=m;y=wt("msgHash",y),w=wt("publicKey",w);const{lowS:_,prehash:l,format:E}=S;if(xd(S),"strict"in S)throw new Error("options.strict was renamed to lowS");if(E!==void 0&&E!=="compact"&&E!=="der")throw new Error("format must be compact or der");const F=typeof $=="string"||yi($),L=!F&&!E&&typeof $=="object"&&$!==null&&typeof $.r=="bigint"&&typeof $.s=="bigint";if(!F&&!L)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,j;try{if(L&&(q=new I($.r,$.s)),F){try{E!=="compact"&&(q=I.fromDER($))}catch(St){if(!(St instanceof Nr.Err))throw St}!q&&E!=="der"&&(q=I.fromCompact($))}j=c.fromHex(w)}catch{return!1}if(!q||_&&q.hasHighS())return!1;l&&(y=e.hash(y));const{r:K,s:W}=q,Z=N(y),H=a(W),G=o(Z*H),Me=o(K*H),X=c.BASE.multiplyAndAddUnsafe(j,G,Me)?.toAffine();return X?o(X.x)===K:!1}return{CURVE:e,getPublicKey:O,getSharedSecret:P,sign:h,verify:p,ProjectivePoint:c,Signature:I,utils:D}}function Cw(t,e){const r=t.ORDER;let i=Xt;for(let g=r-oe;g%Yr===Xt;g/=Yr)i+=oe;const n=i,s=Yr<<n-oe-oe,o=s*Yr,a=(r-oe)/o,c=(a-oe)/Yr,f=o-oe,u=s,d=t.pow(e,a),b=t.pow(e,(a+oe)/Yr);let v=(g,x)=>{let I=d,D=t.pow(x,f),O=t.sqr(D);O=t.mul(O,x);let M=t.mul(g,O);M=t.pow(M,c),M=t.mul(M,D),D=t.mul(M,x),O=t.mul(M,g);let P=t.mul(O,D);M=t.pow(P,u);let T=t.eql(M,t.ONE);D=t.mul(O,b),M=t.mul(P,I),O=t.cmov(D,O,T),P=t.cmov(M,P,T);for(let N=n;N>oe;N--){let C=N-Yr;C=Yr<<C-oe;let B=t.pow(P,C);const R=t.eql(B,t.ONE);D=t.mul(O,I),I=t.mul(I,I),B=t.mul(P,I),O=t.cmov(D,O,R),P=t.cmov(B,P,R)}return{isValid:T,value:O}};if(t.ORDER%Ed===Gs){const g=(t.ORDER-Gs)/Ed,x=t.sqrt(t.neg(e));v=(I,D)=>{let O=t.sqr(D);const M=t.mul(I,D);O=t.mul(O,M);let P=t.pow(O,g);P=t.mul(P,M);const T=t.mul(P,x),N=t.mul(t.sqr(P),D),C=t.eql(N,I);let B=t.cmov(T,P,C);return{isValid:C,value:B}}}return v}function Bw(t,e){if(ld(t),!t.isValid(e.A)||!t.isValid(e.B)||!t.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const r=Cw(t,e.Z);if(!t.isOdd)throw new Error("Fp.isOdd is not implemented!");return i=>{let n,s,o,a,c,f,u,d;n=t.sqr(i),n=t.mul(n,e.Z),s=t.sqr(n),s=t.add(s,n),o=t.add(s,t.ONE),o=t.mul(o,e.B),a=t.cmov(e.Z,t.neg(s),!t.eql(s,t.ZERO)),a=t.mul(a,e.A),s=t.sqr(o),f=t.sqr(a),c=t.mul(f,e.A),s=t.add(s,c),s=t.mul(s,o),f=t.mul(f,a),c=t.mul(f,e.B),s=t.add(s,c),u=t.mul(n,o);const{isValid:b,value:v}=r(s,f);d=t.mul(n,i),d=t.mul(d,v),u=t.cmov(u,o,b),d=t.cmov(d,v,b);const g=t.isOdd(i)===t.isOdd(d);return d=t.cmov(t.neg(d),d,g),u=t.div(u,a),{x:u,y:d}}}function Fw(t){return{hash:t,hmac:(e,...r)=>ud(t,e,om(...r)),randomBytes:kh}}function Lw(t,e){const r=i=>Nw({...t,...Fw(i)});return{...r(e),create:r}}const qw=ur;function Zr(t,e){if(Bn(t),Bn(e),t<0||t>=1<<8*e)throw new Error("invalid I2OSP input: "+t);const r=Array.from({length:e}).fill(0);for(let i=e-1;i>=0;i--)r[i]=t&255,t>>>=8;return new Uint8Array(r)}function kw(t,e){const r=new Uint8Array(t.length);for(let i=0;i<t.length;i++)r[i]=t[i]^e[i];return r}function Bn(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function zw(t,e,r,i){fr(t),fr(e),Bn(r),e.length>255&&(e=i(Bt(Ks("H2C-OVERSIZE-DST-"),e)));const{outputLen:n,blockLen:s}=i,o=Math.ceil(r/n);if(r>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");const a=Bt(e,Zr(e.length,1)),c=Zr(0,s),f=Zr(r,2),u=new Array(o),d=i(Bt(c,t,f,Zr(0,1),a));u[0]=i(Bt(d,Zr(1,1),a));for(let v=1;v<=o;v++){const g=[kw(d,u[v-1]),Zr(v+1,1),a];u[v]=i(Bt(...g))}return Bt(...u).slice(0,r)}function Uw(t,e,r,i,n){if(fr(t),fr(e),Bn(r),e.length>255){const s=Math.ceil(2*i/8);e=n.create({dkLen:s}).update(Ks("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return n.create({dkLen:r}).update(t).update(Zr(r,2)).update(e).update(Zr(e.length,1)).digest()}function Sd(t,e,r){Qi(r,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:i,k:n,m:s,hash:o,expand:a,DST:c}=r;fr(t),Bn(e);const f=typeof c=="string"?Ks(c):c,u=i.toString(2).length,d=Math.ceil((u+n)/8),b=e*s*d;let v;if(a==="xmd")v=zw(t,f,b,o);else if(a==="xof")v=Uw(t,f,b,n,o);else if(a==="_internal_pass")v=t;else throw new Error('expand must be "xmd" or "xof"');const g=new Array(e);for(let x=0;x<e;x++){const I=new Array(s);for(let D=0;D<s;D++){const O=d*(D+x*s),M=v.subarray(O,O+d);I[D]=it(qw(M),i)}g[x]=I}return g}function jw(t,e){const r=e.map(i=>Array.from(i).reverse());return(i,n)=>{const[s,o,a,c]=r.map(f=>f.reduce((u,d)=>t.add(t.mul(u,i),d)));return i=t.div(s,o),n=t.mul(n,t.div(a,c)),{x:i,y:n}}}function Vw(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(i,n){const s=Sd(i,2,{...r,DST:r.DST,...n}),o=t.fromAffine(e(s[0])),a=t.fromAffine(e(s[1])),c=o.add(a).clearCofactor();return c.assertValidity(),c},encodeToCurve(i,n){const s=Sd(i,1,{...r,DST:r.encodeDST,...n}),o=t.fromAffine(e(s[0])).clearCofactor();return o.assertValidity(),o},mapToCurve(i){if(!Array.isArray(i))throw new Error("mapToCurve: expected array of bigints");for(const s of i)if(typeof s!="bigint")throw new Error("mapToCurve: expected array of bigints");const n=t.fromAffine(e(i)).clearCofactor();return n.assertValidity(),n}}}const Fn=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Ys=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Ln=BigInt(1),Zs=BigInt(2),Id=(t,e)=>(t+e/Zs)/e;function Ad(t){const e=Fn,r=BigInt(3),i=BigInt(6),n=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,u=f*f*t%e,d=Ut(u,r,e)*u%e,b=Ut(d,r,e)*u%e,v=Ut(b,Zs,e)*f%e,g=Ut(v,n,e)*v%e,x=Ut(g,s,e)*g%e,I=Ut(x,a,e)*x%e,D=Ut(I,c,e)*I%e,O=Ut(D,a,e)*x%e,M=Ut(O,r,e)*u%e,P=Ut(M,o,e)*g%e,T=Ut(P,i,e)*f%e,N=Ut(T,Zs,e);if(!Jr.eql(Jr.sqr(N),t))throw new Error("Cannot find square root");return N}const Jr=bd(Fn,void 0,void 0,{sqrt:Ad}),qn=Lw({a:BigInt(0),b:BigInt(7),Fp:Jr,n:Ys,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=Ys,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),i=-Ln*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),n=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,o=BigInt("0x100000000000000000000000000000000"),a=Id(s*t,e),c=Id(-i*t,e);let f=it(t-a*r-c*n,e),u=it(-a*i-c*s,e);const d=f>o,b=u>o;if(d&&(f=e-f),b&&(u=e-u),f>o||u>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:d,k1:f,k2neg:b,k2:u}}}},Us),$d=BigInt(0),Dd={};function Js(t,...e){let r=Dd[t];if(r===void 0){const i=Us(Uint8Array.from(t,n=>n.charCodeAt(0)));r=Bt(i,i),Dd[t]=r}return Us(Bt(r,...e))}const Ya=t=>t.toRawBytes(!0).slice(1),Za=t=>Wr(t,32),Ja=t=>it(t,Fn),kn=t=>it(t,Ys),Xa=qn.ProjectivePoint,Kw=(t,e,r)=>Xa.BASE.multiplyAndAddUnsafe(t,e,r);function Qa(t){let e=qn.utils.normPrivateKeyToScalar(t),r=Xa.fromPrivateKey(e);return{scalar:r.hasEvenY()?e:kn(-e),bytes:Ya(r)}}function Od(t){Gr("x",t,Ln,Fn);const e=Ja(t*t),r=Ja(e*t+BigInt(7));let i=Ad(r);i%Zs!==$d&&(i=Ja(-i));const n=new Xa(t,i,Ln);return n.assertValidity(),n}const en=ur;function Md(...t){return kn(en(Js("BIP0340/challenge",...t)))}function Hw(t){return Qa(t).bytes}function Ww(t,e,r=kh(32)){const i=wt("message",t),{bytes:n,scalar:s}=Qa(e),o=wt("auxRand",r,32),a=Za(s^en(Js("BIP0340/aux",o))),c=Js("BIP0340/nonce",a,n,i),f=kn(en(c));if(f===$d)throw new Error("sign failed: k is zero");const{bytes:u,scalar:d}=Qa(f),b=Md(u,n,i),v=new Uint8Array(64);if(v.set(u,0),v.set(Za(kn(d+b*s)),32),!Pd(v,i,n))throw new Error("sign: Invalid signature produced");return v}function Pd(t,e,r){const i=wt("signature",t,64),n=wt("message",e),s=wt("publicKey",r,32);try{const o=Od(en(s)),a=en(i.subarray(0,32));if(!Xi(a,Ln,Fn))return!1;const c=en(i.subarray(32,64));if(!Xi(c,Ln,Ys))return!1;const f=Md(Za(a),Ya(o),n),u=Kw(o,c,kn(-f));return!(!u||!u.hasEvenY()||u.toAffine().x!==a)}catch{return!1}}const Gw=(()=>({getPublicKey:Hw,sign:Ww,verify:Pd,utils:{randomPrivateKey:qn.utils.randomPrivateKey,lift_x:Od,pointToBytes:Ya,numberToBytesBE:Wr,bytesToNumberBE:ur,taggedHash:Js,mod:it}}))(),Yw=(()=>jw(Jr,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(t=>t.map(e=>BigInt(e)))))(),Zw=(()=>Bw(Jr,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:Jr.create(BigInt("-11"))}))(),Rd=(()=>Vw(qn.ProjectivePoint,t=>{const{x:e,y:r}=Zw(Jr.create(t[0]));return Yw(e,r)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:Jr.ORDER,m:1,k:128,expand:"xmd",hash:Us}))();var Jw=Object.freeze({__proto__:null,secp256k1:qn,schnorr:Gw,hashToCurve:(()=>Rd.hashToCurve)(),encodeToCurve:(()=>Rd.encodeToCurve)()});function Xw(t){if(t.length>=255)throw new TypeError("Alphabet too long");const e=new Uint8Array(256);for(let f=0;f<e.length;f++)e[f]=255;for(let f=0;f<t.length;f++){const u=t.charAt(f),d=u.charCodeAt(0);if(e[d]!==255)throw new TypeError(u+" is ambiguous");e[d]=f}const r=t.length,i=t.charAt(0),n=Math.log(r)/Math.log(256),s=Math.log(256)/Math.log(r);function o(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";let u=0,d=0,b=0;const v=f.length;for(;b!==v&&f[b]===0;)b++,u++;const g=(v-b)*s+1>>>0,x=new Uint8Array(g);for(;b!==v;){let O=f[b],M=0;for(let P=g-1;(O!==0||M<d)&&P!==-1;P--,M++)O+=256*x[P]>>>0,x[P]=O%r>>>0,O=O/r>>>0;if(O!==0)throw new Error("Non-zero carry");d=M,b++}let I=g-d;for(;I!==g&&x[I]===0;)I++;let D=i.repeat(u);for(;I<g;++I)D+=t.charAt(x[I]);return D}function a(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;let u=0,d=0,b=0;for(;f[u]===i;)d++,u++;const v=(f.length-u)*n+1>>>0,g=new Uint8Array(v);for(;u<f.length;){const O=f.charCodeAt(u);if(O>255)return;let M=e[O];if(M===255)return;let P=0;for(let T=v-1;(M!==0||P<b)&&T!==-1;T--,P++)M+=r*g[T]>>>0,g[T]=M%256>>>0,M=M/256>>>0;if(M!==0)throw new Error("Non-zero carry");b=P,u++}let x=v-b;for(;x!==v&&g[x]===0;)x++;const I=new Uint8Array(d+(v-x));let D=d;for(;x!==v;)I[D++]=g[x++];return I}function c(f){const u=a(f);if(u)return u;throw new Error("Non-base"+r+" character")}return{encode:o,decodeUnsafe:a,decode:c}}var Qw="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",e3=Xw(Qw);function Td(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}function ec(t,e){e||(e=t.reduce((n,s)=>n+s.length,0));const r=Td(e);let i=0;for(const n of t)r.set(n,i),i+=n.length;return r}function t3(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i<r.length;i++)r[i]=255;for(var n=0;n<t.length;n++){var s=t.charAt(n),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=n}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var x=0,I=0,D=0,O=g.length;D!==O&&g[D]===0;)D++,x++;for(var M=(O-D)*u+1>>>0,P=new Uint8Array(M);D!==O;){for(var T=g[D],N=0,C=M-1;(T!==0||N<I)&&C!==-1;C--,N++)T+=256*P[C]>>>0,P[C]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");I=N,D++}for(var B=M-I;B!==M&&P[B]===0;)B++;for(var R=c.repeat(x);B<M;++B)R+=t.charAt(P[B]);return R}function b(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var x=0;if(g[x]!==" "){for(var I=0,D=0;g[x]===c;)I++,x++;for(var O=(g.length-x)*f+1>>>0,M=new Uint8Array(O);g[x];){var P=r[g.charCodeAt(x)];if(P===255)return;for(var T=0,N=O-1;(P!==0||T<D)&&N!==-1;N--,T++)P+=a*M[N]>>>0,M[N]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");D=T,x++}if(g[x]!==" "){for(var C=O-D;C!==O&&M[C]===0;)C++;for(var B=new Uint8Array(I+(O-C)),R=I;C!==O;)B[R++]=M[C++];return B}}}function v(g){var x=b(g);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:b,decode:v}}var r3=t3,i3=r3;const Nd=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},n3=t=>new TextEncoder().encode(t),s3=t=>new TextDecoder().decode(t);class o3{constructor(e,r,i){this.name=e,this.prefix=r,this.baseEncode=i}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class a3{constructor(e,r,i){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.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 Cd(this,e)}}class c3{constructor(e){this.decoders=e}or(e){return Cd(this,e)}decode(e){const r=e[0],i=this.decoders[r];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 Cd=(t,e)=>new c3({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class f3{constructor(e,r,i,n){this.name=e,this.prefix=r,this.baseEncode=i,this.baseDecode=n,this.encoder=new o3(e,r,i),this.decoder=new a3(e,r,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Xs=({name:t,prefix:e,encode:r,decode:i})=>new f3(t,e,r,i),zn=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=i3(r,e);return Xs({prefix:t,name:e,encode:i,decode:s=>Nd(n(s))})},u3=(t,e,r,i)=>{const n={};for(let u=0;u<e.length;++u)n[e[u]]=u;let s=t.length;for(;t[s-1]==="=";)--s;const o=new Uint8Array(s*r/8|0);let a=0,c=0,f=0;for(let u=0;u<s;++u){const d=n[t[u]];if(d===void 0)throw new SyntaxError(`Non-${i} character`);c=c<<r|d,a+=r,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},h3=(t,e,r)=>{const i=e[e.length-1]==="=",n=(1<<r)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<<r-o]),i)for(;s.length*r&7;)s+="=";return s},ht=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>Xs({prefix:e,name:t,encode(n){return h3(n,i,r)},decode(n){return u3(n,i,r,t)}}),d3=Xs({prefix:"\0",name:"identity",encode:t=>s3(t),decode:t=>n3(t)});var l3=Object.freeze({__proto__:null,identity:d3});const p3=ht({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var b3=Object.freeze({__proto__:null,base2:p3});const g3=ht({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var y3=Object.freeze({__proto__:null,base8:g3});const v3=zn({prefix:"9",name:"base10",alphabet:"0123456789"});var m3=Object.freeze({__proto__:null,base10:v3});const w3=ht({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),_3=ht({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var x3=Object.freeze({__proto__:null,base16:w3,base16upper:_3});const E3=ht({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),S3=ht({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),I3=ht({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),A3=ht({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),$3=ht({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),D3=ht({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),O3=ht({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),M3=ht({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),P3=ht({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var R3=Object.freeze({__proto__:null,base32:E3,base32upper:S3,base32pad:I3,base32padupper:A3,base32hex:$3,base32hexupper:D3,base32hexpad:O3,base32hexpadupper:M3,base32z:P3});const T3=zn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),N3=zn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var C3=Object.freeze({__proto__:null,base36:T3,base36upper:N3});const B3=zn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),F3=zn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var L3=Object.freeze({__proto__:null,base58btc:B3,base58flickr:F3});const q3=ht({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),k3=ht({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),z3=ht({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),U3=ht({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var j3=Object.freeze({__proto__:null,base64:q3,base64pad:k3,base64url:z3,base64urlpad:U3});const Bd=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),V3=Bd.reduce((t,e,r)=>(t[r]=e,t),[]),K3=Bd.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function H3(t){return t.reduce((e,r)=>(e+=V3[r],e),"")}function W3(t){const e=[];for(const r of t){const i=K3[r.codePointAt(0)];if(i===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}const G3=Xs({prefix:"\u{1F680}",name:"base256emoji",encode:H3,decode:W3});var Y3=Object.freeze({__proto__:null,base256emoji:G3}),Z3=Ld,Fd=128,J3=127,X3=~J3,Q3=Math.pow(2,31);function Ld(t,e,r){e=e||[],r=r||0;for(var i=r;t>=Q3;)e[r++]=t&255|Fd,t/=128;for(;t&X3;)e[r++]=t&255|Fd,t>>>=7;return e[r]=t|0,Ld.bytes=r-i+1,e}var e6=tc,t6=128,qd=127;function tc(t,i){var r=0,i=i||0,n=0,s=i,o,a=t.length;do{if(s>=a)throw tc.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=n<28?(o&qd)<<n:(o&qd)*Math.pow(2,n),n+=7}while(o>=t6);return tc.bytes=s-i,r}var r6=Math.pow(2,7),i6=Math.pow(2,14),n6=Math.pow(2,21),s6=Math.pow(2,28),o6=Math.pow(2,35),a6=Math.pow(2,42),c6=Math.pow(2,49),f6=Math.pow(2,56),u6=Math.pow(2,63),h6=function(t){return t<r6?1:t<i6?2:t<n6?3:t<s6?4:t<o6?5:t<a6?6:t<c6?7:t<f6?8:t<u6?9:10},d6={encode:Z3,decode:e6,encodingLength:h6},kd=d6;const zd=(t,e,r=0)=>(kd.encode(t,e,r),e),Ud=t=>kd.encodingLength(t),rc=(t,e)=>{const r=e.byteLength,i=Ud(t),n=i+Ud(r),s=new Uint8Array(n+r);return zd(t,s,0),zd(r,s,i),s.set(e,n),new l6(t,r,e,s)};class l6{constructor(e,r,i,n){this.code=e,this.size=r,this.digest=i,this.bytes=n}}const jd=({name:t,code:e,encode:r})=>new p6(t,e,r);class p6{constructor(e,r,i){this.name=e,this.code=r,this.encode=i}digest(e){if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?rc(this.code,r):r.then(i=>rc(this.code,i))}else throw Error("Unknown type, must be binary type")}}const Vd=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),b6=jd({name:"sha2-256",code:18,encode:Vd("SHA-256")}),g6=jd({name:"sha2-512",code:19,encode:Vd("SHA-512")});var y6=Object.freeze({__proto__:null,sha256:b6,sha512:g6});const Kd=0,v6="identity",Hd=Nd;var m6=Object.freeze({__proto__:null,identity:{code:Kd,name:v6,encode:Hd,digest:t=>rc(Kd,Hd(t))}});new TextEncoder,new TextDecoder;const Wd={...l3,...b3,...y3,...m3,...x3,...R3,...C3,...L3,...j3,...Y3};({...y6,...m6});function Gd(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const Yd=Gd("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ic=Gd("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);const e=Td(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Zd={utf8:Yd,"utf-8":Yd,hex:Wd.base16,latin1:ic,ascii:ic,binary:ic,...Wd};function jt(t,e="utf8"){const r=Zd[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t,"utf8"):r.decoder.decode(`${r.prefix}${t}`)}function $t(t,e="utf8"){const r=Zd[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}var Jd={},w6="elliptic",_6="6.6.1",x6="EC cryptography",E6="lib/elliptic.js",S6=["lib"],I6={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/"},A6={type:"git",url:"git@github.com:indutny/elliptic"},$6=["EC","Elliptic","curve","Cryptography"],D6="Fedor Indutny <fedor@indutny.com>",O6="MIT",M6={url:"https://github.com/indutny/elliptic/issues"},P6="https://github.com/indutny/elliptic",R6={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"},T6={"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"},N6={name:w6,version:_6,description:x6,main:E6,files:S6,scripts:I6,repository:A6,keywords:$6,author:D6,license:O6,bugs:M6,homepage:P6,devDependencies:R6,dependencies:T6},Ft={},hr={exports:{}},C6={},B6=Object.freeze({__proto__:null,default:C6}),Xd=Lo(B6);(function(t){(function(e,r){function i(A,h){if(!A)throw new Error(h||"Assertion failed")}function n(A,h){A.super_=h;var p=function(){};p.prototype=h.prototype,A.prototype=new p,A.prototype.constructor=A}function s(A,h,p){if(s.isBN(A))return A;this.negative=0,this.words=null,this.length=0,this.red=null,A!==null&&((h==="le"||h==="be")&&(p=h,h=10),this._init(A||0,h||10,p||"be"))}typeof e=="object"?e.exports=s:r.BN=s,s.BN=s,s.wordSize=26;var o;try{typeof window<"u"&&typeof window.Buffer<"u"?o=window.Buffer:o=Xd.Buffer}catch{}s.isBN=function(h){return h instanceof s?!0:h!==null&&typeof h=="object"&&h.constructor.wordSize===s.wordSize&&Array.isArray(h.words)},s.max=function(h,p){return h.cmp(p)>0?h:p},s.min=function(h,p){return h.cmp(p)<0?h:p},s.prototype._init=function(h,p,m){if(typeof h=="number")return this._initNumber(h,p,m);if(typeof h=="object")return this._initArray(h,p,m);p==="hex"&&(p=16),i(p===(p|0)&&p>=2&&p<=36),h=h.toString().replace(/\s+/g,"");var y=0;h[0]==="-"&&(y++,this.negative=1),y<h.length&&(p===16?this._parseHex(h,y,m):(this._parseBase(h,p,y),m==="le"&&this._initArray(this.toArray(),p,m)))},s.prototype._initNumber=function(h,p,m){h<0&&(this.negative=1,h=-h),h<67108864?(this.words=[h&67108863],this.length=1):h<4503599627370496?(this.words=[h&67108863,h/67108864&67108863],this.length=2):(i(h<9007199254740992),this.words=[h&67108863,h/67108864&67108863,1],this.length=3),m==="le"&&this._initArray(this.toArray(),p,m)},s.prototype._initArray=function(h,p,m){if(i(typeof h.length=="number"),h.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(h.length/3),this.words=new Array(this.length);for(var y=0;y<this.length;y++)this.words[y]=0;var w,S,$=0;if(m==="be")for(y=h.length-1,w=0;y>=0;y-=3)S=h[y]|h[y-1]<<8|h[y-2]<<16,this.words[w]|=S<<$&67108863,this.words[w+1]=S>>>26-$&67108863,$+=24,$>=26&&($-=26,w++);else if(m==="le")for(y=0,w=0;y<h.length;y+=3)S=h[y]|h[y+1]<<8|h[y+2]<<16,this.words[w]|=S<<$&67108863,this.words[w+1]=S>>>26-$&67108863,$+=24,$>=26&&($-=26,w++);return this.strip()};function a(A,h){var p=A.charCodeAt(h);return p>=65&&p<=70?p-55:p>=97&&p<=102?p-87:p-48&15}function c(A,h,p){var m=a(A,p);return p-1>=h&&(m|=a(A,p-1)<<4),m}s.prototype._parseHex=function(h,p,m){this.length=Math.ceil((h.length-p)/6),this.words=new Array(this.length);for(var y=0;y<this.length;y++)this.words[y]=0;var w=0,S=0,$;if(m==="be")for(y=h.length-1;y>=p;y-=2)$=c(h,p,y)<<w,this.words[S]|=$&67108863,w>=18?(w-=18,S+=1,this.words[S]|=$>>>26):w+=8;else{var _=h.length-p;for(y=_%2===0?p+1:p;y<h.length;y+=2)$=c(h,p,y)<<w,this.words[S]|=$&67108863,w>=18?(w-=18,S+=1,this.words[S]|=$>>>26):w+=8}this.strip()};function f(A,h,p,m){for(var y=0,w=Math.min(A.length,p),S=h;S<w;S++){var $=A.charCodeAt(S)-48;y*=m,$>=49?y+=$-49+10:$>=17?y+=$-17+10:y+=$}return y}s.prototype._parseBase=function(h,p,m){this.words=[0],this.length=1;for(var y=0,w=1;w<=67108863;w*=p)y++;y--,w=w/p|0;for(var S=h.length-m,$=S%y,_=Math.min(S,S-$)+m,l=0,E=m;E<_;E+=y)l=f(h,E,E+y,p),this.imuln(w),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if($!==0){var F=1;for(l=f(h,E,h.length,p),E=0;E<$;E++)F*=p;this.imuln(F),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}this.strip()},s.prototype.copy=function(h){h.words=new Array(this.length);for(var p=0;p<this.length;p++)h.words[p]=this.words[p];h.length=this.length,h.negative=this.negative,h.red=this.red},s.prototype.clone=function(){var h=new s(null);return this.copy(h),h},s.prototype._expand=function(h){for(;this.length<h;)this.words[this.length++]=0;return this},s.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},s.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},s.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var u=["","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"],d=[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],b=[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];s.prototype.toString=function(h,p){h=h||10,p=p|0||1;var m;if(h===16||h==="hex"){m="";for(var y=0,w=0,S=0;S<this.length;S++){var $=this.words[S],_=(($<<y|w)&16777215).toString(16);w=$>>>24-y&16777215,y+=2,y>=26&&(y-=26,S--),w!==0||S!==this.length-1?m=u[6-_.length]+_+m:m=_+m}for(w!==0&&(m=w.toString(16)+m);m.length%p!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}if(h===(h|0)&&h>=2&&h<=36){var l=d[h],E=b[h];m="";var F=this.clone();for(F.negative=0;!F.isZero();){var L=F.modn(E).toString(h);F=F.idivn(E),F.isZero()?m=L+m:m=u[l-L.length]+L+m}for(this.isZero()&&(m="0"+m);m.length%p!==0;)m="0"+m;return this.negative!==0&&(m="-"+m),m}i(!1,"Base should be between 2 and 36")},s.prototype.toNumber=function(){var h=this.words[0];return this.length===2?h+=this.words[1]*67108864:this.length===3&&this.words[2]===1?h+=4503599627370496+this.words[1]*67108864:this.length>2&&i(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-h:h},s.prototype.toJSON=function(){return this.toString(16)},s.prototype.toBuffer=function(h,p){return i(typeof o<"u"),this.toArrayLike(o,h,p)},s.prototype.toArray=function(h,p){return this.toArrayLike(Array,h,p)},s.prototype.toArrayLike=function(h,p,m){var y=this.byteLength(),w=m||Math.max(1,y);i(y<=w,"byte array longer than desired length"),i(w>0,"Requested array length <= 0"),this.strip();var S=p==="le",$=new h(w),_,l,E=this.clone();if(S){for(l=0;!E.isZero();l++)_=E.andln(255),E.iushrn(8),$[l]=_;for(;l<w;l++)$[l]=0}else{for(l=0;l<w-y;l++)$[l]=0;for(l=0;!E.isZero();l++)_=E.andln(255),E.iushrn(8),$[w-l-1]=_}return $},Math.clz32?s.prototype._countBits=function(h){return 32-Math.clz32(h)}:s.prototype._countBits=function(h){var p=h,m=0;return p>=4096&&(m+=13,p>>>=13),p>=64&&(m+=7,p>>>=7),p>=8&&(m+=4,p>>>=4),p>=2&&(m+=2,p>>>=2),m+p},s.prototype._zeroBits=function(h){if(h===0)return 26;var p=h,m=0;return p&8191||(m+=13,p>>>=13),p&127||(m+=7,p>>>=7),p&15||(m+=4,p>>>=4),p&3||(m+=2,p>>>=2),p&1||m++,m},s.prototype.bitLength=function(){var h=this.words[this.length-1],p=this._countBits(h);return(this.length-1)*26+p};function v(A){for(var h=new Array(A.bitLength()),p=0;p<h.length;p++){var m=p/26|0,y=p%26;h[p]=(A.words[m]&1<<y)>>>y}return h}s.prototype.zeroBits=function(){if(this.isZero())return 0;for(var h=0,p=0;p<this.length;p++){var m=this._zeroBits(this.words[p]);if(h+=m,m!==26)break}return h},s.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},s.prototype.toTwos=function(h){return this.negative!==0?this.abs().inotn(h).iaddn(1):this.clone()},s.prototype.fromTwos=function(h){return this.testn(h-1)?this.notn(h).iaddn(1).ineg():this.clone()},s.prototype.isNeg=function(){return this.negative!==0},s.prototype.neg=function(){return this.clone().ineg()},s.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},s.prototype.iuor=function(h){for(;this.length<h.length;)this.words[this.length++]=0;for(var p=0;p<h.length;p++)this.words[p]=this.words[p]|h.words[p];return this.strip()},s.prototype.ior=function(h){return i((this.negative|h.negative)===0),this.iuor(h)},s.prototype.or=function(h){return this.length>h.length?this.clone().ior(h):h.clone().ior(this)},s.prototype.uor=function(h){return this.length>h.length?this.clone().iuor(h):h.clone().iuor(this)},s.prototype.iuand=function(h){var p;this.length>h.length?p=h:p=this;for(var m=0;m<p.length;m++)this.words[m]=this.words[m]&h.words[m];return this.length=p.length,this.strip()},s.prototype.iand=function(h){return i((this.negative|h.negative)===0),this.iuand(h)},s.prototype.and=function(h){return this.length>h.length?this.clone().iand(h):h.clone().iand(this)},s.prototype.uand=function(h){return this.length>h.length?this.clone().iuand(h):h.clone().iuand(this)},s.prototype.iuxor=function(h){var p,m;this.length>h.length?(p=this,m=h):(p=h,m=this);for(var y=0;y<m.length;y++)this.words[y]=p.words[y]^m.words[y];if(this!==p)for(;y<p.length;y++)this.words[y]=p.words[y];return this.length=p.length,this.strip()},s.prototype.ixor=function(h){return i((this.negative|h.negative)===0),this.iuxor(h)},s.prototype.xor=function(h){return this.length>h.length?this.clone().ixor(h):h.clone().ixor(this)},s.prototype.uxor=function(h){return this.length>h.length?this.clone().iuxor(h):h.clone().iuxor(this)},s.prototype.inotn=function(h){i(typeof h=="number"&&h>=0);var p=Math.ceil(h/26)|0,m=h%26;this._expand(p),m>0&&p--;for(var y=0;y<p;y++)this.words[y]=~this.words[y]&67108863;return m>0&&(this.words[y]=~this.words[y]&67108863>>26-m),this.strip()},s.prototype.notn=function(h){return this.clone().inotn(h)},s.prototype.setn=function(h,p){i(typeof h=="number"&&h>=0);var m=h/26|0,y=h%26;return this._expand(m+1),p?this.words[m]=this.words[m]|1<<y:this.words[m]=this.words[m]&~(1<<y),this.strip()},s.prototype.iadd=function(h){var p;if(this.negative!==0&&h.negative===0)return this.negative=0,p=this.isub(h),this.negative^=1,this._normSign();if(this.negative===0&&h.negative!==0)return h.negative=0,p=this.isub(h),h.negative=1,p._normSign();var m,y;this.length>h.length?(m=this,y=h):(m=h,y=this);for(var w=0,S=0;S<y.length;S++)p=(m.words[S]|0)+(y.words[S]|0)+w,this.words[S]=p&67108863,w=p>>>26;for(;w!==0&&S<m.length;S++)p=(m.words[S]|0)+w,this.words[S]=p&67108863,w=p>>>26;if(this.length=m.length,w!==0)this.words[this.length]=w,this.length++;else if(m!==this)for(;S<m.length;S++)this.words[S]=m.words[S];return this},s.prototype.add=function(h){var p;return h.negative!==0&&this.negative===0?(h.negative=0,p=this.sub(h),h.negative^=1,p):h.negative===0&&this.negative!==0?(this.negative=0,p=h.sub(this),this.negative=1,p):this.length>h.length?this.clone().iadd(h):h.clone().iadd(this)},s.prototype.isub=function(h){if(h.negative!==0){h.negative=0;var p=this.iadd(h);return h.negative=1,p._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(h),this.negative=1,this._normSign();var m=this.cmp(h);if(m===0)return this.negative=0,this.length=1,this.words[0]=0,this;var y,w;m>0?(y=this,w=h):(y=h,w=this);for(var S=0,$=0;$<w.length;$++)p=(y.words[$]|0)-(w.words[$]|0)+S,S=p>>26,this.words[$]=p&67108863;for(;S!==0&&$<y.length;$++)p=(y.words[$]|0)+S,S=p>>26,this.words[$]=p&67108863;if(S===0&&$<y.length&&y!==this)for(;$<y.length;$++)this.words[$]=y.words[$];return this.length=Math.max(this.length,$),y!==this&&(this.negative=1),this.strip()},s.prototype.sub=function(h){return this.clone().isub(h)};function g(A,h,p){p.negative=h.negative^A.negative;var m=A.length+h.length|0;p.length=m,m=m-1|0;var y=A.words[0]|0,w=h.words[0]|0,S=y*w,$=S&67108863,_=S/67108864|0;p.words[0]=$;for(var l=1;l<m;l++){for(var E=_>>>26,F=_&67108863,L=Math.min(l,h.length-1),q=Math.max(0,l-A.length+1);q<=L;q++){var j=l-q|0;y=A.words[j]|0,w=h.words[q]|0,S=y*w+F,E+=S/67108864|0,F=S&67108863}p.words[l]=F|0,_=E|0}return _!==0?p.words[l]=_|0:p.length--,p.strip()}var x=function(h,p,m){var y=h.words,w=p.words,S=m.words,$=0,_,l,E,F=y[0]|0,L=F&8191,q=F>>>13,j=y[1]|0,K=j&8191,W=j>>>13,Z=y[2]|0,H=Z&8191,G=Z>>>13,Me=y[3]|0,X=Me&8191,ie=Me>>>13,St=y[4]|0,fe=St&8191,_e=St>>>13,Bo=y[5]|0,xe=Bo&8191,ge=Bo>>>13,gs=y[6]|0,be=gs&8191,ye=gs>>>13,ys=y[7]|0,ve=ys&8191,me=ys>>>13,vs=y[8]|0,Ee=vs&8191,Se=vs>>>13,Fo=y[9]|0,Ie=Fo&8191,Pe=Fo>>>13,r1=w[0]|0,Re=r1&8191,Te=r1>>>13,i1=w[1]|0,Ne=i1&8191,Ce=i1>>>13,n1=w[2]|0,Be=n1&8191,Fe=n1>>>13,s1=w[3]|0,Le=s1&8191,qe=s1>>>13,o1=w[4]|0,ke=o1&8191,ze=o1>>>13,a1=w[5]|0,Ue=a1&8191,je=a1>>>13,c1=w[6]|0,Ve=c1&8191,Ke=c1>>>13,f1=w[7]|0,He=f1&8191,We=f1>>>13,u1=w[8]|0,Ge=u1&8191,Ye=u1>>>13,h1=w[9]|0,Ze=h1&8191,Je=h1>>>13;m.negative=h.negative^p.negative,m.length=19,_=Math.imul(L,Re),l=Math.imul(L,Te),l=l+Math.imul(q,Re)|0,E=Math.imul(q,Te);var xf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(xf>>>26)|0,xf&=67108863,_=Math.imul(K,Re),l=Math.imul(K,Te),l=l+Math.imul(W,Re)|0,E=Math.imul(W,Te),_=_+Math.imul(L,Ne)|0,l=l+Math.imul(L,Ce)|0,l=l+Math.imul(q,Ne)|0,E=E+Math.imul(q,Ce)|0;var Ef=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Ef>>>26)|0,Ef&=67108863,_=Math.imul(H,Re),l=Math.imul(H,Te),l=l+Math.imul(G,Re)|0,E=Math.imul(G,Te),_=_+Math.imul(K,Ne)|0,l=l+Math.imul(K,Ce)|0,l=l+Math.imul(W,Ne)|0,E=E+Math.imul(W,Ce)|0,_=_+Math.imul(L,Be)|0,l=l+Math.imul(L,Fe)|0,l=l+Math.imul(q,Be)|0,E=E+Math.imul(q,Fe)|0;var Sf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Sf>>>26)|0,Sf&=67108863,_=Math.imul(X,Re),l=Math.imul(X,Te),l=l+Math.imul(ie,Re)|0,E=Math.imul(ie,Te),_=_+Math.imul(H,Ne)|0,l=l+Math.imul(H,Ce)|0,l=l+Math.imul(G,Ne)|0,E=E+Math.imul(G,Ce)|0,_=_+Math.imul(K,Be)|0,l=l+Math.imul(K,Fe)|0,l=l+Math.imul(W,Be)|0,E=E+Math.imul(W,Fe)|0,_=_+Math.imul(L,Le)|0,l=l+Math.imul(L,qe)|0,l=l+Math.imul(q,Le)|0,E=E+Math.imul(q,qe)|0;var If=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(If>>>26)|0,If&=67108863,_=Math.imul(fe,Re),l=Math.imul(fe,Te),l=l+Math.imul(_e,Re)|0,E=Math.imul(_e,Te),_=_+Math.imul(X,Ne)|0,l=l+Math.imul(X,Ce)|0,l=l+Math.imul(ie,Ne)|0,E=E+Math.imul(ie,Ce)|0,_=_+Math.imul(H,Be)|0,l=l+Math.imul(H,Fe)|0,l=l+Math.imul(G,Be)|0,E=E+Math.imul(G,Fe)|0,_=_+Math.imul(K,Le)|0,l=l+Math.imul(K,qe)|0,l=l+Math.imul(W,Le)|0,E=E+Math.imul(W,qe)|0,_=_+Math.imul(L,ke)|0,l=l+Math.imul(L,ze)|0,l=l+Math.imul(q,ke)|0,E=E+Math.imul(q,ze)|0;var Af=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Af>>>26)|0,Af&=67108863,_=Math.imul(xe,Re),l=Math.imul(xe,Te),l=l+Math.imul(ge,Re)|0,E=Math.imul(ge,Te),_=_+Math.imul(fe,Ne)|0,l=l+Math.imul(fe,Ce)|0,l=l+Math.imul(_e,Ne)|0,E=E+Math.imul(_e,Ce)|0,_=_+Math.imul(X,Be)|0,l=l+Math.imul(X,Fe)|0,l=l+Math.imul(ie,Be)|0,E=E+Math.imul(ie,Fe)|0,_=_+Math.imul(H,Le)|0,l=l+Math.imul(H,qe)|0,l=l+Math.imul(G,Le)|0,E=E+Math.imul(G,qe)|0,_=_+Math.imul(K,ke)|0,l=l+Math.imul(K,ze)|0,l=l+Math.imul(W,ke)|0,E=E+Math.imul(W,ze)|0,_=_+Math.imul(L,Ue)|0,l=l+Math.imul(L,je)|0,l=l+Math.imul(q,Ue)|0,E=E+Math.imul(q,je)|0;var $f=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+($f>>>26)|0,$f&=67108863,_=Math.imul(be,Re),l=Math.imul(be,Te),l=l+Math.imul(ye,Re)|0,E=Math.imul(ye,Te),_=_+Math.imul(xe,Ne)|0,l=l+Math.imul(xe,Ce)|0,l=l+Math.imul(ge,Ne)|0,E=E+Math.imul(ge,Ce)|0,_=_+Math.imul(fe,Be)|0,l=l+Math.imul(fe,Fe)|0,l=l+Math.imul(_e,Be)|0,E=E+Math.imul(_e,Fe)|0,_=_+Math.imul(X,Le)|0,l=l+Math.imul(X,qe)|0,l=l+Math.imul(ie,Le)|0,E=E+Math.imul(ie,qe)|0,_=_+Math.imul(H,ke)|0,l=l+Math.imul(H,ze)|0,l=l+Math.imul(G,ke)|0,E=E+Math.imul(G,ze)|0,_=_+Math.imul(K,Ue)|0,l=l+Math.imul(K,je)|0,l=l+Math.imul(W,Ue)|0,E=E+Math.imul(W,je)|0,_=_+Math.imul(L,Ve)|0,l=l+Math.imul(L,Ke)|0,l=l+Math.imul(q,Ve)|0,E=E+Math.imul(q,Ke)|0;var Df=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Df>>>26)|0,Df&=67108863,_=Math.imul(ve,Re),l=Math.imul(ve,Te),l=l+Math.imul(me,Re)|0,E=Math.imul(me,Te),_=_+Math.imul(be,Ne)|0,l=l+Math.imul(be,Ce)|0,l=l+Math.imul(ye,Ne)|0,E=E+Math.imul(ye,Ce)|0,_=_+Math.imul(xe,Be)|0,l=l+Math.imul(xe,Fe)|0,l=l+Math.imul(ge,Be)|0,E=E+Math.imul(ge,Fe)|0,_=_+Math.imul(fe,Le)|0,l=l+Math.imul(fe,qe)|0,l=l+Math.imul(_e,Le)|0,E=E+Math.imul(_e,qe)|0,_=_+Math.imul(X,ke)|0,l=l+Math.imul(X,ze)|0,l=l+Math.imul(ie,ke)|0,E=E+Math.imul(ie,ze)|0,_=_+Math.imul(H,Ue)|0,l=l+Math.imul(H,je)|0,l=l+Math.imul(G,Ue)|0,E=E+Math.imul(G,je)|0,_=_+Math.imul(K,Ve)|0,l=l+Math.imul(K,Ke)|0,l=l+Math.imul(W,Ve)|0,E=E+Math.imul(W,Ke)|0,_=_+Math.imul(L,He)|0,l=l+Math.imul(L,We)|0,l=l+Math.imul(q,He)|0,E=E+Math.imul(q,We)|0;var Of=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Of>>>26)|0,Of&=67108863,_=Math.imul(Ee,Re),l=Math.imul(Ee,Te),l=l+Math.imul(Se,Re)|0,E=Math.imul(Se,Te),_=_+Math.imul(ve,Ne)|0,l=l+Math.imul(ve,Ce)|0,l=l+Math.imul(me,Ne)|0,E=E+Math.imul(me,Ce)|0,_=_+Math.imul(be,Be)|0,l=l+Math.imul(be,Fe)|0,l=l+Math.imul(ye,Be)|0,E=E+Math.imul(ye,Fe)|0,_=_+Math.imul(xe,Le)|0,l=l+Math.imul(xe,qe)|0,l=l+Math.imul(ge,Le)|0,E=E+Math.imul(ge,qe)|0,_=_+Math.imul(fe,ke)|0,l=l+Math.imul(fe,ze)|0,l=l+Math.imul(_e,ke)|0,E=E+Math.imul(_e,ze)|0,_=_+Math.imul(X,Ue)|0,l=l+Math.imul(X,je)|0,l=l+Math.imul(ie,Ue)|0,E=E+Math.imul(ie,je)|0,_=_+Math.imul(H,Ve)|0,l=l+Math.imul(H,Ke)|0,l=l+Math.imul(G,Ve)|0,E=E+Math.imul(G,Ke)|0,_=_+Math.imul(K,He)|0,l=l+Math.imul(K,We)|0,l=l+Math.imul(W,He)|0,E=E+Math.imul(W,We)|0,_=_+Math.imul(L,Ge)|0,l=l+Math.imul(L,Ye)|0,l=l+Math.imul(q,Ge)|0,E=E+Math.imul(q,Ye)|0;var Mf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Mf>>>26)|0,Mf&=67108863,_=Math.imul(Ie,Re),l=Math.imul(Ie,Te),l=l+Math.imul(Pe,Re)|0,E=Math.imul(Pe,Te),_=_+Math.imul(Ee,Ne)|0,l=l+Math.imul(Ee,Ce)|0,l=l+Math.imul(Se,Ne)|0,E=E+Math.imul(Se,Ce)|0,_=_+Math.imul(ve,Be)|0,l=l+Math.imul(ve,Fe)|0,l=l+Math.imul(me,Be)|0,E=E+Math.imul(me,Fe)|0,_=_+Math.imul(be,Le)|0,l=l+Math.imul(be,qe)|0,l=l+Math.imul(ye,Le)|0,E=E+Math.imul(ye,qe)|0,_=_+Math.imul(xe,ke)|0,l=l+Math.imul(xe,ze)|0,l=l+Math.imul(ge,ke)|0,E=E+Math.imul(ge,ze)|0,_=_+Math.imul(fe,Ue)|0,l=l+Math.imul(fe,je)|0,l=l+Math.imul(_e,Ue)|0,E=E+Math.imul(_e,je)|0,_=_+Math.imul(X,Ve)|0,l=l+Math.imul(X,Ke)|0,l=l+Math.imul(ie,Ve)|0,E=E+Math.imul(ie,Ke)|0,_=_+Math.imul(H,He)|0,l=l+Math.imul(H,We)|0,l=l+Math.imul(G,He)|0,E=E+Math.imul(G,We)|0,_=_+Math.imul(K,Ge)|0,l=l+Math.imul(K,Ye)|0,l=l+Math.imul(W,Ge)|0,E=E+Math.imul(W,Ye)|0,_=_+Math.imul(L,Ze)|0,l=l+Math.imul(L,Je)|0,l=l+Math.imul(q,Ze)|0,E=E+Math.imul(q,Je)|0;var Pf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Pf>>>26)|0,Pf&=67108863,_=Math.imul(Ie,Ne),l=Math.imul(Ie,Ce),l=l+Math.imul(Pe,Ne)|0,E=Math.imul(Pe,Ce),_=_+Math.imul(Ee,Be)|0,l=l+Math.imul(Ee,Fe)|0,l=l+Math.imul(Se,Be)|0,E=E+Math.imul(Se,Fe)|0,_=_+Math.imul(ve,Le)|0,l=l+Math.imul(ve,qe)|0,l=l+Math.imul(me,Le)|0,E=E+Math.imul(me,qe)|0,_=_+Math.imul(be,ke)|0,l=l+Math.imul(be,ze)|0,l=l+Math.imul(ye,ke)|0,E=E+Math.imul(ye,ze)|0,_=_+Math.imul(xe,Ue)|0,l=l+Math.imul(xe,je)|0,l=l+Math.imul(ge,Ue)|0,E=E+Math.imul(ge,je)|0,_=_+Math.imul(fe,Ve)|0,l=l+Math.imul(fe,Ke)|0,l=l+Math.imul(_e,Ve)|0,E=E+Math.imul(_e,Ke)|0,_=_+Math.imul(X,He)|0,l=l+Math.imul(X,We)|0,l=l+Math.imul(ie,He)|0,E=E+Math.imul(ie,We)|0,_=_+Math.imul(H,Ge)|0,l=l+Math.imul(H,Ye)|0,l=l+Math.imul(G,Ge)|0,E=E+Math.imul(G,Ye)|0,_=_+Math.imul(K,Ze)|0,l=l+Math.imul(K,Je)|0,l=l+Math.imul(W,Ze)|0,E=E+Math.imul(W,Je)|0;var Rf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Rf>>>26)|0,Rf&=67108863,_=Math.imul(Ie,Be),l=Math.imul(Ie,Fe),l=l+Math.imul(Pe,Be)|0,E=Math.imul(Pe,Fe),_=_+Math.imul(Ee,Le)|0,l=l+Math.imul(Ee,qe)|0,l=l+Math.imul(Se,Le)|0,E=E+Math.imul(Se,qe)|0,_=_+Math.imul(ve,ke)|0,l=l+Math.imul(ve,ze)|0,l=l+Math.imul(me,ke)|0,E=E+Math.imul(me,ze)|0,_=_+Math.imul(be,Ue)|0,l=l+Math.imul(be,je)|0,l=l+Math.imul(ye,Ue)|0,E=E+Math.imul(ye,je)|0,_=_+Math.imul(xe,Ve)|0,l=l+Math.imul(xe,Ke)|0,l=l+Math.imul(ge,Ve)|0,E=E+Math.imul(ge,Ke)|0,_=_+Math.imul(fe,He)|0,l=l+Math.imul(fe,We)|0,l=l+Math.imul(_e,He)|0,E=E+Math.imul(_e,We)|0,_=_+Math.imul(X,Ge)|0,l=l+Math.imul(X,Ye)|0,l=l+Math.imul(ie,Ge)|0,E=E+Math.imul(ie,Ye)|0,_=_+Math.imul(H,Ze)|0,l=l+Math.imul(H,Je)|0,l=l+Math.imul(G,Ze)|0,E=E+Math.imul(G,Je)|0;var Tf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Tf>>>26)|0,Tf&=67108863,_=Math.imul(Ie,Le),l=Math.imul(Ie,qe),l=l+Math.imul(Pe,Le)|0,E=Math.imul(Pe,qe),_=_+Math.imul(Ee,ke)|0,l=l+Math.imul(Ee,ze)|0,l=l+Math.imul(Se,ke)|0,E=E+Math.imul(Se,ze)|0,_=_+Math.imul(ve,Ue)|0,l=l+Math.imul(ve,je)|0,l=l+Math.imul(me,Ue)|0,E=E+Math.imul(me,je)|0,_=_+Math.imul(be,Ve)|0,l=l+Math.imul(be,Ke)|0,l=l+Math.imul(ye,Ve)|0,E=E+Math.imul(ye,Ke)|0,_=_+Math.imul(xe,He)|0,l=l+Math.imul(xe,We)|0,l=l+Math.imul(ge,He)|0,E=E+Math.imul(ge,We)|0,_=_+Math.imul(fe,Ge)|0,l=l+Math.imul(fe,Ye)|0,l=l+Math.imul(_e,Ge)|0,E=E+Math.imul(_e,Ye)|0,_=_+Math.imul(X,Ze)|0,l=l+Math.imul(X,Je)|0,l=l+Math.imul(ie,Ze)|0,E=E+Math.imul(ie,Je)|0;var Nf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Nf>>>26)|0,Nf&=67108863,_=Math.imul(Ie,ke),l=Math.imul(Ie,ze),l=l+Math.imul(Pe,ke)|0,E=Math.imul(Pe,ze),_=_+Math.imul(Ee,Ue)|0,l=l+Math.imul(Ee,je)|0,l=l+Math.imul(Se,Ue)|0,E=E+Math.imul(Se,je)|0,_=_+Math.imul(ve,Ve)|0,l=l+Math.imul(ve,Ke)|0,l=l+Math.imul(me,Ve)|0,E=E+Math.imul(me,Ke)|0,_=_+Math.imul(be,He)|0,l=l+Math.imul(be,We)|0,l=l+Math.imul(ye,He)|0,E=E+Math.imul(ye,We)|0,_=_+Math.imul(xe,Ge)|0,l=l+Math.imul(xe,Ye)|0,l=l+Math.imul(ge,Ge)|0,E=E+Math.imul(ge,Ye)|0,_=_+Math.imul(fe,Ze)|0,l=l+Math.imul(fe,Je)|0,l=l+Math.imul(_e,Ze)|0,E=E+Math.imul(_e,Je)|0;var Cf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Cf>>>26)|0,Cf&=67108863,_=Math.imul(Ie,Ue),l=Math.imul(Ie,je),l=l+Math.imul(Pe,Ue)|0,E=Math.imul(Pe,je),_=_+Math.imul(Ee,Ve)|0,l=l+Math.imul(Ee,Ke)|0,l=l+Math.imul(Se,Ve)|0,E=E+Math.imul(Se,Ke)|0,_=_+Math.imul(ve,He)|0,l=l+Math.imul(ve,We)|0,l=l+Math.imul(me,He)|0,E=E+Math.imul(me,We)|0,_=_+Math.imul(be,Ge)|0,l=l+Math.imul(be,Ye)|0,l=l+Math.imul(ye,Ge)|0,E=E+Math.imul(ye,Ye)|0,_=_+Math.imul(xe,Ze)|0,l=l+Math.imul(xe,Je)|0,l=l+Math.imul(ge,Ze)|0,E=E+Math.imul(ge,Je)|0;var Bf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Bf>>>26)|0,Bf&=67108863,_=Math.imul(Ie,Ve),l=Math.imul(Ie,Ke),l=l+Math.imul(Pe,Ve)|0,E=Math.imul(Pe,Ke),_=_+Math.imul(Ee,He)|0,l=l+Math.imul(Ee,We)|0,l=l+Math.imul(Se,He)|0,E=E+Math.imul(Se,We)|0,_=_+Math.imul(ve,Ge)|0,l=l+Math.imul(ve,Ye)|0,l=l+Math.imul(me,Ge)|0,E=E+Math.imul(me,Ye)|0,_=_+Math.imul(be,Ze)|0,l=l+Math.imul(be,Je)|0,l=l+Math.imul(ye,Ze)|0,E=E+Math.imul(ye,Je)|0;var Ff=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Ff>>>26)|0,Ff&=67108863,_=Math.imul(Ie,He),l=Math.imul(Ie,We),l=l+Math.imul(Pe,He)|0,E=Math.imul(Pe,We),_=_+Math.imul(Ee,Ge)|0,l=l+Math.imul(Ee,Ye)|0,l=l+Math.imul(Se,Ge)|0,E=E+Math.imul(Se,Ye)|0,_=_+Math.imul(ve,Ze)|0,l=l+Math.imul(ve,Je)|0,l=l+Math.imul(me,Ze)|0,E=E+Math.imul(me,Je)|0;var Lf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(Lf>>>26)|0,Lf&=67108863,_=Math.imul(Ie,Ge),l=Math.imul(Ie,Ye),l=l+Math.imul(Pe,Ge)|0,E=Math.imul(Pe,Ye),_=_+Math.imul(Ee,Ze)|0,l=l+Math.imul(Ee,Je)|0,l=l+Math.imul(Se,Ze)|0,E=E+Math.imul(Se,Je)|0;var qf=($+_|0)+((l&8191)<<13)|0;$=(E+(l>>>13)|0)+(qf>>>26)|0,qf&=67108863,_=Math.imul(Ie,Ze),l=Math.imul(Ie,Je),l=l+Math.imul(Pe,Ze)|0,E=Math.imul(Pe,Je);var kf=($+_|0)+((l&8191)<<13)|0;return $=(E+(l>>>13)|0)+(kf>>>26)|0,kf&=67108863,S[0]=xf,S[1]=Ef,S[2]=Sf,S[3]=If,S[4]=Af,S[5]=$f,S[6]=Df,S[7]=Of,S[8]=Mf,S[9]=Pf,S[10]=Rf,S[11]=Tf,S[12]=Nf,S[13]=Cf,S[14]=Bf,S[15]=Ff,S[16]=Lf,S[17]=qf,S[18]=kf,$!==0&&(S[19]=$,m.length++),m};Math.imul||(x=g);function I(A,h,p){p.negative=h.negative^A.negative,p.length=A.length+h.length;for(var m=0,y=0,w=0;w<p.length-1;w++){var S=y;y=0;for(var $=m&67108863,_=Math.min(w,h.length-1),l=Math.max(0,w-A.length+1);l<=_;l++){var E=w-l,F=A.words[E]|0,L=h.words[l]|0,q=F*L,j=q&67108863;S=S+(q/67108864|0)|0,j=j+$|0,$=j&67108863,S=S+(j>>>26)|0,y+=S>>>26,S&=67108863}p.words[w]=$,m=S,S=y}return m!==0?p.words[w]=m:p.length--,p.strip()}function D(A,h,p){var m=new O;return m.mulp(A,h,p)}s.prototype.mulTo=function(h,p){var m,y=this.length+h.length;return this.length===10&&h.length===10?m=x(this,h,p):y<63?m=g(this,h,p):y<1024?m=I(this,h,p):m=D(this,h,p),m};function O(A,h){this.x=A,this.y=h}O.prototype.makeRBT=function(h){for(var p=new Array(h),m=s.prototype._countBits(h)-1,y=0;y<h;y++)p[y]=this.revBin(y,m,h);return p},O.prototype.revBin=function(h,p,m){if(h===0||h===m-1)return h;for(var y=0,w=0;w<p;w++)y|=(h&1)<<p-w-1,h>>=1;return y},O.prototype.permute=function(h,p,m,y,w,S){for(var $=0;$<S;$++)y[$]=p[h[$]],w[$]=m[h[$]]},O.prototype.transform=function(h,p,m,y,w,S){this.permute(S,h,p,m,y,w);for(var $=1;$<w;$<<=1)for(var _=$<<1,l=Math.cos(2*Math.PI/_),E=Math.sin(2*Math.PI/_),F=0;F<w;F+=_)for(var L=l,q=E,j=0;j<$;j++){var K=m[F+j],W=y[F+j],Z=m[F+j+$],H=y[F+j+$],G=L*Z-q*H;H=L*H+q*Z,Z=G,m[F+j]=K+Z,y[F+j]=W+H,m[F+j+$]=K-Z,y[F+j+$]=W-H,j!==_&&(G=l*L-E*q,q=l*q+E*L,L=G)}},O.prototype.guessLen13b=function(h,p){var m=Math.max(p,h)|1,y=m&1,w=0;for(m=m/2|0;m;m=m>>>1)w++;return 1<<w+1+y},O.prototype.conjugate=function(h,p,m){if(!(m<=1))for(var y=0;y<m/2;y++){var w=h[y];h[y]=h[m-y-1],h[m-y-1]=w,w=p[y],p[y]=-p[m-y-1],p[m-y-1]=-w}},O.prototype.normalize13b=function(h,p){for(var m=0,y=0;y<p/2;y++){var w=Math.round(h[2*y+1]/p)*8192+Math.round(h[2*y]/p)+m;h[y]=w&67108863,w<67108864?m=0:m=w/67108864|0}return h},O.prototype.convert13b=function(h,p,m,y){for(var w=0,S=0;S<p;S++)w=w+(h[S]|0),m[2*S]=w&8191,w=w>>>13,m[2*S+1]=w&8191,w=w>>>13;for(S=2*p;S<y;++S)m[S]=0;i(w===0),i((w&-8192)===0)},O.prototype.stub=function(h){for(var p=new Array(h),m=0;m<h;m++)p[m]=0;return p},O.prototype.mulp=function(h,p,m){var y=2*this.guessLen13b(h.length,p.length),w=this.makeRBT(y),S=this.stub(y),$=new Array(y),_=new Array(y),l=new Array(y),E=new Array(y),F=new Array(y),L=new Array(y),q=m.words;q.length=y,this.convert13b(h.words,h.length,$,y),this.convert13b(p.words,p.length,E,y),this.transform($,S,_,l,y,w),this.transform(E,S,F,L,y,w);for(var j=0;j<y;j++){var K=_[j]*F[j]-l[j]*L[j];l[j]=_[j]*L[j]+l[j]*F[j],_[j]=K}return this.conjugate(_,l,y),this.transform(_,l,q,S,y,w),this.conjugate(q,S,y),this.normalize13b(q,y),m.negative=h.negative^p.negative,m.length=h.length+p.length,m.strip()},s.prototype.mul=function(h){var p=new s(null);return p.words=new Array(this.length+h.length),this.mulTo(h,p)},s.prototype.mulf=function(h){var p=new s(null);return p.words=new Array(this.length+h.length),D(this,h,p)},s.prototype.imul=function(h){return this.clone().mulTo(h,this)},s.prototype.imuln=function(h){i(typeof h=="number"),i(h<67108864);for(var p=0,m=0;m<this.length;m++){var y=(this.words[m]|0)*h,w=(y&67108863)+(p&67108863);p>>=26,p+=y/67108864|0,p+=w>>>26,this.words[m]=w&67108863}return p!==0&&(this.words[m]=p,this.length++),this},s.prototype.muln=function(h){return this.clone().imuln(h)},s.prototype.sqr=function(){return this.mul(this)},s.prototype.isqr=function(){return this.imul(this.clone())},s.prototype.pow=function(h){var p=v(h);if(p.length===0)return new s(1);for(var m=this,y=0;y<p.length&&p[y]===0;y++,m=m.sqr());if(++y<p.length)for(var w=m.sqr();y<p.length;y++,w=w.sqr())p[y]!==0&&(m=m.mul(w));return m},s.prototype.iushln=function(h){i(typeof h=="number"&&h>=0);var p=h%26,m=(h-p)/26,y=67108863>>>26-p<<26-p,w;if(p!==0){var S=0;for(w=0;w<this.length;w++){var $=this.words[w]&y,_=(this.words[w]|0)-$<<p;this.words[w]=_|S,S=$>>>26-p}S&&(this.words[w]=S,this.length++)}if(m!==0){for(w=this.length-1;w>=0;w--)this.words[w+m]=this.words[w];for(w=0;w<m;w++)this.words[w]=0;this.length+=m}return this.strip()},s.prototype.ishln=function(h){return i(this.negative===0),this.iushln(h)},s.prototype.iushrn=function(h,p,m){i(typeof h=="number"&&h>=0);var y;p?y=(p-p%26)/26:y=0;var w=h%26,S=Math.min((h-w)/26,this.length),$=67108863^67108863>>>w<<w,_=m;if(y-=S,y=Math.max(0,y),_){for(var l=0;l<S;l++)_.words[l]=this.words[l];_.length=S}if(S!==0)if(this.length>S)for(this.length-=S,l=0;l<this.length;l++)this.words[l]=this.words[l+S];else this.words[0]=0,this.length=1;var E=0;for(l=this.length-1;l>=0&&(E!==0||l>=y);l--){var F=this.words[l]|0;this.words[l]=E<<26-w|F>>>w,E=F&$}return _&&E!==0&&(_.words[_.length++]=E),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},s.prototype.ishrn=function(h,p,m){return i(this.negative===0),this.iushrn(h,p,m)},s.prototype.shln=function(h){return this.clone().ishln(h)},s.prototype.ushln=function(h){return this.clone().iushln(h)},s.prototype.shrn=function(h){return this.clone().ishrn(h)},s.prototype.ushrn=function(h){return this.clone().iushrn(h)},s.prototype.testn=function(h){i(typeof h=="number"&&h>=0);var p=h%26,m=(h-p)/26,y=1<<p;if(this.length<=m)return!1;var w=this.words[m];return!!(w&y)},s.prototype.imaskn=function(h){i(typeof h=="number"&&h>=0);var p=h%26,m=(h-p)/26;if(i(this.negative===0,"imaskn works only with positive numbers"),this.length<=m)return this;if(p!==0&&m++,this.length=Math.min(m,this.length),p!==0){var y=67108863^67108863>>>p<<p;this.words[this.length-1]&=y}return this.strip()},s.prototype.maskn=function(h){return this.clone().imaskn(h)},s.prototype.iaddn=function(h){return i(typeof h=="number"),i(h<67108864),h<0?this.isubn(-h):this.negative!==0?this.length===1&&(this.words[0]|0)<h?(this.words[0]=h-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(h),this.negative=1,this):this._iaddn(h)},s.prototype._iaddn=function(h){this.words[0]+=h;for(var p=0;p<this.length&&this.words[p]>=67108864;p++)this.words[p]-=67108864,p===this.length-1?this.words[p+1]=1:this.words[p+1]++;return this.length=Math.max(this.length,p+1),this},s.prototype.isubn=function(h){if(i(typeof h=="number"),i(h<67108864),h<0)return this.iaddn(-h);if(this.negative!==0)return this.negative=0,this.iaddn(h),this.negative=1,this;if(this.words[0]-=h,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var p=0;p<this.length&&this.words[p]<0;p++)this.words[p]+=67108864,this.words[p+1]-=1;return this.strip()},s.prototype.addn=function(h){return this.clone().iaddn(h)},s.prototype.subn=function(h){return this.clone().isubn(h)},s.prototype.iabs=function(){return this.negative=0,this},s.prototype.abs=function(){return this.clone().iabs()},s.prototype._ishlnsubmul=function(h,p,m){var y=h.length+m,w;this._expand(y);var S,$=0;for(w=0;w<h.length;w++){S=(this.words[w+m]|0)+$;var _=(h.words[w]|0)*p;S-=_&67108863,$=(S>>26)-(_/67108864|0),this.words[w+m]=S&67108863}for(;w<this.length-m;w++)S=(this.words[w+m]|0)+$,$=S>>26,this.words[w+m]=S&67108863;if($===0)return this.strip();for(i($===-1),$=0,w=0;w<this.length;w++)S=-(this.words[w]|0)+$,$=S>>26,this.words[w]=S&67108863;return this.negative=1,this.strip()},s.prototype._wordDiv=function(h,p){var m=this.length-h.length,y=this.clone(),w=h,S=w.words[w.length-1]|0,$=this._countBits(S);m=26-$,m!==0&&(w=w.ushln(m),y.iushln(m),S=w.words[w.length-1]|0);var _=y.length-w.length,l;if(p!=="mod"){l=new s(null),l.length=_+1,l.words=new Array(l.length);for(var E=0;E<l.length;E++)l.words[E]=0}var F=y.clone()._ishlnsubmul(w,1,_);F.negative===0&&(y=F,l&&(l.words[_]=1));for(var L=_-1;L>=0;L--){var q=(y.words[w.length+L]|0)*67108864+(y.words[w.length+L-1]|0);for(q=Math.min(q/S|0,67108863),y._ishlnsubmul(w,q,L);y.negative!==0;)q--,y.negative=0,y._ishlnsubmul(w,1,L),y.isZero()||(y.negative^=1);l&&(l.words[L]=q)}return l&&l.strip(),y.strip(),p!=="div"&&m!==0&&y.iushrn(m),{div:l||null,mod:y}},s.prototype.divmod=function(h,p,m){if(i(!h.isZero()),this.isZero())return{div:new s(0),mod:new s(0)};var y,w,S;return this.negative!==0&&h.negative===0?(S=this.neg().divmod(h,p),p!=="mod"&&(y=S.div.neg()),p!=="div"&&(w=S.mod.neg(),m&&w.negative!==0&&w.iadd(h)),{div:y,mod:w}):this.negative===0&&h.negative!==0?(S=this.divmod(h.neg(),p),p!=="mod"&&(y=S.div.neg()),{div:y,mod:S.mod}):this.negative&h.negative?(S=this.neg().divmod(h.neg(),p),p!=="div"&&(w=S.mod.neg(),m&&w.negative!==0&&w.isub(h)),{div:S.div,mod:w}):h.length>this.length||this.cmp(h)<0?{div:new s(0),mod:this}:h.length===1?p==="div"?{div:this.divn(h.words[0]),mod:null}:p==="mod"?{div:null,mod:new s(this.modn(h.words[0]))}:{div:this.divn(h.words[0]),mod:new s(this.modn(h.words[0]))}:this._wordDiv(h,p)},s.prototype.div=function(h){return this.divmod(h,"div",!1).div},s.prototype.mod=function(h){return this.divmod(h,"mod",!1).mod},s.prototype.umod=function(h){return this.divmod(h,"mod",!0).mod},s.prototype.divRound=function(h){var p=this.divmod(h);if(p.mod.isZero())return p.div;var m=p.div.negative!==0?p.mod.isub(h):p.mod,y=h.ushrn(1),w=h.andln(1),S=m.cmp(y);return S<0||w===1&&S===0?p.div:p.div.negative!==0?p.div.isubn(1):p.div.iaddn(1)},s.prototype.modn=function(h){i(h<=67108863);for(var p=(1<<26)%h,m=0,y=this.length-1;y>=0;y--)m=(p*m+(this.words[y]|0))%h;return m},s.prototype.idivn=function(h){i(h<=67108863);for(var p=0,m=this.length-1;m>=0;m--){var y=(this.words[m]|0)+p*67108864;this.words[m]=y/h|0,p=y%h}return this.strip()},s.prototype.divn=function(h){return this.clone().idivn(h)},s.prototype.egcd=function(h){i(h.negative===0),i(!h.isZero());var p=this,m=h.clone();p.negative!==0?p=p.umod(h):p=p.clone();for(var y=new s(1),w=new s(0),S=new s(0),$=new s(1),_=0;p.isEven()&&m.isEven();)p.iushrn(1),m.iushrn(1),++_;for(var l=m.clone(),E=p.clone();!p.isZero();){for(var F=0,L=1;!(p.words[0]&L)&&F<26;++F,L<<=1);if(F>0)for(p.iushrn(F);F-- >0;)(y.isOdd()||w.isOdd())&&(y.iadd(l),w.isub(E)),y.iushrn(1),w.iushrn(1);for(var q=0,j=1;!(m.words[0]&j)&&q<26;++q,j<<=1);if(q>0)for(m.iushrn(q);q-- >0;)(S.isOdd()||$.isOdd())&&(S.iadd(l),$.isub(E)),S.iushrn(1),$.iushrn(1);p.cmp(m)>=0?(p.isub(m),y.isub(S),w.isub($)):(m.isub(p),S.isub(y),$.isub(w))}return{a:S,b:$,gcd:m.iushln(_)}},s.prototype._invmp=function(h){i(h.negative===0),i(!h.isZero());var p=this,m=h.clone();p.negative!==0?p=p.umod(h):p=p.clone();for(var y=new s(1),w=new s(0),S=m.clone();p.cmpn(1)>0&&m.cmpn(1)>0;){for(var $=0,_=1;!(p.words[0]&_)&&$<26;++$,_<<=1);if($>0)for(p.iushrn($);$-- >0;)y.isOdd()&&y.iadd(S),y.iushrn(1);for(var l=0,E=1;!(m.words[0]&E)&&l<26;++l,E<<=1);if(l>0)for(m.iushrn(l);l-- >0;)w.isOdd()&&w.iadd(S),w.iushrn(1);p.cmp(m)>=0?(p.isub(m),y.isub(w)):(m.isub(p),w.isub(y))}var F;return p.cmpn(1)===0?F=y:F=w,F.cmpn(0)<0&&F.iadd(h),F},s.prototype.gcd=function(h){if(this.isZero())return h.abs();if(h.isZero())return this.abs();var p=this.clone(),m=h.clone();p.negative=0,m.negative=0;for(var y=0;p.isEven()&&m.isEven();y++)p.iushrn(1),m.iushrn(1);do{for(;p.isEven();)p.iushrn(1);for(;m.isEven();)m.iushrn(1);var w=p.cmp(m);if(w<0){var S=p;p=m,m=S}else if(w===0||m.cmpn(1)===0)break;p.isub(m)}while(!0);return m.iushln(y)},s.prototype.invm=function(h){return this.egcd(h).a.umod(h)},s.prototype.isEven=function(){return(this.words[0]&1)===0},s.prototype.isOdd=function(){return(this.words[0]&1)===1},s.prototype.andln=function(h){return this.words[0]&h},s.prototype.bincn=function(h){i(typeof h=="number");var p=h%26,m=(h-p)/26,y=1<<p;if(this.length<=m)return this._expand(m+1),this.words[m]|=y,this;for(var w=y,S=m;w!==0&&S<this.length;S++){var $=this.words[S]|0;$+=w,w=$>>>26,$&=67108863,this.words[S]=$}return w!==0&&(this.words[S]=w,this.length++),this},s.prototype.isZero=function(){return this.length===1&&this.words[0]===0},s.prototype.cmpn=function(h){var p=h<0;if(this.negative!==0&&!p)return-1;if(this.negative===0&&p)return 1;this.strip();var m;if(this.length>1)m=1;else{p&&(h=-h),i(h<=67108863,"Number is too big");var y=this.words[0]|0;m=y===h?0:y<h?-1:1}return this.negative!==0?-m|0:m},s.prototype.cmp=function(h){if(this.negative!==0&&h.negative===0)return-1;if(this.negative===0&&h.negative!==0)return 1;var p=this.ucmp(h);return this.negative!==0?-p|0:p},s.prototype.ucmp=function(h){if(this.length>h.length)return 1;if(this.length<h.length)return-1;for(var p=0,m=this.length-1;m>=0;m--){var y=this.words[m]|0,w=h.words[m]|0;if(y!==w){y<w?p=-1:y>w&&(p=1);break}}return p},s.prototype.gtn=function(h){return this.cmpn(h)===1},s.prototype.gt=function(h){return this.cmp(h)===1},s.prototype.gten=function(h){return this.cmpn(h)>=0},s.prototype.gte=function(h){return this.cmp(h)>=0},s.prototype.ltn=function(h){return this.cmpn(h)===-1},s.prototype.lt=function(h){return this.cmp(h)===-1},s.prototype.lten=function(h){return this.cmpn(h)<=0},s.prototype.lte=function(h){return this.cmp(h)<=0},s.prototype.eqn=function(h){return this.cmpn(h)===0},s.prototype.eq=function(h){return this.cmp(h)===0},s.red=function(h){return new R(h)},s.prototype.toRed=function(h){return i(!this.red,"Already a number in reduction context"),i(this.negative===0,"red works only with positives"),h.convertTo(this)._forceRed(h)},s.prototype.fromRed=function(){return i(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},s.prototype._forceRed=function(h){return this.red=h,this},s.prototype.forceRed=function(h){return i(!this.red,"Already a number in reduction context"),this._forceRed(h)},s.prototype.redAdd=function(h){return i(this.red,"redAdd works only with red numbers"),this.red.add(this,h)},s.prototype.redIAdd=function(h){return i(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,h)},s.prototype.redSub=function(h){return i(this.red,"redSub works only with red numbers"),this.red.sub(this,h)},s.prototype.redISub=function(h){return i(this.red,"redISub works only with red numbers"),this.red.isub(this,h)},s.prototype.redShl=function(h){return i(this.red,"redShl works only with red numbers"),this.red.shl(this,h)},s.prototype.redMul=function(h){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,h),this.red.mul(this,h)},s.prototype.redIMul=function(h){return i(this.red,"redMul works only with red numbers"),this.red._verify2(this,h),this.red.imul(this,h)},s.prototype.redSqr=function(){return i(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},s.prototype.redISqr=function(){return i(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},s.prototype.redSqrt=function(){return i(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},s.prototype.redInvm=function(){return i(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},s.prototype.redNeg=function(){return i(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},s.prototype.redPow=function(h){return i(this.red&&!h.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,h)};var M={k256:null,p224:null,p192:null,p25519:null};function P(A,h){this.name=A,this.p=new s(h,16),this.n=this.p.bitLength(),this.k=new s(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}P.prototype._tmp=function(){var h=new s(null);return h.words=new Array(Math.ceil(this.n/13)),h},P.prototype.ireduce=function(h){var p=h,m;do this.split(p,this.tmp),p=this.imulK(p),p=p.iadd(this.tmp),m=p.bitLength();while(m>this.n);var y=m<this.n?-1:p.ucmp(this.p);return y===0?(p.words[0]=0,p.length=1):y>0?p.isub(this.p):p.strip!==void 0?p.strip():p._strip(),p},P.prototype.split=function(h,p){h.iushrn(this.n,0,p)},P.prototype.imulK=function(h){return h.imul(this.k)};function T(){P.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}n(T,P),T.prototype.split=function(h,p){for(var m=4194303,y=Math.min(h.length,9),w=0;w<y;w++)p.words[w]=h.words[w];if(p.length=y,h.length<=9){h.words[0]=0,h.length=1;return}var S=h.words[9];for(p.words[p.length++]=S&m,w=10;w<h.length;w++){var $=h.words[w]|0;h.words[w-10]=($&m)<<4|S>>>22,S=$}S>>>=22,h.words[w-10]=S,S===0&&h.length>10?h.length-=10:h.length-=9},T.prototype.imulK=function(h){h.words[h.length]=0,h.words[h.length+1]=0,h.length+=2;for(var p=0,m=0;m<h.length;m++){var y=h.words[m]|0;p+=y*977,h.words[m]=p&67108863,p=y*64+(p/67108864|0)}return h.words[h.length-1]===0&&(h.length--,h.words[h.length-1]===0&&h.length--),h};function N(){P.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}n(N,P);function C(){P.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}n(C,P);function B(){P.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}n(B,P),B.prototype.imulK=function(h){for(var p=0,m=0;m<h.length;m++){var y=(h.words[m]|0)*19+p,w=y&67108863;y>>>=26,h.words[m]=w,p=y}return p!==0&&(h.words[h.length++]=p),h},s._prime=function(h){if(M[h])return M[h];var p;if(h==="k256")p=new T;else if(h==="p224")p=new N;else if(h==="p192")p=new C;else if(h==="p25519")p=new B;else throw new Error("Unknown prime "+h);return M[h]=p,p};function R(A){if(typeof A=="string"){var h=s._prime(A);this.m=h.p,this.prime=h}else i(A.gtn(1),"modulus must be greater than 1"),this.m=A,this.prime=null}R.prototype._verify1=function(h){i(h.negative===0,"red works only with positives"),i(h.red,"red works only with red numbers")},R.prototype._verify2=function(h,p){i((h.negative|p.negative)===0,"red works only with positives"),i(h.red&&h.red===p.red,"red works only with red numbers")},R.prototype.imod=function(h){return this.prime?this.prime.ireduce(h)._forceRed(this):h.umod(this.m)._forceRed(this)},R.prototype.neg=function(h){return h.isZero()?h.clone():this.m.sub(h)._forceRed(this)},R.prototype.add=function(h,p){this._verify2(h,p);var m=h.add(p);return m.cmp(this.m)>=0&&m.isub(this.m),m._forceRed(this)},R.prototype.iadd=function(h,p){this._verify2(h,p);var m=h.iadd(p);return m.cmp(this.m)>=0&&m.isub(this.m),m},R.prototype.sub=function(h,p){this._verify2(h,p);var m=h.sub(p);return m.cmpn(0)<0&&m.iadd(this.m),m._forceRed(this)},R.prototype.isub=function(h,p){this._verify2(h,p);var m=h.isub(p);return m.cmpn(0)<0&&m.iadd(this.m),m},R.prototype.shl=function(h,p){return this._verify1(h),this.imod(h.ushln(p))},R.prototype.imul=function(h,p){return this._verify2(h,p),this.imod(h.imul(p))},R.prototype.mul=function(h,p){return this._verify2(h,p),this.imod(h.mul(p))},R.prototype.isqr=function(h){return this.imul(h,h.clone())},R.prototype.sqr=function(h){return this.mul(h,h)},R.prototype.sqrt=function(h){if(h.isZero())return h.clone();var p=this.m.andln(3);if(i(p%2===1),p===3){var m=this.m.add(new s(1)).iushrn(2);return this.pow(h,m)}for(var y=this.m.subn(1),w=0;!y.isZero()&&y.andln(1)===0;)w++,y.iushrn(1);i(!y.isZero());var S=new s(1).toRed(this),$=S.redNeg(),_=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new s(2*l*l).toRed(this);this.pow(l,_).cmp($)!==0;)l.redIAdd($);for(var E=this.pow(l,y),F=this.pow(h,y.addn(1).iushrn(1)),L=this.pow(h,y),q=w;L.cmp(S)!==0;){for(var j=L,K=0;j.cmp(S)!==0;K++)j=j.redSqr();i(K<q);var W=this.pow(E,new s(1).iushln(q-K-1));F=F.redMul(W),E=W.redSqr(),L=L.redMul(E),q=K}return F},R.prototype.invm=function(h){var p=h._invmp(this.m);return p.negative!==0?(p.negative=0,this.imod(p).redNeg()):this.imod(p)},R.prototype.pow=function(h,p){if(p.isZero())return new s(1).toRed(this);if(p.cmpn(1)===0)return h.clone();var m=4,y=new Array(1<<m);y[0]=new s(1).toRed(this),y[1]=h;for(var w=2;w<y.length;w++)y[w]=this.mul(y[w-1],h);var S=y[0],$=0,_=0,l=p.bitLength()%26;for(l===0&&(l=26),w=p.length-1;w>=0;w--){for(var E=p.words[w],F=l-1;F>=0;F--){var L=E>>F&1;if(S!==y[0]&&(S=this.sqr(S)),L===0&&$===0){_=0;continue}$<<=1,$|=L,_++,!(_!==m&&(w!==0||F!==0))&&(S=this.mul(S,y[$]),_=0,$=0)}l=26}return S},R.prototype.convertTo=function(h){var p=h.umod(this.m);return p===h?p.clone():p},R.prototype.convertFrom=function(h){var p=h.clone();return p.red=null,p},s.mont=function(h){return new V(h)};function V(A){R.call(this,A),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new s(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(V,R),V.prototype.convertTo=function(h){return this.imod(h.ushln(this.shift))},V.prototype.convertFrom=function(h){var p=this.imod(h.mul(this.rinv));return p.red=null,p},V.prototype.imul=function(h,p){if(h.isZero()||p.isZero())return h.words[0]=0,h.length=1,h;var m=h.imul(p),y=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),w=m.isub(y).iushrn(this.shift),S=w;return w.cmp(this.m)>=0?S=w.isub(this.m):w.cmpn(0)<0&&(S=w.iadd(this.m)),S._forceRed(this)},V.prototype.mul=function(h,p){if(h.isZero()||p.isZero())return new s(0)._forceRed(this);var m=h.mul(p),y=m.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),w=m.isub(y).iushrn(this.shift),S=w;return w.cmp(this.m)>=0?S=w.isub(this.m):w.cmpn(0)<0&&(S=w.iadd(this.m)),S._forceRed(this)},V.prototype.invm=function(h){var p=this.imod(h._invmp(this.m).mul(this.r2));return p._forceRed(this)}})(t,Zt)})(hr);var mi=Qd;function Qd(t,e){if(!t)throw new Error(e||"Assertion failed")}Qd.equal=function(e,r,i){if(e!=r)throw new Error(i||"Assertion failed: "+e+" != "+r)};var nc={};(function(t){var e=t;function r(s,o){if(Array.isArray(s))return s.slice();if(!s)return[];var a=[];if(typeof s!="string"){for(var c=0;c<s.length;c++)a[c]=s[c]|0;return a}if(o==="hex"){s=s.replace(/[^a-z0-9]+/ig,""),s.length%2!==0&&(s="0"+s);for(var c=0;c<s.length;c+=2)a.push(parseInt(s[c]+s[c+1],16))}else for(var c=0;c<s.length;c++){var f=s.charCodeAt(c),u=f>>8,d=f&255;u?a.push(u,d):a.push(d)}return a}e.toArray=r;function i(s){return s.length===1?"0"+s:s}e.zero2=i;function n(s){for(var o="",a=0;a<s.length;a++)o+=i(s[a].toString(16));return o}e.toHex=n,e.encode=function(o,a){return a==="hex"?n(o):o}})(nc),function(t){var e=t,r=hr.exports,i=mi,n=nc;e.assert=i,e.toArray=n.toArray,e.zero2=n.zero2,e.toHex=n.toHex,e.encode=n.encode;function s(u,d,b){var v=new Array(Math.max(u.bitLength(),b)+1),g;for(g=0;g<v.length;g+=1)v[g]=0;var x=1<<d+1,I=u.clone();for(g=0;g<v.length;g++){var D,O=I.andln(x-1);I.isOdd()?(O>(x>>1)-1?D=(x>>1)-O:D=O,I.isubn(D)):D=0,v[g]=D,I.iushrn(1)}return v}e.getNAF=s;function o(u,d){var b=[[],[]];u=u.clone(),d=d.clone();for(var v=0,g=0,x;u.cmpn(-v)>0||d.cmpn(-g)>0;){var I=u.andln(3)+v&3,D=d.andln(3)+g&3;I===3&&(I=-1),D===3&&(D=-1);var O;I&1?(x=u.andln(7)+v&7,(x===3||x===5)&&D===2?O=-I:O=I):O=0,b[0].push(O);var M;D&1?(x=d.andln(7)+g&7,(x===3||x===5)&&I===2?M=-D:M=D):M=0,b[1].push(M),2*v===O+1&&(v=1-v),2*g===M+1&&(g=1-g),u.iushrn(1),d.iushrn(1)}return b}e.getJSF=o;function a(u,d,b){var v="_"+d;u.prototype[d]=function(){return this[v]!==void 0?this[v]:this[v]=b.call(this)}}e.cachedProperty=a;function c(u){return typeof u=="string"?e.toArray(u,"hex"):u}e.parseBytes=c;function f(u){return new r(u,"hex","le")}e.intFromLE=f}(Ft);var Qs={exports:{}},sc;Qs.exports=function(e){return sc||(sc=new Xr(null)),sc.generate(e)};function Xr(t){this.rand=t}if(Qs.exports.Rand=Xr,Xr.prototype.generate=function(e){return this._rand(e)},Xr.prototype._rand=function(e){if(this.rand.getBytes)return this.rand.getBytes(e);for(var r=new Uint8Array(e),i=0;i<r.length;i++)r[i]=this.rand.getByte();return r},typeof self=="object")self.crypto&&self.crypto.getRandomValues?Xr.prototype._rand=function(e){var r=new Uint8Array(e);return self.crypto.getRandomValues(r),r}:self.msCrypto&&self.msCrypto.getRandomValues?Xr.prototype._rand=function(e){var r=new Uint8Array(e);return self.msCrypto.getRandomValues(r),r}:typeof window=="object"&&(Xr.prototype._rand=function(){throw new Error("Not implemented yet")});else try{var el=Xd;if(typeof el.randomBytes!="function")throw new Error("Not supported");Xr.prototype._rand=function(e){return el.randomBytes(e)}}catch{}var oc={},wi=hr.exports,Un=Ft,eo=Un.getNAF,F6=Un.getJSF,to=Un.assert;function Qr(t,e){this.type=t,this.p=new wi(e.p,16),this.red=e.prime?wi.red(e.prime):wi.mont(this.p),this.zero=new wi(0).toRed(this.red),this.one=new wi(1).toRed(this.red),this.two=new wi(2).toRed(this.red),this.n=e.n&&new wi(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 r=this.n&&this.p.div(this.n);!r||r.cmpn(100)>0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red))}var ro=Qr;Qr.prototype.point=function(){throw new Error("Not implemented")},Qr.prototype.validate=function(){throw new Error("Not implemented")},Qr.prototype._fixedNafMul=function(e,r){to(e.precomputed);var i=e._getDoubles(),n=eo(r,1,this._bitLength),s=(1<<i.step+1)-(i.step%2===0?2:1);s/=3;var o=[],a,c;for(a=0;a<n.length;a+=i.step){c=0;for(var f=a+i.step-1;f>=a;f--)c=(c<<1)+n[f];o.push(c)}for(var u=this.jpoint(null,null,null),d=this.jpoint(null,null,null),b=s;b>0;b--){for(a=0;a<o.length;a++)c=o[a],c===b?d=d.mixedAdd(i.points[a]):c===-b&&(d=d.mixedAdd(i.points[a].neg()));u=u.add(d)}return u.toP()},Qr.prototype._wnafMul=function(e,r){var i=4,n=e._getNAFPoints(i);i=n.wnd;for(var s=n.points,o=eo(r,i,this._bitLength),a=this.jpoint(null,null,null),c=o.length-1;c>=0;c--){for(var f=0;c>=0&&o[c]===0;c--)f++;if(c>=0&&f++,a=a.dblp(f),c<0)break;var u=o[c];to(u!==0),e.type==="affine"?u>0?a=a.mixedAdd(s[u-1>>1]):a=a.mixedAdd(s[-u-1>>1].neg()):u>0?a=a.add(s[u-1>>1]):a=a.add(s[-u-1>>1].neg())}return e.type==="affine"?a.toP():a},Qr.prototype._wnafMulAdd=function(e,r,i,n,s){var o=this._wnafT1,a=this._wnafT2,c=this._wnafT3,f=0,u,d,b;for(u=0;u<n;u++){b=r[u];var v=b._getNAFPoints(e);o[u]=v.wnd,a[u]=v.points}for(u=n-1;u>=1;u-=2){var g=u-1,x=u;if(o[g]!==1||o[x]!==1){c[g]=eo(i[g],o[g],this._bitLength),c[x]=eo(i[x],o[x],this._bitLength),f=Math.max(c[g].length,f),f=Math.max(c[x].length,f);continue}var I=[r[g],null,null,r[x]];r[g].y.cmp(r[x].y)===0?(I[1]=r[g].add(r[x]),I[2]=r[g].toJ().mixedAdd(r[x].neg())):r[g].y.cmp(r[x].y.redNeg())===0?(I[1]=r[g].toJ().mixedAdd(r[x]),I[2]=r[g].add(r[x].neg())):(I[1]=r[g].toJ().mixedAdd(r[x]),I[2]=r[g].toJ().mixedAdd(r[x].neg()));var D=[-3,-1,-5,-7,0,7,5,1,3],O=F6(i[g],i[x]);for(f=Math.max(O[0].length,f),c[g]=new Array(f),c[x]=new Array(f),d=0;d<f;d++){var M=O[0][d]|0,P=O[1][d]|0;c[g][d]=D[(M+1)*3+(P+1)],c[x][d]=0,a[g]=I}}var T=this.jpoint(null,null,null),N=this._wnafT4;for(u=f;u>=0;u--){for(var C=0;u>=0;){var B=!0;for(d=0;d<n;d++)N[d]=c[d][u]|0,N[d]!==0&&(B=!1);if(!B)break;C++,u--}if(u>=0&&C++,T=T.dblp(C),u<0)break;for(d=0;d<n;d++){var R=N[d];R!==0&&(R>0?b=a[d][R-1>>1]:R<0&&(b=a[d][-R-1>>1].neg()),b.type==="affine"?T=T.mixedAdd(b):T=T.add(b))}}for(u=0;u<n;u++)a[u]=null;return s?T:T.toP()};function Vt(t,e){this.curve=t,this.type=e,this.precomputed=null}Qr.BasePoint=Vt,Vt.prototype.eq=function(){throw new Error("Not implemented")},Vt.prototype.validate=function(){return this.curve.validate(this)},Qr.prototype.decodePoint=function(e,r){e=Un.toArray(e,r);var i=this.p.byteLength();if((e[0]===4||e[0]===6||e[0]===7)&&e.length-1===2*i){e[0]===6?to(e[e.length-1]%2===0):e[0]===7&&to(e[e.length-1]%2===1);var n=this.point(e.slice(1,1+i),e.slice(1+i,1+2*i));return n}else if((e[0]===2||e[0]===3)&&e.length-1===i)return this.pointFromX(e.slice(1,1+i),e[0]===3);throw new Error("Unknown point format")},Vt.prototype.encodeCompressed=function(e){return this.encode(e,!0)},Vt.prototype._encode=function(e){var r=this.curve.p.byteLength(),i=this.getX().toArray("be",r);return e?[this.getY().isEven()?2:3].concat(i):[4].concat(i,this.getY().toArray("be",r))},Vt.prototype.encode=function(e,r){return Un.encode(this._encode(r),e)},Vt.prototype.precompute=function(e){if(this.precomputed)return this;var r={doubles:null,naf:null,beta:null};return r.naf=this._getNAFPoints(8),r.doubles=this._getDoubles(4,e),r.beta=this._getBeta(),this.precomputed=r,this},Vt.prototype._hasDoubles=function(e){if(!this.precomputed)return!1;var r=this.precomputed.doubles;return r?r.points.length>=Math.ceil((e.bitLength()+1)/r.step):!1},Vt.prototype._getDoubles=function(e,r){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var i=[this],n=this,s=0;s<r;s+=e){for(var o=0;o<e;o++)n=n.dbl();i.push(n)}return{step:e,points:i}},Vt.prototype._getNAFPoints=function(e){if(this.precomputed&&this.precomputed.naf)return this.precomputed.naf;for(var r=[this],i=(1<<e)-1,n=i===1?null:this.dbl(),s=1;s<i;s++)r[s]=r[s-1].add(n);return{wnd:e,points:r}},Vt.prototype._getBeta=function(){return null},Vt.prototype.dblp=function(e){for(var r=this,i=0;i<e;i++)r=r.dbl();return r};var tn={exports:{}};typeof Object.create=="function"?tn.exports=function(e,r){r&&(e.super_=r,e.prototype=Object.create(r.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:tn.exports=function(e,r){if(r){e.super_=r;var i=function(){};i.prototype=r.prototype,e.prototype=new i,e.prototype.constructor=e}};var L6=Ft,we=hr.exports,ac=tn.exports,rn=ro,q6=L6.assert;function Kt(t){rn.call(this,"short",t),this.a=new we(t.a,16).toRed(this.red),this.b=new we(t.b,16).toRed(this.red),this.tinv=this.two.redInvm(),this.zeroA=this.a.fromRed().cmpn(0)===0,this.threeA=this.a.fromRed().sub(this.p).cmpn(-3)===0,this.endo=this._getEndomorphism(t),this._endoWnafT1=new Array(4),this._endoWnafT2=new Array(4)}ac(Kt,rn);var k6=Kt;Kt.prototype._getEndomorphism=function(e){if(!(!this.zeroA||!this.g||!this.n||this.p.modn(3)!==1)){var r,i;if(e.beta)r=new we(e.beta,16).toRed(this.red);else{var n=this._getEndoRoots(this.p);r=n[0].cmp(n[1])<0?n[0]:n[1],r=r.toRed(this.red)}if(e.lambda)i=new we(e.lambda,16);else{var s=this._getEndoRoots(this.n);this.g.mul(s[0]).x.cmp(this.g.x.redMul(r))===0?i=s[0]:(i=s[1],q6(this.g.mul(i).x.cmp(this.g.x.redMul(r))===0))}var o;return e.basis?o=e.basis.map(function(a){return{a:new we(a.a,16),b:new we(a.b,16)}}):o=this._getEndoBasis(i),{beta:r,lambda:i,basis:o}}},Kt.prototype._getEndoRoots=function(e){var r=e===this.p?this.red:we.mont(e),i=new we(2).toRed(r).redInvm(),n=i.redNeg(),s=new we(3).toRed(r).redNeg().redSqrt().redMul(i),o=n.redAdd(s).fromRed(),a=n.redSub(s).fromRed();return[o,a]},Kt.prototype._getEndoBasis=function(e){for(var r=this.n.ushrn(Math.floor(this.n.bitLength()/2)),i=e,n=this.n.clone(),s=new we(1),o=new we(0),a=new we(0),c=new we(1),f,u,d,b,v,g,x,I=0,D,O;i.cmpn(0)!==0;){var M=n.div(i);D=n.sub(M.mul(i)),O=a.sub(M.mul(s));var P=c.sub(M.mul(o));if(!d&&D.cmp(r)<0)f=x.neg(),u=s,d=D.neg(),b=O;else if(d&&++I===2)break;x=D,n=i,i=D,a=s,s=O,c=o,o=P}v=D.neg(),g=O;var T=d.sqr().add(b.sqr()),N=v.sqr().add(g.sqr());return N.cmp(T)>=0&&(v=f,g=u),d.negative&&(d=d.neg(),b=b.neg()),v.negative&&(v=v.neg(),g=g.neg()),[{a:d,b},{a:v,b:g}]},Kt.prototype._endoSplit=function(e){var r=this.endo.basis,i=r[0],n=r[1],s=n.b.mul(e).divRound(this.n),o=i.b.neg().mul(e).divRound(this.n),a=s.mul(i.a),c=o.mul(n.a),f=s.mul(i.b),u=o.mul(n.b),d=e.sub(a).sub(c),b=f.add(u).neg();return{k1:d,k2:b}},Kt.prototype.pointFromX=function(e,r){e=new we(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 s=n.fromRed().isOdd();return(r&&!s||!r&&s)&&(n=n.redNeg()),this.point(e,n)},Kt.prototype.validate=function(e){if(e.inf)return!0;var r=e.x,i=e.y,n=this.a.redMul(r),s=r.redSqr().redMul(r).redIAdd(n).redIAdd(this.b);return i.redSqr().redISub(s).cmpn(0)===0},Kt.prototype._endoWnafMulAdd=function(e,r,i){for(var n=this._endoWnafT1,s=this._endoWnafT2,o=0;o<e.length;o++){var a=this._endoSplit(r[o]),c=e[o],f=c._getBeta();a.k1.negative&&(a.k1.ineg(),c=c.neg(!0)),a.k2.negative&&(a.k2.ineg(),f=f.neg(!0)),n[o*2]=c,n[o*2+1]=f,s[o*2]=a.k1,s[o*2+1]=a.k2}for(var u=this._wnafMulAdd(1,n,s,o*2,i),d=0;d<o*2;d++)n[d]=null,s[d]=null;return u};function nt(t,e,r,i){rn.BasePoint.call(this,t,"affine"),e===null&&r===null?(this.x=null,this.y=null,this.inf=!0):(this.x=new we(e,16),this.y=new we(r,16),i&&(this.x.forceRed(this.curve.red),this.y.forceRed(this.curve.red)),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.inf=!1)}ac(nt,rn.BasePoint),Kt.prototype.point=function(e,r,i){return new nt(this,e,r,i)},Kt.prototype.pointFromJSON=function(e,r){return nt.fromJSON(this,e,r)},nt.prototype._getBeta=function(){if(this.curve.endo){var e=this.precomputed;if(e&&e.beta)return e.beta;var r=this.curve.point(this.x.redMul(this.curve.endo.beta),this.y);if(e){var i=this.curve,n=function(s){return i.point(s.x.redMul(i.endo.beta),s.y)};e.beta=r,r.precomputed={beta:null,naf:e.naf&&{wnd:e.naf.wnd,points:e.naf.points.map(n)},doubles:e.doubles&&{step:e.doubles.step,points:e.doubles.points.map(n)}}}return r}},nt.prototype.toJSON=function(){return this.precomputed?[this.x,this.y,this.precomputed&&{doubles:this.precomputed.doubles&&{step:this.precomputed.doubles.step,points:this.precomputed.doubles.points.slice(1)},naf:this.precomputed.naf&&{wnd:this.precomputed.naf.wnd,points:this.precomputed.naf.points.slice(1)}}]:[this.x,this.y]},nt.fromJSON=function(e,r,i){typeof r=="string"&&(r=JSON.parse(r));var n=e.point(r[0],r[1],i);if(!r[2])return n;function s(a){return e.point(a[0],a[1],i)}var o=r[2];return n.precomputed={beta:null,doubles:o.doubles&&{step:o.doubles.step,points:[n].concat(o.doubles.points.map(s))},naf:o.naf&&{wnd:o.naf.wnd,points:[n].concat(o.naf.points.map(s))}},n},nt.prototype.inspect=function(){return this.isInfinity()?"<EC Point Infinity>":"<EC Point x: "+this.x.fromRed().toString(16,2)+" y: "+this.y.fromRed().toString(16,2)+">"},nt.prototype.isInfinity=function(){return this.inf},nt.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 r=this.y.redSub(e.y);r.cmpn(0)!==0&&(r=r.redMul(this.x.redSub(e.x).redInvm()));var i=r.redSqr().redISub(this.x).redISub(e.x),n=r.redMul(this.x.redSub(i)).redISub(this.y);return this.curve.point(i,n)},nt.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 r=this.curve.a,i=this.x.redSqr(),n=e.redInvm(),s=i.redAdd(i).redIAdd(i).redIAdd(r).redMul(n),o=s.redSqr().redISub(this.x.redAdd(this.x)),a=s.redMul(this.x.redSub(o)).redISub(this.y);return this.curve.point(o,a)},nt.prototype.getX=function(){return this.x.fromRed()},nt.prototype.getY=function(){return this.y.fromRed()},nt.prototype.mul=function(e){return e=new we(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)},nt.prototype.mulAdd=function(e,r,i){var n=[this,r],s=[e,i];return this.curve.endo?this.curve._endoWnafMulAdd(n,s):this.curve._wnafMulAdd(1,n,s,2)},nt.prototype.jmulAdd=function(e,r,i){var n=[this,r],s=[e,i];return this.curve.endo?this.curve._endoWnafMulAdd(n,s,!0):this.curve._wnafMulAdd(1,n,s,2,!0)},nt.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)},nt.prototype.neg=function(e){if(this.inf)return this;var r=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var i=this.precomputed,n=function(s){return s.neg()};r.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 r},nt.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 dt(t,e,r,i){rn.BasePoint.call(this,t,"jacobian"),e===null&&r===null&&i===null?(this.x=this.curve.one,this.y=this.curve.one,this.z=new we(0)):(this.x=new we(e,16),this.y=new we(r,16),this.z=new we(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}ac(dt,rn.BasePoint),Kt.prototype.jpoint=function(e,r,i){return new dt(this,e,r,i)},dt.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),r=e.redSqr(),i=this.x.redMul(r),n=this.y.redMul(r).redMul(e);return this.curve.point(i,n)},dt.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},dt.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var r=e.z.redSqr(),i=this.z.redSqr(),n=this.x.redMul(r),s=e.x.redMul(i),o=this.y.redMul(r.redMul(e.z)),a=e.y.redMul(i.redMul(this.z)),c=n.redSub(s),f=o.redSub(a);if(c.cmpn(0)===0)return f.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var u=c.redSqr(),d=u.redMul(c),b=n.redMul(u),v=f.redSqr().redIAdd(d).redISub(b).redISub(b),g=f.redMul(b.redISub(v)).redISub(o.redMul(d)),x=this.z.redMul(e.z).redMul(c);return this.curve.jpoint(v,g,x)},dt.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var r=this.z.redSqr(),i=this.x,n=e.x.redMul(r),s=this.y,o=e.y.redMul(r).redMul(this.z),a=i.redSub(n),c=s.redSub(o);if(a.cmpn(0)===0)return c.cmpn(0)!==0?this.curve.jpoint(null,null,null):this.dbl();var f=a.redSqr(),u=f.redMul(a),d=i.redMul(f),b=c.redSqr().redIAdd(u).redISub(d).redISub(d),v=c.redMul(d.redISub(b)).redISub(s.redMul(u)),g=this.z.redMul(a);return this.curve.jpoint(b,v,g)},dt.prototype.dblp=function(e){if(e===0)return this;if(this.isInfinity())return this;if(!e)return this.dbl();var r;if(this.curve.zeroA||this.curve.threeA){var i=this;for(r=0;r<e;r++)i=i.dbl();return i}var n=this.curve.a,s=this.curve.tinv,o=this.x,a=this.y,c=this.z,f=c.redSqr().redSqr(),u=a.redAdd(a);for(r=0;r<e;r++){var d=o.redSqr(),b=u.redSqr(),v=b.redSqr(),g=d.redAdd(d).redIAdd(d).redIAdd(n.redMul(f)),x=o.redMul(b),I=g.redSqr().redISub(x.redAdd(x)),D=x.redISub(I),O=g.redMul(D);O=O.redIAdd(O).redISub(v);var M=u.redMul(c);r+1<e&&(f=f.redMul(v)),o=I,c=M,u=O}return this.curve.jpoint(o,u.redMul(s),c)},dt.prototype.dbl=function(){return this.isInfinity()?this:this.curve.zeroA?this._zeroDbl():this.curve.threeA?this._threeDbl():this._dbl()},dt.prototype._zeroDbl=function(){var e,r,i;if(this.zOne){var n=this.x.redSqr(),s=this.y.redSqr(),o=s.redSqr(),a=this.x.redAdd(s).redSqr().redISub(n).redISub(o);a=a.redIAdd(a);var c=n.redAdd(n).redIAdd(n),f=c.redSqr().redISub(a).redISub(a),u=o.redIAdd(o);u=u.redIAdd(u),u=u.redIAdd(u),e=f,r=c.redMul(a.redISub(f)).redISub(u),i=this.y.redAdd(this.y)}else{var d=this.x.redSqr(),b=this.y.redSqr(),v=b.redSqr(),g=this.x.redAdd(b).redSqr().redISub(d).redISub(v);g=g.redIAdd(g);var x=d.redAdd(d).redIAdd(d),I=x.redSqr(),D=v.redIAdd(v);D=D.redIAdd(D),D=D.redIAdd(D),e=I.redISub(g).redISub(g),r=x.redMul(g.redISub(e)).redISub(D),i=this.y.redMul(this.z),i=i.redIAdd(i)}return this.curve.jpoint(e,r,i)},dt.prototype._threeDbl=function(){var e,r,i;if(this.zOne){var n=this.x.redSqr(),s=this.y.redSqr(),o=s.redSqr(),a=this.x.redAdd(s).redSqr().redISub(n).redISub(o);a=a.redIAdd(a);var c=n.redAdd(n).redIAdd(n).redIAdd(this.curve.a),f=c.redSqr().redISub(a).redISub(a);e=f;var u=o.redIAdd(o);u=u.redIAdd(u),u=u.redIAdd(u),r=c.redMul(a.redISub(f)).redISub(u),i=this.y.redAdd(this.y)}else{var d=this.z.redSqr(),b=this.y.redSqr(),v=this.x.redMul(b),g=this.x.redSub(d).redMul(this.x.redAdd(d));g=g.redAdd(g).redIAdd(g);var x=v.redIAdd(v);x=x.redIAdd(x);var I=x.redAdd(x);e=g.redSqr().redISub(I),i=this.y.redAdd(this.z).redSqr().redISub(b).redISub(d);var D=b.redSqr();D=D.redIAdd(D),D=D.redIAdd(D),D=D.redIAdd(D),r=g.redMul(x.redISub(e)).redISub(D)}return this.curve.jpoint(e,r,i)},dt.prototype._dbl=function(){var e=this.curve.a,r=this.x,i=this.y,n=this.z,s=n.redSqr().redSqr(),o=r.redSqr(),a=i.redSqr(),c=o.redAdd(o).redIAdd(o).redIAdd(e.redMul(s)),f=r.redAdd(r);f=f.redIAdd(f);var u=f.redMul(a),d=c.redSqr().redISub(u.redAdd(u)),b=u.redISub(d),v=a.redSqr();v=v.redIAdd(v),v=v.redIAdd(v),v=v.redIAdd(v);var g=c.redMul(b).redISub(v),x=i.redAdd(i).redMul(n);return this.curve.jpoint(d,g,x)},dt.prototype.trpl=function(){if(!this.curve.zeroA)return this.dbl().add(this);var e=this.x.redSqr(),r=this.y.redSqr(),i=this.z.redSqr(),n=r.redSqr(),s=e.redAdd(e).redIAdd(e),o=s.redSqr(),a=this.x.redAdd(r).redSqr().redISub(e).redISub(n);a=a.redIAdd(a),a=a.redAdd(a).redIAdd(a),a=a.redISub(o);var c=a.redSqr(),f=n.redIAdd(n);f=f.redIAdd(f),f=f.redIAdd(f),f=f.redIAdd(f);var u=s.redIAdd(a).redSqr().redISub(o).redISub(c).redISub(f),d=r.redMul(u);d=d.redIAdd(d),d=d.redIAdd(d);var b=this.x.redMul(c).redISub(d);b=b.redIAdd(b),b=b.redIAdd(b);var v=this.y.redMul(u.redMul(f.redISub(u)).redISub(a.redMul(c)));v=v.redIAdd(v),v=v.redIAdd(v),v=v.redIAdd(v);var g=this.z.redAdd(a).redSqr().redISub(i).redISub(c);return this.curve.jpoint(b,v,g)},dt.prototype.mul=function(e,r){return e=new we(e,r),this.curve._wnafMul(this,e)},dt.prototype.eq=function(e){if(e.type==="affine")return this.eq(e.toJ());if(this===e)return!0;var r=this.z.redSqr(),i=e.z.redSqr();if(this.x.redMul(i).redISub(e.x.redMul(r)).cmpn(0)!==0)return!1;var n=r.redMul(this.z),s=i.redMul(e.z);return this.y.redMul(s).redISub(e.y.redMul(n)).cmpn(0)===0},dt.prototype.eqXToP=function(e){var r=this.z.redSqr(),i=e.toRed(this.curve.red).redMul(r);if(this.x.cmp(i)===0)return!0;for(var n=e.clone(),s=this.curve.redN.redMul(r);;){if(n.iadd(this.curve.n),n.cmp(this.curve.p)>=0)return!1;if(i.redIAdd(s),this.x.cmp(i)===0)return!0}},dt.prototype.inspect=function(){return this.isInfinity()?"<EC JPoint Infinity>":"<EC JPoint x: "+this.x.toString(16,2)+" y: "+this.y.toString(16,2)+" z: "+this.z.toString(16,2)+">"},dt.prototype.isInfinity=function(){return this.z.cmpn(0)===0};var nn=hr.exports,tl=tn.exports,io=ro,z6=Ft;function sn(t){io.call(this,"mont",t),this.a=new nn(t.a,16).toRed(this.red),this.b=new nn(t.b,16).toRed(this.red),this.i4=new nn(4).toRed(this.red).redInvm(),this.two=new nn(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two))}tl(sn,io);var U6=sn;sn.prototype.validate=function(e){var r=e.normalize().x,i=r.redSqr(),n=i.redMul(r).redAdd(i.redMul(this.a)).redAdd(r),s=n.redSqrt();return s.redSqr().cmp(n)===0};function st(t,e,r){io.BasePoint.call(this,t,"projective"),e===null&&r===null?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new nn(e,16),this.z=new nn(r,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)))}tl(st,io.BasePoint),sn.prototype.decodePoint=function(e,r){return this.point(z6.toArray(e,r),1)},sn.prototype.point=function(e,r){return new st(this,e,r)},sn.prototype.pointFromJSON=function(e){return st.fromJSON(this,e)},st.prototype.precompute=function(){},st.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},st.fromJSON=function(e,r){return new st(e,r[0],r[1]||e.one)},st.prototype.inspect=function(){return this.isInfinity()?"<EC Point Infinity>":"<EC Point x: "+this.x.fromRed().toString(16,2)+" z: "+this.z.fromRed().toString(16,2)+">"},st.prototype.isInfinity=function(){return this.z.cmpn(0)===0},st.prototype.dbl=function(){var e=this.x.redAdd(this.z),r=e.redSqr(),i=this.x.redSub(this.z),n=i.redSqr(),s=r.redSub(n),o=r.redMul(n),a=s.redMul(n.redAdd(this.curve.a24.redMul(s)));return this.curve.point(o,a)},st.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},st.prototype.diffAdd=function(e,r){var i=this.x.redAdd(this.z),n=this.x.redSub(this.z),s=e.x.redAdd(e.z),o=e.x.redSub(e.z),a=o.redMul(i),c=s.redMul(n),f=r.z.redMul(a.redAdd(c).redSqr()),u=r.x.redMul(a.redISub(c).redSqr());return this.curve.point(f,u)},st.prototype.mul=function(e){for(var r=e.clone(),i=this,n=this.curve.point(null,null),s=this,o=[];r.cmpn(0)!==0;r.iushrn(1))o.push(r.andln(1));for(var a=o.length-1;a>=0;a--)o[a]===0?(i=i.diffAdd(n,s),n=n.dbl()):(n=i.diffAdd(n,s),i=i.dbl());return n},st.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")},st.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")},st.prototype.eq=function(e){return this.getX().cmp(e.getX())===0},st.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},st.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var j6=Ft,Cr=hr.exports,rl=tn.exports,no=ro,V6=j6.assert;function dr(t){this.twisted=(t.a|0)!==1,this.mOneA=this.twisted&&(t.a|0)===-1,this.extended=this.mOneA,no.call(this,"edwards",t),this.a=new Cr(t.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new Cr(t.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new Cr(t.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),V6(!this.twisted||this.c.fromRed().cmpn(1)===0),this.oneC=(t.c|0)===1}rl(dr,no);var K6=dr;dr.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)},dr.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)},dr.prototype.jpoint=function(e,r,i,n){return this.point(e,r,i,n)},dr.prototype.pointFromX=function(e,r){e=new Cr(e,16),e.red||(e=e.toRed(this.red));var i=e.redSqr(),n=this.c2.redSub(this.a.redMul(i)),s=this.one.redSub(this.c2.redMul(this.d).redMul(i)),o=n.redMul(s.redInvm()),a=o.redSqrt();if(a.redSqr().redSub(o).cmp(this.zero)!==0)throw new Error("invalid point");var c=a.fromRed().isOdd();return(r&&!c||!r&&c)&&(a=a.redNeg()),this.point(e,a)},dr.prototype.pointFromY=function(e,r){e=new Cr(e,16),e.red||(e=e.toRed(this.red));var i=e.redSqr(),n=i.redSub(this.c2),s=i.redMul(this.d).redMul(this.c2).redSub(this.a),o=n.redMul(s.redInvm());if(o.cmp(this.zero)===0){if(r)throw new Error("invalid point");return this.point(this.zero,e)}var a=o.redSqrt();if(a.redSqr().redSub(o).cmp(this.zero)!==0)throw new Error("invalid point");return a.fromRed().isOdd()!==r&&(a=a.redNeg()),this.point(a,e)},dr.prototype.validate=function(e){if(e.isInfinity())return!0;e.normalize();var r=e.x.redSqr(),i=e.y.redSqr(),n=r.redMul(this.a).redAdd(i),s=this.c2.redMul(this.one.redAdd(this.d.redMul(r).redMul(i)));return n.cmp(s)===0};function he(t,e,r,i,n){no.BasePoint.call(this,t,"projective"),e===null&&r===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 Cr(e,16),this.y=new Cr(r,16),this.z=i?new Cr(i,16):this.curve.one,this.t=n&&new Cr(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()))))}rl(he,no.BasePoint),dr.prototype.pointFromJSON=function(e){return he.fromJSON(this,e)},dr.prototype.point=function(e,r,i,n){return new he(this,e,r,i,n)},he.fromJSON=function(e,r){return new he(e,r[0],r[1],r[2])},he.prototype.inspect=function(){return this.isInfinity()?"<EC Point Infinity>":"<EC Point x: "+this.x.fromRed().toString(16,2)+" y: "+this.y.fromRed().toString(16,2)+" z: "+this.z.fromRed().toString(16,2)+">"},he.prototype.isInfinity=function(){return this.x.cmpn(0)===0&&(this.y.cmp(this.z)===0||this.zOne&&this.y.cmp(this.curve.c)===0)},he.prototype._extDbl=function(){var e=this.x.redSqr(),r=this.y.redSqr(),i=this.z.redSqr();i=i.redIAdd(i);var n=this.curve._mulA(e),s=this.x.redAdd(this.y).redSqr().redISub(e).redISub(r),o=n.redAdd(r),a=o.redSub(i),c=n.redSub(r),f=s.redMul(a),u=o.redMul(c),d=s.redMul(c),b=a.redMul(o);return this.curve.point(f,u,b,d)},he.prototype._projDbl=function(){var e=this.x.redAdd(this.y).redSqr(),r=this.x.redSqr(),i=this.y.redSqr(),n,s,o,a,c,f;if(this.curve.twisted){a=this.curve._mulA(r);var u=a.redAdd(i);this.zOne?(n=e.redSub(r).redSub(i).redMul(u.redSub(this.curve.two)),s=u.redMul(a.redSub(i)),o=u.redSqr().redSub(u).redSub(u)):(c=this.z.redSqr(),f=u.redSub(c).redISub(c),n=e.redSub(r).redISub(i).redMul(f),s=u.redMul(a.redSub(i)),o=u.redMul(f))}else a=r.redAdd(i),c=this.curve._mulC(this.z).redSqr(),f=a.redSub(c).redSub(c),n=this.curve._mulC(e.redISub(a)).redMul(f),s=this.curve._mulC(a).redMul(r.redISub(i)),o=a.redMul(f);return this.curve.point(n,s,o)},he.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},he.prototype._extAdd=function(e){var r=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),s=this.z.redMul(e.z.redAdd(e.z)),o=i.redSub(r),a=s.redSub(n),c=s.redAdd(n),f=i.redAdd(r),u=o.redMul(a),d=c.redMul(f),b=o.redMul(f),v=a.redMul(c);return this.curve.point(u,d,v,b)},he.prototype._projAdd=function(e){var r=this.z.redMul(e.z),i=r.redSqr(),n=this.x.redMul(e.x),s=this.y.redMul(e.y),o=this.curve.d.redMul(n).redMul(s),a=i.redSub(o),c=i.redAdd(o),f=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(n).redISub(s),u=r.redMul(a).redMul(f),d,b;return this.curve.twisted?(d=r.redMul(c).redMul(s.redSub(this.curve._mulA(n))),b=a.redMul(c)):(d=r.redMul(c).redMul(s.redSub(n)),b=this.curve._mulC(a).redMul(c)),this.curve.point(u,d,b)},he.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},he.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},he.prototype.mulAdd=function(e,r,i){return this.curve._wnafMulAdd(1,[this,r],[e,i],2,!1)},he.prototype.jmulAdd=function(e,r,i){return this.curve._wnafMulAdd(1,[this,r],[e,i],2,!0)},he.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},he.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},he.prototype.getX=function(){return this.normalize(),this.x.fromRed()},he.prototype.getY=function(){return this.normalize(),this.y.fromRed()},he.prototype.eq=function(e){return this===e||this.getX().cmp(e.getX())===0&&this.getY().cmp(e.getY())===0},he.prototype.eqXToP=function(e){var r=e.toRed(this.curve.red).redMul(this.z);if(this.x.cmp(r)===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(r.redIAdd(n),this.x.cmp(r)===0)return!0}},he.prototype.toP=he.prototype.normalize,he.prototype.mixedAdd=he.prototype.add,function(t){var e=t;e.base=ro,e.short=k6,e.mont=U6,e.edwards=K6}(oc);var so={},oo={},J={},H6=mi,W6=tn.exports;J.inherits=W6;function G6(t,e){return(t.charCodeAt(e)&64512)!==55296||e<0||e+1>=t.length?!1:(t.charCodeAt(e+1)&64512)===56320}function Y6(t,e){if(Array.isArray(t))return t.slice();if(!t)return[];var r=[];if(typeof t=="string")if(e){if(e==="hex")for(t=t.replace(/[^a-z0-9]+/ig,""),t.length%2!==0&&(t="0"+t),n=0;n<t.length;n+=2)r.push(parseInt(t[n]+t[n+1],16))}else for(var i=0,n=0;n<t.length;n++){var s=t.charCodeAt(n);s<128?r[i++]=s:s<2048?(r[i++]=s>>6|192,r[i++]=s&63|128):G6(t,n)?(s=65536+((s&1023)<<10)+(t.charCodeAt(++n)&1023),r[i++]=s>>18|240,r[i++]=s>>12&63|128,r[i++]=s>>6&63|128,r[i++]=s&63|128):(r[i++]=s>>12|224,r[i++]=s>>6&63|128,r[i++]=s&63|128)}else for(n=0;n<t.length;n++)r[n]=t[n]|0;return r}J.toArray=Y6;function Z6(t){for(var e="",r=0;r<t.length;r++)e+=nl(t[r].toString(16));return e}J.toHex=Z6;function il(t){var e=t>>>24|t>>>8&65280|t<<8&16711680|(t&255)<<24;return e>>>0}J.htonl=il;function J6(t,e){for(var r="",i=0;i<t.length;i++){var n=t[i];e==="little"&&(n=il(n)),r+=sl(n.toString(16))}return r}J.toHex32=J6;function nl(t){return t.length===1?"0"+t:t}J.zero2=nl;function sl(t){return t.length===7?"0"+t:t.length===6?"00"+t:t.length===5?"000"+t:t.length===4?"0000"+t:t.length===3?"00000"+t:t.length===2?"000000"+t:t.length===1?"0000000"+t:t}J.zero8=sl;function X6(t,e,r,i){var n=r-e;H6(n%4===0);for(var s=new Array(n/4),o=0,a=e;o<s.length;o++,a+=4){var c;i==="big"?c=t[a]<<24|t[a+1]<<16|t[a+2]<<8|t[a+3]:c=t[a+3]<<24|t[a+2]<<16|t[a+1]<<8|t[a],s[o]=c>>>0}return s}J.join32=X6;function Q6(t,e){for(var r=new Array(t.length*4),i=0,n=0;i<t.length;i++,n+=4){var s=t[i];e==="big"?(r[n]=s>>>24,r[n+1]=s>>>16&255,r[n+2]=s>>>8&255,r[n+3]=s&255):(r[n+3]=s>>>24,r[n+2]=s>>>16&255,r[n+1]=s>>>8&255,r[n]=s&255)}return r}J.split32=Q6;function e8(t,e){return t>>>e|t<<32-e}J.rotr32=e8;function t8(t,e){return t<<e|t>>>32-e}J.rotl32=t8;function r8(t,e){return t+e>>>0}J.sum32=r8;function i8(t,e,r){return t+e+r>>>0}J.sum32_3=i8;function n8(t,e,r,i){return t+e+r+i>>>0}J.sum32_4=n8;function s8(t,e,r,i,n){return t+e+r+i+n>>>0}J.sum32_5=s8;function o8(t,e,r,i){var n=t[e],s=t[e+1],o=i+s>>>0,a=(o<i?1:0)+r+n;t[e]=a>>>0,t[e+1]=o}J.sum64=o8;function a8(t,e,r,i){var n=e+i>>>0,s=(n<e?1:0)+t+r;return s>>>0}J.sum64_hi=a8;function c8(t,e,r,i){var n=e+i;return n>>>0}J.sum64_lo=c8;function f8(t,e,r,i,n,s,o,a){var c=0,f=e;f=f+i>>>0,c+=f<e?1:0,f=f+s>>>0,c+=f<s?1:0,f=f+a>>>0,c+=f<a?1:0;var u=t+r+n+o+c;return u>>>0}J.sum64_4_hi=f8;function u8(t,e,r,i,n,s,o,a){var c=e+i+s+a;return c>>>0}J.sum64_4_lo=u8;function h8(t,e,r,i,n,s,o,a,c,f){var u=0,d=e;d=d+i>>>0,u+=d<e?1:0,d=d+s>>>0,u+=d<s?1:0,d=d+a>>>0,u+=d<a?1:0,d=d+f>>>0,u+=d<f?1:0;var b=t+r+n+o+c+u;return b>>>0}J.sum64_5_hi=h8;function d8(t,e,r,i,n,s,o,a,c,f){var u=e+i+s+a+f;return u>>>0}J.sum64_5_lo=d8;function l8(t,e,r){var i=e<<32-r|t>>>r;return i>>>0}J.rotr64_hi=l8;function p8(t,e,r){var i=t<<32-r|e>>>r;return i>>>0}J.rotr64_lo=p8;function b8(t,e,r){return t>>>r}J.shr64_hi=b8;function g8(t,e,r){var i=t<<32-r|e>>>r;return i>>>0}J.shr64_lo=g8;var on={},ol=J,y8=mi;function ao(){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}on.BlockHash=ao,ao.prototype.update=function(e,r){if(e=ol.toArray(e,r),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=ol.join32(e,0,e.length-i,this.endian);for(var n=0;n<e.length;n+=this._delta32)this._update(e,n,n+this._delta32)}return this},ao.prototype.digest=function(e){return this.update(this._pad()),y8(this.pending===null),this._digest(e)},ao.prototype._pad=function(){var e=this.pendingTotal,r=this._delta8,i=r-(e+this.padLength)%r,n=new Array(i+this.padLength);n[0]=128;for(var s=1;s<i;s++)n[s]=0;if(e<<=3,this.endian==="big"){for(var o=8;o<this.padLength;o++)n[s++]=0;n[s++]=0,n[s++]=0,n[s++]=0,n[s++]=0,n[s++]=e>>>24&255,n[s++]=e>>>16&255,n[s++]=e>>>8&255,n[s++]=e&255}else for(n[s++]=e&255,n[s++]=e>>>8&255,n[s++]=e>>>16&255,n[s++]=e>>>24&255,n[s++]=0,n[s++]=0,n[s++]=0,n[s++]=0,o=8;o<this.padLength;o++)n[s++]=0;return n};var an={},lr={},v8=J,pr=v8.rotr32;function m8(t,e,r,i){if(t===0)return al(e,r,i);if(t===1||t===3)return fl(e,r,i);if(t===2)return cl(e,r,i)}lr.ft_1=m8;function al(t,e,r){return t&e^~t&r}lr.ch32=al;function cl(t,e,r){return t&e^t&r^e&r}lr.maj32=cl;function fl(t,e,r){return t^e^r}lr.p32=fl;function w8(t){return pr(t,2)^pr(t,13)^pr(t,22)}lr.s0_256=w8;function _8(t){return pr(t,6)^pr(t,11)^pr(t,25)}lr.s1_256=_8;function x8(t){return pr(t,7)^pr(t,18)^t>>>3}lr.g0_256=x8;function E8(t){return pr(t,17)^pr(t,19)^t>>>10}lr.g1_256=E8;var cn=J,S8=on,I8=lr,cc=cn.rotl32,jn=cn.sum32,A8=cn.sum32_5,$8=I8.ft_1,ul=S8.BlockHash,D8=[1518500249,1859775393,2400959708,3395469782];function br(){if(!(this instanceof br))return new br;ul.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.W=new Array(80)}cn.inherits(br,ul);var O8=br;br.blockSize=512,br.outSize=160,br.hmacStrength=80,br.padLength=64,br.prototype._update=function(e,r){for(var i=this.W,n=0;n<16;n++)i[n]=e[r+n];for(;n<i.length;n++)i[n]=cc(i[n-3]^i[n-8]^i[n-14]^i[n-16],1);var s=this.h[0],o=this.h[1],a=this.h[2],c=this.h[3],f=this.h[4];for(n=0;n<i.length;n++){var u=~~(n/20),d=A8(cc(s,5),$8(u,o,a,c),f,i[n],D8[u]);f=c,c=a,a=cc(o,30),o=s,s=d}this.h[0]=jn(this.h[0],s),this.h[1]=jn(this.h[1],o),this.h[2]=jn(this.h[2],a),this.h[3]=jn(this.h[3],c),this.h[4]=jn(this.h[4],f)},br.prototype._digest=function(e){return e==="hex"?cn.toHex32(this.h,"big"):cn.split32(this.h,"big")};var fn=J,M8=on,un=lr,P8=mi,Qt=fn.sum32,R8=fn.sum32_4,T8=fn.sum32_5,N8=un.ch32,C8=un.maj32,B8=un.s0_256,F8=un.s1_256,L8=un.g0_256,q8=un.g1_256,hl=M8.BlockHash,k8=[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 gr(){if(!(this instanceof gr))return new gr;hl.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=k8,this.W=new Array(64)}fn.inherits(gr,hl);var dl=gr;gr.blockSize=512,gr.outSize=256,gr.hmacStrength=192,gr.padLength=64,gr.prototype._update=function(e,r){for(var i=this.W,n=0;n<16;n++)i[n]=e[r+n];for(;n<i.length;n++)i[n]=R8(q8(i[n-2]),i[n-7],L8(i[n-15]),i[n-16]);var s=this.h[0],o=this.h[1],a=this.h[2],c=this.h[3],f=this.h[4],u=this.h[5],d=this.h[6],b=this.h[7];for(P8(this.k.length===i.length),n=0;n<i.length;n++){var v=T8(b,F8(f),N8(f,u,d),this.k[n],i[n]),g=Qt(B8(s),C8(s,o,a));b=d,d=u,u=f,f=Qt(c,v),c=a,a=o,o=s,s=Qt(v,g)}this.h[0]=Qt(this.h[0],s),this.h[1]=Qt(this.h[1],o),this.h[2]=Qt(this.h[2],a),this.h[3]=Qt(this.h[3],c),this.h[4]=Qt(this.h[4],f),this.h[5]=Qt(this.h[5],u),this.h[6]=Qt(this.h[6],d),this.h[7]=Qt(this.h[7],b)},gr.prototype._digest=function(e){return e==="hex"?fn.toHex32(this.h,"big"):fn.split32(this.h,"big")};var fc=J,ll=dl;function Br(){if(!(this instanceof Br))return new Br;ll.call(this),this.h=[3238371032,914150663,812702999,4144912697,4290775857,1750603025,1694076839,3204075428]}fc.inherits(Br,ll);var z8=Br;Br.blockSize=512,Br.outSize=224,Br.hmacStrength=192,Br.padLength=64,Br.prototype._digest=function(e){return e==="hex"?fc.toHex32(this.h.slice(0,7),"big"):fc.split32(this.h.slice(0,7),"big")};var Rt=J,U8=on,j8=mi,yr=Rt.rotr64_hi,vr=Rt.rotr64_lo,pl=Rt.shr64_hi,bl=Rt.shr64_lo,ei=Rt.sum64,uc=Rt.sum64_hi,hc=Rt.sum64_lo,V8=Rt.sum64_4_hi,K8=Rt.sum64_4_lo,H8=Rt.sum64_5_hi,W8=Rt.sum64_5_lo,gl=U8.BlockHash,G8=[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 er(){if(!(this instanceof er))return new er;gl.call(this),this.h=[1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209],this.k=G8,this.W=new Array(160)}Rt.inherits(er,gl);var yl=er;er.blockSize=1024,er.outSize=512,er.hmacStrength=192,er.padLength=128,er.prototype._prepareBlock=function(e,r){for(var i=this.W,n=0;n<32;n++)i[n]=e[r+n];for(;n<i.length;n+=2){var s=s4(i[n-4],i[n-3]),o=o4(i[n-4],i[n-3]),a=i[n-14],c=i[n-13],f=i4(i[n-30],i[n-29]),u=n4(i[n-30],i[n-29]),d=i[n-32],b=i[n-31];i[n]=V8(s,o,a,c,f,u,d,b),i[n+1]=K8(s,o,a,c,f,u,d,b)}},er.prototype._update=function(e,r){this._prepareBlock(e,r);var i=this.W,n=this.h[0],s=this.h[1],o=this.h[2],a=this.h[3],c=this.h[4],f=this.h[5],u=this.h[6],d=this.h[7],b=this.h[8],v=this.h[9],g=this.h[10],x=this.h[11],I=this.h[12],D=this.h[13],O=this.h[14],M=this.h[15];j8(this.k.length===i.length);for(var P=0;P<i.length;P+=2){var T=O,N=M,C=t4(b,v),B=r4(b,v),R=Y8(b,v,g,x,I),V=Z8(b,v,g,x,I,D),A=this.k[P],h=this.k[P+1],p=i[P],m=i[P+1],y=H8(T,N,C,B,R,V,A,h,p,m),w=W8(T,N,C,B,R,V,A,h,p,m);T=Q8(n,s),N=e4(n,s),C=J8(n,s,o,a,c),B=X8(n,s,o,a,c,f);var S=uc(T,N,C,B),$=hc(T,N,C,B);O=I,M=D,I=g,D=x,g=b,x=v,b=uc(u,d,y,w),v=hc(d,d,y,w),u=c,d=f,c=o,f=a,o=n,a=s,n=uc(y,w,S,$),s=hc(y,w,S,$)}ei(this.h,0,n,s),ei(this.h,2,o,a),ei(this.h,4,c,f),ei(this.h,6,u,d),ei(this.h,8,b,v),ei(this.h,10,g,x),ei(this.h,12,I,D),ei(this.h,14,O,M)},er.prototype._digest=function(e){return e==="hex"?Rt.toHex32(this.h,"big"):Rt.split32(this.h,"big")};function Y8(t,e,r,i,n){var s=t&r^~t&n;return s<0&&(s+=4294967296),s}function Z8(t,e,r,i,n,s){var o=e&i^~e&s;return o<0&&(o+=4294967296),o}function J8(t,e,r,i,n){var s=t&r^t&n^r&n;return s<0&&(s+=4294967296),s}function X8(t,e,r,i,n,s){var o=e&i^e&s^i&s;return o<0&&(o+=4294967296),o}function Q8(t,e){var r=yr(t,e,28),i=yr(e,t,2),n=yr(e,t,7),s=r^i^n;return s<0&&(s+=4294967296),s}function e4(t,e){var r=vr(t,e,28),i=vr(e,t,2),n=vr(e,t,7),s=r^i^n;return s<0&&(s+=4294967296),s}function t4(t,e){var r=yr(t,e,14),i=yr(t,e,18),n=yr(e,t,9),s=r^i^n;return s<0&&(s+=4294967296),s}function r4(t,e){var r=vr(t,e,14),i=vr(t,e,18),n=vr(e,t,9),s=r^i^n;return s<0&&(s+=4294967296),s}function i4(t,e){var r=yr(t,e,1),i=yr(t,e,8),n=pl(t,e,7),s=r^i^n;return s<0&&(s+=4294967296),s}function n4(t,e){var r=vr(t,e,1),i=vr(t,e,8),n=bl(t,e,7),s=r^i^n;return s<0&&(s+=4294967296),s}function s4(t,e){var r=yr(t,e,19),i=yr(e,t,29),n=pl(t,e,6),s=r^i^n;return s<0&&(s+=4294967296),s}function o4(t,e){var r=vr(t,e,19),i=vr(e,t,29),n=bl(t,e,6),s=r^i^n;return s<0&&(s+=4294967296),s}var dc=J,vl=yl;function Fr(){if(!(this instanceof Fr))return new Fr;vl.call(this),this.h=[3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]}dc.inherits(Fr,vl);var a4=Fr;Fr.blockSize=1024,Fr.outSize=384,Fr.hmacStrength=192,Fr.padLength=128,Fr.prototype._digest=function(e){return e==="hex"?dc.toHex32(this.h.slice(0,12),"big"):dc.split32(this.h.slice(0,12),"big")},an.sha1=O8,an.sha224=z8,an.sha256=dl,an.sha384=a4,an.sha512=yl;var ml={},_i=J,c4=on,co=_i.rotl32,wl=_i.sum32,Vn=_i.sum32_3,_l=_i.sum32_4,xl=c4.BlockHash;function mr(){if(!(this instanceof mr))return new mr;xl.call(this),this.h=[1732584193,4023233417,2562383102,271733878,3285377520],this.endian="little"}_i.inherits(mr,xl),ml.ripemd160=mr,mr.blockSize=512,mr.outSize=160,mr.hmacStrength=192,mr.padLength=64,mr.prototype._update=function(e,r){for(var i=this.h[0],n=this.h[1],s=this.h[2],o=this.h[3],a=this.h[4],c=i,f=n,u=s,d=o,b=a,v=0;v<80;v++){var g=wl(co(_l(i,El(v,n,s,o),e[h4[v]+r],f4(v)),l4[v]),a);i=a,a=o,o=co(s,10),s=n,n=g,g=wl(co(_l(c,El(79-v,f,u,d),e[d4[v]+r],u4(v)),p4[v]),b),c=b,b=d,d=co(u,10),u=f,f=g}g=Vn(this.h[1],s,d),this.h[1]=Vn(this.h[2],o,b),this.h[2]=Vn(this.h[3],a,c),this.h[3]=Vn(this.h[4],i,f),this.h[4]=Vn(this.h[0],n,u),this.h[0]=g},mr.prototype._digest=function(e){return e==="hex"?_i.toHex32(this.h,"little"):_i.split32(this.h,"little")};function El(t,e,r,i){return t<=15?e^r^i:t<=31?e&r|~e&i:t<=47?(e|~r)^i:t<=63?e&i|r&~i:e^(r|~i)}function f4(t){return t<=15?0:t<=31?1518500249:t<=47?1859775393:t<=63?2400959708:2840853838}function u4(t){return t<=15?1352829926:t<=31?1548603684:t<=47?1836072691:t<=63?2053994217:0}var h4=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],d4=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],l4=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],p4=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],b4=J,g4=mi;function hn(t,e,r){if(!(this instanceof hn))return new hn(t,e,r);this.Hash=t,this.blockSize=t.blockSize/8,this.outSize=t.outSize/8,this.inner=null,this.outer=null,this._init(b4.toArray(e,r))}var y4=hn;hn.prototype._init=function(e){e.length>this.blockSize&&(e=new this.Hash().update(e).digest()),g4(e.length<=this.blockSize);for(var r=e.length;r<this.blockSize;r++)e.push(0);for(r=0;r<e.length;r++)e[r]^=54;for(this.inner=new this.Hash().update(e),r=0;r<e.length;r++)e[r]^=106;this.outer=new this.Hash().update(e)},hn.prototype.update=function(e,r){return this.inner.update(e,r),this},hn.prototype.digest=function(e){return this.outer.update(this.inner.digest()),this.outer.digest(e)},function(t){var e=t;e.utils=J,e.common=on,e.sha=an,e.ripemd=ml,e.hmac=y4,e.sha1=e.sha.sha1,e.sha256=e.sha.sha256,e.sha224=e.sha.sha224,e.sha384=e.sha.sha384,e.sha512=e.sha.sha512,e.ripemd160=e.ripemd.ripemd160}(oo);var lc,Sl;function v4(){return Sl||(Sl=1,lc={doubles:{step:4,points:[["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a","f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"],["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508","11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"],["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739","d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"],["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640","4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"],["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c","4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"],["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda","96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"],["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa","5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"],["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0","cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"],["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d","9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"],["feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d","e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088"],["da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1","9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d"],["53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0","5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8"],["8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047","10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a"],["385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862","283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453"],["6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7","7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160"],["3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd","56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0"],["85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83","7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6"],["948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a","53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589"],["6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8","bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17"],["e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d","4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda"],["e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725","7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd"],["213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754","4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2"],["4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c","17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6"],["fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6","6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f"],["76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39","c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01"],["c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891","893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3"],["d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b","febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f"],["b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03","2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7"],["e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d","eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78"],["a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070","7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1"],["90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4","e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150"],["8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da","662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82"],["e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11","1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc"],["8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e","efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b"],["e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41","2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51"],["b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef","67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45"],["d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8","db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120"],["324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d","648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84"],["4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96","35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d"],["9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd","ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d"],["6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5","9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8"],["a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266","40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8"],["7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71","34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac"],["928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac","c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f"],["85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751","1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962"],["ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e","493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907"],["827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241","c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec"],["eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3","be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d"],["e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f","4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414"],["1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19","aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd"],["146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be","b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0"],["fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9","6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811"],["da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2","8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1"],["a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13","7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c"],["174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c","ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73"],["959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba","2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd"],["d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151","e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405"],["64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073","d99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589"],["8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458","38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e"],["13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b","69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27"],["bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366","d3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1"],["8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa","40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482"],["8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0","620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945"],["dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787","7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573"],["f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e","ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82"]]},naf:{wnd:7,points:[["f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9","388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672"],["2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4","d8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6"],["5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc","6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da"],["acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe","cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37"],["774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb","d984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b"],["f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8","ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81"],["d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e","581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58"],["defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34","4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77"],["2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c","85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a"],["352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5","321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c"],["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f","2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67"],["9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714","73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402"],["daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729","a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55"],["c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db","2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482"],["6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4","e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82"],["1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5","b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396"],["605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479","2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49"],["62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d","80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf"],["80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f","1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a"],["7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb","d0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7"],["d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9","eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933"],["49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963","758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a"],["77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74","958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6"],["f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530","e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37"],["463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b","5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e"],["f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247","cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6"],["caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1","cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476"],["2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120","4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40"],["7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435","91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61"],["754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18","673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683"],["e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8","59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5"],["186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb","3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b"],["df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f","55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417"],["5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143","efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868"],["290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba","e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a"],["af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45","f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6"],["766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a","744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996"],["59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e","c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e"],["f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8","e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d"],["7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c","30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2"],["948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519","e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e"],["7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab","100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437"],["3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca","ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311"],["d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf","8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4"],["1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610","68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575"],["733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4","f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d"],["15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c","d56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d"],["a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940","edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629"],["e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980","a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06"],["311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3","66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374"],["34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf","9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee"],["f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63","4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1"],["d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448","fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b"],["32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf","5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661"],["7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5","8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6"],["ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6","8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e"],["16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5","5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d"],["eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99","f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc"],["78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51","f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4"],["494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5","42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c"],["a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5","204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b"],["c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997","4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913"],["841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881","73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154"],["5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5","39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865"],["36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66","d2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc"],["336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726","ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224"],["8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede","6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e"],["1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94","60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6"],["85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31","3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511"],["29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51","b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b"],["a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252","ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2"],["4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5","cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c"],["d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b","6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3"],["ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4","322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d"],["af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f","6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700"],["e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889","2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4"],["591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246","b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196"],["11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984","998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4"],["3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a","b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257"],["cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030","bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13"],["c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197","6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096"],["c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593","c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38"],["a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef","21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f"],["347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38","60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448"],["da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a","49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a"],["c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111","5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4"],["4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502","7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437"],["3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea","be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7"],["cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26","8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d"],["b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986","39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a"],["d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e","62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54"],["48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4","25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77"],["dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda","ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517"],["6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859","cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10"],["e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f","f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125"],["eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c","6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e"],["13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942","fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1"],["ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a","1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2"],["b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80","5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423"],["ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d","438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8"],["8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1","cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758"],["52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63","c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375"],["e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352","6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d"],["7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193","ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec"],["5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00","9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0"],["32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58","ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c"],["e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7","d3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4"],["8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8","c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f"],["4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e","67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649"],["3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d","cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826"],["674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b","299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5"],["d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f","f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87"],["30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6","462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b"],["be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297","62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc"],["93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a","7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c"],["b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c","ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f"],["d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52","4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a"],["d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb","bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46"],["463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065","bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f"],["7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917","603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03"],["74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9","cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08"],["30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3","553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8"],["9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57","712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373"],["176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66","ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3"],["75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8","9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8"],["809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721","9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1"],["1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180","4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9"]]}}),lc}(function(t){var e=t,r=oo,i=oc,n=Ft,s=n.assert;function o(f){f.type==="short"?this.curve=new i.short(f):f.type==="edwards"?this.curve=new i.edwards(f):this.curve=new i.mont(f),this.g=this.curve.g,this.n=this.curve.n,this.hash=f.hash,s(this.g.validate(),"Invalid curve"),s(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O")}e.PresetCurve=o;function a(f,u){Object.defineProperty(e,f,{configurable:!0,enumerable:!0,get:function(){var d=new o(u);return Object.defineProperty(e,f,{configurable:!0,enumerable:!0,value:d}),d}})}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:r.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:r.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:r.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:r.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:r.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:r.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:r.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});var c;try{c=v4()}catch{c=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:r.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",c]})})(so);var m4=oo,xi=nc,Il=mi;function ti(t){if(!(this instanceof ti))return new ti(t);this.hash=t.hash,this.predResist=!!t.predResist,this.outLen=this.hash.outSize,this.minEntropy=t.minEntropy||this.hash.hmacStrength,this._reseed=null,this.reseedInterval=null,this.K=null,this.V=null;var e=xi.toArray(t.entropy,t.entropyEnc||"hex"),r=xi.toArray(t.nonce,t.nonceEnc||"hex"),i=xi.toArray(t.pers,t.persEnc||"hex");Il(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,r,i)}var w4=ti;ti.prototype._init=function(e,r,i){var n=e.concat(r).concat(i);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var s=0;s<this.V.length;s++)this.K[s]=0,this.V[s]=1;this._update(n),this._reseed=1,this.reseedInterval=281474976710656},ti.prototype._hmac=function(){return new m4.hmac(this.hash,this.K)},ti.prototype._update=function(e){var r=this._hmac().update(this.V).update([0]);e&&(r=r.update(e)),this.K=r.digest(),this.V=this._hmac().update(this.V).digest(),e&&(this.K=this._hmac().update(this.V).update([1]).update(e).digest(),this.V=this._hmac().update(this.V).digest())},ti.prototype.reseed=function(e,r,i,n){typeof r!="string"&&(n=i,i=r,r=null),e=xi.toArray(e,r),i=xi.toArray(i,n),Il(e.length>=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(e.concat(i||[])),this._reseed=1},ti.prototype.generate=function(e,r,i,n){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");typeof r!="string"&&(n=i,i=r,r=null),i&&(i=xi.toArray(i,n||"hex"),this._update(i));for(var s=[];s.length<e;)this.V=this._hmac().update(this.V).digest(),s=s.concat(this.V);var o=s.slice(0,e);return this._update(i),this._reseed++,xi.encode(o,r)};var _4=hr.exports,x4=Ft,pc=x4.assert;function _t(t,e){this.ec=t,this.priv=null,this.pub=null,e.priv&&this._importPrivate(e.priv,e.privEnc),e.pub&&this._importPublic(e.pub,e.pubEnc)}var E4=_t;_t.fromPublic=function(e,r,i){return r instanceof _t?r:new _t(e,{pub:r,pubEnc:i})},_t.fromPrivate=function(e,r,i){return r instanceof _t?r:new _t(e,{priv:r,privEnc:i})},_t.prototype.validate=function(){var e=this.getPublic();return e.isInfinity()?{result:!1,reason:"Invalid public key"}:e.validate()?e.mul(this.ec.curve.n).isInfinity()?{result:!0,reason:null}:{result:!1,reason:"Public key * N != O"}:{result:!1,reason:"Public key is not a point"}},_t.prototype.getPublic=function(e,r){return typeof e=="string"&&(r=e,e=null),this.pub||(this.pub=this.ec.g.mul(this.priv)),r?this.pub.encode(r,e):this.pub},_t.prototype.getPrivate=function(e){return e==="hex"?this.priv.toString(16,2):this.priv},_t.prototype._importPrivate=function(e,r){this.priv=new _4(e,r||16),this.priv=this.priv.umod(this.ec.curve.n)},_t.prototype._importPublic=function(e,r){if(e.x||e.y){this.ec.curve.type==="mont"?pc(e.x,"Need x coordinate"):(this.ec.curve.type==="short"||this.ec.curve.type==="edwards")&&pc(e.x&&e.y,"Need both x and y coordinate"),this.pub=this.ec.curve.point(e.x,e.y);return}this.pub=this.ec.curve.decodePoint(e,r)},_t.prototype.derive=function(e){return e.validate()||pc(e.validate(),"public point not validated"),e.mul(this.priv).getX()},_t.prototype.sign=function(e,r,i){return this.ec.sign(e,this,r,i)},_t.prototype.verify=function(e,r,i){return this.ec.verify(e,r,this,void 0,i)},_t.prototype.inspect=function(){return"<Key priv: "+(this.priv&&this.priv.toString(16,2))+" pub: "+(this.pub&&this.pub.inspect())+" >"};var fo=hr.exports,bc=Ft,S4=bc.assert;function uo(t,e){if(t instanceof uo)return t;this._importDER(t,e)||(S4(t.r&&t.s,"Signature without r or s"),this.r=new fo(t.r,16),this.s=new fo(t.s,16),t.recoveryParam===void 0?this.recoveryParam=null:this.recoveryParam=t.recoveryParam)}var I4=uo;function A4(){this.place=0}function gc(t,e){var r=t[e.place++];if(!(r&128))return r;var i=r&15;if(i===0||i>4||t[e.place]===0)return!1;for(var n=0,s=0,o=e.place;s<i;s++,o++)n<<=8,n|=t[o],n>>>=0;return n<=127?!1:(e.place=o,n)}function Al(t){for(var e=0,r=t.length-1;!t[e]&&!(t[e+1]&128)&&e<r;)e++;return e===0?t:t.slice(e)}uo.prototype._importDER=function(e,r){e=bc.toArray(e,r);var i=new A4;if(e[i.place++]!==48)return!1;var n=gc(e,i);if(n===!1||n+i.place!==e.length||e[i.place++]!==2)return!1;var s=gc(e,i);if(s===!1||e[i.place]&128)return!1;var o=e.slice(i.place,s+i.place);if(i.place+=s,e[i.place++]!==2)return!1;var a=gc(e,i);if(a===!1||e.length!==a+i.place||e[i.place]&128)return!1;var c=e.slice(i.place,a+i.place);if(o[0]===0)if(o[1]&128)o=o.slice(1);else return!1;if(c[0]===0)if(c[1]&128)c=c.slice(1);else return!1;return this.r=new fo(o),this.s=new fo(c),this.recoveryParam=null,!0};function yc(t,e){if(e<128){t.push(e);return}var r=1+(Math.log(e)/Math.LN2>>>3);for(t.push(r|128);--r;)t.push(e>>>(r<<3)&255);t.push(e)}uo.prototype.toDER=function(e){var r=this.r.toArray(),i=this.s.toArray();for(r[0]&128&&(r=[0].concat(r)),i[0]&128&&(i=[0].concat(i)),r=Al(r),i=Al(i);!i[0]&&!(i[1]&128);)i=i.slice(1);var n=[2];yc(n,r.length),n=n.concat(r),n.push(2),yc(n,i.length);var s=n.concat(i),o=[48];return yc(o,s.length),o=o.concat(s),bc.encode(o,e)};var tr=hr.exports,$l=w4,$4=Ft,vc=so,D4=Qs.exports,Ei=$4.assert,mc=E4,ho=I4;function Ht(t){if(!(this instanceof Ht))return new Ht(t);typeof t=="string"&&(Ei(Object.prototype.hasOwnProperty.call(vc,t),"Unknown curve "+t),t=vc[t]),t instanceof vc.PresetCurve&&(t={curve:t}),this.curve=t.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=t.curve.g,this.g.precompute(t.curve.n.bitLength()+1),this.hash=t.hash||t.curve.hash}var O4=Ht;Ht.prototype.keyPair=function(e){return new mc(this,e)},Ht.prototype.keyFromPrivate=function(e,r){return mc.fromPrivate(this,e,r)},Ht.prototype.keyFromPublic=function(e,r){return mc.fromPublic(this,e,r)},Ht.prototype.genKeyPair=function(e){e||(e={});for(var r=new $l({hash:this.hash,pers:e.pers,persEnc:e.persEnc||"utf8",entropy:e.entropy||D4(this.hash.hmacStrength),entropyEnc:e.entropy&&e.entropyEnc||"utf8",nonce:this.n.toArray()}),i=this.n.byteLength(),n=this.n.sub(new tr(2));;){var s=new tr(r.generate(i));if(!(s.cmp(n)>0))return s.iaddn(1),this.keyFromPrivate(s)}},Ht.prototype._truncateToN=function(e,r,i){var n;if(tr.isBN(e)||typeof e=="number")e=new tr(e,16),n=e.byteLength();else if(typeof e=="object")n=e.length,e=new tr(e,16);else{var s=e.toString();n=s.length+1>>>1,e=new tr(s,16)}typeof i!="number"&&(i=n*8);var o=i-this.n.bitLength();return o>0&&(e=e.ushrn(o)),!r&&e.cmp(this.n)>=0?e.sub(this.n):e},Ht.prototype.sign=function(e,r,i,n){if(typeof i=="object"&&(n=i,i=null),n||(n={}),typeof e!="string"&&typeof e!="number"&&!tr.isBN(e)){Ei(typeof e=="object"&&e&&typeof e.length=="number","Expected message to be an array-like, a hex string, or a BN instance"),Ei(e.length>>>0===e.length);for(var s=0;s<e.length;s++)Ei((e[s]&255)===e[s])}r=this.keyFromPrivate(r,i),e=this._truncateToN(e,!1,n.msgBitLength),Ei(!e.isNeg(),"Can not sign a negative message");var o=this.n.byteLength(),a=r.getPrivate().toArray("be",o),c=e.toArray("be",o);Ei(new tr(c).eq(e),"Can not sign message");for(var f=new $l({hash:this.hash,entropy:a,nonce:c,pers:n.pers,persEnc:n.persEnc||"utf8"}),u=this.n.sub(new tr(1)),d=0;;d++){var b=n.k?n.k(d):new tr(f.generate(this.n.byteLength()));if(b=this._truncateToN(b,!0),!(b.cmpn(1)<=0||b.cmp(u)>=0)){var v=this.g.mul(b);if(!v.isInfinity()){var g=v.getX(),x=g.umod(this.n);if(x.cmpn(0)!==0){var I=b.invm(this.n).mul(x.mul(r.getPrivate()).iadd(e));if(I=I.umod(this.n),I.cmpn(0)!==0){var D=(v.getY().isOdd()?1:0)|(g.cmp(x)!==0?2:0);return n.canonical&&I.cmp(this.nh)>0&&(I=this.n.sub(I),D^=1),new ho({r:x,s:I,recoveryParam:D})}}}}}},Ht.prototype.verify=function(e,r,i,n,s){s||(s={}),e=this._truncateToN(e,!1,s.msgBitLength),i=this.keyFromPublic(i,n),r=new ho(r,"hex");var o=r.r,a=r.s;if(o.cmpn(1)<0||o.cmp(this.n)>=0||a.cmpn(1)<0||a.cmp(this.n)>=0)return!1;var c=a.invm(this.n),f=c.mul(e).umod(this.n),u=c.mul(o).umod(this.n),d;return this.curve._maxwellTrick?(d=this.g.jmulAdd(f,i.getPublic(),u),d.isInfinity()?!1:d.eqXToP(o)):(d=this.g.mulAdd(f,i.getPublic(),u),d.isInfinity()?!1:d.getX().umod(this.n).cmp(o)===0)},Ht.prototype.recoverPubKey=function(t,e,r,i){Ei((3&r)===r,"The recovery param is more than two bits"),e=new ho(e,i);var n=this.n,s=new tr(t),o=e.r,a=e.s,c=r&1,f=r>>1;if(o.cmp(this.curve.p.umod(this.curve.n))>=0&&f)throw new Error("Unable to find sencond key candinate");f?o=this.curve.pointFromX(o.add(this.curve.n),c):o=this.curve.pointFromX(o,c);var u=e.r.invm(n),d=n.sub(s).mul(u).umod(n),b=a.mul(u).umod(n);return this.g.mulAdd(d,o,b)},Ht.prototype.getKeyRecoveryParam=function(t,e,r,i){if(e=new ho(e,i),e.recoveryParam!==null)return e.recoveryParam;for(var n=0;n<4;n++){var s;try{s=this.recoverPubKey(t,e,n)}catch{continue}if(s.eq(r))return n}throw new Error("Unable to find valid recovery factor")};var Kn=Ft,Dl=Kn.assert,Ol=Kn.parseBytes,dn=Kn.cachedProperty;function ot(t,e){this.eddsa=t,this._secret=Ol(e.secret),t.isPoint(e.pub)?this._pub=e.pub:this._pubBytes=Ol(e.pub)}ot.fromPublic=function(e,r){return r instanceof ot?r:new ot(e,{pub:r})},ot.fromSecret=function(e,r){return r instanceof ot?r:new ot(e,{secret:r})},ot.prototype.secret=function(){return this._secret},dn(ot,"pubBytes",function(){return this.eddsa.encodePoint(this.pub())}),dn(ot,"pub",function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())}),dn(ot,"privBytes",function(){var e=this.eddsa,r=this.hash(),i=e.encodingLength-1,n=r.slice(0,e.encodingLength);return n[0]&=248,n[i]&=127,n[i]|=64,n}),dn(ot,"priv",function(){return this.eddsa.decodeInt(this.privBytes())}),dn(ot,"hash",function(){return this.eddsa.hash().update(this.secret()).digest()}),dn(ot,"messagePrefix",function(){return this.hash().slice(this.eddsa.encodingLength)}),ot.prototype.sign=function(e){return Dl(this._secret,"KeyPair can only verify"),this.eddsa.sign(e,this)},ot.prototype.verify=function(e,r){return this.eddsa.verify(e,r,this)},ot.prototype.getSecret=function(e){return Dl(this._secret,"KeyPair is public only"),Kn.encode(this.secret(),e)},ot.prototype.getPublic=function(e){return Kn.encode(this.pubBytes(),e)};var M4=ot,P4=hr.exports,lo=Ft,Ml=lo.assert,po=lo.cachedProperty,R4=lo.parseBytes;function Si(t,e){this.eddsa=t,typeof e!="object"&&(e=R4(e)),Array.isArray(e)&&(Ml(e.length===t.encodingLength*2,"Signature has invalid size"),e={R:e.slice(0,t.encodingLength),S:e.slice(t.encodingLength)}),Ml(e.R&&e.S,"Signature without R or S"),t.isPoint(e.R)&&(this._R=e.R),e.S instanceof P4&&(this._S=e.S),this._Rencoded=Array.isArray(e.R)?e.R:e.Rencoded,this._Sencoded=Array.isArray(e.S)?e.S:e.Sencoded}po(Si,"S",function(){return this.eddsa.decodeInt(this.Sencoded())}),po(Si,"R",function(){return this.eddsa.decodePoint(this.Rencoded())}),po(Si,"Rencoded",function(){return this.eddsa.encodePoint(this.R())}),po(Si,"Sencoded",function(){return this.eddsa.encodeInt(this.S())}),Si.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())},Si.prototype.toHex=function(){return lo.encode(this.toBytes(),"hex").toUpperCase()};var T4=Si,N4=oo,C4=so,ln=Ft,B4=ln.assert,Pl=ln.parseBytes,Rl=M4,Tl=T4;function Tt(t){if(B4(t==="ed25519","only tested with ed25519 so far"),!(this instanceof Tt))return new Tt(t);t=C4[t].curve,this.curve=t,this.g=t.g,this.g.precompute(t.n.bitLength()+1),this.pointClass=t.point().constructor,this.encodingLength=Math.ceil(t.n.bitLength()/8),this.hash=N4.sha512}var F4=Tt;Tt.prototype.sign=function(e,r){e=Pl(e);var i=this.keyFromSecret(r),n=this.hashInt(i.messagePrefix(),e),s=this.g.mul(n),o=this.encodePoint(s),a=this.hashInt(o,i.pubBytes(),e).mul(i.priv()),c=n.add(a).umod(this.curve.n);return this.makeSignature({R:s,S:c,Rencoded:o})},Tt.prototype.verify=function(e,r,i){if(e=Pl(e),r=this.makeSignature(r),r.S().gte(r.eddsa.curve.n)||r.S().isNeg())return!1;var n=this.keyFromPublic(i),s=this.hashInt(r.Rencoded(),n.pubBytes(),e),o=this.g.mul(r.S()),a=r.R().add(n.pub().mul(s));return a.eq(o)},Tt.prototype.hashInt=function(){for(var e=this.hash(),r=0;r<arguments.length;r++)e.update(arguments[r]);return ln.intFromLE(e.digest()).umod(this.curve.n)},Tt.prototype.keyFromPublic=function(e){return Rl.fromPublic(this,e)},Tt.prototype.keyFromSecret=function(e){return Rl.fromSecret(this,e)},Tt.prototype.makeSignature=function(e){return e instanceof Tl?e:new Tl(this,e)},Tt.prototype.encodePoint=function(e){var r=e.getY().toArray("le",this.encodingLength);return r[this.encodingLength-1]|=e.getX().isOdd()?128:0,r},Tt.prototype.decodePoint=function(e){e=ln.parseBytes(e);var r=e.length-1,i=e.slice(0,r).concat(e[r]&-129),n=(e[r]&128)!==0,s=ln.intFromLE(i);return this.curve.pointFromY(s,n)},Tt.prototype.encodeInt=function(e){return e.toArray("le",this.encodingLength)},Tt.prototype.decodeInt=function(e){return ln.intFromLE(e)},Tt.prototype.isPoint=function(e){return e instanceof this.pointClass},function(t){var e=t;e.version=N6.version,e.utils=Ft,e.rand=Qs.exports,e.curve=oc,e.curves=so,e.ec=O4,e.eddsa=F4}(Jd);const L4={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"}},q4=":";function bo(t){const[e,r]=t.split(q4);return{namespace:e,reference:r}}function Nl(t,e){return t.includes(":")?[t]:e.chains||[]}const k4="ReactNative",Lt={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},z4="js";function go(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function ri(){return!Rn()&&!!xa()&&navigator.product===k4}function U4(){return ri()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function j4(){return ri()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function Hn(){return!go()&&!!xa()&&!!Rn()}function Wn(){return ri()?Lt.reactNative:go()?Lt.node:Hn()?Lt.browser:Lt.unknown}function Cl(){var t;try{return ri()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(t=global.Application)==null?void 0:t.applicationId:void 0}catch{return}}function V4(t,e){const r=new URLSearchParams(t);for(const i of Object.keys(e).sort())if(e.hasOwnProperty(i)){const n=e[i];n!==void 0&&r.set(i,n)}return r.toString()}function Bl(){return Sh()||{name:"",description:"",url:"",icons:[""]}}function K4(){if(Wn()===Lt.reactNative&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"){const{OS:r,Version:i}=global.Platform;return[r,i].join("-")}const t=wv();if(t===null)return"unknown";const e=t.os?t.os.replace(" ","").toLowerCase():"unknown";return t.type==="browser"?[e,t.name,t.version].join("-"):[e,t.version].join("-")}function H4(){var t;const e=Wn();return e===Lt.browser?[e,((t=Eh())==null?void 0:t.host)||"unknown"].join(":"):e}function Fl(t,e,r){const i=K4(),n=H4();return[[t,e].join("-"),[z4,r].join("-"),i,n].join("/")}function W4({protocol:t,version:e,relayUrl:r,sdkVersion:i,auth:n,projectId:s,useOnCloseEvent:o,bundleId:a,packageName:c}){const f=r.split("?"),u=Fl(t,e,i),d={auth:n,ua:u,projectId:s,useOnCloseEvent:o||void 0,packageName:c||void 0,bundleId:a||void 0},b=V4(f[1]||"",d);return f[0]+"?"+b}function Ii(t,e){return t.filter(r=>e.includes(r)).length===t.length}function wc(t){return Object.fromEntries(t.entries())}function _c(t){return new Map(Object.entries(t))}function Ai(t=z.FIVE_MINUTES,e){const r=z.toMiliseconds(t||z.FIVE_MINUTES);let i,n,s,o;return{resolve:a=>{s&&i&&(clearTimeout(s),i(a),o=Promise.resolve(a))},reject:a=>{s&&n&&(clearTimeout(s),n(a))},done:()=>new Promise((a,c)=>{if(o)return a(o);s=setTimeout(()=>{const f=new Error(e);o=Promise.reject(f),c(f)},r),i=a,n=c})}}function ii(t,e,r){return new Promise(async(i,n)=>{const s=setTimeout(()=>n(new Error(r)),e);try{const o=await t;i(o)}catch(o){n(o)}clearTimeout(s)})}function Ll(t,e){if(typeof e=="string"&&e.startsWith(`${t}:`))return e;if(t.toLowerCase()==="topic"){if(typeof e!="string")throw new Error('Value must be "string" for expirer target type: topic');return`topic:${e}`}else if(t.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: ${t}`)}function G4(t){return Ll("topic",t)}function Y4(t){return Ll("id",t)}function ql(t){const[e,r]=t.split(":"),i={id:void 0,topic:void 0};if(e==="topic"&&typeof r=="string")i.topic=r;else if(e==="id"&&Number.isInteger(Number(r)))i.id=Number(r);else throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${r}`);return i}function Qe(t,e){return z.fromMiliseconds((e||Date.now())+z.toMiliseconds(t))}function ni(t){return Date.now()>=z.toMiliseconds(t)}function ne(t,e){return`${t}${e?`:${e}`:""}`}function Z4(t=[],e=[]){return[...new Set([...t,...e])]}async function J4({id:t,topic:e,wcDeepLink:r}){var i;try{if(!r)return;const n=typeof r=="string"?JSON.parse(r):r,s=n?.href;if(typeof s!="string")return;const o=X4(s,t,e),a=Wn();if(a===Lt.browser){if(!((i=Rn())!=null&&i.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}Q4(o)}else a===Lt.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(o)}catch(n){console.error(n)}}function X4(t,e,r){const i=`requestId=${e}&sessionTopic=${r}`;t.endsWith("/")&&(t=t.slice(0,-1));let n=`${t}`;if(t.startsWith("https://t.me")){const s=t.includes("?")?"&startapp=":"?startapp=";n=`${n}${s}${i5(i,!0)}`}else n=`${n}/wc?${i}`;return n}function Q4(t){let e="_self";r5()?e="_top":(t5()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function e5(t,e){let r="";try{if(Hn()&&(r=localStorage.getItem(e),r))return r;r=await t.getItem(e)}catch(i){console.error(i)}return r}function kl(t,e){if(!t.includes(e))return null;const r=t.split(/([&,?,=])/),i=r.indexOf(e);return r[i+2]}function zl(){return typeof crypto<"u"&&crypto!=null&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/gu,t=>{const e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function xc(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function t5(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function r5(){try{return window.self!==window.top}catch{return!1}}function i5(t,e=!1){const r=Buffer.from(t).toString("base64");return e?r.replace(/[=]/g,""):r}function Ul(t){return Buffer.from(t,"base64").toString("utf-8")}function n5(t){return new Promise(e=>setTimeout(e,t))}function Gn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function s5(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function yo(t,...e){if(!s5(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Ec(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Gn(t.outputLen),Gn(t.blockLen)}function pn(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function jl(t,e){yo(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const vo=BigInt(2**32-1),Vl=BigInt(32);function o5(t,e=!1){return e?{h:Number(t&vo),l:Number(t>>Vl&vo)}:{h:Number(t>>Vl&vo)|0,l:Number(t&vo)|0}}function a5(t,e=!1){let r=new Uint32Array(t.length),i=new Uint32Array(t.length);for(let n=0;n<t.length;n++){const{h:s,l:o}=o5(t[n],e);[r[n],i[n]]=[s,o]}return[r,i]}const c5=(t,e,r)=>t<<r|e>>>32-r,f5=(t,e,r)=>e<<r|t>>>32-r,u5=(t,e,r)=>e<<r-32|t>>>64-r,h5=(t,e,r)=>t<<r-32|e>>>64-r,bn=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function d5(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Sc(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function wr(t,e){return t<<32-e|t>>>e}const Kl=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function l5(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Hl(t){for(let e=0;e<t.length;e++)t[e]=l5(t[e])}function p5(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function gn(t){return typeof t=="string"&&(t=p5(t)),yo(t),t}class Ic{clone(){return this._cloneInto()}}function Wl(t){const e=i=>t().update(gn(i)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Yn(t=32){if(bn&&typeof bn.getRandomValues=="function")return bn.getRandomValues(new Uint8Array(t));if(bn&&typeof bn.randomBytes=="function")return bn.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}const Gl=[],Yl=[],Zl=[],b5=BigInt(0),Zn=BigInt(1),g5=BigInt(2),y5=BigInt(7),v5=BigInt(256),m5=BigInt(113);for(let t=0,e=Zn,r=1,i=0;t<24;t++){[r,i]=[i,(2*r+3*i)%5],Gl.push(2*(5*i+r)),Yl.push((t+1)*(t+2)/2%64);let n=b5;for(let s=0;s<7;s++)e=(e<<Zn^(e>>y5)*m5)%v5,e&g5&&(n^=Zn<<(Zn<<BigInt(s))-Zn);Zl.push(n)}const[w5,_5]=a5(Zl,!0),Jl=(t,e,r)=>r>32?u5(t,e,r):c5(t,e,r),Xl=(t,e,r)=>r>32?h5(t,e,r):f5(t,e,r);function x5(t,e=24){const r=new Uint32Array(10);for(let i=24-e;i<24;i++){for(let o=0;o<10;o++)r[o]=t[o]^t[o+10]^t[o+20]^t[o+30]^t[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,c=(o+2)%10,f=r[c],u=r[c+1],d=Jl(f,u,1)^r[a],b=Xl(f,u,1)^r[a+1];for(let v=0;v<50;v+=10)t[o+v]^=d,t[o+v+1]^=b}let n=t[2],s=t[3];for(let o=0;o<24;o++){const a=Yl[o],c=Jl(n,s,a),f=Xl(n,s,a),u=Gl[o];n=t[u],s=t[u+1],t[u]=c,t[u+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}t[0]^=w5[i],t[1]^=_5[i]}r.fill(0)}class Ac extends Ic{constructor(e,r,i,n=!1,s=24){if(super(),this.blockLen=e,this.suffix=r,this.outputLen=i,this.enableXOF=n,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Gn(i),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=d5(this.state)}keccak(){Kl||Hl(this.state32),x5(this.state32,this.rounds),Kl||Hl(this.state32),this.posOut=0,this.pos=0}update(e){pn(this);const{blockLen:r,state:i}=this;e=gn(e);const n=e.length;for(let s=0;s<n;){const o=Math.min(r-this.pos,n-s);for(let a=0;a<o;a++)i[this.pos++]^=e[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:r,pos:i,blockLen:n}=this;e[i]^=r,r&128&&i===n-1&&this.keccak(),e[n-1]^=128,this.keccak()}writeInto(e){pn(this,!1),yo(e),this.finish();const r=this.state,{blockLen:i}=this;for(let n=0,s=e.length;n<s;){this.posOut>=i&&this.keccak();const o=Math.min(i-this.posOut,s-n);e.set(r.subarray(this.posOut,this.posOut+o),n),this.posOut+=o,n+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Gn(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(jl(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:r,suffix:i,outputLen:n,rounds:s,enableXOF:o}=this;return e||(e=new Ac(r,i,n,o,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=i,e.outputLen=n,e.enableXOF=o,e.destroyed=this.destroyed,e}}const E5=(t,e,r)=>Wl(()=>new Ac(e,t,r)),S5=E5(1,136,256/8),I5="https://rpc.walletconnect.org/v1";function Ql(t){const e=`Ethereum Signed Message:
18
- ${t.length}`,r=new TextEncoder().encode(e+t);return"0x"+Buffer.from(S5(r)).toString("hex")}async function A5(t,e,r,i,n,s){switch(r.t){case"eip191":return await $5(t,e,r.s);case"eip1271":return await D5(t,e,r.s,i,n,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${r.t}`)}}async function $5(t,e,r){return(await vm({hash:Ql(e),signature:r})).toLowerCase()===t.toLowerCase()}async function D5(t,e,r,i,n,s){const o=bo(i);if(!o.namespace||!o.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${i}`);try{const a="0x1626ba7e",c="0000000000000000000000000000000000000000000000000000000000000040",f="0000000000000000000000000000000000000000000000000000000000000041",u=r.substring(2),d=Ql(e).substring(2),b=a+d+c+f+u,v=await fetch(`${s||I5}/?chainId=${i}&projectId=${n}`,{method:"POST",body:JSON.stringify({id:O5(),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:b},"latest"]})}),{result:g}=await v.json();return g?g.slice(0,a.length).toLowerCase()===a.toLowerCase():!1}catch(a){return console.error("isValidEip1271Signature: ",a),!1}}function O5(){return Date.now()+Math.floor(Math.random()*1e3)}function M5(t){const e=atob(t),r=new Uint8Array(e.length);for(let o=0;o<e.length;o++)r[o]=e.charCodeAt(o);const i=r[0];if(i===0)throw new Error("No signatures found");const n=1+i*64;if(r.length<n)throw new Error("Transaction data too short for claimed signature count");if(r.length<100)throw new Error("Transaction too short");const s=Buffer.from(t,"base64").slice(1,65);return e3.encode(s)}var P5=Object.defineProperty,R5=Object.defineProperties,T5=Object.getOwnPropertyDescriptors,e0=Object.getOwnPropertySymbols,N5=Object.prototype.hasOwnProperty,C5=Object.prototype.propertyIsEnumerable,t0=(t,e,r)=>e in t?P5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,B5=(t,e)=>{for(var r in e||(e={}))N5.call(e,r)&&t0(t,r,e[r]);if(e0)for(var r of e0(e))C5.call(e,r)&&t0(t,r,e[r]);return t},F5=(t,e)=>R5(t,T5(e));const L5="did:pkh:",$c=t=>t?.split(":"),q5=t=>{const e=t&&$c(t);if(e)return t.includes(L5)?e[3]:e[1]},Dc=t=>{const e=t&&$c(t);if(e)return e[2]+":"+e[3]},mo=t=>{const e=t&&$c(t);if(e)return e.pop()};async function r0(t){const{cacao:e,projectId:r}=t,{s:i,p:n}=e,s=i0(n,n.iss),o=mo(n.iss);return await A5(o,s,i,Dc(n.iss),r)}const i0=(t,e)=>{const r=`${t.domain} wants you to sign in with your Ethereum account:`,i=mo(e);if(!t.aud&&!t.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let n=t.statement||void 0;const s=`URI: ${t.aud||t.uri}`,o=`Version: ${t.version}`,a=`Chain ID: ${q5(e)}`,c=`Nonce: ${t.nonce}`,f=`Issued At: ${t.iat}`,u=t.exp?`Expiration Time: ${t.exp}`:void 0,d=t.nbf?`Not Before: ${t.nbf}`:void 0,b=t.requestId?`Request ID: ${t.requestId}`:void 0,v=t.resources?`Resources:${t.resources.map(x=>`
19
- - ${x}`).join("")}`:void 0,g=wo(t.resources);if(g){const x=Jn(g);n=G5(n,x)}return[r,i,"",n,"",s,o,a,c,f,u,d,b,v].filter(x=>x!=null).join(`
20
- `)};function k5(t){return Buffer.from(JSON.stringify(t)).toString("base64")}function z5(t){return JSON.parse(Buffer.from(t,"base64").toString("utf-8"))}function $i(t){if(!t)throw new Error("No recap provided, value is undefined");if(!t.att)throw new Error("No `att` property found");const e=Object.keys(t.att);if(!(e!=null&&e.length))throw new Error("No resources found in `att` property");e.forEach(r=>{const i=t.att[r];if(Array.isArray(i))throw new Error(`Resource must be an object: ${r}`);if(typeof i!="object")throw new Error(`Resource must be an object: ${r}`);if(!Object.keys(i).length)throw new Error(`Resource object is empty: ${r}`);Object.keys(i).forEach(n=>{const s=i[n];if(!Array.isArray(s))throw new Error(`Ability limits ${n} must be an array of objects, found: ${s}`);if(!s.length)throw new Error(`Value of ${n} is empty array, must be an array with objects`);s.forEach(o=>{if(typeof o!="object")throw new Error(`Ability limits (${n}) must be an array of objects, found: ${o}`)})})})}function U5(t,e,r,i={}){return r?.sort((n,s)=>n.localeCompare(s)),{att:{[t]:j5(e,r,i)}}}function j5(t,e,r={}){e=e?.sort((n,s)=>n.localeCompare(s));const i=e.map(n=>({[`${t}/${n}`]:[r]}));return Object.assign({},...i)}function n0(t){return $i(t),`urn:recap:${k5(t).replace(/=/g,"")}`}function Jn(t){const e=z5(t.replace("urn:recap:",""));return $i(e),e}function V5(t,e,r){const i=U5(t,e,r);return n0(i)}function K5(t){return t&&t.includes("urn:recap:")}function H5(t,e){const r=Jn(t),i=Jn(e),n=W5(r,i);return n0(n)}function W5(t,e){$i(t),$i(e);const r=Object.keys(t.att).concat(Object.keys(e.att)).sort((n,s)=>n.localeCompare(s)),i={att:{}};return r.forEach(n=>{var s,o;Object.keys(((s=t.att)==null?void 0:s[n])||{}).concat(Object.keys(((o=e.att)==null?void 0:o[n])||{})).sort((a,c)=>a.localeCompare(c)).forEach(a=>{var c,f;i.att[n]=F5(B5({},i.att[n]),{[a]:((c=t.att[n])==null?void 0:c[a])||((f=e.att[n])==null?void 0:f[a])})})}),i}function G5(t="",e){$i(e);const r="I further authorize the stated URI to perform the following actions on my behalf: ";if(t.includes(r))return t;const i=[];let n=0;Object.keys(e.att).forEach(a=>{const c=Object.keys(e.att[a]).map(d=>({ability:d.split("/")[0],action:d.split("/")[1]}));c.sort((d,b)=>d.action.localeCompare(b.action));const f={};c.forEach(d=>{f[d.ability]||(f[d.ability]=[]),f[d.ability].push(d.action)});const u=Object.keys(f).map(d=>(n++,`(${n}) '${d}': '${f[d].join("', '")}' for '${a}'.`));i.push(u.join(", ").replace(".,","."))});const s=i.join(" "),o=`${r}${s}`;return`${t?t+" ":""}${o}`}function s0(t){var e;const r=Jn(t);$i(r);const i=(e=r.att)==null?void 0:e.eip155;return i?Object.keys(i).map(n=>n.split("/")[1]):[]}function o0(t){const e=Jn(t);$i(e);const r=[];return Object.values(e.att).forEach(i=>{Object.values(i).forEach(n=>{var s;(s=n?.[0])!=null&&s.chains&&r.push(n[0].chains)})}),[...new Set(r.flat())]}function wo(t){if(!t)return;const e=t?.[t.length-1];return K5(e)?e:void 0}function Oc(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function a0(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function qt(t,...e){if(!a0(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function c0(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Y5(t,e){qt(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function f0(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}const si=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),Z5=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function J5(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Mc(t){if(typeof t=="string")t=J5(t);else if(a0(t))t=Pc(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function X5(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function Q5(t,e){if(t.length!==e.length)return!1;let r=0;for(let i=0;i<t.length;i++)r|=t[i]^e[i];return r===0}const e9=(t,e)=>{function r(i,...n){if(qt(i),t.nonceLength!==void 0){const f=n[0];if(!f)throw new Error("nonce / iv required");t.varSizeNonce?qt(f):qt(f,t.nonceLength)}const s=t.tagLength;s&&n[1]!==void 0&&qt(n[1]);const o=e(i,...n),a=(f,u)=>{if(u!==void 0){if(f!==2)throw new Error("cipher output not supported");qt(u)}};let c=!1;return{encrypt(f,u){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,qt(f),a(o.encrypt.length,u),o.encrypt(f,u)},decrypt(f,u){if(qt(f),s&&f.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return a(o.decrypt.length,u),o.decrypt(f,u)}}}return Object.assign(r,t),r};function u0(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(e.length!==t)throw new Error("invalid output length, expected "+t+", got: "+e.length);if(r&&!t9(e))throw new Error("invalid output, must be aligned");return e}function h0(t,e,r,i){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,i);const n=BigInt(32),s=BigInt(4294967295),o=Number(r>>n&s),a=Number(r&s),c=i?4:0,f=i?0:4;t.setUint32(e+c,o,i),t.setUint32(e+f,a,i)}function t9(t){return t.byteOffset%4===0}function Pc(t){return Uint8Array.from(t)}function yn(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}const d0=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),r9=d0("expand 16-byte k"),i9=d0("expand 32-byte k"),n9=si(r9),s9=si(i9);function te(t,e){return t<<e|t>>>32-e}function Rc(t){return t.byteOffset%4===0}const _o=64,o9=16,l0=2**32-1,p0=new Uint32Array;function a9(t,e,r,i,n,s,o,a){const c=n.length,f=new Uint8Array(_o),u=si(f),d=Rc(n)&&Rc(s),b=d?si(n):p0,v=d?si(s):p0;for(let g=0;g<c;o++){if(t(e,r,i,u,o,a),o>=l0)throw new Error("arx: counter overflow");const x=Math.min(_o,c-g);if(d&&x===_o){const I=g/4;if(g%4!==0)throw new Error("arx: invalid block position");for(let D=0,O;D<o9;D++)O=I+D,v[O]=b[O]^u[D];g+=_o;continue}for(let I=0,D;I<x;I++)D=g+I,s[D]=n[D]^f[I];g+=x}}function c9(t,e){const{allowShortKeys:r,extendNonceFn:i,counterLength:n,counterRight:s,rounds:o}=X5({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Oc(n),Oc(o),f0(s),f0(r),(a,c,f,u,d=0)=>{qt(a),qt(c),qt(f);const b=f.length;if(u===void 0&&(u=new Uint8Array(b)),qt(u),Oc(d),d<0||d>=l0)throw new Error("arx: counter overflow");if(u.length<b)throw new Error(`arx: output (${u.length}) is shorter than data (${b})`);const v=[];let g=a.length,x,I;if(g===32)v.push(x=Pc(a)),I=s9;else if(g===16&&r)x=new Uint8Array(32),x.set(a),x.set(a,16),I=n9,v.push(x);else throw new Error(`arx: invalid 32-byte key, got length=${g}`);Rc(c)||v.push(c=Pc(c));const D=si(x);if(i){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");i(I,D,si(c.subarray(0,16)),D),c=c.subarray(16)}const O=16-n;if(O!==c.length)throw new Error(`arx: nonce must be ${O} or 16 bytes`);if(O!==12){const P=new Uint8Array(12);P.set(c,s?0:12-c.length),c=P,v.push(c)}const M=si(c);return a9(t,I,D,M,f,u,d,o),yn(...v),u}}const lt=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class f9{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=Mc(e),qt(e,32);const r=lt(e,0),i=lt(e,2),n=lt(e,4),s=lt(e,6),o=lt(e,8),a=lt(e,10),c=lt(e,12),f=lt(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|i<<3)&8191,this.r[2]=(i>>>10|n<<6)&7939,this.r[3]=(n>>>7|s<<9)&8191,this.r[4]=(s>>>4|o<<12)&255,this.r[5]=o>>>1&8190,this.r[6]=(o>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|f<<8)&8191,this.r[9]=f>>>5&127;for(let u=0;u<8;u++)this.pad[u]=lt(e,16+2*u)}process(e,r,i=!1){const n=i?0:2048,{h:s,r:o}=this,a=o[0],c=o[1],f=o[2],u=o[3],d=o[4],b=o[5],v=o[6],g=o[7],x=o[8],I=o[9],D=lt(e,r+0),O=lt(e,r+2),M=lt(e,r+4),P=lt(e,r+6),T=lt(e,r+8),N=lt(e,r+10),C=lt(e,r+12),B=lt(e,r+14);let R=s[0]+(D&8191),V=s[1]+((D>>>13|O<<3)&8191),A=s[2]+((O>>>10|M<<6)&8191),h=s[3]+((M>>>7|P<<9)&8191),p=s[4]+((P>>>4|T<<12)&8191),m=s[5]+(T>>>1&8191),y=s[6]+((T>>>14|N<<2)&8191),w=s[7]+((N>>>11|C<<5)&8191),S=s[8]+((C>>>8|B<<8)&8191),$=s[9]+(B>>>5|n),_=0,l=_+R*a+V*(5*I)+A*(5*x)+h*(5*g)+p*(5*v);_=l>>>13,l&=8191,l+=m*(5*b)+y*(5*d)+w*(5*u)+S*(5*f)+$*(5*c),_+=l>>>13,l&=8191;let E=_+R*c+V*a+A*(5*I)+h*(5*x)+p*(5*g);_=E>>>13,E&=8191,E+=m*(5*v)+y*(5*b)+w*(5*d)+S*(5*u)+$*(5*f),_+=E>>>13,E&=8191;let F=_+R*f+V*c+A*a+h*(5*I)+p*(5*x);_=F>>>13,F&=8191,F+=m*(5*g)+y*(5*v)+w*(5*b)+S*(5*d)+$*(5*u),_+=F>>>13,F&=8191;let L=_+R*u+V*f+A*c+h*a+p*(5*I);_=L>>>13,L&=8191,L+=m*(5*x)+y*(5*g)+w*(5*v)+S*(5*b)+$*(5*d),_+=L>>>13,L&=8191;let q=_+R*d+V*u+A*f+h*c+p*a;_=q>>>13,q&=8191,q+=m*(5*I)+y*(5*x)+w*(5*g)+S*(5*v)+$*(5*b),_+=q>>>13,q&=8191;let j=_+R*b+V*d+A*u+h*f+p*c;_=j>>>13,j&=8191,j+=m*a+y*(5*I)+w*(5*x)+S*(5*g)+$*(5*v),_+=j>>>13,j&=8191;let K=_+R*v+V*b+A*d+h*u+p*f;_=K>>>13,K&=8191,K+=m*c+y*a+w*(5*I)+S*(5*x)+$*(5*g),_+=K>>>13,K&=8191;let W=_+R*g+V*v+A*b+h*d+p*u;_=W>>>13,W&=8191,W+=m*f+y*c+w*a+S*(5*I)+$*(5*x),_+=W>>>13,W&=8191;let Z=_+R*x+V*g+A*v+h*b+p*d;_=Z>>>13,Z&=8191,Z+=m*u+y*f+w*c+S*a+$*(5*I),_+=Z>>>13,Z&=8191;let H=_+R*I+V*x+A*g+h*v+p*b;_=H>>>13,H&=8191,H+=m*d+y*u+w*f+S*c+$*a,_+=H>>>13,H&=8191,_=(_<<2)+_|0,_=_+l|0,l=_&8191,_=_>>>13,E+=_,s[0]=l,s[1]=E,s[2]=F,s[3]=L,s[4]=q,s[5]=j,s[6]=K,s[7]=W,s[8]=Z,s[9]=H}finalize(){const{h:e,pad:r}=this,i=new Uint16Array(10);let n=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=n,n=e[a]>>>13,e[a]&=8191;e[0]+=n*5,n=e[0]>>>13,e[0]&=8191,e[1]+=n,n=e[1]>>>13,e[1]&=8191,e[2]+=n,i[0]=e[0]+5,n=i[0]>>>13,i[0]&=8191;for(let a=1;a<10;a++)i[a]=e[a]+n,n=i[a]>>>13,i[a]&=8191;i[9]-=8192;let s=(n^1)-1;for(let a=0;a<10;a++)i[a]&=s;s=~s;for(let a=0;a<10;a++)e[a]=e[a]&s|i[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let o=e[0]+r[0];e[0]=o&65535;for(let a=1;a<8;a++)o=(e[a]+r[a]|0)+(o>>>16)|0,e[a]=o&65535;yn(i)}update(e){c0(this);const{buffer:r,blockLen:i}=this;e=Mc(e);const n=e.length;for(let s=0;s<n;){const o=Math.min(i-this.pos,n-s);if(o===i){for(;i<=n-s;s+=i)this.process(e,s);continue}r.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===i&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){yn(this.h,this.r,this.buffer,this.pad)}digestInto(e){c0(this),Y5(e,this),this.finished=!0;const{buffer:r,h:i}=this;let{pos:n}=this;if(n){for(r[n++]=1;n<16;n++)r[n]=0;this.process(r,0,!0)}this.finalize();let s=0;for(let o=0;o<8;o++)e[s++]=i[o]>>>0,e[s++]=i[o]>>>8;return e}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const i=e.slice(0,r);return this.destroy(),i}}function u9(t){const e=(i,n)=>t(n).update(Mc(i)).digest(),r=t(new Uint8Array(32));return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=i=>t(i),e}const h9=u9(t=>new f9(t));function d9(t,e,r,i,n,s=20){let o=t[0],a=t[1],c=t[2],f=t[3],u=e[0],d=e[1],b=e[2],v=e[3],g=e[4],x=e[5],I=e[6],D=e[7],O=n,M=r[0],P=r[1],T=r[2],N=o,C=a,B=c,R=f,V=u,A=d,h=b,p=v,m=g,y=x,w=I,S=D,$=O,_=M,l=P,E=T;for(let L=0;L<s;L+=2)N=N+V|0,$=te($^N,16),m=m+$|0,V=te(V^m,12),N=N+V|0,$=te($^N,8),m=m+$|0,V=te(V^m,7),C=C+A|0,_=te(_^C,16),y=y+_|0,A=te(A^y,12),C=C+A|0,_=te(_^C,8),y=y+_|0,A=te(A^y,7),B=B+h|0,l=te(l^B,16),w=w+l|0,h=te(h^w,12),B=B+h|0,l=te(l^B,8),w=w+l|0,h=te(h^w,7),R=R+p|0,E=te(E^R,16),S=S+E|0,p=te(p^S,12),R=R+p|0,E=te(E^R,8),S=S+E|0,p=te(p^S,7),N=N+A|0,E=te(E^N,16),w=w+E|0,A=te(A^w,12),N=N+A|0,E=te(E^N,8),w=w+E|0,A=te(A^w,7),C=C+h|0,$=te($^C,16),S=S+$|0,h=te(h^S,12),C=C+h|0,$=te($^C,8),S=S+$|0,h=te(h^S,7),B=B+p|0,_=te(_^B,16),m=m+_|0,p=te(p^m,12),B=B+p|0,_=te(_^B,8),m=m+_|0,p=te(p^m,7),R=R+V|0,l=te(l^R,16),y=y+l|0,V=te(V^y,12),R=R+V|0,l=te(l^R,8),y=y+l|0,V=te(V^y,7);let F=0;i[F++]=o+N|0,i[F++]=a+C|0,i[F++]=c+B|0,i[F++]=f+R|0,i[F++]=u+V|0,i[F++]=d+A|0,i[F++]=b+h|0,i[F++]=v+p|0,i[F++]=g+m|0,i[F++]=x+y|0,i[F++]=I+w|0,i[F++]=D+S|0,i[F++]=O+$|0,i[F++]=M+_|0,i[F++]=P+l|0,i[F++]=T+E|0}const l9=c9(d9,{counterRight:!1,counterLength:4,allowShortKeys:!1}),p9=new Uint8Array(16),b0=(t,e)=>{t.update(e);const r=e.length%16;r&&t.update(p9.subarray(r))},b9=new Uint8Array(32);function g0(t,e,r,i,n){const s=t(e,r,b9),o=h9.create(s);n&&b0(o,n),b0(o,i);const a=new Uint8Array(16),c=Z5(a);h0(c,0,BigInt(n?n.length:0),!0),h0(c,8,BigInt(i.length),!0),o.update(a);const f=o.digest();return yn(s,a),f}const g9=t=>(e,r,i)=>({encrypt(n,s){const o=n.length;s=u0(o+16,s,!1),s.set(n);const a=s.subarray(0,-16);t(e,r,a,a,1);const c=g0(t,e,r,a,i);return s.set(c,o),yn(c),s},decrypt(n,s){s=u0(n.length-16,s,!1);const o=n.subarray(0,-16),a=n.subarray(-16),c=g0(t,e,r,o,i);if(!Q5(a,c))throw new Error("invalid tag");return s.set(n.subarray(0,-16)),t(e,r,s,s,1),yn(c),s}}),y0=e9({blockSize:64,nonceLength:12,tagLength:16},g9(l9));class v0 extends Ic{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Ec(e);const i=gn(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const n=this.blockLen,s=new Uint8Array(n);s.set(i.length>n?e.create().update(i).digest():i);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(e){return pn(this),this.iHash.update(e),this}digestInto(e){pn(this),yo(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:i,finished:n,destroyed:s,blockLen:o,outputLen:a}=this;return e=e,e.finished=n,e.destroyed=s,e.blockLen=o,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=i._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Tc=(t,e,r)=>new v0(t,e).update(r).digest();Tc.create=(t,e)=>new v0(t,e);function y9(t,e,r){return Ec(t),r===void 0&&(r=new Uint8Array(t.outputLen)),Tc(t,gn(r),gn(e))}const Nc=new Uint8Array([0]),m0=new Uint8Array;function v9(t,e,r,i=32){if(Ec(t),Gn(i),i>255*t.outputLen)throw new Error("Length should be <= 255*HashLen");const n=Math.ceil(i/t.outputLen);r===void 0&&(r=m0);const s=new Uint8Array(n*t.outputLen),o=Tc.create(t,e),a=o._cloneInto(),c=new Uint8Array(o.outputLen);for(let f=0;f<n;f++)Nc[0]=f+1,a.update(f===0?m0:c).update(r).update(Nc).digestInto(c),s.set(c,t.outputLen*f),o._cloneInto(a);return o.destroy(),a.destroy(),c.fill(0),Nc.fill(0),s.slice(0,i)}const m9=(t,e,r,i,n)=>v9(t,y9(t,e,r),i,n);function w9(t,e,r,i){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,i);const n=BigInt(32),s=BigInt(4294967295),o=Number(r>>n&s),a=Number(r&s),c=i?4:0,f=i?0:4;t.setUint32(e+c,o,i),t.setUint32(e+f,a,i)}function _9(t,e,r){return t&e^~t&r}function x9(t,e,r){return t&e^t&r^e&r}class E9 extends Ic{constructor(e,r,i,n){super(),this.blockLen=e,this.outputLen=r,this.padOffset=i,this.isLE=n,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Sc(this.buffer)}update(e){pn(this);const{view:r,buffer:i,blockLen:n}=this;e=gn(e);const s=e.length;for(let o=0;o<s;){const a=Math.min(n-this.pos,s-o);if(a===n){const c=Sc(e);for(;n<=s-o;o+=n)this.process(c,o);continue}i.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===n&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){pn(this),jl(e,this),this.finished=!0;const{buffer:r,view:i,blockLen:n,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>n-o&&(this.process(i,0),o=0);for(let d=o;d<n;d++)r[d]=0;w9(i,n-8,BigInt(this.length*8),s),this.process(i,0);const a=Sc(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<f;d++)a.setUint32(4*d,u[d],s)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const i=e.slice(0,r);return this.destroy(),i}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:r,buffer:i,length:n,finished:s,destroyed:o,pos:a}=this;return e.length=n,e.pos=a,e.finished=s,e.destroyed=o,n%r&&e.buffer.set(i),e}}const S9=new Uint32Array([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]),oi=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ai=new Uint32Array(64);class I9 extends E9{constructor(){super(64,32,8,!1),this.A=oi[0]|0,this.B=oi[1]|0,this.C=oi[2]|0,this.D=oi[3]|0,this.E=oi[4]|0,this.F=oi[5]|0,this.G=oi[6]|0,this.H=oi[7]|0}get(){const{A:e,B:r,C:i,D:n,E:s,F:o,G:a,H:c}=this;return[e,r,i,n,s,o,a,c]}set(e,r,i,n,s,o,a,c){this.A=e|0,this.B=r|0,this.C=i|0,this.D=n|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let d=0;d<16;d++,r+=4)ai[d]=e.getUint32(r,!1);for(let d=16;d<64;d++){const b=ai[d-15],v=ai[d-2],g=wr(b,7)^wr(b,18)^b>>>3,x=wr(v,17)^wr(v,19)^v>>>10;ai[d]=x+ai[d-7]+g+ai[d-16]|0}let{A:i,B:n,C:s,D:o,E:a,F:c,G:f,H:u}=this;for(let d=0;d<64;d++){const b=wr(a,6)^wr(a,11)^wr(a,25),v=u+b+_9(a,c,f)+S9[d]+ai[d]|0,g=(wr(i,2)^wr(i,13)^wr(i,22))+x9(i,n,s)|0;u=f,f=c,c=a,a=o+v|0,o=s,s=n,n=i,i=v+g|0}i=i+this.A|0,n=n+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,u=u+this.H|0,this.set(i,n,s,o,a,c,f,u)}roundClean(){ai.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const xo=Wl(()=>new I9);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const w0=BigInt(0);function Cc(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function _0(t){if(!Cc(t))throw new Error("Uint8Array expected")}const A9=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function $9(t){_0(t);let e="";for(let r=0;r<t.length;r++)e+=A9[t[r]];return e}function D9(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?w0:BigInt("0x"+t)}const Lr={_0:48,_9:57,A:65,F:70,a:97,f:102};function x0(t){if(t>=Lr._0&&t<=Lr._9)return t-Lr._0;if(t>=Lr.A&&t<=Lr.F)return t-(Lr.A-10);if(t>=Lr.a&&t<=Lr.f)return t-(Lr.a-10)}function E0(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const i=new Uint8Array(r);for(let n=0,s=0;n<r;n++,s+=2){const o=x0(t.charCodeAt(s)),a=x0(t.charCodeAt(s+1));if(o===void 0||a===void 0){const c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}i[n]=o*16+a}return i}function S0(t){return _0(t),D9($9(Uint8Array.from(t).reverse()))}function O9(t,e){return E0(t.toString(16).padStart(e*2,"0"))}function M9(t,e){return O9(t,e).reverse()}function I0(t,e,r){let i;if(typeof e=="string")try{i=E0(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Cc(e))i=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const n=i.length;if(typeof r=="number"&&n!==r)throw new Error(t+" of length "+r+" expected, got "+n);return i}const Bc=t=>typeof t=="bigint"&&w0<=t;function P9(t,e,r){return Bc(t)&&Bc(e)&&Bc(r)&&e<=t&&t<r}function A0(t,e,r,i){if(!P9(e,r,i))throw new Error("expected valid "+t+": "+r+" <= n < "+i+", got "+e)}const R9={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||Cc(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function T9(t,e,r={}){const i=(n,s,o)=>{const a=R9[s];if(typeof a!="function")throw new Error("invalid validator function");const c=t[n];if(!(o&&c===void 0)&&!a(c,t))throw new Error("param "+String(n)+" is invalid. Expected "+s+", got "+c)};for(const[n,s]of Object.entries(e))i(n,s,!1);for(const[n,s]of Object.entries(r))i(n,s,!0);return t}const vn=BigInt(0),Eo=BigInt(1);function $0(t,e){const r=t%e;return r>=vn?r:e+r}function N9(t,e,r){if(e<vn)throw new Error("invalid exponent, negatives unsupported");if(r<=vn)throw new Error("invalid modulus");if(r===Eo)return vn;let i=Eo;for(;e>vn;)e&Eo&&(i=i*t%r),t=t*t%r,e>>=Eo;return i}function rr(t,e,r){let i=t;for(;e-- >vn;)i*=i,i%=r;return i}BigInt(0),BigInt(1),BigInt(0),BigInt(1),BigInt(2),BigInt(8);const mn=BigInt(0),Fc=BigInt(1);function C9(t){return T9(t,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...t})}function B9(t){const e=C9(t),{P:r}=e,i=O=>$0(O,r),n=e.montgomeryBits,s=Math.ceil(n/8),o=e.nByteLength,a=e.adjustScalarBytes||(O=>O),c=e.powPminus2||(O=>N9(O,r-BigInt(2),r));function f(O,M,P){const T=i(O*(M-P));return M=i(M-T),P=i(P+T),[M,P]}const u=(e.a-BigInt(2))/BigInt(4);function d(O,M){A0("u",O,mn,r),A0("scalar",M,mn,r);const P=M,T=O;let N=Fc,C=mn,B=O,R=Fc,V=mn,A;for(let p=BigInt(n-1);p>=mn;p--){const m=P>>p&Fc;V^=m,A=f(V,N,B),N=A[0],B=A[1],A=f(V,C,R),C=A[0],R=A[1],V=m;const y=N+C,w=i(y*y),S=N-C,$=i(S*S),_=w-$,l=B+R,E=B-R,F=i(E*y),L=i(l*S),q=F+L,j=F-L;B=i(q*q),R=i(T*i(j*j)),N=i(w*$),C=i(_*(w+i(u*_)))}A=f(V,N,B),N=A[0],B=A[1],A=f(V,C,R),C=A[0],R=A[1];const h=c(C);return i(N*h)}function b(O){return M9(i(O),s)}function v(O){const M=I0("u coordinate",O,s);return o===32&&(M[31]&=127),S0(M)}function g(O){const M=I0("scalar",O),P=M.length;if(P!==s&&P!==o){let T=""+s+" or "+o;throw new Error("invalid scalar, expected "+T+" bytes, got "+P)}return S0(a(M))}function x(O,M){const P=v(M),T=g(O),N=d(P,T);if(N===mn)throw new Error("invalid private or public key received");return b(N)}const I=b(e.Gu);function D(O){return x(O,I)}return{scalarMult:x,scalarMultBase:D,getSharedSecret:(O,M)=>x(O,M),getPublicKey:O=>D(O),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:I}}const Lc=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949");BigInt(0);const F9=BigInt(1),D0=BigInt(2),L9=BigInt(3),q9=BigInt(5);BigInt(8);function k9(t){const e=BigInt(10),r=BigInt(20),i=BigInt(40),n=BigInt(80),s=Lc,o=t*t%s*t%s,a=rr(o,D0,s)*o%s,c=rr(a,F9,s)*t%s,f=rr(c,q9,s)*c%s,u=rr(f,e,s)*f%s,d=rr(u,r,s)*u%s,b=rr(d,i,s)*d%s,v=rr(b,n,s)*b%s,g=rr(v,n,s)*b%s,x=rr(g,e,s)*f%s;return{pow_p_5_8:rr(x,D0,s)*t%s,b2:o}}function z9(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const qc=B9({P:Lc,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:t=>{const e=Lc,{pow_p_5_8:r,b2:i}=k9(t);return $0(rr(r,L9,e)*i,e)},adjustScalarBytes:z9,randomBytes:Yn}),O0="base10",xt="base16",ci="base64pad",Xn="base64url",Qn="utf8",M0=0,qr=1,es=2,U9=0,P0=1,ts=12,kc=32;function j9(){const t=qc.utils.randomPrivateKey(),e=qc.getPublicKey(t);return{privateKey:$t(t,xt),publicKey:$t(e,xt)}}function zc(){const t=Yn(kc);return $t(t,xt)}function V9(t,e){const r=qc.getSharedSecret(jt(t,xt),jt(e,xt)),i=m9(xo,r,void 0,void 0,kc);return $t(i,xt)}function So(t){const e=xo(jt(t,xt));return $t(e,xt)}function _r(t){const e=xo(jt(t,Qn));return $t(e,xt)}function R0(t){return jt(`${t}`,O0)}function Di(t){return Number($t(t,O0))}function K9(t){const e=R0(typeof t.type<"u"?t.type:M0);if(Di(e)===qr&&typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const r=typeof t.senderPublicKey<"u"?jt(t.senderPublicKey,xt):void 0,i=typeof t.iv<"u"?jt(t.iv,xt):Yn(ts),n=jt(t.symKey,xt),s=y0(n,i).encrypt(jt(t.message,Qn));return T0({type:e,sealed:s,iv:i,senderPublicKey:r,encoding:t.encoding})}function H9(t){const e=jt(t.symKey,xt),{sealed:r,iv:i}=rs(t),n=y0(e,i).decrypt(r);if(n===null)throw new Error("Failed to decrypt");return $t(n,Qn)}function W9(t,e){const r=R0(es),i=Yn(ts),n=jt(t,Qn);return T0({type:r,sealed:n,iv:i,encoding:e})}function G9(t,e){const{sealed:r}=rs({encoded:t,encoding:e});return $t(r,Qn)}function T0(t){const{encoding:e=ci}=t;if(Di(t.type)===es)return $t(ec([t.type,t.sealed]),e);if(Di(t.type)===qr){if(typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return $t(ec([t.type,t.senderPublicKey,t.iv,t.sealed]),e)}return $t(ec([t.type,t.iv,t.sealed]),e)}function rs(t){const{encoded:e,encoding:r=ci}=t,i=jt(e,r),n=i.slice(U9,P0),s=P0;if(Di(n)===qr){const f=s+kc,u=f+ts,d=i.slice(s,f),b=i.slice(f,u),v=i.slice(u);return{type:n,sealed:v,iv:b,senderPublicKey:d}}if(Di(n)===es){const f=i.slice(s),u=Yn(ts);return{type:n,sealed:f,iv:u}}const o=s+ts,a=i.slice(s,o),c=i.slice(o);return{type:n,sealed:c,iv:a}}function Y9(t,e){const r=rs({encoded:t,encoding:e?.encoding});return N0({type:Di(r.type),senderPublicKey:typeof r.senderPublicKey<"u"?$t(r.senderPublicKey,xt):void 0,receiverPublicKey:e?.receiverPublicKey})}function N0(t){const e=t?.type||M0;if(e===qr){if(typeof t?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof t?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:e,senderPublicKey:t?.senderPublicKey,receiverPublicKey:t?.receiverPublicKey}}function C0(t){return t.type===qr&&typeof t.senderPublicKey=="string"&&typeof t.receiverPublicKey=="string"}function B0(t){return t.type===es}function Z9(t){return new Jd.ec("p256").keyFromPublic({x:Buffer.from(t.x,"base64").toString("hex"),y:Buffer.from(t.y,"base64").toString("hex")},"hex")}function J9(t){let e=t.replace(/-/g,"+").replace(/_/g,"/");const r=e.length%4;return r>0&&(e+="=".repeat(4-r)),e}function X9(t){return Buffer.from(J9(t),"base64")}function Q9(t,e){const[r,i,n]=t.split("."),s=X9(n);if(s.length!==64)throw new Error("Invalid signature length");const o=s.slice(0,32).toString("hex"),a=s.slice(32,64).toString("hex"),c=`${r}.${i}`,f=xo(c),u=Z9(e),d=$t(f,xt);if(!u.verify(d,{r:o,s:a}))throw new Error("Invalid signature");return _a(t).payload}const e7="irn";function Io(t){return t?.relay||{protocol:e7}}function is(t){const e=L4[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}function t7(t,e="-"){const r={},i="relay"+e;return Object.keys(t).forEach(n=>{if(n.startsWith(i)){const s=n.replace(i,""),o=t[n];r[s]=o}}),r}function F0(t){if(!t.includes("wc:")){const f=Ul(t);f!=null&&f.includes("wc:")&&(t=f)}t=t.includes("wc://")?t.replace("wc://",""):t,t=t.includes("wc:")?t.replace("wc:",""):t;const e=t.indexOf(":"),r=t.indexOf("?")!==-1?t.indexOf("?"):void 0,i=t.substring(0,e),n=t.substring(e+1,r).split("@"),s=typeof r<"u"?t.substring(r):"",o=new URLSearchParams(s),a={};o.forEach((f,u)=>{a[u]=f});const c=typeof a.methods=="string"?a.methods.split(","):void 0;return{protocol:i,topic:r7(n[0]),version:parseInt(n[1],10),symKey:a.symKey,relay:t7(a),methods:c,expiryTimestamp:a.expiryTimestamp?parseInt(a.expiryTimestamp,10):void 0}}function r7(t){return t.startsWith("//")?t.substring(2):t}function i7(t,e="-"){const r="relay",i={};return Object.keys(t).forEach(n=>{const s=n,o=r+e+s;t[s]&&(i[o]=t[s])}),i}function L0(t){const e=new URLSearchParams,r=i7(t.relay);Object.keys(r).sort().forEach(n=>{e.set(n,r[n])}),e.set("symKey",t.symKey),t.expiryTimestamp&&e.set("expiryTimestamp",t.expiryTimestamp.toString()),t.methods&&e.set("methods",t.methods.join(","));const i=e.toString();return`${t.protocol}:${t.topic}@${t.version}?${i}`}function Ao(t,e,r){return`${t}?wc_ev=${r}&topic=${e}`}function wn(t){const e=[];return t.forEach(r=>{const[i,n]=r.split(":");e.push(`${i}:${n}`)}),e}function n7(t){const e=[];return Object.values(t).forEach(r=>{e.push(...wn(r.accounts))}),e}function s7(t,e){const r=[];return Object.values(t).forEach(i=>{wn(i.accounts).includes(e)&&r.push(...i.methods)}),r}function o7(t,e){const r=[];return Object.values(t).forEach(i=>{wn(i.accounts).includes(e)&&r.push(...i.events)}),r}function a7(t){const e={};return t?.forEach(r=>{var i;const[n,s]=r.split(":");e[n]||(e[n]={accounts:[],chains:[],events:[],methods:[]}),e[n].accounts.push(r),(i=e[n].chains)==null||i.push(`${n}:${s}`)}),e}function q0(t,e){e=e.map(i=>i.replace("did:pkh:",""));const r=a7(e);for(const[i,n]of Object.entries(r))n.methods?n.methods=Z4(n.methods,t):n.methods=t,n.events=["chainChanged","accountsChanged"];return r}const c7={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}},f7={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 U(t,e){const{message:r,code:i}=f7[t];return{message:e?`${r} ${e}`:r,code:i}}function de(t,e){const{message:r,code:i}=c7[t];return{message:e?`${r} ${e}`:r,code:i}}function ns(t,e){return Array.isArray(t)?typeof e<"u"&&t.length?t.every(e):!0:!1}function $o(t){return Object.getPrototypeOf(t)===Object.prototype&&Object.keys(t).length}function pt(t){return typeof t>"u"}function De(t,e){return e&&pt(t)?!0:typeof t=="string"&&!!t.trim().length}function Uc(t,e){return e&&pt(t)?!0:typeof t=="number"&&!isNaN(t)}function u7(t,e){const{requiredNamespaces:r}=e,i=Object.keys(t.namespaces),n=Object.keys(r);let s=!0;return Ii(n,i)?(i.forEach(o=>{const{accounts:a,methods:c,events:f}=t.namespaces[o],u=wn(a),d=r[o];(!Ii(Nl(o,d),u)||!Ii(d.methods,c)||!Ii(d.events,f))&&(s=!1)}),s):!1}function Do(t){return De(t,!1)&&t.includes(":")?t.split(":").length===2:!1}function h7(t){if(De(t,!1)&&t.includes(":")){const e=t.split(":");if(e.length===3){const r=e[0]+":"+e[1];return!!e[2]&&Do(r)}}return!1}function d7(t){function e(r){try{return typeof new URL(r)<"u"}catch{return!1}}try{if(De(t,!1)){if(e(t))return!0;const r=Ul(t);return e(r)}}catch{}return!1}function l7(t){var e;return(e=t?.proposer)==null?void 0:e.publicKey}function p7(t){return t?.topic}function b7(t,e){let r=null;return De(t?.publicKey,!1)||(r=U("MISSING_OR_INVALID",`${e} controller public key should be a string`)),r}function k0(t){let e=!0;return ns(t)?t.length&&(e=t.every(r=>De(r,!1))):e=!1,e}function g7(t,e,r){let i=null;return ns(e)&&e.length?e.forEach(n=>{i||Do(n)||(i=de("UNSUPPORTED_CHAINS",`${r}, chain ${n} should be a string and conform to "namespace:chainId" format`))}):Do(t)||(i=de("UNSUPPORTED_CHAINS",`${r}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),i}function y7(t,e,r){let i=null;return Object.entries(t).forEach(([n,s])=>{if(i)return;const o=g7(n,Nl(n,s),`${e} ${r}`);o&&(i=o)}),i}function v7(t,e){let r=null;return ns(t)?t.forEach(i=>{r||h7(i)||(r=de("UNSUPPORTED_ACCOUNTS",`${e}, account ${i} should be a string and conform to "namespace:chainId:address" format`))}):r=de("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),r}function m7(t,e){let r=null;return Object.values(t).forEach(i=>{if(r)return;const n=v7(i?.accounts,`${e} namespace`);n&&(r=n)}),r}function w7(t,e){let r=null;return k0(t?.methods)?k0(t?.events)||(r=de("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):r=de("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),r}function z0(t,e){let r=null;return Object.values(t).forEach(i=>{if(r)return;const n=w7(i,`${e}, namespace`);n&&(r=n)}),r}function _7(t,e,r){let i=null;if(t&&$o(t)){const n=z0(t,e);n&&(i=n);const s=y7(t,e,r);s&&(i=s)}else i=U("MISSING_OR_INVALID",`${e}, ${r} should be an object with data`);return i}function jc(t,e){let r=null;if(t&&$o(t)){const i=z0(t,e);i&&(r=i);const n=m7(t,e);n&&(r=n)}else r=U("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return r}function U0(t){return De(t.protocol,!0)}function x7(t,e){let r=!1;return e&&!t?r=!0:t&&ns(t)&&t.length&&t.forEach(i=>{r=U0(i)}),r}function E7(t){return typeof t=="number"}function Nt(t){return typeof t<"u"&&typeof t!==null}function S7(t){return!(!t||typeof t!="object"||!t.code||!Uc(t.code,!1)||!t.message||!De(t.message,!1))}function I7(t){return!(pt(t)||!De(t.method,!1))}function A7(t){return!(pt(t)||pt(t.result)&&pt(t.error)||!Uc(t.id,!1)||!De(t.jsonrpc,!1))}function $7(t){return!(pt(t)||!De(t.name,!1))}function j0(t,e){return!(!Do(e)||!n7(t).includes(e))}function D7(t,e,r){return De(r,!1)?s7(t,e).includes(r):!1}function O7(t,e,r){return De(r,!1)?o7(t,e).includes(r):!1}function V0(t,e,r){let i=null;const n=M7(t),s=P7(e),o=Object.keys(n),a=Object.keys(s),c=K0(Object.keys(t)),f=K0(Object.keys(e)),u=c.filter(d=>!f.includes(d));return u.length&&(i=U("NON_CONFORMING_NAMESPACES",`${r} namespaces keys don't satisfy requiredNamespaces.
21
- Required: ${u.toString()}
22
- Received: ${Object.keys(e).toString()}`)),Ii(o,a)||(i=U("NON_CONFORMING_NAMESPACES",`${r} namespaces chains don't satisfy required namespaces.
14
+ ***************************************************************************** */var hs=function(t,e){return hs=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var i in n)n.hasOwnProperty(i)&&(r[i]=n[i])},hs(t,e)};function Jf(t,e){hs(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}var ds=function(){return ds=Object.assign||function(e){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},ds.apply(this,arguments)};function Xf(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r}function Qf(t,e,r,n){var i=arguments.length,s=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,r,s):o(e,r))||s);return i>3&&s&&Object.defineProperty(e,r,s),s}function ep(t,e){return function(r,n){e(r,n,t)}}function tp(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function rp(t,e,r,n){function i(s){return s instanceof r?s:new r(function(o){o(s)})}return new(r||(r=Promise))(function(s,o){function a(l){try{u(n.next(l))}catch(h){o(h)}}function c(l){try{u(n.throw(l))}catch(h){o(h)}}function u(l){l.done?s(l.value):i(l.value).then(a,c)}u((n=n.apply(t,e||[])).next())})}function np(t,e){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(u){return function(l){return c([u,l])}}function c(u){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(s=u[0]&2?i.return:u[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,u[1])).done)return s;switch(i=0,s&&(u=[u[0]&2,s.value]),u[0]){case 0:case 1:s=u;break;case 4:return r.label++,{value:u[1],done:!1};case 5:r.label++,i=u[1],u=[0];continue;case 7:u=r.ops.pop(),r.trys.pop();continue;default:if(s=r.trys,!(s=s.length>0&&s[s.length-1])&&(u[0]===6||u[0]===2)){r=0;continue}if(u[0]===3&&(!s||u[1]>s[0]&&u[1]<s[3])){r.label=u[1];break}if(u[0]===6&&r.label<s[1]){r.label=s[1],s=u;break}if(s&&r.label<s[2]){r.label=s[2],r.ops.push(u);break}s[2]&&r.ops.pop(),r.trys.pop();continue}u=e.call(t,r)}catch(l){u=[6,l],i=0}finally{n=s=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function ip(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}function sp(t,e){for(var r in t)r!=="default"&&!e.hasOwnProperty(r)&&(e[r]=t[r])}function fs(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function Ja(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return s}function op(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(Ja(arguments[e]));return t}function ap(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),i=0,e=0;e<r;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,i++)n[i]=s[o];return n}function fn(t){return this instanceof fn?(this.v=t,this):new fn(t)}function cp(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,s=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(d){n[d]&&(i[d]=function(p){return new Promise(function(f,y){s.push([d,p,f,y])>1||a(d,p)})})}function a(d,p){try{c(n[d](p))}catch(f){h(s[0][3],f)}}function c(d){d.value instanceof fn?Promise.resolve(d.value.v).then(u,l):h(s[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function h(d,p){d(p),s.shift(),s.length&&a(s[0][0],s[0][1])}}function up(t){var e,r;return e={},n("next"),n("throw",function(i){throw i}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(i,s){e[i]=t[i]?function(o){return(r=!r)?{value:fn(t[i](o)),done:i==="return"}:s?s(o):o}:s}}function lp(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof fs=="function"?fs(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(s){r[s]=t[s]&&function(o){return new Promise(function(a,c){o=t[s](o),i(a,c,o.done,o.value)})}}function i(s,o,a,c){Promise.resolve(c).then(function(u){s({value:u,done:a})},o)}}function hp(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function dp(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function fp(t){return t&&t.__esModule?t:{default:t}}function pp(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function gp(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}var yp=Object.freeze({__proto__:null,__extends:Jf,get __assign(){return ds},__rest:Xf,__decorate:Qf,__param:ep,__metadata:tp,__awaiter:rp,__generator:np,__createBinding:ip,__exportStar:sp,__values:fs,__read:Ja,__spread:op,__spreadArrays:ap,__await:fn,__asyncGenerator:cp,__asyncDelegator:up,__asyncValues:lp,__makeTemplateObject:hp,__importStar:dp,__importDefault:fp,__classPrivateFieldGet:pp,__classPrivateFieldSet:gp}),ci=ka(yp),ps={},pn={},Xa;function wp(){if(Xa)return pn;Xa=1,Object.defineProperty(pn,"__esModule",{value:!0}),pn.delay=void 0;function t(e){return new Promise(r=>{setTimeout(()=>{r(!0)},e)})}return pn.delay=t,pn}var cr={},gs={},ur={},Qa;function mp(){return Qa||(Qa=1,Object.defineProperty(ur,"__esModule",{value:!0}),ur.ONE_THOUSAND=ur.ONE_HUNDRED=void 0,ur.ONE_HUNDRED=100,ur.ONE_THOUSAND=1e3),ur}var ys={},ec;function bp(){return ec||(ec=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.ONE_YEAR=t.FOUR_WEEKS=t.THREE_WEEKS=t.TWO_WEEKS=t.ONE_WEEK=t.THIRTY_DAYS=t.SEVEN_DAYS=t.FIVE_DAYS=t.THREE_DAYS=t.ONE_DAY=t.TWENTY_FOUR_HOURS=t.TWELVE_HOURS=t.SIX_HOURS=t.THREE_HOURS=t.ONE_HOUR=t.SIXTY_MINUTES=t.THIRTY_MINUTES=t.TEN_MINUTES=t.FIVE_MINUTES=t.ONE_MINUTE=t.SIXTY_SECONDS=t.THIRTY_SECONDS=t.TEN_SECONDS=t.FIVE_SECONDS=t.ONE_SECOND=void 0,t.ONE_SECOND=1,t.FIVE_SECONDS=5,t.TEN_SECONDS=10,t.THIRTY_SECONDS=30,t.SIXTY_SECONDS=60,t.ONE_MINUTE=t.SIXTY_SECONDS,t.FIVE_MINUTES=t.ONE_MINUTE*5,t.TEN_MINUTES=t.ONE_MINUTE*10,t.THIRTY_MINUTES=t.ONE_MINUTE*30,t.SIXTY_MINUTES=t.ONE_MINUTE*60,t.ONE_HOUR=t.SIXTY_MINUTES,t.THREE_HOURS=t.ONE_HOUR*3,t.SIX_HOURS=t.ONE_HOUR*6,t.TWELVE_HOURS=t.ONE_HOUR*12,t.TWENTY_FOUR_HOURS=t.ONE_HOUR*24,t.ONE_DAY=t.TWENTY_FOUR_HOURS,t.THREE_DAYS=t.ONE_DAY*3,t.FIVE_DAYS=t.ONE_DAY*5,t.SEVEN_DAYS=t.ONE_DAY*7,t.THIRTY_DAYS=t.ONE_DAY*30,t.ONE_WEEK=t.SEVEN_DAYS,t.TWO_WEEKS=t.ONE_WEEK*2,t.THREE_WEEKS=t.ONE_WEEK*3,t.FOUR_WEEKS=t.ONE_WEEK*4,t.ONE_YEAR=t.ONE_DAY*365}(ys)),ys}var tc;function rc(){return tc||(tc=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=ci;e.__exportStar(mp(),t),e.__exportStar(bp(),t)}(gs)),gs}var nc;function vp(){if(nc)return cr;nc=1,Object.defineProperty(cr,"__esModule",{value:!0}),cr.fromMiliseconds=cr.toMiliseconds=void 0;const t=rc();function e(n){return n*t.ONE_THOUSAND}cr.toMiliseconds=e;function r(n){return Math.floor(n/t.ONE_THOUSAND)}return cr.fromMiliseconds=r,cr}var ic;function Ep(){return ic||(ic=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=ci;e.__exportStar(wp(),t),e.__exportStar(vp(),t)}(ps)),ps}var Rr={},sc;function _p(){if(sc)return Rr;sc=1,Object.defineProperty(Rr,"__esModule",{value:!0}),Rr.Watch=void 0;class t{constructor(){this.timestamps=new Map}start(r){if(this.timestamps.has(r))throw new Error(`Watch already started for label: ${r}`);this.timestamps.set(r,{started:Date.now()})}stop(r){const n=this.get(r);if(typeof n.elapsed<"u")throw new Error(`Watch already stopped for label: ${r}`);const i=Date.now()-n.started;this.timestamps.set(r,{started:n.started,elapsed:i})}get(r){const n=this.timestamps.get(r);if(typeof n>"u")throw new Error(`No timestamp found for label: ${r}`);return n}elapsed(r){const n=this.get(r);return n.elapsed||Date.now()-n.started}}return Rr.Watch=t,Rr.default=t,Rr}var ws={},gn={},oc;function Sp(){if(oc)return gn;oc=1,Object.defineProperty(gn,"__esModule",{value:!0}),gn.IWatch=void 0;class t{}return gn.IWatch=t,gn}var ac;function xp(){return ac||(ac=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),ci.__exportStar(Sp(),t)}(ws)),ws}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=ci;e.__exportStar(Ep(),t),e.__exportStar(_p(),t),e.__exportStar(xp(),t),e.__exportStar(rc(),t)})(L);class lr{}class Ip extends lr{constructor(e){super()}}const cc=L.FIVE_SECONDS,Cr={pulse:"heartbeat_pulse"};class ms extends Ip{constructor(e){super(e),this.events=new Le.exports.EventEmitter,this.interval=cc,this.interval=e?.interval||cc}static async init(e){const r=new ms(e);return await r.init(),r}async init(){await this.initialize()}stop(){clearInterval(this.intervalRef)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async initialize(){this.intervalRef=setInterval(()=>this.pulse(),L.toMiliseconds(this.interval))}pulse(){this.events.emit(Cr.pulse)}}const Dp=/"(?:_|\\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*:/,Op=/"(?: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*:/,$p=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function Ap(t,e){if(t==="__proto__"||t==="constructor"&&e&&typeof e=="object"&&"prototype"in e){Pp(t);return}return e}function Pp(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}function ui(t,e={}){if(typeof t!="string")return t;const r=t.trim();if(t[0]==='"'&&t.endsWith('"')&&!t.includes("\\"))return r.slice(1,-1);if(r.length<=9){const n=r.toLowerCase();if(n==="true")return!0;if(n==="false")return!1;if(n==="undefined")return;if(n==="null")return null;if(n==="nan")return Number.NaN;if(n==="infinity")return Number.POSITIVE_INFINITY;if(n==="-infinity")return Number.NEGATIVE_INFINITY}if(!$p.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(Dp.test(t)||Op.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,Ap)}return JSON.parse(t)}catch(n){if(e.strict)throw n;return t}}function Tp(t){return!t||typeof t.then!="function"?Promise.resolve(t):t}function be(t,...e){try{return Tp(t(...e))}catch(r){return Promise.reject(r)}}function Rp(t){const e=typeof t;return t===null||e!=="object"&&e!=="function"}function Cp(t){const e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}function li(t){if(Rp(t))return String(t);if(Cp(t)||Array.isArray(t))return JSON.stringify(t);if(typeof t.toJSON=="function")return li(t.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function uc(){if(typeof Buffer>"u")throw new TypeError("[unstorage] Buffer is not supported!")}const bs="base64:";function Np(t){if(typeof t=="string")return t;uc();const e=Buffer.from(t).toString("base64");return bs+e}function Bp(t){return typeof t!="string"||!t.startsWith(bs)?t:(uc(),Buffer.from(t.slice(bs.length),"base64"))}function Ke(t){return t?t.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function Fp(...t){return Ke(t.join(":"))}function hi(t){return t=Ke(t),t?t+":":""}function qD(t){return t}const Lp="memory",Up=()=>{const t=new Map;return{name:Lp,getInstance:()=>t,hasItem(e){return t.has(e)},getItem(e){return t.get(e)??null},getItemRaw(e){return t.get(e)??null},setItem(e,r){t.set(e,r)},setItemRaw(e,r){t.set(e,r)},removeItem(e){t.delete(e)},getKeys(){return[...t.keys()]},clear(){t.clear()},dispose(){t.clear()}}};function kp(t={}){const e={mounts:{"":t.driver||Up()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},r=u=>{for(const l of e.mountpoints)if(u.startsWith(l))return{base:l,relativeKey:u.slice(l.length),driver:e.mounts[l]};return{base:"",relativeKey:u,driver:e.mounts[""]}},n=(u,l)=>e.mountpoints.filter(h=>h.startsWith(u)||l&&u.startsWith(h)).map(h=>({relativeBase:u.length>h.length?u.slice(h.length):void 0,mountpoint:h,driver:e.mounts[h]})),i=(u,l)=>{if(e.watching){l=Ke(l);for(const h of e.watchListeners)h(u,l)}},s=async()=>{if(!e.watching){e.watching=!0;for(const u in e.mounts)e.unwatch[u]=await lc(e.mounts[u],i,u)}},o=async()=>{if(e.watching){for(const u in e.unwatch)await e.unwatch[u]();e.unwatch={},e.watching=!1}},a=(u,l,h)=>{const d=new Map,p=f=>{let y=d.get(f.base);return y||(y={driver:f.driver,base:f.base,items:[]},d.set(f.base,y)),y};for(const f of u){const y=typeof f=="string",g=Ke(y?f:f.key),w=y?void 0:f.value,m=y||!f.options?l:{...l,...f.options},b=r(g);p(b).items.push({key:g,value:w,relativeKey:b.relativeKey,options:m})}return Promise.all([...d.values()].map(f=>h(f))).then(f=>f.flat())},c={hasItem(u,l={}){u=Ke(u);const{relativeKey:h,driver:d}=r(u);return be(d.hasItem,h,l)},getItem(u,l={}){u=Ke(u);const{relativeKey:h,driver:d}=r(u);return be(d.getItem,h,l).then(p=>ui(p))},getItems(u,l){return a(u,l,h=>h.driver.getItems?be(h.driver.getItems,h.items.map(d=>({key:d.relativeKey,options:d.options})),l).then(d=>d.map(p=>({key:Fp(h.base,p.key),value:ui(p.value)}))):Promise.all(h.items.map(d=>be(h.driver.getItem,d.relativeKey,d.options).then(p=>({key:d.key,value:ui(p)})))))},getItemRaw(u,l={}){u=Ke(u);const{relativeKey:h,driver:d}=r(u);return d.getItemRaw?be(d.getItemRaw,h,l):be(d.getItem,h,l).then(p=>Bp(p))},async setItem(u,l,h={}){if(l===void 0)return c.removeItem(u);u=Ke(u);const{relativeKey:d,driver:p}=r(u);p.setItem&&(await be(p.setItem,d,li(l),h),p.watch||i("update",u))},async setItems(u,l){await a(u,l,async h=>{if(h.driver.setItems)return be(h.driver.setItems,h.items.map(d=>({key:d.relativeKey,value:li(d.value),options:d.options})),l);h.driver.setItem&&await Promise.all(h.items.map(d=>be(h.driver.setItem,d.relativeKey,li(d.value),d.options)))})},async setItemRaw(u,l,h={}){if(l===void 0)return c.removeItem(u,h);u=Ke(u);const{relativeKey:d,driver:p}=r(u);if(p.setItemRaw)await be(p.setItemRaw,d,l,h);else if(p.setItem)await be(p.setItem,d,Np(l),h);else return;p.watch||i("update",u)},async removeItem(u,l={}){typeof l=="boolean"&&(l={removeMeta:l}),u=Ke(u);const{relativeKey:h,driver:d}=r(u);d.removeItem&&(await be(d.removeItem,h,l),(l.removeMeta||l.removeMata)&&await be(d.removeItem,h+"$",l),d.watch||i("remove",u))},async getMeta(u,l={}){typeof l=="boolean"&&(l={nativeOnly:l}),u=Ke(u);const{relativeKey:h,driver:d}=r(u),p=Object.create(null);if(d.getMeta&&Object.assign(p,await be(d.getMeta,h,l)),!l.nativeOnly){const f=await be(d.getItem,h+"$",l).then(y=>ui(y));f&&typeof f=="object"&&(typeof f.atime=="string"&&(f.atime=new Date(f.atime)),typeof f.mtime=="string"&&(f.mtime=new Date(f.mtime)),Object.assign(p,f))}return p},setMeta(u,l,h={}){return this.setItem(u+"$",l,h)},removeMeta(u,l={}){return this.removeItem(u+"$",l)},async getKeys(u,l={}){u=hi(u);const h=n(u,!0);let d=[];const p=[];for(const f of h){const y=await be(f.driver.getKeys,f.relativeBase,l);for(const g of y){const w=f.mountpoint+Ke(g);d.some(m=>w.startsWith(m))||p.push(w)}d=[f.mountpoint,...d.filter(g=>!g.startsWith(f.mountpoint))]}return u?p.filter(f=>f.startsWith(u)&&f[f.length-1]!=="$"):p.filter(f=>f[f.length-1]!=="$")},async clear(u,l={}){u=hi(u),await Promise.all(n(u,!1).map(async h=>{if(h.driver.clear)return be(h.driver.clear,h.relativeBase,l);if(h.driver.removeItem){const d=await h.driver.getKeys(h.relativeBase||"",l);return Promise.all(d.map(p=>h.driver.removeItem(p,l)))}}))},async dispose(){await Promise.all(Object.values(e.mounts).map(u=>hc(u)))},async watch(u){return await s(),e.watchListeners.push(u),async()=>{e.watchListeners=e.watchListeners.filter(l=>l!==u),e.watchListeners.length===0&&await o()}},async unwatch(){e.watchListeners=[],await o()},mount(u,l){if(u=hi(u),u&&e.mounts[u])throw new Error(`already mounted at ${u}`);return u&&(e.mountpoints.push(u),e.mountpoints.sort((h,d)=>d.length-h.length)),e.mounts[u]=l,e.watching&&Promise.resolve(lc(l,i,u)).then(h=>{e.unwatch[u]=h}).catch(console.error),c},async unmount(u,l=!0){u=hi(u),!(!u||!e.mounts[u])&&(e.watching&&u in e.unwatch&&(e.unwatch[u](),delete e.unwatch[u]),l&&await hc(e.mounts[u]),e.mountpoints=e.mountpoints.filter(h=>h!==u),delete e.mounts[u])},getMount(u=""){u=Ke(u)+":";const l=r(u);return{driver:l.driver,base:l.base}},getMounts(u="",l={}){return u=Ke(u),n(u,l.parents).map(d=>({driver:d.driver,base:d.mountpoint}))},keys:(u,l={})=>c.getKeys(u,l),get:(u,l={})=>c.getItem(u,l),set:(u,l,h={})=>c.setItem(u,l,h),has:(u,l={})=>c.hasItem(u,l),del:(u,l={})=>c.removeItem(u,l),remove:(u,l={})=>c.removeItem(u,l)};return c}function lc(t,e,r){return t.watch?t.watch((n,i)=>e(n,r+i)):()=>{}}async function hc(t){typeof t.dispose=="function"&&await be(t.dispose)}function hr(t){return new Promise((e,r)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>r(t.error)})}function dc(t,e){const r=indexedDB.open(t);r.onupgradeneeded=()=>r.result.createObjectStore(e);const n=hr(r);return(i,s)=>n.then(o=>s(o.transaction(e,i).objectStore(e)))}let vs;function yn(){return vs||(vs=dc("keyval-store","keyval")),vs}function fc(t,e=yn()){return e("readonly",r=>hr(r.get(t)))}function Mp(t,e,r=yn()){return r("readwrite",n=>(n.put(e,t),hr(n.transaction)))}function jp(t,e=yn()){return e("readwrite",r=>(r.delete(t),hr(r.transaction)))}function qp(t=yn()){return t("readwrite",e=>(e.clear(),hr(e.transaction)))}function zp(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},hr(t.transaction)}function Vp(t=yn()){return t("readonly",e=>{if(e.getAllKeys)return hr(e.getAllKeys());const r=[];return zp(e,n=>r.push(n.key)).then(()=>r)})}const Kp=t=>JSON.stringify(t,(e,r)=>typeof r=="bigint"?r.toString()+"n":r),Hp=t=>{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,r=t.replace(e,'$1"$2n"$3');return JSON.parse(r,(n,i)=>typeof i=="string"&&i.match(/^\d+n$/)?BigInt(i.substring(0,i.length-1)):i)};function Nr(t){if(typeof t!="string")throw new Error(`Cannot safe json parse value of type ${typeof t}`);try{return Hp(t)}catch{return t}}function dr(t){return typeof t=="string"?t:Kp(t)||""}const Wp="idb-keyval";var Gp=(t={})=>{const e=t.base&&t.base.length>0?`${t.base}:`:"",r=i=>e+i;let n;return t.dbName&&t.storeName&&(n=dc(t.dbName,t.storeName)),{name:Wp,options:t,async hasItem(i){return!(typeof await fc(r(i),n)>"u")},async getItem(i){return await fc(r(i),n)??null},setItem(i,s){return Mp(r(i),s,n)},removeItem(i){return jp(r(i),n)},getKeys(){return Vp(n)},clear(){return qp(n)}}};const Yp="WALLET_CONNECT_V2_INDEXED_DB",Zp="keyvaluestorage";class Jp{constructor(){this.indexedDb=kp({driver:Gp({dbName:Yp,storeName:Zp})})}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 r=await this.indexedDb.getItem(e);if(r!==null)return r}async setItem(e,r){await this.indexedDb.setItem(e,dr(r))}async removeItem(e){await this.indexedDb.removeItem(e)}}var Es=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},di={exports:{}};(function(){let t;function e(){}t=e,t.prototype.getItem=function(r){return this.hasOwnProperty(r)?String(this[r]):null},t.prototype.setItem=function(r,n){this[r]=String(n)},t.prototype.removeItem=function(r){delete this[r]},t.prototype.clear=function(){const r=this;Object.keys(r).forEach(function(n){r[n]=void 0,delete r[n]})},t.prototype.key=function(r){return r=r||0,Object.keys(this)[r]},t.prototype.__defineGetter__("length",function(){return Object.keys(this).length}),typeof Es<"u"&&Es.localStorage?di.exports=Es.localStorage:typeof window<"u"&&window.localStorage?di.exports=window.localStorage:di.exports=new e})();function Xp(t){var e;return[t[0],Nr((e=t[1])!=null?e:"")]}class Qp{constructor(){this.localStorage=di.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(Xp)}async getItem(e){const r=this.localStorage.getItem(e);if(r!==null)return Nr(r)}async setItem(e,r){this.localStorage.setItem(e,dr(r))}async removeItem(e){this.localStorage.removeItem(e)}}const eg="wc_storage_version",pc=1,tg=async(t,e,r)=>{const n=eg,i=await e.getItem(n);if(i&&i>=pc){r(e);return}const s=await t.getKeys();if(!s.length){r(e);return}const o=[];for(;s.length;){const a=s.shift();if(!a)continue;const c=a.toLowerCase();if(c.includes("wc@")||c.includes("walletconnect")||c.includes("wc_")||c.includes("wallet_connect")){const u=await t.getItem(a);await e.setItem(a,u),o.push(a)}}await e.setItem(n,pc),r(e),rg(t,o)},rg=async(t,e)=>{e.length&&e.forEach(async r=>{await t.removeItem(r)})};class ng{constructor(){this.initialized=!1,this.setInitialized=r=>{this.storage=r,this.initialized=!0};const e=new Qp;this.storage=e;try{const r=new Jp;tg(e,r,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,r){return await this.initialize(),this.storage.setItem(e,r)}async removeItem(e){return await this.initialize(),this.storage.removeItem(e)}async initialize(){this.initialized||await new Promise(e=>{const r=setInterval(()=>{this.initialized&&(clearInterval(r),e())},20)})}}function ig(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}var sg=og;function og(t,e,r){var n=r&&r.stringify||ig,i=1;if(typeof t=="object"&&t!==null){var s=e.length+i;if(s===1)return t;var o=new Array(s);o[0]=n(t);for(var a=1;a<s;a++)o[a]=n(e[a]);return o.join(" ")}if(typeof t!="string")return t;var c=e.length;if(c===0)return t;for(var u="",l=1-i,h=-1,d=t&&t.length||0,p=0;p<d;){if(t.charCodeAt(p)===37&&p+1<d){switch(h=h>-1?h:0,t.charCodeAt(p+1)){case 100:case 102:if(l>=c||e[l]==null)break;h<p&&(u+=t.slice(h,p)),u+=Number(e[l]),h=p+2,p++;break;case 105:if(l>=c||e[l]==null)break;h<p&&(u+=t.slice(h,p)),u+=Math.floor(Number(e[l])),h=p+2,p++;break;case 79:case 111:case 106:if(l>=c||e[l]===void 0)break;h<p&&(u+=t.slice(h,p));var f=typeof e[l];if(f==="string"){u+="'"+e[l]+"'",h=p+2,p++;break}if(f==="function"){u+=e[l].name||"<anonymous>",h=p+2,p++;break}u+=n(e[l]),h=p+2,p++;break;case 115:if(l>=c)break;h<p&&(u+=t.slice(h,p)),u+=String(e[l]),h=p+2,p++;break;case 37:h<p&&(u+=t.slice(h,p)),u+="%",h=p+2,p++,l--;break}++l}++p}return h===-1?t:(h<d&&(u+=t.slice(h)),u)}const gc=sg;var Pt=wt;const wn=yg().console||{},ag={mapHttpRequest:pi,mapHttpResponse:pi,wrapRequestSerializer:Ss,wrapResponseSerializer:Ss,wrapErrorSerializer:Ss,req:pi,res:pi,err:dg};function cg(t,e){return Array.isArray(t)?t.filter(function(n){return n!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function wt(t){t=t||{},t.browser=t.browser||{};const e=t.browser.transmit;if(e&&typeof e.send!="function")throw Error("pino: transmit option must have a send function");const r=t.browser.write||wn;t.browser.write&&(t.browser.asObject=!0);const n=t.serializers||{},i=cg(t.browser.serialize,n);let s=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(s=!1);const o=["error","fatal","warn","info","debug","trace"];typeof r=="function"&&(r.error=r.fatal=r.warn=r.info=r.debug=r.trace=r),t.enabled===!1&&(t.level="silent");const a=t.level||"info",c=Object.create(r);c.log||(c.log=mn),Object.defineProperty(c,"levelVal",{get:l}),Object.defineProperty(c,"level",{get:h,set:d});const u={transmit:e,serialize:i,asObject:t.browser.asObject,levels:o,timestamp:fg(t)};c.levels=wt.levels,c.level=a,c.setMaxListeners=c.getMaxListeners=c.emit=c.addListener=c.on=c.prependListener=c.once=c.prependOnceListener=c.removeListener=c.removeAllListeners=c.listeners=c.listenerCount=c.eventNames=c.write=c.flush=mn,c.serializers=n,c._serialize=i,c._stdErrSerialize=s,c.child=p,e&&(c._logEvent=_s());function l(){return this.level==="silent"?1/0:this.levels.values[this.level]}function h(){return this._level}function d(f){if(f!=="silent"&&!this.levels.values[f])throw Error("unknown level "+f);this._level=f,Br(u,c,"error","log"),Br(u,c,"fatal","error"),Br(u,c,"warn","error"),Br(u,c,"info","log"),Br(u,c,"debug","log"),Br(u,c,"trace","log")}function p(f,y){if(!f)throw new Error("missing bindings for child Pino");y=y||{},i&&f.serializers&&(y.serializers=f.serializers);const g=y.serializers;if(i&&g){var w=Object.assign({},n,g),m=t.browser.serialize===!0?Object.keys(w):i;delete f.serializers,fi([f],m,w,this._stdErrSerialize)}function b(E){this._childLevel=(E._childLevel|0)+1,this.error=Fr(E,f,"error"),this.fatal=Fr(E,f,"fatal"),this.warn=Fr(E,f,"warn"),this.info=Fr(E,f,"info"),this.debug=Fr(E,f,"debug"),this.trace=Fr(E,f,"trace"),w&&(this.serializers=w,this._serialize=m),e&&(this._logEvent=_s([].concat(E._logEvent.bindings,f)))}return b.prototype=this,new b(this)}return c}wt.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"}},wt.stdSerializers=ag,wt.stdTimeFunctions=Object.assign({},{nullTime:yc,epochTime:wc,unixTime:pg,isoTime:gg});function Br(t,e,r,n){const i=Object.getPrototypeOf(e);e[r]=e.levelVal>e.levels.values[r]?mn:i[r]?i[r]:wn[r]||wn[n]||mn,ug(t,e,r)}function ug(t,e,r){!t.transmit&&e[r]===mn||(e[r]=function(n){return function(){const s=t.timestamp(),o=new Array(arguments.length),a=Object.getPrototypeOf&&Object.getPrototypeOf(this)===wn?wn:this;for(var c=0;c<o.length;c++)o[c]=arguments[c];if(t.serialize&&!t.asObject&&fi(o,this._serialize,this.serializers,this._stdErrSerialize),t.asObject?n.call(a,lg(this,r,o,s)):n.apply(a,o),t.transmit){const u=t.transmit.level||e.level,l=wt.levels.values[u],h=wt.levels.values[r];if(h<l)return;hg(this,{ts:s,methodLevel:r,methodValue:h,transmitLevel:u,transmitValue:wt.levels.values[t.transmit.level||e.level],send:t.transmit.send,val:e.levelVal},o)}}}(e[r]))}function lg(t,e,r,n){t._serialize&&fi(r,t._serialize,t.serializers,t._stdErrSerialize);const i=r.slice();let s=i[0];const o={};n&&(o.time=n),o.level=wt.levels.values[e];let a=(t._childLevel|0)+1;if(a<1&&(a=1),s!==null&&typeof s=="object"){for(;a--&&typeof i[0]=="object";)Object.assign(o,i.shift());s=i.length?gc(i.shift(),i):void 0}else typeof s=="string"&&(s=gc(i.shift(),i));return s!==void 0&&(o.msg=s),o}function fi(t,e,r,n){for(const i in t)if(n&&t[i]instanceof Error)t[i]=wt.stdSerializers.err(t[i]);else if(typeof t[i]=="object"&&!Array.isArray(t[i]))for(const s in t[i])e&&e.indexOf(s)>-1&&s in r&&(t[i][s]=r[s](t[i][s]))}function Fr(t,e,r){return function(){const n=new Array(1+arguments.length);n[0]=e;for(var i=1;i<n.length;i++)n[i]=arguments[i-1];return t[r].apply(this,n)}}function hg(t,e,r){const n=e.send,i=e.ts,s=e.methodLevel,o=e.methodValue,a=e.val,c=t._logEvent.bindings;fi(r,t._serialize||Object.keys(t.serializers),t.serializers,t._stdErrSerialize===void 0?!0:t._stdErrSerialize),t._logEvent.ts=i,t._logEvent.messages=r.filter(function(u){return c.indexOf(u)===-1}),t._logEvent.level.label=s,t._logEvent.level.value=o,n(s,t._logEvent,a),t._logEvent=_s(c)}function _s(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function dg(t){const e={type:t.constructor.name,msg:t.message,stack:t.stack};for(const r in t)e[r]===void 0&&(e[r]=t[r]);return e}function fg(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?yc:wc}function pi(){return{}}function Ss(t){return t}function mn(){}function yc(){return!1}function wc(){return Date.now()}function pg(){return Math.round(Date.now()/1e3)}function gg(){return new Date(Date.now()).toISOString()}function yg(){function t(e){return typeof e<"u"&&e}try{return typeof globalThis<"u"||Object.defineProperty(Object.prototype,"globalThis",{get:function(){return delete Object.prototype.globalThis,this.globalThis=this},configurable:!0}),globalThis}catch{return t(self)||t(window)||t(this)||{}}}const wg={level:"info"},bn="custom_context",xs=1e3*1024;class mg{constructor(e){this.nodeValue=e,this.sizeInBytes=new TextEncoder().encode(this.nodeValue).length,this.next=null}get value(){return this.nodeValue}get size(){return this.sizeInBytes}}class mc{constructor(e){this.head=null,this.tail=null,this.lengthInNodes=0,this.maxSizeInBytes=e,this.sizeInBytes=0}append(e){const r=new mg(e);if(r.size>this.maxSizeInBytes)throw new Error(`[LinkedList] Value too big to insert into list: ${e} with size ${r.size}`);for(;this.size+r.size>this.maxSizeInBytes;)this.shift();this.head?(this.tail&&(this.tail.next=r),this.tail=r):(this.head=r,this.tail=r),this.lengthInNodes++,this.sizeInBytes+=r.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 r=this.head;for(;r!==null;)e.push(r.value),r=r.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 r=e.value;return e=e.next,{done:!1,value:r}}}}}class bc{constructor(e,r=xs){this.level=e??"error",this.levelValue=Pt.levels.values[this.level],this.MAX_LOG_SIZE_IN_BYTES=r,this.logs=new mc(this.MAX_LOG_SIZE_IN_BYTES)}forwardToConsole(e,r){r===Pt.levels.values.error?console.error(e):r===Pt.levels.values.warn?console.warn(e):r===Pt.levels.values.debug?console.debug(e):r===Pt.levels.values.trace?console.trace(e):console.log(e)}appendToLogs(e){this.logs.append(dr({timestamp:new Date().toISOString(),log:e}));const r=typeof e=="string"?JSON.parse(e).level:e.level;r>=this.levelValue&&this.forwardToConsole(e,r)}getLogs(){return this.logs}clearLogs(){this.logs=new mc(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(e){const r=this.getLogArray();return r.push(dr({extraMetadata:e})),new Blob(r,{type:"application/json"})}}class bg{constructor(e,r=xs){this.baseChunkLogger=new bc(e,r)}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 r=URL.createObjectURL(this.logsToBlob(e)),n=document.createElement("a");n.href=r,n.download=`walletconnect-logs-${new Date().toISOString()}.txt`,document.body.appendChild(n),n.click(),document.body.removeChild(n),URL.revokeObjectURL(r)}}class vg{constructor(e,r=xs){this.baseChunkLogger=new bc(e,r)}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 Eg=Object.defineProperty,_g=Object.defineProperties,Sg=Object.getOwnPropertyDescriptors,vc=Object.getOwnPropertySymbols,xg=Object.prototype.hasOwnProperty,Ig=Object.prototype.propertyIsEnumerable,Ec=(t,e,r)=>e in t?Eg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gi=(t,e)=>{for(var r in e||(e={}))xg.call(e,r)&&Ec(t,r,e[r]);if(vc)for(var r of vc(e))Ig.call(e,r)&&Ec(t,r,e[r]);return t},yi=(t,e)=>_g(t,Sg(e));function Is(t){return yi(gi({},t),{level:t?.level||wg.level})}function Dg(t,e=bn){return t[e]||""}function Og(t,e,r=bn){return t[r]=e,t}function He(t,e=bn){let r="";return typeof t.bindings>"u"?r=Dg(t,e):r=t.bindings().context||"",r}function $g(t,e,r=bn){const n=He(t,r);return n.trim()?`${n}/${e}`:e}function je(t,e,r=bn){const n=$g(t,e,r),i=t.child({context:n});return Og(i,n,r)}function Ag(t){var e,r;const n=new bg((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:Pt(yi(gi({},t.opts),{level:"trace",browser:yi(gi({},(r=t.opts)==null?void 0:r.browser),{write:i=>n.write(i)})})),chunkLoggerController:n}}function Pg(t){var e;const r=new vg((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:Pt(yi(gi({},t.opts),{level:"trace"})),chunkLoggerController:r}}function Tg(t){return typeof t.loggerOverride<"u"&&typeof t.loggerOverride!="string"?{logger:t.loggerOverride,chunkLoggerController:null}:typeof window<"u"?Ag(t):Pg(t)}var Rg=Object.defineProperty,Cg=(t,e,r)=>e in t?Rg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_c=(t,e,r)=>Cg(t,typeof e!="symbol"?e+"":e,r);class Ng extends lr{constructor(e){super(),this.opts=e,_c(this,"protocol","wc"),_c(this,"version",2)}}var Bg=Object.defineProperty,Fg=(t,e,r)=>e in t?Bg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Lg=(t,e,r)=>Fg(t,typeof e!="symbol"?e+"":e,r);class Ug extends lr{constructor(e,r){super(),this.core=e,this.logger=r,Lg(this,"records",new Map)}}class kg{constructor(e,r){this.logger=e,this.core=r}}class Mg extends lr{constructor(e,r){super(),this.relayer=e,this.logger=r}}class jg extends lr{constructor(e){super()}}class qg{constructor(e,r,n,i){this.core=e,this.logger=r,this.name=n}}class zg extends lr{constructor(e,r){super(),this.relayer=e,this.logger=r}}class Vg extends lr{constructor(e,r){super(),this.core=e,this.logger=r}}class Kg{constructor(e,r,n){this.core=e,this.logger=r,this.store=n}}class Hg{constructor(e,r){this.projectId=e,this.logger=r}}class Wg{constructor(e,r,n){this.core=e,this.logger=r,this.telemetryEnabled=n}}var Gg=Object.defineProperty,Yg=(t,e,r)=>e in t?Gg(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Sc=(t,e,r)=>Yg(t,typeof e!="symbol"?e+"":e,r);class Zg{constructor(e){this.opts=e,Sc(this,"protocol","wc"),Sc(this,"version",2)}}class Jg{constructor(e){this.client=e}}function Xg(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function xc(t,...e){if(!Xg(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Ic(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Qg(t,e){xc(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const Lr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ds=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function ey(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function Dc(t){return typeof t=="string"&&(t=ey(t)),xc(t),t}class ty{clone(){return this._cloneInto()}}function ry(t){const e=n=>t().update(Dc(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function Oc(t=32){if(Lr&&typeof Lr.getRandomValues=="function")return Lr.getRandomValues(new Uint8Array(t));if(Lr&&typeof Lr.randomBytes=="function")return Lr.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function ny(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),c=n?4:0,u=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+u,a,n)}class iy extends ty{constructor(e,r,n,i){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Ds(this.buffer)}update(e){Ic(this);const{view:r,buffer:n,blockLen:i}=this;e=Dc(e);const s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Ds(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ic(this),Qg(e,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let h=o;h<i;h++)r[h]=0;ny(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=Ds(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.length=i,e.pos=a,e.finished=s,e.destroyed=o,i%r&&e.buffer.set(n),e}}const wi=BigInt(2**32-1),Os=BigInt(32);function $c(t,e=!1){return e?{h:Number(t&wi),l:Number(t>>Os&wi)}:{h:Number(t>>Os&wi)|0,l:Number(t&wi)|0}}function sy(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:s,l:o}=$c(t[i],e);[r[i],n[i]]=[s,o]}return[r,n]}const oy=(t,e)=>BigInt(t>>>0)<<Os|BigInt(e>>>0),ay=(t,e,r)=>t>>>r,cy=(t,e,r)=>t<<32-r|e>>>r,uy=(t,e,r)=>t>>>r|e<<32-r,ly=(t,e,r)=>t<<32-r|e>>>r,hy=(t,e,r)=>t<<64-r|e>>>r-32,dy=(t,e,r)=>t>>>r-32|e<<64-r,fy=(t,e)=>e,py=(t,e)=>t,gy=(t,e,r)=>t<<r|e>>>32-r,yy=(t,e,r)=>e<<r|t>>>32-r,wy=(t,e,r)=>e<<r-32|t>>>64-r,my=(t,e,r)=>t<<r-32|e>>>64-r;function by(t,e,r,n){const i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}const vy=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),Ey=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,_y=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),Sy=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,xy=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),Iy=(t,e,r,n,i,s)=>e+r+n+i+s+(t/2**32|0)|0,H={fromBig:$c,split:sy,toBig:oy,shrSH:ay,shrSL:cy,rotrSH:uy,rotrSL:ly,rotrBH:hy,rotrBL:dy,rotr32H:fy,rotr32L:py,rotlSH:gy,rotlSL:yy,rotlBH:wy,rotlBL:my,add:by,add3L:vy,add3H:Ey,add4L:_y,add4H:Sy,add5H:Iy,add5L:xy},[Dy,Oy]=(()=>H.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(t=>BigInt(t))))(),Ht=new Uint32Array(80),Wt=new Uint32Array(80);class $y extends iy{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){const{Ah:e,Al:r,Bh:n,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:u,El:l,Fh:h,Fl:d,Gh:p,Gl:f,Hh:y,Hl:g}=this;return[e,r,n,i,s,o,a,c,u,l,h,d,p,f,y,g]}set(e,r,n,i,s,o,a,c,u,l,h,d,p,f,y,g){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=l|0,this.Fh=h|0,this.Fl=d|0,this.Gh=p|0,this.Gl=f|0,this.Hh=y|0,this.Hl=g|0}process(e,r){for(let b=0;b<16;b++,r+=4)Ht[b]=e.getUint32(r),Wt[b]=e.getUint32(r+=4);for(let b=16;b<80;b++){const E=Ht[b-15]|0,$=Wt[b-15]|0,D=H.rotrSH(E,$,1)^H.rotrSH(E,$,8)^H.shrSH(E,$,7),S=H.rotrSL(E,$,1)^H.rotrSL(E,$,8)^H.shrSL(E,$,7),A=Ht[b-2]|0,x=Wt[b-2]|0,k=H.rotrSH(A,x,19)^H.rotrBH(A,x,61)^H.shrSH(A,x,6),C=H.rotrSL(A,x,19)^H.rotrBL(A,x,61)^H.shrSL(A,x,6),B=H.add4L(S,C,Wt[b-7],Wt[b-16]),j=H.add4H(B,D,k,Ht[b-7],Ht[b-16]);Ht[b]=j|0,Wt[b]=B|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:u,Dl:l,Eh:h,El:d,Fh:p,Fl:f,Gh:y,Gl:g,Hh:w,Hl:m}=this;for(let b=0;b<80;b++){const E=H.rotrSH(h,d,14)^H.rotrSH(h,d,18)^H.rotrBH(h,d,41),$=H.rotrSL(h,d,14)^H.rotrSL(h,d,18)^H.rotrBL(h,d,41),D=h&p^~h&y,S=d&f^~d&g,A=H.add5L(m,$,S,Oy[b],Wt[b]),x=H.add5H(A,w,E,D,Dy[b],Ht[b]),k=A|0,C=H.rotrSH(n,i,28)^H.rotrBH(n,i,34)^H.rotrBH(n,i,39),B=H.rotrSL(n,i,28)^H.rotrBL(n,i,34)^H.rotrBL(n,i,39),j=n&s^n&a^s&a,I=i&o^i&c^o&c;w=y|0,m=g|0,y=p|0,g=f|0,p=h|0,f=d|0,{h,l:d}=H.add(u|0,l|0,x|0,k|0),u=a|0,l=c|0,a=s|0,c=o|0,s=n|0,o=i|0;const _=H.add3L(k,B,I);n=H.add3H(_,x,C,j),i=_|0}({h:n,l:i}=H.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=H.add(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=H.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=H.add(this.Dh|0,this.Dl|0,u|0,l|0),{h,l:d}=H.add(this.Eh|0,this.El|0,h|0,d|0),{h:p,l:f}=H.add(this.Fh|0,this.Fl|0,p|0,f|0),{h:y,l:g}=H.add(this.Gh|0,this.Gl|0,y|0,g|0),{h:w,l:m}=H.add(this.Hh|0,this.Hl|0,w|0,m|0),this.set(n,i,s,o,a,c,u,l,h,d,p,f,y,g,w,m)}roundClean(){Ht.fill(0),Wt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const Ay=ry(()=>new $y);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const $s=BigInt(0),Ac=BigInt(1),Py=BigInt(2);function As(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ps(t){if(!As(t))throw new Error("Uint8Array expected")}function Ts(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const Ty=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Rs(t){Ps(t);let e="";for(let r=0;r<t.length;r++)e+=Ty[t[r]];return e}function Pc(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?$s:BigInt("0x"+t)}const Tt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Tc(t){if(t>=Tt._0&&t<=Tt._9)return t-Tt._0;if(t>=Tt.A&&t<=Tt.F)return t-(Tt.A-10);if(t>=Tt.a&&t<=Tt.f)return t-(Tt.a-10)}function Rc(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){const o=Tc(t.charCodeAt(s)),a=Tc(t.charCodeAt(s+1));if(o===void 0||a===void 0){const c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function Ry(t){return Pc(Rs(t))}function mi(t){return Ps(t),Pc(Rs(Uint8Array.from(t).reverse()))}function Cc(t,e){return Rc(t.toString(16).padStart(e*2,"0"))}function Cs(t,e){return Cc(t,e).reverse()}function Rt(t,e,r){let n;if(typeof e=="string")try{n=Rc(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(As(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=n.length;if(typeof r=="number"&&i!==r)throw new Error(t+" of length "+r+" expected, got "+i);return n}function Nc(...t){let e=0;for(let n=0;n<t.length;n++){const i=t[n];Ps(i),e+=i.length}const r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){const s=t[n];r.set(s,i),i+=s.length}return r}const Ns=t=>typeof t=="bigint"&&$s<=t;function Cy(t,e,r){return Ns(t)&&Ns(e)&&Ns(r)&&e<=t&&t<r}function vn(t,e,r,n){if(!Cy(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ny(t){let e;for(e=0;t>$s;t>>=Ac,e+=1);return e}const By=t=>(Py<<BigInt(t-1))-Ac,Fy={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||As(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function Bs(t,e,r={}){const n=(i,s,o)=>{const a=Fy[s];if(typeof a!="function")throw new Error("invalid validator function");const c=t[i];if(!(o&&c===void 0)&&!a(c,t))throw new Error("param "+String(i)+" is invalid. Expected "+s+", got "+c)};for(const[i,s]of Object.entries(e))n(i,s,!1);for(const[i,s]of Object.entries(r))n(i,s,!0);return t}function Bc(t){const e=new WeakMap;return(r,...n)=>{const i=e.get(r);if(i!==void 0)return i;const s=t(r,...n);return e.set(r,s),s}}const ve=BigInt(0),he=BigInt(1),fr=BigInt(2),Ly=BigInt(3),Fs=BigInt(4),Fc=BigInt(5),Lc=BigInt(8);function we(t,e){const r=t%e;return r>=ve?r:e+r}function Uy(t,e,r){if(e<ve)throw new Error("invalid exponent, negatives unsupported");if(r<=ve)throw new Error("invalid modulus");if(r===he)return ve;let n=he;for(;e>ve;)e&he&&(n=n*t%r),t=t*t%r,e>>=he;return n}function mt(t,e,r){let n=t;for(;e-- >ve;)n*=n,n%=r;return n}function Uc(t,e){if(t===ve)throw new Error("invert: expected non-zero number");if(e<=ve)throw new Error("invert: expected positive modulus, got "+e);let r=we(t,e),n=e,i=ve,s=he;for(;r!==ve;){const o=n/r,a=n%r,c=i-s*o;n=r,r=a,i=s,s=c}if(n!==he)throw new Error("invert: does not exist");return we(i,e)}function ky(t){const e=(t-he)/fr;let r,n,i;for(r=t-he,n=0;r%fr===ve;r/=fr,n++);for(i=fr;i<t&&Uy(i,e,t)!==t-he;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const o=(t+he)/Fs;return function(a,c){const u=a.pow(c,o);if(!a.eql(a.sqr(u),c))throw new Error("Cannot find square root");return u}}const s=(r+he)/fr;return function(o,a){if(o.pow(a,e)===o.neg(o.ONE))throw new Error("Cannot find square root");let c=n,u=o.pow(o.mul(o.ONE,i),r),l=o.pow(a,s),h=o.pow(a,r);for(;!o.eql(h,o.ONE);){if(o.eql(h,o.ZERO))return o.ZERO;let d=1;for(let f=o.sqr(h);d<c&&!o.eql(f,o.ONE);d++)f=o.sqr(f);const p=o.pow(u,he<<BigInt(c-d-1));u=o.sqr(p),l=o.mul(l,p),h=o.mul(h,u),c=d}return l}}function My(t){if(t%Fs===Ly){const e=(t+he)/Fs;return function(r,n){const i=r.pow(n,e);if(!r.eql(r.sqr(i),n))throw new Error("Cannot find square root");return i}}if(t%Lc===Fc){const e=(t-Fc)/Lc;return function(r,n){const i=r.mul(n,fr),s=r.pow(i,e),o=r.mul(n,s),a=r.mul(r.mul(o,fr),s),c=r.mul(o,r.sub(a,r.ONE));if(!r.eql(r.sqr(c),n))throw new Error("Cannot find square root");return c}}return ky(t)}const jy=(t,e)=>(we(t,e)&he)===he,qy=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function zy(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=qy.reduce((n,i)=>(n[i]="function",n),e);return Bs(t,r)}function Vy(t,e,r){if(r<ve)throw new Error("invalid exponent, negatives unsupported");if(r===ve)return t.ONE;if(r===he)return e;let n=t.ONE,i=e;for(;r>ve;)r&he&&(n=t.mul(n,i)),i=t.sqr(i),r>>=he;return n}function Ky(t,e){const r=new Array(e.length),n=e.reduce((s,o,a)=>t.is0(o)?s:(r[a]=s,t.mul(s,o)),t.ONE),i=t.inv(n);return e.reduceRight((s,o,a)=>t.is0(o)?s:(r[a]=t.mul(s,r[a]),t.mul(s,o)),i),r}function kc(t,e){const r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Mc(t,e,r=!1,n={}){if(t<=ve)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=kc(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:r,BITS:i,BYTES:s,MASK:By(i),ZERO:ve,ONE:he,create:c=>we(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return ve<=c&&c<t},is0:c=>c===ve,isOdd:c=>(c&he)===he,neg:c=>we(-c,t),eql:(c,u)=>c===u,sqr:c=>we(c*c,t),add:(c,u)=>we(c+u,t),sub:(c,u)=>we(c-u,t),mul:(c,u)=>we(c*u,t),pow:(c,u)=>Vy(a,c,u),div:(c,u)=>we(c*Uc(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Uc(c,t),sqrt:n.sqrt||(c=>(o||(o=My(t)),o(a,c))),invertBatch:c=>Ky(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>r?Cs(c,s):Cc(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?mi(c):Ry(c)}});return Object.freeze(a)}const jc=BigInt(0),bi=BigInt(1);function Ls(t,e){const r=e.negate();return t?r:e}function qc(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Us(t,e){qc(t,e);const r=Math.ceil(e/t)+1,n=2**(t-1);return{windows:r,windowSize:n}}function Hy(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function Wy(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}const ks=new WeakMap,zc=new WeakMap;function Ms(t){return zc.get(t)||1}function Gy(t,e){return{constTimeNegate:Ls,hasPrecomputes(r){return Ms(r)!==1},unsafeLadder(r,n,i=t.ZERO){let s=r;for(;n>jc;)n&bi&&(i=i.add(s)),s=s.double(),n>>=bi;return i},precomputeWindow(r,n){const{windows:i,windowSize:s}=Us(n,e),o=[];let a=r,c=a;for(let u=0;u<i;u++){c=a,o.push(c);for(let l=1;l<s;l++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(r,n,i){const{windows:s,windowSize:o}=Us(r,e);let a=t.ZERO,c=t.BASE;const u=BigInt(2**r-1),l=2**r,h=BigInt(r);for(let d=0;d<s;d++){const p=d*o;let f=Number(i&u);i>>=h,f>o&&(f-=l,i+=bi);const y=p,g=p+Math.abs(f)-1,w=d%2!==0,m=f<0;f===0?c=c.add(Ls(w,n[y])):a=a.add(Ls(m,n[g]))}return{p:a,f:c}},wNAFUnsafe(r,n,i,s=t.ZERO){const{windows:o,windowSize:a}=Us(r,e),c=BigInt(2**r-1),u=2**r,l=BigInt(r);for(let h=0;h<o;h++){const d=h*a;if(i===jc)break;let p=Number(i&c);if(i>>=l,p>a&&(p-=u,i+=bi),p===0)continue;let f=n[d+Math.abs(p)-1];p<0&&(f=f.negate()),s=s.add(f)}return s},getPrecomputes(r,n,i){let s=ks.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&ks.set(n,i(s))),s},wNAFCached(r,n,i){const s=Ms(r);return this.wNAF(s,this.getPrecomputes(s,r,i),n)},wNAFCachedUnsafe(r,n,i,s){const o=Ms(r);return o===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(o,this.getPrecomputes(o,r,i),n,s)},setWindowSize(r,n){qc(n,e),zc.set(r,n),ks.delete(r)}}}function Yy(t,e,r,n){if(Hy(r,t),Wy(n,e),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const i=t.ZERO,s=Ny(BigInt(r.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=(1<<o)-1,c=new Array(a+1).fill(i),u=Math.floor((e.BITS-1)/o)*o;let l=i;for(let h=u;h>=0;h-=o){c.fill(i);for(let p=0;p<n.length;p++){const f=n[p],y=Number(f>>BigInt(h)&BigInt(a));c[y]=c[y].add(r[p])}let d=i;for(let p=c.length-1,f=i;p>0;p--)f=f.add(c[p]),d=d.add(f);if(l=l.add(d),h!==0)for(let p=0;p<o;p++)l=l.double()}return l}function Zy(t){return zy(t.Fp),Bs(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...kc(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}const ut=BigInt(0),We=BigInt(1),vi=BigInt(2),Jy=BigInt(8),Xy={zip215:!0};function Qy(t){const e=Zy(t);return Bs(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function ew(t){const e=Qy(t),{Fp:r,n,prehash:i,hash:s,randomBytes:o,nByteLength:a,h:c}=e,u=vi<<BigInt(a*8)-We,l=r.create,h=Mc(e.n,e.nBitLength),d=e.uvRatio||((_,v)=>{try{return{isValid:!0,value:r.sqrt(_*r.inv(v))}}catch{return{isValid:!1,value:ut}}}),p=e.adjustScalarBytes||(_=>_),f=e.domain||((_,v,O)=>{if(Ts("phflag",O),v.length||O)throw new Error("Contexts/pre-hash are not supported");return _});function y(_,v){vn("coordinate "+_,v,ut,u)}function g(_){if(!(_ instanceof b))throw new Error("ExtendedPoint expected")}const w=Bc((_,v)=>{const{ex:O,ey:T,ez:P}=_,N=_.is0();v==null&&(v=N?Jy:r.inv(P));const F=l(O*v),M=l(T*v),z=l(P*v);if(N)return{x:ut,y:We};if(z!==We)throw new Error("invZ was invalid");return{x:F,y:M}}),m=Bc(_=>{const{a:v,d:O}=e;if(_.is0())throw new Error("bad point: ZERO");const{ex:T,ey:P,ez:N,et:F}=_,M=l(T*T),z=l(P*P),q=l(N*N),V=l(q*q),K=l(M*v),ee=l(q*l(K+z)),G=l(V+l(O*l(M*z)));if(ee!==G)throw new Error("bad point: equation left != right (1)");const W=l(T*P),ye=l(N*F);if(W!==ye)throw new Error("bad point: equation left != right (2)");return!0});class b{constructor(v,O,T,P){this.ex=v,this.ey=O,this.ez=T,this.et=P,y("x",v),y("y",O),y("z",T),y("t",P),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(v){if(v instanceof b)throw new Error("extended point not allowed");const{x:O,y:T}=v||{};return y("x",O),y("y",T),new b(O,T,We,l(O*T))}static normalizeZ(v){const O=r.invertBatch(v.map(T=>T.ez));return v.map((T,P)=>T.toAffine(O[P])).map(b.fromAffine)}static msm(v,O){return Yy(b,h,v,O)}_setWindowSize(v){D.setWindowSize(this,v)}assertValidity(){m(this)}equals(v){g(v);const{ex:O,ey:T,ez:P}=this,{ex:N,ey:F,ez:M}=v,z=l(O*M),q=l(N*P),V=l(T*M),K=l(F*P);return z===q&&V===K}is0(){return this.equals(b.ZERO)}negate(){return new b(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){const{a:v}=e,{ex:O,ey:T,ez:P}=this,N=l(O*O),F=l(T*T),M=l(vi*l(P*P)),z=l(v*N),q=O+T,V=l(l(q*q)-N-F),K=z+F,ee=K-M,G=z-F,W=l(V*ee),ye=l(K*G),ue=l(V*G),le=l(ee*K);return new b(W,ye,le,ue)}add(v){g(v);const{a:O,d:T}=e,{ex:P,ey:N,ez:F,et:M}=this,{ex:z,ey:q,ez:V,et:K}=v;if(O===BigInt(-1)){const Nf=l((N-P)*(q+z)),Bf=l((N+P)*(q-z)),Ua=l(Bf-Nf);if(Ua===ut)return this.double();const Ff=l(F*vi*K),Lf=l(M*vi*V),Uf=Lf+Ff,kf=Bf+Nf,Mf=Lf-Ff,UD=l(Uf*Ua),kD=l(kf*Mf),MD=l(Uf*Mf),jD=l(Ua*kf);return new b(UD,kD,jD,MD)}const ee=l(P*z),G=l(N*q),W=l(M*T*K),ye=l(F*V),ue=l((P+N)*(z+q)-ee-G),le=ye-W,$e=ye+W,Me=l(G-O*ee),Kt=l(ue*le),BD=l($e*Me),FD=l(ue*Me),LD=l(le*$e);return new b(Kt,BD,LD,FD)}subtract(v){return this.add(v.negate())}wNAF(v){return D.wNAFCached(this,v,b.normalizeZ)}multiply(v){const O=v;vn("scalar",O,We,n);const{p:T,f:P}=this.wNAF(O);return b.normalizeZ([T,P])[0]}multiplyUnsafe(v,O=b.ZERO){const T=v;return vn("scalar",T,ut,n),T===ut?$:this.is0()||T===We?this:D.wNAFCachedUnsafe(this,T,b.normalizeZ,O)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return D.unsafeLadder(this,n).is0()}toAffine(v){return w(this,v)}clearCofactor(){const{h:v}=e;return v===We?this:this.multiplyUnsafe(v)}static fromHex(v,O=!1){const{d:T,a:P}=e,N=r.BYTES;v=Rt("pointHex",v,N),Ts("zip215",O);const F=v.slice(),M=v[N-1];F[N-1]=M&-129;const z=mi(F),q=O?u:r.ORDER;vn("pointHex.y",z,ut,q);const V=l(z*z),K=l(V-We),ee=l(T*V-P);let{isValid:G,value:W}=d(K,ee);if(!G)throw new Error("Point.fromHex: invalid y coordinate");const ye=(W&We)===We,ue=(M&128)!==0;if(!O&&W===ut&&ue)throw new Error("Point.fromHex: x=0 and x_0=1");return ue!==ye&&(W=l(-W)),b.fromAffine({x:W,y:z})}static fromPrivateKey(v){return x(v).point}toRawBytes(){const{x:v,y:O}=this.toAffine(),T=Cs(O,r.BYTES);return T[T.length-1]|=v&We?128:0,T}toHex(){return Rs(this.toRawBytes())}}b.BASE=new b(e.Gx,e.Gy,We,l(e.Gx*e.Gy)),b.ZERO=new b(ut,We,We,ut);const{BASE:E,ZERO:$}=b,D=Gy(b,a*8);function S(_){return we(_,n)}function A(_){return S(mi(_))}function x(_){const v=r.BYTES;_=Rt("private key",_,v);const O=Rt("hashed private key",s(_),2*v),T=p(O.slice(0,v)),P=O.slice(v,2*v),N=A(T),F=E.multiply(N),M=F.toRawBytes();return{head:T,prefix:P,scalar:N,point:F,pointBytes:M}}function k(_){return x(_).pointBytes}function C(_=new Uint8Array,...v){const O=Nc(...v);return A(s(f(O,Rt("context",_),!!i)))}function B(_,v,O={}){_=Rt("message",_),i&&(_=i(_));const{prefix:T,scalar:P,pointBytes:N}=x(v),F=C(O.context,T,_),M=E.multiply(F).toRawBytes(),z=C(O.context,M,N,_),q=S(F+z*P);vn("signature.s",q,ut,n);const V=Nc(M,Cs(q,r.BYTES));return Rt("result",V,r.BYTES*2)}const j=Xy;function I(_,v,O,T=j){const{context:P,zip215:N}=T,F=r.BYTES;_=Rt("signature",_,2*F),v=Rt("message",v),O=Rt("publicKey",O,F),N!==void 0&&Ts("zip215",N),i&&(v=i(v));const M=mi(_.slice(F,2*F));let z,q,V;try{z=b.fromHex(O,N),q=b.fromHex(_.slice(0,F),N),V=E.multiplyUnsafe(M)}catch{return!1}if(!N&&z.isSmallOrder())return!1;const K=C(P,q.toRawBytes(),z.toRawBytes(),v);return q.add(z.multiplyUnsafe(K)).subtract(V).clearCofactor().equals(b.ZERO)}return E._setWindowSize(8),{CURVE:e,getPublicKey:k,sign:B,verify:I,ExtendedPoint:b,utils:{getExtendedPublicKey:x,randomPrivateKey:()=>o(r.BYTES),precompute(_=8,v=b.BASE){return v._setWindowSize(_),v.multiply(BigInt(3)),v}}}}BigInt(0),BigInt(1);const js=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),Vc=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);const tw=BigInt(1),Kc=BigInt(2);BigInt(3);const rw=BigInt(5),nw=BigInt(8);function iw(t){const e=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),s=js,o=t*t%s*t%s,a=mt(o,Kc,s)*o%s,c=mt(a,tw,s)*t%s,u=mt(c,rw,s)*c%s,l=mt(u,e,s)*u%s,h=mt(l,r,s)*l%s,d=mt(h,n,s)*h%s,p=mt(d,i,s)*d%s,f=mt(p,i,s)*d%s,y=mt(f,e,s)*u%s;return{pow_p_5_8:mt(y,Kc,s)*t%s,b2:o}}function sw(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function ow(t,e){const r=js,n=we(e*e*e,r),i=we(n*n*e,r),s=iw(t*i).pow_p_5_8;let o=we(t*n*s,r);const a=we(e*o*o,r),c=o,u=we(o*Vc,r),l=a===t,h=a===we(-t,r),d=a===we(-t*Vc,r);return l&&(o=c),(h||d)&&(o=u),jy(o,r)&&(o=we(-o,r)),{isValid:l||h,value:o}}const aw=(()=>Mc(js,void 0,!0))(),cw=(()=>({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:aw,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:nw,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Ay,randomBytes:Oc,adjustScalarBytes:sw,uvRatio:ow}))(),Hc=(()=>ew(cw))(),uw="EdDSA",lw="JWT",Ei=".",_i="base64url",Wc="utf8",Gc="utf8",hw=":",dw="did",fw="key",Yc="base58btc",pw="z",gw="K36",yw=32;function qs(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Zc(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?qs(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function Jc(t,e){e||(e=t.reduce((i,s)=>i+s.length,0));const r=Zc(e);let n=0;for(const i of t)r.set(i,n),n+=i.length;return qs(r)}function ww(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var y=0,g=0,w=0,m=f.length;w!==m&&f[w]===0;)w++,y++;for(var b=(m-w)*l+1>>>0,E=new Uint8Array(b);w!==m;){for(var $=f[w],D=0,S=b-1;($!==0||D<g)&&S!==-1;S--,D++)$+=256*E[S]>>>0,E[S]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");g=D,w++}for(var A=b-g;A!==b&&E[A]===0;)A++;for(var x=c.repeat(y);A<b;++A)x+=t.charAt(E[A]);return x}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var y=0;if(f[y]!==" "){for(var g=0,w=0;f[y]===c;)g++,y++;for(var m=(f.length-y)*u+1>>>0,b=new Uint8Array(m);f[y];){var E=r[f.charCodeAt(y)];if(E===255)return;for(var $=0,D=m-1;(E!==0||$<w)&&D!==-1;D--,$++)E+=a*b[D]>>>0,b[D]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");w=$,y++}if(f[y]!==" "){for(var S=m-w;S!==m&&b[S]===0;)S++;for(var A=new Uint8Array(g+(m-S)),x=g;S!==m;)A[x++]=b[S++];return A}}}function p(f){var y=d(f);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:d,decode:p}}var mw=ww,bw=mw;const Xc=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},vw=t=>new TextEncoder().encode(t),Ew=t=>new TextDecoder().decode(t);class _w{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class Sw{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}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 Qc(this,e)}}class xw{constructor(e){this.decoders=e}or(e){return Qc(this,e)}decode(e){const r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Qc=(t,e)=>new xw({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class Iw{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new _w(e,r,n),this.decoder=new Sw(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Si=({name:t,prefix:e,encode:r,decode:n})=>new Iw(t,e,r,n),En=({prefix:t,name:e,alphabet:r})=>{const{encode:n,decode:i}=bw(r,e);return Si({prefix:t,name:e,encode:n,decode:s=>Xc(i(s))})},Dw=(t,e,r,n)=>{const i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let s=t.length;for(;t[s-1]==="=";)--s;const o=new Uint8Array(s*r/8|0);let a=0,c=0,u=0;for(let l=0;l<s;++l){const h=i[t[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|h,a+=r,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},Ow=(t,e,r)=>{const n=e[e.length-1]==="=",i=(1<<r)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[i&a>>o];if(o&&(s+=e[i&a<<r-o]),n)for(;s.length*r&7;)s+="=";return s},Ae=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>Si({prefix:e,name:t,encode(i){return Ow(i,n,r)},decode(i){return Dw(i,n,r,t)}}),$w=Si({prefix:"\0",name:"identity",encode:t=>Ew(t),decode:t=>vw(t)});var Aw=Object.freeze({__proto__:null,identity:$w});const Pw=Ae({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Tw=Object.freeze({__proto__:null,base2:Pw});const Rw=Ae({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Cw=Object.freeze({__proto__:null,base8:Rw});const Nw=En({prefix:"9",name:"base10",alphabet:"0123456789"});var Bw=Object.freeze({__proto__:null,base10:Nw});const Fw=Ae({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Lw=Ae({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Uw=Object.freeze({__proto__:null,base16:Fw,base16upper:Lw});const kw=Ae({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Mw=Ae({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jw=Ae({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),qw=Ae({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),zw=Ae({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Vw=Ae({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Kw=Ae({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Hw=Ae({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Ww=Ae({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Gw=Object.freeze({__proto__:null,base32:kw,base32upper:Mw,base32pad:jw,base32padupper:qw,base32hex:zw,base32hexupper:Vw,base32hexpad:Kw,base32hexpadupper:Hw,base32z:Ww});const Yw=En({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Zw=En({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Jw=Object.freeze({__proto__:null,base36:Yw,base36upper:Zw});const Xw=En({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Qw=En({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var em=Object.freeze({__proto__:null,base58btc:Xw,base58flickr:Qw});const tm=Ae({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rm=Ae({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),nm=Ae({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),im=Ae({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var sm=Object.freeze({__proto__:null,base64:tm,base64pad:rm,base64url:nm,base64urlpad:im});const eu=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),om=eu.reduce((t,e,r)=>(t[r]=e,t),[]),am=eu.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function cm(t){return t.reduce((e,r)=>(e+=om[r],e),"")}function um(t){const e=[];for(const r of t){const n=am[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}const lm=Si({prefix:"\u{1F680}",name:"base256emoji",encode:cm,decode:um});var hm=Object.freeze({__proto__:null,base256emoji:lm}),dm=ru,tu=128,fm=127,pm=~fm,gm=Math.pow(2,31);function ru(t,e,r){e=e||[],r=r||0;for(var n=r;t>=gm;)e[r++]=t&255|tu,t/=128;for(;t&pm;)e[r++]=t&255|tu,t>>>=7;return e[r]=t|0,ru.bytes=r-n+1,e}var ym=zs,wm=128,nu=127;function zs(t,n){var r=0,n=n||0,i=0,s=n,o,a=t.length;do{if(s>=a)throw zs.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=i<28?(o&nu)<<i:(o&nu)*Math.pow(2,i),i+=7}while(o>=wm);return zs.bytes=s-n,r}var mm=Math.pow(2,7),bm=Math.pow(2,14),vm=Math.pow(2,21),Em=Math.pow(2,28),_m=Math.pow(2,35),Sm=Math.pow(2,42),xm=Math.pow(2,49),Im=Math.pow(2,56),Dm=Math.pow(2,63),Om=function(t){return t<mm?1:t<bm?2:t<vm?3:t<Em?4:t<_m?5:t<Sm?6:t<xm?7:t<Im?8:t<Dm?9:10},$m={encode:dm,decode:ym,encodingLength:Om},iu=$m;const su=(t,e,r=0)=>(iu.encode(t,e,r),e),ou=t=>iu.encodingLength(t),Vs=(t,e)=>{const r=e.byteLength,n=ou(t),i=n+ou(r),s=new Uint8Array(i+r);return su(t,s,0),su(r,s,n),s.set(e,i),new Am(t,r,e,s)};class Am{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}}const au=({name:t,code:e,encode:r})=>new Pm(t,e,r);class Pm{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?Vs(this.code,r):r.then(n=>Vs(this.code,n))}else throw Error("Unknown type, must be binary type")}}const cu=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Tm=au({name:"sha2-256",code:18,encode:cu("SHA-256")}),Rm=au({name:"sha2-512",code:19,encode:cu("SHA-512")});var Cm=Object.freeze({__proto__:null,sha256:Tm,sha512:Rm});const uu=0,Nm="identity",lu=Xc;var Bm=Object.freeze({__proto__:null,identity:{code:uu,name:Nm,encode:lu,digest:t=>Vs(uu,lu(t))}});new TextEncoder,new TextDecoder;const hu={...Aw,...Tw,...Cw,...Bw,...Uw,...Gw,...Jw,...em,...sm,...hm};({...Cm,...Bm});function du(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}const fu=du("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ks=du("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);const e=Zc(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),pu={utf8:fu,"utf-8":fu,hex:hu.base16,latin1:Ks,ascii:Ks,binary:Ks,...hu};function xi(t,e="utf8"){const r=pu[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}function Ur(t,e="utf8"){const r=pu[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?qs(globalThis.Buffer.from(t,"utf-8")):r.decoder.decode(`${r.prefix}${t}`)}function gu(t){return Nr(xi(Ur(t,_i),Wc))}function Ii(t){return xi(Ur(dr(t),Wc),_i)}function yu(t){const e=Ur(gw,Yc),r=pw+xi(Jc([e,t]),Yc);return[dw,fw,r].join(hw)}function Fm(t){return xi(t,_i)}function Lm(t){return Ur(t,_i)}function Um(t){return Ur([Ii(t.header),Ii(t.payload)].join(Ei),Gc)}function km(t){return[Ii(t.header),Ii(t.payload),Fm(t.signature)].join(Ei)}function Hs(t){const e=t.split(Ei),r=gu(e[0]),n=gu(e[1]),i=Lm(e[2]),s=Ur(e.slice(0,2).join(Ei),Gc);return{header:r,payload:n,signature:i,data:s}}function wu(t=Oc(yw)){const e=Hc.getPublicKey(t);return{secretKey:Jc([t,e]),publicKey:e}}async function Mm(t,e,r,n,i=L.fromMiliseconds(Date.now())){const s={alg:uw,typ:lw},o=yu(n.publicKey),a=i+r,c={iss:o,sub:t,aud:e,iat:i,exp:a},u=Um({header:s,payload:c}),l=Hc.sign(u,n.secretKey.slice(0,32));return km({header:s,payload:c,signature:l})}var mu=function(t,e,r){if(r||arguments.length===2)for(var n=0,i=e.length,s;n<i;n++)(s||!(n in e))&&(s||(s=Array.prototype.slice.call(e,0,n)),s[n]=e[n]);return t.concat(s||Array.prototype.slice.call(e))},jm=function(){function t(e,r,n){this.name=e,this.version=r,this.os=n,this.type="browser"}return t}(),qm=function(){function t(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return t}(),zm=function(){function t(e,r,n,i){this.name=e,this.version=r,this.os=n,this.bot=i,this.type="bot-device"}return t}(),Vm=function(){function t(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return t}(),Km=function(){function t(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return t}(),Hm=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,Wm=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,bu=3,Gm=[["aol",/AOLShield\/([0-9\._]+)/],["edge",/Edge\/([0-9\._]+)/],["edge-ios",/EdgiOS\/([0-9\._]+)/],["yandexbrowser",/YaBrowser\/([0-9\._]+)/],["kakaotalk",/KAKAOTALK\s([0-9\.]+)/],["samsung",/SamsungBrowser\/([0-9\.]+)/],["silk",/\bSilk\/([0-9._-]+)\b/],["miui",/MiuiBrowser\/([0-9\.]+)$/],["beaker",/BeakerBrowser\/([0-9\.]+)/],["edge-chromium",/EdgA?\/([0-9\.]+)/],["chromium-webview",/(?!Chrom.*OPR)wv\).*Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["chrome",/(?!Chrom.*OPR)Chrom(?:e|ium)\/([0-9\.]+)(:?\s|$)/],["phantomjs",/PhantomJS\/([0-9\.]+)(:?\s|$)/],["crios",/CriOS\/([0-9\.]+)(:?\s|$)/],["firefox",/Firefox\/([0-9\.]+)(?:\s|$)/],["fxios",/FxiOS\/([0-9\.]+)/],["opera-mini",/Opera Mini.*Version\/([0-9\.]+)/],["opera",/Opera\/([0-9\.]+)(?:\s|$)/],["opera",/OPR\/([0-9\.]+)(:?\s|$)/],["pie",/^Microsoft Pocket Internet Explorer\/(\d+\.\d+)$/],["pie",/^Mozilla\/\d\.\d+\s\(compatible;\s(?:MSP?IE|MSInternet Explorer) (\d+\.\d+);.*Windows CE.*\)$/],["netfront",/^Mozilla\/\d\.\d+.*NetFront\/(\d.\d)/],["ie",/Trident\/7\.0.*rv\:([0-9\.]+).*\).*Gecko$/],["ie",/MSIE\s([0-9\.]+);.*Trident\/[4-7].0/],["ie",/MSIE\s(7\.0)/],["bb10",/BB10;\sTouch.*Version\/([0-9\.]+)/],["android",/Android\s([0-9\.]+)/],["ios",/Version\/([0-9\._]+).*Mobile.*Safari.*/],["safari",/Version\/([0-9\._]+).*Safari/],["facebook",/FB[AS]V\/([0-9\.]+)/],["instagram",/Instagram\s([0-9\.]+)/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Mobile/],["ios-webview",/AppleWebKit\/([0-9\.]+).*Gecko\)$/],["curl",/^curl\/([0-9\.]+)$/],["searchbot",Hm]],vu=[["iOS",/iP(hone|od|ad)/],["Android OS",/Android/],["BlackBerry OS",/BlackBerry|BB10/],["Windows Mobile",/IEMobile/],["Amazon OS",/Kindle/],["Windows 3.11",/Win16/],["Windows 95",/(Windows 95)|(Win95)|(Windows_95)/],["Windows 98",/(Windows 98)|(Win98)/],["Windows 2000",/(Windows NT 5.0)|(Windows 2000)/],["Windows XP",/(Windows NT 5.1)|(Windows XP)/],["Windows Server 2003",/(Windows NT 5.2)/],["Windows Vista",/(Windows NT 6.0)/],["Windows 7",/(Windows NT 6.1)/],["Windows 8",/(Windows NT 6.2)/],["Windows 8.1",/(Windows NT 6.3)/],["Windows 10",/(Windows NT 10.0)/],["Windows ME",/Windows ME/],["Windows CE",/Windows CE|WinCE|Microsoft Pocket Internet Explorer/],["Open BSD",/OpenBSD/],["Sun OS",/SunOS/],["Chrome OS",/CrOS/],["Linux",/(Linux)|(X11)/],["Mac OS",/(Mac_PowerPC)|(Macintosh)/],["QNX",/QNX/],["BeOS",/BeOS/],["OS/2",/OS\/2/]];function Ym(t){return t?Eu(t):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new Km:typeof navigator<"u"?Eu(navigator.userAgent):Xm()}function Zm(t){return t!==""&&Gm.reduce(function(e,r){var n=r[0],i=r[1];if(e)return e;var s=i.exec(t);return!!s&&[n,s]},!1)}function Eu(t){var e=Zm(t);if(!e)return null;var r=e[0],n=e[1];if(r==="searchbot")return new Vm;var i=n[1]&&n[1].split(".").join("_").split("_").slice(0,3);i?i.length<bu&&(i=mu(mu([],i,!0),Qm(bu-i.length),!0)):i=[];var s=i.join("."),o=Jm(t),a=Wm.exec(t);return a&&a[1]?new zm(r,s,o,a[1]):new jm(r,s,o)}function Jm(t){for(var e=0,r=vu.length;e<r;e++){var n=vu[e],i=n[0],s=n[1],o=s.exec(t);if(o)return i}return null}function Xm(){var t=typeof process<"u"&&process.version;return t?new qm(process.version.slice(1)):null}function Qm(t){for(var e=[],r=0;r<t;r++)e.push("0");return e}var se={};Object.defineProperty(se,"__esModule",{value:!0}),se.getLocalStorage=se.getLocalStorageOrThrow=se.getCrypto=se.getCryptoOrThrow=_u=se.getLocation=se.getLocationOrThrow=Ws=se.getNavigator=se.getNavigatorOrThrow=_n=se.getDocument=se.getDocumentOrThrow=se.getFromWindowOrThrow=se.getFromWindow=void 0;function pr(t){let e;return typeof window<"u"&&typeof window[t]<"u"&&(e=window[t]),e}se.getFromWindow=pr;function kr(t){const e=pr(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}se.getFromWindowOrThrow=kr;function eb(){return kr("document")}se.getDocumentOrThrow=eb;function tb(){return pr("document")}var _n=se.getDocument=tb;function rb(){return kr("navigator")}se.getNavigatorOrThrow=rb;function nb(){return pr("navigator")}var Ws=se.getNavigator=nb;function ib(){return kr("location")}se.getLocationOrThrow=ib;function sb(){return pr("location")}var _u=se.getLocation=sb;function ob(){return kr("crypto")}se.getCryptoOrThrow=ob;function ab(){return pr("crypto")}se.getCrypto=ab;function cb(){return kr("localStorage")}se.getLocalStorageOrThrow=cb;function ub(){return pr("localStorage")}se.getLocalStorage=ub;var Gs={};Object.defineProperty(Gs,"__esModule",{value:!0});var Su=Gs.getWindowMetadata=void 0;const xu=se;function lb(){let t,e;try{t=xu.getDocumentOrThrow(),e=xu.getLocationOrThrow()}catch{return null}function r(){const h=t.getElementsByTagName("link"),d=[];for(let p=0;p<h.length;p++){const f=h[p],y=f.getAttribute("rel");if(y&&y.toLowerCase().indexOf("icon")>-1){const g=f.getAttribute("href");if(g)if(g.toLowerCase().indexOf("https:")===-1&&g.toLowerCase().indexOf("http:")===-1&&g.indexOf("//")!==0){let w=e.protocol+"//"+e.host;if(g.indexOf("/")===0)w+=g;else{const m=e.pathname.split("/");m.pop();const b=m.join("/");w+=b+"/"+g}d.push(w)}else if(g.indexOf("//")===0){const w=e.protocol+g;d.push(w)}else d.push(g)}}return d}function n(...h){const d=t.getElementsByTagName("meta");for(let p=0;p<d.length;p++){const f=d[p],y=["itemprop","property","name"].map(g=>f.getAttribute(g)).filter(g=>g?h.includes(g):!1);if(y.length&&y){const g=f.getAttribute("content");if(g)return g}}return""}function i(){let h=n("name","og:site_name","og:title","twitter:title");return h||(h=t.title),h}function s(){return n("description","og:description","twitter:description","keywords")}const o=i(),a=s(),c=e.origin,u=r();return{description:a,url:c,icons:u,name:o}}Su=Gs.getWindowMetadata=lb;function Sn(t,{strict:e=!0}={}){return!t||typeof t!="string"?!1:e?/^0x[0-9a-fA-F]*$/.test(t):t.startsWith("0x")}function Iu(t){return Sn(t,{strict:!1})?Math.ceil((t.length-2)/2):t.length}const Du="2.23.2";let Ys={getDocsUrl:({docsBaseUrl:t,docsPath:e="",docsSlug:r})=>e?`${t??"https://viem.sh"}${e}${r?`#${r}`:""}`:void 0,version:`viem@${Du}`};class gr extends Error{constructor(e,r={}){const n=(()=>r.cause instanceof gr?r.cause.details:r.cause?.message?r.cause.message:r.details)(),i=(()=>r.cause instanceof gr&&r.cause.docsPath||r.docsPath)(),s=Ys.getDocsUrl?.({...r,docsPath:i}),o=[e||"An error occurred.","",...r.metaMessages?[...r.metaMessages,""]:[],...s?[`Docs: ${s}`]:[],...n?[`Details: ${n}`]:[],...Ys.version?[`Version: ${Ys.version}`]:[]].join(`
15
+ `);super(o,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"metaMessages",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),this.details=n,this.docsPath=i,this.metaMessages=r.metaMessages,this.name=r.name??this.name,this.shortMessage=e,this.version=Du}walk(e){return Ou(this,e)}}function Ou(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause!==void 0?Ou(t.cause,e):e?null:t}class $u extends gr{constructor({size:e,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${r}).`,{name:"SizeExceedsPaddingSizeError"})}}function Mr(t,{dir:e,size:r=32}={}){return typeof t=="string"?hb(t,{dir:e,size:r}):db(t,{dir:e,size:r})}function hb(t,{dir:e,size:r=32}={}){if(r===null)return t;const n=t.replace("0x","");if(n.length>r*2)throw new $u({size:Math.ceil(n.length/2),targetSize:r,type:"hex"});return`0x${n[e==="right"?"padEnd":"padStart"](r*2,"0")}`}function db(t,{dir:e,size:r=32}={}){if(r===null)return t;if(t.length>r)throw new $u({size:t.length,targetSize:r,type:"bytes"});const n=new Uint8Array(r);for(let i=0;i<r;i++){const s=e==="right";n[s?i:r-i-1]=t[s?i:t.length-i-1]}return n}class fb extends gr{constructor({max:e,min:r,signed:n,size:i,value:s}){super(`Number "${s}" is not in safe ${i?`${i*8}-bit ${n?"signed":"unsigned"} `:""}integer range ${e?`(${r} to ${e})`:`(above ${r})`}`,{name:"IntegerOutOfRangeError"})}}class pb extends gr{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed ${r} bytes. Given size: ${e} bytes.`,{name:"SizeOverflowError"})}}function jr(t,{size:e}){if(Iu(t)>e)throw new pb({givenSize:Iu(t),maxSize:e})}function Zs(t,e={}){const{signed:r}=e;e.size&&jr(t,{size:e.size});const n=BigInt(t);if(!r)return n;const i=(t.length-2)/2,s=(1n<<BigInt(i)*8n-1n)-1n;return n<=s?n:n-BigInt(`0x${"f".padStart(i*2,"f")}`)-1n}function gb(t,e={}){return Number(Zs(t,e))}const yb=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Js(t,e={}){return typeof t=="number"||typeof t=="bigint"?Pu(t,e):typeof t=="string"?bb(t,e):typeof t=="boolean"?wb(t,e):Au(t,e)}function wb(t,e={}){const r=`0x${Number(t)}`;return typeof e.size=="number"?(jr(r,{size:e.size}),Mr(r,{size:e.size})):r}function Au(t,e={}){let r="";for(let i=0;i<t.length;i++)r+=yb[t[i]];const n=`0x${r}`;return typeof e.size=="number"?(jr(n,{size:e.size}),Mr(n,{dir:"right",size:e.size})):n}function Pu(t,e={}){const{signed:r,size:n}=e,i=BigInt(t);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof t=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&i>s||i<o){const c=typeof t=="bigint"?"n":"";throw new fb({max:s?`${s}${c}`:void 0,min:`${o}${c}`,signed:r,size:n,value:`${t}${c}`})}const a=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?Mr(a,{size:n}):a}const mb=new TextEncoder;function bb(t,e={}){const r=mb.encode(t);return Au(r,e)}const vb=new TextEncoder;function Eb(t,e={}){return typeof t=="number"||typeof t=="bigint"?Sb(t,e):typeof t=="boolean"?_b(t,e):Sn(t)?Ru(t,e):Cu(t,e)}function _b(t,e={}){const r=new Uint8Array(1);return r[0]=Number(t),typeof e.size=="number"?(jr(r,{size:e.size}),Mr(r,{size:e.size})):r}const Ct={zero:48,nine:57,A:65,F:70,a:97,f:102};function Tu(t){if(t>=Ct.zero&&t<=Ct.nine)return t-Ct.zero;if(t>=Ct.A&&t<=Ct.F)return t-(Ct.A-10);if(t>=Ct.a&&t<=Ct.f)return t-(Ct.a-10)}function Ru(t,e={}){let r=t;e.size&&(jr(r,{size:e.size}),r=Mr(r,{dir:"right",size:e.size}));let n=r.slice(2);n.length%2&&(n=`0${n}`);const i=n.length/2,s=new Uint8Array(i);for(let o=0,a=0;o<i;o++){const c=Tu(n.charCodeAt(a++)),u=Tu(n.charCodeAt(a++));if(c===void 0||u===void 0)throw new gr(`Invalid byte sequence ("${n[a-2]}${n[a-1]}" in "${n}").`);s[o]=c*16+u}return s}function Sb(t,e){const r=Pu(t,e);return Ru(r)}function Cu(t,e={}){const r=vb.encode(t);return typeof e.size=="number"?(jr(r,{size:e.size}),Mr(r,{dir:"right",size:e.size})):r}function Di(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function xb(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function xn(t,...e){if(!xb(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Ib(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Di(t.outputLen),Di(t.blockLen)}function qr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Nu(t,e){xn(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const Oi=BigInt(2**32-1),Bu=BigInt(32);function Db(t,e=!1){return e?{h:Number(t&Oi),l:Number(t>>Bu&Oi)}:{h:Number(t>>Bu&Oi)|0,l:Number(t&Oi)|0}}function Ob(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:s,l:o}=Db(t[i],e);[r[i],n[i]]=[s,o]}return[r,n]}const $b=(t,e,r)=>t<<r|e>>>32-r,Ab=(t,e,r)=>e<<r|t>>>32-r,Pb=(t,e,r)=>e<<r-32|t>>>64-r,Tb=(t,e,r)=>t<<r-32|e>>>64-r,zr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Rb(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Xs(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function bt(t,e){return t<<32-e|t>>>e}const Fu=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function Cb(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function Lu(t){for(let e=0;e<t.length;e++)t[e]=Cb(t[e])}function Nb(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function $i(t){return typeof t=="string"&&(t=Nb(t)),xn(t),t}function Bb(...t){let e=0;for(let n=0;n<t.length;n++){const i=t[n];xn(i),e+=i.length}const r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){const s=t[n];r.set(s,i),i+=s.length}return r}class Qs{clone(){return this._cloneInto()}}function Uu(t){const e=n=>t().update($i(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function ku(t=32){if(zr&&typeof zr.getRandomValues=="function")return zr.getRandomValues(new Uint8Array(t));if(zr&&typeof zr.randomBytes=="function")return zr.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}const Mu=[],ju=[],qu=[],Fb=BigInt(0),In=BigInt(1),Lb=BigInt(2),Ub=BigInt(7),kb=BigInt(256),Mb=BigInt(113);for(let t=0,e=In,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],Mu.push(2*(5*n+r)),ju.push((t+1)*(t+2)/2%64);let i=Fb;for(let s=0;s<7;s++)e=(e<<In^(e>>Ub)*Mb)%kb,e&Lb&&(i^=In<<(In<<BigInt(s))-In);qu.push(i)}const[jb,qb]=Ob(qu,!0),zu=(t,e,r)=>r>32?Pb(t,e,r):$b(t,e,r),Vu=(t,e,r)=>r>32?Tb(t,e,r):Ab(t,e,r);function zb(t,e=24){const r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let o=0;o<10;o++)r[o]=t[o]^t[o+10]^t[o+20]^t[o+30]^t[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,c=(o+2)%10,u=r[c],l=r[c+1],h=zu(u,l,1)^r[a],d=Vu(u,l,1)^r[a+1];for(let p=0;p<50;p+=10)t[o+p]^=h,t[o+p+1]^=d}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=ju[o],c=zu(i,s,a),u=Vu(i,s,a),l=Mu[o];i=t[l],s=t[l+1],t[l]=c,t[l+1]=u}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}t[0]^=jb[n],t[1]^=qb[n]}r.fill(0)}class eo extends Qs{constructor(e,r,n,i=!1,s=24){if(super(),this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Di(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=Rb(this.state)}keccak(){Fu||Lu(this.state32),zb(this.state32,this.rounds),Fu||Lu(this.state32),this.posOut=0,this.pos=0}update(e){qr(this);const{blockLen:r,state:n}=this;e=$i(e);const i=e.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);for(let a=0;a<o;a++)n[this.pos++]^=e[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:r,pos:n,blockLen:i}=this;e[n]^=r,r&128&&n===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){qr(this,!1),xn(e),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,s=e.length;i<s;){this.posOut>=n&&this.keccak();const o=Math.min(n-this.posOut,s-i);e.set(r.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Di(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Nu(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:r,suffix:n,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new eo(r,n,i,o,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}}const Ku=((t,e,r)=>Uu(()=>new eo(e,t,r)))(1,136,256/8);function Hu(t,e){const r=e||"hex",n=Ku(Sn(t,{strict:!1})?Eb(t):t);return r==="bytes"?n:Js(n)}class Wu extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const r=super.get(e);return super.has(e)&&r!==void 0&&(this.delete(e),super.set(e,r)),r}set(e,r){if(super.set(e,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const to=new Wu(8192);function Vb(t,e){if(to.has(`${t}.${e}`))return to.get(`${t}.${e}`);const r=e?`${e}${t.toLowerCase()}`:t.substring(2).toLowerCase(),n=Hu(Cu(r),"bytes"),i=(e?r.substring(`${e}0x`.length):r).split("");for(let o=0;o<40;o+=2)n[o>>1]>>4>=8&&i[o]&&(i[o]=i[o].toUpperCase()),(n[o>>1]&15)>=8&&i[o+1]&&(i[o+1]=i[o+1].toUpperCase());const s=`0x${i.join("")}`;return to.set(`${t}.${e}`,s),s}function Kb(t){const e=Hu(`0x${t.substring(4)}`).substring(26);return Vb(`0x${e}`)}async function Hb({hash:t,signature:e}){const r=Sn(t)?t:Js(t),{secp256k1:n}=await Promise.resolve().then(function(){return D1});return`0x${(()=>{if(typeof e=="object"&&"r"in e&&"s"in e){const{r:u,s:l,v:h,yParity:d}=e,p=Number(d??h),f=Gu(p);return new n.Signature(Zs(u),Zs(l)).addRecoveryBit(f)}const o=Sn(e)?e:Js(e),a=gb(`0x${o.slice(130)}`),c=Gu(a);return n.Signature.fromCompact(o.substring(2,130)).addRecoveryBit(c)})().recoverPublicKey(r.substring(2)).toHex(!1)}`}function Gu(t){if(t===0||t===1)return t;if(t===27)return 0;if(t===28)return 1;throw new Error("Invalid yParityOrV value")}async function Wb({hash:t,signature:e}){return Kb(await Hb({hash:t,signature:e}))}function Gb(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),c=n?4:0,u=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+u,a,n)}function Yb(t,e,r){return t&e^~t&r}function Zb(t,e,r){return t&e^t&r^e&r}class Jb extends Qs{constructor(e,r,n,i){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Xs(this.buffer)}update(e){qr(this);const{view:r,buffer:n,blockLen:i}=this;e=$i(e);const s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Xs(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){qr(this),Nu(e,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let h=o;h<i;h++)r[h]=0;Gb(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=Xs(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.length=i,e.pos=a,e.finished=s,e.destroyed=o,i%r&&e.buffer.set(n),e}}const Xb=new Uint32Array([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]),Gt=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Yt=new Uint32Array(64);class Qb extends Jb{constructor(){super(64,32,8,!1),this.A=Gt[0]|0,this.B=Gt[1]|0,this.C=Gt[2]|0,this.D=Gt[3]|0,this.E=Gt[4]|0,this.F=Gt[5]|0,this.G=Gt[6]|0,this.H=Gt[7]|0}get(){const{A:e,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,r,n,i,s,o,a,c]}set(e,r,n,i,s,o,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let h=0;h<16;h++,r+=4)Yt[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){const d=Yt[h-15],p=Yt[h-2],f=bt(d,7)^bt(d,18)^d>>>3,y=bt(p,17)^bt(p,19)^p>>>10;Yt[h]=y+Yt[h-7]+f+Yt[h-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:l}=this;for(let h=0;h<64;h++){const d=bt(a,6)^bt(a,11)^bt(a,25),p=l+d+Yb(a,c,u)+Xb[h]+Yt[h]|0,y=(bt(n,2)^bt(n,13)^bt(n,22))+Zb(n,i,s)|0;l=u,u=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+y|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,i,s,o,a,c,u,l)}roundClean(){Yt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const Ai=Uu(()=>new Qb);new Wu(128);const e0=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),Yu=new Uint8Array(new Array(16).fill(0).map((t,e)=>e)),t0=Yu.map(t=>(9*t+5)%16);let r0=[Yu],n0=[t0];for(let t=0;t<4;t++)for(let e of[r0,n0])e.push(e[t].map(r=>e0[r]));/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Pi=BigInt(0),Ti=BigInt(1),i0=BigInt(2);function yr(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function vt(t){if(!yr(t))throw new Error("Uint8Array expected")}function Vr(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const s0=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Kr(t){vt(t);let e="";for(let r=0;r<t.length;r++)e+=s0[t[r]];return e}function Hr(t){const e=t.toString(16);return e.length&1?"0"+e:e}function ro(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Pi:BigInt("0x"+t)}const Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Zu(t){if(t>=Nt._0&&t<=Nt._9)return t-Nt._0;if(t>=Nt.A&&t<=Nt.F)return t-(Nt.A-10);if(t>=Nt.a&&t<=Nt.f)return t-(Nt.a-10)}function Wr(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){const o=Zu(t.charCodeAt(s)),a=Zu(t.charCodeAt(s+1));if(o===void 0||a===void 0){const c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function Et(t){return ro(Kr(t))}function no(t){return vt(t),ro(Kr(Uint8Array.from(t).reverse()))}function Zt(t,e){return Wr(t.toString(16).padStart(e*2,"0"))}function io(t,e){return Zt(t,e).reverse()}function o0(t){return Wr(Hr(t))}function Ue(t,e,r){let n;if(typeof e=="string")try{n=Wr(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(yr(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=n.length;if(typeof r=="number"&&i!==r)throw new Error(t+" of length "+r+" expected, got "+i);return n}function Xe(...t){let e=0;for(let n=0;n<t.length;n++){const i=t[n];vt(i),e+=i.length}const r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){const s=t[n];r.set(s,i),i+=s.length}return r}function a0(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Ri(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}const so=t=>typeof t=="bigint"&&Pi<=t;function Gr(t,e,r){return so(t)&&so(e)&&so(r)&&e<=t&&t<r}function Jt(t,e,r,n){if(!Gr(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ju(t){let e;for(e=0;t>Pi;t>>=Ti,e+=1);return e}function c0(t,e){return t>>BigInt(e)&Ti}function u0(t,e,r){return t|(r?Ti:Pi)<<BigInt(e)}const oo=t=>(i0<<BigInt(t-1))-Ti,ao=t=>new Uint8Array(t),Xu=t=>Uint8Array.from(t);function Qu(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=ao(t),i=ao(t),s=0;const o=()=>{n.fill(1),i.fill(0),s=0},a=(...h)=>r(i,n,...h),c=(h=ao())=>{i=a(Xu([0]),h),n=a(),h.length!==0&&(i=a(Xu([1]),h),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const d=[];for(;h<e;){n=a();const p=n.slice();d.push(p),h+=n.length}return Xe(...d)};return(h,d)=>{o(),c(h);let p;for(;!(p=d(u()));)c();return o(),p}}const l0={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||yr(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function Yr(t,e,r={}){const n=(i,s,o)=>{const a=l0[s];if(typeof a!="function")throw new Error("invalid validator function");const c=t[i];if(!(o&&c===void 0)&&!a(c,t))throw new Error("param "+String(i)+" is invalid. Expected "+s+", got "+c)};for(const[i,s]of Object.entries(e))n(i,s,!1);for(const[i,s]of Object.entries(r))n(i,s,!0);return t}const h0=()=>{throw new Error("not implemented")};function co(t){const e=new WeakMap;return(r,...n)=>{const i=e.get(r);if(i!==void 0)return i;const s=t(r,...n);return e.set(r,s),s}}var d0=Object.freeze({__proto__:null,isBytes:yr,abytes:vt,abool:Vr,bytesToHex:Kr,numberToHexUnpadded:Hr,hexToNumber:ro,hexToBytes:Wr,bytesToNumberBE:Et,bytesToNumberLE:no,numberToBytesBE:Zt,numberToBytesLE:io,numberToVarBytesBE:o0,ensureBytes:Ue,concatBytes:Xe,equalBytes:a0,utf8ToBytes:Ri,inRange:Gr,aInRange:Jt,bitLen:Ju,bitGet:c0,bitSet:u0,bitMask:oo,createHmacDrbg:Qu,validateObject:Yr,notImplemented:h0,memoized:co});const f0="0.1.1";function p0(){return f0}class qe extends Error{constructor(e,r={}){const n=(()=>{if(r.cause instanceof qe){if(r.cause.details)return r.cause.details;if(r.cause.shortMessage)return r.cause.shortMessage}return r.cause?.message?r.cause.message:r.details})(),i=(()=>r.cause instanceof qe&&r.cause.docsPath||r.docsPath)(),o=`https://oxlib.sh${i??""}`,a=[e||"An error occurred.",...r.metaMessages?["",...r.metaMessages]:[],...n||i?["",n?`Details: ${n}`:void 0,i?`See: ${o}`:void 0]:[]].filter(c=>typeof c=="string").join(`
16
+ `);super(a,r.cause?{cause:r.cause}:void 0),Object.defineProperty(this,"details",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docs",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"docsPath",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"shortMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"cause",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"BaseError"}),Object.defineProperty(this,"version",{enumerable:!0,configurable:!0,writable:!0,value:`ox@${p0()}`}),this.cause=r.cause,this.details=n,this.docs=o,this.docsPath=i,this.shortMessage=e}walk(e){return el(this,e)}}function el(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause?el(t.cause,e):e?null:t}function g0(t,e){if(nl(t)>e)throw new S0({givenSize:nl(t),maxSize:e})}const Bt={zero:48,nine:57,A:65,F:70,a:97,f:102};function tl(t){if(t>=Bt.zero&&t<=Bt.nine)return t-Bt.zero;if(t>=Bt.A&&t<=Bt.F)return t-(Bt.A-10);if(t>=Bt.a&&t<=Bt.f)return t-(Bt.a-10)}function y0(t,e={}){const{dir:r,size:n=32}=e;if(n===0)return t;if(t.length>n)throw new x0({size:t.length,targetSize:n,type:"Bytes"});const i=new Uint8Array(n);for(let s=0;s<n;s++){const o=r==="right";i[o?s:n-s-1]=t[o?s:t.length-s-1]}return i}function uo(t,e){if(ho(t)>e)throw new T0({givenSize:ho(t),maxSize:e})}function rl(t,e={}){const{dir:r,size:n=32}=e;if(n===0)return t;const i=t.replace("0x","");if(i.length>n*2)throw new R0({size:Math.ceil(i.length/2),targetSize:n,type:"Hex"});return`0x${i[r==="right"?"padEnd":"padStart"](n*2,"0")}`}const w0=new TextEncoder;function m0(t){return t instanceof Uint8Array?t:typeof t=="string"?v0(t):b0(t)}function b0(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function v0(t,e={}){const{size:r}=e;let n=t;r&&(uo(t,r),n=lo(t,r));let i=n.slice(2);i.length%2&&(i=`0${i}`);const s=i.length/2,o=new Uint8Array(s);for(let a=0,c=0;a<s;a++){const u=tl(i.charCodeAt(c++)),l=tl(i.charCodeAt(c++));if(u===void 0||l===void 0)throw new qe(`Invalid byte sequence ("${i[c-2]}${i[c-1]}" in "${i}").`);o[a]=u*16+l}return o}function E0(t,e={}){const{size:r}=e,n=w0.encode(t);return typeof r=="number"?(g0(n,r),_0(n,r)):n}function _0(t,e){return y0(t,{dir:"right",size:e})}function nl(t){return t.length}class S0 extends qe{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}}class x0 extends qe{constructor({size:e,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}const I0=new TextEncoder,D0=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function il(...t){return`0x${t.reduce((e,r)=>e+r.replace("0x",""),"")}`}function O0(t,e={}){const r=`0x${Number(t)}`;return typeof e.size=="number"?(uo(r,e.size),Ci(r,e.size)):r}function sl(t,e={}){let r="";for(let i=0;i<t.length;i++)r+=D0[t[i]];const n=`0x${r}`;return typeof e.size=="number"?(uo(n,e.size),lo(n,e.size)):n}function $0(t,e={}){const{signed:r,size:n}=e,i=BigInt(t);let s;n?r?s=(1n<<BigInt(n)*8n-1n)-1n:s=2n**(BigInt(n)*8n)-1n:typeof t=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&r?-s-1n:0;if(s&&i>s||i<o){const u=typeof t=="bigint"?"n":"";throw new P0({max:s?`${s}${u}`:void 0,min:`${o}${u}`,signed:r,size:n,value:`${t}${u}`})}const c=`0x${(r&&i<0?(1n<<BigInt(n*8))+BigInt(i):i).toString(16)}`;return n?Ci(c,n):c}function A0(t,e={}){return sl(I0.encode(t),e)}function Ci(t,e){return rl(t,{dir:"left",size:e})}function lo(t,e){return rl(t,{dir:"right",size:e})}function ho(t){return Math.ceil((t.length-2)/2)}class P0 extends qe{constructor({max:e,min:r,signed:n,size:i,value:s}){super(`Number \`${s}\` is not in safe${i?` ${i*8}-bit`:""}${n?" signed":" unsigned"} integer range ${e?`(\`${r}\` to \`${e}\`)`:`(above \`${r}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class T0 extends qe{constructor({givenSize:e,maxSize:r}){super(`Size cannot exceed \`${r}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}}class R0 extends qe{constructor({size:e,targetSize:r,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}function C0(t,e={}){const{as:r=typeof t=="string"?"Hex":"Bytes"}=e,n=Ku(m0(t));return r==="Bytes"?n:sl(n)}class N0 extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const r=super.get(e);return super.has(e)&&r!==void 0&&(this.delete(e),super.set(e,r)),r}set(e,r){if(super.set(e,r),this.maxSize&&this.size>this.maxSize){const n=this.keys().next().value;n&&this.delete(n)}return this}}const fo={checksum:new N0(8192)}.checksum,B0=/^0x[a-fA-F0-9]{40}$/;function ol(t,e={}){const{strict:r=!0}=e;if(!B0.test(t))throw new al({address:t,cause:new L0});if(r){if(t.toLowerCase()===t)return;if(F0(t)!==t)throw new al({address:t,cause:new U0})}}function F0(t){if(fo.has(t))return fo.get(t);ol(t,{strict:!1});const e=t.substring(2).toLowerCase(),r=C0(E0(e),{as:"Bytes"}),n=e.split("");for(let s=0;s<40;s+=2)r[s>>1]>>4>=8&&n[s]&&(n[s]=n[s].toUpperCase()),(r[s>>1]&15)>=8&&n[s+1]&&(n[s+1]=n[s+1].toUpperCase());const i=`0x${n.join("")}`;return fo.set(t,i),i}class al extends qe{constructor({address:e,cause:r}){super(`Address "${e}" is invalid.`,{cause:r}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class L0 extends qe{constructor(){super("Address is not a 20 byte (40 hexadecimal character) value."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidInputError"})}}class U0 extends qe{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}const k0=/^(.*)\[([0-9]*)\]$/,M0=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,j0=/^(u?int)(8|16|24|32|40|48|56|64|72|80|88|96|104|112|120|128|136|144|152|160|168|176|184|192|200|208|216|224|232|240|248|256)?$/;function po(t,e){if(t.length!==e.length)throw new z0({expectedLength:t.length,givenLength:e.length});const r=[];for(let n=0;n<t.length;n++){const i=t[n],s=e[n];r.push(po.encode(i,s))}return il(...r)}(function(t){function e(r,n,i=!1){if(r==="address"){const c=n;return ol(c),Ci(c.toLowerCase(),i?32:0)}if(r==="string")return A0(n);if(r==="bytes")return n;if(r==="bool")return Ci(O0(n),i?32:1);const s=r.match(j0);if(s){const[c,u,l="256"]=s,h=Number.parseInt(l)/8;return $0(n,{size:i?32:h,signed:u==="int"})}const o=r.match(M0);if(o){const[c,u]=o;if(Number.parseInt(u)!==(n.length-2)/2)throw new q0({expectedSize:Number.parseInt(u),value:n});return lo(n,i?32:0)}const a=r.match(k0);if(a&&Array.isArray(n)){const[c,u]=a,l=[];for(let h=0;h<n.length;h++)l.push(e(u,n[h],!0));return l.length===0?"0x":il(...l)}throw new V0(r)}t.encode=e})(po||(po={}));class q0 extends qe{constructor({expectedSize:e,value:r}){super(`Size of bytes "${r}" (bytes${ho(r)}) does not match expected size (bytes${e}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class z0 extends qe{constructor({expectedLength:e,givenLength:r}){super(["ABI encoding parameters/values length mismatch.",`Expected length (parameters): ${e}`,`Given length (values): ${r}`].join(`
17
+ `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.LengthMismatchError"})}}class V0 extends qe{constructor(e){super(`Type \`${e}\` is not a valid ABI Type.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.InvalidTypeError"})}}class cl extends Qs{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Ib(e);const n=$i(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(n.length>i?e.create().update(n).digest():n);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(e){return qr(this),this.iHash.update(e),this}digestInto(e){qr(this),xn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:n,finished:i,destroyed:s,blockLen:o,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=s,e.blockLen=o,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const ul=(t,e,r)=>new cl(t,e).update(r).digest();ul.create=(t,e)=>new cl(t,e);const Ee=BigInt(0),de=BigInt(1),wr=BigInt(2),K0=BigInt(3),go=BigInt(4),ll=BigInt(5),hl=BigInt(8);function _e(t,e){const r=t%e;return r>=Ee?r:e+r}function H0(t,e,r){if(e<Ee)throw new Error("invalid exponent, negatives unsupported");if(r<=Ee)throw new Error("invalid modulus");if(r===de)return Ee;let n=de;for(;e>Ee;)e&de&&(n=n*t%r),t=t*t%r,e>>=de;return n}function it(t,e,r){let n=t;for(;e-- >Ee;)n*=n,n%=r;return n}function yo(t,e){if(t===Ee)throw new Error("invert: expected non-zero number");if(e<=Ee)throw new Error("invert: expected positive modulus, got "+e);let r=_e(t,e),n=e,i=Ee,s=de;for(;r!==Ee;){const a=n/r,c=n%r,u=i-s*a;n=r,r=c,i=s,s=u}if(n!==de)throw new Error("invert: does not exist");return _e(i,e)}function W0(t){const e=(t-de)/wr;let r,n,i;for(r=t-de,n=0;r%wr===Ee;r/=wr,n++);for(i=wr;i<t&&H0(i,e,t)!==t-de;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const o=(t+de)/go;return function(c,u){const l=c.pow(u,o);if(!c.eql(c.sqr(l),u))throw new Error("Cannot find square root");return l}}const s=(r+de)/wr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let u=n,l=a.pow(a.mul(a.ONE,i),r),h=a.pow(c,s),d=a.pow(c,r);for(;!a.eql(d,a.ONE);){if(a.eql(d,a.ZERO))return a.ZERO;let p=1;for(let y=a.sqr(d);p<u&&!a.eql(y,a.ONE);p++)y=a.sqr(y);const f=a.pow(l,de<<BigInt(u-p-1));l=a.sqr(f),h=a.mul(h,f),d=a.mul(d,l),u=p}return h}}function G0(t){if(t%go===K0){const e=(t+de)/go;return function(n,i){const s=n.pow(i,e);if(!n.eql(n.sqr(s),i))throw new Error("Cannot find square root");return s}}if(t%hl===ll){const e=(t-ll)/hl;return function(n,i){const s=n.mul(i,wr),o=n.pow(s,e),a=n.mul(i,o),c=n.mul(n.mul(a,wr),o),u=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(u),i))throw new Error("Cannot find square root");return u}}return W0(t)}const Y0=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function dl(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=Y0.reduce((n,i)=>(n[i]="function",n),e);return Yr(t,r)}function Z0(t,e,r){if(r<Ee)throw new Error("invalid exponent, negatives unsupported");if(r===Ee)return t.ONE;if(r===de)return e;let n=t.ONE,i=e;for(;r>Ee;)r&de&&(n=t.mul(n,i)),i=t.sqr(i),r>>=de;return n}function J0(t,e){const r=new Array(e.length),n=e.reduce((s,o,a)=>t.is0(o)?s:(r[a]=s,t.mul(s,o)),t.ONE),i=t.inv(n);return e.reduceRight((s,o,a)=>t.is0(o)?s:(r[a]=t.mul(s,r[a]),t.mul(s,o)),i),r}function fl(t,e){const r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function pl(t,e,r=!1,n={}){if(t<=Ee)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=fl(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:r,BITS:i,BYTES:s,MASK:oo(i),ZERO:Ee,ONE:de,create:c=>_e(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Ee<=c&&c<t},is0:c=>c===Ee,isOdd:c=>(c&de)===de,neg:c=>_e(-c,t),eql:(c,u)=>c===u,sqr:c=>_e(c*c,t),add:(c,u)=>_e(c+u,t),sub:(c,u)=>_e(c-u,t),mul:(c,u)=>_e(c*u,t),pow:(c,u)=>Z0(a,c,u),div:(c,u)=>_e(c*yo(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>yo(c,t),sqrt:n.sqrt||(c=>(o||(o=G0(t)),o(a,c))),invertBatch:c=>J0(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>r?io(c,s):Zt(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?no(c):Et(c)}});return Object.freeze(a)}function gl(t){if(typeof t!="bigint")throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function yl(t){const e=gl(t);return e+Math.ceil(e/2)}function X0(t,e,r=!1){const n=t.length,i=gl(e),s=yl(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);const o=r?no(t):Et(t),a=_e(o,e-de)+de;return r?io(a,i):Zt(a,i)}const wl=BigInt(0),Ni=BigInt(1);function wo(t,e){const r=e.negate();return t?r:e}function ml(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function mo(t,e){ml(t,e);const r=Math.ceil(e/t)+1,n=2**(t-1);return{windows:r,windowSize:n}}function Q0(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function e1(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}const bo=new WeakMap,bl=new WeakMap;function vo(t){return bl.get(t)||1}function t1(t,e){return{constTimeNegate:wo,hasPrecomputes(r){return vo(r)!==1},unsafeLadder(r,n,i=t.ZERO){let s=r;for(;n>wl;)n&Ni&&(i=i.add(s)),s=s.double(),n>>=Ni;return i},precomputeWindow(r,n){const{windows:i,windowSize:s}=mo(n,e),o=[];let a=r,c=a;for(let u=0;u<i;u++){c=a,o.push(c);for(let l=1;l<s;l++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(r,n,i){const{windows:s,windowSize:o}=mo(r,e);let a=t.ZERO,c=t.BASE;const u=BigInt(2**r-1),l=2**r,h=BigInt(r);for(let d=0;d<s;d++){const p=d*o;let f=Number(i&u);i>>=h,f>o&&(f-=l,i+=Ni);const y=p,g=p+Math.abs(f)-1,w=d%2!==0,m=f<0;f===0?c=c.add(wo(w,n[y])):a=a.add(wo(m,n[g]))}return{p:a,f:c}},wNAFUnsafe(r,n,i,s=t.ZERO){const{windows:o,windowSize:a}=mo(r,e),c=BigInt(2**r-1),u=2**r,l=BigInt(r);for(let h=0;h<o;h++){const d=h*a;if(i===wl)break;let p=Number(i&c);if(i>>=l,p>a&&(p-=u,i+=Ni),p===0)continue;let f=n[d+Math.abs(p)-1];p<0&&(f=f.negate()),s=s.add(f)}return s},getPrecomputes(r,n,i){let s=bo.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&bo.set(n,i(s))),s},wNAFCached(r,n,i){const s=vo(r);return this.wNAF(s,this.getPrecomputes(s,r,i),n)},wNAFCachedUnsafe(r,n,i,s){const o=vo(r);return o===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(o,this.getPrecomputes(o,r,i),n,s)},setWindowSize(r,n){ml(n,e),bl.set(r,n),bo.delete(r)}}}function r1(t,e,r,n){if(Q0(r,t),e1(n,e),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const i=t.ZERO,s=Ju(BigInt(r.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=(1<<o)-1,c=new Array(a+1).fill(i),u=Math.floor((e.BITS-1)/o)*o;let l=i;for(let h=u;h>=0;h-=o){c.fill(i);for(let p=0;p<n.length;p++){const f=n[p],y=Number(f>>BigInt(h)&BigInt(a));c[y]=c[y].add(r[p])}let d=i;for(let p=c.length-1,f=i;p>0;p--)f=f.add(c[p]),d=d.add(f);if(l=l.add(d),h!==0)for(let p=0;p<o;p++)l=l.double()}return l}function vl(t){return dl(t.Fp),Yr(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...fl(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function El(t){t.lowS!==void 0&&Vr("lowS",t.lowS),t.prehash!==void 0&&Vr("prehash",t.prehash)}function n1(t){const e=vl(t);Yr(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:n,a:i}=e;if(r){if(!n.eql(i,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:i1,hexToBytes:s1}=d0;class o1 extends Error{constructor(e=""){super(e)}}const Ft={Err:o1,_tlv:{encode:(t,e)=>{const{Err:r}=Ft;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");const n=e.length/2,i=Hr(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const s=n>127?Hr(i.length/2|128):"";return Hr(t)+s+i+e},decode(t,e){const{Err:r}=Ft;let n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");const i=e[n++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");const u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const l of u)o=o<<8|l;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}const a=e.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(t){const{Err:e}=Ft;if(t<lt)throw new e("integer: negative integers are not allowed");let r=Hr(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){const{Err:e}=Ft;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return i1(t)}},toSig(t){const{Err:e,_int:r,_tlv:n}=Ft,i=typeof t=="string"?s1(t):t;vt(i);const{v:s,l:o}=n.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){const{_tlv:e,_int:r}=Ft,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),s=n+i;return e.encode(48,s)}},lt=BigInt(0),re=BigInt(1),Xt=BigInt(2),Bi=BigInt(3),_l=BigInt(4);function a1(t){const e=n1(t),{Fp:r}=e,n=pl(e.n,e.nBitLength),i=e.toBytes||((y,g,w)=>{const m=g.toAffine();return Xe(Uint8Array.from([4]),r.toBytes(m.x),r.toBytes(m.y))}),s=e.fromBytes||(y=>{const g=y.subarray(1),w=r.fromBytes(g.subarray(0,r.BYTES)),m=r.fromBytes(g.subarray(r.BYTES,2*r.BYTES));return{x:w,y:m}});function o(y){const{a:g,b:w}=e,m=r.sqr(y),b=r.mul(m,y);return r.add(r.add(b,r.mul(y,g)),w)}if(!r.eql(r.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return Gr(y,re,e.n)}function c(y){const{allowedPrivateKeyLengths:g,nByteLength:w,wrapPrivateKey:m,n:b}=e;if(g&&typeof y!="bigint"){if(yr(y)&&(y=Kr(y)),typeof y!="string"||!g.includes(y.length))throw new Error("invalid private key");y=y.padStart(w*2,"0")}let E;try{E=typeof y=="bigint"?y:Et(Ue("private key",y,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof y)}return m&&(E=_e(E,b)),Jt("private key",E,re,b),E}function u(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}const l=co((y,g)=>{const{px:w,py:m,pz:b}=y;if(r.eql(b,r.ONE))return{x:w,y:m};const E=y.is0();g==null&&(g=E?r.ONE:r.inv(b));const $=r.mul(w,g),D=r.mul(m,g),S=r.mul(b,g);if(E)return{x:r.ZERO,y:r.ZERO};if(!r.eql(S,r.ONE))throw new Error("invZ was invalid");return{x:$,y:D}}),h=co(y=>{if(y.is0()){if(e.allowInfinityPoint&&!r.is0(y.py))return;throw new Error("bad point: ZERO")}const{x:g,y:w}=y.toAffine();if(!r.isValid(g)||!r.isValid(w))throw new Error("bad point: x or y not FE");const m=r.sqr(w),b=o(g);if(!r.eql(m,b))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(g,w,m){if(this.px=g,this.py=w,this.pz=m,g==null||!r.isValid(g))throw new Error("x required");if(w==null||!r.isValid(w))throw new Error("y required");if(m==null||!r.isValid(m))throw new Error("z required");Object.freeze(this)}static fromAffine(g){const{x:w,y:m}=g||{};if(!g||!r.isValid(w)||!r.isValid(m))throw new Error("invalid affine point");if(g instanceof d)throw new Error("projective point not allowed");const b=E=>r.eql(E,r.ZERO);return b(w)&&b(m)?d.ZERO:new d(w,m,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){const w=r.invertBatch(g.map(m=>m.pz));return g.map((m,b)=>m.toAffine(w[b])).map(d.fromAffine)}static fromHex(g){const w=d.fromAffine(s(Ue("pointHex",g)));return w.assertValidity(),w}static fromPrivateKey(g){return d.BASE.multiply(c(g))}static msm(g,w){return r1(d,n,g,w)}_setWindowSize(g){f.setWindowSize(this,g)}assertValidity(){h(this)}hasEvenY(){const{y:g}=this.toAffine();if(r.isOdd)return!r.isOdd(g);throw new Error("Field doesn't support isOdd")}equals(g){u(g);const{px:w,py:m,pz:b}=this,{px:E,py:$,pz:D}=g,S=r.eql(r.mul(w,D),r.mul(E,b)),A=r.eql(r.mul(m,D),r.mul($,b));return S&&A}negate(){return new d(this.px,r.neg(this.py),this.pz)}double(){const{a:g,b:w}=e,m=r.mul(w,Bi),{px:b,py:E,pz:$}=this;let D=r.ZERO,S=r.ZERO,A=r.ZERO,x=r.mul(b,b),k=r.mul(E,E),C=r.mul($,$),B=r.mul(b,E);return B=r.add(B,B),A=r.mul(b,$),A=r.add(A,A),D=r.mul(g,A),S=r.mul(m,C),S=r.add(D,S),D=r.sub(k,S),S=r.add(k,S),S=r.mul(D,S),D=r.mul(B,D),A=r.mul(m,A),C=r.mul(g,C),B=r.sub(x,C),B=r.mul(g,B),B=r.add(B,A),A=r.add(x,x),x=r.add(A,x),x=r.add(x,C),x=r.mul(x,B),S=r.add(S,x),C=r.mul(E,$),C=r.add(C,C),x=r.mul(C,B),D=r.sub(D,x),A=r.mul(C,k),A=r.add(A,A),A=r.add(A,A),new d(D,S,A)}add(g){u(g);const{px:w,py:m,pz:b}=this,{px:E,py:$,pz:D}=g;let S=r.ZERO,A=r.ZERO,x=r.ZERO;const k=e.a,C=r.mul(e.b,Bi);let B=r.mul(w,E),j=r.mul(m,$),I=r.mul(b,D),_=r.add(w,m),v=r.add(E,$);_=r.mul(_,v),v=r.add(B,j),_=r.sub(_,v),v=r.add(w,b);let O=r.add(E,D);return v=r.mul(v,O),O=r.add(B,I),v=r.sub(v,O),O=r.add(m,b),S=r.add($,D),O=r.mul(O,S),S=r.add(j,I),O=r.sub(O,S),x=r.mul(k,v),S=r.mul(C,I),x=r.add(S,x),S=r.sub(j,x),x=r.add(j,x),A=r.mul(S,x),j=r.add(B,B),j=r.add(j,B),I=r.mul(k,I),v=r.mul(C,v),j=r.add(j,I),I=r.sub(B,I),I=r.mul(k,I),v=r.add(v,I),B=r.mul(j,v),A=r.add(A,B),B=r.mul(O,v),S=r.mul(_,S),S=r.sub(S,B),B=r.mul(_,j),x=r.mul(O,x),x=r.add(x,B),new d(S,A,x)}subtract(g){return this.add(g.negate())}is0(){return this.equals(d.ZERO)}wNAF(g){return f.wNAFCached(this,g,d.normalizeZ)}multiplyUnsafe(g){const{endo:w,n:m}=e;Jt("scalar",g,lt,m);const b=d.ZERO;if(g===lt)return b;if(this.is0()||g===re)return this;if(!w||f.hasPrecomputes(this))return f.wNAFCachedUnsafe(this,g,d.normalizeZ);let{k1neg:E,k1:$,k2neg:D,k2:S}=w.splitScalar(g),A=b,x=b,k=this;for(;$>lt||S>lt;)$&re&&(A=A.add(k)),S&re&&(x=x.add(k)),k=k.double(),$>>=re,S>>=re;return E&&(A=A.negate()),D&&(x=x.negate()),x=new d(r.mul(x.px,w.beta),x.py,x.pz),A.add(x)}multiply(g){const{endo:w,n:m}=e;Jt("scalar",g,re,m);let b,E;if(w){const{k1neg:$,k1:D,k2neg:S,k2:A}=w.splitScalar(g);let{p:x,f:k}=this.wNAF(D),{p:C,f:B}=this.wNAF(A);x=f.constTimeNegate($,x),C=f.constTimeNegate(S,C),C=new d(r.mul(C.px,w.beta),C.py,C.pz),b=x.add(C),E=k.add(B)}else{const{p:$,f:D}=this.wNAF(g);b=$,E=D}return d.normalizeZ([b,E])[0]}multiplyAndAddUnsafe(g,w,m){const b=d.BASE,E=(D,S)=>S===lt||S===re||!D.equals(b)?D.multiplyUnsafe(S):D.multiply(S),$=E(this,w).add(E(g,m));return $.is0()?void 0:$}toAffine(g){return l(this,g)}isTorsionFree(){const{h:g,isTorsionFree:w}=e;if(g===re)return!0;if(w)return w(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:g,clearCofactor:w}=e;return g===re?this:w?w(d,this):this.multiplyUnsafe(e.h)}toRawBytes(g=!0){return Vr("isCompressed",g),this.assertValidity(),i(d,this,g)}toHex(g=!0){return Vr("isCompressed",g),Kr(this.toRawBytes(g))}}d.BASE=new d(e.Gx,e.Gy,r.ONE),d.ZERO=new d(r.ZERO,r.ONE,r.ZERO);const p=e.nBitLength,f=t1(d,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function c1(t){const e=vl(t);return Yr(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function u1(t){const e=c1(t),{Fp:r,n}=e,i=r.BYTES+1,s=2*r.BYTES+1;function o(I){return _e(I,n)}function a(I){return yo(I,n)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:h}=a1({...e,toBytes(I,_,v){const O=_.toAffine(),T=r.toBytes(O.x),P=Xe;return Vr("isCompressed",v),v?P(Uint8Array.from([_.hasEvenY()?2:3]),T):P(Uint8Array.from([4]),T,r.toBytes(O.y))},fromBytes(I){const _=I.length,v=I[0],O=I.subarray(1);if(_===i&&(v===2||v===3)){const T=Et(O);if(!Gr(T,re,r.ORDER))throw new Error("Point is not on curve");const P=l(T);let N;try{N=r.sqrt(P)}catch(z){const q=z instanceof Error?": "+z.message:"";throw new Error("Point is not on curve"+q)}const F=(N&re)===re;return(v&1)===1!==F&&(N=r.neg(N)),{x:T,y:N}}else if(_===s&&v===4){const T=r.fromBytes(O.subarray(0,r.BYTES)),P=r.fromBytes(O.subarray(r.BYTES,2*r.BYTES));return{x:T,y:P}}else{const T=i,P=s;throw new Error("invalid Point, expected length of "+T+", or uncompressed "+P+", got "+_)}}}),d=I=>Kr(Zt(I,e.nByteLength));function p(I){const _=n>>re;return I>_}function f(I){return p(I)?o(-I):I}const y=(I,_,v)=>Et(I.slice(_,v));class g{constructor(_,v,O){this.r=_,this.s=v,this.recovery=O,this.assertValidity()}static fromCompact(_){const v=e.nByteLength;return _=Ue("compactSignature",_,v*2),new g(y(_,0,v),y(_,v,2*v))}static fromDER(_){const{r:v,s:O}=Ft.toSig(Ue("DER",_));return new g(v,O)}assertValidity(){Jt("r",this.r,re,n),Jt("s",this.s,re,n)}addRecoveryBit(_){return new g(this.r,this.s,_)}recoverPublicKey(_){const{r:v,s:O,recovery:T}=this,P=D(Ue("msgHash",_));if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");const N=T===2||T===3?v+e.n:v;if(N>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const F=T&1?"03":"02",M=c.fromHex(F+d(N)),z=a(N),q=o(-P*z),V=o(O*z),K=c.BASE.multiplyAndAddUnsafe(M,q,V);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return Wr(this.toDERHex())}toDERHex(){return Ft.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return Wr(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}const w={isValidPrivateKey(I){try{return u(I),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const I=yl(e.n);return X0(e.randomBytes(I),e.n)},precompute(I=8,_=c.BASE){return _._setWindowSize(I),_.multiply(BigInt(3)),_}};function m(I,_=!0){return c.fromPrivateKey(I).toRawBytes(_)}function b(I){const _=yr(I),v=typeof I=="string",O=(_||v)&&I.length;return _?O===i||O===s:v?O===2*i||O===2*s:I instanceof c}function E(I,_,v=!0){if(b(I))throw new Error("first arg must be private key");if(!b(_))throw new Error("second arg must be public key");return c.fromHex(_).multiply(u(I)).toRawBytes(v)}const $=e.bits2int||function(I){if(I.length>8192)throw new Error("input is too large");const _=Et(I),v=I.length*8-e.nBitLength;return v>0?_>>BigInt(v):_},D=e.bits2int_modN||function(I){return o($(I))},S=oo(e.nBitLength);function A(I){return Jt("num < 2^"+e.nBitLength,I,lt,S),Zt(I,e.nByteLength)}function x(I,_,v=k){if(["recovered","canonical"].some(G=>G in v))throw new Error("sign() legacy options not supported");const{hash:O,randomBytes:T}=e;let{lowS:P,prehash:N,extraEntropy:F}=v;P==null&&(P=!0),I=Ue("msgHash",I),El(v),N&&(I=Ue("prehashed msgHash",O(I)));const M=D(I),z=u(_),q=[A(z),A(M)];if(F!=null&&F!==!1){const G=F===!0?T(r.BYTES):F;q.push(Ue("extraEntropy",G))}const V=Xe(...q),K=M;function ee(G){const W=$(G);if(!h(W))return;const ye=a(W),ue=c.BASE.multiply(W).toAffine(),le=o(ue.x);if(le===lt)return;const $e=o(ye*o(K+le*z));if($e===lt)return;let Me=(ue.x===le?0:2)|Number(ue.y&re),Kt=$e;return P&&p($e)&&(Kt=f($e),Me^=1),new g(le,Kt,Me)}return{seed:V,k2sig:ee}}const k={lowS:e.lowS,prehash:!1},C={lowS:e.lowS,prehash:!1};function B(I,_,v=k){const{seed:O,k2sig:T}=x(I,_,v),P=e;return Qu(P.hash.outputLen,P.nByteLength,P.hmac)(O,T)}c.BASE._setWindowSize(8);function j(I,_,v,O=C){const T=I;_=Ue("msgHash",_),v=Ue("publicKey",v);const{lowS:P,prehash:N,format:F}=O;if(El(O),"strict"in O)throw new Error("options.strict was renamed to lowS");if(F!==void 0&&F!=="compact"&&F!=="der")throw new Error("format must be compact or der");const M=typeof T=="string"||yr(T),z=!M&&!F&&typeof T=="object"&&T!==null&&typeof T.r=="bigint"&&typeof T.s=="bigint";if(!M&&!z)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,V;try{if(z&&(q=new g(T.r,T.s)),M){try{F!=="compact"&&(q=g.fromDER(T))}catch(Me){if(!(Me instanceof Ft.Err))throw Me}!q&&F!=="der"&&(q=g.fromCompact(T))}V=c.fromHex(v)}catch{return!1}if(!q||P&&q.hasHighS())return!1;N&&(_=e.hash(_));const{r:K,s:ee}=q,G=D(_),W=a(ee),ye=o(G*W),ue=o(K*W),le=c.BASE.multiplyAndAddUnsafe(V,ye,ue)?.toAffine();return le?o(le.x)===K:!1}return{CURVE:e,getPublicKey:m,getSharedSecret:E,sign:B,verify:j,ProjectivePoint:c,Signature:g,utils:w}}function l1(t,e){const r=t.ORDER;let n=lt;for(let f=r-re;f%Xt===lt;f/=Xt)n+=re;const i=n,s=Xt<<i-re-re,o=s*Xt,a=(r-re)/o,c=(a-re)/Xt,u=o-re,l=s,h=t.pow(e,a),d=t.pow(e,(a+re)/Xt);let p=(f,y)=>{let g=h,w=t.pow(y,u),m=t.sqr(w);m=t.mul(m,y);let b=t.mul(f,m);b=t.pow(b,c),b=t.mul(b,w),w=t.mul(b,y),m=t.mul(b,f);let E=t.mul(m,w);b=t.pow(E,l);let $=t.eql(b,t.ONE);w=t.mul(m,d),b=t.mul(E,g),m=t.cmov(w,m,$),E=t.cmov(b,E,$);for(let D=i;D>re;D--){let S=D-Xt;S=Xt<<S-re;let A=t.pow(E,S);const x=t.eql(A,t.ONE);w=t.mul(m,g),g=t.mul(g,g),A=t.mul(E,g),m=t.cmov(w,m,x),E=t.cmov(A,E,x)}return{isValid:$,value:m}};if(t.ORDER%_l===Bi){const f=(t.ORDER-Bi)/_l,y=t.sqrt(t.neg(e));p=(g,w)=>{let m=t.sqr(w);const b=t.mul(g,w);m=t.mul(m,b);let E=t.pow(m,f);E=t.mul(E,b);const $=t.mul(E,y),D=t.mul(t.sqr(E),w),S=t.eql(D,g);let A=t.cmov($,E,S);return{isValid:S,value:A}}}return p}function h1(t,e){if(dl(t),!t.isValid(e.A)||!t.isValid(e.B)||!t.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const r=l1(t,e.Z);if(!t.isOdd)throw new Error("Fp.isOdd is not implemented!");return n=>{let i,s,o,a,c,u,l,h;i=t.sqr(n),i=t.mul(i,e.Z),s=t.sqr(i),s=t.add(s,i),o=t.add(s,t.ONE),o=t.mul(o,e.B),a=t.cmov(e.Z,t.neg(s),!t.eql(s,t.ZERO)),a=t.mul(a,e.A),s=t.sqr(o),u=t.sqr(a),c=t.mul(u,e.A),s=t.add(s,c),s=t.mul(s,o),u=t.mul(u,a),c=t.mul(u,e.B),s=t.add(s,c),l=t.mul(i,o);const{isValid:d,value:p}=r(s,u);h=t.mul(i,n),h=t.mul(h,p),l=t.cmov(l,o,d),h=t.cmov(h,p,d);const f=t.isOdd(n)===t.isOdd(h);return h=t.cmov(t.neg(h),h,f),l=t.div(l,a),{x:l,y:h}}}function d1(t){return{hash:t,hmac:(e,...r)=>ul(t,e,Bb(...r)),randomBytes:ku}}function f1(t,e){const r=n=>u1({...t,...d1(n)});return{...r(e),create:r}}const p1=Et;function Qt(t,e){if(Dn(t),Dn(e),t<0||t>=1<<8*e)throw new Error("invalid I2OSP input: "+t);const r=Array.from({length:e}).fill(0);for(let n=e-1;n>=0;n--)r[n]=t&255,t>>>=8;return new Uint8Array(r)}function g1(t,e){const r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t[n]^e[n];return r}function Dn(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function y1(t,e,r,n){vt(t),vt(e),Dn(r),e.length>255&&(e=n(Xe(Ri("H2C-OVERSIZE-DST-"),e)));const{outputLen:i,blockLen:s}=n,o=Math.ceil(r/i);if(r>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");const a=Xe(e,Qt(e.length,1)),c=Qt(0,s),u=Qt(r,2),l=new Array(o),h=n(Xe(c,t,u,Qt(0,1),a));l[0]=n(Xe(h,Qt(1,1),a));for(let p=1;p<=o;p++){const f=[g1(h,l[p-1]),Qt(p+1,1),a];l[p]=n(Xe(...f))}return Xe(...l).slice(0,r)}function w1(t,e,r,n,i){if(vt(t),vt(e),Dn(r),e.length>255){const s=Math.ceil(2*n/8);e=i.create({dkLen:s}).update(Ri("H2C-OVERSIZE-DST-")).update(e).digest()}if(r>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:r}).update(t).update(Qt(r,2)).update(e).update(Qt(e.length,1)).digest()}function Sl(t,e,r){Yr(r,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:n,k:i,m:s,hash:o,expand:a,DST:c}=r;vt(t),Dn(e);const u=typeof c=="string"?Ri(c):c,l=n.toString(2).length,h=Math.ceil((l+i)/8),d=e*s*h;let p;if(a==="xmd")p=y1(t,u,d,o);else if(a==="xof")p=w1(t,u,d,i,o);else if(a==="_internal_pass")p=t;else throw new Error('expand must be "xmd" or "xof"');const f=new Array(e);for(let y=0;y<e;y++){const g=new Array(s);for(let w=0;w<s;w++){const m=h*(w+y*s),b=p.subarray(m,m+h);g[w]=_e(p1(b),n)}f[y]=g}return f}function m1(t,e){const r=e.map(n=>Array.from(n).reverse());return(n,i)=>{const[s,o,a,c]=r.map(u=>u.reduce((l,h)=>t.add(t.mul(l,n),h)));return n=t.div(s,o),i=t.mul(i,t.div(a,c)),{x:n,y:i}}}function b1(t,e,r){if(typeof e!="function")throw new Error("mapToCurve() must be defined");return{hashToCurve(n,i){const s=Sl(n,2,{...r,DST:r.DST,...i}),o=t.fromAffine(e(s[0])),a=t.fromAffine(e(s[1])),c=o.add(a).clearCofactor();return c.assertValidity(),c},encodeToCurve(n,i){const s=Sl(n,1,{...r,DST:r.encodeDST,...i}),o=t.fromAffine(e(s[0])).clearCofactor();return o.assertValidity(),o},mapToCurve(n){if(!Array.isArray(n))throw new Error("mapToCurve: expected array of bigints");for(const s of n)if(typeof s!="bigint")throw new Error("mapToCurve: expected array of bigints");const i=t.fromAffine(e(n)).clearCofactor();return i.assertValidity(),i}}}const On=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Fi=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),$n=BigInt(1),Li=BigInt(2),xl=(t,e)=>(t+e/Li)/e;function Il(t){const e=On,r=BigInt(3),n=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=t*t*t%e,l=u*u*t%e,h=it(l,r,e)*l%e,d=it(h,r,e)*l%e,p=it(d,Li,e)*u%e,f=it(p,i,e)*p%e,y=it(f,s,e)*f%e,g=it(y,a,e)*y%e,w=it(g,c,e)*g%e,m=it(w,a,e)*y%e,b=it(m,r,e)*l%e,E=it(b,o,e)*f%e,$=it(E,n,e)*u%e,D=it($,Li,e);if(!er.eql(er.sqr(D),t))throw new Error("Cannot find square root");return D}const er=pl(On,void 0,void 0,{sqrt:Il}),An=f1({a:BigInt(0),b:BigInt(7),Fp:er,n:Fi,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=Fi,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-$n*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,o=BigInt("0x100000000000000000000000000000000"),a=xl(s*t,e),c=xl(-n*t,e);let u=_e(t-a*r-c*i,e),l=_e(-a*n-c*s,e);const h=u>o,d=l>o;if(h&&(u=e-u),d&&(l=e-l),u>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:h,k1:u,k2neg:d,k2:l}}}},Ai),Dl=BigInt(0),Ol={};function Ui(t,...e){let r=Ol[t];if(r===void 0){const n=Ai(Uint8Array.from(t,i=>i.charCodeAt(0)));r=Xe(n,n),Ol[t]=r}return Ai(Xe(r,...e))}const Eo=t=>t.toRawBytes(!0).slice(1),_o=t=>Zt(t,32),So=t=>_e(t,On),Pn=t=>_e(t,Fi),xo=An.ProjectivePoint,v1=(t,e,r)=>xo.BASE.multiplyAndAddUnsafe(t,e,r);function Io(t){let e=An.utils.normPrivateKeyToScalar(t),r=xo.fromPrivateKey(e);return{scalar:r.hasEvenY()?e:Pn(-e),bytes:Eo(r)}}function $l(t){Jt("x",t,$n,On);const e=So(t*t),r=So(e*t+BigInt(7));let n=Il(r);n%Li!==Dl&&(n=So(-n));const i=new xo(t,n,$n);return i.assertValidity(),i}const Zr=Et;function Al(...t){return Pn(Zr(Ui("BIP0340/challenge",...t)))}function E1(t){return Io(t).bytes}function _1(t,e,r=ku(32)){const n=Ue("message",t),{bytes:i,scalar:s}=Io(e),o=Ue("auxRand",r,32),a=_o(s^Zr(Ui("BIP0340/aux",o))),c=Ui("BIP0340/nonce",a,i,n),u=Pn(Zr(c));if(u===Dl)throw new Error("sign failed: k is zero");const{bytes:l,scalar:h}=Io(u),d=Al(l,i,n),p=new Uint8Array(64);if(p.set(l,0),p.set(_o(Pn(h+d*s)),32),!Pl(p,n,i))throw new Error("sign: Invalid signature produced");return p}function Pl(t,e,r){const n=Ue("signature",t,64),i=Ue("message",e),s=Ue("publicKey",r,32);try{const o=$l(Zr(s)),a=Zr(n.subarray(0,32));if(!Gr(a,$n,On))return!1;const c=Zr(n.subarray(32,64));if(!Gr(c,$n,Fi))return!1;const u=Al(_o(a),Eo(o),i),l=v1(o,c,Pn(-u));return!(!l||!l.hasEvenY()||l.toAffine().x!==a)}catch{return!1}}const S1=(()=>({getPublicKey:E1,sign:_1,verify:Pl,utils:{randomPrivateKey:An.utils.randomPrivateKey,lift_x:$l,pointToBytes:Eo,numberToBytesBE:Zt,bytesToNumberBE:Et,taggedHash:Ui,mod:_e}}))(),x1=(()=>m1(er,[["0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa8c7","0x7d3d4c80bc321d5b9f315cea7fd44c5d595d2fc0bf63b92dfff1044f17c6581","0x534c328d23f234e6e2a413deca25caece4506144037c40314ecbd0b53d9dd262","0x8e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38e38daaaaa88c"],["0xd35771193d94918a9ca34ccbb7b640dd86cd409542f8487d9fe6b745781eb49b","0xedadc6f64383dc1df7c4b2d51b54225406d36b641f5e41bbc52a56612a8c6d14","0x0000000000000000000000000000000000000000000000000000000000000001"],["0x4bda12f684bda12f684bda12f684bda12f684bda12f684bda12f684b8e38e23c","0xc75e0c32d5cb7c0fa9d0a54b12a0a6d5647ab046d686da6fdffc90fc201d71a3","0x29a6194691f91a73715209ef6512e576722830a201be2018a765e85a9ecee931","0x2f684bda12f684bda12f684bda12f684bda12f684bda12f684bda12f38e38d84"],["0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffff93b","0x7a06534bb8bdb49fd5e9e6632722c2989467c1bfc8e8d978dfb425d2685c2573","0x6484aa716545ca2cf3a70c3fa8fe337e0a3d21162f0d6299a7bf8192bfd2a76f","0x0000000000000000000000000000000000000000000000000000000000000001"]].map(t=>t.map(e=>BigInt(e)))))(),I1=(()=>h1(er,{A:BigInt("0x3f8731abdd661adca08a5558f0f5d272e953d363cb6f0e5d405447c01a444533"),B:BigInt("1771"),Z:er.create(BigInt("-11"))}))(),Tl=(()=>b1(An.ProjectivePoint,t=>{const{x:e,y:r}=I1(er.create(t[0]));return x1(e,r)},{DST:"secp256k1_XMD:SHA-256_SSWU_RO_",encodeDST:"secp256k1_XMD:SHA-256_SSWU_NU_",p:er.ORDER,m:1,k:128,expand:"xmd",hash:Ai}))();var D1=Object.freeze({__proto__:null,secp256k1:An,schnorr:S1,hashToCurve:(()=>Tl.hashToCurve)(),encodeToCurve:(()=>Tl.encodeToCurve)()});function O1(t){if(t.length>=255)throw new TypeError("Alphabet too long");const e=new Uint8Array(256);for(let u=0;u<e.length;u++)e[u]=255;for(let u=0;u<t.length;u++){const l=t.charAt(u),h=l.charCodeAt(0);if(e[h]!==255)throw new TypeError(l+" is ambiguous");e[h]=u}const r=t.length,n=t.charAt(0),i=Math.log(r)/Math.log(256),s=Math.log(256)/Math.log(r);function o(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";let l=0,h=0,d=0;const p=u.length;for(;d!==p&&u[d]===0;)d++,l++;const f=(p-d)*s+1>>>0,y=new Uint8Array(f);for(;d!==p;){let m=u[d],b=0;for(let E=f-1;(m!==0||b<h)&&E!==-1;E--,b++)m+=256*y[E]>>>0,y[E]=m%r>>>0,m=m/r>>>0;if(m!==0)throw new Error("Non-zero carry");h=b,d++}let g=f-h;for(;g!==f&&y[g]===0;)g++;let w=n.repeat(l);for(;g<f;++g)w+=t.charAt(y[g]);return w}function a(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;let l=0,h=0,d=0;for(;u[l]===n;)h++,l++;const p=(u.length-l)*i+1>>>0,f=new Uint8Array(p);for(;l<u.length;){const m=u.charCodeAt(l);if(m>255)return;let b=e[m];if(b===255)return;let E=0;for(let $=p-1;(b!==0||E<d)&&$!==-1;$--,E++)b+=r*f[$]>>>0,f[$]=b%256>>>0,b=b/256>>>0;if(b!==0)throw new Error("Non-zero carry");d=E,l++}let y=p-d;for(;y!==p&&f[y]===0;)y++;const g=new Uint8Array(h+(p-y));let w=h;for(;y!==p;)g[w++]=f[y++];return g}function c(u){const l=a(u);if(l)return l;throw new Error("Non-base"+r+" character")}return{encode:o,decodeUnsafe:a,decode:c}}var $1="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",A1=O1($1);function Rl(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}function Tn(t,e){e||(e=t.reduce((i,s)=>i+s.length,0));const r=Rl(e);let n=0;for(const i of t)r.set(i,n),n+=i.length;return r}function P1(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var y=0,g=0,w=0,m=f.length;w!==m&&f[w]===0;)w++,y++;for(var b=(m-w)*l+1>>>0,E=new Uint8Array(b);w!==m;){for(var $=f[w],D=0,S=b-1;($!==0||D<g)&&S!==-1;S--,D++)$+=256*E[S]>>>0,E[S]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");g=D,w++}for(var A=b-g;A!==b&&E[A]===0;)A++;for(var x=c.repeat(y);A<b;++A)x+=t.charAt(E[A]);return x}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var y=0;if(f[y]!==" "){for(var g=0,w=0;f[y]===c;)g++,y++;for(var m=(f.length-y)*u+1>>>0,b=new Uint8Array(m);f[y];){var E=r[f.charCodeAt(y)];if(E===255)return;for(var $=0,D=m-1;(E!==0||$<w)&&D!==-1;D--,$++)E+=a*b[D]>>>0,b[D]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");w=$,y++}if(f[y]!==" "){for(var S=m-w;S!==m&&b[S]===0;)S++;for(var A=new Uint8Array(g+(m-S)),x=g;S!==m;)A[x++]=b[S++];return A}}}function p(f){var y=d(f);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:d,decode:p}}var T1=P1,R1=T1;const Cl=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},C1=t=>new TextEncoder().encode(t),N1=t=>new TextDecoder().decode(t);class B1{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class F1{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}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 Nl(this,e)}}class L1{constructor(e){this.decoders=e}or(e){return Nl(this,e)}decode(e){const r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Nl=(t,e)=>new L1({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class U1{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new B1(e,r,n),this.decoder=new F1(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const ki=({name:t,prefix:e,encode:r,decode:n})=>new U1(t,e,r,n),Rn=({prefix:t,name:e,alphabet:r})=>{const{encode:n,decode:i}=R1(r,e);return ki({prefix:t,name:e,encode:n,decode:s=>Cl(i(s))})},k1=(t,e,r,n)=>{const i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let s=t.length;for(;t[s-1]==="=";)--s;const o=new Uint8Array(s*r/8|0);let a=0,c=0,u=0;for(let l=0;l<s;++l){const h=i[t[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|h,a+=r,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},M1=(t,e,r)=>{const n=e[e.length-1]==="=",i=(1<<r)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[i&a>>o];if(o&&(s+=e[i&a<<r-o]),n)for(;s.length*r&7;)s+="=";return s},Pe=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>ki({prefix:e,name:t,encode(i){return M1(i,n,r)},decode(i){return k1(i,n,r,t)}}),j1=ki({prefix:"\0",name:"identity",encode:t=>N1(t),decode:t=>C1(t)});var q1=Object.freeze({__proto__:null,identity:j1});const z1=Pe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var V1=Object.freeze({__proto__:null,base2:z1});const K1=Pe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var H1=Object.freeze({__proto__:null,base8:K1});const W1=Rn({prefix:"9",name:"base10",alphabet:"0123456789"});var G1=Object.freeze({__proto__:null,base10:W1});const Y1=Pe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Z1=Pe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var J1=Object.freeze({__proto__:null,base16:Y1,base16upper:Z1});const X1=Pe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Q1=Pe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ev=Pe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),tv=Pe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),rv=Pe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),nv=Pe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),iv=Pe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),sv=Pe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ov=Pe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var av=Object.freeze({__proto__:null,base32:X1,base32upper:Q1,base32pad:ev,base32padupper:tv,base32hex:rv,base32hexupper:nv,base32hexpad:iv,base32hexpadupper:sv,base32z:ov});const cv=Rn({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),uv=Rn({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var lv=Object.freeze({__proto__:null,base36:cv,base36upper:uv});const hv=Rn({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),dv=Rn({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var fv=Object.freeze({__proto__:null,base58btc:hv,base58flickr:dv});const pv=Pe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),gv=Pe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),yv=Pe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),wv=Pe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var mv=Object.freeze({__proto__:null,base64:pv,base64pad:gv,base64url:yv,base64urlpad:wv});const Bl=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),bv=Bl.reduce((t,e,r)=>(t[r]=e,t),[]),vv=Bl.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function Ev(t){return t.reduce((e,r)=>(e+=bv[r],e),"")}function _v(t){const e=[];for(const r of t){const n=vv[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}const Sv=ki({prefix:"\u{1F680}",name:"base256emoji",encode:Ev,decode:_v});var xv=Object.freeze({__proto__:null,base256emoji:Sv}),Iv=Ll,Fl=128,Dv=127,Ov=~Dv,$v=Math.pow(2,31);function Ll(t,e,r){e=e||[],r=r||0;for(var n=r;t>=$v;)e[r++]=t&255|Fl,t/=128;for(;t&Ov;)e[r++]=t&255|Fl,t>>>=7;return e[r]=t|0,Ll.bytes=r-n+1,e}var Av=Do,Pv=128,Ul=127;function Do(t,n){var r=0,n=n||0,i=0,s=n,o,a=t.length;do{if(s>=a)throw Do.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=i<28?(o&Ul)<<i:(o&Ul)*Math.pow(2,i),i+=7}while(o>=Pv);return Do.bytes=s-n,r}var Tv=Math.pow(2,7),Rv=Math.pow(2,14),Cv=Math.pow(2,21),Nv=Math.pow(2,28),Bv=Math.pow(2,35),Fv=Math.pow(2,42),Lv=Math.pow(2,49),Uv=Math.pow(2,56),kv=Math.pow(2,63),Mv=function(t){return t<Tv?1:t<Rv?2:t<Cv?3:t<Nv?4:t<Bv?5:t<Fv?6:t<Lv?7:t<Uv?8:t<kv?9:10},jv={encode:Iv,decode:Av,encodingLength:Mv},kl=jv;const Ml=(t,e,r=0)=>(kl.encode(t,e,r),e),jl=t=>kl.encodingLength(t),Oo=(t,e)=>{const r=e.byteLength,n=jl(t),i=n+jl(r),s=new Uint8Array(i+r);return Ml(t,s,0),Ml(r,s,n),s.set(e,i),new qv(t,r,e,s)};class qv{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}}const ql=({name:t,code:e,encode:r})=>new zv(t,e,r);class zv{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?Oo(this.code,r):r.then(n=>Oo(this.code,n))}else throw Error("Unknown type, must be binary type")}}const zl=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Vv=ql({name:"sha2-256",code:18,encode:zl("SHA-256")}),Kv=ql({name:"sha2-512",code:19,encode:zl("SHA-512")});var Hv=Object.freeze({__proto__:null,sha256:Vv,sha512:Kv});const Vl=0,Wv="identity",Kl=Cl;var Gv=Object.freeze({__proto__:null,identity:{code:Vl,name:Wv,encode:Kl,digest:t=>Oo(Vl,Kl(t))}});new TextEncoder,new TextDecoder;const Hl={...q1,...V1,...H1,...G1,...J1,...av,...lv,...fv,...mv,...xv};({...Hv,...Gv});function Wl(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}const Gl=Wl("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),$o=Wl("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);const e=Rl(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Yl={utf8:Gl,"utf-8":Gl,hex:Hl.base16,latin1:$o,ascii:$o,binary:$o,...Hl};function st(t,e="utf8"){const r=Yl[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t,"utf8"):r.decoder.decode(`${r.prefix}${t}`)}function Ge(t,e="utf8"){const r=Yl[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t.buffer,t.byteOffset,t.byteLength).toString("utf8"):r.encoder.encode(t).substring(1)}const Yv={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"}},Zv=":";function Mi(t){const[e,r]=t.split(Zv);return{namespace:e,reference:r}}function Zl(t,e){return t.includes(":")?[t]:e.chains||[]}var Jv=Object.defineProperty,Xv=Object.defineProperties,Qv=Object.getOwnPropertyDescriptors,Jl=Object.getOwnPropertySymbols,eE=Object.prototype.hasOwnProperty,tE=Object.prototype.propertyIsEnumerable,Xl=(t,e,r)=>e in t?Jv(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ql=(t,e)=>{for(var r in e||(e={}))eE.call(e,r)&&Xl(t,r,e[r]);if(Jl)for(var r of Jl(e))tE.call(e,r)&&Xl(t,r,e[r]);return t},rE=(t,e)=>Xv(t,Qv(e));const nE="ReactNative",Qe={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},iE="js";function ji(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function tr(){return!_n()&&!!Ws()&&navigator.product===nE}function sE(){return tr()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function oE(){return tr()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function Cn(){return!ji()&&!!Ws()&&!!_n()}function Nn(){return tr()?Qe.reactNative:ji()?Qe.node:Cn()?Qe.browser:Qe.unknown}function eh(){var t;try{return tr()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(t=global.Application)==null?void 0:t.applicationId:void 0}catch{return}}function aE(t,e){const r=new URLSearchParams(t);for(const n of Object.keys(e).sort())if(e.hasOwnProperty(n)){const i=e[n];i!==void 0&&r.set(n,i)}return r.toString()}function cE(t){var e,r;const n=th();try{return t!=null&&t.url&&n.url&&t.url!==n.url&&(console.warn(`The configured WalletConnect 'metadata.url':${t.url} differs from the actual page url:${n.url}. This is probably unintended and can lead to issues.`),t.url=n.url),(e=t?.icons)!=null&&e.length&&t.icons.length>0&&(t.icons=t.icons.filter(i=>i!=="")),rE(Ql(Ql({},n),t),{url:t?.url||n.url,name:t?.name||n.name,description:t?.description||n.description,icons:(r=t?.icons)!=null&&r.length&&t.icons.length>0?t.icons:n.icons})}catch(i){return console.warn("Error populating app metadata",i),t||n}}function th(){return Su()||{name:"",description:"",url:"",icons:[""]}}function uE(){if(Nn()===Qe.reactNative&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"){const{OS:r,Version:n}=global.Platform;return[r,n].join("-")}const t=Ym();if(t===null)return"unknown";const e=t.os?t.os.replace(" ","").toLowerCase():"unknown";return t.type==="browser"?[e,t.name,t.version].join("-"):[e,t.version].join("-")}function lE(){var t;const e=Nn();return e===Qe.browser?[e,((t=_u())==null?void 0:t.host)||"unknown"].join(":"):e}function rh(t,e,r){const n=uE(),i=lE();return[[t,e].join("-"),[iE,r].join("-"),n,i].join("/")}function hE({protocol:t,version:e,relayUrl:r,sdkVersion:n,auth:i,projectId:s,useOnCloseEvent:o,bundleId:a,packageName:c}){const u=r.split("?"),l=rh(t,e,n),h={auth:i,ua:l,projectId:s,useOnCloseEvent:o||void 0,packageName:c||void 0,bundleId:a||void 0},d=aE(u[1]||"",h);return u[0]+"?"+d}function mr(t,e){return t.filter(r=>e.includes(r)).length===t.length}function Ao(t){return Object.fromEntries(t.entries())}function Po(t){return new Map(Object.entries(t))}function br(t=L.FIVE_MINUTES,e){const r=L.toMiliseconds(t||L.FIVE_MINUTES);let n,i,s,o;return{resolve:a=>{s&&n&&(clearTimeout(s),n(a),o=Promise.resolve(a))},reject:a=>{s&&i&&(clearTimeout(s),i(a))},done:()=>new Promise((a,c)=>{if(o)return a(o);s=setTimeout(()=>{const u=new Error(e);o=Promise.reject(u),c(u)},r),n=a,i=c})}}function rr(t,e,r){return new Promise(async(n,i)=>{const s=setTimeout(()=>i(new Error(r)),e);try{const o=await t;n(o)}catch(o){i(o)}clearTimeout(s)})}function nh(t,e){if(typeof e=="string"&&e.startsWith(`${t}:`))return e;if(t.toLowerCase()==="topic"){if(typeof e!="string")throw new Error('Value must be "string" for expirer target type: topic');return`topic:${e}`}else if(t.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: ${t}`)}function dE(t){return nh("topic",t)}function fE(t){return nh("id",t)}function ih(t){const[e,r]=t.split(":"),n={id:void 0,topic:void 0};if(e==="topic"&&typeof r=="string")n.topic=r;else if(e==="id"&&Number.isInteger(Number(r)))n.id=Number(r);else throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${r}`);return n}function me(t,e){return L.fromMiliseconds((e||Date.now())+L.toMiliseconds(t))}function nr(t){return Date.now()>=L.toMiliseconds(t)}function Q(t,e){return`${t}${e?`:${e}`:""}`}function pE(t=[],e=[]){return[...new Set([...t,...e])]}async function gE({id:t,topic:e,wcDeepLink:r}){var n;try{if(!r)return;const i=typeof r=="string"?JSON.parse(r):r,s=i?.href;if(typeof s!="string")return;const o=yE(s,t,e),a=Nn();if(a===Qe.browser){if(!((n=_n())!=null&&n.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}wE(o)}else a===Qe.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(o)}catch(i){console.error(i)}}function yE(t,e,r){const n=`requestId=${e}&sessionTopic=${r}`;t.endsWith("/")&&(t=t.slice(0,-1));let i=`${t}`;if(t.startsWith("https://t.me")){const s=t.includes("?")?"&startapp=":"?startapp=";i=`${i}${s}${EE(n,!0)}`}else i=`${i}/wc?${n}`;return i}function wE(t){let e="_self";vE()?e="_top":(bE()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function mE(t,e){let r="";try{if(Cn()&&(r=localStorage.getItem(e),r))return r;r=await t.getItem(e)}catch(n){console.error(n)}return r}function sh(t,e){if(!t.includes(e))return null;const r=t.split(/([&,?,=])/),n=r.indexOf(e);return r[n+2]}function oh(){return typeof crypto<"u"&&crypto!=null&&crypto.randomUUID?crypto.randomUUID():"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/gu,t=>{const e=Math.random()*16|0;return(t==="x"?e:e&3|8).toString(16)})}function To(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function bE(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function vE(){try{return window.self!==window.top}catch{return!1}}function EE(t,e=!1){const r=Buffer.from(t).toString("base64");return e?r.replace(/[=]/g,""):r}function ah(t){return Buffer.from(t,"base64").toString("utf-8")}function _E(t){return new Promise(e=>setTimeout(e,t))}function Bn(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function SE(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Fn(t,...e){if(!SE(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Ro(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");Bn(t.outputLen),Bn(t.blockLen)}function Jr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function ch(t,e){Fn(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}const qi=BigInt(2**32-1),uh=BigInt(32);function xE(t,e=!1){return e?{h:Number(t&qi),l:Number(t>>uh&qi)}:{h:Number(t>>uh&qi)|0,l:Number(t&qi)|0}}function IE(t,e=!1){let r=new Uint32Array(t.length),n=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:s,l:o}=xE(t[i],e);[r[i],n[i]]=[s,o]}return[r,n]}const DE=(t,e,r)=>t<<r|e>>>32-r,OE=(t,e,r)=>e<<r|t>>>32-r,$E=(t,e,r)=>e<<r-32|t>>>64-r,AE=(t,e,r)=>t<<r-32|e>>>64-r,Xr=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function PE(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Co(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function _t(t,e){return t<<32-e|t>>>e}const lh=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function TE(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function hh(t){for(let e=0;e<t.length;e++)t[e]=TE(t[e])}function RE(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function Qr(t){return typeof t=="string"&&(t=RE(t)),Fn(t),t}function CE(...t){let e=0;for(let n=0;n<t.length;n++){const i=t[n];Fn(i),e+=i.length}const r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){const s=t[n];r.set(s,i),i+=s.length}return r}class No{clone(){return this._cloneInto()}}function dh(t){const e=n=>t().update(Qr(n)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e}function en(t=32){if(Xr&&typeof Xr.getRandomValues=="function")return Xr.getRandomValues(new Uint8Array(t));if(Xr&&typeof Xr.randomBytes=="function")return Xr.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}const fh=[],ph=[],gh=[],NE=BigInt(0),Ln=BigInt(1),BE=BigInt(2),FE=BigInt(7),LE=BigInt(256),UE=BigInt(113);for(let t=0,e=Ln,r=1,n=0;t<24;t++){[r,n]=[n,(2*r+3*n)%5],fh.push(2*(5*n+r)),ph.push((t+1)*(t+2)/2%64);let i=NE;for(let s=0;s<7;s++)e=(e<<Ln^(e>>FE)*UE)%LE,e&BE&&(i^=Ln<<(Ln<<BigInt(s))-Ln);gh.push(i)}const[kE,ME]=IE(gh,!0),yh=(t,e,r)=>r>32?$E(t,e,r):DE(t,e,r),wh=(t,e,r)=>r>32?AE(t,e,r):OE(t,e,r);function jE(t,e=24){const r=new Uint32Array(10);for(let n=24-e;n<24;n++){for(let o=0;o<10;o++)r[o]=t[o]^t[o+10]^t[o+20]^t[o+30]^t[o+40];for(let o=0;o<10;o+=2){const a=(o+8)%10,c=(o+2)%10,u=r[c],l=r[c+1],h=yh(u,l,1)^r[a],d=wh(u,l,1)^r[a+1];for(let p=0;p<50;p+=10)t[o+p]^=h,t[o+p+1]^=d}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=ph[o],c=yh(i,s,a),u=wh(i,s,a),l=fh[o];i=t[l],s=t[l+1],t[l]=c,t[l+1]=u}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)r[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~r[(a+2)%10]&r[(a+4)%10]}t[0]^=kE[n],t[1]^=ME[n]}r.fill(0)}class Bo extends No{constructor(e,r,n,i=!1,s=24){if(super(),this.blockLen=e,this.suffix=r,this.outputLen=n,this.enableXOF=i,this.rounds=s,this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,Bn(n),0>=this.blockLen||this.blockLen>=200)throw new Error("Sha3 supports only keccak-f1600 function");this.state=new Uint8Array(200),this.state32=PE(this.state)}keccak(){lh||hh(this.state32),jE(this.state32,this.rounds),lh||hh(this.state32),this.posOut=0,this.pos=0}update(e){Jr(this);const{blockLen:r,state:n}=this;e=Qr(e);const i=e.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);for(let a=0;a<o;a++)n[this.pos++]^=e[s++];this.pos===r&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:r,pos:n,blockLen:i}=this;e[n]^=r,r&128&&n===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){Jr(this,!1),Fn(e),this.finish();const r=this.state,{blockLen:n}=this;for(let i=0,s=e.length;i<s;){this.posOut>=n&&this.keccak();const o=Math.min(n-this.posOut,s-i);e.set(r.subarray(this.posOut,this.posOut+o),i),this.posOut+=o,i+=o}return e}xofInto(e){if(!this.enableXOF)throw new Error("XOF is not possible for this instance");return this.writeInto(e)}xof(e){return Bn(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(ch(e,this),this.finished)throw new Error("digest() was already called");return this.writeInto(e),this.destroy(),e}digest(){return this.digestInto(new Uint8Array(this.outputLen))}destroy(){this.destroyed=!0,this.state.fill(0)}_cloneInto(e){const{blockLen:r,suffix:n,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new Bo(r,n,i,o,s)),e.state32.set(this.state32),e.pos=this.pos,e.posOut=this.posOut,e.finished=this.finished,e.rounds=s,e.suffix=n,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}}const qE=(t,e,r)=>dh(()=>new Bo(e,t,r)),zE=qE(1,136,256/8),VE="https://rpc.walletconnect.org/v1";function mh(t){const e=`Ethereum Signed Message:
18
+ ${t.length}`,r=new TextEncoder().encode(e+t);return"0x"+Buffer.from(zE(r)).toString("hex")}async function KE(t,e,r,n,i,s){switch(r.t){case"eip191":return await HE(t,e,r.s);case"eip1271":return await WE(t,e,r.s,n,i,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${r.t}`)}}async function HE(t,e,r){return(await Wb({hash:mh(e),signature:r})).toLowerCase()===t.toLowerCase()}async function WE(t,e,r,n,i,s){const o=Mi(n);if(!o.namespace||!o.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${n}`);try{const a="0x1626ba7e",c="0000000000000000000000000000000000000000000000000000000000000040",u="0000000000000000000000000000000000000000000000000000000000000041",l=r.substring(2),h=mh(e).substring(2),d=a+h+c+u+l,p=await fetch(`${s||VE}/?chainId=${n}&projectId=${i}`,{method:"POST",body:JSON.stringify({id:GE(),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:d},"latest"]})}),{result:f}=await p.json();return f?f.slice(0,a.length).toLowerCase()===a.toLowerCase():!1}catch(a){return console.error("isValidEip1271Signature: ",a),!1}}function GE(){return Date.now()+Math.floor(Math.random()*1e3)}function YE(t){const e=atob(t),r=new Uint8Array(e.length);for(let o=0;o<e.length;o++)r[o]=e.charCodeAt(o);const n=r[0];if(n===0)throw new Error("No signatures found");const i=1+n*64;if(r.length<i)throw new Error("Transaction data too short for claimed signature count");if(r.length<100)throw new Error("Transaction too short");const s=Buffer.from(t,"base64").slice(1,65);return A1.encode(s)}var ZE=Object.defineProperty,JE=Object.defineProperties,XE=Object.getOwnPropertyDescriptors,bh=Object.getOwnPropertySymbols,QE=Object.prototype.hasOwnProperty,e2=Object.prototype.propertyIsEnumerable,vh=(t,e,r)=>e in t?ZE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,t2=(t,e)=>{for(var r in e||(e={}))QE.call(e,r)&&vh(t,r,e[r]);if(bh)for(var r of bh(e))e2.call(e,r)&&vh(t,r,e[r]);return t},r2=(t,e)=>JE(t,XE(e));const n2="did:pkh:",Fo=t=>t?.split(":"),i2=t=>{const e=t&&Fo(t);if(e)return t.includes(n2)?e[3]:e[1]},Lo=t=>{const e=t&&Fo(t);if(e)return e[2]+":"+e[3]},zi=t=>{const e=t&&Fo(t);if(e)return e.pop()};async function Eh(t){const{cacao:e,projectId:r}=t,{s:n,p:i}=e,s=_h(i,i.iss),o=zi(i.iss);return await KE(o,s,n,Lo(i.iss),r)}const _h=(t,e)=>{const r=`${t.domain} wants you to sign in with your Ethereum account:`,n=zi(e);if(!t.aud&&!t.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let i=t.statement||void 0;const s=`URI: ${t.aud||t.uri}`,o=`Version: ${t.version}`,a=`Chain ID: ${i2(e)}`,c=`Nonce: ${t.nonce}`,u=`Issued At: ${t.iat}`,l=t.exp?`Expiration Time: ${t.exp}`:void 0,h=t.nbf?`Not Before: ${t.nbf}`:void 0,d=t.requestId?`Request ID: ${t.requestId}`:void 0,p=t.resources?`Resources:${t.resources.map(y=>`
19
+ - ${y}`).join("")}`:void 0,f=Vi(t.resources);if(f){const y=Un(f);i=f2(i,y)}return[r,n,"",i,"",s,o,a,c,u,l,h,d,p].filter(y=>y!=null).join(`
20
+ `)};function s2(t){return Buffer.from(JSON.stringify(t)).toString("base64")}function o2(t){return JSON.parse(Buffer.from(t,"base64").toString("utf-8"))}function vr(t){if(!t)throw new Error("No recap provided, value is undefined");if(!t.att)throw new Error("No `att` property found");const e=Object.keys(t.att);if(!(e!=null&&e.length))throw new Error("No resources found in `att` property");e.forEach(r=>{const n=t.att[r];if(Array.isArray(n))throw new Error(`Resource must be an object: ${r}`);if(typeof n!="object")throw new Error(`Resource must be an object: ${r}`);if(!Object.keys(n).length)throw new Error(`Resource object is empty: ${r}`);Object.keys(n).forEach(i=>{const s=n[i];if(!Array.isArray(s))throw new Error(`Ability limits ${i} must be an array of objects, found: ${s}`);if(!s.length)throw new Error(`Value of ${i} is empty array, must be an array with objects`);s.forEach(o=>{if(typeof o!="object")throw new Error(`Ability limits (${i}) must be an array of objects, found: ${o}`)})})})}function a2(t,e,r,n={}){return r?.sort((i,s)=>i.localeCompare(s)),{att:{[t]:c2(e,r,n)}}}function c2(t,e,r={}){e=e?.sort((i,s)=>i.localeCompare(s));const n=e.map(i=>({[`${t}/${i}`]:[r]}));return Object.assign({},...n)}function Sh(t){return vr(t),`urn:recap:${s2(t).replace(/=/g,"")}`}function Un(t){const e=o2(t.replace("urn:recap:",""));return vr(e),e}function u2(t,e,r){const n=a2(t,e,r);return Sh(n)}function l2(t){return t&&t.includes("urn:recap:")}function h2(t,e){const r=Un(t),n=Un(e),i=d2(r,n);return Sh(i)}function d2(t,e){vr(t),vr(e);const r=Object.keys(t.att).concat(Object.keys(e.att)).sort((i,s)=>i.localeCompare(s)),n={att:{}};return r.forEach(i=>{var s,o;Object.keys(((s=t.att)==null?void 0:s[i])||{}).concat(Object.keys(((o=e.att)==null?void 0:o[i])||{})).sort((a,c)=>a.localeCompare(c)).forEach(a=>{var c,u;n.att[i]=r2(t2({},n.att[i]),{[a]:((c=t.att[i])==null?void 0:c[a])||((u=e.att[i])==null?void 0:u[a])})})}),n}function f2(t="",e){vr(e);const r="I further authorize the stated URI to perform the following actions on my behalf: ";if(t.includes(r))return t;const n=[];let i=0;Object.keys(e.att).forEach(a=>{const c=Object.keys(e.att[a]).map(h=>({ability:h.split("/")[0],action:h.split("/")[1]}));c.sort((h,d)=>h.action.localeCompare(d.action));const u={};c.forEach(h=>{u[h.ability]||(u[h.ability]=[]),u[h.ability].push(h.action)});const l=Object.keys(u).map(h=>(i++,`(${i}) '${h}': '${u[h].join("', '")}' for '${a}'.`));n.push(l.join(", ").replace(".,","."))});const s=n.join(" "),o=`${r}${s}`;return`${t?t+" ":""}${o}`}function xh(t){var e;const r=Un(t);vr(r);const n=(e=r.att)==null?void 0:e.eip155;return n?Object.keys(n).map(i=>i.split("/")[1]):[]}function Ih(t){const e=Un(t);vr(e);const r=[];return Object.values(e.att).forEach(n=>{Object.values(n).forEach(i=>{var s;(s=i?.[0])!=null&&s.chains&&r.push(i[0].chains)})}),[...new Set(r.flat())]}function Vi(t){if(!t)return;const e=t?.[t.length-1];return l2(e)?e:void 0}function Uo(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Dh(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function et(t,...e){if(!Dh(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error("Uint8Array expected of length "+e+", got length="+t.length)}function Oh(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function p2(t,e){et(t);const r=e.outputLen;if(t.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function $h(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}const ir=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),g2=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);if(!(new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68))throw new Error("Non little-endian hardware is not supported");function y2(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function ko(t){if(typeof t=="string")t=y2(t);else if(Dh(t))t=Mo(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function w2(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function m2(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}const b2=(t,e)=>{function r(n,...i){if(et(n),t.nonceLength!==void 0){const u=i[0];if(!u)throw new Error("nonce / iv required");t.varSizeNonce?et(u):et(u,t.nonceLength)}const s=t.tagLength;s&&i[1]!==void 0&&et(i[1]);const o=e(n,...i),a=(u,l)=>{if(l!==void 0){if(u!==2)throw new Error("cipher output not supported");et(l)}};let c=!1;return{encrypt(u,l){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,et(u),a(o.encrypt.length,l),o.encrypt(u,l)},decrypt(u,l){if(et(u),s&&u.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return a(o.decrypt.length,l),o.decrypt(u,l)}}}return Object.assign(r,t),r};function Ah(t,e,r=!0){if(e===void 0)return new Uint8Array(t);if(e.length!==t)throw new Error("invalid output length, expected "+t+", got: "+e.length);if(r&&!v2(e))throw new Error("invalid output, must be aligned");return e}function Ph(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),c=n?4:0,u=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+u,a,n)}function v2(t){return t.byteOffset%4===0}function Mo(t){return Uint8Array.from(t)}function tn(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}const Th=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),E2=Th("expand 16-byte k"),_2=Th("expand 32-byte k"),S2=ir(E2),x2=ir(_2);function J(t,e){return t<<e|t>>>32-e}function jo(t){return t.byteOffset%4===0}const Ki=64,I2=16,Rh=2**32-1,Ch=new Uint32Array;function D2(t,e,r,n,i,s,o,a){const c=i.length,u=new Uint8Array(Ki),l=ir(u),h=jo(i)&&jo(s),d=h?ir(i):Ch,p=h?ir(s):Ch;for(let f=0;f<c;o++){if(t(e,r,n,l,o,a),o>=Rh)throw new Error("arx: counter overflow");const y=Math.min(Ki,c-f);if(h&&y===Ki){const g=f/4;if(f%4!==0)throw new Error("arx: invalid block position");for(let w=0,m;w<I2;w++)m=g+w,p[m]=d[m]^l[w];f+=Ki;continue}for(let g=0,w;g<y;g++)w=f+g,s[w]=i[w]^u[g];f+=y}}function O2(t,e){const{allowShortKeys:r,extendNonceFn:n,counterLength:i,counterRight:s,rounds:o}=w2({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Uo(i),Uo(o),$h(s),$h(r),(a,c,u,l,h=0)=>{et(a),et(c),et(u);const d=u.length;if(l===void 0&&(l=new Uint8Array(d)),et(l),Uo(h),h<0||h>=Rh)throw new Error("arx: counter overflow");if(l.length<d)throw new Error(`arx: output (${l.length}) is shorter than data (${d})`);const p=[];let f=a.length,y,g;if(f===32)p.push(y=Mo(a)),g=x2;else if(f===16&&r)y=new Uint8Array(32),y.set(a),y.set(a,16),g=S2,p.push(y);else throw new Error(`arx: invalid 32-byte key, got length=${f}`);jo(c)||p.push(c=Mo(c));const w=ir(y);if(n){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");n(g,w,ir(c.subarray(0,16)),w),c=c.subarray(16)}const m=16-i;if(m!==c.length)throw new Error(`arx: nonce must be ${m} or 16 bytes`);if(m!==12){const E=new Uint8Array(12);E.set(c,s?0:12-c.length),c=E,p.push(c)}const b=ir(c);return D2(t,g,w,b,u,l,h,o),tn(...p),l}}const Te=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class $2{constructor(e){this.blockLen=16,this.outputLen=16,this.buffer=new Uint8Array(16),this.r=new Uint16Array(10),this.h=new Uint16Array(10),this.pad=new Uint16Array(8),this.pos=0,this.finished=!1,e=ko(e),et(e,32);const r=Te(e,0),n=Te(e,2),i=Te(e,4),s=Te(e,6),o=Te(e,8),a=Te(e,10),c=Te(e,12),u=Te(e,14);this.r[0]=r&8191,this.r[1]=(r>>>13|n<<3)&8191,this.r[2]=(n>>>10|i<<6)&7939,this.r[3]=(i>>>7|s<<9)&8191,this.r[4]=(s>>>4|o<<12)&255,this.r[5]=o>>>1&8190,this.r[6]=(o>>>14|a<<2)&8191,this.r[7]=(a>>>11|c<<5)&8065,this.r[8]=(c>>>8|u<<8)&8191,this.r[9]=u>>>5&127;for(let l=0;l<8;l++)this.pad[l]=Te(e,16+2*l)}process(e,r,n=!1){const i=n?0:2048,{h:s,r:o}=this,a=o[0],c=o[1],u=o[2],l=o[3],h=o[4],d=o[5],p=o[6],f=o[7],y=o[8],g=o[9],w=Te(e,r+0),m=Te(e,r+2),b=Te(e,r+4),E=Te(e,r+6),$=Te(e,r+8),D=Te(e,r+10),S=Te(e,r+12),A=Te(e,r+14);let x=s[0]+(w&8191),k=s[1]+((w>>>13|m<<3)&8191),C=s[2]+((m>>>10|b<<6)&8191),B=s[3]+((b>>>7|E<<9)&8191),j=s[4]+((E>>>4|$<<12)&8191),I=s[5]+($>>>1&8191),_=s[6]+(($>>>14|D<<2)&8191),v=s[7]+((D>>>11|S<<5)&8191),O=s[8]+((S>>>8|A<<8)&8191),T=s[9]+(A>>>5|i),P=0,N=P+x*a+k*(5*g)+C*(5*y)+B*(5*f)+j*(5*p);P=N>>>13,N&=8191,N+=I*(5*d)+_*(5*h)+v*(5*l)+O*(5*u)+T*(5*c),P+=N>>>13,N&=8191;let F=P+x*c+k*a+C*(5*g)+B*(5*y)+j*(5*f);P=F>>>13,F&=8191,F+=I*(5*p)+_*(5*d)+v*(5*h)+O*(5*l)+T*(5*u),P+=F>>>13,F&=8191;let M=P+x*u+k*c+C*a+B*(5*g)+j*(5*y);P=M>>>13,M&=8191,M+=I*(5*f)+_*(5*p)+v*(5*d)+O*(5*h)+T*(5*l),P+=M>>>13,M&=8191;let z=P+x*l+k*u+C*c+B*a+j*(5*g);P=z>>>13,z&=8191,z+=I*(5*y)+_*(5*f)+v*(5*p)+O*(5*d)+T*(5*h),P+=z>>>13,z&=8191;let q=P+x*h+k*l+C*u+B*c+j*a;P=q>>>13,q&=8191,q+=I*(5*g)+_*(5*y)+v*(5*f)+O*(5*p)+T*(5*d),P+=q>>>13,q&=8191;let V=P+x*d+k*h+C*l+B*u+j*c;P=V>>>13,V&=8191,V+=I*a+_*(5*g)+v*(5*y)+O*(5*f)+T*(5*p),P+=V>>>13,V&=8191;let K=P+x*p+k*d+C*h+B*l+j*u;P=K>>>13,K&=8191,K+=I*c+_*a+v*(5*g)+O*(5*y)+T*(5*f),P+=K>>>13,K&=8191;let ee=P+x*f+k*p+C*d+B*h+j*l;P=ee>>>13,ee&=8191,ee+=I*u+_*c+v*a+O*(5*g)+T*(5*y),P+=ee>>>13,ee&=8191;let G=P+x*y+k*f+C*p+B*d+j*h;P=G>>>13,G&=8191,G+=I*l+_*u+v*c+O*a+T*(5*g),P+=G>>>13,G&=8191;let W=P+x*g+k*y+C*f+B*p+j*d;P=W>>>13,W&=8191,W+=I*h+_*l+v*u+O*c+T*a,P+=W>>>13,W&=8191,P=(P<<2)+P|0,P=P+N|0,N=P&8191,P=P>>>13,F+=P,s[0]=N,s[1]=F,s[2]=M,s[3]=z,s[4]=q,s[5]=V,s[6]=K,s[7]=ee,s[8]=G,s[9]=W}finalize(){const{h:e,pad:r}=this,n=new Uint16Array(10);let i=e[1]>>>13;e[1]&=8191;for(let a=2;a<10;a++)e[a]+=i,i=e[a]>>>13,e[a]&=8191;e[0]+=i*5,i=e[0]>>>13,e[0]&=8191,e[1]+=i,i=e[1]>>>13,e[1]&=8191,e[2]+=i,n[0]=e[0]+5,i=n[0]>>>13,n[0]&=8191;for(let a=1;a<10;a++)n[a]=e[a]+i,i=n[a]>>>13,n[a]&=8191;n[9]-=8192;let s=(i^1)-1;for(let a=0;a<10;a++)n[a]&=s;s=~s;for(let a=0;a<10;a++)e[a]=e[a]&s|n[a];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let o=e[0]+r[0];e[0]=o&65535;for(let a=1;a<8;a++)o=(e[a]+r[a]|0)+(o>>>16)|0,e[a]=o&65535;tn(n)}update(e){Oh(this);const{buffer:r,blockLen:n}=this;e=ko(e);const i=e.length;for(let s=0;s<i;){const o=Math.min(n-this.pos,i-s);if(o===n){for(;n<=i-s;s+=n)this.process(e,s);continue}r.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===n&&(this.process(r,0,!1),this.pos=0)}return this}destroy(){tn(this.h,this.r,this.buffer,this.pad)}digestInto(e){Oh(this),p2(e,this),this.finished=!0;const{buffer:r,h:n}=this;let{pos:i}=this;if(i){for(r[i++]=1;i<16;i++)r[i]=0;this.process(r,0,!0)}this.finalize();let s=0;for(let o=0;o<8;o++)e[s++]=n[o]>>>0,e[s++]=n[o]>>>8;return e}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const n=e.slice(0,r);return this.destroy(),n}}function A2(t){const e=(n,i)=>t(i).update(ko(n)).digest(),r=t(new Uint8Array(32));return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=n=>t(n),e}const P2=A2(t=>new $2(t));function T2(t,e,r,n,i,s=20){let o=t[0],a=t[1],c=t[2],u=t[3],l=e[0],h=e[1],d=e[2],p=e[3],f=e[4],y=e[5],g=e[6],w=e[7],m=i,b=r[0],E=r[1],$=r[2],D=o,S=a,A=c,x=u,k=l,C=h,B=d,j=p,I=f,_=y,v=g,O=w,T=m,P=b,N=E,F=$;for(let z=0;z<s;z+=2)D=D+k|0,T=J(T^D,16),I=I+T|0,k=J(k^I,12),D=D+k|0,T=J(T^D,8),I=I+T|0,k=J(k^I,7),S=S+C|0,P=J(P^S,16),_=_+P|0,C=J(C^_,12),S=S+C|0,P=J(P^S,8),_=_+P|0,C=J(C^_,7),A=A+B|0,N=J(N^A,16),v=v+N|0,B=J(B^v,12),A=A+B|0,N=J(N^A,8),v=v+N|0,B=J(B^v,7),x=x+j|0,F=J(F^x,16),O=O+F|0,j=J(j^O,12),x=x+j|0,F=J(F^x,8),O=O+F|0,j=J(j^O,7),D=D+C|0,F=J(F^D,16),v=v+F|0,C=J(C^v,12),D=D+C|0,F=J(F^D,8),v=v+F|0,C=J(C^v,7),S=S+B|0,T=J(T^S,16),O=O+T|0,B=J(B^O,12),S=S+B|0,T=J(T^S,8),O=O+T|0,B=J(B^O,7),A=A+j|0,P=J(P^A,16),I=I+P|0,j=J(j^I,12),A=A+j|0,P=J(P^A,8),I=I+P|0,j=J(j^I,7),x=x+k|0,N=J(N^x,16),_=_+N|0,k=J(k^_,12),x=x+k|0,N=J(N^x,8),_=_+N|0,k=J(k^_,7);let M=0;n[M++]=o+D|0,n[M++]=a+S|0,n[M++]=c+A|0,n[M++]=u+x|0,n[M++]=l+k|0,n[M++]=h+C|0,n[M++]=d+B|0,n[M++]=p+j|0,n[M++]=f+I|0,n[M++]=y+_|0,n[M++]=g+v|0,n[M++]=w+O|0,n[M++]=m+T|0,n[M++]=b+P|0,n[M++]=E+N|0,n[M++]=$+F|0}const R2=O2(T2,{counterRight:!1,counterLength:4,allowShortKeys:!1}),C2=new Uint8Array(16),Nh=(t,e)=>{t.update(e);const r=e.length%16;r&&t.update(C2.subarray(r))},N2=new Uint8Array(32);function Bh(t,e,r,n,i){const s=t(e,r,N2),o=P2.create(s);i&&Nh(o,i),Nh(o,n);const a=new Uint8Array(16),c=g2(a);Ph(c,0,BigInt(i?i.length:0),!0),Ph(c,8,BigInt(n.length),!0),o.update(a);const u=o.digest();return tn(s,a),u}const B2=t=>(e,r,n)=>({encrypt(i,s){const o=i.length;s=Ah(o+16,s,!1),s.set(i);const a=s.subarray(0,-16);t(e,r,a,a,1);const c=Bh(t,e,r,a,n);return s.set(c,o),tn(c),s},decrypt(i,s){s=Ah(i.length-16,s,!1);const o=i.subarray(0,-16),a=i.subarray(-16),c=Bh(t,e,r,o,n);if(!m2(a,c))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),t(e,r,s,s,1),tn(c),s}}),Fh=b2({blockSize:64,nonceLength:12,tagLength:16},B2(R2));class Lh extends No{constructor(e,r){super(),this.finished=!1,this.destroyed=!1,Ro(e);const n=Qr(r);if(this.iHash=e.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const i=this.blockLen,s=new Uint8Array(i);s.set(n.length>i?e.create().update(n).digest():n);for(let o=0;o<s.length;o++)s[o]^=54;this.iHash.update(s),this.oHash=e.create();for(let o=0;o<s.length;o++)s[o]^=106;this.oHash.update(s),s.fill(0)}update(e){return Jr(this),this.iHash.update(e),this}digestInto(e){Jr(this),Fn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash:r,iHash:n,finished:i,destroyed:s,blockLen:o,outputLen:a}=this;return e=e,e.finished=i,e.destroyed=s,e.blockLen=o,e.outputLen=a,e.oHash=r._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Hi=(t,e,r)=>new Lh(t,e).update(r).digest();Hi.create=(t,e)=>new Lh(t,e);function F2(t,e,r){return Ro(t),r===void 0&&(r=new Uint8Array(t.outputLen)),Hi(t,Qr(r),Qr(e))}const qo=new Uint8Array([0]),Uh=new Uint8Array;function L2(t,e,r,n=32){if(Ro(t),Bn(n),n>255*t.outputLen)throw new Error("Length should be <= 255*HashLen");const i=Math.ceil(n/t.outputLen);r===void 0&&(r=Uh);const s=new Uint8Array(i*t.outputLen),o=Hi.create(t,e),a=o._cloneInto(),c=new Uint8Array(o.outputLen);for(let u=0;u<i;u++)qo[0]=u+1,a.update(u===0?Uh:c).update(r).update(qo).digestInto(c),s.set(c,t.outputLen*u),o._cloneInto(a);return o.destroy(),a.destroy(),c.fill(0),qo.fill(0),s.slice(0,n)}const U2=(t,e,r,n,i)=>L2(t,F2(t,e,r),n,i);function k2(t,e,r,n){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,r,n);const i=BigInt(32),s=BigInt(4294967295),o=Number(r>>i&s),a=Number(r&s),c=n?4:0,u=n?0:4;t.setUint32(e+c,o,n),t.setUint32(e+u,a,n)}function M2(t,e,r){return t&e^~t&r}function j2(t,e,r){return t&e^t&r^e&r}class q2 extends No{constructor(e,r,n,i){super(),this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Co(this.buffer)}update(e){Jr(this);const{view:r,buffer:n,blockLen:i}=this;e=Qr(e);const s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Co(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Jr(this),ch(e,this),this.finished=!0;const{buffer:r,view:n,blockLen:i,isLE:s}=this;let{pos:o}=this;r[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let h=o;h<i;h++)r[h]=0;k2(n,i-8,BigInt(this.length*8),s),this.process(n,0);const a=Co(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<u;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:r}=this;this.digestInto(e);const n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.length=i,e.pos=a,e.finished=s,e.destroyed=o,i%r&&e.buffer.set(n),e}}const z2=new Uint32Array([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]),sr=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),or=new Uint32Array(64);class V2 extends q2{constructor(){super(64,32,8,!1),this.A=sr[0]|0,this.B=sr[1]|0,this.C=sr[2]|0,this.D=sr[3]|0,this.E=sr[4]|0,this.F=sr[5]|0,this.G=sr[6]|0,this.H=sr[7]|0}get(){const{A:e,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,r,n,i,s,o,a,c]}set(e,r,n,i,s,o,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let h=0;h<16;h++,r+=4)or[h]=e.getUint32(r,!1);for(let h=16;h<64;h++){const d=or[h-15],p=or[h-2],f=_t(d,7)^_t(d,18)^d>>>3,y=_t(p,17)^_t(p,19)^p>>>10;or[h]=y+or[h-7]+f+or[h-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:l}=this;for(let h=0;h<64;h++){const d=_t(a,6)^_t(a,11)^_t(a,25),p=l+d+M2(a,c,u)+z2[h]+or[h]|0,f=(_t(n,2)^_t(n,13)^_t(n,22))+j2(n,i,s)|0;l=u,u=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+f|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,i,s,o,a,c,u,l)}roundClean(){or.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}const kn=dh(()=>new V2);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Wi=BigInt(0),Gi=BigInt(1),K2=BigInt(2);function Er(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Mn(t){if(!Er(t))throw new Error("Uint8Array expected")}function rn(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const H2=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function nn(t){Mn(t);let e="";for(let r=0;r<t.length;r++)e+=H2[t[r]];return e}function sn(t){const e=t.toString(16);return e.length&1?"0"+e:e}function zo(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Wi:BigInt("0x"+t)}const Lt={_0:48,_9:57,A:65,F:70,a:97,f:102};function kh(t){if(t>=Lt._0&&t<=Lt._9)return t-Lt._0;if(t>=Lt.A&&t<=Lt.F)return t-(Lt.A-10);if(t>=Lt.a&&t<=Lt.f)return t-(Lt.a-10)}function on(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){const o=kh(t.charCodeAt(s)),a=kh(t.charCodeAt(s+1));if(o===void 0||a===void 0){const c=t[s]+t[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function _r(t){return zo(nn(t))}function jn(t){return Mn(t),zo(nn(Uint8Array.from(t).reverse()))}function an(t,e){return on(t.toString(16).padStart(e*2,"0"))}function Yi(t,e){return an(t,e).reverse()}function W2(t){return on(sn(t))}function tt(t,e,r){let n;if(typeof e=="string")try{n=on(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Er(e))n=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=n.length;if(typeof r=="number"&&i!==r)throw new Error(t+" of length "+r+" expected, got "+i);return n}function qn(...t){let e=0;for(let n=0;n<t.length;n++){const i=t[n];Mn(i),e+=i.length}const r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){const s=t[n];r.set(s,i),i+=s.length}return r}function G2(t,e){if(t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function Y2(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}const Vo=t=>typeof t=="bigint"&&Wi<=t;function Zi(t,e,r){return Vo(t)&&Vo(e)&&Vo(r)&&e<=t&&t<r}function Ut(t,e,r,n){if(!Zi(e,r,n))throw new Error("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Mh(t){let e;for(e=0;t>Wi;t>>=Gi,e+=1);return e}function Z2(t,e){return t>>BigInt(e)&Gi}function J2(t,e,r){return t|(r?Gi:Wi)<<BigInt(e)}const Ko=t=>(K2<<BigInt(t-1))-Gi,Ho=t=>new Uint8Array(t),jh=t=>Uint8Array.from(t);function qh(t,e,r){if(typeof t!="number"||t<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=Ho(t),i=Ho(t),s=0;const o=()=>{n.fill(1),i.fill(0),s=0},a=(...l)=>r(i,n,...l),c=(l=Ho())=>{i=a(jh([0]),l),n=a(),l.length!==0&&(i=a(jh([1]),l),n=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let l=0;const h=[];for(;l<e;){n=a();const d=n.slice();h.push(d),l+=n.length}return qn(...h)};return(l,h)=>{o(),c(l);let d;for(;!(d=h(u()));)c();return o(),d}}const X2={bigint:t=>typeof t=="bigint",function:t=>typeof t=="function",boolean:t=>typeof t=="boolean",string:t=>typeof t=="string",stringOrUint8Array:t=>typeof t=="string"||Er(t),isSafeInteger:t=>Number.isSafeInteger(t),array:t=>Array.isArray(t),field:(t,e)=>e.Fp.isValid(t),hash:t=>typeof t=="function"&&Number.isSafeInteger(t.outputLen)};function cn(t,e,r={}){const n=(i,s,o)=>{const a=X2[s];if(typeof a!="function")throw new Error("invalid validator function");const c=t[i];if(!(o&&c===void 0)&&!a(c,t))throw new Error("param "+String(i)+" is invalid. Expected "+s+", got "+c)};for(const[i,s]of Object.entries(e))n(i,s,!1);for(const[i,s]of Object.entries(r))n(i,s,!0);return t}const Q2=()=>{throw new Error("not implemented")};function Wo(t){const e=new WeakMap;return(r,...n)=>{const i=e.get(r);if(i!==void 0)return i;const s=t(r,...n);return e.set(r,s),s}}var e_=Object.freeze({__proto__:null,isBytes:Er,abytes:Mn,abool:rn,bytesToHex:nn,numberToHexUnpadded:sn,hexToNumber:zo,hexToBytes:on,bytesToNumberBE:_r,bytesToNumberLE:jn,numberToBytesBE:an,numberToBytesLE:Yi,numberToVarBytesBE:W2,ensureBytes:tt,concatBytes:qn,equalBytes:G2,utf8ToBytes:Y2,inRange:Zi,aInRange:Ut,bitLen:Mh,bitGet:Z2,bitSet:J2,bitMask:Ko,createHmacDrbg:qh,validateObject:cn,notImplemented:Q2,memoized:Wo});const Se=BigInt(0),fe=BigInt(1),Sr=BigInt(2),t_=BigInt(3),Go=BigInt(4),zh=BigInt(5),Vh=BigInt(8);function Ye(t,e){const r=t%e;return r>=Se?r:e+r}function Kh(t,e,r){if(e<Se)throw new Error("invalid exponent, negatives unsupported");if(r<=Se)throw new Error("invalid modulus");if(r===fe)return Se;let n=fe;for(;e>Se;)e&fe&&(n=n*t%r),t=t*t%r,e>>=fe;return n}function ht(t,e,r){let n=t;for(;e-- >Se;)n*=n,n%=r;return n}function Yo(t,e){if(t===Se)throw new Error("invert: expected non-zero number");if(e<=Se)throw new Error("invert: expected positive modulus, got "+e);let r=Ye(t,e),n=e,i=Se,s=fe;for(;r!==Se;){const o=n/r,a=n%r,c=i-s*o;n=r,r=a,i=s,s=c}if(n!==fe)throw new Error("invert: does not exist");return Ye(i,e)}function r_(t){const e=(t-fe)/Sr;let r,n,i;for(r=t-fe,n=0;r%Sr===Se;r/=Sr,n++);for(i=Sr;i<t&&Kh(i,e,t)!==t-fe;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(n===1){const o=(t+fe)/Go;return function(a,c){const u=a.pow(c,o);if(!a.eql(a.sqr(u),c))throw new Error("Cannot find square root");return u}}const s=(r+fe)/Sr;return function(o,a){if(o.pow(a,e)===o.neg(o.ONE))throw new Error("Cannot find square root");let c=n,u=o.pow(o.mul(o.ONE,i),r),l=o.pow(a,s),h=o.pow(a,r);for(;!o.eql(h,o.ONE);){if(o.eql(h,o.ZERO))return o.ZERO;let d=1;for(let f=o.sqr(h);d<c&&!o.eql(f,o.ONE);d++)f=o.sqr(f);const p=o.pow(u,fe<<BigInt(c-d-1));u=o.sqr(p),l=o.mul(l,p),h=o.mul(h,u),c=d}return l}}function n_(t){if(t%Go===t_){const e=(t+fe)/Go;return function(r,n){const i=r.pow(n,e);if(!r.eql(r.sqr(i),n))throw new Error("Cannot find square root");return i}}if(t%Vh===zh){const e=(t-zh)/Vh;return function(r,n){const i=r.mul(n,Sr),s=r.pow(i,e),o=r.mul(n,s),a=r.mul(r.mul(o,Sr),s),c=r.mul(o,r.sub(a,r.ONE));if(!r.eql(r.sqr(c),n))throw new Error("Cannot find square root");return c}}return r_(t)}const i_=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function s_(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},r=i_.reduce((n,i)=>(n[i]="function",n),e);return cn(t,r)}function o_(t,e,r){if(r<Se)throw new Error("invalid exponent, negatives unsupported");if(r===Se)return t.ONE;if(r===fe)return e;let n=t.ONE,i=e;for(;r>Se;)r&fe&&(n=t.mul(n,i)),i=t.sqr(i),r>>=fe;return n}function a_(t,e){const r=new Array(e.length),n=e.reduce((s,o,a)=>t.is0(o)?s:(r[a]=s,t.mul(s,o)),t.ONE),i=t.inv(n);return e.reduceRight((s,o,a)=>t.is0(o)?s:(r[a]=t.mul(s,r[a]),t.mul(s,o)),i),r}function Hh(t,e){const r=e!==void 0?e:t.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Wh(t,e,r=!1,n={}){if(t<=Se)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=Hh(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:r,BITS:i,BYTES:s,MASK:Ko(i),ZERO:Se,ONE:fe,create:c=>Ye(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Se<=c&&c<t},is0:c=>c===Se,isOdd:c=>(c&fe)===fe,neg:c=>Ye(-c,t),eql:(c,u)=>c===u,sqr:c=>Ye(c*c,t),add:(c,u)=>Ye(c+u,t),sub:(c,u)=>Ye(c-u,t),mul:(c,u)=>Ye(c*u,t),pow:(c,u)=>o_(a,c,u),div:(c,u)=>Ye(c*Yo(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Yo(c,t),sqrt:n.sqrt||(c=>(o||(o=n_(t)),o(a,c))),invertBatch:c=>a_(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>r?Yi(c,s):an(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return r?jn(c):_r(c)}});return Object.freeze(a)}function Gh(t){if(typeof t!="bigint")throw new Error("field order must be bigint");const e=t.toString(2).length;return Math.ceil(e/8)}function Yh(t){const e=Gh(t);return e+Math.ceil(e/2)}function c_(t,e,r=!1){const n=t.length,i=Gh(e),s=Yh(e);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);const o=r?jn(t):_r(t),a=Ye(o,e-fe)+fe;return r?Yi(a,i):an(a,i)}const Zh=BigInt(0),Ji=BigInt(1);function Zo(t,e){const r=e.negate();return t?r:e}function Jh(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Jo(t,e){Jh(t,e);const r=Math.ceil(e/t)+1,n=2**(t-1);return{windows:r,windowSize:n}}function u_(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((r,n)=>{if(!(r instanceof e))throw new Error("invalid point at index "+n)})}function l_(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((r,n)=>{if(!e.isValid(r))throw new Error("invalid scalar at index "+n)})}const Xo=new WeakMap,Xh=new WeakMap;function Qo(t){return Xh.get(t)||1}function h_(t,e){return{constTimeNegate:Zo,hasPrecomputes(r){return Qo(r)!==1},unsafeLadder(r,n,i=t.ZERO){let s=r;for(;n>Zh;)n&Ji&&(i=i.add(s)),s=s.double(),n>>=Ji;return i},precomputeWindow(r,n){const{windows:i,windowSize:s}=Jo(n,e),o=[];let a=r,c=a;for(let u=0;u<i;u++){c=a,o.push(c);for(let l=1;l<s;l++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(r,n,i){const{windows:s,windowSize:o}=Jo(r,e);let a=t.ZERO,c=t.BASE;const u=BigInt(2**r-1),l=2**r,h=BigInt(r);for(let d=0;d<s;d++){const p=d*o;let f=Number(i&u);i>>=h,f>o&&(f-=l,i+=Ji);const y=p,g=p+Math.abs(f)-1,w=d%2!==0,m=f<0;f===0?c=c.add(Zo(w,n[y])):a=a.add(Zo(m,n[g]))}return{p:a,f:c}},wNAFUnsafe(r,n,i,s=t.ZERO){const{windows:o,windowSize:a}=Jo(r,e),c=BigInt(2**r-1),u=2**r,l=BigInt(r);for(let h=0;h<o;h++){const d=h*a;if(i===Zh)break;let p=Number(i&c);if(i>>=l,p>a&&(p-=u,i+=Ji),p===0)continue;let f=n[d+Math.abs(p)-1];p<0&&(f=f.negate()),s=s.add(f)}return s},getPrecomputes(r,n,i){let s=Xo.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&Xo.set(n,i(s))),s},wNAFCached(r,n,i){const s=Qo(r);return this.wNAF(s,this.getPrecomputes(s,r,i),n)},wNAFCachedUnsafe(r,n,i,s){const o=Qo(r);return o===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(o,this.getPrecomputes(o,r,i),n,s)},setWindowSize(r,n){Jh(n,e),Xh.set(r,n),Xo.delete(r)}}}function d_(t,e,r,n){if(u_(r,t),l_(n,e),r.length!==n.length)throw new Error("arrays of points and scalars must have equal length");const i=t.ZERO,s=Mh(BigInt(r.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=(1<<o)-1,c=new Array(a+1).fill(i),u=Math.floor((e.BITS-1)/o)*o;let l=i;for(let h=u;h>=0;h-=o){c.fill(i);for(let p=0;p<n.length;p++){const f=n[p],y=Number(f>>BigInt(h)&BigInt(a));c[y]=c[y].add(r[p])}let d=i;for(let p=c.length-1,f=i;p>0;p--)f=f.add(c[p]),d=d.add(f);if(l=l.add(d),h!==0)for(let p=0;p<o;p++)l=l.double()}return l}function Qh(t){return s_(t.Fp),cn(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Hh(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}BigInt(0),BigInt(1),BigInt(2),BigInt(8);const un=BigInt(0),ea=BigInt(1);function f_(t){return cn(t,{a:"bigint"},{montgomeryBits:"isSafeInteger",nByteLength:"isSafeInteger",adjustScalarBytes:"function",domain:"function",powPminus2:"function",Gu:"bigint"}),Object.freeze({...t})}function p_(t){const e=f_(t),{P:r}=e,n=m=>Ye(m,r),i=e.montgomeryBits,s=Math.ceil(i/8),o=e.nByteLength,a=e.adjustScalarBytes||(m=>m),c=e.powPminus2||(m=>Kh(m,r-BigInt(2),r));function u(m,b,E){const $=n(m*(b-E));return b=n(b-$),E=n(E+$),[b,E]}const l=(e.a-BigInt(2))/BigInt(4);function h(m,b){Ut("u",m,un,r),Ut("scalar",b,un,r);const E=b,$=m;let D=ea,S=un,A=m,x=ea,k=un,C;for(let j=BigInt(i-1);j>=un;j--){const I=E>>j&ea;k^=I,C=u(k,D,A),D=C[0],A=C[1],C=u(k,S,x),S=C[0],x=C[1],k=I;const _=D+S,v=n(_*_),O=D-S,T=n(O*O),P=v-T,N=A+x,F=A-x,M=n(F*_),z=n(N*O),q=M+z,V=M-z;A=n(q*q),x=n($*n(V*V)),D=n(v*T),S=n(P*(v+n(l*P)))}C=u(k,D,A),D=C[0],A=C[1],C=u(k,S,x),S=C[0],x=C[1];const B=c(S);return n(D*B)}function d(m){return Yi(n(m),s)}function p(m){const b=tt("u coordinate",m,s);return o===32&&(b[31]&=127),jn(b)}function f(m){const b=tt("scalar",m),E=b.length;if(E!==s&&E!==o){let $=""+s+" or "+o;throw new Error("invalid scalar, expected "+$+" bytes, got "+E)}return jn(a(b))}function y(m,b){const E=p(b),$=f(m),D=h(E,$);if(D===un)throw new Error("invalid private or public key received");return d(D)}const g=d(e.Gu);function w(m){return y(m,g)}return{scalarMult:y,scalarMultBase:w,getSharedSecret:(m,b)=>y(m,b),getPublicKey:m=>w(m),utils:{randomPrivateKey:()=>e.randomBytes(e.nByteLength)},GuBytes:g}}const ta=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949");BigInt(0);const g_=BigInt(1),ed=BigInt(2),y_=BigInt(3),w_=BigInt(5);BigInt(8);function m_(t){const e=BigInt(10),r=BigInt(20),n=BigInt(40),i=BigInt(80),s=ta,o=t*t%s*t%s,a=ht(o,ed,s)*o%s,c=ht(a,g_,s)*t%s,u=ht(c,w_,s)*c%s,l=ht(u,e,s)*u%s,h=ht(l,r,s)*l%s,d=ht(h,n,s)*h%s,p=ht(d,i,s)*d%s,f=ht(p,i,s)*d%s,y=ht(f,e,s)*u%s;return{pow_p_5_8:ht(y,ed,s)*t%s,b2:o}}function b_(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const ra=p_({P:ta,a:BigInt(486662),montgomeryBits:255,nByteLength:32,Gu:BigInt(9),powPminus2:t=>{const e=ta,{pow_p_5_8:r,b2:n}=m_(t);return Ye(ht(r,y_,e)*n,e)},adjustScalarBytes:b_,randomBytes:en});function td(t){t.lowS!==void 0&&rn("lowS",t.lowS),t.prehash!==void 0&&rn("prehash",t.prehash)}function v_(t){const e=Qh(t);cn(e,{a:"field",b:"field"},{allowedPrivateKeyLengths:"array",wrapPrivateKey:"boolean",isTorsionFree:"function",clearCofactor:"function",allowInfinityPoint:"boolean",fromBytes:"function",toBytes:"function"});const{endo:r,Fp:n,a:i}=e;if(r){if(!n.eql(i,n.ZERO))throw new Error("invalid endomorphism, can only be defined for Koblitz curves that have a=0");if(typeof r!="object"||typeof r.beta!="bigint"||typeof r.splitScalar!="function")throw new Error("invalid endomorphism, expected beta: bigint and splitScalar: function")}return Object.freeze({...e})}const{bytesToNumberBE:E_,hexToBytes:__}=e_;class S_ extends Error{constructor(e=""){super(e)}}const kt={Err:S_,_tlv:{encode:(t,e)=>{const{Err:r}=kt;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length&1)throw new r("tlv.encode: unpadded data");const n=e.length/2,i=sn(n);if(i.length/2&128)throw new r("tlv.encode: long form length too big");const s=n>127?sn(i.length/2|128):"";return sn(t)+s+i+e},decode(t,e){const{Err:r}=kt;let n=0;if(t<0||t>256)throw new r("tlv.encode: wrong tag");if(e.length<2||e[n++]!==t)throw new r("tlv.decode: wrong tlv");const i=e[n++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");const u=e.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(const l of u)o=o<<8|l;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}const a=e.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:e.subarray(n+o)}}},_int:{encode(t){const{Err:e}=kt;if(t<Mt)throw new e("integer: negative integers are not allowed");let r=sn(t);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return r},decode(t){const{Err:e}=kt;if(t[0]&128)throw new e("invalid signature integer: negative");if(t[0]===0&&!(t[1]&128))throw new e("invalid signature integer: unnecessary leading zero");return E_(t)}},toSig(t){const{Err:e,_int:r,_tlv:n}=kt,i=typeof t=="string"?__(t):t;Mn(i);const{v:s,l:o}=n.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=n.decode(2,s),{v:u,l}=n.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(u)}},hexFromSig(t){const{_tlv:e,_int:r}=kt,n=e.encode(2,r.encode(t.r)),i=e.encode(2,r.encode(t.s)),s=n+i;return e.encode(48,s)}},Mt=BigInt(0),xe=BigInt(1);BigInt(2);const rd=BigInt(3);BigInt(4);function x_(t){const e=v_(t),{Fp:r}=e,n=Wh(e.n,e.nBitLength),i=e.toBytes||((y,g,w)=>{const m=g.toAffine();return qn(Uint8Array.from([4]),r.toBytes(m.x),r.toBytes(m.y))}),s=e.fromBytes||(y=>{const g=y.subarray(1),w=r.fromBytes(g.subarray(0,r.BYTES)),m=r.fromBytes(g.subarray(r.BYTES,2*r.BYTES));return{x:w,y:m}});function o(y){const{a:g,b:w}=e,m=r.sqr(y),b=r.mul(m,y);return r.add(r.add(b,r.mul(y,g)),w)}if(!r.eql(r.sqr(e.Gy),o(e.Gx)))throw new Error("bad generator point: equation left != right");function a(y){return Zi(y,xe,e.n)}function c(y){const{allowedPrivateKeyLengths:g,nByteLength:w,wrapPrivateKey:m,n:b}=e;if(g&&typeof y!="bigint"){if(Er(y)&&(y=nn(y)),typeof y!="string"||!g.includes(y.length))throw new Error("invalid private key");y=y.padStart(w*2,"0")}let E;try{E=typeof y=="bigint"?y:_r(tt("private key",y,w))}catch{throw new Error("invalid private key, expected hex or "+w+" bytes, got "+typeof y)}return m&&(E=Ye(E,b)),Ut("private key",E,xe,b),E}function u(y){if(!(y instanceof d))throw new Error("ProjectivePoint expected")}const l=Wo((y,g)=>{const{px:w,py:m,pz:b}=y;if(r.eql(b,r.ONE))return{x:w,y:m};const E=y.is0();g==null&&(g=E?r.ONE:r.inv(b));const $=r.mul(w,g),D=r.mul(m,g),S=r.mul(b,g);if(E)return{x:r.ZERO,y:r.ZERO};if(!r.eql(S,r.ONE))throw new Error("invZ was invalid");return{x:$,y:D}}),h=Wo(y=>{if(y.is0()){if(e.allowInfinityPoint&&!r.is0(y.py))return;throw new Error("bad point: ZERO")}const{x:g,y:w}=y.toAffine();if(!r.isValid(g)||!r.isValid(w))throw new Error("bad point: x or y not FE");const m=r.sqr(w),b=o(g);if(!r.eql(m,b))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class d{constructor(g,w,m){if(this.px=g,this.py=w,this.pz=m,g==null||!r.isValid(g))throw new Error("x required");if(w==null||!r.isValid(w))throw new Error("y required");if(m==null||!r.isValid(m))throw new Error("z required");Object.freeze(this)}static fromAffine(g){const{x:w,y:m}=g||{};if(!g||!r.isValid(w)||!r.isValid(m))throw new Error("invalid affine point");if(g instanceof d)throw new Error("projective point not allowed");const b=E=>r.eql(E,r.ZERO);return b(w)&&b(m)?d.ZERO:new d(w,m,r.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(g){const w=r.invertBatch(g.map(m=>m.pz));return g.map((m,b)=>m.toAffine(w[b])).map(d.fromAffine)}static fromHex(g){const w=d.fromAffine(s(tt("pointHex",g)));return w.assertValidity(),w}static fromPrivateKey(g){return d.BASE.multiply(c(g))}static msm(g,w){return d_(d,n,g,w)}_setWindowSize(g){f.setWindowSize(this,g)}assertValidity(){h(this)}hasEvenY(){const{y:g}=this.toAffine();if(r.isOdd)return!r.isOdd(g);throw new Error("Field doesn't support isOdd")}equals(g){u(g);const{px:w,py:m,pz:b}=this,{px:E,py:$,pz:D}=g,S=r.eql(r.mul(w,D),r.mul(E,b)),A=r.eql(r.mul(m,D),r.mul($,b));return S&&A}negate(){return new d(this.px,r.neg(this.py),this.pz)}double(){const{a:g,b:w}=e,m=r.mul(w,rd),{px:b,py:E,pz:$}=this;let D=r.ZERO,S=r.ZERO,A=r.ZERO,x=r.mul(b,b),k=r.mul(E,E),C=r.mul($,$),B=r.mul(b,E);return B=r.add(B,B),A=r.mul(b,$),A=r.add(A,A),D=r.mul(g,A),S=r.mul(m,C),S=r.add(D,S),D=r.sub(k,S),S=r.add(k,S),S=r.mul(D,S),D=r.mul(B,D),A=r.mul(m,A),C=r.mul(g,C),B=r.sub(x,C),B=r.mul(g,B),B=r.add(B,A),A=r.add(x,x),x=r.add(A,x),x=r.add(x,C),x=r.mul(x,B),S=r.add(S,x),C=r.mul(E,$),C=r.add(C,C),x=r.mul(C,B),D=r.sub(D,x),A=r.mul(C,k),A=r.add(A,A),A=r.add(A,A),new d(D,S,A)}add(g){u(g);const{px:w,py:m,pz:b}=this,{px:E,py:$,pz:D}=g;let S=r.ZERO,A=r.ZERO,x=r.ZERO;const k=e.a,C=r.mul(e.b,rd);let B=r.mul(w,E),j=r.mul(m,$),I=r.mul(b,D),_=r.add(w,m),v=r.add(E,$);_=r.mul(_,v),v=r.add(B,j),_=r.sub(_,v),v=r.add(w,b);let O=r.add(E,D);return v=r.mul(v,O),O=r.add(B,I),v=r.sub(v,O),O=r.add(m,b),S=r.add($,D),O=r.mul(O,S),S=r.add(j,I),O=r.sub(O,S),x=r.mul(k,v),S=r.mul(C,I),x=r.add(S,x),S=r.sub(j,x),x=r.add(j,x),A=r.mul(S,x),j=r.add(B,B),j=r.add(j,B),I=r.mul(k,I),v=r.mul(C,v),j=r.add(j,I),I=r.sub(B,I),I=r.mul(k,I),v=r.add(v,I),B=r.mul(j,v),A=r.add(A,B),B=r.mul(O,v),S=r.mul(_,S),S=r.sub(S,B),B=r.mul(_,j),x=r.mul(O,x),x=r.add(x,B),new d(S,A,x)}subtract(g){return this.add(g.negate())}is0(){return this.equals(d.ZERO)}wNAF(g){return f.wNAFCached(this,g,d.normalizeZ)}multiplyUnsafe(g){const{endo:w,n:m}=e;Ut("scalar",g,Mt,m);const b=d.ZERO;if(g===Mt)return b;if(this.is0()||g===xe)return this;if(!w||f.hasPrecomputes(this))return f.wNAFCachedUnsafe(this,g,d.normalizeZ);let{k1neg:E,k1:$,k2neg:D,k2:S}=w.splitScalar(g),A=b,x=b,k=this;for(;$>Mt||S>Mt;)$&xe&&(A=A.add(k)),S&xe&&(x=x.add(k)),k=k.double(),$>>=xe,S>>=xe;return E&&(A=A.negate()),D&&(x=x.negate()),x=new d(r.mul(x.px,w.beta),x.py,x.pz),A.add(x)}multiply(g){const{endo:w,n:m}=e;Ut("scalar",g,xe,m);let b,E;if(w){const{k1neg:$,k1:D,k2neg:S,k2:A}=w.splitScalar(g);let{p:x,f:k}=this.wNAF(D),{p:C,f:B}=this.wNAF(A);x=f.constTimeNegate($,x),C=f.constTimeNegate(S,C),C=new d(r.mul(C.px,w.beta),C.py,C.pz),b=x.add(C),E=k.add(B)}else{const{p:$,f:D}=this.wNAF(g);b=$,E=D}return d.normalizeZ([b,E])[0]}multiplyAndAddUnsafe(g,w,m){const b=d.BASE,E=(D,S)=>S===Mt||S===xe||!D.equals(b)?D.multiplyUnsafe(S):D.multiply(S),$=E(this,w).add(E(g,m));return $.is0()?void 0:$}toAffine(g){return l(this,g)}isTorsionFree(){const{h:g,isTorsionFree:w}=e;if(g===xe)return!0;if(w)return w(d,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:g,clearCofactor:w}=e;return g===xe?this:w?w(d,this):this.multiplyUnsafe(e.h)}toRawBytes(g=!0){return rn("isCompressed",g),this.assertValidity(),i(d,this,g)}toHex(g=!0){return rn("isCompressed",g),nn(this.toRawBytes(g))}}d.BASE=new d(e.Gx,e.Gy,r.ONE),d.ZERO=new d(r.ZERO,r.ONE,r.ZERO);const p=e.nBitLength,f=h_(d,e.endo?Math.ceil(p/2):p);return{CURVE:e,ProjectivePoint:d,normPrivateKeyToScalar:c,weierstrassEquation:o,isWithinCurveOrder:a}}function I_(t){const e=Qh(t);return cn(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function D_(t){const e=I_(t),{Fp:r,n}=e,i=r.BYTES+1,s=2*r.BYTES+1;function o(I){return Ye(I,n)}function a(I){return Yo(I,n)}const{ProjectivePoint:c,normPrivateKeyToScalar:u,weierstrassEquation:l,isWithinCurveOrder:h}=x_({...e,toBytes(I,_,v){const O=_.toAffine(),T=r.toBytes(O.x),P=qn;return rn("isCompressed",v),v?P(Uint8Array.from([_.hasEvenY()?2:3]),T):P(Uint8Array.from([4]),T,r.toBytes(O.y))},fromBytes(I){const _=I.length,v=I[0],O=I.subarray(1);if(_===i&&(v===2||v===3)){const T=_r(O);if(!Zi(T,xe,r.ORDER))throw new Error("Point is not on curve");const P=l(T);let N;try{N=r.sqrt(P)}catch(M){const z=M instanceof Error?": "+M.message:"";throw new Error("Point is not on curve"+z)}const F=(N&xe)===xe;return(v&1)===1!==F&&(N=r.neg(N)),{x:T,y:N}}else if(_===s&&v===4){const T=r.fromBytes(O.subarray(0,r.BYTES)),P=r.fromBytes(O.subarray(r.BYTES,2*r.BYTES));return{x:T,y:P}}else{const T=i,P=s;throw new Error("invalid Point, expected length of "+T+", or uncompressed "+P+", got "+_)}}}),d=I=>nn(an(I,e.nByteLength));function p(I){const _=n>>xe;return I>_}function f(I){return p(I)?o(-I):I}const y=(I,_,v)=>_r(I.slice(_,v));class g{constructor(_,v,O){this.r=_,this.s=v,this.recovery=O,this.assertValidity()}static fromCompact(_){const v=e.nByteLength;return _=tt("compactSignature",_,v*2),new g(y(_,0,v),y(_,v,2*v))}static fromDER(_){const{r:v,s:O}=kt.toSig(tt("DER",_));return new g(v,O)}assertValidity(){Ut("r",this.r,xe,n),Ut("s",this.s,xe,n)}addRecoveryBit(_){return new g(this.r,this.s,_)}recoverPublicKey(_){const{r:v,s:O,recovery:T}=this,P=D(tt("msgHash",_));if(T==null||![0,1,2,3].includes(T))throw new Error("recovery id invalid");const N=T===2||T===3?v+e.n:v;if(N>=r.ORDER)throw new Error("recovery id 2 or 3 invalid");const F=T&1?"03":"02",M=c.fromHex(F+d(N)),z=a(N),q=o(-P*z),V=o(O*z),K=c.BASE.multiplyAndAddUnsafe(M,q,V);if(!K)throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new g(this.r,o(-this.s),this.recovery):this}toDERRawBytes(){return on(this.toDERHex())}toDERHex(){return kt.hexFromSig({r:this.r,s:this.s})}toCompactRawBytes(){return on(this.toCompactHex())}toCompactHex(){return d(this.r)+d(this.s)}}const w={isValidPrivateKey(I){try{return u(I),!0}catch{return!1}},normPrivateKeyToScalar:u,randomPrivateKey:()=>{const I=Yh(e.n);return c_(e.randomBytes(I),e.n)},precompute(I=8,_=c.BASE){return _._setWindowSize(I),_.multiply(BigInt(3)),_}};function m(I,_=!0){return c.fromPrivateKey(I).toRawBytes(_)}function b(I){const _=Er(I),v=typeof I=="string",O=(_||v)&&I.length;return _?O===i||O===s:v?O===2*i||O===2*s:I instanceof c}function E(I,_,v=!0){if(b(I))throw new Error("first arg must be private key");if(!b(_))throw new Error("second arg must be public key");return c.fromHex(_).multiply(u(I)).toRawBytes(v)}const $=e.bits2int||function(I){if(I.length>8192)throw new Error("input is too large");const _=_r(I),v=I.length*8-e.nBitLength;return v>0?_>>BigInt(v):_},D=e.bits2int_modN||function(I){return o($(I))},S=Ko(e.nBitLength);function A(I){return Ut("num < 2^"+e.nBitLength,I,Mt,S),an(I,e.nByteLength)}function x(I,_,v=k){if(["recovered","canonical"].some(G=>G in v))throw new Error("sign() legacy options not supported");const{hash:O,randomBytes:T}=e;let{lowS:P,prehash:N,extraEntropy:F}=v;P==null&&(P=!0),I=tt("msgHash",I),td(v),N&&(I=tt("prehashed msgHash",O(I)));const M=D(I),z=u(_),q=[A(z),A(M)];if(F!=null&&F!==!1){const G=F===!0?T(r.BYTES):F;q.push(tt("extraEntropy",G))}const V=qn(...q),K=M;function ee(G){const W=$(G);if(!h(W))return;const ye=a(W),ue=c.BASE.multiply(W).toAffine(),le=o(ue.x);if(le===Mt)return;const $e=o(ye*o(K+le*z));if($e===Mt)return;let Me=(ue.x===le?0:2)|Number(ue.y&xe),Kt=$e;return P&&p($e)&&(Kt=f($e),Me^=1),new g(le,Kt,Me)}return{seed:V,k2sig:ee}}const k={lowS:e.lowS,prehash:!1},C={lowS:e.lowS,prehash:!1};function B(I,_,v=k){const{seed:O,k2sig:T}=x(I,_,v),P=e;return qh(P.hash.outputLen,P.nByteLength,P.hmac)(O,T)}c.BASE._setWindowSize(8);function j(I,_,v,O=C){const T=I;_=tt("msgHash",_),v=tt("publicKey",v);const{lowS:P,prehash:N,format:F}=O;if(td(O),"strict"in O)throw new Error("options.strict was renamed to lowS");if(F!==void 0&&F!=="compact"&&F!=="der")throw new Error("format must be compact or der");const M=typeof T=="string"||Er(T),z=!M&&!F&&typeof T=="object"&&T!==null&&typeof T.r=="bigint"&&typeof T.s=="bigint";if(!M&&!z)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let q,V;try{if(z&&(q=new g(T.r,T.s)),M){try{F!=="compact"&&(q=g.fromDER(T))}catch($e){if(!($e instanceof kt.Err))throw $e}!q&&F!=="der"&&(q=g.fromCompact(T))}V=c.fromHex(v)}catch{return!1}if(!q||P&&q.hasHighS())return!1;N&&(_=e.hash(_));const{r:K,s:ee}=q,G=D(_),W=a(ee),ye=o(G*W),ue=o(K*W),le=c.BASE.multiplyAndAddUnsafe(V,ye,ue)?.toAffine();return le?o(le.x)===K:!1}return{CURVE:e,getPublicKey:m,getSharedSecret:E,sign:B,verify:j,ProjectivePoint:c,Signature:g,utils:w}}function O_(t){return{hash:t,hmac:(e,...r)=>Hi(t,e,CE(...r)),randomBytes:en}}function $_(t,e){const r=n=>D_({...t,...O_(n)});return{...r(e),create:r}}const nd=Wh(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),A_=nd.create(BigInt("-3")),P_=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),T_=$_({a:A_,b:P_,Fp:nd,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},kn),id="base10",ze="base16",dt="base64pad",ar="base64url",zn="utf8",sd=0,jt=1,Vn=2,R_=0,od=1,Kn=12,na=32;function C_(){const t=ra.utils.randomPrivateKey(),e=ra.getPublicKey(t);return{privateKey:Ge(t,ze),publicKey:Ge(e,ze)}}function ia(){const t=en(na);return Ge(t,ze)}function N_(t,e){const r=ra.getSharedSecret(st(t,ze),st(e,ze)),n=U2(kn,r,void 0,void 0,na);return Ge(n,ze)}function Xi(t){const e=kn(st(t,ze));return Ge(e,ze)}function St(t){const e=kn(st(t,zn));return Ge(e,ze)}function ad(t){return st(`${t}`,id)}function xr(t){return Number(Ge(t,id))}function cd(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function ud(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),r=(4-e.length%4)%4;return e+"=".repeat(r)}function B_(t){const e=ad(typeof t.type<"u"?t.type:sd);if(xr(e)===jt&&typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const r=typeof t.senderPublicKey<"u"?st(t.senderPublicKey,ze):void 0,n=typeof t.iv<"u"?st(t.iv,ze):en(Kn),i=st(t.symKey,ze),s=Fh(i,n).encrypt(st(t.message,zn)),o=ld({type:e,sealed:s,iv:n,senderPublicKey:r});return t.encoding===ar?cd(o):o}function F_(t){const e=st(t.symKey,ze),{sealed:r,iv:n}=Hn({encoded:t.encoded,encoding:t.encoding}),i=Fh(e,n).decrypt(r);if(i===null)throw new Error("Failed to decrypt");return Ge(i,zn)}function L_(t,e){const r=ad(Vn),n=en(Kn),i=st(t,zn),s=ld({type:r,sealed:i,iv:n});return e===ar?cd(s):s}function U_(t,e){const{sealed:r}=Hn({encoded:t,encoding:e});return Ge(r,zn)}function ld(t){if(xr(t.type)===Vn)return Ge(Tn([t.type,t.sealed]),dt);if(xr(t.type)===jt){if(typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return Ge(Tn([t.type,t.senderPublicKey,t.iv,t.sealed]),dt)}return Ge(Tn([t.type,t.iv,t.sealed]),dt)}function Hn(t){const e=(t.encoding||dt)===ar?ud(t.encoded):t.encoded,r=st(e,dt),n=r.slice(R_,od),i=od;if(xr(n)===jt){const c=i+na,u=c+Kn,l=r.slice(i,c),h=r.slice(c,u),d=r.slice(u);return{type:n,sealed:d,iv:h,senderPublicKey:l}}if(xr(n)===Vn){const c=r.slice(i),u=en(Kn);return{type:n,sealed:c,iv:u}}const s=i+Kn,o=r.slice(i,s),a=r.slice(s);return{type:n,sealed:a,iv:o}}function k_(t,e){const r=Hn({encoded:t,encoding:e?.encoding});return hd({type:xr(r.type),senderPublicKey:typeof r.senderPublicKey<"u"?Ge(r.senderPublicKey,ze):void 0,receiverPublicKey:e?.receiverPublicKey})}function hd(t){const e=t?.type||sd;if(e===jt){if(typeof t?.senderPublicKey>"u")throw new Error("missing sender public key");if(typeof t?.receiverPublicKey>"u")throw new Error("missing receiver public key")}return{type:e,senderPublicKey:t?.senderPublicKey,receiverPublicKey:t?.receiverPublicKey}}function dd(t){return t.type===jt&&typeof t.senderPublicKey=="string"&&typeof t.receiverPublicKey=="string"}function fd(t){return t.type===Vn}function M_(t){const e=Buffer.from(t.x,"base64"),r=Buffer.from(t.y,"base64");return Tn([new Uint8Array([4]),e,r])}function j_(t,e){const[r,n,i]=t.split("."),s=Buffer.from(ud(i),"base64");if(s.length!==64)throw new Error("Invalid signature length");const o=s.slice(0,32),a=s.slice(32,64),c=`${r}.${n}`,u=kn(c),l=M_(e);if(!T_.verify(Tn([o,a]),u,l))throw new Error("Invalid signature");return Hs(t).payload}const q_="irn";function Qi(t){return t?.relay||{protocol:q_}}function Wn(t){const e=Yv[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}function z_(t,e="-"){const r={},n="relay"+e;return Object.keys(t).forEach(i=>{if(i.startsWith(n)){const s=i.replace(n,""),o=t[i];r[s]=o}}),r}function pd(t){if(!t.includes("wc:")){const u=ah(t);u!=null&&u.includes("wc:")&&(t=u)}t=t.includes("wc://")?t.replace("wc://",""):t,t=t.includes("wc:")?t.replace("wc:",""):t;const e=t.indexOf(":"),r=t.indexOf("?")!==-1?t.indexOf("?"):void 0,n=t.substring(0,e),i=t.substring(e+1,r).split("@"),s=typeof r<"u"?t.substring(r):"",o=new URLSearchParams(s),a={};o.forEach((u,l)=>{a[l]=u});const c=typeof a.methods=="string"?a.methods.split(","):void 0;return{protocol:n,topic:V_(i[0]),version:parseInt(i[1],10),symKey:a.symKey,relay:z_(a),methods:c,expiryTimestamp:a.expiryTimestamp?parseInt(a.expiryTimestamp,10):void 0}}function V_(t){return t.startsWith("//")?t.substring(2):t}function K_(t,e="-"){const r="relay",n={};return Object.keys(t).forEach(i=>{const s=i,o=r+e+s;t[s]&&(n[o]=t[s])}),n}function gd(t){const e=new URLSearchParams,r=K_(t.relay);Object.keys(r).sort().forEach(i=>{e.set(i,r[i])}),e.set("symKey",t.symKey),t.expiryTimestamp&&e.set("expiryTimestamp",t.expiryTimestamp.toString()),t.methods&&e.set("methods",t.methods.join(","));const n=e.toString();return`${t.protocol}:${t.topic}@${t.version}?${n}`}function es(t,e,r){return`${t}?wc_ev=${r}&topic=${e}`}function ln(t){const e=[];return t.forEach(r=>{const[n,i]=r.split(":");e.push(`${n}:${i}`)}),e}function H_(t){const e=[];return Object.values(t).forEach(r=>{e.push(...ln(r.accounts))}),e}function W_(t,e){const r=[];return Object.values(t).forEach(n=>{ln(n.accounts).includes(e)&&r.push(...n.methods)}),r}function G_(t,e){const r=[];return Object.values(t).forEach(n=>{ln(n.accounts).includes(e)&&r.push(...n.events)}),r}function Y_(t){const e={};return t?.forEach(r=>{var n;const[i,s]=r.split(":");e[i]||(e[i]={accounts:[],chains:[],events:[],methods:[]}),e[i].accounts.push(r),(n=e[i].chains)==null||n.push(`${i}:${s}`)}),e}function yd(t,e){e=e.map(n=>n.replace("did:pkh:",""));const r=Y_(e);for(const[n,i]of Object.entries(r))i.methods?i.methods=pE(i.methods,t):i.methods=t,i.events=["chainChanged","accountsChanged"];return r}const Z_={INVALID_METHOD:{message:"Invalid method.",code:1001},INVALID_EVENT:{message:"Invalid event.",code:1002},INVALID_UPDATE_REQUEST:{message:"Invalid update request.",code:1003},INVALID_EXTEND_REQUEST:{message:"Invalid extend request.",code:1004},INVALID_SESSION_SETTLE_REQUEST:{message:"Invalid session settle request.",code:1005},UNAUTHORIZED_METHOD:{message:"Unauthorized method.",code:3001},UNAUTHORIZED_EVENT:{message:"Unauthorized event.",code:3002},UNAUTHORIZED_UPDATE_REQUEST:{message:"Unauthorized update request.",code:3003},UNAUTHORIZED_EXTEND_REQUEST:{message:"Unauthorized extend request.",code:3004},USER_REJECTED:{message:"User rejected.",code:5e3},USER_REJECTED_CHAINS:{message:"User rejected chains.",code:5001},USER_REJECTED_METHODS:{message:"User rejected methods.",code:5002},USER_REJECTED_EVENTS:{message:"User rejected events.",code:5003},UNSUPPORTED_CHAINS:{message:"Unsupported chains.",code:5100},UNSUPPORTED_METHODS:{message:"Unsupported methods.",code:5101},UNSUPPORTED_EVENTS:{message:"Unsupported events.",code:5102},UNSUPPORTED_ACCOUNTS:{message:"Unsupported accounts.",code:5103},UNSUPPORTED_NAMESPACE_KEY:{message:"Unsupported namespace key.",code:5104},USER_DISCONNECTED:{message:"User disconnected.",code:6e3},SESSION_SETTLEMENT_FAILED:{message:"Session settlement failed.",code:7e3},WC_METHOD_UNSUPPORTED:{message:"Unsupported wc_ method.",code:10001}},J_={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 U(t,e){const{message:r,code:n}=J_[t];return{message:e?`${r} ${e}`:r,code:n}}function oe(t,e){const{message:r,code:n}=Z_[t];return{message:e?`${r} ${e}`:r,code:n}}function Gn(t,e){return Array.isArray(t)?typeof e<"u"&&t.length?t.every(e):!0:!1}function ts(t){return Object.getPrototypeOf(t)===Object.prototype&&Object.keys(t).length}function Re(t){return typeof t>"u"}function pe(t,e){return e&&Re(t)?!0:typeof t=="string"&&!!t.trim().length}function sa(t,e){return e&&Re(t)?!0:typeof t=="number"&&!isNaN(t)}function X_(t,e){const{requiredNamespaces:r}=e,n=Object.keys(t.namespaces),i=Object.keys(r);let s=!0;return mr(i,n)?(n.forEach(o=>{const{accounts:a,methods:c,events:u}=t.namespaces[o],l=ln(a),h=r[o];(!mr(Zl(o,h),l)||!mr(h.methods,c)||!mr(h.events,u))&&(s=!1)}),s):!1}function rs(t){return pe(t,!1)&&t.includes(":")?t.split(":").length===2:!1}function Q_(t){if(pe(t,!1)&&t.includes(":")){const e=t.split(":");if(e.length===3){const r=e[0]+":"+e[1];return!!e[2]&&rs(r)}}return!1}function eS(t){function e(r){try{return typeof new URL(r)<"u"}catch{return!1}}try{if(pe(t,!1)){if(e(t))return!0;const r=ah(t);return e(r)}}catch{}return!1}function tS(t){var e;return(e=t?.proposer)==null?void 0:e.publicKey}function rS(t){return t?.topic}function nS(t,e){let r=null;return pe(t?.publicKey,!1)||(r=U("MISSING_OR_INVALID",`${e} controller public key should be a string`)),r}function wd(t){let e=!0;return Gn(t)?t.length&&(e=t.every(r=>pe(r,!1))):e=!1,e}function iS(t,e,r){let n=null;return Gn(e)&&e.length?e.forEach(i=>{n||rs(i)||(n=oe("UNSUPPORTED_CHAINS",`${r}, chain ${i} should be a string and conform to "namespace:chainId" format`))}):rs(t)||(n=oe("UNSUPPORTED_CHAINS",`${r}, chains must be defined as "namespace:chainId" e.g. "eip155:1": {...} in the namespace key OR as an array of CAIP-2 chainIds e.g. eip155: { chains: ["eip155:1", "eip155:5"] }`)),n}function sS(t,e,r){let n=null;return Object.entries(t).forEach(([i,s])=>{if(n)return;const o=iS(i,Zl(i,s),`${e} ${r}`);o&&(n=o)}),n}function oS(t,e){let r=null;return Gn(t)?t.forEach(n=>{r||Q_(n)||(r=oe("UNSUPPORTED_ACCOUNTS",`${e}, account ${n} should be a string and conform to "namespace:chainId:address" format`))}):r=oe("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),r}function aS(t,e){let r=null;return Object.values(t).forEach(n=>{if(r)return;const i=oS(n?.accounts,`${e} namespace`);i&&(r=i)}),r}function cS(t,e){let r=null;return wd(t?.methods)?wd(t?.events)||(r=oe("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):r=oe("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),r}function md(t,e){let r=null;return Object.values(t).forEach(n=>{if(r)return;const i=cS(n,`${e}, namespace`);i&&(r=i)}),r}function uS(t,e,r){let n=null;if(t&&ts(t)){const i=md(t,e);i&&(n=i);const s=sS(t,e,r);s&&(n=s)}else n=U("MISSING_OR_INVALID",`${e}, ${r} should be an object with data`);return n}function oa(t,e){let r=null;if(t&&ts(t)){const n=md(t,e);n&&(r=n);const i=aS(t,e);i&&(r=i)}else r=U("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return r}function bd(t){return pe(t.protocol,!0)}function lS(t,e){let r=!1;return e&&!t?r=!0:t&&Gn(t)&&t.length&&t.forEach(n=>{r=bd(n)}),r}function hS(t){return typeof t=="number"}function Ze(t){return typeof t<"u"&&typeof t!==null}function dS(t){return!(!t||typeof t!="object"||!t.code||!sa(t.code,!1)||!t.message||!pe(t.message,!1))}function fS(t){return!(Re(t)||!pe(t.method,!1))}function pS(t){return!(Re(t)||Re(t.result)&&Re(t.error)||!sa(t.id,!1)||!pe(t.jsonrpc,!1))}function gS(t){return!(Re(t)||!pe(t.name,!1))}function vd(t,e){return!(!rs(e)||!H_(t).includes(e))}function yS(t,e,r){return pe(r,!1)?W_(t,e).includes(r):!1}function wS(t,e,r){return pe(r,!1)?G_(t,e).includes(r):!1}function Ed(t,e,r){let n=null;const i=mS(t),s=bS(e),o=Object.keys(i),a=Object.keys(s),c=_d(Object.keys(t)),u=_d(Object.keys(e)),l=c.filter(h=>!u.includes(h));return l.length&&(n=U("NON_CONFORMING_NAMESPACES",`${r} namespaces keys don't satisfy requiredNamespaces.
21
+ Required: ${l.toString()}
22
+ Received: ${Object.keys(e).toString()}`)),mr(o,a)||(n=U("NON_CONFORMING_NAMESPACES",`${r} namespaces chains don't satisfy required namespaces.
23
23
  Required: ${o.toString()}
24
- Approved: ${a.toString()}`)),Object.keys(e).forEach(d=>{if(!d.includes(":")||i)return;const b=wn(e[d].accounts);b.includes(d)||(i=U("NON_CONFORMING_NAMESPACES",`${r} namespaces accounts don't satisfy namespace accounts for ${d}
25
- Required: ${d}
26
- Approved: ${b.toString()}`))}),o.forEach(d=>{i||(Ii(n[d].methods,s[d].methods)?Ii(n[d].events,s[d].events)||(i=U("NON_CONFORMING_NAMESPACES",`${r} namespaces events don't satisfy namespace events for ${d}`)):i=U("NON_CONFORMING_NAMESPACES",`${r} namespaces methods don't satisfy namespace methods for ${d}`))}),i}function M7(t){const e={};return Object.keys(t).forEach(r=>{var i;r.includes(":")?e[r]=t[r]:(i=t[r].chains)==null||i.forEach(n=>{e[n]={methods:t[r].methods,events:t[r].events}})}),e}function K0(t){return[...new Set(t.map(e=>e.includes(":")?e.split(":")[0]:e))]}function P7(t){const e={};return Object.keys(t).forEach(r=>{r.includes(":")?e[r]=t[r]:wn(t[r].accounts)?.forEach(n=>{e[n]={accounts:t[r].accounts.filter(s=>s.includes(`${n}:`)),methods:t[r].methods,events:t[r].events}})}),e}function R7(t,e){return Uc(t,!1)&&t<=e.max&&t>=e.min}function H0(){const t=Wn();return new Promise(e=>{switch(t){case Lt.browser:e(T7());break;case Lt.reactNative:e(N7());break;case Lt.node:e(C7());break;default:e(!0)}})}function T7(){return Hn()&&navigator?.onLine}async function N7(){return ri()&&typeof global<"u"&&global!=null&&global.NetInfo?(await(global==null?void 0:global.NetInfo.fetch()))?.isConnected:!0}function C7(){return!0}function B7(t){switch(Wn()){case Lt.browser:F7(t);break;case Lt.reactNative:L7(t);break}}function F7(t){!ri()&&Hn()&&(window.addEventListener("online",()=>t(!0)),window.addEventListener("offline",()=>t(!1)))}function L7(t){ri()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(e=>t(e?.isConnected))}const Vc={};class ss{static get(e){return Vc[e]}static set(e,r){Vc[e]=r}static delete(e){delete Vc[e]}}const q7="PARSE_ERROR",k7="INVALID_REQUEST",z7="METHOD_NOT_FOUND",U7="INVALID_PARAMS",W0="INTERNAL_ERROR",Kc="SERVER_ERROR",j7=[-32700,-32600,-32601,-32602,-32603],os={[q7]:{code:-32700,message:"Parse error"},[k7]:{code:-32600,message:"Invalid Request"},[z7]:{code:-32601,message:"Method not found"},[U7]:{code:-32602,message:"Invalid params"},[W0]:{code:-32603,message:"Internal error"},[Kc]:{code:-32e3,message:"Server error"}},G0=Kc;function V7(t){return j7.includes(t)}function Y0(t){return Object.keys(os).includes(t)?os[t]:os[G0]}function K7(t){const e=Object.values(os).find(r=>r.code===t);return e||os[G0]}function H7(t,e,r){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable ${r} RPC url at ${e}`):t}var Z0={};/*! *****************************************************************************
24
+ Approved: ${a.toString()}`)),Object.keys(e).forEach(h=>{if(!h.includes(":")||n)return;const d=ln(e[h].accounts);d.includes(h)||(n=U("NON_CONFORMING_NAMESPACES",`${r} namespaces accounts don't satisfy namespace accounts for ${h}
25
+ Required: ${h}
26
+ Approved: ${d.toString()}`))}),o.forEach(h=>{n||(mr(i[h].methods,s[h].methods)?mr(i[h].events,s[h].events)||(n=U("NON_CONFORMING_NAMESPACES",`${r} namespaces events don't satisfy namespace events for ${h}`)):n=U("NON_CONFORMING_NAMESPACES",`${r} namespaces methods don't satisfy namespace methods for ${h}`))}),n}function mS(t){const e={};return Object.keys(t).forEach(r=>{var n;r.includes(":")?e[r]=t[r]:(n=t[r].chains)==null||n.forEach(i=>{e[i]={methods:t[r].methods,events:t[r].events}})}),e}function _d(t){return[...new Set(t.map(e=>e.includes(":")?e.split(":")[0]:e))]}function bS(t){const e={};return Object.keys(t).forEach(r=>{r.includes(":")?e[r]=t[r]:ln(t[r].accounts)?.forEach(i=>{e[i]={accounts:t[r].accounts.filter(s=>s.includes(`${i}:`)),methods:t[r].methods,events:t[r].events}})}),e}function vS(t,e){return sa(t,!1)&&t<=e.max&&t>=e.min}function Sd(){const t=Nn();return new Promise(e=>{switch(t){case Qe.browser:e(ES());break;case Qe.reactNative:e(_S());break;case Qe.node:e(SS());break;default:e(!0)}})}function ES(){return Cn()&&navigator?.onLine}async function _S(){return tr()&&typeof global<"u"&&global!=null&&global.NetInfo?(await(global==null?void 0:global.NetInfo.fetch()))?.isConnected:!0}function SS(){return!0}function xS(t){switch(Nn()){case Qe.browser:IS(t);break;case Qe.reactNative:DS(t);break}}function IS(t){!tr()&&Cn()&&(window.addEventListener("online",()=>t(!0)),window.addEventListener("offline",()=>t(!1)))}function DS(t){tr()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(e=>t(e?.isConnected))}const aa={};class Yn{static get(e){return aa[e]}static set(e,r){aa[e]=r}static delete(e){delete aa[e]}}const OS="PARSE_ERROR",$S="INVALID_REQUEST",AS="METHOD_NOT_FOUND",PS="INVALID_PARAMS",xd="INTERNAL_ERROR",ca="SERVER_ERROR",TS=[-32700,-32600,-32601,-32602,-32603],Zn={[OS]:{code:-32700,message:"Parse error"},[$S]:{code:-32600,message:"Invalid Request"},[AS]:{code:-32601,message:"Method not found"},[PS]:{code:-32602,message:"Invalid params"},[xd]:{code:-32603,message:"Internal error"},[ca]:{code:-32e3,message:"Server error"}},Id=ca;function RS(t){return TS.includes(t)}function Dd(t){return Object.keys(Zn).includes(t)?Zn[t]:Zn[Id]}function CS(t){const e=Object.values(Zn).find(r=>r.code===t);return e||Zn[Id]}function NS(t,e,r){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable ${r} RPC url at ${e}`):t}var Od={};/*! *****************************************************************************
27
27
  Copyright (c) Microsoft Corporation.
28
28
 
29
29
  Permission to use, copy, modify, and/or distribute this software for any
@@ -36,5 +36,5 @@ ${t.length}`,r=new TextEncoder().encode(e+t);return"0x"+Buffer.from(S5(r)).toStr
36
36
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
37
37
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
38
38
  PERFORMANCE OF THIS SOFTWARE.
39
- ***************************************************************************** */var Hc=function(t,e){return Hc=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,i){r.__proto__=i}||function(r,i){for(var n in i)i.hasOwnProperty(n)&&(r[n]=i[n])},Hc(t,e)};function W7(t,e){Hc(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}var Wc=function(){return Wc=Object.assign||function(e){for(var r,i=1,n=arguments.length;i<n;i++){r=arguments[i];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},Wc.apply(this,arguments)};function G7(t,e){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&e.indexOf(i)<0&&(r[i]=t[i]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(t);n<i.length;n++)e.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(t,i[n])&&(r[i[n]]=t[i[n]]);return r}function Y7(t,e,r,i){var n=arguments.length,s=n<3?e:i===null?i=Object.getOwnPropertyDescriptor(e,r):i,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,r,i);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(n<3?o(s):n>3?o(e,r,s):o(e,r))||s);return n>3&&s&&Object.defineProperty(e,r,s),s}function Z7(t,e){return function(r,i){e(r,i,t)}}function J7(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function X7(t,e,r,i){function n(s){return s instanceof r?s:new r(function(o){o(s)})}return new(r||(r=Promise))(function(s,o){function a(u){try{f(i.next(u))}catch(d){o(d)}}function c(u){try{f(i.throw(u))}catch(d){o(d)}}function f(u){u.done?s(u.value):n(u.value).then(a,c)}f((i=i.apply(t,e||[])).next())})}function Q7(t,e){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},i,n,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(f){return function(u){return c([f,u])}}function c(f){if(i)throw new TypeError("Generator is already executing.");for(;r;)try{if(i=1,n&&(s=f[0]&2?n.return:f[0]?n.throw||((s=n.return)&&s.call(n),0):n.next)&&!(s=s.call(n,f[1])).done)return s;switch(n=0,s&&(f=[f[0]&2,s.value]),f[0]){case 0:case 1:s=f;break;case 4:return r.label++,{value:f[1],done:!1};case 5:r.label++,n=f[1],f=[0];continue;case 7:f=r.ops.pop(),r.trys.pop();continue;default:if(s=r.trys,!(s=s.length>0&&s[s.length-1])&&(f[0]===6||f[0]===2)){r=0;continue}if(f[0]===3&&(!s||f[1]>s[0]&&f[1]<s[3])){r.label=f[1];break}if(f[0]===6&&r.label<s[1]){r.label=s[1],s=f;break}if(s&&r.label<s[2]){r.label=s[2],r.ops.push(f);break}s[2]&&r.ops.pop(),r.trys.pop();continue}f=e.call(t,r)}catch(u){f=[6,u],n=0}finally{i=s=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}function e_(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}function t_(t,e){for(var r in t)r!=="default"&&!e.hasOwnProperty(r)&&(e[r]=t[r])}function Gc(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],i=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&i>=t.length&&(t=void 0),{value:t&&t[i++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function J0(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var i=r.call(t),n,s=[],o;try{for(;(e===void 0||e-- >0)&&!(n=i.next()).done;)s.push(n.value)}catch(a){o={error:a}}finally{try{n&&!n.done&&(r=i.return)&&r.call(i)}finally{if(o)throw o.error}}return s}function r_(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(J0(arguments[e]));return t}function i_(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var i=Array(t),n=0,e=0;e<r;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,n++)i[n]=s[o];return i}function as(t){return this instanceof as?(this.v=t,this):new as(t)}function n_(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var i=r.apply(t,e||[]),n,s=[];return n={},o("next"),o("throw"),o("return"),n[Symbol.asyncIterator]=function(){return this},n;function o(b){i[b]&&(n[b]=function(v){return new Promise(function(g,x){s.push([b,v,g,x])>1||a(b,v)})})}function a(b,v){try{c(i[b](v))}catch(g){d(s[0][3],g)}}function c(b){b.value instanceof as?Promise.resolve(b.value.v).then(f,u):d(s[0][2],b)}function f(b){a("next",b)}function u(b){a("throw",b)}function d(b,v){b(v),s.shift(),s.length&&a(s[0][0],s[0][1])}}function s_(t){var e,r;return e={},i("next"),i("throw",function(n){throw n}),i("return"),e[Symbol.iterator]=function(){return this},e;function i(n,s){e[n]=t[n]?function(o){return(r=!r)?{value:as(t[n](o)),done:n==="return"}:s?s(o):o}:s}}function o_(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof Gc=="function"?Gc(t):t[Symbol.iterator](),r={},i("next"),i("throw"),i("return"),r[Symbol.asyncIterator]=function(){return this},r);function i(s){r[s]=t[s]&&function(o){return new Promise(function(a,c){o=t[s](o),n(a,c,o.done,o.value)})}}function n(s,o,a,c){Promise.resolve(c).then(function(f){s({value:f,done:a})},o)}}function a_(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function c_(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function f_(t){return t&&t.__esModule?t:{default:t}}function u_(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function h_(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}var d_=Object.freeze({__proto__:null,__extends:W7,get __assign(){return Wc},__rest:G7,__decorate:Y7,__param:Z7,__metadata:J7,__awaiter:X7,__generator:Q7,__createBinding:e_,__exportStar:t_,__values:Gc,__read:J0,__spread:r_,__spreadArrays:i_,__await:as,__asyncGenerator:n_,__asyncDelegator:s_,__asyncValues:o_,__makeTemplateObject:a_,__importStar:c_,__importDefault:f_,__classPrivateFieldGet:u_,__classPrivateFieldSet:h_}),l_=Lo(d_),kr={},X0;function p_(){if(X0)return kr;X0=1,Object.defineProperty(kr,"__esModule",{value:!0}),kr.isBrowserCryptoAvailable=kr.getSubtleCrypto=kr.getBrowerCrypto=void 0;function t(){return Zt?.crypto||Zt?.msCrypto||{}}kr.getBrowerCrypto=t;function e(){const i=t();return i.subtle||i.webkitSubtle}kr.getSubtleCrypto=e;function r(){return!!t()&&!!e()}return kr.isBrowserCryptoAvailable=r,kr}var zr={},Q0;function b_(){if(Q0)return zr;Q0=1,Object.defineProperty(zr,"__esModule",{value:!0}),zr.isBrowser=zr.isNode=zr.isReactNative=void 0;function t(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}zr.isReactNative=t;function e(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}zr.isNode=e;function r(){return!t()&&!e()}return zr.isBrowser=r,zr}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=l_;e.__exportStar(p_(),t),e.__exportStar(b_(),t)})(Z0);function xr(t=3){const e=Date.now()*Math.pow(10,t),r=Math.floor(Math.random()*Math.pow(10,t));return e+r}function Oi(t=6){return BigInt(xr(t))}function Mi(t,e,r){return{id:r||xr(),jsonrpc:"2.0",method:t,params:e}}function Yc(t,e){return{id:t,jsonrpc:"2.0",result:e}}function Zc(t,e,r){return{id:t,jsonrpc:"2.0",error:g_(e,r)}}function g_(t,e){return typeof t>"u"?Y0(W0):(typeof t=="string"&&(t=Object.assign(Object.assign({},Y0(Kc)),{message:t})),typeof e<"u"&&(t.data=e),V7(t.code)&&(t=K7(t.code)),t)}class y_{}class v_ extends y_{constructor(){super()}}class m_ extends v_{constructor(e){super()}}const w_="^wss?:";function __(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function x_(t,e){const r=__(t);return typeof r>"u"?!1:new RegExp(e).test(r)}function ep(t){return x_(t,w_)}function E_(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function tp(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function Jc(t){return tp(t)&&"method"in t}function Oo(t){return tp(t)&&(Er(t)||Wt(t))}function Er(t){return"result"in t}function Wt(t){return"error"in t}class S_ extends m_{constructor(e){super(e),this.events=new mt.exports.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,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async request(e,r){return this.requestStrict(Mi(e.method,e.params||[],e.id||Oi().toString()),r)}async requestStrict(e,r){return new Promise(async(i,n)=>{if(!this.connection.connected)try{await this.open()}catch(s){n(s)}this.events.on(`${e.id}`,s=>{Wt(s)?n(s.error):i(s.result)});try{await this.connection.send(e,r)}catch(s){n(s)}})}setConnection(e=this.connection){return e}onPayload(e){this.events.emit("payload",e),Oo(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 I_=()=>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"),A_=()=>typeof WebSocket<"u"||typeof global<"u"&&typeof global.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",rp=t=>t.split("?")[0],ip=10,$_=I_();class D_{constructor(e){if(this.url=e,this.events=new mt.exports.EventEmitter,this.registering=!1,!ep(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,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async open(e=this.url){await this.register(e)}async close(){return new Promise((e,r)=>{if(typeof this.socket>"u"){r(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(li(e))}catch(r){this.onError(e.id,r)}}register(e=this.url){if(!ep(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);if(this.registering){const r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((i,n)=>{this.events.once("register_error",s=>{this.resetMaxListeners(),n(s)}),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((r,i)=>{const n=Z0.isReactNative()?void 0:{rejectUnauthorized:!E_(e)},s=new $_(e,[],n);A_()?s.onerror=o=>{const a=o;i(this.emitError(a.error))}:s.on("error",o=>{i(this.emitError(o))}),s.onopen=()=>{this.onOpen(s),r(s)}})}onOpen(e){e.onmessage=r=>this.onPayload(r),e.onclose=r=>this.onClose(r),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 r=typeof e.data=="string"?Li(e.data):e.data;this.events.emit("payload",r)}onError(e,r){const i=this.parseError(r),n=i.message||i.toString(),s=Zc(e,n);this.events.emit("payload",s)}parseError(e,r=this.url){return H7(e,rp(r),"WS")}resetMaxListeners(){this.events.getMaxListeners()>ip&&this.events.setMaxListeners(ip)}emitError(e){const r=this.parseError(new Error(e?.message||`WebSocket connection failed for host: ${rp(this.url)}`));return this.events.emit("register_error",r),r}}const np="wc",sp=2,Mo="core",Sr=`${np}@2:${Mo}:`,O_={name:Mo,logger:"error"},M_={database:":memory:"},P_="crypto",op="client_ed25519_seed",R_=z.ONE_DAY,T_="keychain",N_="0.3",C_="messages",B_="0.3",ap=z.SIX_HOURS,F_="publisher",cp="irn",L_="error",fp="wss://relay.walletconnect.org",q_="relayer",at={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"},k_="_subscription",Gt={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},z_=.1,Xc="2.19.1",pe={link_mode:"link_mode",relay:"relay"},Po={inbound:"inbound",outbound:"outbound"},U_="0.3",j_="WALLETCONNECT_CLIENT_ID",up="WALLETCONNECT_LINK_MODE_APPS",kt={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},V_="subscription",K_="0.3",H_="pairing",W_="0.3",cs={wc_pairingDelete:{req:{ttl:z.ONE_DAY,prompt:!1,tag:1e3},res:{ttl:z.ONE_DAY,prompt:!1,tag:1001}},wc_pairingPing:{req:{ttl:z.THIRTY_SECONDS,prompt:!1,tag:1002},res:{ttl:z.THIRTY_SECONDS,prompt:!1,tag:1003}},unregistered_method:{req:{ttl:z.ONE_DAY,prompt:!1,tag:0},res:{ttl:z.ONE_DAY,prompt:!1,tag:0}}},Pi={create:"pairing_create",expire:"pairing_expire",delete:"pairing_delete",ping:"pairing_ping"},ir={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},G_="history",Y_="0.3",Z_="expirer",Yt={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},J_="0.3",X_="verify-api",Q_="https://verify.walletconnect.com",hp="https://verify.walletconnect.org",fs=hp,ex=`${fs}/v3`,tx=[Q_,hp],rx="echo",ix="https://echo.walletconnect.com",Ir={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"},Ur={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"},nr={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"},Ri={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"},Ti={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"},us={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"},nx=.1,sx="event-client",ox=86400,ax="https://pulse.walletconnect.org/batch";function cx(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),i=0;i<r.length;i++)r[i]=255;for(var n=0;n<t.length;n++){var s=t.charAt(n),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=n}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(g){if(g instanceof Uint8Array||(ArrayBuffer.isView(g)?g=new Uint8Array(g.buffer,g.byteOffset,g.byteLength):Array.isArray(g)&&(g=Uint8Array.from(g))),!(g instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(g.length===0)return"";for(var x=0,I=0,D=0,O=g.length;D!==O&&g[D]===0;)D++,x++;for(var M=(O-D)*u+1>>>0,P=new Uint8Array(M);D!==O;){for(var T=g[D],N=0,C=M-1;(T!==0||N<I)&&C!==-1;C--,N++)T+=256*P[C]>>>0,P[C]=T%a>>>0,T=T/a>>>0;if(T!==0)throw new Error("Non-zero carry");I=N,D++}for(var B=M-I;B!==M&&P[B]===0;)B++;for(var R=c.repeat(x);B<M;++B)R+=t.charAt(P[B]);return R}function b(g){if(typeof g!="string")throw new TypeError("Expected String");if(g.length===0)return new Uint8Array;var x=0;if(g[x]!==" "){for(var I=0,D=0;g[x]===c;)I++,x++;for(var O=(g.length-x)*f+1>>>0,M=new Uint8Array(O);g[x];){var P=r[g.charCodeAt(x)];if(P===255)return;for(var T=0,N=O-1;(P!==0||T<D)&&N!==-1;N--,T++)P+=a*M[N]>>>0,M[N]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");D=T,x++}if(g[x]!==" "){for(var C=O-D;C!==O&&M[C]===0;)C++;for(var B=new Uint8Array(I+(O-C)),R=I;C!==O;)B[R++]=M[C++];return B}}}function v(g){var x=b(g);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:d,decodeUnsafe:b,decode:v}}var fx=cx,ux=fx;const dp=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},hx=t=>new TextEncoder().encode(t),dx=t=>new TextDecoder().decode(t);class lx{constructor(e,r,i){this.name=e,this.prefix=r,this.baseEncode=i}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class px{constructor(e,r,i){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.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 lp(this,e)}}class bx{constructor(e){this.decoders=e}or(e){return lp(this,e)}decode(e){const r=e[0],i=this.decoders[r];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 lp=(t,e)=>new bx({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class gx{constructor(e,r,i,n){this.name=e,this.prefix=r,this.baseEncode=i,this.baseDecode=n,this.encoder=new lx(e,r,i),this.decoder=new px(e,r,n)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Ro=({name:t,prefix:e,encode:r,decode:i})=>new gx(t,e,r,i),hs=({prefix:t,name:e,alphabet:r})=>{const{encode:i,decode:n}=ux(r,e);return Ro({prefix:t,name:e,encode:i,decode:s=>dp(n(s))})},yx=(t,e,r,i)=>{const n={};for(let u=0;u<e.length;++u)n[e[u]]=u;let s=t.length;for(;t[s-1]==="=";)--s;const o=new Uint8Array(s*r/8|0);let a=0,c=0,f=0;for(let u=0;u<s;++u){const d=n[t[u]];if(d===void 0)throw new SyntaxError(`Non-${i} character`);c=c<<r|d,a+=r,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},vx=(t,e,r)=>{const i=e[e.length-1]==="=",n=(1<<r)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[n&a>>o];if(o&&(s+=e[n&a<<r-o]),i)for(;s.length*r&7;)s+="=";return s},bt=({name:t,prefix:e,bitsPerChar:r,alphabet:i})=>Ro({prefix:e,name:t,encode(n){return vx(n,i,r)},decode(n){return yx(n,i,r,t)}}),mx=Ro({prefix:"\0",name:"identity",encode:t=>dx(t),decode:t=>hx(t)});var wx=Object.freeze({__proto__:null,identity:mx});const _x=bt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var xx=Object.freeze({__proto__:null,base2:_x});const Ex=bt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Sx=Object.freeze({__proto__:null,base8:Ex});const Ix=hs({prefix:"9",name:"base10",alphabet:"0123456789"});var Ax=Object.freeze({__proto__:null,base10:Ix});const $x=bt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dx=bt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Ox=Object.freeze({__proto__:null,base16:$x,base16upper:Dx});const Mx=bt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Px=bt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Rx=bt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Tx=bt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Nx=bt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Cx=bt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Bx=bt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Fx=bt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Lx=bt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var qx=Object.freeze({__proto__:null,base32:Mx,base32upper:Px,base32pad:Rx,base32padupper:Tx,base32hex:Nx,base32hexupper:Cx,base32hexpad:Bx,base32hexpadupper:Fx,base32z:Lx});const kx=hs({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),zx=hs({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ux=Object.freeze({__proto__:null,base36:kx,base36upper:zx});const jx=hs({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Vx=hs({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Kx=Object.freeze({__proto__:null,base58btc:jx,base58flickr:Vx});const Hx=bt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Wx=bt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gx=bt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Yx=bt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Zx=Object.freeze({__proto__:null,base64:Hx,base64pad:Wx,base64url:Gx,base64urlpad:Yx});const pp=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Jx=pp.reduce((t,e,r)=>(t[r]=e,t),[]),Xx=pp.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function Qx(t){return t.reduce((e,r)=>(e+=Jx[r],e),"")}function eE(t){const e=[];for(const r of t){const i=Xx[r.codePointAt(0)];if(i===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}const tE=Ro({prefix:"\u{1F680}",name:"base256emoji",encode:Qx,decode:eE});var rE=Object.freeze({__proto__:null,base256emoji:tE}),iE=gp,bp=128,nE=127,sE=~nE,oE=Math.pow(2,31);function gp(t,e,r){e=e||[],r=r||0;for(var i=r;t>=oE;)e[r++]=t&255|bp,t/=128;for(;t&sE;)e[r++]=t&255|bp,t>>>=7;return e[r]=t|0,gp.bytes=r-i+1,e}var aE=Qc,cE=128,yp=127;function Qc(t,i){var r=0,i=i||0,n=0,s=i,o,a=t.length;do{if(s>=a)throw Qc.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=n<28?(o&yp)<<n:(o&yp)*Math.pow(2,n),n+=7}while(o>=cE);return Qc.bytes=s-i,r}var fE=Math.pow(2,7),uE=Math.pow(2,14),hE=Math.pow(2,21),dE=Math.pow(2,28),lE=Math.pow(2,35),pE=Math.pow(2,42),bE=Math.pow(2,49),gE=Math.pow(2,56),yE=Math.pow(2,63),vE=function(t){return t<fE?1:t<uE?2:t<hE?3:t<dE?4:t<lE?5:t<pE?6:t<bE?7:t<gE?8:t<yE?9:10},mE={encode:iE,decode:aE,encodingLength:vE},vp=mE;const mp=(t,e,r=0)=>(vp.encode(t,e,r),e),wp=t=>vp.encodingLength(t),ef=(t,e)=>{const r=e.byteLength,i=wp(t),n=i+wp(r),s=new Uint8Array(n+r);return mp(t,s,0),mp(r,s,i),s.set(e,n),new wE(t,r,e,s)};class wE{constructor(e,r,i,n){this.code=e,this.size=r,this.digest=i,this.bytes=n}}const _p=({name:t,code:e,encode:r})=>new _E(t,e,r);class _E{constructor(e,r,i){this.name=e,this.code=r,this.encode=i}digest(e){if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?ef(this.code,r):r.then(i=>ef(this.code,i))}else throw Error("Unknown type, must be binary type")}}const xp=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),xE=_p({name:"sha2-256",code:18,encode:xp("SHA-256")}),EE=_p({name:"sha2-512",code:19,encode:xp("SHA-512")});var SE=Object.freeze({__proto__:null,sha256:xE,sha512:EE});const Ep=0,IE="identity",Sp=dp;var AE=Object.freeze({__proto__:null,identity:{code:Ep,name:IE,encode:Sp,digest:t=>ef(Ep,Sp(t))}});new TextEncoder,new TextDecoder;const Ip={...wx,...xx,...Sx,...Ax,...Ox,...qx,...Ux,...Kx,...Zx,...rE};({...SE,...AE});function $E(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}function Ap(t,e,r,i){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:i}}}const $p=Ap("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),tf=Ap("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);const e=$E(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),DE={utf8:$p,"utf-8":$p,hex:Ip.base16,latin1:tf,ascii:tf,binary:tf,...Ip};function OE(t,e="utf8"){const r=DE[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t,"utf8"):r.decoder.decode(`${r.prefix}${t}`)}var ME=Object.defineProperty,PE=(t,e,r)=>e in t?ME(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ar=(t,e,r)=>PE(t,typeof e!="symbol"?e+"":e,r);class RE{constructor(e,r){this.core=e,this.logger=r,Ar(this,"keychain",new Map),Ar(this,"name",T_),Ar(this,"version",N_),Ar(this,"initialized",!1),Ar(this,"storagePrefix",Sr),Ar(this,"init",async()=>{if(!this.initialized){const i=await this.getKeyChain();typeof i<"u"&&(this.keychain=i),this.initialized=!0}}),Ar(this,"has",i=>(this.isInitialized(),this.keychain.has(i))),Ar(this,"set",async(i,n)=>{this.isInitialized(),this.keychain.set(i,n),await this.persist()}),Ar(this,"get",i=>{this.isInitialized();const n=this.keychain.get(i);if(typeof n>"u"){const{message:s}=U("NO_MATCHING_KEY",`${this.name}: ${i}`);throw new Error(s)}return n}),Ar(this,"del",async i=>{this.isInitialized(),this.keychain.delete(i),await this.persist()}),this.core=e,this.logger=It(r,this.name)}get context(){return Mt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,wc(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?_c(e):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var TE=Object.defineProperty,NE=(t,e,r)=>e in t?TE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,gt=(t,e,r)=>NE(t,typeof e!="symbol"?e+"":e,r);class CE{constructor(e,r,i){this.core=e,this.logger=r,gt(this,"name",P_),gt(this,"keychain"),gt(this,"randomSessionIdentifier",zc()),gt(this,"initialized",!1),gt(this,"init",async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)}),gt(this,"hasKeys",n=>(this.isInitialized(),this.keychain.has(n))),gt(this,"getClientId",async()=>{this.isInitialized();const n=await this.getClientSeed(),s=vh(n);return yh(s.publicKey)}),gt(this,"generateKeyPair",()=>{this.isInitialized();const n=j9();return this.setPrivateKey(n.publicKey,n.privateKey)}),gt(this,"signJWT",async n=>{this.isInitialized();const s=await this.getClientSeed(),o=vh(s),a=this.randomSessionIdentifier;return await hv(a,n,R_,o)}),gt(this,"generateSharedKey",(n,s,o)=>{this.isInitialized();const a=this.getPrivateKey(n),c=V9(a,s);return this.setSymKey(c,o)}),gt(this,"setSymKey",async(n,s)=>{this.isInitialized();const o=s||So(n);return await this.keychain.set(o,n),o}),gt(this,"deleteKeyPair",async n=>{this.isInitialized(),await this.keychain.del(n)}),gt(this,"deleteSymKey",async n=>{this.isInitialized(),await this.keychain.del(n)}),gt(this,"encode",async(n,s,o)=>{this.isInitialized();const a=N0(o),c=li(s);if(B0(a))return W9(c,o?.encoding);if(C0(a)){const b=a.senderPublicKey,v=a.receiverPublicKey;n=await this.generateSharedKey(b,v)}const f=this.getSymKey(n),{type:u,senderPublicKey:d}=a;return K9({type:u,symKey:f,message:c,senderPublicKey:d,encoding:o?.encoding})}),gt(this,"decode",async(n,s,o)=>{this.isInitialized();const a=Y9(s,o);if(B0(a)){const c=G9(s,o?.encoding);return Li(c)}if(C0(a)){const c=a.receiverPublicKey,f=a.senderPublicKey;n=await this.generateSharedKey(c,f)}try{const c=this.getSymKey(n),f=H9({symKey:c,encoded:s,encoding:o?.encoding});return Li(f)}catch(c){this.logger.error(`Failed to decode message from topic: '${n}', clientId: '${await this.getClientId()}'`),this.logger.error(c)}}),gt(this,"getPayloadType",(n,s=ci)=>{const o=rs({encoded:n,encoding:s});return Di(o.type)}),gt(this,"getPayloadSenderPublicKey",(n,s=ci)=>{const o=rs({encoded:n,encoding:s});return o.senderPublicKey?$t(o.senderPublicKey,xt):void 0}),this.core=e,this.logger=It(r,this.name),this.keychain=i||new RE(this.core,this.logger)}get context(){return Mt(this.logger)}async setPrivateKey(e,r){return await this.keychain.set(e,r),e}getPrivateKey(e){return this.keychain.get(e)}async getClientSeed(){let e="";try{e=this.keychain.get(op)}catch{e=zc(),await this.keychain.set(op,e)}return OE(e,"base16")}getSymKey(e){return this.keychain.get(e)}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var BE=Object.defineProperty,FE=Object.defineProperties,LE=Object.getOwnPropertyDescriptors,Dp=Object.getOwnPropertySymbols,qE=Object.prototype.hasOwnProperty,kE=Object.prototype.propertyIsEnumerable,rf=(t,e,r)=>e in t?BE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zE=(t,e)=>{for(var r in e||(e={}))qE.call(e,r)&&rf(t,r,e[r]);if(Dp)for(var r of Dp(e))kE.call(e,r)&&rf(t,r,e[r]);return t},UE=(t,e)=>FE(t,LE(e)),zt=(t,e,r)=>rf(t,typeof e!="symbol"?e+"":e,r);class jE extends ug{constructor(e,r){super(e,r),this.logger=e,this.core=r,zt(this,"messages",new Map),zt(this,"messagesWithoutClientAck",new Map),zt(this,"name",C_),zt(this,"version",B_),zt(this,"initialized",!1),zt(this,"storagePrefix",Sr),zt(this,"init",async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const i=await this.getRelayerMessages();typeof i<"u"&&(this.messages=i);const n=await this.getRelayerMessagesWithoutClientAck();typeof n<"u"&&(this.messagesWithoutClientAck=n),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}}}),zt(this,"set",async(i,n,s)=>{this.isInitialized();const o=_r(n);let a=this.messages.get(i);if(typeof a>"u"&&(a={}),typeof a[o]<"u")return o;if(a[o]=n,this.messages.set(i,a),s===Po.inbound){const c=this.messagesWithoutClientAck.get(i)||{};this.messagesWithoutClientAck.set(i,UE(zE({},c),{[o]:n}))}return await this.persist(),o}),zt(this,"get",i=>{this.isInitialized();let n=this.messages.get(i);return typeof n>"u"&&(n={}),n}),zt(this,"getWithoutAck",i=>{this.isInitialized();const n={};for(const s of i){const o=this.messagesWithoutClientAck.get(s)||{};n[s]=Object.values(o)}return n}),zt(this,"has",(i,n)=>{this.isInitialized();const s=this.get(i),o=_r(n);return typeof s[o]<"u"}),zt(this,"ack",async(i,n)=>{this.isInitialized();const s=this.messagesWithoutClientAck.get(i);if(typeof s>"u")return;const o=_r(n);delete s[o],Object.keys(s).length===0?this.messagesWithoutClientAck.delete(i):this.messagesWithoutClientAck.set(i,s),await this.persist()}),zt(this,"del",async i=>{this.isInitialized(),this.messages.delete(i),this.messagesWithoutClientAck.delete(i),await this.persist()}),this.logger=It(e,this.name),this.core=r}get context(){return Mt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get storageKeyWithoutClientAck(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name+"_withoutClientAck"}async setRelayerMessages(e){await this.core.storage.setItem(this.storageKey,wc(e))}async setRelayerMessagesWithoutClientAck(e){await this.core.storage.setItem(this.storageKeyWithoutClientAck,wc(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?_c(e):void 0}async getRelayerMessagesWithoutClientAck(){const e=await this.core.storage.getItem(this.storageKeyWithoutClientAck);return typeof e<"u"?_c(e):void 0}async persist(){await this.setRelayerMessages(this.messages),await this.setRelayerMessagesWithoutClientAck(this.messagesWithoutClientAck)}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var VE=Object.defineProperty,KE=Object.defineProperties,HE=Object.getOwnPropertyDescriptors,Op=Object.getOwnPropertySymbols,WE=Object.prototype.hasOwnProperty,GE=Object.prototype.propertyIsEnumerable,nf=(t,e,r)=>e in t?VE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,To=(t,e)=>{for(var r in e||(e={}))WE.call(e,r)&&nf(t,r,e[r]);if(Op)for(var r of Op(e))GE.call(e,r)&&nf(t,r,e[r]);return t},sf=(t,e)=>KE(t,HE(e)),sr=(t,e,r)=>nf(t,typeof e!="symbol"?e+"":e,r);class YE extends hg{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,sr(this,"events",new mt.exports.EventEmitter),sr(this,"name",F_),sr(this,"queue",new Map),sr(this,"publishTimeout",z.toMiliseconds(z.ONE_MINUTE)),sr(this,"initialPublishTimeout",z.toMiliseconds(z.ONE_SECOND*15)),sr(this,"needsTransportRestart",!1),sr(this,"publish",async(i,n,s)=>{var o;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:i,message:n,opts:s}});const a=s?.ttl||ap,c=Io(s),f=s?.prompt||!1,u=s?.tag||0,d=s?.id||Oi().toString(),b={topic:i,message:n,opts:{ttl:a,relay:c,prompt:f,tag:u,id:d,attestation:s?.attestation,tvf:s?.tvf}},v=`Failed to publish payload, please try again. id:${d} tag:${u}`;try{const g=new Promise(async x=>{const I=({id:O})=>{b.opts.id===O&&(this.removeRequestFromQueue(O),this.relayer.events.removeListener(at.publish,I),x(b))};this.relayer.events.on(at.publish,I);const D=ii(new Promise((O,M)=>{this.rpcPublish({topic:i,message:n,ttl:a,prompt:f,tag:u,id:d,attestation:s?.attestation,tvf:s?.tvf}).then(O).catch(P=>{this.logger.warn(P,P?.message),M(P)})}),this.initialPublishTimeout,`Failed initial publish, retrying.... id:${d} tag:${u}`);try{await D,this.events.removeListener(at.publish,I)}catch(O){this.queue.set(d,sf(To({},b),{attempt:1})),this.logger.warn(O,O?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:d,topic:i,message:n,opts:s}}),await ii(g,this.publishTimeout,v)}catch(g){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(g),(o=s?.internal)!=null&&o.throwOnFailedPublish)throw g}finally{this.queue.delete(d)}}),sr(this,"on",(i,n)=>{this.events.on(i,n)}),sr(this,"once",(i,n)=>{this.events.once(i,n)}),sr(this,"off",(i,n)=>{this.events.off(i,n)}),sr(this,"removeListener",(i,n)=>{this.events.removeListener(i,n)}),this.relayer=e,this.logger=It(r,this.name),this.registerEventListeners()}get context(){return Mt(this.logger)}async rpcPublish(e){var r,i,n,s;const{topic:o,message:a,ttl:c=ap,prompt:f,tag:u,id:d,attestation:b,tvf:v}=e,g={method:is(Io().protocol).publish,params:To({topic:o,message:a,ttl:c,prompt:f,tag:u,attestation:b},v),id:d};pt((r=g.params)==null?void 0:r.prompt)&&((i=g.params)==null||delete i.prompt),pt((n=g.params)==null?void 0:n.tag)&&((s=g.params)==null||delete s.tag),this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:g});const x=await this.relayer.request(g);return this.relayer.events.emit(at.publish,e),this.logger.debug("Successfully Published Payload"),x}removeRequestFromQueue(e){this.queue.delete(e)}checkQueue(){this.queue.forEach(async(e,r)=>{const i=e.attempt+1;this.queue.set(r,sf(To({},e),{attempt:i}));const{topic:n,message:s,opts:o,attestation:a}=e;this.logger.warn({},`Publisher: queue->publishing: ${e.opts.id}, tag: ${e.opts.tag}, attempt: ${i}`),await this.rpcPublish(sf(To({},e),{topic:n,message:s,ttl:o.ttl,prompt:o.prompt,tag:o.tag,id:o.id,attestation:a,tvf:o.tvf})),this.logger.warn({},`Publisher: queue->published: ${e.opts.id}`)})}registerEventListeners(){this.relayer.core.heartbeat.on(Fi.pulse,()=>{if(this.needsTransportRestart){this.needsTransportRestart=!1,this.relayer.events.emit(at.connection_stalled);return}this.checkQueue()}),this.relayer.on(at.message_ack,e=>{this.removeRequestFromQueue(e.id.toString())})}}var ZE=Object.defineProperty,JE=(t,e,r)=>e in t?ZE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,_n=(t,e,r)=>JE(t,typeof e!="symbol"?e+"":e,r);class XE{constructor(){_n(this,"map",new Map),_n(this,"set",(e,r)=>{const i=this.get(e);this.exists(e,r)||this.map.set(e,[...i,r])}),_n(this,"get",e=>this.map.get(e)||[]),_n(this,"exists",(e,r)=>this.get(e).includes(r)),_n(this,"delete",(e,r)=>{if(typeof r>"u"){this.map.delete(e);return}if(!this.map.has(e))return;const i=this.get(e);if(!this.exists(e,r))return;const n=i.filter(s=>s!==r);if(!n.length){this.map.delete(e);return}this.map.set(e,n)}),_n(this,"clear",()=>{this.map.clear()})}get topics(){return Array.from(this.map.keys())}}var QE=Object.defineProperty,eS=Object.defineProperties,tS=Object.getOwnPropertyDescriptors,Mp=Object.getOwnPropertySymbols,rS=Object.prototype.hasOwnProperty,iS=Object.prototype.propertyIsEnumerable,of=(t,e,r)=>e in t?QE(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ds=(t,e)=>{for(var r in e||(e={}))rS.call(e,r)&&of(t,r,e[r]);if(Mp)for(var r of Mp(e))iS.call(e,r)&&of(t,r,e[r]);return t},af=(t,e)=>eS(t,tS(e)),ae=(t,e,r)=>of(t,typeof e!="symbol"?e+"":e,r);class nS extends pg{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,ae(this,"subscriptions",new Map),ae(this,"topicMap",new XE),ae(this,"events",new mt.exports.EventEmitter),ae(this,"name",V_),ae(this,"version",K_),ae(this,"pending",new Map),ae(this,"cached",[]),ae(this,"initialized",!1),ae(this,"storagePrefix",Sr),ae(this,"subscribeTimeout",z.toMiliseconds(z.ONE_MINUTE)),ae(this,"initialSubscribeTimeout",z.toMiliseconds(z.ONE_SECOND*15)),ae(this,"clientId"),ae(this,"batchSubscribeTopicsLimit",500),ae(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),await this.restore()),this.initialized=!0}),ae(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 s=Io(n),o={topic:i,relay:s,transportType:n?.transportType};this.pending.set(i,o);const a=await this.rpcSubscribe(i,s,n);return typeof a=="string"&&(this.onSubscribe(a,o),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:i,opts:n}})),a}catch(s){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(s),s}}),ae(this,"unsubscribe",async(i,n)=>{this.isInitialized(),typeof n?.id<"u"?await this.unsubscribeById(i,n.id,n):await this.unsubscribeByTopic(i,n)}),ae(this,"isSubscribed",i=>new Promise(n=>{n(this.topicMap.topics.includes(i))})),ae(this,"isKnownTopic",i=>new Promise(n=>{n(this.topicMap.topics.includes(i)||this.pending.has(i)||this.cached.some(s=>s.topic===i))})),ae(this,"on",(i,n)=>{this.events.on(i,n)}),ae(this,"once",(i,n)=>{this.events.once(i,n)}),ae(this,"off",(i,n)=>{this.events.off(i,n)}),ae(this,"removeListener",(i,n)=>{this.events.removeListener(i,n)}),ae(this,"start",async()=>{await this.onConnect()}),ae(this,"stop",async()=>{await this.onDisconnect()}),ae(this,"restart",async()=>{await this.restore(),await this.onRestart()}),ae(this,"checkPending",async()=>{if(this.pending.size===0&&(!this.initialized||!this.relayer.connected))return;const i=[];this.pending.forEach(n=>{i.push(n)}),await this.batchSubscribe(i)}),ae(this,"registerEventListeners",()=>{this.relayer.core.heartbeat.on(Fi.pulse,async()=>{await this.checkPending()}),this.events.on(kt.created,async i=>{const n=kt.created;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:i}),await this.persist()}),this.events.on(kt.deleted,async i=>{const n=kt.deleted;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:i}),await this.persist()})}),this.relayer=e,this.logger=It(r,this.name),this.clientId=""}get context(){return Mt(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}get hasAnyTopics(){return this.topicMap.topics.length>0||this.pending.size>0||this.cached.length>0||this.subscriptions.size>0}hasSubscription(e,r){let i=!1;try{i=this.getSubscription(e).topic===r}catch{}return i}reset(){this.cached=[],this.initialized=!0}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(e,r){const i=this.topicMap.get(e);await Promise.all(i.map(async n=>await this.unsubscribeById(e,n,r)))}async unsubscribeById(e,r,i){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:i}});try{const n=Io(i);await this.restartToComplete({topic:e,id:r,relay:n}),await this.rpcUnsubscribe(e,r,n);const s=de("USER_DISCONNECTED",`${this.name}, ${e}`);await this.onUnsubscribe(e,r,s),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:i}})}catch(n){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(n),n}}async rpcSubscribe(e,r,i){var n;(!i||i?.transportType===pe.relay)&&await this.restartToComplete({topic:e,id:e,relay:r});const s={method:is(r.protocol).subscribe,params:{topic:e}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:s});const o=(n=i?.internal)==null?void 0:n.throwOnFailedPublish;try{const a=await this.getSubscriptionId(e);if(i?.transportType===pe.link_mode)return setTimeout(()=>{(this.relayer.connected||this.relayer.connecting)&&this.relayer.request(s).catch(u=>this.logger.warn(u))},z.toMiliseconds(z.ONE_SECOND)),a;const c=new Promise(async u=>{const d=b=>{b.topic===e&&(this.events.removeListener(kt.created,d),u(b.id))};this.events.on(kt.created,d);try{const b=await ii(new Promise((v,g)=>{this.relayer.request(s).catch(x=>{this.logger.warn(x,x?.message),g(x)}).then(v)}),this.initialSubscribeTimeout,`Subscribing to ${e} failed, please try again`);this.events.removeListener(kt.created,d),u(b)}catch{}}),f=await ii(c,this.subscribeTimeout,`Subscribing to ${e} failed, please try again`);if(!f&&o)throw new Error(`Subscribing to ${e} failed, please try again`);return f?a:null}catch(a){if(this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(at.connection_stalled),o)throw a}return null}async rpcBatchSubscribe(e){if(!e.length)return;const r=e[0].relay,i={method:is(r.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{await await ii(new Promise(n=>{this.relayer.request(i).catch(s=>this.logger.warn(s)).then(n)}),this.subscribeTimeout,"rpcBatchSubscribe failed, please try again")}catch{this.relayer.events.emit(at.connection_stalled)}}async rpcBatchFetchMessages(e){if(!e.length)return;const r=e[0].relay,i={method:is(r.protocol).batchFetchMessages,params:{topics:e.map(s=>s.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i});let n;try{n=await await ii(new Promise((s,o)=>{this.relayer.request(i).catch(a=>{this.logger.warn(a),o(a)}).then(s)}),this.subscribeTimeout,"rpcBatchFetchMessages failed, please try again")}catch{this.relayer.events.emit(at.connection_stalled)}return n}rpcUnsubscribe(e,r,i){const n={method:is(i.protocol).unsubscribe,params:{topic:e,id:r}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n}),this.relayer.request(n)}onSubscribe(e,r){this.setSubscription(e,af(ds({},r),{id:e})),this.pending.delete(r.topic)}onBatchSubscribe(e){e.length&&e.forEach(r=>{this.setSubscription(r.id,ds({},r)),this.pending.delete(r.topic)})}async onUnsubscribe(e,r,i){this.events.removeAllListeners(r),this.hasSubscription(r,e)&&this.deleteSubscription(r,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,r){this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:r}),this.addSubscription(e,r)}addSubscription(e,r){this.subscriptions.set(e,ds({},r)),this.topicMap.set(r.topic,e),this.events.emit(kt.created,r)}getSubscription(e){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const r=this.subscriptions.get(e);if(!r){const{message:i}=U("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(i)}return r}deleteSubscription(e,r){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:r});const i=this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(i.topic,e),this.events.emit(kt.deleted,af(ds({},i),{reason:r}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit(kt.sync)}async onRestart(){if(this.cached.length){const e=[...this.cached],r=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let i=0;i<r;i++){const n=e.splice(0,this.batchSubscribeTopicsLimit);await this.batchSubscribe(n)}}this.events.emit(kt.resubscribed)}async restore(){try{const e=await this.getRelayerSubscriptions();if(typeof e>"u"||!e.length)return;if(this.subscriptions.size){const{message:r}=U("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(r)}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){e.length&&(await this.rpcBatchSubscribe(e),this.onBatchSubscribe(await Promise.all(e.map(async r=>af(ds({},r),{id:await this.getSubscriptionId(r.topic)})))))}async batchFetchMessages(e){if(!e.length)return;this.logger.trace(`Fetching batch messages for ${e.length} subscriptions`);const r=await this.rpcBatchFetchMessages(e);r&&r.messages&&(await n5(z.toMiliseconds(z.ONE_SECOND)),await this.relayer.handleBatchMessageEvents(r.messages))}async onConnect(){await this.restart(),this.reset()}onDisconnect(){this.onDisable()}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}async restartToComplete(e){!this.relayer.connected&&!this.relayer.connecting&&(this.cached.push(e),await this.relayer.transportOpen())}async getClientId(){return this.clientId||(this.clientId=await this.relayer.core.crypto.getClientId()),this.clientId}async getSubscriptionId(e){return _r(e+await this.getClientId())}}var sS=Object.defineProperty,Pp=Object.getOwnPropertySymbols,oS=Object.prototype.hasOwnProperty,aS=Object.prototype.propertyIsEnumerable,cf=(t,e,r)=>e in t?sS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Rp=(t,e)=>{for(var r in e||(e={}))oS.call(e,r)&&cf(t,r,e[r]);if(Pp)for(var r of Pp(e))aS.call(e,r)&&cf(t,r,e[r]);return t},re=(t,e,r)=>cf(t,typeof e!="symbol"?e+"":e,r);class cS extends dg{constructor(e){super(e),re(this,"protocol","wc"),re(this,"version",2),re(this,"core"),re(this,"logger"),re(this,"events",new mt.exports.EventEmitter),re(this,"provider"),re(this,"messages"),re(this,"subscriber"),re(this,"publisher"),re(this,"name",q_),re(this,"transportExplicitlyClosed",!1),re(this,"initialized",!1),re(this,"connectionAttemptInProgress",!1),re(this,"relayUrl"),re(this,"projectId"),re(this,"packageName"),re(this,"bundleId"),re(this,"hasExperiencedNetworkDisruption",!1),re(this,"pingTimeout"),re(this,"heartBeatTimeout",z.toMiliseconds(z.THIRTY_SECONDS+z.FIVE_SECONDS)),re(this,"reconnectTimeout"),re(this,"connectPromise"),re(this,"reconnectInProgress",!1),re(this,"requestsInFlight",[]),re(this,"connectTimeout",z.toMiliseconds(z.ONE_SECOND*15)),re(this,"request",async r=>{var i,n;this.logger.debug("Publishing Request Payload");const s=r.id||Oi().toString();await this.toEstablishConnection();try{this.logger.trace({id:s,method:r.method,topic:(i=r.params)==null?void 0:i.topic},"relayer.request - publishing...");const o=`${s}:${((n=r.params)==null?void 0:n.tag)||""}`;this.requestsInFlight.push(o);const a=await this.provider.request(r);return this.requestsInFlight=this.requestsInFlight.filter(c=>c!==o),a}catch(o){throw this.logger.debug(`Failed to Publish Request: ${s}`),o}}),re(this,"resetPingTimeout",()=>{go()&&(clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{var r,i,n,s;try{this.logger.debug({},"pingTimeout: Connection stalled, terminating..."),(s=(n=(i=(r=this.provider)==null?void 0:r.connection)==null?void 0:i.socket)==null?void 0:n.terminate)==null||s.call(n)}catch(o){this.logger.warn(o,o?.message)}},this.heartBeatTimeout))}),re(this,"onPayloadHandler",r=>{this.onProviderPayload(r),this.resetPingTimeout()}),re(this,"onConnectHandler",()=>{this.logger.warn({},"Relayer connected \u{1F6DC}"),this.startPingTimeout(),this.events.emit(at.connect)}),re(this,"onDisconnectHandler",()=>{this.logger.warn({},"Relayer disconnected \u{1F6D1}"),this.requestsInFlight=[],this.onProviderDisconnect()}),re(this,"onProviderErrorHandler",r=>{this.logger.fatal(`Fatal socket error: ${r.message}`),this.events.emit(at.error,r),this.logger.fatal("Fatal socket error received, closing transport"),this.transportClose()}),re(this,"registerProviderListeners",()=>{this.provider.on(Gt.payload,this.onPayloadHandler),this.provider.on(Gt.connect,this.onConnectHandler),this.provider.on(Gt.disconnect,this.onDisconnectHandler),this.provider.on(Gt.error,this.onProviderErrorHandler)}),this.core=e.core,this.logger=typeof e.logger<"u"&&typeof e.logger!="string"?It(e.logger,this.name):Dr(ea({level:e.logger||L_})),this.messages=new jE(this.logger,e.core),this.subscriber=new nS(this,this.logger),this.publisher=new YE(this,this.logger),this.relayUrl=e?.relayUrl||fp,this.projectId=e.projectId,U4()?this.packageName=Cl():j4()&&(this.bundleId=Cl()),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.hasAnyTopics)try{await this.transportOpen()}catch(e){this.logger.warn(e,e?.message)}}get context(){return Mt(this.logger)}get connected(){var e,r,i;return((i=(r=(e=this.provider)==null?void 0:e.connection)==null?void 0:r.socket)==null?void 0:i.readyState)===1||!1}get connecting(){var e,r,i;return((i=(r=(e=this.provider)==null?void 0:e.connection)==null?void 0:r.socket)==null?void 0:i.readyState)===0||this.connectPromise!==void 0||!1}async publish(e,r,i){this.isInitialized(),await this.publisher.publish(e,r,i),await this.recordMessageEvent({topic:e,message:r,publishedAt:Date.now(),transportType:pe.relay},Po.outbound)}async subscribe(e,r){var i,n,s;this.isInitialized(),(!(r!=null&&r.transportType)||r?.transportType==="relay")&&await this.toEstablishConnection();const o=typeof((i=r?.internal)==null?void 0:i.throwOnFailedPublish)>"u"?!0:(n=r?.internal)==null?void 0:n.throwOnFailedPublish;let a=((s=this.subscriber.topicMap.get(e))==null?void 0:s[0])||"",c;const f=u=>{u.topic===e&&(this.subscriber.off(kt.created,f),c())};return await Promise.all([new Promise(u=>{c=u,this.subscriber.on(kt.created,f)}),new Promise(async(u,d)=>{a=await this.subscriber.subscribe(e,Rp({internal:{throwOnFailedPublish:o}},r)).catch(b=>{o&&d(b)})||a,u()})]),a}async unsubscribe(e,r){this.isInitialized(),await this.subscriber.unsubscribe(e,r)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async transportDisconnect(){this.provider.disconnect&&(this.hasExperiencedNetworkDisruption||this.connected)?await ii(this.provider.disconnect(),2e3,"provider.disconnect()").catch(()=>this.onProviderDisconnect()):this.onProviderDisconnect()}async transportClose(){this.transportExplicitlyClosed=!0,await this.transportDisconnect()}async transportOpen(e){if(!this.subscriber.hasAnyTopics){this.logger.warn("Starting WS connection skipped because the client has no topics to work with.");return}if(this.connectPromise?(this.logger.debug({},"Waiting for existing connection attempt to resolve..."),await this.connectPromise,this.logger.debug({},"Existing connection attempt resolved")):(this.connectPromise=new Promise(async(r,i)=>{await this.connect(e).then(r).catch(i).finally(()=>{this.connectPromise=void 0})}),await this.connectPromise),!this.connected)throw new Error(`Couldn't establish socket connection to the relay server: ${this.relayUrl}`)}async restartTransport(e){this.logger.debug({},"Restarting transport..."),!this.connectionAttemptInProgress&&(this.relayUrl=e||this.relayUrl,await this.confirmOnlineStateOrThrow(),await this.transportClose(),await this.transportOpen())}async confirmOnlineStateOrThrow(){if(!await H0())throw new Error("No internet connection detected. Please restart your network and try again.")}async handleBatchMessageEvents(e){if(e?.length===0){this.logger.trace("Batch message events is empty. Ignoring...");return}const r=e.sort((i,n)=>i.publishedAt-n.publishedAt);this.logger.debug(`Batch of ${r.length} message events sorted`);for(const i of r)try{await this.onMessageEvent(i)}catch(n){this.logger.warn(n,"Error while processing batch message event: "+n?.message)}this.logger.trace(`Batch of ${r.length} message events processed`)}async onLinkMessageEvent(e,r){const{topic:i}=e;if(!r.sessionExists){const n=Qe(z.FIVE_MINUTES),s={topic:i,expiry:n,relay:{protocol:"irn"},active:!1};await this.core.pairing.pairings.set(i,s)}this.events.emit(at.message,e),await this.recordMessageEvent(e,Po.inbound)}async connect(e){await this.confirmOnlineStateOrThrow(),e&&e!==this.relayUrl&&(this.relayUrl=e,await this.transportDisconnect()),this.connectionAttemptInProgress=!0,this.transportExplicitlyClosed=!1;let r=1;for(;r<6;){try{if(this.transportExplicitlyClosed)break;this.logger.debug({},`Connecting to ${this.relayUrl}, attempt: ${r}...`),await this.createProvider(),await new Promise(async(i,n)=>{const s=()=>{n(new Error("Connection interrupted while trying to subscribe"))};this.provider.once(Gt.disconnect,s),await ii(new Promise((o,a)=>{this.provider.connect().then(o).catch(a)}),this.connectTimeout,`Socket stalled when trying to connect to ${this.relayUrl}`).catch(o=>{n(o)}).finally(()=>{this.provider.off(Gt.disconnect,s),clearTimeout(this.reconnectTimeout)}),await new Promise(async(o,a)=>{const c=()=>{a(new Error("Connection interrupted while trying to subscribe"))};this.provider.once(Gt.disconnect,c),await this.subscriber.start().then(o).catch(a).finally(()=>{this.provider.off(Gt.disconnect,c)})}),this.hasExperiencedNetworkDisruption=!1,i()})}catch(i){await this.subscriber.stop();const n=i;this.logger.warn({},n.message),this.hasExperiencedNetworkDisruption=!0}finally{this.connectionAttemptInProgress=!1}if(this.connected){this.logger.debug({},`Connected to ${this.relayUrl} successfully on attempt: ${r}`);break}await new Promise(i=>setTimeout(i,z.toMiliseconds(r*1))),r++}}startPingTimeout(){var e,r,i,n,s;if(go())try{(r=(e=this.provider)==null?void 0:e.connection)!=null&&r.socket&&((s=(n=(i=this.provider)==null?void 0:i.connection)==null?void 0:n.socket)==null||s.on("ping",()=>{this.resetPingTimeout()})),this.resetPingTimeout()}catch(o){this.logger.warn(o,o?.message)}}async createProvider(){this.provider.connection&&this.unregisterProviderListeners();const e=await this.core.crypto.signJWT(this.relayUrl);this.provider=new S_(new D_(W4({sdkVersion:Xc,protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:e,useOnCloseEvent:!0,bundleId:this.bundleId,packageName:this.packageName}))),this.registerProviderListeners()}async recordMessageEvent(e,r){const{topic:i,message:n}=e;await this.messages.set(i,n,r)}async shouldIgnoreMessageEvent(e){const{topic:r,message:i}=e;if(!i||i.length===0)return this.logger.warn(`Ignoring invalid/empty message: ${i}`),!0;if(!await this.subscriber.isKnownTopic(r))return this.logger.warn(`Ignoring message for unknown topic ${r}`),!0;const n=this.messages.has(r,i);return n&&this.logger.warn(`Ignoring duplicate message: ${i}`),n}async onProviderPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),Jc(e)){if(!e.method.endsWith(k_))return;const r=e.params,{topic:i,message:n,publishedAt:s,attestation:o}=r.data,a={topic:i,message:n,publishedAt:s,transportType:pe.relay,attestation:o};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(Rp({type:"event",event:r.id},a)),this.events.emit(r.id,a),await this.acknowledgePayload(e),await this.onMessageEvent(a)}else Oo(e)&&this.events.emit(at.message_ack,e)}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(await this.recordMessageEvent(e,Po.inbound),this.events.emit(at.message,e))}async acknowledgePayload(e){const r=Yc(e.id,!0);await this.provider.connection.send(r)}unregisterProviderListeners(){this.provider.off(Gt.payload,this.onPayloadHandler),this.provider.off(Gt.connect,this.onConnectHandler),this.provider.off(Gt.disconnect,this.onDisconnectHandler),this.provider.off(Gt.error,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let e=await H0();B7(async r=>{e!==r&&(e=r,r?await this.transportOpen().catch(i=>this.logger.error(i,i?.message)):(this.hasExperiencedNetworkDisruption=!0,await this.transportDisconnect(),this.transportExplicitlyClosed=!1))})}async onProviderDisconnect(){clearTimeout(this.pingTimeout),this.events.emit(at.disconnect),this.connectionAttemptInProgress=!1,!this.reconnectInProgress&&(this.reconnectInProgress=!0,await this.subscriber.stop(),this.subscriber.hasAnyTopics&&(this.transportExplicitlyClosed||(this.reconnectTimeout=setTimeout(async()=>{await this.transportOpen().catch(e=>this.logger.error(e,e?.message)),this.reconnectTimeout=void 0,this.reconnectInProgress=!1},z.toMiliseconds(z_)))))}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}async toEstablishConnection(){await this.confirmOnlineStateOrThrow(),!this.connected&&await this.connect()}}function fS(){}function Tp(t){if(!t||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e===null||e===Object.prototype||Object.getPrototypeOf(e)===null?Object.prototype.toString.call(t)==="[object Object]":!1}function Np(t){return Object.getOwnPropertySymbols(t).filter(e=>Object.prototype.propertyIsEnumerable.call(t,e))}function Cp(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const uS="[object RegExp]",hS="[object String]",dS="[object Number]",lS="[object Boolean]",Bp="[object Arguments]",pS="[object Symbol]",bS="[object Date]",gS="[object Map]",yS="[object Set]",vS="[object Array]",mS="[object Function]",wS="[object ArrayBuffer]",ff="[object Object]",_S="[object Error]",xS="[object DataView]",ES="[object Uint8Array]",SS="[object Uint8ClampedArray]",IS="[object Uint16Array]",AS="[object Uint32Array]",$S="[object BigUint64Array]",DS="[object Int8Array]",OS="[object Int16Array]",MS="[object Int32Array]",PS="[object BigInt64Array]",RS="[object Float32Array]",TS="[object Float64Array]";function NS(t,e){return t===e||Number.isNaN(t)&&Number.isNaN(e)}function CS(t,e,r){return ls(t,e,void 0,void 0,void 0,void 0,r)}function ls(t,e,r,i,n,s,o){const a=o(t,e,r,i,n,s);if(a!==void 0)return a;if(typeof t==typeof e)switch(typeof t){case"bigint":case"string":case"boolean":case"symbol":case"undefined":return t===e;case"number":return t===e||Object.is(t,e);case"function":return t===e;case"object":return ps(t,e,s,o)}return ps(t,e,s,o)}function ps(t,e,r,i){if(Object.is(t,e))return!0;let n=Cp(t),s=Cp(e);if(n===Bp&&(n=ff),s===Bp&&(s=ff),n!==s)return!1;switch(n){case hS:return t.toString()===e.toString();case dS:{const c=t.valueOf(),f=e.valueOf();return NS(c,f)}case lS:case bS:case pS:return Object.is(t.valueOf(),e.valueOf());case uS:return t.source===e.source&&t.flags===e.flags;case mS:return t===e}r=r??new Map;const o=r.get(t),a=r.get(e);if(o!=null&&a!=null)return o===e;r.set(t,e),r.set(e,t);try{switch(n){case gS:{if(t.size!==e.size)return!1;for(const[c,f]of t.entries())if(!e.has(c)||!ls(f,e.get(c),c,t,e,r,i))return!1;return!0}case yS:{if(t.size!==e.size)return!1;const c=Array.from(t.values()),f=Array.from(e.values());for(let u=0;u<c.length;u++){const d=c[u],b=f.findIndex(v=>ls(d,v,void 0,t,e,r,i));if(b===-1)return!1;f.splice(b,1)}return!0}case vS:case ES:case SS:case IS:case AS:case $S:case DS:case OS:case MS:case PS:case RS:case TS:{if(typeof Buffer<"u"&&Buffer.isBuffer(t)!==Buffer.isBuffer(e)||t.length!==e.length)return!1;for(let c=0;c<t.length;c++)if(!ls(t[c],e[c],c,t,e,r,i))return!1;return!0}case wS:return t.byteLength!==e.byteLength?!1:ps(new Uint8Array(t),new Uint8Array(e),r,i);case xS:return t.byteLength!==e.byteLength||t.byteOffset!==e.byteOffset?!1:ps(new Uint8Array(t),new Uint8Array(e),r,i);case _S:return t.name===e.name&&t.message===e.message;case ff:{if(!(ps(t.constructor,e.constructor,r,i)||Tp(t)&&Tp(e)))return!1;const c=[...Object.keys(t),...Np(t)],f=[...Object.keys(e),...Np(e)];if(c.length!==f.length)return!1;for(let u=0;u<c.length;u++){const d=c[u],b=t[d];if(!Object.hasOwn(e,d))return!1;const v=e[d];if(!ls(b,v,d,t,e,r,i))return!1}return!0}default:return!1}}finally{r.delete(t),r.delete(e)}}function BS(t,e){return CS(t,e,fS)}var FS=Object.defineProperty,Fp=Object.getOwnPropertySymbols,LS=Object.prototype.hasOwnProperty,qS=Object.prototype.propertyIsEnumerable,uf=(t,e,r)=>e in t?FS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Lp=(t,e)=>{for(var r in e||(e={}))LS.call(e,r)&&uf(t,r,e[r]);if(Fp)for(var r of Fp(e))qS.call(e,r)&&uf(t,r,e[r]);return t},Ct=(t,e,r)=>uf(t,typeof e!="symbol"?e+"":e,r);class Ni extends lg{constructor(e,r,i,n=Sr,s=void 0){super(e,r,i,n),this.core=e,this.logger=r,this.name=i,Ct(this,"map",new Map),Ct(this,"version",U_),Ct(this,"cached",[]),Ct(this,"initialized",!1),Ct(this,"getKey"),Ct(this,"storagePrefix",Sr),Ct(this,"recentlyDeleted",[]),Ct(this,"recentlyDeletedLimit",200),Ct(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(o=>{this.getKey&&o!==null&&!pt(o)?this.map.set(this.getKey(o),o):l7(o)?this.map.set(o.id,o):p7(o)&&this.map.set(o.topic,o)}),this.cached=[],this.initialized=!0)}),Ct(this,"set",async(o,a)=>{this.isInitialized(),this.map.has(o)?await this.update(o,a):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:o,value:a}),this.map.set(o,a),await this.persist())}),Ct(this,"get",o=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:o}),this.getData(o))),Ct(this,"getAll",o=>(this.isInitialized(),o?this.values.filter(a=>Object.keys(o).every(c=>BS(a[c],o[c]))):this.values)),Ct(this,"update",async(o,a)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:o,update:a});const c=Lp(Lp({},this.getData(o)),a);this.map.set(o,c),await this.persist()}),Ct(this,"delete",async(o,a)=>{this.isInitialized(),this.map.has(o)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:o,reason:a}),this.map.delete(o),this.addToRecentlyDeleted(o),await this.persist())}),this.logger=It(r,this.name),this.storagePrefix=n,this.getKey=s}get context(){return Mt(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 r=this.map.get(e);if(!r){if(this.recentlyDeleted.includes(e)){const{message:n}=U("MISSING_OR_INVALID",`Record was recently deleted - ${this.name}: ${e}`);throw this.logger.error(n),new Error(n)}const{message:i}=U("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(i),new Error(i)}return r}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:r}=U("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}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}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var kS=Object.defineProperty,zS=(t,e,r)=>e in t?kS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Q=(t,e,r)=>zS(t,typeof e!="symbol"?e+"":e,r);class US{constructor(e,r){this.core=e,this.logger=r,Q(this,"name",H_),Q(this,"version",W_),Q(this,"events",new mt.exports),Q(this,"pairings"),Q(this,"initialized",!1),Q(this,"storagePrefix",Sr),Q(this,"ignoredPayloadTypes",[qr]),Q(this,"registeredMethods",[]),Q(this,"init",async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))}),Q(this,"register",({methods:i})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...i])]}),Q(this,"create",async i=>{this.isInitialized();const n=zc(),s=await this.core.crypto.setSymKey(n),o=Qe(z.FIVE_MINUTES),a={protocol:cp},c={topic:s,expiry:o,relay:a,active:!1,methods:i?.methods},f=L0({protocol:this.core.protocol,version:this.core.version,topic:s,symKey:n,relay:a,expiryTimestamp:o,methods:i?.methods});return this.events.emit(Pi.create,c),this.core.expirer.set(s,o),await this.pairings.set(s,c),await this.core.relayer.subscribe(s,{transportType:i?.transportType}),{topic:s,uri:f}}),Q(this,"pair",async i=>{this.isInitialized();const n=this.core.eventClient.createEvent({properties:{topic:i?.uri,trace:[Ir.pairing_started]}});this.isValidPair(i,n);const{topic:s,symKey:o,relay:a,expiryTimestamp:c,methods:f}=F0(i.uri);n.props.properties.topic=s,n.addTrace(Ir.pairing_uri_validation_success),n.addTrace(Ir.pairing_uri_not_expired);let u;if(this.pairings.keys.includes(s)){if(u=this.pairings.get(s),n.addTrace(Ir.existing_pairing),u.active)throw n.setError(Ur.active_pairing_already_exists),new Error(`Pairing already exists: ${s}. Please try again with a new connection URI.`);n.addTrace(Ir.pairing_not_expired)}const d=c||Qe(z.FIVE_MINUTES),b={topic:s,relay:a,expiry:d,active:!1,methods:f};this.core.expirer.set(s,d),await this.pairings.set(s,b),n.addTrace(Ir.store_new_pairing),i.activatePairing&&await this.activate({topic:s}),this.events.emit(Pi.create,b),n.addTrace(Ir.emit_inactive_pairing),this.core.crypto.keychain.has(s)||await this.core.crypto.setSymKey(o,s),n.addTrace(Ir.subscribing_pairing_topic);try{await this.core.relayer.confirmOnlineStateOrThrow()}catch{n.setError(Ur.no_internet_connection)}try{await this.core.relayer.subscribe(s,{relay:a})}catch(v){throw n.setError(Ur.subscribe_pairing_topic_failure),v}return n.addTrace(Ir.subscribe_pairing_topic_success),b}),Q(this,"activate",async({topic:i})=>{this.isInitialized();const n=Qe(z.FIVE_MINUTES);this.core.expirer.set(i,n),await this.pairings.update(i,{active:!0,expiry:n})}),Q(this,"ping",async i=>{this.isInitialized(),await this.isValidPing(i),this.logger.warn("ping() is deprecated and will be removed in the next major release.");const{topic:n}=i;if(this.pairings.keys.includes(n)){const s=await this.sendRequest(n,"wc_pairingPing",{}),{done:o,resolve:a,reject:c}=Ai();this.events.once(ne("pairing_ping",s),({error:f})=>{f?c(f):a()}),await o()}}),Q(this,"updateExpiry",async({topic:i,expiry:n})=>{this.isInitialized(),await this.pairings.update(i,{expiry:n})}),Q(this,"updateMetadata",async({topic:i,metadata:n})=>{this.isInitialized(),await this.pairings.update(i,{peerMetadata:n})}),Q(this,"getPairings",()=>(this.isInitialized(),this.pairings.values)),Q(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",de("USER_DISCONNECTED")),await this.deletePairing(n))}),Q(this,"formatUriFromPairing",i=>{this.isInitialized();const{topic:n,relay:s,expiry:o,methods:a}=i,c=this.core.crypto.keychain.get(n);return L0({protocol:this.core.protocol,version:this.core.version,topic:n,symKey:c,relay:s,expiryTimestamp:o,methods:a})}),Q(this,"sendRequest",async(i,n,s)=>{const o=Mi(n,s),a=await this.core.crypto.encode(i,o),c=cs[n].req;return this.core.history.set(i,o),this.core.relayer.publish(i,a,c),o.id}),Q(this,"sendResult",async(i,n,s)=>{const o=Yc(i,s),a=await this.core.crypto.encode(n,o),c=(await this.core.history.get(n,i)).request.method,f=cs[c].res;await this.core.relayer.publish(n,a,f),await this.core.history.resolve(o)}),Q(this,"sendError",async(i,n,s)=>{const o=Zc(i,s),a=await this.core.crypto.encode(n,o),c=(await this.core.history.get(n,i)).request.method,f=cs[c]?cs[c].res:cs.unregistered_method.res;await this.core.relayer.publish(n,a,f),await this.core.history.resolve(o)}),Q(this,"deletePairing",async(i,n)=>{await this.core.relayer.unsubscribe(i),await Promise.all([this.pairings.delete(i,de("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(i),n?Promise.resolve():this.core.expirer.del(i)])}),Q(this,"cleanup",async()=>{const i=this.pairings.getAll().filter(n=>ni(n.expiry));await Promise.all(i.map(n=>this.deletePairing(n.topic)))}),Q(this,"onRelayEventRequest",async i=>{const{topic:n,payload:s}=i;switch(s.method){case"wc_pairingPing":return await this.onPairingPingRequest(n,s);case"wc_pairingDelete":return await this.onPairingDeleteRequest(n,s);default:return await this.onUnknownRpcMethodRequest(n,s)}}),Q(this,"onRelayEventResponse",async i=>{const{topic:n,payload:s}=i,o=(await this.core.history.get(n,s.id)).request.method;switch(o){case"wc_pairingPing":return this.onPairingPingResponse(n,s);default:return this.onUnknownRpcMethodResponse(o)}}),Q(this,"onPairingPingRequest",async(i,n)=>{const{id:s}=n;try{this.isValidPing({topic:i}),await this.sendResult(s,i,!0),this.events.emit(Pi.ping,{id:s,topic:i})}catch(o){await this.sendError(s,i,o),this.logger.error(o)}}),Q(this,"onPairingPingResponse",(i,n)=>{const{id:s}=n;setTimeout(()=>{Er(n)?this.events.emit(ne("pairing_ping",s),{}):Wt(n)&&this.events.emit(ne("pairing_ping",s),{error:n.error})},500)}),Q(this,"onPairingDeleteRequest",async(i,n)=>{const{id:s}=n;try{this.isValidDisconnect({topic:i}),await this.deletePairing(i),this.events.emit(Pi.delete,{id:s,topic:i})}catch(o){await this.sendError(s,i,o),this.logger.error(o)}}),Q(this,"onUnknownRpcMethodRequest",async(i,n)=>{const{id:s,method:o}=n;try{if(this.registeredMethods.includes(o))return;const a=de("WC_METHOD_UNSUPPORTED",o);await this.sendError(s,i,a),this.logger.error(a)}catch(a){await this.sendError(s,i,a),this.logger.error(a)}}),Q(this,"onUnknownRpcMethodResponse",i=>{this.registeredMethods.includes(i)||this.logger.error(de("WC_METHOD_UNSUPPORTED",i))}),Q(this,"isValidPair",(i,n)=>{var s;if(!Nt(i)){const{message:a}=U("MISSING_OR_INVALID",`pair() params: ${i}`);throw n.setError(Ur.malformed_pairing_uri),new Error(a)}if(!d7(i.uri)){const{message:a}=U("MISSING_OR_INVALID",`pair() uri: ${i.uri}`);throw n.setError(Ur.malformed_pairing_uri),new Error(a)}const o=F0(i?.uri);if(!((s=o?.relay)!=null&&s.protocol)){const{message:a}=U("MISSING_OR_INVALID","pair() uri#relay-protocol");throw n.setError(Ur.malformed_pairing_uri),new Error(a)}if(!(o!=null&&o.symKey)){const{message:a}=U("MISSING_OR_INVALID","pair() uri#symKey");throw n.setError(Ur.malformed_pairing_uri),new Error(a)}if(o!=null&&o.expiryTimestamp&&z.toMiliseconds(o?.expiryTimestamp)<Date.now()){n.setError(Ur.pairing_expired);const{message:a}=U("EXPIRED","pair() URI has expired. Please try again with a new connection URI.");throw new Error(a)}}),Q(this,"isValidPing",async i=>{if(!Nt(i)){const{message:s}=U("MISSING_OR_INVALID",`ping() params: ${i}`);throw new Error(s)}const{topic:n}=i;await this.isValidPairingTopic(n)}),Q(this,"isValidDisconnect",async i=>{if(!Nt(i)){const{message:s}=U("MISSING_OR_INVALID",`disconnect() params: ${i}`);throw new Error(s)}const{topic:n}=i;await this.isValidPairingTopic(n)}),Q(this,"isValidPairingTopic",async i=>{if(!De(i,!1)){const{message:n}=U("MISSING_OR_INVALID",`pairing topic should be a string: ${i}`);throw new Error(n)}if(!this.pairings.keys.includes(i)){const{message:n}=U("NO_MATCHING_KEY",`pairing topic doesn't exist: ${i}`);throw new Error(n)}if(ni(this.pairings.get(i).expiry)){await this.deletePairing(i);const{message:n}=U("EXPIRED",`pairing topic: ${i}`);throw new Error(n)}}),this.core=e,this.logger=It(r,this.name),this.pairings=new Ni(this.core,this.logger,this.name,this.storagePrefix)}get context(){return Mt(this.logger)}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(at.message,async e=>{const{topic:r,message:i,transportType:n}=e;if(this.pairings.keys.includes(r)&&n!==pe.link_mode&&!this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(i)))try{const s=await this.core.crypto.decode(r,i);Jc(s)?(this.core.history.set(r,s),await this.onRelayEventRequest({topic:r,payload:s})):Oo(s)&&(await this.core.history.resolve(s),await this.onRelayEventResponse({topic:r,payload:s}),this.core.history.delete(r,s.id)),await this.core.relayer.messages.ack(r,i)}catch(s){this.logger.error(s)}})}registerExpirerEvents(){this.core.expirer.on(Yt.expired,async e=>{const{topic:r}=ql(e.target);r&&this.pairings.keys.includes(r)&&(await this.deletePairing(r,!0),this.events.emit(Pi.expire,{topic:r}))})}}var jS=Object.defineProperty,VS=(t,e,r)=>e in t?jS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yt=(t,e,r)=>VS(t,typeof e!="symbol"?e+"":e,r);class KS extends fg{constructor(e,r){super(e,r),this.core=e,this.logger=r,yt(this,"records",new Map),yt(this,"events",new mt.exports.EventEmitter),yt(this,"name",G_),yt(this,"version",Y_),yt(this,"cached",[]),yt(this,"initialized",!1),yt(this,"storagePrefix",Sr),yt(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)}),yt(this,"set",(i,n,s)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:i,request:n,chainId:s}),this.records.has(n.id))return;const o={id:n.id,topic:i,request:{method:n.method,params:n.params||null},chainId:s,expiry:Qe(z.THIRTY_DAYS)};this.records.set(o.id,o),this.persist(),this.events.emit(ir.created,o)}),yt(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=Wt(i)?{error:i.error}:{result:i.result},this.records.set(n.id,n),this.persist(),this.events.emit(ir.updated,n))}),yt(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))),yt(this,"delete",(i,n)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:n}),this.values.forEach(s=>{if(s.topic===i){if(typeof n<"u"&&s.id!==n)return;this.records.delete(s.id),this.events.emit(ir.deleted,s)}}),this.persist()}),yt(this,"exists",async(i,n)=>(this.isInitialized(),this.records.has(n)?(await this.getRecord(n)).topic===i:!1)),yt(this,"on",(i,n)=>{this.events.on(i,n)}),yt(this,"once",(i,n)=>{this.events.once(i,n)}),yt(this,"off",(i,n)=>{this.events.off(i,n)}),yt(this,"removeListener",(i,n)=>{this.events.removeListener(i,n)}),this.logger=It(r,this.name)}get context(){return Mt(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(r=>{if(typeof r.response<"u")return;const i={topic:r.topic,request:Mi(r.request.method,r.request.params,r.id),chainId:r.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 r=this.records.get(e);if(!r){const{message:i}=U("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(i)}return r}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(ir.sync)}async restore(){try{const e=await this.getJsonRpcRecords();if(typeof e>"u"||!e.length)return;if(this.records.size){const{message:r}=U("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}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(ir.created,e=>{const r=ir.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.events.on(ir.updated,e=>{const r=ir.updated;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.events.on(ir.deleted,e=>{const r=ir.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.core.heartbeat.on(Fi.pulse,()=>{this.cleanup()})}cleanup(){try{this.isInitialized();let e=!1;this.records.forEach(r=>{z.toMiliseconds(r.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${r.id}`),this.records.delete(r.id),this.events.emit(ir.deleted,r,!1),e=!0)}),e&&this.persist()}catch(e){this.logger.warn(e)}}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var HS=Object.defineProperty,WS=(t,e,r)=>e in t?HS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Et=(t,e,r)=>WS(t,typeof e!="symbol"?e+"":e,r);class GS extends bg{constructor(e,r){super(e,r),this.core=e,this.logger=r,Et(this,"expirations",new Map),Et(this,"events",new mt.exports.EventEmitter),Et(this,"name",Z_),Et(this,"version",J_),Et(this,"cached",[]),Et(this,"initialized",!1),Et(this,"storagePrefix",Sr),Et(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)}),Et(this,"has",i=>{try{const n=this.formatTarget(i);return typeof this.getExpiration(n)<"u"}catch{return!1}}),Et(this,"set",(i,n)=>{this.isInitialized();const s=this.formatTarget(i),o={target:s,expiry:n};this.expirations.set(s,o),this.checkExpiry(s,o),this.events.emit(Yt.created,{target:s,expiration:o})}),Et(this,"get",i=>{this.isInitialized();const n=this.formatTarget(i);return this.getExpiration(n)}),Et(this,"del",i=>{if(this.isInitialized(),this.has(i)){const n=this.formatTarget(i),s=this.getExpiration(n);this.expirations.delete(n),this.events.emit(Yt.deleted,{target:n,expiration:s})}}),Et(this,"on",(i,n)=>{this.events.on(i,n)}),Et(this,"once",(i,n)=>{this.events.once(i,n)}),Et(this,"off",(i,n)=>{this.events.off(i,n)}),Et(this,"removeListener",(i,n)=>{this.events.removeListener(i,n)}),this.logger=It(r,this.name)}get context(){return Mt(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 G4(e);if(typeof e=="number")return Y4(e);const{message:r}=U("UNKNOWN_TYPE",`Target type: ${typeof e}`);throw new Error(r)}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(Yt.sync)}async restore(){try{const e=await this.getExpirations();if(typeof e>"u"||!e.length)return;if(this.expirations.size){const{message:r}=U("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}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 r=this.expirations.get(e);if(!r){const{message:i}=U("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.warn(i),new Error(i)}return r}checkExpiry(e,r){const{expiry:i}=r;z.toMiliseconds(i)-Date.now()<=0&&this.expire(e,r)}expire(e,r){this.expirations.delete(e),this.events.emit(Yt.expired,{target:e,expiration:r})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,r)=>this.checkExpiry(r,e))}registerEventListeners(){this.core.heartbeat.on(Fi.pulse,()=>this.checkExpirations()),this.events.on(Yt.created,e=>{const r=Yt.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(Yt.expired,e=>{const r=Yt.expired;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(Yt.deleted,e=>{const r=Yt.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var YS=Object.defineProperty,ZS=(t,e,r)=>e in t?YS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Oe=(t,e,r)=>ZS(t,typeof e!="symbol"?e+"":e,r);class JS extends gg{constructor(e,r,i){super(e,r,i),this.core=e,this.logger=r,this.store=i,Oe(this,"name",X_),Oe(this,"abortController"),Oe(this,"isDevEnv"),Oe(this,"verifyUrlV3",ex),Oe(this,"storagePrefix",Sr),Oe(this,"version",sp),Oe(this,"publicKey"),Oe(this,"fetchPromise"),Oe(this,"init",async()=>{var n;this.isDevEnv||(this.publicKey=await this.store.getItem(this.storeKey),this.publicKey&&z.toMiliseconds((n=this.publicKey)==null?void 0:n.expiresAt)<Date.now()&&(this.logger.debug("verify v2 public key expired"),await this.removePublicKey()))}),Oe(this,"register",async n=>{if(!Hn()||this.isDevEnv)return;const s=window.location.origin,{id:o,decryptedId:a}=n,c=`${this.verifyUrlV3}/attestation?projectId=${this.core.projectId}&origin=${s}&id=${o}&decryptedId=${a}`;try{const f=Rn(),u=this.startAbortTimer(z.ONE_SECOND*5),d=await new Promise((b,v)=>{const g=()=>{window.removeEventListener("message",I),f.body.removeChild(x),v("attestation aborted")};this.abortController.signal.addEventListener("abort",g);const x=f.createElement("iframe");x.src=c,x.style.display="none",x.addEventListener("error",g,{signal:this.abortController.signal});const I=D=>{if(D.data&&typeof D.data=="string")try{const O=JSON.parse(D.data);if(O.type==="verify_attestation"){if(_a(O.attestation).payload.id!==o)return;clearInterval(u),f.body.removeChild(x),this.abortController.signal.removeEventListener("abort",g),window.removeEventListener("message",I),b(O.attestation===null?"":O.attestation)}}catch(O){this.logger.warn(O)}};f.body.appendChild(x),window.addEventListener("message",I,{signal:this.abortController.signal})});return this.logger.debug("jwt attestation",d),d}catch(f){this.logger.warn(f)}return""}),Oe(this,"resolve",async n=>{if(this.isDevEnv)return"";const{attestationId:s,hash:o,encryptedId:a}=n;if(s===""){this.logger.debug("resolve: attestationId is empty, skipping");return}if(s){if(_a(s).payload.id!==a)return;const f=await this.isValidJwtAttestation(s);if(f){if(!f.isVerified){this.logger.warn("resolve: jwt attestation: origin url not verified");return}return f}}if(!o)return;const c=this.getVerifyUrl(n?.verifyUrl);return this.fetchAttestation(o,c)}),Oe(this,"fetchAttestation",async(n,s)=>{this.logger.debug(`resolving attestation: ${n} from url: ${s}`);const o=this.startAbortTimer(z.ONE_SECOND*5),a=await fetch(`${s}/attestation/${n}?v2Supported=true`,{signal:this.abortController.signal});return clearTimeout(o),a.status===200?await a.json():void 0}),Oe(this,"getVerifyUrl",n=>{let s=n||fs;return tx.includes(s)||(this.logger.info(`verify url: ${s}, not included in trusted list, assigning default: ${fs}`),s=fs),s}),Oe(this,"fetchPublicKey",async()=>{try{this.logger.debug(`fetching public key from: ${this.verifyUrlV3}`);const n=this.startAbortTimer(z.FIVE_SECONDS),s=await fetch(`${this.verifyUrlV3}/public-key`,{signal:this.abortController.signal});return clearTimeout(n),await s.json()}catch(n){this.logger.warn(n)}}),Oe(this,"persistPublicKey",async n=>{this.logger.debug("persisting public key to local storage",n),await this.store.setItem(this.storeKey,n),this.publicKey=n}),Oe(this,"removePublicKey",async()=>{this.logger.debug("removing verify v2 public key from storage"),await this.store.removeItem(this.storeKey),this.publicKey=void 0}),Oe(this,"isValidJwtAttestation",async n=>{const s=await this.getPublicKey();try{if(s)return this.validateAttestation(n,s)}catch(a){this.logger.error(a),this.logger.warn("error validating attestation")}const o=await this.fetchAndPersistPublicKey();try{if(o)return this.validateAttestation(n,o)}catch(a){this.logger.error(a),this.logger.warn("error validating attestation")}}),Oe(this,"getPublicKey",async()=>this.publicKey?this.publicKey:await this.fetchAndPersistPublicKey()),Oe(this,"fetchAndPersistPublicKey",async()=>{if(this.fetchPromise)return await this.fetchPromise,this.publicKey;this.fetchPromise=new Promise(async s=>{const o=await this.fetchPublicKey();o&&(await this.persistPublicKey(o),s(o))});const n=await this.fetchPromise;return this.fetchPromise=void 0,n}),Oe(this,"validateAttestation",(n,s)=>{const o=Q9(n,s.publicKey),a={hasExpired:z.toMiliseconds(o.exp)<Date.now(),payload:o};if(a.hasExpired)throw this.logger.warn("resolve: jwt attestation expired"),new Error("JWT attestation expired");return{origin:a.payload.origin,isScam:a.payload.isScam,isVerified:a.payload.isVerified}}),this.logger=It(r,this.name),this.abortController=new AbortController,this.isDevEnv=xc(),this.init()}get storeKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//verify:public:key"}get context(){return Mt(this.logger)}startAbortTimer(e){return this.abortController=new AbortController,setTimeout(()=>this.abortController.abort(),z.toMiliseconds(e))}}var XS=Object.defineProperty,QS=(t,e,r)=>e in t?XS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,qp=(t,e,r)=>QS(t,typeof e!="symbol"?e+"":e,r);class eI extends yg{constructor(e,r){super(e,r),this.projectId=e,this.logger=r,qp(this,"context",rx),qp(this,"registerDeviceToken",async i=>{const{clientId:n,token:s,notificationType:o,enableEncrypted:a=!1}=i,c=`${ix}/${this.projectId}/clients`;await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:n,type:o,token:s,always_raw:a})})}),this.logger=It(r,this.context)}}var tI=Object.defineProperty,kp=Object.getOwnPropertySymbols,rI=Object.prototype.hasOwnProperty,iI=Object.prototype.propertyIsEnumerable,hf=(t,e,r)=>e in t?tI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,bs=(t,e)=>{for(var r in e||(e={}))rI.call(e,r)&&hf(t,r,e[r]);if(kp)for(var r of kp(e))iI.call(e,r)&&hf(t,r,e[r]);return t},ct=(t,e,r)=>hf(t,typeof e!="symbol"?e+"":e,r);class nI extends vg{constructor(e,r,i=!0){super(e,r,i),this.core=e,this.logger=r,ct(this,"context",sx),ct(this,"storagePrefix",Sr),ct(this,"storageVersion",nx),ct(this,"events",new Map),ct(this,"shouldPersist",!1),ct(this,"init",async()=>{if(!xc())try{const n={eventId:zl(),timestamp:Date.now(),domain:this.getAppDomain(),props:{event:"INIT",type:"",properties:{client_id:await this.core.crypto.getClientId(),user_agent:Fl(this.core.relayer.protocol,this.core.relayer.version,Xc)}}};await this.sendEvent([n])}catch(n){this.logger.warn(n)}}),ct(this,"createEvent",n=>{const{event:s="ERROR",type:o="",properties:{topic:a,trace:c}}=n,f=zl(),u=this.core.projectId||"",d=Date.now(),b=bs({eventId:f,timestamp:d,props:{event:s,type:o,properties:{topic:a,trace:c}},bundleId:u,domain:this.getAppDomain()},this.setMethods(f));return this.telemetryEnabled&&(this.events.set(f,b),this.shouldPersist=!0),b}),ct(this,"getEvent",n=>{const{eventId:s,topic:o}=n;if(s)return this.events.get(s);const a=Array.from(this.events.values()).find(c=>c.props.properties.topic===o);if(a)return bs(bs({},a),this.setMethods(a.eventId))}),ct(this,"deleteEvent",n=>{const{eventId:s}=n;this.events.delete(s),this.shouldPersist=!0}),ct(this,"setEventListeners",()=>{this.core.heartbeat.on(Fi.pulse,async()=>{this.shouldPersist&&await this.persist(),this.events.forEach(n=>{z.fromMiliseconds(Date.now())-z.fromMiliseconds(n.timestamp)>ox&&(this.events.delete(n.eventId),this.shouldPersist=!0)})})}),ct(this,"setMethods",n=>({addTrace:s=>this.addTrace(n,s),setError:s=>this.setError(n,s)})),ct(this,"addTrace",(n,s)=>{const o=this.events.get(n);o&&(o.props.properties.trace.push(s),this.events.set(n,o),this.shouldPersist=!0)}),ct(this,"setError",(n,s)=>{const o=this.events.get(n);o&&(o.props.type=s,o.timestamp=Date.now(),this.events.set(n,o),this.shouldPersist=!0)}),ct(this,"persist",async()=>{await this.core.storage.setItem(this.storageKey,Array.from(this.events.values())),this.shouldPersist=!1}),ct(this,"restore",async()=>{try{const n=await this.core.storage.getItem(this.storageKey)||[];if(!n.length)return;n.forEach(s=>{this.events.set(s.eventId,bs(bs({},s),this.setMethods(s.eventId)))})}catch(n){this.logger.warn(n)}}),ct(this,"submit",async()=>{if(!this.telemetryEnabled||this.events.size===0)return;const n=[];for(const[s,o]of this.events)o.props.type&&n.push(o);if(n.length!==0)try{if((await this.sendEvent(n)).ok)for(const s of n)this.events.delete(s.eventId),this.shouldPersist=!0}catch(s){this.logger.warn(s)}}),ct(this,"sendEvent",async n=>{const s=this.getAppDomain()?"":"&sp=desktop";return await fetch(`${ax}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${Xc}${s}`,{method:"POST",body:JSON.stringify(n)})}),ct(this,"getAppDomain",()=>Bl().url),this.logger=It(r,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 sI=Object.defineProperty,zp=Object.getOwnPropertySymbols,oI=Object.prototype.hasOwnProperty,aI=Object.prototype.propertyIsEnumerable,df=(t,e,r)=>e in t?sI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Up=(t,e)=>{for(var r in e||(e={}))oI.call(e,r)&&df(t,r,e[r]);if(zp)for(var r of zp(e))aI.call(e,r)&&df(t,r,e[r]);return t},le=(t,e,r)=>df(t,typeof e!="symbol"?e+"":e,r);class lf extends sg{constructor(e){var r;super(e),le(this,"protocol",np),le(this,"version",sp),le(this,"name",Mo),le(this,"relayUrl"),le(this,"projectId"),le(this,"customStoragePrefix"),le(this,"events",new mt.exports.EventEmitter),le(this,"logger"),le(this,"heartbeat"),le(this,"relayer"),le(this,"crypto"),le(this,"storage"),le(this,"history"),le(this,"expirer"),le(this,"pairing"),le(this,"verify"),le(this,"echoClient"),le(this,"linkModeSupportedApps"),le(this,"eventClient"),le(this,"initialized",!1),le(this,"logChunkController"),le(this,"on",(o,a)=>this.events.on(o,a)),le(this,"once",(o,a)=>this.events.once(o,a)),le(this,"off",(o,a)=>this.events.off(o,a)),le(this,"removeListener",(o,a)=>this.events.removeListener(o,a)),le(this,"dispatchEnvelope",({topic:o,message:a,sessionExists:c})=>{if(!o||!a)return;const f={topic:o,message:a,publishedAt:Date.now(),transportType:pe.link_mode};this.relayer.onLinkMessageEvent(f,{sessionExists:c})}),this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||fp,this.customStoragePrefix=e!=null&&e.customStoragePrefix?`:${e.customStoragePrefix}`:"";const i=ea({level:typeof e?.logger=="string"&&e.logger?e.logger:O_.logger,name:Mo}),{logger:n,chunkLoggerController:s}=rg({opts:i,maxSizeInBytes:e?.maxLogBlobSizeInBytes,loggerOverride:e?.logger});this.logChunkController=s,(r=this.logChunkController)!=null&&r.downloadLogsBlobInBrowser&&(window.downloadLogsBlobInBrowser=async()=>{var o,a;(o=this.logChunkController)!=null&&o.downloadLogsBlobInBrowser&&((a=this.logChunkController)==null||a.downloadLogsBlobInBrowser({clientId:await this.crypto.getClientId()}))}),this.logger=It(n,this.name),this.heartbeat=new Wo,this.crypto=new CE(this,this.logger,e?.keychain),this.history=new KS(this,this.logger),this.expirer=new GS(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new Db(Up(Up({},M_),e?.storageOptions)),this.relayer=new cS({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new US(this,this.logger),this.verify=new JS(this,this.logger,this.storage),this.echoClient=new eI(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new nI(this,this.logger,e?.telemetryEnabled)}static async init(e){const r=new lf(e);await r.initialize();const i=await r.crypto.getClientId();return await r.storage.setItem(j_,i),r}get context(){return Mt(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(up,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.linkModeSupportedApps=await this.storage.getItem(up)||[],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 pf=lf,jp="wc",Vp=2,Kp="client",bf=`${jp}@${Vp}:${Kp}:`,gf={name:Kp,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.org"},Hp="WALLETCONNECT_DEEPLINK_CHOICE",cI="proposal",Wp="Proposal expired",fI="session",xn=z.SEVEN_DAYS,uI="engine",ft={wc_sessionPropose:{req:{ttl:z.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1101},reject:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1120},autoReject:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1121}},wc_sessionSettle:{req:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:z.ONE_DAY,prompt:!1,tag:1104},res:{ttl:z.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:z.ONE_DAY,prompt:!1,tag:1106},res:{ttl:z.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:z.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:z.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:z.ONE_DAY,prompt:!1,tag:1112},res:{ttl:z.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:z.ONE_DAY,prompt:!1,tag:1114},res:{ttl:z.ONE_DAY,prompt:!1,tag:1115}},wc_sessionAuthenticate:{req:{ttl:z.ONE_HOUR,prompt:!0,tag:1116},res:{ttl:z.ONE_HOUR,prompt:!1,tag:1117},reject:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1118},autoReject:{ttl:z.FIVE_MINUTES,prompt:!1,tag:1119}}},yf={min:z.FIVE_MINUTES,max:z.SEVEN_DAYS},$r={idle:"IDLE",active:"ACTIVE"},Gp={eth_sendTransaction:{key:""},eth_sendRawTransaction:{key:""},wallet_sendCalls:{key:""},solana_signTransaction:{key:"signature"},solana_signAllTransactions:{key:"transactions"},solana_signAndSendTransaction:{key:"signature"}},hI="request",dI=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],lI="wc",pI="auth",bI="authKeys",gI="pairingTopics",yI="requests",No=`${lI}@${1.5}:${pI}:`,Co=`${No}:PUB_KEY`;var vI=Object.defineProperty,mI=Object.defineProperties,wI=Object.getOwnPropertyDescriptors,Yp=Object.getOwnPropertySymbols,_I=Object.prototype.hasOwnProperty,xI=Object.prototype.propertyIsEnumerable,vf=(t,e,r)=>e in t?vI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ce=(t,e)=>{for(var r in e||(e={}))_I.call(e,r)&&vf(t,r,e[r]);if(Yp)for(var r of Yp(e))xI.call(e,r)&&vf(t,r,e[r]);return t},Dt=(t,e)=>mI(t,wI(e)),k=(t,e,r)=>vf(t,typeof e!="symbol"?e+"":e,r);class EI extends xg{constructor(e){super(e),k(this,"name",uI),k(this,"events",new mt.exports),k(this,"initialized",!1),k(this,"requestQueue",{state:$r.idle,queue:[]}),k(this,"sessionRequestQueue",{state:$r.idle,queue:[]}),k(this,"requestQueueDelay",z.ONE_SECOND),k(this,"expectedPairingMethodMap",new Map),k(this,"recentlyDeletedMap",new Map),k(this,"recentlyDeletedLimit",200),k(this,"relayMessageCache",[]),k(this,"pendingSessions",new Map),k(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(ft)}),this.initialized=!0,setTimeout(async()=>{await this.processPendingMessageEvents(),this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()},z.toMiliseconds(this.requestQueueDelay)))}),k(this,"connect",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();const i=Dt(ce({},r),{requiredNamespaces:r.requiredNamespaces||{},optionalNamespaces:r.optionalNamespaces||{}});await this.isValidConnect(i);const{pairingTopic:n,requiredNamespaces:s,optionalNamespaces:o,sessionProperties:a,scopedProperties:c,relays:f}=i;let u=n,d,b=!1;try{if(u){const N=this.client.core.pairing.pairings.get(u);this.client.logger.warn("connect() with existing pairing topic is deprecated and will be removed in the next major release."),b=N.active}}catch(N){throw this.client.logger.error(`connect() -> pairing.get(${u}) failed`),N}if(!u||!b){const{topic:N,uri:C}=await this.client.core.pairing.create();u=N,d=C}if(!u){const{message:N}=U("NO_MATCHING_KEY",`connect() pairing topic: ${u}`);throw new Error(N)}const v=await this.client.core.crypto.generateKeyPair(),g=ft.wc_sessionPropose.req.ttl||z.FIVE_MINUTES,x=Qe(g),I=Dt(ce(ce({requiredNamespaces:s,optionalNamespaces:o,relays:f??[{protocol:cp}],proposer:{publicKey:v,metadata:this.client.metadata},expiryTimestamp:x,pairingTopic:u},a&&{sessionProperties:a}),c&&{scopedProperties:c}),{id:xr()}),D=ne("session_connect",I.id),{reject:O,resolve:M,done:P}=Ai(g,Wp),T=({id:N})=>{N===I.id&&(this.client.events.off("proposal_expire",T),this.pendingSessions.delete(I.id),this.events.emit(D,{error:{message:Wp,code:0}}))};return this.client.events.on("proposal_expire",T),this.events.once(D,({error:N,session:C})=>{this.client.events.off("proposal_expire",T),N?O(N):C&&M(C)}),await this.sendRequest({topic:u,method:"wc_sessionPropose",params:I,throwOnFailedPublish:!0,clientRpcId:I.id}),await this.setProposal(I.id,I),{uri:d,approval:P}}),k(this,"pair",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{return await this.client.core.pairing.pair(r)}catch(i){throw this.client.logger.error("pair() failed"),i}}),k(this,"approve",async r=>{var i,n,s;const o=this.client.core.eventClient.createEvent({properties:{topic:(i=r?.id)==null?void 0:i.toString(),trace:[nr.session_approve_started]}});try{this.isInitialized(),await this.confirmOnlineStateOrThrow()}catch(R){throw o.setError(Ri.no_internet_connection),R}try{await this.isValidProposalId(r?.id)}catch(R){throw this.client.logger.error(`approve() -> proposal.get(${r?.id}) failed`),o.setError(Ri.proposal_not_found),R}try{await this.isValidApprove(r)}catch(R){throw this.client.logger.error("approve() -> isValidApprove() failed"),o.setError(Ri.session_approve_namespace_validation_failure),R}const{id:a,relayProtocol:c,namespaces:f,sessionProperties:u,scopedProperties:d,sessionConfig:b}=r,v=this.client.proposal.get(a);this.client.core.eventClient.deleteEvent({eventId:o.eventId});const{pairingTopic:g,proposer:x,requiredNamespaces:I,optionalNamespaces:D}=v;let O=(n=this.client.core.eventClient)==null?void 0:n.getEvent({topic:g});O||(O=(s=this.client.core.eventClient)==null?void 0:s.createEvent({type:nr.session_approve_started,properties:{topic:g,trace:[nr.session_approve_started,nr.session_namespaces_validation_success]}}));const M=await this.client.core.crypto.generateKeyPair(),P=x.publicKey,T=await this.client.core.crypto.generateSharedKey(M,P),N=ce(ce(ce({relay:{protocol:c??"irn"},namespaces:f,controller:{publicKey:M,metadata:this.client.metadata},expiry:Qe(xn)},u&&{sessionProperties:u}),d&&{scopedProperties:d}),b&&{sessionConfig:b}),C=pe.relay;O.addTrace(nr.subscribing_session_topic);try{await this.client.core.relayer.subscribe(T,{transportType:C})}catch(R){throw O.setError(Ri.subscribe_session_topic_failure),R}O.addTrace(nr.subscribe_session_topic_success);const B=Dt(ce({},N),{topic:T,requiredNamespaces:I,optionalNamespaces:D,pairingTopic:g,acknowledged:!1,self:N.controller,peer:{publicKey:x.publicKey,metadata:x.metadata},controller:M,transportType:pe.relay});await this.client.session.set(T,B),O.addTrace(nr.store_session);try{O.addTrace(nr.publishing_session_settle),await this.sendRequest({topic:T,method:"wc_sessionSettle",params:N,throwOnFailedPublish:!0}).catch(R=>{throw O?.setError(Ri.session_settle_publish_failure),R}),O.addTrace(nr.session_settle_publish_success),O.addTrace(nr.publishing_session_approve),await this.sendResult({id:a,topic:g,result:{relay:{protocol:c??"irn"},responderPublicKey:M},throwOnFailedPublish:!0}).catch(R=>{throw O?.setError(Ri.session_approve_publish_failure),R}),O.addTrace(nr.session_approve_publish_success)}catch(R){throw this.client.logger.error(R),this.client.session.delete(T,de("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe(T),R}return this.client.core.eventClient.deleteEvent({eventId:O.eventId}),await this.client.core.pairing.updateMetadata({topic:g,metadata:x.metadata}),await this.client.proposal.delete(a,de("USER_DISCONNECTED")),await this.client.core.pairing.activate({topic:g}),await this.setExpiry(T,Qe(xn)),{topic:T,acknowledged:()=>Promise.resolve(this.client.session.get(T))}}),k(this,"reject",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidReject(r)}catch(o){throw this.client.logger.error("reject() -> isValidReject() failed"),o}const{id:i,reason:n}=r;let s;try{s=this.client.proposal.get(i).pairingTopic}catch(o){throw this.client.logger.error(`reject() -> proposal.get(${i}) failed`),o}s&&(await this.sendError({id:i,topic:s,error:n,rpcOpts:ft.wc_sessionPropose.reject}),await this.client.proposal.delete(i,de("USER_DISCONNECTED")))}),k(this,"update",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidUpdate(r)}catch(d){throw this.client.logger.error("update() -> isValidUpdate() failed"),d}const{topic:i,namespaces:n}=r,{done:s,resolve:o,reject:a}=Ai(),c=xr(),f=Oi().toString(),u=this.client.session.get(i).namespaces;return this.events.once(ne("session_update",c),({error:d})=>{d?a(d):o()}),await this.client.session.update(i,{namespaces:n}),await this.sendRequest({topic:i,method:"wc_sessionUpdate",params:{namespaces:n},throwOnFailedPublish:!0,clientRpcId:c,relayRpcId:f}).catch(d=>{this.client.logger.error(d),this.client.session.update(i,{namespaces:u}),a(d)}),{acknowledged:s}}),k(this,"extend",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidExtend(r)}catch(c){throw this.client.logger.error("extend() -> isValidExtend() failed"),c}const{topic:i}=r,n=xr(),{done:s,resolve:o,reject:a}=Ai();return this.events.once(ne("session_extend",n),({error:c})=>{c?a(c):o()}),await this.setExpiry(i,Qe(xn)),this.sendRequest({topic:i,method:"wc_sessionExtend",params:{},clientRpcId:n,throwOnFailedPublish:!0}).catch(c=>{a(c)}),{acknowledged:s}}),k(this,"request",async r=>{this.isInitialized();try{await this.isValidRequest(r)}catch(D){throw this.client.logger.error("request() -> isValidRequest() failed"),D}const{chainId:i,request:n,topic:s,expiry:o=ft.wc_sessionRequest.req.ttl}=r,a=this.client.session.get(s);a?.transportType===pe.relay&&await this.confirmOnlineStateOrThrow();const c=xr(),f=Oi().toString(),{done:u,resolve:d,reject:b}=Ai(o,"Request expired. Please try again.");this.events.once(ne("session_request",c),({error:D,result:O})=>{D?b(D):d(O)});const v="wc_sessionRequest",g=this.getAppLinkIfEnabled(a.peer.metadata,a.transportType);if(g)return await this.sendRequest({clientRpcId:c,relayRpcId:f,topic:s,method:v,params:{request:Dt(ce({},n),{expiryTimestamp:Qe(o)}),chainId:i},expiry:o,throwOnFailedPublish:!0,appLink:g}).catch(D=>b(D)),this.client.events.emit("session_request_sent",{topic:s,request:n,chainId:i,id:c}),await u();const x={request:Dt(ce({},n),{expiryTimestamp:Qe(o)}),chainId:i},I=this.shouldSetTVF(v,x);return await Promise.all([new Promise(async D=>{await this.sendRequest(ce({clientRpcId:c,relayRpcId:f,topic:s,method:v,params:x,expiry:o,throwOnFailedPublish:!0},I&&{tvf:this.getTVFParams(c,x)})).catch(O=>b(O)),this.client.events.emit("session_request_sent",{topic:s,request:n,chainId:i,id:c}),D()}),new Promise(async D=>{var O;if(!((O=a.sessionConfig)!=null&&O.disableDeepLink)){const M=await e5(this.client.core.storage,Hp);await J4({id:c,topic:s,wcDeepLink:M})}D()}),u()]).then(D=>D[2])}),k(this,"respond",async r=>{this.isInitialized(),await this.isValidRespond(r);const{topic:i,response:n}=r,{id:s}=n,o=this.client.session.get(i);o.transportType===pe.relay&&await this.confirmOnlineStateOrThrow();const a=this.getAppLinkIfEnabled(o.peer.metadata,o.transportType);Er(n)?await this.sendResult({id:s,topic:i,result:n.result,throwOnFailedPublish:!0,appLink:a}):Wt(n)&&await this.sendError({id:s,topic:i,error:n.error,appLink:a}),this.cleanupAfterResponse(r)}),k(this,"ping",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidPing(r)}catch(n){throw this.client.logger.error("ping() -> isValidPing() failed"),n}const{topic:i}=r;if(this.client.session.keys.includes(i)){const n=xr(),s=Oi().toString(),{done:o,resolve:a,reject:c}=Ai();this.events.once(ne("session_ping",n),({error:f})=>{f?c(f):a()}),await Promise.all([this.sendRequest({topic:i,method:"wc_sessionPing",params:{},throwOnFailedPublish:!0,clientRpcId:n,relayRpcId:s}),o()])}else this.client.core.pairing.pairings.keys.includes(i)&&(this.client.logger.warn("ping() on pairing topic is deprecated and will be removed in the next major release."),await this.client.core.pairing.ping({topic:i}))}),k(this,"emit",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidEmit(r);const{topic:i,event:n,chainId:s}=r,o=Oi().toString(),a=xr();await this.sendRequest({topic:i,method:"wc_sessionEvent",params:{event:n,chainId:s},throwOnFailedPublish:!0,relayRpcId:o,clientRpcId:a})}),k(this,"disconnect",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidDisconnect(r);const{topic:i}=r;if(this.client.session.keys.includes(i))await this.sendRequest({topic:i,method:"wc_sessionDelete",params:de("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}=U("MISMATCHED_TOPIC",`Session or pairing topic not found: ${i}`);throw new Error(n)}}),k(this,"find",r=>(this.isInitialized(),this.client.session.getAll().filter(i=>u7(i,r)))),k(this,"getPendingSessionRequests",()=>this.client.pendingRequest.getAll()),k(this,"authenticate",async(r,i)=>{var n;this.isInitialized(),this.isValidAuthenticate(r);const s=i&&this.client.core.linkModeSupportedApps.includes(i)&&((n=this.client.metadata.redirect)==null?void 0:n.linkMode),o=s?pe.link_mode:pe.relay;o===pe.relay&&await this.confirmOnlineStateOrThrow();const{chains:a,statement:c="",uri:f,domain:u,nonce:d,type:b,exp:v,nbf:g,methods:x=[],expiry:I}=r,D=[...r.resources||[]],{topic:O,uri:M}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:o});this.client.logger.info({message:"Generated new pairing",pairing:{topic:O,uri:M}});const P=await this.client.core.crypto.generateKeyPair(),T=So(P);if(await Promise.all([this.client.auth.authKeys.set(Co,{responseTopic:T,publicKey:P}),this.client.auth.pairingTopics.set(T,{topic:T,pairingTopic:O})]),await this.client.core.relayer.subscribe(T,{transportType:o}),this.client.logger.info(`sending request to new pairing topic: ${O}`),x.length>0){const{namespace:_}=bo(a[0]);let l=V5(_,"request",x);wo(D)&&(l=H5(l,D.pop())),D.push(l)}const N=I&&I>ft.wc_sessionAuthenticate.req.ttl?I:ft.wc_sessionAuthenticate.req.ttl,C={authPayload:{type:b??"caip122",chains:a,statement:c,aud:f,domain:u,version:"1",nonce:d,iat:new Date().toISOString(),exp:v,nbf:g,resources:D},requester:{publicKey:P,metadata:this.client.metadata},expiryTimestamp:Qe(N)},B={eip155:{chains:a,methods:[...new Set(["personal_sign",...x])],events:["chainChanged","accountsChanged"]}},R={requiredNamespaces:{},optionalNamespaces:B,relays:[{protocol:"irn"}],pairingTopic:O,proposer:{publicKey:P,metadata:this.client.metadata},expiryTimestamp:Qe(ft.wc_sessionPropose.req.ttl),id:xr()},{done:V,resolve:A,reject:h}=Ai(N,"Request expired"),p=xr(),m=ne("session_connect",R.id),y=ne("session_request",p),w=async({error:_,session:l})=>{this.events.off(y,S),_?h(_):l&&A({session:l})},S=async _=>{var l,E,F;if(await this.deletePendingAuthRequest(p,{message:"fulfilled",code:0}),_.error){const H=de("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return _.error.code===H.code?void 0:(this.events.off(m,w),h(_.error.message))}await this.deleteProposal(R.id),this.events.off(m,w);const{cacaos:L,responder:q}=_.result,j=[],K=[];for(const H of L){await r0({cacao:H,projectId:this.client.core.projectId})||(this.client.logger.error(H,"Signature verification failed"),h(de("SESSION_SETTLEMENT_FAILED","Signature verification failed")));const{p:G}=H,Me=wo(G.resources),X=[Dc(G.iss)],ie=mo(G.iss);if(Me){const St=s0(Me),fe=o0(Me);j.push(...St),X.push(...fe)}for(const St of X)K.push(`${St}:${ie}`)}const W=await this.client.core.crypto.generateSharedKey(P,q.publicKey);let Z;j.length>0&&(Z={topic:W,acknowledged:!0,self:{publicKey:P,metadata:this.client.metadata},peer:q,controller:q.publicKey,expiry:Qe(xn),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:O,namespaces:q0([...new Set(j)],[...new Set(K)]),transportType:o},await this.client.core.relayer.subscribe(W,{transportType:o}),await this.client.session.set(W,Z),O&&await this.client.core.pairing.updateMetadata({topic:O,metadata:q.metadata}),Z=this.client.session.get(W)),(l=this.client.metadata.redirect)!=null&&l.linkMode&&(E=q.metadata.redirect)!=null&&E.linkMode&&(F=q.metadata.redirect)!=null&&F.universal&&i&&(this.client.core.addLinkModeSupportedApp(q.metadata.redirect.universal),this.client.session.update(W,{transportType:pe.link_mode})),A({auths:L,session:Z})};this.events.once(m,w),this.events.once(y,S);let $;try{if(s){const _=Mi("wc_sessionAuthenticate",C,p);this.client.core.history.set(O,_);const l=await this.client.core.crypto.encode("",_,{type:es,encoding:Xn});$=Ao(i,O,l)}else await Promise.all([this.sendRequest({topic:O,method:"wc_sessionAuthenticate",params:C,expiry:r.expiry,throwOnFailedPublish:!0,clientRpcId:p}),this.sendRequest({topic:O,method:"wc_sessionPropose",params:R,expiry:ft.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:R.id})])}catch(_){throw this.events.off(m,w),this.events.off(y,S),_}return await this.setProposal(R.id,R),await this.setAuthRequest(p,{request:Dt(ce({},C),{verifyContext:{}}),pairingTopic:O,transportType:o}),{uri:$??M,response:V}}),k(this,"approveSessionAuthenticate",async r=>{const{id:i,auths:n}=r,s=this.client.core.eventClient.createEvent({properties:{topic:i.toString(),trace:[Ti.authenticated_session_approve_started]}});try{this.isInitialized()}catch(I){throw s.setError(us.no_internet_connection),I}const o=this.getPendingAuthRequest(i);if(!o)throw s.setError(us.authenticated_session_pending_request_not_found),new Error(`Could not find pending auth request with id ${i}`);const a=o.transportType||pe.relay;a===pe.relay&&await this.confirmOnlineStateOrThrow();const c=o.requester.publicKey,f=await this.client.core.crypto.generateKeyPair(),u=So(c),d={type:qr,receiverPublicKey:c,senderPublicKey:f},b=[],v=[];for(const I of n){if(!await r0({cacao:I,projectId:this.client.core.projectId})){s.setError(us.invalid_cacao);const T=de("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:i,topic:u,error:T,encodeOpts:d}),new Error(T.message)}s.addTrace(Ti.cacaos_verified);const{p:D}=I,O=wo(D.resources),M=[Dc(D.iss)],P=mo(D.iss);if(O){const T=s0(O),N=o0(O);b.push(...T),M.push(...N)}for(const T of M)v.push(`${T}:${P}`)}const g=await this.client.core.crypto.generateSharedKey(f,c);s.addTrace(Ti.create_authenticated_session_topic);let x;if(b?.length>0){x={topic:g,acknowledged:!0,self:{publicKey:f,metadata:this.client.metadata},peer:{publicKey:c,metadata:o.requester.metadata},controller:c,expiry:Qe(xn),authentication:n,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:o.pairingTopic,namespaces:q0([...new Set(b)],[...new Set(v)]),transportType:a},s.addTrace(Ti.subscribing_authenticated_session_topic);try{await this.client.core.relayer.subscribe(g,{transportType:a})}catch(I){throw s.setError(us.subscribe_authenticated_session_topic_failure),I}s.addTrace(Ti.subscribe_authenticated_session_topic_success),await this.client.session.set(g,x),s.addTrace(Ti.store_authenticated_session),await this.client.core.pairing.updateMetadata({topic:o.pairingTopic,metadata:o.requester.metadata})}s.addTrace(Ti.publishing_authenticated_session_approve);try{await this.sendResult({topic:u,id:i,result:{cacaos:n,responder:{publicKey:f,metadata:this.client.metadata}},encodeOpts:d,throwOnFailedPublish:!0,appLink:this.getAppLinkIfEnabled(o.requester.metadata,a)})}catch(I){throw s.setError(us.authenticated_session_approve_publish_failure),I}return await this.client.auth.requests.delete(i,{message:"fulfilled",code:0}),await this.client.core.pairing.activate({topic:o.pairingTopic}),this.client.core.eventClient.deleteEvent({eventId:s.eventId}),{session:x}}),k(this,"rejectSessionAuthenticate",async r=>{this.isInitialized();const{id:i,reason:n}=r,s=this.getPendingAuthRequest(i);if(!s)throw new Error(`Could not find pending auth request with id ${i}`);s.transportType===pe.relay&&await this.confirmOnlineStateOrThrow();const o=s.requester.publicKey,a=await this.client.core.crypto.generateKeyPair(),c=So(o),f={type:qr,receiverPublicKey:o,senderPublicKey:a};await this.sendError({id:i,topic:c,error:n,encodeOpts:f,rpcOpts:ft.wc_sessionAuthenticate.reject,appLink:this.getAppLinkIfEnabled(s.requester.metadata,s.transportType)}),await this.client.auth.requests.delete(i,{message:"rejected",code:0}),await this.client.proposal.delete(i,de("USER_DISCONNECTED"))}),k(this,"formatAuthMessage",r=>{this.isInitialized();const{request:i,iss:n}=r;return i0(i,n)}),k(this,"processRelayMessageCache",()=>{setTimeout(async()=>{if(this.relayMessageCache.length!==0)for(;this.relayMessageCache.length>0;)try{const r=this.relayMessageCache.shift();r&&await this.onRelayMessage(r)}catch(r){this.client.logger.error(r)}},50)}),k(this,"cleanupDuplicatePairings",async r=>{if(r.pairingTopic)try{const i=this.client.core.pairing.pairings.get(r.pairingTopic),n=this.client.core.pairing.pairings.getAll().filter(s=>{var o,a;return((o=s.peerMetadata)==null?void 0:o.url)&&((a=s.peerMetadata)==null?void 0:a.url)===r.peer.metadata.url&&s.topic&&s.topic!==i.topic});if(n.length===0)return;this.client.logger.info(`Cleaning up ${n.length} duplicate pairing(s)`),await Promise.all(n.map(s=>this.client.core.pairing.disconnect({topic:s.topic}))),this.client.logger.info("Duplicate pairings clean up finished")}catch(i){this.client.logger.error(i)}}),k(this,"deleteSession",async r=>{var i;const{topic:n,expirerHasDeleted:s=!1,emitEvent:o=!0,id:a=0}=r,{self:c}=this.client.session.get(n);await this.client.core.relayer.unsubscribe(n),await this.client.session.delete(n,de("USER_DISCONNECTED")),this.addToRecentlyDeleted(n,"session"),this.client.core.crypto.keychain.has(c.publicKey)&&await this.client.core.crypto.deleteKeyPair(c.publicKey),this.client.core.crypto.keychain.has(n)&&await this.client.core.crypto.deleteSymKey(n),s||this.client.core.expirer.del(n),this.client.core.storage.removeItem(Hp).catch(f=>this.client.logger.warn(f)),this.getPendingSessionRequests().forEach(f=>{f.topic===n&&this.deletePendingSessionRequest(f.id,de("USER_DISCONNECTED"))}),n===((i=this.sessionRequestQueue.queue[0])==null?void 0:i.topic)&&(this.sessionRequestQueue.state=$r.idle),o&&this.client.events.emit("session_delete",{id:a,topic:n})}),k(this,"deleteProposal",async(r,i)=>{if(i)try{const n=this.client.proposal.get(r);this.client.core.eventClient.getEvent({topic:n.pairingTopic})?.setError(Ri.proposal_expired)}catch{}await Promise.all([this.client.proposal.delete(r,de("USER_DISCONNECTED")),i?Promise.resolve():this.client.core.expirer.del(r)]),this.addToRecentlyDeleted(r,"proposal")}),k(this,"deletePendingSessionRequest",async(r,i,n=!1)=>{await Promise.all([this.client.pendingRequest.delete(r,i),n?Promise.resolve():this.client.core.expirer.del(r)]),this.addToRecentlyDeleted(r,"request"),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter(s=>s.id!==r),n&&(this.sessionRequestQueue.state=$r.idle,this.client.events.emit("session_request_expire",{id:r}))}),k(this,"deletePendingAuthRequest",async(r,i,n=!1)=>{await Promise.all([this.client.auth.requests.delete(r,i),n?Promise.resolve():this.client.core.expirer.del(r)])}),k(this,"setExpiry",async(r,i)=>{this.client.session.keys.includes(r)&&(this.client.core.expirer.set(r,i),await this.client.session.update(r,{expiry:i}))}),k(this,"setProposal",async(r,i)=>{this.client.core.expirer.set(r,Qe(ft.wc_sessionPropose.req.ttl)),await this.client.proposal.set(r,i)}),k(this,"setAuthRequest",async(r,i)=>{const{request:n,pairingTopic:s,transportType:o=pe.relay}=i;this.client.core.expirer.set(r,n.expiryTimestamp),await this.client.auth.requests.set(r,{authPayload:n.authPayload,requester:n.requester,expiryTimestamp:n.expiryTimestamp,id:r,pairingTopic:s,verifyContext:n.verifyContext,transportType:o})}),k(this,"setPendingSessionRequest",async r=>{const{id:i,topic:n,params:s,verifyContext:o}=r,a=s.request.expiryTimestamp||Qe(ft.wc_sessionRequest.req.ttl);this.client.core.expirer.set(i,a),await this.client.pendingRequest.set(i,{id:i,topic:n,params:s,verifyContext:o})}),k(this,"sendRequest",async r=>{const{topic:i,method:n,params:s,expiry:o,relayRpcId:a,clientRpcId:c,throwOnFailedPublish:f,appLink:u,tvf:d}=r,b=Mi(n,s,c);let v;const g=!!u;try{const D=g?Xn:ci;v=await this.client.core.crypto.encode(i,b,{encoding:D})}catch(D){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${i} failed`),D}let x;if(dI.includes(n)){const D=_r(JSON.stringify(b)),O=_r(v);x=await this.client.core.verify.register({id:O,decryptedId:D})}const I=ft[n].req;if(I.attestation=x,o&&(I.ttl=o),a&&(I.id=a),this.client.core.history.set(i,b),g){const D=Ao(u,i,v);await global.Linking.openURL(D,this.client.name)}else{const D=ft[n].req;o&&(D.ttl=o),a&&(D.id=a),D.tvf=Dt(ce({},d),{correlationId:b.id}),f?(D.internal=Dt(ce({},D.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(i,v,D)):this.client.core.relayer.publish(i,v,D).catch(O=>this.client.logger.error(O))}return b.id}),k(this,"sendResult",async r=>{const{id:i,topic:n,result:s,throwOnFailedPublish:o,encodeOpts:a,appLink:c}=r,f=Yc(i,s);let u;const d=c&&typeof(global==null?void 0:global.Linking)<"u";try{const g=d?Xn:ci;u=await this.client.core.crypto.encode(n,f,Dt(ce({},a||{}),{encoding:g}))}catch(g){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${n} failed`),g}let b,v;try{b=await this.client.core.history.get(n,i);const g=b.request;try{this.shouldSetTVF(g.method,g.params)&&(v=this.getTVFParams(i,g.params,s))}catch(x){this.client.logger.warn("sendResult() -> getTVFParams() failed",x)}}catch(g){throw this.client.logger.error(`sendResult() -> history.get(${n}, ${i}) failed`),g}if(d){const g=Ao(c,n,u);await global.Linking.openURL(g,this.client.name)}else{const g=b.request.method,x=ft[g].res;x.tvf=Dt(ce({},v),{correlationId:i}),o?(x.internal=Dt(ce({},x.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(n,u,x)):this.client.core.relayer.publish(n,u,x).catch(I=>this.client.logger.error(I))}await this.client.core.history.resolve(f)}),k(this,"sendError",async r=>{const{id:i,topic:n,error:s,encodeOpts:o,rpcOpts:a,appLink:c}=r,f=Zc(i,s);let u;const d=c&&typeof(global==null?void 0:global.Linking)<"u";try{const v=d?Xn:ci;u=await this.client.core.crypto.encode(n,f,Dt(ce({},o||{}),{encoding:v}))}catch(v){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${n} failed`),v}let b;try{b=await this.client.core.history.get(n,i)}catch(v){throw this.client.logger.error(`sendError() -> history.get(${n}, ${i}) failed`),v}if(d){const v=Ao(c,n,u);await global.Linking.openURL(v,this.client.name)}else{const v=b.request.method,g=a||ft[v].res;this.client.core.relayer.publish(n,u,g)}await this.client.core.history.resolve(f)}),k(this,"cleanup",async()=>{const r=[],i=[];this.client.session.getAll().forEach(n=>{let s=!1;ni(n.expiry)&&(s=!0),this.client.core.crypto.keychain.has(n.topic)||(s=!0),s&&r.push(n.topic)}),this.client.proposal.getAll().forEach(n=>{ni(n.expiryTimestamp)&&i.push(n.id)}),await Promise.all([...r.map(n=>this.deleteSession({topic:n})),...i.map(n=>this.deleteProposal(n))])}),k(this,"onProviderMessageEvent",async r=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(r):await this.onRelayMessage(r)}),k(this,"onRelayEventRequest",async r=>{this.requestQueue.queue.push(r),await this.processRequestsQueue()}),k(this,"processRequestsQueue",async()=>{if(this.requestQueue.state===$r.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=$r.active;const r=this.requestQueue.queue.shift();if(r)try{await this.processRequest(r)}catch(i){this.client.logger.warn(i)}}this.requestQueue.state=$r.idle}),k(this,"processRequest",async r=>{const{topic:i,payload:n,attestation:s,transportType:o,encryptedId:a}=r,c=n.method;if(!this.shouldIgnorePairingRequest({topic:i,requestMethod:c}))switch(c){case"wc_sessionPropose":return await this.onSessionProposeRequest({topic:i,payload:n,attestation:s,encryptedId:a});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:s,encryptedId:a,transportType:o});case"wc_sessionEvent":return await this.onSessionEventRequest(i,n);case"wc_sessionAuthenticate":return await this.onSessionAuthenticateRequest({topic:i,payload:n,attestation:s,encryptedId:a,transportType:o});default:return this.client.logger.info(`Unsupported request method ${c}`)}}),k(this,"onRelayEventResponse",async r=>{const{topic:i,payload:n,transportType:s}=r,o=(await this.client.core.history.get(i,n.id)).request.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeResponse(i,n,s);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 ${o}`)}}),k(this,"onRelayEventUnknownPayload",r=>{const{topic:i}=r,{message:n}=U("MISSING_OR_INVALID",`Decoded payload on topic ${i} is not identifiable as a JSON-RPC request or a response.`);throw new Error(n)}),k(this,"shouldIgnorePairingRequest",r=>{const{topic:i,requestMethod:n}=r,s=this.expectedPairingMethodMap.get(i);return!s||s.includes(n)?!1:!!(s.includes("wc_sessionAuthenticate")&&this.client.events.listenerCount("session_authenticate")>0)}),k(this,"onSessionProposeRequest",async r=>{const{topic:i,payload:n,attestation:s,encryptedId:o}=r,{params:a,id:c}=n;try{const f=this.client.core.eventClient.getEvent({topic:i});this.client.events.listenerCount("session_proposal")===0&&(console.warn("No listener for session_proposal event"),f?.setError(Ur.proposal_listener_not_found)),this.isValidConnect(ce({},n.params));const u=a.expiryTimestamp||Qe(ft.wc_sessionPropose.req.ttl),d=ce({id:c,pairingTopic:i,expiryTimestamp:u},a);await this.setProposal(c,d);const b=await this.getVerifyContext({attestationId:s,hash:_r(JSON.stringify(n)),encryptedId:o,metadata:d.proposer.metadata});f?.addTrace(Ir.emit_session_proposal),this.client.events.emit("session_proposal",{id:c,params:d,verifyContext:b})}catch(f){await this.sendError({id:c,topic:i,error:f,rpcOpts:ft.wc_sessionPropose.autoReject}),this.client.logger.error(f)}}),k(this,"onSessionProposeResponse",async(r,i,n)=>{const{id:s}=i;if(Er(i)){const{result:o}=i;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:o});const a=this.client.proposal.get(s);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:a});const c=a.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:c});const f=o.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:f});const u=await this.client.core.crypto.generateSharedKey(c,f);this.pendingSessions.set(s,{sessionTopic:u,pairingTopic:r,proposalId:s,publicKey:c});const d=await this.client.core.relayer.subscribe(u,{transportType:n});this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:d}),await this.client.core.pairing.activate({topic:r})}else if(Wt(i)){await this.client.proposal.delete(s,de("USER_DISCONNECTED"));const o=ne("session_connect",s);if(this.events.listenerCount(o)===0)throw new Error(`emitting ${o} without any listeners, 954`);this.events.emit(o,{error:i.error})}}),k(this,"onSessionSettleRequest",async(r,i)=>{const{id:n,params:s}=i;try{this.isValidSessionSettleRequest(s);const{relay:o,controller:a,expiry:c,namespaces:f,sessionProperties:u,scopedProperties:d,sessionConfig:b}=i.params,v=[...this.pendingSessions.values()].find(I=>I.sessionTopic===r);if(!v)return this.client.logger.error(`Pending session not found for topic ${r}`);const g=this.client.proposal.get(v.proposalId),x=Dt(ce(ce(ce({topic:r,relay:o,expiry:c,namespaces:f,acknowledged:!0,pairingTopic:v.pairingTopic,requiredNamespaces:g.requiredNamespaces,optionalNamespaces:g.optionalNamespaces,controller:a.publicKey,self:{publicKey:v.publicKey,metadata:this.client.metadata},peer:{publicKey:a.publicKey,metadata:a.metadata}},u&&{sessionProperties:u}),d&&{scopedProperties:d}),b&&{sessionConfig:b}),{transportType:pe.relay});await this.client.session.set(x.topic,x),await this.setExpiry(x.topic,x.expiry),await this.client.core.pairing.updateMetadata({topic:v.pairingTopic,metadata:x.peer.metadata}),this.client.events.emit("session_connect",{session:x}),this.events.emit(ne("session_connect",v.proposalId),{session:x}),this.pendingSessions.delete(v.proposalId),this.deleteProposal(v.proposalId,!1),this.cleanupDuplicatePairings(x),await this.sendResult({id:i.id,topic:r,result:!0,throwOnFailedPublish:!0})}catch(o){await this.sendError({id:n,topic:r,error:o}),this.client.logger.error(o)}}),k(this,"onSessionSettleResponse",async(r,i)=>{const{id:n}=i;Er(i)?(await this.client.session.update(r,{acknowledged:!0}),this.events.emit(ne("session_approve",n),{})):Wt(i)&&(await this.client.session.delete(r,de("USER_DISCONNECTED")),this.events.emit(ne("session_approve",n),{error:i.error}))}),k(this,"onSessionUpdateRequest",async(r,i)=>{const{params:n,id:s}=i;try{const o=`${r}_session_update`,a=ss.get(o);if(a&&this.isRequestOutOfSync(a,s)){this.client.logger.warn(`Discarding out of sync request - ${s}`),this.sendError({id:s,topic:r,error:de("INVALID_UPDATE_REQUEST")});return}this.isValidUpdate(ce({topic:r},n));try{ss.set(o,s),await this.client.session.update(r,{namespaces:n.namespaces}),await this.sendResult({id:s,topic:r,result:!0,throwOnFailedPublish:!0})}catch(c){throw ss.delete(o),c}this.client.events.emit("session_update",{id:s,topic:r,params:n})}catch(o){await this.sendError({id:s,topic:r,error:o}),this.client.logger.error(o)}}),k(this,"isRequestOutOfSync",(r,i)=>i.toString().slice(0,-3)<r.toString().slice(0,-3)),k(this,"onSessionUpdateResponse",(r,i)=>{const{id:n}=i,s=ne("session_update",n);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);Er(i)?this.events.emit(ne("session_update",n),{}):Wt(i)&&this.events.emit(ne("session_update",n),{error:i.error})}),k(this,"onSessionExtendRequest",async(r,i)=>{const{id:n}=i;try{this.isValidExtend({topic:r}),await this.setExpiry(r,Qe(xn)),await this.sendResult({id:n,topic:r,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_extend",{id:n,topic:r})}catch(s){await this.sendError({id:n,topic:r,error:s}),this.client.logger.error(s)}}),k(this,"onSessionExtendResponse",(r,i)=>{const{id:n}=i,s=ne("session_extend",n);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);Er(i)?this.events.emit(ne("session_extend",n),{}):Wt(i)&&this.events.emit(ne("session_extend",n),{error:i.error})}),k(this,"onSessionPingRequest",async(r,i)=>{const{id:n}=i;try{this.isValidPing({topic:r}),await this.sendResult({id:n,topic:r,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_ping",{id:n,topic:r})}catch(s){await this.sendError({id:n,topic:r,error:s}),this.client.logger.error(s)}}),k(this,"onSessionPingResponse",(r,i)=>{const{id:n}=i,s=ne("session_ping",n);setTimeout(()=>{if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners 2176`);Er(i)?this.events.emit(ne("session_ping",n),{}):Wt(i)&&this.events.emit(ne("session_ping",n),{error:i.error})},500)}),k(this,"onSessionDeleteRequest",async(r,i)=>{const{id:n}=i;try{this.isValidDisconnect({topic:r,reason:i.params}),Promise.all([new Promise(s=>{this.client.core.relayer.once(at.publish,async()=>{s(await this.deleteSession({topic:r,id:n}))})}),this.sendResult({id:n,topic:r,result:!0,throwOnFailedPublish:!0}),this.cleanupPendingSentRequestsForTopic({topic:r,error:de("USER_DISCONNECTED")})]).catch(s=>this.client.logger.error(s))}catch(s){this.client.logger.error(s)}}),k(this,"onSessionRequest",async r=>{var i,n,s;const{topic:o,payload:a,attestation:c,encryptedId:f,transportType:u}=r,{id:d,params:b}=a;try{await this.isValidRequest(ce({topic:o},b));const v=this.client.session.get(o),g=await this.getVerifyContext({attestationId:c,hash:_r(JSON.stringify(Mi("wc_sessionRequest",b,d))),encryptedId:f,metadata:v.peer.metadata,transportType:u}),x={id:d,topic:o,params:b,verifyContext:g};await this.setPendingSessionRequest(x),u===pe.link_mode&&(i=v.peer.metadata.redirect)!=null&&i.universal&&this.client.core.addLinkModeSupportedApp((n=v.peer.metadata.redirect)==null?void 0:n.universal),(s=this.client.signConfig)!=null&&s.disableRequestQueue?this.emitSessionRequest(x):(this.addSessionRequestToSessionRequestQueue(x),this.processSessionRequestQueue())}catch(v){await this.sendError({id:d,topic:o,error:v}),this.client.logger.error(v)}}),k(this,"onSessionRequestResponse",(r,i)=>{const{id:n}=i,s=ne("session_request",n);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);Er(i)?this.events.emit(ne("session_request",n),{result:i.result}):Wt(i)&&this.events.emit(ne("session_request",n),{error:i.error})}),k(this,"onSessionEventRequest",async(r,i)=>{const{id:n,params:s}=i;try{const o=`${r}_session_event_${s.event.name}`,a=ss.get(o);if(a&&this.isRequestOutOfSync(a,n)){this.client.logger.info(`Discarding out of sync request - ${n}`);return}this.isValidEmit(ce({topic:r},s)),this.client.events.emit("session_event",{id:n,topic:r,params:s}),ss.set(o,n)}catch(o){await this.sendError({id:n,topic:r,error:o}),this.client.logger.error(o)}}),k(this,"onSessionAuthenticateResponse",(r,i)=>{const{id:n}=i;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:r,payload:i}),Er(i)?this.events.emit(ne("session_request",n),{result:i.result}):Wt(i)&&this.events.emit(ne("session_request",n),{error:i.error})}),k(this,"onSessionAuthenticateRequest",async r=>{var i;const{topic:n,payload:s,attestation:o,encryptedId:a,transportType:c}=r;try{const{requester:f,authPayload:u,expiryTimestamp:d}=s.params,b=await this.getVerifyContext({attestationId:o,hash:_r(JSON.stringify(s)),encryptedId:a,metadata:f.metadata,transportType:c}),v={requester:f,pairingTopic:n,id:s.id,authPayload:u,verifyContext:b,expiryTimestamp:d};await this.setAuthRequest(s.id,{request:v,pairingTopic:n,transportType:c}),c===pe.link_mode&&(i=f.metadata.redirect)!=null&&i.universal&&this.client.core.addLinkModeSupportedApp(f.metadata.redirect.universal),this.client.events.emit("session_authenticate",{topic:n,params:s.params,id:s.id,verifyContext:b})}catch(f){this.client.logger.error(f);const u=s.params.requester.publicKey,d=await this.client.core.crypto.generateKeyPair(),b=this.getAppLinkIfEnabled(s.params.requester.metadata,c),v={type:qr,receiverPublicKey:u,senderPublicKey:d};await this.sendError({id:s.id,topic:n,error:f,encodeOpts:v,rpcOpts:ft.wc_sessionAuthenticate.autoReject,appLink:b})}}),k(this,"addSessionRequestToSessionRequestQueue",r=>{this.sessionRequestQueue.queue.push(r)}),k(this,"cleanupAfterResponse",r=>{this.deletePendingSessionRequest(r.response.id,{message:"fulfilled",code:0}),setTimeout(()=>{this.sessionRequestQueue.state=$r.idle,this.processSessionRequestQueue()},z.toMiliseconds(this.requestQueueDelay))}),k(this,"cleanupPendingSentRequestsForTopic",({topic:r,error:i})=>{const n=this.client.core.history.pending;n.length>0&&n.filter(s=>s.topic===r&&s.request.method==="wc_sessionRequest").forEach(s=>{const o=s.request.id,a=ne("session_request",o);if(this.events.listenerCount(a)===0)throw new Error(`emitting ${a} without any listeners`);this.events.emit(ne("session_request",s.request.id),{error:i})})}),k(this,"processSessionRequestQueue",()=>{if(this.sessionRequestQueue.state===$r.active){this.client.logger.info("session request queue is already active.");return}const r=this.sessionRequestQueue.queue[0];if(!r){this.client.logger.info("session request queue is empty.");return}try{this.sessionRequestQueue.state=$r.active,this.emitSessionRequest(r)}catch(i){this.client.logger.error(i)}}),k(this,"emitSessionRequest",r=>{this.client.events.emit("session_request",r)}),k(this,"onPairingCreated",r=>{if(r.methods&&this.expectedPairingMethodMap.set(r.topic,r.methods),r.active)return;const i=this.client.proposal.getAll().find(n=>n.pairingTopic===r.topic);i&&this.onSessionProposeRequest({topic:r.topic,payload:Mi("wc_sessionPropose",Dt(ce({},i),{requiredNamespaces:i.requiredNamespaces,optionalNamespaces:i.optionalNamespaces,relays:i.relays,proposer:i.proposer,sessionProperties:i.sessionProperties,scopedProperties:i.scopedProperties}),i.id)})}),k(this,"isValidConnect",async r=>{if(!Nt(r)){const{message:f}=U("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(r)}`);throw new Error(f)}const{pairingTopic:i,requiredNamespaces:n,optionalNamespaces:s,sessionProperties:o,scopedProperties:a,relays:c}=r;if(pt(i)||await this.isValidPairingTopic(i),!x7(c,!0)){const{message:f}=U("MISSING_OR_INVALID",`connect() relays: ${c}`);throw new Error(f)}if(!pt(n)&&$o(n)!==0&&this.validateNamespaces(n,"requiredNamespaces"),!pt(s)&&$o(s)!==0&&this.validateNamespaces(s,"optionalNamespaces"),pt(o)||this.validateSessionProps(o,"sessionProperties"),!pt(a)){this.validateSessionProps(a,"scopedProperties");const f=Object.keys(n||{}).concat(Object.keys(s||{}));if(!Object.keys(a).every(u=>f.includes(u)))throw new Error(`Scoped properties must be a subset of required/optional namespaces, received: ${JSON.stringify(a)}, required/optional namespaces: ${JSON.stringify(f)}`)}}),k(this,"validateNamespaces",(r,i)=>{const n=_7(r,"connect()",i);if(n)throw new Error(n.message)}),k(this,"isValidApprove",async r=>{if(!Nt(r))throw new Error(U("MISSING_OR_INVALID",`approve() params: ${r}`).message);const{id:i,namespaces:n,relayProtocol:s,sessionProperties:o,scopedProperties:a}=r;this.checkRecentlyDeleted(i),await this.isValidProposalId(i);const c=this.client.proposal.get(i),f=jc(n,"approve()");if(f)throw new Error(f.message);const u=V0(c.requiredNamespaces,n,"approve()");if(u)throw new Error(u.message);if(!De(s,!0)){const{message:d}=U("MISSING_OR_INVALID",`approve() relayProtocol: ${s}`);throw new Error(d)}if(pt(o)||this.validateSessionProps(o,"sessionProperties"),!pt(a)){this.validateSessionProps(a,"scopedProperties");const d=new Set(Object.keys(n));if(!Object.keys(a).every(b=>d.has(b)))throw new Error(`Scoped properties must be a subset of approved namespaces, received: ${JSON.stringify(a)}, approved namespaces: ${Array.from(d).join(", ")}`)}}),k(this,"isValidReject",async r=>{if(!Nt(r)){const{message:s}=U("MISSING_OR_INVALID",`reject() params: ${r}`);throw new Error(s)}const{id:i,reason:n}=r;if(this.checkRecentlyDeleted(i),await this.isValidProposalId(i),!S7(n)){const{message:s}=U("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(n)}`);throw new Error(s)}}),k(this,"isValidSessionSettleRequest",r=>{if(!Nt(r)){const{message:f}=U("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${r}`);throw new Error(f)}const{relay:i,controller:n,namespaces:s,expiry:o}=r;if(!U0(i)){const{message:f}=U("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(f)}const a=b7(n,"onSessionSettleRequest()");if(a)throw new Error(a.message);const c=jc(s,"onSessionSettleRequest()");if(c)throw new Error(c.message);if(ni(o)){const{message:f}=U("EXPIRED","onSessionSettleRequest()");throw new Error(f)}}),k(this,"isValidUpdate",async r=>{if(!Nt(r)){const{message:c}=U("MISSING_OR_INVALID",`update() params: ${r}`);throw new Error(c)}const{topic:i,namespaces:n}=r;this.checkRecentlyDeleted(i),await this.isValidSessionTopic(i);const s=this.client.session.get(i),o=jc(n,"update()");if(o)throw new Error(o.message);const a=V0(s.requiredNamespaces,n,"update()");if(a)throw new Error(a.message)}),k(this,"isValidExtend",async r=>{if(!Nt(r)){const{message:n}=U("MISSING_OR_INVALID",`extend() params: ${r}`);throw new Error(n)}const{topic:i}=r;this.checkRecentlyDeleted(i),await this.isValidSessionTopic(i)}),k(this,"isValidRequest",async r=>{if(!Nt(r)){const{message:c}=U("MISSING_OR_INVALID",`request() params: ${r}`);throw new Error(c)}const{topic:i,request:n,chainId:s,expiry:o}=r;this.checkRecentlyDeleted(i),await this.isValidSessionTopic(i);const{namespaces:a}=this.client.session.get(i);if(!j0(a,s)){const{message:c}=U("MISSING_OR_INVALID",`request() chainId: ${s}`);throw new Error(c)}if(!I7(n)){const{message:c}=U("MISSING_OR_INVALID",`request() ${JSON.stringify(n)}`);throw new Error(c)}if(!D7(a,s,n.method)){const{message:c}=U("MISSING_OR_INVALID",`request() method: ${n.method}`);throw new Error(c)}if(o&&!R7(o,yf)){const{message:c}=U("MISSING_OR_INVALID",`request() expiry: ${o}. Expiry must be a number (in seconds) between ${yf.min} and ${yf.max}`);throw new Error(c)}}),k(this,"isValidRespond",async r=>{var i;if(!Nt(r)){const{message:o}=U("MISSING_OR_INVALID",`respond() params: ${r}`);throw new Error(o)}const{topic:n,response:s}=r;try{await this.isValidSessionTopic(n)}catch(o){throw(i=r?.response)!=null&&i.id&&this.cleanupAfterResponse(r),o}if(!A7(s)){const{message:o}=U("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(s)}`);throw new Error(o)}}),k(this,"isValidPing",async r=>{if(!Nt(r)){const{message:n}=U("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(n)}const{topic:i}=r;await this.isValidSessionOrPairingTopic(i)}),k(this,"isValidEmit",async r=>{if(!Nt(r)){const{message:a}=U("MISSING_OR_INVALID",`emit() params: ${r}`);throw new Error(a)}const{topic:i,event:n,chainId:s}=r;await this.isValidSessionTopic(i);const{namespaces:o}=this.client.session.get(i);if(!j0(o,s)){const{message:a}=U("MISSING_OR_INVALID",`emit() chainId: ${s}`);throw new Error(a)}if(!$7(n)){const{message:a}=U("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(n)}`);throw new Error(a)}if(!O7(o,s,n.name)){const{message:a}=U("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(n)}`);throw new Error(a)}}),k(this,"isValidDisconnect",async r=>{if(!Nt(r)){const{message:n}=U("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(n)}const{topic:i}=r;await this.isValidSessionOrPairingTopic(i)}),k(this,"isValidAuthenticate",r=>{const{chains:i,uri:n,domain:s,nonce:o}=r;if(!Array.isArray(i)||i.length===0)throw new Error("chains is required and must be a non-empty array");if(!De(n,!1))throw new Error("uri is required parameter");if(!De(s,!1))throw new Error("domain is required parameter");if(!De(o,!1))throw new Error("nonce is required parameter");if([...new Set(i.map(c=>bo(c).namespace))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");const{namespace:a}=bo(i[0]);if(a!=="eip155")throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")}),k(this,"getVerifyContext",async r=>{const{attestationId:i,hash:n,encryptedId:s,metadata:o,transportType:a}=r,c={verified:{verifyUrl:o.verifyUrl||fs,validation:"UNKNOWN",origin:o.url||""}};try{if(a===pe.link_mode){const u=this.getAppLinkIfEnabled(o,a);return c.verified.validation=u&&new URL(u).origin===new URL(o.url).origin?"VALID":"INVALID",c}const f=await this.client.core.verify.resolve({attestationId:i,hash:n,encryptedId:s,verifyUrl:o.verifyUrl});f&&(c.verified.origin=f.origin,c.verified.isScam=f.isScam,c.verified.validation=f.origin===new URL(o.url).origin?"VALID":"INVALID")}catch(f){this.client.logger.warn(f)}return this.client.logger.debug(`Verify context: ${JSON.stringify(c)}`),c}),k(this,"validateSessionProps",(r,i)=>{Object.values(r).forEach((n,s)=>{if(n==null){const{message:o}=U("MISSING_OR_INVALID",`${i} must contain an existing value for each key. Received: ${n} for key ${Object.keys(r)[s]}`);throw new Error(o)}})}),k(this,"getPendingAuthRequest",r=>{const i=this.client.auth.requests.get(r);return typeof i=="object"?i:void 0}),k(this,"addToRecentlyDeleted",(r,i)=>{if(this.recentlyDeletedMap.set(r,i),this.recentlyDeletedMap.size>=this.recentlyDeletedLimit){let n=0;const s=this.recentlyDeletedLimit/2;for(const o of this.recentlyDeletedMap.keys()){if(n++>=s)break;this.recentlyDeletedMap.delete(o)}}}),k(this,"checkRecentlyDeleted",r=>{const i=this.recentlyDeletedMap.get(r);if(i){const{message:n}=U("MISSING_OR_INVALID",`Record was recently deleted - ${i}: ${r}`);throw new Error(n)}}),k(this,"isLinkModeEnabled",(r,i)=>{var n,s,o,a,c,f,u,d,b;return!r||i!==pe.link_mode?!1:((s=(n=this.client.metadata)==null?void 0:n.redirect)==null?void 0:s.linkMode)===!0&&((a=(o=this.client.metadata)==null?void 0:o.redirect)==null?void 0:a.universal)!==void 0&&((f=(c=this.client.metadata)==null?void 0:c.redirect)==null?void 0:f.universal)!==""&&((u=r?.redirect)==null?void 0:u.universal)!==void 0&&((d=r?.redirect)==null?void 0:d.universal)!==""&&((b=r?.redirect)==null?void 0:b.linkMode)===!0&&this.client.core.linkModeSupportedApps.includes(r.redirect.universal)&&typeof(global==null?void 0:global.Linking)<"u"}),k(this,"getAppLinkIfEnabled",(r,i)=>{var n;return this.isLinkModeEnabled(r,i)?(n=r?.redirect)==null?void 0:n.universal:void 0}),k(this,"handleLinkModeMessage",({url:r})=>{if(!r||!r.includes("wc_ev")||!r.includes("topic"))return;const i=kl(r,"topic")||"",n=decodeURIComponent(kl(r,"wc_ev")||""),s=this.client.session.keys.includes(i);s&&this.client.session.update(i,{transportType:pe.link_mode}),this.client.core.dispatchEnvelope({topic:i,message:n,sessionExists:s})}),k(this,"registerLinkModeListeners",async()=>{var r;if(xc()||ri()&&(r=this.client.metadata.redirect)!=null&&r.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)}}}),k(this,"shouldSetTVF",(r,i)=>{if(!i||r!=="wc_sessionRequest")return!1;const{request:n}=i;return Object.keys(Gp).includes(n.method)}),k(this,"getTVFParams",(r,i,n)=>{var s,o;try{const a=i.request.method,c=this.extractTxHashesFromResult(a,n);return Dt(ce({correlationId:r,rpcMethods:[a],chainId:i.chainId},this.isValidContractData(i.request.params)&&{contractAddresses:[(o=(s=i.request.params)==null?void 0:s[0])==null?void 0:o.to]}),{txHashes:c})}catch(a){this.client.logger.warn("Error getting TVF params",a)}return{}}),k(this,"isValidContractData",r=>{var i;if(!r)return!1;try{const n=r?.data||((i=r?.[0])==null?void 0:i.data);if(!n.startsWith("0x"))return!1;const s=n.slice(2);return/^[0-9a-fA-F]*$/.test(s)?s.length%2===0:!1}catch{}return!1}),k(this,"extractTxHashesFromResult",(r,i)=>{try{const n=Gp[r];if(typeof i=="string")return[i];const s=i[n.key];if(ns(s))return r==="solana_signAllTransactions"?s.map(o=>M5(o)):s;if(typeof s=="string")return[s]}catch(n){this.client.logger.warn("Error extracting tx hashes from result",n)}return[]})}async processPendingMessageEvents(){try{const e=this.client.session.keys,r=this.client.core.relayer.messages.getWithoutAck(e);for(const[i,n]of Object.entries(r))for(const s of n)try{await this.onProviderMessageEvent({topic:i,message:s,publishedAt:Date.now()})}catch{this.client.logger.warn(`Error processing pending message event for topic: ${i}, message: ${s}`)}}catch(e){this.client.logger.warn("processPendingMessageEvents failed",e)}}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}async confirmOnlineStateOrThrow(){await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(at.message,e=>{this.onProviderMessageEvent(e)})}async onRelayMessage(e){const{topic:r,message:i,attestation:n,transportType:s}=e,{publicKey:o}=this.client.auth.authKeys.keys.includes(Co)?this.client.auth.authKeys.get(Co):{responseTopic:void 0,publicKey:void 0};try{const a=await this.client.core.crypto.decode(r,i,{receiverPublicKey:o,encoding:s===pe.link_mode?Xn:ci});Jc(a)?(this.client.core.history.set(r,a),await this.onRelayEventRequest({topic:r,payload:a,attestation:n,transportType:s,encryptedId:_r(i)})):Oo(a)?(await this.client.core.history.resolve(a),await this.onRelayEventResponse({topic:r,payload:a,transportType:s}),this.client.core.history.delete(r,a.id)):await this.onRelayEventUnknownPayload({topic:r,payload:a,transportType:s}),await this.client.core.relayer.messages.ack(r,i)}catch(a){this.client.logger.error(a)}}registerExpirerEvents(){this.client.core.expirer.on(Yt.expired,async e=>{const{topic:r,id:i}=ql(e.target);if(i&&this.client.pendingRequest.keys.includes(i))return await this.deletePendingSessionRequest(i,U("EXPIRED"),!0);if(i&&this.client.auth.requests.keys.includes(i))return await this.deletePendingAuthRequest(i,U("EXPIRED"),!0);r?this.client.session.keys.includes(r)&&(await this.deleteSession({topic:r,expirerHasDeleted:!0}),this.client.events.emit("session_expire",{topic:r})):i&&(await this.deleteProposal(i,!0),this.client.events.emit("proposal_expire",{id:i}))})}registerPairingEvents(){this.client.core.pairing.events.on(Pi.create,e=>this.onPairingCreated(e)),this.client.core.pairing.events.on(Pi.delete,e=>{this.addToRecentlyDeleted(e.topic,"pairing")})}isValidPairingTopic(e){if(!De(e,!1)){const{message:r}=U("MISSING_OR_INVALID",`pairing topic should be a string: ${e}`);throw new Error(r)}if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:r}=U("NO_MATCHING_KEY",`pairing topic doesn't exist: ${e}`);throw new Error(r)}if(ni(this.client.core.pairing.pairings.get(e).expiry)){const{message:r}=U("EXPIRED",`pairing topic: ${e}`);throw new Error(r)}}async isValidSessionTopic(e){if(!De(e,!1)){const{message:r}=U("MISSING_OR_INVALID",`session topic should be a string: ${e}`);throw new Error(r)}if(this.checkRecentlyDeleted(e),!this.client.session.keys.includes(e)){const{message:r}=U("NO_MATCHING_KEY",`session topic doesn't exist: ${e}`);throw new Error(r)}if(ni(this.client.session.get(e).expiry)){await this.deleteSession({topic:e});const{message:r}=U("EXPIRED",`session topic: ${e}`);throw new Error(r)}if(!this.client.core.crypto.keychain.has(e)){const{message:r}=U("MISSING_OR_INVALID",`session topic does not exist in keychain: ${e}`);throw await this.deleteSession({topic:e}),new Error(r)}}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(De(e,!1)){const{message:r}=U("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${e}`);throw new Error(r)}else{const{message:r}=U("MISSING_OR_INVALID",`session or pairing topic should be a string: ${e}`);throw new Error(r)}}async isValidProposalId(e){if(!E7(e)){const{message:r}=U("MISSING_OR_INVALID",`proposal id should be a number: ${e}`);throw new Error(r)}if(!this.client.proposal.keys.includes(e)){const{message:r}=U("NO_MATCHING_KEY",`proposal id doesn't exist: ${e}`);throw new Error(r)}if(ni(this.client.proposal.get(e).expiryTimestamp)){await this.deleteProposal(e);const{message:r}=U("EXPIRED",`proposal id: ${e}`);throw new Error(r)}}}class SI extends Ni{constructor(e,r){super(e,r,cI,bf),this.core=e,this.logger=r}}class Zp extends Ni{constructor(e,r){super(e,r,fI,bf),this.core=e,this.logger=r}}class II extends Ni{constructor(e,r){super(e,r,hI,bf,i=>i.id),this.core=e,this.logger=r}}class AI extends Ni{constructor(e,r){super(e,r,bI,No,()=>Co),this.core=e,this.logger=r}}class $I extends Ni{constructor(e,r){super(e,r,gI,No),this.core=e,this.logger=r}}class DI extends Ni{constructor(e,r){super(e,r,yI,No,i=>i.id),this.core=e,this.logger=r}}var OI=Object.defineProperty,MI=(t,e,r)=>e in t?OI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mf=(t,e,r)=>MI(t,typeof e!="symbol"?e+"":e,r);class PI{constructor(e,r){this.core=e,this.logger=r,mf(this,"authKeys"),mf(this,"pairingTopics"),mf(this,"requests"),this.authKeys=new AI(this.core,this.logger),this.pairingTopics=new $I(this.core,this.logger),this.requests=new DI(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}var RI=Object.defineProperty,TI=(t,e,r)=>e in t?RI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ee=(t,e,r)=>TI(t,typeof e!="symbol"?e+"":e,r);class wf extends _g{constructor(e){super(e),ee(this,"protocol",jp),ee(this,"version",Vp),ee(this,"name",gf.name),ee(this,"metadata"),ee(this,"core"),ee(this,"logger"),ee(this,"events",new mt.exports.EventEmitter),ee(this,"engine"),ee(this,"session"),ee(this,"proposal"),ee(this,"pendingRequest"),ee(this,"auth"),ee(this,"signConfig"),ee(this,"on",(i,n)=>this.events.on(i,n)),ee(this,"once",(i,n)=>this.events.once(i,n)),ee(this,"off",(i,n)=>this.events.off(i,n)),ee(this,"removeListener",(i,n)=>this.events.removeListener(i,n)),ee(this,"removeAllListeners",i=>this.events.removeAllListeners(i)),ee(this,"connect",async i=>{try{return await this.engine.connect(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"pair",async i=>{try{return await this.engine.pair(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"approve",async i=>{try{return await this.engine.approve(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"reject",async i=>{try{return await this.engine.reject(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"update",async i=>{try{return await this.engine.update(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"extend",async i=>{try{return await this.engine.extend(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"request",async i=>{try{return await this.engine.request(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"respond",async i=>{try{return await this.engine.respond(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"ping",async i=>{try{return await this.engine.ping(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"emit",async i=>{try{return await this.engine.emit(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"disconnect",async i=>{try{return await this.engine.disconnect(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"find",i=>{try{return this.engine.find(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"getPendingSessionRequests",()=>{try{return this.engine.getPendingSessionRequests()}catch(i){throw this.logger.error(i.message),i}}),ee(this,"authenticate",async(i,n)=>{try{return await this.engine.authenticate(i,n)}catch(s){throw this.logger.error(s.message),s}}),ee(this,"formatAuthMessage",i=>{try{return this.engine.formatAuthMessage(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"approveSessionAuthenticate",async i=>{try{return await this.engine.approveSessionAuthenticate(i)}catch(n){throw this.logger.error(n.message),n}}),ee(this,"rejectSessionAuthenticate",async i=>{try{return await this.engine.rejectSessionAuthenticate(i)}catch(n){throw this.logger.error(n.message),n}}),this.name=e?.name||gf.name,this.metadata=e?.metadata||Bl(),this.signConfig=e?.signConfig;const r=typeof e?.logger<"u"&&typeof e?.logger!="string"?e.logger:Dr(ea({level:e?.logger||gf.logger}));this.core=e?.core||new pf(e),this.logger=It(r,this.name),this.session=new Zp(this.core,this.logger),this.proposal=new SI(this.core,this.logger),this.pendingRequest=new II(this.core,this.logger),this.engine=new EI(this),this.auth=new PI(this.core,this.logger)}static async init(e){const r=new wf(e);return await r.initialize(),r}get context(){return Mt(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"),setTimeout(()=>{this.engine.processRelayMessageCache()},z.toMiliseconds(z.ONE_SECOND))}catch(e){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(e.message),e}}}const NI=Zp,CI=wf;class BI extends mt.exports{constructor(){super()}}class Jp{constructor(e){this.opts=e}}class Xp{constructor(e){this.client=e}}var FI=Object.defineProperty,LI=Object.defineProperties,qI=Object.getOwnPropertyDescriptors,Qp=Object.getOwnPropertySymbols,kI=Object.prototype.hasOwnProperty,zI=Object.prototype.propertyIsEnumerable,e1=(t,e,r)=>e in t?FI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,UI=(t,e)=>{for(var r in e||(e={}))kI.call(e,r)&&e1(t,r,e[r]);if(Qp)for(var r of Qp(e))zI.call(e,r)&&e1(t,r,e[r]);return t},jI=(t,e)=>LI(t,qI(e));class VI extends Xp{constructor(e){super(e),this.init=async()=>{this.signClient=await CI.init({core:this.client.core,metadata:this.client.metadata,signConfig:this.client.signConfig}),this.signClient.core.eventClient.init().catch(r=>{this.client.logger.warn(r)})},this.pair=async r=>{await this.client.core.pairing.pair(r)},this.approveSession=async r=>{const{topic:i,acknowledged:n}=await this.signClient.approve(jI(UI({},r),{id:r.id,namespaces:r.namespaces,sessionProperties:r.sessionProperties,sessionConfig:r.sessionConfig}));return await n(),this.signClient.session.get(i)},this.rejectSession=async r=>await this.signClient.reject(r),this.updateSession=async r=>await this.signClient.update(r),this.extendSession=async r=>await this.signClient.extend(r),this.respondSessionRequest=async r=>await this.signClient.respond(r),this.disconnectSession=async r=>await this.signClient.disconnect(r),this.emitSessionEvent=async r=>await this.signClient.emit(r),this.getActiveSessions=()=>this.signClient.session.getAll().reduce((r,i)=>(r[i.topic]=i,r),{}),this.getPendingSessionProposals=()=>this.signClient.proposal.getAll(),this.getPendingSessionRequests=()=>this.signClient.getPendingSessionRequests(),this.approveSessionAuthenticate=async r=>await this.signClient.approveSessionAuthenticate(r),this.rejectSessionAuthenticate=async r=>await this.signClient.rejectSessionAuthenticate(r),this.formatAuthMessage=r=>this.signClient.formatAuthMessage(r),this.registerDeviceToken=r=>this.client.core.echoClient.registerDeviceToken(r),this.on=(r,i)=>(this.setEvent(r,"off"),this.setEvent(r,"on"),this.client.events.on(r,i)),this.once=(r,i)=>(this.setEvent(r,"off"),this.setEvent(r,"once"),this.client.events.once(r,i)),this.off=(r,i)=>(this.setEvent(r,"off"),this.client.events.off(r,i)),this.removeListener=(r,i)=>(this.setEvent(r,"removeListener"),this.client.events.removeListener(r,i)),this.onSessionRequest=r=>{this.client.events.emit("session_request",r)},this.onSessionProposal=r=>{this.client.events.emit("session_proposal",r)},this.onSessionDelete=r=>{this.client.events.emit("session_delete",r)},this.onProposalExpire=r=>{this.client.events.emit("proposal_expire",r)},this.onSessionRequestExpire=r=>{this.client.events.emit("session_request_expire",r)},this.onSessionRequestAuthenticate=r=>{this.client.events.emit("session_authenticate",r)},this.setEvent=(r,i)=>{switch(r){case"session_request":this.signClient.events[i]("session_request",this.onSessionRequest);break;case"session_proposal":this.signClient.events[i]("session_proposal",this.onSessionProposal);break;case"session_delete":this.signClient.events[i]("session_delete",this.onSessionDelete);break;case"proposal_expire":this.signClient.events[i]("proposal_expire",this.onProposalExpire);break;case"session_request_expire":this.signClient.events[i]("session_request_expire",this.onSessionRequestExpire);break;case"session_authenticate":this.signClient.events[i]("session_authenticate",this.onSessionRequestAuthenticate);break}},this.signClient={}}}const KI={decryptMessage:async t=>{const e={core:new pf({storageOptions:t.storageOptions,storage:t.storage})};await e.core.crypto.init();const r=e.core.crypto.decode(t.topic,t.encryptedMessage);return e.core=null,r},getMetadata:async t=>{const e={core:new pf({storageOptions:t.storageOptions,storage:t.storage}),sessionStore:null};e.sessionStore=new NI(e.core,e.core.logger),await e.sessionStore.init();const r=e.sessionStore.get(t.topic),i=r?.peer.metadata;return e.core=null,e.sessionStore=null,i}},t1=class extends Jp{constructor(t){super(t),this.events=new mt.exports,this.on=(e,r)=>this.engine.on(e,r),this.once=(e,r)=>this.engine.once(e,r),this.off=(e,r)=>this.engine.off(e,r),this.removeListener=(e,r)=>this.engine.removeListener(e,r),this.pair=async e=>{try{return await this.engine.pair(e)}catch(r){throw this.logger.error(r.message),r}},this.approveSession=async e=>{try{return await this.engine.approveSession(e)}catch(r){throw this.logger.error(r.message),r}},this.rejectSession=async e=>{try{return await this.engine.rejectSession(e)}catch(r){throw this.logger.error(r.message),r}},this.updateSession=async e=>{try{return await this.engine.updateSession(e)}catch(r){throw this.logger.error(r.message),r}},this.extendSession=async e=>{try{return await this.engine.extendSession(e)}catch(r){throw this.logger.error(r.message),r}},this.respondSessionRequest=async e=>{try{return await this.engine.respondSessionRequest(e)}catch(r){throw this.logger.error(r.message),r}},this.disconnectSession=async e=>{try{return await this.engine.disconnectSession(e)}catch(r){throw this.logger.error(r.message),r}},this.emitSessionEvent=async e=>{try{return await this.engine.emitSessionEvent(e)}catch(r){throw this.logger.error(r.message),r}},this.getActiveSessions=()=>{try{return this.engine.getActiveSessions()}catch(e){throw this.logger.error(e.message),e}},this.getPendingSessionProposals=()=>{try{return this.engine.getPendingSessionProposals()}catch(e){throw this.logger.error(e.message),e}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(e){throw this.logger.error(e.message),e}},this.registerDeviceToken=e=>{try{return this.engine.registerDeviceToken(e)}catch(r){throw this.logger.error(r.message),r}},this.approveSessionAuthenticate=e=>{try{return this.engine.approveSessionAuthenticate(e)}catch(r){throw this.logger.error(r.message),r}},this.rejectSessionAuthenticate=e=>{try{return this.engine.rejectSessionAuthenticate(e)}catch(r){throw this.logger.error(r.message),r}},this.formatAuthMessage=e=>{try{return this.engine.formatAuthMessage(e)}catch(r){throw this.logger.error(r.message),r}},this.metadata=t.metadata,this.name=t.name||qo,this.signConfig=t.signConfig,this.core=t.core,this.logger=this.core.logger,this.engine=new VI(this)}static async init(t){const e=new t1(t);return await e.initialize(),e}async initialize(){this.logger.trace("Initialized");try{await this.engine.init(),this.logger.info("WalletKit Initialization Success")}catch(t){throw this.logger.info("WalletKit Initialization Failure"),this.logger.error(t.message),t}}};let _f=t1;_f.notifications=KI;const HI=_f;vt.CLIENT_CONTEXT=qo,vt.CLIENT_STORAGE_OPTIONS=w1,vt.CLIENT_STORAGE_PREFIX=m1,vt.IWalletKit=Jp,vt.IWalletKitEngine=Xp,vt.IWalletKitEvents=BI,vt.PROTOCOL=Jf,vt.PROTOCOL_VERSION=v1,vt.REQUEST_CONTEXT=_1,vt.WalletKit=HI,vt.default=_f,Object.defineProperty(vt,"__esModule",{value:!0})});
39
+ ***************************************************************************** */var ua=function(t,e){return ua=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(r,n){r.__proto__=n}||function(r,n){for(var i in n)n.hasOwnProperty(i)&&(r[i]=n[i])},ua(t,e)};function BS(t,e){ua(t,e);function r(){this.constructor=t}t.prototype=e===null?Object.create(e):(r.prototype=e.prototype,new r)}var la=function(){return la=Object.assign||function(e){for(var r,n=1,i=arguments.length;n<i;n++){r=arguments[n];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(e[s]=r[s])}return e},la.apply(this,arguments)};function FS(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(t);i<n.length;i++)e.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(t,n[i])&&(r[n[i]]=t[n[i]]);return r}function LS(t,e,r,n){var i=arguments.length,s=i<3?e:n===null?n=Object.getOwnPropertyDescriptor(e,r):n,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,r,n);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,r,s):o(e,r))||s);return i>3&&s&&Object.defineProperty(e,r,s),s}function US(t,e){return function(r,n){e(r,n,t)}}function kS(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function MS(t,e,r,n){function i(s){return s instanceof r?s:new r(function(o){o(s)})}return new(r||(r=Promise))(function(s,o){function a(l){try{u(n.next(l))}catch(h){o(h)}}function c(l){try{u(n.throw(l))}catch(h){o(h)}}function u(l){l.done?s(l.value):i(l.value).then(a,c)}u((n=n.apply(t,e||[])).next())})}function jS(t,e){var r={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,i,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol=="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(u){return function(l){return c([u,l])}}function c(u){if(n)throw new TypeError("Generator is already executing.");for(;r;)try{if(n=1,i&&(s=u[0]&2?i.return:u[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,u[1])).done)return s;switch(i=0,s&&(u=[u[0]&2,s.value]),u[0]){case 0:case 1:s=u;break;case 4:return r.label++,{value:u[1],done:!1};case 5:r.label++,i=u[1],u=[0];continue;case 7:u=r.ops.pop(),r.trys.pop();continue;default:if(s=r.trys,!(s=s.length>0&&s[s.length-1])&&(u[0]===6||u[0]===2)){r=0;continue}if(u[0]===3&&(!s||u[1]>s[0]&&u[1]<s[3])){r.label=u[1];break}if(u[0]===6&&r.label<s[1]){r.label=s[1],s=u;break}if(s&&r.label<s[2]){r.label=s[2],r.ops.push(u);break}s[2]&&r.ops.pop(),r.trys.pop();continue}u=e.call(t,r)}catch(l){u=[6,l],i=0}finally{n=s=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function qS(t,e,r,n){n===void 0&&(n=r),t[n]=e[r]}function zS(t,e){for(var r in t)r!=="default"&&!e.hasOwnProperty(r)&&(e[r]=t[r])}function ha(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function $d(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return s}function VS(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat($d(arguments[e]));return t}function KS(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),i=0,e=0;e<r;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,i++)n[i]=s[o];return n}function Jn(t){return this instanceof Jn?(this.v=t,this):new Jn(t)}function HS(t,e,r){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var n=r.apply(t,e||[]),i,s=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(d){n[d]&&(i[d]=function(p){return new Promise(function(f,y){s.push([d,p,f,y])>1||a(d,p)})})}function a(d,p){try{c(n[d](p))}catch(f){h(s[0][3],f)}}function c(d){d.value instanceof Jn?Promise.resolve(d.value.v).then(u,l):h(s[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function h(d,p){d(p),s.shift(),s.length&&a(s[0][0],s[0][1])}}function WS(t){var e,r;return e={},n("next"),n("throw",function(i){throw i}),n("return"),e[Symbol.iterator]=function(){return this},e;function n(i,s){e[i]=t[i]?function(o){return(r=!r)?{value:Jn(t[i](o)),done:i==="return"}:s?s(o):o}:s}}function GS(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],r;return e?e.call(t):(t=typeof ha=="function"?ha(t):t[Symbol.iterator](),r={},n("next"),n("throw"),n("return"),r[Symbol.asyncIterator]=function(){return this},r);function n(s){r[s]=t[s]&&function(o){return new Promise(function(a,c){o=t[s](o),i(a,c,o.done,o.value)})}}function i(s,o,a,c){Promise.resolve(c).then(function(u){s({value:u,done:a})},o)}}function YS(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function ZS(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)Object.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e.default=t,e}function JS(t){return t&&t.__esModule?t:{default:t}}function XS(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function QS(t,e,r){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,r),r}var ex=Object.freeze({__proto__:null,__extends:BS,get __assign(){return la},__rest:FS,__decorate:LS,__param:US,__metadata:kS,__awaiter:MS,__generator:jS,__createBinding:qS,__exportStar:zS,__values:ha,__read:$d,__spread:VS,__spreadArrays:KS,__await:Jn,__asyncGenerator:HS,__asyncDelegator:WS,__asyncValues:GS,__makeTemplateObject:YS,__importStar:ZS,__importDefault:JS,__classPrivateFieldGet:XS,__classPrivateFieldSet:QS}),tx=ka(ex),qt={},Ad;function rx(){if(Ad)return qt;Ad=1,Object.defineProperty(qt,"__esModule",{value:!0}),qt.isBrowserCryptoAvailable=qt.getSubtleCrypto=qt.getBrowerCrypto=void 0;function t(){return yt?.crypto||yt?.msCrypto||{}}qt.getBrowerCrypto=t;function e(){const n=t();return n.subtle||n.webkitSubtle}qt.getSubtleCrypto=e;function r(){return!!t()&&!!e()}return qt.isBrowserCryptoAvailable=r,qt}var zt={},Pd;function nx(){if(Pd)return zt;Pd=1,Object.defineProperty(zt,"__esModule",{value:!0}),zt.isBrowser=zt.isNode=zt.isReactNative=void 0;function t(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}zt.isReactNative=t;function e(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}zt.isNode=e;function r(){return!t()&&!e()}return zt.isBrowser=r,zt}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=tx;e.__exportStar(rx(),t),e.__exportStar(nx(),t)})(Od);function xt(t=3){const e=Date.now()*Math.pow(10,t),r=Math.floor(Math.random()*Math.pow(10,t));return e+r}function Ir(t=6){return BigInt(xt(t))}function Dr(t,e,r){return{id:r||xt(),jsonrpc:"2.0",method:t,params:e}}function da(t,e){return{id:t,jsonrpc:"2.0",result:e}}function fa(t,e,r){return{id:t,jsonrpc:"2.0",error:ix(e,r)}}function ix(t,e){return typeof t>"u"?Dd(xd):(typeof t=="string"&&(t=Object.assign(Object.assign({},Dd(ca)),{message:t})),typeof e<"u"&&(t.data=e),RS(t.code)&&(t=CS(t.code)),t)}class sx{}class ox extends sx{constructor(){super()}}class ax extends ox{constructor(e){super()}}const cx="^wss?:";function ux(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function lx(t,e){const r=ux(t);return typeof r>"u"?!1:new RegExp(e).test(r)}function Td(t){return lx(t,cx)}function hx(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function Rd(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function pa(t){return Rd(t)&&"method"in t}function ns(t){return Rd(t)&&(It(t)||ot(t))}function It(t){return"result"in t}function ot(t){return"error"in t}class dx extends ax{constructor(e){super(e),this.events=new Le.exports.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,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async request(e,r){return this.requestStrict(Dr(e.method,e.params||[],e.id||Ir().toString()),r)}async requestStrict(e,r){return new Promise(async(n,i)=>{if(!this.connection.connected)try{await this.open()}catch(s){i(s)}this.events.on(`${e.id}`,s=>{ot(s)?i(s.error):n(s.result)});try{await this.connection.send(e,r)}catch(s){i(s)}})}setConnection(e=this.connection){return e}onPayload(e){this.events.emit("payload",e),ns(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 fx=()=>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"),px=()=>typeof WebSocket<"u"||typeof global<"u"&&typeof global.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",Cd=t=>t.split("?")[0],Nd=10,gx=fx();class yx{constructor(e){if(this.url=e,this.events=new Le.exports.EventEmitter,this.registering=!1,!Td(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,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async open(e=this.url){await this.register(e)}async close(){return new Promise((e,r)=>{if(typeof this.socket>"u"){r(new Error("Connection already closed"));return}this.socket.onclose=n=>{this.onClose(n),e()},this.socket.close()})}async send(e){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(dr(e))}catch(r){this.onError(e.id,r)}}register(e=this.url){if(!Td(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);if(this.registering){const r=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=r||this.events.listenerCount("open")>=r)&&this.events.setMaxListeners(r+1),new Promise((n,i)=>{this.events.once("register_error",s=>{this.resetMaxListeners(),i(s)}),this.events.once("open",()=>{if(this.resetMaxListeners(),typeof this.socket>"u")return i(new Error("WebSocket connection is missing or invalid"));n(this.socket)})})}return this.url=e,this.registering=!0,new Promise((r,n)=>{const i=Od.isReactNative()?void 0:{rejectUnauthorized:!hx(e)},s=new gx(e,[],i);px()?s.onerror=o=>{const a=o;n(this.emitError(a.error))}:s.on("error",o=>{n(this.emitError(o))}),s.onopen=()=>{this.onOpen(s),r(s)}})}onOpen(e){e.onmessage=r=>this.onPayload(r),e.onclose=r=>this.onClose(r),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 r=typeof e.data=="string"?Nr(e.data):e.data;this.events.emit("payload",r)}onError(e,r){const n=this.parseError(r),i=n.message||n.toString(),s=fa(e,i);this.events.emit("payload",s)}parseError(e,r=this.url){return NS(e,Cd(r),"WS")}resetMaxListeners(){this.events.getMaxListeners()>Nd&&this.events.setMaxListeners(Nd)}emitError(e){const r=this.parseError(new Error(e?.message||`WebSocket connection failed for host: ${Cd(this.url)}`));return this.events.emit("register_error",r),r}}const Bd="wc",Fd=2,is="core",Dt=`${Bd}@2:${is}:`,wx={name:is,logger:"error"},mx={database:":memory:"},bx="crypto",Ld="client_ed25519_seed",vx=L.ONE_DAY,Ex="keychain",_x="0.3",Sx="messages",xx="0.3",Ud=L.SIX_HOURS,Ix="publisher",kd="irn",Dx="error",Md="wss://relay.walletconnect.org",Ox="relayer",Ie={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"},$x="_subscription",at={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},Ax=.1,ga="2.19.2",ce={link_mode:"link_mode",relay:"relay"},ss={inbound:"inbound",outbound:"outbound"},Px="0.3",Tx="WALLETCONNECT_CLIENT_ID",jd="WALLETCONNECT_LINK_MODE_APPS",rt={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},Rx="subscription",Cx="0.3",Nx="pairing",Bx="0.3",Xn={wc_pairingDelete:{req:{ttl:L.ONE_DAY,prompt:!1,tag:1e3},res:{ttl:L.ONE_DAY,prompt:!1,tag:1001}},wc_pairingPing:{req:{ttl:L.THIRTY_SECONDS,prompt:!1,tag:1002},res:{ttl:L.THIRTY_SECONDS,prompt:!1,tag:1003}},unregistered_method:{req:{ttl:L.ONE_DAY,prompt:!1,tag:0},res:{ttl:L.ONE_DAY,prompt:!1,tag:0}}},Or={create:"pairing_create",expire:"pairing_expire",delete:"pairing_delete",ping:"pairing_ping"},ft={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},Fx="history",Lx="0.3",Ux="expirer",ct={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},kx="0.3",Mx="verify-api",jx="https://verify.walletconnect.com",qd="https://verify.walletconnect.org",Qn=qd,qx=`${Qn}/v3`,zx=[jx,qd],Vx="echo",Kx="https://echo.walletconnect.com",Ot={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"},Vt={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"},pt={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"},$r={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"},Ar={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"},ei={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"},Hx=.1,Wx="event-client",Gx=86400,Yx="https://pulse.walletconnect.org/batch";function Zx(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(f){if(f instanceof Uint8Array||(ArrayBuffer.isView(f)?f=new Uint8Array(f.buffer,f.byteOffset,f.byteLength):Array.isArray(f)&&(f=Uint8Array.from(f))),!(f instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(f.length===0)return"";for(var y=0,g=0,w=0,m=f.length;w!==m&&f[w]===0;)w++,y++;for(var b=(m-w)*l+1>>>0,E=new Uint8Array(b);w!==m;){for(var $=f[w],D=0,S=b-1;($!==0||D<g)&&S!==-1;S--,D++)$+=256*E[S]>>>0,E[S]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");g=D,w++}for(var A=b-g;A!==b&&E[A]===0;)A++;for(var x=c.repeat(y);A<b;++A)x+=t.charAt(E[A]);return x}function d(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;var y=0;if(f[y]!==" "){for(var g=0,w=0;f[y]===c;)g++,y++;for(var m=(f.length-y)*u+1>>>0,b=new Uint8Array(m);f[y];){var E=r[f.charCodeAt(y)];if(E===255)return;for(var $=0,D=m-1;(E!==0||$<w)&&D!==-1;D--,$++)E+=a*b[D]>>>0,b[D]=E%256>>>0,E=E/256>>>0;if(E!==0)throw new Error("Non-zero carry");w=$,y++}if(f[y]!==" "){for(var S=m-w;S!==m&&b[S]===0;)S++;for(var A=new Uint8Array(g+(m-S)),x=g;S!==m;)A[x++]=b[S++];return A}}}function p(f){var y=d(f);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:d,decode:p}}var Jx=Zx,Xx=Jx;const zd=t=>{if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")},Qx=t=>new TextEncoder().encode(t),e3=t=>new TextDecoder().decode(t);class t3{constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class r3{constructor(e,r,n){if(this.name=e,this.prefix=r,r.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=r.codePointAt(0),this.baseDecode=n}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 Vd(this,e)}}class n3{constructor(e){this.decoders=e}or(e){return Vd(this,e)}decode(e){const r=e[0],n=this.decoders[r];if(n)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Vd=(t,e)=>new n3({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class i3{constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new t3(e,r,n),this.decoder=new r3(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const os=({name:t,prefix:e,encode:r,decode:n})=>new i3(t,e,r,n),ti=({prefix:t,name:e,alphabet:r})=>{const{encode:n,decode:i}=Xx(r,e);return os({prefix:t,name:e,encode:n,decode:s=>zd(i(s))})},s3=(t,e,r,n)=>{const i={};for(let l=0;l<e.length;++l)i[e[l]]=l;let s=t.length;for(;t[s-1]==="=";)--s;const o=new Uint8Array(s*r/8|0);let a=0,c=0,u=0;for(let l=0;l<s;++l){const h=i[t[l]];if(h===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|h,a+=r,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=r||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},o3=(t,e,r)=>{const n=e[e.length-1]==="=",i=(1<<r)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[i&a>>o];if(o&&(s+=e[i&a<<r-o]),n)for(;s.length*r&7;)s+="=";return s},Ce=({name:t,prefix:e,bitsPerChar:r,alphabet:n})=>os({prefix:e,name:t,encode(i){return o3(i,n,r)},decode(i){return s3(i,n,r,t)}}),a3=os({prefix:"\0",name:"identity",encode:t=>e3(t),decode:t=>Qx(t)});var c3=Object.freeze({__proto__:null,identity:a3});const u3=Ce({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var l3=Object.freeze({__proto__:null,base2:u3});const h3=Ce({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var d3=Object.freeze({__proto__:null,base8:h3});const f3=ti({prefix:"9",name:"base10",alphabet:"0123456789"});var p3=Object.freeze({__proto__:null,base10:f3});const g3=Ce({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),y3=Ce({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var w3=Object.freeze({__proto__:null,base16:g3,base16upper:y3});const m3=Ce({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),b3=Ce({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),v3=Ce({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),E3=Ce({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),_3=Ce({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),S3=Ce({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),x3=Ce({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),I3=Ce({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),D3=Ce({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var O3=Object.freeze({__proto__:null,base32:m3,base32upper:b3,base32pad:v3,base32padupper:E3,base32hex:_3,base32hexupper:S3,base32hexpad:x3,base32hexpadupper:I3,base32z:D3});const $3=ti({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),A3=ti({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var P3=Object.freeze({__proto__:null,base36:$3,base36upper:A3});const T3=ti({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),R3=ti({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var C3=Object.freeze({__proto__:null,base58btc:T3,base58flickr:R3});const N3=Ce({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),B3=Ce({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),F3=Ce({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),L3=Ce({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var U3=Object.freeze({__proto__:null,base64:N3,base64pad:B3,base64url:F3,base64urlpad:L3});const Kd=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),k3=Kd.reduce((t,e,r)=>(t[r]=e,t),[]),M3=Kd.reduce((t,e,r)=>(t[e.codePointAt(0)]=r,t),[]);function j3(t){return t.reduce((e,r)=>(e+=k3[r],e),"")}function q3(t){const e=[];for(const r of t){const n=M3[r.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${r}`);e.push(n)}return new Uint8Array(e)}const z3=os({prefix:"\u{1F680}",name:"base256emoji",encode:j3,decode:q3});var V3=Object.freeze({__proto__:null,base256emoji:z3}),K3=Wd,Hd=128,H3=127,W3=~H3,G3=Math.pow(2,31);function Wd(t,e,r){e=e||[],r=r||0;for(var n=r;t>=G3;)e[r++]=t&255|Hd,t/=128;for(;t&W3;)e[r++]=t&255|Hd,t>>>=7;return e[r]=t|0,Wd.bytes=r-n+1,e}var Y3=ya,Z3=128,Gd=127;function ya(t,n){var r=0,n=n||0,i=0,s=n,o,a=t.length;do{if(s>=a)throw ya.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=i<28?(o&Gd)<<i:(o&Gd)*Math.pow(2,i),i+=7}while(o>=Z3);return ya.bytes=s-n,r}var J3=Math.pow(2,7),X3=Math.pow(2,14),Q3=Math.pow(2,21),eI=Math.pow(2,28),tI=Math.pow(2,35),rI=Math.pow(2,42),nI=Math.pow(2,49),iI=Math.pow(2,56),sI=Math.pow(2,63),oI=function(t){return t<J3?1:t<X3?2:t<Q3?3:t<eI?4:t<tI?5:t<rI?6:t<nI?7:t<iI?8:t<sI?9:10},aI={encode:K3,decode:Y3,encodingLength:oI},Yd=aI;const Zd=(t,e,r=0)=>(Yd.encode(t,e,r),e),Jd=t=>Yd.encodingLength(t),wa=(t,e)=>{const r=e.byteLength,n=Jd(t),i=n+Jd(r),s=new Uint8Array(i+r);return Zd(t,s,0),Zd(r,s,n),s.set(e,i),new cI(t,r,e,s)};class cI{constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}}const Xd=({name:t,code:e,encode:r})=>new uI(t,e,r);class uI{constructor(e,r,n){this.name=e,this.code=r,this.encode=n}digest(e){if(e instanceof Uint8Array){const r=this.encode(e);return r instanceof Uint8Array?wa(this.code,r):r.then(n=>wa(this.code,n))}else throw Error("Unknown type, must be binary type")}}const Qd=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),lI=Xd({name:"sha2-256",code:18,encode:Qd("SHA-256")}),hI=Xd({name:"sha2-512",code:19,encode:Qd("SHA-512")});var dI=Object.freeze({__proto__:null,sha256:lI,sha512:hI});const ef=0,fI="identity",tf=zd;var pI=Object.freeze({__proto__:null,identity:{code:ef,name:fI,encode:tf,digest:t=>wa(ef,tf(t))}});new TextEncoder,new TextDecoder;const rf={...c3,...l3,...d3,...p3,...w3,...O3,...P3,...C3,...U3,...V3};({...dI,...pI});function gI(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?globalThis.Buffer.allocUnsafe(t):new Uint8Array(t)}function nf(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}const sf=nf("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ma=nf("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);const e=gI(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),yI={utf8:sf,"utf-8":sf,hex:rf.base16,latin1:ma,ascii:ma,binary:ma,...rf};function wI(t,e="utf8"){const r=yI[e];if(!r)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?globalThis.Buffer.from(t,"utf8"):r.decoder.decode(`${r.prefix}${t}`)}var mI=Object.defineProperty,bI=(t,e,r)=>e in t?mI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$t=(t,e,r)=>bI(t,typeof e!="symbol"?e+"":e,r);class vI{constructor(e,r){this.core=e,this.logger=r,$t(this,"keychain",new Map),$t(this,"name",Ex),$t(this,"version",_x),$t(this,"initialized",!1),$t(this,"storagePrefix",Dt),$t(this,"init",async()=>{if(!this.initialized){const n=await this.getKeyChain();typeof n<"u"&&(this.keychain=n),this.initialized=!0}}),$t(this,"has",n=>(this.isInitialized(),this.keychain.has(n))),$t(this,"set",async(n,i)=>{this.isInitialized(),this.keychain.set(n,i),await this.persist()}),$t(this,"get",n=>{this.isInitialized();const i=this.keychain.get(n);if(typeof i>"u"){const{message:s}=U("NO_MATCHING_KEY",`${this.name}: ${n}`);throw new Error(s)}return i}),$t(this,"del",async n=>{this.isInitialized(),this.keychain.delete(n),await this.persist()}),this.core=e,this.logger=je(r,this.name)}get context(){return He(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,Ao(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Po(e):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var EI=Object.defineProperty,_I=(t,e,r)=>e in t?EI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ne=(t,e,r)=>_I(t,typeof e!="symbol"?e+"":e,r);class SI{constructor(e,r,n){this.core=e,this.logger=r,Ne(this,"name",bx),Ne(this,"keychain"),Ne(this,"randomSessionIdentifier",ia()),Ne(this,"initialized",!1),Ne(this,"init",async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)}),Ne(this,"hasKeys",i=>(this.isInitialized(),this.keychain.has(i))),Ne(this,"getClientId",async()=>{this.isInitialized();const i=await this.getClientSeed(),s=wu(i);return yu(s.publicKey)}),Ne(this,"generateKeyPair",()=>{this.isInitialized();const i=C_();return this.setPrivateKey(i.publicKey,i.privateKey)}),Ne(this,"signJWT",async i=>{this.isInitialized();const s=await this.getClientSeed(),o=wu(s),a=this.randomSessionIdentifier;return await Mm(a,i,vx,o)}),Ne(this,"generateSharedKey",(i,s,o)=>{this.isInitialized();const a=this.getPrivateKey(i),c=N_(a,s);return this.setSymKey(c,o)}),Ne(this,"setSymKey",async(i,s)=>{this.isInitialized();const o=s||Xi(i);return await this.keychain.set(o,i),o}),Ne(this,"deleteKeyPair",async i=>{this.isInitialized(),await this.keychain.del(i)}),Ne(this,"deleteSymKey",async i=>{this.isInitialized(),await this.keychain.del(i)}),Ne(this,"encode",async(i,s,o)=>{this.isInitialized();const a=hd(o),c=dr(s);if(fd(a))return L_(c,o?.encoding);if(dd(a)){const d=a.senderPublicKey,p=a.receiverPublicKey;i=await this.generateSharedKey(d,p)}const u=this.getSymKey(i),{type:l,senderPublicKey:h}=a;return B_({type:l,symKey:u,message:c,senderPublicKey:h,encoding:o?.encoding})}),Ne(this,"decode",async(i,s,o)=>{this.isInitialized();const a=k_(s,o);if(fd(a)){const c=U_(s,o?.encoding);return Nr(c)}if(dd(a)){const c=a.receiverPublicKey,u=a.senderPublicKey;i=await this.generateSharedKey(c,u)}try{const c=this.getSymKey(i),u=F_({symKey:c,encoded:s,encoding:o?.encoding});return Nr(u)}catch(c){this.logger.error(`Failed to decode message from topic: '${i}', clientId: '${await this.getClientId()}'`),this.logger.error(c)}}),Ne(this,"getPayloadType",(i,s=dt)=>{const o=Hn({encoded:i,encoding:s});return xr(o.type)}),Ne(this,"getPayloadSenderPublicKey",(i,s=dt)=>{const o=Hn({encoded:i,encoding:s});return o.senderPublicKey?Ge(o.senderPublicKey,ze):void 0}),this.core=e,this.logger=je(r,this.name),this.keychain=n||new vI(this.core,this.logger)}get context(){return He(this.logger)}async setPrivateKey(e,r){return await this.keychain.set(e,r),e}getPrivateKey(e){return this.keychain.get(e)}async getClientSeed(){let e="";try{e=this.keychain.get(Ld)}catch{e=ia(),await this.keychain.set(Ld,e)}return wI(e,"base16")}getSymKey(e){return this.keychain.get(e)}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var xI=Object.defineProperty,II=Object.defineProperties,DI=Object.getOwnPropertyDescriptors,of=Object.getOwnPropertySymbols,OI=Object.prototype.hasOwnProperty,$I=Object.prototype.propertyIsEnumerable,ba=(t,e,r)=>e in t?xI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,AI=(t,e)=>{for(var r in e||(e={}))OI.call(e,r)&&ba(t,r,e[r]);if(of)for(var r of of(e))$I.call(e,r)&&ba(t,r,e[r]);return t},PI=(t,e)=>II(t,DI(e)),nt=(t,e,r)=>ba(t,typeof e!="symbol"?e+"":e,r);class TI extends kg{constructor(e,r){super(e,r),this.logger=e,this.core=r,nt(this,"messages",new Map),nt(this,"messagesWithoutClientAck",new Map),nt(this,"name",Sx),nt(this,"version",xx),nt(this,"initialized",!1),nt(this,"storagePrefix",Dt),nt(this,"init",async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const n=await this.getRelayerMessages();typeof n<"u"&&(this.messages=n);const i=await this.getRelayerMessagesWithoutClientAck();typeof i<"u"&&(this.messagesWithoutClientAck=i),this.logger.debug(`Successfully Restored records for ${this.name}`),this.logger.trace({type:"method",method:"restore",size:this.messages.size})}catch(n){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(n)}finally{this.initialized=!0}}}),nt(this,"set",async(n,i,s)=>{this.isInitialized();const o=St(i);let a=this.messages.get(n);if(typeof a>"u"&&(a={}),typeof a[o]<"u")return o;if(a[o]=i,this.messages.set(n,a),s===ss.inbound){const c=this.messagesWithoutClientAck.get(n)||{};this.messagesWithoutClientAck.set(n,PI(AI({},c),{[o]:i}))}return await this.persist(),o}),nt(this,"get",n=>{this.isInitialized();let i=this.messages.get(n);return typeof i>"u"&&(i={}),i}),nt(this,"getWithoutAck",n=>{this.isInitialized();const i={};for(const s of n){const o=this.messagesWithoutClientAck.get(s)||{};i[s]=Object.values(o)}return i}),nt(this,"has",(n,i)=>{this.isInitialized();const s=this.get(n),o=St(i);return typeof s[o]<"u"}),nt(this,"ack",async(n,i)=>{this.isInitialized();const s=this.messagesWithoutClientAck.get(n);if(typeof s>"u")return;const o=St(i);delete s[o],Object.keys(s).length===0?this.messagesWithoutClientAck.delete(n):this.messagesWithoutClientAck.set(n,s),await this.persist()}),nt(this,"del",async n=>{this.isInitialized(),this.messages.delete(n),this.messagesWithoutClientAck.delete(n),await this.persist()}),this.logger=je(e,this.name),this.core=r}get context(){return He(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}get storageKeyWithoutClientAck(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name+"_withoutClientAck"}async setRelayerMessages(e){await this.core.storage.setItem(this.storageKey,Ao(e))}async setRelayerMessagesWithoutClientAck(e){await this.core.storage.setItem(this.storageKeyWithoutClientAck,Ao(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Po(e):void 0}async getRelayerMessagesWithoutClientAck(){const e=await this.core.storage.getItem(this.storageKeyWithoutClientAck);return typeof e<"u"?Po(e):void 0}async persist(){await this.setRelayerMessages(this.messages),await this.setRelayerMessagesWithoutClientAck(this.messagesWithoutClientAck)}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var RI=Object.defineProperty,CI=Object.defineProperties,NI=Object.getOwnPropertyDescriptors,af=Object.getOwnPropertySymbols,BI=Object.prototype.hasOwnProperty,FI=Object.prototype.propertyIsEnumerable,va=(t,e,r)=>e in t?RI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,as=(t,e)=>{for(var r in e||(e={}))BI.call(e,r)&&va(t,r,e[r]);if(af)for(var r of af(e))FI.call(e,r)&&va(t,r,e[r]);return t},Ea=(t,e)=>CI(t,NI(e)),gt=(t,e,r)=>va(t,typeof e!="symbol"?e+"":e,r);class LI extends Mg{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,gt(this,"events",new Le.exports.EventEmitter),gt(this,"name",Ix),gt(this,"queue",new Map),gt(this,"publishTimeout",L.toMiliseconds(L.ONE_MINUTE)),gt(this,"initialPublishTimeout",L.toMiliseconds(L.ONE_SECOND*15)),gt(this,"needsTransportRestart",!1),gt(this,"publish",async(n,i,s)=>{var o;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:n,message:i,opts:s}});const a=s?.ttl||Ud,c=Qi(s),u=s?.prompt||!1,l=s?.tag||0,h=s?.id||Ir().toString(),d={topic:n,message:i,opts:{ttl:a,relay:c,prompt:u,tag:l,id:h,attestation:s?.attestation,tvf:s?.tvf}},p=`Failed to publish payload, please try again. id:${h} tag:${l}`;try{const f=new Promise(async y=>{const g=({id:m})=>{d.opts.id===m&&(this.removeRequestFromQueue(m),this.relayer.events.removeListener(Ie.publish,g),y(d))};this.relayer.events.on(Ie.publish,g);const w=rr(new Promise((m,b)=>{this.rpcPublish({topic:n,message:i,ttl:a,prompt:u,tag:l,id:h,attestation:s?.attestation,tvf:s?.tvf}).then(m).catch(E=>{this.logger.warn(E,E?.message),b(E)})}),this.initialPublishTimeout,`Failed initial publish, retrying.... id:${h} tag:${l}`);try{await w,this.events.removeListener(Ie.publish,g)}catch(m){this.queue.set(h,Ea(as({},d),{attempt:1})),this.logger.warn(m,m?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:h,topic:n,message:i,opts:s}}),await rr(f,this.publishTimeout,p)}catch(f){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(f),(o=s?.internal)!=null&&o.throwOnFailedPublish)throw f}finally{this.queue.delete(h)}}),gt(this,"on",(n,i)=>{this.events.on(n,i)}),gt(this,"once",(n,i)=>{this.events.once(n,i)}),gt(this,"off",(n,i)=>{this.events.off(n,i)}),gt(this,"removeListener",(n,i)=>{this.events.removeListener(n,i)}),this.relayer=e,this.logger=je(r,this.name),this.registerEventListeners()}get context(){return He(this.logger)}async rpcPublish(e){var r,n,i,s;const{topic:o,message:a,ttl:c=Ud,prompt:u,tag:l,id:h,attestation:d,tvf:p}=e,f={method:Wn(Qi().protocol).publish,params:as({topic:o,message:a,ttl:c,prompt:u,tag:l,attestation:d},p),id:h};Re((r=f.params)==null?void 0:r.prompt)&&((n=f.params)==null||delete n.prompt),Re((i=f.params)==null?void 0:i.tag)&&((s=f.params)==null||delete s.tag),this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:f});const y=await this.relayer.request(f);return this.relayer.events.emit(Ie.publish,e),this.logger.debug("Successfully Published Payload"),y}removeRequestFromQueue(e){this.queue.delete(e)}checkQueue(){this.queue.forEach(async(e,r)=>{const n=e.attempt+1;this.queue.set(r,Ea(as({},e),{attempt:n}));const{topic:i,message:s,opts:o,attestation:a}=e;this.logger.warn({},`Publisher: queue->publishing: ${e.opts.id}, tag: ${e.opts.tag}, attempt: ${n}`),await this.rpcPublish(Ea(as({},e),{topic:i,message:s,ttl:o.ttl,prompt:o.prompt,tag:o.tag,id:o.id,attestation:a,tvf:o.tvf})),this.logger.warn({},`Publisher: queue->published: ${e.opts.id}`)})}registerEventListeners(){this.relayer.core.heartbeat.on(Cr.pulse,()=>{if(this.needsTransportRestart){this.needsTransportRestart=!1,this.relayer.events.emit(Ie.connection_stalled);return}this.checkQueue()}),this.relayer.on(Ie.message_ack,e=>{this.removeRequestFromQueue(e.id.toString())})}}var UI=Object.defineProperty,kI=(t,e,r)=>e in t?UI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,hn=(t,e,r)=>kI(t,typeof e!="symbol"?e+"":e,r);class MI{constructor(){hn(this,"map",new Map),hn(this,"set",(e,r)=>{const n=this.get(e);this.exists(e,r)||this.map.set(e,[...n,r])}),hn(this,"get",e=>this.map.get(e)||[]),hn(this,"exists",(e,r)=>this.get(e).includes(r)),hn(this,"delete",(e,r)=>{if(typeof r>"u"){this.map.delete(e);return}if(!this.map.has(e))return;const n=this.get(e);if(!this.exists(e,r))return;const i=n.filter(s=>s!==r);if(!i.length){this.map.delete(e);return}this.map.set(e,i)}),hn(this,"clear",()=>{this.map.clear()})}get topics(){return Array.from(this.map.keys())}}var jI=Object.defineProperty,qI=Object.defineProperties,zI=Object.getOwnPropertyDescriptors,cf=Object.getOwnPropertySymbols,VI=Object.prototype.hasOwnProperty,KI=Object.prototype.propertyIsEnumerable,_a=(t,e,r)=>e in t?jI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ri=(t,e)=>{for(var r in e||(e={}))VI.call(e,r)&&_a(t,r,e[r]);if(cf)for(var r of cf(e))KI.call(e,r)&&_a(t,r,e[r]);return t},Sa=(t,e)=>qI(t,zI(e)),ne=(t,e,r)=>_a(t,typeof e!="symbol"?e+"":e,r);class HI extends zg{constructor(e,r){super(e,r),this.relayer=e,this.logger=r,ne(this,"subscriptions",new Map),ne(this,"topicMap",new MI),ne(this,"events",new Le.exports.EventEmitter),ne(this,"name",Rx),ne(this,"version",Cx),ne(this,"pending",new Map),ne(this,"cached",[]),ne(this,"initialized",!1),ne(this,"storagePrefix",Dt),ne(this,"subscribeTimeout",L.toMiliseconds(L.ONE_MINUTE)),ne(this,"initialSubscribeTimeout",L.toMiliseconds(L.ONE_SECOND*15)),ne(this,"clientId"),ne(this,"batchSubscribeTopicsLimit",500),ne(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),await this.restore()),this.initialized=!0}),ne(this,"subscribe",async(n,i)=>{this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:n,opts:i}});try{const s=Qi(i),o={topic:n,relay:s,transportType:i?.transportType};this.pending.set(n,o);const a=await this.rpcSubscribe(n,s,i);return typeof a=="string"&&(this.onSubscribe(a,o),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:n,opts:i}})),a}catch(s){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(s),s}}),ne(this,"unsubscribe",async(n,i)=>{this.isInitialized(),typeof i?.id<"u"?await this.unsubscribeById(n,i.id,i):await this.unsubscribeByTopic(n,i)}),ne(this,"isSubscribed",n=>new Promise(i=>{i(this.topicMap.topics.includes(n))})),ne(this,"isKnownTopic",n=>new Promise(i=>{i(this.topicMap.topics.includes(n)||this.pending.has(n)||this.cached.some(s=>s.topic===n))})),ne(this,"on",(n,i)=>{this.events.on(n,i)}),ne(this,"once",(n,i)=>{this.events.once(n,i)}),ne(this,"off",(n,i)=>{this.events.off(n,i)}),ne(this,"removeListener",(n,i)=>{this.events.removeListener(n,i)}),ne(this,"start",async()=>{await this.onConnect()}),ne(this,"stop",async()=>{await this.onDisconnect()}),ne(this,"restart",async()=>{await this.restore(),await this.onRestart()}),ne(this,"checkPending",async()=>{if(this.pending.size===0&&(!this.initialized||!this.relayer.connected))return;const n=[];this.pending.forEach(i=>{n.push(i)}),await this.batchSubscribe(n)}),ne(this,"registerEventListeners",()=>{this.relayer.core.heartbeat.on(Cr.pulse,async()=>{await this.checkPending()}),this.events.on(rt.created,async n=>{const i=rt.created;this.logger.info(`Emitting ${i}`),this.logger.debug({type:"event",event:i,data:n}),await this.persist()}),this.events.on(rt.deleted,async n=>{const i=rt.deleted;this.logger.info(`Emitting ${i}`),this.logger.debug({type:"event",event:i,data:n}),await this.persist()})}),this.relayer=e,this.logger=je(r,this.name),this.clientId=""}get context(){return He(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}get hasAnyTopics(){return this.topicMap.topics.length>0||this.pending.size>0||this.cached.length>0||this.subscriptions.size>0}hasSubscription(e,r){let n=!1;try{n=this.getSubscription(e).topic===r}catch{}return n}reset(){this.cached=[],this.initialized=!0}onDisable(){this.cached=this.values,this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(e,r){const n=this.topicMap.get(e);await Promise.all(n.map(async i=>await this.unsubscribeById(e,i,r)))}async unsubscribeById(e,r,n){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:n}});try{const i=Qi(n);await this.restartToComplete({topic:e,id:r,relay:i}),await this.rpcUnsubscribe(e,r,i);const s=oe("USER_DISCONNECTED",`${this.name}, ${e}`);await this.onUnsubscribe(e,r,s),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:r,opts:n}})}catch(i){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(i),i}}async rpcSubscribe(e,r,n){var i;(!n||n?.transportType===ce.relay)&&await this.restartToComplete({topic:e,id:e,relay:r});const s={method:Wn(r.protocol).subscribe,params:{topic:e}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:s});const o=(i=n?.internal)==null?void 0:i.throwOnFailedPublish;try{const a=await this.getSubscriptionId(e);if(n?.transportType===ce.link_mode)return setTimeout(()=>{(this.relayer.connected||this.relayer.connecting)&&this.relayer.request(s).catch(l=>this.logger.warn(l))},L.toMiliseconds(L.ONE_SECOND)),a;const c=new Promise(async l=>{const h=d=>{d.topic===e&&(this.events.removeListener(rt.created,h),l(d.id))};this.events.on(rt.created,h);try{const d=await rr(new Promise((p,f)=>{this.relayer.request(s).catch(y=>{this.logger.warn(y,y?.message),f(y)}).then(p)}),this.initialSubscribeTimeout,`Subscribing to ${e} failed, please try again`);this.events.removeListener(rt.created,h),l(d)}catch{}}),u=await rr(c,this.subscribeTimeout,`Subscribing to ${e} failed, please try again`);if(!u&&o)throw new Error(`Subscribing to ${e} failed, please try again`);return u?a:null}catch(a){if(this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(Ie.connection_stalled),o)throw a}return null}async rpcBatchSubscribe(e){if(!e.length)return;const r=e[0].relay,n={method:Wn(r.protocol).batchSubscribe,params:{topics:e.map(i=>i.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});try{await await rr(new Promise(i=>{this.relayer.request(n).catch(s=>this.logger.warn(s)).then(i)}),this.subscribeTimeout,"rpcBatchSubscribe failed, please try again")}catch{this.relayer.events.emit(Ie.connection_stalled)}}async rpcBatchFetchMessages(e){if(!e.length)return;const r=e[0].relay,n={method:Wn(r.protocol).batchFetchMessages,params:{topics:e.map(s=>s.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:n});let i;try{i=await await rr(new Promise((s,o)=>{this.relayer.request(n).catch(a=>{this.logger.warn(a),o(a)}).then(s)}),this.subscribeTimeout,"rpcBatchFetchMessages failed, please try again")}catch{this.relayer.events.emit(Ie.connection_stalled)}return i}rpcUnsubscribe(e,r,n){const i={method:Wn(n.protocol).unsubscribe,params:{topic:e,id:r}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.request(i)}onSubscribe(e,r){this.setSubscription(e,Sa(ri({},r),{id:e})),this.pending.delete(r.topic)}onBatchSubscribe(e){e.length&&e.forEach(r=>{this.setSubscription(r.id,ri({},r)),this.pending.delete(r.topic)})}async onUnsubscribe(e,r,n){this.events.removeAllListeners(r),this.hasSubscription(r,e)&&this.deleteSubscription(r,n),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,r){this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:r}),this.addSubscription(e,r)}addSubscription(e,r){this.subscriptions.set(e,ri({},r)),this.topicMap.set(r.topic,e),this.events.emit(rt.created,r)}getSubscription(e){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const r=this.subscriptions.get(e);if(!r){const{message:n}=U("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(n)}return r}deleteSubscription(e,r){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:r});const n=this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(n.topic,e),this.events.emit(rt.deleted,Sa(ri({},n),{reason:r}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit(rt.sync)}async onRestart(){if(this.cached.length){const e=[...this.cached],r=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let n=0;n<r;n++){const i=e.splice(0,this.batchSubscribeTopicsLimit);await this.batchSubscribe(i)}}this.events.emit(rt.resubscribed)}async restore(){try{const e=await this.getRelayerSubscriptions();if(typeof e>"u"||!e.length)return;if(this.subscriptions.size){const{message:r}=U("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(r)}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){e.length&&(await this.rpcBatchSubscribe(e),this.onBatchSubscribe(await Promise.all(e.map(async r=>Sa(ri({},r),{id:await this.getSubscriptionId(r.topic)})))))}async batchFetchMessages(e){if(!e.length)return;this.logger.trace(`Fetching batch messages for ${e.length} subscriptions`);const r=await this.rpcBatchFetchMessages(e);r&&r.messages&&(await _E(L.toMiliseconds(L.ONE_SECOND)),await this.relayer.handleBatchMessageEvents(r.messages))}async onConnect(){await this.restart(),this.reset()}onDisconnect(){this.onDisable()}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}async restartToComplete(e){!this.relayer.connected&&!this.relayer.connecting&&(this.cached.push(e),await this.relayer.transportOpen())}async getClientId(){return this.clientId||(this.clientId=await this.relayer.core.crypto.getClientId()),this.clientId}async getSubscriptionId(e){return St(e+await this.getClientId())}}var WI=Object.defineProperty,uf=Object.getOwnPropertySymbols,GI=Object.prototype.hasOwnProperty,YI=Object.prototype.propertyIsEnumerable,xa=(t,e,r)=>e in t?WI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lf=(t,e)=>{for(var r in e||(e={}))GI.call(e,r)&&xa(t,r,e[r]);if(uf)for(var r of uf(e))YI.call(e,r)&&xa(t,r,e[r]);return t},X=(t,e,r)=>xa(t,typeof e!="symbol"?e+"":e,r);class ZI extends jg{constructor(e){super(e),X(this,"protocol","wc"),X(this,"version",2),X(this,"core"),X(this,"logger"),X(this,"events",new Le.exports.EventEmitter),X(this,"provider"),X(this,"messages"),X(this,"subscriber"),X(this,"publisher"),X(this,"name",Ox),X(this,"transportExplicitlyClosed",!1),X(this,"initialized",!1),X(this,"connectionAttemptInProgress",!1),X(this,"relayUrl"),X(this,"projectId"),X(this,"packageName"),X(this,"bundleId"),X(this,"hasExperiencedNetworkDisruption",!1),X(this,"pingTimeout"),X(this,"heartBeatTimeout",L.toMiliseconds(L.THIRTY_SECONDS+L.FIVE_SECONDS)),X(this,"reconnectTimeout"),X(this,"connectPromise"),X(this,"reconnectInProgress",!1),X(this,"requestsInFlight",[]),X(this,"connectTimeout",L.toMiliseconds(L.ONE_SECOND*15)),X(this,"request",async r=>{var n,i;this.logger.debug("Publishing Request Payload");const s=r.id||Ir().toString();await this.toEstablishConnection();try{this.logger.trace({id:s,method:r.method,topic:(n=r.params)==null?void 0:n.topic},"relayer.request - publishing...");const o=`${s}:${((i=r.params)==null?void 0:i.tag)||""}`;this.requestsInFlight.push(o);const a=await this.provider.request(r);return this.requestsInFlight=this.requestsInFlight.filter(c=>c!==o),a}catch(o){throw this.logger.debug(`Failed to Publish Request: ${s}`),o}}),X(this,"resetPingTimeout",()=>{ji()&&(clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{var r,n,i,s;try{this.logger.debug({},"pingTimeout: Connection stalled, terminating..."),(s=(i=(n=(r=this.provider)==null?void 0:r.connection)==null?void 0:n.socket)==null?void 0:i.terminate)==null||s.call(i)}catch(o){this.logger.warn(o,o?.message)}},this.heartBeatTimeout))}),X(this,"onPayloadHandler",r=>{this.onProviderPayload(r),this.resetPingTimeout()}),X(this,"onConnectHandler",()=>{this.logger.warn({},"Relayer connected \u{1F6DC}"),this.startPingTimeout(),this.events.emit(Ie.connect)}),X(this,"onDisconnectHandler",()=>{this.logger.warn({},"Relayer disconnected \u{1F6D1}"),this.requestsInFlight=[],this.onProviderDisconnect()}),X(this,"onProviderErrorHandler",r=>{this.logger.fatal(`Fatal socket error: ${r.message}`),this.events.emit(Ie.error,r),this.logger.fatal("Fatal socket error received, closing transport"),this.transportClose()}),X(this,"registerProviderListeners",()=>{this.provider.on(at.payload,this.onPayloadHandler),this.provider.on(at.connect,this.onConnectHandler),this.provider.on(at.disconnect,this.onDisconnectHandler),this.provider.on(at.error,this.onProviderErrorHandler)}),this.core=e.core,this.logger=typeof e.logger<"u"&&typeof e.logger!="string"?je(e.logger,this.name):Pt(Is({level:e.logger||Dx})),this.messages=new TI(this.logger,e.core),this.subscriber=new HI(this,this.logger),this.publisher=new LI(this,this.logger),this.relayUrl=e?.relayUrl||Md,this.projectId=e.projectId,sE()?this.packageName=eh():oE()&&(this.bundleId=eh()),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.hasAnyTopics)try{await this.transportOpen()}catch(e){this.logger.warn(e,e?.message)}}get context(){return He(this.logger)}get connected(){var e,r,n;return((n=(r=(e=this.provider)==null?void 0:e.connection)==null?void 0:r.socket)==null?void 0:n.readyState)===1||!1}get connecting(){var e,r,n;return((n=(r=(e=this.provider)==null?void 0:e.connection)==null?void 0:r.socket)==null?void 0:n.readyState)===0||this.connectPromise!==void 0||!1}async publish(e,r,n){this.isInitialized(),await this.publisher.publish(e,r,n),await this.recordMessageEvent({topic:e,message:r,publishedAt:Date.now(),transportType:ce.relay},ss.outbound)}async subscribe(e,r){var n,i,s;this.isInitialized(),(!(r!=null&&r.transportType)||r?.transportType==="relay")&&await this.toEstablishConnection();const o=typeof((n=r?.internal)==null?void 0:n.throwOnFailedPublish)>"u"?!0:(i=r?.internal)==null?void 0:i.throwOnFailedPublish;let a=((s=this.subscriber.topicMap.get(e))==null?void 0:s[0])||"",c;const u=l=>{l.topic===e&&(this.subscriber.off(rt.created,u),c())};return await Promise.all([new Promise(l=>{c=l,this.subscriber.on(rt.created,u)}),new Promise(async(l,h)=>{a=await this.subscriber.subscribe(e,lf({internal:{throwOnFailedPublish:o}},r)).catch(d=>{o&&h(d)})||a,l()})]),a}async unsubscribe(e,r){this.isInitialized(),await this.subscriber.unsubscribe(e,r)}on(e,r){this.events.on(e,r)}once(e,r){this.events.once(e,r)}off(e,r){this.events.off(e,r)}removeListener(e,r){this.events.removeListener(e,r)}async transportDisconnect(){this.provider.disconnect&&(this.hasExperiencedNetworkDisruption||this.connected)?await rr(this.provider.disconnect(),2e3,"provider.disconnect()").catch(()=>this.onProviderDisconnect()):this.onProviderDisconnect()}async transportClose(){this.transportExplicitlyClosed=!0,await this.transportDisconnect()}async transportOpen(e){if(!this.subscriber.hasAnyTopics){this.logger.warn("Starting WS connection skipped because the client has no topics to work with.");return}if(this.connectPromise?(this.logger.debug({},"Waiting for existing connection attempt to resolve..."),await this.connectPromise,this.logger.debug({},"Existing connection attempt resolved")):(this.connectPromise=new Promise(async(r,n)=>{await this.connect(e).then(r).catch(n).finally(()=>{this.connectPromise=void 0})}),await this.connectPromise),!this.connected)throw new Error(`Couldn't establish socket connection to the relay server: ${this.relayUrl}`)}async restartTransport(e){this.logger.debug({},"Restarting transport..."),!this.connectionAttemptInProgress&&(this.relayUrl=e||this.relayUrl,await this.confirmOnlineStateOrThrow(),await this.transportClose(),await this.transportOpen())}async confirmOnlineStateOrThrow(){if(!await Sd())throw new Error("No internet connection detected. Please restart your network and try again.")}async handleBatchMessageEvents(e){if(e?.length===0){this.logger.trace("Batch message events is empty. Ignoring...");return}const r=e.sort((n,i)=>n.publishedAt-i.publishedAt);this.logger.debug(`Batch of ${r.length} message events sorted`);for(const n of r)try{await this.onMessageEvent(n)}catch(i){this.logger.warn(i,"Error while processing batch message event: "+i?.message)}this.logger.trace(`Batch of ${r.length} message events processed`)}async onLinkMessageEvent(e,r){const{topic:n}=e;if(!r.sessionExists){const i=me(L.FIVE_MINUTES),s={topic:n,expiry:i,relay:{protocol:"irn"},active:!1};await this.core.pairing.pairings.set(n,s)}this.events.emit(Ie.message,e),await this.recordMessageEvent(e,ss.inbound)}async connect(e){await this.confirmOnlineStateOrThrow(),e&&e!==this.relayUrl&&(this.relayUrl=e,await this.transportDisconnect()),this.connectionAttemptInProgress=!0,this.transportExplicitlyClosed=!1;let r=1;for(;r<6;){try{if(this.transportExplicitlyClosed)break;this.logger.debug({},`Connecting to ${this.relayUrl}, attempt: ${r}...`),await this.createProvider(),await new Promise(async(n,i)=>{const s=()=>{i(new Error("Connection interrupted while trying to subscribe"))};this.provider.once(at.disconnect,s),await rr(new Promise((o,a)=>{this.provider.connect().then(o).catch(a)}),this.connectTimeout,`Socket stalled when trying to connect to ${this.relayUrl}`).catch(o=>{i(o)}).finally(()=>{this.provider.off(at.disconnect,s),clearTimeout(this.reconnectTimeout)}),await new Promise(async(o,a)=>{const c=()=>{a(new Error("Connection interrupted while trying to subscribe"))};this.provider.once(at.disconnect,c),await this.subscriber.start().then(o).catch(a).finally(()=>{this.provider.off(at.disconnect,c)})}),this.hasExperiencedNetworkDisruption=!1,n()})}catch(n){await this.subscriber.stop();const i=n;this.logger.warn({},i.message),this.hasExperiencedNetworkDisruption=!0}finally{this.connectionAttemptInProgress=!1}if(this.connected){this.logger.debug({},`Connected to ${this.relayUrl} successfully on attempt: ${r}`);break}await new Promise(n=>setTimeout(n,L.toMiliseconds(r*1))),r++}}startPingTimeout(){var e,r,n,i,s;if(ji())try{(r=(e=this.provider)==null?void 0:e.connection)!=null&&r.socket&&((s=(i=(n=this.provider)==null?void 0:n.connection)==null?void 0:i.socket)==null||s.on("ping",()=>{this.resetPingTimeout()})),this.resetPingTimeout()}catch(o){this.logger.warn(o,o?.message)}}async createProvider(){this.provider.connection&&this.unregisterProviderListeners();const e=await this.core.crypto.signJWT(this.relayUrl);this.provider=new dx(new yx(hE({sdkVersion:ga,protocol:this.protocol,version:this.version,relayUrl:this.relayUrl,projectId:this.projectId,auth:e,useOnCloseEvent:!0,bundleId:this.bundleId,packageName:this.packageName}))),this.registerProviderListeners()}async recordMessageEvent(e,r){const{topic:n,message:i}=e;await this.messages.set(n,i,r)}async shouldIgnoreMessageEvent(e){const{topic:r,message:n}=e;if(!n||n.length===0)return this.logger.warn(`Ignoring invalid/empty message: ${n}`),!0;if(!await this.subscriber.isKnownTopic(r))return this.logger.warn(`Ignoring message for unknown topic ${r}`),!0;const i=this.messages.has(r,n);return i&&this.logger.warn(`Ignoring duplicate message: ${n}`),i}async onProviderPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),pa(e)){if(!e.method.endsWith($x))return;const r=e.params,{topic:n,message:i,publishedAt:s,attestation:o}=r.data,a={topic:n,message:i,publishedAt:s,transportType:ce.relay,attestation:o};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(lf({type:"event",event:r.id},a)),this.events.emit(r.id,a),await this.acknowledgePayload(e),await this.onMessageEvent(a)}else ns(e)&&this.events.emit(Ie.message_ack,e)}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(await this.recordMessageEvent(e,ss.inbound),this.events.emit(Ie.message,e))}async acknowledgePayload(e){const r=da(e.id,!0);await this.provider.connection.send(r)}unregisterProviderListeners(){this.provider.off(at.payload,this.onPayloadHandler),this.provider.off(at.connect,this.onConnectHandler),this.provider.off(at.disconnect,this.onDisconnectHandler),this.provider.off(at.error,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let e=await Sd();xS(async r=>{e!==r&&(e=r,r?await this.transportOpen().catch(n=>this.logger.error(n,n?.message)):(this.hasExperiencedNetworkDisruption=!0,await this.transportDisconnect(),this.transportExplicitlyClosed=!1))})}async onProviderDisconnect(){clearTimeout(this.pingTimeout),this.events.emit(Ie.disconnect),this.connectionAttemptInProgress=!1,!this.reconnectInProgress&&(this.reconnectInProgress=!0,await this.subscriber.stop(),this.subscriber.hasAnyTopics&&(this.transportExplicitlyClosed||(this.reconnectTimeout=setTimeout(async()=>{await this.transportOpen().catch(e=>this.logger.error(e,e?.message)),this.reconnectTimeout=void 0,this.reconnectInProgress=!1},L.toMiliseconds(Ax)))))}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}async toEstablishConnection(){await this.confirmOnlineStateOrThrow(),!this.connected&&await this.connect()}}function JI(){}function hf(t){if(!t||typeof t!="object")return!1;const e=Object.getPrototypeOf(t);return e===null||e===Object.prototype||Object.getPrototypeOf(e)===null?Object.prototype.toString.call(t)==="[object Object]":!1}function df(t){return Object.getOwnPropertySymbols(t).filter(e=>Object.prototype.propertyIsEnumerable.call(t,e))}function ff(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const XI="[object RegExp]",QI="[object String]",e8="[object Number]",t8="[object Boolean]",pf="[object Arguments]",r8="[object Symbol]",n8="[object Date]",i8="[object Map]",s8="[object Set]",o8="[object Array]",a8="[object Function]",c8="[object ArrayBuffer]",Ia="[object Object]",u8="[object Error]",l8="[object DataView]",h8="[object Uint8Array]",d8="[object Uint8ClampedArray]",f8="[object Uint16Array]",p8="[object Uint32Array]",g8="[object BigUint64Array]",y8="[object Int8Array]",w8="[object Int16Array]",m8="[object Int32Array]",b8="[object BigInt64Array]",v8="[object Float32Array]",E8="[object Float64Array]";function _8(t,e){return t===e||Number.isNaN(t)&&Number.isNaN(e)}function S8(t,e,r){return ni(t,e,void 0,void 0,void 0,void 0,r)}function ni(t,e,r,n,i,s,o){const a=o(t,e,r,n,i,s);if(a!==void 0)return a;if(typeof t==typeof e)switch(typeof t){case"bigint":case"string":case"boolean":case"symbol":case"undefined":return t===e;case"number":return t===e||Object.is(t,e);case"function":return t===e;case"object":return ii(t,e,s,o)}return ii(t,e,s,o)}function ii(t,e,r,n){if(Object.is(t,e))return!0;let i=ff(t),s=ff(e);if(i===pf&&(i=Ia),s===pf&&(s=Ia),i!==s)return!1;switch(i){case QI:return t.toString()===e.toString();case e8:{const c=t.valueOf(),u=e.valueOf();return _8(c,u)}case t8:case n8:case r8:return Object.is(t.valueOf(),e.valueOf());case XI:return t.source===e.source&&t.flags===e.flags;case a8:return t===e}r=r??new Map;const o=r.get(t),a=r.get(e);if(o!=null&&a!=null)return o===e;r.set(t,e),r.set(e,t);try{switch(i){case i8:{if(t.size!==e.size)return!1;for(const[c,u]of t.entries())if(!e.has(c)||!ni(u,e.get(c),c,t,e,r,n))return!1;return!0}case s8:{if(t.size!==e.size)return!1;const c=Array.from(t.values()),u=Array.from(e.values());for(let l=0;l<c.length;l++){const h=c[l],d=u.findIndex(p=>ni(h,p,void 0,t,e,r,n));if(d===-1)return!1;u.splice(d,1)}return!0}case o8:case h8:case d8:case f8:case p8:case g8:case y8:case w8:case m8:case b8:case v8:case E8:{if(typeof Buffer<"u"&&Buffer.isBuffer(t)!==Buffer.isBuffer(e)||t.length!==e.length)return!1;for(let c=0;c<t.length;c++)if(!ni(t[c],e[c],c,t,e,r,n))return!1;return!0}case c8:return t.byteLength!==e.byteLength?!1:ii(new Uint8Array(t),new Uint8Array(e),r,n);case l8:return t.byteLength!==e.byteLength||t.byteOffset!==e.byteOffset?!1:ii(new Uint8Array(t),new Uint8Array(e),r,n);case u8:return t.name===e.name&&t.message===e.message;case Ia:{if(!(ii(t.constructor,e.constructor,r,n)||hf(t)&&hf(e)))return!1;const c=[...Object.keys(t),...df(t)],u=[...Object.keys(e),...df(e)];if(c.length!==u.length)return!1;for(let l=0;l<c.length;l++){const h=c[l],d=t[h];if(!Object.hasOwn(e,h))return!1;const p=e[h];if(!ni(d,p,h,t,e,r,n))return!1}return!0}default:return!1}}finally{r.delete(t),r.delete(e)}}function x8(t,e){return S8(t,e,JI)}var I8=Object.defineProperty,gf=Object.getOwnPropertySymbols,D8=Object.prototype.hasOwnProperty,O8=Object.prototype.propertyIsEnumerable,Da=(t,e,r)=>e in t?I8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yf=(t,e)=>{for(var r in e||(e={}))D8.call(e,r)&&Da(t,r,e[r]);if(gf)for(var r of gf(e))O8.call(e,r)&&Da(t,r,e[r]);return t},Je=(t,e,r)=>Da(t,typeof e!="symbol"?e+"":e,r);class Pr extends qg{constructor(e,r,n,i=Dt,s=void 0){super(e,r,n,i),this.core=e,this.logger=r,this.name=n,Je(this,"map",new Map),Je(this,"version",Px),Je(this,"cached",[]),Je(this,"initialized",!1),Je(this,"getKey"),Je(this,"storagePrefix",Dt),Je(this,"recentlyDeleted",[]),Je(this,"recentlyDeletedLimit",200),Je(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(o=>{this.getKey&&o!==null&&!Re(o)?this.map.set(this.getKey(o),o):tS(o)?this.map.set(o.id,o):rS(o)&&this.map.set(o.topic,o)}),this.cached=[],this.initialized=!0)}),Je(this,"set",async(o,a)=>{this.isInitialized(),this.map.has(o)?await this.update(o,a):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:o,value:a}),this.map.set(o,a),await this.persist())}),Je(this,"get",o=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:o}),this.getData(o))),Je(this,"getAll",o=>(this.isInitialized(),o?this.values.filter(a=>Object.keys(o).every(c=>x8(a[c],o[c]))):this.values)),Je(this,"update",async(o,a)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:o,update:a});const c=yf(yf({},this.getData(o)),a);this.map.set(o,c),await this.persist()}),Je(this,"delete",async(o,a)=>{this.isInitialized(),this.map.has(o)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:o,reason:a}),this.map.delete(o),this.addToRecentlyDeleted(o),await this.persist())}),this.logger=je(r,this.name),this.storagePrefix=i,this.getKey=s}get context(){return He(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 r=this.map.get(e);if(!r){if(this.recentlyDeleted.includes(e)){const{message:i}=U("MISSING_OR_INVALID",`Record was recently deleted - ${this.name}: ${e}`);throw this.logger.error(i),new Error(i)}const{message:n}=U("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(n),new Error(n)}return r}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:r}=U("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}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}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var $8=Object.defineProperty,A8=(t,e,r)=>e in t?$8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Y=(t,e,r)=>A8(t,typeof e!="symbol"?e+"":e,r);class P8{constructor(e,r){this.core=e,this.logger=r,Y(this,"name",Nx),Y(this,"version",Bx),Y(this,"events",new Le.exports),Y(this,"pairings"),Y(this,"initialized",!1),Y(this,"storagePrefix",Dt),Y(this,"ignoredPayloadTypes",[jt]),Y(this,"registeredMethods",[]),Y(this,"init",async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))}),Y(this,"register",({methods:n})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...n])]}),Y(this,"create",async n=>{this.isInitialized();const i=ia(),s=await this.core.crypto.setSymKey(i),o=me(L.FIVE_MINUTES),a={protocol:kd},c={topic:s,expiry:o,relay:a,active:!1,methods:n?.methods},u=gd({protocol:this.core.protocol,version:this.core.version,topic:s,symKey:i,relay:a,expiryTimestamp:o,methods:n?.methods});return this.events.emit(Or.create,c),this.core.expirer.set(s,o),await this.pairings.set(s,c),await this.core.relayer.subscribe(s,{transportType:n?.transportType}),{topic:s,uri:u}}),Y(this,"pair",async n=>{this.isInitialized();const i=this.core.eventClient.createEvent({properties:{topic:n?.uri,trace:[Ot.pairing_started]}});this.isValidPair(n,i);const{topic:s,symKey:o,relay:a,expiryTimestamp:c,methods:u}=pd(n.uri);i.props.properties.topic=s,i.addTrace(Ot.pairing_uri_validation_success),i.addTrace(Ot.pairing_uri_not_expired);let l;if(this.pairings.keys.includes(s)){if(l=this.pairings.get(s),i.addTrace(Ot.existing_pairing),l.active)throw i.setError(Vt.active_pairing_already_exists),new Error(`Pairing already exists: ${s}. Please try again with a new connection URI.`);i.addTrace(Ot.pairing_not_expired)}const h=c||me(L.FIVE_MINUTES),d={topic:s,relay:a,expiry:h,active:!1,methods:u};this.core.expirer.set(s,h),await this.pairings.set(s,d),i.addTrace(Ot.store_new_pairing),n.activatePairing&&await this.activate({topic:s}),this.events.emit(Or.create,d),i.addTrace(Ot.emit_inactive_pairing),this.core.crypto.keychain.has(s)||await this.core.crypto.setSymKey(o,s),i.addTrace(Ot.subscribing_pairing_topic);try{await this.core.relayer.confirmOnlineStateOrThrow()}catch{i.setError(Vt.no_internet_connection)}try{await this.core.relayer.subscribe(s,{relay:a})}catch(p){throw i.setError(Vt.subscribe_pairing_topic_failure),p}return i.addTrace(Ot.subscribe_pairing_topic_success),d}),Y(this,"activate",async({topic:n})=>{this.isInitialized();const i=me(L.FIVE_MINUTES);this.core.expirer.set(n,i),await this.pairings.update(n,{active:!0,expiry:i})}),Y(this,"ping",async n=>{this.isInitialized(),await this.isValidPing(n),this.logger.warn("ping() is deprecated and will be removed in the next major release.");const{topic:i}=n;if(this.pairings.keys.includes(i)){const s=await this.sendRequest(i,"wc_pairingPing",{}),{done:o,resolve:a,reject:c}=br();this.events.once(Q("pairing_ping",s),({error:u})=>{u?c(u):a()}),await o()}}),Y(this,"updateExpiry",async({topic:n,expiry:i})=>{this.isInitialized(),await this.pairings.update(n,{expiry:i})}),Y(this,"updateMetadata",async({topic:n,metadata:i})=>{this.isInitialized(),await this.pairings.update(n,{peerMetadata:i})}),Y(this,"getPairings",()=>(this.isInitialized(),this.pairings.values)),Y(this,"disconnect",async n=>{this.isInitialized(),await this.isValidDisconnect(n);const{topic:i}=n;this.pairings.keys.includes(i)&&(await this.sendRequest(i,"wc_pairingDelete",oe("USER_DISCONNECTED")),await this.deletePairing(i))}),Y(this,"formatUriFromPairing",n=>{this.isInitialized();const{topic:i,relay:s,expiry:o,methods:a}=n,c=this.core.crypto.keychain.get(i);return gd({protocol:this.core.protocol,version:this.core.version,topic:i,symKey:c,relay:s,expiryTimestamp:o,methods:a})}),Y(this,"sendRequest",async(n,i,s)=>{const o=Dr(i,s),a=await this.core.crypto.encode(n,o),c=Xn[i].req;return this.core.history.set(n,o),this.core.relayer.publish(n,a,c),o.id}),Y(this,"sendResult",async(n,i,s)=>{const o=da(n,s),a=await this.core.crypto.encode(i,o),c=(await this.core.history.get(i,n)).request.method,u=Xn[c].res;await this.core.relayer.publish(i,a,u),await this.core.history.resolve(o)}),Y(this,"sendError",async(n,i,s)=>{const o=fa(n,s),a=await this.core.crypto.encode(i,o),c=(await this.core.history.get(i,n)).request.method,u=Xn[c]?Xn[c].res:Xn.unregistered_method.res;await this.core.relayer.publish(i,a,u),await this.core.history.resolve(o)}),Y(this,"deletePairing",async(n,i)=>{await this.core.relayer.unsubscribe(n),await Promise.all([this.pairings.delete(n,oe("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(n),i?Promise.resolve():this.core.expirer.del(n)])}),Y(this,"cleanup",async()=>{const n=this.pairings.getAll().filter(i=>nr(i.expiry));await Promise.all(n.map(i=>this.deletePairing(i.topic)))}),Y(this,"onRelayEventRequest",async n=>{const{topic:i,payload:s}=n;switch(s.method){case"wc_pairingPing":return await this.onPairingPingRequest(i,s);case"wc_pairingDelete":return await this.onPairingDeleteRequest(i,s);default:return await this.onUnknownRpcMethodRequest(i,s)}}),Y(this,"onRelayEventResponse",async n=>{const{topic:i,payload:s}=n,o=(await this.core.history.get(i,s.id)).request.method;switch(o){case"wc_pairingPing":return this.onPairingPingResponse(i,s);default:return this.onUnknownRpcMethodResponse(o)}}),Y(this,"onPairingPingRequest",async(n,i)=>{const{id:s}=i;try{this.isValidPing({topic:n}),await this.sendResult(s,n,!0),this.events.emit(Or.ping,{id:s,topic:n})}catch(o){await this.sendError(s,n,o),this.logger.error(o)}}),Y(this,"onPairingPingResponse",(n,i)=>{const{id:s}=i;setTimeout(()=>{It(i)?this.events.emit(Q("pairing_ping",s),{}):ot(i)&&this.events.emit(Q("pairing_ping",s),{error:i.error})},500)}),Y(this,"onPairingDeleteRequest",async(n,i)=>{const{id:s}=i;try{this.isValidDisconnect({topic:n}),await this.deletePairing(n),this.events.emit(Or.delete,{id:s,topic:n})}catch(o){await this.sendError(s,n,o),this.logger.error(o)}}),Y(this,"onUnknownRpcMethodRequest",async(n,i)=>{const{id:s,method:o}=i;try{if(this.registeredMethods.includes(o))return;const a=oe("WC_METHOD_UNSUPPORTED",o);await this.sendError(s,n,a),this.logger.error(a)}catch(a){await this.sendError(s,n,a),this.logger.error(a)}}),Y(this,"onUnknownRpcMethodResponse",n=>{this.registeredMethods.includes(n)||this.logger.error(oe("WC_METHOD_UNSUPPORTED",n))}),Y(this,"isValidPair",(n,i)=>{var s;if(!Ze(n)){const{message:a}=U("MISSING_OR_INVALID",`pair() params: ${n}`);throw i.setError(Vt.malformed_pairing_uri),new Error(a)}if(!eS(n.uri)){const{message:a}=U("MISSING_OR_INVALID",`pair() uri: ${n.uri}`);throw i.setError(Vt.malformed_pairing_uri),new Error(a)}const o=pd(n?.uri);if(!((s=o?.relay)!=null&&s.protocol)){const{message:a}=U("MISSING_OR_INVALID","pair() uri#relay-protocol");throw i.setError(Vt.malformed_pairing_uri),new Error(a)}if(!(o!=null&&o.symKey)){const{message:a}=U("MISSING_OR_INVALID","pair() uri#symKey");throw i.setError(Vt.malformed_pairing_uri),new Error(a)}if(o!=null&&o.expiryTimestamp&&L.toMiliseconds(o?.expiryTimestamp)<Date.now()){i.setError(Vt.pairing_expired);const{message:a}=U("EXPIRED","pair() URI has expired. Please try again with a new connection URI.");throw new Error(a)}}),Y(this,"isValidPing",async n=>{if(!Ze(n)){const{message:s}=U("MISSING_OR_INVALID",`ping() params: ${n}`);throw new Error(s)}const{topic:i}=n;await this.isValidPairingTopic(i)}),Y(this,"isValidDisconnect",async n=>{if(!Ze(n)){const{message:s}=U("MISSING_OR_INVALID",`disconnect() params: ${n}`);throw new Error(s)}const{topic:i}=n;await this.isValidPairingTopic(i)}),Y(this,"isValidPairingTopic",async n=>{if(!pe(n,!1)){const{message:i}=U("MISSING_OR_INVALID",`pairing topic should be a string: ${n}`);throw new Error(i)}if(!this.pairings.keys.includes(n)){const{message:i}=U("NO_MATCHING_KEY",`pairing topic doesn't exist: ${n}`);throw new Error(i)}if(nr(this.pairings.get(n).expiry)){await this.deletePairing(n);const{message:i}=U("EXPIRED",`pairing topic: ${n}`);throw new Error(i)}}),this.core=e,this.logger=je(r,this.name),this.pairings=new Pr(this.core,this.logger,this.name,this.storagePrefix)}get context(){return He(this.logger)}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(Ie.message,async e=>{const{topic:r,message:n,transportType:i}=e;if(this.pairings.keys.includes(r)&&i!==ce.link_mode&&!this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(n)))try{const s=await this.core.crypto.decode(r,n);pa(s)?(this.core.history.set(r,s),await this.onRelayEventRequest({topic:r,payload:s})):ns(s)&&(await this.core.history.resolve(s),await this.onRelayEventResponse({topic:r,payload:s}),this.core.history.delete(r,s.id)),await this.core.relayer.messages.ack(r,n)}catch(s){this.logger.error(s)}})}registerExpirerEvents(){this.core.expirer.on(ct.expired,async e=>{const{topic:r}=ih(e.target);r&&this.pairings.keys.includes(r)&&(await this.deletePairing(r,!0),this.events.emit(Or.expire,{topic:r}))})}}var T8=Object.defineProperty,R8=(t,e,r)=>e in t?T8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Be=(t,e,r)=>R8(t,typeof e!="symbol"?e+"":e,r);class C8 extends Ug{constructor(e,r){super(e,r),this.core=e,this.logger=r,Be(this,"records",new Map),Be(this,"events",new Le.exports.EventEmitter),Be(this,"name",Fx),Be(this,"version",Lx),Be(this,"cached",[]),Be(this,"initialized",!1),Be(this,"storagePrefix",Dt),Be(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(n=>this.records.set(n.id,n)),this.cached=[],this.registerEventListeners(),this.initialized=!0)}),Be(this,"set",(n,i,s)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:n,request:i,chainId:s}),this.records.has(i.id))return;const o={id:i.id,topic:n,request:{method:i.method,params:i.params||null},chainId:s,expiry:me(L.THIRTY_DAYS)};this.records.set(o.id,o),this.persist(),this.events.emit(ft.created,o)}),Be(this,"resolve",async n=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:n}),!this.records.has(n.id))return;const i=await this.getRecord(n.id);typeof i.response>"u"&&(i.response=ot(n)?{error:n.error}:{result:n.result},this.records.set(i.id,i),this.persist(),this.events.emit(ft.updated,i))}),Be(this,"get",async(n,i)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:n,id:i}),await this.getRecord(i))),Be(this,"delete",(n,i)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:i}),this.values.forEach(s=>{if(s.topic===n){if(typeof i<"u"&&s.id!==i)return;this.records.delete(s.id),this.events.emit(ft.deleted,s)}}),this.persist()}),Be(this,"exists",async(n,i)=>(this.isInitialized(),this.records.has(i)?(await this.getRecord(i)).topic===n:!1)),Be(this,"on",(n,i)=>{this.events.on(n,i)}),Be(this,"once",(n,i)=>{this.events.once(n,i)}),Be(this,"off",(n,i)=>{this.events.off(n,i)}),Be(this,"removeListener",(n,i)=>{this.events.removeListener(n,i)}),this.logger=je(r,this.name)}get context(){return He(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(r=>{if(typeof r.response<"u")return;const n={topic:r.topic,request:Dr(r.request.method,r.request.params,r.id),chainId:r.chainId};return e.push(n)}),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 r=this.records.get(e);if(!r){const{message:n}=U("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(n)}return r}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(ft.sync)}async restore(){try{const e=await this.getJsonRpcRecords();if(typeof e>"u"||!e.length)return;if(this.records.size){const{message:r}=U("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}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(ft.created,e=>{const r=ft.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.events.on(ft.updated,e=>{const r=ft.updated;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.events.on(ft.deleted,e=>{const r=ft.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,record:e})}),this.core.heartbeat.on(Cr.pulse,()=>{this.cleanup()})}cleanup(){try{this.isInitialized();let e=!1;this.records.forEach(r=>{L.toMiliseconds(r.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${r.id}`),this.records.delete(r.id),this.events.emit(ft.deleted,r,!1),e=!0)}),e&&this.persist()}catch(e){this.logger.warn(e)}}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var N8=Object.defineProperty,B8=(t,e,r)=>e in t?N8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ke=(t,e,r)=>B8(t,typeof e!="symbol"?e+"":e,r);class F8 extends Vg{constructor(e,r){super(e,r),this.core=e,this.logger=r,ke(this,"expirations",new Map),ke(this,"events",new Le.exports.EventEmitter),ke(this,"name",Ux),ke(this,"version",kx),ke(this,"cached",[]),ke(this,"initialized",!1),ke(this,"storagePrefix",Dt),ke(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(n=>this.expirations.set(n.target,n)),this.cached=[],this.registerEventListeners(),this.initialized=!0)}),ke(this,"has",n=>{try{const i=this.formatTarget(n);return typeof this.getExpiration(i)<"u"}catch{return!1}}),ke(this,"set",(n,i)=>{this.isInitialized();const s=this.formatTarget(n),o={target:s,expiry:i};this.expirations.set(s,o),this.checkExpiry(s,o),this.events.emit(ct.created,{target:s,expiration:o})}),ke(this,"get",n=>{this.isInitialized();const i=this.formatTarget(n);return this.getExpiration(i)}),ke(this,"del",n=>{if(this.isInitialized(),this.has(n)){const i=this.formatTarget(n),s=this.getExpiration(i);this.expirations.delete(i),this.events.emit(ct.deleted,{target:i,expiration:s})}}),ke(this,"on",(n,i)=>{this.events.on(n,i)}),ke(this,"once",(n,i)=>{this.events.once(n,i)}),ke(this,"off",(n,i)=>{this.events.off(n,i)}),ke(this,"removeListener",(n,i)=>{this.events.removeListener(n,i)}),this.logger=je(r,this.name)}get context(){return He(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 dE(e);if(typeof e=="number")return fE(e);const{message:r}=U("UNKNOWN_TYPE",`Target type: ${typeof e}`);throw new Error(r)}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(ct.sync)}async restore(){try{const e=await this.getExpirations();if(typeof e>"u"||!e.length)return;if(this.expirations.size){const{message:r}=U("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(r),new Error(r)}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 r=this.expirations.get(e);if(!r){const{message:n}=U("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.warn(n),new Error(n)}return r}checkExpiry(e,r){const{expiry:n}=r;L.toMiliseconds(n)-Date.now()<=0&&this.expire(e,r)}expire(e,r){this.expirations.delete(e),this.events.emit(ct.expired,{target:e,expiration:r})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,r)=>this.checkExpiry(r,e))}registerEventListeners(){this.core.heartbeat.on(Cr.pulse,()=>this.checkExpirations()),this.events.on(ct.created,e=>{const r=ct.created;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(ct.expired,e=>{const r=ct.expired;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()}),this.events.on(ct.deleted,e=>{const r=ct.deleted;this.logger.info(`Emitting ${r}`),this.logger.debug({type:"event",event:r,data:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}}var L8=Object.defineProperty,U8=(t,e,r)=>e in t?L8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ge=(t,e,r)=>U8(t,typeof e!="symbol"?e+"":e,r);class k8 extends Kg{constructor(e,r,n){super(e,r,n),this.core=e,this.logger=r,this.store=n,ge(this,"name",Mx),ge(this,"abortController"),ge(this,"isDevEnv"),ge(this,"verifyUrlV3",qx),ge(this,"storagePrefix",Dt),ge(this,"version",Fd),ge(this,"publicKey"),ge(this,"fetchPromise"),ge(this,"init",async()=>{var i;this.isDevEnv||(this.publicKey=await this.store.getItem(this.storeKey),this.publicKey&&L.toMiliseconds((i=this.publicKey)==null?void 0:i.expiresAt)<Date.now()&&(this.logger.debug("verify v2 public key expired"),await this.removePublicKey()))}),ge(this,"register",async i=>{if(!Cn()||this.isDevEnv)return;const s=window.location.origin,{id:o,decryptedId:a}=i,c=`${this.verifyUrlV3}/attestation?projectId=${this.core.projectId}&origin=${s}&id=${o}&decryptedId=${a}`;try{const u=_n(),l=this.startAbortTimer(L.ONE_SECOND*5),h=await new Promise((d,p)=>{const f=()=>{window.removeEventListener("message",g),u.body.removeChild(y),p("attestation aborted")};this.abortController.signal.addEventListener("abort",f);const y=u.createElement("iframe");y.src=c,y.style.display="none",y.addEventListener("error",f,{signal:this.abortController.signal});const g=w=>{if(w.data&&typeof w.data=="string")try{const m=JSON.parse(w.data);if(m.type==="verify_attestation"){if(Hs(m.attestation).payload.id!==o)return;clearInterval(l),u.body.removeChild(y),this.abortController.signal.removeEventListener("abort",f),window.removeEventListener("message",g),d(m.attestation===null?"":m.attestation)}}catch(m){this.logger.warn(m)}};u.body.appendChild(y),window.addEventListener("message",g,{signal:this.abortController.signal})});return this.logger.debug("jwt attestation",h),h}catch(u){this.logger.warn(u)}return""}),ge(this,"resolve",async i=>{if(this.isDevEnv)return"";const{attestationId:s,hash:o,encryptedId:a}=i;if(s===""){this.logger.debug("resolve: attestationId is empty, skipping");return}if(s){if(Hs(s).payload.id!==a)return;const u=await this.isValidJwtAttestation(s);if(u){if(!u.isVerified){this.logger.warn("resolve: jwt attestation: origin url not verified");return}return u}}if(!o)return;const c=this.getVerifyUrl(i?.verifyUrl);return this.fetchAttestation(o,c)}),ge(this,"fetchAttestation",async(i,s)=>{this.logger.debug(`resolving attestation: ${i} from url: ${s}`);const o=this.startAbortTimer(L.ONE_SECOND*5),a=await fetch(`${s}/attestation/${i}?v2Supported=true`,{signal:this.abortController.signal});return clearTimeout(o),a.status===200?await a.json():void 0}),ge(this,"getVerifyUrl",i=>{let s=i||Qn;return zx.includes(s)||(this.logger.info(`verify url: ${s}, not included in trusted list, assigning default: ${Qn}`),s=Qn),s}),ge(this,"fetchPublicKey",async()=>{try{this.logger.debug(`fetching public key from: ${this.verifyUrlV3}`);const i=this.startAbortTimer(L.FIVE_SECONDS),s=await fetch(`${this.verifyUrlV3}/public-key`,{signal:this.abortController.signal});return clearTimeout(i),await s.json()}catch(i){this.logger.warn(i)}}),ge(this,"persistPublicKey",async i=>{this.logger.debug("persisting public key to local storage",i),await this.store.setItem(this.storeKey,i),this.publicKey=i}),ge(this,"removePublicKey",async()=>{this.logger.debug("removing verify v2 public key from storage"),await this.store.removeItem(this.storeKey),this.publicKey=void 0}),ge(this,"isValidJwtAttestation",async i=>{const s=await this.getPublicKey();try{if(s)return this.validateAttestation(i,s)}catch(a){this.logger.error(a),this.logger.warn("error validating attestation")}const o=await this.fetchAndPersistPublicKey();try{if(o)return this.validateAttestation(i,o)}catch(a){this.logger.error(a),this.logger.warn("error validating attestation")}}),ge(this,"getPublicKey",async()=>this.publicKey?this.publicKey:await this.fetchAndPersistPublicKey()),ge(this,"fetchAndPersistPublicKey",async()=>{if(this.fetchPromise)return await this.fetchPromise,this.publicKey;this.fetchPromise=new Promise(async s=>{const o=await this.fetchPublicKey();o&&(await this.persistPublicKey(o),s(o))});const i=await this.fetchPromise;return this.fetchPromise=void 0,i}),ge(this,"validateAttestation",(i,s)=>{const o=j_(i,s.publicKey),a={hasExpired:L.toMiliseconds(o.exp)<Date.now(),payload:o};if(a.hasExpired)throw this.logger.warn("resolve: jwt attestation expired"),new Error("JWT attestation expired");return{origin:a.payload.origin,isScam:a.payload.isScam,isVerified:a.payload.isVerified}}),this.logger=je(r,this.name),this.abortController=new AbortController,this.isDevEnv=To(),this.init()}get storeKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//verify:public:key"}get context(){return He(this.logger)}startAbortTimer(e){return this.abortController=new AbortController,setTimeout(()=>this.abortController.abort(),L.toMiliseconds(e))}}var M8=Object.defineProperty,j8=(t,e,r)=>e in t?M8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,wf=(t,e,r)=>j8(t,typeof e!="symbol"?e+"":e,r);class q8 extends Hg{constructor(e,r){super(e,r),this.projectId=e,this.logger=r,wf(this,"context",Vx),wf(this,"registerDeviceToken",async n=>{const{clientId:i,token:s,notificationType:o,enableEncrypted:a=!1}=n,c=`${Kx}/${this.projectId}/clients`;await fetch(c,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({client_id:i,type:o,token:s,always_raw:a})})}),this.logger=je(r,this.context)}}var z8=Object.defineProperty,mf=Object.getOwnPropertySymbols,V8=Object.prototype.hasOwnProperty,K8=Object.prototype.propertyIsEnumerable,Oa=(t,e,r)=>e in t?z8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,si=(t,e)=>{for(var r in e||(e={}))V8.call(e,r)&&Oa(t,r,e[r]);if(mf)for(var r of mf(e))K8.call(e,r)&&Oa(t,r,e[r]);return t},De=(t,e,r)=>Oa(t,typeof e!="symbol"?e+"":e,r);class H8 extends Wg{constructor(e,r,n=!0){super(e,r,n),this.core=e,this.logger=r,De(this,"context",Wx),De(this,"storagePrefix",Dt),De(this,"storageVersion",Hx),De(this,"events",new Map),De(this,"shouldPersist",!1),De(this,"init",async()=>{if(!To())try{const i={eventId:oh(),timestamp:Date.now(),domain:this.getAppDomain(),props:{event:"INIT",type:"",properties:{client_id:await this.core.crypto.getClientId(),user_agent:rh(this.core.relayer.protocol,this.core.relayer.version,ga)}}};await this.sendEvent([i])}catch(i){this.logger.warn(i)}}),De(this,"createEvent",i=>{const{event:s="ERROR",type:o="",properties:{topic:a,trace:c}}=i,u=oh(),l=this.core.projectId||"",h=Date.now(),d=si({eventId:u,timestamp:h,props:{event:s,type:o,properties:{topic:a,trace:c}},bundleId:l,domain:this.getAppDomain()},this.setMethods(u));return this.telemetryEnabled&&(this.events.set(u,d),this.shouldPersist=!0),d}),De(this,"getEvent",i=>{const{eventId:s,topic:o}=i;if(s)return this.events.get(s);const a=Array.from(this.events.values()).find(c=>c.props.properties.topic===o);if(a)return si(si({},a),this.setMethods(a.eventId))}),De(this,"deleteEvent",i=>{const{eventId:s}=i;this.events.delete(s),this.shouldPersist=!0}),De(this,"setEventListeners",()=>{this.core.heartbeat.on(Cr.pulse,async()=>{this.shouldPersist&&await this.persist(),this.events.forEach(i=>{L.fromMiliseconds(Date.now())-L.fromMiliseconds(i.timestamp)>Gx&&(this.events.delete(i.eventId),this.shouldPersist=!0)})})}),De(this,"setMethods",i=>({addTrace:s=>this.addTrace(i,s),setError:s=>this.setError(i,s)})),De(this,"addTrace",(i,s)=>{const o=this.events.get(i);o&&(o.props.properties.trace.push(s),this.events.set(i,o),this.shouldPersist=!0)}),De(this,"setError",(i,s)=>{const o=this.events.get(i);o&&(o.props.type=s,o.timestamp=Date.now(),this.events.set(i,o),this.shouldPersist=!0)}),De(this,"persist",async()=>{await this.core.storage.setItem(this.storageKey,Array.from(this.events.values())),this.shouldPersist=!1}),De(this,"restore",async()=>{try{const i=await this.core.storage.getItem(this.storageKey)||[];if(!i.length)return;i.forEach(s=>{this.events.set(s.eventId,si(si({},s),this.setMethods(s.eventId)))})}catch(i){this.logger.warn(i)}}),De(this,"submit",async()=>{if(!this.telemetryEnabled||this.events.size===0)return;const i=[];for(const[s,o]of this.events)o.props.type&&i.push(o);if(i.length!==0)try{if((await this.sendEvent(i)).ok)for(const s of i)this.events.delete(s.eventId),this.shouldPersist=!0}catch(s){this.logger.warn(s)}}),De(this,"sendEvent",async i=>{const s=this.getAppDomain()?"":"&sp=desktop";return await fetch(`${Yx}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${ga}${s}`,{method:"POST",body:JSON.stringify(i)})}),De(this,"getAppDomain",()=>th().url),this.logger=je(r,this.context),this.telemetryEnabled=n,n?this.restore().then(async()=>{await this.submit(),this.setEventListeners()}):this.persist()}get storageKey(){return this.storagePrefix+this.storageVersion+this.core.customStoragePrefix+"//"+this.context}}var W8=Object.defineProperty,bf=Object.getOwnPropertySymbols,G8=Object.prototype.hasOwnProperty,Y8=Object.prototype.propertyIsEnumerable,$a=(t,e,r)=>e in t?W8(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,vf=(t,e)=>{for(var r in e||(e={}))G8.call(e,r)&&$a(t,r,e[r]);if(bf)for(var r of bf(e))Y8.call(e,r)&&$a(t,r,e[r]);return t},ae=(t,e,r)=>$a(t,typeof e!="symbol"?e+"":e,r);class Aa extends Ng{constructor(e){var r;super(e),ae(this,"protocol",Bd),ae(this,"version",Fd),ae(this,"name",is),ae(this,"relayUrl"),ae(this,"projectId"),ae(this,"customStoragePrefix"),ae(this,"events",new Le.exports.EventEmitter),ae(this,"logger"),ae(this,"heartbeat"),ae(this,"relayer"),ae(this,"crypto"),ae(this,"storage"),ae(this,"history"),ae(this,"expirer"),ae(this,"pairing"),ae(this,"verify"),ae(this,"echoClient"),ae(this,"linkModeSupportedApps"),ae(this,"eventClient"),ae(this,"initialized",!1),ae(this,"logChunkController"),ae(this,"on",(a,c)=>this.events.on(a,c)),ae(this,"once",(a,c)=>this.events.once(a,c)),ae(this,"off",(a,c)=>this.events.off(a,c)),ae(this,"removeListener",(a,c)=>this.events.removeListener(a,c)),ae(this,"dispatchEnvelope",({topic:a,message:c,sessionExists:u})=>{if(!a||!c)return;const l={topic:a,message:c,publishedAt:Date.now(),transportType:ce.link_mode};this.relayer.onLinkMessageEvent(l,{sessionExists:u})});const n=this.getGlobalCore(e?.customStoragePrefix);if(n)try{return this.customStoragePrefix=n.customStoragePrefix,this.logger=n.logger,this.heartbeat=n.heartbeat,this.crypto=n.crypto,this.history=n.history,this.expirer=n.expirer,this.storage=n.storage,this.relayer=n.relayer,this.pairing=n.pairing,this.verify=n.verify,this.echoClient=n.echoClient,this.linkModeSupportedApps=n.linkModeSupportedApps,this.eventClient=n.eventClient,this.initialized=n.initialized,this.logChunkController=n.logChunkController,n}catch(a){console.warn("Failed to copy global core",a)}this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||Md,this.customStoragePrefix=e!=null&&e.customStoragePrefix?`:${e.customStoragePrefix}`:"";const i=Is({level:typeof e?.logger=="string"&&e.logger?e.logger:wx.logger,name:is}),{logger:s,chunkLoggerController:o}=Tg({opts:i,maxSizeInBytes:e?.maxLogBlobSizeInBytes,loggerOverride:e?.logger});this.logChunkController=o,(r=this.logChunkController)!=null&&r.downloadLogsBlobInBrowser&&(window.downloadLogsBlobInBrowser=async()=>{var a,c;(a=this.logChunkController)!=null&&a.downloadLogsBlobInBrowser&&((c=this.logChunkController)==null||c.downloadLogsBlobInBrowser({clientId:await this.crypto.getClientId()}))}),this.logger=je(s,this.name),this.heartbeat=new ms,this.crypto=new SI(this,this.logger,e?.keychain),this.history=new C8(this,this.logger),this.expirer=new F8(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new ng(vf(vf({},mx),e?.storageOptions)),this.relayer=new ZI({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new P8(this,this.logger),this.verify=new k8(this,this.logger,this.storage),this.echoClient=new q8(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new H8(this,this.logger,e?.telemetryEnabled),this.setGlobalCore(this)}static async init(e){const r=new Aa(e);await r.initialize();const n=await r.crypto.getClientId();return await r.storage.setItem(Tx,n),r}get context(){return He(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(jd,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.linkModeSupportedApps=await this.storage.getItem(jd)||[],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}}getGlobalCore(e=""){try{if(this.isGlobalCoreDisabled())return;const r=`_walletConnectCore_${e}`,n=`${r}_count`;return globalThis[n]=(globalThis[n]||0)+1,globalThis[n]>1&&console.warn(`WalletConnect Core is already initialized. This is probably a mistake and can lead to unexpected behavior. Init() was called ${globalThis[n]} times.`),globalThis[r]}catch(r){console.warn("Failed to get global WalletConnect core",r);return}}setGlobalCore(e){var r;try{if(this.isGlobalCoreDisabled())return;const n=`_walletConnectCore_${((r=e.opts)==null?void 0:r.customStoragePrefix)||""}`;globalThis[n]=e}catch(n){console.warn("Failed to set global WalletConnect core",n)}}isGlobalCoreDisabled(){try{return typeof process<"u"&&process.env.DISABLE_GLOBAL_CORE==="true"}catch{return!0}}}const Pa=Aa,Ef="wc",_f=2,Sf="client",Ta=`${Ef}@${_f}:${Sf}:`,Ra={name:Sf,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.org"},xf="WALLETCONNECT_DEEPLINK_CHOICE",Z8="proposal",If="Proposal expired",J8="session",dn=L.SEVEN_DAYS,X8="engine",Oe={wc_sessionPropose:{req:{ttl:L.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1101},reject:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1120},autoReject:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1121}},wc_sessionSettle:{req:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:L.ONE_DAY,prompt:!1,tag:1104},res:{ttl:L.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:L.ONE_DAY,prompt:!1,tag:1106},res:{ttl:L.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:L.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:L.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:L.ONE_DAY,prompt:!1,tag:1112},res:{ttl:L.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:L.ONE_DAY,prompt:!1,tag:1114},res:{ttl:L.ONE_DAY,prompt:!1,tag:1115}},wc_sessionAuthenticate:{req:{ttl:L.ONE_HOUR,prompt:!0,tag:1116},res:{ttl:L.ONE_HOUR,prompt:!1,tag:1117},reject:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1118},autoReject:{ttl:L.FIVE_MINUTES,prompt:!1,tag:1119}}},Ca={min:L.FIVE_MINUTES,max:L.SEVEN_DAYS},At={idle:"IDLE",active:"ACTIVE"},Df={eth_sendTransaction:{key:""},eth_sendRawTransaction:{key:""},wallet_sendCalls:{key:""},solana_signTransaction:{key:"signature"},solana_signAllTransactions:{key:"transactions"},solana_signAndSendTransaction:{key:"signature"}},Q8="request",eD=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],tD="wc",rD="auth",nD="authKeys",iD="pairingTopics",sD="requests",cs=`${tD}@${1.5}:${rD}:`,us=`${cs}:PUB_KEY`;var oD=Object.defineProperty,aD=Object.defineProperties,cD=Object.getOwnPropertyDescriptors,Of=Object.getOwnPropertySymbols,uD=Object.prototype.hasOwnProperty,lD=Object.prototype.propertyIsEnumerable,Na=(t,e,r)=>e in t?oD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ie=(t,e)=>{for(var r in e||(e={}))uD.call(e,r)&&Na(t,r,e[r]);if(Of)for(var r of Of(e))lD.call(e,r)&&Na(t,r,e[r]);return t},Ve=(t,e)=>aD(t,cD(e)),R=(t,e,r)=>Na(t,typeof e!="symbol"?e+"":e,r);class hD extends Jg{constructor(e){super(e),R(this,"name",X8),R(this,"events",new Le.exports),R(this,"initialized",!1),R(this,"requestQueue",{state:At.idle,queue:[]}),R(this,"sessionRequestQueue",{state:At.idle,queue:[]}),R(this,"requestQueueDelay",L.ONE_SECOND),R(this,"expectedPairingMethodMap",new Map),R(this,"recentlyDeletedMap",new Map),R(this,"recentlyDeletedLimit",200),R(this,"relayMessageCache",[]),R(this,"pendingSessions",new Map),R(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(Oe)}),this.initialized=!0,setTimeout(async()=>{await this.processPendingMessageEvents(),this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()},L.toMiliseconds(this.requestQueueDelay)))}),R(this,"connect",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();const n=Ve(ie({},r),{requiredNamespaces:r.requiredNamespaces||{},optionalNamespaces:r.optionalNamespaces||{}});await this.isValidConnect(n);const{pairingTopic:i,requiredNamespaces:s,optionalNamespaces:o,sessionProperties:a,scopedProperties:c,relays:u}=n;let l=i,h,d=!1;try{if(l){const D=this.client.core.pairing.pairings.get(l);this.client.logger.warn("connect() with existing pairing topic is deprecated and will be removed in the next major release."),d=D.active}}catch(D){throw this.client.logger.error(`connect() -> pairing.get(${l}) failed`),D}if(!l||!d){const{topic:D,uri:S}=await this.client.core.pairing.create();l=D,h=S}if(!l){const{message:D}=U("NO_MATCHING_KEY",`connect() pairing topic: ${l}`);throw new Error(D)}const p=await this.client.core.crypto.generateKeyPair(),f=Oe.wc_sessionPropose.req.ttl||L.FIVE_MINUTES,y=me(f),g=Ve(ie(ie({requiredNamespaces:s,optionalNamespaces:o,relays:u??[{protocol:kd}],proposer:{publicKey:p,metadata:this.client.metadata},expiryTimestamp:y,pairingTopic:l},a&&{sessionProperties:a}),c&&{scopedProperties:c}),{id:xt()}),w=Q("session_connect",g.id),{reject:m,resolve:b,done:E}=br(f,If),$=({id:D})=>{D===g.id&&(this.client.events.off("proposal_expire",$),this.pendingSessions.delete(g.id),this.events.emit(w,{error:{message:If,code:0}}))};return this.client.events.on("proposal_expire",$),this.events.once(w,({error:D,session:S})=>{this.client.events.off("proposal_expire",$),D?m(D):S&&b(S)}),await this.sendRequest({topic:l,method:"wc_sessionPropose",params:g,throwOnFailedPublish:!0,clientRpcId:g.id}),await this.setProposal(g.id,g),{uri:h,approval:E}}),R(this,"pair",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{return await this.client.core.pairing.pair(r)}catch(n){throw this.client.logger.error("pair() failed"),n}}),R(this,"approve",async r=>{var n,i,s;const o=this.client.core.eventClient.createEvent({properties:{topic:(n=r?.id)==null?void 0:n.toString(),trace:[pt.session_approve_started]}});try{this.isInitialized(),await this.confirmOnlineStateOrThrow()}catch(x){throw o.setError($r.no_internet_connection),x}try{await this.isValidProposalId(r?.id)}catch(x){throw this.client.logger.error(`approve() -> proposal.get(${r?.id}) failed`),o.setError($r.proposal_not_found),x}try{await this.isValidApprove(r)}catch(x){throw this.client.logger.error("approve() -> isValidApprove() failed"),o.setError($r.session_approve_namespace_validation_failure),x}const{id:a,relayProtocol:c,namespaces:u,sessionProperties:l,scopedProperties:h,sessionConfig:d}=r,p=this.client.proposal.get(a);this.client.core.eventClient.deleteEvent({eventId:o.eventId});const{pairingTopic:f,proposer:y,requiredNamespaces:g,optionalNamespaces:w}=p;let m=(i=this.client.core.eventClient)==null?void 0:i.getEvent({topic:f});m||(m=(s=this.client.core.eventClient)==null?void 0:s.createEvent({type:pt.session_approve_started,properties:{topic:f,trace:[pt.session_approve_started,pt.session_namespaces_validation_success]}}));const b=await this.client.core.crypto.generateKeyPair(),E=y.publicKey,$=await this.client.core.crypto.generateSharedKey(b,E),D=ie(ie(ie({relay:{protocol:c??"irn"},namespaces:u,controller:{publicKey:b,metadata:this.client.metadata},expiry:me(dn)},l&&{sessionProperties:l}),h&&{scopedProperties:h}),d&&{sessionConfig:d}),S=ce.relay;m.addTrace(pt.subscribing_session_topic);try{await this.client.core.relayer.subscribe($,{transportType:S})}catch(x){throw m.setError($r.subscribe_session_topic_failure),x}m.addTrace(pt.subscribe_session_topic_success);const A=Ve(ie({},D),{topic:$,requiredNamespaces:g,optionalNamespaces:w,pairingTopic:f,acknowledged:!1,self:D.controller,peer:{publicKey:y.publicKey,metadata:y.metadata},controller:b,transportType:ce.relay});await this.client.session.set($,A),m.addTrace(pt.store_session);try{m.addTrace(pt.publishing_session_settle),await this.sendRequest({topic:$,method:"wc_sessionSettle",params:D,throwOnFailedPublish:!0}).catch(x=>{throw m?.setError($r.session_settle_publish_failure),x}),m.addTrace(pt.session_settle_publish_success),m.addTrace(pt.publishing_session_approve),await this.sendResult({id:a,topic:f,result:{relay:{protocol:c??"irn"},responderPublicKey:b},throwOnFailedPublish:!0}).catch(x=>{throw m?.setError($r.session_approve_publish_failure),x}),m.addTrace(pt.session_approve_publish_success)}catch(x){throw this.client.logger.error(x),this.client.session.delete($,oe("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe($),x}return this.client.core.eventClient.deleteEvent({eventId:m.eventId}),await this.client.core.pairing.updateMetadata({topic:f,metadata:y.metadata}),await this.client.proposal.delete(a,oe("USER_DISCONNECTED")),await this.client.core.pairing.activate({topic:f}),await this.setExpiry($,me(dn)),{topic:$,acknowledged:()=>Promise.resolve(this.client.session.get($))}}),R(this,"reject",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidReject(r)}catch(o){throw this.client.logger.error("reject() -> isValidReject() failed"),o}const{id:n,reason:i}=r;let s;try{s=this.client.proposal.get(n).pairingTopic}catch(o){throw this.client.logger.error(`reject() -> proposal.get(${n}) failed`),o}s&&(await this.sendError({id:n,topic:s,error:i,rpcOpts:Oe.wc_sessionPropose.reject}),await this.client.proposal.delete(n,oe("USER_DISCONNECTED")))}),R(this,"update",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidUpdate(r)}catch(h){throw this.client.logger.error("update() -> isValidUpdate() failed"),h}const{topic:n,namespaces:i}=r,{done:s,resolve:o,reject:a}=br(),c=xt(),u=Ir().toString(),l=this.client.session.get(n).namespaces;return this.events.once(Q("session_update",c),({error:h})=>{h?a(h):o()}),await this.client.session.update(n,{namespaces:i}),await this.sendRequest({topic:n,method:"wc_sessionUpdate",params:{namespaces:i},throwOnFailedPublish:!0,clientRpcId:c,relayRpcId:u}).catch(h=>{this.client.logger.error(h),this.client.session.update(n,{namespaces:l}),a(h)}),{acknowledged:s}}),R(this,"extend",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidExtend(r)}catch(c){throw this.client.logger.error("extend() -> isValidExtend() failed"),c}const{topic:n}=r,i=xt(),{done:s,resolve:o,reject:a}=br();return this.events.once(Q("session_extend",i),({error:c})=>{c?a(c):o()}),await this.setExpiry(n,me(dn)),this.sendRequest({topic:n,method:"wc_sessionExtend",params:{},clientRpcId:i,throwOnFailedPublish:!0}).catch(c=>{a(c)}),{acknowledged:s}}),R(this,"request",async r=>{this.isInitialized();try{await this.isValidRequest(r)}catch(w){throw this.client.logger.error("request() -> isValidRequest() failed"),w}const{chainId:n,request:i,topic:s,expiry:o=Oe.wc_sessionRequest.req.ttl}=r,a=this.client.session.get(s);a?.transportType===ce.relay&&await this.confirmOnlineStateOrThrow();const c=xt(),u=Ir().toString(),{done:l,resolve:h,reject:d}=br(o,"Request expired. Please try again.");this.events.once(Q("session_request",c),({error:w,result:m})=>{w?d(w):h(m)});const p="wc_sessionRequest",f=this.getAppLinkIfEnabled(a.peer.metadata,a.transportType);if(f)return await this.sendRequest({clientRpcId:c,relayRpcId:u,topic:s,method:p,params:{request:Ve(ie({},i),{expiryTimestamp:me(o)}),chainId:n},expiry:o,throwOnFailedPublish:!0,appLink:f}).catch(w=>d(w)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:n,id:c}),await l();const y={request:Ve(ie({},i),{expiryTimestamp:me(o)}),chainId:n},g=this.shouldSetTVF(p,y);return await Promise.all([new Promise(async w=>{await this.sendRequest(ie({clientRpcId:c,relayRpcId:u,topic:s,method:p,params:y,expiry:o,throwOnFailedPublish:!0},g&&{tvf:this.getTVFParams(c,y)})).catch(m=>d(m)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:n,id:c}),w()}),new Promise(async w=>{var m;if(!((m=a.sessionConfig)!=null&&m.disableDeepLink)){const b=await mE(this.client.core.storage,xf);await gE({id:c,topic:s,wcDeepLink:b})}w()}),l()]).then(w=>w[2])}),R(this,"respond",async r=>{this.isInitialized(),await this.isValidRespond(r);const{topic:n,response:i}=r,{id:s}=i,o=this.client.session.get(n);o.transportType===ce.relay&&await this.confirmOnlineStateOrThrow();const a=this.getAppLinkIfEnabled(o.peer.metadata,o.transportType);It(i)?await this.sendResult({id:s,topic:n,result:i.result,throwOnFailedPublish:!0,appLink:a}):ot(i)&&await this.sendError({id:s,topic:n,error:i.error,appLink:a}),this.cleanupAfterResponse(r)}),R(this,"ping",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidPing(r)}catch(i){throw this.client.logger.error("ping() -> isValidPing() failed"),i}const{topic:n}=r;if(this.client.session.keys.includes(n)){const i=xt(),s=Ir().toString(),{done:o,resolve:a,reject:c}=br();this.events.once(Q("session_ping",i),({error:u})=>{u?c(u):a()}),await Promise.all([this.sendRequest({topic:n,method:"wc_sessionPing",params:{},throwOnFailedPublish:!0,clientRpcId:i,relayRpcId:s}),o()])}else this.client.core.pairing.pairings.keys.includes(n)&&(this.client.logger.warn("ping() on pairing topic is deprecated and will be removed in the next major release."),await this.client.core.pairing.ping({topic:n}))}),R(this,"emit",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidEmit(r);const{topic:n,event:i,chainId:s}=r,o=Ir().toString(),a=xt();await this.sendRequest({topic:n,method:"wc_sessionEvent",params:{event:i,chainId:s},throwOnFailedPublish:!0,relayRpcId:o,clientRpcId:a})}),R(this,"disconnect",async r=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidDisconnect(r);const{topic:n}=r;if(this.client.session.keys.includes(n))await this.sendRequest({topic:n,method:"wc_sessionDelete",params:oe("USER_DISCONNECTED"),throwOnFailedPublish:!0}),await this.deleteSession({topic:n,emitEvent:!1});else if(this.client.core.pairing.pairings.keys.includes(n))await this.client.core.pairing.disconnect({topic:n});else{const{message:i}=U("MISMATCHED_TOPIC",`Session or pairing topic not found: ${n}`);throw new Error(i)}}),R(this,"find",r=>(this.isInitialized(),this.client.session.getAll().filter(n=>X_(n,r)))),R(this,"getPendingSessionRequests",()=>this.client.pendingRequest.getAll()),R(this,"authenticate",async(r,n)=>{var i;this.isInitialized(),this.isValidAuthenticate(r);const s=n&&this.client.core.linkModeSupportedApps.includes(n)&&((i=this.client.metadata.redirect)==null?void 0:i.linkMode),o=s?ce.link_mode:ce.relay;o===ce.relay&&await this.confirmOnlineStateOrThrow();const{chains:a,statement:c="",uri:u,domain:l,nonce:h,type:d,exp:p,nbf:f,methods:y=[],expiry:g}=r,w=[...r.resources||[]],{topic:m,uri:b}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:o});this.client.logger.info({message:"Generated new pairing",pairing:{topic:m,uri:b}});const E=await this.client.core.crypto.generateKeyPair(),$=Xi(E);if(await Promise.all([this.client.auth.authKeys.set(us,{responseTopic:$,publicKey:E}),this.client.auth.pairingTopics.set($,{topic:$,pairingTopic:m})]),await this.client.core.relayer.subscribe($,{transportType:o}),this.client.logger.info(`sending request to new pairing topic: ${m}`),y.length>0){const{namespace:P}=Mi(a[0]);let N=u2(P,"request",y);Vi(w)&&(N=h2(N,w.pop())),w.push(N)}const D=g&&g>Oe.wc_sessionAuthenticate.req.ttl?g:Oe.wc_sessionAuthenticate.req.ttl,S={authPayload:{type:d??"caip122",chains:a,statement:c,aud:u,domain:l,version:"1",nonce:h,iat:new Date().toISOString(),exp:p,nbf:f,resources:w},requester:{publicKey:E,metadata:this.client.metadata},expiryTimestamp:me(D)},A={eip155:{chains:a,methods:[...new Set(["personal_sign",...y])],events:["chainChanged","accountsChanged"]}},x={requiredNamespaces:{},optionalNamespaces:A,relays:[{protocol:"irn"}],pairingTopic:m,proposer:{publicKey:E,metadata:this.client.metadata},expiryTimestamp:me(Oe.wc_sessionPropose.req.ttl),id:xt()},{done:k,resolve:C,reject:B}=br(D,"Request expired"),j=xt(),I=Q("session_connect",x.id),_=Q("session_request",j),v=async({error:P,session:N})=>{this.events.off(_,O),P?B(P):N&&C({session:N})},O=async P=>{var N,F,M;if(await this.deletePendingAuthRequest(j,{message:"fulfilled",code:0}),P.error){const W=oe("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return P.error.code===W.code?void 0:(this.events.off(I,v),B(P.error.message))}await this.deleteProposal(x.id),this.events.off(I,v);const{cacaos:z,responder:q}=P.result,V=[],K=[];for(const W of z){await Eh({cacao:W,projectId:this.client.core.projectId})||(this.client.logger.error(W,"Signature verification failed"),B(oe("SESSION_SETTLEMENT_FAILED","Signature verification failed")));const{p:ye}=W,ue=Vi(ye.resources),le=[Lo(ye.iss)],$e=zi(ye.iss);if(ue){const Me=xh(ue),Kt=Ih(ue);V.push(...Me),le.push(...Kt)}for(const Me of le)K.push(`${Me}:${$e}`)}const ee=await this.client.core.crypto.generateSharedKey(E,q.publicKey);let G;V.length>0&&(G={topic:ee,acknowledged:!0,self:{publicKey:E,metadata:this.client.metadata},peer:q,controller:q.publicKey,expiry:me(dn),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:m,namespaces:yd([...new Set(V)],[...new Set(K)]),transportType:o},await this.client.core.relayer.subscribe(ee,{transportType:o}),await this.client.session.set(ee,G),m&&await this.client.core.pairing.updateMetadata({topic:m,metadata:q.metadata}),G=this.client.session.get(ee)),(N=this.client.metadata.redirect)!=null&&N.linkMode&&(F=q.metadata.redirect)!=null&&F.linkMode&&(M=q.metadata.redirect)!=null&&M.universal&&n&&(this.client.core.addLinkModeSupportedApp(q.metadata.redirect.universal),this.client.session.update(ee,{transportType:ce.link_mode})),C({auths:z,session:G})};this.events.once(I,v),this.events.once(_,O);let T;try{if(s){const P=Dr("wc_sessionAuthenticate",S,j);this.client.core.history.set(m,P);const N=await this.client.core.crypto.encode("",P,{type:Vn,encoding:ar});T=es(n,m,N)}else await Promise.all([this.sendRequest({topic:m,method:"wc_sessionAuthenticate",params:S,expiry:r.expiry,throwOnFailedPublish:!0,clientRpcId:j}),this.sendRequest({topic:m,method:"wc_sessionPropose",params:x,expiry:Oe.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:x.id})])}catch(P){throw this.events.off(I,v),this.events.off(_,O),P}return await this.setProposal(x.id,x),await this.setAuthRequest(j,{request:Ve(ie({},S),{verifyContext:{}}),pairingTopic:m,transportType:o}),{uri:T??b,response:k}}),R(this,"approveSessionAuthenticate",async r=>{const{id:n,auths:i}=r,s=this.client.core.eventClient.createEvent({properties:{topic:n.toString(),trace:[Ar.authenticated_session_approve_started]}});try{this.isInitialized()}catch(g){throw s.setError(ei.no_internet_connection),g}const o=this.getPendingAuthRequest(n);if(!o)throw s.setError(ei.authenticated_session_pending_request_not_found),new Error(`Could not find pending auth request with id ${n}`);const a=o.transportType||ce.relay;a===ce.relay&&await this.confirmOnlineStateOrThrow();const c=o.requester.publicKey,u=await this.client.core.crypto.generateKeyPair(),l=Xi(c),h={type:jt,receiverPublicKey:c,senderPublicKey:u},d=[],p=[];for(const g of i){if(!await Eh({cacao:g,projectId:this.client.core.projectId})){s.setError(ei.invalid_cacao);const $=oe("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:n,topic:l,error:$,encodeOpts:h}),new Error($.message)}s.addTrace(Ar.cacaos_verified);const{p:w}=g,m=Vi(w.resources),b=[Lo(w.iss)],E=zi(w.iss);if(m){const $=xh(m),D=Ih(m);d.push(...$),b.push(...D)}for(const $ of b)p.push(`${$}:${E}`)}const f=await this.client.core.crypto.generateSharedKey(u,c);s.addTrace(Ar.create_authenticated_session_topic);let y;if(d?.length>0){y={topic:f,acknowledged:!0,self:{publicKey:u,metadata:this.client.metadata},peer:{publicKey:c,metadata:o.requester.metadata},controller:c,expiry:me(dn),authentication:i,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:o.pairingTopic,namespaces:yd([...new Set(d)],[...new Set(p)]),transportType:a},s.addTrace(Ar.subscribing_authenticated_session_topic);try{await this.client.core.relayer.subscribe(f,{transportType:a})}catch(g){throw s.setError(ei.subscribe_authenticated_session_topic_failure),g}s.addTrace(Ar.subscribe_authenticated_session_topic_success),await this.client.session.set(f,y),s.addTrace(Ar.store_authenticated_session),await this.client.core.pairing.updateMetadata({topic:o.pairingTopic,metadata:o.requester.metadata})}s.addTrace(Ar.publishing_authenticated_session_approve);try{await this.sendResult({topic:l,id:n,result:{cacaos:i,responder:{publicKey:u,metadata:this.client.metadata}},encodeOpts:h,throwOnFailedPublish:!0,appLink:this.getAppLinkIfEnabled(o.requester.metadata,a)})}catch(g){throw s.setError(ei.authenticated_session_approve_publish_failure),g}return await this.client.auth.requests.delete(n,{message:"fulfilled",code:0}),await this.client.core.pairing.activate({topic:o.pairingTopic}),this.client.core.eventClient.deleteEvent({eventId:s.eventId}),{session:y}}),R(this,"rejectSessionAuthenticate",async r=>{this.isInitialized();const{id:n,reason:i}=r,s=this.getPendingAuthRequest(n);if(!s)throw new Error(`Could not find pending auth request with id ${n}`);s.transportType===ce.relay&&await this.confirmOnlineStateOrThrow();const o=s.requester.publicKey,a=await this.client.core.crypto.generateKeyPair(),c=Xi(o),u={type:jt,receiverPublicKey:o,senderPublicKey:a};await this.sendError({id:n,topic:c,error:i,encodeOpts:u,rpcOpts:Oe.wc_sessionAuthenticate.reject,appLink:this.getAppLinkIfEnabled(s.requester.metadata,s.transportType)}),await this.client.auth.requests.delete(n,{message:"rejected",code:0}),await this.client.proposal.delete(n,oe("USER_DISCONNECTED"))}),R(this,"formatAuthMessage",r=>{this.isInitialized();const{request:n,iss:i}=r;return _h(n,i)}),R(this,"processRelayMessageCache",()=>{setTimeout(async()=>{if(this.relayMessageCache.length!==0)for(;this.relayMessageCache.length>0;)try{const r=this.relayMessageCache.shift();r&&await this.onRelayMessage(r)}catch(r){this.client.logger.error(r)}},50)}),R(this,"cleanupDuplicatePairings",async r=>{if(r.pairingTopic)try{const n=this.client.core.pairing.pairings.get(r.pairingTopic),i=this.client.core.pairing.pairings.getAll().filter(s=>{var o,a;return((o=s.peerMetadata)==null?void 0:o.url)&&((a=s.peerMetadata)==null?void 0:a.url)===r.peer.metadata.url&&s.topic&&s.topic!==n.topic});if(i.length===0)return;this.client.logger.info(`Cleaning up ${i.length} duplicate pairing(s)`),await Promise.all(i.map(s=>this.client.core.pairing.disconnect({topic:s.topic}))),this.client.logger.info("Duplicate pairings clean up finished")}catch(n){this.client.logger.error(n)}}),R(this,"deleteSession",async r=>{var n;const{topic:i,expirerHasDeleted:s=!1,emitEvent:o=!0,id:a=0}=r,{self:c}=this.client.session.get(i);await this.client.core.relayer.unsubscribe(i),await this.client.session.delete(i,oe("USER_DISCONNECTED")),this.addToRecentlyDeleted(i,"session"),this.client.core.crypto.keychain.has(c.publicKey)&&await this.client.core.crypto.deleteKeyPair(c.publicKey),this.client.core.crypto.keychain.has(i)&&await this.client.core.crypto.deleteSymKey(i),s||this.client.core.expirer.del(i),this.client.core.storage.removeItem(xf).catch(u=>this.client.logger.warn(u)),this.getPendingSessionRequests().forEach(u=>{u.topic===i&&this.deletePendingSessionRequest(u.id,oe("USER_DISCONNECTED"))}),i===((n=this.sessionRequestQueue.queue[0])==null?void 0:n.topic)&&(this.sessionRequestQueue.state=At.idle),o&&this.client.events.emit("session_delete",{id:a,topic:i})}),R(this,"deleteProposal",async(r,n)=>{if(n)try{const i=this.client.proposal.get(r);this.client.core.eventClient.getEvent({topic:i.pairingTopic})?.setError($r.proposal_expired)}catch{}await Promise.all([this.client.proposal.delete(r,oe("USER_DISCONNECTED")),n?Promise.resolve():this.client.core.expirer.del(r)]),this.addToRecentlyDeleted(r,"proposal")}),R(this,"deletePendingSessionRequest",async(r,n,i=!1)=>{await Promise.all([this.client.pendingRequest.delete(r,n),i?Promise.resolve():this.client.core.expirer.del(r)]),this.addToRecentlyDeleted(r,"request"),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter(s=>s.id!==r),i&&(this.sessionRequestQueue.state=At.idle,this.client.events.emit("session_request_expire",{id:r}))}),R(this,"deletePendingAuthRequest",async(r,n,i=!1)=>{await Promise.all([this.client.auth.requests.delete(r,n),i?Promise.resolve():this.client.core.expirer.del(r)])}),R(this,"setExpiry",async(r,n)=>{this.client.session.keys.includes(r)&&(this.client.core.expirer.set(r,n),await this.client.session.update(r,{expiry:n}))}),R(this,"setProposal",async(r,n)=>{this.client.core.expirer.set(r,me(Oe.wc_sessionPropose.req.ttl)),await this.client.proposal.set(r,n)}),R(this,"setAuthRequest",async(r,n)=>{const{request:i,pairingTopic:s,transportType:o=ce.relay}=n;this.client.core.expirer.set(r,i.expiryTimestamp),await this.client.auth.requests.set(r,{authPayload:i.authPayload,requester:i.requester,expiryTimestamp:i.expiryTimestamp,id:r,pairingTopic:s,verifyContext:i.verifyContext,transportType:o})}),R(this,"setPendingSessionRequest",async r=>{const{id:n,topic:i,params:s,verifyContext:o}=r,a=s.request.expiryTimestamp||me(Oe.wc_sessionRequest.req.ttl);this.client.core.expirer.set(n,a),await this.client.pendingRequest.set(n,{id:n,topic:i,params:s,verifyContext:o})}),R(this,"sendRequest",async r=>{const{topic:n,method:i,params:s,expiry:o,relayRpcId:a,clientRpcId:c,throwOnFailedPublish:u,appLink:l,tvf:h}=r,d=Dr(i,s,c);let p;const f=!!l;try{const w=f?ar:dt;p=await this.client.core.crypto.encode(n,d,{encoding:w})}catch(w){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${n} failed`),w}let y;if(eD.includes(i)){const w=St(JSON.stringify(d)),m=St(p);y=await this.client.core.verify.register({id:m,decryptedId:w})}const g=Oe[i].req;if(g.attestation=y,o&&(g.ttl=o),a&&(g.id=a),this.client.core.history.set(n,d),f){const w=es(l,n,p);await global.Linking.openURL(w,this.client.name)}else{const w=Oe[i].req;o&&(w.ttl=o),a&&(w.id=a),w.tvf=Ve(ie({},h),{correlationId:d.id}),u?(w.internal=Ve(ie({},w.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(n,p,w)):this.client.core.relayer.publish(n,p,w).catch(m=>this.client.logger.error(m))}return d.id}),R(this,"sendResult",async r=>{const{id:n,topic:i,result:s,throwOnFailedPublish:o,encodeOpts:a,appLink:c}=r,u=da(n,s);let l;const h=c&&typeof(global==null?void 0:global.Linking)<"u";try{const f=h?ar:dt;l=await this.client.core.crypto.encode(i,u,Ve(ie({},a||{}),{encoding:f}))}catch(f){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${i} failed`),f}let d,p;try{d=await this.client.core.history.get(i,n);const f=d.request;try{this.shouldSetTVF(f.method,f.params)&&(p=this.getTVFParams(n,f.params,s))}catch(y){this.client.logger.warn("sendResult() -> getTVFParams() failed",y)}}catch(f){throw this.client.logger.error(`sendResult() -> history.get(${i}, ${n}) failed`),f}if(h){const f=es(c,i,l);await global.Linking.openURL(f,this.client.name)}else{const f=d.request.method,y=Oe[f].res;y.tvf=Ve(ie({},p),{correlationId:n}),o?(y.internal=Ve(ie({},y.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(i,l,y)):this.client.core.relayer.publish(i,l,y).catch(g=>this.client.logger.error(g))}await this.client.core.history.resolve(u)}),R(this,"sendError",async r=>{const{id:n,topic:i,error:s,encodeOpts:o,rpcOpts:a,appLink:c}=r,u=fa(n,s);let l;const h=c&&typeof(global==null?void 0:global.Linking)<"u";try{const p=h?ar:dt;l=await this.client.core.crypto.encode(i,u,Ve(ie({},o||{}),{encoding:p}))}catch(p){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${i} failed`),p}let d;try{d=await this.client.core.history.get(i,n)}catch(p){throw this.client.logger.error(`sendError() -> history.get(${i}, ${n}) failed`),p}if(h){const p=es(c,i,l);await global.Linking.openURL(p,this.client.name)}else{const p=d.request.method,f=a||Oe[p].res;this.client.core.relayer.publish(i,l,f)}await this.client.core.history.resolve(u)}),R(this,"cleanup",async()=>{const r=[],n=[];this.client.session.getAll().forEach(i=>{let s=!1;nr(i.expiry)&&(s=!0),this.client.core.crypto.keychain.has(i.topic)||(s=!0),s&&r.push(i.topic)}),this.client.proposal.getAll().forEach(i=>{nr(i.expiryTimestamp)&&n.push(i.id)}),await Promise.all([...r.map(i=>this.deleteSession({topic:i})),...n.map(i=>this.deleteProposal(i))])}),R(this,"onProviderMessageEvent",async r=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(r):await this.onRelayMessage(r)}),R(this,"onRelayEventRequest",async r=>{this.requestQueue.queue.push(r),await this.processRequestsQueue()}),R(this,"processRequestsQueue",async()=>{if(this.requestQueue.state===At.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=At.active;const r=this.requestQueue.queue.shift();if(r)try{await this.processRequest(r)}catch(n){this.client.logger.warn(n)}}this.requestQueue.state=At.idle}),R(this,"processRequest",async r=>{const{topic:n,payload:i,attestation:s,transportType:o,encryptedId:a}=r,c=i.method;if(!this.shouldIgnorePairingRequest({topic:n,requestMethod:c}))switch(c){case"wc_sessionPropose":return await this.onSessionProposeRequest({topic:n,payload:i,attestation:s,encryptedId:a});case"wc_sessionSettle":return await this.onSessionSettleRequest(n,i);case"wc_sessionUpdate":return await this.onSessionUpdateRequest(n,i);case"wc_sessionExtend":return await this.onSessionExtendRequest(n,i);case"wc_sessionPing":return await this.onSessionPingRequest(n,i);case"wc_sessionDelete":return await this.onSessionDeleteRequest(n,i);case"wc_sessionRequest":return await this.onSessionRequest({topic:n,payload:i,attestation:s,encryptedId:a,transportType:o});case"wc_sessionEvent":return await this.onSessionEventRequest(n,i);case"wc_sessionAuthenticate":return await this.onSessionAuthenticateRequest({topic:n,payload:i,attestation:s,encryptedId:a,transportType:o});default:return this.client.logger.info(`Unsupported request method ${c}`)}}),R(this,"onRelayEventResponse",async r=>{const{topic:n,payload:i,transportType:s}=r,o=(await this.client.core.history.get(n,i.id)).request.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeResponse(n,i,s);case"wc_sessionSettle":return this.onSessionSettleResponse(n,i);case"wc_sessionUpdate":return this.onSessionUpdateResponse(n,i);case"wc_sessionExtend":return this.onSessionExtendResponse(n,i);case"wc_sessionPing":return this.onSessionPingResponse(n,i);case"wc_sessionRequest":return this.onSessionRequestResponse(n,i);case"wc_sessionAuthenticate":return this.onSessionAuthenticateResponse(n,i);default:return this.client.logger.info(`Unsupported response method ${o}`)}}),R(this,"onRelayEventUnknownPayload",r=>{const{topic:n}=r,{message:i}=U("MISSING_OR_INVALID",`Decoded payload on topic ${n} is not identifiable as a JSON-RPC request or a response.`);throw new Error(i)}),R(this,"shouldIgnorePairingRequest",r=>{const{topic:n,requestMethod:i}=r,s=this.expectedPairingMethodMap.get(n);return!s||s.includes(i)?!1:!!(s.includes("wc_sessionAuthenticate")&&this.client.events.listenerCount("session_authenticate")>0)}),R(this,"onSessionProposeRequest",async r=>{const{topic:n,payload:i,attestation:s,encryptedId:o}=r,{params:a,id:c}=i;try{const u=this.client.core.eventClient.getEvent({topic:n});this.client.events.listenerCount("session_proposal")===0&&(console.warn("No listener for session_proposal event"),u?.setError(Vt.proposal_listener_not_found)),this.isValidConnect(ie({},i.params));const l=a.expiryTimestamp||me(Oe.wc_sessionPropose.req.ttl),h=ie({id:c,pairingTopic:n,expiryTimestamp:l},a);await this.setProposal(c,h);const d=await this.getVerifyContext({attestationId:s,hash:St(JSON.stringify(i)),encryptedId:o,metadata:h.proposer.metadata});u?.addTrace(Ot.emit_session_proposal),this.client.events.emit("session_proposal",{id:c,params:h,verifyContext:d})}catch(u){await this.sendError({id:c,topic:n,error:u,rpcOpts:Oe.wc_sessionPropose.autoReject}),this.client.logger.error(u)}}),R(this,"onSessionProposeResponse",async(r,n,i)=>{const{id:s}=n;if(It(n)){const{result:o}=n;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",result:o});const a=this.client.proposal.get(s);this.client.logger.trace({type:"method",method:"onSessionProposeResponse",proposal:a});const c=a.proposer.publicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",selfPublicKey:c});const u=o.responderPublicKey;this.client.logger.trace({type:"method",method:"onSessionProposeResponse",peerPublicKey:u});const l=await this.client.core.crypto.generateSharedKey(c,u);this.pendingSessions.set(s,{sessionTopic:l,pairingTopic:r,proposalId:s,publicKey:c});const h=await this.client.core.relayer.subscribe(l,{transportType:i});this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:h}),await this.client.core.pairing.activate({topic:r})}else if(ot(n)){await this.client.proposal.delete(s,oe("USER_DISCONNECTED"));const o=Q("session_connect",s);if(this.events.listenerCount(o)===0)throw new Error(`emitting ${o} without any listeners, 954`);this.events.emit(o,{error:n.error})}}),R(this,"onSessionSettleRequest",async(r,n)=>{const{id:i,params:s}=n;try{this.isValidSessionSettleRequest(s);const{relay:o,controller:a,expiry:c,namespaces:u,sessionProperties:l,scopedProperties:h,sessionConfig:d}=n.params,p=[...this.pendingSessions.values()].find(g=>g.sessionTopic===r);if(!p)return this.client.logger.error(`Pending session not found for topic ${r}`);const f=this.client.proposal.get(p.proposalId),y=Ve(ie(ie(ie({topic:r,relay:o,expiry:c,namespaces:u,acknowledged:!0,pairingTopic:p.pairingTopic,requiredNamespaces:f.requiredNamespaces,optionalNamespaces:f.optionalNamespaces,controller:a.publicKey,self:{publicKey:p.publicKey,metadata:this.client.metadata},peer:{publicKey:a.publicKey,metadata:a.metadata}},l&&{sessionProperties:l}),h&&{scopedProperties:h}),d&&{sessionConfig:d}),{transportType:ce.relay});await this.client.session.set(y.topic,y),await this.setExpiry(y.topic,y.expiry),await this.client.core.pairing.updateMetadata({topic:p.pairingTopic,metadata:y.peer.metadata}),this.client.events.emit("session_connect",{session:y}),this.events.emit(Q("session_connect",p.proposalId),{session:y}),this.pendingSessions.delete(p.proposalId),this.deleteProposal(p.proposalId,!1),this.cleanupDuplicatePairings(y),await this.sendResult({id:n.id,topic:r,result:!0,throwOnFailedPublish:!0})}catch(o){await this.sendError({id:i,topic:r,error:o}),this.client.logger.error(o)}}),R(this,"onSessionSettleResponse",async(r,n)=>{const{id:i}=n;It(n)?(await this.client.session.update(r,{acknowledged:!0}),this.events.emit(Q("session_approve",i),{})):ot(n)&&(await this.client.session.delete(r,oe("USER_DISCONNECTED")),this.events.emit(Q("session_approve",i),{error:n.error}))}),R(this,"onSessionUpdateRequest",async(r,n)=>{const{params:i,id:s}=n;try{const o=`${r}_session_update`,a=Yn.get(o);if(a&&this.isRequestOutOfSync(a,s)){this.client.logger.warn(`Discarding out of sync request - ${s}`),this.sendError({id:s,topic:r,error:oe("INVALID_UPDATE_REQUEST")});return}this.isValidUpdate(ie({topic:r},i));try{Yn.set(o,s),await this.client.session.update(r,{namespaces:i.namespaces}),await this.sendResult({id:s,topic:r,result:!0,throwOnFailedPublish:!0})}catch(c){throw Yn.delete(o),c}this.client.events.emit("session_update",{id:s,topic:r,params:i})}catch(o){await this.sendError({id:s,topic:r,error:o}),this.client.logger.error(o)}}),R(this,"isRequestOutOfSync",(r,n)=>n.toString().slice(0,-3)<r.toString().slice(0,-3)),R(this,"onSessionUpdateResponse",(r,n)=>{const{id:i}=n,s=Q("session_update",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);It(n)?this.events.emit(Q("session_update",i),{}):ot(n)&&this.events.emit(Q("session_update",i),{error:n.error})}),R(this,"onSessionExtendRequest",async(r,n)=>{const{id:i}=n;try{this.isValidExtend({topic:r}),await this.setExpiry(r,me(dn)),await this.sendResult({id:i,topic:r,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_extend",{id:i,topic:r})}catch(s){await this.sendError({id:i,topic:r,error:s}),this.client.logger.error(s)}}),R(this,"onSessionExtendResponse",(r,n)=>{const{id:i}=n,s=Q("session_extend",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);It(n)?this.events.emit(Q("session_extend",i),{}):ot(n)&&this.events.emit(Q("session_extend",i),{error:n.error})}),R(this,"onSessionPingRequest",async(r,n)=>{const{id:i}=n;try{this.isValidPing({topic:r}),await this.sendResult({id:i,topic:r,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_ping",{id:i,topic:r})}catch(s){await this.sendError({id:i,topic:r,error:s}),this.client.logger.error(s)}}),R(this,"onSessionPingResponse",(r,n)=>{const{id:i}=n,s=Q("session_ping",i);setTimeout(()=>{if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners 2176`);It(n)?this.events.emit(Q("session_ping",i),{}):ot(n)&&this.events.emit(Q("session_ping",i),{error:n.error})},500)}),R(this,"onSessionDeleteRequest",async(r,n)=>{const{id:i}=n;try{this.isValidDisconnect({topic:r,reason:n.params}),Promise.all([new Promise(s=>{this.client.core.relayer.once(Ie.publish,async()=>{s(await this.deleteSession({topic:r,id:i}))})}),this.sendResult({id:i,topic:r,result:!0,throwOnFailedPublish:!0}),this.cleanupPendingSentRequestsForTopic({topic:r,error:oe("USER_DISCONNECTED")})]).catch(s=>this.client.logger.error(s))}catch(s){this.client.logger.error(s)}}),R(this,"onSessionRequest",async r=>{var n,i,s;const{topic:o,payload:a,attestation:c,encryptedId:u,transportType:l}=r,{id:h,params:d}=a;try{await this.isValidRequest(ie({topic:o},d));const p=this.client.session.get(o),f=await this.getVerifyContext({attestationId:c,hash:St(JSON.stringify(Dr("wc_sessionRequest",d,h))),encryptedId:u,metadata:p.peer.metadata,transportType:l}),y={id:h,topic:o,params:d,verifyContext:f};await this.setPendingSessionRequest(y),l===ce.link_mode&&(n=p.peer.metadata.redirect)!=null&&n.universal&&this.client.core.addLinkModeSupportedApp((i=p.peer.metadata.redirect)==null?void 0:i.universal),(s=this.client.signConfig)!=null&&s.disableRequestQueue?this.emitSessionRequest(y):(this.addSessionRequestToSessionRequestQueue(y),this.processSessionRequestQueue())}catch(p){await this.sendError({id:h,topic:o,error:p}),this.client.logger.error(p)}}),R(this,"onSessionRequestResponse",(r,n)=>{const{id:i}=n,s=Q("session_request",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);It(n)?this.events.emit(Q("session_request",i),{result:n.result}):ot(n)&&this.events.emit(Q("session_request",i),{error:n.error})}),R(this,"onSessionEventRequest",async(r,n)=>{const{id:i,params:s}=n;try{const o=`${r}_session_event_${s.event.name}`,a=Yn.get(o);if(a&&this.isRequestOutOfSync(a,i)){this.client.logger.info(`Discarding out of sync request - ${i}`);return}this.isValidEmit(ie({topic:r},s)),this.client.events.emit("session_event",{id:i,topic:r,params:s}),Yn.set(o,i)}catch(o){await this.sendError({id:i,topic:r,error:o}),this.client.logger.error(o)}}),R(this,"onSessionAuthenticateResponse",(r,n)=>{const{id:i}=n;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:r,payload:n}),It(n)?this.events.emit(Q("session_request",i),{result:n.result}):ot(n)&&this.events.emit(Q("session_request",i),{error:n.error})}),R(this,"onSessionAuthenticateRequest",async r=>{var n;const{topic:i,payload:s,attestation:o,encryptedId:a,transportType:c}=r;try{const{requester:u,authPayload:l,expiryTimestamp:h}=s.params,d=await this.getVerifyContext({attestationId:o,hash:St(JSON.stringify(s)),encryptedId:a,metadata:u.metadata,transportType:c}),p={requester:u,pairingTopic:i,id:s.id,authPayload:l,verifyContext:d,expiryTimestamp:h};await this.setAuthRequest(s.id,{request:p,pairingTopic:i,transportType:c}),c===ce.link_mode&&(n=u.metadata.redirect)!=null&&n.universal&&this.client.core.addLinkModeSupportedApp(u.metadata.redirect.universal),this.client.events.emit("session_authenticate",{topic:i,params:s.params,id:s.id,verifyContext:d})}catch(u){this.client.logger.error(u);const l=s.params.requester.publicKey,h=await this.client.core.crypto.generateKeyPair(),d=this.getAppLinkIfEnabled(s.params.requester.metadata,c),p={type:jt,receiverPublicKey:l,senderPublicKey:h};await this.sendError({id:s.id,topic:i,error:u,encodeOpts:p,rpcOpts:Oe.wc_sessionAuthenticate.autoReject,appLink:d})}}),R(this,"addSessionRequestToSessionRequestQueue",r=>{this.sessionRequestQueue.queue.push(r)}),R(this,"cleanupAfterResponse",r=>{this.deletePendingSessionRequest(r.response.id,{message:"fulfilled",code:0}),setTimeout(()=>{this.sessionRequestQueue.state=At.idle,this.processSessionRequestQueue()},L.toMiliseconds(this.requestQueueDelay))}),R(this,"cleanupPendingSentRequestsForTopic",({topic:r,error:n})=>{const i=this.client.core.history.pending;i.length>0&&i.filter(s=>s.topic===r&&s.request.method==="wc_sessionRequest").forEach(s=>{const o=s.request.id,a=Q("session_request",o);if(this.events.listenerCount(a)===0)throw new Error(`emitting ${a} without any listeners`);this.events.emit(Q("session_request",s.request.id),{error:n})})}),R(this,"processSessionRequestQueue",()=>{if(this.sessionRequestQueue.state===At.active){this.client.logger.info("session request queue is already active.");return}const r=this.sessionRequestQueue.queue[0];if(!r){this.client.logger.info("session request queue is empty.");return}try{this.sessionRequestQueue.state=At.active,this.emitSessionRequest(r)}catch(n){this.client.logger.error(n)}}),R(this,"emitSessionRequest",r=>{this.client.events.emit("session_request",r)}),R(this,"onPairingCreated",r=>{if(r.methods&&this.expectedPairingMethodMap.set(r.topic,r.methods),r.active)return;const n=this.client.proposal.getAll().find(i=>i.pairingTopic===r.topic);n&&this.onSessionProposeRequest({topic:r.topic,payload:Dr("wc_sessionPropose",Ve(ie({},n),{requiredNamespaces:n.requiredNamespaces,optionalNamespaces:n.optionalNamespaces,relays:n.relays,proposer:n.proposer,sessionProperties:n.sessionProperties,scopedProperties:n.scopedProperties}),n.id)})}),R(this,"isValidConnect",async r=>{if(!Ze(r)){const{message:u}=U("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(r)}`);throw new Error(u)}const{pairingTopic:n,requiredNamespaces:i,optionalNamespaces:s,sessionProperties:o,scopedProperties:a,relays:c}=r;if(Re(n)||await this.isValidPairingTopic(n),!lS(c,!0)){const{message:u}=U("MISSING_OR_INVALID",`connect() relays: ${c}`);throw new Error(u)}if(!Re(i)&&ts(i)!==0&&this.validateNamespaces(i,"requiredNamespaces"),!Re(s)&&ts(s)!==0&&this.validateNamespaces(s,"optionalNamespaces"),Re(o)||this.validateSessionProps(o,"sessionProperties"),!Re(a)){this.validateSessionProps(a,"scopedProperties");const u=Object.keys(i||{}).concat(Object.keys(s||{}));if(!Object.keys(a).every(l=>u.includes(l)))throw new Error(`Scoped properties must be a subset of required/optional namespaces, received: ${JSON.stringify(a)}, required/optional namespaces: ${JSON.stringify(u)}`)}}),R(this,"validateNamespaces",(r,n)=>{const i=uS(r,"connect()",n);if(i)throw new Error(i.message)}),R(this,"isValidApprove",async r=>{if(!Ze(r))throw new Error(U("MISSING_OR_INVALID",`approve() params: ${r}`).message);const{id:n,namespaces:i,relayProtocol:s,sessionProperties:o,scopedProperties:a}=r;this.checkRecentlyDeleted(n),await this.isValidProposalId(n);const c=this.client.proposal.get(n),u=oa(i,"approve()");if(u)throw new Error(u.message);const l=Ed(c.requiredNamespaces,i,"approve()");if(l)throw new Error(l.message);if(!pe(s,!0)){const{message:h}=U("MISSING_OR_INVALID",`approve() relayProtocol: ${s}`);throw new Error(h)}if(Re(o)||this.validateSessionProps(o,"sessionProperties"),!Re(a)){this.validateSessionProps(a,"scopedProperties");const h=new Set(Object.keys(i));if(!Object.keys(a).every(d=>h.has(d)))throw new Error(`Scoped properties must be a subset of approved namespaces, received: ${JSON.stringify(a)}, approved namespaces: ${Array.from(h).join(", ")}`)}}),R(this,"isValidReject",async r=>{if(!Ze(r)){const{message:s}=U("MISSING_OR_INVALID",`reject() params: ${r}`);throw new Error(s)}const{id:n,reason:i}=r;if(this.checkRecentlyDeleted(n),await this.isValidProposalId(n),!dS(i)){const{message:s}=U("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(i)}`);throw new Error(s)}}),R(this,"isValidSessionSettleRequest",r=>{if(!Ze(r)){const{message:u}=U("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${r}`);throw new Error(u)}const{relay:n,controller:i,namespaces:s,expiry:o}=r;if(!bd(n)){const{message:u}=U("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(u)}const a=nS(i,"onSessionSettleRequest()");if(a)throw new Error(a.message);const c=oa(s,"onSessionSettleRequest()");if(c)throw new Error(c.message);if(nr(o)){const{message:u}=U("EXPIRED","onSessionSettleRequest()");throw new Error(u)}}),R(this,"isValidUpdate",async r=>{if(!Ze(r)){const{message:c}=U("MISSING_OR_INVALID",`update() params: ${r}`);throw new Error(c)}const{topic:n,namespaces:i}=r;this.checkRecentlyDeleted(n),await this.isValidSessionTopic(n);const s=this.client.session.get(n),o=oa(i,"update()");if(o)throw new Error(o.message);const a=Ed(s.requiredNamespaces,i,"update()");if(a)throw new Error(a.message)}),R(this,"isValidExtend",async r=>{if(!Ze(r)){const{message:i}=U("MISSING_OR_INVALID",`extend() params: ${r}`);throw new Error(i)}const{topic:n}=r;this.checkRecentlyDeleted(n),await this.isValidSessionTopic(n)}),R(this,"isValidRequest",async r=>{if(!Ze(r)){const{message:c}=U("MISSING_OR_INVALID",`request() params: ${r}`);throw new Error(c)}const{topic:n,request:i,chainId:s,expiry:o}=r;this.checkRecentlyDeleted(n),await this.isValidSessionTopic(n);const{namespaces:a}=this.client.session.get(n);if(!vd(a,s)){const{message:c}=U("MISSING_OR_INVALID",`request() chainId: ${s}`);throw new Error(c)}if(!fS(i)){const{message:c}=U("MISSING_OR_INVALID",`request() ${JSON.stringify(i)}`);throw new Error(c)}if(!yS(a,s,i.method)){const{message:c}=U("MISSING_OR_INVALID",`request() method: ${i.method}`);throw new Error(c)}if(o&&!vS(o,Ca)){const{message:c}=U("MISSING_OR_INVALID",`request() expiry: ${o}. Expiry must be a number (in seconds) between ${Ca.min} and ${Ca.max}`);throw new Error(c)}}),R(this,"isValidRespond",async r=>{var n;if(!Ze(r)){const{message:o}=U("MISSING_OR_INVALID",`respond() params: ${r}`);throw new Error(o)}const{topic:i,response:s}=r;try{await this.isValidSessionTopic(i)}catch(o){throw(n=r?.response)!=null&&n.id&&this.cleanupAfterResponse(r),o}if(!pS(s)){const{message:o}=U("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(s)}`);throw new Error(o)}}),R(this,"isValidPing",async r=>{if(!Ze(r)){const{message:i}=U("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(i)}const{topic:n}=r;await this.isValidSessionOrPairingTopic(n)}),R(this,"isValidEmit",async r=>{if(!Ze(r)){const{message:a}=U("MISSING_OR_INVALID",`emit() params: ${r}`);throw new Error(a)}const{topic:n,event:i,chainId:s}=r;await this.isValidSessionTopic(n);const{namespaces:o}=this.client.session.get(n);if(!vd(o,s)){const{message:a}=U("MISSING_OR_INVALID",`emit() chainId: ${s}`);throw new Error(a)}if(!gS(i)){const{message:a}=U("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}if(!wS(o,s,i.name)){const{message:a}=U("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}}),R(this,"isValidDisconnect",async r=>{if(!Ze(r)){const{message:i}=U("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(i)}const{topic:n}=r;await this.isValidSessionOrPairingTopic(n)}),R(this,"isValidAuthenticate",r=>{const{chains:n,uri:i,domain:s,nonce:o}=r;if(!Array.isArray(n)||n.length===0)throw new Error("chains is required and must be a non-empty array");if(!pe(i,!1))throw new Error("uri is required parameter");if(!pe(s,!1))throw new Error("domain is required parameter");if(!pe(o,!1))throw new Error("nonce is required parameter");if([...new Set(n.map(c=>Mi(c).namespace))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");const{namespace:a}=Mi(n[0]);if(a!=="eip155")throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")}),R(this,"getVerifyContext",async r=>{const{attestationId:n,hash:i,encryptedId:s,metadata:o,transportType:a}=r,c={verified:{verifyUrl:o.verifyUrl||Qn,validation:"UNKNOWN",origin:o.url||""}};try{if(a===ce.link_mode){const l=this.getAppLinkIfEnabled(o,a);return c.verified.validation=l&&new URL(l).origin===new URL(o.url).origin?"VALID":"INVALID",c}const u=await this.client.core.verify.resolve({attestationId:n,hash:i,encryptedId:s,verifyUrl:o.verifyUrl});u&&(c.verified.origin=u.origin,c.verified.isScam=u.isScam,c.verified.validation=u.origin===new URL(o.url).origin?"VALID":"INVALID")}catch(u){this.client.logger.warn(u)}return this.client.logger.debug(`Verify context: ${JSON.stringify(c)}`),c}),R(this,"validateSessionProps",(r,n)=>{Object.values(r).forEach((i,s)=>{if(i==null){const{message:o}=U("MISSING_OR_INVALID",`${n} must contain an existing value for each key. Received: ${i} for key ${Object.keys(r)[s]}`);throw new Error(o)}})}),R(this,"getPendingAuthRequest",r=>{const n=this.client.auth.requests.get(r);return typeof n=="object"?n:void 0}),R(this,"addToRecentlyDeleted",(r,n)=>{if(this.recentlyDeletedMap.set(r,n),this.recentlyDeletedMap.size>=this.recentlyDeletedLimit){let i=0;const s=this.recentlyDeletedLimit/2;for(const o of this.recentlyDeletedMap.keys()){if(i++>=s)break;this.recentlyDeletedMap.delete(o)}}}),R(this,"checkRecentlyDeleted",r=>{const n=this.recentlyDeletedMap.get(r);if(n){const{message:i}=U("MISSING_OR_INVALID",`Record was recently deleted - ${n}: ${r}`);throw new Error(i)}}),R(this,"isLinkModeEnabled",(r,n)=>{var i,s,o,a,c,u,l,h,d;return!r||n!==ce.link_mode?!1:((s=(i=this.client.metadata)==null?void 0:i.redirect)==null?void 0:s.linkMode)===!0&&((a=(o=this.client.metadata)==null?void 0:o.redirect)==null?void 0:a.universal)!==void 0&&((u=(c=this.client.metadata)==null?void 0:c.redirect)==null?void 0:u.universal)!==""&&((l=r?.redirect)==null?void 0:l.universal)!==void 0&&((h=r?.redirect)==null?void 0:h.universal)!==""&&((d=r?.redirect)==null?void 0:d.linkMode)===!0&&this.client.core.linkModeSupportedApps.includes(r.redirect.universal)&&typeof(global==null?void 0:global.Linking)<"u"}),R(this,"getAppLinkIfEnabled",(r,n)=>{var i;return this.isLinkModeEnabled(r,n)?(i=r?.redirect)==null?void 0:i.universal:void 0}),R(this,"handleLinkModeMessage",({url:r})=>{if(!r||!r.includes("wc_ev")||!r.includes("topic"))return;const n=sh(r,"topic")||"",i=decodeURIComponent(sh(r,"wc_ev")||""),s=this.client.session.keys.includes(n);s&&this.client.session.update(n,{transportType:ce.link_mode}),this.client.core.dispatchEnvelope({topic:n,message:i,sessionExists:s})}),R(this,"registerLinkModeListeners",async()=>{var r;if(To()||tr()&&(r=this.client.metadata.redirect)!=null&&r.linkMode){const n=global==null?void 0:global.Linking;if(typeof n<"u"){n.addEventListener("url",this.handleLinkModeMessage,this.client.name);const i=await n.getInitialURL();i&&setTimeout(()=>{this.handleLinkModeMessage({url:i})},50)}}}),R(this,"shouldSetTVF",(r,n)=>{if(!n||r!=="wc_sessionRequest")return!1;const{request:i}=n;return Object.keys(Df).includes(i.method)}),R(this,"getTVFParams",(r,n,i)=>{var s,o;try{const a=n.request.method,c=this.extractTxHashesFromResult(a,i);return Ve(ie({correlationId:r,rpcMethods:[a],chainId:n.chainId},this.isValidContractData(n.request.params)&&{contractAddresses:[(o=(s=n.request.params)==null?void 0:s[0])==null?void 0:o.to]}),{txHashes:c})}catch(a){this.client.logger.warn("Error getting TVF params",a)}return{}}),R(this,"isValidContractData",r=>{var n;if(!r)return!1;try{const i=r?.data||((n=r?.[0])==null?void 0:n.data);if(!i.startsWith("0x"))return!1;const s=i.slice(2);return/^[0-9a-fA-F]*$/.test(s)?s.length%2===0:!1}catch{}return!1}),R(this,"extractTxHashesFromResult",(r,n)=>{try{const i=Df[r];if(typeof n=="string")return[n];const s=n[i.key];if(Gn(s))return r==="solana_signAllTransactions"?s.map(o=>YE(o)):s;if(typeof s=="string")return[s]}catch(i){this.client.logger.warn("Error extracting tx hashes from result",i)}return[]})}async processPendingMessageEvents(){try{const e=this.client.session.keys,r=this.client.core.relayer.messages.getWithoutAck(e);for(const[n,i]of Object.entries(r))for(const s of i)try{await this.onProviderMessageEvent({topic:n,message:s,publishedAt:Date.now()})}catch{this.client.logger.warn(`Error processing pending message event for topic: ${n}, message: ${s}`)}}catch(e){this.client.logger.warn("processPendingMessageEvents failed",e)}}isInitialized(){if(!this.initialized){const{message:e}=U("NOT_INITIALIZED",this.name);throw new Error(e)}}async confirmOnlineStateOrThrow(){await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(Ie.message,e=>{this.onProviderMessageEvent(e)})}async onRelayMessage(e){const{topic:r,message:n,attestation:i,transportType:s}=e,{publicKey:o}=this.client.auth.authKeys.keys.includes(us)?this.client.auth.authKeys.get(us):{responseTopic:void 0,publicKey:void 0};try{const a=await this.client.core.crypto.decode(r,n,{receiverPublicKey:o,encoding:s===ce.link_mode?ar:dt});pa(a)?(this.client.core.history.set(r,a),await this.onRelayEventRequest({topic:r,payload:a,attestation:i,transportType:s,encryptedId:St(n)})):ns(a)?(await this.client.core.history.resolve(a),await this.onRelayEventResponse({topic:r,payload:a,transportType:s}),this.client.core.history.delete(r,a.id)):await this.onRelayEventUnknownPayload({topic:r,payload:a,transportType:s}),await this.client.core.relayer.messages.ack(r,n)}catch(a){this.client.logger.error(a)}}registerExpirerEvents(){this.client.core.expirer.on(ct.expired,async e=>{const{topic:r,id:n}=ih(e.target);if(n&&this.client.pendingRequest.keys.includes(n))return await this.deletePendingSessionRequest(n,U("EXPIRED"),!0);if(n&&this.client.auth.requests.keys.includes(n))return await this.deletePendingAuthRequest(n,U("EXPIRED"),!0);r?this.client.session.keys.includes(r)&&(await this.deleteSession({topic:r,expirerHasDeleted:!0}),this.client.events.emit("session_expire",{topic:r})):n&&(await this.deleteProposal(n,!0),this.client.events.emit("proposal_expire",{id:n}))})}registerPairingEvents(){this.client.core.pairing.events.on(Or.create,e=>this.onPairingCreated(e)),this.client.core.pairing.events.on(Or.delete,e=>{this.addToRecentlyDeleted(e.topic,"pairing")})}isValidPairingTopic(e){if(!pe(e,!1)){const{message:r}=U("MISSING_OR_INVALID",`pairing topic should be a string: ${e}`);throw new Error(r)}if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:r}=U("NO_MATCHING_KEY",`pairing topic doesn't exist: ${e}`);throw new Error(r)}if(nr(this.client.core.pairing.pairings.get(e).expiry)){const{message:r}=U("EXPIRED",`pairing topic: ${e}`);throw new Error(r)}}async isValidSessionTopic(e){if(!pe(e,!1)){const{message:r}=U("MISSING_OR_INVALID",`session topic should be a string: ${e}`);throw new Error(r)}if(this.checkRecentlyDeleted(e),!this.client.session.keys.includes(e)){const{message:r}=U("NO_MATCHING_KEY",`session topic doesn't exist: ${e}`);throw new Error(r)}if(nr(this.client.session.get(e).expiry)){await this.deleteSession({topic:e});const{message:r}=U("EXPIRED",`session topic: ${e}`);throw new Error(r)}if(!this.client.core.crypto.keychain.has(e)){const{message:r}=U("MISSING_OR_INVALID",`session topic does not exist in keychain: ${e}`);throw await this.deleteSession({topic:e}),new Error(r)}}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(pe(e,!1)){const{message:r}=U("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${e}`);throw new Error(r)}else{const{message:r}=U("MISSING_OR_INVALID",`session or pairing topic should be a string: ${e}`);throw new Error(r)}}async isValidProposalId(e){if(!hS(e)){const{message:r}=U("MISSING_OR_INVALID",`proposal id should be a number: ${e}`);throw new Error(r)}if(!this.client.proposal.keys.includes(e)){const{message:r}=U("NO_MATCHING_KEY",`proposal id doesn't exist: ${e}`);throw new Error(r)}if(nr(this.client.proposal.get(e).expiryTimestamp)){await this.deleteProposal(e);const{message:r}=U("EXPIRED",`proposal id: ${e}`);throw new Error(r)}}}class dD extends Pr{constructor(e,r){super(e,r,Z8,Ta),this.core=e,this.logger=r}}class $f extends Pr{constructor(e,r){super(e,r,J8,Ta),this.core=e,this.logger=r}}class fD extends Pr{constructor(e,r){super(e,r,Q8,Ta,n=>n.id),this.core=e,this.logger=r}}class pD extends Pr{constructor(e,r){super(e,r,nD,cs,()=>us),this.core=e,this.logger=r}}class gD extends Pr{constructor(e,r){super(e,r,iD,cs),this.core=e,this.logger=r}}class yD extends Pr{constructor(e,r){super(e,r,sD,cs,n=>n.id),this.core=e,this.logger=r}}var wD=Object.defineProperty,mD=(t,e,r)=>e in t?wD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ba=(t,e,r)=>mD(t,typeof e!="symbol"?e+"":e,r);class bD{constructor(e,r){this.core=e,this.logger=r,Ba(this,"authKeys"),Ba(this,"pairingTopics"),Ba(this,"requests"),this.authKeys=new pD(this.core,this.logger),this.pairingTopics=new gD(this.core,this.logger),this.requests=new yD(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}var vD=Object.defineProperty,ED=(t,e,r)=>e in t?vD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Z=(t,e,r)=>ED(t,typeof e!="symbol"?e+"":e,r);class Fa extends Zg{constructor(e){super(e),Z(this,"protocol",Ef),Z(this,"version",_f),Z(this,"name",Ra.name),Z(this,"metadata"),Z(this,"core"),Z(this,"logger"),Z(this,"events",new Le.exports.EventEmitter),Z(this,"engine"),Z(this,"session"),Z(this,"proposal"),Z(this,"pendingRequest"),Z(this,"auth"),Z(this,"signConfig"),Z(this,"on",(n,i)=>this.events.on(n,i)),Z(this,"once",(n,i)=>this.events.once(n,i)),Z(this,"off",(n,i)=>this.events.off(n,i)),Z(this,"removeListener",(n,i)=>this.events.removeListener(n,i)),Z(this,"removeAllListeners",n=>this.events.removeAllListeners(n)),Z(this,"connect",async n=>{try{return await this.engine.connect(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"pair",async n=>{try{return await this.engine.pair(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"approve",async n=>{try{return await this.engine.approve(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"reject",async n=>{try{return await this.engine.reject(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"update",async n=>{try{return await this.engine.update(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"extend",async n=>{try{return await this.engine.extend(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"request",async n=>{try{return await this.engine.request(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"respond",async n=>{try{return await this.engine.respond(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"ping",async n=>{try{return await this.engine.ping(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"emit",async n=>{try{return await this.engine.emit(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"disconnect",async n=>{try{return await this.engine.disconnect(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"find",n=>{try{return this.engine.find(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"getPendingSessionRequests",()=>{try{return this.engine.getPendingSessionRequests()}catch(n){throw this.logger.error(n.message),n}}),Z(this,"authenticate",async(n,i)=>{try{return await this.engine.authenticate(n,i)}catch(s){throw this.logger.error(s.message),s}}),Z(this,"formatAuthMessage",n=>{try{return this.engine.formatAuthMessage(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"approveSessionAuthenticate",async n=>{try{return await this.engine.approveSessionAuthenticate(n)}catch(i){throw this.logger.error(i.message),i}}),Z(this,"rejectSessionAuthenticate",async n=>{try{return await this.engine.rejectSessionAuthenticate(n)}catch(i){throw this.logger.error(i.message),i}}),this.name=e?.name||Ra.name,this.metadata=cE(e?.metadata),this.signConfig=e?.signConfig;const r=typeof e?.logger<"u"&&typeof e?.logger!="string"?e.logger:Pt(Is({level:e?.logger||Ra.logger}));this.core=e?.core||new Pa(e),this.logger=je(r,this.name),this.session=new $f(this.core,this.logger),this.proposal=new dD(this.core,this.logger),this.pendingRequest=new fD(this.core,this.logger),this.engine=new hD(this),this.auth=new bD(this.core,this.logger)}static async init(e){const r=new Fa(e);return await r.initialize(),r}get context(){return He(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"),setTimeout(()=>{this.engine.processRelayMessageCache()},L.toMiliseconds(L.ONE_SECOND))}catch(e){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(e.message),e}}}const _D=$f,SD=Fa;class xD extends Le.exports{constructor(){super()}}class Af{constructor(e){this.opts=e}}class Pf{constructor(e){this.client=e}}var ID=Object.defineProperty,DD=Object.defineProperties,OD=Object.getOwnPropertyDescriptors,Tf=Object.getOwnPropertySymbols,$D=Object.prototype.hasOwnProperty,AD=Object.prototype.propertyIsEnumerable,Rf=(t,e,r)=>e in t?ID(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,PD=(t,e)=>{for(var r in e||(e={}))$D.call(e,r)&&Rf(t,r,e[r]);if(Tf)for(var r of Tf(e))AD.call(e,r)&&Rf(t,r,e[r]);return t},TD=(t,e)=>DD(t,OD(e));class RD extends Pf{constructor(e){super(e),this.init=async()=>{this.signClient=await SD.init({core:this.client.core,metadata:this.client.metadata,signConfig:this.client.signConfig}),this.signClient.core.eventClient.init().catch(r=>{this.client.logger.warn(r)})},this.pair=async r=>{await this.client.core.pairing.pair(r)},this.approveSession=async r=>{const{topic:n,acknowledged:i}=await this.signClient.approve(TD(PD({},r),{id:r.id,namespaces:r.namespaces,sessionProperties:r.sessionProperties,sessionConfig:r.sessionConfig}));return await i(),this.signClient.session.get(n)},this.rejectSession=async r=>await this.signClient.reject(r),this.updateSession=async r=>await this.signClient.update(r),this.extendSession=async r=>await this.signClient.extend(r),this.respondSessionRequest=async r=>await this.signClient.respond(r),this.disconnectSession=async r=>await this.signClient.disconnect(r),this.emitSessionEvent=async r=>await this.signClient.emit(r),this.getActiveSessions=()=>this.signClient.session.getAll().reduce((r,n)=>(r[n.topic]=n,r),{}),this.getPendingSessionProposals=()=>this.signClient.proposal.getAll(),this.getPendingSessionRequests=()=>this.signClient.getPendingSessionRequests(),this.approveSessionAuthenticate=async r=>await this.signClient.approveSessionAuthenticate(r),this.rejectSessionAuthenticate=async r=>await this.signClient.rejectSessionAuthenticate(r),this.formatAuthMessage=r=>this.signClient.formatAuthMessage(r),this.registerDeviceToken=r=>this.client.core.echoClient.registerDeviceToken(r),this.on=(r,n)=>(this.setEvent(r,"off"),this.setEvent(r,"on"),this.client.events.on(r,n)),this.once=(r,n)=>(this.setEvent(r,"off"),this.setEvent(r,"once"),this.client.events.once(r,n)),this.off=(r,n)=>(this.setEvent(r,"off"),this.client.events.off(r,n)),this.removeListener=(r,n)=>(this.setEvent(r,"removeListener"),this.client.events.removeListener(r,n)),this.onSessionRequest=r=>{this.client.events.emit("session_request",r)},this.onSessionProposal=r=>{this.client.events.emit("session_proposal",r)},this.onSessionDelete=r=>{this.client.events.emit("session_delete",r)},this.onProposalExpire=r=>{this.client.events.emit("proposal_expire",r)},this.onSessionRequestExpire=r=>{this.client.events.emit("session_request_expire",r)},this.onSessionRequestAuthenticate=r=>{this.client.events.emit("session_authenticate",r)},this.setEvent=(r,n)=>{switch(r){case"session_request":this.signClient.events[n]("session_request",this.onSessionRequest);break;case"session_proposal":this.signClient.events[n]("session_proposal",this.onSessionProposal);break;case"session_delete":this.signClient.events[n]("session_delete",this.onSessionDelete);break;case"proposal_expire":this.signClient.events[n]("proposal_expire",this.onProposalExpire);break;case"session_request_expire":this.signClient.events[n]("session_request_expire",this.onSessionRequestExpire);break;case"session_authenticate":this.signClient.events[n]("session_authenticate",this.onSessionRequestAuthenticate);break}},this.signClient={}}}const CD={decryptMessage:async t=>{const e={core:new Pa({storageOptions:t.storageOptions,storage:t.storage})};await e.core.crypto.init();const r=e.core.crypto.decode(t.topic,t.encryptedMessage);return e.core=null,r},getMetadata:async t=>{const e={core:new Pa({storageOptions:t.storageOptions,storage:t.storage}),sessionStore:null};e.sessionStore=new _D(e.core,e.core.logger),await e.sessionStore.init();const r=e.sessionStore.get(t.topic),n=r?.peer.metadata;return e.core=null,e.sessionStore=null,n}},Cf=class extends Af{constructor(t){super(t),this.events=new Le.exports,this.on=(e,r)=>this.engine.on(e,r),this.once=(e,r)=>this.engine.once(e,r),this.off=(e,r)=>this.engine.off(e,r),this.removeListener=(e,r)=>this.engine.removeListener(e,r),this.pair=async e=>{try{return await this.engine.pair(e)}catch(r){throw this.logger.error(r.message),r}},this.approveSession=async e=>{try{return await this.engine.approveSession(e)}catch(r){throw this.logger.error(r.message),r}},this.rejectSession=async e=>{try{return await this.engine.rejectSession(e)}catch(r){throw this.logger.error(r.message),r}},this.updateSession=async e=>{try{return await this.engine.updateSession(e)}catch(r){throw this.logger.error(r.message),r}},this.extendSession=async e=>{try{return await this.engine.extendSession(e)}catch(r){throw this.logger.error(r.message),r}},this.respondSessionRequest=async e=>{try{return await this.engine.respondSessionRequest(e)}catch(r){throw this.logger.error(r.message),r}},this.disconnectSession=async e=>{try{return await this.engine.disconnectSession(e)}catch(r){throw this.logger.error(r.message),r}},this.emitSessionEvent=async e=>{try{return await this.engine.emitSessionEvent(e)}catch(r){throw this.logger.error(r.message),r}},this.getActiveSessions=()=>{try{return this.engine.getActiveSessions()}catch(e){throw this.logger.error(e.message),e}},this.getPendingSessionProposals=()=>{try{return this.engine.getPendingSessionProposals()}catch(e){throw this.logger.error(e.message),e}},this.getPendingSessionRequests=()=>{try{return this.engine.getPendingSessionRequests()}catch(e){throw this.logger.error(e.message),e}},this.registerDeviceToken=e=>{try{return this.engine.registerDeviceToken(e)}catch(r){throw this.logger.error(r.message),r}},this.approveSessionAuthenticate=e=>{try{return this.engine.approveSessionAuthenticate(e)}catch(r){throw this.logger.error(r.message),r}},this.rejectSessionAuthenticate=e=>{try{return this.engine.rejectSessionAuthenticate(e)}catch(r){throw this.logger.error(r.message),r}},this.formatAuthMessage=e=>{try{return this.engine.formatAuthMessage(e)}catch(r){throw this.logger.error(r.message),r}},this.metadata=t.metadata,this.name=t.name||ls,this.signConfig=t.signConfig,this.core=t.core,this.logger=this.core.logger,this.engine=new RD(this)}static async init(t){const e=new Cf(t);return await e.initialize(),e}async initialize(){this.logger.trace("Initialized");try{await this.engine.init(),this.logger.info("WalletKit Initialization Success")}catch(t){throw this.logger.info("WalletKit Initialization Failure"),this.logger.error(t.message),t}}};let La=Cf;La.notifications=CD;const ND=La;Fe.CLIENT_CONTEXT=ls,Fe.CLIENT_STORAGE_OPTIONS=Yf,Fe.CLIENT_STORAGE_PREFIX=Gf,Fe.IWalletKit=Af,Fe.IWalletKitEngine=Pf,Fe.IWalletKitEvents=xD,Fe.PROTOCOL=Za,Fe.PROTOCOL_VERSION=Wf,Fe.REQUEST_CONTEXT=Zf,Fe.WalletKit=ND,Fe.default=La,Object.defineProperty(Fe,"__esModule",{value:!0})});
40
40
  //# sourceMappingURL=index.umd.js.map