@openfort/openfort-js 1.3.6 → 1.3.8
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.
- package/dist/cjs/sdk/src/core/errors/sentry.cjs +1 -1
- package/dist/cjs/sdk/src/index.cjs +1 -1
- package/dist/cjs/sdk/src/version.cjs +1 -1
- package/dist/cjs/sdk/src/wallets/iframeManager.cjs +1 -1
- package/dist/cjs/sdk/src/wallets/messaging/browserMessenger/connectRemoteProxy.cjs +1 -1
- package/dist/index.d.cts +34 -1
- package/dist/index.d.ts +34 -1
- package/dist/sdk/src/core/errors/sentry.js +1 -1
- package/dist/sdk/src/index.js +1 -1
- package/dist/sdk/src/version.js +1 -1
- package/dist/sdk/src/wallets/iframeManager.js +1 -1
- package/dist/sdk/src/wallets/messaging/browserMessenger/connectRemoteProxy.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("axios"),t=require("../../version.cjs");const r="https://64a03e4967fb4dad3ecb914918c777b6@o4504593015242752.ingest.us.sentry.io/4509292415287296";class s{static sentryInstance;static queuedCalls=[];static baseTags;static set sentry(t){const n=t.getDsn();if(!n)throw new Error("Sentry DSN is not set");if(n.projectId!==r.split("https://")[1].split("/")[1]||n.host!==r.split("@")[1].split("/")[0]||n.publicKey!==r.split("@")[0].split("https://")[1])throw new Error("Sentry DSN is not valid");t.captureAxiosError=(r,n,o,a)=>{if(n instanceof e.AxiosError){if(400===n.response?.status||401===n.response?.status)return;n.name=r,t.captureException(n,{...o,captureContext:{...o?.captureContext,extra:{errorResponseData:n.response?.data,errorStatus:n.response?.status,errorHeaders:n.response?.headers,errorRequest:n.request},tags:{...s.baseTags,method:r}}})}else t.captureException(n,o,a)},t.captureError=(e,r,n,o)=>{const a=r.statusCode;if(400===a||401===a)return;const c=r,i=c.error,u=c.error_description,p=n?.captureContext;t.captureException(r,{...n,captureContext:{...p,extra:{...p?.extra,errorCode:i,errorDescription:u,errorClass:r.constructor.name,...c.statusCode&&{statusCode:c.statusCode},...c.audience&&{audience:c.audience},...c.scope&&{scope:c.scope},...c.accountId&&{accountId:c.accountId},...c.userId&&{userId:c.userId},...c.provider&&{provider:c.provider},...c.recoveryMethod&&{recoveryMethod:c.recoveryMethod}},tags:{...s.baseTags,context:e,errorClass:r.constructor.name}}})},s.sentryInstance=t}static get sentry(){return s.proxy}static async init({sentry:e,configuration:n}){if(e)return void(s.sentry=e);const o=await import("@sentry/browser");s.sentry=new o.BrowserClient({dsn:r,integrations:[],stackParser:o.defaultStackParser,transport:o.makeFetchTransport}),s.baseTags={projectId:n?.baseConfiguration.publishableKey??"",sdk:t.PACKAGE,sdkVersion:t.VERSION},s.processQueuedCalls()}static proxy=new Proxy({},{get:(e,t)=>s.sentryInstance&&"function"==typeof s.sentryInstance[t]?(...e)=>s.sentryInstance[t](...e):(...e)=>{s.queuedCalls.push({fn:t,args:e})}});static processQueuedCalls(){s.sentryInstance&&(s.queuedCalls.forEach(({fn:e,args:t})=>{"function"==typeof s.sentryInstance[e]&&s.sentryInstance[e](...t)}),s.queuedCalls=[])}}const{sentry:n}=s;exports.InternalSentry=s,exports.sentry=n;
|
|
1
|
+
"use strict";var e=require("axios"),t=require("../../version.cjs");const r="https://64a03e4967fb4dad3ecb914918c777b6@o4504593015242752.ingest.us.sentry.io/4509292415287296";class s{static sentryInstance;static queuedCalls=[];static baseTags;static set sentry(t){const n=t.getDsn();if(!n)throw new Error("Sentry DSN is not set");if(n.projectId!==r.split("https://")[1].split("/")[1]||n.host!==r.split("@")[1].split("/")[0]||n.publicKey!==r.split("@")[0].split("https://")[1])throw new Error("Sentry DSN is not valid");t.captureAxiosError=(r,n,o,a)=>{if(n instanceof e.AxiosError){if(400===n.response?.status||401===n.response?.status)return;n.name=r,t.captureException(n,{...o,captureContext:{...o?.captureContext,extra:{errorResponseData:n.response?.data,errorStatus:n.response?.status,errorHeaders:n.response?.headers,errorRequest:n.request},tags:{...s.baseTags,method:r}}})}else t.captureException(n,o,a)},t.captureError=(e,r,n,o)=>{const a=r.statusCode;if(400===a||401===a)return;const c=r,i=c.error,u=c.error_description,p=n?.captureContext;t.captureException(r,{...n,captureContext:{...p,extra:{...p?.extra,errorCode:i,errorDescription:u,errorClass:r.constructor.name,...c.statusCode&&{statusCode:c.statusCode},...c.audience&&{audience:c.audience},...c.scope&&{scope:c.scope},...c.accountId&&{accountId:c.accountId},...c.userId&&{userId:c.userId},...c.provider&&{provider:c.provider},...c.recoveryMethod&&{recoveryMethod:c.recoveryMethod}},tags:{...s.baseTags,context:e,errorClass:r.constructor.name}}})},s.sentryInstance=t}static get sentry(){return s.proxy}static async init({sentry:e,configuration:n}){if(e)return void(s.sentry=e);const o=await import("@sentry/browser");s.sentry=new o.BrowserClient({dsn:r,release:`${t.PACKAGE}@${t.VERSION}`,integrations:[],stackParser:o.defaultStackParser,transport:o.makeFetchTransport}),s.baseTags={projectId:n?.baseConfiguration.publishableKey??"",sdk:t.PACKAGE,sdkVersion:t.VERSION},s.processQueuedCalls()}static proxy=new Proxy({},{get:(e,t)=>s.sentryInstance&&"function"==typeof s.sentryInstance[t]?(...e)=>s.sentryInstance[t](...e):(...e)=>{s.queuedCalls.push({fn:t,args:e})}});static processQueuedCalls(){s.sentryInstance&&(s.queuedCalls.forEach(({fn:e,args:t})=>{"function"==typeof s.sentryInstance[e]&&s.sentryInstance[e](...t)}),s.queuedCalls=[])}}const{sentry:n}=s;exports.InternalSentry=s,exports.sentry=n;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var r=require("./core/openfort.cjs"),e=require("./api/auth.cjs"),o=require("./api/embeddedWallet.cjs"),t=require("./api/proxy.cjs"),s=require("./api/user.cjs"),n=require("./core/errors/authErrorCodes.cjs"),i=require("./core/errors/openfortError.cjs"),p=require("./core/passkey/errors.cjs"),u=require("./core/passkey/handler.cjs"),a=require("./core/passkey/utils.cjs"),E=require("./core/config/config.cjs"),c=require("./core/openfortInternal.cjs"),d=require("./utils/authorization.cjs"),f=require("./wallets/iframeManager.cjs"),y=require("./types/types.cjs"),x=require("./utils/crypto.cjs");const P=r.Openfort.getEventEmitter();exports.Openfort=r.Openfort,exports.AuthApi=e.AuthApi,exports.EmbeddedWalletApi=o.EmbeddedWalletApi,exports.ProxyApi=t.ProxyApi,exports.UserApi=s.UserApi,exports.OPENFORT_AUTH_ERROR_CODES=n.OPENFORT_AUTH_ERROR_CODES,exports.OPENFORT_ERROR_CODES=n.OPENFORT_ERROR_CODES,exports.AuthenticationError=i.AuthenticationError,exports.AuthorizationError=i.AuthorizationError,exports.ConfigurationError=i.ConfigurationError,exports.OAuthError=i.OAuthError,exports.OTPError=i.OTPError,exports.OpenfortError=i.OpenfortError,exports.RecoveryError=i.RecoveryError,exports.RequestError=i.RequestError,exports.SessionError=i.SessionError,exports.SignerError=i.SignerError,exports.UserError=i.UserError,exports.PASSKEY_ERROR_CODES=p.PASSKEY_ERROR_CODES,exports.PasskeyAssertionFailedError=p.PasskeyAssertionFailedError,exports.PasskeyCreationFailedError=p.PasskeyCreationFailedError,exports.PasskeyPRFNotSupportedError=p.PasskeyPRFNotSupportedError,exports.PasskeySeedInvalidError=p.PasskeySeedInvalidError,exports.PasskeyUserCancelledError=p.PasskeyUserCancelledError,exports.PasskeyHandler=u.PasskeyHandler,exports.arrayBufferToBase64URL=a.arrayBufferToBase64URL,exports.base64ToArrayBuffer=a.base64ToArrayBuffer,exports.OpenfortConfiguration=E.OpenfortConfiguration,exports.SDKConfiguration=E.SDKConfiguration,exports.ShieldConfiguration=E.ShieldConfiguration,exports.OpenfortInternal=c.OpenfortInternal,exports.prepareAndSignAuthorization=d.prepareAndSignAuthorization,exports.serializeSignedAuthorization=d.serializeSignedAuthorization,exports.signAuthorization=d.signAuthorization,exports.MissingProjectEntropyError=f.MissingProjectEntropyError,exports.MissingRecoveryPasswordError=f.MissingRecoveryPasswordError,exports.NotConfiguredError=f.NotConfiguredError,exports.OTPRequiredError=f.OTPRequiredError,exports.SessionEndedBeforeSetupError=f.SessionEndedBeforeSetupError,exports.WrongPasskeyError=f.WrongPasskeyError,exports.WrongRecoveryPasswordError=f.WrongRecoveryPasswordError,Object.defineProperty(exports,"AccountTypeEnum",{enumerable:!0,get:function(){return y.AccountTypeEnum}}),Object.defineProperty(exports,"AuthActionRequiredActions",{enumerable:!0,get:function(){return y.AuthActionRequiredActions}}),Object.defineProperty(exports,"AuthType",{enumerable:!0,get:function(){return y.AuthType}}),Object.defineProperty(exports,"BasicAuthProvider",{enumerable:!0,get:function(){return y.BasicAuthProvider}}),Object.defineProperty(exports,"ChainTypeEnum",{enumerable:!0,get:function(){return y.ChainTypeEnum}}),Object.defineProperty(exports,"EmbeddedState",{enumerable:!0,get:function(){return y.EmbeddedState}}),Object.defineProperty(exports,"OAuthProvider",{enumerable:!0,get:function(){return y.OAuthProvider}}),Object.defineProperty(exports,"OpenfortEvents",{enumerable:!0,get:function(){return y.OpenfortEvents}}),Object.defineProperty(exports,"RecoveryMethod",{enumerable:!0,get:function(){return y.RecoveryMethod}}),Object.defineProperty(exports,"ThirdPartyOAuthProvider",{enumerable:!0,get:function(){return y.ThirdPartyAuthProvider}}),Object.defineProperty(exports,"TokenType",{enumerable:!0,get:function(){return y.TokenType}}),exports.cryptoDigest=x.cryptoDigest,exports.openfortEvents=P;
|
|
1
|
+
"use strict";var r=require("./core/openfort.cjs"),e=require("./api/auth.cjs"),o=require("./api/embeddedWallet.cjs"),t=require("./api/proxy.cjs"),s=require("./api/user.cjs"),n=require("./core/errors/authErrorCodes.cjs"),i=require("./core/errors/openfortError.cjs"),p=require("./core/passkey/errors.cjs"),u=require("./core/passkey/handler.cjs"),a=require("./core/passkey/utils.cjs"),E=require("./core/config/config.cjs"),c=require("./core/openfortInternal.cjs"),d=require("./utils/authorization.cjs"),f=require("./wallets/iframeManager.cjs"),y=require("./types/types.cjs"),x=require("./utils/crypto.cjs");const P=r.Openfort.getEventEmitter();exports.Openfort=r.Openfort,exports.AuthApi=e.AuthApi,exports.EmbeddedWalletApi=o.EmbeddedWalletApi,exports.ProxyApi=t.ProxyApi,exports.UserApi=s.UserApi,exports.OPENFORT_AUTH_ERROR_CODES=n.OPENFORT_AUTH_ERROR_CODES,exports.OPENFORT_ERROR_CODES=n.OPENFORT_ERROR_CODES,exports.AuthenticationError=i.AuthenticationError,exports.AuthorizationError=i.AuthorizationError,exports.ConfigurationError=i.ConfigurationError,exports.OAuthError=i.OAuthError,exports.OTPError=i.OTPError,exports.OpenfortError=i.OpenfortError,exports.RecoveryError=i.RecoveryError,exports.RequestError=i.RequestError,exports.SessionError=i.SessionError,exports.SignerError=i.SignerError,exports.UserError=i.UserError,exports.PASSKEY_ERROR_CODES=p.PASSKEY_ERROR_CODES,exports.PasskeyAssertionFailedError=p.PasskeyAssertionFailedError,exports.PasskeyCreationFailedError=p.PasskeyCreationFailedError,exports.PasskeyPRFNotSupportedError=p.PasskeyPRFNotSupportedError,exports.PasskeySeedInvalidError=p.PasskeySeedInvalidError,exports.PasskeyUserCancelledError=p.PasskeyUserCancelledError,exports.PasskeyHandler=u.PasskeyHandler,exports.arrayBufferToBase64URL=a.arrayBufferToBase64URL,exports.base64ToArrayBuffer=a.base64ToArrayBuffer,exports.OpenfortConfiguration=E.OpenfortConfiguration,exports.SDKConfiguration=E.SDKConfiguration,exports.ShieldConfiguration=E.ShieldConfiguration,exports.OpenfortInternal=c.OpenfortInternal,exports.prepareAndSignAuthorization=d.prepareAndSignAuthorization,exports.serializeSignedAuthorization=d.serializeSignedAuthorization,exports.signAuthorization=d.signAuthorization,exports.IframeHandshakeTimeoutError=f.IframeHandshakeTimeoutError,exports.IframeSignEmptyResponseError=f.IframeSignEmptyResponseError,exports.IframeSignTimeoutError=f.IframeSignTimeoutError,exports.MissingProjectEntropyError=f.MissingProjectEntropyError,exports.MissingRecoveryPasswordError=f.MissingRecoveryPasswordError,exports.NotConfiguredError=f.NotConfiguredError,exports.OTPRequiredError=f.OTPRequiredError,exports.SessionEndedBeforeSetupError=f.SessionEndedBeforeSetupError,exports.WrongPasskeyError=f.WrongPasskeyError,exports.WrongRecoveryPasswordError=f.WrongRecoveryPasswordError,Object.defineProperty(exports,"AccountTypeEnum",{enumerable:!0,get:function(){return y.AccountTypeEnum}}),Object.defineProperty(exports,"AuthActionRequiredActions",{enumerable:!0,get:function(){return y.AuthActionRequiredActions}}),Object.defineProperty(exports,"AuthType",{enumerable:!0,get:function(){return y.AuthType}}),Object.defineProperty(exports,"BasicAuthProvider",{enumerable:!0,get:function(){return y.BasicAuthProvider}}),Object.defineProperty(exports,"ChainTypeEnum",{enumerable:!0,get:function(){return y.ChainTypeEnum}}),Object.defineProperty(exports,"EmbeddedState",{enumerable:!0,get:function(){return y.EmbeddedState}}),Object.defineProperty(exports,"OAuthProvider",{enumerable:!0,get:function(){return y.OAuthProvider}}),Object.defineProperty(exports,"OpenfortEvents",{enumerable:!0,get:function(){return y.OpenfortEvents}}),Object.defineProperty(exports,"RecoveryMethod",{enumerable:!0,get:function(){return y.RecoveryMethod}}),Object.defineProperty(exports,"ThirdPartyOAuthProvider",{enumerable:!0,get:function(){return y.ThirdPartyAuthProvider}}),Object.defineProperty(exports,"TokenType",{enumerable:!0,get:function(){return y.TokenType}}),exports.cryptoDigest=x.cryptoDigest,exports.openfortEvents=P;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.3.
|
|
1
|
+
"use strict";exports.PACKAGE="@openfort/openfort-js",exports.VERSION="1.3.8";
|
|
@@ -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 l extends t.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.INCORRECT_PASSKEY,"Wrong recovery passkey for this embedded signer","passkey")}}class g extends t.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.MISSING_PROJECT_ENTROPY,"Project entropy is missing","entropy")}}class y extends t.RecoveryError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.WRONG_RECOVERY_PASSWORD,"Wrong recovery password for this embedded signer","password")}}class p extends t.SignerError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.NOT_CONFIGURED,"Signer is not configured")}}class R extends t.OpenfortError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.OTP_REQUIRED,"OTP verification required")}}class f extends t.OpenfortError{constructor(){super(r.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Wallet session ended before setup completed."),Object.setPrototypeOf(this,f.prototype)}}exports.IframeManager=class{messenger;connection;remote;storage;sdkConfiguration;isInitialized=!1;initializationPromise=null;isDestroyed=!1;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}assertAlive(){if(this.isDestroyed)throw new f}async initialize(){if(this.assertAlive(),!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)return await this.initializationPromise,void this.assertAlive();this.initializationPromise=this.doInitialize();try{await this.initializationPromise,this.assertAlive(),this.isInitialized=!0}catch(e){if(this.initializationPromise=null,e instanceof f)throw e;throw this.hasFailed=!0,e}}}async doInitialize(){a.debugLog("Initializing IframeManager connection..."),this.assertAlive(),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,this.assertAlive(),a.debugLog("IframeManager connection established")}catch(e){this.isDestroyed&&a.debugLog("Connection rejected after destroy() — surfacing teardown error"),this.assertAlive();const i=e;throw n.sentry.captureException(i),this.clearConnection(),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 `)}}clearConnection(){if(this.connection)try{this.connection.destroy()}catch(e){a.debugLog("clearConnection: connection.destroy() threw, swallowing:",e)}this.remote=void 0,this.isInitialized=!1,this.connection=void 0,this.initializationPromise=null}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 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 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 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 t={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},n=await i.import(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 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 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.isDestroyed||(this.isDestroyed=!0,this.clearConnection())}},exports.MissingProjectEntropyError=g,exports.MissingRecoveryPasswordError=h,exports.NotConfiguredError=p,exports.OTPRequiredError=R,exports.SessionEndedBeforeSetupError=f,exports.WrongPasskeyError=l,exports.WrongRecoveryPasswordError=y;
|
|
1
|
+
"use strict";var e=require("../core/configuration/account.cjs"),r=require("../core/configuration/authentication.cjs"),i=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/CallOptions.cjs"),h=require("./messaging/browserMessenger/connect.cjs");require("./messaging/browserMessenger/backwardCompatibility.cjs");var u=require("./messaging/browserMessenger/PenpalError.cjs"),l=require("./types.cjs");class g extends t.RecoveryError{constructor(){super(i.OPENFORT_AUTH_ERROR_CODES.MISSING_RECOVERY_PASSWORD,"This embedded signer requires a password to be recovered","password")}}class p extends t.RecoveryError{constructor(){super(i.OPENFORT_AUTH_ERROR_CODES.INCORRECT_PASSKEY,"Wrong recovery passkey for this embedded signer","passkey")}}class y extends t.RecoveryError{constructor(){super(i.OPENFORT_AUTH_ERROR_CODES.MISSING_PROJECT_ENTROPY,"Project entropy is missing","entropy")}}class R extends t.RecoveryError{constructor(){super(i.OPENFORT_AUTH_ERROR_CODES.WRONG_RECOVERY_PASSWORD,"Wrong recovery password for this embedded signer","password")}}class f extends t.SignerError{constructor(){super(i.OPENFORT_AUTH_ERROR_CODES.NOT_CONFIGURED,"Signer is not configured")}}class E extends t.OpenfortError{constructor(){super(i.OPENFORT_AUTH_ERROR_CODES.OTP_REQUIRED,"OTP verification required")}}class O extends t.SignerError{constructor(e){super(i.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,`Iframe signer did not respond within ${e}ms. The signing prompt may have been dismissed or the iframe is unresponsive.`),this.name="IframeSignTimeoutError",Object.setPrototypeOf(this,O.prototype)}}class w extends t.SignerError{constructor(){super(i.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Iframe signer returned an empty signature."),this.name="IframeSignEmptyResponseError",Object.setPrototypeOf(this,w.prototype)}}class m extends t.OpenfortError{constructor(){super(i.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Wallet session ended before setup completed."),Object.setPrototypeOf(this,m.prototype)}}class C extends t.OpenfortError{constructor(e,r){super(i.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,`Failed to establish iframe connection within ${e}ms. The embedded wallet page did not respond — it may be unreachable or blocked by CSP/network.`),this.name="IframeHandshakeTimeoutError",this.cause=r,Object.setPrototypeOf(this,C.prototype)}}exports.IframeHandshakeTimeoutError=C,exports.IframeManager=class{messenger;connection;remote;storage;sdkConfiguration;isInitialized=!1;initializationPromise=null;isDestroyed=!1;hasFailed=!1;constructor(e,r,i){if(!e)throw new t.ConfigurationError("Configuration is required for IframeManager");if(!r)throw new t.ConfigurationError("Storage is required for IframeManager");if(!i)throw new t.ConfigurationError("Messenger is required for IframeManager");this.sdkConfiguration=e,this.storage=r,this.messenger=i}assertAlive(){if(this.isDestroyed)throw new m}async initialize(){if(this.assertAlive(),!this.isInitialized){if(this.hasFailed)throw new t.OpenfortError(i.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Failed to establish iFrame connection: Previous connection attempt failed");if(this.initializationPromise)return await this.initializationPromise,void this.assertAlive();this.initializationPromise=this.doInitialize();try{await this.initializationPromise,this.assertAlive(),this.isInitialized=!0}catch(e){if(this.initializationPromise=null,e instanceof m)throw e;throw this.hasFailed=!0,e}}}async doInitialize(){a.debugLog("Initializing IframeManager connection..."),this.assertAlive(),this.messenger.initialize({validateReceivedMessage:e=>!(!e||"object"!=typeof e),log:a.debugLog}),this.connection=h({messenger:this.messenger,timeout:1e4,log:a.debugLog});try{this.remote=await this.connection.promise,this.assertAlive(),a.debugLog("IframeManager connection established")}catch(e){if(this.isDestroyed&&a.debugLog("Connection rejected after destroy() — surfacing teardown error"),this.assertAlive(),n.sentry.captureException(e),this.clearConnection(),a.debugLog("Failed to establish connection:",e),e instanceof u&&"CONNECTION_TIMEOUT"===e.code)throw new C(1e4,e);const r=e;throw new t.OpenfortError(i.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,`Failed to establish iFrame connection: ${r.cause||r.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 `)}}clearConnection(){if(this.connection)try{this.connection.destroy()}catch(e){a.debugLog("clearConnection: connection.destroy() threw, swallowing:",e)}this.remote=void 0,this.isInitialized=!1,this.connection=void 0,this.initializationPromise=null}async ensureConnection(){if(this.isInitialized&&this.remote||await this.initialize(),!this.remote)throw new t.OpenfortError(i.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,"Failed to establish connection");return this.remote}handleError(e){if(l.isErrorResponse(e)){if(e.error===l.NOT_CONFIGURED_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new f;if(e.error===l.MISSING_USER_ENTROPY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new g;if(e.error===l.MISSING_PROJECT_ENTROPY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new y;if(e.error===l.INCORRECT_USER_ENTROPY_ERROR)throw new R;if(e.error===l.MISSING_PASSKEY_ERROR)throw this.storage.remove(o.StorageKeys.ACCOUNT),new g;if(e.error===l.INCORRECT_PASSKEY_ERROR)throw new p;if(e.error===l.OTP_REQUIRED_ERROR)throw new E;throw this.storage.remove(o.StorageKeys.ACCOUNT),new t.OpenfortError(i.OPENFORT_AUTH_ERROR_CODES.INTERNAL_ERROR,`Unknown error: ${e.error}`)}throw e}async buildRequestConfiguration(){const e=await r.Authentication.fromStorage(this.storage);if(!e)throw new t.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"Must be authenticated to create a signer");const n={auth:l.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 r.Authentication.fromStorage(this.storage);if(!e)throw new t.SessionError(i.OPENFORT_AUTH_ERROR_CODES.NOT_LOGGED_IN,"Must be authenticated to create a signer");const n={auth:l.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 r=await this.ensureConnection(),i=await this.buildIFrameRequestConfiguration();i.chainId=e.chainId??null,i.password=e?.entropy?.recoveryPassword??null,i.recovery={...i.recovery,encryptionSession:e?.entropy?.encryptionSession},i.passkey=e?.entropy?.passkey??null;const t={uuid:s.randomUUID(),action:l.Event.CREATE,recovery:i.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",accessToken:i.accessToken,playerID:i.playerID,thirdPartyProvider:i.thirdPartyProvider,thirdPartyTokenType:i.thirdPartyTokenType,encryptionKey:i.password,encryptionSession:i.recovery?.encryptionSession??null,passkey:i.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 r.create(t);return l.isErrorResponse(n)&&this.handleError(n),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",n.version??"undefined"),n}async import(e){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const r=await this.ensureConnection(),i=await this.buildIFrameRequestConfiguration();i.chainId=e.chainId??null,i.password=e?.entropy?.recoveryPassword??null,i.recovery={...i.recovery,encryptionSession:e?.entropy?.encryptionSession},i.passkey=e?.entropy?.passkey??null;const t={uuid:s.randomUUID(),action:l.Event.IMPORT,privateKey:e.privateKey,recovery:i.recovery,publishableKey:this.sdkConfiguration.baseConfiguration.publishableKey,shieldAPIKey:this.sdkConfiguration.shieldConfiguration?.shieldPublishableKey||"",accessToken:i.accessToken,playerID:i.playerID,thirdPartyProvider:i.thirdPartyProvider,thirdPartyTokenType:i.thirdPartyTokenType,encryptionKey:i.password,encryptionSession:i.recovery?.encryptionSession??null,passkey:i.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 r.import(t);return l.isErrorResponse(n)&&this.handleError(n),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",n.version??"undefined"),n}async recover(r){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const i=await e.Account.fromStorage(this.storage),t=await this.ensureConnection(),n=await this.buildIFrameRequestConfiguration();n.chainId=i?.chainId??null,n.password=r?.entropy?.recoveryPassword??null,n.recovery={...n.recovery,encryptionSession:r?.entropy?.encryptionSession},n.passkey=r?.entropy?.passkey??null;const o={uuid:s.randomUUID(),action:l.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:r.account,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},a=await t.recover(o);return l.isErrorResponse(a)&&this.handleError(a),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",a.version??"undefined"),a}async sign(e,r,i,t){a.debugLog("[iframe] ensureConnection");const n=await this.ensureConnection(),o=new l.SignRequest(s.randomUUID(),e,await this.buildRequestConfiguration(),r,i,t);let d;a.debugLog("[iframe] done ensureConnection"),this.assertAlive();try{d=await n.sign(o,new c({timeout:9e4}))}catch(e){if(e instanceof u&&"METHOD_CALL_TIMEOUT"===e.code)throw this.hasFailed=!0,new O(9e4);throw e}if(a.debugLog("[iframe] response",d),l.isErrorResponse(d)&&this.handleError(d),!d.signature)throw new w;return"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",d.version??"undefined"),d.signature}async switchChain(e){const r=await this.ensureConnection(),i=new l.SwitchChainRequest(s.randomUUID(),e,await this.buildRequestConfiguration()),t=await r.switchChain(i);return l.isErrorResponse(t)&&this.handleError(t),t}async export(){const e=await this.ensureConnection(),r=new l.ExportPrivateKeyRequest(s.randomUUID(),await this.buildRequestConfiguration()),i=await e.export(r);return l.isErrorResponse(i)&&this.handleError(i),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",i.version??"undefined"),i.key}async setRecoveryMethod(e,r,i,t,n){const o=await this.ensureConnection(),a=new l.SetRecoveryMethodRequest(s.randomUUID(),e,await this.buildRequestConfiguration(),r,i,t,n),d=await o.setRecoveryMethod(a);l.isErrorResponse(d)&&this.handleError(d),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",d.version??"undefined")}async getCurrentDevice(e){const r=await this.ensureConnection(),i=new l.GetCurrentDeviceRequest(s.randomUUID(),e);try{const e=await r.getCurrentDevice(i);return l.isErrorResponse(e)&&this.handleError(e),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",e.version??"undefined"),e}catch(e){if(e instanceof f)return null;throw e}}async updateAuthentication(){if(!this.isLoaded()||!this.remote)return void a.debugLog("IframeManager not loaded, skipping authentication update");const e=await r.Authentication.fromStorage(this.storage);if(!e)return void a.debugLog("No authentication found, skipping update");const i=new l.UpdateAuthenticationRequest(s.randomUUID(),e.token);a.debugLog("Updating authentication in iframe with token");const t=await this.remote.updateAuthentication(i);l.isErrorResponse(t)&&this.handleError(t)}async disconnect(){const e=await this.ensureConnection(),r={uuid:s.randomUUID()};await e.logout(r)}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.isDestroyed||(this.isDestroyed=!0,this.clearConnection())}},exports.IframeSignEmptyResponseError=w,exports.IframeSignTimeoutError=O,exports.MissingProjectEntropyError=y,exports.MissingRecoveryPasswordError=g,exports.NotConfiguredError=f,exports.OTPRequiredError=E,exports.SessionEndedBeforeSetupError=m,exports.WrongPasskeyError=p,exports.WrongRecoveryPasswordError=R;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=require("../../../utils/crypto.cjs"),t=require("./CallOptions.cjs"),r=require("./errorSerialization.cjs"),
|
|
1
|
+
"use strict";var e=require("../../../utils/crypto.cjs"),t=require("./CallOptions.cjs"),r=require("./errorSerialization.cjs"),o=require("./guards.cjs"),a=require("./methodSerialization.cjs"),s=require("./namespace.cjs"),n=require("./PenpalError.cjs");const i=new Set(["apply","call","bind"]),l=(e,t,r=[])=>new Proxy(r.length?()=>{}:Object.create(null),{get(o,a){if("then"!==a)return r.length&&i.has(a)?Reflect.get(o,a):l(e,t,[...r,a])},apply:(t,o,a)=>e(r,a)}),c=e=>new n("CONNECTION_DESTROYED",`Method call ${a.formatMethodPath(e)}() failed due to destroyed connection`);module.exports=(i,d,h)=>{let u=!1;const m=new Map,f=e=>{if(!o.isReplyMessage(e))return;const{callId:t,value:s,isError:n,isSerializedErrorInstance:i}=e,l=m.get(t);l&&(m.delete(t),clearTimeout(l.timeoutId),h?.(`Received ${a.formatMethodPath(l.methodPath)}() call`,e),n?l.reject(i?r.deserializeError(s):s):l.resolve(s))};i.addMessageHandler(f);return{remoteProxy:l((r,o)=>{if(u)throw c(r);const l=e.randomUUID(),f=o[o.length-1],g=f instanceof t,{timeout:M,transferables:p}=g?f:{},P=g?o.slice(0,-1):o;return new Promise((e,t)=>{const o=void 0!==M?window.setTimeout(()=>{m.delete(l),t(new n("METHOD_CALL_TIMEOUT",`Method call ${a.formatMethodPath(r)}() timed out after ${M}ms`))},M):void 0;m.set(l,{methodPath:r,resolve:e,reject:t,timeoutId:o});try{const e={namespace:s,channel:d,type:"CALL",id:l,methodPath:r,args:P};h?.(`Sending ${a.formatMethodPath(r)}() call`,e),i.sendMessage(e,p)}catch(e){t(new n("TRANSMISSION_FAILED",e.message))}})},h),destroy:()=>{u=!0,i.removeMessageHandler(f);for(const{methodPath:e,reject:t,timeoutId:r}of m.values())clearTimeout(r),t(c(e));m.clear()}}};
|
package/dist/index.d.cts
CHANGED
|
@@ -12955,6 +12955,26 @@ declare class NotConfiguredError extends SignerError {
|
|
|
12955
12955
|
declare class OTPRequiredError extends OpenfortError {
|
|
12956
12956
|
constructor();
|
|
12957
12957
|
}
|
|
12958
|
+
/**
|
|
12959
|
+
* Thrown when the iframe signer does not respond to a `sign` request within
|
|
12960
|
+
* the configured timeout window. The handshake itself succeeded — penpal is
|
|
12961
|
+
* connected — but `remote.sign()` never resolved. In practice this means the
|
|
12962
|
+
* passkey/biometry prompt was dismissed, the iframe is frozen, or a
|
|
12963
|
+
* postMessage was dropped. Without this timeout the promise hangs forever
|
|
12964
|
+
* and the caller sees an endless "Processing" spinner with no error.
|
|
12965
|
+
*/
|
|
12966
|
+
declare class IframeSignTimeoutError extends SignerError {
|
|
12967
|
+
constructor(timeoutMs: number);
|
|
12968
|
+
}
|
|
12969
|
+
/**
|
|
12970
|
+
* Thrown when the iframe signer returns a response without a signature
|
|
12971
|
+
* (empty string, undefined, or null). The transport succeeded but the
|
|
12972
|
+
* payload is unusable — posting it downstream would create a malformed
|
|
12973
|
+
* UserOperation, so fail fast instead.
|
|
12974
|
+
*/
|
|
12975
|
+
declare class IframeSignEmptyResponseError extends SignerError {
|
|
12976
|
+
constructor();
|
|
12977
|
+
}
|
|
12958
12978
|
/**
|
|
12959
12979
|
* Thrown when the consumer calls `destroy()` on an `IframeManager` before its
|
|
12960
12980
|
* connection handshake has finished. The two paths that produce this error are
|
|
@@ -12968,6 +12988,19 @@ declare class OTPRequiredError extends OpenfortError {
|
|
|
12968
12988
|
declare class SessionEndedBeforeSetupError extends OpenfortError {
|
|
12969
12989
|
constructor();
|
|
12970
12990
|
}
|
|
12991
|
+
/**
|
|
12992
|
+
* Thrown when the penpal handshake does not complete within the connection
|
|
12993
|
+
* window — the iframe never replied to SYN/ACK. Distinct from a dashboard
|
|
12994
|
+
* origin misconfiguration: a timeout usually means the embed page is
|
|
12995
|
+
* unreachable, blocked by CSP, or the network dropped the load. Collapsing it
|
|
12996
|
+
* into the native-app "configure your origin" copy misled web users whose
|
|
12997
|
+
* origin was fine (Sentry OPENFORT-JS-D0, seen on playground.openfort.io). The
|
|
12998
|
+
* original PenpalError is kept as `cause` so callers can still inspect
|
|
12999
|
+
* `code === 'CONNECTION_TIMEOUT'`.
|
|
13000
|
+
*/
|
|
13001
|
+
declare class IframeHandshakeTimeoutError extends OpenfortError {
|
|
13002
|
+
constructor(timeoutMs: number, cause: unknown);
|
|
13003
|
+
}
|
|
12971
13004
|
|
|
12972
13005
|
interface Signer$1 {
|
|
12973
13006
|
sign(message: Uint8Array | string, requireArrayify?: boolean, requireHash?: boolean): Promise<string>;
|
|
@@ -13265,4 +13298,4 @@ declare function cryptoDigest(algorithm: string, data: BufferSource): Promise<Ar
|
|
|
13265
13298
|
*/
|
|
13266
13299
|
declare const openfortEvents: TypedEventEmitter<OpenfortEventMap>;
|
|
13267
13300
|
|
|
13268
|
-
export { AccountTypeEnum, AuthActionRequiredActions, AuthActionRequiredResponse, AuthApi, AuthInitPayload, AuthResponse, AuthType, AuthenticationError, Authorization, AuthorizationError, BasicAuthProvider, ChainTypeEnum, ConfigurationError, EmbeddedAccount, EmbeddedState, EmbeddedWalletApi, GrantPermissionsParameters, GrantPermissionsReturnType, IPasskeyHandler, InitializeOAuthOptions, MissingProjectEntropyError, MissingRecoveryPasswordError, NotConfiguredError, OAuthError, OAuthProvider, OPENFORT_AUTH_ERROR_CODES, OPENFORT_ERROR_CODES, OTPError, OTPRequiredError, Openfort, OpenfortAuthErrorCode, OpenfortConfiguration, OpenfortError, OpenfortErrorCode, OpenfortEventMap, OpenfortEvents, OpenfortInternal, OpenfortSDKConfiguration, PASSKEY_ERROR_CODES, PasskeyAssertionFailedError, PasskeyCreateConfig, PasskeyCreationFailedError, PasskeyDeriveConfig, PasskeyDetails, PasskeyEnv, PasskeyErrorCode, PasskeyHandler, PasskeyPRFNotSupportedError, PasskeySeedInvalidError, PasskeyUserCancelledError, Permission, Policy, PrepareAuthorizationParams, Provider, ProxyApi, RecoveryError, RecoveryMethod, RecoveryMethodDetails, RecoveryParams, RequestError, RevokePermissionsRequestParams, SDKConfiguration, SDKOverrides, SessionEndedBeforeSetupError, SessionError, SessionResponse, ShieldAuthOptions, ShieldConfiguration, ShieldOptions, SignAuthorizationParams, SignedAuthorization, SignedMessagePayload, Signer, SignerError, IStorage as Storage, ThirdPartyAuthConfiguration, ThirdPartyAuthProvider as ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataPayload, User, ListAccountsGet200ResponseInner as UserAccount, UserApi, UserError, WrongPasskeyError, WrongRecoveryPasswordError, arrayBufferToBase64URL, base64ToArrayBuffer, cryptoDigest, openfortEvents, prepareAndSignAuthorization, serializeSignedAuthorization, signAuthorization };
|
|
13301
|
+
export { AccountTypeEnum, AuthActionRequiredActions, AuthActionRequiredResponse, AuthApi, AuthInitPayload, AuthResponse, AuthType, AuthenticationError, Authorization, AuthorizationError, BasicAuthProvider, ChainTypeEnum, ConfigurationError, EmbeddedAccount, EmbeddedState, EmbeddedWalletApi, GrantPermissionsParameters, GrantPermissionsReturnType, IPasskeyHandler, IframeHandshakeTimeoutError, IframeSignEmptyResponseError, IframeSignTimeoutError, InitializeOAuthOptions, MissingProjectEntropyError, MissingRecoveryPasswordError, NotConfiguredError, OAuthError, OAuthProvider, OPENFORT_AUTH_ERROR_CODES, OPENFORT_ERROR_CODES, OTPError, OTPRequiredError, Openfort, OpenfortAuthErrorCode, OpenfortConfiguration, OpenfortError, OpenfortErrorCode, OpenfortEventMap, OpenfortEvents, OpenfortInternal, OpenfortSDKConfiguration, PASSKEY_ERROR_CODES, PasskeyAssertionFailedError, PasskeyCreateConfig, PasskeyCreationFailedError, PasskeyDeriveConfig, PasskeyDetails, PasskeyEnv, PasskeyErrorCode, PasskeyHandler, PasskeyPRFNotSupportedError, PasskeySeedInvalidError, PasskeyUserCancelledError, Permission, Policy, PrepareAuthorizationParams, Provider, ProxyApi, RecoveryError, RecoveryMethod, RecoveryMethodDetails, RecoveryParams, RequestError, RevokePermissionsRequestParams, SDKConfiguration, SDKOverrides, SessionEndedBeforeSetupError, SessionError, SessionResponse, ShieldAuthOptions, ShieldConfiguration, ShieldOptions, SignAuthorizationParams, SignedAuthorization, SignedMessagePayload, Signer, SignerError, IStorage as Storage, ThirdPartyAuthConfiguration, ThirdPartyAuthProvider as ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataPayload, User, ListAccountsGet200ResponseInner as UserAccount, UserApi, UserError, WrongPasskeyError, WrongRecoveryPasswordError, arrayBufferToBase64URL, base64ToArrayBuffer, cryptoDigest, openfortEvents, prepareAndSignAuthorization, serializeSignedAuthorization, signAuthorization };
|
package/dist/index.d.ts
CHANGED
|
@@ -12955,6 +12955,26 @@ declare class NotConfiguredError extends SignerError {
|
|
|
12955
12955
|
declare class OTPRequiredError extends OpenfortError {
|
|
12956
12956
|
constructor();
|
|
12957
12957
|
}
|
|
12958
|
+
/**
|
|
12959
|
+
* Thrown when the iframe signer does not respond to a `sign` request within
|
|
12960
|
+
* the configured timeout window. The handshake itself succeeded — penpal is
|
|
12961
|
+
* connected — but `remote.sign()` never resolved. In practice this means the
|
|
12962
|
+
* passkey/biometry prompt was dismissed, the iframe is frozen, or a
|
|
12963
|
+
* postMessage was dropped. Without this timeout the promise hangs forever
|
|
12964
|
+
* and the caller sees an endless "Processing" spinner with no error.
|
|
12965
|
+
*/
|
|
12966
|
+
declare class IframeSignTimeoutError extends SignerError {
|
|
12967
|
+
constructor(timeoutMs: number);
|
|
12968
|
+
}
|
|
12969
|
+
/**
|
|
12970
|
+
* Thrown when the iframe signer returns a response without a signature
|
|
12971
|
+
* (empty string, undefined, or null). The transport succeeded but the
|
|
12972
|
+
* payload is unusable — posting it downstream would create a malformed
|
|
12973
|
+
* UserOperation, so fail fast instead.
|
|
12974
|
+
*/
|
|
12975
|
+
declare class IframeSignEmptyResponseError extends SignerError {
|
|
12976
|
+
constructor();
|
|
12977
|
+
}
|
|
12958
12978
|
/**
|
|
12959
12979
|
* Thrown when the consumer calls `destroy()` on an `IframeManager` before its
|
|
12960
12980
|
* connection handshake has finished. The two paths that produce this error are
|
|
@@ -12968,6 +12988,19 @@ declare class OTPRequiredError extends OpenfortError {
|
|
|
12968
12988
|
declare class SessionEndedBeforeSetupError extends OpenfortError {
|
|
12969
12989
|
constructor();
|
|
12970
12990
|
}
|
|
12991
|
+
/**
|
|
12992
|
+
* Thrown when the penpal handshake does not complete within the connection
|
|
12993
|
+
* window — the iframe never replied to SYN/ACK. Distinct from a dashboard
|
|
12994
|
+
* origin misconfiguration: a timeout usually means the embed page is
|
|
12995
|
+
* unreachable, blocked by CSP, or the network dropped the load. Collapsing it
|
|
12996
|
+
* into the native-app "configure your origin" copy misled web users whose
|
|
12997
|
+
* origin was fine (Sentry OPENFORT-JS-D0, seen on playground.openfort.io). The
|
|
12998
|
+
* original PenpalError is kept as `cause` so callers can still inspect
|
|
12999
|
+
* `code === 'CONNECTION_TIMEOUT'`.
|
|
13000
|
+
*/
|
|
13001
|
+
declare class IframeHandshakeTimeoutError extends OpenfortError {
|
|
13002
|
+
constructor(timeoutMs: number, cause: unknown);
|
|
13003
|
+
}
|
|
12971
13004
|
|
|
12972
13005
|
interface Signer$1 {
|
|
12973
13006
|
sign(message: Uint8Array | string, requireArrayify?: boolean, requireHash?: boolean): Promise<string>;
|
|
@@ -13265,4 +13298,4 @@ declare function cryptoDigest(algorithm: string, data: BufferSource): Promise<Ar
|
|
|
13265
13298
|
*/
|
|
13266
13299
|
declare const openfortEvents: TypedEventEmitter<OpenfortEventMap>;
|
|
13267
13300
|
|
|
13268
|
-
export { AccountTypeEnum, AuthActionRequiredActions, AuthActionRequiredResponse, AuthApi, AuthInitPayload, AuthResponse, AuthType, AuthenticationError, Authorization, AuthorizationError, BasicAuthProvider, ChainTypeEnum, ConfigurationError, EmbeddedAccount, EmbeddedState, EmbeddedWalletApi, GrantPermissionsParameters, GrantPermissionsReturnType, IPasskeyHandler, InitializeOAuthOptions, MissingProjectEntropyError, MissingRecoveryPasswordError, NotConfiguredError, OAuthError, OAuthProvider, OPENFORT_AUTH_ERROR_CODES, OPENFORT_ERROR_CODES, OTPError, OTPRequiredError, Openfort, OpenfortAuthErrorCode, OpenfortConfiguration, OpenfortError, OpenfortErrorCode, OpenfortEventMap, OpenfortEvents, OpenfortInternal, OpenfortSDKConfiguration, PASSKEY_ERROR_CODES, PasskeyAssertionFailedError, PasskeyCreateConfig, PasskeyCreationFailedError, PasskeyDeriveConfig, PasskeyDetails, PasskeyEnv, PasskeyErrorCode, PasskeyHandler, PasskeyPRFNotSupportedError, PasskeySeedInvalidError, PasskeyUserCancelledError, Permission, Policy, PrepareAuthorizationParams, Provider, ProxyApi, RecoveryError, RecoveryMethod, RecoveryMethodDetails, RecoveryParams, RequestError, RevokePermissionsRequestParams, SDKConfiguration, SDKOverrides, SessionEndedBeforeSetupError, SessionError, SessionResponse, ShieldAuthOptions, ShieldConfiguration, ShieldOptions, SignAuthorizationParams, SignedAuthorization, SignedMessagePayload, Signer, SignerError, IStorage as Storage, ThirdPartyAuthConfiguration, ThirdPartyAuthProvider as ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataPayload, User, ListAccountsGet200ResponseInner as UserAccount, UserApi, UserError, WrongPasskeyError, WrongRecoveryPasswordError, arrayBufferToBase64URL, base64ToArrayBuffer, cryptoDigest, openfortEvents, prepareAndSignAuthorization, serializeSignedAuthorization, signAuthorization };
|
|
13301
|
+
export { AccountTypeEnum, AuthActionRequiredActions, AuthActionRequiredResponse, AuthApi, AuthInitPayload, AuthResponse, AuthType, AuthenticationError, Authorization, AuthorizationError, BasicAuthProvider, ChainTypeEnum, ConfigurationError, EmbeddedAccount, EmbeddedState, EmbeddedWalletApi, GrantPermissionsParameters, GrantPermissionsReturnType, IPasskeyHandler, IframeHandshakeTimeoutError, IframeSignEmptyResponseError, IframeSignTimeoutError, InitializeOAuthOptions, MissingProjectEntropyError, MissingRecoveryPasswordError, NotConfiguredError, OAuthError, OAuthProvider, OPENFORT_AUTH_ERROR_CODES, OPENFORT_ERROR_CODES, OTPError, OTPRequiredError, Openfort, OpenfortAuthErrorCode, OpenfortConfiguration, OpenfortError, OpenfortErrorCode, OpenfortEventMap, OpenfortEvents, OpenfortInternal, OpenfortSDKConfiguration, PASSKEY_ERROR_CODES, PasskeyAssertionFailedError, PasskeyCreateConfig, PasskeyCreationFailedError, PasskeyDeriveConfig, PasskeyDetails, PasskeyEnv, PasskeyErrorCode, PasskeyHandler, PasskeyPRFNotSupportedError, PasskeySeedInvalidError, PasskeyUserCancelledError, Permission, Policy, PrepareAuthorizationParams, Provider, ProxyApi, RecoveryError, RecoveryMethod, RecoveryMethodDetails, RecoveryParams, RequestError, RevokePermissionsRequestParams, SDKConfiguration, SDKOverrides, SessionEndedBeforeSetupError, SessionError, SessionResponse, ShieldAuthOptions, ShieldConfiguration, ShieldOptions, SignAuthorizationParams, SignedAuthorization, SignedMessagePayload, Signer, SignerError, IStorage as Storage, ThirdPartyAuthConfiguration, ThirdPartyAuthProvider as ThirdPartyOAuthProvider, TokenType, TransactionIntentResponse, TypedDataPayload, User, ListAccountsGet200ResponseInner as UserAccount, UserApi, UserError, WrongPasskeyError, WrongRecoveryPasswordError, arrayBufferToBase64URL, base64ToArrayBuffer, cryptoDigest, openfortEvents, prepareAndSignAuthorization, serializeSignedAuthorization, signAuthorization };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AxiosError as e}from"axios";import{
|
|
1
|
+
import{AxiosError as e}from"axios";import{PACKAGE as t,VERSION as s}from"../../version.js";const r="https://64a03e4967fb4dad3ecb914918c777b6@o4504593015242752.ingest.us.sentry.io/4509292415287296";class n{static sentryInstance;static queuedCalls=[];static baseTags;static set sentry(t){const s=t.getDsn();if(!s)throw new Error("Sentry DSN is not set");if(s.projectId!==r.split("https://")[1].split("/")[1]||s.host!==r.split("@")[1].split("/")[0]||s.publicKey!==r.split("@")[0].split("https://")[1])throw new Error("Sentry DSN is not valid");t.captureAxiosError=(s,r,o,a)=>{if(r instanceof e){if(400===r.response?.status||401===r.response?.status)return;r.name=s,t.captureException(r,{...o,captureContext:{...o?.captureContext,extra:{errorResponseData:r.response?.data,errorStatus:r.response?.status,errorHeaders:r.response?.headers,errorRequest:r.request},tags:{...n.baseTags,method:s}}})}else t.captureException(r,o,a)},t.captureError=(e,s,r,o)=>{const a=s.statusCode;if(400===a||401===a)return;const c=s,i=c.error,u=c.error_description,p=r?.captureContext;t.captureException(s,{...r,captureContext:{...p,extra:{...p?.extra,errorCode:i,errorDescription:u,errorClass:s.constructor.name,...c.statusCode&&{statusCode:c.statusCode},...c.audience&&{audience:c.audience},...c.scope&&{scope:c.scope},...c.accountId&&{accountId:c.accountId},...c.userId&&{userId:c.userId},...c.provider&&{provider:c.provider},...c.recoveryMethod&&{recoveryMethod:c.recoveryMethod}},tags:{...n.baseTags,context:e,errorClass:s.constructor.name}}})},n.sentryInstance=t}static get sentry(){return n.proxy}static async init({sentry:e,configuration:o}){if(e)return void(n.sentry=e);const a=await import("@sentry/browser");n.sentry=new a.BrowserClient({dsn:r,release:`${t}@${s}`,integrations:[],stackParser:a.defaultStackParser,transport:a.makeFetchTransport}),n.baseTags={projectId:o?.baseConfiguration.publishableKey??"",sdk:t,sdkVersion:s},n.processQueuedCalls()}static proxy=new Proxy({},{get:(e,t)=>n.sentryInstance&&"function"==typeof n.sentryInstance[t]?(...e)=>n.sentryInstance[t](...e):(...e)=>{n.queuedCalls.push({fn:t,args:e})}});static processQueuedCalls(){n.sentryInstance&&(n.queuedCalls.forEach(({fn:e,args:t})=>{"function"==typeof n.sentryInstance[e]&&n.sentryInstance[e](...t)}),n.queuedCalls=[])}}const{sentry:o}=n;export{n as InternalSentry,o as sentry};
|
package/dist/sdk/src/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Openfort as r}from"./core/openfort.js";export{AuthApi}from"./api/auth.js";export{EmbeddedWalletApi}from"./api/embeddedWallet.js";export{ProxyApi}from"./api/proxy.js";export{UserApi}from"./api/user.js";export{OPENFORT_AUTH_ERROR_CODES,OPENFORT_ERROR_CODES}from"./core/errors/authErrorCodes.js";export{AuthenticationError,AuthorizationError,ConfigurationError,OAuthError,OTPError,OpenfortError,RecoveryError,RequestError,SessionError,SignerError,UserError}from"./core/errors/openfortError.js";export{PASSKEY_ERROR_CODES,PasskeyAssertionFailedError,PasskeyCreationFailedError,PasskeyPRFNotSupportedError,PasskeySeedInvalidError,PasskeyUserCancelledError}from"./core/passkey/errors.js";export{PasskeyHandler}from"./core/passkey/handler.js";export{arrayBufferToBase64URL,base64ToArrayBuffer}from"./core/passkey/utils.js";export{OpenfortConfiguration,SDKConfiguration,ShieldConfiguration}from"./core/config/config.js";export{OpenfortInternal}from"./core/openfortInternal.js";export{prepareAndSignAuthorization,serializeSignedAuthorization,signAuthorization}from"./utils/authorization.js";export{MissingProjectEntropyError,MissingRecoveryPasswordError,NotConfiguredError,OTPRequiredError,SessionEndedBeforeSetupError,WrongPasskeyError,WrongRecoveryPasswordError}from"./wallets/iframeManager.js";export{AccountTypeEnum,AuthActionRequiredActions,AuthType,BasicAuthProvider,ChainTypeEnum,EmbeddedState,OAuthProvider,OpenfortEvents,RecoveryMethod,ThirdPartyAuthProvider as ThirdPartyOAuthProvider,TokenType}from"./types/types.js";export{cryptoDigest}from"./utils/crypto.js";const o=r.getEventEmitter();export{r as Openfort,o as openfortEvents};
|
|
1
|
+
import{Openfort as r}from"./core/openfort.js";export{AuthApi}from"./api/auth.js";export{EmbeddedWalletApi}from"./api/embeddedWallet.js";export{ProxyApi}from"./api/proxy.js";export{UserApi}from"./api/user.js";export{OPENFORT_AUTH_ERROR_CODES,OPENFORT_ERROR_CODES}from"./core/errors/authErrorCodes.js";export{AuthenticationError,AuthorizationError,ConfigurationError,OAuthError,OTPError,OpenfortError,RecoveryError,RequestError,SessionError,SignerError,UserError}from"./core/errors/openfortError.js";export{PASSKEY_ERROR_CODES,PasskeyAssertionFailedError,PasskeyCreationFailedError,PasskeyPRFNotSupportedError,PasskeySeedInvalidError,PasskeyUserCancelledError}from"./core/passkey/errors.js";export{PasskeyHandler}from"./core/passkey/handler.js";export{arrayBufferToBase64URL,base64ToArrayBuffer}from"./core/passkey/utils.js";export{OpenfortConfiguration,SDKConfiguration,ShieldConfiguration}from"./core/config/config.js";export{OpenfortInternal}from"./core/openfortInternal.js";export{prepareAndSignAuthorization,serializeSignedAuthorization,signAuthorization}from"./utils/authorization.js";export{IframeHandshakeTimeoutError,IframeSignEmptyResponseError,IframeSignTimeoutError,MissingProjectEntropyError,MissingRecoveryPasswordError,NotConfiguredError,OTPRequiredError,SessionEndedBeforeSetupError,WrongPasskeyError,WrongRecoveryPasswordError}from"./wallets/iframeManager.js";export{AccountTypeEnum,AuthActionRequiredActions,AuthType,BasicAuthProvider,ChainTypeEnum,EmbeddedState,OAuthProvider,OpenfortEvents,RecoveryMethod,ThirdPartyAuthProvider as ThirdPartyOAuthProvider,TokenType}from"./types/types.js";export{cryptoDigest}from"./utils/crypto.js";const o=r.getEventEmitter();export{r as Openfort,o as openfortEvents};
|
package/dist/sdk/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="1.3.
|
|
1
|
+
const o="1.3.8",t="@openfort/openfort-js";export{t as PACKAGE,o as VERSION};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Account as e}from"../core/configuration/account.js";import{Authentication as i}from"../core/configuration/authentication.js";import{OPENFORT_AUTH_ERROR_CODES as t}from"../core/errors/authErrorCodes.js";import{RecoveryError as n,SignerError as r,OpenfortError as o,ConfigurationError as s,SessionError as a}from"../core/errors/openfortError.js";import{sentry as d}from"../core/errors/sentry.js";import{StorageKeys as c}from"../storage/istorage.js";import{randomUUID as h}from"../utils/crypto.js";import{debugLog as u}from"../utils/debug.js";import{ReactNativeMessenger as l}from"./messaging/ReactNativeMessenger.js";import y from"./messaging/browserMessenger/connect.js";import"./messaging/browserMessenger/backwardCompatibility.js";import{isErrorResponse as p,NOT_CONFIGURED_ERROR as f,MISSING_USER_ENTROPY_ERROR as g,MISSING_PROJECT_ENTROPY_ERROR as w,INCORRECT_USER_ENTROPY_ERROR as m,MISSING_PASSKEY_ERROR as v,INCORRECT_PASSKEY_ERROR as C,OTP_REQUIRED_ERROR as k,ShieldAuthType as I,Event as P,SignRequest as b,SwitchChainRequest as T,ExportPrivateKeyRequest as R,SetRecoveryMethodRequest as E,GetCurrentDeviceRequest as S,UpdateAuthenticationRequest as A}from"./types.js";class N extends n{constructor(){super(t.MISSING_RECOVERY_PASSWORD,"This embedded signer requires a password to be recovered","password")}}class O extends n{constructor(){super(t.INCORRECT_PASSKEY,"Wrong recovery passkey for this embedded signer","passkey")}}class D extends n{constructor(){super(t.MISSING_PROJECT_ENTROPY,"Project entropy is missing","entropy")}}class U extends n{constructor(){super(t.WRONG_RECOVERY_PASSWORD,"Wrong recovery password for this embedded signer","password")}}class K extends r{constructor(){super(t.NOT_CONFIGURED,"Signer is not configured")}}class z extends o{constructor(){super(t.OTP_REQUIRED,"OTP verification required")}}class M extends o{constructor(){super(t.INTERNAL_ERROR,"Wallet session ended before setup completed."),Object.setPrototypeOf(this,M.prototype)}}class F{messenger;connection;remote;storage;sdkConfiguration;isInitialized=!1;initializationPromise=null;isDestroyed=!1;hasFailed=!1;constructor(e,i,t){if(!e)throw new s("Configuration is required for IframeManager");if(!i)throw new s("Storage is required for IframeManager");if(!t)throw new s("Messenger is required for IframeManager");this.sdkConfiguration=e,this.storage=i,this.messenger=t}assertAlive(){if(this.isDestroyed)throw new M}async initialize(){if(this.assertAlive(),!this.isInitialized){if(this.hasFailed)throw new o(t.INTERNAL_ERROR,"Failed to establish iFrame connection: Previous connection attempt failed");if(this.initializationPromise)return await this.initializationPromise,void this.assertAlive();this.initializationPromise=this.doInitialize();try{await this.initializationPromise,this.assertAlive(),this.isInitialized=!0}catch(e){if(this.initializationPromise=null,e instanceof M)throw e;throw this.hasFailed=!0,e}}}async doInitialize(){u("Initializing IframeManager connection..."),this.assertAlive(),this.messenger.initialize({validateReceivedMessage:e=>!(!e||"object"!=typeof e),log:u}),this.connection=y({messenger:this.messenger,timeout:1e4,log:u});try{this.remote=await this.connection.promise,this.assertAlive(),u("IframeManager connection established")}catch(e){this.isDestroyed&&u("Connection rejected after destroy() — surfacing teardown error"),this.assertAlive();const i=e;throw d.captureException(i),this.clearConnection(),u("Failed to establish connection:",i),new o(t.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 `)}}clearConnection(){if(this.connection)try{this.connection.destroy()}catch(e){u("clearConnection: connection.destroy() threw, swallowing:",e)}this.remote=void 0,this.isInitialized=!1,this.connection=void 0,this.initializationPromise=null}async ensureConnection(){if(this.isInitialized&&this.remote||await this.initialize(),!this.remote)throw new o(t.INTERNAL_ERROR,"Failed to establish connection");return this.remote}handleError(e){if(p(e)){if(e.error===f)throw this.storage.remove(c.ACCOUNT),new K;if(e.error===g)throw this.storage.remove(c.ACCOUNT),new N;if(e.error===w)throw this.storage.remove(c.ACCOUNT),new D;if(e.error===m)throw new U;if(e.error===v)throw this.storage.remove(c.ACCOUNT),new N;if(e.error===C)throw new O;if(e.error===k)throw new z;throw this.storage.remove(c.ACCOUNT),new o(t.INTERNAL_ERROR,`Unknown error: ${e.error}`)}throw e}async buildRequestConfiguration(){const e=await i.fromStorage(this.storage);if(!e)throw new a(t.NOT_LOGGED_IN,"Must be authenticated to create a signer");const n={auth:I.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.fromStorage(this.storage);if(!e)throw new a(t.NOT_LOGGED_IN,"Must be authenticated to create a signer");const n={auth:I.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(),t=await this.buildIFrameRequestConfiguration();t.chainId=e.chainId??null,t.password=e?.entropy?.recoveryPassword??null,t.recovery={...t.recovery,encryptionSession:e?.entropy?.encryptionSession},t.passkey=e?.entropy?.passkey??null;const n={uuid:h(),action:P.CREATE,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,chainId:e.chainId??null,accountType:e.accountType,chainType:e.chainType,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},r=await i.create(n);return p(r)&&this.handleError(r),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",r.version??"undefined"),r}async import(e){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const i=await this.ensureConnection(),t=await this.buildIFrameRequestConfiguration();t.chainId=e.chainId??null,t.password=e?.entropy?.recoveryPassword??null,t.recovery={...t.recovery,encryptionSession:e?.entropy?.encryptionSession},t.passkey=e?.entropy?.passkey??null;const n={uuid:h(),action:P.IMPORT,privateKey:e.privateKey,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,chainId:e.chainId??null,accountType:e.accountType,chainType:e.chainType,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},r=await i.import(n);return p(r)&&this.handleError(r),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",r.version??"undefined"),r}async recover(i){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const t=await e.fromStorage(this.storage),n=await this.ensureConnection(),r=await this.buildIFrameRequestConfiguration();r.chainId=t?.chainId??null,r.password=i?.entropy?.recoveryPassword??null,r.recovery={...r.recovery,encryptionSession:i?.entropy?.encryptionSession},r.passkey=i?.entropy?.passkey??null;const o={uuid:h(),action:P.RECOVER,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,account:i.account,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},s=await n.recover(o);return p(s)&&this.handleError(s),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",s.version??"undefined"),s}async sign(e,i,t,n){u("[iframe] ensureConnection");const r=await this.ensureConnection(),o=new b(h(),e,await this.buildRequestConfiguration(),i,t,n);u("[iframe] done ensureConnection");const s=await r.sign(o);return u("[iframe] response",s),p(s)&&this.handleError(s),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",s.version??"undefined"),s.signature}async switchChain(e){const i=await this.ensureConnection(),t=new T(h(),e,await this.buildRequestConfiguration()),n=await i.switchChain(t);return p(n)&&this.handleError(n),n}async export(){const e=await this.ensureConnection(),i=new R(h(),await this.buildRequestConfiguration()),t=await e.export(i);return p(t)&&this.handleError(t),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",t.version??"undefined"),t.key}async setRecoveryMethod(e,i,t,n,r){const o=await this.ensureConnection(),s=new E(h(),e,await this.buildRequestConfiguration(),i,t,n,r),a=await o.setRecoveryMethod(s);p(a)&&this.handleError(a),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",a.version??"undefined")}async getCurrentDevice(e){const i=await this.ensureConnection(),t=new S(h(),e);try{const e=await i.getCurrentDevice(t);return p(e)&&this.handleError(e),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",e.version??"undefined"),e}catch(e){if(e instanceof K)return null;throw e}}async updateAuthentication(){if(!this.isLoaded()||!this.remote)return void u("IframeManager not loaded, skipping authentication update");const e=await i.fromStorage(this.storage);if(!e)return void u("No authentication found, skipping update");const t=new A(h(),e.token);u("Updating authentication in iframe with token");const n=await this.remote.updateAuthentication(t);p(n)&&this.handleError(n)}async disconnect(){const e=await this.ensureConnection(),i={uuid:h()};await e.logout(i)}async onMessage(e){u("[HANDSHAKE DEBUG] IframeManager.onMessage called with:",e),this.messenger instanceof l?(this.isInitialized||this.connection?u(`[HANDSHAKE DEBUG] Connection already initialized (isInitialized: ${this.isInitialized}, hasConnection: ${!!this.connection})`):(u("[HANDSHAKE DEBUG] First message received, initializing connection..."),this.initialize().catch(e=>{u("[HANDSHAKE DEBUG] Failed to initialize connection:",e)})),u("[HANDSHAKE DEBUG] Passing message to ReactNativeMessenger"),this.messenger.handleMessage(e)):u("[HANDSHAKE DEBUG] Not a ReactNativeMessenger, ignoring message")}isLoaded(){return this.isInitialized&&void 0!==this.remote}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.clearConnection())}}export{F as IframeManager,D as MissingProjectEntropyError,N as MissingRecoveryPasswordError,K as NotConfiguredError,z as OTPRequiredError,M as SessionEndedBeforeSetupError,O as WrongPasskeyError,U as WrongRecoveryPasswordError};
|
|
1
|
+
import{Account as e}from"../core/configuration/account.js";import{Authentication as i}from"../core/configuration/authentication.js";import{OPENFORT_AUTH_ERROR_CODES as t}from"../core/errors/authErrorCodes.js";import{OpenfortError as n,SignerError as r,RecoveryError as o,ConfigurationError as s,SessionError as a}from"../core/errors/openfortError.js";import{sentry as d}from"../core/errors/sentry.js";import{StorageKeys as c}from"../storage/istorage.js";import{randomUUID as h}from"../utils/crypto.js";import{debugLog as u}from"../utils/debug.js";import{ReactNativeMessenger as l}from"./messaging/ReactNativeMessenger.js";import p from"./messaging/browserMessenger/CallOptions.js";import y from"./messaging/browserMessenger/connect.js";import"./messaging/browserMessenger/backwardCompatibility.js";import f from"./messaging/browserMessenger/PenpalError.js";import{isErrorResponse as g,NOT_CONFIGURED_ERROR as m,MISSING_USER_ENTROPY_ERROR as w,MISSING_PROJECT_ENTROPY_ERROR as v,INCORRECT_USER_ENTROPY_ERROR as C,MISSING_PASSKEY_ERROR as I,INCORRECT_PASSKEY_ERROR as k,OTP_REQUIRED_ERROR as b,ShieldAuthType as T,Event as R,SignRequest as P,SwitchChainRequest as E,ExportPrivateKeyRequest as A,SetRecoveryMethodRequest as S,GetCurrentDeviceRequest as N,UpdateAuthenticationRequest as O}from"./types.js";class D extends o{constructor(){super(t.MISSING_RECOVERY_PASSWORD,"This embedded signer requires a password to be recovered","password")}}class U extends o{constructor(){super(t.INCORRECT_PASSKEY,"Wrong recovery passkey for this embedded signer","passkey")}}class K extends o{constructor(){super(t.MISSING_PROJECT_ENTROPY,"Project entropy is missing","entropy")}}class M extends o{constructor(){super(t.WRONG_RECOVERY_PASSWORD,"Wrong recovery password for this embedded signer","password")}}class z extends r{constructor(){super(t.NOT_CONFIGURED,"Signer is not configured")}}class _ extends n{constructor(){super(t.OTP_REQUIRED,"OTP verification required")}}class L extends r{constructor(e){super(t.INTERNAL_ERROR,`Iframe signer did not respond within ${e}ms. The signing prompt may have been dismissed or the iframe is unresponsive.`),this.name="IframeSignTimeoutError",Object.setPrototypeOf(this,L.prototype)}}class j extends r{constructor(){super(t.INTERNAL_ERROR,"Iframe signer returned an empty signature."),this.name="IframeSignEmptyResponseError",Object.setPrototypeOf(this,j.prototype)}}class F extends n{constructor(){super(t.INTERNAL_ERROR,"Wallet session ended before setup completed."),Object.setPrototypeOf(this,F.prototype)}}class q extends n{constructor(e,i){super(t.INTERNAL_ERROR,`Failed to establish iframe connection within ${e}ms. The embedded wallet page did not respond — it may be unreachable or blocked by CSP/network.`),this.name="IframeHandshakeTimeoutError",this.cause=i,Object.setPrototypeOf(this,q.prototype)}}class x{messenger;connection;remote;storage;sdkConfiguration;isInitialized=!1;initializationPromise=null;isDestroyed=!1;hasFailed=!1;constructor(e,i,t){if(!e)throw new s("Configuration is required for IframeManager");if(!i)throw new s("Storage is required for IframeManager");if(!t)throw new s("Messenger is required for IframeManager");this.sdkConfiguration=e,this.storage=i,this.messenger=t}assertAlive(){if(this.isDestroyed)throw new F}async initialize(){if(this.assertAlive(),!this.isInitialized){if(this.hasFailed)throw new n(t.INTERNAL_ERROR,"Failed to establish iFrame connection: Previous connection attempt failed");if(this.initializationPromise)return await this.initializationPromise,void this.assertAlive();this.initializationPromise=this.doInitialize();try{await this.initializationPromise,this.assertAlive(),this.isInitialized=!0}catch(e){if(this.initializationPromise=null,e instanceof F)throw e;throw this.hasFailed=!0,e}}}async doInitialize(){u("Initializing IframeManager connection..."),this.assertAlive(),this.messenger.initialize({validateReceivedMessage:e=>!(!e||"object"!=typeof e),log:u}),this.connection=y({messenger:this.messenger,timeout:1e4,log:u});try{this.remote=await this.connection.promise,this.assertAlive(),u("IframeManager connection established")}catch(e){if(this.isDestroyed&&u("Connection rejected after destroy() — surfacing teardown error"),this.assertAlive(),d.captureException(e),this.clearConnection(),u("Failed to establish connection:",e),e instanceof f&&"CONNECTION_TIMEOUT"===e.code)throw new q(1e4,e);const i=e;throw new n(t.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 `)}}clearConnection(){if(this.connection)try{this.connection.destroy()}catch(e){u("clearConnection: connection.destroy() threw, swallowing:",e)}this.remote=void 0,this.isInitialized=!1,this.connection=void 0,this.initializationPromise=null}async ensureConnection(){if(this.isInitialized&&this.remote||await this.initialize(),!this.remote)throw new n(t.INTERNAL_ERROR,"Failed to establish connection");return this.remote}handleError(e){if(g(e)){if(e.error===m)throw this.storage.remove(c.ACCOUNT),new z;if(e.error===w)throw this.storage.remove(c.ACCOUNT),new D;if(e.error===v)throw this.storage.remove(c.ACCOUNT),new K;if(e.error===C)throw new M;if(e.error===I)throw this.storage.remove(c.ACCOUNT),new D;if(e.error===k)throw new U;if(e.error===b)throw new _;throw this.storage.remove(c.ACCOUNT),new n(t.INTERNAL_ERROR,`Unknown error: ${e.error}`)}throw e}async buildRequestConfiguration(){const e=await i.fromStorage(this.storage);if(!e)throw new a(t.NOT_LOGGED_IN,"Must be authenticated to create a signer");const n={auth:T.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.fromStorage(this.storage);if(!e)throw new a(t.NOT_LOGGED_IN,"Must be authenticated to create a signer");const n={auth:T.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(),t=await this.buildIFrameRequestConfiguration();t.chainId=e.chainId??null,t.password=e?.entropy?.recoveryPassword??null,t.recovery={...t.recovery,encryptionSession:e?.entropy?.encryptionSession},t.passkey=e?.entropy?.passkey??null;const n={uuid:h(),action:R.CREATE,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,chainId:e.chainId??null,accountType:e.accountType,chainType:e.chainType,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},r=await i.create(n);return g(r)&&this.handleError(r),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",r.version??"undefined"),r}async import(e){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const i=await this.ensureConnection(),t=await this.buildIFrameRequestConfiguration();t.chainId=e.chainId??null,t.password=e?.entropy?.recoveryPassword??null,t.recovery={...t.recovery,encryptionSession:e?.entropy?.encryptionSession},t.passkey=e?.entropy?.passkey??null;const n={uuid:h(),action:R.IMPORT,privateKey:e.privateKey,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,chainId:e.chainId??null,accountType:e.accountType,chainType:e.chainType,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},r=await i.import(n);return g(r)&&this.handleError(r),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",r.version??"undefined"),r}async recover(i){if(!this.sdkConfiguration.shieldConfiguration)throw new Error("shieldConfiguration is required");const t=await e.fromStorage(this.storage),n=await this.ensureConnection(),r=await this.buildIFrameRequestConfiguration();r.chainId=t?.chainId??null,r.password=i?.entropy?.recoveryPassword??null,r.recovery={...r.recovery,encryptionSession:i?.entropy?.encryptionSession},r.passkey=i?.entropy?.passkey??null;const o={uuid:h(),action:R.RECOVER,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,account:i.account,nativeAppIdentifier:this.sdkConfiguration?.nativeAppIdentifier??null},s=await n.recover(o);return g(s)&&this.handleError(s),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",s.version??"undefined"),s}async sign(e,i,t,n){u("[iframe] ensureConnection");const r=await this.ensureConnection(),o=new P(h(),e,await this.buildRequestConfiguration(),i,t,n);let s;u("[iframe] done ensureConnection"),this.assertAlive();try{s=await r.sign(o,new p({timeout:9e4}))}catch(e){if(e instanceof f&&"METHOD_CALL_TIMEOUT"===e.code)throw this.hasFailed=!0,new L(9e4);throw e}if(u("[iframe] response",s),g(s)&&this.handleError(s),!s.signature)throw new j;return"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",s.version??"undefined"),s.signature}async switchChain(e){const i=await this.ensureConnection(),t=new E(h(),e,await this.buildRequestConfiguration()),n=await i.switchChain(t);return g(n)&&this.handleError(n),n}async export(){const e=await this.ensureConnection(),i=new A(h(),await this.buildRequestConfiguration()),t=await e.export(i);return g(t)&&this.handleError(t),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",t.version??"undefined"),t.key}async setRecoveryMethod(e,i,t,n,r){const o=await this.ensureConnection(),s=new S(h(),e,await this.buildRequestConfiguration(),i,t,n,r),a=await o.setRecoveryMethod(s);g(a)&&this.handleError(a),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",a.version??"undefined")}async getCurrentDevice(e){const i=await this.ensureConnection(),t=new N(h(),e);try{const e=await i.getCurrentDevice(t);return g(e)&&this.handleError(e),"undefined"!=typeof sessionStorage&&sessionStorage.setItem("iframe-version",e.version??"undefined"),e}catch(e){if(e instanceof z)return null;throw e}}async updateAuthentication(){if(!this.isLoaded()||!this.remote)return void u("IframeManager not loaded, skipping authentication update");const e=await i.fromStorage(this.storage);if(!e)return void u("No authentication found, skipping update");const t=new O(h(),e.token);u("Updating authentication in iframe with token");const n=await this.remote.updateAuthentication(t);g(n)&&this.handleError(n)}async disconnect(){const e=await this.ensureConnection(),i={uuid:h()};await e.logout(i)}async onMessage(e){u("[HANDSHAKE DEBUG] IframeManager.onMessage called with:",e),this.messenger instanceof l?(this.isInitialized||this.connection?u(`[HANDSHAKE DEBUG] Connection already initialized (isInitialized: ${this.isInitialized}, hasConnection: ${!!this.connection})`):(u("[HANDSHAKE DEBUG] First message received, initializing connection..."),this.initialize().catch(e=>{u("[HANDSHAKE DEBUG] Failed to initialize connection:",e)})),u("[HANDSHAKE DEBUG] Passing message to ReactNativeMessenger"),this.messenger.handleMessage(e)):u("[HANDSHAKE DEBUG] Not a ReactNativeMessenger, ignoring message")}isLoaded(){return this.isInitialized&&void 0!==this.remote}destroy(){this.isDestroyed||(this.isDestroyed=!0,this.clearConnection())}}export{q as IframeHandshakeTimeoutError,x as IframeManager,j as IframeSignEmptyResponseError,L as IframeSignTimeoutError,K as MissingProjectEntropyError,D as MissingRecoveryPasswordError,z as NotConfiguredError,_ as OTPRequiredError,F as SessionEndedBeforeSetupError,U as WrongPasskeyError,M as WrongRecoveryPasswordError};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{randomUUID as e}from"../../../utils/crypto.js";import t from"./CallOptions.js";import{deserializeError as r}from"./errorSerialization.js";import{isReplyMessage as o}from"./guards.js";import{formatMethodPath as a}from"./methodSerialization.js";import s from"./namespace.js";import n from"./PenpalError.js";const l=new Set(["apply","call","bind"]),i=(e,t,r=[])=>new Proxy(r.length?()=>{}:Object.create(null),{get(o,a){if("then"!==a)return r.length&&l.has(a)?Reflect.get(o,a):i(e,t,[...r,a])},apply:(t,o,a)=>e(r,a)}),c=e=>new n("CONNECTION_DESTROYED",`Method call ${a(e)}() failed due to destroyed connection`),d=(l,d,m)=>{let h=!1;const p=new Map,
|
|
1
|
+
import{randomUUID as e}from"../../../utils/crypto.js";import t from"./CallOptions.js";import{deserializeError as r}from"./errorSerialization.js";import{isReplyMessage as o}from"./guards.js";import{formatMethodPath as a}from"./methodSerialization.js";import s from"./namespace.js";import n from"./PenpalError.js";const l=new Set(["apply","call","bind"]),i=(e,t,r=[])=>new Proxy(r.length?()=>{}:Object.create(null),{get(o,a){if("then"!==a)return r.length&&l.has(a)?Reflect.get(o,a):i(e,t,[...r,a])},apply:(t,o,a)=>e(r,a)}),c=e=>new n("CONNECTION_DESTROYED",`Method call ${a(e)}() failed due to destroyed connection`),d=(l,d,m)=>{let h=!1;const p=new Map,u=e=>{if(!o(e))return;const{callId:t,value:s,isError:n,isSerializedErrorInstance:l}=e,i=p.get(t);i&&(p.delete(t),clearTimeout(i.timeoutId),m?.(`Received ${a(i.methodPath)}() call`,e),n?i.reject(l?r(s):s):i.resolve(s))};l.addMessageHandler(u);return{remoteProxy:i((r,o)=>{if(h)throw c(r);const i=e(),u=o[o.length-1],f=u instanceof t,{timeout:g,transferables:j}=f?u:{},w=f?o.slice(0,-1):o;return new Promise((e,t)=>{const o=void 0!==g?window.setTimeout(()=>{p.delete(i),t(new n("METHOD_CALL_TIMEOUT",`Method call ${a(r)}() timed out after ${g}ms`))},g):void 0;p.set(i,{methodPath:r,resolve:e,reject:t,timeoutId:o});try{const e={namespace:s,channel:d,type:"CALL",id:i,methodPath:r,args:w};m?.(`Sending ${a(r)}() call`,e),l.sendMessage(e,j)}catch(e){t(new n("TRANSMISSION_FAILED",e.message))}})},m),destroy:()=>{h=!0,l.removeMessageHandler(u);for(const{methodPath:e,reject:t,timeoutId:r}of p.values())clearTimeout(r),t(c(e));p.clear()}}};export{d as default};
|
package/package.json
CHANGED