1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/eth_getTransactionCount-SfiFiBQ5.js","assets/index-BkIlVDhX.js","assets/index-BWsPdaK_.css"])))=>i.map(i=>d[i]); 2import{u as U,E as I,F as v,G as d,H as h,I as P,J as k,g as O,K as m,a as f,L as $,p as E,M as g,_ as C,O as w,P as b,Q as B,R as M,S,T as z,U as R}from"./index-BkIlVDhX.js";import{signLoginPayload as Q}from"./sign-login-payload-BS5pcbMU.js";import{e as j}from"./eth_sendRawTransaction-DPdnXbFR.js";function G(i=32){return U(J(i))}function J(i=32){return globalThis.crypto.getRandomValues(new Uint8Array(i))}async function V(i){var r;const e=new I({storage:i.storage,clientId:i.client.clientId,ecosystemId:(r=i.ecosystem)==null?void 0:r.id});let t=await e.getGuestSessionId();t||(t=G(32),e.saveGuestSessionId(t));const a=d(i.client,i.ecosystem);return await(async()=>{const n=v({authOption:"guest",client:i.client,ecosystem:i.ecosystem}),s=await a(`${n}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t})});if(!s.ok)throw new Error("Failed to generate guest account");return await s.json()})()}async function q({client:i,ecosystem:e,tokenToLink:t,storage:a}){const o=d(i,e),r=h("inAppWallet"),n=await a.getAuthCookie();if(!n)throw new Error("Failed to link account, no user logged in");const s={Authorization:`Bearer iaw-auth-token:${n}`,"Content-Type":"application/json"},l=await o(`${r}/api/2024-05-05/account/connect`,{method:"POST",headers:s,body:JSON.stringify({accountAuthTokenToConnect:t})});if(!l.ok){const u=await l.json();throw new Error(u.message||"Failed to link account.")}const{linkedAccounts:c}=await l.json();return c??[]}async function H({client:i,ecosystem:e,storage:t}){const a=d(i,e),o=h("inAppWallet"),r=await t.getAuthCookie();if(!r)throw new Error("Failed to get linked accounts, no user logged in");const n={Authorization:`Bearer iaw-auth-token:${r}`,"Content-Type":"application/json"},s=await a(`${o}/api/2024-05-05/accounts`,{method:"GET",headers:n});if(!s.ok){const c=await s.json();throw new Error(c.message||"Failed to get linked accounts.")}const{linkedAccounts:l}=await s.json();return l??[]}function D(){return`${h("inAppWallet")}/api/2024-05-05/login/passkey/callback`}function N(i,e){return`${h("inAppWallet")}/api/2024-05-05/login/passkey?type=${i}${e?`&username=${e}`:""}`}async function x(i){var u,p;if(!i.passkeyClient.isAvailable())throw new Error("Passkeys are not available on this device");const e=d(i.client,i.ecosystem),t=i.username??Y(i.ecosystem),o=await(await e(N("sign-up",t))).json();if(!o.challenge)throw new Error("No challenge received");const r=o.challenge,n=await i.passkeyClient.register({name:t,challenge:r,rp:i.rp}),s={};(u=i.ecosystem)!=null&&u.partnerId&&(s["x-ecosystem-partner-id"]=i.ecosystem.partnerId),(p=i.ecosystem)!=null&&p.id&&(s["x-ecosystem-id"]=i.ecosystem.id);const c=await(await e(D(),{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify({type:"sign-up",authenticatorData:n.authenticatorData,credentialId:n.credentialId,serverVerificationId:o.serverVerificationId,clientData:n.clientData,username:t,credential:{publicKey:n.credential.publicKey,algorithm:n.credential.algorithm},origin:n.origin,rpId:i.rp.id})})).json();if(!c||!c.storedToken)throw new Error(`Error verifying passkey: ${c.message??"unknown error"}`);return await i.storage.savePasskeyCredentialId(n.credentialId),c}async function K(i){var u,p;if(!i.passkeyClient.isAvailable())throw new Error("Passkeys are not available on this device");const e=d(i.client,i.ecosystem),a=await(await e(N("sign-in"))).json();if(!a.challenge)throw new Error("No challenge received");const o=a.challenge,r=await i.storage.getPasskeyCredentialId()??void 0,n=await i.passkeyClient.authenticate({credentialId:r,challenge:o,rp:i.rp}),s={};(u=i.ecosystem)!=null&&u.partnerId&&(s["x-ecosystem-partner-id"]=i.ecosystem.partnerId),(p=i.ecosystem)!=null&&p.id&&(s["x-ecosystem-id"]=i.ecosystem.id);const c=await(await e(D(),{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify({type:"sign-in",authenticatorData:n.authenticatorData,credentialId:n.credentialId,serverVerificationId:a.serverVerificationId,clientData:n.clientData,signature:n.signature,origin:n.origin,rpId:i.rp.id})})).json();if(!c||!c.storedToken)throw new Error(`Error verifying passkey: ${c.message??"unknown error"}`);return await i.storage.savePasskeyCredentialId(n.credentialId),c}function Y(i){return`${(i==null?void 0:i.id)??"wallet"}-${new Date().toISOString()}`}async function X(i){const{wallet:e,chain:t}=i,a=await e.connect({client:i.client}),o=d(i.client,i.ecosystem),r=await(async()=>{const l=P({authOption:"wallet",client:i.client,ecosystem:i.ecosystem}),c=await o(`${l}&address=${a.address}&chainId=${t.id}`);if(!c.ok)throw new Error("Failed to generate SIWE login payload");return await c.json()})(),{signature:n}=await Q({payload:r,account:a});return await(async()=>{const l=v({authOption:"wallet",client:i.client,ecosystem:i.ecosystem}),c=await o(`${l}&signature=${n}&payload=${encodeURIComponent(r)}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({signature:n,payload:r})});if(!c.ok)throw new Error("Failed to verify SIWE signature");return await c.json()})()}async function T({authToken:i,client:e,ecosystem:t}){const o=await d(e,t)(`${h("inAppWallet")}/api/2024-05-05/accounts`,{method:"GET",headers:{"Content-Type":"application/json","x-thirdweb-client-id":e.clientId,Authorization:`Bearer embedded-wallet-token:${i}`}});if(!o.ok){if(console.log("response",o.status),o.status===401)return;const r=await o.json();throw console.log("result",r),new Error(`Failed to get user status: ${r.error}`)}return await o.json()}async function Z({client:i,ecosystem:e,payload:{message:t,isRaw:a},storage:o}){const r=d(i,e),n=await o.getAuthCookie(),s=await r(`${h("inAppWallet")}/api/v1/enclave-wallet/sign-message`,{method:"POST",headers:{"Content-Type":"application/json","x-thirdweb-client-id":i.clientId,Authorization:`Bearer embedded-wallet-token:${n}`},body:k({messagePayload:{message:t,isRaw:a}})});if(!s.ok)throw new Error("Failed to sign message");return await s.json()}async function ee({client:i,ecosystem:e,payload:t,storage:a}){console.log("payload",t);const o=d(i,e),r=await a.getAuthCookie(),n=await o(`${h("inAppWallet")}/api/v1/enclave-wallet/sign-transaction`,{method:"POST",headers:{"Content-Type":"application/json","x-thirdweb-client-id":i.clientId,Authorization:`Bearer embedded-wallet-token:${r}`},body:k({transactionPayload:t})});if(!n.ok)throw new Error("Failed to sign transaction");return(await n.json()).signature}async function te({client:i,ecosystem:e,payload:t,storage:a}){const o=d(i,e),r=await a.getAuthCookie(),n=await o(`${h("inAppWallet")}/api/v1/enclave-wallet/sign-typed-data`,{method:"POST",headers:{"Content-Type":"application/json","x-thirdweb-client-id":i.clientId,Authorization:`Bearer embedded-wallet-token:${r}`},body:k({...t})});if(!n.ok)throw new Error("Failed to sign typed data");return await n.json()}class ae{constructor({client:e,ecosystem:t,address:a,storage:o}){Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ecosystem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"address",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"localStorage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.client=e,this.ecosystem=t,this.address=a,this.localStorage=o}async postWalletSetUp(e){await this.localStorage.saveAuthCookie(e.storedToken.cookieString)}async getUserWalletStatus(){var r,n;const e=await this.localStorage.getAuthCookie();if(!e)return{status:"Logged Out"};const t=await T({authToken:e,client:this.client,ecosystem:this.ecosystem});if(!t)return{status:"Logged Out"};const a=t.wallets[0],o={email:(r=t.linkedAccounts.find(s=>s.details.email!==void 0))==null?void 0:r.details.email,phoneNumber:(n=t.linkedAccounts.find(s=>s.details.phone!==void 0))==null?void 0:n.details.phone,userWalletId:t.id||"",recoveryShareManagement:"ENCLAVE"};return a?{status:"Logged In, Wallet Initialized",walletAddress:a.address,authDetail
2s:o,account:await this.getAccount()}:{status:"Logged In, Wallet Uninitialized",authDetails:o}}async getAccount(){const e=this.client,t=this.ecosystem,a=this.localStorage,o=async r=>{const n=m({client:e,chain:f(r.chainId)}),s={to:r.to??void 0,data:r.data?g(r.data):void 0,value:r.value?g(r.value):void 0,gas:r.gas?g(r.gas+r.gas/BigInt(10)):void 0,nonce:r.nonce?g(r.nonce):g(await C(async()=>{const{eth_getTransactionCount:l}=await import("./eth_getTransactionCount-SfiFiBQ5.js");return{eth_getTransactionCount:l}},__vite__mapDeps([0,1,2])).then(({eth_getTransactionCount:l})=>l(n,{address:this.address,blockTag:"pending"}))),chainId:g(r.chainId)};return r.maxFeePerGas?(s.maxFeePerGas=g(r.maxFeePerGas),s.maxPriorityFeePerGas=r.maxPriorityFeePerGas?g(r.maxPriorityFeePerGas):void 0,s.type=2):(s.gasPrice=r.gasPrice?g(r.gasPrice):void 0,s.type=0),ee({client:e,ecosystem:t,storage:a,payload:s})};return{address:O(this.address),async signTransaction(r){if(!r.chainId)throw new Error("chainId required in tx to sign");return o({chainId:r.chainId,...r})},async sendTransaction(r){const n=m({client:e,chain:f(r.chainId)}),s=await o(r);return{transactionHash:await j(n,s)}},async signMessage({message:r}){const n=typeof r=="string"?{message:r,isRaw:!1}:{message:typeof r.raw=="string"?r.raw:$(r.raw),isRaw:!0},{signature:s}=await Z({client:e,ecosystem:t,payload:n,storage:a});return s},async signTypedData(r){const n=E(r),{signature:s}=await te({client:e,ecosystem:t,payload:n,storage:a});return s}}}}const ie={height:"100%",width:"100%",border:"none",backgroundColor:"transparent",colorScheme:"light",position:"fixed",top:"0px",right:"0px",zIndex:"2147483646",display:"none",pointerEvents:"all"},y=new Map;class ne{constructor({link:e,baseUrl:t,iframeId:a,container:o=document.body,onIframeInitialize:r}){Object.defineProperty(this,"iframe",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"POLLING_INTERVAL_SECONDS",{enumerable:!0,configurable:!0,writable:!0,value:1.4}),Object.defineProperty(this,"iframeBaseUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.iframeBaseUrl=t;let n=document.getElementById(a);const s=new URL(e);if(!n||n.src!==s.href){n=document.createElement("iframe");const l={...ie};Object.assign(n.style,l),n.setAttribute("id",a),n.setAttribute("fetchpriority","high"),o.appendChild(n),n.src=s.href;const c=u=>{if(u.data.eventType==="ewsIframeLoaded"){if(window.removeEventListener("message",c),!n){console.warn("thirdweb iFrame not found");return}this.onIframeLoadHandler(n,r)()}};window.addEventListener("message",c)}this.iframe=n}async onIframeLoadedInitVariables(){return{}}onIframeLoadHandler(e,t){return async()=>{var n;const a=new MessageChannel,o=new Promise((s,l)=>{a.port1.onmessage=c=>{const{data:u}=c;a.port1.close(),u.success||l(new Error(u.error)),y.set(e.src,!0),t&&t(),s(!0)}});(n=e==null?void 0:e.contentWindow)==null||n.postMessage({eventType:"initIframe",data:await this.onIframeLoadedInitVariables()},this.iframeBaseUrl,[a.port2]),await o}}async call({procedureName:e,params:t,showIframe:a=!1}){var n;for(;!y.get(this.iframe.src);)await w(this.POLLING_INTERVAL_SECONDS*1e3);a&&(this.iframe.style.display="block",await w(.005*1e3));const o=new MessageChannel,r=new Promise((s,l)=>{o.port1.onmessage=async c=>{const{data:u}=c;o.port1.close(),a&&(await w(.1*1e3),this.iframe.style.display="none"),u.success?s(u.data):l(new Error(u.error))}});return(n=this.iframe.contentWindow)==null||n.postMessage({eventType:e,data:t},this.iframeBaseUrl,[o.port2]),r}destroy(){y.delete(this.iframe.src)}}class re extends ne{constructor({clientId:e,baseUrl:t,ecosystem:a}){super({iframeId:oe+((a==null?void 0:a.id)||""),link:se({clientId:e,path:B,ecosystem:a,baseUrl:t}).href,baseUrl:t,container:document.body}),Object.defineProperty(this,"clientId",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ecosystem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.clientId=e,this.ecosystem=a}async onIframeLoadedInitVariables(){var t,a,o;const e=new I({storage:b,clientId:this.clientId,ecosystemId:(t=this.ecosystem)==null?void 0:t.id});return{authCookie:await e.getAuthCookie(),deviceShareStored:await e.getDeviceShare(),walletUserId:await e.getWalletUserId(),clientId:this.clientId,partnerId:(a=this.ecosystem)==null?void 0:a.partnerId,ecosystemId:(o=this.ecosystem)==null?void 0:o.id}}}function se({clientId:i,baseUrl:e,path:t,ecosystem:a,queryParams:o}){var n;
2const r=new URL(`${t}`,e);if(o)for(const s of Object.keys(o))r.searchParams.set(s,((n=o[s])==null?void 0:n.toString())||"");return r.searchParams.set("clientId",i),(a==null?void 0:a.partnerId)!==void 0&&r.searchParams.set("partnerId",a.partnerId),(a==null?void 0:a.id)!==void 0&&r.searchParams.set("ecosystemId",a.id),r}const oe="thirdweb-in-app-wallet-iframe";async function ce({authToken:i,client:e,ecosystem:t}){const o=await d(e,t)(`${h("inAppWallet")}/api/v1/enclave-wallet/generate`,{method:"POST",headers:{"Content-Type":"application/json","x-thirdweb-client-id":e.clientId,Authorization:`Bearer embedded-wallet-token:${i}`}});if(!o.ok)throw new Error("Failed to generate wallet");const{wallet:r}=await o.json();return r}class le{constructor({baseUrl:e,querier:t,preLogin:a,postLogin:o,client:r,ecosystem:n}){Object.defineProperty(this,"LoginQuerier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"preLogin",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"postLogin",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"baseUrl",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ecosystem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.baseUrl=e,this.LoginQuerier=t,this.preLogin=a,this.postLogin=o,this.client=r,this.ecosystem=n}async sendEmailLoginOtp({email:e}){return await this.LoginQuerier.call({procedureName:"sendThirdwebEmailLoginOtp",params:{email:e}})}async sendSmsLoginOtp({phoneNumber:e}){return await this.LoginQuerier.call({procedureName:"sendThirdwebSmsLoginOtp",params:{phoneNumber:e}})}}class ue extends le{async authenticateWithModal(){return this.LoginQuerier.call({procedureName:"loginWithThirdwebModal",params:void 0,showIframe:!0})}async loginWithModal(){await this.preLogin();const e=await this.authenticateWithModal();return this.postLogin(e)}async authenticateWithIframe({email:e}){return this.LoginQuerier.call({procedureName:"loginWithThirdwebModal",params:{email:e},showIframe:!0})}async loginWithIframe({email:e}){await this.preLogin();const t=await this.authenticateWithIframe({email:e});return this.postLogin(t)}async authenticateWithCustomJwt({encryptionKey:e,jwt:t}){if(!e||e.length===0)throw new Error("Encryption key is required for custom jwt auth");return this.LoginQuerier.call({procedureName:"loginWithCustomJwt",params:{encryptionKey:e,jwt:t}})}async loginWithCustomJwt({encryptionKey:e,jwt:t}){if(!e||e.length===0)throw new Error("Encryption key is required for custom jwt auth");await this.preLogin();const a=await this.authenticateWithCustomJwt({encryptionKey:e,jwt:t});return this.postLogin(a)}async authenticateWithCustomAuthEndpoint({encryptionKey:e,payload:t}){return this.LoginQuerier.call({procedureName:"loginWithCustomAuthEndpoint",params:{encryptionKey:e,payload:t}})}async loginWithCustomAuthEndpoint({encryptionKey:e,payload:t}){if(!e||e.length===0)throw new Error("Encryption key is required for custom auth");await this.preLogin();const a=await this.authenticateWithCustomAuthEndpoint({encryptionKey:e,payload:t});return this.postLogin(a)}async authenticateWithEmailOtp({email:e,otp:t,recoveryCode:a}){return this.LoginQuerier.call({procedureName:"verifyThirdwebEmailLoginOtp",params:{email:e,otp:t,recoveryCode:a}})}async loginWithEmailOtp({email:e,otp:t,recoveryCode:a}){const o=await this.authenticateWithEmailOtp({email:e,otp:t,recoveryCode:a});return this.postLogin(o)}async authenticateWithSmsOtp({phoneNumber:e,otp:t,recoveryCode:a}){return this.LoginQuerier.call({procedureName:"verifyThirdwebSmsLoginOtp",params:{phoneNumber:e,otp:t,recoveryCode:a}})}async loginWithSmsOtp({phoneNumber:e,otp:t,recoveryCode:a}){const o=await this.authenticateWithSmsOtp({phoneNumber:e,otp:t,recoveryCode:a});return this.postLogin(o)}}class de{constructor({client:e,querier:t,onAuthSuccess:a,ecosystem:o,baseUrl:r,localStorage:n}){Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ecosystem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"AuthQuerier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"localStorage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onAuthSuccess",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"BaseLogin",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.client=e,this.ecosystem=o,this.AuthQuerier=t,this.localStorage=n,this.onAuthSuccess=a,this.BaseLogin=new ue({postLogin:async s=>this.postLogin(s),preLogin:async()=>{await this.preLogin()},ecosystem:o,querier:t,client:e,baseUrl:r})}async preLogin(){await this.logout()}async postLogin({storedToken:e,walletDetails:t}){return e.shouldStoreCookieString&&await this.localStorage.saveAuthCookie(e.co
2okieString),await this.onAuthSuccess({storedToken:e,walletDetails:t})}async loginWithAuthToken(e,t){var r;await this.preLogin();const a=await T({authToken:e.storedToken.cookieString,client:this.client,ecosystem:this.ecosystem});if(!a)throw new Error("Cannot login, no user found for auth token");if(a.wallets.length>0&&((r=a.wallets[0])==null?void 0:r.type)==="enclave")return this.postLogin({storedToken:e.storedToken,walletDetails:{walletAddress:a.wallets[0].address}});if(a.wallets.length===0&&this.ecosystem){const n=await ce({authToken:e.storedToken.cookieString,client:this.client,ecosystem:this.ecosystem});return this.postLogin({storedToken:e.storedToken,walletDetails:{walletAddress:n.address}})}const o=await this.AuthQuerier.call({procedureName:"loginWithStoredTokenDetails",params:{storedToken:e.storedToken,recoveryCode:t}});return this.postLogin(o)}async loginWithModal(){return this.BaseLogin.loginWithModal()}async authenticateWithModal(){return this.BaseLogin.authenticateWithModal()}async loginWithIframe(e){return this.BaseLogin.loginWithIframe(e)}async authenticateWithIframe(e){return this.BaseLogin.authenticateWithIframe(e)}async loginWithCustomJwt(e){return this.BaseLogin.loginWithCustomJwt(e)}
2async authenticateWithCustomJwt(e){return this.BaseLogin.authenticateWithCustomJwt(e)}async loginWithCustomAuthEndpoint(e){return this.BaseLogin.loginWithCustomAuthEndpoint(e)}async authenticateWithCustomAuthEndpoint(e){return this.BaseLogin.authenticateWithCustomAuthEndpoint(e)}async sendEmailLoginOtp({email:e}){return this.BaseLogin.sendEmailLoginOtp({email:e})}async sendSmsLoginOtp({phoneNumber:e}){return this.BaseLogin.sendSmsLoginOtp({phoneNumber:e})}async loginWithEmailOtp(e){return await this.preLogin(),this.BaseLogin.loginWithEmailOtp(e)}async authenticateWithEmailOtp(e){return this.BaseLogin.authenticateWithEmailOtp(e)}async loginWithSmsOtp(e){return await this.preLogin(),this.BaseLogin.loginWithSmsOtp(e)}async authenticateWithSmsOtp(e){return this.BaseLogin.authenticateWithSmsOtp(e)}async logout(){this.AuthQuerier&&await this.AuthQuerier.call({procedureName:"logout",params:void 0});const e=await this.localStorage.removeAuthCookie(),t=await this.localStorage.removeWalletUserId();return{success:e||t}}}const he=async i=>{const{client:e,ecosystem:t}=i,a=P({client:e,ecosystem:t,authOption:i.strategy}),o={"Content-Type":"application/json","x-client-id":e.clientId};t!=null&&t.id&&(o["x-ecosystem-id"]=t.id),t!=null&&t.partnerId&&(o["x-ecosystem-partner-id"]=t.partnerId);const r=(()=>{switch(i.strategy){case"email":return{email:i.email};case"phone":return{phone:i.phoneNumber}}})(),n=await fetch(a,{method:"POST",headers:o,body:JSON.stringify(r)});if(!n.ok)throw new Error("Failed to send verification code");return await n.json()},A=async i=>{const{client:e,ecosystem:t}=i,a=v({authOption:i.strategy,client:i.client,ecosystem:i.ecosystem}),o={"Content-Type":"application/json","x-client-id":e.clientId};t!=null&&t.id&&(o["x-ecosystem-id"]=t.id),t!=null&&t.partnerId&&(o["x-ecosystem-partner-id"]=t.partnerId);const r=(()=>{switch(i.strategy){case"email":return{email:i.email,code:i.verificationCode};case"phone":return{phone:i.phoneNumber,code:i.verificationCode}}})(),n=await fetch(a,{method:"POST",headers:o,body:JSON.stringify(r)});if(!n.ok)throw new Error("Failed to verify verification code");return await n.json()};class ge{constructor({client:e,ecosystem:t,querier:a,localStorage:o}){Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ecosystem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"walletManagerQuerier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"localStorage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.client=e,this.ecosystem=t,this.walletManagerQuerier=a,this.localStorage=o}async postWalletSetUp(e){e.deviceShareStored&&await this.localStorage.saveDeviceShare(e.deviceShareStored,e.storedToken.authDetails.userWalletId)}async getUserWalletStatus(){const e=await this.walletManagerQuerier.call({procedureName:"getUserStatus",params:void 0});return e.status==="Logged In, Wallet Initialized"?{status:"Logged In, Wallet Initialized",...e.user,account:await this.getAccount()}:e.status==="Logged In, New Device"?{status:"Logged In, New Device",...e.user}:e.status==="Logged In, Wallet Uninitialized"?{status:"Logged In, Wallet Uninitialized",...e.user}:{status:e.status}}async getAccount(){var n;const e=this.walletManagerQuerier,t=this.client,a=(n=this.ecosystem)==null?void 0:n.partnerId,{address:o}=await e.call({procedureName:"getAddress",params:void 0}),r=async s=>{const l={to:s.to??void 0,data:s.data,value:s.value,gasLimit:s.gas,nonce:s.nonce,chainId:s.chainId};s.maxFeePerGas?(l.accessList=s.accessList,l.maxFeePerGas=s.maxFeePerGas,l.maxPriorityFeePerGas=s.maxPriorityFeePerGas,l.type=2):(l.gasPrice=s.gasPrice,l.type=0);const c=S().rpc,{signedTransaction:u}=await e.call({procedureName:"signTransaction",params:{transaction:l,chainId:s.chainId,partnerId:a,rpcEndpoint:`https://${s.chainId}.${c}`}});return u};return{address:O(o),async signTransaction(s){if(!s.chainId)throw new Error("chainId required in tx to sign");return r({...s,chainId:s.chainId})},async sendTransaction(s){const l=m({client:t,chain:f(s.chainId)}),c=await r(s);return{transactionHash:await j(l,c)}},async signMessage({message:s}){const l=typeof s=="string"?s:s.raw instanceof Uint8Array?s.raw:M(s.raw),{signedMessage:c}=await e.call({procedureName:"signMessage",params:{message:l,partnerId:a,chainId:1}});return c},async signTypedData(s){var W;const l=E(s);(W=l.types)!=null&&W.EIP712Domain&&(l.types.EIP712Domain=void 0);const c=l.domain,u=c==null?void 0:c.chainId,L={...c!=null&&c.verifyingContract?{verifyingContract:c==null?void 0:c.verifyingContract}:{},name:c==null?void 0:c.name,version:c==null?void 0:c.version};u&&(L.chainId=u);const F=S().rpc,{signedTypedData:_}=await e.call({procedureName:"signTypedDataV4",params:{domain:L,types:l.types,message:l.message,chainId:u||1,partnerId:a,rpcEndpoint:`https://${u}.${F}`}});return _}}}}class fe{isClientIdLegacyPaper(e){return e.indexOf("-")>0&&e.length===36}constructor({client:e,onAuthSuccess:t,ecosystem:a,passkeyDomain:o}
2){if(Object.defineProperty(this,"client",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"ecosystem",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"querier",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"localStorage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"wallet",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"auth",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"passkeyDomain",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.isClientIdLegacyPaper(e.clientId))throw new Error("You are using a legacy clientId. Please use the clientId found on the thirdweb dashboard settings page");const r=h("inAppWallet");this.client=e,this.ecosystem=a,this.passkeyDomain=o,this.localStorage=new I({storage:b,clientId:e.clientId,ecosystemId:a==null?void 0:a.id}),this.querier=new re({clientId:e.clientId,ecosystem:a,baseUrl:r}),this.auth=new de({client:e,querier:this.querier,baseUrl:r,localStorage:this.localStorage,ecosystem:a,onAuthSuccess:async n=>{if(t==null||t(n),this.ecosystem&&n.storedToken.authDetails.walletType==="sharded"&&!await this.querier.call({procedureName:"migrateFromShardToEnclave",params:{storedToken:n.storedToken}}))throw new Error("Failed to migrate from sharded to enclave wallet");if(await this.initializeWallet(n.storedToken.cookieString),!this.wallet)throw new Error("Failed to initialize wallet");const s="deviceShareStored"in n.walletDetails?n.walletDetails.deviceShareStored:void 0;return await this.wallet.postWalletSetUp({storedToken:n.storedToken,deviceShareStored:s}),n.storedToken.authDetails.walletType!=="enclave"&&await this.querier.call({procedureName:"initIframe",params:{partnerId:a==null?void 0:a.partnerId,ecosystemId:a==null?void 0:a.id,clientId:this.client.clientId,deviceShareStored:"deviceShareStored"in n.walletDetails?n.walletDetails.deviceShareStored:null,walletUserId:n.storedToken.authDetails.userWalletId,authCookie:n.storedToken.cookieString}}),{user:{status:"Logged In, Wallet Initialized",authDetails:n.storedToken.authDetails,account:await this.wallet.getAccount(),walletAddress:n.walletDetails.walletAddress}}}})}async initializeWallet(e){const t=await this.localStorage.getAuthCookie();if(!e&&t===null)throw new Error("No auth token provided and no stored auth token found to initialize the wallet");const a=await T({authToken:e||t,client:this.client,ecosystem:this.ecosystem});if(!a)throw new Error("Cannot initialize wallet, no user logged in");if(a.wallets.length===0)throw new Error("Cannot initialize wallet, this user does not have a wallet generated yet");if(a.wallets[0].type==="enclave"){this.wallet=new ae({client:this.client,ecosystem:this.ecosystem,address:a.wallets[0].address,storage:this.localStorage});return}this.wallet=new ge({client:this.client,ecosystem:this.ecosystem,querier:this.querier,localStorage:this.localStorage})}async getUser(){if(!this.wallet){const e=await this.localStorage.getAuthCookie();if(!e)return{status:"Logged Out"};await this.initializeWallet(e)}if(!this.wallet)throw new Error("Wallet not initialized");return await this.wallet.getUserWalletStatus()}getAccount(){if(!this.wallet)throw new Error("Wallet not initialized");return this.wallet.getAccount()}async preAuthenticate(e){return he({...e,client:this.client,ecosystem:this.ecosystem})}authenticateWithRedirect(e,t,a){z({authOption:e,client:this.client,ecosystem:this.ecosystem,redirectUrl:a,mode:t})}async loginWithAuthToken(e){return this.auth.loginWithAuthToken(e)}async authenticate(e){const t=e.strategy;switch(t){case"email":return A({...e,client:this.client,ecosystem:this.ecosystem});case"phone":return A({...e,client:this.client,ecosystem:this.ecosystem});case"jwt":return this.auth.authenticateWithCustomJwt({jwt:e.jwt,encryptionKey:e.encryptionKey});case"passkey":return this.passkeyAuth(e);case"auth_endpoint":return this.auth.authenticateWithCustomAuthEndpoint({payload:e.payload,encryptionKey:e.encryptionKey});case"iframe_email_verification":return this.auth.authenticateWithIframe({email:e.email});case"iframe":return this.auth.authenticateWithModal();case"apple":case"facebook":case"google":case"telegram":case"farcaster":case"line":case"x":case"coinbase":case"discord":return R({authOption:t,client:this.client,ecosystem:this.ecosystem,closeOpenedWindow:e.closeOpenedWindow,openedWindow:e.openedWindow});case"guest":return V({client:this.client,ecosystem:this.ecosystem,storage:b});case"wallet":return X({ecosystem:this.ecosystem,client:this.client,wallet:e.wallet,chain:e.chain})}}async connect(e){const t=e.strategy;switch(t){case"jwt":return this.auth.loginWithCustomJwt({jwt:e.jwt,encryptionKey:e.encryptionKey});case"auth_endpoint":return this.auth.loginWithCustomAuthEndpoint({payload:e.payload,encryptionKey:e.encryptionKey});case"iframe_email_verification":return this.auth.loginWithIframe({email:e.email});case"iframe":return this.auth.loginWithModal();case"passkey":{const a=await this.passkeyAuth(e);return this.loginWithAuthToken(a)}case"phone":case"email":case"wallet":case"apple":case"facebook":case"google":case"farcaster":case"telegram":case"line":case"x":case"guest":case"coinbase":case"discord":{const a=await this.authenticate(e);return await this.auth.loginWithAuthToken(a)}default:pe(t)}}async logout(){return await this.auth.logout()}async passkeyAuth(e){const{PasskeyWebClient:t}=await C(async()=>{const{PasskeyWebClient:r}=await import("./index-BkIlVDhX.js").then(n=>n.dF);return{PasskeyWebClient:r}},__vite__mapDeps([1,2])),a=new t,o=this.localStorage;return e.type==="sign-up"?x({client:this.client,ecosystem:this.ecosystem,username:e.passkeyName,passkeyClient:a,storage:o,rp:{id:this.passkeyDomain??window.location.hostname,name:this.passkeyDomain??window.document.title}}
2):K({client:this.client,ecosystem:this.ecosystem,passkeyClient:a,storage:o,rp:{id:this.passkeyDomain??window.location.hostname,name:this.passkeyDomain??window.document.title}})}async linkProfile(e){const{storedToken:t}=await this.authenticate(e);return await q({client:e.client,tokenToLink:t.cookieString,storage:this.localStorage})}async getProfiles(){return H({client:this.client,ecosystem:this.ecosystem,storage:this.localStorage})}}function pe(i,e){throw new Error(`Invalid param: ${i}`)}export{fe as InAppWebConnector};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.