@imtbl/sdk 1.45.3-alpha.3 → 1.45.3-alpha.4

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/index.cjs CHANGED
@@ -215,7 +215,7 @@ const flattenProperties$1 = (properties) => {
215
215
  };
216
216
 
217
217
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
218
- const SDK_VERSION$1 = '1.45.3-alpha.3';
218
+ const SDK_VERSION$1 = '1.45.3-alpha.4';
219
219
  const getFrameParentDomain$1 = () => {
220
220
  if (isNode$1()) {
221
221
  return '';
@@ -14280,7 +14280,7 @@ class MultiRollupApiClients {
14280
14280
  }
14281
14281
 
14282
14282
  // eslint-disable-next-line @typescript-eslint/naming-convention
14283
- const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.3' };
14283
+ const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.4' };
14284
14284
  const createConfig$1 = ({ basePath, headers, }) => {
14285
14285
  if (!basePath.trim()) {
14286
14286
  throw Error('basePath can not be empty');
@@ -14352,7 +14352,7 @@ class APIError extends Error {
14352
14352
 
14353
14353
  /* eslint-disable implicit-arrow-linebreak */
14354
14354
  const defaultHeaders$1 = {
14355
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.45.3-alpha.3',
14355
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.45.3-alpha.4',
14356
14356
  };
14357
14357
  /**
14358
14358
  * createAPIConfiguration to create a custom Configuration
@@ -14826,7 +14826,7 @@ var blockchain_data = /*#__PURE__*/Object.freeze({
14826
14826
  /* eslint-disable @typescript-eslint/naming-convention */
14827
14827
  class ApiConfiguration extends index$2.Configuration {
14828
14828
  }
14829
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.3' };
14829
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.4' };
14830
14830
  /**
14831
14831
  * @dev use createImmutableXConfiguration instead
14832
14832
  */
@@ -14867,7 +14867,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
14867
14867
  coreContractAddress,
14868
14868
  registrationContractAddress,
14869
14869
  registrationV4ContractAddress,
14870
- sdkVersion: 'ts-immutable-sdk-1.45.3-alpha.3',
14870
+ sdkVersion: 'ts-immutable-sdk-1.45.3-alpha.4',
14871
14871
  baseConfig,
14872
14872
  });
14873
14873
  const production = ({ baseConfig }) => createImmutableXConfiguration({
@@ -27853,6 +27853,7 @@ function isTokenExpired(oidcUser) {
27853
27853
  var PassportEvents;
27854
27854
  (function (PassportEvents) {
27855
27855
  PassportEvents["LOGGED_OUT"] = "loggedOut";
27856
+ PassportEvents["LOGGED_IN"] = "loggedIn";
27856
27857
  PassportEvents["ACCOUNTS_REQUESTED"] = "accountsRequested";
27857
27858
  })(PassportEvents || (PassportEvents = {}));
27858
27859
  const isUserZkEvm = (user) => !!user.zkEvm;
@@ -30288,12 +30289,12 @@ const buildMetaTransactions = async (transactionRequest, rpcProvider, relayerCli
30288
30289
  }
30289
30290
  return metaTransactions;
30290
30291
  };
30291
- const sendTransaction$1 = async ({ params, ethSigner, rpcProvider, relayerClient, guardianClient, zkevmAddress, flow, }) => {
30292
+ const sendTransaction$1 = async ({ params, ethSigner, rpcProvider, relayerClient, guardianClient, zkEvmAddress, flow, }) => {
30292
30293
  const { chainId } = await rpcProvider.detectNetwork();
30293
30294
  const chainIdBigNumber = ethers.BigNumber.from(chainId);
30294
30295
  flow.addEvent('endDetectNetwork');
30295
30296
  // Prepare the meta transactions by adding an optional fee transaction
30296
- const metaTransactions = await buildMetaTransactions(params[0], rpcProvider, relayerClient, zkevmAddress);
30297
+ const metaTransactions = await buildMetaTransactions(params[0], rpcProvider, relayerClient, zkEvmAddress);
30297
30298
  flow.addEvent('endBuildMetaTransactions');
30298
30299
  const { nonce } = metaTransactions[0];
30299
30300
  if (!nonce) {
@@ -30308,13 +30309,13 @@ const sendTransaction$1 = async ({ params, ethSigner, rpcProvider, relayerClient
30308
30309
  validateEVMTransactionPromise.then(() => flow.addEvent('endValidateEVMTransaction'));
30309
30310
  // NOTE: We sign again because we now are adding the fee transaction, so the
30310
30311
  // whole payload is different and needs a new signature.
30311
- const getSignedMetaTransactionsPromise = signMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner);
30312
+ const getSignedMetaTransactionsPromise = signMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkEvmAddress, ethSigner);
30312
30313
  getSignedMetaTransactionsPromise.then(() => flow.addEvent('endGetSignedMetaTransactions'));
30313
30314
  const [, signedTransactions] = await Promise.all([
30314
30315
  validateEVMTransactionPromise,
30315
30316
  getSignedMetaTransactionsPromise,
30316
30317
  ]);
30317
- const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
30318
+ const relayerId = await relayerClient.ethSendTransaction(zkEvmAddress, signedTransactions);
30318
30319
  flow.addEvent('endRelayerSendTransaction');
30319
30320
  const retrieveRelayerTransaction = async () => {
30320
30321
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -30655,7 +30656,6 @@ class ZkEvmProvider {
30655
30656
  */
30656
30657
  #ethSigner;
30657
30658
  #signerInitialisationError;
30658
- #zkEvmAddress;
30659
30659
  isPassport = true;
30660
30660
  constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
30661
30661
  this.#authManager = authManager;
@@ -30681,16 +30681,21 @@ class ZkEvmProvider {
30681
30681
  });
30682
30682
  this.#multiRollupApiClients = multiRollupApiClients;
30683
30683
  this.#providerEventEmitter = new TypedEventEmitter();
30684
+ // Automatically connect an existing user session to Passport
30685
+ this.#authManager.getUser().then((user) => {
30686
+ if (user && isZkEvmUser(user)) {
30687
+ this.#initialiseEthSigner(user);
30688
+ }
30689
+ }).catch(() => {
30690
+ // User does not exist, don't initialise an eth signer
30691
+ });
30692
+ passportEventEmitter.on(PassportEvents.LOGGED_IN, (user) => this.#initialiseEthSigner(user));
30684
30693
  passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
30685
30694
  passportEventEmitter.on(PassportEvents.ACCOUNTS_REQUESTED, trackSessionActivity);
30686
30695
  }
30687
30696
  #handleLogout = () => {
30688
- const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
30689
30697
  this.#ethSigner = undefined;
30690
- this.#zkEvmAddress = undefined;
30691
- if (shouldEmitAccountsChanged) {
30692
- this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
30693
- }
30698
+ this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
30694
30699
  };
30695
30700
  /**
30696
30701
  * This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
@@ -30710,6 +30715,7 @@ class ZkEvmProvider {
30710
30715
  const web3Provider = new providers.Web3Provider(magicRpcProvider);
30711
30716
  return web3Provider.getSigner();
30712
30717
  };
30718
+ this.#signerInitialisationError = undefined;
30713
30719
  // eslint-disable-next-line no-async-promise-executor
30714
30720
  this.#ethSigner = new Promise(async (resolve) => {
30715
30721
  try {
@@ -30733,7 +30739,7 @@ class ZkEvmProvider {
30733
30739
  }
30734
30740
  return ethSigner;
30735
30741
  }
30736
- async #callSessionActivity() {
30742
+ async #callSessionActivity(zkEvmAddress) {
30737
30743
  const sendTransactionClosure = async (params, flow) => {
30738
30744
  const ethSigner = await this.#getSigner();
30739
30745
  return await sendTransaction$1({
@@ -30742,35 +30748,49 @@ class ZkEvmProvider {
30742
30748
  guardianClient: this.#guardianClient,
30743
30749
  rpcProvider: this.#rpcProvider,
30744
30750
  relayerClient: this.#relayerClient,
30745
- zkevmAddress: this.#zkEvmAddress,
30751
+ zkEvmAddress,
30746
30752
  flow,
30747
30753
  });
30748
30754
  };
30749
30755
  this.#passportEventEmitter.emit(PassportEvents.ACCOUNTS_REQUESTED, {
30750
30756
  environment: this.#config.baseConfig.environment,
30751
30757
  sendTransaction: sendTransactionClosure,
30752
- walletAddress: this.#zkEvmAddress || '',
30758
+ walletAddress: zkEvmAddress,
30753
30759
  passportClient: this.#config.oidcConfiguration.clientId,
30754
30760
  });
30755
30761
  }
30762
+ // Used to get the registered zkEvm address from the User session
30763
+ async #getZkEvmAddress() {
30764
+ try {
30765
+ const user = await this.#authManager.getUser();
30766
+ if (user && isZkEvmUser(user)) {
30767
+ return user.zkEvm.ethAddress;
30768
+ }
30769
+ return undefined;
30770
+ }
30771
+ catch {
30772
+ return undefined;
30773
+ }
30774
+ }
30756
30775
  async #performRequest(request) {
30757
30776
  // This is required for sending session activity events
30758
30777
  switch (request.method) {
30759
30778
  case 'eth_requestAccounts': {
30760
30779
  const requestAccounts = async () => {
30761
- if (this.#zkEvmAddress) {
30762
- return [this.#zkEvmAddress];
30763
- }
30780
+ const zkEvmAddress = await this.#getZkEvmAddress();
30781
+ if (zkEvmAddress)
30782
+ return [zkEvmAddress];
30764
30783
  const flow = trackFlow('passport', 'ethRequestAccounts');
30765
30784
  try {
30766
30785
  const user = await this.#authManager.getUserOrLogin();
30767
30786
  flow.addEvent('endGetUserOrLogin');
30768
30787
  this.#initialiseEthSigner(user);
30788
+ let userZkEvmEthAddress;
30769
30789
  if (!isZkEvmUser(user)) {
30770
30790
  flow.addEvent('startUserRegistration');
30771
30791
  const ethSigner = await this.#getSigner();
30772
30792
  flow.addEvent('ethSignerResolved');
30773
- this.#zkEvmAddress = await registerZkEvmUser({
30793
+ userZkEvmEthAddress = await registerZkEvmUser({
30774
30794
  ethSigner,
30775
30795
  authManager: this.#authManager,
30776
30796
  multiRollupApiClients: this.#multiRollupApiClients,
@@ -30781,15 +30801,15 @@ class ZkEvmProvider {
30781
30801
  flow.addEvent('endUserRegistration');
30782
30802
  }
30783
30803
  else {
30784
- this.#zkEvmAddress = user.zkEvm.ethAddress;
30804
+ userZkEvmEthAddress = user.zkEvm.ethAddress;
30785
30805
  }
30786
30806
  this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [
30787
- this.#zkEvmAddress,
30807
+ userZkEvmEthAddress,
30788
30808
  ]);
30789
30809
  identify({
30790
30810
  passportId: user.profile.sub,
30791
30811
  });
30792
- return [this.#zkEvmAddress];
30812
+ return [userZkEvmEthAddress];
30793
30813
  }
30794
30814
  catch (error) {
30795
30815
  if (error instanceof Error) {
@@ -30803,11 +30823,13 @@ class ZkEvmProvider {
30803
30823
  }
30804
30824
  };
30805
30825
  const addresses = await requestAccounts();
30806
- this.#callSessionActivity();
30826
+ const [zkEvmAddress] = addresses;
30827
+ this.#callSessionActivity(zkEvmAddress);
30807
30828
  return addresses;
30808
30829
  }
30809
30830
  case 'eth_sendTransaction': {
30810
- if (!this.#zkEvmAddress) {
30831
+ const zkEvmAddress = await this.#getZkEvmAddress();
30832
+ if (!zkEvmAddress) {
30811
30833
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
30812
30834
  }
30813
30835
  const flow = trackFlow('passport', 'ethSendTransaction');
@@ -30824,7 +30846,7 @@ class ZkEvmProvider {
30824
30846
  guardianClient: this.#guardianClient,
30825
30847
  rpcProvider: this.#rpcProvider,
30826
30848
  relayerClient: this.#relayerClient,
30827
- zkevmAddress: this.#zkEvmAddress,
30849
+ zkEvmAddress,
30828
30850
  flow,
30829
30851
  });
30830
30852
  });
@@ -30841,10 +30863,12 @@ class ZkEvmProvider {
30841
30863
  }
30842
30864
  }
30843
30865
  case 'eth_accounts': {
30844
- return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
30866
+ const zkEvmAddress = await this.#getZkEvmAddress();
30867
+ return zkEvmAddress ? [zkEvmAddress] : [];
30845
30868
  }
30846
30869
  case 'personal_sign': {
30847
- if (!this.#zkEvmAddress) {
30870
+ const zkEvmAddress = await this.#getZkEvmAddress();
30871
+ if (!zkEvmAddress) {
30848
30872
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
30849
30873
  }
30850
30874
  const flow = trackFlow('passport', 'personalSign');
@@ -30858,7 +30882,7 @@ class ZkEvmProvider {
30858
30882
  return await personalSign({
30859
30883
  params: request.params || [],
30860
30884
  ethSigner,
30861
- zkEvmAddress: this.#zkEvmAddress,
30885
+ zkEvmAddress,
30862
30886
  rpcProvider: this.#rpcProvider,
30863
30887
  guardianClient: this.#guardianClient,
30864
30888
  relayerClient: this.#relayerClient,
@@ -30879,7 +30903,8 @@ class ZkEvmProvider {
30879
30903
  }
30880
30904
  case 'eth_signTypedData':
30881
30905
  case 'eth_signTypedData_v4': {
30882
- if (!this.#zkEvmAddress) {
30906
+ const zkEvmAddress = await this.#getZkEvmAddress();
30907
+ if (!zkEvmAddress) {
30883
30908
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
30884
30909
  }
30885
30910
  const flow = trackFlow('passport', 'ethSignTypedDataV4');
@@ -31211,6 +31236,7 @@ class Passport {
31211
31236
  identify({
31212
31237
  passportId: user.profile.sub,
31213
31238
  });
31239
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
31214
31240
  }
31215
31241
  return user ? user.profile : null;
31216
31242
  }
@@ -31222,6 +31248,7 @@ class Passport {
31222
31248
  }
31223
31249
  async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
31224
31250
  const user = await this.authManager.loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs);
31251
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
31225
31252
  return user.profile;
31226
31253
  }
31227
31254
  loginWithPKCEFlow() {
@@ -31229,6 +31256,7 @@ class Passport {
31229
31256
  }
31230
31257
  async loginWithPKCEFlowCallback(authorizationCode, state) {
31231
31258
  const user = await this.authManager.loginWithPKCEFlowCallback(authorizationCode, state);
31259
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
31232
31260
  return user.profile;
31233
31261
  }
31234
31262
  async logout() {
@@ -52581,7 +52609,7 @@ const flattenProperties = (properties) => {
52581
52609
  };
52582
52610
 
52583
52611
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
52584
- const SDK_VERSION = '1.45.3-alpha.3';
52612
+ const SDK_VERSION = '1.45.3-alpha.4';
52585
52613
  const getFrameParentDomain = () => {
52586
52614
  if (isNode()) {
52587
52615
  return '';
@@ -57903,7 +57931,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
57903
57931
  maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
57904
57932
  };
57905
57933
 
57906
- const SDK_VERSION_MARKER = '1.45.3-alpha.3';
57934
+ const SDK_VERSION_MARKER = '1.45.3-alpha.4';
57907
57935
  // This SDK version is replaced by the `yarn build` command ran on the root level
57908
57936
  const globalPackageVersion = () => SDK_VERSION_MARKER;
57909
57937
 
package/dist/index.js CHANGED
@@ -192,7 +192,7 @@ const flattenProperties$1 = (properties) => {
192
192
  };
193
193
 
194
194
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
195
- const SDK_VERSION$1 = '1.45.3-alpha.3';
195
+ const SDK_VERSION$1 = '1.45.3-alpha.4';
196
196
  const getFrameParentDomain$1 = () => {
197
197
  if (isNode$1()) {
198
198
  return '';
@@ -14257,7 +14257,7 @@ class MultiRollupApiClients {
14257
14257
  }
14258
14258
 
14259
14259
  // eslint-disable-next-line @typescript-eslint/naming-convention
14260
- const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.3' };
14260
+ const defaultHeaders$2 = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.4' };
14261
14261
  const createConfig$1 = ({ basePath, headers, }) => {
14262
14262
  if (!basePath.trim()) {
14263
14263
  throw Error('basePath can not be empty');
@@ -14329,7 +14329,7 @@ class APIError extends Error {
14329
14329
 
14330
14330
  /* eslint-disable implicit-arrow-linebreak */
14331
14331
  const defaultHeaders$1 = {
14332
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.45.3-alpha.3',
14332
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.45.3-alpha.4',
14333
14333
  };
14334
14334
  /**
14335
14335
  * createAPIConfiguration to create a custom Configuration
@@ -14803,7 +14803,7 @@ var blockchain_data = /*#__PURE__*/Object.freeze({
14803
14803
  /* eslint-disable @typescript-eslint/naming-convention */
14804
14804
  class ApiConfiguration extends index$2.Configuration {
14805
14805
  }
14806
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.3' };
14806
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.4' };
14807
14807
  /**
14808
14808
  * @dev use createImmutableXConfiguration instead
14809
14809
  */
@@ -14844,7 +14844,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
14844
14844
  coreContractAddress,
14845
14845
  registrationContractAddress,
14846
14846
  registrationV4ContractAddress,
14847
- sdkVersion: 'ts-immutable-sdk-1.45.3-alpha.3',
14847
+ sdkVersion: 'ts-immutable-sdk-1.45.3-alpha.4',
14848
14848
  baseConfig,
14849
14849
  });
14850
14850
  const production = ({ baseConfig }) => createImmutableXConfiguration({
@@ -27830,6 +27830,7 @@ function isTokenExpired(oidcUser) {
27830
27830
  var PassportEvents;
27831
27831
  (function (PassportEvents) {
27832
27832
  PassportEvents["LOGGED_OUT"] = "loggedOut";
27833
+ PassportEvents["LOGGED_IN"] = "loggedIn";
27833
27834
  PassportEvents["ACCOUNTS_REQUESTED"] = "accountsRequested";
27834
27835
  })(PassportEvents || (PassportEvents = {}));
27835
27836
  const isUserZkEvm = (user) => !!user.zkEvm;
@@ -30265,12 +30266,12 @@ const buildMetaTransactions = async (transactionRequest, rpcProvider, relayerCli
30265
30266
  }
30266
30267
  return metaTransactions;
30267
30268
  };
30268
- const sendTransaction$1 = async ({ params, ethSigner, rpcProvider, relayerClient, guardianClient, zkevmAddress, flow, }) => {
30269
+ const sendTransaction$1 = async ({ params, ethSigner, rpcProvider, relayerClient, guardianClient, zkEvmAddress, flow, }) => {
30269
30270
  const { chainId } = await rpcProvider.detectNetwork();
30270
30271
  const chainIdBigNumber = BigNumber$1.from(chainId);
30271
30272
  flow.addEvent('endDetectNetwork');
30272
30273
  // Prepare the meta transactions by adding an optional fee transaction
30273
- const metaTransactions = await buildMetaTransactions(params[0], rpcProvider, relayerClient, zkevmAddress);
30274
+ const metaTransactions = await buildMetaTransactions(params[0], rpcProvider, relayerClient, zkEvmAddress);
30274
30275
  flow.addEvent('endBuildMetaTransactions');
30275
30276
  const { nonce } = metaTransactions[0];
30276
30277
  if (!nonce) {
@@ -30285,13 +30286,13 @@ const sendTransaction$1 = async ({ params, ethSigner, rpcProvider, relayerClient
30285
30286
  validateEVMTransactionPromise.then(() => flow.addEvent('endValidateEVMTransaction'));
30286
30287
  // NOTE: We sign again because we now are adding the fee transaction, so the
30287
30288
  // whole payload is different and needs a new signature.
30288
- const getSignedMetaTransactionsPromise = signMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner);
30289
+ const getSignedMetaTransactionsPromise = signMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkEvmAddress, ethSigner);
30289
30290
  getSignedMetaTransactionsPromise.then(() => flow.addEvent('endGetSignedMetaTransactions'));
30290
30291
  const [, signedTransactions] = await Promise.all([
30291
30292
  validateEVMTransactionPromise,
30292
30293
  getSignedMetaTransactionsPromise,
30293
30294
  ]);
30294
- const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
30295
+ const relayerId = await relayerClient.ethSendTransaction(zkEvmAddress, signedTransactions);
30295
30296
  flow.addEvent('endRelayerSendTransaction');
30296
30297
  const retrieveRelayerTransaction = async () => {
30297
30298
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -30632,7 +30633,6 @@ class ZkEvmProvider {
30632
30633
  */
30633
30634
  #ethSigner;
30634
30635
  #signerInitialisationError;
30635
- #zkEvmAddress;
30636
30636
  isPassport = true;
30637
30637
  constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
30638
30638
  this.#authManager = authManager;
@@ -30658,16 +30658,21 @@ class ZkEvmProvider {
30658
30658
  });
30659
30659
  this.#multiRollupApiClients = multiRollupApiClients;
30660
30660
  this.#providerEventEmitter = new TypedEventEmitter();
30661
+ // Automatically connect an existing user session to Passport
30662
+ this.#authManager.getUser().then((user) => {
30663
+ if (user && isZkEvmUser(user)) {
30664
+ this.#initialiseEthSigner(user);
30665
+ }
30666
+ }).catch(() => {
30667
+ // User does not exist, don't initialise an eth signer
30668
+ });
30669
+ passportEventEmitter.on(PassportEvents.LOGGED_IN, (user) => this.#initialiseEthSigner(user));
30661
30670
  passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
30662
30671
  passportEventEmitter.on(PassportEvents.ACCOUNTS_REQUESTED, trackSessionActivity);
30663
30672
  }
30664
30673
  #handleLogout = () => {
30665
- const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
30666
30674
  this.#ethSigner = undefined;
30667
- this.#zkEvmAddress = undefined;
30668
- if (shouldEmitAccountsChanged) {
30669
- this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
30670
- }
30675
+ this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
30671
30676
  };
30672
30677
  /**
30673
30678
  * This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
@@ -30687,6 +30692,7 @@ class ZkEvmProvider {
30687
30692
  const web3Provider = new Web3Provider(magicRpcProvider);
30688
30693
  return web3Provider.getSigner();
30689
30694
  };
30695
+ this.#signerInitialisationError = undefined;
30690
30696
  // eslint-disable-next-line no-async-promise-executor
30691
30697
  this.#ethSigner = new Promise(async (resolve) => {
30692
30698
  try {
@@ -30710,7 +30716,7 @@ class ZkEvmProvider {
30710
30716
  }
30711
30717
  return ethSigner;
30712
30718
  }
30713
- async #callSessionActivity() {
30719
+ async #callSessionActivity(zkEvmAddress) {
30714
30720
  const sendTransactionClosure = async (params, flow) => {
30715
30721
  const ethSigner = await this.#getSigner();
30716
30722
  return await sendTransaction$1({
@@ -30719,35 +30725,49 @@ class ZkEvmProvider {
30719
30725
  guardianClient: this.#guardianClient,
30720
30726
  rpcProvider: this.#rpcProvider,
30721
30727
  relayerClient: this.#relayerClient,
30722
- zkevmAddress: this.#zkEvmAddress,
30728
+ zkEvmAddress,
30723
30729
  flow,
30724
30730
  });
30725
30731
  };
30726
30732
  this.#passportEventEmitter.emit(PassportEvents.ACCOUNTS_REQUESTED, {
30727
30733
  environment: this.#config.baseConfig.environment,
30728
30734
  sendTransaction: sendTransactionClosure,
30729
- walletAddress: this.#zkEvmAddress || '',
30735
+ walletAddress: zkEvmAddress,
30730
30736
  passportClient: this.#config.oidcConfiguration.clientId,
30731
30737
  });
30732
30738
  }
30739
+ // Used to get the registered zkEvm address from the User session
30740
+ async #getZkEvmAddress() {
30741
+ try {
30742
+ const user = await this.#authManager.getUser();
30743
+ if (user && isZkEvmUser(user)) {
30744
+ return user.zkEvm.ethAddress;
30745
+ }
30746
+ return undefined;
30747
+ }
30748
+ catch {
30749
+ return undefined;
30750
+ }
30751
+ }
30733
30752
  async #performRequest(request) {
30734
30753
  // This is required for sending session activity events
30735
30754
  switch (request.method) {
30736
30755
  case 'eth_requestAccounts': {
30737
30756
  const requestAccounts = async () => {
30738
- if (this.#zkEvmAddress) {
30739
- return [this.#zkEvmAddress];
30740
- }
30757
+ const zkEvmAddress = await this.#getZkEvmAddress();
30758
+ if (zkEvmAddress)
30759
+ return [zkEvmAddress];
30741
30760
  const flow = trackFlow('passport', 'ethRequestAccounts');
30742
30761
  try {
30743
30762
  const user = await this.#authManager.getUserOrLogin();
30744
30763
  flow.addEvent('endGetUserOrLogin');
30745
30764
  this.#initialiseEthSigner(user);
30765
+ let userZkEvmEthAddress;
30746
30766
  if (!isZkEvmUser(user)) {
30747
30767
  flow.addEvent('startUserRegistration');
30748
30768
  const ethSigner = await this.#getSigner();
30749
30769
  flow.addEvent('ethSignerResolved');
30750
- this.#zkEvmAddress = await registerZkEvmUser({
30770
+ userZkEvmEthAddress = await registerZkEvmUser({
30751
30771
  ethSigner,
30752
30772
  authManager: this.#authManager,
30753
30773
  multiRollupApiClients: this.#multiRollupApiClients,
@@ -30758,15 +30778,15 @@ class ZkEvmProvider {
30758
30778
  flow.addEvent('endUserRegistration');
30759
30779
  }
30760
30780
  else {
30761
- this.#zkEvmAddress = user.zkEvm.ethAddress;
30781
+ userZkEvmEthAddress = user.zkEvm.ethAddress;
30762
30782
  }
30763
30783
  this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [
30764
- this.#zkEvmAddress,
30784
+ userZkEvmEthAddress,
30765
30785
  ]);
30766
30786
  identify({
30767
30787
  passportId: user.profile.sub,
30768
30788
  });
30769
- return [this.#zkEvmAddress];
30789
+ return [userZkEvmEthAddress];
30770
30790
  }
30771
30791
  catch (error) {
30772
30792
  if (error instanceof Error) {
@@ -30780,11 +30800,13 @@ class ZkEvmProvider {
30780
30800
  }
30781
30801
  };
30782
30802
  const addresses = await requestAccounts();
30783
- this.#callSessionActivity();
30803
+ const [zkEvmAddress] = addresses;
30804
+ this.#callSessionActivity(zkEvmAddress);
30784
30805
  return addresses;
30785
30806
  }
30786
30807
  case 'eth_sendTransaction': {
30787
- if (!this.#zkEvmAddress) {
30808
+ const zkEvmAddress = await this.#getZkEvmAddress();
30809
+ if (!zkEvmAddress) {
30788
30810
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
30789
30811
  }
30790
30812
  const flow = trackFlow('passport', 'ethSendTransaction');
@@ -30801,7 +30823,7 @@ class ZkEvmProvider {
30801
30823
  guardianClient: this.#guardianClient,
30802
30824
  rpcProvider: this.#rpcProvider,
30803
30825
  relayerClient: this.#relayerClient,
30804
- zkevmAddress: this.#zkEvmAddress,
30826
+ zkEvmAddress,
30805
30827
  flow,
30806
30828
  });
30807
30829
  });
@@ -30818,10 +30840,12 @@ class ZkEvmProvider {
30818
30840
  }
30819
30841
  }
30820
30842
  case 'eth_accounts': {
30821
- return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
30843
+ const zkEvmAddress = await this.#getZkEvmAddress();
30844
+ return zkEvmAddress ? [zkEvmAddress] : [];
30822
30845
  }
30823
30846
  case 'personal_sign': {
30824
- if (!this.#zkEvmAddress) {
30847
+ const zkEvmAddress = await this.#getZkEvmAddress();
30848
+ if (!zkEvmAddress) {
30825
30849
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
30826
30850
  }
30827
30851
  const flow = trackFlow('passport', 'personalSign');
@@ -30835,7 +30859,7 @@ class ZkEvmProvider {
30835
30859
  return await personalSign({
30836
30860
  params: request.params || [],
30837
30861
  ethSigner,
30838
- zkEvmAddress: this.#zkEvmAddress,
30862
+ zkEvmAddress,
30839
30863
  rpcProvider: this.#rpcProvider,
30840
30864
  guardianClient: this.#guardianClient,
30841
30865
  relayerClient: this.#relayerClient,
@@ -30856,7 +30880,8 @@ class ZkEvmProvider {
30856
30880
  }
30857
30881
  case 'eth_signTypedData':
30858
30882
  case 'eth_signTypedData_v4': {
30859
- if (!this.#zkEvmAddress) {
30883
+ const zkEvmAddress = await this.#getZkEvmAddress();
30884
+ if (!zkEvmAddress) {
30860
30885
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
30861
30886
  }
30862
30887
  const flow = trackFlow('passport', 'ethSignTypedDataV4');
@@ -31188,6 +31213,7 @@ class Passport {
31188
31213
  identify({
31189
31214
  passportId: user.profile.sub,
31190
31215
  });
31216
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
31191
31217
  }
31192
31218
  return user ? user.profile : null;
31193
31219
  }
@@ -31199,6 +31225,7 @@ class Passport {
31199
31225
  }
31200
31226
  async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
31201
31227
  const user = await this.authManager.loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs);
31228
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
31202
31229
  return user.profile;
31203
31230
  }
31204
31231
  loginWithPKCEFlow() {
@@ -31206,6 +31233,7 @@ class Passport {
31206
31233
  }
31207
31234
  async loginWithPKCEFlowCallback(authorizationCode, state) {
31208
31235
  const user = await this.authManager.loginWithPKCEFlowCallback(authorizationCode, state);
31236
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
31209
31237
  return user.profile;
31210
31238
  }
31211
31239
  async logout() {
@@ -52558,7 +52586,7 @@ const flattenProperties = (properties) => {
52558
52586
  };
52559
52587
 
52560
52588
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
52561
- const SDK_VERSION = '1.45.3-alpha.3';
52589
+ const SDK_VERSION = '1.45.3-alpha.4';
52562
52590
  const getFrameParentDomain = () => {
52563
52591
  if (isNode()) {
52564
52592
  return '';
@@ -57880,7 +57908,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
57880
57908
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
57881
57909
  };
57882
57910
 
57883
- const SDK_VERSION_MARKER = '1.45.3-alpha.3';
57911
+ const SDK_VERSION_MARKER = '1.45.3-alpha.4';
57884
57912
  // This SDK version is replaced by the `yarn build` command ran on the root level
57885
57913
  const globalPackageVersion = () => SDK_VERSION_MARKER;
57886
57914
 
@@ -5302,7 +5302,7 @@ const flattenProperties = (properties) => {
5302
5302
  };
5303
5303
 
5304
5304
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
5305
- const SDK_VERSION = '1.45.3-alpha.3';
5305
+ const SDK_VERSION = '1.45.3-alpha.4';
5306
5306
  const getFrameParentDomain = () => {
5307
5307
  if (isNode()) {
5308
5308
  return '';
@@ -5573,7 +5573,7 @@ class APIError extends Error {
5573
5573
 
5574
5574
  /* eslint-disable implicit-arrow-linebreak */
5575
5575
  const defaultHeaders = {
5576
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.45.3-alpha.3',
5576
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.45.3-alpha.4',
5577
5577
  };
5578
5578
  /**
5579
5579
  * createAPIConfiguration to create a custom Configuration
package/dist/orderbook.js CHANGED
@@ -149,7 +149,7 @@ const flattenProperties = (properties) => {
149
149
  };
150
150
 
151
151
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
152
- const SDK_VERSION = '1.45.3-alpha.3';
152
+ const SDK_VERSION = '1.45.3-alpha.4';
153
153
  const getFrameParentDomain = () => {
154
154
  if (isNode()) {
155
155
  return '';