@imtbl/sdk 1.6.0 → 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.cjs CHANGED
@@ -10,10 +10,10 @@ var crypto = require('crypto');
10
10
  var magicSdk = require('magic-sdk');
11
11
  var oidc = require('@magic-ext/oidc');
12
12
  var providers = require('@ethersproject/providers');
13
- var ethers = require('ethers');
14
13
  var BN$2 = require('bn.js');
15
14
  var encUtils = require('enc-utils');
16
15
  var events = require('events');
16
+ var ethers = require('ethers');
17
17
  var abi = require('@0xsequence/abi');
18
18
  var core = require('@0xsequence/core');
19
19
  var FormData$2 = require('form-data');
@@ -142,7 +142,7 @@ const storeDetail$1 = (key, value) => {
142
142
  };
143
143
  setItem$1(Store$1.RUNTIME, RUNTIME_DETAILS$1);
144
144
  };
145
- const getDetail$1 = (key) => {
145
+ const getDetail$1$1 = (key) => {
146
146
  // Handle the scenario where detail is a falsy value
147
147
  if (RUNTIME_DETAILS$1[key] === undefined) {
148
148
  return undefined;
@@ -174,7 +174,7 @@ const flattenProperties$1 = (properties) => {
174
174
  };
175
175
 
176
176
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
177
- const SDK_VERSION$1 = '1.6.0';
177
+ const SDK_VERSION$1 = '1.7.0';
178
178
  const getReferrer$1 = () => {
179
179
  if (isNode$1()) {
180
180
  return '';
@@ -217,7 +217,7 @@ const initialise$2 = async () => {
217
217
  initialised$1 = true;
218
218
  try {
219
219
  const runtimeDetails = flattenProperties$1(getRuntimeDetails$1());
220
- const existingRuntimeId = getDetail$1(Detail$1.RUNTIME_ID);
220
+ const existingRuntimeId = getDetail$1$1(Detail$1.RUNTIME_ID);
221
221
  const body = {
222
222
  version: 1,
223
223
  data: {
@@ -370,6 +370,7 @@ const setPublishableApiKeyFn$1 = (publishableApiKey) => {
370
370
  storeDetail$1(Detail$1.PUBLISHABLE_API_KEY, publishableApiKey);
371
371
  };
372
372
  const setPublishableApiKey = errorBoundary$1(getGlobalisedValue$2('setPublishableApiKey', setPublishableApiKeyFn$1));
373
+ const getDetail = errorBoundary$1(getGlobalisedValue$2('getDetail', getDetail$1$1));
373
374
 
374
375
  var Environment$1;
375
376
  (function (Environment) {
@@ -11297,7 +11298,7 @@ class MultiRollupApiClients {
11297
11298
  }
11298
11299
 
11299
11300
  // eslint-disable-next-line @typescript-eslint/naming-convention
11300
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.6.0' };
11301
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.7.0' };
11301
11302
  const createConfig = ({ basePath, headers, }) => {
11302
11303
  if (!basePath.trim()) {
11303
11304
  throw Error('basePath can not be empty');
@@ -11369,7 +11370,7 @@ class APIError extends Error {
11369
11370
 
11370
11371
  /* eslint-disable implicit-arrow-linebreak */
11371
11372
  const defaultHeaders = {
11372
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.6.0',
11373
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-1.7.0',
11373
11374
  };
11374
11375
  /**
11375
11376
  * createAPIConfiguration to create a custom Configuration
@@ -11802,7 +11803,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11802
11803
  chainID,
11803
11804
  coreContractAddress,
11804
11805
  registrationContractAddress,
11805
- sdkVersion: 'ts-immutable-sdk-1.6.0',
11806
+ sdkVersion: 'ts-immutable-sdk-1.7.0',
11806
11807
  });
11807
11808
  /**
11808
11809
  * Sets `sdkVersion` at the time of build
@@ -12305,6 +12306,78 @@ class IMXClient {
12305
12306
  }
12306
12307
  }
12307
12308
 
12309
+ // used to sign message with L1 keys. Used for registration
12310
+ function serializeEthSignature(sig) {
12311
+ // This is because golang appends a recovery param
12312
+ // https://github.com/ethers-io/ethers.js/issues/823
12313
+ return encUtils__namespace.addHexPrefix(encUtils__namespace.padLeft(sig.r.toString(16), 64)
12314
+ + encUtils__namespace.padLeft(sig.s.toString(16), 64)
12315
+ + encUtils__namespace.padLeft(sig.recoveryParam?.toString(16) || '', 2));
12316
+ }
12317
+ function importRecoveryParam(v) {
12318
+ const isValidBigNumber = new BN$2(v, 16).cmp(new BN$2(27)) !== -1
12319
+ ? new BN$2(v, 16).sub(new BN$2(27)).toNumber()
12320
+ : new BN$2(v, 16).toNumber();
12321
+ return v.trim()
12322
+ ? isValidBigNumber
12323
+ : undefined;
12324
+ }
12325
+ // used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
12326
+ function deserializeSignature(sig, size = 64) {
12327
+ const removedHexPrefixSig = encUtils__namespace.removeHexPrefix(sig);
12328
+ return {
12329
+ r: new BN$2(removedHexPrefixSig.substring(0, size), 'hex'),
12330
+ s: new BN$2(removedHexPrefixSig.substring(size, size * 2), 'hex'),
12331
+ recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
12332
+ };
12333
+ }
12334
+ async function signRaw(payload, signer) {
12335
+ const signature = deserializeSignature(await signer.signMessage(payload));
12336
+ return serializeEthSignature(signature);
12337
+ }
12338
+ async function signMessage$1(message, signer) {
12339
+ const ethAddress = await signer.getAddress();
12340
+ const ethSignature = await signRaw(message, signer);
12341
+ return {
12342
+ message,
12343
+ ethAddress,
12344
+ ethSignature,
12345
+ };
12346
+ }
12347
+
12348
+ /**
12349
+ * Helper method to convert token type to a SignableToken type
12350
+ * @param token - the token type to convert to a SignableToken type
12351
+ * @returns the converted SignableToken
12352
+ */
12353
+ function convertToSignableToken(token) {
12354
+ switch (token.type) {
12355
+ case 'ERC721':
12356
+ return {
12357
+ type: 'ERC721',
12358
+ data: {
12359
+ token_id: token.tokenId,
12360
+ token_address: token.tokenAddress,
12361
+ },
12362
+ };
12363
+ case 'ERC20':
12364
+ return {
12365
+ type: 'ERC20',
12366
+ data: {
12367
+ token_address: token.tokenAddress,
12368
+ },
12369
+ };
12370
+ case 'ETH':
12371
+ default:
12372
+ return {
12373
+ type: 'ETH',
12374
+ data: {
12375
+ decimals: 18,
12376
+ },
12377
+ };
12378
+ }
12379
+ }
12380
+
12308
12381
  function bind$1(fn, thisArg) {
12309
12382
  return function wrap() {
12310
12383
  return fn.apply(thisArg, arguments);
@@ -16220,78 +16293,6 @@ const TransactionApprovalRequestChainTypeEnum = {
16220
16293
  Evm: 'evm'
16221
16294
  };
16222
16295
 
16223
- // used to sign message with L1 keys. Used for registration
16224
- function serializeEthSignature(sig) {
16225
- // This is because golang appends a recovery param
16226
- // https://github.com/ethers-io/ethers.js/issues/823
16227
- return encUtils__namespace.addHexPrefix(encUtils__namespace.padLeft(sig.r.toString(16), 64)
16228
- + encUtils__namespace.padLeft(sig.s.toString(16), 64)
16229
- + encUtils__namespace.padLeft(sig.recoveryParam?.toString(16) || '', 2));
16230
- }
16231
- function importRecoveryParam(v) {
16232
- const isValidBigNumber = new BN$2(v, 16).cmp(new BN$2(27)) !== -1
16233
- ? new BN$2(v, 16).sub(new BN$2(27)).toNumber()
16234
- : new BN$2(v, 16).toNumber();
16235
- return v.trim()
16236
- ? isValidBigNumber
16237
- : undefined;
16238
- }
16239
- // used chained with serializeEthSignature. serializeEthSignature(deserializeSignature(...))
16240
- function deserializeSignature(sig, size = 64) {
16241
- const removedHexPrefixSig = encUtils__namespace.removeHexPrefix(sig);
16242
- return {
16243
- r: new BN$2(removedHexPrefixSig.substring(0, size), 'hex'),
16244
- s: new BN$2(removedHexPrefixSig.substring(size, size * 2), 'hex'),
16245
- recoveryParam: importRecoveryParam(removedHexPrefixSig.substring(size * 2, size * 2 + 2)),
16246
- };
16247
- }
16248
- async function signRaw(payload, signer) {
16249
- const signature = deserializeSignature(await signer.signMessage(payload));
16250
- return serializeEthSignature(signature);
16251
- }
16252
- async function signMessage$1(message, signer) {
16253
- const ethAddress = await signer.getAddress();
16254
- const ethSignature = await signRaw(message, signer);
16255
- return {
16256
- message,
16257
- ethAddress,
16258
- ethSignature,
16259
- };
16260
- }
16261
-
16262
- /**
16263
- * Helper method to convert token type to a SignableToken type
16264
- * @param token - the token type to convert to a SignableToken type
16265
- * @returns the converted SignableToken
16266
- */
16267
- function convertToSignableToken(token) {
16268
- switch (token.type) {
16269
- case 'ERC721':
16270
- return {
16271
- type: 'ERC721',
16272
- data: {
16273
- token_id: token.tokenId,
16274
- token_address: token.tokenAddress,
16275
- },
16276
- };
16277
- case 'ERC20':
16278
- return {
16279
- type: 'ERC20',
16280
- data: {
16281
- token_address: token.tokenAddress,
16282
- },
16283
- };
16284
- case 'ETH':
16285
- default:
16286
- return {
16287
- type: 'ETH',
16288
- data: {
16289
- decimals: 18,
16290
- },
16291
- };
16292
- }
16293
- }
16294
-
16295
16296
  var PassportErrorType;
16296
16297
  (function (PassportErrorType) {
16297
16298
  PassportErrorType["AUTHENTICATION_ERROR"] = "AUTHENTICATION_ERROR";
@@ -16536,29 +16537,54 @@ class AuthManager {
16536
16537
  },
16537
16538
  });
16538
16539
  };
16539
- async login() {
16540
+ /**
16541
+ * login
16542
+ * @param anonymousId Caller can pass an anonymousId if they want to associate their user's identity with immutable's internal instrumentation.
16543
+ */
16544
+ async login(anonymousId) {
16540
16545
  return withPassportError(async () => {
16546
+ const rid = getDetail(Detail$1.RUNTIME_ID);
16541
16547
  const popupWindowFeatures = { width: 410, height: 450 };
16542
16548
  const oidcUser = await this.userManager.signinPopup({
16549
+ extraQueryParams: {
16550
+ rid: rid || '',
16551
+ third_party_a_id: anonymousId || '',
16552
+ },
16543
16553
  popupWindowFeatures,
16544
16554
  });
16545
16555
  return AuthManager.mapOidcUserToDomainModel(oidcUser);
16546
16556
  }, PassportErrorType.AUTHENTICATION_ERROR);
16547
16557
  }
16558
+ async getUserOrLogin() {
16559
+ let user = null;
16560
+ try {
16561
+ user = await this.getUser();
16562
+ }
16563
+ catch (err) {
16564
+ // eslint-disable-next-line no-console
16565
+ console.warn('failed to retrieve a cached user session:', err);
16566
+ }
16567
+ return user || this.login();
16568
+ }
16548
16569
  async loginCallback() {
16549
16570
  return withPassportError(async () => this.userManager.signinPopupCallback(), PassportErrorType.AUTHENTICATION_ERROR);
16550
16571
  }
16551
- async loginWithDeviceFlow() {
16572
+ /**
16573
+ * loginWithDeviceFlow
16574
+ * @param anonymousId Caller can pass an anonymousId if they want to associate their user's identity with immutable's internal instrumentation.
16575
+ */
16576
+ async loginWithDeviceFlow(anonymousId) {
16552
16577
  return withPassportError(async () => {
16553
16578
  const response = await globalAxios$1.post(`${this.config.authenticationDomain}/oauth/device/code`, {
16554
16579
  client_id: this.config.oidcConfiguration.clientId,
16555
16580
  scope: this.config.oidcConfiguration.scope,
16556
16581
  audience: this.config.oidcConfiguration.audience,
16557
16582
  }, formUrlEncodedHeader);
16583
+ const rid = getDetail(Detail$1.RUNTIME_ID);
16558
16584
  return {
16559
16585
  code: response.data.user_code,
16560
16586
  deviceCode: response.data.device_code,
16561
- url: response.data.verification_uri_complete,
16587
+ url: `${response.data.verification_uri_complete}${rid ? `&rid=${rid}` : ''}${anonymousId ? `&third_party_a_id=${anonymousId}` : ''}`,
16562
16588
  interval: response.data.interval,
16563
16589
  };
16564
16590
  }, PassportErrorType.AUTHENTICATION_ERROR);
@@ -16792,227 +16818,6 @@ const getStarkSigner = async (signer) => withPassportError(async () => {
16792
16818
  return coreSdk.createStarkSigner(privateKey);
16793
16819
  }, PassportErrorType.WALLET_CONNECTION_ERROR);
16794
16820
 
16795
- const POLL_INTERVAL = 1 * 1000; // every 1 second
16796
- const MAX_RETRIES = 3;
16797
- const wait = (ms) => new Promise((resolve) => {
16798
- setTimeout(() => resolve(), ms);
16799
- });
16800
- const retryWithDelay = async (fn, options) => {
16801
- const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
16802
- try {
16803
- return await fn();
16804
- }
16805
- catch (err) {
16806
- if (retries <= 0) {
16807
- return Promise.reject(finalErr);
16808
- }
16809
- await wait(interval);
16810
- return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
16811
- }
16812
- finally {
16813
- if (retries <= 0) {
16814
- finallyFn();
16815
- }
16816
- }
16817
- };
16818
-
16819
- /**
16820
- * ProviderErrors should take priority over RpcErrorCodes
16821
- * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
16822
- * https://eips.ethereum.org/EIPS/eip-1474#error-codes
16823
- */
16824
- var ProviderErrorCode;
16825
- (function (ProviderErrorCode) {
16826
- ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
16827
- ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
16828
- ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
16829
- ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
16830
- })(ProviderErrorCode || (ProviderErrorCode = {}));
16831
- var RpcErrorCode;
16832
- (function (RpcErrorCode) {
16833
- RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
16834
- RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
16835
- RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
16836
- RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
16837
- RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
16838
- RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
16839
- RpcErrorCode[RpcErrorCode["TRANSACTION_REJECTED"] = -32003] = "TRANSACTION_REJECTED";
16840
- })(RpcErrorCode || (RpcErrorCode = {}));
16841
- class JsonRpcError extends Error {
16842
- message;
16843
- code;
16844
- constructor(code, message) {
16845
- super(message);
16846
- this.message = message;
16847
- this.code = code;
16848
- }
16849
- }
16850
-
16851
- const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
16852
- + ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
16853
- const convertBigNumberishToString = (value) => ethers.BigNumber.from(value).toString();
16854
- const transformGuardianTransactions = (txs) => {
16855
- try {
16856
- return txs.map((t) => ({
16857
- delegateCall: t.delegateCall === true,
16858
- revertOnError: t.revertOnError === true,
16859
- gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
16860
- target: t.to ?? ethers.ethers.constants.AddressZero,
16861
- value: t.value ? convertBigNumberishToString(t.value) : '0',
16862
- data: t.data ? t.data.toString() : '0x',
16863
- }));
16864
- }
16865
- catch (error) {
16866
- const errorMessage = error instanceof Error ? error.message : String(error);
16867
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
16868
- }
16869
- };
16870
- class GuardianClient {
16871
- transactionAPI;
16872
- messageAPI;
16873
- confirmationScreen;
16874
- crossSdkBridgeEnabled;
16875
- authManager;
16876
- constructor({ confirmationScreen, config, authManager }) {
16877
- const guardianConfiguration = new Configuration({ basePath: config.imxPublicApiDomain });
16878
- this.confirmationScreen = confirmationScreen;
16879
- this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
16880
- this.messageAPI = new MessagesApi(guardianConfiguration);
16881
- this.transactionAPI = new TransactionsApi(guardianConfiguration);
16882
- this.authManager = authManager;
16883
- }
16884
- /**
16885
- * Open confirmation screen and close it automatically if the
16886
- * underlying task fails.
16887
- */
16888
- withConfirmationScreen(popupWindowSize) {
16889
- return (task) => this.withConfirmationScreenTask(popupWindowSize)(task)();
16890
- }
16891
- withConfirmationScreenTask(popupWindowSize) {
16892
- return (task) => async () => {
16893
- this.confirmationScreen.loading(popupWindowSize);
16894
- try {
16895
- return await task();
16896
- }
16897
- catch (err) {
16898
- this.confirmationScreen.closeWindow();
16899
- throw err;
16900
- }
16901
- };
16902
- }
16903
- withDefaultConfirmationScreenTask(task) {
16904
- return this.withConfirmationScreenTask()(task);
16905
- }
16906
- async evaluateImxTransaction({ payloadHash }) {
16907
- const finallyFn = () => {
16908
- this.confirmationScreen.closeWindow();
16909
- };
16910
- const user = await this.authManager.getUser();
16911
- const headers = { Authorization: `Bearer ${user.accessToken}` };
16912
- const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
16913
- transactionID: payloadHash,
16914
- chainType: 'starkex',
16915
- }, { headers }), { finallyFn });
16916
- if (!transactionRes.data.id) {
16917
- throw new Error("Transaction doesn't exists");
16918
- }
16919
- const evaluateImxRes = await this.transactionAPI.evaluateTransaction({
16920
- id: payloadHash,
16921
- transactionEvaluationRequest: {
16922
- chainType: 'starkex',
16923
- },
16924
- }, { headers });
16925
- const { confirmationRequired } = evaluateImxRes.data;
16926
- if (confirmationRequired) {
16927
- if (this.crossSdkBridgeEnabled) {
16928
- throw new Error(transactionRejectedCrossSdkBridgeError);
16929
- }
16930
- const confirmationResult = await this.confirmationScreen.requestConfirmation(payloadHash, user.imx.ethAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
16931
- if (!confirmationResult.confirmed) {
16932
- throw new Error('Transaction rejected by user');
16933
- }
16934
- }
16935
- else {
16936
- this.confirmationScreen.closeWindow();
16937
- }
16938
- }
16939
- async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
16940
- const user = await this.authManager.getUser();
16941
- const headers = { Authorization: `Bearer ${user.accessToken}` };
16942
- const guardianTransactions = transformGuardianTransactions(metaTransactions);
16943
- try {
16944
- const transactionEvaluationResponseAxiosResponse = await this.transactionAPI.evaluateTransaction({
16945
- id: 'evm',
16946
- transactionEvaluationRequest: {
16947
- chainType: 'evm',
16948
- chainId,
16949
- transactionData: {
16950
- nonce,
16951
- userAddress: user.zkEvm.ethAddress,
16952
- metaTransactions: guardianTransactions,
16953
- },
16954
- },
16955
- }, { headers });
16956
- return transactionEvaluationResponseAxiosResponse.data;
16957
- }
16958
- catch (error) {
16959
- const errorMessage = error instanceof Error ? error.message : String(error);
16960
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
16961
- }
16962
- }
16963
- async validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
16964
- const transactionEvaluationResponse = await this.evaluateEVMTransaction({
16965
- chainId,
16966
- nonce,
16967
- metaTransactions,
16968
- });
16969
- const { confirmationRequired, transactionId } = transactionEvaluationResponse;
16970
- if (confirmationRequired && this.crossSdkBridgeEnabled) {
16971
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
16972
- }
16973
- if (confirmationRequired && !!transactionId) {
16974
- const user = await this.authManager.getUser();
16975
- const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
16976
- if (!confirmationResult.confirmed) {
16977
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
16978
- }
16979
- }
16980
- else {
16981
- this.confirmationScreen.closeWindow();
16982
- }
16983
- }
16984
- async evaluateMessage({ chainID, payload }) {
16985
- try {
16986
- const user = await this.authManager.getUser();
16987
- if (user === null) {
16988
- throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
16989
- }
16990
- const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
16991
- return messageEvalResponse.data;
16992
- }
16993
- catch (error) {
16994
- const errorMessage = error instanceof Error ? error.message : String(error);
16995
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
16996
- }
16997
- }
16998
- async validateMessage({ chainID, payload }) {
16999
- const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload });
17000
- if (confirmationRequired && this.crossSdkBridgeEnabled) {
17001
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
17002
- }
17003
- if (confirmationRequired && !!messageId) {
17004
- const user = await this.authManager.getUser();
17005
- const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
17006
- if (!confirmationResult.confirmed) {
17007
- throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
17008
- }
17009
- }
17010
- else {
17011
- this.confirmationScreen.closeWindow();
17012
- }
17013
- }
17014
- }
17015
-
17016
16821
  var PassportEvents;
17017
16822
  (function (PassportEvents) {
17018
16823
  PassportEvents["LOGGED_OUT"] = "loggedOut";
@@ -17311,6 +17116,30 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
17311
17116
  }), PassportErrorType.TRANSFER_ERROR);
17312
17117
  }
17313
17118
 
17119
+ const POLL_INTERVAL = 1 * 1000; // every 1 second
17120
+ const MAX_RETRIES = 3;
17121
+ const wait = (ms) => new Promise((resolve) => {
17122
+ setTimeout(() => resolve(), ms);
17123
+ });
17124
+ const retryWithDelay = async (fn, options) => {
17125
+ const { retries = MAX_RETRIES, interval = POLL_INTERVAL, finalErr = Error('Retry failed'), finallyFn = () => { }, } = options || {};
17126
+ try {
17127
+ return await fn();
17128
+ }
17129
+ catch (err) {
17130
+ if (retries <= 0) {
17131
+ return Promise.reject(finalErr);
17132
+ }
17133
+ await wait(interval);
17134
+ return retryWithDelay(fn, { retries: retries - 1, finalErr, finallyFn });
17135
+ }
17136
+ finally {
17137
+ if (retries <= 0) {
17138
+ finallyFn();
17139
+ }
17140
+ }
17141
+ };
17142
+
17314
17143
  async function forceUserRefresh(authManager) {
17315
17144
  // User metadata is updated asynchronously. Poll userinfo endpoint until it is updated.
17316
17145
  await retryWithDelay(async () => {
@@ -17356,16 +17185,12 @@ class PassportImxProvider {
17356
17185
  */
17357
17186
  signers;
17358
17187
  signerInitialisationError;
17359
- constructor({ authManager, immutableXClient, confirmationScreen, config, passportEventEmitter, magicAdapter, imxApiClients, }) {
17188
+ constructor({ authManager, immutableXClient, passportEventEmitter, magicAdapter, imxApiClients, guardianClient, }) {
17360
17189
  this.authManager = authManager;
17361
17190
  this.immutableXClient = immutableXClient;
17362
- this.guardianClient = new GuardianClient({
17363
- confirmationScreen,
17364
- config,
17365
- authManager,
17366
- });
17367
17191
  this.magicAdapter = magicAdapter;
17368
17192
  this.imxApiClients = imxApiClients;
17193
+ this.guardianClient = guardianClient;
17369
17194
  this.initialiseSigners();
17370
17195
  passportEventEmitter.on(PassportEvents.LOGGED_OUT, this.handleLogout);
17371
17196
  }
@@ -17528,33 +17353,21 @@ class PassportImxProvider {
17528
17353
 
17529
17354
  class PassportImxProviderFactory {
17530
17355
  authManager;
17531
- config;
17532
- confirmationScreen;
17533
17356
  immutableXClient;
17534
17357
  magicAdapter;
17535
17358
  passportEventEmitter;
17536
17359
  imxApiClients;
17537
- constructor({ authManager, config, confirmationScreen, immutableXClient, magicAdapter, passportEventEmitter, imxApiClients, }) {
17360
+ guardianClient;
17361
+ constructor({ authManager, immutableXClient, magicAdapter, passportEventEmitter, imxApiClients, guardianClient, }) {
17538
17362
  this.authManager = authManager;
17539
- this.config = config;
17540
- this.confirmationScreen = confirmationScreen;
17541
17363
  this.immutableXClient = immutableXClient;
17542
17364
  this.magicAdapter = magicAdapter;
17543
17365
  this.passportEventEmitter = passportEventEmitter;
17544
17366
  this.imxApiClients = imxApiClients;
17367
+ this.guardianClient = guardianClient;
17545
17368
  }
17546
17369
  async getProvider() {
17547
- let user = null;
17548
- try {
17549
- user = await this.authManager.getUser();
17550
- }
17551
- catch (e) {
17552
- // eslint-disable-next-line no-console
17553
- console.warn(e);
17554
- }
17555
- if (!user) {
17556
- user = await this.authManager.login();
17557
- }
17370
+ const user = await this.authManager.getUserOrLogin();
17558
17371
  return this.createProviderInstance(user);
17559
17372
  }
17560
17373
  async getProviderSilent() {
@@ -17569,13 +17382,12 @@ class PassportImxProviderFactory {
17569
17382
  throw new PassportError('Failed to initialise', PassportErrorType.WALLET_CONNECTION_ERROR);
17570
17383
  }
17571
17384
  return new PassportImxProvider({
17572
- config: this.config,
17573
17385
  authManager: this.authManager,
17574
17386
  immutableXClient: this.immutableXClient,
17575
- confirmationScreen: this.confirmationScreen,
17576
17387
  passportEventEmitter: this.passportEventEmitter,
17577
17388
  magicAdapter: this.magicAdapter,
17578
17389
  imxApiClients: this.imxApiClients,
17390
+ guardianClient: this.guardianClient,
17579
17391
  });
17580
17392
  }
17581
17393
  }
@@ -18070,6 +17882,38 @@ class RelayerClient {
18070
17882
  }
18071
17883
  }
18072
17884
 
17885
+ /**
17886
+ * ProviderErrors should take priority over RpcErrorCodes
17887
+ * https://eips.ethereum.org/EIPS/eip-1193#provider-errors
17888
+ * https://eips.ethereum.org/EIPS/eip-1474#error-codes
17889
+ */
17890
+ var ProviderErrorCode;
17891
+ (function (ProviderErrorCode) {
17892
+ ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
17893
+ ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
17894
+ ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
17895
+ ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
17896
+ })(ProviderErrorCode || (ProviderErrorCode = {}));
17897
+ var RpcErrorCode;
17898
+ (function (RpcErrorCode) {
17899
+ RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
17900
+ RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
17901
+ RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
17902
+ RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
17903
+ RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
17904
+ RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
17905
+ RpcErrorCode[RpcErrorCode["TRANSACTION_REJECTED"] = -32003] = "TRANSACTION_REJECTED";
17906
+ })(RpcErrorCode || (RpcErrorCode = {}));
17907
+ class JsonRpcError extends Error {
17908
+ message;
17909
+ code;
17910
+ constructor(code, message) {
17911
+ super(message);
17912
+ this.message = message;
17913
+ this.code = code;
17914
+ }
17915
+ }
17916
+
18073
17917
  const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
18074
17918
  async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, jsonRpcProvider, }) {
18075
17919
  const web3Provider = new providers.Web3Provider(magicProvider);
@@ -18104,17 +17948,7 @@ async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiCli
18104
17948
  }
18105
17949
 
18106
17950
  const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients, jsonRpcProvider, }) => {
18107
- let user = null;
18108
- try {
18109
- user = await authManager.getUser();
18110
- }
18111
- catch (err) {
18112
- // eslint-disable-next-line no-console
18113
- console.warn('eth_requestAccounts` failed to retrieve a cached user session:', err);
18114
- }
18115
- if (!user) {
18116
- user = await authManager.login();
18117
- }
17951
+ const user = await authManager.getUserOrLogin();
18118
17952
  if (!user.idToken) {
18119
17953
  throw new Error('User is missing idToken');
18120
17954
  }
@@ -18139,6 +17973,171 @@ const loginZkEvmUser = async ({ authManager, magicAdapter, multiRollupApiClients
18139
17973
  };
18140
17974
  };
18141
17975
 
17976
+ const transactionRejectedCrossSdkBridgeError = 'Transaction requires confirmation but this functionality is not'
17977
+ + ' supported in this environment. Please contact Immutable support if you need to enable this feature.';
17978
+ const convertBigNumberishToString = (value) => ethers.BigNumber.from(value).toString();
17979
+ const transformGuardianTransactions = (txs) => {
17980
+ try {
17981
+ return txs.map((t) => ({
17982
+ delegateCall: t.delegateCall === true,
17983
+ revertOnError: t.revertOnError === true,
17984
+ gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
17985
+ target: t.to ?? ethers.ethers.constants.AddressZero,
17986
+ value: t.value ? convertBigNumberishToString(t.value) : '0',
17987
+ data: t.data ? t.data.toString() : '0x',
17988
+ }));
17989
+ }
17990
+ catch (error) {
17991
+ const errorMessage = error instanceof Error ? error.message : String(error);
17992
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
17993
+ }
17994
+ };
17995
+ class GuardianClient {
17996
+ transactionAPI;
17997
+ messageAPI;
17998
+ confirmationScreen;
17999
+ crossSdkBridgeEnabled;
18000
+ authManager;
18001
+ constructor({ confirmationScreen, config, authManager }) {
18002
+ const guardianConfiguration = new Configuration({ basePath: config.imxPublicApiDomain });
18003
+ this.confirmationScreen = confirmationScreen;
18004
+ this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
18005
+ this.messageAPI = new MessagesApi(guardianConfiguration);
18006
+ this.transactionAPI = new TransactionsApi(guardianConfiguration);
18007
+ this.authManager = authManager;
18008
+ }
18009
+ /**
18010
+ * Open confirmation screen and close it automatically if the
18011
+ * underlying task fails.
18012
+ */
18013
+ withConfirmationScreen(popupWindowSize) {
18014
+ return (task) => this.withConfirmationScreenTask(popupWindowSize)(task)();
18015
+ }
18016
+ withConfirmationScreenTask(popupWindowSize) {
18017
+ return (task) => async () => {
18018
+ this.confirmationScreen.loading(popupWindowSize);
18019
+ try {
18020
+ return await task();
18021
+ }
18022
+ catch (err) {
18023
+ this.confirmationScreen.closeWindow();
18024
+ throw err;
18025
+ }
18026
+ };
18027
+ }
18028
+ withDefaultConfirmationScreenTask(task) {
18029
+ return this.withConfirmationScreenTask()(task);
18030
+ }
18031
+ async evaluateImxTransaction({ payloadHash }) {
18032
+ const finallyFn = () => {
18033
+ this.confirmationScreen.closeWindow();
18034
+ };
18035
+ const user = await this.authManager.getUser();
18036
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
18037
+ const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
18038
+ transactionID: payloadHash,
18039
+ chainType: 'starkex',
18040
+ }, { headers }), { finallyFn });
18041
+ if (!transactionRes.data.id) {
18042
+ throw new Error("Transaction doesn't exists");
18043
+ }
18044
+ const evaluateImxRes = await this.transactionAPI.evaluateTransaction({
18045
+ id: payloadHash,
18046
+ transactionEvaluationRequest: {
18047
+ chainType: 'starkex',
18048
+ },
18049
+ }, { headers });
18050
+ const { confirmationRequired } = evaluateImxRes.data;
18051
+ if (confirmationRequired) {
18052
+ if (this.crossSdkBridgeEnabled) {
18053
+ throw new Error(transactionRejectedCrossSdkBridgeError);
18054
+ }
18055
+ const confirmationResult = await this.confirmationScreen.requestConfirmation(payloadHash, user.imx.ethAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
18056
+ if (!confirmationResult.confirmed) {
18057
+ throw new Error('Transaction rejected by user');
18058
+ }
18059
+ }
18060
+ else {
18061
+ this.confirmationScreen.closeWindow();
18062
+ }
18063
+ }
18064
+ async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
18065
+ const user = await this.authManager.getUser();
18066
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
18067
+ const guardianTransactions = transformGuardianTransactions(metaTransactions);
18068
+ try {
18069
+ const transactionEvaluationResponseAxiosResponse = await this.transactionAPI.evaluateTransaction({
18070
+ id: 'evm',
18071
+ transactionEvaluationRequest: {
18072
+ chainType: 'evm',
18073
+ chainId,
18074
+ transactionData: {
18075
+ nonce,
18076
+ userAddress: user.zkEvm.ethAddress,
18077
+ metaTransactions: guardianTransactions,
18078
+ },
18079
+ },
18080
+ }, { headers });
18081
+ return transactionEvaluationResponseAxiosResponse.data;
18082
+ }
18083
+ catch (error) {
18084
+ const errorMessage = error instanceof Error ? error.message : String(error);
18085
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
18086
+ }
18087
+ }
18088
+ async validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
18089
+ const transactionEvaluationResponse = await this.evaluateEVMTransaction({
18090
+ chainId,
18091
+ nonce,
18092
+ metaTransactions,
18093
+ });
18094
+ const { confirmationRequired, transactionId } = transactionEvaluationResponse;
18095
+ if (confirmationRequired && this.crossSdkBridgeEnabled) {
18096
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
18097
+ }
18098
+ if (confirmationRequired && !!transactionId) {
18099
+ const user = await this.authManager.getUser();
18100
+ const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
18101
+ if (!confirmationResult.confirmed) {
18102
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
18103
+ }
18104
+ }
18105
+ else {
18106
+ this.confirmationScreen.closeWindow();
18107
+ }
18108
+ }
18109
+ async evaluateMessage({ chainID, payload }) {
18110
+ try {
18111
+ const user = await this.authManager.getUser();
18112
+ if (user === null) {
18113
+ throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
18114
+ }
18115
+ const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
18116
+ return messageEvalResponse.data;
18117
+ }
18118
+ catch (error) {
18119
+ const errorMessage = error instanceof Error ? error.message : String(error);
18120
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
18121
+ }
18122
+ }
18123
+ async validateMessage({ chainID, payload }) {
18124
+ const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload });
18125
+ if (confirmationRequired && this.crossSdkBridgeEnabled) {
18126
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
18127
+ }
18128
+ if (confirmationRequired && !!messageId) {
18129
+ const user = await this.authManager.getUser();
18130
+ const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
18131
+ if (!confirmationResult.confirmed) {
18132
+ throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
18133
+ }
18134
+ }
18135
+ else {
18136
+ this.confirmationScreen.closeWindow();
18137
+ }
18138
+ }
18139
+ }
18140
+
18142
18141
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
18143
18142
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
18144
18143
  const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddress, signer, relayerClient) => {
@@ -18283,7 +18282,6 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
18283
18282
  class ZkEvmProvider {
18284
18283
  authManager;
18285
18284
  config;
18286
- confirmationScreen;
18287
18285
  magicAdapter;
18288
18286
  multiRollupApiClients;
18289
18287
  jsonRpcProvider; // Used for read
@@ -18293,11 +18291,11 @@ class ZkEvmProvider {
18293
18291
  magicProvider; // Used for signing
18294
18292
  zkevmAddress;
18295
18293
  isPassport = true;
18296
- constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, passportEventEmitter, }) {
18294
+ constructor({ authManager, magicAdapter, config, multiRollupApiClients, passportEventEmitter, guardianClient, }) {
18297
18295
  this.authManager = authManager;
18298
18296
  this.magicAdapter = magicAdapter;
18299
18297
  this.config = config;
18300
- this.confirmationScreen = confirmationScreen;
18298
+ this.guardianClient = guardianClient;
18301
18299
  if (config.crossSdkBridgeEnabled) {
18302
18300
  // JsonRpcProvider by default sets the referrer as "client".
18303
18301
  // On Unreal 4 this errors as the browser used is expecting a valid URL.
@@ -18317,7 +18315,6 @@ class ZkEvmProvider {
18317
18315
  const shouldEmitAccountsChanged = this.isLoggedIn();
18318
18316
  this.magicProvider = undefined;
18319
18317
  this.relayerClient = undefined;
18320
- this.guardianClient = undefined;
18321
18318
  if (shouldEmitAccountsChanged) {
18322
18319
  this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, []);
18323
18320
  }
@@ -18325,8 +18322,7 @@ class ZkEvmProvider {
18325
18322
  isLoggedIn() {
18326
18323
  return this.magicProvider !== undefined
18327
18324
  && this.zkevmAddress !== undefined
18328
- && this.relayerClient !== undefined
18329
- && this.guardianClient !== undefined;
18325
+ && this.relayerClient !== undefined;
18330
18326
  }
18331
18327
  async performRequest(request) {
18332
18328
  switch (request.method) {
@@ -18336,7 +18332,6 @@ class ZkEvmProvider {
18336
18332
  }
18337
18333
  const { magicProvider, user } = await loginZkEvmUser({
18338
18334
  authManager: this.authManager,
18339
- config: this.config,
18340
18335
  magicAdapter: this.magicAdapter,
18341
18336
  multiRollupApiClients: this.multiRollupApiClients,
18342
18337
  jsonRpcProvider: this.jsonRpcProvider,
@@ -18347,11 +18342,6 @@ class ZkEvmProvider {
18347
18342
  jsonRpcProvider: this.jsonRpcProvider,
18348
18343
  authManager: this.authManager,
18349
18344
  });
18350
- this.guardianClient = new GuardianClient({
18351
- confirmationScreen: this.confirmationScreen,
18352
- config: this.config,
18353
- authManager: this.authManager,
18354
- });
18355
18345
  this.zkevmAddress = user.zkEvm.ethAddress;
18356
18346
  this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [user.zkEvm.ethAddress]);
18357
18347
  return [user.zkEvm.ethAddress];
@@ -18530,15 +18520,19 @@ const buildPrivateVars = (passportModuleConfiguration) => {
18530
18520
  const immutableXClient = passportModuleConfiguration.overrides
18531
18521
  ? passportModuleConfiguration.overrides.immutableXClient
18532
18522
  : new IMXClient({ baseConfig: passportModuleConfiguration.baseConfig });
18523
+ const guardianClient = new GuardianClient({
18524
+ confirmationScreen,
18525
+ config,
18526
+ authManager,
18527
+ });
18533
18528
  const imxApiClients = buildImxApiClients(passportModuleConfiguration);
18534
18529
  const passportImxProviderFactory = new PassportImxProviderFactory({
18535
18530
  authManager,
18536
- config,
18537
- confirmationScreen,
18538
18531
  immutableXClient,
18539
18532
  magicAdapter,
18540
18533
  passportEventEmitter,
18541
18534
  imxApiClients,
18535
+ guardianClient,
18542
18536
  });
18543
18537
  return {
18544
18538
  config,
@@ -18549,6 +18543,7 @@ const buildPrivateVars = (passportModuleConfiguration) => {
18549
18543
  multiRollupApiClients,
18550
18544
  passportEventEmitter,
18551
18545
  passportImxProviderFactory,
18546
+ guardianClient,
18552
18547
  };
18553
18548
  };
18554
18549
  class Passport {
@@ -18560,6 +18555,7 @@ class Passport {
18560
18555
  multiRollupApiClients;
18561
18556
  passportImxProviderFactory;
18562
18557
  passportEventEmitter;
18558
+ guardianClient;
18563
18559
  constructor(passportModuleConfiguration) {
18564
18560
  const privateVars = buildPrivateVars(passportModuleConfiguration);
18565
18561
  this.config = privateVars.config;
@@ -18570,6 +18566,7 @@ class Passport {
18570
18566
  this.multiRollupApiClients = privateVars.multiRollupApiClients;
18571
18567
  this.passportEventEmitter = privateVars.passportEventEmitter;
18572
18568
  this.passportImxProviderFactory = privateVars.passportImxProviderFactory;
18569
+ this.guardianClient = privateVars.guardianClient;
18573
18570
  setPassportClientId(passportModuleConfiguration.clientId);
18574
18571
  track('passport', 'initialised');
18575
18572
  }
@@ -18589,8 +18586,8 @@ class Passport {
18589
18586
  authManager: this.authManager,
18590
18587
  magicAdapter: this.magicAdapter,
18591
18588
  config: this.config,
18592
- confirmationScreen: this.confirmationScreen,
18593
18589
  multiRollupApiClients: this.multiRollupApiClients,
18590
+ guardianClient: this.guardianClient,
18594
18591
  });
18595
18592
  }
18596
18593
  /**
@@ -37424,7 +37421,7 @@ const storeDetail = (key, value) => {
37424
37421
  };
37425
37422
  setItem(Store.RUNTIME, RUNTIME_DETAILS);
37426
37423
  };
37427
- const getDetail = (key) => {
37424
+ const getDetail$1 = (key) => {
37428
37425
  // Handle the scenario where detail is a falsy value
37429
37426
  if (RUNTIME_DETAILS[key] === undefined) {
37430
37427
  return undefined;
@@ -37456,7 +37453,7 @@ const flattenProperties = (properties) => {
37456
37453
  };
37457
37454
 
37458
37455
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
37459
- const SDK_VERSION = '1.6.0';
37456
+ const SDK_VERSION = '1.7.0';
37460
37457
  const getReferrer = () => {
37461
37458
  if (isNode()) {
37462
37459
  return '';
@@ -37499,7 +37496,7 @@ const initialise = async () => {
37499
37496
  initialised = true;
37500
37497
  try {
37501
37498
  const runtimeDetails = flattenProperties(getRuntimeDetails());
37502
- const existingRuntimeId = getDetail(Detail.RUNTIME_ID);
37499
+ const existingRuntimeId = getDetail$1(Detail.RUNTIME_ID);
37503
37500
  const body = {
37504
37501
  version: 1,
37505
37502
  data: {
@@ -37631,6 +37628,7 @@ const setPublishableApiKeyFn = (publishableApiKey) => {
37631
37628
  storeDetail(Detail.PUBLISHABLE_API_KEY, publishableApiKey);
37632
37629
  };
37633
37630
  errorBoundary(getGlobalisedValue('setPublishableApiKey', setPublishableApiKeyFn));
37631
+ errorBoundary(getGlobalisedValue('getDetail', getDetail$1));
37634
37632
 
37635
37633
  var Environment;
37636
37634
  (function (Environment) {
@@ -42623,7 +42621,7 @@ const IMMUTABLE_ZKVEM_GAS_OVERRIDES = {
42623
42621
  maxPriorityFeePerGas: ethers.BigNumber.from(10e9),
42624
42622
  };
42625
42623
 
42626
- const SDK_VERSION_MARKER = '1.6.0';
42624
+ const SDK_VERSION_MARKER = '1.7.0';
42627
42625
  // This SDK version is replaced by the `yarn build` command ran on the root level
42628
42626
  const globalPackageVersion = () => SDK_VERSION_MARKER;
42629
42627
 
@@ -46137,13 +46135,15 @@ class FiatRampService {
46137
46135
  const productsAvailed = 'productsAvailed=buy';
46138
46136
  const exchangeScreenTitle = 'exchangeScreenTitle=Buy';
46139
46137
  const themeColor = 'themeColor=0D0D0D';
46138
+ const defaultFiat = 'defaultFiatAmount=50&defaultFiatCurrency=usd';
46140
46139
  widgetUrl += `${transakPublishableKey}&`
46141
46140
  + `${zkevmNetwork}&`
46142
46141
  + `${defaultPaymentMethod}&`
46143
46142
  + `${disableBankTransfer}&`
46144
46143
  + `${productsAvailed}&`
46145
46144
  + `${exchangeScreenTitle}&`
46146
- + `${themeColor}`;
46145
+ + `${themeColor}&`
46146
+ + `${defaultFiat}`;
46147
46147
  if (params.isPassport && params.email) {
46148
46148
  const encodedEmail = encodeURIComponent(params.email);
46149
46149
  widgetUrl += `&email=${encodedEmail}&isAutoFillUserData=true&disableWalletAddressForm=true`;
@@ -46157,6 +46157,9 @@ class FiatRampService {
46157
46157
  if (params.walletAddress) {
46158
46158
  widgetUrl += `&walletAddress=${params.walletAddress}`;
46159
46159
  }
46160
+ if (params.allowedTokens) {
46161
+ widgetUrl += `&cryptoCurrencyList=${params.allowedTokens?.join(',').toLowerCase()}`;
46162
+ }
46160
46163
  return widgetUrl;
46161
46164
  }
46162
46165
  }
@@ -46603,6 +46606,7 @@ class Checkout {
46603
46606
  tokenAmount = params.tokenAmount;
46604
46607
  tokenSymbol = token.symbol;
46605
46608
  }
46609
+ const allowedTokens = tokenList?.tokens?.filter((t) => t.symbol).map((t) => t.symbol);
46606
46610
  return await this.fiatRampService.createWidgetUrl({
46607
46611
  exchangeType: params.exchangeType,
46608
46612
  isPassport,
@@ -46610,6 +46614,7 @@ class Checkout {
46610
46614
  tokenAmount,
46611
46615
  tokenSymbol,
46612
46616
  email,
46617
+ allowedTokens,
46613
46618
  });
46614
46619
  }
46615
46620
  /**