diff --git a/Web/index.js b/Web/index.js index 0156705..d44b316 100644 --- a/Web/index.js +++ b/Web/index.js @@ -1,4 +1,4 @@ -!function(e,t,r,n,i){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s="function"==typeof a[n]&&a[n],o=s.cache||{},c="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function f(t,r){if(!o[t]){if(!e[t]){var i="function"==typeof a[n]&&a[n];if(!r&&i)return i(t,!0);if(s)return s(t,!0);if(c&&"string"==typeof t)return c(t);var u=Error("Cannot find module '"+t+"'");throw u.code="MODULE_NOT_FOUND",u}l.resolve=function(r){var n=e[t][1][r];return null!=n?n:r},l.cache={};var d=o[t]=new f.Module(t);e[t][0].call(d.exports,l,d,d.exports,this)}return o[t].exports;function l(e){var t=l.resolve(e);return!1===t?{}:f(t)}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=o,f.parent=s,f.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(f,"root",{get:function(){return a[n]}}),a[n]=f;for(var u=0;u{let t=JSON.stringify(e);if(console.log(`callbackToGame: ${t}`),void 0!==window.ue){if(void 0===window.ue.jsconnector){let e="Unreal JSConnector not defined";throw console.error(e),Error(e)}window.ue.jsconnector.sendtogame(t)}else if("undefined"!=typeof blu_event)blu_event("sendtogame",t);else if("undefined"!=typeof UnityPostMessage)UnityPostMessage(t);else if("undefined"!==window.Unity)window.Unity.call(t);else{let e="No available game callbacks to call from ImmutableSDK game-bridge";throw console.error(e),Error(e)}},b=()=>{if(null==n)throw Error("No Passport client");return n},g=e=>null!=e?(i=e,console.log("IMX provider set"),!0):(console.log("No IMX provider"),!1),y=()=>{if(null==i)throw Error("No IMX provider");return i},v=e=>null!=e?(a=e,console.log("zkEvm provider set"),!0):(console.log("No zkEvm provider"),!1),w=()=>{if(null==a)throw Error("No zkEvm provider");return a},_=e=>Date.now()-e;(0,u.track)(l,"loadedGameBridge",{sdkVersionTag:h}),window.callFunction=async e=>{console.log(`Call function ${e}`);let t=null,r=null,o=Date.now();try{let E=JSON.parse(e);t=E.fxName,r=E.requestId;let A=E.data;switch((0,u.track)(l,"startedCallFunction",{function:t,requestId:r}),t){case p.init:{let e=JSON.parse(A),i=e?.redirectUri;if(!n){let t={baseConfig:new f.ImmutableConfiguration({environment:e.environment}),clientId:e.clientId,audience:"platform_api",scope:"openid offline_access profile email transact",redirectUri:i??"https://localhost:3000/",logoutRedirectUri:e?.logoutRedirectUri,crossSdkBridgeEnabled:!0};n=new c.Passport(t),(0,u.trackDuration)(l,"initialisedPassport",_(o))}m({responseFor:t,requestId:r,success:!0,error:null});let{engineVersion:a}=e;s={gameBridgeTag:h,gameBridgeSha:"b0b671e3b2907c331bb2a9e5cc48cfaf32e1e2af",engine:a.engine,engineVersion:a.engineVersion,engineSdkVersion:a.engineSdkVersion??"",platform:a.platform,platformVersion:a.platformVersion,deviceModel:a.deviceModel??"N/A"},console.log(`Version check: ${JSON.stringify(s)}`),(0,u.trackDuration)(l,"completedInitGameBridge",_(o),{...s});break}case p.initDeviceFlow:{let e=await b().loginWithDeviceFlow();(0,u.trackDuration)(l,"performedInitDeviceFlow",_(o)),m({responseFor:t,requestId:r,success:!0,error:null,code:e.code,deviceCode:e.deviceCode,url:e.url,interval:e.interval});break}case p.relogin:{let e=await b().login({useCachedSession:!0}),n=null!==e;if(!n)throw Error("Failed to re-login");(0,u.identify)({passportId:e?.sub}),(0,u.trackDuration)(l,"performedRelogin",_(o),{succeeded:n}),m({responseFor:t,requestId:r,success:null!==e,error:null});break}case p.reconnect:{let e=!1,n=await b().login({useCachedSession:!0});if(n){let t=await b().connectImx();e=g(t),(0,u.identify)({passportId:n?.sub})}if(!e)throw Error("Failed to reconnect");(0,u.trackDuration)(l,"performedReconnect",_(o),{succeeded:null!==n}),m({responseFor:t,requestId:r,success:e,error:null});break}case p.getPKCEAuthUrl:{let e=b().loginWithPKCEFlow();(0,u.trackDuration)(l,"performedGetPkceAuthUrl",_(o)),m({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.loginPKCE:{let e=JSON.parse(A),n=await b().loginWithPKCEFlowCallback(e.authorizationCode,e.state);(0,u.identify)({passportId:n.sub}),(0,u.trackDuration)(l,"performedLoginPkce",_(o)),m({responseFor:t,requestId:r,success:!0,error:null});break}case p.connectPKCE:{let e=JSON.parse(A),n=await b().loginWithPKCEFlowCallback(e.authorizationCode,e.state),i=await b().connectImx(),a=g(i);if(!a)throw Error("Failed to connect via PKCE");(0,u.identify)({passportId:n.sub}),(0,u.trackDuration)(l,"performedConnectPkce",_(o),{succeeded:a}),m({responseFor:t,requestId:r,success:a,error:null});break}case p.loginConfirmCode:{let e=JSON.parse(A),n=await b().loginWithDeviceFlowCallback(e.deviceCode,e.interval,e.timeoutMs??null);(0,u.identify)({passportId:n.sub}),(0,u.trackDuration)(l,"performedLoginConfirmCode",_(o)),m({responseFor:t,requestId:r,success:!0,error:null});break}case p.connectConfirmCode:{let e=JSON.parse(A),n=await b().loginWithDeviceFlowCallback(e.deviceCode,e.interval,e.timeoutMs??null),i=await b().connectImx(),a=g(i);if(!a)throw Error("Failed to connect via confirm code");(0,u.identify)({passportId:n.sub}),(0,u.trackDuration)(l,"performedConnectConfirmCode",_(o),{succeeded:a}),m({responseFor:t,requestId:r,success:a,error:null});break}case p.logout:{let e=await b().logoutDeviceFlow();i=null,a=null,(0,u.trackDuration)(l,"performedGetLogoutUrl",_(o)),m({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.getAccessToken:{let e=await b().getAccessToken(),n=void 0!==e;if(!n)throw Error("No access token");(0,u.trackDuration)(l,"performedGetAccessToken",_(o)),m({responseFor:t,requestId:r,success:n,error:null,result:e});break}case p.getIdToken:{let e=await b().getIdToken(),n=void 0!==e;if(!n)throw Error("No ID token");(0,u.trackDuration)(l,"performedGetIdToken",_(o)),m({responseFor:t,requestId:r,success:n,error:null,result:e});break}case p.getEmail:{let e=await b().getUserInfo(),n=e?.email!==void 0;if(!n)throw Error("No email");(0,u.trackDuration)(l,"performedGetEmail",_(o)),m({responseFor:t,requestId:r,success:n,error:null,result:e?.email});break}case p.getPassportId:{let e=await b().getUserInfo(),n=e?.sub!==void 0;if(!n)throw Error("No Passport ID");(0,u.trackDuration)(l,"performedGetPassportId",_(o)),m({responseFor:t,requestId:r,success:n,error:null,result:e?.sub});break}case p.getLinkedAddresses:{let e=await b().getLinkedAddresses();(0,u.trackDuration)(l,"performedGetLinkedAddresses",_(o)),m({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.imx.getAddress:{let e=await y().getAddress();(0,u.trackDuration)(l,"performedImxGetAddress",_(o)),m({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.imx.isRegisteredOffchain:{let e=await y().isRegisteredOffchain();(0,u.trackDuration)(l,"performedImxIsRegisteredOffchain",_(o)),m({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.imx.registerOffchain:{let e=await y().registerOffchain();(0,u.trackDuration)(l,"performedImxRegisterOffchain",_(o)),m({responseFor:t,requestId:r,success:!0,error:null,...e});break}case p.imx.transfer:{let e=JSON.parse(A),n=await y().transfer(e);(0,u.trackDuration)(l,"performedImxTransfer",_(o),{requestId:r,transferRequest:JSON.stringify(e),transferResponse:JSON.stringify(n)}),m({responseFor:t,requestId:r,success:!0,error:null,...n});break}case p.imx.batchNftTransfer:{let e=JSON.parse(A),n=await y().batchNftTransfer(e);(0,u.trackDuration)(l,"performedImxBatchNftTransfer",_(o),{requestId:r,transferRequest:JSON.stringify(e),transferResponse:JSON.stringify(n)}),m({responseFor:t,requestId:r,success:!0,error:null,...n});break}case p.zkEvm.connectEvm:{let e=b().connectEvm(),n=v(e);if(!n)throw Error("Failed to connect to EVM");(0,u.trackDuration)(l,"performedZkevmConnectEvm",_(o),{succeeded:n}),m({responseFor:t,requestId:r,success:n,error:null});break}case p.zkEvm.sendTransaction:{let e=JSON.parse(A),n=await w().request({method:"eth_sendTransaction",params:[e]}),i=null!=n;if(!i)throw Error("Failed to send transaction");(0,u.trackDuration)(l,"performedZkevmSendTransaction",_(o),{requestId:r,transactionRequest:JSON.stringify(e),transactionResponse:n}),m({responseFor:t,requestId:r,success:i,error:null,result:n});break}case p.zkEvm.sendTransactionWithConfirmation:{let e=JSON.parse(A),n=w(),i=new d.providers.Web3Provider(n),a=i.getSigner(),s=await a.sendTransaction(e),c=await s.wait();(0,u.trackDuration)(l,"performedZkevmSendTransactionWithConfirmation",_(o),{requestId:r,transactionRequest:JSON.stringify(e),transactionResponse:JSON.stringify(c)}),m({responseFor:t,requestId:r,success:!0,error:null,...c});break}case p.zkEvm.requestAccounts:{let e=await w().request({method:"eth_requestAccounts"}),n=null!=e;if(!n)throw Error("Failed to request accounts");(0,u.trackDuration)(l,"performedZkevmRequestAccounts",_(o)),m({responseFor:t,requestId:r,success:n,error:null,accounts:e});break}case p.zkEvm.getBalance:{let e=JSON.parse(A),n=await w().request({method:"eth_getBalance",params:[e.address,e.blockNumberOrTag]}),i=null!=n;if(!i)throw Error("Failed to get balance");(0,u.trackDuration)(l,"performedZkevmGetBalance",_(o)),m({responseFor:t,requestId:r,success:i,error:null,result:n});break}case p.zkEvm.getTransactionReceipt:{let e=JSON.parse(A),n=await w().request({method:"eth_getTransactionReceipt",params:[e.txHash]}),i=void 0!==n;if(!i)throw Error("Failed to get transaction receipt");(0,u.trackDuration)(l,"performedZkevmGetTransactionReceipt",_(o)),m({responseFor:t,requestId:r,success:i,error:null,...n});break}case"track":{let e=JSON.parse(A),n=JSON.parse(e.properties);(0,u.track)(e.moduleName,e.eventName,n),m({responseFor:t,requestId:r,success:!0,error:null})}}}catch(i){let e;console.log(`Error in callFunction: ${i}`),e=i instanceof Error?i:Error(i);let n=i instanceof c.PassportError?i?.type:void 0;(0,u.trackError)(l,t,e,{fxName:t,requestId:r,errorType:n,...s}),(0,u.trackDuration)(l,"failedCallFunction",_(o),{fxName:t,requestId:r,error:e.message}),console.log("callFunction error",e),console.log("callFunction errorType",n),m({responseFor:t,requestId:r,success:!1,error:i?.message!==null&&i?.message!==void 0?i.message:"Error",errorType:i instanceof c.PassportError?i?.type:null})}},window.addEventListener("offline",()=>{console.log("gameBridge offline")}),window.addEventListener("online",()=>{console.log("gameBridge online")}),console.log("index.ts loaded"),o=function(){m({responseFor:"init",requestId:"1",success:!0,error:null})},"complete"===document.readyState?o():window.addEventListener("load",o)},{"@imtbl/passport":"iPtWy","@imtbl/config":"ed8SG","@imtbl/metrics":"dO0KB",ethers:"8wpcu"}],iPtWy:[function(e,t,r){let n;var i,a,s,o,c,f,u,d,l,h,p,m,b,g,y=e("@parcel/transformer-js/src/esmodule-helpers.js");y.defineInteropFlag(r),y.export(r,"JsonRpcError",()=>e6),y.export(r,"Passport",()=>tR),y.export(r,"PassportError",()=>K),y.export(r,"ProviderErrorCode",()=>b),y.export(r,"ProviderEvent",()=>m),y.export(r,"RpcErrorCode",()=>g);var v=e("axios"),w=y.interopDefault(v),_=e("@imtbl/metrics"),E=e("@imtbl/generated-clients"),A=e("@imtbl/x-client"),M=e("@imtbl/config"),S=e("oidc-client-ts"),x=e("crypto"),T=e("jwt-decode"),k=y.interopDefault(T),R=e("localforage"),I=y.interopDefault(R),C=e("magic-sdk"),P=e("@magic-ext/oidc"),O=e("@ethersproject/providers"),N=e("@imtbl/toolkit"),j=e("@imtbl/guardian"),B=e("ethers"),L=e("events"),D=e("@0xsequence/abi"),U=e("@0xsequence/core"),F=e("uuid"),q=e("a7402fb880ab41a1");function z(e){return"code"in e&&"message"in e}(i=u||(u={})).AUTHENTICATION_ERROR="AUTHENTICATION_ERROR",i.INVALID_CONFIGURATION="INVALID_CONFIGURATION",i.WALLET_CONNECTION_ERROR="WALLET_CONNECTION_ERROR",i.NOT_LOGGED_IN_ERROR="NOT_LOGGED_IN_ERROR",i.SILENT_LOGIN_ERROR="SILENT_LOGIN_ERROR",i.REFRESH_TOKEN_ERROR="REFRESH_TOKEN_ERROR",i.USER_REGISTRATION_ERROR="USER_REGISTRATION_ERROR",i.USER_NOT_REGISTERED_ERROR="USER_NOT_REGISTERED_ERROR",i.LOGOUT_ERROR="LOGOUT_ERROR",i.TRANSFER_ERROR="TRANSFER_ERROR",i.CREATE_ORDER_ERROR="CREATE_ORDER_ERROR",i.CANCEL_ORDER_ERROR="CANCEL_ORDER_ERROR",i.EXCHANGE_TRANSFER_ERROR="EXCHANGE_TRANSFER_ERROR",i.CREATE_TRADE_ERROR="CREATE_TRADE_ERROR",i.OPERATION_NOT_SUPPORTED_ERROR="OPERATION_NOT_SUPPORTED_ERROR",i.LINK_WALLET_ALREADY_LINKED_ERROR="LINK_WALLET_ALREADY_LINKED_ERROR",i.LINK_WALLET_MAX_WALLETS_LINKED_ERROR="LINK_WALLET_MAX_WALLETS_LINKED_ERROR",i.LINK_WALLET_VALIDATION_ERROR="LINK_WALLET_VALIDATION_ERROR",i.LINK_WALLET_DUPLICATE_NONCE_ERROR="LINK_WALLET_DUPLICATE_NONCE_ERROR",i.LINK_WALLET_GENERIC_ERROR="LINK_WALLET_GENERIC_ERROR";class K extends Error{type;constructor(e,t){super(e),this.type=t}}let H=async(e,t,r)=>{try{return await e()}catch(i){let e;e=(0,v.isAxiosError)(i)&&i.response?.data&&z(i.response.data)?i.response.data.message:i.message;let n=new K(e,t);throw r&&(0,_.trackError)("passport",r,n),n}},V="pkce_state",W="pkce_verifier";class G{areValid(e){if(e){let t=this.isTokenValid(e.access_token),r=this.isTokenValid(e.id_token);return t&&r}return!1}isTokenValid(e){try{let t=(0,k.default)(e),r=t.exp??0,n=Date.now()/1e3+3600;return r>n}catch(e){return!1}}savePKCEData(e){localStorage.setItem(V,e.state),localStorage.setItem(W,e.verifier)}getPKCEData(){let e=localStorage.getItem(V),t=localStorage.getItem(W);return e&&t?{state:e,verifier:t}:null}}var J={warn:(...e)=>{if(void 0===q)return;let t=q?.env?.JEST_WORKER_ID===void 0;t&&console.warn(...e)}};(a=d||(d={})).LOGGED_OUT="loggedOut",a.LOGGED_IN="loggedIn",a.ACCOUNTS_REQUESTED="accountsRequested";let Z=e=>!!e.zkEvm,$=e=>!!e.imx,X="passport-overlay",Y=`${X}-close`,Q=`${X}-try-again`,ee=` +!function(e,t,r,i,n){var a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:"undefined"!=typeof window?window:"undefined"!=typeof global?global:{},s="function"==typeof a[i]&&a[i],o=s.cache||{},f="undefined"!=typeof module&&"function"==typeof module.require&&module.require.bind(module);function c(t,r){if(!o[t]){if(!e[t]){var n="function"==typeof a[i]&&a[i];if(!r&&n)return n(t,!0);if(s)return s(t,!0);if(f&&"string"==typeof t)return f(t);var d=Error("Cannot find module '"+t+"'");throw d.code="MODULE_NOT_FOUND",d}l.resolve=function(r){var i=e[t][1][r];return null!=i?i:r},l.cache={};var u=o[t]=new c.Module(t);e[t][0].call(u.exports,l,u,u.exports,this)}return o[t].exports;function l(e){var t=l.resolve(e);return!1===t?{}:c(t)}}c.isParcelRequire=!0,c.Module=function(e){this.id=e,this.bundle=c,this.exports={}},c.modules=e,c.cache=o,c.parent=s,c.register=function(t,r){e[t]=[function(e,t){t.exports=r},{}]},Object.defineProperty(c,"root",{get:function(){return a[i]}}),a[i]=c;for(var d=0;d{let t=JSON.stringify(e);if(console.log(`callbackToGame: ${t}`),void 0!==window.ue){if(void 0===window.ue.jsconnector){let e="Unreal JSConnector not defined";throw console.error(e),Error(e)}window.ue.jsconnector.sendtogame(t)}else if("undefined"!=typeof blu_event)blu_event("sendtogame",t);else if("undefined"!=typeof UnityPostMessage)UnityPostMessage(t);else if("undefined"!==window.Unity)window.Unity.call(t);else{let e="No available game callbacks to call from ImmutableSDK game-bridge";throw console.error(e),Error(e)}},m=()=>{if(null==i)throw Error("No Passport client");return i},g=e=>null!=e?(n=e,console.log("IMX provider set"),!0):(console.log("No IMX provider"),!1),y=()=>{if(null==n)throw Error("No IMX provider");return n},v=e=>null!=e?(a=e,console.log("zkEvm provider set"),!0):(console.log("No zkEvm provider"),!1),w=()=>{if(null==a)throw Error("No zkEvm provider");return a},_=e=>Date.now()-e;(0,d.track)(l,"loadedGameBridge",{sdkVersionTag:h}),window.callFunction=async e=>{console.log(`Call function ${e}`);let t=null,r=null,o=Date.now();try{let M=JSON.parse(e);t=M.fxName,r=M.requestId;let E=M.data;switch((0,d.track)(l,"startedCallFunction",{function:t,requestId:r}),t){case p.init:{let e=JSON.parse(E),n=e?.redirectUri,a=e?.isSilentLogout===!0?"silent":"redirect";if(!i){let t={baseConfig:new c.ImmutableConfiguration({environment:e.environment}),clientId:e.clientId,audience:"platform_api",scope:"openid offline_access profile email transact",redirectUri:n??"https://localhost:3000/",logoutRedirectUri:e?.logoutRedirectUri,crossSdkBridgeEnabled:!0,logoutMode:a};i=new f.Passport(t),(0,d.trackDuration)(l,"initialisedPassport",_(o))}b({responseFor:t,requestId:r,success:!0,error:null});let{engineVersion:u}=e;s={gameBridgeTag:h,gameBridgeSha:"603dc982247130dee516fc1c54facf2c179ef1b7",engine:u.engine,engineVersion:u.engineVersion,engineSdkVersion:u.engineSdkVersion??"",platform:u.platform,platformVersion:u.platformVersion,deviceModel:u.deviceModel??"N/A"},console.log(`Version check: ${JSON.stringify(s)}`),(0,d.trackDuration)(l,"completedInitGameBridge",_(o),{...s});break}case p.initDeviceFlow:{let e=await m().loginWithDeviceFlow();(0,d.trackDuration)(l,"performedInitDeviceFlow",_(o)),b({responseFor:t,requestId:r,success:!0,error:null,code:e.code,deviceCode:e.deviceCode,url:e.url,interval:e.interval});break}case p.relogin:{let e=await m().login({useCachedSession:!0}),i=null!==e;if(!i)throw Error("Failed to re-login");(0,d.identify)({passportId:e?.sub}),(0,d.trackDuration)(l,"performedRelogin",_(o),{succeeded:i}),b({responseFor:t,requestId:r,success:null!==e,error:null});break}case p.reconnect:{let e=!1,i=await m().login({useCachedSession:!0});if(i){let t=await m().connectImx();e=g(t),(0,d.identify)({passportId:i?.sub})}if(!e)throw Error("Failed to reconnect");(0,d.trackDuration)(l,"performedReconnect",_(o),{succeeded:null!==i}),b({responseFor:t,requestId:r,success:e,error:null});break}case p.getPKCEAuthUrl:{let e=m().loginWithPKCEFlow();(0,d.trackDuration)(l,"performedGetPkceAuthUrl",_(o)),b({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.loginPKCE:{let e=JSON.parse(E),i=await m().loginWithPKCEFlowCallback(e.authorizationCode,e.state);(0,d.identify)({passportId:i.sub}),(0,d.trackDuration)(l,"performedLoginPkce",_(o)),b({responseFor:t,requestId:r,success:!0,error:null});break}case p.connectPKCE:{let e=JSON.parse(E),i=await m().loginWithPKCEFlowCallback(e.authorizationCode,e.state),n=await m().connectImx(),a=g(n);if(!a)throw Error("Failed to connect via PKCE");(0,d.identify)({passportId:i.sub}),(0,d.trackDuration)(l,"performedConnectPkce",_(o),{succeeded:a}),b({responseFor:t,requestId:r,success:a,error:null});break}case p.loginConfirmCode:{let e=JSON.parse(E),i=await m().loginWithDeviceFlowCallback(e.deviceCode,e.interval,e.timeoutMs??null);(0,d.identify)({passportId:i.sub}),(0,d.trackDuration)(l,"performedLoginConfirmCode",_(o)),b({responseFor:t,requestId:r,success:!0,error:null});break}case p.connectConfirmCode:{let e=JSON.parse(E),i=await m().loginWithDeviceFlowCallback(e.deviceCode,e.interval,e.timeoutMs??null),n=await m().connectImx(),a=g(n);if(!a)throw Error("Failed to connect via confirm code");(0,d.identify)({passportId:i.sub}),(0,d.trackDuration)(l,"performedConnectConfirmCode",_(o),{succeeded:a}),b({responseFor:t,requestId:r,success:a,error:null});break}case p.logout:{let e=await m().logoutDeviceFlow();n=null,a=null,(0,d.trackDuration)(l,"performedGetLogoutUrl",_(o)),b({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.getAccessToken:{let e=await m().getAccessToken(),i=void 0!==e;if(!i)throw Error("No access token");(0,d.trackDuration)(l,"performedGetAccessToken",_(o)),b({responseFor:t,requestId:r,success:i,error:null,result:e});break}case p.getIdToken:{let e=await m().getIdToken(),i=void 0!==e;if(!i)throw Error("No ID token");(0,d.trackDuration)(l,"performedGetIdToken",_(o)),b({responseFor:t,requestId:r,success:i,error:null,result:e});break}case p.getEmail:{let e=await m().getUserInfo(),i=e?.email!==void 0;if(!i)throw Error("No email");(0,d.trackDuration)(l,"performedGetEmail",_(o)),b({responseFor:t,requestId:r,success:i,error:null,result:e?.email});break}case p.getPassportId:{let e=await m().getUserInfo(),i=e?.sub!==void 0;if(!i)throw Error("No Passport ID");(0,d.trackDuration)(l,"performedGetPassportId",_(o)),b({responseFor:t,requestId:r,success:i,error:null,result:e?.sub});break}case p.getLinkedAddresses:{let e=await m().getLinkedAddresses();(0,d.trackDuration)(l,"performedGetLinkedAddresses",_(o)),b({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.imx.getAddress:{let e=await y().getAddress();(0,d.trackDuration)(l,"performedImxGetAddress",_(o)),b({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.imx.isRegisteredOffchain:{let e=await y().isRegisteredOffchain();(0,d.trackDuration)(l,"performedImxIsRegisteredOffchain",_(o)),b({responseFor:t,requestId:r,success:!0,error:null,result:e});break}case p.imx.registerOffchain:{let e=await y().registerOffchain();(0,d.trackDuration)(l,"performedImxRegisterOffchain",_(o)),b({responseFor:t,requestId:r,success:!0,error:null,...e});break}case p.imx.transfer:{let e=JSON.parse(E),i=await y().transfer(e);(0,d.trackDuration)(l,"performedImxTransfer",_(o),{requestId:r,transferRequest:JSON.stringify(e),transferResponse:JSON.stringify(i)}),b({responseFor:t,requestId:r,success:!0,error:null,...i});break}case p.imx.batchNftTransfer:{let e=JSON.parse(E),i=await y().batchNftTransfer(e);(0,d.trackDuration)(l,"performedImxBatchNftTransfer",_(o),{requestId:r,transferRequest:JSON.stringify(e),transferResponse:JSON.stringify(i)}),b({responseFor:t,requestId:r,success:!0,error:null,...i});break}case p.zkEvm.connectEvm:{let e=m().connectEvm(),i=v(e);if(!i)throw Error("Failed to connect to EVM");(0,d.trackDuration)(l,"performedZkevmConnectEvm",_(o),{succeeded:i}),b({responseFor:t,requestId:r,success:i,error:null});break}case p.zkEvm.sendTransaction:{let e=JSON.parse(E),i=await w().request({method:"eth_sendTransaction",params:[e]}),n=null!=i;if(!n)throw Error("Failed to send transaction");(0,d.trackDuration)(l,"performedZkevmSendTransaction",_(o),{requestId:r,transactionRequest:JSON.stringify(e),transactionResponse:i}),b({responseFor:t,requestId:r,success:n,error:null,result:i});break}case p.zkEvm.sendTransactionWithConfirmation:{let e=JSON.parse(E),i=w(),n=new u.providers.Web3Provider(i),a=n.getSigner(),s=await a.sendTransaction(e),f=await s.wait();(0,d.trackDuration)(l,"performedZkevmSendTransactionWithConfirmation",_(o),{requestId:r,transactionRequest:JSON.stringify(e),transactionResponse:JSON.stringify(f)}),b({responseFor:t,requestId:r,success:!0,error:null,...f});break}case p.zkEvm.requestAccounts:{let e=await w().request({method:"eth_requestAccounts"}),i=null!=e;if(!i)throw Error("Failed to request accounts");(0,d.trackDuration)(l,"performedZkevmRequestAccounts",_(o)),b({responseFor:t,requestId:r,success:i,error:null,accounts:e});break}case p.zkEvm.getBalance:{let e=JSON.parse(E),i=await w().request({method:"eth_getBalance",params:[e.address,e.blockNumberOrTag]}),n=null!=i;if(!n)throw Error("Failed to get balance");(0,d.trackDuration)(l,"performedZkevmGetBalance",_(o)),b({responseFor:t,requestId:r,success:n,error:null,result:i});break}case p.zkEvm.getTransactionReceipt:{let e=JSON.parse(E),i=await w().request({method:"eth_getTransactionReceipt",params:[e.txHash]}),n=void 0!==i;if(!n)throw Error("Failed to get transaction receipt");(0,d.trackDuration)(l,"performedZkevmGetTransactionReceipt",_(o)),b({responseFor:t,requestId:r,success:n,error:null,...i});break}case"track":{let e=JSON.parse(E),i=e.properties?JSON.parse(e.properties):{};(0,d.track)(e.moduleName,e.eventName,i),b({responseFor:t,requestId:r,success:!0,error:null})}}}catch(n){let e;console.log(`Error in callFunction: ${n}`),e=n instanceof Error?n:Error(n);let i=n instanceof f.PassportError?n?.type:void 0;(0,d.trackError)(l,t,e,{fxName:t,requestId:r,errorType:i,...s}),(0,d.trackDuration)(l,"failedCallFunction",_(o),{fxName:t,requestId:r,error:e.message}),console.log("callFunction error",e),console.log("callFunction errorType",i),b({responseFor:t,requestId:r,success:!1,error:n?.message!==null&&n?.message!==void 0?n.message:"Error",errorType:n instanceof f.PassportError?n?.type:null})}},window.addEventListener("offline",()=>{console.log("gameBridge offline")}),window.addEventListener("online",()=>{console.log("gameBridge online")}),console.log("index.ts loaded"),o=function(){b({responseFor:"init",requestId:"1",success:!0,error:null})},"complete"===document.readyState?o():window.addEventListener("load",o)},{"@imtbl/passport":"iPtWy","@imtbl/config":"ed8SG","@imtbl/metrics":"dO0KB",ethers:"8wpcu"}],iPtWy:[function(e,t,r){let i;var n,a,s,o,f,c,d,u,l,h,p,b,m,g,y=e("@parcel/transformer-js/src/esmodule-helpers.js");y.defineInteropFlag(r),y.export(r,"JsonRpcError",()=>e6),y.export(r,"Passport",()=>tT),y.export(r,"PassportError",()=>K),y.export(r,"ProviderErrorCode",()=>m),y.export(r,"ProviderEvent",()=>b),y.export(r,"RpcErrorCode",()=>g);var v=e("axios"),w=y.interopDefault(v),_=e("@imtbl/generated-clients"),M=e("@imtbl/x-client"),E=e("@imtbl/config"),A=e("@imtbl/metrics"),S=e("oidc-client-ts"),x=e("crypto"),I=e("jwt-decode"),R=y.interopDefault(I),T=e("localforage"),k=y.interopDefault(T),C=e("magic-sdk"),P=e("@magic-ext/oidc"),O=e("@ethersproject/providers"),N=e("@imtbl/toolkit"),j=e("@imtbl/guardian"),B=e("ethers"),L=e("events"),D=e("@0xsequence/abi"),F=e("@0xsequence/core"),U=e("uuid"),q=e("a7402fb880ab41a1");function z(e){return"code"in e&&"message"in e}(n=d||(d={})).AUTHENTICATION_ERROR="AUTHENTICATION_ERROR",n.INVALID_CONFIGURATION="INVALID_CONFIGURATION",n.WALLET_CONNECTION_ERROR="WALLET_CONNECTION_ERROR",n.NOT_LOGGED_IN_ERROR="NOT_LOGGED_IN_ERROR",n.SILENT_LOGIN_ERROR="SILENT_LOGIN_ERROR",n.REFRESH_TOKEN_ERROR="REFRESH_TOKEN_ERROR",n.USER_REGISTRATION_ERROR="USER_REGISTRATION_ERROR",n.USER_NOT_REGISTERED_ERROR="USER_NOT_REGISTERED_ERROR",n.LOGOUT_ERROR="LOGOUT_ERROR",n.TRANSFER_ERROR="TRANSFER_ERROR",n.CREATE_ORDER_ERROR="CREATE_ORDER_ERROR",n.CANCEL_ORDER_ERROR="CANCEL_ORDER_ERROR",n.EXCHANGE_TRANSFER_ERROR="EXCHANGE_TRANSFER_ERROR",n.CREATE_TRADE_ERROR="CREATE_TRADE_ERROR",n.OPERATION_NOT_SUPPORTED_ERROR="OPERATION_NOT_SUPPORTED_ERROR",n.LINK_WALLET_ALREADY_LINKED_ERROR="LINK_WALLET_ALREADY_LINKED_ERROR",n.LINK_WALLET_MAX_WALLETS_LINKED_ERROR="LINK_WALLET_MAX_WALLETS_LINKED_ERROR",n.LINK_WALLET_VALIDATION_ERROR="LINK_WALLET_VALIDATION_ERROR",n.LINK_WALLET_DUPLICATE_NONCE_ERROR="LINK_WALLET_DUPLICATE_NONCE_ERROR",n.LINK_WALLET_GENERIC_ERROR="LINK_WALLET_GENERIC_ERROR";class K extends Error{type;constructor(e,t){super(e),this.type=t}}let H=async(e,t)=>{try{return await e()}catch(r){let e;throw e=(0,v.isAxiosError)(r)&&r.response?.data&&z(r.response.data)?r.response.data.message:r.message,new K(e,t)}},W="pkce_state",V="pkce_verifier";class G{areValid(e){if(e){let t=this.isTokenValid(e.access_token),r=this.isTokenValid(e.id_token);return t&&r}return!1}isTokenValid(e){try{let t=(0,R.default)(e),r=t.exp??0,i=Date.now()/1e3+3600;return r>i}catch(e){return!1}}savePKCEData(e){localStorage.setItem(W,e.state),localStorage.setItem(V,e.verifier)}getPKCEData(){let e=localStorage.getItem(W),t=localStorage.getItem(V);return e&&t?{state:e,verifier:t}:null}}var J={warn:(...e)=>{if(void 0===q)return;let t=q?.env?.JEST_WORKER_ID===void 0;t&&console.warn(...e)}};(a=u||(u={})).LOGGED_OUT="loggedOut",a.LOGGED_IN="loggedIn",a.ACCOUNTS_REQUESTED="accountsRequested";let Z=e=>!!e.zkEvm,X=e=>!!e.imx,$="passport-overlay",Y=`${$}-close`,Q=`${$}-try-again`,ee=` -`,en=()=>` +`,ei=()=>`