@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/passport.js CHANGED
@@ -11459,7 +11459,7 @@ class MultiRollupApiClients {
11459
11459
  }
11460
11460
 
11461
11461
  // eslint-disable-next-line @typescript-eslint/naming-convention
11462
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.3' };
11462
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.4' };
11463
11463
  const createConfig$1 = ({ basePath, headers, }) => {
11464
11464
  if (!basePath.trim()) {
11465
11465
  throw Error('basePath can not be empty');
@@ -11668,7 +11668,7 @@ const flattenProperties = (properties) => {
11668
11668
  };
11669
11669
 
11670
11670
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
11671
- const SDK_VERSION = '1.45.3-alpha.3';
11671
+ const SDK_VERSION = '1.45.3-alpha.4';
11672
11672
  const getFrameParentDomain = () => {
11673
11673
  if (isNode()) {
11674
11674
  return '';
@@ -12096,7 +12096,7 @@ const addKeysToHeadersOverride = (baseConfig, overrides) => {
12096
12096
  /* eslint-disable @typescript-eslint/naming-convention */
12097
12097
  class ApiConfiguration extends index$2.Configuration {
12098
12098
  }
12099
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.3' };
12099
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.4' };
12100
12100
  /**
12101
12101
  * @dev use createImmutableXConfiguration instead
12102
12102
  */
@@ -12137,7 +12137,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
12137
12137
  coreContractAddress,
12138
12138
  registrationContractAddress,
12139
12139
  registrationV4ContractAddress,
12140
- sdkVersion: 'ts-immutable-sdk-1.45.3-alpha.3',
12140
+ sdkVersion: 'ts-immutable-sdk-1.45.3-alpha.4',
12141
12141
  baseConfig,
12142
12142
  });
12143
12143
  const production = ({ baseConfig }) => createImmutableXConfiguration({
@@ -20013,6 +20013,7 @@ function isTokenExpired(oidcUser) {
20013
20013
  var PassportEvents;
20014
20014
  (function (PassportEvents) {
20015
20015
  PassportEvents["LOGGED_OUT"] = "loggedOut";
20016
+ PassportEvents["LOGGED_IN"] = "loggedIn";
20016
20017
  PassportEvents["ACCOUNTS_REQUESTED"] = "accountsRequested";
20017
20018
  })(PassportEvents || (PassportEvents = {}));
20018
20019
  const isUserZkEvm = (user) => !!user.zkEvm;
@@ -22448,12 +22449,12 @@ const buildMetaTransactions = async (transactionRequest, rpcProvider, relayerCli
22448
22449
  }
22449
22450
  return metaTransactions;
22450
22451
  };
22451
- const sendTransaction = async ({ params, ethSigner, rpcProvider, relayerClient, guardianClient, zkevmAddress, flow, }) => {
22452
+ const sendTransaction = async ({ params, ethSigner, rpcProvider, relayerClient, guardianClient, zkEvmAddress, flow, }) => {
22452
22453
  const { chainId } = await rpcProvider.detectNetwork();
22453
22454
  const chainIdBigNumber = BigNumber.from(chainId);
22454
22455
  flow.addEvent('endDetectNetwork');
22455
22456
  // Prepare the meta transactions by adding an optional fee transaction
22456
- const metaTransactions = await buildMetaTransactions(params[0], rpcProvider, relayerClient, zkevmAddress);
22457
+ const metaTransactions = await buildMetaTransactions(params[0], rpcProvider, relayerClient, zkEvmAddress);
22457
22458
  flow.addEvent('endBuildMetaTransactions');
22458
22459
  const { nonce } = metaTransactions[0];
22459
22460
  if (!nonce) {
@@ -22468,13 +22469,13 @@ const sendTransaction = async ({ params, ethSigner, rpcProvider, relayerClient,
22468
22469
  validateEVMTransactionPromise.then(() => flow.addEvent('endValidateEVMTransaction'));
22469
22470
  // NOTE: We sign again because we now are adding the fee transaction, so the
22470
22471
  // whole payload is different and needs a new signature.
22471
- const getSignedMetaTransactionsPromise = signMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner);
22472
+ const getSignedMetaTransactionsPromise = signMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkEvmAddress, ethSigner);
22472
22473
  getSignedMetaTransactionsPromise.then(() => flow.addEvent('endGetSignedMetaTransactions'));
22473
22474
  const [, signedTransactions] = await Promise.all([
22474
22475
  validateEVMTransactionPromise,
22475
22476
  getSignedMetaTransactionsPromise,
22476
22477
  ]);
22477
- const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
22478
+ const relayerId = await relayerClient.ethSendTransaction(zkEvmAddress, signedTransactions);
22478
22479
  flow.addEvent('endRelayerSendTransaction');
22479
22480
  const retrieveRelayerTransaction = async () => {
22480
22481
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -22815,7 +22816,6 @@ class ZkEvmProvider {
22815
22816
  */
22816
22817
  #ethSigner;
22817
22818
  #signerInitialisationError;
22818
- #zkEvmAddress;
22819
22819
  isPassport = true;
22820
22820
  constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
22821
22821
  this.#authManager = authManager;
@@ -22841,16 +22841,21 @@ class ZkEvmProvider {
22841
22841
  });
22842
22842
  this.#multiRollupApiClients = multiRollupApiClients;
22843
22843
  this.#providerEventEmitter = new TypedEventEmitter();
22844
+ // Automatically connect an existing user session to Passport
22845
+ this.#authManager.getUser().then((user) => {
22846
+ if (user && isZkEvmUser(user)) {
22847
+ this.#initialiseEthSigner(user);
22848
+ }
22849
+ }).catch(() => {
22850
+ // User does not exist, don't initialise an eth signer
22851
+ });
22852
+ passportEventEmitter.on(PassportEvents.LOGGED_IN, (user) => this.#initialiseEthSigner(user));
22844
22853
  passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
22845
22854
  passportEventEmitter.on(PassportEvents.ACCOUNTS_REQUESTED, trackSessionActivity);
22846
22855
  }
22847
22856
  #handleLogout = () => {
22848
- const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
22849
22857
  this.#ethSigner = undefined;
22850
- this.#zkEvmAddress = undefined;
22851
- if (shouldEmitAccountsChanged) {
22852
- this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
22853
- }
22858
+ this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
22854
22859
  };
22855
22860
  /**
22856
22861
  * This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
@@ -22870,6 +22875,7 @@ class ZkEvmProvider {
22870
22875
  const web3Provider = new Web3Provider(magicRpcProvider);
22871
22876
  return web3Provider.getSigner();
22872
22877
  };
22878
+ this.#signerInitialisationError = undefined;
22873
22879
  // eslint-disable-next-line no-async-promise-executor
22874
22880
  this.#ethSigner = new Promise(async (resolve) => {
22875
22881
  try {
@@ -22893,7 +22899,7 @@ class ZkEvmProvider {
22893
22899
  }
22894
22900
  return ethSigner;
22895
22901
  }
22896
- async #callSessionActivity() {
22902
+ async #callSessionActivity(zkEvmAddress) {
22897
22903
  const sendTransactionClosure = async (params, flow) => {
22898
22904
  const ethSigner = await this.#getSigner();
22899
22905
  return await sendTransaction({
@@ -22902,35 +22908,49 @@ class ZkEvmProvider {
22902
22908
  guardianClient: this.#guardianClient,
22903
22909
  rpcProvider: this.#rpcProvider,
22904
22910
  relayerClient: this.#relayerClient,
22905
- zkevmAddress: this.#zkEvmAddress,
22911
+ zkEvmAddress,
22906
22912
  flow,
22907
22913
  });
22908
22914
  };
22909
22915
  this.#passportEventEmitter.emit(PassportEvents.ACCOUNTS_REQUESTED, {
22910
22916
  environment: this.#config.baseConfig.environment,
22911
22917
  sendTransaction: sendTransactionClosure,
22912
- walletAddress: this.#zkEvmAddress || '',
22918
+ walletAddress: zkEvmAddress,
22913
22919
  passportClient: this.#config.oidcConfiguration.clientId,
22914
22920
  });
22915
22921
  }
22922
+ // Used to get the registered zkEvm address from the User session
22923
+ async #getZkEvmAddress() {
22924
+ try {
22925
+ const user = await this.#authManager.getUser();
22926
+ if (user && isZkEvmUser(user)) {
22927
+ return user.zkEvm.ethAddress;
22928
+ }
22929
+ return undefined;
22930
+ }
22931
+ catch {
22932
+ return undefined;
22933
+ }
22934
+ }
22916
22935
  async #performRequest(request) {
22917
22936
  // This is required for sending session activity events
22918
22937
  switch (request.method) {
22919
22938
  case 'eth_requestAccounts': {
22920
22939
  const requestAccounts = async () => {
22921
- if (this.#zkEvmAddress) {
22922
- return [this.#zkEvmAddress];
22923
- }
22940
+ const zkEvmAddress = await this.#getZkEvmAddress();
22941
+ if (zkEvmAddress)
22942
+ return [zkEvmAddress];
22924
22943
  const flow = trackFlow('passport', 'ethRequestAccounts');
22925
22944
  try {
22926
22945
  const user = await this.#authManager.getUserOrLogin();
22927
22946
  flow.addEvent('endGetUserOrLogin');
22928
22947
  this.#initialiseEthSigner(user);
22948
+ let userZkEvmEthAddress;
22929
22949
  if (!isZkEvmUser(user)) {
22930
22950
  flow.addEvent('startUserRegistration');
22931
22951
  const ethSigner = await this.#getSigner();
22932
22952
  flow.addEvent('ethSignerResolved');
22933
- this.#zkEvmAddress = await registerZkEvmUser({
22953
+ userZkEvmEthAddress = await registerZkEvmUser({
22934
22954
  ethSigner,
22935
22955
  authManager: this.#authManager,
22936
22956
  multiRollupApiClients: this.#multiRollupApiClients,
@@ -22941,15 +22961,15 @@ class ZkEvmProvider {
22941
22961
  flow.addEvent('endUserRegistration');
22942
22962
  }
22943
22963
  else {
22944
- this.#zkEvmAddress = user.zkEvm.ethAddress;
22964
+ userZkEvmEthAddress = user.zkEvm.ethAddress;
22945
22965
  }
22946
22966
  this.#providerEventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [
22947
- this.#zkEvmAddress,
22967
+ userZkEvmEthAddress,
22948
22968
  ]);
22949
22969
  identify({
22950
22970
  passportId: user.profile.sub,
22951
22971
  });
22952
- return [this.#zkEvmAddress];
22972
+ return [userZkEvmEthAddress];
22953
22973
  }
22954
22974
  catch (error) {
22955
22975
  if (error instanceof Error) {
@@ -22963,11 +22983,13 @@ class ZkEvmProvider {
22963
22983
  }
22964
22984
  };
22965
22985
  const addresses = await requestAccounts();
22966
- this.#callSessionActivity();
22986
+ const [zkEvmAddress] = addresses;
22987
+ this.#callSessionActivity(zkEvmAddress);
22967
22988
  return addresses;
22968
22989
  }
22969
22990
  case 'eth_sendTransaction': {
22970
- if (!this.#zkEvmAddress) {
22991
+ const zkEvmAddress = await this.#getZkEvmAddress();
22992
+ if (!zkEvmAddress) {
22971
22993
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
22972
22994
  }
22973
22995
  const flow = trackFlow('passport', 'ethSendTransaction');
@@ -22984,7 +23006,7 @@ class ZkEvmProvider {
22984
23006
  guardianClient: this.#guardianClient,
22985
23007
  rpcProvider: this.#rpcProvider,
22986
23008
  relayerClient: this.#relayerClient,
22987
- zkevmAddress: this.#zkEvmAddress,
23009
+ zkEvmAddress,
22988
23010
  flow,
22989
23011
  });
22990
23012
  });
@@ -23001,10 +23023,12 @@ class ZkEvmProvider {
23001
23023
  }
23002
23024
  }
23003
23025
  case 'eth_accounts': {
23004
- return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
23026
+ const zkEvmAddress = await this.#getZkEvmAddress();
23027
+ return zkEvmAddress ? [zkEvmAddress] : [];
23005
23028
  }
23006
23029
  case 'personal_sign': {
23007
- if (!this.#zkEvmAddress) {
23030
+ const zkEvmAddress = await this.#getZkEvmAddress();
23031
+ if (!zkEvmAddress) {
23008
23032
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
23009
23033
  }
23010
23034
  const flow = trackFlow('passport', 'personalSign');
@@ -23018,7 +23042,7 @@ class ZkEvmProvider {
23018
23042
  return await personalSign({
23019
23043
  params: request.params || [],
23020
23044
  ethSigner,
23021
- zkEvmAddress: this.#zkEvmAddress,
23045
+ zkEvmAddress,
23022
23046
  rpcProvider: this.#rpcProvider,
23023
23047
  guardianClient: this.#guardianClient,
23024
23048
  relayerClient: this.#relayerClient,
@@ -23039,7 +23063,8 @@ class ZkEvmProvider {
23039
23063
  }
23040
23064
  case 'eth_signTypedData':
23041
23065
  case 'eth_signTypedData_v4': {
23042
- if (!this.#zkEvmAddress) {
23066
+ const zkEvmAddress = await this.#getZkEvmAddress();
23067
+ if (!zkEvmAddress) {
23043
23068
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
23044
23069
  }
23045
23070
  const flow = trackFlow('passport', 'ethSignTypedDataV4');
@@ -23371,6 +23396,7 @@ class Passport {
23371
23396
  identify({
23372
23397
  passportId: user.profile.sub,
23373
23398
  });
23399
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
23374
23400
  }
23375
23401
  return user ? user.profile : null;
23376
23402
  }
@@ -23382,6 +23408,7 @@ class Passport {
23382
23408
  }
23383
23409
  async loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs) {
23384
23410
  const user = await this.authManager.loginWithDeviceFlowCallback(deviceCode, interval, timeoutMs);
23411
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
23385
23412
  return user.profile;
23386
23413
  }
23387
23414
  loginWithPKCEFlow() {
@@ -23389,6 +23416,7 @@ class Passport {
23389
23416
  }
23390
23417
  async loginWithPKCEFlowCallback(authorizationCode, state) {
23391
23418
  const user = await this.authManager.loginWithPKCEFlowCallback(authorizationCode, state);
23419
+ this.passportEventEmitter.emit(PassportEvents.LOGGED_IN, user);
23392
23420
  return user.profile;
23393
23421
  }
23394
23422
  async logout() {
package/dist/webhook.js CHANGED
@@ -145,7 +145,7 @@ const flattenProperties = (properties) => {
145
145
  };
146
146
 
147
147
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
148
- const SDK_VERSION = '1.45.3-alpha.3';
148
+ const SDK_VERSION = '1.45.3-alpha.4';
149
149
  const getFrameParentDomain = () => {
150
150
  if (isNode()) {
151
151
  return '';
package/dist/x.js CHANGED
@@ -9019,7 +9019,7 @@ const flattenProperties = (properties) => {
9019
9019
  };
9020
9020
 
9021
9021
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
9022
- const SDK_VERSION = '1.45.3-alpha.3';
9022
+ const SDK_VERSION = '1.45.3-alpha.4';
9023
9023
  const getFrameParentDomain = () => {
9024
9024
  if (isNode()) {
9025
9025
  return '';
@@ -9288,7 +9288,7 @@ const addKeysToHeadersOverride = (baseConfig, overrides) => {
9288
9288
  /* eslint-disable @typescript-eslint/naming-convention */
9289
9289
  class ApiConfiguration extends index$2.Configuration {
9290
9290
  }
9291
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.3' };
9291
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.45.3-alpha.4' };
9292
9292
  /**
9293
9293
  * @dev use createImmutableXConfiguration instead
9294
9294
  */
@@ -9329,7 +9329,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
9329
9329
  coreContractAddress,
9330
9330
  registrationContractAddress,
9331
9331
  registrationV4ContractAddress,
9332
- sdkVersion: 'ts-immutable-sdk-1.45.3-alpha.3',
9332
+ sdkVersion: 'ts-immutable-sdk-1.45.3-alpha.4',
9333
9333
  baseConfig,
9334
9334
  });
9335
9335
  const production = ({ baseConfig }) => createImmutableXConfiguration({
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Typescript SDK",
4
- "version": "1.45.3-alpha.3",
4
+ "version": "1.45.3-alpha.4",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",