@frak-labs/nexus-sdk 0.0.42 → 0.0.43

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.
@@ -0,0 +1,14 @@
1
+ var NexusSDK=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=(e,t)=>()=>(e&&(t=e(e=0)),t);function n(e,{strict:t=!0}={}){return!e||typeof e!=`string`?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith(`0x`)}var r=t((()=>{}));function i(e){return n(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}var a=t((()=>{r()})),o,s=t((()=>{o=`2.46.3`}));function c(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause!==void 0?c(e.cause,t):t?null:e}var l,u,d=t((()=>{s(),l={getDocsUrl:({docsBaseUrl:e,docsPath:t=``,docsSlug:n})=>t?`${e??`https://viem.sh`}${t}${n?`#${n}`:``}`:void 0,version:`viem@${o}`},u=class e extends Error{constructor(t,n={}){let r=n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details,i=n.cause instanceof e&&n.cause.docsPath||n.docsPath,a=l.getDocsUrl?.({...n,docsPath:i}),s=[t||`An error occurred.`,``,...n.metaMessages?[...n.metaMessages,``]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],...l.version?[`Version: ${l.version}`]:[]].join(`
2
+ `);super(s,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,`details`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`docsPath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`metaMessages`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`shortMessage`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`version`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`name`,{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=o}walk(e){return c(this,e)}}})),f,p=t((()=>{d(),f=class extends u{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:`SizeExceedsPaddingSizeError`})}}}));function m(e,{dir:t,size:n=32}={}){return typeof e==`string`?h(e,{dir:t,size:n}):g(e,{dir:t,size:n})}function h(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new f({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function g(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new f({size:e.length,targetSize:n,type:`bytes`});let r=new Uint8Array(n);for(let i=0;i<n;i++){let a=t===`right`;r[a?i:n-i-1]=e[a?i:e.length-i-1]}return r}var ee=t((()=>{p()})),_,te,ne=t((()=>{d(),_=class extends u{constructor({max:e,min:t,signed:n,size:r,value:i}){super(`Number "${i}" is not in safe ${r?`${r*8}-bit ${n?`signed`:`unsigned`} `:``}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:`IntegerOutOfRangeError`})}},te=class extends u{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}}}));function v(e,{size:t}){if(i(e)>t)throw new te({givenSize:i(e),maxSize:t})}var re=t((()=>{ne(),a()}));function y(e,t={}){return typeof e==`number`||typeof e==`bigint`?x(e,t):typeof e==`string`?ae(e,t):typeof e==`boolean`?ie(e,t):b(e,t)}function ie(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(v(n,{size:t.size}),m(n,{size:t.size})):n}function b(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=oe[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(v(r,{size:t.size}),m(r,{dir:`right`,size:t.size})):r}function x(e,t={}){let{signed:n,size:r}=t,i=BigInt(e),a;r?a=n?(1n<<BigInt(r)*8n-1n)-1n:2n**(BigInt(r)*8n)-1n:typeof e==`number`&&(a=BigInt(2**53-1));let o=typeof a==`bigint`&&n?-a-1n:0;if(a&&i>a||i<o){let t=typeof e==`bigint`?`n`:``;throw new _({max:a?`${a}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}let s=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?m(s,{size:r}):s}function ae(e,t={}){return b(se.encode(e),t)}var oe,se;function ce(e,t={}){return typeof e==`number`||typeof e==`bigint`?de(e,t):typeof e==`boolean`?le(e,t):n(e)?S(e,t):fe(e,t)}function le(e,t={}){let n=new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(v(n,{size:t.size}),m(n,{size:t.size})):n}function ue(e){if(e>=C.zero&&e<=C.nine)return e-C.zero;if(e>=C.A&&e<=C.F)return e-(C.A-10);if(e>=C.a&&e<=C.f)return e-(C.a-10)}function S(e,t={}){let n=e;t.size&&(v(n,{size:t.size}),n=m(n,{dir:`right`,size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);let i=r.length/2,a=new Uint8Array(i);for(let e=0,t=0;e<i;e++){let n=ue(r.charCodeAt(t++)),i=ue(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new u(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function de(e,t){return S(x(e,t))}function fe(e,t={}){let n=pe.encode(e);return typeof t.size==`number`?(v(n,{size:t.size}),m(n,{dir:`right`,size:t.size})):n}var pe,C,me,he;function ge(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function _e(e,...t){if(!ge(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function ve(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function ye(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}var be,xe;function Se(e,t){let r=t||`hex`,i=xe(n(e,{strict:!1})?ce(e):e);return r===`bytes`?i:y(i)}var Ce;function we(e,t){if(w.has(`${e}.${t}`))return w.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=Se(fe(n),`bytes`),i=(t?n.substring(`${t}0x`.length):n).split(``);for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&i[e]&&(i[e]=i[e].toUpperCase()),(r[e>>1]&15)>=8&&i[e+1]&&(i[e+1]=i[e+1].toUpperCase());let a=`0x${i.join(``)}`;return w.set(`${e}.${t}`,a),a}var w;function T(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(E.has(r))return E.get(r);let i=Te.test(e)?e.toLowerCase()===e?!0:n?we(e)===e:!0:!1;return E.set(r,i),i}var Te,E;function Ee(e,t){if(!T(e,{strict:!1}))throw new Ce({address:e});if(!T(t,{strict:!1}))throw new Ce({address:t});return e.toLowerCase()===t.toLowerCase()}let D=256,O;function De(e=11){if(!O||D+e>256*2){O=``,D=0;for(let e=0;e<256;e++)O+=(256+Math.random()*256|0).toString(16).substring(1)}return O.substring(D,D+++e)}let k={parseError:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internalError:-32603,serverError:-32e3,clientNotConnected:-32001,configError:-32002,corruptedResponse:-32003,clientAborted:-32004,walletNotConnected:-32005,serverErrorForInteractionDelegation:-32006,userRejected:-32007};var A=class extends Error{constructor(e,t,n){super(t),this.code=e,this.data=n}toJSON(){return{code:this.code,message:this.message,data:this.data}}},j=class{_promise;_resolve;_reject;constructor(){this._promise=new Promise((e,t)=>{this._resolve=e,this._reject=t})}get promise(){return this._promise}resolve=e=>{this._resolve?.(e)};reject=e=>{this._reject?.(e)}};function Oe(e){let{emittingTransport:t,listeningTransport:n,targetOrigin:r,middleware:i=[],lifecycleHandlers:a}=e,o=new Map;function s(e){return typeof e!=`object`||!e?!1:`clientLifecycle`in e||`iframeLifecycle`in e}function c(e){return typeof e!=`object`||!e?!1:`id`in e&&`topic`in e&&`data`in e}async function l(e){try{`clientLifecycle`in e&&a?.clientLifecycle?await a.clientLifecycle(e,{origin:r,source:null}):`iframeLifecycle`in e&&a?.iframeLifecycle&&await a.iframeLifecycle(e,{origin:r,source:null})}catch(e){console.error(`[RPC Client] Lifecycle handler error:`,e)}}async function u(e){let t={origin:r,source:null};for(let n of i)n.onRequest&&await n.onRequest(e,t);return e}async function d(e,t){let n={origin:r,source:null},a=t;for(let t of i)t.onResponse&&(a=await t.onResponse(e,a,n));return a}async function f(e){try{let t=new URL(e.origin).origin.toLowerCase(),n=new URL(r).origin.toLowerCase();if(t!==n){console.log(`Not expected origin`,t,n);return}}catch(e){console.error(`[RPC Client] Invalid origin`,e);return}if(s(e.data)){await l(e.data);return}if(!c(e.data))return;let t;try{let n=e.data.data,r=n instanceof Uint8Array||ArrayBuffer.isView(n)?{result:n}:n;t=await d(e.data,r)}catch(e){console.error(`[RPC Client] Middleware error on response:`,e);return}let n=o.get(e.data.id);n&&n(t)}async function p(e){let n=e;try{n=await u(e)}catch(e){throw console.error(`[RPC Client] Middleware error on request:`,e),e}t.postMessage(n,r)}function m(e){t.postMessage(e,r)}function h(){return`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}n.addEventListener(`message`,f);function g(e){let t=h(),n=new j;return o.set(t,e=>{e.error?n.reject(new A(e.error.code,e.error.message,e.error.data)):n.resolve(e.result),o.delete(t)}),p({id:t,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{o.delete(t),n.reject(e)}),n.promise}function ee(e,t){let n=h();return o.set(n,e=>{e.error?(console.error(`[RPC Client] Listener error:`,e.error),o.delete(n)):t(e.result)}),p({id:n,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{console.error(`[RPC Client] Failed to send listener request:`,e),o.delete(n)}),()=>{o.delete(n)}}function _(){n.removeEventListener(`message`,f),o.clear()}return{request:g,listen:ee,sendLifecycle:m,cleanup:_}}function ke(e){return new TextEncoder().encode(JSON.stringify(e))}function Ae(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}let M=`frak-client-id`;function N(){return typeof crypto<`u`&&crypto.randomUUID?crypto.randomUUID():`xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx`.replace(/[xy]/g,e=>{let t=Math.random()*16|0;return(e===`x`?t:t&3|8).toString(16)})}function P(){if(typeof window>`u`||!window.localStorage)return console.warn(`[Frak SDK] No Window / localStorage available to save the clientId`),N();let e=localStorage.getItem(M);return e||(e=N(),localStorage.setItem(M,e)),e}function je({domain:e}={}){return Se(y((e??window.location.host).replace(`www.`,``)))}function F(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function I(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(e.length+(t===0?0:4-t),`=`)),e=>e.charCodeAt(0))}function Me(e){return F(ke(e))}function Ne(e,t,n,r,i,a){let o=Me(Pe({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,merchantId:n,metadata:{name:r,css:a,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink},clientId:i})),s=new URL(e);return s.pathname=`/sso`,s.searchParams.set(`p`,o),s.toString()}function Pe(e){return{r:e.redirectUrl,cId:e.clientId,d:e.directExit,l:e.lang,m:e.merchantId,md:{n:e.metadata?.name,css:e.metadata?.css,l:e.metadata?.logoUrl,h:e.metadata?.homepageLink}}}let Fe=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,Ie=`frak-sso`;async function Le(e,t){let{metadata:n,customizations:r,walletUrl:i}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]});let a=t.ssoPopupUrl??Ne(i??`https://wallet.frak.id`,t,je(),n.name,P(),r?.css),o=window.open(a,Ie,Fe);if(!o)throw Error(`Popup was blocked. Please allow popups for this site.`);return o.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}let Re=`https://backend.frak.id`;function ze(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function Be(e){return ze(e)?`http://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:Re}function L(e){if(e)return Be(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return Be(e)}return Re}let R=`fCtx`;function Ve(e){if(e?.r)try{return F(S(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function He(e){if(!(!e||e.length===0))try{return{r:b(I(e),{size:20})}}catch(t){console.error(`Error decompressing Frak context`,{e:t,context:e})}}function Ue({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(R);return t?He(t):null}function We({url:e,context:t}){if(!e)return null;let n=Ue({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let i=Ve(r);if(!i)return null;let a=new URL(e);return a.searchParams.set(R,i),a.toString()}function z(e){let t=new URL(e);return t.searchParams.delete(R),t.toString()}function Ge({url:e,context:t}){if(!window.location?.href||typeof window>`u`){console.error(`No window found, can't update context`);return}let n=e??window.location.href,r;r=t===null?z(n):We({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}let B={compress:Ve,decompress:He,parse:Ue,update:We,remove:z,replaceUrl:Ge},V=`frak-merchant-id`,H,U;async function W(e,t){if(H)return H;if(typeof window<`u`){let e=window.sessionStorage.getItem(V);if(e)return H=e,e}if(U)return U;U=Ke(e,t);let n=await U;return U=void 0,n}async function Ke(e,t){let n=e??(typeof window<`u`?window.location.hostname:``);if(n)try{let e=L(t),r=await fetch(`${e}/user/merchant/resolve?domain=${encodeURIComponent(n)}`);if(!r.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${n}: ${r.status}`);return}let i=await r.json();return H=i.merchantId,typeof window<`u`&&window.sessionStorage.setItem(V,i.merchantId),H}catch(e){console.warn(`[Frak SDK] Failed to fetch merchantId:`,e);return}}function qe(){H=void 0,U=void 0,typeof window<`u`&&window.sessionStorage.removeItem(V)}async function Je(e,t){return e.metadata?.merchantId?e.metadata.merchantId:W(void 0,t)}function G(e,t,n={}){if(!e){console.debug(`[Frak] No client provided, skipping event tracking`);return}try{e.openPanel?.track(t,n)}catch(e){console.debug(`[Frak] Failed to track event:`,t,e)}}var Ye=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":`application/json`,...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[t,n]of Object.entries(this.headers)){let r=await n;r!==null&&(e[t]=r)}return e}addHeader(e,t){this.headers[e]=t}async post(e,t,n,r){try{let r=await fetch(e,{method:`POST`,headers:await this.resolveHeaders(),body:t?JSON.stringify(t??{}):void 0,keepalive:!0,...n});if(r.status===401)return null;if(r.status!==200&&r.status!==202)throw Error(`HTTP error! status: ${r.status}`);let i=await r.text();return i?JSON.parse(i):null}catch(i){if(r<this.maxRetries){let i=this.initialRetryDelay*2**r;return await new Promise(e=>setTimeout(e,i)),this.post(e,t,n,r+1)}return console.error(`Max retries reached:`,i),null}}async fetch(e,t,n={}){let r=`${this.baseUrl}${e}`;return this.post(r,t,n,0)}},Xe=class{constructor(e){this.options=e,this.queue=[];let t={"openpanel-client-id":e.clientId};e.clientSecret&&(t[`openpanel-client-secret`]=e.clientSecret),t[`openpanel-sdk-name`]=e.sdk||`node`,t[`openpanel-sdk-version`]=e.sdkVersion||`1.0.4`,this.api=new Ye({baseUrl:e.apiUrl||`https://api.openpanel.dev`,defaultHeaders:t})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}async send(e){return this.options.disabled||this.options.filter&&!this.options.filter(e)?Promise.resolve():this.options.waitForProfile&&!this.profileId?(this.queue.push(e),Promise.resolve()):this.api.fetch(`/track`,e)}setGlobalProperties(e){this.global={...this.global,...e}}async track(e,t){return this.log(`track event`,e,t),this.send({type:`track`,payload:{name:e,profileId:t?.profileId??this.profileId,properties:{...this.global??{},...t??{}}}})}async identify(e){if(this.log(`identify user`,e),e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:`identify`,payload:{...e,properties:{...this.global,...e.properties}}})}async alias(e){}async increment(e){return this.send({type:`increment`,payload:e})}async decrement(e){return this.send({type:`decrement`,payload:e})}async revenue(e,t){let n=t?.deviceId;return delete t?.deviceId,this.track(`revenue`,{...t??{},...n?{__deviceId:n}:{},__revenue:e})}async fetchDeviceId(){return(await this.api.fetch(`/track/device-id`,void 0,{method:`GET`,keepalive:!1}))?.deviceId??``}clear(){this.profileId=void 0}flush(){this.queue.forEach(e=>{this.send({...e,payload:{...e.payload,profileId:e.payload.profileId??this.profileId}})}),this.queue=[]}log(...e){this.options.debug&&console.log(`[OpenPanel.dev]`,...e)}};function Ze(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var Qe=class extends Xe{constructor(e){if(super({sdk:`web`,sdkVersion:`1.0.7`,...e}),this.options=e,this.lastPath=``,this.pendingRevenues=[],!this.isServer()){try{let e=sessionStorage.getItem(`openpanel-pending-revenues`);if(e){let t=JSON.parse(e);Array.isArray(t)&&(this.pendingRevenues=t)}}catch{this.pendingRevenues=[]}this.setGlobalProperties({__referrer:document.referrer}),this.options.trackScreenViews&&(this.trackScreenViews(),setTimeout(()=>this.screenView(),0)),this.options.trackOutgoingLinks&&this.trackOutgoingLinks(),this.options.trackAttributes&&this.trackAttributes()}}debounce(e,t){clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(e,t)}isServer(){return typeof document>`u`}trackOutgoingLinks(){this.isServer()||document.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`a`);if(n&&t){let e=n.getAttribute(`href`);if(e?.startsWith(`http`))try{let r=new URL(e),i=window.location.hostname;r.hostname!==i&&super.track(`link_out`,{href:e,text:n.innerText||n.getAttribute(`title`)||t.getAttribute(`alt`)||t.getAttribute(`title`)})}catch{}}})}trackScreenViews(){if(this.isServer())return;let e=history.pushState;history.pushState=function(...t){let n=e.apply(this,t);return window.dispatchEvent(new Event(`pushstate`)),window.dispatchEvent(new Event(`locationchange`)),n};let t=history.replaceState;history.replaceState=function(...e){let n=t.apply(this,e);return window.dispatchEvent(new Event(`replacestate`)),window.dispatchEvent(new Event(`locationchange`)),n},window.addEventListener(`popstate`,()=>{window.dispatchEvent(new Event(`locationchange`))});let n=()=>this.debounce(()=>this.screenView(),50);this.options.trackHashChanges?window.addEventListener(`hashchange`,n):window.addEventListener(`locationchange`,n)}trackAttributes(){this.isServer()||document.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`button`),r=t.closest(`a`),i=n?.getAttribute(`data-track`)?n:r?.getAttribute(`data-track`)?r:null;if(i){let e={};for(let t of i.attributes)t.name.startsWith(`data-`)&&t.name!==`data-track`&&(e[Ze(t.name.replace(/^data-/,``))]=t.value);let t=i.getAttribute(`data-track`);t&&super.track(t,e)}})}screenView(e,t){if(this.isServer())return;let n,r;typeof e==`string`?(n=e,r=t):(n=window.location.href,r=e),this.lastPath!==n&&(this.lastPath=n,super.track(`screen_view`,{...r??{},__path:n,__title:document.title}))}async flushRevenue(){let e=this.pendingRevenues.map(e=>super.revenue(e.amount,e.properties));await Promise.all(e),this.clearRevenue()}clearRevenue(){if(this.pendingRevenues=[],!this.isServer())try{sessionStorage.removeItem(`openpanel-pending-revenues`)}catch{}}pendingRevenue(e,t){if(this.pendingRevenues.push({amount:e,properties:t}),!this.isServer())try{sessionStorage.setItem(`openpanel-pending-revenues`,JSON.stringify(this.pendingRevenues))}catch{}}};function $e(e){return Ae(I(e))}let K=`nexus-wallet-backup`,et=`frakwallet://`;function tt(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}function nt(e){return`intent://${e.slice(13)}#Intent;scheme=frakwallet;end`}function rt(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=tt()&&q(e)?nt(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function q(e){return e.startsWith(et)}let J={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function Y(e){return e&&e in J?e:`eur`}function it(e){return e?J[e]??J.eur:J.eur}function at(e,t){let n=it(t),r=Y(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function ot(e){return e?`${e}Amount`:`eurAmount`}let X={id:`frak-wallet`,name:`frak-wallet`,title:`Frak Wallet`,allow:`publickey-credentials-get *; clipboard-write; web-share *`,style:{width:`0`,height:`0`,border:`0`,position:`absolute`,zIndex:2000001,top:`-1000px`,left:`-1000px`,colorScheme:`auto`}};function st({walletBaseUrl:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);r.id=X.id,r.name=X.name,r.allow=X.allow,r.style.zIndex=X.style.zIndex.toString(),ct({iframe:r,isVisible:!1});let i=t?.walletUrl??e??`https://wallet.frak.id`,a=P();return r.src=`${i}/listener?clientId=${encodeURIComponent(a)}`,new Promise(e=>{r.addEventListener(`load`,()=>e(r)),document.body.appendChild(r)})}function ct({iframe:e,isVisible:t}){if(!t){e.style.width=`0`,e.style.height=`0`,e.style.border=`0`,e.style.position=`fixed`,e.style.top=`-1000px`,e.style.left=`-1000px`;return}e.style.position=`fixed`,e.style.top=`0`,e.style.left=`0`,e.style.width=`100%`,e.style.height=`100%`,e.style.pointerEvents=`auto`}function lt(e=`/listener`){if(!window.opener)return null;let t=t=>{try{return t.location.origin===window.location.origin&&t.location.pathname===e}catch{return!1}};if(t(window.opener))return window.opener;try{let e=window.opener.frames;for(let n=0;n<e.length;n++)if(t(e[n]))return e[n];return null}catch(t){return console.error(`[findIframeInOpener] Error finding iframe with pathname ${e}:`,t),null}}function ut(e,t){if(typeof window>`u`)return;let n=new URL(window.location.href),r=n.searchParams.get(`sso`);r&&(t.then(()=>{e.sendLifecycle({clientLifecycle:`sso-redirect-complete`,data:{compressed:r}}),console.log(`[SSO URL Listener] Forwarded compressed SSO data to iframe`)}).catch(e=>{console.error(`[SSO URL Listener] Failed to forward SSO data:`,e)}),n.searchParams.delete(`sso`),window.history.replaceState({},``,n.toString()),console.log(`[SSO URL Listener] SSO parameter detected and URL cleaned`))}var dt=class e{config;iframe;isSetupDone=!1;lastResponse=null;lastRequest=null;constructor(e,t){this.config=e,this.iframe=t,this.lastRequest=null,this.lastResponse=null}setLastResponse(e,t){this.lastResponse={message:e,response:t,timestamp:Date.now()}}setLastRequest(e){this.lastRequest={event:e,timestamp:Date.now()}}updateSetupStatus(e){this.isSetupDone=e}base64Encode(e){try{return btoa(JSON.stringify(e))}catch(e){return console.warn(`Failed to encode debug data`,e),btoa(`Failed to encode data`)}}getIframeStatus(){return this.iframe?{loading:this.iframe.hasAttribute(`loading`),url:this.iframe.src,readyState:this.iframe.contentDocument?.readyState?this.iframe.contentDocument.readyState===`complete`?1:0:-1,contentWindow:!!this.iframe.contentWindow,isConnected:this.iframe.isConnected}:null}getNavigatorInfo(){return navigator?{userAgent:navigator.userAgent,language:navigator.language,onLine:navigator.onLine,screenWidth:window.screen.width,screenHeight:window.screen.height,pixelRatio:window.devicePixelRatio}:null}gatherDebugInfo(e){let t=this.getIframeStatus(),n=this.getNavigatorInfo(),r=`Unknown`;return e instanceof A?r=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?r=e.message:typeof e==`string`&&(r=e),{timestamp:new Date().toISOString(),encodedUrl:btoa(window.location.href),encodedConfig:this.config?this.base64Encode(this.config):`no-config`,navigatorInfo:n?this.base64Encode(n):`no-navigator`,iframeStatus:t?this.base64Encode(t):`not-iframe`,lastRequest:this.lastRequest?this.base64Encode(this.lastRequest):`No Frak request logged`,lastResponse:this.lastResponse?this.base64Encode(this.lastResponse):`No Frak response logged`,clientStatus:this.isSetupDone?`setup`:`not-setup`,error:r}}static empty(){return new e}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
3
+ Debug Information:
4
+ -----------------
5
+ Timestamp: ${t.timestamp}
6
+ URL: ${t.encodedUrl}
7
+ Config: ${t.encodedConfig}
8
+ Navigator Info: ${t.navigatorInfo}
9
+ IFrame Status: ${t.iframeStatus}
10
+ Last Request: ${t.lastRequest}
11
+ Last Response: ${t.lastResponse}
12
+ Client Status: ${t.clientStatus}
13
+ Error: ${t.error}
14
+ `.trim()}};let ft=(()=>{if(typeof navigator>`u`)return!1;let e=navigator.userAgent;if(!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1))return!1;let t=e.toLowerCase();return t.includes(`instagram`)||t.includes(`fban`)||t.includes(`fbav`)||t.includes(`facebook`)})();function pt(e){e?localStorage.setItem(K,e):localStorage.removeItem(K)}function mt(e,t,n,r){let i=new URL(window.location.href),a=i.searchParams.get(`fmt`)??void 0;e.contentWindow?.postMessage({clientLifecycle:`handshake-response`,data:{token:t,currentUrl:window.location.href,pendingMergeToken:a,configDomain:r,clientId:P()}},n),a&&(i.searchParams.delete(`fmt`),window.history.replaceState({},``,i.toString()))}function ht(e,t){try{let n=new URL(e);return n.searchParams.has(`u`)?(n.searchParams.delete(`u`),n.searchParams.append(`u`,window.location.href),t&&n.searchParams.append(`fmt`,t),n.toString()):e}catch{return e}}function gt(e){let t=new URL(window.location.href);e&&t.searchParams.set(`fmt`,e);let n=t.protocol===`http:`?`x-safari-http`:`x-safari-https`;window.location.href=`${n}://${t.host}${t.pathname}${t.search}${t.hash}`}function _t(e){return e.includes(`/common/social`)}function vt(e,t,n,r){if(q(t)){let i=ht(t,r);rt(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(ft&&_t(t))gt(r);else{let e=ht(t,r);window.location.href=e}}function yt({iframe:e,targetOrigin:t,configDomain:n}){let r=new j;return{handleEvent:async i=>{if(!(`iframeLifecycle`in i))return;let{iframeLifecycle:a,data:o}=i;switch(a){case`connected`:r.resolve(!0);break;case`do-backup`:pt(o.backup);break;case`remove-backup`:localStorage.removeItem(K);break;case`show`:case`hide`:ct({iframe:e,isVisible:a===`show`});break;case`handshake`:mt(e,o.token,t,n);break;case`redirect`:vt(e,o.baseRedirectUrl,t,o.mergeToken);break}},isConnected:r.promise}}function Z({config:e,iframe:t}){let n=e?.walletUrl??`https://wallet.frak.id`,r=yt({iframe:t,targetOrigin:n,configDomain:e.domain}),i=new dt(e,t);if(!t.contentWindow)throw new A(k.configError,`The iframe does not have a content window`);let a=Oe({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await r.isConnected)throw new A(k.clientNotConnected,`The iframe provider isn't connected yet`);return t}},{onRequest(e,t){return i.setLastRequest(e),t},onResponse(e,t){return i.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await r.handleEvent(e)}}}),o=bt(a,r),s=async()=>{o(),a.cleanup(),t.remove()},c;console.log(`[Frak SDK] Initializing OpenPanel`),c=new Qe({apiUrl:`https://op-api.gcp.frak.id`,clientId:`f305d11d-b93b-487c-80d4-92deb7903e98`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:e,payload:t})=>(e!==`track`||!t?.properties||`sdkVersion`in t.properties||(t.properties={...t.properties,sdkVersion:`0.2.0`,userAnonymousClientId:P()}),!0)}),c.setGlobalProperties({sdkVersion:`0.2.0`,userAnonymousClientId:P()}),c.init();let l=xt({config:e,rpcClient:a,lifecycleManager:r}).then(()=>i.updateSetupStatus(!0));return{config:e,debugInfo:i,waitForConnection:r.isConnected,waitForSetup:l,request:a.request,listenerRequest:a.listen,destroy:s,openPanel:c}}function bt(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function xt({config:e,rpcClient:t,lifecycleManager:n}){await n.isConnected,ut(t,n.isConnected);async function r(){let n=e.customizations?.css;if(!n)return;let r={clientLifecycle:`modal-css`,data:{cssLink:n}};t.sendLifecycle(r)}async function i(){let n=e.customizations?.i18n;if(!n)return;let r={clientLifecycle:`modal-i18n`,data:{i18n:n}};t.sendLifecycle(r)}async function a(){if(typeof window>`u`)return;let e=window.localStorage.getItem(K);if(!e)return;let n={clientLifecycle:`restore-backup`,data:{backup:e}};t.sendLifecycle(n)}await Promise.allSettled([r(),i(),a()])}async function St({config:e}){let t=Ct(e),n=await st({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=Z({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function Ct(e){let t=Y(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function wt(e){document.readyState===`complete`||document.readyState===`interactive`?setTimeout(e,1):document.addEventListener?document.addEventListener(`DOMContentLoaded`,e):document.attachEvent(`onreadystatechange`,()=>{document.readyState===`complete`&&e()})}async function Tt(e,t,n=`text/javascript`){return document.getElementById(e)?Promise.resolve(!0):new Promise((r,i)=>{let a=document.createElement(`script`);a.id=e,a.src=t,a.defer=!0,a.type=n,a.onload=()=>r(!0),a.onerror=()=>i(Error(`Script load error for ${t}`)),document.head.appendChild(a)})}function Et(){Dt(),Ot()}function Dt(){window.FrakSetup.config={walletUrl:`https://wallet.frak.id`,metadata:{name:`Gapianne`,lang:`fr`,currency:`eur`,logoUrl:`https://gapianne.com/cdn/shop/files/logo-gapianne_7a65f4c4-54e8-4831-afa2-0849e4c5f8de.png`,homepageLink:`https://gapianne.com/`},customizations:{i18n:{"sharing.title":`Prêt(e) à révéler un secret bien-être ?`,"sharing.text":`Découvre ce produit chez Gapianne`,"sdk.wallet.login.text":`Créez votre porte-monnaie avec **{{ productName }}** et recevez **{{ estimatedReward }}** par ami(e) parrainé(e)`}},domain:window.location.host},window.FrakSetup.modalConfig={login:{allowSso:!0},metadata:{isDismissible:!0}},window.FrakSetup.modalShareConfig={link:window.location.href},window.FrakSetup.modalWalletConfig={metadata:{position:`left`}}}function Ot(){let e=document.querySelectorAll(`#nexus-share-button > button`);for(let t of Array.from(e)){let e=document.createElement(`frak-button-share`);e.setAttribute(`text`,`PARTAGE ET GAGNE {REWARD} !`),e.setAttribute(`no-reward-text`,`PARTAGE ET GAGNE`),e.setAttribute(`use-reward`,`true`),e.setAttribute(`show-wallet`,`true`),e.setAttribute(`classname`,`button w-full`),t.replaceWith(e)}}let kt={"gapianne.com":Et};function At(){let e=kt[window.location.host];e&&(e(),Tt(`frak-components`,`https://cdn.jsdelivr.net/npm/@frak-labs/components@latest/cdn/components.js`,`module`))}function jt(){return De(96)}async function Mt(e,t){return await e.request({method:`frak_displayEmbeddedWallet`,params:[t,e.config.metadata]})}async function Q(e,{steps:t,metadata:n}){return await e.request({method:`frak_displayModal`,params:[t,n,e.config.metadata]})}async function Nt(e){if(typeof window>`u`)return;let t=P();if(!t)return;let n=await W();if(!n)return;let r=`frak-identity-ensured-${n}`;if(!window.sessionStorage.getItem(r))try{let i=L();(await fetch(`${i}/user/identity/ensure`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":e,"x-frak-client-id":t},body:JSON.stringify({merchantId:n})})).ok&&window.sessionStorage.setItem(r,`1`)}catch{}}async function Pt(e){return await e.request({method:`frak_getMerchantInformation`})}async function Ft(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function It(e,t){try{await e.request({method:`frak_sendInteraction`,params:[t,{clientId:P()}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}async function Lt(e,{walletStatus:t,frakContext:n,modalConfig:r,options:i}){if(!n?.r)return`no-referrer`;G(e,`user_referred_started`,{properties:{referrer:n?.r,walletStatus:t?.key}}),It(e,{type:`arrival`,referrerWallet:n.r,landingUrl:typeof window<`u`?window.location.href:void 0});let a=!1;async function o(){if(!a)return a=!0,zt(e,{modalConfig:{...r,loggedIn:{action:{key:`referred`}}},walletStatus:t})}try{let{status:r,currentWallet:a}=await Rt({initialWalletStatus:t,getFreshWalletStatus:o,frakContext:n});return B.replaceUrl({url:window.location?.href,context:i?.alwaysAppendUrl?{r:a}:null}),G(e,`user_referred_completed`,{properties:{status:r,referrer:n?.r,wallet:a}}),r}catch(r){return console.log(`Error processing referral`,{error:r}),G(e,`user_referred_error`,{properties:{referrer:n?.r,error:r instanceof A?`[${r.code}] ${r.name} - ${r.message}`:r instanceof Error?r.message:`undefined`}}),B.replaceUrl({url:window.location?.href,context:i?.alwaysAppendUrl?{r:t?.wallet}:null}),Bt(r)}}async function Rt({initialWalletStatus:e,getFreshWalletStatus:t,frakContext:n}){let r=e?.wallet;return r||=await t(),r&&Ee(n.r,r)?{status:`self-referral`,currentWallet:r}:{status:`success`,currentWallet:r}}async function zt(e,{modalConfig:t,walletStatus:n}){return n?.key===`connected`?n.wallet??void 0:(await Mt(e,t??{}))?.wallet??void 0}function Bt(e){if(e instanceof A)switch(e.code){case k.walletNotConnected:return`no-wallet`;default:return`error`}return`error`}async function Vt(e,{modalConfig:t,options:n}={}){let r=B.parse({url:window.location.href}),i=await Ut(e);try{return await Lt(e,{walletStatus:i,frakContext:r,modalConfig:t,options:n})}catch(e){console.warn(`Error processing referral`,{error:e})}}async function Ht(e){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let t=window.sessionStorage.getItem(`frak-wallet-interaction-token`),n=P();if(!t&&!n){console.warn(`[Frak] No identity found, skipping purchase check`);return}let r=window.sessionStorage.getItem(`frak-merchant-id`),i=e.merchantId??r??await W();if(!i){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let a={Accept:`application/json`,"Content-Type":`application/json`};t&&(a[`x-wallet-sdk-auth`]=t),n&&(a[`x-frak-client-id`]=n);let o=L();await fetch(`${o}/user/track/purchase`,{method:`POST`,headers:a,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:i})})}function Ut(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(Wt(e,t),t));let n=new j,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{Wt(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function Wt(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),Nt(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function Gt(e,{metadata:t,login:n}){return $(e,{steps:{login:n??{}},metadata:t})}function $(e,t){function n(n){return $(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return $(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return $(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n){return n&&(t.metadata=n(t.metadata??{})),await Q(e,t)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function Kt(e,{tx:t,metadata:n}){return(await Q(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function qt(e,{siwe:t,metadata:n}){let r=e.config?.domain??window.location.host,i=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await Q(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??jt(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}let Jt=Z;return wt(At),e.DEEP_LINK_SCHEME=et,e.DebugInfoGatherer=dt,e.FrakContextManager=B,e.base64urlDecode=I,e.base64urlEncode=F,e.baseIframeProps=X,e.clearMerchantIdCache=qe,e.compressJsonToB64=Me,e.computeLegacyProductId=je,e.createIFrameFrakClient=Z,e.createIFrameNexusClient=Jt,e.createIframe=st,e.decompressJsonFromB64=$e,e.displayEmbeddedWallet=Mt,e.displayModal=Q,e.ensureIdentity=Nt,e.fetchMerchantId=W,e.findIframeInOpener=lt,e.formatAmount=at,e.generateSsoUrl=Ne,e.getBackendUrl=L,e.getClientId=P,e.getCurrencyAmountKey=ot,e.getMerchantInformation=Pt,e.getSupportedCurrency=Y,e.getSupportedLocale=it,e.isChromiumAndroid=tt,e.isFrakDeepLink=q,e.locales=J,e.modalBuilder=Gt,e.openSso=Le,e.prepareSso=Ft,e.processReferral=Lt,e.referralInteraction=Vt,e.resolveMerchantId=Je,e.sendInteraction=It,e.sendTransaction=Kt,e.setupClient=St,e.siweAuthenticate=qt,e.ssoPopupFeatures=Fe,e.ssoPopupName=Ie,e.toAndroidIntentUrl=nt,e.trackEvent=G,e.trackPurchaseStatus=Ht,e.triggerDeepLinkWithFallback=rt,e.watchWalletStatus=Ut,e})({});
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "url": "https://twitter.com/QNivelais"
12
12
  }
13
13
  ],
14
- "version": "0.0.42",
14
+ "version": "0.0.43",
15
15
  "description": "Legacy SDK, only used here to provide nice wrapper and redirection for older implementation, to not break anything and keep them updated with latest security updates.",
16
16
  "repository": {
17
17
  "url": "https://github.com/frak-id/wallet",
@@ -48,13 +48,13 @@
48
48
  "publish": "echo 'Publishing legacy...'"
49
49
  },
50
50
  "dependencies": {
51
- "@frak-labs/core-sdk": "0.1.0",
51
+ "@frak-labs/core-sdk": "0.2.0",
52
52
  "@frak-labs/ui": "0.0.0"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@frak-labs/dev-tooling": "0.0.0",
56
- "@rolldown/plugin-node-polyfills": "^1.0.0",
57
- "tsdown": "^0.18.2",
56
+ "@rolldown/plugin-node-polyfills": "^1.0.3",
57
+ "tsdown": "^0.20.3",
58
58
  "typescript": "^5.9.3"
59
59
  }
60
60
  }
@@ -1,14 +0,0 @@
1
- var NexusSDK=(function(e){var t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,a=(e,t)=>()=>(e&&(t=e(e=0)),t),o=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),s=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n&&t(r,Symbol.toStringTag,{value:`Module`}),r},c=(e,a,o,s)=>{if(a&&typeof a==`object`||typeof a==`function`)for(var c=r(a),l=0,u=c.length,d;l<u;l++)d=c[l],!i.call(e,d)&&d!==o&&t(e,d,{get:(e=>a[e]).bind(null,d),enumerable:!(s=n(a,d))||s.enumerable});return e},l=e=>i.call(e,`module.exports`)?e[`module.exports`]:c(t({},`__esModule`,{value:!0}),e);function u(e,{strict:t=!0}={}){return!e||typeof e!=`string`?!1:t?/^0x[0-9a-fA-F]*$/.test(e):e.startsWith(`0x`)}var d=a((()=>{}));function f(e){return u(e,{strict:!1})?Math.ceil((e.length-2)/2):e.length}var p=a((()=>{d()})),m,h=a((()=>{m=`2.43.2`}));function g(e,t){return t?.(e)?e:e&&typeof e==`object`&&`cause`in e&&e.cause!==void 0?g(e.cause,t):t?null:e}var _,v,ee=a((()=>{h(),_={getDocsUrl:({docsBaseUrl:e,docsPath:t=``,docsSlug:n})=>t?`${e??`https://viem.sh`}${t}${n?`#${n}`:``}`:void 0,version:`viem@${m}`},v=class e extends Error{constructor(t,n={}){let r=(()=>n.cause instanceof e?n.cause.details:n.cause?.message?n.cause.message:n.details)(),i=(()=>n.cause instanceof e&&n.cause.docsPath||n.docsPath)(),a=_.getDocsUrl?.({...n,docsPath:i}),o=[t||`An error occurred.`,``,...n.metaMessages?[...n.metaMessages,``]:[],...a?[`Docs: ${a}`]:[],...r?[`Details: ${r}`]:[],..._.version?[`Version: ${_.version}`]:[]].join(`
2
- `);super(o,n.cause?{cause:n.cause}:void 0),Object.defineProperty(this,`details`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`docsPath`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`metaMessages`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`shortMessage`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`version`,{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,`name`,{enumerable:!0,configurable:!0,writable:!0,value:`BaseError`}),this.details=r,this.docsPath=i,this.metaMessages=n.metaMessages,this.name=n.name??this.name,this.shortMessage=t,this.version=m}walk(e){return g(this,e)}}})),te,ne,re,ie,ae,oe,se,ce=a((()=>{ee(),oe=class extends v{constructor({offset:e,position:t,size:n}){super(`Slice ${t===`start`?`starting`:`ending`} at offset "${e}" is out-of-bounds (size: ${n}).`,{name:`SliceOffsetOutOfBoundsError`})}},se=class extends v{constructor({size:e,targetSize:t,type:n}){super(`${n.charAt(0).toUpperCase()}${n.slice(1).toLowerCase()} size (${e}) exceeds padding size (${t}).`,{name:`SizeExceedsPaddingSizeError`})}}}));function y(e,{dir:t,size:n=32}={}){return typeof e==`string`?b(e,{dir:t,size:n}):le(e,{dir:t,size:n})}function b(e,{dir:t,size:n=32}={}){if(n===null)return e;let r=e.replace(`0x`,``);if(r.length>n*2)throw new se({size:Math.ceil(r.length/2),targetSize:n,type:`hex`});return`0x${r[t===`right`?`padEnd`:`padStart`](n*2,`0`)}`}function le(e,{dir:t,size:n=32}={}){if(n===null)return e;if(e.length>n)throw new se({size:e.length,targetSize:n,type:`bytes`});let r=new Uint8Array(n);for(let i=0;i<n;i++){let a=t===`right`;r[a?i:n-i-1]=e[a?i:e.length-i-1]}return r}var ue=a((()=>{ce()})),de,fe,pe=a((()=>{ee(),de=class extends v{constructor({max:e,min:t,signed:n,size:r,value:i}){super(`Number "${i}" is not in safe ${r?`${r*8}-bit ${n?`signed`:`unsigned`} `:``}integer range ${e?`(${t} to ${e})`:`(above ${t})`}`,{name:`IntegerOutOfRangeError`})}},fe=class extends v{constructor({givenSize:e,maxSize:t}){super(`Size cannot exceed ${t} bytes. Given size: ${e} bytes.`,{name:`SizeOverflowError`})}}}));function x(e,{size:t}){if(f(e)>t)throw new fe({givenSize:f(e),maxSize:t})}var me=a((()=>{pe(),p()}));function S(e,t={}){return typeof e==`number`||typeof e==`bigint`?C(e,t):typeof e==`string`?_e(e,t):typeof e==`boolean`?he(e,t):ge(e,t)}function he(e,t={}){let n=`0x${Number(e)}`;return typeof t.size==`number`?(x(n,{size:t.size}),y(n,{size:t.size})):n}function ge(e,t={}){let n=``;for(let t=0;t<e.length;t++)n+=ve[e[t]];let r=`0x${n}`;return typeof t.size==`number`?(x(r,{size:t.size}),y(r,{dir:`right`,size:t.size})):r}function C(e,t={}){let{signed:n,size:r}=t,i=BigInt(e),a;r?a=n?(1n<<BigInt(r)*8n-1n)-1n:2n**(BigInt(r)*8n)-1n:typeof e==`number`&&(a=BigInt(2**53-1));let o=typeof a==`bigint`&&n?-a-1n:0;if(a&&i>a||i<o){let t=typeof e==`bigint`?`n`:``;throw new de({max:a?`${a}${t}`:void 0,min:`${o}${t}`,signed:n,size:r,value:`${e}${t}`})}let s=`0x${(n&&i<0?(1n<<BigInt(r*8))+BigInt(i):i).toString(16)}`;return r?y(s,{size:r}):s}function _e(e,t={}){return ge(ye.encode(e),t)}var ve,ye,be=a((()=>{pe(),ue(),me(),ve=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`)),ye=new TextEncoder}));function xe(e,t={}){return typeof e==`number`||typeof e==`bigint`?Te(e,t):typeof e==`boolean`?Se(e,t):u(e)?we(e,t):Ee(e,t)}function Se(e,t={}){let n=new Uint8Array(1);return n[0]=Number(e),typeof t.size==`number`?(x(n,{size:t.size}),y(n,{size:t.size})):n}function Ce(e){if(e>=w.zero&&e<=w.nine)return e-w.zero;if(e>=w.A&&e<=w.F)return e-(w.A-10);if(e>=w.a&&e<=w.f)return e-(w.a-10)}function we(e,t={}){let n=e;t.size&&(x(n,{size:t.size}),n=y(n,{dir:`right`,size:t.size}));let r=n.slice(2);r.length%2&&(r=`0${r}`);let i=r.length/2,a=new Uint8Array(i);for(let e=0,t=0;e<i;e++){let n=Ce(r.charCodeAt(t++)),i=Ce(r.charCodeAt(t++));if(n===void 0||i===void 0)throw new v(`Invalid byte sequence ("${r[t-2]}${r[t-1]}" in "${r}").`);a[e]=n*16+i}return a}function Te(e,t){return we(C(e,t))}function Ee(e,t={}){let n=De.encode(e);return typeof t.size==`number`?(x(n,{size:t.size}),y(n,{dir:`right`,size:t.size})):n}var De,w,Oe=a((()=>{ee(),d(),ue(),me(),be(),De=new TextEncoder,w={zero:48,nine:57,A:65,F:70,a:97,f:102}})),ke,Ae;function je(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`}function T(e,...t){if(!je(e))throw Error(`Uint8Array expected`);if(t.length>0&&!t.includes(e.length))throw Error(`Uint8Array expected of length `+t+`, got length=`+e.length)}function Me(e,t=!0){if(e.destroyed)throw Error(`Hash instance has been destroyed`);if(t&&e.finished)throw Error(`Hash#digest() has already been called`)}function Ne(e,t){T(e);let n=t.outputLen;if(e.length<n)throw Error(`digestInto() expects output buffer of length at least `+n)}function E(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Pe(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function D(e,t){return e<<32-t|e>>>t}function Fe(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function Ie(e){if(typeof e!=`string`)throw Error(`string expected`);return new Uint8Array(new TextEncoder().encode(e))}function Le(e){return typeof e==`string`&&(e=Ie(e)),T(e),e}function Re(e){let t=t=>e().update(Le(t)).digest(),n=e();return t.outputLen=n.outputLen,t.blockLen=n.blockLen,t.create=()=>e(),t}var ze,Be,Ve=a((()=>{Be=class{}})),He;function Ue(e,t){let n=t||`hex`,r=He(u(e,{strict:!1})?xe(e):e);return n===`bytes`?r:S(r)}var We;function Ge(e,t){if(Ke.has(`${e}.${t}`))return Ke.get(`${e}.${t}`);let n=t?`${t}${e.toLowerCase()}`:e.substring(2).toLowerCase(),r=Ue(Ee(n),`bytes`),i=(t?n.substring(`${t}0x`.length):n).split(``);for(let e=0;e<40;e+=2)r[e>>1]>>4>=8&&i[e]&&(i[e]=i[e].toUpperCase()),(r[e>>1]&15)>=8&&i[e+1]&&(i[e+1]=i[e+1].toUpperCase());let a=`0x${i.join(``)}`;return Ke.set(`${e}.${t}`,a),a}var Ke;function qe(e,t){let{strict:n=!0}=t??{},r=`${e}.${n}`;if(Ye.has(r))return Ye.get(r);let i=(()=>Je.test(e)?e.toLowerCase()===e?!0:n?Ge(e)===e:!0:!1)();return Ye.set(r,i),i}var Je,Ye;function O(e){return typeof e[0]==`string`?k(e):Xe(e)}function Xe(e){let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}function k(e){return`0x${e.reduce((e,t)=>e+t.replace(`0x`,``),``)}`}function Ze(e,t,n,{strict:r}={}){return u(e,{strict:!1})?tt(e,t,n,{strict:r}):et(e,t,n,{strict:r})}function Qe(e,t){if(typeof t==`number`&&t>0&&t>f(e)-1)throw new oe({offset:t,position:`start`,size:f(e)})}function $e(e,t,n){if(typeof t==`number`&&typeof n==`number`&&f(e)!==n-t)throw new oe({offset:n,position:`end`,size:f(e)})}function et(e,t,n,{strict:r}={}){Qe(e,t);let i=e.slice(t,n);return r&&$e(i,t,n),i}function tt(e,t,n,{strict:r}={}){Qe(e,t);let i=`0x${e.replace(`0x`,``).slice((t??0)*2,(n??e.length)*2)}`;return r&&$e(i,t,n),i}var nt;function rt(e,t){if(e.length!==t.length)throw new re({expectedLength:e.length,givenLength:t.length});let n=ot(it({params:e,values:t}));return n.length===0?`0x`:n}function it({params:e,values:t}){let n=[];for(let r=0;r<e.length;r++)n.push(at({param:e[r],value:t[r]}));return n}function at({param:e,value:t}){let n=mt(e.type);if(n){let[r,i]=n;return ct(t,{length:r,param:{...e,type:i}})}if(e.type===`tuple`)return pt(t,{param:e});if(e.type===`address`)return st(t);if(e.type===`bool`)return ut(t);if(e.type.startsWith(`uint`)||e.type.startsWith(`int`)){let n=e.type.startsWith(`int`),[,,r=`256`]=nt.exec(e.type)??[];return dt(t,{signed:n,size:Number(r)})}if(e.type.startsWith(`bytes`))return lt(t,{param:e});if(e.type===`string`)return ft(t);throw new ie(e.type,{docsPath:`/docs/contract/encodeAbiParameters`})}function ot(e){let t=0;for(let n=0;n<e.length;n++){let{dynamic:r,encoded:i}=e[n];r?t+=32:t+=f(i)}let n=[],r=[],i=0;for(let a=0;a<e.length;a++){let{dynamic:o,encoded:s}=e[a];o?(n.push(C(t+i,{size:32})),r.push(s),i+=f(s)):n.push(s)}return O([...n,...r])}function st(e){if(!qe(e))throw new We({address:e});return{dynamic:!1,encoded:b(e.toLowerCase())}}function ct(e,{length:t,param:n}){let r=t===null;if(!Array.isArray(e))throw new ae(e);if(!r&&e.length!==t)throw new te({expectedLength:t,givenLength:e.length,type:`${n.type}[${t}]`});let i=!1,a=[];for(let t=0;t<e.length;t++){let r=at({param:n,value:e[t]});r.dynamic&&(i=!0),a.push(r)}if(r||i){let e=ot(a);if(r){let t=C(a.length,{size:32});return{dynamic:!0,encoded:a.length>0?O([t,e]):t}}if(i)return{dynamic:!0,encoded:e}}return{dynamic:!1,encoded:O(a.map(({encoded:e})=>e))}}function lt(e,{param:t}){let[,n]=t.type.split(`bytes`),r=f(e);if(!n){let t=e;return r%32!=0&&(t=b(t,{dir:`right`,size:Math.ceil((e.length-2)/2/32)*32})),{dynamic:!0,encoded:O([b(C(r,{size:32})),t])}}if(r!==Number.parseInt(n,10))throw new ne({expectedSize:Number.parseInt(n,10),value:e});return{dynamic:!1,encoded:b(e,{dir:`right`})}}function ut(e){if(typeof e!=`boolean`)throw new v(`Invalid boolean value: "${e}" (type: ${typeof e}). Expected: \`true\` or \`false\`.`);return{dynamic:!1,encoded:b(he(e))}}function dt(e,{signed:t,size:n=256}){if(typeof n==`number`){let r=2n**(BigInt(n)-(t?1n:0n))-1n,i=t?-r-1n:0n;if(e>r||e<i)throw new de({max:r.toString(),min:i.toString(),signed:t,size:n/8,value:e.toString()})}return{dynamic:!1,encoded:C(e,{size:32,signed:t})}}function ft(e){let t=_e(e),n=Math.ceil(f(t)/32),r=[];for(let e=0;e<n;e++)r.push(b(Ze(t,e*32,(e+1)*32),{dir:`right`}));return{dynamic:!0,encoded:O([b(C(f(t),{size:32})),...r])}}function pt(e,{param:t}){let n=!1,r=[];for(let i=0;i<t.components.length;i++){let a=t.components[i],o=at({param:a,value:e[Array.isArray(e)?i:a.name]});r.push(o),o.dynamic&&(n=!0)}return{dynamic:n,encoded:n?ot(r):O(r.map(({encoded:e})=>e))}}function mt(e){let t=e.match(/^(.*)\[(\d+)?\]$/);return t?[t[2]?Number(t[2]):null,t[1]]:void 0}function ht(e,t,n,r){if(typeof e.setBigUint64==`function`)return e.setBigUint64(t,n,r);let i=BigInt(32),a=BigInt(4294967295),o=Number(n>>i&a),s=Number(n&a),c=r?4:0,l=r?0:4;e.setUint32(t+c,o,r),e.setUint32(t+l,s,r)}function gt(e,t,n){return e&t^~e&n}function _t(e,t,n){return e&t^e&n^t&n}var vt,A,yt=a((()=>{Ve(),vt=class extends Be{constructor(e,t,n,r){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=Pe(this.buffer)}update(e){Me(this),e=Le(e),T(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length;for(let a=0;a<i;){let o=Math.min(r-this.pos,i-a);if(o===r){let t=Pe(e);for(;r<=i-a;a+=r)this.process(t,a);continue}n.set(e.subarray(a,a+o),this.pos),this.pos+=o,a+=o,this.pos===r&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Me(this),Ne(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,E(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;ht(n,r-8,BigInt(this.length*8),i),this.process(n,0);let o=Pe(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen should be aligned to 32bit`);let c=s/4,l=this.get();if(c>l.length)throw Error(`_sha2: outputLen bigger than state`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:t,buffer:n,length:r,finished:i,destroyed:a,pos:o}=this;return e.destroyed=a,e.finished=i,e.length=r,e.pos=o,r%t&&e.buffer.set(n),e}clone(){return this._cloneInto()}},A=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225])})),bt,j,xt,St;a((()=>{yt(),Ve(),bt=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]),j=new Uint32Array(64),xt=class extends vt{constructor(e=32){super(64,e,8,!1),this.A=A[0]|0,this.B=A[1]|0,this.C=A[2]|0,this.D=A[3]|0,this.E=A[4]|0,this.F=A[5]|0,this.G=A[6]|0,this.H=A[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}process(e,t){for(let n=0;n<16;n++,t+=4)j[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=j[e-15],n=j[e-2],r=D(t,7)^D(t,18)^t>>>3;j[e]=(D(n,17)^D(n,19)^n>>>10)+j[e-7]+r+j[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=D(o,6)^D(o,11)^D(o,25),u=l+t+gt(o,s,c)+bt[e]+j[e]|0,d=(D(n,2)^D(n,13)^D(n,22))+_t(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){E(j)}destroy(){this.set(0,0,0,0,0,0,0,0),E(this.buffer)}},St=Re(()=>new xt)}))();let Ct=St;d(),Oe(),be();function wt(e,t){let n=t||`hex`,r=Ct(u(e,{strict:!1})?xe(e):e);return n===`bytes`?r:S(r)}function Tt(e,t){if(!qe(e,{strict:!1}))throw new We({address:e});if(!qe(t,{strict:!1}))throw new We({address:t});return e.toLowerCase()===t.toLowerCase()}let M=256,N;function Et(e=11){if(!N||M+e>256*2){N=``,M=0;for(let e=0;e<256;e++)N+=(256+Math.random()*256|0).toString(16).substring(1)}return N.substring(M,M+++e)}var P=s({__addDisposableResource:()=>Qt,__assign:()=>R,__asyncDelegator:()=>Wt,__asyncGenerator:()=>Ut,__asyncValues:()=>Gt,__await:()=>I,__awaiter:()=>It,__classPrivateFieldGet:()=>Yt,__classPrivateFieldIn:()=>Zt,__classPrivateFieldSet:()=>Xt,__createBinding:()=>z,__decorate:()=>kt,__disposeResources:()=>$t,__esDecorate:()=>jt,__exportStar:()=>Rt,__extends:()=>Dt,__generator:()=>Lt,__importDefault:()=>Jt,__importStar:()=>qt,__makeTemplateObject:()=>Kt,__metadata:()=>Ft,__param:()=>At,__propKey:()=>Nt,__read:()=>zt,__rest:()=>Ot,__rewriteRelativeImportExtension:()=>en,__runInitializers:()=>Mt,__setFunctionName:()=>Pt,__spread:()=>Bt,__spreadArray:()=>Ht,__spreadArrays:()=>Vt,__values:()=>F,default:()=>rn});function Dt(e,t){if(typeof t!=`function`&&t!==null)throw TypeError(`Class extends value `+String(t)+` is not a constructor or null`);L(e,t);function n(){this.constructor=e}e.prototype=t===null?Object.create(t):(n.prototype=t.prototype,new n)}function Ot(e,t){var n={};for(var r in e)Object.prototype.hasOwnProperty.call(e,r)&&t.indexOf(r)<0&&(n[r]=e[r]);if(e!=null&&typeof Object.getOwnPropertySymbols==`function`)for(var i=0,r=Object.getOwnPropertySymbols(e);i<r.length;i++)t.indexOf(r[i])<0&&Object.prototype.propertyIsEnumerable.call(e,r[i])&&(n[r[i]]=e[r[i]]);return n}function kt(e,t,n,r){var i=arguments.length,a=i<3?t:r===null?r=Object.getOwnPropertyDescriptor(t,n):r,o;if(typeof Reflect==`object`&&typeof Reflect.decorate==`function`)a=Reflect.decorate(e,t,n,r);else for(var s=e.length-1;s>=0;s--)(o=e[s])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}function At(e,t){return function(n,r){t(n,r,e)}}function jt(e,t,n,r,i,a){function o(e){if(e!==void 0&&typeof e!=`function`)throw TypeError(`Function expected`);return e}for(var s=r.kind,c=s===`getter`?`get`:s===`setter`?`set`:`value`,l=!t&&e?r.static?e:e.prototype:null,u=t||(l?Object.getOwnPropertyDescriptor(l,r.name):{}),d,f=!1,p=n.length-1;p>=0;p--){var m={};for(var h in r)m[h]=h===`access`?{}:r[h];for(var h in r.access)m.access[h]=r.access[h];m.addInitializer=function(e){if(f)throw TypeError(`Cannot add initializers after decoration has completed`);a.push(o(e||null))};var g=(0,n[p])(s===`accessor`?{get:u.get,set:u.set}:u[c],m);if(s===`accessor`){if(g===void 0)continue;if(typeof g!=`object`||!g)throw TypeError(`Object expected`);(d=o(g.get))&&(u.get=d),(d=o(g.set))&&(u.set=d),(d=o(g.init))&&i.unshift(d)}else (d=o(g))&&(s===`field`?i.unshift(d):u[c]=d)}l&&Object.defineProperty(l,r.name,u),f=!0}function Mt(e,t,n){for(var r=arguments.length>2,i=0;i<t.length;i++)n=r?t[i].call(e,n):t[i].call(e);return r?n:void 0}function Nt(e){return typeof e==`symbol`?e:`${e}`}function Pt(e,t,n){return typeof t==`symbol`&&(t=t.description?`[${t.description}]`:``),Object.defineProperty(e,`name`,{configurable:!0,value:n?`${n} ${t}`:t})}function Ft(e,t){if(typeof Reflect==`object`&&typeof Reflect.metadata==`function`)return Reflect.metadata(e,t)}function It(e,t,n,r){function i(e){return e instanceof n?e:new n(function(t){t(e)})}return new(n||=Promise)(function(n,a){function o(e){try{c(r.next(e))}catch(e){a(e)}}function s(e){try{c(r.throw(e))}catch(e){a(e)}}function c(e){e.done?n(e.value):i(e.value).then(o,s)}c((r=r.apply(e,t||[])).next())})}function Lt(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o=Object.create((typeof Iterator==`function`?Iterator:Object).prototype);return o.next=s(0),o.throw=s(1),o.return=s(2),typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(s){if(r)throw TypeError(`Generator is already executing.`);for(;o&&(o=0,s[0]&&(n=0)),n;)try{if(r=1,i&&(a=s[0]&2?i.return:s[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,s[1])).done)return a;switch(i=0,a&&(s=[s[0]&2,a.value]),s[0]){case 0:case 1:a=s;break;case 4:return n.label++,{value:s[1],done:!1};case 5:n.label++,i=s[1],s=[0];continue;case 7:s=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(s[0]===6||s[0]===2)){n=0;continue}if(s[0]===3&&(!a||s[1]>a[0]&&s[1]<a[3])){n.label=s[1];break}if(s[0]===6&&n.label<a[1]){n.label=a[1],a=s;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(s);break}a[2]&&n.ops.pop(),n.trys.pop();continue}s=t.call(e,n)}catch(e){s=[6,e],i=0}finally{r=a=0}if(s[0]&5)throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}}function Rt(e,t){for(var n in e)n!==`default`&&!Object.prototype.hasOwnProperty.call(t,n)&&z(t,e,n)}function F(e){var t=typeof Symbol==`function`&&Symbol.iterator,n=t&&e[t],r=0;if(n)return n.call(e);if(e&&typeof e.length==`number`)return{next:function(){return e&&r>=e.length&&(e=void 0),{value:e&&e[r++],done:!e}}};throw TypeError(t?`Object is not iterable.`:`Symbol.iterator is not defined.`)}function zt(e,t){var n=typeof Symbol==`function`&&e[Symbol.iterator];if(!n)return e;var r=n.call(e),i,a=[],o;try{for(;(t===void 0||t-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(e){o={error:e}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a}function Bt(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(zt(arguments[t]));return e}function Vt(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;for(var r=Array(e),i=0,t=0;t<n;t++)for(var a=arguments[t],o=0,s=a.length;o<s;o++,i++)r[i]=a[o];return r}function Ht(e,t,n){if(n||arguments.length===2)for(var r=0,i=t.length,a;r<i;r++)(a||!(r in t))&&(a||=Array.prototype.slice.call(t,0,r),a[r]=t[r]);return e.concat(a||Array.prototype.slice.call(t))}function I(e){return this instanceof I?(this.v=e,this):new I(e)}function Ut(e,t,n){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var r=n.apply(e,t||[]),i,a=[];return i=Object.create((typeof AsyncIterator==`function`?AsyncIterator:Object).prototype),s(`next`),s(`throw`),s(`return`,o),i[Symbol.asyncIterator]=function(){return this},i;function o(e){return function(t){return Promise.resolve(t).then(e,d)}}function s(e,t){r[e]&&(i[e]=function(t){return new Promise(function(n,r){a.push([e,t,n,r])>1||c(e,t)})},t&&(i[e]=t(i[e])))}function c(e,t){try{l(r[e](t))}catch(e){f(a[0][3],e)}}function l(e){e.value instanceof I?Promise.resolve(e.value.v).then(u,d):f(a[0][2],e)}function u(e){c(`next`,e)}function d(e){c(`throw`,e)}function f(e,t){e(t),a.shift(),a.length&&c(a[0][0],a[0][1])}}function Wt(e){var t,n;return t={},r(`next`),r(`throw`,function(e){throw e}),r(`return`),t[Symbol.iterator]=function(){return this},t;function r(r,i){t[r]=e[r]?function(t){return(n=!n)?{value:I(e[r](t)),done:!1}:i?i(t):t}:i}}function Gt(e){if(!Symbol.asyncIterator)throw TypeError(`Symbol.asyncIterator is not defined.`);var t=e[Symbol.asyncIterator],n;return t?t.call(e):(e=typeof F==`function`?F(e):e[Symbol.iterator](),n={},r(`next`),r(`throw`),r(`return`),n[Symbol.asyncIterator]=function(){return this},n);function r(t){n[t]=e[t]&&function(n){return new Promise(function(r,a){n=e[t](n),i(r,a,n.done,n.value)})}}function i(e,t,n,r){Promise.resolve(r).then(function(t){e({value:t,done:n})},t)}}function Kt(e,t){return Object.defineProperty?Object.defineProperty(e,`raw`,{value:t}):e.raw=t,e}function qt(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=B(e),r=0;r<n.length;r++)n[r]!==`default`&&z(t,e,n[r]);return tn(t,e),t}function Jt(e){return e&&e.__esModule?e:{default:e}}function Yt(e,t,n,r){if(n===`a`&&!r)throw TypeError(`Private accessor was defined without a getter`);if(typeof t==`function`?e!==t||!r:!t.has(e))throw TypeError(`Cannot read private member from an object whose class did not declare it`);return n===`m`?r:n===`a`?r.call(e):r?r.value:t.get(e)}function Xt(e,t,n,r,i){if(r===`m`)throw TypeError(`Private method is not writable`);if(r===`a`&&!i)throw TypeError(`Private accessor was defined without a setter`);if(typeof t==`function`?e!==t||!i:!t.has(e))throw TypeError(`Cannot write private member to an object whose class did not declare it`);return r===`a`?i.call(e,n):i?i.value=n:t.set(e,n),n}function Zt(e,t){if(t===null||typeof t!=`object`&&typeof t!=`function`)throw TypeError(`Cannot use 'in' operator on non-object`);return typeof e==`function`?t===e:e.has(t)}function Qt(e,t,n){if(t!=null){if(typeof t!=`object`&&typeof t!=`function`)throw TypeError(`Object expected.`);var r,i;if(n){if(!Symbol.asyncDispose)throw TypeError(`Symbol.asyncDispose is not defined.`);r=t[Symbol.asyncDispose]}if(r===void 0){if(!Symbol.dispose)throw TypeError(`Symbol.dispose is not defined.`);r=t[Symbol.dispose],n&&(i=r)}if(typeof r!=`function`)throw TypeError(`Object not disposable.`);i&&(r=function(){try{i.call(this)}catch(e){return Promise.reject(e)}}),e.stack.push({value:t,dispose:r,async:n})}else n&&e.stack.push({async:!0});return t}function $t(e){function t(t){e.error=e.hasError?new nn(t,e.error,`An error was suppressed during disposal.`):t,e.hasError=!0}var n,r=0;function i(){for(;n=e.stack.pop();)try{if(!n.async&&r===1)return r=0,e.stack.push(n),Promise.resolve().then(i);if(n.dispose){var a=n.dispose.call(n.value);if(n.async)return r|=2,Promise.resolve(a).then(i,function(e){return t(e),i()})}else r|=1}catch(e){t(e)}if(r===1)return e.hasError?Promise.reject(e.error):Promise.resolve();if(e.hasError)throw e.error}return i()}function en(e,t){return typeof e==`string`&&/^\.\.?\//.test(e)?e.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i,function(e,n,r,i,a){return n?t?`.jsx`:`.js`:r&&(!i||!a)?e:r+i+`.`+a.toLowerCase()+`js`}):e}var L,R,z,tn,B,nn,rn,V=a((()=>{L=function(e,t){return L=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},L(e,t)},R=function(){return R=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var i in t=arguments[n],t)Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},R.apply(this,arguments)},z=Object.create?(function(e,t,n,r){r===void 0&&(r=n);var i=Object.getOwnPropertyDescriptor(t,n);(!i||(`get`in i?!t.__esModule:i.writable||i.configurable))&&(i={enumerable:!0,get:function(){return t[n]}}),Object.defineProperty(e,r,i)}):(function(e,t,n,r){r===void 0&&(r=n),e[r]=t[n]}),tn=Object.create?(function(e,t){Object.defineProperty(e,`default`,{enumerable:!0,value:t})}):function(e,t){e.default=t},B=function(e){return B=Object.getOwnPropertyNames||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[t.length]=n);return t},B(e)},nn=typeof SuppressedError==`function`?SuppressedError:function(e,t,n){var r=Error(n);return r.name=`SuppressedError`,r.error=e,r.suppressed=t,r},rn={__extends:Dt,__assign:R,__rest:Ot,__decorate:kt,__param:At,__esDecorate:jt,__runInitializers:Mt,__propKey:Nt,__setFunctionName:Pt,__metadata:Ft,__awaiter:It,__generator:Lt,__createBinding:z,__exportStar:Rt,__values:F,__read:zt,__spread:Bt,__spreadArrays:Vt,__spreadArray:Ht,__await:I,__asyncGenerator:Ut,__asyncDelegator:Wt,__asyncValues:Gt,__makeTemplateObject:Kt,__importStar:qt,__importDefault:Jt,__classPrivateFieldGet:Yt,__classPrivateFieldSet:Xt,__classPrivateFieldIn:Zt,__addDisposableResource:Qt,__disposeResources:$t,__rewriteRelativeImportExtension:en}})),an=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0})})),on=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.Slice=void 0,e.Slice=class{constructor(e,t,n,r){this.uint8=e,this.view=t,this.start=n,this.end=r}subarray(){return this.uint8.subarray(this.start,this.end)}}})),sn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.Writer=void 0;let t=on(),n=new Uint8Array([]),r=new DataView(n.buffer),i=typeof Buffer==`function`,a=i?Buffer.prototype.utf8Write:null,o=i?Buffer.from:null,s=typeof TextEncoder<`u`?new TextEncoder:null;e.Writer=class{constructor(e=64*1024){this.allocSize=e,this.view=r,this.x0=0,this.x=0,this.uint8=new Uint8Array(e),this.size=e,this.view=new DataView(this.uint8.buffer)}grow(e){let t=this.x0,n=this.x,r=this.uint8,i=new Uint8Array(e),a=new DataView(i.buffer),o=r.subarray(t,n);i.set(o,0),this.x=n-t,this.x0=0,this.uint8=i,this.size=e,this.view=a}ensureCapacity(e){let t=this.size,n=t-this.x;if(n<e){let r=t-this.x0+(e-n);this.grow(r<=this.allocSize?this.allocSize:r*2)}}move(e){this.ensureCapacity(e),this.x+=e}reset(){this.x0=this.x}newBuffer(e){let t=this.uint8=new Uint8Array(e);this.size=e,this.view=new DataView(t.buffer),this.x=this.x0=0}flush(){let e=this.uint8.subarray(this.x0,this.x);return this.x0=this.x,e}flushSlice(){let e=new t.Slice(this.uint8,this.view,this.x0,this.x);return this.x0=this.x,e}u8(e){this.ensureCapacity(1),this.uint8[this.x++]=e}u16(e){this.ensureCapacity(2),this.view.setUint16(this.x,e),this.x+=2}u32(e){this.ensureCapacity(4),this.view.setUint32(this.x,e),this.x+=4}i32(e){this.ensureCapacity(4),this.view.setInt32(this.x,e),this.x+=4}u64(e){this.ensureCapacity(8),this.view.setBigUint64(this.x,BigInt(e)),this.x+=8}f64(e){this.ensureCapacity(8),this.view.setFloat64(this.x,e),this.x+=8}u8u16(e,t){this.ensureCapacity(3);let n=this.x;this.uint8[n++]=e,this.uint8[n++]=t>>>8,this.uint8[n++]=t&255,this.x=n}u8u32(e,t){this.ensureCapacity(5);let n=this.x;this.uint8[n++]=e,this.view.setUint32(n,t),this.x=n+4}u8u64(e,t){this.ensureCapacity(9);let n=this.x;this.uint8[n++]=e,this.view.setBigUint64(n,BigInt(t)),this.x=n+8}u8f32(e,t){this.ensureCapacity(5);let n=this.x;this.uint8[n++]=e,this.view.setFloat32(n,t),this.x=n+4}u8f64(e,t){this.ensureCapacity(9);let n=this.x;this.uint8[n++]=e,this.view.setFloat64(n,t),this.x=n+8}buf(e,t){this.ensureCapacity(t);let n=this.x;this.uint8.set(e,n),this.x=n+t}utf8(e){let t=e.length*4;if(t<168)return this.utf8Native(e);if(a){let n=a.call(this.uint8,e,this.x,t);return this.x+=n,n}else if(o){let n=this.uint8,r=n.byteOffset+this.x,i=o(n.buffer).subarray(r,r+t).write(e,0,t,`utf8`);return this.x+=i,i}else if(t>1024&&s){let n=s.encodeInto(e,this.uint8.subarray(this.x,this.x+t)).written;return this.x+=n,n}return this.utf8Native(e)}utf8Native(e){let t=e.length,n=this.uint8,r=this.x,i=0;for(;i<t;){let a=e.charCodeAt(i++);if(a&4294967168)if(!(a&4294965248))n[r++]=a>>6&31|192;else{if(a>=55296&&a<=56319&&i<t){let t=e.charCodeAt(i);(t&64512)==56320&&(i++,a=((a&1023)<<10)+(t&1023)+65536)}a&4294901760?(n[r++]=a>>18&7|240,n[r++]=a>>12&63|128,n[r++]=a>>6&63|128):(n[r++]=a>>12&15|224,n[r++]=a>>6&63|128)}else{n[r++]=a;continue}n[r++]=a&63|128}let a=r-this.x;return this.x=r,a}ascii(e){let t=e.length;this.ensureCapacity(t);let n=this.uint8,r=this.x,i=0;for(;i<t;)n[r++]=e.charCodeAt(i++);this.x=r}}})),cn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CborEncoderFast=void 0;let t=sn(),n=Number.isSafeInteger;e.CborEncoderFast=class{constructor(e=new t.Writer){this.writer=e}encode(e){return this.writeAny(e),this.writer.flush()}encodeToSlice(e){return this.writeAny(e),this.writer.flushSlice()}writeAny(e){switch(typeof e){case`number`:return this.writeNumber(e);case`string`:return this.writeStr(e);case`boolean`:return this.writer.u8(244+ +e);case`object`:if(!e)return this.writer.u8(246);switch(e.constructor){case Array:return this.writeArr(e);default:return this.writeObj(e)}}}writeCbor(){this.writer.u8u16(217,55799)}writeEnd(){this.writer.u8(255)}writeNull(){this.writer.u8(246)}writeBoolean(e){e?this.writer.u8(245):this.writer.u8(244)}writeNumber(e){n(e)?this.writeInteger(e):typeof e==`bigint`?this.writeBigInt(e):this.writeFloat(e)}writeBigInt(e){e>=0?this.writeBigUint(e):this.writeBigSint(e)}writeBigUint(e){if(e<=2**53-1)return this.writeUInteger(Number(e));this.writer.u8u64(27,e)}writeBigSint(e){if(e>=-(2**53-1))return this.encodeNint(Number(e));let t=-BigInt(1)-e;this.writer.u8u64(59,t)}writeInteger(e){e>=0?this.writeUInteger(e):this.encodeNint(e)}writeUInteger(e){let t=this.writer;t.ensureCapacity(9);let n=t.uint8,r=t.x;e<=23?n[r++]=0+e:e<=255?(n[r++]=24,n[r++]=e):e<=65535?(n[r++]=25,t.view.setUint16(r,e),r+=2):e<=4294967295?(n[r++]=26,t.view.setUint32(r,e),r+=4):(n[r++]=27,t.view.setBigUint64(r,BigInt(e)),r+=8),t.x=r}encodeNumber(e){this.writeNumber(e)}encodeInteger(e){this.writeInteger(e)}encodeUint(e){this.writeUInteger(e)}encodeNint(e){let t=-1-e,n=this.writer;n.ensureCapacity(9);let r=n.uint8,i=n.x;t<24?r[i++]=32+t:t<=255?(r[i++]=56,r[i++]=t):t<=65535?(r[i++]=57,n.view.setUint16(i,t),i+=2):t<=4294967295?(r[i++]=58,n.view.setUint32(i,t),i+=4):(r[i++]=59,n.view.setBigUint64(i,BigInt(t)),i+=8),n.x=i}writeFloat(e){this.writer.u8f64(251,e)}writeBin(e){let t=e.length;this.writeBinHdr(t),this.writer.buf(e,t)}writeBinHdr(e){let t=this.writer;e<=23?t.u8(64+e):e<=255?t.u16(22528+e):e<=65535?t.u8u16(89,e):e<=4294967295?t.u8u32(90,e):t.u8u64(91,e)}writeStr(e){let t=this.writer,n=e.length*4;t.ensureCapacity(5+n);let r=t.uint8,i=t.x;n<=23?t.x++:n<=255?(r[t.x++]=120,i=t.x,t.x++):n<=65535?(r[t.x++]=121,i=t.x,t.x+=2):(r[t.x++]=122,i=t.x,t.x+=4);let a=t.utf8(e);n<=23?r[i]=96+a:n<=255?r[i]=a:n<=65535?t.view.setUint16(i,a):t.view.setUint32(i,a)}writeStrHdr(e){let t=this.writer;e<=23?t.u8(96+e):e<=255?t.u16(30720+e):e<=65535?t.u8u16(121,e):t.u8u32(122,e)}writeAsciiStr(e){this.writeStrHdr(e.length),this.writer.ascii(e)}writeArr(e){let t=e.length;this.writeArrHdr(t);for(let n=0;n<t;n++)this.writeAny(e[n])}writeArrHdr(e){let t=this.writer;e<=23?t.u8(128+e):e<=255?t.u16(38912+e):e<=65535?t.u8u16(153,e):e<=4294967295?t.u8u32(154,e):t.u8u64(155,e)}writeObj(e){let t=Object.keys(e),n=t.length;this.writeObjHdr(n);for(let r=0;r<n;r++){let n=t[r];this.writeStr(n),this.writeAny(e[n])}}writeObjHdr(e){let t=this.writer;e<=23?t.u8(160+e):e<=255?t.u16(47104+e):e<=65535?t.u8u16(185,e):e<=4294967295?t.u8u32(186,e):t.u8u64(187,e)}writeMapHdr(e){this.writeObjHdr(e)}writeStartMap(){this.writer.u8(191)}writeTag(e,t){this.writeTagHdr(e),this.writeAny(t)}writeTagHdr(e){let t=this.writer;e<=23?t.u8(192+e):e<=255?t.u16(55296+e):e<=65535?t.u8u16(217,e):e<=4294967295?t.u8u32(218,e):t.u8u64(219,e)}writeTkn(e){let t=this.writer;e<=23?t.u8(224+e):e<=255&&t.u16(63488+e)}writeStartStr(){this.writer.u8(127)}writeStrChunk(e){throw Error(`Not implemented`)}writeEndStr(){throw Error(`Not implemented`)}writeStartBin(){this.writer.u8(95)}writeBinChunk(e){throw Error(`Not implemented`)}writeEndBin(){throw Error(`Not implemented`)}writeStartArr(){this.writer.u8(159)}writeArrChunk(e){throw Error(`Not implemented`)}writeEndArr(){this.writer.u8(255)}writeStartObj(){this.writer.u8(191)}writeObjChunk(e,t){throw Error(`Not implemented`)}writeEndObj(){this.writer.u8(255)}}})),ln=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.isFloat32=void 0;let t=new DataView(new ArrayBuffer(4));e.isFloat32=e=>(t.setFloat32(0,e),e===t.getFloat32(0))})),un=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.JsonPackExtension=void 0,e.JsonPackExtension=class{constructor(e,t){this.tag=e,this.val=t}}})),H=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.JsonPackValue=void 0,e.JsonPackValue=class{constructor(e){this.val=e}}})),dn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CborEncoder=void 0;let t=ln(),n=un(),r=cn(),i=H();e.CborEncoder=class extends r.CborEncoderFast{writeUnknown(e){this.writeNull()}writeAny(e){switch(typeof e){case`number`:return this.writeNumber(e);case`string`:return this.writeStr(e);case`boolean`:return this.writer.u8(244+ +e);case`object`:if(!e)return this.writer.u8(246);switch(e.constructor){case Object:return this.writeObj(e);case Array:return this.writeArr(e);case Uint8Array:return this.writeBin(e);case Map:return this.writeMap(e);case n.JsonPackExtension:return this.writeTag(e.tag,e.val);case i.JsonPackValue:let t=e.val;return this.writer.buf(t,t.length);default:return e instanceof Uint8Array?this.writeBin(e):Array.isArray(e)?this.writeArr(e):e instanceof Map?this.writeMap(e):this.writeUnknown(e)}case`undefined`:return this.writeUndef();case`bigint`:return this.writeBigInt(e);default:return this.writeUnknown(e)}}writeFloat(e){(0,t.isFloat32)(e)?this.writer.u8f32(250,e):this.writer.u8f64(251,e)}writeMap(e){this.writeMapHdr(e.size),e.forEach((e,t)=>{this.writeAny(t),this.writeAny(e)})}writeUndef(){this.writer.u8(247)}}})),fn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.sort=void 0,e.sort=(e,t)=>{let n=e.length;for(let r=1;r<n;r++){let n=e[r],i=r;for(;i!==0&&t(e[i-1],n)>0;)e[i]=e[i-1],i--;e[i]=n}return e}})),pn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.objKeyCmp=void 0,e.objKeyCmp=(e,t)=>{let n=e.length,r=t.length;return n===r?e>t?1:-1:n-r}})),mn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CborEncoderStable=void 0;let t=dn(),n=fn(),r=pn(),i=e=>e<=23?1:e<=255?2:e<=65535?3:5;e.CborEncoderStable=class extends t.CborEncoder{writeObj(e){let t=Object.keys(e);(0,n.sort)(t,r.objKeyCmp);let i=t.length;this.writeObjHdr(i);for(let n=0;n<i;n++){let r=t[n];this.writeStr(r),this.writeAny(e[r])}}writeStr(e){let t=this.writer,n=e.length,r=n*4;t.ensureCapacity(5+r);let a=i(n),o=t.x,s=o+a;t.x=s;let c=t.utf8(e),l=t.uint8,u=i(c);if(u!==a){let e=u-a;l.copyWithin(s+e,s,s+c)}switch(u){case 1:l[o]=96+c;break;case 2:l[o]=120,l[o+1]=c;break;case 3:l[o]=121,t.view.setUint16(o+1,c);break;case 5:l[o]=122,t.view.setUint32(o+1,c);break}t.x=o+u+c}writeUndef(){this.writeNull()}}})),hn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CborEncoderDag=void 0;let t=mn();e.CborEncoderDag=class extends t.CborEncoderStable{writeUndef(){this.writeNull()}writeFloat(e){if(e!==e||!Number.isFinite(e))return this.writeNull();this.writer.u8f64(251,e)}writeTag(e,t){e===42&&this.writeTagHdr(e),this.writeAny(t)}}})),gn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.decodeF16=void 0;let t=Math.pow;e.decodeF16=e=>{let n=(e&31744)>>10,r=e&1023;return(e>>15?-1:1)*(n?n===31?r?NaN:1/0:t(2,n-15)*(1+r/1024):r/1024*6103515625e-14)}})),_n=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.decodeAsciiMax15=e.decodeAscii=void 0;let t=String.fromCharCode;e.decodeAscii=(e,n,r)=>{let i=[];for(let t=0;t<r;t++){let t=e[n++];if(t&128)return;i.push(t)}return t.apply(String,i)},e.decodeAsciiMax15=(e,n,r)=>{if(r<4)if(r<2){if(r===0)return``;{let r=e[n++];if((r&128)>1){--n;return}return t(r)}}else{let i=e[n++],a=e[n++];if((i&128)>0||(a&128)>0){n-=2;return}if(r<3)return t(i,a);let o=e[n++];if((o&128)>0){n-=3;return}return t(i,a,o)}else{let i=e[n++],a=e[n++],o=e[n++],s=e[n++];if((i&128)>0||(a&128)>0||(o&128)>0||(s&128)>0){n-=4;return}if(r<6){if(r===4)return t(i,a,o,s);{let r=e[n++];if((r&128)>0){n-=5;return}return t(i,a,o,s,r)}}else if(r<8){let c=e[n++],l=e[n++];if((c&128)>0||(l&128)>0){n-=6;return}if(r<7)return t(i,a,o,s,c,l);let u=e[n++];if((u&128)>0){n-=7;return}return t(i,a,o,s,c,l,u)}else{let c=e[n++],l=e[n++],u=e[n++],d=e[n++];if((c&128)>0||(l&128)>0||(u&128)>0||(d&128)>0){n-=8;return}if(r<10){if(r===8)return t(i,a,o,s,c,l,u,d);{let r=e[n++];if((r&128)>0){n-=9;return}return t(i,a,o,s,c,l,u,d,r)}}else if(r<12){let f=e[n++],p=e[n++];if((f&128)>0||(p&128)>0){n-=10;return}if(r<11)return t(i,a,o,s,c,l,u,d,f,p);let m=e[n++];if((m&128)>0){n-=11;return}return t(i,a,o,s,c,l,u,d,f,p,m)}else{let f=e[n++],p=e[n++],m=e[n++],h=e[n++];if((f&128)>0||(p&128)>0||(m&128)>0||(h&128)>0){n-=12;return}if(r<14){if(r===12)return t(i,a,o,s,c,l,u,d,f,p,m,h);{let r=e[n++];if((r&128)>0){n-=13;return}return t(i,a,o,s,c,l,u,d,f,p,m,h,r)}}else{let g=e[n++],_=e[n++];if((g&128)>0||(_&128)>0){n-=14;return}if(r<15)return t(i,a,o,s,c,l,u,d,f,p,m,h,g,_);let v=e[n++];if((v&128)>0){n-=15;return}return t(i,a,o,s,c,l,u,d,f,p,m,h,g,_,v)}}}}}})),vn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=String.fromCharCode;e.default=(e,n,r)=>{let i=n,a=i+r,o=[];for(;i<a;){let t=e[i++];if(t&128){let n=e[i++]&63;if((t&224)==192)t=(t&31)<<6|n;else{let r=e[i++]&63;if((t&240)==224)t=(t&31)<<12|n<<6|r;else if((t&248)==240){let a=e[i++]&63,s=(t&7)<<18|n<<12|r<<6|a;if(s>65535){s-=65536;let e=s>>>10&1023|55296;t=56320|s&1023,o.push(e)}else t=s}}}o.push(t)}return t.apply(String,o)}})),yn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=(V(),l(P)),n=_n(),r=t.__importDefault(vn()),i=typeof Buffer<`u`,a=i?Buffer.prototype.utf8Slice:null,o=i?Buffer.from:null,s=(e,t,i)=>(0,n.decodeAsciiMax15)(e,t,i)??(0,r.default)(e,t,i),c=(e,t,i)=>(0,n.decodeAscii)(e,t,i)??(0,r.default)(e,t,i),u=a?(e,t,n)=>a.call(e,t,t+n):o?(e,t,n)=>o(e).subarray(t,t+n).toString(`utf8`):r.default;e.default=(e,t,n)=>n<16?s(e,t,n):n<32?c(e,t,n):u(e,t,n)})),bn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.decodeUtf8=void 0,e.decodeUtf8=(V(),l(P)).__importDefault(yn()).default})),xn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.Reader=void 0;let t=bn();e.Reader=class e{constructor(e=new Uint8Array([]),t=new DataView(e.buffer,e.byteOffset,e.length),n=0,r=e.length){this.uint8=e,this.view=t,this.x=n,this.end=r}reset(e){this.x=0,this.uint8=e,this.view=new DataView(e.buffer,e.byteOffset,e.length)}size(){return this.end-this.x}peek(){return this.view.getUint8(this.x)}peak(){return this.peek()}skip(e){this.x+=e}buf(e=this.size()){let t=this.x,n=t+e,r=this.uint8.subarray(t,n);return this.x=n,r}subarray(e=0,t){let n=this.x,r=n+e,i=typeof t==`number`?n+t:this.end;return this.uint8.subarray(r,i)}slice(t=0,n){let r=this.x,i=r+t,a=typeof n==`number`?r+n:this.end;return new e(this.uint8,this.view,i,a)}cut(e=this.size()){let t=this.slice(0,e);return this.skip(e),t}u8(){return this.uint8[this.x++]}i8(){return this.view.getInt8(this.x++)}u16(){let e=this.x,t=(this.uint8[e++]<<8)+this.uint8[e++];return this.x=e,t}i16(){let e=this.view.getInt16(this.x);return this.x+=2,e}u32(){let e=this.view.getUint32(this.x);return this.x+=4,e}i32(){let e=this.view.getInt32(this.x);return this.x+=4,e}u64(){let e=this.view.getBigUint64(this.x);return this.x+=8,e}i64(){let e=this.view.getBigInt64(this.x);return this.x+=8,e}f32(){let e=this.x;return this.x+=4,this.view.getFloat32(e)}f64(){let e=this.x;return this.x+=8,this.view.getFloat64(e)}utf8(e){let n=this.x;return this.x+=e,(0,t.decodeUtf8)(this.uint8,n,e)}ascii(e){let t=this.uint8,n=``,r=this.x+e;for(let e=this.x;e<r;e++)n+=String.fromCharCode(t[e]);return this.x=r,n}}})),Sn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=String.fromCharCode;e.default=(e,n,r)=>{let i=n,a=i+r,o=``;for(;i<a;){let n=e[i++];if(!(n&128)){o+=t(n);continue}let r=e[i++]&63;if((n&224)==192){o+=t((n&31)<<6|r);continue}let a=e[i++]&63;if((n&240)==224){o+=t((n&31)<<12|r<<6|a);continue}if((n&248)==240){let s=e[i++]&63,c=(n&7)<<18|r<<12|a<<6|s;if(c>65535){c-=65536;let e=c>>>10&1023|55296;c=56320|c&1023,o+=t(e,c)}else o+=t(c)}else o+=t(n)}return o}})),Cn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CachedUtf8Decoder=void 0;let t=(V(),l(P)).__importDefault(Sn()),n=1+Math.round(Math.random()*((-1>>>0)-1));function r(e,t){return n^=n<<13,n^=n>>>17,n^=n<<5,(n>>>0)%(t-e+1)+e}var i=class{constructor(e,t){this.bytes=e,this.value=t}};e.CachedUtf8Decoder=class{constructor(){this.caches=[];for(let e=0;e<31;e++)this.caches.push([])}get(e,t,n){let r=this.caches[n-1],i=r.length;FIND_CHUNK:for(let a=0;a<i;a++){let i=r[a],o=i.bytes;for(let r=0;r<n;r++)if(o[r]!==e[t+r])continue FIND_CHUNK;return i.value}return null}store(e,t){let n=this.caches[e.length-1],a=new i(e,t);n.length>=16?n[r(0,15)]=a:n.push(a)}decode(e,n,r){if(!r)return``;let i=this.get(e,n,r);if(i!==null)return i;let a=(0,t.default)(e,n,r),o=Uint8Array.prototype.slice.call(e,n,n+r);return this.store(o,a),a}}})),wn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.default=new(Cn()).CachedUtf8Decoder})),Tn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CborDecoderBase=void 0;let t=(V(),l(P)),n=gn(),r=un(),i=H(),a=xn(),o=t.__importDefault(wn());e.CborDecoderBase=class{constructor(e=new a.Reader,t=o.default){this.reader=e,this.keyDecoder=t}read(e){return this.reader.reset(e),this.readAny()}decode(e){return this.reader.reset(e),this.readAny()}val(){return this.readAny()}readAny(){let e=this.reader.u8(),t=e>>5,n=e&31;return t<4?t<2?t===0?this.readUint(n):this.readNint(n):t===2?this.readBin(n):this.readStr(n):t<6?t===4?this.readArr(n):this.readObj(n):t===6?this.readTag(n):this.readTkn(n)}readAnyRaw(e){let t=e>>5,n=e&31;return t<4?t<2?t===0?this.readUint(n):this.readNint(n):t===2?this.readBin(n):this.readStr(n):t<6?t===4?this.readArr(n):this.readObj(n):t===6?this.readTag(n):this.readTkn(n)}readMinorLen(e){if(e<24)return e;switch(e){case 24:return this.reader.u8();case 25:return this.reader.u16();case 26:return this.reader.u32();case 27:return Number(this.reader.u64());case 31:return-1;default:throw 1}}readUint(e){if(e<25)return e===24?this.reader.u8():e;if(e<27)return e===25?this.reader.u16():this.reader.u32();{let e=this.reader.u64();return e>9007199254740991?e:Number(e)}}readNint(e){if(e<25)return e===24?-this.reader.u8()-1:-e-1;if(e<27)return e===25?-this.reader.u16()-1:-this.reader.u32()-1;{let e=this.reader.u64();return e>9007199254740990?-e-BigInt(1):-Number(e)-1}}readBin(e){let t=this.reader;if(e<=23)return t.buf(e);switch(e){case 24:return t.buf(t.u8());case 25:return t.buf(t.u16());case 26:return t.buf(t.u32());case 27:return t.buf(Number(t.u64()));case 31:{let e=0,t=[];for(;this.reader.peak()!==255;){let n=this.readBinChunk();e+=n.length,t.push(n)}this.reader.x++;let n=new Uint8Array(e),r=0,i=t.length;for(let e=0;e<i;e++){let i=t[e];n.set(i,r),r+=i.length}return n}default:throw 1}}readBinChunk(){let e=this.reader.u8(),t=e>>5,n=e&31;if(t!==2)throw 2;if(n>27)throw 3;return this.readBin(n)}readAsStr(){let e=this.reader.u8(),t=e>>5,n=e&31;if(t!==3)throw 11;return this.readStr(n)}readStr(e){let t=this.reader;if(e<=23)return t.utf8(e);switch(e){case 24:return t.utf8(t.u8());case 25:return t.utf8(t.u16());case 26:return t.utf8(t.u32());case 27:return t.utf8(Number(t.u64()));case 31:{let e=``;for(;t.peak()!==255;)e+=this.readStrChunk();return this.reader.x++,e}default:throw 1}}readStrLen(e){if(e<=23)return e;switch(e){case 24:return this.reader.u8();case 25:return this.reader.u16();case 26:return this.reader.u32();case 27:return Number(this.reader.u64());default:throw 1}}readStrChunk(){let e=this.reader.u8(),t=e>>5,n=e&31;if(t!==3)throw 4;if(n>27)throw 5;return this.readStr(n)}readArr(e){let t=this.readMinorLen(e);return t>=0?this.readArrRaw(t):this.readArrIndef()}readArrRaw(e){let t=[];for(let n=0;n<e;n++)t.push(this.readAny());return t}readArrIndef(){let e=[];for(;this.reader.peak()!==255;)e.push(this.readAny());return this.reader.x++,e}readObj(e){if(e<28){let t=e;switch(e){case 24:t=this.reader.u8();break;case 25:t=this.reader.u16();break;case 26:t=this.reader.u32();break;case 27:t=Number(this.reader.u64());break}let n={};for(let e=0;e<t;e++){let e=this.key();if(e===`__proto__`)throw 6;n[e]=this.readAny()}return n}else if(e===31)return this.readObjIndef();else throw 1}readObjRaw(e){let t={};for(let n=0;n<e;n++){let e=this.key();t[e]=this.readAny()}return t}readObjIndef(){let e={};for(;this.reader.peak()!==255;){let t=this.key();if(this.reader.peak()===255)throw 7;e[t]=this.readAny()}return this.reader.x++,e}key(){let e=this.reader.u8(),t=e>>5,n=e&31;if(t!==3)return String(this.readAnyRaw(e));let r=this.readStrLen(n);if(r>31)return this.reader.utf8(r);let i=this.keyDecoder.decode(this.reader.uint8,this.reader.x,r);return this.reader.skip(r),i}readTag(e){if(e<=23)return this.readTagRaw(e);switch(e){case 24:return this.readTagRaw(this.reader.u8());case 25:return this.readTagRaw(this.reader.u16());case 26:return this.readTagRaw(this.reader.u32());case 27:return this.readTagRaw(Number(this.reader.u64()));default:throw 1}}readTagRaw(e){return new r.JsonPackExtension(e,this.readAny())}readTkn(e){switch(e){case 20:return!1;case 21:return!0;case 22:return null;case 23:return;case 24:return new i.JsonPackValue(this.reader.u8());case 25:return this.f16();case 26:return this.reader.f32();case 27:return this.reader.f64()}if(e<=23)return new i.JsonPackValue(e);throw 1}f16(){return(0,n.decodeF16)(this.reader.u16())}}})),En=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CborDecoder=void 0;let t=Tn(),n=H();e.CborDecoder=class extends t.CborDecoderBase{readAsMap(){let e=this.reader.u8(),t=e>>5,n=e&31;switch(t){case 5:return this.readMap(n);default:throw 0}}readMap(e){let t=this.readMinorLen(e);return t>=0?this.readMapRaw(t):this.readMapIndef()}readMapRaw(e){let t=new Map;for(let n=0;n<e;n++){let e=this.readAny(),n=this.readAny();t.set(e,n)}return t}readMapIndef(){let e=new Map;for(;this.reader.peak()!==255;){let t=this.readAny();if(this.reader.peak()===255)throw 7;let n=this.readAny();e.set(t,n)}return this.reader.x++,e}skipN(e){for(let t=0;t<e;t++)this.skipAny()}skipAny(){this.skipAnyRaw(this.reader.u8())}skipAnyRaw(e){let t=e>>5,n=e&31;switch(t){case 0:case 1:this.skipUNint(n);break;case 2:this.skipBin(n);break;case 3:this.skipStr(n);break;case 4:this.skipArr(n);break;case 5:this.skipObj(n);break;case 7:this.skipTkn(n);break;case 6:this.skipTag(n);break}}skipMinorLen(e){if(e<=23)return e;switch(e){case 24:return this.reader.u8();case 25:return this.reader.u16();case 26:return this.reader.u32();case 27:return Number(this.reader.u64());case 31:return-1;default:throw 1}}skipUNint(e){if(!(e<=23))switch(e){case 24:return this.reader.skip(1);case 25:return this.reader.skip(2);case 26:return this.reader.skip(4);case 27:return this.reader.skip(8);default:throw 1}}skipBin(e){let t=this.skipMinorLen(e);if(t>=0)this.reader.skip(t);else{for(;this.reader.peak()!==255;)this.skipBinChunk();this.reader.x++}}skipBinChunk(){let e=this.reader.u8(),t=e>>5,n=e&31;if(t!==2)throw 2;if(n>27)throw 3;this.skipBin(n)}skipStr(e){let t=this.skipMinorLen(e);if(t>=0)this.reader.skip(t);else{for(;this.reader.peak()!==255;)this.skipStrChunk();this.reader.x++}}skipStrChunk(){let e=this.reader.u8(),t=e>>5,n=e&31;if(t!==3)throw 4;if(n>27)throw 5;this.skipStr(n)}skipArr(e){let t=this.skipMinorLen(e);if(t>=0)this.skipN(t);else{for(;this.reader.peak()!==255;)this.skipAny();this.reader.x++}}skipObj(e){let t=this.readMinorLen(e);if(t>=0)return this.skipN(t*2);for(;this.reader.peak()!==255;){if(this.skipAny(),this.reader.peak()===255)throw 7;this.skipAny()}this.reader.x++}skipTag(e){if(this.skipMinorLen(e)<0)throw 1;this.skipAny()}skipTkn(e){switch(e){case 24:this.reader.skip(1);return;case 25:this.reader.skip(2);return;case 26:this.reader.skip(4);return;case 27:this.reader.skip(8);return}if(!(e<=23))throw 1}validate(e,t=0,n=e.length){this.reader.reset(e),this.reader.x=t;let r=t;if(this.skipAny(),this.reader.x-r!==n)throw 8}decodeLevel(e){return this.reader.reset(e),this.readLevel()}readLevel(){let e=this.reader.u8(),t=e>>5,n=e&31;switch(t){case 4:return this.readArrLevel(n);case 5:return this.readObjLevel(n);default:return super.readAnyRaw(e)}}readPrimitiveOrVal(){switch(this.reader.peak()>>5){case 4:case 5:return this.readAsValue();default:return this.readAny()}}readAsValue(){let e=this.reader,t=e.x;this.skipAny();let r=e.x;return new n.JsonPackValue(e.uint8.subarray(t,r))}readObjLevel(e){let t=this.readMinorLen(e);return t>=0?this.readObjRawLevel(t):this.readObjIndefLevel()}readObjRawLevel(e){let t={};for(let n=0;n<e;n++){let e=this.key();t[e]=this.readPrimitiveOrVal()}return t}readObjIndefLevel(){let e={};for(;this.reader.peak()!==255;){let t=this.key();if(this.reader.peak()===255)throw 7;e[t]=this.readPrimitiveOrVal()}return this.reader.x++,e}readArrLevel(e){let t=this.readMinorLen(e);return t>=0?this.readArrRawLevel(t):this.readArrIndefLevel()}readArrRawLevel(e){let t=[];for(let n=0;n<e;n++)t.push(this.readPrimitiveOrVal());return t}readArrIndefLevel(){let e=[];for(;this.reader.peak()!==255;)e.push(this.readPrimitiveOrVal());return this.reader.x++,e}readHdr(e){let t=this.reader.u8();if(t>>5!==e)throw 0;let n=t&31;if(n<24)return n;switch(n){case 24:return this.reader.u8();case 25:return this.reader.u16();case 26:return this.reader.u32();case 27:return Number(this.reader.u64());case 31:return-1}throw 1}readStrHdr(){return this.readHdr(3)}readObjHdr(){return this.readHdr(5)}readArrHdr(){return this.readHdr(4)}findKey(e){let t=this.readObjHdr();for(let n=0;n<t;n++){if(this.key()===e)return this;this.skipAny()}throw 9}findIndex(e){if(e>=this.readArrHdr())throw 10;for(let t=0;t<e;t++)this.skipAny();return this}find(e){for(let t=0;t<e.length;t++){let n=e[t];typeof n==`string`?this.findKey(n):this.findIndex(n)}return this}}})),Dn=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0}),e.CborDecoderDag=void 0;let t=un(),n=En();e.CborDecoderDag=class extends n.CborDecoder{readTagRaw(e){let n=this.readAny();return e===42?new t.JsonPackExtension(e,n):n}}})),On=o((e=>{Object.defineProperty(e,`__esModule`,{value:!0});let t=(V(),l(P));t.__exportStar(an(),e),t.__exportStar(cn(),e),t.__exportStar(dn(),e),t.__exportStar(mn(),e),t.__exportStar(hn(),e),t.__exportStar(Tn(),e),t.__exportStar(En(),e),t.__exportStar(Dn(),e)}))();let U={parseError:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internalError:-32603,serverError:-32e3,clientNotConnected:-32001,configError:-32002,corruptedResponse:-32003,clientAborted:-32004,walletNotConnected:-32005,serverErrorForInteractionDelegation:-32006,userRejected:-32007};var W=class extends Error{constructor(e,t,n){super(t),this.code=e,this.data=n}toJSON(){return{code:this.code,message:this.message,data:this.data}}};let kn=new On.CborEncoder,An=new On.CborDecoder;function jn(e){let t={...e,validationHash:Fn(e??{})};return kn.encode(t)}function Mn(e){if(!e.length)throw new W(U.corruptedResponse,`Missing compressed data`);let t=Pn(e);if(!t)throw new W(U.corruptedResponse,`Invalid compressed data`);if(!t?.validationHash)throw new W(U.corruptedResponse,`Missing validation hash`);let{validationHash:n,...r}=t,i=Fn(r);if(i!==t.validationHash)throw console.warn(`Validation error`,{validationHash:n,rawResultData:r,parsedData:t,expectedValidationHashes:i,recomputedHash:Fn(void 0)}),new W(U.corruptedResponse,`Invalid validation hash`);return t}function Nn(e){return kn.encode(e)}function Pn(e){try{return An.decode(e)}catch(t){return console.error(`Invalid compressed data`,{e:t,data:e}),null}}function Fn(e){return wt(kn.encode(e))}let In=()=>({onRequest:(e,t)=>{if(e.data instanceof Uint8Array||ArrayBuffer.isView(e.data))return t;try{e.data=jn(e.data)}catch(e){console.error(`[Compression Middleware] Failed to compress request`,e)}return t},onResponse:(e,t,n)=>{if(t.error||!(t.result instanceof Uint8Array||ArrayBuffer.isView(t.result)))return t;try{let{validationHash:e,...n}=Mn(t.result);typeof n==`object`&&n&&`result`in n?t.result=n.result:t.result=n}catch(e){console.error(`[Compression Middleware] Failed to decompress response`,e)}return t}});var Ln=class{_promise;_resolve;_reject;constructor(){this._promise=new Promise((e,t)=>{this._resolve=e,this._reject=t})}get promise(){return this._promise}resolve=e=>{this._resolve?.(e)};reject=e=>{this._reject?.(e)}};function Rn(e){let{emittingTransport:t,listeningTransport:n,targetOrigin:r,middleware:i=[],lifecycleHandlers:a}=e,o=new Map;function s(e){return typeof e!=`object`||!e?!1:`clientLifecycle`in e||`iframeLifecycle`in e}function c(e){return typeof e!=`object`||!e?!1:`id`in e&&`topic`in e&&`data`in e}async function l(e){try{`clientLifecycle`in e&&a?.clientLifecycle?await a.clientLifecycle(e,{origin:r,source:null}):`iframeLifecycle`in e&&a?.iframeLifecycle&&await a.iframeLifecycle(e,{origin:r,source:null})}catch(e){console.error(`[RPC Client] Lifecycle handler error:`,e)}}async function u(e){let t={origin:r,source:null};for(let n of i)n.onRequest&&await n.onRequest(e,t);return e}async function d(e,t){let n={origin:r,source:null},a=t;for(let t of i)t.onResponse&&(a=await t.onResponse(e,a,n));return a}async function f(e){try{let t=new URL(e.origin).origin.toLowerCase(),n=new URL(r).origin.toLowerCase();if(t!==n){console.log(`Not expected origin`,t,n);return}}catch(e){console.error(`[RPC Client] Invalid origin`,e);return}if(s(e.data)){await l(e.data);return}if(!c(e.data))return;let t;try{let n=e.data.data,r=n instanceof Uint8Array||ArrayBuffer.isView(n)?{result:n}:n;t=await d(e.data,r)}catch(e){console.error(`[RPC Client] Middleware error on response:`,e);return}let n=o.get(e.data.id);n&&n(t)}async function p(e){let n=e;try{n=await u(e)}catch(e){throw console.error(`[RPC Client] Middleware error on request:`,e),e}t.postMessage(n,r)}function m(e){t.postMessage(e,r)}function h(){return`${Date.now()}-${Math.random().toString(36).substring(2,9)}`}n.addEventListener(`message`,f);function g(e){let t=h(),n=new Ln;return o.set(t,e=>{e.error?n.reject(new W(e.error.code,e.error.message,e.error.data)):n.resolve(e.result),o.delete(t)}),p({id:t,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{o.delete(t),n.reject(e)}),n.promise}function _(e,t){let n=h();return o.set(n,e=>{e.error?(console.error(`[RPC Client] Listener error:`,e.error),o.delete(n)):t(e.result)}),p({id:n,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{console.error(`[RPC Client] Failed to send listener request:`,e),o.delete(n)}),()=>{o.delete(n)}}function v(){n.removeEventListener(`message`,f),o.clear()}return{request:g,listen:_,sendLifecycle:m,cleanup:v}}function zn({domain:e}={}){return Ue(S((e??window.location.host).replace(`www.`,``)))}function Bn(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Vn(e){let t=e.length%4;return Uint8Array.from(atob(e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(e.length+(t===0?0:4-t),`=`)),e=>e.charCodeAt(0))}function Hn(e){return Bn(Nn(e))}function Un(e,t,n,r,i){let a=Hn(Wn({redirectUrl:t.redirectUrl,directExit:t.directExit,lang:t.lang,productId:n,metadata:{name:r,css:i,logoUrl:t.metadata?.logoUrl,homepageLink:t.metadata?.homepageLink}})),o=new URL(e);return o.pathname=`/sso`,o.searchParams.set(`p`,a),o.toString()}function Wn(e){return{r:e.redirectUrl,d:e.directExit,l:e.lang,p:e.productId,m:{n:e.metadata?.name,css:e.metadata?.css,l:e.metadata?.logoUrl,h:e.metadata?.homepageLink}}}let Gn=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,Kn=`frak-sso`;async function qn(e,t){let{metadata:n,customizations:r,walletUrl:i}=e.config;if(t.openInSameWindow??!!t.redirectUrl)return await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]});let a=t.ssoPopupUrl??Un(i??`https://wallet.frak.id`,t,zn(),n.name,r?.css),o=window.open(a,Kn,Gn);if(!o)throw Error(`Popup was blocked. Please allow popups for this site.`);return o.focus(),await e.request({method:`frak_openSso`,params:[t,n.name,r?.css]})??{}}let Jn=`fCtx`;function Yn(e){if(e?.r)try{return Bn(we(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function Xn(e){if(!(!e||e.length===0))try{return{r:ge(Vn(e),{size:20})}}catch(t){console.error(`Error decompressing Frak context`,{e:t,context:e})}}function Zn({url:e}){if(!e)return null;let t=new URL(e).searchParams.get(Jn);return t?Xn(t):null}function Qn({url:e,context:t}){if(!e)return null;let n=Zn({url:e}),r=n?{...n,...t}:t;if(!r.r)return null;let i=Yn(r);if(!i)return null;let a=new URL(e);return a.searchParams.set(Jn,i),a.toString()}function $n(e){let t=new URL(e);return t.searchParams.delete(Jn),t.toString()}function er({url:e,context:t}){if(!window.location?.href||typeof window>`u`){console.error(`No window found, can't update context`);return}let n=e??window.location.href,r;r=t===null?$n(n):Qn({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}let G={compress:Yn,decompress:Xn,parse:Zn,update:Qn,remove:$n,replaceUrl:er};function K(e,t,n={}){if(!e){console.debug(`[Frak] No client provided, skipping event tracking`);return}try{e.openPanel?.track(t,n)}catch(e){console.debug(`[Frak] Failed to track event:`,t,e)}}var tr=class{constructor(e){this.baseUrl=e.baseUrl,this.headers={"Content-Type":`application/json`,...e.defaultHeaders},this.maxRetries=e.maxRetries??3,this.initialRetryDelay=e.initialRetryDelay??500}async resolveHeaders(){let e={};for(let[t,n]of Object.entries(this.headers)){let r=await n;r!==null&&(e[t]=r)}return e}addHeader(e,t){this.headers[e]=t}async post(e,t,n,r){try{let r=await fetch(e,{method:`POST`,headers:await this.resolveHeaders(),body:t?JSON.stringify(t??{}):void 0,keepalive:!0,...n});if(r.status===401)return null;if(r.status!==200&&r.status!==202)throw Error(`HTTP error! status: ${r.status}`);let i=await r.text();return i?JSON.parse(i):null}catch(i){if(r<this.maxRetries){let i=this.initialRetryDelay*2**r;return await new Promise(e=>setTimeout(e,i)),this.post(e,t,n,r+1)}return console.error(`Max retries reached:`,i),null}}async fetch(e,t,n={}){let r=`${this.baseUrl}${e}`;return this.post(r,t,n,0)}},nr=class{constructor(e){this.options=e,this.queue=[];let t={"openpanel-client-id":e.clientId};e.clientSecret&&(t[`openpanel-client-secret`]=e.clientSecret),t[`openpanel-sdk-name`]=e.sdk||`node`,t[`openpanel-sdk-version`]=e.sdkVersion||`1.0.3`,this.api=new tr({baseUrl:e.apiUrl||`https://api.openpanel.dev`,defaultHeaders:t})}init(){}ready(){this.options.waitForProfile=!1,this.flush()}async send(e){return this.options.disabled||this.options.filter&&!this.options.filter(e)?Promise.resolve():this.options.waitForProfile&&!this.profileId?(this.queue.push(e),Promise.resolve()):this.api.fetch(`/track`,e)}setGlobalProperties(e){this.global={...this.global,...e}}async track(e,t){return this.log(`track event`,e,t),this.send({type:`track`,payload:{name:e,profileId:t?.profileId??this.profileId,properties:{...this.global??{},...t??{}}}})}async identify(e){if(this.log(`identify user`,e),e.profileId&&(this.profileId=e.profileId,this.flush()),Object.keys(e).length>1)return this.send({type:`identify`,payload:{...e,properties:{...this.global,...e.properties}}})}async alias(e){}async increment(e){return this.send({type:`increment`,payload:e})}async decrement(e){return this.send({type:`decrement`,payload:e})}async revenue(e,t){let n=t?.deviceId;return delete t?.deviceId,this.track(`revenue`,{...t??{},...n?{__deviceId:n}:{},__revenue:e})}async fetchDeviceId(){return(await this.api.fetch(`/track/device-id`,void 0,{method:`GET`,keepalive:!1}))?.deviceId??``}clear(){this.profileId=void 0}flush(){this.queue.forEach(e=>{this.send({...e,payload:{...e.payload,profileId:e.payload.profileId??this.profileId}})}),this.queue=[]}log(...e){this.options.debug&&console.log(`[OpenPanel.dev]`,...e)}};function rr(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var ir=class extends nr{constructor(e){if(super({sdk:`web`,sdkVersion:`1.0.6`,...e}),this.options=e,this.lastPath=``,this.pendingRevenues=[],!this.isServer()){try{let e=sessionStorage.getItem(`openpanel-pending-revenues`);if(e){let t=JSON.parse(e);Array.isArray(t)&&(this.pendingRevenues=t)}}catch{this.pendingRevenues=[]}this.setGlobalProperties({__referrer:document.referrer}),this.options.trackScreenViews&&(this.trackScreenViews(),setTimeout(()=>this.screenView(),0)),this.options.trackOutgoingLinks&&this.trackOutgoingLinks(),this.options.trackAttributes&&this.trackAttributes()}}debounce(e,t){clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(e,t)}isServer(){return typeof document>`u`}trackOutgoingLinks(){this.isServer()||document.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`a`);if(n&&t){let e=n.getAttribute(`href`);if(e?.startsWith(`http`))try{let r=new URL(e),i=window.location.hostname;r.hostname!==i&&super.track(`link_out`,{href:e,text:n.innerText||n.getAttribute(`title`)||t.getAttribute(`alt`)||t.getAttribute(`title`)})}catch{}}})}trackScreenViews(){if(this.isServer())return;let e=history.pushState;history.pushState=function(...t){let n=e.apply(this,t);return window.dispatchEvent(new Event(`pushstate`)),window.dispatchEvent(new Event(`locationchange`)),n};let t=history.replaceState;history.replaceState=function(...e){let n=t.apply(this,e);return window.dispatchEvent(new Event(`replacestate`)),window.dispatchEvent(new Event(`locationchange`)),n},window.addEventListener(`popstate`,()=>{window.dispatchEvent(new Event(`locationchange`))});let n=()=>this.debounce(()=>this.screenView(),50);this.options.trackHashChanges?window.addEventListener(`hashchange`,n):window.addEventListener(`locationchange`,n)}trackAttributes(){this.isServer()||document.addEventListener(`click`,e=>{let t=e.target,n=t.closest(`button`),r=t.closest(`a`),i=n?.getAttribute(`data-track`)?n:r?.getAttribute(`data-track`)?r:null;if(i){let e={};for(let t of i.attributes)t.name.startsWith(`data-`)&&t.name!==`data-track`&&(e[rr(t.name.replace(/^data-/,``))]=t.value);let t=i.getAttribute(`data-track`);t&&super.track(t,e)}})}screenView(e,t){if(this.isServer())return;let n,r;typeof e==`string`?(n=e,r=t):(n=window.location.href,r=e),this.lastPath!==n&&(this.lastPath=n,super.track(`screen_view`,{...r??{},__path:n,__title:document.title}))}async flushRevenue(){let e=this.pendingRevenues.map(e=>super.revenue(e.amount,e.properties));await Promise.all(e),this.clearRevenue()}clearRevenue(){if(this.pendingRevenues=[],!this.isServer())try{sessionStorage.removeItem(`openpanel-pending-revenues`)}catch{}}pendingRevenue(e,t){if(this.pendingRevenues.push({amount:e,properties:t}),!this.isServer())try{sessionStorage.setItem(`openpanel-pending-revenues`,JSON.stringify(this.pendingRevenues))}catch{}}};let q=`nexus-wallet-backup`;function ar(e,t){if(typeof window>`u`)return;let n=new URL(window.location.href),r=n.searchParams.get(`sso`);r&&(t.then(()=>{e.sendLifecycle({clientLifecycle:`sso-redirect-complete`,data:{compressed:r}}),console.log(`[SSO URL Listener] Forwarded compressed SSO data to iframe`)}).catch(e=>{console.error(`[SSO URL Listener] Failed to forward SSO data:`,e)}),n.searchParams.delete(`sso`),window.history.replaceState({},``,n.toString()),console.log(`[SSO URL Listener] SSO parameter detected and URL cleaned`))}var or=class e{config;iframe;isSetupDone=!1;lastResponse=null;lastRequest=null;constructor(e,t){this.config=e,this.iframe=t,this.lastRequest=null,this.lastResponse=null}setLastResponse(e,t){this.lastResponse={message:e,response:t,timestamp:Date.now()}}setLastRequest(e){this.lastRequest={event:e,timestamp:Date.now()}}updateSetupStatus(e){this.isSetupDone=e}base64Encode(e){try{return btoa(JSON.stringify(e))}catch(e){return console.warn(`Failed to encode debug data`,e),btoa(`Failed to encode data`)}}getIframeStatus(){return this.iframe?{loading:this.iframe.hasAttribute(`loading`),url:this.iframe.src,readyState:this.iframe.contentDocument?.readyState?this.iframe.contentDocument.readyState===`complete`?1:0:-1,contentWindow:!!this.iframe.contentWindow,isConnected:this.iframe.isConnected}:null}getNavigatorInfo(){return navigator?{userAgent:navigator.userAgent,language:navigator.language,onLine:navigator.onLine,screenWidth:window.screen.width,screenHeight:window.screen.height,pixelRatio:window.devicePixelRatio}:null}gatherDebugInfo(e){let t=this.getIframeStatus(),n=this.getNavigatorInfo(),r=`Unknown`;return e instanceof W?r=`FrakRpcError: ${e.code} '${e.message}'`:e instanceof Error?r=e.message:typeof e==`string`&&(r=e),{timestamp:new Date().toISOString(),encodedUrl:btoa(window.location.href),encodedConfig:this.config?this.base64Encode(this.config):`no-config`,navigatorInfo:n?this.base64Encode(n):`no-navigator`,iframeStatus:t?this.base64Encode(t):`not-iframe`,lastRequest:this.lastRequest?this.base64Encode(this.lastRequest):`No Frak request logged`,lastResponse:this.lastResponse?this.base64Encode(this.lastResponse):`No Frak response logged`,clientStatus:this.isSetupDone?`setup`:`not-setup`,error:r}}static empty(){return new e}formatDebugInfo(e){let t=this.gatherDebugInfo(e);return`
3
- Debug Information:
4
- -----------------
5
- Timestamp: ${t.timestamp}
6
- URL: ${t.encodedUrl}
7
- Config: ${t.encodedConfig}
8
- Navigator Info: ${t.navigatorInfo}
9
- IFrame Status: ${t.iframeStatus}
10
- Last Request: ${t.lastRequest}
11
- Last Response: ${t.lastResponse}
12
- Client Status: ${t.clientStatus}
13
- Error: ${t.error}
14
- `.trim()}};let J={id:`frak-wallet`,name:`frak-wallet`,title:`Frak Wallet`,allow:`publickey-credentials-get *; clipboard-write; web-share *`,style:{width:`0`,height:`0`,border:`0`,position:`absolute`,zIndex:2000001,top:`-1000px`,left:`-1000px`,colorScheme:`auto`}};function sr({walletBaseUrl:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);return r.id=J.id,r.name=J.name,r.allow=J.allow,r.style.zIndex=J.style.zIndex.toString(),cr({iframe:r,isVisible:!1}),document.body.appendChild(r),new Promise(n=>{r?.addEventListener(`load`,()=>n(r)),r.src=`${t?.walletUrl??e??`https://wallet.frak.id`}/listener`})}function cr({iframe:e,isVisible:t}){if(!t){e.style.width=`0`,e.style.height=`0`,e.style.border=`0`,e.style.position=`fixed`,e.style.top=`-1000px`,e.style.left=`-1000px`;return}e.style.position=`fixed`,e.style.top=`0`,e.style.left=`0`,e.style.width=`100%`,e.style.height=`100%`,e.style.pointerEvents=`auto`}function lr(e=`/listener`){if(!window.opener)return null;let t=t=>{try{return t.location.origin===window.location.origin&&t.location.pathname===e}catch{return!1}};if(t(window.opener))return window.opener;try{let e=window.opener.frames;for(let n=0;n<e.length;n++)if(t(e[n]))return e[n];return null}catch(t){return console.error(`[findIframeInOpener] Error finding iframe with pathname ${e}:`,t),null}}function ur({iframe:e}){let t=new Ln;return{handleEvent:async n=>{if(!(`iframeLifecycle`in n))return;let{iframeLifecycle:r,data:i}=n;switch(r){case`connected`:t.resolve(!0);break;case`do-backup`:i.backup?localStorage.setItem(q,i.backup):localStorage.removeItem(q);break;case`remove-backup`:localStorage.removeItem(q);break;case`show`:case`hide`:cr({iframe:e,isVisible:r===`show`});break;case`handshake`:e.contentWindow?.postMessage({clientLifecycle:`handshake-response`,data:{token:i.token,currentUrl:window.location.href}},`*`);break;case`redirect`:{let e=new URL(i.baseRedirectUrl);e.searchParams.has(`u`)?(e.searchParams.delete(`u`),e.searchParams.append(`u`,window.location.href),window.location.href=e.toString()):window.location.href=i.baseRedirectUrl;break}}},isConnected:t.promise}}function dr({config:e,iframe:t}){let n=e?.walletUrl??`https://wallet.frak.id`,r=ur({iframe:t}),i=new or(e,t);if(!t.contentWindow)throw new W(U.configError,`The iframe does not have a content window`);let a=Rn({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await r.isConnected)throw new W(U.clientNotConnected,`The iframe provider isn't connected yet`);return t}},In(),{onRequest(e,t){return i.setLastRequest(e),t},onResponse(e,t){return i.setLastResponse(e,t),t}}],lifecycleHandlers:{iframeLifecycle:async(e,t)=>{await r.handleEvent(e)}}}),o=fr(a,r),s=async()=>{o(),a.cleanup(),t.remove()},c;console.log(`[Frak SDK] Initializing OpenPanel`),c=new ir({apiUrl:`https://op-api.gcp.frak.id`,clientId:`f305d11d-b93b-487c-80d4-92deb7903e98`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:e,payload:t})=>(e!==`track`||!t?.properties||`sdkVersion`in t.properties||(t.properties={...t.properties,sdkVersion:`0.1.1`}),!0)}),c.setGlobalProperties({sdkVersion:`0.1.1`}),c.init();let l=pr({config:e,rpcClient:a,lifecycleManager:r}).then(()=>i.updateSetupStatus(!0));return{config:e,debugInfo:i,waitForConnection:r.isConnected,waitForSetup:l,request:a.request,listenerRequest:a.listen,destroy:s,openPanel:c}}function fr(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,1e3),r=setTimeout(()=>{o(),console.log(`Heartbeat timeout: connection failed`)},3e4),await t.isConnected,o()}function o(){n&&clearInterval(n),r&&clearTimeout(r)}return a(),o}async function pr({config:e,rpcClient:t,lifecycleManager:n}){await n.isConnected,ar(t,n.isConnected);async function r(){let n=e.customizations?.css;if(!n)return;let r={clientLifecycle:`modal-css`,data:{cssLink:n}};t.sendLifecycle(r)}async function i(){let n=e.customizations?.i18n;if(!n)return;let r={clientLifecycle:`modal-i18n`,data:{i18n:n}};t.sendLifecycle(r)}async function a(){if(typeof window>`u`)return;let e=window.localStorage.getItem(q);if(!e)return;let n={clientLifecycle:`restore-backup`,data:{backup:e}};t.sendLifecycle(n)}await Promise.allSettled([r(),i(),a()])}function mr(e){return Pn(Vn(e))}let Y={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function hr(e){return e&&e in Y?e:`eur`}function gr(e){return e?Y[e]??Y.eur:Y.eur}function _r(e,t){let n=gr(t),r=hr(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function vr(e){return e?`${e}Amount`:`eurAmount`}async function yr({config:e}){let t=br(e),n=await sr({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=dr({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function br(e){let t=hr(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}let X={press:{openArticle:`0xc0a24ffb`,readArticle:`0xd5bd0fbe`},dapp:{proofVerifiableStorageUpdate:`0x2ab2aeef`,callableVerifiableStorageUpdate:`0xa07da986`},webshop:{open:`0xb311798f`},referral:{referred:`0x010cc3b9`,createLink:`0xb2c0f17c`},purchase:{started:`0xd87e90c3`,completed:`0x8403aeb4`,unsafeCompleted:`0x4d5b14e0`},retail:{customerMeeting:`0x74489004`}},Z={dapp:1,press:2,webshop:3,retail:4,referral:30,purchase:31},xr=Object.entries(Z).reduce((e,[t,n])=>(e[t]=BigInt(1)<<BigInt(n),e),{});function Sr(e){document.readyState===`complete`||document.readyState===`interactive`?setTimeout(e,1):document.addEventListener?document.addEventListener(`DOMContentLoaded`,e):document.attachEvent(`onreadystatechange`,()=>{document.readyState===`complete`&&e()})}async function Cr(e,t,n=`text/javascript`){return document.getElementById(e)?Promise.resolve(!0):new Promise((r,i)=>{let a=document.createElement(`script`);a.id=e,a.src=t,a.defer=!0,a.type=n,a.onload=()=>r(!0),a.onerror=()=>i(Error(`Script load error for ${t}`)),document.head.appendChild(a)})}function wr(){Tr(),Er()}function Tr(){window.FrakSetup.config={walletUrl:`https://wallet.frak.id`,metadata:{name:`Gapianne`,lang:`fr`,currency:`eur`,logoUrl:`https://gapianne.com/cdn/shop/files/logo-gapianne_7a65f4c4-54e8-4831-afa2-0849e4c5f8de.png`,homepageLink:`https://gapianne.com/`},customizations:{i18n:{"sharing.title":`Prêt(e) à révéler un secret bien-être ?`,"sharing.text":`Découvre ce produit chez Gapianne`,"sdk.wallet.login.text":`Créez votre porte-monnaie avec **{{ productName }}** et recevez **{{ estimatedReward }}** par ami(e) parrainé(e)`}},domain:window.location.host},window.FrakSetup.modalConfig={login:{allowSso:!0},metadata:{isDismissible:!0}},window.FrakSetup.modalShareConfig={link:window.location.href},window.FrakSetup.modalWalletConfig={metadata:{position:`left`}}}function Er(){let e=document.querySelectorAll(`#nexus-share-button > button`);for(let t of Array.from(e)){let e=document.createElement(`frak-button-share`);e.setAttribute(`text`,`PARTAGE ET GAGNE {REWARD} !`),e.setAttribute(`no-reward-text`,`PARTAGE ET GAGNE`),e.setAttribute(`use-reward`,`true`),e.setAttribute(`show-wallet`,`true`),e.setAttribute(`classname`,`button w-full`),t.replaceWith(e)}}let Dr={"gapianne.com":wr};function Or(){let e=Dr[window.location.host];e&&(e(),Cr(`frak-components`,`https://cdn.jsdelivr.net/npm/@frak-labs/components@latest/cdn/components.js`,`module`))}let kr={openArticle({articleId:e}){let t=k([X.press.openArticle,y(e,{size:32})]);return{handlerTypeDenominator:S(Z.press),interactionData:t}},readArticle({articleId:e}){let t=k([X.press.readArticle,y(e,{size:32})]);return{handlerTypeDenominator:S(Z.press),interactionData:t}}},Ar={startPurchase({purchaseId:e}){let t=k([X.purchase.started,y(e,{size:32})]);return{handlerTypeDenominator:S(Z.purchase),interactionData:t}},completedPurchase({purchaseId:e,proof:t}){let n=rt([{type:`uint256`},{type:`bytes32[]`}],[BigInt(e),t]),r=k([X.purchase.completed,n]);return{handlerTypeDenominator:S(Z.purchase),interactionData:r}},unsafeCompletedPurchase({purchaseId:e}){let t=k([X.purchase.unsafeCompleted,y(e,{size:32})]);return{handlerTypeDenominator:S(Z.purchase),interactionData:t}}},jr={createLink(){return{handlerTypeDenominator:S(Z.referral),interactionData:X.referral.createLink}},referred({referrer:e}){let t=k([X.referral.referred,y(e,{size:32})]);return{handlerTypeDenominator:S(Z.referral),interactionData:t}}},Mr={customerMeeting({agencyId:e}){let t=k([X.retail.customerMeeting,y(e,{size:32})]);return{handlerTypeDenominator:S(Z.retail),interactionData:t}}},Nr={open(){return{handlerTypeDenominator:S(Z.webshop),interactionData:X.webshop.open}}};function Pr(){return Et(96)}async function Fr(e,t){return await e.request({method:`frak_displayEmbeddedWallet`,params:[t,e.config.metadata]})}async function Q(e,{steps:t,metadata:n}){return await e.request({method:`frak_displayModal`,params:[t,n,e.config.metadata]})}async function Ir(e){return await e.request({method:`frak_getProductInformation`})}async function Lr(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function Rr(e,{walletStatus:t,frakContext:n,modalConfig:r,productId:i,options:a}){if(!n?.r)return`no-referrer`;K(e,`user_referred_started`,{properties:{referrer:n?.r,walletStatus:t?.key}});let o=!1;async function s(){if(!o)return o=!0,Br(e,{modalConfig:{...r,loggedIn:{action:{key:`referred`}}},walletStatus:t})}async function c(t){await Ur(e,{productId:i,interaction:jr.referred({referrer:t})})}try{let{status:r,currentWallet:i}=await zr({initialWalletStatus:t,getFreshWalletStatus:s,pushReferralInteraction:c,frakContext:n});return G.replaceUrl({url:window.location?.href,context:a?.alwaysAppendUrl?{r:i}:null}),K(e,`user_referred_completed`,{properties:{status:r,referrer:n?.r,wallet:i}}),r}catch(r){return console.log(`Error processing referral`,{error:r}),K(e,`user_referred_error`,{properties:{referrer:n?.r,error:r instanceof W?`[${r.code}] ${r.name} - ${r.message}`:r instanceof Error?r.message:`undefined`}}),G.replaceUrl({url:window.location?.href,context:a?.alwaysAppendUrl?{r:t?.wallet}:null}),Vr(r)}}async function zr({initialWalletStatus:e,getFreshWalletStatus:t,pushReferralInteraction:n,frakContext:r}){let i=e?.wallet;return i||=await t(),i&&Tt(r.r,i)?{status:`self-referral`,currentWallet:i}:(e?.interactionSession||(i=await t()),await n(r.r),{status:`success`,currentWallet:i})}async function Br(e,{modalConfig:t,walletStatus:n}){return n?.interactionSession?n.wallet??void 0:(await Fr(e,t??{}))?.wallet??void 0}function Vr(e){if(e instanceof W)switch(e.code){case U.walletNotConnected:return`no-wallet`;case U.serverErrorForInteractionDelegation:return`no-session`;default:return`error`}return`error`}async function Hr(e,{productId:t,modalConfig:n,options:r}={}){let i=G.parse({url:window.location.href}),a=await Gr(e);try{return await Rr(e,{walletStatus:a,frakContext:i,modalConfig:n,productId:t,options:r})}catch(e){console.warn(`Error processing referral`,{error:e})}}async function Ur(e,{productId:t,interaction:n,validation:r}){let i=t??zn(e.config);return await e.request({method:`frak_sendInteraction`,params:[i,n,r]})}async function Wr(e){if(typeof window>`u`){console.warn(`[Frak] No window found, can't track purchase`);return}let t=window.sessionStorage.getItem(`frak-wallet-interaction-token`);if(!t){console.warn(`[Frak] No frak session found, skipping purchase check`);return}await fetch(`https://backend.frak.id/interactions/listenForPurchase`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":t},body:JSON.stringify(e)})}function Gr(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(Kr(e,t),t));let n=new Ln,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{Kr(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function Kr(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function qr(e,{metadata:t,login:n,openSession:r}){return $(e,{steps:{login:n??{},openSession:r??{}},metadata:t})}function $(e,t){function n(n){return $(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return $(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return $(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n){return n&&(t.metadata=n(t.metadata??{})),await Q(e,t)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function Jr(e,{tx:t,metadata:n}){return(await Q(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}async function Yr(e,{siwe:t,metadata:n}){let r=e.config?.domain??window.location.host,i=t?.statement??`I confirm that I want to use my Frak wallet on: ${e.config.metadata.name}`;return(await Q(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??Pr(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}let Xr=dr;return Sr(Or),e.DebugInfoGatherer=or,e.FrakContextManager=G,e.PressInteractionEncoder=kr,e.PurchaseInteractionEncoder=Ar,e.ReferralInteractionEncoder=jr,e.RetailInteractionEncoder=Mr,e.WebShopInteractionEncoder=Nr,e.base64urlDecode=Vn,e.base64urlEncode=Bn,e.baseIframeProps=J,e.compressJsonToB64=Hn,e.createIFrameFrakClient=dr,e.createIFrameNexusClient=Xr,e.createIframe=sr,e.decompressJsonFromB64=mr,e.displayEmbeddedWallet=Fr,e.displayModal=Q,e.findIframeInOpener=lr,e.formatAmount=_r,e.generateSsoUrl=Un,e.getCurrencyAmountKey=vr,e.getProductInformation=Ir,e.getSupportedCurrency=hr,e.getSupportedLocale=gr,e.interactionTypes=X,e.locales=Y,e.modalBuilder=qr,e.openSso=qn,e.prepareSso=Lr,e.processReferral=Rr,e.productTypes=Z,e.productTypesMask=xr,e.referralInteraction=Hr,e.sendInteraction=Ur,e.sendTransaction=Jr,e.setupClient=yr,e.siweAuthenticate=Yr,e.ssoPopupFeatures=Gn,e.ssoPopupName=Kn,e.trackEvent=K,e.trackPurchaseStatus=Wr,e.watchWalletStatus=Gr,e})({});