@imtbl/sdk 1.6.1 → 1.7.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.
package/dist/index.js CHANGED
@@ -8,10 +8,10 @@ import * as crypto from 'crypto';
8
8
  import { Magic } from 'magic-sdk';
9
9
  import { OpenIdExtension } from '@magic-ext/oidc';
10
10
  import { JsonRpcProvider, Web3Provider } from '@ethersproject/providers';
11
- import { BigNumber as BigNumber$1, ethers, providers, constants as constants$1, ContractFactory, utils as utils$3, Contract as Contract$1 } from 'ethers';
12
11
  import BN$2 from 'bn.js';
13
12
  import * as encUtils from 'enc-utils';
14
13
  import { EventEmitter } from 'events';
14
+ import { BigNumber as BigNumber$1, ethers, providers, constants as constants$1, ContractFactory, utils as utils$3, Contract as Contract$1 } from 'ethers';
15
15
  import { walletContracts } from '@0xsequence/abi';
16
16
  import { v1 } from '@0xsequence/core';
17
17
  import FormData$2 from 'form-data';
@@ -120,7 +120,7 @@ const storeDetail$1 = (key, value) => {
120
120
  };
121
121
  setItem$1(Store$1.RUNTIME, RUNTIME_DETAILS$1);
122
122
  };
123
- const getDetail$1 = (key) => {
123
+ const getDetail$1$1 = (key) => {
124
124
  // Handle the scenario where detail is a falsy value
125
125
  if (RUNTIME_DETAILS$1[key] === undefined) {
126
126
  return undefined;
@@ -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.6.1';
155
+ const SDK_VERSION$1 = '1.7.0';
156
156
  const getReferrer$1 = () => {
157
157
  if (isNode$1()) {
158
158
  return '';
@@ -195,7 +195,7 @@ const initialise$2 = async () => {
195
195
  initialised$1 = true;
196
196
  try {
197
197
  const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
198
- const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
198
+ const existingRuntimeId = getDetail$1$1(Detail$1.RUNTIME_ID);
199
199
  const body = {
200
200
  version: 1,
201
201
  data: {
@@ -348,6 +348,7 @@ const setPublishableApiKeyFn$1 = (publishableApiKey) => {
348
348
  storeDetail$1(Detail$1.PUBLISHABLE_API_KEY, publishableApiKey);
349
349
  };
350
350
  const setPublishableApiKey = errorBoundary$1(getGlobalisedValue$2('setPublishableApiKey', setPublishableApiKeyFn$1));
351
+ const getDetail = errorBoundary$1(getGlobalisedValue$2('getDetail', getDetail$1$1));
351
352
 
352
353
  var Environment$1;
353
354
  (function (Environment) {
@@ -11275,7 +11276,7 @@ class MultiRollupApiClients {
11275
11276
  }
11276
11277
 
11277
11278
  // eslint-disable-next-line @typescript-eslint/naming-convention
11278
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.6.1' };
11279
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.0' };
11279
11280
  const createConfig = ({ basePath, headers, }) => {
11280
11281
  if (!basePath.trim()) {
11281
11282
  throw Error('basePath can not be empty');
@@ -11347,7 +11348,7 @@ class APIError extends Error {
11347
11348
 
11348
11349
  /* eslint-disable implicit-arrow-linebreak */
11349
11350
  const defaultHeaders = {
11350
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.6.1',
11351
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.0',
11351
11352
  };
11352
11353
  /**
11353
11354
  * createAPIConfiguration to create a custom Configuration
@@ -11780,7 +11781,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11780
11781
  chainID,
11781
11782
  coreContractAddress,
11782
11783
  registrationContractAddress,
11783
- sdkVersion: 'ts-immutable-sdk-1.6.1',
11784
+ sdkVersion: 'ts-immutable-sdk-1.7.0',
11784
11785
  });
11785
11786
  /**
11786
11787
  * Sets `sdkVersion` at the time of build
@@ -12283,6 +12284,78 @@ class IMXClient {
12283
12284
  }
12284
12285
  }
12285
12286
 
12287
+ // used to sign message with L1 keys. Used for registration
12288
+ function serializeEthSignature(sig) {
12289
+ // This is because golang appends a recovery param
12290
+ // https://github.com/ethers-io/ethers.js/issues/823
12291
+ return encUtils.addHexPrefix(encUtils.padLeft(sig.r.toString(16), 64)
12292
+ + encUtils.padLeft(sig.s.toString(16), 64)
12293
+ + encUtils.padLeft(sig.recoveryParam?.toString(16) || '', 2));
12294
+ }
12295
+ function importRecoveryParam(v) {
12296
+ const isValidBigNumber = new BN$2(v, 16).cmp(new BN$2(27)) !== -1
12297
+ ? new BN$2(v, 16).sub(new BN$2(27)).toNumber()
12298
+ : new BN$2(v, 16).toNumber();
12299
+ return v.trim()
12300
+ ? isValidBigNumber
12301
+ : undefined;
12302
+ }
12303
+ // used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
12304
+ function deserializeSignature(sig, size = 64) {
12305
+ const removedHexPrefixSig = encUtils.removeHexPrefix(sig);
12306
+ return {
12307
+ r: new BN$2(removedHexPrefixSig.substring(0, size), 'hex'),
12308
+ s: new BN$2(removedHexPrefixSig.substring(size, size * 2), 'hex'),
12309
+ recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
12310
+ };
12311
+ }
12312
+ async function signRaw(payload, signer) {
12313
+ const signature = deserializeSignature(await signer.signMessage(payload));
12314
+ return serializeEthSignature(signature);
12315
+ }
12316
+ async function signMessage$1(message, signer) {
12317
+ const ethAddress = await signer.getAddress();
12318
+ const ethSignature = await signRaw(message, signer);
12319
+ return {
12320
+ message,
12321
+ ethAddress,
12322
+ ethSignature,
12323
+ };
12324
+ }
12325
+
12326
+ /**
12327
+ * Helper method to convert token type to a SignableToken type
12328
+ * @param token - the token type to convert to a SignableToken type
12329
+ * @returns the converted SignableToken
12330
+ */
12331
+ function convertToSignableToken(token) {
12332
+ switch (token.type) {
12333
+ case 'ERC721':
12334
+ return {
12335
+ type: 'ERC721',
12336
+ data: {
12337
+ token_id: token.tokenId,
12338
+ token_address: token.tokenAddress,
12339
+ },
12340
+ };
12341
+ case 'ERC20':
12342
+ return {
12343
+ type: 'ERC20',
12344
+ data: {
12345
+ token_address: token.tokenAddress,
12346
+ },
12347
+ };
12348
+ case 'ETH':
12349
+ default:
12350
+ return {
12351
+ type: 'ETH',
12352
+ data: {
12353
+ decimals: 18,
12354
+ },
12355
+ };
12356
+ }
12357
+ }
12358
+
12286
12359
  function bind$1(fn, thisArg) {
12287
12360
  return function wrap() {
12288
12361
  return fn.apply(thisArg, arguments);
@@ -16198,78 +16271,6 @@ const TransactionApprovalRequestChainTypeEnum = {
16198
16271
  Evm: 'evm'
16199
16272
  };
16200
16273
 
16201
- // used to sign message with L1 keys. Used for registration
16202
- function serializeEthSignature(sig) {
16203
- // This is because golang appends a recovery param
16204
- // https://github.com/ethers-io/ethers.js/issues/823
16205
- return encUtils.addHexPrefix(encUtils.padLeft(sig.r.toString(16), 64)
16206
- + encUtils.padLeft(sig.s.toString(16), 64)
16207
- + encUtils.padLeft(sig.recoveryParam?.toString(16) || '', 2));
16208
- }
16209
- function importRecoveryParam(v) {
16210
- const isValidBigNumber = new BN$2(v, 16).cmp(new BN$2(27)) !== -1
16211
- ? new BN$2(v, 16).sub(new BN$2(27)).toNumber()
16212
- : new BN$2(v, 16).toNumber();
16213
- return v.trim()
16214
- ? isValidBigNumber
16215
- : undefined;
16216
- }
16217
- // used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
16218
- function deserializeSignature(sig, size = 64) {
16219
- const removedHexPrefixSig = encUtils.removeHexPrefix(sig);
16220
- return {
16221
- r: new BN$2(removedHexPrefixSig.substring(0, size), 'hex'),
16222
- s: new BN$2(removedHexPrefixSig.substring(size, size * 2), 'hex'),
16223
- recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
16224
- };
16225
- }
16226
- async function signRaw(payload, signer) {
16227
- const signature = deserializeSignature(await signer.signMessage(payload));
16228
- return serializeEthSignature(signature);
16229
- }
16230
- async function signMessage$1(message, signer) {
16231
- const ethAddress = await signer.getAddress();
16232
- const ethSignature = await signRaw(message, signer);
16233
- return {
16234
- message,
16235
- ethAddress,
16236
- ethSignature,
16237
- };
16238
- }
16239
-
16240
- /**
16241
- * Helper method to convert token type to a SignableToken type
16242
- * @param token - the token type to convert to a SignableToken type
16243
- * @returns the converted SignableToken
16244
- */
16245
- function convertToSignableToken(token) {
16246
- switch (token.type) {
16247
- case 'ERC721':
16248
- return {
16249
- type: 'ERC721',
16250
- data: {
16251
- token_id: token.tokenId,
16252
- token_address: token.tokenAddress,
16253
- },
16254
- };
16255
- case 'ERC20':
16256
- return {
16257
- type: 'ERC20',
16258
- data: {
16259
- token_address: token.tokenAddress,
16260
- },
16261
- };
16262
- case 'ETH':
16263
- default:
16264
- return {
16265
- type: 'ETH',
16266
- data: {
16267
- decimals: 18,
16268
- },
16269
- };
16270
- }
16271
- }
16272
-
16273
16274
  var PassportErrorType;
16274
16275
  (function (PassportErrorType) {
16275
16276
  PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
@@ -16514,29 +16515,54 @@ class AuthManager {
16514
16515
  },
16515
16516
  });
16516
16517
  };
16517
- async login() {
16518
+ /**
16519
+ * login
16520
+ * @param anonymousId Caller can pass an anonymousId if they want to associate their user's identity with immutable's internal instrumentation.
16521
+ */
16522
+ async login(anonymousId) {
16518
16523
  return withPassportError(async () => {
16524
+ const rid = getDetail(Detail$1.RUNTIME_ID);
16519
16525
  const popupWindowFeatures = { width: 410, height: 450 };
16520
16526
  const oidcUser = await this.userManager.signinPopup({
16527
+ extraQueryParams: {
16528
+ rid: rid || '',
16529
+ third_party_a_id: anonymousId || '',
16530
+ },
16521
16531
  popupWindowFeatures,
16522
16532
  });
16523
16533
  return AuthManager.mapOidcUserToDomainModel(oidcUser);
16524
16534
  }, PassportErrorType.AUTHENTICATION_ERROR);
16525
16535
  }
16536
+ async getUserOrLogin() {
16537
+ let user = null;
16538
+ try {
16539
+ user = await this.getUser();
16540
+ }
16541
+ catch (err) {
16542
+ // eslint-disable-next-line no-console
16543
+ console.warn('failed to retrieve a cached user session:', err);
16544
+ }
16545
+ return user || this.login();
16546
+ }
16526
16547
  async loginCallback() {
16527
16548
  return withPassportError(async () => this.userManager.signinPopupCallback(), PassportErrorType.AUTHENTICATION_ERROR);
16528
16549
  }
16529
- async loginWithDeviceFlow() {
16550
+ /**
16551
+ * loginWithDeviceFlow
16552
+ * @param anonymousId Caller can pass an anonymousId if they want to associate their user's identity with immutable's internal instrumentation.
16553
+ */
16554
+ async loginWithDeviceFlow(anonymousId) {
16530
16555
  return withPassportError(async () => {
16531
16556
  const response = await globalAxios$1.post(`${this.config.authenticationDomain}/oauth/device/code`, {
16532
16557
  client_id: this.config.oidcConfiguration.clientId,
16533
16558
  scope: this.config.oidcConfiguration.scope,
16534
16559
  audience: this.config.oidcConfiguration.audience,
16535
16560
  }, formUrlEncodedHeader);
16561
+ const rid = getDetail(Detail$1.RUNTIME_ID);
16536
16562
  return {
16537
16563
  code: response.data.user_code,
16538
16564
  deviceCode: response.data.device_code,
16539
- url: response.data.verification_uri_complete,
16565
+ url: `${response.data.verification_uri_complete}${rid ? `&rid=${rid}` : ''}${anonymousId ? `&third_party_a_id=${anonymousId}` : ''}`,
16540
16566
  interval: response.data.interval,
16541
16567
  };
16542
16568
  }, PassportErrorType.AUTHENTICATION_ERROR);
@@ -16770,227 +16796,6 @@ const getStarkSigner = async (signer) => withPassportError(async () => {
16770
16796
  return createStarkSigner(privateKey);
16771
16797
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
16772
16798
 
16773
- const POLL_INTERVAL = 1 * 1000; // every 1 second
16774
- const MAX_RETRIES = 3;
16775
- const wait = (ms) => new Promise((resolve) => {
16776
- setTimeout(() => resolve(), ms);
16777
- });
16778
- const retryWithDelay = async (fn, options) => {
16779
- const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
16780
- try {
16781
- return await fn();
16782
- }
16783
- catch (err) {
16784
- if (retries <= 0) {
16785
- return Promise.reject(finalErr);
16786
- }
16787
- await wait(interval);
16788
- return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
16789
- }
16790
- finally {
16791
- if (retries <= 0) {
16792
- finallyFn();
16793
- }
16794
- }
16795
- };
16796
-
16797
- /**
16798
- * ProviderErrors should take priority over RpcErrorCodes
16799
- * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
16800
- * https://eips.ethereum.org/EIPS/eip-1474#error-codes
16801
- */
16802
- var ProviderErrorCode;
16803
- (function (ProviderErrorCode) {
16804
- ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
16805
- ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
16806
- ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
16807
- ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
16808
- })(ProviderErrorCode || (ProviderErrorCode = {}));
16809
- var RpcErrorCode;
16810
- (function (RpcErrorCode) {
16811
- RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
16812
- RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
16813
- RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
16814
- RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
16815
- RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
16816
- RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
16817
- RpcErrorCode[RpcErrorCode["TRANSACTION_REJECTED"] = -32003] = "TRANSACTION_REJECTED";
16818
- })(RpcErrorCode || (RpcErrorCode = {}));
16819
- class JsonRpcError extends Error {
16820
- message;
16821
- code;
16822
- constructor(code, message) {
16823
- super(message);
16824
- this.message = message;
16825
- this.code = code;
16826
- }
16827
- }
16828
-
16829
- const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
16830
- + ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
16831
- const convertBigNumberishToString = (value) => BigNumber$1.from(value).toString();
16832
- const transformGuardianTransactions = (txs) => {
16833
- try {
16834
- return txs.map((t) => ({
16835
- delegateCall: t.delegateCall === true,
16836
- revertOnError: t.revertOnError === true,
16837
- gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
16838
- target: t.to ?? ethers.constants.AddressZero,
16839
- value: t.value ? convertBigNumberishToString(t.value) : '0',
16840
- data: t.data ? t.data.toString() : '0x',
16841
- }));
16842
- }
16843
- catch (error) {
16844
- const errorMessage = error instanceof Error ? error.message : String(error);
16845
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
16846
- }
16847
- };
16848
- class GuardianClient {
16849
- transactionAPI;
16850
- messageAPI;
16851
- confirmationScreen;
16852
- crossSdkBridgeEnabled;
16853
- authManager;
16854
- constructor({ confirmationScreen, config, authManager }) {
16855
- const guardianConfiguration = new Configuration({ basePath: config.imxPublicApiDomain });
16856
- this.confirmationScreen = confirmationScreen;
16857
- this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
16858
- this.messageAPI = new MessagesApi(guardianConfiguration);
16859
- this.transactionAPI = new TransactionsApi(guardianConfiguration);
16860
- this.authManager = authManager;
16861
- }
16862
- /**
16863
- * Open confirmation screen and close it automatically if the
16864
- * underlying task fails.
16865
- */
16866
- withConfirmationScreen(popupWindowSize) {
16867
- return (task) => this.withConfirmationScreenTask(popupWindowSize)(task)();
16868
- }
16869
- withConfirmationScreenTask(popupWindowSize) {
16870
- return (task) => async () => {
16871
- this.confirmationScreen.loading(popupWindowSize);
16872
- try {
16873
- return await task();
16874
- }
16875
- catch (err) {
16876
- this.confirmationScreen.closeWindow();
16877
- throw err;
16878
- }
16879
- };
16880
- }
16881
- withDefaultConfirmationScreenTask(task) {
16882
- return this.withConfirmationScreenTask()(task);
16883
- }
16884
- async evaluateImxTransaction({ payloadHash }) {
16885
- const finallyFn = () => {
16886
- this.confirmationScreen.closeWindow();
16887
- };
16888
- const user = await this.authManager.getUser();
16889
- const headers = { Authorization: `Bearer ${user.accessToken}` };
16890
- const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
16891
- transactionID: payloadHash,
16892
- chainType: 'starkex',
16893
- }, { headers }), { finallyFn });
16894
- if (!transactionRes.data.id) {
16895
- throw new Error("Transaction doesn't exists");
16896
- }
16897
- const evaluateImxRes = await this.transactionAPI.evaluateTransaction({
16898
- id: payloadHash,
16899
- transactionEvaluationRequest: {
16900
- chainType: 'starkex',
16901
- },
16902
- }, { headers });
16903
- const { confirmationRequired } = evaluateImxRes.data;
16904
- if (confirmationRequired) {
16905
- if (this.crossSdkBridgeEnabled) {
16906
- throw new Error(transactionRejectedCrossSdkBridgeError);
16907
- }
16908
- const confirmationResult = await this.confirmationScreen.requestConfirmation(payloadHash, user.imx.ethAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
16909
- if (!confirmationResult.confirmed) {
16910
- throw new Error('Transaction rejected by user');
16911
- }
16912
- }
16913
- else {
16914
- this.confirmationScreen.closeWindow();
16915
- }
16916
- }
16917
- async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
16918
- const user = await this.authManager.getUser();
16919
- const headers = { Authorization: `Bearer ${user.accessToken}` };
16920
- const guardianTransactions = transformGuardianTransactions(metaTransactions);
16921
- try {
16922
- const transactionEvaluationResponseAxiosResponse = await this.transactionAPI.evaluateTransaction({
16923
- id: 'evm',
16924
- transactionEvaluationRequest: {
16925
- chainType: 'evm',
16926
- chainId,
16927
- transactionData: {
16928
- nonce,
16929
- userAddress: user.zkEvm.ethAddress,
16930
- metaTransactions: guardianTransactions,
16931
- },
16932
- },
16933
- }, { headers });
16934
- return transactionEvaluationResponseAxiosResponse.data;
16935
- }
16936
- catch (error) {
16937
- const errorMessage = error instanceof Error ? error.message : String(error);
16938
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
16939
- }
16940
- }
16941
- async validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
16942
- const transactionEvaluationResponse = await this.evaluateEVMTransaction({
16943
- chainId,
16944
- nonce,
16945
- metaTransactions,
16946
- });
16947
- const { confirmationRequired, transactionId } = transactionEvaluationResponse;
16948
- if (confirmationRequired && this.crossSdkBridgeEnabled) {
16949
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
16950
- }
16951
- if (confirmationRequired && !!transactionId) {
16952
- const user = await this.authManager.getUser();
16953
- const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
16954
- if (!confirmationResult.confirmed) {
16955
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
16956
- }
16957
- }
16958
- else {
16959
- this.confirmationScreen.closeWindow();
16960
- }
16961
- }
16962
- async evaluateMessage({ chainID, payload }) {
16963
- try {
16964
- const user = await this.authManager.getUser();
16965
- if (user === null) {
16966
- throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
16967
- }
16968
- const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
16969
- return messageEvalResponse.data;
16970
- }
16971
- catch (error) {
16972
- const errorMessage = error instanceof Error ? error.message : String(error);
16973
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
16974
- }
16975
- }
16976
- async validateMessage({ chainID, payload }) {
16977
- const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload });
16978
- if (confirmationRequired && this.crossSdkBridgeEnabled) {
16979
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
16980
- }
16981
- if (confirmationRequired && !!messageId) {
16982
- const user = await this.authManager.getUser();
16983
- const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
16984
- if (!confirmationResult.confirmed) {
16985
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
16986
- }
16987
- }
16988
- else {
16989
- this.confirmationScreen.closeWindow();
16990
- }
16991
- }
16992
- }
16993
-
16994
16799
  var PassportEvents;
16995
16800
  (function (PassportEvents) {
16996
16801
  PassportEvents["LOGGED_OUT"] = "loggedOut";
@@ -17289,6 +17094,30 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
17289
17094
  }), PassportErrorType.TRANSFER_ERROR);
17290
17095
  }
17291
17096
 
17097
+ const POLL_INTERVAL = 1 * 1000; // every 1 second
17098
+ const MAX_RETRIES = 3;
17099
+ const wait = (ms) => new Promise((resolve) => {
17100
+ setTimeout(() => resolve(), ms);
17101
+ });
17102
+ const retryWithDelay = async (fn, options) => {
17103
+ const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
17104
+ try {
17105
+ return await fn();
17106
+ }
17107
+ catch (err) {
17108
+ if (retries <= 0) {
17109
+ return Promise.reject(finalErr);
17110
+ }
17111
+ await wait(interval);
17112
+ return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
17113
+ }
17114
+ finally {
17115
+ if (retries <= 0) {
17116
+ finallyFn();
17117
+ }
17118
+ }
17119
+ };
17120
+
17292
17121
  async function forceUserRefresh(authManager) {
17293
17122
  // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
17294
17123
  await retryWithDelay(async () => {
@@ -17334,16 +17163,12 @@ class PassportImxProvider {
17334
17163
  */
17335
17164
  signers;
17336
17165
  signerInitialisationError;
17337
- constructor({ authManager, immutableXClient, confirmationScreen, config, passportEventEmitter, magicAdapter, imxApiClients, }) {
17166
+ constructor({ authManager, immutableXClient, passportEventEmitter, magicAdapter, imxApiClients, guardianClient, }) {
17338
17167
  this.authManager = authManager;
17339
17168
  this.immutableXClient = immutableXClient;
17340
- this.guardianClient = new GuardianClient({
17341
- confirmationScreen,
17342
- config,
17343
- authManager,
17344
- });
17345
17169
  this.magicAdapter = magicAdapter;
17346
17170
  this.imxApiClients = imxApiClients;
17171
+ this.guardianClient = guardianClient;
17347
17172
  this.initialiseSigners();
17348
17173
  passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
17349
17174
  }
@@ -17506,33 +17331,21 @@ class PassportImxProvider {
17506
17331
 
17507
17332
  class PassportImxProviderFactory {
17508
17333
  authManager;
17509
- config;
17510
- confirmationScreen;
17511
17334
  immutableXClient;
17512
17335
  magicAdapter;
17513
17336
  passportEventEmitter;
17514
17337
  imxApiClients;
17515
- constructor({ authManager, config, confirmationScreen, immutableXClient, magicAdapter, passportEventEmitter, imxApiClients, }) {
17338
+ guardianClient;
17339
+ constructor({ authManager, immutableXClient, magicAdapter, passportEventEmitter, imxApiClients, guardianClient, }) {
17516
17340
  this.authManager = authManager;
17517
- this.config = config;
17518
- this.confirmationScreen = confirmationScreen;
17519
17341
  this.immutableXClient = immutableXClient;
17520
17342
  this.magicAdapter = magicAdapter;
17521
17343
  this.passportEventEmitter = passportEventEmitter;
17522
17344
  this.imxApiClients = imxApiClients;
17345
+ this.guardianClient = guardianClient;
17523
17346
  }
17524
17347
  async getProvider() {
17525
- let user = null;
17526
- try {
17527
- user = await this.authManager.getUser();
17528
- }
17529
- catch (e) {
17530
- // eslint-disable-next-line no-console
17531
- console.warn(e);
17532
- }
17533
- if (!user) {
17534
- user = await this.authManager.login();
17535
- }
17348
+ const user = await this.authManager.getUserOrLogin();
17536
17349
  return this.createProviderInstance(user);
17537
17350
  }
17538
17351
  async getProviderSilent() {
@@ -17547,13 +17360,12 @@ class PassportImxProviderFactory {
17547
17360
  throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
17548
17361
  }
17549
17362
  return new PassportImxProvider({
17550
- config: this.config,
17551
17363
  authManager: this.authManager,
17552
17364
  immutableXClient: this.immutableXClient,
17553
- confirmationScreen: this.confirmationScreen,
17554
17365
  passportEventEmitter: this.passportEventEmitter,
17555
17366
  magicAdapter: this.magicAdapter,
17556
17367
  imxApiClients: this.imxApiClients,
17368
+ guardianClient: this.guardianClient,
17557
17369
  });
17558
17370
  }
17559
17371
  }
@@ -18048,6 +17860,38 @@ class RelayerClient {
18048
17860
  }
18049
17861
  }
18050
17862
 
17863
+ /**
17864
+ * ProviderErrors should take priority over RpcErrorCodes
17865
+ * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
17866
+ * https://eips.ethereum.org/EIPS/eip-1474#error-codes
17867
+ */
17868
+ var ProviderErrorCode;
17869
+ (function (ProviderErrorCode) {
17870
+ ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
17871
+ ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
17872
+ ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
17873
+ ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
17874
+ })(ProviderErrorCode || (ProviderErrorCode = {}));
17875
+ var RpcErrorCode;
17876
+ (function (RpcErrorCode) {
17877
+ RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
17878
+ RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
17879
+ RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
17880
+ RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
17881
+ RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
17882
+ RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
17883
+ RpcErrorCode[RpcErrorCode["TRANSACTION_REJECTED"] = -32003] = "TRANSACTION_REJECTED";
17884
+ })(RpcErrorCode || (RpcErrorCode = {}));
17885
+ class JsonRpcError extends Error {
17886
+ message;
17887
+ code;
17888
+ constructor(code, message) {
17889
+ super(message);
17890
+ this.message = message;
17891
+ this.code = code;
17892
+ }
17893
+ }
17894
+
18051
17895
  const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
18052
17896
  async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
18053
17897
  const web3Provider = new Web3Provider(magicProvider);
@@ -18082,17 +17926,7 @@ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiCli
18082
17926
  }
18083
17927
 
18084
17928
  const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
18085
- let user = null;
18086
- try {
18087
- user = await authManager.getUser();
18088
- }
18089
- catch (err) {
18090
- // eslint-disable-next-line no-console
18091
- console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
18092
- }
18093
- if (!user) {
18094
- user = await authManager.login();
18095
- }
17929
+ const user = await authManager.getUserOrLogin();
18096
17930
  if (!user.idToken) {
18097
17931
  throw new Error('User is missing idToken');
18098
17932
  }
@@ -18117,6 +17951,171 @@ const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients
18117
17951
  };
18118
17952
  };
18119
17953
 
17954
+ const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
17955
+ + ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
17956
+ const convertBigNumberishToString = (value) => BigNumber$1.from(value).toString();
17957
+ const transformGuardianTransactions = (txs) => {
17958
+ try {
17959
+ return txs.map((t) => ({
17960
+ delegateCall: t.delegateCall === true,
17961
+ revertOnError: t.revertOnError === true,
17962
+ gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
17963
+ target: t.to ?? ethers.constants.AddressZero,
17964
+ value: t.value ? convertBigNumberishToString(t.value) : '0',
17965
+ data: t.data ? t.data.toString() : '0x',
17966
+ }));
17967
+ }
17968
+ catch (error) {
17969
+ const errorMessage = error instanceof Error ? error.message : String(error);
17970
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
17971
+ }
17972
+ };
17973
+ class GuardianClient {
17974
+ transactionAPI;
17975
+ messageAPI;
17976
+ confirmationScreen;
17977
+ crossSdkBridgeEnabled;
17978
+ authManager;
17979
+ constructor({ confirmationScreen, config, authManager }) {
17980
+ const guardianConfiguration = new Configuration({ basePath: config.imxPublicApiDomain });
17981
+ this.confirmationScreen = confirmationScreen;
17982
+ this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
17983
+ this.messageAPI = new MessagesApi(guardianConfiguration);
17984
+ this.transactionAPI = new TransactionsApi(guardianConfiguration);
17985
+ this.authManager = authManager;
17986
+ }
17987
+ /**
17988
+ * Open confirmation screen and close it automatically if the
17989
+ * underlying task fails.
17990
+ */
17991
+ withConfirmationScreen(popupWindowSize) {
17992
+ return (task) => this.withConfirmationScreenTask(popupWindowSize)(task)();
17993
+ }
17994
+ withConfirmationScreenTask(popupWindowSize) {
17995
+ return (task) => async () => {
17996
+ this.confirmationScreen.loading(popupWindowSize);
17997
+ try {
17998
+ return await task();
17999
+ }
18000
+ catch (err) {
18001
+ this.confirmationScreen.closeWindow();
18002
+ throw err;
18003
+ }
18004
+ };
18005
+ }
18006
+ withDefaultConfirmationScreenTask(task) {
18007
+ return this.withConfirmationScreenTask()(task);
18008
+ }
18009
+ async evaluateImxTransaction({ payloadHash }) {
18010
+ const finallyFn = () => {
18011
+ this.confirmationScreen.closeWindow();
18012
+ };
18013
+ const user = await this.authManager.getUser();
18014
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
18015
+ const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
18016
+ transactionID: payloadHash,
18017
+ chainType: 'starkex',
18018
+ }, { headers }), { finallyFn });
18019
+ if (!transactionRes.data.id) {
18020
+ throw new Error("Transaction doesn't exists");
18021
+ }
18022
+ const evaluateImxRes = await this.transactionAPI.evaluateTransaction({
18023
+ id: payloadHash,
18024
+ transactionEvaluationRequest: {
18025
+ chainType: 'starkex',
18026
+ },
18027
+ }, { headers });
18028
+ const { confirmationRequired } = evaluateImxRes.data;
18029
+ if (confirmationRequired) {
18030
+ if (this.crossSdkBridgeEnabled) {
18031
+ throw new Error(transactionRejectedCrossSdkBridgeError);
18032
+ }
18033
+ const confirmationResult = await this.confirmationScreen.requestConfirmation(payloadHash, user.imx.ethAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
18034
+ if (!confirmationResult.confirmed) {
18035
+ throw new Error('Transaction rejected by user');
18036
+ }
18037
+ }
18038
+ else {
18039
+ this.confirmationScreen.closeWindow();
18040
+ }
18041
+ }
18042
+ async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
18043
+ const user = await this.authManager.getUser();
18044
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
18045
+ const guardianTransactions = transformGuardianTransactions(metaTransactions);
18046
+ try {
18047
+ const transactionEvaluationResponseAxiosResponse = await this.transactionAPI.evaluateTransaction({
18048
+ id: 'evm',
18049
+ transactionEvaluationRequest: {
18050
+ chainType: 'evm',
18051
+ chainId,
18052
+ transactionData: {
18053
+ nonce,
18054
+ userAddress: user.zkEvm.ethAddress,
18055
+ metaTransactions: guardianTransactions,
18056
+ },
18057
+ },
18058
+ }, { headers });
18059
+ return transactionEvaluationResponseAxiosResponse.data;
18060
+ }
18061
+ catch (error) {
18062
+ const errorMessage = error instanceof Error ? error.message : String(error);
18063
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
18064
+ }
18065
+ }
18066
+ async validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
18067
+ const transactionEvaluationResponse = await this.evaluateEVMTransaction({
18068
+ chainId,
18069
+ nonce,
18070
+ metaTransactions,
18071
+ });
18072
+ const { confirmationRequired, transactionId } = transactionEvaluationResponse;
18073
+ if (confirmationRequired && this.crossSdkBridgeEnabled) {
18074
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
18075
+ }
18076
+ if (confirmationRequired && !!transactionId) {
18077
+ const user = await this.authManager.getUser();
18078
+ const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
18079
+ if (!confirmationResult.confirmed) {
18080
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
18081
+ }
18082
+ }
18083
+ else {
18084
+ this.confirmationScreen.closeWindow();
18085
+ }
18086
+ }
18087
+ async evaluateMessage({ chainID, payload }) {
18088
+ try {
18089
+ const user = await this.authManager.getUser();
18090
+ if (user === null) {
18091
+ throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
18092
+ }
18093
+ const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
18094
+ return messageEvalResponse.data;
18095
+ }
18096
+ catch (error) {
18097
+ const errorMessage = error instanceof Error ? error.message : String(error);
18098
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
18099
+ }
18100
+ }
18101
+ async validateMessage({ chainID, payload }) {
18102
+ const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload });
18103
+ if (confirmationRequired && this.crossSdkBridgeEnabled) {
18104
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
18105
+ }
18106
+ if (confirmationRequired && !!messageId) {
18107
+ const user = await this.authManager.getUser();
18108
+ const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
18109
+ if (!confirmationResult.confirmed) {
18110
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
18111
+ }
18112
+ }
18113
+ else {
18114
+ this.confirmationScreen.closeWindow();
18115
+ }
18116
+ }
18117
+ }
18118
+
18120
18119
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
18121
18120
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
18122
18121
  const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddress, signer, relayerClient) => {
@@ -18261,7 +18260,6 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
18261
18260
  class ZkEvmProvider {
18262
18261
  authManager;
18263
18262
  config;
18264
- confirmationScreen;
18265
18263
  magicAdapter;
18266
18264
  multiRollupApiClients;
18267
18265
  jsonRpcProvider; // Used for read
@@ -18271,11 +18269,11 @@ class ZkEvmProvider {
18271
18269
  magicProvider; // Used for signing
18272
18270
  zkevmAddress;
18273
18271
  isPassport = true;
18274
- constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, passportEventEmitter, }) {
18272
+ constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
18275
18273
  this.authManager = authManager;
18276
18274
  this.magicAdapter = magicAdapter;
18277
18275
  this.config = config;
18278
- this.confirmationScreen = confirmationScreen;
18276
+ this.guardianClient = guardianClient;
18279
18277
  if (config.crossSdkBridgeEnabled) {
18280
18278
  // JsonRpcProvider by default sets the referrer as "client".
18281
18279
  // On Unreal 4 this errors as the browser used is expecting a valid URL.
@@ -18295,7 +18293,6 @@ class ZkEvmProvider {
18295
18293
  const shouldEmitAccountsChanged = this.isLoggedIn();
18296
18294
  this.magicProvider = undefined;
18297
18295
  this.relayerClient = undefined;
18298
- this.guardianClient = undefined;
18299
18296
  if (shouldEmitAccountsChanged) {
18300
18297
  this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
18301
18298
  }
@@ -18303,8 +18300,7 @@ class ZkEvmProvider {
18303
18300
  isLoggedIn() {
18304
18301
  return this.magicProvider !== undefined
18305
18302
  && this.zkevmAddress !== undefined
18306
- && this.relayerClient !== undefined
18307
- && this.guardianClient !== undefined;
18303
+ && this.relayerClient !== undefined;
18308
18304
  }
18309
18305
  async performRequest(request) {
18310
18306
  switch (request.method) {
@@ -18314,7 +18310,6 @@ class ZkEvmProvider {
18314
18310
  }
18315
18311
  const { magicProvider, user } = await loginZkEvmUser({
18316
18312
  authManager: this.authManager,
18317
- config: this.config,
18318
18313
  magicAdapter: this.magicAdapter,
18319
18314
  multiRollupApiClients: this.multiRollupApiClients,
18320
18315
  jsonRpcProvider: this.jsonRpcProvider,
@@ -18325,11 +18320,6 @@ class ZkEvmProvider {
18325
18320
  jsonRpcProvider: this.jsonRpcProvider,
18326
18321
  authManager: this.authManager,
18327
18322
  });
18328
- this.guardianClient = new GuardianClient({
18329
- confirmationScreen: this.confirmationScreen,
18330
- config: this.config,
18331
- authManager: this.authManager,
18332
- });
18333
18323
  this.zkevmAddress = user.zkEvm.ethAddress;
18334
18324
  this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [user.zkEvm.ethAddress]);
18335
18325
  return [user.zkEvm.ethAddress];
@@ -18508,15 +18498,19 @@ const buildPrivateVars = (passportModuleConfiguration) => {
18508
18498
  const immutableXClient = passportModuleConfiguration.overrides
18509
18499
  ? passportModuleConfiguration.overrides.immutableXClient
18510
18500
  : new IMXClient({ baseConfig: passportModuleConfiguration.baseConfig });
18501
+ const guardianClient = new GuardianClient({
18502
+ confirmationScreen,
18503
+ config,
18504
+ authManager,
18505
+ });
18511
18506
  const imxApiClients = buildImxApiClients(passportModuleConfiguration);
18512
18507
  const passportImxProviderFactory = new PassportImxProviderFactory({
18513
18508
  authManager,
18514
- config,
18515
- confirmationScreen,
18516
18509
  immutableXClient,
18517
18510
  magicAdapter,
18518
18511
  passportEventEmitter,
18519
18512
  imxApiClients,
18513
+ guardianClient,
18520
18514
  });
18521
18515
  return {
18522
18516
  config,
@@ -18527,6 +18521,7 @@ const buildPrivateVars = (passportModuleConfiguration) => {
18527
18521
  multiRollupApiClients,
18528
18522
  passportEventEmitter,
18529
18523
  passportImxProviderFactory,
18524
+ guardianClient,
18530
18525
  };
18531
18526
  };
18532
18527
  class Passport {
@@ -18538,6 +18533,7 @@ class Passport {
18538
18533
  multiRollupApiClients;
18539
18534
  passportImxProviderFactory;
18540
18535
  passportEventEmitter;
18536
+ guardianClient;
18541
18537
  constructor(passportModuleConfiguration) {
18542
18538
  const privateVars = buildPrivateVars(passportModuleConfiguration);
18543
18539
  this.config = privateVars.config;
@@ -18548,6 +18544,7 @@ class Passport {
18548
18544
  this.multiRollupApiClients = privateVars.multiRollupApiClients;
18549
18545
  this.passportEventEmitter = privateVars.passportEventEmitter;
18550
18546
  this.passportImxProviderFactory = privateVars.passportImxProviderFactory;
18547
+ this.guardianClient = privateVars.guardianClient;
18551
18548
  setPassportClientId(passportModuleConfiguration.clientId);
18552
18549
  track('passport', 'initialised');
18553
18550
  }
@@ -18567,8 +18564,8 @@ class Passport {
18567
18564
  authManager: this.authManager,
18568
18565
  magicAdapter: this.magicAdapter,
18569
18566
  config: this.config,
18570
- confirmationScreen: this.confirmationScreen,
18571
18567
  multiRollupApiClients: this.multiRollupApiClients,
18568
+ guardianClient: this.guardianClient,
18572
18569
  });
18573
18570
  }
18574
18571
  /**
@@ -37402,7 +37399,7 @@ const storeDetail = (key, value) => {
37402
37399
  };
37403
37400
  setItem(Store.RUNTIME, RUNTIME_DETAILS);
37404
37401
  };
37405
- const getDetail = (key) => {
37402
+ const getDetail$1 = (key) => {
37406
37403
  // Handle the scenario where detail is a falsy value
37407
37404
  if (RUNTIME_DETAILS[key] === undefined) {
37408
37405
  return undefined;
@@ -37434,7 +37431,7 @@ const flattenProperties = (properties) => {
37434
37431
  };
37435
37432
 
37436
37433
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
37437
- const SDK_VERSION = '1.6.1';
37434
+ const SDK_VERSION = '1.7.0';
37438
37435
  const getReferrer = () => {
37439
37436
  if (isNode()) {
37440
37437
  return '';
@@ -37477,7 +37474,7 @@ const initialise = async () => {
37477
37474
  initialised = true;
37478
37475
  try {
37479
37476
  const runtimeDetails = flattenProperties(getRuntimeDetails());
37480
- const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
37477
+ const existingRuntimeId = getDetail$1(Detail.RUNTIME_ID);
37481
37478
  const body = {
37482
37479
  version: 1,
37483
37480
  data: {
@@ -37609,6 +37606,7 @@ const setPublishableApiKeyFn = (publishableApiKey) => {
37609
37606
  storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
37610
37607
  };
37611
37608
  errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
37609
+ errorBoundary(getGlobalisedValue('getDetail', getDetail$1));
37612
37610
 
37613
37611
  var Environment;
37614
37612
  (function (Environment) {
@@ -42601,7 +42599,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
42601
42599
  maxPriorityFeePerGas: BigNumber$1.from(10e9),
42602
42600
  };
42603
42601
 
42604
- const SDK_VERSION_MARKER = '1.6.1';
42602
+ const SDK_VERSION_MARKER = '1.7.0';
42605
42603
  // This SDK version is replaced by the `yarn build` command ran on the root level
42606
42604
  const globalPackageVersion = () => SDK_VERSION_MARKER;
42607
42605
 
@@ -46115,13 +46113,15 @@ class FiatRampService {
46115
46113
  const productsAvailed = 'productsAvailed=buy';
46116
46114
  const exchangeScreenTitle = 'exchangeScreenTitle=Buy';
46117
46115
  const themeColor = 'themeColor=0D0D0D';
46116
+ const defaultFiat = 'defaultFiatAmount=50&defaultFiatCurrency=usd';
46118
46117
  widgetUrl += `${transakPublishableKey}&`
46119
46118
  + `${zkevmNetwork}&`
46120
46119
  + `${defaultPaymentMethod}&`
46121
46120
  + `${disableBankTransfer}&`
46122
46121
  + `${productsAvailed}&`
46123
46122
  + `${exchangeScreenTitle}&`
46124
- + `${themeColor}`;
46123
+ + `${themeColor}&`
46124
+ + `${defaultFiat}`;
46125
46125
  if (params.isPassport && params.email) {
46126
46126
  const encodedEmail = encodeURIComponent(params.email);
46127
46127
  widgetUrl += `&email=${encodedEmail}&isAutoFillUserData=true&disableWalletAddressForm=true`;
@@ -46135,6 +46135,9 @@ class FiatRampService {
46135
46135
  if (params.walletAddress) {
46136
46136
  widgetUrl += `&walletAddress=${params.walletAddress}`;
46137
46137
  }
46138
+ if (params.allowedTokens) {
46139
+ widgetUrl += `&cryptoCurrencyList=${params.allowedTokens?.join(',').toLowerCase()}`;
46140
+ }
46138
46141
  return widgetUrl;
46139
46142
  }
46140
46143
  }
@@ -46581,6 +46584,7 @@ class Checkout {
46581
46584
  tokenAmount = params.tokenAmount;
46582
46585
  tokenSymbol = token.symbol;
46583
46586
  }
46587
+ const allowedTokens = tokenList?.tokens?.filter((t) => t.symbol).map((t) => t.symbol);
46584
46588
  return await this.fiatRampService.createWidgetUrl({
46585
46589
  exchangeType: params.exchangeType,
46586
46590
  isPassport,
@@ -46588,6 +46592,7 @@ class Checkout {
46588
46592
  tokenAmount,
46589
46593
  tokenSymbol,
46590
46594
  email,
46595
+ allowedTokens,
46591
46596
  });
46592
46597
  }
46593
46598
  /**