@openfort/openfort-js 0.10.36 → 0.10.37

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.
@@ -1 +1 @@
1
- "use strict";var t=require("../core/configuration/authentication.js"),e=require("../core/errors/openfortError.js"),i=require("../types/types.js");exports.AuthApi=class{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,i,a,r){this.storage=t,this.authManager=e,this.validateAndRefreshToken=i,this.ensureInitialized=a,this.eventEmitter=r}async logInWithEmailPassword({email:a,password:r,ecosystemGame:n}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"email",provider:"email"});try{const e=await this.authManager.loginEmailPassword(a,r,n);return"action"in e||(new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async signUpGuest(){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"guest"});try{const e=await this.authManager.registerGuest();return new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async signUpWithEmailPassword({email:a,password:r,options:n,ecosystemGame:s}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"email",provider:"email"});try{const e=await this.authManager.signupEmailPassword(a,r,n?.data.name,s);return"action"in e||(new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async linkEmailPassword({email:t,password:e,authToken:i,ecosystemGame:a}){return await this.validateAndRefreshToken(),await this.authManager.linkEmail(t,e,i,a)}async unlinkEmailPassword({email:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkEmail(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async resetPassword({email:t,password:e,state:i}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e,i)}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async verifyEmail({email:t,state:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async initOAuth({provider:a,options:r,ecosystemGame:n}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);return this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"oauth",provider:a}),await this.authManager.initOAuth(a,r,n)}async initLinkOAuth({provider:a,options:r,ecosystemGame:n}){await this.validateAndRefreshToken();const s=await t.Authentication.fromStorage(this.storage);if(!s)throw new e.OpenfortError("No authentication found",e.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"oauth",provider:a}),await this.authManager.linkOAuth(s,a,r,n)}async unlinkOAuth({provider:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkOAuth(t,e)}async poolOAuth(e){await this.ensureInitialized();try{const a=await this.authManager.poolOAuth(e);return new t.Authentication("jwt",a.token,a.player.id,a.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,a),a}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async loginWithIdToken({provider:a,token:r,ecosystemGame:n}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"idToken",provider:a});try{const e=await this.authManager.loginWithIdToken(a,r,n);return new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async initSIWE({address:t,ecosystemGame:e}){return await this.ensureInitialized(),await this.authManager.initSIWE(t,e)}async authenticateWithSIWE({signature:a,message:r,walletClientType:n,connectorType:s}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"siwe",provider:"wallet"});try{const e=await this.authManager.authenticateSIWE(a,r,n,s);return new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async linkWallet({signature:t,message:e,walletClientType:i,connectorType:a,authToken:r}){return await this.validateAndRefreshToken(),await this.authManager.linkWallet(t,e,i,a,r)}async unlinkWallet({address:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkWallet(t,e)}async storeCredentials(i){if(await this.ensureInitialized(),!i.player)throw new e.OpenfortError("Player ID is required to store credentials",e.OpenfortErrorType.INVALID_CONFIGURATION);new t.Authentication("jwt",i.accessToken,i.player,i.refreshToken).save(this.storage)}async logout(){const e=await t.Authentication.fromStorage(this.storage);if(e){try{"third_party"!==e.type&&await this.authManager.logout(e.token,e?.refreshToken)}catch(t){}t.Authentication.clear(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_LOGOUT)}}};
1
+ "use strict";var t=require("../core/configuration/authentication.js"),e=require("../core/errors/openfortError.js"),i=require("../types/types.js");exports.AuthApi=class{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,i,a,r){this.storage=t,this.authManager=e,this.validateAndRefreshToken=i,this.ensureInitialized=a,this.eventEmitter=r}async logInWithEmailPassword({email:a,password:r,ecosystemGame:n}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"email",provider:"email"});try{const e=await this.authManager.loginEmailPassword(a,r,n);return"action"in e||(new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async signUpGuest(){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"guest"});try{const e=await this.authManager.registerGuest();return new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async signUpWithEmailPassword({email:a,password:r,options:n,ecosystemGame:s}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"email",provider:"email"});try{const e=await this.authManager.signupEmailPassword(a,r,n?.data.name,s);return"action"in e||(new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async linkEmailPassword({email:t,password:e,authToken:i,ecosystemGame:a}){return await this.validateAndRefreshToken(),await this.authManager.linkEmail(t,e,i,a)}async unlinkEmailPassword({email:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkEmail(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async resetPassword({email:t,password:e,state:i}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e,i)}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async verifyEmail({email:t,state:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async initOAuth({provider:a,options:r,ecosystemGame:n}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);return this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"oauth",provider:a}),await this.authManager.initOAuth(a,r,n)}async initLinkOAuth({provider:a,options:r,ecosystemGame:n}){await this.validateAndRefreshToken();const s=await t.Authentication.fromStorage(this.storage);if(!s)throw new e.OpenfortError("No authentication found",e.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"oauth",provider:a}),await this.authManager.linkOAuth(s,a,r,n)}async unlinkOAuth({provider:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkOAuth(t,e)}async poolOAuth(e){await this.ensureInitialized();try{const a=await this.authManager.poolOAuth(e);return new t.Authentication("jwt",a.token,a.player.id,a.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,a),a}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async loginWithIdToken({provider:a,token:r,ecosystemGame:n}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"idToken",provider:a});try{const e=await this.authManager.loginWithIdToken(a,r,n);return new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async initSIWE({address:t,ecosystemGame:e}){return await this.ensureInitialized(),await this.authManager.initSIWE(t,e)}async authenticateWithSIWE({signature:a,message:r,walletClientType:n,connectorType:s}){await this.ensureInitialized();if(await t.Authentication.fromStorage(this.storage))throw new e.OpenfortError("Already logged in",e.OpenfortErrorType.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_INIT,{method:"siwe",provider:"wallet"});try{const e=await this.authManager.authenticateSIWE(a,r,n,s);return new t.Authentication("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.OpenfortEvents.ON_AUTH_FAILURE,t),t}}async linkWallet({signature:t,message:e,walletClientType:i,connectorType:a,authToken:r}){return await this.validateAndRefreshToken(),await this.authManager.linkWallet(t,e,i,a,r)}async unlinkWallet({address:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkWallet(t,e)}async storeCredentials(i){if(await this.ensureInitialized(),!i.player)throw new e.OpenfortError("Player ID is required to store credentials",e.OpenfortErrorType.INVALID_CONFIGURATION);new t.Authentication("jwt",i.accessToken,i.player,i.refreshToken).save(this.storage)}async logout(){const e=await t.Authentication.fromStorage(this.storage);if(e){try{"third_party"!==e.type&&await this.authManager.logout(e.token,e.refreshToken??"")}catch(t){}t.Authentication.clear(this.storage),this.eventEmitter.emit(i.OpenfortEvents.ON_LOGOUT)}}};
@@ -1 +1 @@
1
- "use strict";var e=require("../../../packages/internal/openapi-clients/dist/index.js"),r=require("../core/configuration/passkey.js"),t=require("../core/config/config.js"),a=require("../core/configuration/account.js"),s=require("../core/configuration/authentication.js"),n=require("../core/errors/openfortError.js"),i=require("../types/types.js"),o=require("../utils/debug.js"),d=require("../wallets/embedded.js"),c=require("../wallets/evm/evmProvider.js");require("../wallets/evm/types.js");var g=require("../wallets/evm/provider/eip6963.js"),h=require("../wallets/evm/walletHelpers.js"),y=require("../wallets/iframeManager.js"),p=require("../wallets/messaging/ReactNativeMessenger.js");require("../wallets/messaging/browserMessenger/backwardCompatibility.js");var u=require("../wallets/messaging/browserMessenger/messengers/WindowMessenger.js");exports.EmbeddedWalletApi=class{storage;validateAndRefreshToken;ensureInitialized;eventEmitter;passkeyHandler;iframeManager=null;iframeManagerPromise=null;signer=null;signerPromise=null;provider=null;messagePoster=null;messenger=null;constructor(e,r,t,a,s){this.storage=e,this.validateAndRefreshToken=r,this.ensureInitialized=t,this.eventEmitter=a,this.passkeyHandler=s,this.eventEmitter.on(i.OpenfortEvents.ON_LOGOUT,()=>{o.debugLog("Handling logout event in EmbeddedWalletApi"),this.handleLogout()})}get backendApiClients(){const r=t.SDKConfiguration.getInstance();if(!r)throw new n.OpenfortError("Configuration not found",n.OpenfortErrorType.INVALID_CONFIGURATION);return new e.BackendApiClients({basePath:r.backendUrl,accessToken:r.baseConfiguration.publishableKey,nativeAppIdentifier:r.nativeAppIdentifier})}async getIframeManager(){if(o.debugLog("[HANDSHAKE DEBUG] getIframeManager called"),this.iframeManager&&this.iframeManager.hasFailed&&(o.debugLog("[HANDSHAKE DEBUG] Existing iframeManager has failed, clearing for recreation"),this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null),this.iframeManager)return o.debugLog("[HANDSHAKE DEBUG] Returning existing iframeManager instance"),this.iframeManager;if(this.iframeManagerPromise)return o.debugLog("[HANDSHAKE DEBUG] Returning existing iframeManagerPromise"),this.iframeManagerPromise;o.debugLog("[HANDSHAKE DEBUG] Creating new iframeManager"),this.iframeManagerPromise=this.createIframeManager();try{return o.debugLog("[HANDSHAKE DEBUG] Awaiting iframeManager creation"),this.iframeManager=await this.iframeManagerPromise,o.debugLog("[HANDSHAKE DEBUG] IframeManager created successfully"),this.iframeManagerPromise=null,this.iframeManager}catch(e){throw o.debugLog("[HANDSHAKE DEBUG] Error creating iframeManager:",e),this.iframeManagerPromise=null,this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null,e}}async createIframeManager(){o.debugLog("[HANDSHAKE DEBUG] createIframeManager starting");const e=t.SDKConfiguration.getInstance();if(!e)throw o.debugLog("[HANDSHAKE DEBUG] Configuration not found"),new n.OpenfortError("Configuration not found",n.OpenfortErrorType.INVALID_CONFIGURATION);let r;if(o.debugLog("[HANDSHAKE DEBUG] Configuration found"),this.messagePoster)o.debugLog("[HANDSHAKE DEBUG] Creating ReactNativeMessenger with messagePoster"),this.messenger&&(o.debugLog("[HANDSHAKE DEBUG] Destroying old messenger before creating new one"),this.messenger.destroy()),this.messenger=new p.ReactNativeMessenger(this.messagePoster),o.debugLog("[HANDSHAKE DEBUG] Created new ReactNativeMessenger instance"),r=this.messenger;else{o.debugLog("[HANDSHAKE DEBUG] Creating WindowMessenger for browser mode");const t=this.createIframe(e.iframeUrl),a=new URL(e.iframeUrl).origin;r=new u({remoteWindow:t.contentWindow,allowedOrigins:[a]}),o.debugLog("[HANDSHAKE DEBUG] Created WindowMessenger")}return o.debugLog("[HANDSHAKE DEBUG] Creating IframeManager instance"),new y.IframeManager(e,this.storage,r)}async ensureSigner(){if(this.iframeManager&&this.iframeManager.hasFailed&&(o.debugLog("IframeManager has failed, clearing signer for recreation"),this.signer=null),this.signer)return this.signer;if(this.signerPromise)return this.signerPromise;this.signerPromise=this.createSigner();try{return this.signer=await this.signerPromise,this.signer}catch(e){throw this.signerPromise=null,e}finally{this.signerPromise=null}}async createSigner(){const e=await this.getIframeManager();return new d.EmbeddedSigner(e,this.storage,this.backendApiClients,this.passkeyHandler,this.eventEmitter)}createIframe(e){if("undefined"==typeof document)throw new n.OpenfortError("Document is not available. Please provide a message poster for non-browser environments.",n.OpenfortErrorType.INVALID_CONFIGURATION);const r=document.getElementById("openfort-iframe");r&&r.remove();const t=document.createElement("iframe");return t.style.display="none",t.id="openfort-iframe",t.src=e,document.body.appendChild(t),t}async getPasskeyKey(e){const r=await s.Authentication.fromStorage(this.storage);return await this.passkeyHandler.deriveAndExportKey({id:e,seed:r.player})}async getEntropy(e){switch(e.recoveryMethod){case i.RecoveryMethod.PASSWORD:return{recoveryPassword:e.password};case i.RecoveryMethod.AUTOMATIC:return{encryptionSession:e.encryptionSession};case i.RecoveryMethod.PASSKEY:return{passkey:e.passkeyInfo?{id:e.passkeyInfo.passkeyId,key:e.passkeyInfo.passkeyKey||await this.getPasskeyKey(e.passkeyInfo.passkeyId)}:{}};default:throw new n.OpenfortError("Invalid recovery method",n.OpenfortErrorType.INVALID_CONFIGURATION)}}async configure(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:i.RecoveryMethod.AUTOMATIC},[t,n,o]=await Promise.all([s.Authentication.fromStorage(this.storage),this.ensureSigner(),this.getEntropy(r)]),d={chainId:e.chainId,entropy:o,accountType:e.accountType??i.AccountTypeEnum.SMART_ACCOUNT,chainType:e.chainType??i.ChainTypeEnum.EVM,getPasskeyKeyFn:async e=>this.getPasskeyKey(e)},c=await n.configure(d);return{id:c.id,chainId:c.chainId,user:t.player,address:c.address,ownerAddress:c.ownerAddress,chainType:c.chainType,accountType:c.accountType,implementationType:c.implementationType,factoryAddress:c.factoryAddress,salt:c.salt,createdAt:c.createdAt,implementationAddress:c.implementationAddress,recoveryMethod:a.Account.parseRecoveryMethod(c.recoveryMethod),recoveryMethodDetails:c.recoveryMethodDetails}}async create(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:i.RecoveryMethod.AUTOMATIC},o=await s.Authentication.fromStorage(this.storage);if(!o)throw new n.OpenfortError("missing authentication",n.OpenfortErrorType.AUTHENTICATION_ERROR);if(t.recoveryMethod===i.RecoveryMethod.PASSKEY){const e=await this.passkeyHandler.createPasskey({id:r.PasskeyHandler.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:o?.player});t.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[d,c]=await Promise.all([this.ensureSigner(),this.getEntropy(t)]),g=await d.create({accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:c}),h={id:g.id,chainId:g.chainId,user:o.player,address:g.address,ownerAddress:g.ownerAddress,chainType:g.chainType,accountType:g.accountType,implementationType:g.implementationType,factoryAddress:g.factoryAddress,salt:g.salt,createdAt:g.createdAt,implementationAddress:g.implementationAddress,recoveryMethod:a.Account.parseRecoveryMethod(g.recoveryMethod),recoveryMethodDetails:g.recoveryMethodDetails};return this.eventEmitter.emit(i.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,h),h}async recover(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:i.RecoveryMethod.AUTOMATIC};if(r.recoveryMethod===i.RecoveryMethod.PASSKEY){if(!r.passkeyInfo?.passkeyId)throw new n.OpenfortError("Passkey ID must be provided for passkey recovery",n.OpenfortErrorType.INVALID_CONFIGURATION);r.passkeyInfo={passkeyId:r.passkeyInfo.passkeyId}}const[t,o,d]=await Promise.all([this.ensureSigner(),this.getEntropy(r),s.Authentication.fromStorage(this.storage)]),c=await t.recover({account:e.account,entropy:o}),g={id:c.id,chainId:c.chainId,implementationAddress:c.implementationAddress,factoryAddress:c.factoryAddress,salt:c.salt,user:d.player,address:c.address,ownerAddress:c.ownerAddress,chainType:c.chainType,accountType:c.accountType,implementationType:c.implementationType,createdAt:c.createdAt,recoveryMethod:a.Account.parseRecoveryMethod(c.recoveryMethod),recoveryMethodDetails:c.recoveryMethodDetails};return this.eventEmitter.emit(i.OpenfortEvents.ON_EMBEDDED_WALLET_RECOVERED,g),g}async signMessage(e,r){await this.validateAndRefreshToken();const t=await this.ensureSigner(),{hashMessage:s=!0,arrayifyMessage:n=!1}=r||{},i=await a.Account.fromStorage(this.storage);return await t.sign(e,n,s,i?.chainType)}async signTypedData(e,r,t){await this.validateAndRefreshToken();const s=await this.ensureSigner(),i=await a.Account.fromStorage(this.storage);if(!i)throw new n.OpenfortError("No account found",n.OpenfortErrorType.MISSING_SIGNER_ERROR);const o={...r};delete o.EIP712Domain;const{_TypedDataEncoder:d}=await import("@ethersproject/hash"),c=d.hash(e,o,t);return await h.signMessage({hash:c,implementationType:i.implementationType||i.type,chainId:Number(i.chainId),signer:s,address:i.address,ownerAddress:i.ownerAddress,factoryAddress:i.factoryAddress,salt:i.salt})}async exportPrivateKey(){await this.validateAndRefreshToken();const e=await this.ensureSigner();return await e.export()}async setRecoveryMethod(e,t){await this.validateAndRefreshToken();const o=await this.ensureSigner(),d=await s.Authentication.fromStorage(this.storage);if(!d)throw new n.OpenfortError("missing authentication",n.OpenfortErrorType.AUTHENTICATION_ERROR);let c,g,h,y;if(e.recoveryMethod===i.RecoveryMethod.PASSKEY){const e=await a.Account.fromStorage(this.storage);if(!e)throw new n.OpenfortError("missing account",n.OpenfortErrorType.INVALID_CONFIGURATION);const r=e?.recoveryMethodDetails?.passkeyId;if(!r)throw new n.OpenfortError("missing passkey id for account",n.OpenfortErrorType.INVALID_CONFIGURATION);h={passkeyId:r,passkeyKey:await this.passkeyHandler.deriveAndExportKey({id:r,seed:d.player})}}else if(t.recoveryMethod===i.RecoveryMethod.PASSKEY){const e=await this.passkeyHandler.createPasskey({id:r.PasskeyHandler.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:d.player});h={passkeyId:e.id,passkeyKey:e.key},y={passkeyId:e.id}}if(e.recoveryMethod===i.RecoveryMethod.PASSWORD?c=e.password:t.recoveryMethod===i.RecoveryMethod.PASSWORD&&(c=t.password),e.recoveryMethod===i.RecoveryMethod.AUTOMATIC?g=e.encryptionSession:t.recoveryMethod===i.RecoveryMethod.AUTOMATIC&&(g=t.encryptionSession),!c&&!g)throw new n.OpenfortError("Password or encryption session is not provided",n.OpenfortErrorType.INVALID_CONFIGURATION);await o.setRecoveryMethod({recoveryMethod:t.recoveryMethod,recoveryPassword:c,encryptionSession:g,passkeyInfo:h});const p=await a.Account.fromStorage(this.storage);p&&new a.Account({...p,recoveryMethod:t.recoveryMethod,recoveryMethodDetails:y}).save(this.storage)}async get(){const e=await a.Account.fromStorage(this.storage);if(!e)throw new n.OpenfortError("No signer configured",n.OpenfortErrorType.MISSING_SIGNER_ERROR);const r=await s.Authentication.fromStorage(this.storage);if(!r)throw new n.OpenfortError("No access token found",n.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return{id:e.id,chainId:e.chainId,user:r.player,address:e.address,ownerAddress:e.ownerAddress,factoryAddress:e.factoryAddress,salt:e.salt,chainType:e.chainType,accountType:e.accountType,implementationAddress:e.implementationAddress,implementationType:e.implementationType,createdAt:e.createdAt,recoveryMethod:a.Account.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails}}async list(e){const r={accountType:i.AccountTypeEnum.SMART_ACCOUNT,...e},o=t.SDKConfiguration.getInstance();if(!o)throw new n.OpenfortError("Configuration not found",n.OpenfortErrorType.INVALID_CONFIGURATION);await this.validateAndRefreshToken();const d=await s.Authentication.fromStorage(this.storage);if(!d)throw new n.OpenfortError("No access token found",n.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return n.withOpenfortError(async()=>(await this.backendApiClients.accountsApi.getAccountsV2(r,{headers:{authorization:`Bearer ${o.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}})).data.data.map(e=>({user:e.user,chainType:e.chainType,id:e.id,address:e.address,active:e.smartAccount?.active,ownerAddress:e.ownerAddress,factoryAddress:e.smartAccount?.factoryAddress,salt:e.smartAccount?.salt,accountType:e.accountType,implementationAddress:e.smartAccount?.implementationAddress,createdAt:e.createdAt,implementationType:e.smartAccount?.implementationType,chainId:e.chainId,recoveryMethod:a.Account.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails})),{default:n.OpenfortErrorType.AUTHENTICATION_ERROR})}async getEmbeddedState(){try{if(!await s.Authentication.fromStorage(this.storage))return i.EmbeddedState.UNAUTHENTICATED;return await a.Account.fromStorage(this.storage)?i.EmbeddedState.READY:i.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED}catch(e){return o.debugLog("Failed to get embedded state:",e),i.EmbeddedState.UNAUTHENTICATED}}async getEthereumProvider(e){await this.ensureInitialized();const r={announceProvider:!0,...e},t=await s.Authentication.fromStorage(this.storage),n=await a.Account.fromStorage(this.storage);return this.provider?this.provider&&r.policy&&this.provider.updatePolicy(r.policy):(this.provider=new c.EvmProvider({storage:this.storage,openfortEventEmitter:this.eventEmitter,ensureSigner:this.ensureSigner.bind(this),account:n||void 0,authentication:t||void 0,backendApiClients:this.backendApiClients,policyId:r.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this),chains:r.chains}),r.announceProvider&&g.announceProvider({info:{...g.openfortProviderInfo,...r.providerInfo},provider:this.provider})),this.provider}async ping(e){try{e>0&&await new Promise(r=>{setTimeout(r,e)});const r=await this.getIframeManager();if(!r.isLoaded())return!1;const t=await s.Authentication.fromStorage(this.storage);if(t)try{return await r.getCurrentDevice(t.player),!0}catch(e){return!1}return r.isLoaded()}catch(e){return o.debugLog("Ping failed:",e),!1}}getURL(){const e=t.SDKConfiguration.getInstance();if(!e)throw new n.OpenfortError("Configuration not found",n.OpenfortErrorType.INVALID_CONFIGURATION);return e.iframeUrl}async setMessagePoster(e){if(!e||"function"!=typeof e.postMessage)throw new n.OpenfortError("Invalid message poster",n.OpenfortErrorType.INVALID_CONFIGURATION);this.messagePoster=e,this.messenger&&this.messenger.destroy(),this.iframeManager&&this.iframeManager.destroy(),this.signer=null,this.signerPromise=null,this.iframeManager=null,this.iframeManagerPromise=null,this.messenger=null}async handleLogout(){const e=await this.ensureSigner();await e.disconnect(),this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,this.signerPromise=null}async onMessage(e){if(!e||"object"!=typeof e)return void o.debugLog("Invalid message received:",e);o.debugLog("[HANDSHAKE DEBUG] EmbeddedWalletApi onMessage:",e);const r="penpal"===e.namespace&&"SYN"===e.type||e.penpal&&"string"==typeof e.penpal;if(r&&this.messenger&&this.messagePoster)return o.debugLog("[HANDSHAKE DEBUG] Passing message directly to existing ReactNativeMessenger"),void this.messenger.handleMessage(e);const t=await this.getIframeManager();o.debugLog(`[HANDSHAKE DEBUG] IframeManager obtained, isLoaded: ${t.isLoaded()}`),r&&!t.isLoaded()&&o.debugLog("[HANDSHAKE DEBUG] Received penpal message before connection initialized, setting up connection..."),o.debugLog("[HANDSHAKE DEBUG] Calling iframeManager.onMessage"),await t.onMessage(e),o.debugLog("[HANDSHAKE DEBUG] iframeManager.onMessage completed")}isReady(){return this.iframeManager?.isLoaded()||!1}};
1
+ "use strict";var e=require("../../../packages/internal/openapi-clients/dist/index.js"),r=require("../core/configuration/passkey.js"),t=require("../core/config/config.js"),a=require("../core/configuration/account.js"),s=require("../core/configuration/authentication.js"),n=require("../core/errors/openfortError.js"),i=require("../types/types.js"),o=require("../utils/debug.js"),d=require("../wallets/embedded.js"),c=require("../wallets/evm/evmProvider.js");require("../wallets/evm/types.js");var g=require("../wallets/evm/provider/eip6963.js"),h=require("../wallets/evm/walletHelpers.js"),y=require("../wallets/iframeManager.js"),p=require("../wallets/messaging/ReactNativeMessenger.js");require("../wallets/messaging/browserMessenger/backwardCompatibility.js");var u=require("../wallets/messaging/browserMessenger/messengers/WindowMessenger.js");exports.EmbeddedWalletApi=class{storage;validateAndRefreshToken;ensureInitialized;eventEmitter;passkeyHandler;iframeManager=null;iframeManagerPromise=null;signer=null;signerPromise=null;provider=null;messagePoster=null;messenger=null;constructor(e,r,t,a,s){this.storage=e,this.validateAndRefreshToken=r,this.ensureInitialized=t,this.eventEmitter=a,this.passkeyHandler=s,this.eventEmitter.on(i.OpenfortEvents.ON_LOGOUT,()=>{o.debugLog("Handling logout event in EmbeddedWalletApi"),this.handleLogout()})}get backendApiClients(){const r=t.SDKConfiguration.getInstance();if(!r)throw new n.OpenfortError("Configuration not found",n.OpenfortErrorType.INVALID_CONFIGURATION);return new e.BackendApiClients({basePath:r.backendUrl,accessToken:r.baseConfiguration.publishableKey,nativeAppIdentifier:r.nativeAppIdentifier})}async getIframeManager(){if(o.debugLog("[HANDSHAKE DEBUG] getIframeManager called"),this.iframeManager&&this.iframeManager.hasFailed&&(o.debugLog("[HANDSHAKE DEBUG] Existing iframeManager has failed, clearing for recreation"),this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null),this.iframeManager)return o.debugLog("[HANDSHAKE DEBUG] Returning existing iframeManager instance"),this.iframeManager;if(this.iframeManagerPromise)return o.debugLog("[HANDSHAKE DEBUG] Returning existing iframeManagerPromise"),this.iframeManagerPromise;o.debugLog("[HANDSHAKE DEBUG] Creating new iframeManager"),this.iframeManagerPromise=this.createIframeManager();try{return o.debugLog("[HANDSHAKE DEBUG] Awaiting iframeManager creation"),this.iframeManager=await this.iframeManagerPromise,o.debugLog("[HANDSHAKE DEBUG] IframeManager created successfully"),this.iframeManagerPromise=null,this.iframeManager}catch(e){throw o.debugLog("[HANDSHAKE DEBUG] Error creating iframeManager:",e),this.iframeManagerPromise=null,this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null,e}}async createIframeManager(){o.debugLog("[HANDSHAKE DEBUG] createIframeManager starting");const e=t.SDKConfiguration.getInstance();if(!e)throw o.debugLog("[HANDSHAKE DEBUG] Configuration not found"),new n.OpenfortError("Configuration not found",n.OpenfortErrorType.INVALID_CONFIGURATION);let r;if(o.debugLog("[HANDSHAKE DEBUG] Configuration found"),this.messagePoster)o.debugLog("[HANDSHAKE DEBUG] Creating ReactNativeMessenger with messagePoster"),this.messenger&&(o.debugLog("[HANDSHAKE DEBUG] Destroying old messenger before creating new one"),this.messenger.destroy()),this.messenger=new p.ReactNativeMessenger(this.messagePoster),o.debugLog("[HANDSHAKE DEBUG] Created new ReactNativeMessenger instance"),r=this.messenger;else{o.debugLog("[HANDSHAKE DEBUG] Creating WindowMessenger for browser mode");const t=this.createIframe(e.iframeUrl),a=new URL(e.iframeUrl).origin;r=new u({remoteWindow:t.contentWindow,allowedOrigins:[a]}),o.debugLog("[HANDSHAKE DEBUG] Created WindowMessenger")}return o.debugLog("[HANDSHAKE DEBUG] Creating IframeManager instance"),new y.IframeManager(e,this.storage,r)}async ensureSigner(){if(this.iframeManager&&this.iframeManager.hasFailed&&(o.debugLog("IframeManager has failed, clearing signer for recreation"),this.signer=null),this.signer)return this.signer;if(this.signerPromise)return this.signerPromise;this.signerPromise=this.createSigner();try{return this.signer=await this.signerPromise,this.signer}catch(e){throw this.signerPromise=null,e}finally{this.signerPromise=null}}async createSigner(){const e=await this.getIframeManager();return new d.EmbeddedSigner(e,this.storage,this.backendApiClients,this.passkeyHandler,this.eventEmitter)}createIframe(e){if("undefined"==typeof document)throw new n.OpenfortError("Document is not available. Please provide a message poster for non-browser environments.",n.OpenfortErrorType.INVALID_CONFIGURATION);const r=document.getElementById("openfort-iframe");r&&r.remove();const t=document.createElement("iframe");return t.style.display="none",t.id="openfort-iframe",t.src=e,document.body.appendChild(t),t}async getPasskeyKey(e){const r=await s.Authentication.fromStorage(this.storage);return await this.passkeyHandler.deriveAndExportKey({id:e,seed:r.player})}async getEntropy(e){switch(e.recoveryMethod){case i.RecoveryMethod.PASSWORD:return{recoveryPassword:e.password};case i.RecoveryMethod.AUTOMATIC:return{encryptionSession:e.encryptionSession};case i.RecoveryMethod.PASSKEY:return{passkey:e.passkeyInfo?{id:e.passkeyInfo.passkeyId,key:e.passkeyInfo.passkeyKey||await this.getPasskeyKey(e.passkeyInfo.passkeyId)}:{}};default:throw new n.OpenfortError("Invalid recovery method",n.OpenfortErrorType.INVALID_CONFIGURATION)}}async configure(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:i.RecoveryMethod.AUTOMATIC},[t,n,o]=await Promise.all([s.Authentication.fromStorage(this.storage),this.ensureSigner(),this.getEntropy(r)]),d={chainId:e.chainId,entropy:o,accountType:e.accountType??i.AccountTypeEnum.SMART_ACCOUNT,chainType:e.chainType??i.ChainTypeEnum.EVM,getPasskeyKeyFn:async e=>this.getPasskeyKey(e)},c=await n.configure(d);return{id:c.id,chainId:c.chainId,user:t.player,address:c.address,ownerAddress:c.ownerAddress,chainType:c.chainType,accountType:c.accountType,implementationType:c.implementationType,factoryAddress:c.factoryAddress,salt:c.salt,createdAt:c.createdAt,implementationAddress:c.implementationAddress,recoveryMethod:a.Account.parseRecoveryMethod(c.recoveryMethod),recoveryMethodDetails:c.recoveryMethodDetails}}async create(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:i.RecoveryMethod.AUTOMATIC},o=await s.Authentication.fromStorage(this.storage);if(!o)throw new n.OpenfortError("missing authentication",n.OpenfortErrorType.AUTHENTICATION_ERROR);if(t.recoveryMethod===i.RecoveryMethod.PASSKEY){const e=await this.passkeyHandler.createPasskey({id:r.PasskeyHandler.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:o?.player??""});t.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[d,c]=await Promise.all([this.ensureSigner(),this.getEntropy(t)]),g=await d.create({accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:c}),h={id:g.id,chainId:g.chainId,user:o.player,address:g.address,ownerAddress:g.ownerAddress,chainType:g.chainType,accountType:g.accountType,implementationType:g.implementationType,factoryAddress:g.factoryAddress,salt:g.salt,createdAt:g.createdAt,implementationAddress:g.implementationAddress,recoveryMethod:a.Account.parseRecoveryMethod(g.recoveryMethod),recoveryMethodDetails:g.recoveryMethodDetails};return this.eventEmitter.emit(i.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,h),h}async recover(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:i.RecoveryMethod.AUTOMATIC};if(r.recoveryMethod===i.RecoveryMethod.PASSKEY){if(!r.passkeyInfo?.passkeyId)throw new n.OpenfortError("Passkey ID must be provided for passkey recovery",n.OpenfortErrorType.INVALID_CONFIGURATION);r.passkeyInfo={passkeyId:r.passkeyInfo.passkeyId}}const[t,o,d]=await Promise.all([this.ensureSigner(),this.getEntropy(r),s.Authentication.fromStorage(this.storage)]),c=await t.recover({account:e.account,entropy:o}),g={id:c.id,chainId:c.chainId,implementationAddress:c.implementationAddress,factoryAddress:c.factoryAddress,salt:c.salt,user:d.player,address:c.address,ownerAddress:c.ownerAddress,chainType:c.chainType,accountType:c.accountType,implementationType:c.implementationType,createdAt:c.createdAt,recoveryMethod:a.Account.parseRecoveryMethod(c.recoveryMethod),recoveryMethodDetails:c.recoveryMethodDetails};return this.eventEmitter.emit(i.OpenfortEvents.ON_EMBEDDED_WALLET_RECOVERED,g),g}async signMessage(e,r){await this.validateAndRefreshToken();const t=await this.ensureSigner(),{hashMessage:s=!0,arrayifyMessage:n=!1}=r||{},i=await a.Account.fromStorage(this.storage);return await t.sign(e,n,s,i?.chainType)}async signTypedData(e,r,t){await this.validateAndRefreshToken();const s=await this.ensureSigner(),i=await a.Account.fromStorage(this.storage);if(!i)throw new n.OpenfortError("No account found",n.OpenfortErrorType.MISSING_SIGNER_ERROR);const o={...r};delete o.EIP712Domain;const{_TypedDataEncoder:d}=await import("@ethersproject/hash"),c=d.hash(e,o,t);return await h.signMessage({hash:c,implementationType:i.implementationType||i.type,chainId:Number(i.chainId),signer:s,address:i.address,ownerAddress:i.ownerAddress,factoryAddress:i.factoryAddress,salt:i.salt})}async exportPrivateKey(){await this.validateAndRefreshToken();const e=await this.ensureSigner();return await e.export()}async setRecoveryMethod(e,t){await this.validateAndRefreshToken();const o=await this.ensureSigner(),d=await s.Authentication.fromStorage(this.storage);if(!d)throw new n.OpenfortError("missing authentication",n.OpenfortErrorType.AUTHENTICATION_ERROR);let c,g,h,y;if(e.recoveryMethod===i.RecoveryMethod.PASSKEY){const e=await a.Account.fromStorage(this.storage);if(!e)throw new n.OpenfortError("missing account",n.OpenfortErrorType.INVALID_CONFIGURATION);const r=e?.recoveryMethodDetails?.passkeyId;if(!r)throw new n.OpenfortError("missing passkey id for account",n.OpenfortErrorType.INVALID_CONFIGURATION);h={passkeyId:r,passkeyKey:await this.passkeyHandler.deriveAndExportKey({id:r,seed:d.player})}}else if(t.recoveryMethod===i.RecoveryMethod.PASSKEY){const e=await this.passkeyHandler.createPasskey({id:r.PasskeyHandler.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:d.player});h={passkeyId:e.id,passkeyKey:e.key},y={passkeyId:e.id}}if(e.recoveryMethod===i.RecoveryMethod.PASSWORD?c=e.password:t.recoveryMethod===i.RecoveryMethod.PASSWORD&&(c=t.password),e.recoveryMethod===i.RecoveryMethod.AUTOMATIC?g=e.encryptionSession:t.recoveryMethod===i.RecoveryMethod.AUTOMATIC&&(g=t.encryptionSession),!c&&!g)throw new n.OpenfortError("Password or encryption session is not provided",n.OpenfortErrorType.INVALID_CONFIGURATION);await o.setRecoveryMethod({recoveryMethod:t.recoveryMethod,recoveryPassword:c,encryptionSession:g,passkeyInfo:h});const p=await a.Account.fromStorage(this.storage);p&&new a.Account({...p,recoveryMethod:t.recoveryMethod,recoveryMethodDetails:y}).save(this.storage)}async get(){const e=await a.Account.fromStorage(this.storage);if(!e)throw new n.OpenfortError("No signer configured",n.OpenfortErrorType.MISSING_SIGNER_ERROR);const r=await s.Authentication.fromStorage(this.storage);if(!r)throw new n.OpenfortError("No access token found",n.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return{id:e.id,chainId:e.chainId,user:r.player,address:e.address,ownerAddress:e.ownerAddress,factoryAddress:e.factoryAddress,salt:e.salt,chainType:e.chainType,accountType:e.accountType,implementationAddress:e.implementationAddress,implementationType:e.implementationType,createdAt:e.createdAt,recoveryMethod:a.Account.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails}}async list(e){const r={accountType:i.AccountTypeEnum.SMART_ACCOUNT,...e},o=t.SDKConfiguration.getInstance();if(!o)throw new n.OpenfortError("Configuration not found",n.OpenfortErrorType.INVALID_CONFIGURATION);await this.validateAndRefreshToken();const d=await s.Authentication.fromStorage(this.storage);if(!d)throw new n.OpenfortError("No access token found",n.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return n.withOpenfortError(async()=>(await this.backendApiClients.accountsApi.getAccountsV2(r,{headers:{authorization:`Bearer ${o.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}})).data.data.map(e=>({user:e.user,chainType:e.chainType,id:e.id,address:e.address,active:e.smartAccount?.active,ownerAddress:e.ownerAddress,factoryAddress:e.smartAccount?.factoryAddress,salt:e.smartAccount?.salt,accountType:e.accountType,implementationAddress:e.smartAccount?.implementationAddress,createdAt:e.createdAt,implementationType:e.smartAccount?.implementationType,chainId:e.chainId,recoveryMethod:a.Account.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails})),{default:n.OpenfortErrorType.AUTHENTICATION_ERROR})}async getEmbeddedState(){try{if(!await s.Authentication.fromStorage(this.storage))return i.EmbeddedState.UNAUTHENTICATED;return await a.Account.fromStorage(this.storage)?i.EmbeddedState.READY:i.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED}catch(e){return o.debugLog("Failed to get embedded state:",e),i.EmbeddedState.UNAUTHENTICATED}}async getEthereumProvider(e){await this.ensureInitialized();const r={announceProvider:!0,...e},t=await s.Authentication.fromStorage(this.storage),n=await a.Account.fromStorage(this.storage);return this.provider?this.provider&&r.policy&&this.provider.updatePolicy(r.policy):(this.provider=new c.EvmProvider({storage:this.storage,openfortEventEmitter:this.eventEmitter,ensureSigner:this.ensureSigner.bind(this),account:n||void 0,authentication:t||void 0,backendApiClients:this.backendApiClients,policyId:r.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this),chains:r.chains}),r.announceProvider&&g.announceProvider({info:{...g.openfortProviderInfo,...r.providerInfo},provider:this.provider})),this.provider}async ping(e){try{e>0&&await new Promise(r=>{setTimeout(r,e)});const r=await this.getIframeManager();if(!r.isLoaded())return!1;const t=await s.Authentication.fromStorage(this.storage);if(t)try{return await r.getCurrentDevice(t.player),!0}catch(e){return!1}return r.isLoaded()}catch(e){return o.debugLog("Ping failed:",e),!1}}getURL(){const e=t.SDKConfiguration.getInstance();if(!e)throw new n.OpenfortError("Configuration not found",n.OpenfortErrorType.INVALID_CONFIGURATION);return e.iframeUrl}async setMessagePoster(e){if(!e||"function"!=typeof e.postMessage)throw new n.OpenfortError("Invalid message poster",n.OpenfortErrorType.INVALID_CONFIGURATION);this.messagePoster=e,this.messenger&&this.messenger.destroy(),this.iframeManager&&this.iframeManager.destroy(),this.signer=null,this.signerPromise=null,this.iframeManager=null,this.iframeManagerPromise=null,this.messenger=null}async handleLogout(){const e=await this.ensureSigner();await e.disconnect(),this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,this.signerPromise=null}async onMessage(e){if(!e||"object"!=typeof e)return void o.debugLog("Invalid message received:",e);o.debugLog("[HANDSHAKE DEBUG] EmbeddedWalletApi onMessage:",e);const r="penpal"===e.namespace&&"SYN"===e.type||e.penpal&&"string"==typeof e.penpal;if(r&&this.messenger&&this.messagePoster)return o.debugLog("[HANDSHAKE DEBUG] Passing message directly to existing ReactNativeMessenger"),void this.messenger.handleMessage(e);const t=await this.getIframeManager();o.debugLog(`[HANDSHAKE DEBUG] IframeManager obtained, isLoaded: ${t.isLoaded()}`),r&&!t.isLoaded()&&o.debugLog("[HANDSHAKE DEBUG] Received penpal message before connection initialized, setting up connection..."),o.debugLog("[HANDSHAKE DEBUG] Calling iframeManager.onMessage"),await t.onMessage(e),o.debugLog("[HANDSHAKE DEBUG] iframeManager.onMessage completed")}isReady(){return this.iframeManager?.isLoaded()||!1}};
@@ -1 +1 @@
1
- "use strict";var t=require("axios"),e=require("../../version.js");const s="https://64a03e4967fb4dad3ecb914918c777b6@o4504593015242752.ingest.us.sentry.io/4509292415287296";class r{static sentryInstance;static queuedCalls=[];static baseTags;static set sentry(e){const n=e.getDsn();if(!n)throw new Error("Sentry DSN is not set");if(n.projectId!==s.split("https://")[1].split("/")[1]||n.host!==s.split("@")[1].split("/")[0]||n.publicKey!==s.split("@")[0].split("https://")[1])throw new Error("Sentry DSN is not valid");e.captureAxiosError=(s,n,a,o)=>{if(n instanceof t.AxiosError){if(400===n.response?.status||401===n.response?.status)return;n.name=s,e.captureException(n,{...a,captureContext:{...a?.captureContext,extra:{errorResponseData:n.response?.data,errorStatus:n.response?.status,errorHeaders:n.response?.headers,errorRequest:n.request},tags:{...r.baseTags,method:s}}})}else e.captureException(n,a,o)},r.sentryInstance=e}static get sentry(){return r.proxy}static async init({sentry:t,configuration:n}){if(t)return void(r.sentry=t);const a=await import("@sentry/browser");r.sentry=new a.BrowserClient({dsn:s,integrations:[],stackParser:a.defaultStackParser,transport:a.makeFetchTransport}),r.baseTags={projectId:n?.baseConfiguration.publishableKey,sdk:e.PACKAGE,sdkVersion:e.VERSION},r.processQueuedCalls()}static proxy=new Proxy({},{get:(t,e)=>r.sentryInstance&&"function"==typeof r.sentryInstance[e]?(...t)=>r.sentryInstance[e](...t):(...t)=>{r.queuedCalls.push({fn:e,args:t})}});static processQueuedCalls(){r.sentryInstance&&(r.queuedCalls.forEach(({fn:t,args:e})=>{"function"==typeof r.sentryInstance[t]&&r.sentryInstance[t](...e)}),r.queuedCalls=[])}}const{sentry:n}=r;exports.InternalSentry=r,exports.sentry=n;
1
+ "use strict";var t=require("axios"),e=require("../../version.js");const s="https://64a03e4967fb4dad3ecb914918c777b6@o4504593015242752.ingest.us.sentry.io/4509292415287296";class r{static sentryInstance;static queuedCalls=[];static baseTags;static set sentry(e){const n=e.getDsn();if(!n)throw new Error("Sentry DSN is not set");if(n.projectId!==s.split("https://")[1].split("/")[1]||n.host!==s.split("@")[1].split("/")[0]||n.publicKey!==s.split("@")[0].split("https://")[1])throw new Error("Sentry DSN is not valid");e.captureAxiosError=(s,n,a,o)=>{if(n instanceof t.AxiosError){if(400===n.response?.status||401===n.response?.status)return;n.name=s,e.captureException(n,{...a,captureContext:{...a?.captureContext,extra:{errorResponseData:n.response?.data,errorStatus:n.response?.status,errorHeaders:n.response?.headers,errorRequest:n.request},tags:{...r.baseTags,method:s}}})}else e.captureException(n,a,o)},r.sentryInstance=e}static get sentry(){return r.proxy}static async init({sentry:t,configuration:n}){if(t)return void(r.sentry=t);const a=await import("@sentry/browser");r.sentry=new a.BrowserClient({dsn:s,integrations:[],stackParser:a.defaultStackParser,transport:a.makeFetchTransport}),r.baseTags={projectId:n?.baseConfiguration.publishableKey??"",sdk:e.PACKAGE,sdkVersion:e.VERSION},r.processQueuedCalls()}static proxy=new Proxy({},{get:(t,e)=>r.sentryInstance&&"function"==typeof r.sentryInstance[e]?(...t)=>r.sentryInstance[e](...t):(...t)=>{r.queuedCalls.push({fn:e,args:t})}});static processQueuedCalls(){r.sentryInstance&&(r.queuedCalls.forEach(({fn:t,args:e})=>{"function"==typeof r.sentryInstance[t]&&r.sentryInstance[t](...e)}),r.queuedCalls=[])}}const{sentry:n}=r;exports.InternalSentry=r,exports.sentry=n;
@@ -1 +1 @@
1
- "use strict";exports.defaultChainRpcs={1:"https://cloudflare-eth.com",10:"https://optimism-rpc.publicnode.com",56:"https://bsc.publicnode.com",97:"https://bsc-testnet.publicnode.com",137:"https://polygon-rpc.com",204:"https://opbnb-mainnet-rpc.bnbchain.org",300:"https://sepolia.era.zksync.dev",324:"https://mainnet.era.zksync.io",1946:"https://rpc.minato.soneium.org",2741:"https://api.mainnet.abs.xyz",3939:"https://test.doschain.com",4337:"https://build.onbeam.com/rpc",5611:"https://opbnb-testnet-rpc.bnbchain.org",7979:"https://main.doschain.com",8453:"https://mainnet.base.org",11124:"https://api.testnet.abs.xyz",13337:"https://build.onbeam.com/rpc/testnet",13473:"https://rpc.testnet.immutable.com",42161:"https://arb1.arbitrum.io/rpc",42170:"https://nova.arbitrum.io/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",43114:"https://api.avax.network/ext/bc/C/rpc",50104:"https://rpc.sophon.xyz",80002:"https://polygon-amoy-bor-rpc.publicnode.com",84532:"https://sepolia.base.org",421614:"https://sepolia-rollup.arbitrum.io/rpc",7225878:"https://rpc.saakuru.network",7777777:"https://rpc.zora.energy",11155111:"https://ethereum-sepolia-rpc.publicnode.com",11155420:"https://optimism-sepolia-rpc.publicnode.com",28122024:"https://rpcv2-testnet.ancient8.gg",531050104:"https://rpc.testnet.sophon.xyz",666666666:"https://rpc.degen.tips",888888888:"https://rpc.ancient8.gg",999999999:"https://sepolia.rpc.zora.energy",85011:"https://subnets.avax.network/criminalsa/testnet/rpc",84358:"https://subnets.avax.network/titan/mainnet/rpc",10143:"https://testnet-rpc.monad.xyz",510525:"https://rpc.clankermon.com",3008:"https://kl1-testnet.kiooverse.xyz/rpc",167e3:"https://rpc.taiko.xyz"};
1
+ "use strict";exports.defaultChainRpcs={1:"https://cloudflare-eth.com",10:"https://optimism-rpc.publicnode.com",56:"https://bsc.publicnode.com",97:"https://bsc-testnet.publicnode.com",137:"https://polygon-rpc.com",1946:"https://rpc.minato.soneium.org",3008:"https://kl1-testnet.kiooverse.xyz/rpc",4337:"https://build.onbeam.com/rpc",5611:"https://opbnb-testnet-rpc.bnbchain.org",8453:"https://mainnet.base.org",10143:"https://testnet-rpc.monad.xyz",13337:"https://build.onbeam.com/rpc/testnet",42161:"https://arb1.arbitrum.io/rpc",42170:"https://nova.arbitrum.io/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",43114:"https://api.avax.network/ext/bc/C/rpc",80002:"https://polygon-amoy-bor-rpc.publicnode.com",84358:"https://subnets.avax.network/titan/mainnet/rpc",84532:"https://sepolia.base.org",421614:"https://sepolia-rollup.arbitrum.io/rpc",510525:"https://rpc.clankermon.com",510530:"https://open-loot.rpc.syndicate.io",510531:"https://open-loot.rpc.testnet.syndicate.io",7225878:"https://rpc.saakuru.network",7777777:"https://rpc.zora.energy",11155111:"https://ethereum-sepolia-rpc.publicnode.com",11155420:"https://optimism-sepolia-rpc.publicnode.com",28122024:"https://rpcv2-testnet.ancient8.gg",666666666:"https://rpc.degen.tips",888888888:"https://rpc.ancient8.gg",999999999:"https://sepolia.rpc.zora.energy"};
@@ -1 +1 @@
1
- "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="0.10.36";
1
+ "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="0.10.37";
@@ -1 +1 @@
1
- "use strict";var e=require("../core/configuration/authentication.js"),t=require("../core/configuration/passkey.js"),r=require("../core/errors/openfortError.js"),a=require("../types/types.js"),o=require("../core/config/config.js"),n=require("../core/configuration/account.js"),s=require("../storage/istorage.js");require("eventemitter3"),require("./evm/JsonRpcError.js"),require("@ethersproject/keccak256"),require("./evm/types.js"),require("./evm/provider/eip6963.js"),require("../core/errors/sentry.js"),require("./messaging/browserMessenger/backwardCompatibility.js"),require("./types.js"),require("jose");exports.EmbeddedSigner=class{iframeManager;storage;backendApiClients;passkeyHandler;eventEmitter;constructor(e,t,r,a,o){this.iframeManager=e,this.storage=t,this.backendApiClients=r,this.passkeyHandler=a,this.eventEmitter=o}async createPasskey(e){const r=await this.passkeyHandler.createPasskey({id:t.PasskeyHandler.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:e});return{id:r.id,key:r.key}}async configure(t){const s=await e.Authentication.fromStorage(this.storage);if(!s)throw new r.OpenfortError("No access token found",r.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const i=o.SDKConfiguration.getInstance();if(!i)throw new r.OpenfortError("Configuration not found",r.OpenfortErrorType.INVALID_CONFIGURATION);const c=await n.Account.fromStorage(this.storage);let d;if(c){const e={account:c.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===c.recoveryMethod&&{passkey:{id:c.recoveryMethodDetails?.passkeyId,env:c.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(c.recoveryMethodDetails?.passkeyId)}}}}},r=await this.iframeManager.recover(e);d=r.account}else{const e=await this.backendApiClients.accountsApi.getAccountsV2({user:s.player,accountType:t.accountType,chainType:t.chainType},{headers:{authorization:`Bearer ${i.baseConfiguration.publishableKey}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}});if(0===e.data.data.length){const e=t.entropy?.passkey?await this.createPasskey(s.player):void 0,r={accountType:t.accountType,chainType:t.chainType,chainId:t.chainId,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},...t.entropy.passkey&&{passkey:e}}}},a=await this.iframeManager.create(r);d=a.account}else{const r=e.data.data,a=r.find(e=>e.chainId===t.chainId),o=a||r[0],n={account:o.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===o.recoveryMethod&&{passkey:{id:o.recoveryMethodDetails?.passkeyId,env:o.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(o.recoveryMethodDetails?.passkeyId)}}}}},s=await this.iframeManager.recover(n);if(d=s.account,!a){const e=await this.iframeManager.switchChain(t.chainId);d=e.account}}}return r.withOpenfortError(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:d},{headers:{authorization:`Bearer ${i.baseConfiguration.publishableKey}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}}),t=new n.Account({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:n.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.OpenfortErrorType.AUTHENTICATION_ERROR})}async sign(e,t,r,o){const n=await this.iframeManager.sign(e,t,r,o);return this.eventEmitter.emit(a.OpenfortEvents.ON_SIGNED_MESSAGE,{message:e,signature:n}),n}async export(){return await this.iframeManager.export()}async switchChain({chainId:e}){const t=await n.Account.fromStorage(this.storage);if(t?.accountType===a.AccountTypeEnum.EOA)new n.Account({...t,chainId:e}).save(this.storage);else{const r=await this.iframeManager.switchChain(e);new n.Account({...t,id:r.account,chainId:e}).save(this.storage)}}async create(t){const s=await this.iframeManager.create(t),i=await e.Authentication.fromStorage(this.storage);if(!i)throw new r.OpenfortError("No access token found",r.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const c=o.SDKConfiguration.getInstance();if(!c)throw new r.OpenfortError("Configuration not found",r.OpenfortErrorType.INVALID_CONFIGURATION);return r.withOpenfortError(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:s.account},{headers:{authorization:`Bearer ${c.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}}),t=new n.Account({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,implementationAddress:e.data.smartAccount?.implementationAddress,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:n.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.OpenfortErrorType.AUTHENTICATION_ERROR})}async recover(t){const s=await this.iframeManager.recover(t),i=await e.Authentication.fromStorage(this.storage);if(!i)throw new r.OpenfortError("No access token found",r.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const c=o.SDKConfiguration.getInstance();if(!c)throw new r.OpenfortError("Configuration not found",r.OpenfortErrorType.INVALID_CONFIGURATION);return r.withOpenfortError(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:s.account},{headers:{authorization:`Bearer ${c.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}}),t=new n.Account({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:n.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.OpenfortErrorType.AUTHENTICATION_ERROR})}async setRecoveryMethod({recoveryMethod:e,recoveryPassword:t,encryptionSession:r,passkeyInfo:a}){await this.iframeManager.setRecoveryMethod(e,t,r,a?.passkeyKey,a?.passkeyId)}async disconnect(){await this.iframeManager.disconnect(),this.storage.remove(s.StorageKeys.ACCOUNT)}};
1
+ "use strict";var e=require("../core/configuration/authentication.js"),t=require("../core/configuration/passkey.js"),r=require("../core/errors/openfortError.js"),a=require("../types/types.js"),o=require("../core/config/config.js"),n=require("../core/configuration/account.js"),s=require("../storage/istorage.js");require("eventemitter3"),require("./evm/JsonRpcError.js"),require("@ethersproject/keccak256"),require("./evm/types.js"),require("./evm/provider/eip6963.js"),require("../core/errors/sentry.js"),require("./messaging/browserMessenger/backwardCompatibility.js"),require("./types.js"),require("jose");exports.EmbeddedSigner=class{iframeManager;storage;backendApiClients;passkeyHandler;eventEmitter;constructor(e,t,r,a,o){this.iframeManager=e,this.storage=t,this.backendApiClients=r,this.passkeyHandler=a,this.eventEmitter=o}async createPasskey(e){const r=await this.passkeyHandler.createPasskey({id:t.PasskeyHandler.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:e});return{id:r.id,key:r.key}}async configure(t){const s=await e.Authentication.fromStorage(this.storage);if(!s)throw new r.OpenfortError("No access token found",r.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const i=o.SDKConfiguration.getInstance();if(!i)throw new r.OpenfortError("Configuration not found",r.OpenfortErrorType.INVALID_CONFIGURATION);const c=await n.Account.fromStorage(this.storage);let d;if(c){const e={account:c.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===c.recoveryMethod&&{passkey:{id:c.recoveryMethodDetails?.passkeyId,env:c.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(c.recoveryMethodDetails?.passkeyId??"")}}}}},r=await this.iframeManager.recover(e);d=r.account}else{const e=await this.backendApiClients.accountsApi.getAccountsV2({user:s.player,accountType:t.accountType,chainType:t.chainType},{headers:{authorization:`Bearer ${i.baseConfiguration.publishableKey}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}});if(0===e.data.data.length){const e=t.entropy?.passkey?await this.createPasskey(s.player):void 0,r={accountType:t.accountType,chainType:t.chainType,chainId:t.chainId,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},...t.entropy.passkey&&{passkey:e}}}},a=await this.iframeManager.create(r);d=a.account}else{const r=e.data.data,a=r.find(e=>e.chainId===t.chainId),o=a||r[0],n={account:o.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===o.recoveryMethod&&{passkey:{id:o.recoveryMethodDetails?.passkeyId,env:o.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(o.recoveryMethodDetails?.passkeyId??"")}}}}},s=await this.iframeManager.recover(n);if(d=s.account,!a){const e=await this.iframeManager.switchChain(t.chainId);d=e.account}}}return r.withOpenfortError(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:d},{headers:{authorization:`Bearer ${i.baseConfiguration.publishableKey}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}}),t=new n.Account({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:n.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.OpenfortErrorType.AUTHENTICATION_ERROR})}async sign(e,t,r,o){const n=await this.iframeManager.sign(e,t,r,o);return this.eventEmitter.emit(a.OpenfortEvents.ON_SIGNED_MESSAGE,{message:e,signature:n}),n}async export(){return await this.iframeManager.export()}async switchChain({chainId:e}){const t=await n.Account.fromStorage(this.storage);if(t?.accountType===a.AccountTypeEnum.EOA)new n.Account({...t,chainId:e}).save(this.storage);else{const r=await this.iframeManager.switchChain(e);new n.Account({...t,id:r.account,chainId:e}).save(this.storage)}}async create(t){const s=await this.iframeManager.create(t),i=await e.Authentication.fromStorage(this.storage);if(!i)throw new r.OpenfortError("No access token found",r.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const c=o.SDKConfiguration.getInstance();if(!c)throw new r.OpenfortError("Configuration not found",r.OpenfortErrorType.INVALID_CONFIGURATION);return r.withOpenfortError(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:s.account},{headers:{authorization:`Bearer ${c.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}}),t=new n.Account({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,implementationAddress:e.data.smartAccount?.implementationAddress,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:n.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.OpenfortErrorType.AUTHENTICATION_ERROR})}async recover(t){const s=await this.iframeManager.recover(t),i=await e.Authentication.fromStorage(this.storage);if(!i)throw new r.OpenfortError("No access token found",r.OpenfortErrorType.NOT_LOGGED_IN_ERROR);const c=o.SDKConfiguration.getInstance();if(!c)throw new r.OpenfortError("Configuration not found",r.OpenfortErrorType.INVALID_CONFIGURATION);return r.withOpenfortError(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:s.account},{headers:{authorization:`Bearer ${c.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}}),t=new n.Account({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:n.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(a.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.OpenfortErrorType.AUTHENTICATION_ERROR})}async setRecoveryMethod({recoveryMethod:e,recoveryPassword:t,encryptionSession:r,passkeyInfo:a}){await this.iframeManager.setRecoveryMethod(e,t,r,a?.passkeyKey,a?.passkeyId)}async disconnect(){await this.iframeManager.disconnect(),this.storage.remove(s.StorageKeys.ACCOUNT)}};
@@ -1 +1 @@
1
- "use strict";var e=require("../../core/errors/openfortError.js"),r=require("./JsonRpcError.js");exports.getAssets=async({params:t,account:a,authentication:s,backendClient:o})=>{const n=await(async(r,t,a,s)=>{const o=s?.chainFilter?.map(e=>Number.parseInt(e,16));return e.withOpenfortError(async()=>(await r.rpcApi.handleRpcRequest({jsonRpcRequest:{method:"wallet_getAssets",params:{account:t.address,chainFilter:o,assetFilter:s?.assetFilter,assetTypeFilter:s?.assetTypeFilter},id:1,jsonrpc:"2.0"}},{headers:{authorization:`Bearer ${r.config.backend.accessToken}`,"x-player-token":a.token,"x-auth-provider":a.thirdPartyProvider,"x-token-type":a.thirdPartyTokenType}})).data,{default:e.OpenfortErrorType.AUTHENTICATION_ERROR})})(o,a,s,t).catch(e=>{throw new r.JsonRpcError(r.RpcErrorCode.INTERNAL_ERROR,e.message)});return n.result};
1
+ "use strict";var e=require("../../core/errors/openfortError.js"),r=require("./JsonRpcError.js");exports.getAssets=async({params:t,account:a,authentication:s,backendClient:o})=>{const n=await(async(r,t,a,s)=>e.withOpenfortError(async()=>(await r.rpcApi.handleRpcRequest({jsonRpcRequest:{method:"wallet_getAssets",params:{account:t.address,chainFilter:s?.chainFilter,assetFilter:s?.assetFilter,assetTypeFilter:s?.assetTypeFilter},id:1,jsonrpc:"2.0"}},{headers:{authorization:`Bearer ${r.config.backend.accessToken}`,"x-player-token":a.token,"x-auth-provider":a.thirdPartyProvider,"x-token-type":a.thirdPartyTokenType}})).data,{default:e.OpenfortErrorType.AUTHENTICATION_ERROR}))(o,a,s,t).catch(e=>{throw new r.JsonRpcError(r.RpcErrorCode.INTERNAL_ERROR,e.message)});return n.result};
package/dist/index.d.ts CHANGED
@@ -405,6 +405,10 @@ interface AxiosRequestConfig<D = any> {
405
405
  withXSRFToken?: boolean | ((config: InternalAxiosRequestConfig) => boolean | undefined);
406
406
  parseReviver?: (this: any, key: string, value: any) => any;
407
407
  fetchOptions?: Omit<RequestInit, 'body' | 'headers' | 'method' | 'signal'> | Record<string, any>;
408
+ httpVersion?: 1 | 2;
409
+ http2Options?: Record<string, any> & {
410
+ sessionTimeout?: number;
411
+ };
408
412
  }
409
413
 
410
414
  interface InternalAxiosRequestConfig<D = any> extends AxiosRequestConfig<D> {
@@ -1 +1 @@
1
- import{Authentication as t}from"../core/configuration/authentication.js";import{OpenfortError as e,OpenfortErrorType as a}from"../core/errors/openfortError.js";import{OpenfortEvents as i}from"../types/types.js";class r{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,a,i,r){this.storage=t,this.authManager=e,this.validateAndRefreshToken=a,this.ensureInitialized=i,this.eventEmitter=r}async logInWithEmailPassword({email:r,password:s,ecosystemGame:n}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"email",provider:"email"});try{const e=await this.authManager.loginEmailPassword(r,s,n);return"action"in e||(new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async signUpGuest(){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"guest"});try{const e=await this.authManager.registerGuest();return new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async signUpWithEmailPassword({email:r,password:s,options:n,ecosystemGame:o}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"email",provider:"email"});try{const e=await this.authManager.signupEmailPassword(r,s,n?.data.name,o);return"action"in e||(new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async linkEmailPassword({email:t,password:e,authToken:a,ecosystemGame:i}){return await this.validateAndRefreshToken(),await this.authManager.linkEmail(t,e,a,i)}async unlinkEmailPassword({email:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkEmail(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async resetPassword({email:t,password:e,state:a}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e,a)}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async verifyEmail({email:t,state:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async initOAuth({provider:r,options:s,ecosystemGame:n}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);return this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"oauth",provider:r}),await this.authManager.initOAuth(r,s,n)}async initLinkOAuth({provider:r,options:s,ecosystemGame:n}){await this.validateAndRefreshToken();const o=await t.fromStorage(this.storage);if(!o)throw new e("No authentication found",a.NOT_LOGGED_IN_ERROR);return this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"oauth",provider:r}),await this.authManager.linkOAuth(o,r,s,n)}async unlinkOAuth({provider:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkOAuth(t,e)}async poolOAuth(e){await this.ensureInitialized();try{const a=await this.authManager.poolOAuth(e);return new t("jwt",a.token,a.player.id,a.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,a),a}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async loginWithIdToken({provider:r,token:s,ecosystemGame:n}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"idToken",provider:r});try{const e=await this.authManager.loginWithIdToken(r,s,n);return new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async initSIWE({address:t,ecosystemGame:e}){return await this.ensureInitialized(),await this.authManager.initSIWE(t,e)}async authenticateWithSIWE({signature:r,message:s,walletClientType:n,connectorType:o}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"siwe",provider:"wallet"});try{const e=await this.authManager.authenticateSIWE(r,s,n,o);return new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async linkWallet({signature:t,message:e,walletClientType:a,connectorType:i,authToken:r}){return await this.validateAndRefreshToken(),await this.authManager.linkWallet(t,e,a,i,r)}async unlinkWallet({address:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkWallet(t,e)}async storeCredentials(i){if(await this.ensureInitialized(),!i.player)throw new e("Player ID is required to store credentials",a.INVALID_CONFIGURATION);new t("jwt",i.accessToken,i.player,i.refreshToken).save(this.storage)}async logout(){const e=await t.fromStorage(this.storage);if(e){try{"third_party"!==e.type&&await this.authManager.logout(e.token,e?.refreshToken)}catch(t){}t.clear(this.storage),this.eventEmitter.emit(i.ON_LOGOUT)}}}export{r as AuthApi};
1
+ import{Authentication as t}from"../core/configuration/authentication.js";import{OpenfortError as e,OpenfortErrorType as a}from"../core/errors/openfortError.js";import{OpenfortEvents as i}from"../types/types.js";class r{storage;authManager;validateAndRefreshToken;ensureInitialized;eventEmitter;constructor(t,e,a,i,r){this.storage=t,this.authManager=e,this.validateAndRefreshToken=a,this.ensureInitialized=i,this.eventEmitter=r}async logInWithEmailPassword({email:r,password:s,ecosystemGame:n}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"email",provider:"email"});try{const e=await this.authManager.loginEmailPassword(r,s,n);return"action"in e||(new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async signUpGuest(){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"guest"});try{const e=await this.authManager.registerGuest();return new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async signUpWithEmailPassword({email:r,password:s,options:n,ecosystemGame:o}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"email",provider:"email"});try{const e=await this.authManager.signupEmailPassword(r,s,n?.data.name,o);return"action"in e||(new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e)),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async linkEmailPassword({email:t,password:e,authToken:a,ecosystemGame:i}){return await this.validateAndRefreshToken(),await this.authManager.linkEmail(t,e,a,i)}async unlinkEmailPassword({email:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkEmail(t,e)}async requestEmailVerification({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestEmailVerification(t,e)}async resetPassword({email:t,password:e,state:a}){await this.ensureInitialized(),await this.authManager.resetPassword(t,e,a)}async requestResetPassword({email:t,redirectUrl:e}){await this.ensureInitialized(),await this.authManager.requestResetPassword(t,e)}async verifyEmail({email:t,state:e}){await this.ensureInitialized(),await this.authManager.verifyEmail(t,e)}async initOAuth({provider:r,options:s,ecosystemGame:n}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);return this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"oauth",provider:r}),await this.authManager.initOAuth(r,s,n)}async initLinkOAuth({provider:r,options:s,ecosystemGame:n}){await this.validateAndRefreshToken();const o=await t.fromStorage(this.storage);if(!o)throw new e("No authentication found",a.NOT_LOGGED_IN_ERROR);return this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"oauth",provider:r}),await this.authManager.linkOAuth(o,r,s,n)}async unlinkOAuth({provider:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkOAuth(t,e)}async poolOAuth(e){await this.ensureInitialized();try{const a=await this.authManager.poolOAuth(e);return new t("jwt",a.token,a.player.id,a.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,a),a}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async loginWithIdToken({provider:r,token:s,ecosystemGame:n}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"idToken",provider:r});try{const e=await this.authManager.loginWithIdToken(r,s,n);return new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async initSIWE({address:t,ecosystemGame:e}){return await this.ensureInitialized(),await this.authManager.initSIWE(t,e)}async authenticateWithSIWE({signature:r,message:s,walletClientType:n,connectorType:o}){await this.ensureInitialized();if(await t.fromStorage(this.storage))throw new e("Already logged in",a.ALREADY_LOGGED_IN_ERROR);this.eventEmitter.emit(i.ON_AUTH_INIT,{method:"siwe",provider:"wallet"});try{const e=await this.authManager.authenticateSIWE(r,s,n,o);return new t("jwt",e.token,e.player.id,e.refreshToken).save(this.storage),this.eventEmitter.emit(i.ON_AUTH_SUCCESS,e),e}catch(t){throw this.eventEmitter.emit(i.ON_AUTH_FAILURE,t),t}}async linkWallet({signature:t,message:e,walletClientType:a,connectorType:i,authToken:r}){return await this.validateAndRefreshToken(),await this.authManager.linkWallet(t,e,a,i,r)}async unlinkWallet({address:t,authToken:e}){return await this.validateAndRefreshToken(),await this.authManager.unlinkWallet(t,e)}async storeCredentials(i){if(await this.ensureInitialized(),!i.player)throw new e("Player ID is required to store credentials",a.INVALID_CONFIGURATION);new t("jwt",i.accessToken,i.player,i.refreshToken).save(this.storage)}async logout(){const e=await t.fromStorage(this.storage);if(e){try{"third_party"!==e.type&&await this.authManager.logout(e.token,e.refreshToken??"")}catch(t){}t.clear(this.storage),this.eventEmitter.emit(i.ON_LOGOUT)}}}export{r as AuthApi};
@@ -1 +1 @@
1
- import{BackendApiClients as e}from"../../../packages/internal/openapi-clients/dist/index.js";import{PasskeyHandler as t}from"../core/configuration/passkey.js";import{SDKConfiguration as r}from"../core/config/config.js";import{Account as s}from"../core/configuration/account.js";import{Authentication as a}from"../core/configuration/authentication.js";import{OpenfortError as i,OpenfortErrorType as n,withOpenfortError as o}from"../core/errors/openfortError.js";import{OpenfortEvents as d,RecoveryMethod as c,ChainTypeEnum as h,AccountTypeEnum as m,EmbeddedState as g}from"../types/types.js";import{debugLog as y}from"../utils/debug.js";import{EmbeddedSigner as l}from"../wallets/embedded.js";import{EvmProvider as p}from"../wallets/evm/evmProvider.js";import"../wallets/evm/types.js";import{announceProvider as f,openfortProviderInfo as A}from"../wallets/evm/provider/eip6963.js";import{signMessage as u}from"../wallets/evm/walletHelpers.js";import{IframeManager as w}from"../wallets/iframeManager.js";import{ReactNativeMessenger as I}from"../wallets/messaging/ReactNativeMessenger.js";import"../wallets/messaging/browserMessenger/backwardCompatibility.js";import v from"../wallets/messaging/browserMessenger/messengers/WindowMessenger.js";class M{storage;validateAndRefreshToken;ensureInitialized;eventEmitter;passkeyHandler;iframeManager=null;iframeManagerPromise=null;signer=null;signerPromise=null;provider=null;messagePoster=null;messenger=null;constructor(e,t,r,s,a){this.storage=e,this.validateAndRefreshToken=t,this.ensureInitialized=r,this.eventEmitter=s,this.passkeyHandler=a,this.eventEmitter.on(d.ON_LOGOUT,()=>{y("Handling logout event in EmbeddedWalletApi"),this.handleLogout()})}get backendApiClients(){const t=r.getInstance();if(!t)throw new i("Configuration not found",n.INVALID_CONFIGURATION);return new e({basePath:t.backendUrl,accessToken:t.baseConfiguration.publishableKey,nativeAppIdentifier:t.nativeAppIdentifier})}async getIframeManager(){if(y("[HANDSHAKE DEBUG] getIframeManager called"),this.iframeManager&&this.iframeManager.hasFailed&&(y("[HANDSHAKE DEBUG] Existing iframeManager has failed, clearing for recreation"),this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null),this.iframeManager)return y("[HANDSHAKE DEBUG] Returning existing iframeManager instance"),this.iframeManager;if(this.iframeManagerPromise)return y("[HANDSHAKE DEBUG] Returning existing iframeManagerPromise"),this.iframeManagerPromise;y("[HANDSHAKE DEBUG] Creating new iframeManager"),this.iframeManagerPromise=this.createIframeManager();try{return y("[HANDSHAKE DEBUG] Awaiting iframeManager creation"),this.iframeManager=await this.iframeManagerPromise,y("[HANDSHAKE DEBUG] IframeManager created successfully"),this.iframeManagerPromise=null,this.iframeManager}catch(e){throw y("[HANDSHAKE DEBUG] Error creating iframeManager:",e),this.iframeManagerPromise=null,this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null,e}}async createIframeManager(){y("[HANDSHAKE DEBUG] createIframeManager starting");const e=r.getInstance();if(!e)throw y("[HANDSHAKE DEBUG] Configuration not found"),new i("Configuration not found",n.INVALID_CONFIGURATION);let t;if(y("[HANDSHAKE DEBUG] Configuration found"),this.messagePoster)y("[HANDSHAKE DEBUG] Creating ReactNativeMessenger with messagePoster"),this.messenger&&(y("[HANDSHAKE DEBUG] Destroying old messenger before creating new one"),this.messenger.destroy()),this.messenger=new I(this.messagePoster),y("[HANDSHAKE DEBUG] Created new ReactNativeMessenger instance"),t=this.messenger;else{y("[HANDSHAKE DEBUG] Creating WindowMessenger for browser mode");const r=this.createIframe(e.iframeUrl),s=new URL(e.iframeUrl).origin;t=new v({remoteWindow:r.contentWindow,allowedOrigins:[s]}),y("[HANDSHAKE DEBUG] Created WindowMessenger")}return y("[HANDSHAKE DEBUG] Creating IframeManager instance"),new w(e,this.storage,t)}async ensureSigner(){if(this.iframeManager&&this.iframeManager.hasFailed&&(y("IframeManager has failed, clearing signer for recreation"),this.signer=null),this.signer)return this.signer;if(this.signerPromise)return this.signerPromise;this.signerPromise=this.createSigner();try{return this.signer=await this.signerPromise,this.signer}catch(e){throw this.signerPromise=null,e}finally{this.signerPromise=null}}async createSigner(){const e=await this.getIframeManager();return new l(e,this.storage,this.backendApiClients,this.passkeyHandler,this.eventEmitter)}createIframe(e){if("undefined"==typeof document)throw new i("Document is not available. Please provide a message poster for non-browser environments.",n.INVALID_CONFIGURATION);const t=document.getElementById("openfort-iframe");t&&t.remove();const r=document.createElement("iframe");return r.style.display="none",r.id="openfort-iframe",r.src=e,document.body.appendChild(r),r}async getPasskeyKey(e){const t=await a.fromStorage(this.storage);return await this.passkeyHandler.deriveAndExportKey({id:e,seed:t.player})}async getEntropy(e){switch(e.recoveryMethod){case c.PASSWORD:return{recoveryPassword:e.password};case c.AUTOMATIC:return{encryptionSession:e.encryptionSession};case c.PASSKEY:return{passkey:e.passkeyInfo?{id:e.passkeyInfo.passkeyId,key:e.passkeyInfo.passkeyKey||await this.getPasskeyKey(e.passkeyInfo.passkeyId)}:{}};default:throw new i("Invalid recovery method",n.INVALID_CONFIGURATION)}}async configure(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:c.AUTOMATIC},[r,i,n]=await Promise.all([a.fromStorage(this.storage),this.ensureSigner(),this.getEntropy(t)]),o={chainId:e.chainId,entropy:n,accountType:e.accountType??m.SMART_ACCOUNT,chainType:e.chainType??h.EVM,getPasskeyKeyFn:async e=>this.getPasskeyKey(e)},d=await i.configure(o);return{id:d.id,chainId:d.chainId,user:r.player,address:d.address,ownerAddress:d.ownerAddress,chainType:d.chainType,accountType:d.accountType,implementationType:d.implementationType,factoryAddress:d.factoryAddress,salt:d.salt,createdAt:d.createdAt,implementationAddress:d.implementationAddress,recoveryMethod:s.parseRecoveryMethod(d.recoveryMethod),recoveryMethodDetails:d.recoveryMethodDetails}}async create(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:c.AUTOMATIC},o=await a.fromStorage(this.storage);if(!o)throw new i("missing authentication",n.AUTHENTICATION_ERROR);if(r.recoveryMethod===c.PASSKEY){const e=await this.passkeyHandler.createPasskey({id:t.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:o?.player});r.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[h,m]=await Promise.all([this.ensureSigner(),this.getEntropy(r)]),g=await h.create({accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:m}),y={id:g.id,chainId:g.chainId,user:o.player,address:g.address,ownerAddress:g.ownerAddress,chainType:g.chainType,accountType:g.accountType,implementationType:g.implementationType,factoryAddress:g.factoryAddress,salt:g.salt,createdAt:g.createdAt,implementationAddress:g.implementationAddress,recoveryMethod:s.parseRecoveryMethod(g.recoveryMethod),recoveryMethodDetails:g.recoveryMethodDetails};return this.eventEmitter.emit(d.ON_EMBEDDED_WALLET_CREATED,y),y}async recover(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:c.AUTOMATIC};if(t.recoveryMethod===c.PASSKEY){if(!t.passkeyInfo?.passkeyId)throw new i("Passkey ID must be provided for passkey recovery",n.INVALID_CONFIGURATION);t.passkeyInfo={passkeyId:t.passkeyInfo.passkeyId}}const[r,o,h]=await Promise.all([this.ensureSigner(),this.getEntropy(t),a.fromStorage(this.storage)]),m=await r.recover({account:e.account,entropy:o}),g={id:m.id,chainId:m.chainId,implementationAddress:m.implementationAddress,factoryAddress:m.factoryAddress,salt:m.salt,user:h.player,address:m.address,ownerAddress:m.ownerAddress,chainType:m.chainType,accountType:m.accountType,implementationType:m.implementationType,createdAt:m.createdAt,recoveryMethod:s.parseRecoveryMethod(m.recoveryMethod),recoveryMethodDetails:m.recoveryMethodDetails};return this.eventEmitter.emit(d.ON_EMBEDDED_WALLET_RECOVERED,g),g}async signMessage(e,t){await this.validateAndRefreshToken();const r=await this.ensureSigner(),{hashMessage:a=!0,arrayifyMessage:i=!1}=t||{},n=await s.fromStorage(this.storage);return await r.sign(e,i,a,n?.chainType)}async signTypedData(e,t,r){await this.validateAndRefreshToken();const a=await this.ensureSigner(),o=await s.fromStorage(this.storage);if(!o)throw new i("No account found",n.MISSING_SIGNER_ERROR);const d={...t};delete d.EIP712Domain;const{_TypedDataEncoder:c}=await import("@ethersproject/hash"),h=c.hash(e,d,r);return await u({hash:h,implementationType:o.implementationType||o.type,chainId:Number(o.chainId),signer:a,address:o.address,ownerAddress:o.ownerAddress,factoryAddress:o.factoryAddress,salt:o.salt})}async exportPrivateKey(){await this.validateAndRefreshToken();const e=await this.ensureSigner();return await e.export()}async setRecoveryMethod(e,r){await this.validateAndRefreshToken();const o=await this.ensureSigner(),d=await a.fromStorage(this.storage);if(!d)throw new i("missing authentication",n.AUTHENTICATION_ERROR);let h,m,g,y;if(e.recoveryMethod===c.PASSKEY){const e=await s.fromStorage(this.storage);if(!e)throw new i("missing account",n.INVALID_CONFIGURATION);const t=e?.recoveryMethodDetails?.passkeyId;if(!t)throw new i("missing passkey id for account",n.INVALID_CONFIGURATION);g={passkeyId:t,passkeyKey:await this.passkeyHandler.deriveAndExportKey({id:t,seed:d.player})}}else if(r.recoveryMethod===c.PASSKEY){const e=await this.passkeyHandler.createPasskey({id:t.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:d.player});g={passkeyId:e.id,passkeyKey:e.key},y={passkeyId:e.id}}if(e.recoveryMethod===c.PASSWORD?h=e.password:r.recoveryMethod===c.PASSWORD&&(h=r.password),e.recoveryMethod===c.AUTOMATIC?m=e.encryptionSession:r.recoveryMethod===c.AUTOMATIC&&(m=r.encryptionSession),!h&&!m)throw new i("Password or encryption session is not provided",n.INVALID_CONFIGURATION);await o.setRecoveryMethod({recoveryMethod:r.recoveryMethod,recoveryPassword:h,encryptionSession:m,passkeyInfo:g});const l=await s.fromStorage(this.storage);l&&new s({...l,recoveryMethod:r.recoveryMethod,recoveryMethodDetails:y}).save(this.storage)}async get(){const e=await s.fromStorage(this.storage);if(!e)throw new i("No signer configured",n.MISSING_SIGNER_ERROR);const t=await a.fromStorage(this.storage);if(!t)throw new i("No access token found",n.NOT_LOGGED_IN_ERROR);return{id:e.id,chainId:e.chainId,user:t.player,address:e.address,ownerAddress:e.ownerAddress,factoryAddress:e.factoryAddress,salt:e.salt,chainType:e.chainType,accountType:e.accountType,implementationAddress:e.implementationAddress,implementationType:e.implementationType,createdAt:e.createdAt,recoveryMethod:s.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails}}async list(e){const t={accountType:m.SMART_ACCOUNT,...e},d=r.getInstance();if(!d)throw new i("Configuration not found",n.INVALID_CONFIGURATION);await this.validateAndRefreshToken();const c=await a.fromStorage(this.storage);if(!c)throw new i("No access token found",n.NOT_LOGGED_IN_ERROR);return o(async()=>(await this.backendApiClients.accountsApi.getAccountsV2(t,{headers:{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":c.token,"x-auth-provider":c.thirdPartyProvider,"x-token-type":c.thirdPartyTokenType}})).data.data.map(e=>({user:e.user,chainType:e.chainType,id:e.id,address:e.address,active:e.smartAccount?.active,ownerAddress:e.ownerAddress,factoryAddress:e.smartAccount?.factoryAddress,salt:e.smartAccount?.salt,accountType:e.accountType,implementationAddress:e.smartAccount?.implementationAddress,createdAt:e.createdAt,implementationType:e.smartAccount?.implementationType,chainId:e.chainId,recoveryMethod:s.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails})),{default:n.AUTHENTICATION_ERROR})}async getEmbeddedState(){try{if(!await a.fromStorage(this.storage))return g.UNAUTHENTICATED;return await s.fromStorage(this.storage)?g.READY:g.EMBEDDED_SIGNER_NOT_CONFIGURED}catch(e){return y("Failed to get embedded state:",e),g.UNAUTHENTICATED}}async getEthereumProvider(e){await this.ensureInitialized();const t={announceProvider:!0,...e},r=await a.fromStorage(this.storage),i=await s.fromStorage(this.storage);return this.provider?this.provider&&t.policy&&this.provider.updatePolicy(t.policy):(this.provider=new p({storage:this.storage,openfortEventEmitter:this.eventEmitter,ensureSigner:this.ensureSigner.bind(this),account:i||void 0,authentication:r||void 0,backendApiClients:this.backendApiClients,policyId:t.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this),chains:t.chains}),t.announceProvider&&f({info:{...A,...t.providerInfo},provider:this.provider})),this.provider}async ping(e){try{e>0&&await new Promise(t=>{setTimeout(t,e)});const t=await this.getIframeManager();if(!t.isLoaded())return!1;const r=await a.fromStorage(this.storage);if(r)try{return await t.getCurrentDevice(r.player),!0}catch(e){return!1}return t.isLoaded()}catch(e){return y("Ping failed:",e),!1}}getURL(){const e=r.getInstance();if(!e)throw new i("Configuration not found",n.INVALID_CONFIGURATION);return e.iframeUrl}async setMessagePoster(e){if(!e||"function"!=typeof e.postMessage)throw new i("Invalid message poster",n.INVALID_CONFIGURATION);this.messagePoster=e,this.messenger&&this.messenger.destroy(),this.iframeManager&&this.iframeManager.destroy(),this.signer=null,this.signerPromise=null,this.iframeManager=null,this.iframeManagerPromise=null,this.messenger=null}async handleLogout(){const e=await this.ensureSigner();await e.disconnect(),this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,this.signerPromise=null}async onMessage(e){if(!e||"object"!=typeof e)return void y("Invalid message received:",e);y("[HANDSHAKE DEBUG] EmbeddedWalletApi onMessage:",e);const t="penpal"===e.namespace&&"SYN"===e.type||e.penpal&&"string"==typeof e.penpal;if(t&&this.messenger&&this.messagePoster)return y("[HANDSHAKE DEBUG] Passing message directly to existing ReactNativeMessenger"),void this.messenger.handleMessage(e);const r=await this.getIframeManager();y(`[HANDSHAKE DEBUG] IframeManager obtained, isLoaded: ${r.isLoaded()}`),t&&!r.isLoaded()&&y("[HANDSHAKE DEBUG] Received penpal message before connection initialized, setting up connection..."),y("[HANDSHAKE DEBUG] Calling iframeManager.onMessage"),await r.onMessage(e),y("[HANDSHAKE DEBUG] iframeManager.onMessage completed")}isReady(){return this.iframeManager?.isLoaded()||!1}}export{M as EmbeddedWalletApi};
1
+ import{BackendApiClients as e}from"../../../packages/internal/openapi-clients/dist/index.js";import{PasskeyHandler as t}from"../core/configuration/passkey.js";import{SDKConfiguration as r}from"../core/config/config.js";import{Account as s}from"../core/configuration/account.js";import{Authentication as a}from"../core/configuration/authentication.js";import{OpenfortError as i,OpenfortErrorType as n,withOpenfortError as o}from"../core/errors/openfortError.js";import{OpenfortEvents as d,RecoveryMethod as c,ChainTypeEnum as h,AccountTypeEnum as m,EmbeddedState as g}from"../types/types.js";import{debugLog as y}from"../utils/debug.js";import{EmbeddedSigner as l}from"../wallets/embedded.js";import{EvmProvider as p}from"../wallets/evm/evmProvider.js";import"../wallets/evm/types.js";import{announceProvider as f,openfortProviderInfo as A}from"../wallets/evm/provider/eip6963.js";import{signMessage as u}from"../wallets/evm/walletHelpers.js";import{IframeManager as w}from"../wallets/iframeManager.js";import{ReactNativeMessenger as I}from"../wallets/messaging/ReactNativeMessenger.js";import"../wallets/messaging/browserMessenger/backwardCompatibility.js";import v from"../wallets/messaging/browserMessenger/messengers/WindowMessenger.js";class M{storage;validateAndRefreshToken;ensureInitialized;eventEmitter;passkeyHandler;iframeManager=null;iframeManagerPromise=null;signer=null;signerPromise=null;provider=null;messagePoster=null;messenger=null;constructor(e,t,r,s,a){this.storage=e,this.validateAndRefreshToken=t,this.ensureInitialized=r,this.eventEmitter=s,this.passkeyHandler=a,this.eventEmitter.on(d.ON_LOGOUT,()=>{y("Handling logout event in EmbeddedWalletApi"),this.handleLogout()})}get backendApiClients(){const t=r.getInstance();if(!t)throw new i("Configuration not found",n.INVALID_CONFIGURATION);return new e({basePath:t.backendUrl,accessToken:t.baseConfiguration.publishableKey,nativeAppIdentifier:t.nativeAppIdentifier})}async getIframeManager(){if(y("[HANDSHAKE DEBUG] getIframeManager called"),this.iframeManager&&this.iframeManager.hasFailed&&(y("[HANDSHAKE DEBUG] Existing iframeManager has failed, clearing for recreation"),this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null),this.iframeManager)return y("[HANDSHAKE DEBUG] Returning existing iframeManager instance"),this.iframeManager;if(this.iframeManagerPromise)return y("[HANDSHAKE DEBUG] Returning existing iframeManagerPromise"),this.iframeManagerPromise;y("[HANDSHAKE DEBUG] Creating new iframeManager"),this.iframeManagerPromise=this.createIframeManager();try{return y("[HANDSHAKE DEBUG] Awaiting iframeManager creation"),this.iframeManager=await this.iframeManagerPromise,y("[HANDSHAKE DEBUG] IframeManager created successfully"),this.iframeManagerPromise=null,this.iframeManager}catch(e){throw y("[HANDSHAKE DEBUG] Error creating iframeManager:",e),this.iframeManagerPromise=null,this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null,e}}async createIframeManager(){y("[HANDSHAKE DEBUG] createIframeManager starting");const e=r.getInstance();if(!e)throw y("[HANDSHAKE DEBUG] Configuration not found"),new i("Configuration not found",n.INVALID_CONFIGURATION);let t;if(y("[HANDSHAKE DEBUG] Configuration found"),this.messagePoster)y("[HANDSHAKE DEBUG] Creating ReactNativeMessenger with messagePoster"),this.messenger&&(y("[HANDSHAKE DEBUG] Destroying old messenger before creating new one"),this.messenger.destroy()),this.messenger=new I(this.messagePoster),y("[HANDSHAKE DEBUG] Created new ReactNativeMessenger instance"),t=this.messenger;else{y("[HANDSHAKE DEBUG] Creating WindowMessenger for browser mode");const r=this.createIframe(e.iframeUrl),s=new URL(e.iframeUrl).origin;t=new v({remoteWindow:r.contentWindow,allowedOrigins:[s]}),y("[HANDSHAKE DEBUG] Created WindowMessenger")}return y("[HANDSHAKE DEBUG] Creating IframeManager instance"),new w(e,this.storage,t)}async ensureSigner(){if(this.iframeManager&&this.iframeManager.hasFailed&&(y("IframeManager has failed, clearing signer for recreation"),this.signer=null),this.signer)return this.signer;if(this.signerPromise)return this.signerPromise;this.signerPromise=this.createSigner();try{return this.signer=await this.signerPromise,this.signer}catch(e){throw this.signerPromise=null,e}finally{this.signerPromise=null}}async createSigner(){const e=await this.getIframeManager();return new l(e,this.storage,this.backendApiClients,this.passkeyHandler,this.eventEmitter)}createIframe(e){if("undefined"==typeof document)throw new i("Document is not available. Please provide a message poster for non-browser environments.",n.INVALID_CONFIGURATION);const t=document.getElementById("openfort-iframe");t&&t.remove();const r=document.createElement("iframe");return r.style.display="none",r.id="openfort-iframe",r.src=e,document.body.appendChild(r),r}async getPasskeyKey(e){const t=await a.fromStorage(this.storage);return await this.passkeyHandler.deriveAndExportKey({id:e,seed:t.player})}async getEntropy(e){switch(e.recoveryMethod){case c.PASSWORD:return{recoveryPassword:e.password};case c.AUTOMATIC:return{encryptionSession:e.encryptionSession};case c.PASSKEY:return{passkey:e.passkeyInfo?{id:e.passkeyInfo.passkeyId,key:e.passkeyInfo.passkeyKey||await this.getPasskeyKey(e.passkeyInfo.passkeyId)}:{}};default:throw new i("Invalid recovery method",n.INVALID_CONFIGURATION)}}async configure(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:c.AUTOMATIC},[r,i,n]=await Promise.all([a.fromStorage(this.storage),this.ensureSigner(),this.getEntropy(t)]),o={chainId:e.chainId,entropy:n,accountType:e.accountType??m.SMART_ACCOUNT,chainType:e.chainType??h.EVM,getPasskeyKeyFn:async e=>this.getPasskeyKey(e)},d=await i.configure(o);return{id:d.id,chainId:d.chainId,user:r.player,address:d.address,ownerAddress:d.ownerAddress,chainType:d.chainType,accountType:d.accountType,implementationType:d.implementationType,factoryAddress:d.factoryAddress,salt:d.salt,createdAt:d.createdAt,implementationAddress:d.implementationAddress,recoveryMethod:s.parseRecoveryMethod(d.recoveryMethod),recoveryMethodDetails:d.recoveryMethodDetails}}async create(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:c.AUTOMATIC},o=await a.fromStorage(this.storage);if(!o)throw new i("missing authentication",n.AUTHENTICATION_ERROR);if(r.recoveryMethod===c.PASSKEY){const e=await this.passkeyHandler.createPasskey({id:t.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:o?.player??""});r.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[h,m]=await Promise.all([this.ensureSigner(),this.getEntropy(r)]),g=await h.create({accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:m}),y={id:g.id,chainId:g.chainId,user:o.player,address:g.address,ownerAddress:g.ownerAddress,chainType:g.chainType,accountType:g.accountType,implementationType:g.implementationType,factoryAddress:g.factoryAddress,salt:g.salt,createdAt:g.createdAt,implementationAddress:g.implementationAddress,recoveryMethod:s.parseRecoveryMethod(g.recoveryMethod),recoveryMethodDetails:g.recoveryMethodDetails};return this.eventEmitter.emit(d.ON_EMBEDDED_WALLET_CREATED,y),y}async recover(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:c.AUTOMATIC};if(t.recoveryMethod===c.PASSKEY){if(!t.passkeyInfo?.passkeyId)throw new i("Passkey ID must be provided for passkey recovery",n.INVALID_CONFIGURATION);t.passkeyInfo={passkeyId:t.passkeyInfo.passkeyId}}const[r,o,h]=await Promise.all([this.ensureSigner(),this.getEntropy(t),a.fromStorage(this.storage)]),m=await r.recover({account:e.account,entropy:o}),g={id:m.id,chainId:m.chainId,implementationAddress:m.implementationAddress,factoryAddress:m.factoryAddress,salt:m.salt,user:h.player,address:m.address,ownerAddress:m.ownerAddress,chainType:m.chainType,accountType:m.accountType,implementationType:m.implementationType,createdAt:m.createdAt,recoveryMethod:s.parseRecoveryMethod(m.recoveryMethod),recoveryMethodDetails:m.recoveryMethodDetails};return this.eventEmitter.emit(d.ON_EMBEDDED_WALLET_RECOVERED,g),g}async signMessage(e,t){await this.validateAndRefreshToken();const r=await this.ensureSigner(),{hashMessage:a=!0,arrayifyMessage:i=!1}=t||{},n=await s.fromStorage(this.storage);return await r.sign(e,i,a,n?.chainType)}async signTypedData(e,t,r){await this.validateAndRefreshToken();const a=await this.ensureSigner(),o=await s.fromStorage(this.storage);if(!o)throw new i("No account found",n.MISSING_SIGNER_ERROR);const d={...t};delete d.EIP712Domain;const{_TypedDataEncoder:c}=await import("@ethersproject/hash"),h=c.hash(e,d,r);return await u({hash:h,implementationType:o.implementationType||o.type,chainId:Number(o.chainId),signer:a,address:o.address,ownerAddress:o.ownerAddress,factoryAddress:o.factoryAddress,salt:o.salt})}async exportPrivateKey(){await this.validateAndRefreshToken();const e=await this.ensureSigner();return await e.export()}async setRecoveryMethod(e,r){await this.validateAndRefreshToken();const o=await this.ensureSigner(),d=await a.fromStorage(this.storage);if(!d)throw new i("missing authentication",n.AUTHENTICATION_ERROR);let h,m,g,y;if(e.recoveryMethod===c.PASSKEY){const e=await s.fromStorage(this.storage);if(!e)throw new i("missing account",n.INVALID_CONFIGURATION);const t=e?.recoveryMethodDetails?.passkeyId;if(!t)throw new i("missing passkey id for account",n.INVALID_CONFIGURATION);g={passkeyId:t,passkeyKey:await this.passkeyHandler.deriveAndExportKey({id:t,seed:d.player})}}else if(r.recoveryMethod===c.PASSKEY){const e=await this.passkeyHandler.createPasskey({id:t.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:d.player});g={passkeyId:e.id,passkeyKey:e.key},y={passkeyId:e.id}}if(e.recoveryMethod===c.PASSWORD?h=e.password:r.recoveryMethod===c.PASSWORD&&(h=r.password),e.recoveryMethod===c.AUTOMATIC?m=e.encryptionSession:r.recoveryMethod===c.AUTOMATIC&&(m=r.encryptionSession),!h&&!m)throw new i("Password or encryption session is not provided",n.INVALID_CONFIGURATION);await o.setRecoveryMethod({recoveryMethod:r.recoveryMethod,recoveryPassword:h,encryptionSession:m,passkeyInfo:g});const l=await s.fromStorage(this.storage);l&&new s({...l,recoveryMethod:r.recoveryMethod,recoveryMethodDetails:y}).save(this.storage)}async get(){const e=await s.fromStorage(this.storage);if(!e)throw new i("No signer configured",n.MISSING_SIGNER_ERROR);const t=await a.fromStorage(this.storage);if(!t)throw new i("No access token found",n.NOT_LOGGED_IN_ERROR);return{id:e.id,chainId:e.chainId,user:t.player,address:e.address,ownerAddress:e.ownerAddress,factoryAddress:e.factoryAddress,salt:e.salt,chainType:e.chainType,accountType:e.accountType,implementationAddress:e.implementationAddress,implementationType:e.implementationType,createdAt:e.createdAt,recoveryMethod:s.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails}}async list(e){const t={accountType:m.SMART_ACCOUNT,...e},d=r.getInstance();if(!d)throw new i("Configuration not found",n.INVALID_CONFIGURATION);await this.validateAndRefreshToken();const c=await a.fromStorage(this.storage);if(!c)throw new i("No access token found",n.NOT_LOGGED_IN_ERROR);return o(async()=>(await this.backendApiClients.accountsApi.getAccountsV2(t,{headers:{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":c.token,"x-auth-provider":c.thirdPartyProvider,"x-token-type":c.thirdPartyTokenType}})).data.data.map(e=>({user:e.user,chainType:e.chainType,id:e.id,address:e.address,active:e.smartAccount?.active,ownerAddress:e.ownerAddress,factoryAddress:e.smartAccount?.factoryAddress,salt:e.smartAccount?.salt,accountType:e.accountType,implementationAddress:e.smartAccount?.implementationAddress,createdAt:e.createdAt,implementationType:e.smartAccount?.implementationType,chainId:e.chainId,recoveryMethod:s.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails})),{default:n.AUTHENTICATION_ERROR})}async getEmbeddedState(){try{if(!await a.fromStorage(this.storage))return g.UNAUTHENTICATED;return await s.fromStorage(this.storage)?g.READY:g.EMBEDDED_SIGNER_NOT_CONFIGURED}catch(e){return y("Failed to get embedded state:",e),g.UNAUTHENTICATED}}async getEthereumProvider(e){await this.ensureInitialized();const t={announceProvider:!0,...e},r=await a.fromStorage(this.storage),i=await s.fromStorage(this.storage);return this.provider?this.provider&&t.policy&&this.provider.updatePolicy(t.policy):(this.provider=new p({storage:this.storage,openfortEventEmitter:this.eventEmitter,ensureSigner:this.ensureSigner.bind(this),account:i||void 0,authentication:r||void 0,backendApiClients:this.backendApiClients,policyId:t.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this),chains:t.chains}),t.announceProvider&&f({info:{...A,...t.providerInfo},provider:this.provider})),this.provider}async ping(e){try{e>0&&await new Promise(t=>{setTimeout(t,e)});const t=await this.getIframeManager();if(!t.isLoaded())return!1;const r=await a.fromStorage(this.storage);if(r)try{return await t.getCurrentDevice(r.player),!0}catch(e){return!1}return t.isLoaded()}catch(e){return y("Ping failed:",e),!1}}getURL(){const e=r.getInstance();if(!e)throw new i("Configuration not found",n.INVALID_CONFIGURATION);return e.iframeUrl}async setMessagePoster(e){if(!e||"function"!=typeof e.postMessage)throw new i("Invalid message poster",n.INVALID_CONFIGURATION);this.messagePoster=e,this.messenger&&this.messenger.destroy(),this.iframeManager&&this.iframeManager.destroy(),this.signer=null,this.signerPromise=null,this.iframeManager=null,this.iframeManagerPromise=null,this.messenger=null}async handleLogout(){const e=await this.ensureSigner();await e.disconnect(),this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,this.signerPromise=null}async onMessage(e){if(!e||"object"!=typeof e)return void y("Invalid message received:",e);y("[HANDSHAKE DEBUG] EmbeddedWalletApi onMessage:",e);const t="penpal"===e.namespace&&"SYN"===e.type||e.penpal&&"string"==typeof e.penpal;if(t&&this.messenger&&this.messagePoster)return y("[HANDSHAKE DEBUG] Passing message directly to existing ReactNativeMessenger"),void this.messenger.handleMessage(e);const r=await this.getIframeManager();y(`[HANDSHAKE DEBUG] IframeManager obtained, isLoaded: ${r.isLoaded()}`),t&&!r.isLoaded()&&y("[HANDSHAKE DEBUG] Received penpal message before connection initialized, setting up connection..."),y("[HANDSHAKE DEBUG] Calling iframeManager.onMessage"),await r.onMessage(e),y("[HANDSHAKE DEBUG] iframeManager.onMessage completed")}isReady(){return this.iframeManager?.isLoaded()||!1}}export{M as EmbeddedWalletApi};
@@ -1 +1 @@
1
- import{AxiosError as t}from"axios";import{VERSION as s,PACKAGE as e}from"../../version.js";const r="https://64a03e4967fb4dad3ecb914918c777b6@o4504593015242752.ingest.us.sentry.io/4509292415287296";class n{static sentryInstance;static queuedCalls=[];static baseTags;static set sentry(s){const e=s.getDsn();if(!e)throw new Error("Sentry DSN is not set");if(e.projectId!==r.split("https://")[1].split("/")[1]||e.host!==r.split("@")[1].split("/")[0]||e.publicKey!==r.split("@")[0].split("https://")[1])throw new Error("Sentry DSN is not valid");s.captureAxiosError=(e,r,a,o)=>{if(r instanceof t){if(400===r.response?.status||401===r.response?.status)return;r.name=e,s.captureException(r,{...a,captureContext:{...a?.captureContext,extra:{errorResponseData:r.response?.data,errorStatus:r.response?.status,errorHeaders:r.response?.headers,errorRequest:r.request},tags:{...n.baseTags,method:e}}})}else s.captureException(r,a,o)},n.sentryInstance=s}static get sentry(){return n.proxy}static async init({sentry:t,configuration:a}){if(t)return void(n.sentry=t);const o=await import("@sentry/browser");n.sentry=new o.BrowserClient({dsn:r,integrations:[],stackParser:o.defaultStackParser,transport:o.makeFetchTransport}),n.baseTags={projectId:a?.baseConfiguration.publishableKey,sdk:e,sdkVersion:s},n.processQueuedCalls()}static proxy=new Proxy({},{get:(t,s)=>n.sentryInstance&&"function"==typeof n.sentryInstance[s]?(...t)=>n.sentryInstance[s](...t):(...t)=>{n.queuedCalls.push({fn:s,args:t})}});static processQueuedCalls(){n.sentryInstance&&(n.queuedCalls.forEach(({fn:t,args:s})=>{"function"==typeof n.sentryInstance[t]&&n.sentryInstance[t](...s)}),n.queuedCalls=[])}}const{sentry:a}=n;export{n as InternalSentry,a as sentry};
1
+ import{AxiosError as t}from"axios";import{VERSION as s,PACKAGE as e}from"../../version.js";const r="https://64a03e4967fb4dad3ecb914918c777b6@o4504593015242752.ingest.us.sentry.io/4509292415287296";class n{static sentryInstance;static queuedCalls=[];static baseTags;static set sentry(s){const e=s.getDsn();if(!e)throw new Error("Sentry DSN is not set");if(e.projectId!==r.split("https://")[1].split("/")[1]||e.host!==r.split("@")[1].split("/")[0]||e.publicKey!==r.split("@")[0].split("https://")[1])throw new Error("Sentry DSN is not valid");s.captureAxiosError=(e,r,a,o)=>{if(r instanceof t){if(400===r.response?.status||401===r.response?.status)return;r.name=e,s.captureException(r,{...a,captureContext:{...a?.captureContext,extra:{errorResponseData:r.response?.data,errorStatus:r.response?.status,errorHeaders:r.response?.headers,errorRequest:r.request},tags:{...n.baseTags,method:e}}})}else s.captureException(r,a,o)},n.sentryInstance=s}static get sentry(){return n.proxy}static async init({sentry:t,configuration:a}){if(t)return void(n.sentry=t);const o=await import("@sentry/browser");n.sentry=new o.BrowserClient({dsn:r,integrations:[],stackParser:o.defaultStackParser,transport:o.makeFetchTransport}),n.baseTags={projectId:a?.baseConfiguration.publishableKey??"",sdk:e,sdkVersion:s},n.processQueuedCalls()}static proxy=new Proxy({},{get:(t,s)=>n.sentryInstance&&"function"==typeof n.sentryInstance[s]?(...t)=>n.sentryInstance[s](...t):(...t)=>{n.queuedCalls.push({fn:s,args:t})}});static processQueuedCalls(){n.sentryInstance&&(n.queuedCalls.forEach(({fn:t,args:s})=>{"function"==typeof n.sentryInstance[t]&&n.sentryInstance[t](...s)}),n.queuedCalls=[])}}const{sentry:a}=n;export{n as InternalSentry,a as sentry};
@@ -1 +1 @@
1
- const t={1:"https://cloudflare-eth.com",10:"https://optimism-rpc.publicnode.com",56:"https://bsc.publicnode.com",97:"https://bsc-testnet.publicnode.com",137:"https://polygon-rpc.com",204:"https://opbnb-mainnet-rpc.bnbchain.org",300:"https://sepolia.era.zksync.dev",324:"https://mainnet.era.zksync.io",1946:"https://rpc.minato.soneium.org",2741:"https://api.mainnet.abs.xyz",3939:"https://test.doschain.com",4337:"https://build.onbeam.com/rpc",5611:"https://opbnb-testnet-rpc.bnbchain.org",7979:"https://main.doschain.com",8453:"https://mainnet.base.org",11124:"https://api.testnet.abs.xyz",13337:"https://build.onbeam.com/rpc/testnet",13473:"https://rpc.testnet.immutable.com",42161:"https://arb1.arbitrum.io/rpc",42170:"https://nova.arbitrum.io/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",43114:"https://api.avax.network/ext/bc/C/rpc",50104:"https://rpc.sophon.xyz",80002:"https://polygon-amoy-bor-rpc.publicnode.com",84532:"https://sepolia.base.org",421614:"https://sepolia-rollup.arbitrum.io/rpc",7225878:"https://rpc.saakuru.network",7777777:"https://rpc.zora.energy",11155111:"https://ethereum-sepolia-rpc.publicnode.com",11155420:"https://optimism-sepolia-rpc.publicnode.com",28122024:"https://rpcv2-testnet.ancient8.gg",531050104:"https://rpc.testnet.sophon.xyz",666666666:"https://rpc.degen.tips",888888888:"https://rpc.ancient8.gg",999999999:"https://sepolia.rpc.zora.energy",85011:"https://subnets.avax.network/criminalsa/testnet/rpc",84358:"https://subnets.avax.network/titan/mainnet/rpc",10143:"https://testnet-rpc.monad.xyz",510525:"https://rpc.clankermon.com",3008:"https://kl1-testnet.kiooverse.xyz/rpc",167e3:"https://rpc.taiko.xyz"};export{t as defaultChainRpcs};
1
+ const t={1:"https://cloudflare-eth.com",10:"https://optimism-rpc.publicnode.com",56:"https://bsc.publicnode.com",97:"https://bsc-testnet.publicnode.com",137:"https://polygon-rpc.com",1946:"https://rpc.minato.soneium.org",3008:"https://kl1-testnet.kiooverse.xyz/rpc",4337:"https://build.onbeam.com/rpc",5611:"https://opbnb-testnet-rpc.bnbchain.org",8453:"https://mainnet.base.org",10143:"https://testnet-rpc.monad.xyz",13337:"https://build.onbeam.com/rpc/testnet",42161:"https://arb1.arbitrum.io/rpc",42170:"https://nova.arbitrum.io/rpc",43113:"https://api.avax-test.network/ext/bc/C/rpc",43114:"https://api.avax.network/ext/bc/C/rpc",80002:"https://polygon-amoy-bor-rpc.publicnode.com",84358:"https://subnets.avax.network/titan/mainnet/rpc",84532:"https://sepolia.base.org",421614:"https://sepolia-rollup.arbitrum.io/rpc",510525:"https://rpc.clankermon.com",510530:"https://open-loot.rpc.syndicate.io",510531:"https://open-loot.rpc.testnet.syndicate.io",7225878:"https://rpc.saakuru.network",7777777:"https://rpc.zora.energy",11155111:"https://ethereum-sepolia-rpc.publicnode.com",11155420:"https://optimism-sepolia-rpc.publicnode.com",28122024:"https://rpcv2-testnet.ancient8.gg",666666666:"https://rpc.degen.tips",888888888:"https://rpc.ancient8.gg",999999999:"https://sepolia.rpc.zora.energy"};export{t as defaultChainRpcs};
@@ -1 +1 @@
1
- const o="0.10.36",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
1
+ const o="0.10.37",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
@@ -1 +1 @@
1
- import{Authentication as e}from"../core/configuration/authentication.js";import{PasskeyHandler as t}from"../core/configuration/passkey.js";import{OpenfortError as a,OpenfortErrorType as r,withOpenfortError as o}from"../core/errors/openfortError.js";import{OpenfortEvents as s,AccountTypeEnum as n}from"../types/types.js";import{SDKConfiguration as i}from"../core/config/config.js";import{Account as c}from"../core/configuration/account.js";import{StorageKeys as d}from"../storage/istorage.js";import"eventemitter3";import"./evm/JsonRpcError.js";import"@ethersproject/keccak256";import"./evm/types.js";import"./evm/provider/eip6963.js";import"../core/errors/sentry.js";import"./messaging/browserMessenger/backwardCompatibility.js";import"./types.js";import"jose";class y{iframeManager;storage;backendApiClients;passkeyHandler;eventEmitter;constructor(e,t,a,r,o){this.iframeManager=e,this.storage=t,this.backendApiClients=a,this.passkeyHandler=r,this.eventEmitter=o}async createPasskey(e){const a=await this.passkeyHandler.createPasskey({id:t.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:e});return{id:a.id,key:a.key}}async configure(t){const n=await e.fromStorage(this.storage);if(!n)throw new a("No access token found",r.NOT_LOGGED_IN_ERROR);const d=i.getInstance();if(!d)throw new a("Configuration not found",r.INVALID_CONFIGURATION);const y=await c.fromStorage(this.storage);let p;if(y){const e={account:y.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===y.recoveryMethod&&{passkey:{id:y.recoveryMethodDetails?.passkeyId,env:y.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(y.recoveryMethodDetails?.passkeyId)}}}}},a=await this.iframeManager.recover(e);p=a.account}else{const e=await this.backendApiClients.accountsApi.getAccountsV2({user:n.player,accountType:t.accountType,chainType:t.chainType},{headers:{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":n.token,"x-auth-provider":n.thirdPartyProvider,"x-token-type":n.thirdPartyTokenType}});if(0===e.data.data.length){const e=t.entropy?.passkey?await this.createPasskey(n.player):void 0,a={accountType:t.accountType,chainType:t.chainType,chainId:t.chainId,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},...t.entropy.passkey&&{passkey:e}}}},r=await this.iframeManager.create(a);p=r.account}else{const a=e.data.data,r=a.find(e=>e.chainId===t.chainId),o=r||a[0],s={account:o.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===o.recoveryMethod&&{passkey:{id:o.recoveryMethodDetails?.passkeyId,env:o.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(o.recoveryMethodDetails?.passkeyId)}}}}},n=await this.iframeManager.recover(s);if(p=n.account,!r){const e=await this.iframeManager.switchChain(t.chainId);p=e.account}}}return o(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:p},{headers:{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":n.token,"x-auth-provider":n.thirdPartyProvider,"x-token-type":n.thirdPartyTokenType}}),t=new c({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:c.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(s.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.AUTHENTICATION_ERROR})}async sign(e,t,a,r){const o=await this.iframeManager.sign(e,t,a,r);return this.eventEmitter.emit(s.ON_SIGNED_MESSAGE,{message:e,signature:o}),o}async export(){return await this.iframeManager.export()}async switchChain({chainId:e}){const t=await c.fromStorage(this.storage);if(t?.accountType===n.EOA)new c({...t,chainId:e}).save(this.storage);else{const a=await this.iframeManager.switchChain(e);new c({...t,id:a.account,chainId:e}).save(this.storage)}}async create(t){const n=await this.iframeManager.create(t),d=await e.fromStorage(this.storage);if(!d)throw new a("No access token found",r.NOT_LOGGED_IN_ERROR);const y=i.getInstance();if(!y)throw new a("Configuration not found",r.INVALID_CONFIGURATION);return o(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:n.account},{headers:{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}}),t=new c({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,implementationAddress:e.data.smartAccount?.implementationAddress,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:c.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(s.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.AUTHENTICATION_ERROR})}async recover(t){const n=await this.iframeManager.recover(t),d=await e.fromStorage(this.storage);if(!d)throw new a("No access token found",r.NOT_LOGGED_IN_ERROR);const y=i.getInstance();if(!y)throw new a("Configuration not found",r.INVALID_CONFIGURATION);return o(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:n.account},{headers:{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}}),t=new c({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:c.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(s.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.AUTHENTICATION_ERROR})}async setRecoveryMethod({recoveryMethod:e,recoveryPassword:t,encryptionSession:a,passkeyInfo:r}){await this.iframeManager.setRecoveryMethod(e,t,a,r?.passkeyKey,r?.passkeyId)}async disconnect(){await this.iframeManager.disconnect(),this.storage.remove(d.ACCOUNT)}}export{y as EmbeddedSigner};
1
+ import{Authentication as e}from"../core/configuration/authentication.js";import{PasskeyHandler as t}from"../core/configuration/passkey.js";import{OpenfortError as a,OpenfortErrorType as r,withOpenfortError as o}from"../core/errors/openfortError.js";import{OpenfortEvents as s,AccountTypeEnum as n}from"../types/types.js";import{SDKConfiguration as i}from"../core/config/config.js";import{Account as c}from"../core/configuration/account.js";import{StorageKeys as d}from"../storage/istorage.js";import"eventemitter3";import"./evm/JsonRpcError.js";import"@ethersproject/keccak256";import"./evm/types.js";import"./evm/provider/eip6963.js";import"../core/errors/sentry.js";import"./messaging/browserMessenger/backwardCompatibility.js";import"./types.js";import"jose";class y{iframeManager;storage;backendApiClients;passkeyHandler;eventEmitter;constructor(e,t,a,r,o){this.iframeManager=e,this.storage=t,this.backendApiClients=a,this.passkeyHandler=r,this.eventEmitter=o}async createPasskey(e){const a=await this.passkeyHandler.createPasskey({id:t.randomPasskeyName(),displayName:"Openfort - Embedded Wallet",seed:e});return{id:a.id,key:a.key}}async configure(t){const n=await e.fromStorage(this.storage);if(!n)throw new a("No access token found",r.NOT_LOGGED_IN_ERROR);const d=i.getInstance();if(!d)throw new a("Configuration not found",r.INVALID_CONFIGURATION);const y=await c.fromStorage(this.storage);let p;if(y){const e={account:y.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===y.recoveryMethod&&{passkey:{id:y.recoveryMethodDetails?.passkeyId,env:y.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(y.recoveryMethodDetails?.passkeyId??"")}}}}},a=await this.iframeManager.recover(e);p=a.account}else{const e=await this.backendApiClients.accountsApi.getAccountsV2({user:n.player,accountType:t.accountType,chainType:t.chainType},{headers:{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":n.token,"x-auth-provider":n.thirdPartyProvider,"x-token-type":n.thirdPartyTokenType}});if(0===e.data.data.length){const e=t.entropy?.passkey?await this.createPasskey(n.player):void 0,a={accountType:t.accountType,chainType:t.chainType,chainId:t.chainId,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},...t.entropy.passkey&&{passkey:e}}}},r=await this.iframeManager.create(a);p=r.account}else{const a=e.data.data,r=a.find(e=>e.chainId===t.chainId),o=r||a[0],s={account:o.id,...t.entropy&&{entropy:{...t.entropy.recoveryPassword&&{recoveryPassword:t.entropy.recoveryPassword},...t.entropy.encryptionSession&&{encryptionSession:t.entropy.encryptionSession},..."passkey"===o.recoveryMethod&&{passkey:{id:o.recoveryMethodDetails?.passkeyId,env:o.recoveryMethodDetails?.passkeyEnv,key:await t.getPasskeyKeyFn(o.recoveryMethodDetails?.passkeyId??"")}}}}},n=await this.iframeManager.recover(s);if(p=n.account,!r){const e=await this.iframeManager.switchChain(t.chainId);p=e.account}}}return o(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:p},{headers:{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":n.token,"x-auth-provider":n.thirdPartyProvider,"x-token-type":n.thirdPartyTokenType}}),t=new c({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:c.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(s.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.AUTHENTICATION_ERROR})}async sign(e,t,a,r){const o=await this.iframeManager.sign(e,t,a,r);return this.eventEmitter.emit(s.ON_SIGNED_MESSAGE,{message:e,signature:o}),o}async export(){return await this.iframeManager.export()}async switchChain({chainId:e}){const t=await c.fromStorage(this.storage);if(t?.accountType===n.EOA)new c({...t,chainId:e}).save(this.storage);else{const a=await this.iframeManager.switchChain(e);new c({...t,id:a.account,chainId:e}).save(this.storage)}}async create(t){const n=await this.iframeManager.create(t),d=await e.fromStorage(this.storage);if(!d)throw new a("No access token found",r.NOT_LOGGED_IN_ERROR);const y=i.getInstance();if(!y)throw new a("Configuration not found",r.INVALID_CONFIGURATION);return o(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:n.account},{headers:{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}}),t=new c({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,implementationAddress:e.data.smartAccount?.implementationAddress,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:c.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(s.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.AUTHENTICATION_ERROR})}async recover(t){const n=await this.iframeManager.recover(t),d=await e.fromStorage(this.storage);if(!d)throw new a("No access token found",r.NOT_LOGGED_IN_ERROR);const y=i.getInstance();if(!y)throw new a("Configuration not found",r.INVALID_CONFIGURATION);return o(async()=>{const e=await this.backendApiClients.accountsApi.getAccountV2({id:n.account},{headers:{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}}),t=new c({user:e.data.user,chainType:e.data.chainType,id:e.data.id,address:e.data.address,ownerAddress:e.data.ownerAddress,accountType:e.data.accountType,createdAt:e.data.createdAt,implementationAddress:e.data.smartAccount?.implementationAddress,implementationType:e.data.smartAccount?.implementationType,chainId:e.data.chainId,salt:e.data.smartAccount?.salt,factoryAddress:e.data.smartAccount?.factoryAddress,recoveryMethod:c.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(s.ON_SWITCH_ACCOUNT,e.data.address),t},{default:r.AUTHENTICATION_ERROR})}async setRecoveryMethod({recoveryMethod:e,recoveryPassword:t,encryptionSession:a,passkeyInfo:r}){await this.iframeManager.setRecoveryMethod(e,t,a,r?.passkeyKey,r?.passkeyId)}async disconnect(){await this.iframeManager.disconnect(),this.storage.remove(d.ACCOUNT)}}export{y as EmbeddedSigner};
@@ -1 +1 @@
1
- import{withOpenfortError as e,OpenfortErrorType as t}from"../../core/errors/openfortError.js";import{JsonRpcError as r,RpcErrorCode as a}from"./JsonRpcError.js";const s=async({params:s,account:o,authentication:n,backendClient:c})=>{const i=await(async(r,a,s,o)=>{const n=o?.chainFilter?.map(e=>Number.parseInt(e,16));return e(async()=>(await r.rpcApi.handleRpcRequest({jsonRpcRequest:{method:"wallet_getAssets",params:{account:a.address,chainFilter:n,assetFilter:o?.assetFilter,assetTypeFilter:o?.assetTypeFilter},id:1,jsonrpc:"2.0"}},{headers:{authorization:`Bearer ${r.config.backend.accessToken}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}})).data,{default:t.AUTHENTICATION_ERROR})})(c,o,n,s).catch(e=>{throw new r(a.INTERNAL_ERROR,e.message)});return i.result};export{s as getAssets};
1
+ import{withOpenfortError as e,OpenfortErrorType as t}from"../../core/errors/openfortError.js";import{JsonRpcError as r,RpcErrorCode as a}from"./JsonRpcError.js";const s=async({params:s,account:o,authentication:n,backendClient:c})=>{const i=await(async(r,a,s,o)=>e(async()=>(await r.rpcApi.handleRpcRequest({jsonRpcRequest:{method:"wallet_getAssets",params:{account:a.address,chainFilter:o?.chainFilter,assetFilter:o?.assetFilter,assetTypeFilter:o?.assetTypeFilter},id:1,jsonrpc:"2.0"}},{headers:{authorization:`Bearer ${r.config.backend.accessToken}`,"x-player-token":s.token,"x-auth-provider":s.thirdPartyProvider,"x-token-type":s.thirdPartyTokenType}})).data,{default:t.AUTHENTICATION_ERROR}))(c,o,n,s).catch(e=>{throw new r(a.INTERNAL_ERROR,e.message)});return i.result};export{s as getAssets};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openfort/openfort-js",
3
- "version": "0.10.36",
3
+ "version": "0.10.37",
4
4
  "author": "Openfort (https://www.openfort.io)",
5
5
  "bugs": "https://github.com/openfort-xyz/openfort-js/issues",
6
6
  "repository": "openfort-xyz/openfort-js.git",