@imtbl/sdk 1.13.1 → 1.13.2

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
@@ -11,7 +11,7 @@ import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers';
11
11
  import BN from 'bn.js';
12
12
  import * as encUtils from 'enc-utils';
13
13
  import { EventEmitter } from 'events';
14
- import { BigNumber, ethers } from 'ethers';
14
+ import { BigNumber, Contract, errors, utils as utils$2, ethers, constants } from 'ethers';
15
15
  import { walletContracts } from '@0xsequence/abi';
16
16
  import { v1 } from '@0xsequence/core';
17
17
 
@@ -9346,7 +9346,7 @@ class MultiRollupApiClients {
9346
9346
  }
9347
9347
 
9348
9348
  // eslint-disable-next-line @typescript-eslint/naming-convention
9349
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.13.1' };
9349
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.13.2' };
9350
9350
  const createConfig = ({ basePath, headers, }) => {
9351
9351
  if (!basePath.trim()) {
9352
9352
  throw Error('basePath can not be empty');
@@ -9525,7 +9525,7 @@ const flattenProperties = (properties) => {
9525
9525
  };
9526
9526
 
9527
9527
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
9528
- const SDK_VERSION = '1.13.1';
9528
+ const SDK_VERSION = '1.13.2';
9529
9529
  const getReferrer = () => {
9530
9530
  if (isNode()) {
9531
9531
  return '';
@@ -9744,7 +9744,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
9744
9744
  chainID,
9745
9745
  coreContractAddress,
9746
9746
  registrationContractAddress,
9747
- sdkVersion: 'ts-immutable-sdk-1.13.1',
9747
+ sdkVersion: 'ts-immutable-sdk-1.13.2',
9748
9748
  });
9749
9749
  /**
9750
9750
  * Sets `sdkVersion` at the time of build
@@ -14341,6 +14341,17 @@ class DeviceCredentialsManager {
14341
14341
  }
14342
14342
  }
14343
14343
 
14344
+ const shouldLog = process?.env?.JEST_WORKER_ID === undefined;
14345
+ const warn = (...args) => {
14346
+ if (shouldLog) {
14347
+ // eslint-disable-next-line no-console
14348
+ console.warn(...args);
14349
+ }
14350
+ };
14351
+ var logger = {
14352
+ warn,
14353
+ };
14354
+
14344
14355
  function isIdTokenExpired(idToken) {
14345
14356
  if (!idToken) {
14346
14357
  return false;
@@ -14503,8 +14514,7 @@ class AuthManager {
14503
14514
  user = await this.getUser();
14504
14515
  }
14505
14516
  catch (err) {
14506
- // eslint-disable-next-line no-console
14507
- console.warn('failed to retrieve a cached user session:', err);
14517
+ logger.warn('Failed to retrieve a cached user session', err);
14508
14518
  }
14509
14519
  return user || this.login();
14510
14520
  }
@@ -14648,8 +14658,7 @@ class AuthManager {
14648
14658
  }
14649
14659
  forceUserRefreshInBackground() {
14650
14660
  this.refreshTokenAndUpdatePromise().catch((error) => {
14651
- // eslint-disable-next-line no-console
14652
- console.warn('Failed to refresh user token', error);
14661
+ logger.warn('Failed to refresh user token', error);
14653
14662
  });
14654
14663
  }
14655
14664
  async forceUserRefresh() {
@@ -15691,33 +15700,45 @@ function getNormalisedTransactions(txs) {
15691
15700
  return txs.map((t) => ({
15692
15701
  delegateCall: t.delegateCall === true,
15693
15702
  revertOnError: t.revertOnError === true,
15694
- gasLimit: t.gasLimit ?? ethers.constants.Zero,
15695
- target: t.to ?? ethers.constants.AddressZero,
15696
- value: t.value ?? ethers.constants.Zero,
15703
+ gasLimit: t.gasLimit ?? constants.Zero,
15704
+ target: t.to ?? constants.AddressZero,
15705
+ value: t.value ?? constants.Zero,
15697
15706
  data: t.data ?? [],
15698
15707
  }));
15699
15708
  }
15700
15709
  function digestOfTransactionsAndNonce(nonce, normalisedTransactions) {
15701
- const packMetaTransactionsNonceData = ethers.utils.defaultAbiCoder.encode(['uint256', META_TRANSACTIONS_TYPE], [nonce, normalisedTransactions]);
15702
- return ethers.utils.keccak256(packMetaTransactionsNonceData);
15710
+ const packMetaTransactionsNonceData = utils$2.defaultAbiCoder.encode(['uint256', META_TRANSACTIONS_TYPE], [nonce, normalisedTransactions]);
15711
+ return utils$2.keccak256(packMetaTransactionsNonceData);
15703
15712
  }
15704
15713
  const getNonce = async (jsonRpcProvider, smartContractWalletAddress) => {
15705
- const code = await jsonRpcProvider.send('eth_getCode', [smartContractWalletAddress, 'latest']);
15706
- if (code && code !== '0x') {
15707
- const contract = new ethers.Contract(smartContractWalletAddress, walletContracts.mainModule.abi, jsonRpcProvider);
15708
- return contract.nonce();
15714
+ try {
15715
+ const contract = new Contract(smartContractWalletAddress, walletContracts.mainModule.abi, jsonRpcProvider);
15716
+ const result = await contract.nonce();
15717
+ if (result instanceof BigNumber) {
15718
+ return result;
15719
+ }
15720
+ }
15721
+ catch (error) {
15722
+ if (error instanceof Error
15723
+ && 'code' in error
15724
+ && error.code === errors.CALL_EXCEPTION) {
15725
+ // The most likely reason for a CALL_EXCEPTION is that the smart contract wallet
15726
+ // has not been deployed yet, so we should default to a nonce of 0.
15727
+ return BigNumber.from(0);
15728
+ }
15729
+ throw error;
15709
15730
  }
15710
- return 0;
15731
+ throw new Error('Unexpected result from contract.nonce() call.');
15711
15732
  };
15712
- const encodeMessageSubDigest = (chainId, walletAddress, digest) => (ethers.utils.solidityPack(['string', 'uint256', 'address', 'bytes32'], [ETH_SIGN_PREFIX, chainId, walletAddress, digest]));
15733
+ const encodeMessageSubDigest = (chainId, walletAddress, digest) => (utils$2.solidityPack(['string', 'uint256', 'address', 'bytes32'], [ETH_SIGN_PREFIX, chainId, walletAddress, digest]));
15713
15734
  const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walletAddress, signer) => {
15714
15735
  const normalisedMetaTransactions = getNormalisedTransactions(metaTransactions);
15715
15736
  // Get the hash
15716
15737
  const digest = digestOfTransactionsAndNonce(nonce, normalisedMetaTransactions);
15717
15738
  const completePayload = encodeMessageSubDigest(chainId, walletAddress, digest);
15718
- const hash = ethers.utils.keccak256(completePayload);
15739
+ const hash = utils$2.keccak256(completePayload);
15719
15740
  // Sign the digest
15720
- const hashArray = ethers.utils.arrayify(hash);
15741
+ const hashArray = utils$2.arrayify(hash);
15721
15742
  const ethsigNoType = await signer.signMessage(hashArray);
15722
15743
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
15723
15744
  // Add metadata
@@ -15734,7 +15755,7 @@ const getSignedMetaTransactions = async (metaTransactions, nonce, chainId, walle
15734
15755
  ],
15735
15756
  });
15736
15757
  // Encode the transaction;
15737
- const walletInterface = new ethers.utils.Interface(walletContracts.mainModule.abi);
15758
+ const walletInterface = new utils$2.Interface(walletContracts.mainModule.abi);
15738
15759
  return walletInterface.encodeFunctionData(walletInterface.getFunction('execute'), [
15739
15760
  normalisedMetaTransactions,
15740
15761
  nonce,
@@ -15751,13 +15772,13 @@ const getSignedTypedData = async (typedData, relayerSignature, chainId, walletAd
15751
15772
  // @ts-ignore
15752
15773
  delete types.EIP712Domain;
15753
15774
  // Hash the EIP712 payload and generate the complete payload
15754
- const { _TypedDataEncoder: typedDataEncoder } = ethers.utils;
15775
+ const { _TypedDataEncoder: typedDataEncoder } = utils$2;
15755
15776
  const typedDataHash = typedDataEncoder.hash(typedData.domain, types, typedData.message);
15756
15777
  const messageSubDigest = encodeMessageSubDigest(chainId, walletAddress, typedDataHash);
15757
- const hash = ethers.utils.keccak256(messageSubDigest);
15778
+ const hash = utils$2.keccak256(messageSubDigest);
15758
15779
  // Sign the sub digest
15759
15780
  // https://github.com/immutable/wallet-contracts/blob/7824b5f24b2e0eb2dc465ecb5cd71f3984556b73/src/contracts/modules/commons/ModuleAuth.sol#L155
15760
- const hashArray = ethers.utils.arrayify(hash);
15781
+ const hashArray = utils$2.arrayify(hash);
15761
15782
  const ethsigNoType = await signer.signMessage(hashArray);
15762
15783
  const signedDigest = `${ethsigNoType}${ETH_SIGN_FLAG}`;
15763
15784
  // Combine the relayer and user signatures; sort by address to match the imageHash order
@@ -16621,8 +16642,7 @@ class Passport {
16621
16642
  if (useCachedSession) {
16622
16643
  throw error;
16623
16644
  }
16624
- // eslint-disable-next-line no-console
16625
- console.warn('login failed to retrieve a cached user session', error);
16645
+ logger.warn('Failed to retrieve a cached user session', error);
16626
16646
  }
16627
16647
  if (!user && !useCachedSession) {
16628
16648
  user = await this.authManager.login(options?.anonymousId);
@@ -16656,8 +16676,7 @@ class Passport {
16656
16676
  await this.confirmationScreen.logout();
16657
16677
  }
16658
16678
  catch (err) {
16659
- // eslint-disable-next-line no-console
16660
- console.warn('Failed to logout from confirmation screen', err);
16679
+ logger.warn('Failed to logout from confirmation screen', err);
16661
16680
  }
16662
16681
  await Promise.allSettled([
16663
16682
  this.authManager.logout(),
package/dist/x.d.ts CHANGED
@@ -9775,20 +9775,8 @@ declare class ImmutableConfiguration {
9775
9775
  publishableKey?: string;
9776
9776
  });
9777
9777
  }
9778
- type ImmutableConfigurationWithRequireableFields<T> = ImmutableConfiguration & (T extends {
9779
- apiKey: 'required';
9780
- } ? Required<{
9781
- apiKey: string;
9782
- }> : {}) & (T extends {
9783
- publishableKey: 'required';
9784
- } ? Required<{
9785
- publishableKey: string;
9786
- }> : {});
9787
- type ImmutableConfigurationWithOmitableFields<T> = T extends {
9788
- apiKey: 'omit';
9789
- } ? Omit<ImmutableConfigurationWithRequireableFields<T>, 'apiKey'> : ImmutableConfigurationWithRequireableFields<T>;
9790
9778
  interface ModuleConfiguration<T> {
9791
- baseConfig: ImmutableConfigurationWithOmitableFields<T>;
9779
+ baseConfig: ImmutableConfiguration;
9792
9780
  overrides?: T;
9793
9781
  }
9794
9782
 
package/dist/x.js CHANGED
@@ -136,7 +136,7 @@ const flattenProperties = (properties) => {
136
136
  };
137
137
 
138
138
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
139
- const SDK_VERSION = '1.13.1';
139
+ const SDK_VERSION = '1.13.2';
140
140
  const getReferrer = () => {
141
141
  if (isNode()) {
142
142
  return '';
@@ -334,7 +334,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
334
334
  chainID,
335
335
  coreContractAddress,
336
336
  registrationContractAddress,
337
- sdkVersion: 'ts-immutable-sdk-1.13.1',
337
+ sdkVersion: 'ts-immutable-sdk-1.13.2',
338
338
  });
339
339
  /**
340
340
  * Sets `sdkVersion` at the time of build
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "1.13.1",
4
+ "version": "1.13.2",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",