@imtbl/sdk 1.5.0 → 1.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/passport.js CHANGED
@@ -9136,7 +9136,7 @@ class MultiRollupApiClients {
9136
9136
  }
9137
9137
 
9138
9138
  // eslint-disable-next-line @typescript-eslint/naming-convention
9139
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.5.0' };
9139
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.5.2' };
9140
9140
  const createConfig = ({ basePath, headers, }) => {
9141
9141
  if (!basePath.trim()) {
9142
9142
  throw Error('basePath can not be empty');
@@ -9316,7 +9316,7 @@ const flattenProperties = (properties) => {
9316
9316
  };
9317
9317
 
9318
9318
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
9319
- const SDK_VERSION = '1.5.0';
9319
+ const SDK_VERSION = '1.5.2';
9320
9320
  let initialised = false;
9321
9321
  const isInitialised = () => initialised;
9322
9322
  const getReferrer = () => {
@@ -9491,7 +9491,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
9491
9491
  chainID,
9492
9492
  coreContractAddress,
9493
9493
  registrationContractAddress,
9494
- sdkVersion: 'ts-immutable-sdk-1.5.0',
9494
+ sdkVersion: 'ts-immutable-sdk-1.5.2',
9495
9495
  });
9496
9496
  /**
9497
9497
  * Sets `sdkVersion` at the time of build
@@ -14552,12 +14552,14 @@ class GuardianClient {
14552
14552
  messageAPI;
14553
14553
  confirmationScreen;
14554
14554
  crossSdkBridgeEnabled;
14555
- constructor({ confirmationScreen, config }) {
14555
+ authManager;
14556
+ constructor({ confirmationScreen, config, authManager }) {
14556
14557
  const guardianConfiguration = new Configuration({ basePath: config.imxPublicApiDomain });
14557
14558
  this.confirmationScreen = confirmationScreen;
14558
14559
  this.crossSdkBridgeEnabled = config.crossSdkBridgeEnabled;
14559
14560
  this.messageAPI = new MessagesApi(guardianConfiguration);
14560
14561
  this.transactionAPI = new TransactionsApi(guardianConfiguration);
14562
+ this.authManager = authManager;
14561
14563
  }
14562
14564
  /**
14563
14565
  * Open confirmation screen and close it automatically if the
@@ -14581,10 +14583,11 @@ class GuardianClient {
14581
14583
  withDefaultConfirmationScreenTask(task) {
14582
14584
  return this.withConfirmationScreenTask()(task);
14583
14585
  }
14584
- async evaluateImxTransaction({ payloadHash, user }) {
14586
+ async evaluateImxTransaction({ payloadHash }) {
14585
14587
  const finallyFn = () => {
14586
14588
  this.confirmationScreen.closeWindow();
14587
14589
  };
14590
+ const user = await this.authManager.getUser();
14588
14591
  const headers = { Authorization: `Bearer ${user.accessToken}` };
14589
14592
  const transactionRes = await retryWithDelay(async () => this.transactionAPI.getTransactionByID({
14590
14593
  transactionID: payloadHash,
@@ -14613,7 +14616,8 @@ class GuardianClient {
14613
14616
  this.confirmationScreen.closeWindow();
14614
14617
  }
14615
14618
  }
14616
- async evaluateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
14619
+ async evaluateEVMTransaction({ chainId, nonce, metaTransactions, }) {
14620
+ const user = await this.authManager.getUser();
14617
14621
  const headers = { Authorization: `Bearer ${user.accessToken}` };
14618
14622
  const guardianTransactions = transformGuardianTransactions(metaTransactions);
14619
14623
  try {
@@ -14636,11 +14640,10 @@ class GuardianClient {
14636
14640
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Transaction failed to validate with error: ${errorMessage}`);
14637
14641
  }
14638
14642
  }
14639
- async validateEVMTransaction({ chainId, nonce, user, metaTransactions, }) {
14643
+ async validateEVMTransaction({ chainId, nonce, metaTransactions, }) {
14640
14644
  const transactionEvaluationResponse = await this.evaluateEVMTransaction({
14641
14645
  chainId,
14642
14646
  nonce,
14643
- user,
14644
14647
  metaTransactions,
14645
14648
  });
14646
14649
  const { confirmationRequired, transactionId } = transactionEvaluationResponse;
@@ -14648,6 +14651,7 @@ class GuardianClient {
14648
14651
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
14649
14652
  }
14650
14653
  if (confirmationRequired && !!transactionId) {
14654
+ const user = await this.authManager.getUser();
14651
14655
  const confirmationResult = await this.confirmationScreen.requestConfirmation(transactionId, user.zkEvm.ethAddress, TransactionApprovalRequestChainTypeEnum.Evm, chainId);
14652
14656
  if (!confirmationResult.confirmed) {
14653
14657
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Transaction rejected by user');
@@ -14657,8 +14661,12 @@ class GuardianClient {
14657
14661
  this.confirmationScreen.closeWindow();
14658
14662
  }
14659
14663
  }
14660
- async evaluateMessage({ chainID, payload, user }) {
14664
+ async evaluateMessage({ chainID, payload }) {
14661
14665
  try {
14666
+ const user = await this.authManager.getUser();
14667
+ if (user === null) {
14668
+ throw new PassportError('evaluateMessage requires a valid ID token or refresh token. Please log in first', PassportErrorType.NOT_LOGGED_IN_ERROR);
14669
+ }
14662
14670
  const messageEvalResponse = await this.messageAPI.evaluateMessage({ messageEvaluationRequest: { chainID, payload } }, { headers: { Authorization: `Bearer ${user.accessToken}` } });
14663
14671
  return messageEvalResponse.data;
14664
14672
  }
@@ -14667,12 +14675,13 @@ class GuardianClient {
14667
14675
  throw new JsonRpcError(RpcErrorCode.INTERNAL_ERROR, `Message failed to validate with error: ${errorMessage}`);
14668
14676
  }
14669
14677
  }
14670
- async validateMessage({ chainID, payload, user }) {
14671
- const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload, user });
14678
+ async validateMessage({ chainID, payload }) {
14679
+ const { messageId, confirmationRequired } = await this.evaluateMessage({ chainID, payload });
14672
14680
  if (confirmationRequired && this.crossSdkBridgeEnabled) {
14673
14681
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, transactionRejectedCrossSdkBridgeError);
14674
14682
  }
14675
14683
  if (confirmationRequired && !!messageId) {
14684
+ const user = await this.authManager.getUser();
14676
14685
  const confirmationResult = await this.confirmationScreen.requestMessageConfirmation(messageId, user.zkEvm.ethAddress);
14677
14686
  if (!confirmationResult.confirmed) {
14678
14687
  throw new JsonRpcError(RpcErrorCode.TRANSACTION_REJECTED, 'Signature rejected by user');
@@ -14754,7 +14763,6 @@ async function createOrder({ starkSigner, user, request, ordersApi, guardianClie
14754
14763
  getSignableOrderRequestV3,
14755
14764
  }, { headers });
14756
14765
  await guardianClient.evaluateImxTransaction({
14757
- user,
14758
14766
  payloadHash: getSignableOrderResponse.data.payload_hash,
14759
14767
  });
14760
14768
  const { payload_hash: payloadHash } = getSignableOrderResponse.data;
@@ -14797,7 +14805,6 @@ async function cancelOrder({ user, starkSigner, request, ordersApi, guardianClie
14797
14805
  getSignableCancelOrderRequest,
14798
14806
  }, { headers });
14799
14807
  await guardianClient.evaluateImxTransaction({
14800
- user,
14801
14808
  payloadHash: getSignableCancelOrderResponse.data.payload_hash,
14802
14809
  });
14803
14810
  const { payload_hash: payloadHash } = getSignableCancelOrderResponse.data;
@@ -14859,7 +14866,6 @@ async function createTrade({ request, tradesApi, user, starkSigner, guardianClie
14859
14866
  getSignableTradeRequest,
14860
14867
  }, { headers });
14861
14868
  await guardianClient.evaluateImxTransaction({
14862
- user,
14863
14869
  payloadHash: getSignableTradeResponse.data.payload_hash,
14864
14870
  });
14865
14871
  const { payload_hash: payloadHash } = getSignableTradeResponse.data;
@@ -14907,7 +14913,6 @@ async function transfer({ request, transfersApi, starkSigner, user, guardianClie
14907
14913
  getSignableTransferRequest,
14908
14914
  }, { headers });
14909
14915
  await guardianClient.evaluateImxTransaction({
14910
- user,
14911
14916
  payloadHash: signableResult.data.payload_hash,
14912
14917
  });
14913
14918
  const signableResultData = signableResult.data;
@@ -14958,7 +14963,6 @@ async function batchNftTransfer({ user, starkSigner, request, transfersApi, guar
14958
14963
  },
14959
14964
  }, { headers });
14960
14965
  await guardianClient.evaluateImxTransaction({
14961
- user,
14962
14966
  payloadHash: signableResult.data.signable_responses[0]?.payload_hash,
14963
14967
  });
14964
14968
  const requests = await Promise.all(signableResult.data.signable_responses.map(async (resp) => {
@@ -15038,6 +15042,7 @@ class PassportImxProvider {
15038
15042
  this.guardianClient = new GuardianClient({
15039
15043
  confirmationScreen,
15040
15044
  config,
15045
+ authManager,
15041
15046
  });
15042
15047
  this.magicAdapter = magicAdapter;
15043
15048
  this.imxApiClients = imxApiClients;
@@ -15669,11 +15674,11 @@ const getEip155ChainId = (chainId) => `eip155:${chainId}`;
15669
15674
  class RelayerClient {
15670
15675
  config;
15671
15676
  jsonRpcProvider;
15672
- user;
15673
- constructor({ config, jsonRpcProvider, user }) {
15677
+ authManager;
15678
+ constructor({ config, jsonRpcProvider, authManager }) {
15674
15679
  this.config = config;
15675
15680
  this.jsonRpcProvider = jsonRpcProvider;
15676
- this.user = user;
15681
+ this.authManager = authManager;
15677
15682
  }
15678
15683
  async postToRelayer(request) {
15679
15684
  const body = {
@@ -15681,10 +15686,11 @@ class RelayerClient {
15681
15686
  jsonrpc: '2.0',
15682
15687
  ...request,
15683
15688
  };
15689
+ const user = await this.authManager.getUser();
15684
15690
  const response = await fetch(`${this.config.relayerUrl}/v1/transactions`, {
15685
15691
  method: 'POST',
15686
15692
  headers: {
15687
- Authorization: `Bearer ${this.user.accessToken}`,
15693
+ Authorization: `Bearer ${user?.accessToken}`,
15688
15694
  'Content-Type': 'application/json',
15689
15695
  },
15690
15696
  body: JSON.stringify(body),
@@ -15843,7 +15849,7 @@ const getMetaTransactions = async (metaTransaction, nonce, chainId, walletAddres
15843
15849
  }
15844
15850
  return [metaTransaction, feeMetaTransaction];
15845
15851
  };
15846
- const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
15852
+ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient, guardianClient, zkevmAddress, }) => guardianClient
15847
15853
  .withConfirmationScreen({ width: 480, height: 720 })(async () => {
15848
15854
  const transactionRequest = params[0];
15849
15855
  if (!transactionRequest.to) {
@@ -15853,7 +15859,7 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
15853
15859
  const chainIdBigNumber = BigNumber.from(chainId);
15854
15860
  const magicWeb3Provider = new Web3Provider(magicProvider);
15855
15861
  const signer = magicWeb3Provider.getSigner();
15856
- const nonce = await getNonce(jsonRpcProvider, user.zkEvm.ethAddress);
15862
+ const nonce = await getNonce(jsonRpcProvider, zkevmAddress);
15857
15863
  const metaTransaction = {
15858
15864
  to: transactionRequest.to,
15859
15865
  data: transactionRequest.data,
@@ -15861,17 +15867,16 @@ const sendTransaction = ({ params, magicProvider, jsonRpcProvider, relayerClient
15861
15867
  value: transactionRequest.value,
15862
15868
  revertOnError: true,
15863
15869
  };
15864
- const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer, relayerClient);
15870
+ const metaTransactions = await getMetaTransactions(metaTransaction, nonce, chainIdBigNumber, zkevmAddress, signer, relayerClient);
15865
15871
  await guardianClient.validateEVMTransaction({
15866
15872
  chainId: getEip155ChainId(chainId),
15867
15873
  nonce: convertBigNumberishToString(nonce),
15868
- user,
15869
15874
  metaTransactions,
15870
15875
  });
15871
15876
  // NOTE: We sign again because we now are adding the fee transaction, so the
15872
15877
  // whole payload is different and needs a new signature.
15873
- const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, user.zkEvm.ethAddress, signer);
15874
- const relayerId = await relayerClient.ethSendTransaction(user.zkEvm.ethAddress, signedTransactions);
15878
+ const signedTransactions = await getSignedMetaTransactions(metaTransactions, nonce, chainIdBigNumber, zkevmAddress, signer);
15879
+ const relayerId = await relayerClient.ethSendTransaction(zkevmAddress, signedTransactions);
15875
15880
  const retrieveRelayerTransaction = async () => {
15876
15881
  const tx = await relayerClient.imGetTransactionByHash(relayerId);
15877
15882
  // NOTE: The transaction hash is only available from the Relayer once the
@@ -15939,7 +15944,7 @@ const transformTypedData = (typedData, chainId) => {
15939
15944
  }
15940
15945
  return transformedTypedData;
15941
15946
  };
15942
- const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient, user, }) => guardianClient
15947
+ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider, relayerClient, guardianClient, }) => guardianClient
15943
15948
  .withConfirmationScreen({ width: 480, height: 730 })(async () => {
15944
15949
  const fromAddress = params[0];
15945
15950
  const typedDataParam = params[1];
@@ -15948,7 +15953,7 @@ const signTypedDataV4 = async ({ params, method, magicProvider, jsonRpcProvider,
15948
15953
  }
15949
15954
  const { chainId } = await jsonRpcProvider.ready;
15950
15955
  const typedData = transformTypedData(typedDataParam, chainId);
15951
- await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData, user });
15956
+ await guardianClient.validateMessage({ chainID: String(chainId), payload: typedData });
15952
15957
  const relayerSignature = await relayerClient.imSignTypedData(fromAddress, typedData);
15953
15958
  const magicWeb3Provider = new Web3Provider(magicProvider);
15954
15959
  const signer = magicWeb3Provider.getSigner();
@@ -15966,7 +15971,7 @@ class ZkEvmProvider {
15966
15971
  guardianClient;
15967
15972
  relayerClient;
15968
15973
  magicProvider; // Used for signing
15969
- user;
15974
+ zkevmAddress;
15970
15975
  isPassport = true;
15971
15976
  constructor({ authManager, magicAdapter, config, confirmationScreen, multiRollupApiClients, passportEventEmitter, }) {
15972
15977
  this.authManager = authManager;
@@ -15991,7 +15996,6 @@ class ZkEvmProvider {
15991
15996
  handleLogout = () => {
15992
15997
  const shouldEmitAccountsChanged = this.isLoggedIn();
15993
15998
  this.magicProvider = undefined;
15994
- this.user = undefined;
15995
15999
  this.relayerClient = undefined;
15996
16000
  this.guardianClient = undefined;
15997
16001
  if (shouldEmitAccountsChanged) {
@@ -16000,7 +16004,7 @@ class ZkEvmProvider {
16000
16004
  };
16001
16005
  isLoggedIn() {
16002
16006
  return this.magicProvider !== undefined
16003
- && this.user !== undefined
16007
+ && this.zkevmAddress !== undefined
16004
16008
  && this.relayerClient !== undefined
16005
16009
  && this.guardianClient !== undefined;
16006
16010
  }
@@ -16008,7 +16012,7 @@ class ZkEvmProvider {
16008
16012
  switch (request.method) {
16009
16013
  case 'eth_requestAccounts': {
16010
16014
  if (this.isLoggedIn()) {
16011
- return [this.user.zkEvm.ethAddress];
16015
+ return [this.zkevmAddress];
16012
16016
  }
16013
16017
  const { magicProvider, user } = await loginZkEvmUser({
16014
16018
  authManager: this.authManager,
@@ -16017,19 +16021,20 @@ class ZkEvmProvider {
16017
16021
  multiRollupApiClients: this.multiRollupApiClients,
16018
16022
  jsonRpcProvider: this.jsonRpcProvider,
16019
16023
  });
16020
- this.user = user;
16021
16024
  this.magicProvider = magicProvider;
16022
16025
  this.relayerClient = new RelayerClient({
16023
16026
  config: this.config,
16024
16027
  jsonRpcProvider: this.jsonRpcProvider,
16025
- user: this.user,
16028
+ authManager: this.authManager,
16026
16029
  });
16027
16030
  this.guardianClient = new GuardianClient({
16028
16031
  confirmationScreen: this.confirmationScreen,
16029
16032
  config: this.config,
16033
+ authManager: this.authManager,
16030
16034
  });
16031
- this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [this.user.zkEvm.ethAddress]);
16032
- return [this.user.zkEvm.ethAddress];
16035
+ this.zkevmAddress = user.zkEvm.ethAddress;
16036
+ this.eventEmitter.emit(ProviderEvent.ACCOUNTS_CHANGED, [user.zkEvm.ethAddress]);
16037
+ return [user.zkEvm.ethAddress];
16033
16038
  }
16034
16039
  case 'eth_sendTransaction': {
16035
16040
  if (!this.isLoggedIn()) {
@@ -16041,11 +16046,11 @@ class ZkEvmProvider {
16041
16046
  guardianClient: this.guardianClient,
16042
16047
  jsonRpcProvider: this.jsonRpcProvider,
16043
16048
  relayerClient: this.relayerClient,
16044
- user: this.user,
16049
+ zkevmAddress: this.zkevmAddress,
16045
16050
  });
16046
16051
  }
16047
16052
  case 'eth_accounts': {
16048
- return this.isLoggedIn() ? [this.user.zkEvm.ethAddress] : [];
16053
+ return this.zkevmAddress ? [this.zkevmAddress] : [];
16049
16054
  }
16050
16055
  case 'eth_signTypedData':
16051
16056
  case 'eth_signTypedData_v4': {
@@ -16058,7 +16063,6 @@ class ZkEvmProvider {
16058
16063
  magicProvider: this.magicProvider,
16059
16064
  jsonRpcProvider: this.jsonRpcProvider,
16060
16065
  relayerClient: this.relayerClient,
16061
- user: this.user,
16062
16066
  guardianClient: this.guardianClient,
16063
16067
  });
16064
16068
  }
package/dist/x.js CHANGED
@@ -131,7 +131,7 @@ const flattenProperties = (properties) => {
131
131
  };
132
132
 
133
133
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
134
- const SDK_VERSION = '1.5.0';
134
+ const SDK_VERSION = '1.5.2';
135
135
  let initialised = false;
136
136
  const isInitialised = () => initialised;
137
137
  const getReferrer = () => {
@@ -270,7 +270,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
270
270
  chainID,
271
271
  coreContractAddress,
272
272
  registrationContractAddress,
273
- sdkVersion: 'ts-immutable-sdk-1.5.0',
273
+ sdkVersion: 'ts-immutable-sdk-1.5.2',
274
274
  });
275
275
  /**
276
276
  * Sets `sdkVersion` at the time of build
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@imtbl/sdk",
3
3
  "description": "Immutable Unified SDK",
4
- "version": "1.5.0",
4
+ "version": "1.5.2",
5
5
  "author": "Immutable",
6
6
  "browser": "./dist/index.browser.js",
7
7
  "bugs": "https://github.com/immutable/ts-immutable-sdk/issues",