1- import { IMXProvider } from '@imtbl/x-provider' ;
21import {
3- createConfig , ImxApiClients , imxApiConfig , MagicTeeApiClients , MultiRollupApiClients ,
2+ MultiRollupApiClients ,
43} from '@imtbl/generated-clients' ;
5- import { IMXClient } from '@imtbl/x-client' ;
64import { Environment } from '@imtbl/config' ;
75
86import { setPassportClientId , trackError , trackFlow } from '@imtbl/metrics' ;
@@ -16,47 +14,21 @@ import type { DirectLoginOptions } from '@imtbl/auth';
1614import {
1715 connectWallet ,
1816 ZkEvmProvider ,
19- WalletConfiguration ,
20- GuardianClient ,
21- MagicTEESigner ,
2217 ChainConfig ,
23- ConfirmationScreen ,
2418} from '@imtbl/wallet' ;
2519import type { LinkWalletParams , LinkedWallet } from '@imtbl/wallet' ;
2620import {
2721 PassportModuleConfiguration ,
2822 ConnectEvmArguments ,
2923 LoginArguments ,
3024} from './types' ;
31- import { toUserImx } from './utils/imxUser' ;
32- import { PassportImxProviderFactory } from './starkEx' ;
3325import { PassportConfiguration } from './config' ;
3426import { withMetricsAsync } from './utils/metrics' ;
3527import { PassportError , PassportErrorType } from './errors/passportError' ;
36- import { ImxGuardianClient } from './starkEx/imxGuardianClient' ;
3728import { getHttpErrorResponse } from './utils/httpError' ;
3829
39- const buildImxClientConfig = ( passportModuleConfiguration : PassportModuleConfiguration ) => {
40- if ( passportModuleConfiguration . overrides ) {
41- return createConfig ( { basePath : passportModuleConfiguration . overrides . imxPublicApiDomain } ) ;
42- }
43- if ( passportModuleConfiguration . baseConfig . environment === Environment . SANDBOX ) {
44- return imxApiConfig . getSandbox ( ) ;
45- }
46- return imxApiConfig . getProduction ( ) ;
47- } ;
48-
49- const buildImxApiClients = ( passportModuleConfiguration : PassportModuleConfiguration ) => {
50- if ( passportModuleConfiguration . overrides ?. imxApiClients ) return passportModuleConfiguration . overrides . imxApiClients ;
51-
52- const config = buildImxClientConfig ( passportModuleConfiguration ) ;
53- return new ImxApiClients ( config ) ;
54- } ;
55-
5630export const buildPrivateVars = ( passportModuleConfiguration : PassportModuleConfiguration ) => {
5731 const passportConfig = new PassportConfiguration ( passportModuleConfiguration ) ;
58- // Create auth configuration for confirmation screen
59- // Create Auth instance (public API)
6032 const auth = new Auth ( {
6133 ...passportModuleConfiguration ,
6234 authenticationDomain : passportConfig . authenticationDomain ,
@@ -65,75 +37,10 @@ export const buildPrivateVars = (passportModuleConfiguration: PassportModuleConf
6537 passportDomain : passportConfig . passportDomain ,
6638 } ) ;
6739
68- const authConfig = auth . getConfig ( ) ;
69- const confirmationScreen = new ConfirmationScreen ( authConfig ) ;
70-
71- // Create wallet configuration with concrete URLs (no environment)
72- // PassportConfiguration translates environment → URLs
73- const walletConfig = new WalletConfiguration ( {
74- passportDomain : passportConfig . passportDomain ,
75- zkEvmRpcUrl : passportConfig . zkEvmRpcUrl ,
76- relayerUrl : passportConfig . relayerUrl ,
77- indexerMrBasePath : passportConfig . multiRollupConfig . indexer . basePath || passportConfig . passportDomain ,
78- jsonRpcReferrer : passportModuleConfiguration . jsonRpcReferrer ,
79- forceScwDeployBeforeMessageSignature : passportModuleConfiguration . forceScwDeployBeforeMessageSignature ,
80- crossSdkBridgeEnabled : passportModuleConfiguration . crossSdkBridgeEnabled ,
81- } ) ;
82-
83- // Setup IMX-specific components
84- const multiRollupApiClients = new MultiRollupApiClients ( passportConfig . multiRollupConfig ) ;
85-
86- const immutableXClient = passportModuleConfiguration . overrides
87- ? passportModuleConfiguration . overrides . immutableXClient
88- : new IMXClient ( { baseConfig : passportModuleConfiguration . baseConfig } ) ;
89-
90- // Create Guardian client for IMX provider
91- const guardianClient = new GuardianClient ( {
92- config : walletConfig ,
93- getUser : ( forceRefresh ) => ( forceRefresh ? auth . forceUserRefresh ( ) : auth . getUser ( ) ) ,
94- guardianApi : multiRollupApiClients . guardianApi ,
95- passportDomain : passportConfig . passportDomain ,
96- clientId : passportConfig . oidcConfiguration . clientId ,
97- } ) ;
98-
99- const imxGuardianClient = new ImxGuardianClient ( {
100- auth,
101- guardianApi : multiRollupApiClients . guardianApi ,
102- confirmationScreen,
103- crossSdkBridgeEnabled : passportModuleConfiguration . crossSdkBridgeEnabled || false ,
104- } ) ;
105-
106- // Create Magic TEE signer for IMX provider
107- const magicTeeApiClients = new MagicTeeApiClients ( {
108- basePath : passportConfig . magicTeeBasePath ,
109- timeout : passportConfig . magicTeeTimeout ,
110- magicPublishableApiKey : passportConfig . magicPublishableApiKey ,
111- magicProviderId : passportConfig . magicProviderId ,
112- } ) ;
113- const magicTEESigner = new MagicTEESigner (
114- ( forceRefresh ) => ( forceRefresh ? auth . forceUserRefresh ( ) : auth . getUser ( ) ) ,
115- magicTeeApiClients ,
116- ) ;
117-
118- const imxApiClients = buildImxApiClients ( passportModuleConfiguration ) ;
119-
120- const passportImxProviderFactory = new PassportImxProviderFactory ( {
121- auth,
122- immutableXClient,
123- magicTEESigner,
124- passportEventEmitter : auth . eventEmitter ,
125- imxApiClients,
126- guardianClient,
127- imxGuardianClient,
128- } ) ;
129-
13040 return {
13141 passportConfig,
13242 auth,
133- passportImxProviderFactory,
13443 environment : passportModuleConfiguration . baseConfig . environment ,
135- // Keep walletConfig only for IMX GuardianClient
136- walletConfig,
13744 } ;
13845} ;
13946
@@ -142,11 +49,8 @@ export class Passport {
14249 // DEPENDENCIES & CONFIGURATION
14350 // ============================================================================
14451
145- // Auth & Wallet (zkEVM uses these via public APIs)
14652 private readonly auth : Auth ;
14753
148- private readonly passportImxProviderFactory : PassportImxProviderFactory ;
149-
15054 private readonly multiRollupApiClients : MultiRollupApiClients ;
15155
15256 private readonly environment : Environment ;
@@ -157,7 +61,6 @@ export class Passport {
15761 const privateVars = buildPrivateVars ( passportModuleConfiguration ) ;
15862
15963 this . auth = privateVars . auth ;
160- this . passportImxProviderFactory = privateVars . passportImxProviderFactory ;
16164 this . passportConfig = privateVars . passportConfig ;
16265 this . multiRollupApiClients = new MultiRollupApiClients ( this . passportConfig . multiRollupConfig ) ;
16366 this . environment = privateVars . environment ;
@@ -166,42 +69,11 @@ export class Passport {
16669 }
16770
16871 // ============================================================================
169- // IMX-SPECIFIC METHODS
170- // ============================================================================
171-
172- /**
173- * Attempts to connect to IMX silently without user interaction.
174- * @returns {Promise<IMXProvider | null> } A promise that resolves to an IMX provider if successful, or null if no cached session exists
175- * @deprecated The method `login` with an argument of `{ useCachedSession: true }` should be used in conjunction with `connectImx` instead
176- */
177- public async connectImxSilent ( ) : Promise < IMXProvider | null > {
178- return withMetricsAsync (
179- ( ) => this . passportImxProviderFactory . getProviderSilent ( ) ,
180- 'connectImxSilent' ,
181- false ,
182- ) ;
183- }
184-
185- /**
186- * Connects to IMX, prompting user interaction if necessary.
187- * @returns {Promise<IMXProvider> } A promise that resolves to an IMX provider
188- */
189- public async connectImx ( ) : Promise < IMXProvider > {
190- return withMetricsAsync (
191- ( ) => this . passportImxProviderFactory . getProvider ( ) ,
192- 'connectImx' ,
193- false ,
194- ) ;
195- }
196-
197- // ============================================================================
198- // ZKEVM-SPECIFIC METHODS
199- // Uses Auth + Wallet packages
72+ // ZKEVM METHODS
20073 // ============================================================================
20174
20275 /**
20376 * Connects to EVM and optionally announces the provider.
204- * Uses: Auth + Wallet packages
20577 * @param {Object } options - Configuration options
20678 * @param {boolean } options.announceProvider - Whether to announce the provider via EIP-6963 for wallet discovery (defaults to true)
20779 * @returns {Promise<Provider> } The EVM provider instance
@@ -277,14 +149,11 @@ export class Passport {
277149 }
278150
279151 // ============================================================================
280- // SHARED METHODS (zkEVM + IMX)
281- // Uses Auth class (public API)
282- // Exception: forceUserRefresh for silent login (advanced operation)
152+ // AUTH METHODS
283153 // ============================================================================
284154
285155 /**
286- * Logs in the user (works for both zkEVM and IMX).
287- * Uses: Auth class
156+ * Logs in the user.
288157 * @param {Object } [options] - Login options
289158 * @param {boolean } [options.useCachedSession] - If true, attempts to use a cached session without user interaction.
290159 * @param {boolean } [options.useSilentLogin] - If true, attempts silent authentication without user interaction.
@@ -313,16 +182,14 @@ export class Passport {
313182
314183 /**
315184 * Handles the login callback from the authentication service.
316- * Uses: Auth class
317185 * @returns {Promise<void> } A promise that resolves when the login callback is handled
318186 */
319187 public async loginCallback ( ) : Promise < void > {
320188 await this . auth . loginCallback ( ) ;
321189 }
322190
323191 /**
324- * Logs out the user (works for both zkEVM and IMX).
325- * Uses: Auth class
192+ * Logs out the user.
326193 * @returns {Promise<void> } A promise that resolves when the user is logged out
327194 */
328195 public async logout ( ) : Promise < void > {
@@ -331,7 +198,6 @@ export class Passport {
331198
332199 /**
333200 * Retrieves the current user's information.
334- * Uses: Auth class
335201 * @returns {Promise<UserProfile | undefined> } A promise that resolves to the user profile if logged in, undefined otherwise
336202 */
337203 public async getUserInfo ( ) : Promise < UserProfile | undefined > {
@@ -433,7 +299,7 @@ export class Passport {
433299 * @param {LinkWalletParams } params - Parameters for linking the wallet
434300 * @returns {Promise<LinkedWallet> } A promise that resolves to the linked wallet information
435301 * @throws {PassportError } If the user is not logged in (NOT_LOGGED_IN_ERROR)
436- * - If the user is not registered with StarkEx (USER_NOT_REGISTERED_ERROR)
302+ * - If the user is not registered (USER_NOT_REGISTERED_ERROR)
437303 * - If the wallet is already linked (LINK_WALLET_ALREADY_LINKED_ERROR)
438304 * - If the maximum number of wallets are linked (LINK_WALLET_MAX_WALLETS_LINKED_ERROR)
439305 * - Duplicate nonce used (LINK_WALLET_DUPLICATE_NONCE_ERROR)
@@ -461,23 +327,7 @@ export class Passport {
461327 throw new PassportError ( 'User is not logged in' , PassportErrorType . NOT_LOGGED_IN_ERROR ) ;
462328 }
463329
464- const isRegisteredWithZkEvm = isUserZkEvm ( user ) ;
465- const isRegisteredWithIMX = ( ( ) => {
466- try {
467- toUserImx ( user ) ;
468- return true ;
469- } catch ( imxError ) {
470- if (
471- imxError instanceof PassportError
472- && imxError . type === PassportErrorType . USER_NOT_REGISTERED_ERROR
473- ) {
474- return false ;
475- }
476- throw imxError ;
477- }
478- } ) ( ) ;
479-
480- if ( ! isRegisteredWithIMX && ! isRegisteredWithZkEvm ) {
330+ if ( ! isUserZkEvm ( user ) ) {
481331 throw new PassportError ( 'User has not been registered' , PassportErrorType . USER_NOT_REGISTERED_ERROR ) ;
482332 }
483333
0 commit comments