@reown/walletkit 1.4.1 → 1.5.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(Ve,Jt){typeof exports=="object"&&typeof module<"u"?Jt(exports):typeof define=="function"&&define.amd?define(["exports"],Jt):(Ve=typeof globalThis<"u"?globalThis:Ve||self,Jt(Ve["@reown/walletkit"]={}))})(this,function(Ve){"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 Ke={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 Xy(t){console&&console.warn&&console.warn(t)}var Yl=Number.isNaN||function(e){return e!==e};function de(){de.init.call(this)}Ke.exports=de,Ke.exports.once=tb,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,Xy(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 Jy(){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=Jy.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():Qy(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?eb(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 Qy(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function eb(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}function tb(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"&&nb(t,i,{once:!0})})}function nb(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",rb=2,Da="WalletKit",ib=`${of}@2:${Da}:`,sb={database:":memory:"},ob="request";var K={};/*! *****************************************************************************
1
+ (function(ze,mn){typeof exports=="object"&&typeof module<"u"?mn(exports):typeof define=="function"&&define.amd?define(["exports"],mn):(ze=typeof globalThis<"u"?globalThis:ze||self,mn(ze["@reown/walletkit"]={}))})(this,function(ze){"use strict";var mn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Kh(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 Qe={exports:{}},Vi=typeof Reflect=="object"?Reflect:null,Gh=Vi&&typeof Vi.apply=="function"?Vi.apply:function(e,n,r){return Function.prototype.apply.call(e,n,r)},Go;Vi&&typeof Vi.ownKeys=="function"?Go=Vi.ownKeys:Object.getOwnPropertySymbols?Go=function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:Go=function(e){return Object.getOwnPropertyNames(e)};function f2(t){console&&console.warn&&console.warn(t)}var Zh=Number.isNaN||function(e){return e!==e};function ge(){ge.init.call(this)}Qe.exports=ge,Qe.exports.once=d2,ge.EventEmitter=ge,ge.prototype._events=void 0,ge.prototype._eventsCount=0,ge.prototype._maxListeners=void 0;var Wh=10;function Zo(t){if(typeof t!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof t)}Object.defineProperty(ge,"defaultMaxListeners",{enumerable:!0,get:function(){return Wh},set:function(t){if(typeof t!="number"||t<0||Zh(t))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+t+".");Wh=t}}),ge.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},ge.prototype.setMaxListeners=function(e){if(typeof e!="number"||e<0||Zh(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 Yh(t){return t._maxListeners===void 0?ge.defaultMaxListeners:t._maxListeners}ge.prototype.getMaxListeners=function(){return Yh(this)},ge.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")Gh(c,this,n);else for(var f=c.length,u=td(c,f),r=0;r<f;++r)Gh(u[r],this,n);return!0};function Xh(t,e,n,r){var i,s,o;if(Zo(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=Yh(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,f2(a)}return t}ge.prototype.addListener=function(e,n){return Xh(this,e,n,!1)},ge.prototype.on=ge.prototype.addListener,ge.prototype.prependListener=function(e,n){return Xh(this,e,n,!0)};function u2(){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 Jh(t,e,n){var r={fired:!1,wrapFn:void 0,target:t,type:e,listener:n},i=u2.bind(r);return i.listener=n,r.wrapFn=i,i}ge.prototype.once=function(e,n){return Zo(n),this.on(e,Jh(this,e,n)),this},ge.prototype.prependOnceListener=function(e,n){return Zo(n),this.prependListener(e,Jh(this,e,n)),this},ge.prototype.removeListener=function(e,n){var r,i,s,o,a;if(Zo(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():l2(r,s),r.length===1&&(i[e]=r[0]),i.removeListener!==void 0&&this.emit("removeListener",e,a||n)}return this},ge.prototype.off=ge.prototype.removeListener,ge.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 Qh(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?h2(i):td(i,i.length)}ge.prototype.listeners=function(e){return Qh(this,e,!0)},ge.prototype.rawListeners=function(e){return Qh(this,e,!1)},ge.listenerCount=function(t,e){return typeof t.listenerCount=="function"?t.listenerCount(e):ed.call(t,e)},ge.prototype.listenerCount=ed;function ed(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}ge.prototype.eventNames=function(){return this._eventsCount>0?Go(this._events):[]};function td(t,e){for(var n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n}function l2(t,e){for(;e+1<t.length;e++)t[e]=t[e+1];t.pop()}function h2(t){for(var e=new Array(t.length),n=0;n<e.length;++n)e[n]=t[n].listener||t[n];return e}function d2(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))}nd(t,e,s,{once:!0}),e!=="error"&&p2(t,i,{once:!0})})}function p2(t,e,n){typeof t.on=="function"&&nd(t,"error",e,n)}function nd(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 vn={exports:{}};function g2(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}var y2=b2;function b2(t,e,n){var r=n&&n.stringify||g2,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="",u=1-i,h=-1,l=t&&t.length||0,d=0;d<l;){if(t.charCodeAt(d)===37&&d+1<l){switch(h=h>-1?h:0,t.charCodeAt(d+1)){case 100:case 102:if(u>=c||e[u]==null)break;h<d&&(f+=t.slice(h,d)),f+=Number(e[u]),h=d+2,d++;break;case 105:if(u>=c||e[u]==null)break;h<d&&(f+=t.slice(h,d)),f+=Math.floor(Number(e[u])),h=d+2,d++;break;case 79:case 111:case 106:if(u>=c||e[u]===void 0)break;h<d&&(f+=t.slice(h,d));var p=typeof e[u];if(p==="string"){f+="'"+e[u]+"'",h=d+2,d++;break}if(p==="function"){f+=e[u].name||"<anonymous>",h=d+2,d++;break}f+=r(e[u]),h=d+2,d++;break;case 115:if(u>=c)break;h<d&&(f+=t.slice(h,d)),f+=String(e[u]),h=d+2,d++;break;case 37:h<d&&(f+=t.slice(h,d)),f+="%",h=d+2,d++,u--;break}++u}++d}return h===-1?t:(h<l&&(f+=t.slice(h)),f)}const rd=y2;vn.exports=Nn;const Ts=R2().console||{},w2={mapHttpRequest:Wo,mapHttpResponse:Wo,wrapRequestSerializer:Jc,wrapResponseSerializer:Jc,wrapErrorSerializer:Jc,req:Wo,res:Wo,err:sd,errWithCause:sd};function hr(t,e){return t==="silent"?1/0:e.levels.values[t]}const Zc=Symbol("pino.logFuncs"),Wc=Symbol("pino.hierarchy"),m2={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function id(t,e){const n={logger:e,parent:t[Wc]};e[Wc]=n}function v2(t,e,n){const r={};e.forEach(i=>{r[i]=n[i]?n[i]:Ts[i]||Ts[m2[i]||"log"]||Ki}),t[Zc]=r}function E2(t,e){return Array.isArray(t)?t.filter(function(n){return n!=="!stdSerializers.err"}):t===!0?Object.keys(e):!1}function Nn(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||Ts;t.browser.write&&(t.browser.asObject=!0);const r=t.serializers||{},i=E2(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(b){n[b]=n}),(t.enabled===!1||t.browser.disabled)&&(t.level="silent");const c=t.level||"info",f=Object.create(n);f.log||(f.log=Ki),v2(f,a,n),id({},f),Object.defineProperty(f,"levelVal",{get:h}),Object.defineProperty(f,"level",{get:l,set:d});const u={transmit:e,serialize:i,asObject:t.browser.asObject,asObjectBindingsOnly:t.browser.asObjectBindingsOnly,formatters:t.browser.formatters,levels:a,timestamp:O2(t),messageKey:t.messageKey||"msg",onChild:t.onChild||Ki};f.levels=x2(t),f.level=c,f.isLevelEnabled=function(b){return this.levels.values[b]?this.levels.values[b]>=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=Ki,f.serializers=r,f._serialize=i,f._stdErrSerialize=s,f.child=function(...b){return p.call(this,u,...b)},e&&(f._logEvent=Xc());function h(){return hr(this.level,this)}function l(){return this._level}function d(b){if(b!=="silent"&&!this.levels.values[b])throw Error("unknown level "+b);this._level=b,hi(this,u,f,"error"),hi(this,u,f,"fatal"),hi(this,u,f,"warn"),hi(this,u,f,"info"),hi(this,u,f,"debug"),hi(this,u,f,"trace"),o.forEach(v=>{hi(this,u,f,v)})}function p(b,v,O){if(!v)throw new Error("missing bindings for child Pino");O=O||{},i&&v.serializers&&(O.serializers=v.serializers);const P=O.serializers;if(i&&P){var x=Object.assign({},r,P),S=t.browser.serialize===!0?Object.keys(x):i;delete v.serializers,Yc([v],S,x,this._stdErrSerialize)}function R(L){this._childLevel=(L._childLevel|0)+1,this.bindings=v,x&&(this.serializers=x,this._serialize=S),e&&(this._logEvent=Xc([].concat(L._logEvent.bindings,v)))}R.prototype=this;const U=new R(this);return id(this,U),U.child=function(...L){return p.call(this,b,...L)},U.level=O.level||this.level,b.onChild(U),U}return f}function x2(t){const e=t.customLevels||{},n=Object.assign({},Nn.levels.values,e),r=Object.assign({},Nn.levels.labels,_2(e));return{values:n,labels:r}}function _2(t){const e={};return Object.keys(t).forEach(function(n){e[t[n]]=n}),e}Nn.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"}},Nn.stdSerializers=w2,Nn.stdTimeFunctions=Object.assign({},{nullTime:od,epochTime:ad,unixTime:D2,isoTime:P2});function I2(t){const e=[];t.bindings&&e.push(t.bindings);let n=t[Wc];for(;n.parent;)n=n.parent,n.logger.bindings&&e.push(n.logger.bindings);return e.reverse()}function hi(t,e,n,r){if(Object.defineProperty(t,r,{value:hr(t.level,n)>hr(r,n)?Ki:n[Zc][r],writable:!0,enumerable:!0,configurable:!0}),t[r]===Ki){if(!e.transmit)return;const s=e.transmit.level||t.level,o=hr(s,n);if(hr(r,n)<o)return}t[r]=B2(t,e,n,r);const i=I2(t);i.length!==0&&(t[r]=S2(i,t[r]))}function S2(t,e){return function(){return e.apply(this,[...t,...arguments])}}function B2(t,e,n,r){return function(i){return function(){const s=e.timestamp(),o=new Array(arguments.length),a=Object.getPrototypeOf&&Object.getPrototypeOf(this)===Ts?Ts:this;for(var c=0;c<o.length;c++)o[c]=arguments[c];var f=!1;if(e.serialize&&(Yc(o,this._serialize,this.serializers,this._stdErrSerialize),f=!0),e.asObject||e.formatters?i.call(a,...$2(this,r,o,s,e)):i.apply(a,o),e.transmit){const u=e.transmit.level||t._level,h=hr(u,n),l=hr(r,n);if(l<h)return;A2(this,{ts:s,methodLevel:r,methodValue:l,transmitLevel:u,transmitValue:n.levels.values[e.transmit.level||t._level],send:e.transmit.send,val:hr(t._level,n)},o,f)}}}(t[Zc][r])}function $2(t,e,n,r,i){const{level:s,log:o=h=>h}=i.formatters||{},a=n.slice();let c=a[0];const f={};let u=(t._childLevel|0)+1;if(u<1&&(u=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(;u--&&typeof a[0]=="object";)Object.assign(f,a.shift());return[o(f),...a]}else{if(c!==null&&typeof c=="object"){for(;u--&&typeof a[0]=="object";)Object.assign(f,a.shift());c=a.length?rd(a.shift(),a):void 0}else typeof c=="string"&&(c=rd(a.shift(),a));return c!==void 0&&(f[i.messageKey]=c),[o(f)]}}function Yc(t,e,n,r){for(const i in t)if(r&&t[i]instanceof Error)t[i]=Nn.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 A2(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||Yc(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(u){return f.indexOf(u)===-1}),t._logEvent.level.label=o,t._logEvent.level.value=a,i(o,t._logEvent,c),t._logEvent=Xc(f)}function Xc(t){return{ts:0,messages:[],bindings:t||[],level:{label:"",value:0}}}function sd(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 O2(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?od:ad}function Wo(){return{}}function Jc(t){return t}function Ki(){}function od(){return!1}function ad(){return Date.now()}function D2(){return Math.round(Date.now()/1e3)}function P2(){return new Date(Date.now()).toISOString()}function R2(){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=Nn;var cd=vn.exports.pino=Nn;const T2={level:"info"},Yo="custom_context",Qc=1e3*1024;var N2=Object.defineProperty,U2=(t,e,n)=>e in t?N2(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,dr=(t,e,n)=>U2(t,typeof e!="symbol"?e+"":e,n);class C2{constructor(e){dr(this,"nodeValue"),dr(this,"sizeInBytes"),dr(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 fd{constructor(e){dr(this,"lengthInNodes"),dr(this,"sizeInBytes"),dr(this,"head"),dr(this,"tail"),dr(this,"maxSizeInBytes"),this.head=null,this.tail=null,this.lengthInNodes=0,this.maxSizeInBytes=e,this.sizeInBytes=0}append(e){const n=new C2(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 F2=t=>JSON.stringify(t,(e,n)=>typeof n=="bigint"?n.toString()+"n":n);function ud(t){return typeof t=="string"?t:F2(t)||""}var L2=Object.defineProperty,k2=(t,e,n)=>e in t?L2(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Xo=(t,e,n)=>k2(t,typeof e!="symbol"?e+"":e,n);class ld{constructor(e,n=Qc){Xo(this,"logs"),Xo(this,"level"),Xo(this,"levelValue"),Xo(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 fd(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(ud({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 fd(this.MAX_LOG_SIZE_IN_BYTES)}getLogArray(){return Array.from(this.logs)}logsToBlob(e){const n=this.getLogArray();return n.push(ud({extraMetadata:e})),new Blob(n,{type:"application/json"})}}var q2=Object.defineProperty,M2=(t,e,n)=>e in t?q2(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,j2=(t,e,n)=>M2(t,typeof e!="symbol"?e+"":e,n);class z2{constructor(e,n=Qc){j2(this,"baseChunkLogger"),this.baseChunkLogger=new ld(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 H2=Object.defineProperty,V2=(t,e,n)=>e in t?H2(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,K2=(t,e,n)=>V2(t,typeof e!="symbol"?e+"":e,n);class G2{constructor(e,n=Qc){K2(this,"baseChunkLogger"),this.baseChunkLogger=new ld(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 Z2=Object.defineProperty,W2=Object.defineProperties,Y2=Object.getOwnPropertyDescriptors,hd=Object.getOwnPropertySymbols,X2=Object.prototype.hasOwnProperty,J2=Object.prototype.propertyIsEnumerable,dd=(t,e,n)=>e in t?Z2(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,pr=(t,e)=>{for(var n in e||(e={}))X2.call(e,n)&&dd(t,n,e[n]);if(hd)for(var n of hd(e))J2.call(e,n)&&dd(t,n,e[n]);return t},gr=(t,e)=>W2(t,Y2(e));function ef(t){return gr(pr({},t),{level:t?.level||T2.level})}function Q2(t,e,n=Yo){return t[n]=e,t}function xt(t,e=Yo){return t[e]||""}function e3(t,e,n=Yo){const r=xt(t,n);return r.trim()?`${r}/${e}`:e}function Ft(t,e,n=Yo){const r=e3(t,e,n),i=t.child({context:r});return Q2(i,r,n)}function t3(t){var e,n;const r=new z2((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:vn.exports(gr(pr({},t.opts),{level:"trace",browser:gr(pr({},(n=t.opts)==null?void 0:n.browser),{write:i=>r.write(i)})})),chunkLoggerController:r}}function n3(t){var e,n;const r=new G2((e=t.opts)==null?void 0:e.level,t.maxSizeInBytes);return{logger:vn.exports(gr(pr({},t.opts),{level:"trace",browser:gr(pr({},(n=t.opts)==null?void 0:n.browser),{write:i=>r.write(i)})}),r),chunkLoggerController:r}}function pd(t){var e;if(typeof t.loggerOverride<"u"&&typeof t.loggerOverride!="string")return{logger:t.loggerOverride,chunkLoggerController:null};const n=gr(pr({},t.opts),{level:typeof t.loggerOverride=="string"?t.loggerOverride:(e=t.opts)==null?void 0:e.level});return typeof window<"u"?t3(gr(pr({},t),{opts:n})):n3(gr(pr({},t),{opts:n}))}var gd=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))},r3=function(){function t(e,n,r){this.name=e,this.version=n,this.os=r,this.type="browser"}return t}(),i3=function(){function t(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return t}(),s3=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}(),o3=function(){function t(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return t}(),a3=function(){function t(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return t}(),c3=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,f3=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,yd=3,u3=[["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",c3]],bd=[["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 l3(t){return t?wd(t):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new a3:typeof navigator<"u"?wd(navigator.userAgent):p3()}function h3(t){return t!==""&&u3.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 wd(t){var e=h3(t);if(!e)return null;var n=e[0],r=e[1];if(n==="searchbot")return new o3;var i=r[1]&&r[1].split(".").join("_").split("_").slice(0,3);i?i.length<yd&&(i=gd(gd([],i,!0),g3(yd-i.length),!0)):i=[];var s=i.join("."),o=d3(t),a=f3.exec(t);return a&&a[1]?new s3(n,s,o,a[1]):new r3(n,s,o)}function d3(t){for(var e=0,n=bd.length;e<n;e++){var r=bd[e],i=r[0],s=r[1],o=s.exec(t);if(o)return i}return null}function p3(){var t=typeof process<"u"&&process.version;return t?new i3(process.version.slice(1)):null}function g3(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,20 @@
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 $a=function(t,e){return $a=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])},$a(t,e)};function ab(t,e){$a(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var Pa=function(){return Pa=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},Pa.apply(this,arguments)};function cb(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 ub(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 lb(t,e){return function(n,r){e(n,r,t)}}function fb(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function hb(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 db(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 pb(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]}function gb(t,e){for(var n in t)n!=="default"&&!e.hasOwnProperty(n)&&(e[n]=t[n])}function Ta(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 yb(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(af(arguments[e]));return t}function bb(){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 wb(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,y){s.push([d,h,p,y])>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 mb(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 vb(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 Ta=="function"?Ta(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 Eb(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function xb(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 _b(t){return t&&t.__esModule?t:{default:t}}function Sb(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function Ib(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 Ab=Object.freeze({__proto__:null,__extends:ab,get __assign(){return Pa},__rest:cb,__decorate:ub,__param:lb,__metadata:fb,__awaiter:hb,__generator:db,__createBinding:pb,__exportStar:gb,__values:Ta,__read:af,__spread:yb,__spreadArrays:bb,__await:Ci,__asyncGenerator:wb,__asyncDelegator:mb,__asyncValues:vb,__makeTemplateObject:Eb,__importStar:xb,__importDefault:_b,__classPrivateFieldGet:Sb,__classPrivateFieldSet:Ib}),qs=Wl(Ab),Ra={},Ui={},cf;function Bb(){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={},Na={},_r={},uf;function Ob(){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 Ca={},lf;function Db(){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}(Ca)),Ca}var ff;function hf(){return ff||(ff=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=qs;e.__exportStar(Ob(),t),e.__exportStar(Db(),t)}(Na)),Na}var df;function $b(){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 Pb(){return pf||(pf=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=qs;e.__exportStar(Bb(),t),e.__exportStar($b(),t)}(Ra)),Ra}var ti={},gf;function Tb(){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 Ua={},Fi={},yf;function Rb(){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 Nb(){return bf||(bf=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),qs.__exportStar(Rb(),t)}(Ua)),Ua}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=qs;e.__exportStar(Pb(),t),e.__exportStar(Tb(),t),e.__exportStar(Nb(),t),e.__exportStar(hf(),t)})(K);class Sr{}class Cb extends Sr{constructor(e){super()}}const wf=K.FIVE_SECONDS,Ir={pulse:"heartbeat_pulse"};class Fa extends Cb{constructor(e){super(e),this.events=new Ke.exports.EventEmitter,this.interval=wf,this.interval=e?.interval||wf}static async init(e){const n=new Fa(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 Ub=/"(?:_|\\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*:/,Fb=/"(?: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*:/,Lb=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function kb(t,e){if(t==="__proto__"||t==="constructor"&&e&&typeof e=="object"&&"prototype"in e){qb(t);return}return e}function qb(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(!Lb.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(Ub.test(t)||Fb.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,kb)}return JSON.parse(t)}catch(r){if(e.strict)throw r;return t}}function Mb(t){return!t||typeof t.then!="function"?Promise.resolve(t):t}function Te(t,...e){try{return Mb(t(...e))}catch(n){return Promise.reject(n)}}function jb(t){const e=typeof t;return t===null||e!=="object"&&e!=="function"}function zb(t){const e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}function js(t){if(jb(t))return String(t);if(zb(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 La="base64:";function Hb(t){if(typeof t=="string")return t;mf();const e=Buffer.from(t).toString("base64");return La+e}function Vb(t){return typeof t!="string"||!t.startsWith(La)?t:(mf(),Buffer.from(t.slice(La.length),"base64"))}function lt(t){return t?t.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function Kb(...t){return lt(t.join(":"))}function zs(t){return t=lt(t),t?t+":":""}function u$(t){return t}const Gb="memory",Wb=()=>{const t=new Map;return{name:Gb,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 Zb(t={}){const e={mounts:{"":t.driver||Wb()},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 y=d.get(p.base);return y||(y={driver:p.driver,base:p.base,items:[]},d.set(p.base,y)),y};for(const p of u){const y=typeof p=="string",m=lt(y?p:p.key),B=y?void 0:p.value,$=y||!p.options?l:{...l,...p.options},_=n(m);h(_).items.push({key:m,value:B,relativeKey:_.relativeKey,options:$})}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:Kb(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=>Vb(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,Hb(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(y=>Ms(y));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 y=await Te(p.driver.getKeys,p.relativeBase,l);for(const m of y){const B=p.mountpoint+lt(m);d.some($=>B.startsWith($))||h.push(B)}d=[p.mountpoint,...d.filter(m=>!m.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 ka;function Li(){return ka||(ka=xf("keyval-store","keyval")),ka}function _f(t,e=Li()){return e("readonly",n=>Ar(n.get(t)))}function Yb(t,e,n=Li()){return n("readwrite",r=>(r.put(e,t),Ar(r.transaction)))}function Xb(t,e=Li()){return e("readwrite",n=>(n.delete(t),Ar(n.transaction)))}function Jb(t=Li()){return t("readwrite",e=>(e.clear(),Ar(e.transaction)))}function Qb(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},Ar(t.transaction)}function ew(t=Li()){return t("readonly",e=>{if(e.getAllKeys)return Ar(e.getAllKeys());const n=[];return Qb(e,r=>n.push(r.key)).then(()=>n)})}const tw=t=>JSON.stringify(t,(e,n)=>typeof n=="bigint"?n.toString()+"n":n),nw=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 nw(t)}catch{return t}}function Br(t){return typeof t=="string"?t:tw(t)||""}const rw="idb-keyval";var iw=(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:rw,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 Yb(n(i),s,r)},removeItem(i){return Xb(n(i),r)},getKeys(){return ew(r)},clear(){return Jb(r)}}};const sw="WALLET_CONNECT_V2_INDEXED_DB",ow="keyvaluestorage";class aw{constructor(){this.indexedDb=Zb({driver:iw({dbName:sw,storeName:ow})})}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 qa=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 qa<"u"&&qa.localStorage?Hs.exports=qa.localStorage:typeof window<"u"&&window.localStorage?Hs.exports=window.localStorage:Hs.exports=new e})();function cw(t){var e;return[t[0],ni((e=t[1])!=null?e:"")]}class uw{constructor(){this.localStorage=Hs.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(cw)}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 lw="wc_storage_version",Sf=1,fw=async(t,e,n)=>{const r=lw,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),hw(t,o)},hw=async(t,e)=>{e.length&&e.forEach(async n=>{await t.removeItem(n)})};class dw{constructor(){this.initialized=!1,this.setInitialized=n=>{this.storage=n,this.initialized=!0};const e=new uw;this.storage=e;try{const n=new aw;fw(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 pw(t){try{return JSON.stringify(t)}catch{return'"[Circular]"'}}var gw=yw;function yw(t,e,n){var r=n&&n.stringify||pw,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=gw;Qt.exports=dn;const ki=Pw().console||{},bw={mapHttpRequest:Vs,mapHttpResponse:Vs,wrapRequestSerializer:Va,wrapResponseSerializer:Va,wrapErrorSerializer:Va,req:Vs,res:Vs,err:Bf,errWithCause:Bf};function kn(t,e){return t==="silent"?1/0:e.levels.values[t]}const Ma=Symbol("pino.logFuncs"),ja=Symbol("pino.hierarchy"),ww={error:"log",fatal:"error",warn:"error",info:"log",debug:"log",trace:"log"};function Af(t,e){const n={logger:e,parent:t[ja]};e[ja]=n}function mw(t,e,n){const r={};e.forEach(i=>{r[i]=n[i]?n[i]:ki[i]||ki[ww[i]||"log"]||ri}),t[Ma]=r}function vw(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=vw(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(y){n[y]=n}),(t.enabled===!1||t.browser.disabled)&&(t.level="silent");const c=t.level||"info",u=Object.create(n);u.log||(u.log=ri),mw(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:Ow(t),messageKey:t.messageKey||"msg",onChild:t.onChild||ri};u.levels=Ew(t),u.level=c,u.isLevelEnabled=function(y){return this.levels.values[y]?this.levels.values[y]>=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(...y){return p.call(this,l,...y)},e&&(u._logEvent=Ha());function f(){return kn(this.level,this)}function d(){return this._level}function h(y){if(y!=="silent"&&!this.levels.values[y])throw Error("unknown level "+y);this._level=y,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(m=>{Or(this,l,u,m)})}function p(y,m,B){if(!m)throw new Error("missing bindings for child Pino");B=B||{},i&&m.serializers&&(B.serializers=m.serializers);const $=B.serializers;if(i&&$){var _=Object.assign({},r,$),x=t.browser.serialize===!0?Object.keys(_):i;delete m.serializers,za([m],x,_,this._stdErrSerialize)}function P(U){this._childLevel=(U._childLevel|0)+1,this.bindings=m,_&&(this.serializers=_,this._serialize=x),e&&(this._logEvent=Ha([].concat(U._logEvent.bindings,m)))}P.prototype=this;const R=new P(this);return Af(this,R),R.child=function(...U){return p.call(this,y,...U)},R.level=B.level||this.level,y.onChild(R),R}return u}function Ew(t){const e=t.customLevels||{},n=Object.assign({},dn.levels.values,e),r=Object.assign({},dn.levels.labels,xw(e));return{values:n,labels:r}}function xw(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=bw,dn.stdTimeFunctions=Object.assign({},{nullTime:Of,epochTime:Df,unixTime:Dw,isoTime:$w});function _w(t){const e=[];t.bindings&&e.push(t.bindings);let n=t[ja];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[Ma][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]=Iw(t,e,n,r);const i=_w(t);i.length!==0&&(t[r]=Sw(i,t[r]))}function Sw(t,e){return function(){return e.apply(this,[...t,...arguments])}}function Iw(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&&(za(a,this._serialize,this.serializers,this._stdErrSerialize),l=!0),e.asObject||e.formatters?i.call(c,...Aw(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;Bw(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[Ma][r])}function Aw(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 za(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 Bw(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||za(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=Ha(u)}function Ha(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 Ow(t){return typeof t.timestamp=="function"?t.timestamp:t.timestamp===!1?Of:Df}function Vs(){return{}}function Va(t){return t}function ri(){}function Of(){return!1}function Df(){return Date.now()}function Dw(){return Math.round(Date.now()/1e3)}function $w(){return new Date(Date.now()).toISOString()}function Pw(){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 Tw={level:"info"},Ks="custom_context",Ka=1e3*1024;var Rw=Object.defineProperty,Nw=(t,e,n)=>e in t?Rw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,qn=(t,e,n)=>Nw(t,typeof e!="symbol"?e+"":e,n);class Cw{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 Cw(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 Uw=Object.defineProperty,Fw=(t,e,n)=>e in t?Uw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Gs=(t,e,n)=>Fw(t,typeof e!="symbol"?e+"":e,n);class Pf{constructor(e,n=Ka){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 Lw=Object.defineProperty,kw=(t,e,n)=>e in t?Lw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,qw=(t,e,n)=>kw(t,typeof e!="symbol"?e+"":e,n);class Mw{constructor(e,n=Ka){qw(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 jw=Object.defineProperty,zw=(t,e,n)=>e in t?jw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Hw=(t,e,n)=>zw(t,typeof e!="symbol"?e+"":e,n);class Vw{constructor(e,n=Ka){Hw(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 Kw=Object.defineProperty,Gw=Object.defineProperties,Ww=Object.getOwnPropertyDescriptors,Tf=Object.getOwnPropertySymbols,Zw=Object.prototype.hasOwnProperty,Yw=Object.prototype.propertyIsEnumerable,Rf=(t,e,n)=>e in t?Kw(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ws=(t,e)=>{for(var n in e||(e={}))Zw.call(e,n)&&Rf(t,n,e[n]);if(Tf)for(var n of Tf(e))Yw.call(e,n)&&Rf(t,n,e[n]);return t},Zs=(t,e)=>Gw(t,Ww(e));function Xw(t){return Zs(Ws({},t),{level:t?.level||Tw.level})}function Jw(t,e,n=Ks){return t[n]=e,t}function ft(t,e=Ks){return t[e]||""}function Qw(t,e,n=Ks){const r=ft(t,n);return r.trim()?`${r}/${e}`:e}function _t(t,e,n=Ks){const r=Qw(t,e,n),i=t.child({context:r});return Jw(i,r,n)}function em(t){var e,n;const r=new Mw((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 tm(t){var e;const n=new Vw((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"?em(t):tm(t)}var nm=Object.defineProperty,rm=(t,e,n)=>e in t?nm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Cf=(t,e,n)=>rm(t,typeof e!="symbol"?e+"":e,n);class im extends Sr{constructor(e){super(),this.opts=e,Cf(this,"protocol","wc"),Cf(this,"version",2)}}var sm=Object.defineProperty,om=(t,e,n)=>e in t?sm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,am=(t,e,n)=>om(t,typeof e!="symbol"?e+"":e,n);class cm extends Sr{constructor(e,n){super(),this.core=e,this.logger=n,am(this,"records",new Map)}}class um{constructor(e,n){this.logger=e,this.core=n}}class lm extends Sr{constructor(e,n){super(),this.relayer=e,this.logger=n}}class fm extends Sr{constructor(e){super()}}class hm{constructor(e,n,r,i){this.core=e,this.logger=n,this.name=r}}class dm extends Sr{constructor(e,n){super(),this.relayer=e,this.logger=n}}class pm extends Sr{constructor(e,n){super(),this.core=e,this.logger=n}}class gm{constructor(e,n,r){this.core=e,this.logger=n,this.store=r}}class ym{constructor(e,n){this.projectId=e,this.logger=n}}class bm{constructor(e,n,r){this.core=e,this.logger=n,this.telemetryEnabled=r}}var wm=Object.defineProperty,mm=(t,e,n)=>e in t?wm(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Uf=(t,e,n)=>mm(t,typeof e!="symbol"?e+"":e,n);class vm{constructor(e){this.opts=e,Uf(this,"protocol","wc"),Uf(this,"version",2)}}class Em{constructor(e){this.client=e}}function xm(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ff(t,...e){if(!xm(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 _m(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 Ga=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function Sm(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=Sm(t)),Ff(t),t}class Im{clone(){return this._cloneInto()}}function Am(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 Bm(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 Om extends Im{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=Ga(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=Ga(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),_m(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;Bm(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Ga(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),Wa=BigInt(32);function Mf(t,e=!1){return e?{h:Number(t&Ys),l:Number(t>>Wa&Ys)}:{h:Number(t>>Wa&Ys)|0,l:Number(t&Ys)|0}}function Dm(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 $m=(t,e)=>BigInt(t>>>0)<<Wa|BigInt(e>>>0),Pm=(t,e,n)=>t>>>n,Tm=(t,e,n)=>t<<32-n|e>>>n,Rm=(t,e,n)=>t>>>n|e<<32-n,Nm=(t,e,n)=>t<<32-n|e>>>n,Cm=(t,e,n)=>t<<64-n|e>>>n-32,Um=(t,e,n)=>t>>>n-32|e<<64-n,Fm=(t,e)=>e,Lm=(t,e)=>t,km=(t,e,n)=>t<<n|e>>>32-n,qm=(t,e,n)=>e<<n|t>>>32-n,Mm=(t,e,n)=>e<<n-32|t>>>64-n,jm=(t,e,n)=>t<<n-32|e>>>64-n;function zm(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const Hm=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Vm=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Km=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),Gm=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,Wm=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),Zm=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,ne={fromBig:Mf,split:Dm,toBig:$m,shrSH:Pm,shrSL:Tm,rotrSH:Rm,rotrSL:Nm,rotrBH:Cm,rotrBL:Um,rotr32H:Fm,rotr32L:Lm,rotlSH:km,rotlSL:qm,rotlBH:Mm,rotlBL:jm,add:zm,add3L:Hm,add3H:Vm,add4L:Km,add4H:Gm,add5H:Zm,add5L:Wm},[Ym,Xm]=(()=>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 Jm extends Om{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:y,Hl:m}=this;return[e,n,r,i,s,o,a,c,u,l,f,d,h,p,y,m]}set(e,n,r,i,s,o,a,c,u,l,f,d,h,p,y,m){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=y|0,this.Hl=m|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,P=jn[_-15]|0,R=ne.rotrSH(x,P,1)^ne.rotrSH(x,P,8)^ne.shrSH(x,P,7),U=ne.rotrSL(x,P,1)^ne.rotrSL(x,P,8)^ne.shrSL(x,P,7),F=Mn[_-2]|0,D=jn[_-2]|0,j=ne.rotrSH(F,D,19)^ne.rotrBH(F,D,61)^ne.shrSH(F,D,6),M=ne.rotrSL(F,D,19)^ne.rotrBL(F,D,61)^ne.shrSL(F,D,6),E=ne.add4L(U,M,jn[_-7],jn[_-16]),b=ne.add4H(E,R,j,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:y,Gl:m,Hh:B,Hl:$}=this;for(let _=0;_<80;_++){const x=ne.rotrSH(f,d,14)^ne.rotrSH(f,d,18)^ne.rotrBH(f,d,41),P=ne.rotrSL(f,d,14)^ne.rotrSL(f,d,18)^ne.rotrBL(f,d,41),R=f&h^~f&y,U=d&p^~d&m,F=ne.add5L($,P,U,Xm[_],jn[_]),D=ne.add5H(F,B,x,R,Ym[_],Mn[_]),j=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,v=i&o^i&c^o&c;B=y|0,$=m|0,y=h|0,m=p|0,h=f|0,p=d|0,{h:f,l:d}=ne.add(u|0,l|0,D|0,j|0),u=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=ne.add3L(j,E,v);r=ne.add3H(g,D,M,b),i=g|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:y,l:m}=ne.add(this.Gh|0,this.Gl|0,y|0,m|0),{h:B,l:$}=ne.add(this.Hh|0,this.Hl|0,B|0,$|0),this.set(r,i,s,o,a,c,u,l,f,d,h,p,y,m,B,$)}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 Qm=Am(()=>new Jm);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const Za=BigInt(0),jf=BigInt(1),e2=BigInt(2);function Ya(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Xa(t){if(!Ya(t))throw new Error("Uint8Array expected")}function Ja(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const t2=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Qa(t){Xa(t);let e="";for(let n=0;n<t.length;n++)e+=t2[t[n]];return e}function zf(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Za: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 n2(t){return zf(Qa(t))}function Xs(t){return Xa(t),zf(Qa(Uint8Array.from(t).reverse()))}function Kf(t,e){return Vf(t.toString(16).padStart(e*2,"0"))}function ec(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(Ya(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];Xa(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 tc=t=>typeof t=="bigint"&&Za<=t;function r2(t,e,n){return tc(t)&&tc(e)&&tc(n)&&e<=t&&t<n}function qi(t,e,n,r){if(!r2(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function i2(t){let e;for(e=0;t>Za;t>>=jf,e+=1);return e}const s2=t=>(e2<<BigInt(t-1))-jf,o2={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"||Ya(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 nc(t,e,n={}){const r=(i,s,o)=>{const a=o2[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),a2=BigInt(3),rc=BigInt(4),Zf=BigInt(5),Yf=BigInt(8);function Be(t,e){const n=t%e;return n>=Re?n:e+n}function c2(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 u2(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&&c2(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)/rc;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 l2(t){if(t%rc===a2){const e=(t+xe)/rc;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 u2(t)}const f2=(t,e)=>(Be(t,e)&xe)===xe,h2=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function d2(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=h2.reduce((r,i)=>(r[i]="function",r),e);return nc(t,n)}function p2(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 g2(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:s2(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)=>p2(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=l2(t)),o(a,c))),invertBatch:c=>g2(a,c),cmov:(c,u,l)=>l?u:c,toBytes:c=>n?ec(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):n2(c)}});return Object.freeze(a)}const eh=BigInt(0),Js=BigInt(1);function ic(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 sc(t,e){th(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1);return{windows:n,windowSize:r}}function y2(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 b2(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 oc=new WeakMap,nh=new WeakMap;function ac(t){return nh.get(t)||1}function w2(t,e){return{constTimeNegate:ic,hasPrecomputes(n){return ac(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}=sc(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}=sc(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 y=h,m=h+Math.abs(p)-1,B=d%2!==0,$=p<0;p===0?c=c.add(ic(B,r[y])):a=a.add(ic($,r[m]))}return{p:a,f:c}},wNAFUnsafe(n,r,i,s=t.ZERO){const{windows:o,windowSize:a}=sc(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=oc.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&oc.set(r,i(s))),s},wNAFCached(n,r,i){const s=ac(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=ac(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),oc.delete(n)}}}function m2(t,e,n,r){if(y2(n,t),b2(r,e),n.length!==r.length)throw new Error("arrays of points and scalars must have equal length");const i=t.ZERO,s=i2(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],y=Number(p>>BigInt(f)&BigInt(a));c[y]=c[y].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 v2(t){return d2(t.Fp),nc(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),E2=BigInt(8),x2={zip215:!0};function _2(t){const e=v2(t);return nc(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function S2(t){const e=_2(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||((g,w)=>{try{return{isValid:!0,value:n.sqrt(g*n.inv(w))}}catch{return{isValid:!1,value:jt}}}),h=e.adjustScalarBytes||(g=>g),p=e.domain||((g,w,S)=>{if(Ja("phflag",S),w.length||S)throw new Error("Contexts/pre-hash are not supported");return g});function y(g,w){qi("coordinate "+g,w,jt,u)}function m(g){if(!(g instanceof _))throw new Error("ExtendedPoint expected")}const B=Wf((g,w)=>{const{ex:S,ey:A,ez:I}=g,O=g.is0();w==null&&(w=O?E2:n.inv(I));const T=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:T,y:L}}),$=Wf(g=>{const{a:w,d:S}=e;if(g.is0())throw new Error("bad point: ZERO");const{ex:A,ey:I,ez:O,et:T}=g,L=l(A*A),C=l(I*I),k=l(O*O),N=l(k*k),q=l(L*w),z=l(k*l(q+C)),W=l(N+l(S*l(L*C)));if(z!==W)throw new Error("bad point: equation left != right (1)");const V=l(A*I),Z=l(O*T);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,y("x",w),y("y",S),y("z",A),y("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 y("x",S),y("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 m2(_,f,w,S)}_setWindowSize(w){R.setWindowSize(this,w)}assertValidity(){$(this)}equals(w){m(w);const{ex:S,ey:A,ez:I}=this,{ex:O,ey:T,ez:L}=w,C=l(S*L),k=l(O*I),N=l(A*L),q=l(T*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),T=l(A*A),L=l(Qs*l(I*I)),C=l(w*O),k=S+A,N=l(l(k*k)-O-T),q=C+T,z=q-L,W=C-T,V=l(N*z),Z=l(q*W),Q=l(N*W),ee=l(z*q);return new _(V,Z,ee,Q)}add(w){m(w);const{a:S,d:A}=e,{ex:I,ey:O,ez:T,et:L}=this,{ex:C,ey:k,ez:N,et:q}=w;if(S===BigInt(-1)){const Hy=l((O-I)*(k+C)),Vy=l((O+I)*(k-C)),Gl=l(Vy-Hy);if(Gl===jt)return this.double();const Ky=l(T*Qs*q),Gy=l(L*Qs*N),Wy=Gy+Ky,Zy=Vy+Hy,Yy=Gy-Ky,s$=l(Wy*Gl),o$=l(Zy*Yy),a$=l(Wy*Yy),c$=l(Gl*Zy);return new _(s$,o$,c$,a$)}const z=l(I*C),W=l(O*k),V=l(L*A*q),Z=l(T*N),Q=l((I+O)*(C+k)-z-W),ee=Z-V,ie=Z+V,fe=l(W-S*z),ve=l(Q*ee),Ln=l(ie*fe),Oa=l(Q*fe),i$=l(ee*ie);return new _(ve,Ln,i$,Oa)}subtract(w){return this.add(w.negate())}wNAF(w){return R.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?P:this.is0()||A===ht?this:R.wNAFCachedUnsafe(this,A,_.normalizeZ,S)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return R.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),Ja("zip215",S);const T=w.slice(),L=w[O-1];T[O-1]=L&-129;const C=Xs(T),k=S?u:n.ORDER;qi("pointHex.y",C,jt,k);const N=l(C*C),q=l(N-ht),z=l(A*N-I);let{isValid:W,value:V}=d(q,z);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 D(w).point}toRawBytes(){const{x:w,y:S}=this.toAffine(),A=ec(S,n.BYTES);return A[A.length-1]|=w&ht?128:0,A}toHex(){return Qa(this.toRawBytes())}}_.BASE=new _(e.Gx,e.Gy,ht,l(e.Gx*e.Gy)),_.ZERO=new _(jt,ht,ht,jt);const{BASE:x,ZERO:P}=_,R=w2(_,a*8);function U(g){return Be(g,r)}function F(g){return U(Xs(g))}function D(g){const w=n.BYTES;g=gn("private key",g,w);const S=gn("hashed private key",s(g),2*w),A=h(S.slice(0,w)),I=S.slice(w,2*w),O=F(A),T=x.multiply(O),L=T.toRawBytes();return{head:A,prefix:I,scalar:O,point:T,pointBytes:L}}function j(g){return D(g).pointBytes}function M(g=new Uint8Array,...w){const S=Gf(...w);return F(s(p(S,gn("context",g),!!i)))}function E(g,w,S={}){g=gn("message",g),i&&(g=i(g));const{prefix:A,scalar:I,pointBytes:O}=D(w),T=M(S.context,A,g),L=x.multiply(T).toRawBytes(),C=M(S.context,L,O,g),k=U(T+C*I);qi("signature.s",k,jt,r);const N=Gf(L,ec(k,n.BYTES));return gn("result",N,n.BYTES*2)}const b=x2;function v(g,w,S,A=b){const{context:I,zip215:O}=A,T=n.BYTES;g=gn("signature",g,2*T),w=gn("message",w),S=gn("publicKey",S,T),O!==void 0&&Ja("zip215",O),i&&(w=i(w));const L=Xs(g.slice(T,2*T));let C,k,N;try{C=_.fromHex(S,O),k=_.fromHex(g.slice(0,T),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:j,sign:E,verify:v,ExtendedPoint:_,utils:{getExtendedPublicKey:D,randomPrivateKey:()=>o(n.BYTES),precompute(g=8,w=_.BASE){return w._setWindowSize(g),w.multiply(BigInt(3)),w}}}}BigInt(0),BigInt(1);const cc=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),rh=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);const I2=BigInt(1),ih=BigInt(2);BigInt(3);const A2=BigInt(5),B2=BigInt(8);function O2(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=cc,o=t*t%s*t%s,a=en(o,ih,s)*o%s,c=en(a,I2,s)*t%s,u=en(c,A2,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,y=en(p,e,s)*u%s;return{pow_p_5_8:en(y,ih,s)*t%s,b2:o}}function D2(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function $2(t,e){const n=cc,r=Be(e*e*e,n),i=Be(r*r*e,n),s=O2(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),f2(o,n)&&(o=Be(-o,n)),{isValid:l||f,value:o}}const P2=(()=>Qf(cc,void 0,!0))(),T2=(()=>({a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:P2,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:B2,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:Qm,randomBytes:qf,adjustScalarBytes:D2,uvRatio:$2}))(),sh=(()=>S2(T2))(),R2="EdDSA",N2="JWT",eo=".",to="base64url",oh="utf8",ah="utf8",C2=":",U2="did",F2="key",ch="base58btc",L2="z",k2="K36",q2=32;function uc(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?uc(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 uc(n)}function M2(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 y=0,m=0,B=0,$=p.length;B!==$&&p[B]===0;)B++,y++;for(var _=($-B)*l+1>>>0,x=new Uint8Array(_);B!==$;){for(var P=p[B],R=0,U=_-1;(P!==0||R<m)&&U!==-1;U--,R++)P+=256*x[U]>>>0,x[U]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");m=R,B++}for(var F=_-m;F!==_&&x[F]===0;)F++;for(var D=c.repeat(y);F<_;++F)D+=t.charAt(x[F]);return D}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var y=0;if(p[y]!==" "){for(var m=0,B=0;p[y]===c;)m++,y++;for(var $=(p.length-y)*u+1>>>0,_=new Uint8Array($);p[y];){var x=n[p.charCodeAt(y)];if(x===255)return;for(var P=0,R=$-1;(x!==0||P<B)&&R!==-1;R--,P++)x+=a*_[R]>>>0,_[R]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");B=P,y++}if(p[y]!==" "){for(var U=$-B;U!==$&&_[U]===0;)U++;for(var F=new Uint8Array(m+($-U)),D=m;U!==$;)F[D++]=_[U++];return F}}}function h(p){var y=d(p);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:h}}var j2=M2,z2=j2;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")},H2=t=>new TextEncoder().encode(t),V2=t=>new TextDecoder().decode(t);class K2{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 G2{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 W2{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 W2({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class Z2{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new K2(e,n,r),this.decoder=new G2(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 Z2(t,e,n,r),Mi=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=z2(n,e);return no({prefix:t,name:e,encode:r,decode:s=>fh(i(s))})},Y2=(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},X2=(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 X2(i,r,n)},decode(i){return Y2(i,r,n,t)}}),J2=no({prefix:"\0",name:"identity",encode:t=>V2(t),decode:t=>H2(t)});var Q2=Object.freeze({__proto__:null,identity:J2});const ev=Fe({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var tv=Object.freeze({__proto__:null,base2:ev});const nv=Fe({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var rv=Object.freeze({__proto__:null,base8:nv});const iv=Mi({prefix:"9",name:"base10",alphabet:"0123456789"});var sv=Object.freeze({__proto__:null,base10:iv});const ov=Fe({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),av=Fe({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var cv=Object.freeze({__proto__:null,base16:ov,base16upper:av});const uv=Fe({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),lv=Fe({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),fv=Fe({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),hv=Fe({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),dv=Fe({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pv=Fe({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),gv=Fe({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),yv=Fe({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),bv=Fe({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var wv=Object.freeze({__proto__:null,base32:uv,base32upper:lv,base32pad:fv,base32padupper:hv,base32hex:dv,base32hexupper:pv,base32hexpad:gv,base32hexpadupper:yv,base32z:bv});const mv=Mi({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),vv=Mi({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ev=Object.freeze({__proto__:null,base36:mv,base36upper:vv});const xv=Mi({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),_v=Mi({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Sv=Object.freeze({__proto__:null,base58btc:xv,base58flickr:_v});const Iv=Fe({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Av=Fe({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Bv=Fe({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Ov=Fe({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Dv=Object.freeze({__proto__:null,base64:Iv,base64pad:Av,base64url:Bv,base64urlpad:Ov});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}"),$v=dh.reduce((t,e,n)=>(t[n]=e,t),[]),Pv=dh.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function Tv(t){return t.reduce((e,n)=>(e+=$v[n],e),"")}function Rv(t){const e=[];for(const n of t){const r=Pv[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const Nv=no({prefix:"\u{1F680}",name:"base256emoji",encode:Tv,decode:Rv});var Cv=Object.freeze({__proto__:null,base256emoji:Nv}),Uv=gh,ph=128,Fv=127,Lv=~Fv,kv=Math.pow(2,31);function gh(t,e,n){e=e||[],n=n||0;for(var r=n;t>=kv;)e[n++]=t&255|ph,t/=128;for(;t&Lv;)e[n++]=t&255|ph,t>>>=7;return e[n]=t|0,gh.bytes=n-r+1,e}var qv=lc,Mv=128,yh=127;function lc(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw lc.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>=Mv);return lc.bytes=s-r,n}var jv=Math.pow(2,7),zv=Math.pow(2,14),Hv=Math.pow(2,21),Vv=Math.pow(2,28),Kv=Math.pow(2,35),Gv=Math.pow(2,42),Wv=Math.pow(2,49),Zv=Math.pow(2,56),Yv=Math.pow(2,63),Xv=function(t){return t<jv?1:t<zv?2:t<Hv?3:t<Vv?4:t<Kv?5:t<Gv?6:t<Wv?7:t<Zv?8:t<Yv?9:10},Jv={encode:Uv,decode:qv,encodingLength:Xv},bh=Jv;const wh=(t,e,n=0)=>(bh.encode(t,e,n),e),mh=t=>bh.encodingLength(t),fc=(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 Qv(t,n,e,s)};class Qv{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 e3(t,e,n);class e3{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?fc(this.code,n):n.then(r=>fc(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)),t3=vh({name:"sha2-256",code:18,encode:Eh("SHA-256")}),n3=vh({name:"sha2-512",code:19,encode:Eh("SHA-512")});var r3=Object.freeze({__proto__:null,sha256:t3,sha512:n3});const xh=0,i3="identity",_h=fh;var s3=Object.freeze({__proto__:null,identity:{code:xh,name:i3,encode:_h,digest:t=>fc(xh,_h(t))}});new TextEncoder,new TextDecoder;const Sh={...Q2,...tv,...rv,...sv,...cv,...wv,...Ev,...Sv,...Dv,...Cv};({...r3,...s3});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))),hc=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:hc,ascii:hc,binary:hc,...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?uc(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(k2,ch),n=L2+ro(lh([e,t]),ch);return[U2,F2,n].join(C2)}function o3(t){return ro(t,to)}function a3(t){return si(t,to)}function c3(t){return si([io(t.header),io(t.payload)].join(eo),ah)}function u3(t){return[io(t.header),io(t.payload),o3(t.signature)].join(eo)}function dc(t){const e=t.split(eo),n=Oh(e[0]),r=Oh(e[1]),i=a3(e[2]),s=si(e.slice(0,2).join(eo),ah);return{header:n,payload:r,signature:i,data:s}}function $h(t=qf(q2)){const e=sh.getPublicKey(t);return{secretKey:lh([t,e]),publicKey:e}}async function l3(t,e,n,r,i=K.fromMiliseconds(Date.now())){const s={alg:R2,typ:N2},o=Dh(r.publicKey),a=i+n,c={iss:o,sub:t,aud:e,iat:i,exp:a},u=c3({header:s,payload:c}),l=sh.sign(u,r.secretKey.slice(0,32));return u3({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))},f3=function(){function t(e,n,r){this.name=e,this.version=n,this.os=r,this.type="browser"}return t}(),h3=function(){function t(e){this.version=e,this.type="node",this.name="node",this.os=process.platform}return t}(),d3=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}(),p3=function(){function t(){this.type="bot",this.bot=!0,this.name="bot",this.version=null,this.os=null}return t}(),g3=function(){function t(){this.type="react-native",this.name="react-native",this.version=null,this.os=null}return t}(),y3=/alexa|bot|crawl(er|ing)|facebookexternalhit|feedburner|google web preview|nagios|postrank|pingdom|slurp|spider|yahoo!|yandex/,b3=/(nuhk|curl|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask\ Jeeves\/Teoma|ia_archiver)/,Th=3,w3=[["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",y3]],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 m3(t){return t?Nh(t):typeof document>"u"&&typeof navigator<"u"&&navigator.product==="ReactNative"?new g3:typeof navigator<"u"?Nh(navigator.userAgent):x3()}function v3(t){return t!==""&&w3.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=v3(t);if(!e)return null;var n=e[0],r=e[1];if(n==="searchbot")return new p3;var i=r[1]&&r[1].split(".").join("_").split("_").slice(0,3);i?i.length<Th&&(i=Ph(Ph([],i,!0),_3(Th-i.length),!0)):i=[];var s=i.join("."),o=E3(t),a=b3.exec(t);return a&&a[1]?new d3(n,s,o,a[1]):new f3(n,s,o)}function E3(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 x3(){var t=typeof process<"u"&&process.version;return t?new h3(process.version.slice(1)):null}function _3(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=pc=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 S3(){return oi("document")}be.getDocumentOrThrow=S3;function I3(){return $r("document")}var Pr=be.getDocument=I3;function A3(){return oi("navigator")}be.getNavigatorOrThrow=A3;function B3(){return $r("navigator")}var pc=be.getNavigator=B3;function O3(){return oi("location")}be.getLocationOrThrow=O3;function D3(){return $r("location")}var Ch=be.getLocation=D3;function $3(){return oi("crypto")}be.getCryptoOrThrow=$3;function P3(){return $r("crypto")}be.getCrypto=P3;function T3(){return oi("localStorage")}be.getLocalStorageOrThrow=T3;function R3(){return $r("localStorage")}be.getLocalStorage=R3;var gc={};Object.defineProperty(gc,"__esModule",{value:!0});var Uh=gc.getWindowMetadata=void 0;const Fh=be;function N3(){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],y=p.getAttribute("rel");if(y&&y.toLowerCase().indexOf("icon")>-1){const m=p.getAttribute("href");if(m)if(m.toLowerCase().indexOf("https:")===-1&&m.toLowerCase().indexOf("http:")===-1&&m.indexOf("//")!==0){let B=e.protocol+"//"+e.host;if(m.indexOf("/")===0)B+=m;else{const $=e.pathname.split("/");$.pop();const _=$.join("/");B+=_+"/"+m}d.push(B)}else if(m.indexOf("//")===0){const B=e.protocol+m;d.push(B)}else d.push(m)}}return d}function r(...f){const d=t.getElementsByTagName("meta");for(let h=0;h<d.length;h++){const p=d[h],y=["itemprop","property","name"].map(m=>p.getAttribute(m)).filter(m=>m?f.includes(m):!1);if(y.length&&y){const m=p.getAttribute("content");if(m)return m}}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=gc.getWindowMetadata=N3;const C3="0.1.1";function U3(){return C3}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@${U3()}`}),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 F3(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(!F3(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 L3(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 k3(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 yc(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function tn(t,e){return t<<32-e|t>>>e}const q3=(()=>new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68)();function M3(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function j3(t){for(let e=0;e<t.length;e++)t[e]=M3(t[e]);return t}const qh=q3?t=>t:j3;function z3(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=z3(t)),Tr(t),t}function H3(...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 bc{}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 V3(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 K3(t,e,n){return t&e^~t&n}function G3(t,e,n){return t&e^t&n^e&n}class jh extends bc{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=yc(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=yc(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;V3(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=yc(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]),Ge=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),We=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 W3(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}=W3(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,Z3=(t,e,n)=>t<<n|e>>>32-n,Y3=(t,e,n)=>e<<n|t>>>32-n,X3=(t,e,n)=>e<<n-32|t>>>64-n,J3=(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 Q3=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),eE=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,tE=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),nE=(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),iE=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,sE=BigInt(0),zi=BigInt(1),oE=BigInt(2),aE=BigInt(7),cE=BigInt(256),uE=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=sE;for(let s=0;s<7;s++)e=(e<<zi^(e>>aE)*uE)%cE,e&oE&&(i^=zi<<(zi<<BigInt(s))-zi);Zh.push(i)}const Yh=Hh(Zh,!0),lE=Yh[0],fE=Yh[1],Xh=(t,e,n)=>n>32?X3(t,e,n):Z3(t,e,n),Jh=(t,e,n)=>n>32?J3(t,e,n):Y3(t,e,n);function hE(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]^=lE[r],t[1]^=fE[r]}zn(n)}class wc extends bc{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=k3(this.state)}clone(){return this._cloneInto()}keccak(){qh(this.state32),hE(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 wc(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 dE=(t,e,n)=>oo(()=>new wc(e,t,n)),pE=(()=>dE(1,136,256/8))(),gE=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 yE 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,y=tn(h,17)^tn(h,19)^h>>>10;Hn[f]=y+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+K3(a,c,u)+gE[f]+Hn[f]|0,y=(tn(r,2)^tn(r,13)^tn(r,22))+G3(r,i,s)|0;l=u,u=c,c=a,a=o+h|0,o=s,s=i,i=r,r=h+y|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))))(),bE=(()=>Qh[0])(),wE=(()=>Qh[1])(),Vn=new Uint32Array(80),Kn=new Uint32Array(80);class ed extends jh{constructor(e=64){super(128,e,16,!1),this.Ah=We[0]|0,this.Al=We[1]|0,this.Bh=We[2]|0,this.Bl=We[3]|0,this.Ch=We[4]|0,this.Cl=We[5]|0,this.Dh=We[6]|0,this.Dl=We[7]|0,this.Eh=We[8]|0,this.El=We[9]|0,this.Fh=We[10]|0,this.Fl=We[11]|0,this.Gh=We[12]|0,this.Gl=We[13]|0,this.Hh=We[14]|0,this.Hl=We[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:y,Hl:m}=this;return[e,n,r,i,s,o,a,c,u,l,f,d,h,p,y,m]}set(e,n,r,i,s,o,a,c,u,l,f,d,h,p,y,m){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=y|0,this.Hl=m|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,P=Kn[_-15]|0,R=ui(x,P,1)^ui(x,P,8)^Vh(x,P,7),U=li(x,P,1)^li(x,P,8)^Kh(x,P,7),F=Vn[_-2]|0,D=Kn[_-2]|0,j=ui(F,D,19)^co(F,D,61)^Vh(F,D,6),M=li(F,D,19)^uo(F,D,61)^Kh(F,D,6),E=tE(U,M,Kn[_-7],Kn[_-16]),b=nE(E,R,j,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:y,Gl:m,Hh:B,Hl:$}=this;for(let _=0;_<80;_++){const x=ui(f,d,14)^ui(f,d,18)^co(f,d,41),P=li(f,d,14)^li(f,d,18)^uo(f,d,41),R=f&h^~f&y,U=d&p^~d&m,F=rE($,P,U,wE[_],Kn[_]),D=iE(F,B,x,R,bE[_],Vn[_]),j=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,v=i&o^i&c^o&c;B=y|0,$=m|0,y=h|0,m=p|0,h=f|0,p=d|0,{h:f,l:d}=bn(u|0,l|0,D|0,j|0),u=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=Q3(j,E,v);r=eE(g,D,M,b),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: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:y,l:m}=bn(this.Gh|0,this.Gl|0,y|0,m|0),{h:B,l:$}=bn(this.Hh|0,this.Hl|0,B|0,$|0),this.set(r,i,s,o,a,c,u,l,f,d,h,p,y,m,B,$)}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 mE extends ed{constructor(){super(48),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}}const lo=oo(()=>new yE),vE=oo(()=>new ed),EE=oo(()=>new mE);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const mc=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===""?mc:BigInt("0x"+t)}const nd=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",xE=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+=xE[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 Ze(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 vc(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}const Ec=t=>typeof t=="bigint"&&mc<=t;function xc(t,e,n){return Ec(t)&&Ec(e)&&Ec(n)&&e<=t&&t<n}function fi(t,e,n,r){if(!xc(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Ki(t){let e;for(e=0;t>mc;t>>=fo,e+=1);return e}function _E(t,e){return t>>BigInt(e)&fo}const Nr=t=>(fo<<BigInt(t))-fo,_c=t=>new Uint8Array(t),od=t=>Uint8Array.from(t);function SE(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=_c(t),i=_c(t),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},a=(...f)=>n(i,r,...f),c=(f=_c(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 IE={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=IE[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 Sc(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 AE(t,e){if(dd(t)>e)throw new WE({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 BE(t,e={}){const{dir:n,size:r=32}=e;if(r===0)return t;if(t.length>r)throw new ZE({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 Ic(t,e){if(En(t)>e)throw new LE({givenSize:En(t),maxSize:e})}function OE(t,e){if(typeof e=="number"&&e>0&&e>En(t)-1)throw new hd({offset:e,position:"start",size:En(t)})}function DE(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 kE({size:Math.ceil(i.length/2),targetSize:r,type:"Hex"});return`0x${i[n==="right"?"padEnd":"padStart"](r*2,"0")}`}const $E="#__bigint";function Ac(t,e,n){return JSON.stringify(t,(r,i)=>typeof e=="function"?e(r,i):typeof i=="bigint"?i.toString()+$E:i,n)}const PE=new TextEncoder,TE=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function RE(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 Bc(...t){return`0x${t.reduce((e,n)=>e+n.replace("0x",""),"")}`}function Oc(t){return t instanceof Uint8Array?Wi(t):Array.isArray(t)?Wi(new Uint8Array(t)):t}function NE(t,e={}){const n=`0x${Number(t)}`;return typeof e.size=="number"?(Ic(n,e.size),yo(n,e.size)):n}function Wi(t,e={}){let n="";for(let i=0;i<t.length;i++)n+=TE[t[i]];const r=`0x${n}`;return typeof e.size=="number"?(Ic(r,e.size),Dc(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 FE({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 CE(t,e={}){return Wi(PE.encode(t),e)}function yo(t,e){return ud(t,{dir:"left",size:e})}function Dc(t,e){return ud(t,{dir:"right",size:e})}function vn(t,e,n,r={}){const{strict:i}=r;OE(t,e);const s=`0x${t.replace("0x","").slice((e??0)*2,(n??t.length)*2)}`;return i&&DE(s,e,n),s}function En(t){return Math.ceil((t.length-2)/2)}function UE(t,e={}){const{strict:n=!1}=e;try{return RE(t,{strict:n}),!0}catch{return!1}}class FE 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"?Ac(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 LE 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 kE 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 qE=new TextEncoder;function ME(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 jE(t){return t instanceof Uint8Array?t:typeof t=="string"?HE(t):zE(t)}function zE(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function HE(t,e={}){const{size:n}=e;let r=t;n&&(Ic(t,n),r=Dc(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 VE(t,e={}){const{size:n}=e,r=qE.encode(t);return typeof n=="number"?(AE(r,n),KE(r,n)):r}function KE(t,e){return BE(t,{dir:"right",size:e})}function dd(t){return t.length}function GE(t){try{return ME(t),!0}catch{return!1}}class bo extends ge{constructor(e){super(`Value \`${typeof e=="object"?Ac(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 WE 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 ZE 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=pE(jE(t));return n==="Bytes"?r:Wi(r)}class YE 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 $c={checksum:new YE(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 n8});return}if(n===!0||typeof i=="bigint"&&typeof s>"u"){if(r!==3&&r!==2)throw new bd({prefix:r,cause:new t8});return}throw new e8({publicKey:t})}function XE(t){const e=(()=>{if(UE(t))return yd(t);if(GE(t))return JE(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 JE(t){return yd(Wi(t))}function yd(t){if(t.length!==132&&t.length!==130&&t.length!==68)throw new r8({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 QE(t,e={}){gd(t);const{prefix:n,x:r,y:i}=t,{includePrefix:s=!0}=e;return Bc(s?go(n,{size:1}):"0x",go(r,{size:32}),typeof i=="bigint"?go(i,{size:32}):"0x")}class e8 extends ge{constructor({publicKey:e}){super(`Value \`${Ac(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 t8 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 n8 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 r8 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(Oc(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidSerializedSizeError"})}}const i8=/^0x[a-fA-F0-9]{40}$/;function Pc(t,e={}){const{strict:n=!0}=e;if(!i8.test(t))throw new md({address:t,cause:new a8});if(n){if(t.toLowerCase()===t)return;if(wd(t)!==t)throw new md({address:t,cause:new c8})}}function wd(t){if($c.has(t))return $c.get(t);Pc(t,{strict:!1});const e=t.substring(2).toLowerCase(),n=pd(VE(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 $c.set(t,i),i}function s8(t,e={}){const{checksum:n=!1}=e;return Pc(t),n?wd(t):t}function o8(t,e={}){const n=pd(`0x${QE(t).slice(4)}`).substring(26);return s8(`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 a8 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 c8 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 u8=/^(.*)\[([0-9]*)\]$/,l8=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,f8=/^(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 Tc(t,e){if(t.length!==e.length)throw new d8({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(Tc.encode(i,s))}return Bc(...n)}(function(t){function e(n,r,i=!1){if(n==="address"){const c=r;return Pc(c),yo(c.toLowerCase(),i?32:0)}if(n==="string")return CE(r);if(n==="bytes")return r;if(n==="bool")return yo(NE(r),i?32:1);const s=n.match(f8);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(l8);if(o){const[c,u]=o;if(Number.parseInt(u,10)!==(r.length-2)/2)throw new h8({expectedSize:Number.parseInt(u,10),value:r});return Dc(r,i?32:0)}const a=n.match(u8);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":Bc(...l)}throw new p8(n)}t.encode=e})(Tc||(Tc={}));class h8 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 d8 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 p8 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 bc{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,L3(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),g8=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 Rc(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 y8(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 b8(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,y=c.sqr(d);for(;!c.eql(y,c.ONE);)if(p++,y=c.sqr(y),p===l)throw new Error("Cannot find square root");const m=it<<BigInt(l-p-1),B=c.pow(f,m);l=p,f=c.sqr(B),d=c.mul(d,f),h=c.mul(h,B)}return h}}function w8(t){return t%xd===g8?Id:t%Sd===_d?y8:b8(t)}const m8=["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=m8.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*Rc(u,t),t),sqrN:c=>c*c,addN:(c,u)=>c+u,subN:(c,u)=>c-u,mulN:(c,u)=>c*u,inv:c=>Rc(c,t),sqrt:r.sqrt||(c=>(o||(o=w8(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 Nc(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=Nc(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),Cc=BigInt(1);function Uc(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 Fc(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+=Cc);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 v8(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 E8(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 Lc=new WeakMap,Rd=new WeakMap;function kc(t){return Rd.get(t)||1}function x8(t,e){return{constTimeNegate:Uc,hasPrecomputes(n){return kc(n)!==1},unsafeLadder(n,r,i=t.ZERO){let s=n;for(;r>$d;)r&Cc&&(i=i.add(s)),s=s.double(),r>>=Cc;return i},precomputeWindow(n,r){const{windows:i,windowSize:s}=Fc(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=Fc(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(Uc(h,r[p])):s=s.add(Uc(d,r[l]))}return{p:s,f:o}},wNAFUnsafe(n,r,i,s=t.ZERO){const o=Fc(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=Lc.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&Lc.set(r,i(s))),s},wNAFCached(n,r,i){const s=kc(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=kc(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),Lc.delete(n)}}}function _8(t,e,n,r){v8(n,t),E8(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 y=0;y<s;y++){const m=r[y],B=Number(m>>BigInt(h)&u);l[B]=l[B].add(n[y])}let p=o;for(let y=l.length-1,m=o;y>0;y--)m=m.add(l[y]),p=p.add(m);if(d=d.add(p),h!==0)for(let y=0;y<c;y++)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 S8(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 I8 extends Error{constructor(e=""){super(e)}}const xn={Err:I8,_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=Ze("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 qc(t,e){return Rr(Oe(t,e))}const zt=BigInt(0),pe=BigInt(1),Zn=BigInt(2),Zi=BigInt(3),Mc=BigInt(4);function jc(t){const e=S8(t),{Fp:n}=e,r=Wn(e.n,e.nBitLength),i=e.toBytes||((_,x,P)=>{const R=x.toAffine();return _e(Uint8Array.from([4]),n.toBytes(R.x),n.toBytes(R.y))}),s=e.fromBytes||(_=>{const x=_.subarray(1),P=n.fromBytes(x.subarray(0,n.BYTES)),R=n.fromBytes(x.subarray(n.BYTES,2*n.BYTES));return{x:P,y:R}});function o(_){const{a:x,b:P}=e,R=n.sqr(_),U=n.mul(R,_);return n.add(n.add(U,n.mul(_,x)),P)}function a(_,x){const P=n.sqr(x),R=o(_);return n.eql(P,R)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const c=n.mul(n.pow(e.a,Zi),Mc),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 xc(_,pe,e.n)}function f(_){const{allowedPrivateKeyLengths:x,nByteLength:P,wrapPrivateKey:R,n:U}=e;if(x&&typeof _!="bigint"){if(Hi(_)&&(_=Rr(_)),typeof _!="string"||!x.includes(_.length))throw new Error("invalid private key");_=_.padStart(P*2,"0")}let F;try{F=typeof _=="bigint"?_:rt(Ze("private key",_,P))}catch{throw new Error("invalid private key, expected hex or "+P+" bytes, got "+typeof _)}return R&&(F=st(F,U)),fi("private key",F,pe,U),F}function d(_){if(!(_ instanceof y))throw new Error("ProjectivePoint expected")}const h=Sc((_,x)=>{const{px:P,py:R,pz:U}=_;if(n.eql(U,n.ONE))return{x:P,y:R};const F=_.is0();x==null&&(x=F?n.ONE:n.inv(U));const D=n.mul(P,x),j=n.mul(R,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:D,y:j}}),p=Sc(_=>{if(_.is0()){if(e.allowInfinityPoint&&!n.is0(_.py))return;throw new Error("bad point: ZERO")}const{x,y:P}=_.toAffine();if(!n.isValid(x)||!n.isValid(P))throw new Error("bad point: x or y not FE");if(!a(x,P))throw new Error("bad point: equation left != right");if(!_.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class y{constructor(x,P,R){if(x==null||!n.isValid(x))throw new Error("x required");if(P==null||!n.isValid(P)||n.is0(P))throw new Error("y required");if(R==null||!n.isValid(R))throw new Error("z required");this.px=x,this.py=P,this.pz=R,Object.freeze(this)}static fromAffine(x){const{x:P,y:R}=x||{};if(!x||!n.isValid(P)||!n.isValid(R))throw new Error("invalid affine point");if(x instanceof y)throw new Error("projective point not allowed");const U=F=>n.eql(F,n.ZERO);return U(P)&&U(R)?y.ZERO:new y(P,R,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(x){const P=Ur(n,x.map(R=>R.pz));return x.map((R,U)=>R.toAffine(P[U])).map(y.fromAffine)}static fromHex(x){const P=y.fromAffine(s(Ze("pointHex",x)));return P.assertValidity(),P}static fromPrivateKey(x){return y.BASE.multiply(f(x))}static msm(x,P){return _8(y,r,x,P)}_setWindowSize(x){$.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:P,py:R,pz:U}=this,{px:F,py:D,pz:j}=x,M=n.eql(n.mul(P,j),n.mul(F,U)),E=n.eql(n.mul(R,j),n.mul(D,U));return M&&E}negate(){return new y(this.px,n.neg(this.py),this.pz)}double(){const{a:x,b:P}=e,R=n.mul(P,Zi),{px:U,py:F,pz:D}=this;let j=n.ZERO,M=n.ZERO,E=n.ZERO,b=n.mul(U,U),v=n.mul(F,F),g=n.mul(D,D),w=n.mul(U,F);return w=n.add(w,w),E=n.mul(U,D),E=n.add(E,E),j=n.mul(x,E),M=n.mul(R,g),M=n.add(j,M),j=n.sub(v,M),M=n.add(v,M),M=n.mul(j,M),j=n.mul(w,j),E=n.mul(R,E),g=n.mul(x,g),w=n.sub(b,g),w=n.mul(x,w),w=n.add(w,E),E=n.add(b,b),b=n.add(E,b),b=n.add(b,g),b=n.mul(b,w),M=n.add(M,b),g=n.mul(F,D),g=n.add(g,g),b=n.mul(g,w),j=n.sub(j,b),E=n.mul(g,v),E=n.add(E,E),E=n.add(E,E),new y(j,M,E)}add(x){d(x);const{px:P,py:R,pz:U}=this,{px:F,py:D,pz:j}=x;let M=n.ZERO,E=n.ZERO,b=n.ZERO;const v=e.a,g=n.mul(e.b,Zi);let w=n.mul(P,F),S=n.mul(R,D),A=n.mul(U,j),I=n.add(P,R),O=n.add(F,D);I=n.mul(I,O),O=n.add(w,S),I=n.sub(I,O),O=n.add(P,U);let T=n.add(F,j);return O=n.mul(O,T),T=n.add(w,A),O=n.sub(O,T),T=n.add(R,U),M=n.add(D,j),T=n.mul(T,M),M=n.add(S,A),T=n.sub(T,M),b=n.mul(v,O),M=n.mul(g,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(v,A),O=n.mul(g,O),S=n.add(S,A),A=n.sub(w,A),A=n.mul(v,A),O=n.add(O,A),w=n.mul(S,O),E=n.add(E,w),w=n.mul(T,O),M=n.mul(I,M),M=n.sub(M,w),w=n.mul(I,S),b=n.mul(T,b),b=n.add(b,w),new y(M,E,b)}subtract(x){return this.add(x.negate())}is0(){return this.equals(y.ZERO)}wNAF(x){return $.wNAFCached(this,x,y.normalizeZ)}multiplyUnsafe(x){const{endo:P,n:R}=e;fi("scalar",x,zt,R);const U=y.ZERO;if(x===zt)return U;if(this.is0()||x===pe)return this;if(!P||$.hasPrecomputes(this))return $.wNAFCachedUnsafe(this,x,y.normalizeZ);let{k1neg:F,k1:D,k2neg:j,k2:M}=P.splitScalar(x),E=U,b=U,v=this;for(;D>zt||M>zt;)D&pe&&(E=E.add(v)),M&pe&&(b=b.add(v)),v=v.double(),D>>=pe,M>>=pe;return F&&(E=E.negate()),j&&(b=b.negate()),b=new y(n.mul(b.px,P.beta),b.py,b.pz),E.add(b)}multiply(x){const{endo:P,n:R}=e;fi("scalar",x,pe,R);let U,F;if(P){const{k1neg:D,k1:j,k2neg:M,k2:E}=P.splitScalar(x);let{p:b,f:v}=this.wNAF(j),{p:g,f:w}=this.wNAF(E);b=$.constTimeNegate(D,b),g=$.constTimeNegate(M,g),g=new y(n.mul(g.px,P.beta),g.py,g.pz),U=b.add(g),F=v.add(w)}else{const{p:D,f:j}=this.wNAF(x);U=D,F=j}return y.normalizeZ([U,F])[0]}multiplyAndAddUnsafe(x,P,R){const U=y.BASE,F=(j,M)=>M===zt||M===pe||!j.equals(U)?j.multiplyUnsafe(M):j.multiply(M),D=F(this,P).add(F(x,R));return D.is0()?void 0:D}toAffine(x){return h(this,x)}isTorsionFree(){const{h:x,isTorsionFree:P}=e;if(x===pe)return!0;if(P)return P(y,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:x,clearCofactor:P}=e;return x===pe?this:P?P(y,this):this.multiplyUnsafe(e.h)}toRawBytes(x=!0){return Vi("isCompressed",x),this.assertValidity(),i(y,this,x)}toHex(x=!0){return Vi("isCompressed",x),Rr(this.toRawBytes(x))}}y.BASE=new y(e.Gx,e.Gy,n.ONE),y.ZERO=new y(n.ZERO,n.ONE,n.ZERO);const{endo:m,nBitLength:B}=e,$=x8(y,m?Math.ceil(B/2):B);return{CURVE:e,ProjectivePoint:y,normPrivateKeyToScalar:f,weierstrassEquation:o,isWithinCurveOrder:l}}function A8(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 B8(t){const e=A8(t),{Fp:n,n:r,nByteLength:i,nBitLength:s}=e,o=n.BYTES+1,a=2*n.BYTES+1;function c(g){return st(g,r)}function u(g){return Rc(g,r)}const{ProjectivePoint:l,normPrivateKeyToScalar:f,weierstrassEquation:d,isWithinCurveOrder:h}=jc({...e,toBytes(g,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(g){const w=g.length,S=g[0],A=g.subarray(1);if(w===o&&(S===2||S===3)){const I=rt(A);if(!xc(I,pe,n.ORDER))throw new Error("Point is not on curve");const O=d(I);let T;try{T=n.sqrt(O)}catch(k){const N=k instanceof Error?": "+k.message:"";throw new Error("Point is not on curve"+N)}const L=(T&pe)===pe;return(S&1)===1!==L&&(T=n.neg(T)),{x:I,y:T}}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(g){const w=r>>pe;return g>w}function y(g){return p(g)?c(-g):g}const m=(g,w,S)=>rt(g.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=Ze("compactSignature",w,S*2),new B(m(w,0,S),m(w,S,2*S))}static fromDER(w){const{r:S,s:A}=xn.toSig(Ze("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(Ze("msgHash",w));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 L=I&1?"03":"02",C=l.fromHex(L+qc(T,n.BYTES)),k=u(T),N=c(-O*k),q=c(A*k),z=l.BASE.multiplyAndAddUnsafe(C,N,q);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}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 qc(this.r,w)+qc(this.s,w)}}const $={isValidPrivateKey(g){try{return f(g),!0}catch{return!1}},normPrivateKeyToScalar:f,randomPrivateKey:()=>{const g=Nc(e.n);return Dd(e.randomBytes(g),e.n)},precompute(g=8,w=l.BASE){return w._setWindowSize(g),w.multiply(BigInt(3)),w}};function _(g,w=!0){return l.fromPrivateKey(g).toRawBytes(w)}function x(g){if(typeof g=="bigint")return!1;if(g instanceof l)return!0;const S=Ze("key",g).length,A=n.BYTES,I=A+1,O=2*A+1;if(!(e.allowedPrivateKeyLengths||i===I))return S===I||S===O}function P(g,w,S=!0){if(x(g)===!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(g)).toRawBytes(S)}const R=e.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");const w=rt(g),S=g.length*8-s;return S>0?w>>BigInt(S):w},U=e.bits2int_modN||function(g){return c(R(g))},F=Nr(s);function D(g){return fi("num < 2^"+s,g,zt,F),Oe(g,i)}function j(g,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:T,extraEntropy:L}=S;O==null&&(O=!0),g=Ze("msgHash",g),Cd(S),T&&(g=Ze("prehashed msgHash",A(g)));const C=U(g),k=f(w),N=[D(k),D(C)];if(L!=null&&L!==!1){const V=L===!0?I(n.BYTES):L;N.push(Ze("extraEntropy",V))}const q=_e(...N),z=C;function W(V){const Z=R(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(z+ie*k));if(fe===zt)return;let ve=(ee.x===ie?0:2)|Number(ee.y&pe),Ln=fe;return O&&p(fe)&&(Ln=y(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(g,w,S=M){const{seed:A,k2sig:I}=j(g,w,S),O=e;return SE(O.hash.outputLen,O.nByteLength,O.hmac)(A,I)}l.BASE._setWindowSize(8);function v(g,w,S,A=E){const I=g;w=Ze("msgHash",w),S=Ze("publicKey",S);const{lowS:O,prehash:T,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;T&&(w=e.hash(w));const{r:z,s:W}=N,V=U(w),Z=u(W),Q=c(V*Z),ee=c(z*Z),ie=l.BASE.multiplyAndAddUnsafe(q,Q,ee)?.toAffine();return ie?c(ie.x)===z:!1}return{CURVE:e,getPublicKey:_,getSharedSecret:P,sign:b,verify:v,ProjectivePoint:l,Signature:B,utils:$}}function O8(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,y)=>{let m=f,B=t.pow(y,u),$=t.sqr(B);$=t.mul($,y);let _=t.mul(p,$);_=t.pow(_,c),_=t.mul(_,B),B=t.mul(_,y),$=t.mul(_,p);let x=t.mul($,B);_=t.pow(x,l);let P=t.eql(_,t.ONE);B=t.mul($,d),_=t.mul(x,m),$=t.cmov(B,$,P),x=t.cmov(_,x,P);for(let R=i;R>pe;R--){let U=R-Zn;U=Zn<<U-pe;let F=t.pow(x,U);const D=t.eql(F,t.ONE);B=t.mul($,m),m=t.mul(m,m),F=t.mul(x,m),$=t.cmov(B,$,D),x=t.cmov(F,x,D)}return{isValid:P,value:$}};if(t.ORDER%Mc===Zi){const p=(t.ORDER-Zi)/Mc,y=t.sqrt(t.neg(e));h=(m,B)=>{let $=t.sqr(B);const _=t.mul(m,B);$=t.mul($,_);let x=t.pow($,p);x=t.mul(x,_);const P=t.mul(x,y),R=t.mul(t.sqr(x),B),U=t.eql(R,m);let F=t.cmov(P,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=O8(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 y=Ur(t,[a],!0)[0];return l=t.mul(l,y),{x:l,y:f}}}function D8(t){return{hash:t,hmac:(e,...n)=>Ed(t,e,H3(...n)),randomBytes:Mh}}function vo(t,e){const n=r=>B8({...t,...D8(r)});return{...n(e),create:n}}const $8=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 P8(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 T8(t,e,n,r){Gn(t),Gn(e),Yi(n),e.length>255&&(e=r(_e(vc("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=[P8(f,l[h-1]),Yn(h+1,1),a];l[h]=r(_e(...p))}return _e(...l).slice(0,n)}function R8(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(vc("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"?vc(c):c,l=r.toString(2).length,f=Math.ceil((l+i)/8),d=e*s*f;let h;if(a==="xmd")h=T8(t,u,d,o);else if(a==="xof")h=R8(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 y=0;y<e;y++){const m=new Array(s);for(let B=0;B<s;B++){const $=f*(B+y*s),_=h.subarray($,$+f);m[B]=st($8(_),r)}p[y]=m}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"),N8=BigInt(0),C8=BigInt(1),zc=BigInt(2),jd=(t,e)=>(t+e/zc)/e;function U8(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,zc,e)*u%e,p=Pt(h,i,e)*h%e,y=Pt(p,s,e)*p%e,m=Pt(y,a,e)*y%e,B=Pt(m,c,e)*m%e,$=Pt(B,a,e)*y%e,_=Pt($,n,e)*l%e,x=Pt(_,o,e)*p%e,P=Pt(x,r,e)*u%e,R=Pt(P,zc,e);if(!Hc.eql(Hc.sqr(R),t))throw new Error("Cannot find square root");return R}const Hc=Wn(qd,void 0,void 0,{sqrt:U8}),F8=vo({a:N8,b:BigInt(7),Fp:Hc,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=-C8*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 L8(t){if(t.length!==130&&t.length!==132)throw new q8({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 k8(i)}catch{throw new M8({value:i})}})();return typeof r>"u"?{r:e,s:n}:{r:e,s:n,yParity:r}}function k8(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 j8({value:t})}class q8 extends ge{constructor({signature:e}){super(`Value \`${e}\` is an invalid signature size.`,{metaMessages:["Expected: 64 bytes or 65 bytes.",`Received ${En(Oc(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSerializedSizeError"})}}class M8 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 j8 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 z8=BigInt(0),Eo=BigInt(1),zd=BigInt(2),hi=BigInt(3);function H8(t){const e=[];for(;t>Eo;t>>=Eo)(t&Eo)===z8?e.unshift(0):(t&hi)===hi?(e.unshift(-1),t+=Eo):e.unshift(1);return e}function V8(t){const{Fp:e,Fr:n,Fp2:r,Fp6:i,Fp12:s}=t.fields,o=t.params.xNegative,a=t.params.twistType,c=jc({n:n.ORDER,...t.G1}),u=Object.assign(c,kd(c.ProjectivePoint,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),l=jc({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,z,W)=>s.mul014(q,C,r.mul(k,z),r.mul(N,W));else if(a==="divisive")d=(C,k,N,q,z,W)=>s.mul034(q,r.mul(N,W),r.mul(k,z),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 z=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),z),ee=r.sub(V,z),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(z,Z),k),N),h),N=r.sub(r.sqr(r.mul(r.add(z,Z),h)),r.mul(r.sqr(V),hi)),q=r.mul(z,Q),{Rx:k,Ry:N,Rz:q}}function y(C,k,N,q,z,W){const V=r.sub(N,r.mul(W,q)),Z=r.sub(k,r.mul(z,q)),Q=r.sub(r.mul(V,z),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),Oa=r.add(r.sub(ve,r.mul(Ln,zd)),r.mul(r.sqr(V),q));return k=r.mul(Z,Oa),N=r.sub(r.mul(r.sub(Ln,Oa),V),r.mul(ve,N)),q=r.mul(q,ve),{Rx:k,Ry:N,Rz:q}}const m=H8(t.params.ateLoopSize),B=Sc(C=>{const k=C,{x:N,y:q}=k.toAffine(),z=N,W=q,V=r.neg(q);let Z=z,Q=W,ee=r.ONE;const ie=[];for(const fe of m){const ve=[];({Rx:Z,Ry:Q,Rz:ee}=p(ve,Z,Q,ee)),fe&&({Rx:Z,Ry:Q,Rz:ee}=y(ve,Z,Q,ee,z,fe===-1?V:W)),ie.push(ve)}if(t.postPrecompute){const fe=ie[ie.length-1];t.postPrecompute(Z,Q,ee,z,W,y.bind(null,fe))}return ie});function $(C,k=!1){let N=s.ONE;if(C.length){const q=C[0][0].length;for(let z=0;z<q;z++){N=s.sqr(N);for(const[W,V,Z]of C)for(const[Q,ee,ie]of W[z])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:z}of C){if(q.equals(u.ProjectivePoint.ZERO)||z.equals(f.ProjectivePoint.ZERO))throw new Error("pairing is not available for ZERO point");q.assertValidity(),z.assertValidity();const W=q.toAffine();N.push([B(z),W.x,W.y])}return $(N,k)}function x(C,k,N=!0){return _([{g1:C,g2:k}],N)}const P={randomPrivateKey:()=>{const C=Nc(n.ORDER);return Dd(t.randomBytes(C),n.ORDER)},calcPairingPrecomputes:B},{ShortSignature:R}=t.G1,{Signature:U}=t.G2;function F(C){return C instanceof u.ProjectivePoint?C:u.ProjectivePoint.fromHex(C)}function D(C,k){return C instanceof u.ProjectivePoint?C:u.hashToCurve(Ze("point",C),k)}function j(C){return C instanceof f.ProjectivePoint?C:U.fromHex(C)}function M(C,k){return C instanceof f.ProjectivePoint?C:f.hashToCurve(Ze("point",C),k)}function E(C){return u.ProjectivePoint.fromPrivateKey(C).toRawBytes(!0)}function b(C){return f.ProjectivePoint.fromPrivateKey(C).toRawBytes(!0)}function v(C,k,N){const q=M(C,N);q.assertValidity();const z=q.multiply(u.normPrivateKeyToScalar(k));return C instanceof f.ProjectivePoint?z:U.toRawBytes(z)}function g(C,k,N){const q=D(C,N);q.assertValidity();const z=q.multiply(u.normPrivateKeyToScalar(k));return C instanceof u.ProjectivePoint?z:R.toRawBytes(z)}function w(C,k,N,q){const z=F(N),W=M(k,q),V=u.ProjectivePoint.BASE,Z=j(C),Q=_([{g1:z.negate(),g2:W},{g1:V,g2:Z}]);return s.eql(Q,s.ONE)}function S(C,k,N,q){const z=j(N),W=D(k,q),V=f.ProjectivePoint.BASE,Z=F(C),Q=_([{g1:W,g2:z},{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,z)=>q.add(z),u.ProjectivePoint.ZERO);return C[0]instanceof u.ProjectivePoint?(N.assertValidity(),N):N.toRawBytes(!0)}function O(C){A(C);const N=C.map(j).reduce((q,z)=>q.add(z),f.ProjectivePoint.ZERO);return C[0]instanceof f.ProjectivePoint?(N.assertValidity(),N):U.toRawBytes(N)}function T(C){A(C);const N=C.map(F).reduce((q,z)=>q.add(z),u.ProjectivePoint.ZERO);return C[0]instanceof u.ProjectivePoint?(N.assertValidity(),N):R.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 z=j(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:z}),s.eql(_(Q),s.ONE)}catch{return!1}}return u.ProjectivePoint.BASE._setWindowSize(4),{getPublicKey:E,getPublicKeyForShortSignatures:b,sign:v,signShortSignature:g,verify:w,verifyBatch:L,verifyShortSignature:S,aggregatePublicKeys:I,aggregateSignatures:O,aggregateShortSignatures:T,millerLoopBatch:$,pairing:x,pairingBatch:_,G1:u,G2:f,Signature:U,ShortSignature:R,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:P}}const K8=BigInt(0),di=BigInt(1),_n=BigInt(2),Hd=BigInt(3);function Vc(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 G8(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),y=e.mul(e.frobeniusMap(h,1),i);return[p,y]}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 y=p.toAffine(),m=d(y.x,y.y);return h.fromAffine({x:m[0],y:m[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 W8(t){const{ORDER:e}=t,n=Wn(e),r=n.create(t.NONRESIDUE||BigInt(-1)),i=n.div(n.ONE,_n),s=Vc(n,r,n.ORDER,2)[0],o=({c0:E,c1:b},{c0:v,c1:g})=>({c0:n.add(E,v),c1:n.add(b,g)}),a=({c0:E,c1:b},{c0:v,c1:g})=>({c0:n.sub(E,v),c1:n.sub(b,g)}),c=({c0:E,c1:b},v)=>{if(typeof v=="bigint")return{c0:n.mul(E,v),c1:n.mul(b,v)};const{c0:g,c1:w}=v;let S=n.mul(E,g),A=n.mul(b,w);const I=n.sub(S,A),O=n.sub(n.mul(n.add(E,b),n.add(g,w)),n.add(S,A));return{c0:I,c1:O}},u=({c0:E,c1:b})=>{const v=n.add(E,b),g=n.sub(E,b),w=n.add(E,E);return{c0:n.mul(v,g),c1:n.mul(w,b)}},l=E=>{if(E.length!==2)throw new Error("invalid tuple");const b=E.map(v=>n.create(v));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:v,c1:g})=>n.eql(E,v)&&n.eql(b,g),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 v=n.inv(n.create(E*E+b*b));return{c0:n.mul(v,n.create(E)),c1:n.mul(v,n.create(-b))}},sqrt:E=>{if(t.Fp2sqrt)return t.Fp2sqrt(E);const{c0:b,c1:v}=E;if(n.is0(v))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 g=n.sqrt(n.sub(n.sqr(b),n.mul(n.sqr(v),r)));let w=n.mul(n.add(g,b),i);mo(n,w)===-1&&(w=n.sub(w,g));const A=n.sqrt(w),I=h.create({c0:A,c1:n.div(n.mul(v,i),A)});if(!h.eql(h.sqr(I),E))throw new Error("Cannot find square root");const O=I,T=h.neg(O),{re:L,im:C}=h.reim(O),{re:k,im:N}=h.reim(T);return C>N||C===N&&L>k?O:T},isOdd:E=>{const{re:b,im:v}=h.reim(E),g=b%_n,w=b===K8,S=v%_n;return BigInt(g||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:v,c1:g},w)=>({c0:n.cmov(E,v,w),c1:n.cmov(b,g,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},v)=>({c0:E,c1:n.mul(b,s[v%2])})},p=({c0:E,c1:b,c2:v},{c0:g,c1:w,c2:S})=>({c0:h.add(E,g),c1:h.add(b,w),c2:h.add(v,S)}),y=({c0:E,c1:b,c2:v},{c0:g,c1:w,c2:S})=>({c0:h.sub(E,g),c1:h.sub(b,w),c2:h.sub(v,S)}),m=({c0:E,c1:b,c2:v},g)=>{if(typeof g=="bigint")return{c0:h.mul(E,g),c1:h.mul(b,g),c2:h.mul(v,g)};const{c0:w,c1:S,c2:A}=g,I=h.mul(E,w),O=h.mul(b,S),T=h.mul(v,A);return{c0:h.add(I,h.mulByNonresidue(h.sub(h.mul(h.add(b,v),h.add(S,A)),h.add(O,T)))),c1:h.add(h.sub(h.mul(h.add(E,b),h.add(w,S)),h.add(I,O)),h.mulByNonresidue(T)),c2:h.sub(h.add(O,h.mul(h.add(E,v),h.add(w,A))),h.add(I,T))}},B=({c0:E,c1:b,c2:v})=>{let g=h.sqr(E),w=h.mul(h.mul(E,b),_n),S=h.mul(h.mul(b,v),_n),A=h.sqr(v);return{c0:h.add(h.mulByNonresidue(S),g),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),v))),S),g),A)}},[$,_]=Vc(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:v})=>h.isValid(E)&&h.isValid(b)&&h.isValid(v),is0:({c0:E,c1:b,c2:v})=>h.is0(E)&&h.is0(b)&&h.is0(v),neg:({c0:E,c1:b,c2:v})=>({c0:h.neg(E),c1:h.neg(b),c2:h.neg(v)}),eql:({c0:E,c1:b,c2:v},{c0:g,c1:w,c2:S})=>h.eql(E,g)&&h.eql(b,w)&&h.eql(v,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:y,mul:m,sqr:B,addN:p,subN:y,mulN:m,sqrN:B,inv:({c0:E,c1:b,c2:v})=>{let g=h.sub(h.sqr(E),h.mulByNonresidue(h.mul(v,b))),w=h.sub(h.mulByNonresidue(h.sqr(v)),h.mul(E,b)),S=h.sub(h.sqr(b),h.mul(E,v)),A=h.inv(h.add(h.mulByNonresidue(h.add(h.mul(v,w),h.mul(b,S))),h.mul(E,g)));return{c0:h.mul(A,g),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:v})=>_e(h.toBytes(E),h.toBytes(b),h.toBytes(v)),cmov:({c0:E,c1:b,c2:v},{c0:g,c1:w,c2:S},A)=>({c0:h.cmov(E,g,A),c1:h.cmov(b,w,A),c2:h.cmov(v,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:v},g)=>({c0:h.frobeniusMap(E,g),c1:h.mul(h.frobeniusMap(b,g),$[g%6]),c2:h.mul(h.frobeniusMap(v,g),_[g%6])}),mulByFp2:({c0:E,c1:b,c2:v},g)=>({c0:h.mul(E,g),c1:h.mul(b,g),c2:h.mul(v,g)}),mulByNonresidue:({c0:E,c1:b,c2:v})=>({c0:h.mulByNonresidue(v),c1:E,c2:b}),mul1:({c0:E,c1:b,c2:v},g)=>({c0:h.mulByNonresidue(h.mul(v,g)),c1:h.mul(E,g),c2:h.mul(b,g)}),mul01({c0:E,c1:b,c2:v},g,w){let S=h.mul(E,g),A=h.mul(b,w);return{c0:h.add(h.mulByNonresidue(h.sub(h.mul(h.add(b,v),w),A)),S),c1:h.sub(h.sub(h.mul(h.add(g,w),h.add(E,b)),S),A),c2:h.add(h.sub(h.mul(h.add(E,v),g),S),A)}}},P=Vc(h,d,n.ORDER,12,1,6)[0],R=({c0:E,c1:b},{c0:v,c1:g})=>({c0:x.add(E,v),c1:x.add(b,g)}),U=({c0:E,c1:b},{c0:v,c1:g})=>({c0:x.sub(E,v),c1:x.sub(b,g)}),F=({c0:E,c1:b},v)=>{if(typeof v=="bigint")return{c0:x.mul(E,v),c1:x.mul(b,v)};let{c0:g,c1:w}=v,S=x.mul(E,g),A=x.mul(b,w);return{c0:x.add(S,x.mulByNonresidue(A)),c1:x.sub(x.mul(x.add(E,b),x.add(g,w)),x.add(S,A))}},D=({c0:E,c1:b})=>{let v=x.mul(E,b);return{c0:x.sub(x.sub(x.mul(x.add(x.mulByNonresidue(b),E),x.add(E,b)),v),x.mulByNonresidue(v)),c1:x.add(v,v)}};function j(E,b){const v=h.sqr(E),g=h.sqr(b);return{first:h.add(h.mulByNonresidue(g),v),second:h.sub(h.sub(h.sqr(h.add(E,b)),v),g)}}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:v,c1:g})=>x.eql(E,v)&&x.eql(b,g),sqrt:ad,inv:({c0:E,c1:b})=>{let v=x.inv(x.sub(x.sqr(E),x.mulByNonresidue(x.sqr(b))));return{c0:x.mul(E,v),c1:x.neg(x.mul(b,v))}},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:R,sub:U,mul:F,sqr:D,addN:R,subN:U,mulN:F,sqrN:D,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:v,c1:g},w)=>({c0:x.cmov(E,v,w),c1:x.cmov(b,g,w)}),fromBigTwelve:E=>({c0:x.fromBigSix(E.slice(0,6)),c1:x.fromBigSix(E.slice(6,12))}),frobeniusMap(E,b){const{c0:v,c1:g,c2:w}=x.frobeniusMap(E.c1,b),S=P[b%12];return{c0:x.frobeniusMap(E.c0,b),c1:x.create({c0:h.mul(v,S),c1:h.mul(g,S),c2:h.mul(w,S)})}},mulByFp2:({c0:E,c1:b},v)=>({c0:x.mulByFp2(E,v),c1:x.mulByFp2(b,v)}),conjugate:({c0:E,c1:b})=>({c0:E,c1:x.neg(b)}),mul014:({c0:E,c1:b},v,g,w)=>{let S=x.mul01(E,v,g),A=x.mul1(b,w);return{c0:x.add(x.mulByNonresidue(A),S),c1:x.sub(x.sub(x.mul01(x.add(b,E),v,h.add(g,w)),S),A)}},mul034:({c0:E,c1:b},v,g,w)=>{const S=x.create({c0:h.mul(E.c0,v),c1:h.mul(E.c1,v),c2:h.mul(E.c2,v)}),A=x.mul01(b,g,w),I=x.mul01(x.add(E,b),h.add(v,g),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:j,Fp12:M}}const ot=BigInt(0),xo=BigInt(1),Ne=BigInt(2),_o=BigInt(3),Xi=BigInt(4),Xn=BigInt("0xd201000000010000"),Z8=Ki(Xn),{Fp:X,Fp2:J,Fp6:Kc,Fp4Square:Gc,Fp12:re}=W8({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}=Gc(n,o),{first:l,second:f}=Gc(s,i),{first:d,second:h}=Gc(r,a),p=J.mulByNonresidue(h);return{c0:Kc.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:Kc.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=Z8-1;r>=0;r--)n=re._cyclotomicSquare(n),_E(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")),Y8=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))))),X8=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)))),J8=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))})}),Q8=Ud(X,{A:X.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:X.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:X.create(BigInt(11))}),{G2psi:Kd,G2psi2:ex}=G8(X,J,J.div(J.ONE,J.NONRESIDUE)),Wc=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=V8({fields:{Fp:X,Fp2:J,Fp6:Kc,Fp12:re,Fr:Vd},G1:{Fp:X,h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1"),a:X.ZERO,b:Xi,htfDefaults:{...Wc,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}=Q8(X.create(t[0]));return X8(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(Ze("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:{...Wc},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:t=>{const{x:e,y:n}=J8(J.fromBigTuple(t));return Y8(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=ex(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((y,m)=>y!==0?m+1:m,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(Ze("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),y=BigInt(n),m=p>ot&&p*Ne/i!==y,B=p===ot&&h*Ne/i!==y;(m||B)&&(d=J.neg(d));const $=Ht.G2.ProjectivePoint.fromAffine({x:l,y:d});return $.assertValidity(),$},toRawBytes(t){return Wd(t)},toHex(t){return Rr(Wd(t))}}},params:{ateLoopSize:Xn,r:Vd.ORDER,xNegative:!0,twistType:"multiplicative"},htfDefaults:Wc,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 Zc(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");Zc(t.outputLen),Zc(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 tx(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 Yc(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")(),nx=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+=nx[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 Xc(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Jc(t){return typeof t=="string"&&(t=Xc(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 rx(t){const e=r=>t().update(Jc(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 Qc=BigInt(0),eu=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===""?Qc:BigInt("0x"+t)}function To(t){return ep(gi(t))}function tp(t){return Fr(t),ep(gi(Uint8Array.from(t).reverse()))}function tu(t,e){return Do(t.toString(16).padStart(e*2,"0"))}function np(t,e){return tu(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 nu=t=>typeof t=="bigint"&&Qc<=t;function ix(t,e,n){return nu(t)&&nu(e)&&nu(n)&&e<=t&&t<n}function sx(t,e,n,r){if(!ix(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function rp(t){let e;for(e=0;t>Qc;t>>=eu,e+=1);return e}const Qi=t=>(eu<<BigInt(t))-eu;function ox(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 y=s.slice();p.push(y),h+=s.length}return Jn(...p)};return(h,p)=>{c(),l(h);let y;for(;!(y=p(f()));)l();return c(),y}}function ru(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),ax=BigInt(7),cp=BigInt(8),cx=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 iu(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 iu(t,r,e),r}function ux(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 iu(t,a,e),a}function lx(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+ax)/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 y=a.eql(a.sqr(l),c),m=a.cmov(u,l,y);return iu(a,m,c),m}}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,y=c.sqr(d);for(;!c.eql(y,c.ONE);)if(p++,y=c.sqr(y),p===l)throw new Error("Cannot find square root");const m=at<<BigInt(l-p-1),B=c.pow(f,m);l=p,f=c.sqr(B),d=c.mul(d,f),h=c.mul(h,B)}return h}}function fx(t){return t%op===sp?fp:t%cp===ap?ux:t%up===cx?lx(t):hp(t)}const hx=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function dx(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=hx.reduce((r,i)=>(r[i]="function",r),e);return ru(t,n),t}function px(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&&Zc(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)=>px(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=fx(t)),l(f,d))),toBytes:d=>n?np(d,u):tu(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 y=new Uint8Array(u);y.set(d,n?0:y.length-d.length),d=y}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 gx(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):tu(a,i)}function yx(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 bx(t,e,n){return t&e^~t&n}function wx(t,e,n){return t&e^t&n^e&n}class mx 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=Yc(this.buffer)}update(e){Bo(this),e=Jc(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=Yc(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),tx(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;yx(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Yc(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]),vx=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 Ex extends mx{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,y=nn(h,17)^nn(h,19)^h>>>10;er[f]=y+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+bx(a,c,u)+vx[f]+er[f]|0,y=(nn(r,2)^nn(r,13)^nn(r,22))+wx(r,i,s)|0;l=u,u=c,c=a,a=o+h|0,o=s,s=i,i=r,r=h+y|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=rx(()=>new Ex);class mp extends Jd{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,Zd(e);const r=Jc(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 su(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 ou(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 xx(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 _x(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 au=new WeakMap,_p=new WeakMap;function cu(t){return _p.get(t)||1}function Sp(t){if(t!==yi)throw new Error("invalid wNAF")}class Sx{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}=ou(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=ou(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=ou(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=au.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),au.set(n,i))),i}cached(e,n,r){const i=cu(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=cu(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),au.delete(e)}hasCache(e){return cu(e)!==1}}function Ix(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 Ax(t,e,n,r){xx(n,t),_x(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 y=0;y<s;y++){const m=r[y],B=Number(m>>BigInt(h)&u);l[B]=l[B].add(n[y])}let p=o;for(let y=l.length-1,m=o;y>0;y--)m=m.add(l[y]),p=p.add(m);if(d=d.add(p),h!==0)for(let y=0;y<c;y++)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 dx(e),e}else return es(t,{isLE:n})}function Bx(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 Ox(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 uu(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function lu(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&&uu(n.format),n}class Dx extends Error{constructor(e=""){super(e)}}const In={Err:Dx,_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),$x=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 Px(t,e={}){const n=Bx("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;ru(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,v){const{x:g,y:w}=b.toAffine(),S=r.toBytes(g);if($o(v,"isCompressed"),v){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:v}=u,g=E.length,w=E[0],S=E.subarray(1);if(g===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=y(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 T=r.isOdd(O);return(w&1)===1!==T&&(O=r.neg(O)),{x:A,y:O}}else if(g===v&&w===4){const A=r.BYTES,I=r.fromBytes(S.subarray(0,A)),O=r.fromBytes(S.subarray(A,A*2));if(!m(I,O))throw new Error("bad point: is not on curve");return{x:I,y:O}}else throw new Error(`bad point: got length ${g}, expected compressed=${b} or uncompressed=${v}`)}const h=e.toBytes||f,p=e.fromBytes||d;function y(E){const b=r.sqr(E),v=r.mul(b,E);return r.add(r.add(v,r.mul(E,s.a)),s.b)}function m(E,b){const v=r.sqr(b),g=y(E);return r.eql(v,g)}if(!m(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const B=r.mul(r.pow(s.a,No),$x),$=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(B,$)))throw new Error("bad curve params: a or b");function _(E,b,v=!1){if(!r.isValid(b)||v&&r.is0(b))throw new Error(`bad point coordinate ${E}`);return b}function x(E){if(!(E instanceof D))throw new Error("ProjectivePoint expected")}function P(E){if(!c||!c.basises)throw new Error("no endo");return Ox(E,c.basises,i.ORDER)}const R=ip((E,b)=>{const{X:v,Y:g,Z:w}=E;if(r.eql(w,r.ONE))return{x:v,y:g};const S=E.is0();b==null&&(b=S?r.ONE:r.inv(w));const A=r.mul(v,b),I=r.mul(g,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:v}=E.toAffine();if(!r.isValid(b)||!r.isValid(v))throw new Error("bad point: x or y not field elements");if(!m(b,v))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,v,g,w){return v=new D(r.mul(v.X,E),v.Y,v.Z),b=Ro(g,b),v=Ro(w,v),b.add(v)}class D{constructor(b,v,g){this.X=_("x",b),this.Y=_("y",v,!0),this.Z=_("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){const{x:v,y:g}=b||{};if(!b||!r.isValid(v)||!r.isValid(g))throw new Error("invalid affine point");if(b instanceof D)throw new Error("projective point not allowed");return r.is0(v)&&r.is0(g)?D.ZERO:new D(v,g,r.ONE)}static fromBytes(b){const v=D.fromAffine(p(Lr(b,void 0,"point")));return v.assertValidity(),v}static fromHex(b){return D.fromBytes(pt("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,v=!0){return M.createCache(this,b),v||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:v,Y:g,Z:w}=this,{X:S,Y:A,Z:I}=b,O=r.eql(r.mul(v,I),r.mul(S,w)),T=r.eql(r.mul(g,I),r.mul(A,w));return O&&T}negate(){return new D(this.X,r.neg(this.Y),this.Z)}double(){const{a:b,b:v}=s,g=r.mul(v,No),{X:w,Y:S,Z:A}=this;let I=r.ZERO,O=r.ZERO,T=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),T=r.mul(w,A),T=r.add(T,T),I=r.mul(b,T),O=r.mul(g,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),T=r.mul(g,T),k=r.mul(b,k),N=r.sub(L,k),N=r.mul(b,N),N=r.add(N,T),T=r.add(L,L),L=r.add(T,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),T=r.mul(k,C),T=r.add(T,T),T=r.add(T,T),new D(I,O,T)}add(b){x(b);const{X:v,Y:g,Z:w}=this,{X:S,Y:A,Z:I}=b;let O=r.ZERO,T=r.ZERO,L=r.ZERO;const C=s.a,k=r.mul(s.b,No);let N=r.mul(v,S),q=r.mul(g,A),z=r.mul(w,I),W=r.add(v,g),V=r.add(S,A);W=r.mul(W,V),V=r.add(N,q),W=r.sub(W,V),V=r.add(v,w);let Z=r.add(S,I);return V=r.mul(V,Z),Z=r.add(N,z),V=r.sub(V,Z),Z=r.add(g,w),O=r.add(A,I),Z=r.mul(Z,O),O=r.add(q,z),Z=r.sub(Z,O),L=r.mul(C,V),O=r.mul(k,z),L=r.add(O,L),O=r.sub(q,L),L=r.add(q,L),T=r.mul(O,L),q=r.add(N,N),q=r.add(q,N),z=r.mul(C,z),V=r.mul(k,V),q=r.add(q,z),z=r.sub(N,z),z=r.mul(C,z),V=r.add(V,z),N=r.mul(q,V),T=r.add(T,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 D(O,T,L)}subtract(b){return this.add(b.negate())}is0(){return this.equals(D.ZERO)}multiply(b){const{endo:v}=e;if(!i.isValidNot0(b))throw new Error("invalid scalar: out of range");let g,w;const S=A=>M.cached(this,A,I=>su(D,I));if(v){const{k1neg:A,k1:I,k2neg:O,k2:T}=P(b),{p:L,f:C}=S(I),{p:k,f:N}=S(T);w=C.add(N),g=F(v.beta,L,k,A,O)}else{const{p:A,f:I}=S(b);g=A,w=I}return su(D,[g,w])[0]}multiplyUnsafe(b){const{endo:v}=e,g=this;if(!i.isValid(b))throw new Error("invalid scalar: out of range");if(b===An||g.is0())return D.ZERO;if(b===bi)return g;if(M.hasCache(this))return this.multiply(b);if(v){const{k1neg:w,k1:S,k2neg:A,k2:I}=P(b),{p1:O,p2:T}=Ix(D,g,S,I);return F(v.beta,O,T,w,A)}else return M.unsafe(g,b)}multiplyAndAddUnsafe(b,v,g){const w=this.multiplyUnsafe(v).add(b.multiplyUnsafe(g));return w.is0()?void 0:w}toAffine(b){return R(this,b)}isTorsionFree(){const{isTorsionFree:b}=e;return o===bi?!0:b?b(D,this):M.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:b}=e;return o===bi?this:b?b(D,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(b=!0){return $o(b,"isCompressed"),this.assertValidity(),h(D,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 su(D,b)}static msm(b,v){return Ax(D,i,b,v)}static fromPrivateKey(b){return D.BASE.multiply(wi(i,b))}}D.BASE=new D(s.Gx,s.Gy,r.ONE),D.ZERO=new D(r.ZERO,r.ONE,r.ZERO),D.Fp=r,D.Fn=i;const j=i.BITS,M=new Sx(D,e.endo?Math.ceil(j/2):j);return D.BASE.precompute(8),D}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 Tx(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:y,publicKeyUncompressed:m}=i;try{const B=h.length;return p===!0&&B!==y||p===!1&&B!==m?!1:!!t.fromBytes(h)}catch{return!1}}function a(h=r(i.seed)){return gx(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:y,publicKeyUncompressed:m}=i;if(n.allowedLengths||p===y)return;const B=pt("key",h).length;return B===y||B===m}function f(h,p,y=!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 m=wi(n,h);return t.fromHex(p).multiply(m).toBytes(y)}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 Rx(t,e,n={}){Zd(e),ru(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Qd,i=n.hmac||((v,...g)=>vp(e,v,Jn(...g))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h}=Tx(t,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},y="compact";function m(v){const g=a>>bi;return v>g}function B(v,g){if(!o.isValidNot0(g))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return g}function $(v,g){uu(g);const w=h.signature,S=g==="compact"?w:g==="recovered"?w+1:void 0;return Lr(v,S,`${g} signature`)}class _{constructor(g,w,S){this.r=B("r",g),this.s=B("s",w),S!=null&&(this.recovery=S),Object.freeze(this)}static fromBytes(g,w=y){$(g,w);let S;if(w==="der"){const{r:T,s:L}=In.toSig(Lr(g));return new _(T,L)}w==="recovered"&&(S=g[0],w="compact",g=g.subarray(1));const A=o.BYTES,I=g.subarray(0,A),O=g.subarray(A,A*2);return new _(o.fromBytes(I),o.fromBytes(O),S)}static fromHex(g,w){return this.fromBytes(Do(g),w)}addRecoveryBit(g){return new _(this.r,this.s,g)}recoverPublicKey(g){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 T=I===2||I===3?S+a:S;if(!s.isValid(T))throw new Error("recovery id 2 or 3 invalid");const L=s.toBytes(T),C=t.fromBytes(Jn(Op((I&1)===0),L)),k=o.inv(T),N=P(pt("msgHash",g)),q=o.create(-N*k),z=o.create(A*k),W=t.BASE.multiplyUnsafe(q).add(C.multiplyUnsafe(z));if(W.is0())throw new Error("point at infinify");return W.assertValidity(),W}hasHighS(){return m(this.s)}toBytes(g=y){if(uu(g),g==="der")return Do(In.hexFromSig(this));const w=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 Jn(Uint8Array.of(this.recovery),w,S)}return Jn(w,S)}toHex(g){return gi(this.toBytes(g))}assertValidity(){}static fromCompact(g){return _.fromBytes(pt("sig",g),"compact")}static fromDER(g){return _.fromBytes(pt("sig",g),"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(g){if(g.length>8192)throw new Error("input is too large");const w=To(g),S=g.length*8-c;return S>0?w>>BigInt(S):w},P=n.bits2int_modN||function(g){return o.create(x(g))},R=Qi(c);function U(v){return sx("num < 2^"+c,v,An,R),o.toBytes(v)}function F(v,g){return Lr(v,void 0,"message"),g?Lr(e(v),void 0,"prehashed message"):v}function D(v,g,w){if(["recovered","canonical"].some(q=>q in w))throw new Error("sign() legacy options not supported");const{lowS:S,prehash:A,extraEntropy:I}=lu(w,p);v=F(v,A);const O=P(v),T=wi(o,g),L=[U(T),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 z=x(q);if(!o.isValidNot0(z))return;const W=o.inv(z),V=t.BASE.multiply(z).toAffine(),Z=o.create(V.x);if(Z===An)return;const Q=o.create(W*o.create(k+Z*T));if(Q===An)return;let ee=(V.x===Z?0:2)|Number(V.y&bi),ie=Q;return S&&m(Q)&&(ie=o.neg(Q),ee^=1),new _(Z,ie,ee)}return{seed:C,k2sig:N}}function j(v,g,w={}){v=pt("message",v);const{seed:S,k2sig:A}=D(v,g,w);return ox(e.outputLen,o.BYTES,i)(S,A)}function M(v){let g;const w=typeof v=="string"||Ao(v),S=!w&&v!==null&&typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!w&&!S)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(S)g=new _(v.r,v.s);else if(w){try{g=_.fromBytes(pt("sig",v),"der")}catch(A){if(!(A instanceof In.Err))throw A}if(!g)try{g=_.fromBytes(pt("sig",v),"compact")}catch{return!1}}return g||!1}function E(v,g,w,S={}){const{lowS:A,prehash:I,format:O}=lu(S,p);if(w=pt("publicKey",w),g=F(pt("message",g),I),"strict"in S)throw new Error("options.strict was renamed to lowS");const T=O===void 0?M(v):_.fromBytes(pt("sig",v),O);if(T===!1)return!1;try{const L=t.fromBytes(w);if(A&&T.hasHighS())return!1;const{r:C,s:k}=T,N=P(g),q=o.inv(k),z=o.create(N*q),W=o.create(C*q),V=t.BASE.multiplyUnsafe(z).add(L.multiplyUnsafe(W));return V.is0()?!1:o.create(V.x)===C}catch{return!1}}function b(v,g,w={}){const{prehash:S}=lu(w,p);return g=F(g,S),_.fromBytes(v,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h,Point:t,sign:j,verify:E,recoverPublicKey:b,Signature:_,hash:e})}function Nx(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 Cx(t){const{CURVE:e,curveOpts:n}=Nx(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 Ux(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,gp(n.Fn.ORDER,n.Fn.BITS))})}function Fx(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=Cx(t),s=Px(e,n),o=Rx(s,r,i);return Ux(t,o)}function Lx(t,e){const n=r=>Fx({...t,hash:r});return{...n(e),create:n}}Xc("HashToScalar-");const fu={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},kx={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},$p=BigInt(2);function qx(t){const e=fu.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,y=Tt(p,s,e)*p%e,m=Tt(y,a,e)*y%e,B=Tt(m,c,e)*m%e,$=Tt(B,a,e)*y%e,_=Tt($,n,e)*l%e,x=Tt(_,o,e)*p%e,P=Tt(x,r,e)*u%e,R=Tt(P,$p,e);if(!hu.eql(hu.sqr(R),t))throw new Error("Cannot find square root");return R}const hu=es(fu.p,{sqrt:qx});Lx({...fu,Fp:hu,lowS:!0,endo:kx},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 du(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 pu(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 gu(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 pu(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 yu(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 Mx(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=>(gu("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 yu(Array.from(n),8,t,!e)},decode:n=>(gu("radix2.decode",n),Uint8Array.from(yu(n,t,8,e)))}}function Cp(t){return pu(t),function(...e){try{return t.apply(null,e)}catch{}}}function jx(t,e){return vi(t),pu(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 zx=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 bu=t=>yt(Mx(58),St(t),It("")),Hx=bu("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz");bu("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"),bu("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz");const Vx=t=>yt(jx(4,e=>t(t(e))),Hx),wu=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,wu.encode(yu([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)),gu("bech32.encode",d);const p=f.length;if(p===0)throw new TypeError(`Invalid prefix length ${p}`);const y=p+7+d.length;if(h!==!1&&y>h)throw new TypeError(`Length ${y} exceeds limit ${h}`);const m=f.toLowerCase(),B=kp(m,d,e);return`${m}1${wu.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 y=p.lastIndexOf("1");if(y===0||y===-1)throw new Error('Letter "1" must be present between prefix and data only');const m=p.slice(0,y),B=p.slice(y+1);if(B.length<6)throw new Error("Data must be at least 6 characters long");const $=wu.decode(B).slice(0,-6),_=kp(m,$,e);if(!B.endsWith(_))throw new Error(`Invalid checksum in ${f}: expected "${_}"`);return{prefix:m,words:$}}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 Kx=(()=>typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function")(),Gx={encode(t){return du(t),t.toHex()},decode(t){return tr("hex",t),Uint8Array.fromHex(t)}};Kx||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()})),Vx(wp),Xc("Bitcoin seed");function Wx(t){return o8(Zx(t))}function Zx(t){const{payload:e,signature:n}=t,{r,s:i,yParity:s}=n,a=new F8.Signature(BigInt(r),BigInt(i)).addRecoveryBit(s).recoverPublicKey(Oc(e).substring(2));return XE(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 mu(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Yx(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Xx(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=Xx(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,vu=new Uint8Array(16),rn=ns(vu),Jx=225,Qx=(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^Jx<<24&-(i&1)}},Nt=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255|0;function e6(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 t6=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=Yx(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}=Qx(i,s,o,a);const u=t6(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 y=0;y<d;y++){let m=0,B=0,$=0,_=0;for(let x=0;x<u;x++){if(!(y>>>u-x-1&1))continue;const{s0:R,s1:U,s2:F,s3:D}=c[u*p+x];m^=R,B^=U,$^=F,_^=D}h.push({s0:m,s1:B,s2:$,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 y=0;y<4;y++){const m=p>>>8*y&255;for(let B=8/s-1;B>=0;B--){const $=m>>>s*B&d,{s0:_,s1:x,s2:P,s3:R}=o[h*a+$];c^=_,u^=x,l^=P,f^=R,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&&(vu.set(e.subarray(r*Bn)),this._updateBlock(rn[0],rn[1],rn[2],rn[3]),mu(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 n6 extends Hp{constructor(e,n){e=rs(e),qo(e);const r=e6(zp(e));super(r,n),mu(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&&(vu.set(e.subarray(i*Bn)),this._updateBlock(Nt(rn[3]),Nt(rn[2]),Nt(rn[1]),Nt(rn[0])),mu(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 n6(t,e));const Kp=Wn(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),r6=Kp.create(BigInt("-3")),i6=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");vo({a:r6,b:i6,Fp:Kp,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},lo);const Gp=Wn(BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff")),s6=Gp.create(BigInt("-3")),o6=BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef");vo({a:s6,b:o6,Fp:Gp,n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"),h:BigInt(1),lowS:!1},EE);const Wp=Wn(BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),a6=Wp.create(BigInt("-3")),c6=BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00");vo({a:a6,b:c6,Fp:Wp,n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650"),h:BigInt(1),lowS:!1,allowedPrivateKeyLengths:[130,131,132]},vE);var u6={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 y=n?n+u:u;if(!this._events[y])return!1;var m=this._events[y],B=arguments.length,$,_;if(m.fn){switch(m.once&&this.removeListener(u,m.fn,void 0,!0),B){case 1:return m.fn.call(m.context),!0;case 2:return m.fn.call(m.context,l),!0;case 3:return m.fn.call(m.context,l,f),!0;case 4:return m.fn.call(m.context,l,f,d),!0;case 5:return m.fn.call(m.context,l,f,d,h),!0;case 6:return m.fn.call(m.context,l,f,d,h,p),!0}for(_=1,$=new Array(B-1);_<B;_++)$[_-1]=arguments[_];m.fn.apply(m.context,$)}else{var x=m.length,P;for(_=0;_<x;_++)switch(m[_].once&&this.removeListener(u,m[_].fn,void 0,!0),B){case 1:m[_].fn.call(m[_].context);break;case 2:m[_].fn.call(m[_].context,l);break;case 3:m[_].fn.call(m[_].context,l,f);break;case 4:m[_].fn.call(m[_].context,l,f,d);break;default:if(!$)for(P=1,$=new Array(B-1);P<B;P++)$[P-1]=arguments[P];m[_].fn.apply(m[_].context,$)}}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 y=0,m=[],B=p.length;y<B;y++)(p[y].fn!==l||d&&!p[y].once||f&&p[y].context!==f)&&m.push(p[y]);m.length?this._events[h]=m.length===1?m[0]:m: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})(u6);function l6(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,y=new Uint8Array(p);for(;d!==h;){let $=u[d],_=0;for(let x=p-1;($!==0||_<f)&&x!==-1;x--,_++)$+=256*y[x]>>>0,y[x]=$%n>>>0,$=$/n>>>0;if($!==0)throw new Error("Non-zero carry");f=_,d++}let m=p-f;for(;m!==p&&y[m]===0;)m++;let B=r.repeat(l);for(;m<p;++m)B+=t.charAt(y[m]);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 $=u.charCodeAt(l);if($>255)return;let _=e[$];if(_===255)return;let x=0;for(let P=h-1;(_!==0||x<d)&&P!==-1;P--,x++)_+=n*p[P]>>>0,p[P]=_%256>>>0,_=_/256>>>0;if(_!==0)throw new Error("Non-zero carry");d=x,l++}let y=h-d;for(;y!==h&&p[y]===0;)y++;const m=new Uint8Array(f+(h-y));let B=f;for(;y!==h;)m[B++]=p[y++];return m}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 f6="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",is=l6(f6);function h6(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 d6(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 p6=new TextEncoder,g6=50;function y6(t,e,n){p6.encodeInto(t,e.subarray(n))}function b6(t,e,n){t.length>g6?y6(t,e,n):d6(t,e,n)}const w6=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>=w6&&(o+=String.fromCharCode(...s),s.length=0)}return s.length>0&&(o+=String.fromCharCode(...s)),o}const m6=new TextDecoder,v6=200;function E6(t,e,n){const r=t.subarray(e,e+n);return m6.decode(r)}function x6(t,e,n){return n>v6?E6(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 _6(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 S6(t,e){const n=t.getUint32(e),r=t.getUint32(e+4);return n*4294967296+r}const I6=-1,A6=4294967296-1,B6=17179869184-1;function O6({sec:t,nsec:e}){if(t>=0&&e>=0&&t<=B6)if(e===0&&t<=A6){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 D6(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 $6(t){if(t instanceof Date){const e=D6(t);return O6(e)}else return null}function P6(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 T6(t){const e=P6(t);return new Date(e.sec*1e3+e.nsec/1e6)}const R6={type:I6,encode:$6,decode:T6};class zo{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(R6)}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 N6(t){return t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer}function Eu(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):N6(t)?new Uint8Array(t):Uint8Array.from(t)}const C6=100,U6=2048;class xu{constructor(e){this.entered=!1,this.extensionCodec=e?.extensionCodec??zo.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??C6,this.initialBufferSize=e?.initialBufferSize??U6,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 xu({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=h6(e);this.ensureBufferSizeToWrite(5+r),this.writeStringHeader(r),b6(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=Eu(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),_6(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 F6(t,e){return new xu(e).encodeSharedRef(t)}function _u(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}const L6=16,k6=16;class q6{constructor(e=L6,n=k6){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 Su="array",os="map_key",Jp="map_value",M6=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 j6{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=Su,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===Su){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,Iu=new DataView(new ArrayBuffer(0)),z6=new Uint8Array(Iu.buffer);try{Iu.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"),H6=new q6;class Au{constructor(e){this.totalPos=0,this.pos=0,this.view=Iu,this.bytes=z6,this.headByte=as,this.stack=new j6,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:H6,this.mapKeyConverter=e?.mapKeyConverter??M6}clone(){return new Au({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=Eu(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=Eu(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 ${_u(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: ${_u(e)}`);this.complete();const r=this.stack;for(;r.length>0;){const i=r.top();if(i.type===Su)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: ${_u(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=x6(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=S6(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 V6(t,e){return new Au(e).decode(t)}function Bu(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?Bu(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 Bu(n)}function K6(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 y=0,m=0,B=0,$=p.length;B!==$&&p[B]===0;)B++,y++;for(var _=($-B)*l+1>>>0,x=new Uint8Array(_);B!==$;){for(var P=p[B],R=0,U=_-1;(P!==0||R<m)&&U!==-1;U--,R++)P+=256*x[U]>>>0,x[U]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");m=R,B++}for(var F=_-m;F!==_&&x[F]===0;)F++;for(var D=c.repeat(y);F<_;++F)D+=t.charAt(x[F]);return D}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var y=0;if(p[y]!==" "){for(var m=0,B=0;p[y]===c;)m++,y++;for(var $=(p.length-y)*u+1>>>0,_=new Uint8Array($);p[y];){var x=n[p.charCodeAt(y)];if(x===255)return;for(var P=0,R=$-1;(x!==0||P<B)&&R!==-1;R--,P++)x+=a*_[R]>>>0,_[R]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");B=P,y++}if(p[y]!==" "){for(var U=$-B;U!==$&&_[U]===0;)U++;for(var F=new Uint8Array(m+($-U)),D=m;U!==$;)F[D++]=_[U++];return F}}}function h(p){var y=d(p);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:h}}var G6=K6,W6=G6;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")},Z6=t=>new TextEncoder().encode(t),Y6=t=>new TextDecoder().decode(t);class X6{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 J6{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 Q6{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 Q6({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class e4{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new X6(e,n,r),this.decoder=new J6(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 e4(t,e,n,r),us=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=W6(n,e);return Ho({prefix:t,name:e,encode:r,decode:s=>t0(i(s))})},t4=(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},n4=(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 n4(i,r,n)},decode(i){return t4(i,r,n,t)}}),r4=Ho({prefix:"\0",name:"identity",encode:t=>Y6(t),decode:t=>Z6(t)});var i4=Object.freeze({__proto__:null,identity:r4});const s4=Le({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var o4=Object.freeze({__proto__:null,base2:s4});const a4=Le({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var c4=Object.freeze({__proto__:null,base8:a4});const u4=us({prefix:"9",name:"base10",alphabet:"0123456789"});var l4=Object.freeze({__proto__:null,base10:u4});const f4=Le({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),h4=Le({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var d4=Object.freeze({__proto__:null,base16:f4,base16upper:h4});const p4=Le({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),g4=Le({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),y4=Le({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),b4=Le({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),w4=Le({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),m4=Le({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),v4=Le({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),E4=Le({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),x4=Le({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _4=Object.freeze({__proto__:null,base32:p4,base32upper:g4,base32pad:y4,base32padupper:b4,base32hex:w4,base32hexupper:m4,base32hexpad:v4,base32hexpadupper:E4,base32z:x4});const S4=us({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),I4=us({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var A4=Object.freeze({__proto__:null,base36:S4,base36upper:I4});const B4=us({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),O4=us({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var D4=Object.freeze({__proto__:null,base58btc:B4,base58flickr:O4});const $4=Le({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),P4=Le({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),T4=Le({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),R4=Le({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var N4=Object.freeze({__proto__:null,base64:$4,base64pad:P4,base64url:T4,base64urlpad:R4});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}"),C4=r0.reduce((t,e,n)=>(t[n]=e,t),[]),U4=r0.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function F4(t){return t.reduce((e,n)=>(e+=C4[n],e),"")}function L4(t){const e=[];for(const n of t){const r=U4[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const k4=Ho({prefix:"\u{1F680}",name:"base256emoji",encode:F4,decode:L4});var q4=Object.freeze({__proto__:null,base256emoji:k4}),M4=s0,i0=128,j4=127,z4=~j4,H4=Math.pow(2,31);function s0(t,e,n){e=e||[],n=n||0;for(var r=n;t>=H4;)e[n++]=t&255|i0,t/=128;for(;t&z4;)e[n++]=t&255|i0,t>>>=7;return e[n]=t|0,s0.bytes=n-r+1,e}var V4=Ou,K4=128,o0=127;function Ou(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw Ou.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>=K4);return Ou.bytes=s-r,n}var G4=Math.pow(2,7),W4=Math.pow(2,14),Z4=Math.pow(2,21),Y4=Math.pow(2,28),X4=Math.pow(2,35),J4=Math.pow(2,42),Q4=Math.pow(2,49),e_=Math.pow(2,56),t_=Math.pow(2,63),n_=function(t){return t<G4?1:t<W4?2:t<Z4?3:t<Y4?4:t<X4?5:t<J4?6:t<Q4?7:t<e_?8:t<t_?9:10},r_={encode:M4,decode:V4,encodingLength:n_},a0=r_;const c0=(t,e,n=0)=>(a0.encode(t,e,n),e),u0=t=>a0.encodingLength(t),Du=(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 i_(t,n,e,s)};class i_{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 s_(t,e,n);class s_{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?Du(this.code,n):n.then(r=>Du(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)),o_=l0({name:"sha2-256",code:18,encode:f0("SHA-256")}),a_=l0({name:"sha2-512",code:19,encode:f0("SHA-512")});var c_=Object.freeze({__proto__:null,sha256:o_,sha512:a_});const h0=0,u_="identity",d0=t0;var l_=Object.freeze({__proto__:null,identity:{code:h0,name:u_,encode:d0,digest:t=>Du(h0,d0(t))}});new TextEncoder,new TextDecoder;const p0={...i4,...o4,...c4,...l4,...d4,..._4,...A4,...D4,...N4,...q4};({...c_,...l_});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))),$u=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:$u,ascii:$u,binary:$u,...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?Bu(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 f_={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"}},h_="Input must be an string, Buffer or Uint8Array";function d_(t){let e;if(t instanceof Uint8Array)e=t;else if(typeof t=="string")e=new TextEncoder().encode(t);else throw new Error(h_);return e}function p_(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 g_(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 y_(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:d_,toHex:p_,debugPrint:g_,testSpeed:y_};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]),b_=[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],Ye=new Uint8Array(b_.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,Ye[n*16+0],Ye[n*16+1]),nr(2,10,18,26,Ye[n*16+2],Ye[n*16+3]),nr(4,12,20,28,Ye[n*16+4],Ye[n*16+5]),nr(6,14,22,30,Ye[n*16+6],Ye[n*16+7]),nr(0,10,20,30,Ye[n*16+8],Ye[n*16+9]),nr(2,12,22,24,Ye[n*16+10],Ye[n*16+11]),nr(4,14,16,26,Ye[n*16+12],Ye[n*16+13]),nr(6,8,18,28,Ye[n*16+14],Ye[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&&(Pu(i,e),i.c=128),i}function Pu(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 Pu(s,t),S0(s)}function w_(t,e,n,r,i){const s=I0(t,e,n,r,i);return Ko.toHex(s)}var m_={blake2b:I0,blake2bHex:w_,blake2bInit:_0,blake2bUpdate:Pu,blake2bFinal:S0};const A0=w0;function v_(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]),Xe=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]=v_(t.b,4*n);for(n=0;n<10;n++)ir(0,4,8,12,ke[Xe[n*16+0]],ke[Xe[n*16+1]]),ir(1,5,9,13,ke[Xe[n*16+2]],ke[Xe[n*16+3]]),ir(2,6,10,14,ke[Xe[n*16+4]],ke[Xe[n*16+5]]),ir(3,7,11,15,ke[Xe[n*16+6]],ke[Xe[n*16+7]]),ir(0,5,10,15,ke[Xe[n*16+8]],ke[Xe[n*16+9]]),ir(1,6,11,12,ke[Xe[n*16+10]],ke[Xe[n*16+11]]),ir(2,7,8,13,ke[Xe[n*16+12]],ke[Xe[n*16+13]]),ir(3,4,9,14,ke[Xe[n*16+14]],ke[Xe[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&&(Tu(r,e),r.c=64),r}function Tu(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 Tu(r,t),$0(r)}function E_(t,e,n){const r=P0(t,e,n);return A0.toHex(r)}var x_={blake2s:P0,blake2sHex:E_,blake2sInit:D0,blake2sUpdate:Tu,blake2sFinal:$0};const fs=m_,hs=x_;var __={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 S_=":";function Zo(t){const[e,n]=t.split(S_);return{namespace:e,reference:n}}function T0(t,e){return t.includes(":")?[t]:e.chains||[]}var I_=Object.defineProperty,A_=Object.defineProperties,B_=Object.getOwnPropertyDescriptors,R0=Object.getOwnPropertySymbols,O_=Object.prototype.hasOwnProperty,D_=Object.prototype.propertyIsEnumerable,Ru=(t,e,n)=>e in t?I_(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,N0=(t,e)=>{for(var n in e||(e={}))O_.call(e,n)&&Ru(t,n,e[n]);if(R0)for(var n of R0(e))D_.call(e,n)&&Ru(t,n,e[n]);return t},$_=(t,e)=>A_(t,B_(e)),C0=(t,e,n)=>Ru(t,typeof e!="symbol"?e+"":e,n);const P_="ReactNative",Bt={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},T_="js";function Yo(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function sr(){return!Pr()&&!!pc()&&navigator.product===P_}function R_(){return sr()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function N_(){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()&&!!pc()&&!!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 C_(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 U_(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!=="")),$_(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 F_(){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=m3();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 L_(){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=F_(),i=L_();return[[t,e].join("-"),[T_,n].join("-"),r,i].join("/")}function k_({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=C_(u[1]||"",f);return u[0]+"?"+d}function Mr(t,e){return t.filter(n=>e.includes(n)).length===t.length}function Nu(t){return Object.fromEntries(t.entries())}function Cu(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 q_(t){return k0("topic",t)}function M_(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 he(t,e){return`${t}${e?`:${e}`:""}`}function zr(t=[],e=[]){return[...new Set([...t,...e])]}async function j_({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=z_(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}H_(o)}else a===Bt.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(o)}catch(i){console.error(i)}}function z_(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}${W_(r,!0)}`}else i=`${i}/wc?${r}`;return i}function H_(t){let e="_self";G_()?e="_top":(K_()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function V_(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 Uu(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function K_(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function G_(){try{return window.self!==window.top}catch{return!1}}function W_(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 Z_(t){return new Promise(e=>setTimeout(e,t))}class Y_{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,X_=(t,e)=>e,J_=(t,e)=>t,Q_=(t,e,n)=>t<<n|e>>>32-n,e5=(t,e,n)=>e<<n|t>>>32-n,t5=(t,e,n)=>e<<n-32|t>>>64-n,n5=(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 Fu=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Lu=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,r5=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),i5=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,s5=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),o5=(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 ku(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 qu(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 a5(t){for(let e=0;e<t.length;e++)t[e]=Y0(t[e]);return t}const lr=Z0?t=>t:a5,X0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",c5=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+=c5[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 u5(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 l5=BigInt(0),ws=BigInt(1),f5=BigInt(2),h5=BigInt(7),d5=BigInt(256),p5=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=l5;for(let s=0;s<7;s++)e=(e<<ws^(e>>h5)*p5)%d5,e&f5&&(i^=ws<<(ws<<BigInt(s))-ws);ng.push(i)}const rg=K0(ng,!0),g5=rg[0],y5=rg[1],ig=(t,e,n)=>n>32?t5(t,e,n):Q_(t,e,n),sg=(t,e,n)=>n>32?n5(t,e,n):e5(t,e,n);function b5(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]^=g5[r],t[1]^=y5[r]}Ut(n)}class Mu 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),b5(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(ku(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 Mu(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 w5=(t,e,n)=>bs(()=>new Mu(e,t,n)),m5=w5(1,136,256/8);function v5(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 E5(t,e,n){return t&e^~t&n}function x5(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=qu(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=qu(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),ku(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;v5(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=qu(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]),Je=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),Qe=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),_5=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 S5 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,y=on(h,17)^on(h,19)^h>>>10;dr[f]=y+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+E5(a,c,u)+_5[f]+dr[f]|0,p=(on(r,2)^on(r,13)^on(r,22))+x5(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))),I5=ag[0],A5=ag[1],pr=new Uint32Array(80),gr=new Uint32Array(80);class ju extends og{constructor(e=64){super(128,e,16,!1),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}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:y,Hl:m}=this;return[e,n,r,i,s,o,a,c,u,l,f,d,h,p,y,m]}set(e,n,r,i,s,o,a,c,u,l,f,d,h,p,y,m){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=y|0,this.Hl=m|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,P=gr[_-15]|0,R=ar(x,P,1)^ar(x,P,8)^G0(x,P,7),U=cr(x,P,1)^cr(x,P,8)^W0(x,P,7),F=pr[_-2]|0,D=gr[_-2]|0,j=ar(F,D,19)^ps(F,D,61)^G0(F,D,6),M=cr(F,D,19)^gs(F,D,61)^W0(F,D,6),E=r5(U,M,gr[_-7],gr[_-16]),b=i5(E,R,j,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:y,Gl:m,Hh:B,Hl:$}=this;for(let _=0;_<80;_++){const x=ar(f,d,14)^ar(f,d,18)^ps(f,d,41),P=cr(f,d,14)^cr(f,d,18)^gs(f,d,41),R=f&h^~f&y,U=d&p^~d&m,F=s5($,P,U,A5[_],gr[_]),D=o5(F,B,x,R,I5[_],pr[_]),j=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,v=i&o^i&c^o&c;B=y|0,$=m|0,y=h|0,m=p|0,h=f|0,p=d|0,{h:f,l:d}=Kt(u|0,l|0,D|0,j|0),u=a|0,l=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=Fu(j,E,v);r=Lu(g,D,M,b),i=g|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:y,l:m}=Kt(this.Gh|0,this.Gl|0,y|0,m|0),{h:B,l:$}=Kt(this.Hh|0,this.Hl|0,B|0,$|0),this.set(r,i,s,o,a,c,u,l,f,d,h,p,y,m,B,$)}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 B5 extends ju{constructor(){super(48),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}}const et=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class O5 extends ju{constructor(){super(32),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}}const na=bs(()=>new S5),D5=bs(()=>new ju),$5=bs(()=>new B5),P5=bs(()=>new O5),T5=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],y=Y[2*r+1],m=Fu(c,l,o);u=Lu(m,u,f,a),c=m|0,{Dh:y,Dl:p}={Dh:y^u,Dl:p^c},{Dh:y,Dl:p}={Dh:X_(y,p),Dl:J_(y)},{h,l:d}=Kt(h,d,y,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]=y}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],y=Y[2*r+1],m=Fu(c,l,o);u=Lu(m,u,f,a),c=m|0,{Dh:y,Dl:p}={Dh:y^u,Dl:p^c},{Dh:y,Dl:p}={Dh:ar(y,p,16),Dl:cr(y,p,16)},{h,l:d}=Kt(h,d,y,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]=y}function R5(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 N5 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),ku(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 C5 extends N5{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,R5(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:y,v7h:m}=this;return[e,n,r,i,s,o,a,c,u,l,f,d,h,p,y,m]}set(e,n,r,i,s,o,a,c,u,l,f,d,h,p,y,m){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=y|0,this.v7h=m|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=T5;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 U5=u5(t=>new C5(t)),F5="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(m5(n)).toString("hex")}async function L5(t,e,n,r,i,s){switch(n.t){case"eip191":return await k5(t,e,n.s);case"eip1271":return await q5(t,e,n.s,r,i,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}function k5(t,e,n){const r=L8(n);return Wx({payload:cg(e),signature:r}).toLowerCase()===t.toLowerCase()}async function q5(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||F5}/?chainId=${r}&projectId=${i}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify({id:M5(),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 M5(){return Date.now()+Math.floor(Math.random()*1e3)}function j5(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 z5(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=U5(r,{dkLen:32});return is.encode(i)}function ug(t){const e=new Uint8Array(na(H5(t)));return is.encode(e)}function H5(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=V6(e).txn;if(!n)throw new Error("Invalid signed transaction: missing 'txn' field");const r=F6(n),i=Buffer.from("TX"),s=Buffer.concat([i,Buffer.from(r)]),o=P5(s);return zx.encode(o).replace(/=+$/,"")}function zu(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 V5(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(zu(e.length)),i.push(e),i.push(Buffer.from([18])),i.push(zu(n.length)),i.push(n),i.push(Buffer.from([26])),i.push(zu(r.length)),i.push(r);const s=Buffer.concat(i),o=na(s);return Buffer.from(o).toString("hex").toUpperCase()}function K5(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 G5=Object.defineProperty,W5=Object.defineProperties,Z5=Object.getOwnPropertyDescriptors,fg=Object.getOwnPropertySymbols,Y5=Object.prototype.hasOwnProperty,X5=Object.prototype.propertyIsEnumerable,hg=(t,e,n)=>e in t?G5(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,J5=(t,e)=>{for(var n in e||(e={}))Y5.call(e,n)&&hg(t,n,e[n]);if(fg)for(var n of fg(e))X5.call(e,n)&&hg(t,n,e[n]);return t},Q5=(t,e)=>W5(t,Z5(e));const dg="did:pkh:",eS={eip155:"Ethereum",solana:"Solana",bip122:"Bitcoin"},tS=t=>t?eS[t]||t:"",ra=t=>t?.split(":"),nS=t=>{const e=t&&ra(t);if(e)return t.includes(dg)?e[3]:e[1]},rS=t=>{const e=t&&ra(t);if(e)return t.includes(dg)?e[2]:e[0]},Hu=t=>{const e=t&&ra(t);if(e)return e[2]+":"+e[3]},ia=t=>{const e=t&&ra(t);if(e)return e.pop()};async function pg(t){const{cacao:e,projectId:n}=t,{s:r,p:i}=e,s=gg(i,i.iss),o=ia(i.iss);return await L5(o,s,r,Hu(i.iss),n)}const gg=(t,e)=>{const n=rS(e);if(!n)throw new Error("Invalid issuer: "+e);const r=`${t.domain} wants you to sign in with your ${tS(n)} account:`,i=ia(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: ${nS(e)}`,u=`Nonce: ${t.nonce}`,l=`Issued At: ${t.iat}`,f=t.exp?`Expiration Time: ${t.exp}`:void 0,d=t.nbf?`Not Before: ${t.nbf}`:void 0,h=t.requestId?`Request ID: ${t.requestId}`:void 0,p=t.resources?`Resources:${t.resources.map(m=>`
20
- - ${m}`).join("")}`:void 0,y=sa(t.resources);if(y){const m=ms(y);s=hS(s,m)}return[r,i,"",s,"",o,a,c,u,l,f,d,h,p].filter(m=>m!=null).join(`
21
- `)};function iS(t){return Buffer.from(JSON.stringify(t)).toString("base64")}function sS(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 oS(t,e,n,r={}){return n?.sort((i,s)=>i.localeCompare(s)),{att:{[t]:aS(e,n,r)}}}function aS(t,e,n={}){e=e?.sort((i,s)=>i.localeCompare(s));const r=e.map(i=>({[`${t}/${i}`]:[n]}));return Object.assign({},...r)}function yg(t){return Vr(t),`urn:recap:${iS(t).replace(/=/g,"")}`}function ms(t){const e=sS(t.replace("urn:recap:",""));return Vr(e),e}function cS(t,e,n){const r=oS(t,e,n);return yg(r)}function uS(t){return t&&t.includes("urn:recap:")}function lS(t,e){const n=ms(t),r=ms(e),i=fS(n,r);return yg(i)}function fS(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]=Q5(J5({},r.att[i]),{[a]:((c=t.att[i])==null?void 0:c[a])||((u=e.att[i])==null?void 0:u[a])})})}),r}function hS(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 bg(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 wg(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 sa(t){if(!t)return;const e=t?.[t.length-1];return uS(e)?e:void 0}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function mg(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(!mg(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 vg(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 dS(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 pS(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const gS=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function yS(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=yS(t);else if(mg(t))t=Wu(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function bS(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function wS(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 mS=(t,e)=>{function n(r,...i){if(wt(r),!gS)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 Eg(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&&!ES(e))throw new Error("invalid output, must be aligned");return e}function xg(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 vS(t,e,n){Vu(n);const r=new Uint8Array(16),i=pS(r);return xg(i,0,BigInt(e),n),xg(i,8,BigInt(t),n),r}function ES(t){return t.byteOffset%4===0}function Wu(t){return Uint8Array.from(t)}const _g=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),xS=_g("expand 16-byte k"),_S=_g("expand 32-byte k"),SS=wr(xS),IS=wr(_S);function ce(t,e){return t<<e|t>>>32-e}function Zu(t){return t.byteOffset%4===0}const oa=64,AS=16,Sg=2**32-1,Ig=new Uint32Array;function BS(t,e,n,r,i,s,o,a){const c=i.length,u=new Uint8Array(oa),l=wr(u),f=Zu(i)&&Zu(s),d=f?wr(i):Ig,h=f?wr(s):Ig;for(let p=0;p<c;o++){if(t(e,n,r,l,o,a),o>=Sg)throw new Error("arx: counter overflow");const y=Math.min(oa,c-p);if(f&&y===oa){const m=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let B=0,$;B<AS;B++)$=m+B,h[$]=d[$]^l[B];p+=oa;continue}for(let m=0,B;m<y;m++)B=p+m,s[B]=i[B]^u[m];p+=y}}function OS(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=bS({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>=Sg)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,y,m;if(p===32)h.push(y=Wu(a)),m=IS;else if(p===16&&n)y=new Uint8Array(32),y.set(a),y.set(a,16),m=SS,h.push(y);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Zu(c)||h.push(c=Wu(c));const B=wr(y);if(r){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(m,B,wr(c.subarray(0,16)),B),c=c.subarray(16)}const $=16-i;if($!==c.length)throw new Error(`arx: nonce must be ${$} or 16 bytes`);if($!==12){const x=new Uint8Array(12);x.set(c,s?0:12-c.length),c=x,h.push(c)}const _=wr(c);return BS(t,m,B,_,u,l,f,o),Si(...h),l}}const qe=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class DS{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],y=o[8],m=o[9],B=qe(e,n+0),$=qe(e,n+2),_=qe(e,n+4),x=qe(e,n+6),P=qe(e,n+8),R=qe(e,n+10),U=qe(e,n+12),F=qe(e,n+14);let D=s[0]+(B&8191),j=s[1]+((B>>>13|$<<3)&8191),M=s[2]+(($>>>10|_<<6)&8191),E=s[3]+((_>>>7|x<<9)&8191),b=s[4]+((x>>>4|P<<12)&8191),v=s[5]+(P>>>1&8191),g=s[6]+((P>>>14|R<<2)&8191),w=s[7]+((R>>>11|U<<5)&8191),S=s[8]+((U>>>8|F<<8)&8191),A=s[9]+(F>>>5|i),I=0,O=I+D*a+j*(5*m)+M*(5*y)+E*(5*p)+b*(5*h);I=O>>>13,O&=8191,O+=v*(5*d)+g*(5*f)+w*(5*l)+S*(5*u)+A*(5*c),I+=O>>>13,O&=8191;let T=I+D*c+j*a+M*(5*m)+E*(5*y)+b*(5*p);I=T>>>13,T&=8191,T+=v*(5*h)+g*(5*d)+w*(5*f)+S*(5*l)+A*(5*u),I+=T>>>13,T&=8191;let L=I+D*u+j*c+M*a+E*(5*m)+b*(5*y);I=L>>>13,L&=8191,L+=v*(5*p)+g*(5*h)+w*(5*d)+S*(5*f)+A*(5*l),I+=L>>>13,L&=8191;let C=I+D*l+j*u+M*c+E*a+b*(5*m);I=C>>>13,C&=8191,C+=v*(5*y)+g*(5*p)+w*(5*h)+S*(5*d)+A*(5*f),I+=C>>>13,C&=8191;let k=I+D*f+j*l+M*u+E*c+b*a;I=k>>>13,k&=8191,k+=v*(5*m)+g*(5*y)+w*(5*p)+S*(5*h)+A*(5*d),I+=k>>>13,k&=8191;let N=I+D*d+j*f+M*l+E*u+b*c;I=N>>>13,N&=8191,N+=v*a+g*(5*m)+w*(5*y)+S*(5*p)+A*(5*h),I+=N>>>13,N&=8191;let q=I+D*h+j*d+M*f+E*l+b*u;I=q>>>13,q&=8191,q+=v*c+g*a+w*(5*m)+S*(5*y)+A*(5*p),I+=q>>>13,q&=8191;let z=I+D*p+j*h+M*d+E*f+b*l;I=z>>>13,z&=8191,z+=v*u+g*c+w*a+S*(5*m)+A*(5*y),I+=z>>>13,z&=8191;let W=I+D*y+j*p+M*h+E*d+b*f;I=W>>>13,W&=8191,W+=v*l+g*u+w*c+S*a+A*(5*m),I+=W>>>13,W&=8191;let V=I+D*m+j*y+M*p+E*h+b*d;I=V>>>13,V&=8191,V+=v*f+g*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,T+=I,s[0]=O,s[1]=T,s[2]=L,s[3]=C,s[4]=k,s[5]=N,s[6]=q,s[7]=z,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){vg(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){vg(this),dS(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 $S(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 PS=$S(t=>new DS(t));function TS(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],y=e[5],m=e[6],B=e[7],$=i,_=n[0],x=n[1],P=n[2],R=o,U=a,F=c,D=u,j=l,M=f,E=d,b=h,v=p,g=y,w=m,S=B,A=$,I=_,O=x,T=P;for(let C=0;C<s;C+=2)R=R+j|0,A=ce(A^R,16),v=v+A|0,j=ce(j^v,12),R=R+j|0,A=ce(A^R,8),v=v+A|0,j=ce(j^v,7),U=U+M|0,I=ce(I^U,16),g=g+I|0,M=ce(M^g,12),U=U+M|0,I=ce(I^U,8),g=g+I|0,M=ce(M^g,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),D=D+b|0,T=ce(T^D,16),S=S+T|0,b=ce(b^S,12),D=D+b|0,T=ce(T^D,8),S=S+T|0,b=ce(b^S,7),R=R+M|0,T=ce(T^R,16),w=w+T|0,M=ce(M^w,12),R=R+M|0,T=ce(T^R,8),w=w+T|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),v=v+I|0,b=ce(b^v,12),F=F+b|0,I=ce(I^F,8),v=v+I|0,b=ce(b^v,7),D=D+j|0,O=ce(O^D,16),g=g+O|0,j=ce(j^g,12),D=D+j|0,O=ce(O^D,8),g=g+O|0,j=ce(j^g,7);let L=0;r[L++]=o+R|0,r[L++]=a+U|0,r[L++]=c+F|0,r[L++]=u+D|0,r[L++]=l+j|0,r[L++]=f+M|0,r[L++]=d+E|0,r[L++]=h+b|0,r[L++]=p+v|0,r[L++]=y+g|0,r[L++]=m+w|0,r[L++]=B+S|0,r[L++]=$+A|0,r[L++]=_+I|0,r[L++]=x+O|0,r[L++]=P+T|0}const RS=OS(TS,{counterRight:!1,counterLength:4,allowShortKeys:!1}),NS=new Uint8Array(16),Ag=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(NS.subarray(n))},CS=new Uint8Array(32);function Bg(t,e,n,r,i){const s=t(e,n,CS),o=PS.create(s);i&&Ag(o,i),Ag(o,r);const a=vS(r.length,i?i.length:0,!0);o.update(a);const c=o.digest();return Si(s,a),c}const US=t=>(e,n,r)=>({encrypt(i,s){const o=i.length;s=Eg(o+16,s,!1),s.set(i);const a=s.subarray(0,-16);t(e,n,a,a,1);const c=Bg(t,e,n,a,r);return s.set(c,o),Si(c),s},decrypt(i,s){s=Eg(i.length-16,s,!1);const o=i.subarray(0,-16),a=i.subarray(-16),c=Bg(t,e,n,o,r);if(!wS(a,c))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),t(e,n,s,s,1),Si(c),s}}),Og=mS({blockSize:64,nonceLength:12,tagLength:16},US(RS));class Dg 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 aa=(t,e,n)=>new Dg(t,e).update(n).digest();aa.create=(t,e)=>new Dg(t,e);function FS(t,e,n){return Qo(t),n===void 0&&(n=new Uint8Array(t.outputLen)),aa(t,Wt(n),Wt(e))}const Yu=Uint8Array.from([0]),$g=Uint8Array.of();function LS(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=$g);const o=new Uint8Array(s*i),a=aa.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?$g: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 kS=(t,e,n,r,i)=>LS(t,FS(t,e,n),r,i),ca=na,Xu=BigInt(0),Ju=BigInt(1);function ua(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 la(t){const e=t.toString(16);return e.length&1?"0"+e:e}function Pg(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Xu:BigInt("0x"+t)}function fa(t){return Pg(_i(t))}function ha(t){return Gt(t),Pg(_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 tt(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 qS(t,e,n){return tl(t)&&tl(e)&&tl(n)&&e<=t&&t<n}function nl(t,e,n,r){if(!qS(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Tg(t){let e;for(e=0;t>Xu;t>>=Ju,e+=1);return e}const vs=t=>(Ju<<BigInt(t))-Ju;function MS(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 da(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 Rg(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),Ng=BigInt(3),Cg=BigInt(4),Ug=BigInt(5),jS=BigInt(7),Fg=BigInt(8),zS=BigInt(9),Lg=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 kg(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 qg(t,e){const n=(t.ORDER+ct)/Cg,r=t.pow(e,n);return rl(t,r,e),r}function HS(t,e){const n=(t.ORDER-Ug)/Fg,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 VS(t){const e=mr(t),n=Mg(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+jS)/Lg;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 y=a.eql(a.sqr(l),c),m=a.cmov(u,l,y);return rl(a,m,c),m}}function Mg(t){if(t<Ng)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(;zg(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return qg;let s=i.pow(r,e);const o=(e+ct)/Gr;return function(a,c){if(a.is0(c))return c;if(zg(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 y=ct<<BigInt(u-h-1),m=a.pow(l,y);u=h,l=a.sqr(m),f=a.mul(f,l),d=a.mul(d,m)}return d}}function KS(t){return t%Cg===Ng?qg:t%Fg===Ug?HS:t%Lg===zS?VS(t):Mg(t)}const GS=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function WS(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=GS.reduce((r,i)=>(r[i]="function",r),e);return da(t,n),t}function ZS(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 jg(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 zg(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 Hg(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}=Hg(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)=>ZS(f,d,h),div:(d,h)=>Ot(d*kg(h,t),t),sqrN:d=>d*d,addN:(d,h)=>d+h,subN:(d,h)=>d-h,mulN:(d,h)=>d*h,inv:d=>kg(d,t),sqrt:s||(d=>(l||(l=KS(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 y=new Uint8Array(u);y.set(d,n?0:y.length-d.length),d=y}if(d.length!==u)throw new Error("Field.fromBytes: expected "+u+" bytes, got "+d.length);let p=n?ha(d):fa(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=>jg(f,d),cmov:(d,h,p)=>p?h:d});return Object.freeze(f)}function Vg(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 Kg(t){const e=Vg(t);return e+Math.ceil(e/2)}function YS(t,e,n=!1){const r=t.length,i=Vg(e),s=Kg(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?ha(t):fa(t),a=Ot(o,e-ct)+ct;return n?el(a,i):Qu(a,i)}const Ii=BigInt(0),Wr=BigInt(1);function pa(t,e){const n=e.negate();return t?n:e}function il(t,e){const n=jg(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function Gg(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){Gg(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 Wg(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 XS(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 JS(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,Zg=new WeakMap;function al(t){return Zg.get(t)||1}function Yg(t){if(t!==Ii)throw new Error("invalid wNAF")}class QS{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}=Wg(r,a,o);r=c,l?s=s.add(pa(d,n[h])):i=i.add(pa(f,n[u]))}return Yg(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}=Wg(r,o,s);if(r=a,!u){const f=n[c];i=i.add(l?f.negate():f)}}return Yg(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){Gg(n,this.bits),Zg.set(e,n),ol.delete(e)}hasCache(e){return al(e)!==1}}function eI(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 tI(t,e,n,r){XS(n,t),JS(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=Tg(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 y=0;y<s;y++){const m=r[y],B=Number(m>>BigInt(h)&u);l[B]=l[B].add(n[y])}let p=o;for(let y=l.length-1,m=o;y>0;y--)m=m.add(l[y]),p=p.add(m);if(d=d.add(p),h!==0)for(let y=0;y<c;y++)d=d.double()}return d}function Xg(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return WS(e),e}else return mr(t,{isLE:n})}function nI(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=Xg(e.p,n.Fp,r),s=Xg(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),ga=BigInt(2);function rI(t){return da(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function iI(t){const e=rI(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?ga**BigInt(254):ga**BigInt(447),p=a?BigInt(8)*ga**BigInt(251)-Ai:BigInt(4)*ga**BigInt(445)-Ai,y=h+p+Ai,m=E=>Ot(E,n),B=$(f);function $(E){return el(m(E),l)}function _(E){const b=tt("u coordinate",E,l);return a&&(b[31]&=127),m(ha(b))}function x(E){return ha(i(tt("scalar",E,l)))}function P(E,b){const v=F(_(b),x(E));if(v===Es)throw new Error("invalid private or public key received");return $(v)}function R(E){return P(E,B)}function U(E,b,v){const g=m(E*(b-v));return b=m(b-g),v=m(v+g),{x_2:b,x_3:v}}function F(E,b){nl("u",E,Es,n),nl("scalar",b,h,y);const v=b,g=E;let w=Ai,S=Es,A=E,I=Ai,O=Es;for(let L=BigInt(u-1);L>=Es;L--){const C=v>>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=m(k*k),q=w-S,z=m(q*q),W=N-z,V=A+I,Z=A-I,Q=m(Z*k),ee=m(V*q),ie=Q+ee,fe=Q-ee;A=m(ie*ie),I=m(g*m(fe*fe)),w=m(N*z),S=m(W*(N+m(d*W)))}({x_2:w,x_3:A}=U(O,w,A)),{x_2:S,x_3:I}=U(O,S,I);const T=s(S);return m(w*T)}const D={secretKey:l,publicKey:l,seed:l},j=(E=c(l))=>(Gt(E,D.seed),E);function M(E){const b=j(E);return{secretKey:b,publicKey:R(b)}}return{keygen:M,getSharedSecret:(E,b)=>P(E,b),getPublicKey:E=>R(E),scalarMult:P,scalarMultBase:R,utils:{randomSecretKey:j,randomPrivateKey:j},GuBytes:B.slice(),lengths:D}}const sI=BigInt(1),Jg=BigInt(2),oI=BigInt(3),aI=BigInt(5),cI=BigInt(8),Qg=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),uI={p:Qg,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:cI,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function lI(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=Qg,o=t*t%s*t%s,a=Zt(o,Jg,s)*o%s,c=Zt(a,sI,s)*t%s,u=Zt(c,aI,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,y=Zt(p,e,s)*u%s;return{pow_p_5_8:Zt(y,Jg,s)*t%s,b2:o}}function fI(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const hI=mr(uI.p,{isLE:!0}),cl=(()=>{const t=hI.ORDER;return iI({P:t,type:"x25519",powPminus2:e=>{const{pow_p_5_8:n,b2:r}=lI(e);return Ot(Zt(n,oI,t)*r,t)},adjustScalarBytes:fI})})(),e1=(t,e)=>(t+(t>=0?e:-e)/t1)/e;function dI(t,e,n){const[[r,i],[s,o]]=e,a=e1(o*t,n),c=e1(-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(Tg(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 ua(n.lowS,"lowS"),ua(n.prehash,"prehash"),n.format!==void 0&&ul(n.format),n}class pI extends Error{constructor(e=""){super(e)}}const Pn={Err:pI,_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=la(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?la(i.length/2|128):"";return la(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=la(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 fa(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=Pn,i=tt("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),t1=BigInt(2),ya=BigInt(3),gI=BigInt(4);function Oi(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=tt("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 yI(t,e={}){const n=nI("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;da(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=r1(r,i);function l(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function f(E,b,v){const{x:g,y:w}=b.toAffine(),S=r.toBytes(g);if(ua(v,"isCompressed"),v){l();const A=!r.isOdd(w);return fr(n1(A),S)}else return fr(Uint8Array.of(4),S,r.toBytes(w))}function d(E){Kr(E,void 0,"Point");const{publicKey:b,publicKeyUncompressed:v}=u,g=E.length,w=E[0],S=E.subarray(1);if(g===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=y(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 T=r.isOdd(O);return(w&1)===1!==T&&(O=r.neg(O)),{x:A,y:O}}else if(g===v&&w===4){const A=r.BYTES,I=r.fromBytes(S.subarray(0,A)),O=r.fromBytes(S.subarray(A,A*2));if(!m(I,O))throw new Error("bad point: is not on curve");return{x:I,y:O}}else throw new Error(`bad point: got length ${g}, expected compressed=${b} or uncompressed=${v}`)}const h=e.toBytes||f,p=e.fromBytes||d;function y(E){const b=r.sqr(E),v=r.mul(b,E);return r.add(r.add(v,r.mul(E,s.a)),s.b)}function m(E,b){const v=r.sqr(b),g=y(E);return r.eql(v,g)}if(!m(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const B=r.mul(r.pow(s.a,ya),gI),$=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(B,$)))throw new Error("bad curve params: a or b");function _(E,b,v=!1){if(!r.isValid(b)||v&&r.is0(b))throw new Error(`bad point coordinate ${E}`);return b}function x(E){if(!(E instanceof D))throw new Error("ProjectivePoint expected")}function P(E){if(!c||!c.basises)throw new Error("no endo");return dI(E,c.basises,i.ORDER)}const R=Rg((E,b)=>{const{X:v,Y:g,Z:w}=E;if(r.eql(w,r.ONE))return{x:v,y:g};const S=E.is0();b==null&&(b=S?r.ONE:r.inv(w));const A=r.mul(v,b),I=r.mul(g,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=Rg(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.Y))return;throw new Error("bad point: ZERO")}const{x:b,y:v}=E.toAffine();if(!r.isValid(b)||!r.isValid(v))throw new Error("bad point: x or y not field elements");if(!m(b,v))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,v,g,w){return v=new D(r.mul(v.X,E),v.Y,v.Z),b=pa(g,b),v=pa(w,v),b.add(v)}class D{constructor(b,v,g){this.X=_("x",b),this.Y=_("y",v,!0),this.Z=_("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){const{x:v,y:g}=b||{};if(!b||!r.isValid(v)||!r.isValid(g))throw new Error("invalid affine point");if(b instanceof D)throw new Error("projective point not allowed");return r.is0(v)&&r.is0(g)?D.ZERO:new D(v,g,r.ONE)}static fromBytes(b){const v=D.fromAffine(p(Kr(b,void 0,"point")));return v.assertValidity(),v}static fromHex(b){return D.fromBytes(tt("pointHex",b))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,v=!0){return M.createCache(this,b),v||this.multiply(ya),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:v,Y:g,Z:w}=this,{X:S,Y:A,Z:I}=b,O=r.eql(r.mul(v,I),r.mul(S,w)),T=r.eql(r.mul(g,I),r.mul(A,w));return O&&T}negate(){return new D(this.X,r.neg(this.Y),this.Z)}double(){const{a:b,b:v}=s,g=r.mul(v,ya),{X:w,Y:S,Z:A}=this;let I=r.ZERO,O=r.ZERO,T=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),T=r.mul(w,A),T=r.add(T,T),I=r.mul(b,T),O=r.mul(g,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),T=r.mul(g,T),k=r.mul(b,k),N=r.sub(L,k),N=r.mul(b,N),N=r.add(N,T),T=r.add(L,L),L=r.add(T,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),T=r.mul(k,C),T=r.add(T,T),T=r.add(T,T),new D(I,O,T)}add(b){x(b);const{X:v,Y:g,Z:w}=this,{X:S,Y:A,Z:I}=b;let O=r.ZERO,T=r.ZERO,L=r.ZERO;const C=s.a,k=r.mul(s.b,ya);let N=r.mul(v,S),q=r.mul(g,A),z=r.mul(w,I),W=r.add(v,g),V=r.add(S,A);W=r.mul(W,V),V=r.add(N,q),W=r.sub(W,V),V=r.add(v,w);let Z=r.add(S,I);return V=r.mul(V,Z),Z=r.add(N,z),V=r.sub(V,Z),Z=r.add(g,w),O=r.add(A,I),Z=r.mul(Z,O),O=r.add(q,z),Z=r.sub(Z,O),L=r.mul(C,V),O=r.mul(k,z),L=r.add(O,L),O=r.sub(q,L),L=r.add(q,L),T=r.mul(O,L),q=r.add(N,N),q=r.add(q,N),z=r.mul(C,z),V=r.mul(k,V),q=r.add(q,z),z=r.sub(N,z),z=r.mul(C,z),V=r.add(V,z),N=r.mul(q,V),T=r.add(T,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 D(O,T,L)}subtract(b){return this.add(b.negate())}is0(){return this.equals(D.ZERO)}multiply(b){const{endo:v}=e;if(!i.isValidNot0(b))throw new Error("invalid scalar: out of range");let g,w;const S=A=>M.cached(this,A,I=>il(D,I));if(v){const{k1neg:A,k1:I,k2neg:O,k2:T}=P(b),{p:L,f:C}=S(I),{p:k,f:N}=S(T);w=C.add(N),g=F(v.beta,L,k,A,O)}else{const{p:A,f:I}=S(b);g=A,w=I}return il(D,[g,w])[0]}multiplyUnsafe(b){const{endo:v}=e,g=this;if(!i.isValid(b))throw new Error("invalid scalar: out of range");if(b===Tn||g.is0())return D.ZERO;if(b===Bi)return g;if(M.hasCache(this))return this.multiply(b);if(v){const{k1neg:w,k1:S,k2neg:A,k2:I}=P(b),{p1:O,p2:T}=eI(D,g,S,I);return F(v.beta,O,T,w,A)}else return M.unsafe(g,b)}multiplyAndAddUnsafe(b,v,g){const w=this.multiplyUnsafe(v).add(b.multiplyUnsafe(g));return w.is0()?void 0:w}toAffine(b){return R(this,b)}isTorsionFree(){const{isTorsionFree:b}=e;return o===Bi?!0:b?b(D,this):M.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:b}=e;return o===Bi?this:b?b(D,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(b=!0){return ua(b,"isCompressed"),this.assertValidity(),h(D,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(D,b)}static msm(b,v){return tI(D,i,b,v)}static fromPrivateKey(b){return D.BASE.multiply(Oi(i,b))}}D.BASE=new D(s.Gx,s.Gy,r.ONE),D.ZERO=new D(r.ZERO,r.ONE,r.ZERO),D.Fp=r,D.Fn=i;const j=i.BITS,M=new QS(D,e.endo?Math.ceil(j/2):j);return D.BASE.precompute(8),D}function n1(t){return Uint8Array.of(t?2:3)}function r1(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function bI(t,e={}){const{Fn:n}=t,r=e.randomBytes||Hr,i=Object.assign(r1(t.Fp,n),{seed:Kg(n.ORDER)});function s(d){try{return!!Oi(n,d)}catch{return!1}}function o(d,h){const{publicKey:p,publicKeyUncompressed:y}=i;try{const m=d.length;return h===!0&&m!==p||h===!1&&m!==y?!1:!!t.fromBytes(d)}catch{return!1}}function a(d=r(i.seed)){return YS(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:y}=i;if(n.allowedLengths||h===p)return;const m=tt("key",d).length;return m===p||m===y}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 y=Oi(n,d);return t.fromHex(h).multiply(y).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 wI(t,e,n={}){Qo(e),da(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Hr,i=n.hmac||((v,...g)=>aa(e,v,fr(...g))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h}=bI(t,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},y="compact";function m(v){const g=a>>Bi;return v>g}function B(v,g){if(!o.isValidNot0(g))throw new Error(`invalid signature ${v}: out of range 1..Point.Fn.ORDER`);return g}function $(v,g){ul(g);const w=h.signature,S=g==="compact"?w:g==="recovered"?w+1:void 0;return Kr(v,S,`${g} signature`)}class _{constructor(g,w,S){this.r=B("r",g),this.s=B("s",w),S!=null&&(this.recovery=S),Object.freeze(this)}static fromBytes(g,w=y){$(g,w);let S;if(w==="der"){const{r:T,s:L}=Pn.toSig(Kr(g));return new _(T,L)}w==="recovered"&&(S=g[0],w="compact",g=g.subarray(1));const A=o.BYTES,I=g.subarray(0,A),O=g.subarray(A,A*2);return new _(o.fromBytes(I),o.fromBytes(O),S)}static fromHex(g,w){return this.fromBytes(ea(g),w)}addRecoveryBit(g){return new _(this.r,this.s,g)}recoverPublicKey(g){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*t1<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 T=s.toBytes(O),L=t.fromBytes(fr(n1((I&1)===0),T)),C=o.inv(O),k=P(tt("msgHash",g)),N=o.create(-k*C),q=o.create(A*C),z=t.BASE.multiplyUnsafe(N).add(L.multiplyUnsafe(q));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return m(this.s)}toBytes(g=y){if(ul(g),g==="der")return ea(Pn.hexFromSig(this));const w=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 fr(Uint8Array.of(this.recovery),w,S)}return fr(w,S)}toHex(g){return _i(this.toBytes(g))}assertValidity(){}static fromCompact(g){return _.fromBytes(tt("sig",g),"compact")}static fromDER(g){return _.fromBytes(tt("sig",g),"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(v){if(v.length>8192)throw new Error("input is too large");const g=fa(v),w=v.length*8-c;return w>0?g>>BigInt(w):g},P=n.bits2int_modN||function(v){return o.create(x(v))},R=vs(c);function U(v){return nl("num < 2^"+c,v,Tn,R),o.toBytes(v)}function F(v,g){return Kr(v,void 0,"message"),g?Kr(e(v),void 0,"prehashed message"):v}function D(v,g,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);v=F(v,A);const O=P(v),T=Oi(o,g),L=[U(T),U(O)];if(I!=null&&I!==!1){const q=I===!0?r(h.secretKey):I;L.push(tt("extraEntropy",q))}const C=fr(...L),k=O;function N(q){const z=x(q);if(!o.isValidNot0(z))return;const W=o.inv(z),V=t.BASE.multiply(z).toAffine(),Z=o.create(V.x);if(Z===Tn)return;const Q=o.create(W*o.create(k+Z*T));if(Q===Tn)return;let ee=(V.x===Z?0:2)|Number(V.y&Bi),ie=Q;return S&&m(Q)&&(ie=o.neg(Q),ee^=1),new _(Z,ie,ee)}return{seed:C,k2sig:N}}function j(v,g,w={}){v=tt("message",v);const{seed:S,k2sig:A}=D(v,g,w);return MS(e.outputLen,o.BYTES,i)(S,A)}function M(v){let g;const w=typeof v=="string"||Jo(v),S=!w&&v!==null&&typeof v=="object"&&typeof v.r=="bigint"&&typeof v.s=="bigint";if(!w&&!S)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(S)g=new _(v.r,v.s);else if(w){try{g=_.fromBytes(tt("sig",v),"der")}catch(A){if(!(A instanceof Pn.Err))throw A}if(!g)try{g=_.fromBytes(tt("sig",v),"compact")}catch{return!1}}return g||!1}function E(v,g,w,S={}){const{lowS:A,prehash:I,format:O}=ll(S,p);if(w=tt("publicKey",w),g=F(tt("message",g),I),"strict"in S)throw new Error("options.strict was renamed to lowS");const T=O===void 0?M(v):_.fromBytes(tt("sig",v),O);if(T===!1)return!1;try{const L=t.fromBytes(w);if(A&&T.hasHighS())return!1;const{r:C,s:k}=T,N=P(g),q=o.inv(k),z=o.create(N*q),W=o.create(C*q),V=t.BASE.multiplyUnsafe(z).add(L.multiplyUnsafe(W));return V.is0()?!1:o.create(V.x)===C}catch{return!1}}function b(v,g,w={}){const{prehash:S}=ll(w,p);return g=F(g,S),_.fromBytes(v,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:f,utils:d,lengths:h,Point:t,sign:j,verify:E,recoverPublicKey:b,Signature:_,hash:e})}function mI(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 vI(t){const{CURVE:e,curveOpts:n}=mI(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 EI(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,Hg(n.Fn.ORDER,n.Fn.BITS))})}function xI(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=vI(t),s=yI(e,n),o=wI(s,r,i);return EI(t,o)}function fl(t,e){const n=r=>xI({...t,hash:r});return{...n(e),create:n}}const i1={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},s1={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},o1={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},_I=mr(i1.p),SI=mr(s1.p),II=mr(o1.p),AI=fl({...i1,Fp:_I,lowS:!1},na);fl({...s1,Fp:SI,lowS:!1},$5),fl({...o1,Fp:II,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},D5);const BI=AI,a1="base10",ut="base16",vt="base64pad",vr="base64url",xs="utf8",c1=0,Rn=1,_s=2,OI=0,u1=1,Ss=12,hl=32;function DI(){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 $I(t,e){const n=cl.getSharedSecret(Ct(t,ut),Ct(e,ut)),r=kS(ca,n,void 0,void 0,hl);return bt(r,ut)}function ba(t){const e=ca(Ct(t,ut));return bt(e,ut)}function Ft(t){const e=ca(Ct(t,xs));return bt(e,ut)}function l1(t){return Ct(`${t}`,a1)}function Zr(t){return Number(bt(t,a1))}function f1(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function h1(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=(4-e.length%4)%4;return e+"=".repeat(n)}function PI(t){const e=l1(typeof t.type<"u"?t.type:c1);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=Og(i,r).encrypt(Ct(t.message,xs)),o=d1({type:e,sealed:s,iv:r,senderPublicKey:n});return t.encoding===vr?f1(o):o}function TI(t){const e=Ct(t.symKey,ut),{sealed:n,iv:r}=Is({encoded:t.encoded,encoding:t.encoding}),i=Og(e,r).decrypt(n);if(i===null)throw new Error("Failed to decrypt");return bt(i,xs)}function RI(t,e){const n=l1(_s),r=Hr(Ss),i=Ct(t,xs),s=d1({type:n,sealed:i,iv:r});return e===vr?f1(s):s}function NI(t,e){const{sealed:n}=Is({encoded:t,encoding:e});return bt(n,xs)}function d1(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?h1(t.encoded):t.encoded,n=Ct(e,vt),r=n.slice(OI,u1),i=u1;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 CI(t,e){const n=Is({encoded:t,encoding:e?.encoding});return p1({type:Zr(n.type),senderPublicKey:typeof n.senderPublicKey<"u"?bt(n.senderPublicKey,ut):void 0,receiverPublicKey:e?.receiverPublicKey})}function p1(t){const e=t?.type||c1;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 g1(t){return t.type===Rn&&typeof t.senderPublicKey=="string"&&typeof t.receiverPublicKey=="string"}function y1(t){return t.type===_s}function UI(t){const e=Buffer.from(t.x,"base64"),n=Buffer.from(t.y,"base64");return cs([new Uint8Array([4]),e,n])}function FI(t,e){const[n,r,i]=t.split("."),s=Buffer.from(h1(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=ca(c),l=UI(e);if(!BI.verify(cs([o,a]),u,l))throw new Error("Invalid signature");return dc(t).payload}const LI="irn";function wa(t){return t?.relay||{protocol:LI}}function Di(t){const e=f_[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}var kI=Object.defineProperty,qI=Object.defineProperties,MI=Object.getOwnPropertyDescriptors,b1=Object.getOwnPropertySymbols,jI=Object.prototype.hasOwnProperty,zI=Object.prototype.propertyIsEnumerable,w1=(t,e,n)=>e in t?kI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,pl=(t,e)=>{for(var n in e||(e={}))jI.call(e,n)&&w1(t,n,e[n]);if(b1)for(var n of b1(e))zI.call(e,n)&&w1(t,n,e[n]);return t},HI=(t,e)=>qI(t,MI(e));function VI(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 m1(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:KI(i[0]),version:parseInt(i[1],10),symKey:a.symKey,relay:VI(a),methods:c,expiryTimestamp:a.expiryTimestamp?parseInt(a.expiryTimestamp,10):void 0}}function KI(t){return t.startsWith("//")?t.substring(2):t}function GI(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 v1(t){const e=new URLSearchParams,n=pl(pl(HI(pl({},GI(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 ma(t,e,n){return`${t}?wc_ev=${n}&topic=${e}`}var WI=Object.defineProperty,ZI=Object.defineProperties,YI=Object.getOwnPropertyDescriptors,E1=Object.getOwnPropertySymbols,XI=Object.prototype.hasOwnProperty,JI=Object.prototype.propertyIsEnumerable,x1=(t,e,n)=>e in t?WI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,QI=(t,e)=>{for(var n in e||(e={}))XI.call(e,n)&&x1(t,n,e[n]);if(E1)for(var n of E1(e))JI.call(e,n)&&x1(t,n,e[n]);return t},e9=(t,e)=>ZI(t,YI(e));function $i(t){const e=[];return t.forEach(n=>{const[r,i]=n.split(":");e.push(`${r}:${i}`)}),e}function _1(t){const e=[];return Object.values(t).forEach(n=>{e.push(...$i(n.accounts))}),[...new Set(e)]}function t9(t){const e=[];return Object.values(t).forEach(n=>{e.push(...n.methods)}),[...new Set(e)]}function n9(t){const e=[];return Object.values(t).forEach(n=>{e.push(...n.events)}),[...new Set(e)]}function r9(t,e){const n=[];return Object.values(t).forEach(r=>{$i(r.accounts).includes(e)&&n.push(...r.methods)}),n}function i9(t,e){const n=[];return Object.values(t).forEach(r=>{$i(r.accounts).includes(e)&&n.push(...r.events)}),n}function S1(t){return t.includes(":")}function s9(t){return S1(t)?t.split(":")[0]:t}function I1(t){var e,n,r;const i={};if(!As(t))return i;for(const[s,o]of Object.entries(t)){const a=S1(s)?[s]:o.chains,c=o.methods||[],u=o.events||[],l=s9(s);i[l]=e9(QI({},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 o9(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 A1(t,e){e=e.map(r=>r.replace("did:pkh:",""));const n=o9(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 a9(t,e){var n,r,i,s,o,a;const c=I1(t),u=I1(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 c9={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}},u9={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}=u9[t];return{message:e?`${n} ${e}`:n,code:r}}function Ee(t,e){const{message:n,code:r}=c9[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 Se(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 l9(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 va(t){return Se(t,!1)&&t.includes(":")?t.split(":").length===2:!1}function f9(t){if(Se(t,!1)&&t.includes(":")){const e=t.split(":");if(e.length===3){const n=e[0]+":"+e[1];return!!e[2]&&va(n)}}return!1}function h9(t){function e(n){try{return typeof new URL(n)<"u"}catch{return!1}}try{if(Se(t,!1)){if(e(t))return!0;const n=z0(t);return e(n)}}catch{}return!1}function d9(t){var e;return(e=t?.proposer)==null?void 0:e.publicKey}function p9(t){return t?.topic}function g9(t,e){let n=null;return Se(t?.publicKey,!1)||(n=G("MISSING_OR_INVALID",`${e} controller public key should be a string`)),n}function B1(t){let e=!0;return Pi(t)?t.length&&(e=t.every(n=>Se(n,!1))):e=!1,e}function y9(t,e,n){let r=null;return Pi(e)&&e.length?e.forEach(i=>{r||va(i)||(r=Ee("UNSUPPORTED_CHAINS",`${n}, chain ${i} should be a string and conform to "namespace:chainId" format`))}):va(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 b9(t,e,n){let r=null;return Object.entries(t).forEach(([i,s])=>{if(r)return;const o=y9(i,T0(i,s),`${e} ${n}`);o&&(r=o)}),r}function w9(t,e){let n=null;return Pi(t)?t.forEach(r=>{n||f9(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 m9(t,e){let n=null;return Object.values(t).forEach(r=>{if(n)return;const i=w9(r?.accounts,`${e} namespace`);i&&(n=i)}),n}function v9(t,e){let n=null;return B1(t?.methods)?B1(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 O1(t,e){let n=null;return Object.values(t).forEach(r=>{if(n)return;const i=v9(r,`${e}, namespace`);i&&(n=i)}),n}function E9(t,e,n){let r=null;if(t&&As(t)){const i=O1(t,e);i&&(r=i);const s=b9(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=O1(t,e);r&&(n=r);const i=m9(t,e);i&&(n=i)}else n=G("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return n}function D1(t){return Se(t.protocol,!0)}function x9(t,e){let n=!1;return e&&!t?n=!0:t&&Pi(t)&&t.length&&t.forEach(r=>{n=D1(r)}),n}function _9(t){return typeof t=="number"}function Et(t){return typeof t<"u"&&typeof t!==null}function S9(t){return!(!t||typeof t!="object"||!t.code||!gl(t.code,!1)||!t.message||!Se(t.message,!1))}function I9(t){return!(Pe(t)||!Se(t.method,!1))}function A9(t){return!(Pe(t)||Pe(t.result)&&Pe(t.error)||!gl(t.id,!1)||!Se(t.jsonrpc,!1))}function B9(t){return!(Pe(t)||!Se(t.name,!1))}function $1(t,e){return!(!va(e)||!_1(t).includes(e))}function O9(t,e,n){return Se(n,!1)?r9(t,e).includes(n):!1}function D9(t,e,n){return Se(n,!1)?i9(t,e).includes(n):!1}function P1(t,e,n){let r=null;const i=$9(t),s=P9(e),o=Object.keys(i),a=Object.keys(s),c=T1(Object.keys(t)),u=T1(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.
22
- 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.
14
+ ***************************************************************************** */var tf=function(t,e){return tf=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])},tf(t,e)};function y3(t,e){tf(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var nf=function(){return nf=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},nf.apply(this,arguments)};function b3(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 w3(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 m3(t,e){return function(n,r){e(n,r,t)}}function v3(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function E3(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(u){try{f(r.next(u))}catch(h){o(h)}}function c(u){try{f(r.throw(u))}catch(h){o(h)}}function f(u){u.done?s(u.value):i(u.value).then(a,c)}f((r=r.apply(t,e||[])).next())})}function x3(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(u){return c([f,u])}}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(u){f=[6,u],i=0}finally{r=s=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}function _3(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]}function I3(t,e){for(var n in t)n!=="default"&&!e.hasOwnProperty(n)&&(e[n]=t[n])}function rf(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 md(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 S3(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(md(arguments[e]));return t}function B3(){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 Ns(t){return this instanceof Ns?(this.v=t,this):new Ns(t)}function $3(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(l){r[l]&&(i[l]=function(d){return new Promise(function(p,b){s.push([l,d,p,b])>1||a(l,d)})})}function a(l,d){try{c(r[l](d))}catch(p){h(s[0][3],p)}}function c(l){l.value instanceof Ns?Promise.resolve(l.value.v).then(f,u):h(s[0][2],l)}function f(l){a("next",l)}function u(l){a("throw",l)}function h(l,d){l(d),s.shift(),s.length&&a(s[0][0],s[0][1])}}function A3(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:Ns(t[i](o)),done:i==="return"}:s?s(o):o}:s}}function O3(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 rf=="function"?rf(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 D3(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function P3(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 R3(t){return t&&t.__esModule?t:{default:t}}function T3(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function N3(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 U3=Object.freeze({__proto__:null,__extends:y3,get __assign(){return nf},__rest:b3,__decorate:w3,__param:m3,__metadata:v3,__awaiter:E3,__generator:x3,__createBinding:_3,__exportStar:I3,__values:rf,__read:md,__spread:S3,__spreadArrays:B3,__await:Ns,__asyncGenerator:$3,__asyncDelegator:A3,__asyncValues:O3,__makeTemplateObject:D3,__importStar:P3,__importDefault:R3,__classPrivateFieldGet:T3,__classPrivateFieldSet:N3}),Jo=Kh(U3),sf={},Us={},vd;function C3(){if(vd)return Us;vd=1,Object.defineProperty(Us,"__esModule",{value:!0}),Us.delay=void 0;function t(e){return new Promise(n=>{setTimeout(()=>{n(!0)},e)})}return Us.delay=t,Us}var di={},of={},pi={},Ed;function F3(){return Ed||(Ed=1,Object.defineProperty(pi,"__esModule",{value:!0}),pi.ONE_THOUSAND=pi.ONE_HUNDRED=void 0,pi.ONE_HUNDRED=100,pi.ONE_THOUSAND=1e3),pi}var af={},xd;function L3(){return xd||(xd=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}(af)),af}var _d;function Id(){return _d||(_d=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=Jo;e.__exportStar(F3(),t),e.__exportStar(L3(),t)}(of)),of}var Sd;function k3(){if(Sd)return di;Sd=1,Object.defineProperty(di,"__esModule",{value:!0}),di.fromMiliseconds=di.toMiliseconds=void 0;const t=Id();function e(r){return r*t.ONE_THOUSAND}di.toMiliseconds=e;function n(r){return Math.floor(r/t.ONE_THOUSAND)}return di.fromMiliseconds=n,di}var Bd;function q3(){return Bd||(Bd=1,function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=Jo;e.__exportStar(C3(),t),e.__exportStar(k3(),t)}(sf)),sf}var Gi={},$d;function M3(){if($d)return Gi;$d=1,Object.defineProperty(Gi,"__esModule",{value:!0}),Gi.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 Gi.Watch=t,Gi.default=t,Gi}var cf={},Cs={},Ad;function j3(){if(Ad)return Cs;Ad=1,Object.defineProperty(Cs,"__esModule",{value:!0}),Cs.IWatch=void 0;class t{}return Cs.IWatch=t,Cs}var Od;function z3(){return Od||(Od=1,function(t){Object.defineProperty(t,"__esModule",{value:!0}),Jo.__exportStar(j3(),t)}(cf)),cf}(function(t){Object.defineProperty(t,"__esModule",{value:!0});const e=Jo;e.__exportStar(q3(),t),e.__exportStar(M3(),t),e.__exportStar(z3(),t),e.__exportStar(Id(),t)})(Z);var Ee={};Object.defineProperty(Ee,"__esModule",{value:!0}),Ee.getLocalStorage=Ee.getLocalStorageOrThrow=Ee.getCrypto=Ee.getCryptoOrThrow=Dd=Ee.getLocation=Ee.getLocationOrThrow=Fs=Ee.getNavigator=Ee.getNavigatorOrThrow=Un=Ee.getDocument=Ee.getDocumentOrThrow=Ee.getFromWindowOrThrow=Ee.getFromWindow=void 0;function gi(t){let e;return typeof window<"u"&&typeof window[t]<"u"&&(e=window[t]),e}Ee.getFromWindow=gi;function Zi(t){const e=gi(t);if(!e)throw new Error(`${t} is not defined in Window`);return e}Ee.getFromWindowOrThrow=Zi;function H3(){return Zi("document")}Ee.getDocumentOrThrow=H3;function V3(){return gi("document")}var Un=Ee.getDocument=V3;function K3(){return Zi("navigator")}Ee.getNavigatorOrThrow=K3;function G3(){return gi("navigator")}var Fs=Ee.getNavigator=G3;function Z3(){return Zi("location")}Ee.getLocationOrThrow=Z3;function W3(){return gi("location")}var Dd=Ee.getLocation=W3;function Y3(){return Zi("crypto")}Ee.getCryptoOrThrow=Y3;function X3(){return gi("crypto")}Ee.getCrypto=X3;function J3(){return Zi("localStorage")}Ee.getLocalStorageOrThrow=J3;function Q3(){return gi("localStorage")}Ee.getLocalStorage=Q3;var ff={};Object.defineProperty(ff,"__esModule",{value:!0});var Pd=ff.getWindowMetadata=void 0;const Rd=Ee;function ev(){let t,e;try{t=Rd.getDocumentOrThrow(),e=Rd.getLocationOrThrow()}catch{return null}function n(){const h=t.getElementsByTagName("link"),l=[];for(let d=0;d<h.length;d++){const p=h[d],b=p.getAttribute("rel");if(b&&b.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 O=e.protocol+"//"+e.host;if(v.indexOf("/")===0)O+=v;else{const P=e.pathname.split("/");P.pop();const x=P.join("/");O+=x+"/"+v}l.push(O)}else if(v.indexOf("//")===0){const O=e.protocol+v;l.push(O)}else l.push(v)}}return l}function r(...h){const l=t.getElementsByTagName("meta");for(let d=0;d<l.length;d++){const p=l[d],b=["itemprop","property","name"].map(v=>p.getAttribute(v)).filter(v=>v?h.includes(v):!1);if(b.length&&b){const v=p.getAttribute("content");if(v)return v}}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}}Pd=ff.getWindowMetadata=ev;const tv="0.1.1";function nv(){return tv}class me extends Error{constructor(e,n={}){const r=(()=>{if(n.cause instanceof me){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 me&&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@${nv()}`}),this.cause=n.cause,this.details=r,this.docs=o,this.docsPath=i,this.shortMessage=e}walk(e){return Td(this,e)}}function Td(t,e){return e?.(t)?t:t&&typeof t=="object"&&"cause"in t&&t.cause?Td(t.cause,e):e?null:t}const Wi=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function rv(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ls(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function yi(t,...e){if(!rv(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 iv(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Ls(t.outputLen),Ls(t.blockLen)}function Yi(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 Nd(t,e){yi(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function sv(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function yr(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function uf(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function En(t,e){return t<<32-e|t>>>e}const ov=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function av(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}function cv(t){for(let e=0;e<t.length;e++)t[e]=av(t[e]);return t}const Ud=ov?t=>t:cv;function fv(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Qo(t){return typeof t=="string"&&(t=fv(t)),yi(t),t}function uv(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];yi(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 lf{}function ea(t){const e=r=>t().update(Qo(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Cd(t=32){if(Wi&&typeof Wi.getRandomValues=="function")return Wi.getRandomValues(new Uint8Array(t));if(Wi&&typeof Wi.randomBytes=="function")return Uint8Array.from(Wi.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}function lv(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 hv(t,e,n){return t&e^~t&n}function dv(t,e,n){return t&e^t&n^e&n}class Fd extends lf{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=uf(this.buffer)}update(e){Yi(this),e=Qo(e),yi(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=uf(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){Yi(this),Nd(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,yr(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;lv(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=uf(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,u[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 Cn=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),et=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),tt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),ta=BigInt(2**32-1),Ld=BigInt(32);function pv(t,e=!1){return e?{h:Number(t&ta),l:Number(t>>Ld&ta)}:{h:Number(t>>Ld&ta)|0,l:Number(t&ta)|0}}function kd(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}=pv(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const qd=(t,e,n)=>t>>>n,Md=(t,e,n)=>t<<32-n|e>>>n,Xi=(t,e,n)=>t>>>n|e<<32-n,Ji=(t,e,n)=>t<<32-n|e>>>n,na=(t,e,n)=>t<<64-n|e>>>n-32,ra=(t,e,n)=>t>>>n-32|e<<64-n,gv=(t,e,n)=>t<<n|e>>>32-n,yv=(t,e,n)=>e<<n|t>>>32-n,bv=(t,e,n)=>e<<n-32|t>>>64-n,wv=(t,e,n)=>t<<n-32|e>>>64-n;function Fn(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const mv=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),vv=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,Ev=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),xv=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,_v=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),Iv=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,Sv=BigInt(0),ks=BigInt(1),Bv=BigInt(2),$v=BigInt(7),Av=BigInt(256),Ov=BigInt(113),jd=[],zd=[],Hd=[];for(let t=0,e=ks,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],jd.push(2*(5*r+n)),zd.push((t+1)*(t+2)/2%64);let i=Sv;for(let s=0;s<7;s++)e=(e<<ks^(e>>$v)*Ov)%Av,e&Bv&&(i^=ks<<(ks<<BigInt(s))-ks);Hd.push(i)}const Vd=kd(Hd,!0),Dv=Vd[0],Pv=Vd[1],Kd=(t,e,n)=>n>32?bv(t,e,n):gv(t,e,n),Gd=(t,e,n)=>n>32?wv(t,e,n):yv(t,e,n);function Rv(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],u=n[c+1],h=Kd(f,u,1)^n[a],l=Gd(f,u,1)^n[a+1];for(let d=0;d<50;d+=10)t[o+d]^=h,t[o+d+1]^=l}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=zd[o],c=Kd(i,s,a),f=Gd(i,s,a),u=jd[o];i=t[u],s=t[u+1],t[u]=c,t[u+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)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]^=Dv[r],t[1]^=Pv[r]}yr(n)}class hf extends lf{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,Ls(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=sv(this.state)}clone(){return this._cloneInto()}keccak(){Ud(this.state32),Rv(this.state32,this.rounds),Ud(this.state32),this.posOut=0,this.pos=0}update(e){Yi(this),e=Qo(e),yi(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){Yi(this,!1),yi(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 Ls(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Nd(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,yr(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new hf(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 Tv=(t,e,n)=>ea(()=>new hf(e,t,n)),Nv=Tv(1,136,256/8),Uv=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]),br=new Uint32Array(64);class Cv extends Fd{constructor(e=32){super(64,e,8,!1),this.A=Cn[0]|0,this.B=Cn[1]|0,this.C=Cn[2]|0,this.D=Cn[3]|0,this.E=Cn[4]|0,this.F=Cn[5]|0,this.G=Cn[6]|0,this.H=Cn[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)br[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const l=br[h-15],d=br[h-2],p=En(l,7)^En(l,18)^l>>>3,b=En(d,17)^En(d,19)^d>>>10;br[h]=b+br[h-7]+p+br[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){const l=En(a,6)^En(a,11)^En(a,25),d=u+l+hv(a,c,f)+Uv[h]+br[h]|0,b=(En(r,2)^En(r,13)^En(r,22))+dv(r,i,s)|0;u=f,f=c,c=a,a=o+d|0,o=s,s=i,i=r,r=d+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,u=u+this.H|0,this.set(r,i,s,o,a,c,f,u)}roundClean(){yr(br)}destroy(){this.set(0,0,0,0,0,0,0,0),yr(this.buffer)}}const Zd=kd(["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))),Fv=Zd[0],Lv=Zd[1],wr=new Uint32Array(80),mr=new Uint32Array(80);class Wd extends Fd{constructor(e=64){super(128,e,16,!1),this.Ah=tt[0]|0,this.Al=tt[1]|0,this.Bh=tt[2]|0,this.Bl=tt[3]|0,this.Ch=tt[4]|0,this.Cl=tt[5]|0,this.Dh=tt[6]|0,this.Dl=tt[7]|0,this.Eh=tt[8]|0,this.El=tt[9]|0,this.Fh=tt[10]|0,this.Fl=tt[11]|0,this.Gh=tt[12]|0,this.Gl=tt[13]|0,this.Hh=tt[14]|0,this.Hl=tt[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:l,Gh:d,Gl:p,Hh:b,Hl:v}=this;return[e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,v]}set(e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,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=f|0,this.El=u|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=b|0,this.Hl=v|0}process(e,n){for(let x=0;x<16;x++,n+=4)wr[x]=e.getUint32(n),mr[x]=e.getUint32(n+=4);for(let x=16;x<80;x++){const S=wr[x-15]|0,R=mr[x-15]|0,U=Xi(S,R,1)^Xi(S,R,8)^qd(S,R,7),L=Ji(S,R,1)^Ji(S,R,8)^Md(S,R,7),C=wr[x-2]|0,A=mr[x-2]|0,j=Xi(C,A,19)^na(C,A,61)^qd(C,A,6),q=Ji(C,A,19)^ra(C,A,61)^Md(C,A,6),E=Ev(L,q,mr[x-7],mr[x-16]),y=xv(E,U,j,wr[x-7],wr[x-16]);wr[x]=y|0,mr[x]=E|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:l,Fh:d,Fl:p,Gh:b,Gl:v,Hh:O,Hl:P}=this;for(let x=0;x<80;x++){const S=Xi(h,l,14)^Xi(h,l,18)^na(h,l,41),R=Ji(h,l,14)^Ji(h,l,18)^ra(h,l,41),U=h&d^~h&b,L=l&p^~l&v,C=_v(P,R,L,Lv[x],mr[x]),A=Iv(C,O,S,U,Fv[x],wr[x]),j=C|0,q=Xi(r,i,28)^na(r,i,34)^na(r,i,39),E=Ji(r,i,28)^ra(r,i,34)^ra(r,i,39),y=r&s^r&a^s&a,w=i&o^i&c^o&c;O=b|0,P=v|0,b=d|0,v=p|0,d=h|0,p=l|0,{h,l}=Fn(f|0,u|0,A|0,j|0),f=a|0,u=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=mv(j,E,w);r=vv(g,A,q,y),i=g|0}({h:r,l:i}=Fn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=Fn(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=Fn(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=Fn(this.Dh|0,this.Dl|0,f|0,u|0),{h,l}=Fn(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=Fn(this.Fh|0,this.Fl|0,d|0,p|0),{h:b,l:v}=Fn(this.Gh|0,this.Gl|0,b|0,v|0),{h:O,l:P}=Fn(this.Hh|0,this.Hl|0,O|0,P|0),this.set(r,i,s,o,a,c,f,u,h,l,d,p,b,v,O,P)}roundClean(){yr(wr,mr)}destroy(){yr(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class kv extends Wd{constructor(){super(48),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}}const ia=ea(()=>new Cv),qv=ea(()=>new Wd),Mv=ea(()=>new kv);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const df=BigInt(0),sa=BigInt(1);function qs(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function vr(t){if(!qs(t))throw new Error("Uint8Array expected")}function Ms(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}function oa(t){const e=t.toString(16);return e.length&1?"0"+e:e}function Yd(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?df:BigInt("0x"+t)}const Xd=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",jv=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function bi(t){if(vr(t),Xd)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=jv[t[n]];return e}const Ln={_0:48,_9:57,A:65,F:70,a:97,f:102};function Jd(t){if(t>=Ln._0&&t<=Ln._9)return t-Ln._0;if(t>=Ln.A&&t<=Ln.F)return t-(Ln.A-10);if(t>=Ln.a&&t<=Ln.f)return t-(Ln.a-10)}function aa(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(Xd)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=Jd(t.charCodeAt(s)),a=Jd(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 pt(t){return Yd(bi(t))}function Qd(t){return vr(t),Yd(bi(Uint8Array.from(t).reverse()))}function Re(t,e){return aa(t.toString(16).padStart(e*2,"0"))}function e0(t,e){return Re(t,e).reverse()}function nt(t,e,n){let r;if(typeof e=="string")try{r=aa(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(qs(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 Be(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];vr(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 pf(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}const gf=t=>typeof t=="bigint"&&df<=t;function yf(t,e,n){return gf(t)&&gf(e)&&gf(n)&&e<=t&&t<n}function Qi(t,e,n,r){if(!yf(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function js(t){let e;for(e=0;t>df;t>>=sa,e+=1);return e}function zv(t,e){return t>>BigInt(e)&sa}const wi=t=>(sa<<BigInt(t))-sa,bf=t=>new Uint8Array(t),t0=t=>Uint8Array.from(t);function Hv(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=bf(t),i=bf(t),s=0;const o=()=>{r.fill(1),i.fill(0),s=0},a=(...h)=>n(i,r,...h),c=(h=bf(0))=>{i=a(t0([0]),h),r=a(),h.length!==0&&(i=a(t0([1]),h),r=a())},f=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let h=0;const l=[];for(;h<e;){r=a();const d=r.slice();l.push(d),h+=r.length}return Be(...l)};return(h,l)=>{o(),c(h);let d;for(;!(d=l(f()));)c();return o(),d}}const Vv={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"||qs(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 zs(t,e,n={}){const r=(i,s,o)=>{const a=Vv[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 n0=()=>{throw new Error("not implemented")};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}}function Kv(t,e){if(c0(t)>e)throw new pE({givenSize:c0(t),maxSize:e})}const kn={zero:48,nine:57,A:65,F:70,a:97,f:102};function r0(t){if(t>=kn.zero&&t<=kn.nine)return t-kn.zero;if(t>=kn.A&&t<=kn.F)return t-(kn.A-10);if(t>=kn.a&&t<=kn.f)return t-(kn.a-10)}function Gv(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 mf(t,e){if(Mn(t)>e)throw new iE({givenSize:Mn(t),maxSize:e})}function Zv(t,e){if(typeof e=="number"&&e>0&&e>Mn(t)-1)throw new a0({offset:e,position:"start",size:Mn(t)})}function Wv(t,e,n){if(typeof e=="number"&&typeof n=="number"&&Mn(t)!==n-e)throw new a0({offset:n,position:"end",size:Mn(t)})}function i0(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 sE({size:Math.ceil(i.length/2),targetSize:r,type:"Hex"});return`0x${i[n==="right"?"padEnd":"padStart"](r*2,"0")}`}const Yv="#__bigint";function vf(t,e,n){return JSON.stringify(t,(r,i)=>typeof e=="function"?e(r,i):typeof i=="bigint"?i.toString()+Yv:i,n)}const Xv=new TextEncoder,Jv=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Qv(t,e={}){const{strict:n=!1}=e;if(!t)throw new s0(t);if(typeof t!="string")throw new s0(t);if(n&&!/^0x[0-9a-fA-F]*$/.test(t))throw new o0(t);if(!t.startsWith("0x"))throw new o0(t)}function Ef(...t){return`0x${t.reduce((e,n)=>e+n.replace("0x",""),"")}`}function xf(t){return t instanceof Uint8Array?Hs(t):Array.isArray(t)?Hs(new Uint8Array(t)):t}function eE(t,e={}){const n=`0x${Number(t)}`;return typeof e.size=="number"?(mf(n,e.size),fa(n,e.size)):n}function Hs(t,e={}){let n="";for(let i=0;i<t.length;i++)n+=Jv[t[i]];const r=`0x${n}`;return typeof e.size=="number"?(mf(r,e.size),_f(r,e.size)):r}function ca(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 rE({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?fa(c,r):c}function tE(t,e={}){return Hs(Xv.encode(t),e)}function fa(t,e){return i0(t,{dir:"left",size:e})}function _f(t,e){return i0(t,{dir:"right",size:e})}function qn(t,e,n,r={}){const{strict:i}=r;Zv(t,e);const s=`0x${t.replace("0x","").slice((e??0)*2,(n??t.length)*2)}`;return i&&Wv(s,e,n),s}function Mn(t){return Math.ceil((t.length-2)/2)}function nE(t,e={}){const{strict:n=!1}=e;try{return Qv(t,{strict:n}),!0}catch{return!1}}class rE extends me{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 s0 extends me{constructor(e){super(`Value \`${typeof e=="object"?vf(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 o0 extends me{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 iE extends me{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 a0 extends me{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 sE extends me{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 oE=new TextEncoder;function aE(t){if(!(t instanceof Uint8Array)){if(!t)throw new ua(t);if(typeof t!="object")throw new ua(t);if(!("BYTES_PER_ELEMENT"in t))throw new ua(t);if(t.BYTES_PER_ELEMENT!==1||t.constructor.name!=="Uint8Array")throw new ua(t)}}function cE(t){return t instanceof Uint8Array?t:typeof t=="string"?uE(t):fE(t)}function fE(t){return t instanceof Uint8Array?t:new Uint8Array(t)}function uE(t,e={}){const{size:n}=e;let r=t;n&&(mf(t,n),r=_f(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=r0(i.charCodeAt(c++)),u=r0(i.charCodeAt(c++));if(f===void 0||u===void 0)throw new me(`Invalid byte sequence ("${i[c-2]}${i[c-1]}" in "${i}").`);o[a]=f*16+u}return o}function lE(t,e={}){const{size:n}=e,r=oE.encode(t);return typeof n=="number"?(Kv(r,n),hE(r,n)):r}function hE(t,e){return Gv(t,{dir:"right",size:e})}function c0(t){return t.length}function dE(t){try{return aE(t),!0}catch{return!1}}class ua extends me{constructor(e){super(`Value \`${typeof e=="object"?vf(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 pE extends me{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 me{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 f0(t,e={}){const{as:n=typeof t=="string"?"Hex":"Bytes"}=e,r=Nv(cE(t));return n==="Bytes"?r:Hs(r)}class yE 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 If={checksum:new yE(8192)}.checksum;function u0(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 h0({prefix:r,cause:new xE});return}if(n===!0||typeof i=="bigint"&&typeof s>"u"){if(r!==3&&r!==2)throw new h0({prefix:r,cause:new EE});return}throw new vE({publicKey:t})}function bE(t){const e=(()=>{if(nE(t))return l0(t);if(dE(t))return wE(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 u0(e),e}function wE(t){return l0(Hs(t))}function l0(t){if(t.length!==132&&t.length!==130&&t.length!==68)throw new _E({publicKey:t});if(t.length===130){const r=BigInt(qn(t,0,32)),i=BigInt(qn(t,32,64));return{prefix:4,x:r,y:i}}if(t.length===132){const r=Number(qn(t,0,1)),i=BigInt(qn(t,1,33)),s=BigInt(qn(t,33,65));return{prefix:r,x:i,y:s}}const e=Number(qn(t,0,1)),n=BigInt(qn(t,1,33));return{prefix:e,x:n}}function mE(t,e={}){u0(t);const{prefix:n,x:r,y:i}=t,{includePrefix:s=!0}=e;return Ef(s?ca(n,{size:1}):"0x",ca(r,{size:32}),typeof i=="bigint"?ca(i,{size:32}):"0x")}class vE extends me{constructor({publicKey:e}){super(`Value \`${vf(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 h0 extends me{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 EE extends me{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 xE extends me{constructor(){super("Prefix must be 4 for uncompressed public keys."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidUncompressedPrefixError"})}}class _E extends me{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 ${Mn(xf(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"PublicKey.InvalidSerializedSizeError"})}}const IE=/^0x[a-fA-F0-9]{40}$/;function Sf(t,e={}){const{strict:n=!0}=e;if(!IE.test(t))throw new p0({address:t,cause:new $E});if(n){if(t.toLowerCase()===t)return;if(d0(t)!==t)throw new p0({address:t,cause:new AE})}}function d0(t){if(If.has(t))return If.get(t);Sf(t,{strict:!1});const e=t.substring(2).toLowerCase(),n=f0(lE(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 If.set(t,i),i}function SE(t,e={}){const{checksum:n=!1}=e;return Sf(t),n?d0(t):t}function BE(t,e={}){const n=f0(`0x${mE(t).slice(4)}`).substring(26);return SE(`0x${n}`,e)}class p0 extends me{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 $E extends me{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 AE extends me{constructor(){super("Address does not match its checksum counterpart."),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Address.InvalidChecksumError"})}}const OE=/^(.*)\[([0-9]*)\]$/,DE=/^bytes([1-9]|1[0-9]|2[0-9]|3[0-2])?$/,PE=/^(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 Bf(t,e){if(t.length!==e.length)throw new TE({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(Bf.encode(i,s))}return Ef(...n)}(function(t){function e(n,r,i=!1){if(n==="address"){const c=r;return Sf(c),fa(c.toLowerCase(),i?32:0)}if(n==="string")return tE(r);if(n==="bytes")return r;if(n==="bool")return fa(eE(r),i?32:1);const s=n.match(PE);if(s){const[c,f,u="256"]=s,h=Number.parseInt(u,10)/8;return ca(r,{size:i?32:h,signed:f==="int"})}const o=n.match(DE);if(o){const[c,f]=o;if(Number.parseInt(f,10)!==(r.length-2)/2)throw new RE({expectedSize:Number.parseInt(f,10),value:r});return _f(r,i?32:0)}const a=n.match(OE);if(a&&Array.isArray(r)){const[c,f]=a,u=[];for(let h=0;h<r.length;h++)u.push(e(f,r[h],!0));return u.length===0?"0x":Ef(...u)}throw new NE(n)}t.encode=e})(Bf||(Bf={}));class RE extends me{constructor({expectedSize:e,value:n}){super(`Size of bytes "${n}" (bytes${Mn(n)}) does not match expected size (bytes${e}).`),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"AbiParameters.BytesSizeMismatchError"})}}class TE extends me{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 NE extends me{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 g0 extends lf{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,iv(e);const r=Qo(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),yr(s)}update(e){return Yi(this),this.iHash.update(e),this}digestInto(e){Yi(this),yi(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 y0=(t,e,n)=>new g0(t,e).update(n).digest();y0.create=(t,e)=>new g0(t,e);const _t=BigInt(0),gt=BigInt(1),mi=BigInt(2),UE=BigInt(3),b0=BigInt(4),w0=BigInt(5),m0=BigInt(8);function yt(t,e){const n=t%e;return n>=_t?n:e+n}function Kt(t,e,n){let r=t;for(;e-- >_t;)r*=r,r%=n;return r}function $f(t,e){if(t===_t)throw new Error("invert: expected non-zero number");if(e<=_t)throw new Error("invert: expected positive modulus, got "+e);let n=yt(t,e),r=e,i=_t,s=gt;for(;n!==_t;){const a=r/n,c=r%n,f=i-s*a;r=n,n=c,i=s,s=f}if(r!==gt)throw new Error("invert: does not exist");return yt(i,e)}function v0(t,e){const n=(t.ORDER+gt)/b0,r=t.pow(e,n);if(!t.eql(t.sqr(r),e))throw new Error("Cannot find square root");return r}function CE(t,e){const n=(t.ORDER-w0)/m0,r=t.mul(e,mi),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,mi),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 FE(t){if(t<BigInt(3))throw new Error("sqrt is not defined for small field");let e=t-gt,n=0;for(;e%mi===_t;)e/=mi,n++;let r=mi;const i=Er(t);for(;ha(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return v0;let s=i.pow(r,e);const o=(e+gt)/mi;return function(c,f){if(c.is0(f))return f;if(ha(c,f)!==1)throw new Error("Cannot find square root");let u=n,h=c.mul(c.ONE,s),l=c.pow(f,e),d=c.pow(f,o);for(;!c.eql(l,c.ONE);){if(c.is0(l))return c.ZERO;let p=1,b=c.sqr(l);for(;!c.eql(b,c.ONE);)if(p++,b=c.sqr(b),p===u)throw new Error("Cannot find square root");const v=gt<<BigInt(u-p-1),O=c.pow(h,v);u=p,h=c.sqr(O),l=c.mul(l,h),d=c.mul(d,O)}return d}}function LE(t){return t%b0===UE?v0:t%m0===w0?CE:FE(t)}const kE=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function E0(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=kE.reduce((r,i)=>(r[i]="function",r),e);return zs(t,n)}function la(t,e,n){if(n<_t)throw new Error("invalid exponent, negatives unsupported");if(n===_t)return t.ONE;if(n===gt)return e;let r=t.ONE,i=e;for(;n>_t;)n&gt&&(r=t.mul(r,i)),i=t.sqr(i),n>>=gt;return r}function vi(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 ha(t,e){const n=(t.ORDER-gt)/mi,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 x0(t,e){e!==void 0&&Ls(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Er(t,e,n=!1,r={}){if(t<=_t)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=x0(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:wi(i),ZERO:_t,ONE:gt,create:c=>yt(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return _t<=c&&c<t},is0:c=>c===_t,isOdd:c=>(c&gt)===gt,neg:c=>yt(-c,t),eql:(c,f)=>c===f,sqr:c=>yt(c*c,t),add:(c,f)=>yt(c+f,t),sub:(c,f)=>yt(c-f,t),mul:(c,f)=>yt(c*f,t),pow:(c,f)=>la(a,c,f),div:(c,f)=>yt(c*$f(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>$f(c,t),sqrt:r.sqrt||(c=>(o||(o=LE(t)),o(a,c))),toBytes:c=>n?e0(c,s):Re(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return n?Qd(c):pt(c)},invertBatch:c=>vi(a,c),cmov:(c,f,u)=>u?f:c});return Object.freeze(a)}function _0(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 Af(t){const e=_0(t);return e+Math.ceil(e/2)}function I0(t,e,n=!1){const r=t.length,i=_0(e),s=Af(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?Qd(t):pt(t),a=yt(o,e-gt)+gt;return n?e0(a,i):Re(a,i)}const S0=BigInt(0),Of=BigInt(1);function Df(t,e){const n=e.negate();return t?n:e}function B0(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function Pf(t,e){B0(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=wi(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function $0(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+=Of);const f=e*r,u=f+Math.abs(a)-1,h=a===0,l=a<0,d=e%2!==0;return{nextN:c,offset:u,isZero:h,isNeg:l,isNegF:d,offsetF:f}}function qE(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 ME(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 Rf=new WeakMap,A0=new WeakMap;function Tf(t){return A0.get(t)||1}function jE(t,e){return{constTimeNegate:Df,hasPrecomputes(n){return Tf(n)!==1},unsafeLadder(n,r,i=t.ZERO){let s=n;for(;r>S0;)r&Of&&(i=i.add(s)),s=s.double(),r>>=Of;return i},precomputeWindow(n,r){const{windows:i,windowSize:s}=Pf(r,e),o=[];let a=n,c=a;for(let f=0;f<i;f++){c=a,o.push(c);for(let u=1;u<s;u++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(n,r,i){let s=t.ZERO,o=t.BASE;const a=Pf(n,e);for(let c=0;c<a.windows;c++){const{nextN:f,offset:u,isZero:h,isNeg:l,isNegF:d,offsetF:p}=$0(i,c,a);i=f,h?o=o.add(Df(d,r[p])):s=s.add(Df(l,r[u]))}return{p:s,f:o}},wNAFUnsafe(n,r,i,s=t.ZERO){const o=Pf(n,e);for(let a=0;a<o.windows&&i!==S0;a++){const{nextN:c,offset:f,isZero:u,isNeg:h}=$0(i,a,o);if(i=c,!u){const l=r[f];s=s.add(h?l.negate():l)}}return s},getPrecomputes(n,r,i){let s=Rf.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&Rf.set(r,i(s))),s},wNAFCached(n,r,i){const s=Tf(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=Tf(n);return o===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,n,i),r,s)},setWindowSize(n,r){B0(r,e),A0.set(n,r),Rf.delete(n)}}}function zE(t,e,n,r){qE(n,t),ME(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=js(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=wi(c),u=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let l=o;for(let d=h;d>=0;d-=c){u.fill(o);for(let b=0;b<s;b++){const v=r[b],O=Number(v>>BigInt(d)&f);u[O]=u[O].add(n[b])}let p=o;for(let b=u.length-1,v=o;b>0;b--)v=v.add(u[b]),p=p.add(v);if(l=l.add(p),d!==0)for(let b=0;b<c;b++)l=l.double()}return l}function O0(t){return E0(t.Fp),zs(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...x0(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}function D0(t){t.lowS!==void 0&&Ms("lowS",t.lowS),t.prehash!==void 0&&Ms("prehash",t.prehash)}function HE(t){const e=O0(t);zs(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 VE extends Error{constructor(e=""){super(e)}}const jn={Err:VE,_tlv:{encode:(t,e)=>{const{Err:n}=jn;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=oa(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?oa(i.length/2|128):"";return oa(t)+s+i+e},decode(t,e){const{Err:n}=jn;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 u of f)o=o<<8|u;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}=jn;if(t<rn)throw new e("integer: negative integers are not allowed");let n=oa(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}=jn;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 pt(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=jn,i=nt("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:u}=r.decode(2,c);if(u.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}=jn,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 Nf(t,e){return bi(Re(t,e))}const rn=BigInt(0),ye=BigInt(1),xr=BigInt(2),Vs=BigInt(3),Uf=BigInt(4);function Cf(t){const e=HE(t),{Fp:n}=e,r=Er(e.n,e.nBitLength),i=e.toBytes||((x,S,R)=>{const U=S.toAffine();return Be(Uint8Array.from([4]),n.toBytes(U.x),n.toBytes(U.y))}),s=e.fromBytes||(x=>{const S=x.subarray(1),R=n.fromBytes(S.subarray(0,n.BYTES)),U=n.fromBytes(S.subarray(n.BYTES,2*n.BYTES));return{x:R,y:U}});function o(x){const{a:S,b:R}=e,U=n.sqr(x),L=n.mul(U,x);return n.add(n.add(L,n.mul(x,S)),R)}function a(x,S){const R=n.sqr(S),U=o(x);return n.eql(R,U)}if(!a(e.Gx,e.Gy))throw new Error("bad curve params: generator point");const c=n.mul(n.pow(e.a,Vs),Uf),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 u(x){return yf(x,ye,e.n)}function h(x){const{allowedPrivateKeyLengths:S,nByteLength:R,wrapPrivateKey:U,n:L}=e;if(S&&typeof x!="bigint"){if(qs(x)&&(x=bi(x)),typeof x!="string"||!S.includes(x.length))throw new Error("invalid private key");x=x.padStart(R*2,"0")}let C;try{C=typeof x=="bigint"?x:pt(nt("private key",x,R))}catch{throw new Error("invalid private key, expected hex or "+R+" bytes, got "+typeof x)}return U&&(C=yt(C,L)),Qi("private key",C,ye,L),C}function l(x){if(!(x instanceof b))throw new Error("ProjectivePoint expected")}const d=wf((x,S)=>{const{px:R,py:U,pz:L}=x;if(n.eql(L,n.ONE))return{x:R,y:U};const C=x.is0();S==null&&(S=C?n.ONE:n.inv(L));const A=n.mul(R,S),j=n.mul(U,S),q=n.mul(L,S);if(C)return{x:n.ZERO,y:n.ZERO};if(!n.eql(q,n.ONE))throw new Error("invZ was invalid");return{x:A,y:j}}),p=wf(x=>{if(x.is0()){if(e.allowInfinityPoint&&!n.is0(x.py))return;throw new Error("bad point: ZERO")}const{x:S,y:R}=x.toAffine();if(!n.isValid(S)||!n.isValid(R))throw new Error("bad point: x or y not FE");if(!a(S,R))throw new Error("bad point: equation left != right");if(!x.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});class b{constructor(S,R,U){if(S==null||!n.isValid(S))throw new Error("x required");if(R==null||!n.isValid(R)||n.is0(R))throw new Error("y required");if(U==null||!n.isValid(U))throw new Error("z required");this.px=S,this.py=R,this.pz=U,Object.freeze(this)}static fromAffine(S){const{x:R,y:U}=S||{};if(!S||!n.isValid(R)||!n.isValid(U))throw new Error("invalid affine point");if(S instanceof b)throw new Error("projective point not allowed");const L=C=>n.eql(C,n.ZERO);return L(R)&&L(U)?b.ZERO:new b(R,U,n.ONE)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static normalizeZ(S){const R=vi(n,S.map(U=>U.pz));return S.map((U,L)=>U.toAffine(R[L])).map(b.fromAffine)}static fromHex(S){const R=b.fromAffine(s(nt("pointHex",S)));return R.assertValidity(),R}static fromPrivateKey(S){return b.BASE.multiply(h(S))}static msm(S,R){return zE(b,r,S,R)}_setWindowSize(S){P.setWindowSize(this,S)}assertValidity(){p(this)}hasEvenY(){const{y:S}=this.toAffine();if(n.isOdd)return!n.isOdd(S);throw new Error("Field doesn't support isOdd")}equals(S){l(S);const{px:R,py:U,pz:L}=this,{px:C,py:A,pz:j}=S,q=n.eql(n.mul(R,j),n.mul(C,L)),E=n.eql(n.mul(U,j),n.mul(A,L));return q&&E}negate(){return new b(this.px,n.neg(this.py),this.pz)}double(){const{a:S,b:R}=e,U=n.mul(R,Vs),{px:L,py:C,pz:A}=this;let j=n.ZERO,q=n.ZERO,E=n.ZERO,y=n.mul(L,L),w=n.mul(C,C),g=n.mul(A,A),m=n.mul(L,C);return m=n.add(m,m),E=n.mul(L,A),E=n.add(E,E),j=n.mul(S,E),q=n.mul(U,g),q=n.add(j,q),j=n.sub(w,q),q=n.add(w,q),q=n.mul(j,q),j=n.mul(m,j),E=n.mul(U,E),g=n.mul(S,g),m=n.sub(y,g),m=n.mul(S,m),m=n.add(m,E),E=n.add(y,y),y=n.add(E,y),y=n.add(y,g),y=n.mul(y,m),q=n.add(q,y),g=n.mul(C,A),g=n.add(g,g),y=n.mul(g,m),j=n.sub(j,y),E=n.mul(g,w),E=n.add(E,E),E=n.add(E,E),new b(j,q,E)}add(S){l(S);const{px:R,py:U,pz:L}=this,{px:C,py:A,pz:j}=S;let q=n.ZERO,E=n.ZERO,y=n.ZERO;const w=e.a,g=n.mul(e.b,Vs);let m=n.mul(R,C),_=n.mul(U,A),B=n.mul(L,j),I=n.add(R,U),$=n.add(C,A);I=n.mul(I,$),$=n.add(m,_),I=n.sub(I,$),$=n.add(R,L);let D=n.add(C,j);return $=n.mul($,D),D=n.add(m,B),$=n.sub($,D),D=n.add(U,L),q=n.add(A,j),D=n.mul(D,q),q=n.add(_,B),D=n.sub(D,q),y=n.mul(w,$),q=n.mul(g,B),y=n.add(q,y),q=n.sub(_,y),y=n.add(_,y),E=n.mul(q,y),_=n.add(m,m),_=n.add(_,m),B=n.mul(w,B),$=n.mul(g,$),_=n.add(_,B),B=n.sub(m,B),B=n.mul(w,B),$=n.add($,B),m=n.mul(_,$),E=n.add(E,m),m=n.mul(D,$),q=n.mul(I,q),q=n.sub(q,m),m=n.mul(I,_),y=n.mul(D,y),y=n.add(y,m),new b(q,E,y)}subtract(S){return this.add(S.negate())}is0(){return this.equals(b.ZERO)}wNAF(S){return P.wNAFCached(this,S,b.normalizeZ)}multiplyUnsafe(S){const{endo:R,n:U}=e;Qi("scalar",S,rn,U);const L=b.ZERO;if(S===rn)return L;if(this.is0()||S===ye)return this;if(!R||P.hasPrecomputes(this))return P.wNAFCachedUnsafe(this,S,b.normalizeZ);let{k1neg:C,k1:A,k2neg:j,k2:q}=R.splitScalar(S),E=L,y=L,w=this;for(;A>rn||q>rn;)A&ye&&(E=E.add(w)),q&ye&&(y=y.add(w)),w=w.double(),A>>=ye,q>>=ye;return C&&(E=E.negate()),j&&(y=y.negate()),y=new b(n.mul(y.px,R.beta),y.py,y.pz),E.add(y)}multiply(S){const{endo:R,n:U}=e;Qi("scalar",S,ye,U);let L,C;if(R){const{k1neg:A,k1:j,k2neg:q,k2:E}=R.splitScalar(S);let{p:y,f:w}=this.wNAF(j),{p:g,f:m}=this.wNAF(E);y=P.constTimeNegate(A,y),g=P.constTimeNegate(q,g),g=new b(n.mul(g.px,R.beta),g.py,g.pz),L=y.add(g),C=w.add(m)}else{const{p:A,f:j}=this.wNAF(S);L=A,C=j}return b.normalizeZ([L,C])[0]}multiplyAndAddUnsafe(S,R,U){const L=b.BASE,C=(j,q)=>q===rn||q===ye||!j.equals(L)?j.multiplyUnsafe(q):j.multiply(q),A=C(this,R).add(C(S,U));return A.is0()?void 0:A}toAffine(S){return d(this,S)}isTorsionFree(){const{h:S,isTorsionFree:R}=e;if(S===ye)return!0;if(R)return R(b,this);throw new Error("isTorsionFree() has not been declared for the elliptic curve")}clearCofactor(){const{h:S,clearCofactor:R}=e;return S===ye?this:R?R(b,this):this.multiplyUnsafe(e.h)}toRawBytes(S=!0){return Ms("isCompressed",S),this.assertValidity(),i(b,this,S)}toHex(S=!0){return Ms("isCompressed",S),bi(this.toRawBytes(S))}}b.BASE=new b(e.Gx,e.Gy,n.ONE),b.ZERO=new b(n.ZERO,n.ONE,n.ZERO);const{endo:v,nBitLength:O}=e,P=jE(b,v?Math.ceil(O/2):O);return{CURVE:e,ProjectivePoint:b,normPrivateKeyToScalar:h,weierstrassEquation:o,isWithinCurveOrder:u}}function KE(t){const e=O0(t);return zs(e,{hash:"hash",hmac:"function",randomBytes:"function"},{bits2int:"function",bits2int_modN:"function",lowS:"boolean"}),Object.freeze({lowS:!0,...e})}function GE(t){const e=KE(t),{Fp:n,n:r,nByteLength:i,nBitLength:s}=e,o=n.BYTES+1,a=2*n.BYTES+1;function c(g){return yt(g,r)}function f(g){return $f(g,r)}const{ProjectivePoint:u,normPrivateKeyToScalar:h,weierstrassEquation:l,isWithinCurveOrder:d}=Cf({...e,toBytes(g,m,_){const B=m.toAffine(),I=n.toBytes(B.x),$=Be;return Ms("isCompressed",_),_?$(Uint8Array.from([m.hasEvenY()?2:3]),I):$(Uint8Array.from([4]),I,n.toBytes(B.y))},fromBytes(g){const m=g.length,_=g[0],B=g.subarray(1);if(m===o&&(_===2||_===3)){const I=pt(B);if(!yf(I,ye,n.ORDER))throw new Error("Point is not on curve");const $=l(I);let D;try{D=n.sqrt($)}catch(k){const N=k instanceof Error?": "+k.message:"";throw new Error("Point is not on curve"+N)}const T=(D&ye)===ye;return(_&1)===1!==T&&(D=n.neg(D)),{x:I,y:D}}else if(m===a&&_===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 "+m)}}});function p(g){const m=r>>ye;return g>m}function b(g){return p(g)?c(-g):g}const v=(g,m,_)=>pt(g.slice(m,_));class O{constructor(m,_,B){Qi("r",m,ye,r),Qi("s",_,ye,r),this.r=m,this.s=_,B!=null&&(this.recovery=B),Object.freeze(this)}static fromCompact(m){const _=i;return m=nt("compactSignature",m,_*2),new O(v(m,0,_),v(m,_,2*_))}static fromDER(m){const{r:_,s:B}=jn.toSig(nt("DER",m));return new O(_,B)}assertValidity(){}addRecoveryBit(m){return new O(this.r,this.s,m)}recoverPublicKey(m){const{r:_,s:B,recovery:I}=this,$=L(nt("msgHash",m));if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");const D=I===2||I===3?_+e.n:_;if(D>=n.ORDER)throw new Error("recovery id 2 or 3 invalid");const T=(I&1)===0?"02":"03",F=u.fromHex(T+Nf(D,n.BYTES)),k=f(D),N=c(-$*k),M=c(B*k),z=u.BASE.multiplyAndAddUnsafe(F,N,M);if(!z)throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return p(this.s)}normalizeS(){return this.hasHighS()?new O(this.r,c(-this.s),this.recovery):this}toDERRawBytes(){return aa(this.toDERHex())}toDERHex(){return jn.hexFromSig(this)}toCompactRawBytes(){return aa(this.toCompactHex())}toCompactHex(){const m=i;return Nf(this.r,m)+Nf(this.s,m)}}const P={isValidPrivateKey(g){try{return h(g),!0}catch{return!1}},normPrivateKeyToScalar:h,randomPrivateKey:()=>{const g=Af(e.n);return I0(e.randomBytes(g),e.n)},precompute(g=8,m=u.BASE){return m._setWindowSize(g),m.multiply(BigInt(3)),m}};function x(g,m=!0){return u.fromPrivateKey(g).toRawBytes(m)}function S(g){if(typeof g=="bigint")return!1;if(g instanceof u)return!0;const _=nt("key",g).length,B=n.BYTES,I=B+1,$=2*B+1;if(!(e.allowedPrivateKeyLengths||i===I))return _===I||_===$}function R(g,m,_=!0){if(S(g)===!0)throw new Error("first arg must be private key");if(S(m)===!1)throw new Error("second arg must be public key");return u.fromHex(m).multiply(h(g)).toRawBytes(_)}const U=e.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");const m=pt(g),_=g.length*8-s;return _>0?m>>BigInt(_):m},L=e.bits2int_modN||function(g){return c(U(g))},C=wi(s);function A(g){return Qi("num < 2^"+s,g,rn,C),Re(g,i)}function j(g,m,_=q){if(["recovered","canonical"].some(H=>H in _))throw new Error("sign() legacy options not supported");const{hash:B,randomBytes:I}=e;let{lowS:$,prehash:D,extraEntropy:T}=_;$==null&&($=!0),g=nt("msgHash",g),D0(_),D&&(g=nt("prehashed msgHash",B(g)));const F=L(g),k=h(m),N=[A(k),A(F)];if(T!=null&&T!==!1){const H=T===!0?I(n.BYTES):T;N.push(nt("extraEntropy",H))}const M=Be(...N),z=F;function K(H){const G=U(H);if(!d(G))return;const ee=f(G),te=u.BASE.multiply(G).toAffine(),re=c(te.x);if(re===rn)return;const ce=c(ee*c(z+re*k));if(ce===rn)return;let Ie=(te.x===re?0:2)|Number(te.y&ye),lr=ce;return $&&p(ce)&&(lr=b(ce),Ie^=1),new O(re,lr,Ie)}return{seed:M,k2sig:K}}const q={lowS:e.lowS,prehash:!1},E={lowS:e.lowS,prehash:!1};function y(g,m,_=q){const{seed:B,k2sig:I}=j(g,m,_),$=e;return Hv($.hash.outputLen,$.nByteLength,$.hmac)(B,I)}u.BASE._setWindowSize(8);function w(g,m,_,B=E){const I=g;m=nt("msgHash",m),_=nt("publicKey",_);const{lowS:$,prehash:D,format:T}=B;if(D0(B),"strict"in B)throw new Error("options.strict was renamed to lowS");if(T!==void 0&&T!=="compact"&&T!=="der")throw new Error("format must be compact or der");const F=typeof I=="string"||qs(I),k=!F&&!T&&typeof I=="object"&&I!==null&&typeof I.r=="bigint"&&typeof I.s=="bigint";if(!F&&!k)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");let N,M;try{if(k&&(N=new O(I.r,I.s)),F){try{T!=="compact"&&(N=O.fromDER(I))}catch(Ie){if(!(Ie instanceof jn.Err))throw Ie}!N&&T!=="der"&&(N=O.fromCompact(I))}M=u.fromHex(_)}catch{return!1}if(!N||$&&N.hasHighS())return!1;D&&(m=e.hash(m));const{r:z,s:K}=N,H=L(m),G=f(K),ee=c(H*G),te=c(z*G),re=u.BASE.multiplyAndAddUnsafe(M,ee,te)?.toAffine();return re?c(re.x)===z:!1}return{CURVE:e,getPublicKey:x,getSharedSecret:R,sign:y,verify:w,ProjectivePoint:u,Signature:O,utils:P}}function ZE(t,e){const n=t.ORDER;let r=rn;for(let p=n-ye;p%xr===rn;p/=xr)r+=ye;const i=r,s=xr<<i-ye-ye,o=s*xr,a=(n-ye)/o,c=(a-ye)/xr,f=o-ye,u=s,h=t.pow(e,a),l=t.pow(e,(a+ye)/xr);let d=(p,b)=>{let v=h,O=t.pow(b,f),P=t.sqr(O);P=t.mul(P,b);let x=t.mul(p,P);x=t.pow(x,c),x=t.mul(x,O),O=t.mul(x,b),P=t.mul(x,p);let S=t.mul(P,O);x=t.pow(S,u);let R=t.eql(x,t.ONE);O=t.mul(P,l),x=t.mul(S,v),P=t.cmov(O,P,R),S=t.cmov(x,S,R);for(let U=i;U>ye;U--){let L=U-xr;L=xr<<L-ye;let C=t.pow(S,L);const A=t.eql(C,t.ONE);O=t.mul(P,v),v=t.mul(v,v),C=t.mul(S,v),P=t.cmov(O,P,A),S=t.cmov(C,S,A)}return{isValid:R,value:P}};if(t.ORDER%Uf===Vs){const p=(t.ORDER-Vs)/Uf,b=t.sqrt(t.neg(e));d=(v,O)=>{let P=t.sqr(O);const x=t.mul(v,O);P=t.mul(P,x);let S=t.pow(P,p);S=t.mul(S,x);const R=t.mul(S,b),U=t.mul(t.sqr(S),O),L=t.eql(U,v);let C=t.cmov(R,S,L);return{isValid:L,value:C}}}return d}function P0(t,e){if(E0(t),!t.isValid(e.A)||!t.isValid(e.B)||!t.isValid(e.Z))throw new Error("mapToCurveSimpleSWU: invalid opts");const n=ZE(t,e.Z);if(!t.isOdd)throw new Error("Fp.isOdd is not implemented!");return r=>{let i,s,o,a,c,f,u,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),u=t.mul(i,o);const{isValid:l,value:d}=n(s,f);h=t.mul(i,r),h=t.mul(h,d),u=t.cmov(u,o,l),h=t.cmov(h,d,l);const p=t.isOdd(r)===t.isOdd(h);h=t.cmov(t.neg(h),h,p);const b=vi(t,[a],!0)[0];return u=t.mul(u,b),{x:u,y:h}}}function WE(t){return{hash:t,hmac:(e,...n)=>y0(t,e,uv(...n)),randomBytes:Cd}}function da(t,e){const n=r=>GE({...t,...WE(r)});return{...n(e),create:n}}const YE=pt;function _r(t,e){if(Ks(t),Ks(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 XE(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 Ks(t){if(!Number.isSafeInteger(t))throw new Error("number expected")}function JE(t,e,n,r){vr(t),vr(e),Ks(n),e.length>255&&(e=r(Be(pf("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=Be(e,_r(e.length,1)),c=_r(0,s),f=_r(n,2),u=new Array(o),h=r(Be(c,t,f,_r(0,1),a));u[0]=r(Be(h,_r(1,1),a));for(let d=1;d<=o;d++){const p=[XE(h,u[d-1]),_r(d+1,1),a];u[d]=r(Be(...p))}return Be(...u).slice(0,n)}function QE(t,e,n,r,i){if(vr(t),vr(e),Ks(n),e.length>255){const s=Math.ceil(2*r/8);e=i.create({dkLen:s}).update(pf("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(_r(n,2)).update(e).update(_r(e.length,1)).digest()}function R0(t,e,n){zs(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;vr(t),Ks(e);const f=typeof c=="string"?pf(c):c,u=r.toString(2).length,h=Math.ceil((u+i)/8),l=e*s*h;let d;if(a==="xmd")d=JE(t,f,l,o);else if(a==="xof")d=QE(t,f,l,i,o);else if(a==="_internal_pass")d=t;else throw new Error('expand must be "xmd" or "xof"');const p=new Array(e);for(let b=0;b<e;b++){const v=new Array(s);for(let O=0;O<s;O++){const P=h*(O+b*s),x=d.subarray(P,P+h);v[O]=yt(YE(x),r)}p[b]=v}return p}function T0(t,e){const n=e.map(r=>Array.from(r).reverse());return(r,i)=>{const[s,o,a,c]=n.map(h=>h.reduce((l,d)=>t.add(t.mul(l,r),d))),[f,u]=vi(t,[o,c],!0);return r=t.mul(s,f),i=t.mul(i,t.mul(a,u)),{x:r,y:i}}}function N0(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=R0(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=R0(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 U0=BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),C0=BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),e8=BigInt(0),t8=BigInt(1),Ff=BigInt(2),F0=(t,e)=>(t+e/Ff)/e;function n8(t){const e=U0,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,u=f*f*t%e,h=Kt(u,n,e)*u%e,l=Kt(h,n,e)*u%e,d=Kt(l,Ff,e)*f%e,p=Kt(d,i,e)*d%e,b=Kt(p,s,e)*p%e,v=Kt(b,a,e)*b%e,O=Kt(v,c,e)*v%e,P=Kt(O,a,e)*b%e,x=Kt(P,n,e)*u%e,S=Kt(x,o,e)*p%e,R=Kt(S,r,e)*f%e,U=Kt(R,Ff,e);if(!Lf.eql(Lf.sqr(U),t))throw new Error("Cannot find square root");return U}const Lf=Er(U0,void 0,void 0,{sqrt:n8}),r8=da({a:e8,b:BigInt(7),Fp:Lf,n:C0,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),h:BigInt(1),lowS:!0,endo:{beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar:t=>{const e=C0,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-t8*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,o=BigInt("0x100000000000000000000000000000000"),a=F0(s*t,e),c=F0(-r*t,e);let f=yt(t-a*n-c*i,e),u=yt(-a*r-c*s,e);const h=f>o,l=u>o;if(h&&(f=e-f),l&&(u=e-u),f>o||u>o)throw new Error("splitScalar: Endomorphism failed, k="+t);return{k1neg:h,k1:f,k2neg:l,k2:u}}}},ia);function i8(t){if(t.length!==130&&t.length!==132)throw new o8({signature:t});const e=BigInt(qn(t,0,32)),n=BigInt(qn(t,32,64)),r=(()=>{const i=+`0x${t.slice(130)}`;if(!Number.isNaN(i))try{return s8(i)}catch{throw new a8({value:i})}})();return typeof r>"u"?{r:e,s:n}:{r:e,s:n,yParity:r}}function s8(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 c8({value:t})}class o8 extends me{constructor({signature:e}){super(`Value \`${e}\` is an invalid signature size.`,{metaMessages:["Expected: 64 bytes or 65 bytes.",`Received ${Mn(xf(e))} bytes.`]}),Object.defineProperty(this,"name",{enumerable:!0,configurable:!0,writable:!0,value:"Signature.InvalidSerializedSizeError"})}}class a8 extends me{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 c8 extends me{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]))},Cn.slice();const f8=BigInt(0),pa=BigInt(1),L0=BigInt(2),es=BigInt(3);function u8(t){const e=[];for(;t>pa;t>>=pa)(t&pa)===f8?e.unshift(0):(t&es)===es?(e.unshift(-1),t+=pa):e.unshift(1);return e}function l8(t){const{Fp:e,Fr:n,Fp2:r,Fp6:i,Fp12:s}=t.fields,o=t.params.xNegative,a=t.params.twistType,c=Cf({n:n.ORDER,...t.G1}),f=Object.assign(c,N0(c.ProjectivePoint,t.G1.mapToCurve,{...t.htfDefaults,...t.G1.htfDefaults})),u=Cf({n:n.ORDER,...t.G2}),h=Object.assign(u,N0(u.ProjectivePoint,t.G2.mapToCurve,{...t.htfDefaults,...t.G2.htfDefaults}));let l;if(a==="multiplicative")l=(F,k,N,M,z,K)=>s.mul014(M,F,r.mul(k,z),r.mul(N,K));else if(a==="divisive")l=(F,k,N,M,z,K)=>s.mul034(M,r.mul(N,K),r.mul(k,z),F);else throw new Error("bls: unknown twist type");const d=r.div(r.ONE,r.mul(r.ONE,L0));function p(F,k,N,M){const z=r.sqr(N),K=r.sqr(M),H=r.mulByB(r.mul(K,es)),G=r.mul(H,es),ee=r.sub(r.sub(r.sqr(r.add(N,M)),K),z),te=r.sub(H,z),re=r.mul(r.sqr(k),es),ce=r.neg(ee);return F.push([te,re,ce]),k=r.mul(r.mul(r.mul(r.sub(z,G),k),N),d),N=r.sub(r.sqr(r.mul(r.add(z,G),d)),r.mul(r.sqr(H),es)),M=r.mul(z,ee),{Rx:k,Ry:N,Rz:M}}function b(F,k,N,M,z,K){const H=r.sub(N,r.mul(K,M)),G=r.sub(k,r.mul(z,M)),ee=r.sub(r.mul(H,z),r.mul(G,K)),te=r.neg(H),re=G;F.push([ee,te,re]);const ce=r.sqr(G),Ie=r.mul(ce,G),lr=r.mul(ce,k),Gc=r.add(r.sub(Ie,r.mul(lr,L0)),r.mul(r.sqr(H),M));return k=r.mul(G,Gc),N=r.sub(r.mul(r.sub(lr,Gc),H),r.mul(Ie,N)),M=r.mul(M,Ie),{Rx:k,Ry:N,Rz:M}}const v=u8(t.params.ateLoopSize),O=wf(F=>{const k=F,{x:N,y:M}=k.toAffine(),z=N,K=M,H=r.neg(M);let G=z,ee=K,te=r.ONE;const re=[];for(const ce of v){const Ie=[];({Rx:G,Ry:ee,Rz:te}=p(Ie,G,ee,te)),ce&&({Rx:G,Ry:ee,Rz:te}=b(Ie,G,ee,te,z,ce===-1?H:K)),re.push(Ie)}if(t.postPrecompute){const ce=re[re.length-1];t.postPrecompute(G,ee,te,z,K,b.bind(null,ce))}return re});function P(F,k=!1){let N=s.ONE;if(F.length){const M=F[0][0].length;for(let z=0;z<M;z++){N=s.sqr(N);for(const[K,H,G]of F)for(const[ee,te,re]of K[z])N=l(ee,te,re,N,H,G)}}return o&&(N=s.conjugate(N)),k?s.finalExponentiate(N):N}function x(F,k=!0){const N=[];f.ProjectivePoint.normalizeZ(F.map(({g1:M})=>M)),h.ProjectivePoint.normalizeZ(F.map(({g2:M})=>M));for(const{g1:M,g2:z}of F){if(M.equals(f.ProjectivePoint.ZERO)||z.equals(h.ProjectivePoint.ZERO))throw new Error("pairing is not available for ZERO point");M.assertValidity(),z.assertValidity();const K=M.toAffine();N.push([O(z),K.x,K.y])}return P(N,k)}function S(F,k,N=!0){return x([{g1:F,g2:k}],N)}const R={randomPrivateKey:()=>{const F=Af(n.ORDER);return I0(t.randomBytes(F),n.ORDER)},calcPairingPrecomputes:O},{ShortSignature:U}=t.G1,{Signature:L}=t.G2;function C(F){return F instanceof f.ProjectivePoint?F:f.ProjectivePoint.fromHex(F)}function A(F,k){return F instanceof f.ProjectivePoint?F:f.hashToCurve(nt("point",F),k)}function j(F){return F instanceof h.ProjectivePoint?F:L.fromHex(F)}function q(F,k){return F instanceof h.ProjectivePoint?F:h.hashToCurve(nt("point",F),k)}function E(F){return f.ProjectivePoint.fromPrivateKey(F).toRawBytes(!0)}function y(F){return h.ProjectivePoint.fromPrivateKey(F).toRawBytes(!0)}function w(F,k,N){const M=q(F,N);M.assertValidity();const z=M.multiply(f.normPrivateKeyToScalar(k));return F instanceof h.ProjectivePoint?z:L.toRawBytes(z)}function g(F,k,N){const M=A(F,N);M.assertValidity();const z=M.multiply(f.normPrivateKeyToScalar(k));return F instanceof f.ProjectivePoint?z:U.toRawBytes(z)}function m(F,k,N,M){const z=C(N),K=q(k,M),H=f.ProjectivePoint.BASE,G=j(F),ee=x([{g1:z.negate(),g2:K},{g1:H,g2:G}]);return s.eql(ee,s.ONE)}function _(F,k,N,M){const z=j(N),K=A(k,M),H=h.ProjectivePoint.BASE,G=C(F),ee=x([{g1:K,g2:z},{g1:G,g2:H.negate()}]);return s.eql(ee,s.ONE)}function B(F){if(!Array.isArray(F)||F.length===0)throw new Error("expected non-empty array")}function I(F){B(F);const N=F.map(C).reduce((M,z)=>M.add(z),f.ProjectivePoint.ZERO);return F[0]instanceof f.ProjectivePoint?(N.assertValidity(),N):N.toRawBytes(!0)}function $(F){B(F);const N=F.map(j).reduce((M,z)=>M.add(z),h.ProjectivePoint.ZERO);return F[0]instanceof h.ProjectivePoint?(N.assertValidity(),N):L.toRawBytes(N)}function D(F){B(F);const N=F.map(C).reduce((M,z)=>M.add(z),f.ProjectivePoint.ZERO);return F[0]instanceof f.ProjectivePoint?(N.assertValidity(),N):U.toRawBytes(N)}function T(F,k,N,M){if(B(k),N.length!==k.length)throw new Error("amount of public keys and messages should be equal");const z=j(F),K=k.map(te=>q(te,M)),H=N.map(C),G=new Map;for(let te=0;te<H.length;te++){const re=H[te],ce=K[te];let Ie=G.get(ce);Ie===void 0&&(Ie=[],G.set(ce,Ie)),Ie.push(re)}const ee=[];try{for(const[te,re]of G){const ce=re.reduce((Ie,lr)=>Ie.add(lr));ee.push({g1:ce,g2:te})}return ee.push({g1:f.ProjectivePoint.BASE.negate(),g2:z}),s.eql(x(ee),s.ONE)}catch{return!1}}return f.ProjectivePoint.BASE._setWindowSize(4),{getPublicKey:E,getPublicKeyForShortSignatures:y,sign:w,signShortSignature:g,verify:m,verifyBatch:T,verifyShortSignature:_,aggregatePublicKeys:I,aggregateSignatures:$,aggregateShortSignatures:D,millerLoopBatch:P,pairing:S,pairingBatch:x,G1:f,G2:h,Signature:L,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:R}}const h8=BigInt(0),ts=BigInt(1),zn=BigInt(2),k0=BigInt(3);function kf(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 u=BigInt(f+1),h=[];for(let l=0,d=ts;l<r;l++){const p=(u*d-u)/o%a;h.push(t.pow(e,p)),d*=n}c.push(h)}return c}function d8(t,e,n){const r=e.pow(n,(t.ORDER-ts)/k0),i=e.pow(n,(t.ORDER-ts)/zn);function s(l,d){const p=e.mul(e.frobeniusMap(l,1),r),b=e.mul(e.frobeniusMap(d,1),i);return[p,b]}const o=e.pow(n,(t.ORDER**zn-ts)/k0),a=e.pow(n,(t.ORDER**zn-ts)/zn);if(!e.eql(a,e.neg(e.ONE)))throw new Error("psiFrobenius: PSI2_Y!==-1");function c(l,d){return[e.mul(l,o),e.neg(d)]}const f=l=>(d,p)=>{const b=p.toAffine(),v=l(b.x,b.y);return d.fromAffine({x:v[0],y:v[1]})},u=f(s),h=f(c);return{psi:s,psi2:c,G2psi:u,G2psi2:h,PSI_X:r,PSI_Y:i,PSI2_X:o,PSI2_Y:a}}function p8(t){const{ORDER:e}=t,n=Er(e),r=n.create(t.NONRESIDUE||BigInt(-1)),i=n.div(n.ONE,zn),s=kf(n,r,n.ORDER,2)[0],o=({c0:E,c1:y},{c0:w,c1:g})=>({c0:n.add(E,w),c1:n.add(y,g)}),a=({c0:E,c1:y},{c0:w,c1:g})=>({c0:n.sub(E,w),c1:n.sub(y,g)}),c=({c0:E,c1:y},w)=>{if(typeof w=="bigint")return{c0:n.mul(E,w),c1:n.mul(y,w)};const{c0:g,c1:m}=w;let _=n.mul(E,g),B=n.mul(y,m);const I=n.sub(_,B),$=n.sub(n.mul(n.add(E,y),n.add(g,m)),n.add(_,B));return{c0:I,c1:$}},f=({c0:E,c1:y})=>{const w=n.add(E,y),g=n.sub(E,y),m=n.add(E,E);return{c0:n.mul(w,g),c1:n.mul(m,y)}},u=E=>{if(E.length!==2)throw new Error("invalid tuple");const y=E.map(w=>n.create(w));return{c0:y[0],c1:y[1]}},h=e*e,l=u(t.FP2_NONRESIDUE),d={ORDER:h,isLE:n.isLE,NONRESIDUE:l,BITS:js(h),BYTES:Math.ceil(js(h)/8),MASK:wi(js(h)),ZERO:{c0:n.ZERO,c1:n.ZERO},ONE:{c0:n.ONE,c1:n.ZERO},create:E=>E,isValid:({c0:E,c1:y})=>typeof E=="bigint"&&typeof y=="bigint",is0:({c0:E,c1:y})=>n.is0(E)&&n.is0(y),eql:({c0:E,c1:y},{c0:w,c1:g})=>n.eql(E,w)&&n.eql(y,g),neg:({c0:E,c1:y})=>({c0:n.neg(E),c1:n.neg(y)}),pow:(E,y)=>la(d,E,y),invertBatch:E=>vi(d,E),add:o,sub:a,mul:c,sqr:f,addN:o,subN:a,mulN:c,sqrN:f,div:(E,y)=>d.mul(E,typeof y=="bigint"?n.inv(n.create(y)):d.inv(y)),inv:({c0:E,c1:y})=>{const w=n.inv(n.create(E*E+y*y));return{c0:n.mul(w,n.create(E)),c1:n.mul(w,n.create(-y))}},sqrt:E=>{if(t.Fp2sqrt)return t.Fp2sqrt(E);const{c0:y,c1:w}=E;if(n.is0(w))return ha(n,y)===1?d.create({c0:n.sqrt(y),c1:n.ZERO}):d.create({c0:n.ZERO,c1:n.sqrt(n.div(y,r))});const g=n.sqrt(n.sub(n.sqr(y),n.mul(n.sqr(w),r)));let m=n.mul(n.add(g,y),i);ha(n,m)===-1&&(m=n.sub(m,g));const B=n.sqrt(m),I=d.create({c0:B,c1:n.div(n.mul(w,i),B)});if(!d.eql(d.sqr(I),E))throw new Error("Cannot find square root");const $=I,D=d.neg($),{re:T,im:F}=d.reim($),{re:k,im:N}=d.reim(D);return F>N||F===N&&T>k?$:D},isOdd:E=>{const{re:y,im:w}=d.reim(E),g=y%zn,m=y===h8,_=w%zn;return BigInt(g||m&&_)==ts},fromBytes(E){if(E.length!==d.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:y})=>Be(n.toBytes(E),n.toBytes(y)),cmov:({c0:E,c1:y},{c0:w,c1:g},m)=>({c0:n.cmov(E,w,m),c1:n.cmov(y,g,m)}),reim:({c0:E,c1:y})=>({re:E,im:y}),mulByNonresidue:({c0:E,c1:y})=>d.mul({c0:E,c1:y},l),mulByB:t.Fp2mulByB,fromBigTuple:u,frobeniusMap:({c0:E,c1:y},w)=>({c0:E,c1:n.mul(y,s[w%2])})},p=({c0:E,c1:y,c2:w},{c0:g,c1:m,c2:_})=>({c0:d.add(E,g),c1:d.add(y,m),c2:d.add(w,_)}),b=({c0:E,c1:y,c2:w},{c0:g,c1:m,c2:_})=>({c0:d.sub(E,g),c1:d.sub(y,m),c2:d.sub(w,_)}),v=({c0:E,c1:y,c2:w},g)=>{if(typeof g=="bigint")return{c0:d.mul(E,g),c1:d.mul(y,g),c2:d.mul(w,g)};const{c0:m,c1:_,c2:B}=g,I=d.mul(E,m),$=d.mul(y,_),D=d.mul(w,B);return{c0:d.add(I,d.mulByNonresidue(d.sub(d.mul(d.add(y,w),d.add(_,B)),d.add($,D)))),c1:d.add(d.sub(d.mul(d.add(E,y),d.add(m,_)),d.add(I,$)),d.mulByNonresidue(D)),c2:d.sub(d.add($,d.mul(d.add(E,w),d.add(m,B))),d.add(I,D))}},O=({c0:E,c1:y,c2:w})=>{let g=d.sqr(E),m=d.mul(d.mul(E,y),zn),_=d.mul(d.mul(y,w),zn),B=d.sqr(w);return{c0:d.add(d.mulByNonresidue(_),g),c1:d.add(d.mulByNonresidue(B),m),c2:d.sub(d.sub(d.add(d.add(m,d.sqr(d.add(d.sub(E,y),w))),_),g),B)}},[P,x]=kf(d,l,n.ORDER,6,2,3),S={ORDER:d.ORDER,isLE:d.isLE,BITS:3*d.BITS,BYTES:3*d.BYTES,MASK:wi(3*d.BITS),ZERO:{c0:d.ZERO,c1:d.ZERO,c2:d.ZERO},ONE:{c0:d.ONE,c1:d.ZERO,c2:d.ZERO},create:E=>E,isValid:({c0:E,c1:y,c2:w})=>d.isValid(E)&&d.isValid(y)&&d.isValid(w),is0:({c0:E,c1:y,c2:w})=>d.is0(E)&&d.is0(y)&&d.is0(w),neg:({c0:E,c1:y,c2:w})=>({c0:d.neg(E),c1:d.neg(y),c2:d.neg(w)}),eql:({c0:E,c1:y,c2:w},{c0:g,c1:m,c2:_})=>d.eql(E,g)&&d.eql(y,m)&&d.eql(w,_),sqrt:n0,div:(E,y)=>S.mul(E,typeof y=="bigint"?n.inv(n.create(y)):S.inv(y)),pow:(E,y)=>la(S,E,y),invertBatch:E=>vi(S,E),add:p,sub:b,mul:v,sqr:O,addN:p,subN:b,mulN:v,sqrN:O,inv:({c0:E,c1:y,c2:w})=>{let g=d.sub(d.sqr(E),d.mulByNonresidue(d.mul(w,y))),m=d.sub(d.mulByNonresidue(d.sqr(w)),d.mul(E,y)),_=d.sub(d.sqr(y),d.mul(E,w)),B=d.inv(d.add(d.mulByNonresidue(d.add(d.mul(w,m),d.mul(y,_))),d.mul(E,g)));return{c0:d.mul(B,g),c1:d.mul(B,m),c2:d.mul(B,_)}},fromBytes:E=>{if(E.length!==S.BYTES)throw new Error("fromBytes invalid length="+E.length);return{c0:d.fromBytes(E.subarray(0,d.BYTES)),c1:d.fromBytes(E.subarray(d.BYTES,2*d.BYTES)),c2:d.fromBytes(E.subarray(2*d.BYTES))}},toBytes:({c0:E,c1:y,c2:w})=>Be(d.toBytes(E),d.toBytes(y),d.toBytes(w)),cmov:({c0:E,c1:y,c2:w},{c0:g,c1:m,c2:_},B)=>({c0:d.cmov(E,g,B),c1:d.cmov(y,m,B),c2:d.cmov(w,_,B)}),fromBigSix:E=>{if(!Array.isArray(E)||E.length!==6)throw new Error("invalid Fp6 usage");return{c0:d.fromBigTuple(E.slice(0,2)),c1:d.fromBigTuple(E.slice(2,4)),c2:d.fromBigTuple(E.slice(4,6))}},frobeniusMap:({c0:E,c1:y,c2:w},g)=>({c0:d.frobeniusMap(E,g),c1:d.mul(d.frobeniusMap(y,g),P[g%6]),c2:d.mul(d.frobeniusMap(w,g),x[g%6])}),mulByFp2:({c0:E,c1:y,c2:w},g)=>({c0:d.mul(E,g),c1:d.mul(y,g),c2:d.mul(w,g)}),mulByNonresidue:({c0:E,c1:y,c2:w})=>({c0:d.mulByNonresidue(w),c1:E,c2:y}),mul1:({c0:E,c1:y,c2:w},g)=>({c0:d.mulByNonresidue(d.mul(w,g)),c1:d.mul(E,g),c2:d.mul(y,g)}),mul01({c0:E,c1:y,c2:w},g,m){let _=d.mul(E,g),B=d.mul(y,m);return{c0:d.add(d.mulByNonresidue(d.sub(d.mul(d.add(y,w),m),B)),_),c1:d.sub(d.sub(d.mul(d.add(g,m),d.add(E,y)),_),B),c2:d.add(d.sub(d.mul(d.add(E,w),g),_),B)}}},R=kf(d,l,n.ORDER,12,1,6)[0],U=({c0:E,c1:y},{c0:w,c1:g})=>({c0:S.add(E,w),c1:S.add(y,g)}),L=({c0:E,c1:y},{c0:w,c1:g})=>({c0:S.sub(E,w),c1:S.sub(y,g)}),C=({c0:E,c1:y},w)=>{if(typeof w=="bigint")return{c0:S.mul(E,w),c1:S.mul(y,w)};let{c0:g,c1:m}=w,_=S.mul(E,g),B=S.mul(y,m);return{c0:S.add(_,S.mulByNonresidue(B)),c1:S.sub(S.mul(S.add(E,y),S.add(g,m)),S.add(_,B))}},A=({c0:E,c1:y})=>{let w=S.mul(E,y);return{c0:S.sub(S.sub(S.mul(S.add(S.mulByNonresidue(y),E),S.add(E,y)),w),S.mulByNonresidue(w)),c1:S.add(w,w)}};function j(E,y){const w=d.sqr(E),g=d.sqr(y);return{first:d.add(d.mulByNonresidue(g),w),second:d.sub(d.sub(d.sqr(d.add(E,y)),w),g)}}const q={ORDER:d.ORDER,isLE:S.isLE,BITS:2*S.BITS,BYTES:2*S.BYTES,MASK:wi(2*S.BITS),ZERO:{c0:S.ZERO,c1:S.ZERO},ONE:{c0:S.ONE,c1:S.ZERO},create:E=>E,isValid:({c0:E,c1:y})=>S.isValid(E)&&S.isValid(y),is0:({c0:E,c1:y})=>S.is0(E)&&S.is0(y),neg:({c0:E,c1:y})=>({c0:S.neg(E),c1:S.neg(y)}),eql:({c0:E,c1:y},{c0:w,c1:g})=>S.eql(E,w)&&S.eql(y,g),sqrt:n0,inv:({c0:E,c1:y})=>{let w=S.inv(S.sub(S.sqr(E),S.mulByNonresidue(S.sqr(y))));return{c0:S.mul(E,w),c1:S.neg(S.mul(y,w))}},div:(E,y)=>q.mul(E,typeof y=="bigint"?n.inv(n.create(y)):q.inv(y)),pow:(E,y)=>la(q,E,y),invertBatch:E=>vi(q,E),add:U,sub:L,mul:C,sqr:A,addN:U,subN:L,mulN:C,sqrN:A,fromBytes:E=>{if(E.length!==q.BYTES)throw new Error("fromBytes invalid length="+E.length);return{c0:S.fromBytes(E.subarray(0,S.BYTES)),c1:S.fromBytes(E.subarray(S.BYTES))}},toBytes:({c0:E,c1:y})=>Be(S.toBytes(E),S.toBytes(y)),cmov:({c0:E,c1:y},{c0:w,c1:g},m)=>({c0:S.cmov(E,w,m),c1:S.cmov(y,g,m)}),fromBigTwelve:E=>({c0:S.fromBigSix(E.slice(0,6)),c1:S.fromBigSix(E.slice(6,12))}),frobeniusMap(E,y){const{c0:w,c1:g,c2:m}=S.frobeniusMap(E.c1,y),_=R[y%12];return{c0:S.frobeniusMap(E.c0,y),c1:S.create({c0:d.mul(w,_),c1:d.mul(g,_),c2:d.mul(m,_)})}},mulByFp2:({c0:E,c1:y},w)=>({c0:S.mulByFp2(E,w),c1:S.mulByFp2(y,w)}),conjugate:({c0:E,c1:y})=>({c0:E,c1:S.neg(y)}),mul014:({c0:E,c1:y},w,g,m)=>{let _=S.mul01(E,w,g),B=S.mul1(y,m);return{c0:S.add(S.mulByNonresidue(B),_),c1:S.sub(S.sub(S.mul01(S.add(y,E),w,d.add(g,m)),_),B)}},mul034:({c0:E,c1:y},w,g,m)=>{const _=S.create({c0:d.mul(E.c0,w),c1:d.mul(E.c1,w),c2:d.mul(E.c2,w)}),B=S.mul01(y,g,m),I=S.mul01(S.add(E,y),d.add(w,g),m);return{c0:S.add(S.mulByNonresidue(B),_),c1:S.sub(I,S.add(_,B))}},_cyclotomicSquare:t.Fp12cyclotomicSquare,_cyclotomicExp:t.Fp12cyclotomicExp,finalExponentiate:t.Fp12finalExponentiate};return{Fp:n,Fp2:d,Fp6:S,Fp4Square:j,Fp12:q}}const bt=BigInt(0),ga=BigInt(1),Le=BigInt(2),ya=BigInt(3),Gs=BigInt(4),Ir=BigInt("0xd201000000010000"),g8=js(Ir),{Fp:J,Fp2:Q,Fp6:qf,Fp4Square:Mf,Fp12:se}=p8({ORDER:BigInt("0x1a0111ea397fe69a4b1ba7b6434bacd764774b84f38512bf6730d2a0f6b0f6241eabfffeb153ffffb9feffffffffaaab"),FP2_NONRESIDUE:[ga,ga],Fp2mulByB:({c0:t,c1:e})=>{const n=J.mul(t,Gs),r=J.mul(e,Gs);return{c0:J.sub(n,r),c1:J.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}=Mf(n,o),{first:u,second:h}=Mf(s,i),{first:l,second:d}=Mf(r,a),p=Q.mulByNonresidue(d);return{c0:qf.create({c0:Q.add(Q.mul(Q.sub(c,n),Le),c),c1:Q.add(Q.mul(Q.sub(u,r),Le),u),c2:Q.add(Q.mul(Q.sub(l,i),Le),l)}),c1:qf.create({c0:Q.add(Q.mul(Q.add(p,s),Le),p),c1:Q.add(Q.mul(Q.add(f,o),Le),f),c2:Q.add(Q.mul(Q.add(h,a),Le),h)})}},Fp12cyclotomicExp(t,e){let n=se.ONE;for(let r=g8-1;r>=0;r--)n=se._cyclotomicSquare(n),zv(e,r)&&(n=se.mul(n,t));return n},Fp12finalExponentiate:t=>{const e=Ir,n=se.div(se.frobeniusMap(t,6),t),r=se.mul(se.frobeniusMap(n,2),n),i=se.conjugate(se._cyclotomicExp(r,e)),s=se.mul(se.conjugate(se._cyclotomicSquare(r)),i),o=se.conjugate(se._cyclotomicExp(s,e)),a=se.conjugate(se._cyclotomicExp(o,e)),c=se.mul(se.conjugate(se._cyclotomicExp(a,e)),se._cyclotomicSquare(i)),f=se.conjugate(se._cyclotomicExp(c,e)),u=se.frobeniusMap(se.mul(i,a),2),h=se.frobeniusMap(se.mul(o,r),3),l=se.frobeniusMap(se.mul(c,se.conjugate(r)),1),d=se.mul(se.mul(f,se.conjugate(s)),r);return se.mul(se.mul(se.mul(u,h),l),d)}}),q0=Er(BigInt("0x73eda753299d7d483339d80809a1d80553bda402fffe5bfeffffffff00000001")),y8=T0(Q,[[["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=>Q.fromBigTuple(e.map(BigInt))))),b8=T0(J,[["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)))),w8=P0(Q,{A:Q.create({c0:J.create(bt),c1:J.create(BigInt(240))}),B:Q.create({c0:J.create(BigInt(1012)),c1:J.create(BigInt(1012))}),Z:Q.create({c0:J.create(BigInt(-2)),c1:J.create(BigInt(-1))})}),m8=P0(J,{A:J.create(BigInt("0x144698a3b8e9433d693a02c96d4982b0ea985383ee66a8d8e8981aefd881ac98936f8da0e0f97f5cf428082d584c1d")),B:J.create(BigInt("0x12e2908d11688030018b12e8753eee3b2016c1f0f24f4070a0b9c14fcef35ef55a23215a316ceaa5d1cc48e98e172be0")),Z:J.create(BigInt(11))}),{G2psi:M0,G2psi2:v8}=d8(J,Q,Q.div(Q.ONE,Q.NONRESIDUE)),jf=Object.freeze({DST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",encodeDST:"BLS_SIG_BLS12381G2_XMD:SHA-256_SSWU_RO_NUL_",p:J.ORDER,m:2,k:128,expand:"xmd",hash:ia}),ba=Zs(J.toBytes(bt),{infinity:!0,compressed:!0});function wa(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 Zs(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 j0(t){t.assertValidity();const e=t.equals(sn.G1.ProjectivePoint.ZERO),{x:n,y:r}=t.toAffine();if(e)return ba.slice();const i=J.ORDER,s=!!(r*Le/i);return Zs(Re(n,J.BYTES),{compressed:!0,sort:s})}function z0(t){t.assertValidity();const e=J.BYTES;if(t.equals(sn.G2.ProjectivePoint.ZERO))return Be(ba,Re(bt,e));const{x:n,y:r}=t.toAffine(),{re:i,im:s}=Q.reim(n),{re:o,im:a}=Q.reim(r),f=!!((a>bt?a*Le:o*Le)/J.ORDER&ga),u=i;return Be(Zs(Re(s,e),{sort:f,compressed:!0}),Re(u,e))}const sn=l8({fields:{Fp:J,Fp2:Q,Fp6:qf,Fp12:se,Fr:q0},G1:{Fp:J,h:BigInt("0x396c8c005555e1568c00aaab0000aaab"),Gx:BigInt("0x17f1d3a73197d7942695638c4fa9ac0fc3688c4f9774b905a14e3a3f171bac586c55e83ff97a1aeffb3af00adb22c6bb"),Gy:BigInt("0x08b3f481e3aaa0f1a09e30ed741d8ae4fcf5e095d5d00af600db18cb2c04b3edd03cc744a2888ae40caa232946c5e7e1"),a:J.ZERO,b:Gs,htfDefaults:{...jf,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(J.mul(e.px,n),e.py,e.pz);return e.multiplyUnsafe(Ir).negate().multiplyUnsafe(Ir).equals(r)},clearCofactor:(t,e)=>e.multiplyUnsafe(Ir).add(e),mapToCurve:t=>{const{x:e,y:n}=m8(J.create(t[0]));return b8(e,n)},fromBytes:t=>{const{compressed:e,infinity:n,sort:r,value:i}=wa(t);if(i.length===48&&e){const s=J.ORDER,o=pt(i),a=J.create(o&J.MASK);if(n){if(a!==bt)throw new Error("G1: non-empty compressed point at infinity");return{x:bt,y:bt}}const c=J.add(J.pow(a,ya),J.create(sn.params.G1b));let f=J.sqrt(c);if(!f)throw new Error("invalid compressed G1 point");return f*Le/s!==BigInt(r)&&(f=J.neg(f)),{x:J.create(a),y:J.create(f)}}else if(i.length===96&&!e){const s=pt(i.subarray(0,J.BYTES)),o=pt(i.subarray(J.BYTES));if(n){if(s!==bt||o!==bt)throw new Error("G1: non-empty point at infinity");return sn.G1.ProjectivePoint.ZERO.toAffine()}return{x:J.create(s),y:J.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 ba.slice();const o=J.ORDER,a=!!(s*Le/o);return Zs(Re(i,J.BYTES),{compressed:!0,sort:a})}else return r?Be(new Uint8Array([64]),new Uint8Array(2*J.BYTES-1)):Be(Re(i,J.BYTES),Re(s,J.BYTES))},ShortSignature:{fromHex(t){const{infinity:e,sort:n,value:r}=wa(nt("signatureHex",t,48)),i=J.ORDER,s=pt(r);if(e)return sn.G1.ProjectivePoint.ZERO;const o=J.create(s&J.MASK),a=J.add(J.pow(o,ya),J.create(sn.params.G1b));let c=J.sqrt(a);if(!c)throw new Error("invalid compressed G1 point");const f=BigInt(n);c*Le/i!==f&&(c=J.neg(c));const u=sn.G1.ProjectivePoint.fromAffine({x:o,y:c});return u.assertValidity(),u},toRawBytes(t){return j0(t)},toHex(t){return bi(j0(t))}}},G2:{Fp:Q,h:BigInt("0x5d543a95414e7f1091d50792876a202cd91de4547085abaa68a205b2e5a7ddfa628f1cb4d9e82ef21537e293a6691ae1616ec6e786f0c70cf1c38e31c7238e5"),Gx:Q.fromBigTuple([BigInt("0x024aa2b2f08f0a91260805272dc51051c6e47ad4fa403b02b4510b647ae3d1770bac0326a805bbefd48056c8c121bdb8"),BigInt("0x13e02b6052719f607dacd3a088274f65596bd0d09920b61ab5da61bbdc7f5049334cf11213945d57e5ac7d055d042b7e")]),Gy:Q.fromBigTuple([BigInt("0x0ce5d527727d6e118cc9cdc6da2e351aadfd9baa8cbdd3a76d429a695160d12c923ac9cc3baca289e193548608b82801"),BigInt("0x0606c4a02ea734cc32acd2b02bc28b99cb3e287e85a763af267492ab572e99ab3f370d275cec1da1aaa9075ff05f79be")]),a:Q.ZERO,b:Q.fromBigTuple([Gs,Gs]),hEff:BigInt("0xbc69f08f2ee75b3584c6a0ea91b352888e2a8e9145ad7689986ff031508ffe1329c2f178731db956d82bf015d1212b02ec0ec69d7477c1ae954cbc06689f6a359894c0adebbf6b4e8020005aaa95551"),htfDefaults:{...jf},wrapPrivateKey:!0,allowInfinityPoint:!0,mapToCurve:t=>{const{x:e,y:n}=w8(Q.fromBigTuple(t));return y8(e,n)},isTorsionFree:(t,e)=>e.multiplyUnsafe(Ir).negate().equals(M0(t,e)),clearCofactor:(t,e)=>{const n=Ir;let r=e.multiplyUnsafe(n).negate(),i=M0(t,e),s=e.double();return s=v8(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}=wa(t);if(!e&&!n&&r||!e&&n&&r||r&&n&&e)throw new Error("invalid encoding flag: "+(t[0]&224));const s=J.BYTES,o=(a,c,f)=>pt(a.slice(c,f));if(i.length===96&&e){const a=sn.params.G2b,c=J.ORDER;if(n){if(i.reduce((b,v)=>b!==0?v+1:v,0)>0)throw new Error("invalid compressed G2 point");return{x:Q.ZERO,y:Q.ZERO}}const f=o(i,0,s),u=o(i,s,2*s),h=Q.create({c0:J.create(u),c1:J.create(f)}),l=Q.add(Q.pow(h,ya),a);let d=Q.sqrt(l);const p=d.c1===bt?d.c0*Le/c:d.c1*Le/c?ga:bt;return d=r&&p>0?d:Q.neg(d),{x:h,y:d}}else if(i.length===192&&!e){if(n){if(i.reduce((h,l)=>h!==0?l+1:l,0)>0)throw new Error("invalid uncompressed G2 point");return{x:Q.ZERO,y:Q.ZERO}}const a=o(i,0,s),c=o(i,s,2*s),f=o(i,2*s,3*s),u=o(i,3*s,4*s);return{x:Q.fromBigTuple([c,a]),y:Q.fromBigTuple([u,f])}}else throw new Error("invalid point G2, expected 96/192 bytes")},toBytes:(t,e,n)=>{const{BYTES:r,ORDER:i}=J,s=e.equals(t.ZERO),{x:o,y:a}=e.toAffine();if(n){if(s)return Be(ba,Re(bt,r));const c=!!(a.c1===bt?a.c0*Le/i:a.c1*Le/i);return Be(Zs(Re(o.c1,r),{compressed:!0,sort:c}),Re(o.c0,r))}else{if(s)return Be(new Uint8Array([64]),new Uint8Array(4*r-1));const{re:c,im:f}=Q.reim(o),{re:u,im:h}=Q.reim(a);return Be(Re(f,r),Re(c,r),Re(h,r),Re(u,r))}},Signature:{fromHex(t){const{infinity:e,sort:n,value:r}=wa(nt("signatureHex",t)),i=J.ORDER,s=r.length/2;if(s!==48&&s!==96)throw new Error("invalid compressed signature length, must be 96 or 192");const o=pt(r.slice(0,s)),a=pt(r.slice(s));if(e)return sn.G2.ProjectivePoint.ZERO;const c=J.create(o&J.MASK),f=J.create(a),u=Q.create({c0:f,c1:c}),h=Q.add(Q.pow(u,ya),sn.params.G2b);let l=Q.sqrt(h);if(!l)throw new Error("Failed to find a square root");const{re:d,im:p}=Q.reim(l),b=BigInt(n),v=p>bt&&p*Le/i!==b,O=p===bt&&d*Le/i!==b;(v||O)&&(l=Q.neg(l));const P=sn.G2.ProjectivePoint.fromAffine({x:u,y:l});return P.assertValidity(),P},toRawBytes(t){return z0(t)},toHex(t){return bi(z0(t))}}},params:{ateLoopSize:Ir,r:q0.ORDER,xNegative:!0,twistType:"multiplicative"},htfDefaults:jf,hash:ia,randomBytes:Cd});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 ns=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ma(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function zf(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Ei(t,...e){if(!ma(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 H0(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");zf(t.outputLen),zf(t.blockLen)}function va(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 E8(t,e){Ei(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Ea(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Hf(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function xn(t,e){return t<<32-e|t>>>e}const V0=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",x8=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function rs(t){if(Ei(t),V0)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=x8[t[n]];return e}const Hn={_0:48,_9:57,A:65,F:70,a:97,f:102};function K0(t){if(t>=Hn._0&&t<=Hn._9)return t-Hn._0;if(t>=Hn.A&&t<=Hn.F)return t-(Hn.A-10);if(t>=Hn.a&&t<=Hn.f)return t-(Hn.a-10)}function xa(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(V0)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=K0(t.charCodeAt(s)),a=K0(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 Vf(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Kf(t){return typeof t=="string"&&(t=Vf(t)),Ei(t),t}function Sr(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];Ei(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 G0{}function _8(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 Z0(t=32){if(ns&&typeof ns.getRandomValues=="function")return ns.getRandomValues(new Uint8Array(t));if(ns&&typeof ns.randomBytes=="function")return Uint8Array.from(ns.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const Gf=BigInt(0),Zf=BigInt(1);function _a(t,e=""){if(typeof t!="boolean"){const n=e&&`"${e}"`;throw new Error(n+"expected boolean, got type="+typeof t)}return t}function xi(t,e,n=""){const r=ma(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 Ia(t){const e=t.toString(16);return e.length&1?"0"+e:e}function W0(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Gf:BigInt("0x"+t)}function Sa(t){return W0(rs(t))}function Y0(t){return Ei(t),W0(rs(Uint8Array.from(t).reverse()))}function Wf(t,e){return xa(t.toString(16).padStart(e*2,"0"))}function X0(t,e){return Wf(t,e).reverse()}function It(t,e,n){let r;if(typeof e=="string")try{r=xa(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(ma(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 Yf=t=>typeof t=="bigint"&&Gf<=t;function I8(t,e,n){return Yf(t)&&Yf(e)&&Yf(n)&&e<=t&&t<n}function S8(t,e,n,r){if(!I8(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function J0(t){let e;for(e=0;t>Gf;t>>=Zf,e+=1);return e}const Ws=t=>(Zf<<BigInt(t))-Zf;function B8(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),u=(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 p=[];for(;d<e;){s=f();const b=s.slice();p.push(b),d+=s.length}return Sr(...p)};return(d,p)=>{c(),u(d);let b;for(;!(b=p(h()));)u();return c(),b}}function Xf(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 Q0(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 St=BigInt(0),wt=BigInt(1),_i=BigInt(2),ep=BigInt(3),tp=BigInt(4),np=BigInt(5),$8=BigInt(7),rp=BigInt(8),A8=BigInt(9),ip=BigInt(16);function on(t,e){const n=t%e;return n>=St?n:e+n}function Gt(t,e,n){let r=t;for(;e-- >St;)r*=r,r%=n;return r}function sp(t,e){if(t===St)throw new Error("invert: expected non-zero number");if(e<=St)throw new Error("invert: expected positive modulus, got "+e);let n=on(t,e),r=e,i=St,s=wt;for(;n!==St;){const a=r/n,c=r%n,f=i-s*a;r=n,n=c,i=s,s=f}if(r!==wt)throw new Error("invert: does not exist");return on(i,e)}function Jf(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function op(t,e){const n=(t.ORDER+wt)/tp,r=t.pow(e,n);return Jf(t,r,e),r}function O8(t,e){const n=(t.ORDER-np)/rp,r=t.mul(e,_i),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,_i),i),a=t.mul(s,t.sub(o,t.ONE));return Jf(t,a,e),a}function D8(t){const e=Ys(t),n=ap(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+$8)/ip;return(a,c)=>{let f=a.pow(c,o),u=a.mul(f,r);const h=a.mul(f,i),l=a.mul(f,s),d=a.eql(a.sqr(u),c),p=a.eql(a.sqr(h),c);f=a.cmov(f,u,d),u=a.cmov(l,h,p);const b=a.eql(a.sqr(u),c),v=a.cmov(f,u,b);return Jf(a,v,c),v}}function ap(t){if(t<ep)throw new Error("sqrt is not defined for small field");let e=t-wt,n=0;for(;e%_i===St;)e/=_i,n++;let r=_i;const i=Ys(t);for(;fp(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return op;let s=i.pow(r,e);const o=(e+wt)/_i;return function(c,f){if(c.is0(f))return f;if(fp(c,f)!==1)throw new Error("Cannot find square root");let u=n,h=c.mul(c.ONE,s),l=c.pow(f,e),d=c.pow(f,o);for(;!c.eql(l,c.ONE);){if(c.is0(l))return c.ZERO;let p=1,b=c.sqr(l);for(;!c.eql(b,c.ONE);)if(p++,b=c.sqr(b),p===u)throw new Error("Cannot find square root");const v=wt<<BigInt(u-p-1),O=c.pow(h,v);u=p,h=c.sqr(O),l=c.mul(l,h),d=c.mul(d,O)}return d}}function P8(t){return t%tp===ep?op:t%rp===np?O8:t%ip===A8?D8(t):ap(t)}const R8=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function T8(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=R8.reduce((r,i)=>(r[i]="function",r),e);return Xf(t,n),t}function N8(t,e,n){if(n<St)throw new Error("invalid exponent, negatives unsupported");if(n===St)return t.ONE;if(n===wt)return e;let r=t.ONE,i=e;for(;n>St;)n&wt&&(r=t.mul(r,i)),i=t.sqr(i),n>>=wt;return r}function cp(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 fp(t,e){const n=(t.ORDER-wt)/_i,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 up(t,e){e!==void 0&&zf(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Ys(t,e,n=!1,r={}){if(t<=St)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 l=e;l.BITS&&(i=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(n=l.isLE),typeof l.modFromBytes=="boolean"&&(o=l.modFromBytes),a=l.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:f}=up(t,i);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u;const h=Object.freeze({ORDER:t,isLE:n,BITS:c,BYTES:f,MASK:Ws(c),ZERO:St,ONE:wt,allowedLengths:a,create:l=>on(l,t),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return St<=l&&l<t},is0:l=>l===St,isValidNot0:l=>!h.is0(l)&&h.isValid(l),isOdd:l=>(l&wt)===wt,neg:l=>on(-l,t),eql:(l,d)=>l===d,sqr:l=>on(l*l,t),add:(l,d)=>on(l+d,t),sub:(l,d)=>on(l-d,t),mul:(l,d)=>on(l*d,t),pow:(l,d)=>N8(h,l,d),div:(l,d)=>on(l*sp(d,t),t),sqrN:l=>l*l,addN:(l,d)=>l+d,subN:(l,d)=>l-d,mulN:(l,d)=>l*d,inv:l=>sp(l,t),sqrt:s||(l=>(u||(u=P8(t)),u(h,l))),toBytes:l=>n?X0(l,f):Wf(l,f),fromBytes:(l,d=!0)=>{if(a){if(!a.includes(l.length)||l.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);const b=new Uint8Array(f);b.set(l,n?0:b.length-l.length),l=b}if(l.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+l.length);let p=n?Y0(l):Sa(l);if(o&&(p=on(p,t)),!d&&!h.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:l=>cp(h,l),cmov:(l,d,p)=>p?d:l});return Object.freeze(h)}function lp(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 hp(t){const e=lp(t);return e+Math.ceil(e/2)}function U8(t,e,n=!1){const r=t.length,i=lp(e),s=hp(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?Y0(t):Sa(t),a=on(o,e-wt)+wt;return n?X0(a,i):Wf(a,i)}function C8(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 F8(t,e,n){return t&e^~t&n}function L8(t,e,n){return t&e^t&n^e&n}class k8 extends G0{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=Hf(this.buffer)}update(e){va(this),e=Kf(e),Ei(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=Hf(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){va(this),E8(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,Ea(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;C8(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Hf(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,u[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 Br=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),q8=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]),$r=new Uint32Array(64);class M8 extends k8{constructor(e=32){super(64,e,8,!1),this.A=Br[0]|0,this.B=Br[1]|0,this.C=Br[2]|0,this.D=Br[3]|0,this.E=Br[4]|0,this.F=Br[5]|0,this.G=Br[6]|0,this.H=Br[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)$r[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const l=$r[h-15],d=$r[h-2],p=xn(l,7)^xn(l,18)^l>>>3,b=xn(d,17)^xn(d,19)^d>>>10;$r[h]=b+$r[h-7]+p+$r[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){const l=xn(a,6)^xn(a,11)^xn(a,25),d=u+l+F8(a,c,f)+q8[h]+$r[h]|0,b=(xn(r,2)^xn(r,13)^xn(r,22))+L8(r,i,s)|0;u=f,f=c,c=a,a=o+d|0,o=s,s=i,i=r,r=d+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,u=u+this.H|0,this.set(r,i,s,o,a,c,f,u)}roundClean(){Ea($r)}destroy(){this.set(0,0,0,0,0,0,0,0),Ea(this.buffer)}}const dp=_8(()=>new M8);class pp extends G0{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,H0(e);const r=Kf(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),Ea(s)}update(e){return va(this),this.iHash.update(e),this}digestInto(e){va(this),Ei(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 gp=(t,e,n)=>new pp(t,e).update(n).digest();gp.create=(t,e)=>new pp(t,e);const is=BigInt(0),Ii=BigInt(1);function Ba(t,e){const n=e.negate();return t?n:e}function Qf(t,e){const n=cp(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function yp(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function eu(t,e){yp(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 bp(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+=Ii);const f=e*r,u=f+Math.abs(a)-1,h=a===0,l=a<0,d=e%2!==0;return{nextN:c,offset:u,isZero:h,isNeg:l,isNegF:d,offsetF:f}}function j8(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 z8(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 tu=new WeakMap,wp=new WeakMap;function nu(t){return wp.get(t)||1}function mp(t){if(t!==is)throw new Error("invalid wNAF")}class H8{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>is;)n&Ii&&(r=r.add(i)),i=i.double(),n>>=Ii;return r}precomputeWindow(e,n){const{windows:r,windowSize:i}=eu(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=eu(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:c,offset:f,isZero:u,isNeg:h,isNegF:l,offsetF:d}=bp(r,a,o);r=c,u?s=s.add(Ba(l,n[d])):i=i.add(Ba(h,n[f]))}return mp(r),{p:i,f:s}}wNAFUnsafe(e,n,r,i=this.ZERO){const s=eu(e,this.bits);for(let o=0;o<s.windows&&r!==is;o++){const{nextN:a,offset:c,isZero:f,isNeg:u}=bp(r,o,s);if(r=a,!f){const h=n[c];i=i.add(u?h.negate():h)}}return mp(r),i}getPrecomputes(e,n,r){let i=tu.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),tu.set(n,i))),i}cached(e,n,r){const i=nu(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=nu(e);return s===1?this._unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,i)}createCache(e,n){yp(n,this.bits),wp.set(e,n),tu.delete(e)}hasCache(e){return nu(e)!==1}}function V8(t,e,n,r){let i=e,s=t.ZERO,o=t.ZERO;for(;n>is||r>is;)n&Ii&&(s=s.add(i)),r&Ii&&(o=o.add(i)),i=i.double(),n>>=Ii,r>>=Ii;return{p1:s,p2:o}}function K8(t,e,n,r){j8(n,t),z8(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=J0(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=Ws(c),u=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let l=o;for(let d=h;d>=0;d-=c){u.fill(o);for(let b=0;b<s;b++){const v=r[b],O=Number(v>>BigInt(d)&f);u[O]=u[O].add(n[b])}let p=o;for(let b=u.length-1,v=o;b>0;b--)v=v.add(u[b]),p=p.add(v);if(l=l.add(p),d!==0)for(let b=0;b<c;b++)l=l.double()}return l}function vp(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return T8(e),e}else return Ys(t,{isLE:n})}function G8(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>is))throw new Error(`CURVE.${c} must be positive bigint`)}const i=vp(e.p,n.Fp,r),s=vp(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 Ep=(t,e)=>(t+(t>=0?e:-e)/xp)/e;function Z8(t,e,n){const[[r,i],[s,o]]=e,a=Ep(o*t,n),c=Ep(-i*t,n);let f=t-a*r-c*s,u=-a*i-c*o;const h=f<Kn,l=u<Kn;h&&(f=-f),l&&(u=-u);const d=Ws(Math.ceil(J0(n)/2))+ss;if(f<Kn||f>=d||u<Kn||u>=d)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:h,k1:f,k2neg:l,k2:u}}function ru(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function iu(t,e){const n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return _a(n.lowS,"lowS"),_a(n.prehash,"prehash"),n.format!==void 0&&ru(n.format),n}class W8 extends Error{constructor(e=""){super(e)}}const Vn={Err:W8,_tlv:{encode:(t,e)=>{const{Err:n}=Vn;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=Ia(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?Ia(i.length/2|128):"";return Ia(t)+s+i+e},decode(t,e){const{Err:n}=Vn;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 u of f)o=o<<8|u;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}=Vn;if(t<Kn)throw new e("integer: negative integers are not allowed");let n=Ia(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}=Vn;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 Sa(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=Vn,i=It("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:u}=r.decode(2,c);if(u.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}=Vn,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}},Kn=BigInt(0),ss=BigInt(1),xp=BigInt(2),$a=BigInt(3),Y8=BigInt(4);function os(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=It("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 X8(t,e={}){const n=G8("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;Xf(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=Ip(r,i);function u(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(E,y,w){const{x:g,y:m}=y.toAffine(),_=r.toBytes(g);if(_a(w,"isCompressed"),w){u();const B=!r.isOdd(m);return Sr(_p(B),_)}else return Sr(Uint8Array.of(4),_,r.toBytes(m))}function l(E){xi(E,void 0,"Point");const{publicKey:y,publicKeyUncompressed:w}=f,g=E.length,m=E[0],_=E.subarray(1);if(g===y&&(m===2||m===3)){const B=r.fromBytes(_);if(!r.isValid(B))throw new Error("bad point: is not on curve, wrong x");const I=b(B);let $;try{$=r.sqrt(I)}catch(F){const k=F instanceof Error?": "+F.message:"";throw new Error("bad point: is not on curve, sqrt error"+k)}u();const D=r.isOdd($);return(m&1)===1!==D&&($=r.neg($)),{x:B,y:$}}else if(g===w&&m===4){const B=r.BYTES,I=r.fromBytes(_.subarray(0,B)),$=r.fromBytes(_.subarray(B,B*2));if(!v(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=${y} or uncompressed=${w}`)}const d=e.toBytes||h,p=e.fromBytes||l;function b(E){const y=r.sqr(E),w=r.mul(y,E);return r.add(r.add(w,r.mul(E,s.a)),s.b)}function v(E,y){const w=r.sqr(y),g=b(E);return r.eql(w,g)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const O=r.mul(r.pow(s.a,$a),Y8),P=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(O,P)))throw new Error("bad curve params: a or b");function x(E,y,w=!1){if(!r.isValid(y)||w&&r.is0(y))throw new Error(`bad point coordinate ${E}`);return y}function S(E){if(!(E instanceof A))throw new Error("ProjectivePoint expected")}function R(E){if(!c||!c.basises)throw new Error("no endo");return Z8(E,c.basises,i.ORDER)}const U=Q0((E,y)=>{const{X:w,Y:g,Z:m}=E;if(r.eql(m,r.ONE))return{x:w,y:g};const _=E.is0();y==null&&(y=_?r.ONE:r.inv(m));const B=r.mul(w,y),I=r.mul(g,y),$=r.mul(m,y);if(_)return{x:r.ZERO,y:r.ZERO};if(!r.eql($,r.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}),L=Q0(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.Y))return;throw new Error("bad point: ZERO")}const{x:y,y:w}=E.toAffine();if(!r.isValid(y)||!r.isValid(w))throw new Error("bad point: x or y not field elements");if(!v(y,w))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(E,y,w,g,m){return w=new A(r.mul(w.X,E),w.Y,w.Z),y=Ba(g,y),w=Ba(m,w),y.add(w)}class A{constructor(y,w,g){this.X=x("x",y),this.Y=x("y",w,!0),this.Z=x("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){const{x:w,y:g}=y||{};if(!y||!r.isValid(w)||!r.isValid(g))throw new Error("invalid affine point");if(y instanceof A)throw new Error("projective point not allowed");return r.is0(w)&&r.is0(g)?A.ZERO:new A(w,g,r.ONE)}static fromBytes(y){const w=A.fromAffine(p(xi(y,void 0,"point")));return w.assertValidity(),w}static fromHex(y){return A.fromBytes(It("pointHex",y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,w=!0){return q.createCache(this,y),w||this.multiply($a),this}assertValidity(){L(this)}hasEvenY(){const{y}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(y)}equals(y){S(y);const{X:w,Y:g,Z:m}=this,{X:_,Y:B,Z:I}=y,$=r.eql(r.mul(w,I),r.mul(_,m)),D=r.eql(r.mul(g,I),r.mul(B,m));return $&&D}negate(){return new A(this.X,r.neg(this.Y),this.Z)}double(){const{a:y,b:w}=s,g=r.mul(w,$a),{X:m,Y:_,Z:B}=this;let I=r.ZERO,$=r.ZERO,D=r.ZERO,T=r.mul(m,m),F=r.mul(_,_),k=r.mul(B,B),N=r.mul(m,_);return N=r.add(N,N),D=r.mul(m,B),D=r.add(D,D),I=r.mul(y,D),$=r.mul(g,k),$=r.add(I,$),I=r.sub(F,$),$=r.add(F,$),$=r.mul(I,$),I=r.mul(N,I),D=r.mul(g,D),k=r.mul(y,k),N=r.sub(T,k),N=r.mul(y,N),N=r.add(N,D),D=r.add(T,T),T=r.add(D,T),T=r.add(T,k),T=r.mul(T,N),$=r.add($,T),k=r.mul(_,B),k=r.add(k,k),T=r.mul(k,N),I=r.sub(I,T),D=r.mul(k,F),D=r.add(D,D),D=r.add(D,D),new A(I,$,D)}add(y){S(y);const{X:w,Y:g,Z:m}=this,{X:_,Y:B,Z:I}=y;let $=r.ZERO,D=r.ZERO,T=r.ZERO;const F=s.a,k=r.mul(s.b,$a);let N=r.mul(w,_),M=r.mul(g,B),z=r.mul(m,I),K=r.add(w,g),H=r.add(_,B);K=r.mul(K,H),H=r.add(N,M),K=r.sub(K,H),H=r.add(w,m);let G=r.add(_,I);return H=r.mul(H,G),G=r.add(N,z),H=r.sub(H,G),G=r.add(g,m),$=r.add(B,I),G=r.mul(G,$),$=r.add(M,z),G=r.sub(G,$),T=r.mul(F,H),$=r.mul(k,z),T=r.add($,T),$=r.sub(M,T),T=r.add(M,T),D=r.mul($,T),M=r.add(N,N),M=r.add(M,N),z=r.mul(F,z),H=r.mul(k,H),M=r.add(M,z),z=r.sub(N,z),z=r.mul(F,z),H=r.add(H,z),N=r.mul(M,H),D=r.add(D,N),N=r.mul(G,H),$=r.mul(K,$),$=r.sub($,N),N=r.mul(K,M),T=r.mul(G,T),T=r.add(T,N),new A($,D,T)}subtract(y){return this.add(y.negate())}is0(){return this.equals(A.ZERO)}multiply(y){const{endo:w}=e;if(!i.isValidNot0(y))throw new Error("invalid scalar: out of range");let g,m;const _=B=>q.cached(this,B,I=>Qf(A,I));if(w){const{k1neg:B,k1:I,k2neg:$,k2:D}=R(y),{p:T,f:F}=_(I),{p:k,f:N}=_(D);m=F.add(N),g=C(w.beta,T,k,B,$)}else{const{p:B,f:I}=_(y);g=B,m=I}return Qf(A,[g,m])[0]}multiplyUnsafe(y){const{endo:w}=e,g=this;if(!i.isValid(y))throw new Error("invalid scalar: out of range");if(y===Kn||g.is0())return A.ZERO;if(y===ss)return g;if(q.hasCache(this))return this.multiply(y);if(w){const{k1neg:m,k1:_,k2neg:B,k2:I}=R(y),{p1:$,p2:D}=V8(A,g,_,I);return C(w.beta,$,D,m,B)}else return q.unsafe(g,y)}multiplyAndAddUnsafe(y,w,g){const m=this.multiplyUnsafe(w).add(y.multiplyUnsafe(g));return m.is0()?void 0:m}toAffine(y){return U(this,y)}isTorsionFree(){const{isTorsionFree:y}=e;return o===ss?!0:y?y(A,this):q.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:y}=e;return o===ss?this:y?y(A,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(y=!0){return _a(y,"isCompressed"),this.assertValidity(),d(A,this,y)}toHex(y=!0){return rs(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(y=!0){return this.toBytes(y)}_setWindowSize(y){this.precompute(y)}static normalizeZ(y){return Qf(A,y)}static msm(y,w){return K8(A,i,y,w)}static fromPrivateKey(y){return A.BASE.multiply(os(i,y))}}A.BASE=new A(s.Gx,s.Gy,r.ONE),A.ZERO=new A(r.ZERO,r.ONE,r.ZERO),A.Fp=r,A.Fn=i;const j=i.BITS,q=new H8(A,e.endo?Math.ceil(j/2):j);return A.BASE.precompute(8),A}function _p(t){return Uint8Array.of(t?2:3)}function Ip(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function J8(t,e={}){const{Fn:n}=t,r=e.randomBytes||Z0,i=Object.assign(Ip(t.Fp,n),{seed:hp(n.ORDER)});function s(d){try{return!!os(n,d)}catch{return!1}}function o(d,p){const{publicKey:b,publicKeyUncompressed:v}=i;try{const O=d.length;return p===!0&&O!==b||p===!1&&O!==v?!1:!!t.fromBytes(d)}catch{return!1}}function a(d=r(i.seed)){return U8(xi(d,i.seed,"seed"),n.ORDER)}function c(d,p=!0){return t.BASE.multiply(os(n,d)).toBytes(p)}function f(d){const p=a(d);return{secretKey:p,publicKey:c(p)}}function u(d){if(typeof d=="bigint")return!1;if(d instanceof t)return!0;const{secretKey:p,publicKey:b,publicKeyUncompressed:v}=i;if(n.allowedLengths||p===b)return;const O=It("key",d).length;return O===b||O===v}function h(d,p,b=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(p)===!1)throw new Error("second arg must be public key");const v=os(n,d);return t.fromHex(p).multiply(v).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=>os(n,d),precompute(d=8,p=t.BASE){return p.precompute(d,!1)}},lengths:i})}function Q8(t,e,n={}){H0(e),Xf(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Z0,i=n.hmac||((w,...g)=>gp(e,w,Sr(...g))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:f,getPublicKey:u,getSharedSecret:h,utils:l,lengths:d}=J8(t,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},b="compact";function v(w){const g=a>>ss;return w>g}function O(w,g){if(!o.isValidNot0(g))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return g}function P(w,g){ru(g);const m=d.signature,_=g==="compact"?m:g==="recovered"?m+1:void 0;return xi(w,_,`${g} signature`)}class x{constructor(g,m,_){this.r=O("r",g),this.s=O("s",m),_!=null&&(this.recovery=_),Object.freeze(this)}static fromBytes(g,m=b){P(g,m);let _;if(m==="der"){const{r:D,s:T}=Vn.toSig(xi(g));return new x(D,T)}m==="recovered"&&(_=g[0],m="compact",g=g.subarray(1));const B=o.BYTES,I=g.subarray(0,B),$=g.subarray(B,B*2);return new x(o.fromBytes(I),o.fromBytes($),_)}static fromHex(g,m){return this.fromBytes(xa(g),m)}addRecoveryBit(g){return new x(this.r,this.s,g)}recoverPublicKey(g){const m=s.ORDER,{r:_,s:B,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*xp<m&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");const D=I===2||I===3?_+a:_;if(!s.isValid(D))throw new Error("recovery id 2 or 3 invalid");const T=s.toBytes(D),F=t.fromBytes(Sr(_p((I&1)===0),T)),k=o.inv(D),N=R(It("msgHash",g)),M=o.create(-N*k),z=o.create(B*k),K=t.BASE.multiplyUnsafe(M).add(F.multiplyUnsafe(z));if(K.is0())throw new Error("point at infinify");return K.assertValidity(),K}hasHighS(){return v(this.s)}toBytes(g=b){if(ru(g),g==="der")return xa(Vn.hexFromSig(this));const m=o.toBytes(this.r),_=o.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return Sr(Uint8Array.of(this.recovery),m,_)}return Sr(m,_)}toHex(g){return rs(this.toBytes(g))}assertValidity(){}static fromCompact(g){return x.fromBytes(It("sig",g),"compact")}static fromDER(g){return x.fromBytes(It("sig",g),"der")}normalizeS(){return this.hasHighS()?new x(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return rs(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return rs(this.toBytes("compact"))}}const S=n.bits2int||function(g){if(g.length>8192)throw new Error("input is too large");const m=Sa(g),_=g.length*8-c;return _>0?m>>BigInt(_):m},R=n.bits2int_modN||function(g){return o.create(S(g))},U=Ws(c);function L(w){return S8("num < 2^"+c,w,Kn,U),o.toBytes(w)}function C(w,g){return xi(w,void 0,"message"),g?xi(e(w),void 0,"prehashed message"):w}function A(w,g,m){if(["recovered","canonical"].some(M=>M in m))throw new Error("sign() legacy options not supported");const{lowS:_,prehash:B,extraEntropy:I}=iu(m,p);w=C(w,B);const $=R(w),D=os(o,g),T=[L(D),L($)];if(I!=null&&I!==!1){const M=I===!0?r(d.secretKey):I;T.push(It("extraEntropy",M))}const F=Sr(...T),k=$;function N(M){const z=S(M);if(!o.isValidNot0(z))return;const K=o.inv(z),H=t.BASE.multiply(z).toAffine(),G=o.create(H.x);if(G===Kn)return;const ee=o.create(K*o.create(k+G*D));if(ee===Kn)return;let te=(H.x===G?0:2)|Number(H.y&ss),re=ee;return _&&v(ee)&&(re=o.neg(ee),te^=1),new x(G,re,te)}return{seed:F,k2sig:N}}function j(w,g,m={}){w=It("message",w);const{seed:_,k2sig:B}=A(w,g,m);return B8(e.outputLen,o.BYTES,i)(_,B)}function q(w){let g;const m=typeof w=="string"||ma(w),_=!m&&w!==null&&typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!m&&!_)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(_)g=new x(w.r,w.s);else if(m){try{g=x.fromBytes(It("sig",w),"der")}catch(B){if(!(B instanceof Vn.Err))throw B}if(!g)try{g=x.fromBytes(It("sig",w),"compact")}catch{return!1}}return g||!1}function E(w,g,m,_={}){const{lowS:B,prehash:I,format:$}=iu(_,p);if(m=It("publicKey",m),g=C(It("message",g),I),"strict"in _)throw new Error("options.strict was renamed to lowS");const D=$===void 0?q(w):x.fromBytes(It("sig",w),$);if(D===!1)return!1;try{const T=t.fromBytes(m);if(B&&D.hasHighS())return!1;const{r:F,s:k}=D,N=R(g),M=o.inv(k),z=o.create(N*M),K=o.create(F*M),H=t.BASE.multiplyUnsafe(z).add(T.multiplyUnsafe(K));return H.is0()?!1:o.create(H.x)===F}catch{return!1}}function y(w,g,m={}){const{prehash:_}=iu(m,p);return g=C(g,_),x.fromBytes(w,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:h,utils:l,lengths:d,Point:t,sign:j,verify:E,recoverPublicKey:y,Signature:x,hash:e})}function e6(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=Ys(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 t6(t){const{CURVE:e,curveOpts:n}=e6(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 n6(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,up(n.Fn.ORDER,n.Fn.BITS))})}function r6(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=t6(t),s=X8(e,n),o=Q8(s,r,i);return n6(t,o)}function i6(t,e){const n=r=>r6({...t,hash:r});return{...n(e),create:n}}Vf("HashToScalar-");const su={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},s6={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]},Sp=BigInt(2);function o6(t){const e=su.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,u=f*f*t%e,h=Gt(u,n,e)*u%e,l=Gt(h,n,e)*u%e,d=Gt(l,Sp,e)*f%e,p=Gt(d,i,e)*d%e,b=Gt(p,s,e)*p%e,v=Gt(b,a,e)*b%e,O=Gt(v,c,e)*v%e,P=Gt(O,a,e)*b%e,x=Gt(P,n,e)*u%e,S=Gt(x,o,e)*p%e,R=Gt(S,r,e)*f%e,U=Gt(R,Sp,e);if(!ou.eql(ou.sqr(U),t))throw new Error("Cannot find square root");return U}const ou=Ys(su.p,{sqrt:o6});i6({...su,Fp:ou,lowS:!0,endo:s6},dp);/*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) */function as(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function au(t,...e){if(!as(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 Bp(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 cu(t){if(typeof t!="function")throw new Error("function expected");return!0}function Ar(t,e){if(typeof e!="string")throw new Error(`${t}: string expected`);return!0}function cs(t){if(!Number.isSafeInteger(t))throw new Error(`invalid integer: ${t}`)}function Aa(t){if(!Array.isArray(t))throw new Error("array expected")}function Oa(t,e){if(!Bp(!0,e))throw new Error(`${t}: array of strings expected`)}function fu(t,e){if(!Bp(!1,e))throw new Error(`${t}: array of numbers expected`)}function Bt(...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 Lt(t){const e=typeof t=="string"?t.split(""):t,n=e.length;Oa("alphabet",e);const r=new Map(e.map((i,s)=>[i,s]));return{encode:i=>(Aa(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=>(Aa(i),i.map(s=>{Ar("alphabet.decode",s);const o=r.get(s);if(o===void 0)throw new Error(`Unknown letter: "${s}". Allowed: ${t}`);return o}))}}function kt(t=""){return Ar("join",t),{encode:e=>(Oa("join.decode",e),e.join(t)),decode:e=>(Ar("join.decode",e),e.split(t))}}function Da(t,e="="){return cs(t),Ar("padding",e),{encode(n){for(Oa("padding.encode",n);n.length*t%8;)n.push(e);return n},decode(n){Oa("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 $p(t){return cu(t),{encode:e=>e,decode:e=>t(e)}}function Ap(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(Aa(t),!t.length)return[];let r=0;const i=[],s=Array.from(t,a=>{if(cs(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 u=s[f],h=e*a,l=h+u;if(!Number.isSafeInteger(l)||h/e!==a||l-u!==h)throw new Error("convertRadix: carry overflow");const d=l/n;a=l%n;const p=Math.floor(d);if(s[f]=p,!Number.isSafeInteger(p)||p*n+a!==l)throw new Error("convertRadix: carry overflow");if(c)p?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 Op=(t,e)=>e===0?t:Op(e,t%e),Pa=(t,e)=>t+(e-Op(t,e)),Ra=(()=>{let t=[];for(let e=0;e<40;e++)t.push(2**e);return t})();function uu(t,e,n,r){if(Aa(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(Pa(e,n)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${n} carryBits=${Pa(e,n)}`);let i=0,s=0;const o=Ra[e],a=Ra[n]-1,c=[];for(const f of t){if(cs(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 u=Ra[s];if(u===void 0)throw new Error("invalid carry");i&=u-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 a6(t){cs(t);const e=2**8;return{encode:n=>{if(!as(n))throw new Error("radix.encode input should be Uint8Array");return Ap(Array.from(n),e,t)},decode:n=>(fu("radix.decode",n),Uint8Array.from(Ap(n,t,e)))}}function Zt(t,e=!1){if(cs(t),t<=0||t>32)throw new Error("radix2: bits should be in (0..32]");if(Pa(8,t)>32||Pa(t,8)>32)throw new Error("radix2: carry overflow");return{encode:n=>{if(!as(n))throw new Error("radix2.encode input should be Uint8Array");return uu(Array.from(n),8,t,!e)},decode:n=>(fu("radix2.decode",n),Uint8Array.from(uu(n,t,8,e)))}}function Dp(t){return cu(t),function(...e){try{return t.apply(null,e)}catch{}}}function c6(t,e){return cs(t),cu(e),{encode(n){if(!as(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(!as(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 f6=Bt(Zt(5),Lt("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"),Da(5),kt("")),Pp=typeof Uint8Array.from([]).toBase64=="function"&&typeof Uint8Array.fromBase64=="function",Rp=(t,e)=>{Ar("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"})},lu=t=>Bt(a6(58),Lt(t),kt("")),u6=lu("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"),l6=t=>Bt(c6(4,e=>t(t(e))),u6),hu=Bt(Lt("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),kt("")),Tp=[996825010,642813549,513874426,1027748829,705979059];function Xs(t){const e=t>>25;let n=(t&33554431)<<5;for(let r=0;r<Tp.length;r++)(e>>r&1)===1&&(n^=Tp[r]);return n}function Np(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=Xs(i)^o>>5}i=Xs(i);for(let s=0;s<r;s++)i=Xs(i)^t.charCodeAt(s)&31;for(let s of e)i=Xs(i)^s;for(let s=0;s<6;s++)i=Xs(i);return i^=n,hu.encode(uu([i%Ra[30]],30,5,!1))}function Up(t){const e=t==="bech32"?1:734539939,n=Zt(5),r=n.decode,i=n.encode,s=Dp(r);function o(h,l,d=90){Ar("bech32.encode prefix",h),as(l)&&(l=Array.from(l)),fu("bech32.encode",l);const p=h.length;if(p===0)throw new TypeError(`Invalid prefix length ${p}`);const b=p+7+l.length;if(d!==!1&&b>d)throw new TypeError(`Length ${b} exceeds limit ${d}`);const v=h.toLowerCase(),O=Np(v,l,e);return`${v}1${hu.encode(l)}${O}`}function a(h,l=90){Ar("bech32.decode input",h);const d=h.length;if(d<8||l!==!1&&d>l)throw new TypeError(`invalid string length: ${d} (${h}). Expected (8..${l})`);const p=h.toLowerCase();if(h!==p&&h!==h.toUpperCase())throw new Error("String must be lowercase or uppercase");const b=p.lastIndexOf("1");if(b===0||b===-1)throw new Error('Letter "1" must be present between prefix and data only');const v=p.slice(0,b),O=p.slice(b+1);if(O.length<6)throw new Error("Data must be at least 6 characters long");const P=hu.decode(O).slice(0,-6),x=Np(v,P,e);if(!O.endsWith(x))throw new Error(`Invalid checksum in ${h}: expected "${x}"`);return{prefix:v,words:P}}const c=Dp(a);function f(h){const{prefix:l,words:d}=a(h,!1);return{prefix:l,words:d,bytes:r(d)}}function u(h,l){return o(h,i(l))}return{encode:o,decode:a,encodeFromBytes:u,decodeToBytes:f,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:s,toWords:i}}const h6=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",d6={encode(t){return au(t),t.toHex()},decode(t){return Ar("hex",t),Uint8Array.fromHex(t)}};l6(dp),Vf("Bitcoin seed");function p6(t){return BE(g6(t))}function g6(t){const{payload:e,signature:n}=t,{r,s:i,yParity:s}=n,a=new r8.Signature(BigInt(r),BigInt(i)).addRecoveryBit(s).recoverPublicKey(xf(e).substring(2));return bE(a)}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function Cp(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Ta(t,...e){if(!Cp(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 Na(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 Fp(t,e){Ta(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Js(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function du(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function y6(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function b6(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Qs(t){if(typeof t=="string")t=b6(t);else if(Cp(t))t=Lp(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function Lp(t){return Uint8Array.from(t)}const Gn=16,pu=new Uint8Array(16),_n=Js(pu),w6=225,m6=(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^w6<<24&-(i&1)}},Wt=t=>(t>>>0&255)<<24|(t>>>8&255)<<16|(t>>>16&255)<<8|t>>>24&255|0;function v6(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 E6=t=>t>64*1024?8:t>1024?4:2;class kp{constructor(e,n){this.blockLen=Gn,this.outputLen=Gn,this.s0=0,this.s1=0,this.s2=0,this.s3=0,this.finished=!1,e=Qs(e),Ta(e,16);const r=y6(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:Wt(i),s1:Wt(s),s2:Wt(o),s3:Wt(a)}),{s0:i,s1:s,s2:o,s3:a}=m6(i,s,o,a);const f=E6(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,l=this.windowSize=2**f,d=[];for(let p=0;p<h;p++)for(let b=0;b<l;b++){let v=0,O=0,P=0,x=0;for(let S=0;S<f;S++){if(!(b>>>f-S-1&1))continue;const{s0:U,s1:L,s2:C,s3:A}=c[f*p+S];v^=U,O^=L,P^=C,x^=A}d.push({s0:v,s1:O,s2:P,s3:x})}this.t=d}_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,u=0,h=0;const l=(1<<s)-1;let d=0;for(const p of[e,n,r,i])for(let b=0;b<4;b++){const v=p>>>8*b&255;for(let O=8/s-1;O>=0;O--){const P=v>>>s*O&l,{s0:x,s1:S,s2:R,s3:U}=o[d*a+P];c^=x,f^=S,u^=R,h^=U,d+=1}}this.s0=c,this.s1=f,this.s2=u,this.s3=h}update(e){Na(this),e=Qs(e),Ta(e);const n=Js(e),r=Math.floor(e.length/Gn),i=e.length%Gn;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&&(pu.set(e.subarray(r*Gn)),this._updateBlock(_n[0],_n[1],_n[2],_n[3]),du(_n)),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){Na(this),Fp(e,this),this.finished=!0;const{s0:n,s1:r,s2:i,s3:s}=this,o=Js(e);return o[0]=n,o[1]=r,o[2]=i,o[3]=s,e}digest(){const e=new Uint8Array(Gn);return this.digestInto(e),this.destroy(),e}}class x6 extends kp{constructor(e,n){e=Qs(e),Ta(e);const r=v6(Lp(e));super(r,n),du(r)}update(e){e=Qs(e),Na(this);const n=Js(e),r=e.length%Gn,i=Math.floor(e.length/Gn);for(let s=0;s<i;s++)this._updateBlock(Wt(n[s*4+3]),Wt(n[s*4+2]),Wt(n[s*4+1]),Wt(n[s*4+0]));return r&&(pu.set(e.subarray(i*Gn)),this._updateBlock(Wt(_n[3]),Wt(_n[2]),Wt(_n[1]),Wt(_n[0])),du(_n)),this}digestInto(e){Na(this),Fp(e,this),this.finished=!0;const{s0:n,s1:r,s2:i,s3:s}=this,o=Js(e);return o[0]=n,o[1]=r,o[2]=i,o[3]=s,e.reverse()}}function qp(t){const e=(r,i)=>t(i,r.length).update(Qs(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}qp((t,e)=>new kp(t,e)),qp((t,e)=>new x6(t,e));const Mp=Er(BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff")),_6=Mp.create(BigInt("-3")),I6=BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b");da({a:_6,b:I6,Fp:Mp,n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5"),h:BigInt(1),lowS:!1},ia);const jp=Er(BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff")),S6=jp.create(BigInt("-3")),B6=BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef");da({a:S6,b:B6,Fp:jp,n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f"),h:BigInt(1),lowS:!1},Mv);const zp=Er(BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")),$6=zp.create(BigInt("-3")),A6=BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00");da({a:$6,b:A6,Fp:zp,n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650"),h:BigInt(1),lowS:!1,allowedPrivateKeyLengths:[130,131,132]},qv);var O6={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,u){this.fn=c,this.context=f,this.once=u||!1}function s(c,f,u,h,l){if(typeof u!="function")throw new TypeError("The listener must be a function");var d=new i(u,h||c,l),p=n?n+f:f;return c._events[p]?c._events[p].fn?c._events[p]=[c._events[p],d]:c._events[p].push(d):(c._events[p]=d,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=[],u,h;if(this._eventsCount===0)return f;for(h in u=this._events)e.call(u,h)&&f.push(n?h.slice(1):h);return Object.getOwnPropertySymbols?f.concat(Object.getOwnPropertySymbols(u)):f},a.prototype.listeners=function(f){var u=n?n+f:f,h=this._events[u];if(!h)return[];if(h.fn)return[h.fn];for(var l=0,d=h.length,p=new Array(d);l<d;l++)p[l]=h[l].fn;return p},a.prototype.listenerCount=function(f){var u=n?n+f:f,h=this._events[u];return h?h.fn?1:h.length:0},a.prototype.emit=function(f,u,h,l,d,p){var b=n?n+f:f;if(!this._events[b])return!1;var v=this._events[b],O=arguments.length,P,x;if(v.fn){switch(v.once&&this.removeListener(f,v.fn,void 0,!0),O){case 1:return v.fn.call(v.context),!0;case 2:return v.fn.call(v.context,u),!0;case 3:return v.fn.call(v.context,u,h),!0;case 4:return v.fn.call(v.context,u,h,l),!0;case 5:return v.fn.call(v.context,u,h,l,d),!0;case 6:return v.fn.call(v.context,u,h,l,d,p),!0}for(x=1,P=new Array(O-1);x<O;x++)P[x-1]=arguments[x];v.fn.apply(v.context,P)}else{var S=v.length,R;for(x=0;x<S;x++)switch(v[x].once&&this.removeListener(f,v[x].fn,void 0,!0),O){case 1:v[x].fn.call(v[x].context);break;case 2:v[x].fn.call(v[x].context,u);break;case 3:v[x].fn.call(v[x].context,u,h);break;case 4:v[x].fn.call(v[x].context,u,h,l);break;default:if(!P)for(R=1,P=new Array(O-1);R<O;R++)P[R-1]=arguments[R];v[x].fn.apply(v[x].context,P)}}return!0},a.prototype.on=function(f,u,h){return s(this,f,u,h,!1)},a.prototype.once=function(f,u,h){return s(this,f,u,h,!0)},a.prototype.removeListener=function(f,u,h,l){var d=n?n+f:f;if(!this._events[d])return this;if(!u)return o(this,d),this;var p=this._events[d];if(p.fn)p.fn===u&&(!l||p.once)&&(!h||p.context===h)&&o(this,d);else{for(var b=0,v=[],O=p.length;b<O;b++)(p[b].fn!==u||l&&!p[b].once||h&&p[b].context!==h)&&v.push(p[b]);v.length?this._events[d]=v.length===1?v[0]:v:o(this,d)}return this},a.prototype.removeAllListeners=function(f){var u;return f?(u=n?n+f:f,this._events[u]&&o(this,u)):(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})(O6);function D6(t){if(t.length>=255)throw new TypeError("Alphabet too long");const e=new Uint8Array(256);for(let f=0;f<e.length;f++)e[f]=255;for(let f=0;f<t.length;f++){const u=t.charAt(f),h=u.charCodeAt(0);if(e[h]!==255)throw new TypeError(u+" 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 u=0,h=0,l=0;const d=f.length;for(;l!==d&&f[l]===0;)l++,u++;const p=(d-l)*s+1>>>0,b=new Uint8Array(p);for(;l!==d;){let P=f[l],x=0;for(let S=p-1;(P!==0||x<h)&&S!==-1;S--,x++)P+=256*b[S]>>>0,b[S]=P%n>>>0,P=P/n>>>0;if(P!==0)throw new Error("Non-zero carry");h=x,l++}let v=p-h;for(;v!==p&&b[v]===0;)v++;let O=r.repeat(u);for(;v<p;++v)O+=t.charAt(b[v]);return O}function a(f){if(typeof f!="string")throw new TypeError("Expected String");if(f.length===0)return new Uint8Array;let u=0,h=0,l=0;for(;f[u]===r;)h++,u++;const d=(f.length-u)*i+1>>>0,p=new Uint8Array(d);for(;u<f.length;){const P=f.charCodeAt(u);if(P>255)return;let x=e[P];if(x===255)return;let S=0;for(let R=d-1;(x!==0||S<l)&&R!==-1;R--,S++)x+=n*p[R]>>>0,p[R]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");l=S,u++}let b=d-l;for(;b!==d&&p[b]===0;)b++;const v=new Uint8Array(h+(d-b));let O=h;for(;b!==d;)v[O++]=p[b++];return v}function c(f){const u=a(f);if(u)return u;throw new Error("Non-base"+n+" character")}return{encode:o,decodeUnsafe:a,decode:c}}var P6="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz",eo=D6(P6);const R6=t=>JSON.stringify(t,(e,n)=>typeof n=="bigint"?n.toString()+"n":n),T6=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 fs(t){if(typeof t!="string")throw new Error(`Cannot safe json parse value of type ${typeof t}`);try{return T6(t)}catch{return t}}function to(t){return typeof t=="string"?t:R6(t)||""}function N6(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Hp(t,...e){if(!N6(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 Vp(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 U6(t,e){Hp(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}const us=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const gu=t=>new DataView(t.buffer,t.byteOffset,t.byteLength);function C6(t){if(typeof t!="string")throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array(new TextEncoder().encode(t))}function Kp(t){return typeof t=="string"&&(t=C6(t)),Hp(t),t}class F6{clone(){return this._cloneInto()}}function L6(t){const e=r=>t().update(Kp(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function Gp(t=32){if(us&&typeof us.getRandomValues=="function")return us.getRandomValues(new Uint8Array(t));if(us&&typeof us.randomBytes=="function")return us.randomBytes(t);throw new Error("crypto.getRandomValues must be defined")}function k6(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 q6 extends F6{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=gu(this.buffer)}update(e){Vp(this);const{view:n,buffer:r,blockLen:i}=this;e=Kp(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=gu(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){Vp(this),U6(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;k6(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=gu(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,u[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 Ua=BigInt(2**32-1),yu=BigInt(32);function Zp(t,e=!1){return e?{h:Number(t&Ua),l:Number(t>>yu&Ua)}:{h:Number(t>>yu&Ua)|0,l:Number(t&Ua)|0}}function M6(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}=Zp(t[i],e);[n[i],r[i]]=[s,o]}return[n,r]}const j6=(t,e)=>BigInt(t>>>0)<<yu|BigInt(e>>>0),z6=(t,e,n)=>t>>>n,H6=(t,e,n)=>t<<32-n|e>>>n,V6=(t,e,n)=>t>>>n|e<<32-n,K6=(t,e,n)=>t<<32-n|e>>>n,G6=(t,e,n)=>t<<64-n|e>>>n-32,Z6=(t,e,n)=>t>>>n-32|e<<64-n,W6=(t,e)=>e,Y6=(t,e)=>t,X6=(t,e,n)=>t<<n|e>>>32-n,J6=(t,e,n)=>e<<n|t>>>32-n,Q6=(t,e,n)=>e<<n-32|t>>>64-n,ex=(t,e,n)=>t<<n-32|e>>>64-n;function tx(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const nx=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),rx=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,ix=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),sx=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,ox=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),ax=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,ie={fromBig:Zp,split:M6,toBig:j6,shrSH:z6,shrSL:H6,rotrSH:V6,rotrSL:K6,rotrBH:G6,rotrBL:Z6,rotr32H:W6,rotr32L:Y6,rotlSH:X6,rotlSL:J6,rotlBH:Q6,rotlBL:ex,add:tx,add3L:nx,add3H:rx,add4L:ix,add4H:sx,add5H:ax,add5L:ox},[cx,fx]=ie.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))),Or=new Uint32Array(80),Dr=new Uint32Array(80);class ux extends q6{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:u,Fh:h,Fl:l,Gh:d,Gl:p,Hh:b,Hl:v}=this;return[e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,v]}set(e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,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=f|0,this.El=u|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=b|0,this.Hl=v|0}process(e,n){for(let x=0;x<16;x++,n+=4)Or[x]=e.getUint32(n),Dr[x]=e.getUint32(n+=4);for(let x=16;x<80;x++){const S=Or[x-15]|0,R=Dr[x-15]|0,U=ie.rotrSH(S,R,1)^ie.rotrSH(S,R,8)^ie.shrSH(S,R,7),L=ie.rotrSL(S,R,1)^ie.rotrSL(S,R,8)^ie.shrSL(S,R,7),C=Or[x-2]|0,A=Dr[x-2]|0,j=ie.rotrSH(C,A,19)^ie.rotrBH(C,A,61)^ie.shrSH(C,A,6),q=ie.rotrSL(C,A,19)^ie.rotrBL(C,A,61)^ie.shrSL(C,A,6),E=ie.add4L(L,q,Dr[x-7],Dr[x-16]),y=ie.add4H(E,U,j,Or[x-7],Or[x-16]);Or[x]=y|0,Dr[x]=E|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:l,Fh:d,Fl:p,Gh:b,Gl:v,Hh:O,Hl:P}=this;for(let x=0;x<80;x++){const S=ie.rotrSH(h,l,14)^ie.rotrSH(h,l,18)^ie.rotrBH(h,l,41),R=ie.rotrSL(h,l,14)^ie.rotrSL(h,l,18)^ie.rotrBL(h,l,41),U=h&d^~h&b,L=l&p^~l&v,C=ie.add5L(P,R,L,fx[x],Dr[x]),A=ie.add5H(C,O,S,U,cx[x],Or[x]),j=C|0,q=ie.rotrSH(r,i,28)^ie.rotrBH(r,i,34)^ie.rotrBH(r,i,39),E=ie.rotrSL(r,i,28)^ie.rotrBL(r,i,34)^ie.rotrBL(r,i,39),y=r&s^r&a^s&a,w=i&o^i&c^o&c;O=b|0,P=v|0,b=d|0,v=p|0,d=h|0,p=l|0,{h,l}=ie.add(f|0,u|0,A|0,j|0),f=a|0,u=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=ie.add3L(j,E,w);r=ie.add3H(g,A,q,y),i=g|0}({h:r,l:i}=ie.add(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=ie.add(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=ie.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=ie.add(this.Dh|0,this.Dl|0,f|0,u|0),{h,l}=ie.add(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=ie.add(this.Fh|0,this.Fl|0,d|0,p|0),{h:b,l:v}=ie.add(this.Gh|0,this.Gl|0,b|0,v|0),{h:O,l:P}=ie.add(this.Hh|0,this.Hl|0,O|0,P|0),this.set(r,i,s,o,a,c,f,u,h,l,d,p,b,v,O,P)}roundClean(){Or.fill(0),Dr.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 lx=L6(()=>new ux);/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */const bu=BigInt(0),Wp=BigInt(1),hx=BigInt(2);function wu(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function mu(t){if(!wu(t))throw new Error("Uint8Array expected")}function vu(t,e){if(typeof e!="boolean")throw new Error(t+" boolean expected, got "+e)}const dx=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Eu(t){mu(t);let e="";for(let n=0;n<t.length;n++)e+=dx[t[n]];return e}function Yp(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?bu:BigInt("0x"+t)}const Zn={_0:48,_9:57,A:65,F:70,a:97,f:102};function Xp(t){if(t>=Zn._0&&t<=Zn._9)return t-Zn._0;if(t>=Zn.A&&t<=Zn.F)return t-(Zn.A-10);if(t>=Zn.a&&t<=Zn.f)return t-(Zn.a-10)}function Jp(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=Xp(t.charCodeAt(s)),a=Xp(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 px(t){return Yp(Eu(t))}function Ca(t){return mu(t),Yp(Eu(Uint8Array.from(t).reverse()))}function Qp(t,e){return Jp(t.toString(16).padStart(e*2,"0"))}function xu(t,e){return Qp(t,e).reverse()}function Wn(t,e,n){let r;if(typeof e=="string")try{r=Jp(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(wu(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 eg(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];mu(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 _u=t=>typeof t=="bigint"&&bu<=t;function gx(t,e,n){return _u(t)&&_u(e)&&_u(n)&&e<=t&&t<n}function no(t,e,n,r){if(!gx(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function yx(t){let e;for(e=0;t>bu;t>>=Wp,e+=1);return e}const bx=t=>(hx<<BigInt(t-1))-Wp,wx={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"||wu(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 Iu(t,e,n={}){const r=(i,s,o)=>{const a=wx[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 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 ke=BigInt(0),$e=BigInt(1),Si=BigInt(2),mx=BigInt(3),Su=BigInt(4),ng=BigInt(5),rg=BigInt(8);function Te(t,e){const n=t%e;return n>=ke?n:e+n}function vx(t,e,n){if(e<ke)throw new Error("invalid exponent, negatives unsupported");if(n<=ke)throw new Error("invalid modulus");if(n===$e)return ke;let r=$e;for(;e>ke;)e&$e&&(r=r*t%n),t=t*t%n,e>>=$e;return r}function In(t,e,n){let r=t;for(;e-- >ke;)r*=r,r%=n;return r}function ig(t,e){if(t===ke)throw new Error("invert: expected non-zero number");if(e<=ke)throw new Error("invert: expected positive modulus, got "+e);let n=Te(t,e),r=e,i=ke,s=$e;for(;n!==ke;){const o=r/n,a=r%n,c=i-s*o;r=n,n=a,i=s,s=c}if(r!==$e)throw new Error("invert: does not exist");return Te(i,e)}function Ex(t){const e=(t-$e)/Si;let n,r,i;for(n=t-$e,r=0;n%Si===ke;n/=Si,r++);for(i=Si;i<t&&vx(i,e,t)!==t-$e;i++)if(i>1e3)throw new Error("Cannot find square root: likely non-prime P");if(r===1){const o=(t+$e)/Su;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+$e)/Si;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),u=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 l=1;for(let p=o.sqr(h);l<c&&!o.eql(p,o.ONE);l++)p=o.sqr(p);const d=o.pow(f,$e<<BigInt(c-l-1));f=o.sqr(d),u=o.mul(u,d),h=o.mul(h,f),c=l}return u}}function xx(t){if(t%Su===mx){const e=(t+$e)/Su;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%rg===ng){const e=(t-ng)/rg;return function(n,r){const i=n.mul(r,Si),s=n.pow(i,e),o=n.mul(r,s),a=n.mul(n.mul(o,Si),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 Ex(t)}const _x=(t,e)=>(Te(t,e)&$e)===$e,Ix=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Sx(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},n=Ix.reduce((r,i)=>(r[i]="function",r),e);return Iu(t,n)}function Bx(t,e,n){if(n<ke)throw new Error("invalid exponent, negatives unsupported");if(n===ke)return t.ONE;if(n===$e)return e;let r=t.ONE,i=e;for(;n>ke;)n&$e&&(r=t.mul(r,i)),i=t.sqr(i),n>>=$e;return r}function $x(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 sg(t,e){const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function og(t,e,n=!1,r={}){if(t<=ke)throw new Error("invalid field: expected ORDER > 0, got "+t);const{nBitLength:i,nByteLength:s}=sg(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:bx(i),ZERO:ke,ONE:$e,create:c=>Te(c,t),isValid:c=>{if(typeof c!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof c);return ke<=c&&c<t},is0:c=>c===ke,isOdd:c=>(c&$e)===$e,neg:c=>Te(-c,t),eql:(c,f)=>c===f,sqr:c=>Te(c*c,t),add:(c,f)=>Te(c+f,t),sub:(c,f)=>Te(c-f,t),mul:(c,f)=>Te(c*f,t),pow:(c,f)=>Bx(a,c,f),div:(c,f)=>Te(c*ig(f,t),t),sqrN:c=>c*c,addN:(c,f)=>c+f,subN:(c,f)=>c-f,mulN:(c,f)=>c*f,inv:c=>ig(c,t),sqrt:r.sqrt||(c=>(o||(o=xx(t)),o(a,c))),invertBatch:c=>$x(a,c),cmov:(c,f,u)=>u?f:c,toBytes:c=>n?xu(c,s):Qp(c,s),fromBytes:c=>{if(c.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+c.length);return n?Ca(c):px(c)}});return Object.freeze(a)}const ag=BigInt(0),Fa=BigInt(1);function Bu(t,e){const n=e.negate();return t?n:e}function cg(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function $u(t,e){cg(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1);return{windows:n,windowSize:r}}function Ax(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 Ox(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 Au=new WeakMap,fg=new WeakMap;function Ou(t){return fg.get(t)||1}function Dx(t,e){return{constTimeNegate:Bu,hasPrecomputes(n){return Ou(n)!==1},unsafeLadder(n,r,i=t.ZERO){let s=n;for(;r>ag;)r&Fa&&(i=i.add(s)),s=s.double(),r>>=Fa;return i},precomputeWindow(n,r){const{windows:i,windowSize:s}=$u(r,e),o=[];let a=n,c=a;for(let f=0;f<i;f++){c=a,o.push(c);for(let u=1;u<s;u++)c=c.add(a),o.push(c);a=c.double()}return o},wNAF(n,r,i){const{windows:s,windowSize:o}=$u(n,e);let a=t.ZERO,c=t.BASE;const f=BigInt(2**n-1),u=2**n,h=BigInt(n);for(let l=0;l<s;l++){const d=l*o;let p=Number(i&f);i>>=h,p>o&&(p-=u,i+=Fa);const b=d,v=d+Math.abs(p)-1,O=l%2!==0,P=p<0;p===0?c=c.add(Bu(O,r[b])):a=a.add(Bu(P,r[v]))}return{p:a,f:c}},wNAFUnsafe(n,r,i,s=t.ZERO){const{windows:o,windowSize:a}=$u(n,e),c=BigInt(2**n-1),f=2**n,u=BigInt(n);for(let h=0;h<o;h++){const l=h*a;if(i===ag)break;let d=Number(i&c);if(i>>=u,d>a&&(d-=f,i+=Fa),d===0)continue;let p=r[l+Math.abs(d)-1];d<0&&(p=p.negate()),s=s.add(p)}return s},getPrecomputes(n,r,i){let s=Au.get(r);return s||(s=this.precomputeWindow(r,n),n!==1&&Au.set(r,i(s))),s},wNAFCached(n,r,i){const s=Ou(n);return this.wNAF(s,this.getPrecomputes(s,n,i),r)},wNAFCachedUnsafe(n,r,i,s){const o=Ou(n);return o===1?this.unsafeLadder(n,r,s):this.wNAFUnsafe(o,this.getPrecomputes(o,n,i),r,s)},setWindowSize(n,r){cg(r,e),fg.set(n,r),Au.delete(n)}}}function Px(t,e,n,r){if(Ax(n,t),Ox(r,e),n.length!==r.length)throw new Error("arrays of points and scalars must have equal length");const i=t.ZERO,s=yx(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 u=i;for(let h=f;h>=0;h-=o){c.fill(i);for(let d=0;d<r.length;d++){const p=r[d],b=Number(p>>BigInt(h)&BigInt(a));c[b]=c[b].add(n[d])}let l=i;for(let d=c.length-1,p=i;d>0;d--)p=p.add(c[d]),l=l.add(p);if(u=u.add(l),h!==0)for(let d=0;d<o;d++)u=u.double()}return u}function Rx(t){return Sx(t.Fp),Iu(t,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...sg(t.n,t.nBitLength),...t,p:t.Fp.ORDER})}const an=BigInt(0),$t=BigInt(1),La=BigInt(2),Tx=BigInt(8),Nx={zip215:!0};function Ux(t){const e=Rx(t);return Iu(t,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function Cx(t){const e=Ux(t),{Fp:n,n:r,prehash:i,hash:s,randomBytes:o,nByteLength:a,h:c}=e,f=La<<BigInt(a*8)-$t,u=n.create,h=og(e.n,e.nBitLength),l=e.uvRatio||((g,m)=>{try{return{isValid:!0,value:n.sqrt(g*n.inv(m))}}catch{return{isValid:!1,value:an}}}),d=e.adjustScalarBytes||(g=>g),p=e.domain||((g,m,_)=>{if(vu("phflag",_),m.length||_)throw new Error("Contexts/pre-hash are not supported");return g});function b(g,m){no("coordinate "+g,m,an,f)}function v(g){if(!(g instanceof x))throw new Error("ExtendedPoint expected")}const O=tg((g,m)=>{const{ex:_,ey:B,ez:I}=g,$=g.is0();m==null&&(m=$?Tx:n.inv(I));const D=u(_*m),T=u(B*m),F=u(I*m);if($)return{x:an,y:$t};if(F!==$t)throw new Error("invZ was invalid");return{x:D,y:T}}),P=tg(g=>{const{a:m,d:_}=e;if(g.is0())throw new Error("bad point: ZERO");const{ex:B,ey:I,ez:$,et:D}=g,T=u(B*B),F=u(I*I),k=u($*$),N=u(k*k),M=u(T*m),z=u(k*u(M+F)),K=u(N+u(_*u(T*F)));if(z!==K)throw new Error("bad point: equation left != right (1)");const H=u(B*I),G=u($*D);if(H!==G)throw new Error("bad point: equation left != right (2)");return!0});class x{constructor(m,_,B,I){this.ex=m,this.ey=_,this.ez=B,this.et=I,b("x",m),b("y",_),b("z",B),b("t",I),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof x)throw new Error("extended point not allowed");const{x:_,y:B}=m||{};return b("x",_),b("y",B),new x(_,B,$t,u(_*B))}static normalizeZ(m){const _=n.invertBatch(m.map(B=>B.ez));return m.map((B,I)=>B.toAffine(_[I])).map(x.fromAffine)}static msm(m,_){return Px(x,h,m,_)}_setWindowSize(m){U.setWindowSize(this,m)}assertValidity(){P(this)}equals(m){v(m);const{ex:_,ey:B,ez:I}=this,{ex:$,ey:D,ez:T}=m,F=u(_*T),k=u($*I),N=u(B*T),M=u(D*I);return F===k&&N===M}is0(){return this.equals(x.ZERO)}negate(){return new x(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){const{a:m}=e,{ex:_,ey:B,ez:I}=this,$=u(_*_),D=u(B*B),T=u(La*u(I*I)),F=u(m*$),k=_+B,N=u(u(k*k)-$-D),M=F+D,z=M-T,K=F-D,H=u(N*z),G=u(M*K),ee=u(N*K),te=u(z*M);return new x(H,G,te,ee)}add(m){v(m);const{a:_,d:B}=e,{ex:I,ey:$,ez:D,et:T}=this,{ex:F,ey:k,ez:N,et:M}=m;if(_===BigInt(-1)){const t2=u(($-I)*(k+F)),n2=u(($+I)*(k-F)),Vh=u(n2-t2);if(Vh===an)return this.double();const r2=u(D*La*M),i2=u(T*La*N),s2=i2+r2,o2=n2+t2,a2=i2-r2,CU=u(s2*Vh),FU=u(o2*a2),LU=u(s2*a2),kU=u(Vh*o2);return new x(CU,FU,kU,LU)}const z=u(I*F),K=u($*k),H=u(T*B*M),G=u(D*N),ee=u((I+$)*(F+k)-z-K),te=G-H,re=G+H,ce=u(K-_*z),Ie=u(ee*te),lr=u(re*ce),Gc=u(ee*ce),UU=u(te*re);return new x(Ie,lr,UU,Gc)}subtract(m){return this.add(m.negate())}wNAF(m){return U.wNAFCached(this,m,x.normalizeZ)}multiply(m){const _=m;no("scalar",_,$t,r);const{p:B,f:I}=this.wNAF(_);return x.normalizeZ([B,I])[0]}multiplyUnsafe(m,_=x.ZERO){const B=m;return no("scalar",B,an,r),B===an?R:this.is0()||B===$t?this:U.wNAFCachedUnsafe(this,B,x.normalizeZ,_)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return U.unsafeLadder(this,r).is0()}toAffine(m){return O(this,m)}clearCofactor(){const{h:m}=e;return m===$t?this:this.multiplyUnsafe(m)}static fromHex(m,_=!1){const{d:B,a:I}=e,$=n.BYTES;m=Wn("pointHex",m,$),vu("zip215",_);const D=m.slice(),T=m[$-1];D[$-1]=T&-129;const F=Ca(D),k=_?f:n.ORDER;no("pointHex.y",F,an,k);const N=u(F*F),M=u(N-$t),z=u(B*N-I);let{isValid:K,value:H}=l(M,z);if(!K)throw new Error("Point.fromHex: invalid y coordinate");const G=(H&$t)===$t,ee=(T&128)!==0;if(!_&&H===an&&ee)throw new Error("Point.fromHex: x=0 and x_0=1");return ee!==G&&(H=u(-H)),x.fromAffine({x:H,y:F})}static fromPrivateKey(m){return A(m).point}toRawBytes(){const{x:m,y:_}=this.toAffine(),B=xu(_,n.BYTES);return B[B.length-1]|=m&$t?128:0,B}toHex(){return Eu(this.toRawBytes())}}x.BASE=new x(e.Gx,e.Gy,$t,u(e.Gx*e.Gy)),x.ZERO=new x(an,$t,$t,an);const{BASE:S,ZERO:R}=x,U=Dx(x,a*8);function L(g){return Te(g,r)}function C(g){return L(Ca(g))}function A(g){const m=n.BYTES;g=Wn("private key",g,m);const _=Wn("hashed private key",s(g),2*m),B=d(_.slice(0,m)),I=_.slice(m,2*m),$=C(B),D=S.multiply($),T=D.toRawBytes();return{head:B,prefix:I,scalar:$,point:D,pointBytes:T}}function j(g){return A(g).pointBytes}function q(g=new Uint8Array,...m){const _=eg(...m);return C(s(p(_,Wn("context",g),!!i)))}function E(g,m,_={}){g=Wn("message",g),i&&(g=i(g));const{prefix:B,scalar:I,pointBytes:$}=A(m),D=q(_.context,B,g),T=S.multiply(D).toRawBytes(),F=q(_.context,T,$,g),k=L(D+F*I);no("signature.s",k,an,r);const N=eg(T,xu(k,n.BYTES));return Wn("result",N,n.BYTES*2)}const y=Nx;function w(g,m,_,B=y){const{context:I,zip215:$}=B,D=n.BYTES;g=Wn("signature",g,2*D),m=Wn("message",m),_=Wn("publicKey",_,D),$!==void 0&&vu("zip215",$),i&&(m=i(m));const T=Ca(g.slice(D,2*D));let F,k,N;try{F=x.fromHex(_,$),k=x.fromHex(g.slice(0,D),$),N=S.multiplyUnsafe(T)}catch{return!1}if(!$&&F.isSmallOrder())return!1;const M=q(I,k.toRawBytes(),F.toRawBytes(),m);return k.add(F.multiplyUnsafe(M)).subtract(N).clearCofactor().equals(x.ZERO)}return S._setWindowSize(8),{CURVE:e,getPublicKey:j,sign:E,verify:w,ExtendedPoint:x,utils:{getExtendedPublicKey:A,randomPrivateKey:()=>o(n.BYTES),precompute(g=8,m=x.BASE){return m._setWindowSize(g),m.multiply(BigInt(3)),m}}}}BigInt(0),BigInt(1);const Du=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),ug=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");BigInt(0);const Fx=BigInt(1),lg=BigInt(2);BigInt(3);const Lx=BigInt(5),kx=BigInt(8);function qx(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=Du,o=t*t%s*t%s,a=In(o,lg,s)*o%s,c=In(a,Fx,s)*t%s,f=In(c,Lx,s)*c%s,u=In(f,e,s)*f%s,h=In(u,n,s)*u%s,l=In(h,r,s)*h%s,d=In(l,i,s)*l%s,p=In(d,i,s)*l%s,b=In(p,e,s)*f%s;return{pow_p_5_8:In(b,lg,s)*t%s,b2:o}}function Mx(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}function jx(t,e){const n=Du,r=Te(e*e*e,n),i=Te(r*r*e,n),s=qx(t*i).pow_p_5_8;let o=Te(t*r*s,n);const a=Te(e*o*o,n),c=o,f=Te(o*ug,n),u=a===t,h=a===Te(-t,n),l=a===Te(-t*ug,n);return u&&(o=c),(h||l)&&(o=f),_x(o,n)&&(o=Te(-o,n)),{isValid:u||h,value:o}}const zx=og(Du,void 0,!0),Hx={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:zx,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:kx,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:lx,randomBytes:Gp,adjustScalarBytes:Mx,uvRatio:jx},hg=Cx(Hx),Vx="EdDSA",Kx="JWT",ka=".",qa="base64url",dg="utf8",pg="utf8",Gx=":",Zx="did",Wx="key",gg="base58btc",Yx="z",Xx="K36",Jx=32;function Pu(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function yg(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Pu(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function bg(t,e){e||(e=t.reduce((i,s)=>i+s.length,0));const n=yg(e);let r=0;for(const i of t)n.set(i,r),r+=i.length;return Pu(n)}function Qx(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),u=Math.log(256)/Math.log(a);function h(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 b=0,v=0,O=0,P=p.length;O!==P&&p[O]===0;)O++,b++;for(var x=(P-O)*u+1>>>0,S=new Uint8Array(x);O!==P;){for(var R=p[O],U=0,L=x-1;(R!==0||U<v)&&L!==-1;L--,U++)R+=256*S[L]>>>0,S[L]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");v=U,O++}for(var C=x-v;C!==x&&S[C]===0;)C++;for(var A=c.repeat(b);C<x;++C)A+=t.charAt(S[C]);return A}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var v=0,O=0;p[b]===c;)v++,b++;for(var P=(p.length-b)*f+1>>>0,x=new Uint8Array(P);p[b];){var S=n[p.charCodeAt(b)];if(S===255)return;for(var R=0,U=P-1;(S!==0||R<O)&&U!==-1;U--,R++)S+=a*x[U]>>>0,x[U]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");O=R,b++}if(p[b]!==" "){for(var L=P-O;L!==P&&x[L]===0;)L++;for(var C=new Uint8Array(v+(P-L)),A=v;L!==P;)C[A++]=x[L++];return C}}}function d(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var e4=Qx,t4=e4;const wg=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")},n4=t=>new TextEncoder().encode(t),r4=t=>new TextDecoder().decode(t);class i4{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 s4{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 mg(this,e)}}class o4{constructor(e){this.decoders=e}or(e){return mg(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 mg=(t,e)=>new o4({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class a4{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new i4(e,n,r),this.decoder=new s4(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Ma=({name:t,prefix:e,encode:n,decode:r})=>new a4(t,e,n,r),ro=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=t4(n,e);return Ma({prefix:t,name:e,encode:r,decode:s=>wg(i(s))})},c4=(t,e,n,r)=>{const i={};for(let u=0;u<e.length;++u)i[e[u]]=u;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 u=0;u<s;++u){const h=i[t[u]];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},f4=(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},He=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>Ma({prefix:e,name:t,encode(i){return f4(i,r,n)},decode(i){return c4(i,r,n,t)}}),u4=Ma({prefix:"\0",name:"identity",encode:t=>r4(t),decode:t=>n4(t)});var l4=Object.freeze({__proto__:null,identity:u4});const h4=He({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var d4=Object.freeze({__proto__:null,base2:h4});const p4=He({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var g4=Object.freeze({__proto__:null,base8:p4});const y4=ro({prefix:"9",name:"base10",alphabet:"0123456789"});var b4=Object.freeze({__proto__:null,base10:y4});const w4=He({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),m4=He({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var v4=Object.freeze({__proto__:null,base16:w4,base16upper:m4});const E4=He({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),x4=He({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),_4=He({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),I4=He({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),S4=He({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),B4=He({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),$4=He({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),A4=He({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),O4=He({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var D4=Object.freeze({__proto__:null,base32:E4,base32upper:x4,base32pad:_4,base32padupper:I4,base32hex:S4,base32hexupper:B4,base32hexpad:$4,base32hexpadupper:A4,base32z:O4});const P4=ro({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),R4=ro({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var T4=Object.freeze({__proto__:null,base36:P4,base36upper:R4});const N4=ro({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),U4=ro({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var C4=Object.freeze({__proto__:null,base58btc:N4,base58flickr:U4});const F4=He({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),L4=He({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),k4=He({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),q4=He({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var M4=Object.freeze({__proto__:null,base64:F4,base64pad:L4,base64url:k4,base64urlpad:q4});const vg=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}"),j4=vg.reduce((t,e,n)=>(t[n]=e,t),[]),z4=vg.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function H4(t){return t.reduce((e,n)=>(e+=j4[n],e),"")}function V4(t){const e=[];for(const n of t){const r=z4[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const K4=Ma({prefix:"\u{1F680}",name:"base256emoji",encode:H4,decode:V4});var G4=Object.freeze({__proto__:null,base256emoji:K4}),Z4=xg,Eg=128,W4=127,Y4=~W4,X4=Math.pow(2,31);function xg(t,e,n){e=e||[],n=n||0;for(var r=n;t>=X4;)e[n++]=t&255|Eg,t/=128;for(;t&Y4;)e[n++]=t&255|Eg,t>>>=7;return e[n]=t|0,xg.bytes=n-r+1,e}var J4=Ru,Q4=128,_g=127;function Ru(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw Ru.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&_g)<<i:(o&_g)*Math.pow(2,i),i+=7}while(o>=Q4);return Ru.bytes=s-r,n}var e5=Math.pow(2,7),t5=Math.pow(2,14),n5=Math.pow(2,21),r5=Math.pow(2,28),i5=Math.pow(2,35),s5=Math.pow(2,42),o5=Math.pow(2,49),a5=Math.pow(2,56),c5=Math.pow(2,63),f5=function(t){return t<e5?1:t<t5?2:t<n5?3:t<r5?4:t<i5?5:t<s5?6:t<o5?7:t<a5?8:t<c5?9:10},u5={encode:Z4,decode:J4,encodingLength:f5},Ig=u5;const Sg=(t,e,n=0)=>(Ig.encode(t,e,n),e),Bg=t=>Ig.encodingLength(t),Tu=(t,e)=>{const n=e.byteLength,r=Bg(t),i=r+Bg(n),s=new Uint8Array(i+n);return Sg(t,s,0),Sg(n,s,r),s.set(e,i),new l5(t,n,e,s)};class l5{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const $g=({name:t,code:e,encode:n})=>new h5(t,e,n);class h5{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?Tu(this.code,n):n.then(r=>Tu(this.code,r))}else throw Error("Unknown type, must be binary type")}}const Ag=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),d5=$g({name:"sha2-256",code:18,encode:Ag("SHA-256")}),p5=$g({name:"sha2-512",code:19,encode:Ag("SHA-512")});var g5=Object.freeze({__proto__:null,sha256:d5,sha512:p5});const Og=0,y5="identity",Dg=wg;var b5=Object.freeze({__proto__:null,identity:{code:Og,name:y5,encode:Dg,digest:t=>Tu(Og,Dg(t))}});new TextEncoder,new TextDecoder;const Pg={...l4,...d4,...g4,...b4,...v4,...D4,...T4,...C4,...M4,...G4};({...g5,...b5});function Rg(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const Tg=Rg("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Nu=Rg("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=yg(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),Ng={utf8:Tg,"utf-8":Tg,hex:Pg.base16,latin1:Nu,ascii:Nu,binary:Nu,...Pg};function ja(t,e="utf8"){const n=Ng[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 ls(t,e="utf8"){const n=Ng[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Pu(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}function Ug(t){return fs(ja(ls(t,qa),dg))}function za(t){return ja(ls(to(t),dg),qa)}function Cg(t){const e=ls(Xx,gg),n=Yx+ja(bg([e,t]),gg);return[Zx,Wx,n].join(Gx)}function w5(t){return ja(t,qa)}function m5(t){return ls(t,qa)}function v5(t){return ls([za(t.header),za(t.payload)].join(ka),pg)}function E5(t){return[za(t.header),za(t.payload),w5(t.signature)].join(ka)}function Uu(t){const e=t.split(ka),n=Ug(e[0]),r=Ug(e[1]),i=m5(e[2]),s=ls(e.slice(0,2).join(ka),pg);return{header:n,payload:r,signature:i,data:s}}function Fg(t=Gp(Jx)){const e=hg.getPublicKey(t);return{secretKey:bg([t,e]),publicKey:e}}async function x5(t,e,n,r,i=Z.fromMiliseconds(Date.now())){const s={alg:Vx,typ:Kx},o=Cg(r.publicKey),a=i+n,c={iss:o,sub:t,aud:e,iat:i,exp:a},f=v5({header:s,payload:c}),u=hg.sign(f,r.secretKey.slice(0,32));return E5({header:s,payload:c,signature:u})}function Cu(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function Lg(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?Cu(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function io(t,e){e||(e=t.reduce((i,s)=>i+s.length,0));const n=Lg(e);let r=0;for(const i of t)n.set(i,r),r+=i.length;return Cu(n)}function _5(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),u=Math.log(256)/Math.log(a);function h(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 b=0,v=0,O=0,P=p.length;O!==P&&p[O]===0;)O++,b++;for(var x=(P-O)*u+1>>>0,S=new Uint8Array(x);O!==P;){for(var R=p[O],U=0,L=x-1;(R!==0||U<v)&&L!==-1;L--,U++)R+=256*S[L]>>>0,S[L]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");v=U,O++}for(var C=x-v;C!==x&&S[C]===0;)C++;for(var A=c.repeat(b);C<x;++C)A+=t.charAt(S[C]);return A}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var v=0,O=0;p[b]===c;)v++,b++;for(var P=(p.length-b)*f+1>>>0,x=new Uint8Array(P);p[b];){var S=n[p.charCodeAt(b)];if(S===255)return;for(var R=0,U=P-1;(S!==0||R<O)&&U!==-1;U--,R++)S+=a*x[U]>>>0,x[U]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");O=R,b++}if(p[b]!==" "){for(var L=P-O;L!==P&&x[L]===0;)L++;for(var C=new Uint8Array(v+(P-L)),A=v;L!==P;)C[A++]=x[L++];return C}}}function d(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var I5=_5,S5=I5;const kg=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")},B5=t=>new TextEncoder().encode(t),$5=t=>new TextDecoder().decode(t);class A5{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 O5{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 qg(this,e)}}class D5{constructor(e){this.decoders=e}or(e){return qg(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 qg=(t,e)=>new D5({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class P5{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new A5(e,n,r),this.decoder=new O5(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Ha=({name:t,prefix:e,encode:n,decode:r})=>new P5(t,e,n,r),so=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=S5(n,e);return Ha({prefix:t,name:e,encode:r,decode:s=>kg(i(s))})},R5=(t,e,n,r)=>{const i={};for(let u=0;u<e.length;++u)i[e[u]]=u;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 u=0;u<s;++u){const h=i[t[u]];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},T5=(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},Ve=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>Ha({prefix:e,name:t,encode(i){return T5(i,r,n)},decode(i){return R5(i,r,n,t)}}),N5=Ha({prefix:"\0",name:"identity",encode:t=>$5(t),decode:t=>B5(t)});var U5=Object.freeze({__proto__:null,identity:N5});const C5=Ve({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var F5=Object.freeze({__proto__:null,base2:C5});const L5=Ve({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var k5=Object.freeze({__proto__:null,base8:L5});const q5=so({prefix:"9",name:"base10",alphabet:"0123456789"});var M5=Object.freeze({__proto__:null,base10:q5});const j5=Ve({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),z5=Ve({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var H5=Object.freeze({__proto__:null,base16:j5,base16upper:z5});const V5=Ve({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),K5=Ve({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),G5=Ve({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Z5=Ve({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),W5=Ve({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Y5=Ve({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),X5=Ve({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),J5=Ve({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Q5=Ve({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var e_=Object.freeze({__proto__:null,base32:V5,base32upper:K5,base32pad:G5,base32padupper:Z5,base32hex:W5,base32hexupper:Y5,base32hexpad:X5,base32hexpadupper:J5,base32z:Q5});const t_=so({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),n_=so({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var r_=Object.freeze({__proto__:null,base36:t_,base36upper:n_});const i_=so({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),s_=so({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var o_=Object.freeze({__proto__:null,base58btc:i_,base58flickr:s_});const a_=Ve({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),c_=Ve({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),f_=Ve({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),u_=Ve({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var l_=Object.freeze({__proto__:null,base64:a_,base64pad:c_,base64url:f_,base64urlpad:u_});const Mg=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}"),h_=Mg.reduce((t,e,n)=>(t[n]=e,t),[]),d_=Mg.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function p_(t){return t.reduce((e,n)=>(e+=h_[n],e),"")}function g_(t){const e=[];for(const n of t){const r=d_[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const y_=Ha({prefix:"\u{1F680}",name:"base256emoji",encode:p_,decode:g_});var b_=Object.freeze({__proto__:null,base256emoji:y_}),w_=zg,jg=128,m_=127,v_=~m_,E_=Math.pow(2,31);function zg(t,e,n){e=e||[],n=n||0;for(var r=n;t>=E_;)e[n++]=t&255|jg,t/=128;for(;t&v_;)e[n++]=t&255|jg,t>>>=7;return e[n]=t|0,zg.bytes=n-r+1,e}var x_=Fu,__=128,Hg=127;function Fu(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw Fu.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&Hg)<<i:(o&Hg)*Math.pow(2,i),i+=7}while(o>=__);return Fu.bytes=s-r,n}var I_=Math.pow(2,7),S_=Math.pow(2,14),B_=Math.pow(2,21),$_=Math.pow(2,28),A_=Math.pow(2,35),O_=Math.pow(2,42),D_=Math.pow(2,49),P_=Math.pow(2,56),R_=Math.pow(2,63),T_=function(t){return t<I_?1:t<S_?2:t<B_?3:t<$_?4:t<A_?5:t<O_?6:t<D_?7:t<P_?8:t<R_?9:10},N_={encode:w_,decode:x_,encodingLength:T_},Vg=N_;const Kg=(t,e,n=0)=>(Vg.encode(t,e,n),e),Gg=t=>Vg.encodingLength(t),Lu=(t,e)=>{const n=e.byteLength,r=Gg(t),i=r+Gg(n),s=new Uint8Array(i+n);return Kg(t,s,0),Kg(n,s,r),s.set(e,i),new U_(t,n,e,s)};class U_{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const Zg=({name:t,code:e,encode:n})=>new C_(t,e,n);class C_{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?Lu(this.code,n):n.then(r=>Lu(this.code,r))}else throw Error("Unknown type, must be binary type")}}const Wg=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),F_=Zg({name:"sha2-256",code:18,encode:Wg("SHA-256")}),L_=Zg({name:"sha2-512",code:19,encode:Wg("SHA-512")});var k_=Object.freeze({__proto__:null,sha256:F_,sha512:L_});const Yg=0,q_="identity",Xg=kg;var M_=Object.freeze({__proto__:null,identity:{code:Yg,name:q_,encode:Xg,digest:t=>Lu(Yg,Xg(t))}});new TextEncoder,new TextDecoder;const Jg={...U5,...F5,...k5,...M5,...H5,...e_,...r_,...o_,...l_,...b_};({...k_,...M_});function Qg(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const e1=Qg("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),ku=Qg("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=Lg(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),t1={utf8:e1,"utf-8":e1,hex:Jg.base16,latin1:ku,ascii:ku,binary:ku,...Jg};function Yt(t,e="utf8"){const n=t1[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?Cu(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}function At(t,e="utf8"){const n=t1[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 j_={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"}},z_="Input must be an string, Buffer or Uint8Array";function H_(t){let e;if(t instanceof Uint8Array)e=t;else if(typeof t=="string")e=new TextEncoder().encode(t);else throw new Error(z_);return e}function V_(t){return Array.prototype.map.call(t,function(e){return(e<16?"0":"")+e.toString(16)}).join("")}function Va(t){return(4294967296+t).toString(16).substring(1)}function K_(t,e,n){let r=`
17
+ `+t+" = ";for(let i=0;i<e.length;i+=2){if(n===32)r+=Va(e[i]).toUpperCase(),r+=" ",r+=Va(e[i+1]).toUpperCase();else if(n===64)r+=Va(e[i+1]).toUpperCase(),r+=Va(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 G_(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 n1={normalizeInput:H_,toHex:V_,debugPrint:K_,testSpeed:G_};const Ka=n1;function Ga(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 r1(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 i1(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function Pr(t,e,n,r,i,s){const o=oo[i],a=oo[i+1],c=oo[s],f=oo[s+1];Ga(ne,t,e),r1(ne,t,o,a);let u=ne[r]^ne[t],h=ne[r+1]^ne[t+1];ne[r]=h,ne[r+1]=u,Ga(ne,n,r),u=ne[e]^ne[n],h=ne[e+1]^ne[n+1],ne[e]=u>>>24^h<<8,ne[e+1]=h>>>24^u<<8,Ga(ne,t,e),r1(ne,t,c,f),u=ne[r]^ne[t],h=ne[r+1]^ne[t+1],ne[r]=u>>>16^h<<16,ne[r+1]=h>>>16^u<<16,Ga(ne,n,r),u=ne[e]^ne[n],h=ne[e+1]^ne[n+1],ne[e]=h>>>31^u<<1,ne[e+1]=u>>>31^h<<1}const s1=new Uint32Array([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),Z_=[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],rt=new Uint8Array(Z_.map(function(t){return t*2})),ne=new Uint32Array(32),oo=new Uint32Array(32);function o1(t,e){let n=0;for(n=0;n<16;n++)ne[n]=t.h[n],ne[n+16]=s1[n];for(ne[24]=ne[24]^t.t,ne[25]=ne[25]^t.t/4294967296,e&&(ne[28]=~ne[28],ne[29]=~ne[29]),n=0;n<32;n++)oo[n]=i1(t.b,4*n);for(n=0;n<12;n++)Pr(0,8,16,24,rt[n*16+0],rt[n*16+1]),Pr(2,10,18,26,rt[n*16+2],rt[n*16+3]),Pr(4,12,20,28,rt[n*16+4],rt[n*16+5]),Pr(6,14,22,30,rt[n*16+6],rt[n*16+7]),Pr(0,10,20,30,rt[n*16+8],rt[n*16+9]),Pr(2,12,22,24,rt[n*16+10],rt[n*16+11]),Pr(4,14,16,26,rt[n*16+12],rt[n*16+13]),Pr(6,8,18,28,rt[n*16+14],rt[n*16+15]);for(n=0;n<16;n++)t.h[n]=t.h[n]^ne[n]^ne[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 a1(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]=s1[s]^i1(Rr,s*4);return e&&(qu(i,e),i.c=128),i}function qu(t,e){for(let n=0;n<e.length;n++)t.c===128&&(t.t+=t.c,o1(t,!1),t.c=0),t.b[t.c++]=e[n]}function c1(t){for(t.t+=t.c;t.c<128;)t.b[t.c++]=0;o1(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 f1(t,e,n,r,i){n=n||64,t=Ka.normalizeInput(t),r&&(r=Ka.normalizeInput(r)),i&&(i=Ka.normalizeInput(i));const s=a1(n,e,r,i);return qu(s,t),c1(s)}function W_(t,e,n,r,i){const s=f1(t,e,n,r,i);return Ka.toHex(s)}var Y_={blake2b:f1,blake2bHex:W_,blake2bInit:a1,blake2bUpdate:qu,blake2bFinal:c1};const u1=n1;function X_(t,e){return t[e]^t[e+1]<<8^t[e+2]<<16^t[e+3]<<24}function Tr(t,e,n,r,i,s){fe[t]=fe[t]+fe[e]+i,fe[r]=Za(fe[r]^fe[t],16),fe[n]=fe[n]+fe[r],fe[e]=Za(fe[e]^fe[n],12),fe[t]=fe[t]+fe[e]+s,fe[r]=Za(fe[r]^fe[t],8),fe[n]=fe[n]+fe[r],fe[e]=Za(fe[e]^fe[n],7)}function Za(t,e){return t>>>e^t<<32-e}const l1=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),it=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]),fe=new Uint32Array(16),Ke=new Uint32Array(16);function h1(t,e){let n=0;for(n=0;n<8;n++)fe[n]=t.h[n],fe[n+8]=l1[n];for(fe[12]^=t.t,fe[13]^=t.t/4294967296,e&&(fe[14]=~fe[14]),n=0;n<16;n++)Ke[n]=X_(t.b,4*n);for(n=0;n<10;n++)Tr(0,4,8,12,Ke[it[n*16+0]],Ke[it[n*16+1]]),Tr(1,5,9,13,Ke[it[n*16+2]],Ke[it[n*16+3]]),Tr(2,6,10,14,Ke[it[n*16+4]],Ke[it[n*16+5]]),Tr(3,7,11,15,Ke[it[n*16+6]],Ke[it[n*16+7]]),Tr(0,5,10,15,Ke[it[n*16+8]],Ke[it[n*16+9]]),Tr(1,6,11,12,Ke[it[n*16+10]],Ke[it[n*16+11]]),Tr(2,7,8,13,Ke[it[n*16+12]],Ke[it[n*16+13]]),Tr(3,4,9,14,Ke[it[n*16+14]],Ke[it[n*16+15]]);for(n=0;n<8;n++)t.h[n]^=fe[n]^fe[n+8]}function d1(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(l1),b:new Uint8Array(64),c:0,t:0,outlen:t};return r.h[0]^=16842752^n<<8^t,n>0&&(Mu(r,e),r.c=64),r}function Mu(t,e){for(let n=0;n<e.length;n++)t.c===64&&(t.t+=t.c,h1(t,!1),t.c=0),t.b[t.c++]=e[n]}function p1(t){for(t.t+=t.c;t.c<64;)t.b[t.c++]=0;h1(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 g1(t,e,n){n=n||32,t=u1.normalizeInput(t);const r=d1(n,e);return Mu(r,t),p1(r)}function J_(t,e,n){const r=g1(t,e,n);return u1.toHex(r)}var Q_={blake2s:g1,blake2sHex:J_,blake2sInit:d1,blake2sUpdate:Mu,blake2sFinal:p1};const ao=Y_,co=Q_;var e9={blake2b:ao.blake2b,blake2bHex:ao.blake2bHex,blake2bInit:ao.blake2bInit,blake2bUpdate:ao.blake2bUpdate,blake2bFinal:ao.blake2bFinal,blake2s:co.blake2s,blake2sHex:co.blake2sHex,blake2sInit:co.blake2sInit,blake2sUpdate:co.blake2sUpdate,blake2sFinal:co.blake2sFinal};const t9="ReactNative";function y1(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function ju(){return!Un()&&!!Fs()&&navigator.product===t9}function n9(){return ju()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function r9(){return ju()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function i9(){return!y1()&&!!Fs()&&!!Un()}function s9(){var t;try{return ju()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(t=global.Application)==null?void 0:t.applicationId:void 0}catch{return}}const Wa=BigInt(2**32-1),b1=BigInt(32);function w1(t,e=!1){return e?{h:Number(t&Wa),l:Number(t>>b1&Wa)}:{h:Number(t>>b1&Wa)|0,l:Number(t&Wa)|0}}function m1(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}=w1(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const v1=(t,e,n)=>t>>>n,E1=(t,e,n)=>t<<32-n|e>>>n,Nr=(t,e,n)=>t>>>n|e<<32-n,Ur=(t,e,n)=>t<<32-n|e>>>n,fo=(t,e,n)=>t<<64-n|e>>>n-32,uo=(t,e,n)=>t>>>n-32|e<<64-n,o9=(t,e)=>e,a9=(t,e)=>t,c9=(t,e,n)=>t<<n|e>>>32-n,f9=(t,e,n)=>e<<n|t>>>32-n,u9=(t,e,n)=>e<<n-32|t>>>64-n,l9=(t,e,n)=>t<<n-32|e>>>64-n;function cn(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const zu=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Hu=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,h9=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),d9=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,p9=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),g9=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,hs=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Ya(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Cr(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function fn(t,...e){if(!Ya(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 x1(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Cr(t.outputLen),Cr(t.blockLen)}function Fr(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 Vu(t,e){fn(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function lo(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function un(...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 Sn(t,e){return t<<32-e|t>>>e}const _1=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function I1(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}const Yn=_1?t=>t:t=>I1(t);function y9(t){for(let e=0;e<t.length;e++)t[e]=I1(t[e]);return t}const Lr=_1?t=>t:y9,S1=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",b9=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function ds(t){if(fn(t),S1)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=b9[t[n]];return e}const Xn={_0:48,_9:57,A:65,F:70,a:97,f:102};function B1(t){if(t>=Xn._0&&t<=Xn._9)return t-Xn._0;if(t>=Xn.A&&t<=Xn.F)return t-(Xn.A-10);if(t>=Xn.a&&t<=Xn.f)return t-(Xn.a-10)}function Xa(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(S1)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=B1(t.charCodeAt(s)),a=B1(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 $1(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Jn(t){return typeof t=="string"&&(t=$1(t)),fn(t),t}function kr(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];fn(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 Ja{}function ho(t){const e=r=>t().update(Jn(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function w9(t){const e=(r,i)=>t(i).update(Jn(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Gu(t=32){if(hs&&typeof hs.getRandomValues=="function")return hs.getRandomValues(new Uint8Array(t));if(hs&&typeof hs.randomBytes=="function")return Uint8Array.from(hs.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const m9=BigInt(0),po=BigInt(1),v9=BigInt(2),E9=BigInt(7),x9=BigInt(256),_9=BigInt(113),A1=[],O1=[],D1=[];for(let t=0,e=po,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],A1.push(2*(5*r+n)),O1.push((t+1)*(t+2)/2%64);let i=m9;for(let s=0;s<7;s++)e=(e<<po^(e>>E9)*_9)%x9,e&v9&&(i^=po<<(po<<BigInt(s))-po);D1.push(i)}const P1=m1(D1,!0),I9=P1[0],S9=P1[1],R1=(t,e,n)=>n>32?u9(t,e,n):c9(t,e,n),T1=(t,e,n)=>n>32?l9(t,e,n):f9(t,e,n);function B9(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],u=n[c+1],h=R1(f,u,1)^n[a],l=T1(f,u,1)^n[a+1];for(let d=0;d<50;d+=10)t[o+d]^=h,t[o+d+1]^=l}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=O1[o],c=R1(i,s,a),f=T1(i,s,a),u=A1[o];i=t[u],s=t[u+1],t[u]=c,t[u+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)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]^=I9[r],t[1]^=S9[r]}un(n)}class Zu extends Ja{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,Cr(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=lo(this.state)}clone(){return this._cloneInto()}keccak(){Lr(this.state32),B9(this.state32,this.rounds),Lr(this.state32),this.posOut=0,this.pos=0}update(e){Fr(this),e=Jn(e),fn(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){Fr(this,!1),fn(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 Cr(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Vu(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,un(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new Zu(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)=>ho(()=>new Zu(e,t,n)))(1,136,256/8);function $9(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 A9(t,e,n){return t&e^~t&n}function O9(t,e,n){return t&e^t&n^e&n}class N1 extends Ja{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){Fr(this),e=Jn(e),fn(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){Fr(this),Vu(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,un(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;$9(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 f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,u[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 qr=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),st=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),ot=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),D9=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]),Mr=new Uint32Array(64);class P9 extends N1{constructor(e=32){super(64,e,8,!1),this.A=qr[0]|0,this.B=qr[1]|0,this.C=qr[2]|0,this.D=qr[3]|0,this.E=qr[4]|0,this.F=qr[5]|0,this.G=qr[6]|0,this.H=qr[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)Mr[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const l=Mr[h-15],d=Mr[h-2],p=Sn(l,7)^Sn(l,18)^l>>>3,b=Sn(d,17)^Sn(d,19)^d>>>10;Mr[h]=b+Mr[h-7]+p+Mr[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){const l=Sn(a,6)^Sn(a,11)^Sn(a,25),d=u+l+A9(a,c,f)+D9[h]+Mr[h]|0,p=(Sn(r,2)^Sn(r,13)^Sn(r,22))+O9(r,i,s)|0;u=f,f=c,c=a,a=o+d|0,o=s,s=i,i=r,r=d+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,f=f+this.G|0,u=u+this.H|0,this.set(r,i,s,o,a,c,f,u)}roundClean(){un(Mr)}destroy(){this.set(0,0,0,0,0,0,0,0),un(this.buffer)}}const U1=m1(["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))),R9=U1[0],T9=U1[1],jr=new Uint32Array(80),zr=new Uint32Array(80);class Wu extends N1{constructor(e=64){super(128,e,16,!1),this.Ah=ot[0]|0,this.Al=ot[1]|0,this.Bh=ot[2]|0,this.Bl=ot[3]|0,this.Ch=ot[4]|0,this.Cl=ot[5]|0,this.Dh=ot[6]|0,this.Dl=ot[7]|0,this.Eh=ot[8]|0,this.El=ot[9]|0,this.Fh=ot[10]|0,this.Fl=ot[11]|0,this.Gh=ot[12]|0,this.Gl=ot[13]|0,this.Hh=ot[14]|0,this.Hl=ot[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:l,Gh:d,Gl:p,Hh:b,Hl:v}=this;return[e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,v]}set(e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,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=f|0,this.El=u|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=b|0,this.Hl=v|0}process(e,n){for(let x=0;x<16;x++,n+=4)jr[x]=e.getUint32(n),zr[x]=e.getUint32(n+=4);for(let x=16;x<80;x++){const S=jr[x-15]|0,R=zr[x-15]|0,U=Nr(S,R,1)^Nr(S,R,8)^v1(S,R,7),L=Ur(S,R,1)^Ur(S,R,8)^E1(S,R,7),C=jr[x-2]|0,A=zr[x-2]|0,j=Nr(C,A,19)^fo(C,A,61)^v1(C,A,6),q=Ur(C,A,19)^uo(C,A,61)^E1(C,A,6),E=h9(L,q,zr[x-7],zr[x-16]),y=d9(E,U,j,jr[x-7],jr[x-16]);jr[x]=y|0,zr[x]=E|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:l,Fh:d,Fl:p,Gh:b,Gl:v,Hh:O,Hl:P}=this;for(let x=0;x<80;x++){const S=Nr(h,l,14)^Nr(h,l,18)^fo(h,l,41),R=Ur(h,l,14)^Ur(h,l,18)^uo(h,l,41),U=h&d^~h&b,L=l&p^~l&v,C=p9(P,R,L,T9[x],zr[x]),A=g9(C,O,S,U,R9[x],jr[x]),j=C|0,q=Nr(r,i,28)^fo(r,i,34)^fo(r,i,39),E=Ur(r,i,28)^uo(r,i,34)^uo(r,i,39),y=r&s^r&a^s&a,w=i&o^i&c^o&c;O=b|0,P=v|0,b=d|0,v=p|0,d=h|0,p=l|0,{h,l}=cn(f|0,u|0,A|0,j|0),f=a|0,u=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=zu(j,E,w);r=Hu(g,A,q,y),i=g|0}({h:r,l:i}=cn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=cn(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=cn(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=cn(this.Dh|0,this.Dl|0,f|0,u|0),{h,l}=cn(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=cn(this.Fh|0,this.Fl|0,d|0,p|0),{h:b,l:v}=cn(this.Gh|0,this.Gl|0,b|0,v|0),{h:O,l:P}=cn(this.Hh|0,this.Hl|0,O|0,P|0),this.set(r,i,s,o,a,c,f,u,h,l,d,p,b,v,O,P)}roundClean(){un(jr,zr)}destroy(){un(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class N9 extends Wu{constructor(){super(48),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}}const at=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class U9 extends Wu{constructor(){super(32),this.Ah=at[0]|0,this.Al=at[1]|0,this.Bh=at[2]|0,this.Bl=at[3]|0,this.Ch=at[4]|0,this.Cl=at[5]|0,this.Dh=at[6]|0,this.Dl=at[7]|0,this.Eh=at[8]|0,this.El=at[9]|0,this.Fh=at[10]|0,this.Fl=at[11]|0,this.Gh=at[12]|0,this.Gl=at[13]|0,this.Hh=at[14]|0,this.Hl=at[15]|0}}const C9=ho(()=>new P9),F9=ho(()=>new Wu),L9=ho(()=>new N9);ho(()=>new U9);const k9=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]),Ne=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),Y=new Uint32Array(32);function Hr(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=Y[2*t],f=Y[2*t+1],u=Y[2*e],h=Y[2*e+1],l=Y[2*n],d=Y[2*n+1],p=Y[2*r],b=Y[2*r+1],v=zu(c,u,o);f=Hu(v,f,h,a),c=v|0,{Dh:b,Dl:p}={Dh:b^f,Dl:p^c},{Dh:b,Dl:p}={Dh:o9(b,p),Dl:a9(b)},{h:d,l}=cn(d,l,b,p),{Bh:h,Bl:u}={Bh:h^d,Bl:u^l},{Bh:h,Bl:u}={Bh:Nr(h,u,24),Bl:Ur(h,u,24)},Y[2*t]=c,Y[2*t+1]=f,Y[2*e]=u,Y[2*e+1]=h,Y[2*n]=l,Y[2*n+1]=d,Y[2*r]=p,Y[2*r+1]=b}function Vr(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=Y[2*t],f=Y[2*t+1],u=Y[2*e],h=Y[2*e+1],l=Y[2*n],d=Y[2*n+1],p=Y[2*r],b=Y[2*r+1],v=zu(c,u,o);f=Hu(v,f,h,a),c=v|0,{Dh:b,Dl:p}={Dh:b^f,Dl:p^c},{Dh:b,Dl:p}={Dh:Nr(b,p,16),Dl:Ur(b,p,16)},{h:d,l}=cn(d,l,b,p),{Bh:h,Bl:u}={Bh:h^d,Bl:u^l},{Bh:h,Bl:u}={Bh:fo(h,u,63),Bl:uo(h,u,63)},Y[2*t]=c,Y[2*t+1]=f,Y[2*e]=u,Y[2*e+1]=h,Y[2*n]=l,Y[2*n+1]=d,Y[2*r]=p,Y[2*r+1]=b}function q9(t,e={},n,r,i){if(Cr(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 M9 extends Ja{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,Cr(e),Cr(n),this.blockLen=e,this.outputLen=n,this.buffer=new Uint8Array(e),this.buffer32=lo(this.buffer)}update(e){Fr(this),e=Jn(e),fn(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 f=Math.min(n-this.pos,s-c),u=o+c;if(f===n&&!(u%4)&&c+f<s){const h=new Uint32Array(a,u,Math.floor((s-c)/4));Lr(h);for(let l=0;c+n<s;l+=i.length,c+=n)this.length+=n,this.compress(h,l,!1);Lr(h);continue}r.set(e.subarray(c,c+f),this.pos),this.pos+=f,this.length+=f,c+=f}return this}digestInto(e){Fr(this),Vu(e,this);const{pos:n,buffer32:r}=this;this.finished=!0,un(this.buffer.subarray(n)),Lr(r),this.compress(r,0,!0),Lr(r);const i=lo(e);this.get().forEach((s,o)=>i[o]=Yn(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 j9 extends M9{constructor(e={}){const n=e.dkLen===void 0?64:e.dkLen;super(128,n),this.v0l=Ne[0]|0,this.v0h=Ne[1]|0,this.v1l=Ne[2]|0,this.v1h=Ne[3]|0,this.v2l=Ne[4]|0,this.v2h=Ne[5]|0,this.v3l=Ne[6]|0,this.v3h=Ne[7]|0,this.v4l=Ne[8]|0,this.v4h=Ne[9]|0,this.v5l=Ne[10]|0,this.v5h=Ne[11]|0,this.v6l=Ne[12]|0,this.v6h=Ne[13]|0,this.v7l=Ne[14]|0,this.v7h=Ne[15]|0,q9(n,e,64,16,16);let{key:r,personalization:i,salt:s}=e,o=0;if(r!==void 0&&(r=Jn(r),o=r.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=Jn(s);const a=lo(s);this.v4l^=Yn(a[0]),this.v4h^=Yn(a[1]),this.v5l^=Yn(a[2]),this.v5h^=Yn(a[3])}if(i!==void 0){i=Jn(i);const a=lo(i);this.v6l^=Yn(a[0]),this.v6h^=Yn(a[1]),this.v7l^=Yn(a[2]),this.v7h^=Yn(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:u,v5l:h,v5h:l,v6l:d,v6h:p,v7l:b,v7h:v}=this;return[e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,v]}set(e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,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=f|0,this.v4h=u|0,this.v5l=h|0,this.v5h=l|0,this.v6l=d|0,this.v6h=p|0,this.v7l=b|0,this.v7h=v|0}compress(e,n,r){this.get().forEach((c,f)=>Y[f]=c),Y.set(Ne,16);let{h:i,l:s}=w1(BigInt(this.length));Y[24]=Ne[8]^s,Y[25]=Ne[9]^i,r&&(Y[28]=~Y[28],Y[29]=~Y[29]);let o=0;const a=k9;for(let c=0;c<12;c++)Hr(0,4,8,12,e,n+2*a[o++]),Vr(0,4,8,12,e,n+2*a[o++]),Hr(1,5,9,13,e,n+2*a[o++]),Vr(1,5,9,13,e,n+2*a[o++]),Hr(2,6,10,14,e,n+2*a[o++]),Vr(2,6,10,14,e,n+2*a[o++]),Hr(3,7,11,15,e,n+2*a[o++]),Vr(3,7,11,15,e,n+2*a[o++]),Hr(0,5,10,15,e,n+2*a[o++]),Vr(0,5,10,15,e,n+2*a[o++]),Hr(1,6,11,12,e,n+2*a[o++]),Vr(1,6,11,12,e,n+2*a[o++]),Hr(2,7,8,13,e,n+2*a[o++]),Vr(2,7,8,13,e,n+2*a[o++]),Hr(3,4,9,14,e,n+2*a[o++]),Vr(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],un(Y)}destroy(){this.destroyed=!0,un(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}w9(t=>new j9(t));/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function C1(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function Yu(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function Xu(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Ot(t,...e){if(!C1(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 F1(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 z9(t,e){Ot(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function Kr(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function ps(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function H9(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const V9=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function K9(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Ju(t){if(typeof t=="string")t=K9(t);else if(C1(t))t=Qu(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function G9(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function Z9(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 W9=(t,e)=>{function n(r,...i){if(Ot(r),!V9)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?Ot(f):Ot(f,t.nonceLength)}const s=t.tagLength;s&&i[1]!==void 0&&Ot(i[1]);const o=e(r,...i),a=(f,u)=>{if(u!==void 0){if(f!==2)throw new Error("cipher output not supported");Ot(u)}};let c=!1;return{encrypt(f,u){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Ot(f),a(o.encrypt.length,u),o.encrypt(f,u)},decrypt(f,u){if(Ot(f),s&&f.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return a(o.decrypt.length,u),o.decrypt(f,u)}}}return Object.assign(n,t),n};function L1(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&&!X9(e))throw new Error("invalid output, must be aligned");return e}function k1(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 Y9(t,e,n){Yu(n);const r=new Uint8Array(16),i=H9(r);return k1(i,0,BigInt(e),n),k1(i,8,BigInt(t),n),r}function X9(t){return t.byteOffset%4===0}function Qu(t){return Uint8Array.from(t)}const q1=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),J9=q1("expand 16-byte k"),Q9=q1("expand 32-byte k"),e7=Kr(J9),t7=Kr(Q9);function ue(t,e){return t<<e|t>>>32-e}function el(t){return t.byteOffset%4===0}const Qa=64,n7=16,M1=2**32-1,j1=new Uint32Array;function r7(t,e,n,r,i,s,o,a){const c=i.length,f=new Uint8Array(Qa),u=Kr(f),h=el(i)&&el(s),l=h?Kr(i):j1,d=h?Kr(s):j1;for(let p=0;p<c;o++){if(t(e,n,r,u,o,a),o>=M1)throw new Error("arx: counter overflow");const b=Math.min(Qa,c-p);if(h&&b===Qa){const v=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let O=0,P;O<n7;O++)P=v+O,d[P]=l[P]^u[O];p+=Qa;continue}for(let v=0,O;v<b;v++)O=p+v,s[O]=i[O]^f[v];p+=b}}function i7(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=G9({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return Xu(i),Xu(o),Yu(s),Yu(n),(a,c,f,u,h=0)=>{Ot(a),Ot(c),Ot(f);const l=f.length;if(u===void 0&&(u=new Uint8Array(l)),Ot(u),Xu(h),h<0||h>=M1)throw new Error("arx: counter overflow");if(u.length<l)throw new Error(`arx: output (${u.length}) is shorter than data (${l})`);const d=[];let p=a.length,b,v;if(p===32)d.push(b=Qu(a)),v=t7;else if(p===16&&n)b=new Uint8Array(32),b.set(a),b.set(a,16),v=e7,d.push(b);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);el(c)||d.push(c=Qu(c));const O=Kr(b);if(r){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(v,O,Kr(c.subarray(0,16)),O),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 S=new Uint8Array(12);S.set(c,s?0:12-c.length),c=S,d.push(c)}const x=Kr(c);return r7(t,v,O,x,f,u,h,o),ps(...d),u}}const Ge=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class s7{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=Ju(e),Ot(e,32);const n=Ge(e,0),r=Ge(e,2),i=Ge(e,4),s=Ge(e,6),o=Ge(e,8),a=Ge(e,10),c=Ge(e,12),f=Ge(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 u=0;u<8;u++)this.pad[u]=Ge(e,16+2*u)}process(e,n,r=!1){const i=r?0:2048,{h:s,r:o}=this,a=o[0],c=o[1],f=o[2],u=o[3],h=o[4],l=o[5],d=o[6],p=o[7],b=o[8],v=o[9],O=Ge(e,n+0),P=Ge(e,n+2),x=Ge(e,n+4),S=Ge(e,n+6),R=Ge(e,n+8),U=Ge(e,n+10),L=Ge(e,n+12),C=Ge(e,n+14);let A=s[0]+(O&8191),j=s[1]+((O>>>13|P<<3)&8191),q=s[2]+((P>>>10|x<<6)&8191),E=s[3]+((x>>>7|S<<9)&8191),y=s[4]+((S>>>4|R<<12)&8191),w=s[5]+(R>>>1&8191),g=s[6]+((R>>>14|U<<2)&8191),m=s[7]+((U>>>11|L<<5)&8191),_=s[8]+((L>>>8|C<<8)&8191),B=s[9]+(C>>>5|i),I=0,$=I+A*a+j*(5*v)+q*(5*b)+E*(5*p)+y*(5*d);I=$>>>13,$&=8191,$+=w*(5*l)+g*(5*h)+m*(5*u)+_*(5*f)+B*(5*c),I+=$>>>13,$&=8191;let D=I+A*c+j*a+q*(5*v)+E*(5*b)+y*(5*p);I=D>>>13,D&=8191,D+=w*(5*d)+g*(5*l)+m*(5*h)+_*(5*u)+B*(5*f),I+=D>>>13,D&=8191;let T=I+A*f+j*c+q*a+E*(5*v)+y*(5*b);I=T>>>13,T&=8191,T+=w*(5*p)+g*(5*d)+m*(5*l)+_*(5*h)+B*(5*u),I+=T>>>13,T&=8191;let F=I+A*u+j*f+q*c+E*a+y*(5*v);I=F>>>13,F&=8191,F+=w*(5*b)+g*(5*p)+m*(5*d)+_*(5*l)+B*(5*h),I+=F>>>13,F&=8191;let k=I+A*h+j*u+q*f+E*c+y*a;I=k>>>13,k&=8191,k+=w*(5*v)+g*(5*b)+m*(5*p)+_*(5*d)+B*(5*l),I+=k>>>13,k&=8191;let N=I+A*l+j*h+q*u+E*f+y*c;I=N>>>13,N&=8191,N+=w*a+g*(5*v)+m*(5*b)+_*(5*p)+B*(5*d),I+=N>>>13,N&=8191;let M=I+A*d+j*l+q*h+E*u+y*f;I=M>>>13,M&=8191,M+=w*c+g*a+m*(5*v)+_*(5*b)+B*(5*p),I+=M>>>13,M&=8191;let z=I+A*p+j*d+q*l+E*h+y*u;I=z>>>13,z&=8191,z+=w*f+g*c+m*a+_*(5*v)+B*(5*b),I+=z>>>13,z&=8191;let K=I+A*b+j*p+q*d+E*l+y*h;I=K>>>13,K&=8191,K+=w*u+g*f+m*c+_*a+B*(5*v),I+=K>>>13,K&=8191;let H=I+A*v+j*b+q*p+E*d+y*l;I=H>>>13,H&=8191,H+=w*h+g*u+m*f+_*c+B*a,I+=H>>>13,H&=8191,I=(I<<2)+I|0,I=I+$|0,$=I&8191,I=I>>>13,D+=I,s[0]=$,s[1]=D,s[2]=T,s[3]=F,s[4]=k,s[5]=N,s[6]=M,s[7]=z,s[8]=K,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;ps(r)}update(e){F1(this),e=Ju(e),Ot(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(){ps(this.h,this.r,this.buffer,this.pad)}digestInto(e){F1(this),z9(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 o7(t){const e=(r,i)=>t(i).update(Ju(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}const a7=o7(t=>new s7(t));function c7(t,e,n,r,i,s=20){let o=t[0],a=t[1],c=t[2],f=t[3],u=e[0],h=e[1],l=e[2],d=e[3],p=e[4],b=e[5],v=e[6],O=e[7],P=i,x=n[0],S=n[1],R=n[2],U=o,L=a,C=c,A=f,j=u,q=h,E=l,y=d,w=p,g=b,m=v,_=O,B=P,I=x,$=S,D=R;for(let F=0;F<s;F+=2)U=U+j|0,B=ue(B^U,16),w=w+B|0,j=ue(j^w,12),U=U+j|0,B=ue(B^U,8),w=w+B|0,j=ue(j^w,7),L=L+q|0,I=ue(I^L,16),g=g+I|0,q=ue(q^g,12),L=L+q|0,I=ue(I^L,8),g=g+I|0,q=ue(q^g,7),C=C+E|0,$=ue($^C,16),m=m+$|0,E=ue(E^m,12),C=C+E|0,$=ue($^C,8),m=m+$|0,E=ue(E^m,7),A=A+y|0,D=ue(D^A,16),_=_+D|0,y=ue(y^_,12),A=A+y|0,D=ue(D^A,8),_=_+D|0,y=ue(y^_,7),U=U+q|0,D=ue(D^U,16),m=m+D|0,q=ue(q^m,12),U=U+q|0,D=ue(D^U,8),m=m+D|0,q=ue(q^m,7),L=L+E|0,B=ue(B^L,16),_=_+B|0,E=ue(E^_,12),L=L+E|0,B=ue(B^L,8),_=_+B|0,E=ue(E^_,7),C=C+y|0,I=ue(I^C,16),w=w+I|0,y=ue(y^w,12),C=C+y|0,I=ue(I^C,8),w=w+I|0,y=ue(y^w,7),A=A+j|0,$=ue($^A,16),g=g+$|0,j=ue(j^g,12),A=A+j|0,$=ue($^A,8),g=g+$|0,j=ue(j^g,7);let T=0;r[T++]=o+U|0,r[T++]=a+L|0,r[T++]=c+C|0,r[T++]=f+A|0,r[T++]=u+j|0,r[T++]=h+q|0,r[T++]=l+E|0,r[T++]=d+y|0,r[T++]=p+w|0,r[T++]=b+g|0,r[T++]=v+m|0,r[T++]=O+_|0,r[T++]=P+B|0,r[T++]=x+I|0,r[T++]=S+$|0,r[T++]=R+D|0}const f7=i7(c7,{counterRight:!1,counterLength:4,allowShortKeys:!1}),u7=new Uint8Array(16),z1=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(u7.subarray(n))},l7=new Uint8Array(32);function H1(t,e,n,r,i){const s=t(e,n,l7),o=a7.create(s);i&&z1(o,i),z1(o,r);const a=Y9(r.length,i?i.length:0,!0);o.update(a);const c=o.digest();return ps(s,a),c}W9({blockSize:64,nonceLength:12,tagLength:16},(t=>(e,n,r)=>({encrypt(i,s){const o=i.length;s=L1(o+16,s,!1),s.set(i);const a=s.subarray(0,-16);t(e,n,a,a,1);const c=H1(t,e,n,a,r);return s.set(c,o),ps(c),s},decrypt(i,s){s=L1(i.length-16,s,!1);const o=i.subarray(0,-16),a=i.subarray(-16),c=H1(t,e,n,o,r);if(!Z9(a,c))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),t(e,n,s,s,1),ps(c),s}}))(f7));class V1 extends Ja{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,x1(e);const r=Jn(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),un(s)}update(e){return Fr(this),this.iHash.update(e),this}digestInto(e){Fr(this),fn(e,this.outputLen),this.finished=!0,this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),this.destroy()}digest(){const e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||(e=Object.create(Object.getPrototypeOf(this),{}));const{oHash: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 K1=(t,e,n)=>new V1(t,e).update(n).digest();K1.create=(t,e)=>new V1(t,e);const tl=BigInt(0),nl=BigInt(1);function ec(t,e=""){if(typeof t!="boolean"){const n=e&&`"${e}"`;throw new Error(n+"expected boolean, got type="+typeof t)}return t}function Bi(t,e,n=""){const r=Ya(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 tc(t){const e=t.toString(16);return e.length&1?"0"+e:e}function G1(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?tl:BigInt("0x"+t)}function nc(t){return G1(ds(t))}function rc(t){return fn(t),G1(ds(Uint8Array.from(t).reverse()))}function rl(t,e){return Xa(t.toString(16).padStart(e*2,"0"))}function il(t,e){return rl(t,e).reverse()}function ct(t,e,n){let r;if(typeof e=="string")try{r=Xa(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(Ya(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 sl=t=>typeof t=="bigint"&&tl<=t;function h7(t,e,n){return sl(t)&&sl(e)&&sl(n)&&e<=t&&t<n}function ol(t,e,n,r){if(!h7(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function Z1(t){let e;for(e=0;t>tl;t>>=nl,e+=1);return e}const go=t=>(nl<<BigInt(t))-nl;function d7(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=l=>new Uint8Array(l),i=l=>Uint8Array.of(l);let s=r(t),o=r(t),a=0;const c=()=>{s.fill(1),o.fill(0),a=0},f=(...l)=>n(o,s,...l),u=(l=r(0))=>{o=f(i(0),l),s=f(),l.length!==0&&(o=f(i(1),l),s=f())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let l=0;const d=[];for(;l<e;){s=f();const p=s.slice();d.push(p),l+=s.length}return kr(...d)};return(l,d)=>{c(),u(l);let p;for(;!(p=d(h()));)u();return c(),p}}function ic(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 W1(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 Dt=BigInt(0),mt=BigInt(1),$i=BigInt(2),Y1=BigInt(3),X1=BigInt(4),J1=BigInt(5),p7=BigInt(7),Q1=BigInt(8),g7=BigInt(9),ey=BigInt(16);function qt(t,e){const n=t%e;return n>=Dt?n:e+n}function ln(t,e,n){let r=t;for(;e-- >Dt;)r*=r,r%=n;return r}function ty(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=qt(t,e),r=e,i=Dt,s=mt;for(;n!==Dt;){const o=r/n,a=r%n,c=i-s*o;r=n,n=a,i=s,s=c}if(r!==mt)throw new Error("invert: does not exist");return qt(i,e)}function al(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function ny(t,e){const n=(t.ORDER+mt)/X1,r=t.pow(e,n);return al(t,r,e),r}function y7(t,e){const n=(t.ORDER-J1)/Q1,r=t.mul(e,$i),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,$i),i),a=t.mul(s,t.sub(o,t.ONE));return al(t,a,e),a}function b7(t){const e=Gr(t),n=ry(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+p7)/ey;return(a,c)=>{let f=a.pow(c,o),u=a.mul(f,r);const h=a.mul(f,i),l=a.mul(f,s),d=a.eql(a.sqr(u),c),p=a.eql(a.sqr(h),c);f=a.cmov(f,u,d),u=a.cmov(l,h,p);const b=a.eql(a.sqr(u),c),v=a.cmov(f,u,b);return al(a,v,c),v}}function ry(t){if(t<Y1)throw new Error("sqrt is not defined for small field");let e=t-mt,n=0;for(;e%$i===Dt;)e/=$i,n++;let r=$i;const i=Gr(t);for(;sy(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return ny;let s=i.pow(r,e);const o=(e+mt)/$i;return function(a,c){if(a.is0(c))return c;if(sy(a,c)!==1)throw new Error("Cannot find square root");let f=n,u=a.mul(a.ONE,s),h=a.pow(c,e),l=a.pow(c,o);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let d=1,p=a.sqr(h);for(;!a.eql(p,a.ONE);)if(d++,p=a.sqr(p),d===f)throw new Error("Cannot find square root");const b=mt<<BigInt(f-d-1),v=a.pow(u,b);f=d,u=a.sqr(v),h=a.mul(h,u),l=a.mul(l,v)}return l}}function w7(t){return t%X1===Y1?ny:t%Q1===J1?y7:t%ey===g7?b7(t):ry(t)}const m7=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function v7(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=m7.reduce((r,i)=>(r[i]="function",r),e);return ic(t,n),t}function E7(t,e,n){if(n<Dt)throw new Error("invalid exponent, negatives unsupported");if(n===Dt)return t.ONE;if(n===mt)return e;let r=t.ONE,i=e;for(;n>Dt;)n&mt&&(r=t.mul(r,i)),i=t.sqr(i),n>>=mt;return r}function iy(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 sy(t,e){const n=(t.ORDER-mt)/$i,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 oy(t,e){e!==void 0&&Cr(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function Gr(t,e,n=!1,r={}){if(t<=Dt)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 l=e;l.BITS&&(i=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(n=l.isLE),typeof l.modFromBytes=="boolean"&&(o=l.modFromBytes),a=l.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:f}=oy(t,i);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u;const h=Object.freeze({ORDER:t,isLE:n,BITS:c,BYTES:f,MASK:go(c),ZERO:Dt,ONE:mt,allowedLengths:a,create:l=>qt(l,t),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return Dt<=l&&l<t},is0:l=>l===Dt,isValidNot0:l=>!h.is0(l)&&h.isValid(l),isOdd:l=>(l&mt)===mt,neg:l=>qt(-l,t),eql:(l,d)=>l===d,sqr:l=>qt(l*l,t),add:(l,d)=>qt(l+d,t),sub:(l,d)=>qt(l-d,t),mul:(l,d)=>qt(l*d,t),pow:(l,d)=>E7(h,l,d),div:(l,d)=>qt(l*ty(d,t),t),sqrN:l=>l*l,addN:(l,d)=>l+d,subN:(l,d)=>l-d,mulN:(l,d)=>l*d,inv:l=>ty(l,t),sqrt:s||(l=>(u||(u=w7(t)),u(h,l))),toBytes:l=>n?il(l,f):rl(l,f),fromBytes:(l,d=!0)=>{if(a){if(!a.includes(l.length)||l.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);const b=new Uint8Array(f);b.set(l,n?0:b.length-l.length),l=b}if(l.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+l.length);let p=n?rc(l):nc(l);if(o&&(p=qt(p,t)),!d&&!h.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:l=>iy(h,l),cmov:(l,d,p)=>p?d:l});return Object.freeze(h)}function ay(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 cy(t){const e=ay(t);return e+Math.ceil(e/2)}function x7(t,e,n=!1){const r=t.length,i=ay(e),s=cy(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?rc(t):nc(t),a=qt(o,e-mt)+mt;return n?il(a,i):rl(a,i)}const gs=BigInt(0),Ai=BigInt(1);function sc(t,e){const n=e.negate();return t?n:e}function cl(t,e){const n=iy(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function fy(t,e){if(!Number.isSafeInteger(t)||t<=0||t>e)throw new Error("invalid window size, expected [1.."+e+"], got W="+t)}function fl(t,e){fy(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 uy(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+=Ai);const f=e*r,u=f+Math.abs(a)-1,h=a===0,l=a<0,d=e%2!==0;return{nextN:c,offset:u,isZero:h,isNeg:l,isNegF:d,offsetF:f}}function _7(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 I7(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 ul=new WeakMap,ly=new WeakMap;function ll(t){return ly.get(t)||1}function hy(t){if(t!==gs)throw new Error("invalid wNAF")}class S7{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>gs;)n&Ai&&(r=r.add(i)),i=i.double(),n>>=Ai;return r}precomputeWindow(e,n){const{windows:r,windowSize:i}=fl(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=fl(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:c,offset:f,isZero:u,isNeg:h,isNegF:l,offsetF:d}=uy(r,a,o);r=c,u?s=s.add(sc(l,n[d])):i=i.add(sc(h,n[f]))}return hy(r),{p:i,f:s}}wNAFUnsafe(e,n,r,i=this.ZERO){const s=fl(e,this.bits);for(let o=0;o<s.windows&&r!==gs;o++){const{nextN:a,offset:c,isZero:f,isNeg:u}=uy(r,o,s);if(r=a,!f){const h=n[c];i=i.add(u?h.negate():h)}}return hy(r),i}getPrecomputes(e,n,r){let i=ul.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),ul.set(n,i))),i}cached(e,n,r){const i=ll(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=ll(e);return s===1?this._unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,i)}createCache(e,n){fy(n,this.bits),ly.set(e,n),ul.delete(e)}hasCache(e){return ll(e)!==1}}function B7(t,e,n,r){let i=e,s=t.ZERO,o=t.ZERO;for(;n>gs||r>gs;)n&Ai&&(s=s.add(i)),r&Ai&&(o=o.add(i)),i=i.double(),n>>=Ai,r>>=Ai;return{p1:s,p2:o}}function $7(t,e,n,r){_7(n,t),I7(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=Z1(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=go(c),u=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let l=o;for(let d=h;d>=0;d-=c){u.fill(o);for(let b=0;b<s;b++){const v=r[b],O=Number(v>>BigInt(d)&f);u[O]=u[O].add(n[b])}let p=o;for(let b=u.length-1,v=o;b>0;b--)v=v.add(u[b]),p=p.add(v);if(l=l.add(p),d!==0)for(let b=0;b<c;b++)l=l.double()}return l}function dy(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return v7(e),e}else return Gr(t,{isLE:n})}function A7(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>gs))throw new Error(`CURVE.${a} must be positive bigint`)}const i=dy(e.p,n.Fp,r),s=dy(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),$1("HashToScalar-");const yo=BigInt(0),ys=BigInt(1),oc=BigInt(2);function O7(t){return ic(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function D7(t){const e=O7(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||Gu,f=a?255:448,u=a?32:56,h=BigInt(a?9:5),l=BigInt(a?121665:39081),d=a?oc**BigInt(254):oc**BigInt(447),p=a?BigInt(8)*oc**BigInt(251)-ys:BigInt(4)*oc**BigInt(445)-ys,b=d+p+ys,v=E=>qt(E,n),O=P(h);function P(E){return il(v(E),u)}function x(E){const y=ct("u coordinate",E,u);return a&&(y[31]&=127),v(rc(y))}function S(E){return rc(i(ct("scalar",E,u)))}function R(E,y){const w=C(x(y),S(E));if(w===yo)throw new Error("invalid private or public key received");return P(w)}function U(E){return R(E,O)}function L(E,y,w){const g=v(E*(y-w));return y=v(y-g),w=v(w+g),{x_2:y,x_3:w}}function C(E,y){ol("u",E,yo,n),ol("scalar",y,d,b);const w=y,g=E;let m=ys,_=yo,B=E,I=ys,$=yo;for(let T=BigInt(f-1);T>=yo;T--){const F=w>>T&ys;$^=F,{x_2:m,x_3:B}=L($,m,B),{x_2:_,x_3:I}=L($,_,I),$=F;const k=m+_,N=v(k*k),M=m-_,z=v(M*M),K=N-z,H=B+I,G=B-I,ee=v(G*k),te=v(H*M),re=ee+te,ce=ee-te;B=v(re*re),I=v(g*v(ce*ce)),m=v(N*z),_=v(K*(N+v(l*K)))}({x_2:m,x_3:B}=L($,m,B)),{x_2:_,x_3:I}=L($,_,I);const D=s(_);return v(m*D)}const A={secretKey:u,publicKey:u,seed:u},j=(E=c(u))=>(fn(E,A.seed),E);function q(E){const y=j(E);return{secretKey:y,publicKey:U(y)}}return{keygen:q,getSharedSecret:(E,y)=>R(E,y),getPublicKey:E=>U(E),scalarMult:R,scalarMultBase:U,utils:{randomSecretKey:j,randomPrivateKey:j},GuBytes:O.slice(),lengths:A}}const P7=BigInt(1),py=BigInt(2),R7=BigInt(3),T7=BigInt(5),N7=BigInt(8),gy=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),U7={p:gy,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:N7,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function C7(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=gy,o=t*t%s*t%s,a=ln(o,py,s)*o%s,c=ln(a,P7,s)*t%s,f=ln(c,T7,s)*c%s,u=ln(f,e,s)*f%s,h=ln(u,n,s)*u%s,l=ln(h,r,s)*h%s,d=ln(l,i,s)*l%s,p=ln(d,i,s)*l%s,b=ln(p,e,s)*f%s;return{pow_p_5_8:ln(b,py,s)*t%s,b2:o}}function F7(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const L7=Gr(U7.p,{isLE:!0});(()=>{const t=L7.ORDER;return D7({P:t,type:"x25519",powPminus2:e=>{const{pow_p_5_8:n,b2:r}=C7(e);return qt(ln(n,R7,t)*r,t)},adjustScalarBytes:F7})})();const yy=(t,e)=>(t+(t>=0?e:-e)/by)/e;function k7(t,e,n){const[[r,i],[s,o]]=e,a=yy(o*t,n),c=yy(-i*t,n);let f=t-a*r-c*s,u=-a*i-c*o;const h=f<er,l=u<er;h&&(f=-f),l&&(u=-u);const d=go(Math.ceil(Z1(n)/2))+bs;if(f<er||f>=d||u<er||u>=d)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:h,k1:f,k2neg:l,k2:u}}function hl(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function dl(t,e){const n={};for(let r of Object.keys(e))n[r]=t[r]===void 0?e[r]:t[r];return ec(n.lowS,"lowS"),ec(n.prehash,"prehash"),n.format!==void 0&&hl(n.format),n}class q7 extends Error{constructor(e=""){super(e)}}const Qn={Err:q7,_tlv:{encode:(t,e)=>{const{Err:n}=Qn;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=tc(r);if(i.length/2&128)throw new n("tlv.encode: long form length too big");const s=r>127?tc(i.length/2|128):"";return tc(t)+s+i+e},decode(t,e){const{Err:n}=Qn;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 u of f)o=o<<8|u;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}=Qn;if(t<er)throw new e("integer: negative integers are not allowed");let n=tc(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}=Qn;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 nc(t)}},toSig(t){const{Err:e,_int:n,_tlv:r}=Qn,i=ct("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:u}=r.decode(2,c);if(u.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}=Qn,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}},er=BigInt(0),bs=BigInt(1),by=BigInt(2),ac=BigInt(3),M7=BigInt(4);function ws(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=ct("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 j7(t,e={}){const n=A7("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;ic(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=my(r,i);function u(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(E,y,w){const{x:g,y:m}=y.toAffine(),_=r.toBytes(g);if(ec(w,"isCompressed"),w){u();const B=!r.isOdd(m);return kr(wy(B),_)}else return kr(Uint8Array.of(4),_,r.toBytes(m))}function l(E){Bi(E,void 0,"Point");const{publicKey:y,publicKeyUncompressed:w}=f,g=E.length,m=E[0],_=E.subarray(1);if(g===y&&(m===2||m===3)){const B=r.fromBytes(_);if(!r.isValid(B))throw new Error("bad point: is not on curve, wrong x");const I=b(B);let $;try{$=r.sqrt(I)}catch(T){const F=T instanceof Error?": "+T.message:"";throw new Error("bad point: is not on curve, sqrt error"+F)}u();const D=r.isOdd($);return(m&1)===1!==D&&($=r.neg($)),{x:B,y:$}}else if(g===w&&m===4){const B=r.BYTES,I=r.fromBytes(_.subarray(0,B)),$=r.fromBytes(_.subarray(B,B*2));if(!v(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=${y} or uncompressed=${w}`)}const d=e.toBytes||h,p=e.fromBytes||l;function b(E){const y=r.sqr(E),w=r.mul(y,E);return r.add(r.add(w,r.mul(E,s.a)),s.b)}function v(E,y){const w=r.sqr(y),g=b(E);return r.eql(w,g)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const O=r.mul(r.pow(s.a,ac),M7),P=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(O,P)))throw new Error("bad curve params: a or b");function x(E,y,w=!1){if(!r.isValid(y)||w&&r.is0(y))throw new Error(`bad point coordinate ${E}`);return y}function S(E){if(!(E instanceof A))throw new Error("ProjectivePoint expected")}function R(E){if(!c||!c.basises)throw new Error("no endo");return k7(E,c.basises,i.ORDER)}const U=W1((E,y)=>{const{X:w,Y:g,Z:m}=E;if(r.eql(m,r.ONE))return{x:w,y:g};const _=E.is0();y==null&&(y=_?r.ONE:r.inv(m));const B=r.mul(w,y),I=r.mul(g,y),$=r.mul(m,y);if(_)return{x:r.ZERO,y:r.ZERO};if(!r.eql($,r.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}),L=W1(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.Y))return;throw new Error("bad point: ZERO")}const{x:y,y:w}=E.toAffine();if(!r.isValid(y)||!r.isValid(w))throw new Error("bad point: x or y not field elements");if(!v(y,w))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(E,y,w,g,m){return w=new A(r.mul(w.X,E),w.Y,w.Z),y=sc(g,y),w=sc(m,w),y.add(w)}class A{constructor(y,w,g){this.X=x("x",y),this.Y=x("y",w,!0),this.Z=x("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){const{x:w,y:g}=y||{};if(!y||!r.isValid(w)||!r.isValid(g))throw new Error("invalid affine point");if(y instanceof A)throw new Error("projective point not allowed");return r.is0(w)&&r.is0(g)?A.ZERO:new A(w,g,r.ONE)}static fromBytes(y){const w=A.fromAffine(p(Bi(y,void 0,"point")));return w.assertValidity(),w}static fromHex(y){return A.fromBytes(ct("pointHex",y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,w=!0){return q.createCache(this,y),w||this.multiply(ac),this}assertValidity(){L(this)}hasEvenY(){const{y}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(y)}equals(y){S(y);const{X:w,Y:g,Z:m}=this,{X:_,Y:B,Z:I}=y,$=r.eql(r.mul(w,I),r.mul(_,m)),D=r.eql(r.mul(g,I),r.mul(B,m));return $&&D}negate(){return new A(this.X,r.neg(this.Y),this.Z)}double(){const{a:y,b:w}=s,g=r.mul(w,ac),{X:m,Y:_,Z:B}=this;let I=r.ZERO,$=r.ZERO,D=r.ZERO,T=r.mul(m,m),F=r.mul(_,_),k=r.mul(B,B),N=r.mul(m,_);return N=r.add(N,N),D=r.mul(m,B),D=r.add(D,D),I=r.mul(y,D),$=r.mul(g,k),$=r.add(I,$),I=r.sub(F,$),$=r.add(F,$),$=r.mul(I,$),I=r.mul(N,I),D=r.mul(g,D),k=r.mul(y,k),N=r.sub(T,k),N=r.mul(y,N),N=r.add(N,D),D=r.add(T,T),T=r.add(D,T),T=r.add(T,k),T=r.mul(T,N),$=r.add($,T),k=r.mul(_,B),k=r.add(k,k),T=r.mul(k,N),I=r.sub(I,T),D=r.mul(k,F),D=r.add(D,D),D=r.add(D,D),new A(I,$,D)}add(y){S(y);const{X:w,Y:g,Z:m}=this,{X:_,Y:B,Z:I}=y;let $=r.ZERO,D=r.ZERO,T=r.ZERO;const F=s.a,k=r.mul(s.b,ac);let N=r.mul(w,_),M=r.mul(g,B),z=r.mul(m,I),K=r.add(w,g),H=r.add(_,B);K=r.mul(K,H),H=r.add(N,M),K=r.sub(K,H),H=r.add(w,m);let G=r.add(_,I);return H=r.mul(H,G),G=r.add(N,z),H=r.sub(H,G),G=r.add(g,m),$=r.add(B,I),G=r.mul(G,$),$=r.add(M,z),G=r.sub(G,$),T=r.mul(F,H),$=r.mul(k,z),T=r.add($,T),$=r.sub(M,T),T=r.add(M,T),D=r.mul($,T),M=r.add(N,N),M=r.add(M,N),z=r.mul(F,z),H=r.mul(k,H),M=r.add(M,z),z=r.sub(N,z),z=r.mul(F,z),H=r.add(H,z),N=r.mul(M,H),D=r.add(D,N),N=r.mul(G,H),$=r.mul(K,$),$=r.sub($,N),N=r.mul(K,M),T=r.mul(G,T),T=r.add(T,N),new A($,D,T)}subtract(y){return this.add(y.negate())}is0(){return this.equals(A.ZERO)}multiply(y){const{endo:w}=e;if(!i.isValidNot0(y))throw new Error("invalid scalar: out of range");let g,m;const _=B=>q.cached(this,B,I=>cl(A,I));if(w){const{k1neg:B,k1:I,k2neg:$,k2:D}=R(y),{p:T,f:F}=_(I),{p:k,f:N}=_(D);m=F.add(N),g=C(w.beta,T,k,B,$)}else{const{p:B,f:I}=_(y);g=B,m=I}return cl(A,[g,m])[0]}multiplyUnsafe(y){const{endo:w}=e,g=this;if(!i.isValid(y))throw new Error("invalid scalar: out of range");if(y===er||g.is0())return A.ZERO;if(y===bs)return g;if(q.hasCache(this))return this.multiply(y);if(w){const{k1neg:m,k1:_,k2neg:B,k2:I}=R(y),{p1:$,p2:D}=B7(A,g,_,I);return C(w.beta,$,D,m,B)}else return q.unsafe(g,y)}multiplyAndAddUnsafe(y,w,g){const m=this.multiplyUnsafe(w).add(y.multiplyUnsafe(g));return m.is0()?void 0:m}toAffine(y){return U(this,y)}isTorsionFree(){const{isTorsionFree:y}=e;return o===bs?!0:y?y(A,this):q.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:y}=e;return o===bs?this:y?y(A,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(y=!0){return ec(y,"isCompressed"),this.assertValidity(),d(A,this,y)}toHex(y=!0){return ds(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(y=!0){return this.toBytes(y)}_setWindowSize(y){this.precompute(y)}static normalizeZ(y){return cl(A,y)}static msm(y,w){return $7(A,i,y,w)}static fromPrivateKey(y){return A.BASE.multiply(ws(i,y))}}A.BASE=new A(s.Gx,s.Gy,r.ONE),A.ZERO=new A(r.ZERO,r.ONE,r.ZERO),A.Fp=r,A.Fn=i;const j=i.BITS,q=new S7(A,e.endo?Math.ceil(j/2):j);return A.BASE.precompute(8),A}function wy(t){return Uint8Array.of(t?2:3)}function my(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function z7(t,e={}){const{Fn:n}=t,r=e.randomBytes||Gu,i=Object.assign(my(t.Fp,n),{seed:cy(n.ORDER)});function s(l){try{return!!ws(n,l)}catch{return!1}}function o(l,d){const{publicKey:p,publicKeyUncompressed:b}=i;try{const v=l.length;return d===!0&&v!==p||d===!1&&v!==b?!1:!!t.fromBytes(l)}catch{return!1}}function a(l=r(i.seed)){return x7(Bi(l,i.seed,"seed"),n.ORDER)}function c(l,d=!0){return t.BASE.multiply(ws(n,l)).toBytes(d)}function f(l){const d=a(l);return{secretKey:d,publicKey:c(d)}}function u(l){if(typeof l=="bigint")return!1;if(l instanceof t)return!0;const{secretKey:d,publicKey:p,publicKeyUncompressed:b}=i;if(n.allowedLengths||d===p)return;const v=ct("key",l).length;return v===p||v===b}function h(l,d,p=!0){if(u(l)===!0)throw new Error("first arg must be private key");if(u(d)===!1)throw new Error("second arg must be public key");const b=ws(n,l);return t.fromHex(d).multiply(b).toBytes(p)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:f,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:l=>ws(n,l),precompute(l=8,d=t.BASE){return d.precompute(l,!1)}},lengths:i})}function H7(t,e,n={}){x1(e),ic(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Gu,i=n.hmac||((w,...g)=>K1(e,w,kr(...g))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:f,getPublicKey:u,getSharedSecret:h,utils:l,lengths:d}=z7(t,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},b="compact";function v(w){const g=a>>bs;return w>g}function O(w,g){if(!o.isValidNot0(g))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return g}function P(w,g){hl(g);const m=d.signature,_=g==="compact"?m:g==="recovered"?m+1:void 0;return Bi(w,_,`${g} signature`)}class x{constructor(g,m,_){this.r=O("r",g),this.s=O("s",m),_!=null&&(this.recovery=_),Object.freeze(this)}static fromBytes(g,m=b){P(g,m);let _;if(m==="der"){const{r:D,s:T}=Qn.toSig(Bi(g));return new x(D,T)}m==="recovered"&&(_=g[0],m="compact",g=g.subarray(1));const B=o.BYTES,I=g.subarray(0,B),$=g.subarray(B,B*2);return new x(o.fromBytes(I),o.fromBytes($),_)}static fromHex(g,m){return this.fromBytes(Xa(g),m)}addRecoveryBit(g){return new x(this.r,this.s,g)}recoverPublicKey(g){const m=s.ORDER,{r:_,s:B,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*by<m&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");const $=I===2||I===3?_+a:_;if(!s.isValid($))throw new Error("recovery id 2 or 3 invalid");const D=s.toBytes($),T=t.fromBytes(kr(wy((I&1)===0),D)),F=o.inv($),k=R(ct("msgHash",g)),N=o.create(-k*F),M=o.create(B*F),z=t.BASE.multiplyUnsafe(N).add(T.multiplyUnsafe(M));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return v(this.s)}toBytes(g=b){if(hl(g),g==="der")return Xa(Qn.hexFromSig(this));const m=o.toBytes(this.r),_=o.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return kr(Uint8Array.of(this.recovery),m,_)}return kr(m,_)}toHex(g){return ds(this.toBytes(g))}assertValidity(){}static fromCompact(g){return x.fromBytes(ct("sig",g),"compact")}static fromDER(g){return x.fromBytes(ct("sig",g),"der")}normalizeS(){return this.hasHighS()?new x(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return ds(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return ds(this.toBytes("compact"))}}const S=n.bits2int||function(w){if(w.length>8192)throw new Error("input is too large");const g=nc(w),m=w.length*8-c;return m>0?g>>BigInt(m):g},R=n.bits2int_modN||function(w){return o.create(S(w))},U=go(c);function L(w){return ol("num < 2^"+c,w,er,U),o.toBytes(w)}function C(w,g){return Bi(w,void 0,"message"),g?Bi(e(w),void 0,"prehashed message"):w}function A(w,g,m){if(["recovered","canonical"].some(M=>M in m))throw new Error("sign() legacy options not supported");const{lowS:_,prehash:B,extraEntropy:I}=dl(m,p);w=C(w,B);const $=R(w),D=ws(o,g),T=[L(D),L($)];if(I!=null&&I!==!1){const M=I===!0?r(d.secretKey):I;T.push(ct("extraEntropy",M))}const F=kr(...T),k=$;function N(M){const z=S(M);if(!o.isValidNot0(z))return;const K=o.inv(z),H=t.BASE.multiply(z).toAffine(),G=o.create(H.x);if(G===er)return;const ee=o.create(K*o.create(k+G*D));if(ee===er)return;let te=(H.x===G?0:2)|Number(H.y&bs),re=ee;return _&&v(ee)&&(re=o.neg(ee),te^=1),new x(G,re,te)}return{seed:F,k2sig:N}}function j(w,g,m={}){w=ct("message",w);const{seed:_,k2sig:B}=A(w,g,m);return d7(e.outputLen,o.BYTES,i)(_,B)}function q(w){let g;const m=typeof w=="string"||Ya(w),_=!m&&w!==null&&typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!m&&!_)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(_)g=new x(w.r,w.s);else if(m){try{g=x.fromBytes(ct("sig",w),"der")}catch(B){if(!(B instanceof Qn.Err))throw B}if(!g)try{g=x.fromBytes(ct("sig",w),"compact")}catch{return!1}}return g||!1}function E(w,g,m,_={}){const{lowS:B,prehash:I,format:$}=dl(_,p);if(m=ct("publicKey",m),g=C(ct("message",g),I),"strict"in _)throw new Error("options.strict was renamed to lowS");const D=$===void 0?q(w):x.fromBytes(ct("sig",w),$);if(D===!1)return!1;try{const T=t.fromBytes(m);if(B&&D.hasHighS())return!1;const{r:F,s:k}=D,N=R(g),M=o.inv(k),z=o.create(N*M),K=o.create(F*M),H=t.BASE.multiplyUnsafe(z).add(T.multiplyUnsafe(K));return H.is0()?!1:o.create(H.x)===F}catch{return!1}}function y(w,g,m={}){const{prehash:_}=dl(m,p);return g=C(g,_),x.fromBytes(w,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:h,utils:l,lengths:d,Point:t,sign:j,verify:E,recoverPublicKey:y,Signature:x,hash:e})}function V7(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=Gr(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 K7(t){const{CURVE:e,curveOpts:n}=V7(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 G7(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,oy(n.Fn.ORDER,n.Fn.BITS))})}function Z7(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=K7(t),s=j7(e,n),o=H7(s,r,i);return G7(t,o)}function pl(t,e){const n=r=>Z7({...t,hash:r});return{...n(e),create:n}}const vy={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},Ey={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},xy={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},W7=Gr(vy.p),Y7=Gr(Ey.p),X7=Gr(xy.p);pl({...vy,Fp:W7,lowS:!1},C9),pl({...Ey,Fp:Y7,lowS:!1},L9),pl({...xy,Fp:X7,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},F9);const J7="https://api.pay.walletconnect.com",Q7="js-walletconnect-pay",eI="1.0.2",hn="WalletConnectPay";function tI(){return r9()?"rn-ios":n9()?"rn-android":i9()?"browser":y1()?"node":"unknown"}var nI=Object.defineProperty,rI=(t,e,n)=>e in t?nI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,_y=(t,e,n)=>rI(t,typeof e!="symbol"?e+"":e,n);class Ae extends Error{constructor(e,n,r){super(n),_y(this,"code"),_y(this,"originalMessage"),this.name="PayError",this.code=e,this.originalMessage=r??n,Object.setPrototypeOf(this,Ae.prototype)}static fromNativeError(e){if(e instanceof Ae)return e;const n=e instanceof Error?e.message:String(e);return n.includes("JSON parse error")?new Ae("JSON_PARSE",n):n.includes("JSON serialize error")?new Ae("JSON_SERIALIZE",n):n.includes("Payment options error")?new Ae("PAYMENT_OPTIONS",n):n.includes("Payment request error")?new Ae("PAYMENT_REQUEST",n):n.includes("Confirm payment error")?new Ae("CONFIRM_PAYMENT",n):new Ae("UNKNOWN",n)}}class gl extends Ae{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,gl.prototype)}}class yl extends Ae{constructor(e){super("PAYMENT_OPTIONS",`Failed to get payment options: ${e}`,e),this.name="PaymentOptionsError",Object.setPrototypeOf(this,yl.prototype)}}class bl extends Ae{constructor(e){super("PAYMENT_REQUEST",`Failed to get payment actions: ${e}`,e),this.name="PaymentActionsError",Object.setPrototypeOf(this,bl.prototype)}}class wl extends Ae{constructor(e){super("CONFIRM_PAYMENT",`Failed to confirm payment: ${e}`,e),this.name="ConfirmPaymentError",Object.setPrototypeOf(this,wl.prototype)}}var iI=Object.defineProperty,sI=(t,e,n)=>e in t?iI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oI=(t,e,n)=>sI(t,typeof e!="symbol"?e+"":e,n);let Zr;function Iy(){var t,e;if(Zr!==void 0)return Zr;try{const n=globalThis.ReactNative;if((t=n?.NativeModules)!=null&&t.RNWalletConnectPay)return Zr=n.NativeModules.RNWalletConnectPay,Zr;const r=(e=globalThis.expo)==null?void 0:e.modules;return r!=null&&r.RNWalletConnectPay?(Zr=r.RNWalletConnectPay,Zr):(Zr=null,null)}catch{return Zr=null,null}}function aI(){return Iy()!==null}class cI{constructor(e){oI(this,"module");const n=Iy();if(!n)throw new gl;if(n.initialize)try{const r=JSON.stringify(e);n.initialize(r)}catch(r){throw new Ae("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 Ae.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 Ae.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 Ae.fromNativeError(r)}}}function fI(t){return new cI(t)}function Sy(){return aI()?"native":null}function uI(t){const e=Sy();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 fI(t);case"wasm":throw new Error("WASM provider not yet implemented");default:throw new Error(`Unknown provider type: ${e}`)}}function lI(){return Sy()!==null}var hI=Object.defineProperty,dI=(t,e,n)=>e in t?hI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,bo=(t,e,n)=>dI(t,typeof e!="symbol"?e+"":e,n);class pI{constructor(e){bo(this,"appId"),bo(this,"apiKey"),bo(this,"baseUrl"),bo(this,"logger"),bo(this,"provider");var n,r,i;this.appId=e.appId,this.apiKey=e.apiKey,this.baseUrl=(n=e.baseUrl)!=null?n:J7,this.logger=typeof e.logger=="string"?cd(ef({level:e.logger})):(r=e.logger)!=null?r:cd(ef({level:"error"})),this.logger.trace(`${hn} initialized`);const s={baseUrl:this.baseUrl,projectId:e.appId,apiKey:e.apiKey,appId:e.appId,clientId:e.clientId,sdkName:Q7,sdkVersion:eI,sdkPlatform:tI(),bundleId:(i=s9())!=null?i:""};this.provider=uI(s),this.logger.debug(`${hn} provider initialized`)}static isAvailable(){return lI()}async getPaymentOptions(e){this.logger.debug({paymentLink:e.paymentLink,accounts:e.accounts,includePaymentInfo:e.includePaymentInfo},`${hn} getPaymentOptions`);try{const n=await this.provider.getPaymentOptions(e);return this.logger.debug({paymentId:n.paymentId,optionsCount:n.options.length},`${hn} getPaymentOptions response`),n}catch(n){throw this.logger.error({error:n},`${hn} getPaymentOptions error`),n instanceof Ae?n:new yl(String(n))}}async getRequiredPaymentActions(e){this.logger.debug({paymentId:e.paymentId,optionId:e.optionId},`${hn} getRequiredPaymentActions`);try{const n=await this.provider.getRequiredPaymentActions(e);return this.logger.debug({actionsCount:n.length},`${hn} getRequiredPaymentActions response`),n}catch(n){throw this.logger.error({error:n},`${hn} getRequiredPaymentActions error`),n instanceof Ae?n:new bl(String(n))}}async confirmPayment(e){this.logger.debug({paymentId:e.paymentId,optionId:e.optionId,signaturesCount:e.signatures.length,hasCollectedData:!!e.collectedData},`${hn} confirmPayment`);try{const n=await this.provider.confirmPayment(e);return this.logger.debug({status:n.status,isFinal:n.isFinal},`${hn} confirmPayment response`),n}catch(n){throw this.logger.error({error:n},`${hn} confirmPayment error`),n instanceof Ae?n:new wl(String(n))}}}const By=pI,$y="wc",gI=2,ml="WalletKit",yI=`${$y}@2:${ml}:`,bI={database:":memory:"},wI="request";class Oi{}class mI extends Oi{constructor(e){super()}}const Ay=Z.FIVE_SECONDS,Di={pulse:"heartbeat_pulse"};class vl extends mI{constructor(e){super(e),this.events=new Qe.exports.EventEmitter,this.interval=Ay,this.interval=e?.interval||Ay}static async init(e){const n=new vl(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(Di.pulse)}}const vI=/"(?:_|\\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*:/,EI=/"(?: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*:/,xI=/^\s*["[{]|^\s*-?\d{1,16}(\.\d{1,17})?([Ee][+-]?\d+)?\s*$/;function _I(t,e){if(t==="__proto__"||t==="constructor"&&e&&typeof e=="object"&&"prototype"in e){II(t);return}return e}function II(t){console.warn(`[destr] Dropping "${t}" key to prevent prototype pollution.`)}function cc(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(!xI.test(t)){if(e.strict)throw new SyntaxError("[destr] Invalid JSON");return t}try{if(vI.test(t)||EI.test(t)){if(e.strict)throw new Error("[destr] Possible prototype pollution");return JSON.parse(t,_I)}return JSON.parse(t)}catch(r){if(e.strict)throw r;return t}}function SI(t){return!t||typeof t.then!="function"?Promise.resolve(t):t}function qe(t,...e){try{return SI(t(...e))}catch(n){return Promise.reject(n)}}function BI(t){const e=typeof t;return t===null||e!=="object"&&e!=="function"}function $I(t){const e=Object.getPrototypeOf(t);return!e||e.isPrototypeOf(Object)}function fc(t){if(BI(t))return String(t);if($I(t)||Array.isArray(t))return JSON.stringify(t);if(typeof t.toJSON=="function")return fc(t.toJSON());throw new Error("[unstorage] Cannot stringify value!")}function Oy(){if(typeof Buffer>"u")throw new TypeError("[unstorage] Buffer is not supported!")}const El="base64:";function AI(t){if(typeof t=="string")return t;Oy();const e=Buffer.from(t).toString("base64");return El+e}function OI(t){return typeof t!="string"||!t.startsWith(El)?t:(Oy(),Buffer.from(t.slice(El.length),"base64"))}function Pt(t){return t?t.split("?")[0].replace(/[/\\]/g,":").replace(/:+/g,":").replace(/^:|:$/g,""):""}function DI(...t){return Pt(t.join(":"))}function uc(t){return t=Pt(t),t?t+":":""}function GU(t){return t}const PI="memory",RI=()=>{const t=new Map;return{name:PI,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 TI(t={}){const e={mounts:{"":t.driver||RI()},mountpoints:[""],watching:!1,watchListeners:[],unwatch:{}},n=f=>{for(const u of e.mountpoints)if(f.startsWith(u))return{base:u,relativeKey:f.slice(u.length),driver:e.mounts[u]};return{base:"",relativeKey:f,driver:e.mounts[""]}},r=(f,u)=>e.mountpoints.filter(h=>h.startsWith(f)||u&&f.startsWith(h)).map(h=>({relativeBase:f.length>h.length?f.slice(h.length):void 0,mountpoint:h,driver:e.mounts[h]})),i=(f,u)=>{if(e.watching){u=Pt(u);for(const h of e.watchListeners)h(f,u)}},s=async()=>{if(!e.watching){e.watching=!0;for(const f in e.mounts)e.unwatch[f]=await Dy(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,u,h)=>{const l=new Map,d=p=>{let b=l.get(p.base);return b||(b={driver:p.driver,base:p.base,items:[]},l.set(p.base,b)),b};for(const p of f){const b=typeof p=="string",v=Pt(b?p:p.key),O=b?void 0:p.value,P=b||!p.options?u:{...u,...p.options},x=n(v);d(x).items.push({key:v,value:O,relativeKey:x.relativeKey,options:P})}return Promise.all([...l.values()].map(p=>h(p))).then(p=>p.flat())},c={hasItem(f,u={}){f=Pt(f);const{relativeKey:h,driver:l}=n(f);return qe(l.hasItem,h,u)},getItem(f,u={}){f=Pt(f);const{relativeKey:h,driver:l}=n(f);return qe(l.getItem,h,u).then(d=>cc(d))},getItems(f,u){return a(f,u,h=>h.driver.getItems?qe(h.driver.getItems,h.items.map(l=>({key:l.relativeKey,options:l.options})),u).then(l=>l.map(d=>({key:DI(h.base,d.key),value:cc(d.value)}))):Promise.all(h.items.map(l=>qe(h.driver.getItem,l.relativeKey,l.options).then(d=>({key:l.key,value:cc(d)})))))},getItemRaw(f,u={}){f=Pt(f);const{relativeKey:h,driver:l}=n(f);return l.getItemRaw?qe(l.getItemRaw,h,u):qe(l.getItem,h,u).then(d=>OI(d))},async setItem(f,u,h={}){if(u===void 0)return c.removeItem(f);f=Pt(f);const{relativeKey:l,driver:d}=n(f);d.setItem&&(await qe(d.setItem,l,fc(u),h),d.watch||i("update",f))},async setItems(f,u){await a(f,u,async h=>{if(h.driver.setItems)return qe(h.driver.setItems,h.items.map(l=>({key:l.relativeKey,value:fc(l.value),options:l.options})),u);h.driver.setItem&&await Promise.all(h.items.map(l=>qe(h.driver.setItem,l.relativeKey,fc(l.value),l.options)))})},async setItemRaw(f,u,h={}){if(u===void 0)return c.removeItem(f,h);f=Pt(f);const{relativeKey:l,driver:d}=n(f);if(d.setItemRaw)await qe(d.setItemRaw,l,u,h);else if(d.setItem)await qe(d.setItem,l,AI(u),h);else return;d.watch||i("update",f)},async removeItem(f,u={}){typeof u=="boolean"&&(u={removeMeta:u}),f=Pt(f);const{relativeKey:h,driver:l}=n(f);l.removeItem&&(await qe(l.removeItem,h,u),(u.removeMeta||u.removeMata)&&await qe(l.removeItem,h+"$",u),l.watch||i("remove",f))},async getMeta(f,u={}){typeof u=="boolean"&&(u={nativeOnly:u}),f=Pt(f);const{relativeKey:h,driver:l}=n(f),d=Object.create(null);if(l.getMeta&&Object.assign(d,await qe(l.getMeta,h,u)),!u.nativeOnly){const p=await qe(l.getItem,h+"$",u).then(b=>cc(b));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(d,p))}return d},setMeta(f,u,h={}){return this.setItem(f+"$",u,h)},removeMeta(f,u={}){return this.removeItem(f+"$",u)},async getKeys(f,u={}){f=uc(f);const h=r(f,!0);let l=[];const d=[];for(const p of h){const b=await qe(p.driver.getKeys,p.relativeBase,u);for(const v of b){const O=p.mountpoint+Pt(v);l.some(P=>O.startsWith(P))||d.push(O)}l=[p.mountpoint,...l.filter(v=>!v.startsWith(p.mountpoint))]}return f?d.filter(p=>p.startsWith(f)&&p[p.length-1]!=="$"):d.filter(p=>p[p.length-1]!=="$")},async clear(f,u={}){f=uc(f),await Promise.all(r(f,!1).map(async h=>{if(h.driver.clear)return qe(h.driver.clear,h.relativeBase,u);if(h.driver.removeItem){const l=await h.driver.getKeys(h.relativeBase||"",u);return Promise.all(l.map(d=>h.driver.removeItem(d,u)))}}))},async dispose(){await Promise.all(Object.values(e.mounts).map(f=>Py(f)))},async watch(f){return await s(),e.watchListeners.push(f),async()=>{e.watchListeners=e.watchListeners.filter(u=>u!==f),e.watchListeners.length===0&&await o()}},async unwatch(){e.watchListeners=[],await o()},mount(f,u){if(f=uc(f),f&&e.mounts[f])throw new Error(`already mounted at ${f}`);return f&&(e.mountpoints.push(f),e.mountpoints.sort((h,l)=>l.length-h.length)),e.mounts[f]=u,e.watching&&Promise.resolve(Dy(u,i,f)).then(h=>{e.unwatch[f]=h}).catch(console.error),c},async unmount(f,u=!0){f=uc(f),!(!f||!e.mounts[f])&&(e.watching&&f in e.unwatch&&(e.unwatch[f](),delete e.unwatch[f]),u&&await Py(e.mounts[f]),e.mountpoints=e.mountpoints.filter(h=>h!==f),delete e.mounts[f])},getMount(f=""){f=Pt(f)+":";const u=n(f);return{driver:u.driver,base:u.base}},getMounts(f="",u={}){return f=Pt(f),r(f,u.parents).map(l=>({driver:l.driver,base:l.mountpoint}))},keys:(f,u={})=>c.getKeys(f,u),get:(f,u={})=>c.getItem(f,u),set:(f,u,h={})=>c.setItem(f,u,h),has:(f,u={})=>c.hasItem(f,u),del:(f,u={})=>c.removeItem(f,u),remove:(f,u={})=>c.removeItem(f,u)};return c}function Dy(t,e,n){return t.watch?t.watch((r,i)=>e(r,n+i)):()=>{}}async function Py(t){typeof t.dispose=="function"&&await qe(t.dispose)}function Pi(t){return new Promise((e,n)=>{t.oncomplete=t.onsuccess=()=>e(t.result),t.onabort=t.onerror=()=>n(t.error)})}function Ry(t,e){const n=indexedDB.open(t);n.onupgradeneeded=()=>n.result.createObjectStore(e);const r=Pi(n);return(i,s)=>r.then(o=>s(o.transaction(e,i).objectStore(e)))}let xl;function wo(){return xl||(xl=Ry("keyval-store","keyval")),xl}function Ty(t,e=wo()){return e("readonly",n=>Pi(n.get(t)))}function NI(t,e,n=wo()){return n("readwrite",r=>(r.put(e,t),Pi(r.transaction)))}function UI(t,e=wo()){return e("readwrite",n=>(n.delete(t),Pi(n.transaction)))}function CI(t=wo()){return t("readwrite",e=>(e.clear(),Pi(e.transaction)))}function FI(t,e){return t.openCursor().onsuccess=function(){this.result&&(e(this.result),this.result.continue())},Pi(t.transaction)}function LI(t=wo()){return t("readonly",e=>{if(e.getAllKeys)return Pi(e.getAllKeys());const n=[];return FI(e,r=>n.push(r.key)).then(()=>n)})}const kI="idb-keyval";var qI=(t={})=>{const e=t.base&&t.base.length>0?`${t.base}:`:"",n=i=>e+i;let r;return t.dbName&&t.storeName&&(r=Ry(t.dbName,t.storeName)),{name:kI,options:t,async hasItem(i){return!(typeof await Ty(n(i),r)>"u")},async getItem(i){return await Ty(n(i),r)??null},setItem(i,s){return NI(n(i),s,r)},removeItem(i){return UI(n(i),r)},getKeys(){return LI(r)},clear(){return CI(r)}}};const MI="WALLET_CONNECT_V2_INDEXED_DB",jI="keyvaluestorage";class zI{constructor(){this.indexedDb=TI({driver:qI({dbName:MI,storeName:jI})})}async getKeys(){return this.indexedDb.getKeys()}async getEntries(){return(await this.indexedDb.getItems(await this.indexedDb.getKeys())).map(e=>[e.key,e.value])}async getItem(e){const n=await this.indexedDb.getItem(e);if(n!==null)return n}async setItem(e,n){await this.indexedDb.setItem(e,to(n))}async removeItem(e){await this.indexedDb.removeItem(e)}}var _l=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},lc={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 _l<"u"&&_l.localStorage?lc.exports=_l.localStorage:typeof window<"u"&&window.localStorage?lc.exports=window.localStorage:lc.exports=new e})();function HI(t){var e;return[t[0],fs((e=t[1])!=null?e:"")]}class VI{constructor(){this.localStorage=lc.exports}async getKeys(){return Object.keys(this.localStorage)}async getEntries(){return Object.entries(this.localStorage).map(HI)}async getItem(e){const n=this.localStorage.getItem(e);if(n!==null)return fs(n)}async setItem(e,n){this.localStorage.setItem(e,to(n))}async removeItem(e){this.localStorage.removeItem(e)}}const KI="wc_storage_version",Ny=1,GI=async(t,e,n)=>{const r=KI,i=await e.getItem(r);if(i&&i>=Ny){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,Ny),n(e),ZI(t,o)},ZI=async(t,e)=>{e.length&&e.forEach(async n=>{await t.removeItem(n)})};class WI{constructor(){this.initialized=!1,this.setInitialized=n=>{this.storage=n,this.initialized=!0};const e=new VI;this.storage=e;try{const n=new zI;GI(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 YI=Object.defineProperty,XI=(t,e,n)=>e in t?YI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Uy=(t,e,n)=>XI(t,typeof e!="symbol"?e+"":e,n);class JI extends Oi{constructor(e){super(),this.opts=e,Uy(this,"protocol","wc"),Uy(this,"version",2)}}var QI=Object.defineProperty,eS=(t,e,n)=>e in t?QI(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,tS=(t,e,n)=>eS(t,typeof e!="symbol"?e+"":e,n);class nS extends Oi{constructor(e,n){super(),this.core=e,this.logger=n,tS(this,"records",new Map)}}class rS{constructor(e,n){this.logger=e,this.core=n}}class iS extends Oi{constructor(e,n){super(),this.relayer=e,this.logger=n}}class sS extends Oi{constructor(e){super()}}class oS{constructor(e,n,r,i){this.core=e,this.logger=n,this.name=r}}class aS extends Oi{constructor(e,n){super(),this.relayer=e,this.logger=n}}class cS extends Oi{constructor(e,n){super(),this.core=e,this.logger=n}}class fS{constructor(e,n,r){this.core=e,this.logger=n,this.store=r}}class uS{constructor(e,n){this.projectId=e,this.logger=n}}class lS{constructor(e,n,r){this.core=e,this.logger=n,this.telemetryEnabled=r}}var hS=Object.defineProperty,dS=(t,e,n)=>e in t?hS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Cy=(t,e,n)=>dS(t,typeof e!="symbol"?e+"":e,n);class pS{constructor(e){this.opts=e,Cy(this,"protocol","wc"),Cy(this,"version",2)}}class gS{constructor(e){this.client=e}}function yS(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 bS(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 wS=new TextEncoder,mS=50;function vS(t,e,n){wS.encodeInto(t,e.subarray(n))}function ES(t,e,n){t.length>mS?vS(t,e,n):bS(t,e,n)}const xS=4096;function Fy(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,u=t[r++]&63;let h=(a&7)<<18|c<<12|f<<6|u;h>65535&&(h-=65536,s.push(h>>>10&1023|55296),h=56320|h&1023),s.push(h)}else s.push(a);s.length>=xS&&(o+=String.fromCharCode(...s),s.length=0)}return s.length>0&&(o+=String.fromCharCode(...s)),o}const _S=new TextDecoder,IS=200;function SS(t,e,n){const r=t.subarray(e,e+n);return _S.decode(r)}function BS(t,e,n){return n>IS?SS(t,e,n):Fy(t,e,n)}class hc{constructor(e,n){this.type=e,this.data=n}}class Mt extends Error{constructor(e){super(e);const n=Object.create(Mt.prototype);Object.setPrototypeOf(this,n),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:Mt.name})}}const mo=4294967295;function $S(t,e,n){const r=n/4294967296,i=n;t.setUint32(e,r),t.setUint32(e+4,i)}function Ly(t,e,n){const r=Math.floor(n/4294967296),i=n;t.setUint32(e,r),t.setUint32(e+4,i)}function ky(t,e){const n=t.getInt32(e),r=t.getUint32(e+4);return n*4294967296+r}function AS(t,e){const n=t.getUint32(e),r=t.getUint32(e+4);return n*4294967296+r}const OS=-1,DS=4294967296-1,PS=17179869184-1;function RS({sec:t,nsec:e}){if(t>=0&&e>=0&&t<=PS)if(e===0&&t<=DS){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),Ly(r,4,t),n}}function TS(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 NS(t){if(t instanceof Date){const e=TS(t);return RS(e)}else return null}function US(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=ky(e,4),r=e.getUint32(0);return{sec:n,nsec:r}}default:throw new Mt(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${t.length}`)}}function CS(t){const e=US(t);return new Date(e.sec*1e3+e.nsec/1e6)}const FS={type:OS,encode:NS,decode:CS};class dc{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(FS)}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 hc(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 hc(o,s)}}}return e instanceof hc?e:null}decode(e,n,r){const i=n<0?this.builtInDecoders[-1-n]:this.decoders[n];return i?i(e,n,r):new hc(n,e)}}dc.defaultCodec=new dc;function LS(t){return t instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&t instanceof SharedArrayBuffer}function Il(t){return t instanceof Uint8Array?t:ArrayBuffer.isView(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):LS(t)?new Uint8Array(t):Uint8Array.from(t)}const kS=100,qS=2048;class Sl{constructor(e){this.entered=!1,this.extensionCodec=e?.extensionCodec??dc.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??kS,this.initialBufferSize=e?.initialBufferSize??qS,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 Sl({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=yS(e);this.ensureBufferSizeToWrite(5+r),this.writeStringHeader(r),ES(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=Il(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),$S(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),Ly(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 MS(t,e){return new Sl(e).encodeSharedRef(t)}function Bl(t){return`${t<0?"-":""}0x${Math.abs(t).toString(16).padStart(2,"0")}`}const jS=16,zS=16;class HS{constructor(e=jS,n=zS){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=Fy(e,n,r),o=Uint8Array.prototype.slice.call(e,n,n+r);return this.store(o,s),s}}const $l="array",vo="map_key",qy="map_value",VS=t=>{if(typeof t=="string"||typeof t=="number")return t;throw new Mt("The type of key must be string or number but "+typeof t)};class KS{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=$l,n.position=0,n.size=e,n.array=new Array(e)}pushMapState(e){const n=this.getUninitializedStateFromPool();n.type=vo,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===$l){const r=e;r.size=0,r.array=void 0,r.position=0,r.type=void 0}if(e.type===vo||e.type===qy){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 Eo=-1,Al=new DataView(new ArrayBuffer(0)),GS=new Uint8Array(Al.buffer);try{Al.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 My=new RangeError("Insufficient data"),ZS=new HS;class Ol{constructor(e){this.totalPos=0,this.pos=0,this.view=Al,this.bytes=GS,this.headByte=Eo,this.stack=new KS,this.entered=!1,this.extensionCodec=e?.extensionCodec??dc.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??mo,this.maxBinLength=e?.maxBinLength??mo,this.maxArrayLength=e?.maxArrayLength??mo,this.maxMapLength=e?.maxMapLength??mo,this.maxExtLength=e?.maxExtLength??mo,this.keyDecoder=e?.keyDecoder!==void 0?e.keyDecoder:ZS,this.mapKeyConverter=e?.mapKeyConverter??VS}clone(){return new Ol({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=Eo,this.stack.reset()}setBuffer(e){const n=Il(e);this.bytes=n,this.view=new DataView(n.buffer,n.byteOffset,n.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===Eo&&!this.hasRemaining(1))this.setBuffer(e);else{const n=this.bytes.subarray(this.pos),r=Il(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 ${Bl(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 Mt(`Unrecognized type byte: ${Bl(e)}`);this.complete();const r=this.stack;for(;r.length>0;){const i=r.top();if(i.type===$l)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===vo){if(n==="__proto__")throw new Mt("The key __proto__ is not allowed");i.key=this.mapKeyConverter(n),i.type=qy;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=vo;continue e}}return n}}readHeadByte(){return this.headByte===Eo&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=Eo}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 Mt(`Unrecognized array type byte: ${Bl(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new Mt(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new Mt(`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 Mt(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+n+e)throw My;const r=this.pos+n;let i;return this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?i=this.keyDecoder.decode(this.bytes,r,e):i=BS(this.bytes,r,e),this.pos+=n+e,i}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===vo:!1}decodeBinary(e,n){if(e>this.maxBinLength)throw new Mt(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+n))throw My;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 Mt(`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=AS(this.view,this.pos);return this.pos+=8,e}readI64(){const e=ky(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 WS(t,e){return new Ol(e).decode(t)}const YS=":";function pc(t){const[e,n]=t.split(YS);return{namespace:e,reference:n}}function jy(t,e){return t.includes(":")?[t]:e.chains||[]}var XS=Object.defineProperty,JS=Object.defineProperties,QS=Object.getOwnPropertyDescriptors,zy=Object.getOwnPropertySymbols,eB=Object.prototype.hasOwnProperty,tB=Object.prototype.propertyIsEnumerable,Dl=(t,e,n)=>e in t?XS(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Hy=(t,e)=>{for(var n in e||(e={}))eB.call(e,n)&&Dl(t,n,e[n]);if(zy)for(var n of zy(e))tB.call(e,n)&&Dl(t,n,e[n]);return t},nB=(t,e)=>JS(t,QS(e)),Vy=(t,e,n)=>Dl(t,typeof e!="symbol"?e+"":e,n);const rB="ReactNative",jt={reactNative:"react-native",node:"node",browser:"browser",unknown:"unknown"},iB="js";function gc(){return typeof process<"u"&&typeof process.versions<"u"&&typeof process.versions.node<"u"}function Wr(){return!Un()&&!!Fs()&&navigator.product===rB}function sB(){return Wr()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="android"}function oB(){return Wr()&&typeof global<"u"&&typeof(global==null?void 0:global.Platform)<"u"&&(global==null?void 0:global.Platform.OS)==="ios"}function ms(){return!gc()&&!!Fs()&&!!Un()}function xo(){return Wr()?jt.reactNative:gc()?jt.node:ms()?jt.browser:jt.unknown}function Ky(){var t;try{return Wr()&&typeof global<"u"&&typeof(global==null?void 0:global.Application)<"u"?(t=global.Application)==null?void 0:t.applicationId:void 0}catch{return}}function aB(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 cB(t){var e,n;const r=Gy();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!=="")),nB(Hy(Hy({},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 Gy(){return Pd()||{name:"",description:"",url:"",icons:[""]}}function fB(){if(xo()===jt.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=l3();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 uB(){var t;const e=xo();return e===jt.browser?[e,((t=Dd())==null?void 0:t.host)||"unknown"].join(":"):e}function Zy(t,e,n){const r=fB(),i=uB();return[[t,e].join("-"),[iB,n].join("-"),r,i].join("/")}function lB({protocol:t,version:e,relayUrl:n,sdkVersion:r,auth:i,projectId:s,useOnCloseEvent:o,bundleId:a,packageName:c}){const f=n.split("?"),u=Zy(t,e,r),h={auth:i,ua:u,projectId:s,useOnCloseEvent:o||void 0,packageName:c||void 0,bundleId:a||void 0},l=aB(f[1]||"",h);return f[0]+"?"+l}function Ri(t,e){return t.filter(n=>e.includes(n)).length===t.length}function Pl(t){return Object.fromEntries(t.entries())}function Rl(t){return new Map(Object.entries(t))}function Ti(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 Bn(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 Wy(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 hB(t){return Wy("topic",t)}function dB(t){return Wy("id",t)}function Yy(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 Ue(t,e){return Z.fromMiliseconds((e||Date.now())+Z.toMiliseconds(t))}function Yr(t){return Date.now()>=Z.toMiliseconds(t)}function pe(t,e){return`${t}${e?`:${e}`:""}`}function Ni(t=[],e=[]){return[...new Set([...t,...e])]}async function pB({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=gB(s,t,e),a=xo();if(a===jt.browser){if(!((r=Un())!=null&&r.hasFocus())){console.warn("Document does not have focus, skipping deeplink.");return}yB(o)}else a===jt.reactNative&&typeof(global==null?void 0:global.Linking)<"u"&&await global.Linking.openURL(o)}catch(i){console.error(i)}}function gB(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}${vB(r,!0)}`}else i=`${i}/wc?${r}`;return i}function yB(t){let e="_self";mB()?e="_top":(wB()||t.startsWith("https://")||t.startsWith("http://"))&&(e="_blank"),window.open(t,e,"noreferrer noopener")}async function bB(t,e){let n="";try{if(ms()&&(n=localStorage.getItem(e),n))return n;n=await t.getItem(e)}catch(r){console.error(r)}return n}function Xy(t,e){if(!t.includes(e))return null;const n=t.split(/([&,?,=])/),r=n.indexOf(e);return n[r+2]}function Jy(){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 Tl(){return typeof process<"u"&&process.env.IS_VITEST==="true"}function wB(){return typeof window<"u"&&(!!window.TelegramWebviewProxy||!!window.Telegram||!!window.TelegramWebviewProxyProto)}function mB(){try{return window.self!==window.top}catch{return!1}}function vB(t,e=!1){const n=Buffer.from(t).toString("base64");return e?n.replace(/[=]/g,""):n}function Qy(t){return Buffer.from(t,"base64").toString("utf-8")}function EB(t){return new Promise(e=>setTimeout(e,t))}class xB{constructor({limit:e}){Vy(this,"limit"),Vy(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 yc=BigInt(2**32-1),eb=BigInt(32);function tb(t,e=!1){return e?{h:Number(t&yc),l:Number(t>>eb&yc)}:{h:Number(t>>eb&yc)|0,l:Number(t&yc)|0}}function nb(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}=tb(t[s],e);[r[s],i[s]]=[o,a]}return[r,i]}const rb=(t,e,n)=>t>>>n,ib=(t,e,n)=>t<<32-n|e>>>n,Xr=(t,e,n)=>t>>>n|e<<32-n,Jr=(t,e,n)=>t<<32-n|e>>>n,_o=(t,e,n)=>t<<64-n|e>>>n-32,Io=(t,e,n)=>t>>>n-32|e<<64-n,_B=(t,e)=>e,IB=(t,e)=>t,SB=(t,e,n)=>t<<n|e>>>32-n,BB=(t,e,n)=>e<<n|t>>>32-n,$B=(t,e,n)=>e<<n-32|t>>>64-n,AB=(t,e,n)=>t<<n-32|e>>>64-n;function dn(t,e,n,r){const i=(e>>>0)+(r>>>0);return{h:t+n+(i/2**32|0)|0,l:i|0}}const Nl=(t,e,n)=>(t>>>0)+(e>>>0)+(n>>>0),Ul=(t,e,n,r)=>e+n+r+(t/2**32|0)|0,OB=(t,e,n,r)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0),DB=(t,e,n,r,i)=>e+n+r+i+(t/2**32|0)|0,PB=(t,e,n,r,i)=>(t>>>0)+(e>>>0)+(n>>>0)+(r>>>0)+(i>>>0),RB=(t,e,n,r,i,s)=>e+n+r+i+s+(t/2**32|0)|0,vs=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function bc(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function tr(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function pn(t,...e){if(!bc(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 wc(t){if(typeof t!="function"||typeof t.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");tr(t.outputLen),tr(t.blockLen)}function Qr(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Cl(t,e){pn(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function So(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function Xt(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function Fl(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function $n(t,e){return t<<32-e|t>>>e}const sb=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function ob(t){return t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255}const nr=sb?t=>t:t=>ob(t);function TB(t){for(let e=0;e<t.length;e++)t[e]=ob(t[e]);return t}const ei=sb?t=>t:TB,ab=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",NB=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function Es(t){if(pn(t),ab)return t.toHex();let e="";for(let n=0;n<t.length;n++)e+=NB[t[n]];return e}const rr={_0:48,_9:57,A:65,F:70,a:97,f:102};function cb(t){if(t>=rr._0&&t<=rr._9)return t-rr._0;if(t>=rr.A&&t<=rr.F)return t-(rr.A-10);if(t>=rr.a&&t<=rr.f)return t-(rr.a-10)}function mc(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);if(ab)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=cb(t.charCodeAt(s)),a=cb(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 fb(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function gn(t){return typeof t=="string"&&(t=fb(t)),pn(t),t}function ti(...t){let e=0;for(let r=0;r<t.length;r++){const i=t[r];pn(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 vc{}function Bo(t){const e=r=>t().update(gn(r)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e}function UB(t){const e=(r,i)=>t(i).update(gn(r)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}function Ui(t=32){if(vs&&typeof vs.getRandomValues=="function")return vs.getRandomValues(new Uint8Array(t));if(vs&&typeof vs.randomBytes=="function")return Uint8Array.from(vs.randomBytes(t));throw new Error("crypto.getRandomValues must be defined")}const CB=BigInt(0),$o=BigInt(1),FB=BigInt(2),LB=BigInt(7),kB=BigInt(256),qB=BigInt(113),ub=[],lb=[],hb=[];for(let t=0,e=$o,n=1,r=0;t<24;t++){[n,r]=[r,(2*n+3*r)%5],ub.push(2*(5*r+n)),lb.push((t+1)*(t+2)/2%64);let i=CB;for(let s=0;s<7;s++)e=(e<<$o^(e>>LB)*qB)%kB,e&FB&&(i^=$o<<($o<<BigInt(s))-$o);hb.push(i)}const db=nb(hb,!0),MB=db[0],jB=db[1],pb=(t,e,n)=>n>32?$B(t,e,n):SB(t,e,n),gb=(t,e,n)=>n>32?AB(t,e,n):BB(t,e,n);function zB(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],u=n[c+1],h=pb(f,u,1)^n[a],l=gb(f,u,1)^n[a+1];for(let d=0;d<50;d+=10)t[o+d]^=h,t[o+d+1]^=l}let i=t[2],s=t[3];for(let o=0;o<24;o++){const a=lb[o],c=pb(i,s,a),f=gb(i,s,a),u=ub[o];i=t[u],s=t[u+1],t[u]=c,t[u+1]=f}for(let o=0;o<50;o+=10){for(let a=0;a<10;a++)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]^=MB[r],t[1]^=jB[r]}Xt(n)}class Ll extends vc{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,tr(r),!(0<e&&e<200))throw new Error("only keccak-f1600 function is supported");this.state=new Uint8Array(200),this.state32=So(this.state)}clone(){return this._cloneInto()}keccak(){ei(this.state32),zB(this.state32,this.rounds),ei(this.state32),this.posOut=0,this.pos=0}update(e){Qr(this),e=gn(e),pn(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){Qr(this,!1),pn(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 tr(e),this.xofInto(new Uint8Array(e))}digestInto(e){if(Cl(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,Xt(this.state)}_cloneInto(e){const{blockLen:n,suffix:r,outputLen:i,rounds:s,enableXOF:o}=this;return e||(e=new Ll(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 HB=(t,e,n)=>Bo(()=>new Ll(e,t,n)),VB=HB(1,136,256/8);function KB(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 GB(t,e,n){return t&e^~t&n}function ZB(t,e,n){return t&e^t&n^e&n}class yb extends vc{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=Fl(this.buffer)}update(e){Qr(this),e=gn(e),pn(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=Fl(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){Qr(this),Cl(e,this),this.finished=!0;const{buffer:n,view:r,blockLen:i,isLE:s}=this;let{pos:o}=this;n[o++]=128,Xt(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(r,0),o=0);for(let h=o;h<i;h++)n[h]=0;KB(r,i-8,BigInt(this.length*8),s),this.process(r,0);const a=Fl(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=c/4,u=this.get();if(f>u.length)throw new Error("_sha2: outputLen bigger than state");for(let h=0;h<f;h++)a.setUint32(4*h,u[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 ni=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ft=Uint32Array.from([3418070365,3238371032,1654270250,914150663,2438529370,812702999,355462360,4144912697,1731405415,4290775857,2394180231,1750603025,3675008525,1694076839,1203062813,3204075428]),ut=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),WB=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]),ri=new Uint32Array(64);class YB extends yb{constructor(e=32){super(64,e,8,!1),this.A=ni[0]|0,this.B=ni[1]|0,this.C=ni[2]|0,this.D=ni[3]|0,this.E=ni[4]|0,this.F=ni[5]|0,this.G=ni[6]|0,this.H=ni[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)ri[h]=e.getUint32(n,!1);for(let h=16;h<64;h++){const l=ri[h-15],d=ri[h-2],p=$n(l,7)^$n(l,18)^l>>>3,b=$n(d,17)^$n(d,19)^d>>>10;ri[h]=b+ri[h-7]+p+ri[h-16]|0}let{A:r,B:i,C:s,D:o,E:a,F:c,G:f,H:u}=this;for(let h=0;h<64;h++){const l=$n(a,6)^$n(a,11)^$n(a,25),d=u+l+GB(a,c,f)+WB[h]+ri[h]|0,p=($n(r,2)^$n(r,13)^$n(r,22))+ZB(r,i,s)|0;u=f,f=c,c=a,a=o+d|0,o=s,s=i,i=r,r=d+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,f=f+this.G|0,u=u+this.H|0,this.set(r,i,s,o,a,c,f,u)}roundClean(){Xt(ri)}destroy(){this.set(0,0,0,0,0,0,0,0),Xt(this.buffer)}}const bb=nb(["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))),XB=bb[0],JB=bb[1],ii=new Uint32Array(80),si=new Uint32Array(80);class kl extends yb{constructor(e=64){super(128,e,16,!1),this.Ah=ut[0]|0,this.Al=ut[1]|0,this.Bh=ut[2]|0,this.Bl=ut[3]|0,this.Ch=ut[4]|0,this.Cl=ut[5]|0,this.Dh=ut[6]|0,this.Dl=ut[7]|0,this.Eh=ut[8]|0,this.El=ut[9]|0,this.Fh=ut[10]|0,this.Fl=ut[11]|0,this.Gh=ut[12]|0,this.Gl=ut[13]|0,this.Hh=ut[14]|0,this.Hl=ut[15]|0}get(){const{Ah:e,Al:n,Bh:r,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:f,El:u,Fh:h,Fl:l,Gh:d,Gl:p,Hh:b,Hl:v}=this;return[e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,v]}set(e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,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=f|0,this.El=u|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=p|0,this.Hh=b|0,this.Hl=v|0}process(e,n){for(let x=0;x<16;x++,n+=4)ii[x]=e.getUint32(n),si[x]=e.getUint32(n+=4);for(let x=16;x<80;x++){const S=ii[x-15]|0,R=si[x-15]|0,U=Xr(S,R,1)^Xr(S,R,8)^rb(S,R,7),L=Jr(S,R,1)^Jr(S,R,8)^ib(S,R,7),C=ii[x-2]|0,A=si[x-2]|0,j=Xr(C,A,19)^_o(C,A,61)^rb(C,A,6),q=Jr(C,A,19)^Io(C,A,61)^ib(C,A,6),E=OB(L,q,si[x-7],si[x-16]),y=DB(E,U,j,ii[x-7],ii[x-16]);ii[x]=y|0,si[x]=E|0}let{Ah:r,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:f,Dl:u,Eh:h,El:l,Fh:d,Fl:p,Gh:b,Gl:v,Hh:O,Hl:P}=this;for(let x=0;x<80;x++){const S=Xr(h,l,14)^Xr(h,l,18)^_o(h,l,41),R=Jr(h,l,14)^Jr(h,l,18)^Io(h,l,41),U=h&d^~h&b,L=l&p^~l&v,C=PB(P,R,L,JB[x],si[x]),A=RB(C,O,S,U,XB[x],ii[x]),j=C|0,q=Xr(r,i,28)^_o(r,i,34)^_o(r,i,39),E=Jr(r,i,28)^Io(r,i,34)^Io(r,i,39),y=r&s^r&a^s&a,w=i&o^i&c^o&c;O=b|0,P=v|0,b=d|0,v=p|0,d=h|0,p=l|0,{h,l}=dn(f|0,u|0,A|0,j|0),f=a|0,u=c|0,a=s|0,c=o|0,s=r|0,o=i|0;const g=Nl(j,E,w);r=Ul(g,A,q,y),i=g|0}({h:r,l:i}=dn(this.Ah|0,this.Al|0,r|0,i|0)),{h:s,l:o}=dn(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=dn(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l:u}=dn(this.Dh|0,this.Dl|0,f|0,u|0),{h,l}=dn(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:p}=dn(this.Fh|0,this.Fl|0,d|0,p|0),{h:b,l:v}=dn(this.Gh|0,this.Gl|0,b|0,v|0),{h:O,l:P}=dn(this.Hh|0,this.Hl|0,O|0,P|0),this.set(r,i,s,o,a,c,f,u,h,l,d,p,b,v,O,P)}roundClean(){Xt(ii,si)}destroy(){Xt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}class QB extends kl{constructor(){super(48),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}}const lt=Uint32Array.from([573645204,4230739756,2673172387,3360449730,596883563,1867755857,2520282905,1497426621,2519219938,2827943907,3193839141,1401305490,721525244,746961066,246885852,2177182882]);class e$ extends kl{constructor(){super(32),this.Ah=lt[0]|0,this.Al=lt[1]|0,this.Bh=lt[2]|0,this.Bl=lt[3]|0,this.Ch=lt[4]|0,this.Cl=lt[5]|0,this.Dh=lt[6]|0,this.Dl=lt[7]|0,this.Eh=lt[8]|0,this.El=lt[9]|0,this.Fh=lt[10]|0,this.Fl=lt[11]|0,this.Gh=lt[12]|0,this.Gl=lt[13]|0,this.Hh=lt[14]|0,this.Hl=lt[15]|0}}const Ec=Bo(()=>new YB),t$=Bo(()=>new kl),n$=Bo(()=>new QB),r$=Bo(()=>new e$),i$=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]),Ce=Uint32Array.from([4089235720,1779033703,2227873595,3144134277,4271175723,1013904242,1595750129,2773480762,2917565137,1359893119,725511199,2600822924,4215389547,528734635,327033209,1541459225]),X=new Uint32Array(32);function oi(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=X[2*t],f=X[2*t+1],u=X[2*e],h=X[2*e+1],l=X[2*n],d=X[2*n+1],p=X[2*r],b=X[2*r+1],v=Nl(c,u,o);f=Ul(v,f,h,a),c=v|0,{Dh:b,Dl:p}={Dh:b^f,Dl:p^c},{Dh:b,Dl:p}={Dh:_B(b,p),Dl:IB(b)},{h:d,l}=dn(d,l,b,p),{Bh:h,Bl:u}={Bh:h^d,Bl:u^l},{Bh:h,Bl:u}={Bh:Xr(h,u,24),Bl:Jr(h,u,24)},X[2*t]=c,X[2*t+1]=f,X[2*e]=u,X[2*e+1]=h,X[2*n]=l,X[2*n+1]=d,X[2*r]=p,X[2*r+1]=b}function ai(t,e,n,r,i,s){const o=i[s],a=i[s+1];let c=X[2*t],f=X[2*t+1],u=X[2*e],h=X[2*e+1],l=X[2*n],d=X[2*n+1],p=X[2*r],b=X[2*r+1],v=Nl(c,u,o);f=Ul(v,f,h,a),c=v|0,{Dh:b,Dl:p}={Dh:b^f,Dl:p^c},{Dh:b,Dl:p}={Dh:Xr(b,p,16),Dl:Jr(b,p,16)},{h:d,l}=dn(d,l,b,p),{Bh:h,Bl:u}={Bh:h^d,Bl:u^l},{Bh:h,Bl:u}={Bh:_o(h,u,63),Bl:Io(h,u,63)},X[2*t]=c,X[2*t+1]=f,X[2*e]=u,X[2*e+1]=h,X[2*n]=l,X[2*n+1]=d,X[2*r]=p,X[2*r+1]=b}function s$(t,e={},n,r,i){if(tr(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 o$ extends vc{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,this.length=0,this.pos=0,tr(e),tr(n),this.blockLen=e,this.outputLen=n,this.buffer=new Uint8Array(e),this.buffer32=So(this.buffer)}update(e){Qr(this),e=gn(e),pn(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&&(ei(i),this.compress(i,0,!1),ei(i),this.pos=0);const f=Math.min(n-this.pos,s-c),u=o+c;if(f===n&&!(u%4)&&c+f<s){const h=new Uint32Array(a,u,Math.floor((s-c)/4));ei(h);for(let l=0;c+n<s;l+=i.length,c+=n)this.length+=n,this.compress(h,l,!1);ei(h);continue}r.set(e.subarray(c,c+f),this.pos),this.pos+=f,this.length+=f,c+=f}return this}digestInto(e){Qr(this),Cl(e,this);const{pos:n,buffer32:r}=this;this.finished=!0,Xt(this.buffer.subarray(n)),ei(r),this.compress(r,0,!0),ei(r);const i=So(e);this.get().forEach((s,o)=>i[o]=nr(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 a$ extends o${constructor(e={}){const n=e.dkLen===void 0?64:e.dkLen;super(128,n),this.v0l=Ce[0]|0,this.v0h=Ce[1]|0,this.v1l=Ce[2]|0,this.v1h=Ce[3]|0,this.v2l=Ce[4]|0,this.v2h=Ce[5]|0,this.v3l=Ce[6]|0,this.v3h=Ce[7]|0,this.v4l=Ce[8]|0,this.v4h=Ce[9]|0,this.v5l=Ce[10]|0,this.v5h=Ce[11]|0,this.v6l=Ce[12]|0,this.v6h=Ce[13]|0,this.v7l=Ce[14]|0,this.v7h=Ce[15]|0,s$(n,e,64,16,16);let{key:r,personalization:i,salt:s}=e,o=0;if(r!==void 0&&(r=gn(r),o=r.length),this.v0l^=this.outputLen|o<<8|65536|1<<24,s!==void 0){s=gn(s);const a=So(s);this.v4l^=nr(a[0]),this.v4h^=nr(a[1]),this.v5l^=nr(a[2]),this.v5h^=nr(a[3])}if(i!==void 0){i=gn(i);const a=So(i);this.v6l^=nr(a[0]),this.v6h^=nr(a[1]),this.v7l^=nr(a[2]),this.v7h^=nr(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:u,v5l:h,v5h:l,v6l:d,v6h:p,v7l:b,v7h:v}=this;return[e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,v]}set(e,n,r,i,s,o,a,c,f,u,h,l,d,p,b,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=f|0,this.v4h=u|0,this.v5l=h|0,this.v5h=l|0,this.v6l=d|0,this.v6h=p|0,this.v7l=b|0,this.v7h=v|0}compress(e,n,r){this.get().forEach((c,f)=>X[f]=c),X.set(Ce,16);let{h:i,l:s}=tb(BigInt(this.length));X[24]=Ce[8]^s,X[25]=Ce[9]^i,r&&(X[28]=~X[28],X[29]=~X[29]);let o=0;const a=i$;for(let c=0;c<12;c++)oi(0,4,8,12,e,n+2*a[o++]),ai(0,4,8,12,e,n+2*a[o++]),oi(1,5,9,13,e,n+2*a[o++]),ai(1,5,9,13,e,n+2*a[o++]),oi(2,6,10,14,e,n+2*a[o++]),ai(2,6,10,14,e,n+2*a[o++]),oi(3,7,11,15,e,n+2*a[o++]),ai(3,7,11,15,e,n+2*a[o++]),oi(0,5,10,15,e,n+2*a[o++]),ai(0,5,10,15,e,n+2*a[o++]),oi(1,6,11,12,e,n+2*a[o++]),ai(1,6,11,12,e,n+2*a[o++]),oi(2,7,8,13,e,n+2*a[o++]),ai(2,7,8,13,e,n+2*a[o++]),oi(3,4,9,14,e,n+2*a[o++]),ai(3,4,9,14,e,n+2*a[o++]);this.v0l^=X[0]^X[16],this.v0h^=X[1]^X[17],this.v1l^=X[2]^X[18],this.v1h^=X[3]^X[19],this.v2l^=X[4]^X[20],this.v2h^=X[5]^X[21],this.v3l^=X[6]^X[22],this.v3h^=X[7]^X[23],this.v4l^=X[8]^X[24],this.v4h^=X[9]^X[25],this.v5l^=X[10]^X[26],this.v5h^=X[11]^X[27],this.v6l^=X[12]^X[28],this.v6h^=X[13]^X[29],this.v7l^=X[14]^X[30],this.v7h^=X[15]^X[31],Xt(X)}destroy(){this.destroyed=!0,Xt(this.buffer32),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}}const c$=UB(t=>new a$(t)),f$="https://rpc.walletconnect.org/v1";function wb(t){const e=`Ethereum Signed Message:
19
+ ${t.length}`,n=new TextEncoder().encode(e+t);return"0x"+Buffer.from(VB(n)).toString("hex")}async function u$(t,e,n,r,i,s){switch(n.t){case"eip191":return await l$(t,e,n.s);case"eip1271":return await h$(t,e,n.s,r,i,s);default:throw new Error(`verifySignature failed: Attempted to verify CacaoSignature with unknown type: ${n.t}`)}}function l$(t,e,n){const r=i8(n);return p6({payload:wb(e),signature:r}).toLowerCase()===t.toLowerCase()}async function h$(t,e,n,r,i,s){const o=pc(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),u=(f.length/2).toString(16).padStart(64,"0"),h=(e.startsWith("0x")?e:wb(e)).substring(2),l=a+h+c+u+f,d=await fetch(`${s||f$}/?chainId=${r}&projectId=${i}`,{headers:{"Content-Type":"application/json"},method:"POST",body:JSON.stringify({id:d$(),jsonrpc:"2.0",method:"eth_call",params:[{to:t,data:l},"latest"]})}),{result:p}=await d.json();return p?p.slice(0,a.length).toLowerCase()===a.toLowerCase():!1}catch(a){return console.error("isValidEip1271Signature: ",a),!1}}function d$(){return Date.now()+Math.floor(Math.random()*1e3)}function p$(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 eo.encode(s)}function g$(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=c$(r,{dkLen:32});return eo.encode(i)}function mb(t){const e=new Uint8Array(Ec(y$(t)));return eo.encode(e)}function y$(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 vb(t){const e=Buffer.from(t,"base64"),n=WS(e).txn;if(!n)throw new Error("Invalid signed transaction: missing 'txn' field");const r=MS(n),i=Buffer.from("TX"),s=Buffer.concat([i,Buffer.from(r)]),o=r$(s);return f6.encode(o).replace(/=+$/,"")}function ql(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 b$(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(ql(e.length)),i.push(e),i.push(Buffer.from([18])),i.push(ql(n.length)),i.push(n),i.push(Buffer.from([26])),i.push(ql(r.length)),i.push(r);const s=Buffer.concat(i),o=Ec(s);return Buffer.from(o).toString("hex").toUpperCase()}function w$(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 m$=Object.defineProperty,v$=Object.defineProperties,E$=Object.getOwnPropertyDescriptors,Eb=Object.getOwnPropertySymbols,x$=Object.prototype.hasOwnProperty,_$=Object.prototype.propertyIsEnumerable,xb=(t,e,n)=>e in t?m$(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,I$=(t,e)=>{for(var n in e||(e={}))x$.call(e,n)&&xb(t,n,e[n]);if(Eb)for(var n of Eb(e))_$.call(e,n)&&xb(t,n,e[n]);return t},S$=(t,e)=>v$(t,E$(e));const _b="did:pkh:",B$={eip155:"Ethereum",solana:"Solana",bip122:"Bitcoin"},$$=t=>t?B$[t]||t:"",xc=t=>t?.split(":"),A$=t=>{const e=t&&xc(t);if(e)return t.includes(_b)?e[3]:e[1]},O$=t=>{const e=t&&xc(t);if(e)return t.includes(_b)?e[2]:e[0]},Ml=t=>{const e=t&&xc(t);if(e)return e[2]+":"+e[3]},_c=t=>{const e=t&&xc(t);if(e)return e.pop()};async function Ib(t){const{cacao:e,projectId:n}=t,{s:r,p:i}=e,s=Sb(i,i.iss),o=_c(i.iss);return await u$(o,s,r,Ml(i.iss),n)}const Sb=(t,e)=>{const n=O$(e);if(!n)throw new Error("Invalid issuer: "+e);const r=`${t.domain} wants you to sign in with your ${$$(n)} account:`,i=_c(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: ${A$(e)}`,f=`Nonce: ${t.nonce}`,u=`Issued At: ${t.iat}`,h=t.exp?`Expiration Time: ${t.exp}`:void 0,l=t.nbf?`Not Before: ${t.nbf}`:void 0,d=t.requestId?`Request ID: ${t.requestId}`:void 0,p=t.resources?`Resources:${t.resources.map(v=>`
20
+ - ${v}`).join("")}`:void 0,b=Ic(t.resources);if(b){const v=Ao(b);s=L$(s,v)}return[r,i,"",s,"",o,a,c,f,u,h,l,d,p].filter(v=>v!=null).join(`
21
+ `)};function D$(t){return Buffer.from(JSON.stringify(t)).toString("base64")}function P$(t){return JSON.parse(Buffer.from(t,"base64").toString("utf-8"))}function Ci(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 R$(t,e,n,r={}){return n?.sort((i,s)=>i.localeCompare(s)),{att:{[t]:T$(e,n,r)}}}function T$(t,e,n={}){e=e?.sort((i,s)=>i.localeCompare(s));const r=e.map(i=>({[`${t}/${i}`]:[n]}));return Object.assign({},...r)}function Bb(t){return Ci(t),`urn:recap:${D$(t).replace(/=/g,"")}`}function Ao(t){const e=P$(t.replace("urn:recap:",""));return Ci(e),e}function N$(t,e,n){const r=R$(t,e,n);return Bb(r)}function U$(t){return t&&t.includes("urn:recap:")}function C$(t,e){const n=Ao(t),r=Ao(e),i=F$(n,r);return Bb(i)}function F$(t,e){Ci(t),Ci(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]=S$(I$({},r.att[i]),{[a]:((c=t.att[i])==null?void 0:c[a])||((f=e.att[i])==null?void 0:f[a])})})}),r}function L$(t="",e){Ci(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,l)=>h.action.localeCompare(l.action));const f={};c.forEach(h=>{f[h.ability]||(f[h.ability]=[]),f[h.ability].push(h.action)});const u=Object.keys(f).map(h=>(i++,`(${i}) '${h}': '${f[h].join("', '")}' for '${a}'.`));r.push(u.join(", ").replace(".,","."))});const s=r.join(" "),o=`${n}${s}`;return`${t?t+" ":""}${o}`}function $b(t){var e;const n=Ao(t);Ci(n);const r=(e=n.att)==null?void 0:e.eip155;return r?Object.keys(r).map(i=>i.split("/")[1]):[]}function Ab(t){const e=Ao(t);Ci(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 Ic(t){if(!t)return;const e=t?.[t.length-1];return U$(e)?e:void 0}/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */function Ob(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"}function jl(t){if(typeof t!="boolean")throw new Error(`boolean expected, not ${t}`)}function zl(t){if(!Number.isSafeInteger(t)||t<0)throw new Error("positive integer expected, got "+t)}function Rt(t,...e){if(!Ob(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 Db(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 k$(t,e){Rt(t);const n=e.outputLen;if(t.length<n)throw new Error("digestInto() expects output buffer of length at least "+n)}function ci(t){return new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4))}function xs(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function q$(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}const M$=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function j$(t){if(typeof t!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(t))}function Hl(t){if(typeof t=="string")t=j$(t);else if(Ob(t))t=Vl(t);else throw new Error("Uint8Array expected, got "+typeof t);return t}function z$(t,e){if(e==null||typeof e!="object")throw new Error("options must be defined");return Object.assign(t,e)}function H$(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 V$=(t,e)=>{function n(r,...i){if(Rt(r),!M$)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?Rt(f):Rt(f,t.nonceLength)}const s=t.tagLength;s&&i[1]!==void 0&&Rt(i[1]);const o=e(r,...i),a=(f,u)=>{if(u!==void 0){if(f!==2)throw new Error("cipher output not supported");Rt(u)}};let c=!1;return{encrypt(f,u){if(c)throw new Error("cannot encrypt() twice with same key + nonce");return c=!0,Rt(f),a(o.encrypt.length,u),o.encrypt(f,u)},decrypt(f,u){if(Rt(f),s&&f.length<s)throw new Error("invalid ciphertext length: smaller than tagLength="+s);return a(o.decrypt.length,u),o.decrypt(f,u)}}}return Object.assign(n,t),n};function Pb(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&&!G$(e))throw new Error("invalid output, must be aligned");return e}function Rb(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 K$(t,e,n){jl(n);const r=new Uint8Array(16),i=q$(r);return Rb(i,0,BigInt(e),n),Rb(i,8,BigInt(t),n),r}function G$(t){return t.byteOffset%4===0}function Vl(t){return Uint8Array.from(t)}const Tb=t=>Uint8Array.from(t.split("").map(e=>e.charCodeAt(0))),Z$=Tb("expand 16-byte k"),W$=Tb("expand 32-byte k"),Y$=ci(Z$),X$=ci(W$);function le(t,e){return t<<e|t>>>32-e}function Kl(t){return t.byteOffset%4===0}const Sc=64,J$=16,Nb=2**32-1,Ub=new Uint32Array;function Q$(t,e,n,r,i,s,o,a){const c=i.length,f=new Uint8Array(Sc),u=ci(f),h=Kl(i)&&Kl(s),l=h?ci(i):Ub,d=h?ci(s):Ub;for(let p=0;p<c;o++){if(t(e,n,r,u,o,a),o>=Nb)throw new Error("arx: counter overflow");const b=Math.min(Sc,c-p);if(h&&b===Sc){const v=p/4;if(p%4!==0)throw new Error("arx: invalid block position");for(let O=0,P;O<J$;O++)P=v+O,d[P]=l[P]^u[O];p+=Sc;continue}for(let v=0,O;v<b;v++)O=p+v,s[O]=i[O]^f[v];p+=b}}function eA(t,e){const{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:s,rounds:o}=z$({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},e);if(typeof t!="function")throw new Error("core must be a function");return zl(i),zl(o),jl(s),jl(n),(a,c,f,u,h=0)=>{Rt(a),Rt(c),Rt(f);const l=f.length;if(u===void 0&&(u=new Uint8Array(l)),Rt(u),zl(h),h<0||h>=Nb)throw new Error("arx: counter overflow");if(u.length<l)throw new Error(`arx: output (${u.length}) is shorter than data (${l})`);const d=[];let p=a.length,b,v;if(p===32)d.push(b=Vl(a)),v=X$;else if(p===16&&n)b=new Uint8Array(32),b.set(a),b.set(a,16),v=Y$,d.push(b);else throw new Error(`arx: invalid 32-byte key, got length=${p}`);Kl(c)||d.push(c=Vl(c));const O=ci(b);if(r){if(c.length!==24)throw new Error("arx: extended nonce must be 24 bytes");r(v,O,ci(c.subarray(0,16)),O),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 S=new Uint8Array(12);S.set(c,s?0:12-c.length),c=S,d.push(c)}const x=ci(c);return Q$(t,v,O,x,f,u,h,o),xs(...d),u}}const Ze=(t,e)=>t[e++]&255|(t[e++]&255)<<8;class tA{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=Hl(e),Rt(e,32);const n=Ze(e,0),r=Ze(e,2),i=Ze(e,4),s=Ze(e,6),o=Ze(e,8),a=Ze(e,10),c=Ze(e,12),f=Ze(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 u=0;u<8;u++)this.pad[u]=Ze(e,16+2*u)}process(e,n,r=!1){const i=r?0:2048,{h:s,r:o}=this,a=o[0],c=o[1],f=o[2],u=o[3],h=o[4],l=o[5],d=o[6],p=o[7],b=o[8],v=o[9],O=Ze(e,n+0),P=Ze(e,n+2),x=Ze(e,n+4),S=Ze(e,n+6),R=Ze(e,n+8),U=Ze(e,n+10),L=Ze(e,n+12),C=Ze(e,n+14);let A=s[0]+(O&8191),j=s[1]+((O>>>13|P<<3)&8191),q=s[2]+((P>>>10|x<<6)&8191),E=s[3]+((x>>>7|S<<9)&8191),y=s[4]+((S>>>4|R<<12)&8191),w=s[5]+(R>>>1&8191),g=s[6]+((R>>>14|U<<2)&8191),m=s[7]+((U>>>11|L<<5)&8191),_=s[8]+((L>>>8|C<<8)&8191),B=s[9]+(C>>>5|i),I=0,$=I+A*a+j*(5*v)+q*(5*b)+E*(5*p)+y*(5*d);I=$>>>13,$&=8191,$+=w*(5*l)+g*(5*h)+m*(5*u)+_*(5*f)+B*(5*c),I+=$>>>13,$&=8191;let D=I+A*c+j*a+q*(5*v)+E*(5*b)+y*(5*p);I=D>>>13,D&=8191,D+=w*(5*d)+g*(5*l)+m*(5*h)+_*(5*u)+B*(5*f),I+=D>>>13,D&=8191;let T=I+A*f+j*c+q*a+E*(5*v)+y*(5*b);I=T>>>13,T&=8191,T+=w*(5*p)+g*(5*d)+m*(5*l)+_*(5*h)+B*(5*u),I+=T>>>13,T&=8191;let F=I+A*u+j*f+q*c+E*a+y*(5*v);I=F>>>13,F&=8191,F+=w*(5*b)+g*(5*p)+m*(5*d)+_*(5*l)+B*(5*h),I+=F>>>13,F&=8191;let k=I+A*h+j*u+q*f+E*c+y*a;I=k>>>13,k&=8191,k+=w*(5*v)+g*(5*b)+m*(5*p)+_*(5*d)+B*(5*l),I+=k>>>13,k&=8191;let N=I+A*l+j*h+q*u+E*f+y*c;I=N>>>13,N&=8191,N+=w*a+g*(5*v)+m*(5*b)+_*(5*p)+B*(5*d),I+=N>>>13,N&=8191;let M=I+A*d+j*l+q*h+E*u+y*f;I=M>>>13,M&=8191,M+=w*c+g*a+m*(5*v)+_*(5*b)+B*(5*p),I+=M>>>13,M&=8191;let z=I+A*p+j*d+q*l+E*h+y*u;I=z>>>13,z&=8191,z+=w*f+g*c+m*a+_*(5*v)+B*(5*b),I+=z>>>13,z&=8191;let K=I+A*b+j*p+q*d+E*l+y*h;I=K>>>13,K&=8191,K+=w*u+g*f+m*c+_*a+B*(5*v),I+=K>>>13,K&=8191;let H=I+A*v+j*b+q*p+E*d+y*l;I=H>>>13,H&=8191,H+=w*h+g*u+m*f+_*c+B*a,I+=H>>>13,H&=8191,I=(I<<2)+I|0,I=I+$|0,$=I&8191,I=I>>>13,D+=I,s[0]=$,s[1]=D,s[2]=T,s[3]=F,s[4]=k,s[5]=N,s[6]=M,s[7]=z,s[8]=K,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;xs(r)}update(e){Db(this),e=Hl(e),Rt(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(){xs(this.h,this.r,this.buffer,this.pad)}digestInto(e){Db(this),k$(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 nA(t){const e=(r,i)=>t(i).update(Hl(r)).digest(),n=t(new Uint8Array(32));return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=r=>t(r),e}const rA=nA(t=>new tA(t));function iA(t,e,n,r,i,s=20){let o=t[0],a=t[1],c=t[2],f=t[3],u=e[0],h=e[1],l=e[2],d=e[3],p=e[4],b=e[5],v=e[6],O=e[7],P=i,x=n[0],S=n[1],R=n[2],U=o,L=a,C=c,A=f,j=u,q=h,E=l,y=d,w=p,g=b,m=v,_=O,B=P,I=x,$=S,D=R;for(let F=0;F<s;F+=2)U=U+j|0,B=le(B^U,16),w=w+B|0,j=le(j^w,12),U=U+j|0,B=le(B^U,8),w=w+B|0,j=le(j^w,7),L=L+q|0,I=le(I^L,16),g=g+I|0,q=le(q^g,12),L=L+q|0,I=le(I^L,8),g=g+I|0,q=le(q^g,7),C=C+E|0,$=le($^C,16),m=m+$|0,E=le(E^m,12),C=C+E|0,$=le($^C,8),m=m+$|0,E=le(E^m,7),A=A+y|0,D=le(D^A,16),_=_+D|0,y=le(y^_,12),A=A+y|0,D=le(D^A,8),_=_+D|0,y=le(y^_,7),U=U+q|0,D=le(D^U,16),m=m+D|0,q=le(q^m,12),U=U+q|0,D=le(D^U,8),m=m+D|0,q=le(q^m,7),L=L+E|0,B=le(B^L,16),_=_+B|0,E=le(E^_,12),L=L+E|0,B=le(B^L,8),_=_+B|0,E=le(E^_,7),C=C+y|0,I=le(I^C,16),w=w+I|0,y=le(y^w,12),C=C+y|0,I=le(I^C,8),w=w+I|0,y=le(y^w,7),A=A+j|0,$=le($^A,16),g=g+$|0,j=le(j^g,12),A=A+j|0,$=le($^A,8),g=g+$|0,j=le(j^g,7);let T=0;r[T++]=o+U|0,r[T++]=a+L|0,r[T++]=c+C|0,r[T++]=f+A|0,r[T++]=u+j|0,r[T++]=h+q|0,r[T++]=l+E|0,r[T++]=d+y|0,r[T++]=p+w|0,r[T++]=b+g|0,r[T++]=v+m|0,r[T++]=O+_|0,r[T++]=P+B|0,r[T++]=x+I|0,r[T++]=S+$|0,r[T++]=R+D|0}const sA=eA(iA,{counterRight:!1,counterLength:4,allowShortKeys:!1}),oA=new Uint8Array(16),Cb=(t,e)=>{t.update(e);const n=e.length%16;n&&t.update(oA.subarray(n))},aA=new Uint8Array(32);function Fb(t,e,n,r,i){const s=t(e,n,aA),o=rA.create(s);i&&Cb(o,i),Cb(o,r);const a=K$(r.length,i?i.length:0,!0);o.update(a);const c=o.digest();return xs(s,a),c}const cA=t=>(e,n,r)=>({encrypt(i,s){const o=i.length;s=Pb(o+16,s,!1),s.set(i);const a=s.subarray(0,-16);t(e,n,a,a,1);const c=Fb(t,e,n,a,r);return s.set(c,o),xs(c),s},decrypt(i,s){s=Pb(i.length-16,s,!1);const o=i.subarray(0,-16),a=i.subarray(-16),c=Fb(t,e,n,o,r);if(!H$(a,c))throw new Error("invalid tag");return s.set(i.subarray(0,-16)),t(e,n,s,s,1),xs(c),s}}),Lb=V$({blockSize:64,nonceLength:12,tagLength:16},cA(sA));class kb extends vc{constructor(e,n){super(),this.finished=!1,this.destroyed=!1,wc(e);const r=gn(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),Xt(s)}update(e){return Qr(this),this.iHash.update(e),this}digestInto(e){Qr(this),pn(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 Bc=(t,e,n)=>new kb(t,e).update(n).digest();Bc.create=(t,e)=>new kb(t,e);function fA(t,e,n){return wc(t),n===void 0&&(n=new Uint8Array(t.outputLen)),Bc(t,gn(n),gn(e))}const Gl=Uint8Array.from([0]),qb=Uint8Array.of();function uA(t,e,n,r=32){wc(t),tr(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=qb);const o=new Uint8Array(s*i),a=Bc.create(t,e),c=a._cloneInto(),f=new Uint8Array(a.outputLen);for(let u=0;u<s;u++)Gl[0]=u+1,c.update(u===0?qb:f).update(n).update(Gl).digestInto(f),o.set(f,i*u),a._cloneInto(c);return a.destroy(),c.destroy(),Xt(f,Gl),o.slice(0,r)}const lA=(t,e,n,r,i)=>uA(t,fA(t,e,n),r,i),$c=Ec,Zl=BigInt(0),Wl=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 Fi(t,e,n=""){const r=bc(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 Mb(t){if(typeof t!="string")throw new Error("hex string expected, got "+typeof t);return t===""?Zl:BigInt("0x"+t)}function Dc(t){return Mb(Es(t))}function Pc(t){return pn(t),Mb(Es(Uint8Array.from(t).reverse()))}function Yl(t,e){return mc(t.toString(16).padStart(e*2,"0"))}function Xl(t,e){return Yl(t,e).reverse()}function ht(t,e,n){let r;if(typeof e=="string")try{r=mc(e)}catch(s){throw new Error(t+" must be hex string or Uint8Array, cause: "+s)}else if(bc(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 Jl=t=>typeof t=="bigint"&&Zl<=t;function hA(t,e,n){return Jl(t)&&Jl(e)&&Jl(n)&&e<=t&&t<n}function Ql(t,e,n,r){if(!hA(e,n,r))throw new Error("expected valid "+t+": "+n+" <= n < "+r+", got "+e)}function jb(t){let e;for(e=0;t>Zl;t>>=Wl,e+=1);return e}const Oo=t=>(Wl<<BigInt(t))-Wl;function dA(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=l=>new Uint8Array(l),i=l=>Uint8Array.of(l);let s=r(t),o=r(t),a=0;const c=()=>{s.fill(1),o.fill(0),a=0},f=(...l)=>n(o,s,...l),u=(l=r(0))=>{o=f(i(0),l),s=f(),l.length!==0&&(o=f(i(1),l),s=f())},h=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let l=0;const d=[];for(;l<e;){s=f();const p=s.slice();d.push(p),l+=s.length}return ti(...d)};return(l,d)=>{c(),u(l);let p;for(;!(p=d(h()));)u();return c(),p}}function Rc(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 zb(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 Tt=BigInt(0),vt=BigInt(1),Li=BigInt(2),Hb=BigInt(3),Vb=BigInt(4),Kb=BigInt(5),pA=BigInt(7),Gb=BigInt(8),gA=BigInt(9),Zb=BigInt(16);function zt(t,e){const n=t%e;return n>=Tt?n:e+n}function yn(t,e,n){let r=t;for(;e-- >Tt;)r*=r,r%=n;return r}function Wb(t,e){if(t===Tt)throw new Error("invert: expected non-zero number");if(e<=Tt)throw new Error("invert: expected positive modulus, got "+e);let n=zt(t,e),r=e,i=Tt,s=vt;for(;n!==Tt;){const o=r/n,a=r%n,c=i-s*o;r=n,n=a,i=s,s=c}if(r!==vt)throw new Error("invert: does not exist");return zt(i,e)}function eh(t,e,n){if(!t.eql(t.sqr(e),n))throw new Error("Cannot find square root")}function Yb(t,e){const n=(t.ORDER+vt)/Vb,r=t.pow(e,n);return eh(t,r,e),r}function yA(t,e){const n=(t.ORDER-Kb)/Gb,r=t.mul(e,Li),i=t.pow(r,n),s=t.mul(e,i),o=t.mul(t.mul(s,Li),i),a=t.mul(s,t.sub(o,t.ONE));return eh(t,a,e),a}function bA(t){const e=fi(t),n=Xb(t),r=n(e,e.neg(e.ONE)),i=n(e,r),s=n(e,e.neg(r)),o=(t+pA)/Zb;return(a,c)=>{let f=a.pow(c,o),u=a.mul(f,r);const h=a.mul(f,i),l=a.mul(f,s),d=a.eql(a.sqr(u),c),p=a.eql(a.sqr(h),c);f=a.cmov(f,u,d),u=a.cmov(l,h,p);const b=a.eql(a.sqr(u),c),v=a.cmov(f,u,b);return eh(a,v,c),v}}function Xb(t){if(t<Hb)throw new Error("sqrt is not defined for small field");let e=t-vt,n=0;for(;e%Li===Tt;)e/=Li,n++;let r=Li;const i=fi(t);for(;Qb(i,r)===1;)if(r++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(n===1)return Yb;let s=i.pow(r,e);const o=(e+vt)/Li;return function(a,c){if(a.is0(c))return c;if(Qb(a,c)!==1)throw new Error("Cannot find square root");let f=n,u=a.mul(a.ONE,s),h=a.pow(c,e),l=a.pow(c,o);for(;!a.eql(h,a.ONE);){if(a.is0(h))return a.ZERO;let d=1,p=a.sqr(h);for(;!a.eql(p,a.ONE);)if(d++,p=a.sqr(p),d===f)throw new Error("Cannot find square root");const b=vt<<BigInt(f-d-1),v=a.pow(u,b);f=d,u=a.sqr(v),h=a.mul(h,u),l=a.mul(l,v)}return l}}function wA(t){return t%Vb===Hb?Yb:t%Gb===Kb?yA:t%Zb===gA?bA(t):Xb(t)}const mA=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function vA(t){const e={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},n=mA.reduce((r,i)=>(r[i]="function",r),e);return Rc(t,n),t}function EA(t,e,n){if(n<Tt)throw new Error("invalid exponent, negatives unsupported");if(n===Tt)return t.ONE;if(n===vt)return e;let r=t.ONE,i=e;for(;n>Tt;)n&vt&&(r=t.mul(r,i)),i=t.sqr(i),n>>=vt;return r}function Jb(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 Qb(t,e){const n=(t.ORDER-vt)/Li,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 ew(t,e){e!==void 0&&tr(e);const n=e!==void 0?e:t.toString(2).length,r=Math.ceil(n/8);return{nBitLength:n,nByteLength:r}}function fi(t,e,n=!1,r={}){if(t<=Tt)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 l=e;l.BITS&&(i=l.BITS),l.sqrt&&(s=l.sqrt),typeof l.isLE=="boolean"&&(n=l.isLE),typeof l.modFromBytes=="boolean"&&(o=l.modFromBytes),a=l.allowedLengths}else typeof e=="number"&&(i=e),r.sqrt&&(s=r.sqrt);const{nBitLength:c,nByteLength:f}=ew(t,i);if(f>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let u;const h=Object.freeze({ORDER:t,isLE:n,BITS:c,BYTES:f,MASK:Oo(c),ZERO:Tt,ONE:vt,allowedLengths:a,create:l=>zt(l,t),isValid:l=>{if(typeof l!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof l);return Tt<=l&&l<t},is0:l=>l===Tt,isValidNot0:l=>!h.is0(l)&&h.isValid(l),isOdd:l=>(l&vt)===vt,neg:l=>zt(-l,t),eql:(l,d)=>l===d,sqr:l=>zt(l*l,t),add:(l,d)=>zt(l+d,t),sub:(l,d)=>zt(l-d,t),mul:(l,d)=>zt(l*d,t),pow:(l,d)=>EA(h,l,d),div:(l,d)=>zt(l*Wb(d,t),t),sqrN:l=>l*l,addN:(l,d)=>l+d,subN:(l,d)=>l-d,mulN:(l,d)=>l*d,inv:l=>Wb(l,t),sqrt:s||(l=>(u||(u=wA(t)),u(h,l))),toBytes:l=>n?Xl(l,f):Yl(l,f),fromBytes:(l,d=!0)=>{if(a){if(!a.includes(l.length)||l.length>f)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+l.length);const b=new Uint8Array(f);b.set(l,n?0:b.length-l.length),l=b}if(l.length!==f)throw new Error("Field.fromBytes: expected "+f+" bytes, got "+l.length);let p=n?Pc(l):Dc(l);if(o&&(p=zt(p,t)),!d&&!h.isValid(p))throw new Error("invalid field element: outside of range 0..ORDER");return p},invertBatch:l=>Jb(h,l),cmov:(l,d,p)=>p?d:l});return Object.freeze(h)}function tw(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 nw(t){const e=tw(t);return e+Math.ceil(e/2)}function xA(t,e,n=!1){const r=t.length,i=tw(e),s=nw(e);if(r<16||r<s||r>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+r);const o=n?Pc(t):Dc(t),a=zt(o,e-vt)+vt;return n?Xl(a,i):Yl(a,i)}const _s=BigInt(0),ki=BigInt(1);function Tc(t,e){const n=e.negate();return t?n:e}function th(t,e){const n=Jb(t.Fp,e.map(r=>r.Z));return e.map((r,i)=>t.fromAffine(r.toAffine(n[i])))}function rw(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){rw(t,e);const n=Math.ceil(e/t)+1,r=2**(t-1),i=2**t,s=Oo(t),o=BigInt(t);return{windows:n,windowSize:r,mask:s,maxNumber:i,shiftBy:o}}function iw(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+=ki);const f=e*r,u=f+Math.abs(a)-1,h=a===0,l=a<0,d=e%2!==0;return{nextN:c,offset:u,isZero:h,isNeg:l,isNegF:d,offsetF:f}}function _A(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 IA(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,sw=new WeakMap;function ih(t){return sw.get(t)||1}function ow(t){if(t!==_s)throw new Error("invalid wNAF")}class SA{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>_s;)n&ki&&(r=r.add(i)),i=i.double(),n>>=ki;return r}precomputeWindow(e,n){const{windows:r,windowSize:i}=nh(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=nh(e,this.bits);for(let a=0;a<o.windows;a++){const{nextN:c,offset:f,isZero:u,isNeg:h,isNegF:l,offsetF:d}=iw(r,a,o);r=c,u?s=s.add(Tc(l,n[d])):i=i.add(Tc(h,n[f]))}return ow(r),{p:i,f:s}}wNAFUnsafe(e,n,r,i=this.ZERO){const s=nh(e,this.bits);for(let o=0;o<s.windows&&r!==_s;o++){const{nextN:a,offset:c,isZero:f,isNeg:u}=iw(r,o,s);if(r=a,!f){const h=n[c];i=i.add(u?h.negate():h)}}return ow(r),i}getPrecomputes(e,n,r){let i=rh.get(n);return i||(i=this.precomputeWindow(n,e),e!==1&&(typeof r=="function"&&(i=r(i)),rh.set(n,i))),i}cached(e,n,r){const i=ih(e);return this.wNAF(i,this.getPrecomputes(i,e,r),n)}unsafe(e,n,r,i){const s=ih(e);return s===1?this._unsafeLadder(e,n,i):this.wNAFUnsafe(s,this.getPrecomputes(s,e,r),n,i)}createCache(e,n){rw(n,this.bits),sw.set(e,n),rh.delete(e)}hasCache(e){return ih(e)!==1}}function BA(t,e,n,r){let i=e,s=t.ZERO,o=t.ZERO;for(;n>_s||r>_s;)n&ki&&(s=s.add(i)),r&ki&&(o=o.add(i)),i=i.double(),n>>=ki,r>>=ki;return{p1:s,p2:o}}function $A(t,e,n,r){_A(n,t),IA(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=jb(BigInt(i));let c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);const f=Oo(c),u=new Array(Number(f)+1).fill(o),h=Math.floor((e.BITS-1)/c)*c;let l=o;for(let d=h;d>=0;d-=c){u.fill(o);for(let b=0;b<s;b++){const v=r[b],O=Number(v>>BigInt(d)&f);u[O]=u[O].add(n[b])}let p=o;for(let b=u.length-1,v=o;b>0;b--)v=v.add(u[b]),p=p.add(v);if(l=l.add(p),d!==0)for(let b=0;b<c;b++)l=l.double()}return l}function aw(t,e,n){if(e){if(e.ORDER!==t)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return vA(e),e}else return fi(t,{isLE:n})}function AA(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>_s))throw new Error(`CURVE.${a} must be positive bigint`)}const i=aw(e.p,n.Fp,r),s=aw(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),fb("HashToScalar-");const Do=BigInt(0),Is=BigInt(1),Nc=BigInt(2);function OA(t){return Rc(t,{adjustScalarBytes:"function",powPminus2:"function"}),Object.freeze({...t})}function DA(t){const e=OA(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||Ui,f=a?255:448,u=a?32:56,h=BigInt(a?9:5),l=BigInt(a?121665:39081),d=a?Nc**BigInt(254):Nc**BigInt(447),p=a?BigInt(8)*Nc**BigInt(251)-Is:BigInt(4)*Nc**BigInt(445)-Is,b=d+p+Is,v=E=>zt(E,n),O=P(h);function P(E){return Xl(v(E),u)}function x(E){const y=ht("u coordinate",E,u);return a&&(y[31]&=127),v(Pc(y))}function S(E){return Pc(i(ht("scalar",E,u)))}function R(E,y){const w=C(x(y),S(E));if(w===Do)throw new Error("invalid private or public key received");return P(w)}function U(E){return R(E,O)}function L(E,y,w){const g=v(E*(y-w));return y=v(y-g),w=v(w+g),{x_2:y,x_3:w}}function C(E,y){Ql("u",E,Do,n),Ql("scalar",y,d,b);const w=y,g=E;let m=Is,_=Do,B=E,I=Is,$=Do;for(let T=BigInt(f-1);T>=Do;T--){const F=w>>T&Is;$^=F,{x_2:m,x_3:B}=L($,m,B),{x_2:_,x_3:I}=L($,_,I),$=F;const k=m+_,N=v(k*k),M=m-_,z=v(M*M),K=N-z,H=B+I,G=B-I,ee=v(G*k),te=v(H*M),re=ee+te,ce=ee-te;B=v(re*re),I=v(g*v(ce*ce)),m=v(N*z),_=v(K*(N+v(l*K)))}({x_2:m,x_3:B}=L($,m,B)),{x_2:_,x_3:I}=L($,_,I);const D=s(_);return v(m*D)}const A={secretKey:u,publicKey:u,seed:u},j=(E=c(u))=>(pn(E,A.seed),E);function q(E){const y=j(E);return{secretKey:y,publicKey:U(y)}}return{keygen:q,getSharedSecret:(E,y)=>R(E,y),getPublicKey:E=>U(E),scalarMult:R,scalarMultBase:U,utils:{randomSecretKey:j,randomPrivateKey:j},GuBytes:O.slice(),lengths:A}}const PA=BigInt(1),cw=BigInt(2),RA=BigInt(3),TA=BigInt(5),NA=BigInt(8),fw=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),UA={p:fw,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:NA,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function CA(t){const e=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),s=fw,o=t*t%s*t%s,a=yn(o,cw,s)*o%s,c=yn(a,PA,s)*t%s,f=yn(c,TA,s)*c%s,u=yn(f,e,s)*f%s,h=yn(u,n,s)*u%s,l=yn(h,r,s)*h%s,d=yn(l,i,s)*l%s,p=yn(d,i,s)*l%s,b=yn(p,e,s)*f%s;return{pow_p_5_8:yn(b,cw,s)*t%s,b2:o}}function FA(t){return t[0]&=248,t[31]&=127,t[31]|=64,t}const LA=fi(UA.p,{isLE:!0}),sh=(()=>{const t=LA.ORDER;return DA({P:t,type:"x25519",powPminus2:e=>{const{pow_p_5_8:n,b2:r}=CA(e);return zt(yn(n,RA,t)*r,t)},adjustScalarBytes:FA})})(),uw=(t,e)=>(t+(t>=0?e:-e)/lw)/e;function kA(t,e,n){const[[r,i],[s,o]]=e,a=uw(o*t,n),c=uw(-i*t,n);let f=t-a*r-c*s,u=-a*i-c*o;const h=f<sr,l=u<sr;h&&(f=-f),l&&(u=-u);const d=Oo(Math.ceil(jb(n)/2))+Ss;if(f<sr||f>=d||u<sr||u>=d)throw new Error("splitScalar (endomorphism): failed, k="+t);return{k1neg:h,k1:f,k2neg:l,k2:u}}function oh(t){if(!["compact","recovered","der"].includes(t))throw new Error('Signature format must be "compact", "recovered", or "der"');return t}function ah(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&&oh(n.format),n}class qA extends Error{constructor(e=""){super(e)}}const ir={Err:qA,_tlv:{encode:(t,e)=>{const{Err:n}=ir;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}=ir;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 u of f)o=o<<8|u;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}=ir;if(t<sr)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}=ir;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}=ir,i=ht("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:u}=r.decode(2,c);if(u.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}=ir,r=e.encode(2,n.encode(t.r)),i=e.encode(2,n.encode(t.s)),s=r+i;return e.encode(48,s)}},sr=BigInt(0),Ss=BigInt(1),lw=BigInt(2),Uc=BigInt(3),MA=BigInt(4);function Bs(t,e){const{BYTES:n}=t;let r;if(typeof e=="bigint")r=e;else{let i=ht("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 jA(t,e={}){const n=AA("weierstrass",t,e),{Fp:r,Fn:i}=n;let s=n.CURVE;const{h:o,n:a}=s;Rc(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=dw(r,i);function u(){if(!r.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function h(E,y,w){const{x:g,y:m}=y.toAffine(),_=r.toBytes(g);if(Ac(w,"isCompressed"),w){u();const B=!r.isOdd(m);return ti(hw(B),_)}else return ti(Uint8Array.of(4),_,r.toBytes(m))}function l(E){Fi(E,void 0,"Point");const{publicKey:y,publicKeyUncompressed:w}=f,g=E.length,m=E[0],_=E.subarray(1);if(g===y&&(m===2||m===3)){const B=r.fromBytes(_);if(!r.isValid(B))throw new Error("bad point: is not on curve, wrong x");const I=b(B);let $;try{$=r.sqrt(I)}catch(T){const F=T instanceof Error?": "+T.message:"";throw new Error("bad point: is not on curve, sqrt error"+F)}u();const D=r.isOdd($);return(m&1)===1!==D&&($=r.neg($)),{x:B,y:$}}else if(g===w&&m===4){const B=r.BYTES,I=r.fromBytes(_.subarray(0,B)),$=r.fromBytes(_.subarray(B,B*2));if(!v(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=${y} or uncompressed=${w}`)}const d=e.toBytes||h,p=e.fromBytes||l;function b(E){const y=r.sqr(E),w=r.mul(y,E);return r.add(r.add(w,r.mul(E,s.a)),s.b)}function v(E,y){const w=r.sqr(y),g=b(E);return r.eql(w,g)}if(!v(s.Gx,s.Gy))throw new Error("bad curve params: generator point");const O=r.mul(r.pow(s.a,Uc),MA),P=r.mul(r.sqr(s.b),BigInt(27));if(r.is0(r.add(O,P)))throw new Error("bad curve params: a or b");function x(E,y,w=!1){if(!r.isValid(y)||w&&r.is0(y))throw new Error(`bad point coordinate ${E}`);return y}function S(E){if(!(E instanceof A))throw new Error("ProjectivePoint expected")}function R(E){if(!c||!c.basises)throw new Error("no endo");return kA(E,c.basises,i.ORDER)}const U=zb((E,y)=>{const{X:w,Y:g,Z:m}=E;if(r.eql(m,r.ONE))return{x:w,y:g};const _=E.is0();y==null&&(y=_?r.ONE:r.inv(m));const B=r.mul(w,y),I=r.mul(g,y),$=r.mul(m,y);if(_)return{x:r.ZERO,y:r.ZERO};if(!r.eql($,r.ONE))throw new Error("invZ was invalid");return{x:B,y:I}}),L=zb(E=>{if(E.is0()){if(e.allowInfinityPoint&&!r.is0(E.Y))return;throw new Error("bad point: ZERO")}const{x:y,y:w}=E.toAffine();if(!r.isValid(y)||!r.isValid(w))throw new Error("bad point: x or y not field elements");if(!v(y,w))throw new Error("bad point: equation left != right");if(!E.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function C(E,y,w,g,m){return w=new A(r.mul(w.X,E),w.Y,w.Z),y=Tc(g,y),w=Tc(m,w),y.add(w)}class A{constructor(y,w,g){this.X=x("x",y),this.Y=x("y",w,!0),this.Z=x("z",g),Object.freeze(this)}static CURVE(){return s}static fromAffine(y){const{x:w,y:g}=y||{};if(!y||!r.isValid(w)||!r.isValid(g))throw new Error("invalid affine point");if(y instanceof A)throw new Error("projective point not allowed");return r.is0(w)&&r.is0(g)?A.ZERO:new A(w,g,r.ONE)}static fromBytes(y){const w=A.fromAffine(p(Fi(y,void 0,"point")));return w.assertValidity(),w}static fromHex(y){return A.fromBytes(ht("pointHex",y))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(y=8,w=!0){return q.createCache(this,y),w||this.multiply(Uc),this}assertValidity(){L(this)}hasEvenY(){const{y}=this.toAffine();if(!r.isOdd)throw new Error("Field doesn't support isOdd");return!r.isOdd(y)}equals(y){S(y);const{X:w,Y:g,Z:m}=this,{X:_,Y:B,Z:I}=y,$=r.eql(r.mul(w,I),r.mul(_,m)),D=r.eql(r.mul(g,I),r.mul(B,m));return $&&D}negate(){return new A(this.X,r.neg(this.Y),this.Z)}double(){const{a:y,b:w}=s,g=r.mul(w,Uc),{X:m,Y:_,Z:B}=this;let I=r.ZERO,$=r.ZERO,D=r.ZERO,T=r.mul(m,m),F=r.mul(_,_),k=r.mul(B,B),N=r.mul(m,_);return N=r.add(N,N),D=r.mul(m,B),D=r.add(D,D),I=r.mul(y,D),$=r.mul(g,k),$=r.add(I,$),I=r.sub(F,$),$=r.add(F,$),$=r.mul(I,$),I=r.mul(N,I),D=r.mul(g,D),k=r.mul(y,k),N=r.sub(T,k),N=r.mul(y,N),N=r.add(N,D),D=r.add(T,T),T=r.add(D,T),T=r.add(T,k),T=r.mul(T,N),$=r.add($,T),k=r.mul(_,B),k=r.add(k,k),T=r.mul(k,N),I=r.sub(I,T),D=r.mul(k,F),D=r.add(D,D),D=r.add(D,D),new A(I,$,D)}add(y){S(y);const{X:w,Y:g,Z:m}=this,{X:_,Y:B,Z:I}=y;let $=r.ZERO,D=r.ZERO,T=r.ZERO;const F=s.a,k=r.mul(s.b,Uc);let N=r.mul(w,_),M=r.mul(g,B),z=r.mul(m,I),K=r.add(w,g),H=r.add(_,B);K=r.mul(K,H),H=r.add(N,M),K=r.sub(K,H),H=r.add(w,m);let G=r.add(_,I);return H=r.mul(H,G),G=r.add(N,z),H=r.sub(H,G),G=r.add(g,m),$=r.add(B,I),G=r.mul(G,$),$=r.add(M,z),G=r.sub(G,$),T=r.mul(F,H),$=r.mul(k,z),T=r.add($,T),$=r.sub(M,T),T=r.add(M,T),D=r.mul($,T),M=r.add(N,N),M=r.add(M,N),z=r.mul(F,z),H=r.mul(k,H),M=r.add(M,z),z=r.sub(N,z),z=r.mul(F,z),H=r.add(H,z),N=r.mul(M,H),D=r.add(D,N),N=r.mul(G,H),$=r.mul(K,$),$=r.sub($,N),N=r.mul(K,M),T=r.mul(G,T),T=r.add(T,N),new A($,D,T)}subtract(y){return this.add(y.negate())}is0(){return this.equals(A.ZERO)}multiply(y){const{endo:w}=e;if(!i.isValidNot0(y))throw new Error("invalid scalar: out of range");let g,m;const _=B=>q.cached(this,B,I=>th(A,I));if(w){const{k1neg:B,k1:I,k2neg:$,k2:D}=R(y),{p:T,f:F}=_(I),{p:k,f:N}=_(D);m=F.add(N),g=C(w.beta,T,k,B,$)}else{const{p:B,f:I}=_(y);g=B,m=I}return th(A,[g,m])[0]}multiplyUnsafe(y){const{endo:w}=e,g=this;if(!i.isValid(y))throw new Error("invalid scalar: out of range");if(y===sr||g.is0())return A.ZERO;if(y===Ss)return g;if(q.hasCache(this))return this.multiply(y);if(w){const{k1neg:m,k1:_,k2neg:B,k2:I}=R(y),{p1:$,p2:D}=BA(A,g,_,I);return C(w.beta,$,D,m,B)}else return q.unsafe(g,y)}multiplyAndAddUnsafe(y,w,g){const m=this.multiplyUnsafe(w).add(y.multiplyUnsafe(g));return m.is0()?void 0:m}toAffine(y){return U(this,y)}isTorsionFree(){const{isTorsionFree:y}=e;return o===Ss?!0:y?y(A,this):q.unsafe(this,a).is0()}clearCofactor(){const{clearCofactor:y}=e;return o===Ss?this:y?y(A,this):this.multiplyUnsafe(o)}isSmallOrder(){return this.multiplyUnsafe(o).is0()}toBytes(y=!0){return Ac(y,"isCompressed"),this.assertValidity(),d(A,this,y)}toHex(y=!0){return Es(this.toBytes(y))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}get px(){return this.X}get py(){return this.X}get pz(){return this.Z}toRawBytes(y=!0){return this.toBytes(y)}_setWindowSize(y){this.precompute(y)}static normalizeZ(y){return th(A,y)}static msm(y,w){return $A(A,i,y,w)}static fromPrivateKey(y){return A.BASE.multiply(Bs(i,y))}}A.BASE=new A(s.Gx,s.Gy,r.ONE),A.ZERO=new A(r.ZERO,r.ONE,r.ZERO),A.Fp=r,A.Fn=i;const j=i.BITS,q=new SA(A,e.endo?Math.ceil(j/2):j);return A.BASE.precompute(8),A}function hw(t){return Uint8Array.of(t?2:3)}function dw(t,e){return{secretKey:e.BYTES,publicKey:1+t.BYTES,publicKeyUncompressed:1+2*t.BYTES,publicKeyHasPrefix:!0,signature:2*e.BYTES}}function zA(t,e={}){const{Fn:n}=t,r=e.randomBytes||Ui,i=Object.assign(dw(t.Fp,n),{seed:nw(n.ORDER)});function s(l){try{return!!Bs(n,l)}catch{return!1}}function o(l,d){const{publicKey:p,publicKeyUncompressed:b}=i;try{const v=l.length;return d===!0&&v!==p||d===!1&&v!==b?!1:!!t.fromBytes(l)}catch{return!1}}function a(l=r(i.seed)){return xA(Fi(l,i.seed,"seed"),n.ORDER)}function c(l,d=!0){return t.BASE.multiply(Bs(n,l)).toBytes(d)}function f(l){const d=a(l);return{secretKey:d,publicKey:c(d)}}function u(l){if(typeof l=="bigint")return!1;if(l instanceof t)return!0;const{secretKey:d,publicKey:p,publicKeyUncompressed:b}=i;if(n.allowedLengths||d===p)return;const v=ht("key",l).length;return v===p||v===b}function h(l,d,p=!0){if(u(l)===!0)throw new Error("first arg must be private key");if(u(d)===!1)throw new Error("second arg must be public key");const b=Bs(n,l);return t.fromHex(d).multiply(b).toBytes(p)}return Object.freeze({getPublicKey:c,getSharedSecret:h,keygen:f,Point:t,utils:{isValidSecretKey:s,isValidPublicKey:o,randomSecretKey:a,isValidPrivateKey:s,randomPrivateKey:a,normPrivateKeyToScalar:l=>Bs(n,l),precompute(l=8,d=t.BASE){return d.precompute(l,!1)}},lengths:i})}function HA(t,e,n={}){wc(e),Rc(n,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});const r=n.randomBytes||Ui,i=n.hmac||((w,...g)=>Bc(e,w,ti(...g))),{Fp:s,Fn:o}=t,{ORDER:a,BITS:c}=o,{keygen:f,getPublicKey:u,getSharedSecret:h,utils:l,lengths:d}=zA(t,n),p={prehash:!1,lowS:typeof n.lowS=="boolean"?n.lowS:!1,format:void 0,extraEntropy:!1},b="compact";function v(w){const g=a>>Ss;return w>g}function O(w,g){if(!o.isValidNot0(g))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return g}function P(w,g){oh(g);const m=d.signature,_=g==="compact"?m:g==="recovered"?m+1:void 0;return Fi(w,_,`${g} signature`)}class x{constructor(g,m,_){this.r=O("r",g),this.s=O("s",m),_!=null&&(this.recovery=_),Object.freeze(this)}static fromBytes(g,m=b){P(g,m);let _;if(m==="der"){const{r:D,s:T}=ir.toSig(Fi(g));return new x(D,T)}m==="recovered"&&(_=g[0],m="compact",g=g.subarray(1));const B=o.BYTES,I=g.subarray(0,B),$=g.subarray(B,B*2);return new x(o.fromBytes(I),o.fromBytes($),_)}static fromHex(g,m){return this.fromBytes(mc(g),m)}addRecoveryBit(g){return new x(this.r,this.s,g)}recoverPublicKey(g){const m=s.ORDER,{r:_,s:B,recovery:I}=this;if(I==null||![0,1,2,3].includes(I))throw new Error("recovery id invalid");if(a*lw<m&&I>1)throw new Error("recovery id is ambiguous for h>1 curve");const $=I===2||I===3?_+a:_;if(!s.isValid($))throw new Error("recovery id 2 or 3 invalid");const D=s.toBytes($),T=t.fromBytes(ti(hw((I&1)===0),D)),F=o.inv($),k=R(ht("msgHash",g)),N=o.create(-k*F),M=o.create(B*F),z=t.BASE.multiplyUnsafe(N).add(T.multiplyUnsafe(M));if(z.is0())throw new Error("point at infinify");return z.assertValidity(),z}hasHighS(){return v(this.s)}toBytes(g=b){if(oh(g),g==="der")return mc(ir.hexFromSig(this));const m=o.toBytes(this.r),_=o.toBytes(this.s);if(g==="recovered"){if(this.recovery==null)throw new Error("recovery bit must be present");return ti(Uint8Array.of(this.recovery),m,_)}return ti(m,_)}toHex(g){return Es(this.toBytes(g))}assertValidity(){}static fromCompact(g){return x.fromBytes(ht("sig",g),"compact")}static fromDER(g){return x.fromBytes(ht("sig",g),"der")}normalizeS(){return this.hasHighS()?new x(this.r,o.neg(this.s),this.recovery):this}toDERRawBytes(){return this.toBytes("der")}toDERHex(){return Es(this.toBytes("der"))}toCompactRawBytes(){return this.toBytes("compact")}toCompactHex(){return Es(this.toBytes("compact"))}}const S=n.bits2int||function(w){if(w.length>8192)throw new Error("input is too large");const g=Dc(w),m=w.length*8-c;return m>0?g>>BigInt(m):g},R=n.bits2int_modN||function(w){return o.create(S(w))},U=Oo(c);function L(w){return Ql("num < 2^"+c,w,sr,U),o.toBytes(w)}function C(w,g){return Fi(w,void 0,"message"),g?Fi(e(w),void 0,"prehashed message"):w}function A(w,g,m){if(["recovered","canonical"].some(M=>M in m))throw new Error("sign() legacy options not supported");const{lowS:_,prehash:B,extraEntropy:I}=ah(m,p);w=C(w,B);const $=R(w),D=Bs(o,g),T=[L(D),L($)];if(I!=null&&I!==!1){const M=I===!0?r(d.secretKey):I;T.push(ht("extraEntropy",M))}const F=ti(...T),k=$;function N(M){const z=S(M);if(!o.isValidNot0(z))return;const K=o.inv(z),H=t.BASE.multiply(z).toAffine(),G=o.create(H.x);if(G===sr)return;const ee=o.create(K*o.create(k+G*D));if(ee===sr)return;let te=(H.x===G?0:2)|Number(H.y&Ss),re=ee;return _&&v(ee)&&(re=o.neg(ee),te^=1),new x(G,re,te)}return{seed:F,k2sig:N}}function j(w,g,m={}){w=ht("message",w);const{seed:_,k2sig:B}=A(w,g,m);return dA(e.outputLen,o.BYTES,i)(_,B)}function q(w){let g;const m=typeof w=="string"||bc(w),_=!m&&w!==null&&typeof w=="object"&&typeof w.r=="bigint"&&typeof w.s=="bigint";if(!m&&!_)throw new Error("invalid signature, expected Uint8Array, hex string or Signature instance");if(_)g=new x(w.r,w.s);else if(m){try{g=x.fromBytes(ht("sig",w),"der")}catch(B){if(!(B instanceof ir.Err))throw B}if(!g)try{g=x.fromBytes(ht("sig",w),"compact")}catch{return!1}}return g||!1}function E(w,g,m,_={}){const{lowS:B,prehash:I,format:$}=ah(_,p);if(m=ht("publicKey",m),g=C(ht("message",g),I),"strict"in _)throw new Error("options.strict was renamed to lowS");const D=$===void 0?q(w):x.fromBytes(ht("sig",w),$);if(D===!1)return!1;try{const T=t.fromBytes(m);if(B&&D.hasHighS())return!1;const{r:F,s:k}=D,N=R(g),M=o.inv(k),z=o.create(N*M),K=o.create(F*M),H=t.BASE.multiplyUnsafe(z).add(T.multiplyUnsafe(K));return H.is0()?!1:o.create(H.x)===F}catch{return!1}}function y(w,g,m={}){const{prehash:_}=ah(m,p);return g=C(g,_),x.fromBytes(w,"recovered").recoverPublicKey(g).toBytes()}return Object.freeze({keygen:f,getPublicKey:u,getSharedSecret:h,utils:l,lengths:d,Point:t,sign:j,verify:E,recoverPublicKey:y,Signature:x,hash:e})}function VA(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=fi(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 KA(t){const{CURVE:e,curveOpts:n}=VA(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 GA(t,e){const n=e.Point;return Object.assign({},e,{ProjectivePoint:n,CURVE:Object.assign({},t,ew(n.Fn.ORDER,n.Fn.BITS))})}function ZA(t){const{CURVE:e,curveOpts:n,hash:r,ecdsaOpts:i}=KA(t),s=jA(e,n),o=HA(s,r,i);return GA(t,o)}function ch(t,e){const n=r=>ZA({...t,hash:r});return{...n(e),create:n}}const pw={p:BigInt("0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff"),n:BigInt("0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551"),h:BigInt(1),a:BigInt("0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc"),b:BigInt("0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b"),Gx:BigInt("0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296"),Gy:BigInt("0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5")},gw={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000ffffffff"),n:BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffc7634d81f4372ddf581a0db248b0a77aecec196accc52973"),h:BigInt(1),a:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffeffffffff0000000000000000fffffffc"),b:BigInt("0xb3312fa7e23ee7e4988e056be3f82d19181d9c6efe8141120314088f5013875ac656398d8a2ed19d2a85c8edd3ec2aef"),Gx:BigInt("0xaa87ca22be8b05378eb1c71ef320ad746e1d3b628ba79b9859f741e082542a385502f25dbf55296c3a545e3872760ab7"),Gy:BigInt("0x3617de4a96262c6f5d9e98bf9292dc29f8f41dbd289a147ce9da3113b5f0b8c00a60b1ce1d7e819d7a431d7c90ea0e5f")},yw={p:BigInt("0x1ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),n:BigInt("0x01fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffa51868783bf2f966b7fcc0148f709a5d03bb5c9b8899c47aebb6fb71e91386409"),h:BigInt(1),a:BigInt("0x1fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffc"),b:BigInt("0x0051953eb9618e1c9a1f929a21a0b68540eea2da725b99b315f3b8b489918ef109e156193951ec7e937b1652c0bd3bb1bf073573df883d2c34f1ef451fd46b503f00"),Gx:BigInt("0x00c6858e06b70404e9cd9e3ecb662395b4429c648139053fb521f828af606b4d3dbaa14b5e77efe75928fe1dc127a2ffa8de3348b3c1856a429bf97e7e31c2e5bd66"),Gy:BigInt("0x011839296a789a3bc0045c8a5fb42c7d1bd998f54449579b446817afbd17273e662c97ee72995ef42640c550b9013fad0761353c7086a272c24088be94769fd16650")},WA=fi(pw.p),YA=fi(gw.p),XA=fi(yw.p),JA=ch({...pw,Fp:WA,lowS:!1},Ec);ch({...gw,Fp:YA,lowS:!1},n$),ch({...yw,Fp:XA,lowS:!1,allowedPrivateKeyLengths:[130,131,132]},t$);const QA=JA,bw="base10",Et="base16",Nt="base64pad",ui="base64url",Po="utf8",ww=0,or=1,Ro=2,eO=0,mw=1,To=12,fh=32;function tO(){const t=sh.utils.randomPrivateKey(),e=sh.getPublicKey(t);return{privateKey:At(t,Et),publicKey:At(e,Et)}}function uh(){const t=Ui(fh);return At(t,Et)}function nO(t,e){const n=sh.getSharedSecret(Yt(t,Et),Yt(e,Et)),r=lA($c,n,void 0,void 0,fh);return At(r,Et)}function Cc(t){const e=$c(Yt(t,Et));return At(e,Et)}function Jt(t){const e=$c(Yt(t,Po));return At(e,Et)}function vw(t){return Yt(`${t}`,bw)}function qi(t){return Number(At(t,bw))}function Ew(t){return t.replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,"")}function xw(t){const e=t.replace(/-/g,"+").replace(/_/g,"/"),n=(4-e.length%4)%4;return e+"=".repeat(n)}function rO(t){const e=vw(typeof t.type<"u"?t.type:ww);if(qi(e)===or&&typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");const n=typeof t.senderPublicKey<"u"?Yt(t.senderPublicKey,Et):void 0,r=typeof t.iv<"u"?Yt(t.iv,Et):Ui(To),i=Yt(t.symKey,Et),s=Lb(i,r).encrypt(Yt(t.message,Po)),o=_w({type:e,sealed:s,iv:r,senderPublicKey:n});return t.encoding===ui?Ew(o):o}function iO(t){const e=Yt(t.symKey,Et),{sealed:n,iv:r}=No({encoded:t.encoded,encoding:t.encoding}),i=Lb(e,r).decrypt(n);if(i===null)throw new Error("Failed to decrypt");return At(i,Po)}function sO(t,e){const n=vw(Ro),r=Ui(To),i=Yt(t,Po),s=_w({type:n,sealed:i,iv:r});return e===ui?Ew(s):s}function oO(t,e){const{sealed:n}=No({encoded:t,encoding:e});return At(n,Po)}function _w(t){if(qi(t.type)===Ro)return At(io([t.type,t.sealed]),Nt);if(qi(t.type)===or){if(typeof t.senderPublicKey>"u")throw new Error("Missing sender public key for type 1 envelope");return At(io([t.type,t.senderPublicKey,t.iv,t.sealed]),Nt)}return At(io([t.type,t.iv,t.sealed]),Nt)}function No(t){const e=(t.encoding||Nt)===ui?xw(t.encoded):t.encoded,n=Yt(e,Nt),r=n.slice(eO,mw),i=mw;if(qi(r)===or){const c=i+fh,f=c+To,u=n.slice(i,c),h=n.slice(c,f),l=n.slice(f);return{type:r,sealed:l,iv:h,senderPublicKey:u}}if(qi(r)===Ro){const c=n.slice(i),f=Ui(To);return{type:r,sealed:c,iv:f}}const s=i+To,o=n.slice(i,s),a=n.slice(s);return{type:r,sealed:a,iv:o}}function aO(t,e){const n=No({encoded:t,encoding:e?.encoding});return Iw({type:qi(n.type),senderPublicKey:typeof n.senderPublicKey<"u"?At(n.senderPublicKey,Et):void 0,receiverPublicKey:e?.receiverPublicKey})}function Iw(t){const e=t?.type||ww;if(e===or){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 Sw(t){return t.type===or&&typeof t.senderPublicKey=="string"&&typeof t.receiverPublicKey=="string"}function Bw(t){return t.type===Ro}function cO(t){const e=Buffer.from(t.x,"base64"),n=Buffer.from(t.y,"base64");return io([new Uint8Array([4]),e,n])}function fO(t,e){const[n,r,i]=t.split("."),s=Buffer.from(xw(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=$c(c),u=cO(e);if(!QA.verify(io([o,a]),f,u))throw new Error("Invalid signature");return Uu(t).payload}const uO="irn";function Fc(t){return t?.relay||{protocol:uO}}function $s(t){const e=j_[t];if(typeof e>"u")throw new Error(`Relay Protocol not supported: ${t}`);return e}var lO=Object.defineProperty,hO=Object.defineProperties,dO=Object.getOwnPropertyDescriptors,$w=Object.getOwnPropertySymbols,pO=Object.prototype.hasOwnProperty,gO=Object.prototype.propertyIsEnumerable,Aw=(t,e,n)=>e in t?lO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,lh=(t,e)=>{for(var n in e||(e={}))pO.call(e,n)&&Aw(t,n,e[n]);if($w)for(var n of $w(e))gO.call(e,n)&&Aw(t,n,e[n]);return t},yO=(t,e)=>hO(t,dO(e));function bO(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 Ow(t){if(!t.includes("wc:")){const f=Qy(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:wO(i[0]),version:parseInt(i[1],10),symKey:a.symKey,relay:bO(a),methods:c,expiryTimestamp:a.expiryTimestamp?parseInt(a.expiryTimestamp,10):void 0}}function wO(t){return t.startsWith("//")?t.substring(2):t}function mO(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 Dw(t){const e=new URLSearchParams,n=lh(lh(yO(lh({},mO(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 Lc(t,e,n){return`${t}?wc_ev=${n}&topic=${e}`}var vO=Object.defineProperty,EO=Object.defineProperties,xO=Object.getOwnPropertyDescriptors,Pw=Object.getOwnPropertySymbols,_O=Object.prototype.hasOwnProperty,IO=Object.prototype.propertyIsEnumerable,Rw=(t,e,n)=>e in t?vO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,SO=(t,e)=>{for(var n in e||(e={}))_O.call(e,n)&&Rw(t,n,e[n]);if(Pw)for(var n of Pw(e))IO.call(e,n)&&Rw(t,n,e[n]);return t},BO=(t,e)=>EO(t,xO(e));function As(t){const e=[];return t.forEach(n=>{const[r,i]=n.split(":");e.push(`${r}:${i}`)}),e}function Tw(t){const e=[];return Object.values(t).forEach(n=>{e.push(...As(n.accounts))}),[...new Set(e)]}function $O(t){const e=[];return Object.values(t).forEach(n=>{e.push(...n.methods)}),[...new Set(e)]}function AO(t){const e=[];return Object.values(t).forEach(n=>{e.push(...n.events)}),[...new Set(e)]}function OO(t,e){const n=[];return Object.values(t).forEach(r=>{As(r.accounts).includes(e)&&n.push(...r.methods)}),n}function DO(t,e){const n=[];return Object.values(t).forEach(r=>{As(r.accounts).includes(e)&&n.push(...r.events)}),n}function Nw(t){return t.includes(":")}function PO(t){return Nw(t)?t.split(":")[0]:t}function Uw(t){var e,n,r;const i={};if(!Uo(t))return i;for(const[s,o]of Object.entries(t)){const a=Nw(s)?[s]:o.chains,c=o.methods||[],f=o.events||[],u=PO(s);i[u]=BO(SO({},i[u]),{chains:Ni(a,(e=i[u])==null?void 0:e.chains),methods:Ni(c,(n=i[u])==null?void 0:n.methods),events:Ni(f,(r=i[u])==null?void 0:r.events)})}return i}function RO(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 Cw(t,e){e=e.map(r=>r.replace("did:pkh:",""));const n=RO(e);for(const[r,i]of Object.entries(n))i.methods?i.methods=Ni(i.methods,t):i.methods=t,i.events=["chainChanged","accountsChanged"];return n}function TO(t,e){var n,r,i,s,o,a;const c=Uw(t),f=Uw(e),u={},h=Object.keys(c).concat(Object.keys(f));for(const l of h)u[l]={chains:Ni((n=c[l])==null?void 0:n.chains,(r=f[l])==null?void 0:r.chains),methods:Ni((i=c[l])==null?void 0:i.methods,(s=f[l])==null?void 0:s.methods),events:Ni((o=c[l])==null?void 0:o.events,(a=f[l])==null?void 0:a.events)};return u}const NO={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}},UO={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}=UO[t];return{message:e?`${n} ${e}`:n,code:r}}function Se(t,e){const{message:n,code:r}=NO[t];return{message:e?`${n} ${e}`:n,code:r}}function Os(t,e){return Array.isArray(t)?typeof e<"u"&&t.length?t.every(e):!0:!1}function Uo(t){return Object.getPrototypeOf(t)===Object.prototype&&Object.keys(t).length}function Fe(t){return typeof t>"u"}function Oe(t,e){return e&&Fe(t)?!0:typeof t=="string"&&!!t.trim().length}function hh(t,e){return e&&Fe(t)?!0:typeof t=="number"&&!isNaN(t)}function CO(t,e){const{requiredNamespaces:n}=e,r=Object.keys(t.namespaces),i=Object.keys(n);let s=!0;return Ri(i,r)?(r.forEach(o=>{const{accounts:a,methods:c,events:f}=t.namespaces[o],u=As(a),h=n[o];(!Ri(jy(o,h),u)||!Ri(h.methods,c)||!Ri(h.events,f))&&(s=!1)}),s):!1}function kc(t){return Oe(t,!1)&&t.includes(":")?t.split(":").length===2:!1}function FO(t){if(Oe(t,!1)&&t.includes(":")){const e=t.split(":");if(e.length===3){const n=e[0]+":"+e[1];return!!e[2]&&kc(n)}}return!1}function LO(t){function e(n){try{return typeof new URL(n)<"u"}catch{return!1}}try{if(Oe(t,!1)){if(e(t))return!0;const n=Qy(t);return e(n)}}catch{}return!1}function kO(t){var e;return(e=t?.proposer)==null?void 0:e.publicKey}function qO(t){return t?.topic}function MO(t,e){let n=null;return Oe(t?.publicKey,!1)||(n=W("MISSING_OR_INVALID",`${e} controller public key should be a string`)),n}function Fw(t){let e=!0;return Os(t)?t.length&&(e=t.every(n=>Oe(n,!1))):e=!1,e}function jO(t,e,n){let r=null;return Os(e)&&e.length?e.forEach(i=>{r||kc(i)||(r=Se("UNSUPPORTED_CHAINS",`${n}, chain ${i} should be a string and conform to "namespace:chainId" format`))}):kc(t)||(r=Se("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 zO(t,e,n){let r=null;return Object.entries(t).forEach(([i,s])=>{if(r)return;const o=jO(i,jy(i,s),`${e} ${n}`);o&&(r=o)}),r}function HO(t,e){let n=null;return Os(t)?t.forEach(r=>{n||FO(r)||(n=Se("UNSUPPORTED_ACCOUNTS",`${e}, account ${r} should be a string and conform to "namespace:chainId:address" format`))}):n=Se("UNSUPPORTED_ACCOUNTS",`${e}, accounts should be an array of strings conforming to "namespace:chainId:address" format`),n}function VO(t,e){let n=null;return Object.values(t).forEach(r=>{if(n)return;const i=HO(r?.accounts,`${e} namespace`);i&&(n=i)}),n}function KO(t,e){let n=null;return Fw(t?.methods)?Fw(t?.events)||(n=Se("UNSUPPORTED_EVENTS",`${e}, events should be an array of strings or empty array for no events`)):n=Se("UNSUPPORTED_METHODS",`${e}, methods should be an array of strings or empty array for no methods`),n}function Lw(t,e){let n=null;return Object.values(t).forEach(r=>{if(n)return;const i=KO(r,`${e}, namespace`);i&&(n=i)}),n}function GO(t,e,n){let r=null;if(t&&Uo(t)){const i=Lw(t,e);i&&(r=i);const s=zO(t,e,n);s&&(r=s)}else r=W("MISSING_OR_INVALID",`${e}, ${n} should be an object with data`);return r}function dh(t,e){let n=null;if(t&&Uo(t)){const r=Lw(t,e);r&&(n=r);const i=VO(t,e);i&&(n=i)}else n=W("MISSING_OR_INVALID",`${e}, namespaces should be an object with data`);return n}function kw(t){return Oe(t.protocol,!0)}function ZO(t,e){let n=!1;return e&&!t?n=!0:t&&Os(t)&&t.length&&t.forEach(r=>{n=kw(r)}),n}function WO(t){return typeof t=="number"}function Ut(t){return typeof t<"u"&&typeof t!==null}function YO(t){return!(!t||typeof t!="object"||!t.code||!hh(t.code,!1)||!t.message||!Oe(t.message,!1))}function XO(t){return!(Fe(t)||!Oe(t.method,!1))}function JO(t){return!(Fe(t)||Fe(t.result)&&Fe(t.error)||!hh(t.id,!1)||!Oe(t.jsonrpc,!1))}function QO(t){return!(Fe(t)||!Oe(t.name,!1))}function qw(t,e){return!(!kc(e)||!Tw(t).includes(e))}function eD(t,e,n){return Oe(n,!1)?OO(t,e).includes(n):!1}function tD(t,e,n){return Oe(n,!1)?DO(t,e).includes(n):!1}function Mw(t,e,n){let r=null;const i=nD(t),s=rD(e),o=Object.keys(i),a=Object.keys(s),c=jw(Object.keys(t)),f=jw(Object.keys(e)),u=c.filter(h=>!f.includes(h));return u.length&&(r=W("NON_CONFORMING_NAMESPACES",`${n} namespaces keys don't satisfy requiredNamespaces.
22
+ Required: ${u.toString()}
23
+ Received: ${Object.keys(e).toString()}`)),Ri(o,a)||(r=W("NON_CONFORMING_NAMESPACES",`${n} namespaces chains don't satisfy required namespaces.
24
24
  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 $9(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 T1(t){return[...new Set(t.map(e=>e.includes(":")?e.split(":")[0]:e))]}function P9(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 T9(t,e){return gl(t,!1)&&t<=e.max&&t>=e.min}function R1(){const t=ds();return new Promise(e=>{switch(t){case Bt.browser:e(R9());break;case Bt.reactNative:e(N9());break;case Bt.node:e(C9());break;default:e(!0)}})}function R9(){return Ei()&&navigator?.onLine}async function N9(){return sr()&&typeof global<"u"&&global!=null&&global.NetInfo?(await(global==null?void 0:global.NetInfo.fetch()))?.isConnected:!0}function C9(){return!0}function U9(t){switch(ds()){case Bt.browser:F9(t);break;case Bt.reactNative:L9(t);break}}function F9(t){!sr()&&Ei()&&(window.addEventListener("online",()=>t(!0)),window.addEventListener("offline",()=>t(!1)))}function L9(t){sr()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(e=>t(e?.isConnected))}function k9(){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 q9(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 M9({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=H9(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${z9(n.tip)}`),f=K9(l),d=new Uint8Array([0,...t,o,...e,...a,...u,...f,...i]),h=V9(d.length+1);return new Uint8Array([...h,s,...d])}function j9(t){const e=wl(t),n=__.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 z9(t){return t.startsWith("0x")?t.slice(2):t}function H9(t){const e=is.decode(t)[0];return e===42?0:e===60?2:1}function V9(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 K9(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 G9(t){const e=Uint8Array.from(Buffer.from(t.signature,"hex")),n=q9(t.transaction.address),r=M9({publicKey:n,signature:e,payload:t.transaction}),i=Buffer.from(r).toString("hex");return j9(i)}function N1({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 W9="PARSE_ERROR",Z9="INVALID_REQUEST",Y9="METHOD_NOT_FOUND",X9="INVALID_PARAMS",C1="INTERNAL_ERROR",ml="SERVER_ERROR",J9=[-32700,-32600,-32601,-32602,-32603],Os={[W9]:{code:-32700,message:"Parse error"},[Z9]:{code:-32600,message:"Invalid Request"},[Y9]:{code:-32601,message:"Method not found"},[X9]:{code:-32602,message:"Invalid params"},[C1]:{code:-32603,message:"Internal error"},[ml]:{code:-32e3,message:"Server error"}},U1=ml;function Q9(t){return J9.includes(t)}function F1(t){return Object.keys(Os).includes(t)?Os[t]:Os[U1]}function e7(t){const e=Object.values(Os).find(n=>n.code===t);return e||Os[U1]}function t7(t,e,n){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable ${n} RPC url at ${e}`):t}var L1={};/*! *****************************************************************************
25
+ Approved: ${a.toString()}`)),Object.keys(e).forEach(h=>{if(!h.includes(":")||r)return;const l=As(e[h].accounts);l.includes(h)||(r=W("NON_CONFORMING_NAMESPACES",`${n} namespaces accounts don't satisfy namespace accounts for ${h}
26
+ Required: ${h}
27
+ Approved: ${l.toString()}`))}),o.forEach(h=>{r||(Ri(i[h].methods,s[h].methods)?Ri(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 nD(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 jw(t){return[...new Set(t.map(e=>e.includes(":")?e.split(":")[0]:e))]}function rD(t){const e={};return Object.keys(t).forEach(n=>{n.includes(":")?e[n]=t[n]:As(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 iD(t,e){return hh(t,!1)&&t<=e.max&&t>=e.min}function zw(){const t=xo();return new Promise(e=>{switch(t){case jt.browser:e(sD());break;case jt.reactNative:e(oD());break;case jt.node:e(aD());break;default:e(!0)}})}function sD(){return ms()&&navigator?.onLine}async function oD(){return Wr()&&typeof global<"u"&&global!=null&&global.NetInfo?(await(global==null?void 0:global.NetInfo.fetch()))?.isConnected:!0}function aD(){return!0}function cD(t){switch(xo()){case jt.browser:fD(t);break;case jt.reactNative:uD(t);break}}function fD(t){!Wr()&&ms()&&(window.addEventListener("online",()=>t(!0)),window.addEventListener("offline",()=>t(!1)))}function uD(t){Wr()&&typeof global<"u"&&global!=null&&global.NetInfo&&global?.NetInfo.addEventListener(e=>t(e?.isConnected))}function lD(){var t;return ms()&&Un()?((t=Un())==null?void 0:t.visibilityState)==="visible":!0}const ph={};class Co{static get(e){return ph[e]}static set(e,n){ph[e]=n}static delete(e){delete ph[e]}}function hD(t){const e=eo.decode(t);if(e.length<33)throw new Error("Too short to contain a public key");return e.slice(1,33)}function dD({publicKey:t,signature:e,payload:n}){var r;const i=gh(n.method),s=128|parseInt(((r=n.version)==null?void 0:r.toString())||"4"),o=yD(n.address),a=n.era==="00"?new Uint8Array([0]):gh(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]),u=BigInt(`0x${gD(n.tip)}`),h=wD(u),l=new Uint8Array([0,...t,o,...e,...a,...f,...h,...i]),d=bD(l.length+1);return new Uint8Array([...d,s,...l])}function pD(t){const e=gh(t),n=e9.blake2b(e,void 0,32);return"0x"+Buffer.from(n).toString("hex")}function gh(t){return new Uint8Array(t.replace(/^0x/,"").match(/.{1,2}/g).map(e=>parseInt(e,16)))}function gD(t){return t.startsWith("0x")?t.slice(2):t}function yD(t){const e=eo.decode(t)[0];return e===42?0:e===60?2:1}function bD(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 wD(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 mD(t){const e=Uint8Array.from(Buffer.from(t.signature,"hex")),n=hD(t.transaction.address),r=dD({publicKey:n,signature:e,payload:t.transaction}),i=Buffer.from(r).toString("hex");return pD(i)}function Hw({logger:t,name:e}){const n=typeof t=="string"?pd({opts:{level:t,name:e}}).logger:t;return n.level=typeof t=="string"?t:t.level,n}const vD="PARSE_ERROR",ED="INVALID_REQUEST",xD="METHOD_NOT_FOUND",_D="INVALID_PARAMS",Vw="INTERNAL_ERROR",yh="SERVER_ERROR",ID=[-32700,-32600,-32601,-32602,-32603],Fo={[vD]:{code:-32700,message:"Parse error"},[ED]:{code:-32600,message:"Invalid Request"},[xD]:{code:-32601,message:"Method not found"},[_D]:{code:-32602,message:"Invalid params"},[Vw]:{code:-32603,message:"Internal error"},[yh]:{code:-32e3,message:"Server error"}},Kw=yh;function SD(t){return ID.includes(t)}function Gw(t){return Object.keys(Fo).includes(t)?Fo[t]:Fo[Kw]}function BD(t){const e=Object.values(Fo).find(n=>n.code===t);return e||Fo[Kw]}function $D(t,e,n){return t.message.includes("getaddrinfo ENOTFOUND")||t.message.includes("connect ECONNREFUSED")?new Error(`Unavailable ${n} RPC url at ${e}`):t}var Zw={};/*! *****************************************************************************
28
28
  Copyright (c) Microsoft Corporation.
29
29
 
30
30
  Permission to use, copy, modify, and/or distribute this software for any
@@ -37,5 +37,5 @@ ${t.length}`,n=new TextEncoder().encode(e+t);return"0x"+Buffer.from(m5(n)).toStr
37
37
  LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
38
38
  OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
39
39
  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 n7(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 r7(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 i7(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 s7(t,e){return function(n,r){e(n,r,t)}}function o7(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function a7(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 c7(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 u7(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]}function l7(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 k1(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 f7(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(k1(arguments[e]));return t}function h7(){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 d7(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,y){s.push([d,h,p,y])>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 p7(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 g7(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 y7(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function b7(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 w7(t){return t&&t.__esModule?t:{default:t}}function m7(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function v7(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 E7=Object.freeze({__proto__:null,__extends:n7,get __assign(){return El},__rest:r7,__decorate:i7,__param:s7,__metadata:o7,__awaiter:a7,__generator:c7,__createBinding:u7,__exportStar:l7,__values:xl,__read:k1,__spread:f7,__spreadArrays:h7,__await:Ds,__asyncGenerator:d7,__asyncDelegator:p7,__asyncValues:g7,__makeTemplateObject:y7,__importStar:b7,__importDefault:w7,__classPrivateFieldGet:m7,__classPrivateFieldSet:v7}),x7=Wl(E7),Nn={},q1;function _7(){if(q1)return Nn;q1=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={},M1;function S7(){if(M1)return Cn;M1=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=x7;e.__exportStar(_7(),t),e.__exportStar(S7(),t)})(L1);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 Ea(t,e){return{id:t,jsonrpc:"2.0",result:e}}function _l(t,e,n){return{id:t,jsonrpc:"2.0",error:I7(e,n)}}function I7(t,e){return typeof t>"u"?F1(C1):(typeof t=="string"&&(t=Object.assign(Object.assign({},F1(ml)),{message:t})),typeof e<"u"&&(t.data=e),Q9(t.code)&&(t=e7(t.code)),t)}class A7{}class B7 extends A7{constructor(){super()}}class O7 extends B7{constructor(e){super()}}const D7="^wss?:";function $7(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function P7(t,e){const n=$7(t);return typeof n>"u"?!1:new RegExp(e).test(n)}function j1(t){return P7(t,D7)}function T7(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function z1(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function Sl(t){return z1(t)&&"method"in t}function xa(t){return z1(t)&&(cn(t)||Lt(t))}function cn(t){return"result"in t}function Lt(t){return"error"in t}class R7 extends O7{constructor(e){super(e),this.events=new Ke.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),xa(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 N7=()=>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"),C7=()=>typeof WebSocket<"u"||typeof global<"u"&&typeof global.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",H1=t=>t.split("?")[0],V1=10,U7=N7();class F7{constructor(e){if(this.url=e,this.events=new Ke.exports.EventEmitter,this.registering=!1,!j1(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(!j1(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=L1.isReactNative()?void 0:{rejectUnauthorized:!T7(e)},s=new U7(e,[],i);C7()?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 t7(e,H1(n),"WS")}resetMaxListeners(){this.events.getMaxListeners()>V1&&this.events.setMaxListeners(V1)}emitError(e){const n=this.parseError(new Error(e?.message||`WebSocket connection failed for host: ${H1(this.url)}`));return this.events.emit("register_error",n),n}}const K1="wc",G1=2,_a="core",un=`${K1}@2:${_a}:`,L7={name:_a,logger:"error"},k7={database:":memory:"},q7="crypto",W1="client_ed25519_seed",M7=K.ONE_DAY,j7="keychain",z7="0.3",H7="messages",V7="0.3",K7=K.SIX_HOURS,G7="publisher",Z1="irn",W7="error",Y1="wss://relay.walletconnect.org",Z7="relayer",Ie={message:"relayer_message",message_ack:"relayer_message_ack",connect:"relayer_connect",disconnect:"relayer_disconnect",error:"relayer_error",connection_stalled:"relayer_connection_stalled",transport_closed:"relayer_transport_closed",publish:"relayer_publish"},Y7="_subscription",kt={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},X7=.1,Il="2.23.0",me={link_mode:"link_mode",relay:"relay"},Sa={inbound:"inbound",outbound:"outbound"},J7="0.3",Q7="WALLETCONNECT_CLIENT_ID",X1="WALLETCONNECT_LINK_MODE_APPS",Dt={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},eA="subscription",tA="0.3",nA="pairing",rA="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"},iA="history",sA="0.3",oA="expirer",qt={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},aA="0.3",cA="verify-api",uA="https://verify.walletconnect.com",J1="https://verify.walletconnect.org",Ps=J1,lA=`${Ps}/v3`,fA=[uA,J1],hA="echo",dA="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"},pA=.1,gA="event-client",yA=86400,bA="https://pulse.walletconnect.org/batch";function wA(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 y=0,m=0,B=0,$=p.length;B!==$&&p[B]===0;)B++,y++;for(var _=($-B)*l+1>>>0,x=new Uint8Array(_);B!==$;){for(var P=p[B],R=0,U=_-1;(P!==0||R<m)&&U!==-1;U--,R++)P+=256*x[U]>>>0,x[U]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");m=R,B++}for(var F=_-m;F!==_&&x[F]===0;)F++;for(var D=c.repeat(y);F<_;++F)D+=t.charAt(x[F]);return D}function d(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var y=0;if(p[y]!==" "){for(var m=0,B=0;p[y]===c;)m++,y++;for(var $=(p.length-y)*u+1>>>0,_=new Uint8Array($);p[y];){var x=n[p.charCodeAt(y)];if(x===255)return;for(var P=0,R=$-1;(x!==0||P<B)&&R!==-1;R--,P++)x+=a*_[R]>>>0,_[R]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");B=P,y++}if(p[y]!==" "){for(var U=$-B;U!==$&&_[U]===0;)U++;for(var F=new Uint8Array(m+($-U)),D=m;U!==$;)F[D++]=_[U++];return F}}}function h(p){var y=d(p);if(y)return y;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:d,decode:h}}var mA=wA,vA=mA;const Q1=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")},EA=t=>new TextEncoder().encode(t),xA=t=>new TextDecoder().decode(t);class _A{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 SA{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 ey(this,e)}}class IA{constructor(e){this.decoders=e}or(e){return ey(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 ey=(t,e)=>new IA({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class AA{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new _A(e,n,r),this.decoder=new SA(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Ia=({name:t,prefix:e,encode:n,decode:r})=>new AA(t,e,n,r),Rs=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=vA(n,e);return Ia({prefix:t,name:e,encode:r,decode:s=>Q1(i(s))})},BA=(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},OA=(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})=>Ia({prefix:e,name:t,encode(i){return OA(i,r,n)},decode(i){return BA(i,r,n,t)}}),DA=Ia({prefix:"\0",name:"identity",encode:t=>xA(t),decode:t=>EA(t)});var $A=Object.freeze({__proto__:null,identity:DA});const PA=Me({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var TA=Object.freeze({__proto__:null,base2:PA});const RA=Me({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var NA=Object.freeze({__proto__:null,base8:RA});const CA=Rs({prefix:"9",name:"base10",alphabet:"0123456789"});var UA=Object.freeze({__proto__:null,base10:CA});const FA=Me({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),LA=Me({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var kA=Object.freeze({__proto__:null,base16:FA,base16upper:LA});const qA=Me({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),MA=Me({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),jA=Me({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),zA=Me({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),HA=Me({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),VA=Me({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),KA=Me({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),GA=Me({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),WA=Me({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ZA=Object.freeze({__proto__:null,base32:qA,base32upper:MA,base32pad:jA,base32padupper:zA,base32hex:HA,base32hexupper:VA,base32hexpad:KA,base32hexpadupper:GA,base32z:WA});const YA=Rs({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),XA=Rs({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var JA=Object.freeze({__proto__:null,base36:YA,base36upper:XA});const QA=Rs({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),eB=Rs({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var tB=Object.freeze({__proto__:null,base58btc:QA,base58flickr:eB});const nB=Me({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rB=Me({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),iB=Me({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sB=Me({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var oB=Object.freeze({__proto__:null,base64:nB,base64pad:rB,base64url:iB,base64urlpad:sB});const ty=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}"),aB=ty.reduce((t,e,n)=>(t[n]=e,t),[]),cB=ty.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function uB(t){return t.reduce((e,n)=>(e+=aB[n],e),"")}function lB(t){const e=[];for(const n of t){const r=cB[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const fB=Ia({prefix:"\u{1F680}",name:"base256emoji",encode:uB,decode:lB});var hB=Object.freeze({__proto__:null,base256emoji:fB}),dB=ry,ny=128,pB=127,gB=~pB,yB=Math.pow(2,31);function ry(t,e,n){e=e||[],n=n||0;for(var r=n;t>=yB;)e[n++]=t&255|ny,t/=128;for(;t&gB;)e[n++]=t&255|ny,t>>>=7;return e[n]=t|0,ry.bytes=n-r+1,e}var bB=Al,wB=128,iy=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&iy)<<i:(o&iy)*Math.pow(2,i),i+=7}while(o>=wB);return Al.bytes=s-r,n}var mB=Math.pow(2,7),vB=Math.pow(2,14),EB=Math.pow(2,21),xB=Math.pow(2,28),_B=Math.pow(2,35),SB=Math.pow(2,42),IB=Math.pow(2,49),AB=Math.pow(2,56),BB=Math.pow(2,63),OB=function(t){return t<mB?1:t<vB?2:t<EB?3:t<xB?4:t<_B?5:t<SB?6:t<IB?7:t<AB?8:t<BB?9:10},DB={encode:dB,decode:bB,encodingLength:OB},sy=DB;const oy=(t,e,n=0)=>(sy.encode(t,e,n),e),ay=t=>sy.encodingLength(t),Bl=(t,e)=>{const n=e.byteLength,r=ay(t),i=r+ay(n),s=new Uint8Array(i+n);return oy(t,s,0),oy(n,s,r),s.set(e,i),new $B(t,n,e,s)};class $B{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const cy=({name:t,code:e,encode:n})=>new PB(t,e,n);class PB{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 uy=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),TB=cy({name:"sha2-256",code:18,encode:uy("SHA-256")}),RB=cy({name:"sha2-512",code:19,encode:uy("SHA-512")});var NB=Object.freeze({__proto__:null,sha256:TB,sha512:RB});const ly=0,CB="identity",fy=Q1;var UB=Object.freeze({__proto__:null,identity:{code:ly,name:CB,encode:fy,digest:t=>Bl(ly,fy(t))}});new TextEncoder,new TextDecoder;const hy={...$A,...TA,...NA,...UA,...kA,...ZA,...JA,...tB,...oB,...hB};({...NB,...UB});function dy(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function FB(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?dy(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function py(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const gy=py("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Ol=py("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=FB(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),LB={utf8:gy,"utf-8":gy,hex:hy.base16,latin1:Ol,ascii:Ol,binary:Ol,...hy};function kB(t,e="utf8"){const n=LB[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?dy(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}var qB=Object.defineProperty,MB=(t,e,n)=>e in t?qB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,fn=(t,e,n)=>MB(t,typeof e!="symbol"?e+"":e,n);class jB{constructor(e,n){this.core=e,this.logger=n,fn(this,"keychain",new Map),fn(this,"name",j7),fn(this,"version",z7),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,Nu(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Cu(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 zB=Object.defineProperty,HB=(t,e,n)=>e in t?zB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ce=(t,e,n)=>HB(t,typeof e!="symbol"?e+"":e,n);class VB{constructor(e,n,r){this.core=e,this.logger=n,Ce(this,"name",q7),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=DI();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 l3(a,i,M7,o)}),Ce(this,"generateSharedKey",(i,s,o)=>{this.isInitialized();const a=this.getPrivateKey(i),c=$I(a,s);return this.setSymKey(c,o)}),Ce(this,"setSymKey",async(i,s)=>{this.isInitialized();const o=s||ba(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=p1(o),c=Br(s);if(y1(a))return RI(c,o?.encoding);if(g1(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 PI({type:l,symKey:u,message:c,senderPublicKey:f,encoding:o?.encoding})}),Ce(this,"decode",async(i,s,o)=>{this.isInitialized();const a=CI(s,o);if(y1(a)){const c=NI(s,o?.encoding);return ni(c)}if(g1(a)){const c=a.receiverPublicKey,u=a.senderPublicKey;i=await this.generateSharedKey(c,u)}try{const c=this.getSymKey(i),u=TI({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 jB(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(W1)}catch{e=dl(),await this.keychain.set(W1,e)}return kB(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 KB=Object.defineProperty,GB=Object.defineProperties,WB=Object.getOwnPropertyDescriptors,yy=Object.getOwnPropertySymbols,ZB=Object.prototype.hasOwnProperty,YB=Object.prototype.propertyIsEnumerable,Dl=(t,e,n)=>e in t?KB(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,XB=(t,e)=>{for(var n in e||(e={}))ZB.call(e,n)&&Dl(t,n,e[n]);if(yy)for(var n of yy(e))YB.call(e,n)&&Dl(t,n,e[n]);return t},JB=(t,e)=>GB(t,WB(e)),$t=(t,e,n)=>Dl(t,typeof e!="symbol"?e+"":e,n);class QB extends um{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",H7),$t(this,"version",V7),$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===Sa.inbound){const c=this.messagesWithoutClientAck.get(r)||{};this.messagesWithoutClientAck.set(r,JB(XB({},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,Nu(e))}async setRelayerMessagesWithoutClientAck(e){await this.core.storage.setItem(this.storageKeyWithoutClientAck,Nu(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Cu(e):void 0}async getRelayerMessagesWithoutClientAck(){const e=await this.core.storage.getItem(this.storageKeyWithoutClientAck);return typeof e<"u"?Cu(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 eO=Object.defineProperty,tO=Object.defineProperties,nO=Object.getOwnPropertyDescriptors,by=Object.getOwnPropertySymbols,rO=Object.prototype.hasOwnProperty,iO=Object.prototype.propertyIsEnumerable,$l=(t,e,n)=>e in t?eO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ti=(t,e)=>{for(var n in e||(e={}))rO.call(e,n)&&$l(t,n,e[n]);if(by)for(var n of by(e))iO.call(e,n)&&$l(t,n,e[n]);return t},wy=(t,e)=>tO(t,nO(e)),Mt=(t,e,n)=>$l(t,typeof e!="symbol"?e+"":e,n);class sO extends lm{constructor(e,n){super(e,n),this.relayer=e,this.logger=n,Mt(this,"events",new Ke.exports.EventEmitter),Mt(this,"name",G7),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||K7,d=s?.prompt||!1,h=s?.tag||0,p=s?.id||Er().toString(),y=Di(wa().protocol),m={id:p,method:s?.publishMethod||y.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=m.params)==null?void 0:o.prompt)&&((a=m.params)==null||delete a.prompt),Pe((c=m.params)==null?void 0:c.tag)&&((u=m.params)==null||delete u.tag);const $=new Promise(async _=>{const x=({id:R})=>{var U;((U=m.id)==null?void 0:U.toString())===R.toString()&&(this.removeRequestFromQueue(R),this.relayer.events.removeListener(Ie.publish,x),_())};this.relayer.events.on(Ie.publish,x);const P=sn(new Promise((R,U)=>{this.rpcPublish(m,s).then(R).catch(F=>{this.logger.warn(F,F?.message),U(F)})}),this.initialPublishTimeout,`Failed initial publish, retrying.... id:${p} tag:${h}`);try{await P,this.events.removeListener(Ie.publish,x)}catch(R){this.queue.set(p,{request:m,opts:s,attempt:1}),this.logger.warn(R,R?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:p,topic:r,message:i,opts:s}}),await sn($,this.publishTimeout,B)}catch($){if(this.logger.debug("Failed to Publish Payload"),this.logger.error($),(l=s?.internal)!=null&&l.throwOnFailedPublish)throw $}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:y,ttl:m=K.FIVE_MINUTES}=l,B=l.id||Er().toString(),$=Di(wa().protocol),_=h||$.publish,x={id:B,method:_,params:Ti(wy(Ti({},u),{ttl:m,prompt:p,tag:y,attestation:f}),d)},P=`Failed to publish custom payload, please try again. id:${B} tag:${y}`;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 R=new Promise(async U=>{const F=({id:j})=>{var M;((M=x.id)==null?void 0:M.toString())===j.toString()&&(this.removeRequestFromQueue(j),this.relayer.events.removeListener(Ie.publish,F),U())};this.relayer.events.on(Ie.publish,F);const D=sn(new Promise((j,M)=>{this.rpcPublish(x,l).then(j).catch(E=>{this.logger.warn(E,E?.message),M(E)})}),this.initialPublishTimeout,`Failed initial custom payload publish, retrying.... method:${_} id:${B} tag:${y}`);try{await D,this.events.removeListener(Ie.publish,F)}catch(j){this.queue.set(B,{request:x,opts:l,attempt:1}),this.logger.warn(j,j?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:B,payload:u,opts:l}}),await sn(R,this.publishTimeout,P)}catch(R){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(R),(c=l?.internal)!=null&&c.throwOnFailedPublish)throw R}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(Ie.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,wy(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(Ie.connection_stalled);return}this.checkQueue()}),this.relayer.on(Ie.message_ack,e=>{this.removeRequestFromQueue(e.id.toString())})}}var oO=Object.defineProperty,aO=(t,e,n)=>e in t?oO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ri=(t,e,n)=>aO(t,typeof e!="symbol"?e+"":e,n);class cO{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 uO=Object.defineProperty,lO=Object.defineProperties,fO=Object.getOwnPropertyDescriptors,my=Object.getOwnPropertySymbols,hO=Object.prototype.hasOwnProperty,dO=Object.prototype.propertyIsEnumerable,Pl=(t,e,n)=>e in t?uO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ns=(t,e)=>{for(var n in e||(e={}))hO.call(e,n)&&Pl(t,n,e[n]);if(my)for(var n of my(e))dO.call(e,n)&&Pl(t,n,e[n]);return t},Tl=(t,e)=>lO(t,fO(e)),ye=(t,e,n)=>Pl(t,typeof e!="symbol"?e+"":e,n);class pO extends dm{constructor(e,n){super(e,n),this.relayer=e,this.logger=n,ye(this,"subscriptions",new Map),ye(this,"topicMap",new cO),ye(this,"events",new Ke.exports.EventEmitter),ye(this,"name",eA),ye(this,"version",tA),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=wa(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=wa(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,y)=>{this.relayer.request(a).catch(m=>{this.logger.warn(m,m?.message),y(m)}).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(Ie.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(Ie.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(Ie.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 Z_(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 gO=Object.defineProperty,vy=Object.getOwnPropertySymbols,yO=Object.prototype.hasOwnProperty,bO=Object.prototype.propertyIsEnumerable,Rl=(t,e,n)=>e in t?gO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ey=(t,e)=>{for(var n in e||(e={}))yO.call(e,n)&&Rl(t,n,e[n]);if(vy)for(var n of vy(e))bO.call(e,n)&&Rl(t,n,e[n]);return t},ue=(t,e,n)=>Rl(t,typeof e!="symbol"?e+"":e,n);class wO extends fm{constructor(e){var n;super(e),ue(this,"protocol","wc"),ue(this,"version",2),ue(this,"core"),ue(this,"logger"),ue(this,"events",new Ke.exports.EventEmitter),ue(this,"provider"),ue(this,"messages"),ue(this,"subscriber"),ue(this,"publisher"),ue(this,"name",Z7),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(Ie.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(Ie.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=N1({logger:(n=e.logger)!=null?n:W7,name:this.name}),this.messages=new QB(this.logger,e.core),this.subscriber=new pO(this,this.logger),this.publisher=new sO(this,this.logger),this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||Y1,R_()?this.packageName=U0():N_()&&(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},Sa.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,Ey({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 R1())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(Ie.message,e),await this.recordMessageEvent(e,Sa.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 R7(new F7(k_({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(Y7))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(Ey({type:"event",event:n.id},a)),this.events.emit(n.id,a),await this.acknowledgePayload(e),await this.onMessageEvent(a)}else xa(e)&&this.events.emit(Ie.message_ack,e)}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(await this.recordMessageEvent(e,Sa.inbound),this.events.emit(Ie.message,e))}async acknowledgePayload(e){const n=Ea(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 R1();U9(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&&k9())try{await this.confirmOnlineStateOrThrow(),await this.transportOpen()}catch(n){this.logger.warn(n,n?.message)}})}async onProviderDisconnect(){clearTimeout(this.pingTimeout),this.events.emit(Ie.disconnect),this.connectionAttemptInProgress=!1,!this.reconnectInProgress&&(this.reconnectInProgress=!0,await this.subscriber.stop(),this.subscriber.hasAnyTopics&&(this.transportExplicitlyClosed||(this.reconnectTimeout=setTimeout(async()=>{await this.transportOpen().catch(e=>this.logger.error(e,e?.message)),this.reconnectTimeout=void 0,this.reconnectInProgress=!1},K.toMiliseconds(X7)))))}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 mO(t,e){return t===e||Number.isNaN(t)&&Number.isNaN(e)}function xy(t){return Object.getOwnPropertySymbols(t).filter(e=>Object.prototype.propertyIsEnumerable.call(t,e))}function _y(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const vO="[object RegExp]",EO="[object String]",xO="[object Number]",_O="[object Boolean]",Sy="[object Arguments]",SO="[object Symbol]",IO="[object Date]",AO="[object Map]",BO="[object Set]",OO="[object Array]",DO="[object Function]",$O="[object ArrayBuffer]",Nl="[object Object]",PO="[object Error]",TO="[object DataView]",RO="[object Uint8Array]",NO="[object Uint8ClampedArray]",CO="[object Uint16Array]",UO="[object Uint32Array]",FO="[object BigUint64Array]",LO="[object Int8Array]",kO="[object Int16Array]",qO="[object Int32Array]",MO="[object BigInt64Array]",jO="[object Float32Array]",zO="[object Float64Array]";function HO(){}function Iy(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 VO(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=_y(t),s=_y(e);if(i===Sy&&(i=Nl),s===Sy&&(s=Nl),i!==s)return!1;switch(i){case EO:return t.toString()===e.toString();case xO:{const c=t.valueOf(),u=e.valueOf();return mO(c,u)}case _O:case IO:case SO:return Object.is(t.valueOf(),e.valueOf());case vO:return t.source===e.source&&t.flags===e.flags;case DO: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 AO:{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 BO:{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 OO:case RO:case NO:case CO:case UO:case FO:case LO:case kO:case qO:case MO:case jO:case zO:{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 $O:return t.byteLength!==e.byteLength?!1:Us(new Uint8Array(t),new Uint8Array(e),n,r);case TO:return t.byteLength!==e.byteLength||t.byteOffset!==e.byteOffset?!1:Us(new Uint8Array(t),new Uint8Array(e),n,r);case PO:return t.name===e.name&&t.message===e.message;case Nl:{if(!(Us(t.constructor,e.constructor,n,r)||Iy(t)&&Iy(e)))return!1;const c=[...Object.keys(t),...xy(t)],u=[...Object.keys(e),...xy(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 KO(t,e){return VO(t,e,HO)}var GO=Object.defineProperty,Ay=Object.getOwnPropertySymbols,WO=Object.prototype.hasOwnProperty,ZO=Object.prototype.propertyIsEnumerable,Cl=(t,e,n)=>e in t?GO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,By=(t,e)=>{for(var n in e||(e={}))WO.call(e,n)&&Cl(t,n,e[n]);if(Ay)for(var n of Ay(e))ZO.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 hm{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",J7),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):d9(o)?this.map.set(o.id,o):p9(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=>KO(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=By(By({},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 YO=Object.defineProperty,XO=(t,e,n)=>e in t?YO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,se=(t,e,n)=>XO(t,typeof e!="symbol"?e+"":e,n);class JO{constructor(e,n){this.core=e,this.logger=n,se(this,"name",nA),se(this,"version",rA),se(this,"events",new Ke.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:Z1},c={topic:s,expiry:o,relay:a,active:!1,methods:r?.methods},u=v1({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}=m1(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(he("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 v1({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=Ea(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(he("pairing_ping",s),{}):Lt(i)&&this.events.emit(he("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(!h9(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=m1(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(!Se(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(Ie.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})):xa(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 QO=Object.defineProperty,eD=(t,e,n)=>e in t?QO(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,je=(t,e,n)=>eD(t,typeof e!="symbol"?e+"":e,n);class tD extends cm{constructor(e,n){super(e,n),this.core=e,this.logger=n,je(this,"records",new Map),je(this,"events",new Ke.exports.EventEmitter),je(this,"name",iA),je(this,"version",sA),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 nD=Object.defineProperty,rD=(t,e,n)=>e in t?nD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,nt=(t,e,n)=>rD(t,typeof e!="symbol"?e+"":e,n);class iD extends pm{constructor(e,n){super(e,n),this.core=e,this.logger=n,nt(this,"expirations",new Map),nt(this,"events",new Ke.exports.EventEmitter),nt(this,"name",oA),nt(this,"version",aA),nt(this,"cached",[]),nt(this,"initialized",!1),nt(this,"storagePrefix",un),nt(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)}),nt(this,"has",r=>{try{const i=this.formatTarget(r);return typeof this.getExpiration(i)<"u"}catch{return!1}}),nt(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})}),nt(this,"get",r=>{this.isInitialized();const i=this.formatTarget(r);return this.getExpiration(i)}),nt(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})}}),nt(this,"on",(r,i)=>{this.events.on(r,i)}),nt(this,"once",(r,i)=>{this.events.once(r,i)}),nt(this,"off",(r,i)=>{this.events.off(r,i)}),nt(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 q_(e);if(typeof e=="number")return M_(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 sD=Object.defineProperty,oD=(t,e,n)=>e in t?sD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ae=(t,e,n)=>oD(t,typeof e!="symbol"?e+"":e,n);class aD extends gm{constructor(e,n,r){super(e,n,r),this.core=e,this.logger=n,this.store=r,Ae(this,"name",cA),Ae(this,"abortController"),Ae(this,"isDevEnv"),Ae(this,"verifyUrlV3",lA),Ae(this,"storagePrefix",un),Ae(this,"version",G1),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",m),u.body.removeChild(y),h("attestation aborted")};this.abortController.signal.addEventListener("abort",p);const y=u.createElement("iframe");y.src=c,y.style.display="none",y.addEventListener("error",p,{signal:this.abortController.signal});const m=B=>{if(B.data&&typeof B.data=="string")try{const $=JSON.parse(B.data);if($.type==="verify_attestation"){if(dc($.attestation).payload.id!==o)return;clearInterval(l),u.body.removeChild(y),this.abortController.signal.removeEventListener("abort",p),window.removeEventListener("message",m),d($.attestation===null?"":$.attestation)}}catch($){this.logger.warn($)}};u.body.appendChild(y),window.addEventListener("message",m,{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(dc(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 fA.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=FI(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=Uu(),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 cD=Object.defineProperty,uD=(t,e,n)=>e in t?cD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Oy=(t,e,n)=>uD(t,typeof e!="symbol"?e+"":e,n);class lD extends ym{constructor(e,n){super(e,n),this.projectId=e,this.logger=n,Oy(this,"context",hA),Oy(this,"registerDeviceToken",async r=>{const{clientId:i,token:s,notificationType:o,enableEncrypted:a=!1}=r,c=`${dA}/${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 fD=Object.defineProperty,Dy=Object.getOwnPropertySymbols,hD=Object.prototype.hasOwnProperty,dD=Object.prototype.propertyIsEnumerable,Ul=(t,e,n)=>e in t?fD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fs=(t,e)=>{for(var n in e||(e={}))hD.call(e,n)&&Ul(t,n,e[n]);if(Dy)for(var n of Dy(e))dD.call(e,n)&&Ul(t,n,e[n]);return t},Ue=(t,e,n)=>Ul(t,typeof e!="symbol"?e+"":e,n);class pD extends bm{constructor(e,n,r=!0){super(e,n,r),this.core=e,this.logger=n,Ue(this,"context",gA),Ue(this,"storagePrefix",un),Ue(this,"storageVersion",pA),Ue(this,"events",new Map),Ue(this,"shouldPersist",!1),Ue(this,"init",async()=>{if(!Uu())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)>yA&&(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(`${bA}?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 gD=Object.defineProperty,$y=Object.getOwnPropertySymbols,yD=Object.prototype.hasOwnProperty,bD=Object.prototype.propertyIsEnumerable,Fl=(t,e,n)=>e in t?gD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Py=(t,e)=>{for(var n in e||(e={}))yD.call(e,n)&&Fl(t,n,e[n]);if($y)for(var n of $y(e))bD.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 im{constructor(e){var n;super(e),we(this,"protocol",K1),we(this,"version",G1),we(this,"name",_a),we(this,"relayUrl"),we(this,"projectId"),we(this,"customStoragePrefix"),we(this,"events",new Ke.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||Y1,this.customStoragePrefix=e!=null&&e.customStoragePrefix?`:${e.customStoragePrefix}`:"";const i=Xw({level:typeof e?.logger=="string"&&e.logger?e.logger:L7.logger,name:_a}),{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 Fa,this.crypto=new VB(this,this.logger,e?.keychain),this.history=new tD(this,this.logger),this.expirer=new iD(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new dw(Py(Py({},k7),e?.storageOptions)),this.relayer=new wO({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new JO(this,this.logger),this.verify=new aD(this,this.logger,this.storage),this.echoClient=new lD(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new pD(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(Q7,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(X1,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(X1)||[],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,Ty="wc",Ry=2,Ny="client",ql=`${Ty}@${Ry}:${Ny}:`,Ml={name:Ny,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.org"},Cy="WALLETCONNECT_DEEPLINK_CHOICE",wD="proposal",Uy="Proposal expired",mD="session",Ni=K.SEVEN_DAYS,vD="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"},ED={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:""}},xD="request",_D=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],SD="wc",ID="auth",AD="authKeys",BD="pairingTopics",OD="requests",Aa=`${SD}@${1.5}:${ID}:`,Ba=`${Aa}:PUB_KEY`;var DD=Object.defineProperty,$D=Object.defineProperties,PD=Object.getOwnPropertyDescriptors,Fy=Object.getOwnPropertySymbols,TD=Object.prototype.hasOwnProperty,RD=Object.prototype.propertyIsEnumerable,zl=(t,e,n)=>e in t?DD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,le=(t,e)=>{for(var n in e||(e={}))TD.call(e,n)&&zl(t,n,e[n]);if(Fy)for(var n of Fy(e))RD.call(e,n)&&zl(t,n,e[n]);return t},He=(t,e)=>$D(t,PD(e)),H=(t,e,n)=>zl(t,typeof e!="symbol"?e+"":e,n);class ND extends Em{constructor(e){super(e),H(this,"name",vD),H(this,"events",new Ke.exports),H(this,"initialized",!1),H(this,"requestQueue",{state:hn.idle,queue:[]}),H(this,"sessionRequestQueue",{state:hn.idle,queue:[]}),H(this,"emittedSessionRequests",new Y_({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=>{var r;this.isInitialized(),await this.confirmOnlineStateOrThrow();const i=He(le({},n),{requiredNamespaces:n.requiredNamespaces||{},optionalNamespaces:n.optionalNamespaces||{}});await this.isValidConnect(i),i.optionalNamespaces=a9(i.requiredNamespaces,i.optionalNamespaces),i.requiredNamespaces={};const{pairingTopic:s,requiredNamespaces:o,optionalNamespaces:a,sessionProperties:c,scopedProperties:u,relays:l,authentication:f,walletPay:d}=i,h=((r=f?.[0])==null?void 0:r.ttl)||ze.wc_sessionPropose.req.ttl||K.FIVE_MINUTES;this.validateRequestExpiry(h);let p=s,y,m=!1;try{if(p){const D=this.client.core.pairing.pairings.get(p);this.client.logger.warn("connect() with existing pairing topic is deprecated and will be removed in the next major release."),m=D.active}}catch(D){throw this.client.logger.error(`connect() -> pairing.get(${p}) failed`),D}if(!p||!m){const{topic:D,uri:j}=await this.client.core.pairing.create({internal:{skipSubscribe:!0}});p=D,y=j}if(!p){const{message:D}=G("NO_MATCHING_KEY",`connect() pairing topic: ${p}`);throw new Error(D)}const B=await this.client.core.crypto.generateKeyPair(),$=De(h),_=le(He(le(le({requiredNamespaces:o,optionalNamespaces:a,relays:l??[{protocol:Z1}],proposer:{publicKey:B,metadata:this.client.metadata},expiryTimestamp:$,pairingTopic:p},c&&{sessionProperties:c}),u&&{scopedProperties:u}),{id:an()}),(f||d)&&{requests:{authentication:f?.map(D=>{const{domain:j,chains:M,nonce:E,uri:b,exp:v,nbf:g,type:w,statement:S,requestId:A,resources:I,signatureTypes:O}=D;return{domain:j,chains:M,nonce:E,type:w??"caip122",aud:b,version:"1",iat:new Date().toISOString(),exp:v,nbf:g,statement:S,requestId:A,resources:I,signatureTypes:O}}),walletPay:d}}),x=he("session_connect",_.id),{reject:P,resolve:R,done:U}=jr(h,Uy),F=({id:D})=>{D===_.id&&(this.client.events.off("proposal_expire",F),this.pendingSessions.delete(_.id),this.events.emit(x,{error:{message:Uy,code:0}}))};return this.client.events.on("proposal_expire",F),this.events.once(x,({error:D,session:j})=>{this.client.events.off("proposal_expire",F),D?P(D):j&&R(j)}),await this.setProposal(_.id,_),await this.sendProposeSession({proposal:_,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:{correlationId:_.id}}}).catch(D=>{throw this.deleteProposal(_.id),D}),{uri:y,approval:U}}),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(j){throw o.setError(Xr.no_internet_connection),j}try{await this.isValidProposalId(n?.id)}catch(j){throw this.client.logger.error(`approve() -> proposal.get(${n?.id}) failed`),o.setError(Xr.proposal_not_found),j}try{await this.isValidApprove(n)}catch(j){throw this.client.logger.error("approve() -> isValidApprove() failed"),o.setError(Xr.session_approve_namespace_validation_failure),j}const{id:a,relayProtocol:c,namespaces:u,sessionProperties:l,scopedProperties:f,sessionConfig:d,proposalRequestsResponses:h}=n,p=this.client.proposal.get(a);this.client.core.eventClient.deleteEvent({eventId:o.eventId});const{pairingTopic:y,proposer:m,requiredNamespaces:B,optionalNamespaces:$}=p;let _=(i=this.client.core.eventClient)==null?void 0:i.getEvent({topic:y});_||(_=(s=this.client.core.eventClient)==null?void 0:s.createEvent({type:Xt.session_approve_started,properties:{topic:y,trace:[Xt.session_approve_started,Xt.session_namespaces_validation_success]}}));const x=await this.client.core.crypto.generateKeyPair(),P=m.publicKey,R=await this.client.core.crypto.generateSharedKey(x,P),U=He(le(le(le({relay:{protocol:c??"irn"},namespaces:u,controller:{publicKey:x,metadata:this.client.metadata},expiry:De(Ni)},l&&{sessionProperties:l}),f&&{scopedProperties:f}),d&&{sessionConfig:d}),{proposalRequestsResponses:h}),F=me.relay;_.addTrace(Xt.subscribing_session_topic);try{await this.client.core.relayer.subscribe(R,{transportType:F,internal:{skipSubscribe:!0}})}catch(j){throw _.setError(Xr.subscribe_session_topic_failure),j}_.addTrace(Xt.subscribe_session_topic_success);const D=He(le({},U),{topic:R,requiredNamespaces:B,optionalNamespaces:$,pairingTopic:y,acknowledged:!1,self:U.controller,peer:{publicKey:m.publicKey,metadata:m.metadata},controller:x,transportType:me.relay,authentication:h?.authentication,walletPayResult:h?.walletPay});await this.client.session.set(R,D),_.addTrace(Xt.store_session);try{await this.sendApproveSession({sessionTopic:R,proposal:p,pairingProposalResponse:{relay:{protocol:c??"irn"},responderPublicKey:x},sessionSettleRequest:U,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:le({correlationId:a},this.getTVFApproveParams(D))}}),_.addTrace(Xt.session_approve_publish_success)}catch(j){throw this.client.logger.error(j),this.client.session.delete(R,Ee("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe(R),j}return this.client.core.eventClient.deleteEvent({eventId:_.eventId}),await this.client.core.pairing.updateMetadata({topic:y,metadata:m.metadata}),await this.deleteProposal(a),await this.client.core.pairing.activate({topic:y}),await this.setExpiry(R,De(Ni)),{topic:R,acknowledged:()=>Promise.resolve(this.client.session.get(R))}}),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(K.FIVE_MINUTES,"Session update request expired without receiving any acknowledgement"),c=an(),u=Er().toString(),l=this.client.session.get(r).namespaces;return this.events.once(he("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(K.FIVE_MINUTES,"Session extend request expired without receiving any acknowledgement");return this.events.once(he("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(m){throw this.client.logger.error("request() -> isValidRequest() failed"),m}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(he("session_request",c),({error:m,result:B})=>{m?d(m):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:He(le({},i),{expiryTimestamp:De(o)}),chainId:r},expiry:o,throwOnFailedPublish:!0,appLink:p}).catch(m=>d(m)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:r,id:c}),await l();const y={request:He(le({},i),{expiryTimestamp:De(o)}),chainId:r};return await Promise.all([new Promise(async m=>{await this.sendRequest({clientRpcId:c,relayRpcId:u,topic:s,method:h,params:y,expiry:o,throwOnFailedPublish:!0,tvf:this.getTVFParams(c,y)}).catch(B=>d(B)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:r,id:c}),m()}),new Promise(async m=>{var B;if(!((B=a.sessionConfig)!=null&&B.disableDeepLink)){const $=await V_(this.client.core.storage,Cy);await j_({id:c,topic:s,wcDeepLink:$})}m()}),l()]).then(m=>m[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(K.FIVE_MINUTES,"Ping request expired without receiving any acknowledgement");this.events.once(he("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=>l9(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:y=[],expiry:m}=n,B=[...n.resources||[]],{topic:$,uri:_}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:o});this.client.logger.info({message:"Generated new pairing",pairing:{topic:$,uri:_}});const x=await this.client.core.crypto.generateKeyPair(),P=ba(x);if(await Promise.all([this.client.auth.authKeys.set(Ba,{responseTopic:P,publicKey:x}),this.client.auth.pairingTopics.set(P,{topic:P,pairingTopic:$})]),await this.client.core.relayer.subscribe(P,{transportType:o}),this.client.logger.info(`sending request to new pairing topic: ${$}`),y.length>0){const{namespace:I}=Zo(a[0]);let O=cS(I,"request",y);sa(B)&&(O=lS(O,B.pop())),B.push(O)}const R=m&&m>ze.wc_sessionAuthenticate.req.ttl?m: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(R)},F={eip155:{chains:a,methods:[...new Set(["personal_sign",...y])],events:["chainChanged","accountsChanged"]}},D={requiredNamespaces:{},optionalNamespaces:F,relays:[{protocol:"irn"}],pairingTopic:$,proposer:{publicKey:x,metadata:this.client.metadata},expiryTimestamp:De(ze.wc_sessionPropose.req.ttl),id:an()},{done:j,resolve:M,reject:E}=jr(R,"Request expired"),b=an(),v=he("session_connect",D.id),g=he("session_request",b),w=async({error:I,session:O})=>{this.events.off(g,S),I?E(I):O&&M({session:O})},S=async I=>{var O,T,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(v,w),E(I.error.message))}await this.deleteProposal(D.id),this.events.off(v,w);const{cacaos:C,responder:k}=I.result,N=[],q=[];for(const V of C){await pg({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=sa(Z.resources),ee=[Hu(Z.iss)],ie=ia(Z.iss);if(Q){const fe=bg(Q),ve=wg(Q);N.push(...fe),ee.push(...ve)}for(const fe of ee)q.push(`${fe}:${ie}`)}const z=await this.client.core.crypto.generateSharedKey(x,k.publicKey);let W;N.length>0&&(W={topic:z,acknowledged:!0,self:{publicKey:x,metadata:this.client.metadata},peer:k,controller:k.publicKey,expiry:De(Ni),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:$,namespaces:A1([...new Set(N)],[...new Set(q)]),transportType:o},await this.client.core.relayer.subscribe(z,{transportType:o}),await this.client.session.set(z,W),$&&await this.client.core.pairing.updateMetadata({topic:$,metadata:k.metadata}),W=this.client.session.get(z)),(O=this.client.metadata.redirect)!=null&&O.linkMode&&(T=k.metadata.redirect)!=null&&T.linkMode&&(L=k.metadata.redirect)!=null&&L.universal&&r&&(this.client.core.addLinkModeSupportedApp(k.metadata.redirect.universal),this.client.session.update(z,{transportType:me.link_mode})),M({auths:C,session:W})};this.events.once(v,w),this.events.once(g,S);let A;try{if(s){const I=Un("wc_sessionAuthenticate",U,b);this.client.core.history.set($,I);const O=await this.client.core.crypto.encode("",I,{type:_s,encoding:vr});A=ma(r,$,O)}else await Promise.all([this.sendRequest({topic:$,method:"wc_sessionAuthenticate",params:U,expiry:n.expiry,throwOnFailedPublish:!0,clientRpcId:b}),this.sendRequest({topic:$,method:"wc_sessionPropose",params:D,expiry:ze.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:D.id})])}catch(I){throw this.events.off(v,w),this.events.off(g,S),I}return await this.setProposal(D.id,D),await this.setAuthRequest(b,{request:He(le({},U),{verifyContext:{}}),pairingTopic:$,transportType:o}),{uri:A??_,response:j}}),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(m){throw s.setError(Ts.no_internet_connection),m}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=ba(c),f={type:Rn,receiverPublicKey:c,senderPublicKey:u},d=[],h=[];for(const m of i){if(!await pg({cacao:m,projectId:this.client.core.projectId})){s.setError(Ts.invalid_cacao);const P=Ee("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:r,topic:l,error:P,encodeOpts:f}),new Error(P.message)}s.addTrace(Jr.cacaos_verified);const{p:B}=m,$=sa(B.resources),_=[Hu(B.iss)],x=ia(B.iss);if($){const P=bg($),R=wg($);d.push(...P),_.push(...R)}for(const P of _)h.push(`${P}:${x}`)}const p=await this.client.core.crypto.generateSharedKey(u,c);s.addTrace(Jr.create_authenticated_session_topic);let y;if(d?.length>0){y={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:A1([...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(m){throw s.setError(Ts.subscribe_authenticated_session_topic_failure),m}s.addTrace(Jr.subscribe_authenticated_session_topic_success),await this.client.session.set(p,y),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(m){throw s.setError(Ts.authenticated_session_approve_publish_failure),m}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:y}}),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=ba(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 gg(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(Cy).catch(u=>this.client.logger.warn(u)),i===((r=this.sessionRequestQueue.queue[0])==null?void 0:r.topic)&&(this.sessionRequestQueue.state=hn.idle),await Promise.all(this.getPendingSessionRequests().filter(u=>u.topic===i).map(u=>this.deletePendingSessionRequest(u.id,Ee("USER_DISCONNECTED")))),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 y=!!l;try{const $=y?vr:vt;p=await this.client.core.crypto.encode(r,h,{encoding:$})}catch($){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${r} failed`),$}let m;if(_D.includes(i)){const $=Ft(JSON.stringify(h)),_=Ft(p);m=await this.client.core.verify.register({id:_,decryptedId:$})}const B=le(le({},ze[i].req),d);if(B.attestation=m,o&&(B.ttl=o),a&&(B.id=a),this.client.core.history.set(r,h),y){const $=ma(l,r,p);await global.Linking.openURL($,this.client.name)}else B.tvf=He(le({},f),{correlationId:h.id}),u?(B.internal=He(le({},B.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(r,p,B)):this.client.core.relayer.publish(r,p,B).catch($=>this.client.logger.error($));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:He(le({},i),{publishMethod:"wc_proposeSession",attestation:u})})}),H(this,"sendApproveSession",async n=>{const{sessionTopic:r,pairingProposalResponse:i,proposal:s,sessionSettleRequest:o,publishOpts:a}=n,c=Ea(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:He(le({},a),{publishMethod:"wc_approveSession"})})}),H(this,"sendResult",async n=>{const{id:r,topic:i,result:s,throwOnFailedPublish:o,encodeOpts:a,appLink:c}=n,u=Ea(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,He(le({},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(y){this.client.logger.warn(`sendResult() -> getTVFParams() failed: ${y?.message}`)}}catch(p){throw this.client.logger.error(`sendResult() -> history.get(${i}, ${r}) failed`),p}if(f){const p=ma(c,i,l);await global.Linking.openURL(p,this.client.name)}else{const p=d.request.method,y=ze[p].res;y.tvf=He(le({},h),{correlationId:r}),o?(y.internal=He(le({},y.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(i,l,y)):this.client.core.relayer.publish(i,l,y).catch(m=>this.client.logger.error(m))}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,He(le({},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=ma(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(le({},i.params));const l=a.expiryTimestamp||De(ze.wc_sessionPropose.req.ttl),f=le({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=he("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,proposalRequestsResponses:h}=r.params,p=[...this.pendingSessions.values()].find(B=>B.sessionTopic===n);if(!p)return this.client.logger.error(`Pending session not found for topic ${n}`);const y=this.client.proposal.get(p.proposalId),m=He(le(le(le({topic:n,relay:o,expiry:c,namespaces:u,acknowledged:!0,pairingTopic:p.pairingTopic,requiredNamespaces:y.requiredNamespaces,optionalNamespaces:y.optionalNamespaces,controller:a.publicKey,self:{publicKey:p.publicKey,metadata:this.client.metadata},peer:{publicKey:a.publicKey,metadata:a.metadata}},l&&{sessionProperties:l}),f&&{scopedProperties:f}),d&&{sessionConfig:d}),{transportType:me.relay,authentication:h?.authentication,walletPayResult:h?.walletPay});await this.client.session.set(m.topic,m),await this.setExpiry(m.topic,m.expiry),await this.client.core.pairing.updateMetadata({topic:p.pairingTopic,metadata:m.peer.metadata}),this.pendingSessions.delete(p.proposalId),this.deleteProposal(p.proposalId,!1),this.cleanupDuplicatePairings(m),await this.sendResult({id:r.id,topic:n,throwOnFailedPublish:!0,result:!0}),this.client.events.emit("session_connect",{session:m}),this.events.emit(he("session_connect",p.proposalId),{session:m})}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(he("session_approve",i),{})):Lt(r)&&(await this.client.session.delete(n,Ee("USER_DISCONNECTED")),this.events.emit(he("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(le({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=he("session_update",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);cn(r)?this.events.emit(he("session_update",i),{}):Lt(r)&&this.events.emit(he("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=he("session_extend",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);cn(r)?this.events.emit(he("session_extend",i),{}):Lt(r)&&this.events.emit(he("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=he("session_ping",i);setTimeout(()=>{if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners 2176`);cn(r)?this.events.emit(he("session_ping",i),{}):Lt(r)&&this.events.emit(he("session_ping",i),{error:r.error})},500)}),H(this,"onSessionDeleteRequest",async(n,r)=>{const{id:i}=r;try{await this.isValidDisconnect({topic:n,reason:r.params}),this.cleanupPendingSentRequestsForTopic({topic:n,error:Ee("USER_DISCONNECTED")}),await this.deleteSession({topic:n,id:i})}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(le({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}),y={id:f,topic:o,params:d,verifyContext:p};await this.setPendingSessionRequest(y),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(y):(this.addSessionRequestToSessionRequestQueue(y),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=he("session_request",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);cn(r)?this.events.emit(he("session_request",i),{result:r.result}):Lt(r)&&this.events.emit(he("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(le({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(he("session_request",i),{result:r.result}):Lt(r)&&this.events.emit(he("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=>{this.events.emit(he("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",He(le({},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),!x9(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=E9(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=P1(c.requiredNamespaces,i,"approve()");if(l)throw new Error(l.message);if(!Se(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),!S9(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(!D1(r)){const{message:u}=G("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(u)}const a=g9(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=P1(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(!$1(a,s)){const{message:c}=G("MISSING_OR_INVALID",`request() chainId: ${s}`);throw new Error(c)}if(!I9(i)){const{message:c}=G("MISSING_OR_INVALID",`request() ${JSON.stringify(i)}`);throw new Error(c)}if(!O9(a,s,i.method)){const{message:c}=G("MISSING_OR_INVALID",`request() method: ${i.method}`);throw new Error(c)}this.validateRequestExpiry(o)}),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(!A9(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(!$1(o,s)){const{message:a}=G("MISSING_OR_INVALID",`emit() chainId: ${s}`);throw new Error(a)}if(!B9(i)){const{message:a}=G("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}if(!D9(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(!Se(i,!1))throw new Error("uri is required parameter");if(!Se(s,!1))throw new Error("domain is required parameter");if(!Se(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(Uu()||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,"getTVFApproveParams",n=>{try{const r=_1(n.namespaces),i=t9(n.namespaces),s=n9(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"),{}}}),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=ED[s];if(s==="sui_signTransaction")return[z5(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[G9({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[V5(r)];if(s==="wallet_sendCalls")return K5(r);if(typeof r=="string")return[r];const a=r[o.key];if(Pi(a))return s==="solana_signAllTransactions"?a.map(c=>j5(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(Ie.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(Ba)?this.client.auth.authKeys.get(Ba):{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)})):xa(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(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(!Se(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(!Se(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(Se(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(!_9(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)}}validateRequestExpiry(e){if(e&&!T9(e,jl)){const{message:n}=G("MISSING_OR_INVALID",`request() expiry: ${e}. Expiry must be a number (in seconds) between ${jl.min} and ${jl.max}`);throw new Error(n)}}}class CD extends Qr{constructor(e,n){super(e,n,wD,ql),this.core=e,this.logger=n}}class Ly extends Qr{constructor(e,n){super(e,n,mD,ql),this.core=e,this.logger=n}}class UD extends Qr{constructor(e,n){super(e,n,xD,ql,r=>r.id),this.core=e,this.logger=n}}class FD extends Qr{constructor(e,n){super(e,n,AD,Aa,()=>Ba),this.core=e,this.logger=n}}class LD extends Qr{constructor(e,n){super(e,n,BD,Aa),this.core=e,this.logger=n}}class kD extends Qr{constructor(e,n){super(e,n,OD,Aa,r=>r.id),this.core=e,this.logger=n}}var qD=Object.defineProperty,MD=(t,e,n)=>e in t?qD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Hl=(t,e,n)=>MD(t,typeof e!="symbol"?e+"":e,n);class jD{constructor(e,n){this.core=e,this.logger=n,Hl(this,"authKeys"),Hl(this,"pairingTopics"),Hl(this,"requests"),this.authKeys=new FD(this.core,this.logger),this.pairingTopics=new LD(this.core,this.logger),this.requests=new kD(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}var zD=Object.defineProperty,HD=(t,e,n)=>e in t?zD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oe=(t,e,n)=>HD(t,typeof e!="symbol"?e+"":e,n);class Vl extends vm{constructor(e){super(e),oe(this,"protocol",Ty),oe(this,"version",Ry),oe(this,"name",Ml.name),oe(this,"metadata"),oe(this,"core"),oe(this,"logger"),oe(this,"events",new Ke.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=U_(e?.metadata),this.signConfig=e?.signConfig;const n=N1({logger:e?.logger||Ml.logger,name:this.name});this.logger=n,this.core=e?.core||new kl(e),this.session=new Ly(this.core,this.logger),this.proposal=new CD(this.core,this.logger),this.pendingRequest=new UD(this.core,this.logger),this.engine=new ND(this),this.auth=new jD(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 VD=Ly,KD=Vl;class GD extends Ke.exports{constructor(){super()}}class ky{constructor(e){this.opts=e}}class qy{constructor(e){this.client=e}}var WD=Object.defineProperty,ZD=Object.defineProperties,YD=Object.getOwnPropertyDescriptors,My=Object.getOwnPropertySymbols,XD=Object.prototype.hasOwnProperty,JD=Object.prototype.propertyIsEnumerable,jy=(t,e,n)=>e in t?WD(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,QD=(t,e)=>{for(var n in e||(e={}))XD.call(e,n)&&jy(t,n,e[n]);if(My)for(var n of My(e))JD.call(e,n)&&jy(t,n,e[n]);return t},e$=(t,e)=>ZD(t,YD(e));class t$ extends qy{constructor(e){super(e),this.init=async()=>{this.signClient=await KD.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(e$(QD({},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)},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 n$={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 VD(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}},zy=class extends ky{constructor(t){super(t),this.events=new Ke.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||Da,this.signConfig=t.signConfig,this.core=t.core,this.logger=this.core.logger,this.engine=new t$(this)}static async init(t){const e=new zy(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=zy;Kl.notifications=n$;const r$=Kl;Ve.CLIENT_CONTEXT=Da,Ve.CLIENT_STORAGE_OPTIONS=sb,Ve.CLIENT_STORAGE_PREFIX=ib,Ve.IWalletKit=ky,Ve.IWalletKitEngine=qy,Ve.IWalletKitEvents=GD,Ve.PROTOCOL=of,Ve.PROTOCOL_VERSION=rb,Ve.REQUEST_CONTEXT=ob,Ve.WalletKit=r$,Ve.default=Kl,Object.defineProperty(Ve,"__esModule",{value:!0})});
40
+ ***************************************************************************** */var bh=function(t,e){return bh=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])},bh(t,e)};function AD(t,e){bh(t,e);function n(){this.constructor=t}t.prototype=e===null?Object.create(e):(n.prototype=e.prototype,new n)}var wh=function(){return wh=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},wh.apply(this,arguments)};function OD(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 DD(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 PD(t,e){return function(n,r){e(n,r,t)}}function RD(t,e){if(typeof Reflect=="object"&&typeof Reflect.metadata=="function")return Reflect.metadata(t,e)}function TD(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(u){try{f(r.next(u))}catch(h){o(h)}}function c(u){try{f(r.throw(u))}catch(h){o(h)}}function f(u){u.done?s(u.value):i(u.value).then(a,c)}f((r=r.apply(t,e||[])).next())})}function ND(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(u){return c([f,u])}}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(u){f=[6,u],i=0}finally{r=s=0}if(f[0]&5)throw f[1];return{value:f[0]?f[1]:void 0,done:!0}}}function UD(t,e,n,r){r===void 0&&(r=n),t[r]=e[n]}function CD(t,e){for(var n in t)n!=="default"&&!e.hasOwnProperty(n)&&(e[n]=t[n])}function mh(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 Ww(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 FD(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(Ww(arguments[e]));return t}function LD(){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 Lo(t){return this instanceof Lo?(this.v=t,this):new Lo(t)}function kD(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(l){r[l]&&(i[l]=function(d){return new Promise(function(p,b){s.push([l,d,p,b])>1||a(l,d)})})}function a(l,d){try{c(r[l](d))}catch(p){h(s[0][3],p)}}function c(l){l.value instanceof Lo?Promise.resolve(l.value.v).then(f,u):h(s[0][2],l)}function f(l){a("next",l)}function u(l){a("throw",l)}function h(l,d){l(d),s.shift(),s.length&&a(s[0][0],s[0][1])}}function qD(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:Lo(t[i](o)),done:i==="return"}:s?s(o):o}:s}}function MD(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 mh=="function"?mh(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 jD(t,e){return Object.defineProperty?Object.defineProperty(t,"raw",{value:e}):t.raw=e,t}function zD(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 HD(t){return t&&t.__esModule?t:{default:t}}function VD(t,e){if(!e.has(t))throw new TypeError("attempted to get private field on non-instance");return e.get(t)}function KD(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 GD=Object.freeze({__proto__:null,__extends:AD,get __assign(){return wh},__rest:OD,__decorate:DD,__param:PD,__metadata:RD,__awaiter:TD,__generator:ND,__createBinding:UD,__exportStar:CD,__values:mh,__read:Ww,__spread:FD,__spreadArrays:LD,__await:Lo,__asyncGenerator:kD,__asyncDelegator:qD,__asyncValues:MD,__makeTemplateObject:jD,__importStar:zD,__importDefault:HD,__classPrivateFieldGet:VD,__classPrivateFieldSet:KD}),ZD=Kh(GD),ar={},Yw;function WD(){if(Yw)return ar;Yw=1,Object.defineProperty(ar,"__esModule",{value:!0}),ar.isBrowserCryptoAvailable=ar.getSubtleCrypto=ar.getBrowerCrypto=void 0;function t(){return mn?.crypto||mn?.msCrypto||{}}ar.getBrowerCrypto=t;function e(){const r=t();return r.subtle||r.webkitSubtle}ar.getSubtleCrypto=e;function n(){return!!t()&&!!e()}return ar.isBrowserCryptoAvailable=n,ar}var cr={},Xw;function YD(){if(Xw)return cr;Xw=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=ZD;e.__exportStar(WD(),t),e.__exportStar(YD(),t)})(Zw);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 li(t=6){return BigInt(An(t))}function fr(t,e,n){return{id:n||An(),jsonrpc:"2.0",method:t,params:e}}function qc(t,e){return{id:t,jsonrpc:"2.0",result:e}}function vh(t,e,n){return{id:t,jsonrpc:"2.0",error:XD(e,n)}}function XD(t,e){return typeof t>"u"?Gw(Vw):(typeof t=="string"&&(t=Object.assign(Object.assign({},Gw(yh)),{message:t})),typeof e<"u"&&(t.data=e),SD(t.code)&&(t=BD(t.code)),t)}class JD{}class QD extends JD{constructor(){super()}}class eP extends QD{constructor(e){super()}}const tP="^wss?:";function nP(t){const e=t.match(new RegExp(/^\w+:/,"gi"));if(!(!e||!e.length))return e[0]}function rP(t,e){const n=nP(t);return typeof n>"u"?!1:new RegExp(e).test(n)}function Jw(t){return rP(t,tP)}function iP(t){return new RegExp("wss?://localhost(:d{2,5})?").test(t)}function Qw(t){return typeof t=="object"&&"id"in t&&"jsonrpc"in t&&t.jsonrpc==="2.0"}function Eh(t){return Qw(t)&&"method"in t}function Mc(t){return Qw(t)&&(On(t)||Qt(t))}function On(t){return"result"in t}function Qt(t){return"error"in t}class sP extends eP{constructor(e){super(e),this.events=new Qe.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(fr(e.method,e.params||[],e.id||li().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=>{Qt(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),Mc(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 oP=()=>typeof WebSocket<"u"?WebSocket:typeof global<"u"&&typeof global.WebSocket<"u"?global.WebSocket:typeof window<"u"&&typeof window.WebSocket<"u"?window.WebSocket:typeof self<"u"&&typeof self.WebSocket<"u"?self.WebSocket:require("ws"),aP=()=>typeof WebSocket<"u"||typeof global<"u"&&typeof global.WebSocket<"u"||typeof window<"u"&&typeof window.WebSocket<"u"||typeof self<"u"&&typeof self.WebSocket<"u",em=t=>t.split("?")[0],tm=10,cP=oP();class fP{constructor(e){if(this.url=e,this.events=new Qe.exports.EventEmitter,this.registering=!1,!Jw(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(to(e))}catch(n){this.onError(e.id,n)}}register(e=this.url){if(!Jw(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=Zw.isReactNative()?void 0:{rejectUnauthorized:!iP(e)},s=new cP(e,[],i);aP()?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"?fs(e.data):e.data;this.events.emit("payload",n)}onError(e,n){const r=this.parseError(n),i=r.message||r.toString(),s=vh(e,i);this.events.emit("payload",s)}parseError(e,n=this.url){return $D(e,em(n),"WS")}resetMaxListeners(){this.events.getMaxListeners()>tm&&this.events.setMaxListeners(tm)}emitError(e){const n=this.parseError(new Error(e?.message||`WebSocket connection failed for host: ${em(this.url)}`));return this.events.emit("register_error",n),n}}const nm="wc",rm=2,jc="core",Dn=`${nm}@2:${jc}:`,uP={name:jc,logger:"error"},lP={database:":memory:"},hP="crypto",im="client_ed25519_seed",dP=Z.ONE_DAY,pP="keychain",gP="0.3",yP="messages",bP="0.3",wP=Z.SIX_HOURS,mP="publisher",sm="irn",vP="error",om="wss://relay.walletconnect.org",EP="relayer",De={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"},xP="_subscription",en={payload:"payload",connect:"connect",disconnect:"disconnect",error:"error"},_P=.1,xh="2.23.3",_e={link_mode:"link_mode",relay:"relay"},zc={inbound:"inbound",outbound:"outbound"},IP="0.3",SP="WALLETCONNECT_CLIENT_ID",am="WALLETCONNECT_LINK_MODE_APPS",Ht={created:"subscription_created",deleted:"subscription_deleted",expired:"subscription_expired",disabled:"subscription_disabled",sync:"subscription_sync",resubscribed:"subscription_resubscribed"},BP="subscription",$P="0.3",AP="pairing",OP="0.3",ko={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}}},Mi={create:"pairing_create",expire:"pairing_expire",delete:"pairing_delete",ping:"pairing_ping"},bn={created:"history_created",updated:"history_updated",deleted:"history_deleted",sync:"history_sync"},DP="history",PP="0.3",RP="expirer",tn={created:"expirer_created",deleted:"expirer_deleted",expired:"expirer_expired",sync:"expirer_sync"},TP="0.3",NP="verify-api",UP="https://verify.walletconnect.com",cm="https://verify.walletconnect.org",qo=cm,CP=`${qo}/v3`,FP=[UP,cm],LP="echo",kP="https://echo.walletconnect.com",Pn={pairing_started:"pairing_started",pairing_uri_validation_success:"pairing_uri_validation_success",pairing_uri_not_expired:"pairing_uri_not_expired",store_new_pairing:"store_new_pairing",subscribing_pairing_topic:"subscribing_pairing_topic",subscribe_pairing_topic_success:"subscribe_pairing_topic_success",existing_pairing:"existing_pairing",pairing_not_expired:"pairing_not_expired",emit_inactive_pairing:"emit_inactive_pairing",emit_session_proposal:"emit_session_proposal",subscribing_to_pairing_topic:"subscribing_to_pairing_topic"},ur={no_wss_connection:"no_wss_connection",no_internet_connection:"no_internet_connection",malformed_pairing_uri:"malformed_pairing_uri",active_pairing_already_exists:"active_pairing_already_exists",subscribe_pairing_topic_failure:"subscribe_pairing_topic_failure",pairing_expired:"pairing_expired",proposal_expired:"proposal_expired",proposal_listener_not_found:"proposal_listener_not_found"},wn={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"},ji={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"},zi={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"},Mo={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"},qP=.1,MP="event-client",jP=86400,zP="https://pulse.walletconnect.org/batch";function HP(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),u=Math.log(256)/Math.log(a);function h(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 b=0,v=0,O=0,P=p.length;O!==P&&p[O]===0;)O++,b++;for(var x=(P-O)*u+1>>>0,S=new Uint8Array(x);O!==P;){for(var R=p[O],U=0,L=x-1;(R!==0||U<v)&&L!==-1;L--,U++)R+=256*S[L]>>>0,S[L]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");v=U,O++}for(var C=x-v;C!==x&&S[C]===0;)C++;for(var A=c.repeat(b);C<x;++C)A+=t.charAt(S[C]);return A}function l(p){if(typeof p!="string")throw new TypeError("Expected String");if(p.length===0)return new Uint8Array;var b=0;if(p[b]!==" "){for(var v=0,O=0;p[b]===c;)v++,b++;for(var P=(p.length-b)*f+1>>>0,x=new Uint8Array(P);p[b];){var S=n[p.charCodeAt(b)];if(S===255)return;for(var R=0,U=P-1;(S!==0||R<O)&&U!==-1;U--,R++)S+=a*x[U]>>>0,x[U]=S%256>>>0,S=S/256>>>0;if(S!==0)throw new Error("Non-zero carry");O=R,b++}if(p[b]!==" "){for(var L=P-O;L!==P&&x[L]===0;)L++;for(var C=new Uint8Array(v+(P-L)),A=v;L!==P;)C[A++]=x[L++];return C}}}function d(p){var b=l(p);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:h,decodeUnsafe:l,decode:d}}var VP=HP,KP=VP;const fm=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")},GP=t=>new TextEncoder().encode(t),ZP=t=>new TextDecoder().decode(t);class WP{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 YP{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 um(this,e)}}class XP{constructor(e){this.decoders=e}or(e){return um(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 um=(t,e)=>new XP({...t.decoders||{[t.prefix]:t},...e.decoders||{[e.prefix]:e}});class JP{constructor(e,n,r,i){this.name=e,this.prefix=n,this.baseEncode=r,this.baseDecode=i,this.encoder=new WP(e,n,r),this.decoder=new YP(e,n,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}}const Hc=({name:t,prefix:e,encode:n,decode:r})=>new JP(t,e,n,r),jo=({prefix:t,name:e,alphabet:n})=>{const{encode:r,decode:i}=KP(n,e);return Hc({prefix:t,name:e,encode:r,decode:s=>fm(i(s))})},QP=(t,e,n,r)=>{const i={};for(let u=0;u<e.length;++u)i[e[u]]=u;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 u=0;u<s;++u){const h=i[t[u]];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},eR=(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},We=({name:t,prefix:e,bitsPerChar:n,alphabet:r})=>Hc({prefix:e,name:t,encode(i){return eR(i,r,n)},decode(i){return QP(i,r,n,t)}}),tR=Hc({prefix:"\0",name:"identity",encode:t=>ZP(t),decode:t=>GP(t)});var nR=Object.freeze({__proto__:null,identity:tR});const rR=We({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var iR=Object.freeze({__proto__:null,base2:rR});const sR=We({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oR=Object.freeze({__proto__:null,base8:sR});const aR=jo({prefix:"9",name:"base10",alphabet:"0123456789"});var cR=Object.freeze({__proto__:null,base10:aR});const fR=We({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),uR=We({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var lR=Object.freeze({__proto__:null,base16:fR,base16upper:uR});const hR=We({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),dR=We({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pR=We({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),gR=We({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yR=We({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),bR=We({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),wR=We({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mR=We({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),vR=We({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ER=Object.freeze({__proto__:null,base32:hR,base32upper:dR,base32pad:pR,base32padupper:gR,base32hex:yR,base32hexupper:bR,base32hexpad:wR,base32hexpadupper:mR,base32z:vR});const xR=jo({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),_R=jo({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var IR=Object.freeze({__proto__:null,base36:xR,base36upper:_R});const SR=jo({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),BR=jo({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var $R=Object.freeze({__proto__:null,base58btc:SR,base58flickr:BR});const AR=We({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),OR=We({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),DR=We({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),PR=We({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var RR=Object.freeze({__proto__:null,base64:AR,base64pad:OR,base64url:DR,base64urlpad:PR});const lm=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}"),TR=lm.reduce((t,e,n)=>(t[n]=e,t),[]),NR=lm.reduce((t,e,n)=>(t[e.codePointAt(0)]=n,t),[]);function UR(t){return t.reduce((e,n)=>(e+=TR[n],e),"")}function CR(t){const e=[];for(const n of t){const r=NR[n.codePointAt(0)];if(r===void 0)throw new Error(`Non-base256emoji character: ${n}`);e.push(r)}return new Uint8Array(e)}const FR=Hc({prefix:"\u{1F680}",name:"base256emoji",encode:UR,decode:CR});var LR=Object.freeze({__proto__:null,base256emoji:FR}),kR=dm,hm=128,qR=127,MR=~qR,jR=Math.pow(2,31);function dm(t,e,n){e=e||[],n=n||0;for(var r=n;t>=jR;)e[n++]=t&255|hm,t/=128;for(;t&MR;)e[n++]=t&255|hm,t>>>=7;return e[n]=t|0,dm.bytes=n-r+1,e}var zR=_h,HR=128,pm=127;function _h(t,r){var n=0,r=r||0,i=0,s=r,o,a=t.length;do{if(s>=a)throw _h.bytes=0,new RangeError("Could not decode varint");o=t[s++],n+=i<28?(o&pm)<<i:(o&pm)*Math.pow(2,i),i+=7}while(o>=HR);return _h.bytes=s-r,n}var VR=Math.pow(2,7),KR=Math.pow(2,14),GR=Math.pow(2,21),ZR=Math.pow(2,28),WR=Math.pow(2,35),YR=Math.pow(2,42),XR=Math.pow(2,49),JR=Math.pow(2,56),QR=Math.pow(2,63),eT=function(t){return t<VR?1:t<KR?2:t<GR?3:t<ZR?4:t<WR?5:t<YR?6:t<XR?7:t<JR?8:t<QR?9:10},tT={encode:kR,decode:zR,encodingLength:eT},gm=tT;const ym=(t,e,n=0)=>(gm.encode(t,e,n),e),bm=t=>gm.encodingLength(t),Ih=(t,e)=>{const n=e.byteLength,r=bm(t),i=r+bm(n),s=new Uint8Array(i+n);return ym(t,s,0),ym(n,s,r),s.set(e,i),new nT(t,n,e,s)};class nT{constructor(e,n,r,i){this.code=e,this.size=n,this.digest=r,this.bytes=i}}const wm=({name:t,code:e,encode:n})=>new rT(t,e,n);class rT{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?Ih(this.code,n):n.then(r=>Ih(this.code,r))}else throw Error("Unknown type, must be binary type")}}const mm=t=>async e=>new Uint8Array(await crypto.subtle.digest(t,e)),iT=wm({name:"sha2-256",code:18,encode:mm("SHA-256")}),sT=wm({name:"sha2-512",code:19,encode:mm("SHA-512")});var oT=Object.freeze({__proto__:null,sha256:iT,sha512:sT});const vm=0,aT="identity",Em=fm;var cT=Object.freeze({__proto__:null,identity:{code:vm,name:aT,encode:Em,digest:t=>Ih(vm,Em(t))}});new TextEncoder,new TextDecoder;const xm={...nR,...iR,...oR,...cR,...lR,...ER,...IR,...$R,...RR,...LR};({...oT,...cT});function _m(t){return globalThis.Buffer!=null?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t}function fT(t=0){return globalThis.Buffer!=null&&globalThis.Buffer.allocUnsafe!=null?_m(globalThis.Buffer.allocUnsafe(t)):new Uint8Array(t)}function Im(t,e,n,r){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:n},decoder:{decode:r}}}const Sm=Im("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),Sh=Im("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=fT(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}),uT={utf8:Sm,"utf-8":Sm,hex:xm.base16,latin1:Sh,ascii:Sh,binary:Sh,...xm};function lT(t,e="utf8"){const n=uT[e];if(!n)throw new Error(`Unsupported encoding "${e}"`);return(e==="utf8"||e==="utf-8")&&globalThis.Buffer!=null&&globalThis.Buffer.from!=null?_m(globalThis.Buffer.from(t,"utf-8")):n.decoder.decode(`${n.prefix}${t}`)}var hT=Object.defineProperty,dT=(t,e,n)=>e in t?hT(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Rn=(t,e,n)=>dT(t,typeof e!="symbol"?e+"":e,n);class pT{constructor(e,n){this.core=e,this.logger=n,Rn(this,"keychain",new Map),Rn(this,"name",pP),Rn(this,"version",gP),Rn(this,"initialized",!1),Rn(this,"storagePrefix",Dn),Rn(this,"init",async()=>{if(!this.initialized){const r=await this.getKeyChain();typeof r<"u"&&(this.keychain=r),this.initialized=!0}}),Rn(this,"has",r=>(this.isInitialized(),this.keychain.has(r))),Rn(this,"set",async(r,i)=>{this.isInitialized(),this.keychain.set(r,i),await this.persist()}),Rn(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}),Rn(this,"del",async r=>{this.isInitialized(),this.keychain.delete(r),await this.persist()}),this.core=e,this.logger=Ft(n,this.name)}get context(){return xt(this.logger)}get storageKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//"+this.name}async setKeyChain(e){await this.core.storage.setItem(this.storageKey,Pl(e))}async getKeyChain(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Rl(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 gT=Object.defineProperty,yT=(t,e,n)=>e in t?gT(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Me=(t,e,n)=>yT(t,typeof e!="symbol"?e+"":e,n);class bT{constructor(e,n,r){this.core=e,this.logger=n,Me(this,"name",hP),Me(this,"keychain"),Me(this,"randomSessionIdentifier",uh()),Me(this,"initialized",!1),Me(this,"clientId"),Me(this,"init",async()=>{this.initialized||(await this.keychain.init(),this.initialized=!0)}),Me(this,"hasKeys",i=>(this.isInitialized(),this.keychain.has(i))),Me(this,"getClientId",async()=>{if(this.isInitialized(),this.clientId)return this.clientId;const i=await this.getClientSeed(),s=Fg(i),o=Cg(s.publicKey);return this.clientId=o,o}),Me(this,"generateKeyPair",()=>{this.isInitialized();const i=tO();return this.setPrivateKey(i.publicKey,i.privateKey)}),Me(this,"signJWT",async i=>{this.isInitialized();const s=await this.getClientSeed(),o=Fg(s),a=this.randomSessionIdentifier;return await x5(a,i,dP,o)}),Me(this,"generateSharedKey",(i,s,o)=>{this.isInitialized();const a=this.getPrivateKey(i),c=nO(a,s);return this.setSymKey(c,o)}),Me(this,"setSymKey",async(i,s)=>{this.isInitialized();const o=s||Cc(i);return await this.keychain.set(o,i),o}),Me(this,"deleteKeyPair",async i=>{this.isInitialized(),await this.keychain.del(i)}),Me(this,"deleteSymKey",async i=>{this.isInitialized(),await this.keychain.del(i)}),Me(this,"encode",async(i,s,o)=>{this.isInitialized();const a=Iw(o),c=to(s);if(Bw(a))return sO(c,o?.encoding);if(Sw(a)){const l=a.senderPublicKey,d=a.receiverPublicKey;i=await this.generateSharedKey(l,d)}const f=this.getSymKey(i),{type:u,senderPublicKey:h}=a;return rO({type:u,symKey:f,message:c,senderPublicKey:h,encoding:o?.encoding})}),Me(this,"decode",async(i,s,o)=>{this.isInitialized();const a=aO(s,o);if(Bw(a)){const c=oO(s,o?.encoding);return fs(c)}if(Sw(a)){const c=a.receiverPublicKey,f=a.senderPublicKey;i=await this.generateSharedKey(c,f)}try{const c=this.getSymKey(i),f=iO({symKey:c,encoded:s,encoding:o?.encoding});return fs(f)}catch(c){this.logger.error(`Failed to decode message from topic: '${i}', clientId: '${await this.getClientId()}'`),this.logger.error(c)}}),Me(this,"getPayloadType",(i,s=Nt)=>{const o=No({encoded:i,encoding:s});return qi(o.type)}),Me(this,"getPayloadSenderPublicKey",(i,s=Nt)=>{const o=No({encoded:i,encoding:s});return o.senderPublicKey?At(o.senderPublicKey,Et):void 0}),this.core=e,this.logger=Ft(n,this.name),this.keychain=r||new pT(this.core,this.logger)}get context(){return xt(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(im)}catch{e=uh(),await this.keychain.set(im,e)}return lT(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 wT=Object.defineProperty,mT=Object.defineProperties,vT=Object.getOwnPropertyDescriptors,Bm=Object.getOwnPropertySymbols,ET=Object.prototype.hasOwnProperty,xT=Object.prototype.propertyIsEnumerable,Bh=(t,e,n)=>e in t?wT(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,_T=(t,e)=>{for(var n in e||(e={}))ET.call(e,n)&&Bh(t,n,e[n]);if(Bm)for(var n of Bm(e))xT.call(e,n)&&Bh(t,n,e[n]);return t},IT=(t,e)=>mT(t,vT(e)),Vt=(t,e,n)=>Bh(t,typeof e!="symbol"?e+"":e,n);class ST extends rS{constructor(e,n){super(e,n),this.logger=e,this.core=n,Vt(this,"messages",new Map),Vt(this,"messagesWithoutClientAck",new Map),Vt(this,"name",yP),Vt(this,"version",bP),Vt(this,"initialized",!1),Vt(this,"storagePrefix",Dn),Vt(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}}}),Vt(this,"set",async(r,i,s)=>{this.isInitialized();const o=Jt(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===zc.inbound){const c=this.messagesWithoutClientAck.get(r)||{};this.messagesWithoutClientAck.set(r,IT(_T({},c),{[o]:i}))}return await this.persist(),o}),Vt(this,"get",r=>{this.isInitialized();let i=this.messages.get(r);return typeof i>"u"&&(i={}),i}),Vt(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}),Vt(this,"has",(r,i)=>{this.isInitialized();const s=this.get(r),o=Jt(i);return typeof s[o]<"u"}),Vt(this,"ack",async(r,i)=>{this.isInitialized();const s=this.messagesWithoutClientAck.get(r);if(typeof s>"u")return;const o=Jt(i);delete s[o],Object.keys(s).length===0?this.messagesWithoutClientAck.delete(r):this.messagesWithoutClientAck.set(r,s),await this.persist()}),Vt(this,"del",async r=>{this.isInitialized(),this.messages.delete(r),this.messagesWithoutClientAck.delete(r),await this.persist()}),this.logger=Ft(e,this.name),this.core=n}get context(){return xt(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,Pl(e))}async setRelayerMessagesWithoutClientAck(e){await this.core.storage.setItem(this.storageKeyWithoutClientAck,Pl(e))}async getRelayerMessages(){const e=await this.core.storage.getItem(this.storageKey);return typeof e<"u"?Rl(e):void 0}async getRelayerMessagesWithoutClientAck(){const e=await this.core.storage.getItem(this.storageKeyWithoutClientAck);return typeof e<"u"?Rl(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 BT=Object.defineProperty,$T=Object.defineProperties,AT=Object.getOwnPropertyDescriptors,$m=Object.getOwnPropertySymbols,OT=Object.prototype.hasOwnProperty,DT=Object.prototype.propertyIsEnumerable,$h=(t,e,n)=>e in t?BT(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ds=(t,e)=>{for(var n in e||(e={}))OT.call(e,n)&&$h(t,n,e[n]);if($m)for(var n of $m(e))DT.call(e,n)&&$h(t,n,e[n]);return t},Am=(t,e)=>$T(t,AT(e)),nn=(t,e,n)=>$h(t,typeof e!="symbol"?e+"":e,n);class PT extends iS{constructor(e,n){super(e,n),this.relayer=e,this.logger=n,nn(this,"events",new Qe.exports.EventEmitter),nn(this,"name",mP),nn(this,"queue",new Map),nn(this,"publishTimeout",Z.toMiliseconds(Z.ONE_MINUTE)),nn(this,"initialPublishTimeout",Z.toMiliseconds(Z.ONE_SECOND*15)),nn(this,"needsTransportRestart",!1),nn(this,"publish",async(r,i,s)=>{var o,a,c,f,u;this.logger.debug("Publishing Payload"),this.logger.trace({type:"method",method:"publish",params:{topic:r,message:i,opts:s}});const h=s?.ttl||wP,l=s?.prompt||!1,d=s?.tag||0,p=s?.id||li().toString(),b=$s(Fc().protocol),v={id:p,method:s?.publishMethod||b.publish,params:Ds({topic:r,message:i,ttl:h,prompt:l,tag:d,attestation:s?.attestation},s?.tvf)},O=`Failed to publish payload, please try again. id:${p} tag:${d}`;try{Fe((o=v.params)==null?void 0:o.prompt)&&((a=v.params)==null||delete a.prompt),Fe((c=v.params)==null?void 0:c.tag)&&((f=v.params)==null||delete f.tag);const P=new Promise(async x=>{const S=({id:U})=>{var L;((L=v.id)==null?void 0:L.toString())===U.toString()&&(this.removeRequestFromQueue(U),this.relayer.events.removeListener(De.publish,S),x())};this.relayer.events.on(De.publish,S);const R=Bn(new Promise((U,L)=>{this.rpcPublish(v,s).then(U).catch(C=>{this.logger.warn(C,C?.message),L(C)})}),this.initialPublishTimeout,`Failed initial publish, retrying.... id:${p} tag:${d}`);try{await R,this.events.removeListener(De.publish,S)}catch(U){this.queue.set(p,{request:v,opts:s,attempt:1}),this.logger.warn(U,U?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:p,topic:r,message:i,opts:s}}),await Bn(P,this.publishTimeout,O)}catch(P){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(P),(u=s?.internal)!=null&&u.throwOnFailedPublish)throw P}finally{this.queue.delete(p)}}),nn(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:u={}}=r,{attestation:h,tvf:l,publishMethod:d,prompt:p,tag:b,ttl:v=Z.FIVE_MINUTES}=u,O=u.id||li().toString(),P=$s(Fc().protocol),x=d||P.publish,S={id:O,method:x,params:Ds(Am(Ds({},f),{ttl:v,prompt:p,tag:b,attestation:h}),l)},R=`Failed to publish custom payload, please try again. id:${O} tag:${b}`;try{Fe((i=S.params)==null?void 0:i.prompt)&&((s=S.params)==null||delete s.prompt),Fe((o=S.params)==null?void 0:o.tag)&&((a=S.params)==null||delete a.tag);const U=new Promise(async L=>{const C=({id:j})=>{var q;((q=S.id)==null?void 0:q.toString())===j.toString()&&(this.removeRequestFromQueue(j),this.relayer.events.removeListener(De.publish,C),L())};this.relayer.events.on(De.publish,C);const A=Bn(new Promise((j,q)=>{this.rpcPublish(S,u).then(j).catch(E=>{this.logger.warn(E,E?.message),q(E)})}),this.initialPublishTimeout,`Failed initial custom payload publish, retrying.... method:${x} id:${O} tag:${b}`);try{await A,this.events.removeListener(De.publish,C)}catch(j){this.queue.set(O,{request:S,opts:u,attempt:1}),this.logger.warn(j,j?.message)}});this.logger.trace({type:"method",method:"publish",params:{id:O,payload:f,opts:u}}),await Bn(U,this.publishTimeout,R)}catch(U){if(this.logger.debug("Failed to Publish Payload"),this.logger.error(U),(c=u?.internal)!=null&&c.throwOnFailedPublish)throw U}finally{this.queue.delete(O)}}),nn(this,"on",(r,i)=>{this.events.on(r,i)}),nn(this,"once",(r,i)=>{this.events.once(r,i)}),nn(this,"off",(r,i)=>{this.events.off(r,i)}),nn(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),this.relayer=e,this.logger=Ft(n,this.name),this.registerEventListeners()}get context(){return xt(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(De.publish,Ds(Ds({},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,Am(Ds({},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(Di.pulse,()=>{if(this.needsTransportRestart){this.needsTransportRestart=!1,this.relayer.events.emit(De.connection_stalled);return}this.checkQueue()}),this.relayer.on(De.message_ack,e=>{this.removeRequestFromQueue(e.id.toString())})}}var RT=Object.defineProperty,TT=(t,e,n)=>e in t?RT(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ps=(t,e,n)=>TT(t,typeof e!="symbol"?e+"":e,n);class NT{constructor(){Ps(this,"map",new Map),Ps(this,"set",(e,n)=>{const r=this.get(e);this.exists(e,n)||this.map.set(e,[...r,n])}),Ps(this,"get",e=>this.map.get(e)||[]),Ps(this,"exists",(e,n)=>this.get(e).includes(n)),Ps(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)}),Ps(this,"clear",()=>{this.map.clear()})}get topics(){return Array.from(this.map.keys())}}var UT=Object.defineProperty,CT=Object.defineProperties,FT=Object.getOwnPropertyDescriptors,Om=Object.getOwnPropertySymbols,LT=Object.prototype.hasOwnProperty,kT=Object.prototype.propertyIsEnumerable,Ah=(t,e,n)=>e in t?UT(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,zo=(t,e)=>{for(var n in e||(e={}))LT.call(e,n)&&Ah(t,n,e[n]);if(Om)for(var n of Om(e))kT.call(e,n)&&Ah(t,n,e[n]);return t},Oh=(t,e)=>CT(t,FT(e)),ve=(t,e,n)=>Ah(t,typeof e!="symbol"?e+"":e,n);class qT extends aS{constructor(e,n){super(e,n),this.relayer=e,this.logger=n,ve(this,"subscriptions",new Map),ve(this,"topicMap",new NT),ve(this,"events",new Qe.exports.EventEmitter),ve(this,"name",BP),ve(this,"version",$P),ve(this,"pending",new Map),ve(this,"cached",[]),ve(this,"initialized",!1),ve(this,"storagePrefix",Dn),ve(this,"subscribeTimeout",Z.toMiliseconds(Z.ONE_MINUTE)),ve(this,"initialSubscribeTimeout",Z.toMiliseconds(Z.ONE_SECOND*15)),ve(this,"clientId"),ve(this,"batchSubscribeTopicsLimit",500),ve(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),this.registerEventListeners(),await this.restore()),this.initialized=!0}),ve(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=Fc(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}}),ve(this,"unsubscribe",async(r,i)=>{this.isInitialized(),typeof i?.id<"u"?await this.unsubscribeById(r,i.id,i):await this.unsubscribeByTopic(r,i)}),ve(this,"isSubscribed",r=>new Promise(i=>{i(this.topicMap.topics.includes(r))})),ve(this,"isKnownTopic",r=>new Promise(i=>{i(this.topicMap.topics.includes(r)||this.pending.has(r)||this.cached.some(s=>s.topic===r))})),ve(this,"on",(r,i)=>{this.events.on(r,i)}),ve(this,"once",(r,i)=>{this.events.once(r,i)}),ve(this,"off",(r,i)=>{this.events.off(r,i)}),ve(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),ve(this,"start",async()=>{await this.onConnect()}),ve(this,"stop",async()=>{await this.onDisconnect()}),ve(this,"restart",async()=>{await this.restore(),await this.onRestart()}),ve(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)}),ve(this,"registerEventListeners",()=>{this.relayer.core.heartbeat.on(Di.pulse,async()=>{await this.checkPending()}),this.events.on(Ht.created,async r=>{const i=Ht.created;this.logger.info(`Emitting ${i}`),this.logger.debug({type:"event",event:i,data:r}),await this.persist()}),this.events.on(Ht.deleted,async r=>{const i=Ht.deleted;this.logger.info(`Emitting ${i}`),this.logger.debug({type:"event",event:i,data:r}),await this.persist()})}),this.relayer=e,this.logger=Ft(n,this.name),this.clientId=""}get context(){return xt(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=Fc(r);await this.restartToComplete({topic:e,id:n,relay:i}),await this.rpcUnsubscribe(e,n,i);const s=Se("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===_e.relay)&&await this.restartToComplete({topic:e,id:e,relay:n});const a={method:$s(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===_e.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 l=d=>{d.topic===e&&(this.events.removeListener(Ht.created,l),h(d.id))};this.events.on(Ht.created,l);try{const d=await Bn(new Promise((p,b)=>{this.relayer.request(a).catch(v=>{this.logger.warn(v,v?.message),b(v)}).then(p)}),this.initialSubscribeTimeout,`Subscribing to ${e} failed, please try again`);this.events.removeListener(Ht.created,l),h(d)}catch{}}),u=await Bn(f,this.subscribeTimeout,`Subscribing to ${e} failed, please try again`);if(!u&&c)throw new Error(`Subscribing to ${e} failed, please try again`);return u?o:null}catch(f){if(this.logger.debug("Outgoing Relay Subscribe Payload stalled"),this.relayer.events.emit(De.connection_stalled),c)throw f}return null}async rpcBatchSubscribe(e){if(!e.length)return;const n=e[0].relay,r={method:$s(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 Bn(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(De.connection_stalled)}}async rpcBatchFetchMessages(e){if(!e.length)return;const n=e[0].relay,r={method:$s(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 Bn(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(De.connection_stalled)}return i}rpcUnsubscribe(e,n,r){const i={method:$s(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,Oh(zo({},n),{id:e})),this.pending.delete(n.topic)}onBatchSubscribe(e){e.length&&e.forEach(n=>{this.setSubscription(n.id,zo({},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,zo({},n)),this.topicMap.set(n.topic,e),this.events.emit(Ht.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(Ht.deleted,Oh(zo({},r),{reason:n}))}async persist(){await this.setRelayerSubscriptions(this.values),this.events.emit(Ht.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(Ht.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=>Oh(zo({},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 EB(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 Jt(e+await this.getClientId())}}var MT=Object.defineProperty,Dm=Object.getOwnPropertySymbols,jT=Object.prototype.hasOwnProperty,zT=Object.prototype.propertyIsEnumerable,Dh=(t,e,n)=>e in t?MT(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Pm=(t,e)=>{for(var n in e||(e={}))jT.call(e,n)&&Dh(t,n,e[n]);if(Dm)for(var n of Dm(e))zT.call(e,n)&&Dh(t,n,e[n]);return t},he=(t,e,n)=>Dh(t,typeof e!="symbol"?e+"":e,n);class HT extends sS{constructor(e){var n;super(e),he(this,"protocol","wc"),he(this,"version",2),he(this,"core"),he(this,"logger"),he(this,"events",new Qe.exports.EventEmitter),he(this,"provider"),he(this,"messages"),he(this,"subscriber"),he(this,"publisher"),he(this,"name",EP),he(this,"transportExplicitlyClosed",!1),he(this,"initialized",!1),he(this,"connectionAttemptInProgress",!1),he(this,"relayUrl"),he(this,"projectId"),he(this,"packageName"),he(this,"bundleId"),he(this,"hasExperiencedNetworkDisruption",!1),he(this,"pingTimeout"),he(this,"heartBeatTimeout",Z.toMiliseconds(Z.THIRTY_SECONDS+Z.FIVE_SECONDS)),he(this,"reconnectTimeout"),he(this,"connectPromise"),he(this,"reconnectInProgress",!1),he(this,"requestsInFlight",[]),he(this,"connectTimeout",Z.toMiliseconds(Z.ONE_SECOND*15)),he(this,"request",async r=>{var i,s;this.logger.debug("Publishing Request Payload");const o=r.id||li().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}}),he(this,"resetPingTimeout",()=>{gc()&&(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))}),he(this,"onPayloadHandler",r=>{this.onProviderPayload(r),this.resetPingTimeout()}),he(this,"onConnectHandler",()=>{this.logger.warn({},"Relayer connected \u{1F6DC}"),this.startPingTimeout(),this.events.emit(De.connect)}),he(this,"onDisconnectHandler",()=>{this.logger.warn({},"Relayer disconnected \u{1F6D1}"),this.requestsInFlight=[],this.onProviderDisconnect()}),he(this,"onProviderErrorHandler",r=>{this.logger.fatal(`Fatal socket error: ${r.message}`),this.events.emit(De.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))}),he(this,"registerProviderListeners",()=>{this.provider.on(en.payload,this.onPayloadHandler),this.provider.on(en.connect,this.onConnectHandler),this.provider.on(en.disconnect,this.onDisconnectHandler),this.provider.on(en.error,this.onProviderErrorHandler)}),this.core=e.core,this.logger=Hw({logger:(n=e.logger)!=null?n:vP,name:this.name}),this.messages=new ST(this.logger,e.core),this.subscriber=new qT(this,this.logger),this.publisher=new PT(this,this.logger),this.projectId=e?.projectId,this.relayUrl=e?.relayUrl||om,sB()?this.packageName=Ky():oB()&&(this.bundleId=Ky()),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 xt(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:_e.relay},zc.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=u=>{u.topic===e&&(this.subscriber.off(Ht.created,f),c())};return await Promise.all([new Promise(u=>{c=u,this.subscriber.on(Ht.created,f)}),new Promise(async(u,h)=>{a=await this.subscriber.subscribe(e,Pm({internal:{throwOnFailedPublish:o}},n)).catch(l=>{o&&h(l)})||a,u()})]),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 Bn(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 zw())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=Ue(Z.FIVE_MINUTES),s={topic:r,expiry:i,relay:{protocol:"irn"},active:!1};await this.core.pairing.pairings.set(r,s)}this.events.emit(De.message,e),await this.recordMessageEvent(e,zc.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(en.disconnect,s),await Bn(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(en.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(en.disconnect,c),await this.subscriber.start().then(o).catch(a).finally(()=>{this.provider.off(en.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(gc())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 sP(new fP(lB({sdkVersion:xh,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}),Eh(e)){if(!e.method.endsWith(xP))return;const n=e.params,{topic:r,message:i,publishedAt:s,attestation:o}=n.data,a={topic:r,message:i,publishedAt:s,transportType:_e.relay,attestation:o};this.logger.debug("Emitting Relayer Payload"),this.logger.trace(Pm({type:"event",event:n.id},a)),this.events.emit(n.id,a),await this.acknowledgePayload(e),await this.onMessageEvent(a)}else Mc(e)&&this.events.emit(De.message_ack,e)}async onMessageEvent(e){await this.shouldIgnoreMessageEvent(e)||(await this.recordMessageEvent(e,zc.inbound),this.events.emit(De.message,e))}async acknowledgePayload(e){const n=qc(e.id,!0);await this.provider.connection.send(n)}unregisterProviderListeners(){this.provider.off(en.payload,this.onPayloadHandler),this.provider.off(en.connect,this.onConnectHandler),this.provider.off(en.disconnect,this.onDisconnectHandler),this.provider.off(en.error,this.onProviderErrorHandler),clearTimeout(this.pingTimeout)}async registerEventListeners(){let e=await zw();cD(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(Di.pulse,async()=>{if(!this.transportExplicitlyClosed&&!this.connected&&lD())try{await this.confirmOnlineStateOrThrow(),await this.transportOpen()}catch(n){this.logger.warn(n,n?.message)}})}async onProviderDisconnect(){clearTimeout(this.pingTimeout),this.events.emit(De.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(_P)))))}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 VT(t,e){return t===e||Number.isNaN(t)&&Number.isNaN(e)}function Rm(t){return Object.getOwnPropertySymbols(t).filter(e=>Object.prototype.propertyIsEnumerable.call(t,e))}function Tm(t){return t==null?t===void 0?"[object Undefined]":"[object Null]":Object.prototype.toString.call(t)}const KT="[object RegExp]",GT="[object String]",ZT="[object Number]",WT="[object Boolean]",Nm="[object Arguments]",YT="[object Symbol]",XT="[object Date]",JT="[object Map]",QT="[object Set]",eN="[object Array]",tN="[object Function]",nN="[object ArrayBuffer]",Ph="[object Object]",rN="[object Error]",iN="[object DataView]",sN="[object Uint8Array]",oN="[object Uint8ClampedArray]",aN="[object Uint16Array]",cN="[object Uint32Array]",fN="[object BigUint64Array]",uN="[object Int8Array]",lN="[object Int16Array]",hN="[object Int32Array]",dN="[object BigInt64Array]",pN="[object Float32Array]",gN="[object Float64Array]";function yN(){}function Um(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 bN(t,e,n){return Ho(t,e,void 0,void 0,void 0,void 0,n)}function Ho(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 Vo(t,e,s,o)}return Vo(t,e,s,o)}function Vo(t,e,n,r){if(Object.is(t,e))return!0;let i=Tm(t),s=Tm(e);if(i===Nm&&(i=Ph),s===Nm&&(s=Ph),i!==s)return!1;switch(i){case GT:return t.toString()===e.toString();case ZT:{const c=t.valueOf(),f=e.valueOf();return VT(c,f)}case WT:case XT:case YT:return Object.is(t.valueOf(),e.valueOf());case KT:return t.source===e.source&&t.flags===e.flags;case tN: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 JT:{if(t.size!==e.size)return!1;for(const[c,f]of t.entries())if(!e.has(c)||!Ho(f,e.get(c),c,t,e,n,r))return!1;return!0}case QT:{if(t.size!==e.size)return!1;const c=Array.from(t.values()),f=Array.from(e.values());for(let u=0;u<c.length;u++){const h=c[u],l=f.findIndex(d=>Ho(h,d,void 0,t,e,n,r));if(l===-1)return!1;f.splice(l,1)}return!0}case eN:case sN:case oN:case aN:case cN:case fN:case uN:case lN:case hN:case dN:case pN:case gN:{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(!Ho(t[c],e[c],c,t,e,n,r))return!1;return!0}case nN:return t.byteLength!==e.byteLength?!1:Vo(new Uint8Array(t),new Uint8Array(e),n,r);case iN:return t.byteLength!==e.byteLength||t.byteOffset!==e.byteOffset?!1:Vo(new Uint8Array(t),new Uint8Array(e),n,r);case rN:return t.name===e.name&&t.message===e.message;case Ph:{if(!(Vo(t.constructor,e.constructor,n,r)||Um(t)&&Um(e)))return!1;const c=[...Object.keys(t),...Rm(t)],f=[...Object.keys(e),...Rm(e)];if(c.length!==f.length)return!1;for(let u=0;u<c.length;u++){const h=c[u],l=t[h];if(!Object.hasOwn(e,h))return!1;const d=e[h];if(!Ho(l,d,h,t,e,n,r))return!1}return!0}default:return!1}}finally{n.delete(t),n.delete(e)}}function wN(t,e){return bN(t,e,yN)}var mN=Object.defineProperty,Cm=Object.getOwnPropertySymbols,vN=Object.prototype.hasOwnProperty,EN=Object.prototype.propertyIsEnumerable,Rh=(t,e,n)=>e in t?mN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Fm=(t,e)=>{for(var n in e||(e={}))vN.call(e,n)&&Rh(t,n,e[n]);if(Cm)for(var n of Cm(e))EN.call(e,n)&&Rh(t,n,e[n]);return t},Ct=(t,e,n)=>Rh(t,typeof e!="symbol"?e+"":e,n);class Hi extends oS{constructor(e,n,r,i=Dn,s=void 0){super(e,n,r,i),this.core=e,this.logger=n,this.name=r,Ct(this,"map",new Map),Ct(this,"version",IP),Ct(this,"cached",[]),Ct(this,"initialized",!1),Ct(this,"getKey"),Ct(this,"storagePrefix",Dn),Ct(this,"recentlyDeleted",[]),Ct(this,"recentlyDeletedLimit",200),Ct(this,"init",async()=>{this.initialized||(this.logger.trace("Initialized"),await this.restore(),this.cached.forEach(o=>{this.getKey&&o!==null&&!Fe(o)?this.map.set(this.getKey(o),o):kO(o)?this.map.set(o.id,o):qO(o)&&this.map.set(o.topic,o)}),this.cached=[],this.initialized=!0)}),Ct(this,"set",async(o,a)=>{this.isInitialized(),this.map.has(o)?await this.update(o,a):(this.logger.debug("Setting value"),this.logger.trace({type:"method",method:"set",key:o,value:a}),this.map.set(o,a),await this.persist())}),Ct(this,"get",o=>(this.isInitialized(),this.logger.debug("Getting value"),this.logger.trace({type:"method",method:"get",key:o}),this.getData(o))),Ct(this,"getAll",o=>(this.isInitialized(),o?this.values.filter(a=>Object.keys(o).every(c=>wN(a[c],o[c]))):this.values)),Ct(this,"update",async(o,a)=>{this.isInitialized(),this.logger.debug("Updating value"),this.logger.trace({type:"method",method:"update",key:o,update:a});const c=Fm(Fm({},this.getData(o)),a);this.map.set(o,c),await this.persist()}),Ct(this,"delete",async(o,a)=>{this.isInitialized(),this.map.has(o)&&(this.logger.debug("Deleting value"),this.logger.trace({type:"method",method:"delete",key:o,reason:a}),this.map.delete(o),this.addToRecentlyDeleted(o),await this.persist())}),this.logger=Ft(n,this.name),this.storagePrefix=i,this.getKey=s}get context(){return xt(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 xN=Object.defineProperty,_N=(t,e,n)=>e in t?xN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,oe=(t,e,n)=>_N(t,typeof e!="symbol"?e+"":e,n);class IN{constructor(e,n){this.core=e,this.logger=n,oe(this,"name",AP),oe(this,"version",OP),oe(this,"events",new Qe.exports),oe(this,"pairings"),oe(this,"initialized",!1),oe(this,"storagePrefix",Dn),oe(this,"ignoredPayloadTypes",[or]),oe(this,"registeredMethods",[]),oe(this,"init",async()=>{this.initialized||(await this.pairings.init(),await this.cleanup(),this.registerRelayerEvents(),this.registerExpirerEvents(),this.initialized=!0,this.logger.trace("Initialized"))}),oe(this,"register",({methods:r})=>{this.isInitialized(),this.registeredMethods=[...new Set([...this.registeredMethods,...r])]}),oe(this,"create",async r=>{this.isInitialized();const i=uh(),s=await this.core.crypto.setSymKey(i),o=Ue(Z.FIVE_MINUTES),a={protocol:sm},c={topic:s,expiry:o,relay:a,active:!1,methods:r?.methods},f=Dw({protocol:this.core.protocol,version:this.core.version,topic:s,symKey:i,relay:a,expiryTimestamp:o,methods:r?.methods});return this.events.emit(Mi.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}}),oe(this,"pair",async r=>{this.isInitialized();const i=this.core.eventClient.createEvent({properties:{topic:r?.uri,trace:[Pn.pairing_started]}});this.isValidPair(r,i);const{topic:s,symKey:o,relay:a,expiryTimestamp:c,methods:f}=Ow(r.uri);i.props.properties.topic=s,i.addTrace(Pn.pairing_uri_validation_success),i.addTrace(Pn.pairing_uri_not_expired);let u;if(this.pairings.keys.includes(s)){if(u=this.pairings.get(s),i.addTrace(Pn.existing_pairing),u.active)throw i.setError(ur.active_pairing_already_exists),new Error(`Pairing already exists: ${s}. Please try again with a new connection URI.`);i.addTrace(Pn.pairing_not_expired)}const h=c||Ue(Z.FIVE_MINUTES),l={topic:s,relay:a,expiry:h,active:!1,methods:f};this.core.expirer.set(s,h),await this.pairings.set(s,l),i.addTrace(Pn.store_new_pairing),r.activatePairing&&await this.activate({topic:s}),this.events.emit(Mi.create,l),i.addTrace(Pn.emit_inactive_pairing),this.core.crypto.keychain.has(s)||await this.core.crypto.setSymKey(o,s),i.addTrace(Pn.subscribing_pairing_topic);try{await this.core.relayer.confirmOnlineStateOrThrow()}catch{i.setError(ur.no_internet_connection)}try{await this.core.relayer.subscribe(s,{relay:a})}catch(d){throw i.setError(ur.subscribe_pairing_topic_failure),d}return i.addTrace(Pn.subscribe_pairing_topic_success),l}),oe(this,"activate",async({topic:r})=>{this.isInitialized();const i=Ue(Z.FIVE_MINUTES);this.core.expirer.set(r,i),await this.pairings.update(r,{active:!0,expiry:i})}),oe(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}=Ti();this.events.once(pe("pairing_ping",s),({error:f})=>{f?c(f):a()}),await o()}}),oe(this,"updateExpiry",async({topic:r,expiry:i})=>{this.isInitialized(),await this.pairings.update(r,{expiry:i})}),oe(this,"updateMetadata",async({topic:r,metadata:i})=>{this.isInitialized(),await this.pairings.update(r,{peerMetadata:i})}),oe(this,"getPairings",()=>(this.isInitialized(),this.pairings.values)),oe(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",Se("USER_DISCONNECTED")),await this.deletePairing(i))}),oe(this,"formatUriFromPairing",r=>{this.isInitialized();const{topic:i,relay:s,expiry:o,methods:a}=r,c=this.core.crypto.keychain.get(i);return Dw({protocol:this.core.protocol,version:this.core.version,topic:i,symKey:c,relay:s,expiryTimestamp:o,methods:a})}),oe(this,"sendRequest",async(r,i,s)=>{const o=fr(i,s),a=await this.core.crypto.encode(r,o),c=ko[i].req;return this.core.history.set(r,o),this.core.relayer.publish(r,a,c),o.id}),oe(this,"sendResult",async(r,i,s)=>{const o=qc(r,s),a=await this.core.crypto.encode(i,o),c=(await this.core.history.get(i,r)).request.method,f=ko[c].res;await this.core.relayer.publish(i,a,f),await this.core.history.resolve(o)}),oe(this,"sendError",async(r,i,s)=>{const o=vh(r,s),a=await this.core.crypto.encode(i,o),c=(await this.core.history.get(i,r)).request.method,f=ko[c]?ko[c].res:ko.unregistered_method.res;await this.core.relayer.publish(i,a,f),await this.core.history.resolve(o)}),oe(this,"deletePairing",async(r,i)=>{await this.core.relayer.unsubscribe(r),await Promise.all([this.pairings.delete(r,Se("USER_DISCONNECTED")),this.core.crypto.deleteSymKey(r),i?Promise.resolve():this.core.expirer.del(r)])}),oe(this,"cleanup",async()=>{const r=this.pairings.getAll().filter(i=>Yr(i.expiry));await Promise.all(r.map(i=>this.deletePairing(i.topic)))}),oe(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)}}),oe(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)}}),oe(this,"onPairingPingRequest",async(r,i)=>{const{id:s}=i;try{this.isValidPing({topic:r}),await this.sendResult(s,r,!0),this.events.emit(Mi.ping,{id:s,topic:r})}catch(o){await this.sendError(s,r,o),this.logger.error(o)}}),oe(this,"onPairingPingResponse",(r,i)=>{const{id:s}=i;setTimeout(()=>{On(i)?this.events.emit(pe("pairing_ping",s),{}):Qt(i)&&this.events.emit(pe("pairing_ping",s),{error:i.error})},500)}),oe(this,"onPairingDeleteRequest",async(r,i)=>{const{id:s}=i;try{this.isValidDisconnect({topic:r}),await this.deletePairing(r),this.events.emit(Mi.delete,{id:s,topic:r})}catch(o){await this.sendError(s,r,o),this.logger.error(o)}}),oe(this,"onUnknownRpcMethodRequest",async(r,i)=>{const{id:s,method:o}=i;try{if(this.registeredMethods.includes(o))return;const a=Se("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)}}),oe(this,"onUnknownRpcMethodResponse",r=>{this.registeredMethods.includes(r)||this.logger.error(Se("WC_METHOD_UNSUPPORTED",r))}),oe(this,"isValidPair",(r,i)=>{var s;if(!Ut(r)){const{message:a}=W("MISSING_OR_INVALID",`pair() params: ${r}`);throw i.setError(ur.malformed_pairing_uri),new Error(a)}if(!LO(r.uri)){const{message:a}=W("MISSING_OR_INVALID",`pair() uri: ${r.uri}`);throw i.setError(ur.malformed_pairing_uri),new Error(a)}const o=Ow(r?.uri);if(!((s=o?.relay)!=null&&s.protocol)){const{message:a}=W("MISSING_OR_INVALID","pair() uri#relay-protocol");throw i.setError(ur.malformed_pairing_uri),new Error(a)}if(!(o!=null&&o.symKey)){const{message:a}=W("MISSING_OR_INVALID","pair() uri#symKey");throw i.setError(ur.malformed_pairing_uri),new Error(a)}if(o!=null&&o.expiryTimestamp&&Z.toMiliseconds(o?.expiryTimestamp)<Date.now()){i.setError(ur.pairing_expired);const{message:a}=W("EXPIRED","pair() URI has expired. Please try again with a new connection URI.");throw new Error(a)}}),oe(this,"isValidPing",async r=>{if(!Ut(r)){const{message:s}=W("MISSING_OR_INVALID",`ping() params: ${r}`);throw new Error(s)}const{topic:i}=r;await this.isValidPairingTopic(i)}),oe(this,"isValidDisconnect",async r=>{if(!Ut(r)){const{message:s}=W("MISSING_OR_INVALID",`disconnect() params: ${r}`);throw new Error(s)}const{topic:i}=r;await this.isValidPairingTopic(i)}),oe(this,"isValidPairingTopic",async r=>{if(!Oe(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(Yr(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=Ft(n,this.name),this.pairings=new Hi(this.core,this.logger,this.name,this.storagePrefix)}get context(){return xt(this.logger)}isInitialized(){if(!this.initialized){const{message:e}=W("NOT_INITIALIZED",this.name);throw new Error(e)}}registerRelayerEvents(){this.core.relayer.on(De.message,async e=>{const{topic:n,message:r,transportType:i}=e;if(this.pairings.keys.includes(n)&&i!==_e.link_mode&&!this.ignoredPayloadTypes.includes(this.core.crypto.getPayloadType(r)))try{const s=await this.core.crypto.decode(n,r);Eh(s)?(this.core.history.set(n,s),await this.onRelayEventRequest({topic:n,payload:s})):Mc(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(tn.expired,async e=>{const{topic:n}=Yy(e.target);n&&this.pairings.keys.includes(n)&&(await this.deletePairing(n,!0),this.events.emit(Mi.expire,{topic:n}))})}}var SN=Object.defineProperty,BN=(t,e,n)=>e in t?SN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ye=(t,e,n)=>BN(t,typeof e!="symbol"?e+"":e,n);class $N extends nS{constructor(e,n){super(e,n),this.core=e,this.logger=n,Ye(this,"records",new Map),Ye(this,"events",new Qe.exports.EventEmitter),Ye(this,"name",DP),Ye(this,"version",PP),Ye(this,"cached",[]),Ye(this,"initialized",!1),Ye(this,"storagePrefix",Dn),Ye(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)}),Ye(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:Ue(Z.THIRTY_DAYS)};this.records.set(o.id,o),this.persist(),this.events.emit(bn.created,o)}),Ye(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=Qt(r)?{error:r.error}:{result:r.result},this.records.set(i.id,i),this.persist(),this.events.emit(bn.updated,i))}),Ye(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))),Ye(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(bn.deleted,s)}}),this.persist()}),Ye(this,"exists",async(r,i)=>(this.isInitialized(),this.records.has(i)?(await this.getRecord(i)).topic===r:!1)),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)}),this.logger=Ft(n,this.name)}get context(){return xt(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:fr(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(bn.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(bn.created,e=>{const n=bn.created;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.events.on(bn.updated,e=>{const n=bn.updated;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.events.on(bn.deleted,e=>{const n=bn.deleted;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,record:e})}),this.core.heartbeat.on(Di.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(bn.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 AN=Object.defineProperty,ON=(t,e,n)=>e in t?AN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,dt=(t,e,n)=>ON(t,typeof e!="symbol"?e+"":e,n);class DN extends cS{constructor(e,n){super(e,n),this.core=e,this.logger=n,dt(this,"expirations",new Map),dt(this,"events",new Qe.exports.EventEmitter),dt(this,"name",RP),dt(this,"version",TP),dt(this,"cached",[]),dt(this,"initialized",!1),dt(this,"storagePrefix",Dn),dt(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)}),dt(this,"has",r=>{try{const i=this.formatTarget(r);return typeof this.getExpiration(i)<"u"}catch{return!1}}),dt(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(tn.created,{target:s,expiration:o})}),dt(this,"get",r=>{this.isInitialized();const i=this.formatTarget(r);return this.getExpiration(i)}),dt(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(tn.deleted,{target:i,expiration:s})}}),dt(this,"on",(r,i)=>{this.events.on(r,i)}),dt(this,"once",(r,i)=>{this.events.once(r,i)}),dt(this,"off",(r,i)=>{this.events.off(r,i)}),dt(this,"removeListener",(r,i)=>{this.events.removeListener(r,i)}),this.logger=Ft(n,this.name)}get context(){return xt(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 hB(e);if(typeof e=="number")return dB(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(tn.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(tn.expired,{target:e,expiration:n})}checkExpirations(){this.core.relayer.connected&&this.expirations.forEach((e,n)=>this.checkExpiry(n,e))}registerEventListeners(){this.core.heartbeat.on(Di.pulse,()=>this.checkExpirations()),this.events.on(tn.created,e=>{const n=tn.created;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:e}),this.persist()}),this.events.on(tn.expired,e=>{const n=tn.expired;this.logger.info(`Emitting ${n}`),this.logger.debug({type:"event",event:n,data:e}),this.persist()}),this.events.on(tn.deleted,e=>{const n=tn.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 PN=Object.defineProperty,RN=(t,e,n)=>e in t?PN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Pe=(t,e,n)=>RN(t,typeof e!="symbol"?e+"":e,n);class TN extends fS{constructor(e,n,r){super(e,n,r),this.core=e,this.logger=n,this.store=r,Pe(this,"name",NP),Pe(this,"abortController"),Pe(this,"isDevEnv"),Pe(this,"verifyUrlV3",CP),Pe(this,"storagePrefix",Dn),Pe(this,"version",rm),Pe(this,"publicKey"),Pe(this,"fetchPromise"),Pe(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()))}),Pe(this,"register",async i=>{if(!ms()||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=Un(),u=this.startAbortTimer(Z.ONE_SECOND*5),h=await new Promise((l,d)=>{const p=()=>{window.removeEventListener("message",v),f.body.removeChild(b),d("attestation aborted")};this.abortController.signal.addEventListener("abort",p);const b=f.createElement("iframe");b.src=c,b.style.display="none",b.addEventListener("error",p,{signal:this.abortController.signal});const v=O=>{if(O.data&&typeof O.data=="string")try{const P=JSON.parse(O.data);if(P.type==="verify_attestation"){if(Uu(P.attestation).payload.id!==o)return;clearInterval(u),f.body.removeChild(b),this.abortController.signal.removeEventListener("abort",p),window.removeEventListener("message",v),l(P.attestation===null?"":P.attestation)}}catch(P){this.logger.warn(P)}};f.body.appendChild(b),window.addEventListener("message",v,{signal:this.abortController.signal})});return this.logger.debug(h,"jwt attestation"),h}catch(f){this.logger.warn(f)}return""}),Pe(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(Uu(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)}),Pe(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}),Pe(this,"getVerifyUrl",i=>{let s=i||qo;return FP.includes(s)||(this.logger.info(`verify url: ${s}, not included in trusted list, assigning default: ${qo}`),s=qo),s}),Pe(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)}}),Pe(this,"persistPublicKey",async i=>{this.logger.debug(i,"persisting public key to local storage"),await this.store.setItem(this.storeKey,i),this.publicKey=i}),Pe(this,"removePublicKey",async()=>{this.logger.debug("removing verify v2 public key from storage"),await this.store.removeItem(this.storeKey),this.publicKey=void 0}),Pe(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")}}),Pe(this,"getPublicKey",async()=>this.publicKey?this.publicKey:await this.fetchAndPersistPublicKey()),Pe(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}),Pe(this,"validateAttestation",(i,s)=>{const o=fO(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=Ft(n,this.name),this.abortController=new AbortController,this.isDevEnv=Tl(),this.init()}get storeKey(){return this.storagePrefix+this.version+this.core.customStoragePrefix+"//verify:public:key"}get context(){return xt(this.logger)}startAbortTimer(e){return this.abortController=new AbortController,setTimeout(()=>this.abortController.abort(),Z.toMiliseconds(e))}}var NN=Object.defineProperty,UN=(t,e,n)=>e in t?NN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Lm=(t,e,n)=>UN(t,typeof e!="symbol"?e+"":e,n);class CN extends uS{constructor(e,n){super(e,n),this.projectId=e,this.logger=n,Lm(this,"context",LP),Lm(this,"registerDeviceToken",async r=>{const{clientId:i,token:s,notificationType:o,enableEncrypted:a=!1}=r,c=`${kP}/${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=Ft(n,this.context)}}var FN=Object.defineProperty,km=Object.getOwnPropertySymbols,LN=Object.prototype.hasOwnProperty,kN=Object.prototype.propertyIsEnumerable,Th=(t,e,n)=>e in t?FN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ko=(t,e)=>{for(var n in e||(e={}))LN.call(e,n)&&Th(t,n,e[n]);if(km)for(var n of km(e))kN.call(e,n)&&Th(t,n,e[n]);return t},je=(t,e,n)=>Th(t,typeof e!="symbol"?e+"":e,n);class qN extends lS{constructor(e,n,r=!0){super(e,n,r),this.core=e,this.logger=n,je(this,"context",MP),je(this,"storagePrefix",Dn),je(this,"storageVersion",qP),je(this,"events",new Map),je(this,"shouldPersist",!1),je(this,"init",async()=>{if(!Tl())try{const i={eventId:Jy(),timestamp:Date.now(),domain:this.getAppDomain(),props:{event:"INIT",type:"",properties:{client_id:await this.core.crypto.getClientId(),user_agent:Zy(this.core.relayer.protocol,this.core.relayer.version,xh)}}};await this.sendEvent([i])}catch(i){this.logger.warn(i)}}),je(this,"createEvent",i=>{const{event:s="ERROR",type:o="",properties:{topic:a,trace:c}}=i,f=Jy(),u=this.core.projectId||"",h=Date.now(),l=Ko({eventId:f,timestamp:h,props:{event:s,type:o,properties:{topic:a,trace:c}},bundleId:u,domain:this.getAppDomain()},this.setMethods(f));return this.telemetryEnabled&&(this.events.set(f,l),this.shouldPersist=!0),l}),je(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 Ko(Ko({},a),this.setMethods(a.eventId))}),je(this,"deleteEvent",i=>{const{eventId:s}=i;this.events.delete(s),this.shouldPersist=!0}),je(this,"setEventListeners",()=>{this.core.heartbeat.on(Di.pulse,async()=>{this.shouldPersist&&await this.persist(),this.events.forEach(i=>{Z.fromMiliseconds(Date.now())-Z.fromMiliseconds(i.timestamp)>jP&&(this.events.delete(i.eventId),this.shouldPersist=!0)})})}),je(this,"setMethods",i=>({addTrace:s=>this.addTrace(i,s),setError:s=>this.setError(i,s)})),je(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)}),je(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)}),je(this,"persist",async()=>{await this.core.storage.setItem(this.storageKey,Array.from(this.events.values())),this.shouldPersist=!1}),je(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,Ko(Ko({},s),this.setMethods(s.eventId)))})}catch(i){this.logger.warn(i)}}),je(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)}}),je(this,"sendEvent",async i=>{const s=this.getAppDomain()?"":"&sp=desktop";return await fetch(`${zP}?projectId=${this.core.projectId}&st=events_sdk&sv=js-${xh}${s}`,{method:"POST",body:JSON.stringify(i)})}),je(this,"getAppDomain",()=>Gy().url),this.logger=Ft(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 MN=Object.defineProperty,qm=Object.getOwnPropertySymbols,jN=Object.prototype.hasOwnProperty,zN=Object.prototype.propertyIsEnumerable,Nh=(t,e,n)=>e in t?MN(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Mm=(t,e)=>{for(var n in e||(e={}))jN.call(e,n)&&Nh(t,n,e[n]);if(qm)for(var n of qm(e))zN.call(e,n)&&Nh(t,n,e[n]);return t},xe=(t,e,n)=>Nh(t,typeof e!="symbol"?e+"":e,n);class Uh extends JI{constructor(e){var n;super(e),xe(this,"protocol",nm),xe(this,"version",rm),xe(this,"name",jc),xe(this,"relayUrl"),xe(this,"projectId"),xe(this,"customStoragePrefix"),xe(this,"events",new Qe.exports.EventEmitter),xe(this,"logger"),xe(this,"heartbeat"),xe(this,"relayer"),xe(this,"crypto"),xe(this,"storage"),xe(this,"history"),xe(this,"expirer"),xe(this,"pairing"),xe(this,"verify"),xe(this,"echoClient"),xe(this,"linkModeSupportedApps"),xe(this,"eventClient"),xe(this,"initialized",!1),xe(this,"logChunkController"),xe(this,"on",(a,c)=>this.events.on(a,c)),xe(this,"once",(a,c)=>this.events.once(a,c)),xe(this,"off",(a,c)=>this.events.off(a,c)),xe(this,"removeListener",(a,c)=>this.events.removeListener(a,c)),xe(this,"dispatchEnvelope",({topic:a,message:c,sessionExists:f})=>{if(!a||!c)return;const u={topic:a,message:c,publishedAt:Date.now(),transportType:_e.link_mode};this.relayer.onLinkMessageEvent(u,{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||om,this.customStoragePrefix=e!=null&&e.customStoragePrefix?`:${e.customStoragePrefix}`:"";const i=ef({level:typeof e?.logger=="string"&&e.logger?e.logger:uP.logger,name:jc}),{logger:s,chunkLoggerController:o}=pd({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=Ft(s,this.name),this.heartbeat=new vl,this.crypto=new bT(this,this.logger,e?.keychain),this.history=new $N(this,this.logger),this.expirer=new DN(this,this.logger),this.storage=e!=null&&e.storage?e.storage:new WI(Mm(Mm({},lP),e?.storageOptions)),this.relayer=new HT({core:this,logger:this.logger,relayUrl:this.relayUrl,projectId:this.projectId}),this.pairing=new IN(this,this.logger),this.verify=new TN(this,this.logger,this.storage),this.echoClient=new CN(this.projectId||"",this.logger),this.linkModeSupportedApps=[],this.eventClient=new qN(this,this.logger,e?.telemetryEnabled),this.setGlobalCore(this)}static async init(e){const n=new Uh(e);await n.initialize();const r=await n.crypto.getClientId();return await n.storage.setItem(SP,r),n}get context(){return xt(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(am,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(am)||[],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 Ch=Uh,jm="wc",zm=2,Hm="client",Fh=`${jm}@${zm}:${Hm}:`,Lh={name:Hm,logger:"error",controller:!1,relayUrl:"wss://relay.walletconnect.org"},Vm="WALLETCONNECT_DEEPLINK_CHOICE",HN="proposal",Km="Proposal expired",VN="session",Rs=Z.SEVEN_DAYS,KN="engine",Xe={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}}},kh={min:Z.FIVE_MINUTES,max:Z.SEVEN_DAYS},Tn={idle:"IDLE",active:"ACTIVE"},GN={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:""}},ZN="request",WN=["wc_sessionPropose","wc_sessionRequest","wc_authRequest","wc_sessionAuthenticate"],YN="wc",XN="auth",JN="authKeys",QN="pairingTopics",eU="requests",Vc=`${YN}@${1.5}:${XN}:`,Kc=`${Vc}:PUB_KEY`;var tU=Object.defineProperty,nU=Object.defineProperties,rU=Object.getOwnPropertyDescriptors,Gm=Object.getOwnPropertySymbols,iU=Object.prototype.hasOwnProperty,sU=Object.prototype.propertyIsEnumerable,qh=(t,e,n)=>e in t?tU(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,de=(t,e)=>{for(var n in e||(e={}))iU.call(e,n)&&qh(t,n,e[n]);if(Gm)for(var n of Gm(e))sU.call(e,n)&&qh(t,n,e[n]);return t},Je=(t,e)=>nU(t,rU(e)),V=(t,e,n)=>qh(t,typeof e!="symbol"?e+"":e,n);class oU extends gS{constructor(e){super(e),V(this,"name",KN),V(this,"events",new Qe.exports),V(this,"initialized",!1),V(this,"requestQueue",{state:Tn.idle,queue:[]}),V(this,"sessionRequestQueue",{state:Tn.idle,queue:[]}),V(this,"emittedSessionRequests",new xB({limit:500})),V(this,"requestQueueDelay",Z.ONE_SECOND),V(this,"expectedPairingMethodMap",new Map),V(this,"recentlyDeletedMap",new Map),V(this,"recentlyDeletedLimit",200),V(this,"relayMessageCache",[]),V(this,"pendingSessions",new Map),V(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(Xe)}),this.initialized=!0,setTimeout(async()=>{await this.processPendingMessageEvents(),this.sessionRequestQueue.queue=this.getPendingSessionRequests(),this.processSessionRequestQueue()},Z.toMiliseconds(this.requestQueueDelay)))}),V(this,"connect",async n=>{var r;this.isInitialized(),await this.confirmOnlineStateOrThrow();const i=Je(de({},n),{requiredNamespaces:n.requiredNamespaces||{},optionalNamespaces:n.optionalNamespaces||{}});await this.isValidConnect(i),i.optionalNamespaces=TO(i.requiredNamespaces,i.optionalNamespaces),i.requiredNamespaces={};const{pairingTopic:s,requiredNamespaces:o,optionalNamespaces:a,sessionProperties:c,scopedProperties:f,relays:u,authentication:h,walletPay:l}=i,d=((r=h?.[0])==null?void 0:r.ttl)||Xe.wc_sessionPropose.req.ttl||Z.FIVE_MINUTES;this.validateRequestExpiry(d);let p=s,b,v=!1;try{if(p){const A=this.client.core.pairing.pairings.get(p);this.client.logger.warn("connect() with existing pairing topic is deprecated and will be removed in the next major release."),v=A.active}}catch(A){throw this.client.logger.error(`connect() -> pairing.get(${p}) failed`),A}if(!p||!v){const{topic:A,uri:j}=await this.client.core.pairing.create({internal:{skipSubscribe:!0}});p=A,b=j}if(!p){const{message:A}=W("NO_MATCHING_KEY",`connect() pairing topic: ${p}`);throw new Error(A)}const O=await this.client.core.crypto.generateKeyPair(),P=Ue(d),x=de(Je(de(de({requiredNamespaces:o,optionalNamespaces:a,relays:u??[{protocol:sm}],proposer:{publicKey:O,metadata:this.client.metadata},expiryTimestamp:P,pairingTopic:p},c&&{sessionProperties:c}),f&&{scopedProperties:f}),{id:An()}),(h||l)&&{requests:{authentication:h?.map(A=>{const{domain:j,chains:q,nonce:E,uri:y,exp:w,nbf:g,type:m,statement:_,requestId:B,resources:I,signatureTypes:$}=A;return{domain:j,chains:q,nonce:E,type:m??"caip122",aud:y,version:"1",iat:new Date().toISOString(),exp:w,nbf:g,statement:_,requestId:B,resources:I,signatureTypes:$}}),walletPay:l}}),S=pe("session_connect",x.id),{reject:R,resolve:U,done:L}=Ti(d,Km),C=({id:A})=>{A===x.id&&(this.client.events.off("proposal_expire",C),this.pendingSessions.delete(x.id),this.events.emit(S,{error:{message:Km,code:0}}))};return this.client.events.on("proposal_expire",C),this.events.once(S,({error:A,session:j})=>{this.client.events.off("proposal_expire",C),A?R(A):j&&U(j)}),await this.setProposal(x.id,x),await this.sendProposeSession({proposal:x,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:{correlationId:x.id}}}).catch(A=>{throw this.deleteProposal(x.id),A}),{uri:b,approval:L}}),V(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}}),V(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:[wn.session_approve_started]}});try{this.isInitialized(),await this.confirmOnlineStateOrThrow()}catch(j){throw o.setError(ji.no_internet_connection),j}try{await this.isValidProposalId(n?.id)}catch(j){throw this.client.logger.error(`approve() -> proposal.get(${n?.id}) failed`),o.setError(ji.proposal_not_found),j}try{await this.isValidApprove(n)}catch(j){throw this.client.logger.error("approve() -> isValidApprove() failed"),o.setError(ji.session_approve_namespace_validation_failure),j}const{id:a,relayProtocol:c,namespaces:f,sessionProperties:u,scopedProperties:h,sessionConfig:l,proposalRequestsResponses:d}=n,p=this.client.proposal.get(a);this.client.core.eventClient.deleteEvent({eventId:o.eventId});const{pairingTopic:b,proposer:v,requiredNamespaces:O,optionalNamespaces:P}=p;let x=(i=this.client.core.eventClient)==null?void 0:i.getEvent({topic:b});x||(x=(s=this.client.core.eventClient)==null?void 0:s.createEvent({type:wn.session_approve_started,properties:{topic:b,trace:[wn.session_approve_started,wn.session_namespaces_validation_success]}}));const S=await this.client.core.crypto.generateKeyPair(),R=v.publicKey,U=await this.client.core.crypto.generateSharedKey(S,R),L=Je(de(de(de({relay:{protocol:c??"irn"},namespaces:f,controller:{publicKey:S,metadata:this.client.metadata},expiry:Ue(Rs)},u&&{sessionProperties:u}),h&&{scopedProperties:h}),l&&{sessionConfig:l}),{proposalRequestsResponses:d}),C=_e.relay;x.addTrace(wn.subscribing_session_topic);try{await this.client.core.relayer.subscribe(U,{transportType:C,internal:{skipSubscribe:!0}})}catch(j){throw x.setError(ji.subscribe_session_topic_failure),j}x.addTrace(wn.subscribe_session_topic_success);const A=Je(de({},L),{topic:U,requiredNamespaces:O,optionalNamespaces:P,pairingTopic:b,acknowledged:!1,self:L.controller,peer:{publicKey:v.publicKey,metadata:v.metadata},controller:S,transportType:_e.relay,authentication:d?.authentication,walletPayResult:d?.walletPay});await this.client.session.set(U,A),x.addTrace(wn.store_session);try{await this.sendApproveSession({sessionTopic:U,proposal:p,pairingProposalResponse:{relay:{protocol:c??"irn"},responderPublicKey:S},sessionSettleRequest:L,publishOpts:{internal:{throwOnFailedPublish:!0},tvf:de({correlationId:a},this.getTVFApproveParams(A))}}),x.addTrace(wn.session_approve_publish_success)}catch(j){throw this.client.logger.error(j),this.client.session.delete(U,Se("USER_DISCONNECTED")),await this.client.core.relayer.unsubscribe(U),j}return this.client.core.eventClient.deleteEvent({eventId:x.eventId}),await this.client.core.pairing.updateMetadata({topic:b,metadata:v.metadata}),await this.deleteProposal(a),await this.client.core.pairing.activate({topic:b}),await this.setExpiry(U,Ue(Rs)),{topic:U,acknowledged:()=>Promise.resolve(this.client.session.get(U))}}),V(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:Xe.wc_sessionPropose.reject}),await this.deleteProposal(r)}),V(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}=Ti(Z.FIVE_MINUTES,"Session update request expired without receiving any acknowledgement"),c=An(),f=li().toString(),u=this.client.session.get(r).namespaces;return this.events.once(pe("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:u}),a(h)}),{acknowledged:s}}),V(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}=Ti(Z.FIVE_MINUTES,"Session extend request expired without receiving any acknowledgement");return this.events.once(pe("session_extend",i),({error:c})=>{c?a(c):o()}),await this.setExpiry(r,Ue(Rs)),this.sendRequest({topic:r,method:"wc_sessionExtend",params:{},clientRpcId:i,throwOnFailedPublish:!0}).catch(c=>{a(c)}),{acknowledged:s}}),V(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=Xe.wc_sessionRequest.req.ttl}=n,a=this.client.session.get(s);a?.transportType===_e.relay&&await this.confirmOnlineStateOrThrow();const c=An(),f=li().toString(),{done:u,resolve:h,reject:l}=Ti(o,"Request expired. Please try again.");this.events.once(pe("session_request",c),({error:v,result:O})=>{v?l(v):h(O)});const d="wc_sessionRequest",p=this.getAppLinkIfEnabled(a.peer.metadata,a.transportType);if(p)return await this.sendRequest({clientRpcId:c,relayRpcId:f,topic:s,method:d,params:{request:Je(de({},i),{expiryTimestamp:Ue(o)}),chainId:r},expiry:o,throwOnFailedPublish:!0,appLink:p}).catch(v=>l(v)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:r,id:c}),await u();const b={request:Je(de({},i),{expiryTimestamp:Ue(o)}),chainId:r};return await Promise.all([new Promise(async v=>{await this.sendRequest({clientRpcId:c,relayRpcId:f,topic:s,method:d,params:b,expiry:o,throwOnFailedPublish:!0,tvf:this.getTVFParams(c,b)}).catch(O=>l(O)),this.client.events.emit("session_request_sent",{topic:s,request:i,chainId:r,id:c}),v()}),new Promise(async v=>{var O;if(!((O=a.sessionConfig)!=null&&O.disableDeepLink)){const P=await bB(this.client.core.storage,Vm);await pB({id:c,topic:s,wcDeepLink:P})}v()}),u()]).then(v=>v[2])}),V(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:[wn.session_request_response_started]}});try{await this.isValidRespond(n)}catch(h){throw s.addTrace(h?.message),s.setError(ji.session_request_response_validation_failure),h}s.addTrace(wn.session_request_response_validation_success);const{topic:o,response:a}=n,{id:c}=a,f=this.client.session.get(o);f.transportType===_e.relay&&await this.confirmOnlineStateOrThrow();const u=this.getAppLinkIfEnabled(f.peer.metadata,f.transportType);try{s.addTrace(wn.session_request_response_publish_started),On(a)?await this.sendResult({id:c,topic:o,result:a.result,throwOnFailedPublish:!0,appLink:u}):Qt(a)&&await this.sendError({id:c,topic:o,error:a.error,appLink:u}),this.cleanupAfterResponse(n)}catch(h){throw s.addTrace(h?.message),s.setError(ji.session_request_response_publish_failure),h}}),V(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=li().toString(),{done:o,resolve:a,reject:c}=Ti(Z.FIVE_MINUTES,"Ping request expired without receiving any acknowledgement");this.events.once(pe("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}))}),V(this,"emit",async n=>{this.isInitialized(),await this.confirmOnlineStateOrThrow(),await this.isValidEmit(n);const{topic:r,event:i,chainId:s}=n,o=li().toString(),a=An();await this.sendRequest({topic:r,method:"wc_sessionEvent",params:{event:i,chainId:s},throwOnFailedPublish:!0,relayRpcId:o,clientRpcId:a})}),V(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:Se("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)}}),V(this,"find",n=>(this.isInitialized(),this.client.session.getAll().filter(r=>CO(r,n)))),V(this,"getPendingSessionRequests",()=>this.client.pendingRequest.getAll()),V(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?_e.link_mode:_e.relay;o===_e.relay&&await this.confirmOnlineStateOrThrow();const{chains:a,statement:c="",uri:f,domain:u,nonce:h,type:l,exp:d,nbf:p,methods:b=[],expiry:v}=n,O=[...n.resources||[]],{topic:P,uri:x}=await this.client.core.pairing.create({methods:["wc_sessionAuthenticate"],transportType:o});this.client.logger.info({message:"Generated new pairing",pairing:{topic:P,uri:x}});const S=await this.client.core.crypto.generateKeyPair(),R=Cc(S);if(await Promise.all([this.client.auth.authKeys.set(Kc,{responseTopic:R,publicKey:S}),this.client.auth.pairingTopics.set(R,{topic:R,pairingTopic:P})]),await this.client.core.relayer.subscribe(R,{transportType:o}),this.client.logger.info(`sending request to new pairing topic: ${P}`),b.length>0){const{namespace:I}=pc(a[0]);let $=N$(I,"request",b);Ic(O)&&($=C$($,O.pop())),O.push($)}const U=v&&v>Xe.wc_sessionAuthenticate.req.ttl?v:Xe.wc_sessionAuthenticate.req.ttl,L={authPayload:{type:l??"caip122",chains:a,statement:c,aud:f,domain:u,version:"1",nonce:h,iat:new Date().toISOString(),exp:d,nbf:p,resources:O},requester:{publicKey:S,metadata:this.client.metadata},expiryTimestamp:Ue(U)},C={eip155:{chains:a,methods:[...new Set(["personal_sign",...b])],events:["chainChanged","accountsChanged"]}},A={requiredNamespaces:{},optionalNamespaces:C,relays:[{protocol:"irn"}],pairingTopic:P,proposer:{publicKey:S,metadata:this.client.metadata},expiryTimestamp:Ue(Xe.wc_sessionPropose.req.ttl),id:An()},{done:j,resolve:q,reject:E}=Ti(U,"Request expired"),y=An(),w=pe("session_connect",A.id),g=pe("session_request",y),m=async({error:I,session:$})=>{this.events.off(g,_),I?E(I):$&&q({session:$})},_=async I=>{var $,D,T;if(await this.deletePendingAuthRequest(y,{message:"fulfilled",code:0}),I.error){const H=Se("WC_METHOD_UNSUPPORTED","wc_sessionAuthenticate");return I.error.code===H.code?void 0:(this.events.off(w,m),E(I.error.message))}await this.deleteProposal(A.id),this.events.off(w,m);const{cacaos:F,responder:k}=I.result,N=[],M=[];for(const H of F){await Ib({cacao:H,projectId:this.client.core.projectId})||(this.client.logger.error(H,"Signature verification failed"),E(Se("SESSION_SETTLEMENT_FAILED","Signature verification failed")));const{p:G}=H,ee=Ic(G.resources),te=[Ml(G.iss)],re=_c(G.iss);if(ee){const ce=$b(ee),Ie=Ab(ee);N.push(...ce),te.push(...Ie)}for(const ce of te)M.push(`${ce}:${re}`)}const z=await this.client.core.crypto.generateSharedKey(S,k.publicKey);let K;N.length>0&&(K={topic:z,acknowledged:!0,self:{publicKey:S,metadata:this.client.metadata},peer:k,controller:k.publicKey,expiry:Ue(Rs),requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:P,namespaces:Cw([...new Set(N)],[...new Set(M)]),transportType:o},await this.client.core.relayer.subscribe(z,{transportType:o}),await this.client.session.set(z,K),P&&await this.client.core.pairing.updateMetadata({topic:P,metadata:k.metadata}),K=this.client.session.get(z)),($=this.client.metadata.redirect)!=null&&$.linkMode&&(D=k.metadata.redirect)!=null&&D.linkMode&&(T=k.metadata.redirect)!=null&&T.universal&&r&&(this.client.core.addLinkModeSupportedApp(k.metadata.redirect.universal),this.client.session.update(z,{transportType:_e.link_mode})),q({auths:F,session:K})};this.events.once(w,m),this.events.once(g,_);let B;try{if(s){const I=fr("wc_sessionAuthenticate",L,y);this.client.core.history.set(P,I);const $=await this.client.core.crypto.encode("",I,{type:Ro,encoding:ui});B=Lc(r,P,$)}else await Promise.all([this.sendRequest({topic:P,method:"wc_sessionAuthenticate",params:L,expiry:n.expiry,throwOnFailedPublish:!0,clientRpcId:y}),this.sendRequest({topic:P,method:"wc_sessionPropose",params:A,expiry:Xe.wc_sessionPropose.req.ttl,throwOnFailedPublish:!0,clientRpcId:A.id})])}catch(I){throw this.events.off(w,m),this.events.off(g,_),I}return await this.setProposal(A.id,A),await this.setAuthRequest(y,{request:Je(de({},L),{verifyContext:{}}),pairingTopic:P,transportType:o}),{uri:B??x,response:j}}),V(this,"approveSessionAuthenticate",async n=>{const{id:r,auths:i}=n,s=this.client.core.eventClient.createEvent({properties:{topic:r.toString(),trace:[zi.authenticated_session_approve_started]}});try{this.isInitialized()}catch(v){throw s.setError(Mo.no_internet_connection),v}const o=this.getPendingAuthRequest(r);if(!o)throw s.setError(Mo.authenticated_session_pending_request_not_found),new Error(`Could not find pending auth request with id ${r}`);const a=o.transportType||_e.relay;a===_e.relay&&await this.confirmOnlineStateOrThrow();const c=o.requester.publicKey,f=await this.client.core.crypto.generateKeyPair(),u=Cc(c),h={type:or,receiverPublicKey:c,senderPublicKey:f},l=[],d=[];for(const v of i){if(!await Ib({cacao:v,projectId:this.client.core.projectId})){s.setError(Mo.invalid_cacao);const R=Se("SESSION_SETTLEMENT_FAILED","Signature verification failed");throw await this.sendError({id:r,topic:u,error:R,encodeOpts:h}),new Error(R.message)}s.addTrace(zi.cacaos_verified);const{p:O}=v,P=Ic(O.resources),x=[Ml(O.iss)],S=_c(O.iss);if(P){const R=$b(P),U=Ab(P);l.push(...R),x.push(...U)}for(const R of x)d.push(`${R}:${S}`)}const p=await this.client.core.crypto.generateSharedKey(f,c);s.addTrace(zi.create_authenticated_session_topic);let b;if(l?.length>0){b={topic:p,acknowledged:!0,self:{publicKey:f,metadata:this.client.metadata},peer:{publicKey:c,metadata:o.requester.metadata},controller:c,expiry:Ue(Rs),authentication:i,requiredNamespaces:{},optionalNamespaces:{},relay:{protocol:"irn"},pairingTopic:o.pairingTopic,namespaces:Cw([...new Set(l)],[...new Set(d)]),transportType:a},s.addTrace(zi.subscribing_authenticated_session_topic);try{await this.client.core.relayer.subscribe(p,{transportType:a})}catch(v){throw s.setError(Mo.subscribe_authenticated_session_topic_failure),v}s.addTrace(zi.subscribe_authenticated_session_topic_success),await this.client.session.set(p,b),s.addTrace(zi.store_authenticated_session),await this.client.core.pairing.updateMetadata({topic:o.pairingTopic,metadata:o.requester.metadata})}s.addTrace(zi.publishing_authenticated_session_approve);try{await this.sendResult({topic:u,id:r,result:{cacaos:i,responder:{publicKey:f,metadata:this.client.metadata}},encodeOpts:h,throwOnFailedPublish:!0,appLink:this.getAppLinkIfEnabled(o.requester.metadata,a)})}catch(v){throw s.setError(Mo.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:b}}),V(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===_e.relay&&await this.confirmOnlineStateOrThrow();const o=s.requester.publicKey,a=await this.client.core.crypto.generateKeyPair(),c=Cc(o),f={type:or,receiverPublicKey:o,senderPublicKey:a};await this.sendError({id:r,topic:c,error:i,encodeOpts:f,rpcOpts:Xe.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)}),V(this,"formatAuthMessage",n=>{this.isInitialized();const{request:r,iss:i}=n;return Sb(r,i)}),V(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)}),V(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)}}),V(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,Se("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(Vm).catch(f=>this.client.logger.warn(f)),i===((r=this.sessionRequestQueue.queue[0])==null?void 0:r.topic)&&(this.sessionRequestQueue.state=Tn.idle),await Promise.all(this.getPendingSessionRequests().filter(f=>f.topic===i).map(f=>this.deletePendingSessionRequest(f.id,Se("USER_DISCONNECTED")))),o&&this.client.events.emit("session_delete",{id:a,topic:i})}),V(this,"deleteProposal",async(n,r)=>{if(r)try{const i=this.client.proposal.get(n);this.client.core.eventClient.getEvent({topic:i.pairingTopic})?.setError(ji.proposal_expired)}catch{}await Promise.all([this.client.proposal.delete(n,Se("USER_DISCONNECTED")),r?Promise.resolve():this.client.core.expirer.del(n)]),this.addToRecentlyDeleted(n,"proposal")}),V(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=Tn.idle,this.client.events.emit("session_request_expire",{id:n}))}),V(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)])}),V(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}))}),V(this,"setProposal",async(n,r)=>{this.client.core.expirer.set(n,Ue(Xe.wc_sessionPropose.req.ttl)),await this.client.proposal.set(n,r)}),V(this,"setAuthRequest",async(n,r)=>{const{request:i,pairingTopic:s,transportType:o=_e.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})}),V(this,"setPendingSessionRequest",async n=>{const{id:r,topic:i,params:s,verifyContext:o}=n,a=s.request.expiryTimestamp||Ue(Xe.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})}),V(this,"sendRequest",async n=>{const{topic:r,method:i,params:s,expiry:o,relayRpcId:a,clientRpcId:c,throwOnFailedPublish:f,appLink:u,tvf:h,publishOpts:l={}}=n,d=fr(i,s,c);let p;const b=!!u;try{const P=b?ui:Nt;p=await this.client.core.crypto.encode(r,d,{encoding:P})}catch(P){throw await this.cleanup(),this.client.logger.error(`sendRequest() -> core.crypto.encode() for topic ${r} failed`),P}let v;if(WN.includes(i)){const P=Jt(JSON.stringify(d)),x=Jt(p);v=await this.client.core.verify.register({id:x,decryptedId:P})}const O=de(de({},Xe[i].req),l);if(O.attestation=v,o&&(O.ttl=o),a&&(O.id=a),this.client.core.history.set(r,d),b){const P=Lc(u,r,p);await global.Linking.openURL(P,this.client.name)}else O.tvf=Je(de({},h),{correlationId:d.id}),f?(O.internal=Je(de({},O.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(r,p,O)):this.client.core.relayer.publish(r,p,O).catch(P=>this.client.logger.error(P));return d.id}),V(this,"sendProposeSession",async n=>{const{proposal:r,publishOpts:i}=n,s=fr("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:Nt}),a=Jt(JSON.stringify(s)),c=Jt(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:Je(de({},i),{publishMethod:"wc_proposeSession",attestation:f})})}),V(this,"sendApproveSession",async n=>{const{sessionTopic:r,pairingProposalResponse:i,proposal:s,sessionSettleRequest:o,publishOpts:a}=n,c=qc(s.id,i),f=await this.client.core.crypto.encode(s.pairingTopic,c,{encoding:Nt}),u=fr("wc_sessionSettle",o,a?.id),h=await this.client.core.crypto.encode(r,u,{encoding:Nt});this.client.core.history.set(r,u),await this.client.core.relayer.publishCustom({payload:{sessionTopic:r,pairingTopic:s.pairingTopic,sessionProposalResponse:f,sessionSettlementRequest:h},opts:Je(de({},a),{publishMethod:"wc_approveSession"})})}),V(this,"sendResult",async n=>{const{id:r,topic:i,result:s,throwOnFailedPublish:o,encodeOpts:a,appLink:c}=n,f=qc(r,s);let u;const h=c&&typeof(global==null?void 0:global.Linking)<"u";try{const p=h?ui:Nt;u=await this.client.core.crypto.encode(i,f,Je(de({},a||{}),{encoding:p}))}catch(p){throw await this.cleanup(),this.client.logger.error(`sendResult() -> core.crypto.encode() for topic ${i} failed`),p}let l,d;try{l=await this.client.core.history.get(i,r);const p=l.request;try{d=this.getTVFParams(r,p.params,s)}catch(b){this.client.logger.warn(`sendResult() -> getTVFParams() failed: ${b?.message}`)}}catch(p){throw this.client.logger.error(`sendResult() -> history.get(${i}, ${r}) failed`),p}if(h){const p=Lc(c,i,u);await global.Linking.openURL(p,this.client.name)}else{const p=l.request.method,b=Xe[p].res;b.tvf=Je(de({},d),{correlationId:r}),o?(b.internal=Je(de({},b.internal),{throwOnFailedPublish:!0}),await this.client.core.relayer.publish(i,u,b)):this.client.core.relayer.publish(i,u,b).catch(v=>this.client.logger.error(v))}await this.client.core.history.resolve(f)}),V(this,"sendError",async n=>{const{id:r,topic:i,error:s,encodeOpts:o,rpcOpts:a,appLink:c}=n,f=vh(r,s);let u;const h=c&&typeof(global==null?void 0:global.Linking)<"u";try{const d=h?ui:Nt;u=await this.client.core.crypto.encode(i,f,Je(de({},o||{}),{encoding:d}))}catch(d){throw await this.cleanup(),this.client.logger.error(`sendError() -> core.crypto.encode() for topic ${i} failed`),d}let l;try{l=await this.client.core.history.get(i,r)}catch(d){throw this.client.logger.error(`sendError() -> history.get(${i}, ${r}) failed`),d}if(h){const d=Lc(c,i,u);await global.Linking.openURL(d,this.client.name)}else{const d=l.request.method,p=a||Xe[d].res;this.client.core.relayer.publish(i,u,p)}await this.client.core.history.resolve(f)}),V(this,"cleanup",async()=>{const n=[],r=[];this.client.session.getAll().forEach(i=>{let s=!1;Yr(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=>{Yr(i.expiryTimestamp)&&r.push(i.id)}),await Promise.all([...n.map(i=>this.deleteSession({topic:i})),...r.map(i=>this.deleteProposal(i))])}),V(this,"onProviderMessageEvent",async n=>{!this.initialized||this.relayMessageCache.length>0?this.relayMessageCache.push(n):await this.onRelayMessage(n)}),V(this,"onRelayEventRequest",async n=>{this.requestQueue.queue.push(n),await this.processRequestsQueue()}),V(this,"processRequestsQueue",async()=>{if(this.requestQueue.state===Tn.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=Tn.active;const n=this.requestQueue.queue.shift();if(n)try{await this.processRequest(n)}catch(r){this.client.logger.warn(r)}}this.requestQueue.state=Tn.idle}),V(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}`)}}),V(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}`)}}),V(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)}),V(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)}),V(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(ur.proposal_listener_not_found)),this.isValidConnect(de({},i.params));const u=a.expiryTimestamp||Ue(Xe.wc_sessionPropose.req.ttl),h=de({id:c,pairingTopic:r,expiryTimestamp:u,attestation:s,encryptedId:o},a);await this.setProposal(c,h);const l=await this.getVerifyContext({attestationId:s,hash:Jt(JSON.stringify(i)),encryptedId:o,metadata:h.proposer.metadata});f?.addTrace(Pn.emit_session_proposal),this.client.events.emit("session_proposal",{id:c,params:h,verifyContext:l})}catch(f){await this.sendError({id:c,topic:r,error:f,rpcOpts:Xe.wc_sessionPropose.autoReject}),this.client.logger.error(f)}}),V(this,"onSessionProposeResponse",async(n,r,i)=>{const{id:s}=r;if(On(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 u=await this.client.core.crypto.generateSharedKey(c,f);this.pendingSessions.set(s,{sessionTopic:u,pairingTopic:n,proposalId:s,publicKey:c});const h=await this.client.core.relayer.subscribe(u,{transportType:i});this.client.logger.trace({type:"method",method:"onSessionProposeResponse",subscriptionId:h}),await this.client.core.pairing.activate({topic:n})}else if(Qt(r)){await this.deleteProposal(s);const o=pe("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})}}),V(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:u,scopedProperties:h,sessionConfig:l,proposalRequestsResponses:d}=r.params,p=[...this.pendingSessions.values()].find(O=>O.sessionTopic===n);if(!p)return this.client.logger.error(`Pending session not found for topic ${n}`);const b=this.client.proposal.get(p.proposalId),v=Je(de(de(de({topic:n,relay:o,expiry:c,namespaces:f,acknowledged:!0,pairingTopic:p.pairingTopic,requiredNamespaces:b.requiredNamespaces,optionalNamespaces:b.optionalNamespaces,controller:a.publicKey,self:{publicKey:p.publicKey,metadata:this.client.metadata},peer:{publicKey:a.publicKey,metadata:a.metadata}},u&&{sessionProperties:u}),h&&{scopedProperties:h}),l&&{sessionConfig:l}),{transportType:_e.relay,authentication:d?.authentication,walletPayResult:d?.walletPay});await this.client.session.set(v.topic,v),await this.setExpiry(v.topic,v.expiry),await this.client.core.pairing.updateMetadata({topic:p.pairingTopic,metadata:v.peer.metadata}),this.pendingSessions.delete(p.proposalId),this.deleteProposal(p.proposalId,!1),this.cleanupDuplicatePairings(v),await this.sendResult({id:r.id,topic:n,throwOnFailedPublish:!0,result:!0}),this.client.events.emit("session_connect",{session:v}),this.events.emit(pe("session_connect",p.proposalId),{session:v})}catch(o){await this.sendError({id:i,topic:n,error:o}),this.client.logger.error(o)}}),V(this,"onSessionSettleResponse",async(n,r)=>{const{id:i}=r;On(r)?(await this.client.session.update(n,{acknowledged:!0}),this.events.emit(pe("session_approve",i),{})):Qt(r)&&(await this.client.session.delete(n,Se("USER_DISCONNECTED")),this.events.emit(pe("session_approve",i),{error:r.error}))}),V(this,"onSessionUpdateRequest",async(n,r)=>{const{params:i,id:s}=r;try{const o=`${n}_session_update`,a=Co.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:Se("INVALID_UPDATE_REQUEST")});return}this.isValidUpdate(de({topic:n},i));try{Co.set(o,s),await this.client.session.update(n,{namespaces:i.namespaces}),await this.sendResult({id:s,topic:n,result:!0})}catch(c){throw Co.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)}}),V(this,"isRequestOutOfSync",(n,r)=>r.toString().slice(0,-3)<n.toString().slice(0,-3)),V(this,"onSessionUpdateResponse",(n,r)=>{const{id:i}=r,s=pe("session_update",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);On(r)?this.events.emit(pe("session_update",i),{}):Qt(r)&&this.events.emit(pe("session_update",i),{error:r.error})}),V(this,"onSessionExtendRequest",async(n,r)=>{const{id:i}=r;try{this.isValidExtend({topic:n}),await this.setExpiry(n,Ue(Rs)),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)}}),V(this,"onSessionExtendResponse",(n,r)=>{const{id:i}=r,s=pe("session_extend",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);On(r)?this.events.emit(pe("session_extend",i),{}):Qt(r)&&this.events.emit(pe("session_extend",i),{error:r.error})}),V(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)}}),V(this,"onSessionPingResponse",(n,r)=>{const{id:i}=r,s=pe("session_ping",i);setTimeout(()=>{if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners 2176`);On(r)?this.events.emit(pe("session_ping",i),{}):Qt(r)&&this.events.emit(pe("session_ping",i),{error:r.error})},500)}),V(this,"onSessionDeleteRequest",async(n,r)=>{const{id:i}=r;try{await this.isValidDisconnect({topic:n,reason:r.params}),this.cleanupPendingSentRequestsForTopic({topic:n,error:Se("USER_DISCONNECTED")}),await this.deleteSession({topic:n,id:i})}catch(s){this.client.logger.error(s)}}),V(this,"onSessionRequest",async n=>{var r,i,s;const{topic:o,payload:a,attestation:c,encryptedId:f,transportType:u}=n,{id:h,params:l}=a;try{await this.isValidRequest(de({topic:o},l));const d=this.client.session.get(o),p=await this.getVerifyContext({attestationId:c,hash:Jt(JSON.stringify(fr("wc_sessionRequest",l,h))),encryptedId:f,metadata:d.peer.metadata,transportType:u}),b={id:h,topic:o,params:l,verifyContext:p};await this.setPendingSessionRequest(b),u===_e.link_mode&&(r=d.peer.metadata.redirect)!=null&&r.universal&&this.client.core.addLinkModeSupportedApp((i=d.peer.metadata.redirect)==null?void 0:i.universal),(s=this.client.signConfig)!=null&&s.disableRequestQueue?this.emitSessionRequest(b):(this.addSessionRequestToSessionRequestQueue(b),this.processSessionRequestQueue())}catch(d){await this.sendError({id:h,topic:o,error:d}),this.client.logger.error(d)}}),V(this,"onSessionRequestResponse",(n,r)=>{const{id:i}=r,s=pe("session_request",i);if(this.events.listenerCount(s)===0)throw new Error(`emitting ${s} without any listeners`);On(r)?this.events.emit(pe("session_request",i),{result:r.result}):Qt(r)&&this.events.emit(pe("session_request",i),{error:r.error})}),V(this,"onSessionEventRequest",async(n,r)=>{const{id:i,params:s}=r;try{const o=`${n}_session_event_${s.event.name}`,a=Co.get(o);if(a&&this.isRequestOutOfSync(a,i)){this.client.logger.info(`Discarding out of sync request - ${i}`);return}this.isValidEmit(de({topic:n},s)),this.client.events.emit("session_event",{id:i,topic:n,params:s}),Co.set(o,i)}catch(o){await this.sendError({id:i,topic:n,error:o}),this.client.logger.error(o)}}),V(this,"onSessionAuthenticateResponse",(n,r)=>{const{id:i}=r;this.client.logger.trace({type:"method",method:"onSessionAuthenticateResponse",topic:n,payload:r}),On(r)?this.events.emit(pe("session_request",i),{result:r.result}):Qt(r)&&this.events.emit(pe("session_request",i),{error:r.error})}),V(this,"onSessionAuthenticateRequest",async n=>{var r;const{topic:i,payload:s,attestation:o,encryptedId:a,transportType:c}=n;try{const{requester:f,authPayload:u,expiryTimestamp:h}=s.params,l=await this.getVerifyContext({attestationId:o,hash:Jt(JSON.stringify(s)),encryptedId:a,metadata:f.metadata,transportType:c}),d={requester:f,pairingTopic:i,id:s.id,authPayload:u,verifyContext:l,expiryTimestamp:h};await this.setAuthRequest(s.id,{request:d,pairingTopic:i,transportType:c}),c===_e.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:l})}catch(f){this.client.logger.error(f);const u=s.params.requester.publicKey,h=await this.client.core.crypto.generateKeyPair(),l=this.getAppLinkIfEnabled(s.params.requester.metadata,c),d={type:or,receiverPublicKey:u,senderPublicKey:h};await this.sendError({id:s.id,topic:i,error:f,encodeOpts:d,rpcOpts:Xe.wc_sessionAuthenticate.autoReject,appLink:l})}}),V(this,"addSessionRequestToSessionRequestQueue",n=>{this.sessionRequestQueue.queue.push(n)}),V(this,"cleanupAfterResponse",n=>{this.deletePendingSessionRequest(n.response.id,{message:"fulfilled",code:0}),setTimeout(()=>{this.sessionRequestQueue.state=Tn.idle,this.processSessionRequestQueue()},Z.toMiliseconds(this.requestQueueDelay))}),V(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(pe("session_request",s.request.id),{error:r})})}),V(this,"processSessionRequestQueue",()=>{if(this.sessionRequestQueue.state===Tn.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)}}),V(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=Tn.active,this.emittedSessionRequests.add(n.id),this.client.events.emit("session_request",n)}),V(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:fr("wc_sessionPropose",Je(de({},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})}),V(this,"isValidConnect",async n=>{if(!Ut(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(Fe(r)||await this.isValidPairingTopic(r),!ZO(c,!0)){const{message:f}=W("MISSING_OR_INVALID",`connect() relays: ${c}`);throw new Error(f)}if(i&&!Fe(i)&&Uo(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&&!Fe(s)&&Uo(s)!==0&&this.validateNamespaces(s,"optionalNamespaces"),o&&!Fe(o)&&this.validateSessionProps(o,"sessionProperties"),a&&!Fe(a)){this.validateSessionProps(a,"scopedProperties");const f=Object.keys(i||{}).concat(Object.keys(s||{}));if(!Object.keys(a).every(u=>f.includes(u.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)}`)}}),V(this,"validateNamespaces",(n,r)=>{const i=GO(n,"connect()",r);if(i)throw new Error(i.message)}),V(this,"isValidApprove",async n=>{if(!Ut(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=dh(i,"approve()");if(f)throw new Error(f.message);const u=Mw(c.requiredNamespaces,i,"approve()");if(u)throw new Error(u.message);if(!Oe(s,!0)){const{message:h}=W("MISSING_OR_INVALID",`approve() relayProtocol: ${s}`);throw new Error(h)}if(o&&!Fe(o)&&this.validateSessionProps(o,"sessionProperties"),a&&!Fe(a)){this.validateSessionProps(a,"scopedProperties");const h=new Set(Object.keys(i));if(!Object.keys(a).every(l=>h.has(l.split(":")[0])))throw new Error(`Scoped properties must be a subset of approved namespaces, received: ${JSON.stringify(a)}, approved namespaces: ${Array.from(h).join(", ")}`)}}),V(this,"isValidReject",async n=>{if(!Ut(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),!YO(i)){const{message:s}=W("MISSING_OR_INVALID",`reject() reason: ${JSON.stringify(i)}`);throw new Error(s)}}),V(this,"isValidSessionSettleRequest",n=>{if(!Ut(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(!kw(r)){const{message:f}=W("MISSING_OR_INVALID","onSessionSettleRequest() relay protocol should be a string");throw new Error(f)}const a=MO(i,"onSessionSettleRequest()");if(a)throw new Error(a.message);const c=dh(s,"onSessionSettleRequest()");if(c)throw new Error(c.message);if(Yr(o)){const{message:f}=W("EXPIRED","onSessionSettleRequest()");throw new Error(f)}}),V(this,"isValidUpdate",async n=>{if(!Ut(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=dh(i,"update()");if(o)throw new Error(o.message);const a=Mw(s.requiredNamespaces,i,"update()");if(a)throw new Error(a.message)}),V(this,"isValidExtend",async n=>{if(!Ut(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)}),V(this,"isValidRequest",async n=>{if(!Ut(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(!qw(a,s)){const{message:c}=W("MISSING_OR_INVALID",`request() chainId: ${s}`);throw new Error(c)}if(!XO(i)){const{message:c}=W("MISSING_OR_INVALID",`request() ${JSON.stringify(i)}`);throw new Error(c)}if(!eD(a,s,i.method)){const{message:c}=W("MISSING_OR_INVALID",`request() method: ${i.method}`);throw new Error(c)}this.validateRequestExpiry(o)}),V(this,"isValidRespond",async n=>{var r;if(!Ut(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(!JO(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)}}),V(this,"isValidPing",async n=>{if(!Ut(n)){const{message:i}=W("MISSING_OR_INVALID",`ping() params: ${n}`);throw new Error(i)}const{topic:r}=n;await this.isValidSessionOrPairingTopic(r)}),V(this,"isValidEmit",async n=>{if(!Ut(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(!qw(o,s)){const{message:a}=W("MISSING_OR_INVALID",`emit() chainId: ${s}`);throw new Error(a)}if(!QO(i)){const{message:a}=W("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}if(!tD(o,s,i.name)){const{message:a}=W("MISSING_OR_INVALID",`emit() event: ${JSON.stringify(i)}`);throw new Error(a)}}),V(this,"isValidDisconnect",async n=>{if(!Ut(n)){const{message:i}=W("MISSING_OR_INVALID",`disconnect() params: ${n}`);throw new Error(i)}const{topic:r}=n;await this.isValidSessionOrPairingTopic(r)}),V(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(!Oe(i,!1))throw new Error("uri is required parameter");if(!Oe(s,!1))throw new Error("domain is required parameter");if(!Oe(o,!1))throw new Error("nonce is required parameter");if([...new Set(r.map(c=>pc(c).namespace))].length>1)throw new Error("Multi-namespace requests are not supported. Please request single namespace only.");const{namespace:a}=pc(r[0]);if(a!=="eip155")throw new Error("Only eip155 namespace is supported for authenticated sessions. Please use .connect() for non-eip155 chains.")}),V(this,"getVerifyContext",async n=>{const{attestationId:r,hash:i,encryptedId:s,metadata:o,transportType:a}=n,c={verified:{verifyUrl:o.verifyUrl||qo,validation:"UNKNOWN",origin:o.url||""}};try{if(a===_e.link_mode){const u=this.getAppLinkIfEnabled(o,a);return c.verified.validation=u&&new URL(u).origin===new URL(o.url).origin?"VALID":"INVALID",c}const f=await this.client.core.verify.resolve({attestationId: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}),V(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)}})}),V(this,"getPendingAuthRequest",n=>{const r=this.client.auth.requests.get(n);return typeof r=="object"?r:void 0}),V(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)}}}),V(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)}}),V(this,"isLinkModeEnabled",(n,r)=>{var i,s,o,a,c,f,u,h,l;return!n||r!==_e.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)!==""&&((u=n?.redirect)==null?void 0:u.universal)!==void 0&&((h=n?.redirect)==null?void 0:h.universal)!==""&&((l=n?.redirect)==null?void 0:l.linkMode)===!0&&this.client.core.linkModeSupportedApps.includes(n.redirect.universal)&&typeof(global==null?void 0:global.Linking)<"u"}),V(this,"getAppLinkIfEnabled",(n,r)=>{var i;return this.isLinkModeEnabled(n,r)?(i=n?.redirect)==null?void 0:i.universal:void 0}),V(this,"handleLinkModeMessage",({url:n})=>{if(!n||!n.includes("wc_ev")||!n.includes("topic"))return;const r=Xy(n,"topic")||"",i=decodeURIComponent(Xy(n,"wc_ev")||""),s=this.client.session.keys.includes(r);s&&this.client.session.update(r,{transportType:_e.link_mode}),this.client.core.dispatchEnvelope({topic:r,message:i,sessionExists:s})}),V(this,"registerLinkModeListeners",async()=>{var n;if(Tl()||Wr()&&(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)}}}),V(this,"getTVFApproveParams",n=>{try{const r=Tw(n.namespaces),i=$O(n.namespaces),s=AO(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"),{}}}),V(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}),V(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}),V(this,"extractTxHashesFromResult",(n,r)=>{var i;try{if(!r)return[];const s=n.method,o=GN[s];if(s==="sui_signTransaction")return[g$(r.transactionBytes)];if(s==="near_signTransaction")return[mb(r)];if(s==="near_signTransactions")return r.map(c=>mb(c));if(s==="xrpl_signTransactionFor"||s==="xrpl_signTransaction")return[(i=r.tx_json)==null?void 0:i.hash];if(s==="polkadot_signTransaction")return[mD({transaction:n.params.transactionPayload,signature:r.signature})];if(s==="algo_signTxn")return Os(r)?r.map(c=>vb(c)):[vb(r)];if(s==="cosmos_signDirect")return[b$(r)];if(s==="wallet_sendCalls")return w$(r);if(typeof r=="string")return[r];const a=r[o.key];if(Os(a))return s==="solana_signAllTransactions"?a.map(c=>p$(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(De.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(Kc)?this.client.auth.authKeys.get(Kc):{responseTopic:void 0,publicKey:void 0};try{const a=await this.client.core.crypto.decode(n,r,{receiverPublicKey:o,encoding:s===_e.link_mode?ui:Nt});Eh(a)?(this.client.core.history.set(n,a),await this.onRelayEventRequest({topic:n,payload:a,attestation:i,transportType:s,encryptedId:Jt(r)})):Mc(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(tn.expired,async e=>{const{topic:n,id:r}=Yy(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(Mi.create,e=>this.onPairingCreated(e)),this.client.core.pairing.events.on(Mi.delete,e=>{this.addToRecentlyDeleted(e.topic,"pairing")})}isValidPairingTopic(e){if(!Oe(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(Yr(this.client.core.pairing.pairings.get(e).expiry)){const{message:n}=W("EXPIRED",`pairing topic: ${e}`);throw new Error(n)}}async isValidSessionTopic(e){if(!Oe(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(Yr(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(Oe(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(!WO(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(Yr(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&&!iD(e,kh)){const{message:n}=W("MISSING_OR_INVALID",`request() expiry: ${e}. Expiry must be a number (in seconds) between ${kh.min} and ${kh.max}`);throw new Error(n)}}}class aU extends Hi{constructor(e,n){super(e,n,HN,Fh),this.core=e,this.logger=n}}class Zm extends Hi{constructor(e,n){super(e,n,VN,Fh),this.core=e,this.logger=n}}class cU extends Hi{constructor(e,n){super(e,n,ZN,Fh,r=>r.id),this.core=e,this.logger=n}}class fU extends Hi{constructor(e,n){super(e,n,JN,Vc,()=>Kc),this.core=e,this.logger=n}}class uU extends Hi{constructor(e,n){super(e,n,QN,Vc),this.core=e,this.logger=n}}class lU extends Hi{constructor(e,n){super(e,n,eU,Vc,r=>r.id),this.core=e,this.logger=n}}var hU=Object.defineProperty,dU=(t,e,n)=>e in t?hU(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Mh=(t,e,n)=>dU(t,typeof e!="symbol"?e+"":e,n);class pU{constructor(e,n){this.core=e,this.logger=n,Mh(this,"authKeys"),Mh(this,"pairingTopics"),Mh(this,"requests"),this.authKeys=new fU(this.core,this.logger),this.pairingTopics=new uU(this.core,this.logger),this.requests=new lU(this.core,this.logger)}async init(){await this.authKeys.init(),await this.pairingTopics.init(),await this.requests.init()}}var gU=Object.defineProperty,yU=(t,e,n)=>e in t?gU(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ae=(t,e,n)=>yU(t,typeof e!="symbol"?e+"":e,n);class jh extends pS{constructor(e){super(e),ae(this,"protocol",jm),ae(this,"version",zm),ae(this,"name",Lh.name),ae(this,"metadata"),ae(this,"core"),ae(this,"logger"),ae(this,"events",new Qe.exports.EventEmitter),ae(this,"engine"),ae(this,"session"),ae(this,"proposal"),ae(this,"pendingRequest"),ae(this,"auth"),ae(this,"signConfig"),ae(this,"on",(r,i)=>this.events.on(r,i)),ae(this,"once",(r,i)=>this.events.once(r,i)),ae(this,"off",(r,i)=>this.events.off(r,i)),ae(this,"removeListener",(r,i)=>this.events.removeListener(r,i)),ae(this,"removeAllListeners",r=>this.events.removeAllListeners(r)),ae(this,"connect",async r=>{try{return await this.engine.connect(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"pair",async r=>{try{return await this.engine.pair(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"approve",async r=>{try{return await this.engine.approve(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"reject",async r=>{try{return await this.engine.reject(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"update",async r=>{try{return await this.engine.update(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"extend",async r=>{try{return await this.engine.extend(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"request",async r=>{try{return await this.engine.request(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"respond",async r=>{try{return await this.engine.respond(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"ping",async r=>{try{return await this.engine.ping(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"emit",async r=>{try{return await this.engine.emit(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"disconnect",async r=>{try{return await this.engine.disconnect(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"find",r=>{try{return this.engine.find(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"getPendingSessionRequests",()=>{try{return this.engine.getPendingSessionRequests()}catch(r){throw this.logger.error(r.message),r}}),ae(this,"authenticate",async(r,i)=>{try{return await this.engine.authenticate(r,i)}catch(s){throw this.logger.error(s.message),s}}),ae(this,"formatAuthMessage",r=>{try{return this.engine.formatAuthMessage(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"approveSessionAuthenticate",async r=>{try{return await this.engine.approveSessionAuthenticate(r)}catch(i){throw this.logger.error(i.message),i}}),ae(this,"rejectSessionAuthenticate",async r=>{try{return await this.engine.rejectSessionAuthenticate(r)}catch(i){throw this.logger.error(i.message),i}}),this.name=e?.name||Lh.name,this.metadata=cB(e?.metadata),this.signConfig=e?.signConfig;const n=Hw({logger:e?.logger||Lh.logger,name:this.name});this.logger=n,this.core=e?.core||new Ch(e),this.session=new Zm(this.core,this.logger),this.proposal=new aU(this.core,this.logger),this.pendingRequest=new cU(this.core,this.logger),this.engine=new oU(this),this.auth=new pU(this.core,this.logger)}static async init(e){const n=new jh(e);return await n.initialize(),n}get context(){return xt(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 bU=Zm,wU=jh;class mU extends Qe.exports{constructor(){super()}}class Wm{constructor(e){this.opts=e}}class Ym{constructor(e){this.client=e}}var vU=Object.defineProperty,EU=Object.defineProperties,xU=Object.getOwnPropertyDescriptors,Xm=Object.getOwnPropertySymbols,_U=Object.prototype.hasOwnProperty,IU=Object.prototype.propertyIsEnumerable,zh=(t,e,n)=>e in t?vU(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,SU=(t,e)=>{for(var n in e||(e={}))_U.call(e,n)&&zh(t,n,e[n]);if(Xm)for(var n of Xm(e))IU.call(e,n)&&zh(t,n,e[n]);return t},BU=(t,e)=>EU(t,xU(e)),be=(t,e,n)=>zh(t,typeof e!="symbol"?e+"":e,n);class $U extends Ym{constructor(e){super(e),be(this,"signClient"),be(this,"init",async()=>{this.signClient=await wU.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)})}),be(this,"pair",async n=>{await this.client.core.pairing.pair(n)}),be(this,"approveSession",async n=>{const{topic:r,acknowledged:i}=await this.signClient.approve(BU(SU({},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)}),be(this,"rejectSession",async n=>await this.signClient.reject(n)),be(this,"updateSession",async n=>await this.signClient.update(n)),be(this,"extendSession",async n=>await this.signClient.extend(n)),be(this,"respondSessionRequest",async n=>await this.signClient.respond(n)),be(this,"disconnectSession",async n=>await this.signClient.disconnect(n)),be(this,"emitSessionEvent",async n=>await this.signClient.emit(n)),be(this,"getActiveSessions",()=>this.signClient.session.getAll().reduce((n,r)=>(n[r.topic]=r,n),{})),be(this,"getPendingSessionProposals",()=>this.signClient.proposal.getAll()),be(this,"getPendingSessionRequests",()=>this.signClient.getPendingSessionRequests()),be(this,"approveSessionAuthenticate",async n=>await this.signClient.approveSessionAuthenticate(n)),be(this,"rejectSessionAuthenticate",async n=>await this.signClient.rejectSessionAuthenticate(n)),be(this,"formatAuthMessage",n=>this.signClient.formatAuthMessage(n)),be(this,"registerDeviceToken",n=>this.client.core.echoClient.registerDeviceToken(n)),be(this,"on",(n,r)=>(this.setEvent(n,"off"),this.setEvent(n,"on"),this.client.events.on(n,r))),be(this,"once",(n,r)=>(this.setEvent(n,"off"),this.setEvent(n,"once"),this.client.events.once(n,r))),be(this,"off",(n,r)=>(this.setEvent(n,"off"),this.client.events.off(n,r))),be(this,"removeListener",(n,r)=>(this.setEvent(n,"removeListener"),this.client.events.removeListener(n,r))),be(this,"onSessionRequest",n=>{this.client.events.emit("session_request",n)}),be(this,"onSessionProposal",n=>{this.client.events.emit("session_proposal",n)}),be(this,"onSessionDelete",n=>{this.client.events.emit("session_delete",n)}),be(this,"onProposalExpire",n=>{this.client.events.emit("proposal_expire",n)}),be(this,"onSessionRequestExpire",n=>{this.client.events.emit("session_request_expire",n)}),be(this,"onSessionRequestAuthenticate",n=>{this.client.events.emit("session_authenticate",n)}),be(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 AU={decryptMessage:async t=>{const e={core:new Ch({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 Ch({storageOptions:t.storageOptions,storage:t.storage}),sessionStore:null};e.sessionStore=new bU(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 OU(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 DU=Object.defineProperty,Jm=Object.getOwnPropertySymbols,PU=Object.prototype.hasOwnProperty,RU=Object.prototype.propertyIsEnumerable,Hh=(t,e,n)=>e in t?DU(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,TU=(t,e)=>{for(var n in e||(e={}))PU.call(e,n)&&Hh(t,n,e[n]);if(Jm)for(var n of Jm(e))RU.call(e,n)&&Hh(t,n,e[n]);return t},we=(t,e,n)=>Hh(t,typeof e!="symbol"?e+"":e,n);const Qm=class c2 extends Wm{constructor(e){super(e),we(this,"name"),we(this,"core"),we(this,"logger"),we(this,"events",new Qe.exports),we(this,"engine"),we(this,"metadata"),we(this,"signConfig"),we(this,"pay"),we(this,"on",(n,r)=>this.engine.on(n,r)),we(this,"once",(n,r)=>this.engine.once(n,r)),we(this,"off",(n,r)=>this.engine.off(n,r)),we(this,"removeListener",(n,r)=>this.engine.removeListener(n,r)),we(this,"pair",async n=>{try{return await this.engine.pair(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"approveSession",async n=>{try{return await this.engine.approveSession(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"rejectSession",async n=>{try{return await this.engine.rejectSession(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"updateSession",async n=>{try{return await this.engine.updateSession(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"extendSession",async n=>{try{return await this.engine.extendSession(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"respondSessionRequest",async n=>{try{return await this.engine.respondSessionRequest(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"disconnectSession",async n=>{try{return await this.engine.disconnectSession(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"emitSessionEvent",async n=>{try{return await this.engine.emitSessionEvent(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"getActiveSessions",()=>{try{return this.engine.getActiveSessions()}catch(n){throw this.logger.error(n.message),n}}),we(this,"getPendingSessionProposals",()=>{try{return this.engine.getPendingSessionProposals()}catch(n){throw this.logger.error(n.message),n}}),we(this,"getPendingSessionRequests",()=>{try{return this.engine.getPendingSessionRequests()}catch(n){throw this.logger.error(n.message),n}}),we(this,"registerDeviceToken",n=>{try{return this.engine.registerDeviceToken(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"approveSessionAuthenticate",n=>{try{return this.engine.approveSessionAuthenticate(n)}catch(r){throw this.logger.error(r.message),r}}),we(this,"rejectSessionAuthenticate",n=>{try{return this.engine.rejectSessionAuthenticate(n)}catch(r){throw this.logger.error(r.message),r}}),we(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||ml,this.signConfig=e.signConfig,this.core=e.core,this.logger=this.core.logger,this.engine=new $U(this),this.pay=void 0}static async init(e){const n=new c2(e);return await n.initialize(),n}async initialize(){this.logger.trace("Initialized");try{await this.engine.init(),By.isAvailable()&&(this.pay=new By(TU({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}}};we(Qm,"notifications",AU);let e2=Qm;const NU=e2;ze.CLIENT_CONTEXT=ml,ze.CLIENT_STORAGE_OPTIONS=bI,ze.CLIENT_STORAGE_PREFIX=yI,ze.IWalletKit=Wm,ze.IWalletKitEngine=Ym,ze.IWalletKitEvents=mU,ze.PROTOCOL=$y,ze.PROTOCOL_VERSION=gI,ze.REQUEST_CONTEXT=wI,ze.WalletKit=NU,ze.default=e2,ze.isPaymentLink=OU,Object.defineProperty(ze,"__esModule",{value:!0})});
41
41
  //# sourceMappingURL=index.umd.js.map