@openfort/openfort-js 1.3.3 → 1.3.4

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 e=require("../../../packages/internal/openapi-clients/dist/index.cjs"),r=require("../core/errors/openfortError.cjs"),t=require("../core/passkey/handler.cjs"),s=require("../core/config/config.cjs"),n=require("../core/configuration/account.cjs"),a=require("../core/configuration/authentication.cjs"),i=require("../core/errors/authErrorCodes.cjs"),o=require("../core/errors/withApiError.cjs"),d=require("../storage/istorage.cjs"),c=require("../types/types.cjs"),g=require("../utils/debug.cjs"),h=require("../utils/observe.cjs"),u=require("../wallets/embedded.cjs"),y=require("../wallets/evm/evmProvider.cjs");require("../wallets/evm/types.cjs");var l=require("../wallets/evm/provider/eip6963.cjs"),m=require("../wallets/evm/walletHelpers.cjs"),f=require("../wallets/iframeManager.cjs"),p=require("../wallets/messaging/ReactNativeMessenger.cjs");require("../wallets/messaging/browserMessenger/backwardCompatibility.cjs");var E=require("../wallets/messaging/browserMessenger/messengers/WindowMessenger.cjs");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,s,n){this.storage=e,this.validateAndRefreshToken=r,this.ensureInitialized=t,this.eventEmitter=s,this.passkeyHandler=n,this.eventEmitter.on(c.OpenfortEvents.ON_LOGOUT,()=>{g.debugLog("Handling logout event in EmbeddedWalletApi"),this.handleLogout()})}get backendApiClients(){const t=s.SDKConfiguration.getInstance();if(!t)throw new r.ConfigurationError("Configuration not found");return new e.BackendApiClients({basePath:t.backendUrl,accessToken:t.baseConfiguration.publishableKey,nativeAppIdentifier:t.nativeAppIdentifier})}async getIframeManager(){if(g.debugLog("[HANDSHAKE DEBUG] getIframeManager called"),this.iframeManager?.hasFailed&&(g.debugLog("[HANDSHAKE DEBUG] Existing iframeManager has failed, clearing for recreation"),this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null),this.iframeManager)return g.debugLog("[HANDSHAKE DEBUG] Returning existing iframeManager instance"),this.iframeManager;if(this.iframeManagerPromise)return g.debugLog("[HANDSHAKE DEBUG] Returning existing iframeManagerPromise"),this.iframeManagerPromise;g.debugLog("[HANDSHAKE DEBUG] Creating new iframeManager"),this.iframeManagerPromise=this.createIframeManager();try{return g.debugLog("[HANDSHAKE DEBUG] Awaiting iframeManager creation"),this.iframeManager=await this.iframeManagerPromise,g.debugLog("[HANDSHAKE DEBUG] IframeManager created successfully"),this.iframeManagerPromise=null,this.iframeManager}catch(e){throw g.debugLog("[HANDSHAKE DEBUG] Error creating iframeManager:",e),this.iframeManagerPromise=null,this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null,e}}async createIframeManager(){g.debugLog("[HANDSHAKE DEBUG] createIframeManager starting");const e=s.SDKConfiguration.getInstance();if(!e)throw g.debugLog("[HANDSHAKE DEBUG] Configuration not found"),new r.ConfigurationError("Configuration not found");let t;if(g.debugLog("[HANDSHAKE DEBUG] Configuration found"),this.messagePoster)g.debugLog("[HANDSHAKE DEBUG] Creating ReactNativeMessenger with messagePoster"),this.messenger&&(g.debugLog("[HANDSHAKE DEBUG] Destroying old messenger before creating new one"),this.messenger.destroy()),this.messenger=new p.ReactNativeMessenger(this.messagePoster),g.debugLog("[HANDSHAKE DEBUG] Created new ReactNativeMessenger instance"),t=this.messenger;else{g.debugLog("[HANDSHAKE DEBUG] Creating WindowMessenger for browser mode");const r=this.createIframe(e.iframeUrl),s=new URL(e.iframeUrl).origin;t=new E({remoteWindow:r.contentWindow,allowedOrigins:[s]}),g.debugLog("[HANDSHAKE DEBUG] Created WindowMessenger")}return g.debugLog("[HANDSHAKE DEBUG] Creating IframeManager instance"),new f.IframeManager(e,this.storage,t)}async ensureSigner(){if(this.iframeManager?.hasFailed&&(g.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();await e.initialize();return new u.EmbeddedSigner(e,this.storage,this.backendApiClients,this.passkeyHandler,this.eventEmitter)}createIframe(e){if("undefined"==typeof document)throw new r.ConfigurationError("Document is not available. Please provide a message poster for non-browser environments.");const t=document.getElementById("openfort-iframe");t&&t.remove();const s=document.createElement("iframe");return s.style.display="none",s.id="openfort-iframe",s.src=e,document.body.appendChild(s),s}async getPasskeyKey(e){const t=await a.Authentication.fromStorage(this.storage);if(!t?.userId)throw new r.AuthenticationError("auth","User is required for passkey key derivation. Logout and login again.",401);return this.passkeyHandler.deriveAndExportKey({id:e,seed:t.userId})}async getEntropy(e){switch(e.recoveryMethod){case c.RecoveryMethod.PASSWORD:return{recoveryPassword:e.password};case c.RecoveryMethod.AUTOMATIC:return{encryptionSession:e.encryptionSession};case c.RecoveryMethod.PASSKEY:return{passkey:e.passkeyInfo?{id:e.passkeyInfo.passkeyId,key:e.passkeyInfo.passkeyKey||await this.getPasskeyKey(e.passkeyInfo.passkeyId)}:{}};default:throw new r.ConfigurationError("Invalid recovery method")}}async configure(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:c.RecoveryMethod.AUTOMATIC},[t,s]=await Promise.all([this.ensureSigner(),this.getEntropy(r)]),a={chainId:e.chainId,entropy:s,accountType:e.accountType??c.AccountTypeEnum.SMART_ACCOUNT,chainType:e.chainType??c.ChainTypeEnum.EVM,getPasskeyKeyFn:async e=>this.getPasskeyKey(e)},i=await t.configure(a);return{id:i.id,chainId:i.chainId,address:i.address,ownerAddress:i.ownerAddress,chainType:i.chainType,accountType:i.accountType,implementationType:i.implementationType,factoryAddress:i.factoryAddress,salt:i.salt,createdAt:i.createdAt,implementationAddress:i.implementationAddress,recoveryMethod:n.Account.parseRecoveryMethod(i.recoveryMethod),recoveryMethodDetails:i.recoveryMethodDetails}}async create(e){await this.validateAndRefreshToken();const s=e.recoveryParams??{recoveryMethod:c.RecoveryMethod.AUTOMATIC},o=await a.Authentication.fromStorage(this.storage);if(!o)throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"missing authentication");if(s.recoveryMethod===c.RecoveryMethod.PASSKEY){if(!o.userId)throw new r.ConfigurationError("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:t.PasskeyHandler.randomPasskeyName(),seed:o.userId});if(!e.key)throw new r.ConfigurationError("Passkey creation failed: no key material returned");s.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[d,g]=await Promise.all([this.ensureSigner(),this.getEntropy(s)]),h=await d.create({accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:g}),u={id:h.id,chainId:h.chainId,address:h.address,ownerAddress:h.ownerAddress,chainType:h.chainType,accountType:h.accountType,implementationType:h.implementationType,factoryAddress:h.factoryAddress,salt:h.salt,createdAt:h.createdAt,implementationAddress:h.implementationAddress,recoveryMethod:n.Account.parseRecoveryMethod(h.recoveryMethod),recoveryMethodDetails:h.recoveryMethodDetails};return this.eventEmitter.emit(c.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,u),u}async recover(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:c.RecoveryMethod.AUTOMATIC};if(t.recoveryMethod===c.RecoveryMethod.PASSKEY){if(!t.passkeyInfo?.passkeyId)throw new r.ConfigurationError("Passkey ID must be provided for passkey recovery");t.passkeyInfo={passkeyId:t.passkeyInfo.passkeyId}}const[s,a]=await Promise.all([this.ensureSigner(),this.getEntropy(t)]),i=await s.recover({account:e.account,entropy:a}),o={id:i.id,chainId:i.chainId,implementationAddress:i.implementationAddress,factoryAddress:i.factoryAddress,salt:i.salt,address:i.address,ownerAddress:i.ownerAddress,chainType:i.chainType,accountType:i.accountType,implementationType:i.implementationType,createdAt:i.createdAt,recoveryMethod:n.Account.parseRecoveryMethod(i.recoveryMethod),recoveryMethodDetails:i.recoveryMethodDetails};return this.eventEmitter.emit(c.OpenfortEvents.ON_EMBEDDED_WALLET_RECOVERED,o),o}async signMessage(e,r){await this.validateAndRefreshToken();const t=await this.ensureSigner(),{hashMessage:s=!0,arrayifyMessage:a=!1}=r||{},i=await n.Account.fromStorage(this.storage);return await t.sign(e,a,s,i?.chainType)}async signTypedData(e,t,s){await this.validateAndRefreshToken();const a=await this.ensureSigner(),o=await n.Account.fromStorage(this.storage);if(!o)throw new r.SignerError(i.OPENFORT_AUTH_ERROR_CODES.MISSING_SIGNER,"No account found");const d={...t};delete d.EIP712Domain;const{_TypedDataEncoder:c}=await import("@ethersproject/hash"),g=c.hash(e,d,s);return await m.signMessage({hash:g,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,s){await this.validateAndRefreshToken();const o=await this.ensureSigner(),d=await a.Authentication.fromStorage(this.storage);if(!d)throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"missing authentication");let g,h,u,y;if(e.recoveryMethod===c.RecoveryMethod.PASSKEY){const e=await n.Account.fromStorage(this.storage);if(!e)throw new r.ConfigurationError("missing account");const t=e?.recoveryMethodDetails?.passkeyId;if(!t)throw new r.ConfigurationError("missing passkey id for account");if(!d.userId)throw new r.ConfigurationError("User ID is required for passkey key derivation");u={passkeyId:t,passkeyKey:await this.passkeyHandler.deriveAndExportKey({id:t,seed:d.userId})}}else if(s.recoveryMethod===c.RecoveryMethod.PASSKEY){if(!d.userId)throw new r.ConfigurationError("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:t.PasskeyHandler.randomPasskeyName(),seed:d.userId});if(!e.key)throw new r.ConfigurationError("Passkey creation failed: no key material returned");u={passkeyId:e.id,passkeyKey:e.key},y={passkeyId:e.id}}if(e.recoveryMethod===c.RecoveryMethod.PASSWORD?g=e.password:s.recoveryMethod===c.RecoveryMethod.PASSWORD&&(g=s.password),e.recoveryMethod===c.RecoveryMethod.AUTOMATIC?h=e.encryptionSession:s.recoveryMethod===c.RecoveryMethod.AUTOMATIC&&(h=s.encryptionSession),!g&&!h)throw new r.ConfigurationError("Password or encryption session is not provided");await o.setRecoveryMethod({recoveryMethod:s.recoveryMethod,recoveryPassword:g,encryptionSession:h,passkeyInfo:u});const l=await n.Account.fromStorage(this.storage);l&&new n.Account({...l,recoveryMethod:s.recoveryMethod,recoveryMethodDetails:y}).save(this.storage)}async get(){await this.validateAndRefreshToken();const e=await n.Account.fromStorage(this.storage);if(!e)throw new r.SignerError(i.OPENFORT_AUTH_ERROR_CODES.MISSING_SIGNER,"No signer configured");if(!await a.Authentication.fromStorage(this.storage))throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");return{id:e.id,chainId:e.chainId,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:n.Account.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails}}async list(e){await this.validateAndRefreshToken();const t={...e},d=s.SDKConfiguration.getInstance();if(!d)throw new r.ConfigurationError("Configuration not found");const c=await a.Authentication.fromStorage(this.storage);if(!c)throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");return await this.validateAndRefreshToken(),o.withApiError(async()=>(await this.backendApiClients.accountsV2Api.getAccountsV2(t,{headers:c.thirdPartyProvider?{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":c.token,"x-auth-provider":c.thirdPartyProvider,"x-token-type":c.thirdPartyTokenType}:{authorization:`Bearer ${c.token}`,"x-project-key":d.baseConfiguration.publishableKey}})).data.data.map(e=>({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:n.Account.parseRecoveryMethod(e.recoveryMethod),recoveryMethodDetails:e.recoveryMethodDetails})),{context:"list"})}async getEmbeddedState(){try{if(!await a.Authentication.fromStorage(this.storage))return c.EmbeddedState.UNAUTHENTICATED;return await n.Account.fromStorage(this.storage)?c.EmbeddedState.READY:c.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED}catch(e){return g.debugLog("Failed to get embedded state:",e),c.EmbeddedState.UNAUTHENTICATED}}watchEmbeddedState(e){return h.observe("watchEmbeddedState",{onChange:e.onChange,onError:e.onError},r=>{let t;const s=async()=>{try{const e=await this.getEmbeddedState();t!==e&&(r.onChange?.(e,t),t=e)}catch(e){r.onError?.(e instanceof Error?e:new Error(String(e)))}};s();const n=()=>s(),a=()=>s(),i=()=>s(),o=()=>s();this.eventEmitter.on(c.OpenfortEvents.ON_AUTH_SUCCESS,n),this.eventEmitter.on(c.OpenfortEvents.ON_LOGOUT,a),this.eventEmitter.on(c.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,i),this.eventEmitter.on(c.OpenfortEvents.ON_EMBEDDED_WALLET_RECOVERED,o);const d=setInterval(s,e.pollingInterval??2e3);return()=>{clearInterval(d),this.eventEmitter.off(c.OpenfortEvents.ON_AUTH_SUCCESS,n),this.eventEmitter.off(c.OpenfortEvents.ON_LOGOUT,a),this.eventEmitter.off(c.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,i),this.eventEmitter.off(c.OpenfortEvents.ON_EMBEDDED_WALLET_RECOVERED,o)}})}async getEthereumProvider(e){await this.ensureInitialized();const r={announceProvider:!0,...e},t=await a.Authentication.fromStorage(this.storage),s=await n.Account.fromStorage(this.storage);return this.provider?this.provider&&r.feeSponsorship&&this.provider.updateFeeSponsorship(r.feeSponsorship):(this.provider=new y.EvmProvider({storage:this.storage,openfortEventEmitter:this.eventEmitter,ensureSigner:this.ensureSigner.bind(this),account:s||void 0,authentication:t||void 0,backendApiClients:this.backendApiClients,feeSponsorshipId:r.feeSponsorship,validateAndRefreshSession:this.validateAndRefreshToken.bind(this),chains:r.chains}),r.announceProvider&&l.announceProvider({info:{...l.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 a.Authentication.fromStorage(this.storage);if(t)try{return await r.getCurrentDevice(t.userId),!0}catch(e){return!1}return r.isLoaded()}catch(e){return g.debugLog("Ping failed:",e),!1}}getURL(){const e=s.SDKConfiguration.getInstance();if(!e)throw new r.ConfigurationError("Configuration not found");return e.iframeUrl}async setMessagePoster(e){if(!e||"function"!=typeof e.postMessage)throw new r.ConfigurationError("Invalid message poster");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(){if(this.storage.remove(d.StorageKeys.ACCOUNT),"undefined"==typeof document&&!this.messagePoster)return g.debugLog("Skipping signer disconnect: no messagePoster available in non-browser environment"),this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,void(this.signerPromise=null);try{const e=await this.ensureSigner();await e.disconnect()}catch{}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 g.debugLog("Invalid message received:",e);g.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 g.debugLog("[HANDSHAKE DEBUG] Passing message directly to existing ReactNativeMessenger"),void this.messenger.handleMessage(e);const t=await this.getIframeManager();g.debugLog(`[HANDSHAKE DEBUG] IframeManager obtained, isLoaded: ${t.isLoaded()}`),r&&!t.isLoaded()&&g.debugLog("[HANDSHAKE DEBUG] Received penpal message before connection initialized, setting up connection..."),g.debugLog("[HANDSHAKE DEBUG] Calling iframeManager.onMessage"),await t.onMessage(e),g.debugLog("[HANDSHAKE DEBUG] iframeManager.onMessage completed")}isReady(){return this.iframeManager?.isLoaded()||!1}};
1
+ "use strict";var e=require("../../../packages/internal/openapi-clients/dist/index.cjs"),r=require("../core/errors/openfortError.cjs"),t=require("../core/passkey/handler.cjs"),s=require("../core/config/config.cjs"),a=require("../core/configuration/account.cjs"),n=require("../core/configuration/authentication.cjs"),i=require("../core/errors/authErrorCodes.cjs"),o=require("../core/errors/withApiError.cjs"),d=require("../storage/istorage.cjs"),c=require("../types/types.cjs"),h=require("../utils/debug.cjs"),g=require("../utils/observe.cjs"),y=require("../wallets/embedded.cjs"),u=require("../wallets/evm/evmProvider.cjs");require("../wallets/evm/types.cjs");var m=require("../wallets/evm/provider/eip6963.cjs"),l=require("../wallets/evm/walletHelpers.cjs"),f=require("../wallets/iframeManager.cjs"),p=require("../wallets/messaging/ReactNativeMessenger.cjs");require("../wallets/messaging/browserMessenger/backwardCompatibility.cjs");var E=require("../wallets/messaging/browserMessenger/messengers/WindowMessenger.cjs");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,s,a){this.storage=e,this.validateAndRefreshToken=r,this.ensureInitialized=t,this.eventEmitter=s,this.passkeyHandler=a,this.eventEmitter.on(c.OpenfortEvents.ON_LOGOUT,()=>{h.debugLog("Handling logout event in EmbeddedWalletApi"),this.handleLogout()})}get backendApiClients(){const t=s.SDKConfiguration.getInstance();if(!t)throw new r.ConfigurationError("Configuration not found");return new e.BackendApiClients({basePath:t.backendUrl,accessToken:t.baseConfiguration.publishableKey,nativeAppIdentifier:t.nativeAppIdentifier})}async getIframeManager(){if(h.debugLog("[HANDSHAKE DEBUG] getIframeManager called"),this.iframeManager?.hasFailed&&(h.debugLog("[HANDSHAKE DEBUG] Existing iframeManager has failed, clearing for recreation"),this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null),this.iframeManager)return h.debugLog("[HANDSHAKE DEBUG] Returning existing iframeManager instance"),this.iframeManager;if(this.iframeManagerPromise)return h.debugLog("[HANDSHAKE DEBUG] Returning existing iframeManagerPromise"),this.iframeManagerPromise;h.debugLog("[HANDSHAKE DEBUG] Creating new iframeManager"),this.iframeManagerPromise=this.createIframeManager();try{return h.debugLog("[HANDSHAKE DEBUG] Awaiting iframeManager creation"),this.iframeManager=await this.iframeManagerPromise,h.debugLog("[HANDSHAKE DEBUG] IframeManager created successfully"),this.iframeManagerPromise=null,this.iframeManager}catch(e){throw h.debugLog("[HANDSHAKE DEBUG] Error creating iframeManager:",e),this.iframeManagerPromise=null,this.messenger&&(this.messenger.destroy(),this.messenger=null),this.iframeManager=null,e}}async createIframeManager(){h.debugLog("[HANDSHAKE DEBUG] createIframeManager starting");const e=s.SDKConfiguration.getInstance();if(!e)throw h.debugLog("[HANDSHAKE DEBUG] Configuration not found"),new r.ConfigurationError("Configuration not found");let t;if(h.debugLog("[HANDSHAKE DEBUG] Configuration found"),this.messagePoster)h.debugLog("[HANDSHAKE DEBUG] Creating ReactNativeMessenger with messagePoster"),this.messenger&&(h.debugLog("[HANDSHAKE DEBUG] Destroying old messenger before creating new one"),this.messenger.destroy()),this.messenger=new p.ReactNativeMessenger(this.messagePoster),h.debugLog("[HANDSHAKE DEBUG] Created new ReactNativeMessenger instance"),t=this.messenger;else{h.debugLog("[HANDSHAKE DEBUG] Creating WindowMessenger for browser mode");const r=this.createIframe(e.iframeUrl),s=new URL(e.iframeUrl).origin;t=new E({remoteWindow:r.contentWindow,allowedOrigins:[s]}),h.debugLog("[HANDSHAKE DEBUG] Created WindowMessenger")}return h.debugLog("[HANDSHAKE DEBUG] Creating IframeManager instance"),new f.IframeManager(e,this.storage,t)}async ensureSigner(){if(this.iframeManager?.hasFailed&&(h.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();await e.initialize();return new y.EmbeddedSigner(e,this.storage,this.backendApiClients,this.passkeyHandler,this.eventEmitter)}createIframe(e){if("undefined"==typeof document)throw new r.ConfigurationError("Document is not available. Please provide a message poster for non-browser environments.");const t=document.getElementById("openfort-iframe");t&&t.remove();const s=document.createElement("iframe");return s.style.display="none",s.id="openfort-iframe",s.src=e,document.body.appendChild(s),s}async getPasskeyKey(e){const t=await n.Authentication.fromStorage(this.storage);if(!t?.userId)throw new r.AuthenticationError("auth","User is required for passkey key derivation. Logout and login again.",401);return this.passkeyHandler.deriveAndExportKey({id:e,seed:t.userId})}async getEntropy(e){switch(e.recoveryMethod){case c.RecoveryMethod.PASSWORD:return{recoveryPassword:e.password};case c.RecoveryMethod.AUTOMATIC:return{encryptionSession:e.encryptionSession};case c.RecoveryMethod.PASSKEY:return{passkey:e.passkeyInfo?{id:e.passkeyInfo.passkeyId,key:e.passkeyInfo.passkeyKey||await this.getPasskeyKey(e.passkeyInfo.passkeyId)}:{}};default:throw new r.ConfigurationError("Invalid recovery method")}}async configure(e){await this.validateAndRefreshToken();const r=e.recoveryParams??{recoveryMethod:c.RecoveryMethod.AUTOMATIC},[t,s]=await Promise.all([this.ensureSigner(),this.getEntropy(r)]),n={chainId:e.chainId,entropy:s,accountType:e.accountType??c.AccountTypeEnum.SMART_ACCOUNT,chainType:e.chainType??c.ChainTypeEnum.EVM,getPasskeyKeyFn:async e=>this.getPasskeyKey(e)},i=await t.configure(n);return{id:i.id,chainId:i.chainId,address:i.address,ownerAddress:i.ownerAddress,chainType:i.chainType,accountType:i.accountType,implementationType:i.implementationType,factoryAddress:i.factoryAddress,salt:i.salt,createdAt:i.createdAt,implementationAddress:i.implementationAddress,recoveryMethod:a.Account.parseRecoveryMethod(i.recoveryMethod),recoveryMethodDetails:i.recoveryMethodDetails}}async create(e){await this.validateAndRefreshToken();const s=e.recoveryParams??{recoveryMethod:c.RecoveryMethod.AUTOMATIC},o=await n.Authentication.fromStorage(this.storage);if(!o)throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"missing authentication");if(s.recoveryMethod===c.RecoveryMethod.PASSKEY){if(!o.userId)throw new r.ConfigurationError("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:t.PasskeyHandler.randomPasskeyName(),seed:o.userId});if(!e.key)throw new r.ConfigurationError("Passkey creation failed: no key material returned");s.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[d,h]=await Promise.all([this.ensureSigner(),this.getEntropy(s)]),g=await d.create({accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:h}),y={id:g.id,chainId:g.chainId,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(c.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,y),y}async import(e){await this.validateAndRefreshToken();const s=e.recoveryParams??{recoveryMethod:c.RecoveryMethod.AUTOMATIC},o=await n.Authentication.fromStorage(this.storage);if(!o)throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"missing authentication");if(s.recoveryMethod===c.RecoveryMethod.PASSKEY){if(!o.userId)throw new r.ConfigurationError("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:t.PasskeyHandler.randomPasskeyName(),seed:o.userId});if(!e.key)throw new r.ConfigurationError("Passkey creation failed: no key material returned");s.passkeyInfo={passkeyId:e.id,passkeyKey:e.key}}const[d,h]=await Promise.all([this.ensureSigner(),this.getEntropy(s)]),g=await d.import({privateKey:e.privateKey,accountType:e.accountType,chainType:e.chainType,chainId:e.chainId,entropy:h}),y={id:g.id,chainId:g.chainId,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(c.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,y),y}async recover(e){await this.validateAndRefreshToken();const t=e.recoveryParams??{recoveryMethod:c.RecoveryMethod.AUTOMATIC};if(t.recoveryMethod===c.RecoveryMethod.PASSKEY){if(!t.passkeyInfo?.passkeyId)throw new r.ConfigurationError("Passkey ID must be provided for passkey recovery");t.passkeyInfo={passkeyId:t.passkeyInfo.passkeyId}}const[s,n]=await Promise.all([this.ensureSigner(),this.getEntropy(t)]),i=await s.recover({account:e.account,entropy:n}),o={id:i.id,chainId:i.chainId,implementationAddress:i.implementationAddress,factoryAddress:i.factoryAddress,salt:i.salt,address:i.address,ownerAddress:i.ownerAddress,chainType:i.chainType,accountType:i.accountType,implementationType:i.implementationType,createdAt:i.createdAt,recoveryMethod:a.Account.parseRecoveryMethod(i.recoveryMethod),recoveryMethodDetails:i.recoveryMethodDetails};return this.eventEmitter.emit(c.OpenfortEvents.ON_EMBEDDED_WALLET_RECOVERED,o),o}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,t,s){await this.validateAndRefreshToken();const n=await this.ensureSigner(),o=await a.Account.fromStorage(this.storage);if(!o)throw new r.SignerError(i.OPENFORT_AUTH_ERROR_CODES.MISSING_SIGNER,"No account found");const d={...t};delete d.EIP712Domain;const{_TypedDataEncoder:c}=await import("@ethersproject/hash"),h=c.hash(e,d,s);return await l.signMessage({hash:h,implementationType:o.implementationType||o.type,chainId:Number(o.chainId),signer:n,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,s){await this.validateAndRefreshToken();const o=await this.ensureSigner(),d=await n.Authentication.fromStorage(this.storage);if(!d)throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"missing authentication");let h,g,y,u;if(e.recoveryMethod===c.RecoveryMethod.PASSKEY){const e=await a.Account.fromStorage(this.storage);if(!e)throw new r.ConfigurationError("missing account");const t=e?.recoveryMethodDetails?.passkeyId;if(!t)throw new r.ConfigurationError("missing passkey id for account");if(!d.userId)throw new r.ConfigurationError("User ID is required for passkey key derivation");y={passkeyId:t,passkeyKey:await this.passkeyHandler.deriveAndExportKey({id:t,seed:d.userId})}}else if(s.recoveryMethod===c.RecoveryMethod.PASSKEY){if(!d.userId)throw new r.ConfigurationError("User ID is required for passkey creation");const e=await this.passkeyHandler.createPasskey({id:t.PasskeyHandler.randomPasskeyName(),seed:d.userId});if(!e.key)throw new r.ConfigurationError("Passkey creation failed: no key material returned");y={passkeyId:e.id,passkeyKey:e.key},u={passkeyId:e.id}}if(e.recoveryMethod===c.RecoveryMethod.PASSWORD?h=e.password:s.recoveryMethod===c.RecoveryMethod.PASSWORD&&(h=s.password),e.recoveryMethod===c.RecoveryMethod.AUTOMATIC?g=e.encryptionSession:s.recoveryMethod===c.RecoveryMethod.AUTOMATIC&&(g=s.encryptionSession),!h&&!g)throw new r.ConfigurationError("Password or encryption session is not provided");await o.setRecoveryMethod({recoveryMethod:s.recoveryMethod,recoveryPassword:h,encryptionSession:g,passkeyInfo:y});const m=await a.Account.fromStorage(this.storage);m&&new a.Account({...m,recoveryMethod:s.recoveryMethod,recoveryMethodDetails:u}).save(this.storage)}async get(){await this.validateAndRefreshToken();const e=await a.Account.fromStorage(this.storage);if(!e)throw new r.SignerError(i.OPENFORT_AUTH_ERROR_CODES.MISSING_SIGNER,"No signer configured");if(!await n.Authentication.fromStorage(this.storage))throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");return{id:e.id,chainId:e.chainId,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){await this.validateAndRefreshToken();const t={...e},d=s.SDKConfiguration.getInstance();if(!d)throw new r.ConfigurationError("Configuration not found");const c=await n.Authentication.fromStorage(this.storage);if(!c)throw new r.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");return await this.validateAndRefreshToken(),o.withApiError(async()=>(await this.backendApiClients.accountsV2Api.getAccountsV2(t,{headers:c.thirdPartyProvider?{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":c.token,"x-auth-provider":c.thirdPartyProvider,"x-token-type":c.thirdPartyTokenType}:{authorization:`Bearer ${c.token}`,"x-project-key":d.baseConfiguration.publishableKey}})).data.data.map(e=>({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})),{context:"list"})}async getEmbeddedState(){try{if(!await n.Authentication.fromStorage(this.storage))return c.EmbeddedState.UNAUTHENTICATED;return await a.Account.fromStorage(this.storage)?c.EmbeddedState.READY:c.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED}catch(e){return h.debugLog("Failed to get embedded state:",e),c.EmbeddedState.UNAUTHENTICATED}}watchEmbeddedState(e){return g.observe("watchEmbeddedState",{onChange:e.onChange,onError:e.onError},r=>{let t;const s=async()=>{try{const e=await this.getEmbeddedState();t!==e&&(r.onChange?.(e,t),t=e)}catch(e){r.onError?.(e instanceof Error?e:new Error(String(e)))}};s();const a=()=>s(),n=()=>s(),i=()=>s(),o=()=>s();this.eventEmitter.on(c.OpenfortEvents.ON_AUTH_SUCCESS,a),this.eventEmitter.on(c.OpenfortEvents.ON_LOGOUT,n),this.eventEmitter.on(c.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,i),this.eventEmitter.on(c.OpenfortEvents.ON_EMBEDDED_WALLET_RECOVERED,o);const d=setInterval(s,e.pollingInterval??2e3);return()=>{clearInterval(d),this.eventEmitter.off(c.OpenfortEvents.ON_AUTH_SUCCESS,a),this.eventEmitter.off(c.OpenfortEvents.ON_LOGOUT,n),this.eventEmitter.off(c.OpenfortEvents.ON_EMBEDDED_WALLET_CREATED,i),this.eventEmitter.off(c.OpenfortEvents.ON_EMBEDDED_WALLET_RECOVERED,o)}})}async getEthereumProvider(e){await this.ensureInitialized();const r={announceProvider:!0,...e},t=await n.Authentication.fromStorage(this.storage),s=await a.Account.fromStorage(this.storage);return this.provider?this.provider&&r.feeSponsorship&&this.provider.updateFeeSponsorship(r.feeSponsorship):(this.provider=new u.EvmProvider({storage:this.storage,openfortEventEmitter:this.eventEmitter,ensureSigner:this.ensureSigner.bind(this),account:s||void 0,authentication:t||void 0,backendApiClients:this.backendApiClients,feeSponsorshipId:r.feeSponsorship,validateAndRefreshSession:this.validateAndRefreshToken.bind(this),chains:r.chains}),r.announceProvider&&m.announceProvider({info:{...m.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 n.Authentication.fromStorage(this.storage);if(t)try{return await r.getCurrentDevice(t.userId),!0}catch(e){return!1}return r.isLoaded()}catch(e){return h.debugLog("Ping failed:",e),!1}}getURL(){const e=s.SDKConfiguration.getInstance();if(!e)throw new r.ConfigurationError("Configuration not found");return e.iframeUrl}async setMessagePoster(e){if(!e||"function"!=typeof e.postMessage)throw new r.ConfigurationError("Invalid message poster");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(){if(this.storage.remove(d.StorageKeys.ACCOUNT),"undefined"==typeof document&&!this.messagePoster)return h.debugLog("Skipping signer disconnect: no messagePoster available in non-browser environment"),this.provider=null,this.messenger=null,this.iframeManager=null,this.iframeManagerPromise=null,this.signer=null,void(this.signerPromise=null);try{const e=await this.ensureSigner();await e.disconnect()}catch{}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 h.debugLog("Invalid message received:",e);h.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 h.debugLog("[HANDSHAKE DEBUG] Passing message directly to existing ReactNativeMessenger"),void this.messenger.handleMessage(e);const t=await this.getIframeManager();h.debugLog(`[HANDSHAKE DEBUG] IframeManager obtained, isLoaded: ${t.isLoaded()}`),r&&!t.isLoaded()&&h.debugLog("[HANDSHAKE DEBUG] Received penpal message before connection initialized, setting up connection..."),h.debugLog("[HANDSHAKE DEBUG] Calling iframeManager.onMessage"),await t.onMessage(e),h.debugLog("[HANDSHAKE DEBUG] iframeManager.onMessage completed")}isReady(){return this.iframeManager?.isLoaded()||!1}};
@@ -1 +1 @@
1
- "use strict";var e=require("human-id"),r=require("./errors.cjs"),t=require("./types.cjs"),s=require("./utils.cjs");exports.PasskeyHandler=class{validByteLengths=[16,24,32];rpId;rpName;displayName;timeoutMs;derivedKeyLengthBytes;constructor({rpId:e,rpName:r,displayName:s,timeoutMs:a,derivedKeyLengthBytes:i}={}){if(this.rpId=e,this.rpName=r,this.displayName=s??t.DEFAULT_PASSKEY_DISPLAY_NAME,this.timeoutMs=a??6e4,this.derivedKeyLengthBytes=i??32,!this.validByteLengths.includes(this.derivedKeyLengthBytes))throw new Error(`Invalid key byte length ${this.derivedKeyLengthBytes}`)}static randomPasskeyName(){return e.humanId({capitalize:!0,separator:" "})}getChallengeBytes(){return crypto.getRandomValues(new Uint8Array(32))}async deriveKeyFromAssertion(e){const t=e.getClientExtensionResults();if(!t)throw new r.PasskeyPRFNotSupportedError("Passkey fetch failed: no client extension results");const s=t.prf;if(!s||!s.results)throw new r.PasskeyPRFNotSupportedError("PRF extension not supported or missing results");const a=s.results.first,i=await crypto.subtle.importKey("raw",a,{name:"AES-CBC",length:this.derivedKeyLengthBytes},!0,["encrypt","decrypt"]);return crypto.subtle.exportKey("raw",i)}async createPasskey({id:e,seed:t}){if(!t||0===t.trim().length)throw new r.PasskeySeedInvalidError;const a={challenge:this.getChallengeBytes(),rp:{id:this.rpId,name:this.rpName},user:{id:(new TextEncoder).encode(e),name:e,displayName:this.displayName},pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-257}],authenticatorSelection:{residentKey:"required",userVerification:"required"},extensions:{prf:{eval:{first:(new TextEncoder).encode(t)}}},timeout:this.timeoutMs,attestation:"direct"};let i,n;try{i=await navigator.credentials.create({publicKey:a})}catch(e){if(e instanceof Error&&"NotAllowedError"===e.name)throw new r.PasskeyUserCancelledError;throw new r.PasskeyCreationFailedError(e instanceof Error?e.message:"Unknown error",e instanceof Error?e:void 0)}if(!i)throw new r.PasskeyUserCancelledError;try{n=await this.deriveKeyFromAssertion(i)}catch(e){throw e instanceof r.PasskeyPRFNotSupportedError&&console.warn(`[Openfort] Passkey created but PRF extension failed. A passkey credential may exist on the device that cannot be used for wallet recovery. Credential ID: ${s.arrayBufferToBase64URL(i.rawId)}`),e}return{id:s.arrayBufferToBase64URL(i.rawId),displayName:this.displayName,key:s.arrayBufferToBase64URL(n)}}async deriveAndExportKey({id:e,seed:t}){if(!t||0===t.trim().length)throw new r.PasskeySeedInvalidError;let a;try{a=await navigator.credentials.get({publicKey:{challenge:this.getChallengeBytes(),rpId:this.rpId,allowCredentials:[{id:s.base64ToArrayBuffer(e),type:"public-key"}],userVerification:"required",extensions:{prf:{eval:{first:(new TextEncoder).encode(t)}}}}})}catch(e){if(e instanceof Error&&"NotAllowedError"===e.name)throw new r.PasskeyUserCancelledError;throw new r.PasskeyAssertionFailedError(e instanceof Error?e.message:"Unknown error",e instanceof Error?e:void 0)}if(!a)throw new r.PasskeyUserCancelledError;const i=await this.deriveKeyFromAssertion(a);return s.arrayBufferToBase64URL(i)}};
1
+ "use strict";var e=require("human-id"),r=require("./errors.cjs"),t=require("./types.cjs"),s=require("./utils.cjs");exports.PasskeyHandler=class{validByteLengths=[16,24,32];rpId;rpName;displayName;timeoutMs;derivedKeyLengthBytes;constructor({rpId:e,rpName:r,displayName:s,timeoutMs:a,derivedKeyLengthBytes:i}={}){if(this.rpId=e,this.rpName=r,this.displayName=s??t.DEFAULT_PASSKEY_DISPLAY_NAME,this.timeoutMs=a??6e4,this.derivedKeyLengthBytes=i??32,!this.validByteLengths.includes(this.derivedKeyLengthBytes))throw new Error(`Invalid key byte length ${this.derivedKeyLengthBytes}`)}static randomPasskeyName(){return e.humanId({capitalize:!0,separator:" "})}getChallengeBytes(){return crypto.getRandomValues(new Uint8Array(32))}async deriveKeyFromAssertion(e){const t=e.getClientExtensionResults();if(!t)throw new r.PasskeyPRFNotSupportedError("Passkey fetch failed: no client extension results");const s=t.prf;if(!s?.results)throw new r.PasskeyPRFNotSupportedError("PRF extension not supported or missing results");const a=s.results.first,i=await crypto.subtle.importKey("raw",a,{name:"AES-CBC",length:this.derivedKeyLengthBytes},!0,["encrypt","decrypt"]);return crypto.subtle.exportKey("raw",i)}async createPasskey({id:e,seed:t}){if(!t||0===t.trim().length)throw new r.PasskeySeedInvalidError;const a={challenge:this.getChallengeBytes(),rp:{id:this.rpId,name:this.rpName},user:{id:(new TextEncoder).encode(e),name:e,displayName:this.displayName},pubKeyCredParams:[{type:"public-key",alg:-7},{type:"public-key",alg:-257}],authenticatorSelection:{residentKey:"required",userVerification:"required"},extensions:{prf:{eval:{first:(new TextEncoder).encode(t)}}},timeout:this.timeoutMs,attestation:"direct"};let i,n;try{i=await navigator.credentials.create({publicKey:a})}catch(e){if(e instanceof Error&&"NotAllowedError"===e.name)throw new r.PasskeyUserCancelledError;throw new r.PasskeyCreationFailedError(e instanceof Error?e.message:"Unknown error",e instanceof Error?e:void 0)}if(!i)throw new r.PasskeyUserCancelledError;try{n=await this.deriveKeyFromAssertion(i)}catch(e){throw e instanceof r.PasskeyPRFNotSupportedError&&console.warn(`[Openfort] Passkey created but PRF extension failed. A passkey credential may exist on the device that cannot be used for wallet recovery. Credential ID: ${s.arrayBufferToBase64URL(i.rawId)}`),e}return{id:s.arrayBufferToBase64URL(i.rawId),displayName:this.displayName,key:s.arrayBufferToBase64URL(n)}}async deriveAndExportKey({id:e,seed:t}){if(!t||0===t.trim().length)throw new r.PasskeySeedInvalidError;let a;try{a=await navigator.credentials.get({publicKey:{challenge:this.getChallengeBytes(),rpId:this.rpId,allowCredentials:[{id:s.base64ToArrayBuffer(e),type:"public-key"}],userVerification:"required",extensions:{prf:{eval:{first:(new TextEncoder).encode(t)}}}}})}catch(e){if(e instanceof Error&&"NotAllowedError"===e.name)throw new r.PasskeyUserCancelledError;throw new r.PasskeyAssertionFailedError(e instanceof Error?e.message:"Unknown error",e instanceof Error?e:void 0)}if(!a)throw new r.PasskeyUserCancelledError;const i=await this.deriveKeyFromAssertion(a);return s.arrayBufferToBase64URL(i)}};
@@ -1 +1 @@
1
- "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.3.3";
1
+ "use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.3.4";
@@ -1 +1 @@
1
- "use strict";var e=require("../core/configuration/authentication.cjs"),t=require("../core/errors/authErrorCodes.cjs"),a=require("../core/errors/openfortError.cjs"),r=require("../core/errors/withApiError.cjs"),o=require("../core/passkey/handler.cjs"),n=require("../core/config/config.cjs"),s=require("../core/configuration/account.cjs"),i=require("../storage/istorage.cjs"),c=require("../types/types.cjs");exports.EmbeddedSigner=class{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 t=await this.passkeyHandler.createPasskey({id:o.PasskeyHandler.randomPasskeyName(),seed:e});return{id:t.id,key:t.key}}async configure(o){const i=await e.Authentication.fromStorage(this.storage);if(!i)throw new a.SessionError(t.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");const d=n.SDKConfiguration.getInstance();if(!d)throw new a.ConfigurationError("Configuration not found");const y=await s.Account.fromStorage(this.storage);let h;if(y){const e={account:y.id,...o.entropy&&{entropy:{...o.entropy.recoveryPassword&&{recoveryPassword:o.entropy.recoveryPassword},...o.entropy.encryptionSession&&{encryptionSession:o.entropy.encryptionSession},..."passkey"===y.recoveryMethod&&{passkey:{id:y.recoveryMethodDetails?.passkeyId,env:y.recoveryMethodDetails?.passkeyEnv,key:await o.getPasskeyKeyFn(y.recoveryMethodDetails?.passkeyId??"")}}}}},t=await this.iframeManager.recover(e);h=t.account}else{const e=await this.backendApiClients.accountsV2Api.getAccountsV2({accountType:o.accountType,chainType:o.chainType},{headers:i.thirdPartyProvider?{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:{authorization:`Bearer ${i.token}`,"x-project-key":d.baseConfiguration.publishableKey}});if(0===e.data.data.length){const e=o.entropy?.passkey?await this.createPasskey(i.userId):void 0,t={accountType:o.accountType,chainType:o.chainType,chainId:o.chainId,...o.entropy&&{entropy:{...o.entropy.recoveryPassword&&{recoveryPassword:o.entropy.recoveryPassword},...o.entropy.encryptionSession&&{encryptionSession:o.entropy.encryptionSession},...o.entropy.passkey&&{passkey:e}}}},a=await this.iframeManager.create(t);h=a.account}else{const t=e.data.data,a=t.find(e=>e.chainId===o.chainId),r=a||t[0],n={account:r.id,...o.entropy&&{entropy:{...o.entropy.recoveryPassword&&{recoveryPassword:o.entropy.recoveryPassword},...o.entropy.encryptionSession&&{encryptionSession:o.entropy.encryptionSession},..."passkey"===r.recoveryMethod&&{passkey:{id:r.recoveryMethodDetails?.passkeyId,env:r.recoveryMethodDetails?.passkeyEnv,key:await o.getPasskeyKeyFn(r.recoveryMethodDetails?.passkeyId??"")}}}}},s=await this.iframeManager.recover(n);if(h=s.account,!a){const e=await this.iframeManager.switchChain(o.chainId);h=e.account}}}return r.withApiError(async()=>{const e=await this.backendApiClients.accountsV2Api.getAccountV2({id:h},{headers:i.thirdPartyProvider?{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:{authorization:`Bearer ${i.token}`,"x-project-key":d.baseConfiguration.publishableKey}}),t=new s.Account({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:s.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(c.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"configure"})}async sign(e,t,a,r){const o=await this.iframeManager.sign(e,t,a,r);return this.eventEmitter.emit(c.OpenfortEvents.ON_SIGNED_MESSAGE,{message:e,signature:o}),o}async export(){return await this.iframeManager.export()}async switchChain({chainId:e}){const t=await s.Account.fromStorage(this.storage);if(t?.accountType===c.AccountTypeEnum.EOA)new s.Account({...t,chainId:e}).save(this.storage);else{const a=await this.iframeManager.switchChain(e);new s.Account({...t,id:a.account,chainId:e}).save(this.storage)}}async create(o){const i=await this.iframeManager.create(o),d=await e.Authentication.fromStorage(this.storage);if(!d)throw new a.SessionError(t.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");const y=n.SDKConfiguration.getInstance();if(!y)throw new a.ConfigurationError("Configuration not found");return r.withApiError(async()=>{const e=await this.backendApiClients.accountsV2Api.getAccountV2({id:i.account},{headers:d.thirdPartyProvider?{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}:{authorization:`Bearer ${d.token}`,"x-project-key":y.baseConfiguration.publishableKey}}),t=new s.Account({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:s.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(c.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"create"})}async recover(o){const i=await this.iframeManager.recover(o),d=await e.Authentication.fromStorage(this.storage);if(!d)throw new a.SessionError(t.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");const y=n.SDKConfiguration.getInstance();if(!y)throw new a.ConfigurationError("Configuration not found");return r.withApiError(async()=>{const e=await this.backendApiClients.accountsV2Api.getAccountV2({id:i.account},{headers:d.thirdPartyProvider?{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}:{authorization:`Bearer ${d.token}`,"x-project-key":y.baseConfiguration.publishableKey}}),t=new s.Account({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:s.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(c.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"recover"})}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(i.StorageKeys.ACCOUNT)}};
1
+ "use strict";var e=require("../core/configuration/authentication.cjs"),t=require("../core/errors/authErrorCodes.cjs"),a=require("../core/errors/openfortError.cjs"),r=require("../core/errors/withApiError.cjs"),o=require("../core/passkey/handler.cjs"),n=require("../core/config/config.cjs"),s=require("../core/configuration/account.cjs"),i=require("../storage/istorage.cjs"),c=require("../types/types.cjs");exports.EmbeddedSigner=class{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 t=await this.passkeyHandler.createPasskey({id:o.PasskeyHandler.randomPasskeyName(),seed:e});return{id:t.id,key:t.key}}async configure(o){const i=await e.Authentication.fromStorage(this.storage);if(!i)throw new a.SessionError(t.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");const d=n.SDKConfiguration.getInstance();if(!d)throw new a.ConfigurationError("Configuration not found");const y=await s.Account.fromStorage(this.storage);let h;if(y){const e={account:y.id,...o.entropy&&{entropy:{...o.entropy.recoveryPassword&&{recoveryPassword:o.entropy.recoveryPassword},...o.entropy.encryptionSession&&{encryptionSession:o.entropy.encryptionSession},..."passkey"===y.recoveryMethod&&{passkey:{id:y.recoveryMethodDetails?.passkeyId,env:y.recoveryMethodDetails?.passkeyEnv,key:await o.getPasskeyKeyFn(y.recoveryMethodDetails?.passkeyId??"")}}}}},t=await this.iframeManager.recover(e);h=t.account}else{const e=await this.backendApiClients.accountsV2Api.getAccountsV2({accountType:o.accountType,chainType:o.chainType},{headers:i.thirdPartyProvider?{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:{authorization:`Bearer ${i.token}`,"x-project-key":d.baseConfiguration.publishableKey}});if(0===e.data.data.length){const e=o.entropy?.passkey?await this.createPasskey(i.userId):void 0,t={accountType:o.accountType,chainType:o.chainType,chainId:o.chainId,...o.entropy&&{entropy:{...o.entropy.recoveryPassword&&{recoveryPassword:o.entropy.recoveryPassword},...o.entropy.encryptionSession&&{encryptionSession:o.entropy.encryptionSession},...o.entropy.passkey&&{passkey:e}}}},a=await this.iframeManager.create(t);h=a.account}else{const t=e.data.data,a=t.find(e=>e.chainId===o.chainId),r=a||t[0],n={account:r.id,...o.entropy&&{entropy:{...o.entropy.recoveryPassword&&{recoveryPassword:o.entropy.recoveryPassword},...o.entropy.encryptionSession&&{encryptionSession:o.entropy.encryptionSession},..."passkey"===r.recoveryMethod&&{passkey:{id:r.recoveryMethodDetails?.passkeyId,env:r.recoveryMethodDetails?.passkeyEnv,key:await o.getPasskeyKeyFn(r.recoveryMethodDetails?.passkeyId??"")}}}}},s=await this.iframeManager.recover(n);if(h=s.account,!a){const e=await this.iframeManager.switchChain(o.chainId);h=e.account}}}return r.withApiError(async()=>{const e=await this.backendApiClients.accountsV2Api.getAccountV2({id:h},{headers:i.thirdPartyProvider?{authorization:`Bearer ${d.baseConfiguration.publishableKey}`,"x-player-token":i.token,"x-auth-provider":i.thirdPartyProvider,"x-token-type":i.thirdPartyTokenType}:{authorization:`Bearer ${i.token}`,"x-project-key":d.baseConfiguration.publishableKey}}),t=new s.Account({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:s.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(c.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"configure"})}async sign(e,t,a,r){const o=await this.iframeManager.sign(e,t,a,r);return this.eventEmitter.emit(c.OpenfortEvents.ON_SIGNED_MESSAGE,{message:e,signature:o}),o}async export(){return await this.iframeManager.export()}async switchChain({chainId:e}){const t=await s.Account.fromStorage(this.storage);if(t?.accountType===c.AccountTypeEnum.EOA)new s.Account({...t,chainId:e}).save(this.storage);else{const a=await this.iframeManager.switchChain(e);new s.Account({...t,id:a.account,chainId:e}).save(this.storage)}}async create(o){const i=await this.iframeManager.create(o),d=await e.Authentication.fromStorage(this.storage);if(!d)throw new a.SessionError(t.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");const y=n.SDKConfiguration.getInstance();if(!y)throw new a.ConfigurationError("Configuration not found");return r.withApiError(async()=>{const e=await this.backendApiClients.accountsV2Api.getAccountV2({id:i.account},{headers:d.thirdPartyProvider?{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}:{authorization:`Bearer ${d.token}`,"x-project-key":y.baseConfiguration.publishableKey}}),t=new s.Account({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:s.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(c.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"create"})}async import(o){const i=await this.iframeManager.import(o),d=await e.Authentication.fromStorage(this.storage);if(!d)throw new a.SessionError(t.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");const y=n.SDKConfiguration.getInstance();if(!y)throw new a.ConfigurationError("Configuration not found");return r.withApiError(async()=>{const e=await this.backendApiClients.accountsV2Api.getAccountV2({id:i.account},{headers:d.thirdPartyProvider?{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}:{authorization:`Bearer ${d.token}`,"x-project-key":y.baseConfiguration.publishableKey}}),t=new s.Account({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:s.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(c.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"import"})}async recover(o){const i=await this.iframeManager.recover(o),d=await e.Authentication.fromStorage(this.storage);if(!d)throw new a.SessionError(t.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"No access token found");const y=n.SDKConfiguration.getInstance();if(!y)throw new a.ConfigurationError("Configuration not found");return r.withApiError(async()=>{const e=await this.backendApiClients.accountsV2Api.getAccountV2({id:i.account},{headers:d.thirdPartyProvider?{authorization:`Bearer ${y.baseConfiguration.publishableKey}`,"x-player-token":d.token,"x-auth-provider":d.thirdPartyProvider,"x-token-type":d.thirdPartyTokenType}:{authorization:`Bearer ${d.token}`,"x-project-key":y.baseConfiguration.publishableKey}}),t=new s.Account({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:s.Account.parseRecoveryMethod(e.data.recoveryMethod),recoveryMethodDetails:e.data.recoveryMethodDetails});return t.save(this.storage),this.eventEmitter.emit(c.OpenfortEvents.ON_SWITCH_ACCOUNT,e.data.address),t},{context:"recover"})}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(i.StorageKeys.ACCOUNT)}};
@@ -1 +1 @@
1
- "use strict";var e=require("../core/configuration/account.cjs"),i=require("../core/configuration/authentication.cjs"),r=require("../core/errors/authErrorCodes.cjs"),t=require("../core/errors/openfortError.cjs"),n=require("../core/errors/sentry.cjs"),o=require("../storage/istorage.cjs"),s=require("../utils/crypto.cjs"),a=require("../utils/debug.cjs"),d=require("./messaging/ReactNativeMessenger.cjs"),c=require("./messaging/browserMessenger/connect.cjs");require("./messaging/browserMessenger/backwardCompatibility.cjs");var u=require("./types.cjs");class h extends t.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.MISSING_RECOVERY_PASSWORD,"This embedded signer requires a password to be recovered","password")}}class g extends t.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.INCORRECT_PASSKEY,"Wrong recovery passkey for this embedded signer","passkey")}}class l extends t.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.MISSING_PROJECT_ENTROPY,"Project entropy is missing","entropy")}}class R extends t.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.WRONG_RECOVERY_PASSWORD,"Wrong recovery password for this embedded signer","password")}}class y extends t.SignerError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.NOT_CONFIGURED,"Signer is not configured")}}class p extends t.OpenfortError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.OTP_REQUIRED,"OTP verification required")}}exports.IframeManager=class{messenger;connection;remote;storage;sdkConfiguration;isInitialized=!1;initializationPromise=null;hasFailed=!1;constructor(e,i,r){if(!e)throw new t.ConfigurationError("Configuration is required for IframeManager");if(!i)throw new t.ConfigurationError("Storage is required for IframeManager");if(!r)throw new t.ConfigurationError("Messenger is required for IframeManager");this.sdkConfiguration=e,this.storage=i,this.messenger=r}async initialize(){if(!this.isInitialized){if(this.hasFailed)throw new t.OpenfortError(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Failed to establish iFrame connection: Previous connection attempt failed");if(this.initializationPromise)await this.initializationPromise;else{this.initializationPromise=this.doInitialize();try{await this.initializationPromise,this.isInitialized=!0}catch(e){throw this.hasFailed=!0,this.initializationPromise=null,e}}}}async doInitialize(){a.debugLog("Initializing IframeManager connection..."),this.messenger.initialize({validateReceivedMessage:e=>!(!e||"object"!=typeof e),log:a.debugLog}),this.connection=c({messenger:this.messenger,timeout:1e4,log:a.debugLog});try{this.remote=await this.connection.promise,a.debugLog("IframeManager connection established")}catch(e){const i=e;throw n.sentry.captureException(i),this.destroy(),a.debugLog("Failed to establish connection:",i),new t.OpenfortError(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,`Failed to establish iFrame connection: ${i.cause||i.message}\n \n In apps built with:\n - react native\n - swift\n - unity (non-webgl) \n \n You must configure your origin in the openfort dashboard before using the embedded wallet.\n\n For more information, see: https://www.openfort.io/docs/configuration/native-apps\n `)}}async ensureConnection(){if(this.isInitialized&&this.remote||await this.initialize(),!this.remote)throw new t.OpenfortError(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Failed to establish connection");return this.remote}handleError(e){if(u.isErrorResponse(e)){if(e.error===u.NOT_CONFIGURED_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new y;if(e.error===u.MISSING_USER_ENTROPY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new h;if(e.error===u.MISSING_PROJECT_ENTROPY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new l;if(e.error===u.INCORRECT_USER_ENTROPY_ERROR)throw new R;if(e.error===u.MISSING_PASSKEY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new h;if(e.error===u.INCORRECT_PASSKEY_ERROR)throw new g;if(e.error===u.OTP_REQUIRED_ERROR)throw new p;throw this.storage.remove(o.StorageKeys.ACCOUNT),new t.OpenfortError(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,`Unknown error: ${e.error}`)}throw e}async buildRequestConfiguration(){const e=await i.Authentication.fromStorage(this.storage);if(!e)throw new t.SessionError(r.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"Must be authenticated to create a signer");const n={auth:u.ShieldAuthType.OPENFORT,authProvider:e.thirdPartyProvider,token:e.token,tokenType:e.thirdPartyTokenType};return{thirdPartyProvider:e.thirdPartyProvider,thirdPartyTokenType:e.thirdPartyTokenType,token:e.token,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl,shieldAuthentication:n,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",shieldURL:this.sdkConfiguration.shieldUrl,encryptionKey:void 0,appNativeIdentifier:this.sdkConfiguration?.nativeAppIdentifier??void 0}}async buildIFrameRequestConfiguration(){const e=await i.Authentication.fromStorage(this.storage);if(!e)throw new t.SessionError(r.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"Must be authenticated to create a signer");const n={auth:u.ShieldAuthType.OPENFORT,authProvider:e.thirdPartyProvider,token:e.token,tokenType:e.thirdPartyTokenType};return{thirdPartyTokenType:e.thirdPartyTokenType??null,thirdPartyProvider:e.thirdPartyProvider??null,accessToken:e.token,playerID:e.userId,recovery:n,chainId:null,password:null,passkey:null}}async create(e){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const i=await this.ensureConnection(),r=await this.buildIFrameRequestConfiguration();r.chainId=e.chainId??null,r.password=e?.entropy?.recoveryPassword??null,r.recovery={...r.recovery,encryptionSession:e?.entropy?.encryptionSession},r.passkey=e?.entropy?.passkey??null;const t={uuid:s.randomUUID(),action:u.Event.CREATE,recovery:r.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",accessToken:r.accessToken,playerID:r.playerID,thirdPartyProvider:r.thirdPartyProvider,thirdPartyTokenType:r.thirdPartyTokenType,encryptionKey:r.password,encryptionSession:r.recovery?.encryptionSession??null,passkey:r.passkey??null,openfortURL:this.sdkConfiguration.backendUrl,shieldURL:this.sdkConfiguration.shieldUrl,chainId:e.chainId??null,accountType:e.accountType,chainType:e.chainType,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},n=await i.create(t);return u.isErrorResponse(n)&&this.handleError(n),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",n.version??"undefined"),n}async recover(i){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const r=await e.Account.fromStorage(this.storage),t=await this.ensureConnection(),n=await this.buildIFrameRequestConfiguration();n.chainId=r?.chainId??null,n.password=i?.entropy?.recoveryPassword??null,n.recovery={...n.recovery,encryptionSession:i?.entropy?.encryptionSession},n.passkey=i?.entropy?.passkey??null;const o={uuid:s.randomUUID(),action:u.Event.RECOVER,recovery:n.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",accessToken:n.accessToken,playerID:n.playerID,thirdPartyProvider:n.thirdPartyProvider,thirdPartyTokenType:n.thirdPartyTokenType,encryptionKey:n.password,encryptionSession:n.recovery?.encryptionSession??null,passkey:n.passkey??null,openfortURL:this.sdkConfiguration.backendUrl,shieldURL:this.sdkConfiguration.shieldUrl,account:i.account,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},a=await t.recover(o);return u.isErrorResponse(a)&&this.handleError(a),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",a.version??"undefined"),a}async sign(e,i,r,t){a.debugLog("[iframe] ensureConnection");const n=await this.ensureConnection(),o=new u.SignRequest(s.randomUUID(),e,await this.buildRequestConfiguration(),i,r,t);a.debugLog("[iframe] done ensureConnection");const d=await n.sign(o);return a.debugLog("[iframe] response",d),u.isErrorResponse(d)&&this.handleError(d),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",d.version??"undefined"),d.signature}async switchChain(e){const i=await this.ensureConnection(),r=new u.SwitchChainRequest(s.randomUUID(),e,await this.buildRequestConfiguration()),t=await i.switchChain(r);return u.isErrorResponse(t)&&this.handleError(t),t}async export(){const e=await this.ensureConnection(),i=new u.ExportPrivateKeyRequest(s.randomUUID(),await this.buildRequestConfiguration()),r=await e.export(i);return u.isErrorResponse(r)&&this.handleError(r),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",r.version??"undefined"),r.key}async setRecoveryMethod(e,i,r,t,n){const o=await this.ensureConnection(),a=new u.SetRecoveryMethodRequest(s.randomUUID(),e,await this.buildRequestConfiguration(),i,r,t,n),d=await o.setRecoveryMethod(a);u.isErrorResponse(d)&&this.handleError(d),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",d.version??"undefined")}async getCurrentDevice(e){const i=await this.ensureConnection(),r=new u.GetCurrentDeviceRequest(s.randomUUID(),e);try{const e=await i.getCurrentDevice(r);return u.isErrorResponse(e)&&this.handleError(e),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",e.version??"undefined"),e}catch(e){if(e instanceof y)return null;throw e}}async updateAuthentication(){if(!this.isLoaded()||!this.remote)return void a.debugLog("IframeManager not loaded, skipping authentication update");const e=await i.Authentication.fromStorage(this.storage);if(!e)return void a.debugLog("No authentication found, skipping update");const r=new u.UpdateAuthenticationRequest(s.randomUUID(),e.token);a.debugLog("Updating authentication in iframe with token");const t=await this.remote.updateAuthentication(r);u.isErrorResponse(t)&&this.handleError(t)}async disconnect(){const e=await this.ensureConnection(),i={uuid:s.randomUUID()};await e.logout(i)}async onMessage(e){a.debugLog("[HANDSHAKE DEBUG] IframeManager.onMessage called with:",e),this.messenger instanceof d.ReactNativeMessenger?(this.isInitialized||this.connection?a.debugLog(`[HANDSHAKE DEBUG] Connection already initialized (isInitialized: ${this.isInitialized}, hasConnection: ${!!this.connection})`):(a.debugLog("[HANDSHAKE DEBUG] First message received, initializing connection..."),this.initialize().catch(e=>{a.debugLog("[HANDSHAKE DEBUG] Failed to initialize connection:",e)})),a.debugLog("[HANDSHAKE DEBUG] Passing message to ReactNativeMessenger"),this.messenger.handleMessage(e)):a.debugLog("[HANDSHAKE DEBUG] Not a ReactNativeMessenger, ignoring message")}isLoaded(){return this.isInitialized&&void 0!==this.remote}destroy(){this.connection&&this.connection.destroy(),this.remote=void 0,this.isInitialized=!1,this.connection=void 0,this.initializationPromise=null}},exports.MissingProjectEntropyError=l,exports.MissingRecoveryPasswordError=h,exports.NotConfiguredError=y,exports.OTPRequiredError=p,exports.WrongPasskeyError=g,exports.WrongRecoveryPasswordError=R;
1
+ "use strict";var e=require("../core/configuration/account.cjs"),i=require("../core/configuration/authentication.cjs"),r=require("../core/errors/authErrorCodes.cjs"),n=require("../core/errors/openfortError.cjs"),t=require("../core/errors/sentry.cjs"),o=require("../storage/istorage.cjs"),s=require("../utils/crypto.cjs"),a=require("../utils/debug.cjs"),d=require("./messaging/ReactNativeMessenger.cjs"),c=require("./messaging/browserMessenger/connect.cjs");require("./messaging/browserMessenger/backwardCompatibility.cjs");var u=require("./types.cjs");class h extends n.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.MISSING_RECOVERY_PASSWORD,"This embedded signer requires a password to be recovered","password")}}class l extends n.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.INCORRECT_PASSKEY,"Wrong recovery passkey for this embedded signer","passkey")}}class g extends n.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.MISSING_PROJECT_ENTROPY,"Project entropy is missing","entropy")}}class y extends n.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.WRONG_RECOVERY_PASSWORD,"Wrong recovery password for this embedded signer","password")}}class p extends n.SignerError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.NOT_CONFIGURED,"Signer is not configured")}}class R extends n.OpenfortError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.OTP_REQUIRED,"OTP verification required")}}exports.IframeManager=class{messenger;connection;remote;storage;sdkConfiguration;isInitialized=!1;initializationPromise=null;hasFailed=!1;constructor(e,i,r){if(!e)throw new n.ConfigurationError("Configuration is required for IframeManager");if(!i)throw new n.ConfigurationError("Storage is required for IframeManager");if(!r)throw new n.ConfigurationError("Messenger is required for IframeManager");this.sdkConfiguration=e,this.storage=i,this.messenger=r}async initialize(){if(!this.isInitialized){if(this.hasFailed)throw new n.OpenfortError(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Failed to establish iFrame connection: Previous connection attempt failed");if(this.initializationPromise)await this.initializationPromise;else{this.initializationPromise=this.doInitialize();try{await this.initializationPromise,this.isInitialized=!0}catch(e){throw this.hasFailed=!0,this.initializationPromise=null,e}}}}async doInitialize(){a.debugLog("Initializing IframeManager connection..."),this.messenger.initialize({validateReceivedMessage:e=>!(!e||"object"!=typeof e),log:a.debugLog}),this.connection=c({messenger:this.messenger,timeout:1e4,log:a.debugLog});try{this.remote=await this.connection.promise,a.debugLog("IframeManager connection established")}catch(e){const i=e;throw t.sentry.captureException(i),this.destroy(),a.debugLog("Failed to establish connection:",i),new n.OpenfortError(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,`Failed to establish iFrame connection: ${i.cause||i.message}\n \n In apps built with:\n - react native\n - swift\n - unity (non-webgl) \n \n You must configure your origin in the openfort dashboard before using the embedded wallet.\n\n For more information, see: https://www.openfort.io/docs/configuration/native-apps\n `)}}async ensureConnection(){if(this.isInitialized&&this.remote||await this.initialize(),!this.remote)throw new n.OpenfortError(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Failed to establish connection");return this.remote}handleError(e){if(u.isErrorResponse(e)){if(e.error===u.NOT_CONFIGURED_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new p;if(e.error===u.MISSING_USER_ENTROPY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new h;if(e.error===u.MISSING_PROJECT_ENTROPY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new g;if(e.error===u.INCORRECT_USER_ENTROPY_ERROR)throw new y;if(e.error===u.MISSING_PASSKEY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new h;if(e.error===u.INCORRECT_PASSKEY_ERROR)throw new l;if(e.error===u.OTP_REQUIRED_ERROR)throw new R;throw this.storage.remove(o.StorageKeys.ACCOUNT),new n.OpenfortError(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,`Unknown error: ${e.error}`)}throw e}async buildRequestConfiguration(){const e=await i.Authentication.fromStorage(this.storage);if(!e)throw new n.SessionError(r.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"Must be authenticated to create a signer");const t={auth:u.ShieldAuthType.OPENFORT,authProvider:e.thirdPartyProvider,token:e.token,tokenType:e.thirdPartyTokenType};return{thirdPartyProvider:e.thirdPartyProvider,thirdPartyTokenType:e.thirdPartyTokenType,token:e.token,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,openfortURL:this.sdkConfiguration.backendUrl,shieldAuthentication:t,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",shieldURL:this.sdkConfiguration.shieldUrl,encryptionKey:void 0,appNativeIdentifier:this.sdkConfiguration?.nativeAppIdentifier??void 0}}async buildIFrameRequestConfiguration(){const e=await i.Authentication.fromStorage(this.storage);if(!e)throw new n.SessionError(r.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"Must be authenticated to create a signer");const t={auth:u.ShieldAuthType.OPENFORT,authProvider:e.thirdPartyProvider,token:e.token,tokenType:e.thirdPartyTokenType};return{thirdPartyTokenType:e.thirdPartyTokenType??null,thirdPartyProvider:e.thirdPartyProvider??null,accessToken:e.token,playerID:e.userId,recovery:t,chainId:null,password:null,passkey:null}}async create(e){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const i=await this.ensureConnection(),r=await this.buildIFrameRequestConfiguration();r.chainId=e.chainId??null,r.password=e?.entropy?.recoveryPassword??null,r.recovery={...r.recovery,encryptionSession:e?.entropy?.encryptionSession},r.passkey=e?.entropy?.passkey??null;const n={uuid:s.randomUUID(),action:u.Event.CREATE,recovery:r.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",accessToken:r.accessToken,playerID:r.playerID,thirdPartyProvider:r.thirdPartyProvider,thirdPartyTokenType:r.thirdPartyTokenType,encryptionKey:r.password,encryptionSession:r.recovery?.encryptionSession??null,passkey:r.passkey??null,openfortURL:this.sdkConfiguration.backendUrl,shieldURL:this.sdkConfiguration.shieldUrl,chainId:e.chainId??null,accountType:e.accountType,chainType:e.chainType,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},t=await i.create(n);return u.isErrorResponse(t)&&this.handleError(t),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",t.version??"undefined"),t}async import(e){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const i=await this.ensureConnection(),r=await this.buildIFrameRequestConfiguration();r.chainId=e.chainId??null,r.password=e?.entropy?.recoveryPassword??null,r.recovery={...r.recovery,encryptionSession:e?.entropy?.encryptionSession},r.passkey=e?.entropy?.passkey??null;const n={uuid:s.randomUUID(),action:u.Event.IMPORT,privateKey:e.privateKey,recovery:r.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",accessToken:r.accessToken,playerID:r.playerID,thirdPartyProvider:r.thirdPartyProvider,thirdPartyTokenType:r.thirdPartyTokenType,encryptionKey:r.password,encryptionSession:r.recovery?.encryptionSession??null,passkey:r.passkey??null,openfortURL:this.sdkConfiguration.backendUrl,shieldURL:this.sdkConfiguration.shieldUrl,chainId:e.chainId??null,accountType:e.accountType,chainType:e.chainType,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},t=await i.import(n);return u.isErrorResponse(t)&&this.handleError(t),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",t.version??"undefined"),t}async recover(i){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const r=await e.Account.fromStorage(this.storage),n=await this.ensureConnection(),t=await this.buildIFrameRequestConfiguration();t.chainId=r?.chainId??null,t.password=i?.entropy?.recoveryPassword??null,t.recovery={...t.recovery,encryptionSession:i?.entropy?.encryptionSession},t.passkey=i?.entropy?.passkey??null;const o={uuid:s.randomUUID(),action:u.Event.RECOVER,recovery:t.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",accessToken:t.accessToken,playerID:t.playerID,thirdPartyProvider:t.thirdPartyProvider,thirdPartyTokenType:t.thirdPartyTokenType,encryptionKey:t.password,encryptionSession:t.recovery?.encryptionSession??null,passkey:t.passkey??null,openfortURL:this.sdkConfiguration.backendUrl,shieldURL:this.sdkConfiguration.shieldUrl,account:i.account,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},a=await n.recover(o);return u.isErrorResponse(a)&&this.handleError(a),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",a.version??"undefined"),a}async sign(e,i,r,n){a.debugLog("[iframe] ensureConnection");const t=await this.ensureConnection(),o=new u.SignRequest(s.randomUUID(),e,await this.buildRequestConfiguration(),i,r,n);a.debugLog("[iframe] done ensureConnection");const d=await t.sign(o);return a.debugLog("[iframe] response",d),u.isErrorResponse(d)&&this.handleError(d),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",d.version??"undefined"),d.signature}async switchChain(e){const i=await this.ensureConnection(),r=new u.SwitchChainRequest(s.randomUUID(),e,await this.buildRequestConfiguration()),n=await i.switchChain(r);return u.isErrorResponse(n)&&this.handleError(n),n}async export(){const e=await this.ensureConnection(),i=new u.ExportPrivateKeyRequest(s.randomUUID(),await this.buildRequestConfiguration()),r=await e.export(i);return u.isErrorResponse(r)&&this.handleError(r),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",r.version??"undefined"),r.key}async setRecoveryMethod(e,i,r,n,t){const o=await this.ensureConnection(),a=new u.SetRecoveryMethodRequest(s.randomUUID(),e,await this.buildRequestConfiguration(),i,r,n,t),d=await o.setRecoveryMethod(a);u.isErrorResponse(d)&&this.handleError(d),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",d.version??"undefined")}async getCurrentDevice(e){const i=await this.ensureConnection(),r=new u.GetCurrentDeviceRequest(s.randomUUID(),e);try{const e=await i.getCurrentDevice(r);return u.isErrorResponse(e)&&this.handleError(e),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",e.version??"undefined"),e}catch(e){if(e instanceof p)return null;throw e}}async updateAuthentication(){if(!this.isLoaded()||!this.remote)return void a.debugLog("IframeManager not loaded, skipping authentication update");const e=await i.Authentication.fromStorage(this.storage);if(!e)return void a.debugLog("No authentication found, skipping update");const r=new u.UpdateAuthenticationRequest(s.randomUUID(),e.token);a.debugLog("Updating authentication in iframe with token");const n=await this.remote.updateAuthentication(r);u.isErrorResponse(n)&&this.handleError(n)}async disconnect(){const e=await this.ensureConnection(),i={uuid:s.randomUUID()};await e.logout(i)}async onMessage(e){a.debugLog("[HANDSHAKE DEBUG] IframeManager.onMessage called with:",e),this.messenger instanceof d.ReactNativeMessenger?(this.isInitialized||this.connection?a.debugLog(`[HANDSHAKE DEBUG] Connection already initialized (isInitialized: ${this.isInitialized}, hasConnection: ${!!this.connection})`):(a.debugLog("[HANDSHAKE DEBUG] First message received, initializing connection..."),this.initialize().catch(e=>{a.debugLog("[HANDSHAKE DEBUG] Failed to initialize connection:",e)})),a.debugLog("[HANDSHAKE DEBUG] Passing message to ReactNativeMessenger"),this.messenger.handleMessage(e)):a.debugLog("[HANDSHAKE DEBUG] Not a ReactNativeMessenger, ignoring message")}isLoaded(){return this.isInitialized&&void 0!==this.remote}destroy(){this.connection&&this.connection.destroy(),this.remote=void 0,this.isInitialized=!1,this.connection=void 0,this.initializationPromise=null}},exports.MissingProjectEntropyError=g,exports.MissingRecoveryPasswordError=h,exports.NotConfiguredError=p,exports.OTPRequiredError=R,exports.WrongPasskeyError=l,exports.WrongRecoveryPasswordError=y;
@@ -1 +1 @@
1
- "use strict";var e;exports.Event=void 0,(e=exports.Event||(exports.Event={})).RECOVER="recover",e.RECOVERED="recovered",e.CREATE="create",e.CREATED="created",e.UPDATE_AUTHENTICATION="update-authentication",e.AUTHENTICATION_UPDATED="authentication-updated",e.SIGN="sign",e.SET_RECOVERY_METHOD="set-recovery-method",e.SWITCH_CHAIN="switch-chain",e.CHAIN_SWITCHED="chain-switched",e.EXPORT="export",e.SIGNED="signed",e.LOGGED_OUT="logged-out",e.GET_CURRENT_DEVICE="get-current-device",e.CURRENT_DEVICE="current-device";exports.ShieldAuthType=void 0,(exports.ShieldAuthType||(exports.ShieldAuthType={})).OPENFORT="openfort",exports.ExportPrivateKeyRequest=class{uuid;action=exports.Event.EXPORT;requestConfiguration;constructor(e,t){this.uuid=e,this.requestConfiguration=t}},exports.GetCurrentDeviceRequest=class{uuid;action=exports.Event.GET_CURRENT_DEVICE;playerID;constructor(e,t){this.uuid=e,this.playerID=t}},exports.INCORRECT_PASSKEY_ERROR="incorrect-passkey-error",exports.INCORRECT_USER_ENTROPY_ERROR="incorrect-user-entropy-error",exports.MISSING_PASSKEY_ERROR="missing-passkey-error",exports.MISSING_PROJECT_ENTROPY_ERROR="missing-project-entropy-error",exports.MISSING_USER_ENTROPY_ERROR="missing-user-entropy-error",exports.NOT_CONFIGURED_ERROR="not-configured-error",exports.OTP_REQUIRED_ERROR="otp-required-error",exports.SetRecoveryMethodRequest=class{uuid;action=exports.Event.SET_RECOVERY_METHOD;recoveryMethod;recoveryPassword;encryptionSession;passkeyKey;passkeyId;requestConfiguration;constructor(e,t,r,s,o,i,n){this.uuid=e,this.recoveryMethod=t,this.recoveryPassword=s,this.encryptionSession=o,this.requestConfiguration=r,this.passkeyKey=i,this.passkeyId=n}},exports.SignRequest=class{uuid;action=exports.Event.SIGN;message;requestConfiguration;requireArrayify;requireHash;chainType;constructor(e,t,r,s,o,i){this.uuid=e,this.message=t,this.requestConfiguration=r,this.requireArrayify=s,this.requireHash=o,this.chainType=i||"EVM"}},exports.SwitchChainRequest=class{uuid;action=exports.Event.SWITCH_CHAIN;chainId;requestConfiguration;constructor(e,t,r){this.uuid=e,this.chainId=t,this.requestConfiguration=r}},exports.UpdateAuthenticationRequest=class{uuid;action=exports.Event.UPDATE_AUTHENTICATION;accessToken;recovery;constructor(e,t,r){this.uuid=e,this.accessToken=t,this.recovery=r}},exports.isErrorResponse=function(e){return"error"in e};
1
+ "use strict";var e;exports.Event=void 0,(e=exports.Event||(exports.Event={})).RECOVER="recover",e.RECOVERED="recovered",e.CREATE="create",e.CREATED="created",e.IMPORT="import",e.IMPORTED="imported",e.UPDATE_AUTHENTICATION="update-authentication",e.AUTHENTICATION_UPDATED="authentication-updated",e.SIGN="sign",e.SET_RECOVERY_METHOD="set-recovery-method",e.SWITCH_CHAIN="switch-chain",e.CHAIN_SWITCHED="chain-switched",e.EXPORT="export",e.SIGNED="signed",e.LOGGED_OUT="logged-out",e.GET_CURRENT_DEVICE="get-current-device",e.CURRENT_DEVICE="current-device";exports.ShieldAuthType=void 0,(exports.ShieldAuthType||(exports.ShieldAuthType={})).OPENFORT="openfort",exports.ExportPrivateKeyRequest=class{uuid;action=exports.Event.EXPORT;requestConfiguration;constructor(e,t){this.uuid=e,this.requestConfiguration=t}},exports.GetCurrentDeviceRequest=class{uuid;action=exports.Event.GET_CURRENT_DEVICE;playerID;constructor(e,t){this.uuid=e,this.playerID=t}},exports.INCORRECT_PASSKEY_ERROR="incorrect-passkey-error",exports.INCORRECT_USER_ENTROPY_ERROR="incorrect-user-entropy-error",exports.MISSING_PASSKEY_ERROR="missing-passkey-error",exports.MISSING_PROJECT_ENTROPY_ERROR="missing-project-entropy-error",exports.MISSING_USER_ENTROPY_ERROR="missing-user-entropy-error",exports.NOT_CONFIGURED_ERROR="not-configured-error",exports.OTP_REQUIRED_ERROR="otp-required-error",exports.SetRecoveryMethodRequest=class{uuid;action=exports.Event.SET_RECOVERY_METHOD;recoveryMethod;recoveryPassword;encryptionSession;passkeyKey;passkeyId;requestConfiguration;constructor(e,t,r,s,o,i,n){this.uuid=e,this.recoveryMethod=t,this.recoveryPassword=s,this.encryptionSession=o,this.requestConfiguration=r,this.passkeyKey=i,this.passkeyId=n}},exports.SignRequest=class{uuid;action=exports.Event.SIGN;message;requestConfiguration;requireArrayify;requireHash;chainType;constructor(e,t,r,s,o,i){this.uuid=e,this.message=t,this.requestConfiguration=r,this.requireArrayify=s,this.requireHash=o,this.chainType=i||"EVM"}},exports.SwitchChainRequest=class{uuid;action=exports.Event.SWITCH_CHAIN;chainId;requestConfiguration;constructor(e,t,r){this.uuid=e,this.chainId=t,this.requestConfiguration=r}},exports.UpdateAuthenticationRequest=class{uuid;action=exports.Event.UPDATE_AUTHENTICATION;accessToken;recovery;constructor(e,t,r){this.uuid=e,this.accessToken=t,this.recovery=r}},exports.isErrorResponse=function(e){return"error"in e};