@frak-labs/components 1.0.12 → 1.0.13-beta.349e6102
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cdn/Banner.CPfY5JKI.js +183 -0
- package/cdn/ButtonShare.DMwS3SV_.js +1 -0
- package/cdn/ButtonWallet.BCkfhtjS.js +40 -0
- package/cdn/{GiftIcon.DT1i36Fm.js → GiftIcon.S_PCRRWc.js} +1 -1
- package/cdn/OpenInAppButton.CzfepCTf.js +1 -0
- package/cdn/PostPurchase.C5s1IFlL.js +89 -0
- package/cdn/actions-C2MhMidX.DwPAFQBK.js +1 -0
- package/cdn/clientReady.CnuMZs-Q.js +11 -0
- package/cdn/components.js +1 -1
- package/cdn/defaults.8QO14l_n.js +58 -0
- package/cdn/embeddedWallet.GFBOECmv.js +1 -0
- package/cdn/loader.js +1 -154
- package/cdn/replay-V6FXES7X.CgBxdfNp.js +1 -0
- package/cdn/rewards.C5fLEHQ9.js +1 -0
- package/cdn/sharedBaseCss.css.BDzFcWnD.js +154 -0
- package/cdn/sharingPage.yTFaTklh.js +1 -0
- package/cdn/sharingPageProducts.DwoFd3Rz.js +1 -0
- package/cdn/styleManager.Cun1-fKi.js +1 -0
- package/cdn/useGlobalComponents.Chb50YVY.js +1 -0
- package/cdn/useLightDomStyles.w1gAoBeL.js +1 -0
- package/cdn/useReward.D4ldCSt1.js +1 -0
- package/dist/{GiftIcon-BEzYdiux.js → GiftIcon-BhL0bhVu.js} +10 -4
- package/dist/banner.d.ts +1 -16
- package/dist/banner.js +24 -8
- package/dist/buttonShare.d.ts +3 -11
- package/dist/buttonShare.js +6 -6
- package/dist/buttonWallet.d.ts +1 -7
- package/dist/buttonWallet.js +3 -3
- package/dist/i18n/defaults.d.ts +3 -2
- package/dist/i18n/defaults.js +5 -5
- package/dist/openInApp.d.ts +1 -5
- package/dist/openInApp.js +2 -2
- package/dist/postPurchase.d.ts +1 -19
- package/dist/postPurchase.js +5 -5
- package/dist/{rewards-VoZGH2Ko.js → rewards-BtPHdGcI.js} +4 -3
- package/dist/{useGlobalComponents-CZ7Sh2tZ.js → useGlobalComponents-Da9LDlRy.js} +1 -1
- package/dist/{useLightDomStyles-DphuQhvx.js → useLightDomStyles-DRkTVy4s.js} +1 -1
- package/dist/{usePlacement-4PoDbn2X.js → usePlacement-NZOjZ6IR.js} +6 -14
- package/dist/{useReward-BGgymGoH.js → useReward-B-yZ7nhY.js} +1 -1
- package/package.json +21 -20
- package/cdn/Banner.CgCiMrqn.js +0 -167
- package/cdn/ButtonShare.BiOpzkRY.js +0 -1
- package/cdn/ButtonWallet.Mmrku6ws.js +0 -40
- package/cdn/OpenInAppButton.D1UzTuHx.js +0 -1
- package/cdn/PostPurchase.Cvx1TI64.js +0 -89
- package/cdn/defaults.kWEdCyGS.js +0 -58
- package/cdn/embeddedWallet.BS-9u4Be.js +0 -1
- package/cdn/replay-V6FXES7X.BoL9fAjx.js +0 -1
- package/cdn/rewards.CIu9qbmI.js +0 -1
- package/cdn/useGlobalComponents.BC6Jgzg5.js +0 -1
- package/cdn/useLightDomStyles.imPXuAtf.js +0 -1
- package/cdn/useReward.BAmvPaVu.js +0 -1
- /package/dist/{embeddedWallet-By3_p5Xc.js → embeddedWallet-CxgyuwtP.js} +0 -0
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import{t as e}from"./sharedBaseCss.css.BDzFcWnD.js";import{B as t,g as n,o as r}from"./clientReady.CnuMZs-Q.js";import{c as i,f as a}from"./actions-C2MhMidX.DwPAFQBK.js";import{a as o,d as s,f as c,l,m as u,n as d,p as f,s as p,t as m,u as ee}from"./defaults.8QO14l_n.js";import{a as h,i as g,n as _,r as v,t as y}from"./GiftIcon.S_PCRRWc.js";import{t as b}from"./useGlobalComponents.Chb50YVY.js";import{t as x}from"./useLightDomStyles.w1gAoBeL.js";import{r as S}from"./rewards.C5fLEHQ9.js";import{t as C}from"./useReward.D4ldCSt1.js";var w=`inAppBanner_body__1ibpiy74`,T=`inAppBanner_closeButton__1ibpiy77`,E=`inAppBanner_container__1ibpiy70`,D=`inAppBanner_cta__1ibpiy76`,O=`inAppBanner_description__1ibpiy75`,k=`inAppBanner_header__1ibpiy71`,A=`inAppBanner_iconWrapper__1ibpiy72`,j=`inAppBanner_title__1ibpiy73`;function te({title:e,description:t,cta:n,dismissLabel:r,onAction:i,onDismiss:a,className:o,classNames:s}){return u(`div`,{className:`${E}${o?` ${o}`:``}`,role:`alert`,children:[u(`div`,{className:k,children:[u(`span`,{className:`${A}${s?.icon?` ${s.icon}`:``}`,children:u(_,{width:20,height:20})}),u(`p`,{className:`${j}${s?.title?` ${s.title}`:``}`,children:e})]}),u(`div`,{className:w,children:[u(`p`,{className:`${O}${s?.description?` ${s.description}`:``}`,children:t}),u(`button`,{type:`button`,className:`${D}${s?.cta?` ${s.cta}`:``}`,onClick:i,children:[n,u(g,{width:14,height:14})]})]}),u(`button`,{type:`button`,className:`${T}${s?.close?` ${s.close}`:``}`,onClick:a,"aria-label":r,children:u(h,{width:16,height:16})})]})}var ne=`Banner_frakLogo__1gnumzi9`,re=`Banner_iconSvg__1gnumzi1`,ie=`Banner_referral__1gnumzi2 reset_base__1831jhd0 Banner_rootBase__1gnumzi0`,ae=`Banner_referralBody__1gnumzi5`,oe=`Banner_referralCta__1gnumzi8 sharedBaseCss_buttonReset__7cswil0`,se=`Banner_referralDescription__1gnumzi7 reset_base__1831jhd0`,ce=`Banner_referralIconWrapper__1gnumzi3`,le=`Banner_referralImage__1gnumzi4`,ue=`Banner_referralTitle__1gnumzi6 reset_base__1831jhd0`;function M({placement:h,classname:g=``,interaction:_,referralTitle:w,referralDescription:T,referralCta:E,inappTitle:D,inappDescription:O,inappCta:k,imageUrl:A,preview:j,previewMode:M,allowInappRedirect:N}){let P=!!j,F=o(),I=M===`inapp`?`inapp`:`referral`,L=N===!0||N===`true`,R=d(h),{shouldRender:z,isHidden:B,isClientReady:V}=p();x(`frak-banner`,h,R?.components?.banner?.css,`@keyframes keyframes_fadeIn__mnqmlt0 {
|
|
2
|
+
from {
|
|
3
|
+
opacity: 0;
|
|
4
|
+
}
|
|
5
|
+
to {
|
|
6
|
+
opacity: 1;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
@keyframes keyframes_fadeOut__mnqmlt1 {
|
|
10
|
+
from {
|
|
11
|
+
opacity: 1;
|
|
12
|
+
}
|
|
13
|
+
to {
|
|
14
|
+
opacity: 0;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
@keyframes keyframes_fadeInDown__mnqmlt2 {
|
|
18
|
+
from {
|
|
19
|
+
opacity: 0;
|
|
20
|
+
transform: translateY(-4px);
|
|
21
|
+
}
|
|
22
|
+
to {
|
|
23
|
+
opacity: 1;
|
|
24
|
+
transform: translateY(0);
|
|
25
|
+
}
|
|
26
|
+
}.inAppBanner_container__1ibpiy70 {
|
|
27
|
+
position: fixed;
|
|
28
|
+
top: max(8px, env(safe-area-inset-top));
|
|
29
|
+
left: 16px;
|
|
30
|
+
right: 16px;
|
|
31
|
+
z-index: 1000;
|
|
32
|
+
display: flex;
|
|
33
|
+
flex-direction: column;
|
|
34
|
+
gap: 4px;
|
|
35
|
+
padding: 12px 16px;
|
|
36
|
+
padding-right: 32px;
|
|
37
|
+
border-radius: 12px;
|
|
38
|
+
background-color: #000000cc;
|
|
39
|
+
backdrop-filter: blur(12px);
|
|
40
|
+
-webkit-backdrop-filter: blur(12px);
|
|
41
|
+
color: var(--text-onAction__pbq4ak6);
|
|
42
|
+
animation: keyframes_fadeInDown__mnqmlt2 300ms ease-out;
|
|
43
|
+
}
|
|
44
|
+
.inAppBanner_header__1ibpiy71 {
|
|
45
|
+
display: flex;
|
|
46
|
+
align-items: center;
|
|
47
|
+
gap: 8px;
|
|
48
|
+
}
|
|
49
|
+
.inAppBanner_iconWrapper__1ibpiy72 {
|
|
50
|
+
flex-shrink: 0;
|
|
51
|
+
width: 20px;
|
|
52
|
+
height: 20px;
|
|
53
|
+
display: flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
justify-content: center;
|
|
56
|
+
color: var(--text-onAction__pbq4ak6);
|
|
57
|
+
}
|
|
58
|
+
.inAppBanner_title__1ibpiy73 {
|
|
59
|
+
margin: 0;
|
|
60
|
+
padding: 0;
|
|
61
|
+
font-size: 16px;
|
|
62
|
+
font-weight: 500;
|
|
63
|
+
line-height: 26px;
|
|
64
|
+
color: var(--text-onAction__pbq4ak6);
|
|
65
|
+
}
|
|
66
|
+
.inAppBanner_body__1ibpiy74 {
|
|
67
|
+
display: flex;
|
|
68
|
+
flex-wrap: wrap;
|
|
69
|
+
align-items: baseline;
|
|
70
|
+
gap: 0 4px;
|
|
71
|
+
}
|
|
72
|
+
.inAppBanner_description__1ibpiy75 {
|
|
73
|
+
margin: 0;
|
|
74
|
+
padding: 0;
|
|
75
|
+
font-size: 14px;
|
|
76
|
+
color: var(--text-onAction__pbq4ak6);
|
|
77
|
+
line-height: 22px;
|
|
78
|
+
opacity: 0.96;
|
|
79
|
+
}
|
|
80
|
+
.inAppBanner_cta__1ibpiy76 {
|
|
81
|
+
all: unset;
|
|
82
|
+
display: inline-flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
gap: 4px;
|
|
85
|
+
color: #2bb2ff;
|
|
86
|
+
font-size: 14px;
|
|
87
|
+
font-weight: 600;
|
|
88
|
+
text-decoration: underline;
|
|
89
|
+
text-underline-offset: 2px;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
}
|
|
92
|
+
.inAppBanner_cta__1ibpiy76:focus-visible {
|
|
93
|
+
outline: 2px solid #2bb2ff;
|
|
94
|
+
outline-offset: 2px;
|
|
95
|
+
border-radius: 4px;
|
|
96
|
+
}
|
|
97
|
+
.inAppBanner_closeButton__1ibpiy77 {
|
|
98
|
+
all: unset;
|
|
99
|
+
position: absolute;
|
|
100
|
+
top: 8px;
|
|
101
|
+
right: 8px;
|
|
102
|
+
width: 28px;
|
|
103
|
+
height: 28px;
|
|
104
|
+
display: flex;
|
|
105
|
+
align-items: center;
|
|
106
|
+
justify-content: center;
|
|
107
|
+
border-radius: 9999px;
|
|
108
|
+
color: #ffffff99;
|
|
109
|
+
cursor: pointer;
|
|
110
|
+
}
|
|
111
|
+
.inAppBanner_closeButton__1ibpiy77:focus-visible {
|
|
112
|
+
outline: 2px solid var(--text-onAction__pbq4ak6);
|
|
113
|
+
outline-offset: 2px;
|
|
114
|
+
}.Banner_rootBase__1gnumzi0 {
|
|
115
|
+
position: relative;
|
|
116
|
+
display: flex;
|
|
117
|
+
animation: keyframes_fadeInDown__mnqmlt2 300ms ease-out;
|
|
118
|
+
}
|
|
119
|
+
.Banner_iconSvg__1gnumzi1 {
|
|
120
|
+
width: 100%;
|
|
121
|
+
height: 100%;
|
|
122
|
+
}
|
|
123
|
+
.Banner_referral__1gnumzi2 {
|
|
124
|
+
flex-direction: row;
|
|
125
|
+
align-items: center;
|
|
126
|
+
gap: 16px;
|
|
127
|
+
padding: 16px;
|
|
128
|
+
background-color: #ffffff;
|
|
129
|
+
color: var(--text-primary__pbq4ak0);
|
|
130
|
+
border: 1px solid var(--border-default__pbq4akv);
|
|
131
|
+
border-radius: 12px;
|
|
132
|
+
}
|
|
133
|
+
.Banner_referralIconWrapper__1gnumzi3 {
|
|
134
|
+
flex-shrink: 0;
|
|
135
|
+
align-self: flex-start;
|
|
136
|
+
display: flex;
|
|
137
|
+
align-items: center;
|
|
138
|
+
justify-content: center;
|
|
139
|
+
width: 40px;
|
|
140
|
+
height: 40px;
|
|
141
|
+
overflow: hidden;
|
|
142
|
+
}
|
|
143
|
+
.Banner_referralImage__1gnumzi4 {
|
|
144
|
+
max-width: 100%;
|
|
145
|
+
max-height: 100%;
|
|
146
|
+
width: auto;
|
|
147
|
+
height: auto;
|
|
148
|
+
object-fit: contain;
|
|
149
|
+
display: block;
|
|
150
|
+
}
|
|
151
|
+
.Banner_referralBody__1gnumzi5 {
|
|
152
|
+
flex: 1;
|
|
153
|
+
min-width: 0;
|
|
154
|
+
}
|
|
155
|
+
.Banner_referralTitle__1gnumzi6 {
|
|
156
|
+
font-size: 16px;
|
|
157
|
+
font-weight: 600;
|
|
158
|
+
color: var(--text-primary__pbq4ak0);
|
|
159
|
+
line-height: 22px;
|
|
160
|
+
}
|
|
161
|
+
.Banner_referralDescription__1gnumzi7 {
|
|
162
|
+
margin-bottom: 8px;
|
|
163
|
+
font-size: 14px;
|
|
164
|
+
color: #979797;
|
|
165
|
+
line-height: 22px;
|
|
166
|
+
}
|
|
167
|
+
.Banner_referralCta__1gnumzi8 {
|
|
168
|
+
display: inline-block;
|
|
169
|
+
padding: 8px 16px;
|
|
170
|
+
border: 1px solid #000000;
|
|
171
|
+
border-radius: 9999px;
|
|
172
|
+
color: var(--text-primary__pbq4ak0);
|
|
173
|
+
font-size: 10px;
|
|
174
|
+
font-weight: 700;
|
|
175
|
+
line-height: 12px;
|
|
176
|
+
text-transform: uppercase;
|
|
177
|
+
}
|
|
178
|
+
.Banner_frakLogo__1gnumzi9 {
|
|
179
|
+
position: absolute;
|
|
180
|
+
right: 16px;
|
|
181
|
+
bottom: 12px;
|
|
182
|
+
pointer-events: none;
|
|
183
|
+
}`,e);let[H,U]=s(!1),[W,G]=s(()=>P?I:L&&r?`inapp`:null),K=l(null);c(()=>{P&&G(I)},[P,I]);let{reward:q}=C(W===`referral`&&V,_,`referee`),[J,de]=s(null);c(()=>{let e=window.FrakSetup?.client;W!==`inapp`||P||!V||!e||a(e).then(e=>de(e)).catch(()=>{})},[W,P,V]),c(()=>{P||!W||H||K.current!==W&&V&&(t(window.FrakSetup?.client,`banner_impression`,{placement:h,variant:W,has_reward:W===`referral`?!!q:void 0}),K.current=W)},[W,H,V,P,h]),c(()=>{if(P||W===`inapp`)return;let e=()=>G(`referral`);return window.addEventListener(i,e),()=>window.removeEventListener(i,e)},[P,W]);let Y=f(async()=>{if(P)return;if(t(window.FrakSetup?.client,`banner_resolved`,{placement:h,variant:W??`referral`,outcome:`clicked`}),W===`referral`){U(!0);return}let e=J;if(!e&&window.FrakSetup?.client)try{e=await a(window.FrakSetup?.client)}catch{}let r=window.location.href;if(e){let t=new URL(r);t.searchParams.set(`fmt`,e),r=t.toString()}n(r)},[P,W,J,h]),fe=f(()=>{P||(t(window.FrakSetup?.client,`banner_resolved`,{placement:h,variant:W??`referral`,outcome:`dismissed`}),U(!0))},[P,W,h]),X=b(),Z=R?.components?.banner??X?.banner,Q=A??Z?.imageUrl,$=ee(()=>{let e=m[F].banner;if(W===`referral`){let t=q?e.referralTitleReward:e.referralTitle;return{title:S(w??Z?.referralTitle??t,q),description:S(T??Z?.referralDescription??e.referralDescription,q),cta:E??Z?.referralCta??e.referralCta}}return{title:S(D??Z?.inappTitle??e.inappTitle,void 0),description:S(O??Z?.inappDescription??e.inappDescription,void 0),cta:k??Z?.inappCta??e.inappCta}},[F,W,q,Z,w,T,E,D,O,k]);if(!W||!P&&(!z||B||H))return null;let pe=[ie,`frak-banner`,`frak-banner--${W}`,g].filter(Boolean).join(` `);return W===`inapp`?u(te,{title:$.title,description:$.description,cta:$.cta,dismissLabel:m[F].banner.dismissLabel,onAction:Y,onDismiss:fe,className:[`frak-banner`,`frak-banner--inapp`,g].filter(Boolean).join(` `),classNames:{icon:`frak-banner__icon`,title:`frak-banner__title`,description:`frak-banner__description`,cta:`frak-banner__cta`,close:`frak-banner__close`}}):u(`div`,{class:pe,role:`alert`,children:[u(`div`,{class:`${ce} frak-banner__icon`,children:Q?u(`img`,{src:Q,alt:``,class:le}):u(y,{class:re})}),u(`div`,{class:`${ae} frak-banner__text`,children:[u(`p`,{class:`${ue} frak-banner__title`,children:$.title}),u(`p`,{class:`${se} frak-banner__description`,children:$.description}),u(`button`,{type:`button`,class:`${oe} frak-banner__cta`,onClick:Y,children:$.cta})]}),u(v,{class:`${ne} frak-banner__logo`,width:42,height:24})]})}export{M as Banner};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{B as e}from"./clientReady.CnuMZs-Q.js";import{t}from"./sharingPage.yTFaTklh.js";import{a as n,m as r,n as i,p as a,s as o,t as s,u as c}from"./defaults.8QO14l_n.js";import{t as l}from"./useGlobalComponents.Chb50YVY.js";import{t as u}from"./useLightDomStyles.w1gAoBeL.js";import{r as d}from"./rewards.C5fLEHQ9.js";import{t as f}from"./useReward.D4ldCSt1.js";import{t as p}from"./embeddedWallet.GFBOECmv.js";function m({placement:m,text:h,classname:g=``,noRewardText:_,targetInteraction:v,clickAction:y,preview:b}){let x=!!b,S=n(),C=i(m),w=l(),T=C?.components?.buttonShare??w?.buttonShare;u(`frak-button-share`,m,T?.css);let E=c(()=>C?.targetInteraction===void 0?v:C.targetInteraction,[C?.targetInteraction,v]),D=T?.text??h??s[S].buttonShare.text,O=T?.noRewardText??_,k=c(()=>D.includes(`{REWARD}`),[D]),A=c(()=>T?.clickAction??y??`sharing-page`,[T?.clickAction,y]),{shouldRender:j,isHidden:M,isClientReady:N}=o(),{reward:P}=f(k&&N,E),F=c(()=>k?P?d(D,P):O??d(D,void 0):D,[k,D,O,P]),I=a(()=>{if(!x){if(e(window.FrakSetup.client,`share_button_clicked`,{placement:m,target_interaction:E,has_reward:!!P,click_action:A}),A===`embedded-wallet`){p(E,m);return}t(E,m)}},[x,A,E,m,P]);if(!x&&(!j||M))return null;let L=[`button`,`button__fadeIn`,g].filter(Boolean).join(` `);return r(`button`,{type:`button`,disabled:!x&&!N,class:L,onClick:I,children:F})}export{m as ButtonShare};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import{a as e,d as t,f as n,h as r,m as i,n as a,r as o,s,t as c,u as l}from"./defaults.8QO14l_n.js";import{t as u}from"./useReward.D4ldCSt1.js";import{t as d}from"./embeddedWallet.GFBOECmv.js";function f(e){return i(`svg`,{fill:`none`,height:`1em`,viewBox:`0 0 28 28`,width:`1em`,xmlns:`http://www.w3.org/2000/svg`,...e,children:[i(`title`,{children:`Gift icon`}),i(`path`,{d:`m23.14 14v11.43h-18.29v-11.43m9.14 11.43v-17.14m0 0h-5.14c-0.76 0-1.48-0.3-2.02-0.84s-0.84-1.26-0.84-2.020.3-1.480.84-2.02 1.26-0.84 2.02-0.84c4 0 5.14 5.71 5.14 5.71zm0 0h5.14c0.76 0 1.48-0.3 2.02-0.84s0.84-1.260.84-2.02-0.3-1.48-0.84-2.02-1.26-0.84-2.02-0.84c-4 0-5.14 5.71-5.14 5.71zm-11.43 0h22.86v5.71h-22.86z`,stroke:`#fff`,"stroke-linecap":`round`,"stroke-linejoin":`round`})]})}function p(){`vibrate`in navigator?navigator.vibrate(10):console.log(`Vibration not supported`)}function m(e,t){p(),d(e,t)}function h({placement:d,classname:p=``,useReward:h,targetInteraction:g}){let _=e(),v=a(d),y=l(()=>v?.targetInteraction===void 0?g:v.targetInteraction,[v?.targetInteraction,g]),b=l(()=>h===!0,[h]),{shouldRender:x,isHidden:S,isClientReady:C}=s(),{reward:w}=u(b&&C,y),[T,E]=t(`right`);if(n(()=>{let e=v?.components?.buttonWallet?.position,t=window.FrakSetup?.modalWalletConfig?.metadata?.position;E(e??t??`right`)},[v?.components?.buttonWallet?.position]),!x||S)return null;let D=[`button`,`button__fadeIn`,T===`left`?`button__left`:`button__right`,p].filter(Boolean).join(` `);return i(r,{children:[i(`style`,{children:o(`
|
|
2
|
+
.button {
|
|
3
|
+
all: unset;
|
|
4
|
+
position: fixed;
|
|
5
|
+
bottom: 20px;
|
|
6
|
+
z-index: 2000000;
|
|
7
|
+
display: flex;
|
|
8
|
+
justify-content: center;
|
|
9
|
+
align-items: center;
|
|
10
|
+
background-color: #3e557e;
|
|
11
|
+
width: 45px;
|
|
12
|
+
height: 45px;
|
|
13
|
+
border-radius: 50%;
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
text-align: center;
|
|
16
|
+
font-size: 24px;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.button__left {
|
|
20
|
+
left: 20px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.button__right {
|
|
24
|
+
right: 20px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.reward {
|
|
28
|
+
position: absolute;
|
|
29
|
+
top: -4px;
|
|
30
|
+
right: 27px;
|
|
31
|
+
padding: 2px 3px;
|
|
32
|
+
border-radius: 5px;
|
|
33
|
+
background: #ff3f3f;
|
|
34
|
+
font-size: 9px;
|
|
35
|
+
color: #fff;
|
|
36
|
+
font-weight: 600;
|
|
37
|
+
white-space: nowrap;
|
|
38
|
+
line-height: 9px;
|
|
39
|
+
}
|
|
40
|
+
`,v?.components?.buttonWallet?.css)}),i(`button`,{type:`button`,"aria-label":c[_].buttonWallet.ariaLabel,part:`button`,disabled:!C,class:D,onClick:()=>{m(y,d)},children:[i(f,{}),w&&i(`span`,{class:`reward`,children:w})]})]})}export{h as ButtonWallet};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{m as e}from"./defaults.
|
|
1
|
+
import{m as e}from"./defaults.8QO14l_n.js";function t(t){return e(`svg`,{width:`15`,height:`15`,viewBox:`0 0 15 15`,fill:`none`,"aria-hidden":`true`,...t,children:e(`path`,{d:`M7.33 0C11.38 0 14.67 3.28 14.67 7.33C14.67 11.38 11.38 14.67 7.33 14.67C3.28 14.67 0 11.38 0 7.33C0 3.28 3.28 0 7.33 0ZM10.39 4.28C10.15 4.04 9.76 4.04 9.52 4.28L7.33 6.47L5.14 4.28C4.9 4.04 4.52 4.04 4.28 4.28C4.04 4.52 4.04 4.9 4.28 5.14L6.47 7.33L4.28 9.52C4.04 9.76 4.04 10.15 4.28 10.39C4.52 10.63 4.9 10.63 5.14 10.39L7.33 8.2L9.52 10.39C9.76 10.63 10.15 10.63 10.39 10.39C10.63 10.15 10.63 9.76 10.39 9.52L8.2 7.33L10.39 5.14C10.63 4.9 10.63 4.52 10.39 4.28Z`,fill:`currentColor`})})}function n(t){return e(`svg`,{width:`12`,height:`12`,viewBox:`0 0 12 12`,fill:`none`,"aria-hidden":`true`,...t,children:e(`path`,{d:`M5.46 0C5.76 0 6 0.24 6 0.55C6 0.85 5.76 1.09 5.46 1.09H4.36C3.05 1.09 2.28 1.36 1.82 1.82C1.36 2.28 1.09 3.05 1.09 4.36V7.64C1.09 8.95 1.36 9.72 1.82 10.18C2.28 10.64 3.05 10.91 4.36 10.91H7.64C8.95 10.91 9.72 10.64 10.18 10.18C10.64 9.72 10.91 8.95 10.91 7.64V6.55C10.91 6.24 11.15 6 11.46 6C11.76 6 12 6.24 12 6.55V7.64C12 9.05 11.72 10.19 10.95 10.95C10.19 11.72 9.05 12 7.64 12H4.36C2.95 12 1.81 11.72 1.05 10.95C0.28 10.19 6.04e-05 9.05 0 7.64V4.36C0 2.95 0.28 1.81 1.05 1.05C1.81 0.28 2.95 0 4.36 0H5.46ZM11.45 0C11.76 2.2e-05 12 0.24 12 0.55V3.16C12 3.47 11.76 3.71 11.45 3.71C11.15 3.71 10.91 3.46 10.91 3.16V1.86L6.93 5.84C6.72 6.05 6.37 6.05 6.16 5.84C5.95 5.63 5.95 5.28 6.16 5.07L10.14 1.09H8.84C8.54 1.09 8.29 0.85 8.29 0.55C8.29 0.24 8.53 0 8.84 0H11.45Z`,fill:`currentColor`})})}function r(t){return e(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:t.width??`63`,height:t.height??`24`,fill:`none`,viewBox:`0 0 63 24`,...t,children:[e(`title`,{children:`Frak`}),e(`rect`,{width:`24`,height:`24`,rx:`6`,fill:`#0043EF`}),e(`path`,{fill:`white`,d:`M9.77 15.91L5.15 14.35C5.06 14.32 4.97 14.38 4.97 14.47V17.33C4.97 17.39 5.01 17.44 5.06 17.46L9.68 19.02C9.77 19.05 9.86 18.98 9.86 18.89V16.04C9.86 15.98 9.82 15.93 9.77 15.91ZM14.58 10.44L9.95 12C9.9 12.02 9.86 12.07 9.86 12.13V14.98C9.86 15.08 9.95 15.14 10.04 15.11L14.66 13.55C14.72 13.53 14.76 13.48 14.76 13.42V10.57C14.76 10.47 14.66 10.41 14.58 10.44ZM18.92 5.02L11.18 7.51C11.12 7.53 11.08 7.58 11.08 7.64V10.57C11.08 10.62 11.14 10.66 11.2 10.65L18.94 8.15C18.99 8.14 19.03 8.08 19.03 8.02V5.1C19.03 5.04 18.97 5 18.92 5.02Z`}),e(`path`,{fill:`currentColor`,d:`M52.72 9.51C52.83 9.51 52.91 9.6 52.91 9.7L52.84 18.21C52.84 18.31 52.76 18.39 52.66 18.39L52.64 18.39H51.3C51.15 18.39 50.78 18.25 50.39 18C49.86 18.25 49.27 18.39 48.64 18.39H48.39C47.24 18.39 46.19 17.91 45.43 17.14C44.67 16.38 44.2 15.32 44.2 14.15C44.2 12.98 44.67 11.92 45.43 11.15C46.16 10.41 47.16 9.94 48.26 9.91C49.17 9.86 49.99 9.99 50.49 10.5V9.7C50.49 9.6 50.57 9.51 50.68 9.51H52.72ZM35.35 5.62H36.96C37.09 5.62 37.19 5.72 37.19 5.85V7.81C37.19 7.94 37.09 8.04 36.96 8.04H34.92C34.32 8.04 33.63 8.64 33.63 9.25V10.61C34.26 9.98 34.93 9.65 35.35 9.63H36.46C36.59 9.63 36.69 9.73 36.69 9.86V11.82C36.69 11.95 36.59 12.05 36.46 12.05H34.92C34.31 12.05 33.63 12.65 33.63 13.27V18.2C33.63 18.3 33.54 18.39 33.44 18.39H31.39C31.29 18.39 31.21 18.3 31.21 18.2V9.94C31.21 9.87 31.2 9.8 31.2 9.73C31.24 8.88 31.15 5.44 35.35 5.62ZM39.93 9.63C40.04 9.63 40.12 9.72 40.12 9.82V10.61C40.76 9.98 41.58 9.63 41.85 9.63H43.46C43.58 9.63 43.68 9.73 43.69 9.86V11.82C43.68 11.95 43.58 12.05 43.46 12.05H41.41C40.81 12.05 40.12 12.65 40.12 13.27V18.2C40.12 18.3 40.04 18.39 39.93 18.39H37.89C37.79 18.39 37.7 18.3 37.7 18.2V9.82C37.7 9.72 37.79 9.63 37.89 9.63H39.93ZM56.2 7.01C56.3 7.01 56.39 7.09 56.39 7.2V13.45L59.83 10.19C59.87 10.16 59.91 10.14 59.96 10.14H62.28C62.45 10.14 62.54 10.34 62.42 10.46L59.3 13.63L62.8 18.07C62.9 18.2 62.81 18.39 62.65 18.39H60.24C60.18 18.39 60.13 18.36 60.09 18.31L57.67 15.32C57.6 15.23 57.47 15.22 57.39 15.3L56.39 16.29V18.19C56.39 18.3 56.3 18.39 56.2 18.39H54.19C54.08 18.39 54 18.3 54 18.19V7.2C54 7.09 54.08 7.01 54.19 7.01H56.2ZM48.37 11.96C47.78 11.96 47.24 12.21 46.85 12.6C46.46 13 46.22 13.54 46.22 14.14C46.22 14.73 46.46 15.28 46.85 15.67C47.24 16.07 47.78 16.31 48.37 16.31H48.66C49.25 16.31 49.79 16.07 50.18 15.67C50.57 15.28 50.81 14.73 50.81 14.14C50.81 13.54 50.57 12.99 50.18 12.6C49.79 12.21 49.25 11.96 48.66 11.96H48.37Z`})]})}2*Math.PI*11;function i(t){return e(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,...t,children:e(`path`,{d:`M8 0C12.42 0 16 3.58 16 8C16 12.42 12.42 16 8 16C3.58 16 0 12.42 0 8C0 3.58 3.58 0 8 0ZM8 1.5C4.41 1.5 1.5 4.41 1.5 8C1.5 11.59 4.41 14.5 8 14.5C11.59 14.5 14.5 11.59 14.5 8C14.5 4.41 11.59 1.5 8 1.5ZM8.1 10.21C8.82 10.21 9.24 10.63 9.24 11.33C9.24 12.03 8.82 12.46 8.1 12.46C7.36 12.46 6.97 12.03 6.97 11.33C6.97 10.63 7.36 10.21 8.1 10.21ZM8.85 3.54C9.01 3.54 9.15 3.68 9.15 3.84V4.75L8.84 8.37C8.83 8.53 8.7 8.65 8.54 8.65H7.63C7.47 8.65 7.34 8.52 7.33 8.37L7.08 4.75V3.84C7.09 3.68 7.22 3.54 7.38 3.54H8.85Z`,fill:`currentColor`})})}function a(t){return e(`svg`,{viewBox:`0 0 100 100`,fill:`none`,"aria-hidden":`true`,...t,children:[e(`circle`,{cx:`38`,cy:`28`,r:`23`,fill:`#FFF533`}),e(`path`,{d:`M50 38C30 10 12 30 50 38Z`,stroke:`#222222`,"stroke-width":`4`,"stroke-linecap":`round`,"stroke-linejoin":`round`}),e(`path`,{d:`M50 38C70 10 88 30 50 38Z`,stroke:`#222222`,"stroke-width":`4`,"stroke-linecap":`round`,"stroke-linejoin":`round`}),e(`rect`,{x:`10`,y:`38`,width:`80`,height:`16`,rx:`2`,stroke:`#222222`,"stroke-width":`4`}),e(`path`,{d:`M15 54V89C15 90.6 16.4 92 18 92H82C83.6 92 85 90.6 85 89V54`,stroke:`#222222`,"stroke-width":`4`,"stroke-linecap":`round`,"stroke-linejoin":`round`}),e(`line`,{x1:`50`,y1:`54`,x2:`50`,y2:`92`,stroke:`#222222`,"stroke-width":`4`,"stroke-linecap":`round`})]})}export{t as a,n as i,i as n,r,a as t};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{B as e,h as t,i as n,l as r}from"./clientReady.CnuMZs-Q.js";import{a as i,m as a,n as o,s,t as c,u as l}from"./defaults.8QO14l_n.js";import{t as u}from"./useLightDomStyles.w1gAoBeL.js";function d(n=`wallet`,i){let a=window.FrakSetup?.client;a&&e(a,`open_in_app_clicked`,{path:n,placement:i}),r(`${t}${n}`,{onFallback:()=>{a&&e(a,`app_not_installed`,{path:n,placement:i})}})}function f(){return{isMobile:l(()=>n(),[])}}function p({placement:e,text:t,classname:n=``}){let r=i(),l=o(e),{shouldRender:p,isHidden:m,isClientReady:h}=s(),{isMobile:g}=f();u(`frak-open-in-app`,e,l?.components?.openInApp?.css);let _=l?.components?.openInApp?.text??t??c[r].openInApp.text;if(!g||!p||m)return null;let v=()=>{d(void 0,e)},y=[`button`,`button__fadeIn`,n].filter(Boolean).join(` `);return a(`button`,{type:`button`,"aria-label":c[r].openInApp.ariaLabel,disabled:!h,class:y,onClick:v,children:_})}export{p as OpenInAppButton};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import{t as e}from"./sharedBaseCss.css.BDzFcWnD.js";import{B as t,H as n,W as r}from"./clientReady.CnuMZs-Q.js";import{l as i,p as a,r as o}from"./actions-C2MhMidX.DwPAFQBK.js";import{t as s}from"./sharingPage.yTFaTklh.js";import{n as c}from"./sharingPageProducts.DwoFd3Rz.js";import{a as ee,d as l,f as u,l as te,m as d,n as f,p,s as m,t as h,u as g}from"./defaults.8QO14l_n.js";import{r as ne,t as re}from"./GiftIcon.S_PCRRWc.js";import{t as ie}from"./useGlobalComponents.Chb50YVY.js";import{t as ae}from"./useLightDomStyles.w1gAoBeL.js";import{i as oe,n as _,r as v}from"./rewards.C5fLEHQ9.js";var y=`PostPurchase_card__5fv5lh0`,se=`PostPurchase_cardLayout__5fv5lh1`,ce=`PostPurchase_cardLeft__5fv5lh2`,b=`PostPurchase_cardRight__5fv5lh3`,x=`PostPurchase_cta__5fv5lh6 sharedBaseCss_buttonReset__7cswil0`,le=`PostPurchase_customImage__5fv5lha`,ue=`PostPurchase_frakLogo__5fv5lhb`,de=`PostPurchase_giftIcon__5fv5lh8`,fe=`PostPurchase_icon__5fv5lh7`,pe=`PostPurchase_imageWrapper__5fv5lh9`,me=`PostPurchase_message__5fv5lh5`;function he(e,t,n){let r=e?.isReferred?`referee`:`referrer`,i=_(t.rewards,{targetInteraction:`purchase`,currency:n,audience:r});if(!i)return null;let{campaign:a}=i,o=e?.isReferred&&a.referee?`referee`:`referrer`;return{variant:o,reward:o===`referee`?a.referee:a.referrer,merchantDomain:t.onChainMetadata.domain}}function S({customerId:_,orderId:S,token:C,sharingUrl:ge,merchantId:w,placement:T,classname:E=``,variant:D,badgeText:O,referrerText:k,refereeText:A,ctaText:j,preview:M,previewVariant:N,products:P,imageUrl:F}){let I=!!M,{shouldRender:L,isHidden:R,isClientReady:z}=m(),B=f(T),V=ee();ae(`frak-post-purchase`,T,B?.components?.postPurchase?.css,`.PostPurchase_card__5fv5lh0 {
|
|
2
|
+
padding: 16px;
|
|
3
|
+
border-radius: 12px;
|
|
4
|
+
background-color: var(--surface-background__pbq4akc);
|
|
5
|
+
border: 1px solid var(--border-default__pbq4akv);
|
|
6
|
+
}
|
|
7
|
+
.PostPurchase_cardLayout__5fv5lh1 {
|
|
8
|
+
display: flex;
|
|
9
|
+
flex-direction: row;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: 32px;
|
|
12
|
+
}
|
|
13
|
+
.PostPurchase_cardLeft__5fv5lh2 {
|
|
14
|
+
flex-grow: 1;
|
|
15
|
+
min-width: 0;
|
|
16
|
+
display: flex;
|
|
17
|
+
flex-direction: column;
|
|
18
|
+
gap: 8px;
|
|
19
|
+
}
|
|
20
|
+
.PostPurchase_cardRight__5fv5lh3 {
|
|
21
|
+
flex-shrink: 0;
|
|
22
|
+
display: flex;
|
|
23
|
+
flex-direction: column;
|
|
24
|
+
align-items: flex-end;
|
|
25
|
+
gap: 8px;
|
|
26
|
+
text-align: right;
|
|
27
|
+
}
|
|
28
|
+
.PostPurchase_badge__5fv5lh4 {
|
|
29
|
+
align-self: flex-start;
|
|
30
|
+
background-color: #FFF534;
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
padding: 4px 8px;
|
|
33
|
+
font-size: 12px;
|
|
34
|
+
font-weight: 600;
|
|
35
|
+
line-height: 12px;
|
|
36
|
+
color: var(--text-primary__pbq4ak0);
|
|
37
|
+
}
|
|
38
|
+
.PostPurchase_message__5fv5lh5 {
|
|
39
|
+
margin: 0;
|
|
40
|
+
font-size: 16px;
|
|
41
|
+
line-height: 22px;
|
|
42
|
+
color: var(--text-primary__pbq4ak0);
|
|
43
|
+
font-weight: 600;
|
|
44
|
+
}
|
|
45
|
+
.PostPurchase_cta__5fv5lh6 {
|
|
46
|
+
display: inline-flex;
|
|
47
|
+
align-items: center;
|
|
48
|
+
justify-content: center;
|
|
49
|
+
gap: 4px;
|
|
50
|
+
padding: 12px 16px;
|
|
51
|
+
border-radius: 9999px;
|
|
52
|
+
background-color: var(--text-primary__pbq4ak0);
|
|
53
|
+
color: var(--text-onAction__pbq4ak6);
|
|
54
|
+
font-size: 12px;
|
|
55
|
+
font-weight: bold;
|
|
56
|
+
text-transform: uppercase;
|
|
57
|
+
}
|
|
58
|
+
.PostPurchase_cta__5fv5lh6:disabled {
|
|
59
|
+
opacity: 0.7;
|
|
60
|
+
cursor: default;
|
|
61
|
+
}
|
|
62
|
+
.PostPurchase_icon__5fv5lh7 {
|
|
63
|
+
margin: -2px 0;
|
|
64
|
+
}
|
|
65
|
+
.PostPurchase_giftIcon__5fv5lh8 {
|
|
66
|
+
display: block;
|
|
67
|
+
flex-shrink: 0;
|
|
68
|
+
}
|
|
69
|
+
.PostPurchase_imageWrapper__5fv5lh9 {
|
|
70
|
+
flex-shrink: 0;
|
|
71
|
+
display: flex;
|
|
72
|
+
align-items: center;
|
|
73
|
+
justify-content: center;
|
|
74
|
+
width: 80px;
|
|
75
|
+
height: 80px;
|
|
76
|
+
overflow: hidden;
|
|
77
|
+
}
|
|
78
|
+
.PostPurchase_customImage__5fv5lha {
|
|
79
|
+
max-width: 100%;
|
|
80
|
+
max-height: 100%;
|
|
81
|
+
width: auto;
|
|
82
|
+
height: auto;
|
|
83
|
+
object-fit: contain;
|
|
84
|
+
display: block;
|
|
85
|
+
}
|
|
86
|
+
.PostPurchase_frakLogo__5fv5lhb {
|
|
87
|
+
display: block;
|
|
88
|
+
margin-left: auto;
|
|
89
|
+
}`,e);let[H,_e]=l(null),[U,W]=l(!1);u(()=>{I||!z||!_||!S||!C||o({customerId:_,orderId:S,token:C,merchantId:w}).catch(()=>{})},[I,z,_,S,C,w]),u(()=>{if(I||!z||U)return;let e=window.FrakSetup?.client;e&&Promise.all([i(e),a(e)]).then(([t,n])=>{W(!0),_e(he(t,n,e.config.metadata?.currency))}).catch(e=>{if(e instanceof r&&e.code===n.configError){W(!0);return}console.warn(`[Frak] Post-purchase context error`,e)})},[I,z,U]);let G=te(null),K=D??H?.variant??(I?N??`referrer`:void 0),q=ge??H?.merchantDomain,J=g(()=>{if(!H?.reward)return;let e=window.FrakSetup?.client?.config?.metadata?.currency;return oe(H.reward,e)},[H?.reward]),ve=ie(),Y=B?.components?.postPurchase??ve?.postPurchase,X=O??Y?.badgeText,Z=F??Y?.imageUrl,Q=g(()=>{let e=h[V].postPurchase;return{message:K===`referee`?J?v(A??Y?.refereeText??e.refereeText,J):A??Y?.refereeNoRewardText??e.refereeNoRewardText:J?v(k??Y?.referrerText??e.referrerText,J):k??Y?.referrerNoRewardText??e.referrerNoRewardText,cta:J?v(j??Y?.ctaText??e.ctaText,J):j??Y?.ctaNoRewardText??e.ctaNoRewardText}},[V,K,J,Y,k,A,j]);u(()=>{K&&G.current!==K&&z&&(!I&&(!L||R)||(t(window.FrakSetup?.client,`post_purchase_impression`,{placement:T,variant:K,has_reward:!!H?.reward}),G.current=K))},[K,L,R,z,I,T,H?.reward]);let $=g(()=>c(P),[P]),ye=p(()=>{K&&(t(window.FrakSetup?.client,`post_purchase_clicked`,{placement:T,variant:K}),s(void 0,T,{link:q,products:$}))},[K,T,q,$]);return!K||!I&&(!L||R||!H)?null:d(`div`,{className:[y,E].filter(Boolean).join(` `),children:d(`div`,{class:se,children:[d(`div`,{class:ce,children:[X&&d(`span`,{class:`PostPurchase_badge__5fv5lh4`,children:X}),d(`p`,{class:me,children:Q.message}),d(`button`,{type:`button`,className:`${x} button`,disabled:!I&&!z,onClick:I?void 0:ye,children:[Q.cta,d(`svg`,{width:`16`,height:`16`,viewBox:`0 0 16 16`,fill:`none`,"aria-hidden":`true`,className:`${fe} button`,children:d(`path`,{d:`M13.9 11.14C13.99 11.05 14.15 11.11 14.15 11.24V11.64C14.15 13.05 12.63 14.19 10.75 14.19C8.87 14.19 7.34 13.05 7.34 11.64V11.24C7.34 11.11 7.51 11.05 7.59 11.14C8.35 11.93 9.48 12.43 10.75 12.43C12.01 12.43 13.15 11.93 13.9 11.14ZM1.85 9.65C1.85 9.51 2.01 9.44 2.1 9.54C2.85 10.32 3.99 10.82 5.25 10.82C5.52 10.82 5.79 10.8 6.04 10.76C6.26 10.72 6.47 10.88 6.47 11.1V12.17C6.47 12.32 6.37 12.45 6.22 12.48C5.92 12.55 5.59 12.59 5.25 12.59C3.37 12.59 1.85 11.45 1.85 10.04V9.65ZM10.75 6.21C12.63 6.21 14.15 7.35 14.15 8.75C14.15 10.16 12.63 11.3 10.75 11.3C8.87 11.3 7.34 10.16 7.34 8.75C7.34 7.35 8.87 6.21 10.75 6.21ZM1.85 6.85C1.85 6.71 2.01 6.65 2.1 6.74C2.85 7.53 3.99 8.03 5.25 8.03C5.52 8.03 5.79 8 6.04 7.96C6.26 7.92 6.47 8.09 6.47 8.3V9.37C6.47 9.52 6.37 9.65 6.22 9.69C5.92 9.75 5.59 9.79 5.25 9.79C3.37 9.79 1.85 8.65 1.85 7.24V6.85ZM5.25 1.81C7.13 1.81 8.66 2.95 8.66 4.36C8.66 5.76 7.13 6.9 5.25 6.9C3.37 6.9 1.85 5.76 1.85 4.36C1.85 2.95 3.37 1.81 5.25 1.81Z`,fill:`currentColor`})})]})]}),d(`div`,{class:b,children:[Z?d(`span`,{class:pe,children:d(`img`,{src:Z,alt:``,class:le})}):d(re,{className:de,width:80,height:80}),d(ne,{className:ue,width:42,height:24})]})]})})}export{S as PostPurchase};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{B as e,E as t,I as n,L as r,M as i,O as a,T as o,U as s,w as c,x as l,z as u}from"./clientReady.CnuMZs-Q.js";async function d(e,t,n){return await e.request({method:`frak_displayEmbeddedWallet`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function f(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 p(e,t,n){return await e.request({method:`frak_displaySharingPage`,params:n?[t,e.config.metadata,n]:[t,e.config.metadata]})}async function m(e,n){if(typeof window>`u`)return;let i=await c().catch(()=>void 0);if(!i)return;let o=await a.resolveMerchantId();if(!o)return;let s=`frak-identity-ensured-${o}-${i}`;if(!window.sessionStorage.getItem(s))try{let a=r(n),c=await t({op:`frak-ensure-v1`,merchantId:o,anonymousId:i});(await fetch(`${a}/user/identity/ensure`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`,"x-wallet-sdk-auth":e,"x-frak-client-id":i},body:JSON.stringify({merchantId:o,...c&&{proof:c}})})).ok&&window.sessionStorage.setItem(s,`1`)}catch{}}async function h(e,t){return n(()=>e.request({method:`frak_getMerchantInformation`}),{cacheKey:`frak_getMerchantInformation`,cacheTime:t?.cacheTime})}async function g(e,r){return n(async()=>{let n=await c().catch(()=>void 0),r=n?await t({op:`frak-merge-v1`,merchantId:e.config.metadata.merchantId??``,anonymousId:n}):null;return e.request({method:`frak_getMergeToken`,params:r?[r]:void 0})},{cacheKey:`frak_getMergeToken`,cacheTime:r?.cacheTime})}async function _(e,t){return n(()=>e.request({method:`frak_getUserReferralStatus`}),{cacheKey:`frak_getUserReferralStatus`,cacheTime:t?.cacheTime})}async function v(e,t){let{metadata:n,customizations:r}=e.config;return await e.request({method:`frak_prepareSso`,params:[t,n.name,r?.css]})}async function y(e,t){try{let n=await c().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 b(t,n,r){return i(n)?(e(t,`user_referred_started`,{referrer_client_id:n.c,referrer_wallet:n.w,wallet_status:r?.key}),y(t,{type:`arrival`,referrerClientId:n.c,referrerMerchantId:n.m,referrerWallet:n.w,referralTimestamp:n.t}),!0):l(n)?(e(t,`user_referred_started`,{referrer:n.r,wallet_status:r?.key}),y(t,{type:`arrival`,referrerWallet:n.r}),!0):!1}function x(e,t,n){return!t&&!n?null:{v:2,m:e,t:Math.floor(Date.now()/1e3),...t?{c:t}:{},...n?{w:n}:{}}}function S(e,t,n){return i(e)?e.w&&n?.wallet?u(e.w,n.wallet):e.c?t===e.c:!1:l(e)&&n?.wallet?u(e.r,n.wallet):!1}async function C(t,{walletStatus:n,frakContext:r,options:a}){if(!r)return`no-referrer`;let s=await c().catch(()=>void 0);if(S(r,s,n))return`self-referral`;if(!b(t,r,n))return`no-referrer`;let l=i(r)?r.m:a?.merchantId,u=a?.alwaysAppendUrl&&l?x(l,s,n?.wallet):null;return o.replaceUrl({url:window.location?.href,context:u}),e(t,`user_referred_completed`,{status:`success`}),`success`}async function w(e,{options:t}={}){let n=o.parse({url:window.location.href}),r=await O(e);try{return await C(e,{walletStatus:r,frakContext:n,options:t})}catch(e){console.warn(`Error processing referral`,{error:e})}}const T=`frak:referral-success`;async function E(e){try{await w(e)===`success`&&window.dispatchEvent(new Event(T))}catch(e){console.warn(`[Frak] Referral setup failed`,e)}}async function D(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 c().catch(()=>void 0);if(!t&&!n){console.warn(`[Frak] No identity found, skipping purchase check`);return}let i=e.merchantId??await a.resolveMerchantId();if(!i){console.warn(`[Frak] No merchant id found, skipping purchase check`);return}let o={Accept:`application/json`,"Content-Type":`application/json`};t&&(o[`x-wallet-sdk-auth`]=t),n&&(o[`x-frak-client-id`]=n);let s=r();await fetch(`${s}/user/track/purchase`,{method:`POST`,headers:o,body:JSON.stringify({customerId:e.customerId,orderId:e.orderId,token:e.token,merchantId:i})})}function O(e,t){if(!t)return e.request({method:`frak_listenToWalletStatus`}).then(t=>(k(e,t),t));let n=new s,r=!1;return e.listenerRequest({method:`frak_listenToWalletStatus`},i=>{k(e,i),t(i),r||=(n.resolve(i),!0)}),n.promise}function k(e,t){typeof window>`u`||(e.openPanel?.setGlobalProperties({wallet:t.wallet??null}),t.interactionToken?(window.sessionStorage.setItem(`frak-wallet-interaction-token`,t.interactionToken),m(t.interactionToken,e.config.walletUrl)):window.sessionStorage.removeItem(`frak-wallet-interaction-token`))}function A(e,{metadata:t,login:n}){return j(e,{steps:{login:n??{}},metadata:t})}function j(e,t){function n(n){return j(e,{...t,steps:{...t.steps,sendTransaction:n}})}function r(n){return j(e,{...t,steps:{...t.steps,final:{...n,action:{key:`reward`}}}})}function i(n,r){return j(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 f(e,t,r)}return{params:t,sendTx:n,reward:r,sharing:i,display:a}}async function M(e,{tx:t,metadata:n}){return(await f(e,{metadata:n,steps:{login:{},sendTransaction:{tx:t}}})).sendTransaction}function N(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 P(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 f(e,{metadata:n,steps:{login:{},siweAuthenticate:{siwe:{...t,statement:i,nonce:t?.nonce??N(),uri:t?.uri??`https://${r}`,version:t?.version??`1`,domain:r}}}})).siweAuthenticate}export{w as _,M as a,T as c,f as d,g as f,v as g,p as h,E as i,_ as l,m,C as n,O as o,h as p,D as r,P as s,A as t,d as u,y as v};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const e=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,t=new TextEncoder;function n(t,n){if(!e.test(t))throw Error(`${n} must be a UUID string, got: ${t}`);let r=t.replace(/-/g,``),i=new Uint8Array(16);for(let e=0;e<16;e++)i[e]=Number.parseInt(r.slice(e*2,e*2+2),16);return i}function r(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 i(e){if(e.binding.length!==0&&e.binding.length!==32)throw Error(`binding must be empty or 32 bytes, got ${e.binding.length}`);let i=t.encode(e.op),a=new Uint8Array(i.length+32+32+8),o=0;return a.set(i,o),o+=i.length,a.set(n(e.merchantId,`merchantId`),o),o+=16,a.set(n(e.anonymousId,`anonymousId`),o),o+=16,a.set(e.binding,o),o+=32,r(a,o,e.ts),a}function a(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=o(t);return[n.slice(0,8),n.slice(8,12),n.slice(12,16),n.slice(16,20),n.slice(20,32)].join(`-`)}function o(e){return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}function s(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function c(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),r(t,66,e.ts),t.set(e.sig,74),s(t)}function l(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}function u(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 d(e,t,n=``){let r=l(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 f(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`Hash must wrapped by utils.createHasher`);if(u(e.outputLen),u(e.blockLen),e.outputLen<1)throw Error(`"outputLen" must be >= 1`);if(e.blockLen<1)throw Error(`"blockLen" must be >= 1`)}function p(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 m(e,t){d(e,void 0,`digestInto() output`);let n=t.outputLen;if(e.length<n)throw RangeError(`"digestInto() output" expected to be of length >=`+n)}function h(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function g(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function _(e,t){return e<<32-t|e>>>t}const v=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,y=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function b(e){if(d(e),v)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=y[e[n]];return t}const x={_0:48,_9:57,A:65,F:70,a:97,f:102};function S(e){if(e>=x._0&&e<=x._9)return e-x._0;if(e>=x.A&&e<=x.F)return e-(x.A-10);if(e>=x.a&&e<=x.f)return e-(x.a-10)}function C(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);if(v)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=S(e.charCodeAt(i)),a=S(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 w(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];d(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 T(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 E(e=32){u(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 ee=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function te(e,t,n){return e&t^~e&n}function ne(e,t,n){return e&t^e&n^t&n}var re=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=g(this.buffer)}update(e){p(this),d(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=g(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){p(this),m(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,h(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=g(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]),ie=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 ae=class extends re{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,7)^_(t,18)^t>>>3,i=_(n,17)^_(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=_(o,6)^_(o,11)^_(o,25),u=l+t+te(o,s,c)+ie[e]+O[e]|0,d=(_(n,2)^_(n,13)^_(n,22))+ne(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(){h(O)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),h(this.buffer)}},oe=class extends ae{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 se=T(()=>new oe,ee(1)),k=(e,t,n)=>d(e,t,n),ce=u,le=b,A=(...e)=>w(...e),ue=e=>C(e),de=l,fe=e=>E(e),pe=BigInt(0),me=BigInt(1)
|
|
2
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
3
|
+
;function j(e,t=``){if(typeof e!=`boolean`){let n=t&&`"${t}" `;throw TypeError(n+`expected boolean, got type=`+typeof e)}return e}function he(e){if(typeof e==`bigint`){if(!M(e))throw RangeError(`positive bigint expected, got `+e)}else ce(e);return e}function ge(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 _e(e){let t=he(e).toString(16);return t.length&1?`0`+t:t}function ve(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?pe:BigInt(`0x`+e)}function ye(e){return ve(b(e))}function be(e){return ve(b(Ce(d(e)).reverse()))}function xe(e,t){if(u(t),t===0)throw RangeError(`zero length`);e=he(e);let n=e.toString(16);if(n.length>t*2)throw RangeError(`number too large`);return C(n.padStart(t*2,`0`))}function Se(e,t){return xe(e,t).reverse()}function Ce(e){return Uint8Array.from(k(e))}const M=e=>typeof e==`bigint`&&pe<=e;function we(e,t,n){return M(e)&&M(t)&&M(n)&&t<=e&&e<n}function Te(e,t,n,r){if(!we(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function Ee(e){if(e<pe)throw Error(`expected non-negative bigint, got `+e);let t;for(t=0;e>pe;e>>=me,t+=1);return t}const De=e=>(me<<BigInt(e))-me;function Oe(e,t,n){if(u(e,`hashLen`),u(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,d=()=>{s.fill(1),c.fill(0),l=0},f=(...e)=>n(c,A(s,...e)),p=(e=i)=>{c=f(a,e),s=f(),e.length!==0&&(c=f(o,e),s=f())},m=()=>{if(l++>=1e3)throw Error(`drbg: tried max amount of iterations`);let e=0,n=[];for(;e<t;){s=f();let t=s.slice();n.push(t),e+=s.length}return A(...n)};return(e,t)=>{d(),p(e);let n;for(;(n=t(m()))===void 0;)p();return d(),n}}function ke(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)}
|
|
4
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
5
|
+
const N=BigInt(0),P=BigInt(1),F=BigInt(2),Ae=BigInt(3),je=BigInt(4),Me=BigInt(5),Ne=BigInt(7),Pe=BigInt(8),Fe=BigInt(9),Ie=BigInt(16);function I(e,t){if(t<=N)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=N?n:t+n}function Le(e,t){if(e===N)throw Error(`invert: expected non-zero number`);if(t<=N)throw Error(`invert: expected positive modulus, got `+t);let n=I(e,t),r=t,i=N,a=P,o=P,s=N;for(;n!==N;){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!==P)throw Error(`invert: does not exist`);return I(i,t)}function Re(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function ze(e,t){let n=e,r=(n.ORDER+P)/je,i=n.pow(t,r);return Re(n,i,t),i}function Be(e,t){let n=e,r=(n.ORDER-Me)/Pe,i=n.mul(t,F),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,F),a),c=n.mul(o,n.sub(s,n.ONE));return Re(n,c,t),c}function Ve(e){let t=Qe(e),n=He(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+Ne)/Ie;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 Re(n,m,t),m})}function He(e){if(e<Ae)throw Error(`sqrt is not defined for small field`);let t=e-P,n=0;for(;t%F===N;)t/=F,n++;let r=F,i=Qe(e);for(;Je(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return ze;let a=i.pow(r,t),o=(t+P)/F;return function(e,r){let i=e;if(i.is0(r))return r;if(Je(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=P<<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 Ue(e){return e%je===Ae?ze:e%Pe===Me?Be:e%Ie===Fe?Ve(e):He(e)}const We=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function Ge(e){if(ke(e,We.reduce((e,t)=>(e[t]=`function`,e),{ORDER:`bigint`,BYTES:`number`,BITS:`number`})),ge(e.BYTES,`BYTES`),ge(e.BITS,`BITS`),e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=P)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function Ke(e,t,n){let r=e;if(n<N)throw Error(`invalid exponent, negatives unsupported`);if(n===N)return r.ONE;if(n===P)return t;let i=r.ONE,a=t;for(;n>N;)n&P&&(i=r.mul(i,a)),a=r.sqr(a),n>>=P;return i}function qe(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 Je(e,t){let n=e,r=(n.ORDER-P)/F,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 Ye(e,t){if(t!==void 0&&ce(t),e<=N)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=Ee(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 Xe=new WeakMap;var Ze=class{ORDER;BITS;BYTES;isLE;ZERO=N;ONE=P;_lengths;_mod;constructor(e,t={}){if(e<=P)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}=Ye(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 I(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return N<=e&&e<this.ORDER}is0(e){return e===N}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&P)===P}neg(e){return I(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return I(e*e,this.ORDER)}add(e,t){return I(e+t,this.ORDER)}sub(e,t){return I(e-t,this.ORDER)}mul(e,t){return I(e*t,this.ORDER)}pow(e,t){return Ke(this,e,t)}div(e,t){return I(e*Le(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 Le(e,this.ORDER)}sqrt(e){let t=Xe.get(this);return t||Xe.set(this,t=Ue(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?Se(e,this.BYTES):xe(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?be(e):ye(e);if(o&&(s=I(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return qe(this,e)}cmov(e,t,n){return j(n,`condition`),n?t:e}};Object.freeze(Ze.prototype);function Qe(e,t={}){return new Ze(e,t)}function $e(e){if(typeof e!=`bigint`)throw Error(`field order must be bigint`);if(e<=P)throw Error(`field order must be greater than 1`);let t=Ee(e-P);return Math.ceil(t/8)}function et(e){let t=$e(e);return t+Math.ceil(t/2)}function tt(e,t,n=!1){k(e);let r=e.length,i=$e(t),a=Math.max(et(t),16);if(r<a||r>1024)throw Error(`expected `+a+`-1024 bytes of input, got `+r);let o=I(n?be(e):ye(e),t-P)+P;return n?Se(o,i):xe(o,i)}
|
|
6
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
7
|
+
const L=BigInt(0),R=BigInt(1);function nt(e,t){let n=t.negate();return e?n:t}function rt(e,t){let n=qe(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function it(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw Error(`invalid window size, expected [1..`+t+`], got W=`+e)}function at(e,t){it(e,t);let n=Math.ceil(t/e)+1,r=2**(e-1),i=2**e;return{windows:n,windowSize:r,mask:De(e),maxNumber:i,shiftBy:BigInt(e)}}function ot(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+=R);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 st=new WeakMap,ct=new WeakMap;function lt(e){return ct.get(e)||1}function ut(e){if(e!==L)throw Error(`invalid wNAF`)}var dt=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>L;)t&R&&(n=n.add(r)),r=r.double(),t>>=R;return n}precomputeWindow(e,t){let{windows:n,windowSize:r}=at(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=at(e,this.bits);for(let e=0;e<a.windows;e++){let{nextN:o,offset:s,isZero:c,isNeg:l,isNegF:u,offsetF:d}=ot(n,e,a);n=o,c?i=i.add(nt(u,t[d])):r=r.add(nt(l,t[s]))}return ut(n),{p:r,f:i}}wNAFUnsafe(e,t,n,r=this.ZERO){let i=at(e,this.bits);for(let e=0;e<i.windows&&n!==L;e++){let{nextN:a,offset:o,isZero:s,isNeg:c}=ot(n,e,i);if(n=a,!s){let e=t[o];r=r.add(c?e.negate():e)}}return ut(n),r}getPrecomputes(e,t,n){let r=st.get(t);return r||(r=this.precomputeWindow(t,e),e!==1&&(typeof n==`function`&&(r=n(r)),st.set(t,r))),r}cached(e,t,n){let r=lt(e);return this.wNAF(r,this.getPrecomputes(r,e,n),t)}unsafe(e,t,n,r){let i=lt(e);return i===1?this._unsafeLadder(e,t,r):this.wNAFUnsafe(i,this.getPrecomputes(i,e,n),t,r)}createCache(e,t){it(t,this.bits),ct.set(e,t),st.delete(e)}hasCache(e){return lt(e)!==1}};function ft(e,t,n,r){let i=t,a=e.ZERO,o=e.ZERO;for(;n>L||r>L;)n&R&&(a=a.add(i)),r&R&&(o=o.add(i)),i=i.double(),n>>=R,r>>=R;return{p1:a,p2:o}}function pt(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return Ge(t),t}else return Qe(e,{isLE:n})}function mt(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>L))throw Error(`CURVE.${e} must be positive bigint`)}let i=pt(t.p,n.Fp,r),a=pt(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 gt=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(f(e),d(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),h(r)}update(e){return p(this),this.iHash.update(e),this}digestInto(e){p(this),m(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 _t=(()=>{let e=((e,t,n)=>new gt(e,t).update(n).digest());return e.create=(e,t)=>new gt(e,t),e})(),vt=(e,t)=>(e+(e>=0?t:-t)/St)/t
|
|
8
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
9
|
+
;function yt(e,t,n){Te(`scalar`,e,B,n);let[[r,i],[a,o]]=t,s=vt(o*e,n),c=vt(-i*e,n),l=e-s*r-c*a,u=-s*i-c*o,d=l<B,f=u<B;d&&(l=-l),f&&(u=-u);let p=De(Math.ceil(Ee(n)/2))+V;if(l<B||l>=p||u<B||u>=p)throw Error(`splitScalar (endomorphism): failed for k`);return{k1neg:d,k1:l,k2neg:f,k2:u}}function bt(e){if(![`compact`,`recovered`,`der`].includes(e))throw Error(`Signature format must be "compact", "recovered", or "der"`);return e}function xt(e,t){ke(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&&bt(n.format),n}const z={Err:class extends Error{constructor(e=``){super(e)}},_tlv:{encode:(e,t)=>{let{Err:n}=z;if(ge(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=_e(r);if(i.length/2&128)throw new n(`tlv.encode: long form length too big`);let a=r>127?_e(i.length/2|128):``;return _e(e)+a+i+t},decode(e,t){let{Err:n}=z;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}=z;if(he(e),e<B)throw new t(`integer: negative integers are not allowed`);let n=_e(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}=z;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 ye(e)}},toSig(e){let{Err:t,_int:n,_tlv:r}=z,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}=z,r=t.encode(2,n.encode(e.r))+t.encode(2,n.encode(e.s));return t.encode(48,r)}};Object.freeze(z._tlv),Object.freeze(z._int),Object.freeze(z);const B=BigInt(0),V=BigInt(1),St=BigInt(2),Ct=BigInt(3),wt=BigInt(4);function Tt(e,t={}){let n=mt(`weierstrass`,e,t),r=n.Fp,i=n.Fn,a=n.CURVE,{h:o,n:s}=a;ke(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=Dt(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(Et(!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,Ct),wt),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 x(e){if(!(e instanceof w))throw Error(`Weierstrass Point expected`)}function S(e){if(!c||!c.basises)throw Error(`no endo`);return yt(e,c.basises,i.ORDER)}function C(e,t,n,i,a){return n=new w(r.mul(n.X,e),n.Y,n.Z),t=nt(i,t),n=nt(a,n),t.add(n)}class w{static BASE=new w(a.Gx,a.Gy,r.ONE);static ZERO=new w(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 w)throw Error(`projective point not allowed`);return r.is0(t)&&r.is0(n)?w.ZERO:new w(t,n,r.ONE)}static fromBytes(e){let t=w.fromAffine(h(k(e,void 0,`point`)));return t.assertValidity(),t}static fromHex(e){return w.fromBytes(ue(e))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=8,t=!0){return E.createCache(this,e),t||this.multiply(Ct),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){x(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 w(this.X,r.neg(this.Y),this.Z)}double(){let{a:e,b:t}=a,n=r.mul(t,Ct),{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 w(c,l,u)}add(e){x(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,Ct),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 w(l,u,d)}subtract(e){return x(e),this.add(e.negate())}is0(){return this.equals(w.ZERO)}multiply(e){let{endo:n}=t;if(!i.isValidNot0(e))throw RangeError(`invalid scalar: out of range`);let r,a,o=e=>E.cached(this,e,e=>rt(w,e));if(n){let{k1neg:t,k1:i,k2neg:s,k2:c}=S(e),{p:l,f:u}=o(i),{p:d,f}=o(c);a=u.add(f),r=C(n.beta,l,d,t,s)}else{let{p:t,f:n}=o(e);r=t,a=n}return rt(w,[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===B||r.is0())return w.ZERO;if(a===V)return r;if(E.hasCache(this))return this.multiply(a);if(n){let{k1neg:e,k1:t,k2neg:i,k2:o}=S(a),{p1:s,p2:c}=ft(w,r,t,o);return C(n.beta,s,c,e,i)}else return E.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===V?!0:e?e(w,this):E.unsafe(this,s).is0()}clearCofactor(){let{clearCofactor:e}=t;return o===V?this:e?e(w,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===V?this.is0():this.clearCofactor().is0()}toBytes(e=!0){return j(e,`isCompressed`),this.assertValidity(),m(w,this,e)}toHex(e=!0){return le(this.toBytes(e))}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let T=i.BITS,E=new dt(w,t.endo?Math.ceil(T/2):T);return T>=8&&w.BASE.precompute(8),Object.freeze(w.prototype),Object.freeze(w),w}function Et(e){return Uint8Array.of(e?2:3)}function Dt(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ot(e,t={}){let{Fn:n}=e,r=t.randomBytes===void 0?fe:t.randomBytes,i=Object.assign(Dt(e.Fp,n),{seed:Math.max(et(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,tt(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(!de(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=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 kt(e,t,n={}){let r=t;f(r),ke(n,{},{hmac:`function`,lowS:`boolean`,randomBytes:`function`,bits2int:`function`,bits2int_modN:`function`}),n=Object.assign({},n);let i=n.randomBytes===void 0?fe:n.randomBytes,a=n.hmac===void 0?(e,t)=>_t(r,e,t):n.hmac,{Fp:o,Fn:s}=e,{ORDER:c,BITS:l}=s,{keygen:u,getPublicKey:d,getSharedSecret:p,utils:m,lengths:h}=Ot(e,n),g={prehash:!0,lowS:typeof n.lowS!=`boolean`||n.lowS,format:`compact`,extraEntropy:!1},_=c*St+V<o.ORDER;function v(e){return e>c>>V}function y(e,t){if(!s.isValidNot0(t))throw Error(`invalid signature ${e}: out of range 1..Point.Fn.ORDER`);return t}function b(){if(_)throw Error(`"recovered" sig type is not supported for cofactor >2 curves`)}function x(e,t){bt(t);let n=h.signature;return k(e,t===`compact`?n:t===`recovered`?n+1:void 0)}class S{r;s;recovery;constructor(e,t,n){if(this.r=y(`r`,e),this.s=y(`s`,t),n!=null){if(b(),![0,1,2,3].includes(n))throw Error(`invalid recovery id`);this.recovery=n}Object.freeze(this)}static fromBytes(e,t=g.format){x(e,t);let n;if(t===`der`){let{r:t,s:n}=z.toSig(k(e));return new S(t,n)}t===`recovered`&&(n=e[0],t=`compact`,e=e.subarray(1));let r=h.signature/2,i=e.subarray(0,r),a=e.subarray(r,r*2);return new S(s.fromBytes(i),s.fromBytes(a),n)}static fromHex(e,t){return this.fromBytes(ue(e),t)}assertRecovery(){let{recovery:e}=this;if(e==null)throw Error(`invalid recovery id: must be present`);return e}addRecoveryBit(e){return new S(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(Et((i&1)==0),l)),d=s.inv(a),f=w(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 v(this.s)}toBytes(e=g.format){if(bt(e),e===`der`)return ue(z.hexFromSig(this));let{r:t,s:n}=this,r=s.toBytes(t),i=s.toBytes(n);return e===`recovered`?(b(),A(Uint8Array.of(this.assertRecovery()),r,i)):A(r,i)}toHex(e){return le(this.toBytes(e))}}Object.freeze(S.prototype),Object.freeze(S);let C=n.bits2int===void 0?function(e){if(e.length>8192)throw Error(`input is too large`);let t=ye(e),n=e.length*8-l;return n>0?t>>BigInt(n):t}:n.bits2int,w=n.bits2int_modN===void 0?function(e){return s.create(C(e))}:n.bits2int_modN,T=De(l);function E(e){return Te(`num < 2^`+l,e,B,T),s.toBytes(e)}function ee(e,t){return k(e,void 0,`message`),t?k(r(e),void 0,`prehashed message`):e}function te(t,n,r){let{lowS:a,prehash:o,extraEntropy:c}=xt(r,g);t=ee(t,o);let l=w(t),u=s.fromBytes(n);if(!s.isValidNot0(u))throw Error(`invalid private key`);let d=[E(u),E(l)];if(c!=null&&c!==!1){let e=c===!0?i(h.secretKey):c;d.push(k(e,void 0,`extraEntropy`))}let f=A(...d),p=l;function m(t){let n=C(t);if(!s.isValidNot0(n))return;let r=s.inv(n),i=e.BASE.multiply(n).toAffine(),o=s.create(i.x);if(o===B)return;let c=s.create(r*s.create(p+o*u));if(c===B)return;let l=(i.x===o?0:2)|Number(i.y&V),d=c;return a&&v(c)&&(d=s.neg(c),l^=1),new S(o,d,_?void 0:l)}return{seed:f,k2sig:m}}function ne(e,t,n={}){let{seed:i,k2sig:o}=te(e,t,n);return Oe(r.outputLen,s.BYTES,a)(i,o).toBytes(n.format)}function re(t,n,r,i={}){let{lowS:a,prehash:o,format:c}=xt(i,g);if(r=k(r,void 0,`publicKey`),n=ee(n,o),!de(t)){let e=t instanceof S?`, use sig.toBytes()`:``;throw Error(`verify expects Uint8Array signature`+e)}x(t,c);try{let i=S.fromBytes(t,c),o=e.fromBytes(r);if(a&&i.hasHighS())return!1;let{r:l,s:u}=i,d=w(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 D(e,t,n={}){let{prehash:r}=xt(n,g);return t=ee(t,r),S.fromBytes(e,`recovered`).recoverPublicKey(t).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:p,utils:m,lengths:h,Point:e,sign:ne,verify:re,recoverPublicKey:D,Signature:S,hash:r})}
|
|
10
|
+
/*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
|
|
11
|
+
const H=kt(Tt({p:BigInt(`0xffffffff00000001000000000000000000000000ffffffffffffffffffffffff`),n:BigInt(`0xffffffff00000000ffffffffffffffffbce6faada7179e84f3b9cac2fc632551`),h:BigInt(1),a:BigInt(`0xffffffff00000001000000000000000000000000fffffffffffffffffffffffc`),b:BigInt(`0x5ac635d8aa3a93e7b3ebbd55769886bc651d06b0cc53b0f63bce3c3e27d2604b`),Gx:BigInt(`0x6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296`),Gy:BigInt(`0x4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5`)}),se),At=`pkcs8`,jt=At,Mt=`spki`;function U(){let e=globalThis?.crypto?.subtle;if(typeof e==`object`&&e)return e;throw Error(`crypto.subtle must be defined`)}function Nt(e,t){return async function(n){let r=await e();return{secretKey:r,publicKey:await t(r)}}}function Pt(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 Ft(e,t){if(t.type!==e)throw Error(`invalid key type, expected ${e}`)}function It(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 U().importKey(n,t,e,!0,a);return Ft(`public`,r),r},async export(e,t){Ft(`public`,e);let n=await U().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=U(),s;if(a===`raw`){let t=n,a=Pt(r),c=new Uint8Array(a.length+t.length);c.set(a,0),c.set(t,a.length),s=await o.importKey(At,c,e,!0,i)}else t&&a===`jwk`&&(n={...n,key_ops:i}),s=await o.importKey(a,n,e,!0,i);return Ft(`private`,s),s},async export(e,t){let r=U();if(Ft(`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??jt,r=t.formatPub??Mt,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=jt){let n=await U().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=U(),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:Nt(u,l),utils:Object.freeze({randomSecretKey:u,convertPublicKey:s.convert,convertSecretKey:c.convert})}}function Lt(e,t){return{async sign(n,r,i={}){let a=await e.priv.import(r,i.formatSec??jt),o=await U().sign(t,a,n);return new Uint8Array(o)},async verify(n,r,i,a={}){let o=await e.pub.import(i,a.formatPub??Mt);return await U().verify(t,o,n,r)}}}function Rt(e,t,n){return{async getSharedSecret(r,i,a={}){let o=await e.priv.import(r,a.formatSec===void 0?jt:a.formatSec),s=await e.pub.import(i,a.formatPub===void 0?Mt:a.formatPub),c=await U().deriveBits({name:typeof t==`string`?t:t.name,public:s},o,8*n);return new Uint8Array(c)}}}function zt(e,t,n,r){let i={name:`ECDH`,namedCurve:e},a=It({name:`ECDSA`,namedCurve:e},!1,n,r),o=It(i,!0,n,r);return Object.freeze({name:e,isSupported:a.isSupported,getPublicKey:a.getPublicKey,keygen:Nt(a.utils.randomSecretKey,a.getPublicKey),...Lt(a,{name:`ECDSA`,hash:{name:t}}),...Rt(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 Bt=zt(`P-256`,`SHA-256`,32,`3041020100301306072a8648ce3d020106082a8648ce3d030107042730250201010420`),Vt={parseError:-32700,invalidRequest:-32600,methodNotFound:-32601,invalidParams:-32602,internalError:-32603,serverError:-32e3,clientNotConnected:-32001,configError:-32002,corruptedResponse:-32003,clientAborted:-32004,walletNotConnected:-32005,serverErrorForInteractionDelegation:-32006,userRejected:-32007};var W=class extends Error{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}}},Ht=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 Ut(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 Ht;return o.set(t,e=>{e.error?n.reject(new W(e.error.code,e.error.message,e.error.data)):n.resolve(e.result),o.delete(t)}),p({id:t,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{o.delete(t),n.reject(e)}),n.promise}function _(e,t){let n=h();return o.set(n,e=>{e.error?(console.error(`[RPC Client] Listener error:`,e.error),o.delete(n)):t(e.result)}),p({id:n,topic:e.method,data:{method:e.method,params:e.params}}).catch(e=>{console.error(`[RPC Client] Failed to send listener request:`,e),o.delete(n)}),()=>{o.delete(n)}}function v(){n.removeEventListener(`message`,f),o.clear()}return{request:g,listen:_,sendLifecycle:m,cleanup:v}}function Wt(e){return new TextEncoder().encode(JSON.stringify(e))}function Gt(e){try{return JSON.parse(new TextDecoder().decode(e))}catch{return null}}const Kt=`https://backend.frak.id`;function qt(e){return e.includes(`localhost:3000`)||e.includes(`localhost:3010`)}function Jt(e){return qt(e)?`https://localhost:3030`:e.includes(`wallet-dev.frak.id`)||e.includes(`wallet.gcp-dev.frak.id`)?`https://backend.gcp-dev.frak.id`:Kt}function Yt(e){if(e)return Jt(e);if(typeof window<`u`){let e=window.FrakSetup?.client?.config?.walletUrl;if(e)return Jt(e)}return Kt}var Xt=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 G;function Zt(){return G||={promiseCache:new Xt(1024),responseCache:new Xt(1024),failureCache:new Xt(1024)},G}async function Qt(e,{cacheKey:t,cacheTime:n=3e4}){let{promiseCache:r,responseCache:i,failureCache:a}=Zt();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 $t(){G&&(G.promiseCache.clear(),G.responseCache.clear(),G.failureCache.clear())}const K=`__frakSdkConfig`,en=`frak-config-cache`,tn=`frak-merchant-id`,nn={key:en},q=typeof window<`u`;function rn(){return{isResolved:!1,merchantId:``}}let J=null;function an(){if(!q)return null;try{let e=localStorage.getItem(nn.key);if(!e)return null;let t=JSON.parse(e);return t.config?.isResolved?(J=t,t):null}catch{return null}}function on(){return(J??an())?.config}function sn(){let e=J??an();return e?Date.now()-e.timestamp<3e4:!1}function cn(e){if(!(!q||!e.isResolved))try{let t={config:e,timestamp:Date.now()};localStorage.setItem(nn.key,JSON.stringify(t)),J=t}catch{}}function ln(){if(q){J=null;try{localStorage.removeItem(nn.key)}catch{}}}function un(){q&&(window[K]||(window[K]=on()??rn()))}function dn(){return q?(un(),window[K]??rn()):rn()}function fn(e){q&&window.dispatchEvent(new CustomEvent(`frak:config`,{detail:e}))}function pn(e){return e??(q?window.location.hostname:``)}async function mn(e,t,n){try{let r=Yt(t),i=n?`&lang=${encodeURIComponent(n)}`:``,a=await fetch(`${r}/user/merchant/resolve?domain=${encodeURIComponent(e)}${i}`);if(!a.ok){console.warn(`[Frak SDK] Merchant lookup failed for domain ${e}: ${a.status}`);return}let o=await a.json();if(q)try{sessionStorage.setItem(tn,o.merchantId)}catch{}return o}catch(e){console.warn(`[Frak SDK] Failed to fetch merchant config:`,e);return}}const Y={getConfig:dn,get isResolved(){return dn().isResolved},get isCacheFresh(){return sn()},setCacheScope(e,t){let n=`${e}:${t??``}`;nn.key=`${en}:${n}`,J=null},setConfig(e){if(q&&(window[K]=e),cn(e),fn(e),q&&e.merchantId)try{sessionStorage.setItem(tn,e.merchantId)}catch{}},reset(){let e=on()??rn();q&&(window[K]=e),fn(e)},clearCache(){if(ln(),$t(),q)try{sessionStorage.removeItem(tn)}catch{}},resolve(e,t,n){let r=pn(e);return r?Qt(async()=>{let e=await mn(r,t,n);if(!e)throw Error(`Config resolution returned empty`);return e},{cacheKey:`sdkConfig:${r}:${n??``}`,cacheTime:1/0}).catch(()=>void 0):Promise.resolve(void 0)},getMerchantId(){let e=dn();if(e.isResolved&&e.merchantId)return e.merchantId;if(q)try{return sessionStorage.getItem(tn)??void 0}catch{}},async resolveMerchantId(e,t){return Y.getMerchantId()||(await Y.resolve(e,t))?.merchantId}};async function hn(e){return a(se(e))}const gn=`frak-client-id`,_n=`frak-client-key`,vn=`frak-client-id-legacy`,yn={formatSec:`raw`,formatPub:`raw`};let bn=null;function xn(){return bn??=Bt.isSupported().then(e=>e?Bt:H).catch(()=>H),bn}const Sn=e=>Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``),Cn=e=>Uint8Array.from(e.match(/../g)??[],e=>Number.parseInt(e,16));function wn(){if(!(typeof window>`u`||!window.localStorage))return localStorage.getItem(vn)??void 0}function Tn(){typeof window>`u`||!window.localStorage||localStorage.removeItem(vn)}function En(){let e=localStorage.getItem(_n);if(!e)return null;if(!/^[0-9a-f]{64}$/i.test(e))throw Error(`[Frak SDK] Corrupt client key`);return Cn(e)}async function Dn(){if(typeof window>`u`||!window.localStorage)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(gn);try{let t=En(),n=t??H.utils.randomSecretKey(),r=await hn(H.getPublicKey(n,!1));if(t){e!==r&&localStorage.setItem(gn,r);let t=wn();return{clientId:r,...t&&{pendingLegacyId:t}}}return e&&localStorage.setItem(vn,e),localStorage.setItem(_n,Sn(n)),localStorage.setItem(gn,r),{clientId:r,...e&&{pendingLegacyId:e}}}catch(e){throw localStorage.removeItem(_n),e}}async function X(e){if(typeof window>`u`||!window.localStorage)return null;try{let t=En();if(!t)return null;let n=e.ts??Math.floor(Date.now()/1e3),r=i({op:e.op,merchantId:e.merchantId,anonymousId:e.anonymousId,binding:e.binding??new Uint8Array,ts:n}),a=await xn()===Bt?await Bt.sign(r,t,yn):H.sign(r,t,{prehash:!0});return c({v:1,pk:H.getPublicKey(t,!1),ts:n,sig:a})}catch{return null}}async function On({legacyId:e,derivedId:t,walletUrl:n}){if(!(typeof window>`u`)){if(!e||e===t){Tn();return}try{let r=await Y.resolveMerchantId();if(!r)return;let i=await X({op:`frak-merge-v1`,merchantId:r,anonymousId:t});if(!i)return;let a=Yt(n),o=await fetch(`${a}/user/identity/merge/initiate`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({sourceAnonymousId:t,merchantId:r,proof:i})});if(!o.ok){o.status<500&&Tn();return}let{mergeToken:s}=await o.json();if(!s)return;let c=await fetch(`${a}/user/identity/merge/execute`,{method:`POST`,headers:{Accept:`application/json`,"Content-Type":`application/json`},body:JSON.stringify({mergeToken:s,targetAnonymousId:e,merchantId:r})});if(c.ok){Tn();return}c.status<500&&Tn()}catch{}}}let Z=null,kn=null;async function An(e){return Z||kn||(kn=Dn().then(({clientId:t,pendingLegacyId:n})=>(Z=t,n&&On({legacyId:n,derivedId:t,walletUrl:e}),t)),kn)}function jn(){if(Z)return Z;An().catch(()=>{})}async function Mn(){return Z||An()}function Nn(e){return btoa(Array.from(e,e=>String.fromCharCode(e)).join(``)).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)}function Pn(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 Fn(e){return Nn(Wt(e))}function In(e,t,n,r,i,a,o){let s=Fn(Ln({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 Ln(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 Rn(e){return{...e,directExit:e.directExit??!e.redirectUrl}}async function zn(e,t){let{metadata:n,customizations:r,walletUrl:i}=e.config,a=jn()??await Mn(),o=await Y.resolveMerchantId()??``,s=a&&o?await X({op:`frak-sso-v1`,merchantId:o,anonymousId:a}):null;return{ssoUrl:In(i??`https://wallet.frak.id`,Rn(t),o,n.name,a,r?.css,s??void 0)}}const Bn=`menubar=no,status=no,scrollbars=no,fullscreen=no,width=500, height=800`,Vn=`frak-sso`;async function Hn(e,t){let{metadata:n,customizations:r}=e.config;if(`ssoUrl`in t)return Un(t.ssoUrl),await e.request({method:`frak_openSso`,params:[{},n.name,r?.css]})??{};let i=Rn(t);return i.openInSameWindow??!!i.redirectUrl?await e.request({method:`frak_openSso`,params:[i,n.name,r?.css]}):(Un(i.ssoPopupUrl??(await zn(e,i)).ssoUrl),await e.request({method:`frak_openSso`,params:[i,n.name,r?.css]})??{})}function Un(e){let t=window.open(e,Vn,Bn);if(!t)throw Error(`Popup was blocked. Please allow popups for this site.`);t.focus()}function Wn(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 Gn(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 Kn(e,t){let n=t.toLowerCase(),r=[...e.keys()].filter(e=>e.toLowerCase()===n);for(let t of r)e.delete(t)}const qn=/^0x[a-fA-F0-9]{40}$/;function Jn(e){return typeof e==`string`&&qn.test(e)}function Yn(e,t){return e.toLowerCase()===t.toLowerCase()}function Xn(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 Zn=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function Qn(e){let t=`0x`;for(let n=0;n<20;n++)t+=Zn[e[n]];return t}function $n(e){return`r`in e&&!(`v`in e)}function er(e){return`v`in e&&e.v===2}const tr=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function nr(e){return typeof e==`string`&&tr.test(e)}function rr(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 ir(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 ar(e){if(!nr(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`&&Jn(e.w);if(!t&&!n||t&&!nr(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(rr(e.m),a),a+=16,i.setUint32(a,e.t,!1),a+=4,t&&(r.set(rr(e.c),a),a+=16),n&&(r.set(Xn(e.w),a),a+=20),r}function or(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=ir(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=ir(e.subarray(a,a+16)),a+=16),r){let t=Qn(e.subarray(a,a+20));if(!Jn(t))return null;c.w=t,a+=20}return c}const sr=`fCtx`;function cr(e){if(e)try{if(er(e)){let t=ar(e);return t?Nn(t):void 0}return Nn(Xn(e.r))}catch(t){console.error(`Error compressing Frak context`,{e:t,context:e})}}function lr(e){if(!(!e||e.length===0))try{let t=Pn(e);if(t.length!==20)return or(t)||void 0;let n=Qn(t);if(Jn(n))return{r:n}}catch(t){console.error(`Error decompressing Frak context`,{e:t,context:e})}}function ur({url:e}){if(!e)return null;let t=Gn(new URL(e).searchParams,sr);return t?lr(t):null}function dr(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 fr(e,t){let n=dr(t??{});for(let[t,r]of Object.entries(n))r!==void 0&&r!==``&&(e.searchParams.has(t)||e.searchParams.set(t,r))}function pr({url:e,context:t,attribution:n}){if(!e)return null;let r=cr(t);if(!r)return null;let i=new URL(e);return Kn(i.searchParams,sr),i.searchParams.set(sr,r),fr(i,n),i.toString()}function mr(e){let t=new URL(e);return Kn(t.searchParams,sr),t.toString()}function hr({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?mr(n):pr({url:n,context:t}),r&&window.history.replaceState(null,``,r.toString())}const gr={compress:cr,decompress:lr,parse:ur,update:pr,remove:mr,replaceUrl:hr},_r={eur:`fr-FR`,usd:`en-US`,gbp:`en-GB`};function vr(e){return e&&e in _r?e:`eur`}function yr(e){return e?_r[e]??_r.eur:_r.eur}function br(e,t){let n=yr(t),r=vr(t);return e.toLocaleString(n,{style:`currency`,currency:r,minimumFractionDigits:0,maximumFractionDigits:2})}function xr(e){return e?`${e}Amount`:`eurAmount`}var Sr=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)}},Cr=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 Sr({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)}},wr=typeof document<`u`?document.currentScript:null;function Tr(e){return e.replace(/([-_][a-z])/gi,e=>e.toUpperCase().replace(`-`,``).replace(`_`,``))}var Er=class extends Cr{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=wr,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[Tr(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 Dr=`nexus-wallet-backup`,Or=`frakwallet://`;function kr(e){let t=e?.split(`-`)[0]?.toLowerCase();return t===`en`||t===`fr`?t:void 0}function Ar(){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 Mr(){let e=navigator.userAgent;return/Android/i.test(e)&&/Chrome\/\d+/i.test(e)}const Nr=Or.replace(`://`,``);function Pr(e){return`intent://${e.slice(13)}#Intent;scheme=${Nr};end`}function Fr(e,t){let n=t?.timeout??2500,r=!1,i=()=>{document.hidden&&(r=!0)};document.addEventListener(`visibilitychange`,i);let a=Mr()&&Ir(e)?Pr(e):e;window.location.href=a,setTimeout(()=>{document.removeEventListener(`visibilitychange`,i),r||t?.onFallback?.()},n)}function Ir(e){return e.startsWith(Or)}function Lr(){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 Q=Lr();function Rr(){return typeof navigator>`u`?!1:Q?!0:/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)}function zr(){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 Br=zr();function Vr(e){Q&&e.startsWith(`https://`)?window.location.href=`x-safari-https://${e.slice(8)}`:Q&&e.startsWith(`http://`)?window.location.href=`x-safari-http://${e.slice(7)}`:window.location.href=`https://backend.frak.id/common/social?u=${encodeURIComponent(e)}`}const $={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 Hr({walletBaseUrl:e,config:t}){let n=document.querySelector(`#frak-wallet`);n&&n.remove();let r=document.createElement(`iframe`);r.id=$.id,r.name=$.name,r.allow=$.allow,r.style.zIndex=$.style.zIndex.toString(),Wr({iframe:r,isVisible:!1});let i=t?.walletUrl??e??`https://wallet.frak.id`,a=await An(i).catch(e=>{console.warn(`[Frak SDK] Unable to derive a client id`,e)});return Kr(i),Kr(Yt(i)),r.src=Ur({walletUrl:i,clientId:a,preload:t?.preload}),new Promise(e=>{r.addEventListener(`load`,()=>e(r)),document.body.appendChild(r)})}function Ur({walletUrl:e,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 Wr({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 Gr(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 Kr(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 qr=Q&&Br;function Jr(e){e?localStorage.setItem(Dr,e):localStorage.removeItem(Dr)}function Yr(e,t){try{let n=new URL(e);if(!n.searchParams.has(`u`))return e;let r=Qr(window.location.href,t);return n.searchParams.delete(`u`),n.searchParams.append(`u`,r),n.toString()}catch{return e}}function Xr(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 Zr(e){return e.includes(`/common/social`)}function Qr(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 $r(e,t,n,r,i){if(i){let e=Yr(t,r);window.open(e,`_blank`);return}if(Ir(t)){let i=Yr(t,r);Fr(i,{onFallback:()=>{e.contentWindow?.postMessage({clientLifecycle:`deep-link-failed`,data:{originalUrl:i}},n)}})}else if(qr&&Zr(t))Xr(r);else{let e=Yr(t,r);window.location.href=e}}function ei({iframe:e,targetOrigin:t}){let n=new Ht;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`:Jr(a.backup);break;case`remove-backup`:localStorage.removeItem(Dr);break;case`show`:case`hide`:Wr({iframe:e,isVisible:i===`show`});break;case`redirect`:$r(e,a.baseRedirectUrl,t,a.mergeToken,a.openInNewTab);break}},isConnected:n.promise}}async function ti({config:e,iframe:t}){let n=e?.walletUrl??`https://wallet.frak.id`,r=e.metadata.lang??Ar(),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,e.walletUrl,r),o=await Mn().catch(()=>void 0),s=ei({iframe:t,targetOrigin:n}),c=new Ht,l=Date.now();if(!t.contentWindow)throw new W(Vt.configError,`The iframe does not have a content window`);let u=Ut({emittingTransport:t.contentWindow,listeningTransport:window,targetOrigin:n,middleware:[{async onRequest(e,t){if(!await s.isConnected)throw new W(Vt.clientNotConnected,`The iframe provider isn't connected yet`);return await c.promise,t}}],lifecycleHandlers:{iframeLifecycle:(e,t)=>{s.handleEvent(e)}}}),d=ni(u,s),f=async()=>{d(),u.cleanup(),t.remove(),$t(),Y.clearCache(),Y.reset()},p;{console.log(`[Frak SDK] Initializing OpenPanel`),p=new Er({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.2.1`,...o&&{user_anonymous_client_id:o}}),!0)}),p.setGlobalProperties({sdk_version:`1.2.1`,...o&&{user_anonymous_client_id:o}}),p.init(),p.track(`sdk_initialized`,{sdk_version:`1.2.1`});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=si({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 ni(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 ri(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 ii(e,t){if(!e)return;let n=e.global??{};e.setGlobalProperties({...n,merchant_id:t.merchantId,domain:t.domain??``})}async function ai(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 oi({merchantId:e,anonymousId:t,pendingMergeToken:n}){let r=n?await ai(n):void 0;if(n&&!r){let n=await X({op:`frak-install-v1`,merchantId:e,anonymousId:t});return n?{anonymousId:t,proofs:{install:n}}:void 0}let[i,a]=await Promise.all([r?X({op:`frak-merge-v1`,merchantId:e,anonymousId:t,binding:r}):Promise.resolve(null),X({op:`frak-install-v1`,merchantId:e,anonymousId:t})]);if(!(!i&&!a))return{anonymousId:t,proofs:{...i&&{merge:i},...a&&{install:a}}}}async function si({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;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=ri(e),i=o,s=window.location.href;return ii(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 oi({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(Dr);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 ci(e){return Gt(Pn(e))}async function li({config:e}){let t=ui(e),n=await Hr({config:t});if(!n){console.error(`Failed to create iframe`);return}let r=await ti({config:t,iframe:n});if(await r.waitForSetup,!await r.waitForConnection){console.error(`Failed to connect to client`);return}return r}function ui(e){let t=vr(e.metadata?.currency);return{...e,metadata:{...e.metadata,currency:t}}}function di({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}const fi=`frak:client`;function pi(){let e=new CustomEvent(fi);window.dispatchEvent(e)}function mi(e,t){if(window.FrakSetup?.client&&e===`add`){t();return}(e===`add`?window.addEventListener:window.removeEventListener)(fi,t,!1)}export{In as A,Wn as B,Gn as C,Nn as D,X as E,Kn as F,Vt as H,Qt as I,Yt as L,er as M,Bn as N,Y as O,$t as P,Hn as R,jn as S,gr as T,Ht as U,Pn as V,W,xr as _,Ur as a,Fn as b,li as c,ti as d,ci as f,Vr as g,Or as h,Rr as i,Vn as j,zn as k,Fr as l,di as m,mi as n,Br as o,Ar as p,$ as r,Gr as s,pi as t,Q as u,br as v,Mn as w,$n as x,vr as y,Yn as z};
|
package/cdn/components.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import(`https://cdn.jsdelivr.net/npm/@frak-labs/components@
|
|
1
|
+
import(`https://cdn.jsdelivr.net/npm/@frak-labs/components@beta/cdn/loader.js?v=1785399230525`);
|