@imtbl/sdk 1.21.0 → 1.21.2-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.
Files changed (39) hide show
  1. package/dist/blockchain_data.d.ts +72 -22
  2. package/dist/blockchain_data.js +276 -101
  3. package/dist/browser/checkout/{BridgeWidget-48ef95fb.js → BridgeWidget-050bb010.js} +1 -1
  4. package/dist/browser/checkout/{HorizontalMenu-actual-1b0aa351.js → HorizontalMenu-actual-254df9f7.js} +1 -1
  5. package/dist/browser/checkout/{OnRampWidget-1c87f5ac.js → OnRampWidget-84f16f28.js} +1 -1
  6. package/dist/browser/checkout/{SaleWidget-51e77b6f.js → SaleWidget-b493918f.js} +2 -2
  7. package/dist/browser/checkout/{SpendingCapHero-43d4d6a1.js → SpendingCapHero-c21b087f.js} +1 -1
  8. package/dist/browser/checkout/{SwapWidget-3040f466.js → SwapWidget-9190ea19.js} +1 -1
  9. package/dist/browser/checkout/{TopUpView-9237bc6c.js → TopUpView-5fed36e0.js} +1 -1
  10. package/dist/browser/checkout/{WalletWidget-b5e4f4d7.js → WalletWidget-ce8ba9a4.js} +1 -1
  11. package/dist/browser/checkout/{auto-track-dbd0e9c6.js → auto-track-d773ecc1.js} +1 -1
  12. package/dist/browser/checkout/{balance-3b1416a3.js → balance-faa2470f.js} +1 -1
  13. package/dist/browser/checkout/{index-d80910d5.js → index-43c6ad17.js} +1 -1
  14. package/dist/browser/checkout/index-46c773de.js +1 -0
  15. package/dist/browser/checkout/{index-383a69c3.js → index-4b5a276c.js} +1 -1
  16. package/dist/browser/checkout/{index-ebf766fc.js → index-70723ad3.js} +1 -1
  17. package/dist/browser/checkout/{index-f5dd3066.js → index-8d9a8e86.js} +1 -1
  18. package/dist/browser/checkout/{index-67abd982.js → index-a247827a.js} +3 -3
  19. package/dist/browser/checkout/{index-a4b63381.js → index-a45f92e4.js} +1 -1
  20. package/dist/browser/checkout/{index-8107ef81.js → index-a6bbe105.js} +1 -1
  21. package/dist/browser/checkout/{index.umd-b03c715d.js → index.umd-26384df2.js} +1 -1
  22. package/dist/browser/checkout/{retry-da82ba74.js → retry-5c1764e1.js} +1 -1
  23. package/dist/browser/checkout/sdk.js +4 -4
  24. package/dist/browser/checkout/widgets-esm.js +1 -1
  25. package/dist/browser/checkout/widgets.js +5 -5
  26. package/dist/checkout.d.ts +2 -0
  27. package/dist/checkout.js +278 -103
  28. package/dist/config.js +1 -1
  29. package/dist/index.browser.js +11 -28
  30. package/dist/index.browser.js.map +1 -1
  31. package/dist/index.cjs +286 -110
  32. package/dist/index.d.ts +83 -22
  33. package/dist/index.js +286 -110
  34. package/dist/orderbook.js +1 -1
  35. package/dist/passport.js +455 -78
  36. package/dist/x.d.ts +6 -1
  37. package/dist/x.js +5 -4
  38. package/package.json +1 -2
  39. package/dist/browser/checkout/index-a81361a5.js +0 -1
package/dist/passport.js CHANGED
@@ -5,10 +5,10 @@ import { keccak256 } from '@ethersproject/keccak256';
5
5
  import { toUtf8Bytes } from '@ethersproject/strings';
6
6
  import BN from 'bn.js';
7
7
  import * as encUtils from 'enc-utils';
8
- import '@ethersproject/bytes';
8
+ import { splitSignature } from '@ethersproject/bytes';
9
9
  import hashJS from 'hash.js';
10
10
  import { ec, curves } from 'elliptic';
11
- import 'ethereumjs-wallet';
11
+ import { hdkey } from 'ethereumjs-wallet';
12
12
  import 'assert';
13
13
  import { utils as utils$2, BigNumber, Contract, errors, ethers, constants } from 'ethers';
14
14
  import '@ethersproject/abstract-signer';
@@ -17,7 +17,6 @@ import jwt_decode from 'jwt-decode';
17
17
  import * as crypto from 'crypto';
18
18
  import { Magic } from 'magic-sdk';
19
19
  import { OpenIdExtension } from '@magic-ext/oidc';
20
- import { generateLegacyStarkPrivateKey, createStarkSigner } from '@imtbl/core-sdk';
21
20
  import { StaticJsonRpcProvider, Web3Provider } from '@ethersproject/providers';
22
21
  import { EventEmitter } from 'events';
23
22
  import { walletContracts } from '@0xsequence/abi';
@@ -8654,12 +8653,13 @@ const ActivitiesApiAxiosParamCreator = function (configuration) {
8654
8653
  * @param {string} fromUpdatedAt From indexed at including given date
8655
8654
  * @param {string} [toUpdatedAt] To indexed at including given date
8656
8655
  * @param {string} [contractAddress] The contract address of the collection
8656
+ * @param {ActivityType} [activityType] The activity type
8657
8657
  * @param {string} [pageCursor] Encoded page cursor to retrieve previous or next page. Use the value returned in the response.
8658
8658
  * @param {number} [pageSize] Maximum number of items to return
8659
8659
  * @param {*} [options] Override http request option.
8660
8660
  * @throws {RequiredError}
8661
8661
  */
8662
- listActivityHistory: async (chainName, fromUpdatedAt, toUpdatedAt, contractAddress, pageCursor, pageSize, options = {}) => {
8662
+ listActivityHistory: async (chainName, fromUpdatedAt, toUpdatedAt, contractAddress, activityType, pageCursor, pageSize, options = {}) => {
8663
8663
  // verify required parameter 'chainName' is not null or undefined
8664
8664
  assertParamExists$2('listActivityHistory', 'chainName', chainName);
8665
8665
  // verify required parameter 'fromUpdatedAt' is not null or undefined
@@ -8688,6 +8688,9 @@ const ActivitiesApiAxiosParamCreator = function (configuration) {
8688
8688
  if (contractAddress !== undefined) {
8689
8689
  localVarQueryParameter['contract_address'] = contractAddress;
8690
8690
  }
8691
+ if (activityType !== undefined) {
8692
+ localVarQueryParameter['activity_type'] = activityType;
8693
+ }
8691
8694
  if (pageCursor !== undefined) {
8692
8695
  localVarQueryParameter['page_cursor'] = pageCursor;
8693
8696
  }
@@ -8748,13 +8751,14 @@ const ActivitiesApiFp = function (configuration) {
8748
8751
  * @param {string} fromUpdatedAt From indexed at including given date
8749
8752
  * @param {string} [toUpdatedAt] To indexed at including given date
8750
8753
  * @param {string} [contractAddress] The contract address of the collection
8754
+ * @param {ActivityType} [activityType] The activity type
8751
8755
  * @param {string} [pageCursor] Encoded page cursor to retrieve previous or next page. Use the value returned in the response.
8752
8756
  * @param {number} [pageSize] Maximum number of items to return
8753
8757
  * @param {*} [options] Override http request option.
8754
8758
  * @throws {RequiredError}
8755
8759
  */
8756
- async listActivityHistory(chainName, fromUpdatedAt, toUpdatedAt, contractAddress, pageCursor, pageSize, options) {
8757
- const localVarAxiosArgs = await localVarAxiosParamCreator.listActivityHistory(chainName, fromUpdatedAt, toUpdatedAt, contractAddress, pageCursor, pageSize, options);
8760
+ async listActivityHistory(chainName, fromUpdatedAt, toUpdatedAt, contractAddress, activityType, pageCursor, pageSize, options) {
8761
+ const localVarAxiosArgs = await localVarAxiosParamCreator.listActivityHistory(chainName, fromUpdatedAt, toUpdatedAt, contractAddress, activityType, pageCursor, pageSize, options);
8758
8762
  return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
8759
8763
  },
8760
8764
  };
@@ -8797,7 +8801,7 @@ class ActivitiesApi extends BaseAPI$2 {
8797
8801
  * @memberof ActivitiesApi
8798
8802
  */
8799
8803
  listActivityHistory(requestParameters, options) {
8800
- return ActivitiesApiFp(this.configuration).listActivityHistory(requestParameters.chainName, requestParameters.fromUpdatedAt, requestParameters.toUpdatedAt, requestParameters.contractAddress, requestParameters.pageCursor, requestParameters.pageSize, options).then((request) => request(this.axios, this.basePath));
8804
+ return ActivitiesApiFp(this.configuration).listActivityHistory(requestParameters.chainName, requestParameters.fromUpdatedAt, requestParameters.toUpdatedAt, requestParameters.contractAddress, requestParameters.activityType, requestParameters.pageCursor, requestParameters.pageSize, options).then((request) => request(this.axios, this.basePath));
8801
8805
  }
8802
8806
  }
8803
8807
 
@@ -9472,7 +9476,7 @@ const NftsApiAxiosParamCreator = function (configuration) {
9472
9476
  * @summary Mint NFTs
9473
9477
  * @param {string} contractAddress The address of contract
9474
9478
  * @param {string} chainName The name of chain
9475
- * @param {CreateMintRequestRequest} createMintRequestRequest the request body
9479
+ * @param {CreateMintRequestRequest} createMintRequestRequest Create Mint Request Body
9476
9480
  * @param {*} [options] Override http request option.
9477
9481
  * @throws {RequiredError}
9478
9482
  */
@@ -9512,7 +9516,7 @@ const NftsApiAxiosParamCreator = function (configuration) {
9512
9516
  * @summary Get mint request by reference ID
9513
9517
  * @param {string} contractAddress The address of contract
9514
9518
  * @param {string} chainName The name of chain
9515
- * @param {string} referenceId The ID of the mint request
9519
+ * @param {string} referenceId The id of the mint request
9516
9520
  * @param {*} [options] Override http request option.
9517
9521
  * @throws {RequiredError}
9518
9522
  */
@@ -9783,7 +9787,7 @@ const NftsApiFp = function (configuration) {
9783
9787
  * @summary Mint NFTs
9784
9788
  * @param {string} contractAddress The address of contract
9785
9789
  * @param {string} chainName The name of chain
9786
- * @param {CreateMintRequestRequest} createMintRequestRequest the request body
9790
+ * @param {CreateMintRequestRequest} createMintRequestRequest Create Mint Request Body
9787
9791
  * @param {*} [options] Override http request option.
9788
9792
  * @throws {RequiredError}
9789
9793
  */
@@ -9796,7 +9800,7 @@ const NftsApiFp = function (configuration) {
9796
9800
  * @summary Get mint request by reference ID
9797
9801
  * @param {string} contractAddress The address of contract
9798
9802
  * @param {string} chainName The name of chain
9799
- * @param {string} referenceId The ID of the mint request
9803
+ * @param {string} referenceId The id of the mint request
9800
9804
  * @param {*} [options] Override http request option.
9801
9805
  * @throws {RequiredError}
9802
9806
  */
@@ -10158,6 +10162,7 @@ const OrdersApiAxiosParamCreator = function (configuration) {
10158
10162
  * @param {string} chainName
10159
10163
  * @param {OrderStatusName} [status] Order status to filter by
10160
10164
  * @param {string} [sellItemContractAddress] Sell item contract address to filter by
10165
+ * @param {ListListingsBuyItemTypeEnum} [buyItemType] Buy item type to filter by
10161
10166
  * @param {string} [buyItemContractAddress] Buy item contract address to filter by
10162
10167
  * @param {string} [accountAddress] The account address of the user who created the listing
10163
10168
  * @param {string} [sellItemMetadataId] The metadata_id of the sell item
@@ -10170,7 +10175,7 @@ const OrdersApiAxiosParamCreator = function (configuration) {
10170
10175
  * @param {*} [options] Override http request option.
10171
10176
  * @throws {RequiredError}
10172
10177
  */
10173
- listListings: async (chainName, status, sellItemContractAddress, buyItemContractAddress, accountAddress, sellItemMetadataId, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, options = {}) => {
10178
+ listListings: async (chainName, status, sellItemContractAddress, buyItemType, buyItemContractAddress, accountAddress, sellItemMetadataId, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, options = {}) => {
10174
10179
  // verify required parameter 'chainName' is not null or undefined
10175
10180
  assertParamExists$2('listListings', 'chainName', chainName);
10176
10181
  const localVarPath = `/v1/chains/{chain_name}/orders/listings`
@@ -10190,6 +10195,9 @@ const OrdersApiAxiosParamCreator = function (configuration) {
10190
10195
  if (sellItemContractAddress !== undefined) {
10191
10196
  localVarQueryParameter['sell_item_contract_address'] = sellItemContractAddress;
10192
10197
  }
10198
+ if (buyItemType !== undefined) {
10199
+ localVarQueryParameter['buy_item_type'] = buyItemType;
10200
+ }
10193
10201
  if (buyItemContractAddress !== undefined) {
10194
10202
  localVarQueryParameter['buy_item_contract_address'] = buyItemContractAddress;
10195
10203
  }
@@ -10357,6 +10365,7 @@ const OrdersApiFp = function (configuration) {
10357
10365
  * @param {string} chainName
10358
10366
  * @param {OrderStatusName} [status] Order status to filter by
10359
10367
  * @param {string} [sellItemContractAddress] Sell item contract address to filter by
10368
+ * @param {ListListingsBuyItemTypeEnum} [buyItemType] Buy item type to filter by
10360
10369
  * @param {string} [buyItemContractAddress] Buy item contract address to filter by
10361
10370
  * @param {string} [accountAddress] The account address of the user who created the listing
10362
10371
  * @param {string} [sellItemMetadataId] The metadata_id of the sell item
@@ -10369,8 +10378,8 @@ const OrdersApiFp = function (configuration) {
10369
10378
  * @param {*} [options] Override http request option.
10370
10379
  * @throws {RequiredError}
10371
10380
  */
10372
- async listListings(chainName, status, sellItemContractAddress, buyItemContractAddress, accountAddress, sellItemMetadataId, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, options) {
10373
- const localVarAxiosArgs = await localVarAxiosParamCreator.listListings(chainName, status, sellItemContractAddress, buyItemContractAddress, accountAddress, sellItemMetadataId, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, options);
10381
+ async listListings(chainName, status, sellItemContractAddress, buyItemType, buyItemContractAddress, accountAddress, sellItemMetadataId, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, options) {
10382
+ const localVarAxiosArgs = await localVarAxiosParamCreator.listListings(chainName, status, sellItemContractAddress, buyItemType, buyItemContractAddress, accountAddress, sellItemMetadataId, sellItemTokenId, fromUpdatedAt, pageSize, sortBy, sortDirection, pageCursor, options);
10374
10383
  return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
10375
10384
  },
10376
10385
  /**
@@ -10463,7 +10472,7 @@ let OrdersApi$2 = class OrdersApi extends BaseAPI$2 {
10463
10472
  * @memberof OrdersApi
10464
10473
  */
10465
10474
  listListings(requestParameters, options) {
10466
- return OrdersApiFp(this.configuration).listListings(requestParameters.chainName, requestParameters.status, requestParameters.sellItemContractAddress, requestParameters.buyItemContractAddress, requestParameters.accountAddress, requestParameters.sellItemMetadataId, requestParameters.sellItemTokenId, requestParameters.fromUpdatedAt, requestParameters.pageSize, requestParameters.sortBy, requestParameters.sortDirection, requestParameters.pageCursor, options).then((request) => request(this.axios, this.basePath));
10475
+ return OrdersApiFp(this.configuration).listListings(requestParameters.chainName, requestParameters.status, requestParameters.sellItemContractAddress, requestParameters.buyItemType, requestParameters.buyItemContractAddress, requestParameters.accountAddress, requestParameters.sellItemMetadataId, requestParameters.sellItemTokenId, requestParameters.fromUpdatedAt, requestParameters.pageSize, requestParameters.sortBy, requestParameters.sortDirection, requestParameters.pageCursor, options).then((request) => request(this.axios, this.basePath));
10467
10476
  }
10468
10477
  /**
10469
10478
  * List all trades
@@ -10503,6 +10512,7 @@ const PassportApiAxiosParamCreator = function (configuration) {
10503
10512
  * @param {string} chainName
10504
10513
  * @param {CreateCounterfactualAddressRequest} createCounterfactualAddressRequest
10505
10514
  * @param {*} [options] Override http request option.
10515
+ * @deprecated
10506
10516
  * @throws {RequiredError}
10507
10517
  */
10508
10518
  createCounterfactualAddress: async (chainName, createCounterfactualAddressRequest, options = {}) => {
@@ -10539,6 +10549,7 @@ const PassportApiAxiosParamCreator = function (configuration) {
10539
10549
  * @summary Deprecated Create a counterfactual address
10540
10550
  * @param {CreateCounterfactualAddressRequestDeprecated} createCounterfactualAddressRequestDeprecated
10541
10551
  * @param {*} [options] Override http request option.
10552
+ * @deprecated
10542
10553
  * @throws {RequiredError}
10543
10554
  */
10544
10555
  createCounterfactualAddressDeprecated: async (createCounterfactualAddressRequestDeprecated, options = {}) => {
@@ -10605,22 +10616,20 @@ const PassportApiAxiosParamCreator = function (configuration) {
10605
10616
  };
10606
10617
  },
10607
10618
  /**
10608
- * Get a contract abi by contract address and method id
10609
- * @summary Get a contract abi
10619
+ * Get all the Ethereum linked addresses for a user based on its userId
10620
+ * @summary Get Ethereum linked addresses for a user
10621
+ * @param {string} userId The user\'s userId
10610
10622
  * @param {string} chainName
10611
- * @param {string} contractAddress contract address
10612
- * @param {string} methodId method id
10613
10623
  * @param {*} [options] Override http request option.
10614
10624
  * @throws {RequiredError}
10615
10625
  */
10616
- getContractAbi: async (chainName, contractAddress, methodId, options = {}) => {
10626
+ getLinkedAddresses: async (userId, chainName, options = {}) => {
10627
+ // verify required parameter 'userId' is not null or undefined
10628
+ assertParamExists$2('getLinkedAddresses', 'userId', userId);
10617
10629
  // verify required parameter 'chainName' is not null or undefined
10618
- assertParamExists$2('getContractAbi', 'chainName', chainName);
10619
- // verify required parameter 'contractAddress' is not null or undefined
10620
- assertParamExists$2('getContractAbi', 'contractAddress', contractAddress);
10621
- // verify required parameter 'methodId' is not null or undefined
10622
- assertParamExists$2('getContractAbi', 'methodId', methodId);
10623
- const localVarPath = `/v1/chains/{chain_name}/passport/transaction-metadata`
10630
+ assertParamExists$2('getLinkedAddresses', 'chainName', chainName);
10631
+ const localVarPath = `/v1/chains/{chain_name}/passport/users/{user_id}/linked-addresses`
10632
+ .replace(`{${"user_id"}}`, encodeURIComponent(String(userId)))
10624
10633
  .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
10625
10634
  // use dummy base URL string because the URL constructor only accepts absolute URLs.
10626
10635
  const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$2);
@@ -10634,12 +10643,6 @@ const PassportApiAxiosParamCreator = function (configuration) {
10634
10643
  // authentication BearerAuth required
10635
10644
  // http bearer authentication required
10636
10645
  await setBearerAuthToObject$1(localVarHeaderParameter, configuration);
10637
- if (contractAddress !== undefined) {
10638
- localVarQueryParameter['contract_address'] = contractAddress;
10639
- }
10640
- if (methodId !== undefined) {
10641
- localVarQueryParameter['method_id'] = methodId;
10642
- }
10643
10646
  setSearchParams$2(localVarUrlObj, localVarQueryParameter);
10644
10647
  let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
10645
10648
  localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
@@ -10650,19 +10653,51 @@ const PassportApiAxiosParamCreator = function (configuration) {
10650
10653
  },
10651
10654
  /**
10652
10655
  * Get all the Ethereum linked addresses for a user based on its userId
10653
- * @summary Get Ethereum linked addresses for a user
10656
+ * @summary Deprecated Get Ethereum linked addresses for a user
10654
10657
  * @param {string} userId The user\'s userId
10655
- * @param {string} chainName
10656
10658
  * @param {*} [options] Override http request option.
10659
+ * @deprecated
10657
10660
  * @throws {RequiredError}
10658
10661
  */
10659
- getLinkedAddresses: async (userId, chainName, options = {}) => {
10662
+ getLinkedAddressesDeprecated: async (userId, options = {}) => {
10660
10663
  // verify required parameter 'userId' is not null or undefined
10661
- assertParamExists$2('getLinkedAddresses', 'userId', userId);
10664
+ assertParamExists$2('getLinkedAddressesDeprecated', 'userId', userId);
10665
+ const localVarPath = `/passport-mr/v1/users/{userId}/linked-addresses`
10666
+ .replace(`{${"userId"}}`, encodeURIComponent(String(userId)));
10667
+ // use dummy base URL string because the URL constructor only accepts absolute URLs.
10668
+ const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$2);
10669
+ let baseOptions;
10670
+ if (configuration) {
10671
+ baseOptions = configuration.baseOptions;
10672
+ }
10673
+ const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
10674
+ const localVarHeaderParameter = {};
10675
+ const localVarQueryParameter = {};
10676
+ // authentication BearerAuth required
10677
+ // http bearer authentication required
10678
+ await setBearerAuthToObject$1(localVarHeaderParameter, configuration);
10679
+ setSearchParams$2(localVarUrlObj, localVarQueryParameter);
10680
+ let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
10681
+ localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
10682
+ return {
10683
+ url: toPathString$2(localVarUrlObj),
10684
+ options: localVarRequestOptions,
10685
+ };
10686
+ },
10687
+ /**
10688
+ * Get transaction metadata for a given encoded transaction
10689
+ * @summary Get transaction metadata
10690
+ * @param {string} chainName
10691
+ * @param {GetTransactionMetadataRequest} getTransactionMetadataRequest
10692
+ * @param {*} [options] Override http request option.
10693
+ * @throws {RequiredError}
10694
+ */
10695
+ getTransactionMetadata: async (chainName, getTransactionMetadataRequest, options = {}) => {
10662
10696
  // verify required parameter 'chainName' is not null or undefined
10663
- assertParamExists$2('getLinkedAddresses', 'chainName', chainName);
10664
- const localVarPath = `/v1/chains/{chain_name}/passport/users/{user_id}/linked-addresses`
10665
- .replace(`{${"user_id"}}`, encodeURIComponent(String(userId)))
10697
+ assertParamExists$2('getTransactionMetadata', 'chainName', chainName);
10698
+ // verify required parameter 'getTransactionMetadataRequest' is not null or undefined
10699
+ assertParamExists$2('getTransactionMetadata', 'getTransactionMetadataRequest', getTransactionMetadataRequest);
10700
+ const localVarPath = `/v1/chains/{chain_name}/passport/transaction-metadata`
10666
10701
  .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
10667
10702
  // use dummy base URL string because the URL constructor only accepts absolute URLs.
10668
10703
  const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$2);
@@ -10670,32 +10705,47 @@ const PassportApiAxiosParamCreator = function (configuration) {
10670
10705
  if (configuration) {
10671
10706
  baseOptions = configuration.baseOptions;
10672
10707
  }
10673
- const localVarRequestOptions = { method: 'GET', ...baseOptions, ...options };
10708
+ const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options };
10674
10709
  const localVarHeaderParameter = {};
10675
10710
  const localVarQueryParameter = {};
10676
10711
  // authentication BearerAuth required
10677
10712
  // http bearer authentication required
10678
10713
  await setBearerAuthToObject$1(localVarHeaderParameter, configuration);
10714
+ localVarHeaderParameter['Content-Type'] = 'application/json';
10679
10715
  setSearchParams$2(localVarUrlObj, localVarQueryParameter);
10680
10716
  let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
10681
10717
  localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
10718
+ localVarRequestOptions.data = serializeDataIfNeeded$2(getTransactionMetadataRequest, localVarRequestOptions, configuration);
10682
10719
  return {
10683
10720
  url: toPathString$2(localVarUrlObj),
10684
10721
  options: localVarRequestOptions,
10685
10722
  };
10686
10723
  },
10687
10724
  /**
10688
- * Get all the Ethereum linked addresses for a user based on its userId
10689
- * @summary Deprecated Get Ethereum linked addresses for a user
10690
- * @param {string} userId The user\'s userId
10725
+ * Get transaction metadata for a given encoded transaction
10726
+ * @summary Get transaction metadata
10727
+ * @param {string} chainName
10728
+ * @param {string} contractAddress The address of the contract intended for interaction with this transaction
10729
+ * @param {string} methodId The method ID of the contract intended for interaction with this transaction
10730
+ * @param {string} transactionId ID of the given transaction to be decoded
10731
+ * @param {string} transactionData Encoded transaction data
10691
10732
  * @param {*} [options] Override http request option.
10733
+ * @deprecated
10692
10734
  * @throws {RequiredError}
10693
10735
  */
10694
- getLinkedAddressesDeprecated: async (userId, options = {}) => {
10695
- // verify required parameter 'userId' is not null or undefined
10696
- assertParamExists$2('getLinkedAddressesDeprecated', 'userId', userId);
10697
- const localVarPath = `/passport-mr/v1/users/{userId}/linked-addresses`
10698
- .replace(`{${"userId"}}`, encodeURIComponent(String(userId)));
10736
+ getTransactionMetadataDeprecated: async (chainName, contractAddress, methodId, transactionId, transactionData, options = {}) => {
10737
+ // verify required parameter 'chainName' is not null or undefined
10738
+ assertParamExists$2('getTransactionMetadataDeprecated', 'chainName', chainName);
10739
+ // verify required parameter 'contractAddress' is not null or undefined
10740
+ assertParamExists$2('getTransactionMetadataDeprecated', 'contractAddress', contractAddress);
10741
+ // verify required parameter 'methodId' is not null or undefined
10742
+ assertParamExists$2('getTransactionMetadataDeprecated', 'methodId', methodId);
10743
+ // verify required parameter 'transactionId' is not null or undefined
10744
+ assertParamExists$2('getTransactionMetadataDeprecated', 'transactionId', transactionId);
10745
+ // verify required parameter 'transactionData' is not null or undefined
10746
+ assertParamExists$2('getTransactionMetadataDeprecated', 'transactionData', transactionData);
10747
+ const localVarPath = `/v1/chains/{chain_name}/passport/transaction-metadata`
10748
+ .replace(`{${"chain_name"}}`, encodeURIComponent(String(chainName)));
10699
10749
  // use dummy base URL string because the URL constructor only accepts absolute URLs.
10700
10750
  const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL$2);
10701
10751
  let baseOptions;
@@ -10708,6 +10758,18 @@ const PassportApiAxiosParamCreator = function (configuration) {
10708
10758
  // authentication BearerAuth required
10709
10759
  // http bearer authentication required
10710
10760
  await setBearerAuthToObject$1(localVarHeaderParameter, configuration);
10761
+ if (contractAddress !== undefined) {
10762
+ localVarQueryParameter['contract_address'] = contractAddress;
10763
+ }
10764
+ if (methodId !== undefined) {
10765
+ localVarQueryParameter['method_id'] = methodId;
10766
+ }
10767
+ if (transactionId !== undefined) {
10768
+ localVarQueryParameter['transaction_id'] = transactionId;
10769
+ }
10770
+ if (transactionData !== undefined) {
10771
+ localVarQueryParameter['transaction_data'] = transactionData;
10772
+ }
10711
10773
  setSearchParams$2(localVarUrlObj, localVarQueryParameter);
10712
10774
  let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
10713
10775
  localVarRequestOptions.headers = { ...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers };
@@ -10731,6 +10793,7 @@ const PassportApiFp = function (configuration) {
10731
10793
  * @param {string} chainName
10732
10794
  * @param {CreateCounterfactualAddressRequest} createCounterfactualAddressRequest
10733
10795
  * @param {*} [options] Override http request option.
10796
+ * @deprecated
10734
10797
  * @throws {RequiredError}
10735
10798
  */
10736
10799
  async createCounterfactualAddress(chainName, createCounterfactualAddressRequest, options) {
@@ -10742,6 +10805,7 @@ const PassportApiFp = function (configuration) {
10742
10805
  * @summary Deprecated Create a counterfactual address
10743
10806
  * @param {CreateCounterfactualAddressRequestDeprecated} createCounterfactualAddressRequestDeprecated
10744
10807
  * @param {*} [options] Override http request option.
10808
+ * @deprecated
10745
10809
  * @throws {RequiredError}
10746
10810
  */
10747
10811
  async createCounterfactualAddressDeprecated(createCounterfactualAddressRequestDeprecated, options) {
@@ -10760,19 +10824,6 @@ const PassportApiFp = function (configuration) {
10760
10824
  const localVarAxiosArgs = await localVarAxiosParamCreator.createCounterfactualAddressV2(chainName, createCounterfactualAddressRequest, options);
10761
10825
  return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
10762
10826
  },
10763
- /**
10764
- * Get a contract abi by contract address and method id
10765
- * @summary Get a contract abi
10766
- * @param {string} chainName
10767
- * @param {string} contractAddress contract address
10768
- * @param {string} methodId method id
10769
- * @param {*} [options] Override http request option.
10770
- * @throws {RequiredError}
10771
- */
10772
- async getContractAbi(chainName, contractAddress, methodId, options) {
10773
- const localVarAxiosArgs = await localVarAxiosParamCreator.getContractAbi(chainName, contractAddress, methodId, options);
10774
- return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
10775
- },
10776
10827
  /**
10777
10828
  * Get all the Ethereum linked addresses for a user based on its userId
10778
10829
  * @summary Get Ethereum linked addresses for a user
@@ -10790,12 +10841,41 @@ const PassportApiFp = function (configuration) {
10790
10841
  * @summary Deprecated Get Ethereum linked addresses for a user
10791
10842
  * @param {string} userId The user\'s userId
10792
10843
  * @param {*} [options] Override http request option.
10844
+ * @deprecated
10793
10845
  * @throws {RequiredError}
10794
10846
  */
10795
10847
  async getLinkedAddressesDeprecated(userId, options) {
10796
10848
  const localVarAxiosArgs = await localVarAxiosParamCreator.getLinkedAddressesDeprecated(userId, options);
10797
10849
  return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
10798
10850
  },
10851
+ /**
10852
+ * Get transaction metadata for a given encoded transaction
10853
+ * @summary Get transaction metadata
10854
+ * @param {string} chainName
10855
+ * @param {GetTransactionMetadataRequest} getTransactionMetadataRequest
10856
+ * @param {*} [options] Override http request option.
10857
+ * @throws {RequiredError}
10858
+ */
10859
+ async getTransactionMetadata(chainName, getTransactionMetadataRequest, options) {
10860
+ const localVarAxiosArgs = await localVarAxiosParamCreator.getTransactionMetadata(chainName, getTransactionMetadataRequest, options);
10861
+ return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
10862
+ },
10863
+ /**
10864
+ * Get transaction metadata for a given encoded transaction
10865
+ * @summary Get transaction metadata
10866
+ * @param {string} chainName
10867
+ * @param {string} contractAddress The address of the contract intended for interaction with this transaction
10868
+ * @param {string} methodId The method ID of the contract intended for interaction with this transaction
10869
+ * @param {string} transactionId ID of the given transaction to be decoded
10870
+ * @param {string} transactionData Encoded transaction data
10871
+ * @param {*} [options] Override http request option.
10872
+ * @deprecated
10873
+ * @throws {RequiredError}
10874
+ */
10875
+ async getTransactionMetadataDeprecated(chainName, contractAddress, methodId, transactionId, transactionData, options) {
10876
+ const localVarAxiosArgs = await localVarAxiosParamCreator.getTransactionMetadataDeprecated(chainName, contractAddress, methodId, transactionId, transactionData, options);
10877
+ return createRequestFunction$2(localVarAxiosArgs, globalAxios$1, BASE_PATH$2, configuration);
10878
+ },
10799
10879
  };
10800
10880
  };
10801
10881
  /**
@@ -10810,6 +10890,7 @@ class PassportApi extends BaseAPI$2 {
10810
10890
  * @summary Create a counterfactual address
10811
10891
  * @param {PassportApiCreateCounterfactualAddressRequest} requestParameters Request parameters.
10812
10892
  * @param {*} [options] Override http request option.
10893
+ * @deprecated
10813
10894
  * @throws {RequiredError}
10814
10895
  * @memberof PassportApi
10815
10896
  */
@@ -10821,6 +10902,7 @@ class PassportApi extends BaseAPI$2 {
10821
10902
  * @summary Deprecated Create a counterfactual address
10822
10903
  * @param {PassportApiCreateCounterfactualAddressDeprecatedRequest} requestParameters Request parameters.
10823
10904
  * @param {*} [options] Override http request option.
10905
+ * @deprecated
10824
10906
  * @throws {RequiredError}
10825
10907
  * @memberof PassportApi
10826
10908
  */
@@ -10838,17 +10920,6 @@ class PassportApi extends BaseAPI$2 {
10838
10920
  createCounterfactualAddressV2(requestParameters, options) {
10839
10921
  return PassportApiFp(this.configuration).createCounterfactualAddressV2(requestParameters.chainName, requestParameters.createCounterfactualAddressRequest, options).then((request) => request(this.axios, this.basePath));
10840
10922
  }
10841
- /**
10842
- * Get a contract abi by contract address and method id
10843
- * @summary Get a contract abi
10844
- * @param {PassportApiGetContractAbiRequest} requestParameters Request parameters.
10845
- * @param {*} [options] Override http request option.
10846
- * @throws {RequiredError}
10847
- * @memberof PassportApi
10848
- */
10849
- getContractAbi(requestParameters, options) {
10850
- return PassportApiFp(this.configuration).getContractAbi(requestParameters.chainName, requestParameters.contractAddress, requestParameters.methodId, options).then((request) => request(this.axios, this.basePath));
10851
- }
10852
10923
  /**
10853
10924
  * Get all the Ethereum linked addresses for a user based on its userId
10854
10925
  * @summary Get Ethereum linked addresses for a user
@@ -10865,12 +10936,36 @@ class PassportApi extends BaseAPI$2 {
10865
10936
  * @summary Deprecated Get Ethereum linked addresses for a user
10866
10937
  * @param {PassportApiGetLinkedAddressesDeprecatedRequest} requestParameters Request parameters.
10867
10938
  * @param {*} [options] Override http request option.
10939
+ * @deprecated
10868
10940
  * @throws {RequiredError}
10869
10941
  * @memberof PassportApi
10870
10942
  */
10871
10943
  getLinkedAddressesDeprecated(requestParameters, options) {
10872
10944
  return PassportApiFp(this.configuration).getLinkedAddressesDeprecated(requestParameters.userId, options).then((request) => request(this.axios, this.basePath));
10873
10945
  }
10946
+ /**
10947
+ * Get transaction metadata for a given encoded transaction
10948
+ * @summary Get transaction metadata
10949
+ * @param {PassportApiGetTransactionMetadataRequest} requestParameters Request parameters.
10950
+ * @param {*} [options] Override http request option.
10951
+ * @throws {RequiredError}
10952
+ * @memberof PassportApi
10953
+ */
10954
+ getTransactionMetadata(requestParameters, options) {
10955
+ return PassportApiFp(this.configuration).getTransactionMetadata(requestParameters.chainName, requestParameters.getTransactionMetadataRequest, options).then((request) => request(this.axios, this.basePath));
10956
+ }
10957
+ /**
10958
+ * Get transaction metadata for a given encoded transaction
10959
+ * @summary Get transaction metadata
10960
+ * @param {PassportApiGetTransactionMetadataDeprecatedRequest} requestParameters Request parameters.
10961
+ * @param {*} [options] Override http request option.
10962
+ * @deprecated
10963
+ * @throws {RequiredError}
10964
+ * @memberof PassportApi
10965
+ */
10966
+ getTransactionMetadataDeprecated(requestParameters, options) {
10967
+ return PassportApiFp(this.configuration).getTransactionMetadataDeprecated(requestParameters.chainName, requestParameters.contractAddress, requestParameters.methodId, requestParameters.transactionId, requestParameters.transactionData, options).then((request) => request(this.axios, this.basePath));
10968
+ }
10874
10969
  }
10875
10970
 
10876
10971
  /* tslint:disable */
@@ -11213,6 +11308,7 @@ var MintRequestStatus;
11213
11308
  var NFTContractType;
11214
11309
  (function (NFTContractType) {
11215
11310
  NFTContractType["Erc721"] = "ERC721";
11311
+ NFTContractType["Erc1155"] = "ERC1155";
11216
11312
  })(NFTContractType || (NFTContractType = {}));
11217
11313
 
11218
11314
  /* tslint:disable */
@@ -11350,7 +11446,7 @@ class MultiRollupApiClients {
11350
11446
  }
11351
11447
 
11352
11448
  // eslint-disable-next-line @typescript-eslint/naming-convention
11353
- const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.21.0' };
11449
+ const defaultHeaders$1 = { 'x-sdk-version': 'ts-immutable-sdk-1.21.2-alpha' };
11354
11450
  const createConfig$1 = ({ basePath, headers, }) => {
11355
11451
  if (!basePath.trim()) {
11356
11452
  throw Error('basePath can not be empty');
@@ -11529,7 +11625,7 @@ const flattenProperties = (properties) => {
11529
11625
  };
11530
11626
 
11531
11627
  // WARNING: DO NOT CHANGE THE STRING BELOW. IT GETS REPLACED AT BUILD TIME.
11532
- const SDK_VERSION = '1.21.0';
11628
+ const SDK_VERSION = '1.21.2-alpha';
11533
11629
  const getReferrer = () => {
11534
11630
  if (isNode()) {
11535
11631
  return '';
@@ -11779,7 +11875,7 @@ const addKeysToHeadersOverride = (baseConfig, overrides) => {
11779
11875
  /* eslint-disable @typescript-eslint/naming-convention */
11780
11876
  class ApiConfiguration extends index$2.Configuration {
11781
11877
  }
11782
- const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.21.0' };
11878
+ const defaultHeaders = { 'x-sdk-version': 'ts-immutable-sdk-1.21.2-alpha' };
11783
11879
  /**
11784
11880
  * @dev use createImmutableXConfiguration instead
11785
11881
  */
@@ -11818,7 +11914,7 @@ const createImmutableXConfiguration = ({ basePath, chainID, coreContractAddress,
11818
11914
  chainID,
11819
11915
  coreContractAddress,
11820
11916
  registrationContractAddress,
11821
- sdkVersion: 'ts-immutable-sdk-1.21.0',
11917
+ sdkVersion: 'ts-immutable-sdk-1.21.2-alpha',
11822
11918
  baseConfig,
11823
11919
  });
11824
11920
  const production = ({ baseConfig }) => createImmutableXConfiguration({
@@ -13999,6 +14095,12 @@ const constantPointsHex = [
13999
14095
  '5d8f4897ce44007ec5bfcb9aeb78b8f6e1d40a514f72d213c9300d2770d2b8c',
14000
14096
  ],
14001
14097
  ];
14098
+
14099
+ // eslint-disable-next-line @typescript-eslint/naming-convention
14100
+ const DEFAULT_SIGNATURE_MESSAGE = 'Only sign this request if you’ve initiated an action with Immutable X.';
14101
+ const DEFAULT_ACCOUNT_LAYER = 'starkex';
14102
+ const DEFAULT_ACCOUNT_APPLICATION = 'immutablex';
14103
+ const DEFAULT_ACCOUNT_INDEX = '1';
14002
14104
  const prime = new BN('800000000000011000000000000000000000000000000000000000000000001', 16);
14003
14105
  const order = new BN('08000000 00000010 ffffffff ffffffff b781126d cae7b232 1e66a241 adc64d2f', 16);
14004
14106
  const starkEc = new ec(new curves.PresetCurve({
@@ -14036,8 +14138,50 @@ new BN('8000000000000000', 16);
14036
14138
  new BN('800000000000011000000000000000000000000000000000000000000000001', 16);
14037
14139
  // Equals 2**251. This value limits msgHash and the signature parts.
14038
14140
  new BN('800000000000000000000000000000000000000000000000000000000000000', 16);
14039
- new BN('08000000 00000010 ffffffff ffffffff b781126d cae7b232 1e66a241 adc64d2f', 16);
14040
- new BN('FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141', 16);
14141
+ const ORDER = new BN('08000000 00000010 ffffffff ffffffff b781126d cae7b232 1e66a241 adc64d2f', 16);
14142
+ const SECP_ORDER = new BN('FFFFFFFF FFFFFFFF FFFFFFFF FFFFFFFE BAAEDCE6 AF48A03B BFD25E8C D0364141', 16);
14143
+
14144
+ /* eslint-disable no-param-reassign */
14145
+ /* eslint-disable no-plusplus */
14146
+ /* eslint-disable @typescript-eslint/no-explicit-any */
14147
+ function getIntFromBits(hex, start, end = undefined) {
14148
+ const bin = encUtils.hexToBinary(hex);
14149
+ const bits = bin.slice(start, end);
14150
+ const int = encUtils.binaryToNumber(bits);
14151
+ return int;
14152
+ }
14153
+ function getAccountPath(layer, application, ethereumAddress, index) {
14154
+ const layerHash = hashJS.sha256().update(layer).digest('hex');
14155
+ const applicationHash = hashJS.sha256().update(application).digest('hex');
14156
+ const layerInt = getIntFromBits(layerHash, -31);
14157
+ const applicationInt = getIntFromBits(applicationHash, -31);
14158
+ const ethAddressInt1 = getIntFromBits(ethereumAddress, -31);
14159
+ const ethAddressInt2 = getIntFromBits(ethereumAddress, -62, -31);
14160
+ return `m/2645'/${layerInt}'/${applicationInt}'/${ethAddressInt1}'/${ethAddressInt2}'/${index}`;
14161
+ }
14162
+ function hashKeyWithIndex$1(key, index) {
14163
+ return new BN(hashJS
14164
+ .sha256()
14165
+ .update(encUtils.hexToBuffer(encUtils.removeHexPrefix(key)
14166
+ + encUtils.sanitizeBytes(encUtils.numberToHex(index), 2)))
14167
+ .digest('hex'), 16);
14168
+ }
14169
+ function grindKey$1(privateKey) {
14170
+ let i = 0;
14171
+ let key = hashKeyWithIndex$1(privateKey, i);
14172
+ while (!key.lt(SECP_ORDER.sub(SECP_ORDER.mod(ORDER)))) {
14173
+ key = hashKeyWithIndex$1(key.toString(16), i);
14174
+ i = i++;
14175
+ }
14176
+ return key.mod(ORDER).toString('hex');
14177
+ }
14178
+ function getPrivateKeyFromPath$1(seed, path) {
14179
+ return hdkey
14180
+ .fromMasterSeed(Buffer.from(seed.slice(2), 'hex')) // assuming seed is '0x...'
14181
+ .derivePath(path)
14182
+ .getWallet()
14183
+ .getPrivateKeyString();
14184
+ }
14041
14185
 
14042
14186
  var Errors;
14043
14187
  (function (Errors) {
@@ -14045,6 +14189,84 @@ var Errors;
14045
14189
  Errors["StarkCurveInvalidMessageLength"] = "invalid message length";
14046
14190
  })(Errors || (Errors = {}));
14047
14191
 
14192
+ class StandardStarkSigner {
14193
+ privateKey;
14194
+ keyPair;
14195
+ constructor(privateKey) {
14196
+ this.privateKey = privateKey;
14197
+ this.keyPair = starkEc.keyFromPrivate(privateKey, 'hex');
14198
+ }
14199
+ getAddress() {
14200
+ const xCoordinate = this.keyPair.getPublic().getX().toString('hex');
14201
+ return encUtils.sanitizeHex(xCoordinate);
14202
+ }
14203
+ async signMessage(msg) {
14204
+ return this.serialize(this.keyPair.sign(this.fixMsgHashLen(msg)));
14205
+ }
14206
+ // eslint-disable-next-line class-methods-use-this
14207
+ serialize(sig) {
14208
+ return encUtils.addHexPrefix(encUtils.padLeft(sig.r.toString('hex'), 64)
14209
+ + encUtils.padLeft(sig.s.toString('hex'), 64));
14210
+ }
14211
+ /*
14212
+ The function _truncateToN in lib/elliptic/ec/index.js does a shift-right of delta bits,
14213
+ if delta is positive, where
14214
+ delta = msgHash.byteLength() * 8 - starkEx.n.bitLength().
14215
+ This function does the opposite operation so that
14216
+ _truncateToN(fixMsgHashLen(msgHash)) == msgHash.
14217
+ */
14218
+ // eslint-disable-next-line class-methods-use-this
14219
+ fixMsgHashLen(msg) {
14220
+ // eslint-disable-next-line no-param-reassign
14221
+ msg = encUtils.removeHexPrefix(msg);
14222
+ // eslint-disable-next-line no-param-reassign
14223
+ msg = new BN(msg, 'hex').toString('hex');
14224
+ if (msg.length <= 62) {
14225
+ // In this case, msg should not be transformed, as the byteLength() is at most 31,
14226
+ // so delta < 0 (see _truncateToN).
14227
+ return msg;
14228
+ }
14229
+ if (msg.length !== 63) {
14230
+ throw new Error(Errors.StarkCurveInvalidMessageLength);
14231
+ }
14232
+ // In this case delta will be 4 so we perform a shift-left of 4 bits by adding a ZERO_BN.
14233
+ return `${msg}0`;
14234
+ }
14235
+ }
14236
+ /**
14237
+ * Creates a new Stark Signer
14238
+ * @params starkPrivateKey - the private key as a hex string
14239
+ * @returns a StarkSigner
14240
+ */
14241
+ function createStarkSigner(starkPrivateKey) {
14242
+ return new StandardStarkSigner(starkPrivateKey);
14243
+ }
14244
+
14245
+ /**
14246
+ * @description Gets the account (stark public key) value of the requested user
14247
+ * (ethAddress) for Production environment only.
14248
+ * @param ethAddress {string}
14249
+ * @returns {Promise<StarkUserResponse | undefined>}
14250
+ */
14251
+ async function getStarkPublicKeyFromImx(ethAddress) {
14252
+ try {
14253
+ if (ethAddress) {
14254
+ const response = await globalAxios$1.get(`https://api.x.immutable.com/v1/users/${ethAddress}`);
14255
+ const user = response.data;
14256
+ if (user?.accounts && user.accounts.length > 0) {
14257
+ // Only one account per user
14258
+ return { starkPublicKey: user.accounts[0], accountNotFound: false };
14259
+ }
14260
+ }
14261
+ }
14262
+ catch (error) {
14263
+ if (globalAxios$1.isAxiosError(error) && error.response?.data.code === 'account_not_found') {
14264
+ return { starkPublicKey: '', accountNotFound: true };
14265
+ }
14266
+ }
14267
+ return undefined;
14268
+ }
14269
+
14048
14270
  /*
14049
14271
  Stark-friendly elliptic curve
14050
14272
 
@@ -14084,6 +14306,161 @@ new ec(new curves.PresetCurve({
14084
14306
  '5668060aa49730b7be4801df46ec62de53ecd11abe43a32873000c36e8dc1f',
14085
14307
  ],
14086
14308
  }));
14309
+ // eslint-disable-next-line @typescript-eslint/naming-convention
14310
+ const MAX_ALLOWED_VAL = () => {
14311
+ const sha256EcMaxDigest = new BN('1 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000', 16);
14312
+ return sha256EcMaxDigest.sub(sha256EcMaxDigest.mod(starkEcOrder));
14313
+ };
14314
+ // Create a hash from a key + an index
14315
+ function hashKeyWithIndex(key, index) {
14316
+ return new BN(hashJS
14317
+ .sha256()
14318
+ .update(encUtils.hexToBuffer(encUtils.removeHexPrefix(key)
14319
+ + encUtils.sanitizeBytes(encUtils.numberToHex(index), 2)))
14320
+ .digest('hex'), 16);
14321
+ }
14322
+ //////////////////////////////////////////////////////////////////////////////////////////////////
14323
+ // DANGER: DO NOT MODIFY GRIND KEY / KEY GENERATION LOGIC.
14324
+ //////////////////////////////////////////////////////////////////////////////////////////////////
14325
+ /*
14326
+ The grindKeyV201 function is used to provide a backwards compatible way to re-generate keys if any of the accounts were created using v2.0.1 of core-sdk.
14327
+ */
14328
+ function grindKeyV201(keySeed) {
14329
+ const maxAllowedVal = MAX_ALLOWED_VAL();
14330
+ // The key passed to hashKeyWithIndex must have a length of 64 characters
14331
+ // to ensure that the correct number of leading zeroes are used as input
14332
+ // to the hashing loop
14333
+ let key = hashKeyWithIndex(keySeed.toString('hex', 64), 0);
14334
+ // Make sure the produced key is devided by the Stark EC order, and falls within the range
14335
+ // [0, maxAllowedVal).
14336
+ for (let i = 0; key.gte(maxAllowedVal); i++) {
14337
+ key = hashKeyWithIndex(key.toString('hex'), i);
14338
+ }
14339
+ return key.umod(starkEcOrder).toString('hex');
14340
+ }
14341
+ //////////////////////////////////////////////////////////////////////////////////////////////////
14342
+ // DANGER: DO NOT MODIFY GRIND KEY / KEY GENERATION LOGIC.
14343
+ //////////////////////////////////////////////////////////////////////////////////////////////////
14344
+ /*
14345
+ This grindKey function is the default logic to be used by all our SDKs including the imx-sdk-js. All the accounts
14346
+ that were created using imx-sdk-js are to be supported by the legacy.grindKey function.
14347
+
14348
+ This function receives a key seed and produces an appropriate StarkEx key from a uniform
14349
+ distribution.
14350
+
14351
+ Although it is possible to define a StarkEx key as a residue between the StarkEx EC order and a
14352
+ random 256bit digest value, the result would be a biased key. In order to prevent this bias, we
14353
+ deterministically search (by applying more hashes, AKA grinding) for a value lower than the largest
14354
+ 256bit multiple of StarkEx EC order.
14355
+
14356
+ https://github.com/starkware-libs/starkware-crypto-utils/blob/dev/src/js/key_derivation.js#L119
14357
+
14358
+ The accounts that has been created with versions released between 1.0.0-beta.3 and 2.0.0 are fine as it uses this method.
14359
+ Although this logic has been in place in core-sdk since the following commit, it was momentarily changed in version 2.0.1 to use gringKeyV201 method.
14360
+ https://github.com/immutable/imx-core-sdk/commit/3d9e35b4598784589bd7f121f26e105493196716
14361
+ */
14362
+ function grindKey(keySeed) {
14363
+ const maxAllowedVal = MAX_ALLOWED_VAL();
14364
+ // The key passed to hashKeyWithIndex must have a length of 64 characters
14365
+ // to ensure that the correct number of leading zeroes are used as input
14366
+ // to the hashing loop
14367
+ let key = hashKeyWithIndex(keySeed.toString('hex', 64), 0);
14368
+ // Make sure the produced key is devided by the Stark EC order, and falls within the range
14369
+ // [0, maxAllowedVal).
14370
+ for (let i = 1; key.gte(maxAllowedVal); i++) {
14371
+ key = hashKeyWithIndex(key.toString('hex'), i);
14372
+ }
14373
+ return key.umod(starkEcOrder).toString('hex');
14374
+ }
14375
+ // Check if the hash value of the the given PrivateKey falls above the starkEcOrder limit.
14376
+ // This function is only serving the context of DX-2184, used to determine if we need to validate the generated key
14377
+ // against the one recorded in IMX servers.
14378
+ function checkIfHashedKeyIsAboveLimit(keySeed) {
14379
+ const maxAllowedVal = MAX_ALLOWED_VAL();
14380
+ // The key passed to hashKeyWithIndex must have a length of 64 characters
14381
+ // to ensure that the correct number of leading zeroes are used as input
14382
+ // to the hashing loop
14383
+ const key = hashKeyWithIndex(keySeed.toString('hex', 64), 0);
14384
+ return key.gte(maxAllowedVal);
14385
+ }
14386
+ function getPrivateKeyFromPath(seed, path) {
14387
+ const privateKey = hdkey
14388
+ .fromMasterSeed(Buffer.from(seed.slice(2), 'hex')) // assuming seed is '0x...'
14389
+ .derivePath(path)
14390
+ .getWallet()
14391
+ .getPrivateKey();
14392
+ return new BN(privateKey);
14393
+ }
14394
+ async function getKeyFromPath(seed, path, ethAddress) {
14395
+ const privateKeySeed = getPrivateKeyFromPath(seed, path);
14396
+ const starkPrivateKey = grindKey(privateKeySeed);
14397
+ // The following logic is added in response to bug found in DX-2167 and DX-2184.
14398
+ // To provide a backwards compatible way to fetch keys across link/js SDK and Core SDK.
14399
+ // Note: The issue we are addressing here is that if the hashKeyWithIndex value is above the limit, then we perform
14400
+ // hash again with index until it comes below the limit. But for the first time the index is not incremented in
14401
+ // imx-sdk-js where as it was in core-sdk that was the difference. For this reason it would have worked for cases
14402
+ // where the hashed value was less than the limit and fails only when it is above the limit.
14403
+ // Refer, https://immutable.atlassian.net/browse/DX-2167
14404
+ // Same code as grindKey, required to check if the generated private key
14405
+ // goes above the limit when hashed for first time to identify if we need to do backwards
14406
+ // compatibility check:
14407
+ // The bug only exists if the hashed value of given seed is above the stark curve limit.
14408
+ if (!checkIfHashedKeyIsAboveLimit(privateKeySeed)) {
14409
+ return starkPrivateKey;
14410
+ }
14411
+ // Check if the generated stark public key matches with the existing account value for that user.
14412
+ // We are only validating for Production environment.
14413
+ // For Sandbox account/key mismatch, solution is to discard the old account and create a new one.
14414
+ const imxResponse = await getStarkPublicKeyFromImx(ethAddress);
14415
+ // If the account is not found or account matches we just return the key pair at the end of this method.
14416
+ // Only need to so alternative method if the account is found but the stark public key does not match.
14417
+ if (imxResponse === undefined) {
14418
+ throw new Error('Error fetching stark public key from IMX');
14419
+ }
14420
+ // If the account is not found it is a new account, just return the Stark Private Key that is generated by grindKey function.
14421
+ if (imxResponse.accountNotFound) {
14422
+ return starkPrivateKey;
14423
+ }
14424
+ const registeredStarkPublicKeyBN = new BN(encUtils.removeHexPrefix(imxResponse.starkPublicKey), 16);
14425
+ let starkPublicKey = await createStarkSigner(starkPrivateKey).getAddress();
14426
+ // If the user account matches with generated stark public key user, just return Stark Private Key.
14427
+ if (registeredStarkPublicKeyBN.eq(new BN(encUtils.removeHexPrefix(starkPublicKey), 16))) {
14428
+ return starkPrivateKey;
14429
+ }
14430
+ // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
14431
+ // This is backwards compatible crypto (core-sdk) version 2.0.1
14432
+ // If we are here, we found the account but did not match with the recorded user account.
14433
+ // Lets try to use grindKeyV201 method from backwards compatible logic to generate a key and see if that matches.
14434
+ const starkPrivateKeyV201Compatible = grindKeyV201(privateKeySeed);
14435
+ starkPublicKey = await createStarkSigner(starkPrivateKeyV201Compatible).getAddress();
14436
+ if (registeredStarkPublicKeyBN.eq(new BN(encUtils.removeHexPrefix(starkPublicKey), 16))) {
14437
+ return starkPrivateKeyV201Compatible;
14438
+ }
14439
+ // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
14440
+ // This section is legacy crypto, compatible with imx-sdk-js released before 1.43.5
14441
+ const privateKeyString = getPrivateKeyFromPath$1(seed, path);
14442
+ const starkPrivateKeyLegacy = grindKey$1(privateKeyString);
14443
+ starkPublicKey = await createStarkSigner(starkPrivateKeyLegacy).getAddress();
14444
+ if (registeredStarkPublicKeyBN.eq(new BN(encUtils.removeHexPrefix(starkPublicKey), 16))) {
14445
+ return starkPrivateKeyLegacy;
14446
+ }
14447
+ // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
14448
+ // Account is found, but did not match with stark public keys generated by either grindKey or grindKeyV1 method.
14449
+ // Will have to contact support for further investigation.
14450
+ throw new Error('Can not deterministically generate stark private key - please contact support');
14451
+ }
14452
+ /**
14453
+ * Generates a deterministic Stark private key from the provided signer.
14454
+ * @returns the private key as a hex string
14455
+ */
14456
+ async function generateLegacyStarkPrivateKey(signer) {
14457
+ const address = (await signer.getAddress()).toLowerCase();
14458
+ const signature = await signer.signMessage(DEFAULT_SIGNATURE_MESSAGE);
14459
+ const seed = splitSignature(signature).s;
14460
+ const path = getAccountPath(DEFAULT_ACCOUNT_LAYER, DEFAULT_ACCOUNT_APPLICATION, address, DEFAULT_ACCOUNT_INDEX);
14461
+ const key = await getKeyFromPath(seed, path, address);
14462
+ return key.padStart(64, '0');
14463
+ }
14087
14464
 
14088
14465
  async function mintingWorkflow(signer, request, mintsApi) {
14089
14466
  // TODO: improve this object key rearrangement.