@imtbl/sdk 0.4.0-alpha.3 → 0.4.1-alpha

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
@@ -3,13 +3,14 @@ import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner, T
3
3
  export { createStarkSigner as imxClientCreateStarkSigner, generateLegacyStarkPrivateKey as imxClientGenerateLegacyStarkPrivateKey } from '@imtbl/core-sdk';
4
4
  import { UserManager } from 'oidc-client-ts';
5
5
  import jwt_decode from 'jwt-decode';
6
+ import * as crypto from 'crypto';
6
7
  import { Magic } from 'magic-sdk';
7
8
  import { OpenIdExtension } from '@magic-ext/oidc';
9
+ import { BigNumber as BigNumber$1, ethers, providers, constants, utils as utils$2, Contract as Contract$1, ContractFactory } from 'ethers';
8
10
  import BN$2 from 'bn.js';
9
11
  import * as encUtils from 'enc-utils';
10
12
  import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
11
13
  import { EventEmitter } from 'events';
12
- import { ethers, BigNumber as BigNumber$1, providers, constants, utils as utils$2, Contract as Contract$1, ContractFactory } from 'ethers';
13
14
  import { walletContracts } from '@0xsequence/abi';
14
15
  import { encodeSignature } from '@0xsequence/config';
15
16
  import FormData$2 from 'form-data';
@@ -5531,7 +5532,7 @@ class MultiRollupApiClients {
5531
5532
  }
5532
5533
 
5533
5534
  // eslint-disable-next-line @typescript-eslint/naming-convention
5534
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.4.0-alpha.3' };
5535
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-0.4.1-alpha' };
5535
5536
  const createConfig = ({ basePath, headers, }) => {
5536
5537
  if (!basePath.trim()) {
5537
5538
  throw Error('basePath can not be empty');
@@ -5591,7 +5592,7 @@ class APIError extends Error {
5591
5592
 
5592
5593
  /* eslint-disable implicit-arrow-linebreak */
5593
5594
  const defaultHeaders = {
5594
- sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.4.0-alpha.3',
5595
+ sdkVersion: 'ts-immutable-sdk-multi-rollup-api-client-0.4.1-alpha',
5595
5596
  };
5596
5597
  /**
5597
5598
  * createAPIConfiguration to create a custom Configuration
@@ -5857,7 +5858,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
5857
5858
  chainID,
5858
5859
  coreContractAddress,
5859
5860
  registrationContractAddress,
5860
- sdkVersion: 'ts-immutable-sdk-0.4.0-alpha.3',
5861
+ sdkVersion: 'ts-immutable-sdk-0.4.1-alpha',
5861
5862
  });
5862
5863
  /**
5863
5864
  * Sets `sdkVersion` at the time of build
@@ -9581,8 +9582,6 @@ var globalAxios = axios;
9581
9582
  * https://openapi-generator.tech
9582
9583
  * Do not edit the class manually.
9583
9584
  */
9584
- // Some imports not used depending on template conditions
9585
- // @ts-ignore
9586
9585
  const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
9587
9586
  /**
9588
9587
  *
@@ -9610,10 +9609,10 @@ class BaseAPI {
9610
9609
  */
9611
9610
  class RequiredError extends Error {
9612
9611
  field;
9613
- name = "RequiredError";
9614
9612
  constructor(field, msg) {
9615
9613
  super(msg);
9616
9614
  this.field = field;
9615
+ this.name = "RequiredError";
9617
9616
  }
9618
9617
  }
9619
9618
 
@@ -9658,6 +9657,8 @@ const setBearerAuthToObject = async function (object, configuration) {
9658
9657
  }
9659
9658
  };
9660
9659
  function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
9660
+ if (parameter == null)
9661
+ return;
9661
9662
  if (typeof parameter === "object") {
9662
9663
  if (Array.isArray(parameter)) {
9663
9664
  parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
@@ -10028,6 +10029,24 @@ class Configuration {
10028
10029
  }
10029
10030
  }
10030
10031
 
10032
+ /* tslint:disable */
10033
+ /* eslint-disable */
10034
+ /**
10035
+ * Guardian
10036
+ * Guardian API
10037
+ *
10038
+ * The version of the OpenAPI document: 1.0.0
10039
+ * Contact: support@immutable.com
10040
+ *
10041
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
10042
+ * https://openapi-generator.tech
10043
+ * Do not edit the class manually.
10044
+ */
10045
+ const TransactionApprovalRequestChainTypeEnum = {
10046
+ Starkex: 'starkex',
10047
+ Evm: 'evm'
10048
+ };
10049
+
10031
10050
  // used to sign message with L1 keys. Used for registration
10032
10051
  function serializeEthSignature(sig) {
10033
10052
  // This is because golang appends a recovery param
@@ -10135,10 +10154,17 @@ const withPassportError = async (fn, customErrorType) => {
10135
10154
  };
10136
10155
 
10137
10156
  const keyCrendentials = 'passport_credentials';
10157
+ const KEY_PKCE_STATE = 'pkce_state';
10158
+ const KEY_PKCE_VERIFIER = 'pkce_verifier';
10138
10159
  const validCredentialsMinTtlSec = 3600; // 1 hour
10139
10160
  class DeviceCredentialsManager {
10140
10161
  saveCredentials(tokenResponse) {
10141
- localStorage.setItem(keyCrendentials, JSON.stringify(tokenResponse));
10162
+ if (this.areValid(tokenResponse)) {
10163
+ localStorage.setItem(keyCrendentials, JSON.stringify(tokenResponse));
10164
+ }
10165
+ else {
10166
+ throw Error('Invalid credentials.');
10167
+ }
10142
10168
  }
10143
10169
  getCredentials() {
10144
10170
  const credentialsJson = localStorage.getItem(keyCrendentials);
@@ -10156,14 +10182,31 @@ class DeviceCredentialsManager {
10156
10182
  return false;
10157
10183
  }
10158
10184
  isTokenValid(jwt) {
10159
- const tokenPayload = jwt_decode(jwt);
10160
- const expiresAt = tokenPayload.exp ?? 0;
10161
- const now = (Date.now() / 1000) + validCredentialsMinTtlSec;
10162
- return expiresAt > now;
10185
+ try {
10186
+ const tokenPayload = jwt_decode(jwt);
10187
+ const expiresAt = tokenPayload.exp ?? 0;
10188
+ const now = (Date.now() / 1000) + validCredentialsMinTtlSec;
10189
+ return expiresAt > now;
10190
+ }
10191
+ catch (error) {
10192
+ return false;
10193
+ }
10163
10194
  }
10164
10195
  clearCredentials() {
10165
10196
  localStorage.removeItem(keyCrendentials);
10166
10197
  }
10198
+ savePKCEData(data) {
10199
+ localStorage.setItem(KEY_PKCE_STATE, data.state);
10200
+ localStorage.setItem(KEY_PKCE_VERIFIER, data.verifier);
10201
+ }
10202
+ getPKCEData() {
10203
+ const state = localStorage.getItem(KEY_PKCE_STATE);
10204
+ const verifier = localStorage.getItem(KEY_PKCE_VERIFIER);
10205
+ if (state && verifier) {
10206
+ return { state, verifier };
10207
+ }
10208
+ return null;
10209
+ }
10167
10210
  }
10168
10211
 
10169
10212
  const formUrlEncodedHeader = {
@@ -10340,6 +10383,59 @@ class AuthManager {
10340
10383
  }, formUrlEncodedHeader);
10341
10384
  return response.data;
10342
10385
  }
10386
+ static base64URLEncode(str) {
10387
+ return str.toString('base64')
10388
+ .replace(/\+/g, '-')
10389
+ .replace(/\//g, '_')
10390
+ .replace(/=/g, '');
10391
+ }
10392
+ static sha256(buffer) {
10393
+ return crypto.createHash('sha256').update(buffer).digest();
10394
+ }
10395
+ getPKCEAuthorizationUrl() {
10396
+ const verifier = AuthManager.base64URLEncode(crypto.randomBytes(32));
10397
+ const challenge = AuthManager.base64URLEncode(AuthManager.sha256(verifier));
10398
+ // https://auth0.com/docs/secure/attack-protection/state-parameters
10399
+ const state = AuthManager.base64URLEncode(crypto.randomBytes(32));
10400
+ this.deviceCredentialsManager.savePKCEData({ state, verifier });
10401
+ return `${this.config.authenticationDomain}/authorize?`
10402
+ + 'response_type=code'
10403
+ + `&code_challenge=${challenge}`
10404
+ + '&code_challenge_method=S256'
10405
+ + `&client_id=${this.config.oidcConfiguration.clientId}`
10406
+ + `&redirect_uri=${this.config.oidcConfiguration.redirectUri}`
10407
+ + `&scope=${this.config.oidcConfiguration.scope}`
10408
+ + `&state=${state}`
10409
+ + `&audience=${this.config.oidcConfiguration.audience}`;
10410
+ }
10411
+ async connectImxPKCEFlow(authorizationCode, state) {
10412
+ return withPassportError(async () => {
10413
+ const pkceData = this.deviceCredentialsManager.getPKCEData();
10414
+ if (!pkceData) {
10415
+ throw new Error('No code verifier or state for PKCE');
10416
+ }
10417
+ if (state !== pkceData.state) {
10418
+ throw new Error('Provided state does not match stored state');
10419
+ }
10420
+ const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
10421
+ const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
10422
+ // Only persist credentials that contain the necessary data
10423
+ if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
10424
+ this.deviceCredentialsManager.saveCredentials(tokenResponse);
10425
+ }
10426
+ return user;
10427
+ }, PassportErrorType.AUTHENTICATION_ERROR);
10428
+ }
10429
+ async getPKCEToken(authorizationCode, codeVerifier) {
10430
+ const response = await axios$2.post(`${this.config.authenticationDomain}/oauth/token`, {
10431
+ client_id: this.config.oidcConfiguration.clientId,
10432
+ grant_type: 'authorization_code',
10433
+ code_verifier: codeVerifier,
10434
+ code: authorizationCode,
10435
+ redirect_uri: this.config.oidcConfiguration.redirectUri,
10436
+ }, formUrlEncodedHeader);
10437
+ return response.data;
10438
+ }
10343
10439
  async connectImxWithCredentials(tokenResponse) {
10344
10440
  return withPassportError(async () => {
10345
10441
  if (this.deviceCredentialsManager.areValid(tokenResponse)) {
@@ -10468,6 +10564,53 @@ const retryWithDelay = async (fn, options) => {
10468
10564
  }
10469
10565
  };
10470
10566
 
10567
+ /**
10568
+ * ProviderErrors should take priority over RpcErrorCodes
10569
+ */
10570
+ var ProviderErrorCode;
10571
+ (function (ProviderErrorCode) {
10572
+ ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
10573
+ ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
10574
+ ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
10575
+ ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
10576
+ })(ProviderErrorCode || (ProviderErrorCode = {}));
10577
+ var RpcErrorCode;
10578
+ (function (RpcErrorCode) {
10579
+ RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
10580
+ RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
10581
+ RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
10582
+ RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
10583
+ RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
10584
+ RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
10585
+ RpcErrorCode[RpcErrorCode["USER_REJECTED_REQUEST"] = -32003] = "USER_REJECTED_REQUEST";
10586
+ })(RpcErrorCode || (RpcErrorCode = {}));
10587
+ class JsonRpcError extends Error {
10588
+ message;
10589
+ code;
10590
+ constructor(code, message) {
10591
+ super(message);
10592
+ this.message = message;
10593
+ this.code = code;
10594
+ }
10595
+ }
10596
+
10597
+ const convertBigNumberishToString = (value) => BigNumber$1.from(value).toString();
10598
+ const transformGuardianTransactions = (txs) => {
10599
+ try {
10600
+ return txs.map((t) => ({
10601
+ delegateCall: t.delegateCall === true,
10602
+ revertOnError: t.revertOnError === true,
10603
+ gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
10604
+ target: t.to ?? ethers.constants.AddressZero,
10605
+ value: t.value ? convertBigNumberishToString(t.value) : '0',
10606
+ data: t.data ? t.data.toString() : '0x00',
10607
+ }));
10608
+ }
10609
+ catch (error) {
10610
+ const errorMessage = (error instanceof Error) ? error.message : String(error);
10611
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
10612
+ }
10613
+ };
10471
10614
  class GuardianClient {
10472
10615
  transactionAPI;
10473
10616
  confirmationScreen;
@@ -10502,7 +10645,7 @@ class GuardianClient {
10502
10645
  });
10503
10646
  const { confirmationRequired } = evaluateStarkexRes.data;
10504
10647
  if (confirmationRequired) {
10505
- const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress);
10648
+ const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
10506
10649
  if (!confirmationResult.confirmed) {
10507
10650
  throw new Error('Transaction rejected by user');
10508
10651
  }
@@ -10511,6 +10654,47 @@ class GuardianClient {
10511
10654
  this.confirmationScreen.closeWindow();
10512
10655
  }
10513
10656
  }
10657
+ async evaluateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
10658
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
10659
+ const guardianTransactions = transformGuardianTransactions(metaTransactions);
10660
+ try {
10661
+ const transactionEvaluationResponseAxiosResponse = await this.transactionAPI.evaluateTransaction({
10662
+ id: 'evm',
10663
+ transactionEvaluationRequest: {
10664
+ chainType: 'evm',
10665
+ chainId,
10666
+ transactionData: {
10667
+ nonce,
10668
+ userAddress: user.zkEvm.ethAddress,
10669
+ metaTransactions: guardianTransactions,
10670
+ },
10671
+ },
10672
+ }, { headers });
10673
+ return transactionEvaluationResponseAxiosResponse.data;
10674
+ }
10675
+ catch (error) {
10676
+ const errorMessage = (error instanceof Error) ? error.message : String(error);
10677
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
10678
+ }
10679
+ }
10680
+ async validateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
10681
+ const transactionEvaluationResponse = await this.evaluateEVMTransaction({
10682
+ chainId,
10683
+ nonce,
10684
+ user,
10685
+ metaTransactions,
10686
+ });
10687
+ const { confirmationRequired, transactionId } = transactionEvaluationResponse;
10688
+ if (confirmationRequired && !!transactionId) {
10689
+ const confirmationResult = await this.confirmationScreen.startGuardianTransaction(transactionId, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
10690
+ if (!confirmationResult.confirmed) {
10691
+ throw new JsonRpcError(RpcErrorCode.USER_REJECTED_REQUEST, 'Transaction rejected by user ');
10692
+ }
10693
+ }
10694
+ else {
10695
+ this.confirmationScreen.closeWindow();
10696
+ }
10697
+ }
10514
10698
  }
10515
10699
 
10516
10700
  async function exchangeTransfer$1({ user, starkSigner, request, exchangesApi, }) {
@@ -10949,6 +11133,10 @@ class PassportImxProviderFactory {
10949
11133
  const user = await this.authManager.connectImxDeviceFlow(deviceCode, interval, timeoutMs);
10950
11134
  return this.createProviderInstance(user);
10951
11135
  }
11136
+ async getProviderWithPKCEFlow(authorizationCode, state) {
11137
+ const user = await this.authManager.connectImxPKCEFlow(authorizationCode, state);
11138
+ return this.createProviderInstance(user);
11139
+ }
10952
11140
  async getProviderWithCredentials(tokenResponse) {
10953
11141
  const user = await this.authManager.connectImxWithCredentials(tokenResponse);
10954
11142
  if (!user) {
@@ -11212,7 +11400,7 @@ class ConfirmationScreen {
11212
11400
  }, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
11213
11401
  });
11214
11402
  }
11215
- startGuardianTransaction(transactionId, imxEtherAddress) {
11403
+ startGuardianTransaction(transactionId, imxEtherAddress, chainType, chainId) {
11216
11404
  return new Promise((resolve, reject) => {
11217
11405
  const messageHandler = ({ data, origin }) => {
11218
11406
  if (origin !== this.config.passportDomain
@@ -11241,7 +11429,16 @@ class ConfirmationScreen {
11241
11429
  return;
11242
11430
  }
11243
11431
  // eslint-disable-next-line max-len
11244
- this.confirmationWindow.location.href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
11432
+ let href = '';
11433
+ if (chainType === TransactionApprovalRequestChainTypeEnum.Starkex) {
11434
+ // eslint-disable-next-line max-len
11435
+ href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
11436
+ }
11437
+ else {
11438
+ // eslint-disable-next-line max-len
11439
+ href = `${this.config.passportDomain}/transaction-confirmation/zkevm?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=evm&chainId=${chainId}`;
11440
+ }
11441
+ this.confirmationWindow.location.href = href;
11245
11442
  // https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
11246
11443
  const timer = setInterval(() => {
11247
11444
  if (this.confirmationWindow?.closed) {
@@ -11349,35 +11546,6 @@ class RelayerClient {
11349
11546
  }
11350
11547
  }
11351
11548
 
11352
- /**
11353
- * ProviderErrors should take priority over RpcErrorCodes
11354
- */
11355
- var ProviderErrorCode;
11356
- (function (ProviderErrorCode) {
11357
- ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
11358
- ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
11359
- ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
11360
- ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
11361
- })(ProviderErrorCode || (ProviderErrorCode = {}));
11362
- var RpcErrorCode;
11363
- (function (RpcErrorCode) {
11364
- RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
11365
- RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
11366
- RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
11367
- RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
11368
- RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
11369
- RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
11370
- })(RpcErrorCode || (RpcErrorCode = {}));
11371
- class JsonRpcError extends Error {
11372
- message;
11373
- code;
11374
- constructor(code, message) {
11375
- super(message);
11376
- this.message = message;
11377
- this.code = code;
11378
- }
11379
- }
11380
-
11381
11549
  const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
11382
11550
  async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, }) {
11383
11551
  const web3Provider = new Web3Provider(magicProvider);
@@ -11505,46 +11673,9 @@ const chainIdNumber = (chainId) => {
11505
11673
 
11506
11674
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
11507
11675
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
11508
- const converBigNumberishToNumber = (value) => BigNumber$1.from(value).toNumber();
11509
- const transformGardianTransactions = (txs) => {
11510
- try {
11511
- return txs.map((t) => ({
11512
- delegateCall: t.delegateCall === true,
11513
- revertOnError: t.revertOnError === true,
11514
- gasLimit: t.gasLimit ? converBigNumberishToNumber(t.gasLimit).toString() : '0',
11515
- target: t.to ?? ethers.constants.AddressZero,
11516
- value: t.value ? converBigNumberishToNumber(t.value).toString() : '0',
11517
- data: t.data ? t.data.toString() : '0x00',
11518
- }));
11519
- }
11520
- catch (error) {
11521
- const errorMessage = (error instanceof Error) ? error.message : String(error);
11522
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
11523
- }
11524
- };
11525
- const guardianValidation = async ({ transactionAPI, chainId, nonce, user, metaTransactions, }) => {
11526
- const headers = { Authorization: `Bearer ${user.accessToken}` };
11527
- const guardianTransactions = transformGardianTransactions(metaTransactions);
11528
- try {
11529
- await transactionAPI.evaluateTransaction({
11530
- id: 'evm',
11531
- transactionEvaluationRequest: {
11532
- chainType: 'evm',
11533
- chainId,
11534
- transactionData: {
11535
- nonce,
11536
- userAddress: user.zkEvm.ethAddress,
11537
- metaTransactions: guardianTransactions,
11538
- },
11539
- },
11540
- }, { headers });
11541
- }
11542
- catch (error) {
11543
- const errorMessage = (error instanceof Error) ? error.message : String(error);
11544
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
11545
- }
11546
- };
11547
- const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, transactionAPI, config, user, }) => {
11676
+ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => {
11677
+ const popupWindowSize = { width: 480, height: 580 };
11678
+ guardianClient.loading(popupWindowSize);
11548
11679
  const transactionRequest = params[0];
11549
11680
  if (!transactionRequest.to) {
11550
11681
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
@@ -11582,10 +11713,9 @@ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayer
11582
11713
  value: imxFeeOption.tokenPrice,
11583
11714
  revertOnError: true,
11584
11715
  };
11585
- await guardianValidation({
11586
- transactionAPI,
11716
+ await guardianClient.validateEVMTransaction({
11587
11717
  chainId: config.zkEvmChainId,
11588
- nonce: converBigNumberishToNumber(nonce),
11718
+ nonce: convertBigNumberishToString(nonce),
11589
11719
  user,
11590
11720
  metaTransactions: [metaTransaction, feeMetaTransaction],
11591
11721
  });
@@ -11665,10 +11795,16 @@ class ZkEvmProvider {
11665
11795
  if (!this.isLoggedIn()) {
11666
11796
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
11667
11797
  }
11798
+ const guardianClient = new GuardianClient({
11799
+ imxPublicApiDomain: this.config.imxPublicApiDomain,
11800
+ accessToken: this.user.accessToken,
11801
+ confirmationScreen: this.confirmationScreen,
11802
+ imxEtherAddress: this.user?.imx?.ethAddress || '',
11803
+ });
11668
11804
  return sendTransaction({
11669
11805
  params: request.params || [],
11670
11806
  magicProvider: this.magicProvider,
11671
- transactionAPI: this.transactionAPI,
11807
+ guardianClient,
11672
11808
  jsonRpcProvider: this.jsonRpcProvider,
11673
11809
  config: this.config,
11674
11810
  relayerClient: this.relayerClient,
@@ -11834,6 +11970,12 @@ class Passport {
11834
11970
  async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
11835
11971
  return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
11836
11972
  }
11973
+ getPKCEAuthorizationUrl() {
11974
+ return this.authManager.getPKCEAuthorizationUrl();
11975
+ }
11976
+ async connectImxPKCEFlow(authorizationCode, state) {
11977
+ return this.passportImxProviderFactory.getProviderWithPKCEFlow(authorizationCode, state);
11978
+ }
11837
11979
  /**
11838
11980
  * @returns {boolean} the stored device flow credentials if they exist
11839
11981
  */
@@ -28699,7 +28841,7 @@ class $a8cb37a3fc8eb863$export$1f60ba4ec72508a0 {
28699
28841
  function $parcel$export(e, n, v, s) {
28700
28842
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
28701
28843
  }
28702
- const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.4.0-alpha.3";
28844
+ const $d663162fd5a0853f$export$38a083d9fb5551ca = "0.4.1-alpha";
28703
28845
  const $d663162fd5a0853f$export$83bf90b30cdfd29f = ()=>false;
28704
28846
  const $d663162fd5a0853f$export$1169f5475725171b = ()=>$d663162fd5a0853f$export$38a083d9fb5551ca;
28705
28847