@openfort/openfort-js 0.8.39 → 0.8.40
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.js"),t=require("./evm/walletHelpers.js"),r=require("./storage/istorage.js"),a=require("./storage/localStorage.js"),n=require("./manager/signer.js"),o=require("./errors/openfortError.js"),i=require("./types.js"),s=require("./configuration/configuration.js"),u=require("./configuration/account.js"),h=require("./configuration/authentication.js"),g=require("./iframe/iframeManager.js"),d=require("./authManager.js"),c=require("./evm/evmProvider.js");require("./evm/types.js");var l=require("./utils/typedEventEmitter.js"),p=require("./evm/provider/eip6963.js");exports.Openfort=class{storage;provider=null;iAuthManager=null;constructor(e){this.storage=new a.LocalStorage;new s.Configuration(e.baseConfiguration.publishableKey,e.overrides?.backendUrl||"https://api.openfort.xyz",e.shieldConfiguration?.shieldPublishableKey||"",e.shieldConfiguration?.shieldEncryptionKey||"",e.overrides?.shieldUrl||"https://shield.openfort.xyz",e.overrides?.iframeUrl||"https://embedded.openfort.xyz",e.shieldConfiguration?.debug||!1).save()}async logout(){const e=n.SignerManager.fromStorage();this.storage.remove(r.StorageKeys.AUTHENTICATION),this.storage.remove(r.StorageKeys.SIGNER),this.storage.remove(r.StorageKeys.ACCOUNT),e&&await e.logout()}getEthereumProvider(e){const t={announceProvider:!0,...e},r=h.Authentication.fromStorage(this.storage),a=n.SignerManager.fromStorage(),o=u.Account.fromStorage(this.storage);return this.provider?this.provider&&t.policy&&this.provider.updatePolicy(t.policy):(this.provider=new c.EvmProvider({storage:this.storage,openfortEventEmitter:new l,signer:a||void 0,account:o||void 0,authentication:r||void 0,backendApiClients:this.backendApiClients,policyId:t.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this)}),t.announceProvider&&p.announceProvider({info:{...p.openfortProviderInfo,...t.providerInfo},provider:this.provider})),this.provider}async configureEmbeddedSigner(e=null,t=null,r=null){await this.validateAndRefreshToken();const a=s.Configuration.fromStorage();let o=null;(r||t?.encryptionSession)&&(o={encryptionSession:t?.encryptionSession||null,recoveryPassword:r||null,encryptionPart:a?.shieldEncryptionKey||null});let i=null,u=null;t&&(i="openfort"===t.auth?"openfort":"custom",u=t.token),await n.SignerManager.embedded(e,o,i,u)}async signMessage(e,t){await this.validateAndRefreshToken();const r=n.SignerManager.fromStorage();if(!r)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);const{hashMessage:a=!0,arrayifyMessage:i=!1}=t||{};return await r.sign(e,i,a)}async signTypedData(e,r,a){await this.validateAndRefreshToken();const i=n.SignerManager.fromStorage(),s=u.Account.fromStorage(this.storage);if(!i||!s)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return await t.getSignedTypedData({domain:e,types:r,message:a},s.type,Number(s.chainId),i,s.address)}async exportPrivateKey(){await this.validateAndRefreshToken();const e=n.SignerManager.fromStorage();if(!e)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return await e.export()}async setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:t,encryptionSession:r}){await this.validateAndRefreshToken();const a=n.SignerManager.fromStorage();if(!a)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);if("embedded"!==a.type())throw new o.OpenfortError("Signer must be embedded",o.OpenfortErrorType.INVALID_CONFIGURATION);if("password"===e&&!t)throw new o.OpenfortError("Recovery password is required",o.OpenfortErrorType.INVALID_CONFIGURATION);await a.setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:t,encryptionSession:r})}async logInWithEmailPassword({email:e,password:t,ecosystemGame:r}){const a=h.Authentication.fromStorage(this.storage),n=await this.authManager.loginEmailPassword(e,t,r);return a&&a.player!==n.player.id&&this.logout(),new h.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async signUpGuest(){const e=h.Authentication.fromStorage(this.storage),t=await this.authManager.registerGuest();return e&&e.player!==t.player.id&&this.logout(),new h.Authentication("jwt",t.token,t.player.id,t.refreshToken).save(this.storage),t}async signUpWithEmailPassword({email:e,password:t,options:r,ecosystemGame:a}){const n=h.Authentication.fromStorage(this.storage),o=await this.authManager.signupEmailPassword(e,t,r?.data.name,a);return n&&n.player!==o.player.id&&this.logout(),new h.Authentication("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkEmailPassword({email:e,password:t,authToken:r,ecosystemGame:a}){return await this.authManager.linkEmail(e,t,r,a)}async unlinkEmailPassword({email:e,authToken:t}){return await this.authManager.unlinkEmail(e,t)}async requestEmailVerification({email:e,redirectUrl:t}){await this.authManager.requestEmailVerification(e,t)}async resetPassword({email:e,password:t,state:r}){await this.authManager.resetPassword(e,t,r)}async requestResetPassword({email:e,redirectUrl:t}){await this.authManager.requestResetPassword(e,t)}async verifyEmail({email:e,state:t}){await this.authManager.verifyEmail(e,t)}async initOAuth({provider:e,options:t,ecosystemGame:a}){return this.storage.remove(r.StorageKeys.AUTHENTICATION),await this.authManager.initOAuth(e,t,a)}async initLinkOAuth({provider:e,options:t,ecosystemGame:r}){const a=h.Authentication.fromStorage(this.storage);if(!a)throw new o.OpenfortError("No authentication found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(a,e,t,r)}async linkThirdPartyProvider({provider:e,token:t,tokenType:r}){const a=h.Authentication.fromStorage(this.storage);if(!a)throw new o.OpenfortError("No authentication found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkThirdParty(a,e,t,r)}async unlinkOAuth({provider:e,authToken:t}){return await this.authManager.unlinkOAuth(e,t)}async poolOAuth(e){const t=h.Authentication.fromStorage(this.storage),r=await this.authManager.poolOAuth(e);return t&&t.player!==r.player.id&&this.logout(),new h.Authentication("jwt",r.token,r.player.id,r.refreshToken).save(this.storage),r}async authenticateWithThirdPartyProvider({provider:e,token:t,tokenType:r,ecosystemGame:a}){const o=h.Authentication.fromStorage(this.storage),i=await this.authManager.authenticateThirdParty(e,t,r,a);let s=!1;if(o&&o.player!==i.id&&(this.logout(),s=!0),new h.Authentication("third_party",t,i.id,null,e,r).save(this.storage),s)return i;const u=n.SignerManager.fromStorage();try{await(u?.updateAuthentication())}catch(e){throw(e instanceof g.MissingRecoveryPasswordError||e instanceof g.MissingProjectEntropyError)&&await(u?.logout()),e}return i}async loginWithIdToken({provider:e,token:t,ecosystemGame:r}){const a=h.Authentication.fromStorage(this.storage),n=await this.authManager.loginWithIdToken(e,t,r);return a&&a.player!==n.player.id&&this.logout(),new h.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async initSIWE({address:e,ecosystemGame:t}){return await this.authManager.initSIWE(e,t)}async authenticateWithSIWE({signature:e,message:t,walletClientType:r,connectorType:a}){const n=h.Authentication.fromStorage(this.storage),o=await this.authManager.authenticateSIWE(e,t,r,a);return n&&n.player!==o.player.id&&this.logout(),new h.Authentication("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkWallet({signature:e,message:t,walletClientType:r,connectorType:a,authToken:n}){return await this.authManager.linkWallet(e,t,r,a,n)}async unlinkWallet({address:e,authToken:t}){return await this.authManager.unlinkWallet(e,t)}storeCredentials(e){if(this.storage.remove(r.StorageKeys.AUTHENTICATION),!e.player)throw new o.OpenfortError("Player ID is required to store credentials",o.OpenfortErrorType.INVALID_CONFIGURATION);new h.Authentication("jwt",e.accessToken,e.player,e.refreshToken).save(this.storage)}async sendSignatureTransactionIntentRequest(e,t=null,r=null,a=!1){if(!s.Configuration.fromStorage())throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);await this.validateAndRefreshToken();let i=r;if(!i){if(!t)throw new o.OpenfortError("No signableHash or signature provided",o.OpenfortErrorType.OPERATION_NOT_SUPPORTED_ERROR);const e=n.SignerManager.fromStorage();if(!e)throw new o.OpenfortError("In order to sign a transaction intent, a signer must be configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);i=await e.sign(t)}const u={id:e,signatureRequest:{signature:i,optimistic:a}};return(await this.backendApiClients.transactionIntentsApi.signature(u)).data}async getAccount(){const e=u.Account.fromStorage(this.storage);if(!e)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return{chainId:e.chainId,address:e.address,ownerAddress:e.ownerAddress,accountType:e.type}}get backendApiClients(){const t=s.Configuration.fromStorage();if(!t)throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);return new e.BackendApiClients({backend:e.createConfig({basePath:t.openfortURL,accessToken:t.publishableKey})})}async sendSignatureSessionRequest(e,t,r){const a={id:e,signatureRequest:{signature:t,optimistic:r}};return(await this.backendApiClients.sessionsApi.signatureSession(a)).data}getEmbeddedState(){if(!h.Authentication.fromStorage(this.storage))return i.EmbeddedState.UNAUTHENTICATED;const e=n.SignerManager.fromStorage();if(!e||"embedded"!==e.type())return i.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED;return u.Account.fromStorage(this.storage)?i.EmbeddedState.READY:i.EmbeddedState.CREATING_ACCOUNT}getAccessToken(){return h.Authentication.fromStorage(this.storage)?.token??null}get authManager(){if(!this.iAuthManager){const e=s.Configuration.fromStorage();if(!e)throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);this.iAuthManager=new d.AuthManager(e.publishableKey,e.openfortURL)}return this.iAuthManager}async getUser(){await this.validateAndRefreshToken();const e=h.Authentication.fromStorage(this.storage);if(!e)throw new o.OpenfortError("No access token found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.getUser(e)}async validateAndRefreshToken(e){const t=h.Authentication.fromStorage(this.storage);if(!t)throw new o.OpenfortError("Must be logged in to validate and refresh token",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);if("jwt"!==t.type)return;const r=await this.authManager.validateCredentials(t,e);if(!r.player)throw new o.OpenfortError("No player found in credentials",o.OpenfortErrorType.INTERNAL_ERROR);if(r.accessToken===t.token)return;new h.Authentication("jwt",r.accessToken,r.player,r.refreshToken).save(this.storage);const a=n.SignerManager.fromStorage();try{await(a?.updateAuthentication())}catch(e){throw(e instanceof g.MissingRecoveryPasswordError||e instanceof g.MissingProjectEntropyError)&&await(a?.logout()),e}}};
|
|
1
|
+
"use strict";var e=require("../../packages/internal/openapi-clients/dist/index.js"),t=require("./evm/walletHelpers.js"),r=require("./storage/istorage.js"),a=require("./storage/localStorage.js"),n=require("./manager/signer.js"),o=require("./errors/openfortError.js"),i=require("./types.js"),s=require("./configuration/configuration.js"),u=require("./configuration/account.js"),h=require("./configuration/authentication.js"),g=require("./iframe/iframeManager.js"),d=require("./authManager.js"),c=require("./evm/evmProvider.js");require("./evm/types.js");var l=require("./utils/typedEventEmitter.js"),p=require("./evm/provider/eip6963.js");exports.Openfort=class{storage;provider=null;iAuthManager=null;constructor(e){this.storage=new a.LocalStorage;new s.Configuration(e.baseConfiguration.publishableKey,e.overrides?.backendUrl||"https://api.openfort.xyz",e.shieldConfiguration?.shieldPublishableKey||"",e.shieldConfiguration?.shieldEncryptionKey||"",e.overrides?.shieldUrl||"https://shield.openfort.xyz",e.overrides?.iframeUrl||"https://embedded.openfort.xyz",e.shieldConfiguration?.debug||!1).save()}async logout(){const e=n.SignerManager.fromStorage();this.storage.remove(r.StorageKeys.AUTHENTICATION),this.storage.remove(r.StorageKeys.SIGNER),this.storage.remove(r.StorageKeys.ACCOUNT),e&&await e.logout()}getEthereumProvider(e){const t={announceProvider:!0,...e},r=h.Authentication.fromStorage(this.storage),a=n.SignerManager.fromStorage(),o=u.Account.fromStorage(this.storage);return this.provider?this.provider&&t.policy&&this.provider.updatePolicy(t.policy):(this.provider=new c.EvmProvider({storage:this.storage,openfortEventEmitter:new l,signer:a||void 0,account:o||void 0,authentication:r||void 0,backendApiClients:this.backendApiClients,policyId:t.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this)}),t.announceProvider&&p.announceProvider({info:{...p.openfortProviderInfo,...t.providerInfo},provider:this.provider})),this.provider}async configureEmbeddedSigner(e=null,t=null,r=null){await this.validateAndRefreshToken();const a=s.Configuration.fromStorage();let o=null;(r||t?.encryptionSession)&&(o={encryptionSession:t?.encryptionSession||null,recoveryPassword:r||null,encryptionPart:a?.shieldEncryptionKey||null});let i=null,u=null;t&&(i="openfort"===t.auth?"openfort":"custom",u=t.token),await n.SignerManager.embedded(e,o,i,u)}async signMessage(e,t){await this.validateAndRefreshToken();const r=n.SignerManager.fromStorage();if(!r)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);const{hashMessage:a=!0,arrayifyMessage:i=!1}=t||{};return await r.sign(e,i,a)}async signTypedData(e,r,a){await this.validateAndRefreshToken();const i=n.SignerManager.fromStorage(),s=u.Account.fromStorage(this.storage);if(!i||!s)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return await t.getSignedTypedData({domain:e,types:r,message:a},s.type,Number(s.chainId),i,s.address)}async exportPrivateKey(){await this.validateAndRefreshToken();const e=n.SignerManager.fromStorage();if(!e)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return await e.export()}async setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:t,encryptionSession:r}){await this.validateAndRefreshToken();const a=n.SignerManager.fromStorage();if(!a)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);if("embedded"!==a.type())throw new o.OpenfortError("Signer must be embedded",o.OpenfortErrorType.INVALID_CONFIGURATION);if("password"===e&&!t)throw new o.OpenfortError("Recovery password is required",o.OpenfortErrorType.INVALID_CONFIGURATION);await a.setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:t,encryptionSession:r})}async logInWithEmailPassword({email:e,password:t,ecosystemGame:r}){const a=h.Authentication.fromStorage(this.storage),n=await this.authManager.loginEmailPassword(e,t,r);return"action"in n||(a&&a.player!==n.player.id&&this.logout(),new h.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage)),n}async signUpGuest(){const e=h.Authentication.fromStorage(this.storage),t=await this.authManager.registerGuest();return e&&e.player!==t.player.id&&this.logout(),new h.Authentication("jwt",t.token,t.player.id,t.refreshToken).save(this.storage),t}async signUpWithEmailPassword({email:e,password:t,options:r,ecosystemGame:a}){const n=h.Authentication.fromStorage(this.storage),o=await this.authManager.signupEmailPassword(e,t,r?.data.name,a);return"action"in o||(n&&n.player!==o.player.id&&this.logout(),new h.Authentication("jwt",o.token,o.player.id,o.refreshToken).save(this.storage)),o}async linkEmailPassword({email:e,password:t,authToken:r,ecosystemGame:a}){return await this.authManager.linkEmail(e,t,r,a)}async unlinkEmailPassword({email:e,authToken:t}){return await this.authManager.unlinkEmail(e,t)}async requestEmailVerification({email:e,redirectUrl:t}){await this.authManager.requestEmailVerification(e,t)}async resetPassword({email:e,password:t,state:r}){await this.authManager.resetPassword(e,t,r)}async requestResetPassword({email:e,redirectUrl:t}){await this.authManager.requestResetPassword(e,t)}async verifyEmail({email:e,state:t}){await this.authManager.verifyEmail(e,t)}async initOAuth({provider:e,options:t,ecosystemGame:a}){return this.storage.remove(r.StorageKeys.AUTHENTICATION),await this.authManager.initOAuth(e,t,a)}async initLinkOAuth({provider:e,options:t,ecosystemGame:r}){const a=h.Authentication.fromStorage(this.storage);if(!a)throw new o.OpenfortError("No authentication found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(a,e,t,r)}async linkThirdPartyProvider({provider:e,token:t,tokenType:r}){const a=h.Authentication.fromStorage(this.storage);if(!a)throw new o.OpenfortError("No authentication found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.linkThirdParty(a,e,t,r)}async unlinkOAuth({provider:e,authToken:t}){return await this.authManager.unlinkOAuth(e,t)}async poolOAuth(e){const t=h.Authentication.fromStorage(this.storage),r=await this.authManager.poolOAuth(e);return t&&t.player!==r.player.id&&this.logout(),new h.Authentication("jwt",r.token,r.player.id,r.refreshToken).save(this.storage),r}async authenticateWithThirdPartyProvider({provider:e,token:t,tokenType:r,ecosystemGame:a}){const o=h.Authentication.fromStorage(this.storage),i=await this.authManager.authenticateThirdParty(e,t,r,a);let s=!1;if(o&&o.player!==i.id&&(this.logout(),s=!0),new h.Authentication("third_party",t,i.id,null,e,r).save(this.storage),s)return i;const u=n.SignerManager.fromStorage();try{await(u?.updateAuthentication())}catch(e){throw(e instanceof g.MissingRecoveryPasswordError||e instanceof g.MissingProjectEntropyError)&&await(u?.logout()),e}return i}async loginWithIdToken({provider:e,token:t,ecosystemGame:r}){const a=h.Authentication.fromStorage(this.storage),n=await this.authManager.loginWithIdToken(e,t,r);return a&&a.player!==n.player.id&&this.logout(),new h.Authentication("jwt",n.token,n.player.id,n.refreshToken).save(this.storage),n}async initSIWE({address:e,ecosystemGame:t}){return await this.authManager.initSIWE(e,t)}async authenticateWithSIWE({signature:e,message:t,walletClientType:r,connectorType:a}){const n=h.Authentication.fromStorage(this.storage),o=await this.authManager.authenticateSIWE(e,t,r,a);return n&&n.player!==o.player.id&&this.logout(),new h.Authentication("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async linkWallet({signature:e,message:t,walletClientType:r,connectorType:a,authToken:n}){return await this.authManager.linkWallet(e,t,r,a,n)}async unlinkWallet({address:e,authToken:t}){return await this.authManager.unlinkWallet(e,t)}storeCredentials(e){if(this.storage.remove(r.StorageKeys.AUTHENTICATION),!e.player)throw new o.OpenfortError("Player ID is required to store credentials",o.OpenfortErrorType.INVALID_CONFIGURATION);new h.Authentication("jwt",e.accessToken,e.player,e.refreshToken).save(this.storage)}async sendSignatureTransactionIntentRequest(e,t=null,r=null,a=!1){if(!s.Configuration.fromStorage())throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);await this.validateAndRefreshToken();let i=r;if(!i){if(!t)throw new o.OpenfortError("No signableHash or signature provided",o.OpenfortErrorType.OPERATION_NOT_SUPPORTED_ERROR);const e=n.SignerManager.fromStorage();if(!e)throw new o.OpenfortError("In order to sign a transaction intent, a signer must be configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);i=await e.sign(t)}const u={id:e,signatureRequest:{signature:i,optimistic:a}};return(await this.backendApiClients.transactionIntentsApi.signature(u)).data}async getAccount(){const e=u.Account.fromStorage(this.storage);if(!e)throw new o.OpenfortError("No signer configured",o.OpenfortErrorType.MISSING_SIGNER_ERROR);return{chainId:e.chainId,address:e.address,ownerAddress:e.ownerAddress,accountType:e.type}}get backendApiClients(){const t=s.Configuration.fromStorage();if(!t)throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);return new e.BackendApiClients({backend:e.createConfig({basePath:t.openfortURL,accessToken:t.publishableKey})})}async sendSignatureSessionRequest(e,t,r){const a={id:e,signatureRequest:{signature:t,optimistic:r}};return(await this.backendApiClients.sessionsApi.signatureSession(a)).data}getEmbeddedState(){if(!h.Authentication.fromStorage(this.storage))return i.EmbeddedState.UNAUTHENTICATED;const e=n.SignerManager.fromStorage();if(!e||"embedded"!==e.type())return i.EmbeddedState.EMBEDDED_SIGNER_NOT_CONFIGURED;return u.Account.fromStorage(this.storage)?i.EmbeddedState.READY:i.EmbeddedState.CREATING_ACCOUNT}getAccessToken(){return h.Authentication.fromStorage(this.storage)?.token??null}get authManager(){if(!this.iAuthManager){const e=s.Configuration.fromStorage();if(!e)throw new o.OpenfortError("Configuration not found",o.OpenfortErrorType.INVALID_CONFIGURATION);this.iAuthManager=new d.AuthManager(e.publishableKey,e.openfortURL)}return this.iAuthManager}async getUser(){await this.validateAndRefreshToken();const e=h.Authentication.fromStorage(this.storage);if(!e)throw new o.OpenfortError("No access token found",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);return await this.authManager.getUser(e)}async validateAndRefreshToken(e){const t=h.Authentication.fromStorage(this.storage);if(!t)throw new o.OpenfortError("Must be logged in to validate and refresh token",o.OpenfortErrorType.NOT_LOGGED_IN_ERROR);if("jwt"!==t.type)return;const r=await this.authManager.validateCredentials(t,e);if(!r.player)throw new o.OpenfortError("No player found in credentials",o.OpenfortErrorType.INTERNAL_ERROR);if(r.accessToken===t.token)return;new h.Authentication("jwt",r.accessToken,r.player,r.refreshToken).save(this.storage);const a=n.SignerManager.fromStorage();try{await(a?.updateAuthentication())}catch(e){throw(e instanceof g.MissingRecoveryPasswordError||e instanceof g.MissingProjectEntropyError)&&await(a?.logout()),e}}};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e,o,t,r,E,A,p,d,s;exports.EmbeddedState=void 0,(e=exports.EmbeddedState||(exports.EmbeddedState={}))[e.NONE=0]="NONE",e[e.UNAUTHENTICATED=1]="UNAUTHENTICATED",e[e.EMBEDDED_SIGNER_NOT_CONFIGURED=2]="EMBEDDED_SIGNER_NOT_CONFIGURED",e[e.CREATING_ACCOUNT=3]="CREATING_ACCOUNT",e[e.READY=4]="READY",exports.OpenfortEvents=void 0,(exports.OpenfortEvents||(exports.OpenfortEvents={})).LOGGED_OUT="loggedOut",exports.RecoveryMethod=void 0,(o=exports.RecoveryMethod||(exports.RecoveryMethod={})).PASSWORD="password",o.AUTOMATIC="automatic",exports.AccountType=void 0,(t=exports.AccountType||(exports.AccountType={})).UPGRADEABLE_V4="Upgradeable_v04",t.MANAGED_V4="Managed_v04",t.ERC6551_V4="ERC6551_v04",t.ERC6551_V5="ERC6551_v05",t.RECOVERABLE_V4="Recoverable_v04",t.MANAGED_V5="Managed_v05",t.UPGRADEABLE_V5="Upgradeable_v05",t.UPGRADEABLE_V6="Upgradeable_v06",t.ZKSYNC_UPGRADEABLE_V1="zksync_upgradeable_v1",t.ZKSYNC_UPGRADEABLE_V2="zksync_upgradeable_v2",exports.AuthType=void 0,(r=exports.AuthType||(exports.AuthType={})).OPENFORT="openfort",r.THIRD_PARTY="thirdParty",exports.TokenType=void 0,(E=exports.TokenType||(exports.TokenType={})).ID_TOKEN="idToken",E.CUSTOM_TOKEN="customToken",exports.ThirdPartyOAuthProvider=void 0,(A=exports.ThirdPartyOAuthProvider||(exports.ThirdPartyOAuthProvider={})).ACCELBYTE="accelbyte",A.FIREBASE="firebase",A.LOOTLOCKER="lootlocker",A.PLAYFAB="playfab",A.SUPABASE="supabase",A.CUSTOM="custom",A.OIDC="oidc",exports.BasicAuthProvider=void 0,(p=exports.BasicAuthProvider||(exports.BasicAuthProvider={})).EMAIL="email",p.WALLET="wallet",exports.OAuthProvider=void 0,(d=exports.OAuthProvider||(exports.OAuthProvider={})).GOOGLE="google",d.TWITTER="twitter",d.APPLE="apple",d.FACEBOOK="facebook",d.DISCORD="discord",d.EPIC_GAMES="epic_games",d.LINE="line",exports.CodeChallengeMethodEnum=void 0,(s=exports.CodeChallengeMethodEnum||(exports.CodeChallengeMethodEnum={})).PLAIN="plain",s.S256="S256";
|
|
1
|
+
"use strict";var e,o,t,r,E,A,p,d,s;exports.EmbeddedState=void 0,(e=exports.EmbeddedState||(exports.EmbeddedState={}))[e.NONE=0]="NONE",e[e.UNAUTHENTICATED=1]="UNAUTHENTICATED",e[e.EMBEDDED_SIGNER_NOT_CONFIGURED=2]="EMBEDDED_SIGNER_NOT_CONFIGURED",e[e.CREATING_ACCOUNT=3]="CREATING_ACCOUNT",e[e.READY=4]="READY",exports.OpenfortEvents=void 0,(exports.OpenfortEvents||(exports.OpenfortEvents={})).LOGGED_OUT="loggedOut",exports.RecoveryMethod=void 0,(o=exports.RecoveryMethod||(exports.RecoveryMethod={})).PASSWORD="password",o.AUTOMATIC="automatic",exports.AccountType=void 0,(t=exports.AccountType||(exports.AccountType={})).UPGRADEABLE_V4="Upgradeable_v04",t.MANAGED_V4="Managed_v04",t.ERC6551_V4="ERC6551_v04",t.ERC6551_V5="ERC6551_v05",t.RECOVERABLE_V4="Recoverable_v04",t.MANAGED_V5="Managed_v05",t.UPGRADEABLE_V5="Upgradeable_v05",t.UPGRADEABLE_V6="Upgradeable_v06",t.ZKSYNC_UPGRADEABLE_V1="zksync_upgradeable_v1",t.ZKSYNC_UPGRADEABLE_V2="zksync_upgradeable_v2",exports.AuthType=void 0,(r=exports.AuthType||(exports.AuthType={})).OPENFORT="openfort",r.THIRD_PARTY="thirdParty",exports.TokenType=void 0,(E=exports.TokenType||(exports.TokenType={})).ID_TOKEN="idToken",E.CUSTOM_TOKEN="customToken",exports.ThirdPartyOAuthProvider=void 0,(A=exports.ThirdPartyOAuthProvider||(exports.ThirdPartyOAuthProvider={})).ACCELBYTE="accelbyte",A.FIREBASE="firebase",A.LOOTLOCKER="lootlocker",A.PLAYFAB="playfab",A.SUPABASE="supabase",A.CUSTOM="custom",A.OIDC="oidc",exports.BasicAuthProvider=void 0,(p=exports.BasicAuthProvider||(exports.BasicAuthProvider={})).EMAIL="email",p.WALLET="wallet",exports.OAuthProvider=void 0,(d=exports.OAuthProvider||(exports.OAuthProvider={})).GOOGLE="google",d.TWITTER="twitter",d.APPLE="apple",d.FACEBOOK="facebook",d.DISCORD="discord",d.EPIC_GAMES="epic_games",d.LINE="line",exports.Actions=void 0,(exports.Actions||(exports.Actions={})).ACTION_VERIFY_EMAIL="verify_email",exports.CodeChallengeMethodEnum=void 0,(s=exports.CodeChallengeMethodEnum||(exports.CodeChallengeMethodEnum={})).PLAIN="plain",s.S256="S256";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.VERSION="0.8.
|
|
1
|
+
"use strict";exports.VERSION="0.8.40";
|
package/dist/index.d.ts
CHANGED
|
@@ -302,6 +302,12 @@ interface AuthResponse {
|
|
|
302
302
|
'token': string;
|
|
303
303
|
'refreshToken': string;
|
|
304
304
|
}
|
|
305
|
+
declare enum Actions {
|
|
306
|
+
ACTION_VERIFY_EMAIL = "verify_email"
|
|
307
|
+
}
|
|
308
|
+
interface ActionRequiredResponse {
|
|
309
|
+
action: Actions;
|
|
310
|
+
}
|
|
305
311
|
interface AccountAbstractionV6Details {
|
|
306
312
|
'userOperation': UserOperationV6;
|
|
307
313
|
'userOperationHash': string;
|
|
@@ -578,7 +584,7 @@ declare class Openfort {
|
|
|
578
584
|
email: string;
|
|
579
585
|
password: string;
|
|
580
586
|
ecosystemGame?: string;
|
|
581
|
-
}): Promise<AuthResponse>;
|
|
587
|
+
}): Promise<AuthResponse | ActionRequiredResponse>;
|
|
582
588
|
/**
|
|
583
589
|
* Registers a new guest user.
|
|
584
590
|
*
|
|
@@ -603,7 +609,7 @@ declare class Openfort {
|
|
|
603
609
|
};
|
|
604
610
|
};
|
|
605
611
|
ecosystemGame?: string;
|
|
606
|
-
}): Promise<AuthResponse>;
|
|
612
|
+
}): Promise<AuthResponse | ActionRequiredResponse>;
|
|
607
613
|
/**
|
|
608
614
|
* Links an email and password to an existing account using an authentication token.
|
|
609
615
|
*
|
|
@@ -618,7 +624,7 @@ declare class Openfort {
|
|
|
618
624
|
password: string;
|
|
619
625
|
authToken: string;
|
|
620
626
|
ecosystemGame?: string;
|
|
621
|
-
}): Promise<AuthPlayerResponse>;
|
|
627
|
+
}): Promise<AuthPlayerResponse | ActionRequiredResponse>;
|
|
622
628
|
/**
|
|
623
629
|
* Unlinks an email and password from an existing account using an authentication token.
|
|
624
630
|
*
|
package/dist/sdk/src/openfort.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{BackendApiClients as e,createConfig as t}from"../../packages/internal/openapi-clients/dist/index.js";import{getSignedTypedData as r}from"./evm/walletHelpers.js";import{StorageKeys as a}from"./storage/istorage.js";import{LocalStorage as o}from"./storage/localStorage.js";import{SignerManager as i}from"./manager/signer.js";import{OpenfortError as n,OpenfortErrorType as s}from"./errors/openfortError.js";import{EmbeddedState as h}from"./types.js";import{Configuration as d}from"./configuration/configuration.js";import{Account as u}from"./configuration/account.js";import{Authentication as g}from"./configuration/authentication.js";import{MissingRecoveryPasswordError as l,MissingProjectEntropyError as c}from"./iframe/iframeManager.js";import{AuthManager as f}from"./authManager.js";import{EvmProvider as p}from"./evm/evmProvider.js";import"./evm/types.js";import m from"./utils/typedEventEmitter.js";import{announceProvider as w,openfortProviderInfo as y}from"./evm/provider/eip6963.js";class R{storage;provider=null;iAuthManager=null;constructor(e){this.storage=new o;new d(e.baseConfiguration.publishableKey,e.overrides?.backendUrl||"https://api.openfort.xyz",e.shieldConfiguration?.shieldPublishableKey||"",e.shieldConfiguration?.shieldEncryptionKey||"",e.overrides?.shieldUrl||"https://shield.openfort.xyz",e.overrides?.iframeUrl||"https://embedded.openfort.xyz",e.shieldConfiguration?.debug||!1).save()}async logout(){const e=i.fromStorage();this.storage.remove(a.AUTHENTICATION),this.storage.remove(a.SIGNER),this.storage.remove(a.ACCOUNT),e&&await e.logout()}getEthereumProvider(e){const t={announceProvider:!0,...e},r=g.fromStorage(this.storage),a=i.fromStorage(),o=u.fromStorage(this.storage);return this.provider?this.provider&&t.policy&&this.provider.updatePolicy(t.policy):(this.provider=new p({storage:this.storage,openfortEventEmitter:new m,signer:a||void 0,account:o||void 0,authentication:r||void 0,backendApiClients:this.backendApiClients,policyId:t.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this)}),t.announceProvider&&w({info:{...y,...t.providerInfo},provider:this.provider})),this.provider}async configureEmbeddedSigner(e=null,t=null,r=null){await this.validateAndRefreshToken();const a=d.fromStorage();let o=null;(r||t?.encryptionSession)&&(o={encryptionSession:t?.encryptionSession||null,recoveryPassword:r||null,encryptionPart:a?.shieldEncryptionKey||null});let n=null,s=null;t&&(n="openfort"===t.auth?"openfort":"custom",s=t.token),await i.embedded(e,o,n,s)}async signMessage(e,t){await this.validateAndRefreshToken();const r=i.fromStorage();if(!r)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);const{hashMessage:a=!0,arrayifyMessage:o=!1}=t||{};return await r.sign(e,o,a)}async signTypedData(e,t,a){await this.validateAndRefreshToken();const o=i.fromStorage(),h=u.fromStorage(this.storage);if(!o||!h)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);return await r({domain:e,types:t,message:a},h.type,Number(h.chainId),o,h.address)}async exportPrivateKey(){await this.validateAndRefreshToken();const e=i.fromStorage();if(!e)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);return await e.export()}async setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:t,encryptionSession:r}){await this.validateAndRefreshToken();const a=i.fromStorage();if(!a)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);if("embedded"!==a.type())throw new n("Signer must be embedded",s.INVALID_CONFIGURATION);if("password"===e&&!t)throw new n("Recovery password is required",s.INVALID_CONFIGURATION);await a.setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:t,encryptionSession:r})}async logInWithEmailPassword({email:e,password:t,ecosystemGame:r}){const a=g.fromStorage(this.storage),o=await this.authManager.loginEmailPassword(e,t,r);return a&&a.player!==o.player.id&&this.logout(),new g("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async signUpGuest(){const e=g.fromStorage(this.storage),t=await this.authManager.registerGuest();return e&&e.player!==t.player.id&&this.logout(),new g("jwt",t.token,t.player.id,t.refreshToken).save(this.storage),t}async signUpWithEmailPassword({email:e,password:t,options:r,ecosystemGame:a}){const o=g.fromStorage(this.storage),i=await this.authManager.signupEmailPassword(e,t,r?.data.name,a);return o&&o.player!==i.player.id&&this.logout(),new g("jwt",i.token,i.player.id,i.refreshToken).save(this.storage),i}async linkEmailPassword({email:e,password:t,authToken:r,ecosystemGame:a}){return await this.authManager.linkEmail(e,t,r,a)}async unlinkEmailPassword({email:e,authToken:t}){return await this.authManager.unlinkEmail(e,t)}async requestEmailVerification({email:e,redirectUrl:t}){await this.authManager.requestEmailVerification(e,t)}async resetPassword({email:e,password:t,state:r}){await this.authManager.resetPassword(e,t,r)}async requestResetPassword({email:e,redirectUrl:t}){await this.authManager.requestResetPassword(e,t)}async verifyEmail({email:e,state:t}){await this.authManager.verifyEmail(e,t)}async initOAuth({provider:e,options:t,ecosystemGame:r}){return this.storage.remove(a.AUTHENTICATION),await this.authManager.initOAuth(e,t,r)}async initLinkOAuth({provider:e,options:t,ecosystemGame:r}){const a=g.fromStorage(this.storage);if(!a)throw new n("No authentication found",s.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(a,e,t,r)}async linkThirdPartyProvider({provider:e,token:t,tokenType:r}){const a=g.fromStorage(this.storage);if(!a)throw new n("No authentication found",s.NOT_LOGGED_IN_ERROR);return await this.authManager.linkThirdParty(a,e,t,r)}async unlinkOAuth({provider:e,authToken:t}){return await this.authManager.unlinkOAuth(e,t)}async poolOAuth(e){const t=g.fromStorage(this.storage),r=await this.authManager.poolOAuth(e);return t&&t.player!==r.player.id&&this.logout(),new g("jwt",r.token,r.player.id,r.refreshToken).save(this.storage),r}async authenticateWithThirdPartyProvider({provider:e,token:t,tokenType:r,ecosystemGame:a}){const o=g.fromStorage(this.storage),n=await this.authManager.authenticateThirdParty(e,t,r,a);let s=!1;if(o&&o.player!==n.id&&(this.logout(),s=!0),new g("third_party",t,n.id,null,e,r).save(this.storage),s)return n;const h=i.fromStorage();try{await(h?.updateAuthentication())}catch(e){throw(e instanceof l||e instanceof c)&&await(h?.logout()),e}return n}async loginWithIdToken({provider:e,token:t,ecosystemGame:r}){const a=g.fromStorage(this.storage),o=await this.authManager.loginWithIdToken(e,t,r);return a&&a.player!==o.player.id&&this.logout(),new g("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async initSIWE({address:e,ecosystemGame:t}){return await this.authManager.initSIWE(e,t)}async authenticateWithSIWE({signature:e,message:t,walletClientType:r,connectorType:a}){const o=g.fromStorage(this.storage),i=await this.authManager.authenticateSIWE(e,t,r,a);return o&&o.player!==i.player.id&&this.logout(),new g("jwt",i.token,i.player.id,i.refreshToken).save(this.storage),i}async linkWallet({signature:e,message:t,walletClientType:r,connectorType:a,authToken:o}){return await this.authManager.linkWallet(e,t,r,a,o)}async unlinkWallet({address:e,authToken:t}){return await this.authManager.unlinkWallet(e,t)}storeCredentials(e){if(this.storage.remove(a.AUTHENTICATION),!e.player)throw new n("Player ID is required to store credentials",s.INVALID_CONFIGURATION);new g("jwt",e.accessToken,e.player,e.refreshToken).save(this.storage)}async sendSignatureTransactionIntentRequest(e,t=null,r=null,a=!1){if(!d.fromStorage())throw new n("Configuration not found",s.INVALID_CONFIGURATION);await this.validateAndRefreshToken();let o=r;if(!o){if(!t)throw new n("No signableHash or signature provided",s.OPERATION_NOT_SUPPORTED_ERROR);const e=i.fromStorage();if(!e)throw new n("In order to sign a transaction intent, a signer must be configured",s.MISSING_SIGNER_ERROR);o=await e.sign(t)}const h={id:e,signatureRequest:{signature:o,optimistic:a}};return(await this.backendApiClients.transactionIntentsApi.signature(h)).data}async getAccount(){const e=u.fromStorage(this.storage);if(!e)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);return{chainId:e.chainId,address:e.address,ownerAddress:e.ownerAddress,accountType:e.type}}get backendApiClients(){const r=d.fromStorage();if(!r)throw new n("Configuration not found",s.INVALID_CONFIGURATION);return new e({backend:t({basePath:r.openfortURL,accessToken:r.publishableKey})})}async sendSignatureSessionRequest(e,t,r){const a={id:e,signatureRequest:{signature:t,optimistic:r}};return(await this.backendApiClients.sessionsApi.signatureSession(a)).data}getEmbeddedState(){if(!g.fromStorage(this.storage))return h.UNAUTHENTICATED;const e=i.fromStorage();if(!e||"embedded"!==e.type())return h.EMBEDDED_SIGNER_NOT_CONFIGURED;return u.fromStorage(this.storage)?h.READY:h.CREATING_ACCOUNT}getAccessToken(){return g.fromStorage(this.storage)?.token??null}get authManager(){if(!this.iAuthManager){const e=d.fromStorage();if(!e)throw new n("Configuration not found",s.INVALID_CONFIGURATION);this.iAuthManager=new f(e.publishableKey,e.openfortURL)}return this.iAuthManager}async getUser(){await this.validateAndRefreshToken();const e=g.fromStorage(this.storage);if(!e)throw new n("No access token found",s.NOT_LOGGED_IN_ERROR);return await this.authManager.getUser(e)}async validateAndRefreshToken(e){const t=g.fromStorage(this.storage);if(!t)throw new n("Must be logged in to validate and refresh token",s.NOT_LOGGED_IN_ERROR);if("jwt"!==t.type)return;const r=await this.authManager.validateCredentials(t,e);if(!r.player)throw new n("No player found in credentials",s.INTERNAL_ERROR);if(r.accessToken===t.token)return;new g("jwt",r.accessToken,r.player,r.refreshToken).save(this.storage);const a=i.fromStorage();try{await(a?.updateAuthentication())}catch(e){throw(e instanceof l||e instanceof c)&&await(a?.logout()),e}}}export{R as Openfort};
|
|
1
|
+
import{BackendApiClients as e,createConfig as t}from"../../packages/internal/openapi-clients/dist/index.js";import{getSignedTypedData as r}from"./evm/walletHelpers.js";import{StorageKeys as a}from"./storage/istorage.js";import{LocalStorage as o}from"./storage/localStorage.js";import{SignerManager as i}from"./manager/signer.js";import{OpenfortError as n,OpenfortErrorType as s}from"./errors/openfortError.js";import{EmbeddedState as h}from"./types.js";import{Configuration as d}from"./configuration/configuration.js";import{Account as u}from"./configuration/account.js";import{Authentication as g}from"./configuration/authentication.js";import{MissingRecoveryPasswordError as l,MissingProjectEntropyError as c}from"./iframe/iframeManager.js";import{AuthManager as f}from"./authManager.js";import{EvmProvider as p}from"./evm/evmProvider.js";import"./evm/types.js";import m from"./utils/typedEventEmitter.js";import{announceProvider as w,openfortProviderInfo as y}from"./evm/provider/eip6963.js";class R{storage;provider=null;iAuthManager=null;constructor(e){this.storage=new o;new d(e.baseConfiguration.publishableKey,e.overrides?.backendUrl||"https://api.openfort.xyz",e.shieldConfiguration?.shieldPublishableKey||"",e.shieldConfiguration?.shieldEncryptionKey||"",e.overrides?.shieldUrl||"https://shield.openfort.xyz",e.overrides?.iframeUrl||"https://embedded.openfort.xyz",e.shieldConfiguration?.debug||!1).save()}async logout(){const e=i.fromStorage();this.storage.remove(a.AUTHENTICATION),this.storage.remove(a.SIGNER),this.storage.remove(a.ACCOUNT),e&&await e.logout()}getEthereumProvider(e){const t={announceProvider:!0,...e},r=g.fromStorage(this.storage),a=i.fromStorage(),o=u.fromStorage(this.storage);return this.provider?this.provider&&t.policy&&this.provider.updatePolicy(t.policy):(this.provider=new p({storage:this.storage,openfortEventEmitter:new m,signer:a||void 0,account:o||void 0,authentication:r||void 0,backendApiClients:this.backendApiClients,policyId:t.policy,validateAndRefreshSession:this.validateAndRefreshToken.bind(this)}),t.announceProvider&&w({info:{...y,...t.providerInfo},provider:this.provider})),this.provider}async configureEmbeddedSigner(e=null,t=null,r=null){await this.validateAndRefreshToken();const a=d.fromStorage();let o=null;(r||t?.encryptionSession)&&(o={encryptionSession:t?.encryptionSession||null,recoveryPassword:r||null,encryptionPart:a?.shieldEncryptionKey||null});let n=null,s=null;t&&(n="openfort"===t.auth?"openfort":"custom",s=t.token),await i.embedded(e,o,n,s)}async signMessage(e,t){await this.validateAndRefreshToken();const r=i.fromStorage();if(!r)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);const{hashMessage:a=!0,arrayifyMessage:o=!1}=t||{};return await r.sign(e,o,a)}async signTypedData(e,t,a){await this.validateAndRefreshToken();const o=i.fromStorage(),h=u.fromStorage(this.storage);if(!o||!h)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);return await r({domain:e,types:t,message:a},h.type,Number(h.chainId),o,h.address)}async exportPrivateKey(){await this.validateAndRefreshToken();const e=i.fromStorage();if(!e)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);return await e.export()}async setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:t,encryptionSession:r}){await this.validateAndRefreshToken();const a=i.fromStorage();if(!a)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);if("embedded"!==a.type())throw new n("Signer must be embedded",s.INVALID_CONFIGURATION);if("password"===e&&!t)throw new n("Recovery password is required",s.INVALID_CONFIGURATION);await a.setEmbeddedRecovery({recoveryMethod:e,recoveryPassword:t,encryptionSession:r})}async logInWithEmailPassword({email:e,password:t,ecosystemGame:r}){const a=g.fromStorage(this.storage),o=await this.authManager.loginEmailPassword(e,t,r);return"action"in o||(a&&a.player!==o.player.id&&this.logout(),new g("jwt",o.token,o.player.id,o.refreshToken).save(this.storage)),o}async signUpGuest(){const e=g.fromStorage(this.storage),t=await this.authManager.registerGuest();return e&&e.player!==t.player.id&&this.logout(),new g("jwt",t.token,t.player.id,t.refreshToken).save(this.storage),t}async signUpWithEmailPassword({email:e,password:t,options:r,ecosystemGame:a}){const o=g.fromStorage(this.storage),i=await this.authManager.signupEmailPassword(e,t,r?.data.name,a);return"action"in i||(o&&o.player!==i.player.id&&this.logout(),new g("jwt",i.token,i.player.id,i.refreshToken).save(this.storage)),i}async linkEmailPassword({email:e,password:t,authToken:r,ecosystemGame:a}){return await this.authManager.linkEmail(e,t,r,a)}async unlinkEmailPassword({email:e,authToken:t}){return await this.authManager.unlinkEmail(e,t)}async requestEmailVerification({email:e,redirectUrl:t}){await this.authManager.requestEmailVerification(e,t)}async resetPassword({email:e,password:t,state:r}){await this.authManager.resetPassword(e,t,r)}async requestResetPassword({email:e,redirectUrl:t}){await this.authManager.requestResetPassword(e,t)}async verifyEmail({email:e,state:t}){await this.authManager.verifyEmail(e,t)}async initOAuth({provider:e,options:t,ecosystemGame:r}){return this.storage.remove(a.AUTHENTICATION),await this.authManager.initOAuth(e,t,r)}async initLinkOAuth({provider:e,options:t,ecosystemGame:r}){const a=g.fromStorage(this.storage);if(!a)throw new n("No authentication found",s.NOT_LOGGED_IN_ERROR);return await this.authManager.linkOAuth(a,e,t,r)}async linkThirdPartyProvider({provider:e,token:t,tokenType:r}){const a=g.fromStorage(this.storage);if(!a)throw new n("No authentication found",s.NOT_LOGGED_IN_ERROR);return await this.authManager.linkThirdParty(a,e,t,r)}async unlinkOAuth({provider:e,authToken:t}){return await this.authManager.unlinkOAuth(e,t)}async poolOAuth(e){const t=g.fromStorage(this.storage),r=await this.authManager.poolOAuth(e);return t&&t.player!==r.player.id&&this.logout(),new g("jwt",r.token,r.player.id,r.refreshToken).save(this.storage),r}async authenticateWithThirdPartyProvider({provider:e,token:t,tokenType:r,ecosystemGame:a}){const o=g.fromStorage(this.storage),n=await this.authManager.authenticateThirdParty(e,t,r,a);let s=!1;if(o&&o.player!==n.id&&(this.logout(),s=!0),new g("third_party",t,n.id,null,e,r).save(this.storage),s)return n;const h=i.fromStorage();try{await(h?.updateAuthentication())}catch(e){throw(e instanceof l||e instanceof c)&&await(h?.logout()),e}return n}async loginWithIdToken({provider:e,token:t,ecosystemGame:r}){const a=g.fromStorage(this.storage),o=await this.authManager.loginWithIdToken(e,t,r);return a&&a.player!==o.player.id&&this.logout(),new g("jwt",o.token,o.player.id,o.refreshToken).save(this.storage),o}async initSIWE({address:e,ecosystemGame:t}){return await this.authManager.initSIWE(e,t)}async authenticateWithSIWE({signature:e,message:t,walletClientType:r,connectorType:a}){const o=g.fromStorage(this.storage),i=await this.authManager.authenticateSIWE(e,t,r,a);return o&&o.player!==i.player.id&&this.logout(),new g("jwt",i.token,i.player.id,i.refreshToken).save(this.storage),i}async linkWallet({signature:e,message:t,walletClientType:r,connectorType:a,authToken:o}){return await this.authManager.linkWallet(e,t,r,a,o)}async unlinkWallet({address:e,authToken:t}){return await this.authManager.unlinkWallet(e,t)}storeCredentials(e){if(this.storage.remove(a.AUTHENTICATION),!e.player)throw new n("Player ID is required to store credentials",s.INVALID_CONFIGURATION);new g("jwt",e.accessToken,e.player,e.refreshToken).save(this.storage)}async sendSignatureTransactionIntentRequest(e,t=null,r=null,a=!1){if(!d.fromStorage())throw new n("Configuration not found",s.INVALID_CONFIGURATION);await this.validateAndRefreshToken();let o=r;if(!o){if(!t)throw new n("No signableHash or signature provided",s.OPERATION_NOT_SUPPORTED_ERROR);const e=i.fromStorage();if(!e)throw new n("In order to sign a transaction intent, a signer must be configured",s.MISSING_SIGNER_ERROR);o=await e.sign(t)}const h={id:e,signatureRequest:{signature:o,optimistic:a}};return(await this.backendApiClients.transactionIntentsApi.signature(h)).data}async getAccount(){const e=u.fromStorage(this.storage);if(!e)throw new n("No signer configured",s.MISSING_SIGNER_ERROR);return{chainId:e.chainId,address:e.address,ownerAddress:e.ownerAddress,accountType:e.type}}get backendApiClients(){const r=d.fromStorage();if(!r)throw new n("Configuration not found",s.INVALID_CONFIGURATION);return new e({backend:t({basePath:r.openfortURL,accessToken:r.publishableKey})})}async sendSignatureSessionRequest(e,t,r){const a={id:e,signatureRequest:{signature:t,optimistic:r}};return(await this.backendApiClients.sessionsApi.signatureSession(a)).data}getEmbeddedState(){if(!g.fromStorage(this.storage))return h.UNAUTHENTICATED;const e=i.fromStorage();if(!e||"embedded"!==e.type())return h.EMBEDDED_SIGNER_NOT_CONFIGURED;return u.fromStorage(this.storage)?h.READY:h.CREATING_ACCOUNT}getAccessToken(){return g.fromStorage(this.storage)?.token??null}get authManager(){if(!this.iAuthManager){const e=d.fromStorage();if(!e)throw new n("Configuration not found",s.INVALID_CONFIGURATION);this.iAuthManager=new f(e.publishableKey,e.openfortURL)}return this.iAuthManager}async getUser(){await this.validateAndRefreshToken();const e=g.fromStorage(this.storage);if(!e)throw new n("No access token found",s.NOT_LOGGED_IN_ERROR);return await this.authManager.getUser(e)}async validateAndRefreshToken(e){const t=g.fromStorage(this.storage);if(!t)throw new n("Must be logged in to validate and refresh token",s.NOT_LOGGED_IN_ERROR);if("jwt"!==t.type)return;const r=await this.authManager.validateCredentials(t,e);if(!r.player)throw new n("No player found in credentials",s.INTERNAL_ERROR);if(r.accessToken===t.token)return;new g("jwt",r.accessToken,r.player,r.refreshToken).save(this.storage);const a=i.fromStorage();try{await(a?.updateAuthentication())}catch(e){throw(e instanceof l||e instanceof c)&&await(a?.logout()),e}}}export{R as Openfort};
|
package/dist/sdk/src/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var E,A,_,e,a,o,T,
|
|
1
|
+
var E,A,_,e,a,n,o,T,O,R,C;!function(E){E[E.NONE=0]="NONE",E[E.UNAUTHENTICATED=1]="UNAUTHENTICATED",E[E.EMBEDDED_SIGNER_NOT_CONFIGURED=2]="EMBEDDED_SIGNER_NOT_CONFIGURED",E[E.CREATING_ACCOUNT=3]="CREATING_ACCOUNT",E[E.READY=4]="READY"}(E||(E={})),function(E){E.LOGGED_OUT="loggedOut"}(A||(A={})),function(E){E.PASSWORD="password",E.AUTOMATIC="automatic"}(_||(_={})),function(E){E.UPGRADEABLE_V4="Upgradeable_v04",E.MANAGED_V4="Managed_v04",E.ERC6551_V4="ERC6551_v04",E.ERC6551_V5="ERC6551_v05",E.RECOVERABLE_V4="Recoverable_v04",E.MANAGED_V5="Managed_v05",E.UPGRADEABLE_V5="Upgradeable_v05",E.UPGRADEABLE_V6="Upgradeable_v06",E.ZKSYNC_UPGRADEABLE_V1="zksync_upgradeable_v1",E.ZKSYNC_UPGRADEABLE_V2="zksync_upgradeable_v2"}(e||(e={})),function(E){E.OPENFORT="openfort",E.THIRD_PARTY="thirdParty"}(a||(a={})),function(E){E.ID_TOKEN="idToken",E.CUSTOM_TOKEN="customToken"}(n||(n={})),function(E){E.ACCELBYTE="accelbyte",E.FIREBASE="firebase",E.LOOTLOCKER="lootlocker",E.PLAYFAB="playfab",E.SUPABASE="supabase",E.CUSTOM="custom",E.OIDC="oidc"}(o||(o={})),function(E){E.EMAIL="email",E.WALLET="wallet"}(T||(T={})),function(E){E.GOOGLE="google",E.TWITTER="twitter",E.APPLE="apple",E.FACEBOOK="facebook",E.DISCORD="discord",E.EPIC_GAMES="epic_games",E.LINE="line"}(O||(O={})),function(E){E.ACTION_VERIFY_EMAIL="verify_email"}(R||(R={})),function(E){E.PLAIN="plain",E.S256="S256"}(C||(C={}));export{e as AccountType,R as Actions,a as AuthType,T as BasicAuthProvider,C as CodeChallengeMethodEnum,E as EmbeddedState,O as OAuthProvider,A as OpenfortEvents,_ as RecoveryMethod,o as ThirdPartyOAuthProvider,n as TokenType};
|
package/dist/sdk/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.8.
|
|
1
|
+
const o="0.8.40";export{o as VERSION};
|
package/package.json
CHANGED