@imtbl/sdk 1.7.3-alpha.1 → 1.7.3-alpha.2

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 (37) hide show
  1. package/dist/blockchain_data.d.ts +288 -449
  2. package/dist/blockchain_data.js +2 -149
  3. package/dist/browser/checkout/BridgeWidget-85db50d2.js +1 -0
  4. package/dist/browser/checkout/OnRampWidget-58400404.js +1 -0
  5. package/dist/browser/checkout/SaleWidget-549f0f75.js +2 -0
  6. package/dist/browser/checkout/SpendingCapHero-24fed6d2.js +1 -0
  7. package/dist/browser/checkout/SwapWidget-9eecba27.js +1 -0
  8. package/dist/browser/checkout/TopUpView-26964a9e.js +1 -0
  9. package/dist/browser/checkout/WalletWidget-7e6fed9c.js +1 -0
  10. package/dist/browser/checkout/auto-track-da38e5a8.js +1 -0
  11. package/dist/browser/checkout/balance-310539bb.js +1 -0
  12. package/dist/browser/checkout/index-392bc434.js +1 -0
  13. package/dist/browser/checkout/index-3d847e0c.js +1 -0
  14. package/dist/browser/checkout/index-4e77760b.js +773 -0
  15. package/dist/browser/checkout/index-8184ffea.js +1 -0
  16. package/dist/browser/checkout/index-919a5df1.js +1 -0
  17. package/dist/browser/checkout/index-e6159023.js +1 -0
  18. package/dist/browser/checkout/index-eb42cd09.js +106 -0
  19. package/dist/browser/checkout/index.umd-c2e32802.js +1 -0
  20. package/dist/browser/checkout/is-plan-event-enabled-80f76ce6.js +1 -0
  21. package/dist/browser/checkout/retry-355e44f2.js +1 -0
  22. package/dist/browser/checkout/sdk.js +4 -4
  23. package/dist/browser/checkout/useTransakEvents-c6a83ea5.js +2 -0
  24. package/dist/browser/checkout/widgets-esm.js +1 -0
  25. package/dist/browser/checkout/widgets.js +50 -51
  26. package/dist/checkout.d.ts +3 -1
  27. package/dist/checkout.js +65 -179
  28. package/dist/config.js +1 -1
  29. package/dist/index.browser.js +7 -7
  30. package/dist/index.browser.js.map +1 -1
  31. package/dist/index.cjs +200 -290
  32. package/dist/index.d.ts +291 -450
  33. package/dist/index.js +200 -290
  34. package/dist/orderbook.js +1 -1
  35. package/dist/passport.js +136 -239
  36. package/dist/x.js +2 -2
  37. 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-alpha.1';
155
+ const SDK_VERSION$1 = '1.7.3-alpha.2';
156
156
  const getReferrer$1 = () => {
157
157
  if (isNode$1()) {
158
158
  return '';
@@ -8419,85 +8419,6 @@ class NftOwnersApi extends BaseAPI$2 {
8419
8419
  */
8420
8420
  const NftsApiAxiosParamCreator = function (configuration) {
8421
8421
  return {
8422
- /**
8423
- * Create a mint request to mint a set of NFTs for a given collection
8424
- * @summary Mint NFTs
8425
- * @param {string} contractAddress The address of contract
8426
- * @param {string} chainName The name of chain
8427
- * @param {CreateMintRequestRequest} createMintRequestRequest the request body
8428
- * @param {*} [options] Override http request option.
8429
- * @throws {RequiredError}
8430
- */
8431
- createMintRequest: async (contractAddress, chainName, createMintRequestRequest, options = {}) => {
8432
- // verify required parameter 'contractAddress' is not null or undefined
8433
- assertParamExists$2('createMintRequest', 'contractAddress', contractAddress);
8434
- // verify required parameter 'chainName' is not null or undefined
8435
- assertParamExists$2('createMintRequest', 'chainName', chainName);
8436
- // verify required parameter 'createMintRequestRequest' is not null or undefined
8437
- assertParamExists$2('createMintRequest', 'createMintRequestRequest', createMintRequestRequest);
8438
- const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/nfts/mint-requests`
8439
- .replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
8440
- .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
8441
- // use dummy base URL string because the URL constructor only accepts absolute URLs.
8442
- const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$2);
8443
- let baseOptions;
8444
- if (configuration) {
8445
- baseOptions = configuration.baseOptions;
8446
- }
8447
- const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
8448
- const localVarHeaderParameter = {};
8449
- const localVarQueryParameter = {};
8450
- // authentication ImmutableApiKey required
8451
- await setApiKeyToObject(localVarHeaderParameter, "x-immutable-api-key", configuration);
8452
- localVarHeaderParameter['Content-Type'] = 'application/json';
8453
- setSearchParams$2(localVarUrlObj, localVarQueryParameter);
8454
- let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
8455
- localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
8456
- localVarRequestOptions.data = serializeDataIfNeeded$2(createMintRequestRequest, localVarRequestOptions, configuration);
8457
- return {
8458
- url: toPathString$2(localVarUrlObj),
8459
- options: localVarRequestOptions,
8460
- };
8461
- },
8462
- /**
8463
- * Retrieve the status of a mint request identified by its reference_id
8464
- * @summary Mint NFTs
8465
- * @param {string} contractAddress The address of contract
8466
- * @param {string} chainName The name of chain
8467
- * @param {string} referenceId The ID of the mint request
8468
- * @param {*} [options] Override http request option.
8469
- * @throws {RequiredError}
8470
- */
8471
- getMintRequest: async (contractAddress, chainName, referenceId, options = {}) => {
8472
- // verify required parameter 'contractAddress' is not null or undefined
8473
- assertParamExists$2('getMintRequest', 'contractAddress', contractAddress);
8474
- // verify required parameter 'chainName' is not null or undefined
8475
- assertParamExists$2('getMintRequest', 'chainName', chainName);
8476
- // verify required parameter 'referenceId' is not null or undefined
8477
- assertParamExists$2('getMintRequest', 'referenceId', referenceId);
8478
- const localVarPath = `/v1/chains/{chain_name}/collections/{contract_address}/nfts/mint-requests/{reference_id}`
8479
- .replace(`{${"contract_address"}}`, encodeURIComponent(String(contractAddress)))
8480
- .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)))
8481
- .replace(`{${"reference_id"}}`, encodeURIComponent(String(referenceId)));
8482
- // use dummy base URL string because the URL constructor only accepts absolute URLs.
8483
- const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$2);
8484
- let baseOptions;
8485
- if (configuration) {
8486
- baseOptions = configuration.baseOptions;
8487
- }
8488
- const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
8489
- const localVarHeaderParameter = {};
8490
- const localVarQueryParameter = {};
8491
- // authentication ImmutableApiKey required
8492
- await setApiKeyToObject(localVarHeaderParameter, "x-immutable-api-key", configuration);
8493
- setSearchParams$2(localVarUrlObj, localVarQueryParameter);
8494
- let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
8495
- localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
8496
- return {
8497
- url: toPathString$2(localVarUrlObj),
8498
- options: localVarRequestOptions,
8499
- };
8500
- },
8501
8422
  /**
8502
8423
  * Get NFT by token ID
8503
8424
  * @summary Get NFT by token ID
@@ -8683,32 +8604,6 @@ const NftsApiAxiosParamCreator = function (configuration) {
8683
8604
  const NftsApiFp = function (configuration) {
8684
8605
  const localVarAxiosParamCreator = NftsApiAxiosParamCreator(configuration);
8685
8606
  return {
8686
- /**
8687
- * Create a mint request to mint a set of NFTs for a given collection
8688
- * @summary Mint NFTs
8689
- * @param {string} contractAddress The address of contract
8690
- * @param {string} chainName The name of chain
8691
- * @param {CreateMintRequestRequest} createMintRequestRequest the request body
8692
- * @param {*} [options] Override http request option.
8693
- * @throws {RequiredError}
8694
- */
8695
- async createMintRequest(contractAddress, chainName, createMintRequestRequest, options) {
8696
- const localVarAxiosArgs = await localVarAxiosParamCreator.createMintRequest(contractAddress, chainName, createMintRequestRequest, options);
8697
- return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
8698
- },
8699
- /**
8700
- * Retrieve the status of a mint request identified by its reference_id
8701
- * @summary Mint NFTs
8702
- * @param {string} contractAddress The address of contract
8703
- * @param {string} chainName The name of chain
8704
- * @param {string} referenceId The ID of the mint request
8705
- * @param {*} [options] Override http request option.
8706
- * @throws {RequiredError}
8707
- */
8708
- async getMintRequest(contractAddress, chainName, referenceId, options) {
8709
- const localVarAxiosArgs = await localVarAxiosParamCreator.getMintRequest(contractAddress, chainName, referenceId, options);
8710
- return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
8711
- },
8712
8607
  /**
8713
8608
  * Get NFT by token ID
8714
8609
  * @summary Get NFT by token ID
@@ -8776,26 +8671,6 @@ const NftsApiFp = function (configuration) {
8776
8671
  const NftsApiFactory = function (configuration, basePath, axios) {
8777
8672
  const localVarFp = NftsApiFp(configuration);
8778
8673
  return {
8779
- /**
8780
- * Create a mint request to mint a set of NFTs for a given collection
8781
- * @summary Mint NFTs
8782
- * @param {NftsApiCreateMintRequestRequest} requestParameters Request parameters.
8783
- * @param {*} [options] Override http request option.
8784
- * @throws {RequiredError}
8785
- */
8786
- createMintRequest(requestParameters, options) {
8787
- return localVarFp.createMintRequest(requestParameters.contractAddress, requestParameters.chainName, requestParameters.createMintRequestRequest, options).then((request) => request(axios, basePath));
8788
- },
8789
- /**
8790
- * Retrieve the status of a mint request identified by its reference_id
8791
- * @summary Mint NFTs
8792
- * @param {NftsApiGetMintRequestRequest} requestParameters Request parameters.
8793
- * @param {*} [options] Override http request option.
8794
- * @throws {RequiredError}
8795
- */
8796
- getMintRequest(requestParameters, options) {
8797
- return localVarFp.getMintRequest(requestParameters.contractAddress, requestParameters.chainName, requestParameters.referenceId, options).then((request) => request(axios, basePath));
8798
- },
8799
8674
  /**
8800
8675
  * Get NFT by token ID
8801
8676
  * @summary Get NFT by token ID
@@ -8845,28 +8720,6 @@ const NftsApiFactory = function (configuration, basePath, axios) {
8845
8720
  * @extends {BaseAPI}
8846
8721
  */
8847
8722
  class NftsApi extends BaseAPI$2 {
8848
- /**
8849
- * Create a mint request to mint a set of NFTs for a given collection
8850
- * @summary Mint NFTs
8851
- * @param {NftsApiCreateMintRequestRequest} requestParameters Request parameters.
8852
- * @param {*} [options] Override http request option.
8853
- * @throws {RequiredError}
8854
- * @memberof NftsApi
8855
- */
8856
- createMintRequest(requestParameters, options) {
8857
- return NftsApiFp(this.configuration).createMintRequest(requestParameters.contractAddress, requestParameters.chainName, requestParameters.createMintRequestRequest, options).then((request) => request(this.axios, this.basePath));
8858
- }
8859
- /**
8860
- * Retrieve the status of a mint request identified by its reference_id
8861
- * @summary Mint NFTs
8862
- * @param {NftsApiGetMintRequestRequest} requestParameters Request parameters.
8863
- * @param {*} [options] Override http request option.
8864
- * @throws {RequiredError}
8865
- * @memberof NftsApi
8866
- */
8867
- getMintRequest(requestParameters, options) {
8868
- return NftsApiFp(this.configuration).getMintRequest(requestParameters.contractAddress, requestParameters.chainName, requestParameters.referenceId, options).then((request) => request(this.axios, this.basePath));
8869
- }
8870
8723
  /**
8871
8724
  * Get NFT by token ID
8872
8725
  * @summary Get NFT by token ID
@@ -11423,7 +11276,7 @@ class MultiRollupApiClients {
11423
11276
  }
11424
11277
 
11425
11278
  // eslint-disable-next-line @typescript-eslint/naming-convention
11426
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.3-alpha.1' };
11279
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.3-alpha.2' };
11427
11280
  const createConfig = ({ basePath, headers, }) => {
11428
11281
  if (!basePath.trim()) {
11429
11282
  throw Error('basePath can not be empty');
@@ -11495,7 +11348,7 @@ class APIError extends Error {
11495
11348
 
11496
11349
  /* eslint-disable implicit-arrow-linebreak */
11497
11350
  const defaultHeaders = {
11498
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.3-alpha.1',
11351
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.3-alpha.2',
11499
11352
  };
11500
11353
  /**
11501
11354
  * createAPIConfiguration to create a custom Configuration
@@ -11928,7 +11781,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11928
11781
  chainID,
11929
11782
  coreContractAddress,
11930
11783
  registrationContractAddress,
11931
- sdkVersion: 'ts-immutable-sdk-1.7.3-alpha.1',
11784
+ sdkVersion: 'ts-immutable-sdk-1.7.3-alpha.2',
11932
11785
  });
11933
11786
  /**
11934
11787
  * Sets `sdkVersion` at the time of build
@@ -16575,7 +16428,6 @@ const getAuthConfiguration = (config) => {
16575
16428
  end_session_endpoint: endSessionEndpoint,
16576
16429
  },
16577
16430
  mergeClaims: true,
16578
- loadUserInfo: true,
16579
16431
  scope: oidcConfiguration.scope,
16580
16432
  userStore,
16581
16433
  };
@@ -16616,7 +16468,10 @@ class AuthManager {
16616
16468
  this.logoutMode = config.oidcConfiguration.logoutMode || 'redirect';
16617
16469
  }
16618
16470
  static mapOidcUserToDomainModel = (oidcUser) => {
16619
- const passport = oidcUser.profile?.passport;
16471
+ let passport;
16472
+ if (oidcUser.id_token) {
16473
+ passport = jwt_decode(oidcUser.id_token)?.passport;
16474
+ }
16620
16475
  const user = {
16621
16476
  expired: oidcUser.expired,
16622
16477
  idToken: oidcUser.id_token,
@@ -18041,9 +17896,7 @@ class JsonRpcError extends Error {
18041
17896
  }
18042
17897
 
18043
17898
  const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
18044
- async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
18045
- const web3Provider = new Web3Provider(magicProvider);
18046
- const ethSigner = web3Provider.getSigner();
17899
+ async function registerZkEvmUser({ authManager, ethSigner, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
18047
17900
  const ethereumAddress = await ethSigner.getAddress();
18048
17901
  const ethereumSignature = await signRaw(MESSAGE_TO_SIGN, ethSigner);
18049
17902
  const headers = { Authorization: `Bearer ${accessToken}` };
@@ -18073,32 +17926,6 @@ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiCli
18073
17926
  return user;
18074
17927
  }
18075
17928
 
18076
- const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
18077
- const user = await authManager.getUserOrLogin();
18078
- if (!user.idToken) {
18079
- throw new Error('User is missing idToken');
18080
- }
18081
- const magicProvider = await magicAdapter.login(user.idToken);
18082
- if (!user.zkEvm) {
18083
- // Generate counterfactual address and retrieve updated Auth0 user
18084
- const userZkevm = await registerZkEvmUser({
18085
- authManager,
18086
- magicProvider,
18087
- multiRollupApiClients,
18088
- accessToken: user.accessToken,
18089
- jsonRpcProvider,
18090
- });
18091
- return {
18092
- user: userZkevm,
18093
- magicProvider,
18094
- };
18095
- }
18096
- return {
18097
- user: user,
18098
- magicProvider,
18099
- };
18100
- };
18101
-
18102
17929
  const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
18103
17930
  + ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
18104
17931
  const convertBigNumberishToString = (value) => BigNumber$1.from(value).toString();
@@ -18294,7 +18121,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
18294
18121
  }
18295
18122
  return [metaTransaction, feeMetaTransaction];
18296
18123
  };
18297
- const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
18124
+ const sendTransaction$1 = ({ params, ethSigner, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
18298
18125
  .withConfirmationScreen({ width: 480, height: 720 })(async () => {
18299
18126
  const transactionRequest = params[0];
18300
18127
  if (!transactionRequest.to) {
@@ -18302,8 +18129,6 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
18302
18129
  }
18303
18130
  const { chainId } = await jsonRpcProvider.ready;
18304
18131
  const chainIdBigNumber = BigNumber$1.from(chainId);
18305
- const magicWeb3Provider = new Web3Provider(magicProvider);
18306
- const signer = magicWeb3Provider.getSigner();
18307
18132
  const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
18308
18133
  const metaTransaction = {
18309
18134
  to: transactionRequest.to,
@@ -18312,7 +18137,7 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
18312
18137
  value: transactionRequest.value,
18313
18138
  revertOnError: true,
18314
18139
  };
18315
- const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, signer, relayerClient);
18140
+ const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, ethSigner, relayerClient);
18316
18141
  await guardianClient.validateEVMTransaction({
18317
18142
  chainId: getEip155ChainId(chainId),
18318
18143
  nonce: convertBigNumberishToString(nonce),
@@ -18320,7 +18145,7 @@ const sendTransaction$1 = ({ params, magicProvider, jsonRpcProvider, relayerClie
18320
18145
  });
18321
18146
  // NOTE: We sign again because we now are adding the fee transaction, so the
18322
18147
  // whole payload is different and needs a new signature.
18323
- const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, signer);
18148
+ const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, ethSigner);
18324
18149
  const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
18325
18150
  const retrieveRelayerTransaction = async () => {
18326
18151
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
@@ -18389,7 +18214,7 @@ const transformTypedData = (typedData, chainId) => {
18389
18214
  }
18390
18215
  return transformedTypedData;
18391
18216
  };
18392
- const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
18217
+ const signTypedDataV4 = async ({ params, method, ethSigner, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
18393
18218
  .withConfirmationScreen({ width: 480, height: 720 })(async () => {
18394
18219
  const fromAddress = params[0];
18395
18220
  const typedDataParam = params[1];
@@ -18400,106 +18225,158 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
18400
18225
  const typedData = transformTypedData(typedDataParam, chainId);
18401
18226
  await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
18402
18227
  const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
18403
- const magicWeb3Provider = new Web3Provider(magicProvider);
18404
- const signer = magicWeb3Provider.getSigner();
18405
- return getSignedTypedData(typedData, relayerSignature, BigNumber$1.from(chainId), fromAddress, signer);
18228
+ return getSignedTypedData(typedData, relayerSignature, BigNumber$1.from(chainId), fromAddress, ethSigner);
18406
18229
  });
18407
18230
 
18231
+ const isZkEvmUser = (user) => 'zkEvm' in user;
18408
18232
  class ZkEvmProvider {
18409
- authManager;
18410
- config;
18411
- magicAdapter;
18412
- multiRollupApiClients;
18413
- jsonRpcProvider; // Used for read
18414
- eventEmitter;
18415
- guardianClient;
18416
- relayerClient;
18417
- magicProvider; // Used for signing
18418
- zkevmAddress;
18233
+ #authManager;
18234
+ #config;
18235
+ #eventEmitter;
18236
+ #guardianClient;
18237
+ #jsonRpcProvider; // Used for read
18238
+ #magicAdapter;
18239
+ #multiRollupApiClients;
18240
+ #relayerClient;
18241
+ /**
18242
+ * This property is set during `#initialiseEthSigner` and stores the signer in a promise.
18243
+ * This property is not meant to be accessed directly, but through the
18244
+ * `#getSigner` method.
18245
+ * @see getSigner
18246
+ */
18247
+ #ethSigner;
18248
+ #signerInitialisationError;
18249
+ #zkEvmAddress;
18419
18250
  isPassport = true;
18420
18251
  constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
18421
- this.authManager = authManager;
18422
- this.magicAdapter = magicAdapter;
18423
- this.config = config;
18424
- this.guardianClient = guardianClient;
18252
+ this.#authManager = authManager;
18253
+ this.#magicAdapter = magicAdapter;
18254
+ this.#config = config;
18255
+ this.#guardianClient = guardianClient;
18425
18256
  if (config.crossSdkBridgeEnabled) {
18426
18257
  // JsonRpcProvider by default sets the referrer as "client".
18427
18258
  // On Unreal 4 this errors as the browser used is expecting a valid URL.
18428
- this.jsonRpcProvider = new JsonRpcProvider({
18429
- url: this.config.zkEvmRpcUrl,
18259
+ this.#jsonRpcProvider = new JsonRpcProvider({
18260
+ url: this.#config.zkEvmRpcUrl,
18430
18261
  fetchOptions: { referrer: 'http://imtblgamesdk.local' },
18431
18262
  });
18432
18263
  }
18433
18264
  else {
18434
- this.jsonRpcProvider = new JsonRpcProvider(this.config.zkEvmRpcUrl);
18265
+ this.#jsonRpcProvider = new JsonRpcProvider(this.#config.zkEvmRpcUrl);
18435
18266
  }
18436
- this.multiRollupApiClients = multiRollupApiClients;
18437
- this.eventEmitter = new TypedEventEmitter();
18438
- passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
18439
- }
18440
- handleLogout = () => {
18441
- const shouldEmitAccountsChanged = this.isLoggedIn();
18442
- this.magicProvider = undefined;
18443
- this.relayerClient = undefined;
18267
+ this.#relayerClient = new RelayerClient({
18268
+ config: this.#config,
18269
+ jsonRpcProvider: this.#jsonRpcProvider,
18270
+ authManager: this.#authManager,
18271
+ });
18272
+ this.#multiRollupApiClients = multiRollupApiClients;
18273
+ this.#eventEmitter = new TypedEventEmitter();
18274
+ passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.#handleLogout);
18275
+ }
18276
+ #handleLogout = () => {
18277
+ const shouldEmitAccountsChanged = !!this.#zkEvmAddress;
18278
+ this.#ethSigner = undefined;
18279
+ this.#zkEvmAddress = undefined;
18444
18280
  if (shouldEmitAccountsChanged) {
18445
- this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
18281
+ this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
18446
18282
  }
18447
18283
  };
18448
- isLoggedIn() {
18449
- return this.magicProvider !== undefined
18450
- && this.zkevmAddress !== undefined
18451
- && this.relayerClient !== undefined;
18284
+ /**
18285
+ * This method is called by `eth_requestAccounts` and asynchronously initialises the signer.
18286
+ * The signer is stored in a promise so that it can be retrieved by the provider
18287
+ * when needed.
18288
+ *
18289
+ * If an error is thrown during initialisation, it is stored in the `signerInitialisationError`,
18290
+ * so that it doesn't result in an unhandled promise rejection.
18291
+ *
18292
+ * This error is thrown when the signer is requested through:
18293
+ * @see #getSigner
18294
+ *
18295
+ */
18296
+ async #initialiseEthSigner(user) {
18297
+ const generateSigner = async () => {
18298
+ const magicRpcProvider = await this.#magicAdapter.login(user.idToken);
18299
+ const web3Provider = new Web3Provider(magicRpcProvider);
18300
+ return web3Provider.getSigner();
18301
+ };
18302
+ // eslint-disable-next-line no-async-promise-executor
18303
+ this.#ethSigner = new Promise(async (resolve) => {
18304
+ try {
18305
+ resolve(await generateSigner());
18306
+ }
18307
+ catch (err) {
18308
+ // Capture and store the initialization error
18309
+ this.#signerInitialisationError = err;
18310
+ resolve(undefined);
18311
+ }
18312
+ });
18313
+ }
18314
+ async #getSigner() {
18315
+ const ethSigner = await this.#ethSigner;
18316
+ // Throw the stored error if the signers failed to initialise
18317
+ if (typeof ethSigner === 'undefined') {
18318
+ if (typeof this.#signerInitialisationError !== 'undefined') {
18319
+ throw this.#signerInitialisationError;
18320
+ }
18321
+ throw new Error('Signer failed to initialise');
18322
+ }
18323
+ return ethSigner;
18452
18324
  }
18453
- async performRequest(request) {
18325
+ async #performRequest(request) {
18454
18326
  switch (request.method) {
18455
18327
  case 'eth_requestAccounts': {
18456
- if (this.isLoggedIn()) {
18457
- return [this.zkevmAddress];
18328
+ if (this.#zkEvmAddress) {
18329
+ return [this.#zkEvmAddress];
18458
18330
  }
18459
- const { magicProvider, user } = await loginZkEvmUser({
18460
- authManager: this.authManager,
18461
- magicAdapter: this.magicAdapter,
18462
- multiRollupApiClients: this.multiRollupApiClients,
18463
- jsonRpcProvider: this.jsonRpcProvider,
18464
- });
18465
- this.magicProvider = magicProvider;
18466
- this.relayerClient = new RelayerClient({
18467
- config: this.config,
18468
- jsonRpcProvider: this.jsonRpcProvider,
18469
- authManager: this.authManager,
18470
- });
18471
- this.zkevmAddress = user.zkEvm.ethAddress;
18472
- this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [user.zkEvm.ethAddress]);
18473
- return [user.zkEvm.ethAddress];
18331
+ const user = await this.#authManager.getUserOrLogin();
18332
+ this.#initialiseEthSigner(user);
18333
+ if (!isZkEvmUser(user)) {
18334
+ const ethSigner = await this.#getSigner();
18335
+ const userZkEvm = await registerZkEvmUser({
18336
+ ethSigner,
18337
+ authManager: this.#authManager,
18338
+ multiRollupApiClients: this.#multiRollupApiClients,
18339
+ accessToken: user.accessToken,
18340
+ jsonRpcProvider: this.#jsonRpcProvider,
18341
+ });
18342
+ this.#zkEvmAddress = userZkEvm.zkEvm.ethAddress;
18343
+ }
18344
+ else {
18345
+ this.#zkEvmAddress = user.zkEvm.ethAddress;
18346
+ }
18347
+ this.#eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.#zkEvmAddress]);
18348
+ return [this.#zkEvmAddress];
18474
18349
  }
18475
18350
  case 'eth_sendTransaction': {
18476
- if (!this.isLoggedIn()) {
18351
+ if (!this.#zkEvmAddress) {
18477
18352
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
18478
18353
  }
18354
+ const ethSigner = await this.#getSigner();
18479
18355
  return sendTransaction$1({
18480
18356
  params: request.params || [],
18481
- magicProvider: this.magicProvider,
18482
- guardianClient: this.guardianClient,
18483
- jsonRpcProvider: this.jsonRpcProvider,
18484
- relayerClient: this.relayerClient,
18485
- zkevmAddress: this.zkevmAddress,
18357
+ ethSigner,
18358
+ guardianClient: this.#guardianClient,
18359
+ jsonRpcProvider: this.#jsonRpcProvider,
18360
+ relayerClient: this.#relayerClient,
18361
+ zkevmAddress: this.#zkEvmAddress,
18486
18362
  });
18487
18363
  }
18488
18364
  case 'eth_accounts': {
18489
- return this.zkevmAddress ? [this.zkevmAddress] : [];
18365
+ return this.#zkEvmAddress ? [this.#zkEvmAddress] : [];
18490
18366
  }
18491
18367
  case 'eth_signTypedData':
18492
18368
  case 'eth_signTypedData_v4': {
18493
- if (!this.isLoggedIn()) {
18369
+ if (!this.#zkEvmAddress) {
18494
18370
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
18495
18371
  }
18372
+ const ethSigner = await this.#getSigner();
18496
18373
  return signTypedDataV4({
18497
18374
  method: request.method,
18498
18375
  params: request.params || [],
18499
- magicProvider: this.magicProvider,
18500
- jsonRpcProvider: this.jsonRpcProvider,
18501
- relayerClient: this.relayerClient,
18502
- guardianClient: this.guardianClient,
18376
+ ethSigner,
18377
+ jsonRpcProvider: this.#jsonRpcProvider,
18378
+ relayerClient: this.#relayerClient,
18379
+ guardianClient: this.#guardianClient,
18503
18380
  });
18504
18381
  }
18505
18382
  // Pass through methods
@@ -18516,17 +18393,17 @@ class ZkEvmProvider {
18516
18393
  case 'eth_getTransactionByHash':
18517
18394
  case 'eth_getTransactionReceipt':
18518
18395
  case 'eth_getTransactionCount': {
18519
- return this.jsonRpcProvider.send(request.method, request.params || []);
18396
+ return this.#jsonRpcProvider.send(request.method, request.params || []);
18520
18397
  }
18521
18398
  default: {
18522
18399
  throw new JsonRpcError(ProviderErrorCode.UNSUPPORTED_METHOD, 'Method not supported');
18523
18400
  }
18524
18401
  }
18525
18402
  }
18526
- async performJsonRpcRequest(request) {
18403
+ async #performJsonRpcRequest(request) {
18527
18404
  const { id, jsonrpc } = request;
18528
18405
  try {
18529
- const result = await this.performRequest(request);
18406
+ const result = await this.#performRequest(request);
18530
18407
  return {
18531
18408
  id,
18532
18409
  jsonrpc,
@@ -18553,7 +18430,7 @@ class ZkEvmProvider {
18553
18430
  }
18554
18431
  async request(request) {
18555
18432
  try {
18556
- return this.performRequest(request);
18433
+ return this.#performRequest(request);
18557
18434
  }
18558
18435
  catch (error) {
18559
18436
  if (error instanceof JsonRpcError) {
@@ -18570,14 +18447,14 @@ class ZkEvmProvider {
18570
18447
  throw new Error('No callback provided');
18571
18448
  }
18572
18449
  if (Array.isArray(request)) {
18573
- Promise.all(request.map(this.performJsonRpcRequest)).then((result) => {
18450
+ Promise.all(request.map(this.#performJsonRpcRequest)).then((result) => {
18574
18451
  callback(null, result);
18575
18452
  }).catch((error) => {
18576
18453
  callback(error, []);
18577
18454
  });
18578
18455
  }
18579
18456
  else {
18580
- this.performJsonRpcRequest(request).then((result) => {
18457
+ this.#performJsonRpcRequest(request).then((result) => {
18581
18458
  callback(null, result);
18582
18459
  }).catch((error) => {
18583
18460
  callback(error, null);
@@ -18609,15 +18486,15 @@ class ZkEvmProvider {
18609
18486
  return this.sendAsync(request, callbackOrParams);
18610
18487
  }
18611
18488
  if (!Array.isArray(request) && typeof request === 'object') {
18612
- return this.performJsonRpcRequest(request);
18489
+ return this.#performJsonRpcRequest(request);
18613
18490
  }
18614
18491
  throw new JsonRpcError(RpcErrorCode.INVALID_REQUEST, 'Invalid request');
18615
18492
  }
18616
18493
  on(event, listener) {
18617
- this.eventEmitter.on(event, listener);
18494
+ this.#eventEmitter.on(event, listener);
18618
18495
  }
18619
18496
  removeListener(event, listener) {
18620
- this.eventEmitter.removeListener(event, listener);
18497
+ this.#eventEmitter.removeListener(event, listener);
18621
18498
  }
18622
18499
  }
18623
18500
 
@@ -37579,7 +37456,7 @@ const flattenProperties = (properties) => {
37579
37456
  };
37580
37457
 
37581
37458
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
37582
- const SDK_VERSION = '1.7.3-alpha.1';
37459
+ const SDK_VERSION = '1.7.3-alpha.2';
37583
37460
  const getReferrer = () => {
37584
37461
  if (isNode()) {
37585
37462
  return '';
@@ -42747,7 +42624,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
42747
42624
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
42748
42625
  };
42749
42626
 
42750
- const SDK_VERSION_MARKER = '1.7.3-alpha.1';
42627
+ const SDK_VERSION_MARKER = '1.7.3-alpha.2';
42751
42628
  // This SDK version is replaced by the `yarn build` command ran on the root level
42752
42629
  const globalPackageVersion = () => SDK_VERSION_MARKER;
42753
42630
 
@@ -46367,27 +46244,25 @@ function validateAndBuildVersion(version) {
46367
46244
  return validatedVersion;
46368
46245
  }
46369
46246
 
46370
- function loadUnresolved(version) {
46247
+ // Loads the checkout widgets bundle from the CDN and appends the script to the document head
46248
+ function loadUnresolvedBundle(tag, scriptId, validVersion) {
46371
46249
  if (window === undefined) {
46372
46250
  throw new Error('missing window object: please run Checkout client side');
46373
46251
  }
46374
46252
  if (document === undefined) {
46375
46253
  throw new Error('missing document object: please run Checkout client side');
46376
46254
  }
46377
- const scriptId = 'immutable-checkout-widgets-bundle';
46378
- const validVersion = validateAndBuildVersion(version);
46379
- // Prevent the script to be loaded more than once
46380
- // by checking the presence of the script and its version.
46381
- const initScript = document.getElementById(scriptId);
46382
- if (initScript)
46383
- return { loaded: true, element: initScript };
46384
- const tag = document.createElement('script');
46385
46255
  let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets.js`;
46386
46256
  tag.setAttribute('id', scriptId);
46387
46257
  tag.setAttribute('data-version', validVersion);
46388
46258
  tag.setAttribute('src', cdnUrl);
46389
46259
  document.head.appendChild(tag);
46390
- return { loaded: false, element: tag };
46260
+ }
46261
+ // Gets the CDN url for the split checkout widgets bundle
46262
+ function getWidgetsEsmUrl(version) {
46263
+ const validVersion = validateAndBuildVersion(version);
46264
+ let cdnUrl = `https://cdn.jsdelivr.net/npm/@imtbl/sdk@${validVersion}/dist/browser/checkout/widgets-esm.js`;
46265
+ return cdnUrl;
46391
46266
  }
46392
46267
 
46393
46268
  const PUBLISHABLE_KEY_PREFIX = 'pk_imapik-';
@@ -46466,7 +46341,6 @@ const SANDBOX_CONFIGURATION = {
46466
46341
  },
46467
46342
  passport: undefined,
46468
46343
  };
46469
- const WIDGETS_SCRIPT_TIMEOUT = 100;
46470
46344
  // Checkout SDK
46471
46345
  class Checkout {
46472
46346
  readOnlyProviders;
@@ -46496,26 +46370,44 @@ class Checkout {
46496
46370
  const checkout = this;
46497
46371
  // Preload the configurations
46498
46372
  await checkout.config.remote.getConfig();
46373
+ try {
46374
+ const factory = await this.loadEsModules(init.config, init.version);
46375
+ return factory;
46376
+ }
46377
+ catch (err) {
46378
+ throw new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err });
46379
+ }
46380
+ }
46381
+ async loadUmdBundle(config, version) {
46382
+ const checkout = this;
46499
46383
  const factory = new Promise((resolve, reject) => {
46500
- function checkForWidgetsBundleLoaded() {
46501
- if (typeof ImmutableCheckoutWidgets !== 'undefined') {
46502
- resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
46503
- }
46504
- else {
46505
- // If ImmutableCheckoutWidgets is not defined, wait for set amount of time.
46506
- // When time has elapsed, check again if ImmutableCheckoutWidgets is defined.
46507
- // Once it's defined, the promise will resolve and setTimeout won't be called again.
46508
- setTimeout(checkForWidgetsBundleLoaded, WIDGETS_SCRIPT_TIMEOUT);
46509
- }
46510
- }
46511
46384
  try {
46512
- const script = loadUnresolved(init.version);
46513
- if (script.loaded && typeof ImmutableCheckoutWidgets !== 'undefined') {
46514
- resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, init.config));
46515
- }
46516
- else {
46517
- checkForWidgetsBundleLoaded();
46385
+ const scriptId = 'immutable-checkout-widgets-bundle';
46386
+ const validVersion = validateAndBuildVersion(version);
46387
+ // Prevent the script to be loaded more than once
46388
+ // by checking the presence of the script and its version.
46389
+ const initScript = document.getElementById(scriptId);
46390
+ if (initScript) {
46391
+ if (typeof ImmutableCheckoutWidgets !== 'undefined') {
46392
+ resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
46393
+ }
46394
+ else {
46395
+ reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
46396
+ }
46518
46397
  }
46398
+ const tag = document.createElement('script');
46399
+ tag.addEventListener('load', () => {
46400
+ if (typeof ImmutableCheckoutWidgets !== 'undefined') {
46401
+ resolve(new ImmutableCheckoutWidgets.WidgetsFactory(checkout, config));
46402
+ }
46403
+ else {
46404
+ reject(new CheckoutError('Failed to find ImmutableCheckoutWidgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR));
46405
+ }
46406
+ });
46407
+ tag.addEventListener('error', (err) => {
46408
+ reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
46409
+ });
46410
+ loadUnresolvedBundle(tag, scriptId, validVersion);
46519
46411
  }
46520
46412
  catch (err) {
46521
46413
  reject(new CheckoutError('Failed to load widgets script', CheckoutErrorType.WIDGETS_SCRIPT_LOAD_ERROR, { error: err }));
@@ -46523,6 +46415,24 @@ class Checkout {
46523
46415
  });
46524
46416
  return factory;
46525
46417
  }
46418
+ async loadEsModules(config, version) {
46419
+ const checkout = this;
46420
+ try {
46421
+ const cdnUrl = getWidgetsEsmUrl(version);
46422
+ // WebpackIgnore comment required to prevent webpack modifying the import statement and
46423
+ // breaking the dynamic import in certain applications integrating checkout
46424
+ const checkoutWidgetsModule = await import(/* webpackIgnore: true */ cdnUrl);
46425
+ if (checkoutWidgetsModule && checkoutWidgetsModule.WidgetsFactory) {
46426
+ return new checkoutWidgetsModule.WidgetsFactory(checkout, config);
46427
+ }
46428
+ }
46429
+ catch (err) {
46430
+ // eslint-disable-next-line no-console
46431
+ console.warn(`Failed to resolve checkout widgets module, falling back to UMD bundle. Error: ${err.message}`);
46432
+ }
46433
+ // Fallback to UMD bundle if esm bundle fails to load
46434
+ return await checkout.loadUmdBundle(config, version);
46435
+ }
46526
46436
  /**
46527
46437
  * Creates a provider using the given parameters.
46528
46438
  * @param {CreateProviderParams} params - The parameters for creating the provider.