@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/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.1-alpha' };
2075
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.3' };
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.1-alpha',
2131
+ sdkVersion: 'ts-immutable-sdk-0.28.3',
2132
2132
  });
2133
2133
  /**
2134
2134
  * Sets `sdkVersion` at the time of build
@@ -7581,13 +7581,12 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
7581
7581
  }),
7582
7582
  receiver: nftTransfer.receiver,
7583
7583
  }));
7584
- const getSignableTransferRequestV2 = {
7585
- sender_ether_key: ethAddress,
7586
- signable_requests: signableRequests,
7587
- };
7588
7584
  const headers = { Authorization: `Bearer ${user.accessToken}` };
7589
7585
  const signableResult = await transfersApi.getSignableTransfer({
7590
- getSignableTransferRequestV2,
7586
+ getSignableTransferRequestV2: {
7587
+ sender_ether_key: ethAddress,
7588
+ signable_requests: signableRequests,
7589
+ },
7591
7590
  }, { headers });
7592
7591
  await guardianClient.evaluateImxTransaction({
7593
7592
  user,
@@ -8368,36 +8367,19 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
8368
8367
 
8369
8368
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
8370
8369
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
8371
- const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
8372
- .withConfirmationScreen({ width: 480, height: 520 })(async () => {
8373
- const transactionRequest = params[0];
8374
- if (!transactionRequest.to) {
8375
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
8376
- }
8377
- const { chainId } = await jsonRpcProvider.ready;
8378
- const chainIdBigNumber = BigNumber.from(chainId);
8379
- const magicWeb3Provider = new Web3Provider(magicProvider);
8380
- const signer = magicWeb3Provider.getSigner();
8381
- const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
8382
- const metaTransaction = {
8383
- to: transactionRequest.to,
8384
- data: transactionRequest.data,
8385
- nonce,
8386
- value: transactionRequest.value,
8387
- revertOnError: true,
8388
- };
8370
+ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddress, signer, relayerClient) => {
8389
8371
  // NOTE: We sign the transaction before getting the fee options because
8390
8372
  // accurate estimation of a transaction gas cost is only possible if the smart
8391
8373
  // wallet contract can actually execute it (in a simulated environment) - and
8392
8374
  // it can only execute signed transactions.
8393
- const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8375
+ const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainId, walletAddress, signer);
8394
8376
  // TODO: ID-698 Add support for non-native gas payments (e.g ERC20, feeTransaction initialisation must change)
8395
8377
  // NOTE: "Fee Options" represent the multiple ways we could pay for the gas
8396
8378
  // used in this transaction. Each fee option has a "recipientAddress" we
8397
8379
  // should transfer the payment to, an amount and a currency. We choose one
8398
8380
  // option and build a transaction that sends the expected currency amount for
8399
8381
  // that option to the specified address.
8400
- const feeOptions = await relayerClient.imGetFeeOptions(user.zkEvm.ethAddress, signedTransaction);
8382
+ const feeOptions = await relayerClient.imGetFeeOptions(walletAddress, signedTransaction);
8401
8383
  const imxFeeOption = feeOptions.find((feeOption) => feeOption.tokenSymbol === 'IMX');
8402
8384
  if (!imxFeeOption) {
8403
8385
  throw new Error('Failed to retrieve fees for IMX token');
@@ -8408,15 +8390,39 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
8408
8390
  value: imxFeeOption.tokenPrice,
8409
8391
  revertOnError: true,
8410
8392
  };
8393
+ if (BigNumber.from(feeMetaTransaction.value).isZero()) {
8394
+ return [metaTransaction];
8395
+ }
8396
+ return [metaTransaction, feeMetaTransaction];
8397
+ };
8398
+ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
8399
+ .withConfirmationScreen({ width: 480, height: 520 })(async () => {
8400
+ const transactionRequest = params[0];
8401
+ if (!transactionRequest.to) {
8402
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
8403
+ }
8404
+ const { chainId } = await jsonRpcProvider.ready;
8405
+ const chainIdBigNumber = BigNumber.from(chainId);
8406
+ const magicWeb3Provider = new Web3Provider(magicProvider);
8407
+ const signer = magicWeb3Provider.getSigner();
8408
+ const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
8409
+ const metaTransaction = {
8410
+ to: transactionRequest.to,
8411
+ data: transactionRequest.data,
8412
+ nonce,
8413
+ value: transactionRequest.value,
8414
+ revertOnError: true,
8415
+ };
8416
+ const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer, relayerClient);
8411
8417
  await guardianClient.validateEVMTransaction({
8412
8418
  chainId: getEip155ChainId(chainId),
8413
8419
  nonce: convertBigNumberishToString(nonce),
8414
8420
  user,
8415
- metaTransactions: [metaTransaction, feeMetaTransaction],
8421
+ metaTransactions,
8416
8422
  });
8417
8423
  // NOTE: We sign again because we now are adding the fee transaction, so the
8418
8424
  // whole payload is different and needs a new signature.
8419
- const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8425
+ const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8420
8426
  const relayerId = await relayerClient.ethSendTransaction(user.zkEvm.ethAddress, signedTransactions);
8421
8427
  const retrieveRelayerTransaction = async () => {
8422
8428
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -8755,33 +8761,16 @@ class Passport {
8755
8761
  passportEventEmitter: this.passportEventEmitter,
8756
8762
  });
8757
8763
  }
8758
- async signIn(options) {
8759
- const { useCachedSession = false } = options || {};
8760
- let user = await this.authManager.loginSilent();
8761
- if (!user && !useCachedSession) {
8762
- user = await this.authManager.login();
8763
- }
8764
- if (!user) {
8765
- return null;
8766
- }
8767
- return user.profile;
8768
- }
8769
8764
  /**
8770
- * @deprecated The method connectImx(useCachedSession) should be used instead
8765
+ * @deprecated The method `login` with an argument of `{ useCachedSession: true }` should be used in conjunction with
8766
+ * `connectImx` instead.
8771
8767
  */
8772
8768
  async connectImxSilent() {
8773
8769
  return this.passportImxProviderFactory.getProviderSilent();
8774
8770
  }
8775
- async connectImx(options) {
8776
- const { useCachedSession = false } = options || {};
8777
- if (useCachedSession) {
8778
- return this.passportImxProviderFactory.getProviderSilent();
8779
- }
8771
+ async connectImx() {
8780
8772
  return this.passportImxProviderFactory.getProvider();
8781
8773
  }
8782
- async loginWithDeviceFlow() {
8783
- return this.authManager.loginWithDeviceFlow();
8784
- }
8785
8774
  async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
8786
8775
  return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
8787
8776
  }
@@ -8813,6 +8802,25 @@ class Passport {
8813
8802
  multiRollupApiClients: this.multiRollupApiClients,
8814
8803
  });
8815
8804
  }
8805
+ /**
8806
+ *
8807
+ * Initiates the authorisation flow.
8808
+ *
8809
+ * @param options.useCachedSession = false - If true, and no active session exists, then the user will not be
8810
+ * prompted to log in and the Promise will resolve with a null value.
8811
+ * @returns {Promise<UserProfile | null>} the user profile if the user is logged in, otherwise null
8812
+ */
8813
+ async login(options) {
8814
+ const { useCachedSession = false } = options || {};
8815
+ let user = await this.authManager.loginSilent();
8816
+ if (!user && !useCachedSession) {
8817
+ user = await this.authManager.login();
8818
+ }
8819
+ return user ? user.profile : null;
8820
+ }
8821
+ async loginWithDeviceFlow() {
8822
+ return this.authManager.loginWithDeviceFlow();
8823
+ }
8816
8824
  async loginCallback() {
8817
8825
  return this.authManager.loginCallback();
8818
8826
  }
@@ -936,10 +936,14 @@ declare enum Environment {
936
936
  }
937
937
  declare class ImmutableConfiguration {
938
938
  readonly environment: Environment;
939
+ readonly rateLimitingKey?: string;
939
940
  readonly apiKey?: string;
941
+ readonly clientAppId?: string;
940
942
  constructor(options: {
941
943
  environment: Environment;
944
+ rateLimitingKey?: string;
942
945
  apiKey?: string;
946
+ clientAppId?: string;
943
947
  });
944
948
  }
945
949
  interface ModuleConfiguration<T> {
package/dist/provider.js CHANGED
@@ -5,6 +5,7 @@ import { parseUnits } from '@ethersproject/units';
5
5
  import { BigNumber } from '@ethersproject/bignumber';
6
6
  import { ethers } from 'ethers';
7
7
  import detectEthereumProvider from '@metamask/detect-provider';
8
+ import 'axios';
8
9
 
9
10
  // used to sign message with L1 keys. Used for registration
10
11
  function serializeEthSignature(sig) {
@@ -307,6 +308,8 @@ async function getSignableRegistrationOnchain(etherKey, starkPublicKey, usersApi
307
308
  return {
308
309
  operator_signature: response.data.operator_signature,
309
310
  payload_hash: response.data.payload_hash,
311
+ readable_transaction: response.data.readable_transaction,
312
+ verification_signature: response.data.verification_signature,
310
313
  };
311
314
  }
312
315
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.28.1-alpha",
4
+ "version": "0.28.3",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
@@ -12,7 +12,7 @@
12
12
  "@ethersproject/abstract-signer": "^5.7.0",
13
13
  "@ethersproject/providers": "^5.7.2",
14
14
  "@ethersproject/wallet": "^5.7.0",
15
- "@imtbl/core-sdk": "^2.0.2",
15
+ "@imtbl/core-sdk": "^2.4.0",
16
16
  "@jest/globals": "^29.5.0",
17
17
  "@magic-ext/oidc": "^1.0.1",
18
18
  "@metamask/detect-provider": "^2.0.0",
package/dist/global.d.ts DELETED
@@ -1,42 +0,0 @@
1
- /* eslint-disable @typescript-eslint/naming-convention */
2
- import {
3
- ImtblConnectProps,
4
- ImtblWalletProps,
5
- ImtblSwapProps,
6
- ImtblBridgeProps,
7
- ImtblOnRampProps,
8
- // ImtblExampleProps,
9
- // ImtblBuyProps,
10
- // ImtblTransitionExampleProps,
11
- // ImtblInnerWidgetExampleProps,
12
- // ImtblOuterWidgetExampleProps,
13
- ImtblSaleProps,
14
- } from '@imtbl/checkout-widgets';
15
-
16
- declare global {
17
- interface Window {
18
- ImtblCheckoutWidgetConfig: any;
19
- }
20
- namespace JSX {
21
- interface IntrinsicElements {
22
- 'imtbl-connect': ImtblConnectProps;
23
- 'imtbl-wallet': ImtblWalletProps;
24
- 'imtbl-swap': ImtblSwapProps;
25
- 'imtbl-bridge': ImtblBridgeProps;
26
- 'imtbl-onramp': ImtblOnRampProps;
27
- // 'imtbl-buy': ImtblBuyProps;
28
- 'imtbl-sale': ImtblSaleProps;
29
- // 'imtbl-example': ImtblExampleProps;
30
- // 'imtbl-transition-example': ImtblTransitionExampleProps;
31
- // 'imtbl-inner-widget-example': ImtblInnerWidgetExampleProps;
32
- // 'imtbl-outer-widget-example': ImtblOuterWidgetExampleProps;
33
- }
34
- }
35
- interface ImmutableWebComponent {
36
- setProvider: Function;
37
- addPassportOption: Function;
38
- setAttribute: Function;
39
- }
40
- }
41
-
42
- export {};