@reown/walletkit 1.3.0 → 1.4.1-canary-0

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(He,Jt){typeof exports=="object"&&typeof module<"u"?Jt(exports):typeof define=="function"&&define.amd?define(["exports"],Jt):(He=typeof globalThis<"u"?globalThis:He||self,Jt(He["@reown/walletkit"]={}))})(this,function(He){"use strict";var Jt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Wl(t){var e=t.default;if(typeof e=="function"){var n=function(){return e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}),n}var Ve={exports:{}},ei=typeof Reflect=="object"?Reflect:null,Zl=ei&&typeof ei.apply=="function"?ei.apply:function(e,n,r){return Function.prototype.apply.call(e,n,r)},Ls;ei&&typeof ei.ownKeys=="function"?Ls=ei.ownKeys:Object.getOwnPropertySymbols?Ls=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Ls=function(e){return Object.getOwnPropertyNames(e)};function Zy(t){console&&console.warn&&console.warn(t)}var Yl=Number.isNaN||function(e){return e!==e};function de(){de.init.call(this)}Ve.exports=de,Ve.exports.once=Qy,de.EventEmitter=de,de.prototype._events=void 0,de.prototype._eventsCount=0,de.prototype._maxListeners=void 0;var Xl=10;function ks(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(de,"defaultMaxListeners",{enumerable:!0,get:function(){return Xl},set:function(t){if(typeof t!="number"||t<0||Yl(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Xl=t}}),de.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},de.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Yl(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 Jl(t){return t._maxListeners===void 0?de.defaultMaxListeners:t._maxListeners}de.prototype.getMaxListeners=function(){return Jl(this)},de.prototype.emit=function(e){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);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(n.length>0&&(o=n[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")Zl(c,this,n);else for(var u=c.length,l=rf(c,u),r=0;r<u;++r)Zl(l[r],this,n);return!0};function Ql(t,e,n,r){var i,s,o;if(ks(n),s=t._events,s===void 0?(s=t._events=Object.create(null),t._eventsCount=0):(s.newListener!==void 0&&(t.emit("newListener",e,n.listener?n.listener:n),s=t._events),o=s[e]),o===void 0)o=s[e]=n,++t._eventsCount;else if(typeof o=="function"?o=s[e]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),i=Jl(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,Zy(a)}return t}de.prototype.addListener=function(e,n){return Ql(this,e,n,!1)},de.prototype.on=de.prototype.addListener,de.prototype.prependListener=function(e,n){return Ql(this,e,n,!0)};function Yy(){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 ef(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=Yy.bind(r);return i.listener=n,r.wrapFn=i,i}de.prototype.once=function(e,n){return ks(n),this.on(e,ef(this,e,n)),this},de.prototype.prependOnceListener=function(e,n){return ks(n),this.prependListener(e,ef(this,e,n)),this},de.prototype.removeListener=function(e,n){var r,i,s,o,a;if(ks(n),i=this._events,i===void 0)return this;if(r=i[e],r===void 0)return this;if(r===n||r.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||n));else if(typeof r!="function"){for(s=-1,o=r.length-1;o>=0;o--)if(r[o]===n||r[o].listener===n){a=r[o].listener,s=o;break}if(s<0)return this;s===0?r.shift():Xy(r,s),r.length===1&&(i[e]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||n)}return this},de.prototype.off=de.prototype.removeListener,de.prototype.removeAllListeners=function(e){var n,r,i;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[e]),this;if(arguments.length===0){var s=Object.keys(r),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(n=r[e],typeof n=="function")this.removeListener(e,n);else if(n!==void 0)for(i=n.length-1;i>=0;i--)this.removeListener(e,n[i]);return this};function tf(t,e,n){var r=t._events;if(r===void 0)return[];var i=r[e];return i===void 0?[]:typeof i=="function"?n?[i.listener||i]:[i]:n?Jy(i):rf(i,i.length)}de.prototype.listeners=function(e){return tf(this,e,!0)},de.prototype.rawListeners=function(e){return tf(this,e,!1)},de.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):nf.call(t,e)},de.prototype.listenerCount=nf;function nf(t){var e=this._events;if(e!==void 0){var n=e[t];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}de.prototype.eventNames=function(){return this._eventsCount>0?Ls(this._events):[]};function rf(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function Xy(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function Jy(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}function Qy(t,e){return new Promise(function(n,r){function i(o){t.removeListener(e,s),r(o)}function s(){typeof t.removeListener=="function"&&t.removeListener("error",i),n([].slice.call(arguments))}sf(t,e,s,{once:!0}),e!=="error"&&eb(t,i,{once:!0})})}function eb(t,e,n){typeof t.on=="function"&&sf(t,"error",e,n)}function sf(t,e,n,r){if(typeof t.on=="function")r.once?t.once(e,n):t.on(e,n);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(s){r.once&&t.removeEventListener(e,i),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}const of="wc",tb=2,Oa="WalletKit",nb=`${of}@2:${Oa}:`,rb={database:":memory:"},ib="request";var K={};/*! *****************************************************************************
1
+ (function(Ye,kn){typeof exports=="object"&&typeof module<"u"?kn(exports):typeof define=="function"&&define.amd?define(["exports"],kn):(Ye=typeof globalThis<"u"?globalThis:Ye||self,kn(Ye["@reown/walletkit"]={}))})(this,function(Ye){"use strict";var kn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function e1(t){var e=t.default;if(typeof e=="function"){var n=function(){return e.apply(this,arguments)};n.prototype=e.prototype}else n={};return Object.defineProperty(n,"__esModule",{value:!0}),Object.keys(t).forEach(function(r){var i=Object.getOwnPropertyDescriptor(t,r);Object.defineProperty(n,r,i.get?i:{enumerable:!0,get:function(){return t[r]}})}),n}var at={exports:{}},Us=typeof Reflect=="object"?Reflect:null,t1=Us&&typeof Us.apply=="function"?Us.apply:function(e,n,r){return Function.prototype.apply.call(e,n,r)},nc;Us&&typeof Us.ownKeys=="function"?nc=Us.ownKeys:Object.getOwnPropertySymbols?nc=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:nc=function(e){return Object.getOwnPropertyNames(e)};function Nv(t){console&&console.warn&&console.warn(t)}var n1=Number.isNaN||function(e){return e!==e};function me(){me.init.call(this)}at.exports=me,at.exports.once=Fv,me.EventEmitter=me,me.prototype._events=void 0,me.prototype._eventsCount=0,me.prototype._maxListeners=void 0;var r1=10;function rc(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(me,"defaultMaxListeners",{enumerable:!0,get:function(){return r1},set:function(t){if(typeof t!="number"||t<0||n1(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");r1=t}}),me.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},me.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||n1(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 i1(t){return t._maxListeners===void 0?me.defaultMaxListeners:t._maxListeners}me.prototype.getMaxListeners=function(){return i1(this)},me.prototype.emit=function(e){for(var n=[],r=1;r<arguments.length;r++)n.push(arguments[r]);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(n.length>0&&(o=n[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")t1(c,this,n);else for(var f=c.length,l=f1(c,f),r=0;r<f;++r)t1(l[r],this,n);return!0};function s1(t,e,n,r){var i,s,o;if(rc(n),s=t._events,s===void 0?(s=t._events=Object.create(null),t._eventsCount=0):(s.newListener!==void 0&&(t.emit("newListener",e,n.listener?n.listener:n),s=t._events),o=s[e]),o===void 0)o=s[e]=n,++t._eventsCount;else if(typeof o=="function"?o=s[e]=r?[n,o]:[o,n]:r?o.unshift(n):o.push(n),i=i1(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,Nv(a)}return t}me.prototype.addListener=function(e,n){return s1(this,e,n,!1)},me.prototype.on=me.prototype.addListener,me.prototype.prependListener=function(e,n){return s1(this,e,n,!0)};function Uv(){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 o1(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=Uv.bind(r);return i.listener=n,r.wrapFn=i,i}me.prototype.once=function(e,n){return rc(n),this.on(e,o1(this,e,n)),this},me.prototype.prependOnceListener=function(e,n){return rc(n),this.prependListener(e,o1(this,e,n)),this},me.prototype.removeListener=function(e,n){var r,i,s,o,a;if(rc(n),i=this._events,i===void 0)return this;if(r=i[e],r===void 0)return this;if(r===n||r.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete i[e],i.removeListener&&this.emit("removeListener",e,r.listener||n));else if(typeof r!="function"){for(s=-1,o=r.length-1;o>=0;o--)if(r[o]===n||r[o].listener===n){a=r[o].listener,s=o;break}if(s<0)return this;s===0?r.shift():Cv(r,s),r.length===1&&(i[e]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||n)}return this},me.prototype.off=me.prototype.removeListener,me.prototype.removeAllListeners=function(e){var n,r,i;if(r=this._events,r===void 0)return this;if(r.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):r[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete r[e]),this;if(arguments.length===0){var s=Object.keys(r),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(n=r[e],typeof n=="function")this.removeListener(e,n);else if(n!==void 0)for(i=n.length-1;i>=0;i--)this.removeListener(e,n[i]);return this};function a1(t,e,n){var r=t._events;if(r===void 0)return[];var i=r[e];return i===void 0?[]:typeof i=="function"?n?[i.listener||i]:[i]:n?Lv(i):f1(i,i.length)}me.prototype.listeners=function(e){return a1(this,e,!0)},me.prototype.rawListeners=function(e){return a1(this,e,!1)},me.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):c1.call(t,e)},me.prototype.listenerCount=c1;function c1(t){var e=this._events;if(e!==void 0){var n=e[t];if(typeof n=="function")return 1;if(n!==void 0)return n.length}return 0}me.prototype.eventNames=function(){return this._eventsCount>0?nc(this._events):[]};function f1(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function Cv(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function Lv(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}function Fv(t,e){return new Promise(function(n,r){function i(o){t.removeListener(e,s),r(o)}function s(){typeof t.removeListener=="function"&&t.removeListener("error",i),n([].slice.call(arguments))}u1(t,e,s,{once:!0}),e!=="error"&&kv(t,i,{once:!0})})}function kv(t,e,n){typeof t.on=="function"&&u1(t,"error",e,n)}function u1(t,e,n,r){if(typeof t.on=="function")r.once?t.once(e,n):t.on(e,n);else if(typeof t.addEventListener=="function")t.addEventListener(e,function i(s){r.once&&t.removeEventListener(e,i),n(s)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof t)}var xu={exports:{}};function qv(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}var jv=Mv;function Mv(t,e,n){var r=n&&n.stringify||qv,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]=r(t);for(var a=1;a<s;a++)o[a]=r(e[a]);return o.join(" ")}if(typeof t!="string")return t;var c=e.length;if(c===0)return t;for(var f="",l=1-i,h=-1,d=t&&t.length||0,u=0;u<d;){if(t.charCodeAt(u)===37&&u+1<d){switch(h=h>-1?h:0,t.charCodeAt(u+1)){case 100:case 102:if(l>=c||e[l]==null)break;h<u&&(f+=t.slice(h,u)),f+=Number(e[l]),h=u+2,u++;break;case 105:if(l>=c||e[l]==null)break;h<u&&(f+=t.slice(h,u)),f+=Math.floor(Number(e[l])),h=u+2,u++;break;case 79:case 111:case 106:if(l>=c||e[l]===void 0)break;h<u&&(f+=t.slice(h,u));var b=typeof e[l];if(b==="string"){f+="'"+e[l]+"'",h=u+2,u++;break}if(b==="function"){f+=e[l].name||"<anonymous>",h=u+2,u++;break}f+=r(e[l]),h=u+2,u++;break;case 115:if(l>=c)break;h<u&&(f+=t.slice(h,u)),f+=String(e[l]),h=u+2,u++;break;case 37:h<u&&(f+=t.slice(h,u)),f+="%",h=u+2,u++,l--;break}++l}++u}return h===-1?t:(h<d&&(f+=t.slice(h)),f)}const l1=jv;xu.exports=tr;const Ro=r6().console||{},zv={mapHttpRequest:ic,mapHttpResponse:ic,wrapRequestSerializer:$u,wrapResponseSerializer:$u,wrapErrorSerializer:$u,req:ic,res:ic,err:d1,errWithCause:d1};function kr(t,e){return t==="silent"?1/0:e.levels.values[t]}const _u=Symbol("pino.logFuncs"),Su=Symbol("pino.hierarchy"),Hv={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function h1(t,e){const n={logger:e,parent:t[Su]};e[Su]=n}function Vv(t,e,n){const r={};e.forEach(i=>{r[i]=n[i]?n[i]:Ro[i]||Ro[Hv[i]||"log"]||Cs}),t[_u]=r}function Kv(t,e){return Array.isArray(t)?t.filter(function(n){return n!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function tr(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 n=t.browser.write||Ro;t.browser.write&&(t.browser.asObject=!0);const r=t.serializers||{},i=Kv(t.browser.serialize,r);let s=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(s=!1);const o=Object.keys(t.customLevels||{}),a=["error","fatal","warn","info","debug","trace"].concat(o);typeof n=="function"&&a.forEach(function(w){n[w]=n}),(t.enabled===!1||t.browser.disabled)&&(t.level="silent");const c=t.level||"info",f=Object.create(n);f.log||(f.log=Cs),Vv(f,a,n),h1({},f),Object.defineProperty(f,"levelVal",{get:h}),Object.defineProperty(f,"level",{get:d,set:u});const l={transmit:e,serialize:i,asObject:t.browser.asObject,asObjectBindingsOnly:t.browser.asObjectBindingsOnly,formatters:t.browser.formatters,levels:a,timestamp:e6(t),messageKey:t.messageKey||"msg",onChild:t.onChild||Cs};f.levels=Gv(t),f.level=c,f.isLevelEnabled=function(w){return this.levels.values[w]?this.levels.values[w]>=this.levels.values[this.level]:!1},f.setMaxListeners=f.getMaxListeners=f.emit=f.addListener=f.on=f.prependListener=f.once=f.prependOnceListener=f.removeListener=f.removeAllListeners=f.listeners=f.listenerCount=f.eventNames=f.write=f.flush=Cs,f.serializers=r,f._serialize=i,f._stdErrSerialize=s,f.child=function(...w){return b.call(this,l,...w)},e&&(f._logEvent=Bu());function h(){return kr(this.level,this)}function d(){return this._level}function u(w){if(w!=="silent"&&!this.levels.values[w])throw Error("unknown level "+w);this._level=w,Wi(this,l,f,"error"),Wi(this,l,f,"fatal"),Wi(this,l,f,"warn"),Wi(this,l,f,"info"),Wi(this,l,f,"debug"),Wi(this,l,f,"trace"),o.forEach(E=>{Wi(this,l,f,E)})}function b(w,E,A){if(!E)throw new Error("missing bindings for child Pino");A=A||{},i&&E.serializers&&(A.serializers=E.serializers);const P=A.serializers;if(i&&P){var _=Object.assign({},r,P),x=t.browser.serialize===!0?Object.keys(_):i;delete E.serializers,Iu([E],x,_,this._stdErrSerialize)}function D(C){this._childLevel=(C._childLevel|0)+1,this.bindings=E,_&&(this.serializers=_,this._serialize=x),e&&(this._logEvent=Bu([].concat(C._logEvent.bindings,E)))}D.prototype=this;const U=new D(this);return h1(this,U),U.child=function(...C){return b.call(this,w,...C)},U.level=A.level||this.level,w.onChild(U),U}return f}function Gv(t){const e=t.customLevels||{},n=Object.assign({},tr.levels.values,e),r=Object.assign({},tr.levels.labels,Zv(e));return{values:n,labels:r}}function Zv(t){const e={};return Object.keys(t).forEach(function(n){e[t[n]]=n}),e}tr.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"}},tr.stdSerializers=zv,tr.stdTimeFunctions=Object.assign({},{nullTime:p1,epochTime:g1,unixTime:t6,isoTime:n6});function Wv(t){const e=[];t.bindings&&e.push(t.bindings);let n=t[Su];for(;n.parent;)n=n.parent,n.logger.bindings&&e.push(n.logger.bindings);return e.reverse()}function Wi(t,e,n,r){if(Object.defineProperty(t,r,{value:kr(t.level,n)>kr(r,n)?Cs:n[_u][r],writable:!0,enumerable:!0,configurable:!0}),t[r]===Cs){if(!e.transmit)return;const s=e.transmit.level||t.level,o=kr(s,n);if(kr(r,n)<o)return}t[r]=Xv(t,e,n,r);const i=Wv(t);i.length!==0&&(t[r]=Yv(i,t[r]))}function Yv(t,e){return function(){return e.apply(this,[...t,...arguments])}}function Xv(t,e,n,r){return function(i){return function(){const s=e.timestamp(),o=new Array(arguments.length),a=Object.getPrototypeOf&&Object.getPrototypeOf(this)===Ro?Ro:this;for(var c=0;c<o.length;c++)o[c]=arguments[c];var f=!1;if(e.serialize&&(Iu(o,this._serialize,this.serializers,this._stdErrSerialize),f=!0),e.asObject||e.formatters?i.call(a,...Jv(this,r,o,s,e)):i.apply(a,o),e.transmit){const l=e.transmit.level||t._level,h=kr(l,n),d=kr(r,n);if(d<h)return;Qv(this,{ts:s,methodLevel:r,methodValue:d,transmitLevel:l,transmitValue:n.levels.values[e.transmit.level||t._level],send:e.transmit.send,val:kr(t._level,n)},o,f)}}}(t[_u][r])}function Jv(t,e,n,r,i){const{level:s,log:o=h=>h}=i.formatters||{},a=n.slice();let c=a[0];const f={};let l=(t._childLevel|0)+1;if(l<1&&(l=1),r&&(f.time=r),s){const h=s(e,t.levels.values[e]);Object.assign(f,h)}else f.level=t.levels.values[e];if(i.asObjectBindingsOnly){if(c!==null&&typeof c=="object")for(;l--&&typeof a[0]=="object";)Object.assign(f,a.shift());return[o(f),...a]}else{if(c!==null&&typeof c=="object"){for(;l--&&typeof a[0]=="object";)Object.assign(f,a.shift());c=a.length?l1(a.shift(),a):void 0}else typeof c=="string"&&(c=l1(a.shift(),a));return c!==void 0&&(f[i.messageKey]=c),[o(f)]}}function Iu(t,e,n,r){for(const i in t)if(r&&t[i]instanceof Error)t[i]=tr.stdSerializers.err(t[i]);else if(typeof t[i]=="object"&&!Array.isArray(t[i])&&e)for(const s in t[i])e.indexOf(s)>-1&&s in n&&(t[i][s]=n[s](t[i][s]))}function Qv(t,e,n,r=!1){const i=e.send,s=e.ts,o=e.methodLevel,a=e.methodValue,c=e.val,f=t._logEvent.bindings;r||Iu(n,t._serialize||Object.keys(t.serializers),t.serializers,t._stdErrSerialize===void 0?!0:t._stdErrSerialize),t._logEvent.ts=s,t._logEvent.messages=n.filter(function(l){return f.indexOf(l)===-1}),t._logEvent.level.label=o,t._logEvent.level.value=a,i(o,t._logEvent,c),t._logEvent=Bu(f)}function Bu(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function d1(t){const e={type:t.constructor.name,msg:t.message,stack:t.stack};for(const n in t)e[n]===void 0&&(e[n]=t[n]);return e}function e6(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?p1:g1}function ic(){return{}}function $u(t){return t}function Cs(){}function p1(){return!1}function g1(){return Date.now()}function t6(){return Math.round(Date.now()/1e3)}function n6(){return new Date(Date.now()).toISOString()}function r6(){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)||{}}}xu.exports.default=tr;var b1=xu.exports.pino=tr;const i6={level:"info"};var s6=Object.defineProperty,o6=Object.defineProperties,a6=Object.getOwnPropertyDescriptors,y1=Object.getOwnPropertySymbols,c6=Object.prototype.hasOwnProperty,f6=Object.prototype.propertyIsEnumerable,w1=(t,e,n)=>e in t?s6(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,u6=(t,e)=>{for(var n in e||(e={}))c6.call(e,n)&&w1(t,n,e[n]);if(y1)for(var n of y1(e))f6.call(e,n)&&w1(t,n,e[n]);return t},l6=(t,e)=>o6(t,a6(e));function m1(t){return l6(u6({},t),{level:t?.level||i6.level})}var v1=function(t,e,n){if(n||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return t.concat(s||Array.prototype.slice.call(e))},h6=function(){function t(e,n,r){this.name=e,this.version=n,this.os=r,this.type="browser"}return t}(),d6=function(){function t(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return t}(),p6=function(){function t(e,n,r,i){this.name=e,this.version=n,this.os=r,this.bot=i,this.type="bot-device"}return t}(),g6=function(){function t(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return t}(),b6=function(){function t(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return t}(),y6=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,w6=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,E1=3,m6=[["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",y6]],x1=[["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 v6(t){return t?_1(t):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new b6:typeof navigator<"u"?_1(navigator.userAgent):_6()}function E6(t){return t!==""&&m6.reduce(function(e,n){var r=n[0],i=n[1];if(e)return e;var s=i.exec(t);return!!s&&[r,s]},!1)}function _1(t){var e=E6(t);if(!e)return null;var n=e[0],r=e[1];if(n==="searchbot")return new g6;var i=r[1]&&r[1].split(".").join("_").split("_").slice(0,3);i?i.length<E1&&(i=v1(v1([],i,!0),S6(E1-i.length),!0)):i=[];var s=i.join("."),o=x6(t),a=w6.exec(t);return a&&a[1]?new p6(n,s,o,a[1]):new h6(n,s,o)}function x6(t){for(var e=0,n=x1.length;e<n;e++){var r=x1[e],i=r[0],s=r[1],o=s.exec(t);if(o)return i}return null}function _6(){var t=typeof process<"u"&&process.version;return t?new d6(process.version.slice(1)):null}function S6(t){for(var e=[],n=0;n<t;n++)e.push("0");return e}var Z={};/*! *****************************************************************************
2
2
  Copyright (c) Microsoft Corporation.
3
3
 
4
4
  Permission to use, copy, modify, and/or distribute this software for any
@@ -11,20 +11,22 @@
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 Da=function(t,e){return Da=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var i in r)r.hasOwnProperty(i)&&(n[i]=r[i])},Da(t,e)};function sb(t,e){Da(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var $a=function(){return $a=Object.assign||function(e){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},$a.apply(this,arguments)};function ob(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n}function ab(t,e,n,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,n):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function cb(t,e){return function(n,r){e(n,r,t)}}function ub(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function lb(t,e,n,r){function i(s){return s instanceof n?s:new n(function(o){o(s)})}return new(n||(n=Promise))(function(s,o){function a(l){try{u(r.next(l))}catch(f){o(f)}}function c(l){try{u(r.throw(l))}catch(f){o(f)}}function u(l){l.done?s(l.value):i(l.value).then(a,c)}u((r=r.apply(t,e||[])).next())})}function fb(t,e){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,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(r)throw new TypeError("Generator is already executing.");for(;n;)try{if(r=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 n.label++,{value:u[1],done:!1};case 5:n.label++,i=u[1],u=[0];continue;case 7:u=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(u[0]===6||u[0]===2)){n=0;continue}if(u[0]===3&&(!s||u[1]>s[0]&&u[1]<s[3])){n.label=u[1];break}if(u[0]===6&&n.label<s[1]){n.label=s[1],s=u;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(u);break}s[2]&&n.ops.pop(),n.trys.pop();continue}u=e.call(t,n)}catch(l){u=[6,l],i=0}finally{r=s=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function hb(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]}function db(t,e){for(var n in t)n!=="default"&&!e.hasOwnProperty(n)&&(e[n]=t[n])}function Pa(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function af(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function pb(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(af(arguments[e]));return t}function gb(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),i=0,e=0;e<n;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,i++)r[i]=s[o];return r}function Ci(t){return this instanceof Ci?(this.v=t,this):new Ci(t)}function yb(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(t,e||[]),i,s=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(d){r[d]&&(i[d]=function(h){return new Promise(function(p,g){s.push([d,h,p,g])>1||a(d,h)})})}function a(d,h){try{c(r[d](h))}catch(p){f(s[0][3],p)}}function c(d){d.value instanceof Ci?Promise.resolve(d.value.v).then(u,l):f(s[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function f(d,h){d(h),s.shift(),s.length&&a(s[0][0],s[0][1])}}function bb(t){var e,n;return e={},r("next"),r("throw",function(i){throw i}),r("return"),e[Symbol.iterator]=function(){return this},e;function r(i,s){e[i]=t[i]?function(o){return(n=!n)?{value:Ci(t[i](o)),done:i==="return"}:s?s(o):o}:s}}function wb(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof Pa=="function"?Pa(t):t[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[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 mb(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function vb(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function Eb(t){return t&&t.__esModule?t:{default:t}}function xb(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function _b(t,e,n){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,n),n}var Sb=Object.freeze({__proto__:null,__extends:sb,get __assign(){return $a},__rest:ob,__decorate:ab,__param:cb,__metadata:ub,__awaiter:lb,__generator:fb,__createBinding:hb,__exportStar:db,__values:Pa,__read:af,__spread:pb,__spreadArrays:gb,__await:Ci,__asyncGenerator:yb,__asyncDelegator:bb,__asyncValues:wb,__makeTemplateObject:mb,__importStar:vb,__importDefault:Eb,__classPrivateFieldGet:xb,__classPrivateFieldSet:_b}),qs=Wl(Sb),Ta={},Ui={},cf;function Ib(){if(cf)return Ui;cf=1,Object.defineProperty(Ui,"__esModule",{value:!0}),Ui.delay=void 0;function t(e){return new Promise(n=>{setTimeout(()=>{n(!0)},e)})}return Ui.delay=t,Ui}var xr={},Ra={},_r={},uf;function Ab(){return uf||(uf=1,Object.defineProperty(_r,"__esModule",{value:!0}),_r.ONE_THOUSAND=_r.ONE_HUNDRED=void 0,_r.ONE_HUNDRED=100,_r.ONE_THOUSAND=1e3),_r}var Na={},lf;function Bb(){return lf||(lf=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}(Na)),Na}var ff;function hf(){return ff||(ff=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=qs;e.__exportStar(Ab(),t),e.__exportStar(Bb(),t)}(Ra)),Ra}var df;function Ob(){if(df)return xr;df=1,Object.defineProperty(xr,"__esModule",{value:!0}),xr.fromMiliseconds=xr.toMiliseconds=void 0;const t=hf();function e(r){return r*t.ONE_THOUSAND}xr.toMiliseconds=e;function n(r){return Math.floor(r/t.ONE_THOUSAND)}return xr.fromMiliseconds=n,xr}var pf;function Db(){return pf||(pf=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=qs;e.__exportStar(Ib(),t),e.__exportStar(Ob(),t)}(Ta)),Ta}var ti={},gf;function $b(){if(gf)return ti;gf=1,Object.defineProperty(ti,"__esModule",{value:!0}),ti.Watch=void 0;class t{constructor(){this.timestamps=new Map}start(n){if(this.timestamps.has(n))throw new Error(`Watch already started for label: ${n}`);this.timestamps.set(n,{started:Date.now()})}stop(n){const r=this.get(n);if(typeof r.elapsed<"u")throw new Error(`Watch already stopped for label: ${n}`);const i=Date.now()-r.started;this.timestamps.set(n,{started:r.started,elapsed:i})}get(n){const r=this.timestamps.get(n);if(typeof r>"u")throw new Error(`No timestamp found for label: ${n}`);return r}elapsed(n){const r=this.get(n);return r.elapsed||Date.now()-r.started}}return ti.Watch=t,ti.default=t,ti}var Ca={},Fi={},yf;function Pb(){if(yf)return Fi;yf=1,Object.defineProperty(Fi,"__esModule",{value:!0}),Fi.IWatch=void 0;class t{}return Fi.IWatch=t,Fi}var bf;function Tb(){return bf||(bf=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),qs.__exportStar(Pb(),t)}(Ca)),Ca}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=qs;e.__exportStar(Db(),t),e.__exportStar($b(),t),e.__exportStar(Tb(),t),e.__exportStar(hf(),t)})(K);class Sr{}class Rb extends Sr{constructor(e){super()}}const wf=K.FIVE_SECONDS,Ir={pulse:"heartbeat_pulse"};class Ua extends Rb{constructor(e){super(e),this.events=new Ve.exports.EventEmitter,this.interval=wf,this.interval=e?.interval||wf}static async init(e){const n=new Ua(e);return await n.init(),n}async init(){await this.initialize()}stop(){clearInterval(this.intervalRef)}on(e,n){this.events.on(e,n)}once(e,n){this.events.once(e,n)}off(e,n){this.events.off(e,n)}removeListener(e,n){this.events.removeListener(e,n)}async initialize(){this.intervalRef=setInterval(()=>this.pulse(),K.toMiliseconds(this.interval))}pulse(){this.events.emit(Ir.pulse)}}const Nb=/"(?:_|\\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*:/,Cb=/"(?: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*:/,Ub=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function Fb(t,e){if(t==="__proto__"||t==="constructor"&&e&&typeof e=="object"&&"prototype"in e){Lb(t);return}return e}function Lb(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}function Ms(t,e={}){if(typeof t!="string")return t;const n=t.trim();if(t[0]==='"'&&t.endsWith('"')&&!t.includes("\\"))return n.slice(1,-1);if(n.length<=9){const r=n.toLowerCase();if(r==="true")return!0;if(r==="false")return!1;if(r==="undefined")return;if(r==="null")return null;if(r==="nan")return Number.NaN;if(r==="infinity")return Number.POSITIVE_INFINITY;if(r==="-infinity")return Number.NEGATIVE_INFINITY}if(!Ub.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(Nb.test(t)||Cb.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,Fb)}return JSON.parse(t)}catch(r){if(e.strict)throw r;return t}}function kb(t){return!t||typeof t.then!="function"?Promise.resolve(t):t}function Te(t,...e){try{return kb(t(...e))}catch(n){return Promise.reject(n)}}function qb(t){const e=typeof t;return t===null||e!=="object"&&e!=="function"}function Mb(t){const e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}function js(t){if(qb(t))return String(t);if(Mb(t)||Array.isArray(t))return JSON.stringify(t);if(typeof t.toJSON=="function")return js(t.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function mf(){if(typeof Buffer>"u")throw new TypeError("[unstorage] Buffer is not supported!")}const Fa="base64:";function jb(t){if(typeof t=="string")return t;mf();const e=Buffer.from(t).toString("base64");return Fa+e}function zb(t){return typeof t!="string"||!t.startsWith(Fa)?t:(mf(),Buffer.from(t.slice(Fa.length),"base64"))}function lt(t){return t?t.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function Hb(...t){return lt(t.join(":"))}function zs(t){return t=lt(t),t?t+":":""}function i$(t){return t}const Vb="memory",Kb=()=>{const t=new Map;return{name:Vb,getInstance:()=>t,hasItem(e){return t.has(e)},getItem(e){return t.get(e)??null},getItemRaw(e){return t.get(e)??null},setItem(e,n){t.set(e,n)},setItemRaw(e,n){t.set(e,n)},removeItem(e){t.delete(e)},getKeys(){return[...t.keys()]},clear(){t.clear()},dispose(){t.clear()}}};function Gb(t={}){const e={mounts:{"":t.driver||Kb()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},n=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[""]}},r=(u,l)=>e.mountpoints.filter(f=>f.startsWith(u)||l&&u.startsWith(f)).map(f=>({relativeBase:u.length>f.length?u.slice(f.length):void 0,mountpoint:f,driver:e.mounts[f]})),i=(u,l)=>{if(e.watching){l=lt(l);for(const f of e.watchListeners)f(u,l)}},s=async()=>{if(!e.watching){e.watching=!0;for(const u in e.mounts)e.unwatch[u]=await vf(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,f)=>{const d=new Map,h=p=>{let g=d.get(p.base);return g||(g={driver:p.driver,base:p.base,items:[]},d.set(p.base,g)),g};for(const p of u){const g=typeof p=="string",v=lt(g?p:p.key),B=g?void 0:p.value,D=g||!p.options?l:{...l,...p.options},_=n(v);h(_).items.push({key:v,value:B,relativeKey:_.relativeKey,options:D})}return Promise.all([...d.values()].map(p=>f(p))).then(p=>p.flat())},c={hasItem(u,l={}){u=lt(u);const{relativeKey:f,driver:d}=n(u);return Te(d.hasItem,f,l)},getItem(u,l={}){u=lt(u);const{relativeKey:f,driver:d}=n(u);return Te(d.getItem,f,l).then(h=>Ms(h))},getItems(u,l){return a(u,l,f=>f.driver.getItems?Te(f.driver.getItems,f.items.map(d=>({key:d.relativeKey,options:d.options})),l).then(d=>d.map(h=>({key:Hb(f.base,h.key),value:Ms(h.value)}))):Promise.all(f.items.map(d=>Te(f.driver.getItem,d.relativeKey,d.options).then(h=>({key:d.key,value:Ms(h)})))))},getItemRaw(u,l={}){u=lt(u);const{relativeKey:f,driver:d}=n(u);return d.getItemRaw?Te(d.getItemRaw,f,l):Te(d.getItem,f,l).then(h=>zb(h))},async setItem(u,l,f={}){if(l===void 0)return c.removeItem(u);u=lt(u);const{relativeKey:d,driver:h}=n(u);h.setItem&&(await Te(h.setItem,d,js(l),f),h.watch||i("update",u))},async setItems(u,l){await a(u,l,async f=>{if(f.driver.setItems)return Te(f.driver.setItems,f.items.map(d=>({key:d.relativeKey,value:js(d.value),options:d.options})),l);f.driver.setItem&&await Promise.all(f.items.map(d=>Te(f.driver.setItem,d.relativeKey,js(d.value),d.options)))})},async setItemRaw(u,l,f={}){if(l===void 0)return c.removeItem(u,f);u=lt(u);const{relativeKey:d,driver:h}=n(u);if(h.setItemRaw)await Te(h.setItemRaw,d,l,f);else if(h.setItem)await Te(h.setItem,d,jb(l),f);else return;h.watch||i("update",u)},async removeItem(u,l={}){typeof l=="boolean"&&(l={removeMeta:l}),u=lt(u);const{relativeKey:f,driver:d}=n(u);d.removeItem&&(await Te(d.removeItem,f,l),(l.removeMeta||l.removeMata)&&await Te(d.removeItem,f+"$",l),d.watch||i("remove",u))},async getMeta(u,l={}){typeof l=="boolean"&&(l={nativeOnly:l}),u=lt(u);const{relativeKey:f,driver:d}=n(u),h=Object.create(null);if(d.getMeta&&Object.assign(h,await Te(d.getMeta,f,l)),!l.nativeOnly){const p=await Te(d.getItem,f+"$",l).then(g=>Ms(g));p&&typeof p=="object"&&(typeof p.atime=="string"&&(p.atime=new Date(p.atime)),typeof p.mtime=="string"&&(p.mtime=new Date(p.mtime)),Object.assign(h,p))}return h},setMeta(u,l,f={}){return this.setItem(u+"$",l,f)},removeMeta(u,l={}){return this.removeItem(u+"$",l)},async getKeys(u,l={}){u=zs(u);const f=r(u,!0);let d=[];const h=[];for(const p of f){const g=await Te(p.driver.getKeys,p.relativeBase,l);for(const v of g){const B=p.mountpoint+lt(v);d.some(D=>B.startsWith(D))||h.push(B)}d=[p.mountpoint,...d.filter(v=>!v.startsWith(p.mountpoint))]}return u?h.filter(p=>p.startsWith(u)&&p[p.length-1]!=="$"):h.filter(p=>p[p.length-1]!=="$")},async clear(u,l={}){u=zs(u),await Promise.all(r(u,!1).map(async f=>{if(f.driver.clear)return Te(f.driver.clear,f.relativeBase,l);if(f.driver.removeItem){const d=await f.driver.getKeys(f.relativeBase||"",l);return Promise.all(d.map(h=>f.driver.removeItem(h,l)))}}))},async dispose(){await Promise.all(Object.values(e.mounts).map(u=>Ef(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=zs(u),u&&e.mounts[u])throw new Error(`already mounted at ${u}`);return u&&(e.mountpoints.push(u),e.mountpoints.sort((f,d)=>d.length-f.length)),e.mounts[u]=l,e.watching&&Promise.resolve(vf(l,i,u)).then(f=>{e.unwatch[u]=f}).catch(console.error),c},async unmount(u,l=!0){u=zs(u),!(!u||!e.mounts[u])&&(e.watching&&u in e.unwatch&&(e.unwatch[u](),delete e.unwatch[u]),l&&await Ef(e.mounts[u]),e.mountpoints=e.mountpoints.filter(f=>f!==u),delete e.mounts[u])},getMount(u=""){u=lt(u)+":";const l=n(u);return{driver:l.driver,base:l.base}},getMounts(u="",l={}){return u=lt(u),r(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,f={})=>c.setItem(u,l,f),has:(u,l={})=>c.hasItem(u,l),del:(u,l={})=>c.removeItem(u,l),remove:(u,l={})=>c.removeItem(u,l)};return c}function vf(t,e,n){return t.watch?t.watch((r,i)=>e(r,n+i)):()=>{}}async function Ef(t){typeof t.dispose=="function"&&await Te(t.dispose)}function Ar(t){return new Promise((e,n)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>n(t.error)})}function xf(t,e){const n=indexedDB.open(t);n.onupgradeneeded=()=>n.result.createObjectStore(e);const r=Ar(n);return(i,s)=>r.then(o=>s(o.transaction(e,i).objectStore(e)))}let La;function Li(){return La||(La=xf("keyval-store","keyval")),La}function _f(t,e=Li()){return e("readonly",n=>Ar(n.get(t)))}function Wb(t,e,n=Li()){return n("readwrite",r=>(r.put(e,t),Ar(r.transaction)))}function Zb(t,e=Li()){return e("readwrite",n=>(n.delete(t),Ar(n.transaction)))}function Yb(t=Li()){return t("readwrite",e=>(e.clear(),Ar(e.transaction)))}function Xb(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},Ar(t.transaction)}function Jb(t=Li()){return t("readonly",e=>{if(e.getAllKeys)return Ar(e.getAllKeys());const n=[];return Xb(e,r=>n.push(r.key)).then(()=>n)})}const Qb=t=>JSON.stringify(t,(e,n)=>typeof n=="bigint"?n.toString()+"n":n),ew=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,n=t.replace(e,'$1"$2n"$3');return JSON.parse(n,(r,i)=>typeof i=="string"&&i.match(/^\d+n$/)?BigInt(i.substring(0,i.length-1)):i)};function ni(t){if(typeof t!="string")throw new Error(`Cannot safe json parse value of type ${typeof t}`);try{return ew(t)}catch{return t}}function Br(t){return typeof t=="string"?t:Qb(t)||""}const tw="idb-keyval";var nw=(t={})=>{const e=t.base&&t.base.length>0?`${t.base}:`:"",n=i=>e+i;let r;return t.dbName&&t.storeName&&(r=xf(t.dbName,t.storeName)),{name:tw,options:t,async hasItem(i){return!(typeof await _f(n(i),r)>"u")},async getItem(i){return await _f(n(i),r)??null},setItem(i,s){return Wb(n(i),s,r)},removeItem(i){return Zb(n(i),r)},getKeys(){return Jb(r)},clear(){return Yb(r)}}};const rw="WALLET_CONNECT_V2_INDEXED_DB",iw="keyvaluestorage";class sw{constructor(){this.indexedDb=Gb({driver:nw({dbName:rw,storeName:iw})})}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 n=await this.indexedDb.getItem(e);if(n!==null)return n}async setItem(e,n){await this.indexedDb.setItem(e,Br(n))}async removeItem(e){await this.indexedDb.removeItem(e)}}var ka=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},Hs={exports:{}};(function(){let t;function e(){}t=e,t.prototype.getItem=function(n){return this.hasOwnProperty(n)?String(this[n]):null},t.prototype.setItem=function(n,r){this[n]=String(r)},t.prototype.removeItem=function(n){delete this[n]},t.prototype.clear=function(){const n=this;Object.keys(n).forEach(function(r){n[r]=void 0,delete n[r]})},t.prototype.key=function(n){return n=n||0,Object.keys(this)[n]},t.prototype.__defineGetter__("length",function(){return Object.keys(this).length}),typeof ka<"u"&&ka.localStorage?Hs.exports=ka.localStorage:typeof window<"u"&&window.localStorage?Hs.exports=window.localStorage:Hs.exports=new e})();function ow(t){var e;return[t[0],ni((e=t[1])!=null?e:"")]}class aw{constructor(){this.localStorage=Hs.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(ow)}async getItem(e){const n=this.localStorage.getItem(e);if(n!==null)return ni(n)}async setItem(e,n){this.localStorage.setItem(e,Br(n))}async removeItem(e){this.localStorage.removeItem(e)}}const cw="wc_storage_version",Sf=1,uw=async(t,e,n)=>{const r=cw,i=await e.getItem(r);if(i&&i>=Sf){n(e);return}const s=await t.getKeys();if(!s.length){n(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(r,Sf),n(e),lw(t,o)},lw=async(t,e)=>{e.length&&e.forEach(async n=>{await t.removeItem(n)})};class fw{constructor(){this.initialized=!1,this.setInitialized=n=>{this.storage=n,this.initialized=!0};const e=new aw;this.storage=e;try{const n=new sw;uw(e,n,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,n){return await this.initialize(),this.storage.setItem(e,n)}async removeItem(e){return await this.initialize(),this.storage.removeItem(e)}async initialize(){this.initialized||await new Promise(e=>{const n=setInterval(()=>{this.initialized&&(clearInterval(n),e())},20)})}}var Qt={exports:{}};function hw(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}var dw=pw;function pw(t,e,n){var r=n&&n.stringify||hw,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]=r(t);for(var a=1;a<s;a++)o[a]=r(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,f=-1,d=t&&t.length||0,h=0;h<d;){if(t.charCodeAt(h)===37&&h+1<d){switch(f=f>-1?f:0,t.charCodeAt(h+1)){case 100:case 102:if(l>=c||e[l]==null)break;f<h&&(u+=t.slice(f,h)),u+=Number(e[l]),f=h+2,h++;break;case 105:if(l>=c||e[l]==null)break;f<h&&(u+=t.slice(f,h)),u+=Math.floor(Number(e[l])),f=h+2,h++;break;case 79:case 111:case 106:if(l>=c||e[l]===void 0)break;f<h&&(u+=t.slice(f,h));var p=typeof e[l];if(p==="string"){u+="'"+e[l]+"'",f=h+2,h++;break}if(p==="function"){u+=e[l].name||"<anonymous>",f=h+2,h++;break}u+=r(e[l]),f=h+2,h++;break;case 115:if(l>=c)break;f<h&&(u+=t.slice(f,h)),u+=String(e[l]),f=h+2,h++;break;case 37:f<h&&(u+=t.slice(f,h)),u+="%",f=h+2,h++,l--;break}++l}++h}return f===-1?t:(f<d&&(u+=t.slice(f)),u)}const If=dw;Qt.exports=dn;const ki=Dw().console||{},gw={mapHttpRequest:Vs,mapHttpResponse:Vs,wrapRequestSerializer:Ha,wrapResponseSerializer:Ha,wrapErrorSerializer:Ha,req:Vs,res:Vs,err:Bf,errWithCause:Bf};function kn(t,e){return t==="silent"?1/0:e.levels.values[t]}const qa=Symbol("pino.logFuncs"),Ma=Symbol("pino.hierarchy"),yw={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function Af(t,e){const n={logger:e,parent:t[Ma]};e[Ma]=n}function bw(t,e,n){const r={};e.forEach(i=>{r[i]=n[i]?n[i]:ki[i]||ki[yw[i]||"log"]||ri}),t[qa]=r}function ww(t,e){return Array.isArray(t)?t.filter(function(r){return r!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function dn(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 n=t.browser.write||ki;t.browser.write&&(t.browser.asObject=!0);const r=t.serializers||{},i=ww(t.browser.serialize,r);let s=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(s=!1);const o=Object.keys(t.customLevels||{}),a=["error","fatal","warn","info","debug","trace"].concat(o);typeof n=="function"&&a.forEach(function(g){n[g]=n}),(t.enabled===!1||t.browser.disabled)&&(t.level="silent");const c=t.level||"info",u=Object.create(n);u.log||(u.log=ri),bw(u,a,n),Af({},u),Object.defineProperty(u,"levelVal",{get:f}),Object.defineProperty(u,"level",{get:d,set:h});const l={transmit:e,serialize:i,asObject:t.browser.asObject,asObjectBindingsOnly:t.browser.asObjectBindingsOnly,formatters:t.browser.formatters,levels:a,timestamp:Aw(t),messageKey:t.messageKey||"msg",onChild:t.onChild||ri};u.levels=mw(t),u.level=c,u.isLevelEnabled=function(g){return this.levels.values[g]?this.levels.values[g]>=this.levels.values[this.level]:!1},u.setMaxListeners=u.getMaxListeners=u.emit=u.addListener=u.on=u.prependListener=u.once=u.prependOnceListener=u.removeListener=u.removeAllListeners=u.listeners=u.listenerCount=u.eventNames=u.write=u.flush=ri,u.serializers=r,u._serialize=i,u._stdErrSerialize=s,u.child=function(...g){return p.call(this,l,...g)},e&&(u._logEvent=za());function f(){return kn(this.level,this)}function d(){return this._level}function h(g){if(g!=="silent"&&!this.levels.values[g])throw Error("unknown level "+g);this._level=g,Or(this,l,u,"error"),Or(this,l,u,"fatal"),Or(this,l,u,"warn"),Or(this,l,u,"info"),Or(this,l,u,"debug"),Or(this,l,u,"trace"),o.forEach(v=>{Or(this,l,u,v)})}function p(g,v,B){if(!v)throw new Error("missing bindings for child Pino");B=B||{},i&&v.serializers&&(B.serializers=v.serializers);const D=B.serializers;if(i&&D){var _=Object.assign({},r,D),x=t.browser.serialize===!0?Object.keys(_):i;delete v.serializers,ja([v],x,_,this._stdErrSerialize)}function $(U){this._childLevel=(U._childLevel|0)+1,this.bindings=v,_&&(this.serializers=_,this._serialize=x),e&&(this._logEvent=za([].concat(U._logEvent.bindings,v)))}$.prototype=this;const T=new $(this);return Af(this,T),T.child=function(...U){return p.call(this,g,...U)},T.level=B.level||this.level,g.onChild(T),T}return u}function mw(t){const e=t.customLevels||{},n=Object.assign({},dn.levels.values,e),r=Object.assign({},dn.levels.labels,vw(e));return{values:n,labels:r}}function vw(t){const e={};return Object.keys(t).forEach(function(n){e[t[n]]=n}),e}dn.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"}},dn.stdSerializers=gw,dn.stdTimeFunctions=Object.assign({},{nullTime:Of,epochTime:Df,unixTime:Bw,isoTime:Ow});function Ew(t){const e=[];t.bindings&&e.push(t.bindings);let n=t[Ma];for(;n.parent;)n=n.parent,n.logger.bindings&&e.push(n.logger.bindings);return e.reverse()}function Or(t,e,n,r){if(Object.defineProperty(t,r,{value:kn(t.level,n)>kn(r,n)?ri:n[qa][r],writable:!0,enumerable:!0,configurable:!0}),t[r]===ri){if(!e.transmit)return;const s=e.transmit.level||t.level,o=kn(s,n);if(kn(r,n)<o)return}t[r]=_w(t,e,n,r);const i=Ew(t);i.length!==0&&(t[r]=xw(i,t[r]))}function xw(t,e){return function(){return e.apply(this,[...t,...arguments])}}function _w(t,e,n,r){return function(i){return function(){const o=e.timestamp(),a=new Array(arguments.length),c=Object.getPrototypeOf&&Object.getPrototypeOf(this)===ki?ki:this;for(var u=0;u<a.length;u++)a[u]=arguments[u];var l=!1;if(e.serialize&&(ja(a,this._serialize,this.serializers,this._stdErrSerialize),l=!0),e.asObject||e.formatters?i.call(c,...Sw(this,r,a,o,e)):i.apply(c,a),e.transmit){const f=e.transmit.level||t._level,d=kn(f,n),h=kn(r,n);if(h<d)return;Iw(this,{ts:o,methodLevel:r,methodValue:h,transmitLevel:f,transmitValue:n.levels.values[e.transmit.level||t._level],send:e.transmit.send,val:kn(t._level,n)},a,l)}}}(t[qa][r])}function Sw(t,e,n,r,i){const{level:s,log:o=f=>f}=i.formatters||{},a=n.slice();let c=a[0];const u={};let l=(t._childLevel|0)+1;if(l<1&&(l=1),r&&(u.time=r),s){const f=s(e,t.levels.values[e]);Object.assign(u,f)}else u.level=t.levels.values[e];if(i.asObjectBindingsOnly){if(c!==null&&typeof c=="object")for(;l--&&typeof a[0]=="object";)Object.assign(u,a.shift());return[o(u),...a]}else{if(c!==null&&typeof c=="object"){for(;l--&&typeof a[0]=="object";)Object.assign(u,a.shift());c=a.length?If(a.shift(),a):void 0}else typeof c=="string"&&(c=If(a.shift(),a));return c!==void 0&&(u[i.messageKey]=c),[o(u)]}}function ja(t,e,n,r){for(const i in t)if(r&&t[i]instanceof Error)t[i]=dn.stdSerializers.err(t[i]);else if(typeof t[i]=="object"&&!Array.isArray(t[i])&&e)for(const s in t[i])e.indexOf(s)>-1&&s in n&&(t[i][s]=n[s](t[i][s]))}function Iw(t,e,n,r=!1){const i=e.send,s=e.ts,o=e.methodLevel,a=e.methodValue,c=e.val,u=t._logEvent.bindings;r||ja(n,t._serialize||Object.keys(t.serializers),t.serializers,t._stdErrSerialize===void 0?!0:t._stdErrSerialize),t._logEvent.ts=s,t._logEvent.messages=n.filter(function(l){return u.indexOf(l)===-1}),t._logEvent.level.label=o,t._logEvent.level.value=a,i(o,t._logEvent,c),t._logEvent=za(u)}function za(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function Bf(t){const e={type:t.constructor.name,msg:t.message,stack:t.stack};for(const n in t)e[n]===void 0&&(e[n]=t[n]);return e}function Aw(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?Of:Df}function Vs(){return{}}function Ha(t){return t}function ri(){}function Of(){return!1}function Df(){return Date.now()}function Bw(){return Math.round(Date.now()/1e3)}function Ow(){return new Date(Date.now()).toISOString()}function Dw(){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)||{}}}Qt.exports.default=dn,Qt.exports.pino=dn;const $w={level:"info"},Ks="custom_context",Va=1e3*1024;var Pw=Object.defineProperty,Tw=(t,e,n)=>e in t?Pw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,qn=(t,e,n)=>Tw(t,typeof e!="symbol"?e+"":e,n);class Rw{constructor(e){qn(this,"nodeValue"),qn(this,"sizeInBytes"),qn(this,"next"),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 $f{constructor(e){qn(this,"lengthInNodes"),qn(this,"sizeInBytes"),qn(this,"head"),qn(this,"tail"),qn(this,"maxSizeInBytes"),this.head=null,this.tail=null,this.lengthInNodes=0,this.maxSizeInBytes=e,this.sizeInBytes=0}append(e){const n=new Rw(e);if(n.size>this.maxSizeInBytes)throw new Error(`[LinkedList] Value too big to insert into list: ${e} with size ${n.size}`);for(;this.size+n.size>this.maxSizeInBytes;)this.shift();this.head?(this.tail&&(this.tail.next=n),this.tail=n):(this.head=n,this.tail=n),this.lengthInNodes++,this.sizeInBytes+=n.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 n=this.head;for(;n!==null;)e.push(n.value),n=n.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 n=e.value;return e=e.next,{done:!1,value:n}}}}}var Nw=Object.defineProperty,Cw=(t,e,n)=>e in t?Nw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Gs=(t,e,n)=>Cw(t,typeof e!="symbol"?e+"":e,n);class Pf{constructor(e,n=Va){Gs(this,"logs"),Gs(this,"level"),Gs(this,"levelValue"),Gs(this,"MAX_LOG_SIZE_IN_BYTES"),this.level=e??"error",this.levelValue=Qt.exports.levels.values[this.level],this.MAX_LOG_SIZE_IN_BYTES=n,this.logs=new $f(this.MAX_LOG_SIZE_IN_BYTES)}forwardToConsole(e,n){n===Qt.exports.levels.values.error?console.error(e):n===Qt.exports.levels.values.warn?console.warn(e):n===Qt.exports.levels.values.debug?console.debug(e):n===Qt.exports.levels.values.trace?console.trace(e):console.log(e)}appendToLogs(e){this.logs.append(Br({timestamp:new Date().toISOString(),log:e}));const n=typeof e=="string"?JSON.parse(e).level:e.level;n>=this.levelValue&&this.forwardToConsole(e,n)}getLogs(){return this.logs}clearLogs(){this.logs=new $f(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(e){const n=this.getLogArray();return n.push(Br({extraMetadata:e})),new Blob(n,{type:"application/json"})}}var Uw=Object.defineProperty,Fw=(t,e,n)=>e in t?Uw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Lw=(t,e,n)=>Fw(t,typeof e!="symbol"?e+"":e,n);class kw{constructor(e,n=Va){Lw(this,"baseChunkLogger"),this.baseChunkLogger=new Pf(e,n)}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 n=URL.createObjectURL(this.logsToBlob(e)),r=document.createElement("a");r.href=n,r.download=`walletconnect-logs-${new Date().toISOString()}.txt`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}}var qw=Object.defineProperty,Mw=(t,e,n)=>e in t?qw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,jw=(t,e,n)=>Mw(t,typeof e!="symbol"?e+"":e,n);class zw{constructor(e,n=Va){jw(this,"baseChunkLogger"),this.baseChunkLogger=new Pf(e,n)}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 Hw=Object.defineProperty,Vw=Object.defineProperties,Kw=Object.getOwnPropertyDescriptors,Tf=Object.getOwnPropertySymbols,Gw=Object.prototype.hasOwnProperty,Ww=Object.prototype.propertyIsEnumerable,Rf=(t,e,n)=>e in t?Hw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ws=(t,e)=>{for(var n in e||(e={}))Gw.call(e,n)&&Rf(t,n,e[n]);if(Tf)for(var n of Tf(e))Ww.call(e,n)&&Rf(t,n,e[n]);return t},Zs=(t,e)=>Vw(t,Kw(e));function Zw(t){return Zs(Ws({},t),{level:t?.level||$w.level})}function Yw(t,e,n=Ks){return t[n]=e,t}function ft(t,e=Ks){return t[e]||""}function Xw(t,e,n=Ks){const r=ft(t,n);return r.trim()?`${r}/${e}`:e}function _t(t,e,n=Ks){const r=Xw(t,e,n),i=t.child({context:r});return Yw(i,r,n)}function Jw(t){var e,n;const r=new kw((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:Qt.exports(Zs(Ws({},t.opts),{level:"trace",browser:Zs(Ws({},(n=t.opts)==null?void 0:n.browser),{write:i=>r.write(i)})})),chunkLoggerController:r}}function Qw(t){var e;const n=new zw((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:Qt.exports(Zs(Ws({},t.opts),{level:"trace"}),n),chunkLoggerController:n}}function Nf(t){return typeof t.loggerOverride<"u"&&typeof t.loggerOverride!="string"?{logger:t.loggerOverride,chunkLoggerController:null}:typeof window<"u"?Jw(t):Qw(t)}var em=Object.defineProperty,tm=(t,e,n)=>e in t?em(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Cf=(t,e,n)=>tm(t,typeof e!="symbol"?e+"":e,n);class nm extends Sr{constructor(e){super(),this.opts=e,Cf(this,"protocol","wc"),Cf(this,"version",2)}}var rm=Object.defineProperty,im=(t,e,n)=>e in t?rm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,sm=(t,e,n)=>im(t,typeof e!="symbol"?e+"":e,n);class om extends Sr{constructor(e,n){super(),this.core=e,this.logger=n,sm(this,"records",new Map)}}class am{constructor(e,n){this.logger=e,this.core=n}}class cm extends Sr{constructor(e,n){super(),this.relayer=e,this.logger=n}}class um extends Sr{constructor(e){super()}}class lm{constructor(e,n,r,i){this.core=e,this.logger=n,this.name=r}}class fm extends Sr{constructor(e,n){super(),this.relayer=e,this.logger=n}}class hm extends Sr{constructor(e,n){super(),this.core=e,this.logger=n}}class dm{constructor(e,n,r){this.core=e,this.logger=n,this.store=r}}class pm{constructor(e,n){this.projectId=e,this.logger=n}}class gm{constructor(e,n,r){this.core=e,this.logger=n,this.telemetryEnabled=r}}var ym=Object.defineProperty,bm=(t,e,n)=>e in t?ym(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Uf=(t,e,n)=>bm(t,typeof e!="symbol"?e+"":e,n);class wm{constructor(e){this.opts=e,Uf(this,"protocol","wc"),Uf(this,"version",2)}}class mm{constructor(e){this.client=e}}function vm(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ff(t,...e){if(!vm(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 Lf(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 Em(t,e){Ff(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const ii=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Ka=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function xm(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function kf(t){return typeof t=="string"&&(t=xm(t)),Ff(t),t}class _m{clone(){return this._cloneInto()}}function Sm(t){const e=r=>t().update(kf(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function qf(t=32){if(ii&&typeof ii.getRandomValues=="function")return ii.getRandomValues(new Uint8Array(t));if(ii&&typeof ii.randomBytes=="function")return ii.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function Im(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,u=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+u,a,r)}class Am extends _m{constructor(e,n,r,i){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Ka(this.buffer)}update(e){Lf(this);const{view:n,buffer:r,blockLen:i}=this;e=kf(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=Ka(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Lf(this),Em(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let f=o;f<i;f++)n[f]=0;Im(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Ka(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 f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.length=i,e.pos=a,e.finished=s,e.destroyed=o,i%n&&e.buffer.set(r),e}}const Ys=BigInt(2**32-1),Ga=BigInt(32);function Mf(t,e=!1){return e?{h:Number(t&Ys),l:Number(t>>Ga&Ys)}:{h:Number(t>>Ga&Ys)|0,l:Number(t&Ys)|0}}function Bm(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:s,l:o}=Mf(t[i],e);[n[i],r[i]]=[s,o]}return[n,r]}const Om=(t,e)=>BigInt(t>>>0)<<Ga|BigInt(e>>>0),Dm=(t,e,n)=>t>>>n,$m=(t,e,n)=>t<<32-n|e>>>n,Pm=(t,e,n)=>t>>>n|e<<32-n,Tm=(t,e,n)=>t<<32-n|e>>>n,Rm=(t,e,n)=>t<<64-n|e>>>n-32,Nm=(t,e,n)=>t>>>n-32|e<<64-n,Cm=(t,e)=>e,Um=(t,e)=>t,Fm=(t,e,n)=>t<<n|e>>>32-n,Lm=(t,e,n)=>e<<n|t>>>32-n,km=(t,e,n)=>e<<n-32|t>>>64-n,qm=(t,e,n)=>t<<n-32|e>>>64-n;function Mm(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const jm=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),zm=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Hm=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),Vm=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,Km=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),Gm=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,ne={fromBig:Mf,split:Bm,toBig:Om,shrSH:Dm,shrSL:$m,rotrSH:Pm,rotrSL:Tm,rotrBH:Rm,rotrBL:Nm,rotr32H:Cm,rotr32L:Um,rotlSH:Fm,rotlSL:Lm,rotlBH:km,rotlBL:qm,add:Mm,add3L:jm,add3H:zm,add4L:Hm,add4H:Vm,add5H:Gm,add5L:Km},[Wm,Zm]=(()=>ne.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))))(),Mn=new Uint32Array(80),jn=new Uint32Array(80);class Ym extends Am{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:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:h,Gl:p,Hh:g,Hl:v}=this;return[e,n,r,i,s,o,a,c,u,l,f,d,h,p,g,v]}set(e,n,r,i,s,o,a,c,u,l,f,d,h,p,g,v){this.Ah=e|0,this.Al=n|0,this.Bh=r|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=f|0,this.Fl=d|0,this.Gh=h|0,this.Gl=p|0,this.Hh=g|0,this.Hl=v|0}process(e,n){for(let _=0;_<16;_++,n+=4)Mn[_]=e.getUint32(n),jn[_]=e.getUint32(n+=4);for(let _=16;_<80;_++){const x=Mn[_-15]|0,$=jn[_-15]|0,T=ne.rotrSH(x,$,1)^ne.rotrSH(x,$,8)^ne.shrSH(x,$,7),U=ne.rotrSL(x,$,1)^ne.rotrSL(x,$,8)^ne.shrSL(x,$,7),F=Mn[_-2]|0,P=jn[_-2]|0,z=ne.rotrSH(F,P,19)^ne.rotrBH(F,P,61)^ne.shrSH(F,P,6),M=ne.rotrSL(F,P,19)^ne.rotrBL(F,P,61)^ne.shrSL(F,P,6),E=ne.add4L(U,M,jn[_-7],jn[_-16]),b=ne.add4H(E,T,z,Mn[_-7],Mn[_-16]);Mn[_]=b|0,jn[_]=E|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:h,Fl:p,Gh:g,Gl:v,Hh:B,Hl:D}=this;for(let _=0;_<80;_++){const x=ne.rotrSH(f,d,14)^ne.rotrSH(f,d,18)^ne.rotrBH(f,d,41),$=ne.rotrSL(f,d,14)^ne.rotrSL(f,d,18)^ne.rotrBL(f,d,41),T=f&h^~f&g,U=d&p^~d&v,F=ne.add5L(D,$,U,Zm[_],jn[_]),P=ne.add5H(F,B,x,T,Wm[_],Mn[_]),z=F|0,M=ne.rotrSH(r,i,28)^ne.rotrBH(r,i,34)^ne.rotrBH(r,i,39),E=ne.rotrSL(r,i,28)^ne.rotrBL(r,i,34)^ne.rotrBL(r,i,39),b=r&s^r&a^s&a,m=i&o^i&c^o&c;B=g|0,D=v|0,g=h|0,v=p|0,h=f|0,p=d|0,{h:f,l:d}=ne.add(u|0,l|0,P|0,z|0),u=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const y=ne.add3L(z,E,m);r=ne.add3H(y,P,M,b),i=y|0}({h:r,l:i}=ne.add(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=ne.add(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=ne.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=ne.add(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=ne.add(this.Eh|0,this.El|0,f|0,d|0),{h,l:p}=ne.add(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:v}=ne.add(this.Gh|0,this.Gl|0,g|0,v|0),{h:B,l:D}=ne.add(this.Hh|0,this.Hl|0,B|0,D|0),this.set(r,i,s,o,a,c,u,l,f,d,h,p,g,v,B,D)}roundClean(){Mn.fill(0),jn.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 Xm=Sm(()=>new Ym);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Wa=BigInt(0),jf=BigInt(1),Jm=BigInt(2);function Za(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ya(t){if(!Za(t))throw new Error("Uint8Array expected")}function Xa(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const Qm=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Ja(t){Ya(t);let e="";for(let n=0;n<t.length;n++)e+=Qm[t[n]];return e}function zf(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Wa:BigInt("0x"+t)}const pn={_0:48,_9:57,A:65,F:70,a:97,f:102};function Hf(t){if(t>=pn._0&&t<=pn._9)return t-pn._0;if(t>=pn.A&&t<=pn.F)return t-(pn.A-10);if(t>=pn.a&&t<=pn.f)return t-(pn.a-10)}function Vf(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=Hf(t.charCodeAt(s)),a=Hf(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)}r[i]=o*16+a}return r}function e2(t){return zf(Ja(t))}function Xs(t){return Ya(t),zf(Ja(Uint8Array.from(t).reverse()))}function Kf(t,e){return Vf(t.toString(16).padStart(e*2,"0"))}function Qa(t,e){return Kf(t,e).reverse()}function gn(t,e,n){let r;if(typeof e=="string")try{r=Vf(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Za(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}function Gf(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Ya(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}const ec=t=>typeof t=="bigint"&&Wa<=t;function t2(t,e,n){return ec(t)&&ec(e)&&ec(n)&&e<=t&&t<n}function qi(t,e,n,r){if(!t2(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function n2(t){let e;for(e=0;t>Wa;t>>=jf,e+=1);return e}const r2=t=>(Jm<<BigInt(t-1))-jf,i2={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"||Za(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 tc(t,e,n={}){const r=(i,s,o)=>{const a=i2[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))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return t}function Wf(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}const Re=BigInt(0),xe=BigInt(1),Dr=BigInt(2),s2=BigInt(3),nc=BigInt(4),Zf=BigInt(5),Yf=BigInt(8);function Be(t,e){const n=t%e;return n>=Re?n:e+n}function o2(t,e,n){if(e<Re)throw new Error("invalid exponent, negatives unsupported");if(n<=Re)throw new Error("invalid modulus");if(n===xe)return Re;let r=xe;for(;e>Re;)e&xe&&(r=r*t%n),t=t*t%n,e>>=xe;return r}function en(t,e,n){let r=t;for(;e-- >Re;)r*=r,r%=n;return r}function Xf(t,e){if(t===Re)throw new Error("invert: expected non-zero number");if(e<=Re)throw new Error("invert: expected positive modulus, got "+e);let n=Be(t,e),r=e,i=Re,s=xe;for(;n!==Re;){const o=r/n,a=r%n,c=i-s*o;r=n,n=a,i=s,s=c}if(r!==xe)throw new Error("invert: does not exist");return Be(i,e)}function a2(t){const e=(t-xe)/Dr;let n,r,i;for(n=t-xe,r=0;n%Dr===Re;n/=Dr,r++);for(i=Dr;i<t&&o2(i,e,t)!==t-xe;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(r===1){const o=(t+xe)/nc;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=(n+xe)/Dr;return function(o,a){if(o.pow(a,e)===o.neg(o.ONE))throw new Error("Cannot find square root");let c=r,u=o.pow(o.mul(o.ONE,i),n),l=o.pow(a,s),f=o.pow(a,n);for(;!o.eql(f,o.ONE);){if(o.eql(f,o.ZERO))return o.ZERO;let d=1;for(let p=o.sqr(f);d<c&&!o.eql(p,o.ONE);d++)p=o.sqr(p);const h=o.pow(u,xe<<BigInt(c-d-1));u=o.sqr(h),l=o.mul(l,h),f=o.mul(f,u),c=d}return l}}function c2(t){if(t%nc===s2){const e=(t+xe)/nc;return function(n,r){const i=n.pow(r,e);if(!n.eql(n.sqr(i),r))throw new Error("Cannot find square root");return i}}if(t%Yf===Zf){const e=(t-Zf)/Yf;return function(n,r){const i=n.mul(r,Dr),s=n.pow(i,e),o=n.mul(r,s),a=n.mul(n.mul(o,Dr),s),c=n.mul(o,n.sub(a,n.ONE));if(!n.eql(n.sqr(c),r))throw new Error("Cannot find square root");return c}}return a2(t)}const u2=(t,e)=>(Be(t,e)&xe)===xe,l2=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function f2(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=l2.reduce((r,i)=>(r[i]="function",r),e);return tc(t,n)}function h2(t,e,n){if(n<Re)throw new Error("invalid exponent, negatives unsupported");if(n===Re)return t.ONE;if(n===xe)return e;let r=t.ONE,i=e;for(;n>Re;)n&xe&&(r=t.mul(r,i)),i=t.sqr(i),n>>=xe;return r}function d2(t,e){const n=new Array(e.length),r=e.reduce((s,o,a)=>t.is0(o)?s:(n[a]=s,t.mul(s,o)),t.ONE),i=t.inv(r);return e.reduceRight((s,o,a)=>t.is0(o)?s:(n[a]=t.mul(s,n[a]),t.mul(s,o)),i),n}function Jf(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Qf(t,e,n=!1,r={}){if(t<=Re)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=Jf(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:n,BITS:i,BYTES:s,MASK:r2(i),ZERO:Re,ONE:xe,create:c=>Be(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Re<=c&&c<t},is0:c=>c===Re,isOdd:c=>(c&xe)===xe,neg:c=>Be(-c,t),eql:(c,u)=>c===u,sqr:c=>Be(c*c,t),add:(c,u)=>Be(c+u,t),sub:(c,u)=>Be(c-u,t),mul:(c,u)=>Be(c*u,t),pow:(c,u)=>h2(a,c,u),div:(c,u)=>Be(c*Xf(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Xf(c,t),sqrt:r.sqrt||(c=>(o||(o=c2(t)),o(a,c))),invertBatch:c=>d2(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>n?Qa(c,s):Kf(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return n?Xs(c):e2(c)}});return Object.freeze(a)}const eh=BigInt(0),Js=BigInt(1);function rc(t,e){const n=e.negate();return t?n:e}function th(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function ic(t,e){th(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1);return{windows:n,windowSize:r}}function p2(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function g2(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const sc=new WeakMap,nh=new WeakMap;function oc(t){return nh.get(t)||1}function y2(t,e){return{constTimeNegate:rc,hasPrecomputes(n){return oc(n)!==1},unsafeLadder(n,r,i=t.ZERO){let s=n;for(;r>eh;)r&Js&&(i=i.add(s)),s=s.double(),r>>=Js;return i},precomputeWindow(n,r){const{windows:i,windowSize:s}=ic(r,e),o=[];let a=n,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(n,r,i){const{windows:s,windowSize:o}=ic(n,e);let a=t.ZERO,c=t.BASE;const u=BigInt(2**n-1),l=2**n,f=BigInt(n);for(let d=0;d<s;d++){const h=d*o;let p=Number(i&u);i>>=f,p>o&&(p-=l,i+=Js);const g=h,v=h+Math.abs(p)-1,B=d%2!==0,D=p<0;p===0?c=c.add(rc(B,r[g])):a=a.add(rc(D,r[v]))}return{p:a,f:c}},wNAFUnsafe(n,r,i,s=t.ZERO){const{windows:o,windowSize:a}=ic(n,e),c=BigInt(2**n-1),u=2**n,l=BigInt(n);for(let f=0;f<o;f++){const d=f*a;if(i===eh)break;let h=Number(i&c);if(i>>=l,h>a&&(h-=u,i+=Js),h===0)continue;let p=r[d+Math.abs(h)-1];h<0&&(p=p.negate()),s=s.add(p)}return s},getPrecomputes(n,r,i){let s=sc.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&sc.set(r,i(s))),s},wNAFCached(n,r,i){const s=oc(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=oc(n);return o===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,n,i),r,s)},setWindowSize(n,r){th(r,e),nh.set(n,r),sc.delete(n)}}}function b2(t,e,n,r){if(p2(n,t),g2(r,e),n.length!==r.length)throw new Error("arrays of points and scalars must have equal length");const i=t.ZERO,s=n2(BigInt(n.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 f=u;f>=0;f-=o){c.fill(i);for(let h=0;h<r.length;h++){const p=r[h],g=Number(p>>BigInt(f)&BigInt(a));c[g]=c[g].add(n[h])}let d=i;for(let h=c.length-1,p=i;h>0;h--)p=p.add(c[h]),d=d.add(p);if(l=l.add(d),f!==0)for(let h=0;h<o;h++)l=l.double()}return l}function w2(t){return f2(t.Fp),tc(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Jf(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}const jt=BigInt(0),ht=BigInt(1),Qs=BigInt(2),m2=BigInt(8),v2={zip215:!0};function E2(t){const e=w2(t);return tc(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function x2(t){const e=E2(t),{Fp:n,n:r,prehash:i,hash:s,randomBytes:o,nByteLength:a,h:c}=e,u=Qs<<BigInt(a*8)-ht,l=n.create,f=Qf(e.n,e.nBitLength),d=e.uvRatio||((y,w)=>{try{return{isValid:!0,value:n.sqrt(y*n.inv(w))}}catch{return{isValid:!1,value:jt}}}),h=e.adjustScalarBytes||(y=>y),p=e.domain||((y,w,S)=>{if(Xa("phflag",S),w.length||S)throw new Error("Contexts/pre-hash are not supported");return y});function g(y,w){qi("coordinate "+y,w,jt,u)}function v(y){if(!(y instanceof _))throw new Error("ExtendedPoint expected")}const B=Wf((y,w)=>{const{ex:S,ey:A,ez:I}=y,O=y.is0();w==null&&(w=O?m2:n.inv(I));const R=l(S*w),L=l(A*w),C=l(I*w);if(O)return{x:jt,y:ht};if(C!==ht)throw new Error("invZ was invalid");return{x:R,y:L}}),D=Wf(y=>{const{a:w,d:S}=e;if(y.is0())throw new Error("bad point: ZERO");const{ex:A,ey:I,ez:O,et:R}=y,L=l(A*A),C=l(I*I),k=l(O*O),N=l(k*k),q=l(L*w),j=l(k*l(q+C)),W=l(N+l(S*l(L*C)));if(j!==W)throw new Error("bad point: equation left != right (1)");const V=l(A*I),Z=l(O*R);if(V!==Z)throw new Error("bad point: equation left != right (2)");return!0});class _{constructor(w,S,A,I){this.ex=w,this.ey=S,this.ez=A,this.et=I,g("x",w),g("y",S),g("z",A),g("t",I),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(w){if(w instanceof _)throw new Error("extended point not allowed");const{x:S,y:A}=w||{};return g("x",S),g("y",A),new _(S,A,ht,l(S*A))}static normalizeZ(w){const S=n.invertBatch(w.map(A=>A.ez));return w.map((A,I)=>A.toAffine(S[I])).map(_.fromAffine)}static msm(w,S){return b2(_,f,w,S)}_setWindowSize(w){T.setWindowSize(this,w)}assertValidity(){D(this)}equals(w){v(w);const{ex:S,ey:A,ez:I}=this,{ex:O,ey:R,ez:L}=w,C=l(S*L),k=l(O*I),N=l(A*L),q=l(R*I);return C===k&&N===q}is0(){return this.equals(_.ZERO)}negate(){return new _(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){const{a:w}=e,{ex:S,ey:A,ez:I}=this,O=l(S*S),R=l(A*A),L=l(Qs*l(I*I)),C=l(w*O),k=S+A,N=l(l(k*k)-O-R),q=C+R,j=q-L,W=C-R,V=l(N*j),Z=l(q*W),Q=l(N*W),ee=l(j*q);return new _(V,Z,ee,Q)}add(w){v(w);const{a:S,d:A}=e,{ex:I,ey:O,ez:R,et:L}=this,{ex:C,ey:k,ez:N,et:q}=w;if(S===BigInt(-1)){const jy=l((O-I)*(k+C)),zy=l((O+I)*(k-C)),Gl=l(zy-jy);if(Gl===jt)return this.double();const Hy=l(R*Qs*q),Vy=l(L*Qs*N),Ky=Vy+Hy,Gy=zy+jy,Wy=Vy-Hy,e$=l(Ky*Gl),t$=l(Gy*Wy),n$=l(Ky*Wy),r$=l(Gl*Gy);return new _(e$,t$,r$,n$)}const j=l(I*C),W=l(O*k),V=l(L*A*q),Z=l(R*N),Q=l((I+O)*(C+k)-j-W),ee=Z-V,ie=Z+V,fe=l(W-S*j),ve=l(Q*ee),Ln=l(ie*fe),Ba=l(Q*fe),QD=l(ee*ie);return new _(ve,Ln,QD,Ba)}subtract(w){return this.add(w.negate())}wNAF(w){return T.wNAFCached(this,w,_.normalizeZ)}multiply(w){const S=w;qi("scalar",S,ht,r);const{p:A,f:I}=this.wNAF(S);return _.normalizeZ([A,I])[0]}multiplyUnsafe(w,S=_.ZERO){const A=w;return qi("scalar",A,jt,r),A===jt?$:this.is0()||A===ht?this:T.wNAFCachedUnsafe(this,A,_.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return T.unsafeLadder(this,r).is0()}toAffine(w){return B(this,w)}clearCofactor(){const{h:w}=e;return w===ht?this:this.multiplyUnsafe(w)}static fromHex(w,S=!1){const{d:A,a:I}=e,O=n.BYTES;w=gn("pointHex",w,O),Xa("zip215",S);const R=w.slice(),L=w[O-1];R[O-1]=L&-129;const C=Xs(R),k=S?u:n.ORDER;qi("pointHex.y",C,jt,k);const N=l(C*C),q=l(N-ht),j=l(A*N-I);let{isValid:W,value:V}=d(q,j);if(!W)throw new Error("Point.fromHex: invalid y coordinate");const Z=(V&ht)===ht,Q=(L&128)!==0;if(!S&&V===jt&&Q)throw new Error("Point.fromHex: x=0 and x_0=1");return Q!==Z&&(V=l(-V)),_.fromAffine({x:V,y:C})}static fromPrivateKey(w){return P(w).point}toRawBytes(){const{x:w,y:S}=this.toAffine(),A=Qa(S,n.BYTES);return A[A.length-1]|=w&ht?128:0,A}toHex(){return Ja(this.toRawBytes())}}_.BASE=new _(e.Gx,e.Gy,ht,l(e.Gx*e.Gy)),_.ZERO=new _(jt,ht,ht,jt);const{BASE:x,ZERO:$}=_,T=y2(_,a*8);function U(y){return Be(y,r)}function F(y){return U(Xs(y))}function P(y){const w=n.BYTES;y=gn("private key",y,w);const S=gn("hashed private key",s(y),2*w),A=h(S.slice(0,w)),I=S.slice(w,2*w),O=F(A),R=x.multiply(O),L=R.toRawBytes();return{head:A,prefix:I,scalar:O,point:R,pointBytes:L}}function z(y){return P(y).pointBytes}function M(y=new Uint8Array,...w){const S=Gf(...w);return F(s(p(S,gn("context",y),!!i)))}function E(y,w,S={}){y=gn("message",y),i&&(y=i(y));const{prefix:A,scalar:I,pointBytes:O}=P(w),R=M(S.context,A,y),L=x.multiply(R).toRawBytes(),C=M(S.context,L,O,y),k=U(R+C*I);qi("signature.s",k,jt,r);const N=Gf(L,Qa(k,n.BYTES));return gn("result",N,n.BYTES*2)}const b=v2;function m(y,w,S,A=b){const{context:I,zip215:O}=A,R=n.BYTES;y=gn("signature",y,2*R),w=gn("message",w),S=gn("publicKey",S,R),O!==void 0&&Xa("zip215",O),i&&(w=i(w));const L=Xs(y.slice(R,2*R));let C,k,N;try{C=_.fromHex(S,O),k=_.fromHex(y.slice(0,R),O),N=x.multiplyUnsafe(L)}catch{return!1}if(!O&&C.isSmallOrder())return!1;const q=M(I,k.toRawBytes(),C.toRawBytes(),w);return k.add(C.multiplyUnsafe(q)).subtract(N).clearCofactor().equals(_.ZERO)}return x._setWindowSize(8),{CURVE:e,getPublicKey:z,sign:E,verify:m,ExtendedPoint:_,utils:{getExtendedPublicKey:P,randomPrivateKey:()=>o(n.BYTES),precompute(y=8,w=_.BASE){return w._setWindowSize(y),w.multiply(BigInt(3)),w}}}}BigInt(0),BigInt(1);const ac=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),rh=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);const _2=BigInt(1),ih=BigInt(2);BigInt(3);const S2=BigInt(5),I2=BigInt(8);function A2(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=ac,o=t*t%s*t%s,a=en(o,ih,s)*o%s,c=en(a,_2,s)*t%s,u=en(c,S2,s)*c%s,l=en(u,e,s)*u%s,f=en(l,n,s)*l%s,d=en(f,r,s)*f%s,h=en(d,i,s)*d%s,p=en(h,i,s)*d%s,g=en(p,e,s)*u%s;return{pow_p_5_8:en(g,ih,s)*t%s,b2:o}}function B2(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function O2(t,e){const n=ac,r=Be(e*e*e,n),i=Be(r*r*e,n),s=A2(t*i).pow_p_5_8;let o=Be(t*r*s,n);const a=Be(e*o*o,n),c=o,u=Be(o*rh,n),l=a===t,f=a===Be(-t,n),d=a===Be(-t*rh,n);return l&&(o=c),(f||d)&&(o=u),u2(o,n)&&(o=Be(-o,n)),{isValid:l||f,value:o}}const D2=(()=>Qf(ac,void 0,!0))(),$2=(()=>({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:D2,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:I2,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Xm,randomBytes:qf,adjustScalarBytes:B2,uvRatio:O2}))(),sh=(()=>x2($2))(),P2="EdDSA",T2="JWT",eo=".",to="base64url",oh="utf8",ah="utf8",R2=":",N2="did",C2="key",ch="base58btc",U2="z",F2="K36",L2=32;function cc(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function uh(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?cc(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function lh(t,e){e||(e=t.reduce((i,s)=>i+s.length,0));const n=uh(e);let r=0;for(const i of t)n.set(i,r),r+=i.length;return cc(n)}function k2(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[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 f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,v=0,B=0,D=p.length;B!==D&&p[B]===0;)B++,g++;for(var _=(D-B)*l+1>>>0,x=new Uint8Array(_);B!==D;){for(var $=p[B],T=0,U=_-1;($!==0||T<v)&&U!==-1;U--,T++)$+=256*x[U]>>>0,x[U]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");v=T,B++}for(var F=_-v;F!==_&&x[F]===0;)F++;for(var P=c.repeat(g);F<_;++F)P+=t.charAt(x[F]);return P}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var v=0,B=0;p[g]===c;)v++,g++;for(var D=(p.length-g)*u+1>>>0,_=new Uint8Array(D);p[g];){var x=n[p.charCodeAt(g)];if(x===255)return;for(var $=0,T=D-1;(x!==0||$<B)&&T!==-1;T--,$++)x+=a*_[T]>>>0,_[T]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");B=$,g++}if(p[g]!==" "){for(var U=D-B;U!==D&&_[U]===0;)U++;for(var F=new Uint8Array(v+(D-U)),P=v;U!==D;)F[P++]=_[U++];return F}}}function h(p){var g=d(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:h}}var q2=k2,M2=q2;const fh=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")},j2=t=>new TextEncoder().encode(t),z2=t=>new TextDecoder().decode(t);class H2{constructor(e,n,r){this.name=e,this.prefix=n,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class V2{constructor(e,n,r){if(this.name=e,this.prefix=n,n.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=n.codePointAt(0),this.baseDecode=r}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 hh(this,e)}}class K2{constructor(e){this.decoders=e}or(e){return hh(this,e)}decode(e){const n=e[0],r=this.decoders[n];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const hh=(t,e)=>new K2({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class G2{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new H2(e,n,r),this.decoder=new V2(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const no=({name:t,prefix:e,encode:n,decode:r})=>new G2(t,e,n,r),Mi=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=M2(n,e);return no({prefix:t,name:e,encode:r,decode:s=>fh(i(s))})},W2=(t,e,n,r)=>{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*n/8|0);let a=0,c=0,u=0;for(let l=0;l<s;++l){const f=i[t[l]];if(f===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<n|f,a+=n,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=n||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},Z2=(t,e,n)=>{const r=e[e.length-1]==="=",i=(1<<n)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>n;)o-=n,s+=e[i&a>>o];if(o&&(s+=e[i&a<<n-o]),r)for(;s.length*n&7;)s+="=";return s},Fe=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>no({prefix:e,name:t,encode(i){return Z2(i,r,n)},decode(i){return W2(i,r,n,t)}}),Y2=no({prefix:"\0",name:"identity",encode:t=>z2(t),decode:t=>j2(t)});var X2=Object.freeze({__proto__:null,identity:Y2});const J2=Fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Q2=Object.freeze({__proto__:null,base2:J2});const ev=Fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var tv=Object.freeze({__proto__:null,base8:ev});const nv=Mi({prefix:"9",name:"base10",alphabet:"0123456789"});var rv=Object.freeze({__proto__:null,base10:nv});const iv=Fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),sv=Fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ov=Object.freeze({__proto__:null,base16:iv,base16upper:sv});const av=Fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),cv=Fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),uv=Fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lv=Fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),fv=Fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),hv=Fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),dv=Fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),pv=Fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),gv=Fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yv=Object.freeze({__proto__:null,base32:av,base32upper:cv,base32pad:uv,base32padupper:lv,base32hex:fv,base32hexupper:hv,base32hexpad:dv,base32hexpadupper:pv,base32z:gv});const bv=Mi({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),wv=Mi({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var mv=Object.freeze({__proto__:null,base36:bv,base36upper:wv});const vv=Mi({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ev=Mi({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var xv=Object.freeze({__proto__:null,base58btc:vv,base58flickr:Ev});const _v=Fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Sv=Fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Iv=Fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Av=Fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Bv=Object.freeze({__proto__:null,base64:_v,base64pad:Sv,base64url:Iv,base64urlpad:Av});const dh=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}"),Ov=dh.reduce((t,e,n)=>(t[n]=e,t),[]),Dv=dh.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function $v(t){return t.reduce((e,n)=>(e+=Ov[n],e),"")}function Pv(t){const e=[];for(const n of t){const r=Dv[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const Tv=no({prefix:"\u{1F680}",name:"base256emoji",encode:$v,decode:Pv});var Rv=Object.freeze({__proto__:null,base256emoji:Tv}),Nv=gh,ph=128,Cv=127,Uv=~Cv,Fv=Math.pow(2,31);function gh(t,e,n){e=e||[],n=n||0;for(var r=n;t>=Fv;)e[n++]=t&255|ph,t/=128;for(;t&Uv;)e[n++]=t&255|ph,t>>>=7;return e[n]=t|0,gh.bytes=n-r+1,e}var Lv=uc,kv=128,yh=127;function uc(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw uc.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&yh)<<i:(o&yh)*Math.pow(2,i),i+=7}while(o>=kv);return uc.bytes=s-r,n}var qv=Math.pow(2,7),Mv=Math.pow(2,14),jv=Math.pow(2,21),zv=Math.pow(2,28),Hv=Math.pow(2,35),Vv=Math.pow(2,42),Kv=Math.pow(2,49),Gv=Math.pow(2,56),Wv=Math.pow(2,63),Zv=function(t){return t<qv?1:t<Mv?2:t<jv?3:t<zv?4:t<Hv?5:t<Vv?6:t<Kv?7:t<Gv?8:t<Wv?9:10},Yv={encode:Nv,decode:Lv,encodingLength:Zv},bh=Yv;const wh=(t,e,n=0)=>(bh.encode(t,e,n),e),mh=t=>bh.encodingLength(t),lc=(t,e)=>{const n=e.byteLength,r=mh(t),i=r+mh(n),s=new Uint8Array(i+n);return wh(t,s,0),wh(n,s,r),s.set(e,i),new Xv(t,n,e,s)};class Xv{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const vh=({name:t,code:e,encode:n})=>new Jv(t,e,n);class Jv{constructor(e,n,r){this.name=e,this.code=n,this.encode=r}digest(e){if(e instanceof Uint8Array){const n=this.encode(e);return n instanceof Uint8Array?lc(this.code,n):n.then(r=>lc(this.code,r))}else throw Error("Unknown type, must be binary type")}}const Eh=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),Qv=vh({name:"sha2-256",code:18,encode:Eh("SHA-256")}),e3=vh({name:"sha2-512",code:19,encode:Eh("SHA-512")});var t3=Object.freeze({__proto__:null,sha256:Qv,sha512:e3});const xh=0,n3="identity",_h=fh;var r3=Object.freeze({__proto__:null,identity:{code:xh,name:n3,encode:_h,digest:t=>lc(xh,_h(t))}});new TextEncoder,new TextDecoder;const Sh={...X2,...Q2,...tv,...rv,...ov,...yv,...mv,...xv,...Bv,...Rv};({...t3,...r3});function Ih(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const Ah=Ih("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),fc=Ih("ascii","a",t=>{let e="a";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e},t=>{t=t.substring(1);const e=uh(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),Bh={utf8:Ah,"utf-8":Ah,hex:Sh.base16,latin1:fc,ascii:fc,binary:fc,...Sh};function ro(t,e="utf8"){const n=Bh[e];if(!n)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"):n.encoder.encode(t).substring(1)}function si(t,e="utf8"){const n=Bh[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?cc(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}function Oh(t){return ni(ro(si(t,to),oh))}function io(t){return ro(si(Br(t),oh),to)}function Dh(t){const e=si(F2,ch),n=U2+ro(lh([e,t]),ch);return[N2,C2,n].join(R2)}function i3(t){return ro(t,to)}function s3(t){return si(t,to)}function o3(t){return si([io(t.header),io(t.payload)].join(eo),ah)}function a3(t){return[io(t.header),io(t.payload),i3(t.signature)].join(eo)}function hc(t){const e=t.split(eo),n=Oh(e[0]),r=Oh(e[1]),i=s3(e[2]),s=si(e.slice(0,2).join(eo),ah);return{header:n,payload:r,signature:i,data:s}}function $h(t=qf(L2)){const e=sh.getPublicKey(t);return{secretKey:lh([t,e]),publicKey:e}}async function c3(t,e,n,r,i=K.fromMiliseconds(Date.now())){const s={alg:P2,typ:T2},o=Dh(r.publicKey),a=i+n,c={iss:o,sub:t,aud:e,iat:i,exp:a},u=o3({header:s,payload:c}),l=sh.sign(u,r.secretKey.slice(0,32));return a3({header:s,payload:c,signature:l})}var Ph=function(t,e,n){if(n||arguments.length===2)for(var r=0,i=e.length,s;r<i;r++)(s||!(r in e))&&(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return t.concat(s||Array.prototype.slice.call(e))},u3=function(){function t(e,n,r){this.name=e,this.version=n,this.os=r,this.type="browser"}return t}(),l3=function(){function t(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return t}(),f3=function(){function t(e,n,r,i){this.name=e,this.version=n,this.os=r,this.bot=i,this.type="bot-device"}return t}(),h3=function(){function t(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return t}(),d3=function(){function t(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return t}(),p3=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,g3=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Th=3,y3=[["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",p3]],Rh=[["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 b3(t){return t?Nh(t):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new d3:typeof navigator<"u"?Nh(navigator.userAgent):v3()}function w3(t){return t!==""&&y3.reduce(function(e,n){var r=n[0],i=n[1];if(e)return e;var s=i.exec(t);return!!s&&[r,s]},!1)}function Nh(t){var e=w3(t);if(!e)return null;var n=e[0],r=e[1];if(n==="searchbot")return new h3;var i=r[1]&&r[1].split(".").join("_").split("_").slice(0,3);i?i.length<Th&&(i=Ph(Ph([],i,!0),E3(Th-i.length),!0)):i=[];var s=i.join("."),o=m3(t),a=g3.exec(t);return a&&a[1]?new f3(n,s,o,a[1]):new u3(n,s,o)}function m3(t){for(var e=0,n=Rh.length;e<n;e++){var r=Rh[e],i=r[0],s=r[1],o=s.exec(t);if(o)return i}return null}function v3(){var t=typeof process<"u"&&process.version;return t?new l3(process.version.slice(1)):null}function E3(t){for(var e=[],n=0;n<t;n++)e.push("0");return e}var be={};Object.defineProperty(be,"__esModule",{value:!0}),be.getLocalStorage=be.getLocalStorageOrThrow=be.getCrypto=be.getCryptoOrThrow=Ch=be.getLocation=be.getLocationOrThrow=dc=be.getNavigator=be.getNavigatorOrThrow=Pr=be.getDocument=be.getDocumentOrThrow=be.getFromWindowOrThrow=be.getFromWindow=void 0;function $r(t){let e;return typeof window<"u"&&typeof window[t]<"u"&&(e=window[t]),e}be.getFromWindow=$r;function oi(t){const e=$r(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}be.getFromWindowOrThrow=oi;function x3(){return oi("document")}be.getDocumentOrThrow=x3;function _3(){return $r("document")}var Pr=be.getDocument=_3;function S3(){return oi("navigator")}be.getNavigatorOrThrow=S3;function I3(){return $r("navigator")}var dc=be.getNavigator=I3;function A3(){return oi("location")}be.getLocationOrThrow=A3;function B3(){return $r("location")}var Ch=be.getLocation=B3;function O3(){return oi("crypto")}be.getCryptoOrThrow=O3;function D3(){return $r("crypto")}be.getCrypto=D3;function $3(){return oi("localStorage")}be.getLocalStorageOrThrow=$3;function P3(){return $r("localStorage")}be.getLocalStorage=P3;var pc={};Object.defineProperty(pc,"__esModule",{value:!0});var Uh=pc.getWindowMetadata=void 0;const Fh=be;function T3(){let t,e;try{t=Fh.getDocumentOrThrow(),e=Fh.getLocationOrThrow()}catch{return null}function n(){const f=t.getElementsByTagName("link"),d=[];for(let h=0;h<f.length;h++){const p=f[h],g=p.getAttribute("rel");if(g&&g.toLowerCase().indexOf("icon")>-1){const v=p.getAttribute("href");if(v)if(v.toLowerCase().indexOf("https:")===-1&&v.toLowerCase().indexOf("http:")===-1&&v.indexOf("//")!==0){let B=e.protocol+"//"+e.host;if(v.indexOf("/")===0)B+=v;else{const D=e.pathname.split("/");D.pop();const _=D.join("/");B+=_+"/"+v}d.push(B)}else if(v.indexOf("//")===0){const B=e.protocol+v;d.push(B)}else d.push(v)}}return d}function r(...f){const d=t.getElementsByTagName("meta");for(let h=0;h<d.length;h++){const p=d[h],g=["itemprop","property","name"].map(v=>p.getAttribute(v)).filter(v=>v?f.includes(v):!1);if(g.length&&g){const v=p.getAttribute("content");if(v)return v}}return""}function i(){let f=r("name","og:site_name","og:title","twitter:title");return f||(f=t.title),f}function s(){return r("description","og:description","twitter:description","keywords")}const o=i(),a=s(),c=e.origin,u=n();return{description:a,url:c,icons:u,name:o}}Uh=pc.getWindowMetadata=T3;const R3="0.1.1";function N3(){return R3}class ge extends Error{constructor(e,n={}){const r=(()=>{if(n.cause instanceof ge){if(n.cause.details)return n.cause.details;if(n.cause.shortMessage)return n.cause.shortMessage}return n.cause&&"details"in n.cause&&typeof n.cause.details=="string"?n.cause.details:n.cause?.message?n.cause.message:n.details})(),i=(()=>n.cause instanceof ge&&n.cause.docsPath||n.docsPath)(),o=`https://oxlib.sh${i??""}`,a=[e||"An error occurred.",...n.metaMessages?["",...n.metaMessages]:[],...r||i?["",r?`Details: ${r}`:void 0,i?`See: ${o}`:void 0]:[]].filter(c=>typeof c=="string").join(`
15
- `);super(a,n.cause?{cause:n.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@${N3()}`}),this.cause=n.cause,this.details=r,this.docs=o,this.docsPath=i,this.shortMessage=e}walk(e){return Lh(this,e)}}function Lh(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause?Lh(t.cause,e):e?null:t}const ai=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function C3(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function ji(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Tr(t,...e){if(!C3(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 U3(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");ji(t.outputLen),ji(t.blockLen)}function ci(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 kh(t,e){Tr(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function F3(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function zn(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function gc(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function tn(t,e){return t<<32-e|t>>>e}const L3=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function k3(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function q3(t){for(let e=0;e<t.length;e++)t[e]=k3(t[e]);return t}const qh=L3?t=>t:q3;function M3(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function so(t){return typeof t=="string"&&(t=M3(t)),Tr(t),t}function j3(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Tr(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}class yc{}function oo(t){const e=r=>t().update(so(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Mh(t=32){if(ai&&typeof ai.getRandomValues=="function")return ai.getRandomValues(new Uint8Array(t));if(ai&&typeof ai.randomBytes=="function")return Uint8Array.from(ai.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function z3(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,u=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+u,a,r)}function H3(t,e,n){return t&e^~t&n}function V3(t,e,n){return t&e^t&n^e&n}class jh extends yc{constructor(e,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=gc(this.buffer)}update(e){ci(this),e=so(e),Tr(e);const{view:n,buffer:r,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=gc(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ci(this),kh(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,zn(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let f=o;f<i;f++)n[f]=0;z3(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=gc(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 f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const yn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ke=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Ge=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),ao=BigInt(2**32-1),zh=BigInt(32);function K3(t,e=!1){return e?{h:Number(t&ao),l:Number(t>>zh&ao)}:{h:Number(t>>zh&ao)|0,l:Number(t&ao)|0}}function Hh(t,e=!1){const n=t.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:a}=K3(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const Vh=(t,e,n)=>t>>>n,Kh=(t,e,n)=>t<<32-n|e>>>n,ui=(t,e,n)=>t>>>n|e<<32-n,li=(t,e,n)=>t<<32-n|e>>>n,co=(t,e,n)=>t<<64-n|e>>>n-32,uo=(t,e,n)=>t>>>n-32|e<<64-n,G3=(t,e,n)=>t<<n|e>>>32-n,W3=(t,e,n)=>e<<n|t>>>32-n,Z3=(t,e,n)=>e<<n-32|t>>>64-n,Y3=(t,e,n)=>t<<n-32|e>>>64-n;function bn(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const X3=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),J3=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Q3=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),eE=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,tE=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),nE=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,rE=BigInt(0),zi=BigInt(1),iE=BigInt(2),sE=BigInt(7),oE=BigInt(256),aE=BigInt(113),Gh=[],Wh=[],Zh=[];for(let t=0,e=zi,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],Gh.push(2*(5*r+n)),Wh.push((t+1)*(t+2)/2%64);let i=rE;for(let s=0;s<7;s++)e=(e<<zi^(e>>sE)*aE)%oE,e&iE&&(i^=zi<<(zi<<BigInt(s))-zi);Zh.push(i)}const Yh=Hh(Zh,!0),cE=Yh[0],uE=Yh[1],Xh=(t,e,n)=>n>32?Z3(t,e,n):G3(t,e,n),Jh=(t,e,n)=>n>32?Y3(t,e,n):W3(t,e,n);function lE(t,e=24){const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let o=0;o<10;o++)n[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=n[c],l=n[c+1],f=Xh(u,l,1)^n[a],d=Jh(u,l,1)^n[a+1];for(let h=0;h<50;h+=10)t[o+h]^=f,t[o+h+1]^=d}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=Wh[o],c=Xh(i,s,a),u=Jh(i,s,a),l=Gh[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++)n[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~n[(a+2)%10]&n[(a+4)%10]}t[0]^=cE[r],t[1]^=uE[r]}zn(n)}class bc extends yc{constructor(e,n,r,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=s,ji(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=F3(this.state)}clone(){return this._cloneInto()}keccak(){qh(this.state32),lE(this.state32,this.rounds),qh(this.state32),this.posOut=0,this.pos=0}update(e){ci(this),e=so(e),Tr(e);const{blockLen:n,state:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(n-this.pos,i-s);for(let a=0;a<o;a++)r[this.pos++]^=e[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:n,pos:r,blockLen:i}=this;e[r]^=n,n&128&&r===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){ci(this,!1),Tr(e),this.finish();const n=this.state,{blockLen:r}=this;for(let i=0,s=e.length;i<s;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,s-i);e.set(n.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 ji(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(kh(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,zn(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new bc(n,r,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=r,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}}const fE=(t,e,n)=>oo(()=>new bc(e,t,n)),hE=(()=>fE(1,136,256/8))(),dE=Uint32Array.from([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]),Hn=new Uint32Array(64);class pE extends jh{constructor(e=32){super(64,e,8,!1),this.A=yn[0]|0,this.B=yn[1]|0,this.C=yn[2]|0,this.D=yn[3]|0,this.E=yn[4]|0,this.F=yn[5]|0,this.G=yn[6]|0,this.H=yn[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[e,n,r,i,s,o,a,c]}set(e,n,r,i,s,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let f=0;f<16;f++,n+=4)Hn[f]=e.getUint32(n,!1);for(let f=16;f<64;f++){const d=Hn[f-15],h=Hn[f-2],p=tn(d,7)^tn(d,18)^d>>>3,g=tn(h,17)^tn(h,19)^h>>>10;Hn[f]=g+Hn[f-7]+p+Hn[f-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=tn(a,6)^tn(a,11)^tn(a,25),h=l+d+H3(a,c,u)+dE[f]+Hn[f]|0,g=(tn(r,2)^tn(r,13)^tn(r,22))+V3(r,i,s)|0;l=u,u=c,c=a,a=o+h|0,o=s,s=i,i=r,r=h+g|0}r=r+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(r,i,s,o,a,c,u,l)}roundClean(){zn(Hn)}destroy(){this.set(0,0,0,0,0,0,0,0),zn(this.buffer)}}const Qh=(()=>Hh(["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))))(),gE=(()=>Qh[0])(),yE=(()=>Qh[1])(),Vn=new Uint32Array(80),Kn=new Uint32Array(80);class ed extends jh{constructor(e=64){super(128,e,16,!1),this.Ah=Ge[0]|0,this.Al=Ge[1]|0,this.Bh=Ge[2]|0,this.Bl=Ge[3]|0,this.Ch=Ge[4]|0,this.Cl=Ge[5]|0,this.Dh=Ge[6]|0,this.Dl=Ge[7]|0,this.Eh=Ge[8]|0,this.El=Ge[9]|0,this.Fh=Ge[10]|0,this.Fl=Ge[11]|0,this.Gh=Ge[12]|0,this.Gl=Ge[13]|0,this.Hh=Ge[14]|0,this.Hl=Ge[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:h,Gl:p,Hh:g,Hl:v}=this;return[e,n,r,i,s,o,a,c,u,l,f,d,h,p,g,v]}set(e,n,r,i,s,o,a,c,u,l,f,d,h,p,g,v){this.Ah=e|0,this.Al=n|0,this.Bh=r|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=f|0,this.Fl=d|0,this.Gh=h|0,this.Gl=p|0,this.Hh=g|0,this.Hl=v|0}process(e,n){for(let _=0;_<16;_++,n+=4)Vn[_]=e.getUint32(n),Kn[_]=e.getUint32(n+=4);for(let _=16;_<80;_++){const x=Vn[_-15]|0,$=Kn[_-15]|0,T=ui(x,$,1)^ui(x,$,8)^Vh(x,$,7),U=li(x,$,1)^li(x,$,8)^Kh(x,$,7),F=Vn[_-2]|0,P=Kn[_-2]|0,z=ui(F,P,19)^co(F,P,61)^Vh(F,P,6),M=li(F,P,19)^uo(F,P,61)^Kh(F,P,6),E=Q3(U,M,Kn[_-7],Kn[_-16]),b=eE(E,T,z,Vn[_-7],Vn[_-16]);Vn[_]=b|0,Kn[_]=E|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:h,Fl:p,Gh:g,Gl:v,Hh:B,Hl:D}=this;for(let _=0;_<80;_++){const x=ui(f,d,14)^ui(f,d,18)^co(f,d,41),$=li(f,d,14)^li(f,d,18)^uo(f,d,41),T=f&h^~f&g,U=d&p^~d&v,F=tE(D,$,U,yE[_],Kn[_]),P=nE(F,B,x,T,gE[_],Vn[_]),z=F|0,M=ui(r,i,28)^co(r,i,34)^co(r,i,39),E=li(r,i,28)^uo(r,i,34)^uo(r,i,39),b=r&s^r&a^s&a,m=i&o^i&c^o&c;B=g|0,D=v|0,g=h|0,v=p|0,h=f|0,p=d|0,{h:f,l:d}=bn(u|0,l|0,P|0,z|0),u=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const y=X3(z,E,m);r=J3(y,P,M,b),i=y|0}({h:r,l:i}=bn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=bn(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=bn(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=bn(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=bn(this.Eh|0,this.El|0,f|0,d|0),{h,l:p}=bn(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:v}=bn(this.Gh|0,this.Gl|0,g|0,v|0),{h:B,l:D}=bn(this.Hh|0,this.Hl|0,B|0,D|0),this.set(r,i,s,o,a,c,u,l,f,d,h,p,g,v,B,D)}roundClean(){zn(Vn,Kn)}destroy(){zn(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class bE extends ed{constructor(){super(48),this.Ah=Ke[0]|0,this.Al=Ke[1]|0,this.Bh=Ke[2]|0,this.Bl=Ke[3]|0,this.Ch=Ke[4]|0,this.Cl=Ke[5]|0,this.Dh=Ke[6]|0,this.Dl=Ke[7]|0,this.Eh=Ke[8]|0,this.El=Ke[9]|0,this.Fh=Ke[10]|0,this.Fl=Ke[11]|0,this.Gh=Ke[12]|0,this.Gl=Ke[13]|0,this.Hh=Ke[14]|0,this.Hl=Ke[15]|0}}const lo=oo(()=>new pE),wE=oo(()=>new ed),mE=oo(()=>new bE);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const wc=BigInt(0),fo=BigInt(1);function Hi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Gn(t){if(!Hi(t))throw new Error("Uint8Array expected")}function Vi(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function ho(t){const e=t.toString(16);return e.length&1?"0"+e:e}function td(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?wc:BigInt("0x"+t)}const nd=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",vE=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Rr(t){if(Gn(t),nd)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=vE[t[n]];return e}const wn={_0:48,_9:57,A:65,F:70,a:97,f:102};function rd(t){if(t>=wn._0&&t<=wn._9)return t-wn._0;if(t>=wn.A&&t<=wn.F)return t-(wn.A-10);if(t>=wn.a&&t<=wn.f)return t-(wn.a-10)}function po(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(nd)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=rd(t.charCodeAt(s)),a=rd(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)}r[i]=o*16+a}return r}function rt(t){return td(Rr(t))}function id(t){return Gn(t),td(Rr(Uint8Array.from(t).reverse()))}function Oe(t,e){return po(t.toString(16).padStart(e*2,"0"))}function sd(t,e){return Oe(t,e).reverse()}function We(t,e,n){let r;if(typeof e=="string")try{r=po(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Hi(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}function _e(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Gn(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}function mc(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}const vc=t=>typeof t=="bigint"&&wc<=t;function Ec(t,e,n){return vc(t)&&vc(e)&&vc(n)&&e<=t&&t<n}function fi(t,e,n,r){if(!Ec(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Ki(t){let e;for(e=0;t>wc;t>>=fo,e+=1);return e}function EE(t,e){return t>>BigInt(e)&fo}const Nr=t=>(fo<<BigInt(t))-fo,xc=t=>new Uint8Array(t),od=t=>Uint8Array.from(t);function xE(t,e,n){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 n!="function")throw new Error("hmacFn must be a function");let r=xc(t),i=xc(t),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},a=(...f)=>n(i,r,...f),c=(f=xc(0))=>{i=a(od([0]),f),r=a(),f.length!==0&&(i=a(od([1]),f),r=a())},u=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0;const d=[];for(;f<e;){r=a();const h=r.slice();d.push(h),f+=r.length}return _e(...d)};return(f,d)=>{o(),c(f);let h;for(;!(h=d(u()));)c();return o(),h}}const _E={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"||Hi(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 Gi(t,e,n={}){const r=(i,s,o)=>{const a=_E[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))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return t}const ad=()=>{throw new Error("not implemented")};function _c(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}function SE(t,e){if(dd(t)>e)throw new KE({givenSize:dd(t),maxSize:e})}const mn={zero:48,nine:57,A:65,F:70,a:97,f:102};function cd(t){if(t>=mn.zero&&t<=mn.nine)return t-mn.zero;if(t>=mn.A&&t<=mn.F)return t-(mn.A-10);if(t>=mn.a&&t<=mn.f)return t-(mn.a-10)}function IE(t,e={}){const{dir:n,size:r=32}=e;if(r===0)return t;if(t.length>r)throw new GE({size:t.length,targetSize:r,type:"Bytes"});const i=new Uint8Array(r);for(let s=0;s<r;s++){const o=n==="right";i[o?s:r-s-1]=t[o?s:t.length-s-1]}return i}function Sc(t,e){if(En(t)>e)throw new UE({givenSize:En(t),maxSize:e})}function AE(t,e){if(typeof e=="number"&&e>0&&e>En(t)-1)throw new hd({offset:e,position:"start",size:En(t)})}function BE(t,e,n){if(typeof e=="number"&&typeof n=="number"&&En(t)!==n-e)throw new hd({offset:n,position:"end",size:En(t)})}function ud(t,e={}){const{dir:n,size:r=32}=e;if(r===0)return t;const i=t.replace("0x","");if(i.length>r*2)throw new FE({size:Math.ceil(i.length/2),targetSize:r,type:"Hex"});return`0x${i[n==="right"?"padEnd":"padStart"](r*2,"0")}`}const OE="#__bigint";function Ic(t,e,n){return JSON.stringify(t,(r,i)=>typeof e=="function"?e(r,i):typeof i=="bigint"?i.toString()+OE:i,n)}const DE=new TextEncoder,$E=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function PE(t,e={}){const{strict:n=!1}=e;if(!t)throw new ld(t);if(typeof t!="string")throw new ld(t);if(n&&!/^0x[0-9a-fA-F]*$/.test(t))throw new fd(t);if(!t.startsWith("0x"))throw new fd(t)}function Ac(...t){return`0x${t.reduce((e,n)=>e+n.replace("0x",""),"")}`}function Bc(t){return t instanceof Uint8Array?Wi(t):Array.isArray(t)?Wi(new Uint8Array(t)):t}function TE(t,e={}){const n=`0x${Number(t)}`;return typeof e.size=="number"?(Sc(n,e.size),yo(n,e.size)):n}function Wi(t,e={}){let n="";for(let i=0;i<t.length;i++)n+=$E[t[i]];const r=`0x${n}`;return typeof e.size=="number"?(Sc(r,e.size),Oc(r,e.size)):r}function go(t,e={}){const{signed:n,size:r}=e,i=BigInt(t);let s;r?n?s=(1n<<BigInt(r)*8n-1n)-1n:s=2n**(BigInt(r)*8n)-1n:typeof t=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&n?-s-1n:0;if(s&&i>s||i<o){const u=typeof t=="bigint"?"n":"";throw new CE({max:s?`${s}${u}`:void 0,min:`${o}${u}`,signed:n,size:r,value:`${t}${u}`})}const c=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?yo(c,r):c}function RE(t,e={}){return Wi(DE.encode(t),e)}function yo(t,e){return ud(t,{dir:"left",size:e})}function Oc(t,e){return ud(t,{dir:"right",size:e})}function vn(t,e,n,r={}){const{strict:i}=r;AE(t,e);const s=`0x${t.replace("0x","").slice((e??0)*2,(n??t.length)*2)}`;return i&&BE(s,e,n),s}function En(t){return Math.ceil((t.length-2)/2)}function NE(t,e={}){const{strict:n=!1}=e;try{return PE(t,{strict:n}),!0}catch{return!1}}class CE extends ge{constructor({max:e,min:n,signed:r,size:i,value:s}){super(`Number \`${s}\` is not in safe${i?` ${i*8}-bit`:""}${r?" signed":" unsigned"} integer range ${e?`(\`${n}\` to \`${e}\`)`:`(above \`${n}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class ld extends ge{constructor(e){super(`Value \`${typeof e=="object"?Ic(e):e}\` of type \`${typeof e}\` is an invalid hex type.`,{metaMessages:['Hex types must be represented as `"0x${string}"`.']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexTypeError"})}}class fd extends ge{constructor(e){super(`Value \`${e}\` is an invalid hex value.`,{metaMessages:['Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexValueError"})}}class UE extends ge{constructor({givenSize:e,maxSize:n}){super(`Size cannot exceed \`${n}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}}class hd extends ge{constructor({offset:e,position:n,size:r}){super(`Slice ${n==="start"?"starting":"ending"} at offset \`${e}\` is out-of-bounds (size: \`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SliceOffsetOutOfBoundsError"})}}class FE extends ge{constructor({size:e,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}const LE=new TextEncoder;function kE(t){if(!(t instanceof Uint8Array)){if(!t)throw new bo(t);if(typeof t!="object")throw new bo(t);if(!("BYTES_PER_ELEMENT"in t))throw new bo(t);if(t.BYTES_PER_ELEMENT!==1||t.constructor.name!=="Uint8Array")throw new bo(t)}}function qE(t){return t instanceof Uint8Array?t:typeof t=="string"?jE(t):ME(t)}function ME(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function jE(t,e={}){const{size:n}=e;let r=t;n&&(Sc(t,n),r=Oc(t,n));let i=r.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=cd(i.charCodeAt(c++)),l=cd(i.charCodeAt(c++));if(u===void 0||l===void 0)throw new ge(`Invalid byte sequence ("${i[c-2]}${i[c-1]}" in "${i}").`);o[a]=u*16+l}return o}function zE(t,e={}){const{size:n}=e,r=LE.encode(t);return typeof n=="number"?(SE(r,n),HE(r,n)):r}function HE(t,e){return IE(t,{dir:"right",size:e})}function dd(t){return t.length}function VE(t){try{return kE(t),!0}catch{return!1}}class bo extends ge{constructor(e){super(`Value \`${typeof e=="object"?Ic(e):e}\` of type \`${typeof e}\` is an invalid Bytes value.`,{metaMessages:["Bytes values must be of type `Bytes`."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.InvalidBytesTypeError"})}}class KE extends ge{constructor({givenSize:e,maxSize:n}){super(`Size cannot exceed \`${n}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}}class GE extends ge{constructor({size:e,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}function pd(t,e={}){const{as:n=typeof t=="string"?"Hex":"Bytes"}=e,r=hE(qE(t));return n==="Bytes"?r:Wi(r)}class WE extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const n=super.get(e);return super.has(e)&&n!==void 0&&(this.delete(e),super.set(e,n)),n}set(e,n){if(super.set(e,n),this.maxSize&&this.size>this.maxSize){const r=this.keys().next().value;r&&this.delete(r)}return this}}const Dc={checksum:new WE(8192)}.checksum;function gd(t,e={}){const{compressed:n}=e,{prefix:r,x:i,y:s}=t;if(n===!1||typeof i=="bigint"&&typeof s=="bigint"){if(r!==4)throw new bd({prefix:r,cause:new e8});return}if(n===!0||typeof i=="bigint"&&typeof s>"u"){if(r!==3&&r!==2)throw new bd({prefix:r,cause:new QE});return}throw new JE({publicKey:t})}function ZE(t){const e=(()=>{if(NE(t))return yd(t);if(VE(t))return YE(t);const{prefix:n,x:r,y:i}=t;return typeof r=="bigint"&&typeof i=="bigint"?{prefix:n??4,x:r,y:i}:{prefix:n,x:r}})();return gd(e),e}function YE(t){return yd(Wi(t))}function yd(t){if(t.length!==132&&t.length!==130&&t.length!==68)throw new t8({publicKey:t});if(t.length===130){const r=BigInt(vn(t,0,32)),i=BigInt(vn(t,32,64));return{prefix:4,x:r,y:i}}if(t.length===132){const r=Number(vn(t,0,1)),i=BigInt(vn(t,1,33)),s=BigInt(vn(t,33,65));return{prefix:r,x:i,y:s}}const e=Number(vn(t,0,1)),n=BigInt(vn(t,1,33));return{prefix:e,x:n}}function XE(t,e={}){gd(t);const{prefix:n,x:r,y:i}=t,{includePrefix:s=!0}=e;return Ac(s?go(n,{size:1}):"0x",go(r,{size:32}),typeof i=="bigint"?go(i,{size:32}):"0x")}class JE extends ge{constructor({publicKey:e}){super(`Value \`${Ic(e)}\` is not a valid public key.`,{metaMessages:["Public key must contain:","- an `x` and `prefix` value (compressed)","- an `x`, `y`, and `prefix` value (uncompressed)"]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidError"})}}class bd extends ge{constructor({prefix:e,cause:n}){super(`Prefix "${e}" is invalid.`,{cause:n}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidPrefixError"})}}class QE extends ge{constructor(){super("Prefix must be 2 or 3 for compressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidCompressedPrefixError"})}}class e8 extends ge{constructor(){super("Prefix must be 4 for uncompressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidUncompressedPrefixError"})}}class t8 extends ge{constructor({publicKey:e}){super(`Value \`${e}\` is an invalid public key size.`,{metaMessages:["Expected: 33 bytes (compressed + prefix), 64 bytes (uncompressed) or 65 bytes (uncompressed + prefix).",`Received ${En(Bc(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidSerializedSizeError"})}}const n8=/^0x[a-fA-F0-9]{40}$/;function $c(t,e={}){const{strict:n=!0}=e;if(!n8.test(t))throw new md({address:t,cause:new s8});if(n){if(t.toLowerCase()===t)return;if(wd(t)!==t)throw new md({address:t,cause:new o8})}}function wd(t){if(Dc.has(t))return Dc.get(t);$c(t,{strict:!1});const e=t.substring(2).toLowerCase(),n=pd(zE(e),{as:"Bytes"}),r=e.split("");for(let s=0;s<40;s+=2)n[s>>1]>>4>=8&&r[s]&&(r[s]=r[s].toUpperCase()),(n[s>>1]&15)>=8&&r[s+1]&&(r[s+1]=r[s+1].toUpperCase());const i=`0x${r.join("")}`;return Dc.set(t,i),i}function r8(t,e={}){const{checksum:n=!1}=e;return $c(t),n?wd(t):t}function i8(t,e={}){const n=pd(`0x${XE(t).slice(4)}`).substring(26);return r8(`0x${n}`,e)}class md extends ge{constructor({address:e,cause:n}){super(`Address "${e}" is invalid.`,{cause:n}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class s8 extends ge{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 o8 extends ge{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}const a8=/^(.*)\[([0-9]*)\]$/,c8=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,u8=/^(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 Pc(t,e){if(t.length!==e.length)throw new f8({expectedLength:t.length,givenLength:e.length});const n=[];for(let r=0;r<t.length;r++){const i=t[r],s=e[r];n.push(Pc.encode(i,s))}return Ac(...n)}(function(t){function e(n,r,i=!1){if(n==="address"){const c=r;return $c(c),yo(c.toLowerCase(),i?32:0)}if(n==="string")return RE(r);if(n==="bytes")return r;if(n==="bool")return yo(TE(r),i?32:1);const s=n.match(u8);if(s){const[c,u,l="256"]=s,f=Number.parseInt(l,10)/8;return go(r,{size:i?32:f,signed:u==="int"})}const o=n.match(c8);if(o){const[c,u]=o;if(Number.parseInt(u,10)!==(r.length-2)/2)throw new l8({expectedSize:Number.parseInt(u,10),value:r});return Oc(r,i?32:0)}const a=n.match(a8);if(a&&Array.isArray(r)){const[c,u]=a,l=[];for(let f=0;f<r.length;f++)l.push(e(u,r[f],!0));return l.length===0?"0x":Ac(...l)}throw new h8(n)}t.encode=e})(Pc||(Pc={}));class l8 extends ge{constructor({expectedSize:e,value:n}){super(`Size of bytes "${n}" (bytes${En(n)}) does not match expected size (bytes${e}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class f8 extends ge{constructor({expectedLength:e,givenLength:n}){super(["ABI encoding parameters/values length mismatch.",`Expected length (parameters): ${e}`,`Given length (values): ${n}`].join(`
16
- `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.LengthMismatchError"})}}class h8 extends ge{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 vd extends yc{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,U3(e);const r=so(n);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(r.length>i?e.create().update(r).digest():r);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),zn(s)}update(e){return ci(this),this.iHash.update(e),this}digestInto(e){ci(this),Tr(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:n,iHash:r,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=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Ed=(t,e,n)=>new vd(t,e).update(n).digest();Ed.create=(t,e)=>new vd(t,e);const dt=BigInt(0),it=BigInt(1),Cr=BigInt(2),d8=BigInt(3),xd=BigInt(4),_d=BigInt(5),Sd=BigInt(8);function st(t,e){const n=t%e;return n>=dt?n:e+n}function Pt(t,e,n){let r=t;for(;e-- >dt;)r*=r,r%=n;return r}function Tc(t,e){if(t===dt)throw new Error("invert: expected non-zero number");if(e<=dt)throw new Error("invert: expected positive modulus, got "+e);let n=st(t,e),r=e,i=dt,s=it;for(;n!==dt;){const a=r/n,c=r%n,u=i-s*a;r=n,n=c,i=s,s=u}if(r!==it)throw new Error("invert: does not exist");return st(i,e)}function Id(t,e){const n=(t.ORDER+it)/xd,r=t.pow(e,n);if(!t.eql(t.sqr(r),e))throw new Error("Cannot find square root");return r}function p8(t,e){const n=(t.ORDER-_d)/Sd,r=t.mul(e,Cr),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,Cr),i),a=t.mul(s,t.sub(o,t.ONE));if(!t.eql(t.sqr(a),e))throw new Error("Cannot find square root");return a}function g8(t){if(t<BigInt(3))throw new Error("sqrt is not defined for small field");let e=t-it,n=0;for(;e%Cr===dt;)e/=Cr,n++;let r=Cr;const i=Wn(t);for(;mo(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return Id;let s=i.pow(r,e);const o=(e+it)/Cr;return function(c,u){if(c.is0(u))return u;if(mo(c,u)!==1)throw new Error("Cannot find square root");let l=n,f=c.mul(c.ONE,s),d=c.pow(u,e),h=c.pow(u,o);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let p=1,g=c.sqr(d);for(;!c.eql(g,c.ONE);)if(p++,g=c.sqr(g),p===l)throw new Error("Cannot find square root");const v=it<<BigInt(l-p-1),B=c.pow(f,v);l=p,f=c.sqr(B),d=c.mul(d,f),h=c.mul(h,B)}return h}}function y8(t){return t%xd===d8?Id:t%Sd===_d?p8:g8(t)}const b8=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ad(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=b8.reduce((r,i)=>(r[i]="function",r),e);return Gi(t,n)}function wo(t,e,n){if(n<dt)throw new Error("invalid exponent, negatives unsupported");if(n===dt)return t.ONE;if(n===it)return e;let r=t.ONE,i=e;for(;n>dt;)n&it&&(r=t.mul(r,i)),i=t.sqr(i),n>>=it;return r}function Ur(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),i=e.reduce((o,a,c)=>t.is0(a)?o:(r[c]=o,t.mul(o,a)),t.ONE),s=t.inv(i);return e.reduceRight((o,a,c)=>t.is0(a)?o:(r[c]=t.mul(o,r[c]),t.mul(o,a)),s),r}function mo(t,e){const n=(t.ORDER-it)/Cr,r=t.pow(e,n),i=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),o=t.eql(r,t.neg(t.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Bd(t,e){e!==void 0&&ji(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Wn(t,e,n=!1,r={}){if(t<=dt)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=Bd(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:n,BITS:i,BYTES:s,MASK:Nr(i),ZERO:dt,ONE:it,create:c=>st(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return dt<=c&&c<t},is0:c=>c===dt,isOdd:c=>(c&it)===it,neg:c=>st(-c,t),eql:(c,u)=>c===u,sqr:c=>st(c*c,t),add:(c,u)=>st(c+u,t),sub:(c,u)=>st(c-u,t),mul:(c,u)=>st(c*u,t),pow:(c,u)=>wo(a,c,u),div:(c,u)=>st(c*Tc(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Tc(c,t),sqrt:r.sqrt||(c=>(o||(o=y8(t)),o(a,c))),toBytes:c=>n?sd(c,s):Oe(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return n?id(c):rt(c)},invertBatch:c=>Ur(a,c),cmov:(c,u,l)=>l?u:c});return Object.freeze(a)}function Od(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 Rc(t){const e=Od(t);return e+Math.ceil(e/2)}function Dd(t,e,n=!1){const r=t.length,i=Od(e),s=Rc(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?id(t):rt(t),a=st(o,e-it)+it;return n?sd(a,i):Oe(a,i)}const $d=BigInt(0),Nc=BigInt(1);function Cc(t,e){const n=e.negate();return t?n:e}function Pd(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Uc(t,e){Pd(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=Nr(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function Td(t,e,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(t&i),c=t>>o;a>r&&(a-=s,c+=Nc);const u=e*r,l=u+Math.abs(a)-1,f=a===0,d=a<0,h=e%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:h,offsetF:u}}function w8(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function m8(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const Fc=new WeakMap,Rd=new WeakMap;function Lc(t){return Rd.get(t)||1}function v8(t,e){return{constTimeNegate:Cc,hasPrecomputes(n){return Lc(n)!==1},unsafeLadder(n,r,i=t.ZERO){let s=n;for(;r>$d;)r&Nc&&(i=i.add(s)),s=s.double(),r>>=Nc;return i},precomputeWindow(n,r){const{windows:i,windowSize:s}=Uc(r,e),o=[];let a=n,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(n,r,i){let s=t.ZERO,o=t.BASE;const a=Uc(n,e);for(let c=0;c<a.windows;c++){const{nextN:u,offset:l,isZero:f,isNeg:d,isNegF:h,offsetF:p}=Td(i,c,a);i=u,f?o=o.add(Cc(h,r[p])):s=s.add(Cc(d,r[l]))}return{p:s,f:o}},wNAFUnsafe(n,r,i,s=t.ZERO){const o=Uc(n,e);for(let a=0;a<o.windows&&i!==$d;a++){const{nextN:c,offset:u,isZero:l,isNeg:f}=Td(i,a,o);if(i=c,!l){const d=r[u];s=s.add(f?d.negate():d)}}return s},getPrecomputes(n,r,i){let s=Fc.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&Fc.set(r,i(s))),s},wNAFCached(n,r,i){const s=Lc(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=Lc(n);return o===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,n,i),r,s)},setWindowSize(n,r){Pd(r,e),Rd.set(n,r),Fc.delete(n)}}}function E8(t,e,n,r){w8(n,t),m8(r,e);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,a=Ki(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=Nr(c),l=new Array(Number(u)+1).fill(o),f=Math.floor((e.BITS-1)/c)*c;let d=o;for(let h=f;h>=0;h-=c){l.fill(o);for(let g=0;g<s;g++){const v=r[g],B=Number(v>>BigInt(h)&u);l[B]=l[B].add(n[g])}let p=o;for(let g=l.length-1,v=o;g>0;g--)v=v.add(l[g]),p=p.add(v);if(d=d.add(p),h!==0)for(let g=0;g<c;g++)d=d.double()}return d}function Nd(t){return Ad(t.Fp),Gi(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Bd(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function Cd(t){t.lowS!==void 0&&Vi("lowS",t.lowS),t.prehash!==void 0&&Vi("prehash",t.prehash)}function x8(t){const e=Nd(t);Gi(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});const{endo:n,Fp:r,a:i}=e;if(n){if(!r.eql(i,r.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}class _8 extends Error{constructor(e=""){super(e)}}const xn={Err:_8,_tlv:{encode:(t,e)=>{const{Err:n}=xn;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");const r=e.length/2,i=ho(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?ho(i.length/2|128):"";return ho(t)+s+i+e},decode(t,e){const{Err:n}=xn;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const u=e.subarray(r,r+c);if(u.length!==c)throw new n("tlv.decode: length bytes not complete");if(u[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of u)o=o<<8|l;if(r+=c,o<128)throw new n("tlv.decode(long): not minimal encoding")}const a=e.subarray(r,r+o);if(a.length!==o)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(t){const{Err:e}=xn;if(t<zt)throw new e("integer: negative integers are not allowed");let n=ho(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=xn;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 rt(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=xn,i=We("signature",t),{v:s,l:o}=r.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,s),{v:u,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(t){const{_tlv:e,_int:n}=xn,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}};function kc(t,e){return Rr(Oe(t,e))}const zt=BigInt(0),pe=BigInt(1),Zn=BigInt(2),Zi=BigInt(3),qc=BigInt(4);function Mc(t){const e=x8(t),{Fp:n}=e,r=Wn(e.n,e.nBitLength),i=e.toBytes||((_,x,$)=>{const T=x.toAffine();return _e(Uint8Array.from([4]),n.toBytes(T.x),n.toBytes(T.y))}),s=e.fromBytes||(_=>{const x=_.subarray(1),$=n.fromBytes(x.subarray(0,n.BYTES)),T=n.fromBytes(x.subarray(n.BYTES,2*n.BYTES));return{x:$,y:T}});function o(_){const{a:x,b:$}=e,T=n.sqr(_),U=n.mul(T,_);return n.add(n.add(U,n.mul(_,x)),$)}function a(_,x){const $=n.sqr(x),T=o(_);return n.eql($,T)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const c=n.mul(n.pow(e.a,Zi),qc),u=n.mul(n.sqr(e.b),BigInt(27));if(n.is0(n.add(c,u)))throw new Error("bad curve params: a or b");function l(_){return Ec(_,pe,e.n)}function f(_){const{allowedPrivateKeyLengths:x,nByteLength:$,wrapPrivateKey:T,n:U}=e;if(x&&typeof _!="bigint"){if(Hi(_)&&(_=Rr(_)),typeof _!="string"||!x.includes(_.length))throw new Error("invalid private key");_=_.padStart($*2,"0")}let F;try{F=typeof _=="bigint"?_:rt(We("private key",_,$))}catch{throw new Error("invalid private key, expected hex or "+$+" bytes, got "+typeof _)}return T&&(F=st(F,U)),fi("private key",F,pe,U),F}function d(_){if(!(_ instanceof g))throw new Error("ProjectivePoint expected")}const h=_c((_,x)=>{const{px:$,py:T,pz:U}=_;if(n.eql(U,n.ONE))return{x:$,y:T};const F=_.is0();x==null&&(x=F?n.ONE:n.inv(U));const P=n.mul($,x),z=n.mul(T,x),M=n.mul(U,x);if(F)return{x:n.ZERO,y:n.ZERO};if(!n.eql(M,n.ONE))throw new Error("invZ was invalid");return{x:P,y:z}}),p=_c(_=>{if(_.is0()){if(e.allowInfinityPoint&&!n.is0(_.py))return;throw new Error("bad point: ZERO")}const{x,y:$}=_.toAffine();if(!n.isValid(x)||!n.isValid($))throw new Error("bad point: x or y not FE");if(!a(x,$))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class g{constructor(x,$,T){if(x==null||!n.isValid(x))throw new Error("x required");if($==null||!n.isValid($)||n.is0($))throw new Error("y required");if(T==null||!n.isValid(T))throw new Error("z required");this.px=x,this.py=$,this.pz=T,Object.freeze(this)}static fromAffine(x){const{x:$,y:T}=x||{};if(!x||!n.isValid($)||!n.isValid(T))throw new Error("invalid affine point");if(x instanceof g)throw new Error("projective point not allowed");const U=F=>n.eql(F,n.ZERO);return U($)&&U(T)?g.ZERO:new g($,T,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){const $=Ur(n,x.map(T=>T.pz));return x.map((T,U)=>T.toAffine($[U])).map(g.fromAffine)}static fromHex(x){const $=g.fromAffine(s(We("pointHex",x)));return $.assertValidity(),$}static fromPrivateKey(x){return g.BASE.multiply(f(x))}static msm(x,$){return E8(g,r,x,$)}_setWindowSize(x){D.setWindowSize(this,x)}assertValidity(){p(this)}hasEvenY(){const{y:x}=this.toAffine();if(n.isOdd)return!n.isOdd(x);throw new Error("Field doesn't support isOdd")}equals(x){d(x);const{px:$,py:T,pz:U}=this,{px:F,py:P,pz:z}=x,M=n.eql(n.mul($,z),n.mul(F,U)),E=n.eql(n.mul(T,z),n.mul(P,U));return M&&E}negate(){return new g(this.px,n.neg(this.py),this.pz)}double(){const{a:x,b:$}=e,T=n.mul($,Zi),{px:U,py:F,pz:P}=this;let z=n.ZERO,M=n.ZERO,E=n.ZERO,b=n.mul(U,U),m=n.mul(F,F),y=n.mul(P,P),w=n.mul(U,F);return w=n.add(w,w),E=n.mul(U,P),E=n.add(E,E),z=n.mul(x,E),M=n.mul(T,y),M=n.add(z,M),z=n.sub(m,M),M=n.add(m,M),M=n.mul(z,M),z=n.mul(w,z),E=n.mul(T,E),y=n.mul(x,y),w=n.sub(b,y),w=n.mul(x,w),w=n.add(w,E),E=n.add(b,b),b=n.add(E,b),b=n.add(b,y),b=n.mul(b,w),M=n.add(M,b),y=n.mul(F,P),y=n.add(y,y),b=n.mul(y,w),z=n.sub(z,b),E=n.mul(y,m),E=n.add(E,E),E=n.add(E,E),new g(z,M,E)}add(x){d(x);const{px:$,py:T,pz:U}=this,{px:F,py:P,pz:z}=x;let M=n.ZERO,E=n.ZERO,b=n.ZERO;const m=e.a,y=n.mul(e.b,Zi);let w=n.mul($,F),S=n.mul(T,P),A=n.mul(U,z),I=n.add($,T),O=n.add(F,P);I=n.mul(I,O),O=n.add(w,S),I=n.sub(I,O),O=n.add($,U);let R=n.add(F,z);return O=n.mul(O,R),R=n.add(w,A),O=n.sub(O,R),R=n.add(T,U),M=n.add(P,z),R=n.mul(R,M),M=n.add(S,A),R=n.sub(R,M),b=n.mul(m,O),M=n.mul(y,A),b=n.add(M,b),M=n.sub(S,b),b=n.add(S,b),E=n.mul(M,b),S=n.add(w,w),S=n.add(S,w),A=n.mul(m,A),O=n.mul(y,O),S=n.add(S,A),A=n.sub(w,A),A=n.mul(m,A),O=n.add(O,A),w=n.mul(S,O),E=n.add(E,w),w=n.mul(R,O),M=n.mul(I,M),M=n.sub(M,w),w=n.mul(I,S),b=n.mul(R,b),b=n.add(b,w),new g(M,E,b)}subtract(x){return this.add(x.negate())}is0(){return this.equals(g.ZERO)}wNAF(x){return D.wNAFCached(this,x,g.normalizeZ)}multiplyUnsafe(x){const{endo:$,n:T}=e;fi("scalar",x,zt,T);const U=g.ZERO;if(x===zt)return U;if(this.is0()||x===pe)return this;if(!$||D.hasPrecomputes(this))return D.wNAFCachedUnsafe(this,x,g.normalizeZ);let{k1neg:F,k1:P,k2neg:z,k2:M}=$.splitScalar(x),E=U,b=U,m=this;for(;P>zt||M>zt;)P&pe&&(E=E.add(m)),M&pe&&(b=b.add(m)),m=m.double(),P>>=pe,M>>=pe;return F&&(E=E.negate()),z&&(b=b.negate()),b=new g(n.mul(b.px,$.beta),b.py,b.pz),E.add(b)}multiply(x){const{endo:$,n:T}=e;fi("scalar",x,pe,T);let U,F;if($){const{k1neg:P,k1:z,k2neg:M,k2:E}=$.splitScalar(x);let{p:b,f:m}=this.wNAF(z),{p:y,f:w}=this.wNAF(E);b=D.constTimeNegate(P,b),y=D.constTimeNegate(M,y),y=new g(n.mul(y.px,$.beta),y.py,y.pz),U=b.add(y),F=m.add(w)}else{const{p:P,f:z}=this.wNAF(x);U=P,F=z}return g.normalizeZ([U,F])[0]}multiplyAndAddUnsafe(x,$,T){const U=g.BASE,F=(z,M)=>M===zt||M===pe||!z.equals(U)?z.multiplyUnsafe(M):z.multiply(M),P=F(this,$).add(F(x,T));return P.is0()?void 0:P}toAffine(x){return h(this,x)}isTorsionFree(){const{h:x,isTorsionFree:$}=e;if(x===pe)return!0;if($)return $(g,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:x,clearCofactor:$}=e;return x===pe?this:$?$(g,this):this.multiplyUnsafe(e.h)}toRawBytes(x=!0){return Vi("isCompressed",x),this.assertValidity(),i(g,this,x)}toHex(x=!0){return Vi("isCompressed",x),Rr(this.toRawBytes(x))}}g.BASE=new g(e.Gx,e.Gy,n.ONE),g.ZERO=new g(n.ZERO,n.ONE,n.ZERO);const{endo:v,nBitLength:B}=e,D=v8(g,v?Math.ceil(B/2):B);return{CURVE:e,ProjectivePoint:g,normPrivateKeyToScalar:f,weierstrassEquation:o,isWithinCurveOrder:l}}function S8(t){const e=Nd(t);return Gi(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function I8(t){const e=S8(t),{Fp:n,n:r,nByteLength:i,nBitLength:s}=e,o=n.BYTES+1,a=2*n.BYTES+1;function c(y){return st(y,r)}function u(y){return Tc(y,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:d,isWithinCurveOrder:h}=Mc({...e,toBytes(y,w,S){const A=w.toAffine(),I=n.toBytes(A.x),O=_e;return Vi("isCompressed",S),S?O(Uint8Array.from([w.hasEvenY()?2:3]),I):O(Uint8Array.from([4]),I,n.toBytes(A.y))},fromBytes(y){const w=y.length,S=y[0],A=y.subarray(1);if(w===o&&(S===2||S===3)){const I=rt(A);if(!Ec(I,pe,n.ORDER))throw new Error("Point is not on curve");const O=d(I);let R;try{R=n.sqrt(O)}catch(k){const N=k instanceof Error?": "+k.message:"";throw new Error("Point is not on curve"+N)}const L=(R&pe)===pe;return(S&1)===1!==L&&(R=n.neg(R)),{x:I,y:R}}else if(w===a&&S===4){const I=n.fromBytes(A.subarray(0,n.BYTES)),O=n.fromBytes(A.subarray(n.BYTES,2*n.BYTES));return{x:I,y:O}}else{const I=o,O=a;throw new Error("invalid Point, expected length of "+I+", or uncompressed "+O+", got "+w)}}});function p(y){const w=r>>pe;return y>w}function g(y){return p(y)?c(-y):y}const v=(y,w,S)=>rt(y.slice(w,S));class B{constructor(w,S,A){fi("r",w,pe,r),fi("s",S,pe,r),this.r=w,this.s=S,A!=null&&(this.recovery=A),Object.freeze(this)}static fromCompact(w){const S=i;return w=We("compactSignature",w,S*2),new B(v(w,0,S),v(w,S,2*S))}static fromDER(w){const{r:S,s:A}=xn.toSig(We("DER",w));return new B(S,A)}assertValidity(){}addRecoveryBit(w){return new B(this.r,this.s,w)}recoverPublicKey(w){const{r:S,s:A,recovery:I}=this,O=U(We("msgHash",w));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");const R=I===2||I===3?S+e.n:S;if(R>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const L=I&1?"03":"02",C=l.fromHex(L+kc(R,n.BYTES)),k=u(R),N=c(-O*k),q=c(A*k),j=l.BASE.multiplyAndAddUnsafe(C,N,q);if(!j)throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new B(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return po(this.toDERHex())}toDERHex(){return xn.hexFromSig(this)}toCompactRawBytes(){return po(this.toCompactHex())}toCompactHex(){const w=i;return kc(this.r,w)+kc(this.s,w)}}const D={isValidPrivateKey(y){try{return f(y),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const y=Rc(e.n);return Dd(e.randomBytes(y),e.n)},precompute(y=8,w=l.BASE){return w._setWindowSize(y),w.multiply(BigInt(3)),w}};function _(y,w=!0){return l.fromPrivateKey(y).toRawBytes(w)}function x(y){if(typeof y=="bigint")return!1;if(y instanceof l)return!0;const S=We("key",y).length,A=n.BYTES,I=A+1,O=2*A+1;if(!(e.allowedPrivateKeyLengths||i===I))return S===I||S===O}function $(y,w,S=!0){if(x(y)===!0)throw new Error("first arg must be private key");if(x(w)===!1)throw new Error("second arg must be public key");return l.fromHex(w).multiply(f(y)).toRawBytes(S)}const T=e.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");const w=rt(y),S=y.length*8-s;return S>0?w>>BigInt(S):w},U=e.bits2int_modN||function(y){return c(T(y))},F=Nr(s);function P(y){return fi("num < 2^"+s,y,zt,F),Oe(y,i)}function z(y,w,S=M){if(["recovered","canonical"].some(V=>V in S))throw new Error("sign() legacy options not supported");const{hash:A,randomBytes:I}=e;let{lowS:O,prehash:R,extraEntropy:L}=S;O==null&&(O=!0),y=We("msgHash",y),Cd(S),R&&(y=We("prehashed msgHash",A(y)));const C=U(y),k=f(w),N=[P(k),P(C)];if(L!=null&&L!==!1){const V=L===!0?I(n.BYTES):L;N.push(We("extraEntropy",V))}const q=_e(...N),j=C;function W(V){const Z=T(V);if(!h(Z))return;const Q=u(Z),ee=l.BASE.multiply(Z).toAffine(),ie=c(ee.x);if(ie===zt)return;const fe=c(Q*c(j+ie*k));if(fe===zt)return;let ve=(ee.x===ie?0:2)|Number(ee.y&pe),Ln=fe;return O&&p(fe)&&(Ln=g(fe),ve^=1),new B(ie,Ln,ve)}return{seed:q,k2sig:W}}const M={lowS:e.lowS,prehash:!1},E={lowS:e.lowS,prehash:!1};function b(y,w,S=M){const{seed:A,k2sig:I}=z(y,w,S),O=e;return xE(O.hash.outputLen,O.nByteLength,O.hmac)(A,I)}l.BASE._setWindowSize(8);function m(y,w,S,A=E){const I=y;w=We("msgHash",w),S=We("publicKey",S);const{lowS:O,prehash:R,format:L}=A;if(Cd(A),"strict"in A)throw new Error("options.strict was renamed to lowS");if(L!==void 0&&L!=="compact"&&L!=="der")throw new Error("format must be compact or der");const C=typeof I=="string"||Hi(I),k=!C&&!L&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!C&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,q;try{if(k&&(N=new B(I.r,I.s)),C){try{L!=="compact"&&(N=B.fromDER(I))}catch(ve){if(!(ve instanceof xn.Err))throw ve}!N&&L!=="der"&&(N=B.fromCompact(I))}q=l.fromHex(S)}catch{return!1}if(!N||O&&N.hasHighS())return!1;R&&(w=e.hash(w));const{r:j,s:W}=N,V=U(w),Z=u(W),Q=c(V*Z),ee=c(j*Z),ie=l.BASE.multiplyAndAddUnsafe(q,Q,ee)?.toAffine();return ie?c(ie.x)===j:!1}return{CURVE:e,getPublicKey:_,getSharedSecret:$,sign:b,verify:m,ProjectivePoint:l,Signature:B,utils:D}}function A8(t,e){const n=t.ORDER;let r=zt;for(let p=n-pe;p%Zn===zt;p/=Zn)r+=pe;const i=r,s=Zn<<i-pe-pe,o=s*Zn,a=(n-pe)/o,c=(a-pe)/Zn,u=o-pe,l=s,f=t.pow(e,a),d=t.pow(e,(a+pe)/Zn);let h=(p,g)=>{let v=f,B=t.pow(g,u),D=t.sqr(B);D=t.mul(D,g);let _=t.mul(p,D);_=t.pow(_,c),_=t.mul(_,B),B=t.mul(_,g),D=t.mul(_,p);let x=t.mul(D,B);_=t.pow(x,l);let $=t.eql(_,t.ONE);B=t.mul(D,d),_=t.mul(x,v),D=t.cmov(B,D,$),x=t.cmov(_,x,$);for(let T=i;T>pe;T--){let U=T-Zn;U=Zn<<U-pe;let F=t.pow(x,U);const P=t.eql(F,t.ONE);B=t.mul(D,v),v=t.mul(v,v),F=t.mul(x,v),D=t.cmov(B,D,P),x=t.cmov(F,x,P)}return{isValid:$,value:D}};if(t.ORDER%qc===Zi){const p=(t.ORDER-Zi)/qc,g=t.sqrt(t.neg(e));h=(v,B)=>{let D=t.sqr(B);const _=t.mul(v,B);D=t.mul(D,_);let x=t.pow(D,p);x=t.mul(x,_);const $=t.mul(x,g),T=t.mul(t.sqr(x),B),U=t.eql(T,v);let F=t.cmov($,x,U);return{isValid:U,value:F}}}return h}function Ud(t,e){if(Ad(t),!t.isValid(e.A)||!t.isValid(e.B)||!t.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=A8(t,e.Z);if(!t.isOdd)throw new Error("Fp.isOdd is not implemented!");return r=>{let i,s,o,a,c,u,l,f;i=t.sqr(r),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:h}=n(s,u);f=t.mul(i,r),f=t.mul(f,h),l=t.cmov(l,o,d),f=t.cmov(f,h,d);const p=t.isOdd(r)===t.isOdd(f);f=t.cmov(t.neg(f),f,p);const g=Ur(t,[a],!0)[0];return l=t.mul(l,g),{x:l,y:f}}}function B8(t){return{hash:t,hmac:(e,...n)=>Ed(t,e,j3(...n)),randomBytes:Mh}}function vo(t,e){const n=r=>I8({...t,...B8(r)});return{...n(e),create:n}}const O8=rt;function Yn(t,e){if(Yi(t),Yi(e),t<0||t>=1<<8*e)throw new Error("invalid I2OSP input: "+t);const n=Array.from({length:e}).fill(0);for(let r=e-1;r>=0;r--)n[r]=t&255,t>>>=8;return new Uint8Array(n)}function D8(t,e){const n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t[r]^e[r];return n}function Yi(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function $8(t,e,n,r){Gn(t),Gn(e),Yi(n),e.length>255&&(e=r(_e(mc("H2C-OVERSIZE-DST-"),e)));const{outputLen:i,blockLen:s}=r,o=Math.ceil(n/i);if(n>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");const a=_e(e,Yn(e.length,1)),c=Yn(0,s),u=Yn(n,2),l=new Array(o),f=r(_e(c,t,u,Yn(0,1),a));l[0]=r(_e(f,Yn(1,1),a));for(let h=1;h<=o;h++){const p=[D8(f,l[h-1]),Yn(h+1,1),a];l[h]=r(_e(...p))}return _e(...l).slice(0,n)}function P8(t,e,n,r,i){if(Gn(t),Gn(e),Yi(n),e.length>255){const s=Math.ceil(2*r/8);e=i.create({dkLen:s}).update(mc("H2C-OVERSIZE-DST-")).update(e).digest()}if(n>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:n}).update(t).update(Yn(n,2)).update(e).update(Yn(e.length,1)).digest()}function Fd(t,e,n){Gi(n,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:r,k:i,m:s,hash:o,expand:a,DST:c}=n;Gn(t),Yi(e);const u=typeof c=="string"?mc(c):c,l=r.toString(2).length,f=Math.ceil((l+i)/8),d=e*s*f;let h;if(a==="xmd")h=$8(t,u,d,o);else if(a==="xof")h=P8(t,u,d,i,o);else if(a==="_internal_pass")h=t;else throw new Error('expand must be "xmd" or "xof"');const p=new Array(e);for(let g=0;g<e;g++){const v=new Array(s);for(let B=0;B<s;B++){const D=f*(B+g*s),_=h.subarray(D,D+f);v[B]=st(O8(_),r)}p[g]=v}return p}function Ld(t,e){const n=e.map(r=>Array.from(r).reverse());return(r,i)=>{const[s,o,a,c]=n.map(f=>f.reduce((d,h)=>t.add(t.mul(d,r),h))),[u,l]=Ur(t,[o,c],!0);return r=t.mul(s,u),i=t.mul(i,t.mul(a,l)),{x:r,y:i}}}function kd(t,e,n){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function r(s){return t.fromAffine(e(s))}function i(s){const o=s.clearCofactor();return o.equals(t.ZERO)?t.ZERO:(o.assertValidity(),o)}return{defaults:n,hashToCurve(s,o){const a=Fd(s,2,{...n,DST:n.DST,...o}),c=r(a[0]),u=r(a[1]);return i(c.add(u))},encodeToCurve(s,o){const a=Fd(s,1,{...n,DST:n.encodeDST,...o});return i(r(a[0]))},mapToCurve(s){if(!Array.isArray(s))throw new Error("expected array of bigints");for(const o of s)if(typeof o!="bigint")throw new Error("expected array of bigints");return i(r(s))}}}const qd=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Md=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),T8=BigInt(0),R8=BigInt(1),jc=BigInt(2),jd=(t,e)=>(t+e/jc)/e;function N8(t){const e=qd,n=BigInt(3),r=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,f=Pt(l,n,e)*l%e,d=Pt(f,n,e)*l%e,h=Pt(d,jc,e)*u%e,p=Pt(h,i,e)*h%e,g=Pt(p,s,e)*p%e,v=Pt(g,a,e)*g%e,B=Pt(v,c,e)*v%e,D=Pt(B,a,e)*g%e,_=Pt(D,n,e)*l%e,x=Pt(_,o,e)*p%e,$=Pt(x,r,e)*u%e,T=Pt($,jc,e);if(!zc.eql(zc.sqr(T),t))throw new Error("Cannot find square root");return T}const zc=Wn(qd,void 0,void 0,{sqrt:N8}),C8=vo({a:T8,b:BigInt(7),Fp:zc,n:Md,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=Md,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-R8*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=jd(s*t,e),c=jd(-r*t,e);let u=st(t-a*n-c*i,e),l=st(-a*r-c*s,e);const f=u>o,d=l>o;if(f&&(u=e-u),d&&(l=e-l),u>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:f,k1:u,k2neg:d,k2:l}}}},lo);function U8(t){if(t.length!==130&&t.length!==132)throw new L8({signature:t});const e=BigInt(vn(t,0,32)),n=BigInt(vn(t,32,64)),r=(()=>{const i=+`0x${t.slice(130)}`;if(!Number.isNaN(i))try{return F8(i)}catch{throw new k8({value:i})}})();return typeof r>"u"?{r:e,s:n}:{r:e,s:n,yParity:r}}function F8(t){if(t===0||t===27)return 0;if(t===1||t===28)return 1;if(t>=35)return t%2===0?1:0;throw new q8({value:t})}class L8 extends ge{constructor({signature:e}){super(`Value \`${e}\` is an invalid signature size.`,{metaMessages:["Expected: 64 bytes or 65 bytes.",`Received ${En(Bc(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSerializedSizeError"})}}class k8 extends ge{constructor({value:e}){super(`Value \`${e}\` is an invalid y-parity value. Y-parity must be 0 or 1.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidYParityError"})}}class q8 extends ge{constructor({value:e}){super(`Value \`${e}\` is an invalid v value. v must be 27, 28 or >=35.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidVError"})}}Object.freeze({1:0n,2:1n,3:2n,4:3n,5:4n,6:5n,7:6n,8:7n,9:8n,A:9n,B:10n,C:11n,D:12n,E:13n,F:14n,G:15n,H:16n,J:17n,K:18n,L:19n,M:20n,N:21n,P:22n,Q:23n,R:24n,S:25n,T:26n,U:27n,V:28n,W:29n,X:30n,Y:31n,Z:32n,a:33n,b:34n,c:35n,d:36n,e:37n,f:38n,g:39n,h:40n,i:41n,j:42n,k:43n,m:44n,n:45n,o:46n,p:47n,q:48n,r:49n,s:50n,t:51n,u:52n,v:53n,w:54n,x:55n,y:56n,z:57n}),Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").map((t,e)=>[e,t.charCodeAt(0)]),{...Object.fromEntries(Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").map((t,e)=>[t.charCodeAt(0),e])),["=".charCodeAt(0)]:0,["-".charCodeAt(0)]:0,["_".charCodeAt(0)]:0},yn.slice();const M8=BigInt(0),Eo=BigInt(1),zd=BigInt(2),hi=BigInt(3);function j8(t){const e=[];for(;t>Eo;t>>=Eo)(t&Eo)===M8?e.unshift(0):(t&hi)===hi?(e.unshift(-1),t+=Eo):e.unshift(1);return e}function z8(t){const{Fp:e,Fr:n,Fp2:r,Fp6:i,Fp12:s}=t.fields,o=t.params.xNegative,a=t.params.twistType,c=Mc({n:n.ORDER,...t.G1}),u=Object.assign(c,kd(c.ProjectivePoint,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),l=Mc({n:n.ORDER,...t.G2}),f=Object.assign(l,kd(l.ProjectivePoint,t.G2.mapToCurve,{...t.htfDefaults,...t.G2.htfDefaults}));let d;if(a==="multiplicative")d=(C,k,N,q,j,W)=>s.mul014(q,C,r.mul(k,j),r.mul(N,W));else if(a==="divisive")d=(C,k,N,q,j,W)=>s.mul034(q,r.mul(N,W),r.mul(k,j),C);else throw new Error("bls: unknown twist type");const h=r.div(r.ONE,r.mul(r.ONE,zd));function p(C,k,N,q){const j=r.sqr(N),W=r.sqr(q),V=r.mulByB(r.mul(W,hi)),Z=r.mul(V,hi),Q=r.sub(r.sub(r.sqr(r.add(N,q)),W),j),ee=r.sub(V,j),ie=r.mul(r.sqr(k),hi),fe=r.neg(Q);return C.push([ee,ie,fe]),k=r.mul(r.mul(r.mul(r.sub(j,Z),k),N),h),N=r.sub(r.sqr(r.mul(r.add(j,Z),h)),r.mul(r.sqr(V),hi)),q=r.mul(j,Q),{Rx:k,Ry:N,Rz:q}}function g(C,k,N,q,j,W){const V=r.sub(N,r.mul(W,q)),Z=r.sub(k,r.mul(j,q)),Q=r.sub(r.mul(V,j),r.mul(Z,W)),ee=r.neg(V),ie=Z;C.push([Q,ee,ie]);const fe=r.sqr(Z),ve=r.mul(fe,Z),Ln=r.mul(fe,k),Ba=r.add(r.sub(ve,r.mul(Ln,zd)),r.mul(r.sqr(V),q));return k=r.mul(Z,Ba),N=r.sub(r.mul(r.sub(Ln,Ba),V),r.mul(ve,N)),q=r.mul(q,ve),{Rx:k,Ry:N,Rz:q}}const v=j8(t.params.ateLoopSize),B=_c(C=>{const k=C,{x:N,y:q}=k.toAffine(),j=N,W=q,V=r.neg(q);let Z=j,Q=W,ee=r.ONE;const ie=[];for(const fe of v){const ve=[];({Rx:Z,Ry:Q,Rz:ee}=p(ve,Z,Q,ee)),fe&&({Rx:Z,Ry:Q,Rz:ee}=g(ve,Z,Q,ee,j,fe===-1?V:W)),ie.push(ve)}if(t.postPrecompute){const fe=ie[ie.length-1];t.postPrecompute(Z,Q,ee,j,W,g.bind(null,fe))}return ie});function D(C,k=!1){let N=s.ONE;if(C.length){const q=C[0][0].length;for(let j=0;j<q;j++){N=s.sqr(N);for(const[W,V,Z]of C)for(const[Q,ee,ie]of W[j])N=d(Q,ee,ie,N,V,Z)}}return o&&(N=s.conjugate(N)),k?s.finalExponentiate(N):N}function _(C,k=!0){const N=[];u.ProjectivePoint.normalizeZ(C.map(({g1:q})=>q)),f.ProjectivePoint.normalizeZ(C.map(({g2:q})=>q));for(const{g1:q,g2:j}of C){if(q.equals(u.ProjectivePoint.ZERO)||j.equals(f.ProjectivePoint.ZERO))throw new Error("pairing is not available for ZERO point");q.assertValidity(),j.assertValidity();const W=q.toAffine();N.push([B(j),W.x,W.y])}return D(N,k)}function x(C,k,N=!0){return _([{g1:C,g2:k}],N)}const $={randomPrivateKey:()=>{const C=Rc(n.ORDER);return Dd(t.randomBytes(C),n.ORDER)},calcPairingPrecomputes:B},{ShortSignature:T}=t.G1,{Signature:U}=t.G2;function F(C){return C instanceof u.ProjectivePoint?C:u.ProjectivePoint.fromHex(C)}function P(C,k){return C instanceof u.ProjectivePoint?C:u.hashToCurve(We("point",C),k)}function z(C){return C instanceof f.ProjectivePoint?C:U.fromHex(C)}function M(C,k){return C instanceof f.ProjectivePoint?C:f.hashToCurve(We("point",C),k)}function E(C){return u.ProjectivePoint.fromPrivateKey(C).toRawBytes(!0)}function b(C){return f.ProjectivePoint.fromPrivateKey(C).toRawBytes(!0)}function m(C,k,N){const q=M(C,N);q.assertValidity();const j=q.multiply(u.normPrivateKeyToScalar(k));return C instanceof f.ProjectivePoint?j:U.toRawBytes(j)}function y(C,k,N){const q=P(C,N);q.assertValidity();const j=q.multiply(u.normPrivateKeyToScalar(k));return C instanceof u.ProjectivePoint?j:T.toRawBytes(j)}function w(C,k,N,q){const j=F(N),W=M(k,q),V=u.ProjectivePoint.BASE,Z=z(C),Q=_([{g1:j.negate(),g2:W},{g1:V,g2:Z}]);return s.eql(Q,s.ONE)}function S(C,k,N,q){const j=z(N),W=P(k,q),V=f.ProjectivePoint.BASE,Z=F(C),Q=_([{g1:W,g2:j},{g1:Z,g2:V.negate()}]);return s.eql(Q,s.ONE)}function A(C){if(!Array.isArray(C)||C.length===0)throw new Error("expected non-empty array")}function I(C){A(C);const N=C.map(F).reduce((q,j)=>q.add(j),u.ProjectivePoint.ZERO);return C[0]instanceof u.ProjectivePoint?(N.assertValidity(),N):N.toRawBytes(!0)}function O(C){A(C);const N=C.map(z).reduce((q,j)=>q.add(j),f.ProjectivePoint.ZERO);return C[0]instanceof f.ProjectivePoint?(N.assertValidity(),N):U.toRawBytes(N)}function R(C){A(C);const N=C.map(F).reduce((q,j)=>q.add(j),u.ProjectivePoint.ZERO);return C[0]instanceof u.ProjectivePoint?(N.assertValidity(),N):T.toRawBytes(N)}function L(C,k,N,q){if(A(k),N.length!==k.length)throw new Error("amount of public keys and messages should be equal");const j=z(C),W=k.map(ee=>M(ee,q)),V=N.map(F),Z=new Map;for(let ee=0;ee<V.length;ee++){const ie=V[ee],fe=W[ee];let ve=Z.get(fe);ve===void 0&&(ve=[],Z.set(fe,ve)),ve.push(ie)}const Q=[];try{for(const[ee,ie]of Z){const fe=ie.reduce((ve,Ln)=>ve.add(Ln));Q.push({g1:fe,g2:ee})}return Q.push({g1:u.ProjectivePoint.BASE.negate(),g2:j}),s.eql(_(Q),s.ONE)}catch{return!1}}return u.ProjectivePoint.BASE._setWindowSize(4),{getPublicKey:E,getPublicKeyForShortSignatures:b,sign:m,signShortSignature:y,verify:w,verifyBatch:L,verifyShortSignature:S,aggregatePublicKeys:I,aggregateSignatures:O,aggregateShortSignatures:R,millerLoopBatch:D,pairing:x,pairingBatch:_,G1:u,G2:f,Signature:U,ShortSignature:T,fields:{Fr:n,Fp:e,Fp2:r,Fp6:i,Fp12:s},params:{ateLoopSize:t.params.ateLoopSize,r:t.params.r,G1b:t.G1.b,G2b:t.G2.b},utils:$}}const H8=BigInt(0),di=BigInt(1),_n=BigInt(2),Hd=BigInt(3);function Hc(t,e,n,r,i=1,s){const o=BigInt(s===void 0?r:s),a=n**BigInt(r),c=[];for(let u=0;u<i;u++){const l=BigInt(u+1),f=[];for(let d=0,h=di;d<r;d++){const p=(l*h-l)/o%a;f.push(t.pow(e,p)),h*=n}c.push(f)}return c}function V8(t,e,n){const r=e.pow(n,(t.ORDER-di)/Hd),i=e.pow(n,(t.ORDER-di)/_n);function s(d,h){const p=e.mul(e.frobeniusMap(d,1),r),g=e.mul(e.frobeniusMap(h,1),i);return[p,g]}const o=e.pow(n,(t.ORDER**_n-di)/Hd),a=e.pow(n,(t.ORDER**_n-di)/_n);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(d,h){return[e.mul(d,o),e.neg(h)]}const u=d=>(h,p)=>{const g=p.toAffine(),v=d(g.x,g.y);return h.fromAffine({x:v[0],y:v[1]})},l=u(s),f=u(c);return{psi:s,psi2:c,G2psi:l,G2psi2:f,PSI_X:r,PSI_Y:i,PSI2_X:o,PSI2_Y:a}}function K8(t){const{ORDER:e}=t,n=Wn(e),r=n.create(t.NONRESIDUE||BigInt(-1)),i=n.div(n.ONE,_n),s=Hc(n,r,n.ORDER,2)[0],o=({c0:E,c1:b},{c0:m,c1:y})=>({c0:n.add(E,m),c1:n.add(b,y)}),a=({c0:E,c1:b},{c0:m,c1:y})=>({c0:n.sub(E,m),c1:n.sub(b,y)}),c=({c0:E,c1:b},m)=>{if(typeof m=="bigint")return{c0:n.mul(E,m),c1:n.mul(b,m)};const{c0:y,c1:w}=m;let S=n.mul(E,y),A=n.mul(b,w);const I=n.sub(S,A),O=n.sub(n.mul(n.add(E,b),n.add(y,w)),n.add(S,A));return{c0:I,c1:O}},u=({c0:E,c1:b})=>{const m=n.add(E,b),y=n.sub(E,b),w=n.add(E,E);return{c0:n.mul(m,y),c1:n.mul(w,b)}},l=E=>{if(E.length!==2)throw new Error("invalid tuple");const b=E.map(m=>n.create(m));return{c0:b[0],c1:b[1]}},f=e*e,d=l(t.FP2_NONRESIDUE),h={ORDER:f,isLE:n.isLE,NONRESIDUE:d,BITS:Ki(f),BYTES:Math.ceil(Ki(f)/8),MASK:Nr(Ki(f)),ZERO:{c0:n.ZERO,c1:n.ZERO},ONE:{c0:n.ONE,c1:n.ZERO},create:E=>E,isValid:({c0:E,c1:b})=>typeof E=="bigint"&&typeof b=="bigint",is0:({c0:E,c1:b})=>n.is0(E)&&n.is0(b),eql:({c0:E,c1:b},{c0:m,c1:y})=>n.eql(E,m)&&n.eql(b,y),neg:({c0:E,c1:b})=>({c0:n.neg(E),c1:n.neg(b)}),pow:(E,b)=>wo(h,E,b),invertBatch:E=>Ur(h,E),add:o,sub:a,mul:c,sqr:u,addN:o,subN:a,mulN:c,sqrN:u,div:(E,b)=>h.mul(E,typeof b=="bigint"?n.inv(n.create(b)):h.inv(b)),inv:({c0:E,c1:b})=>{const m=n.inv(n.create(E*E+b*b));return{c0:n.mul(m,n.create(E)),c1:n.mul(m,n.create(-b))}},sqrt:E=>{if(t.Fp2sqrt)return t.Fp2sqrt(E);const{c0:b,c1:m}=E;if(n.is0(m))return mo(n,b)===1?h.create({c0:n.sqrt(b),c1:n.ZERO}):h.create({c0:n.ZERO,c1:n.sqrt(n.div(b,r))});const y=n.sqrt(n.sub(n.sqr(b),n.mul(n.sqr(m),r)));let w=n.mul(n.add(y,b),i);mo(n,w)===-1&&(w=n.sub(w,y));const A=n.sqrt(w),I=h.create({c0:A,c1:n.div(n.mul(m,i),A)});if(!h.eql(h.sqr(I),E))throw new Error("Cannot find square root");const O=I,R=h.neg(O),{re:L,im:C}=h.reim(O),{re:k,im:N}=h.reim(R);return C>N||C===N&&L>k?O:R},isOdd:E=>{const{re:b,im:m}=h.reim(E),y=b%_n,w=b===H8,S=m%_n;return BigInt(y||w&&S)==di},fromBytes(E){if(E.length!==h.BYTES)throw new Error("fromBytes invalid length="+E.length);return{c0:n.fromBytes(E.subarray(0,n.BYTES)),c1:n.fromBytes(E.subarray(n.BYTES))}},toBytes:({c0:E,c1:b})=>_e(n.toBytes(E),n.toBytes(b)),cmov:({c0:E,c1:b},{c0:m,c1:y},w)=>({c0:n.cmov(E,m,w),c1:n.cmov(b,y,w)}),reim:({c0:E,c1:b})=>({re:E,im:b}),mulByNonresidue:({c0:E,c1:b})=>h.mul({c0:E,c1:b},d),mulByB:t.Fp2mulByB,fromBigTuple:l,frobeniusMap:({c0:E,c1:b},m)=>({c0:E,c1:n.mul(b,s[m%2])})},p=({c0:E,c1:b,c2:m},{c0:y,c1:w,c2:S})=>({c0:h.add(E,y),c1:h.add(b,w),c2:h.add(m,S)}),g=({c0:E,c1:b,c2:m},{c0:y,c1:w,c2:S})=>({c0:h.sub(E,y),c1:h.sub(b,w),c2:h.sub(m,S)}),v=({c0:E,c1:b,c2:m},y)=>{if(typeof y=="bigint")return{c0:h.mul(E,y),c1:h.mul(b,y),c2:h.mul(m,y)};const{c0:w,c1:S,c2:A}=y,I=h.mul(E,w),O=h.mul(b,S),R=h.mul(m,A);return{c0:h.add(I,h.mulByNonresidue(h.sub(h.mul(h.add(b,m),h.add(S,A)),h.add(O,R)))),c1:h.add(h.sub(h.mul(h.add(E,b),h.add(w,S)),h.add(I,O)),h.mulByNonresidue(R)),c2:h.sub(h.add(O,h.mul(h.add(E,m),h.add(w,A))),h.add(I,R))}},B=({c0:E,c1:b,c2:m})=>{let y=h.sqr(E),w=h.mul(h.mul(E,b),_n),S=h.mul(h.mul(b,m),_n),A=h.sqr(m);return{c0:h.add(h.mulByNonresidue(S),y),c1:h.add(h.mulByNonresidue(A),w),c2:h.sub(h.sub(h.add(h.add(w,h.sqr(h.add(h.sub(E,b),m))),S),y),A)}},[D,_]=Hc(h,d,n.ORDER,6,2,3),x={ORDER:h.ORDER,isLE:h.isLE,BITS:3*h.BITS,BYTES:3*h.BYTES,MASK:Nr(3*h.BITS),ZERO:{c0:h.ZERO,c1:h.ZERO,c2:h.ZERO},ONE:{c0:h.ONE,c1:h.ZERO,c2:h.ZERO},create:E=>E,isValid:({c0:E,c1:b,c2:m})=>h.isValid(E)&&h.isValid(b)&&h.isValid(m),is0:({c0:E,c1:b,c2:m})=>h.is0(E)&&h.is0(b)&&h.is0(m),neg:({c0:E,c1:b,c2:m})=>({c0:h.neg(E),c1:h.neg(b),c2:h.neg(m)}),eql:({c0:E,c1:b,c2:m},{c0:y,c1:w,c2:S})=>h.eql(E,y)&&h.eql(b,w)&&h.eql(m,S),sqrt:ad,div:(E,b)=>x.mul(E,typeof b=="bigint"?n.inv(n.create(b)):x.inv(b)),pow:(E,b)=>wo(x,E,b),invertBatch:E=>Ur(x,E),add:p,sub:g,mul:v,sqr:B,addN:p,subN:g,mulN:v,sqrN:B,inv:({c0:E,c1:b,c2:m})=>{let y=h.sub(h.sqr(E),h.mulByNonresidue(h.mul(m,b))),w=h.sub(h.mulByNonresidue(h.sqr(m)),h.mul(E,b)),S=h.sub(h.sqr(b),h.mul(E,m)),A=h.inv(h.add(h.mulByNonresidue(h.add(h.mul(m,w),h.mul(b,S))),h.mul(E,y)));return{c0:h.mul(A,y),c1:h.mul(A,w),c2:h.mul(A,S)}},fromBytes:E=>{if(E.length!==x.BYTES)throw new Error("fromBytes invalid length="+E.length);return{c0:h.fromBytes(E.subarray(0,h.BYTES)),c1:h.fromBytes(E.subarray(h.BYTES,2*h.BYTES)),c2:h.fromBytes(E.subarray(2*h.BYTES))}},toBytes:({c0:E,c1:b,c2:m})=>_e(h.toBytes(E),h.toBytes(b),h.toBytes(m)),cmov:({c0:E,c1:b,c2:m},{c0:y,c1:w,c2:S},A)=>({c0:h.cmov(E,y,A),c1:h.cmov(b,w,A),c2:h.cmov(m,S,A)}),fromBigSix:E=>{if(!Array.isArray(E)||E.length!==6)throw new Error("invalid Fp6 usage");return{c0:h.fromBigTuple(E.slice(0,2)),c1:h.fromBigTuple(E.slice(2,4)),c2:h.fromBigTuple(E.slice(4,6))}},frobeniusMap:({c0:E,c1:b,c2:m},y)=>({c0:h.frobeniusMap(E,y),c1:h.mul(h.frobeniusMap(b,y),D[y%6]),c2:h.mul(h.frobeniusMap(m,y),_[y%6])}),mulByFp2:({c0:E,c1:b,c2:m},y)=>({c0:h.mul(E,y),c1:h.mul(b,y),c2:h.mul(m,y)}),mulByNonresidue:({c0:E,c1:b,c2:m})=>({c0:h.mulByNonresidue(m),c1:E,c2:b}),mul1:({c0:E,c1:b,c2:m},y)=>({c0:h.mulByNonresidue(h.mul(m,y)),c1:h.mul(E,y),c2:h.mul(b,y)}),mul01({c0:E,c1:b,c2:m},y,w){let S=h.mul(E,y),A=h.mul(b,w);return{c0:h.add(h.mulByNonresidue(h.sub(h.mul(h.add(b,m),w),A)),S),c1:h.sub(h.sub(h.mul(h.add(y,w),h.add(E,b)),S),A),c2:h.add(h.sub(h.mul(h.add(E,m),y),S),A)}}},$=Hc(h,d,n.ORDER,12,1,6)[0],T=({c0:E,c1:b},{c0:m,c1:y})=>({c0:x.add(E,m),c1:x.add(b,y)}),U=({c0:E,c1:b},{c0:m,c1:y})=>({c0:x.sub(E,m),c1:x.sub(b,y)}),F=({c0:E,c1:b},m)=>{if(typeof m=="bigint")return{c0:x.mul(E,m),c1:x.mul(b,m)};let{c0:y,c1:w}=m,S=x.mul(E,y),A=x.mul(b,w);return{c0:x.add(S,x.mulByNonresidue(A)),c1:x.sub(x.mul(x.add(E,b),x.add(y,w)),x.add(S,A))}},P=({c0:E,c1:b})=>{let m=x.mul(E,b);return{c0:x.sub(x.sub(x.mul(x.add(x.mulByNonresidue(b),E),x.add(E,b)),m),x.mulByNonresidue(m)),c1:x.add(m,m)}};function z(E,b){const m=h.sqr(E),y=h.sqr(b);return{first:h.add(h.mulByNonresidue(y),m),second:h.sub(h.sub(h.sqr(h.add(E,b)),m),y)}}const M={ORDER:h.ORDER,isLE:x.isLE,BITS:2*x.BITS,BYTES:2*x.BYTES,MASK:Nr(2*x.BITS),ZERO:{c0:x.ZERO,c1:x.ZERO},ONE:{c0:x.ONE,c1:x.ZERO},create:E=>E,isValid:({c0:E,c1:b})=>x.isValid(E)&&x.isValid(b),is0:({c0:E,c1:b})=>x.is0(E)&&x.is0(b),neg:({c0:E,c1:b})=>({c0:x.neg(E),c1:x.neg(b)}),eql:({c0:E,c1:b},{c0:m,c1:y})=>x.eql(E,m)&&x.eql(b,y),sqrt:ad,inv:({c0:E,c1:b})=>{let m=x.inv(x.sub(x.sqr(E),x.mulByNonresidue(x.sqr(b))));return{c0:x.mul(E,m),c1:x.neg(x.mul(b,m))}},div:(E,b)=>M.mul(E,typeof b=="bigint"?n.inv(n.create(b)):M.inv(b)),pow:(E,b)=>wo(M,E,b),invertBatch:E=>Ur(M,E),add:T,sub:U,mul:F,sqr:P,addN:T,subN:U,mulN:F,sqrN:P,fromBytes:E=>{if(E.length!==M.BYTES)throw new Error("fromBytes invalid length="+E.length);return{c0:x.fromBytes(E.subarray(0,x.BYTES)),c1:x.fromBytes(E.subarray(x.BYTES))}},toBytes:({c0:E,c1:b})=>_e(x.toBytes(E),x.toBytes(b)),cmov:({c0:E,c1:b},{c0:m,c1:y},w)=>({c0:x.cmov(E,m,w),c1:x.cmov(b,y,w)}),fromBigTwelve:E=>({c0:x.fromBigSix(E.slice(0,6)),c1:x.fromBigSix(E.slice(6,12))}),frobeniusMap(E,b){const{c0:m,c1:y,c2:w}=x.frobeniusMap(E.c1,b),S=$[b%12];return{c0:x.frobeniusMap(E.c0,b),c1:x.create({c0:h.mul(m,S),c1:h.mul(y,S),c2:h.mul(w,S)})}},mulByFp2:({c0:E,c1:b},m)=>({c0:x.mulByFp2(E,m),c1:x.mulByFp2(b,m)}),conjugate:({c0:E,c1:b})=>({c0:E,c1:x.neg(b)}),mul014:({c0:E,c1:b},m,y,w)=>{let S=x.mul01(E,m,y),A=x.mul1(b,w);return{c0:x.add(x.mulByNonresidue(A),S),c1:x.sub(x.sub(x.mul01(x.add(b,E),m,h.add(y,w)),S),A)}},mul034:({c0:E,c1:b},m,y,w)=>{const S=x.create({c0:h.mul(E.c0,m),c1:h.mul(E.c1,m),c2:h.mul(E.c2,m)}),A=x.mul01(b,y,w),I=x.mul01(x.add(E,b),h.add(m,y),w);return{c0:x.add(x.mulByNonresidue(A),S),c1:x.sub(I,x.add(S,A))}},_cyclotomicSquare:t.Fp12cyclotomicSquare,_cyclotomicExp:t.Fp12cyclotomicExp,finalExponentiate:t.Fp12finalExponentiate};return{Fp:n,Fp2:h,Fp6:x,Fp4Square:z,Fp12:M}}const ot=BigInt(0),xo=BigInt(1),Ne=BigInt(2),_o=BigInt(3),Xi=BigInt(4),Xn=BigInt("0xd201000000010000"),G8=Ki(Xn),{Fp:X,Fp2:J,Fp6:Vc,Fp4Square:Kc,Fp12:re}=K8({ORDER:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),FP2_NONRESIDUE:[xo,xo],Fp2mulByB:({c0:t,c1:e})=>{const n=X.mul(t,Xi),r=X.mul(e,Xi);return{c0:X.sub(n,r),c1:X.add(n,r)}},Fp12cyclotomicSquare:({c0:t,c1:e})=>{const{c0:n,c1:r,c2:i}=t,{c0:s,c1:o,c2:a}=e,{first:c,second:u}=Kc(n,o),{first:l,second:f}=Kc(s,i),{first:d,second:h}=Kc(r,a),p=J.mulByNonresidue(h);return{c0:Vc.create({c0:J.add(J.mul(J.sub(c,n),Ne),c),c1:J.add(J.mul(J.sub(l,r),Ne),l),c2:J.add(J.mul(J.sub(d,i),Ne),d)}),c1:Vc.create({c0:J.add(J.mul(J.add(p,s),Ne),p),c1:J.add(J.mul(J.add(u,o),Ne),u),c2:J.add(J.mul(J.add(f,a),Ne),f)})}},Fp12cyclotomicExp(t,e){let n=re.ONE;for(let r=G8-1;r>=0;r--)n=re._cyclotomicSquare(n),EE(e,r)&&(n=re.mul(n,t));return n},Fp12finalExponentiate:t=>{const e=Xn,n=re.div(re.frobeniusMap(t,6),t),r=re.mul(re.frobeniusMap(n,2),n),i=re.conjugate(re._cyclotomicExp(r,e)),s=re.mul(re.conjugate(re._cyclotomicSquare(r)),i),o=re.conjugate(re._cyclotomicExp(s,e)),a=re.conjugate(re._cyclotomicExp(o,e)),c=re.mul(re.conjugate(re._cyclotomicExp(a,e)),re._cyclotomicSquare(i)),u=re.conjugate(re._cyclotomicExp(c,e)),l=re.frobeniusMap(re.mul(i,a),2),f=re.frobeniusMap(re.mul(o,r),3),d=re.frobeniusMap(re.mul(c,re.conjugate(r)),1),h=re.mul(re.mul(u,re.conjugate(s)),r);return re.mul(re.mul(re.mul(l,f),d),h)}}),Vd=Wn(BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001")),W8=Ld(J,[[["0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6"],["0x0","0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71a"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71e","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38d"],["0x171d6541fa38ccfaed6dea691f5fb614cb14b4e7f4e810aa22d6108f142b85757098e38d0f671c7188e2aaaaaaaa5ed1","0x0"]],[["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa63"],["0xc","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa9f"],["0x1","0x0"]],[["0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706","0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706"],["0x0","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97be"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71c","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38f"],["0x124c9ad43b6cf79bfbf7043de3811ad0761b0f37a1e26286b0e977c69aa274524e79097a56dc4bd9e1b371c71c718b10","0x0"]],[["0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb"],["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3"],["0x12","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99"],["0x1","0x0"]]].map(t=>t.map(e=>J.fromBigTuple(e.map(BigInt))))),Z8=Ld(X,[["0x11a05f2b1e833340b809101dd99815856b303e88a2d7005ff2627b56cdb4e2c85610c2d5f2e62d6eaeac1662734649b7","0x17294ed3e943ab2f0588bab22147a81c7c17e75b2f6a8417f565e33c70d1e86b4838f2a6f318c356e834eef1b3cb83bb","0xd54005db97678ec1d1048c5d10a9a1bce032473295983e56878e501ec68e25c958c3e3d2a09729fe0179f9dac9edcb0","0x1778e7166fcc6db74e0609d307e55412d7f5e4656a8dbf25f1b33289f1b330835336e25ce3107193c5b388641d9b6861","0xe99726a3199f4436642b4b3e4118e5499db995a1257fb3f086eeb65982fac18985a286f301e77c451154ce9ac8895d9","0x1630c3250d7313ff01d1201bf7a74ab5db3cb17dd952799b9ed3ab9097e68f90a0870d2dcae73d19cd13c1c66f652983","0xd6ed6553fe44d296a3726c38ae652bfb11586264f0f8ce19008e218f9c86b2a8da25128c1052ecaddd7f225a139ed84","0x17b81e7701abdbe2e8743884d1117e53356de5ab275b4db1a682c62ef0f2753339b7c8f8c8f475af9ccb5618e3f0c88e","0x80d3cf1f9a78fc47b90b33563be990dc43b756ce79f5574a2c596c928c5d1de4fa295f296b74e956d71986a8497e317","0x169b1f8e1bcfa7c42e0c37515d138f22dd2ecb803a0c5c99676314baf4bb1b7fa3190b2edc0327797f241067be390c9e","0x10321da079ce07e272d8ec09d2565b0dfa7dccdde6787f96d50af36003b14866f69b771f8c285decca67df3f1605fb7b","0x6e08c248e260e70bd1e962381edee3d31d79d7e22c837bc23c0bf1bc24c6b68c24b1b80b64d391fa9c8ba2e8ba2d229"],["0x8ca8d548cff19ae18b2e62f4bd3fa6f01d5ef4ba35b48ba9c9588617fc8ac62b558d681be343df8993cf9fa40d21b1c","0x12561a5deb559c4348b4711298e536367041e8ca0cf0800c0126c2588c48bf5713daa8846cb026e9e5c8276ec82b3bff","0xb2962fe57a3225e8137e629bff2991f6f89416f5a718cd1fca64e00b11aceacd6a3d0967c94fedcfcc239ba5cb83e19","0x3425581a58ae2fec83aafef7c40eb545b08243f16b1655154cca8abc28d6fd04976d5243eecf5c4130de8938dc62cd8","0x13a8e162022914a80a6f1d5f43e7a07dffdfc759a12062bb8d6b44e833b306da9bd29ba81f35781d539d395b3532a21e","0xe7355f8e4e667b955390f7f0506c6e9395735e9ce9cad4d0a43bcef24b8982f7400d24bc4228f11c02df9a29f6304a5","0x772caacf16936190f3e0c63e0596721570f5799af53a1894e2e073062aede9cea73b3538f0de06cec2574496ee84a3a","0x14a7ac2a9d64a8b230b3f5b074cf01996e7f63c21bca68a81996e1cdf9822c580fa5b9489d11e2d311f7d99bbdcc5a5e","0xa10ecf6ada54f825e920b3dafc7a3cce07f8d1d7161366b74100da67f39883503826692abba43704776ec3a79a1d641","0x95fc13ab9e92ad4476d6e3eb3a56680f682b4ee96f7d03776df533978f31c1593174e4b4b7865002d6384d168ecdd0a","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"],["0x90d97c81ba24ee0259d1f094980dcfa11ad138e48a869522b52af6c956543d3cd0c7aee9b3ba3c2be9845719707bb33","0x134996a104ee5811d51036d776fb46831223e96c254f383d0f906343eb67ad34d6c56711962fa8bfe097e75a2e41c696","0xcc786baa966e66f4a384c86a3b49942552e2d658a31ce2c344be4b91400da7d26d521628b00523b8dfe240c72de1f6","0x1f86376e8981c217898751ad8746757d42aa7b90eeb791c09e4a3ec03251cf9de405aba9ec61deca6355c77b0e5f4cb","0x8cc03fdefe0ff135caf4fe2a21529c4195536fbe3ce50b879833fd221351adc2ee7f8dc099040a841b6daecf2e8fedb","0x16603fca40634b6a2211e11db8f0a6a074a7d0d4afadb7bd76505c3d3ad5544e203f6326c95a807299b23ab13633a5f0","0x4ab0b9bcfac1bbcb2c977d027796b3ce75bb8ca2be184cb5231413c4d634f3747a87ac2460f415ec961f8855fe9d6f2","0x987c8d5333ab86fde9926bd2ca6c674170a05bfe3bdd81ffd038da6c26c842642f64550fedfe935a15e4ca31870fb29","0x9fc4018bd96684be88c9e221e4da1bb8f3abd16679dc26c1e8b6e6a1f20cabe69d65201c78607a360370e577bdba587","0xe1bba7a1186bdb5223abde7ada14a23c42a0ca7915af6fe06985e7ed1e4d43b9b3f7055dd4eba6f2bafaaebca731c30","0x19713e47937cd1be0dfd0b8f1d43fb93cd2fcbcb6caf493fd1183e416389e61031bf3a5cce3fbafce813711ad011c132","0x18b46a908f36f6deb918c143fed2edcc523559b8aaf0c2462e6bfe7f911f643249d9cdf41b44d606ce07c8a4d0074d8e","0xb182cac101b9399d155096004f53f447aa7b12a3426b08ec02710e807b4633f06c851c1919211f20d4c04f00b971ef8","0x245a394ad1eca9b72fc00ae7be315dc757b3b080d4c158013e6632d3c40659cc6cf90ad1c232a6442d9d3f5db980133","0x5c129645e44cf1102a159f748c4a3fc5e673d81d7e86568d9ab0f5d396a7ce46ba1049b6579afb7866b1e715475224b","0x15e6be4e990f03ce4ea50b3b42df2eb5cb181d8f84965a3957add4fa95af01b2b665027efec01c7704b456be69c8b604"],["0x16112c4c3a9c98b252181140fad0eae9601a6de578980be6eec3232b5be72e7a07f3688ef60c206d01479253b03663c1","0x1962d75c2381201e1a0cbd6c43c348b885c84ff731c4d59ca4a10356f453e01f78a4260763529e3532f6102c2e49a03d","0x58df3306640da276faaae7d6e8eb15778c4855551ae7f310c35a5dd279cd2eca6757cd636f96f891e2538b53dbf67f2","0x16b7d288798e5395f20d23bf89edb4d1d115c5dbddbcd30e123da489e726af41727364f2c28297ada8d26d98445f5416","0xbe0e079545f43e4b00cc912f8228ddcc6d19c9f0f69bbb0542eda0fc9dec916a20b15dc0fd2ededda39142311a5001d","0x8d9e5297186db2d9fb266eaac783182b70152c65550d881c5ecd87b6f0f5a6449f38db9dfa9cce202c6477faaf9b7ac","0x166007c08a99db2fc3ba8734ace9824b5eecfdfa8d0cf8ef5dd365bc400a0051d5fa9c01a58b1fb93d1a1399126a775c","0x16a3ef08be3ea7ea03bcddfabba6ff6ee5a4375efa1f4fd7feb34fd206357132b920f5b00801dee460ee415a15812ed9","0x1866c8ed336c61231a1be54fd1d74cc4f9fb0ce4c6af5920abc5750c4bf39b4852cfe2f7bb9248836b233d9d55535d4a","0x167a55cda70a6e1cea820597d94a84903216f763e13d87bb5308592e7ea7d4fbc7385ea3d529b35e346ef48bb8913f55","0x4d2f259eea405bd48f010a01ad2911d9c6dd039bb61a6290e591b36e636a5c871a5c29f4f83060400f8b49cba8f6aa8","0xaccbb67481d033ff5852c1e48c50c477f94ff8aefce42d28c0f9a88cea7913516f968986f7ebbea9684b529e2561092","0xad6b9514c767fe3c3613144b45f1496543346d98adf02267d5ceef9a00d9b8693000763e3b90ac11e99b138573345cc","0x2660400eb2e4f3b628bdd0d53cd76f2bf565b94e72927c1cb748df27942480e420517bd8714cc80d1fadc1326ed06f7","0xe0fa1d816ddc03e6b24255e0d7819c171c40f65e273b853324efcd6356caa205ca2f570f13497804415473a1d634b8f","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"]].map(t=>t.map(e=>BigInt(e)))),Y8=Ud(J,{A:J.create({c0:X.create(ot),c1:X.create(BigInt(240))}),B:J.create({c0:X.create(BigInt(1012)),c1:X.create(BigInt(1012))}),Z:J.create({c0:X.create(BigInt(-2)),c1:X.create(BigInt(-1))})}),X8=Ud(X,{A:X.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:X.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:X.create(BigInt(11))}),{G2psi:Kd,G2psi2:J8}=V8(X,J,J.div(J.ONE,J.NONRESIDUE)),Gc=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:X.ORDER,m:2,k:128,expand:"xmd",hash:lo}),So=Ji(X.toBytes(ot),{infinity:!0,compressed:!0});function Io(t){t=t.slice();const e=t[0]&224,n=!!(e>>7&1),r=!!(e>>6&1),i=!!(e>>5&1);return t[0]&=31,{compressed:n,infinity:r,sort:i,value:t}}function Ji(t,e){if(t[0]&224)throw new Error("setMask: non-empty mask");return e.compressed&&(t[0]|=128),e.infinity&&(t[0]|=64),e.sort&&(t[0]|=32),t}function Gd(t){t.assertValidity();const e=t.equals(Ht.G1.ProjectivePoint.ZERO),{x:n,y:r}=t.toAffine();if(e)return So.slice();const i=X.ORDER,s=!!(r*Ne/i);return Ji(Oe(n,X.BYTES),{compressed:!0,sort:s})}function Wd(t){t.assertValidity();const e=X.BYTES;if(t.equals(Ht.G2.ProjectivePoint.ZERO))return _e(So,Oe(ot,e));const{x:n,y:r}=t.toAffine(),{re:i,im:s}=J.reim(n),{re:o,im:a}=J.reim(r),u=!!((a>ot?a*Ne:o*Ne)/X.ORDER&xo),l=i;return _e(Ji(Oe(s,e),{sort:u,compressed:!0}),Oe(l,e))}const Ht=z8({fields:{Fp:X,Fp2:J,Fp6:Vc,Fp12:re,Fr:Vd},G1:{Fp:X,h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1"),a:X.ZERO,b:Xi,htfDefaults:{...Gc,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(t,e)=>{const n=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),r=new t(X.mul(e.px,n),e.py,e.pz);return e.multiplyUnsafe(Xn).negate().multiplyUnsafe(Xn).equals(r)},clearCofactor:(t,e)=>e.multiplyUnsafe(Xn).add(e),mapToCurve:t=>{const{x:e,y:n}=X8(X.create(t[0]));return Z8(e,n)},fromBytes:t=>{const{compressed:e,infinity:n,sort:r,value:i}=Io(t);if(i.length===48&&e){const s=X.ORDER,o=rt(i),a=X.create(o&X.MASK);if(n){if(a!==ot)throw new Error("G1: non-empty compressed point at infinity");return{x:ot,y:ot}}const c=X.add(X.pow(a,_o),X.create(Ht.params.G1b));let u=X.sqrt(c);if(!u)throw new Error("invalid compressed G1 point");return u*Ne/s!==BigInt(r)&&(u=X.neg(u)),{x:X.create(a),y:X.create(u)}}else if(i.length===96&&!e){const s=rt(i.subarray(0,X.BYTES)),o=rt(i.subarray(X.BYTES));if(n){if(s!==ot||o!==ot)throw new Error("G1: non-empty point at infinity");return Ht.G1.ProjectivePoint.ZERO.toAffine()}return{x:X.create(s),y:X.create(o)}}else throw new Error("invalid point G1, expected 48/96 bytes")},toBytes:(t,e,n)=>{const r=e.equals(t.ZERO),{x:i,y:s}=e.toAffine();if(n){if(r)return So.slice();const o=X.ORDER,a=!!(s*Ne/o);return Ji(Oe(i,X.BYTES),{compressed:!0,sort:a})}else return r?_e(new Uint8Array([64]),new Uint8Array(2*X.BYTES-1)):_e(Oe(i,X.BYTES),Oe(s,X.BYTES))},ShortSignature:{fromHex(t){const{infinity:e,sort:n,value:r}=Io(We("signatureHex",t,48)),i=X.ORDER,s=rt(r);if(e)return Ht.G1.ProjectivePoint.ZERO;const o=X.create(s&X.MASK),a=X.add(X.pow(o,_o),X.create(Ht.params.G1b));let c=X.sqrt(a);if(!c)throw new Error("invalid compressed G1 point");const u=BigInt(n);c*Ne/i!==u&&(c=X.neg(c));const l=Ht.G1.ProjectivePoint.fromAffine({x:o,y:c});return l.assertValidity(),l},toRawBytes(t){return Gd(t)},toHex(t){return Rr(Gd(t))}}},G2:{Fp:J,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),Gx:J.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:J.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")]),a:J.ZERO,b:J.fromBigTuple([Xi,Xi]),hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...Gc},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:t=>{const{x:e,y:n}=Y8(J.fromBigTuple(t));return W8(e,n)},isTorsionFree:(t,e)=>e.multiplyUnsafe(Xn).negate().equals(Kd(t,e)),clearCofactor:(t,e)=>{const n=Xn;let r=e.multiplyUnsafe(n).negate(),i=Kd(t,e),s=e.double();return s=J8(t,s),s=s.subtract(i),i=r.add(i),i=i.multiplyUnsafe(n).negate(),s=s.add(i),s=s.subtract(r),s.subtract(e)},fromBytes:t=>{const{compressed:e,infinity:n,sort:r,value:i}=Io(t);if(!e&&!n&&r||!e&&n&&r||r&&n&&e)throw new Error("invalid encoding flag: "+(t[0]&224));const s=X.BYTES,o=(a,c,u)=>rt(a.slice(c,u));if(i.length===96&&e){const a=Ht.params.G2b,c=X.ORDER;if(n){if(i.reduce((g,v)=>g!==0?v+1:v,0)>0)throw new Error("invalid compressed G2 point");return{x:J.ZERO,y:J.ZERO}}const u=o(i,0,s),l=o(i,s,2*s),f=J.create({c0:X.create(l),c1:X.create(u)}),d=J.add(J.pow(f,_o),a);let h=J.sqrt(d);const p=h.c1===ot?h.c0*Ne/c:h.c1*Ne/c?xo:ot;return h=r&&p>0?h:J.neg(h),{x:f,y:h}}else if(i.length===192&&!e){if(n){if(i.reduce((f,d)=>f!==0?d+1:d,0)>0)throw new Error("invalid uncompressed G2 point");return{x:J.ZERO,y:J.ZERO}}const a=o(i,0,s),c=o(i,s,2*s),u=o(i,2*s,3*s),l=o(i,3*s,4*s);return{x:J.fromBigTuple([c,a]),y:J.fromBigTuple([l,u])}}else throw new Error("invalid point G2, expected 96/192 bytes")},toBytes:(t,e,n)=>{const{BYTES:r,ORDER:i}=X,s=e.equals(t.ZERO),{x:o,y:a}=e.toAffine();if(n){if(s)return _e(So,Oe(ot,r));const c=!!(a.c1===ot?a.c0*Ne/i:a.c1*Ne/i);return _e(Ji(Oe(o.c1,r),{compressed:!0,sort:c}),Oe(o.c0,r))}else{if(s)return _e(new Uint8Array([64]),new Uint8Array(4*r-1));const{re:c,im:u}=J.reim(o),{re:l,im:f}=J.reim(a);return _e(Oe(u,r),Oe(c,r),Oe(f,r),Oe(l,r))}},Signature:{fromHex(t){const{infinity:e,sort:n,value:r}=Io(We("signatureHex",t)),i=X.ORDER,s=r.length/2;if(s!==48&&s!==96)throw new Error("invalid compressed signature length, must be 96 or 192");const o=rt(r.slice(0,s)),a=rt(r.slice(s));if(e)return Ht.G2.ProjectivePoint.ZERO;const c=X.create(o&X.MASK),u=X.create(a),l=J.create({c0:u,c1:c}),f=J.add(J.pow(l,_o),Ht.params.G2b);let d=J.sqrt(f);if(!d)throw new Error("Failed to find a square root");const{re:h,im:p}=J.reim(d),g=BigInt(n),v=p>ot&&p*Ne/i!==g,B=p===ot&&h*Ne/i!==g;(v||B)&&(d=J.neg(d));const D=Ht.G2.ProjectivePoint.fromAffine({x:l,y:d});return D.assertValidity(),D},toRawBytes(t){return Wd(t)},toHex(t){return Rr(Wd(t))}}},params:{ateLoopSize:Xn,r:Vd.ORDER,xNegative:!0,twistType:"multiplicative"},htfDefaults:Gc,hash:lo,randomBytes:Mh});BigInt(0),BigInt(1),BigInt(2),BigInt(8),BigInt(0),BigInt(1),BigInt(2),BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),BigInt(0),BigInt(1),BigInt(2),BigInt(3),BigInt(5),BigInt(8);const pi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ao(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Wc(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Fr(t,...e){if(!Ao(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 Zd(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Wc(t.outputLen),Wc(t.blockLen)}function Bo(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 Q8(t,e){Fr(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Oo(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Zc(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function nn(t,e){return t<<32-e|t>>>e}const Yd=(()=>typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function")(),ex=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function gi(t){if(Fr(t),Yd)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=ex[t[n]];return e}const Sn={_0:48,_9:57,A:65,F:70,a:97,f:102};function Xd(t){if(t>=Sn._0&&t<=Sn._9)return t-Sn._0;if(t>=Sn.A&&t<=Sn.F)return t-(Sn.A-10);if(t>=Sn.a&&t<=Sn.f)return t-(Sn.a-10)}function Do(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Yd)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=Xd(t.charCodeAt(s)),a=Xd(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)}r[i]=o*16+a}return r}function Yc(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Xc(t){return typeof t=="string"&&(t=Yc(t)),Fr(t),t}function Jn(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Fr(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}class Jd{}function tx(t){const e=r=>t().update(Xc(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Qd(t=32){if(pi&&typeof pi.getRandomValues=="function")return pi.getRandomValues(new Uint8Array(t));if(pi&&typeof pi.randomBytes=="function")return Uint8Array.from(pi.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const Jc=BigInt(0),Qc=BigInt(1);function $o(t,e=""){if(typeof t!="boolean"){const n=e&&`"${e}"`;throw new Error(n+"expected boolean, got type="+typeof t)}return t}function Lr(t,e,n=""){const r=Ao(t),i=t?.length,s=e!==void 0;if(!r||s&&i!==e){const o=n&&`"${n}" `,a=s?` of length ${e}`:"",c=r?`length=${i}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return t}function Po(t){const e=t.toString(16);return e.length&1?"0"+e:e}function ep(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Jc:BigInt("0x"+t)}function To(t){return ep(gi(t))}function tp(t){return Fr(t),ep(gi(Uint8Array.from(t).reverse()))}function eu(t,e){return Do(t.toString(16).padStart(e*2,"0"))}function np(t,e){return eu(t,e).reverse()}function pt(t,e,n){let r;if(typeof e=="string")try{r=Do(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Ao(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}const tu=t=>typeof t=="bigint"&&Jc<=t;function nx(t,e,n){return tu(t)&&tu(e)&&tu(n)&&e<=t&&t<n}function rx(t,e,n,r){if(!nx(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function rp(t){let e;for(e=0;t>Jc;t>>=Qc,e+=1);return e}const Qi=t=>(Qc<<BigInt(t))-Qc;function ix(t,e,n){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 n!="function")throw new Error("hmacFn must be a function");const r=h=>new Uint8Array(h),i=h=>Uint8Array.of(h);let s=r(t),o=r(t),a=0;const c=()=>{s.fill(1),o.fill(0),a=0},u=(...h)=>n(o,s,...h),l=(h=r(0))=>{o=u(i(0),h),s=u(),h.length!==0&&(o=u(i(1),h),s=u())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const p=[];for(;h<e;){s=u();const g=s.slice();p.push(g),h+=s.length}return Jn(...p)};return(h,p)=>{c(),l(h);let g;for(;!(g=p(f()));)l();return c(),g}}function nu(t,e,n={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function r(i,s,o){const a=t[i];if(o&&a===void 0)return;const c=typeof a;if(c!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${c}`)}Object.entries(e).forEach(([i,s])=>r(i,s,!1)),Object.entries(n).forEach(([i,s])=>r(i,s,!0))}function ip(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}const gt=BigInt(0),at=BigInt(1),kr=BigInt(2),sp=BigInt(3),op=BigInt(4),ap=BigInt(5),sx=BigInt(7),cp=BigInt(8),ox=BigInt(9),up=BigInt(16);function Vt(t,e){const n=t%e;return n>=gt?n:e+n}function Tt(t,e,n){let r=t;for(;e-- >gt;)r*=r,r%=n;return r}function lp(t,e){if(t===gt)throw new Error("invert: expected non-zero number");if(e<=gt)throw new Error("invert: expected positive modulus, got "+e);let n=Vt(t,e),r=e,i=gt,s=at;for(;n!==gt;){const a=r/n,c=r%n,u=i-s*a;r=n,n=c,i=s,s=u}if(r!==at)throw new Error("invert: does not exist");return Vt(i,e)}function ru(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function fp(t,e){const n=(t.ORDER+at)/op,r=t.pow(e,n);return ru(t,r,e),r}function ax(t,e){const n=(t.ORDER-ap)/cp,r=t.mul(e,kr),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,kr),i),a=t.mul(s,t.sub(o,t.ONE));return ru(t,a,e),a}function cx(t){const e=es(t),n=hp(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+sx)/up;return(a,c)=>{let u=a.pow(c,o),l=a.mul(u,r);const f=a.mul(u,i),d=a.mul(u,s),h=a.eql(a.sqr(l),c),p=a.eql(a.sqr(f),c);u=a.cmov(u,l,h),l=a.cmov(d,f,p);const g=a.eql(a.sqr(l),c),v=a.cmov(u,l,g);return ru(a,v,c),v}}function hp(t){if(t<sp)throw new Error("sqrt is not defined for small field");let e=t-at,n=0;for(;e%kr===gt;)e/=kr,n++;let r=kr;const i=es(t);for(;pp(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return fp;let s=i.pow(r,e);const o=(e+at)/kr;return function(c,u){if(c.is0(u))return u;if(pp(c,u)!==1)throw new Error("Cannot find square root");let l=n,f=c.mul(c.ONE,s),d=c.pow(u,e),h=c.pow(u,o);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let p=1,g=c.sqr(d);for(;!c.eql(g,c.ONE);)if(p++,g=c.sqr(g),p===l)throw new Error("Cannot find square root");const v=at<<BigInt(l-p-1),B=c.pow(f,v);l=p,f=c.sqr(B),d=c.mul(d,f),h=c.mul(h,B)}return h}}function ux(t){return t%op===sp?fp:t%cp===ap?ax:t%up===ox?cx(t):hp(t)}const lx=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function fx(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=lx.reduce((r,i)=>(r[i]="function",r),e);return nu(t,n),t}function hx(t,e,n){if(n<gt)throw new Error("invalid exponent, negatives unsupported");if(n===gt)return t.ONE;if(n===at)return e;let r=t.ONE,i=e;for(;n>gt;)n&at&&(r=t.mul(r,i)),i=t.sqr(i),n>>=at;return r}function dp(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),i=e.reduce((o,a,c)=>t.is0(a)?o:(r[c]=o,t.mul(o,a)),t.ONE),s=t.inv(i);return e.reduceRight((o,a,c)=>t.is0(a)?o:(r[c]=t.mul(o,r[c]),t.mul(o,a)),s),r}function pp(t,e){const n=(t.ORDER-at)/kr,r=t.pow(e,n),i=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),o=t.eql(r,t.neg(t.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function gp(t,e){e!==void 0&&Wc(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function es(t,e,n=!1,r={}){if(t<=gt)throw new Error("invalid field: expected ORDER > 0, got "+t);let i,s,o=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const d=e;d.BITS&&(i=d.BITS),d.sqrt&&(s=d.sqrt),typeof d.isLE=="boolean"&&(n=d.isLE),typeof d.modFromBytes=="boolean"&&(o=d.modFromBytes),a=d.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:u}=gp(t,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const f=Object.freeze({ORDER:t,isLE:n,BITS:c,BYTES:u,MASK:Qi(c),ZERO:gt,ONE:at,allowedLengths:a,create:d=>Vt(d,t),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return gt<=d&&d<t},is0:d=>d===gt,isValidNot0:d=>!f.is0(d)&&f.isValid(d),isOdd:d=>(d&at)===at,neg:d=>Vt(-d,t),eql:(d,h)=>d===h,sqr:d=>Vt(d*d,t),add:(d,h)=>Vt(d+h,t),sub:(d,h)=>Vt(d-h,t),mul:(d,h)=>Vt(d*h,t),pow:(d,h)=>hx(f,d,h),div:(d,h)=>Vt(d*lp(h,t),t),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>lp(d,t),sqrt:s||(d=>(l||(l=ux(t)),l(f,d))),toBytes:d=>n?np(d,u):eu(d,u),fromBytes:(d,h=!0)=>{if(a){if(!a.includes(d.length)||d.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);const g=new Uint8Array(u);g.set(d,n?0:g.length-d.length),d=g}if(d.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+d.length);let p=n?tp(d):To(d);if(o&&(p=Vt(p,t)),!h&&!f.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:d=>dp(f,d),cmov:(d,h,p)=>p?h:d});return Object.freeze(f)}function yp(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 bp(t){const e=yp(t);return e+Math.ceil(e/2)}function dx(t,e,n=!1){const r=t.length,i=yp(e),s=bp(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?tp(t):To(t),a=Vt(o,e-at)+at;return n?np(a,i):eu(a,i)}function px(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,u=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+u,a,r)}function gx(t,e,n){return t&e^~t&n}function yx(t,e,n){return t&e^t&n^e&n}class bx extends Jd{constructor(e,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=Zc(this.buffer)}update(e){Bo(this),e=Xc(e),Fr(e);const{view:n,buffer:r,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Zc(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Bo(this),Q8(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,Oo(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let f=o;f<i;f++)n[f]=0;px(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Zc(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 f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const Qn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),wx=Uint32Array.from([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]),er=new Uint32Array(64);class mx extends bx{constructor(e=32){super(64,e,8,!1),this.A=Qn[0]|0,this.B=Qn[1]|0,this.C=Qn[2]|0,this.D=Qn[3]|0,this.E=Qn[4]|0,this.F=Qn[5]|0,this.G=Qn[6]|0,this.H=Qn[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[e,n,r,i,s,o,a,c]}set(e,n,r,i,s,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let f=0;f<16;f++,n+=4)er[f]=e.getUint32(n,!1);for(let f=16;f<64;f++){const d=er[f-15],h=er[f-2],p=nn(d,7)^nn(d,18)^d>>>3,g=nn(h,17)^nn(h,19)^h>>>10;er[f]=g+er[f-7]+p+er[f-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=nn(a,6)^nn(a,11)^nn(a,25),h=l+d+gx(a,c,u)+wx[f]+er[f]|0,g=(nn(r,2)^nn(r,13)^nn(r,22))+yx(r,i,s)|0;l=u,u=c,c=a,a=o+h|0,o=s,s=i,i=r,r=h+g|0}r=r+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(r,i,s,o,a,c,u,l)}roundClean(){Oo(er)}destroy(){this.set(0,0,0,0,0,0,0,0),Oo(this.buffer)}}const wp=tx(()=>new mx);class mp extends Jd{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Zd(e);const r=Xc(n);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(r.length>i?e.create().update(r).digest():r);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),Oo(s)}update(e){return Bo(this),this.iHash.update(e),this}digestInto(e){Bo(this),Fr(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:n,iHash:r,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=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const vp=(t,e,n)=>new mp(t,e).update(n).digest();vp.create=(t,e)=>new mp(t,e);const yi=BigInt(0),qr=BigInt(1);function Ro(t,e){const n=e.negate();return t?n:e}function iu(t,e){const n=dp(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function Ep(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function su(t,e){Ep(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=Qi(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function xp(t,e,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(t&i),c=t>>o;a>r&&(a-=s,c+=qr);const u=e*r,l=u+Math.abs(a)-1,f=a===0,d=a<0,h=e%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:h,offsetF:u}}function vx(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function Ex(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const ou=new WeakMap,_p=new WeakMap;function au(t){return _p.get(t)||1}function Sp(t){if(t!==yi)throw new Error("invalid wNAF")}class xx{constructor(e,n){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=n}_unsafeLadder(e,n,r=this.ZERO){let i=e;for(;n>yi;)n&qr&&(r=r.add(i)),i=i.double(),n>>=qr;return r}precomputeWindow(e,n){const{windows:r,windowSize:i}=su(n,this.bits),s=[];let o=e,a=o;for(let c=0;c<r;c++){a=o,s.push(a);for(let u=1;u<i;u++)a=a.add(o),s.push(a);o=a.double()}return s}wNAF(e,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=su(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:d,offsetF:h}=xp(r,a,o);r=c,l?s=s.add(Ro(d,n[h])):i=i.add(Ro(f,n[u]))}return Sp(r),{p:i,f:s}}wNAFUnsafe(e,n,r,i=this.ZERO){const s=su(e,this.bits);for(let o=0;o<s.windows&&r!==yi;o++){const{nextN:a,offset:c,isZero:u,isNeg:l}=xp(r,o,s);if(r=a,!u){const f=n[c];i=i.add(l?f.negate():f)}}return Sp(r),i}getPrecomputes(e,n,r){let i=ou.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),ou.set(n,i))),i}cached(e,n,r){const i=au(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=au(e);return s===1?this._unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,i)}createCache(e,n){Ep(n,this.bits),_p.set(e,n),ou.delete(e)}hasCache(e){return au(e)!==1}}function _x(t,e,n,r){let i=e,s=t.ZERO,o=t.ZERO;for(;n>yi||r>yi;)n&qr&&(s=s.add(i)),r&qr&&(o=o.add(i)),i=i.double(),n>>=qr,r>>=qr;return{p1:s,p2:o}}function Sx(t,e,n,r){vx(n,t),Ex(r,e);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,a=rp(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=Qi(c),l=new Array(Number(u)+1).fill(o),f=Math.floor((e.BITS-1)/c)*c;let d=o;for(let h=f;h>=0;h-=c){l.fill(o);for(let g=0;g<s;g++){const v=r[g],B=Number(v>>BigInt(h)&u);l[B]=l[B].add(n[g])}let p=o;for(let g=l.length-1,v=o;g>0;g--)v=v.add(l[g]),p=p.add(v);if(d=d.add(p),h!==0)for(let g=0;g<c;g++)d=d.double()}return d}function Ip(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return fx(e),e}else return es(t,{isLE:n})}function Ix(t,e,n={},r){if(r===void 0&&(r=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(const c of["p","n","h"]){const u=e[c];if(!(typeof u=="bigint"&&u>yi))throw new Error(`CURVE.${c} must be positive bigint`)}const i=Ip(e.p,n.Fp,r),s=Ip(e.n,n.Fn,r),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(const c of a)if(!i.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:s}}const Ap=(t,e)=>(t+(t>=0?e:-e)/Bp)/e;function Ax(t,e,n){const[[r,i],[s,o]]=e,a=Ap(o*t,n),c=Ap(-i*t,n);let u=t-a*r-c*s,l=-a*i-c*o;const f=u<An,d=l<An;f&&(u=-u),d&&(l=-l);const h=Qi(Math.ceil(rp(n)/2))+bi;if(u<An||u>=h||l<An||l>=h)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:u,k2neg:d,k2:l}}function cu(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function uu(t,e){const n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return $o(n.lowS,"lowS"),$o(n.prehash,"prehash"),n.format!==void 0&&cu(n.format),n}class Bx extends Error{constructor(e=""){super(e)}}const In={Err:Bx,_tlv:{encode:(t,e)=>{const{Err:n}=In;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");const r=e.length/2,i=Po(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?Po(i.length/2|128):"";return Po(t)+s+i+e},decode(t,e){const{Err:n}=In;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const u=e.subarray(r,r+c);if(u.length!==c)throw new n("tlv.decode: length bytes not complete");if(u[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of u)o=o<<8|l;if(r+=c,o<128)throw new n("tlv.decode(long): not minimal encoding")}const a=e.subarray(r,r+o);if(a.length!==o)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(t){const{Err:e}=In;if(t<An)throw new e("integer: negative integers are not allowed");let n=Po(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=In;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 To(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=In,i=pt("signature",t),{v:s,l:o}=r.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,s),{v:u,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(t){const{_tlv:e,_int:n}=In,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}},An=BigInt(0),bi=BigInt(1),Bp=BigInt(2),No=BigInt(3),Ox=BigInt(4);function wi(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=pt("private key",e);try{r=t.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof e}`)}}if(!t.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function Dx(t,e={}){const n=Ix("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;nu(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=e;if(c&&(!r.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=Dp(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(E,b,m){const{x:y,y:w}=b.toAffine(),S=r.toBytes(y);if($o(m,"isCompressed"),m){l();const A=!r.isOdd(w);return Jn(Op(A),S)}else return Jn(Uint8Array.of(4),S,r.toBytes(w))}function d(E){Lr(E,void 0,"Point");const{publicKey:b,publicKeyUncompressed:m}=u,y=E.length,w=E[0],S=E.subarray(1);if(y===b&&(w===2||w===3)){const A=r.fromBytes(S);if(!r.isValid(A))throw new Error("bad point: is not on curve, wrong x");const I=g(A);let O;try{O=r.sqrt(I)}catch(C){const k=C instanceof Error?": "+C.message:"";throw new Error("bad point: is not on curve, sqrt error"+k)}l();const R=r.isOdd(O);return(w&1)===1!==R&&(O=r.neg(O)),{x:A,y:O}}else if(y===m&&w===4){const A=r.BYTES,I=r.fromBytes(S.subarray(0,A)),O=r.fromBytes(S.subarray(A,A*2));if(!v(I,O))throw new Error("bad point: is not on curve");return{x:I,y:O}}else throw new Error(`bad point: got length ${y}, expected compressed=${b} or uncompressed=${m}`)}const h=e.toBytes||f,p=e.fromBytes||d;function g(E){const b=r.sqr(E),m=r.mul(b,E);return r.add(r.add(m,r.mul(E,s.a)),s.b)}function v(E,b){const m=r.sqr(b),y=g(E);return r.eql(m,y)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const B=r.mul(r.pow(s.a,No),Ox),D=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(B,D)))throw new Error("bad curve params: a or b");function _(E,b,m=!1){if(!r.isValid(b)||m&&r.is0(b))throw new Error(`bad point coordinate ${E}`);return b}function x(E){if(!(E instanceof P))throw new Error("ProjectivePoint expected")}function $(E){if(!c||!c.basises)throw new Error("no endo");return Ax(E,c.basises,i.ORDER)}const T=ip((E,b)=>{const{X:m,Y:y,Z:w}=E;if(r.eql(w,r.ONE))return{x:m,y};const S=E.is0();b==null&&(b=S?r.ONE:r.inv(w));const A=r.mul(m,b),I=r.mul(y,b),O=r.mul(w,b);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql(O,r.ONE))throw new Error("invZ was invalid");return{x:A,y:I}}),U=ip(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.Y))return;throw new Error("bad point: ZERO")}const{x:b,y:m}=E.toAffine();if(!r.isValid(b)||!r.isValid(m))throw new Error("bad point: x or y not field elements");if(!v(b,m))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function F(E,b,m,y,w){return m=new P(r.mul(m.X,E),m.Y,m.Z),b=Ro(y,b),m=Ro(w,m),b.add(m)}class P{constructor(b,m,y){this.X=_("x",b),this.Y=_("y",m,!0),this.Z=_("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){const{x:m,y}=b||{};if(!b||!r.isValid(m)||!r.isValid(y))throw new Error("invalid affine point");if(b instanceof P)throw new Error("projective point not allowed");return r.is0(m)&&r.is0(y)?P.ZERO:new P(m,y,r.ONE)}static fromBytes(b){const m=P.fromAffine(p(Lr(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return P.fromBytes(pt("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return M.createCache(this,b),m||this.multiply(No),this}assertValidity(){U(this)}hasEvenY(){const{y:b}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(b)}equals(b){x(b);const{X:m,Y:y,Z:w}=this,{X:S,Y:A,Z:I}=b,O=r.eql(r.mul(m,I),r.mul(S,w)),R=r.eql(r.mul(y,I),r.mul(A,w));return O&&R}negate(){return new P(this.X,r.neg(this.Y),this.Z)}double(){const{a:b,b:m}=s,y=r.mul(m,No),{X:w,Y:S,Z:A}=this;let I=r.ZERO,O=r.ZERO,R=r.ZERO,L=r.mul(w,w),C=r.mul(S,S),k=r.mul(A,A),N=r.mul(w,S);return N=r.add(N,N),R=r.mul(w,A),R=r.add(R,R),I=r.mul(b,R),O=r.mul(y,k),O=r.add(I,O),I=r.sub(C,O),O=r.add(C,O),O=r.mul(I,O),I=r.mul(N,I),R=r.mul(y,R),k=r.mul(b,k),N=r.sub(L,k),N=r.mul(b,N),N=r.add(N,R),R=r.add(L,L),L=r.add(R,L),L=r.add(L,k),L=r.mul(L,N),O=r.add(O,L),k=r.mul(S,A),k=r.add(k,k),L=r.mul(k,N),I=r.sub(I,L),R=r.mul(k,C),R=r.add(R,R),R=r.add(R,R),new P(I,O,R)}add(b){x(b);const{X:m,Y:y,Z:w}=this,{X:S,Y:A,Z:I}=b;let O=r.ZERO,R=r.ZERO,L=r.ZERO;const C=s.a,k=r.mul(s.b,No);let N=r.mul(m,S),q=r.mul(y,A),j=r.mul(w,I),W=r.add(m,y),V=r.add(S,A);W=r.mul(W,V),V=r.add(N,q),W=r.sub(W,V),V=r.add(m,w);let Z=r.add(S,I);return V=r.mul(V,Z),Z=r.add(N,j),V=r.sub(V,Z),Z=r.add(y,w),O=r.add(A,I),Z=r.mul(Z,O),O=r.add(q,j),Z=r.sub(Z,O),L=r.mul(C,V),O=r.mul(k,j),L=r.add(O,L),O=r.sub(q,L),L=r.add(q,L),R=r.mul(O,L),q=r.add(N,N),q=r.add(q,N),j=r.mul(C,j),V=r.mul(k,V),q=r.add(q,j),j=r.sub(N,j),j=r.mul(C,j),V=r.add(V,j),N=r.mul(q,V),R=r.add(R,N),N=r.mul(Z,V),O=r.mul(W,O),O=r.sub(O,N),N=r.mul(W,q),L=r.mul(Z,L),L=r.add(L,N),new P(O,R,L)}subtract(b){return this.add(b.negate())}is0(){return this.equals(P.ZERO)}multiply(b){const{endo:m}=e;if(!i.isValidNot0(b))throw new Error("invalid scalar: out of range");let y,w;const S=A=>M.cached(this,A,I=>iu(P,I));if(m){const{k1neg:A,k1:I,k2neg:O,k2:R}=$(b),{p:L,f:C}=S(I),{p:k,f:N}=S(R);w=C.add(N),y=F(m.beta,L,k,A,O)}else{const{p:A,f:I}=S(b);y=A,w=I}return iu(P,[y,w])[0]}multiplyUnsafe(b){const{endo:m}=e,y=this;if(!i.isValid(b))throw new Error("invalid scalar: out of range");if(b===An||y.is0())return P.ZERO;if(b===bi)return y;if(M.hasCache(this))return this.multiply(b);if(m){const{k1neg:w,k1:S,k2neg:A,k2:I}=$(b),{p1:O,p2:R}=_x(P,y,S,I);return F(m.beta,O,R,w,A)}else return M.unsafe(y,b)}multiplyAndAddUnsafe(b,m,y){const w=this.multiplyUnsafe(m).add(b.multiplyUnsafe(y));return w.is0()?void 0:w}toAffine(b){return T(this,b)}isTorsionFree(){const{isTorsionFree:b}=e;return o===bi?!0:b?b(P,this):M.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:b}=e;return o===bi?this:b?b(P,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(b=!0){return $o(b,"isCompressed"),this.assertValidity(),h(P,this,b)}toHex(b=!0){return gi(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return iu(P,b)}static msm(b,m){return Sx(P,i,b,m)}static fromPrivateKey(b){return P.BASE.multiply(wi(i,b))}}P.BASE=new P(s.Gx,s.Gy,r.ONE),P.ZERO=new P(r.ZERO,r.ONE,r.ZERO),P.Fp=r,P.Fn=i;const z=i.BITS,M=new xx(P,e.endo?Math.ceil(z/2):z);return P.BASE.precompute(8),P}function Op(t){return Uint8Array.of(t?2:3)}function Dp(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function $x(t,e={}){const{Fn:n}=t,r=e.randomBytes||Qd,i=Object.assign(Dp(t.Fp,n),{seed:bp(n.ORDER)});function s(h){try{return!!wi(n,h)}catch{return!1}}function o(h,p){const{publicKey:g,publicKeyUncompressed:v}=i;try{const B=h.length;return p===!0&&B!==g||p===!1&&B!==v?!1:!!t.fromBytes(h)}catch{return!1}}function a(h=r(i.seed)){return dx(Lr(h,i.seed,"seed"),n.ORDER)}function c(h,p=!0){return t.BASE.multiply(wi(n,h)).toBytes(p)}function u(h){const p=a(h);return{secretKey:p,publicKey:c(p)}}function l(h){if(typeof h=="bigint")return!1;if(h instanceof t)return!0;const{secretKey:p,publicKey:g,publicKeyUncompressed:v}=i;if(n.allowedLengths||p===g)return;const B=pt("key",h).length;return B===g||B===v}function f(h,p,g=!0){if(l(h)===!0)throw new Error("first arg must be private key");if(l(p)===!1)throw new Error("second arg must be public key");const v=wi(n,h);return t.fromHex(p).multiply(v).toBytes(g)}return Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:u,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:h=>wi(n,h),precompute(h=8,p=t.BASE){return p.precompute(h,!1)}},lengths:i})}function Px(t,e,n={}){Zd(e),nu(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Qd,i=n.hmac||((m,...y)=>vp(e,m,Jn(...y))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h}=$x(t,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function v(m){const y=a>>bi;return m>y}function B(m,y){if(!o.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function D(m,y){cu(y);const w=h.signature,S=y==="compact"?w:y==="recovered"?w+1:void 0;return Lr(m,S,`${y} signature`)}class _{constructor(y,w,S){this.r=B("r",y),this.s=B("s",w),S!=null&&(this.recovery=S),Object.freeze(this)}static fromBytes(y,w=g){D(y,w);let S;if(w==="der"){const{r:R,s:L}=In.toSig(Lr(y));return new _(R,L)}w==="recovered"&&(S=y[0],w="compact",y=y.subarray(1));const A=o.BYTES,I=y.subarray(0,A),O=y.subarray(A,A*2);return new _(o.fromBytes(I),o.fromBytes(O),S)}static fromHex(y,w){return this.fromBytes(Do(y),w)}addRecoveryBit(y){return new _(this.r,this.s,y)}recoverPublicKey(y){const w=s.ORDER,{r:S,s:A,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*Bp<w&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");const R=I===2||I===3?S+a:S;if(!s.isValid(R))throw new Error("recovery id 2 or 3 invalid");const L=s.toBytes(R),C=t.fromBytes(Jn(Op((I&1)===0),L)),k=o.inv(R),N=$(pt("msgHash",y)),q=o.create(-N*k),j=o.create(A*k),W=t.BASE.multiplyUnsafe(q).add(C.multiplyUnsafe(j));if(W.is0())throw new Error("point at infinify");return W.assertValidity(),W}hasHighS(){return v(this.s)}toBytes(y=g){if(cu(y),y==="der")return Do(In.hexFromSig(this));const w=o.toBytes(this.r),S=o.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Jn(Uint8Array.of(this.recovery),w,S)}return Jn(w,S)}toHex(y){return gi(this.toBytes(y))}assertValidity(){}static fromCompact(y){return _.fromBytes(pt("sig",y),"compact")}static fromDER(y){return _.fromBytes(pt("sig",y),"der")}normalizeS(){return this.hasHighS()?new _(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return gi(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return gi(this.toBytes("compact"))}}const x=n.bits2int||function(y){if(y.length>8192)throw new Error("input is too large");const w=To(y),S=y.length*8-c;return S>0?w>>BigInt(S):w},$=n.bits2int_modN||function(y){return o.create(x(y))},T=Qi(c);function U(m){return rx("num < 2^"+c,m,An,T),o.toBytes(m)}function F(m,y){return Lr(m,void 0,"message"),y?Lr(e(m),void 0,"prehashed message"):m}function P(m,y,w){if(["recovered","canonical"].some(q=>q in w))throw new Error("sign() legacy options not supported");const{lowS:S,prehash:A,extraEntropy:I}=uu(w,p);m=F(m,A);const O=$(m),R=wi(o,y),L=[U(R),U(O)];if(I!=null&&I!==!1){const q=I===!0?r(h.secretKey):I;L.push(pt("extraEntropy",q))}const C=Jn(...L),k=O;function N(q){const j=x(q);if(!o.isValidNot0(j))return;const W=o.inv(j),V=t.BASE.multiply(j).toAffine(),Z=o.create(V.x);if(Z===An)return;const Q=o.create(W*o.create(k+Z*R));if(Q===An)return;let ee=(V.x===Z?0:2)|Number(V.y&bi),ie=Q;return S&&v(Q)&&(ie=o.neg(Q),ee^=1),new _(Z,ie,ee)}return{seed:C,k2sig:N}}function z(m,y,w={}){m=pt("message",m);const{seed:S,k2sig:A}=P(m,y,w);return ix(e.outputLen,o.BYTES,i)(S,A)}function M(m){let y;const w=typeof m=="string"||Ao(m),S=!w&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!w&&!S)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(S)y=new _(m.r,m.s);else if(w){try{y=_.fromBytes(pt("sig",m),"der")}catch(A){if(!(A instanceof In.Err))throw A}if(!y)try{y=_.fromBytes(pt("sig",m),"compact")}catch{return!1}}return y||!1}function E(m,y,w,S={}){const{lowS:A,prehash:I,format:O}=uu(S,p);if(w=pt("publicKey",w),y=F(pt("message",y),I),"strict"in S)throw new Error("options.strict was renamed to lowS");const R=O===void 0?M(m):_.fromBytes(pt("sig",m),O);if(R===!1)return!1;try{const L=t.fromBytes(w);if(A&&R.hasHighS())return!1;const{r:C,s:k}=R,N=$(y),q=o.inv(k),j=o.create(N*q),W=o.create(C*q),V=t.BASE.multiplyUnsafe(j).add(L.multiplyUnsafe(W));return V.is0()?!1:o.create(V.x)===C}catch{return!1}}function b(m,y,w={}){const{prehash:S}=uu(w,p);return y=F(y,S),_.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h,Point:t,sign:z,verify:E,recoverPublicKey:b,Signature:_,hash:e})}function Tx(t){const e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},n=t.Fp;let r=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0;const i=es(e.n,{BITS:t.nBitLength,allowedLengths:r,modFromBytes:t.wrapPrivateKey}),s={Fp:n,Fn:i,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function Rx(t){const{CURVE:e,curveOpts:n}=Tx(t),r={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:n,hash:t.hash,ecdsaOpts:r}}function Nx(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,gp(n.Fn.ORDER,n.Fn.BITS))})}function Cx(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=Rx(t),s=Dx(e,n),o=Px(s,r,i);return Nx(t,o)}function Ux(t,e){const n=r=>Cx({...t,hash:r});return{...n(e),create:n}}Yc("HashToScalar-");const lu={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Fx={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},$p=BigInt(2);function Lx(t){const e=lu.p,n=BigInt(3),r=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,f=Tt(l,n,e)*l%e,d=Tt(f,n,e)*l%e,h=Tt(d,$p,e)*u%e,p=Tt(h,i,e)*h%e,g=Tt(p,s,e)*p%e,v=Tt(g,a,e)*g%e,B=Tt(v,c,e)*v%e,D=Tt(B,a,e)*g%e,_=Tt(D,n,e)*l%e,x=Tt(_,o,e)*p%e,$=Tt(x,r,e)*u%e,T=Tt($,$p,e);if(!fu.eql(fu.sqr(T),t))throw new Error("Cannot find square root");return T}const fu=es(lu.p,{sqrt:Lx});Ux({...lu,Fp:fu,lowS:!0,endo:Fx},wp);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function mi(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function hu(t,...e){if(!mi(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 Pp(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(n=>typeof n=="string"):e.every(n=>Number.isSafeInteger(n)):!1}function du(t){if(typeof t!="function")throw new Error("function expected");return!0}function tr(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function vi(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Co(t){if(!Array.isArray(t))throw new Error("array expected")}function Uo(t,e){if(!Pp(!0,e))throw new Error(`${t}: array of strings expected`)}function pu(t,e){if(!Pp(!1,e))throw new Error(`${t}: array of numbers expected`)}function yt(...t){const e=s=>s,n=(s,o)=>a=>s(o(a)),r=t.map(s=>s.encode).reduceRight(n,e),i=t.map(s=>s.decode).reduce(n,e);return{encode:r,decode:i}}function St(t){const e=typeof t=="string"?t.split(""):t,n=e.length;Uo("alphabet",e);const r=new Map(e.map((i,s)=>[i,s]));return{encode:i=>(Co(i),i.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);return e[s]})),decode:i=>(Co(i),i.map(s=>{tr("alphabet.decode",s);const o=r.get(s);if(o===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return o}))}}function It(t=""){return tr("join",t),{encode:e=>(Uo("join.decode",e),e.join(t)),decode:e=>(tr("join.decode",e),e.split(t))}}function Fo(t,e="="){return vi(t),tr("padding",e),{encode(n){for(Uo("padding.encode",n);n.length*t%8;)n.push(e);return n},decode(n){Uo("padding.decode",n);let r=n.length;if(r*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if((r-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return n.slice(0,r)}}}function Tp(t){return du(t),{encode:e=>e,decode:e=>t(e)}}function Rp(t,e,n){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(Co(t),!t.length)return[];let r=0;const i=[],s=Array.from(t,a=>{if(vi(a),a<0||a>=e)throw new Error(`invalid integer: ${a}`);return a}),o=s.length;for(;;){let a=0,c=!0;for(let u=r;u<o;u++){const l=s[u],f=e*a,d=f+l;if(!Number.isSafeInteger(d)||f/e!==a||d-l!==f)throw new Error("convertRadix: carry overflow");const h=d/n;a=d%n;const p=Math.floor(h);if(s[u]=p,!Number.isSafeInteger(p)||p*n+a!==d)throw new Error("convertRadix: carry overflow");if(c)p?c=!1:r=u;else continue}if(i.push(a),c)break}for(let a=0;a<t.length-1&&t[a]===0;a++)i.push(0);return i.reverse()}const Np=(t,e)=>e===0?t:Np(e,t%e),Lo=(t,e)=>t+(e-Np(t,e)),ko=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function gu(t,e,n,r){if(Co(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Lo(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Lo(e,n)}`);let i=0,s=0;const o=ko[e],a=ko[n]-1,c=[];for(const u of t){if(vi(u),u>=o)throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);if(i=i<<e|u,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=n;s-=n)c.push((i>>s-n&a)>>>0);const l=ko[s];if(l===void 0)throw new Error("invalid carry");i&=l-1}if(i=i<<n-s&a,!r&&s>=e)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&c.push(i>>>0),c}function kx(t){vi(t);const e=2**8;return{encode:n=>{if(!mi(n))throw new Error("radix.encode input should be Uint8Array");return Rp(Array.from(n),e,t)},decode:n=>(pu("radix.decode",n),Uint8Array.from(Rp(n,t,e)))}}function Rt(t,e=!1){if(vi(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Lo(8,t)>32||Lo(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!mi(n))throw new Error("radix2.encode input should be Uint8Array");return gu(Array.from(n),8,t,!e)},decode:n=>(pu("radix2.decode",n),Uint8Array.from(gu(n,t,8,e)))}}function Cp(t){return du(t),function(...e){try{return t.apply(null,e)}catch{}}}function qx(t,e){return vi(t),du(e),{encode(n){if(!mi(n))throw new Error("checksum.encode: input should be Uint8Array");const r=e(n).slice(0,t),i=new Uint8Array(n.length+t);return i.set(n),i.set(r,n.length),i},decode(n){if(!mi(n))throw new Error("checksum.decode: input should be Uint8Array");const r=n.slice(0,-t),i=n.slice(-t),s=e(r).slice(0,t);for(let o=0;o<t;o++)if(s[o]!==i[o])throw new Error("Invalid checksum");return r}}}yt(Rt(4),St("0123456789ABCDEF"),It(""));const Mx=yt(Rt(5),St("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Fo(5),It(""));yt(Rt(5),St("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),It("")),yt(Rt(5),St("0123456789ABCDEFGHIJKLMNOPQRSTUV"),Fo(5),It("")),yt(Rt(5),St("0123456789ABCDEFGHIJKLMNOPQRSTUV"),It("")),yt(Rt(5),St("0123456789ABCDEFGHJKMNPQRSTVWXYZ"),It(""),Tp(t=>t.toUpperCase().replace(/O/g,"0").replace(/[IL]/g,"1")));const Up=(()=>typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function")(),Fp=(t,e)=>{tr("base64",t);const n=e?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=e?"base64url":"base64";if(t.length>0&&!n.test(t))throw new Error("invalid base64");return Uint8Array.fromBase64(t,{alphabet:r,lastChunkHandling:"strict"})};Up||yt(Rt(6),St("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),Fo(6),It("")),yt(Rt(6),St("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"),It("")),Up||yt(Rt(6),St("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),Fo(6),It("")),yt(Rt(6),St("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"),It(""));const yu=t=>yt(kx(58),St(t),It("")),jx=yu("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");yu("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),yu("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const zx=t=>yt(qx(4,e=>t(t(e))),jx),bu=yt(St("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),It("")),Lp=[996825010,642813549,513874426,1027748829,705979059];function ts(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<Lp.length;r++)(e>>r&1)===1&&(n^=Lp[r]);return n}function kp(t,e,n=1){const r=t.length;let i=1;for(let s=0;s<r;s++){const o=t.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${t})`);i=ts(i)^o>>5}i=ts(i);for(let s=0;s<r;s++)i=ts(i)^t.charCodeAt(s)&31;for(let s of e)i=ts(i)^s;for(let s=0;s<6;s++)i=ts(i);return i^=n,bu.encode(gu([i%ko[30]],30,5,!1))}function qp(t){const e=t==="bech32"?1:734539939,n=Rt(5),r=n.decode,i=n.encode,s=Cp(r);function o(f,d,h=90){tr("bech32.encode prefix",f),mi(d)&&(d=Array.from(d)),pu("bech32.encode",d);const p=f.length;if(p===0)throw new TypeError(`Invalid prefix length ${p}`);const g=p+7+d.length;if(h!==!1&&g>h)throw new TypeError(`Length ${g} exceeds limit ${h}`);const v=f.toLowerCase(),B=kp(v,d,e);return`${v}1${bu.encode(d)}${B}`}function a(f,d=90){tr("bech32.decode input",f);const h=f.length;if(h<8||d!==!1&&h>d)throw new TypeError(`invalid string length: ${h} (${f}). Expected (8..${d})`);const p=f.toLowerCase();if(f!==p&&f!==f.toUpperCase())throw new Error("String must be lowercase or uppercase");const g=p.lastIndexOf("1");if(g===0||g===-1)throw new Error('Letter "1" must be present between prefix and data only');const v=p.slice(0,g),B=p.slice(g+1);if(B.length<6)throw new Error("Data must be at least 6 characters long");const D=bu.decode(B).slice(0,-6),_=kp(v,D,e);if(!B.endsWith(_))throw new Error(`Invalid checksum in ${f}: expected "${_}"`);return{prefix:v,words:D}}const c=Cp(a);function u(f){const{prefix:d,words:h}=a(f,!1);return{prefix:d,words:h,bytes:r(h)}}function l(f,d){return o(f,i(d))}return{encode:o,decode:a,encodeFromBytes:l,decodeToBytes:u,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:s,toWords:i}}qp("bech32"),qp("bech32m");const Hx=(()=>typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function")(),Vx={encode(t){return hu(t),t.toHex()},decode(t){return tr("hex",t),Uint8Array.fromHex(t)}};Hx||yt(Rt(4),St("0123456789abcdef"),It(""),Tp(t=>{if(typeof t!="string"||t.length%2!==0)throw new TypeError(`hex.decode: expected string, got ${typeof t} with length ${t.length}`);return t.toLowerCase()})),zx(wp),Yc("Bitcoin seed");function Kx(t){return i8(Gx(t))}function Gx(t){const{payload:e,signature:n}=t,{r,s:i,yParity:s}=n,a=new C8.Signature(BigInt(r),BigInt(i)).addRecoveryBit(s).recoverPublicKey(Bc(e).substring(2));return ZE(a)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function Mp(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function qo(t,...e){if(!Mp(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 Mo(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 jp(t,e){qo(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function ns(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function wu(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Wx(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Zx(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function rs(t){if(typeof t=="string")t=Zx(t);else if(Mp(t))t=zp(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function zp(t){return Uint8Array.from(t)}const Bn=16,mu=new Uint8Array(16),rn=ns(mu),Yx=225,Xx=(t,e,n,r)=>{const i=r&1;return{s3:n<<31|r>>>1,s2:e<<31|n>>>1,s1:t<<31|e>>>1,s0:t>>>1^Yx<<24&-(i&1)}},Nt=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255|0;function Jx(t){t.reverse();const e=t[15]&1;let n=0;for(let r=0;r<t.length;r++){const i=t[r];t[r]=i>>>1|n,n=(i&1)<<7}return t[0]^=-e&225,t}const Qx=t=>t>64*1024?8:t>1024?4:2;class Hp{constructor(e,n){this.blockLen=Bn,this.outputLen=Bn,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=rs(e),qo(e,16);const r=Wx(e);let i=r.getUint32(0,!1),s=r.getUint32(4,!1),o=r.getUint32(8,!1),a=r.getUint32(12,!1);const c=[];for(let p=0;p<128;p++)c.push({s0:Nt(i),s1:Nt(s),s2:Nt(o),s3:Nt(a)}),{s0:i,s1:s,s2:o,s3:a}=Xx(i,s,o,a);const u=Qx(n||1024);if(![1,2,4,8].includes(u))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=u;const f=128/u,d=this.windowSize=2**u,h=[];for(let p=0;p<f;p++)for(let g=0;g<d;g++){let v=0,B=0,D=0,_=0;for(let x=0;x<u;x++){if(!(g>>>u-x-1&1))continue;const{s0:T,s1:U,s2:F,s3:P}=c[u*p+x];v^=T,B^=U,D^=F,_^=P}h.push({s0:v,s1:B,s2:D,s3:_})}this.t=h}_updateBlock(e,n,r,i){e^=this.s0,n^=this.s1,r^=this.s2,i^=this.s3;const{W:s,t:o,windowSize:a}=this;let c=0,u=0,l=0,f=0;const d=(1<<s)-1;let h=0;for(const p of[e,n,r,i])for(let g=0;g<4;g++){const v=p>>>8*g&255;for(let B=8/s-1;B>=0;B--){const D=v>>>s*B&d,{s0:_,s1:x,s2:$,s3:T}=o[h*a+D];c^=_,u^=x,l^=$,f^=T,h+=1}}this.s0=c,this.s1=u,this.s2=l,this.s3=f}update(e){Mo(this),e=rs(e),qo(e);const n=ns(e),r=Math.floor(e.length/Bn),i=e.length%Bn;for(let s=0;s<r;s++)this._updateBlock(n[s*4+0],n[s*4+1],n[s*4+2],n[s*4+3]);return i&&(mu.set(e.subarray(r*Bn)),this._updateBlock(rn[0],rn[1],rn[2],rn[3]),wu(rn)),this}destroy(){const{t:e}=this;for(const n of e)n.s0=0,n.s1=0,n.s2=0,n.s3=0}digestInto(e){Mo(this),jp(e,this),this.finished=!0;const{s0:n,s1:r,s2:i,s3:s}=this,o=ns(e);return o[0]=n,o[1]=r,o[2]=i,o[3]=s,e}digest(){const e=new Uint8Array(Bn);return this.digestInto(e),this.destroy(),e}}class e6 extends Hp{constructor(e,n){e=rs(e),qo(e);const r=Jx(zp(e));super(r,n),wu(r)}update(e){e=rs(e),Mo(this);const n=ns(e),r=e.length%Bn,i=Math.floor(e.length/Bn);for(let s=0;s<i;s++)this._updateBlock(Nt(n[s*4+3]),Nt(n[s*4+2]),Nt(n[s*4+1]),Nt(n[s*4+0]));return r&&(mu.set(e.subarray(i*Bn)),this._updateBlock(Nt(rn[3]),Nt(rn[2]),Nt(rn[1]),Nt(rn[0])),wu(rn)),this}digestInto(e){Mo(this),jp(e,this),this.finished=!0;const{s0:n,s1:r,s2:i,s3:s}=this,o=ns(e);return o[0]=n,o[1]=r,o[2]=i,o[3]=s,e.reverse()}}function Vp(t){const e=(r,i)=>t(i,r.length).update(rs(r)).digest(),n=t(new Uint8Array(16),0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=(r,i)=>t(r,i),e}Vp((t,e)=>new Hp(t,e)),Vp((t,e)=>new e6(t,e));const Kp=Wn(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),t6=Kp.create(BigInt("-3")),n6=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");vo({a:t6,b:n6,Fp:Kp,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},lo);const Gp=Wn(BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff")),r6=Gp.create(BigInt("-3")),i6=BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef");vo({a:r6,b:i6,Fp:Gp,n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"),h:BigInt(1),lowS:!1},mE);const Wp=Wn(BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),s6=Wp.create(BigInt("-3")),o6=BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00");vo({a:s6,b:o6,Fp:Wp,n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650"),h:BigInt(1),lowS:!1,allowedPrivateKeyLengths:[130,131,132]},wE);var a6={exports:{}};(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(c,u,l){this.fn=c,this.context=u,this.once=l||!1}function s(c,u,l,f,d){if(typeof l!="function")throw new TypeError("The listener must be a function");var h=new i(l,f||c,d),p=n?n+u:u;return c._events[p]?c._events[p].fn?c._events[p]=[c._events[p],h]:c._events[p].push(h):(c._events[p]=h,c._eventsCount++),c}function o(c,u){--c._eventsCount===0?c._events=new r:delete c._events[u]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var u=[],l,f;if(this._eventsCount===0)return u;for(f in l=this._events)e.call(l,f)&&u.push(n?f.slice(1):f);return Object.getOwnPropertySymbols?u.concat(Object.getOwnPropertySymbols(l)):u},a.prototype.listeners=function(u){var l=n?n+u:u,f=this._events[l];if(!f)return[];if(f.fn)return[f.fn];for(var d=0,h=f.length,p=new Array(h);d<h;d++)p[d]=f[d].fn;return p},a.prototype.listenerCount=function(u){var l=n?n+u:u,f=this._events[l];return f?f.fn?1:f.length:0},a.prototype.emit=function(u,l,f,d,h,p){var g=n?n+u:u;if(!this._events[g])return!1;var v=this._events[g],B=arguments.length,D,_;if(v.fn){switch(v.once&&this.removeListener(u,v.fn,void 0,!0),B){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,l),!0;case 3:return v.fn.call(v.context,l,f),!0;case 4:return v.fn.call(v.context,l,f,d),!0;case 5:return v.fn.call(v.context,l,f,d,h),!0;case 6:return v.fn.call(v.context,l,f,d,h,p),!0}for(_=1,D=new Array(B-1);_<B;_++)D[_-1]=arguments[_];v.fn.apply(v.context,D)}else{var x=v.length,$;for(_=0;_<x;_++)switch(v[_].once&&this.removeListener(u,v[_].fn,void 0,!0),B){case 1:v[_].fn.call(v[_].context);break;case 2:v[_].fn.call(v[_].context,l);break;case 3:v[_].fn.call(v[_].context,l,f);break;case 4:v[_].fn.call(v[_].context,l,f,d);break;default:if(!D)for($=1,D=new Array(B-1);$<B;$++)D[$-1]=arguments[$];v[_].fn.apply(v[_].context,D)}}return!0},a.prototype.on=function(u,l,f){return s(this,u,l,f,!1)},a.prototype.once=function(u,l,f){return s(this,u,l,f,!0)},a.prototype.removeListener=function(u,l,f,d){var h=n?n+u:u;if(!this._events[h])return this;if(!l)return o(this,h),this;var p=this._events[h];if(p.fn)p.fn===l&&(!d||p.once)&&(!f||p.context===f)&&o(this,h);else{for(var g=0,v=[],B=p.length;g<B;g++)(p[g].fn!==l||d&&!p[g].once||f&&p[g].context!==f)&&v.push(p[g]);v.length?this._events[h]=v.length===1?v[0]:v:o(this,h)}return this},a.prototype.removeAllListeners=function(u){var l;return u?(l=n?n+u:u,this._events[l]&&o(this,l)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a})(a6);function c6(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),f=l.charCodeAt(0);if(e[f]!==255)throw new TypeError(l+" is ambiguous");e[f]=u}const n=t.length,r=t.charAt(0),i=Math.log(n)/Math.log(256),s=Math.log(256)/Math.log(n);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,f=0,d=0;const h=u.length;for(;d!==h&&u[d]===0;)d++,l++;const p=(h-d)*s+1>>>0,g=new Uint8Array(p);for(;d!==h;){let D=u[d],_=0;for(let x=p-1;(D!==0||_<f)&&x!==-1;x--,_++)D+=256*g[x]>>>0,g[x]=D%n>>>0,D=D/n>>>0;if(D!==0)throw new Error("Non-zero carry");f=_,d++}let v=p-f;for(;v!==p&&g[v]===0;)v++;let B=r.repeat(l);for(;v<p;++v)B+=t.charAt(g[v]);return B}function a(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;let l=0,f=0,d=0;for(;u[l]===r;)f++,l++;const h=(u.length-l)*i+1>>>0,p=new Uint8Array(h);for(;l<u.length;){const D=u.charCodeAt(l);if(D>255)return;let _=e[D];if(_===255)return;let x=0;for(let $=h-1;(_!==0||x<d)&&$!==-1;$--,x++)_+=n*p[$]>>>0,p[$]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");d=x,l++}let g=h-d;for(;g!==h&&p[g]===0;)g++;const v=new Uint8Array(f+(h-g));let B=f;for(;g!==h;)v[B++]=p[g++];return v}function c(u){const l=a(u);if(l)return l;throw new Error("Non-base"+n+" character")}return{encode:o,decodeUnsafe:a,decode:c}}var u6="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",is=c6(u6);function l6(t){const e=t.length;let n=0,r=0;for(;r<e;){let i=t.charCodeAt(r++);if(i&4294967168)if(!(i&4294965248))n+=2;else{if(i>=55296&&i<=56319&&r<e){const s=t.charCodeAt(r);(s&64512)===56320&&(++r,i=((i&1023)<<10)+(s&1023)+65536)}i&4294901760?n+=4:n+=3}else{n++;continue}}return n}function f6(t,e,n){const r=t.length;let i=n,s=0;for(;s<r;){let o=t.charCodeAt(s++);if(o&4294967168)if(!(o&4294965248))e[i++]=o>>6&31|192;else{if(o>=55296&&o<=56319&&s<r){const a=t.charCodeAt(s);(a&64512)===56320&&(++s,o=((o&1023)<<10)+(a&1023)+65536)}o&4294901760?(e[i++]=o>>18&7|240,e[i++]=o>>12&63|128,e[i++]=o>>6&63|128):(e[i++]=o>>12&15|224,e[i++]=o>>6&63|128)}else{e[i++]=o;continue}e[i++]=o&63|128}}const h6=new TextEncoder,d6=50;function p6(t,e,n){h6.encodeInto(t,e.subarray(n))}function g6(t,e,n){t.length>d6?p6(t,e,n):f6(t,e,n)}const y6=4096;function Zp(t,e,n){let r=e;const i=r+n,s=[];let o="";for(;r<i;){const a=t[r++];if(!(a&128))s.push(a);else if((a&224)===192){const c=t[r++]&63;s.push((a&31)<<6|c)}else if((a&240)===224){const c=t[r++]&63,u=t[r++]&63;s.push((a&31)<<12|c<<6|u)}else if((a&248)===240){const c=t[r++]&63,u=t[r++]&63,l=t[r++]&63;let f=(a&7)<<18|c<<12|u<<6|l;f>65535&&(f-=65536,s.push(f>>>10&1023|55296),f=56320|f&1023),s.push(f)}else s.push(a);s.length>=y6&&(o+=String.fromCharCode(...s),s.length=0)}return s.length>0&&(o+=String.fromCharCode(...s)),o}const b6=new TextDecoder,w6=200;function m6(t,e,n){const r=t.subarray(e,e+n);return b6.decode(r)}function v6(t,e,n){return n>w6?m6(t,e,n):Zp(t,e,n)}class jo{constructor(e,n){this.type=e,this.data=n}}class At extends Error{constructor(e){super(e);const n=Object.create(At.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:At.name})}}const ss=4294967295;function E6(t,e,n){const r=n/4294967296,i=n;t.setUint32(e,r),t.setUint32(e+4,i)}function Yp(t,e,n){const r=Math.floor(n/4294967296),i=n;t.setUint32(e,r),t.setUint32(e+4,i)}function Xp(t,e){const n=t.getInt32(e),r=t.getUint32(e+4);return n*4294967296+r}function x6(t,e){const n=t.getUint32(e),r=t.getUint32(e+4);return n*4294967296+r}const _6=-1,S6=4294967296-1,I6=17179869184-1;function A6({sec:t,nsec:e}){if(t>=0&&e>=0&&t<=I6)if(e===0&&t<=S6){const n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,t),n}else{const n=t/4294967296,r=t&4294967295,i=new Uint8Array(8),s=new DataView(i.buffer);return s.setUint32(0,e<<2|n&3),s.setUint32(4,r),i}else{const n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,e),Yp(r,4,t),n}}function B6(t){const e=t.getTime(),n=Math.floor(e/1e3),r=(e-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function O6(t){if(t instanceof Date){const e=B6(t);return A6(e)}else return null}function D6(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(t.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{const n=e.getUint32(0),r=e.getUint32(4),i=(n&3)*4294967296+r,s=n>>>2;return{sec:i,nsec:s}}case 12:{const n=Xp(e,4),r=e.getUint32(0);return{sec:n,nsec:r}}default:throw new At(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${t.length}`)}}function $6(t){const e=D6(t);return new Date(e.sec*1e3+e.nsec/1e6)}const P6={type:_6,encode:O6,decode:$6};class zo{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(P6)}register({type:e,encode:n,decode:r}){if(e>=0)this.encoders[e]=n,this.decoders[e]=r;else{const i=-1-e;this.builtInEncoders[i]=n,this.builtInDecoders[i]=r}}tryToEncode(e,n){for(let r=0;r<this.builtInEncoders.length;r++){const i=this.builtInEncoders[r];if(i!=null){const s=i(e,n);if(s!=null){const o=-1-r;return new jo(o,s)}}}for(let r=0;r<this.encoders.length;r++){const i=this.encoders[r];if(i!=null){const s=i(e,n);if(s!=null){const o=r;return new jo(o,s)}}}return e instanceof jo?e:null}decode(e,n,r){const i=n<0?this.builtInDecoders[-1-n]:this.decoders[n];return i?i(e,n,r):new jo(n,e)}}zo.defaultCodec=new zo;function T6(t){return t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer}function vu(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):T6(t)?new Uint8Array(t):Uint8Array.from(t)}const R6=100,N6=2048;class Eu{constructor(e){this.entered=!1,this.extensionCodec=e?.extensionCodec??zo.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??R6,this.initialBufferSize=e?.initialBufferSize??N6,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new Eu({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,n){if(n>this.maxDepth)throw new Error(`Too deep objects in depth ${n}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,n)}ensureBufferSizeToWrite(e){const n=this.pos+e;this.view.byteLength<n&&this.resizeBuffer(n*2)}resizeBuffer(e){const n=new ArrayBuffer(e),r=new Uint8Array(n),i=new DataView(n);r.set(this.bytes),this.view=i,this.bytes=r}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){const r=l6(e);this.ensureBufferSizeToWrite(5+r),this.writeStringHeader(r),g6(e,this.bytes,this.pos),this.pos+=r}encodeObject(e,n){const r=this.extensionCodec.tryToEncode(e,this.context);if(r!=null)this.encodeExtension(r);else if(Array.isArray(e))this.encodeArray(e,n);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,n);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){const n=e.byteLength;if(n<256)this.writeU8(196),this.writeU8(n);else if(n<65536)this.writeU8(197),this.writeU16(n);else if(n<4294967296)this.writeU8(198),this.writeU32(n);else throw new Error(`Too large binary: ${n}`);const r=vu(e);this.writeU8a(r)}encodeArray(e,n){const r=e.length;if(r<16)this.writeU8(144+r);else if(r<65536)this.writeU8(220),this.writeU16(r);else if(r<4294967296)this.writeU8(221),this.writeU32(r);else throw new Error(`Too large array: ${r}`);for(const i of e)this.doEncode(i,n+1)}countWithoutUndefined(e,n){let r=0;for(const i of n)e[i]!==void 0&&r++;return r}encodeMap(e,n){const r=Object.keys(e);this.sortKeys&&r.sort();const i=this.ignoreUndefined?this.countWithoutUndefined(e,r):r.length;if(i<16)this.writeU8(128+i);else if(i<65536)this.writeU8(222),this.writeU16(i);else if(i<4294967296)this.writeU8(223),this.writeU32(i);else throw new Error(`Too large map object: ${i}`);for(const s of r){const o=e[s];this.ignoreUndefined&&o===void 0||(this.encodeString(s),this.doEncode(o,n+1))}}encodeExtension(e){if(typeof e.data=="function"){const r=e.data(this.pos+6),i=r.length;if(i>=4294967296)throw new Error(`Too large extension object: ${i}`);this.writeU8(201),this.writeU32(i),this.writeI8(e.type),this.writeU8a(r);return}const n=e.data.length;if(n===1)this.writeU8(212);else if(n===2)this.writeU8(213);else if(n===4)this.writeU8(214);else if(n===8)this.writeU8(215);else if(n===16)this.writeU8(216);else if(n<256)this.writeU8(199),this.writeU8(n);else if(n<65536)this.writeU8(200),this.writeU16(n);else if(n<4294967296)this.writeU8(201),this.writeU32(n);else throw new Error(`Too large extension object: ${n}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){const n=e.length;this.ensureBufferSizeToWrite(n),this.bytes.set(e,this.pos),this.pos+=n}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),E6(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),Yp(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}}function C6(t,e){return new Eu(e).encodeSharedRef(t)}function xu(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}const U6=16,F6=16;class L6{constructor(e=U6,n=F6){this.hit=0,this.miss=0,this.maxKeyLength=e,this.maxLengthPerKey=n,this.caches=[];for(let r=0;r<this.maxKeyLength;r++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,n,r){const i=this.caches[r-1];e:for(const s of i){const o=s.bytes;for(let a=0;a<r;a++)if(o[a]!==e[n+a])continue e;return s.str}return null}store(e,n){const r=this.caches[e.length-1],i={bytes:e,str:n};r.length>=this.maxLengthPerKey?r[Math.random()*r.length|0]=i:r.push(i)}decode(e,n,r){const i=this.find(e,n,r);if(i!=null)return this.hit++,i;this.miss++;const s=Zp(e,n,r),o=Uint8Array.prototype.slice.call(e,n,n+r);return this.store(o,s),s}}const _u="array",os="map_key",Jp="map_value",k6=t=>{if(typeof t=="string"||typeof t=="number")return t;throw new At("The type of key must be string or number but "+typeof t)};class q6{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){const n=this.getUninitializedStateFromPool();n.type=_u,n.position=0,n.size=e,n.array=new Array(e)}pushMapState(e){const n=this.getUninitializedStateFromPool();n.type=os,n.readCount=0,n.size=e,n.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){const e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===_u){const r=e;r.size=0,r.array=void 0,r.position=0,r.type=void 0}if(e.type===os||e.type===Jp){const r=e;r.size=0,r.map=void 0,r.readCount=0,r.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}const as=-1,Su=new DataView(new ArrayBuffer(0)),M6=new Uint8Array(Su.buffer);try{Su.getInt8(0)}catch(t){if(!(t instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}const Qp=new RangeError("Insufficient data"),j6=new L6;class Iu{constructor(e){this.totalPos=0,this.pos=0,this.view=Su,this.bytes=M6,this.headByte=as,this.stack=new q6,this.entered=!1,this.extensionCodec=e?.extensionCodec??zo.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??ss,this.maxBinLength=e?.maxBinLength??ss,this.maxArrayLength=e?.maxArrayLength??ss,this.maxMapLength=e?.maxMapLength??ss,this.maxExtLength=e?.maxExtLength??ss,this.keyDecoder=e?.keyDecoder!==void 0?e.keyDecoder:j6,this.mapKeyConverter=e?.mapKeyConverter??k6}clone(){return new Iu({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=as,this.stack.reset()}setBuffer(e){const n=vu(e);this.bytes=n,this.view=new DataView(n.buffer,n.byteOffset,n.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===as&&!this.hasRemaining(1))this.setBuffer(e);else{const n=this.bytes.subarray(this.pos),r=vu(e),i=new Uint8Array(n.length+r.length);i.set(n),i.set(r,n.length),this.setBuffer(i)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){const{view:n,pos:r}=this;return new RangeError(`Extra ${n.byteLength-r} of ${n.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);const n=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return n}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let n=!1,r;for await(const a of e){if(n)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(a);try{r=this.doDecodeSync(),n=!0}catch(c){if(!(c instanceof RangeError))throw c}this.totalPos+=this.pos}if(n){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return r}const{headByte:i,pos:s,totalPos:o}=this;throw new RangeError(`Insufficient data in parsing ${xu(i)} at ${o} (${s} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,n){if(this.entered){yield*this.clone().decodeMultiAsync(e,n);return}try{this.entered=!0;let r=n,i=-1;for await(const s of e){if(n&&i===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(s),r&&(i=this.readArraySize(),r=!1,this.complete());try{for(;yield this.doDecodeSync(),--i!==0;);}catch(o){if(!(o instanceof RangeError))throw o}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){const e=this.readHeadByte();let n;if(e>=224)n=e-256;else if(e<192)if(e<128)n=e;else if(e<144){const i=e-128;if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e<160){const i=e-144;if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else{const i=e-160;n=this.decodeString(i,0)}else if(e===192)n=null;else if(e===194)n=!1;else if(e===195)n=!0;else if(e===202)n=this.readF32();else if(e===203)n=this.readF64();else if(e===204)n=this.readU8();else if(e===205)n=this.readU16();else if(e===206)n=this.readU32();else if(e===207)this.useBigInt64?n=this.readU64AsBigInt():n=this.readU64();else if(e===208)n=this.readI8();else if(e===209)n=this.readI16();else if(e===210)n=this.readI32();else if(e===211)this.useBigInt64?n=this.readI64AsBigInt():n=this.readI64();else if(e===217){const i=this.lookU8();n=this.decodeString(i,1)}else if(e===218){const i=this.lookU16();n=this.decodeString(i,2)}else if(e===219){const i=this.lookU32();n=this.decodeString(i,4)}else if(e===220){const i=this.readU16();if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else if(e===221){const i=this.readU32();if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else if(e===222){const i=this.readU16();if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e===223){const i=this.readU32();if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e===196){const i=this.lookU8();n=this.decodeBinary(i,1)}else if(e===197){const i=this.lookU16();n=this.decodeBinary(i,2)}else if(e===198){const i=this.lookU32();n=this.decodeBinary(i,4)}else if(e===212)n=this.decodeExtension(1,0);else if(e===213)n=this.decodeExtension(2,0);else if(e===214)n=this.decodeExtension(4,0);else if(e===215)n=this.decodeExtension(8,0);else if(e===216)n=this.decodeExtension(16,0);else if(e===199){const i=this.lookU8();n=this.decodeExtension(i,1)}else if(e===200){const i=this.lookU16();n=this.decodeExtension(i,2)}else if(e===201){const i=this.lookU32();n=this.decodeExtension(i,4)}else throw new At(`Unrecognized type byte: ${xu(e)}`);this.complete();const r=this.stack;for(;r.length>0;){const i=r.top();if(i.type===_u)if(i.array[i.position]=n,i.position++,i.position===i.size)n=i.array,r.release(i);else continue e;else if(i.type===os){if(n==="__proto__")throw new At("The key __proto__ is not allowed");i.key=this.mapKeyConverter(n),i.type=Jp;continue e}else if(i.map[i.key]=n,i.readCount++,i.readCount===i.size)n=i.map,r.release(i);else{i.key=null,i.type=os;continue e}}return n}}readHeadByte(){return this.headByte===as&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=as}readArraySize(){const e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new At(`Unrecognized array type byte: ${xu(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new At(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new At(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,n){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,n):this.decodeBinary(e,n)}decodeUtf8String(e,n){if(e>this.maxStrLength)throw new At(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+n+e)throw Qp;const r=this.pos+n;let i;return this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?i=this.keyDecoder.decode(this.bytes,r,e):i=v6(this.bytes,r,e),this.pos+=n+e,i}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===os:!1}decodeBinary(e,n){if(e>this.maxBinLength)throw new At(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+n))throw Qp;const r=this.pos+n,i=this.bytes.subarray(r,r+e);return this.pos+=n+e,i}decodeExtension(e,n){if(e>this.maxExtLength)throw new At(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);const r=this.view.getInt8(this.pos+n),i=this.decodeBinary(e,n+1);return this.extensionCodec.decode(i,r,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){const e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){const e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){const e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){const e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){const e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){const e=x6(this.view,this.pos);return this.pos+=8,e}readI64(){const e=Xp(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){const e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){const e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){const e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){const e=this.view.getFloat64(this.pos);return this.pos+=8,e}}function z6(t,e){return new Iu(e).decode(t)}function Au(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function e0(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Au(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function cs(t,e){e||(e=t.reduce((i,s)=>i+s.length,0));const n=e0(e);let r=0;for(const i of t)n.set(i,r),r+=i.length;return Au(n)}function H6(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[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 f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,v=0,B=0,D=p.length;B!==D&&p[B]===0;)B++,g++;for(var _=(D-B)*l+1>>>0,x=new Uint8Array(_);B!==D;){for(var $=p[B],T=0,U=_-1;($!==0||T<v)&&U!==-1;U--,T++)$+=256*x[U]>>>0,x[U]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");v=T,B++}for(var F=_-v;F!==_&&x[F]===0;)F++;for(var P=c.repeat(g);F<_;++F)P+=t.charAt(x[F]);return P}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var v=0,B=0;p[g]===c;)v++,g++;for(var D=(p.length-g)*u+1>>>0,_=new Uint8Array(D);p[g];){var x=n[p.charCodeAt(g)];if(x===255)return;for(var $=0,T=D-1;(x!==0||$<B)&&T!==-1;T--,$++)x+=a*_[T]>>>0,_[T]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");B=$,g++}if(p[g]!==" "){for(var U=D-B;U!==D&&_[U]===0;)U++;for(var F=new Uint8Array(v+(D-U)),P=v;U!==D;)F[P++]=_[U++];return F}}}function h(p){var g=d(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:h}}var V6=H6,K6=V6;const t0=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")},G6=t=>new TextEncoder().encode(t),W6=t=>new TextDecoder().decode(t);class Z6{constructor(e,n,r){this.name=e,this.prefix=n,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class Y6{constructor(e,n,r){if(this.name=e,this.prefix=n,n.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=n.codePointAt(0),this.baseDecode=r}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 n0(this,e)}}class X6{constructor(e){this.decoders=e}or(e){return n0(this,e)}decode(e){const n=e[0],r=this.decoders[n];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const n0=(t,e)=>new X6({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class J6{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new Z6(e,n,r),this.decoder=new Y6(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Ho=({name:t,prefix:e,encode:n,decode:r})=>new J6(t,e,n,r),us=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=K6(n,e);return Ho({prefix:t,name:e,encode:r,decode:s=>t0(i(s))})},Q6=(t,e,n,r)=>{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*n/8|0);let a=0,c=0,u=0;for(let l=0;l<s;++l){const f=i[t[l]];if(f===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<n|f,a+=n,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=n||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},e4=(t,e,n)=>{const r=e[e.length-1]==="=",i=(1<<n)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>n;)o-=n,s+=e[i&a>>o];if(o&&(s+=e[i&a<<n-o]),r)for(;s.length*n&7;)s+="=";return s},Le=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>Ho({prefix:e,name:t,encode(i){return e4(i,r,n)},decode(i){return Q6(i,r,n,t)}}),t4=Ho({prefix:"\0",name:"identity",encode:t=>W6(t),decode:t=>G6(t)});var n4=Object.freeze({__proto__:null,identity:t4});const r4=Le({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var i4=Object.freeze({__proto__:null,base2:r4});const s4=Le({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var o4=Object.freeze({__proto__:null,base8:s4});const a4=us({prefix:"9",name:"base10",alphabet:"0123456789"});var c4=Object.freeze({__proto__:null,base10:a4});const u4=Le({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),l4=Le({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var f4=Object.freeze({__proto__:null,base16:u4,base16upper:l4});const h4=Le({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),d4=Le({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),p4=Le({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),g4=Le({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),y4=Le({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),b4=Le({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),w4=Le({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),m4=Le({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),v4=Le({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var E4=Object.freeze({__proto__:null,base32:h4,base32upper:d4,base32pad:p4,base32padupper:g4,base32hex:y4,base32hexupper:b4,base32hexpad:w4,base32hexpadupper:m4,base32z:v4});const x4=us({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),_4=us({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var S4=Object.freeze({__proto__:null,base36:x4,base36upper:_4});const I4=us({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),A4=us({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var B4=Object.freeze({__proto__:null,base58btc:I4,base58flickr:A4});const O4=Le({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),D4=Le({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),$4=Le({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),P4=Le({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var T4=Object.freeze({__proto__:null,base64:O4,base64pad:D4,base64url:$4,base64urlpad:P4});const r0=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}"),R4=r0.reduce((t,e,n)=>(t[n]=e,t),[]),N4=r0.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function C4(t){return t.reduce((e,n)=>(e+=R4[n],e),"")}function U4(t){const e=[];for(const n of t){const r=N4[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const F4=Ho({prefix:"\u{1F680}",name:"base256emoji",encode:C4,decode:U4});var L4=Object.freeze({__proto__:null,base256emoji:F4}),k4=s0,i0=128,q4=127,M4=~q4,j4=Math.pow(2,31);function s0(t,e,n){e=e||[],n=n||0;for(var r=n;t>=j4;)e[n++]=t&255|i0,t/=128;for(;t&M4;)e[n++]=t&255|i0,t>>>=7;return e[n]=t|0,s0.bytes=n-r+1,e}var z4=Bu,H4=128,o0=127;function Bu(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw Bu.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&o0)<<i:(o&o0)*Math.pow(2,i),i+=7}while(o>=H4);return Bu.bytes=s-r,n}var V4=Math.pow(2,7),K4=Math.pow(2,14),G4=Math.pow(2,21),W4=Math.pow(2,28),Z4=Math.pow(2,35),Y4=Math.pow(2,42),X4=Math.pow(2,49),J4=Math.pow(2,56),Q4=Math.pow(2,63),e_=function(t){return t<V4?1:t<K4?2:t<G4?3:t<W4?4:t<Z4?5:t<Y4?6:t<X4?7:t<J4?8:t<Q4?9:10},t_={encode:k4,decode:z4,encodingLength:e_},a0=t_;const c0=(t,e,n=0)=>(a0.encode(t,e,n),e),u0=t=>a0.encodingLength(t),Ou=(t,e)=>{const n=e.byteLength,r=u0(t),i=r+u0(n),s=new Uint8Array(i+n);return c0(t,s,0),c0(n,s,r),s.set(e,i),new n_(t,n,e,s)};class n_{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const l0=({name:t,code:e,encode:n})=>new r_(t,e,n);class r_{constructor(e,n,r){this.name=e,this.code=n,this.encode=r}digest(e){if(e instanceof Uint8Array){const n=this.encode(e);return n instanceof Uint8Array?Ou(this.code,n):n.then(r=>Ou(this.code,r))}else throw Error("Unknown type, must be binary type")}}const f0=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),i_=l0({name:"sha2-256",code:18,encode:f0("SHA-256")}),s_=l0({name:"sha2-512",code:19,encode:f0("SHA-512")});var o_=Object.freeze({__proto__:null,sha256:i_,sha512:s_});const h0=0,a_="identity",d0=t0;var c_=Object.freeze({__proto__:null,identity:{code:h0,name:a_,encode:d0,digest:t=>Ou(h0,d0(t))}});new TextEncoder,new TextDecoder;const p0={...n4,...i4,...o4,...c4,...f4,...E4,...S4,...B4,...T4,...L4};({...o_,...c_});function g0(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const y0=g0("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Du=g0("ascii","a",t=>{let e="a";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e},t=>{t=t.substring(1);const e=e0(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),b0={utf8:y0,"utf-8":y0,hex:p0.base16,latin1:Du,ascii:Du,binary:Du,...p0};function Ct(t,e="utf8"){const n=b0[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Au(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}function bt(t,e="utf8"){const n=b0[e];if(!n)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"):n.encoder.encode(t).substring(1)}const u_={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"}},l_="Input must be an string, Buffer or Uint8Array";function f_(t){let e;if(t instanceof Uint8Array)e=t;else if(typeof t=="string")e=new TextEncoder().encode(t);else throw new Error(l_);return e}function h_(t){return Array.prototype.map.call(t,function(e){return(e<16?"0":"")+e.toString(16)}).join("")}function Vo(t){return(4294967296+t).toString(16).substring(1)}function d_(t,e,n){let r=`
17
- `+t+" = ";for(let i=0;i<e.length;i+=2){if(n===32)r+=Vo(e[i]).toUpperCase(),r+=" ",r+=Vo(e[i+1]).toUpperCase();else if(n===64)r+=Vo(e[i+1]).toUpperCase(),r+=Vo(e[i]).toUpperCase();else throw new Error("Invalid size "+n);i%6===4?r+=`
18
- `+new Array(t.length+4).join(" "):i<e.length-2&&(r+=" ")}console.log(r)}function p_(t,e,n){let r=new Date().getTime();const i=new Uint8Array(e);for(let o=0;o<e;o++)i[o]=o%256;const s=new Date().getTime();console.log("Generated random input in "+(s-r)+"ms"),r=s;for(let o=0;o<n;o++){const a=t(i),c=new Date().getTime(),u=c-r;r=c,console.log("Hashed in "+u+"ms: "+a.substring(0,20)+"..."),console.log(Math.round(e/(1<<20)/(u/1e3)*100)/100+" MB PER SECOND")}}var w0={normalizeInput:f_,toHex:h_,debugPrint:d_,testSpeed:p_};const Ko=w0;function Go(t,e,n){const r=t[e]+t[n];let i=t[e+1]+t[n+1];r>=4294967296&&i++,t[e]=r,t[e+1]=i}function m0(t,e,n,r){let i=t[e]+n;n<0&&(i+=4294967296);let s=t[e+1]+r;i>=4294967296&&s++,t[e]=i,t[e+1]=s}function v0(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function nr(t,e,n,r,i,s){const o=ls[i],a=ls[i+1],c=ls[s],u=ls[s+1];Go(te,t,e),m0(te,t,o,a);let l=te[r]^te[t],f=te[r+1]^te[t+1];te[r]=f,te[r+1]=l,Go(te,n,r),l=te[e]^te[n],f=te[e+1]^te[n+1],te[e]=l>>>24^f<<8,te[e+1]=f>>>24^l<<8,Go(te,t,e),m0(te,t,c,u),l=te[r]^te[t],f=te[r+1]^te[t+1],te[r]=l>>>16^f<<16,te[r+1]=f>>>16^l<<16,Go(te,n,r),l=te[e]^te[n],f=te[e+1]^te[n+1],te[e]=f>>>31^l<<1,te[e+1]=l>>>31^f<<1}const E0=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),g_=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3],Ze=new Uint8Array(g_.map(function(t){return t*2})),te=new Uint32Array(32),ls=new Uint32Array(32);function x0(t,e){let n=0;for(n=0;n<16;n++)te[n]=t.h[n],te[n+16]=E0[n];for(te[24]=te[24]^t.t,te[25]=te[25]^t.t/4294967296,e&&(te[28]=~te[28],te[29]=~te[29]),n=0;n<32;n++)ls[n]=v0(t.b,4*n);for(n=0;n<12;n++)nr(0,8,16,24,Ze[n*16+0],Ze[n*16+1]),nr(2,10,18,26,Ze[n*16+2],Ze[n*16+3]),nr(4,12,20,28,Ze[n*16+4],Ze[n*16+5]),nr(6,14,22,30,Ze[n*16+6],Ze[n*16+7]),nr(0,10,20,30,Ze[n*16+8],Ze[n*16+9]),nr(2,12,22,24,Ze[n*16+10],Ze[n*16+11]),nr(4,14,16,26,Ze[n*16+12],Ze[n*16+13]),nr(6,8,18,28,Ze[n*16+14],Ze[n*16+15]);for(n=0;n<16;n++)t.h[n]=t.h[n]^te[n]^te[n+16]}const rr=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);function _0(t,e,n,r){if(t===0||t>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(e&&e.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");if(n&&n.length!==16)throw new Error("Illegal salt, expected Uint8Array with length is 16");if(r&&r.length!==16)throw new Error("Illegal personal, expected Uint8Array with length is 16");const i={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:t};rr.fill(0),rr[0]=t,e&&(rr[1]=e.length),rr[2]=1,rr[3]=1,n&&rr.set(n,32),r&&rr.set(r,48);for(let s=0;s<16;s++)i.h[s]=E0[s]^v0(rr,s*4);return e&&($u(i,e),i.c=128),i}function $u(t,e){for(let n=0;n<e.length;n++)t.c===128&&(t.t+=t.c,x0(t,!1),t.c=0),t.b[t.c++]=e[n]}function S0(t){for(t.t+=t.c;t.c<128;)t.b[t.c++]=0;x0(t,!0);const e=new Uint8Array(t.outlen);for(let n=0;n<t.outlen;n++)e[n]=t.h[n>>2]>>8*(n&3);return e}function I0(t,e,n,r,i){n=n||64,t=Ko.normalizeInput(t),r&&(r=Ko.normalizeInput(r)),i&&(i=Ko.normalizeInput(i));const s=_0(n,e,r,i);return $u(s,t),S0(s)}function y_(t,e,n,r,i){const s=I0(t,e,n,r,i);return Ko.toHex(s)}var b_={blake2b:I0,blake2bHex:y_,blake2bInit:_0,blake2bUpdate:$u,blake2bFinal:S0};const A0=w0;function w_(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function ir(t,e,n,r,i,s){ae[t]=ae[t]+ae[e]+i,ae[r]=Wo(ae[r]^ae[t],16),ae[n]=ae[n]+ae[r],ae[e]=Wo(ae[e]^ae[n],12),ae[t]=ae[t]+ae[e]+s,ae[r]=Wo(ae[r]^ae[t],8),ae[n]=ae[n]+ae[r],ae[e]=Wo(ae[e]^ae[n],7)}function Wo(t,e){return t>>>e^t<<32-e}const B0=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Ye=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),ae=new Uint32Array(16),ke=new Uint32Array(16);function O0(t,e){let n=0;for(n=0;n<8;n++)ae[n]=t.h[n],ae[n+8]=B0[n];for(ae[12]^=t.t,ae[13]^=t.t/4294967296,e&&(ae[14]=~ae[14]),n=0;n<16;n++)ke[n]=w_(t.b,4*n);for(n=0;n<10;n++)ir(0,4,8,12,ke[Ye[n*16+0]],ke[Ye[n*16+1]]),ir(1,5,9,13,ke[Ye[n*16+2]],ke[Ye[n*16+3]]),ir(2,6,10,14,ke[Ye[n*16+4]],ke[Ye[n*16+5]]),ir(3,7,11,15,ke[Ye[n*16+6]],ke[Ye[n*16+7]]),ir(0,5,10,15,ke[Ye[n*16+8]],ke[Ye[n*16+9]]),ir(1,6,11,12,ke[Ye[n*16+10]],ke[Ye[n*16+11]]),ir(2,7,8,13,ke[Ye[n*16+12]],ke[Ye[n*16+13]]),ir(3,4,9,14,ke[Ye[n*16+14]],ke[Ye[n*16+15]]);for(n=0;n<8;n++)t.h[n]^=ae[n]^ae[n+8]}function D0(t,e){if(!(t>0&&t<=32))throw new Error("Incorrect output length, should be in [1, 32]");const n=e?e.length:0;if(e&&!(n>0&&n<=32))throw new Error("Incorrect key length, should be in [1, 32]");const r={h:new Uint32Array(B0),b:new Uint8Array(64),c:0,t:0,outlen:t};return r.h[0]^=16842752^n<<8^t,n>0&&(Pu(r,e),r.c=64),r}function Pu(t,e){for(let n=0;n<e.length;n++)t.c===64&&(t.t+=t.c,O0(t,!1),t.c=0),t.b[t.c++]=e[n]}function $0(t){for(t.t+=t.c;t.c<64;)t.b[t.c++]=0;O0(t,!0);const e=new Uint8Array(t.outlen);for(let n=0;n<t.outlen;n++)e[n]=t.h[n>>2]>>8*(n&3)&255;return e}function P0(t,e,n){n=n||32,t=A0.normalizeInput(t);const r=D0(n,e);return Pu(r,t),$0(r)}function m_(t,e,n){const r=P0(t,e,n);return A0.toHex(r)}var v_={blake2s:P0,blake2sHex:m_,blake2sInit:D0,blake2sUpdate:Pu,blake2sFinal:$0};const fs=b_,hs=v_;var E_={blake2b:fs.blake2b,blake2bHex:fs.blake2bHex,blake2bInit:fs.blake2bInit,blake2bUpdate:fs.blake2bUpdate,blake2bFinal:fs.blake2bFinal,blake2s:hs.blake2s,blake2sHex:hs.blake2sHex,blake2sInit:hs.blake2sInit,blake2sUpdate:hs.blake2sUpdate,blake2sFinal:hs.blake2sFinal};const x_=":";function Zo(t){const[e,n]=t.split(x_);return{namespace:e,reference:n}}function T0(t,e){return t.includes(":")?[t]:e.chains||[]}var __=Object.defineProperty,S_=Object.defineProperties,I_=Object.getOwnPropertyDescriptors,R0=Object.getOwnPropertySymbols,A_=Object.prototype.hasOwnProperty,B_=Object.prototype.propertyIsEnumerable,Tu=(t,e,n)=>e in t?__(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,N0=(t,e)=>{for(var n in e||(e={}))A_.call(e,n)&&Tu(t,n,e[n]);if(R0)for(var n of R0(e))B_.call(e,n)&&Tu(t,n,e[n]);return t},O_=(t,e)=>S_(t,I_(e)),C0=(t,e,n)=>Tu(t,typeof e!="symbol"?e+"":e,n);const D_="ReactNative",Bt={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},$_="js";function Yo(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function sr(){return!Pr()&&!!dc()&&navigator.product===D_}function P_(){return sr()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function T_(){return sr()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function Ei(){return!Yo()&&!!dc()&&!!Pr()}function ds(){return sr()?Bt.reactNative:Yo()?Bt.node:Ei()?Bt.browser:Bt.unknown}function U0(){var t;try{return sr()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(t=global.Application)==null?void 0:t.applicationId:void 0}catch{return}}function R_(t,e){const n=new URLSearchParams(t);return Object.entries(e).sort(([r],[i])=>r.localeCompare(i)).forEach(([r,i])=>{i!=null&&n.set(r,String(i))}),n.toString()}function N_(t){var e,n;const r=F0();try{return t!=null&&t.url&&r.url&&new URL(t.url).host!==new URL(r.url).host&&(console.warn(`The configured WalletConnect 'metadata.url':${t.url} differs from the actual page url:${r.url}. This is probably unintended and can lead to issues.`),t.url=r.url),(e=t?.icons)!=null&&e.length&&t.icons.length>0&&(t.icons=t.icons.filter(i=>i!=="")),O_(N0(N0({},r),t),{url:t?.url||r.url,name:t?.name||r.name,description:t?.description||r.description,icons:(n=t?.icons)!=null&&n.length&&t.icons.length>0?t.icons:r.icons})}catch(i){return console.warn("Error populating app metadata",i),t||r}}function F0(){return Uh()||{name:"",description:"",url:"",icons:[""]}}function C_(){if(ds()===Bt.reactNative&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"){const{OS:n,Version:r}=global.Platform;return[n,r].join("-")}const t=b3();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 U_(){var t;const e=ds();return e===Bt.browser?[e,((t=Ch())==null?void 0:t.host)||"unknown"].join(":"):e}function L0(t,e,n){const r=C_(),i=U_();return[[t,e].join("-"),[$_,n].join("-"),r,i].join("/")}function F_({protocol:t,version:e,relayUrl:n,sdkVersion:r,auth:i,projectId:s,useOnCloseEvent:o,bundleId:a,packageName:c}){const u=n.split("?"),l=L0(t,e,r),f={auth:i,ua:l,projectId:s,useOnCloseEvent:o||void 0,packageName:c||void 0,bundleId:a||void 0},d=R_(u[1]||"",f);return u[0]+"?"+d}function Mr(t,e){return t.filter(n=>e.includes(n)).length===t.length}function Ru(t){return Object.fromEntries(t.entries())}function Nu(t){return new Map(Object.entries(t))}function jr(t=K.FIVE_MINUTES,e){const n=K.toMiliseconds(t||K.FIVE_MINUTES);let r,i,s,o;return{resolve:a=>{s&&r&&(clearTimeout(s),r(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)},n),r=a,i=c})}}function sn(t,e,n){return new Promise(async(r,i)=>{const s=setTimeout(()=>i(new Error(n)),e);try{const o=await t;r(o)}catch(o){i(o)}clearTimeout(s)})}function k0(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 L_(t){return k0("topic",t)}function k_(t){return k0("id",t)}function q0(t){const[e,n]=t.split(":"),r={id:void 0,topic:void 0};if(e==="topic"&&typeof n=="string")r.topic=n;else if(e==="id"&&Number.isInteger(Number(n)))r.id=Number(n);else throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${n}`);return r}function De(t,e){return K.fromMiliseconds((e||Date.now())+K.toMiliseconds(t))}function or(t){return Date.now()>=K.toMiliseconds(t)}function le(t,e){return`${t}${e?`:${e}`:""}`}function zr(t=[],e=[]){return[...new Set([...t,...e])]}async function q_({id:t,topic:e,wcDeepLink:n}){var r;try{if(!n)return;const i=typeof n=="string"?JSON.parse(n):n,s=i?.href;if(typeof s!="string")return;const o=M_(s,t,e),a=ds();if(a===Bt.browser){if(!((r=Pr())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}j_(o)}else a===Bt.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(o)}catch(i){console.error(i)}}function M_(t,e,n){const r=`requestId=${e}&sessionTopic=${n}`;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}${K_(r,!0)}`}else i=`${i}/wc?${r}`;return i}function j_(t){let e="_self";V_()?e="_top":(H_()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function z_(t,e){let n="";try{if(Ei()&&(n=localStorage.getItem(e),n))return n;n=await t.getItem(e)}catch(r){console.error(r)}return n}function M0(t,e){if(!t.includes(e))return null;const n=t.split(/([&,?,=])/),r=n.indexOf(e);return n[r+2]}function j0(){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 Cu(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function H_(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function V_(){try{return window.self!==window.top}catch{return!1}}function K_(t,e=!1){const n=Buffer.from(t).toString("base64");return e?n.replace(/[=]/g,""):n}function z0(t){return Buffer.from(t,"base64").toString("utf-8")}function G_(t){return new Promise(e=>setTimeout(e,t))}class W_{constructor({limit:e}){C0(this,"limit"),C0(this,"set"),this.limit=e,this.set=new Set}add(e){if(!this.set.has(e)){if(this.set.size>=this.limit){const n=this.set.values().next().value;n&&this.set.delete(n)}this.set.add(e)}}has(e){return this.set.has(e)}}const Xo=BigInt(2**32-1),H0=BigInt(32);function V0(t,e=!1){return e?{h:Number(t&Xo),l:Number(t>>H0&Xo)}:{h:Number(t>>H0&Xo)|0,l:Number(t&Xo)|0}}function K0(t,e=!1){const n=t.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:a}=V0(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const G0=(t,e,n)=>t>>>n,W0=(t,e,n)=>t<<32-n|e>>>n,ar=(t,e,n)=>t>>>n|e<<32-n,cr=(t,e,n)=>t<<32-n|e>>>n,ps=(t,e,n)=>t<<64-n|e>>>n-32,gs=(t,e,n)=>t>>>n-32|e<<64-n,Z_=(t,e)=>e,Y_=(t,e)=>t,X_=(t,e,n)=>t<<n|e>>>32-n,J_=(t,e,n)=>e<<n|t>>>32-n,Q_=(t,e,n)=>e<<n-32|t>>>64-n,e5=(t,e,n)=>t<<n-32|e>>>64-n;function Kt(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const Uu=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Fu=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,t5=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),n5=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,r5=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),i5=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,xi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Jo(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function On(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Gt(t,...e){if(!Jo(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 Qo(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");On(t.outputLen),On(t.blockLen)}function ur(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 Lu(t,e){Gt(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function ys(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Ut(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ku(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function on(t,e){return t<<32-e|t>>>e}const Z0=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Y0(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}const Dn=Z0?t=>t:t=>Y0(t);function s5(t){for(let e=0;e<t.length;e++)t[e]=Y0(t[e]);return t}const lr=Z0?t=>t:s5,X0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",o5=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function _i(t){if(Gt(t),X0)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=o5[t[n]];return e}const $n={_0:48,_9:57,A:65,F:70,a:97,f:102};function J0(t){if(t>=$n._0&&t<=$n._9)return t-$n._0;if(t>=$n.A&&t<=$n.F)return t-($n.A-10);if(t>=$n.a&&t<=$n.f)return t-($n.a-10)}function ea(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(X0)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=J0(t.charCodeAt(s)),a=J0(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)}r[i]=o*16+a}return r}function Q0(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Wt(t){return typeof t=="string"&&(t=Q0(t)),Gt(t),t}function fr(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Gt(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}class ta{}function bs(t){const e=r=>t().update(Wt(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function a5(t){const e=(r,i)=>t(i).update(Wt(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Hr(t=32){if(xi&&typeof xi.getRandomValues=="function")return xi.getRandomValues(new Uint8Array(t));if(xi&&typeof xi.randomBytes=="function")return Uint8Array.from(xi.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const c5=BigInt(0),ws=BigInt(1),u5=BigInt(2),l5=BigInt(7),f5=BigInt(256),h5=BigInt(113),eg=[],tg=[],ng=[];for(let t=0,e=ws,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],eg.push(2*(5*r+n)),tg.push((t+1)*(t+2)/2%64);let i=c5;for(let s=0;s<7;s++)e=(e<<ws^(e>>l5)*h5)%f5,e&u5&&(i^=ws<<(ws<<BigInt(s))-ws);ng.push(i)}const rg=K0(ng,!0),d5=rg[0],p5=rg[1],ig=(t,e,n)=>n>32?Q_(t,e,n):X_(t,e,n),sg=(t,e,n)=>n>32?e5(t,e,n):J_(t,e,n);function g5(t,e=24){const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let o=0;o<10;o++)n[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=n[c],l=n[c+1],f=ig(u,l,1)^n[a],d=sg(u,l,1)^n[a+1];for(let h=0;h<50;h+=10)t[o+h]^=f,t[o+h+1]^=d}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=tg[o],c=ig(i,s,a),u=sg(i,s,a),l=eg[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++)n[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~n[(a+2)%10]&n[(a+4)%10]}t[0]^=d5[r],t[1]^=p5[r]}Ut(n)}class qu extends ta{constructor(e,n,r,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=s,On(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=ys(this.state)}clone(){return this._cloneInto()}keccak(){lr(this.state32),g5(this.state32,this.rounds),lr(this.state32),this.posOut=0,this.pos=0}update(e){ur(this),e=Wt(e),Gt(e);const{blockLen:n,state:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(n-this.pos,i-s);for(let a=0;a<o;a++)r[this.pos++]^=e[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:n,pos:r,blockLen:i}=this;e[r]^=n,n&128&&r===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){ur(this,!1),Gt(e),this.finish();const n=this.state,{blockLen:r}=this;for(let i=0,s=e.length;i<s;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,s-i);e.set(n.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 On(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Lu(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,Ut(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new qu(n,r,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=r,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}}const y5=(t,e,n)=>bs(()=>new qu(e,t,n)),b5=y5(1,136,256/8);function w5(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,u=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+u,a,r)}function m5(t,e,n){return t&e^~t&n}function v5(t,e,n){return t&e^t&n^e&n}class og extends ta{constructor(e,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=ku(this.buffer)}update(e){ur(this),e=Wt(e),Gt(e);const{view:n,buffer:r,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=ku(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ur(this),Lu(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,Ut(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let f=o;f<i;f++)n[f]=0;w5(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=ku(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 f=0;f<u;f++)a.setUint32(4*f,l[f],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const hr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Xe=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Je=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),E5=Uint32Array.from([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]),dr=new Uint32Array(64);class x5 extends og{constructor(e=32){super(64,e,8,!1),this.A=hr[0]|0,this.B=hr[1]|0,this.C=hr[2]|0,this.D=hr[3]|0,this.E=hr[4]|0,this.F=hr[5]|0,this.G=hr[6]|0,this.H=hr[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[e,n,r,i,s,o,a,c]}set(e,n,r,i,s,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let f=0;f<16;f++,n+=4)dr[f]=e.getUint32(n,!1);for(let f=16;f<64;f++){const d=dr[f-15],h=dr[f-2],p=on(d,7)^on(d,18)^d>>>3,g=on(h,17)^on(h,19)^h>>>10;dr[f]=g+dr[f-7]+p+dr[f-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const d=on(a,6)^on(a,11)^on(a,25),h=l+d+m5(a,c,u)+E5[f]+dr[f]|0,p=(on(r,2)^on(r,13)^on(r,22))+v5(r,i,s)|0;l=u,u=c,c=a,a=o+h|0,o=s,s=i,i=r,r=h+p|0}r=r+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(r,i,s,o,a,c,u,l)}roundClean(){Ut(dr)}destroy(){this.set(0,0,0,0,0,0,0,0),Ut(this.buffer)}}const ag=K0(["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))),_5=ag[0],S5=ag[1],pr=new Uint32Array(80),gr=new Uint32Array(80);class Mu extends og{constructor(e=64){super(128,e,16,!1),this.Ah=Je[0]|0,this.Al=Je[1]|0,this.Bh=Je[2]|0,this.Bl=Je[3]|0,this.Ch=Je[4]|0,this.Cl=Je[5]|0,this.Dh=Je[6]|0,this.Dl=Je[7]|0,this.Eh=Je[8]|0,this.El=Je[9]|0,this.Fh=Je[10]|0,this.Fl=Je[11]|0,this.Gh=Je[12]|0,this.Gl=Je[13]|0,this.Hh=Je[14]|0,this.Hl=Je[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:u,El:l,Fh:f,Fl:d,Gh:h,Gl:p,Hh:g,Hl:v}=this;return[e,n,r,i,s,o,a,c,u,l,f,d,h,p,g,v]}set(e,n,r,i,s,o,a,c,u,l,f,d,h,p,g,v){this.Ah=e|0,this.Al=n|0,this.Bh=r|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=f|0,this.Fl=d|0,this.Gh=h|0,this.Gl=p|0,this.Hh=g|0,this.Hl=v|0}process(e,n){for(let _=0;_<16;_++,n+=4)pr[_]=e.getUint32(n),gr[_]=e.getUint32(n+=4);for(let _=16;_<80;_++){const x=pr[_-15]|0,$=gr[_-15]|0,T=ar(x,$,1)^ar(x,$,8)^G0(x,$,7),U=cr(x,$,1)^cr(x,$,8)^W0(x,$,7),F=pr[_-2]|0,P=gr[_-2]|0,z=ar(F,P,19)^ps(F,P,61)^G0(F,P,6),M=cr(F,P,19)^gs(F,P,61)^W0(F,P,6),E=t5(U,M,gr[_-7],gr[_-16]),b=n5(E,T,z,pr[_-7],pr[_-16]);pr[_]=b|0,gr[_]=E|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:u,Dl:l,Eh:f,El:d,Fh:h,Fl:p,Gh:g,Gl:v,Hh:B,Hl:D}=this;for(let _=0;_<80;_++){const x=ar(f,d,14)^ar(f,d,18)^ps(f,d,41),$=cr(f,d,14)^cr(f,d,18)^gs(f,d,41),T=f&h^~f&g,U=d&p^~d&v,F=r5(D,$,U,S5[_],gr[_]),P=i5(F,B,x,T,_5[_],pr[_]),z=F|0,M=ar(r,i,28)^ps(r,i,34)^ps(r,i,39),E=cr(r,i,28)^gs(r,i,34)^gs(r,i,39),b=r&s^r&a^s&a,m=i&o^i&c^o&c;B=g|0,D=v|0,g=h|0,v=p|0,h=f|0,p=d|0,{h:f,l:d}=Kt(u|0,l|0,P|0,z|0),u=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const y=Uu(z,E,m);r=Fu(y,P,M,b),i=y|0}({h:r,l:i}=Kt(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=Kt(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=Kt(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l}=Kt(this.Dh|0,this.Dl|0,u|0,l|0),{h:f,l:d}=Kt(this.Eh|0,this.El|0,f|0,d|0),{h,l:p}=Kt(this.Fh|0,this.Fl|0,h|0,p|0),{h:g,l:v}=Kt(this.Gh|0,this.Gl|0,g|0,v|0),{h:B,l:D}=Kt(this.Hh|0,this.Hl|0,B|0,D|0),this.set(r,i,s,o,a,c,u,l,f,d,h,p,g,v,B,D)}roundClean(){Ut(pr,gr)}destroy(){Ut(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class I5 extends Mu{constructor(){super(48),this.Ah=Xe[0]|0,this.Al=Xe[1]|0,this.Bh=Xe[2]|0,this.Bl=Xe[3]|0,this.Ch=Xe[4]|0,this.Cl=Xe[5]|0,this.Dh=Xe[6]|0,this.Dl=Xe[7]|0,this.Eh=Xe[8]|0,this.El=Xe[9]|0,this.Fh=Xe[10]|0,this.Fl=Xe[11]|0,this.Gh=Xe[12]|0,this.Gl=Xe[13]|0,this.Hh=Xe[14]|0,this.Hl=Xe[15]|0}}const Qe=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class A5 extends Mu{constructor(){super(32),this.Ah=Qe[0]|0,this.Al=Qe[1]|0,this.Bh=Qe[2]|0,this.Bl=Qe[3]|0,this.Ch=Qe[4]|0,this.Cl=Qe[5]|0,this.Dh=Qe[6]|0,this.Dl=Qe[7]|0,this.Eh=Qe[8]|0,this.El=Qe[9]|0,this.Fh=Qe[10]|0,this.Fl=Qe[11]|0,this.Gh=Qe[12]|0,this.Gl=Qe[13]|0,this.Hh=Qe[14]|0,this.Hl=Qe[15]|0}}const na=bs(()=>new x5),B5=bs(()=>new Mu),O5=bs(()=>new I5),D5=bs(()=>new A5),$5=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]),$e=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),Y=new Uint32Array(32);function yr(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=Y[2*t],u=Y[2*t+1],l=Y[2*e],f=Y[2*e+1],d=Y[2*n],h=Y[2*n+1],p=Y[2*r],g=Y[2*r+1],v=Uu(c,l,o);u=Fu(v,u,f,a),c=v|0,{Dh:g,Dl:p}={Dh:g^u,Dl:p^c},{Dh:g,Dl:p}={Dh:Z_(g,p),Dl:Y_(g)},{h,l:d}=Kt(h,d,g,p),{Bh:f,Bl:l}={Bh:f^h,Bl:l^d},{Bh:f,Bl:l}={Bh:ar(f,l,24),Bl:cr(f,l,24)},Y[2*t]=c,Y[2*t+1]=u,Y[2*e]=l,Y[2*e+1]=f,Y[2*n]=d,Y[2*n+1]=h,Y[2*r]=p,Y[2*r+1]=g}function br(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=Y[2*t],u=Y[2*t+1],l=Y[2*e],f=Y[2*e+1],d=Y[2*n],h=Y[2*n+1],p=Y[2*r],g=Y[2*r+1],v=Uu(c,l,o);u=Fu(v,u,f,a),c=v|0,{Dh:g,Dl:p}={Dh:g^u,Dl:p^c},{Dh:g,Dl:p}={Dh:ar(g,p,16),Dl:cr(g,p,16)},{h,l:d}=Kt(h,d,g,p),{Bh:f,Bl:l}={Bh:f^h,Bl:l^d},{Bh:f,Bl:l}={Bh:ps(f,l,63),Bl:gs(f,l,63)},Y[2*t]=c,Y[2*t+1]=u,Y[2*e]=l,Y[2*e+1]=f,Y[2*n]=d,Y[2*n+1]=h,Y[2*r]=p,Y[2*r+1]=g}function P5(t,e={},n,r,i){if(On(n),t<0||t>n)throw new Error("outputLen bigger than keyLen");const{key:s,salt:o,personalization:a}=e;if(s!==void 0&&(s.length<1||s.length>n))throw new Error("key length must be undefined or 1.."+n);if(o!==void 0&&o.length!==r)throw new Error("salt must be undefined or "+r);if(a!==void 0&&a.length!==i)throw new Error("personalization must be undefined or "+i)}class T5 extends ta{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,On(e),On(n),this.blockLen=e,this.outputLen=n,this.buffer=new Uint8Array(e),this.buffer32=ys(this.buffer)}update(e){ur(this),e=Wt(e),Gt(e);const{blockLen:n,buffer:r,buffer32:i}=this,s=e.length,o=e.byteOffset,a=e.buffer;for(let c=0;c<s;){this.pos===n&&(lr(i),this.compress(i,0,!1),lr(i),this.pos=0);const u=Math.min(n-this.pos,s-c),l=o+c;if(u===n&&!(l%4)&&c+u<s){const f=new Uint32Array(a,l,Math.floor((s-c)/4));lr(f);for(let d=0;c+n<s;d+=i.length,c+=n)this.length+=n,this.compress(f,d,!1);lr(f);continue}r.set(e.subarray(c,c+u),this.pos),this.pos+=u,this.length+=u,c+=u}return this}digestInto(e){ur(this),Lu(e,this);const{pos:n,buffer32:r}=this;this.finished=!0,Ut(this.buffer.subarray(n)),lr(r),this.compress(r,0,!0),lr(r);const i=ys(e);this.get().forEach((s,o)=>i[o]=Dn(s))}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){const{buffer:n,length:r,finished:i,destroyed:s,outputLen:o,pos:a}=this;return e||(e=new this.constructor({dkLen:o})),e.set(...this.get()),e.buffer.set(n),e.destroyed=s,e.finished=i,e.length=r,e.pos=a,e.outputLen=o,e}clone(){return this._cloneInto()}}class R5 extends T5{constructor(e={}){const n=e.dkLen===void 0?64:e.dkLen;super(128,n),this.v0l=$e[0]|0,this.v0h=$e[1]|0,this.v1l=$e[2]|0,this.v1h=$e[3]|0,this.v2l=$e[4]|0,this.v2h=$e[5]|0,this.v3l=$e[6]|0,this.v3h=$e[7]|0,this.v4l=$e[8]|0,this.v4h=$e[9]|0,this.v5l=$e[10]|0,this.v5h=$e[11]|0,this.v6l=$e[12]|0,this.v6h=$e[13]|0,this.v7l=$e[14]|0,this.v7h=$e[15]|0,P5(n,e,64,16,16);let{key:r,personalization:i,salt:s}=e,o=0;if(r!==void 0&&(r=Wt(r),o=r.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=Wt(s);const a=ys(s);this.v4l^=Dn(a[0]),this.v4h^=Dn(a[1]),this.v5l^=Dn(a[2]),this.v5h^=Dn(a[3])}if(i!==void 0){i=Wt(i);const a=ys(i);this.v6l^=Dn(a[0]),this.v6h^=Dn(a[1]),this.v7l^=Dn(a[2]),this.v7h^=Dn(a[3])}if(r!==void 0){const a=new Uint8Array(this.blockLen);a.set(r),this.update(a)}}get(){let{v0l:e,v0h:n,v1l:r,v1h:i,v2l:s,v2h:o,v3l:a,v3h:c,v4l:u,v4h:l,v5l:f,v5h:d,v6l:h,v6h:p,v7l:g,v7h:v}=this;return[e,n,r,i,s,o,a,c,u,l,f,d,h,p,g,v]}set(e,n,r,i,s,o,a,c,u,l,f,d,h,p,g,v){this.v0l=e|0,this.v0h=n|0,this.v1l=r|0,this.v1h=i|0,this.v2l=s|0,this.v2h=o|0,this.v3l=a|0,this.v3h=c|0,this.v4l=u|0,this.v4h=l|0,this.v5l=f|0,this.v5h=d|0,this.v6l=h|0,this.v6h=p|0,this.v7l=g|0,this.v7h=v|0}compress(e,n,r){this.get().forEach((c,u)=>Y[u]=c),Y.set($e,16);let{h:i,l:s}=V0(BigInt(this.length));Y[24]=$e[8]^s,Y[25]=$e[9]^i,r&&(Y[28]=~Y[28],Y[29]=~Y[29]);let o=0;const a=$5;for(let c=0;c<12;c++)yr(0,4,8,12,e,n+2*a[o++]),br(0,4,8,12,e,n+2*a[o++]),yr(1,5,9,13,e,n+2*a[o++]),br(1,5,9,13,e,n+2*a[o++]),yr(2,6,10,14,e,n+2*a[o++]),br(2,6,10,14,e,n+2*a[o++]),yr(3,7,11,15,e,n+2*a[o++]),br(3,7,11,15,e,n+2*a[o++]),yr(0,5,10,15,e,n+2*a[o++]),br(0,5,10,15,e,n+2*a[o++]),yr(1,6,11,12,e,n+2*a[o++]),br(1,6,11,12,e,n+2*a[o++]),yr(2,7,8,13,e,n+2*a[o++]),br(2,7,8,13,e,n+2*a[o++]),yr(3,4,9,14,e,n+2*a[o++]),br(3,4,9,14,e,n+2*a[o++]);this.v0l^=Y[0]^Y[16],this.v0h^=Y[1]^Y[17],this.v1l^=Y[2]^Y[18],this.v1h^=Y[3]^Y[19],this.v2l^=Y[4]^Y[20],this.v2h^=Y[5]^Y[21],this.v3l^=Y[6]^Y[22],this.v3h^=Y[7]^Y[23],this.v4l^=Y[8]^Y[24],this.v4h^=Y[9]^Y[25],this.v5l^=Y[10]^Y[26],this.v5h^=Y[11]^Y[27],this.v6l^=Y[12]^Y[28],this.v6h^=Y[13]^Y[29],this.v7l^=Y[14]^Y[30],this.v7h^=Y[15]^Y[31],Ut(Y)}destroy(){this.destroyed=!0,Ut(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const N5=a5(t=>new R5(t)),C5="https://rpc.walletconnect.org/v1";function cg(t){const e=`Ethereum Signed Message:
19
- ${t.length}`,n=new TextEncoder().encode(e+t);return"0x"+Buffer.from(b5(n)).toString("hex")}async function U5(t,e,n,r,i,s){switch(n.t){case"eip191":return await F5(t,e,n.s);case"eip1271":return await L5(t,e,n.s,r,i,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}function F5(t,e,n){const r=U8(n);return Kx({payload:cg(e),signature:r}).toLowerCase()===t.toLowerCase()}async function L5(t,e,n,r,i,s){const o=Zo(r);if(!o.namespace||!o.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const a="0x1626ba7e",c="0000000000000000000000000000000000000000000000000000000000000040",u=n.substring(2),l=(u.length/2).toString(16).padStart(64,"0"),f=(e.startsWith("0x")?e:cg(e)).substring(2),d=a+f+c+l+u,h=await fetch(`${s||C5}/?chainId=${r}&projectId=${i}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify({id:k5(),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:d},"latest"]})}),{result:p}=await h.json();return p?p.slice(0,a.length).toLowerCase()===a.toLowerCase():!1}catch(a){return console.error("isValidEip1271Signature: ",a),!1}}function k5(){return Date.now()+Math.floor(Math.random()*1e3)}function q5(t){const e=atob(t),n=new Uint8Array(e.length);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);const r=n[0];if(r===0)throw new Error("No signatures found");const i=1+r*64;if(n.length<i)throw new Error("Transaction data too short for claimed signature count");if(n.length<100)throw new Error("Transaction too short");const s=Buffer.from(t,"base64").slice(1,65);return is.encode(s)}function M5(t){const e=new Uint8Array(Buffer.from(t,"base64")),n=Array.from("TransactionData::").map(s=>s.charCodeAt(0)),r=new Uint8Array(n.length+e.length);r.set(n),r.set(e,n.length);const i=N5(r,{dkLen:32});return is.encode(i)}function ug(t){const e=new Uint8Array(na(j5(t)));return is.encode(e)}function j5(t){if(t instanceof Uint8Array)return t;if(Array.isArray(t))return new Uint8Array(t);if(typeof t=="object"&&t!=null&&t.data)return new Uint8Array(Object.values(t.data));if(typeof t=="object"&&t)return new Uint8Array(Object.values(t));throw new Error("getNearUint8ArrayFromBytes: Unexpected result type from bytes array")}function lg(t){const e=Buffer.from(t,"base64"),n=z6(e).txn;if(!n)throw new Error("Invalid signed transaction: missing 'txn' field");const r=C6(n),i=Buffer.from("TX"),s=Buffer.concat([i,Buffer.from(r)]),o=D5(s);return Mx.encode(o).replace(/=+$/,"")}function ju(t){const e=[];let n=BigInt(t);for(;n>=BigInt(128);)e.push(Number(n&BigInt(127)|BigInt(128))),n>>=BigInt(7);return e.push(Number(n)),Buffer.from(e)}function z5(t){const e=Buffer.from(t.signed.bodyBytes,"base64"),n=Buffer.from(t.signed.authInfoBytes,"base64"),r=Buffer.from(t.signature.signature,"base64"),i=[];i.push(Buffer.from([10])),i.push(ju(e.length)),i.push(e),i.push(Buffer.from([18])),i.push(ju(n.length)),i.push(n),i.push(Buffer.from([26])),i.push(ju(r.length)),i.push(r);const s=Buffer.concat(i),o=na(s);return Buffer.from(o).toString("hex").toUpperCase()}function H5(t){var e,n;const r=[];try{if(typeof t=="string")return r.push(t),r;if(typeof t!="object")return r;t!=null&&t.id&&r.push(t.id);const i=(n=(e=t?.capabilities)==null?void 0:e.caip345)==null?void 0:n.transactionHashes;i&&r.push(...i)}catch(i){console.warn("getWalletSendCallsHashes failed: ",i)}return r}var V5=Object.defineProperty,K5=Object.defineProperties,G5=Object.getOwnPropertyDescriptors,fg=Object.getOwnPropertySymbols,W5=Object.prototype.hasOwnProperty,Z5=Object.prototype.propertyIsEnumerable,hg=(t,e,n)=>e in t?V5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Y5=(t,e)=>{for(var n in e||(e={}))W5.call(e,n)&&hg(t,n,e[n]);if(fg)for(var n of fg(e))Z5.call(e,n)&&hg(t,n,e[n]);return t},X5=(t,e)=>K5(t,G5(e));const J5="did:pkh:",zu=t=>t?.split(":"),Q5=t=>{const e=t&&zu(t);if(e)return t.includes(J5)?e[3]:e[1]},Hu=t=>{const e=t&&zu(t);if(e)return e[2]+":"+e[3]},ra=t=>{const e=t&&zu(t);if(e)return e.pop()};async function dg(t){const{cacao:e,projectId:n}=t,{s:r,p:i}=e,s=pg(i,i.iss),o=ra(i.iss);return await U5(o,s,r,Hu(i.iss),n)}const pg=(t,e)=>{const n=`${t.domain} wants you to sign in with your Ethereum account:`,r=ra(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: ${Q5(e)}`,c=`Nonce: ${t.nonce}`,u=`Issued At: ${t.iat}`,l=t.exp?`Expiration Time: ${t.exp}`:void 0,f=t.nbf?`Not Before: ${t.nbf}`:void 0,d=t.requestId?`Request ID: ${t.requestId}`:void 0,h=t.resources?`Resources:${t.resources.map(g=>`
20
- - ${g}`).join("")}`:void 0,p=ia(t.resources);if(p){const g=ms(p);i=cS(i,g)}return[n,r,"",i,"",s,o,a,c,u,l,f,d,h].filter(g=>g!=null).join(`
21
- `)};function eS(t){return Buffer.from(JSON.stringify(t)).toString("base64")}function tS(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(n=>{const r=t.att[n];if(Array.isArray(r))throw new Error(`Resource must be an object: ${n}`);if(typeof r!="object")throw new Error(`Resource must be an object: ${n}`);if(!Object.keys(r).length)throw new Error(`Resource object is empty: ${n}`);Object.keys(r).forEach(i=>{const s=r[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 nS(t,e,n,r={}){return n?.sort((i,s)=>i.localeCompare(s)),{att:{[t]:rS(e,n,r)}}}function rS(t,e,n={}){e=e?.sort((i,s)=>i.localeCompare(s));const r=e.map(i=>({[`${t}/${i}`]:[n]}));return Object.assign({},...r)}function gg(t){return Vr(t),`urn:recap:${eS(t).replace(/=/g,"")}`}function ms(t){const e=tS(t.replace("urn:recap:",""));return Vr(e),e}function iS(t,e,n){const r=nS(t,e,n);return gg(r)}function sS(t){return t&&t.includes("urn:recap:")}function oS(t,e){const n=ms(t),r=ms(e),i=aS(n,r);return gg(i)}function aS(t,e){Vr(t),Vr(e);const n=Object.keys(t.att).concat(Object.keys(e.att)).sort((i,s)=>i.localeCompare(s)),r={att:{}};return n.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;r.att[i]=X5(Y5({},r.att[i]),{[a]:((c=t.att[i])==null?void 0:c[a])||((u=e.att[i])==null?void 0:u[a])})})}),r}function cS(t="",e){Vr(e);const n="I further authorize the stated URI to perform the following actions on my behalf: ";if(t.includes(n))return t;const r=[];let i=0;Object.keys(e.att).forEach(a=>{const c=Object.keys(e.att[a]).map(f=>({ability:f.split("/")[0],action:f.split("/")[1]}));c.sort((f,d)=>f.action.localeCompare(d.action));const u={};c.forEach(f=>{u[f.ability]||(u[f.ability]=[]),u[f.ability].push(f.action)});const l=Object.keys(u).map(f=>(i++,`(${i}) '${f}': '${u[f].join("', '")}' for '${a}'.`));r.push(l.join(", ").replace(".,","."))});const s=r.join(" "),o=`${n}${s}`;return`${t?t+" ":""}${o}`}function yg(t){var e;const n=ms(t);Vr(n);const r=(e=n.att)==null?void 0:e.eip155;return r?Object.keys(r).map(i=>i.split("/")[1]):[]}function bg(t){const e=ms(t);Vr(e);const n=[];return Object.values(e.att).forEach(r=>{Object.values(r).forEach(i=>{var s;(s=i?.[0])!=null&&s.chains&&n.push(i[0].chains)})}),[...new Set(n.flat())]}function ia(t){if(!t)return;const e=t?.[t.length-1];return sS(e)?e:void 0}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function wg(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Vu(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function Ku(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function wt(t,...e){if(!wg(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 mg(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 uS(t,e){wt(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function wr(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Si(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function lS(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const fS=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function hS(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Gu(t){if(typeof t=="string")t=hS(t);else if(wg(t))t=Wu(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function dS(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function pS(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}const gS=(t,e)=>{function n(r,...i){if(wt(r),!fS)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){const u=i[0];if(!u)throw new Error("nonce / iv required");t.varSizeNonce?wt(u):wt(u,t.nonceLength)}const s=t.tagLength;s&&i[1]!==void 0&&wt(i[1]);const o=e(r,...i),a=(u,l)=>{if(l!==void 0){if(u!==2)throw new Error("cipher output not supported");wt(l)}};let c=!1;return{encrypt(u,l){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,wt(u),a(o.encrypt.length,l),o.encrypt(u,l)},decrypt(u,l){if(wt(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(n,t),n};function vg(t,e,n=!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(n&&!bS(e))throw new Error("invalid output, must be aligned");return e}function Eg(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,u=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+u,a,r)}function yS(t,e,n){Vu(n);const r=new Uint8Array(16),i=lS(r);return Eg(i,0,BigInt(e),n),Eg(i,8,BigInt(t),n),r}function bS(t){return t.byteOffset%4===0}function Wu(t){return Uint8Array.from(t)}const xg=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),wS=xg("expand 16-byte k"),mS=xg("expand 32-byte k"),vS=wr(wS),ES=wr(mS);function ce(t,e){return t<<e|t>>>32-e}function Zu(t){return t.byteOffset%4===0}const sa=64,xS=16,_g=2**32-1,Sg=new Uint32Array;function _S(t,e,n,r,i,s,o,a){const c=i.length,u=new Uint8Array(sa),l=wr(u),f=Zu(i)&&Zu(s),d=f?wr(i):Sg,h=f?wr(s):Sg;for(let p=0;p<c;o++){if(t(e,n,r,l,o,a),o>=_g)throw new Error("arx: counter overflow");const g=Math.min(sa,c-p);if(f&&g===sa){const v=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let B=0,D;B<xS;B++)D=v+B,h[D]=d[D]^l[B];p+=sa;continue}for(let v=0,B;v<g;v++)B=p+v,s[B]=i[B]^u[v];p+=g}}function SS(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=dS({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Ku(i),Ku(o),Vu(s),Vu(n),(a,c,u,l,f=0)=>{wt(a),wt(c),wt(u);const d=u.length;if(l===void 0&&(l=new Uint8Array(d)),wt(l),Ku(f),f<0||f>=_g)throw new Error("arx: counter overflow");if(l.length<d)throw new Error(`arx: output (${l.length}) is shorter than data (${d})`);const h=[];let p=a.length,g,v;if(p===32)h.push(g=Wu(a)),v=ES;else if(p===16&&n)g=new Uint8Array(32),g.set(a),g.set(a,16),v=vS,h.push(g);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Zu(c)||h.push(c=Wu(c));const B=wr(g);if(r){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(v,B,wr(c.subarray(0,16)),B),c=c.subarray(16)}const D=16-i;if(D!==c.length)throw new Error(`arx: nonce must be ${D} or 16 bytes`);if(D!==12){const x=new Uint8Array(12);x.set(c,s?0:12-c.length),c=x,h.push(c)}const _=wr(c);return _S(t,v,B,_,u,l,f,o),Si(...h),l}}const qe=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class IS{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=Gu(e),wt(e,32);const n=qe(e,0),r=qe(e,2),i=qe(e,4),s=qe(e,6),o=qe(e,8),a=qe(e,10),c=qe(e,12),u=qe(e,14);this.r[0]=n&8191,this.r[1]=(n>>>13|r<<3)&8191,this.r[2]=(r>>>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]=qe(e,16+2*l)}process(e,n,r=!1){const i=r?0:2048,{h:s,r:o}=this,a=o[0],c=o[1],u=o[2],l=o[3],f=o[4],d=o[5],h=o[6],p=o[7],g=o[8],v=o[9],B=qe(e,n+0),D=qe(e,n+2),_=qe(e,n+4),x=qe(e,n+6),$=qe(e,n+8),T=qe(e,n+10),U=qe(e,n+12),F=qe(e,n+14);let P=s[0]+(B&8191),z=s[1]+((B>>>13|D<<3)&8191),M=s[2]+((D>>>10|_<<6)&8191),E=s[3]+((_>>>7|x<<9)&8191),b=s[4]+((x>>>4|$<<12)&8191),m=s[5]+($>>>1&8191),y=s[6]+(($>>>14|T<<2)&8191),w=s[7]+((T>>>11|U<<5)&8191),S=s[8]+((U>>>8|F<<8)&8191),A=s[9]+(F>>>5|i),I=0,O=I+P*a+z*(5*v)+M*(5*g)+E*(5*p)+b*(5*h);I=O>>>13,O&=8191,O+=m*(5*d)+y*(5*f)+w*(5*l)+S*(5*u)+A*(5*c),I+=O>>>13,O&=8191;let R=I+P*c+z*a+M*(5*v)+E*(5*g)+b*(5*p);I=R>>>13,R&=8191,R+=m*(5*h)+y*(5*d)+w*(5*f)+S*(5*l)+A*(5*u),I+=R>>>13,R&=8191;let L=I+P*u+z*c+M*a+E*(5*v)+b*(5*g);I=L>>>13,L&=8191,L+=m*(5*p)+y*(5*h)+w*(5*d)+S*(5*f)+A*(5*l),I+=L>>>13,L&=8191;let C=I+P*l+z*u+M*c+E*a+b*(5*v);I=C>>>13,C&=8191,C+=m*(5*g)+y*(5*p)+w*(5*h)+S*(5*d)+A*(5*f),I+=C>>>13,C&=8191;let k=I+P*f+z*l+M*u+E*c+b*a;I=k>>>13,k&=8191,k+=m*(5*v)+y*(5*g)+w*(5*p)+S*(5*h)+A*(5*d),I+=k>>>13,k&=8191;let N=I+P*d+z*f+M*l+E*u+b*c;I=N>>>13,N&=8191,N+=m*a+y*(5*v)+w*(5*g)+S*(5*p)+A*(5*h),I+=N>>>13,N&=8191;let q=I+P*h+z*d+M*f+E*l+b*u;I=q>>>13,q&=8191,q+=m*c+y*a+w*(5*v)+S*(5*g)+A*(5*p),I+=q>>>13,q&=8191;let j=I+P*p+z*h+M*d+E*f+b*l;I=j>>>13,j&=8191,j+=m*u+y*c+w*a+S*(5*v)+A*(5*g),I+=j>>>13,j&=8191;let W=I+P*g+z*p+M*h+E*d+b*f;I=W>>>13,W&=8191,W+=m*l+y*u+w*c+S*a+A*(5*v),I+=W>>>13,W&=8191;let V=I+P*v+z*g+M*p+E*h+b*d;I=V>>>13,V&=8191,V+=m*f+y*l+w*u+S*c+A*a,I+=V>>>13,V&=8191,I=(I<<2)+I|0,I=I+O|0,O=I&8191,I=I>>>13,R+=I,s[0]=O,s[1]=R,s[2]=L,s[3]=C,s[4]=k,s[5]=N,s[6]=q,s[7]=j,s[8]=W,s[9]=V}finalize(){const{h:e,pad:n}=this,r=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,r[0]=e[0]+5,i=r[0]>>>13,r[0]&=8191;for(let a=1;a<10;a++)r[a]=e[a]+i,i=r[a]>>>13,r[a]&=8191;r[9]-=8192;let s=(i^1)-1;for(let a=0;a<10;a++)r[a]&=s;s=~s;for(let a=0;a<10;a++)e[a]=e[a]&s|r[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]+n[0];e[0]=o&65535;for(let a=1;a<8;a++)o=(e[a]+n[a]|0)+(o>>>16)|0,e[a]=o&65535;Si(r)}update(e){mg(this),e=Gu(e),wt(e);const{buffer:n,blockLen:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);if(o===r){for(;r<=i-s;s+=r)this.process(e,s);continue}n.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===r&&(this.process(n,0,!1),this.pos=0)}return this}destroy(){Si(this.h,this.r,this.buffer,this.pad)}digestInto(e){mg(this),uS(e,this),this.finished=!0;const{buffer:n,h:r}=this;let{pos:i}=this;if(i){for(n[i++]=1;i<16;i++)n[i]=0;this.process(n,0,!0)}this.finalize();let s=0;for(let o=0;o<8;o++)e[s++]=r[o]>>>0,e[s++]=r[o]>>>8;return e}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}}function AS(t){const e=(r,i)=>t(i).update(Gu(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}const BS=AS(t=>new IS(t));function OS(t,e,n,r,i,s=20){let o=t[0],a=t[1],c=t[2],u=t[3],l=e[0],f=e[1],d=e[2],h=e[3],p=e[4],g=e[5],v=e[6],B=e[7],D=i,_=n[0],x=n[1],$=n[2],T=o,U=a,F=c,P=u,z=l,M=f,E=d,b=h,m=p,y=g,w=v,S=B,A=D,I=_,O=x,R=$;for(let C=0;C<s;C+=2)T=T+z|0,A=ce(A^T,16),m=m+A|0,z=ce(z^m,12),T=T+z|0,A=ce(A^T,8),m=m+A|0,z=ce(z^m,7),U=U+M|0,I=ce(I^U,16),y=y+I|0,M=ce(M^y,12),U=U+M|0,I=ce(I^U,8),y=y+I|0,M=ce(M^y,7),F=F+E|0,O=ce(O^F,16),w=w+O|0,E=ce(E^w,12),F=F+E|0,O=ce(O^F,8),w=w+O|0,E=ce(E^w,7),P=P+b|0,R=ce(R^P,16),S=S+R|0,b=ce(b^S,12),P=P+b|0,R=ce(R^P,8),S=S+R|0,b=ce(b^S,7),T=T+M|0,R=ce(R^T,16),w=w+R|0,M=ce(M^w,12),T=T+M|0,R=ce(R^T,8),w=w+R|0,M=ce(M^w,7),U=U+E|0,A=ce(A^U,16),S=S+A|0,E=ce(E^S,12),U=U+E|0,A=ce(A^U,8),S=S+A|0,E=ce(E^S,7),F=F+b|0,I=ce(I^F,16),m=m+I|0,b=ce(b^m,12),F=F+b|0,I=ce(I^F,8),m=m+I|0,b=ce(b^m,7),P=P+z|0,O=ce(O^P,16),y=y+O|0,z=ce(z^y,12),P=P+z|0,O=ce(O^P,8),y=y+O|0,z=ce(z^y,7);let L=0;r[L++]=o+T|0,r[L++]=a+U|0,r[L++]=c+F|0,r[L++]=u+P|0,r[L++]=l+z|0,r[L++]=f+M|0,r[L++]=d+E|0,r[L++]=h+b|0,r[L++]=p+m|0,r[L++]=g+y|0,r[L++]=v+w|0,r[L++]=B+S|0,r[L++]=D+A|0,r[L++]=_+I|0,r[L++]=x+O|0,r[L++]=$+R|0}const DS=SS(OS,{counterRight:!1,counterLength:4,allowShortKeys:!1}),$S=new Uint8Array(16),Ig=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update($S.subarray(n))},PS=new Uint8Array(32);function Ag(t,e,n,r,i){const s=t(e,n,PS),o=BS.create(s);i&&Ig(o,i),Ig(o,r);const a=yS(r.length,i?i.length:0,!0);o.update(a);const c=o.digest();return Si(s,a),c}const TS=t=>(e,n,r)=>({encrypt(i,s){const o=i.length;s=vg(o+16,s,!1),s.set(i);const a=s.subarray(0,-16);t(e,n,a,a,1);const c=Ag(t,e,n,a,r);return s.set(c,o),Si(c),s},decrypt(i,s){s=vg(i.length-16,s,!1);const o=i.subarray(0,-16),a=i.subarray(-16),c=Ag(t,e,n,o,r);if(!pS(a,c))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),t(e,n,s,s,1),Si(c),s}}),Bg=gS({blockSize:64,nonceLength:12,tagLength:16},TS(DS));class Og extends ta{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Qo(e);const r=Wt(n);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(r.length>i?e.create().update(r).digest():r);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),Ut(s)}update(e){return ur(this),this.iHash.update(e),this}digestInto(e){ur(this),Gt(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:n,iHash:r,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=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const oa=(t,e,n)=>new Og(t,e).update(n).digest();oa.create=(t,e)=>new Og(t,e);function RS(t,e,n){return Qo(t),n===void 0&&(n=new Uint8Array(t.outputLen)),oa(t,Wt(n),Wt(e))}const Yu=Uint8Array.from([0]),Dg=Uint8Array.of();function NS(t,e,n,r=32){Qo(t),On(r);const i=t.outputLen;if(r>255*i)throw new Error("Length should be <= 255*HashLen");const s=Math.ceil(r/i);n===void 0&&(n=Dg);const o=new Uint8Array(s*i),a=oa.create(t,e),c=a._cloneInto(),u=new Uint8Array(a.outputLen);for(let l=0;l<s;l++)Yu[0]=l+1,c.update(l===0?Dg:u).update(n).update(Yu).digestInto(u),o.set(u,i*l),a._cloneInto(c);return a.destroy(),c.destroy(),Ut(u,Yu),o.slice(0,r)}const CS=(t,e,n,r,i)=>NS(t,RS(t,e,n),r,i),aa=na,Xu=BigInt(0),Ju=BigInt(1);function ca(t,e=""){if(typeof t!="boolean"){const n=e&&`"${e}"`;throw new Error(n+"expected boolean, got type="+typeof t)}return t}function Kr(t,e,n=""){const r=Jo(t),i=t?.length,s=e!==void 0;if(!r||s&&i!==e){const o=n&&`"${n}" `,a=s?` of length ${e}`:"",c=r?`length=${i}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return t}function ua(t){const e=t.toString(16);return e.length&1?"0"+e:e}function $g(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Xu:BigInt("0x"+t)}function la(t){return $g(_i(t))}function fa(t){return Gt(t),$g(_i(Uint8Array.from(t).reverse()))}function Qu(t,e){return ea(t.toString(16).padStart(e*2,"0"))}function el(t,e){return Qu(t,e).reverse()}function et(t,e,n){let r;if(typeof e=="string")try{r=ea(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Jo(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}const tl=t=>typeof t=="bigint"&&Xu<=t;function US(t,e,n){return tl(t)&&tl(e)&&tl(n)&&e<=t&&t<n}function nl(t,e,n,r){if(!US(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Pg(t){let e;for(e=0;t>Xu;t>>=Ju,e+=1);return e}const vs=t=>(Ju<<BigInt(t))-Ju;function FS(t,e,n){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 n!="function")throw new Error("hmacFn must be a function");const r=d=>new Uint8Array(d),i=d=>Uint8Array.of(d);let s=r(t),o=r(t),a=0;const c=()=>{s.fill(1),o.fill(0),a=0},u=(...d)=>n(o,s,...d),l=(d=r(0))=>{o=u(i(0),d),s=u(),d.length!==0&&(o=u(i(1),d),s=u())},f=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0;const h=[];for(;d<e;){s=u();const p=s.slice();h.push(p),d+=s.length}return fr(...h)};return(d,h)=>{c(),l(d);let p;for(;!(p=h(f()));)l();return c(),p}}function ha(t,e,n={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function r(i,s,o){const a=t[i];if(o&&a===void 0)return;const c=typeof a;if(c!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${c}`)}Object.entries(e).forEach(([i,s])=>r(i,s,!1)),Object.entries(n).forEach(([i,s])=>r(i,s,!0))}function Tg(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}const mt=BigInt(0),ct=BigInt(1),Gr=BigInt(2),Rg=BigInt(3),Ng=BigInt(4),Cg=BigInt(5),LS=BigInt(7),Ug=BigInt(8),kS=BigInt(9),Fg=BigInt(16);function Ot(t,e){const n=t%e;return n>=mt?n:e+n}function Zt(t,e,n){let r=t;for(;e-- >mt;)r*=r,r%=n;return r}function Lg(t,e){if(t===mt)throw new Error("invert: expected non-zero number");if(e<=mt)throw new Error("invert: expected positive modulus, got "+e);let n=Ot(t,e),r=e,i=mt,s=ct;for(;n!==mt;){const o=r/n,a=r%n,c=i-s*o;r=n,n=a,i=s,s=c}if(r!==ct)throw new Error("invert: does not exist");return Ot(i,e)}function rl(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function kg(t,e){const n=(t.ORDER+ct)/Ng,r=t.pow(e,n);return rl(t,r,e),r}function qS(t,e){const n=(t.ORDER-Cg)/Ug,r=t.mul(e,Gr),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,Gr),i),a=t.mul(s,t.sub(o,t.ONE));return rl(t,a,e),a}function MS(t){const e=mr(t),n=qg(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+LS)/Fg;return(a,c)=>{let u=a.pow(c,o),l=a.mul(u,r);const f=a.mul(u,i),d=a.mul(u,s),h=a.eql(a.sqr(l),c),p=a.eql(a.sqr(f),c);u=a.cmov(u,l,h),l=a.cmov(d,f,p);const g=a.eql(a.sqr(l),c),v=a.cmov(u,l,g);return rl(a,v,c),v}}function qg(t){if(t<Rg)throw new Error("sqrt is not defined for small field");let e=t-ct,n=0;for(;e%Gr===mt;)e/=Gr,n++;let r=Gr;const i=mr(t);for(;jg(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return kg;let s=i.pow(r,e);const o=(e+ct)/Gr;return function(a,c){if(a.is0(c))return c;if(jg(a,c)!==1)throw new Error("Cannot find square root");let u=n,l=a.mul(a.ONE,s),f=a.pow(c,e),d=a.pow(c,o);for(;!a.eql(f,a.ONE);){if(a.is0(f))return a.ZERO;let h=1,p=a.sqr(f);for(;!a.eql(p,a.ONE);)if(h++,p=a.sqr(p),h===u)throw new Error("Cannot find square root");const g=ct<<BigInt(u-h-1),v=a.pow(l,g);u=h,l=a.sqr(v),f=a.mul(f,l),d=a.mul(d,v)}return d}}function jS(t){return t%Ng===Rg?kg:t%Ug===Cg?qS:t%Fg===kS?MS(t):qg(t)}const zS=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function HS(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=zS.reduce((r,i)=>(r[i]="function",r),e);return ha(t,n),t}function VS(t,e,n){if(n<mt)throw new Error("invalid exponent, negatives unsupported");if(n===mt)return t.ONE;if(n===ct)return e;let r=t.ONE,i=e;for(;n>mt;)n&ct&&(r=t.mul(r,i)),i=t.sqr(i),n>>=ct;return r}function Mg(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),i=e.reduce((o,a,c)=>t.is0(a)?o:(r[c]=o,t.mul(o,a)),t.ONE),s=t.inv(i);return e.reduceRight((o,a,c)=>t.is0(a)?o:(r[c]=t.mul(o,r[c]),t.mul(o,a)),s),r}function jg(t,e){const n=(t.ORDER-ct)/Gr,r=t.pow(e,n),i=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),o=t.eql(r,t.neg(t.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function zg(t,e){e!==void 0&&On(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function mr(t,e,n=!1,r={}){if(t<=mt)throw new Error("invalid field: expected ORDER > 0, got "+t);let i,s,o=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const d=e;d.BITS&&(i=d.BITS),d.sqrt&&(s=d.sqrt),typeof d.isLE=="boolean"&&(n=d.isLE),typeof d.modFromBytes=="boolean"&&(o=d.modFromBytes),a=d.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:u}=zg(t,i);if(u>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const f=Object.freeze({ORDER:t,isLE:n,BITS:c,BYTES:u,MASK:vs(c),ZERO:mt,ONE:ct,allowedLengths:a,create:d=>Ot(d,t),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return mt<=d&&d<t},is0:d=>d===mt,isValidNot0:d=>!f.is0(d)&&f.isValid(d),isOdd:d=>(d&ct)===ct,neg:d=>Ot(-d,t),eql:(d,h)=>d===h,sqr:d=>Ot(d*d,t),add:(d,h)=>Ot(d+h,t),sub:(d,h)=>Ot(d-h,t),mul:(d,h)=>Ot(d*h,t),pow:(d,h)=>VS(f,d,h),div:(d,h)=>Ot(d*Lg(h,t),t),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>Lg(d,t),sqrt:s||(d=>(l||(l=jS(t)),l(f,d))),toBytes:d=>n?el(d,u):Qu(d,u),fromBytes:(d,h=!0)=>{if(a){if(!a.includes(d.length)||d.length>u)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);const g=new Uint8Array(u);g.set(d,n?0:g.length-d.length),d=g}if(d.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+d.length);let p=n?fa(d):la(d);if(o&&(p=Ot(p,t)),!h&&!f.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:d=>Mg(f,d),cmov:(d,h,p)=>p?h:d});return Object.freeze(f)}function Hg(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 Vg(t){const e=Hg(t);return e+Math.ceil(e/2)}function KS(t,e,n=!1){const r=t.length,i=Hg(e),s=Vg(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?fa(t):la(t),a=Ot(o,e-ct)+ct;return n?el(a,i):Qu(a,i)}const Ii=BigInt(0),Wr=BigInt(1);function da(t,e){const n=e.negate();return t?n:e}function il(t,e){const n=Mg(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function Kg(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function sl(t,e){Kg(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=vs(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function Gg(t,e,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(t&i),c=t>>o;a>r&&(a-=s,c+=Wr);const u=e*r,l=u+Math.abs(a)-1,f=a===0,d=a<0,h=e%2!==0;return{nextN:c,offset:l,isZero:f,isNeg:d,isNegF:h,offsetF:u}}function GS(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function WS(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const ol=new WeakMap,Wg=new WeakMap;function al(t){return Wg.get(t)||1}function Zg(t){if(t!==Ii)throw new Error("invalid wNAF")}class ZS{constructor(e,n){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=n}_unsafeLadder(e,n,r=this.ZERO){let i=e;for(;n>Ii;)n&Wr&&(r=r.add(i)),i=i.double(),n>>=Wr;return r}precomputeWindow(e,n){const{windows:r,windowSize:i}=sl(n,this.bits),s=[];let o=e,a=o;for(let c=0;c<r;c++){a=o,s.push(a);for(let u=1;u<i;u++)a=a.add(o),s.push(a);o=a.double()}return s}wNAF(e,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=sl(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:c,offset:u,isZero:l,isNeg:f,isNegF:d,offsetF:h}=Gg(r,a,o);r=c,l?s=s.add(da(d,n[h])):i=i.add(da(f,n[u]))}return Zg(r),{p:i,f:s}}wNAFUnsafe(e,n,r,i=this.ZERO){const s=sl(e,this.bits);for(let o=0;o<s.windows&&r!==Ii;o++){const{nextN:a,offset:c,isZero:u,isNeg:l}=Gg(r,o,s);if(r=a,!u){const f=n[c];i=i.add(l?f.negate():f)}}return Zg(r),i}getPrecomputes(e,n,r){let i=ol.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),ol.set(n,i))),i}cached(e,n,r){const i=al(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=al(e);return s===1?this._unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,i)}createCache(e,n){Kg(n,this.bits),Wg.set(e,n),ol.delete(e)}hasCache(e){return al(e)!==1}}function YS(t,e,n,r){let i=e,s=t.ZERO,o=t.ZERO;for(;n>Ii||r>Ii;)n&Wr&&(s=s.add(i)),r&Wr&&(o=o.add(i)),i=i.double(),n>>=Wr,r>>=Wr;return{p1:s,p2:o}}function XS(t,e,n,r){GS(n,t),WS(r,e);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,a=Pg(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const u=vs(c),l=new Array(Number(u)+1).fill(o),f=Math.floor((e.BITS-1)/c)*c;let d=o;for(let h=f;h>=0;h-=c){l.fill(o);for(let g=0;g<s;g++){const v=r[g],B=Number(v>>BigInt(h)&u);l[B]=l[B].add(n[g])}let p=o;for(let g=l.length-1,v=o;g>0;g--)v=v.add(l[g]),p=p.add(v);if(d=d.add(p),h!==0)for(let g=0;g<c;g++)d=d.double()}return d}function Yg(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return HS(e),e}else return mr(t,{isLE:n})}function JS(t,e,n={},r){if(r===void 0&&(r=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(const a of["p","n","h"]){const c=e[a];if(!(typeof c=="bigint"&&c>Ii))throw new Error(`CURVE.${a} must be positive bigint`)}const i=Yg(e.p,n.Fp,r),s=Yg(e.n,n.Fn,r),o=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(const a of o)if(!i.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:s}}BigInt(0),BigInt(1),BigInt(2),BigInt(8),Q0("HashToScalar-");const Es=BigInt(0),Ai=BigInt(1),pa=BigInt(2);function QS(t){return ha(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function eI(t){const e=QS(t),{P:n,type:r,adjustScalarBytes:i,powPminus2:s,randomBytes:o}=e,a=r==="x25519";if(!a&&r!=="x448")throw new Error("invalid type");const c=o||Hr,u=a?255:448,l=a?32:56,f=BigInt(a?9:5),d=BigInt(a?121665:39081),h=a?pa**BigInt(254):pa**BigInt(447),p=a?BigInt(8)*pa**BigInt(251)-Ai:BigInt(4)*pa**BigInt(445)-Ai,g=h+p+Ai,v=E=>Ot(E,n),B=D(f);function D(E){return el(v(E),l)}function _(E){const b=et("u coordinate",E,l);return a&&(b[31]&=127),v(fa(b))}function x(E){return fa(i(et("scalar",E,l)))}function $(E,b){const m=F(_(b),x(E));if(m===Es)throw new Error("invalid private or public key received");return D(m)}function T(E){return $(E,B)}function U(E,b,m){const y=v(E*(b-m));return b=v(b-y),m=v(m+y),{x_2:b,x_3:m}}function F(E,b){nl("u",E,Es,n),nl("scalar",b,h,g);const m=b,y=E;let w=Ai,S=Es,A=E,I=Ai,O=Es;for(let L=BigInt(u-1);L>=Es;L--){const C=m>>L&Ai;O^=C,{x_2:w,x_3:A}=U(O,w,A),{x_2:S,x_3:I}=U(O,S,I),O=C;const k=w+S,N=v(k*k),q=w-S,j=v(q*q),W=N-j,V=A+I,Z=A-I,Q=v(Z*k),ee=v(V*q),ie=Q+ee,fe=Q-ee;A=v(ie*ie),I=v(y*v(fe*fe)),w=v(N*j),S=v(W*(N+v(d*W)))}({x_2:w,x_3:A}=U(O,w,A)),{x_2:S,x_3:I}=U(O,S,I);const R=s(S);return v(w*R)}const P={secretKey:l,publicKey:l,seed:l},z=(E=c(l))=>(Gt(E,P.seed),E);function M(E){const b=z(E);return{secretKey:b,publicKey:T(b)}}return{keygen:M,getSharedSecret:(E,b)=>$(E,b),getPublicKey:E=>T(E),scalarMult:$,scalarMultBase:T,utils:{randomSecretKey:z,randomPrivateKey:z},GuBytes:B.slice(),lengths:P}}const tI=BigInt(1),Xg=BigInt(2),nI=BigInt(3),rI=BigInt(5),iI=BigInt(8),Jg=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),sI={p:Jg,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:iI,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function oI(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=Jg,o=t*t%s*t%s,a=Zt(o,Xg,s)*o%s,c=Zt(a,tI,s)*t%s,u=Zt(c,rI,s)*c%s,l=Zt(u,e,s)*u%s,f=Zt(l,n,s)*l%s,d=Zt(f,r,s)*f%s,h=Zt(d,i,s)*d%s,p=Zt(h,i,s)*d%s,g=Zt(p,e,s)*u%s;return{pow_p_5_8:Zt(g,Xg,s)*t%s,b2:o}}function aI(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const cI=mr(sI.p,{isLE:!0}),cl=(()=>{const t=cI.ORDER;return eI({P:t,type:"x25519",powPminus2:e=>{const{pow_p_5_8:n,b2:r}=oI(e);return Ot(Zt(n,nI,t)*r,t)},adjustScalarBytes:aI})})(),Qg=(t,e)=>(t+(t>=0?e:-e)/e1)/e;function uI(t,e,n){const[[r,i],[s,o]]=e,a=Qg(o*t,n),c=Qg(-i*t,n);let u=t-a*r-c*s,l=-a*i-c*o;const f=u<Tn,d=l<Tn;f&&(u=-u),d&&(l=-l);const h=vs(Math.ceil(Pg(n)/2))+Bi;if(u<Tn||u>=h||l<Tn||l>=h)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:f,k1:u,k2neg:d,k2:l}}function ul(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function ll(t,e){const n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return ca(n.lowS,"lowS"),ca(n.prehash,"prehash"),n.format!==void 0&&ul(n.format),n}class lI extends Error{constructor(e=""){super(e)}}const Pn={Err:lI,_tlv:{encode:(t,e)=>{const{Err:n}=Pn;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");const r=e.length/2,i=ua(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?ua(i.length/2|128):"";return ua(t)+s+i+e},decode(t,e){const{Err:n}=Pn;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const u=e.subarray(r,r+c);if(u.length!==c)throw new n("tlv.decode: length bytes not complete");if(u[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of u)o=o<<8|l;if(r+=c,o<128)throw new n("tlv.decode(long): not minimal encoding")}const a=e.subarray(r,r+o);if(a.length!==o)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(t){const{Err:e}=Pn;if(t<Tn)throw new e("integer: negative integers are not allowed");let n=ua(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=Pn;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 la(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=Pn,i=et("signature",t),{v:s,l:o}=r.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,s),{v:u,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(u)}},hexFromSig(t){const{_tlv:e,_int:n}=Pn,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}},Tn=BigInt(0),Bi=BigInt(1),e1=BigInt(2),ga=BigInt(3),fI=BigInt(4);function Oi(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=et("private key",e);try{r=t.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof e}`)}}if(!t.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function hI(t,e={}){const n=JS("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;ha(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=e;if(c&&(!r.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const u=n1(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(E,b,m){const{x:y,y:w}=b.toAffine(),S=r.toBytes(y);if(ca(m,"isCompressed"),m){l();const A=!r.isOdd(w);return fr(t1(A),S)}else return fr(Uint8Array.of(4),S,r.toBytes(w))}function d(E){Kr(E,void 0,"Point");const{publicKey:b,publicKeyUncompressed:m}=u,y=E.length,w=E[0],S=E.subarray(1);if(y===b&&(w===2||w===3)){const A=r.fromBytes(S);if(!r.isValid(A))throw new Error("bad point: is not on curve, wrong x");const I=g(A);let O;try{O=r.sqrt(I)}catch(L){const C=L instanceof Error?": "+L.message:"";throw new Error("bad point: is not on curve, sqrt error"+C)}l();const R=r.isOdd(O);return(w&1)===1!==R&&(O=r.neg(O)),{x:A,y:O}}else if(y===m&&w===4){const A=r.BYTES,I=r.fromBytes(S.subarray(0,A)),O=r.fromBytes(S.subarray(A,A*2));if(!v(I,O))throw new Error("bad point: is not on curve");return{x:I,y:O}}else throw new Error(`bad point: got length ${y}, expected compressed=${b} or uncompressed=${m}`)}const h=e.toBytes||f,p=e.fromBytes||d;function g(E){const b=r.sqr(E),m=r.mul(b,E);return r.add(r.add(m,r.mul(E,s.a)),s.b)}function v(E,b){const m=r.sqr(b),y=g(E);return r.eql(m,y)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const B=r.mul(r.pow(s.a,ga),fI),D=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(B,D)))throw new Error("bad curve params: a or b");function _(E,b,m=!1){if(!r.isValid(b)||m&&r.is0(b))throw new Error(`bad point coordinate ${E}`);return b}function x(E){if(!(E instanceof P))throw new Error("ProjectivePoint expected")}function $(E){if(!c||!c.basises)throw new Error("no endo");return uI(E,c.basises,i.ORDER)}const T=Tg((E,b)=>{const{X:m,Y:y,Z:w}=E;if(r.eql(w,r.ONE))return{x:m,y};const S=E.is0();b==null&&(b=S?r.ONE:r.inv(w));const A=r.mul(m,b),I=r.mul(y,b),O=r.mul(w,b);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql(O,r.ONE))throw new Error("invZ was invalid");return{x:A,y:I}}),U=Tg(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.Y))return;throw new Error("bad point: ZERO")}const{x:b,y:m}=E.toAffine();if(!r.isValid(b)||!r.isValid(m))throw new Error("bad point: x or y not field elements");if(!v(b,m))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function F(E,b,m,y,w){return m=new P(r.mul(m.X,E),m.Y,m.Z),b=da(y,b),m=da(w,m),b.add(m)}class P{constructor(b,m,y){this.X=_("x",b),this.Y=_("y",m,!0),this.Z=_("z",y),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){const{x:m,y}=b||{};if(!b||!r.isValid(m)||!r.isValid(y))throw new Error("invalid affine point");if(b instanceof P)throw new Error("projective point not allowed");return r.is0(m)&&r.is0(y)?P.ZERO:new P(m,y,r.ONE)}static fromBytes(b){const m=P.fromAffine(p(Kr(b,void 0,"point")));return m.assertValidity(),m}static fromHex(b){return P.fromBytes(et("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,m=!0){return M.createCache(this,b),m||this.multiply(ga),this}assertValidity(){U(this)}hasEvenY(){const{y:b}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(b)}equals(b){x(b);const{X:m,Y:y,Z:w}=this,{X:S,Y:A,Z:I}=b,O=r.eql(r.mul(m,I),r.mul(S,w)),R=r.eql(r.mul(y,I),r.mul(A,w));return O&&R}negate(){return new P(this.X,r.neg(this.Y),this.Z)}double(){const{a:b,b:m}=s,y=r.mul(m,ga),{X:w,Y:S,Z:A}=this;let I=r.ZERO,O=r.ZERO,R=r.ZERO,L=r.mul(w,w),C=r.mul(S,S),k=r.mul(A,A),N=r.mul(w,S);return N=r.add(N,N),R=r.mul(w,A),R=r.add(R,R),I=r.mul(b,R),O=r.mul(y,k),O=r.add(I,O),I=r.sub(C,O),O=r.add(C,O),O=r.mul(I,O),I=r.mul(N,I),R=r.mul(y,R),k=r.mul(b,k),N=r.sub(L,k),N=r.mul(b,N),N=r.add(N,R),R=r.add(L,L),L=r.add(R,L),L=r.add(L,k),L=r.mul(L,N),O=r.add(O,L),k=r.mul(S,A),k=r.add(k,k),L=r.mul(k,N),I=r.sub(I,L),R=r.mul(k,C),R=r.add(R,R),R=r.add(R,R),new P(I,O,R)}add(b){x(b);const{X:m,Y:y,Z:w}=this,{X:S,Y:A,Z:I}=b;let O=r.ZERO,R=r.ZERO,L=r.ZERO;const C=s.a,k=r.mul(s.b,ga);let N=r.mul(m,S),q=r.mul(y,A),j=r.mul(w,I),W=r.add(m,y),V=r.add(S,A);W=r.mul(W,V),V=r.add(N,q),W=r.sub(W,V),V=r.add(m,w);let Z=r.add(S,I);return V=r.mul(V,Z),Z=r.add(N,j),V=r.sub(V,Z),Z=r.add(y,w),O=r.add(A,I),Z=r.mul(Z,O),O=r.add(q,j),Z=r.sub(Z,O),L=r.mul(C,V),O=r.mul(k,j),L=r.add(O,L),O=r.sub(q,L),L=r.add(q,L),R=r.mul(O,L),q=r.add(N,N),q=r.add(q,N),j=r.mul(C,j),V=r.mul(k,V),q=r.add(q,j),j=r.sub(N,j),j=r.mul(C,j),V=r.add(V,j),N=r.mul(q,V),R=r.add(R,N),N=r.mul(Z,V),O=r.mul(W,O),O=r.sub(O,N),N=r.mul(W,q),L=r.mul(Z,L),L=r.add(L,N),new P(O,R,L)}subtract(b){return this.add(b.negate())}is0(){return this.equals(P.ZERO)}multiply(b){const{endo:m}=e;if(!i.isValidNot0(b))throw new Error("invalid scalar: out of range");let y,w;const S=A=>M.cached(this,A,I=>il(P,I));if(m){const{k1neg:A,k1:I,k2neg:O,k2:R}=$(b),{p:L,f:C}=S(I),{p:k,f:N}=S(R);w=C.add(N),y=F(m.beta,L,k,A,O)}else{const{p:A,f:I}=S(b);y=A,w=I}return il(P,[y,w])[0]}multiplyUnsafe(b){const{endo:m}=e,y=this;if(!i.isValid(b))throw new Error("invalid scalar: out of range");if(b===Tn||y.is0())return P.ZERO;if(b===Bi)return y;if(M.hasCache(this))return this.multiply(b);if(m){const{k1neg:w,k1:S,k2neg:A,k2:I}=$(b),{p1:O,p2:R}=YS(P,y,S,I);return F(m.beta,O,R,w,A)}else return M.unsafe(y,b)}multiplyAndAddUnsafe(b,m,y){const w=this.multiplyUnsafe(m).add(b.multiplyUnsafe(y));return w.is0()?void 0:w}toAffine(b){return T(this,b)}isTorsionFree(){const{isTorsionFree:b}=e;return o===Bi?!0:b?b(P,this):M.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:b}=e;return o===Bi?this:b?b(P,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(b=!0){return ca(b,"isCompressed"),this.assertValidity(),h(P,this,b)}toHex(b=!0){return _i(this.toBytes(b))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(b=!0){return this.toBytes(b)}_setWindowSize(b){this.precompute(b)}static normalizeZ(b){return il(P,b)}static msm(b,m){return XS(P,i,b,m)}static fromPrivateKey(b){return P.BASE.multiply(Oi(i,b))}}P.BASE=new P(s.Gx,s.Gy,r.ONE),P.ZERO=new P(r.ZERO,r.ONE,r.ZERO),P.Fp=r,P.Fn=i;const z=i.BITS,M=new ZS(P,e.endo?Math.ceil(z/2):z);return P.BASE.precompute(8),P}function t1(t){return Uint8Array.of(t?2:3)}function n1(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function dI(t,e={}){const{Fn:n}=t,r=e.randomBytes||Hr,i=Object.assign(n1(t.Fp,n),{seed:Vg(n.ORDER)});function s(d){try{return!!Oi(n,d)}catch{return!1}}function o(d,h){const{publicKey:p,publicKeyUncompressed:g}=i;try{const v=d.length;return h===!0&&v!==p||h===!1&&v!==g?!1:!!t.fromBytes(d)}catch{return!1}}function a(d=r(i.seed)){return KS(Kr(d,i.seed,"seed"),n.ORDER)}function c(d,h=!0){return t.BASE.multiply(Oi(n,d)).toBytes(h)}function u(d){const h=a(d);return{secretKey:h,publicKey:c(h)}}function l(d){if(typeof d=="bigint")return!1;if(d instanceof t)return!0;const{secretKey:h,publicKey:p,publicKeyUncompressed:g}=i;if(n.allowedLengths||h===p)return;const v=et("key",d).length;return v===p||v===g}function f(d,h,p=!0){if(l(d)===!0)throw new Error("first arg must be private key");if(l(h)===!1)throw new Error("second arg must be public key");const g=Oi(n,d);return t.fromHex(h).multiply(g).toBytes(p)}return Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:u,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:d=>Oi(n,d),precompute(d=8,h=t.BASE){return h.precompute(d,!1)}},lengths:i})}function pI(t,e,n={}){Qo(e),ha(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Hr,i=n.hmac||((m,...y)=>oa(e,m,fr(...y))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h}=dI(t,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},g="compact";function v(m){const y=a>>Bi;return m>y}function B(m,y){if(!o.isValidNot0(y))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return y}function D(m,y){ul(y);const w=h.signature,S=y==="compact"?w:y==="recovered"?w+1:void 0;return Kr(m,S,`${y} signature`)}class _{constructor(y,w,S){this.r=B("r",y),this.s=B("s",w),S!=null&&(this.recovery=S),Object.freeze(this)}static fromBytes(y,w=g){D(y,w);let S;if(w==="der"){const{r:R,s:L}=Pn.toSig(Kr(y));return new _(R,L)}w==="recovered"&&(S=y[0],w="compact",y=y.subarray(1));const A=o.BYTES,I=y.subarray(0,A),O=y.subarray(A,A*2);return new _(o.fromBytes(I),o.fromBytes(O),S)}static fromHex(y,w){return this.fromBytes(ea(y),w)}addRecoveryBit(y){return new _(this.r,this.s,y)}recoverPublicKey(y){const w=s.ORDER,{r:S,s:A,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*e1<w&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");const O=I===2||I===3?S+a:S;if(!s.isValid(O))throw new Error("recovery id 2 or 3 invalid");const R=s.toBytes(O),L=t.fromBytes(fr(t1((I&1)===0),R)),C=o.inv(O),k=$(et("msgHash",y)),N=o.create(-k*C),q=o.create(A*C),j=t.BASE.multiplyUnsafe(N).add(L.multiplyUnsafe(q));if(j.is0())throw new Error("point at infinify");return j.assertValidity(),j}hasHighS(){return v(this.s)}toBytes(y=g){if(ul(y),y==="der")return ea(Pn.hexFromSig(this));const w=o.toBytes(this.r),S=o.toBytes(this.s);if(y==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return fr(Uint8Array.of(this.recovery),w,S)}return fr(w,S)}toHex(y){return _i(this.toBytes(y))}assertValidity(){}static fromCompact(y){return _.fromBytes(et("sig",y),"compact")}static fromDER(y){return _.fromBytes(et("sig",y),"der")}normalizeS(){return this.hasHighS()?new _(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return _i(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return _i(this.toBytes("compact"))}}const x=n.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");const y=la(m),w=m.length*8-c;return w>0?y>>BigInt(w):y},$=n.bits2int_modN||function(m){return o.create(x(m))},T=vs(c);function U(m){return nl("num < 2^"+c,m,Tn,T),o.toBytes(m)}function F(m,y){return Kr(m,void 0,"message"),y?Kr(e(m),void 0,"prehashed message"):m}function P(m,y,w){if(["recovered","canonical"].some(q=>q in w))throw new Error("sign() legacy options not supported");const{lowS:S,prehash:A,extraEntropy:I}=ll(w,p);m=F(m,A);const O=$(m),R=Oi(o,y),L=[U(R),U(O)];if(I!=null&&I!==!1){const q=I===!0?r(h.secretKey):I;L.push(et("extraEntropy",q))}const C=fr(...L),k=O;function N(q){const j=x(q);if(!o.isValidNot0(j))return;const W=o.inv(j),V=t.BASE.multiply(j).toAffine(),Z=o.create(V.x);if(Z===Tn)return;const Q=o.create(W*o.create(k+Z*R));if(Q===Tn)return;let ee=(V.x===Z?0:2)|Number(V.y&Bi),ie=Q;return S&&v(Q)&&(ie=o.neg(Q),ee^=1),new _(Z,ie,ee)}return{seed:C,k2sig:N}}function z(m,y,w={}){m=et("message",m);const{seed:S,k2sig:A}=P(m,y,w);return FS(e.outputLen,o.BYTES,i)(S,A)}function M(m){let y;const w=typeof m=="string"||Jo(m),S=!w&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!w&&!S)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(S)y=new _(m.r,m.s);else if(w){try{y=_.fromBytes(et("sig",m),"der")}catch(A){if(!(A instanceof Pn.Err))throw A}if(!y)try{y=_.fromBytes(et("sig",m),"compact")}catch{return!1}}return y||!1}function E(m,y,w,S={}){const{lowS:A,prehash:I,format:O}=ll(S,p);if(w=et("publicKey",w),y=F(et("message",y),I),"strict"in S)throw new Error("options.strict was renamed to lowS");const R=O===void 0?M(m):_.fromBytes(et("sig",m),O);if(R===!1)return!1;try{const L=t.fromBytes(w);if(A&&R.hasHighS())return!1;const{r:C,s:k}=R,N=$(y),q=o.inv(k),j=o.create(N*q),W=o.create(C*q),V=t.BASE.multiplyUnsafe(j).add(L.multiplyUnsafe(W));return V.is0()?!1:o.create(V.x)===C}catch{return!1}}function b(m,y,w={}){const{prehash:S}=ll(w,p);return y=F(y,S),_.fromBytes(m,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h,Point:t,sign:z,verify:E,recoverPublicKey:b,Signature:_,hash:e})}function gI(t){const e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},n=t.Fp;let r=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0;const i=mr(e.n,{BITS:t.nBitLength,allowedLengths:r,modFromBytes:t.wrapPrivateKey}),s={Fp:n,Fn:i,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function yI(t){const{CURVE:e,curveOpts:n}=gI(t),r={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:n,hash:t.hash,ecdsaOpts:r}}function bI(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,zg(n.Fn.ORDER,n.Fn.BITS))})}function wI(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=yI(t),s=hI(e,n),o=pI(s,r,i);return bI(t,o)}function fl(t,e){const n=r=>wI({...t,hash:r});return{...n(e),create:n}}const r1={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},i1={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},s1={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},mI=mr(r1.p),vI=mr(i1.p),EI=mr(s1.p),xI=fl({...r1,Fp:mI,lowS:!1},na);fl({...i1,Fp:vI,lowS:!1},O5),fl({...s1,Fp:EI,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},B5);const _I=xI,o1="base10",ut="base16",vt="base64pad",vr="base64url",xs="utf8",a1=0,Rn=1,_s=2,SI=0,c1=1,Ss=12,hl=32;function II(){const t=cl.utils.randomPrivateKey(),e=cl.getPublicKey(t);return{privateKey:bt(t,ut),publicKey:bt(e,ut)}}function dl(){const t=Hr(hl);return bt(t,ut)}function AI(t,e){const n=cl.getSharedSecret(Ct(t,ut),Ct(e,ut)),r=CS(aa,n,void 0,void 0,hl);return bt(r,ut)}function ya(t){const e=aa(Ct(t,ut));return bt(e,ut)}function Ft(t){const e=aa(Ct(t,xs));return bt(e,ut)}function u1(t){return Ct(`${t}`,o1)}function Zr(t){return Number(bt(t,o1))}function l1(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function f1(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=(4-e.length%4)%4;return e+"=".repeat(n)}function BI(t){const e=u1(typeof t.type<"u"?t.type:a1);if(Zr(e)===Rn&&typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const n=typeof t.senderPublicKey<"u"?Ct(t.senderPublicKey,ut):void 0,r=typeof t.iv<"u"?Ct(t.iv,ut):Hr(Ss),i=Ct(t.symKey,ut),s=Bg(i,r).encrypt(Ct(t.message,xs)),o=h1({type:e,sealed:s,iv:r,senderPublicKey:n});return t.encoding===vr?l1(o):o}function OI(t){const e=Ct(t.symKey,ut),{sealed:n,iv:r}=Is({encoded:t.encoded,encoding:t.encoding}),i=Bg(e,r).decrypt(n);if(i===null)throw new Error("Failed to decrypt");return bt(i,xs)}function DI(t,e){const n=u1(_s),r=Hr(Ss),i=Ct(t,xs),s=h1({type:n,sealed:i,iv:r});return e===vr?l1(s):s}function $I(t,e){const{sealed:n}=Is({encoded:t,encoding:e});return bt(n,xs)}function h1(t){if(Zr(t.type)===_s)return bt(cs([t.type,t.sealed]),vt);if(Zr(t.type)===Rn){if(typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return bt(cs([t.type,t.senderPublicKey,t.iv,t.sealed]),vt)}return bt(cs([t.type,t.iv,t.sealed]),vt)}function Is(t){const e=(t.encoding||vt)===vr?f1(t.encoded):t.encoded,n=Ct(e,vt),r=n.slice(SI,c1),i=c1;if(Zr(r)===Rn){const c=i+hl,u=c+Ss,l=n.slice(i,c),f=n.slice(c,u),d=n.slice(u);return{type:r,sealed:d,iv:f,senderPublicKey:l}}if(Zr(r)===_s){const c=n.slice(i),u=Hr(Ss);return{type:r,sealed:c,iv:u}}const s=i+Ss,o=n.slice(i,s),a=n.slice(s);return{type:r,sealed:a,iv:o}}function PI(t,e){const n=Is({encoded:t,encoding:e?.encoding});return d1({type:Zr(n.type),senderPublicKey:typeof n.senderPublicKey<"u"?bt(n.senderPublicKey,ut):void 0,receiverPublicKey:e?.receiverPublicKey})}function d1(t){const e=t?.type||a1;if(e===Rn){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 p1(t){return t.type===Rn&&typeof t.senderPublicKey=="string"&&typeof t.receiverPublicKey=="string"}function g1(t){return t.type===_s}function TI(t){const e=Buffer.from(t.x,"base64"),n=Buffer.from(t.y,"base64");return cs([new Uint8Array([4]),e,n])}function RI(t,e){const[n,r,i]=t.split("."),s=Buffer.from(f1(i),"base64");if(s.length!==64)throw new Error("Invalid signature length");const o=s.slice(0,32),a=s.slice(32,64),c=`${n}.${r}`,u=aa(c),l=TI(e);if(!_I.verify(cs([o,a]),u,l))throw new Error("Invalid signature");return hc(t).payload}const NI="irn";function ba(t){return t?.relay||{protocol:NI}}function Di(t){const e=u_[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}var CI=Object.defineProperty,UI=Object.defineProperties,FI=Object.getOwnPropertyDescriptors,y1=Object.getOwnPropertySymbols,LI=Object.prototype.hasOwnProperty,kI=Object.prototype.propertyIsEnumerable,b1=(t,e,n)=>e in t?CI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,pl=(t,e)=>{for(var n in e||(e={}))LI.call(e,n)&&b1(t,n,e[n]);if(y1)for(var n of y1(e))kI.call(e,n)&&b1(t,n,e[n]);return t},qI=(t,e)=>UI(t,FI(e));function MI(t,e="-"){const n={},r="relay"+e;return Object.keys(t).forEach(i=>{if(i.startsWith(r)){const s=i.replace(r,""),o=t[i];n[s]=o}}),n}function w1(t){if(!t.includes("wc:")){const u=z0(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(":"),n=t.indexOf("?")!==-1?t.indexOf("?"):void 0,r=t.substring(0,e),i=t.substring(e+1,n).split("@"),s=typeof n<"u"?t.substring(n):"",o=new URLSearchParams(s),a=Object.fromEntries(o.entries()),c=typeof a.methods=="string"?a.methods.split(","):void 0;return{protocol:r,topic:jI(i[0]),version:parseInt(i[1],10),symKey:a.symKey,relay:MI(a),methods:c,expiryTimestamp:a.expiryTimestamp?parseInt(a.expiryTimestamp,10):void 0}}function jI(t){return t.startsWith("//")?t.substring(2):t}function zI(t,e="-"){const n="relay",r={};return Object.keys(t).forEach(i=>{const s=i,o=n+e+s;t[s]&&(r[o]=t[s])}),r}function m1(t){const e=new URLSearchParams,n=pl(pl(qI(pl({},zI(t.relay)),{symKey:t.symKey}),t.expiryTimestamp&&{expiryTimestamp:t.expiryTimestamp.toString()}),t.methods&&{methods:t.methods.join(",")});return Object.entries(n).sort(([r],[i])=>r.localeCompare(i)).forEach(([r,i])=>{i!==void 0&&e.append(r,String(i))}),`${t.protocol}:${t.topic}@${t.version}?${e}`}function wa(t,e,n){return`${t}?wc_ev=${n}&topic=${e}`}var HI=Object.defineProperty,VI=Object.defineProperties,KI=Object.getOwnPropertyDescriptors,v1=Object.getOwnPropertySymbols,GI=Object.prototype.hasOwnProperty,WI=Object.prototype.propertyIsEnumerable,E1=(t,e,n)=>e in t?HI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ZI=(t,e)=>{for(var n in e||(e={}))GI.call(e,n)&&E1(t,n,e[n]);if(v1)for(var n of v1(e))WI.call(e,n)&&E1(t,n,e[n]);return t},YI=(t,e)=>VI(t,KI(e));function $i(t){const e=[];return t.forEach(n=>{const[r,i]=n.split(":");e.push(`${r}:${i}`)}),e}function XI(t){const e=[];return Object.values(t).forEach(n=>{e.push(...$i(n.accounts))}),e}function JI(t,e){const n=[];return Object.values(t).forEach(r=>{$i(r.accounts).includes(e)&&n.push(...r.methods)}),n}function QI(t,e){const n=[];return Object.values(t).forEach(r=>{$i(r.accounts).includes(e)&&n.push(...r.events)}),n}function x1(t){return t.includes(":")}function e9(t){return x1(t)?t.split(":")[0]:t}function _1(t){var e,n,r;const i={};if(!As(t))return i;for(const[s,o]of Object.entries(t)){const a=x1(s)?[s]:o.chains,c=o.methods||[],u=o.events||[],l=e9(s);i[l]=YI(ZI({},i[l]),{chains:zr(a,(e=i[l])==null?void 0:e.chains),methods:zr(c,(n=i[l])==null?void 0:n.methods),events:zr(u,(r=i[l])==null?void 0:r.events)})}return i}function t9(t){const e={};return t?.forEach(n=>{var r;const[i,s]=n.split(":");e[i]||(e[i]={accounts:[],chains:[],events:[],methods:[]}),e[i].accounts.push(n),(r=e[i].chains)==null||r.push(`${i}:${s}`)}),e}function S1(t,e){e=e.map(r=>r.replace("did:pkh:",""));const n=t9(e);for(const[r,i]of Object.entries(n))i.methods?i.methods=zr(i.methods,t):i.methods=t,i.events=["chainChanged","accountsChanged"];return n}function n9(t,e){var n,r,i,s,o,a;const c=_1(t),u=_1(e),l={},f=Object.keys(c).concat(Object.keys(u));for(const d of f)l[d]={chains:zr((n=c[d])==null?void 0:n.chains,(r=u[d])==null?void 0:r.chains),methods:zr((i=c[d])==null?void 0:i.methods,(s=u[d])==null?void 0:s.methods),events:zr((o=c[d])==null?void 0:o.events,(a=u[d])==null?void 0:a.events)};return l}const r9={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}},i9={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 G(t,e){const{message:n,code:r}=i9[t];return{message:e?`${n} ${e}`:n,code:r}}function Ee(t,e){const{message:n,code:r}=r9[t];return{message:e?`${n} ${e}`:n,code:r}}function Pi(t,e){return Array.isArray(t)?typeof e<"u"&&t.length?t.every(e):!0:!1}function As(t){return Object.getPrototypeOf(t)===Object.prototype&&Object.keys(t).length}function Pe(t){return typeof t>"u"}function Ie(t,e){return e&&Pe(t)?!0:typeof t=="string"&&!!t.trim().length}function gl(t,e){return e&&Pe(t)?!0:typeof t=="number"&&!isNaN(t)}function s9(t,e){const{requiredNamespaces:n}=e,r=Object.keys(t.namespaces),i=Object.keys(n);let s=!0;return Mr(i,r)?(r.forEach(o=>{const{accounts:a,methods:c,events:u}=t.namespaces[o],l=$i(a),f=n[o];(!Mr(T0(o,f),l)||!Mr(f.methods,c)||!Mr(f.events,u))&&(s=!1)}),s):!1}function ma(t){return Ie(t,!1)&&t.includes(":")?t.split(":").length===2:!1}function o9(t){if(Ie(t,!1)&&t.includes(":")){const e=t.split(":");if(e.length===3){const n=e[0]+":"+e[1];return!!e[2]&&ma(n)}}return!1}function a9(t){function e(n){try{return typeof new URL(n)<"u"}catch{return!1}}try{if(Ie(t,!1)){if(e(t))return!0;const n=z0(t);return e(n)}}catch{}return!1}function c9(t){var e;return(e=t?.proposer)==null?void 0:e.publicKey}function u9(t){return t?.topic}function l9(t,e){let n=null;return Ie(t?.publicKey,!1)||(n=G("MISSING_OR_INVALID",`${e} controller public key should be a string`)),n}function I1(t){let e=!0;return Pi(t)?t.length&&(e=t.every(n=>Ie(n,!1))):e=!1,e}function f9(t,e,n){let r=null;return Pi(e)&&e.length?e.forEach(i=>{r||ma(i)||(r=Ee("UNSUPPORTED_CHAINS",`${n}, chain ${i} should be a string and conform to "namespace:chainId" format`))}):ma(t)||(r=Ee("UNSUPPORTED_CHAINS",`${n}, 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"] }`)),r}function h9(t,e,n){let r=null;return Object.entries(t).forEach(([i,s])=>{if(r)return;const o=f9(i,T0(i,s),`${e} ${n}`);o&&(r=o)}),r}function d9(t,e){let n=null;return Pi(t)?t.forEach(r=>{n||o9(r)||(n=Ee("UNSUPPORTED_ACCOUNTS",`${e}, account ${r} should be a string and conform to "namespace:chainId:address" format`))}):n=Ee("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),n}function p9(t,e){let n=null;return Object.values(t).forEach(r=>{if(n)return;const i=d9(r?.accounts,`${e} namespace`);i&&(n=i)}),n}function g9(t,e){let n=null;return I1(t?.methods)?I1(t?.events)||(n=Ee("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):n=Ee("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),n}function A1(t,e){let n=null;return Object.values(t).forEach(r=>{if(n)return;const i=g9(r,`${e}, namespace`);i&&(n=i)}),n}function y9(t,e,n){let r=null;if(t&&As(t)){const i=A1(t,e);i&&(r=i);const s=h9(t,e,n);s&&(r=s)}else r=G("MISSING_OR_INVALID",`${e}, ${n} should be an object with data`);return r}function yl(t,e){let n=null;if(t&&As(t)){const r=A1(t,e);r&&(n=r);const i=p9(t,e);i&&(n=i)}else n=G("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return n}function B1(t){return Ie(t.protocol,!0)}function b9(t,e){let n=!1;return e&&!t?n=!0:t&&Pi(t)&&t.length&&t.forEach(r=>{n=B1(r)}),n}function w9(t){return typeof t=="number"}function Et(t){return typeof t<"u"&&typeof t!==null}function m9(t){return!(!t||typeof t!="object"||!t.code||!gl(t.code,!1)||!t.message||!Ie(t.message,!1))}function v9(t){return!(Pe(t)||!Ie(t.method,!1))}function E9(t){return!(Pe(t)||Pe(t.result)&&Pe(t.error)||!gl(t.id,!1)||!Ie(t.jsonrpc,!1))}function x9(t){return!(Pe(t)||!Ie(t.name,!1))}function O1(t,e){return!(!ma(e)||!XI(t).includes(e))}function _9(t,e,n){return Ie(n,!1)?JI(t,e).includes(n):!1}function S9(t,e,n){return Ie(n,!1)?QI(t,e).includes(n):!1}function D1(t,e,n){let r=null;const i=I9(t),s=A9(e),o=Object.keys(i),a=Object.keys(s),c=$1(Object.keys(t)),u=$1(Object.keys(e)),l=c.filter(f=>!u.includes(f));return l.length&&(r=G("NON_CONFORMING_NAMESPACES",`${n} namespaces keys don't satisfy requiredNamespaces.
14
+ ***************************************************************************** */var Au=function(t,e){return Au=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var i in r)r.hasOwnProperty(i)&&(n[i]=r[i])},Au(t,e)};function I6(t,e){Au(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var Ou=function(){return Ou=Object.assign||function(e){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},Ou.apply(this,arguments)};function B6(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n}function $6(t,e,n,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,n):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function A6(t,e){return function(n,r){e(n,r,t)}}function O6(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function D6(t,e,n,r){function i(s){return s instanceof n?s:new n(function(o){o(s)})}return new(n||(n=Promise))(function(s,o){function a(l){try{f(r.next(l))}catch(h){o(h)}}function c(l){try{f(r.throw(l))}catch(h){o(h)}}function f(l){l.done?s(l.value):i(l.value).then(a,c)}f((r=r.apply(t,e||[])).next())})}function P6(t,e){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,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(f){return function(l){return c([f,l])}}function c(f){if(r)throw new TypeError("Generator is already executing.");for(;n;)try{if(r=1,i&&(s=f[0]&2?i.return:f[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,f[1])).done)return s;switch(i=0,s&&(f=[f[0]&2,s.value]),f[0]){case 0:case 1:s=f;break;case 4:return n.label++,{value:f[1],done:!1};case 5:n.label++,i=f[1],f=[0];continue;case 7:f=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(f[0]===6||f[0]===2)){n=0;continue}if(f[0]===3&&(!s||f[1]>s[0]&&f[1]<s[3])){n.label=f[1];break}if(f[0]===6&&n.label<s[1]){n.label=s[1],s=f;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(f);break}s[2]&&n.ops.pop(),n.trys.pop();continue}f=e.call(t,n)}catch(l){f=[6,l],i=0}finally{r=s=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}function R6(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]}function T6(t,e){for(var n in t)n!=="default"&&!e.hasOwnProperty(n)&&(e[n]=t[n])}function Du(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function S1(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function N6(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(S1(arguments[e]));return t}function U6(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),i=0,e=0;e<n;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,i++)r[i]=s[o];return r}function To(t){return this instanceof To?(this.v=t,this):new To(t)}function C6(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(t,e||[]),i,s=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(d){r[d]&&(i[d]=function(u){return new Promise(function(b,w){s.push([d,u,b,w])>1||a(d,u)})})}function a(d,u){try{c(r[d](u))}catch(b){h(s[0][3],b)}}function c(d){d.value instanceof To?Promise.resolve(d.value.v).then(f,l):h(s[0][2],d)}function f(d){a("next",d)}function l(d){a("throw",d)}function h(d,u){d(u),s.shift(),s.length&&a(s[0][0],s[0][1])}}function L6(t){var e,n;return e={},r("next"),r("throw",function(i){throw i}),r("return"),e[Symbol.iterator]=function(){return this},e;function r(i,s){e[i]=t[i]?function(o){return(n=!n)?{value:To(t[i](o)),done:i==="return"}:s?s(o):o}:s}}function F6(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof Du=="function"?Du(t):t[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[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(f){s({value:f,done:a})},o)}}function k6(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function q6(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function j6(t){return t&&t.__esModule?t:{default:t}}function M6(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function z6(t,e,n){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,n),n}var H6=Object.freeze({__proto__:null,__extends:I6,get __assign(){return Ou},__rest:B6,__decorate:$6,__param:A6,__metadata:O6,__awaiter:D6,__generator:P6,__createBinding:R6,__exportStar:T6,__values:Du,__read:S1,__spread:N6,__spreadArrays:U6,__await:To,__asyncGenerator:C6,__asyncDelegator:L6,__asyncValues:F6,__makeTemplateObject:k6,__importStar:q6,__importDefault:j6,__classPrivateFieldGet:M6,__classPrivateFieldSet:z6}),sc=e1(H6),Pu={},No={},I1;function V6(){if(I1)return No;I1=1,Object.defineProperty(No,"__esModule",{value:!0}),No.delay=void 0;function t(e){return new Promise(n=>{setTimeout(()=>{n(!0)},e)})}return No.delay=t,No}var Yi={},Ru={},Xi={},B1;function K6(){return B1||(B1=1,Object.defineProperty(Xi,"__esModule",{value:!0}),Xi.ONE_THOUSAND=Xi.ONE_HUNDRED=void 0,Xi.ONE_HUNDRED=100,Xi.ONE_THOUSAND=1e3),Xi}var Tu={},$1;function G6(){return $1||($1=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}(Tu)),Tu}var A1;function O1(){return A1||(A1=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=sc;e.__exportStar(K6(),t),e.__exportStar(G6(),t)}(Ru)),Ru}var D1;function Z6(){if(D1)return Yi;D1=1,Object.defineProperty(Yi,"__esModule",{value:!0}),Yi.fromMiliseconds=Yi.toMiliseconds=void 0;const t=O1();function e(r){return r*t.ONE_THOUSAND}Yi.toMiliseconds=e;function n(r){return Math.floor(r/t.ONE_THOUSAND)}return Yi.fromMiliseconds=n,Yi}var P1;function W6(){return P1||(P1=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=sc;e.__exportStar(V6(),t),e.__exportStar(Z6(),t)}(Pu)),Pu}var Ls={},R1;function Y6(){if(R1)return Ls;R1=1,Object.defineProperty(Ls,"__esModule",{value:!0}),Ls.Watch=void 0;class t{constructor(){this.timestamps=new Map}start(n){if(this.timestamps.has(n))throw new Error(`Watch already started for label: ${n}`);this.timestamps.set(n,{started:Date.now()})}stop(n){const r=this.get(n);if(typeof r.elapsed<"u")throw new Error(`Watch already stopped for label: ${n}`);const i=Date.now()-r.started;this.timestamps.set(n,{started:r.started,elapsed:i})}get(n){const r=this.timestamps.get(n);if(typeof r>"u")throw new Error(`No timestamp found for label: ${n}`);return r}elapsed(n){const r=this.get(n);return r.elapsed||Date.now()-r.started}}return Ls.Watch=t,Ls.default=t,Ls}var Nu={},Uo={},T1;function X6(){if(T1)return Uo;T1=1,Object.defineProperty(Uo,"__esModule",{value:!0}),Uo.IWatch=void 0;class t{}return Uo.IWatch=t,Uo}var N1;function J6(){return N1||(N1=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),sc.__exportStar(X6(),t)}(Nu)),Nu}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=sc;e.__exportStar(W6(),t),e.__exportStar(Y6(),t),e.__exportStar(J6(),t),e.__exportStar(O1(),t)})(Z);var Be={};Object.defineProperty(Be,"__esModule",{value:!0}),Be.getLocalStorage=Be.getLocalStorageOrThrow=Be.getCrypto=Be.getCryptoOrThrow=U1=Be.getLocation=Be.getLocationOrThrow=Co=Be.getNavigator=Be.getNavigatorOrThrow=nr=Be.getDocument=Be.getDocumentOrThrow=Be.getFromWindowOrThrow=Be.getFromWindow=void 0;function Ji(t){let e;return typeof window<"u"&&typeof window[t]<"u"&&(e=window[t]),e}Be.getFromWindow=Ji;function Fs(t){const e=Ji(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}Be.getFromWindowOrThrow=Fs;function Q6(){return Fs("document")}Be.getDocumentOrThrow=Q6;function eE(){return Ji("document")}var nr=Be.getDocument=eE;function tE(){return Fs("navigator")}Be.getNavigatorOrThrow=tE;function nE(){return Ji("navigator")}var Co=Be.getNavigator=nE;function rE(){return Fs("location")}Be.getLocationOrThrow=rE;function iE(){return Ji("location")}var U1=Be.getLocation=iE;function sE(){return Fs("crypto")}Be.getCryptoOrThrow=sE;function oE(){return Ji("crypto")}Be.getCrypto=oE;function aE(){return Fs("localStorage")}Be.getLocalStorageOrThrow=aE;function cE(){return Ji("localStorage")}Be.getLocalStorage=cE;var Uu={};Object.defineProperty(Uu,"__esModule",{value:!0});var C1=Uu.getWindowMetadata=void 0;const L1=Be;function fE(){let t,e;try{t=L1.getDocumentOrThrow(),e=L1.getLocationOrThrow()}catch{return null}function n(){const h=t.getElementsByTagName("link"),d=[];for(let u=0;u<h.length;u++){const b=h[u],w=b.getAttribute("rel");if(w&&w.toLowerCase().indexOf("icon")>-1){const E=b.getAttribute("href");if(E)if(E.toLowerCase().indexOf("https:")===-1&&E.toLowerCase().indexOf("http:")===-1&&E.indexOf("//")!==0){let A=e.protocol+"//"+e.host;if(E.indexOf("/")===0)A+=E;else{const P=e.pathname.split("/");P.pop();const _=P.join("/");A+=_+"/"+E}d.push(A)}else if(E.indexOf("//")===0){const A=e.protocol+E;d.push(A)}else d.push(E)}}return d}function r(...h){const d=t.getElementsByTagName("meta");for(let u=0;u<d.length;u++){const b=d[u],w=["itemprop","property","name"].map(E=>b.getAttribute(E)).filter(E=>E?h.includes(E):!1);if(w.length&&w){const E=b.getAttribute("content");if(E)return E}}return""}function i(){let h=r("name","og:site_name","og:title","twitter:title");return h||(h=t.title),h}function s(){return r("description","og:description","twitter:description","keywords")}const o=i(),a=s(),c=e.origin,f=n();return{description:a,url:c,icons:f,name:o}}C1=Uu.getWindowMetadata=fE;const uE="0.1.1";function lE(){return uE}class It extends Error{constructor(e,n={}){const r=(()=>{if(n.cause instanceof It){if(n.cause.details)return n.cause.details;if(n.cause.shortMessage)return n.cause.shortMessage}return n.cause&&"details"in n.cause&&typeof n.cause.details=="string"?n.cause.details:n.cause?.message?n.cause.message:n.details})(),i=n.cause instanceof It&&n.cause.docsPath||n.docsPath,o=`https://oxlib.sh${i??""}`,a=[e||"An error occurred.",...n.metaMessages?["",...n.metaMessages]:[],...r||i?["",r?`Details: ${r}`:void 0,i?`See: ${o}`:void 0]:[]].filter(c=>typeof c=="string").join(`
15
+ `);super(a,n.cause?{cause:n.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@${lE()}`}),this.cause=n.cause,this.details=r,this.docs=o,this.docsPath=i,this.shortMessage=e}walk(e){return F1(this,e)}}function F1(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause?F1(t.cause,e):e?null:t}const ks=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function hE(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Lo(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Qi(t,...e){if(!hE(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 dE(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Lo(t.outputLen),Lo(t.blockLen)}function qs(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 k1(t,e){Qi(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function pE(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function qr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Cu(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function qn(t,e){return t<<32-e|t>>>e}const gE=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function bE(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function yE(t){for(let e=0;e<t.length;e++)t[e]=bE(t[e]);return t}const q1=gE?t=>t:yE;function wE(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function oc(t){return typeof t=="string"&&(t=wE(t)),Qi(t),t}function mE(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Qi(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}class Lu{}function ac(t){const e=r=>t().update(oc(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function j1(t=32){if(ks&&typeof ks.getRandomValues=="function")return ks.getRandomValues(new Uint8Array(t));if(ks&&typeof ks.randomBytes=="function")return Uint8Array.from(ks.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function vE(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,f=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+f,a,r)}function EE(t,e,n){return t&e^~t&n}function xE(t,e,n){return t&e^t&n^e&n}class M1 extends Lu{constructor(e,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=Cu(this.buffer)}update(e){qs(this),e=oc(e),Qi(e);const{view:n,buffer:r,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Cu(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){qs(this),k1(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,qr(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;vE(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Cu(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const rr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ct=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),cc=BigInt(2**32-1),z1=BigInt(32);function _E(t,e=!1){return e?{h:Number(t&cc),l:Number(t>>z1&cc)}:{h:Number(t>>z1&cc)|0,l:Number(t&cc)|0}}function H1(t,e=!1){const n=t.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:a}=_E(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const V1=(t,e,n)=>t>>>n,K1=(t,e,n)=>t<<32-n|e>>>n,js=(t,e,n)=>t>>>n|e<<32-n,Ms=(t,e,n)=>t<<32-n|e>>>n,fc=(t,e,n)=>t<<64-n|e>>>n-32,uc=(t,e,n)=>t>>>n-32|e<<64-n,SE=(t,e,n)=>t<<n|e>>>32-n,IE=(t,e,n)=>e<<n|t>>>32-n,BE=(t,e,n)=>e<<n-32|t>>>64-n,$E=(t,e,n)=>t<<n-32|e>>>64-n;function ir(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const AE=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),OE=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,DE=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),PE=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,RE=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),TE=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,NE=BigInt(0),Fo=BigInt(1),UE=BigInt(2),CE=BigInt(7),LE=BigInt(256),FE=BigInt(113),G1=[],Z1=[],W1=[];for(let t=0,e=Fo,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],G1.push(2*(5*r+n)),Z1.push((t+1)*(t+2)/2%64);let i=NE;for(let s=0;s<7;s++)e=(e<<Fo^(e>>CE)*FE)%LE,e&UE&&(i^=Fo<<(Fo<<BigInt(s))-Fo);W1.push(i)}const Y1=H1(W1,!0),kE=Y1[0],qE=Y1[1],X1=(t,e,n)=>n>32?BE(t,e,n):SE(t,e,n),J1=(t,e,n)=>n>32?$E(t,e,n):IE(t,e,n);function jE(t,e=24){const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let o=0;o<10;o++)n[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=n[c],l=n[c+1],h=X1(f,l,1)^n[a],d=J1(f,l,1)^n[a+1];for(let u=0;u<50;u+=10)t[o+u]^=h,t[o+u+1]^=d}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=Z1[o],c=X1(i,s,a),f=J1(i,s,a),l=G1[o];i=t[l],s=t[l+1],t[l]=c,t[l+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)n[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~n[(a+2)%10]&n[(a+4)%10]}t[0]^=kE[r],t[1]^=qE[r]}qr(n)}class Fu extends Lu{constructor(e,n,r,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=s,Lo(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=pE(this.state)}clone(){return this._cloneInto()}keccak(){q1(this.state32),jE(this.state32,this.rounds),q1(this.state32),this.posOut=0,this.pos=0}update(e){qs(this),e=oc(e),Qi(e);const{blockLen:n,state:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(n-this.pos,i-s);for(let a=0;a<o;a++)r[this.pos++]^=e[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:n,pos:r,blockLen:i}=this;e[r]^=n,(n&128)!==0&&r===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){qs(this,!1),Qi(e),this.finish();const n=this.state,{blockLen:r}=this;for(let i=0,s=e.length;i<s;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,s-i);e.set(n.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 Lo(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(k1(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,qr(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new Fu(n,r,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=r,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}}const ME=(t,e,n)=>ac(()=>new Fu(e,t,n)),zE=ME(1,136,256/8),HE=Uint32Array.from([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]),jr=new Uint32Array(64);class VE extends M1{constructor(e=32){super(64,e,8,!1),this.A=rr[0]|0,this.B=rr[1]|0,this.C=rr[2]|0,this.D=rr[3]|0,this.E=rr[4]|0,this.F=rr[5]|0,this.G=rr[6]|0,this.H=rr[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[e,n,r,i,s,o,a,c]}set(e,n,r,i,s,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let h=0;h<16;h++,n+=4)jr[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const d=jr[h-15],u=jr[h-2],b=qn(d,7)^qn(d,18)^d>>>3,w=qn(u,17)^qn(u,19)^u>>>10;jr[h]=w+jr[h-7]+b+jr[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const d=qn(a,6)^qn(a,11)^qn(a,25),u=l+d+EE(a,c,f)+HE[h]+jr[h]|0,w=(qn(r,2)^qn(r,13)^qn(r,22))+xE(r,i,s)|0;l=f,f=c,c=a,a=o+u|0,o=s,s=i,i=r,r=u+w|0}r=r+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,f=f+this.G|0,l=l+this.H|0,this.set(r,i,s,o,a,c,f,l)}roundClean(){qr(jr)}destroy(){this.set(0,0,0,0,0,0,0,0),qr(this.buffer)}}const Q1=H1(["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))),KE=Q1[0],GE=Q1[1],Mr=new Uint32Array(80),zr=new Uint32Array(80);class ep extends M1{constructor(e=64){super(128,e,16,!1),this.Ah=ft[0]|0,this.Al=ft[1]|0,this.Bh=ft[2]|0,this.Bl=ft[3]|0,this.Ch=ft[4]|0,this.Cl=ft[5]|0,this.Dh=ft[6]|0,this.Dl=ft[7]|0,this.Eh=ft[8]|0,this.El=ft[9]|0,this.Fh=ft[10]|0,this.Fl=ft[11]|0,this.Gh=ft[12]|0,this.Gl=ft[13]|0,this.Hh=ft[14]|0,this.Hl=ft[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:h,Fl:d,Gh:u,Gl:b,Hh:w,Hl:E}=this;return[e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E]}set(e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=h|0,this.Fl=d|0,this.Gh=u|0,this.Gl=b|0,this.Hh=w|0,this.Hl=E|0}process(e,n){for(let _=0;_<16;_++,n+=4)Mr[_]=e.getUint32(n),zr[_]=e.getUint32(n+=4);for(let _=16;_<80;_++){const x=Mr[_-15]|0,D=zr[_-15]|0,U=js(x,D,1)^js(x,D,8)^V1(x,D,7),C=Ms(x,D,1)^Ms(x,D,8)^K1(x,D,7),L=Mr[_-2]|0,O=zr[_-2]|0,M=js(L,O,19)^fc(L,O,61)^V1(L,O,6),q=Ms(L,O,19)^uc(L,O,61)^K1(L,O,6),y=DE(C,q,zr[_-7],zr[_-16]),p=PE(y,U,M,Mr[_-7],Mr[_-16]);Mr[_]=p|0,zr[_]=y|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:h,El:d,Fh:u,Fl:b,Gh:w,Gl:E,Hh:A,Hl:P}=this;for(let _=0;_<80;_++){const x=js(h,d,14)^js(h,d,18)^fc(h,d,41),D=Ms(h,d,14)^Ms(h,d,18)^uc(h,d,41),U=h&u^~h&w,C=d&b^~d&E,L=RE(P,D,C,GE[_],zr[_]),O=TE(L,A,x,U,KE[_],Mr[_]),M=L|0,q=js(r,i,28)^fc(r,i,34)^fc(r,i,39),y=Ms(r,i,28)^uc(r,i,34)^uc(r,i,39),p=r&s^r&a^s&a,m=i&o^i&c^o&c;A=w|0,P=E|0,w=u|0,E=b|0,u=h|0,b=d|0,{h,l:d}=ir(f|0,l|0,O|0,M|0),f=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=AE(M,y,m);r=OE(g,O,q,p),i=g|0}({h:r,l:i}=ir(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=ir(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=ir(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=ir(this.Dh|0,this.Dl|0,f|0,l|0),{h,l:d}=ir(this.Eh|0,this.El|0,h|0,d|0),{h:u,l:b}=ir(this.Fh|0,this.Fl|0,u|0,b|0),{h:w,l:E}=ir(this.Gh|0,this.Gl|0,w|0,E|0),{h:A,l:P}=ir(this.Hh|0,this.Hl|0,A|0,P|0),this.set(r,i,s,o,a,c,f,l,h,d,u,b,w,E,A,P)}roundClean(){qr(Mr,zr)}destroy(){qr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class ZE extends ep{constructor(){super(48),this.Ah=ct[0]|0,this.Al=ct[1]|0,this.Bh=ct[2]|0,this.Bl=ct[3]|0,this.Ch=ct[4]|0,this.Cl=ct[5]|0,this.Dh=ct[6]|0,this.Dl=ct[7]|0,this.Eh=ct[8]|0,this.El=ct[9]|0,this.Fh=ct[10]|0,this.Fl=ct[11]|0,this.Gh=ct[12]|0,this.Gl=ct[13]|0,this.Hh=ct[14]|0,this.Hl=ct[15]|0}}const lc=ac(()=>new VE),WE=ac(()=>new ep),YE=ac(()=>new ZE);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const ku=BigInt(0),hc=BigInt(1);function ko(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Hr(t){if(!ko(t))throw new Error("Uint8Array expected")}function qo(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function dc(t){const e=t.toString(16);return e.length&1?"0"+e:e}function tp(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?ku:BigInt("0x"+t)}const np=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",XE=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function es(t){if(Hr(t),np)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=XE[t[n]];return e}const sr={_0:48,_9:57,A:65,F:70,a:97,f:102};function rp(t){if(t>=sr._0&&t<=sr._9)return t-sr._0;if(t>=sr.A&&t<=sr.F)return t-(sr.A-10);if(t>=sr.a&&t<=sr.f)return t-(sr.a-10)}function pc(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(np)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=rp(t.charCodeAt(s)),a=rp(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)}r[i]=o*16+a}return r}function Bt(t){return tp(es(t))}function ip(t){return Hr(t),tp(es(Uint8Array.from(t).reverse()))}function Le(t,e){return pc(t.toString(16).padStart(e*2,"0"))}function sp(t,e){return Le(t,e).reverse()}function ut(t,e,n){let r;if(typeof e=="string")try{r=pc(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(ko(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}function De(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Hr(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}function qu(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}const ju=t=>typeof t=="bigint"&&ku<=t;function Mu(t,e,n){return ju(t)&&ju(e)&&ju(n)&&e<=t&&t<n}function zs(t,e,n,r){if(!Mu(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function jo(t){let e;for(e=0;t>ku;t>>=hc,e+=1);return e}function JE(t,e){return t>>BigInt(e)&hc}const ts=t=>(hc<<BigInt(t))-hc,zu=t=>new Uint8Array(t),op=t=>Uint8Array.from(t);function QE(t,e,n){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 n!="function")throw new Error("hmacFn must be a function");let r=zu(t),i=zu(t),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},a=(...h)=>n(i,r,...h),c=(h=zu(0))=>{i=a(op([0]),h),r=a(),h.length!==0&&(i=a(op([1]),h),r=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const d=[];for(;h<e;){r=a();const u=r.slice();d.push(u),h+=r.length}return De(...d)};return(h,d)=>{o(),c(h);let u;for(;!(u=d(f()));)c();return o(),u}}const e4={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"||ko(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 Mo(t,e,n={}){const r=(i,s,o)=>{const a=e4[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))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return t}const ap=()=>{throw new Error("not implemented")};function Hu(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}function t4(t,e){if(hp(t)>e)throw new y4({givenSize:hp(t),maxSize:e})}const or={zero:48,nine:57,A:65,F:70,a:97,f:102};function cp(t){if(t>=or.zero&&t<=or.nine)return t-or.zero;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 n4(t,e={}){const{dir:n,size:r=32}=e;if(r===0)return t;if(t.length>r)throw new w4({size:t.length,targetSize:r,type:"Bytes"});const i=new Uint8Array(r);for(let s=0;s<r;s++){const o=n==="right";i[o?s:r-s-1]=t[o?s:t.length-s-1]}return i}function Vu(t,e){if(Gu(t)>e)throw new f4({givenSize:Gu(t),maxSize:e})}function fp(t,e={}){const{dir:n,size:r=32}=e;if(r===0)return t;const i=t.replace("0x","");if(i.length>r*2)throw new u4({size:Math.ceil(i.length/2),targetSize:r,type:"Hex"});return`0x${i[n==="right"?"padEnd":"padStart"](r*2,"0")}`}const r4=new TextEncoder,i4=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function up(...t){return`0x${t.reduce((e,n)=>e+n.replace("0x",""),"")}`}function s4(t,e={}){const n=`0x${Number(t)}`;return typeof e.size=="number"?(Vu(n,e.size),gc(n,e.size)):n}function lp(t,e={}){let n="";for(let i=0;i<t.length;i++)n+=i4[t[i]];const r=`0x${n}`;return typeof e.size=="number"?(Vu(r,e.size),Ku(r,e.size)):r}function o4(t,e={}){const{signed:n,size:r}=e,i=BigInt(t);let s;r?n?s=(1n<<BigInt(r)*8n-1n)-1n:s=2n**(BigInt(r)*8n)-1n:typeof t=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&n?-s-1n:0;if(s&&i>s||i<o){const f=typeof t=="bigint"?"n":"";throw new c4({max:s?`${s}${f}`:void 0,min:`${o}${f}`,signed:n,size:r,value:`${t}${f}`})}const c=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?gc(c,r):c}function a4(t,e={}){return lp(r4.encode(t),e)}function gc(t,e){return fp(t,{dir:"left",size:e})}function Ku(t,e){return fp(t,{dir:"right",size:e})}function Gu(t){return Math.ceil((t.length-2)/2)}class c4 extends It{constructor({max:e,min:n,signed:r,size:i,value:s}){super(`Number \`${s}\` is not in safe${i?` ${i*8}-bit`:""}${r?" signed":" unsigned"} integer range ${e?`(\`${n}\` to \`${e}\`)`:`(above \`${n}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class f4 extends It{constructor({givenSize:e,maxSize:n}){super(`Size cannot exceed \`${n}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}}class u4 extends It{constructor({size:e,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}const l4=new TextEncoder;function h4(t){return t instanceof Uint8Array?t:typeof t=="string"?p4(t):d4(t)}function d4(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function p4(t,e={}){const{size:n}=e;let r=t;n&&(Vu(t,n),r=Ku(t,n));let i=r.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 f=cp(i.charCodeAt(c++)),l=cp(i.charCodeAt(c++));if(f===void 0||l===void 0)throw new It(`Invalid byte sequence ("${i[c-2]}${i[c-1]}" in "${i}").`);o[a]=f*16+l}return o}function g4(t,e={}){const{size:n}=e,r=l4.encode(t);return typeof n=="number"?(t4(r,n),b4(r,n)):r}function b4(t,e){return n4(t,{dir:"right",size:e})}function hp(t){return t.length}class y4 extends It{constructor({givenSize:e,maxSize:n}){super(`Size cannot exceed \`${n}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}}class w4 extends It{constructor({size:e,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}function m4(t,e={}){const{as:n=typeof t=="string"?"Hex":"Bytes"}=e,r=zE(h4(t));return n==="Bytes"?r:lp(r)}class v4 extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const n=super.get(e);return super.has(e)&&n!==void 0&&(this.delete(e),super.set(e,n)),n}set(e,n){if(super.set(e,n),this.maxSize&&this.size>this.maxSize){const r=this.keys().next().value;r&&this.delete(r)}return this}}const Zu={checksum:new v4(8192)}.checksum,E4=/^0x[a-fA-F0-9]{40}$/;function dp(t,e={}){const{strict:n=!0}=e;if(!E4.test(t))throw new pp({address:t,cause:new _4});if(n){if(t.toLowerCase()===t)return;if(x4(t)!==t)throw new pp({address:t,cause:new S4})}}function x4(t){if(Zu.has(t))return Zu.get(t);dp(t,{strict:!1});const e=t.substring(2).toLowerCase(),n=m4(g4(e),{as:"Bytes"}),r=e.split("");for(let s=0;s<40;s+=2)n[s>>1]>>4>=8&&r[s]&&(r[s]=r[s].toUpperCase()),(n[s>>1]&15)>=8&&r[s+1]&&(r[s+1]=r[s+1].toUpperCase());const i=`0x${r.join("")}`;return Zu.set(t,i),i}class pp extends It{constructor({address:e,cause:n}){super(`Address "${e}" is invalid.`,{cause:n}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class _4 extends It{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 S4 extends It{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}const I4=/^(.*)\[([0-9]*)\]$/,B4=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,$4=/^(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 Wu(t,e){if(t.length!==e.length)throw new O4({expectedLength:t.length,givenLength:e.length});const n=[];for(let r=0;r<t.length;r++){const i=t[r],s=e[r];n.push(Wu.encode(i,s))}return up(...n)}(function(t){function e(n,r,i=!1){if(n==="address"){const c=r;return dp(c),gc(c.toLowerCase(),i?32:0)}if(n==="string")return a4(r);if(n==="bytes")return r;if(n==="bool")return gc(s4(r),i?32:1);const s=n.match($4);if(s){const[c,f,l="256"]=s,h=Number.parseInt(l,10)/8;return o4(r,{size:i?32:h,signed:f==="int"})}const o=n.match(B4);if(o){const[c,f]=o;if(Number.parseInt(f,10)!==(r.length-2)/2)throw new A4({expectedSize:Number.parseInt(f,10),value:r});return Ku(r,i?32:0)}const a=n.match(I4);if(a&&Array.isArray(r)){const[c,f]=a,l=[];for(let h=0;h<r.length;h++)l.push(e(f,r[h],!0));return l.length===0?"0x":up(...l)}throw new D4(n)}t.encode=e})(Wu||(Wu={}));class A4 extends It{constructor({expectedSize:e,value:n}){super(`Size of bytes "${n}" (bytes${Gu(n)}) does not match expected size (bytes${e}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class O4 extends It{constructor({expectedLength:e,givenLength:n}){super(["ABI encoding parameters/values length mismatch.",`Expected length (parameters): ${e}`,`Given length (values): ${n}`].join(`
16
+ `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.LengthMismatchError"})}}class D4 extends It{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 gp extends Lu{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,dE(e);const r=oc(n);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(r.length>i?e.create().update(r).digest():r);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),qr(s)}update(e){return qs(this),this.iHash.update(e),this}digestInto(e){qs(this),Qi(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:n,iHash:r,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=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const bp=(t,e,n)=>new gp(t,e).update(n).digest();bp.create=(t,e)=>new gp(t,e);const Ft=BigInt(0),$t=BigInt(1),ns=BigInt(2),P4=BigInt(3),yp=BigInt(4),wp=BigInt(5),mp=BigInt(8);function At(t,e){const n=t%e;return n>=Ft?n:e+n}function un(t,e,n){let r=t;for(;e-- >Ft;)r*=r,r%=n;return r}function Yu(t,e){if(t===Ft)throw new Error("invert: expected non-zero number");if(e<=Ft)throw new Error("invert: expected positive modulus, got "+e);let n=At(t,e),r=e,i=Ft,s=$t;for(;n!==Ft;){const a=r/n,c=r%n,f=i-s*a;r=n,n=c,i=s,s=f}if(r!==$t)throw new Error("invert: does not exist");return At(i,e)}function vp(t,e){const n=(t.ORDER+$t)/yp,r=t.pow(e,n);if(!t.eql(t.sqr(r),e))throw new Error("Cannot find square root");return r}function R4(t,e){const n=(t.ORDER-wp)/mp,r=t.mul(e,ns),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,ns),i),a=t.mul(s,t.sub(o,t.ONE));if(!t.eql(t.sqr(a),e))throw new Error("Cannot find square root");return a}function T4(t){if(t<BigInt(3))throw new Error("sqrt is not defined for small field");let e=t-$t,n=0;for(;e%ns===Ft;)e/=ns,n++;let r=ns;const i=Vr(t);for(;yc(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return vp;let s=i.pow(r,e);const o=(e+$t)/ns;return function(c,f){if(c.is0(f))return f;if(yc(c,f)!==1)throw new Error("Cannot find square root");let l=n,h=c.mul(c.ONE,s),d=c.pow(f,e),u=c.pow(f,o);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let b=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(b++,w=c.sqr(w),b===l)throw new Error("Cannot find square root");const E=$t<<BigInt(l-b-1),A=c.pow(h,E);l=b,h=c.sqr(A),d=c.mul(d,h),u=c.mul(u,A)}return u}}function N4(t){return t%yp===P4?vp:t%mp===wp?R4:T4(t)}const U4=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Ep(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=U4.reduce((r,i)=>(r[i]="function",r),e);return Mo(t,n)}function bc(t,e,n){if(n<Ft)throw new Error("invalid exponent, negatives unsupported");if(n===Ft)return t.ONE;if(n===$t)return e;let r=t.ONE,i=e;for(;n>Ft;)n&$t&&(r=t.mul(r,i)),i=t.sqr(i),n>>=$t;return r}function rs(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),i=e.reduce((o,a,c)=>t.is0(a)?o:(r[c]=o,t.mul(o,a)),t.ONE),s=t.inv(i);return e.reduceRight((o,a,c)=>t.is0(a)?o:(r[c]=t.mul(o,r[c]),t.mul(o,a)),s),r}function yc(t,e){const n=(t.ORDER-$t)/ns,r=t.pow(e,n),i=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),o=t.eql(r,t.neg(t.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function xp(t,e){e!==void 0&&Lo(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Vr(t,e,n=!1,r={}){if(t<=Ft)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=xp(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:n,BITS:i,BYTES:s,MASK:ts(i),ZERO:Ft,ONE:$t,create:c=>At(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Ft<=c&&c<t},is0:c=>c===Ft,isOdd:c=>(c&$t)===$t,neg:c=>At(-c,t),eql:(c,f)=>c===f,sqr:c=>At(c*c,t),add:(c,f)=>At(c+f,t),sub:(c,f)=>At(c-f,t),mul:(c,f)=>At(c*f,t),pow:(c,f)=>bc(a,c,f),div:(c,f)=>At(c*Yu(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>Yu(c,t),sqrt:r.sqrt||(c=>(o||(o=N4(t)),o(a,c))),toBytes:c=>n?sp(c,s):Le(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return n?ip(c):Bt(c)},invertBatch:c=>rs(a,c),cmov:(c,f,l)=>l?f:c});return Object.freeze(a)}function _p(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 Xu(t){const e=_p(t);return e+Math.ceil(e/2)}function Sp(t,e,n=!1){const r=t.length,i=_p(e),s=Xu(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?ip(t):Bt(t),a=At(o,e-$t)+$t;return n?sp(a,i):Le(a,i)}const Ip=BigInt(0),Ju=BigInt(1);function Qu(t,e){const n=e.negate();return t?n:e}function Bp(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function el(t,e){Bp(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=ts(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function $p(t,e,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(t&i),c=t>>o;a>r&&(a-=s,c+=Ju);const f=e*r,l=f+Math.abs(a)-1,h=a===0,d=a<0,u=e%2!==0;return{nextN:c,offset:l,isZero:h,isNeg:d,isNegF:u,offsetF:f}}function C4(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function L4(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const tl=new WeakMap,Ap=new WeakMap;function nl(t){return Ap.get(t)||1}function F4(t,e){return{constTimeNegate:Qu,hasPrecomputes(n){return nl(n)!==1},unsafeLadder(n,r,i=t.ZERO){let s=n;for(;r>Ip;)r&Ju&&(i=i.add(s)),s=s.double(),r>>=Ju;return i},precomputeWindow(n,r){const{windows:i,windowSize:s}=el(r,e),o=[];let a=n,c=a;for(let f=0;f<i;f++){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(n,r,i){let s=t.ZERO,o=t.BASE;const a=el(n,e);for(let c=0;c<a.windows;c++){const{nextN:f,offset:l,isZero:h,isNeg:d,isNegF:u,offsetF:b}=$p(i,c,a);i=f,h?o=o.add(Qu(u,r[b])):s=s.add(Qu(d,r[l]))}return{p:s,f:o}},wNAFUnsafe(n,r,i,s=t.ZERO){const o=el(n,e);for(let a=0;a<o.windows&&i!==Ip;a++){const{nextN:c,offset:f,isZero:l,isNeg:h}=$p(i,a,o);if(i=c,!l){const d=r[f];s=s.add(h?d.negate():d)}}return s},getPrecomputes(n,r,i){let s=tl.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&tl.set(r,i(s))),s},wNAFCached(n,r,i){const s=nl(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=nl(n);return o===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,n,i),r,s)},setWindowSize(n,r){Bp(r,e),Ap.set(n,r),tl.delete(n)}}}function k4(t,e,n,r){C4(n,t),L4(r,e);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,a=jo(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=ts(c),l=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let d=o;for(let u=h;u>=0;u-=c){l.fill(o);for(let w=0;w<s;w++){const E=r[w],A=Number(E>>BigInt(u)&f);l[A]=l[A].add(n[w])}let b=o;for(let w=l.length-1,E=o;w>0;w--)E=E.add(l[w]),b=b.add(E);if(d=d.add(b),u!==0)for(let w=0;w<c;w++)d=d.double()}return d}function Op(t){return Ep(t.Fp),Mo(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...xp(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function Dp(t){t.lowS!==void 0&&qo("lowS",t.lowS),t.prehash!==void 0&&qo("prehash",t.prehash)}function q4(t){const e=Op(t);Mo(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});const{endo:n,Fp:r,a:i}=e;if(n){if(!r.eql(i,r.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}class j4 extends Error{constructor(e=""){super(e)}}const ar={Err:j4,_tlv:{encode:(t,e)=>{const{Err:n}=ar;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");const r=e.length/2,i=dc(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?dc(i.length/2|128):"";return dc(t)+s+i+e},decode(t,e){const{Err:n}=ar;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const f=e.subarray(r,r+c);if(f.length!==c)throw new n("tlv.decode: length bytes not complete");if(f[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of f)o=o<<8|l;if(r+=c,o<128)throw new n("tlv.decode(long): not minimal encoding")}const a=e.subarray(r,r+o);if(a.length!==o)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(t){const{Err:e}=ar;if(t<xn)throw new e("integer: negative integers are not allowed");let n=dc(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=ar;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 Bt(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=ar,i=ut("signature",t),{v:s,l:o}=r.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,s),{v:f,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(f)}},hexFromSig(t){const{_tlv:e,_int:n}=ar,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}};function rl(t,e){return es(Le(t,e))}const xn=BigInt(0),ve=BigInt(1),Kr=BigInt(2),zo=BigInt(3),il=BigInt(4);function sl(t){const e=q4(t),{Fp:n}=e,r=Vr(e.n,e.nBitLength),i=e.toBytes||((_,x,D)=>{const U=x.toAffine();return De(Uint8Array.from([4]),n.toBytes(U.x),n.toBytes(U.y))}),s=e.fromBytes||(_=>{const x=_.subarray(1),D=n.fromBytes(x.subarray(0,n.BYTES)),U=n.fromBytes(x.subarray(n.BYTES,2*n.BYTES));return{x:D,y:U}});function o(_){const{a:x,b:D}=e,U=n.sqr(_),C=n.mul(U,_);return n.add(n.add(C,n.mul(_,x)),D)}function a(_,x){const D=n.sqr(x),U=o(_);return n.eql(D,U)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const c=n.mul(n.pow(e.a,zo),il),f=n.mul(n.sqr(e.b),BigInt(27));if(n.is0(n.add(c,f)))throw new Error("bad curve params: a or b");function l(_){return Mu(_,ve,e.n)}function h(_){const{allowedPrivateKeyLengths:x,nByteLength:D,wrapPrivateKey:U,n:C}=e;if(x&&typeof _!="bigint"){if(ko(_)&&(_=es(_)),typeof _!="string"||!x.includes(_.length))throw new Error("invalid private key");_=_.padStart(D*2,"0")}let L;try{L=typeof _=="bigint"?_:Bt(ut("private key",_,D))}catch{throw new Error("invalid private key, expected hex or "+D+" bytes, got "+typeof _)}return U&&(L=At(L,C)),zs("private key",L,ve,C),L}function d(_){if(!(_ instanceof w))throw new Error("ProjectivePoint expected")}const u=Hu((_,x)=>{const{px:D,py:U,pz:C}=_;if(n.eql(C,n.ONE))return{x:D,y:U};const L=_.is0();x==null&&(x=L?n.ONE:n.inv(C));const O=n.mul(D,x),M=n.mul(U,x),q=n.mul(C,x);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(q,n.ONE))throw new Error("invZ was invalid");return{x:O,y:M}}),b=Hu(_=>{if(_.is0()){if(e.allowInfinityPoint&&!n.is0(_.py))return;throw new Error("bad point: ZERO")}const{x,y:D}=_.toAffine();if(!n.isValid(x)||!n.isValid(D))throw new Error("bad point: x or y not FE");if(!a(x,D))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(x,D,U){if(x==null||!n.isValid(x))throw new Error("x required");if(D==null||!n.isValid(D)||n.is0(D))throw new Error("y required");if(U==null||!n.isValid(U))throw new Error("z required");this.px=x,this.py=D,this.pz=U,Object.freeze(this)}static fromAffine(x){const{x:D,y:U}=x||{};if(!x||!n.isValid(D)||!n.isValid(U))throw new Error("invalid affine point");if(x instanceof w)throw new Error("projective point not allowed");const C=L=>n.eql(L,n.ZERO);return C(D)&&C(U)?w.ZERO:new w(D,U,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){const D=rs(n,x.map(U=>U.pz));return x.map((U,C)=>U.toAffine(D[C])).map(w.fromAffine)}static fromHex(x){const D=w.fromAffine(s(ut("pointHex",x)));return D.assertValidity(),D}static fromPrivateKey(x){return w.BASE.multiply(h(x))}static msm(x,D){return k4(w,r,x,D)}_setWindowSize(x){P.setWindowSize(this,x)}assertValidity(){b(this)}hasEvenY(){const{y:x}=this.toAffine();if(n.isOdd)return!n.isOdd(x);throw new Error("Field doesn't support isOdd")}equals(x){d(x);const{px:D,py:U,pz:C}=this,{px:L,py:O,pz:M}=x,q=n.eql(n.mul(D,M),n.mul(L,C)),y=n.eql(n.mul(U,M),n.mul(O,C));return q&&y}negate(){return new w(this.px,n.neg(this.py),this.pz)}double(){const{a:x,b:D}=e,U=n.mul(D,zo),{px:C,py:L,pz:O}=this;let M=n.ZERO,q=n.ZERO,y=n.ZERO,p=n.mul(C,C),m=n.mul(L,L),g=n.mul(O,O),v=n.mul(C,L);return v=n.add(v,v),y=n.mul(C,O),y=n.add(y,y),M=n.mul(x,y),q=n.mul(U,g),q=n.add(M,q),M=n.sub(m,q),q=n.add(m,q),q=n.mul(M,q),M=n.mul(v,M),y=n.mul(U,y),g=n.mul(x,g),v=n.sub(p,g),v=n.mul(x,v),v=n.add(v,y),y=n.add(p,p),p=n.add(y,p),p=n.add(p,g),p=n.mul(p,v),q=n.add(q,p),g=n.mul(L,O),g=n.add(g,g),p=n.mul(g,v),M=n.sub(M,p),y=n.mul(g,m),y=n.add(y,y),y=n.add(y,y),new w(M,q,y)}add(x){d(x);const{px:D,py:U,pz:C}=this,{px:L,py:O,pz:M}=x;let q=n.ZERO,y=n.ZERO,p=n.ZERO;const m=e.a,g=n.mul(e.b,zo);let v=n.mul(D,L),S=n.mul(U,O),B=n.mul(C,M),I=n.add(D,U),$=n.add(L,O);I=n.mul(I,$),$=n.add(v,S),I=n.sub(I,$),$=n.add(D,C);let T=n.add(L,M);return $=n.mul($,T),T=n.add(v,B),$=n.sub($,T),T=n.add(U,C),q=n.add(O,M),T=n.mul(T,q),q=n.add(S,B),T=n.sub(T,q),p=n.mul(m,$),q=n.mul(g,B),p=n.add(q,p),q=n.sub(S,p),p=n.add(S,p),y=n.mul(q,p),S=n.add(v,v),S=n.add(S,v),B=n.mul(m,B),$=n.mul(g,$),S=n.add(S,B),B=n.sub(v,B),B=n.mul(m,B),$=n.add($,B),v=n.mul(S,$),y=n.add(y,v),v=n.mul(T,$),q=n.mul(I,q),q=n.sub(q,v),v=n.mul(I,S),p=n.mul(T,p),p=n.add(p,v),new w(q,y,p)}subtract(x){return this.add(x.negate())}is0(){return this.equals(w.ZERO)}wNAF(x){return P.wNAFCached(this,x,w.normalizeZ)}multiplyUnsafe(x){const{endo:D,n:U}=e;zs("scalar",x,xn,U);const C=w.ZERO;if(x===xn)return C;if(this.is0()||x===ve)return this;if(!D||P.hasPrecomputes(this))return P.wNAFCachedUnsafe(this,x,w.normalizeZ);let{k1neg:L,k1:O,k2neg:M,k2:q}=D.splitScalar(x),y=C,p=C,m=this;for(;O>xn||q>xn;)O&ve&&(y=y.add(m)),q&ve&&(p=p.add(m)),m=m.double(),O>>=ve,q>>=ve;return L&&(y=y.negate()),M&&(p=p.negate()),p=new w(n.mul(p.px,D.beta),p.py,p.pz),y.add(p)}multiply(x){const{endo:D,n:U}=e;zs("scalar",x,ve,U);let C,L;if(D){const{k1neg:O,k1:M,k2neg:q,k2:y}=D.splitScalar(x);let{p,f:m}=this.wNAF(M),{p:g,f:v}=this.wNAF(y);p=P.constTimeNegate(O,p),g=P.constTimeNegate(q,g),g=new w(n.mul(g.px,D.beta),g.py,g.pz),C=p.add(g),L=m.add(v)}else{const{p:O,f:M}=this.wNAF(x);C=O,L=M}return w.normalizeZ([C,L])[0]}multiplyAndAddUnsafe(x,D,U){const C=w.BASE,L=(M,q)=>q===xn||q===ve||!M.equals(C)?M.multiplyUnsafe(q):M.multiply(q),O=L(this,D).add(L(x,U));return O.is0()?void 0:O}toAffine(x){return u(this,x)}isTorsionFree(){const{h:x,isTorsionFree:D}=e;if(x===ve)return!0;if(D)return D(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:x,clearCofactor:D}=e;return x===ve?this:D?D(w,this):this.multiplyUnsafe(e.h)}toRawBytes(x=!0){return qo("isCompressed",x),this.assertValidity(),i(w,this,x)}toHex(x=!0){return qo("isCompressed",x),es(this.toRawBytes(x))}}w.BASE=new w(e.Gx,e.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO);const{endo:E,nBitLength:A}=e,P=F4(w,E?Math.ceil(A/2):A);return{CURVE:e,ProjectivePoint:w,normPrivateKeyToScalar:h,weierstrassEquation:o,isWithinCurveOrder:l}}function M4(t){const e=Op(t);return Mo(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function z4(t){const e=M4(t),{Fp:n,n:r,nByteLength:i,nBitLength:s}=e,o=n.BYTES+1,a=2*n.BYTES+1;function c(g){return At(g,r)}function f(g){return Yu(g,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:h,weierstrassEquation:d,isWithinCurveOrder:u}=sl({...e,toBytes(g,v,S){const B=v.toAffine(),I=n.toBytes(B.x),$=De;return qo("isCompressed",S),S?$(Uint8Array.from([v.hasEvenY()?2:3]),I):$(Uint8Array.from([4]),I,n.toBytes(B.y))},fromBytes(g){const v=g.length,S=g[0],B=g.subarray(1);if(v===o&&(S===2||S===3)){const I=Bt(B);if(!Mu(I,ve,n.ORDER))throw new Error("Point is not on curve");const $=d(I);let T;try{T=n.sqrt($)}catch(k){const R=k instanceof Error?": "+k.message:"";throw new Error("Point is not on curve"+R)}const F=(T&ve)===ve;return(S&1)===1!==F&&(T=n.neg(T)),{x:I,y:T}}else if(v===a&&S===4){const I=n.fromBytes(B.subarray(0,n.BYTES)),$=n.fromBytes(B.subarray(n.BYTES,2*n.BYTES));return{x:I,y:$}}else{const I=o,$=a;throw new Error("invalid Point, expected length of "+I+", or uncompressed "+$+", got "+v)}}});function b(g){const v=r>>ve;return g>v}function w(g){return b(g)?c(-g):g}const E=(g,v,S)=>Bt(g.slice(v,S));class A{constructor(v,S,B){zs("r",v,ve,r),zs("s",S,ve,r),this.r=v,this.s=S,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(v){const S=i;return v=ut("compactSignature",v,S*2),new A(E(v,0,S),E(v,S,2*S))}static fromDER(v){const{r:S,s:B}=ar.toSig(ut("DER",v));return new A(S,B)}assertValidity(){}addRecoveryBit(v){return new A(this.r,this.s,v)}recoverPublicKey(v){const{r:S,s:B,recovery:I}=this,$=C(ut("msgHash",v));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");const T=I===2||I===3?S+e.n:S;if(T>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const F=(I&1)===0?"02":"03",N=l.fromHex(F+rl(T,n.BYTES)),k=f(T),R=c(-$*k),j=c(B*k),z=l.BASE.multiplyAndAddUnsafe(N,R,j);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return b(this.s)}normalizeS(){return this.hasHighS()?new A(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return pc(this.toDERHex())}toDERHex(){return ar.hexFromSig(this)}toCompactRawBytes(){return pc(this.toCompactHex())}toCompactHex(){const v=i;return rl(this.r,v)+rl(this.s,v)}}const P={isValidPrivateKey(g){try{return h(g),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const g=Xu(e.n);return Sp(e.randomBytes(g),e.n)},precompute(g=8,v=l.BASE){return v._setWindowSize(g),v.multiply(BigInt(3)),v}};function _(g,v=!0){return l.fromPrivateKey(g).toRawBytes(v)}function x(g){if(typeof g=="bigint")return!1;if(g instanceof l)return!0;const S=ut("key",g).length,B=n.BYTES,I=B+1,$=2*B+1;if(!(e.allowedPrivateKeyLengths||i===I))return S===I||S===$}function D(g,v,S=!0){if(x(g)===!0)throw new Error("first arg must be private key");if(x(v)===!1)throw new Error("second arg must be public key");return l.fromHex(v).multiply(h(g)).toRawBytes(S)}const U=e.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");const v=Bt(g),S=g.length*8-s;return S>0?v>>BigInt(S):v},C=e.bits2int_modN||function(g){return c(U(g))},L=ts(s);function O(g){return zs("num < 2^"+s,g,xn,L),Le(g,i)}function M(g,v,S=q){if(["recovered","canonical"].some(H=>H in S))throw new Error("sign() legacy options not supported");const{hash:B,randomBytes:I}=e;let{lowS:$,prehash:T,extraEntropy:F}=S;$==null&&($=!0),g=ut("msgHash",g),Dp(S),T&&(g=ut("prehashed msgHash",B(g)));const N=C(g),k=h(v),R=[O(k),O(N)];if(F!=null&&F!==!1){const H=F===!0?I(n.BYTES):F;R.push(ut("extraEntropy",H))}const j=De(...R),z=N;function V(H){const K=U(H);if(!u(K))return;const Y=f(K),X=l.BASE.multiply(K).toAffine(),ee=c(X.x);if(ee===xn)return;const se=c(Y*c(z+ee*k));if(se===xn)return;let oe=(X.x===ee?0:2)|Number(X.y&ve),ot=se;return $&&b(se)&&(ot=w(se),oe^=1),new A(ee,ot,oe)}return{seed:j,k2sig:V}}const q={lowS:e.lowS,prehash:!1},y={lowS:e.lowS,prehash:!1};function p(g,v,S=q){const{seed:B,k2sig:I}=M(g,v,S),$=e;return QE($.hash.outputLen,$.nByteLength,$.hmac)(B,I)}l.BASE._setWindowSize(8);function m(g,v,S,B=y){const I=g;v=ut("msgHash",v),S=ut("publicKey",S);const{lowS:$,prehash:T,format:F}=B;if(Dp(B),"strict"in B)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 N=typeof I=="string"||ko(I),k=!N&&!F&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!N&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let R,j;try{if(k&&(R=new A(I.r,I.s)),N){try{F!=="compact"&&(R=A.fromDER(I))}catch(oe){if(!(oe instanceof ar.Err))throw oe}!R&&F!=="der"&&(R=A.fromCompact(I))}j=l.fromHex(S)}catch{return!1}if(!R||$&&R.hasHighS())return!1;T&&(v=e.hash(v));const{r:z,s:V}=R,H=C(v),K=f(V),Y=c(H*K),X=c(z*K),ee=l.BASE.multiplyAndAddUnsafe(j,Y,X)?.toAffine();return ee?c(ee.x)===z:!1}return{CURVE:e,getPublicKey:_,getSharedSecret:D,sign:p,verify:m,ProjectivePoint:l,Signature:A,utils:P}}function H4(t,e){const n=t.ORDER;let r=xn;for(let b=n-ve;b%Kr===xn;b/=Kr)r+=ve;const i=r,s=Kr<<i-ve-ve,o=s*Kr,a=(n-ve)/o,c=(a-ve)/Kr,f=o-ve,l=s,h=t.pow(e,a),d=t.pow(e,(a+ve)/Kr);let u=(b,w)=>{let E=h,A=t.pow(w,f),P=t.sqr(A);P=t.mul(P,w);let _=t.mul(b,P);_=t.pow(_,c),_=t.mul(_,A),A=t.mul(_,w),P=t.mul(_,b);let x=t.mul(P,A);_=t.pow(x,l);let D=t.eql(_,t.ONE);A=t.mul(P,d),_=t.mul(x,E),P=t.cmov(A,P,D),x=t.cmov(_,x,D);for(let U=i;U>ve;U--){let C=U-Kr;C=Kr<<C-ve;let L=t.pow(x,C);const O=t.eql(L,t.ONE);A=t.mul(P,E),E=t.mul(E,E),L=t.mul(x,E),P=t.cmov(A,P,O),x=t.cmov(L,x,O)}return{isValid:D,value:P}};if(t.ORDER%il===zo){const b=(t.ORDER-zo)/il,w=t.sqrt(t.neg(e));u=(E,A)=>{let P=t.sqr(A);const _=t.mul(E,A);P=t.mul(P,_);let x=t.pow(P,b);x=t.mul(x,_);const D=t.mul(x,w),U=t.mul(t.sqr(x),A),C=t.eql(U,E);let L=t.cmov(D,x,C);return{isValid:C,value:L}}}return u}function Pp(t,e){if(Ep(t),!t.isValid(e.A)||!t.isValid(e.B)||!t.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=H4(t,e.Z);if(!t.isOdd)throw new Error("Fp.isOdd is not implemented!");return r=>{let i,s,o,a,c,f,l,h;i=t.sqr(r),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),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),l=t.mul(i,o);const{isValid:d,value:u}=n(s,f);h=t.mul(i,r),h=t.mul(h,u),l=t.cmov(l,o,d),h=t.cmov(h,u,d);const b=t.isOdd(r)===t.isOdd(h);h=t.cmov(t.neg(h),h,b);const w=rs(t,[a],!0)[0];return l=t.mul(l,w),{x:l,y:h}}}function V4(t){return{hash:t,hmac:(e,...n)=>bp(t,e,mE(...n)),randomBytes:j1}}function wc(t,e){const n=r=>z4({...t,...V4(r)});return{...n(e),create:n}}const K4=Bt;function Gr(t,e){if(Ho(t),Ho(e),t<0||t>=1<<8*e)throw new Error("invalid I2OSP input: "+t);const n=Array.from({length:e}).fill(0);for(let r=e-1;r>=0;r--)n[r]=t&255,t>>>=8;return new Uint8Array(n)}function G4(t,e){const n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t[r]^e[r];return n}function Ho(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function Z4(t,e,n,r){Hr(t),Hr(e),Ho(n),e.length>255&&(e=r(De(qu("H2C-OVERSIZE-DST-"),e)));const{outputLen:i,blockLen:s}=r,o=Math.ceil(n/i);if(n>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");const a=De(e,Gr(e.length,1)),c=Gr(0,s),f=Gr(n,2),l=new Array(o),h=r(De(c,t,f,Gr(0,1),a));l[0]=r(De(h,Gr(1,1),a));for(let u=1;u<=o;u++){const b=[G4(h,l[u-1]),Gr(u+1,1),a];l[u]=r(De(...b))}return De(...l).slice(0,n)}function W4(t,e,n,r,i){if(Hr(t),Hr(e),Ho(n),e.length>255){const s=Math.ceil(2*r/8);e=i.create({dkLen:s}).update(qu("H2C-OVERSIZE-DST-")).update(e).digest()}if(n>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:n}).update(t).update(Gr(n,2)).update(e).update(Gr(e.length,1)).digest()}function Rp(t,e,n){Mo(n,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:r,k:i,m:s,hash:o,expand:a,DST:c}=n;Hr(t),Ho(e);const f=typeof c=="string"?qu(c):c,l=r.toString(2).length,h=Math.ceil((l+i)/8),d=e*s*h;let u;if(a==="xmd")u=Z4(t,f,d,o);else if(a==="xof")u=W4(t,f,d,i,o);else if(a==="_internal_pass")u=t;else throw new Error('expand must be "xmd" or "xof"');const b=new Array(e);for(let w=0;w<e;w++){const E=new Array(s);for(let A=0;A<s;A++){const P=h*(A+w*s),_=u.subarray(P,P+h);E[A]=At(K4(_),r)}b[w]=E}return b}function Tp(t,e){const n=e.map(r=>Array.from(r).reverse());return(r,i)=>{const[s,o,a,c]=n.map(h=>h.reduce((d,u)=>t.add(t.mul(d,r),u))),[f,l]=rs(t,[o,c],!0);return r=t.mul(s,f),i=t.mul(i,t.mul(a,l)),{x:r,y:i}}}function Np(t,e,n){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function r(s){return t.fromAffine(e(s))}function i(s){const o=s.clearCofactor();return o.equals(t.ZERO)?t.ZERO:(o.assertValidity(),o)}return{defaults:n,hashToCurve(s,o){const a=Rp(s,2,{...n,DST:n.DST,...o}),c=r(a[0]),f=r(a[1]);return i(c.add(f))},encodeToCurve(s,o){const a=Rp(s,1,{...n,DST:n.encodeDST,...o});return i(r(a[0]))},mapToCurve(s){if(!Array.isArray(s))throw new Error("expected array of bigints");for(const o of s)if(typeof o!="bigint")throw new Error("expected array of bigints");return i(r(s))}}}const Up=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Cp=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),Y4=BigInt(0),X4=BigInt(1),ol=BigInt(2),Lp=(t,e)=>(t+e/ol)/e;function J4(t){const e=Up,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,l=f*f*t%e,h=un(l,n,e)*l%e,d=un(h,n,e)*l%e,u=un(d,ol,e)*f%e,b=un(u,i,e)*u%e,w=un(b,s,e)*b%e,E=un(w,a,e)*w%e,A=un(E,c,e)*E%e,P=un(A,a,e)*w%e,_=un(P,n,e)*l%e,x=un(_,o,e)*b%e,D=un(x,r,e)*f%e,U=un(D,ol,e);if(!al.eql(al.sqr(U),t))throw new Error("Cannot find square root");return U}const al=Vr(Up,void 0,void 0,{sqrt:J4});wc({a:Y4,b:BigInt(7),Fp:al,n:Cp,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=Cp,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-X4*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=Lp(s*t,e),c=Lp(-r*t,e);let f=At(t-a*n-c*i,e),l=At(-a*r-c*s,e);const h=f>o,d=l>o;if(h&&(f=e-f),d&&(l=e-l),f>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:h,k1:f,k2neg:d,k2:l}}}},lc),Object.freeze({1:0n,2:1n,3:2n,4:3n,5:4n,6:5n,7:6n,8:7n,9:8n,A:9n,B:10n,C:11n,D:12n,E:13n,F:14n,G:15n,H:16n,J:17n,K:18n,L:19n,M:20n,N:21n,P:22n,Q:23n,R:24n,S:25n,T:26n,U:27n,V:28n,W:29n,X:30n,Y:31n,Z:32n,a:33n,b:34n,c:35n,d:36n,e:37n,f:38n,g:39n,h:40n,i:41n,j:42n,k:43n,m:44n,n:45n,o:46n,p:47n,q:48n,r:49n,s:50n,t:51n,u:52n,v:53n,w:54n,x:55n,y:56n,z:57n}),Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").map((t,e)=>[e,t.charCodeAt(0)]),{...Object.fromEntries(Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").map((t,e)=>[t.charCodeAt(0),e]))},rr.slice();const Q4=BigInt(0),mc=BigInt(1),Fp=BigInt(2),Hs=BigInt(3);function e5(t){const e=[];for(;t>mc;t>>=mc)(t&mc)===Q4?e.unshift(0):(t&Hs)===Hs?(e.unshift(-1),t+=mc):e.unshift(1);return e}function t5(t){const{Fp:e,Fr:n,Fp2:r,Fp6:i,Fp12:s}=t.fields,o=t.params.xNegative,a=t.params.twistType,c=sl({n:n.ORDER,...t.G1}),f=Object.assign(c,Np(c.ProjectivePoint,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),l=sl({n:n.ORDER,...t.G2}),h=Object.assign(l,Np(l.ProjectivePoint,t.G2.mapToCurve,{...t.htfDefaults,...t.G2.htfDefaults}));let d;if(a==="multiplicative")d=(N,k,R,j,z,V)=>s.mul014(j,N,r.mul(k,z),r.mul(R,V));else if(a==="divisive")d=(N,k,R,j,z,V)=>s.mul034(j,r.mul(R,V),r.mul(k,z),N);else throw new Error("bls: unknown twist type");const u=r.div(r.ONE,r.mul(r.ONE,Fp));function b(N,k,R,j){const z=r.sqr(R),V=r.sqr(j),H=r.mulByB(r.mul(V,Hs)),K=r.mul(H,Hs),Y=r.sub(r.sub(r.sqr(r.add(R,j)),V),z),X=r.sub(H,z),ee=r.mul(r.sqr(k),Hs),se=r.neg(Y);return N.push([X,ee,se]),k=r.mul(r.mul(r.mul(r.sub(z,K),k),R),u),R=r.sub(r.sqr(r.mul(r.add(z,K),u)),r.mul(r.sqr(H),Hs)),j=r.mul(z,Y),{Rx:k,Ry:R,Rz:j}}function w(N,k,R,j,z,V){const H=r.sub(R,r.mul(V,j)),K=r.sub(k,r.mul(z,j)),Y=r.sub(r.mul(H,z),r.mul(K,V)),X=r.neg(H),ee=K;N.push([Y,X,ee]);const se=r.sqr(K),oe=r.mul(se,K),ot=r.mul(se,k),Ns=r.add(r.sub(oe,r.mul(ot,Fp)),r.mul(r.sqr(H),j));return k=r.mul(K,Ns),R=r.sub(r.mul(r.sub(ot,Ns),H),r.mul(oe,R)),j=r.mul(j,oe),{Rx:k,Ry:R,Rz:j}}const E=e5(t.params.ateLoopSize),A=Hu(N=>{const k=N,{x:R,y:j}=k.toAffine(),z=R,V=j,H=r.neg(j);let K=z,Y=V,X=r.ONE;const ee=[];for(const se of E){const oe=[];({Rx:K,Ry:Y,Rz:X}=b(oe,K,Y,X)),se&&({Rx:K,Ry:Y,Rz:X}=w(oe,K,Y,X,z,se===-1?H:V)),ee.push(oe)}if(t.postPrecompute){const se=ee[ee.length-1];t.postPrecompute(K,Y,X,z,V,w.bind(null,se))}return ee});function P(N,k=!1){let R=s.ONE;if(N.length){const j=N[0][0].length;for(let z=0;z<j;z++){R=s.sqr(R);for(const[V,H,K]of N)for(const[Y,X,ee]of V[z])R=d(Y,X,ee,R,H,K)}}return o&&(R=s.conjugate(R)),k?s.finalExponentiate(R):R}function _(N,k=!0){const R=[];f.ProjectivePoint.normalizeZ(N.map(({g1:j})=>j)),h.ProjectivePoint.normalizeZ(N.map(({g2:j})=>j));for(const{g1:j,g2:z}of N){if(j.equals(f.ProjectivePoint.ZERO)||z.equals(h.ProjectivePoint.ZERO))throw new Error("pairing is not available for ZERO point");j.assertValidity(),z.assertValidity();const V=j.toAffine();R.push([A(z),V.x,V.y])}return P(R,k)}function x(N,k,R=!0){return _([{g1:N,g2:k}],R)}const D={randomPrivateKey:()=>{const N=Xu(n.ORDER);return Sp(t.randomBytes(N),n.ORDER)},calcPairingPrecomputes:A},{ShortSignature:U}=t.G1,{Signature:C}=t.G2;function L(N){return N instanceof f.ProjectivePoint?N:f.ProjectivePoint.fromHex(N)}function O(N,k){return N instanceof f.ProjectivePoint?N:f.hashToCurve(ut("point",N),k)}function M(N){return N instanceof h.ProjectivePoint?N:C.fromHex(N)}function q(N,k){return N instanceof h.ProjectivePoint?N:h.hashToCurve(ut("point",N),k)}function y(N){return f.ProjectivePoint.fromPrivateKey(N).toRawBytes(!0)}function p(N){return h.ProjectivePoint.fromPrivateKey(N).toRawBytes(!0)}function m(N,k,R){const j=q(N,R);j.assertValidity();const z=j.multiply(f.normPrivateKeyToScalar(k));return N instanceof h.ProjectivePoint?z:C.toRawBytes(z)}function g(N,k,R){const j=O(N,R);j.assertValidity();const z=j.multiply(f.normPrivateKeyToScalar(k));return N instanceof f.ProjectivePoint?z:U.toRawBytes(z)}function v(N,k,R,j){const z=L(R),V=q(k,j),H=f.ProjectivePoint.BASE,K=M(N),Y=_([{g1:z.negate(),g2:V},{g1:H,g2:K}]);return s.eql(Y,s.ONE)}function S(N,k,R,j){const z=M(R),V=O(k,j),H=h.ProjectivePoint.BASE,K=L(N),Y=_([{g1:V,g2:z},{g1:K,g2:H.negate()}]);return s.eql(Y,s.ONE)}function B(N){if(!Array.isArray(N)||N.length===0)throw new Error("expected non-empty array")}function I(N){B(N);const R=N.map(L).reduce((j,z)=>j.add(z),f.ProjectivePoint.ZERO);return N[0]instanceof f.ProjectivePoint?(R.assertValidity(),R):R.toRawBytes(!0)}function $(N){B(N);const R=N.map(M).reduce((j,z)=>j.add(z),h.ProjectivePoint.ZERO);return N[0]instanceof h.ProjectivePoint?(R.assertValidity(),R):C.toRawBytes(R)}function T(N){B(N);const R=N.map(L).reduce((j,z)=>j.add(z),f.ProjectivePoint.ZERO);return N[0]instanceof f.ProjectivePoint?(R.assertValidity(),R):U.toRawBytes(R)}function F(N,k,R,j){if(B(k),R.length!==k.length)throw new Error("amount of public keys and messages should be equal");const z=M(N),V=k.map(X=>q(X,j)),H=R.map(L),K=new Map;for(let X=0;X<H.length;X++){const ee=H[X],se=V[X];let oe=K.get(se);oe===void 0&&(oe=[],K.set(se,oe)),oe.push(ee)}const Y=[];try{for(const[X,ee]of K){const se=ee.reduce((oe,ot)=>oe.add(ot));Y.push({g1:se,g2:X})}return Y.push({g1:f.ProjectivePoint.BASE.negate(),g2:z}),s.eql(_(Y),s.ONE)}catch{return!1}}return f.ProjectivePoint.BASE._setWindowSize(4),{getPublicKey:y,getPublicKeyForShortSignatures:p,sign:m,signShortSignature:g,verify:v,verifyBatch:F,verifyShortSignature:S,aggregatePublicKeys:I,aggregateSignatures:$,aggregateShortSignatures:T,millerLoopBatch:P,pairing:x,pairingBatch:_,G1:f,G2:h,Signature:C,ShortSignature:U,fields:{Fr:n,Fp:e,Fp2:r,Fp6:i,Fp12:s},params:{ateLoopSize:t.params.ateLoopSize,r:t.params.r,G1b:t.G1.b,G2b:t.G2.b},utils:D}}const n5=BigInt(0),Vs=BigInt(1),cr=BigInt(2),kp=BigInt(3);function cl(t,e,n,r,i=1,s){const o=BigInt(s===void 0?r:s),a=n**BigInt(r),c=[];for(let f=0;f<i;f++){const l=BigInt(f+1),h=[];for(let d=0,u=Vs;d<r;d++){const b=(l*u-l)/o%a;h.push(t.pow(e,b)),u*=n}c.push(h)}return c}function r5(t,e,n){const r=e.pow(n,(t.ORDER-Vs)/kp),i=e.pow(n,(t.ORDER-Vs)/cr);function s(d,u){const b=e.mul(e.frobeniusMap(d,1),r),w=e.mul(e.frobeniusMap(u,1),i);return[b,w]}const o=e.pow(n,(t.ORDER**cr-Vs)/kp),a=e.pow(n,(t.ORDER**cr-Vs)/cr);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(d,u){return[e.mul(d,o),e.neg(u)]}const f=d=>(u,b)=>{const w=b.toAffine(),E=d(w.x,w.y);return u.fromAffine({x:E[0],y:E[1]})},l=f(s),h=f(c);return{psi:s,psi2:c,G2psi:l,G2psi2:h,PSI_X:r,PSI_Y:i,PSI2_X:o,PSI2_Y:a}}function i5(t){const{ORDER:e}=t,n=Vr(e),r=n.create(t.NONRESIDUE||BigInt(-1)),i=n.div(n.ONE,cr),s=cl(n,r,n.ORDER,2)[0],o=({c0:y,c1:p},{c0:m,c1:g})=>({c0:n.add(y,m),c1:n.add(p,g)}),a=({c0:y,c1:p},{c0:m,c1:g})=>({c0:n.sub(y,m),c1:n.sub(p,g)}),c=({c0:y,c1:p},m)=>{if(typeof m=="bigint")return{c0:n.mul(y,m),c1:n.mul(p,m)};const{c0:g,c1:v}=m;let S=n.mul(y,g),B=n.mul(p,v);const I=n.sub(S,B),$=n.sub(n.mul(n.add(y,p),n.add(g,v)),n.add(S,B));return{c0:I,c1:$}},f=({c0:y,c1:p})=>{const m=n.add(y,p),g=n.sub(y,p),v=n.add(y,y);return{c0:n.mul(m,g),c1:n.mul(v,p)}},l=y=>{if(y.length!==2)throw new Error("invalid tuple");const p=y.map(m=>n.create(m));return{c0:p[0],c1:p[1]}},h=e*e,d=l(t.FP2_NONRESIDUE),u={ORDER:h,isLE:n.isLE,NONRESIDUE:d,BITS:jo(h),BYTES:Math.ceil(jo(h)/8),MASK:ts(jo(h)),ZERO:{c0:n.ZERO,c1:n.ZERO},ONE:{c0:n.ONE,c1:n.ZERO},create:y=>y,isValid:({c0:y,c1:p})=>typeof y=="bigint"&&typeof p=="bigint",is0:({c0:y,c1:p})=>n.is0(y)&&n.is0(p),eql:({c0:y,c1:p},{c0:m,c1:g})=>n.eql(y,m)&&n.eql(p,g),neg:({c0:y,c1:p})=>({c0:n.neg(y),c1:n.neg(p)}),pow:(y,p)=>bc(u,y,p),invertBatch:y=>rs(u,y),add:o,sub:a,mul:c,sqr:f,addN:o,subN:a,mulN:c,sqrN:f,div:(y,p)=>u.mul(y,typeof p=="bigint"?n.inv(n.create(p)):u.inv(p)),inv:({c0:y,c1:p})=>{const m=n.inv(n.create(y*y+p*p));return{c0:n.mul(m,n.create(y)),c1:n.mul(m,n.create(-p))}},sqrt:y=>{if(t.Fp2sqrt)return t.Fp2sqrt(y);const{c0:p,c1:m}=y;if(n.is0(m))return yc(n,p)===1?u.create({c0:n.sqrt(p),c1:n.ZERO}):u.create({c0:n.ZERO,c1:n.sqrt(n.div(p,r))});const g=n.sqrt(n.sub(n.sqr(p),n.mul(n.sqr(m),r)));let v=n.mul(n.add(g,p),i);yc(n,v)===-1&&(v=n.sub(v,g));const B=n.sqrt(v),I=u.create({c0:B,c1:n.div(n.mul(m,i),B)});if(!u.eql(u.sqr(I),y))throw new Error("Cannot find square root");const $=I,T=u.neg($),{re:F,im:N}=u.reim($),{re:k,im:R}=u.reim(T);return N>R||N===R&&F>k?$:T},isOdd:y=>{const{re:p,im:m}=u.reim(y),g=p%cr,v=p===n5,S=m%cr;return BigInt(g||v&&S)==Vs},fromBytes(y){if(y.length!==u.BYTES)throw new Error("fromBytes invalid length="+y.length);return{c0:n.fromBytes(y.subarray(0,n.BYTES)),c1:n.fromBytes(y.subarray(n.BYTES))}},toBytes:({c0:y,c1:p})=>De(n.toBytes(y),n.toBytes(p)),cmov:({c0:y,c1:p},{c0:m,c1:g},v)=>({c0:n.cmov(y,m,v),c1:n.cmov(p,g,v)}),reim:({c0:y,c1:p})=>({re:y,im:p}),mulByNonresidue:({c0:y,c1:p})=>u.mul({c0:y,c1:p},d),mulByB:t.Fp2mulByB,fromBigTuple:l,frobeniusMap:({c0:y,c1:p},m)=>({c0:y,c1:n.mul(p,s[m%2])})},b=({c0:y,c1:p,c2:m},{c0:g,c1:v,c2:S})=>({c0:u.add(y,g),c1:u.add(p,v),c2:u.add(m,S)}),w=({c0:y,c1:p,c2:m},{c0:g,c1:v,c2:S})=>({c0:u.sub(y,g),c1:u.sub(p,v),c2:u.sub(m,S)}),E=({c0:y,c1:p,c2:m},g)=>{if(typeof g=="bigint")return{c0:u.mul(y,g),c1:u.mul(p,g),c2:u.mul(m,g)};const{c0:v,c1:S,c2:B}=g,I=u.mul(y,v),$=u.mul(p,S),T=u.mul(m,B);return{c0:u.add(I,u.mulByNonresidue(u.sub(u.mul(u.add(p,m),u.add(S,B)),u.add($,T)))),c1:u.add(u.sub(u.mul(u.add(y,p),u.add(v,S)),u.add(I,$)),u.mulByNonresidue(T)),c2:u.sub(u.add($,u.mul(u.add(y,m),u.add(v,B))),u.add(I,T))}},A=({c0:y,c1:p,c2:m})=>{let g=u.sqr(y),v=u.mul(u.mul(y,p),cr),S=u.mul(u.mul(p,m),cr),B=u.sqr(m);return{c0:u.add(u.mulByNonresidue(S),g),c1:u.add(u.mulByNonresidue(B),v),c2:u.sub(u.sub(u.add(u.add(v,u.sqr(u.add(u.sub(y,p),m))),S),g),B)}},[P,_]=cl(u,d,n.ORDER,6,2,3),x={ORDER:u.ORDER,isLE:u.isLE,BITS:3*u.BITS,BYTES:3*u.BYTES,MASK:ts(3*u.BITS),ZERO:{c0:u.ZERO,c1:u.ZERO,c2:u.ZERO},ONE:{c0:u.ONE,c1:u.ZERO,c2:u.ZERO},create:y=>y,isValid:({c0:y,c1:p,c2:m})=>u.isValid(y)&&u.isValid(p)&&u.isValid(m),is0:({c0:y,c1:p,c2:m})=>u.is0(y)&&u.is0(p)&&u.is0(m),neg:({c0:y,c1:p,c2:m})=>({c0:u.neg(y),c1:u.neg(p),c2:u.neg(m)}),eql:({c0:y,c1:p,c2:m},{c0:g,c1:v,c2:S})=>u.eql(y,g)&&u.eql(p,v)&&u.eql(m,S),sqrt:ap,div:(y,p)=>x.mul(y,typeof p=="bigint"?n.inv(n.create(p)):x.inv(p)),pow:(y,p)=>bc(x,y,p),invertBatch:y=>rs(x,y),add:b,sub:w,mul:E,sqr:A,addN:b,subN:w,mulN:E,sqrN:A,inv:({c0:y,c1:p,c2:m})=>{let g=u.sub(u.sqr(y),u.mulByNonresidue(u.mul(m,p))),v=u.sub(u.mulByNonresidue(u.sqr(m)),u.mul(y,p)),S=u.sub(u.sqr(p),u.mul(y,m)),B=u.inv(u.add(u.mulByNonresidue(u.add(u.mul(m,v),u.mul(p,S))),u.mul(y,g)));return{c0:u.mul(B,g),c1:u.mul(B,v),c2:u.mul(B,S)}},fromBytes:y=>{if(y.length!==x.BYTES)throw new Error("fromBytes invalid length="+y.length);return{c0:u.fromBytes(y.subarray(0,u.BYTES)),c1:u.fromBytes(y.subarray(u.BYTES,2*u.BYTES)),c2:u.fromBytes(y.subarray(2*u.BYTES))}},toBytes:({c0:y,c1:p,c2:m})=>De(u.toBytes(y),u.toBytes(p),u.toBytes(m)),cmov:({c0:y,c1:p,c2:m},{c0:g,c1:v,c2:S},B)=>({c0:u.cmov(y,g,B),c1:u.cmov(p,v,B),c2:u.cmov(m,S,B)}),fromBigSix:y=>{if(!Array.isArray(y)||y.length!==6)throw new Error("invalid Fp6 usage");return{c0:u.fromBigTuple(y.slice(0,2)),c1:u.fromBigTuple(y.slice(2,4)),c2:u.fromBigTuple(y.slice(4,6))}},frobeniusMap:({c0:y,c1:p,c2:m},g)=>({c0:u.frobeniusMap(y,g),c1:u.mul(u.frobeniusMap(p,g),P[g%6]),c2:u.mul(u.frobeniusMap(m,g),_[g%6])}),mulByFp2:({c0:y,c1:p,c2:m},g)=>({c0:u.mul(y,g),c1:u.mul(p,g),c2:u.mul(m,g)}),mulByNonresidue:({c0:y,c1:p,c2:m})=>({c0:u.mulByNonresidue(m),c1:y,c2:p}),mul1:({c0:y,c1:p,c2:m},g)=>({c0:u.mulByNonresidue(u.mul(m,g)),c1:u.mul(y,g),c2:u.mul(p,g)}),mul01({c0:y,c1:p,c2:m},g,v){let S=u.mul(y,g),B=u.mul(p,v);return{c0:u.add(u.mulByNonresidue(u.sub(u.mul(u.add(p,m),v),B)),S),c1:u.sub(u.sub(u.mul(u.add(g,v),u.add(y,p)),S),B),c2:u.add(u.sub(u.mul(u.add(y,m),g),S),B)}}},D=cl(u,d,n.ORDER,12,1,6)[0],U=({c0:y,c1:p},{c0:m,c1:g})=>({c0:x.add(y,m),c1:x.add(p,g)}),C=({c0:y,c1:p},{c0:m,c1:g})=>({c0:x.sub(y,m),c1:x.sub(p,g)}),L=({c0:y,c1:p},m)=>{if(typeof m=="bigint")return{c0:x.mul(y,m),c1:x.mul(p,m)};let{c0:g,c1:v}=m,S=x.mul(y,g),B=x.mul(p,v);return{c0:x.add(S,x.mulByNonresidue(B)),c1:x.sub(x.mul(x.add(y,p),x.add(g,v)),x.add(S,B))}},O=({c0:y,c1:p})=>{let m=x.mul(y,p);return{c0:x.sub(x.sub(x.mul(x.add(x.mulByNonresidue(p),y),x.add(y,p)),m),x.mulByNonresidue(m)),c1:x.add(m,m)}};function M(y,p){const m=u.sqr(y),g=u.sqr(p);return{first:u.add(u.mulByNonresidue(g),m),second:u.sub(u.sub(u.sqr(u.add(y,p)),m),g)}}const q={ORDER:u.ORDER,isLE:x.isLE,BITS:2*x.BITS,BYTES:2*x.BYTES,MASK:ts(2*x.BITS),ZERO:{c0:x.ZERO,c1:x.ZERO},ONE:{c0:x.ONE,c1:x.ZERO},create:y=>y,isValid:({c0:y,c1:p})=>x.isValid(y)&&x.isValid(p),is0:({c0:y,c1:p})=>x.is0(y)&&x.is0(p),neg:({c0:y,c1:p})=>({c0:x.neg(y),c1:x.neg(p)}),eql:({c0:y,c1:p},{c0:m,c1:g})=>x.eql(y,m)&&x.eql(p,g),sqrt:ap,inv:({c0:y,c1:p})=>{let m=x.inv(x.sub(x.sqr(y),x.mulByNonresidue(x.sqr(p))));return{c0:x.mul(y,m),c1:x.neg(x.mul(p,m))}},div:(y,p)=>q.mul(y,typeof p=="bigint"?n.inv(n.create(p)):q.inv(p)),pow:(y,p)=>bc(q,y,p),invertBatch:y=>rs(q,y),add:U,sub:C,mul:L,sqr:O,addN:U,subN:C,mulN:L,sqrN:O,fromBytes:y=>{if(y.length!==q.BYTES)throw new Error("fromBytes invalid length="+y.length);return{c0:x.fromBytes(y.subarray(0,x.BYTES)),c1:x.fromBytes(y.subarray(x.BYTES))}},toBytes:({c0:y,c1:p})=>De(x.toBytes(y),x.toBytes(p)),cmov:({c0:y,c1:p},{c0:m,c1:g},v)=>({c0:x.cmov(y,m,v),c1:x.cmov(p,g,v)}),fromBigTwelve:y=>({c0:x.fromBigSix(y.slice(0,6)),c1:x.fromBigSix(y.slice(6,12))}),frobeniusMap(y,p){const{c0:m,c1:g,c2:v}=x.frobeniusMap(y.c1,p),S=D[p%12];return{c0:x.frobeniusMap(y.c0,p),c1:x.create({c0:u.mul(m,S),c1:u.mul(g,S),c2:u.mul(v,S)})}},mulByFp2:({c0:y,c1:p},m)=>({c0:x.mulByFp2(y,m),c1:x.mulByFp2(p,m)}),conjugate:({c0:y,c1:p})=>({c0:y,c1:x.neg(p)}),mul014:({c0:y,c1:p},m,g,v)=>{let S=x.mul01(y,m,g),B=x.mul1(p,v);return{c0:x.add(x.mulByNonresidue(B),S),c1:x.sub(x.sub(x.mul01(x.add(p,y),m,u.add(g,v)),S),B)}},mul034:({c0:y,c1:p},m,g,v)=>{const S=x.create({c0:u.mul(y.c0,m),c1:u.mul(y.c1,m),c2:u.mul(y.c2,m)}),B=x.mul01(p,g,v),I=x.mul01(x.add(y,p),u.add(m,g),v);return{c0:x.add(x.mulByNonresidue(B),S),c1:x.sub(I,x.add(S,B))}},_cyclotomicSquare:t.Fp12cyclotomicSquare,_cyclotomicExp:t.Fp12cyclotomicExp,finalExponentiate:t.Fp12finalExponentiate};return{Fp:n,Fp2:u,Fp6:x,Fp4Square:M,Fp12:q}}const Ot=BigInt(0),vc=BigInt(1),He=BigInt(2),Ec=BigInt(3),Vo=BigInt(4),Zr=BigInt("0xd201000000010000"),s5=jo(Zr),{Fp:te,Fp2:re,Fp6:fl,Fp4Square:ul,Fp12:fe}=i5({ORDER:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),FP2_NONRESIDUE:[vc,vc],Fp2mulByB:({c0:t,c1:e})=>{const n=te.mul(t,Vo),r=te.mul(e,Vo);return{c0:te.sub(n,r),c1:te.add(n,r)}},Fp12cyclotomicSquare:({c0:t,c1:e})=>{const{c0:n,c1:r,c2:i}=t,{c0:s,c1:o,c2:a}=e,{first:c,second:f}=ul(n,o),{first:l,second:h}=ul(s,i),{first:d,second:u}=ul(r,a),b=re.mulByNonresidue(u);return{c0:fl.create({c0:re.add(re.mul(re.sub(c,n),He),c),c1:re.add(re.mul(re.sub(l,r),He),l),c2:re.add(re.mul(re.sub(d,i),He),d)}),c1:fl.create({c0:re.add(re.mul(re.add(b,s),He),b),c1:re.add(re.mul(re.add(f,o),He),f),c2:re.add(re.mul(re.add(h,a),He),h)})}},Fp12cyclotomicExp(t,e){let n=fe.ONE;for(let r=s5-1;r>=0;r--)n=fe._cyclotomicSquare(n),JE(e,r)&&(n=fe.mul(n,t));return n},Fp12finalExponentiate:t=>{const e=Zr,n=fe.div(fe.frobeniusMap(t,6),t),r=fe.mul(fe.frobeniusMap(n,2),n),i=fe.conjugate(fe._cyclotomicExp(r,e)),s=fe.mul(fe.conjugate(fe._cyclotomicSquare(r)),i),o=fe.conjugate(fe._cyclotomicExp(s,e)),a=fe.conjugate(fe._cyclotomicExp(o,e)),c=fe.mul(fe.conjugate(fe._cyclotomicExp(a,e)),fe._cyclotomicSquare(i)),f=fe.conjugate(fe._cyclotomicExp(c,e)),l=fe.frobeniusMap(fe.mul(i,a),2),h=fe.frobeniusMap(fe.mul(o,r),3),d=fe.frobeniusMap(fe.mul(c,fe.conjugate(r)),1),u=fe.mul(fe.mul(f,fe.conjugate(s)),r);return fe.mul(fe.mul(fe.mul(l,h),d),u)}}),qp=Vr(BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001")),o5=Tp(re,[[["0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6"],["0x0","0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71a"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71e","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38d"],["0x171d6541fa38ccfaed6dea691f5fb614cb14b4e7f4e810aa22d6108f142b85757098e38d0f671c7188e2aaaaaaaa5ed1","0x0"]],[["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa63"],["0xc","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa9f"],["0x1","0x0"]],[["0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706","0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706"],["0x0","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97be"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71c","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38f"],["0x124c9ad43b6cf79bfbf7043de3811ad0761b0f37a1e26286b0e977c69aa274524e79097a56dc4bd9e1b371c71c718b10","0x0"]],[["0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb"],["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3"],["0x12","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99"],["0x1","0x0"]]].map(t=>t.map(e=>re.fromBigTuple(e.map(BigInt))))),a5=Tp(te,[["0x11a05f2b1e833340b809101dd99815856b303e88a2d7005ff2627b56cdb4e2c85610c2d5f2e62d6eaeac1662734649b7","0x17294ed3e943ab2f0588bab22147a81c7c17e75b2f6a8417f565e33c70d1e86b4838f2a6f318c356e834eef1b3cb83bb","0xd54005db97678ec1d1048c5d10a9a1bce032473295983e56878e501ec68e25c958c3e3d2a09729fe0179f9dac9edcb0","0x1778e7166fcc6db74e0609d307e55412d7f5e4656a8dbf25f1b33289f1b330835336e25ce3107193c5b388641d9b6861","0xe99726a3199f4436642b4b3e4118e5499db995a1257fb3f086eeb65982fac18985a286f301e77c451154ce9ac8895d9","0x1630c3250d7313ff01d1201bf7a74ab5db3cb17dd952799b9ed3ab9097e68f90a0870d2dcae73d19cd13c1c66f652983","0xd6ed6553fe44d296a3726c38ae652bfb11586264f0f8ce19008e218f9c86b2a8da25128c1052ecaddd7f225a139ed84","0x17b81e7701abdbe2e8743884d1117e53356de5ab275b4db1a682c62ef0f2753339b7c8f8c8f475af9ccb5618e3f0c88e","0x80d3cf1f9a78fc47b90b33563be990dc43b756ce79f5574a2c596c928c5d1de4fa295f296b74e956d71986a8497e317","0x169b1f8e1bcfa7c42e0c37515d138f22dd2ecb803a0c5c99676314baf4bb1b7fa3190b2edc0327797f241067be390c9e","0x10321da079ce07e272d8ec09d2565b0dfa7dccdde6787f96d50af36003b14866f69b771f8c285decca67df3f1605fb7b","0x6e08c248e260e70bd1e962381edee3d31d79d7e22c837bc23c0bf1bc24c6b68c24b1b80b64d391fa9c8ba2e8ba2d229"],["0x8ca8d548cff19ae18b2e62f4bd3fa6f01d5ef4ba35b48ba9c9588617fc8ac62b558d681be343df8993cf9fa40d21b1c","0x12561a5deb559c4348b4711298e536367041e8ca0cf0800c0126c2588c48bf5713daa8846cb026e9e5c8276ec82b3bff","0xb2962fe57a3225e8137e629bff2991f6f89416f5a718cd1fca64e00b11aceacd6a3d0967c94fedcfcc239ba5cb83e19","0x3425581a58ae2fec83aafef7c40eb545b08243f16b1655154cca8abc28d6fd04976d5243eecf5c4130de8938dc62cd8","0x13a8e162022914a80a6f1d5f43e7a07dffdfc759a12062bb8d6b44e833b306da9bd29ba81f35781d539d395b3532a21e","0xe7355f8e4e667b955390f7f0506c6e9395735e9ce9cad4d0a43bcef24b8982f7400d24bc4228f11c02df9a29f6304a5","0x772caacf16936190f3e0c63e0596721570f5799af53a1894e2e073062aede9cea73b3538f0de06cec2574496ee84a3a","0x14a7ac2a9d64a8b230b3f5b074cf01996e7f63c21bca68a81996e1cdf9822c580fa5b9489d11e2d311f7d99bbdcc5a5e","0xa10ecf6ada54f825e920b3dafc7a3cce07f8d1d7161366b74100da67f39883503826692abba43704776ec3a79a1d641","0x95fc13ab9e92ad4476d6e3eb3a56680f682b4ee96f7d03776df533978f31c1593174e4b4b7865002d6384d168ecdd0a","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"],["0x90d97c81ba24ee0259d1f094980dcfa11ad138e48a869522b52af6c956543d3cd0c7aee9b3ba3c2be9845719707bb33","0x134996a104ee5811d51036d776fb46831223e96c254f383d0f906343eb67ad34d6c56711962fa8bfe097e75a2e41c696","0xcc786baa966e66f4a384c86a3b49942552e2d658a31ce2c344be4b91400da7d26d521628b00523b8dfe240c72de1f6","0x1f86376e8981c217898751ad8746757d42aa7b90eeb791c09e4a3ec03251cf9de405aba9ec61deca6355c77b0e5f4cb","0x8cc03fdefe0ff135caf4fe2a21529c4195536fbe3ce50b879833fd221351adc2ee7f8dc099040a841b6daecf2e8fedb","0x16603fca40634b6a2211e11db8f0a6a074a7d0d4afadb7bd76505c3d3ad5544e203f6326c95a807299b23ab13633a5f0","0x4ab0b9bcfac1bbcb2c977d027796b3ce75bb8ca2be184cb5231413c4d634f3747a87ac2460f415ec961f8855fe9d6f2","0x987c8d5333ab86fde9926bd2ca6c674170a05bfe3bdd81ffd038da6c26c842642f64550fedfe935a15e4ca31870fb29","0x9fc4018bd96684be88c9e221e4da1bb8f3abd16679dc26c1e8b6e6a1f20cabe69d65201c78607a360370e577bdba587","0xe1bba7a1186bdb5223abde7ada14a23c42a0ca7915af6fe06985e7ed1e4d43b9b3f7055dd4eba6f2bafaaebca731c30","0x19713e47937cd1be0dfd0b8f1d43fb93cd2fcbcb6caf493fd1183e416389e61031bf3a5cce3fbafce813711ad011c132","0x18b46a908f36f6deb918c143fed2edcc523559b8aaf0c2462e6bfe7f911f643249d9cdf41b44d606ce07c8a4d0074d8e","0xb182cac101b9399d155096004f53f447aa7b12a3426b08ec02710e807b4633f06c851c1919211f20d4c04f00b971ef8","0x245a394ad1eca9b72fc00ae7be315dc757b3b080d4c158013e6632d3c40659cc6cf90ad1c232a6442d9d3f5db980133","0x5c129645e44cf1102a159f748c4a3fc5e673d81d7e86568d9ab0f5d396a7ce46ba1049b6579afb7866b1e715475224b","0x15e6be4e990f03ce4ea50b3b42df2eb5cb181d8f84965a3957add4fa95af01b2b665027efec01c7704b456be69c8b604"],["0x16112c4c3a9c98b252181140fad0eae9601a6de578980be6eec3232b5be72e7a07f3688ef60c206d01479253b03663c1","0x1962d75c2381201e1a0cbd6c43c348b885c84ff731c4d59ca4a10356f453e01f78a4260763529e3532f6102c2e49a03d","0x58df3306640da276faaae7d6e8eb15778c4855551ae7f310c35a5dd279cd2eca6757cd636f96f891e2538b53dbf67f2","0x16b7d288798e5395f20d23bf89edb4d1d115c5dbddbcd30e123da489e726af41727364f2c28297ada8d26d98445f5416","0xbe0e079545f43e4b00cc912f8228ddcc6d19c9f0f69bbb0542eda0fc9dec916a20b15dc0fd2ededda39142311a5001d","0x8d9e5297186db2d9fb266eaac783182b70152c65550d881c5ecd87b6f0f5a6449f38db9dfa9cce202c6477faaf9b7ac","0x166007c08a99db2fc3ba8734ace9824b5eecfdfa8d0cf8ef5dd365bc400a0051d5fa9c01a58b1fb93d1a1399126a775c","0x16a3ef08be3ea7ea03bcddfabba6ff6ee5a4375efa1f4fd7feb34fd206357132b920f5b00801dee460ee415a15812ed9","0x1866c8ed336c61231a1be54fd1d74cc4f9fb0ce4c6af5920abc5750c4bf39b4852cfe2f7bb9248836b233d9d55535d4a","0x167a55cda70a6e1cea820597d94a84903216f763e13d87bb5308592e7ea7d4fbc7385ea3d529b35e346ef48bb8913f55","0x4d2f259eea405bd48f010a01ad2911d9c6dd039bb61a6290e591b36e636a5c871a5c29f4f83060400f8b49cba8f6aa8","0xaccbb67481d033ff5852c1e48c50c477f94ff8aefce42d28c0f9a88cea7913516f968986f7ebbea9684b529e2561092","0xad6b9514c767fe3c3613144b45f1496543346d98adf02267d5ceef9a00d9b8693000763e3b90ac11e99b138573345cc","0x2660400eb2e4f3b628bdd0d53cd76f2bf565b94e72927c1cb748df27942480e420517bd8714cc80d1fadc1326ed06f7","0xe0fa1d816ddc03e6b24255e0d7819c171c40f65e273b853324efcd6356caa205ca2f570f13497804415473a1d634b8f","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"]].map(t=>t.map(e=>BigInt(e)))),c5=Pp(re,{A:re.create({c0:te.create(Ot),c1:te.create(BigInt(240))}),B:re.create({c0:te.create(BigInt(1012)),c1:te.create(BigInt(1012))}),Z:re.create({c0:te.create(BigInt(-2)),c1:te.create(BigInt(-1))})}),f5=Pp(te,{A:te.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:te.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:te.create(BigInt(11))}),{G2psi:jp,G2psi2:u5}=r5(te,re,re.div(re.ONE,re.NONRESIDUE)),ll=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:te.ORDER,m:2,k:128,expand:"xmd",hash:lc}),xc=Ko(te.toBytes(Ot),{infinity:!0,compressed:!0});function _c(t){t=t.slice();const e=t[0]&224,n=!!(e>>7&1),r=!!(e>>6&1),i=!!(e>>5&1);return t[0]&=31,{compressed:n,infinity:r,sort:i,value:t}}function Ko(t,e){if(t[0]&224)throw new Error("setMask: non-empty mask");return e.compressed&&(t[0]|=128),e.infinity&&(t[0]|=64),e.sort&&(t[0]|=32),t}function Mp(t){t.assertValidity();const e=t.equals(_n.G1.ProjectivePoint.ZERO),{x:n,y:r}=t.toAffine();if(e)return xc.slice();const i=te.ORDER,s=!!(r*He/i);return Ko(Le(n,te.BYTES),{compressed:!0,sort:s})}function zp(t){t.assertValidity();const e=te.BYTES;if(t.equals(_n.G2.ProjectivePoint.ZERO))return De(xc,Le(Ot,e));const{x:n,y:r}=t.toAffine(),{re:i,im:s}=re.reim(n),{re:o,im:a}=re.reim(r),f=!!((a>Ot?a*He:o*He)/te.ORDER&vc),l=i;return De(Ko(Le(s,e),{sort:f,compressed:!0}),Le(l,e))}const _n=t5({fields:{Fp:te,Fp2:re,Fp6:fl,Fp12:fe,Fr:qp},G1:{Fp:te,h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1"),a:te.ZERO,b:Vo,htfDefaults:{...ll,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(t,e)=>{const n=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),r=new t(te.mul(e.px,n),e.py,e.pz);return e.multiplyUnsafe(Zr).negate().multiplyUnsafe(Zr).equals(r)},clearCofactor:(t,e)=>e.multiplyUnsafe(Zr).add(e),mapToCurve:t=>{const{x:e,y:n}=f5(te.create(t[0]));return a5(e,n)},fromBytes:t=>{const{compressed:e,infinity:n,sort:r,value:i}=_c(t);if(i.length===48&&e){const s=te.ORDER,o=Bt(i),a=te.create(o&te.MASK);if(n){if(a!==Ot)throw new Error("G1: non-empty compressed point at infinity");return{x:Ot,y:Ot}}const c=te.add(te.pow(a,Ec),te.create(_n.params.G1b));let f=te.sqrt(c);if(!f)throw new Error("invalid compressed G1 point");return f*He/s!==BigInt(r)&&(f=te.neg(f)),{x:te.create(a),y:te.create(f)}}else if(i.length===96&&!e){const s=Bt(i.subarray(0,te.BYTES)),o=Bt(i.subarray(te.BYTES));if(n){if(s!==Ot||o!==Ot)throw new Error("G1: non-empty point at infinity");return _n.G1.ProjectivePoint.ZERO.toAffine()}return{x:te.create(s),y:te.create(o)}}else throw new Error("invalid point G1, expected 48/96 bytes")},toBytes:(t,e,n)=>{const r=e.equals(t.ZERO),{x:i,y:s}=e.toAffine();if(n){if(r)return xc.slice();const o=te.ORDER,a=!!(s*He/o);return Ko(Le(i,te.BYTES),{compressed:!0,sort:a})}else return r?De(new Uint8Array([64]),new Uint8Array(2*te.BYTES-1)):De(Le(i,te.BYTES),Le(s,te.BYTES))},ShortSignature:{fromHex(t){const{infinity:e,sort:n,value:r}=_c(ut("signatureHex",t,48)),i=te.ORDER,s=Bt(r);if(e)return _n.G1.ProjectivePoint.ZERO;const o=te.create(s&te.MASK),a=te.add(te.pow(o,Ec),te.create(_n.params.G1b));let c=te.sqrt(a);if(!c)throw new Error("invalid compressed G1 point");const f=BigInt(n);c*He/i!==f&&(c=te.neg(c));const l=_n.G1.ProjectivePoint.fromAffine({x:o,y:c});return l.assertValidity(),l},toRawBytes(t){return Mp(t)},toHex(t){return es(Mp(t))}}},G2:{Fp:re,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),Gx:re.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:re.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")]),a:re.ZERO,b:re.fromBigTuple([Vo,Vo]),hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...ll},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:t=>{const{x:e,y:n}=c5(re.fromBigTuple(t));return o5(e,n)},isTorsionFree:(t,e)=>e.multiplyUnsafe(Zr).negate().equals(jp(t,e)),clearCofactor:(t,e)=>{const n=Zr;let r=e.multiplyUnsafe(n).negate(),i=jp(t,e),s=e.double();return s=u5(t,s),s=s.subtract(i),i=r.add(i),i=i.multiplyUnsafe(n).negate(),s=s.add(i),s=s.subtract(r),s.subtract(e)},fromBytes:t=>{const{compressed:e,infinity:n,sort:r,value:i}=_c(t);if(!e&&!n&&r||!e&&n&&r||r&&n&&e)throw new Error("invalid encoding flag: "+(t[0]&224));const s=te.BYTES,o=(a,c,f)=>Bt(a.slice(c,f));if(i.length===96&&e){const a=_n.params.G2b,c=te.ORDER;if(n){if(i.reduce((w,E)=>w!==0?E+1:E,0)>0)throw new Error("invalid compressed G2 point");return{x:re.ZERO,y:re.ZERO}}const f=o(i,0,s),l=o(i,s,2*s),h=re.create({c0:te.create(l),c1:te.create(f)}),d=re.add(re.pow(h,Ec),a);let u=re.sqrt(d);const b=u.c1===Ot?u.c0*He/c:u.c1*He/c?vc:Ot;return u=r&&b>0?u:re.neg(u),{x:h,y:u}}else if(i.length===192&&!e){if(n){if(i.reduce((h,d)=>h!==0?d+1:d,0)>0)throw new Error("invalid uncompressed G2 point");return{x:re.ZERO,y:re.ZERO}}const a=o(i,0,s),c=o(i,s,2*s),f=o(i,2*s,3*s),l=o(i,3*s,4*s);return{x:re.fromBigTuple([c,a]),y:re.fromBigTuple([l,f])}}else throw new Error("invalid point G2, expected 96/192 bytes")},toBytes:(t,e,n)=>{const{BYTES:r,ORDER:i}=te,s=e.equals(t.ZERO),{x:o,y:a}=e.toAffine();if(n){if(s)return De(xc,Le(Ot,r));const c=!!(a.c1===Ot?a.c0*He/i:a.c1*He/i);return De(Ko(Le(o.c1,r),{compressed:!0,sort:c}),Le(o.c0,r))}else{if(s)return De(new Uint8Array([64]),new Uint8Array(4*r-1));const{re:c,im:f}=re.reim(o),{re:l,im:h}=re.reim(a);return De(Le(f,r),Le(c,r),Le(h,r),Le(l,r))}},Signature:{fromHex(t){const{infinity:e,sort:n,value:r}=_c(ut("signatureHex",t)),i=te.ORDER,s=r.length/2;if(s!==48&&s!==96)throw new Error("invalid compressed signature length, must be 96 or 192");const o=Bt(r.slice(0,s)),a=Bt(r.slice(s));if(e)return _n.G2.ProjectivePoint.ZERO;const c=te.create(o&te.MASK),f=te.create(a),l=re.create({c0:f,c1:c}),h=re.add(re.pow(l,Ec),_n.params.G2b);let d=re.sqrt(h);if(!d)throw new Error("Failed to find a square root");const{re:u,im:b}=re.reim(d),w=BigInt(n),E=b>Ot&&b*He/i!==w,A=b===Ot&&u*He/i!==w;(E||A)&&(d=re.neg(d));const P=_n.G2.ProjectivePoint.fromAffine({x:l,y:d});return P.assertValidity(),P},toRawBytes(t){return zp(t)},toHex(t){return es(zp(t))}}},params:{ateLoopSize:Zr,r:qp.ORDER,xNegative:!0,twistType:"multiplicative"},htfDefaults:ll,hash:lc,randomBytes:j1});BigInt(0),BigInt(1),BigInt(2),BigInt(8),BigInt(0),BigInt(1),BigInt(2),BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),BigInt(0),BigInt(1),BigInt(2),BigInt(3),BigInt(5),BigInt(8);const Ks=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Sc(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function hl(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function is(t,...e){if(!Sc(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 Hp(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");hl(t.outputLen),hl(t.blockLen)}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 l5(t,e){is(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Bc(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function dl(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function jn(t,e){return t<<32-e|t>>>e}const Vp=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",h5=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Gs(t){if(is(t),Vp)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=h5[t[n]];return e}const fr={_0:48,_9:57,A:65,F:70,a:97,f:102};function Kp(t){if(t>=fr._0&&t<=fr._9)return t-fr._0;if(t>=fr.A&&t<=fr.F)return t-(fr.A-10);if(t>=fr.a&&t<=fr.f)return t-(fr.a-10)}function $c(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Vp)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=Kp(t.charCodeAt(s)),a=Kp(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)}r[i]=o*16+a}return r}function pl(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function gl(t){return typeof t=="string"&&(t=pl(t)),is(t),t}function Wr(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];is(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}class Gp{}function d5(t){const e=r=>t().update(gl(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Zp(t=32){if(Ks&&typeof Ks.getRandomValues=="function")return Ks.getRandomValues(new Uint8Array(t));if(Ks&&typeof Ks.randomBytes=="function")return Uint8Array.from(Ks.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const bl=BigInt(0),yl=BigInt(1);function Ac(t,e=""){if(typeof t!="boolean"){const n=e&&`"${e}"`;throw new Error(n+"expected boolean, got type="+typeof t)}return t}function ss(t,e,n=""){const r=Sc(t),i=t?.length,s=e!==void 0;if(!r||s&&i!==e){const o=n&&`"${n}" `,a=s?` of length ${e}`:"",c=r?`length=${i}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return t}function Oc(t){const e=t.toString(16);return e.length&1?"0"+e:e}function Wp(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?bl:BigInt("0x"+t)}function Dc(t){return Wp(Gs(t))}function Yp(t){return is(t),Wp(Gs(Uint8Array.from(t).reverse()))}function wl(t,e){return $c(t.toString(16).padStart(e*2,"0"))}function Xp(t,e){return wl(t,e).reverse()}function kt(t,e,n){let r;if(typeof e=="string")try{r=$c(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Sc(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}const ml=t=>typeof t=="bigint"&&bl<=t;function p5(t,e,n){return ml(t)&&ml(e)&&ml(n)&&e<=t&&t<n}function g5(t,e,n,r){if(!p5(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Jp(t){let e;for(e=0;t>bl;t>>=yl,e+=1);return e}const Go=t=>(yl<<BigInt(t))-yl;function b5(t,e,n){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 n!="function")throw new Error("hmacFn must be a function");const r=u=>new Uint8Array(u),i=u=>Uint8Array.of(u);let s=r(t),o=r(t),a=0;const c=()=>{s.fill(1),o.fill(0),a=0},f=(...u)=>n(o,s,...u),l=(u=r(0))=>{o=f(i(0),u),s=f(),u.length!==0&&(o=f(i(1),u),s=f())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let u=0;const b=[];for(;u<e;){s=f();const w=s.slice();b.push(w),u+=s.length}return Wr(...b)};return(u,b)=>{c(),l(u);let w;for(;!(w=b(h()));)l();return c(),w}}function vl(t,e,n={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function r(i,s,o){const a=t[i];if(o&&a===void 0)return;const c=typeof a;if(c!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${c}`)}Object.entries(e).forEach(([i,s])=>r(i,s,!1)),Object.entries(n).forEach(([i,s])=>r(i,s,!0))}function Qp(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}const qt=BigInt(0),Dt=BigInt(1),os=BigInt(2),eg=BigInt(3),tg=BigInt(4),ng=BigInt(5),y5=BigInt(7),rg=BigInt(8),w5=BigInt(9),ig=BigInt(16);function Sn(t,e){const n=t%e;return n>=qt?n:e+n}function ln(t,e,n){let r=t;for(;e-- >qt;)r*=r,r%=n;return r}function sg(t,e){if(t===qt)throw new Error("invert: expected non-zero number");if(e<=qt)throw new Error("invert: expected positive modulus, got "+e);let n=Sn(t,e),r=e,i=qt,s=Dt;for(;n!==qt;){const a=r/n,c=r%n,f=i-s*a;r=n,n=c,i=s,s=f}if(r!==Dt)throw new Error("invert: does not exist");return Sn(i,e)}function El(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function og(t,e){const n=(t.ORDER+Dt)/tg,r=t.pow(e,n);return El(t,r,e),r}function m5(t,e){const n=(t.ORDER-ng)/rg,r=t.mul(e,os),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,os),i),a=t.mul(s,t.sub(o,t.ONE));return El(t,a,e),a}function v5(t){const e=Zo(t),n=ag(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+y5)/ig;return(a,c)=>{let f=a.pow(c,o),l=a.mul(f,r);const h=a.mul(f,i),d=a.mul(f,s),u=a.eql(a.sqr(l),c),b=a.eql(a.sqr(h),c);f=a.cmov(f,l,u),l=a.cmov(d,h,b);const w=a.eql(a.sqr(l),c),E=a.cmov(f,l,w);return El(a,E,c),E}}function ag(t){if(t<eg)throw new Error("sqrt is not defined for small field");let e=t-Dt,n=0;for(;e%os===qt;)e/=os,n++;let r=os;const i=Zo(t);for(;fg(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return og;let s=i.pow(r,e);const o=(e+Dt)/os;return function(c,f){if(c.is0(f))return f;if(fg(c,f)!==1)throw new Error("Cannot find square root");let l=n,h=c.mul(c.ONE,s),d=c.pow(f,e),u=c.pow(f,o);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let b=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(b++,w=c.sqr(w),b===l)throw new Error("Cannot find square root");const E=Dt<<BigInt(l-b-1),A=c.pow(h,E);l=b,h=c.sqr(A),d=c.mul(d,h),u=c.mul(u,A)}return u}}function E5(t){return t%tg===eg?og:t%rg===ng?m5:t%ig===w5?v5(t):ag(t)}const x5=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function _5(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=x5.reduce((r,i)=>(r[i]="function",r),e);return vl(t,n),t}function S5(t,e,n){if(n<qt)throw new Error("invalid exponent, negatives unsupported");if(n===qt)return t.ONE;if(n===Dt)return e;let r=t.ONE,i=e;for(;n>qt;)n&Dt&&(r=t.mul(r,i)),i=t.sqr(i),n>>=Dt;return r}function cg(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),i=e.reduce((o,a,c)=>t.is0(a)?o:(r[c]=o,t.mul(o,a)),t.ONE),s=t.inv(i);return e.reduceRight((o,a,c)=>t.is0(a)?o:(r[c]=t.mul(o,r[c]),t.mul(o,a)),s),r}function fg(t,e){const n=(t.ORDER-Dt)/os,r=t.pow(e,n),i=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),o=t.eql(r,t.neg(t.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function ug(t,e){e!==void 0&&hl(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Zo(t,e,n=!1,r={}){if(t<=qt)throw new Error("invalid field: expected ORDER > 0, got "+t);let i,s,o=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const d=e;d.BITS&&(i=d.BITS),d.sqrt&&(s=d.sqrt),typeof d.isLE=="boolean"&&(n=d.isLE),typeof d.modFromBytes=="boolean"&&(o=d.modFromBytes),a=d.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:f}=ug(t,i);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const h=Object.freeze({ORDER:t,isLE:n,BITS:c,BYTES:f,MASK:Go(c),ZERO:qt,ONE:Dt,allowedLengths:a,create:d=>Sn(d,t),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return qt<=d&&d<t},is0:d=>d===qt,isValidNot0:d=>!h.is0(d)&&h.isValid(d),isOdd:d=>(d&Dt)===Dt,neg:d=>Sn(-d,t),eql:(d,u)=>d===u,sqr:d=>Sn(d*d,t),add:(d,u)=>Sn(d+u,t),sub:(d,u)=>Sn(d-u,t),mul:(d,u)=>Sn(d*u,t),pow:(d,u)=>S5(h,d,u),div:(d,u)=>Sn(d*sg(u,t),t),sqrN:d=>d*d,addN:(d,u)=>d+u,subN:(d,u)=>d-u,mulN:(d,u)=>d*u,inv:d=>sg(d,t),sqrt:s||(d=>(l||(l=E5(t)),l(h,d))),toBytes:d=>n?Xp(d,f):wl(d,f),fromBytes:(d,u=!0)=>{if(a){if(!a.includes(d.length)||d.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);const w=new Uint8Array(f);w.set(d,n?0:w.length-d.length),d=w}if(d.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+d.length);let b=n?Yp(d):Dc(d);if(o&&(b=Sn(b,t)),!u&&!h.isValid(b))throw new Error("invalid field element: outside of range 0..ORDER");return b},invertBatch:d=>cg(h,d),cmov:(d,u,b)=>b?u:d});return Object.freeze(h)}function lg(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 hg(t){const e=lg(t);return e+Math.ceil(e/2)}function I5(t,e,n=!1){const r=t.length,i=lg(e),s=hg(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?Yp(t):Dc(t),a=Sn(o,e-Dt)+Dt;return n?Xp(a,i):wl(a,i)}function B5(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,f=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+f,a,r)}function $5(t,e,n){return t&e^~t&n}function A5(t,e,n){return t&e^t&n^e&n}class O5 extends Gp{constructor(e,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=dl(this.buffer)}update(e){Ic(this),e=gl(e),is(e);const{view:n,buffer:r,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=dl(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ic(this),l5(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,Bc(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;B5(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=dl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const Yr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),D5=Uint32Array.from([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]),Xr=new Uint32Array(64);class P5 extends O5{constructor(e=32){super(64,e,8,!1),this.A=Yr[0]|0,this.B=Yr[1]|0,this.C=Yr[2]|0,this.D=Yr[3]|0,this.E=Yr[4]|0,this.F=Yr[5]|0,this.G=Yr[6]|0,this.H=Yr[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[e,n,r,i,s,o,a,c]}set(e,n,r,i,s,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let h=0;h<16;h++,n+=4)Xr[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const d=Xr[h-15],u=Xr[h-2],b=jn(d,7)^jn(d,18)^d>>>3,w=jn(u,17)^jn(u,19)^u>>>10;Xr[h]=w+Xr[h-7]+b+Xr[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const d=jn(a,6)^jn(a,11)^jn(a,25),u=l+d+$5(a,c,f)+D5[h]+Xr[h]|0,w=(jn(r,2)^jn(r,13)^jn(r,22))+A5(r,i,s)|0;l=f,f=c,c=a,a=o+u|0,o=s,s=i,i=r,r=u+w|0}r=r+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,f=f+this.G|0,l=l+this.H|0,this.set(r,i,s,o,a,c,f,l)}roundClean(){Bc(Xr)}destroy(){this.set(0,0,0,0,0,0,0,0),Bc(this.buffer)}}const dg=d5(()=>new P5);class pg extends Gp{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Hp(e);const r=gl(n);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(r.length>i?e.create().update(r).digest():r);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),Bc(s)}update(e){return Ic(this),this.iHash.update(e),this}digestInto(e){Ic(this),is(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:n,iHash:r,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=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const gg=(t,e,n)=>new pg(t,e).update(n).digest();gg.create=(t,e)=>new pg(t,e);const Zs=BigInt(0),as=BigInt(1);function Pc(t,e){const n=e.negate();return t?n:e}function xl(t,e){const n=cg(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function bg(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function _l(t,e){bg(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=Go(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function yg(t,e,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(t&i),c=t>>o;a>r&&(a-=s,c+=as);const f=e*r,l=f+Math.abs(a)-1,h=a===0,d=a<0,u=e%2!==0;return{nextN:c,offset:l,isZero:h,isNeg:d,isNegF:u,offsetF:f}}function R5(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function T5(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const Sl=new WeakMap,wg=new WeakMap;function Il(t){return wg.get(t)||1}function mg(t){if(t!==Zs)throw new Error("invalid wNAF")}class N5{constructor(e,n){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=n}_unsafeLadder(e,n,r=this.ZERO){let i=e;for(;n>Zs;)n&as&&(r=r.add(i)),i=i.double(),n>>=as;return r}precomputeWindow(e,n){const{windows:r,windowSize:i}=_l(n,this.bits),s=[];let o=e,a=o;for(let c=0;c<r;c++){a=o,s.push(a);for(let f=1;f<i;f++)a=a.add(o),s.push(a);o=a.double()}return s}wNAF(e,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=_l(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}=yg(r,a,o);r=c,l?s=s.add(Pc(d,n[u])):i=i.add(Pc(h,n[f]))}return mg(r),{p:i,f:s}}wNAFUnsafe(e,n,r,i=this.ZERO){const s=_l(e,this.bits);for(let o=0;o<s.windows&&r!==Zs;o++){const{nextN:a,offset:c,isZero:f,isNeg:l}=yg(r,o,s);if(r=a,!f){const h=n[c];i=i.add(l?h.negate():h)}}return mg(r),i}getPrecomputes(e,n,r){let i=Sl.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),Sl.set(n,i))),i}cached(e,n,r){const i=Il(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=Il(e);return s===1?this._unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,i)}createCache(e,n){bg(n,this.bits),wg.set(e,n),Sl.delete(e)}hasCache(e){return Il(e)!==1}}function U5(t,e,n,r){let i=e,s=t.ZERO,o=t.ZERO;for(;n>Zs||r>Zs;)n&as&&(s=s.add(i)),r&as&&(o=o.add(i)),i=i.double(),n>>=as,r>>=as;return{p1:s,p2:o}}function C5(t,e,n,r){R5(n,t),T5(r,e);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,a=Jp(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=Go(c),l=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let d=o;for(let u=h;u>=0;u-=c){l.fill(o);for(let w=0;w<s;w++){const E=r[w],A=Number(E>>BigInt(u)&f);l[A]=l[A].add(n[w])}let b=o;for(let w=l.length-1,E=o;w>0;w--)E=E.add(l[w]),b=b.add(E);if(d=d.add(b),u!==0)for(let w=0;w<c;w++)d=d.double()}return d}function vg(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return _5(e),e}else return Zo(t,{isLE:n})}function L5(t,e,n={},r){if(r===void 0&&(r=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(const c of["p","n","h"]){const f=e[c];if(!(typeof f=="bigint"&&f>Zs))throw new Error(`CURVE.${c} must be positive bigint`)}const i=vg(e.p,n.Fp,r),s=vg(e.n,n.Fn,r),a=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(const c of a)if(!i.isValid(e[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:s}}const Eg=(t,e)=>(t+(t>=0?e:-e)/xg)/e;function F5(t,e,n){const[[r,i],[s,o]]=e,a=Eg(o*t,n),c=Eg(-i*t,n);let f=t-a*r-c*s,l=-a*i-c*o;const h=f<lr,d=l<lr;h&&(f=-f),d&&(l=-l);const u=Go(Math.ceil(Jp(n)/2))+Ws;if(f<lr||f>=u||l<lr||l>=u)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:h,k1:f,k2neg:d,k2:l}}function Bl(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function $l(t,e){const n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return Ac(n.lowS,"lowS"),Ac(n.prehash,"prehash"),n.format!==void 0&&Bl(n.format),n}class k5 extends Error{constructor(e=""){super(e)}}const ur={Err:k5,_tlv:{encode:(t,e)=>{const{Err:n}=ur;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");const r=e.length/2,i=Oc(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?Oc(i.length/2|128):"";return Oc(t)+s+i+e},decode(t,e){const{Err:n}=ur;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const f=e.subarray(r,r+c);if(f.length!==c)throw new n("tlv.decode: length bytes not complete");if(f[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of f)o=o<<8|l;if(r+=c,o<128)throw new n("tlv.decode(long): not minimal encoding")}const a=e.subarray(r,r+o);if(a.length!==o)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(t){const{Err:e}=ur;if(t<lr)throw new e("integer: negative integers are not allowed");let n=Oc(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=ur;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 Dc(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=ur,i=kt("signature",t),{v:s,l:o}=r.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,s),{v:f,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(f)}},hexFromSig(t){const{_tlv:e,_int:n}=ur,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}},lr=BigInt(0),Ws=BigInt(1),xg=BigInt(2),Rc=BigInt(3),q5=BigInt(4);function Ys(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=kt("private key",e);try{r=t.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof e}`)}}if(!t.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function j5(t,e={}){const n=L5("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;vl(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=e;if(c&&(!r.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const f=Sg(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(y,p,m){const{x:g,y:v}=p.toAffine(),S=r.toBytes(g);if(Ac(m,"isCompressed"),m){l();const B=!r.isOdd(v);return Wr(_g(B),S)}else return Wr(Uint8Array.of(4),S,r.toBytes(v))}function d(y){ss(y,void 0,"Point");const{publicKey:p,publicKeyUncompressed:m}=f,g=y.length,v=y[0],S=y.subarray(1);if(g===p&&(v===2||v===3)){const B=r.fromBytes(S);if(!r.isValid(B))throw new Error("bad point: is not on curve, wrong x");const I=w(B);let $;try{$=r.sqrt(I)}catch(N){const k=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+k)}l();const T=r.isOdd($);return(v&1)===1!==T&&($=r.neg($)),{x:B,y:$}}else if(g===m&&v===4){const B=r.BYTES,I=r.fromBytes(S.subarray(0,B)),$=r.fromBytes(S.subarray(B,B*2));if(!E(I,$))throw new Error("bad point: is not on curve");return{x:I,y:$}}else throw new Error(`bad point: got length ${g}, expected compressed=${p} or uncompressed=${m}`)}const u=e.toBytes||h,b=e.fromBytes||d;function w(y){const p=r.sqr(y),m=r.mul(p,y);return r.add(r.add(m,r.mul(y,s.a)),s.b)}function E(y,p){const m=r.sqr(p),g=w(y);return r.eql(m,g)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const A=r.mul(r.pow(s.a,Rc),q5),P=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(A,P)))throw new Error("bad curve params: a or b");function _(y,p,m=!1){if(!r.isValid(p)||m&&r.is0(p))throw new Error(`bad point coordinate ${y}`);return p}function x(y){if(!(y instanceof O))throw new Error("ProjectivePoint expected")}function D(y){if(!c||!c.basises)throw new Error("no endo");return F5(y,c.basises,i.ORDER)}const U=Qp((y,p)=>{const{X:m,Y:g,Z:v}=y;if(r.eql(v,r.ONE))return{x:m,y:g};const S=y.is0();p==null&&(p=S?r.ONE:r.inv(v));const B=r.mul(m,p),I=r.mul(g,p),$=r.mul(v,p);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql($,r.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}),C=Qp(y=>{if(y.is0()){if(e.allowInfinityPoint&&!r.is0(y.Y))return;throw new Error("bad point: ZERO")}const{x:p,y:m}=y.toAffine();if(!r.isValid(p)||!r.isValid(m))throw new Error("bad point: x or y not field elements");if(!E(p,m))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function L(y,p,m,g,v){return m=new O(r.mul(m.X,y),m.Y,m.Z),p=Pc(g,p),m=Pc(v,m),p.add(m)}class O{constructor(p,m,g){this.X=_("x",p),this.Y=_("y",m,!0),this.Z=_("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){const{x:m,y:g}=p||{};if(!p||!r.isValid(m)||!r.isValid(g))throw new Error("invalid affine point");if(p instanceof O)throw new Error("projective point not allowed");return r.is0(m)&&r.is0(g)?O.ZERO:new O(m,g,r.ONE)}static fromBytes(p){const m=O.fromAffine(b(ss(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return O.fromBytes(kt("pointHex",p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,m=!0){return q.createCache(this,p),m||this.multiply(Rc),this}assertValidity(){C(this)}hasEvenY(){const{y:p}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(p)}equals(p){x(p);const{X:m,Y:g,Z:v}=this,{X:S,Y:B,Z:I}=p,$=r.eql(r.mul(m,I),r.mul(S,v)),T=r.eql(r.mul(g,I),r.mul(B,v));return $&&T}negate(){return new O(this.X,r.neg(this.Y),this.Z)}double(){const{a:p,b:m}=s,g=r.mul(m,Rc),{X:v,Y:S,Z:B}=this;let I=r.ZERO,$=r.ZERO,T=r.ZERO,F=r.mul(v,v),N=r.mul(S,S),k=r.mul(B,B),R=r.mul(v,S);return R=r.add(R,R),T=r.mul(v,B),T=r.add(T,T),I=r.mul(p,T),$=r.mul(g,k),$=r.add(I,$),I=r.sub(N,$),$=r.add(N,$),$=r.mul(I,$),I=r.mul(R,I),T=r.mul(g,T),k=r.mul(p,k),R=r.sub(F,k),R=r.mul(p,R),R=r.add(R,T),T=r.add(F,F),F=r.add(T,F),F=r.add(F,k),F=r.mul(F,R),$=r.add($,F),k=r.mul(S,B),k=r.add(k,k),F=r.mul(k,R),I=r.sub(I,F),T=r.mul(k,N),T=r.add(T,T),T=r.add(T,T),new O(I,$,T)}add(p){x(p);const{X:m,Y:g,Z:v}=this,{X:S,Y:B,Z:I}=p;let $=r.ZERO,T=r.ZERO,F=r.ZERO;const N=s.a,k=r.mul(s.b,Rc);let R=r.mul(m,S),j=r.mul(g,B),z=r.mul(v,I),V=r.add(m,g),H=r.add(S,B);V=r.mul(V,H),H=r.add(R,j),V=r.sub(V,H),H=r.add(m,v);let K=r.add(S,I);return H=r.mul(H,K),K=r.add(R,z),H=r.sub(H,K),K=r.add(g,v),$=r.add(B,I),K=r.mul(K,$),$=r.add(j,z),K=r.sub(K,$),F=r.mul(N,H),$=r.mul(k,z),F=r.add($,F),$=r.sub(j,F),F=r.add(j,F),T=r.mul($,F),j=r.add(R,R),j=r.add(j,R),z=r.mul(N,z),H=r.mul(k,H),j=r.add(j,z),z=r.sub(R,z),z=r.mul(N,z),H=r.add(H,z),R=r.mul(j,H),T=r.add(T,R),R=r.mul(K,H),$=r.mul(V,$),$=r.sub($,R),R=r.mul(V,j),F=r.mul(K,F),F=r.add(F,R),new O($,T,F)}subtract(p){return this.add(p.negate())}is0(){return this.equals(O.ZERO)}multiply(p){const{endo:m}=e;if(!i.isValidNot0(p))throw new Error("invalid scalar: out of range");let g,v;const S=B=>q.cached(this,B,I=>xl(O,I));if(m){const{k1neg:B,k1:I,k2neg:$,k2:T}=D(p),{p:F,f:N}=S(I),{p:k,f:R}=S(T);v=N.add(R),g=L(m.beta,F,k,B,$)}else{const{p:B,f:I}=S(p);g=B,v=I}return xl(O,[g,v])[0]}multiplyUnsafe(p){const{endo:m}=e,g=this;if(!i.isValid(p))throw new Error("invalid scalar: out of range");if(p===lr||g.is0())return O.ZERO;if(p===Ws)return g;if(q.hasCache(this))return this.multiply(p);if(m){const{k1neg:v,k1:S,k2neg:B,k2:I}=D(p),{p1:$,p2:T}=U5(O,g,S,I);return L(m.beta,$,T,v,B)}else return q.unsafe(g,p)}multiplyAndAddUnsafe(p,m,g){const v=this.multiplyUnsafe(m).add(p.multiplyUnsafe(g));return v.is0()?void 0:v}toAffine(p){return U(this,p)}isTorsionFree(){const{isTorsionFree:p}=e;return o===Ws?!0:p?p(O,this):q.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:p}=e;return o===Ws?this:p?p(O,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(p=!0){return Ac(p,"isCompressed"),this.assertValidity(),u(O,this,p)}toHex(p=!0){return Gs(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(p=!0){return this.toBytes(p)}_setWindowSize(p){this.precompute(p)}static normalizeZ(p){return xl(O,p)}static msm(p,m){return C5(O,i,p,m)}static fromPrivateKey(p){return O.BASE.multiply(Ys(i,p))}}O.BASE=new O(s.Gx,s.Gy,r.ONE),O.ZERO=new O(r.ZERO,r.ONE,r.ZERO),O.Fp=r,O.Fn=i;const M=i.BITS,q=new N5(O,e.endo?Math.ceil(M/2):M);return O.BASE.precompute(8),O}function _g(t){return Uint8Array.of(t?2:3)}function Sg(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function M5(t,e={}){const{Fn:n}=t,r=e.randomBytes||Zp,i=Object.assign(Sg(t.Fp,n),{seed:hg(n.ORDER)});function s(u){try{return!!Ys(n,u)}catch{return!1}}function o(u,b){const{publicKey:w,publicKeyUncompressed:E}=i;try{const A=u.length;return b===!0&&A!==w||b===!1&&A!==E?!1:!!t.fromBytes(u)}catch{return!1}}function a(u=r(i.seed)){return I5(ss(u,i.seed,"seed"),n.ORDER)}function c(u,b=!0){return t.BASE.multiply(Ys(n,u)).toBytes(b)}function f(u){const b=a(u);return{secretKey:b,publicKey:c(b)}}function l(u){if(typeof u=="bigint")return!1;if(u instanceof t)return!0;const{secretKey:b,publicKey:w,publicKeyUncompressed:E}=i;if(n.allowedLengths||b===w)return;const A=kt("key",u).length;return A===w||A===E}function h(u,b,w=!0){if(l(u)===!0)throw new Error("first arg must be private key");if(l(b)===!1)throw new Error("second arg must be public key");const E=Ys(n,u);return t.fromHex(b).multiply(E).toBytes(w)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:f,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:u=>Ys(n,u),precompute(u=8,b=t.BASE){return b.precompute(u,!1)}},lengths:i})}function z5(t,e,n={}){Hp(e),vl(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Zp,i=n.hmac||((m,...g)=>gg(e,m,Wr(...g))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:u}=M5(t,n),b={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function E(m){const g=a>>Ws;return m>g}function A(m,g){if(!o.isValidNot0(g))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return g}function P(m,g){Bl(g);const v=u.signature,S=g==="compact"?v:g==="recovered"?v+1:void 0;return ss(m,S,`${g} signature`)}class _{constructor(g,v,S){this.r=A("r",g),this.s=A("s",v),S!=null&&(this.recovery=S),Object.freeze(this)}static fromBytes(g,v=w){P(g,v);let S;if(v==="der"){const{r:T,s:F}=ur.toSig(ss(g));return new _(T,F)}v==="recovered"&&(S=g[0],v="compact",g=g.subarray(1));const B=o.BYTES,I=g.subarray(0,B),$=g.subarray(B,B*2);return new _(o.fromBytes(I),o.fromBytes($),S)}static fromHex(g,v){return this.fromBytes($c(g),v)}addRecoveryBit(g){return new _(this.r,this.s,g)}recoverPublicKey(g){const v=s.ORDER,{r:S,s:B,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*xg<v&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");const T=I===2||I===3?S+a:S;if(!s.isValid(T))throw new Error("recovery id 2 or 3 invalid");const F=s.toBytes(T),N=t.fromBytes(Wr(_g((I&1)===0),F)),k=o.inv(T),R=D(kt("msgHash",g)),j=o.create(-R*k),z=o.create(B*k),V=t.BASE.multiplyUnsafe(j).add(N.multiplyUnsafe(z));if(V.is0())throw new Error("point at infinify");return V.assertValidity(),V}hasHighS(){return E(this.s)}toBytes(g=w){if(Bl(g),g==="der")return $c(ur.hexFromSig(this));const v=o.toBytes(this.r),S=o.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Wr(Uint8Array.of(this.recovery),v,S)}return Wr(v,S)}toHex(g){return Gs(this.toBytes(g))}assertValidity(){}static fromCompact(g){return _.fromBytes(kt("sig",g),"compact")}static fromDER(g){return _.fromBytes(kt("sig",g),"der")}normalizeS(){return this.hasHighS()?new _(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Gs(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Gs(this.toBytes("compact"))}}const x=n.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");const v=Dc(g),S=g.length*8-c;return S>0?v>>BigInt(S):v},D=n.bits2int_modN||function(g){return o.create(x(g))},U=Go(c);function C(m){return g5("num < 2^"+c,m,lr,U),o.toBytes(m)}function L(m,g){return ss(m,void 0,"message"),g?ss(e(m),void 0,"prehashed message"):m}function O(m,g,v){if(["recovered","canonical"].some(j=>j in v))throw new Error("sign() legacy options not supported");const{lowS:S,prehash:B,extraEntropy:I}=$l(v,b);m=L(m,B);const $=D(m),T=Ys(o,g),F=[C(T),C($)];if(I!=null&&I!==!1){const j=I===!0?r(u.secretKey):I;F.push(kt("extraEntropy",j))}const N=Wr(...F),k=$;function R(j){const z=x(j);if(!o.isValidNot0(z))return;const V=o.inv(z),H=t.BASE.multiply(z).toAffine(),K=o.create(H.x);if(K===lr)return;const Y=o.create(V*o.create(k+K*T));if(Y===lr)return;let X=(H.x===K?0:2)|Number(H.y&Ws),ee=Y;return S&&E(Y)&&(ee=o.neg(Y),X^=1),new _(K,ee,X)}return{seed:N,k2sig:R}}function M(m,g,v={}){m=kt("message",m);const{seed:S,k2sig:B}=O(m,g,v);return b5(e.outputLen,o.BYTES,i)(S,B)}function q(m){let g;const v=typeof m=="string"||Sc(m),S=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!S)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(S)g=new _(m.r,m.s);else if(v){try{g=_.fromBytes(kt("sig",m),"der")}catch(B){if(!(B instanceof ur.Err))throw B}if(!g)try{g=_.fromBytes(kt("sig",m),"compact")}catch{return!1}}return g||!1}function y(m,g,v,S={}){const{lowS:B,prehash:I,format:$}=$l(S,b);if(v=kt("publicKey",v),g=L(kt("message",g),I),"strict"in S)throw new Error("options.strict was renamed to lowS");const T=$===void 0?q(m):_.fromBytes(kt("sig",m),$);if(T===!1)return!1;try{const F=t.fromBytes(v);if(B&&T.hasHighS())return!1;const{r:N,s:k}=T,R=D(g),j=o.inv(k),z=o.create(R*j),V=o.create(N*j),H=t.BASE.multiplyUnsafe(z).add(F.multiplyUnsafe(V));return H.is0()?!1:o.create(H.x)===N}catch{return!1}}function p(m,g,v={}){const{prehash:S}=$l(v,b);return g=L(g,S),_.fromBytes(m,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:u,Point:t,sign:M,verify:y,recoverPublicKey:p,Signature:_,hash:e})}function H5(t){const e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},n=t.Fp;let r=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0;const i=Zo(e.n,{BITS:t.nBitLength,allowedLengths:r,modFromBytes:t.wrapPrivateKey}),s={Fp:n,Fn:i,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function V5(t){const{CURVE:e,curveOpts:n}=H5(t),r={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:n,hash:t.hash,ecdsaOpts:r}}function K5(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,ug(n.Fn.ORDER,n.Fn.BITS))})}function G5(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=V5(t),s=j5(e,n),o=z5(s,r,i);return K5(t,o)}function Z5(t,e){const n=r=>G5({...t,hash:r});return{...n(e),create:n}}pl("HashToScalar-");const Al={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},W5={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Ig=BigInt(2);function Y5(t){const e=Al.p,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,l=f*f*t%e,h=ln(l,n,e)*l%e,d=ln(h,n,e)*l%e,u=ln(d,Ig,e)*f%e,b=ln(u,i,e)*u%e,w=ln(b,s,e)*b%e,E=ln(w,a,e)*w%e,A=ln(E,c,e)*E%e,P=ln(A,a,e)*w%e,_=ln(P,n,e)*l%e,x=ln(_,o,e)*b%e,D=ln(x,r,e)*f%e,U=ln(D,Ig,e);if(!Ol.eql(Ol.sqr(U),t))throw new Error("Cannot find square root");return U}const Ol=Zo(Al.p,{sqrt:Y5});Z5({...Al,Fp:Ol,lowS:!0,endo:W5},dg);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function Xs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Dl(t,...e){if(!Xs(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 Bg(t,e){return Array.isArray(e)?e.length===0?!0:t?e.every(n=>typeof n=="string"):e.every(n=>Number.isSafeInteger(n)):!1}function Pl(t){if(typeof t!="function")throw new Error("function expected");return!0}function Jr(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function Js(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Tc(t){if(!Array.isArray(t))throw new Error("array expected")}function Nc(t,e){if(!Bg(!0,e))throw new Error(`${t}: array of strings expected`)}function Rl(t,e){if(!Bg(!1,e))throw new Error(`${t}: array of numbers expected`)}function jt(...t){const e=s=>s,n=(s,o)=>a=>s(o(a)),r=t.map(s=>s.encode).reduceRight(n,e),i=t.map(s=>s.decode).reduce(n,e);return{encode:r,decode:i}}function en(t){const e=typeof t=="string"?t.split(""):t,n=e.length;Nc("alphabet",e);const r=new Map(e.map((i,s)=>[i,s]));return{encode:i=>(Tc(i),i.map(s=>{if(!Number.isSafeInteger(s)||s<0||s>=n)throw new Error(`alphabet.encode: digit index outside alphabet "${s}". Allowed: ${t}`);return e[s]})),decode:i=>(Tc(i),i.map(s=>{Jr("alphabet.decode",s);const o=r.get(s);if(o===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return o}))}}function tn(t=""){return Jr("join",t),{encode:e=>(Nc("join.decode",e),e.join(t)),decode:e=>(Jr("join.decode",e),e.split(t))}}function Uc(t,e="="){return Js(t),Jr("padding",e),{encode(n){for(Nc("padding.encode",n);n.length*t%8;)n.push(e);return n},decode(n){Nc("padding.decode",n);let r=n.length;if(r*t%8)throw new Error("padding: invalid, string should have whole number of bytes");for(;r>0&&n[r-1]===e;r--)if((r-1)*t%8===0)throw new Error("padding: invalid, string has too much padding");return n.slice(0,r)}}}function $g(t){return Pl(t),{encode:e=>e,decode:e=>t(e)}}function Ag(t,e,n){if(e<2)throw new Error(`convertRadix: invalid from=${e}, base cannot be less than 2`);if(n<2)throw new Error(`convertRadix: invalid to=${n}, base cannot be less than 2`);if(Tc(t),!t.length)return[];let r=0;const i=[],s=Array.from(t,a=>{if(Js(a),a<0||a>=e)throw new Error(`invalid integer: ${a}`);return a}),o=s.length;for(;;){let a=0,c=!0;for(let f=r;f<o;f++){const l=s[f],h=e*a,d=h+l;if(!Number.isSafeInteger(d)||h/e!==a||d-l!==h)throw new Error("convertRadix: carry overflow");const u=d/n;a=d%n;const b=Math.floor(u);if(s[f]=b,!Number.isSafeInteger(b)||b*n+a!==d)throw new Error("convertRadix: carry overflow");if(c)b?c=!1:r=f;else continue}if(i.push(a),c)break}for(let a=0;a<t.length-1&&t[a]===0;a++)i.push(0);return i.reverse()}const Og=(t,e)=>e===0?t:Og(e,t%e),Cc=(t,e)=>t+(e-Og(t,e)),Lc=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function Tl(t,e,n,r){if(Tc(t),e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(n<=0||n>32)throw new Error(`convertRadix2: wrong to=${n}`);if(Cc(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Cc(e,n)}`);let i=0,s=0;const o=Lc[e],a=Lc[n]-1,c=[];for(const f of t){if(Js(f),f>=o)throw new Error(`convertRadix2: invalid data word=${f} from=${e}`);if(i=i<<e|f,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=n;s-=n)c.push((i>>s-n&a)>>>0);const l=Lc[s];if(l===void 0)throw new Error("invalid carry");i&=l-1}if(i=i<<n-s&a,!r&&s>=e)throw new Error("Excess padding");if(!r&&i>0)throw new Error(`Non-zero padding: ${i}`);return r&&s>0&&c.push(i>>>0),c}function X5(t){Js(t);const e=2**8;return{encode:n=>{if(!Xs(n))throw new Error("radix.encode input should be Uint8Array");return Ag(Array.from(n),e,t)},decode:n=>(Rl("radix.decode",n),Uint8Array.from(Ag(n,t,e)))}}function hn(t,e=!1){if(Js(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Cc(8,t)>32||Cc(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!Xs(n))throw new Error("radix2.encode input should be Uint8Array");return Tl(Array.from(n),8,t,!e)},decode:n=>(Rl("radix2.decode",n),Uint8Array.from(Tl(n,t,8,e)))}}function Dg(t){return Pl(t),function(...e){try{return t.apply(null,e)}catch{}}}function J5(t,e){return Js(t),Pl(e),{encode(n){if(!Xs(n))throw new Error("checksum.encode: input should be Uint8Array");const r=e(n).slice(0,t),i=new Uint8Array(n.length+t);return i.set(n),i.set(r,n.length),i},decode(n){if(!Xs(n))throw new Error("checksum.decode: input should be Uint8Array");const r=n.slice(0,-t),i=n.slice(-t),s=e(r).slice(0,t);for(let o=0;o<t;o++)if(s[o]!==i[o])throw new Error("Invalid checksum");return r}}}const Q5=jt(hn(5),en("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Uc(5),tn("")),Pg=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",Rg=(t,e)=>{Jr("base64",t);const n=e?/^[A-Za-z0-9=_-]+$/:/^[A-Za-z0-9=+/]+$/,r=e?"base64url":"base64";if(t.length>0&&!n.test(t))throw new Error("invalid base64");return Uint8Array.fromBase64(t,{alphabet:r,lastChunkHandling:"strict"})},Nl=t=>jt(X5(58),en(t),tn("")),ex=Nl("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),tx=t=>jt(J5(4,e=>t(t(e))),ex),Ul=jt(en("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),tn("")),Tg=[996825010,642813549,513874426,1027748829,705979059];function Wo(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<Tg.length;r++)(e>>r&1)===1&&(n^=Tg[r]);return n}function Ng(t,e,n=1){const r=t.length;let i=1;for(let s=0;s<r;s++){const o=t.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${t})`);i=Wo(i)^o>>5}i=Wo(i);for(let s=0;s<r;s++)i=Wo(i)^t.charCodeAt(s)&31;for(let s of e)i=Wo(i)^s;for(let s=0;s<6;s++)i=Wo(i);return i^=n,Ul.encode(Tl([i%Lc[30]],30,5,!1))}function Ug(t){const e=t==="bech32"?1:734539939,n=hn(5),r=n.decode,i=n.encode,s=Dg(r);function o(h,d,u=90){Jr("bech32.encode prefix",h),Xs(d)&&(d=Array.from(d)),Rl("bech32.encode",d);const b=h.length;if(b===0)throw new TypeError(`Invalid prefix length ${b}`);const w=b+7+d.length;if(u!==!1&&w>u)throw new TypeError(`Length ${w} exceeds limit ${u}`);const E=h.toLowerCase(),A=Ng(E,d,e);return`${E}1${Ul.encode(d)}${A}`}function a(h,d=90){Jr("bech32.decode input",h);const u=h.length;if(u<8||d!==!1&&u>d)throw new TypeError(`invalid string length: ${u} (${h}). Expected (8..${d})`);const b=h.toLowerCase();if(h!==b&&h!==h.toUpperCase())throw new Error("String must be lowercase or uppercase");const w=b.lastIndexOf("1");if(w===0||w===-1)throw new Error('Letter "1" must be present between prefix and data only');const E=b.slice(0,w),A=b.slice(w+1);if(A.length<6)throw new Error("Data must be at least 6 characters long");const P=Ul.decode(A).slice(0,-6),_=Ng(E,P,e);if(!A.endsWith(_))throw new Error(`Invalid checksum in ${h}: expected "${_}"`);return{prefix:E,words:P}}const c=Dg(a);function f(h){const{prefix:d,words:u}=a(h,!1);return{prefix:d,words:u,bytes:r(u)}}function l(h,d){return o(h,i(d))}return{encode:o,decode:a,encodeFromBytes:l,decodeToBytes:f,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:s,toWords:i}}const nx=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",rx={encode(t){return Dl(t),t.toHex()},decode(t){return Jr("hex",t),Uint8Array.fromHex(t)}};tx(dg),pl("Bitcoin seed");/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function Cg(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Fc(t,...e){if(!Cg(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 kc(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 Lg(t,e){Fc(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Yo(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Cl(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function ix(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function sx(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Xo(t){if(typeof t=="string")t=sx(t);else if(Cg(t))t=Fg(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function Fg(t){return Uint8Array.from(t)}const hr=16,Ll=new Uint8Array(16),Mn=Yo(Ll),ox=225,ax=(t,e,n,r)=>{const i=r&1;return{s3:n<<31|r>>>1,s2:e<<31|n>>>1,s1:t<<31|e>>>1,s0:t>>>1^ox<<24&-(i&1)}},dn=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255|0;function cx(t){t.reverse();const e=t[15]&1;let n=0;for(let r=0;r<t.length;r++){const i=t[r];t[r]=i>>>1|n,n=(i&1)<<7}return t[0]^=-e&225,t}const fx=t=>t>64*1024?8:t>1024?4:2;class kg{constructor(e,n){this.blockLen=hr,this.outputLen=hr,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=Xo(e),Fc(e,16);const r=ix(e);let i=r.getUint32(0,!1),s=r.getUint32(4,!1),o=r.getUint32(8,!1),a=r.getUint32(12,!1);const c=[];for(let b=0;b<128;b++)c.push({s0:dn(i),s1:dn(s),s2:dn(o),s3:dn(a)}),{s0:i,s1:s,s2:o,s3:a}=ax(i,s,o,a);const f=fx(n||1024);if(![1,2,4,8].includes(f))throw new Error("ghash: invalid window size, expected 2, 4 or 8");this.W=f;const h=128/f,d=this.windowSize=2**f,u=[];for(let b=0;b<h;b++)for(let w=0;w<d;w++){let E=0,A=0,P=0,_=0;for(let x=0;x<f;x++){if(!(w>>>f-x-1&1))continue;const{s0:U,s1:C,s2:L,s3:O}=c[f*b+x];E^=U,A^=C,P^=L,_^=O}u.push({s0:E,s1:A,s2:P,s3:_})}this.t=u}_updateBlock(e,n,r,i){e^=this.s0,n^=this.s1,r^=this.s2,i^=this.s3;const{W:s,t:o,windowSize:a}=this;let c=0,f=0,l=0,h=0;const d=(1<<s)-1;let u=0;for(const b of[e,n,r,i])for(let w=0;w<4;w++){const E=b>>>8*w&255;for(let A=8/s-1;A>=0;A--){const P=E>>>s*A&d,{s0:_,s1:x,s2:D,s3:U}=o[u*a+P];c^=_,f^=x,l^=D,h^=U,u+=1}}this.s0=c,this.s1=f,this.s2=l,this.s3=h}update(e){kc(this),e=Xo(e),Fc(e);const n=Yo(e),r=Math.floor(e.length/hr),i=e.length%hr;for(let s=0;s<r;s++)this._updateBlock(n[s*4+0],n[s*4+1],n[s*4+2],n[s*4+3]);return i&&(Ll.set(e.subarray(r*hr)),this._updateBlock(Mn[0],Mn[1],Mn[2],Mn[3]),Cl(Mn)),this}destroy(){const{t:e}=this;for(const n of e)n.s0=0,n.s1=0,n.s2=0,n.s3=0}digestInto(e){kc(this),Lg(e,this),this.finished=!0;const{s0:n,s1:r,s2:i,s3:s}=this,o=Yo(e);return o[0]=n,o[1]=r,o[2]=i,o[3]=s,e}digest(){const e=new Uint8Array(hr);return this.digestInto(e),this.destroy(),e}}class ux extends kg{constructor(e,n){e=Xo(e),Fc(e);const r=cx(Fg(e));super(r,n),Cl(r)}update(e){e=Xo(e),kc(this);const n=Yo(e),r=e.length%hr,i=Math.floor(e.length/hr);for(let s=0;s<i;s++)this._updateBlock(dn(n[s*4+3]),dn(n[s*4+2]),dn(n[s*4+1]),dn(n[s*4+0]));return r&&(Ll.set(e.subarray(i*hr)),this._updateBlock(dn(Mn[3]),dn(Mn[2]),dn(Mn[1]),dn(Mn[0])),Cl(Mn)),this}digestInto(e){kc(this),Lg(e,this),this.finished=!0;const{s0:n,s1:r,s2:i,s3:s}=this,o=Yo(e);return o[0]=n,o[1]=r,o[2]=i,o[3]=s,e.reverse()}}function qg(t){const e=(r,i)=>t(i,r.length).update(Xo(r)).digest(),n=t(new Uint8Array(16),0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=(r,i)=>t(r,i),e}qg((t,e)=>new kg(t,e)),qg((t,e)=>new ux(t,e));const jg=Vr(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),lx=jg.create(BigInt("-3")),hx=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");wc({a:lx,b:hx,Fp:jg,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},lc);const Mg=Vr(BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff")),dx=Mg.create(BigInt("-3")),px=BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef");wc({a:dx,b:px,Fp:Mg,n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"),h:BigInt(1),lowS:!1},YE);const zg=Vr(BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),gx=zg.create(BigInt("-3")),bx=BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00");wc({a:gx,b:bx,Fp:zg,n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650"),h:BigInt(1),lowS:!1,allowedPrivateKeyLengths:[130,131,132]},WE);var yx={exports:{}};(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(c,f,l){this.fn=c,this.context=f,this.once=l||!1}function s(c,f,l,h,d){if(typeof l!="function")throw new TypeError("The listener must be a function");var u=new i(l,h||c,d),b=n?n+f:f;return c._events[b]?c._events[b].fn?c._events[b]=[c._events[b],u]:c._events[b].push(u):(c._events[b]=u,c._eventsCount++),c}function o(c,f){--c._eventsCount===0?c._events=new r:delete c._events[f]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var f=[],l,h;if(this._eventsCount===0)return f;for(h in l=this._events)e.call(l,h)&&f.push(n?h.slice(1):h);return Object.getOwnPropertySymbols?f.concat(Object.getOwnPropertySymbols(l)):f},a.prototype.listeners=function(f){var l=n?n+f:f,h=this._events[l];if(!h)return[];if(h.fn)return[h.fn];for(var d=0,u=h.length,b=new Array(u);d<u;d++)b[d]=h[d].fn;return b},a.prototype.listenerCount=function(f){var l=n?n+f:f,h=this._events[l];return h?h.fn?1:h.length:0},a.prototype.emit=function(f,l,h,d,u,b){var w=n?n+f:f;if(!this._events[w])return!1;var E=this._events[w],A=arguments.length,P,_;if(E.fn){switch(E.once&&this.removeListener(f,E.fn,void 0,!0),A){case 1:return E.fn.call(E.context),!0;case 2:return E.fn.call(E.context,l),!0;case 3:return E.fn.call(E.context,l,h),!0;case 4:return E.fn.call(E.context,l,h,d),!0;case 5:return E.fn.call(E.context,l,h,d,u),!0;case 6:return E.fn.call(E.context,l,h,d,u,b),!0}for(_=1,P=new Array(A-1);_<A;_++)P[_-1]=arguments[_];E.fn.apply(E.context,P)}else{var x=E.length,D;for(_=0;_<x;_++)switch(E[_].once&&this.removeListener(f,E[_].fn,void 0,!0),A){case 1:E[_].fn.call(E[_].context);break;case 2:E[_].fn.call(E[_].context,l);break;case 3:E[_].fn.call(E[_].context,l,h);break;case 4:E[_].fn.call(E[_].context,l,h,d);break;default:if(!P)for(D=1,P=new Array(A-1);D<A;D++)P[D-1]=arguments[D];E[_].fn.apply(E[_].context,P)}}return!0},a.prototype.on=function(f,l,h){return s(this,f,l,h,!1)},a.prototype.once=function(f,l,h){return s(this,f,l,h,!0)},a.prototype.removeListener=function(f,l,h,d){var u=n?n+f:f;if(!this._events[u])return this;if(!l)return o(this,u),this;var b=this._events[u];if(b.fn)b.fn===l&&(!d||b.once)&&(!h||b.context===h)&&o(this,u);else{for(var w=0,E=[],A=b.length;w<A;w++)(b[w].fn!==l||d&&!b[w].once||h&&b[w].context!==h)&&E.push(b[w]);E.length?this._events[u]=E.length===1?E[0]:E:o(this,u)}return this},a.prototype.removeAllListeners=function(f){var l;return f?(l=n?n+f:f,this._events[l]&&o(this,l)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a})(yx);function wx(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 l=t.charAt(f),h=l.charCodeAt(0);if(e[h]!==255)throw new TypeError(l+" is ambiguous");e[h]=f}const n=t.length,r=t.charAt(0),i=Math.log(n)/Math.log(256),s=Math.log(256)/Math.log(n);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 l=0,h=0,d=0;const u=f.length;for(;d!==u&&f[d]===0;)d++,l++;const b=(u-d)*s+1>>>0,w=new Uint8Array(b);for(;d!==u;){let P=f[d],_=0;for(let x=b-1;(P!==0||_<h)&&x!==-1;x--,_++)P+=256*w[x]>>>0,w[x]=P%n>>>0,P=P/n>>>0;if(P!==0)throw new Error("Non-zero carry");h=_,d++}let E=b-h;for(;E!==b&&w[E]===0;)E++;let A=r.repeat(l);for(;E<b;++E)A+=t.charAt(w[E]);return A}function a(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;let l=0,h=0,d=0;for(;f[l]===r;)h++,l++;const u=(f.length-l)*i+1>>>0,b=new Uint8Array(u);for(;l<f.length;){const P=f.charCodeAt(l);if(P>255)return;let _=e[P];if(_===255)return;let x=0;for(let D=u-1;(_!==0||x<d)&&D!==-1;D--,x++)_+=n*b[D]>>>0,b[D]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");d=x,l++}let w=u-d;for(;w!==u&&b[w]===0;)w++;const E=new Uint8Array(h+(u-w));let A=h;for(;w!==u;)E[A++]=b[w++];return E}function c(f){const l=a(f);if(l)return l;throw new Error("Non-base"+n+" character")}return{encode:o,decodeUnsafe:a,decode:c}}var mx="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",Jo=wx(mx);function vx(t){const e=t.length;let n=0,r=0;for(;r<e;){let i=t.charCodeAt(r++);if((i&4294967168)===0){n++;continue}else if((i&4294965248)===0)n+=2;else{if(i>=55296&&i<=56319&&r<e){const s=t.charCodeAt(r);(s&64512)===56320&&(++r,i=((i&1023)<<10)+(s&1023)+65536)}(i&4294901760)===0?n+=3:n+=4}}return n}function Ex(t,e,n){const r=t.length;let i=n,s=0;for(;s<r;){let o=t.charCodeAt(s++);if((o&4294967168)===0){e[i++]=o;continue}else if((o&4294965248)===0)e[i++]=o>>6&31|192;else{if(o>=55296&&o<=56319&&s<r){const a=t.charCodeAt(s);(a&64512)===56320&&(++s,o=((o&1023)<<10)+(a&1023)+65536)}(o&4294901760)===0?(e[i++]=o>>12&15|224,e[i++]=o>>6&63|128):(e[i++]=o>>18&7|240,e[i++]=o>>12&63|128,e[i++]=o>>6&63|128)}e[i++]=o&63|128}}const xx=new TextEncoder,_x=50;function Sx(t,e,n){xx.encodeInto(t,e.subarray(n))}function Ix(t,e,n){t.length>_x?Sx(t,e,n):Ex(t,e,n)}const Bx=4096;function Hg(t,e,n){let r=e;const i=r+n,s=[];let o="";for(;r<i;){const a=t[r++];if((a&128)===0)s.push(a);else if((a&224)===192){const c=t[r++]&63;s.push((a&31)<<6|c)}else if((a&240)===224){const c=t[r++]&63,f=t[r++]&63;s.push((a&31)<<12|c<<6|f)}else if((a&248)===240){const c=t[r++]&63,f=t[r++]&63,l=t[r++]&63;let h=(a&7)<<18|c<<12|f<<6|l;h>65535&&(h-=65536,s.push(h>>>10&1023|55296),h=56320|h&1023),s.push(h)}else s.push(a);s.length>=Bx&&(o+=String.fromCharCode(...s),s.length=0)}return s.length>0&&(o+=String.fromCharCode(...s)),o}const $x=new TextDecoder,Ax=200;function Ox(t,e,n){const r=t.subarray(e,e+n);return $x.decode(r)}function Dx(t,e,n){return n>Ax?Ox(t,e,n):Hg(t,e,n)}class qc{constructor(e,n){this.type=e,this.data=n}}class nn extends Error{constructor(e){super(e);const n=Object.create(nn.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:nn.name})}}const Qo=4294967295;function Px(t,e,n){const r=n/4294967296,i=n;t.setUint32(e,r),t.setUint32(e+4,i)}function Vg(t,e,n){const r=Math.floor(n/4294967296),i=n;t.setUint32(e,r),t.setUint32(e+4,i)}function Kg(t,e){const n=t.getInt32(e),r=t.getUint32(e+4);return n*4294967296+r}function Rx(t,e){const n=t.getUint32(e),r=t.getUint32(e+4);return n*4294967296+r}const Tx=-1,Nx=4294967296-1,Ux=17179869184-1;function Cx({sec:t,nsec:e}){if(t>=0&&e>=0&&t<=Ux)if(e===0&&t<=Nx){const n=new Uint8Array(4);return new DataView(n.buffer).setUint32(0,t),n}else{const n=t/4294967296,r=t&4294967295,i=new Uint8Array(8),s=new DataView(i.buffer);return s.setUint32(0,e<<2|n&3),s.setUint32(4,r),i}else{const n=new Uint8Array(12),r=new DataView(n.buffer);return r.setUint32(0,e),Vg(r,4,t),n}}function Lx(t){const e=t.getTime(),n=Math.floor(e/1e3),r=(e-n*1e3)*1e6,i=Math.floor(r/1e9);return{sec:n+i,nsec:r-i*1e9}}function Fx(t){if(t instanceof Date){const e=Lx(t);return Cx(e)}else return null}function kx(t){const e=new DataView(t.buffer,t.byteOffset,t.byteLength);switch(t.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{const n=e.getUint32(0),r=e.getUint32(4),i=(n&3)*4294967296+r,s=n>>>2;return{sec:i,nsec:s}}case 12:{const n=Kg(e,4),r=e.getUint32(0);return{sec:n,nsec:r}}default:throw new nn(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${t.length}`)}}function qx(t){const e=kx(t);return new Date(e.sec*1e3+e.nsec/1e6)}const jx={type:Tx,encode:Fx,decode:qx};class jc{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(jx)}register({type:e,encode:n,decode:r}){if(e>=0)this.encoders[e]=n,this.decoders[e]=r;else{const i=-1-e;this.builtInEncoders[i]=n,this.builtInDecoders[i]=r}}tryToEncode(e,n){for(let r=0;r<this.builtInEncoders.length;r++){const i=this.builtInEncoders[r];if(i!=null){const s=i(e,n);if(s!=null){const o=-1-r;return new qc(o,s)}}}for(let r=0;r<this.encoders.length;r++){const i=this.encoders[r];if(i!=null){const s=i(e,n);if(s!=null){const o=r;return new qc(o,s)}}}return e instanceof qc?e:null}decode(e,n,r){const i=n<0?this.builtInDecoders[-1-n]:this.decoders[n];return i?i(e,n,r):new qc(n,e)}}jc.defaultCodec=new jc;function Mx(t){return t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer}function Fl(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Mx(t)?new Uint8Array(t):Uint8Array.from(t)}const zx=100,Hx=2048;class kl{constructor(e){this.entered=!1,this.extensionCodec=e?.extensionCodec??jc.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??zx,this.initialBufferSize=e?.initialBufferSize??Hx,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new kl({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,n){if(n>this.maxDepth)throw new Error(`Too deep objects in depth ${n}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,n)}ensureBufferSizeToWrite(e){const n=this.pos+e;this.view.byteLength<n&&this.resizeBuffer(n*2)}resizeBuffer(e){const n=new ArrayBuffer(e),r=new Uint8Array(n),i=new DataView(n);r.set(this.bytes),this.view=i,this.bytes=r}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){const r=vx(e);this.ensureBufferSizeToWrite(5+r),this.writeStringHeader(r),Ix(e,this.bytes,this.pos),this.pos+=r}encodeObject(e,n){const r=this.extensionCodec.tryToEncode(e,this.context);if(r!=null)this.encodeExtension(r);else if(Array.isArray(e))this.encodeArray(e,n);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,n);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){const n=e.byteLength;if(n<256)this.writeU8(196),this.writeU8(n);else if(n<65536)this.writeU8(197),this.writeU16(n);else if(n<4294967296)this.writeU8(198),this.writeU32(n);else throw new Error(`Too large binary: ${n}`);const r=Fl(e);this.writeU8a(r)}encodeArray(e,n){const r=e.length;if(r<16)this.writeU8(144+r);else if(r<65536)this.writeU8(220),this.writeU16(r);else if(r<4294967296)this.writeU8(221),this.writeU32(r);else throw new Error(`Too large array: ${r}`);for(const i of e)this.doEncode(i,n+1)}countWithoutUndefined(e,n){let r=0;for(const i of n)e[i]!==void 0&&r++;return r}encodeMap(e,n){const r=Object.keys(e);this.sortKeys&&r.sort();const i=this.ignoreUndefined?this.countWithoutUndefined(e,r):r.length;if(i<16)this.writeU8(128+i);else if(i<65536)this.writeU8(222),this.writeU16(i);else if(i<4294967296)this.writeU8(223),this.writeU32(i);else throw new Error(`Too large map object: ${i}`);for(const s of r){const o=e[s];this.ignoreUndefined&&o===void 0||(this.encodeString(s),this.doEncode(o,n+1))}}encodeExtension(e){if(typeof e.data=="function"){const r=e.data(this.pos+6),i=r.length;if(i>=4294967296)throw new Error(`Too large extension object: ${i}`);this.writeU8(201),this.writeU32(i),this.writeI8(e.type),this.writeU8a(r);return}const n=e.data.length;if(n===1)this.writeU8(212);else if(n===2)this.writeU8(213);else if(n===4)this.writeU8(214);else if(n===8)this.writeU8(215);else if(n===16)this.writeU8(216);else if(n<256)this.writeU8(199),this.writeU8(n);else if(n<65536)this.writeU8(200),this.writeU16(n);else if(n<4294967296)this.writeU8(201),this.writeU32(n);else throw new Error(`Too large extension object: ${n}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){const n=e.length;this.ensureBufferSizeToWrite(n),this.bytes.set(e,this.pos),this.pos+=n}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),Px(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),Vg(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}}function Vx(t,e){return new kl(e).encodeSharedRef(t)}function ql(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}const Kx=16,Gx=16;class Zx{constructor(e=Kx,n=Gx){this.hit=0,this.miss=0,this.maxKeyLength=e,this.maxLengthPerKey=n,this.caches=[];for(let r=0;r<this.maxKeyLength;r++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,n,r){const i=this.caches[r-1];e:for(const s of i){const o=s.bytes;for(let a=0;a<r;a++)if(o[a]!==e[n+a])continue e;return s.str}return null}store(e,n){const r=this.caches[e.length-1],i={bytes:e,str:n};r.length>=this.maxLengthPerKey?r[Math.random()*r.length|0]=i:r.push(i)}decode(e,n,r){const i=this.find(e,n,r);if(i!=null)return this.hit++,i;this.miss++;const s=Hg(e,n,r),o=Uint8Array.prototype.slice.call(e,n,n+r);return this.store(o,s),s}}const jl="array",ea="map_key",Gg="map_value",Wx=t=>{if(typeof t=="string"||typeof t=="number")return t;throw new nn("The type of key must be string or number but "+typeof t)};class Yx{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){const n=this.getUninitializedStateFromPool();n.type=jl,n.position=0,n.size=e,n.array=new Array(e)}pushMapState(e){const n=this.getUninitializedStateFromPool();n.type=ea,n.readCount=0,n.size=e,n.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){const e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===jl){const r=e;r.size=0,r.array=void 0,r.position=0,r.type=void 0}if(e.type===ea||e.type===Gg){const r=e;r.size=0,r.map=void 0,r.readCount=0,r.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}const ta=-1,Ml=new DataView(new ArrayBuffer(0)),Xx=new Uint8Array(Ml.buffer);try{Ml.getInt8(0)}catch(t){if(!(t instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}const Zg=new RangeError("Insufficient data"),Jx=new Zx;class zl{constructor(e){this.totalPos=0,this.pos=0,this.view=Ml,this.bytes=Xx,this.headByte=ta,this.stack=new Yx,this.entered=!1,this.extensionCodec=e?.extensionCodec??jc.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??Qo,this.maxBinLength=e?.maxBinLength??Qo,this.maxArrayLength=e?.maxArrayLength??Qo,this.maxMapLength=e?.maxMapLength??Qo,this.maxExtLength=e?.maxExtLength??Qo,this.keyDecoder=e?.keyDecoder!==void 0?e.keyDecoder:Jx,this.mapKeyConverter=e?.mapKeyConverter??Wx}clone(){return new zl({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=ta,this.stack.reset()}setBuffer(e){const n=Fl(e);this.bytes=n,this.view=new DataView(n.buffer,n.byteOffset,n.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===ta&&!this.hasRemaining(1))this.setBuffer(e);else{const n=this.bytes.subarray(this.pos),r=Fl(e),i=new Uint8Array(n.length+r.length);i.set(n),i.set(r,n.length),this.setBuffer(i)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){const{view:n,pos:r}=this;return new RangeError(`Extra ${n.byteLength-r} of ${n.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);const n=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return n}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let n=!1,r;for await(const a of e){if(n)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(a);try{r=this.doDecodeSync(),n=!0}catch(c){if(!(c instanceof RangeError))throw c}this.totalPos+=this.pos}if(n){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return r}const{headByte:i,pos:s,totalPos:o}=this;throw new RangeError(`Insufficient data in parsing ${ql(i)} at ${o} (${s} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,n){if(this.entered){yield*this.clone().decodeMultiAsync(e,n);return}try{this.entered=!0;let r=n,i=-1;for await(const s of e){if(n&&i===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(s),r&&(i=this.readArraySize(),r=!1,this.complete());try{for(;yield this.doDecodeSync(),--i!==0;);}catch(o){if(!(o instanceof RangeError))throw o}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){const e=this.readHeadByte();let n;if(e>=224)n=e-256;else if(e<192)if(e<128)n=e;else if(e<144){const i=e-128;if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e<160){const i=e-144;if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else{const i=e-160;n=this.decodeString(i,0)}else if(e===192)n=null;else if(e===194)n=!1;else if(e===195)n=!0;else if(e===202)n=this.readF32();else if(e===203)n=this.readF64();else if(e===204)n=this.readU8();else if(e===205)n=this.readU16();else if(e===206)n=this.readU32();else if(e===207)this.useBigInt64?n=this.readU64AsBigInt():n=this.readU64();else if(e===208)n=this.readI8();else if(e===209)n=this.readI16();else if(e===210)n=this.readI32();else if(e===211)this.useBigInt64?n=this.readI64AsBigInt():n=this.readI64();else if(e===217){const i=this.lookU8();n=this.decodeString(i,1)}else if(e===218){const i=this.lookU16();n=this.decodeString(i,2)}else if(e===219){const i=this.lookU32();n=this.decodeString(i,4)}else if(e===220){const i=this.readU16();if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else if(e===221){const i=this.readU32();if(i!==0){this.pushArrayState(i),this.complete();continue e}else n=[]}else if(e===222){const i=this.readU16();if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e===223){const i=this.readU32();if(i!==0){this.pushMapState(i),this.complete();continue e}else n={}}else if(e===196){const i=this.lookU8();n=this.decodeBinary(i,1)}else if(e===197){const i=this.lookU16();n=this.decodeBinary(i,2)}else if(e===198){const i=this.lookU32();n=this.decodeBinary(i,4)}else if(e===212)n=this.decodeExtension(1,0);else if(e===213)n=this.decodeExtension(2,0);else if(e===214)n=this.decodeExtension(4,0);else if(e===215)n=this.decodeExtension(8,0);else if(e===216)n=this.decodeExtension(16,0);else if(e===199){const i=this.lookU8();n=this.decodeExtension(i,1)}else if(e===200){const i=this.lookU16();n=this.decodeExtension(i,2)}else if(e===201){const i=this.lookU32();n=this.decodeExtension(i,4)}else throw new nn(`Unrecognized type byte: ${ql(e)}`);this.complete();const r=this.stack;for(;r.length>0;){const i=r.top();if(i.type===jl)if(i.array[i.position]=n,i.position++,i.position===i.size)n=i.array,r.release(i);else continue e;else if(i.type===ea){if(n==="__proto__")throw new nn("The key __proto__ is not allowed");i.key=this.mapKeyConverter(n),i.type=Gg;continue e}else if(i.map[i.key]=n,i.readCount++,i.readCount===i.size)n=i.map,r.release(i);else{i.key=null,i.type=ea;continue e}}return n}}readHeadByte(){return this.headByte===ta&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=ta}readArraySize(){const e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new nn(`Unrecognized array type byte: ${ql(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new nn(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new nn(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,n){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,n):this.decodeBinary(e,n)}decodeUtf8String(e,n){if(e>this.maxStrLength)throw new nn(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+n+e)throw Zg;const r=this.pos+n;let i;return this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?i=this.keyDecoder.decode(this.bytes,r,e):i=Dx(this.bytes,r,e),this.pos+=n+e,i}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===ea:!1}decodeBinary(e,n){if(e>this.maxBinLength)throw new nn(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+n))throw Zg;const r=this.pos+n,i=this.bytes.subarray(r,r+e);return this.pos+=n+e,i}decodeExtension(e,n){if(e>this.maxExtLength)throw new nn(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);const r=this.view.getInt8(this.pos+n),i=this.decodeBinary(e,n+1);return this.extensionCodec.decode(i,r,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){const e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){const e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){const e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){const e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){const e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){const e=Rx(this.view,this.pos);return this.pos+=8,e}readI64(){const e=Kg(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){const e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){const e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){const e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){const e=this.view.getFloat64(this.pos);return this.pos+=8,e}}function Qx(t,e){return new zl(e).decode(t)}const e7=t=>JSON.stringify(t,(e,n)=>typeof n=="bigint"?n.toString()+"n":n),t7=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,n=t.replace(e,'$1"$2n"$3');return JSON.parse(n,(r,i)=>typeof i=="string"&&i.match(/^\d+n$/)?BigInt(i.substring(0,i.length-1)):i)};function Qs(t){if(typeof t!="string")throw new Error(`Cannot safe json parse value of type ${typeof t}`);try{return t7(t)}catch{return t}}function na(t){return typeof t=="string"?t:e7(t)||""}function n7(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Wg(t,...e){if(!n7(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 Yg(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 r7(t,e){Wg(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const eo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Hl=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function i7(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function Xg(t){return typeof t=="string"&&(t=i7(t)),Wg(t),t}class s7{clone(){return this._cloneInto()}}function o7(t){const e=r=>t().update(Xg(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Jg(t=32){if(eo&&typeof eo.getRandomValues=="function")return eo.getRandomValues(new Uint8Array(t));if(eo&&typeof eo.randomBytes=="function")return eo.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function a7(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,f=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+f,a,r)}class c7 extends s7{constructor(e,n,r,i){super(),this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=Hl(this.buffer)}update(e){Yg(this);const{view:n,buffer:r,blockLen:i}=this;e=Xg(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=Hl(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Yg(this),r7(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;a7(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Hl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.length=i,e.pos=a,e.finished=s,e.destroyed=o,i%n&&e.buffer.set(r),e}}const Mc=BigInt(2**32-1),Vl=BigInt(32);function Qg(t,e=!1){return e?{h:Number(t&Mc),l:Number(t>>Vl&Mc)}:{h:Number(t>>Vl&Mc)|0,l:Number(t&Mc)|0}}function f7(t,e=!1){let n=new Uint32Array(t.length),r=new Uint32Array(t.length);for(let i=0;i<t.length;i++){const{h:s,l:o}=Qg(t[i],e);[n[i],r[i]]=[s,o]}return[n,r]}const u7=(t,e)=>BigInt(t>>>0)<<Vl|BigInt(e>>>0),l7=(t,e,n)=>t>>>n,h7=(t,e,n)=>t<<32-n|e>>>n,d7=(t,e,n)=>t>>>n|e<<32-n,p7=(t,e,n)=>t<<32-n|e>>>n,g7=(t,e,n)=>t<<64-n|e>>>n-32,b7=(t,e,n)=>t>>>n-32|e<<64-n,y7=(t,e)=>e,w7=(t,e)=>t,m7=(t,e,n)=>t<<n|e>>>32-n,v7=(t,e,n)=>e<<n|t>>>32-n,E7=(t,e,n)=>e<<n-32|t>>>64-n,x7=(t,e,n)=>t<<n-32|e>>>64-n;function _7(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const S7=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),I7=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,B7=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),$7=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,A7=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),O7=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,ce={fromBig:Qg,split:f7,toBig:u7,shrSH:l7,shrSL:h7,rotrSH:d7,rotrSL:p7,rotrBH:g7,rotrBL:b7,rotr32H:y7,rotr32L:w7,rotlSH:m7,rotlSL:v7,rotlBH:E7,rotlBL:x7,add:_7,add3L:S7,add3H:I7,add4L:B7,add4H:$7,add5H:O7,add5L:A7},[D7,P7]=ce.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))),Qr=new Uint32Array(80),ei=new Uint32Array(80);class R7 extends c7{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:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:h,Fl:d,Gh:u,Gl:b,Hh:w,Hl:E}=this;return[e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E]}set(e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=h|0,this.Fl=d|0,this.Gh=u|0,this.Gl=b|0,this.Hh=w|0,this.Hl=E|0}process(e,n){for(let _=0;_<16;_++,n+=4)Qr[_]=e.getUint32(n),ei[_]=e.getUint32(n+=4);for(let _=16;_<80;_++){const x=Qr[_-15]|0,D=ei[_-15]|0,U=ce.rotrSH(x,D,1)^ce.rotrSH(x,D,8)^ce.shrSH(x,D,7),C=ce.rotrSL(x,D,1)^ce.rotrSL(x,D,8)^ce.shrSL(x,D,7),L=Qr[_-2]|0,O=ei[_-2]|0,M=ce.rotrSH(L,O,19)^ce.rotrBH(L,O,61)^ce.shrSH(L,O,6),q=ce.rotrSL(L,O,19)^ce.rotrBL(L,O,61)^ce.shrSL(L,O,6),y=ce.add4L(C,q,ei[_-7],ei[_-16]),p=ce.add4H(y,U,M,Qr[_-7],Qr[_-16]);Qr[_]=p|0,ei[_]=y|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:h,El:d,Fh:u,Fl:b,Gh:w,Gl:E,Hh:A,Hl:P}=this;for(let _=0;_<80;_++){const x=ce.rotrSH(h,d,14)^ce.rotrSH(h,d,18)^ce.rotrBH(h,d,41),D=ce.rotrSL(h,d,14)^ce.rotrSL(h,d,18)^ce.rotrBL(h,d,41),U=h&u^~h&w,C=d&b^~d&E,L=ce.add5L(P,D,C,P7[_],ei[_]),O=ce.add5H(L,A,x,U,D7[_],Qr[_]),M=L|0,q=ce.rotrSH(r,i,28)^ce.rotrBH(r,i,34)^ce.rotrBH(r,i,39),y=ce.rotrSL(r,i,28)^ce.rotrBL(r,i,34)^ce.rotrBL(r,i,39),p=r&s^r&a^s&a,m=i&o^i&c^o&c;A=w|0,P=E|0,w=u|0,E=b|0,u=h|0,b=d|0,{h,l:d}=ce.add(f|0,l|0,O|0,M|0),f=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=ce.add3L(M,y,m);r=ce.add3H(g,O,q,p),i=g|0}({h:r,l:i}=ce.add(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=ce.add(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=ce.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=ce.add(this.Dh|0,this.Dl|0,f|0,l|0),{h,l:d}=ce.add(this.Eh|0,this.El|0,h|0,d|0),{h:u,l:b}=ce.add(this.Fh|0,this.Fl|0,u|0,b|0),{h:w,l:E}=ce.add(this.Gh|0,this.Gl|0,w|0,E|0),{h:A,l:P}=ce.add(this.Hh|0,this.Hl|0,A|0,P|0),this.set(r,i,s,o,a,c,f,l,h,d,u,b,w,E,A,P)}roundClean(){Qr.fill(0),ei.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 T7=o7(()=>new R7);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Kl=BigInt(0),eb=BigInt(1),N7=BigInt(2);function Gl(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Zl(t){if(!Gl(t))throw new Error("Uint8Array expected")}function Wl(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const U7=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Yl(t){Zl(t);let e="";for(let n=0;n<t.length;n++)e+=U7[t[n]];return e}function tb(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Kl:BigInt("0x"+t)}const dr={_0:48,_9:57,A:65,F:70,a:97,f:102};function nb(t){if(t>=dr._0&&t<=dr._9)return t-dr._0;if(t>=dr.A&&t<=dr.F)return t-(dr.A-10);if(t>=dr.a&&t<=dr.f)return t-(dr.a-10)}function rb(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=nb(t.charCodeAt(s)),a=nb(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)}r[i]=o*16+a}return r}function C7(t){return tb(Yl(t))}function zc(t){return Zl(t),tb(Yl(Uint8Array.from(t).reverse()))}function ib(t,e){return rb(t.toString(16).padStart(e*2,"0"))}function Xl(t,e){return ib(t,e).reverse()}function pr(t,e,n){let r;if(typeof e=="string")try{r=rb(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Gl(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}function sb(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Zl(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}const Jl=t=>typeof t=="bigint"&&Kl<=t;function L7(t,e,n){return Jl(t)&&Jl(e)&&Jl(n)&&e<=t&&t<n}function ra(t,e,n,r){if(!L7(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function F7(t){let e;for(e=0;t>Kl;t>>=eb,e+=1);return e}const k7=t=>(N7<<BigInt(t-1))-eb,q7={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"||Gl(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 Ql(t,e,n={}){const r=(i,s,o)=>{const a=q7[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))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return t}function ob(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}const Ve=BigInt(0),Pe=BigInt(1),cs=BigInt(2),j7=BigInt(3),eh=BigInt(4),ab=BigInt(5),cb=BigInt(8);function Fe(t,e){const n=t%e;return n>=Ve?n:e+n}function M7(t,e,n){if(e<Ve)throw new Error("invalid exponent, negatives unsupported");if(n<=Ve)throw new Error("invalid modulus");if(n===Pe)return Ve;let r=Pe;for(;e>Ve;)e&Pe&&(r=r*t%n),t=t*t%n,e>>=Pe;return r}function zn(t,e,n){let r=t;for(;e-- >Ve;)r*=r,r%=n;return r}function fb(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 n=Fe(t,e),r=e,i=Ve,s=Pe;for(;n!==Ve;){const o=r/n,a=r%n,c=i-s*o;r=n,n=a,i=s,s=c}if(r!==Pe)throw new Error("invert: does not exist");return Fe(i,e)}function z7(t){const e=(t-Pe)/cs;let n,r,i;for(n=t-Pe,r=0;n%cs===Ve;n/=cs,r++);for(i=cs;i<t&&M7(i,e,t)!==t-Pe;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(r===1){const o=(t+Pe)/eh;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=(n+Pe)/cs;return function(o,a){if(o.pow(a,e)===o.neg(o.ONE))throw new Error("Cannot find square root");let c=r,f=o.pow(o.mul(o.ONE,i),n),l=o.pow(a,s),h=o.pow(a,n);for(;!o.eql(h,o.ONE);){if(o.eql(h,o.ZERO))return o.ZERO;let d=1;for(let b=o.sqr(h);d<c&&!o.eql(b,o.ONE);d++)b=o.sqr(b);const u=o.pow(f,Pe<<BigInt(c-d-1));f=o.sqr(u),l=o.mul(l,u),h=o.mul(h,f),c=d}return l}}function H7(t){if(t%eh===j7){const e=(t+Pe)/eh;return function(n,r){const i=n.pow(r,e);if(!n.eql(n.sqr(i),r))throw new Error("Cannot find square root");return i}}if(t%cb===ab){const e=(t-ab)/cb;return function(n,r){const i=n.mul(r,cs),s=n.pow(i,e),o=n.mul(r,s),a=n.mul(n.mul(o,cs),s),c=n.mul(o,n.sub(a,n.ONE));if(!n.eql(n.sqr(c),r))throw new Error("Cannot find square root");return c}}return z7(t)}const V7=(t,e)=>(Fe(t,e)&Pe)===Pe,K7=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function G7(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=K7.reduce((r,i)=>(r[i]="function",r),e);return Ql(t,n)}function Z7(t,e,n){if(n<Ve)throw new Error("invalid exponent, negatives unsupported");if(n===Ve)return t.ONE;if(n===Pe)return e;let r=t.ONE,i=e;for(;n>Ve;)n&Pe&&(r=t.mul(r,i)),i=t.sqr(i),n>>=Pe;return r}function W7(t,e){const n=new Array(e.length),r=e.reduce((s,o,a)=>t.is0(o)?s:(n[a]=s,t.mul(s,o)),t.ONE),i=t.inv(r);return e.reduceRight((s,o,a)=>t.is0(o)?s:(n[a]=t.mul(s,n[a]),t.mul(s,o)),i),n}function ub(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function lb(t,e,n=!1,r={}){if(t<=Ve)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=ub(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:n,BITS:i,BYTES:s,MASK:k7(i),ZERO:Ve,ONE:Pe,create:c=>Fe(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&Pe)===Pe,neg:c=>Fe(-c,t),eql:(c,f)=>c===f,sqr:c=>Fe(c*c,t),add:(c,f)=>Fe(c+f,t),sub:(c,f)=>Fe(c-f,t),mul:(c,f)=>Fe(c*f,t),pow:(c,f)=>Z7(a,c,f),div:(c,f)=>Fe(c*fb(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>fb(c,t),sqrt:r.sqrt||(c=>(o||(o=H7(t)),o(a,c))),invertBatch:c=>W7(a,c),cmov:(c,f,l)=>l?f:c,toBytes:c=>n?Xl(c,s):ib(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return n?zc(c):C7(c)}});return Object.freeze(a)}const hb=BigInt(0),Hc=BigInt(1);function th(t,e){const n=e.negate();return t?n:e}function db(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function nh(t,e){db(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1);return{windows:n,windowSize:r}}function Y7(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function X7(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const rh=new WeakMap,pb=new WeakMap;function ih(t){return pb.get(t)||1}function J7(t,e){return{constTimeNegate:th,hasPrecomputes(n){return ih(n)!==1},unsafeLadder(n,r,i=t.ZERO){let s=n;for(;r>hb;)r&Hc&&(i=i.add(s)),s=s.double(),r>>=Hc;return i},precomputeWindow(n,r){const{windows:i,windowSize:s}=nh(r,e),o=[];let a=n,c=a;for(let f=0;f<i;f++){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(n,r,i){const{windows:s,windowSize:o}=nh(n,e);let a=t.ZERO,c=t.BASE;const f=BigInt(2**n-1),l=2**n,h=BigInt(n);for(let d=0;d<s;d++){const u=d*o;let b=Number(i&f);i>>=h,b>o&&(b-=l,i+=Hc);const w=u,E=u+Math.abs(b)-1,A=d%2!==0,P=b<0;b===0?c=c.add(th(A,r[w])):a=a.add(th(P,r[E]))}return{p:a,f:c}},wNAFUnsafe(n,r,i,s=t.ZERO){const{windows:o,windowSize:a}=nh(n,e),c=BigInt(2**n-1),f=2**n,l=BigInt(n);for(let h=0;h<o;h++){const d=h*a;if(i===hb)break;let u=Number(i&c);if(i>>=l,u>a&&(u-=f,i+=Hc),u===0)continue;let b=r[d+Math.abs(u)-1];u<0&&(b=b.negate()),s=s.add(b)}return s},getPrecomputes(n,r,i){let s=rh.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&rh.set(r,i(s))),s},wNAFCached(n,r,i){const s=ih(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=ih(n);return o===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,n,i),r,s)},setWindowSize(n,r){db(r,e),pb.set(n,r),rh.delete(n)}}}function Q7(t,e,n,r){if(Y7(n,t),X7(r,e),n.length!==r.length)throw new Error("arrays of points and scalars must have equal length");const i=t.ZERO,s=F7(BigInt(n.length)),o=s>12?s-3:s>4?s-2:s?2:1,a=(1<<o)-1,c=new Array(a+1).fill(i),f=Math.floor((e.BITS-1)/o)*o;let l=i;for(let h=f;h>=0;h-=o){c.fill(i);for(let u=0;u<r.length;u++){const b=r[u],w=Number(b>>BigInt(h)&BigInt(a));c[w]=c[w].add(n[u])}let d=i;for(let u=c.length-1,b=i;u>0;u--)b=b.add(c[u]),d=d.add(b);if(l=l.add(d),h!==0)for(let u=0;u<o;u++)l=l.double()}return l}function e9(t){return G7(t.Fp),Ql(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...ub(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}const In=BigInt(0),Mt=BigInt(1),Vc=BigInt(2),t9=BigInt(8),n9={zip215:!0};function r9(t){const e=e9(t);return Ql(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function i9(t){const e=r9(t),{Fp:n,n:r,prehash:i,hash:s,randomBytes:o,nByteLength:a,h:c}=e,f=Vc<<BigInt(a*8)-Mt,l=n.create,h=lb(e.n,e.nBitLength),d=e.uvRatio||((g,v)=>{try{return{isValid:!0,value:n.sqrt(g*n.inv(v))}}catch{return{isValid:!1,value:In}}}),u=e.adjustScalarBytes||(g=>g),b=e.domain||((g,v,S)=>{if(Wl("phflag",S),v.length||S)throw new Error("Contexts/pre-hash are not supported");return g});function w(g,v){ra("coordinate "+g,v,In,f)}function E(g){if(!(g instanceof _))throw new Error("ExtendedPoint expected")}const A=ob((g,v)=>{const{ex:S,ey:B,ez:I}=g,$=g.is0();v==null&&(v=$?t9:n.inv(I));const T=l(S*v),F=l(B*v),N=l(I*v);if($)return{x:In,y:Mt};if(N!==Mt)throw new Error("invZ was invalid");return{x:T,y:F}}),P=ob(g=>{const{a:v,d:S}=e;if(g.is0())throw new Error("bad point: ZERO");const{ex:B,ey:I,ez:$,et:T}=g,F=l(B*B),N=l(I*I),k=l($*$),R=l(k*k),j=l(F*v),z=l(k*l(j+N)),V=l(R+l(S*l(F*N)));if(z!==V)throw new Error("bad point: equation left != right (1)");const H=l(B*I),K=l($*T);if(H!==K)throw new Error("bad point: equation left != right (2)");return!0});class _{constructor(v,S,B,I){this.ex=v,this.ey=S,this.ez=B,this.et=I,w("x",v),w("y",S),w("z",B),w("t",I),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(v){if(v instanceof _)throw new Error("extended point not allowed");const{x:S,y:B}=v||{};return w("x",S),w("y",B),new _(S,B,Mt,l(S*B))}static normalizeZ(v){const S=n.invertBatch(v.map(B=>B.ez));return v.map((B,I)=>B.toAffine(S[I])).map(_.fromAffine)}static msm(v,S){return Q7(_,h,v,S)}_setWindowSize(v){U.setWindowSize(this,v)}assertValidity(){P(this)}equals(v){E(v);const{ex:S,ey:B,ez:I}=this,{ex:$,ey:T,ez:F}=v,N=l(S*F),k=l($*I),R=l(B*F),j=l(T*I);return N===k&&R===j}is0(){return this.equals(_.ZERO)}negate(){return new _(l(-this.ex),this.ey,this.ez,l(-this.et))}double(){const{a:v}=e,{ex:S,ey:B,ez:I}=this,$=l(S*S),T=l(B*B),F=l(Vc*l(I*I)),N=l(v*$),k=S+B,R=l(l(k*k)-$-T),j=N+T,z=j-F,V=N-T,H=l(R*z),K=l(j*V),Y=l(R*V),X=l(z*j);return new _(H,K,X,Y)}add(v){E(v);const{a:S,d:B}=e,{ex:I,ey:$,ez:T,et:F}=this,{ex:N,ey:k,ez:R,et:j}=v;if(S===BigInt(-1)){const Bv=l(($-I)*(k+N)),$v=l(($+I)*(k-N)),Q0=l($v-Bv);if(Q0===In)return this.double();const Av=l(T*Vc*j),Ov=l(F*Vc*R),Dv=Ov+Av,Pv=$v+Bv,Rv=Ov-Av,Mj=l(Dv*Q0),zj=l(Pv*Rv),Hj=l(Dv*Rv),Vj=l(Q0*Pv);return new _(Mj,zj,Vj,Hj)}const z=l(I*N),V=l($*k),H=l(F*B*j),K=l(T*R),Y=l((I+$)*(N+k)-z-V),X=K-H,ee=K+H,se=l(V-S*z),oe=l(Y*X),ot=l(ee*se),Ns=l(Y*se),jj=l(X*ee);return new _(oe,ot,jj,Ns)}subtract(v){return this.add(v.negate())}wNAF(v){return U.wNAFCached(this,v,_.normalizeZ)}multiply(v){const S=v;ra("scalar",S,Mt,r);const{p:B,f:I}=this.wNAF(S);return _.normalizeZ([B,I])[0]}multiplyUnsafe(v,S=_.ZERO){const B=v;return ra("scalar",B,In,r),B===In?D:this.is0()||B===Mt?this:U.wNAFCachedUnsafe(this,B,_.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.unsafeLadder(this,r).is0()}toAffine(v){return A(this,v)}clearCofactor(){const{h:v}=e;return v===Mt?this:this.multiplyUnsafe(v)}static fromHex(v,S=!1){const{d:B,a:I}=e,$=n.BYTES;v=pr("pointHex",v,$),Wl("zip215",S);const T=v.slice(),F=v[$-1];T[$-1]=F&-129;const N=zc(T),k=S?f:n.ORDER;ra("pointHex.y",N,In,k);const R=l(N*N),j=l(R-Mt),z=l(B*R-I);let{isValid:V,value:H}=d(j,z);if(!V)throw new Error("Point.fromHex: invalid y coordinate");const K=(H&Mt)===Mt,Y=(F&128)!==0;if(!S&&H===In&&Y)throw new Error("Point.fromHex: x=0 and x_0=1");return Y!==K&&(H=l(-H)),_.fromAffine({x:H,y:N})}static fromPrivateKey(v){return O(v).point}toRawBytes(){const{x:v,y:S}=this.toAffine(),B=Xl(S,n.BYTES);return B[B.length-1]|=v&Mt?128:0,B}toHex(){return Yl(this.toRawBytes())}}_.BASE=new _(e.Gx,e.Gy,Mt,l(e.Gx*e.Gy)),_.ZERO=new _(In,Mt,Mt,In);const{BASE:x,ZERO:D}=_,U=J7(_,a*8);function C(g){return Fe(g,r)}function L(g){return C(zc(g))}function O(g){const v=n.BYTES;g=pr("private key",g,v);const S=pr("hashed private key",s(g),2*v),B=u(S.slice(0,v)),I=S.slice(v,2*v),$=L(B),T=x.multiply($),F=T.toRawBytes();return{head:B,prefix:I,scalar:$,point:T,pointBytes:F}}function M(g){return O(g).pointBytes}function q(g=new Uint8Array,...v){const S=sb(...v);return L(s(b(S,pr("context",g),!!i)))}function y(g,v,S={}){g=pr("message",g),i&&(g=i(g));const{prefix:B,scalar:I,pointBytes:$}=O(v),T=q(S.context,B,g),F=x.multiply(T).toRawBytes(),N=q(S.context,F,$,g),k=C(T+N*I);ra("signature.s",k,In,r);const R=sb(F,Xl(k,n.BYTES));return pr("result",R,n.BYTES*2)}const p=n9;function m(g,v,S,B=p){const{context:I,zip215:$}=B,T=n.BYTES;g=pr("signature",g,2*T),v=pr("message",v),S=pr("publicKey",S,T),$!==void 0&&Wl("zip215",$),i&&(v=i(v));const F=zc(g.slice(T,2*T));let N,k,R;try{N=_.fromHex(S,$),k=_.fromHex(g.slice(0,T),$),R=x.multiplyUnsafe(F)}catch{return!1}if(!$&&N.isSmallOrder())return!1;const j=q(I,k.toRawBytes(),N.toRawBytes(),v);return k.add(N.multiplyUnsafe(j)).subtract(R).clearCofactor().equals(_.ZERO)}return x._setWindowSize(8),{CURVE:e,getPublicKey:M,sign:y,verify:m,ExtendedPoint:_,utils:{getExtendedPublicKey:O,randomPrivateKey:()=>o(n.BYTES),precompute(g=8,v=_.BASE){return v._setWindowSize(g),v.multiply(BigInt(3)),v}}}}BigInt(0),BigInt(1);const sh=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),gb=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);const s9=BigInt(1),bb=BigInt(2);BigInt(3);const o9=BigInt(5),a9=BigInt(8);function c9(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=sh,o=t*t%s*t%s,a=zn(o,bb,s)*o%s,c=zn(a,s9,s)*t%s,f=zn(c,o9,s)*c%s,l=zn(f,e,s)*f%s,h=zn(l,n,s)*l%s,d=zn(h,r,s)*h%s,u=zn(d,i,s)*d%s,b=zn(u,i,s)*d%s,w=zn(b,e,s)*f%s;return{pow_p_5_8:zn(w,bb,s)*t%s,b2:o}}function f9(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function u9(t,e){const n=sh,r=Fe(e*e*e,n),i=Fe(r*r*e,n),s=c9(t*i).pow_p_5_8;let o=Fe(t*r*s,n);const a=Fe(e*o*o,n),c=o,f=Fe(o*gb,n),l=a===t,h=a===Fe(-t,n),d=a===Fe(-t*gb,n);return l&&(o=c),(h||d)&&(o=f),V7(o,n)&&(o=Fe(-o,n)),{isValid:l||h,value:o}}const l9=lb(sh,void 0,!0),h9={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:l9,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:a9,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:T7,randomBytes:Jg,adjustScalarBytes:f9,uvRatio:u9},yb=i9(h9),d9="EdDSA",p9="JWT",Kc=".",Gc="base64url",wb="utf8",mb="utf8",g9=":",b9="did",y9="key",vb="base58btc",w9="z",m9="K36",v9=32;function oh(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Eb(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?oh(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function xb(t,e){e||(e=t.reduce((i,s)=>i+s.length,0));const n=Eb(e);let r=0;for(const i of t)n.set(i,r),r+=i.length;return oh(n)}function E9(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var w=0,E=0,A=0,P=b.length;A!==P&&b[A]===0;)A++,w++;for(var _=(P-A)*l+1>>>0,x=new Uint8Array(_);A!==P;){for(var D=b[A],U=0,C=_-1;(D!==0||U<E)&&C!==-1;C--,U++)D+=256*x[C]>>>0,x[C]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");E=U,A++}for(var L=_-E;L!==_&&x[L]===0;)L++;for(var O=c.repeat(w);L<_;++L)O+=t.charAt(x[L]);return O}function d(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var w=0;if(b[w]!==" "){for(var E=0,A=0;b[w]===c;)E++,w++;for(var P=(b.length-w)*f+1>>>0,_=new Uint8Array(P);b[w];){var x=n[b.charCodeAt(w)];if(x===255)return;for(var D=0,U=P-1;(x!==0||D<A)&&U!==-1;U--,D++)x+=a*_[U]>>>0,_[U]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");A=D,w++}if(b[w]!==" "){for(var C=P-A;C!==P&&_[C]===0;)C++;for(var L=new Uint8Array(E+(P-C)),O=E;C!==P;)L[O++]=_[C++];return L}}}function u(b){var w=d(b);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:d,decode:u}}var x9=E9,_9=x9;const _b=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")},S9=t=>new TextEncoder().encode(t),I9=t=>new TextDecoder().decode(t);class B9{constructor(e,n,r){this.name=e,this.prefix=n,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class $9{constructor(e,n,r){if(this.name=e,this.prefix=n,n.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=n.codePointAt(0),this.baseDecode=r}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 Sb(this,e)}}class A9{constructor(e){this.decoders=e}or(e){return Sb(this,e)}decode(e){const n=e[0],r=this.decoders[n];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Sb=(t,e)=>new A9({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class O9{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new B9(e,n,r),this.decoder=new $9(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Zc=({name:t,prefix:e,encode:n,decode:r})=>new O9(t,e,n,r),ia=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=_9(n,e);return Zc({prefix:t,name:e,encode:r,decode:s=>_b(i(s))})},D9=(t,e,n,r)=>{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*n/8|0);let a=0,c=0,f=0;for(let l=0;l<s;++l){const h=i[t[l]];if(h===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<n|h,a+=n,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=n||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},P9=(t,e,n)=>{const r=e[e.length-1]==="=",i=(1<<n)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>n;)o-=n,s+=e[i&a>>o];if(o&&(s+=e[i&a<<n-o]),r)for(;s.length*n&7;)s+="=";return s},Xe=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>Zc({prefix:e,name:t,encode(i){return P9(i,r,n)},decode(i){return D9(i,r,n,t)}}),R9=Zc({prefix:"\0",name:"identity",encode:t=>I9(t),decode:t=>S9(t)});var T9=Object.freeze({__proto__:null,identity:R9});const N9=Xe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var U9=Object.freeze({__proto__:null,base2:N9});const C9=Xe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var L9=Object.freeze({__proto__:null,base8:C9});const F9=ia({prefix:"9",name:"base10",alphabet:"0123456789"});var k9=Object.freeze({__proto__:null,base10:F9});const q9=Xe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),j9=Xe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var M9=Object.freeze({__proto__:null,base16:q9,base16upper:j9});const z9=Xe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),H9=Xe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),V9=Xe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),K9=Xe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),G9=Xe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Z9=Xe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),W9=Xe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Y9=Xe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),X9=Xe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var J9=Object.freeze({__proto__:null,base32:z9,base32upper:H9,base32pad:V9,base32padupper:K9,base32hex:G9,base32hexupper:Z9,base32hexpad:W9,base32hexpadupper:Y9,base32z:X9});const Q9=ia({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),e_=ia({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var t_=Object.freeze({__proto__:null,base36:Q9,base36upper:e_});const n_=ia({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),r_=ia({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var i_=Object.freeze({__proto__:null,base58btc:n_,base58flickr:r_});const s_=Xe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),o_=Xe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),a_=Xe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),c_=Xe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var f_=Object.freeze({__proto__:null,base64:s_,base64pad:o_,base64url:a_,base64urlpad:c_});const Ib=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}"),u_=Ib.reduce((t,e,n)=>(t[n]=e,t),[]),l_=Ib.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function h_(t){return t.reduce((e,n)=>(e+=u_[n],e),"")}function d_(t){const e=[];for(const n of t){const r=l_[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const p_=Zc({prefix:"\u{1F680}",name:"base256emoji",encode:h_,decode:d_});var g_=Object.freeze({__proto__:null,base256emoji:p_}),b_=$b,Bb=128,y_=127,w_=~y_,m_=Math.pow(2,31);function $b(t,e,n){e=e||[],n=n||0;for(var r=n;t>=m_;)e[n++]=t&255|Bb,t/=128;for(;t&w_;)e[n++]=t&255|Bb,t>>>=7;return e[n]=t|0,$b.bytes=n-r+1,e}var v_=ah,E_=128,Ab=127;function ah(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw ah.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&Ab)<<i:(o&Ab)*Math.pow(2,i),i+=7}while(o>=E_);return ah.bytes=s-r,n}var x_=Math.pow(2,7),__=Math.pow(2,14),S_=Math.pow(2,21),I_=Math.pow(2,28),B_=Math.pow(2,35),$_=Math.pow(2,42),A_=Math.pow(2,49),O_=Math.pow(2,56),D_=Math.pow(2,63),P_=function(t){return t<x_?1:t<__?2:t<S_?3:t<I_?4:t<B_?5:t<$_?6:t<A_?7:t<O_?8:t<D_?9:10},R_={encode:b_,decode:v_,encodingLength:P_},Ob=R_;const Db=(t,e,n=0)=>(Ob.encode(t,e,n),e),Pb=t=>Ob.encodingLength(t),ch=(t,e)=>{const n=e.byteLength,r=Pb(t),i=r+Pb(n),s=new Uint8Array(i+n);return Db(t,s,0),Db(n,s,r),s.set(e,i),new T_(t,n,e,s)};class T_{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const Rb=({name:t,code:e,encode:n})=>new N_(t,e,n);class N_{constructor(e,n,r){this.name=e,this.code=n,this.encode=r}digest(e){if(e instanceof Uint8Array){const n=this.encode(e);return n instanceof Uint8Array?ch(this.code,n):n.then(r=>ch(this.code,r))}else throw Error("Unknown type, must be binary type")}}const Tb=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),U_=Rb({name:"sha2-256",code:18,encode:Tb("SHA-256")}),C_=Rb({name:"sha2-512",code:19,encode:Tb("SHA-512")});var L_=Object.freeze({__proto__:null,sha256:U_,sha512:C_});const Nb=0,F_="identity",Ub=_b;var k_=Object.freeze({__proto__:null,identity:{code:Nb,name:F_,encode:Ub,digest:t=>ch(Nb,Ub(t))}});new TextEncoder,new TextDecoder;const Cb={...T9,...U9,...L9,...k9,...M9,...J9,...t_,...i_,...f_,...g_};({...L_,...k_});function Lb(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const Fb=Lb("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),fh=Lb("ascii","a",t=>{let e="a";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e},t=>{t=t.substring(1);const e=Eb(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),kb={utf8:Fb,"utf-8":Fb,hex:Cb.base16,latin1:fh,ascii:fh,binary:fh,...Cb};function Wc(t,e="utf8"){const n=kb[e];if(!n)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"):n.encoder.encode(t).substring(1)}function to(t,e="utf8"){const n=kb[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?oh(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}function qb(t){return Qs(Wc(to(t,Gc),wb))}function Yc(t){return Wc(to(na(t),wb),Gc)}function jb(t){const e=to(m9,vb),n=w9+Wc(xb([e,t]),vb);return[b9,y9,n].join(g9)}function q_(t){return Wc(t,Gc)}function j_(t){return to(t,Gc)}function M_(t){return to([Yc(t.header),Yc(t.payload)].join(Kc),mb)}function z_(t){return[Yc(t.header),Yc(t.payload),q_(t.signature)].join(Kc)}function uh(t){const e=t.split(Kc),n=qb(e[0]),r=qb(e[1]),i=j_(e[2]),s=to(e.slice(0,2).join(Kc),mb);return{header:n,payload:r,signature:i,data:s}}function Mb(t=Jg(v9)){const e=yb.getPublicKey(t);return{secretKey:xb([t,e]),publicKey:e}}async function H_(t,e,n,r,i=Z.fromMiliseconds(Date.now())){const s={alg:d9,typ:p9},o=jb(r.publicKey),a=i+n,c={iss:o,sub:t,aud:e,iat:i,exp:a},f=M_({header:s,payload:c}),l=yb.sign(f,r.secretKey.slice(0,32));return z_({header:s,payload:c,signature:l})}function lh(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function zb(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?lh(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function sa(t,e){e||(e=t.reduce((i,s)=>i+s.length,0));const n=zb(e);let r=0;for(const i of t)n.set(i,r),r+=i.length;return lh(n)}function V_(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var w=0,E=0,A=0,P=b.length;A!==P&&b[A]===0;)A++,w++;for(var _=(P-A)*l+1>>>0,x=new Uint8Array(_);A!==P;){for(var D=b[A],U=0,C=_-1;(D!==0||U<E)&&C!==-1;C--,U++)D+=256*x[C]>>>0,x[C]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");E=U,A++}for(var L=_-E;L!==_&&x[L]===0;)L++;for(var O=c.repeat(w);L<_;++L)O+=t.charAt(x[L]);return O}function d(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var w=0;if(b[w]!==" "){for(var E=0,A=0;b[w]===c;)E++,w++;for(var P=(b.length-w)*f+1>>>0,_=new Uint8Array(P);b[w];){var x=n[b.charCodeAt(w)];if(x===255)return;for(var D=0,U=P-1;(x!==0||D<A)&&U!==-1;U--,D++)x+=a*_[U]>>>0,_[U]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");A=D,w++}if(b[w]!==" "){for(var C=P-A;C!==P&&_[C]===0;)C++;for(var L=new Uint8Array(E+(P-C)),O=E;C!==P;)L[O++]=_[C++];return L}}}function u(b){var w=d(b);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:d,decode:u}}var K_=V_,G_=K_;const Hb=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")},Z_=t=>new TextEncoder().encode(t),W_=t=>new TextDecoder().decode(t);class Y_{constructor(e,n,r){this.name=e,this.prefix=n,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class X_{constructor(e,n,r){if(this.name=e,this.prefix=n,n.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=n.codePointAt(0),this.baseDecode=r}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 Vb(this,e)}}class J_{constructor(e){this.decoders=e}or(e){return Vb(this,e)}decode(e){const n=e[0],r=this.decoders[n];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const Vb=(t,e)=>new J_({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class Q_{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new Y_(e,n,r),this.decoder=new X_(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Xc=({name:t,prefix:e,encode:n,decode:r})=>new Q_(t,e,n,r),oa=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=G_(n,e);return Xc({prefix:t,name:e,encode:r,decode:s=>Hb(i(s))})},eS=(t,e,n,r)=>{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*n/8|0);let a=0,c=0,f=0;for(let l=0;l<s;++l){const h=i[t[l]];if(h===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<n|h,a+=n,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=n||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},tS=(t,e,n)=>{const r=e[e.length-1]==="=",i=(1<<n)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>n;)o-=n,s+=e[i&a>>o];if(o&&(s+=e[i&a<<n-o]),r)for(;s.length*n&7;)s+="=";return s},Je=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>Xc({prefix:e,name:t,encode(i){return tS(i,r,n)},decode(i){return eS(i,r,n,t)}}),nS=Xc({prefix:"\0",name:"identity",encode:t=>W_(t),decode:t=>Z_(t)});var rS=Object.freeze({__proto__:null,identity:nS});const iS=Je({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var sS=Object.freeze({__proto__:null,base2:iS});const oS=Je({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var aS=Object.freeze({__proto__:null,base8:oS});const cS=oa({prefix:"9",name:"base10",alphabet:"0123456789"});var fS=Object.freeze({__proto__:null,base10:cS});const uS=Je({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),lS=Je({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hS=Object.freeze({__proto__:null,base16:uS,base16upper:lS});const dS=Je({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),pS=Je({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),gS=Je({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),bS=Je({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yS=Je({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),wS=Je({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),mS=Je({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),vS=Je({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ES=Je({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var xS=Object.freeze({__proto__:null,base32:dS,base32upper:pS,base32pad:gS,base32padupper:bS,base32hex:yS,base32hexupper:wS,base32hexpad:mS,base32hexpadupper:vS,base32z:ES});const _S=oa({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),SS=oa({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var IS=Object.freeze({__proto__:null,base36:_S,base36upper:SS});const BS=oa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$S=oa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var AS=Object.freeze({__proto__:null,base58btc:BS,base58flickr:$S});const OS=Je({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),DS=Je({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),PS=Je({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),RS=Je({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var TS=Object.freeze({__proto__:null,base64:OS,base64pad:DS,base64url:PS,base64urlpad:RS});const Kb=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}"),NS=Kb.reduce((t,e,n)=>(t[n]=e,t),[]),US=Kb.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function CS(t){return t.reduce((e,n)=>(e+=NS[n],e),"")}function LS(t){const e=[];for(const n of t){const r=US[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const FS=Xc({prefix:"\u{1F680}",name:"base256emoji",encode:CS,decode:LS});var kS=Object.freeze({__proto__:null,base256emoji:FS}),qS=Zb,Gb=128,jS=127,MS=~jS,zS=Math.pow(2,31);function Zb(t,e,n){e=e||[],n=n||0;for(var r=n;t>=zS;)e[n++]=t&255|Gb,t/=128;for(;t&MS;)e[n++]=t&255|Gb,t>>>=7;return e[n]=t|0,Zb.bytes=n-r+1,e}var HS=hh,VS=128,Wb=127;function hh(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw hh.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&Wb)<<i:(o&Wb)*Math.pow(2,i),i+=7}while(o>=VS);return hh.bytes=s-r,n}var KS=Math.pow(2,7),GS=Math.pow(2,14),ZS=Math.pow(2,21),WS=Math.pow(2,28),YS=Math.pow(2,35),XS=Math.pow(2,42),JS=Math.pow(2,49),QS=Math.pow(2,56),eI=Math.pow(2,63),tI=function(t){return t<KS?1:t<GS?2:t<ZS?3:t<WS?4:t<YS?5:t<XS?6:t<JS?7:t<QS?8:t<eI?9:10},nI={encode:qS,decode:HS,encodingLength:tI},Yb=nI;const Xb=(t,e,n=0)=>(Yb.encode(t,e,n),e),Jb=t=>Yb.encodingLength(t),dh=(t,e)=>{const n=e.byteLength,r=Jb(t),i=r+Jb(n),s=new Uint8Array(i+n);return Xb(t,s,0),Xb(n,s,r),s.set(e,i),new rI(t,n,e,s)};class rI{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const Qb=({name:t,code:e,encode:n})=>new iI(t,e,n);class iI{constructor(e,n,r){this.name=e,this.code=n,this.encode=r}digest(e){if(e instanceof Uint8Array){const n=this.encode(e);return n instanceof Uint8Array?dh(this.code,n):n.then(r=>dh(this.code,r))}else throw Error("Unknown type, must be binary type")}}const ey=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),sI=Qb({name:"sha2-256",code:18,encode:ey("SHA-256")}),oI=Qb({name:"sha2-512",code:19,encode:ey("SHA-512")});var aI=Object.freeze({__proto__:null,sha256:sI,sha512:oI});const ty=0,cI="identity",ny=Hb;var fI=Object.freeze({__proto__:null,identity:{code:ty,name:cI,encode:ny,digest:t=>dh(ty,ny(t))}});new TextEncoder,new TextDecoder;const ry={...rS,...sS,...aS,...fS,...hS,...xS,...IS,...AS,...TS,...kS};({...aI,...fI});function iy(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const sy=iy("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ph=iy("ascii","a",t=>{let e="a";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e},t=>{t=t.substring(1);const e=zb(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),oy={utf8:sy,"utf-8":sy,hex:ry.base16,latin1:ph,ascii:ph,binary:ph,...ry};function pn(t,e="utf8"){const n=oy[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?lh(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}function zt(t,e="utf8"){const n=oy[e];if(!n)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"):n.encoder.encode(t).substring(1)}const uI={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"}},lI="Input must be an string, Buffer or Uint8Array";function hI(t){let e;if(t instanceof Uint8Array)e=t;else if(typeof t=="string")e=new TextEncoder().encode(t);else throw new Error(lI);return e}function dI(t){return Array.prototype.map.call(t,function(e){return(e<16?"0":"")+e.toString(16)}).join("")}function Jc(t){return(4294967296+t).toString(16).substring(1)}function pI(t,e,n){let r=`
17
+ `+t+" = ";for(let i=0;i<e.length;i+=2){if(n===32)r+=Jc(e[i]).toUpperCase(),r+=" ",r+=Jc(e[i+1]).toUpperCase();else if(n===64)r+=Jc(e[i+1]).toUpperCase(),r+=Jc(e[i]).toUpperCase();else throw new Error("Invalid size "+n);i%6===4?r+=`
18
+ `+new Array(t.length+4).join(" "):i<e.length-2&&(r+=" ")}console.log(r)}function gI(t,e,n){let r=new Date().getTime();const i=new Uint8Array(e);for(let o=0;o<e;o++)i[o]=o%256;const s=new Date().getTime();console.log("Generated random input in "+(s-r)+"ms"),r=s;for(let o=0;o<n;o++){const a=t(i),c=new Date().getTime(),f=c-r;r=c,console.log("Hashed in "+f+"ms: "+a.substring(0,20)+"..."),console.log(Math.round(e/(1<<20)/(f/1e3)*100)/100+" MB PER SECOND")}}var ay={normalizeInput:hI,toHex:dI,debugPrint:pI,testSpeed:gI};const Qc=ay;function ef(t,e,n){const r=t[e]+t[n];let i=t[e+1]+t[n+1];r>=4294967296&&i++,t[e]=r,t[e+1]=i}function cy(t,e,n,r){let i=t[e]+n;n<0&&(i+=4294967296);let s=t[e+1]+r;i>=4294967296&&s++,t[e]=i,t[e+1]=s}function fy(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function ti(t,e,n,r,i,s){const o=aa[i],a=aa[i+1],c=aa[s],f=aa[s+1];ef(ae,t,e),cy(ae,t,o,a);let l=ae[r]^ae[t],h=ae[r+1]^ae[t+1];ae[r]=h,ae[r+1]=l,ef(ae,n,r),l=ae[e]^ae[n],h=ae[e+1]^ae[n+1],ae[e]=l>>>24^h<<8,ae[e+1]=h>>>24^l<<8,ef(ae,t,e),cy(ae,t,c,f),l=ae[r]^ae[t],h=ae[r+1]^ae[t+1],ae[r]=l>>>16^h<<16,ae[r+1]=h>>>16^l<<16,ef(ae,n,r),l=ae[e]^ae[n],h=ae[e+1]^ae[n+1],ae[e]=h>>>31^l<<1,ae[e+1]=l>>>31^h<<1}const uy=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),bI=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3],lt=new Uint8Array(bI.map(function(t){return t*2})),ae=new Uint32Array(32),aa=new Uint32Array(32);function ly(t,e){let n=0;for(n=0;n<16;n++)ae[n]=t.h[n],ae[n+16]=uy[n];for(ae[24]=ae[24]^t.t,ae[25]=ae[25]^t.t/4294967296,e&&(ae[28]=~ae[28],ae[29]=~ae[29]),n=0;n<32;n++)aa[n]=fy(t.b,4*n);for(n=0;n<12;n++)ti(0,8,16,24,lt[n*16+0],lt[n*16+1]),ti(2,10,18,26,lt[n*16+2],lt[n*16+3]),ti(4,12,20,28,lt[n*16+4],lt[n*16+5]),ti(6,14,22,30,lt[n*16+6],lt[n*16+7]),ti(0,10,20,30,lt[n*16+8],lt[n*16+9]),ti(2,12,22,24,lt[n*16+10],lt[n*16+11]),ti(4,14,16,26,lt[n*16+12],lt[n*16+13]),ti(6,8,18,28,lt[n*16+14],lt[n*16+15]);for(n=0;n<16;n++)t.h[n]=t.h[n]^ae[n]^ae[n+16]}const ni=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]);function hy(t,e,n,r){if(t===0||t>64)throw new Error("Illegal output length, expected 0 < length <= 64");if(e&&e.length>64)throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");if(n&&n.length!==16)throw new Error("Illegal salt, expected Uint8Array with length is 16");if(r&&r.length!==16)throw new Error("Illegal personal, expected Uint8Array with length is 16");const i={b:new Uint8Array(128),h:new Uint32Array(16),t:0,c:0,outlen:t};ni.fill(0),ni[0]=t,e&&(ni[1]=e.length),ni[2]=1,ni[3]=1,n&&ni.set(n,32),r&&ni.set(r,48);for(let s=0;s<16;s++)i.h[s]=uy[s]^fy(ni,s*4);return e&&(gh(i,e),i.c=128),i}function gh(t,e){for(let n=0;n<e.length;n++)t.c===128&&(t.t+=t.c,ly(t,!1),t.c=0),t.b[t.c++]=e[n]}function dy(t){for(t.t+=t.c;t.c<128;)t.b[t.c++]=0;ly(t,!0);const e=new Uint8Array(t.outlen);for(let n=0;n<t.outlen;n++)e[n]=t.h[n>>2]>>8*(n&3);return e}function py(t,e,n,r,i){n=n||64,t=Qc.normalizeInput(t),r&&(r=Qc.normalizeInput(r)),i&&(i=Qc.normalizeInput(i));const s=hy(n,e,r,i);return gh(s,t),dy(s)}function yI(t,e,n,r,i){const s=py(t,e,n,r,i);return Qc.toHex(s)}var wI={blake2b:py,blake2bHex:yI,blake2bInit:hy,blake2bUpdate:gh,blake2bFinal:dy};const gy=ay;function mI(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function ri(t,e,n,r,i,s){de[t]=de[t]+de[e]+i,de[r]=tf(de[r]^de[t],16),de[n]=de[n]+de[r],de[e]=tf(de[e]^de[n],12),de[t]=de[t]+de[e]+s,de[r]=tf(de[r]^de[t],8),de[n]=de[n]+de[r],de[e]=tf(de[e]^de[n],7)}function tf(t,e){return t>>>e^t<<32-e}const by=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ht=new Uint8Array([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0]),de=new Uint32Array(16),Qe=new Uint32Array(16);function yy(t,e){let n=0;for(n=0;n<8;n++)de[n]=t.h[n],de[n+8]=by[n];for(de[12]^=t.t,de[13]^=t.t/4294967296,e&&(de[14]=~de[14]),n=0;n<16;n++)Qe[n]=mI(t.b,4*n);for(n=0;n<10;n++)ri(0,4,8,12,Qe[ht[n*16+0]],Qe[ht[n*16+1]]),ri(1,5,9,13,Qe[ht[n*16+2]],Qe[ht[n*16+3]]),ri(2,6,10,14,Qe[ht[n*16+4]],Qe[ht[n*16+5]]),ri(3,7,11,15,Qe[ht[n*16+6]],Qe[ht[n*16+7]]),ri(0,5,10,15,Qe[ht[n*16+8]],Qe[ht[n*16+9]]),ri(1,6,11,12,Qe[ht[n*16+10]],Qe[ht[n*16+11]]),ri(2,7,8,13,Qe[ht[n*16+12]],Qe[ht[n*16+13]]),ri(3,4,9,14,Qe[ht[n*16+14]],Qe[ht[n*16+15]]);for(n=0;n<8;n++)t.h[n]^=de[n]^de[n+8]}function wy(t,e){if(!(t>0&&t<=32))throw new Error("Incorrect output length, should be in [1, 32]");const n=e?e.length:0;if(e&&!(n>0&&n<=32))throw new Error("Incorrect key length, should be in [1, 32]");const r={h:new Uint32Array(by),b:new Uint8Array(64),c:0,t:0,outlen:t};return r.h[0]^=16842752^n<<8^t,n>0&&(bh(r,e),r.c=64),r}function bh(t,e){for(let n=0;n<e.length;n++)t.c===64&&(t.t+=t.c,yy(t,!1),t.c=0),t.b[t.c++]=e[n]}function my(t){for(t.t+=t.c;t.c<64;)t.b[t.c++]=0;yy(t,!0);const e=new Uint8Array(t.outlen);for(let n=0;n<t.outlen;n++)e[n]=t.h[n>>2]>>8*(n&3)&255;return e}function vy(t,e,n){n=n||32,t=gy.normalizeInput(t);const r=wy(n,e);return bh(r,t),my(r)}function vI(t,e,n){const r=vy(t,e,n);return gy.toHex(r)}var EI={blake2s:vy,blake2sHex:vI,blake2sInit:wy,blake2sUpdate:bh,blake2sFinal:my};const ca=wI,fa=EI;var xI={blake2b:ca.blake2b,blake2bHex:ca.blake2bHex,blake2bInit:ca.blake2bInit,blake2bUpdate:ca.blake2bUpdate,blake2bFinal:ca.blake2bFinal,blake2s:fa.blake2s,blake2sHex:fa.blake2sHex,blake2sInit:fa.blake2sInit,blake2sUpdate:fa.blake2sUpdate,blake2sFinal:fa.blake2sFinal};const _I="ReactNative";function Ey(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function yh(){return!nr()&&!!Co()&&navigator.product===_I}function SI(){return yh()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function II(){return yh()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function BI(){return!Ey()&&!!Co()&&!!nr()}function $I(){var t;try{return yh()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(t=global.Application)==null?void 0:t.applicationId:void 0}catch{return}}const nf=BigInt(2**32-1),xy=BigInt(32);function _y(t,e=!1){return e?{h:Number(t&nf),l:Number(t>>xy&nf)}:{h:Number(t>>xy&nf)|0,l:Number(t&nf)|0}}function Sy(t,e=!1){const n=t.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:a}=_y(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const Iy=(t,e,n)=>t>>>n,By=(t,e,n)=>t<<32-n|e>>>n,ii=(t,e,n)=>t>>>n|e<<32-n,si=(t,e,n)=>t<<32-n|e>>>n,ua=(t,e,n)=>t<<64-n|e>>>n-32,la=(t,e,n)=>t>>>n-32|e<<64-n,AI=(t,e)=>e,OI=(t,e)=>t,DI=(t,e,n)=>t<<n|e>>>32-n,PI=(t,e,n)=>e<<n|t>>>32-n,RI=(t,e,n)=>e<<n-32|t>>>64-n,TI=(t,e,n)=>t<<n-32|e>>>64-n;function Bn(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const wh=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),mh=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,NI=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),UI=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,CI=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),LI=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,no=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function rf(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function oi(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function $n(t,...e){if(!rf(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 $y(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");oi(t.outputLen),oi(t.blockLen)}function ai(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 vh(t,e){$n(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function ha(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function An(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Eh(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Hn(t,e){return t<<32-e|t>>>e}const Ay=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Oy(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}const gr=Ay?t=>t:t=>Oy(t);function FI(t){for(let e=0;e<t.length;e++)t[e]=Oy(t[e]);return t}const ci=Ay?t=>t:FI,Dy=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",kI=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ro(t){if($n(t),Dy)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=kI[t[n]];return e}const br={_0:48,_9:57,A:65,F:70,a:97,f:102};function Py(t){if(t>=br._0&&t<=br._9)return t-br._0;if(t>=br.A&&t<=br.F)return t-(br.A-10);if(t>=br.a&&t<=br.f)return t-(br.a-10)}function sf(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Dy)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=Py(t.charCodeAt(s)),a=Py(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)}r[i]=o*16+a}return r}function Ry(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function yr(t){return typeof t=="string"&&(t=Ry(t)),$n(t),t}function fi(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];$n(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}class of{}function da(t){const e=r=>t().update(yr(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function qI(t){const e=(r,i)=>t(i).update(yr(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function xh(t=32){if(no&&typeof no.getRandomValues=="function")return no.getRandomValues(new Uint8Array(t));if(no&&typeof no.randomBytes=="function")return Uint8Array.from(no.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const jI=BigInt(0),pa=BigInt(1),MI=BigInt(2),zI=BigInt(7),HI=BigInt(256),VI=BigInt(113),Ty=[],Ny=[],Uy=[];for(let t=0,e=pa,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],Ty.push(2*(5*r+n)),Ny.push((t+1)*(t+2)/2%64);let i=jI;for(let s=0;s<7;s++)e=(e<<pa^(e>>zI)*VI)%HI,e&MI&&(i^=pa<<(pa<<BigInt(s))-pa);Uy.push(i)}const Cy=Sy(Uy,!0),KI=Cy[0],GI=Cy[1],Ly=(t,e,n)=>n>32?RI(t,e,n):DI(t,e,n),Fy=(t,e,n)=>n>32?TI(t,e,n):PI(t,e,n);function ZI(t,e=24){const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let o=0;o<10;o++)n[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=n[c],l=n[c+1],h=Ly(f,l,1)^n[a],d=Fy(f,l,1)^n[a+1];for(let u=0;u<50;u+=10)t[o+u]^=h,t[o+u+1]^=d}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=Ny[o],c=Ly(i,s,a),f=Fy(i,s,a),l=Ty[o];i=t[l],s=t[l+1],t[l]=c,t[l+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)n[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~n[(a+2)%10]&n[(a+4)%10]}t[0]^=KI[r],t[1]^=GI[r]}An(n)}class _h extends of{constructor(e,n,r,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=s,oi(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=ha(this.state)}clone(){return this._cloneInto()}keccak(){ci(this.state32),ZI(this.state32,this.rounds),ci(this.state32),this.posOut=0,this.pos=0}update(e){ai(this),e=yr(e),$n(e);const{blockLen:n,state:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(n-this.pos,i-s);for(let a=0;a<o;a++)r[this.pos++]^=e[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:n,pos:r,blockLen:i}=this;e[r]^=n,(n&128)!==0&&r===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){ai(this,!1),$n(e),this.finish();const n=this.state,{blockLen:r}=this;for(let i=0,s=e.length;i<s;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,s-i);e.set(n.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 oi(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(vh(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,An(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new _h(n,r,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=r,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}}((t,e,n)=>da(()=>new _h(e,t,n)))(1,136,256/8);function WI(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,f=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+f,a,r)}function YI(t,e,n){return t&e^~t&n}function XI(t,e,n){return t&e^t&n^e&n}class ky extends of{constructor(e,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=Eh(this.buffer)}update(e){ai(this),e=yr(e),$n(e);const{view:n,buffer:r,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Eh(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){ai(this),vh(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,An(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;WI(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Eh(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const ui=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),dt=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),pt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),JI=Uint32Array.from([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]),li=new Uint32Array(64);class QI extends ky{constructor(e=32){super(64,e,8,!1),this.A=ui[0]|0,this.B=ui[1]|0,this.C=ui[2]|0,this.D=ui[3]|0,this.E=ui[4]|0,this.F=ui[5]|0,this.G=ui[6]|0,this.H=ui[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[e,n,r,i,s,o,a,c]}set(e,n,r,i,s,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let h=0;h<16;h++,n+=4)li[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const d=li[h-15],u=li[h-2],b=Hn(d,7)^Hn(d,18)^d>>>3,w=Hn(u,17)^Hn(u,19)^u>>>10;li[h]=w+li[h-7]+b+li[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const d=Hn(a,6)^Hn(a,11)^Hn(a,25),u=l+d+YI(a,c,f)+JI[h]+li[h]|0,b=(Hn(r,2)^Hn(r,13)^Hn(r,22))+XI(r,i,s)|0;l=f,f=c,c=a,a=o+u|0,o=s,s=i,i=r,r=u+b|0}r=r+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,f=f+this.G|0,l=l+this.H|0,this.set(r,i,s,o,a,c,f,l)}roundClean(){An(li)}destroy(){this.set(0,0,0,0,0,0,0,0),An(this.buffer)}}const qy=Sy(["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))),eB=qy[0],tB=qy[1],hi=new Uint32Array(80),di=new Uint32Array(80);class Sh extends ky{constructor(e=64){super(128,e,16,!1),this.Ah=pt[0]|0,this.Al=pt[1]|0,this.Bh=pt[2]|0,this.Bl=pt[3]|0,this.Ch=pt[4]|0,this.Cl=pt[5]|0,this.Dh=pt[6]|0,this.Dl=pt[7]|0,this.Eh=pt[8]|0,this.El=pt[9]|0,this.Fh=pt[10]|0,this.Fl=pt[11]|0,this.Gh=pt[12]|0,this.Gl=pt[13]|0,this.Hh=pt[14]|0,this.Hl=pt[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:h,Fl:d,Gh:u,Gl:b,Hh:w,Hl:E}=this;return[e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E]}set(e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=h|0,this.Fl=d|0,this.Gh=u|0,this.Gl=b|0,this.Hh=w|0,this.Hl=E|0}process(e,n){for(let _=0;_<16;_++,n+=4)hi[_]=e.getUint32(n),di[_]=e.getUint32(n+=4);for(let _=16;_<80;_++){const x=hi[_-15]|0,D=di[_-15]|0,U=ii(x,D,1)^ii(x,D,8)^Iy(x,D,7),C=si(x,D,1)^si(x,D,8)^By(x,D,7),L=hi[_-2]|0,O=di[_-2]|0,M=ii(L,O,19)^ua(L,O,61)^Iy(L,O,6),q=si(L,O,19)^la(L,O,61)^By(L,O,6),y=NI(C,q,di[_-7],di[_-16]),p=UI(y,U,M,hi[_-7],hi[_-16]);hi[_]=p|0,di[_]=y|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:h,El:d,Fh:u,Fl:b,Gh:w,Gl:E,Hh:A,Hl:P}=this;for(let _=0;_<80;_++){const x=ii(h,d,14)^ii(h,d,18)^ua(h,d,41),D=si(h,d,14)^si(h,d,18)^la(h,d,41),U=h&u^~h&w,C=d&b^~d&E,L=CI(P,D,C,tB[_],di[_]),O=LI(L,A,x,U,eB[_],hi[_]),M=L|0,q=ii(r,i,28)^ua(r,i,34)^ua(r,i,39),y=si(r,i,28)^la(r,i,34)^la(r,i,39),p=r&s^r&a^s&a,m=i&o^i&c^o&c;A=w|0,P=E|0,w=u|0,E=b|0,u=h|0,b=d|0,{h,l:d}=Bn(f|0,l|0,O|0,M|0),f=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=wh(M,y,m);r=mh(g,O,q,p),i=g|0}({h:r,l:i}=Bn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=Bn(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=Bn(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=Bn(this.Dh|0,this.Dl|0,f|0,l|0),{h,l:d}=Bn(this.Eh|0,this.El|0,h|0,d|0),{h:u,l:b}=Bn(this.Fh|0,this.Fl|0,u|0,b|0),{h:w,l:E}=Bn(this.Gh|0,this.Gl|0,w|0,E|0),{h:A,l:P}=Bn(this.Hh|0,this.Hl|0,A|0,P|0),this.set(r,i,s,o,a,c,f,l,h,d,u,b,w,E,A,P)}roundClean(){An(hi,di)}destroy(){An(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class nB extends Sh{constructor(){super(48),this.Ah=dt[0]|0,this.Al=dt[1]|0,this.Bh=dt[2]|0,this.Bl=dt[3]|0,this.Ch=dt[4]|0,this.Cl=dt[5]|0,this.Dh=dt[6]|0,this.Dl=dt[7]|0,this.Eh=dt[8]|0,this.El=dt[9]|0,this.Fh=dt[10]|0,this.Fl=dt[11]|0,this.Gh=dt[12]|0,this.Gl=dt[13]|0,this.Hh=dt[14]|0,this.Hl=dt[15]|0}}const gt=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class rB extends Sh{constructor(){super(32),this.Ah=gt[0]|0,this.Al=gt[1]|0,this.Bh=gt[2]|0,this.Bl=gt[3]|0,this.Ch=gt[4]|0,this.Cl=gt[5]|0,this.Dh=gt[6]|0,this.Dl=gt[7]|0,this.Eh=gt[8]|0,this.El=gt[9]|0,this.Fh=gt[10]|0,this.Fl=gt[11]|0,this.Gh=gt[12]|0,this.Gl=gt[13]|0,this.Hh=gt[14]|0,this.Hl=gt[15]|0}}const iB=da(()=>new QI),sB=da(()=>new Sh),oB=da(()=>new nB);da(()=>new rB);const aB=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]),ke=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),J=new Uint32Array(32);function pi(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=J[2*t],f=J[2*t+1],l=J[2*e],h=J[2*e+1],d=J[2*n],u=J[2*n+1],b=J[2*r],w=J[2*r+1],E=wh(c,l,o);f=mh(E,f,h,a),c=E|0,{Dh:w,Dl:b}={Dh:w^f,Dl:b^c},{Dh:w,Dl:b}={Dh:AI(w,b),Dl:OI(w)},{h:u,l:d}=Bn(u,d,w,b),{Bh:h,Bl:l}={Bh:h^u,Bl:l^d},{Bh:h,Bl:l}={Bh:ii(h,l,24),Bl:si(h,l,24)},J[2*t]=c,J[2*t+1]=f,J[2*e]=l,J[2*e+1]=h,J[2*n]=d,J[2*n+1]=u,J[2*r]=b,J[2*r+1]=w}function gi(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=J[2*t],f=J[2*t+1],l=J[2*e],h=J[2*e+1],d=J[2*n],u=J[2*n+1],b=J[2*r],w=J[2*r+1],E=wh(c,l,o);f=mh(E,f,h,a),c=E|0,{Dh:w,Dl:b}={Dh:w^f,Dl:b^c},{Dh:w,Dl:b}={Dh:ii(w,b,16),Dl:si(w,b,16)},{h:u,l:d}=Bn(u,d,w,b),{Bh:h,Bl:l}={Bh:h^u,Bl:l^d},{Bh:h,Bl:l}={Bh:ua(h,l,63),Bl:la(h,l,63)},J[2*t]=c,J[2*t+1]=f,J[2*e]=l,J[2*e+1]=h,J[2*n]=d,J[2*n+1]=u,J[2*r]=b,J[2*r+1]=w}function cB(t,e={},n,r,i){if(oi(n),t<0||t>n)throw new Error("outputLen bigger than keyLen");const{key:s,salt:o,personalization:a}=e;if(s!==void 0&&(s.length<1||s.length>n))throw new Error("key length must be undefined or 1.."+n);if(o!==void 0&&o.length!==r)throw new Error("salt must be undefined or "+r);if(a!==void 0&&a.length!==i)throw new Error("personalization must be undefined or "+i)}class fB extends of{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,oi(e),oi(n),this.blockLen=e,this.outputLen=n,this.buffer=new Uint8Array(e),this.buffer32=ha(this.buffer)}update(e){ai(this),e=yr(e),$n(e);const{blockLen:n,buffer:r,buffer32:i}=this,s=e.length,o=e.byteOffset,a=e.buffer;for(let c=0;c<s;){this.pos===n&&(ci(i),this.compress(i,0,!1),ci(i),this.pos=0);const f=Math.min(n-this.pos,s-c),l=o+c;if(f===n&&!(l%4)&&c+f<s){const h=new Uint32Array(a,l,Math.floor((s-c)/4));ci(h);for(let d=0;c+n<s;d+=i.length,c+=n)this.length+=n,this.compress(h,d,!1);ci(h);continue}r.set(e.subarray(c,c+f),this.pos),this.pos+=f,this.length+=f,c+=f}return this}digestInto(e){ai(this),vh(e,this);const{pos:n,buffer32:r}=this;this.finished=!0,An(this.buffer.subarray(n)),ci(r),this.compress(r,0,!0),ci(r);const i=ha(e);this.get().forEach((s,o)=>i[o]=gr(s))}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){const{buffer:n,length:r,finished:i,destroyed:s,outputLen:o,pos:a}=this;return e||(e=new this.constructor({dkLen:o})),e.set(...this.get()),e.buffer.set(n),e.destroyed=s,e.finished=i,e.length=r,e.pos=a,e.outputLen=o,e}clone(){return this._cloneInto()}}class uB extends fB{constructor(e={}){const n=e.dkLen===void 0?64:e.dkLen;super(128,n),this.v0l=ke[0]|0,this.v0h=ke[1]|0,this.v1l=ke[2]|0,this.v1h=ke[3]|0,this.v2l=ke[4]|0,this.v2h=ke[5]|0,this.v3l=ke[6]|0,this.v3h=ke[7]|0,this.v4l=ke[8]|0,this.v4h=ke[9]|0,this.v5l=ke[10]|0,this.v5h=ke[11]|0,this.v6l=ke[12]|0,this.v6h=ke[13]|0,this.v7l=ke[14]|0,this.v7h=ke[15]|0,cB(n,e,64,16,16);let{key:r,personalization:i,salt:s}=e,o=0;if(r!==void 0&&(r=yr(r),o=r.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=yr(s);const a=ha(s);this.v4l^=gr(a[0]),this.v4h^=gr(a[1]),this.v5l^=gr(a[2]),this.v5h^=gr(a[3])}if(i!==void 0){i=yr(i);const a=ha(i);this.v6l^=gr(a[0]),this.v6h^=gr(a[1]),this.v7l^=gr(a[2]),this.v7h^=gr(a[3])}if(r!==void 0){const a=new Uint8Array(this.blockLen);a.set(r),this.update(a)}}get(){let{v0l:e,v0h:n,v1l:r,v1h:i,v2l:s,v2h:o,v3l:a,v3h:c,v4l:f,v4h:l,v5l:h,v5h:d,v6l:u,v6h:b,v7l:w,v7h:E}=this;return[e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E]}set(e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E){this.v0l=e|0,this.v0h=n|0,this.v1l=r|0,this.v1h=i|0,this.v2l=s|0,this.v2h=o|0,this.v3l=a|0,this.v3h=c|0,this.v4l=f|0,this.v4h=l|0,this.v5l=h|0,this.v5h=d|0,this.v6l=u|0,this.v6h=b|0,this.v7l=w|0,this.v7h=E|0}compress(e,n,r){this.get().forEach((c,f)=>J[f]=c),J.set(ke,16);let{h:i,l:s}=_y(BigInt(this.length));J[24]=ke[8]^s,J[25]=ke[9]^i,r&&(J[28]=~J[28],J[29]=~J[29]);let o=0;const a=aB;for(let c=0;c<12;c++)pi(0,4,8,12,e,n+2*a[o++]),gi(0,4,8,12,e,n+2*a[o++]),pi(1,5,9,13,e,n+2*a[o++]),gi(1,5,9,13,e,n+2*a[o++]),pi(2,6,10,14,e,n+2*a[o++]),gi(2,6,10,14,e,n+2*a[o++]),pi(3,7,11,15,e,n+2*a[o++]),gi(3,7,11,15,e,n+2*a[o++]),pi(0,5,10,15,e,n+2*a[o++]),gi(0,5,10,15,e,n+2*a[o++]),pi(1,6,11,12,e,n+2*a[o++]),gi(1,6,11,12,e,n+2*a[o++]),pi(2,7,8,13,e,n+2*a[o++]),gi(2,7,8,13,e,n+2*a[o++]),pi(3,4,9,14,e,n+2*a[o++]),gi(3,4,9,14,e,n+2*a[o++]);this.v0l^=J[0]^J[16],this.v0h^=J[1]^J[17],this.v1l^=J[2]^J[18],this.v1h^=J[3]^J[19],this.v2l^=J[4]^J[20],this.v2h^=J[5]^J[21],this.v3l^=J[6]^J[22],this.v3h^=J[7]^J[23],this.v4l^=J[8]^J[24],this.v4h^=J[9]^J[25],this.v5l^=J[10]^J[26],this.v5h^=J[11]^J[27],this.v6l^=J[12]^J[28],this.v6h^=J[13]^J[29],this.v7l^=J[14]^J[30],this.v7h^=J[15]^J[31],An(J)}destroy(){this.destroyed=!0,An(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}qI(t=>new uB(t));/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function jy(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ih(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function Bh(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Ht(t,...e){if(!jy(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 My(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 lB(t,e){Ht(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function bi(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function io(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function hB(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const dB=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function pB(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function $h(t){if(typeof t=="string")t=pB(t);else if(jy(t))t=Ah(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function gB(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function bB(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}const yB=(t,e)=>{function n(r,...i){if(Ht(r),!dB)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){const f=i[0];if(!f)throw new Error("nonce / iv required");t.varSizeNonce?Ht(f):Ht(f,t.nonceLength)}const s=t.tagLength;s&&i[1]!==void 0&&Ht(i[1]);const o=e(r,...i),a=(f,l)=>{if(l!==void 0){if(f!==2)throw new Error("cipher output not supported");Ht(l)}};let c=!1;return{encrypt(f,l){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Ht(f),a(o.encrypt.length,l),o.encrypt(f,l)},decrypt(f,l){if(Ht(f),s&&f.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return a(o.decrypt.length,l),o.decrypt(f,l)}}}return Object.assign(n,t),n};function zy(t,e,n=!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(n&&!mB(e))throw new Error("invalid output, must be aligned");return e}function Hy(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,f=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+f,a,r)}function wB(t,e,n){Ih(n);const r=new Uint8Array(16),i=hB(r);return Hy(i,0,BigInt(e),n),Hy(i,8,BigInt(t),n),r}function mB(t){return t.byteOffset%4===0}function Ah(t){return Uint8Array.from(t)}const Vy=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),vB=Vy("expand 16-byte k"),EB=Vy("expand 32-byte k"),xB=bi(vB),_B=bi(EB);function pe(t,e){return t<<e|t>>>32-e}function Oh(t){return t.byteOffset%4===0}const af=64,SB=16,Ky=2**32-1,Gy=new Uint32Array;function IB(t,e,n,r,i,s,o,a){const c=i.length,f=new Uint8Array(af),l=bi(f),h=Oh(i)&&Oh(s),d=h?bi(i):Gy,u=h?bi(s):Gy;for(let b=0;b<c;o++){if(t(e,n,r,l,o,a),o>=Ky)throw new Error("arx: counter overflow");const w=Math.min(af,c-b);if(h&&w===af){const E=b/4;if(b%4!==0)throw new Error("arx: invalid block position");for(let A=0,P;A<SB;A++)P=E+A,u[P]=d[P]^l[A];b+=af;continue}for(let E=0,A;E<w;E++)A=b+E,s[A]=i[A]^f[E];b+=w}}function BB(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=gB({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Bh(i),Bh(o),Ih(s),Ih(n),(a,c,f,l,h=0)=>{Ht(a),Ht(c),Ht(f);const d=f.length;if(l===void 0&&(l=new Uint8Array(d)),Ht(l),Bh(h),h<0||h>=Ky)throw new Error("arx: counter overflow");if(l.length<d)throw new Error(`arx: output (${l.length}) is shorter than data (${d})`);const u=[];let b=a.length,w,E;if(b===32)u.push(w=Ah(a)),E=_B;else if(b===16&&n)w=new Uint8Array(32),w.set(a),w.set(a,16),E=xB,u.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${b}`);Oh(c)||u.push(c=Ah(c));const A=bi(w);if(r){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(E,A,bi(c.subarray(0,16)),A),c=c.subarray(16)}const P=16-i;if(P!==c.length)throw new Error(`arx: nonce must be ${P} or 16 bytes`);if(P!==12){const x=new Uint8Array(12);x.set(c,s?0:12-c.length),c=x,u.push(c)}const _=bi(c);return IB(t,E,A,_,f,l,h,o),io(...u),l}}const et=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class $B{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=$h(e),Ht(e,32);const n=et(e,0),r=et(e,2),i=et(e,4),s=et(e,6),o=et(e,8),a=et(e,10),c=et(e,12),f=et(e,14);this.r[0]=n&8191,this.r[1]=(n>>>13|r<<3)&8191,this.r[2]=(r>>>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|f<<8)&8191,this.r[9]=f>>>5&127;for(let l=0;l<8;l++)this.pad[l]=et(e,16+2*l)}process(e,n,r=!1){const i=r?0:2048,{h:s,r:o}=this,a=o[0],c=o[1],f=o[2],l=o[3],h=o[4],d=o[5],u=o[6],b=o[7],w=o[8],E=o[9],A=et(e,n+0),P=et(e,n+2),_=et(e,n+4),x=et(e,n+6),D=et(e,n+8),U=et(e,n+10),C=et(e,n+12),L=et(e,n+14);let O=s[0]+(A&8191),M=s[1]+((A>>>13|P<<3)&8191),q=s[2]+((P>>>10|_<<6)&8191),y=s[3]+((_>>>7|x<<9)&8191),p=s[4]+((x>>>4|D<<12)&8191),m=s[5]+(D>>>1&8191),g=s[6]+((D>>>14|U<<2)&8191),v=s[7]+((U>>>11|C<<5)&8191),S=s[8]+((C>>>8|L<<8)&8191),B=s[9]+(L>>>5|i),I=0,$=I+O*a+M*(5*E)+q*(5*w)+y*(5*b)+p*(5*u);I=$>>>13,$&=8191,$+=m*(5*d)+g*(5*h)+v*(5*l)+S*(5*f)+B*(5*c),I+=$>>>13,$&=8191;let T=I+O*c+M*a+q*(5*E)+y*(5*w)+p*(5*b);I=T>>>13,T&=8191,T+=m*(5*u)+g*(5*d)+v*(5*h)+S*(5*l)+B*(5*f),I+=T>>>13,T&=8191;let F=I+O*f+M*c+q*a+y*(5*E)+p*(5*w);I=F>>>13,F&=8191,F+=m*(5*b)+g*(5*u)+v*(5*d)+S*(5*h)+B*(5*l),I+=F>>>13,F&=8191;let N=I+O*l+M*f+q*c+y*a+p*(5*E);I=N>>>13,N&=8191,N+=m*(5*w)+g*(5*b)+v*(5*u)+S*(5*d)+B*(5*h),I+=N>>>13,N&=8191;let k=I+O*h+M*l+q*f+y*c+p*a;I=k>>>13,k&=8191,k+=m*(5*E)+g*(5*w)+v*(5*b)+S*(5*u)+B*(5*d),I+=k>>>13,k&=8191;let R=I+O*d+M*h+q*l+y*f+p*c;I=R>>>13,R&=8191,R+=m*a+g*(5*E)+v*(5*w)+S*(5*b)+B*(5*u),I+=R>>>13,R&=8191;let j=I+O*u+M*d+q*h+y*l+p*f;I=j>>>13,j&=8191,j+=m*c+g*a+v*(5*E)+S*(5*w)+B*(5*b),I+=j>>>13,j&=8191;let z=I+O*b+M*u+q*d+y*h+p*l;I=z>>>13,z&=8191,z+=m*f+g*c+v*a+S*(5*E)+B*(5*w),I+=z>>>13,z&=8191;let V=I+O*w+M*b+q*u+y*d+p*h;I=V>>>13,V&=8191,V+=m*l+g*f+v*c+S*a+B*(5*E),I+=V>>>13,V&=8191;let H=I+O*E+M*w+q*b+y*u+p*d;I=H>>>13,H&=8191,H+=m*h+g*l+v*f+S*c+B*a,I+=H>>>13,H&=8191,I=(I<<2)+I|0,I=I+$|0,$=I&8191,I=I>>>13,T+=I,s[0]=$,s[1]=T,s[2]=F,s[3]=N,s[4]=k,s[5]=R,s[6]=j,s[7]=z,s[8]=V,s[9]=H}finalize(){const{h:e,pad:n}=this,r=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,r[0]=e[0]+5,i=r[0]>>>13,r[0]&=8191;for(let a=1;a<10;a++)r[a]=e[a]+i,i=r[a]>>>13,r[a]&=8191;r[9]-=8192;let s=(i^1)-1;for(let a=0;a<10;a++)r[a]&=s;s=~s;for(let a=0;a<10;a++)e[a]=e[a]&s|r[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]+n[0];e[0]=o&65535;for(let a=1;a<8;a++)o=(e[a]+n[a]|0)+(o>>>16)|0,e[a]=o&65535;io(r)}update(e){My(this),e=$h(e),Ht(e);const{buffer:n,blockLen:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);if(o===r){for(;r<=i-s;s+=r)this.process(e,s);continue}n.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===r&&(this.process(n,0,!1),this.pos=0)}return this}destroy(){io(this.h,this.r,this.buffer,this.pad)}digestInto(e){My(this),lB(e,this),this.finished=!0;const{buffer:n,h:r}=this;let{pos:i}=this;if(i){for(n[i++]=1;i<16;i++)n[i]=0;this.process(n,0,!0)}this.finalize();let s=0;for(let o=0;o<8;o++)e[s++]=r[o]>>>0,e[s++]=r[o]>>>8;return e}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}}function AB(t){const e=(r,i)=>t(i).update($h(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}const OB=AB(t=>new $B(t));function DB(t,e,n,r,i,s=20){let o=t[0],a=t[1],c=t[2],f=t[3],l=e[0],h=e[1],d=e[2],u=e[3],b=e[4],w=e[5],E=e[6],A=e[7],P=i,_=n[0],x=n[1],D=n[2],U=o,C=a,L=c,O=f,M=l,q=h,y=d,p=u,m=b,g=w,v=E,S=A,B=P,I=_,$=x,T=D;for(let N=0;N<s;N+=2)U=U+M|0,B=pe(B^U,16),m=m+B|0,M=pe(M^m,12),U=U+M|0,B=pe(B^U,8),m=m+B|0,M=pe(M^m,7),C=C+q|0,I=pe(I^C,16),g=g+I|0,q=pe(q^g,12),C=C+q|0,I=pe(I^C,8),g=g+I|0,q=pe(q^g,7),L=L+y|0,$=pe($^L,16),v=v+$|0,y=pe(y^v,12),L=L+y|0,$=pe($^L,8),v=v+$|0,y=pe(y^v,7),O=O+p|0,T=pe(T^O,16),S=S+T|0,p=pe(p^S,12),O=O+p|0,T=pe(T^O,8),S=S+T|0,p=pe(p^S,7),U=U+q|0,T=pe(T^U,16),v=v+T|0,q=pe(q^v,12),U=U+q|0,T=pe(T^U,8),v=v+T|0,q=pe(q^v,7),C=C+y|0,B=pe(B^C,16),S=S+B|0,y=pe(y^S,12),C=C+y|0,B=pe(B^C,8),S=S+B|0,y=pe(y^S,7),L=L+p|0,I=pe(I^L,16),m=m+I|0,p=pe(p^m,12),L=L+p|0,I=pe(I^L,8),m=m+I|0,p=pe(p^m,7),O=O+M|0,$=pe($^O,16),g=g+$|0,M=pe(M^g,12),O=O+M|0,$=pe($^O,8),g=g+$|0,M=pe(M^g,7);let F=0;r[F++]=o+U|0,r[F++]=a+C|0,r[F++]=c+L|0,r[F++]=f+O|0,r[F++]=l+M|0,r[F++]=h+q|0,r[F++]=d+y|0,r[F++]=u+p|0,r[F++]=b+m|0,r[F++]=w+g|0,r[F++]=E+v|0,r[F++]=A+S|0,r[F++]=P+B|0,r[F++]=_+I|0,r[F++]=x+$|0,r[F++]=D+T|0}const PB=BB(DB,{counterRight:!1,counterLength:4,allowShortKeys:!1}),RB=new Uint8Array(16),Zy=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(RB.subarray(n))},TB=new Uint8Array(32);function Wy(t,e,n,r,i){const s=t(e,n,TB),o=OB.create(s);i&&Zy(o,i),Zy(o,r);const a=wB(r.length,i?i.length:0,!0);o.update(a);const c=o.digest();return io(s,a),c}yB({blockSize:64,nonceLength:12,tagLength:16},(t=>(e,n,r)=>({encrypt(i,s){const o=i.length;s=zy(o+16,s,!1),s.set(i);const a=s.subarray(0,-16);t(e,n,a,a,1);const c=Wy(t,e,n,a,r);return s.set(c,o),io(c),s},decrypt(i,s){s=zy(i.length-16,s,!1);const o=i.subarray(0,-16),a=i.subarray(-16),c=Wy(t,e,n,o,r);if(!bB(a,c))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),t(e,n,s,s,1),io(c),s}}))(PB));class Yy extends of{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,$y(e);const r=yr(n);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(r.length>i?e.create().update(r).digest():r);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),An(s)}update(e){return ai(this),this.iHash.update(e),this}digestInto(e){ai(this),$n(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:n,iHash:r,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=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Xy=(t,e,n)=>new Yy(t,e).update(n).digest();Xy.create=(t,e)=>new Yy(t,e);const Dh=BigInt(0),Ph=BigInt(1);function cf(t,e=""){if(typeof t!="boolean"){const n=e&&`"${e}"`;throw new Error(n+"expected boolean, got type="+typeof t)}return t}function fs(t,e,n=""){const r=rf(t),i=t?.length,s=e!==void 0;if(!r||s&&i!==e){const o=n&&`"${n}" `,a=s?` of length ${e}`:"",c=r?`length=${i}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return t}function ff(t){const e=t.toString(16);return e.length&1?"0"+e:e}function Jy(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Dh:BigInt("0x"+t)}function uf(t){return Jy(ro(t))}function lf(t){return $n(t),Jy(ro(Uint8Array.from(t).reverse()))}function Rh(t,e){return sf(t.toString(16).padStart(e*2,"0"))}function Th(t,e){return Rh(t,e).reverse()}function bt(t,e,n){let r;if(typeof e=="string")try{r=sf(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(rf(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}const Nh=t=>typeof t=="bigint"&&Dh<=t;function NB(t,e,n){return Nh(t)&&Nh(e)&&Nh(n)&&e<=t&&t<n}function Uh(t,e,n,r){if(!NB(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Qy(t){let e;for(e=0;t>Dh;t>>=Ph,e+=1);return e}const ga=t=>(Ph<<BigInt(t))-Ph;function UB(t,e,n){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 n!="function")throw new Error("hmacFn must be a function");const r=d=>new Uint8Array(d),i=d=>Uint8Array.of(d);let s=r(t),o=r(t),a=0;const c=()=>{s.fill(1),o.fill(0),a=0},f=(...d)=>n(o,s,...d),l=(d=r(0))=>{o=f(i(0),d),s=f(),d.length!==0&&(o=f(i(1),d),s=f())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0;const u=[];for(;d<e;){s=f();const b=s.slice();u.push(b),d+=s.length}return fi(...u)};return(d,u)=>{c(),l(d);let b;for(;!(b=u(h()));)l();return c(),b}}function hf(t,e,n={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function r(i,s,o){const a=t[i];if(o&&a===void 0)return;const c=typeof a;if(c!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${c}`)}Object.entries(e).forEach(([i,s])=>r(i,s,!1)),Object.entries(n).forEach(([i,s])=>r(i,s,!0))}function e2(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}const Vt=BigInt(0),Pt=BigInt(1),us=BigInt(2),t2=BigInt(3),n2=BigInt(4),r2=BigInt(5),CB=BigInt(7),i2=BigInt(8),LB=BigInt(9),s2=BigInt(16);function rn(t,e){const n=t%e;return n>=Vt?n:e+n}function On(t,e,n){let r=t;for(;e-- >Vt;)r*=r,r%=n;return r}function o2(t,e){if(t===Vt)throw new Error("invert: expected non-zero number");if(e<=Vt)throw new Error("invert: expected positive modulus, got "+e);let n=rn(t,e),r=e,i=Vt,s=Pt;for(;n!==Vt;){const o=r/n,a=r%n,c=i-s*o;r=n,n=a,i=s,s=c}if(r!==Pt)throw new Error("invert: does not exist");return rn(i,e)}function Ch(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function a2(t,e){const n=(t.ORDER+Pt)/n2,r=t.pow(e,n);return Ch(t,r,e),r}function FB(t,e){const n=(t.ORDER-r2)/i2,r=t.mul(e,us),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,us),i),a=t.mul(s,t.sub(o,t.ONE));return Ch(t,a,e),a}function kB(t){const e=yi(t),n=c2(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+CB)/s2;return(a,c)=>{let f=a.pow(c,o),l=a.mul(f,r);const h=a.mul(f,i),d=a.mul(f,s),u=a.eql(a.sqr(l),c),b=a.eql(a.sqr(h),c);f=a.cmov(f,l,u),l=a.cmov(d,h,b);const w=a.eql(a.sqr(l),c),E=a.cmov(f,l,w);return Ch(a,E,c),E}}function c2(t){if(t<t2)throw new Error("sqrt is not defined for small field");let e=t-Pt,n=0;for(;e%us===Vt;)e/=us,n++;let r=us;const i=yi(t);for(;u2(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return a2;let s=i.pow(r,e);const o=(e+Pt)/us;return function(a,c){if(a.is0(c))return c;if(u2(a,c)!==1)throw new Error("Cannot find square root");let f=n,l=a.mul(a.ONE,s),h=a.pow(c,e),d=a.pow(c,o);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let u=1,b=a.sqr(h);for(;!a.eql(b,a.ONE);)if(u++,b=a.sqr(b),u===f)throw new Error("Cannot find square root");const w=Pt<<BigInt(f-u-1),E=a.pow(l,w);f=u,l=a.sqr(E),h=a.mul(h,l),d=a.mul(d,E)}return d}}function qB(t){return t%n2===t2?a2:t%i2===r2?FB:t%s2===LB?kB(t):c2(t)}const jB=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function MB(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=jB.reduce((r,i)=>(r[i]="function",r),e);return hf(t,n),t}function zB(t,e,n){if(n<Vt)throw new Error("invalid exponent, negatives unsupported");if(n===Vt)return t.ONE;if(n===Pt)return e;let r=t.ONE,i=e;for(;n>Vt;)n&Pt&&(r=t.mul(r,i)),i=t.sqr(i),n>>=Pt;return r}function f2(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),i=e.reduce((o,a,c)=>t.is0(a)?o:(r[c]=o,t.mul(o,a)),t.ONE),s=t.inv(i);return e.reduceRight((o,a,c)=>t.is0(a)?o:(r[c]=t.mul(o,r[c]),t.mul(o,a)),s),r}function u2(t,e){const n=(t.ORDER-Pt)/us,r=t.pow(e,n),i=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),o=t.eql(r,t.neg(t.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function l2(t,e){e!==void 0&&oi(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function yi(t,e,n=!1,r={}){if(t<=Vt)throw new Error("invalid field: expected ORDER > 0, got "+t);let i,s,o=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const d=e;d.BITS&&(i=d.BITS),d.sqrt&&(s=d.sqrt),typeof d.isLE=="boolean"&&(n=d.isLE),typeof d.modFromBytes=="boolean"&&(o=d.modFromBytes),a=d.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:f}=l2(t,i);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const h=Object.freeze({ORDER:t,isLE:n,BITS:c,BYTES:f,MASK:ga(c),ZERO:Vt,ONE:Pt,allowedLengths:a,create:d=>rn(d,t),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return Vt<=d&&d<t},is0:d=>d===Vt,isValidNot0:d=>!h.is0(d)&&h.isValid(d),isOdd:d=>(d&Pt)===Pt,neg:d=>rn(-d,t),eql:(d,u)=>d===u,sqr:d=>rn(d*d,t),add:(d,u)=>rn(d+u,t),sub:(d,u)=>rn(d-u,t),mul:(d,u)=>rn(d*u,t),pow:(d,u)=>zB(h,d,u),div:(d,u)=>rn(d*o2(u,t),t),sqrN:d=>d*d,addN:(d,u)=>d+u,subN:(d,u)=>d-u,mulN:(d,u)=>d*u,inv:d=>o2(d,t),sqrt:s||(d=>(l||(l=qB(t)),l(h,d))),toBytes:d=>n?Th(d,f):Rh(d,f),fromBytes:(d,u=!0)=>{if(a){if(!a.includes(d.length)||d.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);const w=new Uint8Array(f);w.set(d,n?0:w.length-d.length),d=w}if(d.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+d.length);let b=n?lf(d):uf(d);if(o&&(b=rn(b,t)),!u&&!h.isValid(b))throw new Error("invalid field element: outside of range 0..ORDER");return b},invertBatch:d=>f2(h,d),cmov:(d,u,b)=>b?u:d});return Object.freeze(h)}function h2(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 d2(t){const e=h2(t);return e+Math.ceil(e/2)}function HB(t,e,n=!1){const r=t.length,i=h2(e),s=d2(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?lf(t):uf(t),a=rn(o,e-Pt)+Pt;return n?Th(a,i):Rh(a,i)}const so=BigInt(0),ls=BigInt(1);function df(t,e){const n=e.negate();return t?n:e}function Lh(t,e){const n=f2(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function p2(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Fh(t,e){p2(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=ga(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function g2(t,e,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(t&i),c=t>>o;a>r&&(a-=s,c+=ls);const f=e*r,l=f+Math.abs(a)-1,h=a===0,d=a<0,u=e%2!==0;return{nextN:c,offset:l,isZero:h,isNeg:d,isNegF:u,offsetF:f}}function VB(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function KB(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const kh=new WeakMap,b2=new WeakMap;function qh(t){return b2.get(t)||1}function y2(t){if(t!==so)throw new Error("invalid wNAF")}class GB{constructor(e,n){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=n}_unsafeLadder(e,n,r=this.ZERO){let i=e;for(;n>so;)n&ls&&(r=r.add(i)),i=i.double(),n>>=ls;return r}precomputeWindow(e,n){const{windows:r,windowSize:i}=Fh(n,this.bits),s=[];let o=e,a=o;for(let c=0;c<r;c++){a=o,s.push(a);for(let f=1;f<i;f++)a=a.add(o),s.push(a);o=a.double()}return s}wNAF(e,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=Fh(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}=g2(r,a,o);r=c,l?s=s.add(df(d,n[u])):i=i.add(df(h,n[f]))}return y2(r),{p:i,f:s}}wNAFUnsafe(e,n,r,i=this.ZERO){const s=Fh(e,this.bits);for(let o=0;o<s.windows&&r!==so;o++){const{nextN:a,offset:c,isZero:f,isNeg:l}=g2(r,o,s);if(r=a,!f){const h=n[c];i=i.add(l?h.negate():h)}}return y2(r),i}getPrecomputes(e,n,r){let i=kh.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),kh.set(n,i))),i}cached(e,n,r){const i=qh(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=qh(e);return s===1?this._unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,i)}createCache(e,n){p2(n,this.bits),b2.set(e,n),kh.delete(e)}hasCache(e){return qh(e)!==1}}function ZB(t,e,n,r){let i=e,s=t.ZERO,o=t.ZERO;for(;n>so||r>so;)n&ls&&(s=s.add(i)),r&ls&&(o=o.add(i)),i=i.double(),n>>=ls,r>>=ls;return{p1:s,p2:o}}function WB(t,e,n,r){VB(n,t),KB(r,e);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,a=Qy(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=ga(c),l=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let d=o;for(let u=h;u>=0;u-=c){l.fill(o);for(let w=0;w<s;w++){const E=r[w],A=Number(E>>BigInt(u)&f);l[A]=l[A].add(n[w])}let b=o;for(let w=l.length-1,E=o;w>0;w--)E=E.add(l[w]),b=b.add(E);if(d=d.add(b),u!==0)for(let w=0;w<c;w++)d=d.double()}return d}function w2(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return MB(e),e}else return yi(t,{isLE:n})}function YB(t,e,n={},r){if(r===void 0&&(r=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(const a of["p","n","h"]){const c=e[a];if(!(typeof c=="bigint"&&c>so))throw new Error(`CURVE.${a} must be positive bigint`)}const i=w2(e.p,n.Fp,r),s=w2(e.n,n.Fn,r),o=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(const a of o)if(!i.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:s}}BigInt(0),BigInt(1),BigInt(2),BigInt(8),Ry("HashToScalar-");const ba=BigInt(0),oo=BigInt(1),pf=BigInt(2);function XB(t){return hf(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function JB(t){const e=XB(t),{P:n,type:r,adjustScalarBytes:i,powPminus2:s,randomBytes:o}=e,a=r==="x25519";if(!a&&r!=="x448")throw new Error("invalid type");const c=o||xh,f=a?255:448,l=a?32:56,h=BigInt(a?9:5),d=BigInt(a?121665:39081),u=a?pf**BigInt(254):pf**BigInt(447),b=a?BigInt(8)*pf**BigInt(251)-oo:BigInt(4)*pf**BigInt(445)-oo,w=u+b+oo,E=y=>rn(y,n),A=P(h);function P(y){return Th(E(y),l)}function _(y){const p=bt("u coordinate",y,l);return a&&(p[31]&=127),E(lf(p))}function x(y){return lf(i(bt("scalar",y,l)))}function D(y,p){const m=L(_(p),x(y));if(m===ba)throw new Error("invalid private or public key received");return P(m)}function U(y){return D(y,A)}function C(y,p,m){const g=E(y*(p-m));return p=E(p-g),m=E(m+g),{x_2:p,x_3:m}}function L(y,p){Uh("u",y,ba,n),Uh("scalar",p,u,w);const m=p,g=y;let v=oo,S=ba,B=y,I=oo,$=ba;for(let F=BigInt(f-1);F>=ba;F--){const N=m>>F&oo;$^=N,{x_2:v,x_3:B}=C($,v,B),{x_2:S,x_3:I}=C($,S,I),$=N;const k=v+S,R=E(k*k),j=v-S,z=E(j*j),V=R-z,H=B+I,K=B-I,Y=E(K*k),X=E(H*j),ee=Y+X,se=Y-X;B=E(ee*ee),I=E(g*E(se*se)),v=E(R*z),S=E(V*(R+E(d*V)))}({x_2:v,x_3:B}=C($,v,B)),{x_2:S,x_3:I}=C($,S,I);const T=s(S);return E(v*T)}const O={secretKey:l,publicKey:l,seed:l},M=(y=c(l))=>($n(y,O.seed),y);function q(y){const p=M(y);return{secretKey:p,publicKey:U(p)}}return{keygen:q,getSharedSecret:(y,p)=>D(y,p),getPublicKey:y=>U(y),scalarMult:D,scalarMultBase:U,utils:{randomSecretKey:M,randomPrivateKey:M},GuBytes:A.slice(),lengths:O}}const QB=BigInt(1),m2=BigInt(2),e$=BigInt(3),t$=BigInt(5),n$=BigInt(8),v2=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),r$={p:v2,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:n$,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function i$(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=v2,o=t*t%s*t%s,a=On(o,m2,s)*o%s,c=On(a,QB,s)*t%s,f=On(c,t$,s)*c%s,l=On(f,e,s)*f%s,h=On(l,n,s)*l%s,d=On(h,r,s)*h%s,u=On(d,i,s)*d%s,b=On(u,i,s)*d%s,w=On(b,e,s)*f%s;return{pow_p_5_8:On(w,m2,s)*t%s,b2:o}}function s$(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const o$=yi(r$.p,{isLE:!0});(()=>{const t=o$.ORDER;return JB({P:t,type:"x25519",powPminus2:e=>{const{pow_p_5_8:n,b2:r}=i$(e);return rn(On(n,e$,t)*r,t)},adjustScalarBytes:s$})})();const E2=(t,e)=>(t+(t>=0?e:-e)/x2)/e;function a$(t,e,n){const[[r,i],[s,o]]=e,a=E2(o*t,n),c=E2(-i*t,n);let f=t-a*r-c*s,l=-a*i-c*o;const h=f<mr,d=l<mr;h&&(f=-f),d&&(l=-l);const u=ga(Math.ceil(Qy(n)/2))+ao;if(f<mr||f>=u||l<mr||l>=u)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:h,k1:f,k2neg:d,k2:l}}function jh(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function Mh(t,e){const n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return cf(n.lowS,"lowS"),cf(n.prehash,"prehash"),n.format!==void 0&&jh(n.format),n}class c$ extends Error{constructor(e=""){super(e)}}const wr={Err:c$,_tlv:{encode:(t,e)=>{const{Err:n}=wr;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");const r=e.length/2,i=ff(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?ff(i.length/2|128):"";return ff(t)+s+i+e},decode(t,e){const{Err:n}=wr;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const f=e.subarray(r,r+c);if(f.length!==c)throw new n("tlv.decode: length bytes not complete");if(f[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of f)o=o<<8|l;if(r+=c,o<128)throw new n("tlv.decode(long): not minimal encoding")}const a=e.subarray(r,r+o);if(a.length!==o)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(t){const{Err:e}=wr;if(t<mr)throw new e("integer: negative integers are not allowed");let n=ff(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=wr;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 uf(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=wr,i=bt("signature",t),{v:s,l:o}=r.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,s),{v:f,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(f)}},hexFromSig(t){const{_tlv:e,_int:n}=wr,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}},mr=BigInt(0),ao=BigInt(1),x2=BigInt(2),gf=BigInt(3),f$=BigInt(4);function co(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=bt("private key",e);try{r=t.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof e}`)}}if(!t.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function u$(t,e={}){const n=YB("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;hf(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=e;if(c&&(!r.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const f=S2(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(y,p,m){const{x:g,y:v}=p.toAffine(),S=r.toBytes(g);if(cf(m,"isCompressed"),m){l();const B=!r.isOdd(v);return fi(_2(B),S)}else return fi(Uint8Array.of(4),S,r.toBytes(v))}function d(y){fs(y,void 0,"Point");const{publicKey:p,publicKeyUncompressed:m}=f,g=y.length,v=y[0],S=y.subarray(1);if(g===p&&(v===2||v===3)){const B=r.fromBytes(S);if(!r.isValid(B))throw new Error("bad point: is not on curve, wrong x");const I=w(B);let $;try{$=r.sqrt(I)}catch(F){const N=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+N)}l();const T=r.isOdd($);return(v&1)===1!==T&&($=r.neg($)),{x:B,y:$}}else if(g===m&&v===4){const B=r.BYTES,I=r.fromBytes(S.subarray(0,B)),$=r.fromBytes(S.subarray(B,B*2));if(!E(I,$))throw new Error("bad point: is not on curve");return{x:I,y:$}}else throw new Error(`bad point: got length ${g}, expected compressed=${p} or uncompressed=${m}`)}const u=e.toBytes||h,b=e.fromBytes||d;function w(y){const p=r.sqr(y),m=r.mul(p,y);return r.add(r.add(m,r.mul(y,s.a)),s.b)}function E(y,p){const m=r.sqr(p),g=w(y);return r.eql(m,g)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const A=r.mul(r.pow(s.a,gf),f$),P=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(A,P)))throw new Error("bad curve params: a or b");function _(y,p,m=!1){if(!r.isValid(p)||m&&r.is0(p))throw new Error(`bad point coordinate ${y}`);return p}function x(y){if(!(y instanceof O))throw new Error("ProjectivePoint expected")}function D(y){if(!c||!c.basises)throw new Error("no endo");return a$(y,c.basises,i.ORDER)}const U=e2((y,p)=>{const{X:m,Y:g,Z:v}=y;if(r.eql(v,r.ONE))return{x:m,y:g};const S=y.is0();p==null&&(p=S?r.ONE:r.inv(v));const B=r.mul(m,p),I=r.mul(g,p),$=r.mul(v,p);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql($,r.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}),C=e2(y=>{if(y.is0()){if(e.allowInfinityPoint&&!r.is0(y.Y))return;throw new Error("bad point: ZERO")}const{x:p,y:m}=y.toAffine();if(!r.isValid(p)||!r.isValid(m))throw new Error("bad point: x or y not field elements");if(!E(p,m))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function L(y,p,m,g,v){return m=new O(r.mul(m.X,y),m.Y,m.Z),p=df(g,p),m=df(v,m),p.add(m)}class O{constructor(p,m,g){this.X=_("x",p),this.Y=_("y",m,!0),this.Z=_("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){const{x:m,y:g}=p||{};if(!p||!r.isValid(m)||!r.isValid(g))throw new Error("invalid affine point");if(p instanceof O)throw new Error("projective point not allowed");return r.is0(m)&&r.is0(g)?O.ZERO:new O(m,g,r.ONE)}static fromBytes(p){const m=O.fromAffine(b(fs(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return O.fromBytes(bt("pointHex",p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,m=!0){return q.createCache(this,p),m||this.multiply(gf),this}assertValidity(){C(this)}hasEvenY(){const{y:p}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(p)}equals(p){x(p);const{X:m,Y:g,Z:v}=this,{X:S,Y:B,Z:I}=p,$=r.eql(r.mul(m,I),r.mul(S,v)),T=r.eql(r.mul(g,I),r.mul(B,v));return $&&T}negate(){return new O(this.X,r.neg(this.Y),this.Z)}double(){const{a:p,b:m}=s,g=r.mul(m,gf),{X:v,Y:S,Z:B}=this;let I=r.ZERO,$=r.ZERO,T=r.ZERO,F=r.mul(v,v),N=r.mul(S,S),k=r.mul(B,B),R=r.mul(v,S);return R=r.add(R,R),T=r.mul(v,B),T=r.add(T,T),I=r.mul(p,T),$=r.mul(g,k),$=r.add(I,$),I=r.sub(N,$),$=r.add(N,$),$=r.mul(I,$),I=r.mul(R,I),T=r.mul(g,T),k=r.mul(p,k),R=r.sub(F,k),R=r.mul(p,R),R=r.add(R,T),T=r.add(F,F),F=r.add(T,F),F=r.add(F,k),F=r.mul(F,R),$=r.add($,F),k=r.mul(S,B),k=r.add(k,k),F=r.mul(k,R),I=r.sub(I,F),T=r.mul(k,N),T=r.add(T,T),T=r.add(T,T),new O(I,$,T)}add(p){x(p);const{X:m,Y:g,Z:v}=this,{X:S,Y:B,Z:I}=p;let $=r.ZERO,T=r.ZERO,F=r.ZERO;const N=s.a,k=r.mul(s.b,gf);let R=r.mul(m,S),j=r.mul(g,B),z=r.mul(v,I),V=r.add(m,g),H=r.add(S,B);V=r.mul(V,H),H=r.add(R,j),V=r.sub(V,H),H=r.add(m,v);let K=r.add(S,I);return H=r.mul(H,K),K=r.add(R,z),H=r.sub(H,K),K=r.add(g,v),$=r.add(B,I),K=r.mul(K,$),$=r.add(j,z),K=r.sub(K,$),F=r.mul(N,H),$=r.mul(k,z),F=r.add($,F),$=r.sub(j,F),F=r.add(j,F),T=r.mul($,F),j=r.add(R,R),j=r.add(j,R),z=r.mul(N,z),H=r.mul(k,H),j=r.add(j,z),z=r.sub(R,z),z=r.mul(N,z),H=r.add(H,z),R=r.mul(j,H),T=r.add(T,R),R=r.mul(K,H),$=r.mul(V,$),$=r.sub($,R),R=r.mul(V,j),F=r.mul(K,F),F=r.add(F,R),new O($,T,F)}subtract(p){return this.add(p.negate())}is0(){return this.equals(O.ZERO)}multiply(p){const{endo:m}=e;if(!i.isValidNot0(p))throw new Error("invalid scalar: out of range");let g,v;const S=B=>q.cached(this,B,I=>Lh(O,I));if(m){const{k1neg:B,k1:I,k2neg:$,k2:T}=D(p),{p:F,f:N}=S(I),{p:k,f:R}=S(T);v=N.add(R),g=L(m.beta,F,k,B,$)}else{const{p:B,f:I}=S(p);g=B,v=I}return Lh(O,[g,v])[0]}multiplyUnsafe(p){const{endo:m}=e,g=this;if(!i.isValid(p))throw new Error("invalid scalar: out of range");if(p===mr||g.is0())return O.ZERO;if(p===ao)return g;if(q.hasCache(this))return this.multiply(p);if(m){const{k1neg:v,k1:S,k2neg:B,k2:I}=D(p),{p1:$,p2:T}=ZB(O,g,S,I);return L(m.beta,$,T,v,B)}else return q.unsafe(g,p)}multiplyAndAddUnsafe(p,m,g){const v=this.multiplyUnsafe(m).add(p.multiplyUnsafe(g));return v.is0()?void 0:v}toAffine(p){return U(this,p)}isTorsionFree(){const{isTorsionFree:p}=e;return o===ao?!0:p?p(O,this):q.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:p}=e;return o===ao?this:p?p(O,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(p=!0){return cf(p,"isCompressed"),this.assertValidity(),u(O,this,p)}toHex(p=!0){return ro(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(p=!0){return this.toBytes(p)}_setWindowSize(p){this.precompute(p)}static normalizeZ(p){return Lh(O,p)}static msm(p,m){return WB(O,i,p,m)}static fromPrivateKey(p){return O.BASE.multiply(co(i,p))}}O.BASE=new O(s.Gx,s.Gy,r.ONE),O.ZERO=new O(r.ZERO,r.ONE,r.ZERO),O.Fp=r,O.Fn=i;const M=i.BITS,q=new GB(O,e.endo?Math.ceil(M/2):M);return O.BASE.precompute(8),O}function _2(t){return Uint8Array.of(t?2:3)}function S2(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function l$(t,e={}){const{Fn:n}=t,r=e.randomBytes||xh,i=Object.assign(S2(t.Fp,n),{seed:d2(n.ORDER)});function s(d){try{return!!co(n,d)}catch{return!1}}function o(d,u){const{publicKey:b,publicKeyUncompressed:w}=i;try{const E=d.length;return u===!0&&E!==b||u===!1&&E!==w?!1:!!t.fromBytes(d)}catch{return!1}}function a(d=r(i.seed)){return HB(fs(d,i.seed,"seed"),n.ORDER)}function c(d,u=!0){return t.BASE.multiply(co(n,d)).toBytes(u)}function f(d){const u=a(d);return{secretKey:u,publicKey:c(u)}}function l(d){if(typeof d=="bigint")return!1;if(d instanceof t)return!0;const{secretKey:u,publicKey:b,publicKeyUncompressed:w}=i;if(n.allowedLengths||u===b)return;const E=bt("key",d).length;return E===b||E===w}function h(d,u,b=!0){if(l(d)===!0)throw new Error("first arg must be private key");if(l(u)===!1)throw new Error("second arg must be public key");const w=co(n,d);return t.fromHex(u).multiply(w).toBytes(b)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:f,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:d=>co(n,d),precompute(d=8,u=t.BASE){return u.precompute(d,!1)}},lengths:i})}function h$(t,e,n={}){$y(e),hf(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||xh,i=n.hmac||((m,...g)=>Xy(e,m,fi(...g))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:u}=l$(t,n),b={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function E(m){const g=a>>ao;return m>g}function A(m,g){if(!o.isValidNot0(g))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return g}function P(m,g){jh(g);const v=u.signature,S=g==="compact"?v:g==="recovered"?v+1:void 0;return fs(m,S,`${g} signature`)}class _{constructor(g,v,S){this.r=A("r",g),this.s=A("s",v),S!=null&&(this.recovery=S),Object.freeze(this)}static fromBytes(g,v=w){P(g,v);let S;if(v==="der"){const{r:T,s:F}=wr.toSig(fs(g));return new _(T,F)}v==="recovered"&&(S=g[0],v="compact",g=g.subarray(1));const B=o.BYTES,I=g.subarray(0,B),$=g.subarray(B,B*2);return new _(o.fromBytes(I),o.fromBytes($),S)}static fromHex(g,v){return this.fromBytes(sf(g),v)}addRecoveryBit(g){return new _(this.r,this.s,g)}recoverPublicKey(g){const v=s.ORDER,{r:S,s:B,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*x2<v&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");const $=I===2||I===3?S+a:S;if(!s.isValid($))throw new Error("recovery id 2 or 3 invalid");const T=s.toBytes($),F=t.fromBytes(fi(_2((I&1)===0),T)),N=o.inv($),k=D(bt("msgHash",g)),R=o.create(-k*N),j=o.create(B*N),z=t.BASE.multiplyUnsafe(R).add(F.multiplyUnsafe(j));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return E(this.s)}toBytes(g=w){if(jh(g),g==="der")return sf(wr.hexFromSig(this));const v=o.toBytes(this.r),S=o.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return fi(Uint8Array.of(this.recovery),v,S)}return fi(v,S)}toHex(g){return ro(this.toBytes(g))}assertValidity(){}static fromCompact(g){return _.fromBytes(bt("sig",g),"compact")}static fromDER(g){return _.fromBytes(bt("sig",g),"der")}normalizeS(){return this.hasHighS()?new _(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return ro(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return ro(this.toBytes("compact"))}}const x=n.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");const g=uf(m),v=m.length*8-c;return v>0?g>>BigInt(v):g},D=n.bits2int_modN||function(m){return o.create(x(m))},U=ga(c);function C(m){return Uh("num < 2^"+c,m,mr,U),o.toBytes(m)}function L(m,g){return fs(m,void 0,"message"),g?fs(e(m),void 0,"prehashed message"):m}function O(m,g,v){if(["recovered","canonical"].some(j=>j in v))throw new Error("sign() legacy options not supported");const{lowS:S,prehash:B,extraEntropy:I}=Mh(v,b);m=L(m,B);const $=D(m),T=co(o,g),F=[C(T),C($)];if(I!=null&&I!==!1){const j=I===!0?r(u.secretKey):I;F.push(bt("extraEntropy",j))}const N=fi(...F),k=$;function R(j){const z=x(j);if(!o.isValidNot0(z))return;const V=o.inv(z),H=t.BASE.multiply(z).toAffine(),K=o.create(H.x);if(K===mr)return;const Y=o.create(V*o.create(k+K*T));if(Y===mr)return;let X=(H.x===K?0:2)|Number(H.y&ao),ee=Y;return S&&E(Y)&&(ee=o.neg(Y),X^=1),new _(K,ee,X)}return{seed:N,k2sig:R}}function M(m,g,v={}){m=bt("message",m);const{seed:S,k2sig:B}=O(m,g,v);return UB(e.outputLen,o.BYTES,i)(S,B)}function q(m){let g;const v=typeof m=="string"||rf(m),S=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!S)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(S)g=new _(m.r,m.s);else if(v){try{g=_.fromBytes(bt("sig",m),"der")}catch(B){if(!(B instanceof wr.Err))throw B}if(!g)try{g=_.fromBytes(bt("sig",m),"compact")}catch{return!1}}return g||!1}function y(m,g,v,S={}){const{lowS:B,prehash:I,format:$}=Mh(S,b);if(v=bt("publicKey",v),g=L(bt("message",g),I),"strict"in S)throw new Error("options.strict was renamed to lowS");const T=$===void 0?q(m):_.fromBytes(bt("sig",m),$);if(T===!1)return!1;try{const F=t.fromBytes(v);if(B&&T.hasHighS())return!1;const{r:N,s:k}=T,R=D(g),j=o.inv(k),z=o.create(R*j),V=o.create(N*j),H=t.BASE.multiplyUnsafe(z).add(F.multiplyUnsafe(V));return H.is0()?!1:o.create(H.x)===N}catch{return!1}}function p(m,g,v={}){const{prehash:S}=Mh(v,b);return g=L(g,S),_.fromBytes(m,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:u,Point:t,sign:M,verify:y,recoverPublicKey:p,Signature:_,hash:e})}function d$(t){const e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},n=t.Fp;let r=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0;const i=yi(e.n,{BITS:t.nBitLength,allowedLengths:r,modFromBytes:t.wrapPrivateKey}),s={Fp:n,Fn:i,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function p$(t){const{CURVE:e,curveOpts:n}=d$(t),r={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:n,hash:t.hash,ecdsaOpts:r}}function g$(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,l2(n.Fn.ORDER,n.Fn.BITS))})}function b$(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=p$(t),s=u$(e,n),o=h$(s,r,i);return g$(t,o)}function zh(t,e){const n=r=>b$({...t,hash:r});return{...n(e),create:n}}const I2={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},B2={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},$2={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},y$=yi(I2.p),w$=yi(B2.p),m$=yi($2.p);zh({...I2,Fp:y$,lowS:!1},iB),zh({...B2,Fp:w$,lowS:!1},oB),zh({...$2,Fp:m$,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},sB);const v$="https://api.pay.walletconnect.com",E$="js-walletconnect-pay",x$="1.0.1-canary.1",Dn="WalletConnectPay";function _$(){return II()?"rn-ios":SI()?"rn-android":BI()?"browser":Ey()?"node":"unknown"}var S$=Object.defineProperty,I$=(t,e,n)=>e in t?S$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,A2=(t,e,n)=>I$(t,typeof e!="symbol"?e+"":e,n);class Te extends Error{constructor(e,n,r){super(n),A2(this,"code"),A2(this,"originalMessage"),this.name="PayError",this.code=e,this.originalMessage=r??n,Object.setPrototypeOf(this,Te.prototype)}static fromNativeError(e){if(e instanceof Te)return e;const n=e instanceof Error?e.message:String(e);return n.includes("JSON parse error")?new Te("JSON_PARSE",n):n.includes("JSON serialize error")?new Te("JSON_SERIALIZE",n):n.includes("Payment options error")?new Te("PAYMENT_OPTIONS",n):n.includes("Payment request error")?new Te("PAYMENT_REQUEST",n):n.includes("Confirm payment error")?new Te("CONFIRM_PAYMENT",n):new Te("UNKNOWN",n)}}class Hh extends Te{constructor(){super("NATIVE_MODULE_NOT_FOUND","WalletConnect Pay native module not found. Make sure @walletconnect/react-native-compat is installed and linked."),this.name="NativeModuleNotFoundError",Object.setPrototypeOf(this,Hh.prototype)}}class Vh extends Te{constructor(e){super("PAYMENT_OPTIONS",`Failed to get payment options: ${e}`,e),this.name="PaymentOptionsError",Object.setPrototypeOf(this,Vh.prototype)}}class Kh extends Te{constructor(e){super("PAYMENT_REQUEST",`Failed to get payment actions: ${e}`,e),this.name="PaymentActionsError",Object.setPrototypeOf(this,Kh.prototype)}}class Gh extends Te{constructor(e){super("CONFIRM_PAYMENT",`Failed to confirm payment: ${e}`,e),this.name="ConfirmPaymentError",Object.setPrototypeOf(this,Gh.prototype)}}var B$=Object.defineProperty,$$=(t,e,n)=>e in t?B$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,A$=(t,e,n)=>$$(t,typeof e!="symbol"?e+"":e,n);let wi;function O2(){var t,e;if(wi!==void 0)return wi;try{const n=globalThis.ReactNative;if((t=n?.NativeModules)!=null&&t.RNWalletConnectPay)return wi=n.NativeModules.RNWalletConnectPay,wi;const r=(e=globalThis.expo)==null?void 0:e.modules;return r!=null&&r.RNWalletConnectPay?(wi=r.RNWalletConnectPay,wi):(wi=null,null)}catch{return wi=null,null}}function O$(){return O2()!==null}class D${constructor(e){A$(this,"module");const n=O2();if(!n)throw new Hh;if(n.initialize)try{const r=JSON.stringify(e);n.initialize(r)}catch(r){throw new Te("INITIALIZATION_ERROR",`Failed to initialize native Pay module: ${r instanceof Error?r.message:String(r)}`)}this.module=n}async getPaymentOptions(e){var n;const r={paymentLink:e.paymentLink,accounts:e.accounts,includePaymentInfo:(n=e.includePaymentInfo)!=null?n:!1};try{const i=await this.module.getPaymentOptions(JSON.stringify(r));return JSON.parse(i)}catch(i){throw Te.fromNativeError(i)}}async getRequiredPaymentActions(e){const n={paymentId:e.paymentId,optionId:e.optionId};try{const r=await this.module.getRequiredPaymentActions(JSON.stringify(n));return JSON.parse(r)}catch(r){throw Te.fromNativeError(r)}}async confirmPayment(e){const n={paymentId:e.paymentId,optionId:e.optionId,signatures:e.signatures,collectedData:e.collectedData};try{const r=await this.module.confirmPayment(JSON.stringify(n));return JSON.parse(r)}catch(r){throw Te.fromNativeError(r)}}}function P$(t){return new D$(t)}function D2(){return O$()?"native":null}function R$(t){const e=D2();if(!e)throw new Error("No Pay provider available. Make sure you are running in React Native with the native module installed, or in a browser with WASM support.");switch(e){case"native":return P$(t);case"wasm":throw new Error("WASM provider not yet implemented");default:throw new Error(`Unknown provider type: ${e}`)}}function T$(){return D2()!==null}var N$=Object.defineProperty,U$=(t,e,n)=>e in t?N$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ya=(t,e,n)=>U$(t,typeof e!="symbol"?e+"":e,n);class C${constructor(e){ya(this,"appId"),ya(this,"apiKey"),ya(this,"baseUrl"),ya(this,"logger"),ya(this,"provider");var n,r,i;this.appId=e.appId,this.apiKey=e.apiKey,this.baseUrl=(n=e.baseUrl)!=null?n:v$,this.logger=typeof e.logger=="string"?b1(m1({level:e.logger})):(r=e.logger)!=null?r:b1(m1({level:"error"})),this.logger.trace(`${Dn} initialized`);const s={baseUrl:this.baseUrl,projectId:e.appId,apiKey:e.apiKey,appId:e.appId,clientId:e.clientId,sdkName:E$,sdkVersion:x$,sdkPlatform:_$(),bundleId:(i=$I())!=null?i:""};this.provider=R$(s),this.logger.debug(`${Dn} provider initialized`)}static isAvailable(){return T$()}async getPaymentOptions(e){this.logger.debug({paymentLink:e.paymentLink,accounts:e.accounts,includePaymentInfo:e.includePaymentInfo},`${Dn} getPaymentOptions`);try{const n=await this.provider.getPaymentOptions(e);return this.logger.debug({paymentId:n.paymentId,optionsCount:n.options.length},`${Dn} getPaymentOptions response`),n}catch(n){throw this.logger.error({error:n},`${Dn} getPaymentOptions error`),n instanceof Te?n:new Vh(String(n))}}async getRequiredPaymentActions(e){this.logger.debug({paymentId:e.paymentId,optionId:e.optionId},`${Dn} getRequiredPaymentActions`);try{const n=await this.provider.getRequiredPaymentActions(e);return this.logger.debug({actionsCount:n.length},`${Dn} getRequiredPaymentActions response`),n}catch(n){throw this.logger.error({error:n},`${Dn} getRequiredPaymentActions error`),n instanceof Te?n:new Kh(String(n))}}async confirmPayment(e){this.logger.debug({paymentId:e.paymentId,optionId:e.optionId,signaturesCount:e.signatures.length,hasCollectedData:!!e.collectedData},`${Dn} confirmPayment`);try{const n=await this.provider.confirmPayment(e);return this.logger.debug({status:n.status,isFinal:n.isFinal},`${Dn} confirmPayment response`),n}catch(n){throw this.logger.error({error:n},`${Dn} confirmPayment error`),n instanceof Te?n:new Gh(String(n))}}}const P2=C$,R2="wc",L$=2,Zh="WalletKit",F$=`${R2}@2:${Zh}:`,k$={database:":memory:"},q$="request";class hs{}class j$ extends hs{constructor(e){super()}}const T2=Z.FIVE_SECONDS,ds={pulse:"heartbeat_pulse"};class Wh extends j${constructor(e){super(e),this.events=new at.exports.EventEmitter,this.interval=T2,this.interval=e?.interval||T2}static async init(e){const n=new Wh(e);return await n.init(),n}async init(){await this.initialize()}stop(){clearInterval(this.intervalRef)}on(e,n){this.events.on(e,n)}once(e,n){this.events.once(e,n)}off(e,n){this.events.off(e,n)}removeListener(e,n){this.events.removeListener(e,n)}async initialize(){this.intervalRef=setInterval(()=>this.pulse(),Z.toMiliseconds(this.interval))}pulse(){this.events.emit(ds.pulse)}}const M$=/"(?:_|\\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*:/,z$=/"(?: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*:/,H$=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function V$(t,e){if(t==="__proto__"||t==="constructor"&&e&&typeof e=="object"&&"prototype"in e){K$(t);return}return e}function K$(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}function bf(t,e={}){if(typeof t!="string")return t;if(t[0]==='"'&&t[t.length-1]==='"'&&t.indexOf("\\")===-1)return t.slice(1,-1);const n=t.trim();if(n.length<=9)switch(n.toLowerCase()){case"true":return!0;case"false":return!1;case"undefined":return;case"null":return null;case"nan":return Number.NaN;case"infinity":return Number.POSITIVE_INFINITY;case"-infinity":return Number.NEGATIVE_INFINITY}if(!H$.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(M$.test(t)||z$.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,V$)}return JSON.parse(t)}catch(r){if(e.strict)throw r;return t}}function G$(t){return!t||typeof t.then!="function"?Promise.resolve(t):t}function Ke(t,...e){try{return G$(t(...e))}catch(n){return Promise.reject(n)}}function Z$(t){const e=typeof t;return t===null||e!=="object"&&e!=="function"}function W$(t){const e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}function yf(t){if(Z$(t))return String(t);if(W$(t)||Array.isArray(t))return JSON.stringify(t);if(typeof t.toJSON=="function")return yf(t.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function N2(){if(typeof Buffer>"u")throw new TypeError("[unstorage] Buffer is not supported!")}const Yh="base64:";function Y$(t){if(typeof t=="string")return t;N2();const e=Buffer.from(t).toString("base64");return Yh+e}function X$(t){return typeof t!="string"||!t.startsWith(Yh)?t:(N2(),Buffer.from(t.slice(Yh.length),"base64"))}function Kt(t){return t?t.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function J$(...t){return Kt(t.join(":"))}function wf(t){return t=Kt(t),t?t+":":""}function Qj(t){return t}const Q$="memory",eA=()=>{const t=new Map;return{name:Q$,getInstance:()=>t,hasItem(e){return t.has(e)},getItem(e){return t.get(e)??null},getItemRaw(e){return t.get(e)??null},setItem(e,n){t.set(e,n)},setItemRaw(e,n){t.set(e,n)},removeItem(e){t.delete(e)},getKeys(){return[...t.keys()]},clear(){t.clear()},dispose(){t.clear()}}};function tA(t={}){const e={mounts:{"":t.driver||eA()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},n=f=>{for(const l of e.mountpoints)if(f.startsWith(l))return{base:l,relativeKey:f.slice(l.length),driver:e.mounts[l]};return{base:"",relativeKey:f,driver:e.mounts[""]}},r=(f,l)=>e.mountpoints.filter(h=>h.startsWith(f)||l&&f.startsWith(h)).map(h=>({relativeBase:f.length>h.length?f.slice(h.length):void 0,mountpoint:h,driver:e.mounts[h]})),i=(f,l)=>{if(e.watching){l=Kt(l);for(const h of e.watchListeners)h(f,l)}},s=async()=>{if(!e.watching){e.watching=!0;for(const f in e.mounts)e.unwatch[f]=await U2(e.mounts[f],i,f)}},o=async()=>{if(e.watching){for(const f in e.unwatch)await e.unwatch[f]();e.unwatch={},e.watching=!1}},a=(f,l,h)=>{const d=new Map,u=b=>{let w=d.get(b.base);return w||(w={driver:b.driver,base:b.base,items:[]},d.set(b.base,w)),w};for(const b of f){const w=typeof b=="string",E=Kt(w?b:b.key),A=w?void 0:b.value,P=w||!b.options?l:{...l,...b.options},_=n(E);u(_).items.push({key:E,value:A,relativeKey:_.relativeKey,options:P})}return Promise.all([...d.values()].map(b=>h(b))).then(b=>b.flat())},c={hasItem(f,l={}){f=Kt(f);const{relativeKey:h,driver:d}=n(f);return Ke(d.hasItem,h,l)},getItem(f,l={}){f=Kt(f);const{relativeKey:h,driver:d}=n(f);return Ke(d.getItem,h,l).then(u=>bf(u))},getItems(f,l){return a(f,l,h=>h.driver.getItems?Ke(h.driver.getItems,h.items.map(d=>({key:d.relativeKey,options:d.options})),l).then(d=>d.map(u=>({key:J$(h.base,u.key),value:bf(u.value)}))):Promise.all(h.items.map(d=>Ke(h.driver.getItem,d.relativeKey,d.options).then(u=>({key:d.key,value:bf(u)})))))},getItemRaw(f,l={}){f=Kt(f);const{relativeKey:h,driver:d}=n(f);return d.getItemRaw?Ke(d.getItemRaw,h,l):Ke(d.getItem,h,l).then(u=>X$(u))},async setItem(f,l,h={}){if(l===void 0)return c.removeItem(f);f=Kt(f);const{relativeKey:d,driver:u}=n(f);u.setItem&&(await Ke(u.setItem,d,yf(l),h),u.watch||i("update",f))},async setItems(f,l){await a(f,l,async h=>{if(h.driver.setItems)return Ke(h.driver.setItems,h.items.map(d=>({key:d.relativeKey,value:yf(d.value),options:d.options})),l);h.driver.setItem&&await Promise.all(h.items.map(d=>Ke(h.driver.setItem,d.relativeKey,yf(d.value),d.options)))})},async setItemRaw(f,l,h={}){if(l===void 0)return c.removeItem(f,h);f=Kt(f);const{relativeKey:d,driver:u}=n(f);if(u.setItemRaw)await Ke(u.setItemRaw,d,l,h);else if(u.setItem)await Ke(u.setItem,d,Y$(l),h);else return;u.watch||i("update",f)},async removeItem(f,l={}){typeof l=="boolean"&&(l={removeMeta:l}),f=Kt(f);const{relativeKey:h,driver:d}=n(f);d.removeItem&&(await Ke(d.removeItem,h,l),(l.removeMeta||l.removeMata)&&await Ke(d.removeItem,h+"$",l),d.watch||i("remove",f))},async getMeta(f,l={}){typeof l=="boolean"&&(l={nativeOnly:l}),f=Kt(f);const{relativeKey:h,driver:d}=n(f),u=Object.create(null);if(d.getMeta&&Object.assign(u,await Ke(d.getMeta,h,l)),!l.nativeOnly){const b=await Ke(d.getItem,h+"$",l).then(w=>bf(w));b&&typeof b=="object"&&(typeof b.atime=="string"&&(b.atime=new Date(b.atime)),typeof b.mtime=="string"&&(b.mtime=new Date(b.mtime)),Object.assign(u,b))}return u},setMeta(f,l,h={}){return this.setItem(f+"$",l,h)},removeMeta(f,l={}){return this.removeItem(f+"$",l)},async getKeys(f,l={}){f=wf(f);const h=r(f,!0);let d=[];const u=[];for(const b of h){const w=await Ke(b.driver.getKeys,b.relativeBase,l);for(const E of w){const A=b.mountpoint+Kt(E);d.some(P=>A.startsWith(P))||u.push(A)}d=[b.mountpoint,...d.filter(E=>!E.startsWith(b.mountpoint))]}return f?u.filter(b=>b.startsWith(f)&&b[b.length-1]!=="$"):u.filter(b=>b[b.length-1]!=="$")},async clear(f,l={}){f=wf(f),await Promise.all(r(f,!1).map(async h=>{if(h.driver.clear)return Ke(h.driver.clear,h.relativeBase,l);if(h.driver.removeItem){const d=await h.driver.getKeys(h.relativeBase||"",l);return Promise.all(d.map(u=>h.driver.removeItem(u,l)))}}))},async dispose(){await Promise.all(Object.values(e.mounts).map(f=>C2(f)))},async watch(f){return await s(),e.watchListeners.push(f),async()=>{e.watchListeners=e.watchListeners.filter(l=>l!==f),e.watchListeners.length===0&&await o()}},async unwatch(){e.watchListeners=[],await o()},mount(f,l){if(f=wf(f),f&&e.mounts[f])throw new Error(`already mounted at ${f}`);return f&&(e.mountpoints.push(f),e.mountpoints.sort((h,d)=>d.length-h.length)),e.mounts[f]=l,e.watching&&Promise.resolve(U2(l,i,f)).then(h=>{e.unwatch[f]=h}).catch(console.error),c},async unmount(f,l=!0){f=wf(f),!(!f||!e.mounts[f])&&(e.watching&&f in e.unwatch&&(e.unwatch[f](),delete e.unwatch[f]),l&&await C2(e.mounts[f]),e.mountpoints=e.mountpoints.filter(h=>h!==f),delete e.mounts[f])},getMount(f=""){f=Kt(f)+":";const l=n(f);return{driver:l.driver,base:l.base}},getMounts(f="",l={}){return f=Kt(f),r(f,l.parents).map(d=>({driver:d.driver,base:d.mountpoint}))},keys:(f,l={})=>c.getKeys(f,l),get:(f,l={})=>c.getItem(f,l),set:(f,l,h={})=>c.setItem(f,l,h),has:(f,l={})=>c.hasItem(f,l),del:(f,l={})=>c.removeItem(f,l),remove:(f,l={})=>c.removeItem(f,l)};return c}function U2(t,e,n){return t.watch?t.watch((r,i)=>e(r,n+i)):()=>{}}async function C2(t){typeof t.dispose=="function"&&await Ke(t.dispose)}function ps(t){return new Promise((e,n)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>n(t.error)})}function L2(t,e){const n=indexedDB.open(t);n.onupgradeneeded=()=>n.result.createObjectStore(e);const r=ps(n);return(i,s)=>r.then(o=>s(o.transaction(e,i).objectStore(e)))}let Xh;function wa(){return Xh||(Xh=L2("keyval-store","keyval")),Xh}function F2(t,e=wa()){return e("readonly",n=>ps(n.get(t)))}function nA(t,e,n=wa()){return n("readwrite",r=>(r.put(e,t),ps(r.transaction)))}function rA(t,e=wa()){return e("readwrite",n=>(n.delete(t),ps(n.transaction)))}function iA(t=wa()){return t("readwrite",e=>(e.clear(),ps(e.transaction)))}function sA(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},ps(t.transaction)}function oA(t=wa()){return t("readonly",e=>{if(e.getAllKeys)return ps(e.getAllKeys());const n=[];return sA(e,r=>n.push(r.key)).then(()=>n)})}const aA="idb-keyval";var cA=(t={})=>{const e=t.base&&t.base.length>0?`${t.base}:`:"",n=i=>e+i;let r;return t.dbName&&t.storeName&&(r=L2(t.dbName,t.storeName)),{name:aA,options:t,async hasItem(i){return!(typeof await F2(n(i),r)>"u")},async getItem(i){return await F2(n(i),r)??null},setItem(i,s){return nA(n(i),s,r)},removeItem(i){return rA(n(i),r)},getKeys(){return oA(r)},clear(){return iA(r)}}};const fA="WALLET_CONNECT_V2_INDEXED_DB",uA="keyvaluestorage";class lA{constructor(){this.indexedDb=tA({driver:cA({dbName:fA,storeName:uA})})}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 n=await this.indexedDb.getItem(e);if(n!==null)return n}async setItem(e,n){await this.indexedDb.setItem(e,na(n))}async removeItem(e){await this.indexedDb.removeItem(e)}}var Jh=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},mf={exports:{}};(function(){let t;function e(){}t=e,t.prototype.getItem=function(n){return this.hasOwnProperty(n)?String(this[n]):null},t.prototype.setItem=function(n,r){this[n]=String(r)},t.prototype.removeItem=function(n){delete this[n]},t.prototype.clear=function(){const n=this;Object.keys(n).forEach(function(r){n[r]=void 0,delete n[r]})},t.prototype.key=function(n){return n=n||0,Object.keys(this)[n]},t.prototype.__defineGetter__("length",function(){return Object.keys(this).length}),typeof Jh<"u"&&Jh.localStorage?mf.exports=Jh.localStorage:typeof window<"u"&&window.localStorage?mf.exports=window.localStorage:mf.exports=new e})();function hA(t){var e;return[t[0],Qs((e=t[1])!=null?e:"")]}class dA{constructor(){this.localStorage=mf.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(hA)}async getItem(e){const n=this.localStorage.getItem(e);if(n!==null)return Qs(n)}async setItem(e,n){this.localStorage.setItem(e,na(n))}async removeItem(e){this.localStorage.removeItem(e)}}const pA="wc_storage_version",k2=1,gA=async(t,e,n)=>{const r=pA,i=await e.getItem(r);if(i&&i>=k2){n(e);return}const s=await t.getKeys();if(!s.length){n(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(r,k2),n(e),bA(t,o)},bA=async(t,e)=>{e.length&&e.forEach(async n=>{await t.removeItem(n)})};class yA{constructor(){this.initialized=!1,this.setInitialized=n=>{this.storage=n,this.initialized=!0};const e=new dA;this.storage=e;try{const n=new lA;gA(e,n,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,n){return await this.initialize(),this.storage.setItem(e,n)}async removeItem(e){return await this.initialize(),this.storage.removeItem(e)}async initialize(){this.initialized||await new Promise(e=>{const n=setInterval(()=>{this.initialized&&(clearInterval(n),e())},20)})}}var Vn={exports:{}};function wA(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}var mA=vA;function vA(t,e,n){var r=n&&n.stringify||wA,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]=r(t);for(var a=1;a<s;a++)o[a]=r(e[a]);return o.join(" ")}if(typeof t!="string")return t;var c=e.length;if(c===0)return t;for(var f="",l=1-i,h=-1,d=t&&t.length||0,u=0;u<d;){if(t.charCodeAt(u)===37&&u+1<d){switch(h=h>-1?h:0,t.charCodeAt(u+1)){case 100:case 102:if(l>=c||e[l]==null)break;h<u&&(f+=t.slice(h,u)),f+=Number(e[l]),h=u+2,u++;break;case 105:if(l>=c||e[l]==null)break;h<u&&(f+=t.slice(h,u)),f+=Math.floor(Number(e[l])),h=u+2,u++;break;case 79:case 111:case 106:if(l>=c||e[l]===void 0)break;h<u&&(f+=t.slice(h,u));var b=typeof e[l];if(b==="string"){f+="'"+e[l]+"'",h=u+2,u++;break}if(b==="function"){f+=e[l].name||"<anonymous>",h=u+2,u++;break}f+=r(e[l]),h=u+2,u++;break;case 115:if(l>=c)break;h<u&&(f+=t.slice(h,u)),f+=String(e[l]),h=u+2,u++;break;case 37:h<u&&(f+=t.slice(h,u)),f+="%",h=u+2,u++,l--;break}++l}++u}return h===-1?t:(h<d&&(f+=t.slice(h)),f)}const q2=mA;Vn.exports=vr;const ma=UA().console||{},EA={mapHttpRequest:vf,mapHttpResponse:vf,wrapRequestSerializer:rd,wrapResponseSerializer:rd,wrapErrorSerializer:rd,req:vf,res:vf,err:M2,errWithCause:M2};function mi(t,e){return t==="silent"?1/0:e.levels.values[t]}const Qh=Symbol("pino.logFuncs"),ed=Symbol("pino.hierarchy"),xA={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function j2(t,e){const n={logger:e,parent:t[ed]};e[ed]=n}function _A(t,e,n){const r={};e.forEach(i=>{r[i]=n[i]?n[i]:ma[i]||ma[xA[i]||"log"]||fo}),t[Qh]=r}function SA(t,e){return Array.isArray(t)?t.filter(function(n){return n!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function vr(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 n=t.browser.write||ma;t.browser.write&&(t.browser.asObject=!0);const r=t.serializers||{},i=SA(t.browser.serialize,r);let s=t.browser.serialize;Array.isArray(t.browser.serialize)&&t.browser.serialize.indexOf("!stdSerializers.err")>-1&&(s=!1);const o=Object.keys(t.customLevels||{}),a=["error","fatal","warn","info","debug","trace"].concat(o);typeof n=="function"&&a.forEach(function(w){n[w]=n}),(t.enabled===!1||t.browser.disabled)&&(t.level="silent");const c=t.level||"info",f=Object.create(n);f.log||(f.log=fo),_A(f,a,n),j2({},f),Object.defineProperty(f,"levelVal",{get:h}),Object.defineProperty(f,"level",{get:d,set:u});const l={transmit:e,serialize:i,asObject:t.browser.asObject,asObjectBindingsOnly:t.browser.asObjectBindingsOnly,formatters:t.browser.formatters,levels:a,timestamp:RA(t),messageKey:t.messageKey||"msg",onChild:t.onChild||fo};f.levels=IA(t),f.level=c,f.isLevelEnabled=function(w){return this.levels.values[w]?this.levels.values[w]>=this.levels.values[this.level]:!1},f.setMaxListeners=f.getMaxListeners=f.emit=f.addListener=f.on=f.prependListener=f.once=f.prependOnceListener=f.removeListener=f.removeAllListeners=f.listeners=f.listenerCount=f.eventNames=f.write=f.flush=fo,f.serializers=r,f._serialize=i,f._stdErrSerialize=s,f.child=function(...w){return b.call(this,l,...w)},e&&(f._logEvent=nd());function h(){return mi(this.level,this)}function d(){return this._level}function u(w){if(w!=="silent"&&!this.levels.values[w])throw Error("unknown level "+w);this._level=w,gs(this,l,f,"error"),gs(this,l,f,"fatal"),gs(this,l,f,"warn"),gs(this,l,f,"info"),gs(this,l,f,"debug"),gs(this,l,f,"trace"),o.forEach(E=>{gs(this,l,f,E)})}function b(w,E,A){if(!E)throw new Error("missing bindings for child Pino");A=A||{},i&&E.serializers&&(A.serializers=E.serializers);const P=A.serializers;if(i&&P){var _=Object.assign({},r,P),x=t.browser.serialize===!0?Object.keys(_):i;delete E.serializers,td([E],x,_,this._stdErrSerialize)}function D(C){this._childLevel=(C._childLevel|0)+1,this.bindings=E,_&&(this.serializers=_,this._serialize=x),e&&(this._logEvent=nd([].concat(C._logEvent.bindings,E)))}D.prototype=this;const U=new D(this);return j2(this,U),U.child=function(...C){return b.call(this,w,...C)},U.level=A.level||this.level,w.onChild(U),U}return f}function IA(t){const e=t.customLevels||{},n=Object.assign({},vr.levels.values,e),r=Object.assign({},vr.levels.labels,BA(e));return{values:n,labels:r}}function BA(t){const e={};return Object.keys(t).forEach(function(n){e[t[n]]=n}),e}vr.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"}},vr.stdSerializers=EA,vr.stdTimeFunctions=Object.assign({},{nullTime:z2,epochTime:H2,unixTime:TA,isoTime:NA});function $A(t){const e=[];t.bindings&&e.push(t.bindings);let n=t[ed];for(;n.parent;)n=n.parent,n.logger.bindings&&e.push(n.logger.bindings);return e.reverse()}function gs(t,e,n,r){if(Object.defineProperty(t,r,{value:mi(t.level,n)>mi(r,n)?fo:n[Qh][r],writable:!0,enumerable:!0,configurable:!0}),t[r]===fo){if(!e.transmit)return;const s=e.transmit.level||t.level,o=mi(s,n);if(mi(r,n)<o)return}t[r]=OA(t,e,n,r);const i=$A(t);i.length!==0&&(t[r]=AA(i,t[r]))}function AA(t,e){return function(){return e.apply(this,[...t,...arguments])}}function OA(t,e,n,r){return function(i){return function(){const s=e.timestamp(),o=new Array(arguments.length),a=Object.getPrototypeOf&&Object.getPrototypeOf(this)===ma?ma:this;for(var c=0;c<o.length;c++)o[c]=arguments[c];var f=!1;if(e.serialize&&(td(o,this._serialize,this.serializers,this._stdErrSerialize),f=!0),e.asObject||e.formatters?i.call(a,...DA(this,r,o,s,e)):i.apply(a,o),e.transmit){const l=e.transmit.level||t._level,h=mi(l,n),d=mi(r,n);if(d<h)return;PA(this,{ts:s,methodLevel:r,methodValue:d,transmitLevel:l,transmitValue:n.levels.values[e.transmit.level||t._level],send:e.transmit.send,val:mi(t._level,n)},o,f)}}}(t[Qh][r])}function DA(t,e,n,r,i){const{level:s,log:o=h=>h}=i.formatters||{},a=n.slice();let c=a[0];const f={};let l=(t._childLevel|0)+1;if(l<1&&(l=1),r&&(f.time=r),s){const h=s(e,t.levels.values[e]);Object.assign(f,h)}else f.level=t.levels.values[e];if(i.asObjectBindingsOnly){if(c!==null&&typeof c=="object")for(;l--&&typeof a[0]=="object";)Object.assign(f,a.shift());return[o(f),...a]}else{if(c!==null&&typeof c=="object"){for(;l--&&typeof a[0]=="object";)Object.assign(f,a.shift());c=a.length?q2(a.shift(),a):void 0}else typeof c=="string"&&(c=q2(a.shift(),a));return c!==void 0&&(f[i.messageKey]=c),[o(f)]}}function td(t,e,n,r){for(const i in t)if(r&&t[i]instanceof Error)t[i]=vr.stdSerializers.err(t[i]);else if(typeof t[i]=="object"&&!Array.isArray(t[i])&&e)for(const s in t[i])e.indexOf(s)>-1&&s in n&&(t[i][s]=n[s](t[i][s]))}function PA(t,e,n,r=!1){const i=e.send,s=e.ts,o=e.methodLevel,a=e.methodValue,c=e.val,f=t._logEvent.bindings;r||td(n,t._serialize||Object.keys(t.serializers),t.serializers,t._stdErrSerialize===void 0?!0:t._stdErrSerialize),t._logEvent.ts=s,t._logEvent.messages=n.filter(function(l){return f.indexOf(l)===-1}),t._logEvent.level.label=o,t._logEvent.level.value=a,i(o,t._logEvent,c),t._logEvent=nd(f)}function nd(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function M2(t){const e={type:t.constructor.name,msg:t.message,stack:t.stack};for(const n in t)e[n]===void 0&&(e[n]=t[n]);return e}function RA(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?z2:H2}function vf(){return{}}function rd(t){return t}function fo(){}function z2(){return!1}function H2(){return Date.now()}function TA(){return Math.round(Date.now()/1e3)}function NA(){return new Date(Date.now()).toISOString()}function UA(){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)||{}}}Vn.exports.default=vr,Vn.exports.pino=vr;const CA={level:"info"},Ef="custom_context",id=1e3*1024;var LA=Object.defineProperty,FA=(t,e,n)=>e in t?LA(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,vi=(t,e,n)=>FA(t,typeof e!="symbol"?e+"":e,n);class kA{constructor(e){vi(this,"nodeValue"),vi(this,"sizeInBytes"),vi(this,"next"),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 V2{constructor(e){vi(this,"lengthInNodes"),vi(this,"sizeInBytes"),vi(this,"head"),vi(this,"tail"),vi(this,"maxSizeInBytes"),this.head=null,this.tail=null,this.lengthInNodes=0,this.maxSizeInBytes=e,this.sizeInBytes=0}append(e){const n=new kA(e);if(n.size>this.maxSizeInBytes)throw new Error(`[LinkedList] Value too big to insert into list: ${e} with size ${n.size}`);for(;this.size+n.size>this.maxSizeInBytes;)this.shift();this.head?(this.tail&&(this.tail.next=n),this.tail=n):(this.head=n,this.tail=n),this.lengthInNodes++,this.sizeInBytes+=n.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 n=this.head;for(;n!==null;)e.push(n.value),n=n.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 n=e.value;return e=e.next,{done:!1,value:n}}}}}const qA=t=>JSON.stringify(t,(e,n)=>typeof n=="bigint"?n.toString()+"n":n);function K2(t){return typeof t=="string"?t:qA(t)||""}var jA=Object.defineProperty,MA=(t,e,n)=>e in t?jA(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,xf=(t,e,n)=>MA(t,typeof e!="symbol"?e+"":e,n);class G2{constructor(e,n=id){xf(this,"logs"),xf(this,"level"),xf(this,"levelValue"),xf(this,"MAX_LOG_SIZE_IN_BYTES"),this.level=e??"error",this.levelValue=Vn.exports.levels.values[this.level],this.MAX_LOG_SIZE_IN_BYTES=n,this.logs=new V2(this.MAX_LOG_SIZE_IN_BYTES)}forwardToConsole(e,n){n===Vn.exports.levels.values.error?console.error(e):n===Vn.exports.levels.values.warn?console.warn(e):n===Vn.exports.levels.values.debug?console.debug(e):n===Vn.exports.levels.values.trace?console.trace(e):console.log(e)}appendToLogs(e){this.logs.append(K2({timestamp:new Date().toISOString(),log:e}));const n=typeof e=="string"?JSON.parse(e).level:e.level;n>=this.levelValue&&this.forwardToConsole(e,n)}getLogs(){return this.logs}clearLogs(){this.logs=new V2(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(e){const n=this.getLogArray();return n.push(K2({extraMetadata:e})),new Blob(n,{type:"application/json"})}}var zA=Object.defineProperty,HA=(t,e,n)=>e in t?zA(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,VA=(t,e,n)=>HA(t,typeof e!="symbol"?e+"":e,n);class KA{constructor(e,n=id){VA(this,"baseChunkLogger"),this.baseChunkLogger=new G2(e,n)}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 n=URL.createObjectURL(this.logsToBlob(e)),r=document.createElement("a");r.href=n,r.download=`walletconnect-logs-${new Date().toISOString()}.txt`,document.body.appendChild(r),r.click(),document.body.removeChild(r),URL.revokeObjectURL(n)}}var GA=Object.defineProperty,ZA=(t,e,n)=>e in t?GA(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,WA=(t,e,n)=>ZA(t,typeof e!="symbol"?e+"":e,n);class YA{constructor(e,n=id){WA(this,"baseChunkLogger"),this.baseChunkLogger=new G2(e,n)}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 XA=Object.defineProperty,JA=Object.defineProperties,QA=Object.getOwnPropertyDescriptors,Z2=Object.getOwnPropertySymbols,eO=Object.prototype.hasOwnProperty,tO=Object.prototype.propertyIsEnumerable,W2=(t,e,n)=>e in t?XA(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ei=(t,e)=>{for(var n in e||(e={}))eO.call(e,n)&&W2(t,n,e[n]);if(Z2)for(var n of Z2(e))tO.call(e,n)&&W2(t,n,e[n]);return t},xi=(t,e)=>JA(t,QA(e));function nO(t){return xi(Ei({},t),{level:t?.level||CA.level})}function rO(t,e,n=Ef){return t[n]=e,t}function Gt(t,e=Ef){return t[e]||""}function iO(t,e,n=Ef){const r=Gt(t,n);return r.trim()?`${r}/${e}`:e}function sn(t,e,n=Ef){const r=iO(t,e,n),i=t.child({context:r});return rO(i,r,n)}function sO(t){var e,n;const r=new KA((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:Vn.exports(xi(Ei({},t.opts),{level:"trace",browser:xi(Ei({},(n=t.opts)==null?void 0:n.browser),{write:i=>r.write(i)})})),chunkLoggerController:r}}function oO(t){var e,n;const r=new YA((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:Vn.exports(xi(Ei({},t.opts),{level:"trace",browser:xi(Ei({},(n=t.opts)==null?void 0:n.browser),{write:i=>r.write(i)})}),r),chunkLoggerController:r}}function Y2(t){var e;if(typeof t.loggerOverride<"u"&&typeof t.loggerOverride!="string")return{logger:t.loggerOverride,chunkLoggerController:null};const n=xi(Ei({},t.opts),{level:typeof t.loggerOverride=="string"?t.loggerOverride:(e=t.opts)==null?void 0:e.level});return typeof window<"u"?sO(xi(Ei({},t),{opts:n})):oO(xi(Ei({},t),{opts:n}))}var aO=Object.defineProperty,cO=(t,e,n)=>e in t?aO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,X2=(t,e,n)=>cO(t,typeof e!="symbol"?e+"":e,n);class fO extends hs{constructor(e){super(),this.opts=e,X2(this,"protocol","wc"),X2(this,"version",2)}}var uO=Object.defineProperty,lO=(t,e,n)=>e in t?uO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,hO=(t,e,n)=>lO(t,typeof e!="symbol"?e+"":e,n);class dO extends hs{constructor(e,n){super(),this.core=e,this.logger=n,hO(this,"records",new Map)}}class pO{constructor(e,n){this.logger=e,this.core=n}}class gO extends hs{constructor(e,n){super(),this.relayer=e,this.logger=n}}class bO extends hs{constructor(e){super()}}class yO{constructor(e,n,r,i){this.core=e,this.logger=n,this.name=r}}class wO extends hs{constructor(e,n){super(),this.relayer=e,this.logger=n}}class mO extends hs{constructor(e,n){super(),this.core=e,this.logger=n}}class vO{constructor(e,n,r){this.core=e,this.logger=n,this.store=r}}class EO{constructor(e,n){this.projectId=e,this.logger=n}}class xO{constructor(e,n,r){this.core=e,this.logger=n,this.telemetryEnabled=r}}var _O=Object.defineProperty,SO=(t,e,n)=>e in t?_O(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,J2=(t,e,n)=>SO(t,typeof e!="symbol"?e+"":e,n);class IO{constructor(e){this.opts=e,J2(this,"protocol","wc"),J2(this,"version",2)}}class BO{constructor(e){this.client=e}}const $O="0.1.1";function AO(){return $O}class Se extends Error{constructor(e,n={}){const r=(()=>{if(n.cause instanceof Se){if(n.cause.details)return n.cause.details;if(n.cause.shortMessage)return n.cause.shortMessage}return n.cause&&"details"in n.cause&&typeof n.cause.details=="string"?n.cause.details:n.cause?.message?n.cause.message:n.details})(),i=n.cause instanceof Se&&n.cause.docsPath||n.docsPath,o=`https://oxlib.sh${i??""}`,a=[e||"An error occurred.",...n.metaMessages?["",...n.metaMessages]:[],...r||i?["",r?`Details: ${r}`:void 0,i?`See: ${o}`:void 0]:[]].filter(c=>typeof c=="string").join(`
19
+ `);super(a,n.cause?{cause:n.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@${AO()}`}),this.cause=n.cause,this.details=r,this.docs=o,this.docsPath=i,this.shortMessage=e}walk(e){return Q2(this,e)}}function Q2(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause?Q2(t.cause,e):e?null:t}const uo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function OO(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function va(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function bs(t,...e){if(!OO(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 DO(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");va(t.outputLen),va(t.blockLen)}function lo(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 ew(t,e){bs(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function PO(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function _i(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function sd(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Kn(t,e){return t<<32-e|t>>>e}const RO=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function TO(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function NO(t){for(let e=0;e<t.length;e++)t[e]=TO(t[e]);return t}const tw=RO?t=>t:NO;function UO(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function _f(t){return typeof t=="string"&&(t=UO(t)),bs(t),t}function CO(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];bs(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}class od{}function Sf(t){const e=r=>t().update(_f(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function nw(t=32){if(uo&&typeof uo.getRandomValues=="function")return uo.getRandomValues(new Uint8Array(t));if(uo&&typeof uo.randomBytes=="function")return Uint8Array.from(uo.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function LO(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,f=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+f,a,r)}function FO(t,e,n){return t&e^~t&n}function kO(t,e,n){return t&e^t&n^e&n}class rw extends od{constructor(e,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=sd(this.buffer)}update(e){lo(this),e=_f(e),bs(e);const{view:n,buffer:r,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=sd(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){lo(this),ew(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,_i(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;LO(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=sd(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const Er=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),yt=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),wt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),If=BigInt(2**32-1),iw=BigInt(32);function qO(t,e=!1){return e?{h:Number(t&If),l:Number(t>>iw&If)}:{h:Number(t>>iw&If)|0,l:Number(t&If)|0}}function sw(t,e=!1){const n=t.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:a}=qO(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const ow=(t,e,n)=>t>>>n,aw=(t,e,n)=>t<<32-n|e>>>n,ho=(t,e,n)=>t>>>n|e<<32-n,po=(t,e,n)=>t<<32-n|e>>>n,Bf=(t,e,n)=>t<<64-n|e>>>n-32,$f=(t,e,n)=>t>>>n-32|e<<64-n,jO=(t,e,n)=>t<<n|e>>>32-n,MO=(t,e,n)=>e<<n|t>>>32-n,zO=(t,e,n)=>e<<n-32|t>>>64-n,HO=(t,e,n)=>t<<n-32|e>>>64-n;function xr(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const VO=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),KO=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,GO=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),ZO=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,WO=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),YO=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,XO=BigInt(0),Ea=BigInt(1),JO=BigInt(2),QO=BigInt(7),eD=BigInt(256),tD=BigInt(113),cw=[],fw=[],uw=[];for(let t=0,e=Ea,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],cw.push(2*(5*r+n)),fw.push((t+1)*(t+2)/2%64);let i=XO;for(let s=0;s<7;s++)e=(e<<Ea^(e>>QO)*tD)%eD,e&JO&&(i^=Ea<<(Ea<<BigInt(s))-Ea);uw.push(i)}const lw=sw(uw,!0),nD=lw[0],rD=lw[1],hw=(t,e,n)=>n>32?zO(t,e,n):jO(t,e,n),dw=(t,e,n)=>n>32?HO(t,e,n):MO(t,e,n);function iD(t,e=24){const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let o=0;o<10;o++)n[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=n[c],l=n[c+1],h=hw(f,l,1)^n[a],d=dw(f,l,1)^n[a+1];for(let u=0;u<50;u+=10)t[o+u]^=h,t[o+u+1]^=d}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=fw[o],c=hw(i,s,a),f=dw(i,s,a),l=cw[o];i=t[l],s=t[l+1],t[l]=c,t[l+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)n[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~n[(a+2)%10]&n[(a+4)%10]}t[0]^=nD[r],t[1]^=rD[r]}_i(n)}class ad extends od{constructor(e,n,r,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=s,va(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=PO(this.state)}clone(){return this._cloneInto()}keccak(){tw(this.state32),iD(this.state32,this.rounds),tw(this.state32),this.posOut=0,this.pos=0}update(e){lo(this),e=_f(e),bs(e);const{blockLen:n,state:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(n-this.pos,i-s);for(let a=0;a<o;a++)r[this.pos++]^=e[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:n,pos:r,blockLen:i}=this;e[r]^=n,(n&128)!==0&&r===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){lo(this,!1),bs(e),this.finish();const n=this.state,{blockLen:r}=this;for(let i=0,s=e.length;i<s;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,s-i);e.set(n.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 va(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(ew(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,_i(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new ad(n,r,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=r,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}}const sD=(t,e,n)=>Sf(()=>new ad(e,t,n)),oD=sD(1,136,256/8),aD=Uint32Array.from([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]),Si=new Uint32Array(64);class cD extends rw{constructor(e=32){super(64,e,8,!1),this.A=Er[0]|0,this.B=Er[1]|0,this.C=Er[2]|0,this.D=Er[3]|0,this.E=Er[4]|0,this.F=Er[5]|0,this.G=Er[6]|0,this.H=Er[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[e,n,r,i,s,o,a,c]}set(e,n,r,i,s,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let h=0;h<16;h++,n+=4)Si[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const d=Si[h-15],u=Si[h-2],b=Kn(d,7)^Kn(d,18)^d>>>3,w=Kn(u,17)^Kn(u,19)^u>>>10;Si[h]=w+Si[h-7]+b+Si[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const d=Kn(a,6)^Kn(a,11)^Kn(a,25),u=l+d+FO(a,c,f)+aD[h]+Si[h]|0,w=(Kn(r,2)^Kn(r,13)^Kn(r,22))+kO(r,i,s)|0;l=f,f=c,c=a,a=o+u|0,o=s,s=i,i=r,r=u+w|0}r=r+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,f=f+this.G|0,l=l+this.H|0,this.set(r,i,s,o,a,c,f,l)}roundClean(){_i(Si)}destroy(){this.set(0,0,0,0,0,0,0,0),_i(this.buffer)}}const pw=sw(["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))),fD=pw[0],uD=pw[1],Ii=new Uint32Array(80),Bi=new Uint32Array(80);class gw extends rw{constructor(e=64){super(128,e,16,!1),this.Ah=wt[0]|0,this.Al=wt[1]|0,this.Bh=wt[2]|0,this.Bl=wt[3]|0,this.Ch=wt[4]|0,this.Cl=wt[5]|0,this.Dh=wt[6]|0,this.Dl=wt[7]|0,this.Eh=wt[8]|0,this.El=wt[9]|0,this.Fh=wt[10]|0,this.Fl=wt[11]|0,this.Gh=wt[12]|0,this.Gl=wt[13]|0,this.Hh=wt[14]|0,this.Hl=wt[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:h,Fl:d,Gh:u,Gl:b,Hh:w,Hl:E}=this;return[e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E]}set(e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=h|0,this.Fl=d|0,this.Gh=u|0,this.Gl=b|0,this.Hh=w|0,this.Hl=E|0}process(e,n){for(let _=0;_<16;_++,n+=4)Ii[_]=e.getUint32(n),Bi[_]=e.getUint32(n+=4);for(let _=16;_<80;_++){const x=Ii[_-15]|0,D=Bi[_-15]|0,U=ho(x,D,1)^ho(x,D,8)^ow(x,D,7),C=po(x,D,1)^po(x,D,8)^aw(x,D,7),L=Ii[_-2]|0,O=Bi[_-2]|0,M=ho(L,O,19)^Bf(L,O,61)^ow(L,O,6),q=po(L,O,19)^$f(L,O,61)^aw(L,O,6),y=GO(C,q,Bi[_-7],Bi[_-16]),p=ZO(y,U,M,Ii[_-7],Ii[_-16]);Ii[_]=p|0,Bi[_]=y|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:h,El:d,Fh:u,Fl:b,Gh:w,Gl:E,Hh:A,Hl:P}=this;for(let _=0;_<80;_++){const x=ho(h,d,14)^ho(h,d,18)^Bf(h,d,41),D=po(h,d,14)^po(h,d,18)^$f(h,d,41),U=h&u^~h&w,C=d&b^~d&E,L=WO(P,D,C,uD[_],Bi[_]),O=YO(L,A,x,U,fD[_],Ii[_]),M=L|0,q=ho(r,i,28)^Bf(r,i,34)^Bf(r,i,39),y=po(r,i,28)^$f(r,i,34)^$f(r,i,39),p=r&s^r&a^s&a,m=i&o^i&c^o&c;A=w|0,P=E|0,w=u|0,E=b|0,u=h|0,b=d|0,{h,l:d}=xr(f|0,l|0,O|0,M|0),f=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=VO(M,y,m);r=KO(g,O,q,p),i=g|0}({h:r,l:i}=xr(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=xr(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=xr(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=xr(this.Dh|0,this.Dl|0,f|0,l|0),{h,l:d}=xr(this.Eh|0,this.El|0,h|0,d|0),{h:u,l:b}=xr(this.Fh|0,this.Fl|0,u|0,b|0),{h:w,l:E}=xr(this.Gh|0,this.Gl|0,w|0,E|0),{h:A,l:P}=xr(this.Hh|0,this.Hl|0,A|0,P|0),this.set(r,i,s,o,a,c,f,l,h,d,u,b,w,E,A,P)}roundClean(){_i(Ii,Bi)}destroy(){_i(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class lD extends gw{constructor(){super(48),this.Ah=yt[0]|0,this.Al=yt[1]|0,this.Bh=yt[2]|0,this.Bl=yt[3]|0,this.Ch=yt[4]|0,this.Cl=yt[5]|0,this.Dh=yt[6]|0,this.Dl=yt[7]|0,this.Eh=yt[8]|0,this.El=yt[9]|0,this.Fh=yt[10]|0,this.Fl=yt[11]|0,this.Gh=yt[12]|0,this.Gl=yt[13]|0,this.Hh=yt[14]|0,this.Hl=yt[15]|0}}const Af=Sf(()=>new cD),hD=Sf(()=>new gw),dD=Sf(()=>new lD);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const cd=BigInt(0),Of=BigInt(1);function xa(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function $i(t){if(!xa(t))throw new Error("Uint8Array expected")}function _a(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function Df(t){const e=t.toString(16);return e.length&1?"0"+e:e}function bw(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?cd:BigInt("0x"+t)}const yw=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",pD=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ys(t){if($i(t),yw)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=pD[t[n]];return e}const _r={_0:48,_9:57,A:65,F:70,a:97,f:102};function ww(t){if(t>=_r._0&&t<=_r._9)return t-_r._0;if(t>=_r.A&&t<=_r.F)return t-(_r.A-10);if(t>=_r.a&&t<=_r.f)return t-(_r.a-10)}function Pf(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(yw)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=ww(t.charCodeAt(s)),a=ww(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)}r[i]=o*16+a}return r}function Rt(t){return bw(ys(t))}function mw(t){return $i(t),bw(ys(Uint8Array.from(t).reverse()))}function qe(t,e){return Pf(t.toString(16).padStart(e*2,"0"))}function vw(t,e){return qe(t,e).reverse()}function mt(t,e,n){let r;if(typeof e=="string")try{r=Pf(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(xa(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}function Re(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];$i(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}function fd(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}const ud=t=>typeof t=="bigint"&&cd<=t;function ld(t,e,n){return ud(t)&&ud(e)&&ud(n)&&e<=t&&t<n}function go(t,e,n,r){if(!ld(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Sa(t){let e;for(e=0;t>cd;t>>=Of,e+=1);return e}function gD(t,e){return t>>BigInt(e)&Of}const ws=t=>(Of<<BigInt(t))-Of,hd=t=>new Uint8Array(t),Ew=t=>Uint8Array.from(t);function bD(t,e,n){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 n!="function")throw new Error("hmacFn must be a function");let r=hd(t),i=hd(t),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},a=(...h)=>n(i,r,...h),c=(h=hd(0))=>{i=a(Ew([0]),h),r=a(),h.length!==0&&(i=a(Ew([1]),h),r=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const d=[];for(;h<e;){r=a();const u=r.slice();d.push(u),h+=r.length}return Re(...d)};return(h,d)=>{o(),c(h);let u;for(;!(u=d(f()));)c();return o(),u}}const yD={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"||xa(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 Ia(t,e,n={}){const r=(i,s,o)=>{const a=yD[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))r(i,s,!1);for(const[i,s]of Object.entries(n))r(i,s,!0);return t}const xw=()=>{throw new Error("not implemented")};function dd(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}function wD(t,e){if(Aw(t)>e)throw new qD({givenSize:Aw(t),maxSize:e})}const Sr={zero:48,nine:57,A:65,F:70,a:97,f:102};function _w(t){if(t>=Sr.zero&&t<=Sr.nine)return t-Sr.zero;if(t>=Sr.A&&t<=Sr.F)return t-(Sr.A-10);if(t>=Sr.a&&t<=Sr.f)return t-(Sr.a-10)}function mD(t,e={}){const{dir:n,size:r=32}=e;if(r===0)return t;if(t.length>r)throw new jD({size:t.length,targetSize:r,type:"Bytes"});const i=new Uint8Array(r);for(let s=0;s<r;s++){const o=n==="right";i[o?s:r-s-1]=t[o?s:t.length-s-1]}return i}function pd(t,e){if(Br(t)>e)throw new DD({givenSize:Br(t),maxSize:e})}function vD(t,e){if(typeof e=="number"&&e>0&&e>Br(t)-1)throw new $w({offset:e,position:"start",size:Br(t)})}function ED(t,e,n){if(typeof e=="number"&&typeof n=="number"&&Br(t)!==n-e)throw new $w({offset:n,position:"end",size:Br(t)})}function Sw(t,e={}){const{dir:n,size:r=32}=e;if(r===0)return t;const i=t.replace("0x","");if(i.length>r*2)throw new PD({size:Math.ceil(i.length/2),targetSize:r,type:"Hex"});return`0x${i[n==="right"?"padEnd":"padStart"](r*2,"0")}`}const xD="#__bigint";function gd(t,e,n){return JSON.stringify(t,(r,i)=>typeof e=="function"?e(r,i):typeof i=="bigint"?i.toString()+xD:i,n)}const _D=new TextEncoder,SD=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ID(t,e={}){const{strict:n=!1}=e;if(!t)throw new Iw(t);if(typeof t!="string")throw new Iw(t);if(n&&!/^0x[0-9a-fA-F]*$/.test(t))throw new Bw(t);if(!t.startsWith("0x"))throw new Bw(t)}function bd(...t){return`0x${t.reduce((e,n)=>e+n.replace("0x",""),"")}`}function yd(t){return t instanceof Uint8Array?Ba(t):Array.isArray(t)?Ba(new Uint8Array(t)):t}function BD(t,e={}){const n=`0x${Number(t)}`;return typeof e.size=="number"?(pd(n,e.size),Tf(n,e.size)):n}function Ba(t,e={}){let n="";for(let i=0;i<t.length;i++)n+=SD[t[i]];const r=`0x${n}`;return typeof e.size=="number"?(pd(r,e.size),wd(r,e.size)):r}function Rf(t,e={}){const{signed:n,size:r}=e,i=BigInt(t);let s;r?n?s=(1n<<BigInt(r)*8n-1n)-1n:s=2n**(BigInt(r)*8n)-1n:typeof t=="number"&&(s=BigInt(Number.MAX_SAFE_INTEGER));const o=typeof s=="bigint"&&n?-s-1n:0;if(s&&i>s||i<o){const f=typeof t=="bigint"?"n":"";throw new OD({max:s?`${s}${f}`:void 0,min:`${o}${f}`,signed:n,size:r,value:`${t}${f}`})}const c=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?Tf(c,r):c}function $D(t,e={}){return Ba(_D.encode(t),e)}function Tf(t,e){return Sw(t,{dir:"left",size:e})}function wd(t,e){return Sw(t,{dir:"right",size:e})}function Ir(t,e,n,r={}){const{strict:i}=r;vD(t,e);const s=`0x${t.replace("0x","").slice((e??0)*2,(n??t.length)*2)}`;return i&&ED(s,e,n),s}function Br(t){return Math.ceil((t.length-2)/2)}function AD(t,e={}){const{strict:n=!1}=e;try{return ID(t,{strict:n}),!0}catch{return!1}}class OD extends Se{constructor({max:e,min:n,signed:r,size:i,value:s}){super(`Number \`${s}\` is not in safe${i?` ${i*8}-bit`:""}${r?" signed":" unsigned"} integer range ${e?`(\`${n}\` to \`${e}\`)`:`(above \`${n}\`)`}`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.IntegerOutOfRangeError"})}}class Iw extends Se{constructor(e){super(`Value \`${typeof e=="object"?gd(e):e}\` of type \`${typeof e}\` is an invalid hex type.`,{metaMessages:['Hex types must be represented as `"0x${string}"`.']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexTypeError"})}}class Bw extends Se{constructor(e){super(`Value \`${e}\` is an invalid hex value.`,{metaMessages:['Hex values must start with `"0x"` and contain only hexadecimal characters (0-9, a-f, A-F).']}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.InvalidHexValueError"})}}class DD extends Se{constructor({givenSize:e,maxSize:n}){super(`Size cannot exceed \`${n}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeOverflowError"})}}class $w extends Se{constructor({offset:e,position:n,size:r}){super(`Slice ${n==="start"?"starting":"ending"} at offset \`${e}\` is out-of-bounds (size: \`${r}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SliceOffsetOutOfBoundsError"})}}class PD extends Se{constructor({size:e,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Hex.SizeExceedsPaddingSizeError"})}}const RD=new TextEncoder;function TD(t){if(!(t instanceof Uint8Array)){if(!t)throw new Nf(t);if(typeof t!="object")throw new Nf(t);if(!("BYTES_PER_ELEMENT"in t))throw new Nf(t);if(t.BYTES_PER_ELEMENT!==1||t.constructor.name!=="Uint8Array")throw new Nf(t)}}function ND(t){return t instanceof Uint8Array?t:typeof t=="string"?CD(t):UD(t)}function UD(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function CD(t,e={}){const{size:n}=e;let r=t;n&&(pd(t,n),r=wd(t,n));let i=r.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 f=_w(i.charCodeAt(c++)),l=_w(i.charCodeAt(c++));if(f===void 0||l===void 0)throw new Se(`Invalid byte sequence ("${i[c-2]}${i[c-1]}" in "${i}").`);o[a]=f*16+l}return o}function LD(t,e={}){const{size:n}=e,r=RD.encode(t);return typeof n=="number"?(wD(r,n),FD(r,n)):r}function FD(t,e){return mD(t,{dir:"right",size:e})}function Aw(t){return t.length}function kD(t){try{return TD(t),!0}catch{return!1}}class Nf extends Se{constructor(e){super(`Value \`${typeof e=="object"?gd(e):e}\` of type \`${typeof e}\` is an invalid Bytes value.`,{metaMessages:["Bytes values must be of type `Bytes`."]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.InvalidBytesTypeError"})}}class qD extends Se{constructor({givenSize:e,maxSize:n}){super(`Size cannot exceed \`${n}\` bytes. Given size: \`${e}\` bytes.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeOverflowError"})}}class jD extends Se{constructor({size:e,targetSize:n,type:r}){super(`${r.charAt(0).toUpperCase()}${r.slice(1).toLowerCase()} size (\`${e}\`) exceeds padding size (\`${n}\`).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Bytes.SizeExceedsPaddingSizeError"})}}function Ow(t,e={}){const{as:n=typeof t=="string"?"Hex":"Bytes"}=e,r=oD(ND(t));return n==="Bytes"?r:Ba(r)}class MD extends Map{constructor(e){super(),Object.defineProperty(this,"maxSize",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.maxSize=e}get(e){const n=super.get(e);return super.has(e)&&n!==void 0&&(this.delete(e),super.set(e,n)),n}set(e,n){if(super.set(e,n),this.maxSize&&this.size>this.maxSize){const r=this.keys().next().value;r&&this.delete(r)}return this}}const md={checksum:new MD(8192)}.checksum;function Dw(t,e={}){const{compressed:n}=e,{prefix:r,x:i,y:s}=t;if(n===!1||typeof i=="bigint"&&typeof s=="bigint"){if(r!==4)throw new Rw({prefix:r,cause:new ZD});return}if(n===!0||typeof i=="bigint"&&typeof s>"u"){if(r!==3&&r!==2)throw new Rw({prefix:r,cause:new GD});return}throw new KD({publicKey:t})}function zD(t){const e=(()=>{if(AD(t))return Pw(t);if(kD(t))return HD(t);const{prefix:n,x:r,y:i}=t;return typeof r=="bigint"&&typeof i=="bigint"?{prefix:n??4,x:r,y:i}:{prefix:n,x:r}})();return Dw(e),e}function HD(t){return Pw(Ba(t))}function Pw(t){if(t.length!==132&&t.length!==130&&t.length!==68)throw new WD({publicKey:t});if(t.length===130){const r=BigInt(Ir(t,0,32)),i=BigInt(Ir(t,32,64));return{prefix:4,x:r,y:i}}if(t.length===132){const r=Number(Ir(t,0,1)),i=BigInt(Ir(t,1,33)),s=BigInt(Ir(t,33,65));return{prefix:r,x:i,y:s}}const e=Number(Ir(t,0,1)),n=BigInt(Ir(t,1,33));return{prefix:e,x:n}}function VD(t,e={}){Dw(t);const{prefix:n,x:r,y:i}=t,{includePrefix:s=!0}=e;return bd(s?Rf(n,{size:1}):"0x",Rf(r,{size:32}),typeof i=="bigint"?Rf(i,{size:32}):"0x")}class KD extends Se{constructor({publicKey:e}){super(`Value \`${gd(e)}\` is not a valid public key.`,{metaMessages:["Public key must contain:","- an `x` and `prefix` value (compressed)","- an `x`, `y`, and `prefix` value (uncompressed)"]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidError"})}}class Rw extends Se{constructor({prefix:e,cause:n}){super(`Prefix "${e}" is invalid.`,{cause:n}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidPrefixError"})}}class GD extends Se{constructor(){super("Prefix must be 2 or 3 for compressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidCompressedPrefixError"})}}class ZD extends Se{constructor(){super("Prefix must be 4 for uncompressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidUncompressedPrefixError"})}}class WD extends Se{constructor({publicKey:e}){super(`Value \`${e}\` is an invalid public key size.`,{metaMessages:["Expected: 33 bytes (compressed + prefix), 64 bytes (uncompressed) or 65 bytes (uncompressed + prefix).",`Received ${Br(yd(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidSerializedSizeError"})}}const YD=/^0x[a-fA-F0-9]{40}$/;function vd(t,e={}){const{strict:n=!0}=e;if(!YD.test(t))throw new Nw({address:t,cause:new QD});if(n){if(t.toLowerCase()===t)return;if(Tw(t)!==t)throw new Nw({address:t,cause:new eP})}}function Tw(t){if(md.has(t))return md.get(t);vd(t,{strict:!1});const e=t.substring(2).toLowerCase(),n=Ow(LD(e),{as:"Bytes"}),r=e.split("");for(let s=0;s<40;s+=2)n[s>>1]>>4>=8&&r[s]&&(r[s]=r[s].toUpperCase()),(n[s>>1]&15)>=8&&r[s+1]&&(r[s+1]=r[s+1].toUpperCase());const i=`0x${r.join("")}`;return md.set(t,i),i}function XD(t,e={}){const{checksum:n=!1}=e;return vd(t),n?Tw(t):t}function JD(t,e={}){const n=Ow(`0x${VD(t).slice(4)}`).substring(26);return XD(`0x${n}`,e)}class Nw extends Se{constructor({address:e,cause:n}){super(`Address "${e}" is invalid.`,{cause:n}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidAddressError"})}}class QD extends Se{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 eP extends Se{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}const tP=/^(.*)\[([0-9]*)\]$/,nP=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,rP=/^(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 Ed(t,e){if(t.length!==e.length)throw new sP({expectedLength:t.length,givenLength:e.length});const n=[];for(let r=0;r<t.length;r++){const i=t[r],s=e[r];n.push(Ed.encode(i,s))}return bd(...n)}(function(t){function e(n,r,i=!1){if(n==="address"){const c=r;return vd(c),Tf(c.toLowerCase(),i?32:0)}if(n==="string")return $D(r);if(n==="bytes")return r;if(n==="bool")return Tf(BD(r),i?32:1);const s=n.match(rP);if(s){const[c,f,l="256"]=s,h=Number.parseInt(l,10)/8;return Rf(r,{size:i?32:h,signed:f==="int"})}const o=n.match(nP);if(o){const[c,f]=o;if(Number.parseInt(f,10)!==(r.length-2)/2)throw new iP({expectedSize:Number.parseInt(f,10),value:r});return wd(r,i?32:0)}const a=n.match(tP);if(a&&Array.isArray(r)){const[c,f]=a,l=[];for(let h=0;h<r.length;h++)l.push(e(f,r[h],!0));return l.length===0?"0x":bd(...l)}throw new oP(n)}t.encode=e})(Ed||(Ed={}));class iP extends Se{constructor({expectedSize:e,value:n}){super(`Size of bytes "${n}" (bytes${Br(n)}) does not match expected size (bytes${e}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class sP extends Se{constructor({expectedLength:e,givenLength:n}){super(["ABI encoding parameters/values length mismatch.",`Expected length (parameters): ${e}`,`Given length (values): ${n}`].join(`
20
+ `)),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.LengthMismatchError"})}}class oP extends Se{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 Uw extends od{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,DO(e);const r=_f(n);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(r.length>i?e.create().update(r).digest():r);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),_i(s)}update(e){return lo(this),this.iHash.update(e),this}digestInto(e){lo(this),bs(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:n,iHash:r,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=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const Cw=(t,e,n)=>new Uw(t,e).update(n).digest();Cw.create=(t,e)=>new Uw(t,e);const Zt=BigInt(0),Tt=BigInt(1),ms=BigInt(2),aP=BigInt(3),Lw=BigInt(4),Fw=BigInt(5),kw=BigInt(8);function Nt(t,e){const n=t%e;return n>=Zt?n:e+n}function gn(t,e,n){let r=t;for(;e-- >Zt;)r*=r,r%=n;return r}function xd(t,e){if(t===Zt)throw new Error("invert: expected non-zero number");if(e<=Zt)throw new Error("invert: expected positive modulus, got "+e);let n=Nt(t,e),r=e,i=Zt,s=Tt;for(;n!==Zt;){const a=r/n,c=r%n,f=i-s*a;r=n,n=c,i=s,s=f}if(r!==Tt)throw new Error("invert: does not exist");return Nt(i,e)}function qw(t,e){const n=(t.ORDER+Tt)/Lw,r=t.pow(e,n);if(!t.eql(t.sqr(r),e))throw new Error("Cannot find square root");return r}function cP(t,e){const n=(t.ORDER-Fw)/kw,r=t.mul(e,ms),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,ms),i),a=t.mul(s,t.sub(o,t.ONE));if(!t.eql(t.sqr(a),e))throw new Error("Cannot find square root");return a}function fP(t){if(t<BigInt(3))throw new Error("sqrt is not defined for small field");let e=t-Tt,n=0;for(;e%ms===Zt;)e/=ms,n++;let r=ms;const i=Ai(t);for(;Cf(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return qw;let s=i.pow(r,e);const o=(e+Tt)/ms;return function(c,f){if(c.is0(f))return f;if(Cf(c,f)!==1)throw new Error("Cannot find square root");let l=n,h=c.mul(c.ONE,s),d=c.pow(f,e),u=c.pow(f,o);for(;!c.eql(d,c.ONE);){if(c.is0(d))return c.ZERO;let b=1,w=c.sqr(d);for(;!c.eql(w,c.ONE);)if(b++,w=c.sqr(w),b===l)throw new Error("Cannot find square root");const E=Tt<<BigInt(l-b-1),A=c.pow(h,E);l=b,h=c.sqr(A),d=c.mul(d,h),u=c.mul(u,A)}return u}}function uP(t){return t%Lw===aP?qw:t%kw===Fw?cP:fP(t)}const lP=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function jw(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=lP.reduce((r,i)=>(r[i]="function",r),e);return Ia(t,n)}function Uf(t,e,n){if(n<Zt)throw new Error("invalid exponent, negatives unsupported");if(n===Zt)return t.ONE;if(n===Tt)return e;let r=t.ONE,i=e;for(;n>Zt;)n&Tt&&(r=t.mul(r,i)),i=t.sqr(i),n>>=Tt;return r}function vs(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),i=e.reduce((o,a,c)=>t.is0(a)?o:(r[c]=o,t.mul(o,a)),t.ONE),s=t.inv(i);return e.reduceRight((o,a,c)=>t.is0(a)?o:(r[c]=t.mul(o,r[c]),t.mul(o,a)),s),r}function Cf(t,e){const n=(t.ORDER-Tt)/ms,r=t.pow(e,n),i=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),o=t.eql(r,t.neg(t.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function Mw(t,e){e!==void 0&&va(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Ai(t,e,n=!1,r={}){if(t<=Zt)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=Mw(t,e);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let o;const a=Object.freeze({ORDER:t,isLE:n,BITS:i,BYTES:s,MASK:ws(i),ZERO:Zt,ONE:Tt,create:c=>Nt(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return Zt<=c&&c<t},is0:c=>c===Zt,isOdd:c=>(c&Tt)===Tt,neg:c=>Nt(-c,t),eql:(c,f)=>c===f,sqr:c=>Nt(c*c,t),add:(c,f)=>Nt(c+f,t),sub:(c,f)=>Nt(c-f,t),mul:(c,f)=>Nt(c*f,t),pow:(c,f)=>Uf(a,c,f),div:(c,f)=>Nt(c*xd(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>xd(c,t),sqrt:r.sqrt||(c=>(o||(o=uP(t)),o(a,c))),toBytes:c=>n?vw(c,s):qe(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return n?mw(c):Rt(c)},invertBatch:c=>vs(a,c),cmov:(c,f,l)=>l?f:c});return Object.freeze(a)}function zw(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 _d(t){const e=zw(t);return e+Math.ceil(e/2)}function Hw(t,e,n=!1){const r=t.length,i=zw(e),s=_d(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?mw(t):Rt(t),a=Nt(o,e-Tt)+Tt;return n?vw(a,i):qe(a,i)}const Vw=BigInt(0),Sd=BigInt(1);function Id(t,e){const n=e.negate();return t?n:e}function Kw(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Bd(t,e){Kw(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=ws(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function Gw(t,e,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(t&i),c=t>>o;a>r&&(a-=s,c+=Sd);const f=e*r,l=f+Math.abs(a)-1,h=a===0,d=a<0,u=e%2!==0;return{nextN:c,offset:l,isZero:h,isNeg:d,isNegF:u,offsetF:f}}function hP(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function dP(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const $d=new WeakMap,Zw=new WeakMap;function Ad(t){return Zw.get(t)||1}function pP(t,e){return{constTimeNegate:Id,hasPrecomputes(n){return Ad(n)!==1},unsafeLadder(n,r,i=t.ZERO){let s=n;for(;r>Vw;)r&Sd&&(i=i.add(s)),s=s.double(),r>>=Sd;return i},precomputeWindow(n,r){const{windows:i,windowSize:s}=Bd(r,e),o=[];let a=n,c=a;for(let f=0;f<i;f++){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(n,r,i){let s=t.ZERO,o=t.BASE;const a=Bd(n,e);for(let c=0;c<a.windows;c++){const{nextN:f,offset:l,isZero:h,isNeg:d,isNegF:u,offsetF:b}=Gw(i,c,a);i=f,h?o=o.add(Id(u,r[b])):s=s.add(Id(d,r[l]))}return{p:s,f:o}},wNAFUnsafe(n,r,i,s=t.ZERO){const o=Bd(n,e);for(let a=0;a<o.windows&&i!==Vw;a++){const{nextN:c,offset:f,isZero:l,isNeg:h}=Gw(i,a,o);if(i=c,!l){const d=r[f];s=s.add(h?d.negate():d)}}return s},getPrecomputes(n,r,i){let s=$d.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&$d.set(r,i(s))),s},wNAFCached(n,r,i){const s=Ad(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=Ad(n);return o===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,n,i),r,s)},setWindowSize(n,r){Kw(r,e),Zw.set(n,r),$d.delete(n)}}}function gP(t,e,n,r){hP(n,t),dP(r,e);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,a=Sa(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=ws(c),l=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let d=o;for(let u=h;u>=0;u-=c){l.fill(o);for(let w=0;w<s;w++){const E=r[w],A=Number(E>>BigInt(u)&f);l[A]=l[A].add(n[w])}let b=o;for(let w=l.length-1,E=o;w>0;w--)E=E.add(l[w]),b=b.add(E);if(d=d.add(b),u!==0)for(let w=0;w<c;w++)d=d.double()}return d}function Ww(t){return jw(t.Fp),Ia(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Mw(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function Yw(t){t.lowS!==void 0&&_a("lowS",t.lowS),t.prehash!==void 0&&_a("prehash",t.prehash)}function bP(t){const e=Ww(t);Ia(e,{a:"field",b:"field"},{allowInfinityPoint:"boolean",allowedPrivateKeyLengths:"array",clearCofactor:"function",fromBytes:"function",isTorsionFree:"function",toBytes:"function",wrapPrivateKey:"boolean"});const{endo:n,Fp:r,a:i}=e;if(n){if(!r.eql(i,r.ZERO))throw new Error("invalid endo: CURVE.a must be 0");if(typeof n!="object"||typeof n.beta!="bigint"||typeof n.splitScalar!="function")throw new Error('invalid endo: expected "beta": bigint and "splitScalar": function')}return Object.freeze({...e})}class yP extends Error{constructor(e=""){super(e)}}const $r={Err:yP,_tlv:{encode:(t,e)=>{const{Err:n}=$r;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");const r=e.length/2,i=Df(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?Df(i.length/2|128):"";return Df(t)+s+i+e},decode(t,e){const{Err:n}=$r;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const f=e.subarray(r,r+c);if(f.length!==c)throw new n("tlv.decode: length bytes not complete");if(f[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of f)o=o<<8|l;if(r+=c,o<128)throw new n("tlv.decode(long): not minimal encoding")}const a=e.subarray(r,r+o);if(a.length!==o)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(t){const{Err:e}=$r;if(t<Pn)throw new e("integer: negative integers are not allowed");let n=Df(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=$r;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 Rt(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=$r,i=mt("signature",t),{v:s,l:o}=r.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,s),{v:f,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(f)}},hexFromSig(t){const{_tlv:e,_int:n}=$r,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}};function Od(t,e){return ys(qe(t,e))}const Pn=BigInt(0),Ee=BigInt(1),Oi=BigInt(2),$a=BigInt(3),Dd=BigInt(4);function Pd(t){const e=bP(t),{Fp:n}=e,r=Ai(e.n,e.nBitLength),i=e.toBytes||((_,x,D)=>{const U=x.toAffine();return Re(Uint8Array.from([4]),n.toBytes(U.x),n.toBytes(U.y))}),s=e.fromBytes||(_=>{const x=_.subarray(1),D=n.fromBytes(x.subarray(0,n.BYTES)),U=n.fromBytes(x.subarray(n.BYTES,2*n.BYTES));return{x:D,y:U}});function o(_){const{a:x,b:D}=e,U=n.sqr(_),C=n.mul(U,_);return n.add(n.add(C,n.mul(_,x)),D)}function a(_,x){const D=n.sqr(x),U=o(_);return n.eql(D,U)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const c=n.mul(n.pow(e.a,$a),Dd),f=n.mul(n.sqr(e.b),BigInt(27));if(n.is0(n.add(c,f)))throw new Error("bad curve params: a or b");function l(_){return ld(_,Ee,e.n)}function h(_){const{allowedPrivateKeyLengths:x,nByteLength:D,wrapPrivateKey:U,n:C}=e;if(x&&typeof _!="bigint"){if(xa(_)&&(_=ys(_)),typeof _!="string"||!x.includes(_.length))throw new Error("invalid private key");_=_.padStart(D*2,"0")}let L;try{L=typeof _=="bigint"?_:Rt(mt("private key",_,D))}catch{throw new Error("invalid private key, expected hex or "+D+" bytes, got "+typeof _)}return U&&(L=Nt(L,C)),go("private key",L,Ee,C),L}function d(_){if(!(_ instanceof w))throw new Error("ProjectivePoint expected")}const u=dd((_,x)=>{const{px:D,py:U,pz:C}=_;if(n.eql(C,n.ONE))return{x:D,y:U};const L=_.is0();x==null&&(x=L?n.ONE:n.inv(C));const O=n.mul(D,x),M=n.mul(U,x),q=n.mul(C,x);if(L)return{x:n.ZERO,y:n.ZERO};if(!n.eql(q,n.ONE))throw new Error("invZ was invalid");return{x:O,y:M}}),b=dd(_=>{if(_.is0()){if(e.allowInfinityPoint&&!n.is0(_.py))return;throw new Error("bad point: ZERO")}const{x,y:D}=_.toAffine();if(!n.isValid(x)||!n.isValid(D))throw new Error("bad point: x or y not FE");if(!a(x,D))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class w{constructor(x,D,U){if(x==null||!n.isValid(x))throw new Error("x required");if(D==null||!n.isValid(D)||n.is0(D))throw new Error("y required");if(U==null||!n.isValid(U))throw new Error("z required");this.px=x,this.py=D,this.pz=U,Object.freeze(this)}static fromAffine(x){const{x:D,y:U}=x||{};if(!x||!n.isValid(D)||!n.isValid(U))throw new Error("invalid affine point");if(x instanceof w)throw new Error("projective point not allowed");const C=L=>n.eql(L,n.ZERO);return C(D)&&C(U)?w.ZERO:new w(D,U,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){const D=vs(n,x.map(U=>U.pz));return x.map((U,C)=>U.toAffine(D[C])).map(w.fromAffine)}static fromHex(x){const D=w.fromAffine(s(mt("pointHex",x)));return D.assertValidity(),D}static fromPrivateKey(x){return w.BASE.multiply(h(x))}static msm(x,D){return gP(w,r,x,D)}_setWindowSize(x){P.setWindowSize(this,x)}assertValidity(){b(this)}hasEvenY(){const{y:x}=this.toAffine();if(n.isOdd)return!n.isOdd(x);throw new Error("Field doesn't support isOdd")}equals(x){d(x);const{px:D,py:U,pz:C}=this,{px:L,py:O,pz:M}=x,q=n.eql(n.mul(D,M),n.mul(L,C)),y=n.eql(n.mul(U,M),n.mul(O,C));return q&&y}negate(){return new w(this.px,n.neg(this.py),this.pz)}double(){const{a:x,b:D}=e,U=n.mul(D,$a),{px:C,py:L,pz:O}=this;let M=n.ZERO,q=n.ZERO,y=n.ZERO,p=n.mul(C,C),m=n.mul(L,L),g=n.mul(O,O),v=n.mul(C,L);return v=n.add(v,v),y=n.mul(C,O),y=n.add(y,y),M=n.mul(x,y),q=n.mul(U,g),q=n.add(M,q),M=n.sub(m,q),q=n.add(m,q),q=n.mul(M,q),M=n.mul(v,M),y=n.mul(U,y),g=n.mul(x,g),v=n.sub(p,g),v=n.mul(x,v),v=n.add(v,y),y=n.add(p,p),p=n.add(y,p),p=n.add(p,g),p=n.mul(p,v),q=n.add(q,p),g=n.mul(L,O),g=n.add(g,g),p=n.mul(g,v),M=n.sub(M,p),y=n.mul(g,m),y=n.add(y,y),y=n.add(y,y),new w(M,q,y)}add(x){d(x);const{px:D,py:U,pz:C}=this,{px:L,py:O,pz:M}=x;let q=n.ZERO,y=n.ZERO,p=n.ZERO;const m=e.a,g=n.mul(e.b,$a);let v=n.mul(D,L),S=n.mul(U,O),B=n.mul(C,M),I=n.add(D,U),$=n.add(L,O);I=n.mul(I,$),$=n.add(v,S),I=n.sub(I,$),$=n.add(D,C);let T=n.add(L,M);return $=n.mul($,T),T=n.add(v,B),$=n.sub($,T),T=n.add(U,C),q=n.add(O,M),T=n.mul(T,q),q=n.add(S,B),T=n.sub(T,q),p=n.mul(m,$),q=n.mul(g,B),p=n.add(q,p),q=n.sub(S,p),p=n.add(S,p),y=n.mul(q,p),S=n.add(v,v),S=n.add(S,v),B=n.mul(m,B),$=n.mul(g,$),S=n.add(S,B),B=n.sub(v,B),B=n.mul(m,B),$=n.add($,B),v=n.mul(S,$),y=n.add(y,v),v=n.mul(T,$),q=n.mul(I,q),q=n.sub(q,v),v=n.mul(I,S),p=n.mul(T,p),p=n.add(p,v),new w(q,y,p)}subtract(x){return this.add(x.negate())}is0(){return this.equals(w.ZERO)}wNAF(x){return P.wNAFCached(this,x,w.normalizeZ)}multiplyUnsafe(x){const{endo:D,n:U}=e;go("scalar",x,Pn,U);const C=w.ZERO;if(x===Pn)return C;if(this.is0()||x===Ee)return this;if(!D||P.hasPrecomputes(this))return P.wNAFCachedUnsafe(this,x,w.normalizeZ);let{k1neg:L,k1:O,k2neg:M,k2:q}=D.splitScalar(x),y=C,p=C,m=this;for(;O>Pn||q>Pn;)O&Ee&&(y=y.add(m)),q&Ee&&(p=p.add(m)),m=m.double(),O>>=Ee,q>>=Ee;return L&&(y=y.negate()),M&&(p=p.negate()),p=new w(n.mul(p.px,D.beta),p.py,p.pz),y.add(p)}multiply(x){const{endo:D,n:U}=e;go("scalar",x,Ee,U);let C,L;if(D){const{k1neg:O,k1:M,k2neg:q,k2:y}=D.splitScalar(x);let{p,f:m}=this.wNAF(M),{p:g,f:v}=this.wNAF(y);p=P.constTimeNegate(O,p),g=P.constTimeNegate(q,g),g=new w(n.mul(g.px,D.beta),g.py,g.pz),C=p.add(g),L=m.add(v)}else{const{p:O,f:M}=this.wNAF(x);C=O,L=M}return w.normalizeZ([C,L])[0]}multiplyAndAddUnsafe(x,D,U){const C=w.BASE,L=(M,q)=>q===Pn||q===Ee||!M.equals(C)?M.multiplyUnsafe(q):M.multiply(q),O=L(this,D).add(L(x,U));return O.is0()?void 0:O}toAffine(x){return u(this,x)}isTorsionFree(){const{h:x,isTorsionFree:D}=e;if(x===Ee)return!0;if(D)return D(w,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:x,clearCofactor:D}=e;return x===Ee?this:D?D(w,this):this.multiplyUnsafe(e.h)}toRawBytes(x=!0){return _a("isCompressed",x),this.assertValidity(),i(w,this,x)}toHex(x=!0){return _a("isCompressed",x),ys(this.toRawBytes(x))}}w.BASE=new w(e.Gx,e.Gy,n.ONE),w.ZERO=new w(n.ZERO,n.ONE,n.ZERO);const{endo:E,nBitLength:A}=e,P=pP(w,E?Math.ceil(A/2):A);return{CURVE:e,ProjectivePoint:w,normPrivateKeyToScalar:h,weierstrassEquation:o,isWithinCurveOrder:l}}function wP(t){const e=Ww(t);return Ia(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function mP(t){const e=wP(t),{Fp:n,n:r,nByteLength:i,nBitLength:s}=e,o=n.BYTES+1,a=2*n.BYTES+1;function c(g){return Nt(g,r)}function f(g){return xd(g,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:h,weierstrassEquation:d,isWithinCurveOrder:u}=Pd({...e,toBytes(g,v,S){const B=v.toAffine(),I=n.toBytes(B.x),$=Re;return _a("isCompressed",S),S?$(Uint8Array.from([v.hasEvenY()?2:3]),I):$(Uint8Array.from([4]),I,n.toBytes(B.y))},fromBytes(g){const v=g.length,S=g[0],B=g.subarray(1);if(v===o&&(S===2||S===3)){const I=Rt(B);if(!ld(I,Ee,n.ORDER))throw new Error("Point is not on curve");const $=d(I);let T;try{T=n.sqrt($)}catch(k){const R=k instanceof Error?": "+k.message:"";throw new Error("Point is not on curve"+R)}const F=(T&Ee)===Ee;return(S&1)===1!==F&&(T=n.neg(T)),{x:I,y:T}}else if(v===a&&S===4){const I=n.fromBytes(B.subarray(0,n.BYTES)),$=n.fromBytes(B.subarray(n.BYTES,2*n.BYTES));return{x:I,y:$}}else{const I=o,$=a;throw new Error("invalid Point, expected length of "+I+", or uncompressed "+$+", got "+v)}}});function b(g){const v=r>>Ee;return g>v}function w(g){return b(g)?c(-g):g}const E=(g,v,S)=>Rt(g.slice(v,S));class A{constructor(v,S,B){go("r",v,Ee,r),go("s",S,Ee,r),this.r=v,this.s=S,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(v){const S=i;return v=mt("compactSignature",v,S*2),new A(E(v,0,S),E(v,S,2*S))}static fromDER(v){const{r:S,s:B}=$r.toSig(mt("DER",v));return new A(S,B)}assertValidity(){}addRecoveryBit(v){return new A(this.r,this.s,v)}recoverPublicKey(v){const{r:S,s:B,recovery:I}=this,$=C(mt("msgHash",v));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");const T=I===2||I===3?S+e.n:S;if(T>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const F=(I&1)===0?"02":"03",N=l.fromHex(F+Od(T,n.BYTES)),k=f(T),R=c(-$*k),j=c(B*k),z=l.BASE.multiplyAndAddUnsafe(N,R,j);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return b(this.s)}normalizeS(){return this.hasHighS()?new A(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return Pf(this.toDERHex())}toDERHex(){return $r.hexFromSig(this)}toCompactRawBytes(){return Pf(this.toCompactHex())}toCompactHex(){const v=i;return Od(this.r,v)+Od(this.s,v)}}const P={isValidPrivateKey(g){try{return h(g),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const g=_d(e.n);return Hw(e.randomBytes(g),e.n)},precompute(g=8,v=l.BASE){return v._setWindowSize(g),v.multiply(BigInt(3)),v}};function _(g,v=!0){return l.fromPrivateKey(g).toRawBytes(v)}function x(g){if(typeof g=="bigint")return!1;if(g instanceof l)return!0;const S=mt("key",g).length,B=n.BYTES,I=B+1,$=2*B+1;if(!(e.allowedPrivateKeyLengths||i===I))return S===I||S===$}function D(g,v,S=!0){if(x(g)===!0)throw new Error("first arg must be private key");if(x(v)===!1)throw new Error("second arg must be public key");return l.fromHex(v).multiply(h(g)).toRawBytes(S)}const U=e.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");const v=Rt(g),S=g.length*8-s;return S>0?v>>BigInt(S):v},C=e.bits2int_modN||function(g){return c(U(g))},L=ws(s);function O(g){return go("num < 2^"+s,g,Pn,L),qe(g,i)}function M(g,v,S=q){if(["recovered","canonical"].some(H=>H in S))throw new Error("sign() legacy options not supported");const{hash:B,randomBytes:I}=e;let{lowS:$,prehash:T,extraEntropy:F}=S;$==null&&($=!0),g=mt("msgHash",g),Yw(S),T&&(g=mt("prehashed msgHash",B(g)));const N=C(g),k=h(v),R=[O(k),O(N)];if(F!=null&&F!==!1){const H=F===!0?I(n.BYTES):F;R.push(mt("extraEntropy",H))}const j=Re(...R),z=N;function V(H){const K=U(H);if(!u(K))return;const Y=f(K),X=l.BASE.multiply(K).toAffine(),ee=c(X.x);if(ee===Pn)return;const se=c(Y*c(z+ee*k));if(se===Pn)return;let oe=(X.x===ee?0:2)|Number(X.y&Ee),ot=se;return $&&b(se)&&(ot=w(se),oe^=1),new A(ee,ot,oe)}return{seed:j,k2sig:V}}const q={lowS:e.lowS,prehash:!1},y={lowS:e.lowS,prehash:!1};function p(g,v,S=q){const{seed:B,k2sig:I}=M(g,v,S),$=e;return bD($.hash.outputLen,$.nByteLength,$.hmac)(B,I)}l.BASE._setWindowSize(8);function m(g,v,S,B=y){const I=g;v=mt("msgHash",v),S=mt("publicKey",S);const{lowS:$,prehash:T,format:F}=B;if(Yw(B),"strict"in B)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 N=typeof I=="string"||xa(I),k=!N&&!F&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!N&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let R,j;try{if(k&&(R=new A(I.r,I.s)),N){try{F!=="compact"&&(R=A.fromDER(I))}catch(oe){if(!(oe instanceof $r.Err))throw oe}!R&&F!=="der"&&(R=A.fromCompact(I))}j=l.fromHex(S)}catch{return!1}if(!R||$&&R.hasHighS())return!1;T&&(v=e.hash(v));const{r:z,s:V}=R,H=C(v),K=f(V),Y=c(H*K),X=c(z*K),ee=l.BASE.multiplyAndAddUnsafe(j,Y,X)?.toAffine();return ee?c(ee.x)===z:!1}return{CURVE:e,getPublicKey:_,getSharedSecret:D,sign:p,verify:m,ProjectivePoint:l,Signature:A,utils:P}}function vP(t,e){const n=t.ORDER;let r=Pn;for(let b=n-Ee;b%Oi===Pn;b/=Oi)r+=Ee;const i=r,s=Oi<<i-Ee-Ee,o=s*Oi,a=(n-Ee)/o,c=(a-Ee)/Oi,f=o-Ee,l=s,h=t.pow(e,a),d=t.pow(e,(a+Ee)/Oi);let u=(b,w)=>{let E=h,A=t.pow(w,f),P=t.sqr(A);P=t.mul(P,w);let _=t.mul(b,P);_=t.pow(_,c),_=t.mul(_,A),A=t.mul(_,w),P=t.mul(_,b);let x=t.mul(P,A);_=t.pow(x,l);let D=t.eql(_,t.ONE);A=t.mul(P,d),_=t.mul(x,E),P=t.cmov(A,P,D),x=t.cmov(_,x,D);for(let U=i;U>Ee;U--){let C=U-Oi;C=Oi<<C-Ee;let L=t.pow(x,C);const O=t.eql(L,t.ONE);A=t.mul(P,E),E=t.mul(E,E),L=t.mul(x,E),P=t.cmov(A,P,O),x=t.cmov(L,x,O)}return{isValid:D,value:P}};if(t.ORDER%Dd===$a){const b=(t.ORDER-$a)/Dd,w=t.sqrt(t.neg(e));u=(E,A)=>{let P=t.sqr(A);const _=t.mul(E,A);P=t.mul(P,_);let x=t.pow(P,b);x=t.mul(x,_);const D=t.mul(x,w),U=t.mul(t.sqr(x),A),C=t.eql(U,E);let L=t.cmov(D,x,C);return{isValid:C,value:L}}}return u}function Xw(t,e){if(jw(t),!t.isValid(e.A)||!t.isValid(e.B)||!t.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=vP(t,e.Z);if(!t.isOdd)throw new Error("Fp.isOdd is not implemented!");return r=>{let i,s,o,a,c,f,l,h;i=t.sqr(r),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),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),l=t.mul(i,o);const{isValid:d,value:u}=n(s,f);h=t.mul(i,r),h=t.mul(h,u),l=t.cmov(l,o,d),h=t.cmov(h,u,d);const b=t.isOdd(r)===t.isOdd(h);h=t.cmov(t.neg(h),h,b);const w=vs(t,[a],!0)[0];return l=t.mul(l,w),{x:l,y:h}}}function EP(t){return{hash:t,hmac:(e,...n)=>Cw(t,e,CO(...n)),randomBytes:nw}}function Lf(t,e){const n=r=>mP({...t,...EP(r)});return{...n(e),create:n}}const xP=Rt;function Di(t,e){if(Aa(t),Aa(e),t<0||t>=1<<8*e)throw new Error("invalid I2OSP input: "+t);const n=Array.from({length:e}).fill(0);for(let r=e-1;r>=0;r--)n[r]=t&255,t>>>=8;return new Uint8Array(n)}function _P(t,e){const n=new Uint8Array(t.length);for(let r=0;r<t.length;r++)n[r]=t[r]^e[r];return n}function Aa(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function SP(t,e,n,r){$i(t),$i(e),Aa(n),e.length>255&&(e=r(Re(fd("H2C-OVERSIZE-DST-"),e)));const{outputLen:i,blockLen:s}=r,o=Math.ceil(n/i);if(n>65535||o>255)throw new Error("expand_message_xmd: invalid lenInBytes");const a=Re(e,Di(e.length,1)),c=Di(0,s),f=Di(n,2),l=new Array(o),h=r(Re(c,t,f,Di(0,1),a));l[0]=r(Re(h,Di(1,1),a));for(let u=1;u<=o;u++){const b=[_P(h,l[u-1]),Di(u+1,1),a];l[u]=r(Re(...b))}return Re(...l).slice(0,n)}function IP(t,e,n,r,i){if($i(t),$i(e),Aa(n),e.length>255){const s=Math.ceil(2*r/8);e=i.create({dkLen:s}).update(fd("H2C-OVERSIZE-DST-")).update(e).digest()}if(n>65535||e.length>255)throw new Error("expand_message_xof: invalid lenInBytes");return i.create({dkLen:n}).update(t).update(Di(n,2)).update(e).update(Di(e.length,1)).digest()}function Jw(t,e,n){Ia(n,{DST:"stringOrUint8Array",p:"bigint",m:"isSafeInteger",k:"isSafeInteger",hash:"hash"});const{p:r,k:i,m:s,hash:o,expand:a,DST:c}=n;$i(t),Aa(e);const f=typeof c=="string"?fd(c):c,l=r.toString(2).length,h=Math.ceil((l+i)/8),d=e*s*h;let u;if(a==="xmd")u=SP(t,f,d,o);else if(a==="xof")u=IP(t,f,d,i,o);else if(a==="_internal_pass")u=t;else throw new Error('expand must be "xmd" or "xof"');const b=new Array(e);for(let w=0;w<e;w++){const E=new Array(s);for(let A=0;A<s;A++){const P=h*(A+w*s),_=u.subarray(P,P+h);E[A]=Nt(xP(_),r)}b[w]=E}return b}function Qw(t,e){const n=e.map(r=>Array.from(r).reverse());return(r,i)=>{const[s,o,a,c]=n.map(h=>h.reduce((d,u)=>t.add(t.mul(d,r),u))),[f,l]=vs(t,[o,c],!0);return r=t.mul(s,f),i=t.mul(i,t.mul(a,l)),{x:r,y:i}}}function em(t,e,n){if(typeof e!="function")throw new Error("mapToCurve() must be defined");function r(s){return t.fromAffine(e(s))}function i(s){const o=s.clearCofactor();return o.equals(t.ZERO)?t.ZERO:(o.assertValidity(),o)}return{defaults:n,hashToCurve(s,o){const a=Jw(s,2,{...n,DST:n.DST,...o}),c=r(a[0]),f=r(a[1]);return i(c.add(f))},encodeToCurve(s,o){const a=Jw(s,1,{...n,DST:n.encodeDST,...o});return i(r(a[0]))},mapToCurve(s){if(!Array.isArray(s))throw new Error("expected array of bigints");for(const o of s)if(typeof o!="bigint")throw new Error("expected array of bigints");return i(r(s))}}}const tm=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),nm=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),BP=BigInt(0),$P=BigInt(1),Rd=BigInt(2),rm=(t,e)=>(t+e/Rd)/e;function AP(t){const e=tm,n=BigInt(3),r=BigInt(6),i=BigInt(11),s=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),f=t*t*t%e,l=f*f*t%e,h=gn(l,n,e)*l%e,d=gn(h,n,e)*l%e,u=gn(d,Rd,e)*f%e,b=gn(u,i,e)*u%e,w=gn(b,s,e)*b%e,E=gn(w,a,e)*w%e,A=gn(E,c,e)*E%e,P=gn(A,a,e)*w%e,_=gn(P,n,e)*l%e,x=gn(_,o,e)*b%e,D=gn(x,r,e)*f%e,U=gn(D,Rd,e);if(!Td.eql(Td.sqr(U),t))throw new Error("Cannot find square root");return U}const Td=Ai(tm,void 0,void 0,{sqrt:AP}),OP=Lf({a:BP,b:BigInt(7),Fp:Td,n:nm,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=nm,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-$P*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=rm(s*t,e),c=rm(-r*t,e);let f=Nt(t-a*n-c*i,e),l=Nt(-a*r-c*s,e);const h=f>o,d=l>o;if(h&&(f=e-f),d&&(l=e-l),f>o||l>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:h,k1:f,k2neg:d,k2:l}}}},Af);function DP(t){if(t.length!==130&&t.length!==132)throw new RP({signature:t});const e=BigInt(Ir(t,0,32)),n=BigInt(Ir(t,32,64)),r=(()=>{const i=+`0x${t.slice(130)}`;if(!Number.isNaN(i))try{return PP(i)}catch{throw new TP({value:i})}})();return typeof r>"u"?{r:e,s:n}:{r:e,s:n,yParity:r}}function PP(t){if(t===0||t===27)return 0;if(t===1||t===28)return 1;if(t>=35)return t%2===0?1:0;throw new NP({value:t})}class RP extends Se{constructor({signature:e}){super(`Value \`${e}\` is an invalid signature size.`,{metaMessages:["Expected: 64 bytes or 65 bytes.",`Received ${Br(yd(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSerializedSizeError"})}}class TP extends Se{constructor({value:e}){super(`Value \`${e}\` is an invalid y-parity value. Y-parity must be 0 or 1.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidYParityError"})}}class NP extends Se{constructor({value:e}){super(`Value \`${e}\` is an invalid v value. v must be 27, 28 or >=35.`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidVError"})}}Object.freeze({1:0n,2:1n,3:2n,4:3n,5:4n,6:5n,7:6n,8:7n,9:8n,A:9n,B:10n,C:11n,D:12n,E:13n,F:14n,G:15n,H:16n,J:17n,K:18n,L:19n,M:20n,N:21n,P:22n,Q:23n,R:24n,S:25n,T:26n,U:27n,V:28n,W:29n,X:30n,Y:31n,Z:32n,a:33n,b:34n,c:35n,d:36n,e:37n,f:38n,g:39n,h:40n,i:41n,j:42n,k:43n,m:44n,n:45n,o:46n,p:47n,q:48n,r:49n,s:50n,t:51n,u:52n,v:53n,w:54n,x:55n,y:56n,z:57n}),Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").map((t,e)=>[e,t.charCodeAt(0)]),{...Object.fromEntries(Array.from("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/").map((t,e)=>[t.charCodeAt(0),e]))},Er.slice();const UP=BigInt(0),Ff=BigInt(1),im=BigInt(2),bo=BigInt(3);function CP(t){const e=[];for(;t>Ff;t>>=Ff)(t&Ff)===UP?e.unshift(0):(t&bo)===bo?(e.unshift(-1),t+=Ff):e.unshift(1);return e}function LP(t){const{Fp:e,Fr:n,Fp2:r,Fp6:i,Fp12:s}=t.fields,o=t.params.xNegative,a=t.params.twistType,c=Pd({n:n.ORDER,...t.G1}),f=Object.assign(c,em(c.ProjectivePoint,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),l=Pd({n:n.ORDER,...t.G2}),h=Object.assign(l,em(l.ProjectivePoint,t.G2.mapToCurve,{...t.htfDefaults,...t.G2.htfDefaults}));let d;if(a==="multiplicative")d=(N,k,R,j,z,V)=>s.mul014(j,N,r.mul(k,z),r.mul(R,V));else if(a==="divisive")d=(N,k,R,j,z,V)=>s.mul034(j,r.mul(R,V),r.mul(k,z),N);else throw new Error("bls: unknown twist type");const u=r.div(r.ONE,r.mul(r.ONE,im));function b(N,k,R,j){const z=r.sqr(R),V=r.sqr(j),H=r.mulByB(r.mul(V,bo)),K=r.mul(H,bo),Y=r.sub(r.sub(r.sqr(r.add(R,j)),V),z),X=r.sub(H,z),ee=r.mul(r.sqr(k),bo),se=r.neg(Y);return N.push([X,ee,se]),k=r.mul(r.mul(r.mul(r.sub(z,K),k),R),u),R=r.sub(r.sqr(r.mul(r.add(z,K),u)),r.mul(r.sqr(H),bo)),j=r.mul(z,Y),{Rx:k,Ry:R,Rz:j}}function w(N,k,R,j,z,V){const H=r.sub(R,r.mul(V,j)),K=r.sub(k,r.mul(z,j)),Y=r.sub(r.mul(H,z),r.mul(K,V)),X=r.neg(H),ee=K;N.push([Y,X,ee]);const se=r.sqr(K),oe=r.mul(se,K),ot=r.mul(se,k),Ns=r.add(r.sub(oe,r.mul(ot,im)),r.mul(r.sqr(H),j));return k=r.mul(K,Ns),R=r.sub(r.mul(r.sub(ot,Ns),H),r.mul(oe,R)),j=r.mul(j,oe),{Rx:k,Ry:R,Rz:j}}const E=CP(t.params.ateLoopSize),A=dd(N=>{const k=N,{x:R,y:j}=k.toAffine(),z=R,V=j,H=r.neg(j);let K=z,Y=V,X=r.ONE;const ee=[];for(const se of E){const oe=[];({Rx:K,Ry:Y,Rz:X}=b(oe,K,Y,X)),se&&({Rx:K,Ry:Y,Rz:X}=w(oe,K,Y,X,z,se===-1?H:V)),ee.push(oe)}if(t.postPrecompute){const se=ee[ee.length-1];t.postPrecompute(K,Y,X,z,V,w.bind(null,se))}return ee});function P(N,k=!1){let R=s.ONE;if(N.length){const j=N[0][0].length;for(let z=0;z<j;z++){R=s.sqr(R);for(const[V,H,K]of N)for(const[Y,X,ee]of V[z])R=d(Y,X,ee,R,H,K)}}return o&&(R=s.conjugate(R)),k?s.finalExponentiate(R):R}function _(N,k=!0){const R=[];f.ProjectivePoint.normalizeZ(N.map(({g1:j})=>j)),h.ProjectivePoint.normalizeZ(N.map(({g2:j})=>j));for(const{g1:j,g2:z}of N){if(j.equals(f.ProjectivePoint.ZERO)||z.equals(h.ProjectivePoint.ZERO))throw new Error("pairing is not available for ZERO point");j.assertValidity(),z.assertValidity();const V=j.toAffine();R.push([A(z),V.x,V.y])}return P(R,k)}function x(N,k,R=!0){return _([{g1:N,g2:k}],R)}const D={randomPrivateKey:()=>{const N=_d(n.ORDER);return Hw(t.randomBytes(N),n.ORDER)},calcPairingPrecomputes:A},{ShortSignature:U}=t.G1,{Signature:C}=t.G2;function L(N){return N instanceof f.ProjectivePoint?N:f.ProjectivePoint.fromHex(N)}function O(N,k){return N instanceof f.ProjectivePoint?N:f.hashToCurve(mt("point",N),k)}function M(N){return N instanceof h.ProjectivePoint?N:C.fromHex(N)}function q(N,k){return N instanceof h.ProjectivePoint?N:h.hashToCurve(mt("point",N),k)}function y(N){return f.ProjectivePoint.fromPrivateKey(N).toRawBytes(!0)}function p(N){return h.ProjectivePoint.fromPrivateKey(N).toRawBytes(!0)}function m(N,k,R){const j=q(N,R);j.assertValidity();const z=j.multiply(f.normPrivateKeyToScalar(k));return N instanceof h.ProjectivePoint?z:C.toRawBytes(z)}function g(N,k,R){const j=O(N,R);j.assertValidity();const z=j.multiply(f.normPrivateKeyToScalar(k));return N instanceof f.ProjectivePoint?z:U.toRawBytes(z)}function v(N,k,R,j){const z=L(R),V=q(k,j),H=f.ProjectivePoint.BASE,K=M(N),Y=_([{g1:z.negate(),g2:V},{g1:H,g2:K}]);return s.eql(Y,s.ONE)}function S(N,k,R,j){const z=M(R),V=O(k,j),H=h.ProjectivePoint.BASE,K=L(N),Y=_([{g1:V,g2:z},{g1:K,g2:H.negate()}]);return s.eql(Y,s.ONE)}function B(N){if(!Array.isArray(N)||N.length===0)throw new Error("expected non-empty array")}function I(N){B(N);const R=N.map(L).reduce((j,z)=>j.add(z),f.ProjectivePoint.ZERO);return N[0]instanceof f.ProjectivePoint?(R.assertValidity(),R):R.toRawBytes(!0)}function $(N){B(N);const R=N.map(M).reduce((j,z)=>j.add(z),h.ProjectivePoint.ZERO);return N[0]instanceof h.ProjectivePoint?(R.assertValidity(),R):C.toRawBytes(R)}function T(N){B(N);const R=N.map(L).reduce((j,z)=>j.add(z),f.ProjectivePoint.ZERO);return N[0]instanceof f.ProjectivePoint?(R.assertValidity(),R):U.toRawBytes(R)}function F(N,k,R,j){if(B(k),R.length!==k.length)throw new Error("amount of public keys and messages should be equal");const z=M(N),V=k.map(X=>q(X,j)),H=R.map(L),K=new Map;for(let X=0;X<H.length;X++){const ee=H[X],se=V[X];let oe=K.get(se);oe===void 0&&(oe=[],K.set(se,oe)),oe.push(ee)}const Y=[];try{for(const[X,ee]of K){const se=ee.reduce((oe,ot)=>oe.add(ot));Y.push({g1:se,g2:X})}return Y.push({g1:f.ProjectivePoint.BASE.negate(),g2:z}),s.eql(_(Y),s.ONE)}catch{return!1}}return f.ProjectivePoint.BASE._setWindowSize(4),{getPublicKey:y,getPublicKeyForShortSignatures:p,sign:m,signShortSignature:g,verify:v,verifyBatch:F,verifyShortSignature:S,aggregatePublicKeys:I,aggregateSignatures:$,aggregateShortSignatures:T,millerLoopBatch:P,pairing:x,pairingBatch:_,G1:f,G2:h,Signature:C,ShortSignature:U,fields:{Fr:n,Fp:e,Fp2:r,Fp6:i,Fp12:s},params:{ateLoopSize:t.params.ateLoopSize,r:t.params.r,G1b:t.G1.b,G2b:t.G2.b},utils:D}}const FP=BigInt(0),yo=BigInt(1),Ar=BigInt(2),sm=BigInt(3);function Nd(t,e,n,r,i=1,s){const o=BigInt(s===void 0?r:s),a=n**BigInt(r),c=[];for(let f=0;f<i;f++){const l=BigInt(f+1),h=[];for(let d=0,u=yo;d<r;d++){const b=(l*u-l)/o%a;h.push(t.pow(e,b)),u*=n}c.push(h)}return c}function kP(t,e,n){const r=e.pow(n,(t.ORDER-yo)/sm),i=e.pow(n,(t.ORDER-yo)/Ar);function s(d,u){const b=e.mul(e.frobeniusMap(d,1),r),w=e.mul(e.frobeniusMap(u,1),i);return[b,w]}const o=e.pow(n,(t.ORDER**Ar-yo)/sm),a=e.pow(n,(t.ORDER**Ar-yo)/Ar);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(d,u){return[e.mul(d,o),e.neg(u)]}const f=d=>(u,b)=>{const w=b.toAffine(),E=d(w.x,w.y);return u.fromAffine({x:E[0],y:E[1]})},l=f(s),h=f(c);return{psi:s,psi2:c,G2psi:l,G2psi2:h,PSI_X:r,PSI_Y:i,PSI2_X:o,PSI2_Y:a}}function qP(t){const{ORDER:e}=t,n=Ai(e),r=n.create(t.NONRESIDUE||BigInt(-1)),i=n.div(n.ONE,Ar),s=Nd(n,r,n.ORDER,2)[0],o=({c0:y,c1:p},{c0:m,c1:g})=>({c0:n.add(y,m),c1:n.add(p,g)}),a=({c0:y,c1:p},{c0:m,c1:g})=>({c0:n.sub(y,m),c1:n.sub(p,g)}),c=({c0:y,c1:p},m)=>{if(typeof m=="bigint")return{c0:n.mul(y,m),c1:n.mul(p,m)};const{c0:g,c1:v}=m;let S=n.mul(y,g),B=n.mul(p,v);const I=n.sub(S,B),$=n.sub(n.mul(n.add(y,p),n.add(g,v)),n.add(S,B));return{c0:I,c1:$}},f=({c0:y,c1:p})=>{const m=n.add(y,p),g=n.sub(y,p),v=n.add(y,y);return{c0:n.mul(m,g),c1:n.mul(v,p)}},l=y=>{if(y.length!==2)throw new Error("invalid tuple");const p=y.map(m=>n.create(m));return{c0:p[0],c1:p[1]}},h=e*e,d=l(t.FP2_NONRESIDUE),u={ORDER:h,isLE:n.isLE,NONRESIDUE:d,BITS:Sa(h),BYTES:Math.ceil(Sa(h)/8),MASK:ws(Sa(h)),ZERO:{c0:n.ZERO,c1:n.ZERO},ONE:{c0:n.ONE,c1:n.ZERO},create:y=>y,isValid:({c0:y,c1:p})=>typeof y=="bigint"&&typeof p=="bigint",is0:({c0:y,c1:p})=>n.is0(y)&&n.is0(p),eql:({c0:y,c1:p},{c0:m,c1:g})=>n.eql(y,m)&&n.eql(p,g),neg:({c0:y,c1:p})=>({c0:n.neg(y),c1:n.neg(p)}),pow:(y,p)=>Uf(u,y,p),invertBatch:y=>vs(u,y),add:o,sub:a,mul:c,sqr:f,addN:o,subN:a,mulN:c,sqrN:f,div:(y,p)=>u.mul(y,typeof p=="bigint"?n.inv(n.create(p)):u.inv(p)),inv:({c0:y,c1:p})=>{const m=n.inv(n.create(y*y+p*p));return{c0:n.mul(m,n.create(y)),c1:n.mul(m,n.create(-p))}},sqrt:y=>{if(t.Fp2sqrt)return t.Fp2sqrt(y);const{c0:p,c1:m}=y;if(n.is0(m))return Cf(n,p)===1?u.create({c0:n.sqrt(p),c1:n.ZERO}):u.create({c0:n.ZERO,c1:n.sqrt(n.div(p,r))});const g=n.sqrt(n.sub(n.sqr(p),n.mul(n.sqr(m),r)));let v=n.mul(n.add(g,p),i);Cf(n,v)===-1&&(v=n.sub(v,g));const B=n.sqrt(v),I=u.create({c0:B,c1:n.div(n.mul(m,i),B)});if(!u.eql(u.sqr(I),y))throw new Error("Cannot find square root");const $=I,T=u.neg($),{re:F,im:N}=u.reim($),{re:k,im:R}=u.reim(T);return N>R||N===R&&F>k?$:T},isOdd:y=>{const{re:p,im:m}=u.reim(y),g=p%Ar,v=p===FP,S=m%Ar;return BigInt(g||v&&S)==yo},fromBytes(y){if(y.length!==u.BYTES)throw new Error("fromBytes invalid length="+y.length);return{c0:n.fromBytes(y.subarray(0,n.BYTES)),c1:n.fromBytes(y.subarray(n.BYTES))}},toBytes:({c0:y,c1:p})=>Re(n.toBytes(y),n.toBytes(p)),cmov:({c0:y,c1:p},{c0:m,c1:g},v)=>({c0:n.cmov(y,m,v),c1:n.cmov(p,g,v)}),reim:({c0:y,c1:p})=>({re:y,im:p}),mulByNonresidue:({c0:y,c1:p})=>u.mul({c0:y,c1:p},d),mulByB:t.Fp2mulByB,fromBigTuple:l,frobeniusMap:({c0:y,c1:p},m)=>({c0:y,c1:n.mul(p,s[m%2])})},b=({c0:y,c1:p,c2:m},{c0:g,c1:v,c2:S})=>({c0:u.add(y,g),c1:u.add(p,v),c2:u.add(m,S)}),w=({c0:y,c1:p,c2:m},{c0:g,c1:v,c2:S})=>({c0:u.sub(y,g),c1:u.sub(p,v),c2:u.sub(m,S)}),E=({c0:y,c1:p,c2:m},g)=>{if(typeof g=="bigint")return{c0:u.mul(y,g),c1:u.mul(p,g),c2:u.mul(m,g)};const{c0:v,c1:S,c2:B}=g,I=u.mul(y,v),$=u.mul(p,S),T=u.mul(m,B);return{c0:u.add(I,u.mulByNonresidue(u.sub(u.mul(u.add(p,m),u.add(S,B)),u.add($,T)))),c1:u.add(u.sub(u.mul(u.add(y,p),u.add(v,S)),u.add(I,$)),u.mulByNonresidue(T)),c2:u.sub(u.add($,u.mul(u.add(y,m),u.add(v,B))),u.add(I,T))}},A=({c0:y,c1:p,c2:m})=>{let g=u.sqr(y),v=u.mul(u.mul(y,p),Ar),S=u.mul(u.mul(p,m),Ar),B=u.sqr(m);return{c0:u.add(u.mulByNonresidue(S),g),c1:u.add(u.mulByNonresidue(B),v),c2:u.sub(u.sub(u.add(u.add(v,u.sqr(u.add(u.sub(y,p),m))),S),g),B)}},[P,_]=Nd(u,d,n.ORDER,6,2,3),x={ORDER:u.ORDER,isLE:u.isLE,BITS:3*u.BITS,BYTES:3*u.BYTES,MASK:ws(3*u.BITS),ZERO:{c0:u.ZERO,c1:u.ZERO,c2:u.ZERO},ONE:{c0:u.ONE,c1:u.ZERO,c2:u.ZERO},create:y=>y,isValid:({c0:y,c1:p,c2:m})=>u.isValid(y)&&u.isValid(p)&&u.isValid(m),is0:({c0:y,c1:p,c2:m})=>u.is0(y)&&u.is0(p)&&u.is0(m),neg:({c0:y,c1:p,c2:m})=>({c0:u.neg(y),c1:u.neg(p),c2:u.neg(m)}),eql:({c0:y,c1:p,c2:m},{c0:g,c1:v,c2:S})=>u.eql(y,g)&&u.eql(p,v)&&u.eql(m,S),sqrt:xw,div:(y,p)=>x.mul(y,typeof p=="bigint"?n.inv(n.create(p)):x.inv(p)),pow:(y,p)=>Uf(x,y,p),invertBatch:y=>vs(x,y),add:b,sub:w,mul:E,sqr:A,addN:b,subN:w,mulN:E,sqrN:A,inv:({c0:y,c1:p,c2:m})=>{let g=u.sub(u.sqr(y),u.mulByNonresidue(u.mul(m,p))),v=u.sub(u.mulByNonresidue(u.sqr(m)),u.mul(y,p)),S=u.sub(u.sqr(p),u.mul(y,m)),B=u.inv(u.add(u.mulByNonresidue(u.add(u.mul(m,v),u.mul(p,S))),u.mul(y,g)));return{c0:u.mul(B,g),c1:u.mul(B,v),c2:u.mul(B,S)}},fromBytes:y=>{if(y.length!==x.BYTES)throw new Error("fromBytes invalid length="+y.length);return{c0:u.fromBytes(y.subarray(0,u.BYTES)),c1:u.fromBytes(y.subarray(u.BYTES,2*u.BYTES)),c2:u.fromBytes(y.subarray(2*u.BYTES))}},toBytes:({c0:y,c1:p,c2:m})=>Re(u.toBytes(y),u.toBytes(p),u.toBytes(m)),cmov:({c0:y,c1:p,c2:m},{c0:g,c1:v,c2:S},B)=>({c0:u.cmov(y,g,B),c1:u.cmov(p,v,B),c2:u.cmov(m,S,B)}),fromBigSix:y=>{if(!Array.isArray(y)||y.length!==6)throw new Error("invalid Fp6 usage");return{c0:u.fromBigTuple(y.slice(0,2)),c1:u.fromBigTuple(y.slice(2,4)),c2:u.fromBigTuple(y.slice(4,6))}},frobeniusMap:({c0:y,c1:p,c2:m},g)=>({c0:u.frobeniusMap(y,g),c1:u.mul(u.frobeniusMap(p,g),P[g%6]),c2:u.mul(u.frobeniusMap(m,g),_[g%6])}),mulByFp2:({c0:y,c1:p,c2:m},g)=>({c0:u.mul(y,g),c1:u.mul(p,g),c2:u.mul(m,g)}),mulByNonresidue:({c0:y,c1:p,c2:m})=>({c0:u.mulByNonresidue(m),c1:y,c2:p}),mul1:({c0:y,c1:p,c2:m},g)=>({c0:u.mulByNonresidue(u.mul(m,g)),c1:u.mul(y,g),c2:u.mul(p,g)}),mul01({c0:y,c1:p,c2:m},g,v){let S=u.mul(y,g),B=u.mul(p,v);return{c0:u.add(u.mulByNonresidue(u.sub(u.mul(u.add(p,m),v),B)),S),c1:u.sub(u.sub(u.mul(u.add(g,v),u.add(y,p)),S),B),c2:u.add(u.sub(u.mul(u.add(y,m),g),S),B)}}},D=Nd(u,d,n.ORDER,12,1,6)[0],U=({c0:y,c1:p},{c0:m,c1:g})=>({c0:x.add(y,m),c1:x.add(p,g)}),C=({c0:y,c1:p},{c0:m,c1:g})=>({c0:x.sub(y,m),c1:x.sub(p,g)}),L=({c0:y,c1:p},m)=>{if(typeof m=="bigint")return{c0:x.mul(y,m),c1:x.mul(p,m)};let{c0:g,c1:v}=m,S=x.mul(y,g),B=x.mul(p,v);return{c0:x.add(S,x.mulByNonresidue(B)),c1:x.sub(x.mul(x.add(y,p),x.add(g,v)),x.add(S,B))}},O=({c0:y,c1:p})=>{let m=x.mul(y,p);return{c0:x.sub(x.sub(x.mul(x.add(x.mulByNonresidue(p),y),x.add(y,p)),m),x.mulByNonresidue(m)),c1:x.add(m,m)}};function M(y,p){const m=u.sqr(y),g=u.sqr(p);return{first:u.add(u.mulByNonresidue(g),m),second:u.sub(u.sub(u.sqr(u.add(y,p)),m),g)}}const q={ORDER:u.ORDER,isLE:x.isLE,BITS:2*x.BITS,BYTES:2*x.BYTES,MASK:ws(2*x.BITS),ZERO:{c0:x.ZERO,c1:x.ZERO},ONE:{c0:x.ONE,c1:x.ZERO},create:y=>y,isValid:({c0:y,c1:p})=>x.isValid(y)&&x.isValid(p),is0:({c0:y,c1:p})=>x.is0(y)&&x.is0(p),neg:({c0:y,c1:p})=>({c0:x.neg(y),c1:x.neg(p)}),eql:({c0:y,c1:p},{c0:m,c1:g})=>x.eql(y,m)&&x.eql(p,g),sqrt:xw,inv:({c0:y,c1:p})=>{let m=x.inv(x.sub(x.sqr(y),x.mulByNonresidue(x.sqr(p))));return{c0:x.mul(y,m),c1:x.neg(x.mul(p,m))}},div:(y,p)=>q.mul(y,typeof p=="bigint"?n.inv(n.create(p)):q.inv(p)),pow:(y,p)=>Uf(q,y,p),invertBatch:y=>vs(q,y),add:U,sub:C,mul:L,sqr:O,addN:U,subN:C,mulN:L,sqrN:O,fromBytes:y=>{if(y.length!==q.BYTES)throw new Error("fromBytes invalid length="+y.length);return{c0:x.fromBytes(y.subarray(0,x.BYTES)),c1:x.fromBytes(y.subarray(x.BYTES))}},toBytes:({c0:y,c1:p})=>Re(x.toBytes(y),x.toBytes(p)),cmov:({c0:y,c1:p},{c0:m,c1:g},v)=>({c0:x.cmov(y,m,v),c1:x.cmov(p,g,v)}),fromBigTwelve:y=>({c0:x.fromBigSix(y.slice(0,6)),c1:x.fromBigSix(y.slice(6,12))}),frobeniusMap(y,p){const{c0:m,c1:g,c2:v}=x.frobeniusMap(y.c1,p),S=D[p%12];return{c0:x.frobeniusMap(y.c0,p),c1:x.create({c0:u.mul(m,S),c1:u.mul(g,S),c2:u.mul(v,S)})}},mulByFp2:({c0:y,c1:p},m)=>({c0:x.mulByFp2(y,m),c1:x.mulByFp2(p,m)}),conjugate:({c0:y,c1:p})=>({c0:y,c1:x.neg(p)}),mul014:({c0:y,c1:p},m,g,v)=>{let S=x.mul01(y,m,g),B=x.mul1(p,v);return{c0:x.add(x.mulByNonresidue(B),S),c1:x.sub(x.sub(x.mul01(x.add(p,y),m,u.add(g,v)),S),B)}},mul034:({c0:y,c1:p},m,g,v)=>{const S=x.create({c0:u.mul(y.c0,m),c1:u.mul(y.c1,m),c2:u.mul(y.c2,m)}),B=x.mul01(p,g,v),I=x.mul01(x.add(y,p),u.add(m,g),v);return{c0:x.add(x.mulByNonresidue(B),S),c1:x.sub(I,x.add(S,B))}},_cyclotomicSquare:t.Fp12cyclotomicSquare,_cyclotomicExp:t.Fp12cyclotomicExp,finalExponentiate:t.Fp12finalExponentiate};return{Fp:n,Fp2:u,Fp6:x,Fp4Square:M,Fp12:q}}const Ut=BigInt(0),kf=BigInt(1),Ge=BigInt(2),qf=BigInt(3),Oa=BigInt(4),Pi=BigInt("0xd201000000010000"),jP=Sa(Pi),{Fp:ne,Fp2:ie,Fp6:Ud,Fp4Square:Cd,Fp12:ue}=qP({ORDER:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),FP2_NONRESIDUE:[kf,kf],Fp2mulByB:({c0:t,c1:e})=>{const n=ne.mul(t,Oa),r=ne.mul(e,Oa);return{c0:ne.sub(n,r),c1:ne.add(n,r)}},Fp12cyclotomicSquare:({c0:t,c1:e})=>{const{c0:n,c1:r,c2:i}=t,{c0:s,c1:o,c2:a}=e,{first:c,second:f}=Cd(n,o),{first:l,second:h}=Cd(s,i),{first:d,second:u}=Cd(r,a),b=ie.mulByNonresidue(u);return{c0:Ud.create({c0:ie.add(ie.mul(ie.sub(c,n),Ge),c),c1:ie.add(ie.mul(ie.sub(l,r),Ge),l),c2:ie.add(ie.mul(ie.sub(d,i),Ge),d)}),c1:Ud.create({c0:ie.add(ie.mul(ie.add(b,s),Ge),b),c1:ie.add(ie.mul(ie.add(f,o),Ge),f),c2:ie.add(ie.mul(ie.add(h,a),Ge),h)})}},Fp12cyclotomicExp(t,e){let n=ue.ONE;for(let r=jP-1;r>=0;r--)n=ue._cyclotomicSquare(n),gD(e,r)&&(n=ue.mul(n,t));return n},Fp12finalExponentiate:t=>{const e=Pi,n=ue.div(ue.frobeniusMap(t,6),t),r=ue.mul(ue.frobeniusMap(n,2),n),i=ue.conjugate(ue._cyclotomicExp(r,e)),s=ue.mul(ue.conjugate(ue._cyclotomicSquare(r)),i),o=ue.conjugate(ue._cyclotomicExp(s,e)),a=ue.conjugate(ue._cyclotomicExp(o,e)),c=ue.mul(ue.conjugate(ue._cyclotomicExp(a,e)),ue._cyclotomicSquare(i)),f=ue.conjugate(ue._cyclotomicExp(c,e)),l=ue.frobeniusMap(ue.mul(i,a),2),h=ue.frobeniusMap(ue.mul(o,r),3),d=ue.frobeniusMap(ue.mul(c,ue.conjugate(r)),1),u=ue.mul(ue.mul(f,ue.conjugate(s)),r);return ue.mul(ue.mul(ue.mul(l,h),d),u)}}),om=Ai(BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001")),MP=Qw(ie,[[["0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97d6"],["0x0","0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71a"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71e","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38d"],["0x171d6541fa38ccfaed6dea691f5fb614cb14b4e7f4e810aa22d6108f142b85757098e38d0f671c7188e2aaaaaaaa5ed1","0x0"]],[["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa63"],["0xc","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa9f"],["0x1","0x0"]],[["0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706","0x1530477c7ab4113b59a4c18b076d11930f7da5d4a07f649bf54439d87d27e500fc8c25ebf8c92f6812cfc71c71c6d706"],["0x0","0x5c759507e8e333ebb5b7a9a47d7ed8532c52d39fd3a042a88b58423c50ae15d5c2638e343d9c71c6238aaaaaaaa97be"],["0x11560bf17baa99bc32126fced787c88f984f87adf7ae0c7f9a208c6b4f20a4181472aaa9cb8d555526a9ffffffffc71c","0x8ab05f8bdd54cde190937e76bc3e447cc27c3d6fbd7063fcd104635a790520c0a395554e5c6aaaa9354ffffffffe38f"],["0x124c9ad43b6cf79bfbf7043de3811ad0761b0f37a1e26286b0e977c69aa274524e79097a56dc4bd9e1b371c71c718b10","0x0"]],[["0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa8fb"],["0x0","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffa9d3"],["0x12","0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaa99"],["0x1","0x0"]]].map(t=>t.map(e=>ie.fromBigTuple(e.map(BigInt))))),zP=Qw(ne,[["0x11a05f2b1e833340b809101dd99815856b303e88a2d7005ff2627b56cdb4e2c85610c2d5f2e62d6eaeac1662734649b7","0x17294ed3e943ab2f0588bab22147a81c7c17e75b2f6a8417f565e33c70d1e86b4838f2a6f318c356e834eef1b3cb83bb","0xd54005db97678ec1d1048c5d10a9a1bce032473295983e56878e501ec68e25c958c3e3d2a09729fe0179f9dac9edcb0","0x1778e7166fcc6db74e0609d307e55412d7f5e4656a8dbf25f1b33289f1b330835336e25ce3107193c5b388641d9b6861","0xe99726a3199f4436642b4b3e4118e5499db995a1257fb3f086eeb65982fac18985a286f301e77c451154ce9ac8895d9","0x1630c3250d7313ff01d1201bf7a74ab5db3cb17dd952799b9ed3ab9097e68f90a0870d2dcae73d19cd13c1c66f652983","0xd6ed6553fe44d296a3726c38ae652bfb11586264f0f8ce19008e218f9c86b2a8da25128c1052ecaddd7f225a139ed84","0x17b81e7701abdbe2e8743884d1117e53356de5ab275b4db1a682c62ef0f2753339b7c8f8c8f475af9ccb5618e3f0c88e","0x80d3cf1f9a78fc47b90b33563be990dc43b756ce79f5574a2c596c928c5d1de4fa295f296b74e956d71986a8497e317","0x169b1f8e1bcfa7c42e0c37515d138f22dd2ecb803a0c5c99676314baf4bb1b7fa3190b2edc0327797f241067be390c9e","0x10321da079ce07e272d8ec09d2565b0dfa7dccdde6787f96d50af36003b14866f69b771f8c285decca67df3f1605fb7b","0x6e08c248e260e70bd1e962381edee3d31d79d7e22c837bc23c0bf1bc24c6b68c24b1b80b64d391fa9c8ba2e8ba2d229"],["0x8ca8d548cff19ae18b2e62f4bd3fa6f01d5ef4ba35b48ba9c9588617fc8ac62b558d681be343df8993cf9fa40d21b1c","0x12561a5deb559c4348b4711298e536367041e8ca0cf0800c0126c2588c48bf5713daa8846cb026e9e5c8276ec82b3bff","0xb2962fe57a3225e8137e629bff2991f6f89416f5a718cd1fca64e00b11aceacd6a3d0967c94fedcfcc239ba5cb83e19","0x3425581a58ae2fec83aafef7c40eb545b08243f16b1655154cca8abc28d6fd04976d5243eecf5c4130de8938dc62cd8","0x13a8e162022914a80a6f1d5f43e7a07dffdfc759a12062bb8d6b44e833b306da9bd29ba81f35781d539d395b3532a21e","0xe7355f8e4e667b955390f7f0506c6e9395735e9ce9cad4d0a43bcef24b8982f7400d24bc4228f11c02df9a29f6304a5","0x772caacf16936190f3e0c63e0596721570f5799af53a1894e2e073062aede9cea73b3538f0de06cec2574496ee84a3a","0x14a7ac2a9d64a8b230b3f5b074cf01996e7f63c21bca68a81996e1cdf9822c580fa5b9489d11e2d311f7d99bbdcc5a5e","0xa10ecf6ada54f825e920b3dafc7a3cce07f8d1d7161366b74100da67f39883503826692abba43704776ec3a79a1d641","0x95fc13ab9e92ad4476d6e3eb3a56680f682b4ee96f7d03776df533978f31c1593174e4b4b7865002d6384d168ecdd0a","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"],["0x90d97c81ba24ee0259d1f094980dcfa11ad138e48a869522b52af6c956543d3cd0c7aee9b3ba3c2be9845719707bb33","0x134996a104ee5811d51036d776fb46831223e96c254f383d0f906343eb67ad34d6c56711962fa8bfe097e75a2e41c696","0xcc786baa966e66f4a384c86a3b49942552e2d658a31ce2c344be4b91400da7d26d521628b00523b8dfe240c72de1f6","0x1f86376e8981c217898751ad8746757d42aa7b90eeb791c09e4a3ec03251cf9de405aba9ec61deca6355c77b0e5f4cb","0x8cc03fdefe0ff135caf4fe2a21529c4195536fbe3ce50b879833fd221351adc2ee7f8dc099040a841b6daecf2e8fedb","0x16603fca40634b6a2211e11db8f0a6a074a7d0d4afadb7bd76505c3d3ad5544e203f6326c95a807299b23ab13633a5f0","0x4ab0b9bcfac1bbcb2c977d027796b3ce75bb8ca2be184cb5231413c4d634f3747a87ac2460f415ec961f8855fe9d6f2","0x987c8d5333ab86fde9926bd2ca6c674170a05bfe3bdd81ffd038da6c26c842642f64550fedfe935a15e4ca31870fb29","0x9fc4018bd96684be88c9e221e4da1bb8f3abd16679dc26c1e8b6e6a1f20cabe69d65201c78607a360370e577bdba587","0xe1bba7a1186bdb5223abde7ada14a23c42a0ca7915af6fe06985e7ed1e4d43b9b3f7055dd4eba6f2bafaaebca731c30","0x19713e47937cd1be0dfd0b8f1d43fb93cd2fcbcb6caf493fd1183e416389e61031bf3a5cce3fbafce813711ad011c132","0x18b46a908f36f6deb918c143fed2edcc523559b8aaf0c2462e6bfe7f911f643249d9cdf41b44d606ce07c8a4d0074d8e","0xb182cac101b9399d155096004f53f447aa7b12a3426b08ec02710e807b4633f06c851c1919211f20d4c04f00b971ef8","0x245a394ad1eca9b72fc00ae7be315dc757b3b080d4c158013e6632d3c40659cc6cf90ad1c232a6442d9d3f5db980133","0x5c129645e44cf1102a159f748c4a3fc5e673d81d7e86568d9ab0f5d396a7ce46ba1049b6579afb7866b1e715475224b","0x15e6be4e990f03ce4ea50b3b42df2eb5cb181d8f84965a3957add4fa95af01b2b665027efec01c7704b456be69c8b604"],["0x16112c4c3a9c98b252181140fad0eae9601a6de578980be6eec3232b5be72e7a07f3688ef60c206d01479253b03663c1","0x1962d75c2381201e1a0cbd6c43c348b885c84ff731c4d59ca4a10356f453e01f78a4260763529e3532f6102c2e49a03d","0x58df3306640da276faaae7d6e8eb15778c4855551ae7f310c35a5dd279cd2eca6757cd636f96f891e2538b53dbf67f2","0x16b7d288798e5395f20d23bf89edb4d1d115c5dbddbcd30e123da489e726af41727364f2c28297ada8d26d98445f5416","0xbe0e079545f43e4b00cc912f8228ddcc6d19c9f0f69bbb0542eda0fc9dec916a20b15dc0fd2ededda39142311a5001d","0x8d9e5297186db2d9fb266eaac783182b70152c65550d881c5ecd87b6f0f5a6449f38db9dfa9cce202c6477faaf9b7ac","0x166007c08a99db2fc3ba8734ace9824b5eecfdfa8d0cf8ef5dd365bc400a0051d5fa9c01a58b1fb93d1a1399126a775c","0x16a3ef08be3ea7ea03bcddfabba6ff6ee5a4375efa1f4fd7feb34fd206357132b920f5b00801dee460ee415a15812ed9","0x1866c8ed336c61231a1be54fd1d74cc4f9fb0ce4c6af5920abc5750c4bf39b4852cfe2f7bb9248836b233d9d55535d4a","0x167a55cda70a6e1cea820597d94a84903216f763e13d87bb5308592e7ea7d4fbc7385ea3d529b35e346ef48bb8913f55","0x4d2f259eea405bd48f010a01ad2911d9c6dd039bb61a6290e591b36e636a5c871a5c29f4f83060400f8b49cba8f6aa8","0xaccbb67481d033ff5852c1e48c50c477f94ff8aefce42d28c0f9a88cea7913516f968986f7ebbea9684b529e2561092","0xad6b9514c767fe3c3613144b45f1496543346d98adf02267d5ceef9a00d9b8693000763e3b90ac11e99b138573345cc","0x2660400eb2e4f3b628bdd0d53cd76f2bf565b94e72927c1cb748df27942480e420517bd8714cc80d1fadc1326ed06f7","0xe0fa1d816ddc03e6b24255e0d7819c171c40f65e273b853324efcd6356caa205ca2f570f13497804415473a1d634b8f","0x000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"]].map(t=>t.map(e=>BigInt(e)))),HP=Xw(ie,{A:ie.create({c0:ne.create(Ut),c1:ne.create(BigInt(240))}),B:ie.create({c0:ne.create(BigInt(1012)),c1:ne.create(BigInt(1012))}),Z:ie.create({c0:ne.create(BigInt(-2)),c1:ne.create(BigInt(-1))})}),VP=Xw(ne,{A:ne.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:ne.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:ne.create(BigInt(11))}),{G2psi:am,G2psi2:KP}=kP(ne,ie,ie.div(ie.ONE,ie.NONRESIDUE)),Ld=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:ne.ORDER,m:2,k:128,expand:"xmd",hash:Af}),jf=Da(ne.toBytes(Ut),{infinity:!0,compressed:!0});function Mf(t){t=t.slice();const e=t[0]&224,n=!!(e>>7&1),r=!!(e>>6&1),i=!!(e>>5&1);return t[0]&=31,{compressed:n,infinity:r,sort:i,value:t}}function Da(t,e){if(t[0]&224)throw new Error("setMask: non-empty mask");return e.compressed&&(t[0]|=128),e.infinity&&(t[0]|=64),e.sort&&(t[0]|=32),t}function cm(t){t.assertValidity();const e=t.equals(Rn.G1.ProjectivePoint.ZERO),{x:n,y:r}=t.toAffine();if(e)return jf.slice();const i=ne.ORDER,s=!!(r*Ge/i);return Da(qe(n,ne.BYTES),{compressed:!0,sort:s})}function fm(t){t.assertValidity();const e=ne.BYTES;if(t.equals(Rn.G2.ProjectivePoint.ZERO))return Re(jf,qe(Ut,e));const{x:n,y:r}=t.toAffine(),{re:i,im:s}=ie.reim(n),{re:o,im:a}=ie.reim(r),f=!!((a>Ut?a*Ge:o*Ge)/ne.ORDER&kf),l=i;return Re(Da(qe(s,e),{sort:f,compressed:!0}),qe(l,e))}const Rn=LP({fields:{Fp:ne,Fp2:ie,Fp6:Ud,Fp12:ue,Fr:om},G1:{Fp:ne,h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1"),a:ne.ZERO,b:Oa,htfDefaults:{...Ld,m:1,DST:"BLS_SIG_BLS12381G1_XMD:SHA-256_SSWU_RO_NUL_"},wrapPrivateKey:!0,allowInfinityPoint:!0,isTorsionFree:(t,e)=>{const n=BigInt("0x5f19672fdf76ce51ba69c6076a0f77eaddb3a93be6f89688de17d813620a00022e01fffffffefffe"),r=new t(ne.mul(e.px,n),e.py,e.pz);return e.multiplyUnsafe(Pi).negate().multiplyUnsafe(Pi).equals(r)},clearCofactor:(t,e)=>e.multiplyUnsafe(Pi).add(e),mapToCurve:t=>{const{x:e,y:n}=VP(ne.create(t[0]));return zP(e,n)},fromBytes:t=>{const{compressed:e,infinity:n,sort:r,value:i}=Mf(t);if(i.length===48&&e){const s=ne.ORDER,o=Rt(i),a=ne.create(o&ne.MASK);if(n){if(a!==Ut)throw new Error("G1: non-empty compressed point at infinity");return{x:Ut,y:Ut}}const c=ne.add(ne.pow(a,qf),ne.create(Rn.params.G1b));let f=ne.sqrt(c);if(!f)throw new Error("invalid compressed G1 point");return f*Ge/s!==BigInt(r)&&(f=ne.neg(f)),{x:ne.create(a),y:ne.create(f)}}else if(i.length===96&&!e){const s=Rt(i.subarray(0,ne.BYTES)),o=Rt(i.subarray(ne.BYTES));if(n){if(s!==Ut||o!==Ut)throw new Error("G1: non-empty point at infinity");return Rn.G1.ProjectivePoint.ZERO.toAffine()}return{x:ne.create(s),y:ne.create(o)}}else throw new Error("invalid point G1, expected 48/96 bytes")},toBytes:(t,e,n)=>{const r=e.equals(t.ZERO),{x:i,y:s}=e.toAffine();if(n){if(r)return jf.slice();const o=ne.ORDER,a=!!(s*Ge/o);return Da(qe(i,ne.BYTES),{compressed:!0,sort:a})}else return r?Re(new Uint8Array([64]),new Uint8Array(2*ne.BYTES-1)):Re(qe(i,ne.BYTES),qe(s,ne.BYTES))},ShortSignature:{fromHex(t){const{infinity:e,sort:n,value:r}=Mf(mt("signatureHex",t,48)),i=ne.ORDER,s=Rt(r);if(e)return Rn.G1.ProjectivePoint.ZERO;const o=ne.create(s&ne.MASK),a=ne.add(ne.pow(o,qf),ne.create(Rn.params.G1b));let c=ne.sqrt(a);if(!c)throw new Error("invalid compressed G1 point");const f=BigInt(n);c*Ge/i!==f&&(c=ne.neg(c));const l=Rn.G1.ProjectivePoint.fromAffine({x:o,y:c});return l.assertValidity(),l},toRawBytes(t){return cm(t)},toHex(t){return ys(cm(t))}}},G2:{Fp:ie,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),Gx:ie.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:ie.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")]),a:ie.ZERO,b:ie.fromBigTuple([Oa,Oa]),hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...Ld},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:t=>{const{x:e,y:n}=HP(ie.fromBigTuple(t));return MP(e,n)},isTorsionFree:(t,e)=>e.multiplyUnsafe(Pi).negate().equals(am(t,e)),clearCofactor:(t,e)=>{const n=Pi;let r=e.multiplyUnsafe(n).negate(),i=am(t,e),s=e.double();return s=KP(t,s),s=s.subtract(i),i=r.add(i),i=i.multiplyUnsafe(n).negate(),s=s.add(i),s=s.subtract(r),s.subtract(e)},fromBytes:t=>{const{compressed:e,infinity:n,sort:r,value:i}=Mf(t);if(!e&&!n&&r||!e&&n&&r||r&&n&&e)throw new Error("invalid encoding flag: "+(t[0]&224));const s=ne.BYTES,o=(a,c,f)=>Rt(a.slice(c,f));if(i.length===96&&e){const a=Rn.params.G2b,c=ne.ORDER;if(n){if(i.reduce((w,E)=>w!==0?E+1:E,0)>0)throw new Error("invalid compressed G2 point");return{x:ie.ZERO,y:ie.ZERO}}const f=o(i,0,s),l=o(i,s,2*s),h=ie.create({c0:ne.create(l),c1:ne.create(f)}),d=ie.add(ie.pow(h,qf),a);let u=ie.sqrt(d);const b=u.c1===Ut?u.c0*Ge/c:u.c1*Ge/c?kf:Ut;return u=r&&b>0?u:ie.neg(u),{x:h,y:u}}else if(i.length===192&&!e){if(n){if(i.reduce((h,d)=>h!==0?d+1:d,0)>0)throw new Error("invalid uncompressed G2 point");return{x:ie.ZERO,y:ie.ZERO}}const a=o(i,0,s),c=o(i,s,2*s),f=o(i,2*s,3*s),l=o(i,3*s,4*s);return{x:ie.fromBigTuple([c,a]),y:ie.fromBigTuple([l,f])}}else throw new Error("invalid point G2, expected 96/192 bytes")},toBytes:(t,e,n)=>{const{BYTES:r,ORDER:i}=ne,s=e.equals(t.ZERO),{x:o,y:a}=e.toAffine();if(n){if(s)return Re(jf,qe(Ut,r));const c=!!(a.c1===Ut?a.c0*Ge/i:a.c1*Ge/i);return Re(Da(qe(o.c1,r),{compressed:!0,sort:c}),qe(o.c0,r))}else{if(s)return Re(new Uint8Array([64]),new Uint8Array(4*r-1));const{re:c,im:f}=ie.reim(o),{re:l,im:h}=ie.reim(a);return Re(qe(f,r),qe(c,r),qe(h,r),qe(l,r))}},Signature:{fromHex(t){const{infinity:e,sort:n,value:r}=Mf(mt("signatureHex",t)),i=ne.ORDER,s=r.length/2;if(s!==48&&s!==96)throw new Error("invalid compressed signature length, must be 96 or 192");const o=Rt(r.slice(0,s)),a=Rt(r.slice(s));if(e)return Rn.G2.ProjectivePoint.ZERO;const c=ne.create(o&ne.MASK),f=ne.create(a),l=ie.create({c0:f,c1:c}),h=ie.add(ie.pow(l,qf),Rn.params.G2b);let d=ie.sqrt(h);if(!d)throw new Error("Failed to find a square root");const{re:u,im:b}=ie.reim(d),w=BigInt(n),E=b>Ut&&b*Ge/i!==w,A=b===Ut&&u*Ge/i!==w;(E||A)&&(d=ie.neg(d));const P=Rn.G2.ProjectivePoint.fromAffine({x:l,y:d});return P.assertValidity(),P},toRawBytes(t){return fm(t)},toHex(t){return ys(fm(t))}}},params:{ateLoopSize:Pi,r:om.ORDER,xNegative:!0,twistType:"multiplicative"},htfDefaults:Ld,hash:Af,randomBytes:nw});BigInt(0),BigInt(1),BigInt(2),BigInt(8),BigInt(0),BigInt(1),BigInt(2),BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),BigInt(0),BigInt(1),BigInt(2),BigInt(3),BigInt(5),BigInt(8);function GP(t){return JD(ZP(t))}function ZP(t){const{payload:e,signature:n}=t,{r,s:i,yParity:s}=n,a=new OP.Signature(BigInt(r),BigInt(i)).addRecoveryBit(s).recoverPublicKey(yd(e).substring(2));return zD(a)}const um=Ai(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),WP=um.create(BigInt("-3")),YP=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");Lf({a:WP,b:YP,Fp:um,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},Af);const lm=Ai(BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff")),XP=lm.create(BigInt("-3")),JP=BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef");Lf({a:XP,b:JP,Fp:lm,n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"),h:BigInt(1),lowS:!1},dD);const hm=Ai(BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),QP=hm.create(BigInt("-3")),eR=BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00");Lf({a:QP,b:eR,Fp:hm,n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650"),h:BigInt(1),lowS:!1,allowedPrivateKeyLengths:[130,131,132]},hD);var tR={exports:{}};(function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}Object.create&&(r.prototype=Object.create(null),new r().__proto__||(n=!1));function i(c,f,l){this.fn=c,this.context=f,this.once=l||!1}function s(c,f,l,h,d){if(typeof l!="function")throw new TypeError("The listener must be a function");var u=new i(l,h||c,d),b=n?n+f:f;return c._events[b]?c._events[b].fn?c._events[b]=[c._events[b],u]:c._events[b].push(u):(c._events[b]=u,c._eventsCount++),c}function o(c,f){--c._eventsCount===0?c._events=new r:delete c._events[f]}function a(){this._events=new r,this._eventsCount=0}a.prototype.eventNames=function(){var f=[],l,h;if(this._eventsCount===0)return f;for(h in l=this._events)e.call(l,h)&&f.push(n?h.slice(1):h);return Object.getOwnPropertySymbols?f.concat(Object.getOwnPropertySymbols(l)):f},a.prototype.listeners=function(f){var l=n?n+f:f,h=this._events[l];if(!h)return[];if(h.fn)return[h.fn];for(var d=0,u=h.length,b=new Array(u);d<u;d++)b[d]=h[d].fn;return b},a.prototype.listenerCount=function(f){var l=n?n+f:f,h=this._events[l];return h?h.fn?1:h.length:0},a.prototype.emit=function(f,l,h,d,u,b){var w=n?n+f:f;if(!this._events[w])return!1;var E=this._events[w],A=arguments.length,P,_;if(E.fn){switch(E.once&&this.removeListener(f,E.fn,void 0,!0),A){case 1:return E.fn.call(E.context),!0;case 2:return E.fn.call(E.context,l),!0;case 3:return E.fn.call(E.context,l,h),!0;case 4:return E.fn.call(E.context,l,h,d),!0;case 5:return E.fn.call(E.context,l,h,d,u),!0;case 6:return E.fn.call(E.context,l,h,d,u,b),!0}for(_=1,P=new Array(A-1);_<A;_++)P[_-1]=arguments[_];E.fn.apply(E.context,P)}else{var x=E.length,D;for(_=0;_<x;_++)switch(E[_].once&&this.removeListener(f,E[_].fn,void 0,!0),A){case 1:E[_].fn.call(E[_].context);break;case 2:E[_].fn.call(E[_].context,l);break;case 3:E[_].fn.call(E[_].context,l,h);break;case 4:E[_].fn.call(E[_].context,l,h,d);break;default:if(!P)for(D=1,P=new Array(A-1);D<A;D++)P[D-1]=arguments[D];E[_].fn.apply(E[_].context,P)}}return!0},a.prototype.on=function(f,l,h){return s(this,f,l,h,!1)},a.prototype.once=function(f,l,h){return s(this,f,l,h,!0)},a.prototype.removeListener=function(f,l,h,d){var u=n?n+f:f;if(!this._events[u])return this;if(!l)return o(this,u),this;var b=this._events[u];if(b.fn)b.fn===l&&(!d||b.once)&&(!h||b.context===h)&&o(this,u);else{for(var w=0,E=[],A=b.length;w<A;w++)(b[w].fn!==l||d&&!b[w].once||h&&b[w].context!==h)&&E.push(b[w]);E.length?this._events[u]=E.length===1?E[0]:E:o(this,u)}return this},a.prototype.removeAllListeners=function(f){var l;return f?(l=n?n+f:f,this._events[l]&&o(this,l)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a})(tR);const nR=":";function zf(t){const[e,n]=t.split(nR);return{namespace:e,reference:n}}function dm(t,e){return t.includes(":")?[t]:e.chains||[]}var rR=Object.defineProperty,iR=Object.defineProperties,sR=Object.getOwnPropertyDescriptors,pm=Object.getOwnPropertySymbols,oR=Object.prototype.hasOwnProperty,aR=Object.prototype.propertyIsEnumerable,Fd=(t,e,n)=>e in t?rR(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,gm=(t,e)=>{for(var n in e||(e={}))oR.call(e,n)&&Fd(t,n,e[n]);if(pm)for(var n of pm(e))aR.call(e,n)&&Fd(t,n,e[n]);return t},cR=(t,e)=>iR(t,sR(e)),bm=(t,e,n)=>Fd(t,typeof e!="symbol"?e+"":e,n);const fR="ReactNative",on={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},uR="js";function Hf(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function Ri(){return!nr()&&!!Co()&&navigator.product===fR}function lR(){return Ri()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function hR(){return Ri()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function wo(){return!Hf()&&!!Co()&&!!nr()}function Pa(){return Ri()?on.reactNative:Hf()?on.node:wo()?on.browser:on.unknown}function ym(){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 dR(t,e){const n=new URLSearchParams(t);return Object.entries(e).sort(([r],[i])=>r.localeCompare(i)).forEach(([r,i])=>{i!=null&&n.set(r,String(i))}),n.toString()}function pR(t){var e,n;const r=wm();try{return t!=null&&t.url&&r.url&&new URL(t.url).host!==new URL(r.url).host&&(console.warn(`The configured WalletConnect 'metadata.url':${t.url} differs from the actual page url:${r.url}. This is probably unintended and can lead to issues.`),t.url=r.url),(e=t?.icons)!=null&&e.length&&t.icons.length>0&&(t.icons=t.icons.filter(i=>i!=="")),cR(gm(gm({},r),t),{url:t?.url||r.url,name:t?.name||r.name,description:t?.description||r.description,icons:(n=t?.icons)!=null&&n.length&&t.icons.length>0?t.icons:r.icons})}catch(i){return console.warn("Error populating app metadata",i),t||r}}function wm(){return C1()||{name:"",description:"",url:"",icons:[""]}}function gR(){if(Pa()===on.reactNative&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"){const{OS:n,Version:r}=global.Platform;return[n,r].join("-")}const t=v6();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 bR(){var t;const e=Pa();return e===on.browser?[e,((t=U1())==null?void 0:t.host)||"unknown"].join(":"):e}function mm(t,e,n){const r=gR(),i=bR();return[[t,e].join("-"),[uR,n].join("-"),r,i].join("/")}function yR({protocol:t,version:e,relayUrl:n,sdkVersion:r,auth:i,projectId:s,useOnCloseEvent:o,bundleId:a,packageName:c}){const f=n.split("?"),l=mm(t,e,r),h={auth:i,ua:l,projectId:s,useOnCloseEvent:o||void 0,packageName:c||void 0,bundleId:a||void 0},d=dR(f[1]||"",h);return f[0]+"?"+d}function Es(t,e){return t.filter(n=>e.includes(n)).length===t.length}function kd(t){return Object.fromEntries(t.entries())}function qd(t){return new Map(Object.entries(t))}function xs(t=Z.FIVE_MINUTES,e){const n=Z.toMiliseconds(t||Z.FIVE_MINUTES);let r,i,s,o;return{resolve:a=>{s&&r&&(clearTimeout(s),r(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 f=new Error(e);o=Promise.reject(f),c(f)},n),r=a,i=c})}}function Gn(t,e,n){return new Promise(async(r,i)=>{const s=setTimeout(()=>i(new Error(n)),e);try{const o=await t;r(o)}catch(o){i(o)}clearTimeout(s)})}function vm(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 wR(t){return vm("topic",t)}function mR(t){return vm("id",t)}function Em(t){const[e,n]=t.split(":"),r={id:void 0,topic:void 0};if(e==="topic"&&typeof n=="string")r.topic=n;else if(e==="id"&&Number.isInteger(Number(n)))r.id=Number(n);else throw new Error(`Invalid target, expected id:number or topic:string, got ${e}:${n}`);return r}function je(t,e){return Z.fromMiliseconds((e||Date.now())+Z.toMiliseconds(t))}function Ti(t){return Date.now()>=Z.toMiliseconds(t)}function we(t,e){return`${t}${e?`:${e}`:""}`}function _s(t=[],e=[]){return[...new Set([...t,...e])]}async function vR({id:t,topic:e,wcDeepLink:n}){var r;try{if(!n)return;const i=typeof n=="string"?JSON.parse(n):n,s=i?.href;if(typeof s!="string")return;const o=ER(s,t,e),a=Pa();if(a===on.browser){if(!((r=nr())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}xR(o)}else a===on.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(o)}catch(i){console.error(i)}}function ER(t,e,n){const r=`requestId=${e}&sessionTopic=${n}`;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}${BR(r,!0)}`}else i=`${i}/wc?${r}`;return i}function xR(t){let e="_self";IR()?e="_top":(SR()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function _R(t,e){let n="";try{if(wo()&&(n=localStorage.getItem(e),n))return n;n=await t.getItem(e)}catch(r){console.error(r)}return n}function xm(t,e){if(!t.includes(e))return null;const n=t.split(/([&,?,=])/),r=n.indexOf(e);return n[r+2]}function _m(){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 jd(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function SR(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function IR(){try{return window.self!==window.top}catch{return!1}}function BR(t,e=!1){const n=Buffer.from(t).toString("base64");return e?n.replace(/[=]/g,""):n}function Sm(t){return Buffer.from(t,"base64").toString("utf-8")}function $R(t){return new Promise(e=>setTimeout(e,t))}class AR{constructor({limit:e}){bm(this,"limit"),bm(this,"set"),this.limit=e,this.set=new Set}add(e){if(!this.set.has(e)){if(this.set.size>=this.limit){const n=this.set.values().next().value;n&&this.set.delete(n)}this.set.add(e)}}has(e){return this.set.has(e)}}const Vf=BigInt(2**32-1),Im=BigInt(32);function Bm(t,e=!1){return e?{h:Number(t&Vf),l:Number(t>>Im&Vf)}:{h:Number(t>>Im&Vf)|0,l:Number(t&Vf)|0}}function $m(t,e=!1){const n=t.length;let r=new Uint32Array(n),i=new Uint32Array(n);for(let s=0;s<n;s++){const{h:o,l:a}=Bm(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const Am=(t,e,n)=>t>>>n,Om=(t,e,n)=>t<<32-n|e>>>n,Ni=(t,e,n)=>t>>>n|e<<32-n,Ui=(t,e,n)=>t<<32-n|e>>>n,Ra=(t,e,n)=>t<<64-n|e>>>n-32,Ta=(t,e,n)=>t>>>n-32|e<<64-n,OR=(t,e)=>e,DR=(t,e)=>t,PR=(t,e,n)=>t<<n|e>>>32-n,RR=(t,e,n)=>e<<n|t>>>32-n,TR=(t,e,n)=>e<<n-32|t>>>64-n,NR=(t,e,n)=>t<<n-32|e>>>64-n;function Tn(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const Md=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),zd=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,UR=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),CR=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,LR=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),FR=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,mo=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Kf(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Or(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Nn(t,...e){if(!Kf(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 Gf(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Or(t.outputLen),Or(t.blockLen)}function Ci(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 Hd(t,e){Nn(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Na(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function bn(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Vd(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Zn(t,e){return t<<32-e|t>>>e}const Dm=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function Pm(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}const Dr=Dm?t=>t:t=>Pm(t);function kR(t){for(let e=0;e<t.length;e++)t[e]=Pm(t[e]);return t}const Li=Dm?t=>t:kR,Rm=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",qR=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function vo(t){if(Nn(t),Rm)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=qR[t[n]];return e}const Pr={_0:48,_9:57,A:65,F:70,a:97,f:102};function Tm(t){if(t>=Pr._0&&t<=Pr._9)return t-Pr._0;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 Zf(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Rm)return Uint8Array.fromHex(t);const e=t.length,n=e/2;if(e%2)throw new Error("hex string expected, got unpadded hex of length "+e);const r=new Uint8Array(n);for(let i=0,s=0;i<n;i++,s+=2){const o=Tm(t.charCodeAt(s)),a=Tm(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)}r[i]=o*16+a}return r}function Nm(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Un(t){return typeof t=="string"&&(t=Nm(t)),Nn(t),t}function Fi(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Nn(i),e+=i.length}const n=new Uint8Array(e);for(let r=0,i=0;r<t.length;r++){const s=t[r];n.set(s,i),i+=s.length}return n}class Wf{}function Ua(t){const e=r=>t().update(Un(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function jR(t){const e=(r,i)=>t(i).update(Un(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Ss(t=32){if(mo&&typeof mo.getRandomValues=="function")return mo.getRandomValues(new Uint8Array(t));if(mo&&typeof mo.randomBytes=="function")return Uint8Array.from(mo.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const MR=BigInt(0),Ca=BigInt(1),zR=BigInt(2),HR=BigInt(7),VR=BigInt(256),KR=BigInt(113),Um=[],Cm=[],Lm=[];for(let t=0,e=Ca,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],Um.push(2*(5*r+n)),Cm.push((t+1)*(t+2)/2%64);let i=MR;for(let s=0;s<7;s++)e=(e<<Ca^(e>>HR)*KR)%VR,e&zR&&(i^=Ca<<(Ca<<BigInt(s))-Ca);Lm.push(i)}const Fm=$m(Lm,!0),GR=Fm[0],ZR=Fm[1],km=(t,e,n)=>n>32?TR(t,e,n):PR(t,e,n),qm=(t,e,n)=>n>32?NR(t,e,n):RR(t,e,n);function WR(t,e=24){const n=new Uint32Array(10);for(let r=24-e;r<24;r++){for(let o=0;o<10;o++)n[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=n[c],l=n[c+1],h=km(f,l,1)^n[a],d=qm(f,l,1)^n[a+1];for(let u=0;u<50;u+=10)t[o+u]^=h,t[o+u+1]^=d}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=Cm[o],c=km(i,s,a),f=qm(i,s,a),l=Um[o];i=t[l],s=t[l+1],t[l]=c,t[l+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)n[a]=t[o+a];for(let a=0;a<10;a++)t[o+a]^=~n[(a+2)%10]&n[(a+4)%10]}t[0]^=GR[r],t[1]^=ZR[r]}bn(n)}class Kd extends Wf{constructor(e,n,r,i=!1,s=24){if(super(),this.pos=0,this.posOut=0,this.finished=!1,this.destroyed=!1,this.enableXOF=!1,this.blockLen=e,this.suffix=n,this.outputLen=r,this.enableXOF=i,this.rounds=s,Or(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=Na(this.state)}clone(){return this._cloneInto()}keccak(){Li(this.state32),WR(this.state32,this.rounds),Li(this.state32),this.posOut=0,this.pos=0}update(e){Ci(this),e=Un(e),Nn(e);const{blockLen:n,state:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(n-this.pos,i-s);for(let a=0;a<o;a++)r[this.pos++]^=e[s++];this.pos===n&&this.keccak()}return this}finish(){if(this.finished)return;this.finished=!0;const{state:e,suffix:n,pos:r,blockLen:i}=this;e[r]^=n,(n&128)!==0&&r===i-1&&this.keccak(),e[i-1]^=128,this.keccak()}writeInto(e){Ci(this,!1),Nn(e),this.finish();const n=this.state,{blockLen:r}=this;for(let i=0,s=e.length;i<s;){this.posOut>=r&&this.keccak();const o=Math.min(r-this.posOut,s-i);e.set(n.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 Or(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Hd(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,bn(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new Kd(n,r,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=r,e.outputLen=i,e.enableXOF=o,e.destroyed=this.destroyed,e}}const YR=(t,e,n)=>Ua(()=>new Kd(e,t,n)),XR=YR(1,136,256/8);function JR(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,f=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+f,a,r)}function QR(t,e,n){return t&e^~t&n}function eT(t,e,n){return t&e^t&n^e&n}class jm extends Wf{constructor(e,n,r,i){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=n,this.padOffset=r,this.isLE=i,this.buffer=new Uint8Array(e),this.view=Vd(this.buffer)}update(e){Ci(this),e=Un(e),Nn(e);const{view:n,buffer:r,blockLen:i}=this,s=e.length;for(let o=0;o<s;){const a=Math.min(i-this.pos,s-o);if(a===i){const c=Vd(e);for(;i<=s-o;o+=i)this.process(c,o);continue}r.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(n,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Ci(this),Hd(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,bn(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;JR(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Vd(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,l[h],s)}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());const{blockLen:n,buffer:r,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%n&&e.buffer.set(r),e}clone(){return this._cloneInto()}}const ki=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),vt=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Et=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),tT=Uint32Array.from([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]),qi=new Uint32Array(64);class nT extends jm{constructor(e=32){super(64,e,8,!1),this.A=ki[0]|0,this.B=ki[1]|0,this.C=ki[2]|0,this.D=ki[3]|0,this.E=ki[4]|0,this.F=ki[5]|0,this.G=ki[6]|0,this.H=ki[7]|0}get(){const{A:e,B:n,C:r,D:i,E:s,F:o,G:a,H:c}=this;return[e,n,r,i,s,o,a,c]}set(e,n,r,i,s,o,a,c){this.A=e|0,this.B=n|0,this.C=r|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,n){for(let h=0;h<16;h++,n+=4)qi[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const d=qi[h-15],u=qi[h-2],b=Zn(d,7)^Zn(d,18)^d>>>3,w=Zn(u,17)^Zn(u,19)^u>>>10;qi[h]=w+qi[h-7]+b+qi[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:l}=this;for(let h=0;h<64;h++){const d=Zn(a,6)^Zn(a,11)^Zn(a,25),u=l+d+QR(a,c,f)+tT[h]+qi[h]|0,b=(Zn(r,2)^Zn(r,13)^Zn(r,22))+eT(r,i,s)|0;l=f,f=c,c=a,a=o+u|0,o=s,s=i,i=r,r=u+b|0}r=r+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,f=f+this.G|0,l=l+this.H|0,this.set(r,i,s,o,a,c,f,l)}roundClean(){bn(qi)}destroy(){this.set(0,0,0,0,0,0,0,0),bn(this.buffer)}}const Mm=$m(["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))),rT=Mm[0],iT=Mm[1],ji=new Uint32Array(80),Mi=new Uint32Array(80);class Gd extends jm{constructor(e=64){super(128,e,16,!1),this.Ah=Et[0]|0,this.Al=Et[1]|0,this.Bh=Et[2]|0,this.Bl=Et[3]|0,this.Ch=Et[4]|0,this.Cl=Et[5]|0,this.Dh=Et[6]|0,this.Dl=Et[7]|0,this.Eh=Et[8]|0,this.El=Et[9]|0,this.Fh=Et[10]|0,this.Fl=Et[11]|0,this.Gh=Et[12]|0,this.Gl=Et[13]|0,this.Hh=Et[14]|0,this.Hl=Et[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:l,Fh:h,Fl:d,Gh:u,Gl:b,Hh:w,Hl:E}=this;return[e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E]}set(e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E){this.Ah=e|0,this.Al=n|0,this.Bh=r|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=h|0,this.Fl=d|0,this.Gh=u|0,this.Gl=b|0,this.Hh=w|0,this.Hl=E|0}process(e,n){for(let _=0;_<16;_++,n+=4)ji[_]=e.getUint32(n),Mi[_]=e.getUint32(n+=4);for(let _=16;_<80;_++){const x=ji[_-15]|0,D=Mi[_-15]|0,U=Ni(x,D,1)^Ni(x,D,8)^Am(x,D,7),C=Ui(x,D,1)^Ui(x,D,8)^Om(x,D,7),L=ji[_-2]|0,O=Mi[_-2]|0,M=Ni(L,O,19)^Ra(L,O,61)^Am(L,O,6),q=Ui(L,O,19)^Ta(L,O,61)^Om(L,O,6),y=UR(C,q,Mi[_-7],Mi[_-16]),p=CR(y,U,M,ji[_-7],ji[_-16]);ji[_]=p|0,Mi[_]=y|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:l,Eh:h,El:d,Fh:u,Fl:b,Gh:w,Gl:E,Hh:A,Hl:P}=this;for(let _=0;_<80;_++){const x=Ni(h,d,14)^Ni(h,d,18)^Ra(h,d,41),D=Ui(h,d,14)^Ui(h,d,18)^Ta(h,d,41),U=h&u^~h&w,C=d&b^~d&E,L=LR(P,D,C,iT[_],Mi[_]),O=FR(L,A,x,U,rT[_],ji[_]),M=L|0,q=Ni(r,i,28)^Ra(r,i,34)^Ra(r,i,39),y=Ui(r,i,28)^Ta(r,i,34)^Ta(r,i,39),p=r&s^r&a^s&a,m=i&o^i&c^o&c;A=w|0,P=E|0,w=u|0,E=b|0,u=h|0,b=d|0,{h,l:d}=Tn(f|0,l|0,O|0,M|0),f=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=Md(M,y,m);r=zd(g,O,q,p),i=g|0}({h:r,l:i}=Tn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=Tn(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=Tn(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=Tn(this.Dh|0,this.Dl|0,f|0,l|0),{h,l:d}=Tn(this.Eh|0,this.El|0,h|0,d|0),{h:u,l:b}=Tn(this.Fh|0,this.Fl|0,u|0,b|0),{h:w,l:E}=Tn(this.Gh|0,this.Gl|0,w|0,E|0),{h:A,l:P}=Tn(this.Hh|0,this.Hl|0,A|0,P|0),this.set(r,i,s,o,a,c,f,l,h,d,u,b,w,E,A,P)}roundClean(){bn(ji,Mi)}destroy(){bn(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class sT extends Gd{constructor(){super(48),this.Ah=vt[0]|0,this.Al=vt[1]|0,this.Bh=vt[2]|0,this.Bl=vt[3]|0,this.Ch=vt[4]|0,this.Cl=vt[5]|0,this.Dh=vt[6]|0,this.Dl=vt[7]|0,this.Eh=vt[8]|0,this.El=vt[9]|0,this.Fh=vt[10]|0,this.Fl=vt[11]|0,this.Gh=vt[12]|0,this.Gl=vt[13]|0,this.Hh=vt[14]|0,this.Hl=vt[15]|0}}const xt=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class oT extends Gd{constructor(){super(32),this.Ah=xt[0]|0,this.Al=xt[1]|0,this.Bh=xt[2]|0,this.Bl=xt[3]|0,this.Ch=xt[4]|0,this.Cl=xt[5]|0,this.Dh=xt[6]|0,this.Dl=xt[7]|0,this.Eh=xt[8]|0,this.El=xt[9]|0,this.Fh=xt[10]|0,this.Fl=xt[11]|0,this.Gh=xt[12]|0,this.Gl=xt[13]|0,this.Hh=xt[14]|0,this.Hl=xt[15]|0}}const Yf=Ua(()=>new nT),aT=Ua(()=>new Gd),cT=Ua(()=>new sT),fT=Ua(()=>new oT),uT=Uint8Array.from([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9,12,5,1,15,14,13,4,10,0,7,6,3,9,2,8,11,13,11,7,14,12,1,3,9,5,0,15,4,8,6,2,10,6,15,14,9,11,3,0,8,12,2,13,7,1,4,10,5,10,2,8,4,7,6,1,5,15,11,9,14,3,12,13,0,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,14,10,4,8,9,15,13,6,1,12,0,2,11,7,5,3,11,8,12,0,5,2,15,13,10,14,3,6,7,1,9,4,7,9,3,1,13,12,11,14,2,6,5,10,4,0,15,8,9,0,5,7,2,4,10,15,14,1,11,12,6,8,3,13,2,12,6,10,0,11,8,3,4,13,7,5,15,14,1,9]),Me=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),Q=new Uint32Array(32);function zi(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=Q[2*t],f=Q[2*t+1],l=Q[2*e],h=Q[2*e+1],d=Q[2*n],u=Q[2*n+1],b=Q[2*r],w=Q[2*r+1],E=Md(c,l,o);f=zd(E,f,h,a),c=E|0,{Dh:w,Dl:b}={Dh:w^f,Dl:b^c},{Dh:w,Dl:b}={Dh:OR(w,b),Dl:DR(w)},{h:u,l:d}=Tn(u,d,w,b),{Bh:h,Bl:l}={Bh:h^u,Bl:l^d},{Bh:h,Bl:l}={Bh:Ni(h,l,24),Bl:Ui(h,l,24)},Q[2*t]=c,Q[2*t+1]=f,Q[2*e]=l,Q[2*e+1]=h,Q[2*n]=d,Q[2*n+1]=u,Q[2*r]=b,Q[2*r+1]=w}function Hi(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=Q[2*t],f=Q[2*t+1],l=Q[2*e],h=Q[2*e+1],d=Q[2*n],u=Q[2*n+1],b=Q[2*r],w=Q[2*r+1],E=Md(c,l,o);f=zd(E,f,h,a),c=E|0,{Dh:w,Dl:b}={Dh:w^f,Dl:b^c},{Dh:w,Dl:b}={Dh:Ni(w,b,16),Dl:Ui(w,b,16)},{h:u,l:d}=Tn(u,d,w,b),{Bh:h,Bl:l}={Bh:h^u,Bl:l^d},{Bh:h,Bl:l}={Bh:Ra(h,l,63),Bl:Ta(h,l,63)},Q[2*t]=c,Q[2*t+1]=f,Q[2*e]=l,Q[2*e+1]=h,Q[2*n]=d,Q[2*n+1]=u,Q[2*r]=b,Q[2*r+1]=w}function lT(t,e={},n,r,i){if(Or(n),t<0||t>n)throw new Error("outputLen bigger than keyLen");const{key:s,salt:o,personalization:a}=e;if(s!==void 0&&(s.length<1||s.length>n))throw new Error("key length must be undefined or 1.."+n);if(o!==void 0&&o.length!==r)throw new Error("salt must be undefined or "+r);if(a!==void 0&&a.length!==i)throw new Error("personalization must be undefined or "+i)}class hT extends Wf{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,Or(e),Or(n),this.blockLen=e,this.outputLen=n,this.buffer=new Uint8Array(e),this.buffer32=Na(this.buffer)}update(e){Ci(this),e=Un(e),Nn(e);const{blockLen:n,buffer:r,buffer32:i}=this,s=e.length,o=e.byteOffset,a=e.buffer;for(let c=0;c<s;){this.pos===n&&(Li(i),this.compress(i,0,!1),Li(i),this.pos=0);const f=Math.min(n-this.pos,s-c),l=o+c;if(f===n&&!(l%4)&&c+f<s){const h=new Uint32Array(a,l,Math.floor((s-c)/4));Li(h);for(let d=0;c+n<s;d+=i.length,c+=n)this.length+=n,this.compress(h,d,!1);Li(h);continue}r.set(e.subarray(c,c+f),this.pos),this.pos+=f,this.length+=f,c+=f}return this}digestInto(e){Ci(this),Hd(e,this);const{pos:n,buffer32:r}=this;this.finished=!0,bn(this.buffer.subarray(n)),Li(r),this.compress(r,0,!0),Li(r);const i=Na(e);this.get().forEach((s,o)=>i[o]=Dr(s))}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}_cloneInto(e){const{buffer:n,length:r,finished:i,destroyed:s,outputLen:o,pos:a}=this;return e||(e=new this.constructor({dkLen:o})),e.set(...this.get()),e.buffer.set(n),e.destroyed=s,e.finished=i,e.length=r,e.pos=a,e.outputLen=o,e}clone(){return this._cloneInto()}}class dT extends hT{constructor(e={}){const n=e.dkLen===void 0?64:e.dkLen;super(128,n),this.v0l=Me[0]|0,this.v0h=Me[1]|0,this.v1l=Me[2]|0,this.v1h=Me[3]|0,this.v2l=Me[4]|0,this.v2h=Me[5]|0,this.v3l=Me[6]|0,this.v3h=Me[7]|0,this.v4l=Me[8]|0,this.v4h=Me[9]|0,this.v5l=Me[10]|0,this.v5h=Me[11]|0,this.v6l=Me[12]|0,this.v6h=Me[13]|0,this.v7l=Me[14]|0,this.v7h=Me[15]|0,lT(n,e,64,16,16);let{key:r,personalization:i,salt:s}=e,o=0;if(r!==void 0&&(r=Un(r),o=r.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=Un(s);const a=Na(s);this.v4l^=Dr(a[0]),this.v4h^=Dr(a[1]),this.v5l^=Dr(a[2]),this.v5h^=Dr(a[3])}if(i!==void 0){i=Un(i);const a=Na(i);this.v6l^=Dr(a[0]),this.v6h^=Dr(a[1]),this.v7l^=Dr(a[2]),this.v7h^=Dr(a[3])}if(r!==void 0){const a=new Uint8Array(this.blockLen);a.set(r),this.update(a)}}get(){let{v0l:e,v0h:n,v1l:r,v1h:i,v2l:s,v2h:o,v3l:a,v3h:c,v4l:f,v4h:l,v5l:h,v5h:d,v6l:u,v6h:b,v7l:w,v7h:E}=this;return[e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E]}set(e,n,r,i,s,o,a,c,f,l,h,d,u,b,w,E){this.v0l=e|0,this.v0h=n|0,this.v1l=r|0,this.v1h=i|0,this.v2l=s|0,this.v2h=o|0,this.v3l=a|0,this.v3h=c|0,this.v4l=f|0,this.v4h=l|0,this.v5l=h|0,this.v5h=d|0,this.v6l=u|0,this.v6h=b|0,this.v7l=w|0,this.v7h=E|0}compress(e,n,r){this.get().forEach((c,f)=>Q[f]=c),Q.set(Me,16);let{h:i,l:s}=Bm(BigInt(this.length));Q[24]=Me[8]^s,Q[25]=Me[9]^i,r&&(Q[28]=~Q[28],Q[29]=~Q[29]);let o=0;const a=uT;for(let c=0;c<12;c++)zi(0,4,8,12,e,n+2*a[o++]),Hi(0,4,8,12,e,n+2*a[o++]),zi(1,5,9,13,e,n+2*a[o++]),Hi(1,5,9,13,e,n+2*a[o++]),zi(2,6,10,14,e,n+2*a[o++]),Hi(2,6,10,14,e,n+2*a[o++]),zi(3,7,11,15,e,n+2*a[o++]),Hi(3,7,11,15,e,n+2*a[o++]),zi(0,5,10,15,e,n+2*a[o++]),Hi(0,5,10,15,e,n+2*a[o++]),zi(1,6,11,12,e,n+2*a[o++]),Hi(1,6,11,12,e,n+2*a[o++]),zi(2,7,8,13,e,n+2*a[o++]),Hi(2,7,8,13,e,n+2*a[o++]),zi(3,4,9,14,e,n+2*a[o++]),Hi(3,4,9,14,e,n+2*a[o++]);this.v0l^=Q[0]^Q[16],this.v0h^=Q[1]^Q[17],this.v1l^=Q[2]^Q[18],this.v1h^=Q[3]^Q[19],this.v2l^=Q[4]^Q[20],this.v2h^=Q[5]^Q[21],this.v3l^=Q[6]^Q[22],this.v3h^=Q[7]^Q[23],this.v4l^=Q[8]^Q[24],this.v4h^=Q[9]^Q[25],this.v5l^=Q[10]^Q[26],this.v5h^=Q[11]^Q[27],this.v6l^=Q[12]^Q[28],this.v6h^=Q[13]^Q[29],this.v7l^=Q[14]^Q[30],this.v7h^=Q[15]^Q[31],bn(Q)}destroy(){this.destroyed=!0,bn(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const pT=jR(t=>new dT(t)),gT="https://rpc.walletconnect.org/v1";function zm(t){const e=`Ethereum Signed Message:
21
+ ${t.length}`,n=new TextEncoder().encode(e+t);return"0x"+Buffer.from(XR(n)).toString("hex")}async function bT(t,e,n,r,i,s){switch(n.t){case"eip191":return await yT(t,e,n.s);case"eip1271":return await wT(t,e,n.s,r,i,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}function yT(t,e,n){const r=DP(n);return GP({payload:zm(e),signature:r}).toLowerCase()===t.toLowerCase()}async function wT(t,e,n,r,i,s){const o=zf(r);if(!o.namespace||!o.reference)throw new Error(`isValidEip1271Signature failed: chainId must be in CAIP-2 format, received: ${r}`);try{const a="0x1626ba7e",c="0000000000000000000000000000000000000000000000000000000000000040",f=n.substring(2),l=(f.length/2).toString(16).padStart(64,"0"),h=(e.startsWith("0x")?e:zm(e)).substring(2),d=a+h+c+l+f,u=await fetch(`${s||gT}/?chainId=${r}&projectId=${i}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify({id:mT(),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:d},"latest"]})}),{result:b}=await u.json();return b?b.slice(0,a.length).toLowerCase()===a.toLowerCase():!1}catch(a){return console.error("isValidEip1271Signature: ",a),!1}}function mT(){return Date.now()+Math.floor(Math.random()*1e3)}function vT(t){const e=atob(t),n=new Uint8Array(e.length);for(let o=0;o<e.length;o++)n[o]=e.charCodeAt(o);const r=n[0];if(r===0)throw new Error("No signatures found");const i=1+r*64;if(n.length<i)throw new Error("Transaction data too short for claimed signature count");if(n.length<100)throw new Error("Transaction too short");const s=Buffer.from(t,"base64").slice(1,65);return Jo.encode(s)}function ET(t){const e=new Uint8Array(Buffer.from(t,"base64")),n=Array.from("TransactionData::").map(s=>s.charCodeAt(0)),r=new Uint8Array(n.length+e.length);r.set(n),r.set(e,n.length);const i=pT(r,{dkLen:32});return Jo.encode(i)}function Hm(t){const e=new Uint8Array(Yf(xT(t)));return Jo.encode(e)}function xT(t){if(t instanceof Uint8Array)return t;if(Array.isArray(t))return new Uint8Array(t);if(typeof t=="object"&&t!=null&&t.data)return new Uint8Array(Object.values(t.data));if(typeof t=="object"&&t)return new Uint8Array(Object.values(t));throw new Error("getNearUint8ArrayFromBytes: Unexpected result type from bytes array")}function Vm(t){const e=Buffer.from(t,"base64"),n=Qx(e).txn;if(!n)throw new Error("Invalid signed transaction: missing 'txn' field");const r=Vx(n),i=Buffer.from("TX"),s=Buffer.concat([i,Buffer.from(r)]),o=fT(s);return Q5.encode(o).replace(/=+$/,"")}function Zd(t){const e=[];let n=BigInt(t);for(;n>=BigInt(128);)e.push(Number(n&BigInt(127)|BigInt(128))),n>>=BigInt(7);return e.push(Number(n)),Buffer.from(e)}function _T(t){const e=Buffer.from(t.signed.bodyBytes,"base64"),n=Buffer.from(t.signed.authInfoBytes,"base64"),r=Buffer.from(t.signature.signature,"base64"),i=[];i.push(Buffer.from([10])),i.push(Zd(e.length)),i.push(e),i.push(Buffer.from([18])),i.push(Zd(n.length)),i.push(n),i.push(Buffer.from([26])),i.push(Zd(r.length)),i.push(r);const s=Buffer.concat(i),o=Yf(s);return Buffer.from(o).toString("hex").toUpperCase()}function ST(t){var e,n;const r=[];try{if(typeof t=="string")return r.push(t),r;if(typeof t!="object")return r;t!=null&&t.id&&r.push(t.id);const i=(n=(e=t?.capabilities)==null?void 0:e.caip345)==null?void 0:n.transactionHashes;i&&r.push(...i)}catch(i){console.warn("getWalletSendCallsHashes failed: ",i)}return r}var IT=Object.defineProperty,BT=Object.defineProperties,$T=Object.getOwnPropertyDescriptors,Km=Object.getOwnPropertySymbols,AT=Object.prototype.hasOwnProperty,OT=Object.prototype.propertyIsEnumerable,Gm=(t,e,n)=>e in t?IT(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,DT=(t,e)=>{for(var n in e||(e={}))AT.call(e,n)&&Gm(t,n,e[n]);if(Km)for(var n of Km(e))OT.call(e,n)&&Gm(t,n,e[n]);return t},PT=(t,e)=>BT(t,$T(e));const Zm="did:pkh:",RT={eip155:"Ethereum",solana:"Solana",bip122:"Bitcoin"},TT=t=>t?RT[t]||t:"",Xf=t=>t?.split(":"),NT=t=>{const e=t&&Xf(t);if(e)return t.includes(Zm)?e[3]:e[1]},UT=t=>{const e=t&&Xf(t);if(e)return t.includes(Zm)?e[2]:e[0]},Wd=t=>{const e=t&&Xf(t);if(e)return e[2]+":"+e[3]},Jf=t=>{const e=t&&Xf(t);if(e)return e.pop()};async function Wm(t){const{cacao:e,projectId:n}=t,{s:r,p:i}=e,s=Ym(i,i.iss),o=Jf(i.iss);return await bT(o,s,r,Wd(i.iss),n)}const Ym=(t,e)=>{const n=UT(e);if(!n)throw new Error("Invalid issuer: "+e);const r=`${t.domain} wants you to sign in with your ${TT(n)} account:`,i=Jf(e);if(!t.aud&&!t.uri)throw new Error("Either `aud` or `uri` is required to construct the message");let s=t.statement||void 0;const o=`URI: ${t.aud||t.uri}`,a=`Version: ${t.version}`,c=`Chain ID: ${NT(e)}`,f=`Nonce: ${t.nonce}`,l=`Issued At: ${t.iat}`,h=t.exp?`Expiration Time: ${t.exp}`:void 0,d=t.nbf?`Not Before: ${t.nbf}`:void 0,u=t.requestId?`Request ID: ${t.requestId}`:void 0,b=t.resources?`Resources:${t.resources.map(E=>`
22
+ - ${E}`).join("")}`:void 0,w=Qf(t.resources);if(w){const E=La(w);s=HT(s,E)}return[r,i,"",s,"",o,a,c,f,l,h,d,u,b].filter(E=>E!=null).join(`
23
+ `)};function CT(t){return Buffer.from(JSON.stringify(t)).toString("base64")}function LT(t){return JSON.parse(Buffer.from(t,"base64").toString("utf-8"))}function Is(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(n=>{const r=t.att[n];if(Array.isArray(r))throw new Error(`Resource must be an object: ${n}`);if(typeof r!="object")throw new Error(`Resource must be an object: ${n}`);if(!Object.keys(r).length)throw new Error(`Resource object is empty: ${n}`);Object.keys(r).forEach(i=>{const s=r[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 FT(t,e,n,r={}){return n?.sort((i,s)=>i.localeCompare(s)),{att:{[t]:kT(e,n,r)}}}function kT(t,e,n={}){e=e?.sort((i,s)=>i.localeCompare(s));const r=e.map(i=>({[`${t}/${i}`]:[n]}));return Object.assign({},...r)}function Xm(t){return Is(t),`urn:recap:${CT(t).replace(/=/g,"")}`}function La(t){const e=LT(t.replace("urn:recap:",""));return Is(e),e}function qT(t,e,n){const r=FT(t,e,n);return Xm(r)}function jT(t){return t&&t.includes("urn:recap:")}function MT(t,e){const n=La(t),r=La(e),i=zT(n,r);return Xm(i)}function zT(t,e){Is(t),Is(e);const n=Object.keys(t.att).concat(Object.keys(e.att)).sort((i,s)=>i.localeCompare(s)),r={att:{}};return n.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,f;r.att[i]=PT(DT({},r.att[i]),{[a]:((c=t.att[i])==null?void 0:c[a])||((f=e.att[i])==null?void 0:f[a])})})}),r}function HT(t="",e){Is(e);const n="I further authorize the stated URI to perform the following actions on my behalf: ";if(t.includes(n))return t;const r=[];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 f={};c.forEach(h=>{f[h.ability]||(f[h.ability]=[]),f[h.ability].push(h.action)});const l=Object.keys(f).map(h=>(i++,`(${i}) '${h}': '${f[h].join("', '")}' for '${a}'.`));r.push(l.join(", ").replace(".,","."))});const s=r.join(" "),o=`${n}${s}`;return`${t?t+" ":""}${o}`}function Jm(t){var e;const n=La(t);Is(n);const r=(e=n.att)==null?void 0:e.eip155;return r?Object.keys(r).map(i=>i.split("/")[1]):[]}function Qm(t){const e=La(t);Is(e);const n=[];return Object.values(e.att).forEach(r=>{Object.values(r).forEach(i=>{var s;(s=i?.[0])!=null&&s.chains&&n.push(i[0].chains)})}),[...new Set(n.flat())]}function Qf(t){if(!t)return;const e=t?.[t.length-1];return jT(e)?e:void 0}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function e3(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Yd(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function Xd(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Wt(t,...e){if(!e3(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 t3(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 VT(t,e){Wt(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Vi(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Eo(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function KT(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const GT=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ZT(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Jd(t){if(typeof t=="string")t=ZT(t);else if(e3(t))t=Qd(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function WT(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function YT(t,e){if(t.length!==e.length)return!1;let n=0;for(let r=0;r<t.length;r++)n|=t[r]^e[r];return n===0}const XT=(t,e)=>{function n(r,...i){if(Wt(r),!GT)throw new Error("Non little-endian hardware is not yet supported");if(t.nonceLength!==void 0){const f=i[0];if(!f)throw new Error("nonce / iv required");t.varSizeNonce?Wt(f):Wt(f,t.nonceLength)}const s=t.tagLength;s&&i[1]!==void 0&&Wt(i[1]);const o=e(r,...i),a=(f,l)=>{if(l!==void 0){if(f!==2)throw new Error("cipher output not supported");Wt(l)}};let c=!1;return{encrypt(f,l){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Wt(f),a(o.encrypt.length,l),o.encrypt(f,l)},decrypt(f,l){if(Wt(f),s&&f.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return a(o.decrypt.length,l),o.decrypt(f,l)}}}return Object.assign(n,t),n};function n3(t,e,n=!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(n&&!QT(e))throw new Error("invalid output, must be aligned");return e}function r3(t,e,n,r){if(typeof t.setBigUint64=="function")return t.setBigUint64(e,n,r);const i=BigInt(32),s=BigInt(4294967295),o=Number(n>>i&s),a=Number(n&s),c=r?4:0,f=r?0:4;t.setUint32(e+c,o,r),t.setUint32(e+f,a,r)}function JT(t,e,n){Yd(n);const r=new Uint8Array(16),i=KT(r);return r3(i,0,BigInt(e),n),r3(i,8,BigInt(t),n),r}function QT(t){return t.byteOffset%4===0}function Qd(t){return Uint8Array.from(t)}const i3=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),eN=i3("expand 16-byte k"),tN=i3("expand 32-byte k"),nN=Vi(eN),rN=Vi(tN);function ge(t,e){return t<<e|t>>>32-e}function e0(t){return t.byteOffset%4===0}const eu=64,iN=16,s3=2**32-1,o3=new Uint32Array;function sN(t,e,n,r,i,s,o,a){const c=i.length,f=new Uint8Array(eu),l=Vi(f),h=e0(i)&&e0(s),d=h?Vi(i):o3,u=h?Vi(s):o3;for(let b=0;b<c;o++){if(t(e,n,r,l,o,a),o>=s3)throw new Error("arx: counter overflow");const w=Math.min(eu,c-b);if(h&&w===eu){const E=b/4;if(b%4!==0)throw new Error("arx: invalid block position");for(let A=0,P;A<iN;A++)P=E+A,u[P]=d[P]^l[A];b+=eu;continue}for(let E=0,A;E<w;E++)A=b+E,s[A]=i[A]^f[E];b+=w}}function oN(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=WT({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Xd(i),Xd(o),Yd(s),Yd(n),(a,c,f,l,h=0)=>{Wt(a),Wt(c),Wt(f);const d=f.length;if(l===void 0&&(l=new Uint8Array(d)),Wt(l),Xd(h),h<0||h>=s3)throw new Error("arx: counter overflow");if(l.length<d)throw new Error(`arx: output (${l.length}) is shorter than data (${d})`);const u=[];let b=a.length,w,E;if(b===32)u.push(w=Qd(a)),E=rN;else if(b===16&&n)w=new Uint8Array(32),w.set(a),w.set(a,16),E=nN,u.push(w);else throw new Error(`arx: invalid 32-byte key, got length=${b}`);e0(c)||u.push(c=Qd(c));const A=Vi(w);if(r){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(E,A,Vi(c.subarray(0,16)),A),c=c.subarray(16)}const P=16-i;if(P!==c.length)throw new Error(`arx: nonce must be ${P} or 16 bytes`);if(P!==12){const x=new Uint8Array(12);x.set(c,s?0:12-c.length),c=x,u.push(c)}const _=Vi(c);return sN(t,E,A,_,f,l,h,o),Eo(...u),l}}const tt=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class aN{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=Jd(e),Wt(e,32);const n=tt(e,0),r=tt(e,2),i=tt(e,4),s=tt(e,6),o=tt(e,8),a=tt(e,10),c=tt(e,12),f=tt(e,14);this.r[0]=n&8191,this.r[1]=(n>>>13|r<<3)&8191,this.r[2]=(r>>>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|f<<8)&8191,this.r[9]=f>>>5&127;for(let l=0;l<8;l++)this.pad[l]=tt(e,16+2*l)}process(e,n,r=!1){const i=r?0:2048,{h:s,r:o}=this,a=o[0],c=o[1],f=o[2],l=o[3],h=o[4],d=o[5],u=o[6],b=o[7],w=o[8],E=o[9],A=tt(e,n+0),P=tt(e,n+2),_=tt(e,n+4),x=tt(e,n+6),D=tt(e,n+8),U=tt(e,n+10),C=tt(e,n+12),L=tt(e,n+14);let O=s[0]+(A&8191),M=s[1]+((A>>>13|P<<3)&8191),q=s[2]+((P>>>10|_<<6)&8191),y=s[3]+((_>>>7|x<<9)&8191),p=s[4]+((x>>>4|D<<12)&8191),m=s[5]+(D>>>1&8191),g=s[6]+((D>>>14|U<<2)&8191),v=s[7]+((U>>>11|C<<5)&8191),S=s[8]+((C>>>8|L<<8)&8191),B=s[9]+(L>>>5|i),I=0,$=I+O*a+M*(5*E)+q*(5*w)+y*(5*b)+p*(5*u);I=$>>>13,$&=8191,$+=m*(5*d)+g*(5*h)+v*(5*l)+S*(5*f)+B*(5*c),I+=$>>>13,$&=8191;let T=I+O*c+M*a+q*(5*E)+y*(5*w)+p*(5*b);I=T>>>13,T&=8191,T+=m*(5*u)+g*(5*d)+v*(5*h)+S*(5*l)+B*(5*f),I+=T>>>13,T&=8191;let F=I+O*f+M*c+q*a+y*(5*E)+p*(5*w);I=F>>>13,F&=8191,F+=m*(5*b)+g*(5*u)+v*(5*d)+S*(5*h)+B*(5*l),I+=F>>>13,F&=8191;let N=I+O*l+M*f+q*c+y*a+p*(5*E);I=N>>>13,N&=8191,N+=m*(5*w)+g*(5*b)+v*(5*u)+S*(5*d)+B*(5*h),I+=N>>>13,N&=8191;let k=I+O*h+M*l+q*f+y*c+p*a;I=k>>>13,k&=8191,k+=m*(5*E)+g*(5*w)+v*(5*b)+S*(5*u)+B*(5*d),I+=k>>>13,k&=8191;let R=I+O*d+M*h+q*l+y*f+p*c;I=R>>>13,R&=8191,R+=m*a+g*(5*E)+v*(5*w)+S*(5*b)+B*(5*u),I+=R>>>13,R&=8191;let j=I+O*u+M*d+q*h+y*l+p*f;I=j>>>13,j&=8191,j+=m*c+g*a+v*(5*E)+S*(5*w)+B*(5*b),I+=j>>>13,j&=8191;let z=I+O*b+M*u+q*d+y*h+p*l;I=z>>>13,z&=8191,z+=m*f+g*c+v*a+S*(5*E)+B*(5*w),I+=z>>>13,z&=8191;let V=I+O*w+M*b+q*u+y*d+p*h;I=V>>>13,V&=8191,V+=m*l+g*f+v*c+S*a+B*(5*E),I+=V>>>13,V&=8191;let H=I+O*E+M*w+q*b+y*u+p*d;I=H>>>13,H&=8191,H+=m*h+g*l+v*f+S*c+B*a,I+=H>>>13,H&=8191,I=(I<<2)+I|0,I=I+$|0,$=I&8191,I=I>>>13,T+=I,s[0]=$,s[1]=T,s[2]=F,s[3]=N,s[4]=k,s[5]=R,s[6]=j,s[7]=z,s[8]=V,s[9]=H}finalize(){const{h:e,pad:n}=this,r=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,r[0]=e[0]+5,i=r[0]>>>13,r[0]&=8191;for(let a=1;a<10;a++)r[a]=e[a]+i,i=r[a]>>>13,r[a]&=8191;r[9]-=8192;let s=(i^1)-1;for(let a=0;a<10;a++)r[a]&=s;s=~s;for(let a=0;a<10;a++)e[a]=e[a]&s|r[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]+n[0];e[0]=o&65535;for(let a=1;a<8;a++)o=(e[a]+n[a]|0)+(o>>>16)|0,e[a]=o&65535;Eo(r)}update(e){t3(this),e=Jd(e),Wt(e);const{buffer:n,blockLen:r}=this,i=e.length;for(let s=0;s<i;){const o=Math.min(r-this.pos,i-s);if(o===r){for(;r<=i-s;s+=r)this.process(e,s);continue}n.set(e.subarray(s,s+o),this.pos),this.pos+=o,s+=o,this.pos===r&&(this.process(n,0,!1),this.pos=0)}return this}destroy(){Eo(this.h,this.r,this.buffer,this.pad)}digestInto(e){t3(this),VT(e,this),this.finished=!0;const{buffer:n,h:r}=this;let{pos:i}=this;if(i){for(n[i++]=1;i<16;i++)n[i]=0;this.process(n,0,!0)}this.finalize();let s=0;for(let o=0;o<8;o++)e[s++]=r[o]>>>0,e[s++]=r[o]>>>8;return e}digest(){const{buffer:e,outputLen:n}=this;this.digestInto(e);const r=e.slice(0,n);return this.destroy(),r}}function cN(t){const e=(r,i)=>t(i).update(Jd(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}const fN=cN(t=>new aN(t));function uN(t,e,n,r,i,s=20){let o=t[0],a=t[1],c=t[2],f=t[3],l=e[0],h=e[1],d=e[2],u=e[3],b=e[4],w=e[5],E=e[6],A=e[7],P=i,_=n[0],x=n[1],D=n[2],U=o,C=a,L=c,O=f,M=l,q=h,y=d,p=u,m=b,g=w,v=E,S=A,B=P,I=_,$=x,T=D;for(let N=0;N<s;N+=2)U=U+M|0,B=ge(B^U,16),m=m+B|0,M=ge(M^m,12),U=U+M|0,B=ge(B^U,8),m=m+B|0,M=ge(M^m,7),C=C+q|0,I=ge(I^C,16),g=g+I|0,q=ge(q^g,12),C=C+q|0,I=ge(I^C,8),g=g+I|0,q=ge(q^g,7),L=L+y|0,$=ge($^L,16),v=v+$|0,y=ge(y^v,12),L=L+y|0,$=ge($^L,8),v=v+$|0,y=ge(y^v,7),O=O+p|0,T=ge(T^O,16),S=S+T|0,p=ge(p^S,12),O=O+p|0,T=ge(T^O,8),S=S+T|0,p=ge(p^S,7),U=U+q|0,T=ge(T^U,16),v=v+T|0,q=ge(q^v,12),U=U+q|0,T=ge(T^U,8),v=v+T|0,q=ge(q^v,7),C=C+y|0,B=ge(B^C,16),S=S+B|0,y=ge(y^S,12),C=C+y|0,B=ge(B^C,8),S=S+B|0,y=ge(y^S,7),L=L+p|0,I=ge(I^L,16),m=m+I|0,p=ge(p^m,12),L=L+p|0,I=ge(I^L,8),m=m+I|0,p=ge(p^m,7),O=O+M|0,$=ge($^O,16),g=g+$|0,M=ge(M^g,12),O=O+M|0,$=ge($^O,8),g=g+$|0,M=ge(M^g,7);let F=0;r[F++]=o+U|0,r[F++]=a+C|0,r[F++]=c+L|0,r[F++]=f+O|0,r[F++]=l+M|0,r[F++]=h+q|0,r[F++]=d+y|0,r[F++]=u+p|0,r[F++]=b+m|0,r[F++]=w+g|0,r[F++]=E+v|0,r[F++]=A+S|0,r[F++]=P+B|0,r[F++]=_+I|0,r[F++]=x+$|0,r[F++]=D+T|0}const lN=oN(uN,{counterRight:!1,counterLength:4,allowShortKeys:!1}),hN=new Uint8Array(16),a3=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(hN.subarray(n))},dN=new Uint8Array(32);function c3(t,e,n,r,i){const s=t(e,n,dN),o=fN.create(s);i&&a3(o,i),a3(o,r);const a=JT(r.length,i?i.length:0,!0);o.update(a);const c=o.digest();return Eo(s,a),c}const pN=t=>(e,n,r)=>({encrypt(i,s){const o=i.length;s=n3(o+16,s,!1),s.set(i);const a=s.subarray(0,-16);t(e,n,a,a,1);const c=c3(t,e,n,a,r);return s.set(c,o),Eo(c),s},decrypt(i,s){s=n3(i.length-16,s,!1);const o=i.subarray(0,-16),a=i.subarray(-16),c=c3(t,e,n,o,r);if(!YT(a,c))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),t(e,n,s,s,1),Eo(c),s}}),f3=XT({blockSize:64,nonceLength:12,tagLength:16},pN(lN));class u3 extends Wf{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Gf(e);const r=Un(n);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(r.length>i?e.create().update(r).digest():r);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),bn(s)}update(e){return Ci(this),this.iHash.update(e),this}digestInto(e){Ci(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:n,iHash:r,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=n._cloneInto(e.oHash),e.iHash=r._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}const tu=(t,e,n)=>new u3(t,e).update(n).digest();tu.create=(t,e)=>new u3(t,e);function gN(t,e,n){return Gf(t),n===void 0&&(n=new Uint8Array(t.outputLen)),tu(t,Un(n),Un(e))}const t0=Uint8Array.from([0]),l3=Uint8Array.of();function bN(t,e,n,r=32){Gf(t),Or(r);const i=t.outputLen;if(r>255*i)throw new Error("Length should be <= 255*HashLen");const s=Math.ceil(r/i);n===void 0&&(n=l3);const o=new Uint8Array(s*i),a=tu.create(t,e),c=a._cloneInto(),f=new Uint8Array(a.outputLen);for(let l=0;l<s;l++)t0[0]=l+1,c.update(l===0?l3:f).update(n).update(t0).digestInto(f),o.set(f,i*l),a._cloneInto(c);return a.destroy(),c.destroy(),bn(f,t0),o.slice(0,r)}const yN=(t,e,n,r,i)=>bN(t,gN(t,e,n),r,i),nu=Yf,n0=BigInt(0),r0=BigInt(1);function ru(t,e=""){if(typeof t!="boolean"){const n=e&&`"${e}"`;throw new Error(n+"expected boolean, got type="+typeof t)}return t}function Bs(t,e,n=""){const r=Kf(t),i=t?.length,s=e!==void 0;if(!r||s&&i!==e){const o=n&&`"${n}" `,a=s?` of length ${e}`:"",c=r?`length=${i}`:`type=${typeof t}`;throw new Error(o+"expected Uint8Array"+a+", got "+c)}return t}function iu(t){const e=t.toString(16);return e.length&1?"0"+e:e}function h3(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?n0:BigInt("0x"+t)}function su(t){return h3(vo(t))}function ou(t){return Nn(t),h3(vo(Uint8Array.from(t).reverse()))}function i0(t,e){return Zf(t.toString(16).padStart(e*2,"0"))}function s0(t,e){return i0(t,e).reverse()}function _t(t,e,n){let r;if(typeof e=="string")try{r=Zf(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Kf(e))r=Uint8Array.from(e);else throw new Error(t+" must be hex string or Uint8Array");const i=r.length;if(typeof n=="number"&&i!==n)throw new Error(t+" of length "+n+" expected, got "+i);return r}const o0=t=>typeof t=="bigint"&&n0<=t;function wN(t,e,n){return o0(t)&&o0(e)&&o0(n)&&e<=t&&t<n}function a0(t,e,n,r){if(!wN(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function d3(t){let e;for(e=0;t>n0;t>>=r0,e+=1);return e}const Fa=t=>(r0<<BigInt(t))-r0;function mN(t,e,n){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 n!="function")throw new Error("hmacFn must be a function");const r=d=>new Uint8Array(d),i=d=>Uint8Array.of(d);let s=r(t),o=r(t),a=0;const c=()=>{s.fill(1),o.fill(0),a=0},f=(...d)=>n(o,s,...d),l=(d=r(0))=>{o=f(i(0),d),s=f(),d.length!==0&&(o=f(i(1),d),s=f())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let d=0;const u=[];for(;d<e;){s=f();const b=s.slice();u.push(b),d+=s.length}return Fi(...u)};return(d,u)=>{c(),l(d);let b;for(;!(b=u(h()));)l();return c(),b}}function au(t,e,n={}){if(!t||typeof t!="object")throw new Error("expected valid options object");function r(i,s,o){const a=t[i];if(o&&a===void 0)return;const c=typeof a;if(c!==s||a===null)throw new Error(`param "${i}" is invalid: expected ${s}, got ${c}`)}Object.entries(e).forEach(([i,s])=>r(i,s,!1)),Object.entries(n).forEach(([i,s])=>r(i,s,!0))}function p3(t){const e=new WeakMap;return(n,...r)=>{const i=e.get(n);if(i!==void 0)return i;const s=t(n,...r);return e.set(n,s),s}}const Yt=BigInt(0),Ct=BigInt(1),$s=BigInt(2),g3=BigInt(3),b3=BigInt(4),y3=BigInt(5),vN=BigInt(7),w3=BigInt(8),EN=BigInt(9),m3=BigInt(16);function an(t,e){const n=t%e;return n>=Yt?n:e+n}function Cn(t,e,n){let r=t;for(;e-- >Yt;)r*=r,r%=n;return r}function v3(t,e){if(t===Yt)throw new Error("invert: expected non-zero number");if(e<=Yt)throw new Error("invert: expected positive modulus, got "+e);let n=an(t,e),r=e,i=Yt,s=Ct;for(;n!==Yt;){const o=r/n,a=r%n,c=i-s*o;r=n,n=a,i=s,s=c}if(r!==Ct)throw new Error("invert: does not exist");return an(i,e)}function c0(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function E3(t,e){const n=(t.ORDER+Ct)/b3,r=t.pow(e,n);return c0(t,r,e),r}function xN(t,e){const n=(t.ORDER-y3)/w3,r=t.mul(e,$s),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,$s),i),a=t.mul(s,t.sub(o,t.ONE));return c0(t,a,e),a}function _N(t){const e=Ki(t),n=x3(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+vN)/m3;return(a,c)=>{let f=a.pow(c,o),l=a.mul(f,r);const h=a.mul(f,i),d=a.mul(f,s),u=a.eql(a.sqr(l),c),b=a.eql(a.sqr(h),c);f=a.cmov(f,l,u),l=a.cmov(d,h,b);const w=a.eql(a.sqr(l),c),E=a.cmov(f,l,w);return c0(a,E,c),E}}function x3(t){if(t<g3)throw new Error("sqrt is not defined for small field");let e=t-Ct,n=0;for(;e%$s===Yt;)e/=$s,n++;let r=$s;const i=Ki(t);for(;S3(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return E3;let s=i.pow(r,e);const o=(e+Ct)/$s;return function(a,c){if(a.is0(c))return c;if(S3(a,c)!==1)throw new Error("Cannot find square root");let f=n,l=a.mul(a.ONE,s),h=a.pow(c,e),d=a.pow(c,o);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let u=1,b=a.sqr(h);for(;!a.eql(b,a.ONE);)if(u++,b=a.sqr(b),u===f)throw new Error("Cannot find square root");const w=Ct<<BigInt(f-u-1),E=a.pow(l,w);f=u,l=a.sqr(E),h=a.mul(h,l),d=a.mul(d,E)}return d}}function SN(t){return t%b3===g3?E3:t%w3===y3?xN:t%m3===EN?_N(t):x3(t)}const IN=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function BN(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=IN.reduce((r,i)=>(r[i]="function",r),e);return au(t,n),t}function $N(t,e,n){if(n<Yt)throw new Error("invalid exponent, negatives unsupported");if(n===Yt)return t.ONE;if(n===Ct)return e;let r=t.ONE,i=e;for(;n>Yt;)n&Ct&&(r=t.mul(r,i)),i=t.sqr(i),n>>=Ct;return r}function _3(t,e,n=!1){const r=new Array(e.length).fill(n?t.ZERO:void 0),i=e.reduce((o,a,c)=>t.is0(a)?o:(r[c]=o,t.mul(o,a)),t.ONE),s=t.inv(i);return e.reduceRight((o,a,c)=>t.is0(a)?o:(r[c]=t.mul(o,r[c]),t.mul(o,a)),s),r}function S3(t,e){const n=(t.ORDER-Ct)/$s,r=t.pow(e,n),i=t.eql(r,t.ONE),s=t.eql(r,t.ZERO),o=t.eql(r,t.neg(t.ONE));if(!i&&!s&&!o)throw new Error("invalid Legendre symbol result");return i?1:s?0:-1}function I3(t,e){e!==void 0&&Or(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Ki(t,e,n=!1,r={}){if(t<=Yt)throw new Error("invalid field: expected ORDER > 0, got "+t);let i,s,o=!1,a;if(typeof e=="object"&&e!=null){if(r.sqrt||n)throw new Error("cannot specify opts in two arguments");const d=e;d.BITS&&(i=d.BITS),d.sqrt&&(s=d.sqrt),typeof d.isLE=="boolean"&&(n=d.isLE),typeof d.modFromBytes=="boolean"&&(o=d.modFromBytes),a=d.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:f}=I3(t,i);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let l;const h=Object.freeze({ORDER:t,isLE:n,BITS:c,BYTES:f,MASK:Fa(c),ZERO:Yt,ONE:Ct,allowedLengths:a,create:d=>an(d,t),isValid:d=>{if(typeof d!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof d);return Yt<=d&&d<t},is0:d=>d===Yt,isValidNot0:d=>!h.is0(d)&&h.isValid(d),isOdd:d=>(d&Ct)===Ct,neg:d=>an(-d,t),eql:(d,u)=>d===u,sqr:d=>an(d*d,t),add:(d,u)=>an(d+u,t),sub:(d,u)=>an(d-u,t),mul:(d,u)=>an(d*u,t),pow:(d,u)=>$N(h,d,u),div:(d,u)=>an(d*v3(u,t),t),sqrN:d=>d*d,addN:(d,u)=>d+u,subN:(d,u)=>d-u,mulN:(d,u)=>d*u,inv:d=>v3(d,t),sqrt:s||(d=>(l||(l=SN(t)),l(h,d))),toBytes:d=>n?s0(d,f):i0(d,f),fromBytes:(d,u=!0)=>{if(a){if(!a.includes(d.length)||d.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+d.length);const w=new Uint8Array(f);w.set(d,n?0:w.length-d.length),d=w}if(d.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+d.length);let b=n?ou(d):su(d);if(o&&(b=an(b,t)),!u&&!h.isValid(b))throw new Error("invalid field element: outside of range 0..ORDER");return b},invertBatch:d=>_3(h,d),cmov:(d,u,b)=>b?u:d});return Object.freeze(h)}function B3(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 $3(t){const e=B3(t);return e+Math.ceil(e/2)}function AN(t,e,n=!1){const r=t.length,i=B3(e),s=$3(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?ou(t):su(t),a=an(o,e-Ct)+Ct;return n?s0(a,i):i0(a,i)}const xo=BigInt(0),As=BigInt(1);function cu(t,e){const n=e.negate();return t?n:e}function f0(t,e){const n=_3(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function A3(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function u0(t,e){A3(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=Fa(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function O3(t,e,n){const{windowSize:r,mask:i,maxNumber:s,shiftBy:o}=n;let a=Number(t&i),c=t>>o;a>r&&(a-=s,c+=As);const f=e*r,l=f+Math.abs(a)-1,h=a===0,d=a<0,u=e%2!==0;return{nextN:c,offset:l,isZero:h,isNeg:d,isNegF:u,offsetF:f}}function ON(t,e){if(!Array.isArray(t))throw new Error("array expected");t.forEach((n,r)=>{if(!(n instanceof e))throw new Error("invalid point at index "+r)})}function DN(t,e){if(!Array.isArray(t))throw new Error("array of scalars expected");t.forEach((n,r)=>{if(!e.isValid(n))throw new Error("invalid scalar at index "+r)})}const l0=new WeakMap,D3=new WeakMap;function h0(t){return D3.get(t)||1}function P3(t){if(t!==xo)throw new Error("invalid wNAF")}class PN{constructor(e,n){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=n}_unsafeLadder(e,n,r=this.ZERO){let i=e;for(;n>xo;)n&As&&(r=r.add(i)),i=i.double(),n>>=As;return r}precomputeWindow(e,n){const{windows:r,windowSize:i}=u0(n,this.bits),s=[];let o=e,a=o;for(let c=0;c<r;c++){a=o,s.push(a);for(let f=1;f<i;f++)a=a.add(o),s.push(a);o=a.double()}return s}wNAF(e,n,r){if(!this.Fn.isValid(r))throw new Error("invalid scalar");let i=this.ZERO,s=this.BASE;const o=u0(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:c,offset:f,isZero:l,isNeg:h,isNegF:d,offsetF:u}=O3(r,a,o);r=c,l?s=s.add(cu(d,n[u])):i=i.add(cu(h,n[f]))}return P3(r),{p:i,f:s}}wNAFUnsafe(e,n,r,i=this.ZERO){const s=u0(e,this.bits);for(let o=0;o<s.windows&&r!==xo;o++){const{nextN:a,offset:c,isZero:f,isNeg:l}=O3(r,o,s);if(r=a,!f){const h=n[c];i=i.add(l?h.negate():h)}}return P3(r),i}getPrecomputes(e,n,r){let i=l0.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),l0.set(n,i))),i}cached(e,n,r){const i=h0(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=h0(e);return s===1?this._unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,i)}createCache(e,n){A3(n,this.bits),D3.set(e,n),l0.delete(e)}hasCache(e){return h0(e)!==1}}function RN(t,e,n,r){let i=e,s=t.ZERO,o=t.ZERO;for(;n>xo||r>xo;)n&As&&(s=s.add(i)),r&As&&(o=o.add(i)),i=i.double(),n>>=As,r>>=As;return{p1:s,p2:o}}function TN(t,e,n,r){ON(n,t),DN(r,e);const i=n.length,s=r.length;if(i!==s)throw new Error("arrays of points and scalars must have equal length");const o=t.ZERO,a=d3(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=Fa(c),l=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let d=o;for(let u=h;u>=0;u-=c){l.fill(o);for(let w=0;w<s;w++){const E=r[w],A=Number(E>>BigInt(u)&f);l[A]=l[A].add(n[w])}let b=o;for(let w=l.length-1,E=o;w>0;w--)E=E.add(l[w]),b=b.add(E);if(d=d.add(b),u!==0)for(let w=0;w<c;w++)d=d.double()}return d}function R3(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return BN(e),e}else return Ki(t,{isLE:n})}function NN(t,e,n={},r){if(r===void 0&&(r=t==="edwards"),!e||typeof e!="object")throw new Error(`expected valid ${t} CURVE object`);for(const a of["p","n","h"]){const c=e[a];if(!(typeof c=="bigint"&&c>xo))throw new Error(`CURVE.${a} must be positive bigint`)}const i=R3(e.p,n.Fp,r),s=R3(e.n,n.Fn,r),o=["Gx","Gy","a",t==="weierstrass"?"b":"d"];for(const a of o)if(!i.isValid(e[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return e=Object.freeze(Object.assign({},e)),{CURVE:e,Fp:i,Fn:s}}BigInt(0),BigInt(1),BigInt(2),BigInt(8),Nm("HashToScalar-");const ka=BigInt(0),_o=BigInt(1),fu=BigInt(2);function UN(t){return au(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function CN(t){const e=UN(t),{P:n,type:r,adjustScalarBytes:i,powPminus2:s,randomBytes:o}=e,a=r==="x25519";if(!a&&r!=="x448")throw new Error("invalid type");const c=o||Ss,f=a?255:448,l=a?32:56,h=BigInt(a?9:5),d=BigInt(a?121665:39081),u=a?fu**BigInt(254):fu**BigInt(447),b=a?BigInt(8)*fu**BigInt(251)-_o:BigInt(4)*fu**BigInt(445)-_o,w=u+b+_o,E=y=>an(y,n),A=P(h);function P(y){return s0(E(y),l)}function _(y){const p=_t("u coordinate",y,l);return a&&(p[31]&=127),E(ou(p))}function x(y){return ou(i(_t("scalar",y,l)))}function D(y,p){const m=L(_(p),x(y));if(m===ka)throw new Error("invalid private or public key received");return P(m)}function U(y){return D(y,A)}function C(y,p,m){const g=E(y*(p-m));return p=E(p-g),m=E(m+g),{x_2:p,x_3:m}}function L(y,p){a0("u",y,ka,n),a0("scalar",p,u,w);const m=p,g=y;let v=_o,S=ka,B=y,I=_o,$=ka;for(let F=BigInt(f-1);F>=ka;F--){const N=m>>F&_o;$^=N,{x_2:v,x_3:B}=C($,v,B),{x_2:S,x_3:I}=C($,S,I),$=N;const k=v+S,R=E(k*k),j=v-S,z=E(j*j),V=R-z,H=B+I,K=B-I,Y=E(K*k),X=E(H*j),ee=Y+X,se=Y-X;B=E(ee*ee),I=E(g*E(se*se)),v=E(R*z),S=E(V*(R+E(d*V)))}({x_2:v,x_3:B}=C($,v,B)),{x_2:S,x_3:I}=C($,S,I);const T=s(S);return E(v*T)}const O={secretKey:l,publicKey:l,seed:l},M=(y=c(l))=>(Nn(y,O.seed),y);function q(y){const p=M(y);return{secretKey:p,publicKey:U(p)}}return{keygen:q,getSharedSecret:(y,p)=>D(y,p),getPublicKey:y=>U(y),scalarMult:D,scalarMultBase:U,utils:{randomSecretKey:M,randomPrivateKey:M},GuBytes:A.slice(),lengths:O}}const LN=BigInt(1),T3=BigInt(2),FN=BigInt(3),kN=BigInt(5),qN=BigInt(8),N3=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),jN={p:N3,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:qN,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function MN(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=N3,o=t*t%s*t%s,a=Cn(o,T3,s)*o%s,c=Cn(a,LN,s)*t%s,f=Cn(c,kN,s)*c%s,l=Cn(f,e,s)*f%s,h=Cn(l,n,s)*l%s,d=Cn(h,r,s)*h%s,u=Cn(d,i,s)*d%s,b=Cn(u,i,s)*d%s,w=Cn(b,e,s)*f%s;return{pow_p_5_8:Cn(w,T3,s)*t%s,b2:o}}function zN(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const HN=Ki(jN.p,{isLE:!0}),d0=(()=>{const t=HN.ORDER;return CN({P:t,type:"x25519",powPminus2:e=>{const{pow_p_5_8:n,b2:r}=MN(e);return an(Cn(n,FN,t)*r,t)},adjustScalarBytes:zN})})(),U3=(t,e)=>(t+(t>=0?e:-e)/C3)/e;function VN(t,e,n){const[[r,i],[s,o]]=e,a=U3(o*t,n),c=U3(-i*t,n);let f=t-a*r-c*s,l=-a*i-c*o;const h=f<Tr,d=l<Tr;h&&(f=-f),d&&(l=-l);const u=Fa(Math.ceil(d3(n)/2))+So;if(f<Tr||f>=u||l<Tr||l>=u)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:h,k1:f,k2neg:d,k2:l}}function p0(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function g0(t,e){const n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return ru(n.lowS,"lowS"),ru(n.prehash,"prehash"),n.format!==void 0&&p0(n.format),n}class KN extends Error{constructor(e=""){super(e)}}const Rr={Err:KN,_tlv:{encode:(t,e)=>{const{Err:n}=Rr;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length&1)throw new n("tlv.encode: unpadded data");const r=e.length/2,i=iu(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?iu(i.length/2|128):"";return iu(t)+s+i+e},decode(t,e){const{Err:n}=Rr;let r=0;if(t<0||t>256)throw new n("tlv.encode: wrong tag");if(e.length<2||e[r++]!==t)throw new n("tlv.decode: wrong tlv");const i=e[r++],s=!!(i&128);let o=0;if(!s)o=i;else{const c=i&127;if(!c)throw new n("tlv.decode(long): indefinite length not supported");if(c>4)throw new n("tlv.decode(long): byte length is too big");const f=e.subarray(r,r+c);if(f.length!==c)throw new n("tlv.decode: length bytes not complete");if(f[0]===0)throw new n("tlv.decode(long): zero leftmost byte");for(const l of f)o=o<<8|l;if(r+=c,o<128)throw new n("tlv.decode(long): not minimal encoding")}const a=e.subarray(r,r+o);if(a.length!==o)throw new n("tlv.decode: wrong value length");return{v:a,l:e.subarray(r+o)}}},_int:{encode(t){const{Err:e}=Rr;if(t<Tr)throw new e("integer: negative integers are not allowed");let n=iu(t);if(Number.parseInt(n[0],16)&8&&(n="00"+n),n.length&1)throw new e("unexpected DER parsing assertion: unpadded hex");return n},decode(t){const{Err:e}=Rr;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 su(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=Rr,i=_t("signature",t),{v:s,l:o}=r.decode(48,i);if(o.length)throw new e("invalid signature: left bytes after parsing");const{v:a,l:c}=r.decode(2,s),{v:f,l}=r.decode(2,c);if(l.length)throw new e("invalid signature: left bytes after parsing");return{r:n.decode(a),s:n.decode(f)}},hexFromSig(t){const{_tlv:e,_int:n}=Rr,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}},Tr=BigInt(0),So=BigInt(1),C3=BigInt(2),uu=BigInt(3),GN=BigInt(4);function Io(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=_t("private key",e);try{r=t.fromBytes(i)}catch{throw new Error(`invalid private key: expected ui8a of size ${n}, got ${typeof e}`)}}if(!t.isValidNot0(r))throw new Error("invalid private key: out of range [1..N-1]");return r}function ZN(t,e={}){const n=NN("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;au(e,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",wrapPrivateKey:"boolean"});const{endo:c}=e;if(c&&(!r.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');const f=F3(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(y,p,m){const{x:g,y:v}=p.toAffine(),S=r.toBytes(g);if(ru(m,"isCompressed"),m){l();const B=!r.isOdd(v);return Fi(L3(B),S)}else return Fi(Uint8Array.of(4),S,r.toBytes(v))}function d(y){Bs(y,void 0,"Point");const{publicKey:p,publicKeyUncompressed:m}=f,g=y.length,v=y[0],S=y.subarray(1);if(g===p&&(v===2||v===3)){const B=r.fromBytes(S);if(!r.isValid(B))throw new Error("bad point: is not on curve, wrong x");const I=w(B);let $;try{$=r.sqrt(I)}catch(F){const N=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+N)}l();const T=r.isOdd($);return(v&1)===1!==T&&($=r.neg($)),{x:B,y:$}}else if(g===m&&v===4){const B=r.BYTES,I=r.fromBytes(S.subarray(0,B)),$=r.fromBytes(S.subarray(B,B*2));if(!E(I,$))throw new Error("bad point: is not on curve");return{x:I,y:$}}else throw new Error(`bad point: got length ${g}, expected compressed=${p} or uncompressed=${m}`)}const u=e.toBytes||h,b=e.fromBytes||d;function w(y){const p=r.sqr(y),m=r.mul(p,y);return r.add(r.add(m,r.mul(y,s.a)),s.b)}function E(y,p){const m=r.sqr(p),g=w(y);return r.eql(m,g)}if(!E(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const A=r.mul(r.pow(s.a,uu),GN),P=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(A,P)))throw new Error("bad curve params: a or b");function _(y,p,m=!1){if(!r.isValid(p)||m&&r.is0(p))throw new Error(`bad point coordinate ${y}`);return p}function x(y){if(!(y instanceof O))throw new Error("ProjectivePoint expected")}function D(y){if(!c||!c.basises)throw new Error("no endo");return VN(y,c.basises,i.ORDER)}const U=p3((y,p)=>{const{X:m,Y:g,Z:v}=y;if(r.eql(v,r.ONE))return{x:m,y:g};const S=y.is0();p==null&&(p=S?r.ONE:r.inv(v));const B=r.mul(m,p),I=r.mul(g,p),$=r.mul(v,p);if(S)return{x:r.ZERO,y:r.ZERO};if(!r.eql($,r.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}),C=p3(y=>{if(y.is0()){if(e.allowInfinityPoint&&!r.is0(y.Y))return;throw new Error("bad point: ZERO")}const{x:p,y:m}=y.toAffine();if(!r.isValid(p)||!r.isValid(m))throw new Error("bad point: x or y not field elements");if(!E(p,m))throw new Error("bad point: equation left != right");if(!y.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function L(y,p,m,g,v){return m=new O(r.mul(m.X,y),m.Y,m.Z),p=cu(g,p),m=cu(v,m),p.add(m)}class O{constructor(p,m,g){this.X=_("x",p),this.Y=_("y",m,!0),this.Z=_("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(p){const{x:m,y:g}=p||{};if(!p||!r.isValid(m)||!r.isValid(g))throw new Error("invalid affine point");if(p instanceof O)throw new Error("projective point not allowed");return r.is0(m)&&r.is0(g)?O.ZERO:new O(m,g,r.ONE)}static fromBytes(p){const m=O.fromAffine(b(Bs(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return O.fromBytes(_t("pointHex",p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,m=!0){return q.createCache(this,p),m||this.multiply(uu),this}assertValidity(){C(this)}hasEvenY(){const{y:p}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(p)}equals(p){x(p);const{X:m,Y:g,Z:v}=this,{X:S,Y:B,Z:I}=p,$=r.eql(r.mul(m,I),r.mul(S,v)),T=r.eql(r.mul(g,I),r.mul(B,v));return $&&T}negate(){return new O(this.X,r.neg(this.Y),this.Z)}double(){const{a:p,b:m}=s,g=r.mul(m,uu),{X:v,Y:S,Z:B}=this;let I=r.ZERO,$=r.ZERO,T=r.ZERO,F=r.mul(v,v),N=r.mul(S,S),k=r.mul(B,B),R=r.mul(v,S);return R=r.add(R,R),T=r.mul(v,B),T=r.add(T,T),I=r.mul(p,T),$=r.mul(g,k),$=r.add(I,$),I=r.sub(N,$),$=r.add(N,$),$=r.mul(I,$),I=r.mul(R,I),T=r.mul(g,T),k=r.mul(p,k),R=r.sub(F,k),R=r.mul(p,R),R=r.add(R,T),T=r.add(F,F),F=r.add(T,F),F=r.add(F,k),F=r.mul(F,R),$=r.add($,F),k=r.mul(S,B),k=r.add(k,k),F=r.mul(k,R),I=r.sub(I,F),T=r.mul(k,N),T=r.add(T,T),T=r.add(T,T),new O(I,$,T)}add(p){x(p);const{X:m,Y:g,Z:v}=this,{X:S,Y:B,Z:I}=p;let $=r.ZERO,T=r.ZERO,F=r.ZERO;const N=s.a,k=r.mul(s.b,uu);let R=r.mul(m,S),j=r.mul(g,B),z=r.mul(v,I),V=r.add(m,g),H=r.add(S,B);V=r.mul(V,H),H=r.add(R,j),V=r.sub(V,H),H=r.add(m,v);let K=r.add(S,I);return H=r.mul(H,K),K=r.add(R,z),H=r.sub(H,K),K=r.add(g,v),$=r.add(B,I),K=r.mul(K,$),$=r.add(j,z),K=r.sub(K,$),F=r.mul(N,H),$=r.mul(k,z),F=r.add($,F),$=r.sub(j,F),F=r.add(j,F),T=r.mul($,F),j=r.add(R,R),j=r.add(j,R),z=r.mul(N,z),H=r.mul(k,H),j=r.add(j,z),z=r.sub(R,z),z=r.mul(N,z),H=r.add(H,z),R=r.mul(j,H),T=r.add(T,R),R=r.mul(K,H),$=r.mul(V,$),$=r.sub($,R),R=r.mul(V,j),F=r.mul(K,F),F=r.add(F,R),new O($,T,F)}subtract(p){return this.add(p.negate())}is0(){return this.equals(O.ZERO)}multiply(p){const{endo:m}=e;if(!i.isValidNot0(p))throw new Error("invalid scalar: out of range");let g,v;const S=B=>q.cached(this,B,I=>f0(O,I));if(m){const{k1neg:B,k1:I,k2neg:$,k2:T}=D(p),{p:F,f:N}=S(I),{p:k,f:R}=S(T);v=N.add(R),g=L(m.beta,F,k,B,$)}else{const{p:B,f:I}=S(p);g=B,v=I}return f0(O,[g,v])[0]}multiplyUnsafe(p){const{endo:m}=e,g=this;if(!i.isValid(p))throw new Error("invalid scalar: out of range");if(p===Tr||g.is0())return O.ZERO;if(p===So)return g;if(q.hasCache(this))return this.multiply(p);if(m){const{k1neg:v,k1:S,k2neg:B,k2:I}=D(p),{p1:$,p2:T}=RN(O,g,S,I);return L(m.beta,$,T,v,B)}else return q.unsafe(g,p)}multiplyAndAddUnsafe(p,m,g){const v=this.multiplyUnsafe(m).add(p.multiplyUnsafe(g));return v.is0()?void 0:v}toAffine(p){return U(this,p)}isTorsionFree(){const{isTorsionFree:p}=e;return o===So?!0:p?p(O,this):q.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:p}=e;return o===So?this:p?p(O,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(p=!0){return ru(p,"isCompressed"),this.assertValidity(),u(O,this,p)}toHex(p=!0){return vo(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(p=!0){return this.toBytes(p)}_setWindowSize(p){this.precompute(p)}static normalizeZ(p){return f0(O,p)}static msm(p,m){return TN(O,i,p,m)}static fromPrivateKey(p){return O.BASE.multiply(Io(i,p))}}O.BASE=new O(s.Gx,s.Gy,r.ONE),O.ZERO=new O(r.ZERO,r.ONE,r.ZERO),O.Fp=r,O.Fn=i;const M=i.BITS,q=new PN(O,e.endo?Math.ceil(M/2):M);return O.BASE.precompute(8),O}function L3(t){return Uint8Array.of(t?2:3)}function F3(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function WN(t,e={}){const{Fn:n}=t,r=e.randomBytes||Ss,i=Object.assign(F3(t.Fp,n),{seed:$3(n.ORDER)});function s(d){try{return!!Io(n,d)}catch{return!1}}function o(d,u){const{publicKey:b,publicKeyUncompressed:w}=i;try{const E=d.length;return u===!0&&E!==b||u===!1&&E!==w?!1:!!t.fromBytes(d)}catch{return!1}}function a(d=r(i.seed)){return AN(Bs(d,i.seed,"seed"),n.ORDER)}function c(d,u=!0){return t.BASE.multiply(Io(n,d)).toBytes(u)}function f(d){const u=a(d);return{secretKey:u,publicKey:c(u)}}function l(d){if(typeof d=="bigint")return!1;if(d instanceof t)return!0;const{secretKey:u,publicKey:b,publicKeyUncompressed:w}=i;if(n.allowedLengths||u===b)return;const E=_t("key",d).length;return E===b||E===w}function h(d,u,b=!0){if(l(d)===!0)throw new Error("first arg must be private key");if(l(u)===!1)throw new Error("second arg must be public key");const w=Io(n,d);return t.fromHex(u).multiply(w).toBytes(b)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:f,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:d=>Io(n,d),precompute(d=8,u=t.BASE){return u.precompute(d,!1)}},lengths:i})}function YN(t,e,n={}){Gf(e),au(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Ss,i=n.hmac||((m,...g)=>tu(e,m,Fi(...g))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:u}=WN(t,n),b={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},w="compact";function E(m){const g=a>>So;return m>g}function A(m,g){if(!o.isValidNot0(g))throw new Error(`invalid signature ${m}: out of range 1..Point.Fn.ORDER`);return g}function P(m,g){p0(g);const v=u.signature,S=g==="compact"?v:g==="recovered"?v+1:void 0;return Bs(m,S,`${g} signature`)}class _{constructor(g,v,S){this.r=A("r",g),this.s=A("s",v),S!=null&&(this.recovery=S),Object.freeze(this)}static fromBytes(g,v=w){P(g,v);let S;if(v==="der"){const{r:T,s:F}=Rr.toSig(Bs(g));return new _(T,F)}v==="recovered"&&(S=g[0],v="compact",g=g.subarray(1));const B=o.BYTES,I=g.subarray(0,B),$=g.subarray(B,B*2);return new _(o.fromBytes(I),o.fromBytes($),S)}static fromHex(g,v){return this.fromBytes(Zf(g),v)}addRecoveryBit(g){return new _(this.r,this.s,g)}recoverPublicKey(g){const v=s.ORDER,{r:S,s:B,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*C3<v&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");const $=I===2||I===3?S+a:S;if(!s.isValid($))throw new Error("recovery id 2 or 3 invalid");const T=s.toBytes($),F=t.fromBytes(Fi(L3((I&1)===0),T)),N=o.inv($),k=D(_t("msgHash",g)),R=o.create(-k*N),j=o.create(B*N),z=t.BASE.multiplyUnsafe(R).add(F.multiplyUnsafe(j));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return E(this.s)}toBytes(g=w){if(p0(g),g==="der")return Zf(Rr.hexFromSig(this));const v=o.toBytes(this.r),S=o.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Fi(Uint8Array.of(this.recovery),v,S)}return Fi(v,S)}toHex(g){return vo(this.toBytes(g))}assertValidity(){}static fromCompact(g){return _.fromBytes(_t("sig",g),"compact")}static fromDER(g){return _.fromBytes(_t("sig",g),"der")}normalizeS(){return this.hasHighS()?new _(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return vo(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return vo(this.toBytes("compact"))}}const x=n.bits2int||function(m){if(m.length>8192)throw new Error("input is too large");const g=su(m),v=m.length*8-c;return v>0?g>>BigInt(v):g},D=n.bits2int_modN||function(m){return o.create(x(m))},U=Fa(c);function C(m){return a0("num < 2^"+c,m,Tr,U),o.toBytes(m)}function L(m,g){return Bs(m,void 0,"message"),g?Bs(e(m),void 0,"prehashed message"):m}function O(m,g,v){if(["recovered","canonical"].some(j=>j in v))throw new Error("sign() legacy options not supported");const{lowS:S,prehash:B,extraEntropy:I}=g0(v,b);m=L(m,B);const $=D(m),T=Io(o,g),F=[C(T),C($)];if(I!=null&&I!==!1){const j=I===!0?r(u.secretKey):I;F.push(_t("extraEntropy",j))}const N=Fi(...F),k=$;function R(j){const z=x(j);if(!o.isValidNot0(z))return;const V=o.inv(z),H=t.BASE.multiply(z).toAffine(),K=o.create(H.x);if(K===Tr)return;const Y=o.create(V*o.create(k+K*T));if(Y===Tr)return;let X=(H.x===K?0:2)|Number(H.y&So),ee=Y;return S&&E(Y)&&(ee=o.neg(Y),X^=1),new _(K,ee,X)}return{seed:N,k2sig:R}}function M(m,g,v={}){m=_t("message",m);const{seed:S,k2sig:B}=O(m,g,v);return mN(e.outputLen,o.BYTES,i)(S,B)}function q(m){let g;const v=typeof m=="string"||Kf(m),S=!v&&m!==null&&typeof m=="object"&&typeof m.r=="bigint"&&typeof m.s=="bigint";if(!v&&!S)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(S)g=new _(m.r,m.s);else if(v){try{g=_.fromBytes(_t("sig",m),"der")}catch(B){if(!(B instanceof Rr.Err))throw B}if(!g)try{g=_.fromBytes(_t("sig",m),"compact")}catch{return!1}}return g||!1}function y(m,g,v,S={}){const{lowS:B,prehash:I,format:$}=g0(S,b);if(v=_t("publicKey",v),g=L(_t("message",g),I),"strict"in S)throw new Error("options.strict was renamed to lowS");const T=$===void 0?q(m):_.fromBytes(_t("sig",m),$);if(T===!1)return!1;try{const F=t.fromBytes(v);if(B&&T.hasHighS())return!1;const{r:N,s:k}=T,R=D(g),j=o.inv(k),z=o.create(R*j),V=o.create(N*j),H=t.BASE.multiplyUnsafe(z).add(F.multiplyUnsafe(V));return H.is0()?!1:o.create(H.x)===N}catch{return!1}}function p(m,g,v={}){const{prehash:S}=g0(v,b);return g=L(g,S),_.fromBytes(m,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:h,utils:d,lengths:u,Point:t,sign:M,verify:y,recoverPublicKey:p,Signature:_,hash:e})}function XN(t){const e={a:t.a,b:t.b,p:t.Fp.ORDER,n:t.n,h:t.h,Gx:t.Gx,Gy:t.Gy},n=t.Fp;let r=t.allowedPrivateKeyLengths?Array.from(new Set(t.allowedPrivateKeyLengths.map(o=>Math.ceil(o/2)))):void 0;const i=Ki(e.n,{BITS:t.nBitLength,allowedLengths:r,modFromBytes:t.wrapPrivateKey}),s={Fp:n,Fn:i,allowInfinityPoint:t.allowInfinityPoint,endo:t.endo,isTorsionFree:t.isTorsionFree,clearCofactor:t.clearCofactor,fromBytes:t.fromBytes,toBytes:t.toBytes};return{CURVE:e,curveOpts:s}}function JN(t){const{CURVE:e,curveOpts:n}=XN(t),r={hmac:t.hmac,randomBytes:t.randomBytes,lowS:t.lowS,bits2int:t.bits2int,bits2int_modN:t.bits2int_modN};return{CURVE:e,curveOpts:n,hash:t.hash,ecdsaOpts:r}}function QN(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,I3(n.Fn.ORDER,n.Fn.BITS))})}function eU(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=JN(t),s=ZN(e,n),o=YN(s,r,i);return QN(t,o)}function b0(t,e){const n=r=>eU({...t,hash:r});return{...n(e),create:n}}const k3={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},q3={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},j3={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},tU=Ki(k3.p),nU=Ki(q3.p),rU=Ki(j3.p),iU=b0({...k3,Fp:tU,lowS:!1},Yf);b0({...q3,Fp:nU,lowS:!1},cT),b0({...j3,Fp:rU,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},aT);const sU=iU,M3="base10",Lt="base16",Xt="base64pad",Gi="base64url",qa="utf8",z3=0,Nr=1,ja=2,oU=0,H3=1,Ma=12,y0=32;function aU(){const t=d0.utils.randomPrivateKey(),e=d0.getPublicKey(t);return{privateKey:zt(t,Lt),publicKey:zt(e,Lt)}}function w0(){const t=Ss(y0);return zt(t,Lt)}function cU(t,e){const n=d0.getSharedSecret(pn(t,Lt),pn(e,Lt)),r=yN(nu,n,void 0,void 0,y0);return zt(r,Lt)}function lu(t){const e=nu(pn(t,Lt));return zt(e,Lt)}function yn(t){const e=nu(pn(t,qa));return zt(e,Lt)}function V3(t){return pn(`${t}`,M3)}function Os(t){return Number(zt(t,M3))}function K3(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function G3(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=(4-e.length%4)%4;return e+"=".repeat(n)}function fU(t){const e=V3(typeof t.type<"u"?t.type:z3);if(Os(e)===Nr&&typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const n=typeof t.senderPublicKey<"u"?pn(t.senderPublicKey,Lt):void 0,r=typeof t.iv<"u"?pn(t.iv,Lt):Ss(Ma),i=pn(t.symKey,Lt),s=f3(i,r).encrypt(pn(t.message,qa)),o=Z3({type:e,sealed:s,iv:r,senderPublicKey:n});return t.encoding===Gi?K3(o):o}function uU(t){const e=pn(t.symKey,Lt),{sealed:n,iv:r}=za({encoded:t.encoded,encoding:t.encoding}),i=f3(e,r).decrypt(n);if(i===null)throw new Error("Failed to decrypt");return zt(i,qa)}function lU(t,e){const n=V3(ja),r=Ss(Ma),i=pn(t,qa),s=Z3({type:n,sealed:i,iv:r});return e===Gi?K3(s):s}function hU(t,e){const{sealed:n}=za({encoded:t,encoding:e});return zt(n,qa)}function Z3(t){if(Os(t.type)===ja)return zt(sa([t.type,t.sealed]),Xt);if(Os(t.type)===Nr){if(typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return zt(sa([t.type,t.senderPublicKey,t.iv,t.sealed]),Xt)}return zt(sa([t.type,t.iv,t.sealed]),Xt)}function za(t){const e=(t.encoding||Xt)===Gi?G3(t.encoded):t.encoded,n=pn(e,Xt),r=n.slice(oU,H3),i=H3;if(Os(r)===Nr){const c=i+y0,f=c+Ma,l=n.slice(i,c),h=n.slice(c,f),d=n.slice(f);return{type:r,sealed:d,iv:h,senderPublicKey:l}}if(Os(r)===ja){const c=n.slice(i),f=Ss(Ma);return{type:r,sealed:c,iv:f}}const s=i+Ma,o=n.slice(i,s),a=n.slice(s);return{type:r,sealed:a,iv:o}}function dU(t,e){const n=za({encoded:t,encoding:e?.encoding});return W3({type:Os(n.type),senderPublicKey:typeof n.senderPublicKey<"u"?zt(n.senderPublicKey,Lt):void 0,receiverPublicKey:e?.receiverPublicKey})}function W3(t){const e=t?.type||z3;if(e===Nr){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 Y3(t){return t.type===Nr&&typeof t.senderPublicKey=="string"&&typeof t.receiverPublicKey=="string"}function X3(t){return t.type===ja}function pU(t){const e=Buffer.from(t.x,"base64"),n=Buffer.from(t.y,"base64");return sa([new Uint8Array([4]),e,n])}function gU(t,e){const[n,r,i]=t.split("."),s=Buffer.from(G3(i),"base64");if(s.length!==64)throw new Error("Invalid signature length");const o=s.slice(0,32),a=s.slice(32,64),c=`${n}.${r}`,f=nu(c),l=pU(e);if(!sU.verify(sa([o,a]),f,l))throw new Error("Invalid signature");return uh(t).payload}const bU="irn";function hu(t){return t?.relay||{protocol:bU}}function Bo(t){const e=uI[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}var yU=Object.defineProperty,wU=Object.defineProperties,mU=Object.getOwnPropertyDescriptors,J3=Object.getOwnPropertySymbols,vU=Object.prototype.hasOwnProperty,EU=Object.prototype.propertyIsEnumerable,Q3=(t,e,n)=>e in t?yU(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,m0=(t,e)=>{for(var n in e||(e={}))vU.call(e,n)&&Q3(t,n,e[n]);if(J3)for(var n of J3(e))EU.call(e,n)&&Q3(t,n,e[n]);return t},xU=(t,e)=>wU(t,mU(e));function _U(t,e="-"){const n={},r="relay"+e;return Object.keys(t).forEach(i=>{if(i.startsWith(r)){const s=i.replace(r,""),o=t[i];n[s]=o}}),n}function e8(t){if(!t.includes("wc:")){const f=Sm(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(":"),n=t.indexOf("?")!==-1?t.indexOf("?"):void 0,r=t.substring(0,e),i=t.substring(e+1,n).split("@"),s=typeof n<"u"?t.substring(n):"",o=new URLSearchParams(s),a=Object.fromEntries(o.entries()),c=typeof a.methods=="string"?a.methods.split(","):void 0;return{protocol:r,topic:SU(i[0]),version:parseInt(i[1],10),symKey:a.symKey,relay:_U(a),methods:c,expiryTimestamp:a.expiryTimestamp?parseInt(a.expiryTimestamp,10):void 0}}function SU(t){return t.startsWith("//")?t.substring(2):t}function IU(t,e="-"){const n="relay",r={};return Object.keys(t).forEach(i=>{const s=i,o=n+e+s;t[s]&&(r[o]=t[s])}),r}function t8(t){const e=new URLSearchParams,n=m0(m0(xU(m0({},IU(t.relay)),{symKey:t.symKey}),t.expiryTimestamp&&{expiryTimestamp:t.expiryTimestamp.toString()}),t.methods&&{methods:t.methods.join(",")});return Object.entries(n).sort(([r],[i])=>r.localeCompare(i)).forEach(([r,i])=>{i!==void 0&&e.append(r,String(i))}),`${t.protocol}:${t.topic}@${t.version}?${e}`}function du(t,e,n){return`${t}?wc_ev=${n}&topic=${e}`}var BU=Object.defineProperty,$U=Object.defineProperties,AU=Object.getOwnPropertyDescriptors,n8=Object.getOwnPropertySymbols,OU=Object.prototype.hasOwnProperty,DU=Object.prototype.propertyIsEnumerable,r8=(t,e,n)=>e in t?BU(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,PU=(t,e)=>{for(var n in e||(e={}))OU.call(e,n)&&r8(t,n,e[n]);if(n8)for(var n of n8(e))DU.call(e,n)&&r8(t,n,e[n]);return t},RU=(t,e)=>$U(t,AU(e));function $o(t){const e=[];return t.forEach(n=>{const[r,i]=n.split(":");e.push(`${r}:${i}`)}),e}function i8(t){const e=[];return Object.values(t).forEach(n=>{e.push(...$o(n.accounts))}),[...new Set(e)]}function TU(t){const e=[];return Object.values(t).forEach(n=>{e.push(...n.methods)}),[...new Set(e)]}function NU(t){const e=[];return Object.values(t).forEach(n=>{e.push(...n.events)}),[...new Set(e)]}function UU(t,e){const n=[];return Object.values(t).forEach(r=>{$o(r.accounts).includes(e)&&n.push(...r.methods)}),n}function CU(t,e){const n=[];return Object.values(t).forEach(r=>{$o(r.accounts).includes(e)&&n.push(...r.events)}),n}function s8(t){return t.includes(":")}function LU(t){return s8(t)?t.split(":")[0]:t}function o8(t){var e,n,r;const i={};if(!Ha(t))return i;for(const[s,o]of Object.entries(t)){const a=s8(s)?[s]:o.chains,c=o.methods||[],f=o.events||[],l=LU(s);i[l]=RU(PU({},i[l]),{chains:_s(a,(e=i[l])==null?void 0:e.chains),methods:_s(c,(n=i[l])==null?void 0:n.methods),events:_s(f,(r=i[l])==null?void 0:r.events)})}return i}function FU(t){const e={};return t?.forEach(n=>{var r;const[i,s]=n.split(":");e[i]||(e[i]={accounts:[],chains:[],events:[],methods:[]}),e[i].accounts.push(n),(r=e[i].chains)==null||r.push(`${i}:${s}`)}),e}function a8(t,e){e=e.map(r=>r.replace("did:pkh:",""));const n=FU(e);for(const[r,i]of Object.entries(n))i.methods?i.methods=_s(i.methods,t):i.methods=t,i.events=["chainChanged","accountsChanged"];return n}function kU(t,e){var n,r,i,s,o,a;const c=o8(t),f=o8(e),l={},h=Object.keys(c).concat(Object.keys(f));for(const d of h)l[d]={chains:_s((n=c[d])==null?void 0:n.chains,(r=f[d])==null?void 0:r.chains),methods:_s((i=c[d])==null?void 0:i.methods,(s=f[d])==null?void 0:s.methods),events:_s((o=c[d])==null?void 0:o.events,(a=f[d])==null?void 0:a.events)};return l}const qU={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}},jU={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 W(t,e){const{message:n,code:r}=jU[t];return{message:e?`${n} ${e}`:n,code:r}}function Oe(t,e){const{message:n,code:r}=qU[t];return{message:e?`${n} ${e}`:n,code:r}}function Ao(t,e){return Array.isArray(t)?typeof e<"u"&&t.length?t.every(e):!0:!1}function Ha(t){return Object.getPrototypeOf(t)===Object.prototype&&Object.keys(t).length}function ze(t){return typeof t>"u"}function Ne(t,e){return e&&ze(t)?!0:typeof t=="string"&&!!t.trim().length}function v0(t,e){return e&&ze(t)?!0:typeof t=="number"&&!isNaN(t)}function MU(t,e){const{requiredNamespaces:n}=e,r=Object.keys(t.namespaces),i=Object.keys(n);let s=!0;return Es(i,r)?(r.forEach(o=>{const{accounts:a,methods:c,events:f}=t.namespaces[o],l=$o(a),h=n[o];(!Es(dm(o,h),l)||!Es(h.methods,c)||!Es(h.events,f))&&(s=!1)}),s):!1}function pu(t){return Ne(t,!1)&&t.includes(":")?t.split(":").length===2:!1}function zU(t){if(Ne(t,!1)&&t.includes(":")){const e=t.split(":");if(e.length===3){const n=e[0]+":"+e[1];return!!e[2]&&pu(n)}}return!1}function HU(t){function e(n){try{return typeof new URL(n)<"u"}catch{return!1}}try{if(Ne(t,!1)){if(e(t))return!0;const n=Sm(t);return e(n)}}catch{}return!1}function VU(t){var e;return(e=t?.proposer)==null?void 0:e.publicKey}function KU(t){return t?.topic}function GU(t,e){let n=null;return Ne(t?.publicKey,!1)||(n=W("MISSING_OR_INVALID",`${e} controller public key should be a string`)),n}function c8(t){let e=!0;return Ao(t)?t.length&&(e=t.every(n=>Ne(n,!1))):e=!1,e}function ZU(t,e,n){let r=null;return Ao(e)&&e.length?e.forEach(i=>{r||pu(i)||(r=Oe("UNSUPPORTED_CHAINS",`${n}, chain ${i} should be a string and conform to "namespace:chainId" format`))}):pu(t)||(r=Oe("UNSUPPORTED_CHAINS",`${n}, 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"] }`)),r}function WU(t,e,n){let r=null;return Object.entries(t).forEach(([i,s])=>{if(r)return;const o=ZU(i,dm(i,s),`${e} ${n}`);o&&(r=o)}),r}function YU(t,e){let n=null;return Ao(t)?t.forEach(r=>{n||zU(r)||(n=Oe("UNSUPPORTED_ACCOUNTS",`${e}, account ${r} should be a string and conform to "namespace:chainId:address" format`))}):n=Oe("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),n}function XU(t,e){let n=null;return Object.values(t).forEach(r=>{if(n)return;const i=YU(r?.accounts,`${e} namespace`);i&&(n=i)}),n}function JU(t,e){let n=null;return c8(t?.methods)?c8(t?.events)||(n=Oe("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):n=Oe("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),n}function f8(t,e){let n=null;return Object.values(t).forEach(r=>{if(n)return;const i=JU(r,`${e}, namespace`);i&&(n=i)}),n}function QU(t,e,n){let r=null;if(t&&Ha(t)){const i=f8(t,e);i&&(r=i);const s=WU(t,e,n);s&&(r=s)}else r=W("MISSING_OR_INVALID",`${e}, ${n} should be an object with data`);return r}function E0(t,e){let n=null;if(t&&Ha(t)){const r=f8(t,e);r&&(n=r);const i=XU(t,e);i&&(n=i)}else n=W("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return n}function u8(t){return Ne(t.protocol,!0)}function eC(t,e){let n=!1;return e&&!t?n=!0:t&&Ao(t)&&t.length&&t.forEach(r=>{n=u8(r)}),n}function tC(t){return typeof t=="number"}function Jt(t){return typeof t<"u"&&typeof t!==null}function nC(t){return!(!t||typeof t!="object"||!t.code||!v0(t.code,!1)||!t.message||!Ne(t.message,!1))}function rC(t){return!(ze(t)||!Ne(t.method,!1))}function iC(t){return!(ze(t)||ze(t.result)&&ze(t.error)||!v0(t.id,!1)||!Ne(t.jsonrpc,!1))}function sC(t){return!(ze(t)||!Ne(t.name,!1))}function l8(t,e){return!(!pu(e)||!i8(t).includes(e))}function oC(t,e,n){return Ne(n,!1)?UU(t,e).includes(n):!1}function aC(t,e,n){return Ne(n,!1)?CU(t,e).includes(n):!1}function h8(t,e,n){let r=null;const i=cC(t),s=fC(e),o=Object.keys(i),a=Object.keys(s),c=d8(Object.keys(t)),f=d8(Object.keys(e)),l=c.filter(h=>!f.includes(h));return l.length&&(r=W("NON_CONFORMING_NAMESPACES",`${n} namespaces keys don't satisfy requiredNamespaces.
22
24
  Required: ${l.toString()}
23
- Received: ${Object.keys(e).toString()}`)),Mr(o,a)||(r=G("NON_CONFORMING_NAMESPACES",`${n} namespaces chains don't satisfy required namespaces.
25
+ Received: ${Object.keys(e).toString()}`)),Es(o,a)||(r=W("NON_CONFORMING_NAMESPACES",`${n} namespaces chains don't satisfy required namespaces.
24
26
  Required: ${o.toString()}
25
- Approved: ${a.toString()}`)),Object.keys(e).forEach(f=>{if(!f.includes(":")||r)return;const d=$i(e[f].accounts);d.includes(f)||(r=G("NON_CONFORMING_NAMESPACES",`${n} namespaces accounts don't satisfy namespace accounts for ${f}
26
- Required: ${f}
27
- Approved: ${d.toString()}`))}),o.forEach(f=>{r||(Mr(i[f].methods,s[f].methods)?Mr(i[f].events,s[f].events)||(r=G("NON_CONFORMING_NAMESPACES",`${n} namespaces events don't satisfy namespace events for ${f}`)):r=G("NON_CONFORMING_NAMESPACES",`${n} namespaces methods don't satisfy namespace methods for ${f}`))}),r}function I9(t){const e={};return Object.keys(t).forEach(n=>{var r;n.includes(":")?e[n]=t[n]:(r=t[n].chains)==null||r.forEach(i=>{e[i]={methods:t[n].methods,events:t[n].events}})}),e}function $1(t){return[...new Set(t.map(e=>e.includes(":")?e.split(":")[0]:e))]}function A9(t){const e={};return Object.keys(t).forEach(n=>{n.includes(":")?e[n]=t[n]:$i(t[n].accounts)?.forEach(i=>{e[i]={accounts:t[n].accounts.filter(s=>s.includes(`${i}:`)),methods:t[n].methods,events:t[n].events}})}),e}function B9(t,e){return gl(t,!1)&&t<=e.max&&t>=e.min}function P1(){const t=ds();return new Promise(e=>{switch(t){case Bt.browser:e(O9());break;case Bt.reactNative:e(D9());break;case Bt.node:e($9());break;default:e(!0)}})}function O9(){return Ei()&&navigator?.onLine}async function D9(){return sr()&&typeof global<"u"&&global!=null&&global.NetInfo?(await(global==null?void 0:global.NetInfo.fetch()))?.isConnected:!0}function $9(){return!0}function P9(t){switch(ds()){case Bt.browser:T9(t);break;case Bt.reactNative:R9(t);break}}function T9(t){!sr()&&Ei()&&(window.addEventListener("online",()=>t(!0)),window.addEventListener("offline",()=>t(!1)))}function R9(t){sr()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(e=>t(e?.isConnected))}function N9(){var t;return Ei()&&Pr()?((t=Pr())==null?void 0:t.visibilityState)==="visible":!0}const bl={};class Bs{static get(e){return bl[e]}static set(e,n){bl[e]=n}static delete(e){delete bl[e]}}function C9(t){const e=is.decode(t);if(e.length<33)throw new Error("Too short to contain a public key");return e.slice(1,33)}function U9({publicKey:t,signature:e,payload:n}){var r;const i=wl(n.method),s=128|parseInt(((r=n.version)==null?void 0:r.toString())||"4"),o=k9(n.address),a=n.era==="00"?new Uint8Array([0]):wl(n.era);if(a.length!==1&&a.length!==2)throw new Error("Invalid era length");const c=parseInt(n.nonce,16),u=new Uint8Array([c&255,c>>8&255]),l=BigInt(`0x${L9(n.tip)}`),f=M9(l),d=new Uint8Array([0,...t,o,...e,...a,...u,...f,...i]),h=q9(d.length+1);return new Uint8Array([...h,s,...d])}function F9(t){const e=wl(t),n=E_.blake2b(e,void 0,32);return"0x"+Buffer.from(n).toString("hex")}function wl(t){return new Uint8Array(t.replace(/^0x/,"").match(/.{1,2}/g).map(e=>parseInt(e,16)))}function L9(t){return t.startsWith("0x")?t.slice(2):t}function k9(t){const e=is.decode(t)[0];return e===42?0:e===60?2:1}function q9(t){if(t<64)return new Uint8Array([t<<2]);if(t<16384){const e=t<<2|1;return new Uint8Array([e&255,e>>8&255])}else if(t<1<<30){const e=t<<2|2;return new Uint8Array([e&255,e>>8&255,e>>16&255,e>>24&255])}else throw new Error("Compact encoding > 2^30 not supported")}function M9(t){if(t<BigInt(1)<<BigInt(6))return new Uint8Array([Number(t<<BigInt(2))]);if(t<BigInt(1)<<BigInt(14)){const e=t<<BigInt(2)|BigInt(1);return new Uint8Array([Number(e&BigInt(255)),Number(e>>BigInt(8)&BigInt(255))])}else if(t<BigInt(1)<<BigInt(30)){const e=t<<BigInt(2)|BigInt(2);return new Uint8Array([Number(e&BigInt(255)),Number(e>>BigInt(8)&BigInt(255)),Number(e>>BigInt(16)&BigInt(255)),Number(e>>BigInt(24)&BigInt(255))])}else throw new Error("BigInt compact encoding not supported > 2^30")}function j9(t){const e=Uint8Array.from(Buffer.from(t.signature,"hex")),n=C9(t.transaction.address),r=U9({publicKey:n,signature:e,payload:t.transaction}),i=Buffer.from(r).toString("hex");return F9(i)}function T1({logger:t,name:e}){const n=typeof t=="string"?Nf({opts:{level:t,name:e}}).logger:t;return n.level=typeof t=="string"?t:t.level,n}const z9="PARSE_ERROR",H9="INVALID_REQUEST",V9="METHOD_NOT_FOUND",K9="INVALID_PARAMS",R1="INTERNAL_ERROR",ml="SERVER_ERROR",G9=[-32700,-32600,-32601,-32602,-32603],Os={[z9]:{code:-32700,message:"Parse error"},[H9]:{code:-32600,message:"Invalid Request"},[V9]:{code:-32601,message:"Method not found"},[K9]:{code:-32602,message:"Invalid params"},[R1]:{code:-32603,message:"Internal error"},[ml]:{code:-32e3,message:"Server error"}},N1=ml;function W9(t){return G9.includes(t)}function C1(t){return Object.keys(Os).includes(t)?Os[t]:Os[N1]}function Z9(t){const e=Object.values(Os).find(n=>n.code===t);return e||Os[N1]}function Y9(t,e,n){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable ${n} RPC url at ${e}`):t}var U1={};/*! *****************************************************************************
27
+ Approved: ${a.toString()}`)),Object.keys(e).forEach(h=>{if(!h.includes(":")||r)return;const d=$o(e[h].accounts);d.includes(h)||(r=W("NON_CONFORMING_NAMESPACES",`${n} namespaces accounts don't satisfy namespace accounts for ${h}
28
+ Required: ${h}
29
+ Approved: ${d.toString()}`))}),o.forEach(h=>{r||(Es(i[h].methods,s[h].methods)?Es(i[h].events,s[h].events)||(r=W("NON_CONFORMING_NAMESPACES",`${n} namespaces events don't satisfy namespace events for ${h}`)):r=W("NON_CONFORMING_NAMESPACES",`${n} namespaces methods don't satisfy namespace methods for ${h}`))}),r}function cC(t){const e={};return Object.keys(t).forEach(n=>{var r;n.includes(":")?e[n]=t[n]:(r=t[n].chains)==null||r.forEach(i=>{e[i]={methods:t[n].methods,events:t[n].events}})}),e}function d8(t){return[...new Set(t.map(e=>e.includes(":")?e.split(":")[0]:e))]}function fC(t){const e={};return Object.keys(t).forEach(n=>{n.includes(":")?e[n]=t[n]:$o(t[n].accounts)?.forEach(i=>{e[i]={accounts:t[n].accounts.filter(s=>s.includes(`${i}:`)),methods:t[n].methods,events:t[n].events}})}),e}function uC(t,e){return v0(t,!1)&&t<=e.max&&t>=e.min}function p8(){const t=Pa();return new Promise(e=>{switch(t){case on.browser:e(lC());break;case on.reactNative:e(hC());break;case on.node:e(dC());break;default:e(!0)}})}function lC(){return wo()&&navigator?.onLine}async function hC(){return Ri()&&typeof global<"u"&&global!=null&&global.NetInfo?(await(global==null?void 0:global.NetInfo.fetch()))?.isConnected:!0}function dC(){return!0}function pC(t){switch(Pa()){case on.browser:gC(t);break;case on.reactNative:bC(t);break}}function gC(t){!Ri()&&wo()&&(window.addEventListener("online",()=>t(!0)),window.addEventListener("offline",()=>t(!1)))}function bC(t){Ri()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(e=>t(e?.isConnected))}function yC(){var t;return wo()&&nr()?((t=nr())==null?void 0:t.visibilityState)==="visible":!0}const x0={};class Va{static get(e){return x0[e]}static set(e,n){x0[e]=n}static delete(e){delete x0[e]}}function wC(t){const e=Jo.decode(t);if(e.length<33)throw new Error("Too short to contain a public key");return e.slice(1,33)}function mC({publicKey:t,signature:e,payload:n}){var r;const i=_0(n.method),s=128|parseInt(((r=n.version)==null?void 0:r.toString())||"4"),o=xC(n.address),a=n.era==="00"?new Uint8Array([0]):_0(n.era);if(a.length!==1&&a.length!==2)throw new Error("Invalid era length");const c=parseInt(n.nonce,16),f=new Uint8Array([c&255,c>>8&255]),l=BigInt(`0x${EC(n.tip)}`),h=SC(l),d=new Uint8Array([0,...t,o,...e,...a,...f,...h,...i]),u=_C(d.length+1);return new Uint8Array([...u,s,...d])}function vC(t){const e=_0(t),n=xI.blake2b(e,void 0,32);return"0x"+Buffer.from(n).toString("hex")}function _0(t){return new Uint8Array(t.replace(/^0x/,"").match(/.{1,2}/g).map(e=>parseInt(e,16)))}function EC(t){return t.startsWith("0x")?t.slice(2):t}function xC(t){const e=Jo.decode(t)[0];return e===42?0:e===60?2:1}function _C(t){if(t<64)return new Uint8Array([t<<2]);if(t<16384){const e=t<<2|1;return new Uint8Array([e&255,e>>8&255])}else if(t<1<<30){const e=t<<2|2;return new Uint8Array([e&255,e>>8&255,e>>16&255,e>>24&255])}else throw new Error("Compact encoding > 2^30 not supported")}function SC(t){if(t<BigInt(1)<<BigInt(6))return new Uint8Array([Number(t<<BigInt(2))]);if(t<BigInt(1)<<BigInt(14)){const e=t<<BigInt(2)|BigInt(1);return new Uint8Array([Number(e&BigInt(255)),Number(e>>BigInt(8)&BigInt(255))])}else if(t<BigInt(1)<<BigInt(30)){const e=t<<BigInt(2)|BigInt(2);return new Uint8Array([Number(e&BigInt(255)),Number(e>>BigInt(8)&BigInt(255)),Number(e>>BigInt(16)&BigInt(255)),Number(e>>BigInt(24)&BigInt(255))])}else throw new Error("BigInt compact encoding not supported > 2^30")}function IC(t){const e=Uint8Array.from(Buffer.from(t.signature,"hex")),n=wC(t.transaction.address),r=mC({publicKey:n,signature:e,payload:t.transaction}),i=Buffer.from(r).toString("hex");return vC(i)}function g8({logger:t,name:e}){const n=typeof t=="string"?Y2({opts:{level:t,name:e}}).logger:t;return n.level=typeof t=="string"?t:t.level,n}const BC="PARSE_ERROR",$C="INVALID_REQUEST",AC="METHOD_NOT_FOUND",OC="INVALID_PARAMS",b8="INTERNAL_ERROR",S0="SERVER_ERROR",DC=[-32700,-32600,-32601,-32602,-32603],Ka={[BC]:{code:-32700,message:"Parse error"},[$C]:{code:-32600,message:"Invalid Request"},[AC]:{code:-32601,message:"Method not found"},[OC]:{code:-32602,message:"Invalid params"},[b8]:{code:-32603,message:"Internal error"},[S0]:{code:-32e3,message:"Server error"}},y8=S0;function PC(t){return DC.includes(t)}function w8(t){return Object.keys(Ka).includes(t)?Ka[t]:Ka[y8]}function RC(t){const e=Object.values(Ka).find(n=>n.code===t);return e||Ka[y8]}function TC(t,e,n){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable ${n} RPC url at ${e}`):t}var m8={};/*! *****************************************************************************
28
30
  Copyright (c) Microsoft Corporation.
29
31
 
30
32
  Permission to use, copy, modify, and/or distribute this software for any
@@ -37,5 +39,5 @@ ${t.length}`,n=new TextEncoder().encode(e+t);return"0x"+Buffer.from(b5(n)).toStr
37
39
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
38
40
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39
41
  PERFORMANCE OF THIS SOFTWARE.
40
- ***************************************************************************** */var vl=function(t,e){return vl=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var i in r)r.hasOwnProperty(i)&&(n[i]=r[i])},vl(t,e)};function X9(t,e){vl(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var El=function(){return El=Object.assign||function(e){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},El.apply(this,arguments)};function J9(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n}function Q9(t,e,n,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,n):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function e7(t,e){return function(n,r){e(n,r,t)}}function t7(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function n7(t,e,n,r){function i(s){return s instanceof n?s:new n(function(o){o(s)})}return new(n||(n=Promise))(function(s,o){function a(l){try{u(r.next(l))}catch(f){o(f)}}function c(l){try{u(r.throw(l))}catch(f){o(f)}}function u(l){l.done?s(l.value):i(l.value).then(a,c)}u((r=r.apply(t,e||[])).next())})}function r7(t,e){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,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(r)throw new TypeError("Generator is already executing.");for(;n;)try{if(r=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 n.label++,{value:u[1],done:!1};case 5:n.label++,i=u[1],u=[0];continue;case 7:u=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(u[0]===6||u[0]===2)){n=0;continue}if(u[0]===3&&(!s||u[1]>s[0]&&u[1]<s[3])){n.label=u[1];break}if(u[0]===6&&n.label<s[1]){n.label=s[1],s=u;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(u);break}s[2]&&n.ops.pop(),n.trys.pop();continue}u=e.call(t,n)}catch(l){u=[6,l],i=0}finally{r=s=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}}function i7(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]}function s7(t,e){for(var n in t)n!=="default"&&!e.hasOwnProperty(n)&&(e[n]=t[n])}function xl(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function F1(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function o7(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(F1(arguments[e]));return t}function a7(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),i=0,e=0;e<n;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,i++)r[i]=s[o];return r}function Ds(t){return this instanceof Ds?(this.v=t,this):new Ds(t)}function c7(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(t,e||[]),i,s=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(d){r[d]&&(i[d]=function(h){return new Promise(function(p,g){s.push([d,h,p,g])>1||a(d,h)})})}function a(d,h){try{c(r[d](h))}catch(p){f(s[0][3],p)}}function c(d){d.value instanceof Ds?Promise.resolve(d.value.v).then(u,l):f(s[0][2],d)}function u(d){a("next",d)}function l(d){a("throw",d)}function f(d,h){d(h),s.shift(),s.length&&a(s[0][0],s[0][1])}}function u7(t){var e,n;return e={},r("next"),r("throw",function(i){throw i}),r("return"),e[Symbol.iterator]=function(){return this},e;function r(i,s){e[i]=t[i]?function(o){return(n=!n)?{value:Ds(t[i](o)),done:i==="return"}:s?s(o):o}:s}}function l7(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof xl=="function"?xl(t):t[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[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 f7(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function h7(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function d7(t){return t&&t.__esModule?t:{default:t}}function p7(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function g7(t,e,n){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,n),n}var y7=Object.freeze({__proto__:null,__extends:X9,get __assign(){return El},__rest:J9,__decorate:Q9,__param:e7,__metadata:t7,__awaiter:n7,__generator:r7,__createBinding:i7,__exportStar:s7,__values:xl,__read:F1,__spread:o7,__spreadArrays:a7,__await:Ds,__asyncGenerator:c7,__asyncDelegator:u7,__asyncValues:l7,__makeTemplateObject:f7,__importStar:h7,__importDefault:d7,__classPrivateFieldGet:p7,__classPrivateFieldSet:g7}),b7=Wl(y7),Nn={},L1;function w7(){if(L1)return Nn;L1=1,Object.defineProperty(Nn,"__esModule",{value:!0}),Nn.isBrowserCryptoAvailable=Nn.getSubtleCrypto=Nn.getBrowerCrypto=void 0;function t(){return Jt?.crypto||Jt?.msCrypto||{}}Nn.getBrowerCrypto=t;function e(){const r=t();return r.subtle||r.webkitSubtle}Nn.getSubtleCrypto=e;function n(){return!!t()&&!!e()}return Nn.isBrowserCryptoAvailable=n,Nn}var Cn={},k1;function m7(){if(k1)return Cn;k1=1,Object.defineProperty(Cn,"__esModule",{value:!0}),Cn.isBrowser=Cn.isNode=Cn.isReactNative=void 0;function t(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}Cn.isReactNative=t;function e(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}Cn.isNode=e;function n(){return!t()&&!e()}return Cn.isBrowser=n,Cn}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=b7;e.__exportStar(w7(),t),e.__exportStar(m7(),t)})(U1);function an(t=3){const e=Date.now()*Math.pow(10,t),n=Math.floor(Math.random()*Math.pow(10,t));return e+n}function Er(t=6){return BigInt(an(t))}function Un(t,e,n){return{id:n||an(),jsonrpc:"2.0",method:t,params:e}}function va(t,e){return{id:t,jsonrpc:"2.0",result:e}}function _l(t,e,n){return{id:t,jsonrpc:"2.0",error:v7(e,n)}}function v7(t,e){return typeof t>"u"?C1(R1):(typeof t=="string"&&(t=Object.assign(Object.assign({},C1(ml)),{message:t})),typeof e<"u"&&(t.data=e),W9(t.code)&&(t=Z9(t.code)),t)}class E7{}class x7 extends E7{constructor(){super()}}class _7 extends x7{constructor(e){super()}}const S7="^wss?:";function I7(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function A7(t,e){const n=I7(t);return typeof n>"u"?!1:new RegExp(e).test(n)}function q1(t){return A7(t,S7)}function B7(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function M1(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function Sl(t){return M1(t)&&"method"in t}function Ea(t){return M1(t)&&(cn(t)||Lt(t))}function cn(t){return"result"in t}function Lt(t){return"error"in t}class O7 extends _7{constructor(e){super(e),this.events=new Ve.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,n){this.events.on(e,n)}once(e,n){this.events.once(e,n)}off(e,n){this.events.off(e,n)}removeListener(e,n){this.events.removeListener(e,n)}async request(e,n){return this.requestStrict(Un(e.method,e.params||[],e.id||Er().toString()),n)}async requestStrict(e,n){return new Promise(async(r,i)=>{if(!this.connection.connected)try{await this.open()}catch(s){i(s)}this.events.on(`${e.id}`,s=>{Lt(s)?i(s.error):r(s.result)});try{await this.connection.send(e,n)}catch(s){i(s)}})}setConnection(e=this.connection){return e}onPayload(e){this.events.emit("payload",e),Ea(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 D7=()=>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"),$7=()=>typeof WebSocket<"u"||typeof global<"u"&&typeof global.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",j1=t=>t.split("?")[0],z1=10,P7=D7();class T7{constructor(e){if(this.url=e,this.events=new Ve.exports.EventEmitter,this.registering=!1,!q1(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,n){this.events.on(e,n)}once(e,n){this.events.once(e,n)}off(e,n){this.events.off(e,n)}removeListener(e,n){this.events.removeListener(e,n)}async open(e=this.url){await this.register(e)}async close(){return new Promise((e,n)=>{if(typeof this.socket>"u"){n(new Error("Connection already closed"));return}this.socket.onclose=r=>{this.onClose(r),e()},this.socket.close()})}async send(e){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(Br(e))}catch(n){this.onError(e.id,n)}}register(e=this.url){if(!q1(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);if(this.registering){const n=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=n||this.events.listenerCount("open")>=n)&&this.events.setMaxListeners(n+1),new Promise((r,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"));r(this.socket)})})}return this.url=e,this.registering=!0,new Promise((n,r)=>{const i=U1.isReactNative()?void 0:{rejectUnauthorized:!B7(e)},s=new P7(e,[],i);$7()?s.onerror=o=>{const a=o;r(this.emitError(a.error))}:s.on("error",o=>{r(this.emitError(o))}),s.onopen=()=>{this.onOpen(s),n(s)}})}onOpen(e){e.onmessage=n=>this.onPayload(n),e.onclose=n=>this.onClose(n),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 n=typeof e.data=="string"?ni(e.data):e.data;this.events.emit("payload",n)}onError(e,n){const r=this.parseError(n),i=r.message||r.toString(),s=_l(e,i);this.events.emit("payload",s)}parseError(e,n=this.url){return Y9(e,j1(n),"WS")}resetMaxListeners(){this.events.getMaxListeners()>z1&&this.events.setMaxListeners(z1)}emitError(e){const n=this.parseError(new Error(e?.message||`WebSocket connection failed for host: ${j1(this.url)}`));return this.events.emit("register_error",n),n}}const H1="wc",V1=2,xa="core",un=`${H1}@2:${xa}:`,R7={name:xa,logger:"error"},N7={database:":memory:"},C7="crypto",K1="client_ed25519_seed",U7=K.ONE_DAY,F7="keychain",L7="0.3",k7="messages",q7="0.3",M7=K.SIX_HOURS,j7="publisher",G1="irn",z7="error",W1="wss://relay.walletconnect.org",H7="relayer",Se={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"},V7="_subscription",kt={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},K7=.1,Il="2.22.3",me={link_mode:"link_mode",relay:"relay"},_a={inbound:"inbound",outbound:"outbound"},G7="0.3",W7="WALLETCONNECT_CLIENT_ID",Z1="WALLETCONNECT_LINK_MODE_APPS",Dt={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},Z7="subscription",Y7="0.3",X7="pairing",J7="0.3",$s={wc_pairingDelete:{req:{ttl:K.ONE_DAY,prompt:!1,tag:1e3},res:{ttl:K.ONE_DAY,prompt:!1,tag:1001}},wc_pairingPing:{req:{ttl:K.THIRTY_SECONDS,prompt:!1,tag:1002},res:{ttl:K.THIRTY_SECONDS,prompt:!1,tag:1003}},unregistered_method:{req:{ttl:K.ONE_DAY,prompt:!1,tag:0},res:{ttl:K.ONE_DAY,prompt:!1,tag:0}}},Yr={create:"pairing_create",expire:"pairing_expire",delete:"pairing_delete",ping:"pairing_ping"},Yt={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},Q7="history",eA="0.3",tA="expirer",qt={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},nA="0.3",rA="verify-api",iA="https://verify.walletconnect.com",Y1="https://verify.walletconnect.org",Ps=Y1,sA=`${Ps}/v3`,oA=[iA,Y1],aA="echo",cA="https://echo.walletconnect.com",ln={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"},Fn={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"},Xt={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",session_request_response_started:"session_request_response_started",session_request_response_validation_success:"session_request_response_validation_success",session_request_response_publish_started:"session_request_response_publish_started"},Xr={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",session_request_response_validation_failure:"session_request_response_validation_failure",session_request_response_publish_failure:"session_request_response_publish_failure"},Jr={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"},Ts={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"},uA=.1,lA="event-client",fA=86400,hA="https://pulse.walletconnect.org/batch";function dA(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[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 f(p){if(p instanceof Uint8Array||(ArrayBuffer.isView(p)?p=new Uint8Array(p.buffer,p.byteOffset,p.byteLength):Array.isArray(p)&&(p=Uint8Array.from(p))),!(p instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(p.length===0)return"";for(var g=0,v=0,B=0,D=p.length;B!==D&&p[B]===0;)B++,g++;for(var _=(D-B)*l+1>>>0,x=new Uint8Array(_);B!==D;){for(var $=p[B],T=0,U=_-1;($!==0||T<v)&&U!==-1;U--,T++)$+=256*x[U]>>>0,x[U]=$%a>>>0,$=$/a>>>0;if($!==0)throw new Error("Non-zero carry");v=T,B++}for(var F=_-v;F!==_&&x[F]===0;)F++;for(var P=c.repeat(g);F<_;++F)P+=t.charAt(x[F]);return P}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var g=0;if(p[g]!==" "){for(var v=0,B=0;p[g]===c;)v++,g++;for(var D=(p.length-g)*u+1>>>0,_=new Uint8Array(D);p[g];){var x=n[p.charCodeAt(g)];if(x===255)return;for(var $=0,T=D-1;(x!==0||$<B)&&T!==-1;T--,$++)x+=a*_[T]>>>0,_[T]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");B=$,g++}if(p[g]!==" "){for(var U=D-B;U!==D&&_[U]===0;)U++;for(var F=new Uint8Array(v+(D-U)),P=v;U!==D;)F[P++]=_[U++];return F}}}function h(p){var g=d(p);if(g)return g;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:h}}var pA=dA,gA=pA;const X1=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")},yA=t=>new TextEncoder().encode(t),bA=t=>new TextDecoder().decode(t);class wA{constructor(e,n,r){this.name=e,this.prefix=n,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class mA{constructor(e,n,r){if(this.name=e,this.prefix=n,n.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=n.codePointAt(0),this.baseDecode=r}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 J1(this,e)}}class vA{constructor(e){this.decoders=e}or(e){return J1(this,e)}decode(e){const n=e[0],r=this.decoders[n];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const J1=(t,e)=>new vA({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class EA{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new wA(e,n,r),this.decoder=new mA(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Sa=({name:t,prefix:e,encode:n,decode:r})=>new EA(t,e,n,r),Rs=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=gA(n,e);return Sa({prefix:t,name:e,encode:r,decode:s=>X1(i(s))})},xA=(t,e,n,r)=>{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*n/8|0);let a=0,c=0,u=0;for(let l=0;l<s;++l){const f=i[t[l]];if(f===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<n|f,a+=n,a>=8&&(a-=8,o[u++]=255&c>>a)}if(a>=n||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},_A=(t,e,n)=>{const r=e[e.length-1]==="=",i=(1<<n)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>n;)o-=n,s+=e[i&a>>o];if(o&&(s+=e[i&a<<n-o]),r)for(;s.length*n&7;)s+="=";return s},Me=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>Sa({prefix:e,name:t,encode(i){return _A(i,r,n)},decode(i){return xA(i,r,n,t)}}),SA=Sa({prefix:"\0",name:"identity",encode:t=>bA(t),decode:t=>yA(t)});var IA=Object.freeze({__proto__:null,identity:SA});const AA=Me({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var BA=Object.freeze({__proto__:null,base2:AA});const OA=Me({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var DA=Object.freeze({__proto__:null,base8:OA});const $A=Rs({prefix:"9",name:"base10",alphabet:"0123456789"});var PA=Object.freeze({__proto__:null,base10:$A});const TA=Me({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),RA=Me({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var NA=Object.freeze({__proto__:null,base16:TA,base16upper:RA});const CA=Me({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),UA=Me({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),FA=Me({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),LA=Me({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),kA=Me({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),qA=Me({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),MA=Me({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),jA=Me({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),zA=Me({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var HA=Object.freeze({__proto__:null,base32:CA,base32upper:UA,base32pad:FA,base32padupper:LA,base32hex:kA,base32hexupper:qA,base32hexpad:MA,base32hexpadupper:jA,base32z:zA});const VA=Rs({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),KA=Rs({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var GA=Object.freeze({__proto__:null,base36:VA,base36upper:KA});const WA=Rs({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ZA=Rs({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var YA=Object.freeze({__proto__:null,base58btc:WA,base58flickr:ZA});const XA=Me({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),JA=Me({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),QA=Me({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),eB=Me({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var tB=Object.freeze({__proto__:null,base64:XA,base64pad:JA,base64url:QA,base64urlpad:eB});const Q1=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}"),nB=Q1.reduce((t,e,n)=>(t[n]=e,t),[]),rB=Q1.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function iB(t){return t.reduce((e,n)=>(e+=nB[n],e),"")}function sB(t){const e=[];for(const n of t){const r=rB[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const oB=Sa({prefix:"\u{1F680}",name:"base256emoji",encode:iB,decode:sB});var aB=Object.freeze({__proto__:null,base256emoji:oB}),cB=ty,ey=128,uB=127,lB=~uB,fB=Math.pow(2,31);function ty(t,e,n){e=e||[],n=n||0;for(var r=n;t>=fB;)e[n++]=t&255|ey,t/=128;for(;t&lB;)e[n++]=t&255|ey,t>>>=7;return e[n]=t|0,ty.bytes=n-r+1,e}var hB=Al,dB=128,ny=127;function Al(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw Al.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&ny)<<i:(o&ny)*Math.pow(2,i),i+=7}while(o>=dB);return Al.bytes=s-r,n}var pB=Math.pow(2,7),gB=Math.pow(2,14),yB=Math.pow(2,21),bB=Math.pow(2,28),wB=Math.pow(2,35),mB=Math.pow(2,42),vB=Math.pow(2,49),EB=Math.pow(2,56),xB=Math.pow(2,63),_B=function(t){return t<pB?1:t<gB?2:t<yB?3:t<bB?4:t<wB?5:t<mB?6:t<vB?7:t<EB?8:t<xB?9:10},SB={encode:cB,decode:hB,encodingLength:_B},ry=SB;const iy=(t,e,n=0)=>(ry.encode(t,e,n),e),sy=t=>ry.encodingLength(t),Bl=(t,e)=>{const n=e.byteLength,r=sy(t),i=r+sy(n),s=new Uint8Array(i+n);return iy(t,s,0),iy(n,s,r),s.set(e,i),new IB(t,n,e,s)};class IB{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const oy=({name:t,code:e,encode:n})=>new AB(t,e,n);class AB{constructor(e,n,r){this.name=e,this.code=n,this.encode=r}digest(e){if(e instanceof Uint8Array){const n=this.encode(e);return n instanceof Uint8Array?Bl(this.code,n):n.then(r=>Bl(this.code,r))}else throw Error("Unknown type, must be binary type")}}const ay=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),BB=oy({name:"sha2-256",code:18,encode:ay("SHA-256")}),OB=oy({name:"sha2-512",code:19,encode:ay("SHA-512")});var DB=Object.freeze({__proto__:null,sha256:BB,sha512:OB});const cy=0,$B="identity",uy=X1;var PB=Object.freeze({__proto__:null,identity:{code:cy,name:$B,encode:uy,digest:t=>Bl(cy,uy(t))}});new TextEncoder,new TextDecoder;const ly={...IA,...BA,...DA,...PA,...NA,...HA,...GA,...YA,...tB,...aB};({...DB,...PB});function fy(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function TB(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?fy(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function hy(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const dy=hy("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ol=hy("ascii","a",t=>{let e="a";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e},t=>{t=t.substring(1);const e=TB(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),RB={utf8:dy,"utf-8":dy,hex:ly.base16,latin1:Ol,ascii:Ol,binary:Ol,...ly};function NB(t,e="utf8"){const n=RB[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?fy(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}var CB=Object.defineProperty,UB=(t,e,n)=>e in t?CB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fn=(t,e,n)=>UB(t,typeof e!="symbol"?e+"":e,n);class FB{constructor(e,n){this.core=e,this.logger=n,fn(this,"keychain",new Map),fn(this,"name",F7),fn(this,"version",L7),fn(this,"initialized",!1),fn(this,"storagePrefix",un),fn(this,"init",async()=>{if(!this.initialized){const r=await this.getKeyChain();typeof r<"u"&&(this.keychain=r),this.initialized=!0}}),fn(this,"has",r=>(this.isInitialized(),this.keychain.has(r))),fn(this,"set",async(r,i)=>{this.isInitialized(),this.keychain.set(r,i),await this.persist()}),fn(this,"get",r=>{this.isInitialized();const i=this.keychain.get(r);if(typeof i>"u"){const{message:s}=G("NO_MATCHING_KEY",`${this.name}: ${r}`);throw new Error(s)}return i}),fn(this,"del",async r=>{this.isInitialized(),this.keychain.delete(r),await this.persist()}),this.core=e,this.logger=_t(n,this.name)}get context(){return ft(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,Ru(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Nu(e):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:e}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}}var LB=Object.defineProperty,kB=(t,e,n)=>e in t?LB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ce=(t,e,n)=>kB(t,typeof e!="symbol"?e+"":e,n);class qB{constructor(e,n,r){this.core=e,this.logger=n,Ce(this,"name",C7),Ce(this,"keychain"),Ce(this,"randomSessionIdentifier",dl()),Ce(this,"initialized",!1),Ce(this,"clientId"),Ce(this,"init",async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)}),Ce(this,"hasKeys",i=>(this.isInitialized(),this.keychain.has(i))),Ce(this,"getClientId",async()=>{if(this.isInitialized(),this.clientId)return this.clientId;const i=await this.getClientSeed(),s=$h(i),o=Dh(s.publicKey);return this.clientId=o,o}),Ce(this,"generateKeyPair",()=>{this.isInitialized();const i=II();return this.setPrivateKey(i.publicKey,i.privateKey)}),Ce(this,"signJWT",async i=>{this.isInitialized();const s=await this.getClientSeed(),o=$h(s),a=this.randomSessionIdentifier;return await c3(a,i,U7,o)}),Ce(this,"generateSharedKey",(i,s,o)=>{this.isInitialized();const a=this.getPrivateKey(i),c=AI(a,s);return this.setSymKey(c,o)}),Ce(this,"setSymKey",async(i,s)=>{this.isInitialized();const o=s||ya(i);return await this.keychain.set(o,i),o}),Ce(this,"deleteKeyPair",async i=>{this.isInitialized(),await this.keychain.del(i)}),Ce(this,"deleteSymKey",async i=>{this.isInitialized(),await this.keychain.del(i)}),Ce(this,"encode",async(i,s,o)=>{this.isInitialized();const a=d1(o),c=Br(s);if(g1(a))return DI(c,o?.encoding);if(p1(a)){const d=a.senderPublicKey,h=a.receiverPublicKey;i=await this.generateSharedKey(d,h)}const u=this.getSymKey(i),{type:l,senderPublicKey:f}=a;return BI({type:l,symKey:u,message:c,senderPublicKey:f,encoding:o?.encoding})}),Ce(this,"decode",async(i,s,o)=>{this.isInitialized();const a=PI(s,o);if(g1(a)){const c=$I(s,o?.encoding);return ni(c)}if(p1(a)){const c=a.receiverPublicKey,u=a.senderPublicKey;i=await this.generateSharedKey(c,u)}try{const c=this.getSymKey(i),u=OI({symKey:c,encoded:s,encoding:o?.encoding});return ni(u)}catch(c){this.logger.error(`Failed to decode message from topic: '${i}', clientId: '${await this.getClientId()}'`),this.logger.error(c)}}),Ce(this,"getPayloadType",(i,s=vt)=>{const o=Is({encoded:i,encoding:s});return Zr(o.type)}),Ce(this,"getPayloadSenderPublicKey",(i,s=vt)=>{const o=Is({encoded:i,encoding:s});return o.senderPublicKey?bt(o.senderPublicKey,ut):void 0}),this.core=e,this.logger=_t(n,this.name),this.keychain=r||new FB(this.core,this.logger)}get context(){return ft(this.logger)}async setPrivateKey(e,n){return await this.keychain.set(e,n),e}getPrivateKey(e){return this.keychain.get(e)}async getClientSeed(){let e="";try{e=this.keychain.get(K1)}catch{e=dl(),await this.keychain.set(K1,e)}return NB(e,"base16")}getSymKey(e){return this.keychain.get(e)}isInitialized(){if(!this.initialized){const{message:e}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}}var MB=Object.defineProperty,jB=Object.defineProperties,zB=Object.getOwnPropertyDescriptors,py=Object.getOwnPropertySymbols,HB=Object.prototype.hasOwnProperty,VB=Object.prototype.propertyIsEnumerable,Dl=(t,e,n)=>e in t?MB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,KB=(t,e)=>{for(var n in e||(e={}))HB.call(e,n)&&Dl(t,n,e[n]);if(py)for(var n of py(e))VB.call(e,n)&&Dl(t,n,e[n]);return t},GB=(t,e)=>jB(t,zB(e)),$t=(t,e,n)=>Dl(t,typeof e!="symbol"?e+"":e,n);class WB extends am{constructor(e,n){super(e,n),this.logger=e,this.core=n,$t(this,"messages",new Map),$t(this,"messagesWithoutClientAck",new Map),$t(this,"name",k7),$t(this,"version",q7),$t(this,"initialized",!1),$t(this,"storagePrefix",un),$t(this,"init",async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const r=await this.getRelayerMessages();typeof r<"u"&&(this.messages=r);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(r){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(r)}finally{this.initialized=!0}}}),$t(this,"set",async(r,i,s)=>{this.isInitialized();const o=Ft(i);let a=this.messages.get(r);if(typeof a>"u"&&(a={}),typeof a[o]<"u")return o;if(a[o]=i,this.messages.set(r,a),s===_a.inbound){const c=this.messagesWithoutClientAck.get(r)||{};this.messagesWithoutClientAck.set(r,GB(KB({},c),{[o]:i}))}return await this.persist(),o}),$t(this,"get",r=>{this.isInitialized();let i=this.messages.get(r);return typeof i>"u"&&(i={}),i}),$t(this,"getWithoutAck",r=>{this.isInitialized();const i={};for(const s of r){const o=this.messagesWithoutClientAck.get(s)||{};i[s]=Object.values(o)}return i}),$t(this,"has",(r,i)=>{this.isInitialized();const s=this.get(r),o=Ft(i);return typeof s[o]<"u"}),$t(this,"ack",async(r,i)=>{this.isInitialized();const s=this.messagesWithoutClientAck.get(r);if(typeof s>"u")return;const o=Ft(i);delete s[o],Object.keys(s).length===0?this.messagesWithoutClientAck.delete(r):this.messagesWithoutClientAck.set(r,s),await this.persist()}),$t(this,"del",async r=>{this.isInitialized(),this.messages.delete(r),this.messagesWithoutClientAck.delete(r),await this.persist()}),this.logger=_t(e,this.name),this.core=n}get context(){return ft(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,Ru(e))}async setRelayerMessagesWithoutClientAck(e){await this.core.storage.setItem(this.storageKeyWithoutClientAck,Ru(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Nu(e):void 0}async getRelayerMessagesWithoutClientAck(){const e=await this.core.storage.getItem(this.storageKeyWithoutClientAck);return typeof e<"u"?Nu(e):void 0}async persist(){await this.setRelayerMessages(this.messages),await this.setRelayerMessagesWithoutClientAck(this.messagesWithoutClientAck)}isInitialized(){if(!this.initialized){const{message:e}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}}var ZB=Object.defineProperty,YB=Object.defineProperties,XB=Object.getOwnPropertyDescriptors,gy=Object.getOwnPropertySymbols,JB=Object.prototype.hasOwnProperty,QB=Object.prototype.propertyIsEnumerable,$l=(t,e,n)=>e in t?ZB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ti=(t,e)=>{for(var n in e||(e={}))JB.call(e,n)&&$l(t,n,e[n]);if(gy)for(var n of gy(e))QB.call(e,n)&&$l(t,n,e[n]);return t},yy=(t,e)=>YB(t,XB(e)),Mt=(t,e,n)=>$l(t,typeof e!="symbol"?e+"":e,n);class eO extends cm{constructor(e,n){super(e,n),this.relayer=e,this.logger=n,Mt(this,"events",new Ve.exports.EventEmitter),Mt(this,"name",j7),Mt(this,"queue",new Map),Mt(this,"publishTimeout",K.toMiliseconds(K.ONE_MINUTE)),Mt(this,"initialPublishTimeout",K.toMiliseconds(K.ONE_SECOND*15)),Mt(this,"needsTransportRestart",!1),Mt(this,"publish",async(r,i,s)=>{var o,a,c,u,l;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:r,message:i,opts:s}});const f=s?.ttl||M7,d=s?.prompt||!1,h=s?.tag||0,p=s?.id||Er().toString(),g=Di(ba().protocol),v={id:p,method:s?.publishMethod||g.publish,params:Ti({topic:r,message:i,ttl:f,prompt:d,tag:h,attestation:s?.attestation},s?.tvf)},B=`Failed to publish payload, please try again. id:${p} tag:${h}`;try{Pe((o=v.params)==null?void 0:o.prompt)&&((a=v.params)==null||delete a.prompt),Pe((c=v.params)==null?void 0:c.tag)&&((u=v.params)==null||delete u.tag);const D=new Promise(async _=>{const x=({id:T})=>{var U;((U=v.id)==null?void 0:U.toString())===T.toString()&&(this.removeRequestFromQueue(T),this.relayer.events.removeListener(Se.publish,x),_())};this.relayer.events.on(Se.publish,x);const $=sn(new Promise((T,U)=>{this.rpcPublish(v,s).then(T).catch(F=>{this.logger.warn(F,F?.message),U(F)})}),this.initialPublishTimeout,`Failed initial publish, retrying.... id:${p} tag:${h}`);try{await $,this.events.removeListener(Se.publish,x)}catch(T){this.queue.set(p,{request:v,opts:s,attempt:1}),this.logger.warn(T,T?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:p,topic:r,message:i,opts:s}}),await sn(D,this.publishTimeout,B)}catch(D){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(D),(l=s?.internal)!=null&&l.throwOnFailedPublish)throw D}finally{this.queue.delete(p)}}),Mt(this,"publishCustom",async r=>{var i,s,o,a,c;this.logger.debug("Publishing custom payload"),this.logger.trace({type:"method",method:"publishCustom",params:r});const{payload:u,opts:l={}}=r,{attestation:f,tvf:d,publishMethod:h,prompt:p,tag:g,ttl:v=K.FIVE_MINUTES}=l,B=l.id||Er().toString(),D=Di(ba().protocol),_=h||D.publish,x={id:B,method:_,params:Ti(yy(Ti({},u),{ttl:v,prompt:p,tag:g,attestation:f}),d)},$=`Failed to publish custom payload, please try again. id:${B} tag:${g}`;try{Pe((i=x.params)==null?void 0:i.prompt)&&((s=x.params)==null||delete s.prompt),Pe((o=x.params)==null?void 0:o.tag)&&((a=x.params)==null||delete a.tag);const T=new Promise(async U=>{const F=({id:z})=>{var M;((M=x.id)==null?void 0:M.toString())===z.toString()&&(this.removeRequestFromQueue(z),this.relayer.events.removeListener(Se.publish,F),U())};this.relayer.events.on(Se.publish,F);const P=sn(new Promise((z,M)=>{this.rpcPublish(x,l).then(z).catch(E=>{this.logger.warn(E,E?.message),M(E)})}),this.initialPublishTimeout,`Failed initial custom payload publish, retrying.... method:${_} id:${B} tag:${g}`);try{await P,this.events.removeListener(Se.publish,F)}catch(z){this.queue.set(B,{request:x,opts:l,attempt:1}),this.logger.warn(z,z?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:B,payload:u,opts:l}}),await sn(T,this.publishTimeout,$)}catch(T){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(T),(c=l?.internal)!=null&&c.throwOnFailedPublish)throw T}finally{this.queue.delete(B)}}),Mt(this,"on",(r,i)=>{this.events.on(r,i)}),Mt(this,"once",(r,i)=>{this.events.once(r,i)}),Mt(this,"off",(r,i)=>{this.events.off(r,i)}),Mt(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),this.relayer=e,this.logger=_t(n,this.name),this.registerEventListeners()}get context(){return ft(this.logger)}async rpcPublish(e,n){this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:e});const r=await this.relayer.request(e);return this.relayer.events.emit(Se.publish,Ti(Ti({},e),n)),this.logger.debug("Successfully Published Payload"),r}removeRequestFromQueue(e){this.queue.delete(e)}checkQueue(){this.queue.forEach(async(e,n)=>{var r;const i=e.attempt+1;this.queue.set(n,yy(Ti({},e),{attempt:i})),this.logger.warn({},`Publisher: queue->publishing: ${e.request.id}, tag: ${(r=e.request.params)==null?void 0:r.tag}, attempt: ${i}`),await this.rpcPublish(e.request,e.opts),this.logger.warn({},`Publisher: queue->published: ${e.request.id}`)})}registerEventListeners(){this.relayer.core.heartbeat.on(Ir.pulse,()=>{if(this.needsTransportRestart){this.needsTransportRestart=!1,this.relayer.events.emit(Se.connection_stalled);return}this.checkQueue()}),this.relayer.on(Se.message_ack,e=>{this.removeRequestFromQueue(e.id.toString())})}}var tO=Object.defineProperty,nO=(t,e,n)=>e in t?tO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ri=(t,e,n)=>nO(t,typeof e!="symbol"?e+"":e,n);class rO{constructor(){Ri(this,"map",new Map),Ri(this,"set",(e,n)=>{const r=this.get(e);this.exists(e,n)||this.map.set(e,[...r,n])}),Ri(this,"get",e=>this.map.get(e)||[]),Ri(this,"exists",(e,n)=>this.get(e).includes(n)),Ri(this,"delete",(e,n)=>{if(typeof n>"u"){this.map.delete(e);return}if(!this.map.has(e))return;const r=this.get(e);if(!this.exists(e,n))return;const i=r.filter(s=>s!==n);if(!i.length){this.map.delete(e);return}this.map.set(e,i)}),Ri(this,"clear",()=>{this.map.clear()})}get topics(){return Array.from(this.map.keys())}}var iO=Object.defineProperty,sO=Object.defineProperties,oO=Object.getOwnPropertyDescriptors,by=Object.getOwnPropertySymbols,aO=Object.prototype.hasOwnProperty,cO=Object.prototype.propertyIsEnumerable,Pl=(t,e,n)=>e in t?iO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ns=(t,e)=>{for(var n in e||(e={}))aO.call(e,n)&&Pl(t,n,e[n]);if(by)for(var n of by(e))cO.call(e,n)&&Pl(t,n,e[n]);return t},Tl=(t,e)=>sO(t,oO(e)),ye=(t,e,n)=>Pl(t,typeof e!="symbol"?e+"":e,n);class uO extends fm{constructor(e,n){super(e,n),this.relayer=e,this.logger=n,ye(this,"subscriptions",new Map),ye(this,"topicMap",new rO),ye(this,"events",new Ve.exports.EventEmitter),ye(this,"name",Z7),ye(this,"version",Y7),ye(this,"pending",new Map),ye(this,"cached",[]),ye(this,"initialized",!1),ye(this,"storagePrefix",un),ye(this,"subscribeTimeout",K.toMiliseconds(K.ONE_MINUTE)),ye(this,"initialSubscribeTimeout",K.toMiliseconds(K.ONE_SECOND*15)),ye(this,"clientId"),ye(this,"batchSubscribeTopicsLimit",500),ye(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),await this.restore()),this.initialized=!0}),ye(this,"subscribe",async(r,i)=>{var s;this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:r,opts:i}});try{const o=ba(i),a={topic:r,relay:o,transportType:i?.transportType};(s=i?.internal)!=null&&s.skipSubscribe||this.pending.set(r,a);const c=await this.rpcSubscribe(r,o,i);return typeof c=="string"&&(this.onSubscribe(c,a),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:r,opts:i}})),c}catch(o){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(o),o}}),ye(this,"unsubscribe",async(r,i)=>{this.isInitialized(),typeof i?.id<"u"?await this.unsubscribeById(r,i.id,i):await this.unsubscribeByTopic(r,i)}),ye(this,"isSubscribed",r=>new Promise(i=>{i(this.topicMap.topics.includes(r))})),ye(this,"isKnownTopic",r=>new Promise(i=>{i(this.topicMap.topics.includes(r)||this.pending.has(r)||this.cached.some(s=>s.topic===r))})),ye(this,"on",(r,i)=>{this.events.on(r,i)}),ye(this,"once",(r,i)=>{this.events.once(r,i)}),ye(this,"off",(r,i)=>{this.events.off(r,i)}),ye(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),ye(this,"start",async()=>{await this.onConnect()}),ye(this,"stop",async()=>{await this.onDisconnect()}),ye(this,"restart",async()=>{await this.restore(),await this.onRestart()}),ye(this,"checkPending",async()=>{if(this.pending.size===0&&(!this.initialized||!this.relayer.connected))return;const r=[];this.pending.forEach(i=>{r.push(i)}),await this.batchSubscribe(r)}),ye(this,"registerEventListeners",()=>{this.relayer.core.heartbeat.on(Ir.pulse,async()=>{await this.checkPending()}),this.events.on(Dt.created,async r=>{const i=Dt.created;this.logger.info(`Emitting ${i}`),this.logger.debug({type:"event",event:i,data:r}),await this.persist()}),this.events.on(Dt.deleted,async r=>{const i=Dt.deleted;this.logger.info(`Emitting ${i}`),this.logger.debug({type:"event",event:i,data:r}),await this.persist()})}),this.relayer=e,this.logger=_t(n,this.name),this.clientId=""}get context(){return ft(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,n){let r=!1;try{r=this.getSubscription(e).topic===n}catch{}return r}reset(){this.cached=[],this.initialized=!0}onDisable(){this.values.length>0&&(this.cached=this.values),this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(e,n){const r=this.topicMap.get(e);await Promise.all(r.map(async i=>await this.unsubscribeById(e,i,n)))}async unsubscribeById(e,n,r){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:n,opts:r}});try{const i=ba(r);await this.restartToComplete({topic:e,id:n,relay:i}),await this.rpcUnsubscribe(e,n,i);const s=Ee("USER_DISCONNECTED",`${this.name}, ${e}`);await this.onUnsubscribe(e,n,s),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:n,opts:r}})}catch(i){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(i),i}}async rpcSubscribe(e,n,r){var i,s;const o=await this.getSubscriptionId(e);if((i=r?.internal)!=null&&i.skipSubscribe)return o;(!r||r?.transportType===me.relay)&&await this.restartToComplete({topic:e,id:e,relay:n});const a={method:Di(n.protocol).subscribe,params:{topic:e}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:a});const c=(s=r?.internal)==null?void 0:s.throwOnFailedPublish;try{if(r?.transportType===me.link_mode)return setTimeout(()=>{(this.relayer.connected||this.relayer.connecting)&&this.relayer.request(a).catch(f=>this.logger.warn(f))},K.toMiliseconds(K.ONE_SECOND)),o;const u=new Promise(async f=>{const d=h=>{h.topic===e&&(this.events.removeListener(Dt.created,d),f(h.id))};this.events.on(Dt.created,d);try{const h=await sn(new Promise((p,g)=>{this.relayer.request(a).catch(v=>{this.logger.warn(v,v?.message),g(v)}).then(p)}),this.initialSubscribeTimeout,`Subscribing to ${e} failed, please try again`);this.events.removeListener(Dt.created,d),f(h)}catch{}}),l=await sn(u,this.subscribeTimeout,`Subscribing to ${e} failed, please try again`);if(!l&&c)throw new Error(`Subscribing to ${e} failed, please try again`);return l?o:null}catch(u){if(this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(Se.connection_stalled),c)throw u}return null}async rpcBatchSubscribe(e){if(!e.length)return;const n=e[0].relay,r={method:Di(n.protocol).batchSubscribe,params:{topics:e.map(i=>i.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:r});try{await await sn(new Promise(i=>{this.relayer.request(r).catch(s=>this.logger.warn(s)).then(i)}),this.subscribeTimeout,"rpcBatchSubscribe failed, please try again")}catch{this.relayer.events.emit(Se.connection_stalled)}}async rpcBatchFetchMessages(e){if(!e.length)return;const n=e[0].relay,r={method:Di(n.protocol).batchFetchMessages,params:{topics:e.map(s=>s.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:r});let i;try{i=await await sn(new Promise((s,o)=>{this.relayer.request(r).catch(a=>{this.logger.warn(a),o(a)}).then(s)}),this.subscribeTimeout,"rpcBatchFetchMessages failed, please try again")}catch{this.relayer.events.emit(Se.connection_stalled)}return i}rpcUnsubscribe(e,n,r){const i={method:Di(r.protocol).unsubscribe,params:{topic:e,id:n}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.request(i)}onSubscribe(e,n){this.setSubscription(e,Tl(Ns({},n),{id:e})),this.pending.delete(n.topic)}onBatchSubscribe(e){e.length&&e.forEach(n=>{this.setSubscription(n.id,Ns({},n)),this.pending.delete(n.topic)})}async onUnsubscribe(e,n,r){this.events.removeAllListeners(n),this.hasSubscription(n,e)&&this.deleteSubscription(n,r),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,n){this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:n}),this.addSubscription(e,n)}addSubscription(e,n){this.subscriptions.set(e,Ns({},n)),this.topicMap.set(n.topic,e),this.events.emit(Dt.created,n)}getSubscription(e){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const n=this.subscriptions.get(e);if(!n){const{message:r}=G("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(r)}return n}deleteSubscription(e,n){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:n});const r=this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(r.topic,e),this.events.emit(Dt.deleted,Tl(Ns({},r),{reason:n}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit(Dt.sync)}async onRestart(){if(this.cached.length){const e=[...this.cached],n=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let r=0;r<n;r++){const i=e.splice(0,this.batchSubscribeTopicsLimit);await this.batchSubscribe(i)}}this.events.emit(Dt.resubscribed)}async restore(){try{const e=await this.getRelayerSubscriptions();if(typeof e>"u"||!e.length)return;if(this.subscriptions.size&&!e.every(n=>{var r;return n.topic===((r=this.subscriptions.get(n.id))==null?void 0:r.topic)})){const{message:n}=G("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(n),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(n)}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 n=>Tl(Ns({},n),{id:await this.getSubscriptionId(n.topic)})))))}async batchFetchMessages(e){if(!e.length)return;this.logger.trace(`Fetching batch messages for ${e.length} subscriptions`);const n=await this.rpcBatchFetchMessages(e);n&&n.messages&&(await G_(K.toMiliseconds(K.ONE_SECOND)),await this.relayer.handleBatchMessageEvents(n.messages))}async onConnect(){await this.restart(),this.reset()}onDisconnect(){this.onDisable()}isInitialized(){if(!this.initialized){const{message:e}=G("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 Ft(e+await this.getClientId())}}var lO=Object.defineProperty,wy=Object.getOwnPropertySymbols,fO=Object.prototype.hasOwnProperty,hO=Object.prototype.propertyIsEnumerable,Rl=(t,e,n)=>e in t?lO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,my=(t,e)=>{for(var n in e||(e={}))fO.call(e,n)&&Rl(t,n,e[n]);if(wy)for(var n of wy(e))hO.call(e,n)&&Rl(t,n,e[n]);return t},ue=(t,e,n)=>Rl(t,typeof e!="symbol"?e+"":e,n);class dO extends um{constructor(e){var n;super(e),ue(this,"protocol","wc"),ue(this,"version",2),ue(this,"core"),ue(this,"logger"),ue(this,"events",new Ve.exports.EventEmitter),ue(this,"provider"),ue(this,"messages"),ue(this,"subscriber"),ue(this,"publisher"),ue(this,"name",H7),ue(this,"transportExplicitlyClosed",!1),ue(this,"initialized",!1),ue(this,"connectionAttemptInProgress",!1),ue(this,"relayUrl"),ue(this,"projectId"),ue(this,"packageName"),ue(this,"bundleId"),ue(this,"hasExperiencedNetworkDisruption",!1),ue(this,"pingTimeout"),ue(this,"heartBeatTimeout",K.toMiliseconds(K.THIRTY_SECONDS+K.FIVE_SECONDS)),ue(this,"reconnectTimeout"),ue(this,"connectPromise"),ue(this,"reconnectInProgress",!1),ue(this,"requestsInFlight",[]),ue(this,"connectTimeout",K.toMiliseconds(K.ONE_SECOND*15)),ue(this,"request",async r=>{var i,s;this.logger.debug("Publishing Request Payload");const o=r.id||Er().toString();await this.toEstablishConnection();try{this.logger.trace({id:o,method:r.method,topic:(i=r.params)==null?void 0:i.topic},"relayer.request - publishing...");const a=`${o}:${((s=r.params)==null?void 0:s.tag)||""}`;this.requestsInFlight.push(a);const c=await this.provider.request(r);return this.requestsInFlight=this.requestsInFlight.filter(u=>u!==a),c}catch(a){throw this.logger.debug(`Failed to Publish Request: ${o}`),a}}),ue(this,"resetPingTimeout",()=>{Yo()&&(clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{var r,i,s,o;try{this.logger.debug({},"pingTimeout: Connection stalled, terminating..."),(o=(s=(i=(r=this.provider)==null?void 0:r.connection)==null?void 0:i.socket)==null?void 0:s.terminate)==null||o.call(s)}catch(a){this.logger.warn(a,a?.message)}},this.heartBeatTimeout))}),ue(this,"onPayloadHandler",r=>{this.onProviderPayload(r),this.resetPingTimeout()}),ue(this,"onConnectHandler",()=>{this.logger.warn({},"Relayer connected \u{1F6DC}"),this.startPingTimeout(),this.events.emit(Se.connect)}),ue(this,"onDisconnectHandler",()=>{this.logger.warn({},"Relayer disconnected \u{1F6D1}"),this.requestsInFlight=[],this.onProviderDisconnect()}),ue(this,"onProviderErrorHandler",r=>{this.logger.fatal(`Fatal socket error: ${r.message}`),this.events.emit(Se.error,r),this.logger.fatal("Fatal socket error received, closing transport"),this.transportClose()}),ue(this,"registerProviderListeners",()=>{this.provider.on(kt.payload,this.onPayloadHandler),this.provider.on(kt.connect,this.onConnectHandler),this.provider.on(kt.disconnect,this.onDisconnectHandler),this.provider.on(kt.error,this.onProviderErrorHandler)}),this.core=e.core,this.logger=T1({logger:(n=e.logger)!=null?n:z7,name:this.name}),this.messages=new WB(this.logger,e.core),this.subscriber=new uO(this,this.logger),this.publisher=new eO(this,this.logger),this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||W1,P_()?this.packageName=U0():T_()&&(this.bundleId=U0()),this.provider={}}async init(){this.logger.trace("Initialized"),this.registerEventListeners(),await Promise.all([this.messages.init(),this.subscriber.init()]),this.initialized=!0,this.transportOpen().catch(e=>this.logger.warn(e,e?.message))}get context(){return ft(this.logger)}get connected(){var e,n,r;return((r=(n=(e=this.provider)==null?void 0:e.connection)==null?void 0:n.socket)==null?void 0:r.readyState)===1||!1}get connecting(){var e,n,r;return((r=(n=(e=this.provider)==null?void 0:e.connection)==null?void 0:n.socket)==null?void 0:r.readyState)===0||this.connectPromise!==void 0||!1}async publish(e,n,r){this.isInitialized(),await this.publisher.publish(e,n,r),await this.recordMessageEvent({topic:e,message:n,publishedAt:Date.now(),transportType:me.relay},_a.outbound)}async publishCustom(e){this.isInitialized(),await this.publisher.publishCustom(e)}async subscribe(e,n){var r,i,s;this.isInitialized(),(!(n!=null&&n.transportType)||n?.transportType==="relay")&&await this.toEstablishConnection();const o=typeof((r=n?.internal)==null?void 0:r.throwOnFailedPublish)>"u"?!0:(i=n?.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(Dt.created,u),c())};return await Promise.all([new Promise(l=>{c=l,this.subscriber.on(Dt.created,u)}),new Promise(async(l,f)=>{a=await this.subscriber.subscribe(e,my({internal:{throwOnFailedPublish:o}},n)).catch(d=>{o&&f(d)})||a,l()})]),a}async unsubscribe(e,n){this.isInitialized(),await this.subscriber.unsubscribe(e,n)}on(e,n){this.events.on(e,n)}once(e,n){this.events.once(e,n)}off(e,n){this.events.off(e,n)}removeListener(e,n){this.events.removeListener(e,n)}async transportDisconnect(){this.provider.disconnect&&(this.hasExperiencedNetworkDisruption||this.connected)?await sn(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.info("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(n,r)=>{await this.connect(e).then(n).catch(r).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 P1())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 n=e.sort((r,i)=>r.publishedAt-i.publishedAt);this.logger.debug(`Batch of ${n.length} message events sorted`);for(const r of n)try{await this.onMessageEvent(r)}catch(i){this.logger.warn(i,"Error while processing batch message event: "+i?.message)}this.logger.trace(`Batch of ${n.length} message events processed`)}async onLinkMessageEvent(e,n){const{topic:r}=e;if(!n.sessionExists){const i=De(K.FIVE_MINUTES),s={topic:r,expiry:i,relay:{protocol:"irn"},active:!1};await this.core.pairing.pairings.set(r,s)}this.events.emit(Se.message,e),await this.recordMessageEvent(e,_a.inbound)}async connect(e){await this.confirmOnlineStateOrThrow(),e&&e!==this.relayUrl&&(this.relayUrl=e,await this.transportDisconnect()),this.connectionAttemptInProgress=!0,this.transportExplicitlyClosed=!1;let n=1;for(;n<6;){try{if(this.transportExplicitlyClosed)break;this.logger.debug({},`Connecting to ${this.relayUrl}, attempt: ${n}...`),await this.createProvider(),await new Promise(async(r,i)=>{const s=()=>{i(new Error("Connection interrupted while trying to connect"))};this.provider.once(kt.disconnect,s),await sn(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(kt.disconnect,s),clearTimeout(this.reconnectTimeout)}),await new Promise(async(o,a)=>{const c=()=>{i(new Error("Connection interrupted while trying to subscribe"))};this.provider.once(kt.disconnect,c),await this.subscriber.start().then(o).catch(a).finally(()=>{this.provider.off(kt.disconnect,c)})}),this.hasExperiencedNetworkDisruption=!1,r()})}catch(r){await this.subscriber.stop();const i=r;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: ${n}`);break}await new Promise(r=>setTimeout(r,K.toMiliseconds(n*1))),n++}}startPingTimeout(){var e,n,r,i,s;if(Yo())try{(n=(e=this.provider)==null?void 0:e.connection)!=null&&n.socket&&((s=(i=(r=this.provider)==null?void 0:r.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 O7(new T7(F_({sdkVersion:Il,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,n){const{topic:r,message:i}=e;await this.messages.set(r,i,n)}async shouldIgnoreMessageEvent(e){const{topic:n,message:r}=e;if(!r||r.length===0)return this.logger.warn(`Ignoring invalid/empty message: ${r}`),!0;if(!await this.subscriber.isKnownTopic(n))return this.logger.warn(`Ignoring message for unknown topic ${n}`),!0;const i=this.messages.has(n,r);return i&&this.logger.warn(`Ignoring duplicate message: ${r}`),i}async onProviderPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),Sl(e)){if(!e.method.endsWith(V7))return;const n=e.params,{topic:r,message:i,publishedAt:s,attestation:o}=n.data,a={topic:r,message:i,publishedAt:s,transportType:me.relay,attestation:o};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(my({type:"event",event:n.id},a)),this.events.emit(n.id,a),await this.acknowledgePayload(e),await this.onMessageEvent(a)}else Ea(e)&&this.events.emit(Se.message_ack,e)}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(await this.recordMessageEvent(e,_a.inbound),this.events.emit(Se.message,e))}async acknowledgePayload(e){const n=va(e.id,!0);await this.provider.connection.send(n)}unregisterProviderListeners(){this.provider.off(kt.payload,this.onPayloadHandler),this.provider.off(kt.connect,this.onConnectHandler),this.provider.off(kt.disconnect,this.onDisconnectHandler),this.provider.off(kt.error,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let e=await P1();P9(async n=>{e!==n&&(e=n,n?await this.transportOpen().catch(r=>this.logger.error(r,r?.message)):(this.hasExperiencedNetworkDisruption=!0,await this.transportDisconnect(),this.transportExplicitlyClosed=!1))}),this.core.heartbeat.on(Ir.pulse,async()=>{if(!this.transportExplicitlyClosed&&!this.connected&&N9())try{await this.confirmOnlineStateOrThrow(),await this.transportOpen()}catch(n){this.logger.warn(n,n?.message)}})}async onProviderDisconnect(){clearTimeout(this.pingTimeout),this.events.emit(Se.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},K.toMiliseconds(K7)))))}isInitialized(){if(!this.initialized){const{message:e}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}async toEstablishConnection(){if(await this.confirmOnlineStateOrThrow(),!this.connected){if(this.connectPromise){await this.connectPromise;return}await this.connect()}}}function pO(t,e){return t===e||Number.isNaN(t)&&Number.isNaN(e)}function vy(t){return Object.getOwnPropertySymbols(t).filter(e=>Object.prototype.propertyIsEnumerable.call(t,e))}function Ey(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const gO="[object RegExp]",yO="[object String]",bO="[object Number]",wO="[object Boolean]",xy="[object Arguments]",mO="[object Symbol]",vO="[object Date]",EO="[object Map]",xO="[object Set]",_O="[object Array]",SO="[object Function]",IO="[object ArrayBuffer]",Nl="[object Object]",AO="[object Error]",BO="[object DataView]",OO="[object Uint8Array]",DO="[object Uint8ClampedArray]",$O="[object Uint16Array]",PO="[object Uint32Array]",TO="[object BigUint64Array]",RO="[object Int8Array]",NO="[object Int16Array]",CO="[object Int32Array]",UO="[object BigInt64Array]",FO="[object Float32Array]",LO="[object Float64Array]";function kO(){}function _y(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 qO(t,e,n){return Cs(t,e,void 0,void 0,void 0,void 0,n)}function Cs(t,e,n,r,i,s,o){const a=o(t,e,n,r,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 Us(t,e,s,o)}return Us(t,e,s,o)}function Us(t,e,n,r){if(Object.is(t,e))return!0;let i=Ey(t),s=Ey(e);if(i===xy&&(i=Nl),s===xy&&(s=Nl),i!==s)return!1;switch(i){case yO:return t.toString()===e.toString();case bO:{const c=t.valueOf(),u=e.valueOf();return pO(c,u)}case wO:case vO:case mO:return Object.is(t.valueOf(),e.valueOf());case gO:return t.source===e.source&&t.flags===e.flags;case SO:return t===e}n=n??new Map;const o=n.get(t),a=n.get(e);if(o!=null&&a!=null)return o===e;n.set(t,e),n.set(e,t);try{switch(i){case EO:{if(t.size!==e.size)return!1;for(const[c,u]of t.entries())if(!e.has(c)||!Cs(u,e.get(c),c,t,e,n,r))return!1;return!0}case xO:{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 f=c[l],d=u.findIndex(h=>Cs(f,h,void 0,t,e,n,r));if(d===-1)return!1;u.splice(d,1)}return!0}case _O:case OO:case DO:case $O:case PO:case TO:case RO:case NO:case CO:case UO:case FO:case LO:{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(!Cs(t[c],e[c],c,t,e,n,r))return!1;return!0}case IO:return t.byteLength!==e.byteLength?!1:Us(new Uint8Array(t),new Uint8Array(e),n,r);case BO:return t.byteLength!==e.byteLength||t.byteOffset!==e.byteOffset?!1:Us(new Uint8Array(t),new Uint8Array(e),n,r);case AO:return t.name===e.name&&t.message===e.message;case Nl:{if(!(Us(t.constructor,e.constructor,n,r)||_y(t)&&_y(e)))return!1;const c=[...Object.keys(t),...vy(t)],u=[...Object.keys(e),...vy(e)];if(c.length!==u.length)return!1;for(let l=0;l<c.length;l++){const f=c[l],d=t[f];if(!Object.hasOwn(e,f))return!1;const h=e[f];if(!Cs(d,h,f,t,e,n,r))return!1}return!0}default:return!1}}finally{n.delete(t),n.delete(e)}}function MO(t,e){return qO(t,e,kO)}var jO=Object.defineProperty,Sy=Object.getOwnPropertySymbols,zO=Object.prototype.hasOwnProperty,HO=Object.prototype.propertyIsEnumerable,Cl=(t,e,n)=>e in t?jO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Iy=(t,e)=>{for(var n in e||(e={}))zO.call(e,n)&&Cl(t,n,e[n]);if(Sy)for(var n of Sy(e))HO.call(e,n)&&Cl(t,n,e[n]);return t},xt=(t,e,n)=>Cl(t,typeof e!="symbol"?e+"":e,n);class Qr extends lm{constructor(e,n,r,i=un,s=void 0){super(e,n,r,i),this.core=e,this.logger=n,this.name=r,xt(this,"map",new Map),xt(this,"version",G7),xt(this,"cached",[]),xt(this,"initialized",!1),xt(this,"getKey"),xt(this,"storagePrefix",un),xt(this,"recentlyDeleted",[]),xt(this,"recentlyDeletedLimit",200),xt(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(o=>{this.getKey&&o!==null&&!Pe(o)?this.map.set(this.getKey(o),o):c9(o)?this.map.set(o.id,o):u9(o)&&this.map.set(o.topic,o)}),this.cached=[],this.initialized=!0)}),xt(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())}),xt(this,"get",o=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:o}),this.getData(o))),xt(this,"getAll",o=>(this.isInitialized(),o?this.values.filter(a=>Object.keys(o).every(c=>MO(a[c],o[c]))):this.values)),xt(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=Iy(Iy({},this.getData(o)),a);this.map.set(o,c),await this.persist()}),xt(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=_t(n,this.name),this.storagePrefix=i,this.getKey=s}get context(){return ft(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 n=this.map.get(e);if(!n){if(this.recentlyDeleted.includes(e)){const{message:i}=G("MISSING_OR_INVALID",`Record was recently deleted - ${this.name}: ${e}`);throw this.logger.error(i),new Error(i)}const{message:r}=G("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(r),new Error(r)}return n}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:n}=G("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(n),new Error(n)}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}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}}var VO=Object.defineProperty,KO=(t,e,n)=>e in t?VO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,se=(t,e,n)=>KO(t,typeof e!="symbol"?e+"":e,n);class GO{constructor(e,n){this.core=e,this.logger=n,se(this,"name",X7),se(this,"version",J7),se(this,"events",new Ve.exports),se(this,"pairings"),se(this,"initialized",!1),se(this,"storagePrefix",un),se(this,"ignoredPayloadTypes",[Rn]),se(this,"registeredMethods",[]),se(this,"init",async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))}),se(this,"register",({methods:r})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...r])]}),se(this,"create",async r=>{this.isInitialized();const i=dl(),s=await this.core.crypto.setSymKey(i),o=De(K.FIVE_MINUTES),a={protocol:G1},c={topic:s,expiry:o,relay:a,active:!1,methods:r?.methods},u=m1({protocol:this.core.protocol,version:this.core.version,topic:s,symKey:i,relay:a,expiryTimestamp:o,methods:r?.methods});return this.events.emit(Yr.create,c),this.core.expirer.set(s,o),await this.pairings.set(s,c),await this.core.relayer.subscribe(s,{transportType:r?.transportType,internal:r?.internal}),{topic:s,uri:u}}),se(this,"pair",async r=>{this.isInitialized();const i=this.core.eventClient.createEvent({properties:{topic:r?.uri,trace:[ln.pairing_started]}});this.isValidPair(r,i);const{topic:s,symKey:o,relay:a,expiryTimestamp:c,methods:u}=w1(r.uri);i.props.properties.topic=s,i.addTrace(ln.pairing_uri_validation_success),i.addTrace(ln.pairing_uri_not_expired);let l;if(this.pairings.keys.includes(s)){if(l=this.pairings.get(s),i.addTrace(ln.existing_pairing),l.active)throw i.setError(Fn.active_pairing_already_exists),new Error(`Pairing already exists: ${s}. Please try again with a new connection URI.`);i.addTrace(ln.pairing_not_expired)}const f=c||De(K.FIVE_MINUTES),d={topic:s,relay:a,expiry:f,active:!1,methods:u};this.core.expirer.set(s,f),await this.pairings.set(s,d),i.addTrace(ln.store_new_pairing),r.activatePairing&&await this.activate({topic:s}),this.events.emit(Yr.create,d),i.addTrace(ln.emit_inactive_pairing),this.core.crypto.keychain.has(s)||await this.core.crypto.setSymKey(o,s),i.addTrace(ln.subscribing_pairing_topic);try{await this.core.relayer.confirmOnlineStateOrThrow()}catch{i.setError(Fn.no_internet_connection)}try{await this.core.relayer.subscribe(s,{relay:a})}catch(h){throw i.setError(Fn.subscribe_pairing_topic_failure),h}return i.addTrace(ln.subscribe_pairing_topic_success),d}),se(this,"activate",async({topic:r})=>{this.isInitialized();const i=De(K.FIVE_MINUTES);this.core.expirer.set(r,i),await this.pairings.update(r,{active:!0,expiry:i})}),se(this,"ping",async r=>{this.isInitialized(),await this.isValidPing(r),this.logger.warn("ping() is deprecated and will be removed in the next major release.");const{topic:i}=r;if(this.pairings.keys.includes(i)){const s=await this.sendRequest(i,"wc_pairingPing",{}),{done:o,resolve:a,reject:c}=jr();this.events.once(le("pairing_ping",s),({error:u})=>{u?c(u):a()}),await o()}}),se(this,"updateExpiry",async({topic:r,expiry:i})=>{this.isInitialized(),await this.pairings.update(r,{expiry:i})}),se(this,"updateMetadata",async({topic:r,metadata:i})=>{this.isInitialized(),await this.pairings.update(r,{peerMetadata:i})}),se(this,"getPairings",()=>(this.isInitialized(),this.pairings.values)),se(this,"disconnect",async r=>{this.isInitialized(),await this.isValidDisconnect(r);const{topic:i}=r;this.pairings.keys.includes(i)&&(await this.sendRequest(i,"wc_pairingDelete",Ee("USER_DISCONNECTED")),await this.deletePairing(i))}),se(this,"formatUriFromPairing",r=>{this.isInitialized();const{topic:i,relay:s,expiry:o,methods:a}=r,c=this.core.crypto.keychain.get(i);return m1({protocol:this.core.protocol,version:this.core.version,topic:i,symKey:c,relay:s,expiryTimestamp:o,methods:a})}),se(this,"sendRequest",async(r,i,s)=>{const o=Un(i,s),a=await this.core.crypto.encode(r,o),c=$s[i].req;return this.core.history.set(r,o),this.core.relayer.publish(r,a,c),o.id}),se(this,"sendResult",async(r,i,s)=>{const o=va(r,s),a=await this.core.crypto.encode(i,o),c=(await this.core.history.get(i,r)).request.method,u=$s[c].res;await this.core.relayer.publish(i,a,u),await this.core.history.resolve(o)}),se(this,"sendError",async(r,i,s)=>{const o=_l(r,s),a=await this.core.crypto.encode(i,o),c=(await this.core.history.get(i,r)).request.method,u=$s[c]?$s[c].res:$s.unregistered_method.res;await this.core.relayer.publish(i,a,u),await this.core.history.resolve(o)}),se(this,"deletePairing",async(r,i)=>{await this.core.relayer.unsubscribe(r),await Promise.all([this.pairings.delete(r,Ee("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(r),i?Promise.resolve():this.core.expirer.del(r)])}),se(this,"cleanup",async()=>{const r=this.pairings.getAll().filter(i=>or(i.expiry));await Promise.all(r.map(i=>this.deletePairing(i.topic)))}),se(this,"onRelayEventRequest",async r=>{const{topic:i,payload:s}=r;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)}}),se(this,"onRelayEventResponse",async r=>{const{topic:i,payload:s}=r,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)}}),se(this,"onPairingPingRequest",async(r,i)=>{const{id:s}=i;try{this.isValidPing({topic:r}),await this.sendResult(s,r,!0),this.events.emit(Yr.ping,{id:s,topic:r})}catch(o){await this.sendError(s,r,o),this.logger.error(o)}}),se(this,"onPairingPingResponse",(r,i)=>{const{id:s}=i;setTimeout(()=>{cn(i)?this.events.emit(le("pairing_ping",s),{}):Lt(i)&&this.events.emit(le("pairing_ping",s),{error:i.error})},500)}),se(this,"onPairingDeleteRequest",async(r,i)=>{const{id:s}=i;try{this.isValidDisconnect({topic:r}),await this.deletePairing(r),this.events.emit(Yr.delete,{id:s,topic:r})}catch(o){await this.sendError(s,r,o),this.logger.error(o)}}),se(this,"onUnknownRpcMethodRequest",async(r,i)=>{const{id:s,method:o}=i;try{if(this.registeredMethods.includes(o))return;const a=Ee("WC_METHOD_UNSUPPORTED",o);await this.sendError(s,r,a),this.logger.error(a)}catch(a){await this.sendError(s,r,a),this.logger.error(a)}}),se(this,"onUnknownRpcMethodResponse",r=>{this.registeredMethods.includes(r)||this.logger.error(Ee("WC_METHOD_UNSUPPORTED",r))}),se(this,"isValidPair",(r,i)=>{var s;if(!Et(r)){const{message:a}=G("MISSING_OR_INVALID",`pair() params: ${r}`);throw i.setError(Fn.malformed_pairing_uri),new Error(a)}if(!a9(r.uri)){const{message:a}=G("MISSING_OR_INVALID",`pair() uri: ${r.uri}`);throw i.setError(Fn.malformed_pairing_uri),new Error(a)}const o=w1(r?.uri);if(!((s=o?.relay)!=null&&s.protocol)){const{message:a}=G("MISSING_OR_INVALID","pair() uri#relay-protocol");throw i.setError(Fn.malformed_pairing_uri),new Error(a)}if(!(o!=null&&o.symKey)){const{message:a}=G("MISSING_OR_INVALID","pair() uri#symKey");throw i.setError(Fn.malformed_pairing_uri),new Error(a)}if(o!=null&&o.expiryTimestamp&&K.toMiliseconds(o?.expiryTimestamp)<Date.now()){i.setError(Fn.pairing_expired);const{message:a}=G("EXPIRED","pair() URI has expired. Please try again with a new connection URI.");throw new Error(a)}}),se(this,"isValidPing",async r=>{if(!Et(r)){const{message:s}=G("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(s)}const{topic:i}=r;await this.isValidPairingTopic(i)}),se(this,"isValidDisconnect",async r=>{if(!Et(r)){const{message:s}=G("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(s)}const{topic:i}=r;await this.isValidPairingTopic(i)}),se(this,"isValidPairingTopic",async r=>{if(!Ie(r,!1)){const{message:i}=G("MISSING_OR_INVALID",`pairing topic should be a string: ${r}`);throw new Error(i)}if(!this.pairings.keys.includes(r)){const{message:i}=G("NO_MATCHING_KEY",`pairing topic doesn't exist: ${r}`);throw new Error(i)}if(or(this.pairings.get(r).expiry)){await this.deletePairing(r);const{message:i}=G("EXPIRED",`pairing topic: ${r}`);throw new Error(i)}}),this.core=e,this.logger=_t(n,this.name),this.pairings=new Qr(this.core,this.logger,this.name,this.storagePrefix)}get context(){return ft(this.logger)}isInitialized(){if(!this.initialized){const{message:e}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(Se.message,async e=>{const{topic:n,message:r,transportType:i}=e;if(this.pairings.keys.includes(n)&&i!==me.link_mode&&!this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(r)))try{const s=await this.core.crypto.decode(n,r);Sl(s)?(this.core.history.set(n,s),await this.onRelayEventRequest({topic:n,payload:s})):Ea(s)&&(await this.core.history.resolve(s),await this.onRelayEventResponse({topic:n,payload:s}),this.core.history.delete(n,s.id)),await this.core.relayer.messages.ack(n,r)}catch(s){this.logger.error(s)}})}registerExpirerEvents(){this.core.expirer.on(qt.expired,async e=>{const{topic:n}=q0(e.target);n&&this.pairings.keys.includes(n)&&(await this.deletePairing(n,!0),this.events.emit(Yr.expire,{topic:n}))})}}var WO=Object.defineProperty,ZO=(t,e,n)=>e in t?WO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,je=(t,e,n)=>ZO(t,typeof e!="symbol"?e+"":e,n);class YO extends om{constructor(e,n){super(e,n),this.core=e,this.logger=n,je(this,"records",new Map),je(this,"events",new Ve.exports.EventEmitter),je(this,"name",Q7),je(this,"version",eA),je(this,"cached",[]),je(this,"initialized",!1),je(this,"storagePrefix",un),je(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(r=>this.records.set(r.id,r)),this.cached=[],this.registerEventListeners(),this.initialized=!0)}),je(this,"set",(r,i,s)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:r,request:i,chainId:s}),this.records.has(i.id))return;const o={id:i.id,topic:r,request:{method:i.method,params:i.params||null},chainId:s,expiry:De(K.THIRTY_DAYS)};this.records.set(o.id,o),this.persist(),this.events.emit(Yt.created,o)}),je(this,"resolve",async r=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:r}),!this.records.has(r.id))return;const i=await this.getRecord(r.id);typeof i.response>"u"&&(i.response=Lt(r)?{error:r.error}:{result:r.result},this.records.set(i.id,i),this.persist(),this.events.emit(Yt.updated,i))}),je(this,"get",async(r,i)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:r,id:i}),await this.getRecord(i))),je(this,"delete",(r,i)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:i}),this.values.forEach(s=>{if(s.topic===r){if(typeof i<"u"&&s.id!==i)return;this.records.delete(s.id),this.events.emit(Yt.deleted,s)}}),this.persist()}),je(this,"exists",async(r,i)=>(this.isInitialized(),this.records.has(i)?(await this.getRecord(i)).topic===r:!1)),je(this,"on",(r,i)=>{this.events.on(r,i)}),je(this,"once",(r,i)=>{this.events.once(r,i)}),je(this,"off",(r,i)=>{this.events.off(r,i)}),je(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),this.logger=_t(n,this.name)}get context(){return ft(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(n=>{if(typeof n.response<"u")return;const r={topic:n.topic,request:Un(n.request.method,n.request.params,n.id),chainId:n.chainId};return e.push(r)}),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 n=this.records.get(e);if(!n){const{message:r}=G("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(r)}return n}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(Yt.sync)}async restore(){try{const e=await this.getJsonRpcRecords();if(typeof e>"u"||!e.length)return;if(this.records.size){const{message:n}=G("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(n),new Error(n)}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(Yt.created,e=>{const n=Yt.created;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.events.on(Yt.updated,e=>{const n=Yt.updated;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.events.on(Yt.deleted,e=>{const n=Yt.deleted;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.core.heartbeat.on(Ir.pulse,()=>{this.cleanup()})}cleanup(){try{this.isInitialized();let e=!1;this.records.forEach(n=>{K.toMiliseconds(n.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${n.id}`),this.records.delete(n.id),this.events.emit(Yt.deleted,n,!1),e=!0)}),e&&this.persist()}catch(e){this.logger.warn(e)}}isInitialized(){if(!this.initialized){const{message:e}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}}var XO=Object.defineProperty,JO=(t,e,n)=>e in t?XO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,tt=(t,e,n)=>JO(t,typeof e!="symbol"?e+"":e,n);class QO extends hm{constructor(e,n){super(e,n),this.core=e,this.logger=n,tt(this,"expirations",new Map),tt(this,"events",new Ve.exports.EventEmitter),tt(this,"name",tA),tt(this,"version",nA),tt(this,"cached",[]),tt(this,"initialized",!1),tt(this,"storagePrefix",un),tt(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(r=>this.expirations.set(r.target,r)),this.cached=[],this.registerEventListeners(),this.initialized=!0)}),tt(this,"has",r=>{try{const i=this.formatTarget(r);return typeof this.getExpiration(i)<"u"}catch{return!1}}),tt(this,"set",(r,i)=>{this.isInitialized();const s=this.formatTarget(r),o={target:s,expiry:i};this.expirations.set(s,o),this.checkExpiry(s,o),this.events.emit(qt.created,{target:s,expiration:o})}),tt(this,"get",r=>{this.isInitialized();const i=this.formatTarget(r);return this.getExpiration(i)}),tt(this,"del",r=>{if(this.isInitialized(),this.has(r)){const i=this.formatTarget(r),s=this.getExpiration(i);this.expirations.delete(i),this.events.emit(qt.deleted,{target:i,expiration:s})}}),tt(this,"on",(r,i)=>{this.events.on(r,i)}),tt(this,"once",(r,i)=>{this.events.once(r,i)}),tt(this,"off",(r,i)=>{this.events.off(r,i)}),tt(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),this.logger=_t(n,this.name)}get context(){return ft(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 L_(e);if(typeof e=="number")return k_(e);const{message:n}=G("UNKNOWN_TYPE",`Target type: ${typeof e}`);throw new Error(n)}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(qt.sync)}async restore(){try{const e=await this.getExpirations();if(typeof e>"u"||!e.length)return;if(this.expirations.size){const{message:n}=G("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(n),new Error(n)}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 n=this.expirations.get(e);if(!n){const{message:r}=G("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.warn(r),new Error(r)}return n}checkExpiry(e,n){const{expiry:r}=n;K.toMiliseconds(r)-Date.now()<=0&&this.expire(e,n)}expire(e,n){this.expirations.delete(e),this.events.emit(qt.expired,{target:e,expiration:n})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,n)=>this.checkExpiry(n,e))}registerEventListeners(){this.core.heartbeat.on(Ir.pulse,()=>this.checkExpirations()),this.events.on(qt.created,e=>{const n=qt.created;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:e}),this.persist()}),this.events.on(qt.expired,e=>{const n=qt.expired;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:e}),this.persist()}),this.events.on(qt.deleted,e=>{const n=qt.deleted;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}}var eD=Object.defineProperty,tD=(t,e,n)=>e in t?eD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ae=(t,e,n)=>tD(t,typeof e!="symbol"?e+"":e,n);class nD extends dm{constructor(e,n,r){super(e,n,r),this.core=e,this.logger=n,this.store=r,Ae(this,"name",rA),Ae(this,"abortController"),Ae(this,"isDevEnv"),Ae(this,"verifyUrlV3",sA),Ae(this,"storagePrefix",un),Ae(this,"version",V1),Ae(this,"publicKey"),Ae(this,"fetchPromise"),Ae(this,"init",async()=>{var i;this.isDevEnv||(this.publicKey=await this.store.getItem(this.storeKey),this.publicKey&&K.toMiliseconds((i=this.publicKey)==null?void 0:i.expiresAt)<Date.now()&&(this.logger.debug("verify v2 public key expired"),await this.removePublicKey()))}),Ae(this,"register",async i=>{if(!Ei()||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=Pr(),l=this.startAbortTimer(K.ONE_SECOND*5),f=await new Promise((d,h)=>{const p=()=>{window.removeEventListener("message",v),u.body.removeChild(g),h("attestation aborted")};this.abortController.signal.addEventListener("abort",p);const g=u.createElement("iframe");g.src=c,g.style.display="none",g.addEventListener("error",p,{signal:this.abortController.signal});const v=B=>{if(B.data&&typeof B.data=="string")try{const D=JSON.parse(B.data);if(D.type==="verify_attestation"){if(hc(D.attestation).payload.id!==o)return;clearInterval(l),u.body.removeChild(g),this.abortController.signal.removeEventListener("abort",p),window.removeEventListener("message",v),d(D.attestation===null?"":D.attestation)}}catch(D){this.logger.warn(D)}};u.body.appendChild(g),window.addEventListener("message",v,{signal:this.abortController.signal})});return this.logger.debug(f,"jwt attestation"),f}catch(u){this.logger.warn(u)}return""}),Ae(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(hc(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)}),Ae(this,"fetchAttestation",async(i,s)=>{this.logger.debug(`resolving attestation: ${i} from url: ${s}`);const o=this.startAbortTimer(K.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}),Ae(this,"getVerifyUrl",i=>{let s=i||Ps;return oA.includes(s)||(this.logger.info(`verify url: ${s}, not included in trusted list, assigning default: ${Ps}`),s=Ps),s}),Ae(this,"fetchPublicKey",async()=>{try{this.logger.debug(`fetching public key from: ${this.verifyUrlV3}`);const i=this.startAbortTimer(K.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)}}),Ae(this,"persistPublicKey",async i=>{this.logger.debug(i,"persisting public key to local storage"),await this.store.setItem(this.storeKey,i),this.publicKey=i}),Ae(this,"removePublicKey",async()=>{this.logger.debug("removing verify v2 public key from storage"),await this.store.removeItem(this.storeKey),this.publicKey=void 0}),Ae(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")}}),Ae(this,"getPublicKey",async()=>this.publicKey?this.publicKey:await this.fetchAndPersistPublicKey()),Ae(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}),Ae(this,"validateAttestation",(i,s)=>{const o=RI(i,s.publicKey),a={hasExpired:K.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=_t(n,this.name),this.abortController=new AbortController,this.isDevEnv=Cu(),this.init()}get storeKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//verify:public:key"}get context(){return ft(this.logger)}startAbortTimer(e){return this.abortController=new AbortController,setTimeout(()=>this.abortController.abort(),K.toMiliseconds(e))}}var rD=Object.defineProperty,iD=(t,e,n)=>e in t?rD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ay=(t,e,n)=>iD(t,typeof e!="symbol"?e+"":e,n);class sD extends pm{constructor(e,n){super(e,n),this.projectId=e,this.logger=n,Ay(this,"context",aA),Ay(this,"registerDeviceToken",async r=>{const{clientId:i,token:s,notificationType:o,enableEncrypted:a=!1}=r,c=`${cA}/${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=_t(n,this.context)}}var oD=Object.defineProperty,By=Object.getOwnPropertySymbols,aD=Object.prototype.hasOwnProperty,cD=Object.prototype.propertyIsEnumerable,Ul=(t,e,n)=>e in t?oD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fs=(t,e)=>{for(var n in e||(e={}))aD.call(e,n)&&Ul(t,n,e[n]);if(By)for(var n of By(e))cD.call(e,n)&&Ul(t,n,e[n]);return t},Ue=(t,e,n)=>Ul(t,typeof e!="symbol"?e+"":e,n);class uD extends gm{constructor(e,n,r=!0){super(e,n,r),this.core=e,this.logger=n,Ue(this,"context",lA),Ue(this,"storagePrefix",un),Ue(this,"storageVersion",uA),Ue(this,"events",new Map),Ue(this,"shouldPersist",!1),Ue(this,"init",async()=>{if(!Cu())try{const i={eventId:j0(),timestamp:Date.now(),domain:this.getAppDomain(),props:{event:"INIT",type:"",properties:{client_id:await this.core.crypto.getClientId(),user_agent:L0(this.core.relayer.protocol,this.core.relayer.version,Il)}}};await this.sendEvent([i])}catch(i){this.logger.warn(i)}}),Ue(this,"createEvent",i=>{const{event:s="ERROR",type:o="",properties:{topic:a,trace:c}}=i,u=j0(),l=this.core.projectId||"",f=Date.now(),d=Fs({eventId:u,timestamp:f,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}),Ue(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 Fs(Fs({},a),this.setMethods(a.eventId))}),Ue(this,"deleteEvent",i=>{const{eventId:s}=i;this.events.delete(s),this.shouldPersist=!0}),Ue(this,"setEventListeners",()=>{this.core.heartbeat.on(Ir.pulse,async()=>{this.shouldPersist&&await this.persist(),this.events.forEach(i=>{K.fromMiliseconds(Date.now())-K.fromMiliseconds(i.timestamp)>fA&&(this.events.delete(i.eventId),this.shouldPersist=!0)})})}),Ue(this,"setMethods",i=>({addTrace:s=>this.addTrace(i,s),setError:s=>this.setError(i,s)})),Ue(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)}),Ue(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)}),Ue(this,"persist",async()=>{await this.core.storage.setItem(this.storageKey,Array.from(this.events.values())),this.shouldPersist=!1}),Ue(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,Fs(Fs({},s),this.setMethods(s.eventId)))})}catch(i){this.logger.warn(i)}}),Ue(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)}}),Ue(this,"sendEvent",async i=>{const s=this.getAppDomain()?"":"&sp=desktop";return await fetch(`${hA}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${Il}${s}`,{method:"POST",body:JSON.stringify(i)})}),Ue(this,"getAppDomain",()=>F0().url),this.logger=_t(n,this.context),this.telemetryEnabled=r,r?this.restore().then(async()=>{await this.submit(),this.setEventListeners()}):this.persist()}get storageKey(){return this.storagePrefix+this.storageVersion+this.core.customStoragePrefix+"//"+this.context}}var lD=Object.defineProperty,Oy=Object.getOwnPropertySymbols,fD=Object.prototype.hasOwnProperty,hD=Object.prototype.propertyIsEnumerable,Fl=(t,e,n)=>e in t?lD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Dy=(t,e)=>{for(var n in e||(e={}))fD.call(e,n)&&Fl(t,n,e[n]);if(Oy)for(var n of Oy(e))hD.call(e,n)&&Fl(t,n,e[n]);return t},we=(t,e,n)=>Fl(t,typeof e!="symbol"?e+"":e,n);class Ll extends nm{constructor(e){var n;super(e),we(this,"protocol",H1),we(this,"version",V1),we(this,"name",xa),we(this,"relayUrl"),we(this,"projectId"),we(this,"customStoragePrefix"),we(this,"events",new Ve.exports.EventEmitter),we(this,"logger"),we(this,"heartbeat"),we(this,"relayer"),we(this,"crypto"),we(this,"storage"),we(this,"history"),we(this,"expirer"),we(this,"pairing"),we(this,"verify"),we(this,"echoClient"),we(this,"linkModeSupportedApps"),we(this,"eventClient"),we(this,"initialized",!1),we(this,"logChunkController"),we(this,"on",(a,c)=>this.events.on(a,c)),we(this,"once",(a,c)=>this.events.once(a,c)),we(this,"off",(a,c)=>this.events.off(a,c)),we(this,"removeListener",(a,c)=>this.events.removeListener(a,c)),we(this,"dispatchEnvelope",({topic:a,message:c,sessionExists:u})=>{if(!a||!c)return;const l={topic:a,message:c,publishedAt:Date.now(),transportType:me.link_mode};this.relayer.onLinkMessageEvent(l,{sessionExists:u})});const r=this.getGlobalCore(e?.customStoragePrefix);if(r)try{return this.customStoragePrefix=r.customStoragePrefix,this.logger=r.logger,this.heartbeat=r.heartbeat,this.crypto=r.crypto,this.history=r.history,this.expirer=r.expirer,this.storage=r.storage,this.relayer=r.relayer,this.pairing=r.pairing,this.verify=r.verify,this.echoClient=r.echoClient,this.linkModeSupportedApps=r.linkModeSupportedApps,this.eventClient=r.eventClient,this.initialized=r.initialized,this.logChunkController=r.logChunkController,r}catch(a){console.warn("Failed to copy global core",a)}this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||W1,this.customStoragePrefix=e!=null&&e.customStoragePrefix?`:${e.customStoragePrefix}`:"";const i=Zw({level:typeof e?.logger=="string"&&e.logger?e.logger:R7.logger,name:xa}),{logger:s,chunkLoggerController:o}=Nf({opts:i,maxSizeInBytes:e?.maxLogBlobSizeInBytes,loggerOverride:e?.logger});this.logChunkController=o,(n=this.logChunkController)!=null&&n.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=_t(s,this.name),this.heartbeat=new Ua,this.crypto=new qB(this,this.logger,e?.keychain),this.history=new YO(this,this.logger),this.expirer=new QO(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new fw(Dy(Dy({},N7),e?.storageOptions)),this.relayer=new dO({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new GO(this,this.logger),this.verify=new nD(this,this.logger,this.storage),this.echoClient=new sD(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new uD(this,this.logger,e?.telemetryEnabled),this.setGlobalCore(this)}static async init(e){const n=new Ll(e);await n.initialize();const r=await n.crypto.getClientId();return await n.storage.setItem(W7,r),n}get context(){return ft(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(Z1,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(Z1)||[],this.initialized=!0,this.logger.info("Core Initialization Success")}catch(e){throw this.logger.warn(e,`Core Initialization Failure at epoch ${Date.now()}`),this.logger.error(e.message),e}}getGlobalCore(e=""){try{if(this.isGlobalCoreDisabled())return;const n=`_walletConnectCore_${e}`,r=`${n}_count`;return globalThis[r]=(globalThis[r]||0)+1,globalThis[r]>1&&console.warn(`WalletConnect Core is already initialized. This is probably a mistake and can lead to unexpected behavior. Init() was called ${globalThis[r]} times.`),globalThis[n]}catch(n){console.warn("Failed to get global WalletConnect core",n);return}}setGlobalCore(e){var n;try{if(this.isGlobalCoreDisabled())return;const r=`_walletConnectCore_${((n=e.opts)==null?void 0:n.customStoragePrefix)||""}`;globalThis[r]=e}catch(r){console.warn("Failed to set global WalletConnect core",r)}}isGlobalCoreDisabled(){try{return typeof process<"u"&&process.env.DISABLE_GLOBAL_CORE==="true"}catch{return!0}}}const kl=Ll,$y="wc",Py=2,Ty="client",ql=`${$y}@${Py}:${Ty}:`,Ml={name:Ty,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.org"},Ry="WALLETCONNECT_DEEPLINK_CHOICE",dD="proposal",Ny="Proposal expired",pD="session",Ni=K.SEVEN_DAYS,gD="engine",ze={wc_sessionPropose:{req:{ttl:K.FIVE_MINUTES,prompt:!0,tag:1100},res:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1101},reject:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1120},autoReject:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1121}},wc_sessionSettle:{req:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1102},res:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1103}},wc_sessionUpdate:{req:{ttl:K.ONE_DAY,prompt:!1,tag:1104},res:{ttl:K.ONE_DAY,prompt:!1,tag:1105}},wc_sessionExtend:{req:{ttl:K.ONE_DAY,prompt:!1,tag:1106},res:{ttl:K.ONE_DAY,prompt:!1,tag:1107}},wc_sessionRequest:{req:{ttl:K.FIVE_MINUTES,prompt:!0,tag:1108},res:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1109}},wc_sessionEvent:{req:{ttl:K.FIVE_MINUTES,prompt:!0,tag:1110},res:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1111}},wc_sessionDelete:{req:{ttl:K.ONE_DAY,prompt:!1,tag:1112},res:{ttl:K.ONE_DAY,prompt:!1,tag:1113}},wc_sessionPing:{req:{ttl:K.ONE_DAY,prompt:!1,tag:1114},res:{ttl:K.ONE_DAY,prompt:!1,tag:1115}},wc_sessionAuthenticate:{req:{ttl:K.ONE_HOUR,prompt:!0,tag:1116},res:{ttl:K.ONE_HOUR,prompt:!1,tag:1117},reject:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1118},autoReject:{ttl:K.FIVE_MINUTES,prompt:!1,tag:1119}}},jl={min:K.FIVE_MINUTES,max:K.SEVEN_DAYS},hn={idle:"IDLE",active:"ACTIVE"},yD={eth_sendTransaction:{key:""},eth_sendRawTransaction:{key:""},wallet_sendCalls:{key:""},solana_signTransaction:{key:"signature"},solana_signAllTransactions:{key:"transactions"},solana_signAndSendTransaction:{key:"signature"},sui_signAndExecuteTransaction:{key:"digest"},sui_signTransaction:{key:""},hedera_signAndExecuteTransaction:{key:"transactionId"},hedera_executeTransaction:{key:"transactionId"},near_signTransaction:{key:""},near_signTransactions:{key:""},tron_signTransaction:{key:"txID"},xrpl_signTransaction:{key:""},xrpl_signTransactionFor:{key:""},algo_signTxn:{key:""},sendTransfer:{key:"txid"},stacks_stxTransfer:{key:"txId"},polkadot_signTransaction:{key:""},cosmos_signDirect:{key:""}},bD="request",wD=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],mD="wc",vD="auth",ED="authKeys",xD="pairingTopics",_D="requests",Ia=`${mD}@${1.5}:${vD}:`,Aa=`${Ia}:PUB_KEY`;var SD=Object.defineProperty,ID=Object.defineProperties,AD=Object.getOwnPropertyDescriptors,Cy=Object.getOwnPropertySymbols,BD=Object.prototype.hasOwnProperty,OD=Object.prototype.propertyIsEnumerable,zl=(t,e,n)=>e in t?SD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,he=(t,e)=>{for(var n in e||(e={}))BD.call(e,n)&&zl(t,n,e[n]);if(Cy)for(var n of Cy(e))OD.call(e,n)&&zl(t,n,e[n]);return t},nt=(t,e)=>ID(t,AD(e)),H=(t,e,n)=>zl(t,typeof e!="symbol"?e+"":e,n);class DD extends mm{constructor(e){super(e),H(this,"name",gD),H(this,"events",new Ve.exports),H(this,"initialized",!1),H(this,"requestQueue",{state:hn.idle,queue:[]}),H(this,"sessionRequestQueue",{state:hn.idle,queue:[]}),H(this,"emittedSessionRequests",new W_({limit:500})),H(this,"requestQueueDelay",K.ONE_SECOND),H(this,"expectedPairingMethodMap",new Map),H(this,"recentlyDeletedMap",new Map),H(this,"recentlyDeletedLimit",200),H(this,"relayMessageCache",[]),H(this,"pendingSessions",new Map),H(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(ze)}),this.initialized=!0,setTimeout(async()=>{await this.processPendingMessageEvents(),this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()},K.toMiliseconds(this.requestQueueDelay)))}),H(this,"connect",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();const r=nt(he({},n),{requiredNamespaces:n.requiredNamespaces||{},optionalNamespaces:n.optionalNamespaces||{}});await this.isValidConnect(r),r.optionalNamespaces=n9(r.requiredNamespaces,r.optionalNamespaces),r.requiredNamespaces={};const{pairingTopic:i,requiredNamespaces:s,optionalNamespaces:o,sessionProperties:a,scopedProperties:c,relays:u}=r;let l=i,f,d=!1;try{if(l){const T=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=T.active}}catch(T){throw this.client.logger.error(`connect() -> pairing.get(${l}) failed`),T}if(!l||!d){const{topic:T,uri:U}=await this.client.core.pairing.create({internal:{skipSubscribe:!0}});l=T,f=U}if(!l){const{message:T}=G("NO_MATCHING_KEY",`connect() pairing topic: ${l}`);throw new Error(T)}const h=await this.client.core.crypto.generateKeyPair(),p=ze.wc_sessionPropose.req.ttl||K.FIVE_MINUTES,g=De(p),v=nt(he(he({requiredNamespaces:s,optionalNamespaces:o,relays:u??[{protocol:G1}],proposer:{publicKey:h,metadata:this.client.metadata},expiryTimestamp:g,pairingTopic:l},a&&{sessionProperties:a}),c&&{scopedProperties:c}),{id:an()}),B=le("session_connect",v.id),{reject:D,resolve:_,done:x}=jr(p,Ny),$=({id:T})=>{T===v.id&&(this.client.events.off("proposal_expire",$),this.pendingSessions.delete(v.id),this.events.emit(B,{error:{message:Ny,code:0}}))};return this.client.events.on("proposal_expire",$),this.events.once(B,({error:T,session:U})=>{this.client.events.off("proposal_expire",$),T?D(T):U&&_(U)}),await this.sendProposeSession({proposal:v,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:{correlationId:v.id}}}),await this.setProposal(v.id,v),{uri:f,approval:x}}),H(this,"pair",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{return await this.client.core.pairing.pair(n)}catch(r){throw this.client.logger.error("pair() failed"),r}}),H(this,"approve",async n=>{var r,i,s;const o=this.client.core.eventClient.createEvent({properties:{topic:(r=n?.id)==null?void 0:r.toString(),trace:[Xt.session_approve_started]}});try{this.isInitialized(),await this.confirmOnlineStateOrThrow()}catch(P){throw o.setError(Xr.no_internet_connection),P}try{await this.isValidProposalId(n?.id)}catch(P){throw this.client.logger.error(`approve() -> proposal.get(${n?.id}) failed`),o.setError(Xr.proposal_not_found),P}try{await this.isValidApprove(n)}catch(P){throw this.client.logger.error("approve() -> isValidApprove() failed"),o.setError(Xr.session_approve_namespace_validation_failure),P}const{id:a,relayProtocol:c,namespaces:u,sessionProperties:l,scopedProperties:f,sessionConfig:d}=n,h=this.client.proposal.get(a);this.client.core.eventClient.deleteEvent({eventId:o.eventId});const{pairingTopic:p,proposer:g,requiredNamespaces:v,optionalNamespaces:B}=h;let D=(i=this.client.core.eventClient)==null?void 0:i.getEvent({topic:p});D||(D=(s=this.client.core.eventClient)==null?void 0:s.createEvent({type:Xt.session_approve_started,properties:{topic:p,trace:[Xt.session_approve_started,Xt.session_namespaces_validation_success]}}));const _=await this.client.core.crypto.generateKeyPair(),x=g.publicKey,$=await this.client.core.crypto.generateSharedKey(_,x),T=he(he(he({relay:{protocol:c??"irn"},namespaces:u,controller:{publicKey:_,metadata:this.client.metadata},expiry:De(Ni)},l&&{sessionProperties:l}),f&&{scopedProperties:f}),d&&{sessionConfig:d}),U=me.relay;D.addTrace(Xt.subscribing_session_topic);try{await this.client.core.relayer.subscribe($,{transportType:U,internal:{skipSubscribe:!0}})}catch(P){throw D.setError(Xr.subscribe_session_topic_failure),P}D.addTrace(Xt.subscribe_session_topic_success);const F=nt(he({},T),{topic:$,requiredNamespaces:v,optionalNamespaces:B,pairingTopic:p,acknowledged:!1,self:T.controller,peer:{publicKey:g.publicKey,metadata:g.metadata},controller:_,transportType:me.relay});await this.client.session.set($,F),D.addTrace(Xt.store_session);try{await this.sendApproveSession({sessionTopic:$,proposal:h,pairingProposalResponse:{relay:{protocol:c??"irn"},responderPublicKey:_},sessionSettleRequest:T,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:{correlationId:a}}}),D.addTrace(Xt.session_approve_publish_success)}catch(P){throw this.client.logger.error(P),this.client.session.delete($,Ee("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe($),P}return this.client.core.eventClient.deleteEvent({eventId:D.eventId}),await this.client.core.pairing.updateMetadata({topic:p,metadata:g.metadata}),await this.deleteProposal(a),await this.client.core.pairing.activate({topic:p}),await this.setExpiry($,De(Ni)),{topic:$,acknowledged:()=>Promise.resolve(this.client.session.get($))}}),H(this,"reject",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidReject(n)}catch(o){throw this.client.logger.error("reject() -> isValidReject() failed"),o}const{id:r,reason:i}=n;let s;try{s=this.client.proposal.get(r).pairingTopic}catch(o){throw this.client.logger.error(`reject() -> proposal.get(${r}) failed`),o}s&&await this.sendError({id:r,topic:s,error:i,rpcOpts:ze.wc_sessionPropose.reject}),await this.deleteProposal(r)}),H(this,"update",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidUpdate(n)}catch(f){throw this.client.logger.error("update() -> isValidUpdate() failed"),f}const{topic:r,namespaces:i}=n,{done:s,resolve:o,reject:a}=jr(),c=an(),u=Er().toString(),l=this.client.session.get(r).namespaces;return this.events.once(le("session_update",c),({error:f})=>{f?a(f):o()}),await this.client.session.update(r,{namespaces:i}),await this.sendRequest({topic:r,method:"wc_sessionUpdate",params:{namespaces:i},throwOnFailedPublish:!0,clientRpcId:c,relayRpcId:u}).catch(f=>{this.client.logger.error(f),this.client.session.update(r,{namespaces:l}),a(f)}),{acknowledged:s}}),H(this,"extend",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidExtend(n)}catch(c){throw this.client.logger.error("extend() -> isValidExtend() failed"),c}const{topic:r}=n,i=an(),{done:s,resolve:o,reject:a}=jr();return this.events.once(le("session_extend",i),({error:c})=>{c?a(c):o()}),await this.setExpiry(r,De(Ni)),this.sendRequest({topic:r,method:"wc_sessionExtend",params:{},clientRpcId:i,throwOnFailedPublish:!0}).catch(c=>{a(c)}),{acknowledged:s}}),H(this,"request",async n=>{this.isInitialized();try{await this.isValidRequest(n)}catch(v){throw this.client.logger.error("request() -> isValidRequest() failed"),v}const{chainId:r,request:i,topic:s,expiry:o=ze.wc_sessionRequest.req.ttl}=n,a=this.client.session.get(s);a?.transportType===me.relay&&await this.confirmOnlineStateOrThrow();const c=an(),u=Er().toString(),{done:l,resolve:f,reject:d}=jr(o,"Request expired. Please try again.");this.events.once(le("session_request",c),({error:v,result:B})=>{v?d(v):f(B)});const h="wc_sessionRequest",p=this.getAppLinkIfEnabled(a.peer.metadata,a.transportType);if(p)return await this.sendRequest({clientRpcId:c,relayRpcId:u,topic:s,method:h,params:{request:nt(he({},i),{expiryTimestamp:De(o)}),chainId:r},expiry:o,throwOnFailedPublish:!0,appLink:p}).catch(v=>d(v)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:r,id:c}),await l();const g={request:nt(he({},i),{expiryTimestamp:De(o)}),chainId:r};return await Promise.all([new Promise(async v=>{await this.sendRequest({clientRpcId:c,relayRpcId:u,topic:s,method:h,params:g,expiry:o,throwOnFailedPublish:!0,tvf:this.getTVFParams(c,g)}).catch(B=>d(B)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:r,id:c}),v()}),new Promise(async v=>{var B;if(!((B=a.sessionConfig)!=null&&B.disableDeepLink)){const D=await z_(this.client.core.storage,Ry);await q_({id:c,topic:s,wcDeepLink:D})}v()}),l()]).then(v=>v[2])}),H(this,"respond",async n=>{var r,i;this.isInitialized();const s=this.client.core.eventClient.createEvent({properties:{topic:n?.topic||((i=(r=n?.response)==null?void 0:r.id)==null?void 0:i.toString()),trace:[Xt.session_request_response_started]}});try{await this.isValidRespond(n)}catch(f){throw s.addTrace(f?.message),s.setError(Xr.session_request_response_validation_failure),f}s.addTrace(Xt.session_request_response_validation_success);const{topic:o,response:a}=n,{id:c}=a,u=this.client.session.get(o);u.transportType===me.relay&&await this.confirmOnlineStateOrThrow();const l=this.getAppLinkIfEnabled(u.peer.metadata,u.transportType);try{s.addTrace(Xt.session_request_response_publish_started),cn(a)?await this.sendResult({id:c,topic:o,result:a.result,throwOnFailedPublish:!0,appLink:l}):Lt(a)&&await this.sendError({id:c,topic:o,error:a.error,appLink:l}),this.cleanupAfterResponse(n)}catch(f){throw s.addTrace(f?.message),s.setError(Xr.session_request_response_publish_failure),f}}),H(this,"ping",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidPing(n)}catch(i){throw this.client.logger.error("ping() -> isValidPing() failed"),i}const{topic:r}=n;if(this.client.session.keys.includes(r)){const i=an(),s=Er().toString(),{done:o,resolve:a,reject:c}=jr();this.events.once(le("session_ping",i),({error:u})=>{u?c(u):a()}),await Promise.all([this.sendRequest({topic:r,method:"wc_sessionPing",params:{},throwOnFailedPublish:!0,clientRpcId:i,relayRpcId:s}),o()])}else this.client.core.pairing.pairings.keys.includes(r)&&(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:r}))}),H(this,"emit",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidEmit(n);const{topic:r,event:i,chainId:s}=n,o=Er().toString(),a=an();await this.sendRequest({topic:r,method:"wc_sessionEvent",params:{event:i,chainId:s},throwOnFailedPublish:!0,relayRpcId:o,clientRpcId:a})}),H(this,"disconnect",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidDisconnect(n);const{topic:r}=n;if(this.client.session.keys.includes(r))await this.sendRequest({topic:r,method:"wc_sessionDelete",params:Ee("USER_DISCONNECTED"),throwOnFailedPublish:!0}),await this.deleteSession({topic:r,emitEvent:!1});else if(this.client.core.pairing.pairings.keys.includes(r))await this.client.core.pairing.disconnect({topic:r});else{const{message:i}=G("MISMATCHED_TOPIC",`Session or pairing topic not found: ${r}`);throw new Error(i)}}),H(this,"find",n=>(this.isInitialized(),this.client.session.getAll().filter(r=>s9(r,n)))),H(this,"getPendingSessionRequests",()=>this.client.pendingRequest.getAll()),H(this,"authenticate",async(n,r)=>{var i;this.isInitialized(),this.isValidAuthenticate(n);const s=r&&this.client.core.linkModeSupportedApps.includes(r)&&((i=this.client.metadata.redirect)==null?void 0:i.linkMode),o=s?me.link_mode:me.relay;o===me.relay&&await this.confirmOnlineStateOrThrow();const{chains:a,statement:c="",uri:u,domain:l,nonce:f,type:d,exp:h,nbf:p,methods:g=[],expiry:v}=n,B=[...n.resources||[]],{topic:D,uri:_}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:o});this.client.logger.info({message:"Generated new pairing",pairing:{topic:D,uri:_}});const x=await this.client.core.crypto.generateKeyPair(),$=ya(x);if(await Promise.all([this.client.auth.authKeys.set(Aa,{responseTopic:$,publicKey:x}),this.client.auth.pairingTopics.set($,{topic:$,pairingTopic:D})]),await this.client.core.relayer.subscribe($,{transportType:o}),this.client.logger.info(`sending request to new pairing topic: ${D}`),g.length>0){const{namespace:I}=Zo(a[0]);let O=iS(I,"request",g);ia(B)&&(O=oS(O,B.pop())),B.push(O)}const T=v&&v>ze.wc_sessionAuthenticate.req.ttl?v:ze.wc_sessionAuthenticate.req.ttl,U={authPayload:{type:d??"caip122",chains:a,statement:c,aud:u,domain:l,version:"1",nonce:f,iat:new Date().toISOString(),exp:h,nbf:p,resources:B},requester:{publicKey:x,metadata:this.client.metadata},expiryTimestamp:De(T)},F={eip155:{chains:a,methods:[...new Set(["personal_sign",...g])],events:["chainChanged","accountsChanged"]}},P={requiredNamespaces:{},optionalNamespaces:F,relays:[{protocol:"irn"}],pairingTopic:D,proposer:{publicKey:x,metadata:this.client.metadata},expiryTimestamp:De(ze.wc_sessionPropose.req.ttl),id:an()},{done:z,resolve:M,reject:E}=jr(T,"Request expired"),b=an(),m=le("session_connect",P.id),y=le("session_request",b),w=async({error:I,session:O})=>{this.events.off(y,S),I?E(I):O&&M({session:O})},S=async I=>{var O,R,L;if(await this.deletePendingAuthRequest(b,{message:"fulfilled",code:0}),I.error){const V=Ee("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return I.error.code===V.code?void 0:(this.events.off(m,w),E(I.error.message))}await this.deleteProposal(P.id),this.events.off(m,w);const{cacaos:C,responder:k}=I.result,N=[],q=[];for(const V of C){await dg({cacao:V,projectId:this.client.core.projectId})||(this.client.logger.error(V,"Signature verification failed"),E(Ee("SESSION_SETTLEMENT_FAILED","Signature verification failed")));const{p:Z}=V,Q=ia(Z.resources),ee=[Hu(Z.iss)],ie=ra(Z.iss);if(Q){const fe=yg(Q),ve=bg(Q);N.push(...fe),ee.push(...ve)}for(const fe of ee)q.push(`${fe}:${ie}`)}const j=await this.client.core.crypto.generateSharedKey(x,k.publicKey);let W;N.length>0&&(W={topic:j,acknowledged:!0,self:{publicKey:x,metadata:this.client.metadata},peer:k,controller:k.publicKey,expiry:De(Ni),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:D,namespaces:S1([...new Set(N)],[...new Set(q)]),transportType:o},await this.client.core.relayer.subscribe(j,{transportType:o}),await this.client.session.set(j,W),D&&await this.client.core.pairing.updateMetadata({topic:D,metadata:k.metadata}),W=this.client.session.get(j)),(O=this.client.metadata.redirect)!=null&&O.linkMode&&(R=k.metadata.redirect)!=null&&R.linkMode&&(L=k.metadata.redirect)!=null&&L.universal&&r&&(this.client.core.addLinkModeSupportedApp(k.metadata.redirect.universal),this.client.session.update(j,{transportType:me.link_mode})),M({auths:C,session:W})};this.events.once(m,w),this.events.once(y,S);let A;try{if(s){const I=Un("wc_sessionAuthenticate",U,b);this.client.core.history.set(D,I);const O=await this.client.core.crypto.encode("",I,{type:_s,encoding:vr});A=wa(r,D,O)}else await Promise.all([this.sendRequest({topic:D,method:"wc_sessionAuthenticate",params:U,expiry:n.expiry,throwOnFailedPublish:!0,clientRpcId:b}),this.sendRequest({topic:D,method:"wc_sessionPropose",params:P,expiry:ze.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:P.id})])}catch(I){throw this.events.off(m,w),this.events.off(y,S),I}return await this.setProposal(P.id,P),await this.setAuthRequest(b,{request:nt(he({},U),{verifyContext:{}}),pairingTopic:D,transportType:o}),{uri:A??_,response:z}}),H(this,"approveSessionAuthenticate",async n=>{const{id:r,auths:i}=n,s=this.client.core.eventClient.createEvent({properties:{topic:r.toString(),trace:[Jr.authenticated_session_approve_started]}});try{this.isInitialized()}catch(v){throw s.setError(Ts.no_internet_connection),v}const o=this.getPendingAuthRequest(r);if(!o)throw s.setError(Ts.authenticated_session_pending_request_not_found),new Error(`Could not find pending auth request with id ${r}`);const a=o.transportType||me.relay;a===me.relay&&await this.confirmOnlineStateOrThrow();const c=o.requester.publicKey,u=await this.client.core.crypto.generateKeyPair(),l=ya(c),f={type:Rn,receiverPublicKey:c,senderPublicKey:u},d=[],h=[];for(const v of i){if(!await dg({cacao:v,projectId:this.client.core.projectId})){s.setError(Ts.invalid_cacao);const $=Ee("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:r,topic:l,error:$,encodeOpts:f}),new Error($.message)}s.addTrace(Jr.cacaos_verified);const{p:B}=v,D=ia(B.resources),_=[Hu(B.iss)],x=ra(B.iss);if(D){const $=yg(D),T=bg(D);d.push(...$),_.push(...T)}for(const $ of _)h.push(`${$}:${x}`)}const p=await this.client.core.crypto.generateSharedKey(u,c);s.addTrace(Jr.create_authenticated_session_topic);let g;if(d?.length>0){g={topic:p,acknowledged:!0,self:{publicKey:u,metadata:this.client.metadata},peer:{publicKey:c,metadata:o.requester.metadata},controller:c,expiry:De(Ni),authentication:i,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:o.pairingTopic,namespaces:S1([...new Set(d)],[...new Set(h)]),transportType:a},s.addTrace(Jr.subscribing_authenticated_session_topic);try{await this.client.core.relayer.subscribe(p,{transportType:a})}catch(v){throw s.setError(Ts.subscribe_authenticated_session_topic_failure),v}s.addTrace(Jr.subscribe_authenticated_session_topic_success),await this.client.session.set(p,g),s.addTrace(Jr.store_authenticated_session),await this.client.core.pairing.updateMetadata({topic:o.pairingTopic,metadata:o.requester.metadata})}s.addTrace(Jr.publishing_authenticated_session_approve);try{await this.sendResult({topic:l,id:r,result:{cacaos:i,responder:{publicKey:u,metadata:this.client.metadata}},encodeOpts:f,throwOnFailedPublish:!0,appLink:this.getAppLinkIfEnabled(o.requester.metadata,a)})}catch(v){throw s.setError(Ts.authenticated_session_approve_publish_failure),v}return await this.client.auth.requests.delete(r,{message:"fulfilled",code:0}),await this.client.core.pairing.activate({topic:o.pairingTopic}),this.client.core.eventClient.deleteEvent({eventId:s.eventId}),{session:g}}),H(this,"rejectSessionAuthenticate",async n=>{this.isInitialized();const{id:r,reason:i}=n,s=this.getPendingAuthRequest(r);if(!s)throw new Error(`Could not find pending auth request with id ${r}`);s.transportType===me.relay&&await this.confirmOnlineStateOrThrow();const o=s.requester.publicKey,a=await this.client.core.crypto.generateKeyPair(),c=ya(o),u={type:Rn,receiverPublicKey:o,senderPublicKey:a};await this.sendError({id:r,topic:c,error:i,encodeOpts:u,rpcOpts:ze.wc_sessionAuthenticate.reject,appLink:this.getAppLinkIfEnabled(s.requester.metadata,s.transportType)}),await this.client.auth.requests.delete(r,{message:"rejected",code:0}),await this.deleteProposal(r)}),H(this,"formatAuthMessage",n=>{this.isInitialized();const{request:r,iss:i}=n;return pg(r,i)}),H(this,"processRelayMessageCache",()=>{setTimeout(async()=>{if(this.relayMessageCache.length!==0)for(;this.relayMessageCache.length>0;)try{const n=this.relayMessageCache.shift();n&&await this.onRelayMessage(n)}catch(n){this.client.logger.error(n)}},50)}),H(this,"cleanupDuplicatePairings",async n=>{if(n.pairingTopic)try{const r=this.client.core.pairing.pairings.get(n.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)===n.peer.metadata.url&&s.topic&&s.topic!==r.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(r){this.client.logger.error(r)}}),H(this,"deleteSession",async n=>{var r;const{topic:i,expirerHasDeleted:s=!1,emitEvent:o=!0,id:a=0}=n,{self:c}=this.client.session.get(i);await this.client.core.relayer.unsubscribe(i),await this.client.session.delete(i,Ee("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(Ry).catch(u=>this.client.logger.warn(u)),this.getPendingSessionRequests().forEach(u=>{u.topic===i&&this.deletePendingSessionRequest(u.id,Ee("USER_DISCONNECTED"))}),i===((r=this.sessionRequestQueue.queue[0])==null?void 0:r.topic)&&(this.sessionRequestQueue.state=hn.idle),o&&this.client.events.emit("session_delete",{id:a,topic:i})}),H(this,"deleteProposal",async(n,r)=>{if(r)try{const i=this.client.proposal.get(n);this.client.core.eventClient.getEvent({topic:i.pairingTopic})?.setError(Xr.proposal_expired)}catch{}await Promise.all([this.client.proposal.delete(n,Ee("USER_DISCONNECTED")),r?Promise.resolve():this.client.core.expirer.del(n)]),this.addToRecentlyDeleted(n,"proposal")}),H(this,"deletePendingSessionRequest",async(n,r,i=!1)=>{await Promise.all([this.client.pendingRequest.delete(n,r),i?Promise.resolve():this.client.core.expirer.del(n)]),this.addToRecentlyDeleted(n,"request"),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter(s=>s.id!==n),i&&(this.sessionRequestQueue.state=hn.idle,this.client.events.emit("session_request_expire",{id:n}))}),H(this,"deletePendingAuthRequest",async(n,r,i=!1)=>{await Promise.all([this.client.auth.requests.delete(n,r),i?Promise.resolve():this.client.core.expirer.del(n)])}),H(this,"setExpiry",async(n,r)=>{this.client.session.keys.includes(n)&&(this.client.core.expirer.set(n,r),await this.client.session.update(n,{expiry:r}))}),H(this,"setProposal",async(n,r)=>{this.client.core.expirer.set(n,De(ze.wc_sessionPropose.req.ttl)),await this.client.proposal.set(n,r)}),H(this,"setAuthRequest",async(n,r)=>{const{request:i,pairingTopic:s,transportType:o=me.relay}=r;this.client.core.expirer.set(n,i.expiryTimestamp),await this.client.auth.requests.set(n,{authPayload:i.authPayload,requester:i.requester,expiryTimestamp:i.expiryTimestamp,id:n,pairingTopic:s,verifyContext:i.verifyContext,transportType:o})}),H(this,"setPendingSessionRequest",async n=>{const{id:r,topic:i,params:s,verifyContext:o}=n,a=s.request.expiryTimestamp||De(ze.wc_sessionRequest.req.ttl);this.client.core.expirer.set(r,a),await this.client.pendingRequest.set(r,{id:r,topic:i,params:s,verifyContext:o})}),H(this,"sendRequest",async n=>{const{topic:r,method:i,params:s,expiry:o,relayRpcId:a,clientRpcId:c,throwOnFailedPublish:u,appLink:l,tvf:f,publishOpts:d={}}=n,h=Un(i,s,c);let p;const g=!!l;try{const D=g?vr:vt;p=await this.client.core.crypto.encode(r,h,{encoding:D})}catch(D){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${r} failed`),D}let v;if(wD.includes(i)){const D=Ft(JSON.stringify(h)),_=Ft(p);v=await this.client.core.verify.register({id:_,decryptedId:D})}const B=he(he({},ze[i].req),d);if(B.attestation=v,o&&(B.ttl=o),a&&(B.id=a),this.client.core.history.set(r,h),g){const D=wa(l,r,p);await global.Linking.openURL(D,this.client.name)}else B.tvf=nt(he({},f),{correlationId:h.id}),u?(B.internal=nt(he({},B.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(r,p,B)):this.client.core.relayer.publish(r,p,B).catch(D=>this.client.logger.error(D));return h.id}),H(this,"sendProposeSession",async n=>{const{proposal:r,publishOpts:i}=n,s=Un("wc_sessionPropose",r,r.id);this.client.core.history.set(r.pairingTopic,s);const o=await this.client.core.crypto.encode(r.pairingTopic,s,{encoding:vt}),a=Ft(JSON.stringify(s)),c=Ft(o),u=await this.client.core.verify.register({id:c,decryptedId:a});await this.client.core.relayer.publishCustom({payload:{pairingTopic:r.pairingTopic,sessionProposal:o},opts:nt(he({},i),{publishMethod:"wc_proposeSession",attestation:u})})}),H(this,"sendApproveSession",async n=>{const{sessionTopic:r,pairingProposalResponse:i,proposal:s,sessionSettleRequest:o,publishOpts:a}=n,c=va(s.id,i),u=await this.client.core.crypto.encode(s.pairingTopic,c,{encoding:vt}),l=Un("wc_sessionSettle",o,a?.id),f=await this.client.core.crypto.encode(r,l,{encoding:vt});this.client.core.history.set(r,l),await this.client.core.relayer.publishCustom({payload:{sessionTopic:r,pairingTopic:s.pairingTopic,sessionProposalResponse:u,sessionSettlementRequest:f},opts:nt(he({},a),{publishMethod:"wc_approveSession"})})}),H(this,"sendResult",async n=>{const{id:r,topic:i,result:s,throwOnFailedPublish:o,encodeOpts:a,appLink:c}=n,u=va(r,s);let l;const f=c&&typeof(global==null?void 0:global.Linking)<"u";try{const p=f?vr:vt;l=await this.client.core.crypto.encode(i,u,nt(he({},a||{}),{encoding:p}))}catch(p){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${i} failed`),p}let d,h;try{d=await this.client.core.history.get(i,r);const p=d.request;try{h=this.getTVFParams(r,p.params,s)}catch(g){this.client.logger.warn(`sendResult() -> getTVFParams() failed: ${g?.message}`)}}catch(p){throw this.client.logger.error(`sendResult() -> history.get(${i}, ${r}) failed`),p}if(f){const p=wa(c,i,l);await global.Linking.openURL(p,this.client.name)}else{const p=d.request.method,g=ze[p].res;g.tvf=nt(he({},h),{correlationId:r}),o?(g.internal=nt(he({},g.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(i,l,g)):this.client.core.relayer.publish(i,l,g).catch(v=>this.client.logger.error(v))}await this.client.core.history.resolve(u)}),H(this,"sendError",async n=>{const{id:r,topic:i,error:s,encodeOpts:o,rpcOpts:a,appLink:c}=n,u=_l(r,s);let l;const f=c&&typeof(global==null?void 0:global.Linking)<"u";try{const h=f?vr:vt;l=await this.client.core.crypto.encode(i,u,nt(he({},o||{}),{encoding:h}))}catch(h){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${i} failed`),h}let d;try{d=await this.client.core.history.get(i,r)}catch(h){throw this.client.logger.error(`sendError() -> history.get(${i}, ${r}) failed`),h}if(f){const h=wa(c,i,l);await global.Linking.openURL(h,this.client.name)}else{const h=d.request.method,p=a||ze[h].res;this.client.core.relayer.publish(i,l,p)}await this.client.core.history.resolve(u)}),H(this,"cleanup",async()=>{const n=[],r=[];this.client.session.getAll().forEach(i=>{let s=!1;or(i.expiry)&&(s=!0),this.client.core.crypto.keychain.has(i.topic)||(s=!0),s&&n.push(i.topic)}),this.client.proposal.getAll().forEach(i=>{or(i.expiryTimestamp)&&r.push(i.id)}),await Promise.all([...n.map(i=>this.deleteSession({topic:i})),...r.map(i=>this.deleteProposal(i))])}),H(this,"onProviderMessageEvent",async n=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(n):await this.onRelayMessage(n)}),H(this,"onRelayEventRequest",async n=>{this.requestQueue.queue.push(n),await this.processRequestsQueue()}),H(this,"processRequestsQueue",async()=>{if(this.requestQueue.state===hn.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=hn.active;const n=this.requestQueue.queue.shift();if(n)try{await this.processRequest(n)}catch(r){this.client.logger.warn(r)}}this.requestQueue.state=hn.idle}),H(this,"processRequest",async n=>{const{topic:r,payload:i,attestation:s,transportType:o,encryptedId:a}=n,c=i.method;if(!this.shouldIgnorePairingRequest({topic:r,requestMethod:c}))switch(c){case"wc_sessionPropose":return await this.onSessionProposeRequest({topic:r,payload:i,attestation:s,encryptedId:a});case"wc_sessionSettle":return await this.onSessionSettleRequest(r,i);case"wc_sessionUpdate":return await this.onSessionUpdateRequest(r,i);case"wc_sessionExtend":return await this.onSessionExtendRequest(r,i);case"wc_sessionPing":return await this.onSessionPingRequest(r,i);case"wc_sessionDelete":return await this.onSessionDeleteRequest(r,i);case"wc_sessionRequest":return await this.onSessionRequest({topic:r,payload:i,attestation:s,encryptedId:a,transportType:o});case"wc_sessionEvent":return await this.onSessionEventRequest(r,i);case"wc_sessionAuthenticate":return await this.onSessionAuthenticateRequest({topic:r,payload:i,attestation:s,encryptedId:a,transportType:o});default:return this.client.logger.info(`Unsupported request method ${c}`)}}),H(this,"onRelayEventResponse",async n=>{const{topic:r,payload:i,transportType:s}=n,o=(await this.client.core.history.get(r,i.id)).request.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeResponse(r,i,s);case"wc_sessionSettle":return this.onSessionSettleResponse(r,i);case"wc_sessionUpdate":return this.onSessionUpdateResponse(r,i);case"wc_sessionExtend":return this.onSessionExtendResponse(r,i);case"wc_sessionPing":return this.onSessionPingResponse(r,i);case"wc_sessionRequest":return this.onSessionRequestResponse(r,i);case"wc_sessionAuthenticate":return this.onSessionAuthenticateResponse(r,i);default:return this.client.logger.info(`Unsupported response method ${o}`)}}),H(this,"onRelayEventUnknownPayload",n=>{const{topic:r}=n,{message:i}=G("MISSING_OR_INVALID",`Decoded payload on topic ${r} is not identifiable as a JSON-RPC request or a response.`);throw new Error(i)}),H(this,"shouldIgnorePairingRequest",n=>{const{topic:r,requestMethod:i}=n,s=this.expectedPairingMethodMap.get(r);return!s||s.includes(i)?!1:!!(s.includes("wc_sessionAuthenticate")&&this.client.events.listenerCount("session_authenticate")>0)}),H(this,"onSessionProposeRequest",async n=>{const{topic:r,payload:i,attestation:s,encryptedId:o}=n,{params:a,id:c}=i;try{const u=this.client.core.eventClient.getEvent({topic:r});this.client.events.listenerCount("session_proposal")===0&&(console.warn("No listener for session_proposal event"),u?.setError(Fn.proposal_listener_not_found)),this.isValidConnect(he({},i.params));const l=a.expiryTimestamp||De(ze.wc_sessionPropose.req.ttl),f=he({id:c,pairingTopic:r,expiryTimestamp:l,attestation:s,encryptedId:o},a);await this.setProposal(c,f);const d=await this.getVerifyContext({attestationId:s,hash:Ft(JSON.stringify(i)),encryptedId:o,metadata:f.proposer.metadata});u?.addTrace(ln.emit_session_proposal),this.client.events.emit("session_proposal",{id:c,params:f,verifyContext:d})}catch(u){await this.sendError({id:c,topic:r,error:u,rpcOpts:ze.wc_sessionPropose.autoReject}),this.client.logger.error(u)}}),H(this,"onSessionProposeResponse",async(n,r,i)=>{const{id:s}=r;if(cn(r)){const{result:o}=r;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:n,proposalId:s,publicKey:c});const f=await this.client.core.relayer.subscribe(l,{transportType:i});this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:f}),await this.client.core.pairing.activate({topic:n})}else if(Lt(r)){await this.deleteProposal(s);const o=le("session_connect",s);if(this.events.listenerCount(o)===0)throw new Error(`emitting ${o} without any listeners, 954`);this.events.emit(o,{error:r.error})}}),H(this,"onSessionSettleRequest",async(n,r)=>{const{id:i,params:s}=r;try{this.isValidSessionSettleRequest(s);const{relay:o,controller:a,expiry:c,namespaces:u,sessionProperties:l,scopedProperties:f,sessionConfig:d}=r.params,h=[...this.pendingSessions.values()].find(v=>v.sessionTopic===n);if(!h)return this.client.logger.error(`Pending session not found for topic ${n}`);const p=this.client.proposal.get(h.proposalId),g=nt(he(he(he({topic:n,relay:o,expiry:c,namespaces:u,acknowledged:!0,pairingTopic:h.pairingTopic,requiredNamespaces:p.requiredNamespaces,optionalNamespaces:p.optionalNamespaces,controller:a.publicKey,self:{publicKey:h.publicKey,metadata:this.client.metadata},peer:{publicKey:a.publicKey,metadata:a.metadata}},l&&{sessionProperties:l}),f&&{scopedProperties:f}),d&&{sessionConfig:d}),{transportType:me.relay});await this.client.session.set(g.topic,g),await this.setExpiry(g.topic,g.expiry),await this.client.core.pairing.updateMetadata({topic:h.pairingTopic,metadata:g.peer.metadata}),this.client.events.emit("session_connect",{session:g}),this.events.emit(le("session_connect",h.proposalId),{session:g}),this.pendingSessions.delete(h.proposalId),this.deleteProposal(h.proposalId,!1),this.cleanupDuplicatePairings(g),await this.sendResult({id:r.id,topic:n,result:!0})}catch(o){await this.sendError({id:i,topic:n,error:o}),this.client.logger.error(o)}}),H(this,"onSessionSettleResponse",async(n,r)=>{const{id:i}=r;cn(r)?(await this.client.session.update(n,{acknowledged:!0}),this.events.emit(le("session_approve",i),{})):Lt(r)&&(await this.client.session.delete(n,Ee("USER_DISCONNECTED")),this.events.emit(le("session_approve",i),{error:r.error}))}),H(this,"onSessionUpdateRequest",async(n,r)=>{const{params:i,id:s}=r;try{const o=`${n}_session_update`,a=Bs.get(o);if(a&&this.isRequestOutOfSync(a,s)){this.client.logger.warn(`Discarding out of sync request - ${s}`),this.sendError({id:s,topic:n,error:Ee("INVALID_UPDATE_REQUEST")});return}this.isValidUpdate(he({topic:n},i));try{Bs.set(o,s),await this.client.session.update(n,{namespaces:i.namespaces}),await this.sendResult({id:s,topic:n,result:!0})}catch(c){throw Bs.delete(o),c}this.client.events.emit("session_update",{id:s,topic:n,params:i})}catch(o){await this.sendError({id:s,topic:n,error:o}),this.client.logger.error(o)}}),H(this,"isRequestOutOfSync",(n,r)=>r.toString().slice(0,-3)<n.toString().slice(0,-3)),H(this,"onSessionUpdateResponse",(n,r)=>{const{id:i}=r,s=le("session_update",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);cn(r)?this.events.emit(le("session_update",i),{}):Lt(r)&&this.events.emit(le("session_update",i),{error:r.error})}),H(this,"onSessionExtendRequest",async(n,r)=>{const{id:i}=r;try{this.isValidExtend({topic:n}),await this.setExpiry(n,De(Ni)),await this.sendResult({id:i,topic:n,result:!0}),this.client.events.emit("session_extend",{id:i,topic:n})}catch(s){await this.sendError({id:i,topic:n,error:s}),this.client.logger.error(s)}}),H(this,"onSessionExtendResponse",(n,r)=>{const{id:i}=r,s=le("session_extend",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);cn(r)?this.events.emit(le("session_extend",i),{}):Lt(r)&&this.events.emit(le("session_extend",i),{error:r.error})}),H(this,"onSessionPingRequest",async(n,r)=>{const{id:i}=r;try{this.isValidPing({topic:n}),await this.sendResult({id:i,topic:n,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_ping",{id:i,topic:n})}catch(s){await this.sendError({id:i,topic:n,error:s}),this.client.logger.error(s)}}),H(this,"onSessionPingResponse",(n,r)=>{const{id:i}=r,s=le("session_ping",i);setTimeout(()=>{if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners 2176`);cn(r)?this.events.emit(le("session_ping",i),{}):Lt(r)&&this.events.emit(le("session_ping",i),{error:r.error})},500)}),H(this,"onSessionDeleteRequest",async(n,r)=>{const{id:i}=r;try{this.isValidDisconnect({topic:n,reason:r.params}),await Promise.all([new Promise(s=>{this.client.core.relayer.once(Se.publish,async()=>{s(await this.deleteSession({topic:n,id:i}))})}),this.sendResult({id:i,topic:n,result:!0}),this.cleanupPendingSentRequestsForTopic({topic:n,error:Ee("USER_DISCONNECTED")})]).catch(s=>this.client.logger.error(s))}catch(s){this.client.logger.error(s)}}),H(this,"onSessionRequest",async n=>{var r,i,s;const{topic:o,payload:a,attestation:c,encryptedId:u,transportType:l}=n,{id:f,params:d}=a;try{await this.isValidRequest(he({topic:o},d));const h=this.client.session.get(o),p=await this.getVerifyContext({attestationId:c,hash:Ft(JSON.stringify(Un("wc_sessionRequest",d,f))),encryptedId:u,metadata:h.peer.metadata,transportType:l}),g={id:f,topic:o,params:d,verifyContext:p};await this.setPendingSessionRequest(g),l===me.link_mode&&(r=h.peer.metadata.redirect)!=null&&r.universal&&this.client.core.addLinkModeSupportedApp((i=h.peer.metadata.redirect)==null?void 0:i.universal),(s=this.client.signConfig)!=null&&s.disableRequestQueue?this.emitSessionRequest(g):(this.addSessionRequestToSessionRequestQueue(g),this.processSessionRequestQueue())}catch(h){await this.sendError({id:f,topic:o,error:h}),this.client.logger.error(h)}}),H(this,"onSessionRequestResponse",(n,r)=>{const{id:i}=r,s=le("session_request",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);cn(r)?this.events.emit(le("session_request",i),{result:r.result}):Lt(r)&&this.events.emit(le("session_request",i),{error:r.error})}),H(this,"onSessionEventRequest",async(n,r)=>{const{id:i,params:s}=r;try{const o=`${n}_session_event_${s.event.name}`,a=Bs.get(o);if(a&&this.isRequestOutOfSync(a,i)){this.client.logger.info(`Discarding out of sync request - ${i}`);return}this.isValidEmit(he({topic:n},s)),this.client.events.emit("session_event",{id:i,topic:n,params:s}),Bs.set(o,i)}catch(o){await this.sendError({id:i,topic:n,error:o}),this.client.logger.error(o)}}),H(this,"onSessionAuthenticateResponse",(n,r)=>{const{id:i}=r;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:n,payload:r}),cn(r)?this.events.emit(le("session_request",i),{result:r.result}):Lt(r)&&this.events.emit(le("session_request",i),{error:r.error})}),H(this,"onSessionAuthenticateRequest",async n=>{var r;const{topic:i,payload:s,attestation:o,encryptedId:a,transportType:c}=n;try{const{requester:u,authPayload:l,expiryTimestamp:f}=s.params,d=await this.getVerifyContext({attestationId:o,hash:Ft(JSON.stringify(s)),encryptedId:a,metadata:u.metadata,transportType:c}),h={requester:u,pairingTopic:i,id:s.id,authPayload:l,verifyContext:d,expiryTimestamp:f};await this.setAuthRequest(s.id,{request:h,pairingTopic:i,transportType:c}),c===me.link_mode&&(r=u.metadata.redirect)!=null&&r.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,f=await this.client.core.crypto.generateKeyPair(),d=this.getAppLinkIfEnabled(s.params.requester.metadata,c),h={type:Rn,receiverPublicKey:l,senderPublicKey:f};await this.sendError({id:s.id,topic:i,error:u,encodeOpts:h,rpcOpts:ze.wc_sessionAuthenticate.autoReject,appLink:d})}}),H(this,"addSessionRequestToSessionRequestQueue",n=>{this.sessionRequestQueue.queue.push(n)}),H(this,"cleanupAfterResponse",n=>{this.deletePendingSessionRequest(n.response.id,{message:"fulfilled",code:0}),setTimeout(()=>{this.sessionRequestQueue.state=hn.idle,this.processSessionRequestQueue()},K.toMiliseconds(this.requestQueueDelay))}),H(this,"cleanupPendingSentRequestsForTopic",({topic:n,error:r})=>{const i=this.client.core.history.pending;i.length>0&&i.filter(s=>s.topic===n&&s.request.method==="wc_sessionRequest").forEach(s=>{const o=s.request.id,a=le("session_request",o);if(this.events.listenerCount(a)===0)throw new Error(`emitting ${a} without any listeners`);this.events.emit(le("session_request",s.request.id),{error:r})})}),H(this,"processSessionRequestQueue",()=>{if(this.sessionRequestQueue.state===hn.active){this.client.logger.info("session request queue is already active.");return}const n=this.sessionRequestQueue.queue[0];if(!n){this.client.logger.info("session request queue is empty.");return}try{this.emitSessionRequest(n)}catch(r){this.client.logger.error(r)}}),H(this,"emitSessionRequest",n=>{if(this.emittedSessionRequests.has(n.id)){this.client.logger.warn({id:n.id},`Skipping emitting \`session_request\` event for duplicate request. id: ${n.id}`);return}this.sessionRequestQueue.state=hn.active,this.emittedSessionRequests.add(n.id),this.client.events.emit("session_request",n)}),H(this,"onPairingCreated",n=>{if(n.methods&&this.expectedPairingMethodMap.set(n.topic,n.methods),n.active)return;const r=this.client.proposal.getAll().find(i=>i.pairingTopic===n.topic);r&&this.onSessionProposeRequest({topic:n.topic,payload:Un("wc_sessionPropose",nt(he({},r),{requiredNamespaces:r.requiredNamespaces,optionalNamespaces:r.optionalNamespaces,relays:r.relays,proposer:r.proposer,sessionProperties:r.sessionProperties,scopedProperties:r.scopedProperties}),r.id),attestation:r.attestation,encryptedId:r.encryptedId})}),H(this,"isValidConnect",async n=>{if(!Et(n)){const{message:u}=G("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(n)}`);throw new Error(u)}const{pairingTopic:r,requiredNamespaces:i,optionalNamespaces:s,sessionProperties:o,scopedProperties:a,relays:c}=n;if(Pe(r)||await this.isValidPairingTopic(r),!b9(c,!0)){const{message:u}=G("MISSING_OR_INVALID",`connect() relays: ${c}`);throw new Error(u)}if(i&&!Pe(i)&&As(i)!==0){const u="requiredNamespaces are deprecated and are automatically assigned to optionalNamespaces";["fatal","error","silent"].includes(this.client.logger.level)?console.warn(u):this.client.logger.warn(u),this.validateNamespaces(i,"requiredNamespaces")}if(s&&!Pe(s)&&As(s)!==0&&this.validateNamespaces(s,"optionalNamespaces"),o&&!Pe(o)&&this.validateSessionProps(o,"sessionProperties"),a&&!Pe(a)){this.validateSessionProps(a,"scopedProperties");const u=Object.keys(i||{}).concat(Object.keys(s||{}));if(!Object.keys(a).every(l=>u.includes(l.split(":")[0])))throw new Error(`Scoped properties must be a subset of required/optional namespaces, received: ${JSON.stringify(a)}, required/optional namespaces: ${JSON.stringify(u)}`)}}),H(this,"validateNamespaces",(n,r)=>{const i=y9(n,"connect()",r);if(i)throw new Error(i.message)}),H(this,"isValidApprove",async n=>{if(!Et(n))throw new Error(G("MISSING_OR_INVALID",`approve() params: ${n}`).message);const{id:r,namespaces:i,relayProtocol:s,sessionProperties:o,scopedProperties:a}=n;this.checkRecentlyDeleted(r),await this.isValidProposalId(r);const c=this.client.proposal.get(r),u=yl(i,"approve()");if(u)throw new Error(u.message);const l=D1(c.requiredNamespaces,i,"approve()");if(l)throw new Error(l.message);if(!Ie(s,!0)){const{message:f}=G("MISSING_OR_INVALID",`approve() relayProtocol: ${s}`);throw new Error(f)}if(o&&!Pe(o)&&this.validateSessionProps(o,"sessionProperties"),a&&!Pe(a)){this.validateSessionProps(a,"scopedProperties");const f=new Set(Object.keys(i));if(!Object.keys(a).every(d=>f.has(d.split(":")[0])))throw new Error(`Scoped properties must be a subset of approved namespaces, received: ${JSON.stringify(a)}, approved namespaces: ${Array.from(f).join(", ")}`)}}),H(this,"isValidReject",async n=>{if(!Et(n)){const{message:s}=G("MISSING_OR_INVALID",`reject() params: ${n}`);throw new Error(s)}const{id:r,reason:i}=n;if(this.checkRecentlyDeleted(r),await this.isValidProposalId(r),!m9(i)){const{message:s}=G("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(i)}`);throw new Error(s)}}),H(this,"isValidSessionSettleRequest",n=>{if(!Et(n)){const{message:u}=G("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${n}`);throw new Error(u)}const{relay:r,controller:i,namespaces:s,expiry:o}=n;if(!B1(r)){const{message:u}=G("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(u)}const a=l9(i,"onSessionSettleRequest()");if(a)throw new Error(a.message);const c=yl(s,"onSessionSettleRequest()");if(c)throw new Error(c.message);if(or(o)){const{message:u}=G("EXPIRED","onSessionSettleRequest()");throw new Error(u)}}),H(this,"isValidUpdate",async n=>{if(!Et(n)){const{message:c}=G("MISSING_OR_INVALID",`update() params: ${n}`);throw new Error(c)}const{topic:r,namespaces:i}=n;this.checkRecentlyDeleted(r),await this.isValidSessionTopic(r);const s=this.client.session.get(r),o=yl(i,"update()");if(o)throw new Error(o.message);const a=D1(s.requiredNamespaces,i,"update()");if(a)throw new Error(a.message)}),H(this,"isValidExtend",async n=>{if(!Et(n)){const{message:i}=G("MISSING_OR_INVALID",`extend() params: ${n}`);throw new Error(i)}const{topic:r}=n;this.checkRecentlyDeleted(r),await this.isValidSessionTopic(r)}),H(this,"isValidRequest",async n=>{if(!Et(n)){const{message:c}=G("MISSING_OR_INVALID",`request() params: ${n}`);throw new Error(c)}const{topic:r,request:i,chainId:s,expiry:o}=n;this.checkRecentlyDeleted(r),await this.isValidSessionTopic(r);const{namespaces:a}=this.client.session.get(r);if(!O1(a,s)){const{message:c}=G("MISSING_OR_INVALID",`request() chainId: ${s}`);throw new Error(c)}if(!v9(i)){const{message:c}=G("MISSING_OR_INVALID",`request() ${JSON.stringify(i)}`);throw new Error(c)}if(!_9(a,s,i.method)){const{message:c}=G("MISSING_OR_INVALID",`request() method: ${i.method}`);throw new Error(c)}if(o&&!B9(o,jl)){const{message:c}=G("MISSING_OR_INVALID",`request() expiry: ${o}. Expiry must be a number (in seconds) between ${jl.min} and ${jl.max}`);throw new Error(c)}}),H(this,"isValidRespond",async n=>{var r;if(!Et(n)){const{message:a}=G("MISSING_OR_INVALID",`respond() params: ${n}`);throw new Error(a)}const{topic:i,response:s}=n;try{await this.isValidSessionTopic(i)}catch(a){throw(r=n?.response)!=null&&r.id&&this.cleanupAfterResponse(n),a}if(!E9(s)){const{message:a}=G("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(s)}`);throw new Error(a)}const o=this.client.pendingRequest.get(s.id);if(o.topic!==i){const{message:a}=G("MISMATCHED_TOPIC",`Request response topic mismatch. reqId: ${s.id}, expected topic: ${o.topic}, received topic: ${i}`);throw new Error(a)}}),H(this,"isValidPing",async n=>{if(!Et(n)){const{message:i}=G("MISSING_OR_INVALID",`ping() params: ${n}`);throw new Error(i)}const{topic:r}=n;await this.isValidSessionOrPairingTopic(r)}),H(this,"isValidEmit",async n=>{if(!Et(n)){const{message:a}=G("MISSING_OR_INVALID",`emit() params: ${n}`);throw new Error(a)}const{topic:r,event:i,chainId:s}=n;await this.isValidSessionTopic(r);const{namespaces:o}=this.client.session.get(r);if(!O1(o,s)){const{message:a}=G("MISSING_OR_INVALID",`emit() chainId: ${s}`);throw new Error(a)}if(!x9(i)){const{message:a}=G("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}if(!S9(o,s,i.name)){const{message:a}=G("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}}),H(this,"isValidDisconnect",async n=>{if(!Et(n)){const{message:i}=G("MISSING_OR_INVALID",`disconnect() params: ${n}`);throw new Error(i)}const{topic:r}=n;await this.isValidSessionOrPairingTopic(r)}),H(this,"isValidAuthenticate",n=>{const{chains:r,uri:i,domain:s,nonce:o}=n;if(!Array.isArray(r)||r.length===0)throw new Error("chains is required and must be a non-empty array");if(!Ie(i,!1))throw new Error("uri is required parameter");if(!Ie(s,!1))throw new Error("domain is required parameter");if(!Ie(o,!1))throw new Error("nonce is required parameter");if([...new Set(r.map(c=>Zo(c).namespace))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");const{namespace:a}=Zo(r[0]);if(a!=="eip155")throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")}),H(this,"getVerifyContext",async n=>{const{attestationId:r,hash:i,encryptedId:s,metadata:o,transportType:a}=n,c={verified:{verifyUrl:o.verifyUrl||Ps,validation:"UNKNOWN",origin:o.url||""}};try{if(a===me.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:r,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}),H(this,"validateSessionProps",(n,r)=>{Object.values(n).forEach((i,s)=>{if(i==null){const{message:o}=G("MISSING_OR_INVALID",`${r} must contain an existing value for each key. Received: ${i} for key ${Object.keys(n)[s]}`);throw new Error(o)}})}),H(this,"getPendingAuthRequest",n=>{const r=this.client.auth.requests.get(n);return typeof r=="object"?r:void 0}),H(this,"addToRecentlyDeleted",(n,r)=>{if(this.recentlyDeletedMap.set(n,r),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)}}}),H(this,"checkRecentlyDeleted",n=>{const r=this.recentlyDeletedMap.get(n);if(r){const{message:i}=G("MISSING_OR_INVALID",`Record was recently deleted - ${r}: ${n}`);throw new Error(i)}}),H(this,"isLinkModeEnabled",(n,r)=>{var i,s,o,a,c,u,l,f,d;return!n||r!==me.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=n?.redirect)==null?void 0:l.universal)!==void 0&&((f=n?.redirect)==null?void 0:f.universal)!==""&&((d=n?.redirect)==null?void 0:d.linkMode)===!0&&this.client.core.linkModeSupportedApps.includes(n.redirect.universal)&&typeof(global==null?void 0:global.Linking)<"u"}),H(this,"getAppLinkIfEnabled",(n,r)=>{var i;return this.isLinkModeEnabled(n,r)?(i=n?.redirect)==null?void 0:i.universal:void 0}),H(this,"handleLinkModeMessage",({url:n})=>{if(!n||!n.includes("wc_ev")||!n.includes("topic"))return;const r=M0(n,"topic")||"",i=decodeURIComponent(M0(n,"wc_ev")||""),s=this.client.session.keys.includes(r);s&&this.client.session.update(r,{transportType:me.link_mode}),this.client.core.dispatchEnvelope({topic:r,message:i,sessionExists:s})}),H(this,"registerLinkModeListeners",async()=>{var n;if(Cu()||sr()&&(n=this.client.metadata.redirect)!=null&&n.linkMode){const r=global==null?void 0:global.Linking;if(typeof r<"u"){r.addEventListener("url",this.handleLinkModeMessage,this.client.name);const i=await r.getInitialURL();i&&setTimeout(()=>{this.handleLinkModeMessage({url:i})},50)}}}),H(this,"getTVFParams",(n,r,i)=>{var s,o,a;if(!((s=r.request)!=null&&s.method))return{};const c={correlationId:n,rpcMethods:[r.request.method],chainId:r.chainId};try{const u=this.extractTxHashesFromResult(r.request,i);c.txHashes=u,c.contractAddresses=this.isValidContractData(r.request.params)?[(a=(o=r.request.params)==null?void 0:o[0])==null?void 0:a.to]:[]}catch(u){this.client.logger.warn(u,"Error getting TVF params")}return c}),H(this,"isValidContractData",n=>{var r;if(!n)return!1;try{const i=n?.data||((r=n?.[0])==null?void 0:r.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}),H(this,"extractTxHashesFromResult",(n,r)=>{var i;try{if(!r)return[];const s=n.method,o=yD[s];if(s==="sui_signTransaction")return[M5(r.transactionBytes)];if(s==="near_signTransaction")return[ug(r)];if(s==="near_signTransactions")return r.map(c=>ug(c));if(s==="xrpl_signTransactionFor"||s==="xrpl_signTransaction")return[(i=r.tx_json)==null?void 0:i.hash];if(s==="polkadot_signTransaction")return[j9({transaction:n.params.transactionPayload,signature:r.signature})];if(s==="algo_signTxn")return Pi(r)?r.map(c=>lg(c)):[lg(r)];if(s==="cosmos_signDirect")return[z5(r)];if(s==="wallet_sendCalls")return H5(r);if(typeof r=="string")return[r];const a=r[o.key];if(Pi(a))return s==="solana_signAllTransactions"?a.map(c=>q5(c)):a;if(typeof a=="string")return[a]}catch(s){this.client.logger.warn(s,"Error extracting tx hashes from result")}return[]})}async processPendingMessageEvents(){try{const e=this.client.session.keys,n=this.client.core.relayer.messages.getWithoutAck(e);for(const[r,i]of Object.entries(n))for(const s of i)try{await this.onProviderMessageEvent({topic:r,message:s,publishedAt:Date.now()})}catch{this.client.logger.warn(`Error processing pending message event for topic: ${r}, message: ${s}`)}}catch(e){this.client.logger.warn(e,"processPendingMessageEvents failed")}}isInitialized(){if(!this.initialized){const{message:e}=G("NOT_INITIALIZED",this.name);throw new Error(e)}}async confirmOnlineStateOrThrow(){await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(Se.message,e=>{this.onProviderMessageEvent(e)})}async onRelayMessage(e){const{topic:n,message:r,attestation:i,transportType:s}=e,{publicKey:o}=this.client.auth.authKeys.keys.includes(Aa)?this.client.auth.authKeys.get(Aa):{responseTopic:void 0,publicKey:void 0};try{const a=await this.client.core.crypto.decode(n,r,{receiverPublicKey:o,encoding:s===me.link_mode?vr:vt});Sl(a)?(this.client.core.history.set(n,a),await this.onRelayEventRequest({topic:n,payload:a,attestation:i,transportType:s,encryptedId:Ft(r)})):Ea(a)?(await this.client.core.history.resolve(a),await this.onRelayEventResponse({topic:n,payload:a,transportType:s}),this.client.core.history.delete(n,a.id)):await this.onRelayEventUnknownPayload({topic:n,payload:a,transportType:s}),await this.client.core.relayer.messages.ack(n,r)}catch(a){this.client.logger.error(a)}}registerExpirerEvents(){this.client.core.expirer.on(qt.expired,async e=>{const{topic:n,id:r}=q0(e.target);if(r&&this.client.pendingRequest.keys.includes(r))return await this.deletePendingSessionRequest(r,G("EXPIRED"),!0);if(r&&this.client.auth.requests.keys.includes(r))return await this.deletePendingAuthRequest(r,G("EXPIRED"),!0);n?this.client.session.keys.includes(n)&&(await this.deleteSession({topic:n,expirerHasDeleted:!0}),this.client.events.emit("session_expire",{topic:n})):r&&(await this.deleteProposal(r,!0),this.client.events.emit("proposal_expire",{id:r}))})}registerPairingEvents(){this.client.core.pairing.events.on(Yr.create,e=>this.onPairingCreated(e)),this.client.core.pairing.events.on(Yr.delete,e=>{this.addToRecentlyDeleted(e.topic,"pairing")})}isValidPairingTopic(e){if(!Ie(e,!1)){const{message:n}=G("MISSING_OR_INVALID",`pairing topic should be a string: ${e}`);throw new Error(n)}if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:n}=G("NO_MATCHING_KEY",`pairing topic doesn't exist: ${e}`);throw new Error(n)}if(or(this.client.core.pairing.pairings.get(e).expiry)){const{message:n}=G("EXPIRED",`pairing topic: ${e}`);throw new Error(n)}}async isValidSessionTopic(e){if(!Ie(e,!1)){const{message:n}=G("MISSING_OR_INVALID",`session topic should be a string: ${e}`);throw new Error(n)}if(this.checkRecentlyDeleted(e),!this.client.session.keys.includes(e)){const{message:n}=G("NO_MATCHING_KEY",`session topic doesn't exist: ${e}`);throw new Error(n)}if(or(this.client.session.get(e).expiry)){await this.deleteSession({topic:e});const{message:n}=G("EXPIRED",`session topic: ${e}`);throw new Error(n)}if(!this.client.core.crypto.keychain.has(e)){const{message:n}=G("MISSING_OR_INVALID",`session topic does not exist in keychain: ${e}`);throw await this.deleteSession({topic:e}),new Error(n)}}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(Ie(e,!1)){const{message:n}=G("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${e}`);throw new Error(n)}else{const{message:n}=G("MISSING_OR_INVALID",`session or pairing topic should be a string: ${e}`);throw new Error(n)}}async isValidProposalId(e){if(!w9(e)){const{message:n}=G("MISSING_OR_INVALID",`proposal id should be a number: ${e}`);throw new Error(n)}if(!this.client.proposal.keys.includes(e)){const{message:n}=G("NO_MATCHING_KEY",`proposal id doesn't exist: ${e}`);throw new Error(n)}if(or(this.client.proposal.get(e).expiryTimestamp)){await this.deleteProposal(e);const{message:n}=G("EXPIRED",`proposal id: ${e}`);throw new Error(n)}}}class $D extends Qr{constructor(e,n){super(e,n,dD,ql),this.core=e,this.logger=n}}class Uy extends Qr{constructor(e,n){super(e,n,pD,ql),this.core=e,this.logger=n}}class PD extends Qr{constructor(e,n){super(e,n,bD,ql,r=>r.id),this.core=e,this.logger=n}}class TD extends Qr{constructor(e,n){super(e,n,ED,Ia,()=>Aa),this.core=e,this.logger=n}}class RD extends Qr{constructor(e,n){super(e,n,xD,Ia),this.core=e,this.logger=n}}class ND extends Qr{constructor(e,n){super(e,n,_D,Ia,r=>r.id),this.core=e,this.logger=n}}var CD=Object.defineProperty,UD=(t,e,n)=>e in t?CD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Hl=(t,e,n)=>UD(t,typeof e!="symbol"?e+"":e,n);class FD{constructor(e,n){this.core=e,this.logger=n,Hl(this,"authKeys"),Hl(this,"pairingTopics"),Hl(this,"requests"),this.authKeys=new TD(this.core,this.logger),this.pairingTopics=new RD(this.core,this.logger),this.requests=new ND(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}var LD=Object.defineProperty,kD=(t,e,n)=>e in t?LD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oe=(t,e,n)=>kD(t,typeof e!="symbol"?e+"":e,n);class Vl extends wm{constructor(e){super(e),oe(this,"protocol",$y),oe(this,"version",Py),oe(this,"name",Ml.name),oe(this,"metadata"),oe(this,"core"),oe(this,"logger"),oe(this,"events",new Ve.exports.EventEmitter),oe(this,"engine"),oe(this,"session"),oe(this,"proposal"),oe(this,"pendingRequest"),oe(this,"auth"),oe(this,"signConfig"),oe(this,"on",(r,i)=>this.events.on(r,i)),oe(this,"once",(r,i)=>this.events.once(r,i)),oe(this,"off",(r,i)=>this.events.off(r,i)),oe(this,"removeListener",(r,i)=>this.events.removeListener(r,i)),oe(this,"removeAllListeners",r=>this.events.removeAllListeners(r)),oe(this,"connect",async r=>{try{return await this.engine.connect(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"pair",async r=>{try{return await this.engine.pair(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"approve",async r=>{try{return await this.engine.approve(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"reject",async r=>{try{return await this.engine.reject(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"update",async r=>{try{return await this.engine.update(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"extend",async r=>{try{return await this.engine.extend(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"request",async r=>{try{return await this.engine.request(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"respond",async r=>{try{return await this.engine.respond(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"ping",async r=>{try{return await this.engine.ping(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"emit",async r=>{try{return await this.engine.emit(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"disconnect",async r=>{try{return await this.engine.disconnect(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"find",r=>{try{return this.engine.find(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"getPendingSessionRequests",()=>{try{return this.engine.getPendingSessionRequests()}catch(r){throw this.logger.error(r.message),r}}),oe(this,"authenticate",async(r,i)=>{try{return await this.engine.authenticate(r,i)}catch(s){throw this.logger.error(s.message),s}}),oe(this,"formatAuthMessage",r=>{try{return this.engine.formatAuthMessage(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"approveSessionAuthenticate",async r=>{try{return await this.engine.approveSessionAuthenticate(r)}catch(i){throw this.logger.error(i.message),i}}),oe(this,"rejectSessionAuthenticate",async r=>{try{return await this.engine.rejectSessionAuthenticate(r)}catch(i){throw this.logger.error(i.message),i}}),this.name=e?.name||Ml.name,this.metadata=N_(e?.metadata),this.signConfig=e?.signConfig;const n=T1({logger:e?.logger||Ml.logger,name:this.name});this.logger=n,this.core=e?.core||new kl(e),this.session=new Uy(this.core,this.logger),this.proposal=new $D(this.core,this.logger),this.pendingRequest=new PD(this.core,this.logger),this.engine=new DD(this),this.auth=new FD(this.core,this.logger)}static async init(e){const n=new Vl(e);return await n.initialize(),n}get context(){return ft(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")}catch(e){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(e.message),e}}}const qD=Uy,MD=Vl;class jD extends Ve.exports{constructor(){super()}}class Fy{constructor(e){this.opts=e}}class Ly{constructor(e){this.client=e}}var zD=Object.defineProperty,HD=Object.defineProperties,VD=Object.getOwnPropertyDescriptors,ky=Object.getOwnPropertySymbols,KD=Object.prototype.hasOwnProperty,GD=Object.prototype.propertyIsEnumerable,qy=(t,e,n)=>e in t?zD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,WD=(t,e)=>{for(var n in e||(e={}))KD.call(e,n)&&qy(t,n,e[n]);if(ky)for(var n of ky(e))GD.call(e,n)&&qy(t,n,e[n]);return t},ZD=(t,e)=>HD(t,VD(e));class YD extends Ly{constructor(e){super(e),this.init=async()=>{this.signClient=await MD.init({core:this.client.core,metadata:this.client.metadata,signConfig:this.client.signConfig}),this.signClient.core.eventClient.init().catch(n=>{this.client.logger.warn(n)})},this.pair=async n=>{await this.client.core.pairing.pair(n)},this.approveSession=async n=>{const{topic:r,acknowledged:i}=await this.signClient.approve(ZD(WD({},n),{id:n.id,namespaces:n.namespaces,sessionProperties:n.sessionProperties,sessionConfig:n.sessionConfig}));return await i(),this.signClient.session.get(r)},this.rejectSession=async n=>await this.signClient.reject(n),this.updateSession=async n=>await this.signClient.update(n),this.extendSession=async n=>await this.signClient.extend(n),this.respondSessionRequest=async n=>await this.signClient.respond(n),this.disconnectSession=async n=>await this.signClient.disconnect(n),this.emitSessionEvent=async n=>await this.signClient.emit(n),this.getActiveSessions=()=>this.signClient.session.getAll().reduce((n,r)=>(n[r.topic]=r,n),{}),this.getPendingSessionProposals=()=>this.signClient.proposal.getAll(),this.getPendingSessionRequests=()=>this.signClient.getPendingSessionRequests(),this.approveSessionAuthenticate=async n=>await this.signClient.approveSessionAuthenticate(n),this.rejectSessionAuthenticate=async n=>await this.signClient.rejectSessionAuthenticate(n),this.formatAuthMessage=n=>this.signClient.formatAuthMessage(n),this.registerDeviceToken=n=>this.client.core.echoClient.registerDeviceToken(n),this.on=(n,r)=>(this.setEvent(n,"off"),this.setEvent(n,"on"),this.client.events.on(n,r)),this.once=(n,r)=>(this.setEvent(n,"off"),this.setEvent(n,"once"),this.client.events.once(n,r)),this.off=(n,r)=>(this.setEvent(n,"off"),this.client.events.off(n,r)),this.removeListener=(n,r)=>(this.setEvent(n,"removeListener"),this.client.events.removeListener(n,r)),this.onSessionRequest=n=>{this.client.events.emit("session_request",n)},this.onSessionProposal=n=>{this.client.events.emit("session_proposal",n)},this.onSessionDelete=n=>{this.client.events.emit("session_delete",n)},this.onProposalExpire=n=>{this.client.events.emit("proposal_expire",n)},this.onSessionRequestExpire=n=>{this.client.events.emit("session_request_expire",n)},this.onSessionRequestAuthenticate=n=>{this.client.events.emit("session_authenticate",n)},this.setEvent=(n,r)=>{switch(n){case"session_request":this.signClient.events[r]("session_request",this.onSessionRequest);break;case"session_proposal":this.signClient.events[r]("session_proposal",this.onSessionProposal);break;case"session_delete":this.signClient.events[r]("session_delete",this.onSessionDelete);break;case"proposal_expire":this.signClient.events[r]("proposal_expire",this.onProposalExpire);break;case"session_request_expire":this.signClient.events[r]("session_request_expire",this.onSessionRequestExpire);break;case"session_authenticate":this.signClient.events[r]("session_authenticate",this.onSessionRequestAuthenticate);break}},this.signClient={}}}const XD={decryptMessage:async t=>{const e={core:new kl({storageOptions:t.storageOptions,storage:t.storage})};await e.core.crypto.init();const n=e.core.crypto.decode(t.topic,t.encryptedMessage);return e.core=null,n},getMetadata:async t=>{const e={core:new kl({storageOptions:t.storageOptions,storage:t.storage}),sessionStore:null};e.sessionStore=new qD(e.core,e.core.logger),await e.sessionStore.init();const n=e.sessionStore.get(t.topic),r=n?.peer.metadata;return e.core=null,e.sessionStore=null,r}},My=class extends Fy{constructor(t){super(t),this.events=new Ve.exports,this.on=(e,n)=>this.engine.on(e,n),this.once=(e,n)=>this.engine.once(e,n),this.off=(e,n)=>this.engine.off(e,n),this.removeListener=(e,n)=>this.engine.removeListener(e,n),this.pair=async e=>{try{return await this.engine.pair(e)}catch(n){throw this.logger.error(n.message),n}},this.approveSession=async e=>{try{return await this.engine.approveSession(e)}catch(n){throw this.logger.error(n.message),n}},this.rejectSession=async e=>{try{return await this.engine.rejectSession(e)}catch(n){throw this.logger.error(n.message),n}},this.updateSession=async e=>{try{return await this.engine.updateSession(e)}catch(n){throw this.logger.error(n.message),n}},this.extendSession=async e=>{try{return await this.engine.extendSession(e)}catch(n){throw this.logger.error(n.message),n}},this.respondSessionRequest=async e=>{try{return await this.engine.respondSessionRequest(e)}catch(n){throw this.logger.error(n.message),n}},this.disconnectSession=async e=>{try{return await this.engine.disconnectSession(e)}catch(n){throw this.logger.error(n.message),n}},this.emitSessionEvent=async e=>{try{return await this.engine.emitSessionEvent(e)}catch(n){throw this.logger.error(n.message),n}},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(n){throw this.logger.error(n.message),n}},this.approveSessionAuthenticate=e=>{try{return this.engine.approveSessionAuthenticate(e)}catch(n){throw this.logger.error(n.message),n}},this.rejectSessionAuthenticate=e=>{try{return this.engine.rejectSessionAuthenticate(e)}catch(n){throw this.logger.error(n.message),n}},this.formatAuthMessage=e=>{try{return this.engine.formatAuthMessage(e)}catch(n){throw this.logger.error(n.message),n}},this.metadata=t.metadata,this.name=t.name||Oa,this.signConfig=t.signConfig,this.core=t.core,this.logger=this.core.logger,this.engine=new YD(this)}static async init(t){const e=new My(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 Kl=My;Kl.notifications=XD;const JD=Kl;He.CLIENT_CONTEXT=Oa,He.CLIENT_STORAGE_OPTIONS=rb,He.CLIENT_STORAGE_PREFIX=nb,He.IWalletKit=Fy,He.IWalletKitEngine=Ly,He.IWalletKitEvents=jD,He.PROTOCOL=of,He.PROTOCOL_VERSION=tb,He.REQUEST_CONTEXT=ib,He.WalletKit=JD,He.default=Kl,Object.defineProperty(He,"__esModule",{value:!0})});
42
+ ***************************************************************************** */var I0=function(t,e){return I0=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(n,r){n.__proto__=r}||function(n,r){for(var i in r)r.hasOwnProperty(i)&&(n[i]=r[i])},I0(t,e)};function NC(t,e){I0(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var B0=function(){return B0=Object.assign||function(e){for(var n,r=1,i=arguments.length;r<i;r++){n=arguments[r];for(var s in n)Object.prototype.hasOwnProperty.call(n,s)&&(e[s]=n[s])}return e},B0.apply(this,arguments)};function UC(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(t!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,r=Object.getOwnPropertySymbols(t);i<r.length;i++)e.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(t,r[i])&&(n[r[i]]=t[r[i]]);return n}function CC(t,e,n,r){var i=arguments.length,s=i<3?e:r===null?r=Object.getOwnPropertyDescriptor(e,n):r,o;if(typeof Reflect=="object"&&typeof Reflect.decorate=="function")s=Reflect.decorate(t,e,n,r);else for(var a=t.length-1;a>=0;a--)(o=t[a])&&(s=(i<3?o(s):i>3?o(e,n,s):o(e,n))||s);return i>3&&s&&Object.defineProperty(e,n,s),s}function LC(t,e){return function(n,r){e(n,r,t)}}function FC(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function kC(t,e,n,r){function i(s){return s instanceof n?s:new n(function(o){o(s)})}return new(n||(n=Promise))(function(s,o){function a(l){try{f(r.next(l))}catch(h){o(h)}}function c(l){try{f(r.throw(l))}catch(h){o(h)}}function f(l){l.done?s(l.value):i(l.value).then(a,c)}f((r=r.apply(t,e||[])).next())})}function qC(t,e){var n={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},r,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(f){return function(l){return c([f,l])}}function c(f){if(r)throw new TypeError("Generator is already executing.");for(;n;)try{if(r=1,i&&(s=f[0]&2?i.return:f[0]?i.throw||((s=i.return)&&s.call(i),0):i.next)&&!(s=s.call(i,f[1])).done)return s;switch(i=0,s&&(f=[f[0]&2,s.value]),f[0]){case 0:case 1:s=f;break;case 4:return n.label++,{value:f[1],done:!1};case 5:n.label++,i=f[1],f=[0];continue;case 7:f=n.ops.pop(),n.trys.pop();continue;default:if(s=n.trys,!(s=s.length>0&&s[s.length-1])&&(f[0]===6||f[0]===2)){n=0;continue}if(f[0]===3&&(!s||f[1]>s[0]&&f[1]<s[3])){n.label=f[1];break}if(f[0]===6&&n.label<s[1]){n.label=s[1],s=f;break}if(s&&n.label<s[2]){n.label=s[2],n.ops.push(f);break}s[2]&&n.ops.pop(),n.trys.pop();continue}f=e.call(t,n)}catch(l){f=[6,l],i=0}finally{r=s=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}function jC(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]}function MC(t,e){for(var n in t)n!=="default"&&!e.hasOwnProperty(n)&&(e[n]=t[n])}function $0(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function v8(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,s=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)s.push(i.value)}catch(a){o={error:a}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return s}function zC(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(v8(arguments[e]));return t}function HC(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;for(var r=Array(t),i=0,e=0;e<n;e++)for(var s=arguments[e],o=0,a=s.length;o<a;o++,i++)r[i]=s[o];return r}function Ga(t){return this instanceof Ga?(this.v=t,this):new Ga(t)}function VC(t,e,n){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var r=n.apply(t,e||[]),i,s=[];return i={},o("next"),o("throw"),o("return"),i[Symbol.asyncIterator]=function(){return this},i;function o(d){r[d]&&(i[d]=function(u){return new Promise(function(b,w){s.push([d,u,b,w])>1||a(d,u)})})}function a(d,u){try{c(r[d](u))}catch(b){h(s[0][3],b)}}function c(d){d.value instanceof Ga?Promise.resolve(d.value.v).then(f,l):h(s[0][2],d)}function f(d){a("next",d)}function l(d){a("throw",d)}function h(d,u){d(u),s.shift(),s.length&&a(s[0][0],s[0][1])}}function KC(t){var e,n;return e={},r("next"),r("throw",function(i){throw i}),r("return"),e[Symbol.iterator]=function(){return this},e;function r(i,s){e[i]=t[i]?function(o){return(n=!n)?{value:Ga(t[i](o)),done:i==="return"}:s?s(o):o}:s}}function GC(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e=t[Symbol.asyncIterator],n;return e?e.call(t):(t=typeof $0=="function"?$0(t):t[Symbol.iterator](),n={},r("next"),r("throw"),r("return"),n[Symbol.asyncIterator]=function(){return this},n);function r(s){n[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(f){s({value:f,done:a})},o)}}function ZC(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function WC(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var n in t)Object.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e.default=t,e}function YC(t){return t&&t.__esModule?t:{default:t}}function XC(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function JC(t,e,n){if(!e.has(t))throw new TypeError("attempted to set private field on non-instance");return e.set(t,n),n}var QC=Object.freeze({__proto__:null,__extends:NC,get __assign(){return B0},__rest:UC,__decorate:CC,__param:LC,__metadata:FC,__awaiter:kC,__generator:qC,__createBinding:jC,__exportStar:MC,__values:$0,__read:v8,__spread:zC,__spreadArrays:HC,__await:Ga,__asyncGenerator:VC,__asyncDelegator:KC,__asyncValues:GC,__makeTemplateObject:ZC,__importStar:WC,__importDefault:YC,__classPrivateFieldGet:XC,__classPrivateFieldSet:JC}),eL=e1(QC),Ur={},E8;function tL(){if(E8)return Ur;E8=1,Object.defineProperty(Ur,"__esModule",{value:!0}),Ur.isBrowserCryptoAvailable=Ur.getSubtleCrypto=Ur.getBrowerCrypto=void 0;function t(){return kn?.crypto||kn?.msCrypto||{}}Ur.getBrowerCrypto=t;function e(){const r=t();return r.subtle||r.webkitSubtle}Ur.getSubtleCrypto=e;function n(){return!!t()&&!!e()}return Ur.isBrowserCryptoAvailable=n,Ur}var Cr={},x8;function nL(){if(x8)return Cr;x8=1,Object.defineProperty(Cr,"__esModule",{value:!0}),Cr.isBrowser=Cr.isNode=Cr.isReactNative=void 0;function t(){return typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"}Cr.isReactNative=t;function e(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}Cr.isNode=e;function n(){return!t()&&!e()}return Cr.isBrowser=n,Cr}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=eL;e.__exportStar(tL(),t),e.__exportStar(nL(),t)})(m8);function Wn(t=3){const e=Date.now()*Math.pow(10,t),n=Math.floor(Math.random()*Math.pow(10,t));return e+n}function Zi(t=6){return BigInt(Wn(t))}function Lr(t,e,n){return{id:n||Wn(),jsonrpc:"2.0",method:t,params:e}}function gu(t,e){return{id:t,jsonrpc:"2.0",result:e}}function A0(t,e,n){return{id:t,jsonrpc:"2.0",error:rL(e,n)}}function rL(t,e){return typeof t>"u"?w8(b8):(typeof t=="string"&&(t=Object.assign(Object.assign({},w8(S0)),{message:t})),typeof e<"u"&&(t.data=e),PC(t.code)&&(t=RC(t.code)),t)}class iL{}class sL extends iL{constructor(){super()}}class oL extends sL{constructor(e){super()}}const aL="^wss?:";function cL(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function fL(t,e){const n=cL(t);return typeof n>"u"?!1:new RegExp(e).test(n)}function _8(t){return fL(t,aL)}function uL(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function S8(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function O0(t){return S8(t)&&"method"in t}function bu(t){return S8(t)&&(Yn(t)||wn(t))}function Yn(t){return"result"in t}function wn(t){return"error"in t}class lL extends oL{constructor(e){super(e),this.events=new at.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,n){this.events.on(e,n)}once(e,n){this.events.once(e,n)}off(e,n){this.events.off(e,n)}removeListener(e,n){this.events.removeListener(e,n)}async request(e,n){return this.requestStrict(Lr(e.method,e.params||[],e.id||Zi().toString()),n)}async requestStrict(e,n){return new Promise(async(r,i)=>{if(!this.connection.connected)try{await this.open()}catch(s){i(s)}this.events.on(`${e.id}`,s=>{wn(s)?i(s.error):r(s.result)});try{await this.connection.send(e,n)}catch(s){i(s)}})}setConnection(e=this.connection){return e}onPayload(e){this.events.emit("payload",e),bu(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 hL=()=>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"),dL=()=>typeof WebSocket<"u"||typeof global<"u"&&typeof global.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",I8=t=>t.split("?")[0],B8=10,pL=hL();class gL{constructor(e){if(this.url=e,this.events=new at.exports.EventEmitter,this.registering=!1,!_8(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,n){this.events.on(e,n)}once(e,n){this.events.once(e,n)}off(e,n){this.events.off(e,n)}removeListener(e,n){this.events.removeListener(e,n)}async open(e=this.url){await this.register(e)}async close(){return new Promise((e,n)=>{if(typeof this.socket>"u"){n(new Error("Connection already closed"));return}this.socket.onclose=r=>{this.onClose(r),e()},this.socket.close()})}async send(e){typeof this.socket>"u"&&(this.socket=await this.register());try{this.socket.send(na(e))}catch(n){this.onError(e.id,n)}}register(e=this.url){if(!_8(e))throw new Error(`Provided URL is not compatible with WebSocket connection: ${e}`);if(this.registering){const n=this.events.getMaxListeners();return(this.events.listenerCount("register_error")>=n||this.events.listenerCount("open")>=n)&&this.events.setMaxListeners(n+1),new Promise((r,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"));r(this.socket)})})}return this.url=e,this.registering=!0,new Promise((n,r)=>{const i=m8.isReactNative()?void 0:{rejectUnauthorized:!uL(e)},s=new pL(e,[],i);dL()?s.onerror=o=>{const a=o;r(this.emitError(a.error))}:s.on("error",o=>{r(this.emitError(o))}),s.onopen=()=>{this.onOpen(s),n(s)}})}onOpen(e){e.onmessage=n=>this.onPayload(n),e.onclose=n=>this.onClose(n),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 n=typeof e.data=="string"?Qs(e.data):e.data;this.events.emit("payload",n)}onError(e,n){const r=this.parseError(n),i=r.message||r.toString(),s=A0(e,i);this.events.emit("payload",s)}parseError(e,n=this.url){return TC(e,I8(n),"WS")}resetMaxListeners(){this.events.getMaxListeners()>B8&&this.events.setMaxListeners(B8)}emitError(e){const n=this.parseError(new Error(e?.message||`WebSocket connection failed for host: ${I8(this.url)}`));return this.events.emit("register_error",n),n}}const $8="wc",A8=2,yu="core",Xn=`${$8}@2:${yu}:`,bL={name:yu,logger:"error"},yL={database:":memory:"},wL="crypto",O8="client_ed25519_seed",mL=Z.ONE_DAY,vL="keychain",EL="0.3",xL="messages",_L="0.3",SL=Z.SIX_HOURS,IL="publisher",D8="irn",BL="error",P8="wss://relay.walletconnect.org",$L="relayer",Ue={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"},AL="_subscription",mn={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},OL=.1,D0="2.23.3",Ae={link_mode:"link_mode",relay:"relay"},wu={inbound:"inbound",outbound:"outbound"},DL="0.3",PL="WALLETCONNECT_CLIENT_ID",R8="WALLETCONNECT_LINK_MODE_APPS",cn={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},RL="subscription",TL="0.3",NL="pairing",UL="0.3",Za={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}}},Ds={create:"pairing_create",expire:"pairing_expire",delete:"pairing_delete",ping:"pairing_ping"},Ln={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},CL="history",LL="0.3",FL="expirer",vn={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},kL="0.3",qL="verify-api",jL="https://verify.walletconnect.com",T8="https://verify.walletconnect.org",Wa=T8,ML=`${Wa}/v3`,zL=[jL,T8],HL="echo",VL="https://echo.walletconnect.com",Jn={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"},Fr={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"},Fn={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",session_request_response_started:"session_request_response_started",session_request_response_validation_success:"session_request_response_validation_success",session_request_response_publish_started:"session_request_response_publish_started"},Ps={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",session_request_response_validation_failure:"session_request_response_validation_failure",session_request_response_publish_failure:"session_request_response_publish_failure"},Rs={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"},Ya={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"},KL=.1,GL="event-client",ZL=86400,WL="https://pulse.walletconnect.org/batch";function YL(t,e){if(t.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),r=0;r<n.length;r++)n[r]=255;for(var i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(n[o]!==255)throw new TypeError(s+" is ambiguous");n[o]=i}var a=t.length,c=t.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function h(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var w=0,E=0,A=0,P=b.length;A!==P&&b[A]===0;)A++,w++;for(var _=(P-A)*l+1>>>0,x=new Uint8Array(_);A!==P;){for(var D=b[A],U=0,C=_-1;(D!==0||U<E)&&C!==-1;C--,U++)D+=256*x[C]>>>0,x[C]=D%a>>>0,D=D/a>>>0;if(D!==0)throw new Error("Non-zero carry");E=U,A++}for(var L=_-E;L!==_&&x[L]===0;)L++;for(var O=c.repeat(w);L<_;++L)O+=t.charAt(x[L]);return O}function d(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var w=0;if(b[w]!==" "){for(var E=0,A=0;b[w]===c;)E++,w++;for(var P=(b.length-w)*f+1>>>0,_=new Uint8Array(P);b[w];){var x=n[b.charCodeAt(w)];if(x===255)return;for(var D=0,U=P-1;(x!==0||D<A)&&U!==-1;U--,D++)x+=a*_[U]>>>0,_[U]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");A=D,w++}if(b[w]!==" "){for(var C=P-A;C!==P&&_[C]===0;)C++;for(var L=new Uint8Array(E+(P-C)),O=E;C!==P;)L[O++]=_[C++];return L}}}function u(b){var w=d(b);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:d,decode:u}}var XL=YL,JL=XL;const N8=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")},QL=t=>new TextEncoder().encode(t),eF=t=>new TextDecoder().decode(t);class tF{constructor(e,n,r){this.name=e,this.prefix=n,this.baseEncode=r}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}}class nF{constructor(e,n,r){if(this.name=e,this.prefix=n,n.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=n.codePointAt(0),this.baseDecode=r}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 U8(this,e)}}class rF{constructor(e){this.decoders=e}or(e){return U8(this,e)}decode(e){const n=e[0],r=this.decoders[n];if(r)return r.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}}const U8=(t,e)=>new rF({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class iF{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new tF(e,n,r),this.decoder=new nF(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const mu=({name:t,prefix:e,encode:n,decode:r})=>new iF(t,e,n,r),Xa=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=JL(n,e);return mu({prefix:t,name:e,encode:r,decode:s=>N8(i(s))})},sF=(t,e,n,r)=>{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*n/8|0);let a=0,c=0,f=0;for(let l=0;l<s;++l){const h=i[t[l]];if(h===void 0)throw new SyntaxError(`Non-${r} character`);c=c<<n|h,a+=n,a>=8&&(a-=8,o[f++]=255&c>>a)}if(a>=n||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o},oF=(t,e,n)=>{const r=e[e.length-1]==="=",i=(1<<n)-1;let s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>n;)o-=n,s+=e[i&a>>o];if(o&&(s+=e[i&a<<n-o]),r)for(;s.length*n&7;)s+="=";return s},nt=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>mu({prefix:e,name:t,encode(i){return oF(i,r,n)},decode(i){return sF(i,r,n,t)}}),aF=mu({prefix:"\0",name:"identity",encode:t=>eF(t),decode:t=>QL(t)});var cF=Object.freeze({__proto__:null,identity:aF});const fF=nt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var uF=Object.freeze({__proto__:null,base2:fF});const lF=nt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var hF=Object.freeze({__proto__:null,base8:lF});const dF=Xa({prefix:"9",name:"base10",alphabet:"0123456789"});var pF=Object.freeze({__proto__:null,base10:dF});const gF=nt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),bF=nt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var yF=Object.freeze({__proto__:null,base16:gF,base16upper:bF});const wF=nt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),mF=nt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),vF=nt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),EF=nt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),xF=nt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),_F=nt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),SF=nt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),IF=nt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),BF=nt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var $F=Object.freeze({__proto__:null,base32:wF,base32upper:mF,base32pad:vF,base32padupper:EF,base32hex:xF,base32hexupper:_F,base32hexpad:SF,base32hexpadupper:IF,base32z:BF});const AF=Xa({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),OF=Xa({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var DF=Object.freeze({__proto__:null,base36:AF,base36upper:OF});const PF=Xa({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),RF=Xa({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var TF=Object.freeze({__proto__:null,base58btc:PF,base58flickr:RF});const NF=nt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),UF=nt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),CF=nt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),LF=nt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var FF=Object.freeze({__proto__:null,base64:NF,base64pad:UF,base64url:CF,base64urlpad:LF});const C8=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}"),kF=C8.reduce((t,e,n)=>(t[n]=e,t),[]),qF=C8.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function jF(t){return t.reduce((e,n)=>(e+=kF[n],e),"")}function MF(t){const e=[];for(const n of t){const r=qF[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const zF=mu({prefix:"\u{1F680}",name:"base256emoji",encode:jF,decode:MF});var HF=Object.freeze({__proto__:null,base256emoji:zF}),VF=F8,L8=128,KF=127,GF=~KF,ZF=Math.pow(2,31);function F8(t,e,n){e=e||[],n=n||0;for(var r=n;t>=ZF;)e[n++]=t&255|L8,t/=128;for(;t&GF;)e[n++]=t&255|L8,t>>>=7;return e[n]=t|0,F8.bytes=n-r+1,e}var WF=P0,YF=128,k8=127;function P0(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw P0.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&k8)<<i:(o&k8)*Math.pow(2,i),i+=7}while(o>=YF);return P0.bytes=s-r,n}var XF=Math.pow(2,7),JF=Math.pow(2,14),QF=Math.pow(2,21),ek=Math.pow(2,28),tk=Math.pow(2,35),nk=Math.pow(2,42),rk=Math.pow(2,49),ik=Math.pow(2,56),sk=Math.pow(2,63),ok=function(t){return t<XF?1:t<JF?2:t<QF?3:t<ek?4:t<tk?5:t<nk?6:t<rk?7:t<ik?8:t<sk?9:10},ak={encode:VF,decode:WF,encodingLength:ok},q8=ak;const j8=(t,e,n=0)=>(q8.encode(t,e,n),e),M8=t=>q8.encodingLength(t),R0=(t,e)=>{const n=e.byteLength,r=M8(t),i=r+M8(n),s=new Uint8Array(i+n);return j8(t,s,0),j8(n,s,r),s.set(e,i),new ck(t,n,e,s)};class ck{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const z8=({name:t,code:e,encode:n})=>new fk(t,e,n);class fk{constructor(e,n,r){this.name=e,this.code=n,this.encode=r}digest(e){if(e instanceof Uint8Array){const n=this.encode(e);return n instanceof Uint8Array?R0(this.code,n):n.then(r=>R0(this.code,r))}else throw Error("Unknown type, must be binary type")}}const H8=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),uk=z8({name:"sha2-256",code:18,encode:H8("SHA-256")}),lk=z8({name:"sha2-512",code:19,encode:H8("SHA-512")});var hk=Object.freeze({__proto__:null,sha256:uk,sha512:lk});const V8=0,dk="identity",K8=N8;var pk=Object.freeze({__proto__:null,identity:{code:V8,name:dk,encode:K8,digest:t=>R0(V8,K8(t))}});new TextEncoder,new TextDecoder;const G8={...cF,...uF,...hF,...pF,...yF,...$F,...DF,...TF,...FF,...HF};({...hk,...pk});function Z8(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function gk(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Z8(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function W8(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const Y8=W8("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),T0=W8("ascii","a",t=>{let e="a";for(let n=0;n<t.length;n++)e+=String.fromCharCode(t[n]);return e},t=>{t=t.substring(1);const e=gk(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),bk={utf8:Y8,"utf-8":Y8,hex:G8.base16,latin1:T0,ascii:T0,binary:T0,...G8};function yk(t,e="utf8"){const n=bk[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Z8(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}var wk=Object.defineProperty,mk=(t,e,n)=>e in t?wk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Qn=(t,e,n)=>mk(t,typeof e!="symbol"?e+"":e,n);class vk{constructor(e,n){this.core=e,this.logger=n,Qn(this,"keychain",new Map),Qn(this,"name",vL),Qn(this,"version",EL),Qn(this,"initialized",!1),Qn(this,"storagePrefix",Xn),Qn(this,"init",async()=>{if(!this.initialized){const r=await this.getKeyChain();typeof r<"u"&&(this.keychain=r),this.initialized=!0}}),Qn(this,"has",r=>(this.isInitialized(),this.keychain.has(r))),Qn(this,"set",async(r,i)=>{this.isInitialized(),this.keychain.set(r,i),await this.persist()}),Qn(this,"get",r=>{this.isInitialized();const i=this.keychain.get(r);if(typeof i>"u"){const{message:s}=W("NO_MATCHING_KEY",`${this.name}: ${r}`);throw new Error(s)}return i}),Qn(this,"del",async r=>{this.isInitialized(),this.keychain.delete(r),await this.persist()}),this.core=e,this.logger=sn(n,this.name)}get context(){return Gt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,kd(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?qd(e):void 0}async persist(){await this.setKeyChain(this.keychain)}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}}var Ek=Object.defineProperty,xk=(t,e,n)=>e in t?Ek(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ze=(t,e,n)=>xk(t,typeof e!="symbol"?e+"":e,n);class _k{constructor(e,n,r){this.core=e,this.logger=n,Ze(this,"name",wL),Ze(this,"keychain"),Ze(this,"randomSessionIdentifier",w0()),Ze(this,"initialized",!1),Ze(this,"clientId"),Ze(this,"init",async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)}),Ze(this,"hasKeys",i=>(this.isInitialized(),this.keychain.has(i))),Ze(this,"getClientId",async()=>{if(this.isInitialized(),this.clientId)return this.clientId;const i=await this.getClientSeed(),s=Mb(i),o=jb(s.publicKey);return this.clientId=o,o}),Ze(this,"generateKeyPair",()=>{this.isInitialized();const i=aU();return this.setPrivateKey(i.publicKey,i.privateKey)}),Ze(this,"signJWT",async i=>{this.isInitialized();const s=await this.getClientSeed(),o=Mb(s),a=this.randomSessionIdentifier;return await H_(a,i,mL,o)}),Ze(this,"generateSharedKey",(i,s,o)=>{this.isInitialized();const a=this.getPrivateKey(i),c=cU(a,s);return this.setSymKey(c,o)}),Ze(this,"setSymKey",async(i,s)=>{this.isInitialized();const o=s||lu(i);return await this.keychain.set(o,i),o}),Ze(this,"deleteKeyPair",async i=>{this.isInitialized(),await this.keychain.del(i)}),Ze(this,"deleteSymKey",async i=>{this.isInitialized(),await this.keychain.del(i)}),Ze(this,"encode",async(i,s,o)=>{this.isInitialized();const a=W3(o),c=na(s);if(X3(a))return lU(c,o?.encoding);if(Y3(a)){const d=a.senderPublicKey,u=a.receiverPublicKey;i=await this.generateSharedKey(d,u)}const f=this.getSymKey(i),{type:l,senderPublicKey:h}=a;return fU({type:l,symKey:f,message:c,senderPublicKey:h,encoding:o?.encoding})}),Ze(this,"decode",async(i,s,o)=>{this.isInitialized();const a=dU(s,o);if(X3(a)){const c=hU(s,o?.encoding);return Qs(c)}if(Y3(a)){const c=a.receiverPublicKey,f=a.senderPublicKey;i=await this.generateSharedKey(c,f)}try{const c=this.getSymKey(i),f=uU({symKey:c,encoded:s,encoding:o?.encoding});return Qs(f)}catch(c){this.logger.error(`Failed to decode message from topic: '${i}', clientId: '${await this.getClientId()}'`),this.logger.error(c)}}),Ze(this,"getPayloadType",(i,s=Xt)=>{const o=za({encoded:i,encoding:s});return Os(o.type)}),Ze(this,"getPayloadSenderPublicKey",(i,s=Xt)=>{const o=za({encoded:i,encoding:s});return o.senderPublicKey?zt(o.senderPublicKey,Lt):void 0}),this.core=e,this.logger=sn(n,this.name),this.keychain=r||new vk(this.core,this.logger)}get context(){return Gt(this.logger)}async setPrivateKey(e,n){return await this.keychain.set(e,n),e}getPrivateKey(e){return this.keychain.get(e)}async getClientSeed(){let e="";try{e=this.keychain.get(O8)}catch{e=w0(),await this.keychain.set(O8,e)}return yk(e,"base16")}getSymKey(e){return this.keychain.get(e)}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}}var Sk=Object.defineProperty,Ik=Object.defineProperties,Bk=Object.getOwnPropertyDescriptors,X8=Object.getOwnPropertySymbols,$k=Object.prototype.hasOwnProperty,Ak=Object.prototype.propertyIsEnumerable,N0=(t,e,n)=>e in t?Sk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ok=(t,e)=>{for(var n in e||(e={}))$k.call(e,n)&&N0(t,n,e[n]);if(X8)for(var n of X8(e))Ak.call(e,n)&&N0(t,n,e[n]);return t},Dk=(t,e)=>Ik(t,Bk(e)),fn=(t,e,n)=>N0(t,typeof e!="symbol"?e+"":e,n);class Pk extends pO{constructor(e,n){super(e,n),this.logger=e,this.core=n,fn(this,"messages",new Map),fn(this,"messagesWithoutClientAck",new Map),fn(this,"name",xL),fn(this,"version",_L),fn(this,"initialized",!1),fn(this,"storagePrefix",Xn),fn(this,"init",async()=>{if(!this.initialized){this.logger.trace("Initialized");try{const r=await this.getRelayerMessages();typeof r<"u"&&(this.messages=r);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(r){this.logger.debug(`Failed to Restore records for ${this.name}`),this.logger.error(r)}finally{this.initialized=!0}}}),fn(this,"set",async(r,i,s)=>{this.isInitialized();const o=yn(i);let a=this.messages.get(r);if(typeof a>"u"&&(a={}),typeof a[o]<"u")return o;if(a[o]=i,this.messages.set(r,a),s===wu.inbound){const c=this.messagesWithoutClientAck.get(r)||{};this.messagesWithoutClientAck.set(r,Dk(Ok({},c),{[o]:i}))}return await this.persist(),o}),fn(this,"get",r=>{this.isInitialized();let i=this.messages.get(r);return typeof i>"u"&&(i={}),i}),fn(this,"getWithoutAck",r=>{this.isInitialized();const i={};for(const s of r){const o=this.messagesWithoutClientAck.get(s)||{};i[s]=Object.values(o)}return i}),fn(this,"has",(r,i)=>{this.isInitialized();const s=this.get(r),o=yn(i);return typeof s[o]<"u"}),fn(this,"ack",async(r,i)=>{this.isInitialized();const s=this.messagesWithoutClientAck.get(r);if(typeof s>"u")return;const o=yn(i);delete s[o],Object.keys(s).length===0?this.messagesWithoutClientAck.delete(r):this.messagesWithoutClientAck.set(r,s),await this.persist()}),fn(this,"del",async r=>{this.isInitialized(),this.messages.delete(r),this.messagesWithoutClientAck.delete(r),await this.persist()}),this.logger=sn(e,this.name),this.core=n}get context(){return Gt(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,kd(e))}async setRelayerMessagesWithoutClientAck(e){await this.core.storage.setItem(this.storageKeyWithoutClientAck,kd(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?qd(e):void 0}async getRelayerMessagesWithoutClientAck(){const e=await this.core.storage.getItem(this.storageKeyWithoutClientAck);return typeof e<"u"?qd(e):void 0}async persist(){await this.setRelayerMessages(this.messages),await this.setRelayerMessagesWithoutClientAck(this.messagesWithoutClientAck)}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}}var Rk=Object.defineProperty,Tk=Object.defineProperties,Nk=Object.getOwnPropertyDescriptors,J8=Object.getOwnPropertySymbols,Uk=Object.prototype.hasOwnProperty,Ck=Object.prototype.propertyIsEnumerable,U0=(t,e,n)=>e in t?Rk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Oo=(t,e)=>{for(var n in e||(e={}))Uk.call(e,n)&&U0(t,n,e[n]);if(J8)for(var n of J8(e))Ck.call(e,n)&&U0(t,n,e[n]);return t},Q8=(t,e)=>Tk(t,Nk(e)),En=(t,e,n)=>U0(t,typeof e!="symbol"?e+"":e,n);class Lk extends gO{constructor(e,n){super(e,n),this.relayer=e,this.logger=n,En(this,"events",new at.exports.EventEmitter),En(this,"name",IL),En(this,"queue",new Map),En(this,"publishTimeout",Z.toMiliseconds(Z.ONE_MINUTE)),En(this,"initialPublishTimeout",Z.toMiliseconds(Z.ONE_SECOND*15)),En(this,"needsTransportRestart",!1),En(this,"publish",async(r,i,s)=>{var o,a,c,f,l;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:r,message:i,opts:s}});const h=s?.ttl||SL,d=s?.prompt||!1,u=s?.tag||0,b=s?.id||Zi().toString(),w=Bo(hu().protocol),E={id:b,method:s?.publishMethod||w.publish,params:Oo({topic:r,message:i,ttl:h,prompt:d,tag:u,attestation:s?.attestation},s?.tvf)},A=`Failed to publish payload, please try again. id:${b} tag:${u}`;try{ze((o=E.params)==null?void 0:o.prompt)&&((a=E.params)==null||delete a.prompt),ze((c=E.params)==null?void 0:c.tag)&&((f=E.params)==null||delete f.tag);const P=new Promise(async _=>{const x=({id:U})=>{var C;((C=E.id)==null?void 0:C.toString())===U.toString()&&(this.removeRequestFromQueue(U),this.relayer.events.removeListener(Ue.publish,x),_())};this.relayer.events.on(Ue.publish,x);const D=Gn(new Promise((U,C)=>{this.rpcPublish(E,s).then(U).catch(L=>{this.logger.warn(L,L?.message),C(L)})}),this.initialPublishTimeout,`Failed initial publish, retrying.... id:${b} tag:${u}`);try{await D,this.events.removeListener(Ue.publish,x)}catch(U){this.queue.set(b,{request:E,opts:s,attempt:1}),this.logger.warn(U,U?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:b,topic:r,message:i,opts:s}}),await Gn(P,this.publishTimeout,A)}catch(P){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(P),(l=s?.internal)!=null&&l.throwOnFailedPublish)throw P}finally{this.queue.delete(b)}}),En(this,"publishCustom",async r=>{var i,s,o,a,c;this.logger.debug("Publishing custom payload"),this.logger.trace({type:"method",method:"publishCustom",params:r});const{payload:f,opts:l={}}=r,{attestation:h,tvf:d,publishMethod:u,prompt:b,tag:w,ttl:E=Z.FIVE_MINUTES}=l,A=l.id||Zi().toString(),P=Bo(hu().protocol),_=u||P.publish,x={id:A,method:_,params:Oo(Q8(Oo({},f),{ttl:E,prompt:b,tag:w,attestation:h}),d)},D=`Failed to publish custom payload, please try again. id:${A} tag:${w}`;try{ze((i=x.params)==null?void 0:i.prompt)&&((s=x.params)==null||delete s.prompt),ze((o=x.params)==null?void 0:o.tag)&&((a=x.params)==null||delete a.tag);const U=new Promise(async C=>{const L=({id:M})=>{var q;((q=x.id)==null?void 0:q.toString())===M.toString()&&(this.removeRequestFromQueue(M),this.relayer.events.removeListener(Ue.publish,L),C())};this.relayer.events.on(Ue.publish,L);const O=Gn(new Promise((M,q)=>{this.rpcPublish(x,l).then(M).catch(y=>{this.logger.warn(y,y?.message),q(y)})}),this.initialPublishTimeout,`Failed initial custom payload publish, retrying.... method:${_} id:${A} tag:${w}`);try{await O,this.events.removeListener(Ue.publish,L)}catch(M){this.queue.set(A,{request:x,opts:l,attempt:1}),this.logger.warn(M,M?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:A,payload:f,opts:l}}),await Gn(U,this.publishTimeout,D)}catch(U){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(U),(c=l?.internal)!=null&&c.throwOnFailedPublish)throw U}finally{this.queue.delete(A)}}),En(this,"on",(r,i)=>{this.events.on(r,i)}),En(this,"once",(r,i)=>{this.events.once(r,i)}),En(this,"off",(r,i)=>{this.events.off(r,i)}),En(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),this.relayer=e,this.logger=sn(n,this.name),this.registerEventListeners()}get context(){return Gt(this.logger)}async rpcPublish(e,n){this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"message",direction:"outgoing",request:e});const r=await this.relayer.request(e);return this.relayer.events.emit(Ue.publish,Oo(Oo({},e),n)),this.logger.debug("Successfully Published Payload"),r}removeRequestFromQueue(e){this.queue.delete(e)}checkQueue(){this.queue.forEach(async(e,n)=>{var r;const i=e.attempt+1;this.queue.set(n,Q8(Oo({},e),{attempt:i})),this.logger.warn({},`Publisher: queue->publishing: ${e.request.id}, tag: ${(r=e.request.params)==null?void 0:r.tag}, attempt: ${i}`),await this.rpcPublish(e.request,e.opts),this.logger.warn({},`Publisher: queue->published: ${e.request.id}`)})}registerEventListeners(){this.relayer.core.heartbeat.on(ds.pulse,()=>{if(this.needsTransportRestart){this.needsTransportRestart=!1,this.relayer.events.emit(Ue.connection_stalled);return}this.checkQueue()}),this.relayer.on(Ue.message_ack,e=>{this.removeRequestFromQueue(e.id.toString())})}}var Fk=Object.defineProperty,kk=(t,e,n)=>e in t?Fk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Do=(t,e,n)=>kk(t,typeof e!="symbol"?e+"":e,n);class qk{constructor(){Do(this,"map",new Map),Do(this,"set",(e,n)=>{const r=this.get(e);this.exists(e,n)||this.map.set(e,[...r,n])}),Do(this,"get",e=>this.map.get(e)||[]),Do(this,"exists",(e,n)=>this.get(e).includes(n)),Do(this,"delete",(e,n)=>{if(typeof n>"u"){this.map.delete(e);return}if(!this.map.has(e))return;const r=this.get(e);if(!this.exists(e,n))return;const i=r.filter(s=>s!==n);if(!i.length){this.map.delete(e);return}this.map.set(e,i)}),Do(this,"clear",()=>{this.map.clear()})}get topics(){return Array.from(this.map.keys())}}var jk=Object.defineProperty,Mk=Object.defineProperties,zk=Object.getOwnPropertyDescriptors,ev=Object.getOwnPropertySymbols,Hk=Object.prototype.hasOwnProperty,Vk=Object.prototype.propertyIsEnumerable,C0=(t,e,n)=>e in t?jk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ja=(t,e)=>{for(var n in e||(e={}))Hk.call(e,n)&&C0(t,n,e[n]);if(ev)for(var n of ev(e))Vk.call(e,n)&&C0(t,n,e[n]);return t},L0=(t,e)=>Mk(t,zk(e)),Ie=(t,e,n)=>C0(t,typeof e!="symbol"?e+"":e,n);class Kk extends wO{constructor(e,n){super(e,n),this.relayer=e,this.logger=n,Ie(this,"subscriptions",new Map),Ie(this,"topicMap",new qk),Ie(this,"events",new at.exports.EventEmitter),Ie(this,"name",RL),Ie(this,"version",TL),Ie(this,"pending",new Map),Ie(this,"cached",[]),Ie(this,"initialized",!1),Ie(this,"storagePrefix",Xn),Ie(this,"subscribeTimeout",Z.toMiliseconds(Z.ONE_MINUTE)),Ie(this,"initialSubscribeTimeout",Z.toMiliseconds(Z.ONE_SECOND*15)),Ie(this,"clientId"),Ie(this,"batchSubscribeTopicsLimit",500),Ie(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),await this.restore()),this.initialized=!0}),Ie(this,"subscribe",async(r,i)=>{var s;this.isInitialized(),this.logger.debug("Subscribing Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:r,opts:i}});try{const o=hu(i),a={topic:r,relay:o,transportType:i?.transportType};(s=i?.internal)!=null&&s.skipSubscribe||this.pending.set(r,a);const c=await this.rpcSubscribe(r,o,i);return typeof c=="string"&&(this.onSubscribe(c,a),this.logger.debug("Successfully Subscribed Topic"),this.logger.trace({type:"method",method:"subscribe",params:{topic:r,opts:i}})),c}catch(o){throw this.logger.debug("Failed to Subscribe Topic"),this.logger.error(o),o}}),Ie(this,"unsubscribe",async(r,i)=>{this.isInitialized(),typeof i?.id<"u"?await this.unsubscribeById(r,i.id,i):await this.unsubscribeByTopic(r,i)}),Ie(this,"isSubscribed",r=>new Promise(i=>{i(this.topicMap.topics.includes(r))})),Ie(this,"isKnownTopic",r=>new Promise(i=>{i(this.topicMap.topics.includes(r)||this.pending.has(r)||this.cached.some(s=>s.topic===r))})),Ie(this,"on",(r,i)=>{this.events.on(r,i)}),Ie(this,"once",(r,i)=>{this.events.once(r,i)}),Ie(this,"off",(r,i)=>{this.events.off(r,i)}),Ie(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),Ie(this,"start",async()=>{await this.onConnect()}),Ie(this,"stop",async()=>{await this.onDisconnect()}),Ie(this,"restart",async()=>{await this.restore(),await this.onRestart()}),Ie(this,"checkPending",async()=>{if(this.pending.size===0&&(!this.initialized||!this.relayer.connected))return;const r=[];this.pending.forEach(i=>{r.push(i)}),await this.batchSubscribe(r)}),Ie(this,"registerEventListeners",()=>{this.relayer.core.heartbeat.on(ds.pulse,async()=>{await this.checkPending()}),this.events.on(cn.created,async r=>{const i=cn.created;this.logger.info(`Emitting ${i}`),this.logger.debug({type:"event",event:i,data:r}),await this.persist()}),this.events.on(cn.deleted,async r=>{const i=cn.deleted;this.logger.info(`Emitting ${i}`),this.logger.debug({type:"event",event:i,data:r}),await this.persist()})}),this.relayer=e,this.logger=sn(n,this.name),this.clientId=""}get context(){return Gt(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,n){let r=!1;try{r=this.getSubscription(e).topic===n}catch{}return r}reset(){this.cached=[],this.initialized=!0}onDisable(){this.values.length>0&&(this.cached=this.values),this.subscriptions.clear(),this.topicMap.clear()}async unsubscribeByTopic(e,n){const r=this.topicMap.get(e);await Promise.all(r.map(async i=>await this.unsubscribeById(e,i,n)))}async unsubscribeById(e,n,r){this.logger.debug("Unsubscribing Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:n,opts:r}});try{const i=hu(r);await this.restartToComplete({topic:e,id:n,relay:i}),await this.rpcUnsubscribe(e,n,i);const s=Oe("USER_DISCONNECTED",`${this.name}, ${e}`);await this.onUnsubscribe(e,n,s),this.logger.debug("Successfully Unsubscribed Topic"),this.logger.trace({type:"method",method:"unsubscribe",params:{topic:e,id:n,opts:r}})}catch(i){throw this.logger.debug("Failed to Unsubscribe Topic"),this.logger.error(i),i}}async rpcSubscribe(e,n,r){var i,s;const o=await this.getSubscriptionId(e);if((i=r?.internal)!=null&&i.skipSubscribe)return o;(!r||r?.transportType===Ae.relay)&&await this.restartToComplete({topic:e,id:e,relay:n});const a={method:Bo(n.protocol).subscribe,params:{topic:e}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:a});const c=(s=r?.internal)==null?void 0:s.throwOnFailedPublish;try{if(r?.transportType===Ae.link_mode)return setTimeout(()=>{(this.relayer.connected||this.relayer.connecting)&&this.relayer.request(a).catch(h=>this.logger.warn(h))},Z.toMiliseconds(Z.ONE_SECOND)),o;const f=new Promise(async h=>{const d=u=>{u.topic===e&&(this.events.removeListener(cn.created,d),h(u.id))};this.events.on(cn.created,d);try{const u=await Gn(new Promise((b,w)=>{this.relayer.request(a).catch(E=>{this.logger.warn(E,E?.message),w(E)}).then(b)}),this.initialSubscribeTimeout,`Subscribing to ${e} failed, please try again`);this.events.removeListener(cn.created,d),h(u)}catch{}}),l=await Gn(f,this.subscribeTimeout,`Subscribing to ${e} failed, please try again`);if(!l&&c)throw new Error(`Subscribing to ${e} failed, please try again`);return l?o:null}catch(f){if(this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(Ue.connection_stalled),c)throw f}return null}async rpcBatchSubscribe(e){if(!e.length)return;const n=e[0].relay,r={method:Bo(n.protocol).batchSubscribe,params:{topics:e.map(i=>i.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:r});try{await await Gn(new Promise(i=>{this.relayer.request(r).catch(s=>this.logger.warn(s)).then(i)}),this.subscribeTimeout,"rpcBatchSubscribe failed, please try again")}catch{this.relayer.events.emit(Ue.connection_stalled)}}async rpcBatchFetchMessages(e){if(!e.length)return;const n=e[0].relay,r={method:Bo(n.protocol).batchFetchMessages,params:{topics:e.map(s=>s.topic)}};this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:r});let i;try{i=await await Gn(new Promise((s,o)=>{this.relayer.request(r).catch(a=>{this.logger.warn(a),o(a)}).then(s)}),this.subscribeTimeout,"rpcBatchFetchMessages failed, please try again")}catch{this.relayer.events.emit(Ue.connection_stalled)}return i}rpcUnsubscribe(e,n,r){const i={method:Bo(r.protocol).unsubscribe,params:{topic:e,id:n}};return this.logger.debug("Outgoing Relay Payload"),this.logger.trace({type:"payload",direction:"outgoing",request:i}),this.relayer.request(i)}onSubscribe(e,n){this.setSubscription(e,L0(Ja({},n),{id:e})),this.pending.delete(n.topic)}onBatchSubscribe(e){e.length&&e.forEach(n=>{this.setSubscription(n.id,Ja({},n)),this.pending.delete(n.topic)})}async onUnsubscribe(e,n,r){this.events.removeAllListeners(n),this.hasSubscription(n,e)&&this.deleteSubscription(n,r),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,n){this.logger.debug("Setting subscription"),this.logger.trace({type:"method",method:"setSubscription",id:e,subscription:n}),this.addSubscription(e,n)}addSubscription(e,n){this.subscriptions.set(e,Ja({},n)),this.topicMap.set(n.topic,e),this.events.emit(cn.created,n)}getSubscription(e){this.logger.debug("Getting subscription"),this.logger.trace({type:"method",method:"getSubscription",id:e});const n=this.subscriptions.get(e);if(!n){const{message:r}=W("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(r)}return n}deleteSubscription(e,n){this.logger.debug("Deleting subscription"),this.logger.trace({type:"method",method:"deleteSubscription",id:e,reason:n});const r=this.getSubscription(e);this.subscriptions.delete(e),this.topicMap.delete(r.topic,e),this.events.emit(cn.deleted,L0(Ja({},r),{reason:n}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit(cn.sync)}async onRestart(){if(this.cached.length){const e=[...this.cached],n=Math.ceil(this.cached.length/this.batchSubscribeTopicsLimit);for(let r=0;r<n;r++){const i=e.splice(0,this.batchSubscribeTopicsLimit);await this.batchSubscribe(i)}}this.events.emit(cn.resubscribed)}async restore(){try{const e=await this.getRelayerSubscriptions();if(typeof e>"u"||!e.length)return;if(this.subscriptions.size&&!e.every(n=>{var r;return n.topic===((r=this.subscriptions.get(n.id))==null?void 0:r.topic)})){const{message:n}=W("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(n),this.logger.error(`${this.name}: ${JSON.stringify(this.values)}`),new Error(n)}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 n=>L0(Ja({},n),{id:await this.getSubscriptionId(n.topic)})))))}async batchFetchMessages(e){if(!e.length)return;this.logger.trace(`Fetching batch messages for ${e.length} subscriptions`);const n=await this.rpcBatchFetchMessages(e);n&&n.messages&&(await $R(Z.toMiliseconds(Z.ONE_SECOND)),await this.relayer.handleBatchMessageEvents(n.messages))}async onConnect(){await this.restart(),this.reset()}onDisconnect(){this.onDisable()}isInitialized(){if(!this.initialized){const{message:e}=W("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 yn(e+await this.getClientId())}}var Gk=Object.defineProperty,tv=Object.getOwnPropertySymbols,Zk=Object.prototype.hasOwnProperty,Wk=Object.prototype.propertyIsEnumerable,F0=(t,e,n)=>e in t?Gk(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,nv=(t,e)=>{for(var n in e||(e={}))Zk.call(e,n)&&F0(t,n,e[n]);if(tv)for(var n of tv(e))Wk.call(e,n)&&F0(t,n,e[n]);return t},be=(t,e,n)=>F0(t,typeof e!="symbol"?e+"":e,n);class Yk extends bO{constructor(e){var n;super(e),be(this,"protocol","wc"),be(this,"version",2),be(this,"core"),be(this,"logger"),be(this,"events",new at.exports.EventEmitter),be(this,"provider"),be(this,"messages"),be(this,"subscriber"),be(this,"publisher"),be(this,"name",$L),be(this,"transportExplicitlyClosed",!1),be(this,"initialized",!1),be(this,"connectionAttemptInProgress",!1),be(this,"relayUrl"),be(this,"projectId"),be(this,"packageName"),be(this,"bundleId"),be(this,"hasExperiencedNetworkDisruption",!1),be(this,"pingTimeout"),be(this,"heartBeatTimeout",Z.toMiliseconds(Z.THIRTY_SECONDS+Z.FIVE_SECONDS)),be(this,"reconnectTimeout"),be(this,"connectPromise"),be(this,"reconnectInProgress",!1),be(this,"requestsInFlight",[]),be(this,"connectTimeout",Z.toMiliseconds(Z.ONE_SECOND*15)),be(this,"request",async r=>{var i,s;this.logger.debug("Publishing Request Payload");const o=r.id||Zi().toString();await this.toEstablishConnection();try{this.logger.trace({id:o,method:r.method,topic:(i=r.params)==null?void 0:i.topic},"relayer.request - publishing...");const a=`${o}:${((s=r.params)==null?void 0:s.tag)||""}`;this.requestsInFlight.push(a);const c=await this.provider.request(r);return this.requestsInFlight=this.requestsInFlight.filter(f=>f!==a),c}catch(a){throw this.logger.debug(`Failed to Publish Request: ${o}`),a}}),be(this,"resetPingTimeout",()=>{Hf()&&(clearTimeout(this.pingTimeout),this.pingTimeout=setTimeout(()=>{var r,i,s,o;try{this.logger.debug({},"pingTimeout: Connection stalled, terminating..."),(o=(s=(i=(r=this.provider)==null?void 0:r.connection)==null?void 0:i.socket)==null?void 0:s.terminate)==null||o.call(s)}catch(a){this.logger.warn(a,a?.message)}},this.heartBeatTimeout))}),be(this,"onPayloadHandler",r=>{this.onProviderPayload(r),this.resetPingTimeout()}),be(this,"onConnectHandler",()=>{this.logger.warn({},"Relayer connected \u{1F6DC}"),this.startPingTimeout(),this.events.emit(Ue.connect)}),be(this,"onDisconnectHandler",()=>{this.logger.warn({},"Relayer disconnected \u{1F6D1}"),this.requestsInFlight=[],this.onProviderDisconnect()}),be(this,"onProviderErrorHandler",r=>{this.logger.fatal(`Fatal socket error: ${r.message}`),this.events.emit(Ue.error,r),this.logger.fatal("Fatal socket error received, closing transport"),this.transportExplicitlyClosed=!0,clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0,this.reconnectInProgress=!1,this.transportClose().catch(i=>this.logger.warn(i))}),be(this,"registerProviderListeners",()=>{this.provider.on(mn.payload,this.onPayloadHandler),this.provider.on(mn.connect,this.onConnectHandler),this.provider.on(mn.disconnect,this.onDisconnectHandler),this.provider.on(mn.error,this.onProviderErrorHandler)}),this.core=e.core,this.logger=g8({logger:(n=e.logger)!=null?n:BL,name:this.name}),this.messages=new Pk(this.logger,e.core),this.subscriber=new Kk(this,this.logger),this.publisher=new Lk(this,this.logger),this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||P8,lR()?this.packageName=ym():hR()&&(this.bundleId=ym()),this.provider={}}async init(){this.logger.trace("Initialized"),this.registerEventListeners(),await Promise.all([this.messages.init(),this.subscriber.init()]),this.initialized=!0,this.transportOpen().catch(e=>this.logger.warn(e,e?.message))}get context(){return Gt(this.logger)}get connected(){var e,n,r;return((r=(n=(e=this.provider)==null?void 0:e.connection)==null?void 0:n.socket)==null?void 0:r.readyState)===1||!1}get connecting(){var e,n,r;return((r=(n=(e=this.provider)==null?void 0:e.connection)==null?void 0:n.socket)==null?void 0:r.readyState)===0||this.connectPromise!==void 0||!1}async publish(e,n,r){this.isInitialized(),await this.publisher.publish(e,n,r),await this.recordMessageEvent({topic:e,message:n,publishedAt:Date.now(),transportType:Ae.relay},wu.outbound)}async publishCustom(e){this.isInitialized(),await this.publisher.publishCustom(e)}async subscribe(e,n){var r,i,s;this.isInitialized(),(!(n!=null&&n.transportType)||n?.transportType==="relay")&&await this.toEstablishConnection();const o=typeof((r=n?.internal)==null?void 0:r.throwOnFailedPublish)>"u"?!0:(i=n?.internal)==null?void 0:i.throwOnFailedPublish;let a=((s=this.subscriber.topicMap.get(e))==null?void 0:s[0])||"",c;const f=l=>{l.topic===e&&(this.subscriber.off(cn.created,f),c())};return await Promise.all([new Promise(l=>{c=l,this.subscriber.on(cn.created,f)}),new Promise(async(l,h)=>{a=await this.subscriber.subscribe(e,nv({internal:{throwOnFailedPublish:o}},n)).catch(d=>{o&&h(d)})||a,l()})]),a}async unsubscribe(e,n){this.isInitialized(),await this.subscriber.unsubscribe(e,n)}on(e,n){this.events.on(e,n)}once(e,n){this.events.once(e,n)}off(e,n){this.events.off(e,n)}removeListener(e,n){this.events.removeListener(e,n)}async transportDisconnect(){this.provider.disconnect&&(this.hasExperiencedNetworkDisruption||this.connected)?await Gn(this.provider.disconnect(),2e3,"provider.disconnect()").catch(()=>this.onProviderDisconnect()):this.onProviderDisconnect()}async transportClose(){this.transportExplicitlyClosed=!0,clearTimeout(this.reconnectTimeout),this.reconnectTimeout=void 0,this.reconnectInProgress=!1,await this.transportDisconnect()}async transportOpen(e){if(!this.subscriber.hasAnyTopics){this.logger.info("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(n,r)=>{await this.connect(e).then(n).catch(r).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 p8())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 n=e.sort((r,i)=>r.publishedAt-i.publishedAt);this.logger.debug(`Batch of ${n.length} message events sorted`);for(const r of n)try{await this.onMessageEvent(r)}catch(i){this.logger.warn(i,"Error while processing batch message event: "+i?.message)}this.logger.trace(`Batch of ${n.length} message events processed`)}async onLinkMessageEvent(e,n){const{topic:r}=e;if(!n.sessionExists){const i=je(Z.FIVE_MINUTES),s={topic:r,expiry:i,relay:{protocol:"irn"},active:!1};await this.core.pairing.pairings.set(r,s)}this.events.emit(Ue.message,e),await this.recordMessageEvent(e,wu.inbound)}async connect(e){await this.confirmOnlineStateOrThrow(),e&&e!==this.relayUrl&&(this.relayUrl=e,await this.transportDisconnect()),this.connectionAttemptInProgress=!0,this.transportExplicitlyClosed=!1;let n=1;for(;n<6;){try{if(this.transportExplicitlyClosed)break;this.logger.debug({},`Connecting to ${this.relayUrl}, attempt: ${n}...`),await this.createProvider(),await new Promise(async(r,i)=>{const s=()=>{i(new Error("Connection interrupted while trying to connect"))};this.provider.once(mn.disconnect,s),await Gn(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(mn.disconnect,s),clearTimeout(this.reconnectTimeout)}),await new Promise(async(o,a)=>{const c=()=>{i(new Error("Connection interrupted while trying to subscribe"))};this.provider.once(mn.disconnect,c),await this.subscriber.start().then(o).catch(a).finally(()=>{this.provider.off(mn.disconnect,c)})}),this.hasExperiencedNetworkDisruption=!1,r()})}catch(r){await this.subscriber.stop();const i=r;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: ${n}`);break}await new Promise(r=>setTimeout(r,Z.toMiliseconds(n*1))),n++}}startPingTimeout(){var e,n,r,i,s;if(Hf())try{(n=(e=this.provider)==null?void 0:e.connection)!=null&&n.socket&&((s=(i=(r=this.provider)==null?void 0:r.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 lL(new gL(yR({sdkVersion:D0,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,n){const{topic:r,message:i}=e;await this.messages.set(r,i,n)}async shouldIgnoreMessageEvent(e){const{topic:n,message:r}=e;if(!r||r.length===0)return this.logger.warn(`Ignoring invalid/empty message: ${r}`),!0;if(!await this.subscriber.isKnownTopic(n))return this.logger.warn(`Ignoring message for unknown topic ${n}`),!0;const i=this.messages.has(n,r);return i&&this.logger.warn(`Ignoring duplicate message: ${r}`),i}async onProviderPayload(e){if(this.logger.debug("Incoming Relay Payload"),this.logger.trace({type:"payload",direction:"incoming",payload:e}),O0(e)){if(!e.method.endsWith(AL))return;const n=e.params,{topic:r,message:i,publishedAt:s,attestation:o}=n.data,a={topic:r,message:i,publishedAt:s,transportType:Ae.relay,attestation:o};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(nv({type:"event",event:n.id},a)),this.events.emit(n.id,a),await this.acknowledgePayload(e),await this.onMessageEvent(a)}else bu(e)&&this.events.emit(Ue.message_ack,e)}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(await this.recordMessageEvent(e,wu.inbound),this.events.emit(Ue.message,e))}async acknowledgePayload(e){const n=gu(e.id,!0);await this.provider.connection.send(n)}unregisterProviderListeners(){this.provider.off(mn.payload,this.onPayloadHandler),this.provider.off(mn.connect,this.onConnectHandler),this.provider.off(mn.disconnect,this.onDisconnectHandler),this.provider.off(mn.error,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let e=await p8();pC(async n=>{e!==n&&(e=n,n?await this.transportOpen().catch(r=>this.logger.error(r,r?.message)):(this.hasExperiencedNetworkDisruption=!0,await this.transportDisconnect(),this.transportExplicitlyClosed=!1))}),this.core.heartbeat.on(ds.pulse,async()=>{if(!this.transportExplicitlyClosed&&!this.connected&&yC())try{await this.confirmOnlineStateOrThrow(),await this.transportOpen()}catch(n){this.logger.warn(n,n?.message)}})}async onProviderDisconnect(){clearTimeout(this.pingTimeout),this.events.emit(Ue.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(OL)))))}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}async toEstablishConnection(){if(await this.confirmOnlineStateOrThrow(),!this.connected){if(this.connectPromise){await this.connectPromise;return}await this.connect()}}}function Xk(t,e){return t===e||Number.isNaN(t)&&Number.isNaN(e)}function rv(t){return Object.getOwnPropertySymbols(t).filter(e=>Object.prototype.propertyIsEnumerable.call(t,e))}function iv(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const Jk="[object RegExp]",Qk="[object String]",eq="[object Number]",tq="[object Boolean]",sv="[object Arguments]",nq="[object Symbol]",rq="[object Date]",iq="[object Map]",sq="[object Set]",oq="[object Array]",aq="[object Function]",cq="[object ArrayBuffer]",k0="[object Object]",fq="[object Error]",uq="[object DataView]",lq="[object Uint8Array]",hq="[object Uint8ClampedArray]",dq="[object Uint16Array]",pq="[object Uint32Array]",gq="[object BigUint64Array]",bq="[object Int8Array]",yq="[object Int16Array]",wq="[object Int32Array]",mq="[object BigInt64Array]",vq="[object Float32Array]",Eq="[object Float64Array]";function xq(){}function ov(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 _q(t,e,n){return Qa(t,e,void 0,void 0,void 0,void 0,n)}function Qa(t,e,n,r,i,s,o){const a=o(t,e,n,r,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 ec(t,e,s,o)}return ec(t,e,s,o)}function ec(t,e,n,r){if(Object.is(t,e))return!0;let i=iv(t),s=iv(e);if(i===sv&&(i=k0),s===sv&&(s=k0),i!==s)return!1;switch(i){case Qk:return t.toString()===e.toString();case eq:{const c=t.valueOf(),f=e.valueOf();return Xk(c,f)}case tq:case rq:case nq:return Object.is(t.valueOf(),e.valueOf());case Jk:return t.source===e.source&&t.flags===e.flags;case aq:return t===e}n=n??new Map;const o=n.get(t),a=n.get(e);if(o!=null&&a!=null)return o===e;n.set(t,e),n.set(e,t);try{switch(i){case iq:{if(t.size!==e.size)return!1;for(const[c,f]of t.entries())if(!e.has(c)||!Qa(f,e.get(c),c,t,e,n,r))return!1;return!0}case sq:{if(t.size!==e.size)return!1;const c=Array.from(t.values()),f=Array.from(e.values());for(let l=0;l<c.length;l++){const h=c[l],d=f.findIndex(u=>Qa(h,u,void 0,t,e,n,r));if(d===-1)return!1;f.splice(d,1)}return!0}case oq:case lq:case hq:case dq:case pq:case gq:case bq:case yq:case wq:case mq:case vq:case Eq:{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(!Qa(t[c],e[c],c,t,e,n,r))return!1;return!0}case cq:return t.byteLength!==e.byteLength?!1:ec(new Uint8Array(t),new Uint8Array(e),n,r);case uq:return t.byteLength!==e.byteLength||t.byteOffset!==e.byteOffset?!1:ec(new Uint8Array(t),new Uint8Array(e),n,r);case fq:return t.name===e.name&&t.message===e.message;case k0:{if(!(ec(t.constructor,e.constructor,n,r)||ov(t)&&ov(e)))return!1;const c=[...Object.keys(t),...rv(t)],f=[...Object.keys(e),...rv(e)];if(c.length!==f.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 u=e[h];if(!Qa(d,u,h,t,e,n,r))return!1}return!0}default:return!1}}finally{n.delete(t),n.delete(e)}}function Sq(t,e){return _q(t,e,xq)}var Iq=Object.defineProperty,av=Object.getOwnPropertySymbols,Bq=Object.prototype.hasOwnProperty,$q=Object.prototype.propertyIsEnumerable,q0=(t,e,n)=>e in t?Iq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,cv=(t,e)=>{for(var n in e||(e={}))Bq.call(e,n)&&q0(t,n,e[n]);if(av)for(var n of av(e))$q.call(e,n)&&q0(t,n,e[n]);return t},Qt=(t,e,n)=>q0(t,typeof e!="symbol"?e+"":e,n);class Ts extends yO{constructor(e,n,r,i=Xn,s=void 0){super(e,n,r,i),this.core=e,this.logger=n,this.name=r,Qt(this,"map",new Map),Qt(this,"version",DL),Qt(this,"cached",[]),Qt(this,"initialized",!1),Qt(this,"getKey"),Qt(this,"storagePrefix",Xn),Qt(this,"recentlyDeleted",[]),Qt(this,"recentlyDeletedLimit",200),Qt(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(o=>{this.getKey&&o!==null&&!ze(o)?this.map.set(this.getKey(o),o):VU(o)?this.map.set(o.id,o):KU(o)&&this.map.set(o.topic,o)}),this.cached=[],this.initialized=!0)}),Qt(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())}),Qt(this,"get",o=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:o}),this.getData(o))),Qt(this,"getAll",o=>(this.isInitialized(),o?this.values.filter(a=>Object.keys(o).every(c=>Sq(a[c],o[c]))):this.values)),Qt(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=cv(cv({},this.getData(o)),a);this.map.set(o,c),await this.persist()}),Qt(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=sn(n,this.name),this.storagePrefix=i,this.getKey=s}get context(){return Gt(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 n=this.map.get(e);if(!n){if(this.recentlyDeleted.includes(e)){const{message:i}=W("MISSING_OR_INVALID",`Record was recently deleted - ${this.name}: ${e}`);throw this.logger.error(i),new Error(i)}const{message:r}=W("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.error(r),new Error(r)}return n}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:n}=W("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(n),new Error(n)}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}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}}var Aq=Object.defineProperty,Oq=(t,e,n)=>e in t?Aq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,le=(t,e,n)=>Oq(t,typeof e!="symbol"?e+"":e,n);class Dq{constructor(e,n){this.core=e,this.logger=n,le(this,"name",NL),le(this,"version",UL),le(this,"events",new at.exports),le(this,"pairings"),le(this,"initialized",!1),le(this,"storagePrefix",Xn),le(this,"ignoredPayloadTypes",[Nr]),le(this,"registeredMethods",[]),le(this,"init",async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))}),le(this,"register",({methods:r})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...r])]}),le(this,"create",async r=>{this.isInitialized();const i=w0(),s=await this.core.crypto.setSymKey(i),o=je(Z.FIVE_MINUTES),a={protocol:D8},c={topic:s,expiry:o,relay:a,active:!1,methods:r?.methods},f=t8({protocol:this.core.protocol,version:this.core.version,topic:s,symKey:i,relay:a,expiryTimestamp:o,methods:r?.methods});return this.events.emit(Ds.create,c),this.core.expirer.set(s,o),await this.pairings.set(s,c),await this.core.relayer.subscribe(s,{transportType:r?.transportType,internal:r?.internal}),{topic:s,uri:f}}),le(this,"pair",async r=>{this.isInitialized();const i=this.core.eventClient.createEvent({properties:{topic:r?.uri,trace:[Jn.pairing_started]}});this.isValidPair(r,i);const{topic:s,symKey:o,relay:a,expiryTimestamp:c,methods:f}=e8(r.uri);i.props.properties.topic=s,i.addTrace(Jn.pairing_uri_validation_success),i.addTrace(Jn.pairing_uri_not_expired);let l;if(this.pairings.keys.includes(s)){if(l=this.pairings.get(s),i.addTrace(Jn.existing_pairing),l.active)throw i.setError(Fr.active_pairing_already_exists),new Error(`Pairing already exists: ${s}. Please try again with a new connection URI.`);i.addTrace(Jn.pairing_not_expired)}const h=c||je(Z.FIVE_MINUTES),d={topic:s,relay:a,expiry:h,active:!1,methods:f};this.core.expirer.set(s,h),await this.pairings.set(s,d),i.addTrace(Jn.store_new_pairing),r.activatePairing&&await this.activate({topic:s}),this.events.emit(Ds.create,d),i.addTrace(Jn.emit_inactive_pairing),this.core.crypto.keychain.has(s)||await this.core.crypto.setSymKey(o,s),i.addTrace(Jn.subscribing_pairing_topic);try{await this.core.relayer.confirmOnlineStateOrThrow()}catch{i.setError(Fr.no_internet_connection)}try{await this.core.relayer.subscribe(s,{relay:a})}catch(u){throw i.setError(Fr.subscribe_pairing_topic_failure),u}return i.addTrace(Jn.subscribe_pairing_topic_success),d}),le(this,"activate",async({topic:r})=>{this.isInitialized();const i=je(Z.FIVE_MINUTES);this.core.expirer.set(r,i),await this.pairings.update(r,{active:!0,expiry:i})}),le(this,"ping",async r=>{this.isInitialized(),await this.isValidPing(r),this.logger.warn("ping() is deprecated and will be removed in the next major release.");const{topic:i}=r;if(this.pairings.keys.includes(i)){const s=await this.sendRequest(i,"wc_pairingPing",{}),{done:o,resolve:a,reject:c}=xs();this.events.once(we("pairing_ping",s),({error:f})=>{f?c(f):a()}),await o()}}),le(this,"updateExpiry",async({topic:r,expiry:i})=>{this.isInitialized(),await this.pairings.update(r,{expiry:i})}),le(this,"updateMetadata",async({topic:r,metadata:i})=>{this.isInitialized(),await this.pairings.update(r,{peerMetadata:i})}),le(this,"getPairings",()=>(this.isInitialized(),this.pairings.values)),le(this,"disconnect",async r=>{this.isInitialized(),await this.isValidDisconnect(r);const{topic:i}=r;this.pairings.keys.includes(i)&&(await this.sendRequest(i,"wc_pairingDelete",Oe("USER_DISCONNECTED")),await this.deletePairing(i))}),le(this,"formatUriFromPairing",r=>{this.isInitialized();const{topic:i,relay:s,expiry:o,methods:a}=r,c=this.core.crypto.keychain.get(i);return t8({protocol:this.core.protocol,version:this.core.version,topic:i,symKey:c,relay:s,expiryTimestamp:o,methods:a})}),le(this,"sendRequest",async(r,i,s)=>{const o=Lr(i,s),a=await this.core.crypto.encode(r,o),c=Za[i].req;return this.core.history.set(r,o),this.core.relayer.publish(r,a,c),o.id}),le(this,"sendResult",async(r,i,s)=>{const o=gu(r,s),a=await this.core.crypto.encode(i,o),c=(await this.core.history.get(i,r)).request.method,f=Za[c].res;await this.core.relayer.publish(i,a,f),await this.core.history.resolve(o)}),le(this,"sendError",async(r,i,s)=>{const o=A0(r,s),a=await this.core.crypto.encode(i,o),c=(await this.core.history.get(i,r)).request.method,f=Za[c]?Za[c].res:Za.unregistered_method.res;await this.core.relayer.publish(i,a,f),await this.core.history.resolve(o)}),le(this,"deletePairing",async(r,i)=>{await this.core.relayer.unsubscribe(r),await Promise.all([this.pairings.delete(r,Oe("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(r),i?Promise.resolve():this.core.expirer.del(r)])}),le(this,"cleanup",async()=>{const r=this.pairings.getAll().filter(i=>Ti(i.expiry));await Promise.all(r.map(i=>this.deletePairing(i.topic)))}),le(this,"onRelayEventRequest",async r=>{const{topic:i,payload:s}=r;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)}}),le(this,"onRelayEventResponse",async r=>{const{topic:i,payload:s}=r,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)}}),le(this,"onPairingPingRequest",async(r,i)=>{const{id:s}=i;try{this.isValidPing({topic:r}),await this.sendResult(s,r,!0),this.events.emit(Ds.ping,{id:s,topic:r})}catch(o){await this.sendError(s,r,o),this.logger.error(o)}}),le(this,"onPairingPingResponse",(r,i)=>{const{id:s}=i;setTimeout(()=>{Yn(i)?this.events.emit(we("pairing_ping",s),{}):wn(i)&&this.events.emit(we("pairing_ping",s),{error:i.error})},500)}),le(this,"onPairingDeleteRequest",async(r,i)=>{const{id:s}=i;try{this.isValidDisconnect({topic:r}),await this.deletePairing(r),this.events.emit(Ds.delete,{id:s,topic:r})}catch(o){await this.sendError(s,r,o),this.logger.error(o)}}),le(this,"onUnknownRpcMethodRequest",async(r,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,r,a),this.logger.error(a)}catch(a){await this.sendError(s,r,a),this.logger.error(a)}}),le(this,"onUnknownRpcMethodResponse",r=>{this.registeredMethods.includes(r)||this.logger.error(Oe("WC_METHOD_UNSUPPORTED",r))}),le(this,"isValidPair",(r,i)=>{var s;if(!Jt(r)){const{message:a}=W("MISSING_OR_INVALID",`pair() params: ${r}`);throw i.setError(Fr.malformed_pairing_uri),new Error(a)}if(!HU(r.uri)){const{message:a}=W("MISSING_OR_INVALID",`pair() uri: ${r.uri}`);throw i.setError(Fr.malformed_pairing_uri),new Error(a)}const o=e8(r?.uri);if(!((s=o?.relay)!=null&&s.protocol)){const{message:a}=W("MISSING_OR_INVALID","pair() uri#relay-protocol");throw i.setError(Fr.malformed_pairing_uri),new Error(a)}if(!(o!=null&&o.symKey)){const{message:a}=W("MISSING_OR_INVALID","pair() uri#symKey");throw i.setError(Fr.malformed_pairing_uri),new Error(a)}if(o!=null&&o.expiryTimestamp&&Z.toMiliseconds(o?.expiryTimestamp)<Date.now()){i.setError(Fr.pairing_expired);const{message:a}=W("EXPIRED","pair() URI has expired. Please try again with a new connection URI.");throw new Error(a)}}),le(this,"isValidPing",async r=>{if(!Jt(r)){const{message:s}=W("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(s)}const{topic:i}=r;await this.isValidPairingTopic(i)}),le(this,"isValidDisconnect",async r=>{if(!Jt(r)){const{message:s}=W("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(s)}const{topic:i}=r;await this.isValidPairingTopic(i)}),le(this,"isValidPairingTopic",async r=>{if(!Ne(r,!1)){const{message:i}=W("MISSING_OR_INVALID",`pairing topic should be a string: ${r}`);throw new Error(i)}if(!this.pairings.keys.includes(r)){const{message:i}=W("NO_MATCHING_KEY",`pairing topic doesn't exist: ${r}`);throw new Error(i)}if(Ti(this.pairings.get(r).expiry)){await this.deletePairing(r);const{message:i}=W("EXPIRED",`pairing topic: ${r}`);throw new Error(i)}}),this.core=e,this.logger=sn(n,this.name),this.pairings=new Ts(this.core,this.logger,this.name,this.storagePrefix)}get context(){return Gt(this.logger)}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(Ue.message,async e=>{const{topic:n,message:r,transportType:i}=e;if(this.pairings.keys.includes(n)&&i!==Ae.link_mode&&!this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(r)))try{const s=await this.core.crypto.decode(n,r);O0(s)?(this.core.history.set(n,s),await this.onRelayEventRequest({topic:n,payload:s})):bu(s)&&(await this.core.history.resolve(s),await this.onRelayEventResponse({topic:n,payload:s}),this.core.history.delete(n,s.id)),await this.core.relayer.messages.ack(n,r)}catch(s){this.logger.error(s)}})}registerExpirerEvents(){this.core.expirer.on(vn.expired,async e=>{const{topic:n}=Em(e.target);n&&this.pairings.keys.includes(n)&&(await this.deletePairing(n,!0),this.events.emit(Ds.expire,{topic:n}))})}}var Pq=Object.defineProperty,Rq=(t,e,n)=>e in t?Pq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,rt=(t,e,n)=>Rq(t,typeof e!="symbol"?e+"":e,n);class Tq extends dO{constructor(e,n){super(e,n),this.core=e,this.logger=n,rt(this,"records",new Map),rt(this,"events",new at.exports.EventEmitter),rt(this,"name",CL),rt(this,"version",LL),rt(this,"cached",[]),rt(this,"initialized",!1),rt(this,"storagePrefix",Xn),rt(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(r=>this.records.set(r.id,r)),this.cached=[],this.registerEventListeners(),this.initialized=!0)}),rt(this,"set",(r,i,s)=>{if(this.isInitialized(),this.logger.debug("Setting JSON-RPC request history record"),this.logger.trace({type:"method",method:"set",topic:r,request:i,chainId:s}),this.records.has(i.id))return;const o={id:i.id,topic:r,request:{method:i.method,params:i.params||null},chainId:s,expiry:je(Z.THIRTY_DAYS)};this.records.set(o.id,o),this.persist(),this.events.emit(Ln.created,o)}),rt(this,"resolve",async r=>{if(this.isInitialized(),this.logger.debug("Updating JSON-RPC response history record"),this.logger.trace({type:"method",method:"update",response:r}),!this.records.has(r.id))return;const i=await this.getRecord(r.id);typeof i.response>"u"&&(i.response=wn(r)?{error:r.error}:{result:r.result},this.records.set(i.id,i),this.persist(),this.events.emit(Ln.updated,i))}),rt(this,"get",async(r,i)=>(this.isInitialized(),this.logger.debug("Getting record"),this.logger.trace({type:"method",method:"get",topic:r,id:i}),await this.getRecord(i))),rt(this,"delete",(r,i)=>{this.isInitialized(),this.logger.debug("Deleting record"),this.logger.trace({type:"method",method:"delete",id:i}),this.values.forEach(s=>{if(s.topic===r){if(typeof i<"u"&&s.id!==i)return;this.records.delete(s.id),this.events.emit(Ln.deleted,s)}}),this.persist()}),rt(this,"exists",async(r,i)=>(this.isInitialized(),this.records.has(i)?(await this.getRecord(i)).topic===r:!1)),rt(this,"on",(r,i)=>{this.events.on(r,i)}),rt(this,"once",(r,i)=>{this.events.once(r,i)}),rt(this,"off",(r,i)=>{this.events.off(r,i)}),rt(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),this.logger=sn(n,this.name)}get context(){return Gt(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(n=>{if(typeof n.response<"u")return;const r={topic:n.topic,request:Lr(n.request.method,n.request.params,n.id),chainId:n.chainId};return e.push(r)}),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 n=this.records.get(e);if(!n){const{message:r}=W("NO_MATCHING_KEY",`${this.name}: ${e}`);throw new Error(r)}return n}async persist(){await this.setJsonRpcRecords(this.values),this.events.emit(Ln.sync)}async restore(){try{const e=await this.getJsonRpcRecords();if(typeof e>"u"||!e.length)return;if(this.records.size){const{message:n}=W("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(n),new Error(n)}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(Ln.created,e=>{const n=Ln.created;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.events.on(Ln.updated,e=>{const n=Ln.updated;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.events.on(Ln.deleted,e=>{const n=Ln.deleted;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.core.heartbeat.on(ds.pulse,()=>{this.cleanup()})}cleanup(){try{this.isInitialized();let e=!1;this.records.forEach(n=>{Z.toMiliseconds(n.expiry||0)-Date.now()<=0&&(this.logger.info(`Deleting expired history log: ${n.id}`),this.records.delete(n.id),this.events.emit(Ln.deleted,n,!1),e=!0)}),e&&this.persist()}catch(e){this.logger.warn(e)}}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}}var Nq=Object.defineProperty,Uq=(t,e,n)=>e in t?Nq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,St=(t,e,n)=>Uq(t,typeof e!="symbol"?e+"":e,n);class Cq extends mO{constructor(e,n){super(e,n),this.core=e,this.logger=n,St(this,"expirations",new Map),St(this,"events",new at.exports.EventEmitter),St(this,"name",FL),St(this,"version",kL),St(this,"cached",[]),St(this,"initialized",!1),St(this,"storagePrefix",Xn),St(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(r=>this.expirations.set(r.target,r)),this.cached=[],this.registerEventListeners(),this.initialized=!0)}),St(this,"has",r=>{try{const i=this.formatTarget(r);return typeof this.getExpiration(i)<"u"}catch{return!1}}),St(this,"set",(r,i)=>{this.isInitialized();const s=this.formatTarget(r),o={target:s,expiry:i};this.expirations.set(s,o),this.checkExpiry(s,o),this.events.emit(vn.created,{target:s,expiration:o})}),St(this,"get",r=>{this.isInitialized();const i=this.formatTarget(r);return this.getExpiration(i)}),St(this,"del",r=>{if(this.isInitialized(),this.has(r)){const i=this.formatTarget(r),s=this.getExpiration(i);this.expirations.delete(i),this.events.emit(vn.deleted,{target:i,expiration:s})}}),St(this,"on",(r,i)=>{this.events.on(r,i)}),St(this,"once",(r,i)=>{this.events.once(r,i)}),St(this,"off",(r,i)=>{this.events.off(r,i)}),St(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),this.logger=sn(n,this.name)}get context(){return Gt(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 wR(e);if(typeof e=="number")return mR(e);const{message:n}=W("UNKNOWN_TYPE",`Target type: ${typeof e}`);throw new Error(n)}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(vn.sync)}async restore(){try{const e=await this.getExpirations();if(typeof e>"u"||!e.length)return;if(this.expirations.size){const{message:n}=W("RESTORE_WILL_OVERRIDE",this.name);throw this.logger.error(n),new Error(n)}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 n=this.expirations.get(e);if(!n){const{message:r}=W("NO_MATCHING_KEY",`${this.name}: ${e}`);throw this.logger.warn(r),new Error(r)}return n}checkExpiry(e,n){const{expiry:r}=n;Z.toMiliseconds(r)-Date.now()<=0&&this.expire(e,n)}expire(e,n){this.expirations.delete(e),this.events.emit(vn.expired,{target:e,expiration:n})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,n)=>this.checkExpiry(n,e))}registerEventListeners(){this.core.heartbeat.on(ds.pulse,()=>this.checkExpirations()),this.events.on(vn.created,e=>{const n=vn.created;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:e}),this.persist()}),this.events.on(vn.expired,e=>{const n=vn.expired;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:e}),this.persist()}),this.events.on(vn.deleted,e=>{const n=vn.deleted;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:e}),this.persist()})}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}}var Lq=Object.defineProperty,Fq=(t,e,n)=>e in t?Lq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ce=(t,e,n)=>Fq(t,typeof e!="symbol"?e+"":e,n);class kq extends vO{constructor(e,n,r){super(e,n,r),this.core=e,this.logger=n,this.store=r,Ce(this,"name",qL),Ce(this,"abortController"),Ce(this,"isDevEnv"),Ce(this,"verifyUrlV3",ML),Ce(this,"storagePrefix",Xn),Ce(this,"version",A8),Ce(this,"publicKey"),Ce(this,"fetchPromise"),Ce(this,"init",async()=>{var i;this.isDevEnv||(this.publicKey=await this.store.getItem(this.storeKey),this.publicKey&&Z.toMiliseconds((i=this.publicKey)==null?void 0:i.expiresAt)<Date.now()&&(this.logger.debug("verify v2 public key expired"),await this.removePublicKey()))}),Ce(this,"register",async i=>{if(!wo()||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 f=nr(),l=this.startAbortTimer(Z.ONE_SECOND*5),h=await new Promise((d,u)=>{const b=()=>{window.removeEventListener("message",E),f.body.removeChild(w),u("attestation aborted")};this.abortController.signal.addEventListener("abort",b);const w=f.createElement("iframe");w.src=c,w.style.display="none",w.addEventListener("error",b,{signal:this.abortController.signal});const E=A=>{if(A.data&&typeof A.data=="string")try{const P=JSON.parse(A.data);if(P.type==="verify_attestation"){if(uh(P.attestation).payload.id!==o)return;clearInterval(l),f.body.removeChild(w),this.abortController.signal.removeEventListener("abort",b),window.removeEventListener("message",E),d(P.attestation===null?"":P.attestation)}}catch(P){this.logger.warn(P)}};f.body.appendChild(w),window.addEventListener("message",E,{signal:this.abortController.signal})});return this.logger.debug(h,"jwt attestation"),h}catch(f){this.logger.warn(f)}return""}),Ce(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(uh(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(i?.verifyUrl);return this.fetchAttestation(o,c)}),Ce(this,"fetchAttestation",async(i,s)=>{this.logger.debug(`resolving attestation: ${i} from url: ${s}`);const o=this.startAbortTimer(Z.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}),Ce(this,"getVerifyUrl",i=>{let s=i||Wa;return zL.includes(s)||(this.logger.info(`verify url: ${s}, not included in trusted list, assigning default: ${Wa}`),s=Wa),s}),Ce(this,"fetchPublicKey",async()=>{try{this.logger.debug(`fetching public key from: ${this.verifyUrlV3}`);const i=this.startAbortTimer(Z.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)}}),Ce(this,"persistPublicKey",async i=>{this.logger.debug(i,"persisting public key to local storage"),await this.store.setItem(this.storeKey,i),this.publicKey=i}),Ce(this,"removePublicKey",async()=>{this.logger.debug("removing verify v2 public key from storage"),await this.store.removeItem(this.storeKey),this.publicKey=void 0}),Ce(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")}}),Ce(this,"getPublicKey",async()=>this.publicKey?this.publicKey:await this.fetchAndPersistPublicKey()),Ce(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}),Ce(this,"validateAttestation",(i,s)=>{const o=gU(i,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=sn(n,this.name),this.abortController=new AbortController,this.isDevEnv=jd(),this.init()}get storeKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//verify:public:key"}get context(){return Gt(this.logger)}startAbortTimer(e){return this.abortController=new AbortController,setTimeout(()=>this.abortController.abort(),Z.toMiliseconds(e))}}var qq=Object.defineProperty,jq=(t,e,n)=>e in t?qq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fv=(t,e,n)=>jq(t,typeof e!="symbol"?e+"":e,n);class Mq extends EO{constructor(e,n){super(e,n),this.projectId=e,this.logger=n,fv(this,"context",HL),fv(this,"registerDeviceToken",async r=>{const{clientId:i,token:s,notificationType:o,enableEncrypted:a=!1}=r,c=`${VL}/${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=sn(n,this.context)}}var zq=Object.defineProperty,uv=Object.getOwnPropertySymbols,Hq=Object.prototype.hasOwnProperty,Vq=Object.prototype.propertyIsEnumerable,j0=(t,e,n)=>e in t?zq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,tc=(t,e)=>{for(var n in e||(e={}))Hq.call(e,n)&&j0(t,n,e[n]);if(uv)for(var n of uv(e))Vq.call(e,n)&&j0(t,n,e[n]);return t},We=(t,e,n)=>j0(t,typeof e!="symbol"?e+"":e,n);class Kq extends xO{constructor(e,n,r=!0){super(e,n,r),this.core=e,this.logger=n,We(this,"context",GL),We(this,"storagePrefix",Xn),We(this,"storageVersion",KL),We(this,"events",new Map),We(this,"shouldPersist",!1),We(this,"init",async()=>{if(!jd())try{const i={eventId:_m(),timestamp:Date.now(),domain:this.getAppDomain(),props:{event:"INIT",type:"",properties:{client_id:await this.core.crypto.getClientId(),user_agent:mm(this.core.relayer.protocol,this.core.relayer.version,D0)}}};await this.sendEvent([i])}catch(i){this.logger.warn(i)}}),We(this,"createEvent",i=>{const{event:s="ERROR",type:o="",properties:{topic:a,trace:c}}=i,f=_m(),l=this.core.projectId||"",h=Date.now(),d=tc({eventId:f,timestamp:h,props:{event:s,type:o,properties:{topic:a,trace:c}},bundleId:l,domain:this.getAppDomain()},this.setMethods(f));return this.telemetryEnabled&&(this.events.set(f,d),this.shouldPersist=!0),d}),We(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 tc(tc({},a),this.setMethods(a.eventId))}),We(this,"deleteEvent",i=>{const{eventId:s}=i;this.events.delete(s),this.shouldPersist=!0}),We(this,"setEventListeners",()=>{this.core.heartbeat.on(ds.pulse,async()=>{this.shouldPersist&&await this.persist(),this.events.forEach(i=>{Z.fromMiliseconds(Date.now())-Z.fromMiliseconds(i.timestamp)>ZL&&(this.events.delete(i.eventId),this.shouldPersist=!0)})})}),We(this,"setMethods",i=>({addTrace:s=>this.addTrace(i,s),setError:s=>this.setError(i,s)})),We(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)}),We(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)}),We(this,"persist",async()=>{await this.core.storage.setItem(this.storageKey,Array.from(this.events.values())),this.shouldPersist=!1}),We(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,tc(tc({},s),this.setMethods(s.eventId)))})}catch(i){this.logger.warn(i)}}),We(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)}}),We(this,"sendEvent",async i=>{const s=this.getAppDomain()?"":"&sp=desktop";return await fetch(`${WL}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${D0}${s}`,{method:"POST",body:JSON.stringify(i)})}),We(this,"getAppDomain",()=>wm().url),this.logger=sn(n,this.context),this.telemetryEnabled=r,r?this.restore().then(async()=>{await this.submit(),this.setEventListeners()}):this.persist()}get storageKey(){return this.storagePrefix+this.storageVersion+this.core.customStoragePrefix+"//"+this.context}}var Gq=Object.defineProperty,lv=Object.getOwnPropertySymbols,Zq=Object.prototype.hasOwnProperty,Wq=Object.prototype.propertyIsEnumerable,M0=(t,e,n)=>e in t?Gq(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,hv=(t,e)=>{for(var n in e||(e={}))Zq.call(e,n)&&M0(t,n,e[n]);if(lv)for(var n of lv(e))Wq.call(e,n)&&M0(t,n,e[n]);return t},$e=(t,e,n)=>M0(t,typeof e!="symbol"?e+"":e,n);class z0 extends fO{constructor(e){var n;super(e),$e(this,"protocol",$8),$e(this,"version",A8),$e(this,"name",yu),$e(this,"relayUrl"),$e(this,"projectId"),$e(this,"customStoragePrefix"),$e(this,"events",new at.exports.EventEmitter),$e(this,"logger"),$e(this,"heartbeat"),$e(this,"relayer"),$e(this,"crypto"),$e(this,"storage"),$e(this,"history"),$e(this,"expirer"),$e(this,"pairing"),$e(this,"verify"),$e(this,"echoClient"),$e(this,"linkModeSupportedApps"),$e(this,"eventClient"),$e(this,"initialized",!1),$e(this,"logChunkController"),$e(this,"on",(a,c)=>this.events.on(a,c)),$e(this,"once",(a,c)=>this.events.once(a,c)),$e(this,"off",(a,c)=>this.events.off(a,c)),$e(this,"removeListener",(a,c)=>this.events.removeListener(a,c)),$e(this,"dispatchEnvelope",({topic:a,message:c,sessionExists:f})=>{if(!a||!c)return;const l={topic:a,message:c,publishedAt:Date.now(),transportType:Ae.link_mode};this.relayer.onLinkMessageEvent(l,{sessionExists:f})});const r=this.getGlobalCore(e?.customStoragePrefix);if(r)try{return this.customStoragePrefix=r.customStoragePrefix,this.logger=r.logger,this.heartbeat=r.heartbeat,this.crypto=r.crypto,this.history=r.history,this.expirer=r.expirer,this.storage=r.storage,this.relayer=r.relayer,this.pairing=r.pairing,this.verify=r.verify,this.echoClient=r.echoClient,this.linkModeSupportedApps=r.linkModeSupportedApps,this.eventClient=r.eventClient,this.initialized=r.initialized,this.logChunkController=r.logChunkController,r}catch(a){console.warn("Failed to copy global core",a)}this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||P8,this.customStoragePrefix=e!=null&&e.customStoragePrefix?`:${e.customStoragePrefix}`:"";const i=nO({level:typeof e?.logger=="string"&&e.logger?e.logger:bL.logger,name:yu}),{logger:s,chunkLoggerController:o}=Y2({opts:i,maxSizeInBytes:e?.maxLogBlobSizeInBytes,loggerOverride:e?.logger});this.logChunkController=o,(n=this.logChunkController)!=null&&n.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=sn(s,this.name),this.heartbeat=new Wh,this.crypto=new _k(this,this.logger,e?.keychain),this.history=new Tq(this,this.logger),this.expirer=new Cq(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new yA(hv(hv({},yL),e?.storageOptions)),this.relayer=new Yk({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new Dq(this,this.logger),this.verify=new kq(this,this.logger,this.storage),this.echoClient=new Mq(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new Kq(this,this.logger,e?.telemetryEnabled),this.setGlobalCore(this)}static async init(e){const n=new z0(e);await n.initialize();const r=await n.crypto.getClientId();return await n.storage.setItem(PL,r),n}get context(){return Gt(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(R8,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(R8)||[],this.initialized=!0,this.logger.info("Core Initialization Success")}catch(e){throw this.logger.warn(e,`Core Initialization Failure at epoch ${Date.now()}`),this.logger.error(e.message),e}}getGlobalCore(e=""){try{if(this.isGlobalCoreDisabled())return;const n=`_walletConnectCore_${e}`,r=`${n}_count`;return globalThis[r]=(globalThis[r]||0)+1,globalThis[r]>1&&console.warn(`WalletConnect Core is already initialized. This is probably a mistake and can lead to unexpected behavior. Init() was called ${globalThis[r]} times.`),globalThis[n]}catch(n){console.warn("Failed to get global WalletConnect core",n);return}}setGlobalCore(e){var n;try{if(this.isGlobalCoreDisabled())return;const r=`_walletConnectCore_${((n=e.opts)==null?void 0:n.customStoragePrefix)||""}`;globalThis[r]=e}catch(r){console.warn("Failed to set global WalletConnect core",r)}}isGlobalCoreDisabled(){try{return typeof process<"u"&&process.env.DISABLE_GLOBAL_CORE==="true"}catch{return!0}}}const H0=z0,dv="wc",pv=2,gv="client",V0=`${dv}@${pv}:${gv}:`,K0={name:gv,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.org"},bv="WALLETCONNECT_DEEPLINK_CHOICE",Yq="proposal",yv="Proposal expired",Xq="session",Po=Z.SEVEN_DAYS,Jq="engine",it={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}}},G0={min:Z.FIVE_MINUTES,max:Z.SEVEN_DAYS},er={idle:"IDLE",active:"ACTIVE"},Qq={eth_sendTransaction:{key:""},eth_sendRawTransaction:{key:""},wallet_sendCalls:{key:""},solana_signTransaction:{key:"signature"},solana_signAllTransactions:{key:"transactions"},solana_signAndSendTransaction:{key:"signature"},sui_signAndExecuteTransaction:{key:"digest"},sui_signTransaction:{key:""},hedera_signAndExecuteTransaction:{key:"transactionId"},hedera_executeTransaction:{key:"transactionId"},near_signTransaction:{key:""},near_signTransactions:{key:""},tron_signTransaction:{key:"txID"},xrpl_signTransaction:{key:""},xrpl_signTransactionFor:{key:""},algo_signTxn:{key:""},sendTransfer:{key:"txid"},stacks_stxTransfer:{key:"txId"},polkadot_signTransaction:{key:""},cosmos_signDirect:{key:""}},ej="request",tj=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],nj="wc",rj="auth",ij="authKeys",sj="pairingTopics",oj="requests",vu=`${nj}@${1.5}:${rj}:`,Eu=`${vu}:PUB_KEY`;var aj=Object.defineProperty,cj=Object.defineProperties,fj=Object.getOwnPropertyDescriptors,wv=Object.getOwnPropertySymbols,uj=Object.prototype.hasOwnProperty,lj=Object.prototype.propertyIsEnumerable,Z0=(t,e,n)=>e in t?aj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ye=(t,e)=>{for(var n in e||(e={}))uj.call(e,n)&&Z0(t,n,e[n]);if(wv)for(var n of wv(e))lj.call(e,n)&&Z0(t,n,e[n]);return t},st=(t,e)=>cj(t,fj(e)),G=(t,e,n)=>Z0(t,typeof e!="symbol"?e+"":e,n);class hj extends BO{constructor(e){super(e),G(this,"name",Jq),G(this,"events",new at.exports),G(this,"initialized",!1),G(this,"requestQueue",{state:er.idle,queue:[]}),G(this,"sessionRequestQueue",{state:er.idle,queue:[]}),G(this,"emittedSessionRequests",new AR({limit:500})),G(this,"requestQueueDelay",Z.ONE_SECOND),G(this,"expectedPairingMethodMap",new Map),G(this,"recentlyDeletedMap",new Map),G(this,"recentlyDeletedLimit",200),G(this,"relayMessageCache",[]),G(this,"pendingSessions",new Map),G(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(it)}),this.initialized=!0,setTimeout(async()=>{await this.processPendingMessageEvents(),this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()},Z.toMiliseconds(this.requestQueueDelay)))}),G(this,"connect",async n=>{var r;this.isInitialized(),await this.confirmOnlineStateOrThrow();const i=st(ye({},n),{requiredNamespaces:n.requiredNamespaces||{},optionalNamespaces:n.optionalNamespaces||{}});await this.isValidConnect(i),i.optionalNamespaces=kU(i.requiredNamespaces,i.optionalNamespaces),i.requiredNamespaces={};const{pairingTopic:s,requiredNamespaces:o,optionalNamespaces:a,sessionProperties:c,scopedProperties:f,relays:l,authentication:h,walletPay:d}=i,u=((r=h?.[0])==null?void 0:r.ttl)||it.wc_sessionPropose.req.ttl||Z.FIVE_MINUTES;this.validateRequestExpiry(u);let b=s,w,E=!1;try{if(b){const O=this.client.core.pairing.pairings.get(b);this.client.logger.warn("connect() with existing pairing topic is deprecated and will be removed in the next major release."),E=O.active}}catch(O){throw this.client.logger.error(`connect() -> pairing.get(${b}) failed`),O}if(!b||!E){const{topic:O,uri:M}=await this.client.core.pairing.create({internal:{skipSubscribe:!0}});b=O,w=M}if(!b){const{message:O}=W("NO_MATCHING_KEY",`connect() pairing topic: ${b}`);throw new Error(O)}const A=await this.client.core.crypto.generateKeyPair(),P=je(u),_=ye(st(ye(ye({requiredNamespaces:o,optionalNamespaces:a,relays:l??[{protocol:D8}],proposer:{publicKey:A,metadata:this.client.metadata},expiryTimestamp:P,pairingTopic:b},c&&{sessionProperties:c}),f&&{scopedProperties:f}),{id:Wn()}),(h||d)&&{requests:{authentication:h?.map(O=>{const{domain:M,chains:q,nonce:y,uri:p,exp:m,nbf:g,type:v,statement:S,requestId:B,resources:I,signatureTypes:$}=O;return{domain:M,chains:q,nonce:y,type:v??"caip122",aud:p,version:"1",iat:new Date().toISOString(),exp:m,nbf:g,statement:S,requestId:B,resources:I,signatureTypes:$}}),walletPay:d}}),x=we("session_connect",_.id),{reject:D,resolve:U,done:C}=xs(u,yv),L=({id:O})=>{O===_.id&&(this.client.events.off("proposal_expire",L),this.pendingSessions.delete(_.id),this.events.emit(x,{error:{message:yv,code:0}}))};return this.client.events.on("proposal_expire",L),this.events.once(x,({error:O,session:M})=>{this.client.events.off("proposal_expire",L),O?D(O):M&&U(M)}),await this.setProposal(_.id,_),await this.sendProposeSession({proposal:_,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:{correlationId:_.id}}}).catch(O=>{throw this.deleteProposal(_.id),O}),{uri:w,approval:C}}),G(this,"pair",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{return await this.client.core.pairing.pair(n)}catch(r){throw this.client.logger.error("pair() failed"),r}}),G(this,"approve",async n=>{var r,i,s;const o=this.client.core.eventClient.createEvent({properties:{topic:(r=n?.id)==null?void 0:r.toString(),trace:[Fn.session_approve_started]}});try{this.isInitialized(),await this.confirmOnlineStateOrThrow()}catch(M){throw o.setError(Ps.no_internet_connection),M}try{await this.isValidProposalId(n?.id)}catch(M){throw this.client.logger.error(`approve() -> proposal.get(${n?.id}) failed`),o.setError(Ps.proposal_not_found),M}try{await this.isValidApprove(n)}catch(M){throw this.client.logger.error("approve() -> isValidApprove() failed"),o.setError(Ps.session_approve_namespace_validation_failure),M}const{id:a,relayProtocol:c,namespaces:f,sessionProperties:l,scopedProperties:h,sessionConfig:d,proposalRequestsResponses:u}=n,b=this.client.proposal.get(a);this.client.core.eventClient.deleteEvent({eventId:o.eventId});const{pairingTopic:w,proposer:E,requiredNamespaces:A,optionalNamespaces:P}=b;let _=(i=this.client.core.eventClient)==null?void 0:i.getEvent({topic:w});_||(_=(s=this.client.core.eventClient)==null?void 0:s.createEvent({type:Fn.session_approve_started,properties:{topic:w,trace:[Fn.session_approve_started,Fn.session_namespaces_validation_success]}}));const x=await this.client.core.crypto.generateKeyPair(),D=E.publicKey,U=await this.client.core.crypto.generateSharedKey(x,D),C=st(ye(ye(ye({relay:{protocol:c??"irn"},namespaces:f,controller:{publicKey:x,metadata:this.client.metadata},expiry:je(Po)},l&&{sessionProperties:l}),h&&{scopedProperties:h}),d&&{sessionConfig:d}),{proposalRequestsResponses:u}),L=Ae.relay;_.addTrace(Fn.subscribing_session_topic);try{await this.client.core.relayer.subscribe(U,{transportType:L,internal:{skipSubscribe:!0}})}catch(M){throw _.setError(Ps.subscribe_session_topic_failure),M}_.addTrace(Fn.subscribe_session_topic_success);const O=st(ye({},C),{topic:U,requiredNamespaces:A,optionalNamespaces:P,pairingTopic:w,acknowledged:!1,self:C.controller,peer:{publicKey:E.publicKey,metadata:E.metadata},controller:x,transportType:Ae.relay,authentication:u?.authentication,walletPayResult:u?.walletPay});await this.client.session.set(U,O),_.addTrace(Fn.store_session);try{await this.sendApproveSession({sessionTopic:U,proposal:b,pairingProposalResponse:{relay:{protocol:c??"irn"},responderPublicKey:x},sessionSettleRequest:C,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:ye({correlationId:a},this.getTVFApproveParams(O))}}),_.addTrace(Fn.session_approve_publish_success)}catch(M){throw this.client.logger.error(M),this.client.session.delete(U,Oe("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe(U),M}return this.client.core.eventClient.deleteEvent({eventId:_.eventId}),await this.client.core.pairing.updateMetadata({topic:w,metadata:E.metadata}),await this.deleteProposal(a),await this.client.core.pairing.activate({topic:w}),await this.setExpiry(U,je(Po)),{topic:U,acknowledged:()=>Promise.resolve(this.client.session.get(U))}}),G(this,"reject",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidReject(n)}catch(o){throw this.client.logger.error("reject() -> isValidReject() failed"),o}const{id:r,reason:i}=n;let s;try{s=this.client.proposal.get(r).pairingTopic}catch(o){throw this.client.logger.error(`reject() -> proposal.get(${r}) failed`),o}s&&await this.sendError({id:r,topic:s,error:i,rpcOpts:it.wc_sessionPropose.reject}),await this.deleteProposal(r)}),G(this,"update",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidUpdate(n)}catch(h){throw this.client.logger.error("update() -> isValidUpdate() failed"),h}const{topic:r,namespaces:i}=n,{done:s,resolve:o,reject:a}=xs(Z.FIVE_MINUTES,"Session update request expired without receiving any acknowledgement"),c=Wn(),f=Zi().toString(),l=this.client.session.get(r).namespaces;return this.events.once(we("session_update",c),({error:h})=>{h?a(h):o()}),await this.client.session.update(r,{namespaces:i}),await this.sendRequest({topic:r,method:"wc_sessionUpdate",params:{namespaces:i},throwOnFailedPublish:!0,clientRpcId:c,relayRpcId:f}).catch(h=>{this.client.logger.error(h),this.client.session.update(r,{namespaces:l}),a(h)}),{acknowledged:s}}),G(this,"extend",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidExtend(n)}catch(c){throw this.client.logger.error("extend() -> isValidExtend() failed"),c}const{topic:r}=n,i=Wn(),{done:s,resolve:o,reject:a}=xs(Z.FIVE_MINUTES,"Session extend request expired without receiving any acknowledgement");return this.events.once(we("session_extend",i),({error:c})=>{c?a(c):o()}),await this.setExpiry(r,je(Po)),this.sendRequest({topic:r,method:"wc_sessionExtend",params:{},clientRpcId:i,throwOnFailedPublish:!0}).catch(c=>{a(c)}),{acknowledged:s}}),G(this,"request",async n=>{this.isInitialized();try{await this.isValidRequest(n)}catch(E){throw this.client.logger.error("request() -> isValidRequest() failed"),E}const{chainId:r,request:i,topic:s,expiry:o=it.wc_sessionRequest.req.ttl}=n,a=this.client.session.get(s);a?.transportType===Ae.relay&&await this.confirmOnlineStateOrThrow();const c=Wn(),f=Zi().toString(),{done:l,resolve:h,reject:d}=xs(o,"Request expired. Please try again.");this.events.once(we("session_request",c),({error:E,result:A})=>{E?d(E):h(A)});const u="wc_sessionRequest",b=this.getAppLinkIfEnabled(a.peer.metadata,a.transportType);if(b)return await this.sendRequest({clientRpcId:c,relayRpcId:f,topic:s,method:u,params:{request:st(ye({},i),{expiryTimestamp:je(o)}),chainId:r},expiry:o,throwOnFailedPublish:!0,appLink:b}).catch(E=>d(E)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:r,id:c}),await l();const w={request:st(ye({},i),{expiryTimestamp:je(o)}),chainId:r};return await Promise.all([new Promise(async E=>{await this.sendRequest({clientRpcId:c,relayRpcId:f,topic:s,method:u,params:w,expiry:o,throwOnFailedPublish:!0,tvf:this.getTVFParams(c,w)}).catch(A=>d(A)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:r,id:c}),E()}),new Promise(async E=>{var A;if(!((A=a.sessionConfig)!=null&&A.disableDeepLink)){const P=await _R(this.client.core.storage,bv);await vR({id:c,topic:s,wcDeepLink:P})}E()}),l()]).then(E=>E[2])}),G(this,"respond",async n=>{var r,i;this.isInitialized();const s=this.client.core.eventClient.createEvent({properties:{topic:n?.topic||((i=(r=n?.response)==null?void 0:r.id)==null?void 0:i.toString()),trace:[Fn.session_request_response_started]}});try{await this.isValidRespond(n)}catch(h){throw s.addTrace(h?.message),s.setError(Ps.session_request_response_validation_failure),h}s.addTrace(Fn.session_request_response_validation_success);const{topic:o,response:a}=n,{id:c}=a,f=this.client.session.get(o);f.transportType===Ae.relay&&await this.confirmOnlineStateOrThrow();const l=this.getAppLinkIfEnabled(f.peer.metadata,f.transportType);try{s.addTrace(Fn.session_request_response_publish_started),Yn(a)?await this.sendResult({id:c,topic:o,result:a.result,throwOnFailedPublish:!0,appLink:l}):wn(a)&&await this.sendError({id:c,topic:o,error:a.error,appLink:l}),this.cleanupAfterResponse(n)}catch(h){throw s.addTrace(h?.message),s.setError(Ps.session_request_response_publish_failure),h}}),G(this,"ping",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow();try{await this.isValidPing(n)}catch(i){throw this.client.logger.error("ping() -> isValidPing() failed"),i}const{topic:r}=n;if(this.client.session.keys.includes(r)){const i=Wn(),s=Zi().toString(),{done:o,resolve:a,reject:c}=xs(Z.FIVE_MINUTES,"Ping request expired without receiving any acknowledgement");this.events.once(we("session_ping",i),({error:f})=>{f?c(f):a()}),await Promise.all([this.sendRequest({topic:r,method:"wc_sessionPing",params:{},throwOnFailedPublish:!0,clientRpcId:i,relayRpcId:s}),o()])}else this.client.core.pairing.pairings.keys.includes(r)&&(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:r}))}),G(this,"emit",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidEmit(n);const{topic:r,event:i,chainId:s}=n,o=Zi().toString(),a=Wn();await this.sendRequest({topic:r,method:"wc_sessionEvent",params:{event:i,chainId:s},throwOnFailedPublish:!0,relayRpcId:o,clientRpcId:a})}),G(this,"disconnect",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidDisconnect(n);const{topic:r}=n;if(this.client.session.keys.includes(r))await this.sendRequest({topic:r,method:"wc_sessionDelete",params:Oe("USER_DISCONNECTED"),throwOnFailedPublish:!0}),await this.deleteSession({topic:r,emitEvent:!1});else if(this.client.core.pairing.pairings.keys.includes(r))await this.client.core.pairing.disconnect({topic:r});else{const{message:i}=W("MISMATCHED_TOPIC",`Session or pairing topic not found: ${r}`);throw new Error(i)}}),G(this,"find",n=>(this.isInitialized(),this.client.session.getAll().filter(r=>MU(r,n)))),G(this,"getPendingSessionRequests",()=>this.client.pendingRequest.getAll()),G(this,"authenticate",async(n,r)=>{var i;this.isInitialized(),this.isValidAuthenticate(n);const s=r&&this.client.core.linkModeSupportedApps.includes(r)&&((i=this.client.metadata.redirect)==null?void 0:i.linkMode),o=s?Ae.link_mode:Ae.relay;o===Ae.relay&&await this.confirmOnlineStateOrThrow();const{chains:a,statement:c="",uri:f,domain:l,nonce:h,type:d,exp:u,nbf:b,methods:w=[],expiry:E}=n,A=[...n.resources||[]],{topic:P,uri:_}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:o});this.client.logger.info({message:"Generated new pairing",pairing:{topic:P,uri:_}});const x=await this.client.core.crypto.generateKeyPair(),D=lu(x);if(await Promise.all([this.client.auth.authKeys.set(Eu,{responseTopic:D,publicKey:x}),this.client.auth.pairingTopics.set(D,{topic:D,pairingTopic:P})]),await this.client.core.relayer.subscribe(D,{transportType:o}),this.client.logger.info(`sending request to new pairing topic: ${P}`),w.length>0){const{namespace:I}=zf(a[0]);let $=qT(I,"request",w);Qf(A)&&($=MT($,A.pop())),A.push($)}const U=E&&E>it.wc_sessionAuthenticate.req.ttl?E:it.wc_sessionAuthenticate.req.ttl,C={authPayload:{type:d??"caip122",chains:a,statement:c,aud:f,domain:l,version:"1",nonce:h,iat:new Date().toISOString(),exp:u,nbf:b,resources:A},requester:{publicKey:x,metadata:this.client.metadata},expiryTimestamp:je(U)},L={eip155:{chains:a,methods:[...new Set(["personal_sign",...w])],events:["chainChanged","accountsChanged"]}},O={requiredNamespaces:{},optionalNamespaces:L,relays:[{protocol:"irn"}],pairingTopic:P,proposer:{publicKey:x,metadata:this.client.metadata},expiryTimestamp:je(it.wc_sessionPropose.req.ttl),id:Wn()},{done:M,resolve:q,reject:y}=xs(U,"Request expired"),p=Wn(),m=we("session_connect",O.id),g=we("session_request",p),v=async({error:I,session:$})=>{this.events.off(g,S),I?y(I):$&&q({session:$})},S=async I=>{var $,T,F;if(await this.deletePendingAuthRequest(p,{message:"fulfilled",code:0}),I.error){const H=Oe("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return I.error.code===H.code?void 0:(this.events.off(m,v),y(I.error.message))}await this.deleteProposal(O.id),this.events.off(m,v);const{cacaos:N,responder:k}=I.result,R=[],j=[];for(const H of N){await Wm({cacao:H,projectId:this.client.core.projectId})||(this.client.logger.error(H,"Signature verification failed"),y(Oe("SESSION_SETTLEMENT_FAILED","Signature verification failed")));const{p:K}=H,Y=Qf(K.resources),X=[Wd(K.iss)],ee=Jf(K.iss);if(Y){const se=Jm(Y),oe=Qm(Y);R.push(...se),X.push(...oe)}for(const se of X)j.push(`${se}:${ee}`)}const z=await this.client.core.crypto.generateSharedKey(x,k.publicKey);let V;R.length>0&&(V={topic:z,acknowledged:!0,self:{publicKey:x,metadata:this.client.metadata},peer:k,controller:k.publicKey,expiry:je(Po),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:P,namespaces:a8([...new Set(R)],[...new Set(j)]),transportType:o},await this.client.core.relayer.subscribe(z,{transportType:o}),await this.client.session.set(z,V),P&&await this.client.core.pairing.updateMetadata({topic:P,metadata:k.metadata}),V=this.client.session.get(z)),($=this.client.metadata.redirect)!=null&&$.linkMode&&(T=k.metadata.redirect)!=null&&T.linkMode&&(F=k.metadata.redirect)!=null&&F.universal&&r&&(this.client.core.addLinkModeSupportedApp(k.metadata.redirect.universal),this.client.session.update(z,{transportType:Ae.link_mode})),q({auths:N,session:V})};this.events.once(m,v),this.events.once(g,S);let B;try{if(s){const I=Lr("wc_sessionAuthenticate",C,p);this.client.core.history.set(P,I);const $=await this.client.core.crypto.encode("",I,{type:ja,encoding:Gi});B=du(r,P,$)}else await Promise.all([this.sendRequest({topic:P,method:"wc_sessionAuthenticate",params:C,expiry:n.expiry,throwOnFailedPublish:!0,clientRpcId:p}),this.sendRequest({topic:P,method:"wc_sessionPropose",params:O,expiry:it.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:O.id})])}catch(I){throw this.events.off(m,v),this.events.off(g,S),I}return await this.setProposal(O.id,O),await this.setAuthRequest(p,{request:st(ye({},C),{verifyContext:{}}),pairingTopic:P,transportType:o}),{uri:B??_,response:M}}),G(this,"approveSessionAuthenticate",async n=>{const{id:r,auths:i}=n,s=this.client.core.eventClient.createEvent({properties:{topic:r.toString(),trace:[Rs.authenticated_session_approve_started]}});try{this.isInitialized()}catch(E){throw s.setError(Ya.no_internet_connection),E}const o=this.getPendingAuthRequest(r);if(!o)throw s.setError(Ya.authenticated_session_pending_request_not_found),new Error(`Could not find pending auth request with id ${r}`);const a=o.transportType||Ae.relay;a===Ae.relay&&await this.confirmOnlineStateOrThrow();const c=o.requester.publicKey,f=await this.client.core.crypto.generateKeyPair(),l=lu(c),h={type:Nr,receiverPublicKey:c,senderPublicKey:f},d=[],u=[];for(const E of i){if(!await Wm({cacao:E,projectId:this.client.core.projectId})){s.setError(Ya.invalid_cacao);const D=Oe("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:r,topic:l,error:D,encodeOpts:h}),new Error(D.message)}s.addTrace(Rs.cacaos_verified);const{p:A}=E,P=Qf(A.resources),_=[Wd(A.iss)],x=Jf(A.iss);if(P){const D=Jm(P),U=Qm(P);d.push(...D),_.push(...U)}for(const D of _)u.push(`${D}:${x}`)}const b=await this.client.core.crypto.generateSharedKey(f,c);s.addTrace(Rs.create_authenticated_session_topic);let w;if(d?.length>0){w={topic:b,acknowledged:!0,self:{publicKey:f,metadata:this.client.metadata},peer:{publicKey:c,metadata:o.requester.metadata},controller:c,expiry:je(Po),authentication:i,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:o.pairingTopic,namespaces:a8([...new Set(d)],[...new Set(u)]),transportType:a},s.addTrace(Rs.subscribing_authenticated_session_topic);try{await this.client.core.relayer.subscribe(b,{transportType:a})}catch(E){throw s.setError(Ya.subscribe_authenticated_session_topic_failure),E}s.addTrace(Rs.subscribe_authenticated_session_topic_success),await this.client.session.set(b,w),s.addTrace(Rs.store_authenticated_session),await this.client.core.pairing.updateMetadata({topic:o.pairingTopic,metadata:o.requester.metadata})}s.addTrace(Rs.publishing_authenticated_session_approve);try{await this.sendResult({topic:l,id:r,result:{cacaos:i,responder:{publicKey:f,metadata:this.client.metadata}},encodeOpts:h,throwOnFailedPublish:!0,appLink:this.getAppLinkIfEnabled(o.requester.metadata,a)})}catch(E){throw s.setError(Ya.authenticated_session_approve_publish_failure),E}return await this.client.auth.requests.delete(r,{message:"fulfilled",code:0}),await this.client.core.pairing.activate({topic:o.pairingTopic}),this.client.core.eventClient.deleteEvent({eventId:s.eventId}),{session:w}}),G(this,"rejectSessionAuthenticate",async n=>{this.isInitialized();const{id:r,reason:i}=n,s=this.getPendingAuthRequest(r);if(!s)throw new Error(`Could not find pending auth request with id ${r}`);s.transportType===Ae.relay&&await this.confirmOnlineStateOrThrow();const o=s.requester.publicKey,a=await this.client.core.crypto.generateKeyPair(),c=lu(o),f={type:Nr,receiverPublicKey:o,senderPublicKey:a};await this.sendError({id:r,topic:c,error:i,encodeOpts:f,rpcOpts:it.wc_sessionAuthenticate.reject,appLink:this.getAppLinkIfEnabled(s.requester.metadata,s.transportType)}),await this.client.auth.requests.delete(r,{message:"rejected",code:0}),await this.deleteProposal(r)}),G(this,"formatAuthMessage",n=>{this.isInitialized();const{request:r,iss:i}=n;return Ym(r,i)}),G(this,"processRelayMessageCache",()=>{setTimeout(async()=>{if(this.relayMessageCache.length!==0)for(;this.relayMessageCache.length>0;)try{const n=this.relayMessageCache.shift();n&&await this.onRelayMessage(n)}catch(n){this.client.logger.error(n)}},50)}),G(this,"cleanupDuplicatePairings",async n=>{if(n.pairingTopic)try{const r=this.client.core.pairing.pairings.get(n.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)===n.peer.metadata.url&&s.topic&&s.topic!==r.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(r){this.client.logger.error(r)}}),G(this,"deleteSession",async n=>{var r;const{topic:i,expirerHasDeleted:s=!1,emitEvent:o=!0,id:a=0}=n,{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(bv).catch(f=>this.client.logger.warn(f)),i===((r=this.sessionRequestQueue.queue[0])==null?void 0:r.topic)&&(this.sessionRequestQueue.state=er.idle),await Promise.all(this.getPendingSessionRequests().filter(f=>f.topic===i).map(f=>this.deletePendingSessionRequest(f.id,Oe("USER_DISCONNECTED")))),o&&this.client.events.emit("session_delete",{id:a,topic:i})}),G(this,"deleteProposal",async(n,r)=>{if(r)try{const i=this.client.proposal.get(n);this.client.core.eventClient.getEvent({topic:i.pairingTopic})?.setError(Ps.proposal_expired)}catch{}await Promise.all([this.client.proposal.delete(n,Oe("USER_DISCONNECTED")),r?Promise.resolve():this.client.core.expirer.del(n)]),this.addToRecentlyDeleted(n,"proposal")}),G(this,"deletePendingSessionRequest",async(n,r,i=!1)=>{await Promise.all([this.client.pendingRequest.delete(n,r),i?Promise.resolve():this.client.core.expirer.del(n)]),this.addToRecentlyDeleted(n,"request"),this.sessionRequestQueue.queue=this.sessionRequestQueue.queue.filter(s=>s.id!==n),i&&(this.sessionRequestQueue.state=er.idle,this.client.events.emit("session_request_expire",{id:n}))}),G(this,"deletePendingAuthRequest",async(n,r,i=!1)=>{await Promise.all([this.client.auth.requests.delete(n,r),i?Promise.resolve():this.client.core.expirer.del(n)])}),G(this,"setExpiry",async(n,r)=>{this.client.session.keys.includes(n)&&(this.client.core.expirer.set(n,r),await this.client.session.update(n,{expiry:r}))}),G(this,"setProposal",async(n,r)=>{this.client.core.expirer.set(n,je(it.wc_sessionPropose.req.ttl)),await this.client.proposal.set(n,r)}),G(this,"setAuthRequest",async(n,r)=>{const{request:i,pairingTopic:s,transportType:o=Ae.relay}=r;this.client.core.expirer.set(n,i.expiryTimestamp),await this.client.auth.requests.set(n,{authPayload:i.authPayload,requester:i.requester,expiryTimestamp:i.expiryTimestamp,id:n,pairingTopic:s,verifyContext:i.verifyContext,transportType:o})}),G(this,"setPendingSessionRequest",async n=>{const{id:r,topic:i,params:s,verifyContext:o}=n,a=s.request.expiryTimestamp||je(it.wc_sessionRequest.req.ttl);this.client.core.expirer.set(r,a),await this.client.pendingRequest.set(r,{id:r,topic:i,params:s,verifyContext:o})}),G(this,"sendRequest",async n=>{const{topic:r,method:i,params:s,expiry:o,relayRpcId:a,clientRpcId:c,throwOnFailedPublish:f,appLink:l,tvf:h,publishOpts:d={}}=n,u=Lr(i,s,c);let b;const w=!!l;try{const P=w?Gi:Xt;b=await this.client.core.crypto.encode(r,u,{encoding:P})}catch(P){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${r} failed`),P}let E;if(tj.includes(i)){const P=yn(JSON.stringify(u)),_=yn(b);E=await this.client.core.verify.register({id:_,decryptedId:P})}const A=ye(ye({},it[i].req),d);if(A.attestation=E,o&&(A.ttl=o),a&&(A.id=a),this.client.core.history.set(r,u),w){const P=du(l,r,b);await global.Linking.openURL(P,this.client.name)}else A.tvf=st(ye({},h),{correlationId:u.id}),f?(A.internal=st(ye({},A.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(r,b,A)):this.client.core.relayer.publish(r,b,A).catch(P=>this.client.logger.error(P));return u.id}),G(this,"sendProposeSession",async n=>{const{proposal:r,publishOpts:i}=n,s=Lr("wc_sessionPropose",r,r.id);this.client.core.history.set(r.pairingTopic,s);const o=await this.client.core.crypto.encode(r.pairingTopic,s,{encoding:Xt}),a=yn(JSON.stringify(s)),c=yn(o),f=await this.client.core.verify.register({id:c,decryptedId:a});await this.client.core.relayer.publishCustom({payload:{pairingTopic:r.pairingTopic,sessionProposal:o},opts:st(ye({},i),{publishMethod:"wc_proposeSession",attestation:f})})}),G(this,"sendApproveSession",async n=>{const{sessionTopic:r,pairingProposalResponse:i,proposal:s,sessionSettleRequest:o,publishOpts:a}=n,c=gu(s.id,i),f=await this.client.core.crypto.encode(s.pairingTopic,c,{encoding:Xt}),l=Lr("wc_sessionSettle",o,a?.id),h=await this.client.core.crypto.encode(r,l,{encoding:Xt});this.client.core.history.set(r,l),await this.client.core.relayer.publishCustom({payload:{sessionTopic:r,pairingTopic:s.pairingTopic,sessionProposalResponse:f,sessionSettlementRequest:h},opts:st(ye({},a),{publishMethod:"wc_approveSession"})})}),G(this,"sendResult",async n=>{const{id:r,topic:i,result:s,throwOnFailedPublish:o,encodeOpts:a,appLink:c}=n,f=gu(r,s);let l;const h=c&&typeof(global==null?void 0:global.Linking)<"u";try{const b=h?Gi:Xt;l=await this.client.core.crypto.encode(i,f,st(ye({},a||{}),{encoding:b}))}catch(b){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${i} failed`),b}let d,u;try{d=await this.client.core.history.get(i,r);const b=d.request;try{u=this.getTVFParams(r,b.params,s)}catch(w){this.client.logger.warn(`sendResult() -> getTVFParams() failed: ${w?.message}`)}}catch(b){throw this.client.logger.error(`sendResult() -> history.get(${i}, ${r}) failed`),b}if(h){const b=du(c,i,l);await global.Linking.openURL(b,this.client.name)}else{const b=d.request.method,w=it[b].res;w.tvf=st(ye({},u),{correlationId:r}),o?(w.internal=st(ye({},w.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(i,l,w)):this.client.core.relayer.publish(i,l,w).catch(E=>this.client.logger.error(E))}await this.client.core.history.resolve(f)}),G(this,"sendError",async n=>{const{id:r,topic:i,error:s,encodeOpts:o,rpcOpts:a,appLink:c}=n,f=A0(r,s);let l;const h=c&&typeof(global==null?void 0:global.Linking)<"u";try{const u=h?Gi:Xt;l=await this.client.core.crypto.encode(i,f,st(ye({},o||{}),{encoding:u}))}catch(u){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${i} failed`),u}let d;try{d=await this.client.core.history.get(i,r)}catch(u){throw this.client.logger.error(`sendError() -> history.get(${i}, ${r}) failed`),u}if(h){const u=du(c,i,l);await global.Linking.openURL(u,this.client.name)}else{const u=d.request.method,b=a||it[u].res;this.client.core.relayer.publish(i,l,b)}await this.client.core.history.resolve(f)}),G(this,"cleanup",async()=>{const n=[],r=[];this.client.session.getAll().forEach(i=>{let s=!1;Ti(i.expiry)&&(s=!0),this.client.core.crypto.keychain.has(i.topic)||(s=!0),s&&n.push(i.topic)}),this.client.proposal.getAll().forEach(i=>{Ti(i.expiryTimestamp)&&r.push(i.id)}),await Promise.all([...n.map(i=>this.deleteSession({topic:i})),...r.map(i=>this.deleteProposal(i))])}),G(this,"onProviderMessageEvent",async n=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(n):await this.onRelayMessage(n)}),G(this,"onRelayEventRequest",async n=>{this.requestQueue.queue.push(n),await this.processRequestsQueue()}),G(this,"processRequestsQueue",async()=>{if(this.requestQueue.state===er.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=er.active;const n=this.requestQueue.queue.shift();if(n)try{await this.processRequest(n)}catch(r){this.client.logger.warn(r)}}this.requestQueue.state=er.idle}),G(this,"processRequest",async n=>{const{topic:r,payload:i,attestation:s,transportType:o,encryptedId:a}=n,c=i.method;if(!this.shouldIgnorePairingRequest({topic:r,requestMethod:c}))switch(c){case"wc_sessionPropose":return await this.onSessionProposeRequest({topic:r,payload:i,attestation:s,encryptedId:a});case"wc_sessionSettle":return await this.onSessionSettleRequest(r,i);case"wc_sessionUpdate":return await this.onSessionUpdateRequest(r,i);case"wc_sessionExtend":return await this.onSessionExtendRequest(r,i);case"wc_sessionPing":return await this.onSessionPingRequest(r,i);case"wc_sessionDelete":return await this.onSessionDeleteRequest(r,i);case"wc_sessionRequest":return await this.onSessionRequest({topic:r,payload:i,attestation:s,encryptedId:a,transportType:o});case"wc_sessionEvent":return await this.onSessionEventRequest(r,i);case"wc_sessionAuthenticate":return await this.onSessionAuthenticateRequest({topic:r,payload:i,attestation:s,encryptedId:a,transportType:o});default:return this.client.logger.info(`Unsupported request method ${c}`)}}),G(this,"onRelayEventResponse",async n=>{const{topic:r,payload:i,transportType:s}=n,o=(await this.client.core.history.get(r,i.id)).request.method;switch(o){case"wc_sessionPropose":return this.onSessionProposeResponse(r,i,s);case"wc_sessionSettle":return this.onSessionSettleResponse(r,i);case"wc_sessionUpdate":return this.onSessionUpdateResponse(r,i);case"wc_sessionExtend":return this.onSessionExtendResponse(r,i);case"wc_sessionPing":return this.onSessionPingResponse(r,i);case"wc_sessionRequest":return this.onSessionRequestResponse(r,i);case"wc_sessionAuthenticate":return this.onSessionAuthenticateResponse(r,i);default:return this.client.logger.info(`Unsupported response method ${o}`)}}),G(this,"onRelayEventUnknownPayload",n=>{const{topic:r}=n,{message:i}=W("MISSING_OR_INVALID",`Decoded payload on topic ${r} is not identifiable as a JSON-RPC request or a response.`);throw new Error(i)}),G(this,"shouldIgnorePairingRequest",n=>{const{topic:r,requestMethod:i}=n,s=this.expectedPairingMethodMap.get(r);return!s||s.includes(i)?!1:!!(s.includes("wc_sessionAuthenticate")&&this.client.events.listenerCount("session_authenticate")>0)}),G(this,"onSessionProposeRequest",async n=>{const{topic:r,payload:i,attestation:s,encryptedId:o}=n,{params:a,id:c}=i;try{const f=this.client.core.eventClient.getEvent({topic:r});this.client.events.listenerCount("session_proposal")===0&&(console.warn("No listener for session_proposal event"),f?.setError(Fr.proposal_listener_not_found)),this.isValidConnect(ye({},i.params));const l=a.expiryTimestamp||je(it.wc_sessionPropose.req.ttl),h=ye({id:c,pairingTopic:r,expiryTimestamp:l,attestation:s,encryptedId:o},a);await this.setProposal(c,h);const d=await this.getVerifyContext({attestationId:s,hash:yn(JSON.stringify(i)),encryptedId:o,metadata:h.proposer.metadata});f?.addTrace(Jn.emit_session_proposal),this.client.events.emit("session_proposal",{id:c,params:h,verifyContext:d})}catch(f){await this.sendError({id:c,topic:r,error:f,rpcOpts:it.wc_sessionPropose.autoReject}),this.client.logger.error(f)}}),G(this,"onSessionProposeResponse",async(n,r,i)=>{const{id:s}=r;if(Yn(r)){const{result:o}=r;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 l=await this.client.core.crypto.generateSharedKey(c,f);this.pendingSessions.set(s,{sessionTopic:l,pairingTopic:n,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:n})}else if(wn(r)){await this.deleteProposal(s);const o=we("session_connect",s);if(this.events.listenerCount(o)===0)throw new Error(`emitting ${o} without any listeners, 954`);this.events.emit(o,{error:r.error})}}),G(this,"onSessionSettleRequest",async(n,r)=>{const{id:i,params:s}=r;try{this.isValidSessionSettleRequest(s);const{relay:o,controller:a,expiry:c,namespaces:f,sessionProperties:l,scopedProperties:h,sessionConfig:d,proposalRequestsResponses:u}=r.params,b=[...this.pendingSessions.values()].find(A=>A.sessionTopic===n);if(!b)return this.client.logger.error(`Pending session not found for topic ${n}`);const w=this.client.proposal.get(b.proposalId),E=st(ye(ye(ye({topic:n,relay:o,expiry:c,namespaces:f,acknowledged:!0,pairingTopic:b.pairingTopic,requiredNamespaces:w.requiredNamespaces,optionalNamespaces:w.optionalNamespaces,controller:a.publicKey,self:{publicKey:b.publicKey,metadata:this.client.metadata},peer:{publicKey:a.publicKey,metadata:a.metadata}},l&&{sessionProperties:l}),h&&{scopedProperties:h}),d&&{sessionConfig:d}),{transportType:Ae.relay,authentication:u?.authentication,walletPayResult:u?.walletPay});await this.client.session.set(E.topic,E),await this.setExpiry(E.topic,E.expiry),await this.client.core.pairing.updateMetadata({topic:b.pairingTopic,metadata:E.peer.metadata}),this.pendingSessions.delete(b.proposalId),this.deleteProposal(b.proposalId,!1),this.cleanupDuplicatePairings(E),await this.sendResult({id:r.id,topic:n,throwOnFailedPublish:!0,result:!0}),this.client.events.emit("session_connect",{session:E}),this.events.emit(we("session_connect",b.proposalId),{session:E})}catch(o){await this.sendError({id:i,topic:n,error:o}),this.client.logger.error(o)}}),G(this,"onSessionSettleResponse",async(n,r)=>{const{id:i}=r;Yn(r)?(await this.client.session.update(n,{acknowledged:!0}),this.events.emit(we("session_approve",i),{})):wn(r)&&(await this.client.session.delete(n,Oe("USER_DISCONNECTED")),this.events.emit(we("session_approve",i),{error:r.error}))}),G(this,"onSessionUpdateRequest",async(n,r)=>{const{params:i,id:s}=r;try{const o=`${n}_session_update`,a=Va.get(o);if(a&&this.isRequestOutOfSync(a,s)){this.client.logger.warn(`Discarding out of sync request - ${s}`),this.sendError({id:s,topic:n,error:Oe("INVALID_UPDATE_REQUEST")});return}this.isValidUpdate(ye({topic:n},i));try{Va.set(o,s),await this.client.session.update(n,{namespaces:i.namespaces}),await this.sendResult({id:s,topic:n,result:!0})}catch(c){throw Va.delete(o),c}this.client.events.emit("session_update",{id:s,topic:n,params:i})}catch(o){await this.sendError({id:s,topic:n,error:o}),this.client.logger.error(o)}}),G(this,"isRequestOutOfSync",(n,r)=>r.toString().slice(0,-3)<n.toString().slice(0,-3)),G(this,"onSessionUpdateResponse",(n,r)=>{const{id:i}=r,s=we("session_update",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);Yn(r)?this.events.emit(we("session_update",i),{}):wn(r)&&this.events.emit(we("session_update",i),{error:r.error})}),G(this,"onSessionExtendRequest",async(n,r)=>{const{id:i}=r;try{this.isValidExtend({topic:n}),await this.setExpiry(n,je(Po)),await this.sendResult({id:i,topic:n,result:!0}),this.client.events.emit("session_extend",{id:i,topic:n})}catch(s){await this.sendError({id:i,topic:n,error:s}),this.client.logger.error(s)}}),G(this,"onSessionExtendResponse",(n,r)=>{const{id:i}=r,s=we("session_extend",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);Yn(r)?this.events.emit(we("session_extend",i),{}):wn(r)&&this.events.emit(we("session_extend",i),{error:r.error})}),G(this,"onSessionPingRequest",async(n,r)=>{const{id:i}=r;try{this.isValidPing({topic:n}),await this.sendResult({id:i,topic:n,result:!0,throwOnFailedPublish:!0}),this.client.events.emit("session_ping",{id:i,topic:n})}catch(s){await this.sendError({id:i,topic:n,error:s}),this.client.logger.error(s)}}),G(this,"onSessionPingResponse",(n,r)=>{const{id:i}=r,s=we("session_ping",i);setTimeout(()=>{if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners 2176`);Yn(r)?this.events.emit(we("session_ping",i),{}):wn(r)&&this.events.emit(we("session_ping",i),{error:r.error})},500)}),G(this,"onSessionDeleteRequest",async(n,r)=>{const{id:i}=r;try{await this.isValidDisconnect({topic:n,reason:r.params}),this.cleanupPendingSentRequestsForTopic({topic:n,error:Oe("USER_DISCONNECTED")}),await this.deleteSession({topic:n,id:i})}catch(s){this.client.logger.error(s)}}),G(this,"onSessionRequest",async n=>{var r,i,s;const{topic:o,payload:a,attestation:c,encryptedId:f,transportType:l}=n,{id:h,params:d}=a;try{await this.isValidRequest(ye({topic:o},d));const u=this.client.session.get(o),b=await this.getVerifyContext({attestationId:c,hash:yn(JSON.stringify(Lr("wc_sessionRequest",d,h))),encryptedId:f,metadata:u.peer.metadata,transportType:l}),w={id:h,topic:o,params:d,verifyContext:b};await this.setPendingSessionRequest(w),l===Ae.link_mode&&(r=u.peer.metadata.redirect)!=null&&r.universal&&this.client.core.addLinkModeSupportedApp((i=u.peer.metadata.redirect)==null?void 0:i.universal),(s=this.client.signConfig)!=null&&s.disableRequestQueue?this.emitSessionRequest(w):(this.addSessionRequestToSessionRequestQueue(w),this.processSessionRequestQueue())}catch(u){await this.sendError({id:h,topic:o,error:u}),this.client.logger.error(u)}}),G(this,"onSessionRequestResponse",(n,r)=>{const{id:i}=r,s=we("session_request",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);Yn(r)?this.events.emit(we("session_request",i),{result:r.result}):wn(r)&&this.events.emit(we("session_request",i),{error:r.error})}),G(this,"onSessionEventRequest",async(n,r)=>{const{id:i,params:s}=r;try{const o=`${n}_session_event_${s.event.name}`,a=Va.get(o);if(a&&this.isRequestOutOfSync(a,i)){this.client.logger.info(`Discarding out of sync request - ${i}`);return}this.isValidEmit(ye({topic:n},s)),this.client.events.emit("session_event",{id:i,topic:n,params:s}),Va.set(o,i)}catch(o){await this.sendError({id:i,topic:n,error:o}),this.client.logger.error(o)}}),G(this,"onSessionAuthenticateResponse",(n,r)=>{const{id:i}=r;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:n,payload:r}),Yn(r)?this.events.emit(we("session_request",i),{result:r.result}):wn(r)&&this.events.emit(we("session_request",i),{error:r.error})}),G(this,"onSessionAuthenticateRequest",async n=>{var r;const{topic:i,payload:s,attestation:o,encryptedId:a,transportType:c}=n;try{const{requester:f,authPayload:l,expiryTimestamp:h}=s.params,d=await this.getVerifyContext({attestationId:o,hash:yn(JSON.stringify(s)),encryptedId:a,metadata:f.metadata,transportType:c}),u={requester:f,pairingTopic:i,id:s.id,authPayload:l,verifyContext:d,expiryTimestamp:h};await this.setAuthRequest(s.id,{request:u,pairingTopic:i,transportType:c}),c===Ae.link_mode&&(r=f.metadata.redirect)!=null&&r.universal&&this.client.core.addLinkModeSupportedApp(f.metadata.redirect.universal),this.client.events.emit("session_authenticate",{topic:i,params:s.params,id:s.id,verifyContext:d})}catch(f){this.client.logger.error(f);const l=s.params.requester.publicKey,h=await this.client.core.crypto.generateKeyPair(),d=this.getAppLinkIfEnabled(s.params.requester.metadata,c),u={type:Nr,receiverPublicKey:l,senderPublicKey:h};await this.sendError({id:s.id,topic:i,error:f,encodeOpts:u,rpcOpts:it.wc_sessionAuthenticate.autoReject,appLink:d})}}),G(this,"addSessionRequestToSessionRequestQueue",n=>{this.sessionRequestQueue.queue.push(n)}),G(this,"cleanupAfterResponse",n=>{this.deletePendingSessionRequest(n.response.id,{message:"fulfilled",code:0}),setTimeout(()=>{this.sessionRequestQueue.state=er.idle,this.processSessionRequestQueue()},Z.toMiliseconds(this.requestQueueDelay))}),G(this,"cleanupPendingSentRequestsForTopic",({topic:n,error:r})=>{const i=this.client.core.history.pending;i.length>0&&i.filter(s=>s.topic===n&&s.request.method==="wc_sessionRequest").forEach(s=>{this.events.emit(we("session_request",s.request.id),{error:r})})}),G(this,"processSessionRequestQueue",()=>{if(this.sessionRequestQueue.state===er.active){this.client.logger.info("session request queue is already active.");return}const n=this.sessionRequestQueue.queue[0];if(!n){this.client.logger.info("session request queue is empty.");return}try{this.emitSessionRequest(n)}catch(r){this.client.logger.error(r)}}),G(this,"emitSessionRequest",n=>{if(this.emittedSessionRequests.has(n.id)){this.client.logger.warn({id:n.id},`Skipping emitting \`session_request\` event for duplicate request. id: ${n.id}`);return}this.sessionRequestQueue.state=er.active,this.emittedSessionRequests.add(n.id),this.client.events.emit("session_request",n)}),G(this,"onPairingCreated",n=>{if(n.methods&&this.expectedPairingMethodMap.set(n.topic,n.methods),n.active)return;const r=this.client.proposal.getAll().find(i=>i.pairingTopic===n.topic);r&&this.onSessionProposeRequest({topic:n.topic,payload:Lr("wc_sessionPropose",st(ye({},r),{requiredNamespaces:r.requiredNamespaces,optionalNamespaces:r.optionalNamespaces,relays:r.relays,proposer:r.proposer,sessionProperties:r.sessionProperties,scopedProperties:r.scopedProperties}),r.id),attestation:r.attestation,encryptedId:r.encryptedId})}),G(this,"isValidConnect",async n=>{if(!Jt(n)){const{message:f}=W("MISSING_OR_INVALID",`connect() params: ${JSON.stringify(n)}`);throw new Error(f)}const{pairingTopic:r,requiredNamespaces:i,optionalNamespaces:s,sessionProperties:o,scopedProperties:a,relays:c}=n;if(ze(r)||await this.isValidPairingTopic(r),!eC(c,!0)){const{message:f}=W("MISSING_OR_INVALID",`connect() relays: ${c}`);throw new Error(f)}if(i&&!ze(i)&&Ha(i)!==0){const f="requiredNamespaces are deprecated and are automatically assigned to optionalNamespaces";["fatal","error","silent"].includes(this.client.logger.level)?console.warn(f):this.client.logger.warn(f),this.validateNamespaces(i,"requiredNamespaces")}if(s&&!ze(s)&&Ha(s)!==0&&this.validateNamespaces(s,"optionalNamespaces"),o&&!ze(o)&&this.validateSessionProps(o,"sessionProperties"),a&&!ze(a)){this.validateSessionProps(a,"scopedProperties");const f=Object.keys(i||{}).concat(Object.keys(s||{}));if(!Object.keys(a).every(l=>f.includes(l.split(":")[0])))throw new Error(`Scoped properties must be a subset of required/optional namespaces, received: ${JSON.stringify(a)}, required/optional namespaces: ${JSON.stringify(f)}`)}}),G(this,"validateNamespaces",(n,r)=>{const i=QU(n,"connect()",r);if(i)throw new Error(i.message)}),G(this,"isValidApprove",async n=>{if(!Jt(n))throw new Error(W("MISSING_OR_INVALID",`approve() params: ${n}`).message);const{id:r,namespaces:i,relayProtocol:s,sessionProperties:o,scopedProperties:a}=n;this.checkRecentlyDeleted(r),await this.isValidProposalId(r);const c=this.client.proposal.get(r),f=E0(i,"approve()");if(f)throw new Error(f.message);const l=h8(c.requiredNamespaces,i,"approve()");if(l)throw new Error(l.message);if(!Ne(s,!0)){const{message:h}=W("MISSING_OR_INVALID",`approve() relayProtocol: ${s}`);throw new Error(h)}if(o&&!ze(o)&&this.validateSessionProps(o,"sessionProperties"),a&&!ze(a)){this.validateSessionProps(a,"scopedProperties");const h=new Set(Object.keys(i));if(!Object.keys(a).every(d=>h.has(d.split(":")[0])))throw new Error(`Scoped properties must be a subset of approved namespaces, received: ${JSON.stringify(a)}, approved namespaces: ${Array.from(h).join(", ")}`)}}),G(this,"isValidReject",async n=>{if(!Jt(n)){const{message:s}=W("MISSING_OR_INVALID",`reject() params: ${n}`);throw new Error(s)}const{id:r,reason:i}=n;if(this.checkRecentlyDeleted(r),await this.isValidProposalId(r),!nC(i)){const{message:s}=W("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(i)}`);throw new Error(s)}}),G(this,"isValidSessionSettleRequest",n=>{if(!Jt(n)){const{message:f}=W("MISSING_OR_INVALID",`onSessionSettleRequest() params: ${n}`);throw new Error(f)}const{relay:r,controller:i,namespaces:s,expiry:o}=n;if(!u8(r)){const{message:f}=W("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(f)}const a=GU(i,"onSessionSettleRequest()");if(a)throw new Error(a.message);const c=E0(s,"onSessionSettleRequest()");if(c)throw new Error(c.message);if(Ti(o)){const{message:f}=W("EXPIRED","onSessionSettleRequest()");throw new Error(f)}}),G(this,"isValidUpdate",async n=>{if(!Jt(n)){const{message:c}=W("MISSING_OR_INVALID",`update() params: ${n}`);throw new Error(c)}const{topic:r,namespaces:i}=n;this.checkRecentlyDeleted(r),await this.isValidSessionTopic(r);const s=this.client.session.get(r),o=E0(i,"update()");if(o)throw new Error(o.message);const a=h8(s.requiredNamespaces,i,"update()");if(a)throw new Error(a.message)}),G(this,"isValidExtend",async n=>{if(!Jt(n)){const{message:i}=W("MISSING_OR_INVALID",`extend() params: ${n}`);throw new Error(i)}const{topic:r}=n;this.checkRecentlyDeleted(r),await this.isValidSessionTopic(r)}),G(this,"isValidRequest",async n=>{if(!Jt(n)){const{message:c}=W("MISSING_OR_INVALID",`request() params: ${n}`);throw new Error(c)}const{topic:r,request:i,chainId:s,expiry:o}=n;this.checkRecentlyDeleted(r),await this.isValidSessionTopic(r);const{namespaces:a}=this.client.session.get(r);if(!l8(a,s)){const{message:c}=W("MISSING_OR_INVALID",`request() chainId: ${s}`);throw new Error(c)}if(!rC(i)){const{message:c}=W("MISSING_OR_INVALID",`request() ${JSON.stringify(i)}`);throw new Error(c)}if(!oC(a,s,i.method)){const{message:c}=W("MISSING_OR_INVALID",`request() method: ${i.method}`);throw new Error(c)}this.validateRequestExpiry(o)}),G(this,"isValidRespond",async n=>{var r;if(!Jt(n)){const{message:a}=W("MISSING_OR_INVALID",`respond() params: ${n}`);throw new Error(a)}const{topic:i,response:s}=n;try{await this.isValidSessionTopic(i)}catch(a){throw(r=n?.response)!=null&&r.id&&this.cleanupAfterResponse(n),a}if(!iC(s)){const{message:a}=W("MISSING_OR_INVALID",`respond() response: ${JSON.stringify(s)}`);throw new Error(a)}const o=this.client.pendingRequest.get(s.id);if(o.topic!==i){const{message:a}=W("MISMATCHED_TOPIC",`Request response topic mismatch. reqId: ${s.id}, expected topic: ${o.topic}, received topic: ${i}`);throw new Error(a)}}),G(this,"isValidPing",async n=>{if(!Jt(n)){const{message:i}=W("MISSING_OR_INVALID",`ping() params: ${n}`);throw new Error(i)}const{topic:r}=n;await this.isValidSessionOrPairingTopic(r)}),G(this,"isValidEmit",async n=>{if(!Jt(n)){const{message:a}=W("MISSING_OR_INVALID",`emit() params: ${n}`);throw new Error(a)}const{topic:r,event:i,chainId:s}=n;await this.isValidSessionTopic(r);const{namespaces:o}=this.client.session.get(r);if(!l8(o,s)){const{message:a}=W("MISSING_OR_INVALID",`emit() chainId: ${s}`);throw new Error(a)}if(!sC(i)){const{message:a}=W("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}if(!aC(o,s,i.name)){const{message:a}=W("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}}),G(this,"isValidDisconnect",async n=>{if(!Jt(n)){const{message:i}=W("MISSING_OR_INVALID",`disconnect() params: ${n}`);throw new Error(i)}const{topic:r}=n;await this.isValidSessionOrPairingTopic(r)}),G(this,"isValidAuthenticate",n=>{const{chains:r,uri:i,domain:s,nonce:o}=n;if(!Array.isArray(r)||r.length===0)throw new Error("chains is required and must be a non-empty array");if(!Ne(i,!1))throw new Error("uri is required parameter");if(!Ne(s,!1))throw new Error("domain is required parameter");if(!Ne(o,!1))throw new Error("nonce is required parameter");if([...new Set(r.map(c=>zf(c).namespace))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");const{namespace:a}=zf(r[0]);if(a!=="eip155")throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")}),G(this,"getVerifyContext",async n=>{const{attestationId:r,hash:i,encryptedId:s,metadata:o,transportType:a}=n,c={verified:{verifyUrl:o.verifyUrl||Wa,validation:"UNKNOWN",origin:o.url||""}};try{if(a===Ae.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 f=await this.client.core.verify.resolve({attestationId:r,hash:i,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}),G(this,"validateSessionProps",(n,r)=>{Object.values(n).forEach((i,s)=>{if(i==null){const{message:o}=W("MISSING_OR_INVALID",`${r} must contain an existing value for each key. Received: ${i} for key ${Object.keys(n)[s]}`);throw new Error(o)}})}),G(this,"getPendingAuthRequest",n=>{const r=this.client.auth.requests.get(n);return typeof r=="object"?r:void 0}),G(this,"addToRecentlyDeleted",(n,r)=>{if(this.recentlyDeletedMap.set(n,r),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)}}}),G(this,"checkRecentlyDeleted",n=>{const r=this.recentlyDeletedMap.get(n);if(r){const{message:i}=W("MISSING_OR_INVALID",`Record was recently deleted - ${r}: ${n}`);throw new Error(i)}}),G(this,"isLinkModeEnabled",(n,r)=>{var i,s,o,a,c,f,l,h,d;return!n||r!==Ae.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&&((f=(c=this.client.metadata)==null?void 0:c.redirect)==null?void 0:f.universal)!==""&&((l=n?.redirect)==null?void 0:l.universal)!==void 0&&((h=n?.redirect)==null?void 0:h.universal)!==""&&((d=n?.redirect)==null?void 0:d.linkMode)===!0&&this.client.core.linkModeSupportedApps.includes(n.redirect.universal)&&typeof(global==null?void 0:global.Linking)<"u"}),G(this,"getAppLinkIfEnabled",(n,r)=>{var i;return this.isLinkModeEnabled(n,r)?(i=n?.redirect)==null?void 0:i.universal:void 0}),G(this,"handleLinkModeMessage",({url:n})=>{if(!n||!n.includes("wc_ev")||!n.includes("topic"))return;const r=xm(n,"topic")||"",i=decodeURIComponent(xm(n,"wc_ev")||""),s=this.client.session.keys.includes(r);s&&this.client.session.update(r,{transportType:Ae.link_mode}),this.client.core.dispatchEnvelope({topic:r,message:i,sessionExists:s})}),G(this,"registerLinkModeListeners",async()=>{var n;if(jd()||Ri()&&(n=this.client.metadata.redirect)!=null&&n.linkMode){const r=global==null?void 0:global.Linking;if(typeof r<"u"){r.addEventListener("url",this.handleLinkModeMessage,this.client.name);const i=await r.getInitialURL();i&&setTimeout(()=>{this.handleLinkModeMessage({url:i})},50)}}}),G(this,"getTVFApproveParams",n=>{try{const r=i8(n.namespaces),i=TU(n.namespaces),s=NU(n.namespaces),o=n.sessionProperties,a=n.scopedProperties;return{approvedChains:r,approvedMethods:i,approvedEvents:s,sessionProperties:o,scopedProperties:a}}catch(r){return this.client.logger.warn(r,"Error getting TVF approve params"),{}}}),G(this,"getTVFParams",(n,r,i)=>{var s,o,a;if(!((s=r.request)!=null&&s.method))return{};const c={correlationId:n,rpcMethods:[r.request.method],chainId:r.chainId};try{const f=this.extractTxHashesFromResult(r.request,i);c.txHashes=f,c.contractAddresses=this.isValidContractData(r.request.params)?[(a=(o=r.request.params)==null?void 0:o[0])==null?void 0:a.to]:[]}catch(f){this.client.logger.warn(f,"Error getting TVF params")}return c}),G(this,"isValidContractData",n=>{var r;if(!n)return!1;try{const i=n?.data||((r=n?.[0])==null?void 0:r.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}),G(this,"extractTxHashesFromResult",(n,r)=>{var i;try{if(!r)return[];const s=n.method,o=Qq[s];if(s==="sui_signTransaction")return[ET(r.transactionBytes)];if(s==="near_signTransaction")return[Hm(r)];if(s==="near_signTransactions")return r.map(c=>Hm(c));if(s==="xrpl_signTransactionFor"||s==="xrpl_signTransaction")return[(i=r.tx_json)==null?void 0:i.hash];if(s==="polkadot_signTransaction")return[IC({transaction:n.params.transactionPayload,signature:r.signature})];if(s==="algo_signTxn")return Ao(r)?r.map(c=>Vm(c)):[Vm(r)];if(s==="cosmos_signDirect")return[_T(r)];if(s==="wallet_sendCalls")return ST(r);if(typeof r=="string")return[r];const a=r[o.key];if(Ao(a))return s==="solana_signAllTransactions"?a.map(c=>vT(c)):a;if(typeof a=="string")return[a]}catch(s){this.client.logger.warn(s,"Error extracting tx hashes from result")}return[]})}async processPendingMessageEvents(){try{const e=this.client.session.keys,n=this.client.core.relayer.messages.getWithoutAck(e);for(const[r,i]of Object.entries(n))for(const s of i)try{await this.onProviderMessageEvent({topic:r,message:s,publishedAt:Date.now()})}catch{this.client.logger.warn(`Error processing pending message event for topic: ${r}, message: ${s}`)}}catch(e){this.client.logger.warn(e,"processPendingMessageEvents failed")}}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}async confirmOnlineStateOrThrow(){await this.client.core.relayer.confirmOnlineStateOrThrow()}registerRelayerEvents(){this.client.core.relayer.on(Ue.message,e=>{this.onProviderMessageEvent(e)})}async onRelayMessage(e){const{topic:n,message:r,attestation:i,transportType:s}=e,{publicKey:o}=this.client.auth.authKeys.keys.includes(Eu)?this.client.auth.authKeys.get(Eu):{responseTopic:void 0,publicKey:void 0};try{const a=await this.client.core.crypto.decode(n,r,{receiverPublicKey:o,encoding:s===Ae.link_mode?Gi:Xt});O0(a)?(this.client.core.history.set(n,a),await this.onRelayEventRequest({topic:n,payload:a,attestation:i,transportType:s,encryptedId:yn(r)})):bu(a)?(await this.client.core.history.resolve(a),await this.onRelayEventResponse({topic:n,payload:a,transportType:s}),this.client.core.history.delete(n,a.id)):(this.client.logger.error(`onRelayMessage() -> unknown payload: ${JSON.stringify(a)}`),await this.onRelayEventUnknownPayload({topic:n,payload:a,transportType:s})),await this.client.core.relayer.messages.ack(n,r)}catch(a){this.client.logger.error(`onRelayMessage() -> failed to process an inbound message: ${r}`),this.client.logger.error(a)}}registerExpirerEvents(){this.client.core.expirer.on(vn.expired,async e=>{const{topic:n,id:r}=Em(e.target);if(r&&this.client.pendingRequest.keys.includes(r))return await this.deletePendingSessionRequest(r,W("EXPIRED"),!0);if(r&&this.client.auth.requests.keys.includes(r))return await this.deletePendingAuthRequest(r,W("EXPIRED"),!0);n?this.client.session.keys.includes(n)&&(await this.deleteSession({topic:n,expirerHasDeleted:!0}),this.client.events.emit("session_expire",{topic:n})):r&&(await this.deleteProposal(r,!0),this.client.events.emit("proposal_expire",{id:r}))})}registerPairingEvents(){this.client.core.pairing.events.on(Ds.create,e=>this.onPairingCreated(e)),this.client.core.pairing.events.on(Ds.delete,e=>{this.addToRecentlyDeleted(e.topic,"pairing")})}isValidPairingTopic(e){if(!Ne(e,!1)){const{message:n}=W("MISSING_OR_INVALID",`pairing topic should be a string: ${e}`);throw new Error(n)}if(!this.client.core.pairing.pairings.keys.includes(e)){const{message:n}=W("NO_MATCHING_KEY",`pairing topic doesn't exist: ${e}`);throw new Error(n)}if(Ti(this.client.core.pairing.pairings.get(e).expiry)){const{message:n}=W("EXPIRED",`pairing topic: ${e}`);throw new Error(n)}}async isValidSessionTopic(e){if(!Ne(e,!1)){const{message:n}=W("MISSING_OR_INVALID",`session topic should be a string: ${e}`);throw new Error(n)}if(this.checkRecentlyDeleted(e),!this.client.session.keys.includes(e)){const{message:n}=W("NO_MATCHING_KEY",`session topic doesn't exist: ${e}`);throw new Error(n)}if(Ti(this.client.session.get(e).expiry)){await this.deleteSession({topic:e});const{message:n}=W("EXPIRED",`session topic: ${e}`);throw new Error(n)}if(!this.client.core.crypto.keychain.has(e)){const{message:n}=W("MISSING_OR_INVALID",`session topic does not exist in keychain: ${e}`);throw await this.deleteSession({topic:e}),new Error(n)}}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(Ne(e,!1)){const{message:n}=W("NO_MATCHING_KEY",`session or pairing topic doesn't exist: ${e}`);throw new Error(n)}else{const{message:n}=W("MISSING_OR_INVALID",`session or pairing topic should be a string: ${e}`);throw new Error(n)}}async isValidProposalId(e){if(!tC(e)){const{message:n}=W("MISSING_OR_INVALID",`proposal id should be a number: ${e}`);throw new Error(n)}if(!this.client.proposal.keys.includes(e)){const{message:n}=W("NO_MATCHING_KEY",`proposal id doesn't exist: ${e}`);throw new Error(n)}if(Ti(this.client.proposal.get(e).expiryTimestamp)){await this.deleteProposal(e);const{message:n}=W("EXPIRED",`proposal id: ${e}`);throw new Error(n)}}validateRequestExpiry(e){if(e&&!uC(e,G0)){const{message:n}=W("MISSING_OR_INVALID",`request() expiry: ${e}. Expiry must be a number (in seconds) between ${G0.min} and ${G0.max}`);throw new Error(n)}}}class dj extends Ts{constructor(e,n){super(e,n,Yq,V0),this.core=e,this.logger=n}}class mv extends Ts{constructor(e,n){super(e,n,Xq,V0),this.core=e,this.logger=n}}class pj extends Ts{constructor(e,n){super(e,n,ej,V0,r=>r.id),this.core=e,this.logger=n}}class gj extends Ts{constructor(e,n){super(e,n,ij,vu,()=>Eu),this.core=e,this.logger=n}}class bj extends Ts{constructor(e,n){super(e,n,sj,vu),this.core=e,this.logger=n}}class yj extends Ts{constructor(e,n){super(e,n,oj,vu,r=>r.id),this.core=e,this.logger=n}}var wj=Object.defineProperty,mj=(t,e,n)=>e in t?wj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,W0=(t,e,n)=>mj(t,typeof e!="symbol"?e+"":e,n);class vj{constructor(e,n){this.core=e,this.logger=n,W0(this,"authKeys"),W0(this,"pairingTopics"),W0(this,"requests"),this.authKeys=new gj(this.core,this.logger),this.pairingTopics=new bj(this.core,this.logger),this.requests=new yj(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}var Ej=Object.defineProperty,xj=(t,e,n)=>e in t?Ej(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,he=(t,e,n)=>xj(t,typeof e!="symbol"?e+"":e,n);class Y0 extends IO{constructor(e){super(e),he(this,"protocol",dv),he(this,"version",pv),he(this,"name",K0.name),he(this,"metadata"),he(this,"core"),he(this,"logger"),he(this,"events",new at.exports.EventEmitter),he(this,"engine"),he(this,"session"),he(this,"proposal"),he(this,"pendingRequest"),he(this,"auth"),he(this,"signConfig"),he(this,"on",(r,i)=>this.events.on(r,i)),he(this,"once",(r,i)=>this.events.once(r,i)),he(this,"off",(r,i)=>this.events.off(r,i)),he(this,"removeListener",(r,i)=>this.events.removeListener(r,i)),he(this,"removeAllListeners",r=>this.events.removeAllListeners(r)),he(this,"connect",async r=>{try{return await this.engine.connect(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"pair",async r=>{try{return await this.engine.pair(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"approve",async r=>{try{return await this.engine.approve(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"reject",async r=>{try{return await this.engine.reject(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"update",async r=>{try{return await this.engine.update(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"extend",async r=>{try{return await this.engine.extend(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"request",async r=>{try{return await this.engine.request(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"respond",async r=>{try{return await this.engine.respond(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"ping",async r=>{try{return await this.engine.ping(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"emit",async r=>{try{return await this.engine.emit(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"disconnect",async r=>{try{return await this.engine.disconnect(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"find",r=>{try{return this.engine.find(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"getPendingSessionRequests",()=>{try{return this.engine.getPendingSessionRequests()}catch(r){throw this.logger.error(r.message),r}}),he(this,"authenticate",async(r,i)=>{try{return await this.engine.authenticate(r,i)}catch(s){throw this.logger.error(s.message),s}}),he(this,"formatAuthMessage",r=>{try{return this.engine.formatAuthMessage(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"approveSessionAuthenticate",async r=>{try{return await this.engine.approveSessionAuthenticate(r)}catch(i){throw this.logger.error(i.message),i}}),he(this,"rejectSessionAuthenticate",async r=>{try{return await this.engine.rejectSessionAuthenticate(r)}catch(i){throw this.logger.error(i.message),i}}),this.name=e?.name||K0.name,this.metadata=pR(e?.metadata),this.signConfig=e?.signConfig;const n=g8({logger:e?.logger||K0.logger,name:this.name});this.logger=n,this.core=e?.core||new H0(e),this.session=new mv(this.core,this.logger),this.proposal=new dj(this.core,this.logger),this.pendingRequest=new pj(this.core,this.logger),this.engine=new hj(this),this.auth=new vj(this.core,this.logger)}static async init(e){const n=new Y0(e);return await n.initialize(),n}get context(){return Gt(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")}catch(e){throw this.logger.info("SignClient Initialization Failure"),this.logger.error(e.message),e}}}const _j=mv,Sj=Y0;class Ij extends at.exports{constructor(){super()}}class vv{constructor(e){this.opts=e}}class Ev{constructor(e){this.client=e}}var Bj=Object.defineProperty,$j=Object.defineProperties,Aj=Object.getOwnPropertyDescriptors,xv=Object.getOwnPropertySymbols,Oj=Object.prototype.hasOwnProperty,Dj=Object.prototype.propertyIsEnumerable,X0=(t,e,n)=>e in t?Bj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Pj=(t,e)=>{for(var n in e||(e={}))Oj.call(e,n)&&X0(t,n,e[n]);if(xv)for(var n of xv(e))Dj.call(e,n)&&X0(t,n,e[n]);return t},Rj=(t,e)=>$j(t,Aj(e)),xe=(t,e,n)=>X0(t,typeof e!="symbol"?e+"":e,n);class Tj extends Ev{constructor(e){super(e),xe(this,"signClient"),xe(this,"init",async()=>{this.signClient=await Sj.init({core:this.client.core,metadata:this.client.metadata,signConfig:this.client.signConfig}),this.signClient.core.eventClient.init().catch(n=>{this.client.logger.warn(n)})}),xe(this,"pair",async n=>{await this.client.core.pairing.pair(n)}),xe(this,"approveSession",async n=>{const{topic:r,acknowledged:i}=await this.signClient.approve(Rj(Pj({},n),{id:n.id,namespaces:n.namespaces,sessionProperties:n.sessionProperties,scopedProperties:n.scopedProperties,sessionConfig:n.sessionConfig,proposalRequestsResponses:n?.proposalRequestsResponses}));return await i(),this.signClient.session.get(r)}),xe(this,"rejectSession",async n=>await this.signClient.reject(n)),xe(this,"updateSession",async n=>await this.signClient.update(n)),xe(this,"extendSession",async n=>await this.signClient.extend(n)),xe(this,"respondSessionRequest",async n=>await this.signClient.respond(n)),xe(this,"disconnectSession",async n=>await this.signClient.disconnect(n)),xe(this,"emitSessionEvent",async n=>await this.signClient.emit(n)),xe(this,"getActiveSessions",()=>this.signClient.session.getAll().reduce((n,r)=>(n[r.topic]=r,n),{})),xe(this,"getPendingSessionProposals",()=>this.signClient.proposal.getAll()),xe(this,"getPendingSessionRequests",()=>this.signClient.getPendingSessionRequests()),xe(this,"approveSessionAuthenticate",async n=>await this.signClient.approveSessionAuthenticate(n)),xe(this,"rejectSessionAuthenticate",async n=>await this.signClient.rejectSessionAuthenticate(n)),xe(this,"formatAuthMessage",n=>this.signClient.formatAuthMessage(n)),xe(this,"registerDeviceToken",n=>this.client.core.echoClient.registerDeviceToken(n)),xe(this,"on",(n,r)=>(this.setEvent(n,"off"),this.setEvent(n,"on"),this.client.events.on(n,r))),xe(this,"once",(n,r)=>(this.setEvent(n,"off"),this.setEvent(n,"once"),this.client.events.once(n,r))),xe(this,"off",(n,r)=>(this.setEvent(n,"off"),this.client.events.off(n,r))),xe(this,"removeListener",(n,r)=>(this.setEvent(n,"removeListener"),this.client.events.removeListener(n,r))),xe(this,"onSessionRequest",n=>{this.client.events.emit("session_request",n)}),xe(this,"onSessionProposal",n=>{this.client.events.emit("session_proposal",n)}),xe(this,"onSessionDelete",n=>{this.client.events.emit("session_delete",n)}),xe(this,"onProposalExpire",n=>{this.client.events.emit("proposal_expire",n)}),xe(this,"onSessionRequestExpire",n=>{this.client.events.emit("session_request_expire",n)}),xe(this,"onSessionRequestAuthenticate",n=>{this.client.events.emit("session_authenticate",n)}),xe(this,"setEvent",(n,r)=>{switch(n){case"session_request":this.signClient.events[r]("session_request",this.onSessionRequest);break;case"session_proposal":this.signClient.events[r]("session_proposal",this.onSessionProposal);break;case"session_delete":this.signClient.events[r]("session_delete",this.onSessionDelete);break;case"proposal_expire":this.signClient.events[r]("proposal_expire",this.onProposalExpire);break;case"session_request_expire":this.signClient.events[r]("session_request_expire",this.onSessionRequestExpire);break;case"session_authenticate":this.signClient.events[r]("session_authenticate",this.onSessionRequestAuthenticate);break}}),this.signClient={}}}const Nj={decryptMessage:async t=>{const e={core:new H0({storageOptions:t.storageOptions,storage:t.storage})};await e.core.crypto.init();const n=e.core.crypto.decode(t.topic,t.encryptedMessage);return e.core=null,n},getMetadata:async t=>{const e={core:new H0({storageOptions:t.storageOptions,storage:t.storage}),sessionStore:null};e.sessionStore=new _j(e.core,e.core.logger),await e.sessionStore.init();const n=e.sessionStore.get(t.topic),r=n?.peer.metadata;return e.core=null,e.sessionStore=null,r}};function Uj(t){const e=t.toLowerCase();return e.includes("pay.")||e.includes("pay=")||e.includes("pay_")||e.includes("pay%2e")||e.includes("pay%3d")||e.includes("pay%5f")}var Cj=Object.defineProperty,_v=Object.getOwnPropertySymbols,Lj=Object.prototype.hasOwnProperty,Fj=Object.prototype.propertyIsEnumerable,J0=(t,e,n)=>e in t?Cj(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,kj=(t,e)=>{for(var n in e||(e={}))Lj.call(e,n)&&J0(t,n,e[n]);if(_v)for(var n of _v(e))Fj.call(e,n)&&J0(t,n,e[n]);return t},_e=(t,e,n)=>J0(t,typeof e!="symbol"?e+"":e,n);const Sv=class Tv extends vv{constructor(e){super(e),_e(this,"name"),_e(this,"core"),_e(this,"logger"),_e(this,"events",new at.exports),_e(this,"engine"),_e(this,"metadata"),_e(this,"signConfig"),_e(this,"pay"),_e(this,"on",(n,r)=>this.engine.on(n,r)),_e(this,"once",(n,r)=>this.engine.once(n,r)),_e(this,"off",(n,r)=>this.engine.off(n,r)),_e(this,"removeListener",(n,r)=>this.engine.removeListener(n,r)),_e(this,"pair",async n=>{try{return await this.engine.pair(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"approveSession",async n=>{try{return await this.engine.approveSession(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"rejectSession",async n=>{try{return await this.engine.rejectSession(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"updateSession",async n=>{try{return await this.engine.updateSession(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"extendSession",async n=>{try{return await this.engine.extendSession(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"respondSessionRequest",async n=>{try{return await this.engine.respondSessionRequest(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"disconnectSession",async n=>{try{return await this.engine.disconnectSession(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"emitSessionEvent",async n=>{try{return await this.engine.emitSessionEvent(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"getActiveSessions",()=>{try{return this.engine.getActiveSessions()}catch(n){throw this.logger.error(n.message),n}}),_e(this,"getPendingSessionProposals",()=>{try{return this.engine.getPendingSessionProposals()}catch(n){throw this.logger.error(n.message),n}}),_e(this,"getPendingSessionRequests",()=>{try{return this.engine.getPendingSessionRequests()}catch(n){throw this.logger.error(n.message),n}}),_e(this,"registerDeviceToken",n=>{try{return this.engine.registerDeviceToken(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"approveSessionAuthenticate",n=>{try{return this.engine.approveSessionAuthenticate(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"rejectSessionAuthenticate",n=>{try{return this.engine.rejectSessionAuthenticate(n)}catch(r){throw this.logger.error(r.message),r}}),_e(this,"formatAuthMessage",n=>{try{return this.engine.formatAuthMessage(n)}catch(r){throw this.logger.error(r.message),r}}),this.metadata=e.metadata,this.name=e.name||Zh,this.signConfig=e.signConfig,this.core=e.core,this.logger=this.core.logger,this.engine=new Tj(this),this.pay={}}static async init(e){const n=new Tv(e);return await n.initialize(),n}async initialize(){this.logger.trace("Initialized");try{await this.engine.init(),P2.isAvailable()&&(this.pay=new P2(kj({clientId:await this.core.crypto.getClientId(),appId:this.core.projectId},this.opts.payConfig||{}))),this.logger.info("WalletKit Initialization Success")}catch(e){throw this.logger.info("WalletKit Initialization Failure"),this.logger.error(e.message),e}}};_e(Sv,"notifications",Nj);let Iv=Sv;const qj=Iv;Ye.CLIENT_CONTEXT=Zh,Ye.CLIENT_STORAGE_OPTIONS=k$,Ye.CLIENT_STORAGE_PREFIX=F$,Ye.IWalletKit=vv,Ye.IWalletKitEngine=Ev,Ye.IWalletKitEvents=Ij,Ye.PROTOCOL=R2,Ye.PROTOCOL_VERSION=L$,Ye.REQUEST_CONTEXT=q$,Ye.WalletKit=qj,Ye.default=Iv,Ye.isPaymentLink=Uj,Object.defineProperty(Ye,"__esModule",{value:!0})});
41
43
  //# sourceMappingURL=index.umd.js.map