@imtbl/sdk 0.28.1-alpha → 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.js CHANGED
@@ -33,10 +33,29 @@ var Environment$1;
33
33
  })(Environment$1 || (Environment$1 = {}));
34
34
  class ImmutableConfiguration {
35
35
  environment;
36
+ rateLimitingKey;
36
37
  apiKey;
38
+ clientAppId;
37
39
  constructor(options) {
38
40
  this.environment = options.environment;
39
- this.apiKey = options.apiKey;
41
+ if (options.rateLimitingKey) {
42
+ this.rateLimitingKey = options.rateLimitingKey;
43
+ globalAxios$1.defaults.headers.common['x-api-key'] = this.rateLimitingKey;
44
+ }
45
+ if (options.apiKey) {
46
+ if (!options.apiKey.startsWith('sk_imapik-')) {
47
+ throw new Error('Invalid API key');
48
+ }
49
+ this.apiKey = options.apiKey;
50
+ globalAxios$1.defaults.headers.common['x-immutable-api-key'] = this.apiKey;
51
+ }
52
+ if (options.clientAppId) {
53
+ if (!options.clientAppId.startsWith('cai_imapik-')) {
54
+ throw new Error('Invalid Client App Id');
55
+ }
56
+ this.clientAppId = options.clientAppId;
57
+ globalAxios$1.defaults.headers.common['x-immutable-client-app-id'] = this.clientAppId;
58
+ }
40
59
  }
41
60
  }
42
61
 
@@ -3610,7 +3629,7 @@ class MultiRollupApiClients {
3610
3629
  }
3611
3630
 
3612
3631
  // eslint-disable-next-line @typescript-eslint/naming-convention
3613
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.28.1-alpha' };
3632
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.28.3' };
3614
3633
  const createConfig = ({ basePath, headers, }) => {
3615
3634
  if (!basePath.trim()) {
3616
3635
  throw Error('basePath can not be empty');
@@ -3670,7 +3689,7 @@ class APIError extends Error {
3670
3689
 
3671
3690
  /* eslint-disable implicit-arrow-linebreak */
3672
3691
  const defaultHeaders = {
3673
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.1-alpha',
3692
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.28.3',
3674
3693
  };
3675
3694
  /**
3676
3695
  * createAPIConfiguration to create a custom Configuration
@@ -4081,7 +4100,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4081
4100
  chainID,
4082
4101
  coreContractAddress,
4083
4102
  registrationContractAddress,
4084
- sdkVersion: 'ts-immutable-sdk-0.28.1-alpha',
4103
+ sdkVersion: 'ts-immutable-sdk-0.28.3',
4085
4104
  });
4086
4105
  /**
4087
4106
  * Sets `sdkVersion` at the time of build
@@ -9551,13 +9570,12 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
9551
9570
  }),
9552
9571
  receiver: nftTransfer.receiver,
9553
9572
  }));
9554
- const getSignableTransferRequestV2 = {
9555
- sender_ether_key: ethAddress,
9556
- signable_requests: signableRequests,
9557
- };
9558
9573
  const headers = { Authorization: `Bearer ${user.accessToken}` };
9559
9574
  const signableResult = await transfersApi.getSignableTransfer({
9560
- getSignableTransferRequestV2,
9575
+ getSignableTransferRequestV2: {
9576
+ sender_ether_key: ethAddress,
9577
+ signable_requests: signableRequests,
9578
+ },
9561
9579
  }, { headers });
9562
9580
  await guardianClient.evaluateImxTransaction({
9563
9581
  user,
@@ -10338,36 +10356,19 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
10338
10356
 
10339
10357
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
10340
10358
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
10341
- const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
10342
- .withConfirmationScreen({ width: 480, height: 520 })(async () => {
10343
- const transactionRequest = params[0];
10344
- if (!transactionRequest.to) {
10345
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
10346
- }
10347
- const { chainId } = await jsonRpcProvider.ready;
10348
- const chainIdBigNumber = BigNumber$1.from(chainId);
10349
- const magicWeb3Provider = new Web3Provider(magicProvider);
10350
- const signer = magicWeb3Provider.getSigner();
10351
- const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
10352
- const metaTransaction = {
10353
- to: transactionRequest.to,
10354
- data: transactionRequest.data,
10355
- nonce,
10356
- value: transactionRequest.value,
10357
- revertOnError: true,
10358
- };
10359
+ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddress, signer, relayerClient) => {
10359
10360
  // NOTE: We sign the transaction before getting the fee options because
10360
10361
  // accurate estimation of a transaction gas cost is only possible if the smart
10361
10362
  // wallet contract can actually execute it (in a simulated environment) - and
10362
10363
  // it can only execute signed transactions.
10363
- const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
10364
+ const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainId, walletAddress, signer);
10364
10365
  // TODO: ID-698 Add support for non-native gas payments (e.g ERC20, feeTransaction initialisation must change)
10365
10366
  // NOTE: "Fee Options" represent the multiple ways we could pay for the gas
10366
10367
  // used in this transaction. Each fee option has a "recipientAddress" we
10367
10368
  // should transfer the payment to, an amount and a currency. We choose one
10368
10369
  // option and build a transaction that sends the expected currency amount for
10369
10370
  // that option to the specified address.
10370
- const feeOptions = await relayerClient.imGetFeeOptions(user.zkEvm.ethAddress, signedTransaction);
10371
+ const feeOptions = await relayerClient.imGetFeeOptions(walletAddress, signedTransaction);
10371
10372
  const imxFeeOption = feeOptions.find((feeOption) => feeOption.tokenSymbol === 'IMX');
10372
10373
  if (!imxFeeOption) {
10373
10374
  throw new Error('Failed to retrieve fees for IMX token');
@@ -10378,15 +10379,39 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
10378
10379
  value: imxFeeOption.tokenPrice,
10379
10380
  revertOnError: true,
10380
10381
  };
10382
+ if (BigNumber$1.from(feeMetaTransaction.value).isZero()) {
10383
+ return [metaTransaction];
10384
+ }
10385
+ return [metaTransaction, feeMetaTransaction];
10386
+ };
10387
+ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
10388
+ .withConfirmationScreen({ width: 480, height: 520 })(async () => {
10389
+ const transactionRequest = params[0];
10390
+ if (!transactionRequest.to) {
10391
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
10392
+ }
10393
+ const { chainId } = await jsonRpcProvider.ready;
10394
+ const chainIdBigNumber = BigNumber$1.from(chainId);
10395
+ const magicWeb3Provider = new Web3Provider(magicProvider);
10396
+ const signer = magicWeb3Provider.getSigner();
10397
+ const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
10398
+ const metaTransaction = {
10399
+ to: transactionRequest.to,
10400
+ data: transactionRequest.data,
10401
+ nonce,
10402
+ value: transactionRequest.value,
10403
+ revertOnError: true,
10404
+ };
10405
+ const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer, relayerClient);
10381
10406
  await guardianClient.validateEVMTransaction({
10382
10407
  chainId: getEip155ChainId(chainId),
10383
10408
  nonce: convertBigNumberishToString(nonce),
10384
10409
  user,
10385
- metaTransactions: [metaTransaction, feeMetaTransaction],
10410
+ metaTransactions,
10386
10411
  });
10387
10412
  // NOTE: We sign again because we now are adding the fee transaction, so the
10388
10413
  // whole payload is different and needs a new signature.
10389
- const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
10414
+ const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
10390
10415
  const relayerId = await relayerClient.ethSendTransaction(user.zkEvm.ethAddress, signedTransactions);
10391
10416
  const retrieveRelayerTransaction = async () => {
10392
10417
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -10725,33 +10750,16 @@ class Passport {
10725
10750
  passportEventEmitter: this.passportEventEmitter,
10726
10751
  });
10727
10752
  }
10728
- async signIn(options) {
10729
- const { useCachedSession = false } = options || {};
10730
- let user = await this.authManager.loginSilent();
10731
- if (!user && !useCachedSession) {
10732
- user = await this.authManager.login();
10733
- }
10734
- if (!user) {
10735
- return null;
10736
- }
10737
- return user.profile;
10738
- }
10739
10753
  /**
10740
- * @deprecated The method connectImx(useCachedSession) should be used instead
10754
+ * @deprecated The method `login` with an argument of `{ useCachedSession: true }` should be used in conjunction with
10755
+ * `connectImx` instead.
10741
10756
  */
10742
10757
  async connectImxSilent() {
10743
10758
  return this.passportImxProviderFactory.getProviderSilent();
10744
10759
  }
10745
- async connectImx(options) {
10746
- const { useCachedSession = false } = options || {};
10747
- if (useCachedSession) {
10748
- return this.passportImxProviderFactory.getProviderSilent();
10749
- }
10760
+ async connectImx() {
10750
10761
  return this.passportImxProviderFactory.getProvider();
10751
10762
  }
10752
- async loginWithDeviceFlow() {
10753
- return this.authManager.loginWithDeviceFlow();
10754
- }
10755
10763
  async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
10756
10764
  return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
10757
10765
  }
@@ -10783,6 +10791,25 @@ class Passport {
10783
10791
  multiRollupApiClients: this.multiRollupApiClients,
10784
10792
  });
10785
10793
  }
10794
+ /**
10795
+ *
10796
+ * Initiates the authorisation flow.
10797
+ *
10798
+ * @param options.useCachedSession = false - If true, and no active session exists, then the user will not be
10799
+ * prompted to log in and the Promise will resolve with a null value.
10800
+ * @returns {Promise<UserProfile | null>} the user profile if the user is logged in, otherwise null
10801
+ */
10802
+ async login(options) {
10803
+ const { useCachedSession = false } = options || {};
10804
+ let user = await this.authManager.loginSilent();
10805
+ if (!user && !useCachedSession) {
10806
+ user = await this.authManager.login();
10807
+ }
10808
+ return user ? user.profile : null;
10809
+ }
10810
+ async loginWithDeviceFlow() {
10811
+ return this.authManager.loginWithDeviceFlow();
10812
+ }
10786
10813
  async loginCallback() {
10787
10814
  return this.authManager.loginCallback();
10788
10815
  }
@@ -12645,6 +12672,8 @@ async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi
12645
12672
  return {
12646
12673
  operator_signature: response.data.operator_signature,
12647
12674
  payload_hash: response.data.payload_hash,
12675
+ readable_transaction: response.data.readable_transaction,
12676
+ verification_signature: response.data.verification_signature,
12648
12677
  };
12649
12678
  }
12650
12679
 
@@ -30295,7 +30324,7 @@ class $fd8a8472dcc3ec2b$export$ef140a6b05dfc786 {
30295
30324
 
30296
30325
  const $458d407830d66110$export$e6a390ea6399b7d8 = (config, debugString, seconds)=>{
30297
30326
  // eslint-disable-next-line no-console
30298
- if (!config.isProduction) console.debug(debugString, seconds);
30327
+ if (!config.isProduction) console.info(debugString, seconds);
30299
30328
  };
30300
30329
  const $458d407830d66110$export$5280dbcb91c8b391 = async (config, debugString, promise)=>{
30301
30330
  const startTime = performance.now();
@@ -33536,7 +33565,7 @@ var $045213b18e9f1f94$export$75be0f6af9650f2c;
33536
33565
  })($045213b18e9f1f94$export$75be0f6af9650f2c || ($045213b18e9f1f94$export$75be0f6af9650f2c = {}));
33537
33566
 
33538
33567
 
33539
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.28.1-alpha";
33568
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.28.3";
33540
33569
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
33541
33570
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
33542
33571
 
@@ -5,10 +5,14 @@ declare enum Environment {
5
5
  }
6
6
  declare class ImmutableConfiguration {
7
7
  readonly environment: Environment;
8
+ readonly rateLimitingKey?: string;
8
9
  readonly apiKey?: string;
10
+ readonly clientAppId?: string;
9
11
  constructor(options: {
10
12
  environment: Environment;
13
+ rateLimitingKey?: string;
11
14
  apiKey?: string;
15
+ clientAppId?: string;
12
16
  });
13
17
  }
14
18
  interface ModuleConfiguration<T> {