@imtbl/sdk 0.28.2 → 0.28.3

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
@@ -55,10 +55,29 @@ var Environment$1;
55
55
  })(Environment$1 || (Environment$1 = {}));
56
56
  class ImmutableConfiguration {
57
57
  environment;
58
+ rateLimitingKey;
58
59
  apiKey;
60
+ clientAppId;
59
61
  constructor(options) {
60
62
  this.environment = options.environment;
61
- this.apiKey = options.apiKey;
63
+ if (options.rateLimitingKey) {
64
+ this.rateLimitingKey = options.rateLimitingKey;
65
+ globalAxios$1.defaults.headers.common['x-api-key'] = this.rateLimitingKey;
66
+ }
67
+ if (options.apiKey) {
68
+ if (!options.apiKey.startsWith('sk_imapik-')) {
69
+ throw new Error('Invalid API key');
70
+ }
71
+ this.apiKey = options.apiKey;
72
+ globalAxios$1.defaults.headers.common['x-immutable-api-key'] = this.apiKey;
73
+ }
74
+ if (options.clientAppId) {
75
+ if (!options.clientAppId.startsWith('cai_imapik-')) {
76
+ throw new Error('Invalid Client App Id');
77
+ }
78
+ this.clientAppId = options.clientAppId;
79
+ globalAxios$1.defaults.headers.common['x-immutable-client-app-id'] = this.clientAppId;
80
+ }
62
81
  }
63
82
  }
64
83
 
@@ -3632,7 +3651,7 @@ class MultiRollupApiClients {
3632
3651
  }
3633
3652
 
3634
3653
  // eslint-disable-next-line @typescript-eslint/naming-convention
3635
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.28.2' };
3654
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.28.3' };
3636
3655
  const createConfig = ({ basePath, headers, }) => {
3637
3656
  if (!basePath.trim()) {
3638
3657
  throw Error('basePath can not be empty');
@@ -3692,7 +3711,7 @@ class APIError extends Error {
3692
3711
 
3693
3712
  /* eslint-disable implicit-arrow-linebreak */
3694
3713
  const defaultHeaders = {
3695
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.2',
3714
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.3',
3696
3715
  };
3697
3716
  /**
3698
3717
  * createAPIConfiguration to create a custom Configuration
@@ -4103,7 +4122,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4103
4122
  chainID,
4104
4123
  coreContractAddress,
4105
4124
  registrationContractAddress,
4106
- sdkVersion: 'ts-immutable-sdk-0.28.2',
4125
+ sdkVersion: 'ts-immutable-sdk-0.28.3',
4107
4126
  });
4108
4127
  /**
4109
4128
  * Sets `sdkVersion` at the time of build
@@ -9573,13 +9592,12 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
9573
9592
  }),
9574
9593
  receiver: nftTransfer.receiver,
9575
9594
  }));
9576
- const getSignableTransferRequestV2 = {
9577
- sender_ether_key: ethAddress,
9578
- signable_requests: signableRequests,
9579
- };
9580
9595
  const headers = { Authorization: `Bearer ${user.accessToken}` };
9581
9596
  const signableResult = await transfersApi.getSignableTransfer({
9582
- getSignableTransferRequestV2,
9597
+ getSignableTransferRequestV2: {
9598
+ sender_ether_key: ethAddress,
9599
+ signable_requests: signableRequests,
9600
+ },
9583
9601
  }, { headers });
9584
9602
  await guardianClient.evaluateImxTransaction({
9585
9603
  user,
@@ -10360,36 +10378,19 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
10360
10378
 
10361
10379
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
10362
10380
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
10363
- const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
10364
- .withConfirmationScreen({ width: 480, height: 520 })(async () => {
10365
- const transactionRequest = params[0];
10366
- if (!transactionRequest.to) {
10367
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
10368
- }
10369
- const { chainId } = await jsonRpcProvider.ready;
10370
- const chainIdBigNumber = ethers.BigNumber.from(chainId);
10371
- const magicWeb3Provider = new providers.Web3Provider(magicProvider);
10372
- const signer = magicWeb3Provider.getSigner();
10373
- const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
10374
- const metaTransaction = {
10375
- to: transactionRequest.to,
10376
- data: transactionRequest.data,
10377
- nonce,
10378
- value: transactionRequest.value,
10379
- revertOnError: true,
10380
- };
10381
+ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddress, signer, relayerClient) => {
10381
10382
  // NOTE: We sign the transaction before getting the fee options because
10382
10383
  // accurate estimation of a transaction gas cost is only possible if the smart
10383
10384
  // wallet contract can actually execute it (in a simulated environment) - and
10384
10385
  // it can only execute signed transactions.
10385
- const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
10386
+ const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainId, walletAddress, signer);
10386
10387
  // TODO: ID-698 Add support for non-native gas payments (e.g ERC20, feeTransaction initialisation must change)
10387
10388
  // NOTE: "Fee Options" represent the multiple ways we could pay for the gas
10388
10389
  // used in this transaction. Each fee option has a "recipientAddress" we
10389
10390
  // should transfer the payment to, an amount and a currency. We choose one
10390
10391
  // option and build a transaction that sends the expected currency amount for
10391
10392
  // that option to the specified address.
10392
- const feeOptions = await relayerClient.imGetFeeOptions(user.zkEvm.ethAddress, signedTransaction);
10393
+ const feeOptions = await relayerClient.imGetFeeOptions(walletAddress, signedTransaction);
10393
10394
  const imxFeeOption = feeOptions.find((feeOption) => feeOption.tokenSymbol === 'IMX');
10394
10395
  if (!imxFeeOption) {
10395
10396
  throw new Error('Failed to retrieve fees for IMX token');
@@ -10400,15 +10401,39 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
10400
10401
  value: imxFeeOption.tokenPrice,
10401
10402
  revertOnError: true,
10402
10403
  };
10404
+ if (ethers.BigNumber.from(feeMetaTransaction.value).isZero()) {
10405
+ return [metaTransaction];
10406
+ }
10407
+ return [metaTransaction, feeMetaTransaction];
10408
+ };
10409
+ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
10410
+ .withConfirmationScreen({ width: 480, height: 520 })(async () => {
10411
+ const transactionRequest = params[0];
10412
+ if (!transactionRequest.to) {
10413
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
10414
+ }
10415
+ const { chainId } = await jsonRpcProvider.ready;
10416
+ const chainIdBigNumber = ethers.BigNumber.from(chainId);
10417
+ const magicWeb3Provider = new providers.Web3Provider(magicProvider);
10418
+ const signer = magicWeb3Provider.getSigner();
10419
+ const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
10420
+ const metaTransaction = {
10421
+ to: transactionRequest.to,
10422
+ data: transactionRequest.data,
10423
+ nonce,
10424
+ value: transactionRequest.value,
10425
+ revertOnError: true,
10426
+ };
10427
+ const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer, relayerClient);
10403
10428
  await guardianClient.validateEVMTransaction({
10404
10429
  chainId: getEip155ChainId(chainId),
10405
10430
  nonce: convertBigNumberishToString(nonce),
10406
10431
  user,
10407
- metaTransactions: [metaTransaction, feeMetaTransaction],
10432
+ metaTransactions,
10408
10433
  });
10409
10434
  // NOTE: We sign again because we now are adding the fee transaction, so the
10410
10435
  // whole payload is different and needs a new signature.
10411
- const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
10436
+ const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
10412
10437
  const relayerId = await relayerClient.ethSendTransaction(user.zkEvm.ethAddress, signedTransactions);
10413
10438
  const retrieveRelayerTransaction = async () => {
10414
10439
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -10747,19 +10772,9 @@ class Passport {
10747
10772
  passportEventEmitter: this.passportEventEmitter,
10748
10773
  });
10749
10774
  }
10750
- async signIn(options) {
10751
- const { useCachedSession = false } = options || {};
10752
- let user = await this.authManager.loginSilent();
10753
- if (!user && !useCachedSession) {
10754
- user = await this.authManager.login();
10755
- }
10756
- if (!user) {
10757
- return null;
10758
- }
10759
- return user.profile;
10760
- }
10761
10775
  /**
10762
- * @deprecated The method connectImx(useCachedSession) should be used instead
10776
+ * @deprecated The method `login` with an argument of `{ useCachedSession: true }` should be used in conjunction with
10777
+ * `connectImx` instead.
10763
10778
  */
10764
10779
  async connectImxSilent() {
10765
10780
  return this.passportImxProviderFactory.getProviderSilent();
@@ -10767,9 +10782,6 @@ class Passport {
10767
10782
  async connectImx() {
10768
10783
  return this.passportImxProviderFactory.getProvider();
10769
10784
  }
10770
- async loginWithDeviceFlow() {
10771
- return this.authManager.loginWithDeviceFlow();
10772
- }
10773
10785
  async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
10774
10786
  return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
10775
10787
  }
@@ -10801,6 +10813,25 @@ class Passport {
10801
10813
  multiRollupApiClients: this.multiRollupApiClients,
10802
10814
  });
10803
10815
  }
10816
+ /**
10817
+ *
10818
+ * Initiates the authorisation flow.
10819
+ *
10820
+ * @param options.useCachedSession = false - If true, and no active session exists, then the user will not be
10821
+ * prompted to log in and the Promise will resolve with a null value.
10822
+ * @returns {Promise<UserProfile | null>} the user profile if the user is logged in, otherwise null
10823
+ */
10824
+ async login(options) {
10825
+ const { useCachedSession = false } = options || {};
10826
+ let user = await this.authManager.loginSilent();
10827
+ if (!user && !useCachedSession) {
10828
+ user = await this.authManager.login();
10829
+ }
10830
+ return user ? user.profile : null;
10831
+ }
10832
+ async loginWithDeviceFlow() {
10833
+ return this.authManager.loginWithDeviceFlow();
10834
+ }
10804
10835
  async loginCallback() {
10805
10836
  return this.authManager.loginCallback();
10806
10837
  }
@@ -12663,6 +12694,8 @@ async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi
12663
12694
  return {
12664
12695
  operator_signature: response.data.operator_signature,
12665
12696
  payload_hash: response.data.payload_hash,
12697
+ readable_transaction: response.data.readable_transaction,
12698
+ verification_signature: response.data.verification_signature,
12666
12699
  };
12667
12700
  }
12668
12701
 
@@ -33554,7 +33587,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
33554
33587
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
33555
33588
 
33556
33589
 
33557
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.28.2";
33590
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.28.3";
33558
33591
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
33559
33592
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
33560
33593