@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/passport.js CHANGED
@@ -2,13 +2,14 @@ import { ImmutableX, Config, generateLegacyStarkPrivateKey, createStarkSigner }
2
2
  import { UserManager } from 'oidc-client-ts';
3
3
  import axios$2 from 'axios';
4
4
  import jwt_decode from 'jwt-decode';
5
+ import * as crypto from 'crypto';
5
6
  import { Magic } from 'magic-sdk';
6
7
  import { OpenIdExtension } from '@magic-ext/oidc';
8
+ import { BigNumber, ethers } from 'ethers';
7
9
  import BN from 'bn.js';
8
10
  import * as encUtils from 'enc-utils';
9
11
  import { Web3Provider, JsonRpcProvider } from '@ethersproject/providers';
10
12
  import { EventEmitter } from 'events';
11
- import { ethers, BigNumber } from 'ethers';
12
13
  import { walletContracts } from '@0xsequence/abi';
13
14
  import { encodeSignature } from '@0xsequence/config';
14
15
 
@@ -4607,7 +4608,7 @@ class MultiRollupApiClients {
4607
4608
  }
4608
4609
 
4609
4610
  // eslint-disable-next-line @typescript-eslint/naming-convention
4610
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.4.0-alpha.3' };
4611
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-0.4.1-alpha' };
4611
4612
  const createConfig = ({ basePath, headers, }) => {
4612
4613
  if (!basePath.trim()) {
4613
4614
  throw Error('basePath can not be empty');
@@ -4663,7 +4664,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
4663
4664
  chainID,
4664
4665
  coreContractAddress,
4665
4666
  registrationContractAddress,
4666
- sdkVersion: 'ts-immutable-sdk-0.4.0-alpha.3',
4667
+ sdkVersion: 'ts-immutable-sdk-0.4.1-alpha',
4667
4668
  });
4668
4669
  /**
4669
4670
  * Sets `sdkVersion` at the time of build
@@ -8387,8 +8388,6 @@ var globalAxios = axios;
8387
8388
  * https://openapi-generator.tech
8388
8389
  * Do not edit the class manually.
8389
8390
  */
8390
- // Some imports not used depending on template conditions
8391
- // @ts-ignore
8392
8391
  const BASE_PATH = "https://guardian.sandbox.imtbl.com".replace(/\/+$/, "");
8393
8392
  /**
8394
8393
  *
@@ -8416,10 +8415,10 @@ class BaseAPI {
8416
8415
  */
8417
8416
  class RequiredError extends Error {
8418
8417
  field;
8419
- name = "RequiredError";
8420
8418
  constructor(field, msg) {
8421
8419
  super(msg);
8422
8420
  this.field = field;
8421
+ this.name = "RequiredError";
8423
8422
  }
8424
8423
  }
8425
8424
 
@@ -8464,6 +8463,8 @@ const setBearerAuthToObject = async function (object, configuration) {
8464
8463
  }
8465
8464
  };
8466
8465
  function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
8466
+ if (parameter == null)
8467
+ return;
8467
8468
  if (typeof parameter === "object") {
8468
8469
  if (Array.isArray(parameter)) {
8469
8470
  parameter.forEach(item => setFlattenedQueryParams(urlSearchParams, item, key));
@@ -8834,6 +8835,24 @@ class Configuration {
8834
8835
  }
8835
8836
  }
8836
8837
 
8838
+ /* tslint:disable */
8839
+ /* eslint-disable */
8840
+ /**
8841
+ * Guardian
8842
+ * Guardian API
8843
+ *
8844
+ * The version of the OpenAPI document: 1.0.0
8845
+ * Contact: support@immutable.com
8846
+ *
8847
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
8848
+ * https://openapi-generator.tech
8849
+ * Do not edit the class manually.
8850
+ */
8851
+ const TransactionApprovalRequestChainTypeEnum = {
8852
+ Starkex: 'starkex',
8853
+ Evm: 'evm'
8854
+ };
8855
+
8837
8856
  // used to sign message with L1 keys. Used for registration
8838
8857
  function serializeEthSignature(sig) {
8839
8858
  // This is because golang appends a recovery param
@@ -8932,10 +8951,17 @@ const withPassportError = async (fn, customErrorType) => {
8932
8951
  };
8933
8952
 
8934
8953
  const keyCrendentials = 'passport_credentials';
8954
+ const KEY_PKCE_STATE = 'pkce_state';
8955
+ const KEY_PKCE_VERIFIER = 'pkce_verifier';
8935
8956
  const validCredentialsMinTtlSec = 3600; // 1 hour
8936
8957
  class DeviceCredentialsManager {
8937
8958
  saveCredentials(tokenResponse) {
8938
- localStorage.setItem(keyCrendentials, JSON.stringify(tokenResponse));
8959
+ if (this.areValid(tokenResponse)) {
8960
+ localStorage.setItem(keyCrendentials, JSON.stringify(tokenResponse));
8961
+ }
8962
+ else {
8963
+ throw Error('Invalid credentials.');
8964
+ }
8939
8965
  }
8940
8966
  getCredentials() {
8941
8967
  const credentialsJson = localStorage.getItem(keyCrendentials);
@@ -8953,14 +8979,31 @@ class DeviceCredentialsManager {
8953
8979
  return false;
8954
8980
  }
8955
8981
  isTokenValid(jwt) {
8956
- const tokenPayload = jwt_decode(jwt);
8957
- const expiresAt = tokenPayload.exp ?? 0;
8958
- const now = (Date.now() / 1000) + validCredentialsMinTtlSec;
8959
- return expiresAt > now;
8982
+ try {
8983
+ const tokenPayload = jwt_decode(jwt);
8984
+ const expiresAt = tokenPayload.exp ?? 0;
8985
+ const now = (Date.now() / 1000) + validCredentialsMinTtlSec;
8986
+ return expiresAt > now;
8987
+ }
8988
+ catch (error) {
8989
+ return false;
8990
+ }
8960
8991
  }
8961
8992
  clearCredentials() {
8962
8993
  localStorage.removeItem(keyCrendentials);
8963
8994
  }
8995
+ savePKCEData(data) {
8996
+ localStorage.setItem(KEY_PKCE_STATE, data.state);
8997
+ localStorage.setItem(KEY_PKCE_VERIFIER, data.verifier);
8998
+ }
8999
+ getPKCEData() {
9000
+ const state = localStorage.getItem(KEY_PKCE_STATE);
9001
+ const verifier = localStorage.getItem(KEY_PKCE_VERIFIER);
9002
+ if (state && verifier) {
9003
+ return { state, verifier };
9004
+ }
9005
+ return null;
9006
+ }
8964
9007
  }
8965
9008
 
8966
9009
  const formUrlEncodedHeader = {
@@ -9137,6 +9180,59 @@ class AuthManager {
9137
9180
  }, formUrlEncodedHeader);
9138
9181
  return response.data;
9139
9182
  }
9183
+ static base64URLEncode(str) {
9184
+ return str.toString('base64')
9185
+ .replace(/\+/g, '-')
9186
+ .replace(/\//g, '_')
9187
+ .replace(/=/g, '');
9188
+ }
9189
+ static sha256(buffer) {
9190
+ return crypto.createHash('sha256').update(buffer).digest();
9191
+ }
9192
+ getPKCEAuthorizationUrl() {
9193
+ const verifier = AuthManager.base64URLEncode(crypto.randomBytes(32));
9194
+ const challenge = AuthManager.base64URLEncode(AuthManager.sha256(verifier));
9195
+ // https://auth0.com/docs/secure/attack-protection/state-parameters
9196
+ const state = AuthManager.base64URLEncode(crypto.randomBytes(32));
9197
+ this.deviceCredentialsManager.savePKCEData({ state, verifier });
9198
+ return `${this.config.authenticationDomain}/authorize?`
9199
+ + 'response_type=code'
9200
+ + `&code_challenge=${challenge}`
9201
+ + '&code_challenge_method=S256'
9202
+ + `&client_id=${this.config.oidcConfiguration.clientId}`
9203
+ + `&redirect_uri=${this.config.oidcConfiguration.redirectUri}`
9204
+ + `&scope=${this.config.oidcConfiguration.scope}`
9205
+ + `&state=${state}`
9206
+ + `&audience=${this.config.oidcConfiguration.audience}`;
9207
+ }
9208
+ async connectImxPKCEFlow(authorizationCode, state) {
9209
+ return withPassportError(async () => {
9210
+ const pkceData = this.deviceCredentialsManager.getPKCEData();
9211
+ if (!pkceData) {
9212
+ throw new Error('No code verifier or state for PKCE');
9213
+ }
9214
+ if (state !== pkceData.state) {
9215
+ throw new Error('Provided state does not match stored state');
9216
+ }
9217
+ const tokenResponse = await this.getPKCEToken(authorizationCode, pkceData.verifier);
9218
+ const user = AuthManager.mapDeviceTokenResponseToDomainUserModel(tokenResponse);
9219
+ // Only persist credentials that contain the necessary data
9220
+ if (user.imx?.ethAddress && user.imx?.starkAddress && user.imx?.userAdminAddress) {
9221
+ this.deviceCredentialsManager.saveCredentials(tokenResponse);
9222
+ }
9223
+ return user;
9224
+ }, PassportErrorType.AUTHENTICATION_ERROR);
9225
+ }
9226
+ async getPKCEToken(authorizationCode, codeVerifier) {
9227
+ const response = await axios$2.post(`${this.config.authenticationDomain}/oauth/token`, {
9228
+ client_id: this.config.oidcConfiguration.clientId,
9229
+ grant_type: 'authorization_code',
9230
+ code_verifier: codeVerifier,
9231
+ code: authorizationCode,
9232
+ redirect_uri: this.config.oidcConfiguration.redirectUri,
9233
+ }, formUrlEncodedHeader);
9234
+ return response.data;
9235
+ }
9140
9236
  async connectImxWithCredentials(tokenResponse) {
9141
9237
  return withPassportError(async () => {
9142
9238
  if (this.deviceCredentialsManager.areValid(tokenResponse)) {
@@ -9265,6 +9361,53 @@ const retryWithDelay = async (fn, options) => {
9265
9361
  }
9266
9362
  };
9267
9363
 
9364
+ /**
9365
+ * ProviderErrors should take priority over RpcErrorCodes
9366
+ */
9367
+ var ProviderErrorCode;
9368
+ (function (ProviderErrorCode) {
9369
+ ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
9370
+ ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
9371
+ ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
9372
+ ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
9373
+ })(ProviderErrorCode || (ProviderErrorCode = {}));
9374
+ var RpcErrorCode;
9375
+ (function (RpcErrorCode) {
9376
+ RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
9377
+ RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
9378
+ RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
9379
+ RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
9380
+ RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
9381
+ RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
9382
+ RpcErrorCode[RpcErrorCode["USER_REJECTED_REQUEST"] = -32003] = "USER_REJECTED_REQUEST";
9383
+ })(RpcErrorCode || (RpcErrorCode = {}));
9384
+ class JsonRpcError extends Error {
9385
+ message;
9386
+ code;
9387
+ constructor(code, message) {
9388
+ super(message);
9389
+ this.message = message;
9390
+ this.code = code;
9391
+ }
9392
+ }
9393
+
9394
+ const convertBigNumberishToString = (value) => BigNumber.from(value).toString();
9395
+ const transformGuardianTransactions = (txs) => {
9396
+ try {
9397
+ return txs.map((t) => ({
9398
+ delegateCall: t.delegateCall === true,
9399
+ revertOnError: t.revertOnError === true,
9400
+ gasLimit: t.gasLimit ? convertBigNumberishToString(t.gasLimit) : '0',
9401
+ target: t.to ?? ethers.constants.AddressZero,
9402
+ value: t.value ? convertBigNumberishToString(t.value) : '0',
9403
+ data: t.data ? t.data.toString() : '0x00',
9404
+ }));
9405
+ }
9406
+ catch (error) {
9407
+ const errorMessage = (error instanceof Error) ? error.message : String(error);
9408
+ throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
9409
+ }
9410
+ };
9268
9411
  class GuardianClient {
9269
9412
  transactionAPI;
9270
9413
  confirmationScreen;
@@ -9299,7 +9442,7 @@ class GuardianClient {
9299
9442
  });
9300
9443
  const { confirmationRequired } = evaluateStarkexRes.data;
9301
9444
  if (confirmationRequired) {
9302
- const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress);
9445
+ const confirmationResult = await this.confirmationScreen.startGuardianTransaction(payloadHash, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Starkex);
9303
9446
  if (!confirmationResult.confirmed) {
9304
9447
  throw new Error('Transaction rejected by user');
9305
9448
  }
@@ -9308,6 +9451,47 @@ class GuardianClient {
9308
9451
  this.confirmationScreen.closeWindow();
9309
9452
  }
9310
9453
  }
9454
+ async evaluateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
9455
+ const headers = { Authorization: `Bearer ${user.accessToken}` };
9456
+ const guardianTransactions = transformGuardianTransactions(metaTransactions);
9457
+ try {
9458
+ const transactionEvaluationResponseAxiosResponse = await this.transactionAPI.evaluateTransaction({
9459
+ id: 'evm',
9460
+ transactionEvaluationRequest: {
9461
+ chainType: 'evm',
9462
+ chainId,
9463
+ transactionData: {
9464
+ nonce,
9465
+ userAddress: user.zkEvm.ethAddress,
9466
+ metaTransactions: guardianTransactions,
9467
+ },
9468
+ },
9469
+ }, { headers });
9470
+ return transactionEvaluationResponseAxiosResponse.data;
9471
+ }
9472
+ catch (error) {
9473
+ const errorMessage = (error instanceof Error) ? error.message : String(error);
9474
+ throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
9475
+ }
9476
+ }
9477
+ async validateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
9478
+ const transactionEvaluationResponse = await this.evaluateEVMTransaction({
9479
+ chainId,
9480
+ nonce,
9481
+ user,
9482
+ metaTransactions,
9483
+ });
9484
+ const { confirmationRequired, transactionId } = transactionEvaluationResponse;
9485
+ if (confirmationRequired && !!transactionId) {
9486
+ const confirmationResult = await this.confirmationScreen.startGuardianTransaction(transactionId, this.imxEtherAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
9487
+ if (!confirmationResult.confirmed) {
9488
+ throw new JsonRpcError(RpcErrorCode.USER_REJECTED_REQUEST, 'Transaction rejected by user ');
9489
+ }
9490
+ }
9491
+ else {
9492
+ this.confirmationScreen.closeWindow();
9493
+ }
9494
+ }
9311
9495
  }
9312
9496
 
9313
9497
  async function exchangeTransfer({ user, starkSigner, request, exchangesApi, }) {
@@ -9746,6 +9930,10 @@ class PassportImxProviderFactory {
9746
9930
  const user = await this.authManager.connectImxDeviceFlow(deviceCode, interval, timeoutMs);
9747
9931
  return this.createProviderInstance(user);
9748
9932
  }
9933
+ async getProviderWithPKCEFlow(authorizationCode, state) {
9934
+ const user = await this.authManager.connectImxPKCEFlow(authorizationCode, state);
9935
+ return this.createProviderInstance(user);
9936
+ }
9749
9937
  async getProviderWithCredentials(tokenResponse) {
9750
9938
  const user = await this.authManager.connectImxWithCredentials(tokenResponse);
9751
9939
  if (!user) {
@@ -10009,7 +10197,7 @@ class ConfirmationScreen {
10009
10197
  }, CONFIRMATION_WINDOW_CLOSED_POLLING_DURATION);
10010
10198
  });
10011
10199
  }
10012
- startGuardianTransaction(transactionId, imxEtherAddress) {
10200
+ startGuardianTransaction(transactionId, imxEtherAddress, chainType, chainId) {
10013
10201
  return new Promise((resolve, reject) => {
10014
10202
  const messageHandler = ({ data, origin }) => {
10015
10203
  if (origin !== this.config.passportDomain
@@ -10038,7 +10226,16 @@ class ConfirmationScreen {
10038
10226
  return;
10039
10227
  }
10040
10228
  // eslint-disable-next-line max-len
10041
- this.confirmationWindow.location.href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
10229
+ let href = '';
10230
+ if (chainType === TransactionApprovalRequestChainTypeEnum.Starkex) {
10231
+ // eslint-disable-next-line max-len
10232
+ href = `${this.config.passportDomain}/transaction-confirmation/transaction.html?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=starkex`;
10233
+ }
10234
+ else {
10235
+ // eslint-disable-next-line max-len
10236
+ href = `${this.config.passportDomain}/transaction-confirmation/zkevm?transactionId=${transactionId}&imxEtherAddress=${imxEtherAddress}&chainType=evm&chainId=${chainId}`;
10237
+ }
10238
+ this.confirmationWindow.location.href = href;
10042
10239
  // https://stackoverflow.com/questions/9388380/capture-the-close-event-of-popup-window-in-javascript/48240128#48240128
10043
10240
  const timer = setInterval(() => {
10044
10241
  if (this.confirmationWindow?.closed) {
@@ -10146,35 +10343,6 @@ class RelayerClient {
10146
10343
  }
10147
10344
  }
10148
10345
 
10149
- /**
10150
- * ProviderErrors should take priority over RpcErrorCodes
10151
- */
10152
- var ProviderErrorCode;
10153
- (function (ProviderErrorCode) {
10154
- ProviderErrorCode[ProviderErrorCode["USER_REJECTED_REQUEST"] = 4001] = "USER_REJECTED_REQUEST";
10155
- ProviderErrorCode[ProviderErrorCode["UNAUTHORIZED"] = 4100] = "UNAUTHORIZED";
10156
- ProviderErrorCode[ProviderErrorCode["UNSUPPORTED_METHOD"] = 4200] = "UNSUPPORTED_METHOD";
10157
- ProviderErrorCode[ProviderErrorCode["DISCONNECTED"] = 4900] = "DISCONNECTED";
10158
- })(ProviderErrorCode || (ProviderErrorCode = {}));
10159
- var RpcErrorCode;
10160
- (function (RpcErrorCode) {
10161
- RpcErrorCode[RpcErrorCode["RPC_SERVER_ERROR"] = -32000] = "RPC_SERVER_ERROR";
10162
- RpcErrorCode[RpcErrorCode["INVALID_REQUEST"] = -32600] = "INVALID_REQUEST";
10163
- RpcErrorCode[RpcErrorCode["METHOD_NOT_FOUND"] = -32601] = "METHOD_NOT_FOUND";
10164
- RpcErrorCode[RpcErrorCode["INVALID_PARAMS"] = -32602] = "INVALID_PARAMS";
10165
- RpcErrorCode[RpcErrorCode["INTERNAL_ERROR"] = -32603] = "INTERNAL_ERROR";
10166
- RpcErrorCode[RpcErrorCode["PARSE_ERROR"] = -32700] = "PARSE_ERROR";
10167
- })(RpcErrorCode || (RpcErrorCode = {}));
10168
- class JsonRpcError extends Error {
10169
- message;
10170
- code;
10171
- constructor(code, message) {
10172
- super(message);
10173
- this.message = message;
10174
- this.code = code;
10175
- }
10176
- }
10177
-
10178
10346
  const MESSAGE_TO_SIGN = 'Only sign this message from Immutable Passport';
10179
10347
  async function registerZkEvmUser({ authManager, magicProvider, multiRollupApiClients, accessToken, }) {
10180
10348
  const web3Provider = new Web3Provider(magicProvider);
@@ -10302,46 +10470,9 @@ const chainIdNumber = (chainId) => {
10302
10470
 
10303
10471
  const MAX_TRANSACTION_HASH_RETRIEVAL_RETRIES = 30;
10304
10472
  const TRANSACTION_HASH_RETRIEVAL_WAIT = 1000;
10305
- const converBigNumberishToNumber = (value) => BigNumber.from(value).toNumber();
10306
- const transformGardianTransactions = (txs) => {
10307
- try {
10308
- return txs.map((t) => ({
10309
- delegateCall: t.delegateCall === true,
10310
- revertOnError: t.revertOnError === true,
10311
- gasLimit: t.gasLimit ? converBigNumberishToNumber(t.gasLimit).toString() : '0',
10312
- target: t.to ?? ethers.constants.AddressZero,
10313
- value: t.value ? converBigNumberishToNumber(t.value).toString() : '0',
10314
- data: t.data ? t.data.toString() : '0x00',
10315
- }));
10316
- }
10317
- catch (error) {
10318
- const errorMessage = (error instanceof Error) ? error.message : String(error);
10319
- throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, `Transaction failed to parsing: ${errorMessage}`);
10320
- }
10321
- };
10322
- const guardianValidation = async ({ transactionAPI, chainId, nonce, user, metaTransactions, }) => {
10323
- const headers = { Authorization: `Bearer ${user.accessToken}` };
10324
- const guardianTransactions = transformGardianTransactions(metaTransactions);
10325
- try {
10326
- await transactionAPI.evaluateTransaction({
10327
- id: 'evm',
10328
- transactionEvaluationRequest: {
10329
- chainType: 'evm',
10330
- chainId,
10331
- transactionData: {
10332
- nonce,
10333
- userAddress: user.zkEvm.ethAddress,
10334
- metaTransactions: guardianTransactions,
10335
- },
10336
- },
10337
- }, { headers });
10338
- }
10339
- catch (error) {
10340
- const errorMessage = (error instanceof Error) ? error.message : String(error);
10341
- throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
10342
- }
10343
- };
10344
- const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, transactionAPI, config, user, }) => {
10473
+ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, config, user, }) => {
10474
+ const popupWindowSize = { width: 480, height: 580 };
10475
+ guardianClient.loading(popupWindowSize);
10345
10476
  const transactionRequest = params[0];
10346
10477
  if (!transactionRequest.to) {
10347
10478
  throw new JsonRpcError(RpcErrorCode.INVALID_PARAMS, 'eth_sendTransaction requires a "to" field');
@@ -10379,10 +10510,9 @@ const sendTransaction = async ({ params, magicProvider, jsonRpcProvider, relayer
10379
10510
  value: imxFeeOption.tokenPrice,
10380
10511
  revertOnError: true,
10381
10512
  };
10382
- await guardianValidation({
10383
- transactionAPI,
10513
+ await guardianClient.validateEVMTransaction({
10384
10514
  chainId: config.zkEvmChainId,
10385
- nonce: converBigNumberishToNumber(nonce),
10515
+ nonce: convertBigNumberishToString(nonce),
10386
10516
  user,
10387
10517
  metaTransactions: [metaTransaction, feeMetaTransaction],
10388
10518
  });
@@ -10462,10 +10592,16 @@ class ZkEvmProvider {
10462
10592
  if (!this.isLoggedIn()) {
10463
10593
  throw new JsonRpcError(ProviderErrorCode.UNAUTHORIZED, 'Unauthorised - call eth_requestAccounts first');
10464
10594
  }
10595
+ const guardianClient = new GuardianClient({
10596
+ imxPublicApiDomain: this.config.imxPublicApiDomain,
10597
+ accessToken: this.user.accessToken,
10598
+ confirmationScreen: this.confirmationScreen,
10599
+ imxEtherAddress: this.user?.imx?.ethAddress || '',
10600
+ });
10465
10601
  return sendTransaction({
10466
10602
  params: request.params || [],
10467
10603
  magicProvider: this.magicProvider,
10468
- transactionAPI: this.transactionAPI,
10604
+ guardianClient,
10469
10605
  jsonRpcProvider: this.jsonRpcProvider,
10470
10606
  config: this.config,
10471
10607
  relayerClient: this.relayerClient,
@@ -10631,6 +10767,12 @@ class Passport {
10631
10767
  async connectImxDeviceFlow(deviceCode, interval, timeoutMs) {
10632
10768
  return this.passportImxProviderFactory.getProviderWithDeviceFlow(deviceCode, interval, timeoutMs);
10633
10769
  }
10770
+ getPKCEAuthorizationUrl() {
10771
+ return this.authManager.getPKCEAuthorizationUrl();
10772
+ }
10773
+ async connectImxPKCEFlow(authorizationCode, state) {
10774
+ return this.passportImxProviderFactory.getProviderWithPKCEFlow(authorizationCode, state);
10775
+ }
10634
10776
  /**
10635
10777
  * @returns {boolean} the stored device flow credentials if they exist
10636
10778
  */
@@ -686,7 +686,7 @@ interface GetSignableCancelOrderRequest {
686
686
  */
687
687
  interface GetSignableTradeRequest {
688
688
  /**
689
- * ExpirationTimestamp in Unix time. Note: will be rounded down to the nearest hour
689
+ * ExpirationTimestamp in Unix time in hours. Note: will be rounded down to the nearest hour
690
690
  * @type {number}
691
691
  * @memberof GetSignableTradeRequest
692
692
  */
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "0.4.0-alpha.3",
4
+ "version": "0.4.1-alpha",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",
@@ -11,7 +11,7 @@
11
11
  "@ethersproject/abstract-signer": "^5.7.0",
12
12
  "@ethersproject/providers": "^5.7.2",
13
13
  "@ethersproject/wallet": "^5.7.0",
14
- "@imtbl/core-sdk": "^2.0.1",
14
+ "@imtbl/core-sdk": "^2.0.2",
15
15
  "@jest/globals": "^29.5.0",
16
16
  "@magic-ext/oidc": "^1.0.1",
17
17
  "@metamask/detect-provider": "^2.0.0",