@frak-labs/components 1.1.0-beta.594d023c → 1.1.0-beta.85ee7f39

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.
Files changed (31) hide show
  1. package/cdn/{Banner.DGYexiiS.js → Banner.wHYQSyz3.js} +2 -2
  2. package/cdn/{ButtonShare.DFg0XCDd.js → ButtonShare.DIyDUgaT.js} +1 -1
  3. package/cdn/{ButtonWallet.sGDvcAXt.js → ButtonWallet.DNxaFMHH.js} +1 -1
  4. package/cdn/{GiftIcon.C1uAOx7A.js → GiftIcon.DV54EwfG.js} +1 -1
  5. package/cdn/OpenInAppButton.X1noMnvq.js +1 -0
  6. package/cdn/PostPurchase._SYhdjOf.js +89 -0
  7. package/cdn/components.js +1 -1
  8. package/cdn/defaults.CT8FNvot.js +58 -0
  9. package/cdn/loader.js +10 -6
  10. package/cdn/rewards.D3nh4aTd.js +1 -0
  11. package/cdn/useGlobalComponents.BT0loDl8.js +1 -0
  12. package/cdn/{useLightDomStyles.CKtA4k-_.js → useLightDomStyles.CZ1iTaa9.js} +1 -1
  13. package/cdn/{useReward.CXgeQcsH.js → useReward.DWHEt1Zs.js} +1 -1
  14. package/dist/{GiftIcon-BhL0bhVu.js → GiftIcon-DI0rUKHp.js} +7 -7
  15. package/dist/banner.js +6 -6
  16. package/dist/buttonShare.js +5 -5
  17. package/dist/buttonWallet.js +2 -2
  18. package/dist/openInApp.js +4 -3
  19. package/dist/postPurchase.d.ts +3 -1
  20. package/dist/postPurchase.js +11 -8
  21. package/dist/{rewards-Cxn-bgzC.js → rewards-CZkWSndn.js} +3 -6
  22. package/dist/{useGlobalComponents-CeTO2xYs.js → useGlobalComponents-DFv33ujB.js} +1 -1
  23. package/dist/{useLightDomStyles-B2U96tzU.js → useLightDomStyles-B_IbOqJZ.js} +1 -1
  24. package/dist/{usePlacement-Bpo25qjA.js → usePlacement-DtwWaLHO.js} +3 -1
  25. package/dist/{useReward-BMYSGY-o.js → useReward-D5zzFR11.js} +1 -1
  26. package/package.json +3 -3
  27. package/cdn/OpenInAppButton.CxLPpqFO.js +0 -1
  28. package/cdn/PostPurchase.D6Mzbjtu.js +0 -89
  29. package/cdn/defaults.BEvoSiy5.js +0 -58
  30. package/cdn/rewards.B2smvfIs.js +0 -1
  31. package/cdn/useGlobalComponents.CqTI84Mw.js +0 -1
package/cdn/loader.js CHANGED
@@ -151,14 +151,18 @@ var e=Object.defineProperty,t=(t,n)=>{let r={};for(var i in t)e(r,i,{get:t[i],en
151
151
  }
152
152
  .sharedBaseCss_buttonReset__7cswil0:focus-visible {
153
153
  outline-color: currentColor;
154
- }`;function r(e,t){let n=document.getElementById(e);if(n){n.textContent!==t&&(n.textContent=t);return}let r=document.createElement(`style`);r.id=e,r.textContent=t,document.head.appendChild(r)}function i(e,t){let n=`frak-base-${e}`;if(document.getElementById(n)||!t)return;let r=document.createElement(`style`);r.id=n,r.textContent=t,document.head.appendChild(r)}function a(e,t,n){r(`frak-placement-${e}-${t}`,n)}const o={injectBase:i,injectPlacement:a};function s(e){document.readyState===`complete`||document.readyState===`interactive`?setTimeout(e,1):document.addEventListener(`DOMContentLoaded`,e)}const c=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,l=new TextEncoder;function u(e,t){if(!c.test(e))throw Error(`${t} must be a UUID string, got: ${e}`);return h(e.replace(/-/g,``))}function d(e,t,n){if(!Number.isInteger(n)||n<0)throw Error(`ts must be a non-negative integer: ${n}`);let r=BigInt(n);for(let n=7;n>=0;n--)e[t+n]=Number(r&255n),r>>=8n}function f(e){if(e.binding.length!==0&&e.binding.length!==32)throw Error(`binding must be empty or 32 bytes, got ${e.binding.length}`);let t=l.encode(e.op),n=new Uint8Array(t.length+32+32+8),r=0;return n.set(t,r),r+=t.length,n.set(u(e.merchantId,`merchantId`),r),r+=16,n.set(u(e.anonymousId,`anonymousId`),r),r+=16,n.set(e.binding,r),r+=32,d(n,r,e.ts),n}function p(e){if(e.length<16)throw Error(`deriveClientIdFromHash requires at least 16 bytes, got ${e.length}`);let t=e.slice(0,16);t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=m(t);return[n.slice(0,8),n.slice(8,12),n.slice(12,16),n.slice(16,20),n.slice(20,32)].join(`-`)}function m(e){return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}function h(e){return Uint8Array.from(e.match(/../g)??[],e=>Number.parseInt(e,16))}function g(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function _(e){if(e.pk.length!==65)throw Error(`pk must be 65 bytes, got ${e.pk.length}`);if(e.sig.length!==64)throw Error(`sig must be 64 bytes, got ${e.sig.length}`);let t=new Uint8Array(138);return t[0]=e.v,t.set(e.pk,1),d(t,66,e.ts),t.set(e.sig,74),g(t)}function v(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}function y(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(`${n}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let n=t&&`"${t}" `;throw RangeError(`${n}expected integer >= 0, got ${e}`)}}function b(e,t,n=``){let r=v(e),i=e?.length,a=t!==void 0;if(!r||a&&i!==t){let o=n&&`"${n}" `,s=a?` of length ${t}`:``,c=r?`length=${i}`:`type=${typeof e}`,l=o+`expected Uint8Array`+s+`, got `+c;throw r?RangeError(l):TypeError(l)}return e}function ee(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`Hash must wrapped by utils.createHasher`);if(y(e.outputLen),y(e.blockLen),e.outputLen<1)throw Error(`"outputLen" must be >= 1`);if(e.blockLen<1)throw Error(`"blockLen" must be >= 1`)}function x(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 S(e,t){b(e,void 0,`digestInto() output`);let n=t.outputLen;if(e.length<n)throw RangeError(`"digestInto() output" expected to be of length >=`+n)}function C(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function w(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function T(e,t){return e<<32-t|e>>>t}const te=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,ne=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function re(e){if(b(e),te)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=ne[e[n]];return t}const E={_0:48,_9:57,A:65,F:70,a:97,f:102};function ie(e){if(e>=E._0&&e<=E._9)return e-E._0;if(e>=E.A&&e<=E.F)return e-(E.A-10);if(e>=E.a&&e<=E.f)return e-(E.a-10)}function ae(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);if(te)try{return Uint8Array.fromHex(e)}catch(e){throw e instanceof SyntaxError?RangeError(e.message):e}let t=e.length,n=t/2;if(t%2)throw RangeError(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=ie(e.charCodeAt(i)),a=ie(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw RangeError(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function oe(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];b(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function se(e,t={}){let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function ce(e=32){y(e,`bytesLength`);let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);if(e>65536)throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}const le=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ue(e,t,n){return e&t^~e&n}function de(e,t,n){return e&t^e&n^t&n}var fe=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=w(this.buffer)}update(e){x(this),b(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=w(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){x(this),S(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,C(this.buffer.subarray(a)),this.padOffset>r-a&&(this.process(n,0),a=0);for(let e=a;e<r;e++)t[e]=0;n.setBigUint64(r-8,BigInt(this.length*8),i),this.process(n,0);let o=w(e),s=this.outputLen;if(s%4)throw Error(`_sha2: outputLen must 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()}};const D=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),pe=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]),O=new Uint32Array(64);var me=class extends fe{constructor(e){super(64,e,8,!1)}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)O[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=O[e-15],n=O[e-2],r=T(t,7)^T(t,18)^t>>>3,i=T(n,17)^T(n,19)^n>>>10;O[e]=i+O[e-7]+r+O[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=T(o,6)^T(o,11)^T(o,25),u=l+t+ue(o,s,c)+pe[e]+O[e]|0,d=(T(n,2)^T(n,13)^T(n,22))+de(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(){C(O)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),C(this.buffer)}},he=class extends me{A=D[0]|0;B=D[1]|0;C=D[2]|0;D=D[3]|0;E=D[4]|0;F=D[5]|0;G=D[6]|0;H=D[7]|0;constructor(){super(32)}};const ge=se(()=>new he,le(1)),k=(e,t,n)=>b(e,t,n),_e=y,ve=re,A=(...e)=>oe(...e),ye=e=>ae(e),be=v,xe=e=>ce(e),Se=BigInt(0),Ce=BigInt(1)
154
+ }`;function r(e,t){let n=document.getElementById(e);if(n){n.textContent!==t&&(n.textContent=t);return}let r=document.createElement(`style`);r.id=e,r.textContent=t,document.head.appendChild(r)}function i(e,t){let n=`frak-base-${e}`;if(document.getElementById(n)||!t)return;let r=document.createElement(`style`);r.id=n,r.textContent=t,document.head.appendChild(r)}function a(e,t,n){r(`frak-placement-${e}-${t}`,n)}const o={injectBase:i,injectPlacement:a};function s(e){document.readyState===`complete`||document.readyState===`interactive`?setTimeout(e,1):document.addEventListener(`DOMContentLoaded`,e)}const c=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,l=new TextEncoder;function u(e,t){if(!c.test(e))throw Error(`${t} must be a UUID string, got: ${e}`);return h(e.replace(/-/g,``))}function d(e,t,n){if(!Number.isInteger(n)||n<0)throw Error(`ts must be a non-negative integer: ${n}`);let r=BigInt(n);for(let n=7;n>=0;n--)e[t+n]=Number(r&255n),r>>=8n}function f(e){if(e.binding.length!==0&&e.binding.length!==32)throw Error(`binding must be empty or 32 bytes, got ${e.binding.length}`);let t=l.encode(e.op),n=new Uint8Array(t.length+32+32+8),r=0;return n.set(t,r),r+=t.length,n.set(u(e.merchantId,`merchantId`),r),r+=16,n.set(u(e.anonymousId,`anonymousId`),r),r+=16,n.set(e.binding,r),r+=32,d(n,r,e.ts),n}function p(e){if(e.length<16)throw Error(`deriveClientIdFromHash requires at least 16 bytes, got ${e.length}`);let t=e.slice(0,16);t[6]=t[6]&15|64,t[8]=t[8]&63|128;let n=m(t);return[n.slice(0,8),n.slice(8,12),n.slice(12,16),n.slice(16,20),n.slice(20,32)].join(`-`)}function m(e){return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}function h(e){return Uint8Array.from(e.match(/../g)??[],e=>Number.parseInt(e,16))}function g(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function _(e){if(e.pk.length!==65)throw Error(`pk must be 65 bytes, got ${e.pk.length}`);if(e.sig.length!==64)throw Error(`sig must be 64 bytes, got ${e.sig.length}`);let t=new Uint8Array(138);return t[0]=e.v,t.set(e.pk,1),d(t,66,e.ts),t.set(e.sig,74),g(t)}const v=e=>e/2**32|0,ee=e=>e>>>0;function y(e,t,n,r){let i=v(n),a=ee(n);e.setUint32(t,r?a:i,r),e.setUint32(t+4,r?i:a,r)}function b(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}const te=e=>e?`"${e}" `:``;function x(e,t=``){if(typeof e!=`number`)throw TypeError(te(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(te(t)+`expected integer >= 0, got `+e);return e}function S(e,t,n=``){if(b(e)&&(t===void 0||e.length===t))return e;t!==void 0&&x(t,`length`);let r=b(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=te(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}function ne(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`expected hash wrapped by utils.createHasher`);if(x(e.outputLen),x(e.blockLen),e.outputLen<1||e.blockLen<1)throw Error(`hash blockLen / outputLen must be >= 1`)}const C=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`"${t}" `)+`expected object, got type=`+typeof e)};function w(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function T(e,t){S(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function E(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function D(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function O(e,t){return e<<32-t|e>>>t}const re=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,ie=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function ae(e){if(S(e),re)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=ie[e[n]];return t}function oe(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function se(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);if(re)try{return Uint8Array.fromHex(e)}catch(e){throw e instanceof SyntaxError?RangeError(e.message):e}let t=e.length,n=t/2;if(t%2)throw RangeError(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=oe(e.charCodeAt(i)),a=oe(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw RangeError(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function ce(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];S(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function le(e,t,n=`opts`){return C(e,`defaults`),t!==void 0&&C(t,n),Object.assign(e,t)}function ue(e,t={}){if(typeof e!=`function`)throw TypeError(`"hashCons" expected function, got type=`+typeof e);t=le({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function de(e=32){x(e,`bytesLength`);let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);if(e>65536)throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}const fe=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function pe(e,t,n){return e&t^~e&n}function me(e,t,n){return e&t^e&n^t&n}var he=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=D(this.buffer)}update(e){w(this),S(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=D(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){w(this),T(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,t.fill(0,a),this.padOffset>r-a&&(this.process(n,0),t.fill(0)),y(n,r-8,this.length*8,i),this.process(n,0),this.roundClean();let o=e===t?n:D(e),s=this.outputLen,c=s/4,l=this.get();if(s%4||c>l.length)throw Error(`invalid outputLen`);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}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}};const ge=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),_e=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]),k=new Uint32Array(64);var ve=class extends he{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[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}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)k[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=k[e-15],n=k[e-2],r=O(t,7)^O(t,18)^t>>>3,i=O(n,17)^O(n,19)^n>>>10;k[e]=i+k[e-7]+r+k[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=O(o,6)^O(o,11)^O(o,25),u=l+t+pe(o,s,c)+_e[e]+k[e]|0,d=(O(n,2)^O(n,13)^O(n,22))+me(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(k)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),E(this.buffer)}},ye=class extends ve{constructor(){super(32,ge)}};const be=ue(()=>new ye,fe(1));
155
155
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
156
- ;function j(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}" `;throw TypeError(n+`expected boolean, got type=`+typeof e)}return e}function we(e){if(typeof e==`bigint`){if(!Ne(e))throw RangeError(`positive bigint expected, got `+e)}else _e(e);return e}function Te(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(n+`expected number, got type=`+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw RangeError(n+`expected safe integer, got `+e)}}function Ee(e){let t=we(e).toString(16);return t.length&1?`0`+t:t}function De(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?Se:BigInt(`0x`+e)}function Oe(e){return De(re(e))}function ke(e){return De(re(Me(b(e)).reverse()))}function Ae(e,t){if(y(t),t===0)throw RangeError(`zero length`);e=we(e);let n=e.toString(16);if(n.length>t*2)throw RangeError(`number too large`);return ae(n.padStart(t*2,`0`))}function je(e,t){return Ae(e,t).reverse()}function Me(e){return Uint8Array.from(k(e))}const Ne=e=>typeof e==`bigint`&&Se<=e;function Pe(e,t,n){return Ne(e)&&Ne(t)&&Ne(n)&&t<=e&&e<n}function Fe(e,t,n,r){if(!Pe(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function Ie(e){if(e<Se)throw Error(`expected non-negative bigint, got `+e);let t;for(t=0;e>Se;e>>=Ce,t+=1);return t}const Le=e=>(Ce<<BigInt(e))-Ce;function Re(e,t,n){if(y(e,`hashLen`),y(t,`qByteLen`),typeof n!=`function`)throw TypeError(`hmacFn must be a function`);let r=e=>new Uint8Array(e),i=Uint8Array.of(),a=Uint8Array.of(0),o=Uint8Array.of(1),s=r(e),c=r(e),l=0,u=()=>{s.fill(1),c.fill(0),l=0},d=(...e)=>n(c,A(s,...e)),f=(e=i)=>{c=d(a,e),s=d(),e.length!==0&&(c=d(o,e),s=d())},p=()=>{if(l++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,n=[];for(;e<t;){s=d();let t=s.slice();n.push(t),e+=s.length}return A(...n)};return(e,t)=>{u(),f(e);let n;for(;(n=t(p()))===void 0;)f();return u(),n}}function ze(e,t={},n={}){if(Object.prototype.toString.call(e)!==`[object Object]`)throw TypeError(`expected valid options object`);function r(t,n,r){if(!r&&n!==`function`&&!Object.hasOwn(e,t))throw TypeError(`param "${t}" is invalid: expected own property`);let i=e[t];if(r&&i===void 0)return;let a=typeof i;if(a!==n||i===null)throw TypeError(`param "${t}" is invalid: expected ${n}, got ${a}`)}let i=(e,t)=>Object.entries(e).forEach(([e,n])=>r(e,n,t));i(t,!1),i(n,!0)}
156
+ function xe(e,t,n=()=>{}){if(!Array.isArray(e))throw TypeError(`"${t}" expected array, got type=${typeof e}`);for(let r=0;r<e.length;r++)n(e[r],`${t}[${r}]`);return e}const A=(e,t,n)=>S(e,t,n),Se=x;function Ce(e,t=``){if(typeof e!=`string`){let n=t&&`"${t}" `;throw TypeError(n+`expected string, got type=`+typeof e)}return e}function j(e,t=`object`){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`);return e}function we(e,t){if(typeof e!=`function`)throw TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}const Te=ae,M=(...e)=>ce(...e),Ee=e=>se(e),De=b,Oe=e=>de(e),ke=BigInt(0),Ae=BigInt(1),je=e=>e?`"${e}" `:``;function N(e,t=``){if(typeof e!=`boolean`)throw TypeError(je(t)+`expected boolean, got type=`+typeof e);return e}function Me(e){if(typeof e==`bigint`){if(!F(e))throw RangeError(`positive bigint expected, got `+e)}else Se(e);return e}function Ne(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(n+`expected number, got type=`+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw RangeError(n+`expected safe integer, got `+e)}}function Pe(e){let t=Me(e).toString(16);return t.length&1?`0`+t:t}function Fe(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?ke:BigInt(`0x`+e)}function P(e){return Fe(ae(e))}function Ie(e){return Fe(ae(ze(S(e)).reverse()))}function Le(e,t){if(x(t),t===0)throw Error(`zero output length is invalid`);e=Me(e);let n=t*2,r=e.toString(16);if(r.length>n)throw RangeError(`number is too large`);return se(r.padStart(n,`0`))}function Re(e,t){return Le(e,t).reverse()}function ze(e){return Uint8Array.from(A(e))}function F(e){return typeof e==`bigint`&&ke<=e}function Be(e,t,n){return F(e)&&F(t)&&F(n)&&t<=e&&e<n}function Ve(e,t,n,r){if(!Be(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function He(e){if(e<ke)throw Error(`expected non-negative bigint, got `+e);return e===ke?0:e.toString(2).length}const Ue=e=>(Ne(e,`n`),(Ae<<BigInt(e))-Ae);function We(e,t,n){if(x(e,`hashLen`),x(t,`qByteLen`),typeof n!=`function`)throw TypeError(`hmacFn must be a function`);let r=e=>new Uint8Array(e),i=Uint8Array.of(),a=Uint8Array.of(0),o=Uint8Array.of(1),s=r(e),c=r(e),l=0,u=()=>{s.fill(1),c.fill(0),l=0},d=(...e)=>n(c,M(s,...e)),f=(e=i)=>{c=d(a,e),s=d(),e.length!==0&&(c=d(o,e),s=d())},p=()=>{if(l++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,n=[];for(;e<t;){s=d();let t=s.slice();n.push(t),e+=s.length}return M(...n)};return(e,t)=>{u(),f(e);let n;for(;(n=t(p()))===void 0;)f();return u(),n}}function I(e,t={},n={},r=`object`){j(e,r),j(t,`fields`),j(n,`optFields`);function i(t,n,i){let a=r===`object`?`param "${String(t)}"`:`"${r}.${String(t)}"`,o=e[t];if(!Object.hasOwn(e,t)&&(i?o!==void 0:n!==`function`))throw TypeError(`${a} is invalid: expected own property`);if(i&&o===void 0)return;let s=typeof o;if(s!==n||o===null)throw TypeError(`${a} is invalid: expected ${n}, got ${s}`)}let a=(e,t)=>Object.entries(e).forEach(([e,n])=>i(e,n,t));a(t,!1),a(n,!0)}
157
157
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
158
- const M=BigInt(0),N=BigInt(1),P=BigInt(2),Be=BigInt(3),Ve=BigInt(4),He=BigInt(5),Ue=BigInt(7),We=BigInt(8),Ge=BigInt(9),Ke=BigInt(16);function F(e,t){if(t<=M)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=M?n:t+n}function qe(e,t){if(e===M)throw Error(`invert: expected non-zero number`);if(t<=M)throw Error(`invert: expected positive modulus, got `+t);let n=F(e,t),r=t,i=M,a=N,o=N,s=M;for(;n!==M;){let e=r/n,t=r-n*e,c=i-o*e,l=a-s*e;r=n,n=t,i=o,a=s,o=c,s=l}if(r!==N)throw Error(`invert: does not exist`);return F(i,t)}function Je(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function Ye(e,t){let n=e,r=(n.ORDER+N)/Ve,i=n.pow(t,r);return Je(n,i,t),i}function Xe(e,t){let n=e,r=(n.ORDER-He)/We,i=n.mul(t,P),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,P),a),c=n.mul(o,n.sub(s,n.ONE));return Je(n,c,t),c}function Ze(e){let t=ct(e),n=Qe(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+Ue)/Ke;return((e,t)=>{let n=e,s=n.pow(t,o),c=n.mul(s,r),l=n.mul(s,i),u=n.mul(s,a),d=n.eql(n.sqr(c),t),f=n.eql(n.sqr(l),t);s=n.cmov(s,c,d),c=n.cmov(u,l,f);let p=n.eql(n.sqr(c),t),m=n.cmov(s,c,p);return Je(n,m,t),m})}function Qe(e){if(e<Be)throw Error(`sqrt is not defined for small field`);let t=e-N,n=0;for(;t%P===M;)t/=P,n++;let r=P,i=ct(e);for(;it(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return Ye;let a=i.pow(r,t),o=(t+N)/P;return function(e,r){let i=e;if(i.is0(r))return r;if(it(i,r)!==1)throw Error(`Cannot find square root`);let s=n,c=i.mul(i.ONE,a),l=i.pow(r,t),u=i.pow(r,o);for(;!i.eql(l,i.ONE);){if(i.is0(l))return i.ZERO;let e=1,t=i.sqr(l);for(;!i.eql(t,i.ONE);)if(e++,t=i.sqr(t),e===s)throw Error(`Cannot find square root`);let n=N<<BigInt(s-e-1),r=i.pow(c,n);s=e,c=i.sqr(r),l=i.mul(l,c),u=i.mul(u,r)}return u}}function $e(e){return e%Ve===Be?Ye:e%We===He?Xe:e%Ke===Ge?Ze(e):Qe(e)}const et=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function tt(e){if(ze(e,et.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,BYTES:`number`,BITS:`number`})),Te(e.BYTES,`BYTES`),Te(e.BITS,`BITS`),e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=N)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function nt(e,t,n){let r=e;if(n<M)throw Error(`invalid exponent, negatives unsupported`);if(n===M)return r.ONE;if(n===N)return t;let i=r.ONE,a=t;for(;n>M;)n&N&&(i=r.mul(i,a)),a=r.sqr(a),n>>=N;return i}function rt(e,t,n=!1){let r=e,i=Array(t.length).fill(n?r.ZERO:void 0),a=t.reduce((e,t,n)=>r.is0(t)?e:(i[n]=e,r.mul(e,t)),r.ONE),o=r.inv(a);return t.reduceRight((e,t,n)=>r.is0(t)?e:(i[n]=r.mul(e,i[n]),r.mul(e,t)),o),i}function it(e,t){let n=e,r=(n.ORDER-N)/P,i=n.pow(t,r),a=n.eql(i,n.ONE),o=n.eql(i,n.ZERO),s=n.eql(i,n.neg(n.ONE));if(!a&&!o&&!s)throw Error(`invalid Legendre symbol result`);return a?1:o?0:-1}function at(e,t){if(t!==void 0&&_e(t),e<=M)throw Error(`invalid n length: expected positive n, got `+e);if(t!==void 0&&t<1)throw Error(`invalid n length: expected positive bit length, got `+t);let n=Ie(e);if(t!==void 0&&t<n)throw Error(`invalid n length: expected bit length (${n}) >= n.length (${t})`);let r=t===void 0?n:t;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}const ot=new WeakMap;var st=class{ORDER;BITS;BYTES;isLE;ZERO=M;ONE=N;_lengths;_mod;constructor(e,t={}){if(e<=N)throw Error(`invalid field: expected ORDER > 1, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=at(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return F(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return M<=e&&e<this.ORDER}is0(e){return e===M}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&N)===N}neg(e){return F(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return F(e*e,this.ORDER)}add(e,t){return F(e+t,this.ORDER)}sub(e,t){return F(e-t,this.ORDER)}mul(e,t){return F(e*t,this.ORDER)}pow(e,t){return nt(this,e,t)}div(e,t){return F(e*qe(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return qe(e,this.ORDER)}sqrt(e){let t=ot.get(this);return t||ot.set(this,t=$e(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?je(e,this.BYTES):Ae(e,this.BYTES)}fromBytes(e,t=!1){k(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:a,_mod:o}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let s=i?ke(e):Oe(e);if(o&&(s=F(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return rt(this,e)}cmov(e,t,n){return j(n,`condition`),n?t:e}};Object.freeze(st.prototype);function ct(e,t={}){return new st(e,t)}function lt(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);if(e<=N)throw Error(`field order must be greater than 1`);let t=Ie(e-N);return Math.ceil(t/8)}function ut(e){let t=lt(e);return t+Math.ceil(t/2)}function dt(e,t,n=!1){k(e);let r=e.length,i=lt(t),a=Math.max(ut(t),16);if(r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=F(n?ke(e):Oe(e),t-N)+N;return n?je(o,i):Ae(o,i)}
158
+ const L=BigInt(0),R=BigInt(1),z=BigInt(2),Ge=BigInt(3),Ke=BigInt(4),qe=BigInt(5),Je=BigInt(7),Ye=BigInt(8),Xe=BigInt(9),Ze=BigInt(15),Qe=BigInt(16),$e=BigInt(`0x10000000000000000`);function B(e,t){if(t<=L)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=L?n:t+n}function et(e,t,n){if(n<=R)throw Error(`pow: expected modulus > 1, got `+n);if(typeof t!=`bigint`)throw TypeError(`invalid exponent: expected bigint, got `+typeof t);if(t<L)throw Error(`invalid exponent, negatives unsupported`);if(t===L)return R;if(t===R)return e;let r=e%n;if(r<L&&(r+=n),t<$e){let e=R;for(;t>L;)t&R&&(e=e*r%n),r=r*r%n,t>>=R;return e}let i=[];for(;t>L;)i.push(Number(t&Ze)),t>>=Ke;let a=Array(16);a[0]=R,a[1]=r;for(let e=2;e<16;e++)a[e]=a[e-1]*r%n;let o=a[i[i.length-1]];for(let e=i.length-2;e>=0;e--){o=o*o%n,o=o*o%n,o=o*o%n,o=o*o%n;let t=i[e];t!==0&&(o=o*a[t]%n)}return o}function tt(e,t){if(e===L)throw Error(`invert: expected non-zero number`);if(t<=R)throw Error(`invert: expected modulus > 1, got `+t);let n=B(e,t),r=t,i=L,a=R;for(;n!==L;){let e=r/n,t=r-n*e,o=i-a*e;r=n,n=t,i=a,a=o}if(r!==R)throw Error(`invert: does not exist`);return B(i,t)}function nt(e,t){if(t<=R)throw Error(`invertCt: expected prime modulus > 1, got `+t);let n=B(e,t);if(n===L)throw Error(`invertCt: expected non-zero number`);let r=et(n,t-z,t);if(B(n*r,t)!==R)throw Error(`invertCt: does not exist`);return r}function rt(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function it(e,t){if((e&R)===L)throw Error(t+`: expected odd modulus, got `+e)}function at(e,t){let n=e,r=(n.ORDER+R)/Ke,i=n.pow(t,r);return rt(n,i,t),i}function ot(e,t){let n=e,r=(n.ORDER-qe)/Ye,i=n.mul(t,z),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,z),a),c=n.mul(o,n.sub(s,n.ONE));return rt(n,c,t),c}function st(e){let t=_t(e),n=ct(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+Je)/Qe;return((e,t)=>{let n=e,s=n.pow(t,o),c=n.mul(s,r),l=n.mul(s,i),u=n.mul(s,a),d=n.eql(n.sqr(c),t),f=n.eql(n.sqr(l),t);s=n.cmov(s,c,d),c=n.cmov(u,l,f);let p=n.eql(n.sqr(c),t),m=n.cmov(s,c,p);return rt(n,m,t),m})}function ct(e){if(e<Ge)throw Error(`sqrt is not defined for small field`);it(e,`tonelliShanks`);let t=e-R,n=0;for(;t%z===L;)t/=z,n++;let r=z,i=_t(e);for(;pt(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return at;let a=i.pow(r,t),o=(t+R)/z;return function(e,r){let i=e;if(i.is0(r))return r;if(pt(i,r)!==1)throw Error(`Cannot find square root`);let s=n,c=i.mul(i.ONE,a),l=i.pow(r,t),u=i.pow(r,o);for(;!i.eql(l,i.ONE);){if(i.is0(l))throw Error(`Cannot find square root: probably non-prime P`);let e=1,t=i.sqr(l);for(;!i.eql(t,i.ONE);)if(e++,t=i.sqr(t),e===s)throw Error(`Cannot find square root`);let n=R<<BigInt(s-e-1),r=i.pow(c,n);s=e,c=i.sqr(r),l=i.mul(l,c),u=i.mul(u,r)}return u}}function lt(e){return it(e,`Fp.sqrt`),e%Ke===Ge?at:e%Ye===qe?ot:e%Qe===Xe?st(e):ct(e)}const ut=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function dt(e){if(j(e,`field`),typeof e.ORDER!=`bigint`)throw TypeError(`param "ORDER" is invalid: expected bigint, got `+typeof e.ORDER);Ne(e.BYTES,`BYTES`),Ne(e.BITS,`BITS`);for(let t of ut)we(e[t],`field.`+t);if(e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=R)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function ft(e,t,n=!1){dt(e),xe(t,`nums`),N(n,`passZero`);let r=e,i=Array(t.length).fill(n?r.ZERO:void 0),a=t.reduce((e,t,n)=>r.is0(t)?e:(i[n]=e,r.mul(e,t)),r.ONE),o=r.inv(a);return t.reduceRight((e,t,n)=>r.is0(t)?e:(i[n]=r.mul(e,i[n]),r.mul(e,t)),o),i}function pt(e,t){dt(e);let n=e;it(n.ORDER,`FpLegendre`);let r=(n.ORDER-R)/z,i=n.pow(t,r),a=n.eql(i,n.ONE),o=n.eql(i,n.ZERO),s=n.eql(i,n.neg(n.ONE));if(!a&&!o&&!s)throw Error(`invalid Legendre symbol result`);return a?1:o?0:-1}function mt(e,t){if(t!==void 0&&Se(t),e<=L)throw Error(`invalid n length: expected positive n, got `+e);if(t!==void 0&&t<1)throw Error(`invalid n length: expected positive bit length, got `+t);let n=He(e);if(t!==void 0&&t<n)throw Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${n})`);let r=t===void 0?n:t;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}const ht=new WeakMap;var gt=class{ORDER;BITS;BYTES;isLE;ZERO=L;ONE=R;_lengths;_mod;constructor(e,t={}){if(e<=R)throw Error(`invalid field: expected ORDER > 1, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=mt(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return B(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return L<=e&&e<this.ORDER}is0(e){return e===L}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&R)===R}neg(e){return B(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return B(e*e,this.ORDER)}add(e,t){return B(e+t,this.ORDER)}sub(e,t){return B(e-t,this.ORDER)}mul(e,t){return B(e*t,this.ORDER)}pow(e,t){return et(e,t,this.ORDER)}div(e,t){return B(e*tt(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return tt(e,this.ORDER)}sqrt(e){let t=ht.get(this);return t||ht.set(this,t=lt(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?Re(e,this.BYTES):Le(e,this.BYTES)}fromBytes(e,t=!1){A(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:a,_mod:o}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let s=i?Ie(e):P(e);if(o&&(s=B(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return ft(this,e,!0)}cmov(e,t,n){return N(n,`condition`),n?t:e}};function _t(e,t={}){return Object.freeze(gt.prototype),new gt(e,t)}function vt(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);if(e<=R)throw Error(`field order must be greater than 1`);let t=He(e-R);return Math.ceil(t/8)}function yt(e){let t=vt(e);return t+Math.ceil(t/2)}function bt(e,t,n=!1){A(e);let r=e.length,i=vt(t),a=Math.max(yt(t),16);if(r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=B(n?Ie(e):P(e),t-R)+R;return n?Re(o,i):Le(o,i)}
159
159
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
160
- const I=BigInt(0),L=BigInt(1);function ft(e,t){let n=t.negate();return e?n:t}function pt(e,t){let n=rt(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function mt(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function ht(e,t){mt(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:Le(e),maxNumber:i,shiftBy:BigInt(e)}}function gt(e,t,n){let{windowSize:r,mask:i,maxNumber:a,shiftBy:o}=n,s=Number(e&i),c=e>>o;s>r&&(s-=a,c+=L);let l=t*r,u=l+Math.abs(s)-1,d=s===0,f=s<0,p=t%2!=0;return{nextN:c,offset:u,isZero:d,isNeg:f,isNegF:p,offsetF:l}}const _t=new WeakMap,vt=new WeakMap;function yt(e){return vt.get(e)||1}function bt(e){if(e!==I)throw Error(`invalid wNAF`)}var xt=class{BASE;ZERO;Fn;bits;constructor(e,t){this.BASE=e.BASE,this.ZERO=e.ZERO,this.Fn=e.Fn,this.bits=t}_unsafeLadder(e,t,n=this.ZERO){let r=e;for(;t>I;)t&L&&(n=n.add(r)),r=r.double(),t>>=L;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=ht(t,this.bits),i=[],a=e,o=a;for(let e=0;e<n;e++){o=a,i.push(o);for(let e=1;e<r;e++)o=o.add(a),i.push(o);a=o.double()}return i}wNAF(e,t,n){if(!this.Fn.isValid(n))throw Error(`invalid scalar`);let r=this.ZERO,i=this.BASE,a=ht(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=gt(n,e,a);n=o,c?i=i.add(ft(u,t[d])):r=r.add(ft(l,t[s]))}return bt(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=ht(e,this.bits);for(let e=0;e<i.windows&&n!==I;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=gt(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return bt(n),r}getPrecomputes(e,t,n){let r=_t.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),_t.set(t,r))),r}cached(e,t,n){let r=yt(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=yt(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){mt(t,this.bits),vt.set(e,t),_t.delete(e)}hasCache(e){return yt(e)!==1}};function St(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>I||r>I;)n&L&&(a=a.add(i)),r&L&&(o=o.add(i)),i=i.double(),n>>=L,r>>=L;return{p1:a,p2:o}}function Ct(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return tt(t),t}else return ct(e,{isLE:n})}function wt(e,t,n={},r){if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(typeof n==`bigint`&&n>I))throw Error(`CURVE.${e} must be positive bigint`)}let i=Ct(t.p,n.Fp,r),a=Ct(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function Tt(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}var Et=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(ee(e),b(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`Expected instance of class which extends utils.Hash`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),C(r)}update(e){return x(this),this.iHash.update(e),this}digestInto(e){x(this),S(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const Dt=(()=>{let e=((e,t,n)=>new Et(e,t).update(n).digest());return e.create=(e,t)=>new Et(e,t),e})(),Ot=(e,t)=>(e+(e>=0?t:-t)/Mt)/t
160
+ const xt=BigInt(0),St=BigInt(1),Ct=BigInt(4),wt=2**31;function Tt(e){let t=e;if(typeof t!=`function`)throw TypeError(`"Point" expected constructor, got type=`+typeof e);we(t.fromAffine,`Point.fromAffine`),we(t.fromBytes,`Point.fromBytes`),we(t.fromHex,`Point.fromHex`),j(t.BASE,`Point.BASE`),j(t.ZERO,`Point.ZERO`),dt(t.Fp),dt(t.Fn)}function Et(e,t){Tt(e),At(t,e);let n=ft(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Dt(e,t,n=1){if(!Number.isSafeInteger(e)||e<n||e>t)throw Error(`invalid window size, expected [`+n+`..`+t+`], got W=`+e)}function Ot(e,t){let n=e*(4*t+128);if(n>wt)throw Error(`invalid window size: table would need ~`+Math.ceil(n/2**20)+` MiB, max `+wt/2**20+` MiB`)}function kt(e,t){if(e!==void 0){we(e,`randomBytes`);try{let n=e(t);if(!De(n)||n.length!==t)return}catch{return}return e}}function At(e,t){xe(e,`points`),e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function jt(e,t,n){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,r)=>{if(!(n===void 0?t.isValid(e):F(e)&&e<n))throw Error(`invalid scalar at index `+r)})}const Mt=new WeakMap;function Nt(e){return Mt.get(e)||1}function Pt(e,t){let n=e.double(),r=[e];for(let e=1;e<t;e++)r.push(r[e-1].add(n));return r}function Ft(e,t){let n=2**t,r=n/2,i=BigInt(n-1),a=[];for(;e>xt;){let t=0;e&St&&(t=Number(e&i),t>=r&&(t-=n),e-=BigInt(t)),a.push(t),e>>=St}return a}function It(e,t,n){let r=2**t,i=r/2,a=BigInt(r-1),o=BigInt(t),s=[];for(let t=0;t<n;t++){let t=Number(e&a);e>>=o,t>i&&(t-=r,e+=St),s.push(t)}if(e!==xt)throw Error(`invalid wnaf`);return s}function Lt(e,t,n){let r=0;for(let e of n)r=Math.max(r,e.length);let i=e;for(let e=r-1;e>=0;e--){e!==r-1&&(i=i.double());for(let r=0;r<n.length;r++){let a=n[r][e];if(a){let e=t[r][Math.abs(a)-1>>1];i=i.add(a<0?e.negate():e)}}}return i}var Rt=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,t){Tt(e),this.randomBytes=kt(t,16),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,t,n){let r=Math.ceil(n/t)+1,i=2**(t-1),a=[],o=e;for(let e=0;e<r;e++){let e=o;for(let t=0;t<i;t++)a.push(e),e=e.add(o);o=a[a.length-1].double()}return{W:t,bits:n,windows:r,comp:a}}wnafCachedCT(e,t){let{W:n,windows:r,comp:i}=e,a=2**(n-1),o=It(t,n,r),s=this.ZERO,c=this.BASE;for(let e=0;e<r;e++){let t=o[e],n=e*a,r=Math.abs(t)-1,l=i[n];for(let e=1;e<a;e++)l=e===r?i[n+e]:l;let u=l.negate();t===0?c=c.add(i[n]):s=s.add(t<0?u:l)}return{p:s,f:c}}getWnafPrecomputes(e,t,n,r){let i=this.wnafPrecomputes.get(t),a=i?.find(t=>t.W===e&&t.bits===n);return a||(a=this.buildWnafTable(t,e,n),typeof r==`function`&&(a={...a,comp:r(a.comp)}),i||(i=[],this.wnafPrecomputes.set(t,i)),i.push(a)),a}assertPoint(e){if(!(e instanceof this.Point))throw TypeError(`"point" expected Point instance, got type=`+typeof e)}validateMulInput(e,t){if(this.assertPoint(e),!Be(t,St,this.Point.Fn.ORDER))throw Error(`invalid scalar`)}runCT(e,t,n,r){let i=Nt(e);return i===1?this.fixedWindowCT(e,t,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,r),t)}mulCT(e,t,n){return this.validateMulInput(e,t),this.runCT(e,t,this.bits,n)}mulCTBlinded(e,t,n){if(this.validateMulInput(e,t),this.randomBytes===void 0)throw Error(`randomBytes is required for scalar blinding`);let r=this.Point.Fn.BITS+128,i=this.randomBytes(16);if(!De(i)||i.length!==16)throw Error(`randomBytes returned invalid byte array`);i[0]=i[0]&63|128;let a=t+P(i)*this.Point.Fn.ORDER;return this.runCT(e,a,r,n)}fixedWindowCT(e,t,n){let r=Ue(5),i=Array(32);i[0]=this.ZERO;for(let t=1;t<32;t++)i[t]=i[t-1].add(e);let a=Math.ceil(n/5),o=this.ZERO;for(let e=a-1;e>=0;e--){if(e!==a-1)for(let e=0;e<5;e++)o=o.double();let n=Number(t>>BigInt(e*5)&r),s=i[0];for(let e=1;e<32;e++)s=e===n?i[e]:s;o=o.add(s)}return{p:o,f:o}}shouldBlind(e,t){return this.randomBytes===void 0?!1:t===St||e===this.BASE&&(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,t,n,r){return this.shouldBlind(e,n)?this.mulCTBlinded(e,t,r):this.mulCT(e,t,r)}mulUnsafe(e,t,n){if(this.assertPoint(e),!F(t))throw Error(`invalid scalar`);let r=Nt(e);if(r===1||t>=this.Point.Fn.ORDER)return zt(this.Point,[e],[t],!0);let i=this.getWnafPrecomputes(r,e,this.bits,n);return this.wnafCachedCT(i,t).p}setWindowSize(e,t){this.assertPoint(e),Dt(t,this.bits),Ot((Math.ceil((this.bits+128)/t)+1)*2**(t-1),this.Point.Fp.BYTES),Mt.set(e,t),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Nt(e)!==1}};function zt(e,t,n,r=!1){if(Tt(e),At(t,e),N(r,`allowOversized`),jt(n,e.Fn,r?e.Fn.ORDER**Ct:void 0),t.length!==n.length)throw Error(`arrays of points and scalars must have equal length`);let i=t.map(e=>Pt(e,4)),a=n.map(e=>Ft(e,4));return Lt(e.ZERO,i,a)}function Bt(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return dt(t),t}return _t(e,{isLE:n})}function Vt(e,t,n={},r){if(e!==`weierstrass`&&e!==`edwards`)throw Error(`expected curve type "weierstrass" or "edwards"`);if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);I(n);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(F(n)&&n!==xt))throw Error(`CURVE.${e} must be positive bigint`)}let i=Bt(t.p,n.Fp,r),a=Bt(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function Ht(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}var Ut=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(ne(e),S(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`expected Hash instance`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),E(r)}update(e){return w(this),this.iHash.update(e),this}digestInto(e){w(this),T(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o,canXOF:s}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.canXOF=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}};const Wt=(()=>{let e=((e,t,n)=>new Ut(e,t).update(n).digest());return e.create=(e,t)=>new Ut(e,t),e})(),Gt=BigInt(0),V={Err:class extends Error{constructor(e=``){
161
161
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
162
- ;function kt(e,t,n){Fe(`scalar`,e,z,n);let[[r,i],[a,o]]=t,s=Ot(o*e,n),c=Ot(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<z,f=u<z;d&&(l=-l),f&&(u=-u);let p=Le(Math.ceil(Ie(n)/2))+B;if(l<z||l>=p||u<z||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function At(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function jt(e,t){ze(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return j(n.lowS,`lowS`),j(n.prehash,`prehash`),n.format!==void 0&&At(n.format),n}const R={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=R;if(Te(e,`tag`),e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(typeof t!=`string`)throw TypeError(`"data" expected string, got type=`+typeof t);if(t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=Ee(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?Ee(i.length/2|128):``;return Ee(e)+a+i+t},decode(e,t){let{Err:n}=R;t=k(t,void 0,`DER data`);let r=0;if(e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=R;if(we(e),e<z)throw new t(`integer: negative integers are not allowed`);let n=Ee(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=R;if(e.length<1)throw new t(`invalid signature integer: empty`);if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return Oe(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=R,i=k(e,void 0,`signature`),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=R,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}};Object.freeze(R._tlv),Object.freeze(R._int),Object.freeze(R);const z=BigInt(0),B=BigInt(1),Mt=BigInt(2),Nt=BigInt(3),Pt=BigInt(4);function Ft(e,t={}){let n=wt(`weierstrass`,e,t),r=n.Fp,i=n.Fn,a=n.CURVE,{h:o,n:s}=a;ze(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`});let{endo:c,allowInfinityPoint:l}=t;if(c&&(!r.is0(a.a)||typeof c.beta!=`bigint`||!Array.isArray(c.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let u=Lt(r,i);function d(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function f(e,t,n){if(l&&t.is0())return Uint8Array.of(0);let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);return j(n,`isCompressed`),n?(d(),A(It(!r.isOdd(a)),o)):A(Uint8Array.of(4),o,r.toBytes(a))}function p(e){k(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=u,i=e.length,a=e[0],o=e.subarray(1);if(l&&i===1&&a===0)return{x:r.ZERO,y:r.ZERO};if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=g(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}d();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}else if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!_(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}else throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let m=t.toBytes===void 0?f:t.toBytes,h=t.fromBytes===void 0?p:t.fromBytes;function g(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,a.a)),a.b)}function _(e,t){let n=r.sqr(t),i=g(e);return r.eql(n,i)}if(!_(a.Gx,a.Gy))throw Error(`bad curve params: generator point`);let v=r.mul(r.pow(a.a,Nt),Pt),y=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(v,y)))throw Error(`bad curve params: a or b`);function b(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function ee(e){if(!(e instanceof C))throw Error(`Weierstrass Point expected`)}function x(e){if(!c||!c.basises)throw Error(`no endo`);return kt(e,c.basises,i.ORDER)}function S(e,t,n,i,a){return n=new C(r.mul(n.X,e),n.Y,n.Z),t=ft(i,t),n=ft(a,n),t.add(n)}class C{static BASE=new C(a.Gx,a.Gy,r.ONE);static ZERO=new C(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=b(`x`,e),this.Y=b(`y`,t,!0),this.Z=b(`z`,n),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof C)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?C.ZERO:new C(t,n,r.ONE)}static fromBytes(e){let t=C.fromAffine(h(k(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return C.fromBytes(ye(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return T.createCache(this,e),t||this.multiply(Nt),this}assertValidity(){let e=this;if(e.is0()){if(t.allowInfinityPoint&&r.is0(e.X)&&r.eql(e.Y,r.ONE)&&r.is0(e.Z))return;throw Error(`bad point: ZERO`)}let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!_(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){ee(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new C(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=a,n=r.mul(t,Nt),{X:i,Y:o,Z:s}=this,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(i,i),f=r.mul(o,o),p=r.mul(s,s),m=r.mul(i,o);return m=r.add(m,m),u=r.mul(i,s),u=r.add(u,u),c=r.mul(e,u),l=r.mul(n,p),l=r.add(c,l),c=r.sub(f,l),l=r.add(f,l),l=r.mul(c,l),c=r.mul(m,c),u=r.mul(n,u),p=r.mul(e,p),m=r.sub(d,p),m=r.mul(e,m),m=r.add(m,u),u=r.add(d,d),d=r.add(u,d),d=r.add(d,p),d=r.mul(d,m),l=r.add(l,d),p=r.mul(o,s),p=r.add(p,p),d=r.mul(p,m),c=r.sub(c,d),u=r.mul(p,f),u=r.add(u,u),u=r.add(u,u),new C(c,l,u)}add(e){ee(e);let{X:t,Y:n,Z:i}=this,{X:o,Y:s,Z:c}=e,l=r.ZERO,u=r.ZERO,d=r.ZERO,f=a.a,p=r.mul(a.b,Nt),m=r.mul(t,o),h=r.mul(n,s),g=r.mul(i,c),_=r.add(t,n),v=r.add(o,s);_=r.mul(_,v),v=r.add(m,h),_=r.sub(_,v),v=r.add(t,i);let y=r.add(o,c);return v=r.mul(v,y),y=r.add(m,g),v=r.sub(v,y),y=r.add(n,i),l=r.add(s,c),y=r.mul(y,l),l=r.add(h,g),y=r.sub(y,l),d=r.mul(f,v),l=r.mul(p,g),d=r.add(l,d),l=r.sub(h,d),d=r.add(h,d),u=r.mul(l,d),h=r.add(m,m),h=r.add(h,m),g=r.mul(f,g),v=r.mul(p,v),h=r.add(h,g),g=r.sub(m,g),g=r.mul(f,g),v=r.add(v,g),m=r.mul(h,v),u=r.add(u,m),m=r.mul(y,v),l=r.mul(_,l),l=r.sub(l,m),m=r.mul(_,h),d=r.mul(y,d),d=r.add(d,m),new C(l,u,d)}subtract(e){return ee(e),this.add(e.negate())}is0(){return this.equals(C.ZERO)}multiply(e){let{endo:n}=t;if(!i.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let r,a,o=e=>T.cached(this,e,e=>pt(C,e));if(n){let{k1neg:t,k1:i,k2neg:s,k2:c}=x(e),{p:l,f:u}=o(i),{p:d,f}=o(c);a=u.add(f),r=S(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,a=n}return pt(C,[r,a])[0]}multiplyUnsafe(e){let{endo:n}=t,r=this,a=e;if(!i.isValid(a))throw RangeError(`invalid scalar: out of range`);if(a===z||r.is0())return C.ZERO;if(a===B)return r;if(T.hasCache(this))return this.multiply(a);if(n){let{k1neg:e,k1:t,k2neg:i,k2:o}=x(a),{p1:s,p2:c}=St(C,r,t,o);return S(n.beta,s,c,e,i)}else return T.unsafe(r,a)}toAffine(e){let t=this,n=e,{X:i,Y:a,Z:o}=t;if(r.eql(o,r.ONE))return{x:i,y:a};let s=t.is0();n??=s?r.ONE:r.inv(o);let c=r.mul(i,n),l=r.mul(a,n),u=r.mul(o,n);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}isTorsionFree(){let{isTorsionFree:e}=t;return o===B?!0:e?e(C,this):T.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:e}=t;return o===B?this:e?e(C,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===B?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return j(e,`isCompressed`),this.assertValidity(),m(C,this,e)}toHex(e=!0){return ve(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let w=i.BITS,T=new xt(C,t.endo?Math.ceil(w/2):w);return w>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function It(e){return Uint8Array.of(e?2:3)}function Lt(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Rt(e,t={}){let{Fn:n}=e,r=t.randomBytes===void 0?xe:t.randomBytes,i=Object.assign(Lt(e.Fp,n),{seed:Math.max(ut(n.ORDER),16)});function a(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function s(e){return e=e===void 0?r(i.seed):e,dt(k(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function l(e){let{secretKey:t,publicKey:r,publicKeyUncompressed:a}=i,o=n._lengths;if(!be(e))return;let s=k(e,void 0,`key`).length,c=s===r||s===a,l=s===t||!!o?.includes(s);if(!(c&&l))return c}function u(t,r,i=!0){if(l(t)===!0)throw Error(`first arg must be private key`);if(l(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t);return e.fromBytes(r).multiply(a).toBytes(i)}let d={isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s},f=Tt(s,c);return Object.freeze(d),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:i})}function zt(e,t,n={}){let r=t;ee(r),ze(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`}),n=Object.assign({},n);let i=n.randomBytes===void 0?xe:n.randomBytes,a=n.hmac===void 0?(e,t)=>Dt(r,e,t):n.hmac,{Fp:o,Fn:s}=e,{ORDER:c,BITS:l}=s,{keygen:u,getPublicKey:d,getSharedSecret:f,utils:p,lengths:m}=Rt(e,n),h={prehash:!0,lowS:typeof n.lowS!=`boolean`||n.lowS,format:`compact`,extraEntropy:!1},g=c*Mt+B<o.ORDER;function _(e){return e>c>>B}function v(e,t){if(!s.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function y(){if(g)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function b(e,t){At(t);let n=m.signature;return k(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class x{r;s;recovery;constructor(e,t,n){if(this.r=v(`r`,e),this.s=v(`s`,t),n!=null){if(y(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=h.format){b(e,t);let n;if(t===`der`){let{r:t,s:n}=R.toSig(k(e));return new x(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=m.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new x(s.fromBytes(i),s.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(ye(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new x(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),a=i===2||i===3?n+c:n;if(!o.isValid(a))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let l=o.toBytes(a),u=e.fromBytes(A(It((i&1)==0),l)),d=s.inv(a),f=C(k(t,void 0,`msgHash`)),p=s.create(-f*d),m=s.create(r*d),h=e.BASE.multiplyUnsafe(p).add(u.multiplyUnsafe(m));if(h.is0())throw Error(`invalid recovery: point at infinify`);return h.assertValidity(),h}hasHighS(){return _(this.s)}toBytes(e=h.format){if(At(e),e===`der`)return ye(R.hexFromSig(this));let{r:t,s:n}=this,r=s.toBytes(t),i=s.toBytes(n);return e===`recovered`?(y(),A(Uint8Array.of(this.assertRecovery()),r,i)):A(r,i)}toHex(e){return ve(this.toBytes(e))}}Object.freeze(x.prototype),Object.freeze(x);let S=n.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=Oe(e),n=e.length*8-l;return n>0?t>>BigInt(n):t}:n.bits2int,C=n.bits2int_modN===void 0?function(e){return s.create(S(e))}:n.bits2int_modN,w=Le(l);function T(e){return Fe(`num < 2^`+l,e,z,w),s.toBytes(e)}function te(e,t){return k(e,void 0,`message`),t?k(r(e),void 0,`prehashed message`):e}function ne(t,n,r){let{lowS:a,prehash:o,extraEntropy:c}=jt(r,h);t=te(t,o);let l=C(t),u=s.fromBytes(n);if(!s.isValidNot0(u))throw Error(`invalid private key`);let d=[T(u),T(l)];if(c!=null&&c!==!1){let e=c===!0?i(m.secretKey):c;d.push(k(e,void 0,`extraEntropy`))}let f=A(...d),p=l;function v(t){let n=S(t);if(!s.isValidNot0(n))return;let r=s.inv(n),i=e.BASE.multiply(n).toAffine(),o=s.create(i.x);if(o===z)return;let c=s.create(r*s.create(p+o*u));if(c===z)return;let l=(i.x===o?0:2)|Number(i.y&B),d=c;return a&&_(c)&&(d=s.neg(c),l^=1),new x(o,d,g?void 0:l)}return{seed:f,k2sig:v}}function re(e,t,n={}){let{seed:i,k2sig:o}=ne(e,t,n);return Re(r.outputLen,s.BYTES,a)(i,o).toBytes(n.format)}function E(t,n,r,i={}){let{lowS:a,prehash:o,format:c}=jt(i,h);if(r=k(r,void 0,`publicKey`),n=te(n,o),!be(t)){let e=t instanceof x?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}b(t,c);try{let i=x.fromBytes(t,c),o=e.fromBytes(r);if(a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=C(n),f=s.inv(u),p=s.create(d*f),m=s.create(l*f),h=e.BASE.multiplyUnsafe(p).add(o.multiplyUnsafe(m));return!h.is0()&&s.create(h.x)===l}catch{return!1}}function ie(e,t,n={}){let{prehash:r}=jt(n,h);return t=te(t,r),x.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:f,utils:p,lengths:m,Point:e,sign:re,verify:E,recoverPublicKey:ie,Signature:x,hash:r})}
162
+ super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=V;if(Ne(e,`tag`),e<0||e>255)throw new n(`tlv.encode: wrong tag`);if(Ce(t,`data`),t.length&1)throw new n(`tlv.encode: unpadded data`);let r=t.length/2,i=Pe(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?Pe(i.length/2|128):``;return Pe(e)+a+i+t},decode(e,t){let{Err:n}=V;t=A(t,void 0,`DER data`);let r=0;if(e<0||e>255)throw new n(`tlv.decode: wrong tag`);if(t.length<2||t[r++]!==e)throw new n(`tlv.decode: wrong tlv`);let i=t[r++],a=!!(i&128),o=0;if(!a)o=i;else{let e=i&127;if(!e)throw new n(`tlv.decode(long): indefinite length not supported`);if(e>4)throw new n(`tlv.decode(long): byte length is too big`);let a=t.subarray(r,r+e);if(a.length!==e)throw new n(`tlv.decode: length bytes not complete`);if(a[0]===0)throw new n(`tlv.decode(long): zero leftmost byte`);for(let e of a)o=o<<8|e;if(r+=e,o<128)throw new n(`tlv.decode(long): not minimal encoding`)}let s=t.subarray(r,r+o);if(s.length!==o)throw new n(`tlv.decode: wrong value length`);return{v:s,l:t.subarray(r+o)}}},_int:{encode(e){let{Err:t}=V;if(Me(e),e<Gt)throw new t(`integer: negative integers are not allowed`);let n=Pe(e);if(Number.parseInt(n[0],16)&8&&(n=`00`+n),n.length&1)throw new t(`unexpected DER parsing assertion: unpadded hex`);return n},decode(e){let{Err:t}=V;if(e.length<1)throw new t(`invalid signature integer: empty`);if(e[0]&128)throw new t(`invalid signature integer: negative`);if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t(`invalid signature integer: unnecessary leading zero`);return P(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=V,i=A(e,void 0,`signature`),{v:a,l:o}=r.decode(48,i);if(o.length)throw new t(`invalid signature: left bytes after parsing`);let{v:s,l:c}=r.decode(2,a),{v:l,l:u}=r.decode(2,c);if(u.length)throw new t(`invalid signature: left bytes after parsing`);return{r:n.decode(s),s:n.decode(l)}},hexFromSig(e){let{_tlv:t,_int:n}=V;I(e,{r:`bigint`,s:`bigint`},{},`sig`);let r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}},Kt=(Object.freeze(V._tlv),Object.freeze(V._int),Object.freeze(V)),qt=(e,t)=>(e+(e>=0?t:-t)/Zt)/t
163
163
  /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
164
- const V=zt(Ft({p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)}),ge),Bt=`pkcs8`,Vt=Bt,Ht=`spki`;function H(){let e=globalThis?.crypto?.subtle;if(typeof e==`object`&&e)return e;throw Error(`crypto.subtle must be defined`)}function Ut(e,t){return async function(n){let r=await e();return{secretKey:r,publicKey:await t(r)}}}function Wt(e){let t=e.match(/[0-9a-f]{2}/gi);if(!t||t.length*2!==e.length)throw Error(`invalid hex`);return Uint8Array.from(t,e=>Number.parseInt(e,16))}function Gt(e,t){if(t.type!==e)throw Error(`invalid key type, expected ${e}`)}function Kt(e,t,n,r){let i=t?[`deriveBits`]:[`sign`],a=t?[]:[`verify`],o=(e,t)=>t===`jwk`?e:new Uint8Array(e),s={async import(t,n){let r=await H().importKey(n,t,e,!0,a);return Gt(`public`,r),r},async export(e,t){Gt(`public`,e);let n=await H().exportKey(t,e);return o(n,t)},async convert(e,t,n){return s.export(await s.import(e,t),n)}},c={async import(n,a){let o=H(),s;if(a===`raw`){let t=n,a=Wt(r),c=new Uint8Array(a.length+t.length);c.set(a,0),c.set(t,a.length),s=await o.importKey(Bt,c,e,!0,i)}else t&&a===`jwk`&&(n={...n,key_ops:i}),s=await o.importKey(a,n,e,!0,i);return Gt(`private`,s),s},async export(e,t){let r=H();if(Gt(`private`,e),t===`raw`){let t=(await r.exportKey(`jwk`,e)).d.replace(/-/g,`+`).replace(/_/g,`/`),i=t.length%4?`=`.repeat(4-t.length%4):``,a=atob(t+i),o=Uint8Array.from(a,e=>e.charCodeAt(0)),s=new Uint8Array(n);return s.set(o,n-o.length),s}let i=await r.exportKey(t,e);return o(i,t)},async convert(e,t,n){return c.export(await c.import(e,t),n)}};async function l(e,t={}){let n=t.formatSec??Vt,r=t.formatPub??Ht,i=n===`jwk`?{...e}:await c.convert(e,n,`jwk`);return delete i.d,i.key_ops=a,r===`jwk`?i:s.convert(i,`jwk`,r)}async function u(t=Vt){let n=await H().generateKey(e,!0,i);return c.export(n.privateKey,t)}let d;return{pub:s,priv:c,async isSupported(){if(d!==void 0)return d;try{let n=H(),r=await n.generateKey(e,!0,i);return await c.export(r.privateKey,`jwk`),t&&await n.deriveBits({name:typeof e==`string`?e:e.name,public:r.publicKey},r.privateKey,8),d=!0}catch{return d=!1}},getPublicKey:l,keygen:Ut(u,l),utils:Object.freeze({randomSecretKey:u,convertPublicKey:s.convert,convertSecretKey:c.convert})}}function qt(e,t){return{async sign(n,r,i={}){let a=await e.priv.import(r,i.formatSec??Vt),o=await H().sign(t,a,n);return new Uint8Array(o)},async verify(n,r,i,a={}){let o=await e.pub.import(i,a.formatPub??Ht);return await H().verify(t,o,n,r)}}}function Jt(e,t,n){return{async getSharedSecret(r,i,a={}){let o=await e.priv.import(r,a.formatSec===void 0?Vt:a.formatSec),s=await e.pub.import(i,a.formatPub===void 0?Ht:a.formatPub),c=await H().deriveBits({name:typeof t==`string`?t:t.name,public:s},o,8*n);return new Uint8Array(c)}}}function Yt(e,t,n,r){let i={name:`ECDH`,namedCurve:e},a=Kt({name:`ECDSA`,namedCurve:e},!1,n,r),o=Kt(i,!0,n,r);return Object.freeze({name:e,isSupported:a.isSupported,getPublicKey:a.getPublicKey,keygen:Ut(a.utils.randomSecretKey,a.getPublicKey),...qt(a,{name:`ECDSA`,hash:{name:t}}),...Jt(o,i,n),utils:Object.freeze({...a.utils,async convertSecretKey(e,t,n){let r=t===`jwk`?e:void 0;return Array.isArray(r?.key_ops)&&r.key_ops.length===1&&r.key_ops[0]===`deriveBits`?o.utils.convertSecretKey(e,t,n):a.utils.convertSecretKey(e,t,n)}})})}const Xt=Yt(`P-256`,`SHA-256`,32,`3041020100301306072a8648ce3d020106082a8648ce3d030107042730250201010420`),Zt={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 Qt=class extends Error{code;data;constructor(e,t,n){super(t),this.code=e,this.data=n}toJSON(){return{code:this.code,message:this.message,data:this.data}}},$t=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 en(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 $t;return o.set(t,e=>{e.error?n.reject(new Qt(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 tn(e){return new TextEncoder().encode(JSON.stringify(e))}function nn(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}const rn=`__frakEnv`,an={prod:{wallet:`https://wallet.frak.id`,backend:`https://backend.frak.id`},dev:{wallet:`https://wallet-dev.frak.id`,backend:`https://backend.gcp-dev.frak.id`}};function on(){return typeof window<`u`}let sn=an.prod;function cn(e){return e.endsWith(`/`)?e.slice(0,-1):e}function ln(e){return typeof e==`string`?an[e]||(console.error(`[Frak SDK] Unknown env "${e}", falling back to production. Expected "prod", "dev", or { wallet, backend }.`),an.prod):!e?.wallet||!e?.backend?(console.error("[Frak SDK] env must state both `wallet` and `backend` origins, falling back to production. Received:",e),an.prod):{wallet:cn(e.wallet),backend:cn(e.backend)}}function un(e){if(!e)return dn();let t=ln(e),n=on()?window[rn]:void 0;return n&&(n.wallet!==t.wallet||n.backend!==t.backend)&&console.warn(`[Frak SDK] env changed after being published; the last value wins for every SDK call on this page.`,{previous:n,next:t}),sn=t,on()&&(window[rn]=t),t}function dn(){return on()?window[rn]??sn:sn}function fn(){return dn().wallet}function U(){return dn().backend}var pn=class extends Map{maxSize;constructor(e){super(),this.maxSize=e}get(e){let t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){let e=super.keys().next().value;e!==void 0&&super.delete(e)}return this}};let W;function mn(){return W||={promiseCache:new pn(1024),responseCache:new pn(1024),failureCache:new pn(1024)},W}async function G(e,{cacheKey:t,cacheTime:n=3e4}){let{promiseCache:r,responseCache:i,failureCache:a}=mn();if(n>0){let e=i.get(t);if(e&&Date.now()-e.created<n)return e.data}let o=a.get(t);if(o&&Date.now()-o<1e3)throw Error(`Cache: ${t} recently failed, backing off`);let s=r.get(t);s||(s=e(),r.set(t,s));try{let e=await s;return i.set(t,{data:e,created:Date.now()}),a.delete(t),e}catch(e){throw a.set(t,Date.now()),e}finally{r.delete(t)}}function hn(){W&&(W.promiseCache.clear(),W.responseCache.clear(),W.failureCache.clear())}const gn=`__frakSdkConfig`,_n=`frak-config-cache`,vn=`frak-merchant-id`,yn={key:_n},K=typeof window<`u`;function bn(){return{isResolved:!1,merchantId:``}}let q=null;function xn(){if(!K)return null;try{let e=localStorage.getItem(yn.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(q=t,t):null}catch{return null}}function Sn(){return(q??xn())?.config}function Cn(){let e=q??xn();return e?Date.now()-e.timestamp<3e4:!1}function wn(e){if(!(!K||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(yn.key,JSON.stringify(t)),q=t}catch{}}function Tn(){if(K){q=null;try{localStorage.removeItem(yn.key)}catch{}}}function En(){K&&(window[gn]||(window[gn]=Sn()??bn()))}function Dn(){return K?(En(),window[gn]??bn()):bn()}function On(e){K&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function kn(e){return e??(K?window.location.hostname:``)}async function An(e,t){try{let n=U(),r=t?`&lang=${encodeURIComponent(t)}`:``,i=await fetch(`${n}/user/merchant/resolve?domain=${encodeURIComponent(e)}${r}`);if(!i.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${e}: ${i.status}`);return}let a=await i.json();if(K)try{sessionStorage.setItem(vn,a.merchantId)}catch{}return a}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}const J={getConfig:Dn,get isResolved(){return Dn().isResolved},get isCacheFresh(){return Cn()},setCacheScope(e,t){let n=`${e}:${t??``}`;yn.key=`${_n}:${n}`,q=null},setConfig(e){if(K&&(window[gn]=e),wn(e),On(e),K&&e.merchantId)try{sessionStorage.setItem(vn,e.merchantId)}catch{}},reset(){let e=Sn()??bn();K&&(window[gn]=e),On(e)},clearCache(){if(Tn(),hn(),K)try{sessionStorage.removeItem(vn)}catch{}},resolve(e,t){let n=kn(e);return n?G(async()=>{let e=await An(n,t);if(!e)throw Error(`Config resolution returned empty`);return e},{cacheKey:`sdkConfig:${n}:${t??``}`,cacheTime:1/0}).catch(()=>void 0):Promise.resolve(void 0)},getMerchantId(){let e=Dn();if(e.isResolved&&e.merchantId)return e.merchantId;if(K)try{return sessionStorage.getItem(vn)??void 0}catch{}},async resolveMerchantId(e){return J.getMerchantId()||(await J.resolve(e))?.merchantId}};async function jn(e){return p(ge(e))}const Mn=`frak-client-id`,Nn=`frak-client-key`,Pn=`frak-client-id-legacy`,Fn={formatSec:`raw`,formatPub:`raw`};let In=null;function Ln(){return In??=Xt.isSupported().then(e=>e?Xt:V).catch(()=>V),In}const Rn=()=>typeof window<`u`&&!!window.localStorage;let zn=null;function Bn(e){let t=m(e);if(zn?.keyHex===t)return zn.publicKey;let n=V.getPublicKey(e,!1);return zn={keyHex:t,publicKey:n},n}function Vn(){if(Rn())return localStorage.getItem(Pn)??void 0}function Hn(){Rn()&&localStorage.removeItem(Pn)}function Un(){let e=localStorage.getItem(Nn);if(!e)return null;if(!/^[0-9a-f]{64}$/i.test(e))throw Error(`[Frak SDK] Corrupt client key`);return h(e)}async function Wn(){if(!Rn())throw Error(`[Frak SDK] No window/localStorage available to derive a client id`);if(typeof crypto>`u`||!crypto.getRandomValues)throw Error(`[Frak SDK] crypto.getRandomValues unavailable, cannot derive a client id`);let e=localStorage.getItem(Mn);try{let t=Un(),n=t??V.utils.randomSecretKey(),r=await jn(Bn(n));if(t){e!==r&&localStorage.setItem(Mn,r);let t=Vn();return{clientId:r,...t&&{pendingLegacyId:t}}}return e&&localStorage.setItem(Pn,e),localStorage.setItem(Nn,m(n)),localStorage.setItem(Mn,r),{clientId:r,...e&&{pendingLegacyId:e}}}catch(e){throw localStorage.removeItem(Nn),zn=null,e}}async function Y(e){if(!Rn())return null;try{let t=Un();if(!t)return null;let n=e.ts??Math.floor(Date.now()/1e3),r=f({op:e.op,merchantId:e.merchantId,anonymousId:e.anonymousId,binding:e.binding??new Uint8Array,ts:n}),i=await Ln()===Xt?await Xt.sign(r,t,Fn):V.sign(r,t,{prehash:!0});return _({v:1,pk:Bn(t),ts:n,sig:i})}catch{return null}}async function Gn({legacyId:e,derivedId:t}){if(!(typeof window>`u`)){if(!e||e===t){Hn();return}try{let n=await J.resolveMerchantId();if(!n)return;let r=await Y({op:`frak-merge-v1`,merchantId:n,anonymousId:t});if(!r)return;let i=U(),a=await fetch(`${i}/user/identity/merge/initiate`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({sourceAnonymousId:t,merchantId:n,proof:r})});if(!a.ok){a.status<500&&Hn();return}let{mergeToken:o}=await a.json();if(!o)return;let s=await fetch(`${i}/user/identity/merge/execute`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({mergeToken:o,targetAnonymousId:e,merchantId:n})});if(s.ok){Hn();return}s.status<500&&Hn()}catch{}}}let Kn=null,qn=null;async function Jn(){return Kn||qn||(qn=Wn().then(({clientId:e,pendingLegacyId:t})=>(Kn=e,t&&Gn({legacyId:t,derivedId:e}),e)),qn)}function Yn(){if(Kn)return Kn;Jn().catch(()=>{})}async function X(){return Kn||Jn()}function Xn(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Zn(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 Qn(e){return Xn(tn(e))}function $n(e,t,n,r,i,a,o){let s=Qn(er({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,proof:o})),c=new URL(e);return c.pathname=`/sso`,c.searchParams.set(`p`,s),c.toString()}function er(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},pf:e.proof}}function tr(e){return{...e,directExit:e.directExit??!e.redirectUrl}}async function nr(e,t){let{metadata:n,customizations:r}=e.config,i=Yn()??await X().catch(()=>void 0),a=await J.resolveMerchantId()??``,o=i&&a?await Y({op:`frak-sso-v1`,merchantId:a,anonymousId:i}):null;return{ssoUrl:$n(fn(),tr(t),a,n.name,i,r?.css,o??void 0)}}const rr=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,ir=`frak-sso`;async function ar(e,t){let{metadata:n,customizations:r}=e.config;if(`ssoUrl`in t)return or(t.ssoUrl),await e.request({method:`frak_openSso`,params:[{},n.name,r?.css]})??{};let i=tr(t);return i.openInSameWindow??!!i.redirectUrl?await e.request({method:`frak_openSso`,params:[i,n.name,r?.css]}):(or(i.ssoPopupUrl??(await nr(e,i)).ssoUrl),await e.request({method:`frak_openSso`,params:[i,n.name,r?.css]})??{})}function or(e){let t=window.open(e,ir,rr);if(!t)throw Error(`Popup was blocked. Please allow popups for this site.`);t.focus()}function Z(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)}}function Q(e,t){let n=e.get(t);if(n!==null)return n;let r=t.toLowerCase();for(let[t,n]of e)if(t.toLowerCase()===r)return n;return null}function $(e,t){let n=t.toLowerCase(),r=[...e.keys()].filter(e=>e.toLowerCase()===n);for(let t of r)e.delete(t)}const sr=/^0x[a-fA-F0-9]{40}$/;function cr(e){return typeof e==`string`&&sr.test(e)}function lr(e,t){return e.toLowerCase()===t.toLowerCase()}function ur(e){let t=new Uint8Array(20);for(let n=0;n<20;n++){let r=Number.parseInt(e.substring(2+n*2,4+n*2),16);if(Number.isNaN(r))throw Error(`Invalid address: ${e}`);t[n]=r}return t}const dr=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function fr(e){let t=`0x`;for(let n=0;n<20;n++)t+=dr[e[n]];return t}function pr(e){return`r`in e&&!(`v`in e)}function mr(e){return`v`in e&&e.v===2}const hr=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function gr(e){return typeof e==`string`&&hr.test(e)}function _r(e){let t=e.replace(/-/g,``),n=new Uint8Array(16);for(let e=0;e<16;e++)n[e]=Number.parseInt(t.substring(e*2,e*2+2),16);return n}function vr(e){let t=``;for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,`0`);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20,32)}`}function yr(e){if(!gr(e.m)||!Number.isInteger(e.t)||e.t<0||e.t>4294967295)return null;let t=typeof e.c==`string`&&e.c.length>0,n=typeof e.w==`string`&&cr(e.w);if(!t&&!n||t&&!gr(e.c))return null;let r=new Uint8Array(21+(t?16:0)+(n?20:0)),i=new DataView(r.buffer,r.byteOffset,r.byteLength),a=0;return r[a++]=2|(t?16:0)|(n?32:0),r.set(_r(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set(_r(e.c),a),a+=16),n&&(r.set(ur(e.w),a),a+=20),r}function br(e){if(e.length<21)return null;let t=e[0];if((t&15)!=2||t&192)return null;let n=(t&16)!=0,r=(t&32)!=0;if(!n&&!r)return null;let i=21+(n?16:0)+(r?20:0);if(e.length!==i)return null;let a=1,o=vr(e.subarray(a,a+16));a+=16;let s=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(a,!1);a+=4;let c={v:2,m:o,t:s};if(n&&(c.c=vr(e.subarray(a,a+16)),a+=16),r){let t=fr(e.subarray(a,a+20));if(!cr(t))return null;c.w=t,a+=20}return c}const xr=`fCtx`;function Sr(e){if(e)try{if(mr(e)){let t=yr(e);return t?Xn(t):void 0}return Xn(ur(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function Cr(e){if(!(!e||e.length===0))try{let t=Zn(e);if(t.length!==20)return br(t)||void 0;let n=fr(t);if(cr(n))return{r:n}}catch(t){console.error(`Error decompressing Frak context`,{e:t,context:e})}}function wr({url:e}){if(!e)return null;let t=Q(new URL(e).searchParams,xr);return t?Cr(t):null}function Tr(e){return{utm_source:e.utmSource??`frak`,utm_medium:e.utmMedium??void 0,utm_campaign:e.utmCampaign??void 0,utm_content:e.utmContent,utm_term:e.utmTerm,via:e.via??void 0,ref:e.ref??void 0}}function Er(e,t){let n=Tr(t??{});for(let[t,r]of Object.entries(n))r!==void 0&&r!==``&&(e.searchParams.has(t)||e.searchParams.set(t,r))}function Dr({url:e,context:t,attribution:n}){if(!e)return null;let r=Sr(t);if(!r)return null;let i=new URL(e);return $(i.searchParams,xr),i.searchParams.set(xr,r),Er(i,n),i.toString()}function Or(e){let t=new URL(e);return $(t.searchParams,xr),t.toString()}function kr({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?Or(n):Dr({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const Ar={compress:Sr,decompress:Cr,parse:wr,update:Dr,remove:Or,replaceUrl:kr},jr={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function Mr(e){return e&&e in jr?e:`eur`}function Nr(e){return e?jr[e]??jr.eur:jr.eur}function Pr(e,t){let n=Nr(t),r=Mr(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function Fr(e){return e.formatToParts(1.1).find(e=>e.type===`decimal`)?.value??`.`}function Ir(e,t){let n=Nr(t),r=Mr(t),i=new Intl.NumberFormat(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2}),a=i.formatToParts(e),o=``,s=``,c=``,l=`suffix`,u=!1;for(let e of a)switch(e.type){case`integer`:case`group`:o+=e.value,u=!0;break;case`decimal`:case`fraction`:s+=e.value;break;case`currency`:c=e.value,l=u?`suffix`:`prefix`;break;default:break}return{integer:o,decimals:s||`${Fr(i)}00`,unit:c,unitPosition:l}}function Lr(e){return{integer:String(e),unit:`%`,unitPosition:`suffix`}}function Rr(e){return e?`${e}Amount`:`eurAmount`}var zr=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)}},Br=class{constructor(e){this.groups=[],this.queue=[],this.options=e;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.3.1`,this.api=new zr({baseUrl:e.apiUrl||`https://api.openpanel.dev`,defaultHeaders:t})}init(){}ready(){this.options.disabled=!1,this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(this.options.disabled||this.options.waitForProfile&&!this.profileId||e.type===`replay`&&!this.sessionId)}addQueue(e){e.type===`track`&&(e.payload.properties={...e.payload.properties??{},__timestamp:new Date().toISOString()}),this.queue.push(e)}async send(e){if(this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.addQueue(e),Promise.resolve();let t=await this.api.fetch(`/track`,e,{keepalive:e.type!==`replay`});this.deviceId=t?.deviceId;let n=!!this.sessionId;return this.sessionId=t?.sessionId,!n&&this.sessionId&&this.flush(),t}setGlobalProperties(e){this.global={...this.global,...e}}track(e,t){this.log(`track event`,e,t);let{groups:n,profileId:r,...i}=t??{},a=[...new Set([...this.groups,...n??[]])];return this.send({type:`track`,payload:{name:e,profileId:r??this.profileId,groups:a.length>0?a:void 0,properties:{...this.global??{},...i}}})}identify(e){if(this.log(`identify user`,e),e.profileId&&(this.profileId=e.profileId,this.flush()),e.profileId&&Object.keys(e).length>1)return this.send({type:`identify`,payload:{...e,properties:{...this.global,...e.properties}}})}upsertGroup(e){return this.log(`upsert group`,e),this.send({type:`group`,payload:e})}setGroup(e){return this.log(`set group`,e),this.groups.includes(e)||(this.groups=[...this.groups,e]),this.send({type:`assign_group`,payload:{groupIds:[e],profileId:this.profileId}})}setGroups(e){return this.log(`set groups`,e),this.groups=[...new Set([...this.groups,...e])],this.send({type:`assign_group`,payload:{groupIds:e,profileId:this.profileId}})}alias(e){}increment(e){return this.send({type:`increment`,payload:e})}decrement(e){return this.send({type:`decrement`,payload:e})}revenue(e,t){let n=t?.deviceId;return delete t?.deviceId,this.track(`revenue`,{...t??{},...n?{__deviceId:n}:{},__revenue:e})}getDeviceId(){return this.deviceId??``}getSessionId(){return this.sessionId??``}fetchDeviceId(){return Promise.resolve(this.deviceId??``)}clear(){this.profileId=void 0,this.groups=[],this.deviceId=void 0,this.sessionId=void 0}buildFlushPayload(e){if(e.type===`replay`)return e.payload;if(e.type===`track`){let t=`groups`in e.payload?e.payload.groups??[]:[],n=[...new Set([...this.groups,...t])];return{...e.payload,profileId:e.payload.profileId??this.profileId,groups:n.length>0?n:void 0}}return e.type===`identify`||e.type===`increment`||e.type===`decrement`||e.type===`assign_group`?{...e.payload,profileId:e.payload.profileId??this.profileId}:e.payload}flush(){let e=[];for(let t of this.queue){if(this.shouldQueue(t)){e.push(t);continue}let n=this.buildFlushPayload(t);this.send({...t,payload:n})}this.queue=e}log(...e){this.options.debug&&console.log(`[OpenPanel.dev]`,...e)}},Vr=typeof document<`u`?document.currentScript:null;function Hr(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var Ur=class extends Br{constructor(e){if(super({sdk:`web`,sdkVersion:`1.4.1`,...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=[]}if(this.setGlobalProperties({__referrer:document.referrer}),this.options.trackScreenViews&&(this.trackScreenViews(),setTimeout(()=>this.screenView(),0)),this.options.trackOutgoingLinks&&this.trackOutgoingLinks(),this.options.trackAttributes&&this.trackAttributes(),this.options.sessionReplay?.enabled){let e=this.options.sessionReplay.sampleRate??1;Math.random()<e&&this.loadReplayModule().then(e=>{e&&e.startReplayRecorder(this.options.sessionReplay,e=>{this.send({type:`replay`,payload:{...e}})})})}}}async loadReplayModule(){try{if(typeof __OPENPANEL_REPLAY_URL__<`u`){let e=Vr,t=this.options.sessionReplay?.scriptUrl||e?.src?.replace(`.js`,`-replay.js`)||`https://openpanel.dev/op1-replay.js`;return window.__openpanel_replay?window.__openpanel_replay:new Promise(e=>{let n=document.createElement(`script`);n.src=t,n.onload=()=>{e(window.__openpanel_replay??null)},n.onerror=()=>{console.warn(`[OpenPanel] Failed to load replay script from`,t),e(null)},document.head.appendChild(n)})}return await import(`./replay-V6FXES7X.CgBxdfNp.js`)}catch(e){return console.warn(`[OpenPanel] Failed to load replay module`,e),null}}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[Hr(t.name.replace(/^data-/,``))]=t.value);let t=i.getAttribute(`data-track`);t&&super.track(t,e)}})}track(e,t){return super.track(e,{...t,__path:this.lastPath})}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{}}};const Wr=`nexus-wallet-backup`,Gr=`frakwallet://`;function Kr(e){let t=e?.split(`-`)[0]?.toLowerCase();return t===`en`||t===`fr`?t:void 0}function qr(){return(typeof document<`u`?Kr(document.documentElement.lang):void 0)||(typeof navigator<`u`?Kr(navigator.language):void 0)}function Jr(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`))}function Yr(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const Xr=Gr.replace(`://`,``);function Zr(e){return`intent://${e.slice(13)}#Intent;scheme=${Xr};end`}function Qr(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=Yr()&&$r(e)?Zr(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function $r(e){return e.startsWith(Gr)}function ei(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}const ti=ei();function ni(){return typeof navigator>`u`?!1:ti?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function ri(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}const ii=ri();function ai(e){ti&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:ti&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`${U()}/common/social?u=${encodeURIComponent(e)}`}const oi={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`}};async function si({config:e}){let t=document.querySelector(`#frak-wallet`);t&&t.remove();let n=document.createElement(`iframe`);n.id=oi.id,n.name=oi.name,n.allow=oi.allow,n.style.zIndex=oi.style.zIndex.toString(),li({iframe:n,isVisible:!1});let r=un(e?.env).wallet,i=await Jn().catch(e=>{console.warn(`[Frak SDK] Unable to derive a client id`,e)});return di(r),di(U()),n.src=ci({walletUrl:r,clientId:i,preload:e?.preload}),new Promise(e=>{n.addEventListener(`load`,()=>e(n)),document.body.appendChild(n)})}function ci({walletUrl:e=fn(),clientId:t,preload:n}){let r=t?`${e}/listener?clientId=${encodeURIComponent(t)}`:`${e}/listener`;return!n||n.length===0?r:`${r}#preload=${n.join(`,`)}`}function li({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 ui(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 di(e){if(!(typeof document>`u`))try{let t=new URL(e).origin,n=`link[rel="preconnect"][data-frak-preconnect="${t}"]`;if(document.head.querySelector(n))return;let r=document.createElement(`link`);r.rel=`preconnect`,r.href=t,r.crossOrigin=``,r.dataset.frakPreconnect=t,document.head.appendChild(r)}catch{}}const fi=ti&&ii;function pi(e){e?localStorage.setItem(Wr,e):localStorage.removeItem(Wr)}function mi(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=_i(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function hi(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 gi(e){return e.includes(`/common/social`)}function _i(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function vi(e,t,n,r,i){if(i){let e=mi(t,r);window.open(e,`_blank`);return}if($r(t)){let i=mi(t,r);Qr(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(fi&&gi(t))hi(r);else{let e=mi(t,r);window.location.href=e}}function yi({iframe:e,targetOrigin:t}){let n=new $t;return{handleEvent:r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:pi(a.backup);break;case`remove-backup`:localStorage.removeItem(Wr);break;case`show`:case`hide`:li({iframe:e,isVisible:i===`show`});break;case`redirect`:vi(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}async function bi({config:e,iframe:t}){let n=un(e?.env).wallet,r=e.metadata.lang??qr(),i=e.domain??(typeof window<`u`?window.location.hostname:``);J.setCacheScope(i,r),J.reset();let a=J.isCacheFresh?void 0:J.resolve(e.domain,r),o=await X().catch(()=>void 0),s=yi({iframe:t,targetOrigin:n}),c=new $t,l=Date.now();if(!t.contentWindow)throw new Qt(Zt.configError,`The iframe does not have a content window`);let u=en({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await s.isConnected)throw new Qt(Zt.clientNotConnected,`The iframe provider isn't connected yet`);return await c.promise,t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{s.handleEvent(e)}}}),d=xi(u,s),f=async()=>{d(),u.cleanup(),t.remove(),hn(),J.clearCache(),J.reset()},p;{console.log(`[Frak SDK] Initializing OpenPanel`),p=new Ur({apiUrl:`https://op-api.gcp.frak.id`,clientId:`6eacc8d7-49ac-4936-95e9-81ef29449570`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:e,payload:t})=>(e!==`track`||!t?.properties||`sdk_version`in t.properties||(t.properties={...t.properties,sdk_version:`1.3.0`,...o&&{user_anonymous_client_id:o}}),!0)}),p.setGlobalProperties({sdk_version:`1.3.0`,...o&&{user_anonymous_client_id:o}}),p.init(),p.track(`sdk_initialized`,{sdk_version:`1.3.0`});let e=!1,t=setTimeout(()=>{e||(e=!0,p?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);s.isConnected.then(()=>{e||(e=!0,clearTimeout(t),p?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-l}))}).catch(()=>{e||(e=!0,clearTimeout(t),p?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let m=Ei({config:e,rpcClient:u,lifecycleManager:s,configPromise:a,contextSent:c,openPanel:p,clientId:o}).then(()=>{}).catch(e=>{throw c.reject(e),e});return{config:e,waitForConnection:s.isConnected,waitForSetup:m,request:u.request,listenerRequest:u.listen,destroy:f,openPanel:p}}function xi(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,250),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}function Si(e){return e.hasRawSdkConfig?{name:e.name,logoUrl:e.logoUrl,homepageLink:e.homepageLink,lang:e.lang,currency:e.currency,hidden:e.hidden,css:e.css,translations:e.translations,placements:e.placements,attribution:e.attribution}:e.attribution?{attribution:e.attribution}:void 0}function Ci(e,t){if(!e)return;let n=e.global??{};e.setGlobalProperties({...n,merchant_id:t.merchantId,domain:t.domain??``})}async function wi(e){if(!(typeof crypto>`u`||!crypto.subtle))try{let t=await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(e));return new Uint8Array(t)}catch{return}}async function Ti({merchantId:e,anonymousId:t,pendingMergeToken:n}){let r=n?await wi(n):void 0;if(n&&!r){let n=await Y({op:`frak-install-v1`,merchantId:e,anonymousId:t});return n?{anonymousId:t,proofs:{install:n}}:void 0}let[i,a]=await Promise.all([r?Y({op:`frak-merge-v1`,merchantId:e,anonymousId:t,binding:r}):Promise.resolve(null),Y({op:`frak-install-v1`,merchantId:e,anonymousId:t})]);if(!(!i&&!a))return{anonymousId:t,proofs:{...i&&{merge:i},...a&&{install:a}}}}async function Ei({config:e,rpcClient:t,lifecycleManager:n,configPromise:r,contextSent:i,openPanel:a,clientId:o}){await n.isConnected,Jr(t,n.isConnected);let s=new URL(window.location.href),c=s.searchParams.get(`fmt`)??void 0;c&&(s.searchParams.delete(`fmt`),window.history.replaceState({},``,s.toString()));let l=t=>{let n=t?.merchantId??e.metadata.merchantId??``,r=t?.domain??``,i=t?.allowedDomains??[],a=t?.sdkConfig,o=a?.attribution||e.attribution?{...e.attribution,...a?.attribution}:void 0;J.setConfig(a?{isResolved:!0,merchantId:n,domain:r,allowedDomains:i,hasRawSdkConfig:!0,name:a.name??e.metadata.name,logoUrl:a.logoUrl??e.metadata.logoUrl,homepageLink:a.homepageLink??e.metadata.homepageLink,lang:a.lang??e.metadata.lang,currency:a.currency??e.metadata.currency,hidden:a.hidden,css:a.css,translations:a.translations,placements:a.placements,components:a.components,attribution:o}:{isResolved:!0,merchantId:n,domain:r,allowedDomains:i,name:e.metadata.name,logoUrl:e.metadata.logoUrl,homepageLink:e.metadata.homepageLink,lang:e.metadata.lang,currency:e.metadata.currency,attribution:o})},u=!1,d=Promise.resolve(),f=e=>{let n=u?void 0:c;u=!0;let r=Si(e),i=o,s=window.location.href;return Ci(a,e),d=d.then(async()=>{t.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:e.merchantId,domain:e.domain??``,allowedDomains:e.allowedDomains??[],sourceUrl:s,...i&&{sdkAnonymousId:i},...n&&{pendingMergeToken:n},...r&&{sdkConfig:r},...i&&{sdkIdentity:await Ti({merchantId:e.merchantId,anonymousId:i,pendingMergeToken:n})}}})}).catch(e=>{console.error(`Failed to send lifecycle config`,e)}),d};J.isResolved&&f(J.getConfig()).then(i.resolve),r&&(l(await r),f(J.getConfig()).then(i.resolve));async function p(){let n=e.customizations?.css;n&&t.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:n}})}async function m(){let n=e.customizations?.i18n;n&&t.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:n}})}async function h(){if(typeof window>`u`)return;let e=window.localStorage.getItem(Wr);e&&t.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}(await Promise.allSettled([p(),m(),h()])).some(e=>e.status===`rejected`)&&a?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`})}function Di(e){return nn(Zn(e))}function Oi(e){try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}}function ki(e){if(!e)return null;if(Array.isArray(e))return e;if(typeof e!=`string`)return null;try{let t=JSON.parse(e);return Array.isArray(t)?t:null}catch{return null}}function Ai(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e==`string`&&e.trim()!==``){let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}}function ji(e){if(typeof e!=`string`)return;let t=e.trim();return t===``?void 0:t}function Mi(e){if(!e||typeof e!=`object`)return;let t=e,n={},r=ji(t.productId);r!==void 0&&(n.productId=r);let i=ji(t.sku);i!==void 0&&(n.sku=i);let a=ji(t.name);a!==void 0&&(n.name=a);let o=Ai(t.quantity);o!==void 0&&(n.quantity=o);let s=Ai(t.unitPrice);s!==void 0&&(n.unitPrice=s);let c=Ai(t.totalPrice);return c!==void 0&&(n.totalPrice=c),Object.keys(n).length>0?n:void 0}function Ni(e){let t=ki(e);if(!t)return;let n=[];for(let e of t){let t=Mi(e);t&&n.push(t)}return n.length>0?n:void 0}function Pi(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.title==`string`?t.title.trim():``;if(n===``)return null;let r={title:n,...Mi(e)};return typeof t.imageUrl==`string`&&Oi(t.imageUrl)&&(r.imageUrl=t.imageUrl),typeof t.link==`string`&&Oi(t.link)&&(r.link=t.link),typeof t.utmContent==`string`&&t.utmContent!==``&&(r.utmContent=t.utmContent),r}function Fi(e){let t=ki(e);if(!t)return;let n=[];for(let e of t){let t=Pi(e);t&&n.push(t)}return n.length>0?n:void 0}function Ii(e){if(!e)return;let t;try{t=Di(e)}catch{return}if(t!==null)return Fi(t)}async function Li({config:e}){let t=Ri(e),n=await si({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=await bi({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function Ri(e){let t=Mr(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function zi({perCall:e,defaults:t,productUtmContent:n}){if(e===null)return;let r=e!==void 0,i=t!==void 0&&Object.keys(t).length>0;if(!r&&!i&&(n===void 0||n===``))return;let a={...t,...e??{}},o=n??e?.utmContent;return o!==void 0&&o!==``?a.utmContent=o:delete a.utmContent,a}var Bi=t({DEEP_LINK_SCHEME:()=>Gr,FrakContextManager:()=>Ar,areAddressesEqual:()=>lr,base64urlDecode:()=>Zn,base64urlEncode:()=>Xn,baseIframeProps:()=>oi,buildListenerUrl:()=>ci,clearAllCache:()=>hn,coerceProductCandidates:()=>ki,compressJsonToB64:()=>Qn,createIFrameFrakClient:()=>bi,decodeProductsParam:()=>Ii,decompressJsonFromB64:()=>Di,deleteQueryParamCaseInsensitive:()=>$,detectPageLanguage:()=>qr,findIframeInOpener:()=>ui,formatAmount:()=>Pr,formatAmountParts:()=>Ir,generateSsoUrl:()=>$n,getBackendUrl:()=>U,getClientId:()=>Yn,getClientIdAsync:()=>X,getCurrencyAmountKey:()=>Rr,getEnvironment:()=>dn,getQueryParamCaseInsensitive:()=>Q,getSupportedCurrency:()=>Mr,isIOS:()=>ti,isInAppBrowser:()=>ii,isMobile:()=>ni,mergeAttribution:()=>zi,normalizeProductDetails:()=>Mi,normalizeSharingProduct:()=>Pi,redirectToExternalBrowser:()=>ai,sanitizeProductDetailsList:()=>Ni,sanitizeSharingProducts:()=>Fi,sdkConfigStore:()=>J,setEnvironment:()=>un,setupClient:()=>Li,ssoPopupFeatures:()=>rr,ssoPopupName:()=>ir,trackEvent:()=>Z,triggerDeepLinkWithFallback:()=>Qr,withCache:()=>G});async function Vi(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function Hi(e,{steps:t,metadata:n},r){return await e.request({method:`frak_displayModal`,params:r?[t,n,e.config.metadata,r]:[t,n,e.config.metadata]})}async function Ui(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function Wi(e){if(typeof window>`u`)return;let t=await X().catch(()=>void 0);if(!t)return;let n=await J.resolveMerchantId();if(!n)return;let r=`frak-identity-ensured-${n}-${t}`;if(!window.sessionStorage.getItem(r))try{let i=U(),a=await Y({op:`frak-ensure-v1`,merchantId:n,anonymousId:t});(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,...a&&{proof:a}})})).ok&&window.sessionStorage.setItem(r,`1`)}catch{}}async function Gi(e,t){return G(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:t?.cacheTime})}async function Ki(e,t){return G(async()=>{let t=await X().catch(()=>void 0),n=t?await Y({op:`frak-merge-v1`,merchantId:e.config.metadata.merchantId??``,anonymousId:t}):null;return e.request({method:`frak_getMergeToken`,params:n?[n]:void 0})},{cacheKey:`frak_getMergeToken`,cacheTime:t?.cacheTime})}async function qi(e,t){return G(()=>e.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:t?.cacheTime})}async function Ji(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function Yi(e,t){try{let n=await X().catch(()=>void 0);await e.request({method:`frak_sendInteraction`,params:[t,{clientId:n}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}function Xi(e,t,n){return mr(t)?(Z(e,`user_referred_started`,{referrer_client_id:t.c,referrer_wallet:t.w,wallet_status:n?.key}),Yi(e,{type:`arrival`,referrerClientId:t.c,referrerMerchantId:t.m,referrerWallet:t.w,referralTimestamp:t.t}),!0):pr(t)?(Z(e,`user_referred_started`,{referrer:t.r,wallet_status:n?.key}),Yi(e,{type:`arrival`,referrerWallet:t.r}),!0):!1}function Zi(e,t,n){return!t&&!n?null:{v:2,m:e,t:Math.floor(Date.now()/1e3),...t?{c:t}:{},...n?{w:n}:{}}}function Qi(e,t,n){return mr(e)?e.w&&n?.wallet?lr(e.w,n.wallet):e.c?t===e.c:!1:pr(e)&&n?.wallet?lr(e.r,n.wallet):!1}async function $i(e,{walletStatus:t,frakContext:n,options:r}){if(!n)return`no-referrer`;let i=await X().catch(()=>void 0);if(Qi(n,i,t))return`self-referral`;if(!Xi(e,n,t))return`no-referrer`;let a=mr(n)?n.m:r?.merchantId,o=r?.alwaysAppendUrl&&a?Zi(a,i,t?.wallet):null;return Ar.replaceUrl({url:window.location?.href,context:o}),Z(e,`user_referred_completed`,{status:`success`}),`success`}async function ea(e,{options:t}={}){let n=Ar.parse({url:window.location.href}),r=await ia(e);try{return await $i(e,{walletStatus:r,frakContext:n,options:t})}catch(e){console.warn(`Error processing referral`,{error:e})}}const ta=`frak:referral-success`;async function na(e){try{await ea(e)===`success`&&window.dispatchEvent(new Event(ta))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function ra(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=await X().catch(()=>void 0);if(!t&&!n){console.warn(`[Frak] No identity found, skipping purchase check`);return}let r=e.merchantId??await J.resolveMerchantId();if(!r){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let i={Accept:`application/json`,"Content-Type":`application/json`};t&&(i[`x-wallet-sdk-auth`]=t),n&&(i[`x-frak-client-id`]=n);let a=U();await fetch(`${a}/user/track/purchase`,{method:`POST`,headers:i,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:r})})}function ia(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(aa(e,t),t));let n=new $t,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{aa(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function aa(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),Wi(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function oa(e,{metadata:t,login:n}){return sa(e,{steps:{login:n??{}},metadata:t})}function sa(e,t){function n(n){return sa(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return sa(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return sa(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n,r){return n&&(t.metadata=n(t.metadata??{})),await Hi(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function ca(e,{tx:t,metadata:n}){return(await Hi(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function la(e=96){let t=Math.ceil(e/2),n=``;if(typeof crypto<`u`&&crypto.getRandomValues){let e=new Uint8Array(t);crypto.getRandomValues(e);for(let t=0;t<e.length;t++)n+=e[t].toString(16).padStart(2,`0`)}else for(let e=0;e<t;e++)n+=(Math.random()*256|0).toString(16).padStart(2,`0`);return n.substring(0,e)}async function ua(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 Hi(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??la(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}var da=t({REFERRAL_SUCCESS_EVENT:()=>ta,displayEmbeddedWallet:()=>Vi,displayModal:()=>Hi,displaySharingPage:()=>Ui,ensureIdentity:()=>Wi,getMerchantInformation:()=>Gi,getMergeToken:()=>Ki,getUserReferralStatus:()=>qi,modalBuilder:()=>oa,openSso:()=>ar,prepareSso:()=>Ji,prepareSsoUrl:()=>nr,processReferral:()=>$i,referralInteraction:()=>ea,sendInteraction:()=>Yi,sendTransaction:()=>ca,setupReferral:()=>na,siweAuthenticate:()=>ua,trackPurchaseStatus:()=>ra,watchWalletStatus:()=>ia});async function fa(e,t,n){if(!window.FrakSetup?.client){console.error(`Frak client not found`);return}await Ui(window.FrakSetup.client,{...n?.link&&{link:n.link},...n?.products?.length&&{products:n.products},...e&&{metadata:{targetInteraction:e}}},t)}const pa=[`frak-button-share`,`frak-button-wallet`,`frak-open-in-app`,`frak-post-purchase`,`frak-banner`].join(`,`);function ma(){return typeof document>`u`||document.querySelector(pa)===null?[]:[`sharing`]}const ha=`frak:client`;function ga(){let e=new CustomEvent(ha);window.dispatchEvent(e)}function _a(e,t){if(window.FrakSetup?.client&&e===`add`){t();return}(e===`add`?window.addEventListener:window.removeEventListener)(ha,t,!1)}function va(){return window.FrakSetup.core={...Bi,...da},window.FrakSetup?.client?Promise.resolve():G(()=>ya(),{cacheKey:`frak-sdk-init`,cacheTime:1/0}).catch(e=>{Z(window.FrakSetup?.client,`sdk_init_failed`,{reason:e instanceof Error?e.message:typeof e==`string`?e:`unknown`,config_missing:!window.FrakSetup?.config})})}async function ya(){if(!window.FrakSetup?.config)throw Error(`[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.`);console.log(`[Frak SDK] Starting initialization`);let e=await Li({config:ba(window.FrakSetup.config)});if(!e)throw Error(`[Frak SDK] Failed to create client`);window.FrakSetup.client=e,console.log(`[Frak SDK] Client initialized successfully`),ga(),na(e),xa()}function ba(e){return e.preload===void 0?{...e,preload:ma()}:e}function xa(){let e=new URL(window.location.href);if(Q(e.searchParams,`frakAction`)?.toLowerCase()!==`share`)return;console.log(`[Frak SDK] Auto open share via query param`);let t=Q(e.searchParams,`link`)??void 0,n=Q(e.searchParams,`placement`)??void 0,r=Ii(Q(e.searchParams,`products`));$(e.searchParams,`frakAction`),$(e.searchParams,`link`),$(e.searchParams,`placement`),$(e.searchParams,`products`),window.history.replaceState({},``,e.toString()),fa(void 0,n,{link:t,products:r})}o.injectBase(`shared`,n),o.injectBase(`fouce`,`frak-button-share:not(:defined), frak-button-wallet:not(:defined), frak-open-in-app:not(:defined), frak-post-purchase:not(:defined), frak-banner:not(:defined) { display: none !important; }`),s(va);const Sa={"button-share":()=>import(`./ButtonShare.DFg0XCDd.js`),"button-wallet":()=>import(`./ButtonWallet.sGDvcAXt.js`),"open-in-app":()=>import(`./OpenInAppButton.CxLPpqFO.js`),"post-purchase":()=>import(`./PostPurchase.D6Mzbjtu.js`),banner:()=>import(`./Banner.DGYexiiS.js`)},Ca=new MutationObserver(e=>{for(let{addedNodes:t}of e)for(let e of Array.from(t))e.nodeType===Node.ELEMENT_NODE&&wa(e)});async function wa(e){let t=e instanceof Element?e.tagName.toLowerCase():``,n=t?.startsWith(`frak-`),r=Array.from(e.querySelectorAll(`:not(:defined)`)).map(e=>e.tagName.toLowerCase()).filter(e=>e.startsWith(`frak-`));n&&!customElements.get(t)&&r.push(t);let i=[...new Set(r)];await Promise.allSettled(i.map(e=>Ta(e)))}async function Ta(e){if(customElements.get(e))return Promise.resolve();try{let t=e.replace(/^frak-/i,``);if(!(t in Sa))throw Error(`Component ${e} is not supported.`);await Sa[t]()}catch(e){console.error(e)}}wa(document.body),Ca.observe(document.documentElement,{subtree:!0,childList:!0});export{J as C,s as D,Qt as E,o as O,Mr as S,Zt as T,qr as _,ta as a,Pr as b,Ki as c,ii as d,Gr as f,Qr as g,ni as h,ra as i,n as k,Gi as l,Ni as m,_a as n,qi as o,ai as p,fa as r,Vi as s,va as t,Fi as u,Ir as v,Z as w,Rr as x,Lr as y};
164
+ ;function Jt(e,t,n){Ve(`scalar`,e,H,n);let[[r,i],[a,o]]=t,s=qt(o*e,n),c=qt(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<H,f=u<H;d&&(l=-l),f&&(u=-u);let p=Ue(Math.ceil(He(n)/2))+U;if(l<H||l>=p||u<H||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function Yt(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function Xt(e,t){I(e);let n={};for(let r of Object.keys(t))n[r]=e[r]===void 0?t[r]:e[r];return N(n.lowS,`lowS`),N(n.prehash,`prehash`),n.format!==void 0&&Yt(n.format),n}const H=BigInt(0),U=BigInt(1),Zt=BigInt(2),Qt=BigInt(3),$t=BigInt(4);function en(e,t={}){let n=Vt(`weierstrass`,e,t),r=n.Fp,i=n.Fn,a=n.CURVE,{h:o,n:s}=a;I(t,{},{allowInfinityPoint:`boolean`,clearCofactor:`function`,isTorsionFree:`function`,fromBytes:`function`,toBytes:`function`,endo:`object`,randomBytes:`function`});let{endo:c,allowInfinityPoint:l}=t,u=t.randomBytes===void 0?Oe:t.randomBytes;if(c&&(!r.is0(a.a)||typeof c.beta!=`bigint`||!Array.isArray(c.basises)))throw Error(`invalid endo: expected "beta": bigint and "basises": array`);let d=nn(r,i);function f(){if(!r.isOdd)throw Error(`compression is not supported: Field does not have .isOdd()`)}function p(e,t,n){if(l&&t.is0())return Uint8Array.of(0);let{x:i,y:a}=t.toAffine(),o=r.toBytes(i);if(N(n,`isCompressed`),n){f();let e=!r.isOdd(a);return M(tn(e),o)}return M(Uint8Array.of(4),o,r.toBytes(a))}function m(e){A(e,void 0,`Point`);let{publicKey:t,publicKeyUncompressed:n}=d,i=e.length,a=e[0],o=e.subarray(1);if(l&&i===1&&a===0)return{x:r.ZERO,y:r.ZERO};if(i===t&&(a===2||a===3)){let e=r.fromBytes(o);if(!r.isValid(e))throw Error(`bad point: is not on curve, wrong x`);let t=ee(e),n;try{n=r.sqrt(t)}catch(e){let t=e instanceof Error?`: `+e.message:``;throw Error(`bad point: is not on curve, sqrt error`+t)}f();let i=r.isOdd(n);return(a&1)==1!==i&&(n=r.neg(n)),{x:e,y:n}}if(i===n&&a===4){let e=r.BYTES,t=r.fromBytes(o.subarray(0,e)),n=r.fromBytes(o.subarray(e,e*2));if(!y(t,n))throw Error(`bad point: is not on curve`);return{x:t,y:n}}throw Error(`bad point: got length ${i}, expected compressed=${t} or uncompressed=${n}`)}let h=t.toBytes===void 0?p:t.toBytes,g=t.fromBytes===void 0?m:t.fromBytes,_=r.mul(a.b,Qt),v=r.is0(a.a)?e=>r.ZERO:e=>r.mul(a.a,e);function ee(e){let t=r.sqr(e),n=r.mul(t,e);return r.add(r.add(n,r.mul(e,a.a)),a.b)}function y(e,t){let n=r.sqr(t),i=ee(e);return r.eql(n,i)}if(!y(a.Gx,a.Gy))throw Error(`bad curve params: generator point`);let b=r.mul(r.pow(a.a,Qt),$t),te=r.mul(r.sqr(a.b),BigInt(27));if(r.is0(r.add(b,te)))throw Error(`bad curve params: a or b`);function x(e,t,n=!1){if(!r.isValid(t)||n&&r.is0(t))throw Error(`bad point coordinate ${e}`);return t}function S(e){if(!(e instanceof T))throw Error(`Weierstrass Point expected`)}function ne(e){if(!c||!c.basises)throw Error(`no endo`);return Jt(e,c.basises,i.ORDER)}function C(e,t,n,a){if(!i.isValid(a))throw RangeError(`invalid scalar: out of range`);if(c){let{k1neg:i,k1:o,k2neg:s,k2:l}=ne(a),u=new T(r.mul(n.X,c.beta),n.Y,n.Z);e.push(i?n.negate():n,s?u.negate():u),t.push(o,l)}else e.push(n),t.push(a)}let w=new WeakSet;class T{static BASE=new T(a.Gx,a.Gy,r.ONE);static ZERO=new T(r.ZERO,r.ONE,r.ZERO);static Fp=r;static Fn=i;X;Y;Z;constructor(e,t,n){this.X=x(`x`,e),this.Y=x(`y`,t,!0),this.Z=x(`z`,n),Object.freeze(this)}static CURVE(){return a}static fromAffine(e){let{x:t,y:n}=e||{};if(!e||!r.isValid(t)||!r.isValid(n))throw Error(`invalid affine point`);if(e instanceof T)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?T.ZERO:new T(t,n,r.ONE)}static fromBytes(e){let t=T.fromAffine(g(A(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return T.fromBytes(Ee(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=6,t=!0){return D.setWindowSize(this,e),t||this.multiply(Qt),this}assertValidity(){let e=this;if(e.is0()){if(t.allowInfinityPoint&&r.is0(e.X)&&r.eql(e.Y,r.ONE)&&r.is0(e.Z))return;throw Error(`bad point: ZERO`)}if(w.has(e))return;let{x:n,y:i}=e.toAffine();if(!r.isValid(n)||!r.isValid(i))throw Error(`bad point: x or y not field elements`);if(!y(n,i))throw Error(`bad point: equation left != right`);if(!e.isTorsionFree())throw Error(`bad point: not in prime-order subgroup`);w.add(e)}hasEvenY(){let{y:e}=this.toAffine();if(!r.isOdd)throw Error(`Field doesn't support isOdd`);return!r.isOdd(e)}equals(e){S(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.eql(r.mul(t,s),r.mul(a,i)),l=r.eql(r.mul(n,s),r.mul(o,i));return c&&l}negate(){return new T(this.X,r.neg(this.Y),this.Z)}double(){let{X:e,Y:t,Z:n}=this,i=r.ZERO,a=r.ZERO,o=r.ZERO,s=r.mul(e,e),c=r.mul(t,t),l=r.mul(n,n),u=r.mul(e,t);return u=r.add(u,u),o=r.mul(e,n),o=r.add(o,o),i=v(o),a=r.mul(_,l),a=r.add(i,a),i=r.sub(c,a),a=r.add(c,a),a=r.mul(i,a),i=r.mul(u,i),o=r.mul(_,o),l=v(l),u=r.sub(s,l),u=v(u),u=r.add(u,o),o=r.add(s,s),s=r.add(o,s),s=r.add(s,l),s=r.mul(s,u),a=r.add(a,s),l=r.mul(t,n),l=r.add(l,l),s=r.mul(l,u),i=r.sub(i,s),o=r.mul(l,c),o=r.add(o,o),o=r.add(o,o),new T(i,a,o)}add(e){S(e);let{X:t,Y:n,Z:i}=this,{X:a,Y:o,Z:s}=e,c=r.ZERO,l=r.ZERO,u=r.ZERO,d=r.mul(t,a),f=r.mul(n,o),p=r.mul(i,s),m=r.add(t,n),h=r.add(a,o);m=r.mul(m,h),h=r.add(d,f),m=r.sub(m,h),h=r.add(t,i);let g=r.add(a,s);return h=r.mul(h,g),g=r.add(d,p),h=r.sub(h,g),g=r.add(n,i),c=r.add(o,s),g=r.mul(g,c),c=r.add(f,p),g=r.sub(g,c),u=v(h),c=r.mul(_,p),u=r.add(c,u),c=r.sub(f,u),u=r.add(f,u),l=r.mul(c,u),f=r.add(d,d),f=r.add(f,d),p=v(p),h=r.mul(_,h),f=r.add(f,p),p=r.sub(d,p),p=v(p),h=r.add(h,p),d=r.mul(f,h),l=r.add(l,d),d=r.mul(g,h),c=r.mul(m,c),c=r.sub(c,d),d=r.mul(m,f),u=r.mul(g,u),u=r.add(u,d),new T(c,l,u)}subtract(e){return S(e),this.add(e.negate())}is0(){return this.equals(T.ZERO)}multiply(e){if(!i.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let{p:t,f:n}=D.mulSecret(this,e,o,E);return E([t,n])[0]}multiplyUnsafe(e){let t=this,n=e;if(!i.isValid(n))throw RangeError(`invalid scalar: out of range`);if(n===H||t.is0())return T.ZERO;if(n===U)return t;if(D.hasWindowSize(this))return D.mulUnsafe(t,n,E);let r=[],a=[];return C(r,a,t,n),zt(T,r,a)}mulAddUnsafe(e,t,n){S(t);let r=[],i=[];return C(r,i,this,e),C(r,i,t,n),zt(T,r,i)}toAffine(e){let t=this,n=e;if(n!=null&&!r.isValid(n))throw RangeError(`"invertedZ" expected valid field element`);let{X:i,Y:a,Z:o}=t;if(r.eql(o,r.ONE))return{x:i,y:a};let s=t.is0();n??=s?r.ONE:r.inv(o);let c=r.mul(i,n),l=r.mul(a,n),u=r.mul(o,n);if(s)return{x:r.ZERO,y:r.ZERO};if(!r.eql(u,r.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}isTorsionFree(){let{isTorsionFree:e}=t;return o===U?!0:e?e(T,this):D.mulUnsafe(this,s).is0()}clearCofactor(){let{clearCofactor:e}=t;return o===U?this:e?e(T,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===U?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return N(e,`isCompressed`),this.assertValidity(),h(T,this,e)}toHex(e=!0){return Te(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let E=e=>Et(T,e),D=new Rt(T,u);return D.bits>=6&&T.BASE.precompute(6),Object.freeze(T.prototype),Object.freeze(T),T}function tn(e){return Uint8Array.of(e?2:3)}function nn(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function rn(e,t={}){Tt(e);let{Fn:n}=e,r=t.randomBytes===void 0?Oe:t.randomBytes,i=Object.assign(nn(e.Fp,n),{seed:Math.max(yt(n.ORDER),16)});function a(e){try{let t=n.fromBytes(e);return n.isValidNot0(t)}catch{return!1}}function o(t,n){let{publicKey:r,publicKeyUncompressed:a}=i;try{let i=t.length;return n===!0&&i!==r||n===!1&&i!==a?!1:!!e.fromBytes(t)}catch{return!1}}function s(e){return e=e===void 0?r(i.seed):e,bt(A(e,i.seed,`seed`),n.ORDER)}function c(t,r=!0){return e.BASE.multiply(n.fromBytes(t)).toBytes(r)}function l(e){let{secretKey:t,publicKey:r,publicKeyUncompressed:a}=i,o=n._lengths;if(!De(e))return;let s=A(e,void 0,`key`).length,c=s===r||s===a,l=s===t||!!o?.includes(s);if(!(c&&l))return c}function u(t,r,i=!0){if(l(t)===!0)throw Error(`first arg must be private key`);if(l(r)===!1)throw Error(`second arg must be public key`);let a=n.fromBytes(t);return e.fromBytes(r).multiply(a).toBytes(i)}let d={isValidSecretKey:a,isValidPublicKey:o,randomSecretKey:s},f=Ht(s,c);return Object.freeze(d),Object.freeze(i),Object.freeze({getPublicKey:c,getSharedSecret:u,keygen:f,Point:e,utils:d,lengths:i})}function an(e,t,n={}){Tt(e);let r=t;ne(r),I(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`});let i=Object.assign({},n),a=i.randomBytes===void 0?Oe:i.randomBytes,o=i.hmac===void 0?(e,t)=>Wt(r,e,t):i.hmac,{Fp:s,Fn:c}=e,{ORDER:l,BITS:u}=c,d=yt(l),f=kt(a,d),{keygen:p,getPublicKey:m,getSharedSecret:h,utils:g,lengths:_}=rn(e,i),v={prehash:!0,lowS:typeof i.lowS!=`boolean`||i.lowS,format:`compact`,extraEntropy:!1},ee=l*Zt+U<s.ORDER;function y(e){return e>l>>U}function b(e,t){if(!c.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function te(){if(!s.isOdd)throw Error(`Field doesn't support isOdd`)}function x(e,t,n){return te(),(e===n?0:2)|Number(s.isOdd(t))}function S(){if(ee)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function C(e,t){Yt(t);let n=_.signature,r=t===`compact`?n:t===`recovered`?n+1:void 0;return A(e,r)}class w{r;s;recovery;constructor(e,t,n){if(this.r=b(`r`,e),this.s=b(`s`,t),n!=null){if(S(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=v.format){C(e,t);let n;if(t===`der`){let{r:t,s:n}=Kt.toSig(A(e));return new w(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=_.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new w(c.fromBytes(i),c.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(Ee(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new w(this.r,this.s,e)}recoverPublicKey(t){let{r:n,s:r}=this,i=this.assertRecovery(),a=i===2||i===3?n+l:n;if(!s.isValid(a))throw Error(`invalid recovery id: sig.r+curve.n != R.x`);let o=s.toBytes(a),u=e.fromBytes(M(tn(!(i&1)),o)),d=c.inv(a),f=E(A(t,void 0,`msgHash`)),p=c.create(-f*d),m=c.create(r*d),h=e.BASE.mulAddUnsafe(p,u,m);if(h.is0())throw Error(`invalid recovery: point at infinify`);return h.assertValidity(),h}hasHighS(){return y(this.s)}toBytes(e=v.format){if(Yt(e),e===`der`)return Ee(Kt.hexFromSig(this));let{r:t,s:n}=this,r=c.toBytes(t),i=c.toBytes(n);return e===`recovered`?(S(),M(Uint8Array.of(this.assertRecovery()),r,i)):M(r,i)}toHex(e){return Te(this.toBytes(e))}}Object.freeze(w.prototype),Object.freeze(w);let T=i.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=P(e),n=e.length*8-u;return n>0?t>>BigInt(n):t}:i.bits2int,E=i.bits2int_modN===void 0?function(e){return c.create(T(e))}:i.bits2int_modN,D=Ue(u);function O(e){return Ve(`num < 2^`+u,e,H,D),c.toBytes(e)}function re(e,t){return A(e,void 0,`message`),t?A(r(e),void 0,`prehashed message`):e}function ie(t,n,r){let{lowS:i,prehash:o,extraEntropy:s}=Xt(r,v);t=re(t,o);let u=E(t),p=c.fromBytes(n);if(!c.isValidNot0(p))throw Error(`invalid private key`);let m=[O(p),O(u)];if(s!=null&&s!==!1){let e=s===!0?a(_.secretKey):s;m.push(A(e,void 0,`extraEntropy`))}let h=M(...m),g=u;function b(t){let n=T(t);if(!c.isValidNot0(n))return;let r=e.BASE.multiply(n).toAffine(),a=c.create(r.x);if(a===H)return;let o;if(f!==void 0){let e=P(bt(f(d),l)),t=c.inv(c.mul(e,n)),r=c.mul(e,g),i=c.mul(e,p);o=c.create(t*c.create(r+i*a))}else{let e=nt(n,l);o=c.create(e*c.create(g+a*p))}if(o===H)return;let s=x(r.x,r.y,a),u=o;return i&&y(o)&&(u=c.neg(o),s^=1),new w(a,u,ee?void 0:s)}return{seed:h,k2sig:b}}function ae(e,t,n={}){let{seed:i,k2sig:a}=ie(e,t,n);return We(r.outputLen,c.BYTES,o)(i,a).toBytes(n.format)}function oe(t,n,r,i={}){let{lowS:a,prehash:o,format:s}=Xt(i,v);if(r=A(r,void 0,`publicKey`),n=re(n,o),!De(t)){let e=t instanceof w?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}C(t,s);try{let i=w.fromBytes(t,s),o=e.fromBytes(r);if(a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=E(n),f=c.inv(u),p=c.create(d*f),m=c.create(l*f),h=e.BASE.mulAddUnsafe(p,o,m);if(h.is0())return!1;let g=h.toAffine();return!(c.create(g.x)!==l||s===`recovered`&&i.recovery!==x(g.x,g.y,l))}catch{return!1}}function se(e,t,n={}){let{prehash:r}=Xt(n,v);return t=re(t,r),w.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:p,getPublicKey:m,getSharedSecret:h,utils:g,lengths:_,Point:e,sign:ae,verify:oe,recoverPublicKey:se,Signature:w,hash:r})}
165
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
166
+ const on=an(en({p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)}),be),sn=`pkcs8`,cn=sn,ln=`spki`
167
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
168
+ ;function W(){let e=globalThis?.crypto?.subtle;if(typeof e==`object`&&e)return e;throw Error(`crypto.subtle must be defined`)}function un(e,t){return async function(n){let r=await e();return{secretKey:r,publicKey:await t(r)}}}function dn(e){let t=e.match(/[0-9a-f]{2}/gi);if(!t||t.length*2!==e.length)throw Error(`invalid hex`);return Uint8Array.from(t,e=>Number.parseInt(e,16))}function fn(e,t){if(t.type!==e)throw Error(`invalid key type, expected ${e}`)}function pn(e,t,n,r){let i=t?[`deriveBits`]:[`sign`],a=t?[]:[`verify`],o=(e,t)=>t===`jwk`?e:new Uint8Array(e),s={async import(t,n){let r=await W().importKey(n,t,e,!0,a);return fn(`public`,r),r},async export(e,t){fn(`public`,e);let n=await W().exportKey(t,e);return o(n,t)},async convert(e,t,n){return s.export(await s.import(e,t),n)}},c={async import(a,o){let s=W(),c;if(o===`raw`){let t=A(a,n,`secretKey`),o=dn(r),l=new Uint8Array(o.length+t.length);l.set(o,0),l.set(t,o.length),c=await s.importKey(sn,l,e,!0,i)}else t&&o===`jwk`&&(a={...a,key_ops:i}),c=await s.importKey(o,a,e,!0,i);return fn(`private`,c),c},async export(e,t){let r=W();if(fn(`private`,e),t===`raw`){let t=(await r.exportKey(`jwk`,e)).d.replace(/-/g,`+`).replace(/_/g,`/`),i=t.length%4?`=`.repeat(4-t.length%4):``,a=atob(t+i),o=Uint8Array.from(a,e=>e.charCodeAt(0)),s=new Uint8Array(n);return s.set(o,n-o.length),s}let i=await r.exportKey(t,e);return o(i,t)},async convert(e,t,n){return c.export(await c.import(e,t),n)}};async function l(e,t={}){I(t,{},{formatSec:`string`,formatPub:`string`},`opts`);let n=t.formatSec??cn,r=t.formatPub??ln,i=n===`jwk`?{...e}:await c.convert(e,n,`jwk`);return delete i.d,i.key_ops=a,r===`jwk`?i:s.convert(i,`jwk`,r)}async function u(t=cn){let n=await W().generateKey(e,!0,i);return c.export(n.privateKey,t)}let d;return{pub:s,priv:c,async isSupported(){if(d!==void 0)return d;try{let n=W(),r=await n.generateKey(e,!0,i);return await c.export(r.privateKey,`jwk`),t&&await n.deriveBits({name:typeof e==`string`?e:e.name,public:r.publicKey},r.privateKey,8),d=!0}catch{return d=!1}},getPublicKey:l,keygen:un(u,l),utils:Object.freeze({randomSecretKey:u,convertPublicKey:s.convert,convertSecretKey:c.convert})}}function mn(e,t){return{async sign(n,r,i={}){I(i,{},{formatSec:`string`,formatPub:`string`},`opts`);let a=await e.priv.import(r,i.formatSec??cn),o=await W().sign(t,a,n);return new Uint8Array(o)},async verify(n,r,i,a={}){I(a,{},{formatSec:`string`,formatPub:`string`},`opts`);let o=await e.pub.import(i,a.formatPub??ln);return await W().verify(t,o,n,r)}}}function hn(e,t,n){return{async getSharedSecret(r,i,a={}){I(a,{},{formatSec:`string`,formatPub:`string`},`opts`);let o=await e.priv.import(r,a.formatSec===void 0?cn:a.formatSec),s=await e.pub.import(i,a.formatPub===void 0?ln:a.formatPub),c=await W().deriveBits({name:typeof t==`string`?t:t.name,public:s},o,8*n);return new Uint8Array(c)}}}function gn(e,t,n,r){let i={name:`ECDH`,namedCurve:e},a=pn({name:`ECDSA`,namedCurve:e},!1,n,r),o=pn(i,!0,n,r);return Object.freeze({name:e,isSupported:a.isSupported,getPublicKey:a.getPublicKey,keygen:un(a.utils.randomSecretKey,a.getPublicKey),...mn(a,{name:`ECDSA`,hash:{name:t}}),...hn(o,i,n),utils:Object.freeze({...a.utils,async convertSecretKey(e,t,n){let r=t===`jwk`?e:void 0;return Array.isArray(r?.key_ops)&&r.key_ops.length===1&&r.key_ops[0]===`deriveBits`?o.utils.convertSecretKey(e,t,n):a.utils.convertSecretKey(e,t,n)}})})}const _n=gn(`P-256`,`SHA-256`,32,`3041020100301306072a8648ce3d020106082a8648ce3d030107042730250201010420`),vn={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 yn=class extends Error{code;data;constructor(e,t,n){super(t),this.code=e,this.data=n}toJSON(){return{code:this.code,message:this.message,data:this.data}}},bn=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 xn(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 bn;return o.set(t,e=>{e.error?n.reject(new yn(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 Sn(e){return new TextEncoder().encode(JSON.stringify(e))}function Cn(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}const wn=`__frakEnv`,Tn={prod:{wallet:`https://wallet.frak.id`,backend:`https://backend.frak.id`},dev:{wallet:`https://wallet-dev.frak.id`,backend:`https://backend.gcp-dev.frak.id`}};function En(){return typeof window<`u`}let Dn=Tn.prod;function On(e){return e.endsWith(`/`)?e.slice(0,-1):e}function kn(e){return typeof e==`string`?Tn[e]||(console.error(`[Frak SDK] Unknown env "${e}", falling back to production. Expected "prod", "dev", or { wallet, backend }.`),Tn.prod):!e?.wallet||!e?.backend?(console.error("[Frak SDK] env must state both `wallet` and `backend` origins, falling back to production. Received:",e),Tn.prod):{wallet:On(e.wallet),backend:On(e.backend)}}function An(e){if(!e)return jn();let t=kn(e),n=En()?window[wn]:void 0;return n&&(n.wallet!==t.wallet||n.backend!==t.backend)&&console.warn(`[Frak SDK] env changed after being published; the last value wins for every SDK call on this page.`,{previous:n,next:t}),Dn=t,En()&&(window[wn]=t),t}function jn(){return En()?window[wn]??Dn:Dn}function Mn(){return jn().wallet}function G(){return jn().backend}var Nn=class extends Map{maxSize;constructor(e){super(),this.maxSize=e}get(e){let t=super.get(e);return super.has(e)&&(super.delete(e),super.set(e,t)),t}set(e,t){if(super.has(e)&&super.delete(e),super.set(e,t),this.maxSize&&this.size>this.maxSize){let e=super.keys().next().value;e!==void 0&&super.delete(e)}return this}};let K;function Pn(){return K||={promiseCache:new Nn(1024),responseCache:new Nn(1024),failureCache:new Nn(1024)},K}async function q(e,{cacheKey:t,cacheTime:n=3e4}){let{promiseCache:r,responseCache:i,failureCache:a}=Pn();if(n>0){let e=i.get(t);if(e&&Date.now()-e.created<n)return e.data}let o=a.get(t);if(o&&Date.now()-o<1e3)throw Error(`Cache: ${t} recently failed, backing off`);let s=r.get(t);s||(s=e(),r.set(t,s));try{let e=await s;return i.set(t,{data:e,created:Date.now()}),a.delete(t),e}catch(e){throw a.set(t,Date.now()),e}finally{r.delete(t)}}function Fn(){K&&(K.promiseCache.clear(),K.responseCache.clear(),K.failureCache.clear())}const In=`__frakSdkConfig`,Ln=`frak-config-cache`,Rn=`frak-merchant-id`,zn={key:Ln},J=typeof window<`u`;function Bn(){return{isResolved:!1,merchantId:``}}let Vn=null;function Hn(){if(!J)return null;try{let e=localStorage.getItem(zn.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(Vn=t,t):null}catch{return null}}function Un(){return(Vn??Hn())?.config}function Wn(){let e=Vn??Hn();return e?Date.now()-e.timestamp<3e4:!1}function Gn(e){if(!(!J||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(zn.key,JSON.stringify(t)),Vn=t}catch{}}function Kn(){if(J){Vn=null;try{localStorage.removeItem(zn.key)}catch{}}}function qn(){J&&(window[In]||(window[In]=Un()??Bn()))}function Jn(){return J?(qn(),window[In]??Bn()):Bn()}function Yn(e){J&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function Xn(e){return e??(J?window.location.hostname:``)}async function Zn(e,t){try{let n=G(),r=t?`&lang=${encodeURIComponent(t)}`:``,i=await fetch(`${n}/user/merchant/resolve?domain=${encodeURIComponent(e)}${r}`);if(!i.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${e}: ${i.status}`);return}let a=await i.json();if(J)try{sessionStorage.setItem(Rn,a.merchantId)}catch{}return a}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}const Y={getConfig:Jn,get isResolved(){return Jn().isResolved},get isCacheFresh(){return Wn()},setCacheScope(e,t){let n=`${e}:${t??``}`;zn.key=`${Ln}:${n}`,Vn=null},setConfig(e){if(J&&(window[In]=e),Gn(e),Yn(e),J&&e.merchantId)try{sessionStorage.setItem(Rn,e.merchantId)}catch{}},reset(){let e=Un()??Bn();J&&(window[In]=e),Yn(e)},clearCache(){if(Kn(),Fn(),J)try{sessionStorage.removeItem(Rn)}catch{}},resolve(e,t){let n=Xn(e);return n?q(async()=>{let e=await Zn(n,t);if(!e)throw Error(`Config resolution returned empty`);return e},{cacheKey:`sdkConfig:${n}:${t??``}`,cacheTime:1/0}).catch(()=>void 0):Promise.resolve(void 0)},getMerchantId(){let e=Jn();if(e.isResolved&&e.merchantId)return e.merchantId;if(J)try{return sessionStorage.getItem(Rn)??void 0}catch{}},async resolveMerchantId(e){return Y.getMerchantId()||(await Y.resolve(e))?.merchantId}};function Qn(){if(!(typeof navigator>`u`))return navigator.locks}async function $n(e,t,n={}){let r=Qn();if(!r)return t();if(n.ifAvailable)return r.request(e,{ifAvailable:!0},async e=>e?t():void 0);let i=new AbortController,a=setTimeout(()=>i.abort(),5e3),o=!1;try{return await r.request(e,{signal:i.signal},()=>(o=!0,t()))}catch(e){if(o)throw e;return t()}finally{clearTimeout(a)}}async function er(e){return p(be(e))}const tr=`frak-client-id`,nr=`frak-client-key`,rr=`frak-client-id-legacy`,ir={formatSec:`raw`,formatPub:`raw`};let ar=null;function or(){return ar??=_n.isSupported().then(e=>e?_n:on).catch(()=>on),ar}const sr=()=>typeof window<`u`&&!!window.localStorage;let cr=null;function lr(e){let t=m(e);if(cr?.keyHex===t)return cr.publicKey;let n=on.getPublicKey(e,!1);return cr={keyHex:t,publicKey:n},n}function ur(){if(sr())return localStorage.getItem(rr)??void 0}function dr(){sr()&&localStorage.removeItem(rr)}function fr(){let e=localStorage.getItem(nr);if(!e)return null;if(!/^[0-9a-f]{64}$/i.test(e))throw Error(`[Frak SDK] Corrupt client key`);return h(e)}function pr(e){try{for(let[t,n]of e)localStorage.setItem(t,n)}catch{}}async function mr(){if(!sr())throw Error(`[Frak SDK] No window/localStorage available to derive a client id`);if(typeof crypto>`u`||!crypto.getRandomValues)throw Error(`[Frak SDK] crypto.getRandomValues unavailable, cannot derive a client id`);return $n(`frak-identity-key`,hr)}async function hr(){let e=localStorage.getItem(tr),t,n,r;try{t=fr(),n=t??on.utils.randomSecretKey(),r=await er(lr(n))}catch(e){throw localStorage.removeItem(nr),cr=null,e}if(t){e!==r&&pr([[tr,r]]);let t=ur();return{clientId:r,...t&&{pendingLegacyId:t}}}return pr([...e?[[rr,e]]:[],[nr,m(n)],[tr,r]]),{clientId:r,...e&&{pendingLegacyId:e}}}async function X(e){if(!sr())return null;try{let t=fr();if(!t)return null;let n=e.ts??Math.floor(Date.now()/1e3),r=f({op:e.op,merchantId:e.merchantId,anonymousId:e.anonymousId,binding:e.binding??new Uint8Array,ts:n}),i=await or()===_n?await _n.sign(r,t,ir):on.sign(r,t,{prehash:!0});return _({v:1,pk:lr(t),ts:n,sig:i})}catch{return null}}function gr(){return{"x-frak-sdk-version":`1.3.0`}}const _r=new Set([`PROOF_REQUIRED`,`PROOF_OR_TOKEN_REQUIRED`,`MISSING_ANONYMOUS_ID`]);async function vr(e){if(e.status>=500||e.status===403)return!0;try{let t=await e.clone().json();return typeof t.code==`string`&&_r.has(t.code)}catch{return!1}}async function yr({legacyId:e,derivedId:t}){if(!(typeof window>`u`)){if(!e||e===t){dr();return}await $n(`frak-legacy-merge`,async()=>{ur()===e&&await br({legacyId:e,derivedId:t})},{ifAvailable:!0})}}async function br({legacyId:e,derivedId:t}){try{let n=await Y.resolveMerchantId();if(!n)return;let r=await X({op:`frak-merge-v1`,merchantId:n,anonymousId:t});if(!r)return;let i=G(),a=await fetch(`${i}/user/identity/merge/initiate`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,...gr()},body:JSON.stringify({sourceAnonymousId:t,merchantId:n,proof:r})});if(!a.ok){await vr(a)||dr();return}let{mergeToken:o}=await a.json();if(!o)return;let s=await fetch(`${i}/user/identity/merge/execute`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,...gr()},body:JSON.stringify({mergeToken:o,targetAnonymousId:e,merchantId:n})});if(s.ok){dr();return}await vr(s)||dr()}catch{}}let xr=null,Sr=null;async function Cr(){return xr||Sr||(Sr=mr().then(({clientId:e,pendingLegacyId:t})=>(xr=e,t&&yr({legacyId:t,derivedId:e}),e)),Sr)}function wr(){if(xr)return xr;Cr().catch(()=>{})}async function Z(){return xr||Cr()}function Tr(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Er(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 Dr(e){return Tr(Sn(e))}function Or(e,t,n,r,i,a,o){let s=Dr(kr({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,proof:o})),c=new URL(e);return c.pathname=`/sso`,c.searchParams.set(`p`,s),c.toString()}function kr(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},pf:e.proof}}function Ar(e){return{...e,directExit:e.directExit??!e.redirectUrl}}async function jr(e,t){let{metadata:n,customizations:r}=e.config,i=wr()??await Z().catch(()=>void 0),a=await Y.resolveMerchantId()??``,o=i&&a?await X({op:`frak-sso-v1`,merchantId:a,anonymousId:i}):null;return{ssoUrl:Or(Mn(),Ar(t),a,n.name,i,r?.css,o??void 0)}}const Mr=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,Nr=`frak-sso`;async function Pr(e,t){let{metadata:n,customizations:r}=e.config;if(`ssoUrl`in t)return Fr(t.ssoUrl),await e.request({method:`frak_openSso`,params:[{},n.name,r?.css]})??{};let i=Ar(t);return i.openInSameWindow??!!i.redirectUrl?await e.request({method:`frak_openSso`,params:[i,n.name,r?.css]}):(Fr(i.ssoPopupUrl??(await jr(e,i)).ssoUrl),await e.request({method:`frak_openSso`,params:[i,n.name,r?.css]})??{})}function Fr(e){let t=window.open(e,Nr,Mr);if(!t)throw Error(`Popup was blocked. Please allow popups for this site.`);t.focus()}function Q(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)}}function Ir(e,t){let n=e.get(t);if(n!==null)return n;let r=t.toLowerCase();for(let[t,n]of e)if(t.toLowerCase()===r)return n;return null}function $(e,t){let n=t.toLowerCase(),r=[...e.keys()].filter(e=>e.toLowerCase()===n);for(let t of r)e.delete(t)}const Lr=/^0x[a-fA-F0-9]{40}$/;function Rr(e){return typeof e==`string`&&Lr.test(e)}function zr(e,t){return e.toLowerCase()===t.toLowerCase()}function Br(e){let t=new Uint8Array(20);for(let n=0;n<20;n++){let r=Number.parseInt(e.substring(2+n*2,4+n*2),16);if(Number.isNaN(r))throw Error(`Invalid address: ${e}`);t[n]=r}return t}const Vr=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function Hr(e){let t=`0x`;for(let n=0;n<20;n++)t+=Vr[e[n]];return t}function Ur(e){return`r`in e&&!(`v`in e)}function Wr(e){return`v`in e&&e.v===2}const Gr=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Kr(e){return typeof e==`string`&&Gr.test(e)}function qr(e){let t=e.replace(/-/g,``),n=new Uint8Array(16);for(let e=0;e<16;e++)n[e]=Number.parseInt(t.substring(e*2,e*2+2),16);return n}function Jr(e){let t=``;for(let n=0;n<16;n++)t+=e[n].toString(16).padStart(2,`0`);return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20,32)}`}function Yr(e){if(!Kr(e.m)||!Number.isInteger(e.t)||e.t<0||e.t>4294967295)return null;let t=typeof e.c==`string`&&e.c.length>0,n=typeof e.w==`string`&&Rr(e.w);if(!t&&!n||t&&!Kr(e.c))return null;let r=new Uint8Array(21+(t?16:0)+(n?20:0)),i=new DataView(r.buffer,r.byteOffset,r.byteLength),a=0;return r[a++]=2|(t?16:0)|(n?32:0),r.set(qr(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set(qr(e.c),a),a+=16),n&&(r.set(Br(e.w),a),a+=20),r}function Xr(e){if(e.length<21)return null;let t=e[0];if((t&15)!=2||t&192)return null;let n=!!(t&16),r=!!(t&32);if(!n&&!r)return null;let i=21+(n?16:0)+(r?20:0);if(e.length!==i)return null;let a=1,o=Jr(e.subarray(a,a+16));a+=16;let s=new DataView(e.buffer,e.byteOffset,e.byteLength).getUint32(a,!1);a+=4;let c={v:2,m:o,t:s};if(n&&(c.c=Jr(e.subarray(a,a+16)),a+=16),r){let t=Hr(e.subarray(a,a+20));if(!Rr(t))return null;c.w=t,a+=20}return c}const Zr=`fCtx`;function Qr(e){if(e)try{if(Wr(e)){let t=Yr(e);return t?Tr(t):void 0}return Tr(Br(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function $r(e){if(!(!e||e.length===0))try{let t=Er(e);if(t.length!==20)return Xr(t)||void 0;let n=Hr(t);if(Rr(n))return{r:n}}catch(t){console.error(`Error decompressing Frak context`,{e:t,context:e})}}function ei({url:e}){if(!e)return null;let t=Ir(new URL(e).searchParams,Zr);return t?$r(t):null}function ti(e){return{utm_source:e.utmSource??`frak`,utm_medium:e.utmMedium??void 0,utm_campaign:e.utmCampaign??void 0,utm_content:e.utmContent,utm_term:e.utmTerm,via:e.via??void 0,ref:e.ref??void 0}}function ni(e,t){let n=ti(t??{});for(let[t,r]of Object.entries(n))r!==void 0&&r!==``&&(e.searchParams.has(t)||e.searchParams.set(t,r))}function ri({url:e,context:t,attribution:n}){if(!e)return null;let r=Qr(t);if(!r)return null;let i=new URL(e);return $(i.searchParams,Zr),i.searchParams.set(Zr,r),ni(i,n),i.toString()}function ii(e){let t=new URL(e);return $(t.searchParams,Zr),t.toString()}function ai({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?ii(n):ri({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const oi={compress:Qr,decompress:$r,parse:ei,update:ri,remove:ii,replaceUrl:ai},si={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function ci(e){return e&&e in si?e:`eur`}function li(e){return e?si[e]??si.eur:si.eur}function ui(e,t){let n=li(t),r=ci(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function di(e){return e.formatToParts(1.1).find(e=>e.type===`decimal`)?.value??`.`}function fi(e,t){let n=li(t),r=ci(t),i=new Intl.NumberFormat(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2}),a=i.formatToParts(e),o=``,s=``,c=``,l=`suffix`,u=!1;for(let e of a)switch(e.type){case`integer`:case`group`:o+=e.value,u=!0;break;case`decimal`:case`fraction`:s+=e.value;break;case`currency`:c=e.value,l=u?`suffix`:`prefix`}return{integer:o,decimals:s||`${di(i)}00`,unit:c,unitPosition:l}}function pi(e){return{integer:String(e),unit:`%`,unitPosition:`suffix`}}function mi(e){return e?`${e}Amount`:`eurAmount`}var hi=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)}},gi=class{constructor(e){this.groups=[],this.queue=[],this.options=e;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.3.1`,this.api=new hi({baseUrl:e.apiUrl||`https://api.openpanel.dev`,defaultHeaders:t})}init(){}ready(){this.options.disabled=!1,this.options.waitForProfile=!1,this.flush()}shouldQueue(e){return!!(this.options.disabled||this.options.waitForProfile&&!this.profileId||e.type===`replay`&&!this.sessionId)}addQueue(e){e.type===`track`&&(e.payload.properties={...e.payload.properties??{},__timestamp:new Date().toISOString()}),this.queue.push(e)}async send(e){if(this.options.filter&&!this.options.filter(e))return Promise.resolve();if(this.shouldQueue(e))return this.addQueue(e),Promise.resolve();let t=await this.api.fetch(`/track`,e,{keepalive:e.type!==`replay`});this.deviceId=t?.deviceId;let n=!!this.sessionId;return this.sessionId=t?.sessionId,!n&&this.sessionId&&this.flush(),t}setGlobalProperties(e){this.global={...this.global,...e}}track(e,t){this.log(`track event`,e,t);let{groups:n,profileId:r,...i}=t??{},a=[...new Set([...this.groups,...n??[]])];return this.send({type:`track`,payload:{name:e,profileId:r??this.profileId,groups:a.length>0?a:void 0,properties:{...this.global??{},...i}}})}identify(e){if(this.log(`identify user`,e),e.profileId&&(this.profileId=e.profileId,this.flush()),e.profileId&&Object.keys(e).length>1)return this.send({type:`identify`,payload:{...e,properties:{...this.global,...e.properties}}})}upsertGroup(e){return this.log(`upsert group`,e),this.send({type:`group`,payload:e})}setGroup(e){return this.log(`set group`,e),this.groups.includes(e)||(this.groups=[...this.groups,e]),this.send({type:`assign_group`,payload:{groupIds:[e],profileId:this.profileId}})}setGroups(e){return this.log(`set groups`,e),this.groups=[...new Set([...this.groups,...e])],this.send({type:`assign_group`,payload:{groupIds:e,profileId:this.profileId}})}alias(e){}increment(e){return this.send({type:`increment`,payload:e})}decrement(e){return this.send({type:`decrement`,payload:e})}revenue(e,t){let n=t?.deviceId;return delete t?.deviceId,this.track(`revenue`,{...t??{},...n?{__deviceId:n}:{},__revenue:e})}getDeviceId(){return this.deviceId??``}getSessionId(){return this.sessionId??``}fetchDeviceId(){return Promise.resolve(this.deviceId??``)}clear(){this.profileId=void 0,this.groups=[],this.deviceId=void 0,this.sessionId=void 0}buildFlushPayload(e){if(e.type===`replay`)return e.payload;if(e.type===`track`){let t=`groups`in e.payload?e.payload.groups??[]:[],n=[...new Set([...this.groups,...t])];return{...e.payload,profileId:e.payload.profileId??this.profileId,groups:n.length>0?n:void 0}}return e.type===`identify`||e.type===`increment`||e.type===`decrement`||e.type===`assign_group`?{...e.payload,profileId:e.payload.profileId??this.profileId}:e.payload}flush(){let e=[];for(let t of this.queue){if(this.shouldQueue(t)){e.push(t);continue}let n=this.buildFlushPayload(t);this.send({...t,payload:n})}this.queue=e}log(...e){this.options.debug&&console.log(`[OpenPanel.dev]`,...e)}},_i=typeof document<`u`?document.currentScript:null;function vi(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var yi=class extends gi{constructor(e){if(super({sdk:`web`,sdkVersion:`1.4.1`,...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=[]}if(this.setGlobalProperties({__referrer:document.referrer}),this.options.trackScreenViews&&(this.trackScreenViews(),setTimeout(()=>this.screenView(),0)),this.options.trackOutgoingLinks&&this.trackOutgoingLinks(),this.options.trackAttributes&&this.trackAttributes(),this.options.sessionReplay?.enabled){let e=this.options.sessionReplay.sampleRate??1;Math.random()<e&&this.loadReplayModule().then(e=>{e&&e.startReplayRecorder(this.options.sessionReplay,e=>{this.send({type:`replay`,payload:{...e}})})})}}}async loadReplayModule(){try{if(typeof __OPENPANEL_REPLAY_URL__<`u`){let e=_i,t=this.options.sessionReplay?.scriptUrl||e?.src?.replace(`.js`,`-replay.js`)||`https://openpanel.dev/op1-replay.js`;return window.__openpanel_replay?window.__openpanel_replay:new Promise(e=>{let n=document.createElement(`script`);n.src=t,n.onload=()=>{e(window.__openpanel_replay??null)},n.onerror=()=>{console.warn(`[OpenPanel] Failed to load replay script from`,t),e(null)},document.head.appendChild(n)})}return await import(`./replay-V6FXES7X.CgBxdfNp.js`)}catch(e){return console.warn(`[OpenPanel] Failed to load replay module`,e),null}}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[vi(t.name.replace(/^data-/,``))]=t.value);let t=i.getAttribute(`data-track`);t&&super.track(t,e)}})}track(e,t){return super.track(e,{...t,__path:this.lastPath})}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{}}};const bi=`nexus-wallet-backup`,xi=`frakwallet://`;function Si(e){let t=e?.split(`-`)[0]?.toLowerCase();return t===`en`||t===`fr`?t:void 0}function Ci(){return(typeof document<`u`?Si(document.documentElement.lang):void 0)||(typeof navigator<`u`?Si(navigator.language):void 0)}function wi(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`))}function Ti(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const Ei=xi.replace(`://`,``);function Di(e){return`intent://${e.slice(13)}#Intent;scheme=${Ei};end`}function Oi(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=Ti()&&ki(e)?Di(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function ki(e){return e.startsWith(xi)}function Ai(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent;return!!(/iPhone|iPad|iPod/i.test(e)||/Macintosh/i.test(e)&&navigator.maxTouchPoints>1)}const ji=Ai();function Mi(){return typeof navigator>`u`?!1:ji?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function Ni(){if(typeof navigator>`u`)return!1;let e=navigator.userAgent.toLowerCase();return e.includes(`instagram`)||e.includes(`fban`)||e.includes(`fbav`)||e.includes(`facebook`)}const Pi=Ni();function Fi(e){ji&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:ji&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`${G()}/common/social?u=${encodeURIComponent(e)}`}const Ii={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`}};async function Li({config:e}){let t=document.querySelector(`#frak-wallet`);t&&t.remove();let n=document.createElement(`iframe`);n.id=Ii.id,n.name=Ii.name,n.allow=Ii.allow,n.style.zIndex=Ii.style.zIndex.toString(),zi({iframe:n,isVisible:!1});let r=An(e?.env).wallet,i=await Cr().catch(e=>{console.warn(`[Frak SDK] Unable to derive a client id`,e)});return Vi(r),Vi(G()),n.src=Ri({walletUrl:r,clientId:i,preload:e?.preload}),new Promise(e=>{n.addEventListener(`load`,()=>e(n)),document.body.appendChild(n)})}function Ri({walletUrl:e=Mn(),clientId:t,preload:n}){let r=t?`${e}/listener?clientId=${encodeURIComponent(t)}`:`${e}/listener`;return!n||n.length===0?r:`${r}#preload=${n.join(`,`)}`}function zi({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 Bi(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 Vi(e){if(!(typeof document>`u`))try{let t=new URL(e).origin,n=`link[rel="preconnect"][data-frak-preconnect="${t}"]`;if(document.head.querySelector(n))return;let r=document.createElement(`link`);r.rel=`preconnect`,r.href=t,r.crossOrigin=``,r.dataset.frakPreconnect=t,document.head.appendChild(r)}catch{}}const Hi=ji&&Pi;function Ui(e){e?localStorage.setItem(bi,e):localStorage.removeItem(bi)}function Wi(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=qi(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function Gi(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 Ki(e){return e.includes(`/common/social`)}function qi(e,t){if(!t)return e;try{let n=new URL(e);return n.searchParams.set(`fmt`,t),n.toString()}catch{return`${e}${e.includes(`?`)?`&`:`?`}fmt=${encodeURIComponent(t)}`}}function Ji(e,t,n,r,i){if(i){let e=Wi(t,r);window.open(e,`_blank`);return}if(ki(t)){let i=Wi(t,r);Oi(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(Hi&&Ki(t))Gi(r);else{let e=Wi(t,r);window.location.href=e}}function Yi({iframe:e,targetOrigin:t}){let n=new bn;return{handleEvent:r=>{if(!(`iframeLifecycle`in r))return;let{iframeLifecycle:i,data:a}=r;switch(i){case`connected`:n.resolve(!0);break;case`do-backup`:Ui(a.backup);break;case`remove-backup`:localStorage.removeItem(bi);break;case`show`:case`hide`:zi({iframe:e,isVisible:i===`show`});break;case`redirect`:Ji(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab)}},isConnected:n.promise}}async function Xi({config:e,iframe:t}){let n=An(e?.env).wallet,r=e.metadata.lang??Ci(),i=e.domain??(typeof window<`u`?window.location.hostname:``);Y.setCacheScope(i,r),Y.reset();let a=Y.isCacheFresh?void 0:Y.resolve(e.domain,r),o=await Z().catch(()=>void 0),s=Yi({iframe:t,targetOrigin:n}),c=new bn,l=Date.now();if(!t.contentWindow)throw new yn(vn.configError,`The iframe does not have a content window`);let u=xn({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await s.isConnected)throw new yn(vn.clientNotConnected,`The iframe provider isn't connected yet`);return await c.promise,t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{s.handleEvent(e)}}}),d=Zi(u,s),f,p=!1,m=async()=>{p=!0,d(),f?.(),u.cleanup(),t.remove(),Fn(),Y.clearCache(),Y.reset()},h;{console.log(`[Frak SDK] Initializing OpenPanel`),h=new yi({apiUrl:`https://op-api.gcp.frak.id`,clientId:`6eacc8d7-49ac-4936-95e9-81ef29449570`,trackScreenViews:!0,trackOutgoingLinks:!0,trackAttributes:!1,filter:({type:e,payload:t})=>(e!==`track`||!t?.properties||`sdk_version`in t.properties||(t.properties={...t.properties,sdk_version:`1.3.0`,...o&&{user_anonymous_client_id:o}}),!0)}),h.setGlobalProperties({sdk_version:`1.3.0`,...o&&{user_anonymous_client_id:o}}),h.init(),h.track(`sdk_initialized`,{sdk_version:`1.3.0`});let e=!1,t=setTimeout(()=>{e||(e=!0,h?.track(`sdk_iframe_handshake_failed`,{reason:`timeout`}))},3e4);s.isConnected.then(()=>{e||(e=!0,clearTimeout(t),h?.track(`sdk_iframe_connected`,{handshake_duration_ms:Date.now()-l}))}).catch(()=>{e||(e=!0,clearTimeout(t),h?.track(`sdk_iframe_handshake_failed`,{reason:`unknown`}))})}let g=na({config:e,rpcClient:u,lifecycleManager:s,configPromise:a,contextSent:c,openPanel:h,clientId:o}).then(e=>{if(p){e();return}f=e}).catch(e=>{throw c.reject(e),e});return{config:e,waitForConnection:s.isConnected,waitForSetup:g,request:u.request,listenerRequest:u.listen,destroy:m,openPanel:h}}function Zi(e,t){let n,r,i=()=>e.sendLifecycle({clientLifecycle:`heartbeat`});async function a(){i(),n=setInterval(i,250),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}function Qi(e){return e.hasRawSdkConfig?{name:e.name,logoUrl:e.logoUrl,homepageLink:e.homepageLink,lang:e.lang,currency:e.currency,hidden:e.hidden,css:e.css,translations:e.translations,placements:e.placements,attribution:e.attribution}:e.attribution?{attribution:e.attribution}:void 0}function $i(e,t){if(!e)return;let n=e.global??{};e.setGlobalProperties({...n,merchant_id:t.merchantId,domain:t.domain??``})}async function ea(e){let t=new TextEncoder().encode(e);if(typeof crypto<`u`&&crypto.subtle)try{let e=await crypto.subtle.digest(`SHA-256`,t);return new Uint8Array(e)}catch{}try{return be(t)}catch{return}}async function ta({merchantId:e,anonymousId:t,pendingMergeToken:n}){let r=n?await ea(n):void 0,[i,a,o]=await Promise.all([r?X({op:`frak-merge-v1`,merchantId:e,anonymousId:t,binding:r}):Promise.resolve(null),X({op:`frak-merge-v1`,merchantId:e,anonymousId:t}),X({op:`frak-install-v1`,merchantId:e,anonymousId:t})]);if(!(!i&&!a&&!o))return{anonymousId:t,proofs:{...i&&{merge:i},...a&&{mergeSource:a},...o&&{install:o}}}}async function na({config:e,rpcClient:t,lifecycleManager:n,configPromise:r,contextSent:i,openPanel:a,clientId:o}){await n.isConnected,wi(t,n.isConnected);let s=new URL(window.location.href),c=s.searchParams.get(`fmt`)??void 0;c&&(s.searchParams.delete(`fmt`),window.history.replaceState({},``,s.toString()));let l=t=>{let n=t?.merchantId??e.metadata.merchantId??``,r=t?.domain??``,i=t?.allowedDomains??[],a=t?.sdkConfig,o=a?.attribution||e.attribution?{...e.attribution,...a?.attribution}:void 0;Y.setConfig(a?{isResolved:!0,merchantId:n,domain:r,allowedDomains:i,hasRawSdkConfig:!0,name:a.name??e.metadata.name,logoUrl:a.logoUrl??e.metadata.logoUrl,homepageLink:a.homepageLink??e.metadata.homepageLink,lang:a.lang??e.metadata.lang,currency:a.currency??e.metadata.currency,hidden:a.hidden,css:a.css,translations:a.translations,placements:a.placements,components:a.components,attribution:o}:{isResolved:!0,merchantId:n,domain:r,allowedDomains:i,name:e.metadata.name,logoUrl:e.metadata.logoUrl,homepageLink:e.metadata.homepageLink,lang:e.metadata.lang,currency:e.metadata.currency,attribution:o})},u=!1,d=Promise.resolve(),f=e=>{let n=u?void 0:c;u=!0;let r=Qi(e),i=o,s=window.location.href;return $i(a,e),d=d.then(async()=>{t.sendLifecycle({clientLifecycle:`resolved-config`,data:{merchantId:e.merchantId,domain:e.domain??``,allowedDomains:e.allowedDomains??[],sourceUrl:s,...i&&{sdkAnonymousId:i},...n&&{pendingMergeToken:n},...r&&{sdkConfig:r},...i&&{sdkIdentity:await ta({merchantId:e.merchantId,anonymousId:i,pendingMergeToken:n})}}})}).catch(e=>{console.error(`Failed to send lifecycle config`,e)}),d};Y.isResolved&&f(Y.getConfig()).then(i.resolve),r&&(l(await r),f(Y.getConfig()).then(i.resolve));async function p(){let n=e.customizations?.css;n&&t.sendLifecycle({clientLifecycle:`modal-css`,data:{cssLink:n}})}async function m(){let n=e.customizations?.i18n;n&&t.sendLifecycle({clientLifecycle:`modal-i18n`,data:{i18n:n}})}async function h(){if(typeof window>`u`)return;let e=window.localStorage.getItem(bi);e&&t.sendLifecycle({clientLifecycle:`restore-backup`,data:{backup:e}})}return(await Promise.allSettled([p(),m(),h()])).some(e=>e.status===`rejected`)&&a?.track(`sdk_iframe_handshake_failed`,{reason:`asset_push`}),ra(f)}function ra(e){if(typeof document>`u`)return()=>{};let t=0,n=n=>{if(document.visibilityState!==`visible`||!Y.isResolved)return;let r=Date.now();n&&r-t<6e4||(t=r,e(Y.getConfig()))},r=()=>n(!0),i=setInterval(()=>n(!1),3e5);return document.addEventListener(`visibilitychange`,r),()=>{clearInterval(i),document.removeEventListener(`visibilitychange`,r)}}function ia(e){return Cn(Er(e))}function aa(e){try{let t=new URL(e);return t.protocol===`http:`||t.protocol===`https:`}catch{return!1}}function oa(e){if(!e)return null;if(Array.isArray(e))return e;if(typeof e!=`string`)return null;try{let t=JSON.parse(e);return Array.isArray(t)?t:null}catch{return null}}function sa(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e==`string`&&e.trim()!==``){let t=Number.parseFloat(e);return Number.isFinite(t)?t:void 0}}function ca(e){if(typeof e!=`string`)return;let t=e.trim();return t===``?void 0:t}function la(e){if(!e||typeof e!=`object`)return;let t=e,n={},r=ca(t.productId);r!==void 0&&(n.productId=r);let i=ca(t.sku);i!==void 0&&(n.sku=i);let a=ca(t.name);a!==void 0&&(n.name=a);let o=sa(t.quantity);o!==void 0&&(n.quantity=o);let s=sa(t.unitPrice);s!==void 0&&(n.unitPrice=s);let c=sa(t.totalPrice);return c!==void 0&&(n.totalPrice=c),Object.keys(n).length>0?n:void 0}function ua(e){let t=oa(e);if(!t)return;let n=[];for(let e of t){let t=la(e);t&&n.push(t)}return n.length>0?n:void 0}function da(e){if(!e||typeof e!=`object`)return null;let t=e,n=typeof t.title==`string`?t.title.trim():``;if(n===``)return null;let r={title:n,...la(e)};return typeof t.imageUrl==`string`&&aa(t.imageUrl)&&(r.imageUrl=t.imageUrl),typeof t.link==`string`&&aa(t.link)&&(r.link=t.link),typeof t.utmContent==`string`&&t.utmContent!==``&&(r.utmContent=t.utmContent),r}function fa(e){let t=oa(e);if(!t)return;let n=[];for(let e of t){let t=da(e);t&&n.push(t)}return n.length>0?n:void 0}function pa(e){if(!e)return;let t;try{t=ia(e)}catch{return}if(t!==null)return fa(t)}async function ma({config:e}){let t=ha(e),n=await Li({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=await Xi({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function ha(e){let t=ci(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function ga({perCall:e,defaults:t,productUtmContent:n}){if(e===null)return;let r=e!==void 0,i=t!==void 0&&Object.keys(t).length>0;if(!r&&!i&&(n===void 0||n===``))return;let a={...t,...e??{}},o=n??e?.utmContent;return o!==void 0&&o!==``?a.utmContent=o:delete a.utmContent,a}var _a=t({DEEP_LINK_SCHEME:()=>xi,FrakContextManager:()=>oi,areAddressesEqual:()=>zr,base64urlDecode:()=>Er,base64urlEncode:()=>Tr,baseIframeProps:()=>Ii,buildListenerUrl:()=>Ri,clearAllCache:()=>Fn,coerceProductCandidates:()=>oa,compressJsonToB64:()=>Dr,createIFrameFrakClient:()=>Xi,decodeProductsParam:()=>pa,decompressJsonFromB64:()=>ia,deleteQueryParamCaseInsensitive:()=>$,detectPageLanguage:()=>Ci,findIframeInOpener:()=>Bi,formatAmount:()=>ui,formatAmountParts:()=>fi,generateSsoUrl:()=>Or,getBackendUrl:()=>G,getClientId:()=>wr,getClientIdAsync:()=>Z,getCurrencyAmountKey:()=>mi,getEnvironment:()=>jn,getQueryParamCaseInsensitive:()=>Ir,getSupportedCurrency:()=>ci,isIOS:()=>ji,isInAppBrowser:()=>Pi,isMobile:()=>Mi,mergeAttribution:()=>ga,normalizeProductDetails:()=>la,normalizeSharingProduct:()=>da,redirectToExternalBrowser:()=>Fi,sanitizeProductDetailsList:()=>ua,sanitizeSharingProducts:()=>fa,sdkConfigStore:()=>Y,setEnvironment:()=>An,setupClient:()=>ma,ssoPopupFeatures:()=>Mr,ssoPopupName:()=>Nr,trackEvent:()=>Q,triggerDeepLinkWithFallback:()=>Oi,withCache:()=>q});async function va(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function ya(e,{steps:t,metadata:n},r){return await e.request({method:`frak_displayModal`,params:r?[t,n,e.config.metadata,r]:[t,n,e.config.metadata]})}async function ba(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function xa(e){if(typeof window>`u`)return;let t=await Z().catch(()=>void 0);if(!t)return;let n=await Y.resolveMerchantId();if(!n)return;let r=`frak-identity-ensured-${n}-${t}`;if(!window.sessionStorage.getItem(r))try{let i=G(),a=await X({op:`frak-ensure-v1`,merchantId:n,anonymousId:t});(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,...gr()},body:JSON.stringify({merchantId:n,...a&&{proof:a}})})).ok&&window.sessionStorage.setItem(r,`1`)}catch{}}async function Sa(e,t){return q(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:t?.cacheTime})}async function Ca(e,t){return q(async()=>{let t=await Z().catch(()=>void 0),n=await Y.resolveMerchantId(),r=t&&n?await X({op:`frak-merge-v1`,merchantId:n,anonymousId:t}):null;return e.request({method:`frak_getMergeToken`,params:r?[r]:void 0})},{cacheKey:`frak_getMergeToken`,cacheTime:t?.cacheTime})}async function wa(e,t){return q(()=>e.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:t?.cacheTime})}async function Ta(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function Ea(e,t){try{let n=await Z().catch(()=>void 0);await e.request({method:`frak_sendInteraction`,params:[t,{clientId:n}]})}catch{console.warn(`[Frak SDK] Failed to send interaction:`,t.type)}}function Da(e,t,n){return Wr(t)?(Q(e,`user_referred_started`,{referrer_client_id:t.c,referrer_wallet:t.w,wallet_status:n?.key}),Ea(e,{type:`arrival`,referrerClientId:t.c,referrerMerchantId:t.m,referrerWallet:t.w,referralTimestamp:t.t}),!0):Ur(t)?(Q(e,`user_referred_started`,{referrer:t.r,wallet_status:n?.key}),Ea(e,{type:`arrival`,referrerWallet:t.r}),!0):!1}function Oa(e,t,n){return!t&&!n?null:{v:2,m:e,t:Math.floor(Date.now()/1e3),...t?{c:t}:{},...n?{w:n}:{}}}function ka(e,t,n){return Wr(e)?e.w&&n?.wallet?zr(e.w,n.wallet):e.c?t===e.c:!1:Ur(e)&&n?.wallet?zr(e.r,n.wallet):!1}async function Aa(e,{walletStatus:t,frakContext:n,options:r}){if(!n)return`no-referrer`;let i=await Z().catch(()=>void 0);if(ka(n,i,t))return`self-referral`;if(!Da(e,n,t))return`no-referrer`;let a=Wr(n)?n.m:r?.merchantId,o=r?.alwaysAppendUrl&&a?Oa(a,i,t?.wallet):null;return oi.replaceUrl({url:window.location?.href,context:o}),Q(e,`user_referred_completed`,{status:`success`}),`success`}async function ja(e,{options:t}={}){let n=oi.parse({url:window.location.href}),r=await Fa(e);try{return await Aa(e,{walletStatus:r,frakContext:n,options:t})}catch(e){console.warn(`Error processing referral`,{error:e})}}const Ma=`frak:referral-success`;async function Na(e){try{await ja(e)===`success`&&window.dispatchEvent(new Event(Ma))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function Pa(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=await Z().catch(()=>void 0);if(!t&&!n){console.warn(`[Frak] No identity found, skipping purchase check`);return}let r=e.merchantId??await Y.resolveMerchantId();if(!r){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let i={Accept:`application/json`,"Content-Type":`application/json`};t&&(i[`x-wallet-sdk-auth`]=t),n&&(i[`x-frak-client-id`]=n);let a=G();await fetch(`${a}/user/track/purchase`,{method:`POST`,headers:i,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:r})})}function Fa(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(Ia(e,t),t));let n=new bn,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{Ia(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function Ia(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),xa(t.interactionToken)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function La(e,{metadata:t,login:n}){return Ra(e,{steps:{login:n??{}},metadata:t})}function Ra(e,t){function n(n){return Ra(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return Ra(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return Ra(e,{...t,steps:{...t.steps,final:{...r,action:{key:`sharing`,options:n}}}})}async function a(n,r){return n&&(t.metadata=n(t.metadata??{})),await ya(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function za(e,{tx:t,metadata:n}){return(await ya(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function Ba(e=96){let t=Math.ceil(e/2),n=``;if(typeof crypto<`u`&&crypto.getRandomValues){let e=new Uint8Array(t);crypto.getRandomValues(e);for(let t=0;t<e.length;t++)n+=e[t].toString(16).padStart(2,`0`)}else for(let e=0;e<t;e++)n+=(Math.random()*256|0).toString(16).padStart(2,`0`);return n.substring(0,e)}async function Va(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 ya(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??Ba(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}var Ha=t({REFERRAL_SUCCESS_EVENT:()=>Ma,displayEmbeddedWallet:()=>va,displayModal:()=>ya,displaySharingPage:()=>ba,ensureIdentity:()=>xa,getMerchantInformation:()=>Sa,getMergeToken:()=>Ca,getUserReferralStatus:()=>wa,modalBuilder:()=>La,openSso:()=>Pr,prepareSso:()=>Ta,prepareSsoUrl:()=>jr,processReferral:()=>Aa,referralInteraction:()=>ja,sendInteraction:()=>Ea,sendTransaction:()=>za,setupReferral:()=>Na,siweAuthenticate:()=>Va,trackPurchaseStatus:()=>Pa,watchWalletStatus:()=>Fa});async function Ua(e,t,n){if(!window.FrakSetup?.client){console.error(`Frak client not found`);return}await ba(window.FrakSetup.client,{...n?.link&&{link:n.link},...n?.products?.length&&{products:n.products},...n?.checkoutToken&&{checkoutToken:n.checkoutToken},...e&&{metadata:{targetInteraction:e}}},t)}const Wa=[`frak-button-share`,`frak-button-wallet`,`frak-open-in-app`,`frak-post-purchase`,`frak-banner`].join(`,`);function Ga(){return typeof document>`u`||document.querySelector(Wa)===null?[]:[`sharing`]}const Ka=`frak:client`;function qa(){let e=new CustomEvent(Ka);window.dispatchEvent(e)}function Ja(e,t){if(window.FrakSetup?.client&&e===`add`){t();return}(e===`add`?window.addEventListener:window.removeEventListener)(Ka,t,!1)}function Ya(){return window.FrakSetup.core={..._a,...Ha},window.FrakSetup?.client?Promise.resolve():q(()=>Xa(),{cacheKey:`frak-sdk-init`,cacheTime:1/0}).catch(e=>{Q(window.FrakSetup?.client,`sdk_init_failed`,{reason:e instanceof Error?e.message:typeof e==`string`?e:`unknown`,config_missing:!window.FrakSetup?.config})})}async function Xa(){if(!window.FrakSetup?.config)throw Error(`[Frak SDK] Configuration not found. Please ensure window.FrakSetup.config is set.`);console.log(`[Frak SDK] Starting initialization`);let e=await ma({config:Za(window.FrakSetup.config)});if(!e)throw Error(`[Frak SDK] Failed to create client`);window.FrakSetup.client=e,console.log(`[Frak SDK] Client initialized successfully`),qa(),Na(e),Qa()}function Za(e){return e.preload===void 0?{...e,preload:Ga()}:e}function Qa(){let e=new URL(window.location.href);if(Ir(e.searchParams,`frakAction`)?.toLowerCase()!==`share`)return;console.log(`[Frak SDK] Auto open share via query param`);let t=Ir(e.searchParams,`link`)??void 0,n=Ir(e.searchParams,`placement`)??void 0,r=pa(Ir(e.searchParams,`products`));$(e.searchParams,`frakAction`),$(e.searchParams,`link`),$(e.searchParams,`placement`),$(e.searchParams,`products`),window.history.replaceState({},``,e.toString()),Ua(void 0,n,{link:t,products:r})}o.injectBase(`shared`,n),o.injectBase(`fouce`,`frak-button-share:not(:defined), frak-button-wallet:not(:defined), frak-open-in-app:not(:defined), frak-post-purchase:not(:defined), frak-banner:not(:defined) { display: none !important; }`),s(Ya);const $a={"button-share":()=>import(`./ButtonShare.DIyDUgaT.js`),"button-wallet":()=>import(`./ButtonWallet.DNxaFMHH.js`),"open-in-app":()=>import(`./OpenInAppButton.X1noMnvq.js`),"post-purchase":()=>import(`./PostPurchase._SYhdjOf.js`),banner:()=>import(`./Banner.wHYQSyz3.js`)},eo=new MutationObserver(e=>{for(let{addedNodes:t}of e)for(let e of Array.from(t))e.nodeType===Node.ELEMENT_NODE&&to(e)});async function to(e){let t=e instanceof Element?e.tagName.toLowerCase():``,n=t?.startsWith(`frak-`),r=Array.from(e.querySelectorAll(`:not(:defined)`)).map(e=>e.tagName.toLowerCase()).filter(e=>e.startsWith(`frak-`));n&&!customElements.get(t)&&r.push(t);let i=[...new Set(r)];await Promise.allSettled(i.map(e=>no(e)))}async function no(e){if(customElements.get(e))return Promise.resolve();try{let t=e.replace(/^frak-/i,``);if(!(t in $a))throw Error(`Component ${e} is not supported.`);await $a[t]()}catch(e){console.error(e)}}to(document.body),eo.observe(document.documentElement,{subtree:!0,childList:!0});export{Q as C,s as D,yn as E,o as O,ci as S,vn as T,xi as _,Pa as a,ui as b,Sa as c,Oi as d,Ci as f,Mi as g,Fi as h,Ma as i,n as k,wa as l,ua as m,Ja as n,Ca as o,Pi as p,Ua as r,va as s,Ya as t,fa as u,fi as v,Y as w,mi as x,pi as y};
@@ -0,0 +1 @@
1
+ import{S as e,b as t,v as n,x as r,y as i}from"./loader.js";function a(e){return Array.isArray(e)?e:e.conditions}function o(e){if(typeof e==`number`)return e;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function s(e,t,n){let r=[];for(let i of a(e)){if(`logic`in i){r.push(...s(i,t,n));continue}if(i.field===t&&n.has(i.operator)){let e=o(i.value);e!=null&&r.push(e)}}return r}const c=new Set([`gt`,`gte`,`between`]),l=new Set([`gt`,`gte`]);function u(e){let t=s(e,`purchase.amount`,c);return t.length>0?Math.min(...t):void 0}function d(e){let t=s(e,`time.timestamp`,l);if(t.length!==0)return new Date(Math.min(...t)*1e3)}function f(e,t){switch(e.payoutType){case`fixed`:return e.amount[t];case`percentage`:return e.maxAmount?.[t]??0;case`tiered`:return e.tiers.reduce((e,n)=>`amount`in n?Math.max(e,n.amount[t]):e,0)}}function p(e){return e.payoutType===`percentage`?e.percent:e.payoutType===`tiered`?e.tiers.reduce((e,t)=>`percent`in t?Math.max(e,t.percent):e,0):0}function m(e,t){let n=f(e,t);return n>0?n:p(e)*1e-6}function h(n,i){let a=e(i),o=r(a);switch(n.payoutType){case`fixed`:return t(Math.round(n.amount[o]),a);case`percentage`:return`${n.percent} %`;case`tiered`:{let e=f(n,o);if(e>0)return t(Math.round(e),a);let r=p(n);return r>0?`${r} %`:t(0,a)}}}function g(t,a){let o=e(a),s=r(o);switch(t.payoutType){case`fixed`:return n(Math.round(t.amount[s]),o);case`percentage`:return i(t.percent);case`tiered`:{let e=f(t,s);if(e>0)return n(Math.round(e),o);let r=p(t);return r>0?i(r):n(0,o)}}}function _(t,n){if(!(!t||m(t,r(e(n)))<=0))return h(t,n)}function v(e,t){return t?e.replaceAll(`{REWARD}`,t):e.replaceAll(`{REWARD}`,``)}const y=new Set([`eq`,`neq`,`gt`,`gte`,`lt`,`lte`,`between`]),b=new Set([`contains`,`starts_with`,`ends_with`]);function x(e){return`logic`in e&&`conditions`in e}function S(e,t){return e[t]}function C(e){if(typeof e==`number`)return Number.isFinite(e)?e:void 0;if(typeof e==`string`&&e.trim()!==``){let t=Number(e);return Number.isFinite(t)?t:void 0}}function w(e,t){let n=C(e),r=C(t);return n!==void 0&&r!==void 0?n-r:String(e).localeCompare(String(t))}function T(e,t,n){if(!Array.isArray(n))return e===`not_in`;if(t===void 0)return;let r=n.includes(t);return e===`in`?r:!r}function E(e,t,n,r){switch(e){case`eq`:return t===n;case`neq`:return t!==n;case`gt`:return w(t,n)>0;case`gte`:return w(t,n)>=0;case`lt`:return w(t,n)<0;case`lte`:return w(t,n)<=0;case`between`:return r==null||Array.isArray(r)?void 0:w(t,n)>=0&&w(t,r)<=0}}function D(e,t,n){if(typeof t==`string`&&typeof n==`string`)return e===`contains`?t.includes(n):e===`starts_with`?t.startsWith(n):t.endsWith(n)}function O(e,t){let n=S(t,e.field),{operator:r,value:i,valueTo:a}=e;if(r===`exists`)return n!==void 0;if(r===`not_exists`)return n===void 0;if(r===`in`||r===`not_in`)return T(r,n,i);if(!(Array.isArray(i)||n===void 0||i===null)){if(y.has(r))return E(r,n,i,a);if(b.has(r))return D(r,n,i)}}function k(e,t){if(x(e)){let n=e.conditions.map(e=>k(e,t));return e.logic===`all`?n.every(Boolean):e.logic===`any`?n.some(Boolean):e.logic!==`none`||!n.some(Boolean)}return O(e,t)??!0}function A(e,t){return e?Array.isArray(e)?e.every(e=>k(e,t)):k(e,t):!0}function j(e,t){return e.expiresAt!=null&&new Date(e.expiresAt).getTime()<=t}function M(e,t){let n=d(e.conditions);return n==null||n.getTime()<=t}function N(e,t){return t===`referee`?e.referee:e.referrer}function P(e,t,n){let r=N(e,n);return r?m(r,t):0}function F(e,t){if(!t||t.length===0||!e.productScope)return;let n=t.filter(t=>A(e.productScope,t));return n.length>0?n:void 0}function I(e,t){return!t||t.length===0||!e.productScope||t.some(t=>A(e.productScope,t))}function L(t,n={}){let i=(n.now??new Date).getTime(),a=n.audience??`referrer`,o=r(e(n.currency)),s=(n.targetInteraction?t.filter(e=>e.interactionTypeKey===n.targetInteraction):t).filter(e=>!j(e,i)),c=s.filter(e=>M(e,i));if(c.length>0){let e=c.reduce((e,t)=>{let r=I(e,n.products),i=I(t,n.products);return r===i?P(t,o,a)>P(e,o,a)?t:e:i?t:e});return{campaign:e,status:`live`,matchedProducts:F(e,n.products)}}let l=s.map(e=>({campaign:e,startsAt:d(e.conditions)})).filter(e=>e.startsAt!=null);if(l.length===0)return;let u=l.reduce((e,t)=>{let r=I(e.campaign,n.products),i=I(t.campaign,n.products);return r===i?t.startsAt.getTime()<e.startsAt.getTime()?t:e:i?t:e});return{campaign:u.campaign,status:`upcoming`,startsAt:u.startsAt,matchedProducts:F(u.campaign,n.products)}}function R(e,n={}){let r=L(e,n);if(!r)return;let i=N(r.campaign,n.audience??`referrer`);if(!i)return;let a=_(i,n.currency);if(!a)return;let o=u(r.campaign.conditions),s=o==null?void 0:t(o,n.currency),c=r.campaign.defaultLockupSeconds,l=c&&c>0?Math.round(c/86400):void 0;return{formatted:a,parts:g(i,n.currency),payoutType:i.payoutType,minPurchaseAmount:s,lockupDurationDays:l,referrerReward:r.campaign.referrer,refereeReward:r.campaign.referee,minPurchaseValue:o??void 0,isProductScoped:r.campaign.productScope!=null,matchedProducts:r.matchedProducts}}export{v as i,L as n,R as r,_ as t};
@@ -0,0 +1 @@
1
+ import{w as e}from"./loader.js";import{c as t,o as n}from"./defaults.CT8FNvot.js";function r(){return t(n,()=>e.getConfig().components)}export{r as t};
@@ -1 +1 @@
1
- import{O as e}from"./loader.js";import{f as t,i as n}from"./defaults.BEvoSiy5.js";function r(r,i,a,o,s){t(()=>{s&&e.injectBase(`shared`,s),e.injectBase(r,o??n)},[r]),t(()=>{!i||!a||e.injectPlacement(r,i,a)},[r,i,a])}export{r as t};
1
+ import{O as e}from"./loader.js";import{f as t,i as n}from"./defaults.CT8FNvot.js";function r(r,i,a,o,s){t(()=>{s&&e.injectBase(`shared`,s),e.injectBase(r,o??n)},[r]),t(()=>{!i||!a||e.injectPlacement(r,i,a)},[r,i,a])}export{r as t};
@@ -1 +1 @@
1
- import{l as e}from"./loader.js";import{d as t,f as n}from"./defaults.BEvoSiy5.js";import{r}from"./rewards.B2smvfIs.js";function i(i,a,o,s){let[c,l]=t(void 0);return n(()=>{if(!i)return;let t=window.FrakSetup?.client;t&&e(t).then(e=>{let n=r(e.rewards,{currency:t.config.metadata?.currency,targetInteraction:a,audience:o,products:s});n&&n.payoutType!==`percentage`&&l(n.formatted)}).catch(()=>{})},[i,a,o,s]),{reward:c}}export{i as t};
1
+ import{c as e}from"./loader.js";import{d as t,f as n}from"./defaults.CT8FNvot.js";import{r}from"./rewards.D3nh4aTd.js";function i(i,a,o,s){let[c,l]=t(void 0);return n(()=>{if(!i)return;let t=window.FrakSetup?.client;t&&e(t).then(e=>{let n=r(e.rewards,{currency:t.config.metadata?.currency,targetInteraction:a,audience:o,products:s});n&&n.payoutType!==`percentage`&&l(n.formatted)}).catch(()=>{})},[i,a,o,s]),{reward:c}}export{i as t};
@@ -1,7 +1,7 @@
1
1
  import "preact/hooks";
2
2
  import { jsx, jsxs } from "preact/jsx-runtime";
3
3
  import { Component, Fragment as Fragment$1, createElement, options, toChildArray } from "preact";
4
- //#region ../../node_modules/.bun/preact@10.29.7/node_modules/preact/compat/dist/compat.module.js
4
+ //#region ../../node_modules/.bun/preact@10.29.8/node_modules/preact/compat/dist/compat.module.js
5
5
  function g(n, t) {
6
6
  for (var e in t) n[e] = t[e];
7
7
  return n;
@@ -59,12 +59,12 @@ options.unmount = function(n) {
59
59
  var e = t.__c, r = this;
60
60
  r.o ??= [], r.o.push(e);
61
61
  var u = j(r.__v), o = !1, i = function() {
62
- o || r.__z || (o = !0, e.__R = null, u ? u(c) : c());
62
+ o || r.__z || (o = !0, e.__R = null, u ? u(f) : f());
63
63
  };
64
64
  e.__R = i;
65
65
  var l = e.__P;
66
66
  e.__P = null;
67
- var c = function() {
67
+ var f = function() {
68
68
  if (!--r.__u) {
69
69
  if (r.state.__a) {
70
70
  var n = r.state.__a;
@@ -167,8 +167,8 @@ options.vnode = function(n) {
167
167
  for (var i in t) {
168
168
  var l = t[i];
169
169
  if (!("value" === i && "defaultValue" in t && null == l || Q && "children" === i && "noscript" === e || "class" === i || "className" === i)) {
170
- var c = i.toLowerCase();
171
- "defaultValue" === i && "value" in t && null == t.value ? i = "value" : "download" === i && !0 === l ? l = "" : "translate" === c && "no" === l ? l = !1 : "o" === c[0] && "n" === c[1] ? "ondoubleclick" === c ? i = "ondblclick" : "onchange" !== c || "input" !== e && "textarea" !== e || X(t.type) ? "onfocus" === c ? i = "onfocusin" : "onblur" === c ? i = "onfocusout" : J.test(i) && (i = c) : c = i = "oninput" : o && G.test(i) ? i = i.replace(K, "-$&").toLowerCase() : null === l && (l = void 0), "oninput" === c && u[i = c] && (i = "oninputCapture"), u[i] = l;
170
+ var f = i.toLowerCase();
171
+ "defaultValue" === i && "value" in t && null == t.value ? i = "value" : "download" === i && !0 === l ? l = "" : "translate" === f && "no" === l ? l = !1 : "o" === f[0] && "n" === f[1] ? "ondoubleclick" === f ? i = "ondblclick" : "onchange" !== f || "input" !== e && "textarea" !== e || X(t.type) ? "onfocus" === f ? i = "onfocusin" : "onblur" === f ? i = "onfocusout" : J.test(i) && (i = f) : f = i = "oninput" : o && G.test(i) ? i = i.replace(K, "-$&").toLowerCase() : null === l && (l = void 0), "oninput" === f && u[i = f] && (i = "oninputCapture"), u[i] = l;
172
172
  }
173
173
  }
174
174
  "select" == e && (u.multiple && Array.isArray(u.value) && (u.value = toChildArray(t.children).forEach(function(n) {
@@ -182,9 +182,9 @@ var ln = options.__r;
182
182
  options.__r = function(n) {
183
183
  ln && ln(n), n.__c;
184
184
  };
185
- var cn = options.diffed;
185
+ var fn = options.diffed;
186
186
  options.diffed = function(n) {
187
- cn && cn(n);
187
+ fn && fn(n);
188
188
  var t = n.props, e = n.__e;
189
189
  null != e && "textarea" === n.type && "value" in t && t.value !== e.value && (e.value = null == t.value ? "" : t.value);
190
190
  };
package/dist/banner.js CHANGED
@@ -1,10 +1,10 @@
1
- import { i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-Bpo25qjA.js";
2
- import { t as useGlobalComponents } from "./useGlobalComponents-CeTO2xYs.js";
3
- import { t as useLightDomStyles } from "./useLightDomStyles-B2U96tzU.js";
4
- import { i as w } from "./rewards-Cxn-bgzC.js";
5
- import { t as useReward } from "./useReward-BMYSGY-o.js";
1
+ import { i as useLang, o as useClientReady, s as registerWebComponent, t as usePlacement } from "./usePlacement-DtwWaLHO.js";
2
+ import { t as useGlobalComponents } from "./useGlobalComponents-DFv33ujB.js";
3
+ import { t as useLightDomStyles } from "./useLightDomStyles-B_IbOqJZ.js";
4
+ import { i as w } from "./rewards-CZkWSndn.js";
5
+ import { t as useReward } from "./useReward-D5zzFR11.js";
6
6
  import { componentDefaults } from "./i18n/defaults.js";
7
- import { a as ExternalLinkIcon, i as LogoFrakWithName, n as cssSource$5, o as CloseCircleIcon, r as WarningIcon, t as GiftIcon } from "./GiftIcon-BhL0bhVu.js";
7
+ import { a as ExternalLinkIcon, i as LogoFrakWithName, n as cssSource$5, o as CloseCircleIcon, r as WarningIcon, t as GiftIcon } from "./GiftIcon-DI0rUKHp.js";
8
8
  import { isInAppBrowser, redirectToExternalBrowser, sanitizeProductDetailsList, trackEvent } from "@frak-labs/core-sdk";
9
9
  import { REFERRAL_SUCCESS_EVENT, getMergeToken } from "@frak-labs/core-sdk/actions";
10
10
  import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";