@imtbl/sdk 1.7.3 → 1.8.0

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.
Files changed (36) hide show
  1. package/dist/blockchain_data.js +2 -2
  2. package/dist/browser/checkout/BridgeWidget-85db50d2.js +1 -0
  3. package/dist/browser/checkout/OnRampWidget-58400404.js +1 -0
  4. package/dist/browser/checkout/SaleWidget-549f0f75.js +2 -0
  5. package/dist/browser/checkout/SpendingCapHero-24fed6d2.js +1 -0
  6. package/dist/browser/checkout/SwapWidget-9eecba27.js +1 -0
  7. package/dist/browser/checkout/TopUpView-26964a9e.js +1 -0
  8. package/dist/browser/checkout/WalletWidget-7e6fed9c.js +1 -0
  9. package/dist/browser/checkout/auto-track-da38e5a8.js +1 -0
  10. package/dist/browser/checkout/balance-310539bb.js +1 -0
  11. package/dist/browser/checkout/index-392bc434.js +1 -0
  12. package/dist/browser/checkout/index-3d847e0c.js +1 -0
  13. package/dist/browser/checkout/index-4e77760b.js +773 -0
  14. package/dist/browser/checkout/index-8184ffea.js +1 -0
  15. package/dist/browser/checkout/index-919a5df1.js +1 -0
  16. package/dist/browser/checkout/index-e6159023.js +1 -0
  17. package/dist/browser/checkout/index-eb42cd09.js +106 -0
  18. package/dist/browser/checkout/index.umd-c2e32802.js +1 -0
  19. package/dist/browser/checkout/is-plan-event-enabled-80f76ce6.js +1 -0
  20. package/dist/browser/checkout/retry-355e44f2.js +1 -0
  21. package/dist/browser/checkout/sdk.js +4 -4
  22. package/dist/browser/checkout/useTransakEvents-c6a83ea5.js +2 -0
  23. package/dist/browser/checkout/widgets-esm.js +1 -0
  24. package/dist/browser/checkout/widgets.js +50 -51
  25. package/dist/checkout.d.ts +3 -1
  26. package/dist/checkout.js +65 -32
  27. package/dist/config.js +1 -1
  28. package/dist/index.browser.js +7 -7
  29. package/dist/index.browser.js.map +1 -1
  30. package/dist/index.cjs +224 -161
  31. package/dist/index.d.ts +3 -1
  32. package/dist/index.js +224 -161
  33. package/dist/orderbook.js +1 -1
  34. package/dist/passport.js +160 -130
  35. package/dist/x.js +2 -2
  36. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -152,7 +152,7 @@ const flattenProperties$1 = (properties) => {
152
152
  };
153
153
 
154
154
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
155
- const SDK_VERSION$1 = '1.7.3';
155
+ const SDK_VERSION$1 = '1.8.0';
156
156
  const getReferrer$1 = () => {
157
157
  if (isNode$1()) {
158
158
  return '';
@@ -11276,7 +11276,7 @@ class MultiRollupApiClients {
11276
11276
  }
11277
11277
 
11278
11278
  // eslint-disable-next-line @typescript-eslint/naming-convention
11279
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.3' };
11279
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.8.0' };
11280
11280
  const createConfig = ({ basePath, headers, }) => {
11281
11281
  if (!basePath.trim()) {
11282
11282
  throw Error('basePath can not be empty');
@@ -11348,7 +11348,7 @@ class APIError extends Error {
11348
11348
 
11349
11349
  /* eslint-disable implicit-arrow-linebreak */
11350
11350
  const defaultHeaders = {
11351
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.3',
11351
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.8.0',
11352
11352
  };
11353
11353
  /**
11354
11354
  * createAPIConfiguration to create a custom Configuration
@@ -11781,7 +11781,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11781
11781
  chainID,
11782
11782
  coreContractAddress,
11783
11783
  registrationContractAddress,
11784
- sdkVersion: 'ts-immutable-sdk-1.7.3',
11784
+ sdkVersion: 'ts-immutable-sdk-1.8.0',
11785
11785
  });
11786
11786
  /**
11787
11787
  * Sets `sdkVersion` at the time of build
@@ -16428,7 +16428,6 @@ const getAuthConfiguration = (config) => {
16428
16428
  end_session_endpoint: endSessionEndpoint,
16429
16429
  },
16430
16430
  mergeClaims: true,
16431
- loadUserInfo: true,
16432
16431
  scope: oidcConfiguration.scope,
16433
16432
  userStore,
16434
16433
  };
@@ -16469,7 +16468,10 @@ class AuthManager {
16469
16468
  this.logoutMode = config.oidcConfiguration.logoutMode || 'redirect';
16470
16469
  }
16471
16470
  static mapOidcUserToDomainModel = (oidcUser) => {
16472
- const passport = oidcUser.profile?.passport;
16471
+ let passport;
16472
+ if (oidcUser.id_token) {
16473
+ passport = jwt_decode(oidcUser.id_token)?.passport;
16474
+ }
16473
16475
  const user = {
16474
16476
  expired: oidcUser.expired,
16475
16477
  idToken: oidcUser.id_token,
@@ -17894,27 +17896,28 @@ class JsonRpcError extends Error {
17894
17896
  }
17895
17897
 
17896
17898
  const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
17897
- async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
17898
- const web3Provider = new Web3Provider(magicProvider);
17899
- const ethSigner = web3Provider.getSigner();
17900
- const ethereumAddress = await ethSigner.getAddress();
17901
- const ethereumSignature = await signRaw(MESSAGE_TO_SIGN, ethSigner);
17902
- const headers = { Authorization: `Bearer ${accessToken}` };
17903
- const { chainId } = await jsonRpcProvider.ready;
17904
- const eipChainId = getEip155ChainId(chainId);
17899
+ async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
17900
+ const [ethereumAddress, ethereumSignature, network, chainListResponse] = await Promise.all([
17901
+ ethSigner.getAddress(),
17902
+ signRaw(MESSAGE_TO_SIGN, ethSigner),
17903
+ jsonRpcProvider.ready,
17904
+ multiRollupApiClients.chainsApi.listChains(),
17905
+ ]);
17906
+ const eipChainId = getEip155ChainId(network.chainId);
17907
+ const chainName = chainListResponse.data?.result?.find((chain) => chain.id === eipChainId)?.name;
17908
+ if (!chainName) {
17909
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Chain name does not exist on for chain id ${network.chainId}`);
17910
+ }
17905
17911
  try {
17906
- const chainList = (await multiRollupApiClients.chainsApi.listChains()).data.result;
17907
- const chainName = chainList.find((chain) => chain.id === eipChainId)?.name;
17908
- if (!chainName) {
17909
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Chain name does not exist on for chain id ${chainId}`);
17910
- }
17911
17912
  await multiRollupApiClients.passportApi.createCounterfactualAddressV2({
17912
17913
  chainName,
17913
17914
  createCounterfactualAddressRequest: {
17914
17915
  ethereum_address: ethereumAddress,
17915
17916
  ethereum_signature: ethereumSignature,
17916
17917
  },
17917
- }, { headers });
17918
+ }, {
17919
+ headers: { Authorization: `Bearer ${accessToken}` },
17920
+ });
17918
17921
  }
17919
17922
  catch (error) {
17920
17923
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Failed to create counterfactual address: ${error}`);
@@ -17926,32 +17929,6 @@ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiCli
17926
17929
  return user;
17927
17930
  }
17928
17931
 
17929
- const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
17930
- const user = await authManager.getUserOrLogin();
17931
- if (!user.idToken) {
17932
- throw new Error('User is missing idToken');
17933
- }
17934
- const magicProvider = await magicAdapter.login(user.idToken);
17935
- if (!user.zkEvm) {
17936
- // Generate counterfactual address and retrieve updated Auth0 user
17937
- const userZkevm = await registerZkEvmUser({
17938
- authManager,
17939
- magicProvider,
17940
- multiRollupApiClients,
17941
- accessToken: user.accessToken,
17942
- jsonRpcProvider,
17943
- });
17944
- return {
17945
- user: userZkevm,
17946
- magicProvider,
17947
- };
17948
- }
17949
- return {
17950
- user: user,
17951
- magicProvider,
17952
- };
17953
- };
17954
-
17955
17932
  const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
17956
17933
  + ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
17957
17934
  const convertBigNumberishToString = (value) => BigNumber$1.from(value).toString();
@@ -18147,7 +18124,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
18147
18124
  }
18148
18125
  return [metaTransaction, feeMetaTransaction];
18149
18126
  };
18150
- const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
18127
+ const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
18151
18128
  .withConfirmationScreen({ width: 480, height: 720 })(async () => {
18152
18129
  const transactionRequest = params[0];
18153
18130
  if (!transactionRequest.to) {
@@ -18155,8 +18132,6 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
18155
18132
  }
18156
18133
  const { chainId } = await jsonRpcProvider.ready;
18157
18134
  const chainIdBigNumber = BigNumber$1.from(chainId);
18158
- const magicWeb3Provider = new Web3Provider(magicProvider);
18159
- const signer = magicWeb3Provider.getSigner();
18160
18135
  const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
18161
18136
  const metaTransaction = {
18162
18137
  to: transactionRequest.to,
@@ -18165,15 +18140,18 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
18165
18140
  value: transactionRequest.value,
18166
18141
  revertOnError: true,
18167
18142
  };
18168
- const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, signer, relayerClient);
18169
- await guardianClient.validateEVMTransaction({
18170
- chainId: getEip155ChainId(chainId),
18171
- nonce: convertBigNumberishToString(nonce),
18172
- metaTransactions,
18173
- });
18174
- // NOTE: We sign again because we now are adding the fee transaction, so the
18175
- // whole payload is different and needs a new signature.
18176
- const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, signer);
18143
+ const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, ethSigner, relayerClient);
18144
+ // Parallelize the validation and signing of the transaction
18145
+ const [, signedTransactions] = await Promise.all([
18146
+ guardianClient.validateEVMTransaction({
18147
+ chainId: getEip155ChainId(chainId),
18148
+ nonce: convertBigNumberishToString(nonce),
18149
+ metaTransactions,
18150
+ }),
18151
+ // NOTE: We sign again because we now are adding the fee transaction, so the
18152
+ // whole payload is different and needs a new signature.
18153
+ getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner),
18154
+ ]);
18177
18155
  const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
18178
18156
  const retrieveRelayerTransaction = async () => {
18179
18157
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -18242,7 +18220,7 @@ const transformTypedData = (typedData, chainId) => {
18242
18220
  }
18243
18221
  return transformedTypedData;
18244
18222
  };
18245
- const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
18223
+ const signTypedDataV4 = async ({ params, method, ethSigner, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
18246
18224
  .withConfirmationScreen({ width: 480, height: 720 })(async () => {
18247
18225
  const fromAddress = params[0];
18248
18226
  const typedDataParam = params[1];
@@ -18253,106 +18231,158 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
18253
18231
  const typedData = transformTypedData(typedDataParam, chainId);
18254
18232
  await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
18255
18233
  const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
18256
- const magicWeb3Provider = new Web3Provider(magicProvider);
18257
- const signer = magicWeb3Provider.getSigner();
18258
- return getSignedTypedData(typedData, relayerSignature, BigNumber$1.from(chainId), fromAddress, signer);
18234
+ return getSignedTypedData(typedData, relayerSignature, BigNumber$1.from(chainId), fromAddress, ethSigner);
18259
18235
  });
18260
18236
 
18237
+ const isZkEvmUser = (user) => 'zkEvm' in user;
18261
18238
  class ZkEvmProvider {
18262
- authManager;
18263
- config;
18264
- magicAdapter;
18265
- multiRollupApiClients;
18266
- jsonRpcProvider; // Used for read
18267
- eventEmitter;
18268
- guardianClient;
18269
- relayerClient;
18270
- magicProvider; // Used for signing
18271
- zkevmAddress;
18239
+ #authManager;
18240
+ #config;
18241
+ #eventEmitter;
18242
+ #guardianClient;
18243
+ #jsonRpcProvider; // Used for read
18244
+ #magicAdapter;
18245
+ #multiRollupApiClients;
18246
+ #relayerClient;
18247
+ /**
18248
+ * This property is set during `#initialiseEthSigner` and stores the signer in a promise.
18249
+ * This property is not meant to be accessed directly, but through the
18250
+ * `#getSigner` method.
18251
+ * @see getSigner
18252
+ */
18253
+ #ethSigner;
18254
+ #signerInitialisationError;
18255
+ #zkEvmAddress;
18272
18256
  isPassport = true;
18273
18257
  constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
18274
- this.authManager = authManager;
18275
- this.magicAdapter = magicAdapter;
18276
- this.config = config;
18277
- this.guardianClient = guardianClient;
18258
+ this.#authManager = authManager;
18259
+ this.#magicAdapter = magicAdapter;
18260
+ this.#config = config;
18261
+ this.#guardianClient = guardianClient;
18278
18262
  if (config.crossSdkBridgeEnabled) {
18279
18263
  // JsonRpcProvider by default sets the referrer as "client".
18280
18264
  // On Unreal 4 this errors as the browser used is expecting a valid URL.
18281
- this.jsonRpcProvider = new JsonRpcProvider({
18282
- url: this.config.zkEvmRpcUrl,
18265
+ this.#jsonRpcProvider = new JsonRpcProvider({
18266
+ url: this.#config.zkEvmRpcUrl,
18283
18267
  fetchOptions: { referrer: 'http://imtblgamesdk.local' },
18284
18268
  });
18285
18269
  }
18286
18270
  else {
18287
- this.jsonRpcProvider = new JsonRpcProvider(this.config.zkEvmRpcUrl);
18271
+ this.#jsonRpcProvider = new JsonRpcProvider(this.#config.zkEvmRpcUrl);
18288
18272
  }
18289
- this.multiRollupApiClients = multiRollupApiClients;
18290
- this.eventEmitter = new TypedEventEmitter();
18291
- passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
18292
- }
18293
- handleLogout = () => {
18294
- const shouldEmitAccountsChanged = this.isLoggedIn();
18295
- this.magicProvider = undefined;
18296
- this.relayerClient = undefined;
18273
+ this.#relayerClient = new RelayerClient({
18274
+ config: this.#config,
18275
+ jsonRpcProvider: this.#jsonRpcProvider,
18276
+ authManager: this.#authManager,
18277
+ });
18278
+ this.#multiRollupApiClients = multiRollupApiClients;
18279
+ this.#eventEmitter = new TypedEventEmitter();
18280
+ passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
18281
+ }
18282
+ #handleLogout = () => {
18283
+ const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
18284
+ this.#ethSigner = undefined;
18285
+ this.#zkEvmAddress = undefined;
18297
18286
  if (shouldEmitAccountsChanged) {
18298
- this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
18287
+ this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
18299
18288
  }
18300
18289
  };
18301
- isLoggedIn() {
18302
- return this.magicProvider !== undefined
18303
- && this.zkevmAddress !== undefined
18304
- && this.relayerClient !== undefined;
18290
+ /**
18291
+ * This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
18292
+ * The signer is stored in a promise so that it can be retrieved by the provider
18293
+ * when needed.
18294
+ *
18295
+ * If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
18296
+ * so that it doesn't result in an unhandled promise rejection.
18297
+ *
18298
+ * This error is thrown when the signer is requested through:
18299
+ * @see #getSigner
18300
+ *
18301
+ */
18302
+ async #initialiseEthSigner(user) {
18303
+ const generateSigner = async () => {
18304
+ const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
18305
+ const web3Provider = new Web3Provider(magicRpcProvider);
18306
+ return web3Provider.getSigner();
18307
+ };
18308
+ // eslint-disable-next-line no-async-promise-executor
18309
+ this.#ethSigner = new Promise(async (resolve) => {
18310
+ try {
18311
+ resolve(await generateSigner());
18312
+ }
18313
+ catch (err) {
18314
+ // Capture and store the initialization error
18315
+ this.#signerInitialisationError = err;
18316
+ resolve(undefined);
18317
+ }
18318
+ });
18305
18319
  }
18306
- async performRequest(request) {
18320
+ async #getSigner() {
18321
+ const ethSigner = await this.#ethSigner;
18322
+ // Throw the stored error if the signers failed to initialise
18323
+ if (typeof ethSigner === 'undefined') {
18324
+ if (typeof this.#signerInitialisationError !== 'undefined') {
18325
+ throw this.#signerInitialisationError;
18326
+ }
18327
+ throw new Error('Signer failed to initialise');
18328
+ }
18329
+ return ethSigner;
18330
+ }
18331
+ async #performRequest(request) {
18307
18332
  switch (request.method) {
18308
18333
  case 'eth_requestAccounts': {
18309
- if (this.isLoggedIn()) {
18310
- return [this.zkevmAddress];
18334
+ if (this.#zkEvmAddress) {
18335
+ return [this.#zkEvmAddress];
18311
18336
  }
18312
- const { magicProvider, user } = await loginZkEvmUser({
18313
- authManager: this.authManager,
18314
- magicAdapter: this.magicAdapter,
18315
- multiRollupApiClients: this.multiRollupApiClients,
18316
- jsonRpcProvider: this.jsonRpcProvider,
18317
- });
18318
- this.magicProvider = magicProvider;
18319
- this.relayerClient = new RelayerClient({
18320
- config: this.config,
18321
- jsonRpcProvider: this.jsonRpcProvider,
18322
- authManager: this.authManager,
18323
- });
18324
- this.zkevmAddress = user.zkEvm.ethAddress;
18325
- this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [user.zkEvm.ethAddress]);
18326
- return [user.zkEvm.ethAddress];
18337
+ const user = await this.#authManager.getUserOrLogin();
18338
+ this.#initialiseEthSigner(user);
18339
+ if (!isZkEvmUser(user)) {
18340
+ const ethSigner = await this.#getSigner();
18341
+ const userZkEvm = await registerZkEvmUser({
18342
+ ethSigner,
18343
+ authManager: this.#authManager,
18344
+ multiRollupApiClients: this.#multiRollupApiClients,
18345
+ accessToken: user.accessToken,
18346
+ jsonRpcProvider: this.#jsonRpcProvider,
18347
+ });
18348
+ this.#zkEvmAddress = userZkEvm.zkEvm.ethAddress;
18349
+ }
18350
+ else {
18351
+ this.#zkEvmAddress = user.zkEvm.ethAddress;
18352
+ }
18353
+ this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.#zkEvmAddress]);
18354
+ return [this.#zkEvmAddress];
18327
18355
  }
18328
18356
  case 'eth_sendTransaction': {
18329
- if (!this.isLoggedIn()) {
18357
+ if (!this.#zkEvmAddress) {
18330
18358
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
18331
18359
  }
18360
+ const ethSigner = await this.#getSigner();
18332
18361
  return sendTransaction$1({
18333
18362
  params: request.params || [],
18334
- magicProvider: this.magicProvider,
18335
- guardianClient: this.guardianClient,
18336
- jsonRpcProvider: this.jsonRpcProvider,
18337
- relayerClient: this.relayerClient,
18338
- zkevmAddress: this.zkevmAddress,
18363
+ ethSigner,
18364
+ guardianClient: this.#guardianClient,
18365
+ jsonRpcProvider: this.#jsonRpcProvider,
18366
+ relayerClient: this.#relayerClient,
18367
+ zkevmAddress: this.#zkEvmAddress,
18339
18368
  });
18340
18369
  }
18341
18370
  case 'eth_accounts': {
18342
- return this.zkevmAddress ? [this.zkevmAddress] : [];
18371
+ return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
18343
18372
  }
18344
18373
  case 'eth_signTypedData':
18345
18374
  case 'eth_signTypedData_v4': {
18346
- if (!this.isLoggedIn()) {
18375
+ if (!this.#zkEvmAddress) {
18347
18376
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
18348
18377
  }
18378
+ const ethSigner = await this.#getSigner();
18349
18379
  return signTypedDataV4({
18350
18380
  method: request.method,
18351
18381
  params: request.params || [],
18352
- magicProvider: this.magicProvider,
18353
- jsonRpcProvider: this.jsonRpcProvider,
18354
- relayerClient: this.relayerClient,
18355
- guardianClient: this.guardianClient,
18382
+ ethSigner,
18383
+ jsonRpcProvider: this.#jsonRpcProvider,
18384
+ relayerClient: this.#relayerClient,
18385
+ guardianClient: this.#guardianClient,
18356
18386
  });
18357
18387
  }
18358
18388
  // Pass through methods
@@ -18369,17 +18399,17 @@ class ZkEvmProvider {
18369
18399
  case 'eth_getTransactionByHash':
18370
18400
  case 'eth_getTransactionReceipt':
18371
18401
  case 'eth_getTransactionCount': {
18372
- return this.jsonRpcProvider.send(request.method, request.params || []);
18402
+ return this.#jsonRpcProvider.send(request.method, request.params || []);
18373
18403
  }
18374
18404
  default: {
18375
18405
  throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');
18376
18406
  }
18377
18407
  }
18378
18408
  }
18379
- async performJsonRpcRequest(request) {
18409
+ async #performJsonRpcRequest(request) {
18380
18410
  const { id, jsonrpc } = request;
18381
18411
  try {
18382
- const result = await this.performRequest(request);
18412
+ const result = await this.#performRequest(request);
18383
18413
  return {
18384
18414
  id,
18385
18415
  jsonrpc,
@@ -18406,7 +18436,7 @@ class ZkEvmProvider {
18406
18436
  }
18407
18437
  async request(request) {
18408
18438
  try {
18409
- return this.performRequest(request);
18439
+ return this.#performRequest(request);
18410
18440
  }
18411
18441
  catch (error) {
18412
18442
  if (error instanceof JsonRpcError) {
@@ -18423,14 +18453,14 @@ class ZkEvmProvider {
18423
18453
  throw new Error('No callback provided');
18424
18454
  }
18425
18455
  if (Array.isArray(request)) {
18426
- Promise.all(request.map(this.performJsonRpcRequest)).then((result) => {
18456
+ Promise.all(request.map(this.#performJsonRpcRequest)).then((result) => {
18427
18457
  callback(null, result);
18428
18458
  }).catch((error) => {
18429
18459
  callback(error, []);
18430
18460
  });
18431
18461
  }
18432
18462
  else {
18433
- this.performJsonRpcRequest(request).then((result) => {
18463
+ this.#performJsonRpcRequest(request).then((result) => {
18434
18464
  callback(null, result);
18435
18465
  }).catch((error) => {
18436
18466
  callback(error, null);
@@ -18462,15 +18492,15 @@ class ZkEvmProvider {
18462
18492
  return this.sendAsync(request, callbackOrParams);
18463
18493
  }
18464
18494
  if (!Array.isArray(request) && typeof request === 'object') {
18465
- return this.performJsonRpcRequest(request);
18495
+ return this.#performJsonRpcRequest(request);
18466
18496
  }
18467
18497
  throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
18468
18498
  }
18469
18499
  on(event, listener) {
18470
- this.eventEmitter.on(event, listener);
18500
+ this.#eventEmitter.on(event, listener);
18471
18501
  }
18472
18502
  removeListener(event, listener) {
18473
- this.eventEmitter.removeListener(event, listener);
18503
+ this.#eventEmitter.removeListener(event, listener);
18474
18504
  }
18475
18505
  }
18476
18506
 
@@ -37432,7 +37462,7 @@ const flattenProperties = (properties) => {
37432
37462
  };
37433
37463
 
37434
37464
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
37435
- const SDK_VERSION = '1.7.3';
37465
+ const SDK_VERSION = '1.8.0';
37436
37466
  const getReferrer = () => {
37437
37467
  if (isNode()) {
37438
37468
  return '';
@@ -42600,7 +42630,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
42600
42630
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
42601
42631
  };
42602
42632
 
42603
- const SDK_VERSION_MARKER = '1.7.3';
42633
+ const SDK_VERSION_MARKER = '1.8.0';
42604
42634
  // This SDK version is replaced by the `yarn build` command ran on the root level
42605
42635
  const globalPackageVersion = () => SDK_VERSION_MARKER;
42606
42636
 
@@ -46220,27 +46250,25 @@ function validateAndBuildVersion(version) {
46220
46250
  return validatedVersion;
46221
46251
  }
46222
46252
 
46223
- function loadUnresolved(version) {
46253
+ // Loads the checkout widgets bundle from the CDN and appends the script to the document head
46254
+ function loadUnresolvedBundle(tag, scriptId, validVersion) {
46224
46255
  if (window === undefined) {
46225
46256
  throw new Error('missing window object: please run Checkout client side');
46226
46257
  }
46227
46258
  if (document === undefined) {
46228
46259
  throw new Error('missing document object: please run Checkout client side');
46229
46260
  }
46230
- const scriptId = 'immutable-checkout-widgets-bundle';
46231
- const validVersion = validateAndBuildVersion(version);
46232
- // Prevent the script to be loaded more than once
46233
- // by checking the presence of the script and its version.
46234
- const initScript = document.getElementById(scriptId);
46235
- if (initScript)
46236
- return { loaded: true, element: initScript };
46237
- const tag = document.createElement('script');
46238
46261
  let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets.js`;
46239
46262
  tag.setAttribute('id', scriptId);
46240
46263
  tag.setAttribute('data-version', validVersion);
46241
46264
  tag.setAttribute('src', cdnUrl);
46242
46265
  document.head.appendChild(tag);
46243
- return { loaded: false, element: tag };
46266
+ }
46267
+ // Gets the CDN url for the split checkout widgets bundle
46268
+ function getWidgetsEsmUrl(version) {
46269
+ const validVersion = validateAndBuildVersion(version);
46270
+ let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets-esm.js`;
46271
+ return cdnUrl;
46244
46272
  }
46245
46273
 
46246
46274
  const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
@@ -46319,7 +46347,6 @@ const SANDBOX_CONFIGURATION = {
46319
46347
  },
46320
46348
  passport: undefined,
46321
46349
  };
46322
- const WIDGETS_SCRIPT_TIMEOUT = 100;
46323
46350
  // Checkout SDK
46324
46351
  class Checkout {
46325
46352
  readOnlyProviders;
@@ -46349,26 +46376,44 @@ class Checkout {
46349
46376
  const checkout = this;
46350
46377
  // Preload the configurations
46351
46378
  await checkout.config.remote.getConfig();
46379
+ try {
46380
+ const factory = await this.loadEsModules(init.config, init.version);
46381
+ return factory;
46382
+ }
46383
+ catch (err) {
46384
+ throw new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err });
46385
+ }
46386
+ }
46387
+ async loadUmdBundle(config, version) {
46388
+ const checkout = this;
46352
46389
  const factory = new Promise((resolve, reject) => {
46353
- function checkForWidgetsBundleLoaded() {
46354
- if (typeof ImmutableCheckoutWidgets !== 'undefined') {
46355
- resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
46356
- }
46357
- else {
46358
- // If ImmutableCheckoutWidgets is not defined, wait for set amount of time.
46359
- // When time has elapsed, check again if ImmutableCheckoutWidgets is defined.
46360
- // Once it's defined, the promise will resolve and setTimeout won't be called again.
46361
- setTimeout(checkForWidgetsBundleLoaded, WIDGETS_SCRIPT_TIMEOUT);
46362
- }
46363
- }
46364
46390
  try {
46365
- const script = loadUnresolved(init.version);
46366
- if (script.loaded && typeof ImmutableCheckoutWidgets !== 'undefined') {
46367
- resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
46368
- }
46369
- else {
46370
- checkForWidgetsBundleLoaded();
46391
+ const scriptId = 'immutable-checkout-widgets-bundle';
46392
+ const validVersion = validateAndBuildVersion(version);
46393
+ // Prevent the script to be loaded more than once
46394
+ // by checking the presence of the script and its version.
46395
+ const initScript = document.getElementById(scriptId);
46396
+ if (initScript) {
46397
+ if (typeof ImmutableCheckoutWidgets !== 'undefined') {
46398
+ resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
46399
+ }
46400
+ else {
46401
+ reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
46402
+ }
46371
46403
  }
46404
+ const tag = document.createElement('script');
46405
+ tag.addEventListener('load', () => {
46406
+ if (typeof ImmutableCheckoutWidgets !== 'undefined') {
46407
+ resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
46408
+ }
46409
+ else {
46410
+ reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
46411
+ }
46412
+ });
46413
+ tag.addEventListener('error', (err) => {
46414
+ reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
46415
+ });
46416
+ loadUnresolvedBundle(tag, scriptId, validVersion);
46372
46417
  }
46373
46418
  catch (err) {
46374
46419
  reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
@@ -46376,6 +46421,24 @@ class Checkout {
46376
46421
  });
46377
46422
  return factory;
46378
46423
  }
46424
+ async loadEsModules(config, version) {
46425
+ const checkout = this;
46426
+ try {
46427
+ const cdnUrl = getWidgetsEsmUrl(version);
46428
+ // WebpackIgnore comment required to prevent webpack modifying the import statement and
46429
+ // breaking the dynamic import in certain applications integrating checkout
46430
+ const checkoutWidgetsModule = await import(/* webpackIgnore: true */ cdnUrl);
46431
+ if (checkoutWidgetsModule && checkoutWidgetsModule.WidgetsFactory) {
46432
+ return new checkoutWidgetsModule.WidgetsFactory(checkout, config);
46433
+ }
46434
+ }
46435
+ catch (err) {
46436
+ // eslint-disable-next-line no-console
46437
+ console.warn(`Failed to resolve checkout widgets module, falling back to UMD bundle. Error: ${err.message}`);
46438
+ }
46439
+ // Fallback to UMD bundle if esm bundle fails to load
46440
+ return await checkout.loadUmdBundle(config, version);
46441
+ }
46379
46442
  /**
46380
46443
  * Creates a provider using the given parameters.
46381
46444
  * @param {CreateProviderParams} params - The parameters for creating the provider.
package/dist/orderbook.js CHANGED
@@ -131,7 +131,7 @@ const flattenProperties = (properties) => {
131
131
  };
132
132
 
133
133
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
134
- const SDK_VERSION = '1.7.3';
134
+ const SDK_VERSION = '1.8.0';
135
135
  const getReferrer = () => {
136
136
  if (isNode()) {
137
137
  return '';