11import { IMXProvider } from '@imtbl/x-provider' ;
22import {
3- createConfig , ImxApiClients , imxApiConfig , MultiRollupApiClients ,
3+ createConfig , ImxApiClients , imxApiConfig , MagicTeeApiClients , MultiRollupApiClients ,
44} from '@imtbl/generated-clients' ;
55import { IMXClient } from '@imtbl/x-client' ;
66import { Environment } from '@imtbl/config' ;
@@ -11,7 +11,7 @@ import {
1111} from '@imtbl/metrics' ;
1212import { isAxiosError } from 'axios' ;
1313import AuthManager from './authManager' ;
14- import MagicAdapter from './magic/magicAdapter ' ;
14+ import MagicTEESigner from './magic/magicTEESigner ' ;
1515import { PassportImxProviderFactory } from './starkEx' ;
1616import { PassportConfiguration } from './config' ;
1717import {
@@ -38,7 +38,6 @@ import logger from './utils/logger';
3838import { announceProvider , passportProviderInfo } from './zkEvm/provider/eip6963' ;
3939import { isAPIError , PassportError , PassportErrorType } from './errors/passportError' ;
4040import { withMetricsAsync } from './utils/metrics' ;
41- import { MagicProviderProxyFactory } from './magic/magicProviderProxyFactory' ;
4241
4342const buildImxClientConfig = ( passportModuleConfiguration : PassportModuleConfiguration ) => {
4443 if ( passportModuleConfiguration . overrides ) {
@@ -61,9 +60,14 @@ export const buildPrivateVars = (passportModuleConfiguration: PassportModuleConf
6160 const config = new PassportConfiguration ( passportModuleConfiguration ) ;
6261 const embeddedLoginPrompt = new EmbeddedLoginPrompt ( config ) ;
6362 const authManager = new AuthManager ( config , embeddedLoginPrompt ) ;
64- const magicProviderProxyFactory = new MagicProviderProxyFactory ( authManager , config ) ;
65- const magicAdapter = new MagicAdapter ( config , magicProviderProxyFactory ) ;
6663 const confirmationScreen = new ConfirmationScreen ( config ) ;
64+ const magicTeeApiClients = new MagicTeeApiClients ( {
65+ basePath : config . magicTeeBasePath ,
66+ timeout : config . magicTeeTimeout ,
67+ magicPublishableApiKey : config . magicPublishableApiKey ,
68+ magicProviderId : config . magicProviderId ,
69+ } ) ;
70+ const magicTEESigner = new MagicTEESigner ( authManager , magicTeeApiClients ) ;
6771 const multiRollupApiClients = new MultiRollupApiClients ( config . multiRollupConfig ) ;
6872 const passportEventEmitter = new TypedEventEmitter < PassportEventMap > ( ) ;
6973
@@ -83,7 +87,7 @@ export const buildPrivateVars = (passportModuleConfiguration: PassportModuleConf
8387 const passportImxProviderFactory = new PassportImxProviderFactory ( {
8488 authManager,
8589 immutableXClient,
86- magicAdapter ,
90+ magicTEESigner ,
8791 passportEventEmitter,
8892 imxApiClients,
8993 guardianClient,
@@ -92,7 +96,7 @@ export const buildPrivateVars = (passportModuleConfiguration: PassportModuleConf
9296 return {
9397 config,
9498 authManager,
95- magicAdapter ,
99+ magicTEESigner ,
96100 confirmationScreen,
97101 embeddedLoginPrompt,
98102 immutableXClient,
@@ -114,7 +118,7 @@ export class Passport {
114118
115119 private readonly immutableXClient : IMXClient ;
116120
117- private readonly magicAdapter : MagicAdapter ;
121+ private readonly magicTEESigner : MagicTEESigner ;
118122
119123 private readonly multiRollupApiClients : MultiRollupApiClients ;
120124
@@ -129,7 +133,7 @@ export class Passport {
129133
130134 this . config = privateVars . config ;
131135 this . authManager = privateVars . authManager ;
132- this . magicAdapter = privateVars . magicAdapter ;
136+ this . magicTEESigner = privateVars . magicTEESigner ;
133137 this . confirmationScreen = privateVars . confirmationScreen ;
134138 this . embeddedLoginPrompt = privateVars . embeddedLoginPrompt ;
135139 this . immutableXClient = privateVars . immutableXClient ;
@@ -163,17 +167,25 @@ export class Passport {
163167 * Connects to EVM and optionally announces the provider.
164168 * @param {Object } options - Configuration options
165169 * @param {boolean } options.announceProvider - Whether to announce the provider via EIP-6963 for wallet discovery (defaults to true)
166- * @returns {Provider } The EVM provider instance
170+ * @returns {Promise< Provider> } The EVM provider instance
167171 */
168- public connectEvm ( options : ConnectEvmArguments = { announceProvider : true } ) : Promise < Provider > {
172+ public async connectEvm ( options : ConnectEvmArguments = { announceProvider : true } ) : Promise < Provider > {
169173 return withMetricsAsync ( async ( ) => {
174+ let user : User | null = null ;
175+ try {
176+ user = await this . authManager . getUser ( ) ;
177+ } catch ( error ) {
178+ // Initialise the zkEvmProvider without a user
179+ }
180+
170181 const provider = new ZkEvmProvider ( {
171182 passportEventEmitter : this . passportEventEmitter ,
172183 authManager : this . authManager ,
173- magicAdapter : this . magicAdapter ,
174184 config : this . config ,
175185 multiRollupApiClients : this . multiRollupApiClients ,
176186 guardianClient : this . guardianClient ,
187+ ethSigner : this . magicTEESigner ,
188+ user,
177189 } ) ;
178190
179191 if ( options ?. announceProvider ) {
@@ -304,16 +316,7 @@ export class Passport {
304316 */
305317 public async logout ( ) : Promise < void > {
306318 return withMetricsAsync ( async ( ) => {
307- if ( this . config . oidcConfiguration . logoutMode === 'silent' ) {
308- await Promise . allSettled ( [
309- this . authManager . logout ( ) ,
310- this . magicAdapter . logout ( ) ,
311- ] ) ;
312- } else {
313- // We need to ensure that the Magic wallet is logged out BEFORE redirecting
314- await this . magicAdapter . logout ( ) ;
315- await this . authManager . logout ( ) ;
316- }
319+ await this . authManager . logout ( ) ;
317320 this . passportEventEmitter . emit ( PassportEvents . LOGGED_OUT ) ;
318321 } , 'logout' ) ;
319322 }
@@ -325,7 +328,6 @@ export class Passport {
325328 public async getLogoutUrl ( ) : Promise < string | null > {
326329 return withMetricsAsync ( async ( ) => {
327330 await this . authManager . removeUser ( ) ;
328- await this . magicAdapter . logout ( ) ;
329331 this . passportEventEmitter . emit ( PassportEvents . LOGGED_OUT ) ;
330332 return await this . authManager . getLogoutUrl ( ) ;
331333 } , 'getLogoutUrl' ) ;
0 commit comments