diff --git a/packages/passport/sdk/src/Passport.int.test.ts b/packages/passport/sdk/src/Passport.int.test.ts index 2f8ecb9dc6..d3075ba157 100644 --- a/packages/passport/sdk/src/Passport.int.test.ts +++ b/packages/passport/sdk/src/Passport.int.test.ts @@ -15,10 +15,10 @@ import { mswHandlers, } from './mocks/zkEvm/msw'; import { JsonRpcError, RpcErrorCode } from './zkEvm/JsonRpcError'; -import GuardianClient from './guardian/guardian'; +import GuardianClient from './guardian'; import { chainIdHex } from './test/mocks'; -jest.mock('./guardian/guardian'); +jest.mock('./guardian'); jest.mock('magic-sdk'); jest.mock('oidc-client-ts'); diff --git a/packages/passport/sdk/src/Passport.ts b/packages/passport/sdk/src/Passport.ts index bd254d8176..62cc20f022 100644 --- a/packages/passport/sdk/src/Passport.ts +++ b/packages/passport/sdk/src/Passport.ts @@ -26,6 +26,7 @@ import { ConfirmationScreen } from './confirmation'; import { ZkEvmProvider } from './zkEvm'; import { Provider } from './zkEvm/types'; import TypedEventEmitter from './utils/typedEventEmitter'; +import GuardianClient from './guardian'; const buildImxClientConfig = (passportModuleConfiguration: PassportModuleConfiguration) => { if (passportModuleConfiguration.overrides) { @@ -56,16 +57,21 @@ export const buildPrivateVars = (passportModuleConfiguration: PassportModuleConf ? passportModuleConfiguration.overrides.immutableXClient : new IMXClient({ baseConfig: passportModuleConfiguration.baseConfig }); + const guardianClient = new GuardianClient({ + confirmationScreen, + config, + authManager, + }); + const imxApiClients = buildImxApiClients(passportModuleConfiguration); const passportImxProviderFactory = new PassportImxProviderFactory({ authManager, - config, - confirmationScreen, immutableXClient, magicAdapter, passportEventEmitter, imxApiClients, + guardianClient, }); return { @@ -77,6 +83,7 @@ export const buildPrivateVars = (passportModuleConfiguration: PassportModuleConf multiRollupApiClients, passportEventEmitter, passportImxProviderFactory, + guardianClient, }; }; @@ -97,6 +104,8 @@ export class Passport { private readonly passportEventEmitter: TypedEventEmitter; + private readonly guardianClient: GuardianClient; + constructor(passportModuleConfiguration: PassportModuleConfiguration) { const privateVars = buildPrivateVars(passportModuleConfiguration); @@ -108,6 +117,7 @@ export class Passport { this.multiRollupApiClients = privateVars.multiRollupApiClients; this.passportEventEmitter = privateVars.passportEventEmitter; this.passportImxProviderFactory = privateVars.passportImxProviderFactory; + this.guardianClient = privateVars.guardianClient; setPassportClientId(passportModuleConfiguration.clientId); track('passport', 'initialised'); @@ -131,8 +141,8 @@ export class Passport { authManager: this.authManager, magicAdapter: this.magicAdapter, config: this.config, - confirmationScreen: this.confirmationScreen, multiRollupApiClients: this.multiRollupApiClients, + guardianClient: this.guardianClient, }); } diff --git a/packages/passport/sdk/src/guardian/guardian.test.ts b/packages/passport/sdk/src/guardian/index.test.ts similarity index 99% rename from packages/passport/sdk/src/guardian/guardian.test.ts rename to packages/passport/sdk/src/guardian/index.test.ts index 20a8e647b5..c90a38aded 100644 --- a/packages/passport/sdk/src/guardian/guardian.test.ts +++ b/packages/passport/sdk/src/guardian/index.test.ts @@ -3,7 +3,7 @@ import * as guardian from '@imtbl/guardian'; import { TransactionRequest } from '@ethersproject/providers'; import { ImmutableConfiguration } from '@imtbl/config'; import AuthManager from 'authManager'; -import GuardianClient from './guardian'; +import GuardianClient from './index'; import { mockUser, mockUserImx, mockUserZkEvm } from '../test/mocks'; import { JsonRpcError, RpcErrorCode } from '../zkEvm/JsonRpcError'; import { PassportConfiguration } from '../config'; diff --git a/packages/passport/sdk/src/guardian/guardian.ts b/packages/passport/sdk/src/guardian/index.ts similarity index 100% rename from packages/passport/sdk/src/guardian/guardian.ts rename to packages/passport/sdk/src/guardian/index.ts diff --git a/packages/passport/sdk/src/starkEx/passportImxProvider.test.ts b/packages/passport/sdk/src/starkEx/passportImxProvider.test.ts index 17e46929c3..9a57101c50 100644 --- a/packages/passport/sdk/src/starkEx/passportImxProvider.test.ts +++ b/packages/passport/sdk/src/starkEx/passportImxProvider.test.ts @@ -17,19 +17,18 @@ import { import { Web3Provider } from '@ethersproject/providers'; import { ImxApiClients } from '@imtbl/generated-clients'; import registerPassportStarkEx from './workflows/registration'; -import { mockUser, mockUserImx, testConfig } from '../test/mocks'; +import { mockUser, mockUserImx } from '../test/mocks'; import { PassportError, PassportErrorType } from '../errors/passportError'; import { PassportImxProvider } from './passportImxProvider'; import { batchNftTransfer, cancelOrder, createOrder, createTrade, exchangeTransfer, transfer, } from './workflows'; -import { ConfirmationScreen } from '../confirmation'; -import { PassportConfiguration } from '../config'; import { PassportEventMap, PassportEvents } from '../types'; import TypedEventEmitter from '../utils/typedEventEmitter'; import AuthManager from '../authManager'; import MagicAdapter from '../magicAdapter'; import { getStarkSigner } from './getStarkSigner'; +import GuardianClient from '../guardian'; jest.mock('@ethersproject/providers'); jest.mock('./workflows'); @@ -48,8 +47,6 @@ describe('PassportImxProvider', () => { }), }); - const confirmationScreen = new ConfirmationScreen({} as PassportConfiguration); - const mockAuthManager = { login: jest.fn(), getUser: jest.fn(), @@ -70,6 +67,8 @@ describe('PassportImxProvider', () => { login: jest.fn(), }; + const mockGuardianClient = {}; + const getSignerMock = jest.fn(); let passportEventEmitter: TypedEventEmitter; @@ -91,9 +90,8 @@ describe('PassportImxProvider', () => { passportImxProvider = new PassportImxProvider({ authManager: mockAuthManager as unknown as AuthManager, magicAdapter: magicAdapterMock as unknown as MagicAdapter, - confirmationScreen, + guardianClient: mockGuardianClient as unknown as GuardianClient, immutableXClient, - config: testConfig, passportEventEmitter, imxApiClients, }); @@ -129,9 +127,8 @@ describe('PassportImxProvider', () => { const pp = new PassportImxProvider({ authManager: mockAuthManager as unknown as AuthManager, magicAdapter: magicAdapterMock as unknown as MagicAdapter, - confirmationScreen, + guardianClient: mockGuardianClient as unknown as GuardianClient, immutableXClient, - config: testConfig, passportEventEmitter: new TypedEventEmitter(), imxApiClients: new ImxApiClients({} as any), }); @@ -154,8 +151,7 @@ describe('PassportImxProvider', () => { user: mockUserImx, starkSigner: mockStarkSigner, transfersApi: immutableXClient.transfersApi, - // @ts-ignore - guardianClient: passportImxProvider.guardianClient, + guardianClient: mockGuardianClient, }); expect(result) .toEqual(returnValue); @@ -198,8 +194,7 @@ describe('PassportImxProvider', () => { user: mockUserImx, starkSigner: mockStarkSigner, ordersApi: immutableXClient.ordersApi, - // @ts-ignore - guardianClient: passportImxProvider.guardianClient, + guardianClient: mockGuardianClient, }); expect(result) .toEqual(returnValue); @@ -220,8 +215,7 @@ describe('PassportImxProvider', () => { user: mockUserImx, starkSigner: mockStarkSigner, ordersApi: immutableXClient.ordersApi, - // @ts-ignore - guardianClient: passportImxProvider.guardianClient, + guardianClient: mockGuardianClient, }); expect(result) .toEqual(returnValue); @@ -242,8 +236,7 @@ describe('PassportImxProvider', () => { user: mockUserImx, starkSigner: mockStarkSigner, tradesApi: immutableXClient.tradesApi, - // @ts-ignore - guardianClient: passportImxProvider.guardianClient, + guardianClient: mockGuardianClient, }); expect(result) .toEqual(returnValue); @@ -264,8 +257,7 @@ describe('PassportImxProvider', () => { user: mockUserImx, starkSigner: mockStarkSigner, transfersApi: immutableXClient.transfersApi, - // @ts-ignore - guardianClient: passportImxProvider.guardianClient, + guardianClient: mockGuardianClient, }); expect(result) .toEqual(returnValue); diff --git a/packages/passport/sdk/src/starkEx/passportImxProvider.ts b/packages/passport/sdk/src/starkEx/passportImxProvider.ts index cdb8801f6f..404a93e6be 100644 --- a/packages/passport/sdk/src/starkEx/passportImxProvider.ts +++ b/packages/passport/sdk/src/starkEx/passportImxProvider.ts @@ -24,7 +24,7 @@ import { Web3Provider } from '@ethersproject/providers'; import { ImxApiClients } from '@imtbl/generated-clients'; import TypedEventEmitter from '../utils/typedEventEmitter'; import AuthManager from '../authManager'; -import GuardianClient from '../guardian/guardian'; +import GuardianClient from '../guardian'; import { PassportEventMap, PassportEvents, UserImx, User, IMXSigners, } from '../types'; @@ -32,8 +32,6 @@ import { PassportError, PassportErrorType } from '../errors/passportError'; import { batchNftTransfer, cancelOrder, createOrder, createTrade, exchangeTransfer, transfer, } from './workflows'; -import { ConfirmationScreen } from '../confirmation'; -import { PassportConfiguration } from '../config'; import registerOffchain from './workflows/registerOffchain'; import MagicAdapter from '../magicAdapter'; import { getStarkSigner } from './getStarkSigner'; @@ -41,11 +39,10 @@ import { getStarkSigner } from './getStarkSigner'; export interface PassportImxProviderOptions { authManager: AuthManager; immutableXClient: IMXClient; - confirmationScreen: ConfirmationScreen; - config: PassportConfiguration; passportEventEmitter: TypedEventEmitter; magicAdapter: MagicAdapter; imxApiClients: ImxApiClients; + guardianClient: GuardianClient; } type AuthenticatedUserAndSigners = { @@ -84,21 +81,16 @@ export class PassportImxProvider implements IMXProvider { constructor({ authManager, immutableXClient, - confirmationScreen, - config, passportEventEmitter, magicAdapter, imxApiClients, + guardianClient, }: PassportImxProviderOptions) { this.authManager = authManager; this.immutableXClient = immutableXClient; - this.guardianClient = new GuardianClient({ - confirmationScreen, - config, - authManager, - }); this.magicAdapter = magicAdapter; this.imxApiClients = imxApiClients; + this.guardianClient = guardianClient; this.initialiseSigners(); passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout); diff --git a/packages/passport/sdk/src/starkEx/passportImxProviderFactory.test.ts b/packages/passport/sdk/src/starkEx/passportImxProviderFactory.test.ts index c9f3884899..903cd09307 100644 --- a/packages/passport/sdk/src/starkEx/passportImxProviderFactory.test.ts +++ b/packages/passport/sdk/src/starkEx/passportImxProviderFactory.test.ts @@ -1,15 +1,15 @@ import { IMXClient } from '@imtbl/x-client'; import { ImxApiClients } from '@imtbl/generated-clients'; -import { ConfirmationScreen } from '../confirmation'; import registerPassportStarkEx from './workflows/registration'; import { PassportImxProviderFactory } from './passportImxProviderFactory'; import MagicAdapter from '../magicAdapter'; import AuthManager from '../authManager'; import { PassportError, PassportErrorType } from '../errors/passportError'; import { PassportEventMap } from '../types'; -import { mockUserImx, testConfig } from '../test/mocks'; +import { mockUserImx } from '../test/mocks'; import TypedEventEmitter from '../utils/typedEventEmitter'; import { PassportImxProvider } from './passportImxProvider'; +import GuardianClient from '../guardian'; jest.mock('./workflows/registration'); jest.mock('./passportImxProvider'); @@ -27,17 +27,15 @@ describe('PassportImxProviderFactory', () => { const immutableXClient = { usersApi: {}, } as IMXClient; - const confirmationScreen = {} as ConfirmationScreen; - const config = testConfig; + const guardianClient = {} as GuardianClient; const passportEventEmitter = new TypedEventEmitter(); const passportImxProviderFactory = new PassportImxProviderFactory({ - config, - confirmationScreen, immutableXClient, authManager: mockAuthManager as unknown as AuthManager, magicAdapter: mockMagicAdapter as unknown as MagicAdapter, passportEventEmitter, imxApiClients, + guardianClient, }); const mockPassportImxProvider = {}; @@ -89,10 +87,9 @@ describe('PassportImxProviderFactory', () => { magicAdapter: mockMagicAdapter, authManager: mockAuthManager, immutableXClient, - config, - confirmationScreen, passportEventEmitter, imxApiClients: new ImxApiClients({} as any), + guardianClient, }); }); }); diff --git a/packages/passport/sdk/src/starkEx/passportImxProviderFactory.ts b/packages/passport/sdk/src/starkEx/passportImxProviderFactory.ts index c2f046b4ba..0dfcc7771d 100644 --- a/packages/passport/sdk/src/starkEx/passportImxProviderFactory.ts +++ b/packages/passport/sdk/src/starkEx/passportImxProviderFactory.ts @@ -2,31 +2,25 @@ import { IMXClient } from '@imtbl/x-client'; import { IMXProvider } from '@imtbl/x-provider'; import { ImxApiClients } from '@imtbl/generated-clients'; import { PassportError, PassportErrorType } from '../errors/passportError'; -import { PassportConfiguration } from '../config'; import AuthManager from '../authManager'; -import { ConfirmationScreen } from '../confirmation'; import MagicAdapter from '../magicAdapter'; import { PassportEventMap, User } from '../types'; import TypedEventEmitter from '../utils/typedEventEmitter'; import { PassportImxProvider } from './passportImxProvider'; +import GuardianClient from '../guardian'; export type PassportImxProviderFactoryInput = { authManager: AuthManager; - config: PassportConfiguration; - confirmationScreen: ConfirmationScreen; immutableXClient: IMXClient; magicAdapter: MagicAdapter; passportEventEmitter: TypedEventEmitter; imxApiClients: ImxApiClients; + guardianClient: GuardianClient; }; export class PassportImxProviderFactory { private readonly authManager: AuthManager; - private readonly config: PassportConfiguration; - - private readonly confirmationScreen: ConfirmationScreen; - private readonly immutableXClient: IMXClient; private readonly magicAdapter: MagicAdapter; @@ -35,22 +29,22 @@ export class PassportImxProviderFactory { public readonly imxApiClients: ImxApiClients; + private readonly guardianClient: GuardianClient; + constructor({ authManager, - config, - confirmationScreen, immutableXClient, magicAdapter, passportEventEmitter, imxApiClients, + guardianClient, }: PassportImxProviderFactoryInput) { this.authManager = authManager; - this.config = config; - this.confirmationScreen = confirmationScreen; this.immutableXClient = immutableXClient; this.magicAdapter = magicAdapter; this.passportEventEmitter = passportEventEmitter; this.imxApiClients = imxApiClients; + this.guardianClient = guardianClient; } public async getProvider(): Promise { @@ -85,13 +79,12 @@ export class PassportImxProviderFactory { } return new PassportImxProvider({ - config: this.config, authManager: this.authManager, immutableXClient: this.immutableXClient, - confirmationScreen: this.confirmationScreen, passportEventEmitter: this.passportEventEmitter, magicAdapter: this.magicAdapter, imxApiClients: this.imxApiClients, + guardianClient: this.guardianClient, }); } } diff --git a/packages/passport/sdk/src/starkEx/workflows/order.test.ts b/packages/passport/sdk/src/starkEx/workflows/order.test.ts index 9ac01c35ac..3062ec991e 100644 --- a/packages/passport/sdk/src/starkEx/workflows/order.test.ts +++ b/packages/passport/sdk/src/starkEx/workflows/order.test.ts @@ -1,10 +1,10 @@ import { ETHAmount, OrdersApi, UnsignedOrderRequest } from '@imtbl/core-sdk'; -import GuardianClient from '../../guardian/guardian'; +import GuardianClient from '../../guardian'; import { PassportError, PassportErrorType } from '../../errors/passportError'; import { mockErrorMessage, mockStarkSignature, mockUserImx } from '../../test/mocks'; import { cancelOrder, createOrder } from './order'; -jest.mock('../../guardian/guardian'); +jest.mock('../../guardian'); describe('order', () => { const mockGuardianClient = new GuardianClient({} as any); diff --git a/packages/passport/sdk/src/starkEx/workflows/order.ts b/packages/passport/sdk/src/starkEx/workflows/order.ts index fd3a7a044e..df4b50ef75 100644 --- a/packages/passport/sdk/src/starkEx/workflows/order.ts +++ b/packages/passport/sdk/src/starkEx/workflows/order.ts @@ -11,7 +11,7 @@ import { import { convertToSignableToken } from '@imtbl/toolkit'; import { PassportErrorType, withPassportError } from '../../errors/passportError'; import { UserImx } from '../../types'; -import GuardianClient from '../../guardian/guardian'; +import GuardianClient from '../../guardian'; type CancelOrderParams = { request: GetSignableCancelOrderRequest; diff --git a/packages/passport/sdk/src/starkEx/workflows/trades.test.ts b/packages/passport/sdk/src/starkEx/workflows/trades.test.ts index 50425f960f..231d2db84e 100644 --- a/packages/passport/sdk/src/starkEx/workflows/trades.test.ts +++ b/packages/passport/sdk/src/starkEx/workflows/trades.test.ts @@ -2,9 +2,9 @@ import { TradesApi } from '@imtbl/core-sdk'; import { createTrade } from './trades'; import { mockErrorMessage, mockStarkSignature, mockUserImx } from '../../test/mocks'; import { PassportError, PassportErrorType } from '../../errors/passportError'; -import GuardianClient from '../../guardian/guardian'; +import GuardianClient from '../../guardian'; -jest.mock('../../guardian/guardian'); +jest.mock('../../guardian'); const mockPayloadHash = 'test_payload_hash'; const mockSignableTradeRequest = { diff --git a/packages/passport/sdk/src/starkEx/workflows/trades.ts b/packages/passport/sdk/src/starkEx/workflows/trades.ts index bef155d171..4f767944b7 100644 --- a/packages/passport/sdk/src/starkEx/workflows/trades.ts +++ b/packages/passport/sdk/src/starkEx/workflows/trades.ts @@ -7,7 +7,7 @@ import { } from '@imtbl/core-sdk'; import { PassportErrorType, withPassportError } from '../../errors/passportError'; import { UserImx } from '../../types'; -import GuardianClient from '../../guardian/guardian'; +import GuardianClient from '../../guardian'; type CreateTradeParams = { request: GetSignableTradeRequest; diff --git a/packages/passport/sdk/src/starkEx/workflows/transfer.test.ts b/packages/passport/sdk/src/starkEx/workflows/transfer.test.ts index e5da2a8f09..19d5470ceb 100644 --- a/packages/passport/sdk/src/starkEx/workflows/transfer.test.ts +++ b/packages/passport/sdk/src/starkEx/workflows/transfer.test.ts @@ -2,9 +2,9 @@ import { TransfersApi, UnsignedTransferRequest } from '@imtbl/core-sdk'; import { PassportError, PassportErrorType } from '../../errors/passportError'; import { mockErrorMessage, mockStarkSignature, mockUserImx } from '../../test/mocks'; import { batchNftTransfer, transfer } from './transfer'; -import GuardianClient from '../../guardian/guardian'; +import GuardianClient from '../../guardian'; -jest.mock('../../guardian/guardian'); +jest.mock('../../guardian'); describe('transfer', () => { const mockGuardianClient = new GuardianClient({} as any); diff --git a/packages/passport/sdk/src/starkEx/workflows/transfer.ts b/packages/passport/sdk/src/starkEx/workflows/transfer.ts index 609b5ff4c1..30ae527659 100644 --- a/packages/passport/sdk/src/starkEx/workflows/transfer.ts +++ b/packages/passport/sdk/src/starkEx/workflows/transfer.ts @@ -14,7 +14,7 @@ import { withPassportError, } from '../../errors/passportError'; import { UserImx } from '../../types'; -import GuardianClient from '../../guardian/guardian'; +import GuardianClient from '../../guardian'; const ERC721 = 'ERC721'; diff --git a/packages/passport/sdk/src/zkEvm/sendTransaction.test.ts b/packages/passport/sdk/src/zkEvm/sendTransaction.test.ts index ec8c6de074..efc9e79c63 100644 --- a/packages/passport/sdk/src/zkEvm/sendTransaction.test.ts +++ b/packages/passport/sdk/src/zkEvm/sendTransaction.test.ts @@ -6,7 +6,7 @@ import { RelayerClient } from './relayerClient'; import { retryWithDelay } from '../network/retry'; import { RelayerTransaction, RelayerTransactionStatus } from './types'; import { JsonRpcError, RpcErrorCode } from './JsonRpcError'; -import GuardianClient from '../guardian/guardian'; +import GuardianClient from '../guardian'; jest.mock('@ethersproject/providers'); jest.mock('./walletHelpers'); diff --git a/packages/passport/sdk/src/zkEvm/sendTransaction.ts b/packages/passport/sdk/src/zkEvm/sendTransaction.ts index 1a78fa1766..ec5a35fe26 100644 --- a/packages/passport/sdk/src/zkEvm/sendTransaction.ts +++ b/packages/passport/sdk/src/zkEvm/sendTransaction.ts @@ -7,7 +7,7 @@ import { MetaTransaction, RelayerTransactionStatus } from './types'; import { JsonRpcError, RpcErrorCode } from './JsonRpcError'; import { retryWithDelay } from '../network/retry'; import { RelayerClient } from './relayerClient'; -import GuardianClient, { convertBigNumberishToString } from '../guardian/guardian'; +import GuardianClient, { convertBigNumberishToString } from '../guardian'; const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30; const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000; diff --git a/packages/passport/sdk/src/zkEvm/signTypedDataV4.test.ts b/packages/passport/sdk/src/zkEvm/signTypedDataV4.test.ts index 64936f39c7..cfeba5f75c 100644 --- a/packages/passport/sdk/src/zkEvm/signTypedDataV4.test.ts +++ b/packages/passport/sdk/src/zkEvm/signTypedDataV4.test.ts @@ -1,6 +1,6 @@ import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers'; import { BigNumber } from 'ethers'; -import GuardianClient from 'guardian/guardian'; +import GuardianClient from 'guardian'; import { getEip155ChainId, getSignedTypedData } from './walletHelpers'; import { chainId, diff --git a/packages/passport/sdk/src/zkEvm/signTypedDataV4.ts b/packages/passport/sdk/src/zkEvm/signTypedDataV4.ts index 3b36932b57..300da1f946 100644 --- a/packages/passport/sdk/src/zkEvm/signTypedDataV4.ts +++ b/packages/passport/sdk/src/zkEvm/signTypedDataV4.ts @@ -4,7 +4,7 @@ import { Web3Provider, } from '@ethersproject/providers'; import { BigNumber } from 'ethers'; -import GuardianClient from 'guardian/guardian'; +import GuardianClient from 'guardian'; import { getSignedTypedData } from './walletHelpers'; import { TypedDataPayload } from './types'; import { JsonRpcError, RpcErrorCode } from './JsonRpcError'; diff --git a/packages/passport/sdk/src/zkEvm/user/loginZkEvmUser.test.ts b/packages/passport/sdk/src/zkEvm/user/loginZkEvmUser.test.ts index bddf886205..952d157f68 100644 --- a/packages/passport/sdk/src/zkEvm/user/loginZkEvmUser.test.ts +++ b/packages/passport/sdk/src/zkEvm/user/loginZkEvmUser.test.ts @@ -1,6 +1,4 @@ import { mockUser, mockUserZkEvm } from 'test/mocks'; -import { PassportConfiguration } from 'config'; -import { ImmutableConfiguration } from '@imtbl/config'; import { MultiRollupApiClients } from '@imtbl/generated-clients'; import { JsonRpcProvider } from '@ethersproject/providers'; import { loginZkEvmUser } from './loginZkEvmUser'; @@ -24,20 +22,12 @@ describe('loginZkEvmUser', () => { login: () => magicProvider, } as unknown as MagicAdapter; - const config = new PassportConfiguration({ - baseConfig: {} as ImmutableConfiguration, - clientId: 'client123', - logoutRedirectUri: 'http://localhost:3000/logout', - redirectUri: 'http://localhost:3000/redirect', - }); - const multiRollupApiClients = { } as unknown as MultiRollupApiClients; it('should return a user that has registered with zkEvm', async () => { getUserMock.mockResolvedValue(mockUserZkEvm); const result = await loginZkEvmUser({ authManager, - config, magicAdapter, multiRollupApiClients, jsonRpcProvider: {} as JsonRpcProvider, @@ -56,7 +46,6 @@ describe('loginZkEvmUser', () => { (registerZkEvmUser as unknown as jest.Mock).mockResolvedValue(mockUserZkEvm); const result = await loginZkEvmUser({ authManager, - config, magicAdapter, multiRollupApiClients, jsonRpcProvider: {} as JsonRpcProvider, @@ -74,7 +63,6 @@ describe('loginZkEvmUser', () => { (authManager.login as unknown as jest.Mock).mockResolvedValue(mockUserZkEvm); const result = await loginZkEvmUser({ authManager, - config, magicAdapter, multiRollupApiClients, jsonRpcProvider: {} as JsonRpcProvider, diff --git a/packages/passport/sdk/src/zkEvm/user/loginZkEvmUser.ts b/packages/passport/sdk/src/zkEvm/user/loginZkEvmUser.ts index c57b4ca7ef..b38b7c784c 100644 --- a/packages/passport/sdk/src/zkEvm/user/loginZkEvmUser.ts +++ b/packages/passport/sdk/src/zkEvm/user/loginZkEvmUser.ts @@ -3,12 +3,10 @@ import { ExternalProvider, JsonRpcProvider } from '@ethersproject/providers'; import { registerZkEvmUser } from './registerZkEvmUser'; import { UserZkEvm } from '../../types'; import AuthManager from '../../authManager'; -import { PassportConfiguration } from '../../config'; import MagicAdapter from '../../magicAdapter'; type LoginZkEvmUserInput = { authManager: AuthManager; - config: PassportConfiguration; magicAdapter: MagicAdapter; multiRollupApiClients: MultiRollupApiClients; jsonRpcProvider: JsonRpcProvider; diff --git a/packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts b/packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts index 4490517a10..2cfda91103 100644 --- a/packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts +++ b/packages/passport/sdk/src/zkEvm/zkEvmProvider.test.ts @@ -4,12 +4,12 @@ import { ZkEvmProviderInput, ZkEvmProvider } from './zkEvmProvider'; import { loginZkEvmUser } from './user'; import { sendTransaction } from './sendTransaction'; import { JsonRpcError, ProviderErrorCode } from './JsonRpcError'; -import GuardianClient from '../guardian/guardian'; +import GuardianClient from '../guardian'; import { RelayerClient } from './relayerClient'; import { Provider } from './types'; import { PassportEventMap, PassportEvents } from '../types'; import TypedEventEmitter from '../utils/typedEventEmitter'; -import { mockUserZkEvm } from '../test/mocks'; +import { mockUserZkEvm, testConfig } from '../test/mocks'; import { signTypedDataV4 } from './signTypedDataV4'; jest.mock('@ethersproject/providers'); @@ -23,16 +23,22 @@ describe('ZkEvmProvider', () => { beforeEach(() => { passportEventEmitter = new TypedEventEmitter(); + jest.resetAllMocks(); }); + const config = testConfig; + const authManager = { + getUser: jest.fn().mockResolvedValue(mockUserZkEvm), + removeUser: jest.fn(), + } as unknown as AuthManager; + const guardianClient = {} as GuardianClient; + const getProvider = () => { const constructorParameters = { - config: {}, - authManager: { - getUser: jest.fn().mockResolvedValue(mockUserZkEvm), - removeUser: jest.fn(), - } as unknown as AuthManager, + config, + authManager, passportEventEmitter, + guardianClient, } as Partial; return new ZkEvmProvider(constructorParameters as ZkEvmProviderInput); @@ -272,8 +278,8 @@ describe('ZkEvmProvider', () => { expect(result).toEqual(transactionHash); expect(sendTransaction).toHaveBeenCalledWith({ params: [transaction], + guardianClient, magicProvider: mockMagicProvider, - guardianClient: expect.any(GuardianClient), jsonRpcProvider: expect.any(Object), relayerClient: expect.any(RelayerClient), zkevmAddress: mockUserZkEvm.zkEvm.ethAddress, @@ -315,10 +321,10 @@ describe('ZkEvmProvider', () => { expect(signTypedDataV4).toHaveBeenCalledWith({ method: 'eth_signTypedData_v4', params: [address, typedDataPayload], + guardianClient, magicProvider: mockMagicProvider, jsonRpcProvider: expect.any(Object), relayerClient: expect.any(RelayerClient), - guardianClient: expect.any(GuardianClient), }); }); }); @@ -344,7 +350,6 @@ describe('ZkEvmProvider', () => { const userLoggedInKeys = [ 'magicProvider', 'relayerClient', - 'guardianClient', ]; userLoggedInKeys.forEach((key) => { diff --git a/packages/passport/sdk/src/zkEvm/zkEvmProvider.ts b/packages/passport/sdk/src/zkEvm/zkEvmProvider.ts index 92f5be15b2..afe10df1c1 100644 --- a/packages/passport/sdk/src/zkEvm/zkEvmProvider.ts +++ b/packages/passport/sdk/src/zkEvm/zkEvmProvider.ts @@ -13,7 +13,6 @@ import AuthManager from '../authManager'; import MagicAdapter from '../magicAdapter'; import TypedEventEmitter from '../utils/typedEventEmitter'; import { PassportConfiguration } from '../config'; -import { ConfirmationScreen } from '../confirmation'; import { PassportEventMap, PassportEvents, } from '../types'; @@ -21,22 +20,21 @@ import { RelayerClient } from './relayerClient'; import { JsonRpcError, ProviderErrorCode, RpcErrorCode } from './JsonRpcError'; import { loginZkEvmUser } from './user'; import { sendTransaction } from './sendTransaction'; -import GuardianClient from '../guardian/guardian'; +import GuardianClient from '../guardian'; import { signTypedDataV4 } from './signTypedDataV4'; export type ZkEvmProviderInput = { authManager: AuthManager; magicAdapter: MagicAdapter, config: PassportConfiguration, - confirmationScreen: ConfirmationScreen, multiRollupApiClients: MultiRollupApiClients, passportEventEmitter: TypedEventEmitter; + guardianClient: GuardianClient; }; type LoggedInZkEvmProvider = { magicProvider: ExternalProvider; relayerClient: RelayerClient; - guardianClient: GuardianClient; zkevmAddress: string; }; @@ -45,8 +43,6 @@ export class ZkEvmProvider implements Provider { private readonly config: PassportConfiguration; - private readonly confirmationScreen: ConfirmationScreen; - private readonly magicAdapter: MagicAdapter; private readonly multiRollupApiClients: MultiRollupApiClients; @@ -55,7 +51,7 @@ export class ZkEvmProvider implements Provider { private readonly eventEmitter: TypedEventEmitter; - protected guardianClient?: GuardianClient; + private readonly guardianClient: GuardianClient; protected relayerClient?: RelayerClient; @@ -69,14 +65,14 @@ export class ZkEvmProvider implements Provider { authManager, magicAdapter, config, - confirmationScreen, multiRollupApiClients, passportEventEmitter, + guardianClient, }: ZkEvmProviderInput) { this.authManager = authManager; this.magicAdapter = magicAdapter; this.config = config; - this.confirmationScreen = confirmationScreen; + this.guardianClient = guardianClient; if (config.crossSdkBridgeEnabled) { // JsonRpcProvider by default sets the referrer as "client". @@ -100,7 +96,6 @@ export class ZkEvmProvider implements Provider { this.magicProvider = undefined; this.relayerClient = undefined; - this.guardianClient = undefined; if (shouldEmitAccountsChanged) { this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []); @@ -110,8 +105,7 @@ export class ZkEvmProvider implements Provider { private isLoggedIn(): this is LoggedInZkEvmProvider { return this.magicProvider !== undefined && this.zkevmAddress !== undefined - && this.relayerClient !== undefined - && this.guardianClient !== undefined; + && this.relayerClient !== undefined; } private async performRequest(request: RequestArguments): Promise { @@ -120,25 +114,19 @@ export class ZkEvmProvider implements Provider { if (this.isLoggedIn()) { return [this.zkevmAddress]; } + const { magicProvider, user } = await loginZkEvmUser({ authManager: this.authManager, - config: this.config, magicAdapter: this.magicAdapter, multiRollupApiClients: this.multiRollupApiClients, jsonRpcProvider: this.jsonRpcProvider, }); - this.magicProvider = magicProvider; this.relayerClient = new RelayerClient({ config: this.config, jsonRpcProvider: this.jsonRpcProvider, authManager: this.authManager, }); - this.guardianClient = new GuardianClient({ - confirmationScreen: this.confirmationScreen, - config: this.config, - authManager: this.authManager, - }); this.zkevmAddress = user.zkEvm.ethAddress;