@imtbl/sdk 0.28.3-alpha.1 → 0.28.4

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.3-alpha.1' };
2075
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.28.4' };
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.3-alpha.1',
2131
+ sdkVersion: 'ts-immutable-sdk-0.28.4',
2132
2132
  });
2133
2133
  /**
2134
2134
  * Sets `sdkVersion` at the time of build
@@ -2144,9 +2144,9 @@ const production = () => createImmutableXConfiguration({
2144
2144
  */
2145
2145
  const sandbox = () => createImmutableXConfiguration({
2146
2146
  basePath: 'https://api.sandbox.x.immutable.com',
2147
- chainID: 5,
2148
- coreContractAddress: '0x7917eDb51ecD6CdB3F9854c3cc593F33de10c623',
2149
- registrationContractAddress: '0x1C97Ada273C9A52253f463042f29117090Cd7D83',
2147
+ chainID: 11155111,
2148
+ coreContractAddress: '0x2d5C349fD8464DA06a3f90b4B0E9195F3d1b7F98',
2149
+ registrationContractAddress: '0xDbA6129C02E69405622fAdc3d5A7f8d23eac3b97',
2150
2150
  });
2151
2151
  class ImxConfiguration {
2152
2152
  immutableXConfig;
@@ -7061,7 +7061,7 @@ class MagicAdapter {
7061
7061
  magicClient;
7062
7062
  constructor(config) {
7063
7063
  this.config = config;
7064
- if (window) {
7064
+ if (typeof window !== 'undefined') {
7065
7065
  this.magicClient = this.initMagicClient();
7066
7066
  this.magicClient.preload();
7067
7067
  }
@@ -7297,7 +7297,7 @@ class GuardianClient {
7297
7297
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
7298
7298
  }
7299
7299
  if (confirmationRequired && !!messageId) {
7300
- const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId);
7300
+ const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
7301
7301
  if (!confirmationResult.confirmed) {
7302
7302
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
7303
7303
  }
@@ -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,
@@ -7758,7 +7757,7 @@ class PassportImxProviderFactory {
7758
7757
  this.passportEventEmitter = passportEventEmitter;
7759
7758
  }
7760
7759
  async getProvider() {
7761
- const user = await this.authManager.login();
7760
+ const user = await this.authManager.loginSilent() || await this.authManager.login();
7762
7761
  return this.createProviderInstance(user);
7763
7762
  }
7764
7763
  async getProviderSilent() {
@@ -7972,7 +7971,19 @@ class ConfirmationScreen {
7972
7971
  constructor(config) {
7973
7972
  this.config = config;
7974
7973
  }
7975
- requestConfirmation(transactionId, imxEtherAddress, chainType, chainId) {
7974
+ getHref(relativePath, queryStringParams) {
7975
+ let href = `${this.config.passportDomain}/transaction-confirmation/${relativePath}`;
7976
+ if (queryStringParams) {
7977
+ const queryString = queryStringParams
7978
+ ? Object.keys(queryStringParams)
7979
+ .map((key) => `${key}=${queryStringParams[key]}`)
7980
+ .join('&')
7981
+ : '';
7982
+ href = `${href}?${queryString}`;
7983
+ }
7984
+ return href;
7985
+ }
7986
+ requestConfirmation(transactionId, etherAddress, chainType, chainId) {
7976
7987
  return new Promise((resolve, reject) => {
7977
7988
  const messageHandler = ({ data, origin }) => {
7978
7989
  if (origin !== this.config.passportDomain
@@ -8002,17 +8013,17 @@ class ConfirmationScreen {
8002
8013
  window.addEventListener('message', messageHandler);
8003
8014
  let href = '';
8004
8015
  if (chainType === TransactionApprovalRequestChainTypeEnum.Starkex) {
8005
- // eslint-disable-next-line max-len
8006
- href = `${this.config.passportDomain}/transaction-confirmation/transaction?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
8016
+ href = this.getHref('transaction', { transactionId, etherAddress, chainType });
8007
8017
  }
8008
8018
  else {
8009
- // eslint-disable-next-line max-len
8010
- href = `${this.config.passportDomain}/transaction-confirmation/zkevm?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=evm&chainId=${chainId}`;
8019
+ href = this.getHref('zkevm', {
8020
+ transactionId, etherAddress, chainType, chainId,
8021
+ });
8011
8022
  }
8012
8023
  this.showConfirmationScreen(href, messageHandler, resolve);
8013
8024
  });
8014
8025
  }
8015
- requestMessageConfirmation(messageId) {
8026
+ requestMessageConfirmation(messageID, etherAddress) {
8016
8027
  return new Promise((resolve, reject) => {
8017
8028
  const messageHandler = ({ data, origin }) => {
8018
8029
  if (origin !== this.config.passportDomain
@@ -8040,7 +8051,7 @@ class ConfirmationScreen {
8040
8051
  return;
8041
8052
  }
8042
8053
  window.addEventListener('message', messageHandler);
8043
- const href = `${this.config.passportDomain}/transaction-confirmation/zkevm/message?messageID=${messageId}`;
8054
+ const href = this.getHref('zkevm/message', { messageID, etherAddress });
8044
8055
  this.showConfirmationScreen(href, messageHandler, resolve);
8045
8056
  });
8046
8057
  }
@@ -8050,7 +8061,7 @@ class ConfirmationScreen {
8050
8061
  return;
8051
8062
  }
8052
8063
  this.confirmationWindow = openPopupCenter({
8053
- url: `${this.config.passportDomain}/transaction-confirmation/loading`,
8064
+ url: this.getHref('loading'),
8054
8065
  title: CONFIRMATION_WINDOW_TITLE,
8055
8066
  width: popupOptions?.width || CONFIRMATION_WINDOW_WIDTH,
8056
8067
  height: popupOptions?.height || CONFIRMATION_WINDOW_HEIGHT,
@@ -8063,7 +8074,7 @@ class ConfirmationScreen {
8063
8074
  return new Promise((resolve, rejects) => {
8064
8075
  const iframe = document.createElement('iframe');
8065
8076
  iframe.setAttribute('id', CONFIRMATION_IFRAME_ID);
8066
- iframe.setAttribute('src', `${this.config.passportDomain}/transaction-confirmation/logout`);
8077
+ iframe.setAttribute('src', this.getHref('logout'));
8067
8078
  iframe.setAttribute('style', CONFIRMATION_IFRAME_STYLE);
8068
8079
  const logoutHandler = ({ data, origin }) => {
8069
8080
  if (origin !== this.config.passportDomain
@@ -8356,36 +8367,19 @@ const loginZkEvmUser = async ({ authManager, config, magicAdapter, multiRollupAp
8356
8367
 
8357
8368
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
8358
8369
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
8359
- const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
8360
- .withConfirmationScreen({ width: 480, height: 520 })(async () => {
8361
- const transactionRequest = params[0];
8362
- if (!transactionRequest.to) {
8363
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
8364
- }
8365
- const { chainId } = await jsonRpcProvider.ready;
8366
- const chainIdBigNumber = BigNumber.from(chainId);
8367
- const magicWeb3Provider = new Web3Provider(magicProvider);
8368
- const signer = magicWeb3Provider.getSigner();
8369
- const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
8370
- const metaTransaction = {
8371
- to: transactionRequest.to,
8372
- data: transactionRequest.data,
8373
- nonce,
8374
- value: transactionRequest.value,
8375
- revertOnError: true,
8376
- };
8370
+ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddress, signer, relayerClient) => {
8377
8371
  // NOTE: We sign the transaction before getting the fee options because
8378
8372
  // accurate estimation of a transaction gas cost is only possible if the smart
8379
8373
  // wallet contract can actually execute it (in a simulated environment) - and
8380
8374
  // it can only execute signed transactions.
8381
- const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8375
+ const signedTransaction = await getSignedMetaTransactions([metaTransaction], nonce, chainId, walletAddress, signer);
8382
8376
  // TODO: ID-698 Add support for non-native gas payments (e.g ERC20, feeTransaction initialisation must change)
8383
8377
  // NOTE: "Fee Options" represent the multiple ways we could pay for the gas
8384
8378
  // used in this transaction. Each fee option has a "recipientAddress" we
8385
8379
  // should transfer the payment to, an amount and a currency. We choose one
8386
8380
  // option and build a transaction that sends the expected currency amount for
8387
8381
  // that option to the specified address.
8388
- const feeOptions = await relayerClient.imGetFeeOptions(user.zkEvm.ethAddress, signedTransaction);
8382
+ const feeOptions = await relayerClient.imGetFeeOptions(walletAddress, signedTransaction);
8389
8383
  const imxFeeOption = feeOptions.find((feeOption) => feeOption.tokenSymbol === 'IMX');
8390
8384
  if (!imxFeeOption) {
8391
8385
  throw new Error('Failed to retrieve fees for IMX token');
@@ -8396,15 +8390,39 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
8396
8390
  value: imxFeeOption.tokenPrice,
8397
8391
  revertOnError: true,
8398
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);
8399
8417
  await guardianClient.validateEVMTransaction({
8400
8418
  chainId: getEip155ChainId(chainId),
8401
8419
  nonce: convertBigNumberishToString(nonce),
8402
8420
  user,
8403
- metaTransactions: [metaTransaction, feeMetaTransaction],
8421
+ metaTransactions,
8404
8422
  });
8405
8423
  // NOTE: We sign again because we now are adding the fee transaction, so the
8406
8424
  // whole payload is different and needs a new signature.
8407
- const signedTransactions = await getSignedMetaTransactions([metaTransaction, feeMetaTransaction], nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8425
+ const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
8408
8426
  const relayerId = await relayerClient.ethSendTransaction(user.zkEvm.ethAddress, signedTransactions);
8409
8427
  const retrieveRelayerTransaction = async () => {
8410
8428
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -8507,7 +8525,17 @@ class ZkEvmProvider {
8507
8525
  this.magicAdapter = magicAdapter;
8508
8526
  this.config = config;
8509
8527
  this.confirmationScreen = confirmationScreen;
8510
- this.jsonRpcProvider = new JsonRpcProvider(this.config.zkEvmRpcUrl);
8528
+ if (config.crossSdkBridgeEnabled) {
8529
+ // JsonRpcProvider by default sets the referrer as "client".
8530
+ // On Unreal 4 this errors as the browser used is expecting a valid URL.
8531
+ this.jsonRpcProvider = new JsonRpcProvider({
8532
+ url: this.config.zkEvmRpcUrl,
8533
+ fetchOptions: { referrer: 'http://imtblgamesdk.local' },
8534
+ });
8535
+ }
8536
+ else {
8537
+ this.jsonRpcProvider = new JsonRpcProvider(this.config.zkEvmRpcUrl);
8538
+ }
8511
8539
  this.multiRollupApiClients = multiRollupApiClients;
8512
8540
  this.eventEmitter = new TypedEventEmitter();
8513
8541
  passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
@@ -8733,15 +8761,16 @@ class Passport {
8733
8761
  passportEventEmitter: this.passportEventEmitter,
8734
8762
  });
8735
8763
  }
8764
+ /**
8765
+ * @deprecated The method `login` with an argument of `{ useCachedSession: true }` should be used in conjunction with
8766
+ * `connectImx` instead.
8767
+ */
8736
8768
  async connectImxSilent() {
8737
8769
  return this.passportImxProviderFactory.getProviderSilent();
8738
8770
  }
8739
8771
  async connectImx() {
8740
8772
  return this.passportImxProviderFactory.getProvider();
8741
8773
  }
8742
- async loginWithDeviceFlow() {
8743
- return this.authManager.loginWithDeviceFlow();
8744
- }
8745
8774
  async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
8746
8775
  return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
8747
8776
  }
@@ -8773,6 +8802,25 @@ class Passport {
8773
8802
  multiRollupApiClients: this.multiRollupApiClients,
8774
8803
  });
8775
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
+ }
8776
8824
  async loginCallback() {
8777
8825
  return this.authManager.loginCallback();
8778
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,21 +1,18 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.28.3-alpha.1",
4
+ "version": "0.28.4",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
8
8
  "dependencies": {
9
9
  "@0xsequence/abi": "^0.43.34",
10
10
  "@0xsequence/config": "^0.43.34",
11
- "@biom3/design-tokens": "0.2.4-beta",
12
- "@biom3/react": "^0.10.12",
13
11
  "@ethersproject/abi": "^5.7.0",
14
12
  "@ethersproject/abstract-signer": "^5.7.0",
15
13
  "@ethersproject/providers": "^5.7.2",
16
14
  "@ethersproject/wallet": "^5.7.0",
17
- "@imtbl/core-sdk": "^2.0.2",
18
- "@imtbl/react-analytics": "0.0.5-alpha",
15
+ "@imtbl/core-sdk": "^2.4.0",
19
16
  "@jest/globals": "^29.5.0",
20
17
  "@magic-ext/oidc": "^1.0.1",
21
18
  "@metamask/detect-provider": "^2.0.0",
@@ -23,25 +20,13 @@
23
20
  "@uniswap/router-sdk": "^1.4.0",
24
21
  "@uniswap/sdk-core": "^3.0.1",
25
22
  "@uniswap/v3-sdk": "^3.9.0",
26
- "assert": "^2.0.0",
27
23
  "axios": "^1.3.5",
28
24
  "bn.js": "^5.2.1",
29
- "buffer": "^6.0.3",
30
- "crypto-browserify": "^3.12.0",
31
25
  "enc-utils": "^3.0.0",
32
26
  "ethers": "^5.7.2",
33
- "https-browserify": "^1.0.0",
34
27
  "jwt-decode": "^3.1.2",
35
28
  "magic-sdk": "^13.3.1",
36
- "oidc-client-ts": "^2.2.1",
37
- "os-browserify": "^0.3.0",
38
- "pako": "^2.1.0",
39
- "react": "^18.2.0",
40
- "react-dom": "^18.2.0",
41
- "react-router-dom": "^6.11.0",
42
- "stream-browserify": "^3.0.0",
43
- "stream-http": "^3.2.0",
44
- "url": "^0.11.0"
29
+ "oidc-client-ts": "^2.2.1"
45
30
  },
46
31
  "devDependencies": {
47
32
  "@imtbl/blockchain-data": "0.0.0",
@@ -109,6 +94,10 @@
109
94
  "./checkout_sdk": {
110
95
  "types": "./dist/checkout_sdk.d.ts",
111
96
  "import": "./dist/checkout_sdk.js"
97
+ },
98
+ "./checkout_widgets": {
99
+ "types": "./dist/checkout_widgets.d.ts",
100
+ "import": "./dist/checkout_widgets.js"
112
101
  }
113
102
  },
114
103
  "files": [