@imtbl/sdk 0.28.6-alpha.1 → 0.28.7-alpha

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import globalAxios$1, { isAxiosError as isAxiosError$1, HttpStatusCode as HttpStatusCode$2 } from 'axios';
1
+ import globalAxios$1, { isAxiosError as isAxiosError$1, AxiosError as AxiosError$1, HttpStatusCode as HttpStatusCode$2 } from 'axios';
2
2
  import { ImmutableX, Config, IMXError, createStarkSigner, generateLegacyStarkPrivateKey, TransfersApi, OrdersApi as OrdersApi$1, UsersApi, Contracts, TradesApi, ExchangesApi, WithdrawalsApi, MintsApi, DepositsApi, EncodingApi, TokensApi as TokensApi$1 } from '@imtbl/core-sdk';
3
3
  import { UserManager, InMemoryWebStorage, WebStorageStateStore } from 'oidc-client-ts';
4
4
  import jwt_decode from 'jwt-decode';
@@ -3627,7 +3627,7 @@ class MultiRollupApiClients {
3627
3627
  }
3628
3628
 
3629
3629
  // eslint-disable-next-line @typescript-eslint/naming-convention
3630
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.28.6-alpha.1' };
3630
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.28.7-alpha' };
3631
3631
  const createConfig = ({ basePath, headers, }) => {
3632
3632
  if (!basePath.trim()) {
3633
3633
  throw Error('basePath can not be empty');
@@ -3687,7 +3687,7 @@ class APIError extends Error {
3687
3687
 
3688
3688
  /* eslint-disable implicit-arrow-linebreak */
3689
3689
  const defaultHeaders = {
3690
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.6-alpha.1',
3690
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.7-alpha',
3691
3691
  };
3692
3692
  /**
3693
3693
  * createAPIConfiguration to create a custom Configuration
@@ -4098,7 +4098,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4098
4098
  chainID,
4099
4099
  coreContractAddress,
4100
4100
  registrationContractAddress,
4101
- sdkVersion: 'ts-immutable-sdk-0.28.6-alpha.1',
4101
+ sdkVersion: 'ts-immutable-sdk-0.28.7-alpha',
4102
4102
  });
4103
4103
  /**
4104
4104
  * Sets `sdkVersion` at the time of build
@@ -9043,39 +9043,63 @@ class AuthManager {
9043
9043
  }
9044
9044
  }
9045
9045
 
9046
+ const lazyLoad = (promiseToAwait, initialiseFunction) => (promiseToAwait().then(initialiseFunction));
9047
+ const lazyDocumentReady = (initialiseFunction) => {
9048
+ const documentReadyPromise = () => new Promise((resolve) => {
9049
+ if (window.document.readyState === 'complete') {
9050
+ resolve();
9051
+ }
9052
+ else {
9053
+ const onReadyStateChange = () => {
9054
+ if (window.document.readyState === 'complete') {
9055
+ resolve();
9056
+ window.document.removeEventListener('readystatechange', onReadyStateChange);
9057
+ }
9058
+ };
9059
+ window.document.addEventListener('readystatechange', onReadyStateChange);
9060
+ }
9061
+ });
9062
+ return lazyLoad(documentReadyPromise, initialiseFunction);
9063
+ };
9064
+
9046
9065
  class MagicAdapter {
9047
9066
  config;
9048
- magicClient;
9067
+ lazyMagicClient;
9049
9068
  constructor(config) {
9050
9069
  this.config = config;
9051
9070
  if (typeof window !== 'undefined') {
9052
- this.magicClient = this.initMagicClient();
9053
- this.magicClient.preload();
9071
+ this.lazyMagicClient = lazyDocumentReady(() => {
9072
+ const client = new Magic(this.config.magicPublishableApiKey, {
9073
+ extensions: [new OpenIdExtension()],
9074
+ network: this.config.network,
9075
+ });
9076
+ client.preload();
9077
+ return client;
9078
+ });
9079
+ }
9080
+ }
9081
+ get magicClient() {
9082
+ if (!this.lazyMagicClient) {
9083
+ throw new Error('Cannot perform this action outside of the browser');
9054
9084
  }
9085
+ return this.lazyMagicClient;
9055
9086
  }
9056
9087
  async login(idToken) {
9057
9088
  return withPassportError(async () => {
9058
- if (!this.magicClient) {
9059
- this.magicClient = this.initMagicClient();
9060
- }
9061
- await this.magicClient.openid.loginWithOIDC({
9089
+ const magicClient = await this.magicClient;
9090
+ await magicClient.openid.loginWithOIDC({
9062
9091
  jwt: idToken,
9063
9092
  providerId: this.config.magicProviderId,
9064
9093
  });
9065
- return this.magicClient.rpcProvider;
9094
+ return magicClient.rpcProvider;
9066
9095
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
9067
9096
  }
9068
9097
  async logout() {
9069
- if (this.magicClient?.user) {
9070
- await this.magicClient.user.logout();
9098
+ const magicClient = await this.magicClient;
9099
+ if (magicClient.user) {
9100
+ await magicClient.user.logout();
9071
9101
  }
9072
9102
  }
9073
- initMagicClient() {
9074
- return new Magic(this.config.magicPublishableApiKey, {
9075
- extensions: [new OpenIdExtension()],
9076
- network: this.config.network,
9077
- });
9078
- }
9079
9103
  }
9080
9104
 
9081
9105
  const getStarkSigner = async (signer) => withPassportError(async () => {
@@ -9302,7 +9326,7 @@ var PassportEvents;
9302
9326
  var Networks;
9303
9327
  (function (Networks) {
9304
9328
  Networks["PRODUCTION"] = "mainnet";
9305
- Networks["SANDBOX"] = "goerli";
9329
+ Networks["SANDBOX"] = "sepolia";
9306
9330
  })(Networks || (Networks = {}));
9307
9331
 
9308
9332
  async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
@@ -9651,6 +9675,11 @@ class PassportImxProvider {
9651
9675
  }
9652
9676
  // TODO: Remove once implemented
9653
9677
  // eslint-disable-next-line class-methods-use-this
9678
+ isRegisteredOffchain() {
9679
+ throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
9680
+ }
9681
+ // TODO: Remove once implemented
9682
+ // eslint-disable-next-line class-methods-use-this
9654
9683
  isRegisteredOnchain() {
9655
9684
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
9656
9685
  }
@@ -9744,7 +9773,17 @@ class PassportImxProviderFactory {
9744
9773
  this.passportEventEmitter = passportEventEmitter;
9745
9774
  }
9746
9775
  async getProvider() {
9747
- const user = await this.authManager.loginSilent() || await this.authManager.login();
9776
+ let user = null;
9777
+ try {
9778
+ user = await this.authManager.loginSilent();
9779
+ }
9780
+ catch (e) {
9781
+ // eslint-disable-next-line no-console
9782
+ console.warn(e);
9783
+ }
9784
+ if (!user) {
9785
+ user = await this.authManager.login();
9786
+ }
9748
9787
  return this.createProviderInstance(user);
9749
9788
  }
9750
9789
  async getProviderSilent() {
@@ -10799,7 +10838,14 @@ class Passport {
10799
10838
  */
10800
10839
  async login(options) {
10801
10840
  const { useCachedSession = false } = options || {};
10802
- let user = await this.authManager.loginSilent();
10841
+ let user = null;
10842
+ try {
10843
+ user = await this.authManager.loginSilent();
10844
+ }
10845
+ catch (error) {
10846
+ // eslint-disable-next-line no-console
10847
+ console.warn('loginSilent failed with error:', error);
10848
+ }
10803
10849
  if (!user && !useCachedSession) {
10804
10850
  user = await this.authManager.login();
10805
10851
  }
@@ -12647,6 +12693,22 @@ async function registerOffchain(signers, config) {
12647
12693
  });
12648
12694
  return registeredUser.data;
12649
12695
  }
12696
+ async function isRegisteredOffchain(ethAddress, config) {
12697
+ try {
12698
+ const usersApi = new UsersApi(config.immutableXConfig.apiConfiguration);
12699
+ const getUsersResult = await usersApi.getUsers({
12700
+ user: ethAddress,
12701
+ });
12702
+ const { accounts } = getUsersResult.data;
12703
+ return accounts?.length > 0;
12704
+ }
12705
+ catch (ex) {
12706
+ if (ex instanceof AxiosError$1 && ex.response?.status === 404) {
12707
+ return false;
12708
+ }
12709
+ throw ex;
12710
+ }
12711
+ }
12650
12712
  async function isRegisteredOnChain(starkPublicKey, ethSigner, config) {
12651
12713
  await validateChain(ethSigner, config.immutableXConfig);
12652
12714
  const registrationContract = Contracts.Registration.connect(config.immutableXConfig.ethConfiguration.registrationContractAddress, ethSigner);
@@ -13182,7 +13244,11 @@ class GenericIMXProvider {
13182
13244
  this.signers = { ethSigner, starkSigner };
13183
13245
  }
13184
13246
  async getAddress() {
13185
- return await this.signers.ethSigner.getAddress();
13247
+ return this.signers.ethSigner.getAddress();
13248
+ }
13249
+ async isRegisteredOffchain() {
13250
+ const ethAddress = await this.getAddress();
13251
+ return isRegisteredOffchain(ethAddress, this.config);
13186
13252
  }
13187
13253
  registerOffchain() {
13188
13254
  return registerOffchain(this.signers, this.config);
@@ -29402,6 +29468,7 @@ var SaleEventType;
29402
29468
  SaleEventType["SUCCESS"] = "success";
29403
29469
  SaleEventType["FAILURE"] = "failure";
29404
29470
  SaleEventType["REJECTED"] = "rejected";
29471
+ SaleEventType["TRANSACTION_SUCCESS"] = "transaction-success";
29405
29472
  })(SaleEventType || (SaleEventType = {}));
29406
29473
 
29407
29474
  /**
@@ -30570,6 +30637,9 @@ async function getERC20Balance(web3Provider, walletAddress, contractAddress) {
30570
30637
  }
30571
30638
  // Blockscout client singleton per chain id
30572
30639
  const blockscoutClientMap = new Map();
30640
+ // This function is a utility function that can be used to reset the
30641
+ // blockscout map and therefore clear all the cache.
30642
+ const resetBlockscoutClientMap = () => blockscoutClientMap.clear();
30573
30643
  const getIndexerBalance = async (walletAddress, chainId, filterTokens) => {
30574
30644
  // Shuffle the mapping of the tokens configuration so it is a hashmap
30575
30645
  // for faster access to tokens config objects.
@@ -30670,6 +30740,8 @@ const getBalances = async (config, web3Provider, walletAddress, tokens) => {
30670
30740
  return { balances };
30671
30741
  };
30672
30742
  const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
30743
+ // eslint-disable-next-line no-param-reassign
30744
+ chainId ||= await web3Provider.getSigner().getChainId();
30673
30745
  const { tokens } = await getTokenAllowList(config, {
30674
30746
  type: TokenFilterTypes.ALL,
30675
30747
  chainId,
@@ -30692,7 +30764,7 @@ const getAllBalances = async (config, web3Provider, walletAddress, chainId) => {
30692
30764
  // Please remove this hack once https://immutable.atlassian.net/browse/WT-1710
30693
30765
  // is done.
30694
30766
  const isL1Chain = getL1ChainId(config) === chainId;
30695
- return measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(walletAddress, chainId, isL1Chain ? tokens : []));
30767
+ return await measureAsyncExecution(config, `Time to fetch balances using blockscout for ${chainId}`, getIndexerBalance(walletAddress, chainId, isL1Chain ? tokens : []));
30696
30768
  }
30697
30769
  // This fallback to use ERC20s calls which is a best effort solution
30698
30770
  // Fails in fetching data from the RCP calls might result in some
@@ -31566,18 +31638,15 @@ const getTokenBalanceRequirement = (itemRequirement, balances) => {
31566
31638
  * Gets the balances for all NATIVE and ERC20 balance requirements.
31567
31639
  */
31568
31640
  const getTokenBalances = async (config, provider, ownerAddress, itemRequirements) => {
31569
- let tokenBalances = [];
31570
31641
  try {
31571
- const tokenList = getTokensFromRequirements(itemRequirements);
31572
- const { balances } = await getBalances(config, provider, ownerAddress, tokenList);
31573
- tokenBalances = [
31574
- ...balances.map((balance) => balance),
31575
- ];
31642
+ const tokenMap = new Map();
31643
+ getTokensFromRequirements(itemRequirements).forEach((item) => tokenMap.set((item.address || '').toLocaleLowerCase(), item));
31644
+ const { balances } = await getAllBalances(config, provider, ownerAddress);
31645
+ return balances.filter((balance) => tokenMap.get((balance.token.address || '').toLocaleLowerCase()));
31576
31646
  }
31577
31647
  catch (error) {
31578
31648
  throw new CheckoutError('Failed to get balances', CheckoutErrorType.GET_BALANCE_ERROR);
31579
31649
  }
31580
- return tokenBalances;
31581
31650
  };
31582
31651
  /**
31583
31652
  * Gets the balances for all ERC721 balance requirements.
@@ -31624,53 +31693,56 @@ const getERC721Balances = async (provider, ownerAddress, itemRequirements) => {
31624
31693
  */
31625
31694
  const balanceCheck = async (config, provider, ownerAddress, itemRequirements) => {
31626
31695
  const aggregatedItems = balanceAggregator(itemRequirements);
31627
- if (aggregatedItems.filter((itemRequirement) => {
31628
- return itemRequirement.type !== ItemType.ERC721
31629
- && itemRequirement.type !== ItemType.ERC20
31630
- && itemRequirement.type !== ItemType.NATIVE;
31631
- }).length > 0) {
31696
+ const requiredToken = [];
31697
+ const requiredERC721 = [];
31698
+ aggregatedItems.forEach((item) => {
31699
+ switch (item.type) {
31700
+ case ItemType.ERC20:
31701
+ case ItemType.NATIVE:
31702
+ requiredToken.push(item);
31703
+ break;
31704
+ case ItemType.ERC721:
31705
+ requiredERC721.push(item);
31706
+ break;
31707
+ }
31708
+ });
31709
+ if (requiredERC721.length === 0 && requiredToken.length === 0) {
31632
31710
  throw new CheckoutError('Unsupported item requirement balance check', CheckoutErrorType.UNSUPPORTED_BALANCE_REQUIREMENT_ERROR);
31633
31711
  }
31634
31712
  // Get all ERC20 and NATIVE balances
31635
- const currentBalances = [];
31636
- const tokenItemRequirements = aggregatedItems
31637
- .filter((itemRequirement) => itemRequirement.type === ItemType.ERC20 || itemRequirement.type === ItemType.NATIVE);
31638
- if (tokenItemRequirements.length > 0) {
31639
- currentBalances.push(getTokenBalances(config, provider, ownerAddress, aggregatedItems));
31713
+ const balancePromises = [];
31714
+ if (requiredToken.length > 0) {
31715
+ balancePromises.push(getTokenBalances(config, provider, ownerAddress, aggregatedItems));
31640
31716
  }
31641
31717
  // Get all ERC721 balances
31642
- const erc721ItemRequirements = aggregatedItems
31643
- .filter((itemRequirement) => itemRequirement.type === ItemType.ERC721);
31644
- if (erc721ItemRequirements.length > 0) {
31645
- currentBalances.push(getERC721Balances(provider, ownerAddress, aggregatedItems));
31718
+ if (requiredERC721.length > 0) {
31719
+ balancePromises.push(getERC721Balances(provider, ownerAddress, aggregatedItems));
31646
31720
  }
31647
31721
  // Wait for all balances and calculate the requirements
31648
- const balanceRequirements = await Promise.all(currentBalances).then((balances) => {
31649
- const requirements = [];
31650
- if (balances.length > 1 || tokenItemRequirements.length > 0) {
31651
- const tokenBalances = balances[0];
31652
- tokenItemRequirements.forEach((tokenItemRequirement) => {
31653
- requirements.push(getTokenBalanceRequirement(tokenItemRequirement, tokenBalances));
31722
+ const promisesResponses = await Promise.all(balancePromises);
31723
+ const balanceRequirements = [];
31724
+ // Get all ERC20 and NATIVE balances
31725
+ if (requiredToken.length > 0 && promisesResponses.length > 0) {
31726
+ const result = promisesResponses.shift();
31727
+ if (result) {
31728
+ requiredToken.forEach((item) => {
31729
+ balanceRequirements.push(getTokenBalanceRequirement(item, result));
31654
31730
  });
31655
- if (erc721ItemRequirements.length > 0) {
31656
- const erc721Balances = balances[1];
31657
- erc721ItemRequirements.forEach((erc721ItemRequirement) => {
31658
- requirements.push(getERC721BalanceRequirement(erc721ItemRequirement, erc721Balances));
31659
- });
31660
- }
31661
31731
  }
31662
- else if (erc721ItemRequirements.length > 0) {
31663
- // Only erc721
31664
- const erc721Balances = balances[0];
31665
- erc721ItemRequirements.forEach((erc721ItemRequirement) => {
31666
- requirements.push(getERC721BalanceRequirement(erc721ItemRequirement, erc721Balances));
31732
+ }
31733
+ // Get all ERC721 balances
31734
+ if (requiredERC721.length > 0 && promisesResponses.length > 0) {
31735
+ const result = promisesResponses.shift();
31736
+ if (result) {
31737
+ requiredERC721.forEach((item) => {
31738
+ balanceRequirements.push(getERC721BalanceRequirement(item, result));
31667
31739
  });
31668
31740
  }
31669
- return requirements;
31670
- });
31671
- const sufficient = balanceRequirements.reduce((acc, balanceRequirement) => {
31672
- return acc && balanceRequirement.sufficient;
31673
- }, true);
31741
+ }
31742
+ // Find if there are any requirements that aren't sufficient.
31743
+ // If there is not item with sufficient === false then the requirements
31744
+ // are satisfied.
31745
+ const sufficient = balanceRequirements.find((req) => req.sufficient === false) === undefined;
31674
31746
  return {
31675
31747
  sufficient,
31676
31748
  balanceRequirements,
@@ -32273,8 +32345,12 @@ const getBridgeFeeEstimate = async (config, readOnlyProviders) => {
32273
32345
  // If the root address evaluates to this then its ETH
32274
32346
  const INDEXER_ETH_ROOT_CONTRACT_ADDRESS = '0x0000000000000000000000000000000000000001';
32275
32347
  const getIndexerChainName = (chainId) => {
32348
+ if (chainId === ChainId.IMTBL_ZKEVM_MAINNET)
32349
+ return 'imtbl-zkevm-mainnet';
32276
32350
  if (chainId === ChainId.IMTBL_ZKEVM_TESTNET)
32277
32351
  return 'imtbl-zkevm-testnet';
32352
+ if (chainId === ChainId.IMTBL_ZKEVM_DEVNET)
32353
+ return 'imtbl-zkevm-devent';
32278
32354
  return '';
32279
32355
  };
32280
32356
  // Indexer ERC20 call does not support IMX so cannot get root chain mapping from this endpoint.
@@ -33273,18 +33349,26 @@ const getTransactionOrGas = (gasLimit, fulfillmentTransactions) => {
33273
33349
  };
33274
33350
  };
33275
33351
  const buy = async (config, provider, orders) => {
33276
- let orderbook;
33277
- let order;
33278
- let spenderAddress = '';
33279
- const gasLimit = constants.estimatedFulfillmentGasGwei;
33280
33352
  if (orders.length === 0) {
33281
33353
  throw new CheckoutError('No orders were provided to the orders array. Please provide at least one order.', CheckoutErrorType.FULFILL_ORDER_LISTING_ERROR);
33282
33354
  }
33355
+ let order;
33356
+ let spenderAddress = '';
33357
+ let decimals = 18;
33358
+ const gasLimit = constants.estimatedFulfillmentGasGwei;
33359
+ const orderbook = createOrderbookInstance(config);
33360
+ const blockchainClient = createBlockchainDataInstance(config);
33361
+ const fulfillerAddress = await measureAsyncExecution(config, 'Time to get the address from the provider', provider.getSigner().getAddress());
33362
+ // Prefetch balances and store them in memory
33363
+ resetBlockscoutClientMap();
33364
+ getAllBalances(config, provider, fulfillerAddress, getL1ChainId(config));
33365
+ getAllBalances(config, provider, fulfillerAddress, getL2ChainId(config));
33283
33366
  const { id, takerFees } = orders[0];
33367
+ let orderChainName;
33284
33368
  try {
33285
- orderbook = createOrderbookInstance(config);
33286
33369
  order = await measureAsyncExecution(config, 'Time to fetch the listing from the orderbook', orderbook.getListing(id));
33287
- const { seaportContractAddress } = orderbook.config();
33370
+ const { seaportContractAddress, chainName } = orderbook.config();
33371
+ orderChainName = chainName;
33288
33372
  spenderAddress = seaportContractAddress;
33289
33373
  }
33290
33374
  catch (err) {
@@ -33300,10 +33384,10 @@ const buy = async (config, provider, orders) => {
33300
33384
  });
33301
33385
  }
33302
33386
  const buyToken = order.result.buy[0];
33303
- let decimals = 18;
33304
- if (order.result.buy[0].type === 'ERC20') {
33305
- const tokenContract = getTokenContract(order.result.buy[0].contractAddress, ERC20ABI, provider);
33306
- decimals = await measureAsyncExecution(config, 'Time to get decimals of token contract for the buy token', tokenContract.decimals());
33387
+ if (buyToken.type === 'ERC20') {
33388
+ const token = await measureAsyncExecution(config, 'Time to get decimals of token contract for the buy token', blockchainClient.getToken({ contractAddress: buyToken.contractAddress, chainName: orderChainName }));
33389
+ if (token.result.decimals)
33390
+ decimals = token.result.decimals;
33307
33391
  }
33308
33392
  let fees = [];
33309
33393
  if (takerFees && takerFees.length > 0) {
@@ -33314,7 +33398,6 @@ const buy = async (config, provider, orders) => {
33314
33398
  let orderActions = [];
33315
33399
  const fulfillOrderStartTime = performance.now();
33316
33400
  try {
33317
- const fulfillerAddress = await measureAsyncExecution(config, 'Time to get the address from the provider', provider.getSigner().getAddress());
33318
33401
  const { actions } = await measureAsyncExecution(config, 'Time to call fulfillOrder from the orderbook', orderbook.fulfillOrder(id, fulfillerAddress, fees));
33319
33402
  orderActions = actions;
33320
33403
  unsignedApprovalTransactions = await measureAsyncExecution(config, 'Time to construct the unsigned approval transactions', getUnsignedERC20ApprovalTransactions(actions));
@@ -33652,7 +33735,7 @@ async function getItemRequirementsFromRequirements(provider, requirements) {
33652
33735
  return itemRequirements;
33653
33736
  }
33654
33737
 
33655
- const SDK_VERSION_MARKER = '0.28.6-alpha.1';
33738
+ const SDK_VERSION_MARKER = '0.28.7-alpha';
33656
33739
  // This SDK version is replaced by the `yarn build` command ran on the root level
33657
33740
  const globalPackageVersion = () => SDK_VERSION_MARKER;
33658
33741
 
@@ -33813,11 +33896,7 @@ class Checkout {
33813
33896
  async connect(params) {
33814
33897
  const web3Provider = await validateProvider(this.config, params.provider, { allowUnsupportedProvider: true });
33815
33898
  await connectSite(web3Provider);
33816
- const networkInfo = await getNetworkInfo(this.config, web3Provider);
33817
- return {
33818
- provider: web3Provider,
33819
- network: networkInfo,
33820
- };
33899
+ return { provider: web3Provider };
33821
33900
  }
33822
33901
  /**
33823
33902
  * Switches the network for the current wallet provider.
@@ -9732,6 +9732,12 @@ interface IMXProvider {
9732
9732
  * @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
9733
9733
  */
9734
9734
  registerOffchain(): Promise<RegisterUserResponse>;
9735
+ /**
9736
+ * Checks if a User is registered off-chain
9737
+ *
9738
+ * @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
9739
+ */
9740
+ isRegisteredOffchain(): Promise<boolean>;
9735
9741
  /**
9736
9742
  * Checks if a User is registered on-chain
9737
9743
  *
@@ -10184,7 +10190,7 @@ type UserProfile = {
10184
10190
  };
10185
10191
  declare enum Networks {
10186
10192
  PRODUCTION = "mainnet",
10187
- SANDBOX = "goerli"
10193
+ SANDBOX = "sepolia"
10188
10194
  }
10189
10195
  interface OidcConfiguration {
10190
10196
  clientId: string;
package/dist/passport.js CHANGED
@@ -2072,7 +2072,7 @@ class MultiRollupApiClients {
2072
2072
  }
2073
2073
 
2074
2074
  // eslint-disable-next-line @typescript-eslint/naming-convention
2075
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.6-alpha.1' };
2075
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.7-alpha' };
2076
2076
  const createConfig = ({ basePath, headers, }) => {
2077
2077
  if (!basePath.trim()) {
2078
2078
  throw Error('basePath can not be empty');
@@ -2128,7 +2128,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
2128
2128
  chainID,
2129
2129
  coreContractAddress,
2130
2130
  registrationContractAddress,
2131
- sdkVersion: 'ts-immutable-sdk-0.28.6-alpha.1',
2131
+ sdkVersion: 'ts-immutable-sdk-0.28.7-alpha',
2132
2132
  });
2133
2133
  /**
2134
2134
  * Sets `sdkVersion` at the time of build
@@ -7056,39 +7056,63 @@ class AuthManager {
7056
7056
  }
7057
7057
  }
7058
7058
 
7059
+ const lazyLoad = (promiseToAwait, initialiseFunction) => (promiseToAwait().then(initialiseFunction));
7060
+ const lazyDocumentReady = (initialiseFunction) => {
7061
+ const documentReadyPromise = () => new Promise((resolve) => {
7062
+ if (window.document.readyState === 'complete') {
7063
+ resolve();
7064
+ }
7065
+ else {
7066
+ const onReadyStateChange = () => {
7067
+ if (window.document.readyState === 'complete') {
7068
+ resolve();
7069
+ window.document.removeEventListener('readystatechange', onReadyStateChange);
7070
+ }
7071
+ };
7072
+ window.document.addEventListener('readystatechange', onReadyStateChange);
7073
+ }
7074
+ });
7075
+ return lazyLoad(documentReadyPromise, initialiseFunction);
7076
+ };
7077
+
7059
7078
  class MagicAdapter {
7060
7079
  config;
7061
- magicClient;
7080
+ lazyMagicClient;
7062
7081
  constructor(config) {
7063
7082
  this.config = config;
7064
7083
  if (typeof window !== 'undefined') {
7065
- this.magicClient = this.initMagicClient();
7066
- this.magicClient.preload();
7084
+ this.lazyMagicClient = lazyDocumentReady(() => {
7085
+ const client = new Magic(this.config.magicPublishableApiKey, {
7086
+ extensions: [new OpenIdExtension()],
7087
+ network: this.config.network,
7088
+ });
7089
+ client.preload();
7090
+ return client;
7091
+ });
7092
+ }
7093
+ }
7094
+ get magicClient() {
7095
+ if (!this.lazyMagicClient) {
7096
+ throw new Error('Cannot perform this action outside of the browser');
7067
7097
  }
7098
+ return this.lazyMagicClient;
7068
7099
  }
7069
7100
  async login(idToken) {
7070
7101
  return withPassportError(async () => {
7071
- if (!this.magicClient) {
7072
- this.magicClient = this.initMagicClient();
7073
- }
7074
- await this.magicClient.openid.loginWithOIDC({
7102
+ const magicClient = await this.magicClient;
7103
+ await magicClient.openid.loginWithOIDC({
7075
7104
  jwt: idToken,
7076
7105
  providerId: this.config.magicProviderId,
7077
7106
  });
7078
- return this.magicClient.rpcProvider;
7107
+ return magicClient.rpcProvider;
7079
7108
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
7080
7109
  }
7081
7110
  async logout() {
7082
- if (this.magicClient?.user) {
7083
- await this.magicClient.user.logout();
7111
+ const magicClient = await this.magicClient;
7112
+ if (magicClient.user) {
7113
+ await magicClient.user.logout();
7084
7114
  }
7085
7115
  }
7086
- initMagicClient() {
7087
- return new Magic(this.config.magicPublishableApiKey, {
7088
- extensions: [new OpenIdExtension()],
7089
- network: this.config.network,
7090
- });
7091
- }
7092
7116
  }
7093
7117
 
7094
7118
  const getStarkSigner = async (signer) => withPassportError(async () => {
@@ -7315,7 +7339,7 @@ var PassportEvents;
7315
7339
  var Networks;
7316
7340
  (function (Networks) {
7317
7341
  Networks["PRODUCTION"] = "mainnet";
7318
- Networks["SANDBOX"] = "goerli";
7342
+ Networks["SANDBOX"] = "sepolia";
7319
7343
  })(Networks || (Networks = {}));
7320
7344
 
7321
7345
  async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
@@ -7664,6 +7688,11 @@ class PassportImxProvider {
7664
7688
  }
7665
7689
  // TODO: Remove once implemented
7666
7690
  // eslint-disable-next-line class-methods-use-this
7691
+ isRegisteredOffchain() {
7692
+ throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7693
+ }
7694
+ // TODO: Remove once implemented
7695
+ // eslint-disable-next-line class-methods-use-this
7667
7696
  isRegisteredOnchain() {
7668
7697
  throw new PassportError('Operation not supported', PassportErrorType.OPERATION_NOT_SUPPORTED_ERROR);
7669
7698
  }
@@ -7757,7 +7786,17 @@ class PassportImxProviderFactory {
7757
7786
  this.passportEventEmitter = passportEventEmitter;
7758
7787
  }
7759
7788
  async getProvider() {
7760
- const user = await this.authManager.loginSilent() || await this.authManager.login();
7789
+ let user = null;
7790
+ try {
7791
+ user = await this.authManager.loginSilent();
7792
+ }
7793
+ catch (e) {
7794
+ // eslint-disable-next-line no-console
7795
+ console.warn(e);
7796
+ }
7797
+ if (!user) {
7798
+ user = await this.authManager.login();
7799
+ }
7761
7800
  return this.createProviderInstance(user);
7762
7801
  }
7763
7802
  async getProviderSilent() {
@@ -8812,7 +8851,14 @@ class Passport {
8812
8851
  */
8813
8852
  async login(options) {
8814
8853
  const { useCachedSession = false } = options || {};
8815
- let user = await this.authManager.loginSilent();
8854
+ let user = null;
8855
+ try {
8856
+ user = await this.authManager.loginSilent();
8857
+ }
8858
+ catch (error) {
8859
+ // eslint-disable-next-line no-console
8860
+ console.warn('loginSilent failed with error:', error);
8861
+ }
8816
8862
  if (!user && !useCachedSession) {
8817
8863
  user = await this.authManager.login();
8818
8864
  }
@@ -833,6 +833,12 @@ interface IMXProvider {
833
833
  * @return {Promise<RegisterUserResponse>} Returns a promise that resolves with the user registration response
834
834
  */
835
835
  registerOffchain(): Promise<RegisterUserResponse>;
836
+ /**
837
+ * Checks if a User is registered off-chain
838
+ *
839
+ * @return {Promise<boolean>} Returns a promise that resolves with true if the User is registered with IMX, false otherwise
840
+ */
841
+ isRegisteredOffchain(): Promise<boolean>;
836
842
  /**
837
843
  * Checks if a User is registered on-chain
838
844
  *
@@ -910,6 +916,7 @@ declare class GenericIMXProvider implements IMXProvider {
910
916
  private readonly signers;
911
917
  constructor(config: ProviderConfiguration$1, ethSigner: Signer, starkSigner: StarkSigner);
912
918
  getAddress(): Promise<string>;
919
+ isRegisteredOffchain(): Promise<boolean>;
913
920
  registerOffchain(): Promise<RegisterUserResponse>;
914
921
  batchNftTransfer(request: Array<NftTransferDetails>): Promise<CreateTransferResponse>;
915
922
  cancelOrder(request: GetSignableCancelOrderRequest): Promise<CancelOrderResponse>;